xref: /llvm-project/llvm/include/llvm/Transforms/Utils/SimplifyCFGOptions.h (revision 87c86aa6b93aea3d1603c1759a17fb6b5ba6e814)
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 HoistLoadsStoresWithCondFaulting = false;
31   bool SinkCommonInsts = false;
32   bool SimplifyCondBranch = true;
33   bool SpeculateBlocks = true;
34   bool SpeculateUnpredictables = false;
35 
36   AssumptionCache *AC = nullptr;
37 
38   // Support 'builder' pattern to set members by name at construction time.
39   SimplifyCFGOptions &bonusInstThreshold(int I) {
40     BonusInstThreshold = I;
41     return *this;
42   }
43   SimplifyCFGOptions &forwardSwitchCondToPhi(bool B) {
44     ForwardSwitchCondToPhi = B;
45     return *this;
46   }
47   SimplifyCFGOptions &convertSwitchRangeToICmp(bool B) {
48     ConvertSwitchRangeToICmp = B;
49     return *this;
50   }
51   SimplifyCFGOptions &convertSwitchToLookupTable(bool B) {
52     ConvertSwitchToLookupTable = B;
53     return *this;
54   }
55   SimplifyCFGOptions &needCanonicalLoops(bool B) {
56     NeedCanonicalLoop = B;
57     return *this;
58   }
59   SimplifyCFGOptions &hoistCommonInsts(bool B) {
60     HoistCommonInsts = B;
61     return *this;
62   }
63   SimplifyCFGOptions &hoistLoadsStoresWithCondFaulting(bool B) {
64     HoistLoadsStoresWithCondFaulting = B;
65     return *this;
66   }
67   SimplifyCFGOptions &sinkCommonInsts(bool B) {
68     SinkCommonInsts = B;
69     return *this;
70   }
71   SimplifyCFGOptions &setAssumptionCache(AssumptionCache *Cache) {
72     AC = Cache;
73     return *this;
74   }
75   SimplifyCFGOptions &setSimplifyCondBranch(bool B) {
76     SimplifyCondBranch = B;
77     return *this;
78   }
79 
80   SimplifyCFGOptions &speculateBlocks(bool B) {
81     SpeculateBlocks = B;
82     return *this;
83   }
84   SimplifyCFGOptions &speculateUnpredictables(bool B) {
85     SpeculateUnpredictables = B;
86     return *this;
87   }
88 };
89 
90 } // namespace llvm
91 
92 #endif // LLVM_TRANSFORMS_UTILS_SIMPLIFYCFGOPTIONS_H
93