1 | //===- SimplifyCFGOptions.h - Control structure for SimplifyCFG -*- C++ -*-===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | // |
9 | // A set of parameters used to control the transforms in the SimplifyCFG pass. |
10 | // Options may change depending on the position in the optimization pipeline. |
11 | // For example, canonical form that includes switches and branches may later be |
12 | // replaced by lookup tables and selects. |
13 | // |
14 | //===----------------------------------------------------------------------===// |
15 | |
16 | #ifndef LLVM_TRANSFORMS_UTILS_SIMPLIFYCFGOPTIONS_H |
17 | #define LLVM_TRANSFORMS_UTILS_SIMPLIFYCFGOPTIONS_H |
18 | |
19 | namespace llvm { |
20 | |
21 | class AssumptionCache; |
22 | |
23 | struct SimplifyCFGOptions { |
24 | int BonusInstThreshold = 1; |
25 | bool ForwardSwitchCondToPhi = false; |
26 | bool ConvertSwitchRangeToICmp = false; |
27 | bool ConvertSwitchToLookupTable = false; |
28 | bool NeedCanonicalLoop = true; |
29 | bool HoistCommonInsts = false; |
30 | bool SinkCommonInsts = false; |
31 | bool SimplifyCondBranch = true; |
32 | bool SpeculateBlocks = true; |
33 | |
34 | AssumptionCache *AC = nullptr; |
35 | |
36 | // Support 'builder' pattern to set members by name at construction time. |
37 | SimplifyCFGOptions &bonusInstThreshold(int I) { |
38 | BonusInstThreshold = I; |
39 | return *this; |
40 | } |
41 | SimplifyCFGOptions &forwardSwitchCondToPhi(bool B) { |
42 | ForwardSwitchCondToPhi = B; |
43 | return *this; |
44 | } |
45 | SimplifyCFGOptions &convertSwitchRangeToICmp(bool B) { |
46 | ConvertSwitchRangeToICmp = B; |
47 | return *this; |
48 | } |
49 | SimplifyCFGOptions &convertSwitchToLookupTable(bool B) { |
50 | ConvertSwitchToLookupTable = B; |
51 | return *this; |
52 | } |
53 | SimplifyCFGOptions &needCanonicalLoops(bool B) { |
54 | NeedCanonicalLoop = B; |
55 | return *this; |
56 | } |
57 | SimplifyCFGOptions &hoistCommonInsts(bool B) { |
58 | HoistCommonInsts = B; |
59 | return *this; |
60 | } |
61 | SimplifyCFGOptions &sinkCommonInsts(bool B) { |
62 | SinkCommonInsts = B; |
63 | return *this; |
64 | } |
65 | SimplifyCFGOptions &setAssumptionCache(AssumptionCache *Cache) { |
66 | AC = Cache; |
67 | return *this; |
68 | } |
69 | SimplifyCFGOptions &setSimplifyCondBranch(bool B) { |
70 | SimplifyCondBranch = B; |
71 | return *this; |
72 | } |
73 | |
74 | SimplifyCFGOptions &speculateBlocks(bool B) { |
75 | SpeculateBlocks = B; |
76 | return *this; |
77 | } |
78 | }; |
79 | |
80 | } // namespace llvm |
81 | |
82 | #endif // LLVM_TRANSFORMS_UTILS_SIMPLIFYCFGOPTIONS_H |
83 | |