summaryrefslogtreecommitdiffstats
path: root/contrib/llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm/lib/Transforms/IPO/PassManagerBuilder.cpp')
-rw-r--r--contrib/llvm/lib/Transforms/IPO/PassManagerBuilder.cpp138
1 files changed, 96 insertions, 42 deletions
diff --git a/contrib/llvm/lib/Transforms/IPO/PassManagerBuilder.cpp b/contrib/llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
index df6a48e..941efb2 100644
--- a/contrib/llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
+++ b/contrib/llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
@@ -19,6 +19,7 @@
#include "llvm/Analysis/CFLAndersAliasAnalysis.h"
#include "llvm/Analysis/CFLSteensAliasAnalysis.h"
#include "llvm/Analysis/GlobalsModRef.h"
+#include "llvm/Analysis/InlineCost.h"
#include "llvm/Analysis/Passes.h"
#include "llvm/Analysis/ScopedNoAliasAA.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
@@ -66,14 +67,13 @@ static cl::opt<bool>
RunLoopRerolling("reroll-loops", cl::Hidden,
cl::desc("Run the loop rerolling pass"));
-static cl::opt<bool>
-RunFloat2Int("float-to-int", cl::Hidden, cl::init(true),
- cl::desc("Run the float2int (float demotion) pass"));
-
static cl::opt<bool> RunLoadCombine("combine-loads", cl::init(false),
cl::Hidden,
cl::desc("Run the load combining pass"));
+static cl::opt<bool> RunNewGVN("enable-newgvn", cl::init(false), cl::Hidden,
+ cl::desc("Run the NewGVN pass"));
+
static cl::opt<bool>
RunSLPAfterLoopVectorization("run-slp-after-loop-vectorization",
cl::init(true), cl::Hidden,
@@ -91,8 +91,7 @@ static cl::opt<CFLAAType>
clEnumValN(CFLAAType::Andersen, "anders",
"Enable inclusion-based CFL-AA"),
clEnumValN(CFLAAType::Both, "both",
- "Enable both variants of CFL-aa"),
- clEnumValEnd));
+ "Enable both variants of CFL-AA")));
static cl::opt<bool>
EnableMLSM("mlsm", cl::init(true), cl::Hidden,
@@ -111,10 +110,17 @@ static cl::opt<bool> EnableLoopLoadElim(
"enable-loop-load-elim", cl::init(true), cl::Hidden,
cl::desc("Enable the LoopLoadElimination Pass"));
-static cl::opt<std::string> RunPGOInstrGen(
- "profile-generate", cl::init(""), cl::Hidden,
- cl::desc("Enable generation phase of PGO instrumentation and specify the "
- "path of profile data file"));
+static cl::opt<bool>
+ EnablePrepareForThinLTO("prepare-for-thinlto", cl::init(false), cl::Hidden,
+ cl::desc("Enable preparation for ThinLTO."));
+
+static cl::opt<bool> RunPGOInstrGen(
+ "profile-generate", cl::init(false), cl::Hidden,
+ cl::desc("Enable PGO instrumentation."));
+
+static cl::opt<std::string>
+ PGOOutputFile("profile-generate-file", cl::init(""), cl::Hidden,
+ cl::desc("Specify the path of profile data file."));
static cl::opt<std::string> RunPGOInstrUse(
"profile-use", cl::init(""), cl::Hidden, cl::value_desc("filename"),
@@ -136,14 +142,18 @@ static cl::opt<int> PreInlineThreshold(
static cl::opt<bool> EnableGVNHoist(
"enable-gvn-hoist", cl::init(false), cl::Hidden,
- cl::desc("Enable the experimental GVN Hoisting pass"));
+ cl::desc("Enable the GVN hoisting pass"));
+
+static cl::opt<bool>
+ DisableLibCallsShrinkWrap("disable-libcalls-shrinkwrap", cl::init(false),
+ cl::Hidden,
+ cl::desc("Disable shrink-wrap library calls"));
PassManagerBuilder::PassManagerBuilder() {
OptLevel = 2;
SizeLevel = 0;
LibraryInfo = nullptr;
Inliner = nullptr;
- ModuleSummary = nullptr;
DisableUnitAtATime = false;
DisableUnrollLoops = false;
BBVectorize = RunBBVectorization;
@@ -151,14 +161,16 @@ PassManagerBuilder::PassManagerBuilder() {
LoopVectorize = RunLoopVectorization;
RerollLoops = RunLoopRerolling;
LoadCombine = RunLoadCombine;
+ NewGVN = RunNewGVN;
DisableGVNLoadPRE = false;
VerifyInput = false;
VerifyOutput = false;
MergeFunctions = false;
PrepareForLTO = false;
- PGOInstrGen = RunPGOInstrGen;
+ EnablePGOInstrGen = RunPGOInstrGen;
+ PGOInstrGen = PGOOutputFile;
PGOInstrUse = RunPGOInstrUse;
- PrepareForThinLTO = false;
+ PrepareForThinLTO = EnablePrepareForThinLTO;
PerformThinLTO = false;
}
@@ -243,24 +255,34 @@ void PassManagerBuilder::populateFunctionPassManager(
// Do PGO instrumentation generation or use pass as the option specified.
void PassManagerBuilder::addPGOInstrPasses(legacy::PassManagerBase &MPM) {
- if (PGOInstrGen.empty() && PGOInstrUse.empty())
+ if (!EnablePGOInstrGen && PGOInstrUse.empty())
return;
// Perform the preinline and cleanup passes for O1 and above.
// And avoid doing them if optimizing for size.
if (OptLevel > 0 && SizeLevel == 0 && !DisablePreInliner) {
- // Create preinline pass.
- MPM.add(createFunctionInliningPass(PreInlineThreshold));
+ // Create preinline pass. We construct an InlineParams object and specify
+ // the threshold here to avoid the command line options of the regular
+ // inliner to influence pre-inlining. The only fields of InlineParams we
+ // care about are DefaultThreshold and HintThreshold.
+ InlineParams IP;
+ IP.DefaultThreshold = PreInlineThreshold;
+ // FIXME: The hint threshold has the same value used by the regular inliner.
+ // This should probably be lowered after performance testing.
+ IP.HintThreshold = 325;
+
+ MPM.add(createFunctionInliningPass(IP));
MPM.add(createSROAPass());
MPM.add(createEarlyCSEPass()); // Catch trivial redundancies
MPM.add(createCFGSimplificationPass()); // Merge & remove BBs
MPM.add(createInstructionCombiningPass()); // Combine silly seq's
addExtensionsToPM(EP_Peephole, MPM);
}
- if (!PGOInstrGen.empty()) {
+ if (EnablePGOInstrGen) {
MPM.add(createPGOInstrumentationGenLegacyPass());
// Add the profile lowering pass.
InstrProfOptions Options;
- Options.InstrProfileOutput = PGOInstrGen;
+ if (!PGOInstrGen.empty())
+ Options.InstrProfileOutput = PGOInstrGen;
MPM.add(createInstrProfilingLegacyPass(Options));
}
if (!PGOInstrUse.empty())
@@ -279,6 +301,8 @@ void PassManagerBuilder::addFunctionSimplificationPasses(
MPM.add(createCFGSimplificationPass()); // Merge & remove BBs
// Combine silly seq's
addInstructionCombiningPass(MPM);
+ if (SizeLevel == 0 && !DisableLibCallsShrinkWrap)
+ MPM.add(createLibCallsShrinkWrapPass());
addExtensionsToPM(EP_Peephole, MPM);
MPM.add(createTailCallEliminationPass()); // Eliminate tail calls
@@ -304,7 +328,8 @@ void PassManagerBuilder::addFunctionSimplificationPasses(
if (OptLevel > 1) {
if (EnableMLSM)
MPM.add(createMergedLoadStoreMotionPass()); // Merge ld/st in diamonds
- MPM.add(createGVNPass(DisableGVNLoadPRE)); // Remove redundancies
+ MPM.add(NewGVN ? createNewGVNPass()
+ : createGVNPass(DisableGVNLoadPRE)); // Remove redundancies
}
MPM.add(createMemCpyOptPass()); // Remove memcpy / form memset
MPM.add(createSCCPPass()); // Constant prop with SCCP
@@ -336,7 +361,9 @@ void PassManagerBuilder::addFunctionSimplificationPasses(
addInstructionCombiningPass(MPM);
addExtensionsToPM(EP_Peephole, MPM);
if (OptLevel > 1 && UseGVNAfterVectorization)
- MPM.add(createGVNPass(DisableGVNLoadPRE)); // Remove redundancies
+ MPM.add(NewGVN
+ ? createNewGVNPass()
+ : createGVNPass(DisableGVNLoadPRE)); // Remove redundancies
else
MPM.add(createEarlyCSEPass()); // Catch trivial redundancies
@@ -358,6 +385,11 @@ void PassManagerBuilder::addFunctionSimplificationPasses(
void PassManagerBuilder::populateModulePassManager(
legacy::PassManagerBase &MPM) {
+ if (!PGOSampleUse.empty()) {
+ MPM.add(createPruneEHPass());
+ MPM.add(createSampleProfileLoaderPass(PGOSampleUse));
+ }
+
// Allow forcing function attributes as a debugging and tuning aid.
MPM.add(createForceFunctionAttrsLegacyPass());
@@ -380,6 +412,10 @@ void PassManagerBuilder::populateModulePassManager(
else if (!GlobalExtensions->empty() || !Extensions.empty())
MPM.add(createBarrierNoopPass());
+ if (PrepareForThinLTO)
+ // Rename anon globals to be able to export them in the summary.
+ MPM.add(createNameAnonGlobalPass());
+
addExtensionsToPM(EP_EnabledOnOptLevel0, MPM);
return;
}
@@ -390,6 +426,16 @@ void PassManagerBuilder::populateModulePassManager(
addInitialAliasAnalysisPasses(MPM);
+ // For ThinLTO there are two passes of indirect call promotion. The
+ // first is during the compile phase when PerformThinLTO=false and
+ // intra-module indirect call targets are promoted. The second is during
+ // the ThinLTO backend when PerformThinLTO=true, when we promote imported
+ // inter-module indirect calls. For that we perform indirect call promotion
+ // earlier in the pass pipeline, here before globalopt. Otherwise imported
+ // available_externally functions look unreferenced and are removed.
+ if (PerformThinLTO)
+ MPM.add(createPGOIndirectCallPromotionLegacyPass(/*InLTO = */ true));
+
if (!DisableUnitAtATime) {
// Infer attributes about declarations if possible.
MPM.add(createInferFunctionAttrsLegacyPass());
@@ -412,11 +458,12 @@ void PassManagerBuilder::populateModulePassManager(
/// PGO instrumentation is added during the compile phase for ThinLTO, do
/// not run it a second time
addPGOInstrPasses(MPM);
+ // Indirect call promotion that promotes intra-module targets only.
+ // For ThinLTO this is done earlier due to interactions with globalopt
+ // for imported functions.
+ MPM.add(createPGOIndirectCallPromotionLegacyPass());
}
- // Indirect call promotion that promotes intra-module targets only.
- MPM.add(createPGOIndirectCallPromotionLegacyPass());
-
if (EnableNonLTOGlobalsModRef)
// We add a module alias analysis pass here. In part due to bugs in the
// analysis infrastructure this "works" in that the analysis stays alive
@@ -435,6 +482,7 @@ void PassManagerBuilder::populateModulePassManager(
if (OptLevel > 2)
MPM.add(createArgumentPromotionPass()); // Scalarize uninlined fn args
+ addExtensionsToPM(EP_CGSCCOptimizerLate, MPM);
addFunctionSimplificationPasses(MPM);
// FIXME: This is a HACK! The inliner pass above implicitly creates a CGSCC
@@ -464,8 +512,8 @@ void PassManagerBuilder::populateModulePassManager(
if (PrepareForThinLTO) {
// Reduce the size of the IR as much as possible.
MPM.add(createGlobalOptimizerPass());
- // Rename anon function to be able to export them in the summary.
- MPM.add(createNameAnonFunctionPass());
+ // Rename anon globals to be able to export them in the summary.
+ MPM.add(createNameAnonGlobalPass());
return;
}
@@ -502,8 +550,7 @@ void PassManagerBuilder::populateModulePassManager(
// correct in the face of IR changes).
MPM.add(createGlobalsAAWrapperPass());
- if (RunFloat2Int)
- MPM.add(createFloat2IntPass());
+ MPM.add(createFloat2IntPass());
addExtensionsToPM(EP_VectorizerStart, MPM);
@@ -516,7 +563,7 @@ void PassManagerBuilder::populateModulePassManager(
// into separate loop that would otherwise inhibit vectorization. This is
// currently only performed for loops marked with the metadata
// llvm.loop.distribute=true or when -enable-loop-distribute is specified.
- MPM.add(createLoopDistributePass(/*ProcessAllLoopsByDefault=*/false));
+ MPM.add(createLoopDistributePass());
MPM.add(createLoopVectorizePass(DisableUnrollLoops, LoopVectorize));
@@ -560,7 +607,9 @@ void PassManagerBuilder::populateModulePassManager(
addInstructionCombiningPass(MPM);
addExtensionsToPM(EP_Peephole, MPM);
if (OptLevel > 1 && UseGVNAfterVectorization)
- MPM.add(createGVNPass(DisableGVNLoadPRE)); // Remove redundancies
+ MPM.add(NewGVN
+ ? createNewGVNPass()
+ : createGVNPass(DisableGVNLoadPRE)); // Remove redundancies
else
MPM.add(createEarlyCSEPass()); // Catch trivial redundancies
@@ -585,10 +634,7 @@ void PassManagerBuilder::populateModulePassManager(
// outer loop. LICM pass can help to promote the runtime check out if the
// checked value is loop invariant.
MPM.add(createLICMPass());
-
- // Get rid of LCSSA nodes.
- MPM.add(createInstructionSimplifierPass());
- }
+ }
// After vectorization and unrolling, assume intrinsics may tell us more
// about pointer alignments.
@@ -609,6 +655,13 @@ void PassManagerBuilder::populateModulePassManager(
if (MergeFunctions)
MPM.add(createMergeFunctionsPass());
+ // LoopSink pass sinks instructions hoisted by LICM, which serves as a
+ // canonicalization pass that enables other optimizations. As a result,
+ // LoopSink pass needs to be a very late IR pass to avoid undoing LICM
+ // result too early.
+ MPM.add(createLoopSinkPass());
+ // Get rid of LCSSA nodes.
+ MPM.add(createInstructionSimplifierPass());
addExtensionsToPM(EP_OptimizerLast, MPM);
}
@@ -620,9 +673,6 @@ void PassManagerBuilder::addLTOOptimizationPasses(legacy::PassManagerBase &PM) {
// Provide AliasAnalysis services for optimizations.
addInitialAliasAnalysisPasses(PM);
- if (ModuleSummary)
- PM.add(createFunctionImportPass(ModuleSummary));
-
// Allow forcing function attributes as a debugging and tuning aid.
PM.add(createForceFunctionAttrsLegacyPass());
@@ -647,6 +697,11 @@ void PassManagerBuilder::addLTOOptimizationPasses(legacy::PassManagerBase &PM) {
PM.add(createPostOrderFunctionAttrsLegacyPass());
PM.add(createReversePostOrderFunctionAttrsPass());
+ // Split globals using inrange annotations on GEP indices. This can help
+ // improve the quality of generated code when virtual constant propagation or
+ // control flow integrity are enabled.
+ PM.add(createGlobalSplitPass());
+
// Apply whole-program devirtualization and virtual constant propagation.
PM.add(createWholeProgramDevirtPass());
@@ -706,7 +761,8 @@ void PassManagerBuilder::addLTOOptimizationPasses(legacy::PassManagerBase &PM) {
PM.add(createLICMPass()); // Hoist loop invariants.
if (EnableMLSM)
PM.add(createMergedLoadStoreMotionPass()); // Merge ld/st in diamonds.
- PM.add(createGVNPass(DisableGVNLoadPRE)); // Remove redundancies.
+ PM.add(NewGVN ? createNewGVNPass()
+ : createGVNPass(DisableGVNLoadPRE)); // Remove redundancies.
PM.add(createMemCpyOptPass()); // Remove dead memcpys.
// Nuke dead stores.
@@ -777,9 +833,6 @@ void PassManagerBuilder::populateThinLTOPassManager(
if (VerifyInput)
PM.add(createVerifierPass());
- if (ModuleSummary)
- PM.add(createFunctionImportPass(ModuleSummary));
-
populateModulePassManager(PM);
if (VerifyOutput)
@@ -804,7 +857,8 @@ void PassManagerBuilder::populateLTOPassManager(legacy::PassManagerBase &PM) {
// Lower type metadata and the type.test intrinsic. This pass supports Clang's
// control flow integrity mechanisms (-fsanitize=cfi*) and needs to run at
// link time if CFI is enabled. The pass does nothing if CFI is disabled.
- PM.add(createLowerTypeTestsPass());
+ PM.add(createLowerTypeTestsPass(LowerTypeTestsSummaryAction::None,
+ /*Summary=*/nullptr));
if (OptLevel != 0)
addLateLTOOptimizationPasses(PM);
OpenPOWER on IntegriCloud