109d30697STobias Grosser //===------ CodeGeneration.cpp - Code generate the Scops using ISL. ----======// 209d30697STobias Grosser // 309d30697STobias Grosser // The LLVM Compiler Infrastructure 409d30697STobias Grosser // 509d30697STobias Grosser // This file is distributed under the University of Illinois Open Source 609d30697STobias Grosser // License. See LICENSE.TXT for details. 709d30697STobias Grosser // 809d30697STobias Grosser //===----------------------------------------------------------------------===// 909d30697STobias Grosser // 1009d30697STobias Grosser // The CodeGeneration pass takes a Scop created by ScopInfo and translates it 1109d30697STobias Grosser // back to LLVM-IR using the ISL code generator. 1209d30697STobias Grosser // 13a6d48f59SMichael Kruse // The Scop describes the high level memory behavior of a control flow region. 1409d30697STobias Grosser // Transformation passes can update the schedule (execution order) of statements 1509d30697STobias Grosser // in the Scop. ISL is used to generate an abstract syntax tree that reflects 1609d30697STobias Grosser // the updated execution order. This clast is used to create new LLVM-IR that is 1709d30697STobias Grosser // computationally equivalent to the original control flow region, but executes 1809d30697STobias Grosser // its code in the new execution order defined by the changed schedule. 1909d30697STobias Grosser // 2009d30697STobias Grosser //===----------------------------------------------------------------------===// 2109d30697STobias Grosser 2278ae52f0SPhilip Pfaffe #include "polly/CodeGen/CodeGeneration.h" 2309d30697STobias Grosser #include "polly/CodeGen/IslAst.h" 245624d3c9STobias Grosser #include "polly/CodeGen/IslNodeBuilder.h" 2565371af2STobias Grosser #include "polly/CodeGen/PerfMonitor.h" 2609d30697STobias Grosser #include "polly/CodeGen/Utils.h" 2709d30697STobias Grosser #include "polly/DependenceInfo.h" 2809d30697STobias Grosser #include "polly/LinkAllPasses.h" 2958e58544STobias Grosser #include "polly/Options.h" 3009d30697STobias Grosser #include "polly/ScopInfo.h" 3109d30697STobias Grosser #include "polly/Support/ScopHelper.h" 3266ef16b2SChandler Carruth #include "llvm/Analysis/AliasAnalysis.h" 3366ef16b2SChandler Carruth #include "llvm/Analysis/BasicAliasAnalysis.h" 3466ef16b2SChandler Carruth #include "llvm/Analysis/GlobalsModRef.h" 3578ae52f0SPhilip Pfaffe #include "llvm/Analysis/LoopInfo.h" 3666ef16b2SChandler Carruth #include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h" 37c2bb0cbeSTobias Grosser #include "llvm/IR/Module.h" 3878ae52f0SPhilip Pfaffe #include "llvm/IR/PassManager.h" 39c2bb0cbeSTobias Grosser #include "llvm/IR/Verifier.h" 40c2bb0cbeSTobias Grosser #include "llvm/Support/Debug.h" 4109d30697STobias Grosser 4209d30697STobias Grosser using namespace polly; 4309d30697STobias Grosser using namespace llvm; 4409d30697STobias Grosser 4509d30697STobias Grosser #define DEBUG_TYPE "polly-codegen" 4609d30697STobias Grosser 4758e58544STobias Grosser static cl::opt<bool> Verify("polly-codegen-verify", 4858e58544STobias Grosser cl::desc("Verify the function generated by Polly"), 49f1372217STobias Grosser cl::Hidden, cl::init(false), cl::ZeroOrMore, 5058e58544STobias Grosser cl::cat(PollyCategory)); 5158e58544STobias Grosser 527b9f5ca2SSiddharth Bhat bool polly::PerfMonitoring; 537b9f5ca2SSiddharth Bhat static cl::opt<bool, true> 547b9f5ca2SSiddharth Bhat XPerfMonitoring("polly-codegen-perf-monitoring", 5565371af2STobias Grosser cl::desc("Add run-time performance monitoring"), cl::Hidden, 567b9f5ca2SSiddharth Bhat cl::location(polly::PerfMonitoring), cl::init(false), 577b9f5ca2SSiddharth Bhat cl::ZeroOrMore, cl::cat(PollyCategory)); 5865371af2STobias Grosser 59*06ed5292SMichael Kruse STATISTIC(ScopsProcessed, "Number of SCoP processed"); 60*06ed5292SMichael Kruse STATISTIC(CodegenedScops, "Number of successfully generated SCoPs"); 61*06ed5292SMichael Kruse STATISTIC(CodegenedAffineLoops, 62*06ed5292SMichael Kruse "Number of original affine loops in SCoPs that have been generated"); 63*06ed5292SMichael Kruse STATISTIC(CodegenedBoxedLoops, 64*06ed5292SMichael Kruse "Number of original boxed loops in SCoPs that have been generated"); 65*06ed5292SMichael Kruse 6671dfb3ebSSiddharth Bhat namespace polly { 6771dfb3ebSSiddharth Bhat /// Mark a basic block unreachable. 6871dfb3ebSSiddharth Bhat /// 6971dfb3ebSSiddharth Bhat /// Marks the basic block @p Block unreachable by equipping it with an 7071dfb3ebSSiddharth Bhat /// UnreachableInst. 7171dfb3ebSSiddharth Bhat void markBlockUnreachable(BasicBlock &Block, PollyIRBuilder &Builder) { 7271dfb3ebSSiddharth Bhat auto *OrigTerminator = Block.getTerminator(); 7371dfb3ebSSiddharth Bhat Builder.SetInsertPoint(OrigTerminator); 7471dfb3ebSSiddharth Bhat Builder.CreateUnreachable(); 7571dfb3ebSSiddharth Bhat OrigTerminator->eraseFromParent(); 7671dfb3ebSSiddharth Bhat } 7771dfb3ebSSiddharth Bhat 7871dfb3ebSSiddharth Bhat } // namespace polly 7971dfb3ebSSiddharth Bhat 8009d30697STobias Grosser namespace { 8109d30697STobias Grosser 8278ae52f0SPhilip Pfaffe static void verifyGeneratedFunction(Scop &S, Function &F, IslAstInfo &AI) { 83d439911fSTobias Grosser if (!Verify || !verifyFunction(F, &errs())) 8458e58544STobias Grosser return; 8509d30697STobias Grosser 8609d30697STobias Grosser DEBUG({ 8709d30697STobias Grosser errs() << "== ISL Codegen created an invalid function ==\n\n== The " 8809d30697STobias Grosser "SCoP ==\n"; 89cd4c977bSMichael Kruse errs() << S; 9009d30697STobias Grosser errs() << "\n== The isl AST ==\n"; 9178ae52f0SPhilip Pfaffe AI.print(errs()); 9209d30697STobias Grosser errs() << "\n== The invalid function ==\n"; 9309d30697STobias Grosser F.print(errs()); 9409d30697STobias Grosser }); 9509d30697STobias Grosser 9658e58544STobias Grosser llvm_unreachable("Polly generated function could not be verified. Add " 9758e58544STobias Grosser "-polly-codegen-verify=false to disable this assertion."); 9809d30697STobias Grosser } 9909d30697STobias Grosser 1009c483c58SMichael Kruse // CodeGeneration adds a lot of BBs without updating the RegionInfo 1019c483c58SMichael Kruse // We make all created BBs belong to the scop's parent region without any 1029c483c58SMichael Kruse // nested structure to keep the RegionInfo verifier happy. 10378ae52f0SPhilip Pfaffe static void fixRegionInfo(Function &F, Region &ParentRegion, RegionInfo &RI) { 10478ae52f0SPhilip Pfaffe for (BasicBlock &BB : F) { 10578ae52f0SPhilip Pfaffe if (RI.getRegionFor(&BB)) 1069c483c58SMichael Kruse continue; 1079c483c58SMichael Kruse 10878ae52f0SPhilip Pfaffe RI.setRegionFor(&BB, &ParentRegion); 1099c483c58SMichael Kruse } 1109c483c58SMichael Kruse } 1119c483c58SMichael Kruse 112895f5d80SMichael Kruse /// Remove all lifetime markers (llvm.lifetime.start, llvm.lifetime.end) from 113895f5d80SMichael Kruse /// @R. 114895f5d80SMichael Kruse /// 115895f5d80SMichael Kruse /// CodeGeneration does not copy lifetime markers into the optimized SCoP, 116895f5d80SMichael Kruse /// which would leave the them only in the original path. This can transform 117895f5d80SMichael Kruse /// code such as 118895f5d80SMichael Kruse /// 119895f5d80SMichael Kruse /// llvm.lifetime.start(%p) 120895f5d80SMichael Kruse /// llvm.lifetime.end(%p) 121895f5d80SMichael Kruse /// 122895f5d80SMichael Kruse /// into 123895f5d80SMichael Kruse /// 124895f5d80SMichael Kruse /// if (RTC) { 125895f5d80SMichael Kruse /// // generated code 126895f5d80SMichael Kruse /// } else { 127895f5d80SMichael Kruse /// // original code 128895f5d80SMichael Kruse /// llvm.lifetime.start(%p) 129895f5d80SMichael Kruse /// } 130895f5d80SMichael Kruse /// llvm.lifetime.end(%p) 131895f5d80SMichael Kruse /// 132895f5d80SMichael Kruse /// The current StackColoring algorithm cannot handle if some, but not all, 133895f5d80SMichael Kruse /// paths from the end marker to the entry block cross the start marker. Same 134895f5d80SMichael Kruse /// for start markers that do not always cross the end markers. We avoid any 135895f5d80SMichael Kruse /// issues by removing all lifetime markers, even from the original code. 136895f5d80SMichael Kruse /// 137895f5d80SMichael Kruse /// A better solution could be to hoist all llvm.lifetime.start to the split 138895f5d80SMichael Kruse /// node and all llvm.lifetime.end to the merge node, which should be 139895f5d80SMichael Kruse /// conservatively correct. 14078ae52f0SPhilip Pfaffe static void removeLifetimeMarkers(Region *R) { 141895f5d80SMichael Kruse for (auto *BB : R->blocks()) { 142895f5d80SMichael Kruse auto InstIt = BB->begin(); 143895f5d80SMichael Kruse auto InstEnd = BB->end(); 144895f5d80SMichael Kruse 145895f5d80SMichael Kruse while (InstIt != InstEnd) { 146895f5d80SMichael Kruse auto NextIt = InstIt; 147895f5d80SMichael Kruse ++NextIt; 148895f5d80SMichael Kruse 149895f5d80SMichael Kruse if (auto *IT = dyn_cast<IntrinsicInst>(&*InstIt)) { 150895f5d80SMichael Kruse switch (IT->getIntrinsicID()) { 151895f5d80SMichael Kruse case llvm::Intrinsic::lifetime_start: 152895f5d80SMichael Kruse case llvm::Intrinsic::lifetime_end: 153895f5d80SMichael Kruse BB->getInstList().erase(InstIt); 154895f5d80SMichael Kruse break; 155895f5d80SMichael Kruse default: 156895f5d80SMichael Kruse break; 157895f5d80SMichael Kruse } 158895f5d80SMichael Kruse } 159895f5d80SMichael Kruse 160895f5d80SMichael Kruse InstIt = NextIt; 161895f5d80SMichael Kruse } 162895f5d80SMichael Kruse } 163895f5d80SMichael Kruse } 164895f5d80SMichael Kruse 16578ae52f0SPhilip Pfaffe static bool CodeGen(Scop &S, IslAstInfo &AI, LoopInfo &LI, DominatorTree &DT, 16678ae52f0SPhilip Pfaffe ScalarEvolution &SE, RegionInfo &RI) { 16709d30697STobias Grosser // Check if we created an isl_ast root node, otherwise exit. 16878ae52f0SPhilip Pfaffe isl_ast_node *AstRoot = AI.getAst(); 16909d30697STobias Grosser if (!AstRoot) 17009d30697STobias Grosser return false; 17109d30697STobias Grosser 172*06ed5292SMichael Kruse // Collect statistics. Do it before we modify the IR to avoid having it any 173*06ed5292SMichael Kruse // influence on the result. 174*06ed5292SMichael Kruse auto ScopStats = S.getStatistics(); 175*06ed5292SMichael Kruse ScopsProcessed++; 176*06ed5292SMichael Kruse 17778ae52f0SPhilip Pfaffe auto &DL = S.getFunction().getParent()->getDataLayout(); 17822370884SMichael Kruse Region *R = &S.getRegion(); 17922370884SMichael Kruse assert(!R->isTopLevelRegion() && "Top level regions are not supported"); 18009d30697STobias Grosser 181d78616f9STobias Grosser ScopAnnotator Annotator; 18209d30697STobias Grosser 18378ae52f0SPhilip Pfaffe simplifyRegion(R, &DT, &LI, &RI); 18422370884SMichael Kruse assert(R->isSimple()); 185ef74443cSJohannes Doerfert BasicBlock *EnteringBB = S.getEnteringBlock(); 18622370884SMichael Kruse assert(EnteringBB); 18709d30697STobias Grosser PollyIRBuilder Builder = createPollyIRBuilder(EnteringBB, Annotator); 18809d30697STobias Grosser 18909d30697STobias Grosser // Only build the run-time condition and parameters _after_ having 19009d30697STobias Grosser // introduced the conditional branch. This is important as the conditional 19109d30697STobias Grosser // branch will guard the original scop from new induction variables that 19209d30697STobias Grosser // the SCEVExpander may introduce while code generating the parameters and 19309d30697STobias Grosser // which may introduce scalar dependences that prevent us from correctly 19409d30697STobias Grosser // code generating this scop. 195256070d8SAndreas Simbuerger BBPair StartExitBlocks = 19603346c27SSiddharth Bhat std::get<0>(executeScopConditionally(S, Builder.getTrue(), DT, RI, LI)); 197256070d8SAndreas Simbuerger BasicBlock *StartBlock = std::get<0>(StartExitBlocks); 198dbb0ef8eSAndreas Simbuerger BasicBlock *ExitBlock = std::get<1>(StartExitBlocks); 199256070d8SAndreas Simbuerger 200895f5d80SMichael Kruse removeLifetimeMarkers(R); 201bfb6a968STobias Grosser auto *SplitBlock = StartBlock->getSinglePredecessor(); 20209e3697fSJohannes Doerfert 20378ae52f0SPhilip Pfaffe IslNodeBuilder NodeBuilder(Builder, Annotator, DL, LI, SE, DT, S, StartBlock); 204acf80064SEli Friedman 205214deb79SMichael Kruse // All arrays must have their base pointers known before 206214deb79SMichael Kruse // ScopAnnotator::buildAliasScopes. 207b738ffa8SMichael Kruse NodeBuilder.allocateNewArrays(StartExitBlocks); 208214deb79SMichael Kruse Annotator.buildAliasScopes(S); 209214deb79SMichael Kruse 21065371af2STobias Grosser if (PerfMonitoring) { 21107bee290SSiddharth Bhat PerfMonitor P(S, EnteringBB->getParent()->getParent()); 21265371af2STobias Grosser P.initialize(); 21365371af2STobias Grosser P.insertRegionStart(SplitBlock->getTerminator()); 21465371af2STobias Grosser 215dbb0ef8eSAndreas Simbuerger BasicBlock *MergeBlock = ExitBlock->getUniqueSuccessor(); 21665371af2STobias Grosser P.insertRegionEnd(MergeBlock->getTerminator()); 21765371af2STobias Grosser } 21865371af2STobias Grosser 21909e3697fSJohannes Doerfert // First generate code for the hoisted invariant loads and transitively the 22009e3697fSJohannes Doerfert // parameters they reference. Afterwards, for the remaining parameters that 22109e3697fSJohannes Doerfert // might reference the hoisted loads. Finally, build the runtime check 22209e3697fSJohannes Doerfert // that might reference both hoisted loads as well as parameters. 223c4898504SJohannes Doerfert // If the hoisting fails we have to bail and execute the original code. 22409d30697STobias Grosser Builder.SetInsertPoint(SplitBlock->getTerminator()); 225c4898504SJohannes Doerfert if (!NodeBuilder.preloadInvariantLoads()) { 2261dd6e37aSJohannes Doerfert 227bfb6a968STobias Grosser // Patch the introduced branch condition to ensure that we always execute 228bfb6a968STobias Grosser // the original SCoP. 229c4898504SJohannes Doerfert auto *FalseI1 = Builder.getFalse(); 23037977076SJohannes Doerfert auto *SplitBBTerm = Builder.GetInsertBlock()->getTerminator(); 23137977076SJohannes Doerfert SplitBBTerm->setOperand(0, FalseI1); 2321dd6e37aSJohannes Doerfert 233bfb6a968STobias Grosser // Since the other branch is hence ignored we mark it as unreachable and 234bfb6a968STobias Grosser // adjust the dominator tree accordingly. 235bfb6a968STobias Grosser auto *ExitingBlock = StartBlock->getUniqueSuccessor(); 236bfb6a968STobias Grosser assert(ExitingBlock); 237bfb6a968STobias Grosser auto *MergeBlock = ExitingBlock->getUniqueSuccessor(); 238bfb6a968STobias Grosser assert(MergeBlock); 239bfb6a968STobias Grosser markBlockUnreachable(*StartBlock, Builder); 240bfb6a968STobias Grosser markBlockUnreachable(*ExitingBlock, Builder); 241ef74443cSJohannes Doerfert auto *ExitingBB = S.getExitingBlock(); 242bfb6a968STobias Grosser assert(ExitingBB); 24378ae52f0SPhilip Pfaffe DT.changeImmediateDominator(MergeBlock, ExitingBB); 24478ae52f0SPhilip Pfaffe DT.eraseNode(ExitingBlock); 245bfb6a968STobias Grosser 246bfb6a968STobias Grosser isl_ast_node_free(AstRoot); 2471dd6e37aSJohannes Doerfert } else { 2488ea1fc19STobias Grosser NodeBuilder.addParameters(S.getContext().release()); 24978ae52f0SPhilip Pfaffe Value *RTC = NodeBuilder.createRTC(AI.getRunCondition()); 250404a0f81SJohannes Doerfert 2513717aa5dSTobias Grosser Builder.GetInsertBlock()->getTerminator()->setOperand(0, RTC); 252b738ffa8SMichael Kruse 253b738ffa8SMichael Kruse // Explicitly set the insert point to the end of the block to avoid that a 254b738ffa8SMichael Kruse // split at the builder's current 255b738ffa8SMichael Kruse // insert position would move the malloc calls to the wrong BasicBlock. 256b738ffa8SMichael Kruse // Ideally we would just split the block during allocation of the new 257b738ffa8SMichael Kruse // arrays, but this would break the assumption that there are no blocks 258b738ffa8SMichael Kruse // between polly.start and polly.exiting (at this point). 259b738ffa8SMichael Kruse Builder.SetInsertPoint(StartBlock->getTerminator()); 2603717aa5dSTobias Grosser 2613717aa5dSTobias Grosser NodeBuilder.create(AstRoot); 2628ed5e599STobias Grosser NodeBuilder.finalize(); 26378ae52f0SPhilip Pfaffe fixRegionInfo(*EnteringBB->getParent(), *R->getParent(), RI); 264*06ed5292SMichael Kruse 265*06ed5292SMichael Kruse CodegenedScops++; 266*06ed5292SMichael Kruse CodegenedAffineLoops += ScopStats.NumAffineLoops; 267*06ed5292SMichael Kruse CodegenedBoxedLoops += ScopStats.NumBoxedLoops; 2681dd6e37aSJohannes Doerfert } 269ecff11dcSJohannes Doerfert 2706a6a671cSJohannes Doerfert Function *F = EnteringBB->getParent(); 27178ae52f0SPhilip Pfaffe verifyGeneratedFunction(S, *F, AI); 272a9dc5294SJohannes Doerfert for (auto *SubF : NodeBuilder.getParallelSubfunctions()) 27378ae52f0SPhilip Pfaffe verifyGeneratedFunction(S, *SubF, AI); 274652f7808STobias Grosser 2754c86a1d9SMichael Kruse // Mark the function such that we run additional cleanup passes on this 2764c86a1d9SMichael Kruse // function (e.g. mem2reg to rediscover phi nodes). 2774c86a1d9SMichael Kruse F->addFnAttr("polly-optimized"); 27809d30697STobias Grosser return true; 27909d30697STobias Grosser } 28009d30697STobias Grosser 28178ae52f0SPhilip Pfaffe class CodeGeneration : public ScopPass { 28278ae52f0SPhilip Pfaffe public: 28378ae52f0SPhilip Pfaffe static char ID; 28478ae52f0SPhilip Pfaffe 28578ae52f0SPhilip Pfaffe CodeGeneration() : ScopPass(ID) {} 28678ae52f0SPhilip Pfaffe 287a6d48f59SMichael Kruse /// The data layout used. 28878ae52f0SPhilip Pfaffe const DataLayout *DL; 28978ae52f0SPhilip Pfaffe 29078ae52f0SPhilip Pfaffe /// @name The analysis passes we need to generate code. 29178ae52f0SPhilip Pfaffe /// 29278ae52f0SPhilip Pfaffe ///{ 29378ae52f0SPhilip Pfaffe LoopInfo *LI; 29478ae52f0SPhilip Pfaffe IslAstInfo *AI; 29578ae52f0SPhilip Pfaffe DominatorTree *DT; 29678ae52f0SPhilip Pfaffe ScalarEvolution *SE; 29778ae52f0SPhilip Pfaffe RegionInfo *RI; 29878ae52f0SPhilip Pfaffe ///} 29978ae52f0SPhilip Pfaffe 30078ae52f0SPhilip Pfaffe /// Generate LLVM-IR for the SCoP @p S. 30178ae52f0SPhilip Pfaffe bool runOnScop(Scop &S) override { 30202ca346eSSingapuram Sanjay Srivallabh // Skip SCoPs in case they're already code-generated by PPCGCodeGeneration. 30302ca346eSSingapuram Sanjay Srivallabh if (S.isToBeSkipped()) 30402ca346eSSingapuram Sanjay Srivallabh return false; 30502ca346eSSingapuram Sanjay Srivallabh 30678ae52f0SPhilip Pfaffe AI = &getAnalysis<IslAstInfoWrapperPass>().getAI(); 30778ae52f0SPhilip Pfaffe LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo(); 30878ae52f0SPhilip Pfaffe DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree(); 30978ae52f0SPhilip Pfaffe SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE(); 31078ae52f0SPhilip Pfaffe DL = &S.getFunction().getParent()->getDataLayout(); 31178ae52f0SPhilip Pfaffe RI = &getAnalysis<RegionInfoPass>().getRegionInfo(); 31278ae52f0SPhilip Pfaffe return CodeGen(S, *AI, *LI, *DT, *SE, *RI); 31378ae52f0SPhilip Pfaffe } 31478ae52f0SPhilip Pfaffe 315c80d6979STobias Grosser /// Register all analyses and transformation required. 31609d30697STobias Grosser void getAnalysisUsage(AnalysisUsage &AU) const override { 31709d30697STobias Grosser AU.addRequired<DominatorTreeWrapperPass>(); 3182b852e2eSPhilip Pfaffe AU.addRequired<IslAstInfoWrapperPass>(); 31909d30697STobias Grosser AU.addRequired<RegionInfoPass>(); 320c5bcf246STobias Grosser AU.addRequired<ScalarEvolutionWrapperPass>(); 3215cc87e3aSPhilip Pfaffe AU.addRequired<ScopDetectionWrapperPass>(); 32299191c78SJohannes Doerfert AU.addRequired<ScopInfoRegionPass>(); 32309d30697STobias Grosser AU.addRequired<LoopInfoWrapperPass>(); 32409d30697STobias Grosser 32509d30697STobias Grosser AU.addPreserved<DependenceInfo>(); 32609d30697STobias Grosser 32766ef16b2SChandler Carruth AU.addPreserved<AAResultsWrapperPass>(); 32866ef16b2SChandler Carruth AU.addPreserved<BasicAAWrapperPass>(); 32909d30697STobias Grosser AU.addPreserved<LoopInfoWrapperPass>(); 33009d30697STobias Grosser AU.addPreserved<DominatorTreeWrapperPass>(); 33166ef16b2SChandler Carruth AU.addPreserved<GlobalsAAWrapperPass>(); 3322b852e2eSPhilip Pfaffe AU.addPreserved<IslAstInfoWrapperPass>(); 3335cc87e3aSPhilip Pfaffe AU.addPreserved<ScopDetectionWrapperPass>(); 334c5bcf246STobias Grosser AU.addPreserved<ScalarEvolutionWrapperPass>(); 33566ef16b2SChandler Carruth AU.addPreserved<SCEVAAWrapperPass>(); 33609d30697STobias Grosser 33709d30697STobias Grosser // FIXME: We do not yet add regions for the newly generated code to the 33809d30697STobias Grosser // region tree. 33909d30697STobias Grosser AU.addPreserved<RegionInfoPass>(); 34099191c78SJohannes Doerfert AU.addPreserved<ScopInfoRegionPass>(); 34109d30697STobias Grosser } 34209d30697STobias Grosser }; 343522478d2STobias Grosser } // namespace 34409d30697STobias Grosser 34578ae52f0SPhilip Pfaffe PreservedAnalyses 34678ae52f0SPhilip Pfaffe polly::CodeGenerationPass::run(Scop &S, ScopAnalysisManager &SAM, 34778ae52f0SPhilip Pfaffe ScopStandardAnalysisResults &AR, SPMUpdater &U) { 34878ae52f0SPhilip Pfaffe auto &AI = SAM.getResult<IslAstAnalysis>(S, AR); 349f43e7c2eSPhilip Pfaffe if (CodeGen(S, AI, AR.LI, AR.DT, AR.SE, AR.RI)) { 350f43e7c2eSPhilip Pfaffe U.invalidateScop(S); 35178ae52f0SPhilip Pfaffe return PreservedAnalyses::none(); 352f43e7c2eSPhilip Pfaffe } 35378ae52f0SPhilip Pfaffe 35478ae52f0SPhilip Pfaffe return PreservedAnalyses::all(); 35578ae52f0SPhilip Pfaffe } 35678ae52f0SPhilip Pfaffe 35709d30697STobias Grosser char CodeGeneration::ID = 1; 35809d30697STobias Grosser 35909d30697STobias Grosser Pass *polly::createCodeGenerationPass() { return new CodeGeneration(); } 36009d30697STobias Grosser 36109d30697STobias Grosser INITIALIZE_PASS_BEGIN(CodeGeneration, "polly-codegen", 36209d30697STobias Grosser "Polly - Create LLVM-IR from SCoPs", false, false); 36309d30697STobias Grosser INITIALIZE_PASS_DEPENDENCY(DependenceInfo); 36409d30697STobias Grosser INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass); 36509d30697STobias Grosser INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass); 36609d30697STobias Grosser INITIALIZE_PASS_DEPENDENCY(RegionInfoPass); 367c5bcf246STobias Grosser INITIALIZE_PASS_DEPENDENCY(ScalarEvolutionWrapperPass); 3685cc87e3aSPhilip Pfaffe INITIALIZE_PASS_DEPENDENCY(ScopDetectionWrapperPass); 36909d30697STobias Grosser INITIALIZE_PASS_END(CodeGeneration, "polly-codegen", 37009d30697STobias Grosser "Polly - Create LLVM-IR from SCoPs", false, false) 371