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 ConvertSwitchToLookupTable = false; 27 bool NeedCanonicalLoop = true; 28 bool HoistCommonInsts = false; 29 bool SinkCommonInsts = false; 30 bool SimplifyCondBranch = true; 31 bool FoldTwoEntryPHINode = true; 32 33 AssumptionCache *AC = nullptr; 34 35 // Support 'builder' pattern to set members by name at construction time. bonusInstThresholdSimplifyCFGOptions36 SimplifyCFGOptions &bonusInstThreshold(int I) { 37 BonusInstThreshold = I; 38 return *this; 39 } forwardSwitchCondToPhiSimplifyCFGOptions40 SimplifyCFGOptions &forwardSwitchCondToPhi(bool B) { 41 ForwardSwitchCondToPhi = B; 42 return *this; 43 } convertSwitchToLookupTableSimplifyCFGOptions44 SimplifyCFGOptions &convertSwitchToLookupTable(bool B) { 45 ConvertSwitchToLookupTable = B; 46 return *this; 47 } needCanonicalLoopsSimplifyCFGOptions48 SimplifyCFGOptions &needCanonicalLoops(bool B) { 49 NeedCanonicalLoop = B; 50 return *this; 51 } hoistCommonInstsSimplifyCFGOptions52 SimplifyCFGOptions &hoistCommonInsts(bool B) { 53 HoistCommonInsts = B; 54 return *this; 55 } sinkCommonInstsSimplifyCFGOptions56 SimplifyCFGOptions &sinkCommonInsts(bool B) { 57 SinkCommonInsts = B; 58 return *this; 59 } setAssumptionCacheSimplifyCFGOptions60 SimplifyCFGOptions &setAssumptionCache(AssumptionCache *Cache) { 61 AC = Cache; 62 return *this; 63 } setSimplifyCondBranchSimplifyCFGOptions64 SimplifyCFGOptions &setSimplifyCondBranch(bool B) { 65 SimplifyCondBranch = B; 66 return *this; 67 } 68 setFoldTwoEntryPHINodeSimplifyCFGOptions69 SimplifyCFGOptions &setFoldTwoEntryPHINode(bool B) { 70 FoldTwoEntryPHINode = B; 71 return *this; 72 } 73 }; 74 75 } // namespace llvm 76 77 #endif // LLVM_TRANSFORMS_UTILS_SIMPLIFYCFGOPTIONS_H 78