From 00fd43b327a252280db1c34696efee809c2286bc Mon Sep 17 00:00:00 2001 From: Philip Pfaffe Date: Sun, 19 Nov 2017 22:13:34 +0000 Subject: Port ScopInfo to the isl cpp bindings Summary: Most changes are mechanical, but in one place I changed the program semantics by fixing a likely bug: In `Scop::hasFeasibleRuntimeContext()`, I'm now explicitely handling the error-case. Before, when the call to `addNonEmptyDomainConstraints()` returned a null set, this (probably) accidentally worked because isl_bool_error converts to true. I'm checking for nullptr now. Reviewers: grosser, Meinersbur, bollu Reviewed By: Meinersbur Subscribers: nemanjai, kbarton, pollydev, llvm-commits Differential Revision: https://reviews.llvm.org/D39971 llvm-svn: 318632 --- polly/lib/CodeGen/IslAst.cpp | 23 +++++++++--------- polly/lib/CodeGen/IslNodeBuilder.cpp | 16 ++++++------- polly/lib/CodeGen/PPCGCodeGeneration.cpp | 41 ++++++++++++++++---------------- 3 files changed, 40 insertions(+), 40 deletions(-) (limited to 'polly/lib/CodeGen') diff --git a/polly/lib/CodeGen/IslAst.cpp b/polly/lib/CodeGen/IslAst.cpp index 346e14f496b..4e1623ad7e5 100644 --- a/polly/lib/CodeGen/IslAst.cpp +++ b/polly/lib/CodeGen/IslAst.cpp @@ -351,10 +351,10 @@ static isl::ast_expr buildCondition(Scop &S, isl::ast_build Build, const Scop::MinMaxAccessTy *It0, const Scop::MinMaxAccessTy *It1) { - isl::pw_multi_aff AFirst = isl::manage(isl_pw_multi_aff_copy(It0->first)); - isl::pw_multi_aff ASecond = isl::manage(isl_pw_multi_aff_copy(It0->second)); - isl::pw_multi_aff BFirst = isl::manage(isl_pw_multi_aff_copy(It1->first)); - isl::pw_multi_aff BSecond = isl::manage(isl_pw_multi_aff_copy(It1->second)); + isl::pw_multi_aff AFirst = It0->first; + isl::pw_multi_aff ASecond = It0->second; + isl::pw_multi_aff BFirst = It1->first; + isl::pw_multi_aff BSecond = It1->second; isl::id Left = AFirst.get_tuple_id(isl::dim::set); isl::id Right = BFirst.get_tuple_id(isl::dim::set); @@ -529,10 +529,9 @@ void IslAst::init(const Dependences &D) { // We can not perform the dependence analysis and, consequently, // the parallel code generation in case the schedule tree contains // extension nodes. - auto *ScheduleTree = S.getScheduleTree().release(); + auto ScheduleTree = S.getScheduleTree(); PerformParallelTest = PerformParallelTest && !S.containsExtensionNode(ScheduleTree); - isl_schedule_free(ScheduleTree); // Skip AST and code generation if there was no benefit achieved. if (!benefitsFromPolly(S, PerformParallelTest)) @@ -543,9 +542,9 @@ void IslAst::init(const Dependences &D) { BeneficialAffineLoops += ScopStats.NumAffineLoops; BeneficialBoxedLoops += ScopStats.NumBoxedLoops; - 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); + auto Ctx = S.getIslCtx(); + isl_options_set_ast_build_atomic_upper_bound(Ctx.get(), true); + isl_options_set_ast_build_detect_min_max(Ctx.get(), true); isl_ast_build *Build; AstBuildUserInfo BuildInfo; @@ -677,7 +676,7 @@ isl_ast_build *IslAstInfo::getBuild(__isl_keep isl_ast_node *Node) { IslAstInfo IslAstAnalysis::run(Scop &S, ScopAnalysisManager &SAM, ScopStandardAnalysisResults &SAR) { return {S, SAM.getResult(S, SAR).getDependences( - Dependences::AL_Statement)}; + Dependences::AL_Statement)}; } static __isl_give isl_printer *cbPrintUser(__isl_take isl_printer *P, @@ -749,14 +748,14 @@ void IslAstInfo::print(raw_ostream &OS) { isl_ast_expr *RunCondition = Ast.getRunCondition(); char *RtCStr, *AstStr; - Options = isl_ast_print_options_alloc(S.getIslCtx()); + Options = isl_ast_print_options_alloc(S.getIslCtx().get()); if (PrintAccesses) Options = isl_ast_print_options_set_print_user(Options, cbPrintUser, nullptr); Options = isl_ast_print_options_set_print_for(Options, cbPrintFor, nullptr); - isl_printer *P = isl_printer_to_str(S.getIslCtx()); + 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); RtCStr = isl_printer_get_str(P); diff --git a/polly/lib/CodeGen/IslNodeBuilder.cpp b/polly/lib/CodeGen/IslNodeBuilder.cpp index 381195d48ee..cd4f8d6605a 100644 --- a/polly/lib/CodeGen/IslNodeBuilder.cpp +++ b/polly/lib/CodeGen/IslNodeBuilder.cpp @@ -849,7 +849,7 @@ __isl_give isl_id_to_ast_expr * IslNodeBuilder::createNewAccesses(ScopStmt *Stmt, __isl_keep isl_ast_node *Node) { isl_id_to_ast_expr *NewAccesses = - isl_id_to_ast_expr_alloc(Stmt->getParent()->getIslCtx(), 0); + isl_id_to_ast_expr_alloc(Stmt->getParent()->getIslCtx().get(), 0); auto *Build = IslAstInfo::getBuild(Node); assert(Build && "Could not obtain isl_ast_build from user node"); @@ -1072,7 +1072,7 @@ bool IslNodeBuilder::materializeValue(isl_id *Id) { auto MemInst = MemAccInst::dyn_cast(Inst); auto Address = MemInst ? MemInst.getPointerOperand() : nullptr; if (Address && SE.getUnknown(UndefValue::get(Address->getType())) == - SE.getPointerBase(SE.getSCEV(Address))) { + SE.getPointerBase(SE.getSCEV(Address))) { } else if (S.getStmtFor(Inst)) { IsDead = false; } else { @@ -1353,7 +1353,7 @@ bool IslNodeBuilder::preloadInvariantEquivClass( return false; // The execution context of the IAClass. - isl_set *&ExecutionCtx = IAClass.ExecutionContext; + isl::set &ExecutionCtx = IAClass.ExecutionContext; // If the base pointer of this class is dependent on another one we have to // make sure it was preloaded already. @@ -1364,8 +1364,8 @@ bool IslNodeBuilder::preloadInvariantEquivClass( // After we preloaded the BaseIAClass we adjusted the BaseExecutionCtx and // we need to refine the ExecutionCtx. - isl_set *BaseExecutionCtx = isl_set_copy(BaseIAClass->ExecutionContext); - ExecutionCtx = isl_set_intersect(ExecutionCtx, BaseExecutionCtx); + isl::set BaseExecutionCtx = BaseIAClass->ExecutionContext; + ExecutionCtx = ExecutionCtx.intersect(BaseExecutionCtx); } // If the size of a dimension is dependent on another class, make sure it is @@ -1381,8 +1381,8 @@ bool IslNodeBuilder::preloadInvariantEquivClass( // After we preloaded the BaseIAClass we adjusted the BaseExecutionCtx // and we need to refine the ExecutionCtx. - isl_set *BaseExecutionCtx = isl_set_copy(BaseIAClass->ExecutionContext); - ExecutionCtx = isl_set_intersect(ExecutionCtx, BaseExecutionCtx); + isl::set BaseExecutionCtx = BaseIAClass->ExecutionContext; + ExecutionCtx = ExecutionCtx.intersect(BaseExecutionCtx); } } } @@ -1390,7 +1390,7 @@ bool IslNodeBuilder::preloadInvariantEquivClass( Instruction *AccInst = MA->getAccessInstruction(); Type *AccInstTy = AccInst->getType(); - Value *PreloadVal = preloadInvariantLoad(*MA, isl_set_copy(ExecutionCtx)); + Value *PreloadVal = preloadInvariantLoad(*MA, ExecutionCtx.copy()); if (!PreloadVal) return false; diff --git a/polly/lib/CodeGen/PPCGCodeGeneration.cpp b/polly/lib/CodeGen/PPCGCodeGeneration.cpp index b606828069e..c6c8db8a911 100644 --- a/polly/lib/CodeGen/PPCGCodeGeneration.cpp +++ b/polly/lib/CodeGen/PPCGCodeGeneration.cpp @@ -2261,7 +2261,7 @@ void GPUNodeBuilder::createKernelVariables(ppcg_kernel *Kernel, Function *FN) { } SAI = S.getOrCreateScopArrayInfo(Allocation, EleTy, Sizes, MemoryKind::Array); - Id = isl_id_alloc(S.getIslCtx(), Var.name, nullptr); + Id = isl_id_alloc(S.getIslCtx().get(), Var.name, nullptr); IDToValue[Id] = Allocation; LocalArrays.push_back(Allocation); KernelIds.push_back(Id); @@ -2684,9 +2684,9 @@ public: /// @returns Retun a map from collected ids to 'zero' ast expressions. __isl_give isl_id_to_ast_expr *getNames() { auto *Names = isl_id_to_ast_expr_alloc( - S->getIslCtx(), + S->getIslCtx().get(), S->getNumParams() + std::distance(S->array_begin(), S->array_end())); - auto *Zero = isl_ast_expr_from_val(isl_val_zero(S->getIslCtx())); + auto *Zero = isl_ast_expr_from_val(isl_val_zero(S->getIslCtx().get())); for (const SCEV *P : S->parameters()) { isl_id *Id = S->getIdForParam(P).release(); @@ -2773,7 +2773,8 @@ public: gpu_stmt_access *Accesses = nullptr; for (MemoryAccess *Acc : Stmt) { - auto Access = isl_alloc_type(S->getIslCtx(), struct gpu_stmt_access); + auto Access = + isl_alloc_type(S->getIslCtx().get(), struct gpu_stmt_access); Access->read = Acc->isRead(); Access->write = Acc->isWrite(); Access->access = Acc->getAccessRelation().release(); @@ -2806,7 +2807,7 @@ public: /// /// @returns A linked-list of statements. gpu_stmt *getStatements() { - gpu_stmt *Stmts = isl_calloc_array(S->getIslCtx(), struct gpu_stmt, + gpu_stmt *Stmts = isl_calloc_array(S->getIslCtx().get(), struct gpu_stmt, std::distance(S->begin(), S->end())); int i = 0; @@ -2978,7 +2979,7 @@ public: assert(AlignSpace && "alignPwAffs did not initialise AlignSpace"); isl_pw_aff_list *BoundsList = - createPwAffList(S->getIslCtx(), std::move(AlignedBounds)); + createPwAffList(S->getIslCtx().get(), std::move(AlignedBounds)); isl_space *BoundsSpace = isl_set_get_space(PPCGArray.extent); BoundsSpace = isl_space_align_params(BoundsSpace, AlignSpace); @@ -3059,9 +3060,9 @@ public: if (!PPCGScop) return nullptr; - auto PPCGProg = isl_calloc_type(S->getIslCtx(), struct gpu_prog); + auto PPCGProg = isl_calloc_type(S->getIslCtx().get(), struct gpu_prog); - PPCGProg->ctx = S->getIslCtx(); + PPCGProg->ctx = S->getIslCtx().get(); PPCGProg->scop = PPCGScop; PPCGProg->context = isl_set_copy(PPCGScop->context); PPCGProg->read = isl_union_map_copy(PPCGScop->reads); @@ -3090,7 +3091,7 @@ public: PPCGProg->n_array = ValidSAIs.size(); // std::distance(S->array_begin(), S->array_end()); - PPCGProg->array = isl_calloc_array(S->getIslCtx(), struct gpu_array_info, + PPCGProg->array = isl_calloc_array(S->getIslCtx().get(), struct gpu_array_info, PPCGProg->n_array); createArrays(PPCGProg, ValidSAIs); @@ -3155,9 +3156,9 @@ public: /// /// @param Kernel The kernel to print void printKernel(ppcg_kernel *Kernel) { - auto *P = isl_printer_to_str(S->getIslCtx()); + auto *P = isl_printer_to_str(S->getIslCtx().get()); P = isl_printer_set_output_format(P, ISL_FORMAT_C); - auto *Options = isl_ast_print_options_alloc(S->getIslCtx()); + auto *Options = isl_ast_print_options_alloc(S->getIslCtx().get()); P = isl_ast_node_print(Kernel->tree, P, Options); char *String = isl_printer_get_str(P); printf("%s\n", String); @@ -3170,13 +3171,13 @@ public: /// @param Tree An AST describing GPU code /// @param PPCGProg The PPCG program from which @Tree has been constructed. void printGPUTree(isl_ast_node *Tree, gpu_prog *PPCGProg) { - auto *P = isl_printer_to_str(S->getIslCtx()); + auto *P = isl_printer_to_str(S->getIslCtx().get()); P = isl_printer_set_output_format(P, ISL_FORMAT_C); PrintGPUUserData Data; Data.PPCGProg = PPCGProg; - auto *Options = isl_ast_print_options_alloc(S->getIslCtx()); + auto *Options = isl_ast_print_options_alloc(S->getIslCtx().get()); Options = isl_ast_print_options_set_print_user(Options, printHostUser, &Data); P = isl_ast_node_print(Tree, P, Options); @@ -3205,9 +3206,9 @@ public: // strategy directly from this pass. gpu_gen *generateGPU(ppcg_scop *PPCGScop, gpu_prog *PPCGProg) { - auto PPCGGen = isl_calloc_type(S->getIslCtx(), struct gpu_gen); + auto PPCGGen = isl_calloc_type(S->getIslCtx().get(), struct gpu_gen); - PPCGGen->ctx = S->getIslCtx(); + PPCGGen->ctx = S->getIslCtx().get(); PPCGGen->options = PPCGScop->options; PPCGGen->print = nullptr; PPCGGen->print_user = nullptr; @@ -3243,7 +3244,7 @@ public: } if (DumpSchedule) { - isl_printer *P = isl_printer_to_str(S->getIslCtx()); + isl_printer *P = isl_printer_to_str(S->getIslCtx().get()); P = isl_printer_set_yaml_style(P, ISL_YAML_STYLE_BLOCK); P = isl_printer_print_str(P, "Schedule\n"); P = isl_printer_print_str(P, "========\n"); @@ -3355,7 +3356,7 @@ public: } } - isl_val *InstVal = isl_val_int_from_si(S->getIslCtx(), InstCount); + isl_val *InstVal = isl_val_int_from_si(S->getIslCtx().get(), InstCount); auto *InstExpr = isl_ast_expr_from_val(InstVal); return isl_ast_expr_mul(InstExpr, Iterations); } @@ -3371,7 +3372,7 @@ public: getNumberOfIterations(Scop &S, __isl_keep isl_ast_build *Build) { isl_ast_expr *Instructions; - isl_val *Zero = isl_val_int_from_si(S.getIslCtx(), 0); + isl_val *Zero = isl_val_int_from_si(S.getIslCtx().get(), 0); Instructions = isl_ast_expr_from_val(Zero); for (ScopStmt &Stmt : S) { @@ -3391,7 +3392,7 @@ public: __isl_give isl_ast_expr * createSufficientComputeCheck(Scop &S, __isl_keep isl_ast_build *Build) { auto Iterations = getNumberOfIterations(S, Build); - auto *MinComputeVal = isl_val_int_from_si(S.getIslCtx(), MinCompute); + auto *MinComputeVal = isl_val_int_from_si(S.getIslCtx().get(), MinCompute); auto *MinComputeExpr = isl_ast_expr_from_val(MinComputeVal); return isl_ast_expr_ge(Iterations, MinComputeExpr); } @@ -3477,7 +3478,7 @@ public: auto SplitBlock = StartBlock->getSinglePredecessor(); Builder.SetInsertPoint(SplitBlock->getTerminator()); - isl_ast_build *Build = isl_ast_build_alloc(S->getIslCtx()); + isl_ast_build *Build = isl_ast_build_alloc(S->getIslCtx().get()); isl_ast_expr *Condition = IslAst::buildRunCondition(*S, Build); isl_ast_expr *SufficientCompute = createSufficientComputeCheck(*S, Build); Condition = isl_ast_expr_and(Condition, SufficientCompute); -- cgit v1.2.1