|
| 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_SCALAR_SIMPLIFYCFGOPTIONS_H |
| 17 | +#define LLVM_TRANSFORMS_SCALAR_SIMPLIFYCFGOPTIONS_H |
| 18 | + |
| 19 | +namespace llvm { |
| 20 | + |
| 21 | +class AssumptionCache; |
| 22 | + |
| 23 | +struct SimplifyCFGOptions { |
| 24 | + int BonusInstThreshold; |
| 25 | + bool ForwardSwitchCondToPhi; |
| 26 | + bool ConvertSwitchToLookupTable; |
| 27 | + bool NeedCanonicalLoop; |
| 28 | + bool SinkCommonInsts; |
| 29 | + bool SimplifyCondBranch; |
| 30 | + bool FoldTwoEntryPHINode; |
| 31 | + |
| 32 | + AssumptionCache *AC; |
| 33 | + |
| 34 | + SimplifyCFGOptions(unsigned BonusThreshold = 1, |
| 35 | + bool ForwardSwitchCond = false, |
| 36 | + bool SwitchToLookup = false, bool CanonicalLoops = true, |
| 37 | + bool SinkCommon = false, |
| 38 | + AssumptionCache *AssumpCache = nullptr, |
| 39 | + bool SimplifyCondBranch = true, |
| 40 | + bool FoldTwoEntryPHINode = true) |
| 41 | + : BonusInstThreshold(BonusThreshold), |
| 42 | + ForwardSwitchCondToPhi(ForwardSwitchCond), |
| 43 | + ConvertSwitchToLookupTable(SwitchToLookup), |
| 44 | + NeedCanonicalLoop(CanonicalLoops), SinkCommonInsts(SinkCommon), |
| 45 | + SimplifyCondBranch(SimplifyCondBranch), |
| 46 | + FoldTwoEntryPHINode(FoldTwoEntryPHINode), AC(AssumpCache) {} |
| 47 | + |
| 48 | + // Support 'builder' pattern to set members by name at construction time. |
| 49 | + SimplifyCFGOptions &bonusInstThreshold(int I) { |
| 50 | + BonusInstThreshold = I; |
| 51 | + return *this; |
| 52 | + } |
| 53 | + SimplifyCFGOptions &forwardSwitchCondToPhi(bool B) { |
| 54 | + ForwardSwitchCondToPhi = B; |
| 55 | + return *this; |
| 56 | + } |
| 57 | + SimplifyCFGOptions &convertSwitchToLookupTable(bool B) { |
| 58 | + ConvertSwitchToLookupTable = B; |
| 59 | + return *this; |
| 60 | + } |
| 61 | + SimplifyCFGOptions &needCanonicalLoops(bool B) { |
| 62 | + NeedCanonicalLoop = B; |
| 63 | + return *this; |
| 64 | + } |
| 65 | + SimplifyCFGOptions &sinkCommonInsts(bool B) { |
| 66 | + SinkCommonInsts = B; |
| 67 | + return *this; |
| 68 | + } |
| 69 | + SimplifyCFGOptions &setAssumptionCache(AssumptionCache *Cache) { |
| 70 | + AC = Cache; |
| 71 | + return *this; |
| 72 | + } |
| 73 | + SimplifyCFGOptions &setSimplifyCondBranch(bool B) { |
| 74 | + SimplifyCondBranch = B; |
| 75 | + return *this; |
| 76 | + } |
| 77 | + |
| 78 | + SimplifyCFGOptions &setFoldTwoEntryPHINode(bool B) { |
| 79 | + FoldTwoEntryPHINode = B; |
| 80 | + return *this; |
| 81 | + } |
| 82 | +}; |
| 83 | + |
| 84 | +} // namespace llvm |
| 85 | + |
| 86 | +#endif // LLVM_TRANSFORMS_SCALAR_SIMPLIFYCFGOPTIONS_H |
0 commit comments