diff options
-rw-r--r-- | polly/include/polly/CodeGen/IslAst.h | 5 | ||||
-rw-r--r-- | polly/include/polly/DependenceInfo.h | 2 | ||||
-rw-r--r-- | polly/lib/CodeGen/CodeGeneration.cpp | 21 | ||||
-rw-r--r-- | polly/lib/CodeGen/IslAst.cpp | 8 | ||||
-rw-r--r-- | polly/lib/Transform/ScheduleOptimizer.cpp | 5 | ||||
-rw-r--r-- | polly/test/Isl/CodeGen/multiple-codegens.ll | 61 | ||||
-rw-r--r-- | polly/test/ScopDetect/base_pointer_load_setNewAccessRelation.ll | 2 |
7 files changed, 101 insertions, 3 deletions
diff --git a/polly/include/polly/CodeGen/IslAst.h b/polly/include/polly/CodeGen/IslAst.h index 79335be524b..c1d3305e430 100644 --- a/polly/include/polly/CodeGen/IslAst.h +++ b/polly/include/polly/CodeGen/IslAst.h @@ -67,6 +67,8 @@ public: __isl_give isl_ast_node *getAst(); + const std::shared_ptr<isl_ctx> getSharedIslCtx() const { return Ctx; } + /// Get the run-time conditions for the Scop. __isl_give isl_ast_expr *getRunCondition(); @@ -131,6 +133,9 @@ private: public: IslAstInfo(Scop &S, const Dependences &D) : S(S), Ast(IslAst::create(S, D)) {} + /// Return the isl AST computed by this IslAstInfo. + IslAst &getIslAst() { return Ast; } + /// Return a copy of the AST root node. __isl_give isl_ast_node *getAst(); diff --git a/polly/include/polly/DependenceInfo.h b/polly/include/polly/DependenceInfo.h index d440dd54e7f..89c3205a437 100644 --- a/polly/include/polly/DependenceInfo.h +++ b/polly/include/polly/DependenceInfo.h @@ -92,6 +92,8 @@ struct Dependences { TYPE_TC_RED = 1 << 4, }; + const std::shared_ptr<isl_ctx> &getSharedIslCtx() const { return IslCtx; } + /// Get the dependences of type @p Kinds. /// /// @param Kinds This integer defines the different kinds of dependences diff --git a/polly/lib/CodeGen/CodeGeneration.cpp b/polly/lib/CodeGen/CodeGeneration.cpp index 240ce23c1b4..41a3b2fcf6a 100644 --- a/polly/lib/CodeGen/CodeGeneration.cpp +++ b/polly/lib/CodeGen/CodeGeneration.cpp @@ -182,8 +182,27 @@ static void removeLifetimeMarkers(Region *R) { static bool CodeGen(Scop &S, IslAstInfo &AI, LoopInfo &LI, DominatorTree &DT, ScalarEvolution &SE, RegionInfo &RI) { + // Check whether IslAstInfo uses the same isl_ctx. Since -polly-codegen + // reports itself to preserve DependenceInfo and IslAstInfo, we might get + // those analysis that were computed by a different ScopInfo for a different + // Scop structure. When the ScopInfo/Scop object is freed, there is a high + // probability that the new ScopInfo/Scop object will be created at the same + // heap position with the same address. Comparing whether the Scop or ScopInfo + // address is the expected therefore is unreliable. + // Instead, we compare the address of the isl_ctx object. Both, DependenceInfo + // and IslAstInfo must hold a reference to the isl_ctx object to ensure it is + // not freed before the destruction of those analyses which might happen after + // the destruction of the Scop/ScopInfo they refer to. Hence, the isl_ctx + // will not be freed and its space not reused as long there is a + // DependenceInfo or IslAstInfo around. + IslAst &Ast = AI.getIslAst(); + if (Ast.getSharedIslCtx() != S.getSharedIslCtx()) { + DEBUG(dbgs() << "Got an IstAst for a different Scop/isl_ctx\n"); + return false; + } + // Check if we created an isl_ast root node, otherwise exit. - isl_ast_node *AstRoot = AI.getAst(); + isl_ast_node *AstRoot = Ast.getAst(); if (!AstRoot) return false; diff --git a/polly/lib/CodeGen/IslAst.cpp b/polly/lib/CodeGen/IslAst.cpp index 3c67cc7ed10..346e14f496b 100644 --- a/polly/lib/CodeGen/IslAst.cpp +++ b/polly/lib/CodeGen/IslAst.cpp @@ -806,6 +806,12 @@ bool IslAstInfoWrapperPass::runOnScop(Scop &Scop) { const Dependences &D = getAnalysis<DependenceInfo>().getDependences(Dependences::AL_Statement); + if (D.getSharedIslCtx() != Scop.getSharedIslCtx()) { + DEBUG(dbgs() << "Got dependence analysis for different SCoP/isl_ctx\n"); + Ast.reset(); + return false; + } + Ast.reset(new IslAstInfo(Scop, D)); DEBUG(printScop(dbgs(), Scop)); @@ -815,7 +821,7 @@ bool IslAstInfoWrapperPass::runOnScop(Scop &Scop) { void IslAstInfoWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const { // Get the Common analysis usage of ScopPasses. ScopPass::getAnalysisUsage(AU); - AU.addRequired<ScopInfoRegionPass>(); + AU.addRequiredTransitive<ScopInfoRegionPass>(); AU.addRequired<DependenceInfo>(); AU.addPreserved<DependenceInfo>(); diff --git a/polly/lib/Transform/ScheduleOptimizer.cpp b/polly/lib/Transform/ScheduleOptimizer.cpp index 0a2fe8b6897..899f1c06830 100644 --- a/polly/lib/Transform/ScheduleOptimizer.cpp +++ b/polly/lib/Transform/ScheduleOptimizer.cpp @@ -1485,6 +1485,11 @@ bool IslScheduleOptimizer::runOnScop(Scop &S) { const Dependences &D = getAnalysis<DependenceInfo>().getDependences(Dependences::AL_Statement); + if (D.getSharedIslCtx() != S.getSharedIslCtx()) { + DEBUG(dbgs() << "DependenceInfo for another SCoP/isl_ctx\n"); + return false; + } + if (!D.hasValidDependences()) return false; diff --git a/polly/test/Isl/CodeGen/multiple-codegens.ll b/polly/test/Isl/CodeGen/multiple-codegens.ll new file mode 100644 index 00000000000..b9bfb55e041 --- /dev/null +++ b/polly/test/Isl/CodeGen/multiple-codegens.ll @@ -0,0 +1,61 @@ +; RUN: opt %loadPolly -polly-scops -polly-opt-isl -polly-codegen -polly-scops -polly-codegen -S < %s | FileCheck %s +; +; llvm.org/PR34441 +; Properly handle multiple -polly-scops/-polly-codegen in the same +; RegionPassManager. -polly-codegen must not reuse the -polly-ast analysis the +; was created for the first -polly-scops pass. +; The current solution is that only the first -polly-codegen is allowed to +; generate code, the second detects it is re-using an IslAst that belongs to a +; different ScopInfo. +; +; int a, b, c; +; +; int main () { +; while (a++) +; while (b) { +; c = 0; +; break; +; } +; return 0; +; } +; +target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" + +@a = common global i32 0, align 4 +@b = common global i32 0, align 4 +@c = common global i32 0, align 4 + +; Function Attrs: nounwind uwtable +define i32 @main() { +entry: + %retval = alloca i32, align 4 + store i32 0, i32* %retval, align 4 + %.pre = load i32, i32* @a, align 4 + br label %while.cond + +while.cond: ; preds = %while.end, %entry + %0 = phi i32 [ %inc, %while.end ], [ %.pre, %entry ] + %inc = add nsw i32 %0, 1 + store i32 %inc, i32* @a, align 4 + %tobool = icmp ne i32 %0, 0 + br i1 %tobool, label %while.body, label %while.end4 + +while.body: ; preds = %while.cond + %1 = load i32, i32* @b, align 4 + %tobool2 = icmp ne i32 %1, 0 + br i1 %tobool2, label %while.body3, label %while.end + +while.body3: ; preds = %while.body + store i32 0, i32* @c, align 4 + br label %while.end + +while.end: ; preds = %while.body3, %while.body + br label %while.cond + +while.end4: ; preds = %while.cond + ret i32 0 +} + + +; CHECK: polly.start: +; CHECK-NOT: polly.start: diff --git a/polly/test/ScopDetect/base_pointer_load_setNewAccessRelation.ll b/polly/test/ScopDetect/base_pointer_load_setNewAccessRelation.ll index bc965526b4f..3561a49a271 100644 --- a/polly/test/ScopDetect/base_pointer_load_setNewAccessRelation.ll +++ b/polly/test/ScopDetect/base_pointer_load_setNewAccessRelation.ll @@ -1,4 +1,4 @@ -; RUN: opt %loadPolly -polly-ignore-aliasing -polly-invariant-load-hoisting=true -polly-import-jscop -polly-scops -polly-codegen -analyze < %s | FileCheck %s +; RUN: opt %loadPolly -polly-ignore-aliasing -polly-invariant-load-hoisting=true -polly-scops -polly-import-jscop -polly-codegen -analyze < %s | FileCheck %s ; ; This violated an assertion in setNewAccessRelation that assumed base pointers ; to be load-hoisted. Without this assertion, it codegen would generate invalid |