forked from OSchip/llvm-project
[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 llvm-svn: 361560
This commit is contained in:
parent
e60cb7d1be
commit
d82ddfa7c3
|
@ -88,6 +88,10 @@ public:
|
|||
/// Tuning option to enable/disable loop unrolling. Its default value is true.
|
||||
bool LoopUnrolling;
|
||||
|
||||
/// Tuning option to forget all SCEV loops in LoopUnroll. Its default value
|
||||
/// is that of the flag: `-forget-scev-loop-unroll`.
|
||||
bool ForgetAllSCEVInLoopUnroll;
|
||||
|
||||
/// Tuning option to cap the number of calls to retrive clobbering accesses in
|
||||
/// MemorySSA, in LICM.
|
||||
unsigned LicmMssaOptCap;
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
|
||||
namespace llvm {
|
||||
|
||||
extern cl::opt<bool> ForgetSCEVInLoopUnroll;
|
||||
|
||||
class Function;
|
||||
class Loop;
|
||||
class LPMUpdater;
|
||||
|
@ -28,9 +30,16 @@ class LoopFullUnrollPass : public PassInfoMixin<LoopFullUnrollPass> {
|
|||
/// metadata are considered. All other loops are skipped.
|
||||
const bool OnlyWhenForced;
|
||||
|
||||
/// If true, forget all loops when unrolling. If false, forget top-most loop
|
||||
/// of the currently processed loops, which removes one entry at a time from
|
||||
/// the internal SCEV records. For large loops, the former is faster.
|
||||
const bool ForgetSCEV;
|
||||
|
||||
public:
|
||||
explicit LoopFullUnrollPass(int OptLevel = 2, bool OnlyWhenForced = false)
|
||||
: OptLevel(OptLevel), OnlyWhenForced(OnlyWhenForced) {}
|
||||
explicit LoopFullUnrollPass(int OptLevel = 2, bool OnlyWhenForced = false,
|
||||
bool ForgetSCEV = false)
|
||||
: OptLevel(OptLevel), OnlyWhenForced(OnlyWhenForced),
|
||||
ForgetSCEV(ForgetSCEV) {}
|
||||
|
||||
PreservedAnalyses run(Loop &L, LoopAnalysisManager &AM,
|
||||
LoopStandardAnalysisResults &AR, LPMUpdater &U);
|
||||
|
@ -60,8 +69,15 @@ struct LoopUnrollOptions {
|
|||
/// metadata are considered. All other loops are skipped.
|
||||
bool OnlyWhenForced;
|
||||
|
||||
LoopUnrollOptions(int OptLevel = 2, bool OnlyWhenForced = false)
|
||||
: OptLevel(OptLevel), OnlyWhenForced(OnlyWhenForced) {}
|
||||
/// If true, forget all loops when unrolling. If false, forget top-most loop
|
||||
/// of the currently processed loops, which removes one entry at a time from
|
||||
/// the internal SCEV records. For large loops, the former is faster.
|
||||
const bool ForgetSCEV;
|
||||
|
||||
LoopUnrollOptions(int OptLevel = 2, bool OnlyWhenForced = false,
|
||||
bool ForgetSCEV = false)
|
||||
: OptLevel(OptLevel), OnlyWhenForced(OnlyWhenForced),
|
||||
ForgetSCEV(ForgetSCEV) {}
|
||||
|
||||
/// Enables or disables partial unrolling. When disabled only full unrolling
|
||||
/// is allowed.
|
||||
|
|
|
@ -218,6 +218,7 @@ PipelineTuningOptions::PipelineTuningOptions() {
|
|||
LoopVectorization = EnableLoopVectorization;
|
||||
SLPVectorization = RunSLPVectorization;
|
||||
LoopUnrolling = true;
|
||||
ForgetAllSCEVInLoopUnroll = ForgetSCEVInLoopUnroll;
|
||||
LicmMssaOptCap = SetLicmMssaOptCap;
|
||||
LicmMssaNoAccForPromotionCap = SetLicmMssaNoAccForPromotionCap;
|
||||
}
|
||||
|
@ -463,7 +464,8 @@ PassBuilder::buildFunctionSimplificationPipeline(OptimizationLevel Level,
|
|||
if ((Phase != ThinLTOPhase::PreLink || !PGOOpt ||
|
||||
PGOOpt->Action != PGOOptions::SampleUse) &&
|
||||
PTO.LoopUnrolling)
|
||||
LPM2.addPass(LoopFullUnrollPass(Level));
|
||||
LPM2.addPass(
|
||||
LoopFullUnrollPass(Level, false, PTO.ForgetAllSCEVInLoopUnroll));
|
||||
|
||||
for (auto &C : LoopOptimizerEndEPCallbacks)
|
||||
C(LPM2, Level);
|
||||
|
@ -910,7 +912,8 @@ ModulePassManager PassBuilder::buildModuleOptimizationPipeline(
|
|||
createFunctionToLoopPassAdaptor(LoopUnrollAndJamPass(Level)));
|
||||
}
|
||||
if (PTO.LoopUnrolling)
|
||||
OptimizePM.addPass(LoopUnrollPass(LoopUnrollOptions(Level)));
|
||||
OptimizePM.addPass(LoopUnrollPass(
|
||||
LoopUnrollOptions(Level, false, PTO.ForgetAllSCEVInLoopUnroll)));
|
||||
OptimizePM.addPass(WarnMissedTransformationsPass());
|
||||
OptimizePM.addPass(InstCombinePass());
|
||||
OptimizePM.addPass(RequireAnalysisPass<OptimizationRemarkEmitterAnalysis, Function>());
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
#include "llvm/Transforms/Scalar/GVN.h"
|
||||
#include "llvm/Transforms/Scalar/InstSimplifyPass.h"
|
||||
#include "llvm/Transforms/Scalar/LICM.h"
|
||||
#include "llvm/Transforms/Scalar/LoopUnrollPass.h"
|
||||
#include "llvm/Transforms/Scalar/SimpleLoopUnswitch.h"
|
||||
#include "llvm/Transforms/Utils.h"
|
||||
#include "llvm/Transforms/Vectorize.h"
|
||||
|
@ -145,12 +146,6 @@ cl::opt<bool> EnableOrderFileInstrumentation(
|
|||
"enable-order-file-instrumentation", cl::init(false), cl::Hidden,
|
||||
cl::desc("Enable order file instrumentation (default = off)"));
|
||||
|
||||
cl::opt<bool> ForgetSCEVInLoopUnroll(
|
||||
"forget-scev-loop-unroll", cl::init(false), cl::Hidden,
|
||||
cl::desc("Forget everything in SCEV when doing LoopUnroll, instead of just"
|
||||
" the current top-most loop. This is somtimes preferred to reduce"
|
||||
" compile time."));
|
||||
|
||||
PassManagerBuilder::PassManagerBuilder() {
|
||||
OptLevel = 2;
|
||||
SizeLevel = 0;
|
||||
|
|
|
@ -71,6 +71,12 @@ using namespace llvm;
|
|||
|
||||
#define DEBUG_TYPE "loop-unroll"
|
||||
|
||||
cl::opt<bool> llvm::ForgetSCEVInLoopUnroll(
|
||||
"forget-scev-loop-unroll", cl::init(false), cl::Hidden,
|
||||
cl::desc("Forget everything in SCEV when doing LoopUnroll, instead of just"
|
||||
" the current top-most loop. This is somtimes preferred to reduce"
|
||||
" compile time."));
|
||||
|
||||
static cl::opt<unsigned>
|
||||
UnrollThreshold("unroll-threshold", cl::Hidden,
|
||||
cl::desc("The cost threshold for loop unrolling"));
|
||||
|
@ -1281,7 +1287,7 @@ PreservedAnalyses LoopFullUnrollPass::run(Loop &L, LoopAnalysisManager &AM,
|
|||
tryToUnrollLoop(&L, AR.DT, &AR.LI, AR.SE, AR.TTI, AR.AC, *ORE,
|
||||
/*BFI*/ nullptr, /*PSI*/ nullptr,
|
||||
/*PreserveLCSSA*/ true, OptLevel, OnlyWhenForced,
|
||||
/*ForgetAllSCEV*/ false, /*Count*/ None,
|
||||
ForgetSCEV, /*Count*/ None,
|
||||
/*Threshold*/ None, /*AllowPartial*/ false,
|
||||
/*Runtime*/ false, /*UpperBound*/ false,
|
||||
/*AllowPeeling*/ false) != LoopUnrollResult::Unmodified;
|
||||
|
@ -1422,7 +1428,7 @@ PreservedAnalyses LoopUnrollPass::run(Function &F,
|
|||
LoopUnrollResult Result = tryToUnrollLoop(
|
||||
&L, DT, &LI, SE, TTI, AC, ORE, BFI, PSI,
|
||||
/*PreserveLCSSA*/ true, UnrollOpts.OptLevel, UnrollOpts.OnlyWhenForced,
|
||||
/*ForgetAllSCEV*/ false, /*Count*/ None,
|
||||
UnrollOpts.ForgetSCEV, /*Count*/ None,
|
||||
/*Threshold*/ None, UnrollOpts.AllowPartial, UnrollOpts.AllowRuntime,
|
||||
UnrollOpts.AllowUpperBound, LocalAllowPeeling);
|
||||
Changed |= Result != LoopUnrollResult::Unmodified;
|
||||
|
|
Loading…
Reference in New Issue