[llvm] af19b1c - [NFCI] CFGSimplifyPass: change (the only) constructor to take SimplifyCFGOptions

Roman Lebedev via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 15 15:28:15 PDT 2020


Author: Roman Lebedev
Date: 2020-07-16T01:27:53+03:00
New Revision: af19b1ceefce48534c138e223ba7cb1bfc9a02f8

URL: https://github.com/llvm/llvm-project/commit/af19b1ceefce48534c138e223ba7cb1bfc9a02f8
DIFF: https://github.com/llvm/llvm-project/commit/af19b1ceefce48534c138e223ba7cb1bfc9a02f8.diff

LOG: [NFCI] CFGSimplifyPass: change (the only) constructor to take SimplifyCFGOptions

Taking that long list of parameters is already simply unmaintainable.

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp b/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp
index 2e459c9a64d4..4187d5b55adf 100644
--- a/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp
+++ b/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp
@@ -247,33 +247,27 @@ struct CFGSimplifyPass : public FunctionPass {
   SimplifyCFGOptions Options;
   std::function<bool(const Function &)> PredicateFtor;
 
-  CFGSimplifyPass(unsigned Threshold = 1, bool ForwardSwitchCond = false,
-                  bool ConvertSwitch = false, bool KeepLoops = true,
-                  bool SinkCommon = false,
+  CFGSimplifyPass(SimplifyCFGOptions Options_ = SimplifyCFGOptions(),
                   std::function<bool(const Function &)> Ftor = nullptr)
-      : FunctionPass(ID), PredicateFtor(std::move(Ftor)) {
+      : FunctionPass(ID), Options(Options_), PredicateFtor(std::move(Ftor)) {
 
     initializeCFGSimplifyPassPass(*PassRegistry::getPassRegistry());
 
     // Check for command-line overrides of options for debug/customization.
-    Options.BonusInstThreshold = UserBonusInstThreshold.getNumOccurrences()
-                                    ? UserBonusInstThreshold
-                                    : Threshold;
+    if (UserBonusInstThreshold.getNumOccurrences())
+      Options.BonusInstThreshold = UserBonusInstThreshold;
 
-    Options.ForwardSwitchCondToPhi = UserForwardSwitchCond.getNumOccurrences()
-                                         ? UserForwardSwitchCond
-                                         : ForwardSwitchCond;
+    if (UserForwardSwitchCond.getNumOccurrences())
+      Options.ForwardSwitchCondToPhi = UserForwardSwitchCond;
 
-    Options.ConvertSwitchToLookupTable = UserSwitchToLookup.getNumOccurrences()
-                                             ? UserSwitchToLookup
-                                             : ConvertSwitch;
+    if (UserSwitchToLookup.getNumOccurrences())
+      Options.ConvertSwitchToLookupTable = UserSwitchToLookup;
 
-    Options.NeedCanonicalLoop =
-        UserKeepLoops.getNumOccurrences() ? UserKeepLoops : KeepLoops;
+    if (UserKeepLoops.getNumOccurrences())
+      Options.NeedCanonicalLoop = UserKeepLoops;
 
-    Options.SinkCommonInsts = UserSinkCommonInsts.getNumOccurrences()
-                                  ? UserSinkCommonInsts
-                                  : SinkCommon;
+    if (UserSinkCommonInsts.getNumOccurrences())
+      Options.SinkCommonInsts = UserSinkCommonInsts;
   }
 
   bool runOnFunction(Function &F) override {
@@ -314,6 +308,11 @@ llvm::createCFGSimplificationPass(unsigned Threshold, bool ForwardSwitchCond,
                                   bool ConvertSwitch, bool KeepLoops,
                                   bool SinkCommon,
                                   std::function<bool(const Function &)> Ftor) {
-  return new CFGSimplifyPass(Threshold, ForwardSwitchCond, ConvertSwitch,
-                             KeepLoops, SinkCommon, std::move(Ftor));
+  return new CFGSimplifyPass(SimplifyCFGOptions()
+                                 .bonusInstThreshold(Threshold)
+                                 .forwardSwitchCondToPhi(ForwardSwitchCond)
+                                 .convertSwitchToLookupTable(ConvertSwitch)
+                                 .needCanonicalLoops(KeepLoops)
+                                 .sinkCommonInsts(SinkCommon),
+                             std::move(Ftor));
 }


        


More information about the llvm-commits mailing list