llvm.org GIT mirror llvm / 08cb195
[NewPassManager] Add tuning option: ForgetAllSCEVInLoopUnroll [NFC]. Summary: Mirror tuning option from old pass manager in new pass manager. Reviewers: chandlerc Subscribers: mehdi_amini, jlebar, zzheng, dmgreen, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D61612 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@361560 91177308-0d34-0410-b5e6-96231b3b80d8 Alina Sbirlea 5 months ago
5 changed file(s) with 38 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
8686
8787 /// Tuning option to enable/disable loop unrolling. Its default value is true.
8888 bool LoopUnrolling;
89
90 /// Tuning option to forget all SCEV loops in LoopUnroll. Its default value
91 /// is that of the flag: `-forget-scev-loop-unroll`.
92 bool ForgetAllSCEVInLoopUnroll;
8993
9094 /// Tuning option to cap the number of calls to retrive clobbering accesses in
9195 /// MemorySSA, in LICM.
1414
1515 namespace llvm {
1616
17 extern cl::opt ForgetSCEVInLoopUnroll;
18
1719 class Function;
1820 class Loop;
1921 class LPMUpdater;
2729 /// metadata are considered. All other loops are skipped.
2830 const bool OnlyWhenForced;
2931
32 /// If true, forget all loops when unrolling. If false, forget top-most loop
33 /// of the currently processed loops, which removes one entry at a time from
34 /// the internal SCEV records. For large loops, the former is faster.
35 const bool ForgetSCEV;
36
3037 public:
31 explicit LoopFullUnrollPass(int OptLevel = 2, bool OnlyWhenForced = false)
32 : OptLevel(OptLevel), OnlyWhenForced(OnlyWhenForced) {}
38 explicit LoopFullUnrollPass(int OptLevel = 2, bool OnlyWhenForced = false,
39 bool ForgetSCEV = false)
40 : OptLevel(OptLevel), OnlyWhenForced(OnlyWhenForced),
41 ForgetSCEV(ForgetSCEV) {}
3342
3443 PreservedAnalyses run(Loop &L, LoopAnalysisManager &AM,
3544 LoopStandardAnalysisResults &AR, LPMUpdater &U);
5968 /// metadata are considered. All other loops are skipped.
6069 bool OnlyWhenForced;
6170
62 LoopUnrollOptions(int OptLevel = 2, bool OnlyWhenForced = false)
63 : OptLevel(OptLevel), OnlyWhenForced(OnlyWhenForced) {}
71 /// If true, forget all loops when unrolling. If false, forget top-most loop
72 /// of the currently processed loops, which removes one entry at a time from
73 /// the internal SCEV records. For large loops, the former is faster.
74 const bool ForgetSCEV;
75
76 LoopUnrollOptions(int OptLevel = 2, bool OnlyWhenForced = false,
77 bool ForgetSCEV = false)
78 : OptLevel(OptLevel), OnlyWhenForced(OnlyWhenForced),
79 ForgetSCEV(ForgetSCEV) {}
6480
6581 /// Enables or disables partial unrolling. When disabled only full unrolling
6682 /// is allowed.
217217 LoopVectorization = EnableLoopVectorization;
218218 SLPVectorization = RunSLPVectorization;
219219 LoopUnrolling = true;
220 ForgetAllSCEVInLoopUnroll = ForgetSCEVInLoopUnroll;
220221 LicmMssaOptCap = SetLicmMssaOptCap;
221222 LicmMssaNoAccForPromotionCap = SetLicmMssaNoAccForPromotionCap;
222223 }
462463 if ((Phase != ThinLTOPhase::PreLink || !PGOOpt ||
463464 PGOOpt->Action != PGOOptions::SampleUse) &&
464465 PTO.LoopUnrolling)
465 LPM2.addPass(LoopFullUnrollPass(Level));
466 LPM2.addPass(
467 LoopFullUnrollPass(Level, false, PTO.ForgetAllSCEVInLoopUnroll));
466468
467469 for (auto &C : LoopOptimizerEndEPCallbacks)
468470 C(LPM2, Level);
909911 createFunctionToLoopPassAdaptor(LoopUnrollAndJamPass(Level)));
910912 }
911913 if (PTO.LoopUnrolling)
912 OptimizePM.addPass(LoopUnrollPass(LoopUnrollOptions(Level)));
914 OptimizePM.addPass(LoopUnrollPass(
915 LoopUnrollOptions(Level, false, PTO.ForgetAllSCEVInLoopUnroll)));
913916 OptimizePM.addPass(WarnMissedTransformationsPass());
914917 OptimizePM.addPass(InstCombinePass());
915918 OptimizePM.addPass(RequireAnalysisPass());
3838 #include "llvm/Transforms/Scalar/GVN.h"
3939 #include "llvm/Transforms/Scalar/InstSimplifyPass.h"
4040 #include "llvm/Transforms/Scalar/LICM.h"
41 #include "llvm/Transforms/Scalar/LoopUnrollPass.h"
4142 #include "llvm/Transforms/Scalar/SimpleLoopUnswitch.h"
4243 #include "llvm/Transforms/Utils.h"
4344 #include "llvm/Transforms/Vectorize.h"
143144 cl::opt EnableOrderFileInstrumentation(
144145 "enable-order-file-instrumentation", cl::init(false), cl::Hidden,
145146 cl::desc("Enable order file instrumentation (default = off)"));
146
147 cl::opt ForgetSCEVInLoopUnroll(
148 "forget-scev-loop-unroll", cl::init(false), cl::Hidden,
149 cl::desc("Forget everything in SCEV when doing LoopUnroll, instead of just"
150 " the current top-most loop. This is somtimes preferred to reduce"
151 " compile time."));
152147
153148 PassManagerBuilder::PassManagerBuilder() {
154149 OptLevel = 2;
6969 using namespace llvm;
7070
7171 #define DEBUG_TYPE "loop-unroll"
72
73 cl::opt llvm::ForgetSCEVInLoopUnroll(
74 "forget-scev-loop-unroll", cl::init(false), cl::Hidden,
75 cl::desc("Forget everything in SCEV when doing LoopUnroll, instead of just"
76 " the current top-most loop. This is somtimes preferred to reduce"
77 " compile time."));
7278
7379 static cl::opt
7480 UnrollThreshold("unroll-threshold", cl::Hidden,
12801286 tryToUnrollLoop(&L, AR.DT, &AR.LI, AR.SE, AR.TTI, AR.AC, *ORE,
12811287 /*BFI*/ nullptr, /*PSI*/ nullptr,
12821288 /*PreserveLCSSA*/ true, OptLevel, OnlyWhenForced,
1283 /*ForgetAllSCEV*/ false, /*Count*/ None,
1289 ForgetSCEV, /*Count*/ None,
12841290 /*Threshold*/ None, /*AllowPartial*/ false,
12851291 /*Runtime*/ false, /*UpperBound*/ false,
12861292 /*AllowPeeling*/ false) != LoopUnrollResult::Unmodified;
14211427 LoopUnrollResult Result = tryToUnrollLoop(
14221428 &L, DT, &LI, SE, TTI, AC, ORE, BFI, PSI,
14231429 /*PreserveLCSSA*/ true, UnrollOpts.OptLevel, UnrollOpts.OnlyWhenForced,
1424 /*ForgetAllSCEV*/ false, /*Count*/ None,
1430 UnrollOpts.ForgetSCEV, /*Count*/ None,
14251431 /*Threshold*/ None, UnrollOpts.AllowPartial, UnrollOpts.AllowRuntime,
14261432 UnrollOpts.AllowUpperBound, LocalAllowPeeling);
14271433 Changed |= Result != LoopUnrollResult::Unmodified;