From 9744c4af1618d3232b7ff5b4d04d39501f4ff079 Mon Sep 17 00:00:00 2001 From: Johannes Doerfert Date: Tue, 12 Aug 2014 18:35:54 +0000 Subject: [Refactor] Cleanup runtime code generation + Use regexp in two test case. + Refactor the runtime condition build function llvm-svn: 215466 --- polly/lib/CodeGen/IslCodeGeneration.cpp | 67 +++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 25 deletions(-) (limited to 'polly/lib/CodeGen/IslCodeGeneration.cpp') diff --git a/polly/lib/CodeGen/IslCodeGeneration.cpp b/polly/lib/CodeGen/IslCodeGeneration.cpp index 71ca0089aed..9cf8bf89faa 100644 --- a/polly/lib/CodeGen/IslCodeGeneration.cpp +++ b/polly/lib/CodeGen/IslCodeGeneration.cpp @@ -568,41 +568,58 @@ public: IslCodeGeneration() : ScopPass(ID) {} + /// @name The analysis passes we need to generate code. + /// + ///{ + LoopInfo *LI; + IslAstInfo *AI; + DominatorTree *DT; + ScalarEvolution *SE; + ///} + + /// @brief The loop anotator to generate llvm.loop metadata. + LoopAnnotator Annotator; + + /// @brief Build the delinearization runtime condition. + /// + /// Build the condition that evaluates at run-time to true iff all + /// delinearization assumptions taken for the SCoP hold, and to zero + /// otherwise. + /// + /// @return A value evaluating to true/false if delinarization is save/unsave. + Value *buildRTC(PollyIRBuilder &Builder, IslExprBuilder &ExprBuilder) { + Builder.SetInsertPoint(Builder.GetInsertBlock()->getTerminator()); + Value *RTC = ExprBuilder.create(AI->getRunCondition()); + return Builder.CreateIsNotNull(RTC); + } + bool runOnScop(Scop &S) { - LoopInfo &LI = getAnalysis(); - IslAstInfo &AstInfo = getAnalysis(); - ScalarEvolution &SE = getAnalysis(); - DominatorTree &DT = getAnalysis().getDomTree(); + LI = &getAnalysis(); + AI = &getAnalysis(); + DT = &getAnalysis().getDomTree(); + SE = &getAnalysis(); assert(!S.getRegion().isTopLevelRegion() && "Top level regions are not supported"); - simplifyRegion(&S, this); + PollyIRBuilder Builder = + createPollyIRBuilder(S.getRegionEntry(), Annotator); - BasicBlock *StartBlock = executeScopConditionally(S, this); - isl_ast_node *Ast = AstInfo.getAst(); - LoopAnnotator Annotator; - PollyIRBuilder Builder(StartBlock->getContext(), llvm::ConstantFolder(), - polly::IRInserter(Annotator)); - Builder.SetInsertPoint(StartBlock->begin()); - - IslNodeBuilder NodeBuilder(Builder, Annotator, this, LI, SE, DT); - - Builder.SetInsertPoint(StartBlock->getSinglePredecessor()->begin()); + IslNodeBuilder NodeBuilder(Builder, Annotator, this, *LI, *SE, *DT); NodeBuilder.addMemoryAccesses(S); NodeBuilder.addParameters(S.getContext()); - // Build condition that evaluates at run-time if all assumptions taken - // for the scop hold. If we detect some assumptions do not hold, the - // original code is executed. - Value *V = NodeBuilder.getExprBuilder().create(AstInfo.getRunCondition()); - Value *Zero = ConstantInt::get(V->getType(), 0); - V = Builder.CreateICmp(CmpInst::ICMP_NE, Zero, V); - BasicBlock *PrevBB = StartBlock->getUniquePredecessor(); - BranchInst *Branch = dyn_cast(PrevBB->getTerminator()); - Branch->setCondition(V); + + simplifyRegion(&S, this); + Builder.SetInsertPoint( + S.getRegion().getEnteringBlock()->getFirstInsertionPt()); + + Value *RTC = buildRTC(Builder, NodeBuilder.getExprBuilder()); + BasicBlock *StartBlock = executeScopConditionally(S, this, RTC); Builder.SetInsertPoint(StartBlock->begin()); - NodeBuilder.create(Ast); + NodeBuilder.create(AI->getAst()); + + DEBUG(StartBlock->getParent()->dump()); return true; } -- cgit v1.2.3