forked from OSchip/llvm-project
[PM] Properly require and preserve OptimizationRemarkEmitter. NFCI.
Properly require and preserve the OptimizationRemarkEmitter for use in ScopPass. Previously one had to get the ORE from ScopDetection because CodeGeneration did not mark it as preserved. It would need to be recomputed which results in the legacy PM to throw away all previous SCoP analysis. This also changes the implementation of ScopPass::getAnalysisUsage to not unconditionally preserve all passes, but only those needed to be preserved by any SCoP pass (at least when using the legacy PM). This allows invalidating DependenceInfo (and IslAstInfo) in case the pass would cause them to change (e.g. OpTree, DeLICM, MaximalArrayExpansion) JSONImporter should also invalidate the DependenceInfo. In this patch it marks DependenceInfo as preserved anyway because some regression tests depend on it. Differential Revision: https://reviews.llvm.org/D37010 llvm-svn: 311888
This commit is contained in:
parent
1587086f88
commit
a4f447c2a4
|
@ -143,7 +143,8 @@ class ScopBuilder {
|
|||
// @}
|
||||
|
||||
// Build the SCoP for Region @p R.
|
||||
void buildScop(Region &R, AssumptionCache &AC);
|
||||
void buildScop(Region &R, AssumptionCache &AC,
|
||||
OptimizationRemarkEmitter &ORE);
|
||||
|
||||
/// Try to build a multi-dimensional fixed sized MemoryAccess from the
|
||||
/// Load/Store instruction.
|
||||
|
@ -337,7 +338,8 @@ class ScopBuilder {
|
|||
public:
|
||||
explicit ScopBuilder(Region *R, AssumptionCache &AC, AliasAnalysis &AA,
|
||||
const DataLayout &DL, DominatorTree &DT, LoopInfo &LI,
|
||||
ScopDetection &SD, ScalarEvolution &SE);
|
||||
ScopDetection &SD, ScalarEvolution &SE,
|
||||
OptimizationRemarkEmitter &ORE);
|
||||
ScopBuilder(const ScopBuilder &) = delete;
|
||||
ScopBuilder &operator=(const ScopBuilder &) = delete;
|
||||
~ScopBuilder() = default;
|
||||
|
|
|
@ -630,6 +630,7 @@ public:
|
|||
countBeneficialLoops(Region *R, ScalarEvolution &SE, LoopInfo &LI,
|
||||
unsigned MinProfitableTrips);
|
||||
|
||||
private:
|
||||
/// OptimizationRemarkEmitter object used to emit diagnostic remarks
|
||||
OptimizationRemarkEmitter &ORE;
|
||||
};
|
||||
|
|
|
@ -3096,11 +3096,12 @@ private:
|
|||
AliasAnalysis &AA;
|
||||
DominatorTree &DT;
|
||||
AssumptionCache ∾
|
||||
OptimizationRemarkEmitter &ORE;
|
||||
|
||||
public:
|
||||
ScopInfo(const DataLayout &DL, ScopDetection &SD, ScalarEvolution &SE,
|
||||
LoopInfo &LI, AliasAnalysis &AA, DominatorTree &DT,
|
||||
AssumptionCache &AC);
|
||||
AssumptionCache &AC, OptimizationRemarkEmitter &ORE);
|
||||
|
||||
/// Get the Scop object for the given Region.
|
||||
///
|
||||
|
|
|
@ -964,8 +964,9 @@ static inline BasicBlock *getRegionNodeBasicBlock(RegionNode *RN) {
|
|||
: RN->getNodeAs<BasicBlock>();
|
||||
}
|
||||
|
||||
void ScopBuilder::buildScop(Region &R, AssumptionCache &AC) {
|
||||
scop.reset(new Scop(R, SE, LI, *SD.getDetectionContext(&R), SD.ORE));
|
||||
void ScopBuilder::buildScop(Region &R, AssumptionCache &AC,
|
||||
OptimizationRemarkEmitter &ORE) {
|
||||
scop.reset(new Scop(R, SE, LI, *SD.getDetectionContext(&R), ORE));
|
||||
|
||||
buildStmts(R);
|
||||
buildAccessFunctions();
|
||||
|
@ -1064,17 +1065,18 @@ void ScopBuilder::buildScop(Region &R, AssumptionCache &AC) {
|
|||
|
||||
ScopBuilder::ScopBuilder(Region *R, AssumptionCache &AC, AliasAnalysis &AA,
|
||||
const DataLayout &DL, DominatorTree &DT, LoopInfo &LI,
|
||||
ScopDetection &SD, ScalarEvolution &SE)
|
||||
ScopDetection &SD, ScalarEvolution &SE,
|
||||
OptimizationRemarkEmitter &ORE)
|
||||
: AA(AA), DL(DL), DT(DT), LI(LI), SD(SD), SE(SE) {
|
||||
DebugLoc Beg, End;
|
||||
auto P = getBBPairForRegion(R);
|
||||
getDebugLocations(P, Beg, End);
|
||||
|
||||
std::string Msg = "SCoP begins here.";
|
||||
SD.ORE.emit(OptimizationRemarkAnalysis(DEBUG_TYPE, "ScopEntry", Beg, P.first)
|
||||
<< Msg);
|
||||
ORE.emit(OptimizationRemarkAnalysis(DEBUG_TYPE, "ScopEntry", Beg, P.first)
|
||||
<< Msg);
|
||||
|
||||
buildScop(*R, AC);
|
||||
buildScop(*R, AC, ORE);
|
||||
|
||||
DEBUG(dbgs() << *scop);
|
||||
|
||||
|
@ -1090,9 +1092,9 @@ ScopBuilder::ScopBuilder(Region *R, AssumptionCache &AC, AliasAnalysis &AA,
|
|||
}
|
||||
|
||||
if (R->isTopLevelRegion())
|
||||
SD.ORE.emit(OptimizationRemarkAnalysis(DEBUG_TYPE, "ScopEnd", End, P.first)
|
||||
<< Msg);
|
||||
ORE.emit(OptimizationRemarkAnalysis(DEBUG_TYPE, "ScopEnd", End, P.first)
|
||||
<< Msg);
|
||||
else
|
||||
SD.ORE.emit(OptimizationRemarkAnalysis(DEBUG_TYPE, "ScopEnd", End, P.second)
|
||||
<< Msg);
|
||||
ORE.emit(OptimizationRemarkAnalysis(DEBUG_TYPE, "ScopEnd", End, P.second)
|
||||
<< Msg);
|
||||
}
|
||||
|
|
|
@ -5230,6 +5230,7 @@ void ScopInfoRegionPass::getAnalysisUsage(AnalysisUsage &AU) const {
|
|||
AU.addRequiredTransitive<ScopDetectionWrapperPass>();
|
||||
AU.addRequired<AAResultsWrapperPass>();
|
||||
AU.addRequired<AssumptionCacheTracker>();
|
||||
AU.addRequired<OptimizationRemarkEmitterWrapperPass>();
|
||||
AU.setPreservesAll();
|
||||
}
|
||||
|
||||
|
@ -5279,8 +5280,9 @@ bool ScopInfoRegionPass::runOnRegion(Region *R, RGPassManager &RGM) {
|
|||
auto const &DL = F->getParent()->getDataLayout();
|
||||
auto &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
|
||||
auto &AC = getAnalysis<AssumptionCacheTracker>().getAssumptionCache(*F);
|
||||
auto &ORE = getAnalysis<OptimizationRemarkEmitterWrapperPass>().getORE();
|
||||
|
||||
ScopBuilder SB(R, AC, AA, DL, DT, LI, SD, SE);
|
||||
ScopBuilder SB(R, AC, AA, DL, DT, LI, SD, SE, ORE);
|
||||
S = SB.getScop(); // take ownership of scop object
|
||||
|
||||
#if !defined(NDEBUG) || defined(LLVM_ENABLE_STATS)
|
||||
|
@ -5322,8 +5324,8 @@ INITIALIZE_PASS_END(ScopInfoRegionPass, "polly-scops",
|
|||
//===----------------------------------------------------------------------===//
|
||||
ScopInfo::ScopInfo(const DataLayout &DL, ScopDetection &SD, ScalarEvolution &SE,
|
||||
LoopInfo &LI, AliasAnalysis &AA, DominatorTree &DT,
|
||||
AssumptionCache &AC)
|
||||
: DL(DL), SD(SD), SE(SE), LI(LI), AA(AA), DT(DT), AC(AC) {
|
||||
AssumptionCache &AC, OptimizationRemarkEmitter &ORE)
|
||||
: DL(DL), SD(SD), SE(SE), LI(LI), AA(AA), DT(DT), AC(AC), ORE(ORE) {
|
||||
recompute();
|
||||
}
|
||||
|
||||
|
@ -5336,7 +5338,7 @@ void ScopInfo::recompute() {
|
|||
if (!SD.isMaxRegionInScop(*R))
|
||||
continue;
|
||||
|
||||
ScopBuilder SB(R, AC, AA, DL, DT, LI, SD, SE);
|
||||
ScopBuilder SB(R, AC, AA, DL, DT, LI, SD, SE, ORE);
|
||||
std::unique_ptr<Scop> S = SB.getScop();
|
||||
if (!S)
|
||||
continue;
|
||||
|
@ -5376,7 +5378,8 @@ ScopInfoAnalysis::Result ScopInfoAnalysis::run(Function &F,
|
|||
auto &DT = FAM.getResult<DominatorTreeAnalysis>(F);
|
||||
auto &AC = FAM.getResult<AssumptionAnalysis>(F);
|
||||
auto &DL = F.getParent()->getDataLayout();
|
||||
return {DL, SD, SE, LI, AA, DT, AC};
|
||||
auto &ORE = FAM.getResult<OptimizationRemarkEmitterAnalysis>(F);
|
||||
return {DL, SD, SE, LI, AA, DT, AC, ORE};
|
||||
}
|
||||
|
||||
PreservedAnalyses ScopInfoPrinterPass::run(Function &F,
|
||||
|
@ -5401,6 +5404,7 @@ void ScopInfoWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const {
|
|||
AU.addRequiredTransitive<ScopDetectionWrapperPass>();
|
||||
AU.addRequired<AAResultsWrapperPass>();
|
||||
AU.addRequired<AssumptionCacheTracker>();
|
||||
AU.addRequired<OptimizationRemarkEmitterWrapperPass>();
|
||||
AU.setPreservesAll();
|
||||
}
|
||||
|
||||
|
@ -5412,8 +5416,9 @@ bool ScopInfoWrapperPass::runOnFunction(Function &F) {
|
|||
auto const &DL = F.getParent()->getDataLayout();
|
||||
auto &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
|
||||
auto &AC = getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F);
|
||||
auto &ORE = getAnalysis<OptimizationRemarkEmitterWrapperPass>().getORE();
|
||||
|
||||
Result.reset(new ScopInfo{DL, SD, SE, LI, AA, DT, AC});
|
||||
Result.reset(new ScopInfo{DL, SD, SE, LI, AA, DT, AC, ORE});
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,11 @@
|
|||
#include "polly/ScopInfo.h"
|
||||
|
||||
#include "llvm/Analysis/AssumptionCache.h"
|
||||
#include "llvm/Analysis/BasicAliasAnalysis.h"
|
||||
#include "llvm/Analysis/GlobalsModRef.h"
|
||||
#include "llvm/Analysis/OptimizationDiagnosticInfo.h"
|
||||
#include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h"
|
||||
#include "llvm/Analysis/TargetTransformInfo.h"
|
||||
|
||||
using namespace llvm;
|
||||
using namespace polly;
|
||||
|
@ -38,7 +43,19 @@ void ScopPass::print(raw_ostream &OS, const Module *M) const {
|
|||
|
||||
void ScopPass::getAnalysisUsage(AnalysisUsage &AU) const {
|
||||
AU.addRequired<ScopInfoRegionPass>();
|
||||
AU.setPreservesAll();
|
||||
|
||||
AU.addPreserved<AAResultsWrapperPass>();
|
||||
AU.addPreserved<BasicAAWrapperPass>();
|
||||
AU.addPreserved<LoopInfoWrapperPass>();
|
||||
AU.addPreserved<DominatorTreeWrapperPass>();
|
||||
AU.addPreserved<GlobalsAAWrapperPass>();
|
||||
AU.addPreserved<ScopDetectionWrapperPass>();
|
||||
AU.addPreserved<ScalarEvolutionWrapperPass>();
|
||||
AU.addPreserved<SCEVAAWrapperPass>();
|
||||
AU.addPreserved<OptimizationRemarkEmitterWrapperPass>();
|
||||
AU.addPreserved<RegionInfoPass>();
|
||||
AU.addPreserved<ScopInfoRegionPass>();
|
||||
AU.addPreserved<TargetTransformInfoWrapperPass>();
|
||||
}
|
||||
|
||||
namespace polly {
|
||||
|
|
|
@ -333,6 +333,8 @@ public:
|
|||
|
||||
/// Register all analyses and transformation required.
|
||||
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
||||
ScopPass::getAnalysisUsage(AU);
|
||||
|
||||
AU.addRequired<DominatorTreeWrapperPass>();
|
||||
AU.addRequired<IslAstInfoWrapperPass>();
|
||||
AU.addRequired<RegionInfoPass>();
|
||||
|
@ -342,21 +344,10 @@ public:
|
|||
AU.addRequired<LoopInfoWrapperPass>();
|
||||
|
||||
AU.addPreserved<DependenceInfo>();
|
||||
|
||||
AU.addPreserved<AAResultsWrapperPass>();
|
||||
AU.addPreserved<BasicAAWrapperPass>();
|
||||
AU.addPreserved<LoopInfoWrapperPass>();
|
||||
AU.addPreserved<DominatorTreeWrapperPass>();
|
||||
AU.addPreserved<GlobalsAAWrapperPass>();
|
||||
AU.addPreserved<IslAstInfoWrapperPass>();
|
||||
AU.addPreserved<ScopDetectionWrapperPass>();
|
||||
AU.addPreserved<ScalarEvolutionWrapperPass>();
|
||||
AU.addPreserved<SCEVAAWrapperPass>();
|
||||
|
||||
// FIXME: We do not yet add regions for the newly generated code to the
|
||||
// region tree.
|
||||
AU.addPreserved<RegionInfoPass>();
|
||||
AU.addPreserved<ScopInfoRegionPass>();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -771,6 +771,8 @@ void IslAstInfoWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const {
|
|||
ScopPass::getAnalysisUsage(AU);
|
||||
AU.addRequired<ScopInfoRegionPass>();
|
||||
AU.addRequired<DependenceInfo>();
|
||||
|
||||
AU.addPreserved<DependenceInfo>();
|
||||
}
|
||||
|
||||
void IslAstInfoWrapperPass::printScop(raw_ostream &OS, Scop &S) const {
|
||||
|
|
|
@ -3520,6 +3520,8 @@ public:
|
|||
void printScop(raw_ostream &, Scop &) const override {}
|
||||
|
||||
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
||||
ScopPass::getAnalysisUsage(AU);
|
||||
|
||||
AU.addRequired<DominatorTreeWrapperPass>();
|
||||
AU.addRequired<RegionInfoPass>();
|
||||
AU.addRequired<ScalarEvolutionWrapperPass>();
|
||||
|
@ -3527,19 +3529,8 @@ public:
|
|||
AU.addRequired<ScopInfoRegionPass>();
|
||||
AU.addRequired<LoopInfoWrapperPass>();
|
||||
|
||||
AU.addPreserved<AAResultsWrapperPass>();
|
||||
AU.addPreserved<BasicAAWrapperPass>();
|
||||
AU.addPreserved<LoopInfoWrapperPass>();
|
||||
AU.addPreserved<DominatorTreeWrapperPass>();
|
||||
AU.addPreserved<GlobalsAAWrapperPass>();
|
||||
AU.addPreserved<ScopDetectionWrapperPass>();
|
||||
AU.addPreserved<ScalarEvolutionWrapperPass>();
|
||||
AU.addPreserved<SCEVAAWrapperPass>();
|
||||
|
||||
// FIXME: We do not yet add regions for the newly generated code to the
|
||||
// region tree.
|
||||
AU.addPreserved<RegionInfoPass>();
|
||||
AU.addPreserved<ScopInfoRegionPass>();
|
||||
}
|
||||
};
|
||||
} // namespace
|
||||
|
|
|
@ -792,6 +792,9 @@ bool JSONImporter::runOnScop(Scop &S) {
|
|||
void JSONImporter::getAnalysisUsage(AnalysisUsage &AU) const {
|
||||
ScopPass::getAnalysisUsage(AU);
|
||||
AU.addRequired<DependenceInfo>();
|
||||
|
||||
// TODO: JSONImporter should throw away DependenceInfo.
|
||||
AU.addPreserved<DependenceInfo>();
|
||||
}
|
||||
|
||||
Pass *polly::createJSONImporterPass() { return new JSONImporter(); }
|
||||
|
|
|
@ -1591,6 +1591,8 @@ void IslScheduleOptimizer::getAnalysisUsage(AnalysisUsage &AU) const {
|
|||
ScopPass::getAnalysisUsage(AU);
|
||||
AU.addRequired<DependenceInfo>();
|
||||
AU.addRequired<TargetTransformInfoWrapperPass>();
|
||||
|
||||
AU.addPreserved<DependenceInfo>();
|
||||
}
|
||||
|
||||
Pass *polly::createIslScheduleOptimizerPass() {
|
||||
|
|
Loading…
Reference in New Issue