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   bool SpeculateUnpredictables = false;
34 
35   AssumptionCache *AC = nullptr;
36 
37   // Support 'builder' pattern to set members by name at construction time.
bonusInstThresholdSimplifyCFGOptions38   SimplifyCFGOptions &bonusInstThreshold(int I) {
39     BonusInstThreshold = I;
40     return *this;
41   }
forwardSwitchCondToPhiSimplifyCFGOptions42   SimplifyCFGOptions &forwardSwitchCondToPhi(bool B) {
43     ForwardSwitchCondToPhi = B;
44     return *this;
45   }
convertSwitchRangeToICmpSimplifyCFGOptions46   SimplifyCFGOptions &convertSwitchRangeToICmp(bool B) {
47     ConvertSwitchRangeToICmp = B;
48     return *this;
49   }
convertSwitchToLookupTableSimplifyCFGOptions50   SimplifyCFGOptions &convertSwitchToLookupTable(bool B) {
51     ConvertSwitchToLookupTable = B;
52     return *this;
53   }
needCanonicalLoopsSimplifyCFGOptions54   SimplifyCFGOptions &needCanonicalLoops(bool B) {
55     NeedCanonicalLoop = B;
56     return *this;
57   }
hoistCommonInstsSimplifyCFGOptions58   SimplifyCFGOptions &hoistCommonInsts(bool B) {
59     HoistCommonInsts = B;
60     return *this;
61   }
sinkCommonInstsSimplifyCFGOptions62   SimplifyCFGOptions &sinkCommonInsts(bool B) {
63     SinkCommonInsts = B;
64     return *this;
65   }
setAssumptionCacheSimplifyCFGOptions66   SimplifyCFGOptions &setAssumptionCache(AssumptionCache *Cache) {
67     AC = Cache;
68     return *this;
69   }
setSimplifyCondBranchSimplifyCFGOptions70   SimplifyCFGOptions &setSimplifyCondBranch(bool B) {
71     SimplifyCondBranch = B;
72     return *this;
73   }
74 
speculateBlocksSimplifyCFGOptions75   SimplifyCFGOptions &speculateBlocks(bool B) {
76     SpeculateBlocks = B;
77     return *this;
78   }
speculateUnpredictablesSimplifyCFGOptions79   SimplifyCFGOptions &speculateUnpredictables(bool B) {
80     SpeculateUnpredictables = B;
81     return *this;
82   }
83 };
84 
85 } // namespace llvm
86 
87 #endif // LLVM_TRANSFORMS_UTILS_SIMPLIFYCFGOPTIONS_H
88