diff --git a/polly/include/polly/CodeGen/IslAst.h b/polly/include/polly/CodeGen/IslAst.h --- a/polly/include/polly/CodeGen/IslAst.h +++ b/polly/include/polly/CodeGen/IslAst.h @@ -44,12 +44,12 @@ /// Print a source code representation of the program. void pprint(raw_ostream &OS); - __isl_give isl_ast_node *getAst(); + isl::ast_node getAst(); const std::shared_ptr getSharedIslCtx() const { return Ctx; } /// Get the run-time conditions for the Scop. - __isl_give isl_ast_expr *getRunCondition(); + isl::ast_expr getRunCondition(); /// Build run-time condition for scop. /// @@ -57,14 +57,13 @@ /// @param Build The isl_build object to use to build the condition. /// /// @returns An ast expression that describes the necessary run-time check. - static isl_ast_expr *buildRunCondition(Scop &S, - __isl_keep isl_ast_build *Build); + static isl::ast_expr buildRunCondition(Scop &S, const isl::ast_build &Build); private: Scop &S; isl_ast_node *Root = nullptr; - isl_ast_expr *RunCondition = nullptr; std::shared_ptr Ctx; + isl::ast_expr RunCondition; IslAst(Scop &Scop); @@ -120,7 +119,7 @@ IslAst &getIslAst() { return Ast; } /// Return a copy of the AST root node. - __isl_give isl_ast_node *getAst(); + isl::ast_node getAst(); /// Get the run condition. /// @@ -128,7 +127,7 @@ /// assumptions that have been taken hold. If the run condition evaluates to /// zero/false some assumptions do not hold and the original code needs to /// be executed. - __isl_give isl_ast_expr *getRunCondition(); + isl::ast_expr getRunCondition(); void print(raw_ostream &O); diff --git a/polly/lib/CodeGen/CodeGeneration.cpp b/polly/lib/CodeGen/CodeGeneration.cpp --- a/polly/lib/CodeGen/CodeGeneration.cpp +++ b/polly/lib/CodeGen/CodeGeneration.cpp @@ -188,8 +188,8 @@ } // Check if we created an isl_ast root node, otherwise exit. - isl_ast_node *AstRoot = Ast.getAst(); - if (!AstRoot) + isl::ast_node AstRoot = Ast.getAst(); + if (AstRoot.is_null()) return false; // Collect statistics. Do it before we modify the IR to avoid having it any @@ -266,11 +266,9 @@ assert(ExitingBB); DT.changeImmediateDominator(MergeBlock, ExitingBB); DT.eraseNode(ExitingBlock); - - isl_ast_node_free(AstRoot); } else { NodeBuilder.addParameters(S.getContext().release()); - Value *RTC = NodeBuilder.createRTC(AI.getRunCondition()); + Value *RTC = NodeBuilder.createRTC(AI.getRunCondition().release()); Builder.GetInsertBlock()->getTerminator()->setOperand(0, RTC); @@ -282,7 +280,7 @@ // between polly.start and polly.exiting (at this point). Builder.SetInsertPoint(StartBlock->getTerminator()); - NodeBuilder.create(AstRoot); + NodeBuilder.create(AstRoot.release()); NodeBuilder.finalize(); fixRegionInfo(*EnteringBB->getParent(), *R->getParent(), RI); diff --git a/polly/lib/CodeGen/IslAst.cpp b/polly/lib/CodeGen/IslAst.cpp --- a/polly/lib/CodeGen/IslAst.cpp +++ b/polly/lib/CodeGen/IslAst.cpp @@ -398,23 +398,22 @@ return NonAliasGroup; } -__isl_give isl_ast_expr * -IslAst::buildRunCondition(Scop &S, __isl_keep isl_ast_build *Build) { - isl_ast_expr *RunCondition; +isl::ast_expr IslAst::buildRunCondition(Scop &S, const isl::ast_build &Build) { + isl::ast_expr RunCondition; // The conditions that need to be checked at run-time for this scop are // available as an isl_set in the runtime check context from which we can // directly derive a run-time condition. - auto *PosCond = - isl_ast_build_expr_from_set(Build, S.getAssumedContext().release()); + auto PosCond = Build.expr_from(S.getAssumedContext()); if (S.hasTrivialInvalidContext()) { - RunCondition = PosCond; + RunCondition = std::move(PosCond); } else { - auto *ZeroV = isl_val_zero(isl_ast_build_get_ctx(Build)); - auto *NegCond = - isl_ast_build_expr_from_set(Build, S.getInvalidContext().release()); - auto *NotNegCond = isl_ast_expr_eq(isl_ast_expr_from_val(ZeroV), NegCond); - RunCondition = isl_ast_expr_and(PosCond, NotNegCond); + auto ZeroV = isl::val::zero(Build.get_ctx()); + auto NegCond = Build.expr_from(S.getInvalidContext()); + auto NotNegCond = + isl::ast_expr::from_val(std::move(ZeroV)).eq(std::move(NegCond)); + RunCondition = + isl::manage(isl_ast_expr_and(PosCond.release(), NotNegCond.release())); } // Create the alias checks from the minimal/maximal accesses in each alias @@ -429,15 +428,13 @@ for (auto RWAccIt0 = MinMaxReadWrite.begin(); RWAccIt0 != RWAccEnd; ++RWAccIt0) { for (auto RWAccIt1 = RWAccIt0 + 1; RWAccIt1 != RWAccEnd; ++RWAccIt1) - RunCondition = isl_ast_expr_and( - RunCondition, - buildCondition(S, isl::manage_copy(Build), RWAccIt0, RWAccIt1) - .release()); + RunCondition = isl::manage(isl_ast_expr_and( + RunCondition.release(), + buildCondition(S, Build, RWAccIt0, RWAccIt1).release())); for (const Scop::MinMaxAccessTy &ROAccIt : MinMaxReadOnly) - RunCondition = isl_ast_expr_and( - RunCondition, - buildCondition(S, isl::manage_copy(Build), RWAccIt0, &ROAccIt) - .release()); + RunCondition = isl::manage(isl_ast_expr_and( + RunCondition.release(), + buildCondition(S, Build, RWAccIt0, &ROAccIt).release())); } } @@ -502,15 +499,12 @@ IslAst::IslAst(Scop &Scop) : S(Scop), Ctx(Scop.getSharedIslCtx()) {} IslAst::IslAst(IslAst &&O) - : S(O.S), Root(O.Root), RunCondition(O.RunCondition), Ctx(O.Ctx) { + : S(O.S), Root(O.Root), Ctx(O.Ctx), + RunCondition(std::move(O.RunCondition)) { O.Root = nullptr; - O.RunCondition = nullptr; } -IslAst::~IslAst() { - isl_ast_node_free(Root); - isl_ast_expr_free(RunCondition); -} +IslAst::~IslAst() { isl_ast_node_free(Root); } void IslAst::init(const Dependences &D) { bool PerformParallelTest = PollyParallel || DetectParallel || @@ -557,7 +551,7 @@ &BuildInfo); } - RunCondition = buildRunCondition(S, Build); + RunCondition = buildRunCondition(S, isl::manage_copy(Build)); Root = isl_ast_build_node_from_schedule(Build, S.getScheduleTree().release()); walkAstForStatistics(Root); @@ -571,15 +565,11 @@ return Ast; } -__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); -} +isl::ast_node IslAst::getAst() { return isl::manage_copy(Root); } +isl::ast_expr IslAst::getRunCondition() { return RunCondition; } -__isl_give isl_ast_node *IslAstInfo::getAst() { return Ast.getAst(); } -__isl_give isl_ast_expr *IslAstInfo::getRunCondition() { - return Ast.getRunCondition(); -} +isl::ast_node IslAstInfo::getAst() { return Ast.getAst(); } +isl::ast_expr IslAstInfo::getRunCondition() { return Ast.getRunCondition(); } IslAstUserPayload *IslAstInfo::getNodePayload(const isl::ast_node &Node) { isl::id Id = Node.get_annotation(); @@ -745,12 +735,12 @@ void IslAstInfo::print(raw_ostream &OS) { isl_ast_print_options *Options; - isl_ast_node *RootNode = Ast.getAst(); + isl::ast_node RootNode = Ast.getAst(); Function &F = S.getFunction(); OS << ":: isl ast :: " << F.getName() << " :: " << S.getNameStr() << "\n"; - if (!RootNode) { + if (RootNode.is_null()) { OS << ":: isl ast generation and code generation was skipped!\n\n"; OS << ":: This is either because no useful optimizations could be applied " "(use -polly-process-unprofitable to enforce code generation) or " @@ -760,7 +750,7 @@ return; } - isl_ast_expr *RunCondition = Ast.getRunCondition(); + isl::ast_expr RunCondition = Ast.getRunCondition(); char *RtCStr, *AstStr; Options = isl_ast_print_options_alloc(S.getIslCtx().get()); @@ -772,11 +762,11 @@ isl_printer *P = isl_printer_to_str(S.getIslCtx().get()); P = isl_printer_set_output_format(P, ISL_FORMAT_C); - P = isl_printer_print_ast_expr(P, RunCondition); + P = isl_printer_print_ast_expr(P, RunCondition.get()); RtCStr = isl_printer_get_str(P); P = isl_printer_flush(P); P = isl_printer_indent(P, 4); - P = isl_ast_node_print(RootNode, P, Options); + P = isl_ast_node_print(RootNode.get(), P, Options); AstStr = isl_printer_get_str(P); auto *Schedule = S.getScheduleTree().release(); @@ -793,9 +783,7 @@ free(RtCStr); free(AstStr); - isl_ast_expr_free(RunCondition); isl_schedule_free(Schedule); - isl_ast_node_free(RootNode); isl_printer_free(P); } diff --git a/polly/lib/CodeGen/PPCGCodeGeneration.cpp b/polly/lib/CodeGen/PPCGCodeGeneration.cpp --- a/polly/lib/CodeGen/PPCGCodeGeneration.cpp +++ b/polly/lib/CodeGen/PPCGCodeGeneration.cpp @@ -3506,9 +3506,11 @@ Builder.SetInsertPoint(SplitBlock->getTerminator()); isl_ast_build *Build = isl_ast_build_alloc(S->getIslCtx().get()); - isl_ast_expr *Condition = IslAst::buildRunCondition(*S, Build); + isl::ast_expr Condition = + IslAst::buildRunCondition(*S, isl::manage_copy(Build)); isl_ast_expr *SufficientCompute = createSufficientComputeCheck(*S, Build); - Condition = isl_ast_expr_and(Condition, SufficientCompute); + Condition = + isl::manage(isl_ast_expr_and(Condition.release(), SufficientCompute)); isl_ast_build_free(Build); // preload invariant loads. Note: This should happen before the RTC @@ -3535,7 +3537,6 @@ DT->changeImmediateDominator(MergeBlock, ExitingBB); DT->eraseNode(ExitingBlock); - isl_ast_expr_free(Condition); isl_ast_node_free(Root); } else { @@ -3556,7 +3557,7 @@ } NodeBuilder.addParameters(S->getContext().release()); - Value *RTC = NodeBuilder.createRTC(Condition); + Value *RTC = NodeBuilder.createRTC(Condition.release()); Builder.GetInsertBlock()->getTerminator()->setOperand(0, RTC); Builder.SetInsertPoint(&*StartBlock->begin());