mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-03-07 11:59:09 +00:00
Add MemorySSA as loop dependency, disabled by default [NFC].
Summary: First step in adding MemorySSA as dependency for loop pass manager. Adding the dependency under a flag. New pass manager: MSSA pointer in LoopStandardAnalysisResults can be null. Legacy and new pass manager: Use cl::opt EnableMSSALoopDependency. Disabled by default. Reviewers: sanjoy, davide, gberry Subscribers: mehdi_amini, Prazek, llvm-commits Differential Revision: https://reviews.llvm.org/D40274 llvm-svn: 318772
This commit is contained in:
parent
33706d76ee
commit
77a10244b2
@ -37,6 +37,7 @@
|
||||
#include "llvm/Analysis/BasicAliasAnalysis.h"
|
||||
#include "llvm/Analysis/GlobalsModRef.h"
|
||||
#include "llvm/Analysis/LoopInfo.h"
|
||||
#include "llvm/Analysis/MemorySSA.h"
|
||||
#include "llvm/Analysis/ScalarEvolution.h"
|
||||
#include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h"
|
||||
#include "llvm/Analysis/TargetLibraryInfo.h"
|
||||
@ -58,8 +59,12 @@ struct LoopStandardAnalysisResults {
|
||||
ScalarEvolution &SE;
|
||||
TargetLibraryInfo &TLI;
|
||||
TargetTransformInfo &TTI;
|
||||
MemorySSA *MSSA;
|
||||
};
|
||||
|
||||
/// Enables memory ssa as a dependency for loop passes.
|
||||
extern cl::opt<bool> EnableMSSALoopDependency;
|
||||
|
||||
/// Extern template declaration for the analysis set for this IR unit.
|
||||
extern template class AllAnalysesOn<Loop>;
|
||||
|
||||
|
@ -285,13 +285,17 @@ public:
|
||||
return PA;
|
||||
|
||||
// Get the analysis results needed by loop passes.
|
||||
MemorySSA *MSSA = EnableMSSALoopDependency
|
||||
? (&AM.getResult<MemorySSAAnalysis>(F).getMSSA())
|
||||
: nullptr;
|
||||
LoopStandardAnalysisResults LAR = {AM.getResult<AAManager>(F),
|
||||
AM.getResult<AssumptionAnalysis>(F),
|
||||
AM.getResult<DominatorTreeAnalysis>(F),
|
||||
AM.getResult<LoopAnalysis>(F),
|
||||
AM.getResult<ScalarEvolutionAnalysis>(F),
|
||||
AM.getResult<TargetLibraryAnalysis>(F),
|
||||
AM.getResult<TargetIRAnalysis>(F)};
|
||||
AM.getResult<TargetIRAnalysis>(F),
|
||||
MSSA};
|
||||
|
||||
// Setup the loop analysis manager from its proxy. It is important that
|
||||
// this is only done when there are loops to process and we have built the
|
||||
@ -359,6 +363,8 @@ public:
|
||||
PA.preserve<DominatorTreeAnalysis>();
|
||||
PA.preserve<LoopAnalysis>();
|
||||
PA.preserve<ScalarEvolutionAnalysis>();
|
||||
// FIXME: Uncomment this when all loop passes preserve MemorySSA
|
||||
// PA.preserve<MemorySSAAnalysis>();
|
||||
// FIXME: What we really want to do here is preserve an AA category, but
|
||||
// that concept doesn't exist yet.
|
||||
PA.preserve<AAManager>();
|
||||
|
@ -11,15 +11,21 @@
|
||||
#include "llvm/Analysis/BasicAliasAnalysis.h"
|
||||
#include "llvm/Analysis/GlobalsModRef.h"
|
||||
#include "llvm/Analysis/LoopInfo.h"
|
||||
#include "llvm/Analysis/MemorySSA.h"
|
||||
#include "llvm/Analysis/ScalarEvolution.h"
|
||||
#include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h"
|
||||
#include "llvm/IR/Dominators.h"
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
namespace llvm {
|
||||
/// Enables memory ssa as a dependency for loop passes in legacy pass manager.
|
||||
cl::opt<bool> EnableMSSALoopDependency(
|
||||
"enable-mssa-loop-dependency", cl::Hidden, cl::init(false),
|
||||
cl::desc("Enable MemorySSA dependency for loop pass manager"));
|
||||
|
||||
// Explicit template instantiations and specialization defininitions for core
|
||||
// template typedefs.
|
||||
namespace llvm {
|
||||
template class AllAnalysesOn<Loop>;
|
||||
template class AnalysisManager<Loop, LoopStandardAnalysisResults &>;
|
||||
template class InnerAnalysisManagerProxy<LoopAnalysisManager, Function>;
|
||||
@ -45,12 +51,16 @@ bool LoopAnalysisManagerFunctionProxy::Result::invalidate(
|
||||
// loop analyses declare any dependencies on these and use the more general
|
||||
// invalidation logic below to act on that.
|
||||
auto PAC = PA.getChecker<LoopAnalysisManagerFunctionProxy>();
|
||||
bool invalidateMemorySSAAnalysis = false;
|
||||
if (EnableMSSALoopDependency)
|
||||
invalidateMemorySSAAnalysis = Inv.invalidate<MemorySSAAnalysis>(F, PA);
|
||||
if (!(PAC.preserved() || PAC.preservedSet<AllAnalysesOn<Function>>()) ||
|
||||
Inv.invalidate<AAManager>(F, PA) ||
|
||||
Inv.invalidate<AssumptionAnalysis>(F, PA) ||
|
||||
Inv.invalidate<DominatorTreeAnalysis>(F, PA) ||
|
||||
Inv.invalidate<LoopAnalysis>(F, PA) ||
|
||||
Inv.invalidate<ScalarEvolutionAnalysis>(F, PA)) {
|
||||
Inv.invalidate<ScalarEvolutionAnalysis>(F, PA) ||
|
||||
invalidateMemorySSAAnalysis) {
|
||||
// Note that the LoopInfo may be stale at this point, however the loop
|
||||
// objects themselves remain the only viable keys that could be in the
|
||||
// analysis manager's cache. So we just walk the keys and forcibly clear
|
||||
@ -137,7 +147,9 @@ PreservedAnalyses llvm::getLoopPassPreservedAnalyses() {
|
||||
PA.preserve<LoopAnalysis>();
|
||||
PA.preserve<LoopAnalysisManagerFunctionProxy>();
|
||||
PA.preserve<ScalarEvolutionAnalysis>();
|
||||
// TODO: What we really want to do here is preserve an AA category, but that
|
||||
// FIXME: Uncomment this when all loop passes preserve MemorySSA
|
||||
// PA.preserve<MemorySSAAnalysis>();
|
||||
// FIXME: What we really want to do here is preserve an AA category, but that
|
||||
// concept doesn't exist yet.
|
||||
PA.preserve<AAManager>();
|
||||
PA.preserve<BasicAA>();
|
||||
|
@ -42,6 +42,7 @@
|
||||
#include "llvm/Analysis/LoopInfo.h"
|
||||
#include "llvm/Analysis/LoopPass.h"
|
||||
#include "llvm/Analysis/MemoryBuiltins.h"
|
||||
#include "llvm/Analysis/MemorySSA.h"
|
||||
#include "llvm/Analysis/OptimizationRemarkEmitter.h"
|
||||
#include "llvm/Analysis/ScalarEvolution.h"
|
||||
#include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h"
|
||||
@ -114,7 +115,7 @@ CloneInstructionInExitBlock(Instruction &I, BasicBlock &ExitBlock, PHINode &PN,
|
||||
namespace {
|
||||
struct LoopInvariantCodeMotion {
|
||||
bool runOnLoop(Loop *L, AliasAnalysis *AA, LoopInfo *LI, DominatorTree *DT,
|
||||
TargetLibraryInfo *TLI, ScalarEvolution *SE,
|
||||
TargetLibraryInfo *TLI, ScalarEvolution *SE, MemorySSA *MSSA,
|
||||
OptimizationRemarkEmitter *ORE, bool DeleteAST);
|
||||
|
||||
DenseMap<Loop *, AliasSetTracker *> &getLoopToAliasSetMap() {
|
||||
@ -146,6 +147,9 @@ struct LegacyLICMPass : public LoopPass {
|
||||
}
|
||||
|
||||
auto *SE = getAnalysisIfAvailable<ScalarEvolutionWrapperPass>();
|
||||
MemorySSA *MSSA = EnableMSSALoopDependency
|
||||
? (&getAnalysis<MemorySSAWrapperPass>().getMSSA())
|
||||
: nullptr;
|
||||
// For the old PM, we can't use OptimizationRemarkEmitter as an analysis
|
||||
// pass. Function analyses need to be preserved across loop transformations
|
||||
// but ORE cannot be preserved (see comment before the pass definition).
|
||||
@ -155,7 +159,7 @@ struct LegacyLICMPass : public LoopPass {
|
||||
&getAnalysis<LoopInfoWrapperPass>().getLoopInfo(),
|
||||
&getAnalysis<DominatorTreeWrapperPass>().getDomTree(),
|
||||
&getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(),
|
||||
SE ? &SE->getSE() : nullptr, &ORE, false);
|
||||
SE ? &SE->getSE() : nullptr, MSSA, &ORE, false);
|
||||
}
|
||||
|
||||
/// This transformation requires natural loop information & requires that
|
||||
@ -164,6 +168,8 @@ struct LegacyLICMPass : public LoopPass {
|
||||
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
||||
AU.setPreservesCFG();
|
||||
AU.addRequired<TargetLibraryInfoWrapperPass>();
|
||||
if (EnableMSSALoopDependency)
|
||||
AU.addRequired<MemorySSAWrapperPass>();
|
||||
getLoopAnalysisUsage(AU);
|
||||
}
|
||||
|
||||
@ -204,7 +210,8 @@ PreservedAnalyses LICMPass::run(Loop &L, LoopAnalysisManager &AM,
|
||||
"cached at a higher level");
|
||||
|
||||
LoopInvariantCodeMotion LICM;
|
||||
if (!LICM.runOnLoop(&L, &AR.AA, &AR.LI, &AR.DT, &AR.TLI, &AR.SE, ORE, true))
|
||||
if (!LICM.runOnLoop(&L, &AR.AA, &AR.LI, &AR.DT, &AR.TLI, &AR.SE, AR.MSSA, ORE,
|
||||
true))
|
||||
return PreservedAnalyses::all();
|
||||
|
||||
auto PA = getLoopPassPreservedAnalyses();
|
||||
@ -217,6 +224,7 @@ INITIALIZE_PASS_BEGIN(LegacyLICMPass, "licm", "Loop Invariant Code Motion",
|
||||
false, false)
|
||||
INITIALIZE_PASS_DEPENDENCY(LoopPass)
|
||||
INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
|
||||
INITIALIZE_PASS_DEPENDENCY(MemorySSAWrapperPass)
|
||||
INITIALIZE_PASS_END(LegacyLICMPass, "licm", "Loop Invariant Code Motion", false,
|
||||
false)
|
||||
|
||||
@ -231,7 +239,7 @@ Pass *llvm::createLICMPass() { return new LegacyLICMPass(); }
|
||||
bool LoopInvariantCodeMotion::runOnLoop(Loop *L, AliasAnalysis *AA,
|
||||
LoopInfo *LI, DominatorTree *DT,
|
||||
TargetLibraryInfo *TLI,
|
||||
ScalarEvolution *SE,
|
||||
ScalarEvolution *SE, MemorySSA *MSSA,
|
||||
OptimizationRemarkEmitter *ORE,
|
||||
bool DeleteAST) {
|
||||
bool Changed = false;
|
||||
|
@ -995,7 +995,7 @@ PreservedAnalyses LoopDistributePass::run(Function &F,
|
||||
auto &LAM = AM.getResult<LoopAnalysisManagerFunctionProxy>(F).getManager();
|
||||
std::function<const LoopAccessInfo &(Loop &)> GetLAA =
|
||||
[&](Loop &L) -> const LoopAccessInfo & {
|
||||
LoopStandardAnalysisResults AR = {AA, AC, DT, LI, SE, TLI, TTI};
|
||||
LoopStandardAnalysisResults AR = {AA, AC, DT, LI, SE, TLI, TTI, nullptr};
|
||||
return LAM.getResult<LoopAccessAnalysis>(L, AR);
|
||||
};
|
||||
|
||||
|
@ -666,7 +666,8 @@ PreservedAnalyses LoopLoadEliminationPass::run(Function &F,
|
||||
auto &LAM = AM.getResult<LoopAnalysisManagerFunctionProxy>(F).getManager();
|
||||
bool Changed = eliminateLoadsAcrossLoops(
|
||||
F, LI, DT, [&](Loop &L) -> const LoopAccessInfo & {
|
||||
LoopStandardAnalysisResults AR = {AA, AC, DT, LI, SE, TLI, TTI};
|
||||
LoopStandardAnalysisResults AR = {AA, AC, DT, LI,
|
||||
SE, TLI, TTI, nullptr};
|
||||
return LAM.getResult<LoopAccessAnalysis>(L, AR);
|
||||
});
|
||||
|
||||
|
@ -9027,7 +9027,7 @@ PreservedAnalyses LoopVectorizePass::run(Function &F,
|
||||
auto &LAM = AM.getResult<LoopAnalysisManagerFunctionProxy>(F).getManager();
|
||||
std::function<const LoopAccessInfo &(Loop &)> GetLAA =
|
||||
[&](Loop &L) -> const LoopAccessInfo & {
|
||||
LoopStandardAnalysisResults AR = {AA, AC, DT, LI, SE, TLI, TTI};
|
||||
LoopStandardAnalysisResults AR = {AA, AC, DT, LI, SE, TLI, TTI, nullptr};
|
||||
return LAM.getResult<LoopAccessAnalysis>(L, AR);
|
||||
};
|
||||
bool Changed =
|
||||
|
Loading…
x
Reference in New Issue
Block a user