Skip to content

Commit

Permalink
[PM] Properly require and preserve OptimizationRemarkEmitter. NFCI.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Meinersbur committed Aug 28, 2017
1 parent 1587086 commit a4f447c
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 42 deletions.
6 changes: 4 additions & 2 deletions polly/include/polly/ScopBuilder.h
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions polly/include/polly/ScopDetection.h
Expand Up @@ -630,6 +630,7 @@ class ScopDetection {
countBeneficialLoops(Region *R, ScalarEvolution &SE, LoopInfo &LI,
unsigned MinProfitableTrips);

private:
/// OptimizationRemarkEmitter object used to emit diagnostic remarks
OptimizationRemarkEmitter &ORE;
};
Expand Down
3 changes: 2 additions & 1 deletion polly/include/polly/ScopInfo.h
Expand Up @@ -3096,11 +3096,12 @@ class ScopInfo {
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.
///
Expand Down
22 changes: 12 additions & 10 deletions polly/lib/Analysis/ScopBuilder.cpp
Expand Up @@ -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();
Expand Down Expand Up @@ -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);

Expand All @@ -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);
}
17 changes: 11 additions & 6 deletions polly/lib/Analysis/ScopInfo.cpp
Expand Up @@ -5230,6 +5230,7 @@ void ScopInfoRegionPass::getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequiredTransitive<ScopDetectionWrapperPass>();
AU.addRequired<AAResultsWrapperPass>();
AU.addRequired<AssumptionCacheTracker>();
AU.addRequired<OptimizationRemarkEmitterWrapperPass>();
AU.setPreservesAll();
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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();
}

Expand All @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -5401,6 +5404,7 @@ void ScopInfoWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequiredTransitive<ScopDetectionWrapperPass>();
AU.addRequired<AAResultsWrapperPass>();
AU.addRequired<AssumptionCacheTracker>();
AU.addRequired<OptimizationRemarkEmitterWrapperPass>();
AU.setPreservesAll();
}

Expand All @@ -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;
}

Expand Down
19 changes: 18 additions & 1 deletion polly/lib/Analysis/ScopPass.cpp
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down
13 changes: 2 additions & 11 deletions polly/lib/CodeGen/CodeGeneration.cpp
Expand Up @@ -333,6 +333,8 @@ class CodeGeneration : public ScopPass {

/// Register all analyses and transformation required.
void getAnalysisUsage(AnalysisUsage &AU) const override {
ScopPass::getAnalysisUsage(AU);

AU.addRequired<DominatorTreeWrapperPass>();
AU.addRequired<IslAstInfoWrapperPass>();
AU.addRequired<RegionInfoPass>();
Expand All @@ -342,21 +344,10 @@ class CodeGeneration : public ScopPass {
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>();
}
};

Expand Down
2 changes: 2 additions & 0 deletions polly/lib/CodeGen/IslAst.cpp
Expand Up @@ -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 {
Expand Down
13 changes: 2 additions & 11 deletions polly/lib/CodeGen/PPCGCodeGeneration.cpp
Expand Up @@ -3520,26 +3520,17 @@ class PPCGCodeGeneration : public ScopPass {
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>();
AU.addRequired<ScopDetectionWrapperPass>();
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
Expand Down
3 changes: 3 additions & 0 deletions polly/lib/Exchange/JSONExporter.cpp
Expand Up @@ -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(); }
Expand Down
2 changes: 2 additions & 0 deletions polly/lib/Transform/ScheduleOptimizer.cpp
Expand Up @@ -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() {
Expand Down

0 comments on commit a4f447c

Please sign in to comment.