[NFC] Generate runtime checks after the SCoP
We now generate runtime checks __after__ the SCoP code generation and
not before, though they are still inserted at the same position int
the code. This allows to modify the runtime check during SCoP code
generation.
llvm-svn: 271894
diff --git a/polly/lib/CodeGen/CodeGeneration.cpp b/polly/lib/CodeGen/CodeGeneration.cpp
index ce1098f..b434144 100644
--- a/polly/lib/CodeGen/CodeGeneration.cpp
+++ b/polly/lib/CodeGen/CodeGeneration.cpp
@@ -191,7 +191,12 @@
} else {
NodeBuilder.addParameters(S.getContext());
+ SplitBlock = Builder.GetInsertBlock();
+ Builder.SetInsertPoint(&StartBlock->front());
+ NodeBuilder.create(AstRoot);
+
+ Builder.SetInsertPoint(SplitBlock->getTerminator());
ExprBuilder.setTrackOverflow(true);
Value *RTC = buildRTC(Builder, ExprBuilder);
Value *OverflowHappened = Builder.CreateNot(
@@ -199,10 +204,7 @@
RTC = Builder.CreateAnd(RTC, OverflowHappened, "polly.rtc.result");
ExprBuilder.setTrackOverflow(false);
- Builder.GetInsertBlock()->getTerminator()->setOperand(0, RTC);
- Builder.SetInsertPoint(&StartBlock->front());
-
- NodeBuilder.create(AstRoot);
+ SplitBlock->getTerminator()->setOperand(0, RTC);
NodeBuilder.finalizeSCoP(S);
fixRegionInfo(EnteringBB->getParent(), R->getParent());
diff --git a/polly/lib/CodeGen/IslAst.cpp b/polly/lib/CodeGen/IslAst.cpp
index 5bcd784..f524954 100644
--- a/polly/lib/CodeGen/IslAst.cpp
+++ b/polly/lib/CodeGen/IslAst.cpp
@@ -331,8 +331,7 @@
return NonAliasGroup;
}
-__isl_give isl_ast_expr *
-IslAst::buildRunCondition(Scop *S, __isl_keep isl_ast_build *Build) {
+__isl_give isl_ast_expr *IslAst::buildRunCondition() {
isl_ast_expr *RunCondition;
// The conditions that need to be checked at run-time for this scop are
@@ -393,8 +392,7 @@
}
IslAst::IslAst(Scop *Scop)
- : S(Scop), Root(nullptr), RunCondition(nullptr),
- Ctx(Scop->getSharedIslCtx()) {}
+ : S(Scop), Root(nullptr), Build(nullptr), Ctx(Scop->getSharedIslCtx()) {}
void IslAst::init(const Dependences &D) {
bool PerformParallelTest = PollyParallel || DetectParallel ||
@@ -407,7 +405,6 @@
isl_ctx *Ctx = S->getIslCtx();
isl_options_set_ast_build_atomic_upper_bound(Ctx, true);
isl_options_set_ast_build_detect_min_max(Ctx, true);
- isl_ast_build *Build;
AstBuildUserInfo BuildInfo;
if (UseContext)
@@ -433,11 +430,7 @@
&BuildInfo);
}
- RunCondition = buildRunCondition(S, Build);
-
Root = isl_ast_build_node_from_schedule(Build, S->getScheduleTree());
-
- isl_ast_build_free(Build);
}
IslAst *IslAst::create(Scop *Scop, const Dependences &D) {
@@ -448,13 +441,10 @@
IslAst::~IslAst() {
isl_ast_node_free(Root);
- isl_ast_expr_free(RunCondition);
+ isl_ast_build_free(Build);
}
__isl_give isl_ast_node *IslAst::getAst() { return isl_ast_node_copy(Root); }
-__isl_give isl_ast_expr *IslAst::getRunCondition() {
- return isl_ast_expr_copy(RunCondition);
-}
void IslAstInfo::releaseMemory() {
if (Ast) {
@@ -480,7 +470,7 @@
__isl_give isl_ast_node *IslAstInfo::getAst() const { return Ast->getAst(); }
__isl_give isl_ast_expr *IslAstInfo::getRunCondition() const {
- return Ast->getRunCondition();
+ return Ast->buildRunCondition();
}
IslAstUserPayload *IslAstInfo::getNodePayload(__isl_keep isl_ast_node *Node) {