From 2ef3f4fd2378c6b1f6acbb18a9332d58f3d8b2cc Mon Sep 17 00:00:00 2001 From: Johannes Doerfert Date: Thu, 7 Aug 2014 17:14:54 +0000 Subject: [PATCH] Make used analysis passes explicit Use the explicit analysis if possible, only for splitBlock we will continue to use the Pass * argument. This change allows us to remove the getAnalysis calls from the code generation. llvm-svn: 215121 --- polly/include/polly/CodeGen/BlockGenerators.h | 38 +++++++++++-------- polly/include/polly/CodeGen/LoopGenerators.h | 5 ++- polly/lib/CodeGen/BlockGenerators.cpp | 21 +++++----- polly/lib/CodeGen/IslCodeGeneration.cpp | 25 +++++++----- polly/lib/CodeGen/LoopGenerators.cpp | 8 ++-- 5 files changed, 56 insertions(+), 41 deletions(-) diff --git a/polly/include/polly/CodeGen/BlockGenerators.h b/polly/include/polly/CodeGen/BlockGenerators.h index 08ea0595e28a..af8ebd7e5e85 100644 --- a/polly/include/polly/CodeGen/BlockGenerators.h +++ b/polly/include/polly/CodeGen/BlockGenerators.h @@ -67,22 +67,23 @@ class BlockGenerator { public: /// @brief Generate a new BasicBlock for a ScopStmt. /// - /// @param Builder The LLVM-IR Builder used to generate the statement. The - /// code is generated at the location, the Builder points - /// to. - /// @param Stmt The statement to code generate. - /// @param GlobalMap A map that defines for certain Values referenced from - /// the original code new Values they should be replaced - /// with. - /// @param P A reference to the pass this function is called from. - /// The pass is needed to update other analysis. + /// @param Builder The LLVM-IR Builder used to generate the statement. The + /// code is generated at the location, the Builder points to. + /// @param Stmt The statement to code generate. + /// @param GlobalMap A map that defines for certain Values referenced from the + /// original code new Values they should be replaced with. + /// @param P A reference to the pass this function is called from. + /// The pass is needed to update other analysis. + /// @param LI The loop info for the current function + /// @param SE The scalar evolution info for the current function /// @param Build The AST build with the new schedule. /// @param ExprBuilder An expression builder to generate new access functions. static void generate(PollyIRBuilder &Builder, ScopStmt &Stmt, ValueMapT &GlobalMap, LoopToScevMapT <S, Pass *P, + LoopInfo &LI, ScalarEvolution &SE, __isl_keep isl_ast_build *Build = nullptr, IslExprBuilder *ExprBuilder = nullptr) { - BlockGenerator Generator(Builder, Stmt, P, Build, ExprBuilder); + BlockGenerator Generator(Builder, Stmt, P, LI, SE, Build, ExprBuilder); Generator.copyBB(GlobalMap, LTS); } @@ -90,12 +91,14 @@ protected: PollyIRBuilder &Builder; ScopStmt &Statement; Pass *P; + LoopInfo &LI; ScalarEvolution &SE; isl_ast_build *Build; IslExprBuilder *ExprBuilder; - BlockGenerator(PollyIRBuilder &B, ScopStmt &Stmt, Pass *P, - __isl_keep isl_ast_build *Build, IslExprBuilder *ExprBuilder); + BlockGenerator(PollyIRBuilder &B, ScopStmt &Stmt, Pass *P, LoopInfo &LI, + ScalarEvolution &SE, __isl_keep isl_ast_build *Build, + IslExprBuilder *ExprBuilder); /// @brief Get the new version of a Value. /// @@ -204,11 +207,15 @@ public: /// loop containing the statemenet. /// @param P A reference to the pass this function is called from. /// The pass is needed to update other analysis. + /// @param LI The loop info for the current function + /// @param SE The scalar evolution info for the current function static void generate(PollyIRBuilder &B, ScopStmt &Stmt, VectorValueMapT &GlobalMaps, std::vector &VLTS, - __isl_keep isl_map *Schedule, Pass *P) { - VectorBlockGenerator Generator(B, GlobalMaps, VLTS, Stmt, Schedule, P); + __isl_keep isl_map *Schedule, Pass *P, LoopInfo &LI, + ScalarEvolution &SE) { + VectorBlockGenerator Generator(B, GlobalMaps, VLTS, Stmt, Schedule, P, LI, + SE); Generator.copyBB(); } @@ -244,7 +251,8 @@ private: VectorBlockGenerator(PollyIRBuilder &B, VectorValueMapT &GlobalMaps, std::vector &VLTS, ScopStmt &Stmt, - __isl_keep isl_map *Schedule, Pass *P); + __isl_keep isl_map *Schedule, Pass *P, LoopInfo &LI, + ScalarEvolution &SE); int getVectorWidth(); diff --git a/polly/include/polly/CodeGen/LoopGenerators.h b/polly/include/polly/CodeGen/LoopGenerators.h index 37d5dc93b70b..6467161d10f0 100644 --- a/polly/include/polly/CodeGen/LoopGenerators.h +++ b/polly/include/polly/CodeGen/LoopGenerators.h @@ -36,6 +36,8 @@ using namespace llvm; /// @param Builder The builder used to create the loop. /// @param P A pointer to the pass that uses this function. It is used /// to update analysis information. +/// @param LI The loop info for the current function +/// @param DT The dominator tree we need to update /// @param ExitBlock The block the loop will exit to. /// @param Predicate The predicate used to generate the upper loop bound. /// @param Annotator This function can (optionally) take a LoopAnnotator which @@ -43,7 +45,8 @@ using namespace llvm; /// @param Parallel If this loop should be marked parallel in the Annotator. /// @return Value* The newly created induction variable for this loop. Value *createLoop(Value *LowerBound, Value *UpperBound, Value *Stride, - PollyIRBuilder &Builder, Pass *P, BasicBlock *&ExitBlock, + PollyIRBuilder &Builder, Pass *P, LoopInfo &LI, + DominatorTree &DT, BasicBlock *&ExitBlock, ICmpInst::Predicate Predicate, LoopAnnotator *Annotator = NULL, bool Parallel = false); diff --git a/polly/lib/CodeGen/BlockGenerators.cpp b/polly/lib/CodeGen/BlockGenerators.cpp index 66d90d9cff5b..52c8ce02bc7b 100644 --- a/polly/lib/CodeGen/BlockGenerators.cpp +++ b/polly/lib/CodeGen/BlockGenerators.cpp @@ -67,10 +67,11 @@ bool polly::canSynthesize(const Instruction *I, const llvm::LoopInfo *LI, } BlockGenerator::BlockGenerator(PollyIRBuilder &B, ScopStmt &Stmt, Pass *P, + LoopInfo &LI, ScalarEvolution &SE, isl_ast_build *Build, IslExprBuilder *ExprBuilder) - : Builder(B), Statement(Stmt), P(P), SE(P->getAnalysis()), - Build(Build), ExprBuilder(ExprBuilder) {} + : Builder(B), Statement(Stmt), P(P), LI(LI), SE(SE), Build(Build), + ExprBuilder(ExprBuilder) {} Value *BlockGenerator::lookupAvailableValue(const Value *Old, ValueMapT &BBMap, ValueMapT &GlobalMap) const { @@ -209,7 +210,7 @@ Value *BlockGenerator::generateLocationAccessed(const Instruction *Inst, } Loop *BlockGenerator::getLoopForInst(const llvm::Instruction *Inst) { - return P->getAnalysis().getLoopFor(Inst->getParent()); + return LI.getLoopFor(Inst->getParent()); } Value *BlockGenerator::generateScalarLoad(const LoadInst *Load, @@ -282,14 +283,12 @@ void BlockGenerator::copyBB(ValueMapT &GlobalMap, LoopToScevMapT <S) { copyInstruction(&Inst, BBMap, GlobalMap, LTS); } -VectorBlockGenerator::VectorBlockGenerator(PollyIRBuilder &B, - VectorValueMapT &GlobalMaps, - std::vector &VLTS, - ScopStmt &Stmt, - __isl_keep isl_map *Schedule, - Pass *P) - : BlockGenerator(B, Stmt, P, nullptr, nullptr), GlobalMaps(GlobalMaps), - VLTS(VLTS), Schedule(Schedule) { +VectorBlockGenerator::VectorBlockGenerator( + PollyIRBuilder &B, VectorValueMapT &GlobalMaps, + std::vector &VLTS, ScopStmt &Stmt, + __isl_keep isl_map *Schedule, Pass *P, LoopInfo &LI, ScalarEvolution &SE) + : BlockGenerator(B, Stmt, P, LI, SE, nullptr, nullptr), + GlobalMaps(GlobalMaps), VLTS(VLTS), Schedule(Schedule) { assert(GlobalMaps.size() > 1 && "Only one vector lane found"); assert(Schedule && "No statement domain provided"); } diff --git a/polly/lib/CodeGen/IslCodeGeneration.cpp b/polly/lib/CodeGen/IslCodeGeneration.cpp index 361ef8ac5a5d..71ca0089aed1 100644 --- a/polly/lib/CodeGen/IslCodeGeneration.cpp +++ b/polly/lib/CodeGen/IslCodeGeneration.cpp @@ -58,9 +58,10 @@ using namespace llvm; class IslNodeBuilder { public: - IslNodeBuilder(PollyIRBuilder &Builder, LoopAnnotator &Annotator, Pass *P) + IslNodeBuilder(PollyIRBuilder &Builder, LoopAnnotator &Annotator, Pass *P, + LoopInfo &LI, ScalarEvolution &SE, DominatorTree &DT) : Builder(Builder), Annotator(Annotator), ExprBuilder(Builder, IDToValue), - P(P) {} + P(P), LI(LI), SE(SE), DT(DT) {} /// @brief Add the mappings from array id's to array llvm::Value's. void addMemoryAccesses(Scop &S); @@ -73,6 +74,9 @@ private: LoopAnnotator &Annotator; IslExprBuilder ExprBuilder; Pass *P; + LoopInfo &LI; + ScalarEvolution &SE; + DominatorTree &DT; // This maps an isl_id* to the Value* it has in the generated program. For now // on, the only isl_ids that are stored here are the newly calculated loop @@ -239,7 +243,7 @@ void IslNodeBuilder::createUserVector(__isl_take isl_ast_node *User, isl_map *S = isl_map_from_union_map(Schedule); createSubstitutionsVector(Expr, Stmt, VectorMap, VLTS, IVS, IteratorID); - VectorBlockGenerator::generate(Builder, *Stmt, VectorMap, VLTS, S, P); + VectorBlockGenerator::generate(Builder, *Stmt, VectorMap, VLTS, S, P, LI, SE); isl_map_free(S); isl_id_free(Id); @@ -350,8 +354,8 @@ void IslNodeBuilder::createForSequential(__isl_take isl_ast_node *For) { if (MaxType != ValueInc->getType()) ValueInc = Builder.CreateSExt(ValueInc, MaxType); - IV = createLoop(ValueLB, ValueUB, ValueInc, Builder, P, ExitBlock, Predicate, - &Annotator, Parallel); + IV = createLoop(ValueLB, ValueUB, ValueInc, Builder, P, LI, DT, ExitBlock, + Predicate, &Annotator, Parallel); IDToValue[IteratorID] = IV; create(Body); @@ -395,12 +399,10 @@ void IslNodeBuilder::createIf(__isl_take isl_ast_node *If) { BasicBlock *ThenBB = BasicBlock::Create(Context, "polly.then", F); BasicBlock *ElseBB = BasicBlock::Create(Context, "polly.else", F); - DominatorTree &DT = P->getAnalysis().getDomTree(); DT.addNewBlock(ThenBB, CondBB); DT.addNewBlock(ElseBB, CondBB); DT.changeImmediateDominator(MergeBB, CondBB); - LoopInfo &LI = P->getAnalysis(); Loop *L = LI.getLoopFor(CondBB); if (L) { L->addBasicBlockToLoop(ThenBB, LI.getBase()); @@ -490,7 +492,7 @@ void IslNodeBuilder::createUser(__isl_take isl_ast_node *User) { Stmt = (ScopStmt *)isl_id_get_user(Id); createSubstitutions(Expr, Stmt, VMap, LTS); - BlockGenerator::generate(Builder, *Stmt, VMap, LTS, P, + BlockGenerator::generate(Builder, *Stmt, VMap, LTS, P, LI, SE, IslAstInfo::getBuild(User), &ExprBuilder); isl_ast_node_free(User); @@ -529,7 +531,7 @@ void IslNodeBuilder::create(__isl_take isl_ast_node *Node) { } void IslNodeBuilder::addParameters(__isl_take isl_set *Context) { - SCEVExpander Rewriter(P->getAnalysis(), "polly"); + SCEVExpander Rewriter(SE, "polly"); for (unsigned i = 0; i < isl_set_dim(Context, isl_dim_param); ++i) { isl_id *Id; @@ -567,7 +569,10 @@ public: IslCodeGeneration() : ScopPass(ID) {} bool runOnScop(Scop &S) { + LoopInfo &LI = getAnalysis(); IslAstInfo &AstInfo = getAnalysis(); + ScalarEvolution &SE = getAnalysis(); + DominatorTree &DT = getAnalysis().getDomTree(); assert(!S.getRegion().isTopLevelRegion() && "Top level regions are not supported"); @@ -581,7 +586,7 @@ public: polly::IRInserter(Annotator)); Builder.SetInsertPoint(StartBlock->begin()); - IslNodeBuilder NodeBuilder(Builder, Annotator, this); + IslNodeBuilder NodeBuilder(Builder, Annotator, this, LI, SE, DT); Builder.SetInsertPoint(StartBlock->getSinglePredecessor()->begin()); NodeBuilder.addMemoryAccesses(S); diff --git a/polly/lib/CodeGen/LoopGenerators.cpp b/polly/lib/CodeGen/LoopGenerators.cpp index 432960d2b85a..4eaaac0bc6da 100644 --- a/polly/lib/CodeGen/LoopGenerators.cpp +++ b/polly/lib/CodeGen/LoopGenerators.cpp @@ -47,11 +47,10 @@ using namespace polly; // TODO: We currently always create the GuardBB. If we can prove the loop is // always executed at least once, we can get rid of this branch. Value *polly::createLoop(Value *LB, Value *UB, Value *Stride, - PollyIRBuilder &Builder, Pass *P, BasicBlock *&ExitBB, + PollyIRBuilder &Builder, Pass *P, LoopInfo &LI, + DominatorTree &DT, BasicBlock *&ExitBB, ICmpInst::Predicate Predicate, LoopAnnotator *Annotator, bool Parallel) { - DominatorTree &DT = P->getAnalysis().getDomTree(); - LoopInfo &LI = P->getAnalysis(); Function *F = Builder.GetInsertBlock()->getParent(); LLVMContext &Context = F->getContext(); @@ -321,7 +320,8 @@ Value *OMPGenerator::createSubfunction(Value *Stride, Value *StructData, Builder.CreateBr(CheckNextBB); Builder.SetInsertPoint(--Builder.GetInsertPoint()); - IV = createLoop(LowerBound, UpperBound, Stride, Builder, P, AfterBB, + LoopInfo &LI = P->getAnalysis(); + IV = createLoop(LowerBound, UpperBound, Stride, Builder, P, LI, DT, AfterBB, ICmpInst::ICMP_SLE); BasicBlock::iterator LoopBody = Builder.GetInsertPoint();