|
30 | 30 | #include "llvm/IR/Value.h"
|
31 | 31 | #include "llvm/IR/ValueHandle.h"
|
32 | 32 | #include "llvm/Support/Casting.h"
|
33 |
| -#include "llvm/Transforms/Scalar/SimplifyCFGOptions.h" |
34 | 33 | #include <cstdint>
|
35 | 34 | #include <limits>
|
36 | 35 |
|
@@ -59,6 +58,73 @@ class StoreInst;
|
59 | 58 | class TargetLibraryInfo;
|
60 | 59 | class TargetTransformInfo;
|
61 | 60 |
|
| 61 | +/// A set of parameters used to control the transforms in the SimplifyCFG pass. |
| 62 | +/// Options may change depending on the position in the optimization pipeline. |
| 63 | +/// For example, canonical form that includes switches and branches may later be |
| 64 | +/// replaced by lookup tables and selects. |
| 65 | +struct SimplifyCFGOptions { |
| 66 | + int BonusInstThreshold; |
| 67 | + bool ForwardSwitchCondToPhi; |
| 68 | + bool ConvertSwitchToLookupTable; |
| 69 | + bool NeedCanonicalLoop; |
| 70 | + bool SinkCommonInsts; |
| 71 | + bool SimplifyCondBranch; |
| 72 | + bool FoldTwoEntryPHINode; |
| 73 | + |
| 74 | + AssumptionCache *AC; |
| 75 | + |
| 76 | + SimplifyCFGOptions(unsigned BonusThreshold = 1, |
| 77 | + bool ForwardSwitchCond = false, |
| 78 | + bool SwitchToLookup = false, bool CanonicalLoops = true, |
| 79 | + bool SinkCommon = false, |
| 80 | + AssumptionCache *AssumpCache = nullptr, |
| 81 | + bool SimplifyCondBranch = true, |
| 82 | + bool FoldTwoEntryPHINode = true) |
| 83 | + : BonusInstThreshold(BonusThreshold), |
| 84 | + ForwardSwitchCondToPhi(ForwardSwitchCond), |
| 85 | + ConvertSwitchToLookupTable(SwitchToLookup), |
| 86 | + NeedCanonicalLoop(CanonicalLoops), |
| 87 | + SinkCommonInsts(SinkCommon), |
| 88 | + SimplifyCondBranch(SimplifyCondBranch), |
| 89 | + FoldTwoEntryPHINode(FoldTwoEntryPHINode), |
| 90 | + AC(AssumpCache) {} |
| 91 | + |
| 92 | + // Support 'builder' pattern to set members by name at construction time. |
| 93 | + SimplifyCFGOptions &bonusInstThreshold(int I) { |
| 94 | + BonusInstThreshold = I; |
| 95 | + return *this; |
| 96 | + } |
| 97 | + SimplifyCFGOptions &forwardSwitchCondToPhi(bool B) { |
| 98 | + ForwardSwitchCondToPhi = B; |
| 99 | + return *this; |
| 100 | + } |
| 101 | + SimplifyCFGOptions &convertSwitchToLookupTable(bool B) { |
| 102 | + ConvertSwitchToLookupTable = B; |
| 103 | + return *this; |
| 104 | + } |
| 105 | + SimplifyCFGOptions &needCanonicalLoops(bool B) { |
| 106 | + NeedCanonicalLoop = B; |
| 107 | + return *this; |
| 108 | + } |
| 109 | + SimplifyCFGOptions &sinkCommonInsts(bool B) { |
| 110 | + SinkCommonInsts = B; |
| 111 | + return *this; |
| 112 | + } |
| 113 | + SimplifyCFGOptions &setAssumptionCache(AssumptionCache *Cache) { |
| 114 | + AC = Cache; |
| 115 | + return *this; |
| 116 | + } |
| 117 | + SimplifyCFGOptions &setSimplifyCondBranch(bool B) { |
| 118 | + SimplifyCondBranch = B; |
| 119 | + return *this; |
| 120 | + } |
| 121 | + |
| 122 | + SimplifyCFGOptions &setFoldTwoEntryPHINode(bool B) { |
| 123 | + FoldTwoEntryPHINode = B; |
| 124 | + return *this; |
| 125 | + } |
| 126 | +}; |
| 127 | + |
62 | 128 | //===----------------------------------------------------------------------===//
|
63 | 129 | // Local constant propagation.
|
64 | 130 | //
|
|
0 commit comments