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 
52*7b9f5ca2SSiddharth Bhat bool polly::PerfMonitoring;
53*7b9f5ca2SSiddharth Bhat static cl::opt<bool, true>
54*7b9f5ca2SSiddharth Bhat     XPerfMonitoring("polly-codegen-perf-monitoring",
5565371af2STobias Grosser                     cl::desc("Add run-time performance monitoring"), cl::Hidden,
56*7b9f5ca2SSiddharth Bhat                     cl::location(polly::PerfMonitoring), cl::init(false),
57*7b9f5ca2SSiddharth Bhat                     cl::ZeroOrMore, cl::cat(PollyCategory));
5865371af2STobias Grosser 
5971dfb3ebSSiddharth Bhat namespace polly {
6071dfb3ebSSiddharth Bhat /// Mark a basic block unreachable.
6171dfb3ebSSiddharth Bhat ///
6271dfb3ebSSiddharth Bhat /// Marks the basic block @p Block unreachable by equipping it with an
6371dfb3ebSSiddharth Bhat /// UnreachableInst.
6471dfb3ebSSiddharth Bhat void markBlockUnreachable(BasicBlock &Block, PollyIRBuilder &Builder) {
6571dfb3ebSSiddharth Bhat   auto *OrigTerminator = Block.getTerminator();
6671dfb3ebSSiddharth Bhat   Builder.SetInsertPoint(OrigTerminator);
6771dfb3ebSSiddharth Bhat   Builder.CreateUnreachable();
6871dfb3ebSSiddharth Bhat   OrigTerminator->eraseFromParent();
6971dfb3ebSSiddharth Bhat }
7071dfb3ebSSiddharth Bhat 
7171dfb3ebSSiddharth Bhat } // namespace polly
7271dfb3ebSSiddharth Bhat 
7309d30697STobias Grosser namespace {
7409d30697STobias Grosser 
7578ae52f0SPhilip Pfaffe static void verifyGeneratedFunction(Scop &S, Function &F, IslAstInfo &AI) {
76d439911fSTobias Grosser   if (!Verify || !verifyFunction(F, &errs()))
7758e58544STobias Grosser     return;
7809d30697STobias Grosser 
7909d30697STobias Grosser   DEBUG({
8009d30697STobias Grosser     errs() << "== ISL Codegen created an invalid function ==\n\n== The "
8109d30697STobias Grosser               "SCoP ==\n";
82cd4c977bSMichael Kruse     errs() << S;
8309d30697STobias Grosser     errs() << "\n== The isl AST ==\n";
8478ae52f0SPhilip Pfaffe     AI.print(errs());
8509d30697STobias Grosser     errs() << "\n== The invalid function ==\n";
8609d30697STobias Grosser     F.print(errs());
8709d30697STobias Grosser   });
8809d30697STobias Grosser 
8958e58544STobias Grosser   llvm_unreachable("Polly generated function could not be verified. Add "
9058e58544STobias Grosser                    "-polly-codegen-verify=false to disable this assertion.");
9109d30697STobias Grosser }
9209d30697STobias Grosser 
939c483c58SMichael Kruse // CodeGeneration adds a lot of BBs without updating the RegionInfo
949c483c58SMichael Kruse // We make all created BBs belong to the scop's parent region without any
959c483c58SMichael Kruse // nested structure to keep the RegionInfo verifier happy.
9678ae52f0SPhilip Pfaffe static void fixRegionInfo(Function &F, Region &ParentRegion, RegionInfo &RI) {
9778ae52f0SPhilip Pfaffe   for (BasicBlock &BB : F) {
9878ae52f0SPhilip Pfaffe     if (RI.getRegionFor(&BB))
999c483c58SMichael Kruse       continue;
1009c483c58SMichael Kruse 
10178ae52f0SPhilip Pfaffe     RI.setRegionFor(&BB, &ParentRegion);
1029c483c58SMichael Kruse   }
1039c483c58SMichael Kruse }
1049c483c58SMichael Kruse 
105895f5d80SMichael Kruse /// Remove all lifetime markers (llvm.lifetime.start, llvm.lifetime.end) from
106895f5d80SMichael Kruse /// @R.
107895f5d80SMichael Kruse ///
108895f5d80SMichael Kruse /// CodeGeneration does not copy lifetime markers into the optimized SCoP,
109895f5d80SMichael Kruse /// which would leave the them only in the original path. This can transform
110895f5d80SMichael Kruse /// code such as
111895f5d80SMichael Kruse ///
112895f5d80SMichael Kruse ///     llvm.lifetime.start(%p)
113895f5d80SMichael Kruse ///     llvm.lifetime.end(%p)
114895f5d80SMichael Kruse ///
115895f5d80SMichael Kruse /// into
116895f5d80SMichael Kruse ///
117895f5d80SMichael Kruse ///     if (RTC) {
118895f5d80SMichael Kruse ///       // generated code
119895f5d80SMichael Kruse ///     } else {
120895f5d80SMichael Kruse ///       // original code
121895f5d80SMichael Kruse ///       llvm.lifetime.start(%p)
122895f5d80SMichael Kruse ///     }
123895f5d80SMichael Kruse ///     llvm.lifetime.end(%p)
124895f5d80SMichael Kruse ///
125895f5d80SMichael Kruse /// The current StackColoring algorithm cannot handle if some, but not all,
126895f5d80SMichael Kruse /// paths from the end marker to the entry block cross the start marker. Same
127895f5d80SMichael Kruse /// for start markers that do not always cross the end markers. We avoid any
128895f5d80SMichael Kruse /// issues by removing all lifetime markers, even from the original code.
129895f5d80SMichael Kruse ///
130895f5d80SMichael Kruse /// A better solution could be to hoist all llvm.lifetime.start to the split
131895f5d80SMichael Kruse /// node and all llvm.lifetime.end to the merge node, which should be
132895f5d80SMichael Kruse /// conservatively correct.
13378ae52f0SPhilip Pfaffe static void removeLifetimeMarkers(Region *R) {
134895f5d80SMichael Kruse   for (auto *BB : R->blocks()) {
135895f5d80SMichael Kruse     auto InstIt = BB->begin();
136895f5d80SMichael Kruse     auto InstEnd = BB->end();
137895f5d80SMichael Kruse 
138895f5d80SMichael Kruse     while (InstIt != InstEnd) {
139895f5d80SMichael Kruse       auto NextIt = InstIt;
140895f5d80SMichael Kruse       ++NextIt;
141895f5d80SMichael Kruse 
142895f5d80SMichael Kruse       if (auto *IT = dyn_cast<IntrinsicInst>(&*InstIt)) {
143895f5d80SMichael Kruse         switch (IT->getIntrinsicID()) {
144895f5d80SMichael Kruse         case llvm::Intrinsic::lifetime_start:
145895f5d80SMichael Kruse         case llvm::Intrinsic::lifetime_end:
146895f5d80SMichael Kruse           BB->getInstList().erase(InstIt);
147895f5d80SMichael Kruse           break;
148895f5d80SMichael Kruse         default:
149895f5d80SMichael Kruse           break;
150895f5d80SMichael Kruse         }
151895f5d80SMichael Kruse       }
152895f5d80SMichael Kruse 
153895f5d80SMichael Kruse       InstIt = NextIt;
154895f5d80SMichael Kruse     }
155895f5d80SMichael Kruse   }
156895f5d80SMichael Kruse }
157895f5d80SMichael Kruse 
15878ae52f0SPhilip Pfaffe static bool CodeGen(Scop &S, IslAstInfo &AI, LoopInfo &LI, DominatorTree &DT,
15978ae52f0SPhilip Pfaffe                     ScalarEvolution &SE, RegionInfo &RI) {
16009d30697STobias Grosser   // Check if we created an isl_ast root node, otherwise exit.
16178ae52f0SPhilip Pfaffe   isl_ast_node *AstRoot = AI.getAst();
16209d30697STobias Grosser   if (!AstRoot)
16309d30697STobias Grosser     return false;
16409d30697STobias Grosser 
16578ae52f0SPhilip Pfaffe   auto &DL = S.getFunction().getParent()->getDataLayout();
16622370884SMichael Kruse   Region *R = &S.getRegion();
16722370884SMichael Kruse   assert(!R->isTopLevelRegion() && "Top level regions are not supported");
16809d30697STobias Grosser 
169d78616f9STobias Grosser   ScopAnnotator Annotator;
17009d30697STobias Grosser 
17178ae52f0SPhilip Pfaffe   simplifyRegion(R, &DT, &LI, &RI);
17222370884SMichael Kruse   assert(R->isSimple());
173ef74443cSJohannes Doerfert   BasicBlock *EnteringBB = S.getEnteringBlock();
17422370884SMichael Kruse   assert(EnteringBB);
17509d30697STobias Grosser   PollyIRBuilder Builder = createPollyIRBuilder(EnteringBB, Annotator);
17609d30697STobias Grosser 
17709d30697STobias Grosser   // Only build the run-time condition and parameters _after_ having
17809d30697STobias Grosser   // introduced the conditional branch. This is important as the conditional
17909d30697STobias Grosser   // branch will guard the original scop from new induction variables that
18009d30697STobias Grosser   // the SCEVExpander may introduce while code generating the parameters and
18109d30697STobias Grosser   // which may introduce scalar dependences that prevent us from correctly
18209d30697STobias Grosser   // code generating this scop.
183256070d8SAndreas Simbuerger   BBPair StartExitBlocks =
18403346c27SSiddharth Bhat       std::get<0>(executeScopConditionally(S, Builder.getTrue(), DT, RI, LI));
185256070d8SAndreas Simbuerger   BasicBlock *StartBlock = std::get<0>(StartExitBlocks);
186dbb0ef8eSAndreas Simbuerger   BasicBlock *ExitBlock = std::get<1>(StartExitBlocks);
187256070d8SAndreas Simbuerger 
188895f5d80SMichael Kruse   removeLifetimeMarkers(R);
189bfb6a968STobias Grosser   auto *SplitBlock = StartBlock->getSinglePredecessor();
19009e3697fSJohannes Doerfert 
19178ae52f0SPhilip Pfaffe   IslNodeBuilder NodeBuilder(Builder, Annotator, DL, LI, SE, DT, S, StartBlock);
192acf80064SEli Friedman 
193214deb79SMichael Kruse   // All arrays must have their base pointers known before
194214deb79SMichael Kruse   // ScopAnnotator::buildAliasScopes.
195b738ffa8SMichael Kruse   NodeBuilder.allocateNewArrays(StartExitBlocks);
196214deb79SMichael Kruse   Annotator.buildAliasScopes(S);
197214deb79SMichael Kruse 
19865371af2STobias Grosser   if (PerfMonitoring) {
19907bee290SSiddharth Bhat     PerfMonitor P(S, EnteringBB->getParent()->getParent());
20065371af2STobias Grosser     P.initialize();
20165371af2STobias Grosser     P.insertRegionStart(SplitBlock->getTerminator());
20265371af2STobias Grosser 
203dbb0ef8eSAndreas Simbuerger     BasicBlock *MergeBlock = ExitBlock->getUniqueSuccessor();
20465371af2STobias Grosser     P.insertRegionEnd(MergeBlock->getTerminator());
20565371af2STobias Grosser   }
20665371af2STobias Grosser 
20709e3697fSJohannes Doerfert   // First generate code for the hoisted invariant loads and transitively the
20809e3697fSJohannes Doerfert   // parameters they reference. Afterwards, for the remaining parameters that
20909e3697fSJohannes Doerfert   // might reference the hoisted loads. Finally, build the runtime check
21009e3697fSJohannes Doerfert   // that might reference both hoisted loads as well as parameters.
211c4898504SJohannes Doerfert   // If the hoisting fails we have to bail and execute the original code.
21209d30697STobias Grosser   Builder.SetInsertPoint(SplitBlock->getTerminator());
213c4898504SJohannes Doerfert   if (!NodeBuilder.preloadInvariantLoads()) {
2141dd6e37aSJohannes Doerfert 
215bfb6a968STobias Grosser     // Patch the introduced branch condition to ensure that we always execute
216bfb6a968STobias Grosser     // the original SCoP.
217c4898504SJohannes Doerfert     auto *FalseI1 = Builder.getFalse();
21837977076SJohannes Doerfert     auto *SplitBBTerm = Builder.GetInsertBlock()->getTerminator();
21937977076SJohannes Doerfert     SplitBBTerm->setOperand(0, FalseI1);
2201dd6e37aSJohannes Doerfert 
221bfb6a968STobias Grosser     // Since the other branch is hence ignored we mark it as unreachable and
222bfb6a968STobias Grosser     // adjust the dominator tree accordingly.
223bfb6a968STobias Grosser     auto *ExitingBlock = StartBlock->getUniqueSuccessor();
224bfb6a968STobias Grosser     assert(ExitingBlock);
225bfb6a968STobias Grosser     auto *MergeBlock = ExitingBlock->getUniqueSuccessor();
226bfb6a968STobias Grosser     assert(MergeBlock);
227bfb6a968STobias Grosser     markBlockUnreachable(*StartBlock, Builder);
228bfb6a968STobias Grosser     markBlockUnreachable(*ExitingBlock, Builder);
229ef74443cSJohannes Doerfert     auto *ExitingBB = S.getExitingBlock();
230bfb6a968STobias Grosser     assert(ExitingBB);
23178ae52f0SPhilip Pfaffe     DT.changeImmediateDominator(MergeBlock, ExitingBB);
23278ae52f0SPhilip Pfaffe     DT.eraseNode(ExitingBlock);
233bfb6a968STobias Grosser 
234bfb6a968STobias Grosser     isl_ast_node_free(AstRoot);
2351dd6e37aSJohannes Doerfert   } else {
2368ea1fc19STobias Grosser     NodeBuilder.addParameters(S.getContext().release());
23778ae52f0SPhilip Pfaffe     Value *RTC = NodeBuilder.createRTC(AI.getRunCondition());
238404a0f81SJohannes Doerfert 
2393717aa5dSTobias Grosser     Builder.GetInsertBlock()->getTerminator()->setOperand(0, RTC);
240b738ffa8SMichael Kruse 
241b738ffa8SMichael Kruse     // Explicitly set the insert point to the end of the block to avoid that a
242b738ffa8SMichael Kruse     // split at the builder's current
243b738ffa8SMichael Kruse     // insert position would move the malloc calls to the wrong BasicBlock.
244b738ffa8SMichael Kruse     // Ideally we would just split the block during allocation of the new
245b738ffa8SMichael Kruse     // arrays, but this would break the assumption that there are no blocks
246b738ffa8SMichael Kruse     // between polly.start and polly.exiting (at this point).
247b738ffa8SMichael Kruse     Builder.SetInsertPoint(StartBlock->getTerminator());
2483717aa5dSTobias Grosser 
2493717aa5dSTobias Grosser     NodeBuilder.create(AstRoot);
2508ed5e599STobias Grosser     NodeBuilder.finalize();
25178ae52f0SPhilip Pfaffe     fixRegionInfo(*EnteringBB->getParent(), *R->getParent(), RI);
2521dd6e37aSJohannes Doerfert   }
253ecff11dcSJohannes Doerfert 
2546a6a671cSJohannes Doerfert   Function *F = EnteringBB->getParent();
25578ae52f0SPhilip Pfaffe   verifyGeneratedFunction(S, *F, AI);
256a9dc5294SJohannes Doerfert   for (auto *SubF : NodeBuilder.getParallelSubfunctions())
25778ae52f0SPhilip Pfaffe     verifyGeneratedFunction(S, *SubF, AI);
258652f7808STobias Grosser 
2594c86a1d9SMichael Kruse   // Mark the function such that we run additional cleanup passes on this
2604c86a1d9SMichael Kruse   // function (e.g. mem2reg to rediscover phi nodes).
2614c86a1d9SMichael Kruse   F->addFnAttr("polly-optimized");
26209d30697STobias Grosser   return true;
26309d30697STobias Grosser }
26409d30697STobias Grosser 
26578ae52f0SPhilip Pfaffe class CodeGeneration : public ScopPass {
26678ae52f0SPhilip Pfaffe public:
26778ae52f0SPhilip Pfaffe   static char ID;
26878ae52f0SPhilip Pfaffe 
26978ae52f0SPhilip Pfaffe   CodeGeneration() : ScopPass(ID) {}
27078ae52f0SPhilip Pfaffe 
271a6d48f59SMichael Kruse   /// The data layout used.
27278ae52f0SPhilip Pfaffe   const DataLayout *DL;
27378ae52f0SPhilip Pfaffe 
27478ae52f0SPhilip Pfaffe   /// @name The analysis passes we need to generate code.
27578ae52f0SPhilip Pfaffe   ///
27678ae52f0SPhilip Pfaffe   ///{
27778ae52f0SPhilip Pfaffe   LoopInfo *LI;
27878ae52f0SPhilip Pfaffe   IslAstInfo *AI;
27978ae52f0SPhilip Pfaffe   DominatorTree *DT;
28078ae52f0SPhilip Pfaffe   ScalarEvolution *SE;
28178ae52f0SPhilip Pfaffe   RegionInfo *RI;
28278ae52f0SPhilip Pfaffe   ///}
28378ae52f0SPhilip Pfaffe 
28478ae52f0SPhilip Pfaffe   /// Generate LLVM-IR for the SCoP @p S.
28578ae52f0SPhilip Pfaffe   bool runOnScop(Scop &S) override {
28602ca346eSSingapuram Sanjay Srivallabh     // Skip SCoPs in case they're already code-generated by PPCGCodeGeneration.
28702ca346eSSingapuram Sanjay Srivallabh     if (S.isToBeSkipped())
28802ca346eSSingapuram Sanjay Srivallabh       return false;
28902ca346eSSingapuram Sanjay Srivallabh 
29078ae52f0SPhilip Pfaffe     AI = &getAnalysis<IslAstInfoWrapperPass>().getAI();
29178ae52f0SPhilip Pfaffe     LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
29278ae52f0SPhilip Pfaffe     DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
29378ae52f0SPhilip Pfaffe     SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE();
29478ae52f0SPhilip Pfaffe     DL = &S.getFunction().getParent()->getDataLayout();
29578ae52f0SPhilip Pfaffe     RI = &getAnalysis<RegionInfoPass>().getRegionInfo();
29678ae52f0SPhilip Pfaffe     return CodeGen(S, *AI, *LI, *DT, *SE, *RI);
29778ae52f0SPhilip Pfaffe   }
29878ae52f0SPhilip Pfaffe 
299c80d6979STobias Grosser   /// Register all analyses and transformation required.
30009d30697STobias Grosser   void getAnalysisUsage(AnalysisUsage &AU) const override {
30109d30697STobias Grosser     AU.addRequired<DominatorTreeWrapperPass>();
3022b852e2eSPhilip Pfaffe     AU.addRequired<IslAstInfoWrapperPass>();
30309d30697STobias Grosser     AU.addRequired<RegionInfoPass>();
304c5bcf246STobias Grosser     AU.addRequired<ScalarEvolutionWrapperPass>();
3055cc87e3aSPhilip Pfaffe     AU.addRequired<ScopDetectionWrapperPass>();
30699191c78SJohannes Doerfert     AU.addRequired<ScopInfoRegionPass>();
30709d30697STobias Grosser     AU.addRequired<LoopInfoWrapperPass>();
30809d30697STobias Grosser 
30909d30697STobias Grosser     AU.addPreserved<DependenceInfo>();
31009d30697STobias Grosser 
31166ef16b2SChandler Carruth     AU.addPreserved<AAResultsWrapperPass>();
31266ef16b2SChandler Carruth     AU.addPreserved<BasicAAWrapperPass>();
31309d30697STobias Grosser     AU.addPreserved<LoopInfoWrapperPass>();
31409d30697STobias Grosser     AU.addPreserved<DominatorTreeWrapperPass>();
31566ef16b2SChandler Carruth     AU.addPreserved<GlobalsAAWrapperPass>();
3162b852e2eSPhilip Pfaffe     AU.addPreserved<IslAstInfoWrapperPass>();
3175cc87e3aSPhilip Pfaffe     AU.addPreserved<ScopDetectionWrapperPass>();
318c5bcf246STobias Grosser     AU.addPreserved<ScalarEvolutionWrapperPass>();
31966ef16b2SChandler Carruth     AU.addPreserved<SCEVAAWrapperPass>();
32009d30697STobias Grosser 
32109d30697STobias Grosser     // FIXME: We do not yet add regions for the newly generated code to the
32209d30697STobias Grosser     //        region tree.
32309d30697STobias Grosser     AU.addPreserved<RegionInfoPass>();
32499191c78SJohannes Doerfert     AU.addPreserved<ScopInfoRegionPass>();
32509d30697STobias Grosser   }
32609d30697STobias Grosser };
327522478d2STobias Grosser } // namespace
32809d30697STobias Grosser 
32978ae52f0SPhilip Pfaffe PreservedAnalyses
33078ae52f0SPhilip Pfaffe polly::CodeGenerationPass::run(Scop &S, ScopAnalysisManager &SAM,
33178ae52f0SPhilip Pfaffe                                ScopStandardAnalysisResults &AR, SPMUpdater &U) {
33278ae52f0SPhilip Pfaffe   auto &AI = SAM.getResult<IslAstAnalysis>(S, AR);
333f43e7c2eSPhilip Pfaffe   if (CodeGen(S, AI, AR.LI, AR.DT, AR.SE, AR.RI)) {
334f43e7c2eSPhilip Pfaffe     U.invalidateScop(S);
33578ae52f0SPhilip Pfaffe     return PreservedAnalyses::none();
336f43e7c2eSPhilip Pfaffe   }
33778ae52f0SPhilip Pfaffe 
33878ae52f0SPhilip Pfaffe   return PreservedAnalyses::all();
33978ae52f0SPhilip Pfaffe }
34078ae52f0SPhilip Pfaffe 
34109d30697STobias Grosser char CodeGeneration::ID = 1;
34209d30697STobias Grosser 
34309d30697STobias Grosser Pass *polly::createCodeGenerationPass() { return new CodeGeneration(); }
34409d30697STobias Grosser 
34509d30697STobias Grosser INITIALIZE_PASS_BEGIN(CodeGeneration, "polly-codegen",
34609d30697STobias Grosser                       "Polly - Create LLVM-IR from SCoPs", false, false);
34709d30697STobias Grosser INITIALIZE_PASS_DEPENDENCY(DependenceInfo);
34809d30697STobias Grosser INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass);
34909d30697STobias Grosser INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass);
35009d30697STobias Grosser INITIALIZE_PASS_DEPENDENCY(RegionInfoPass);
351c5bcf246STobias Grosser INITIALIZE_PASS_DEPENDENCY(ScalarEvolutionWrapperPass);
3525cc87e3aSPhilip Pfaffe INITIALIZE_PASS_DEPENDENCY(ScopDetectionWrapperPass);
35309d30697STobias Grosser INITIALIZE_PASS_END(CodeGeneration, "polly-codegen",
35409d30697STobias Grosser                     "Polly - Create LLVM-IR from SCoPs", false, false)
355