[llvm] 30f6c08 - Reland "[NFC] SimplifyCFG: refactor/deduplicate command-line settings override handling"

Roman Lebedev via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 16 05:25:56 PDT 2020


Author: Roman Lebedev
Date: 2020-07-16T15:25:11+03:00
New Revision: 30f6c08ba3ba98921768073bf349cfcc8096ed6c

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

LOG: Reland "[NFC] SimplifyCFG: refactor/deduplicate command-line settings override handling"

Initially i forgot to stage the SimplifyCFGPass::SimplifyCFGPass() change
to actually take the passed params..

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 d48d5408dd3c..99055b991805 100644
--- a/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp
+++ b/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp
@@ -213,22 +213,22 @@ static bool simplifyFunctionCFG(Function &F, const TargetTransformInfo &TTI,
 }
 
 // Command-line settings override compile-time settings.
-SimplifyCFGPass::SimplifyCFGPass(const SimplifyCFGOptions &Opts) {
-  Options.BonusInstThreshold = UserBonusInstThreshold.getNumOccurrences()
-                                   ? UserBonusInstThreshold
-                                   : Opts.BonusInstThreshold;
-  Options.ForwardSwitchCondToPhi = UserForwardSwitchCond.getNumOccurrences()
-                                       ? UserForwardSwitchCond
-                                       : Opts.ForwardSwitchCondToPhi;
-  Options.ConvertSwitchToLookupTable = UserSwitchToLookup.getNumOccurrences()
-                                           ? UserSwitchToLookup
-                                           : Opts.ConvertSwitchToLookupTable;
-  Options.NeedCanonicalLoop = UserKeepLoops.getNumOccurrences()
-                                  ? UserKeepLoops
-                                  : Opts.NeedCanonicalLoop;
-  Options.SinkCommonInsts = UserSinkCommonInsts.getNumOccurrences()
-                                ? UserSinkCommonInsts
-                                : Opts.SinkCommonInsts;
+static void applyCommandLineOverridesToOptions(SimplifyCFGOptions &Options) {
+  if (UserBonusInstThreshold.getNumOccurrences())
+    Options.BonusInstThreshold = UserBonusInstThreshold;
+  if (UserForwardSwitchCond.getNumOccurrences())
+    Options.ForwardSwitchCondToPhi = UserForwardSwitchCond;
+  if (UserSwitchToLookup.getNumOccurrences())
+    Options.ConvertSwitchToLookupTable = UserSwitchToLookup;
+  if (UserKeepLoops.getNumOccurrences())
+    Options.NeedCanonicalLoop = UserKeepLoops;
+  if (UserSinkCommonInsts.getNumOccurrences())
+    Options.SinkCommonInsts = UserSinkCommonInsts;
+}
+
+SimplifyCFGPass::SimplifyCFGPass(const SimplifyCFGOptions &Opts)
+    : Options(Opts) {
+  applyCommandLineOverridesToOptions(Options);
 }
 
 PreservedAnalyses SimplifyCFGPass::run(Function &F,
@@ -255,20 +255,7 @@ struct CFGSimplifyPass : public FunctionPass {
     initializeCFGSimplifyPassPass(*PassRegistry::getPassRegistry());
 
     // Check for command-line overrides of options for debug/customization.
-    if (UserBonusInstThreshold.getNumOccurrences())
-      Options.BonusInstThreshold = UserBonusInstThreshold;
-
-    if (UserForwardSwitchCond.getNumOccurrences())
-      Options.ForwardSwitchCondToPhi = UserForwardSwitchCond;
-
-    if (UserSwitchToLookup.getNumOccurrences())
-      Options.ConvertSwitchToLookupTable = UserSwitchToLookup;
-
-    if (UserKeepLoops.getNumOccurrences())
-      Options.NeedCanonicalLoop = UserKeepLoops;
-
-    if (UserSinkCommonInsts.getNumOccurrences())
-      Options.SinkCommonInsts = UserSinkCommonInsts;
+    applyCommandLineOverridesToOptions(Options);
   }
 
   bool runOnFunction(Function &F) override {


        


More information about the llvm-commits mailing list