[polly] 2a629ef - [Polly][Isl] Refactoring IslAstInfo::getBuild() and IslAstInfo::IslAstUserPayload::Build to use isl++. NFC

via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 18 00:53:58 PDT 2021


Author: patacca
Date: 2021-06-18T09:53:51+02:00
New Revision: 2a629efc74e5ad414f05e293f296b392f724bc9f

URL: https://github.com/llvm/llvm-project/commit/2a629efc74e5ad414f05e293f296b392f724bc9f
DIFF: https://github.com/llvm/llvm-project/commit/2a629efc74e5ad414f05e293f296b392f724bc9f.diff

LOG: [Polly][Isl] Refactoring IslAstInfo::getBuild() and IslAstInfo::IslAstUserPayload::Build to use isl++. NFC

Polly uses algorithms from the Integer Set Library (isl), which is a library written in C and which is incompatible with the rest of the LLVM as it is written in C++.

Changes made:
 - Refactoring the method `IslAstInfo::getBuild()`
 - `IslAstInfo::IslAstUserPayload.Build` now uses C++ types instead of C types
 - Removing destructor of `IslAstInfo::IslAstUserPayload`

Reviewed By: Meinersbur

Differential Revision: https://reviews.llvm.org/D104370

Added: 
    

Modified: 
    polly/include/polly/CodeGen/IslAst.h
    polly/lib/CodeGen/IslAst.cpp
    polly/lib/CodeGen/IslNodeBuilder.cpp

Removed: 
    


################################################################################
diff  --git a/polly/include/polly/CodeGen/IslAst.h b/polly/include/polly/CodeGen/IslAst.h
index f7e0b67162df8..bab4fce864a80 100644
--- a/polly/include/polly/CodeGen/IslAst.h
+++ b/polly/include/polly/CodeGen/IslAst.h
@@ -78,9 +78,6 @@ class IslAstInfo {
     /// Construct and initialize the payload.
     IslAstUserPayload() = default;
 
-    /// Cleanup all isl structs on destruction.
-    ~IslAstUserPayload();
-
     /// Does the dependence analysis determine that there are no loop-carried
     /// dependencies?
     bool IsParallel = false;
@@ -101,7 +98,7 @@ class IslAstInfo {
     isl::pw_aff MinimalDependenceDistance;
 
     /// The build environment at the time this node was constructed.
-    isl_ast_build *Build = nullptr;
+    isl::ast_build Build;
 
     /// Set of accesses which break reduction dependences.
     MemoryAccessSet BrokenReductions;
@@ -164,7 +161,7 @@ class IslAstInfo {
   static MemoryAccessSet *getBrokenReductions(const isl::ast_node &Node);
 
   /// Get the nodes build context or a nullptr if not available.
-  static __isl_give isl_ast_build *getBuild(__isl_keep isl_ast_node *Node);
+  static isl::ast_build getBuild(const isl::ast_node &Node);
 
   ///}
 };

diff  --git a/polly/lib/CodeGen/IslAst.cpp b/polly/lib/CodeGen/IslAst.cpp
index 50a59092c475f..ddb78ab62bccc 100644
--- a/polly/lib/CodeGen/IslAst.cpp
+++ b/polly/lib/CodeGen/IslAst.cpp
@@ -124,10 +124,6 @@ static void freeIslAstUserPayload(void *Ptr) {
   delete ((IslAstInfo::IslAstUserPayload *)Ptr);
 }
 
-IslAstInfo::IslAstUserPayload::~IslAstUserPayload() {
-  isl_ast_build_free(Build);
-}
-
 /// Print a string @p str in a single line using @p Printer.
 static isl_printer *printLine(__isl_take isl_printer *Printer,
                               const std::string &str,
@@ -286,8 +282,8 @@ astBuildAfterFor(__isl_take isl_ast_node *Node, __isl_keep isl_ast_build *Build,
   assert(Payload && "Post order visit assumes annotated for nodes");
 
   AstBuildUserInfo *BuildInfo = (AstBuildUserInfo *)User;
-  assert(!Payload->Build && "Build environment already set");
-  Payload->Build = isl_ast_build_copy(Build);
+  assert(Payload->Build.is_null() && "Build environment already set");
+  Payload->Build = isl::manage_copy(Build);
   Payload->IsInnermost = (Id == BuildInfo->LastForNodeId);
 
   Payload->IsInnermostParallel =
@@ -333,7 +329,7 @@ static __isl_give isl_ast_node *AtEachDomain(__isl_take isl_ast_node *Node,
   isl_id *Id = isl_id_alloc(isl_ast_build_get_ctx(Build), "", Payload);
   Id = isl_id_set_free_user(Id, freeIslAstUserPayload);
 
-  Payload->Build = isl_ast_build_copy(Build);
+  Payload->Build = isl::manage_copy(Build);
 
   return isl_ast_node_set_annotation(Node, Id);
 }
@@ -622,11 +618,7 @@ bool IslAstInfo::isExecutedInParallel(const isl::ast_node &Node) {
 
 isl::union_map IslAstInfo::getSchedule(const isl::ast_node &Node) {
   IslAstUserPayload *Payload = getNodePayload(Node);
-  if (!Payload)
-    return {};
-
-  isl::ast_build Build = isl::manage_copy(Payload->Build);
-  return Build.get_schedule();
+  return Payload ? Payload->Build.get_schedule() : isl::union_map();
 }
 
 isl::pw_aff
@@ -641,9 +633,9 @@ IslAstInfo::getBrokenReductions(const isl::ast_node &Node) {
   return Payload ? &Payload->BrokenReductions : nullptr;
 }
 
-isl_ast_build *IslAstInfo::getBuild(__isl_keep isl_ast_node *Node) {
-  IslAstUserPayload *Payload = getNodePayload(isl::manage_copy(Node));
-  return Payload ? Payload->Build : nullptr;
+isl::ast_build IslAstInfo::getBuild(const isl::ast_node &Node) {
+  IslAstUserPayload *Payload = getNodePayload(Node);
+  return Payload ? Payload->Build : isl::ast_build();
 }
 
 static std::unique_ptr<IslAstInfo> runIslAst(
@@ -706,7 +698,7 @@ static __isl_give isl_printer *cbPrintUser(__isl_take isl_printer *P,
     else
       P = isl_printer_print_str(P, "/* write */  ");
 
-    isl::ast_build Build = isl::manage_copy(IslAstInfo::getBuild(Node));
+    isl::ast_build Build = IslAstInfo::getBuild(isl::manage_copy(Node));
     if (MemAcc->isAffine()) {
       isl_pw_multi_aff *PwmaPtr =
           MemAcc->applyScheduleToAccessRelation(Build.get_schedule()).release();

diff  --git a/polly/lib/CodeGen/IslNodeBuilder.cpp b/polly/lib/CodeGen/IslNodeBuilder.cpp
index e9675c9a56831..2cf958bc2a8a9 100644
--- a/polly/lib/CodeGen/IslNodeBuilder.cpp
+++ b/polly/lib/CodeGen/IslNodeBuilder.cpp
@@ -850,12 +850,12 @@ void IslNodeBuilder::createIf(__isl_take isl_ast_node *If) {
 __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().get(), 0);
+  isl::id_to_ast_expr NewAccesses =
+      isl::id_to_ast_expr::alloc(Stmt->getParent()->getIslCtx(), 0);
 
-  auto *Build = IslAstInfo::getBuild(Node);
-  assert(Build && "Could not obtain isl_ast_build from user node");
-  Stmt->setAstBuild(isl::manage_copy(Build));
+  isl::ast_build Build = IslAstInfo::getBuild(isl::manage_copy(Node));
+  assert(!Build.is_null() && "Could not obtain isl_ast_build from user node");
+  Stmt->setAstBuild(Build);
 
   for (auto *MA : *Stmt) {
     if (!MA->hasNewAccessRelation()) {
@@ -876,13 +876,12 @@ IslNodeBuilder::createNewAccesses(ScopStmt *Stmt,
     assert(MA->isAffine() &&
            "Only affine memory accesses can be code generated");
 
-    auto Schedule = isl_ast_build_get_schedule(Build);
+    isl::union_map Schedule = Build.get_schedule();
 
 #ifndef NDEBUG
     if (MA->isRead()) {
       auto Dom = Stmt->getDomain().release();
-      auto SchedDom = isl_set_from_union_set(
-          isl_union_map_domain(isl_union_map_copy(Schedule)));
+      auto SchedDom = isl_set_from_union_set(Schedule.domain().release());
       auto AccDom = isl_map_domain(MA->getAccessRelation().release());
       Dom = isl_set_intersect_params(Dom,
                                      Stmt->getParent()->getContext().release());
@@ -898,25 +897,20 @@ IslNodeBuilder::createNewAccesses(ScopStmt *Stmt,
     }
 #endif
 
-    auto PWAccRel =
-        MA->applyScheduleToAccessRelation(isl::manage(Schedule)).release();
+    isl::pw_multi_aff PWAccRel = MA->applyScheduleToAccessRelation(Schedule);
 
     // isl cannot generate an index expression for access-nothing accesses.
-    isl::set AccDomain =
-        isl::manage(isl_pw_multi_aff_domain(isl_pw_multi_aff_copy(PWAccRel)));
+    isl::set AccDomain = PWAccRel.domain();
     isl::set Context = S.getContext();
     AccDomain = AccDomain.intersect_params(Context);
-    if (AccDomain.is_empty()) {
-      isl_pw_multi_aff_free(PWAccRel);
+    if (AccDomain.is_empty())
       continue;
-    }
 
-    auto AccessExpr = isl_ast_build_access_from_pw_multi_aff(Build, PWAccRel);
-    NewAccesses =
-        isl_id_to_ast_expr_set(NewAccesses, MA->getId().release(), AccessExpr);
+    isl::ast_expr AccessExpr = Build.access_from(PWAccRel);
+    NewAccesses = NewAccesses.set(MA->getId(), AccessExpr);
   }
 
-  return NewAccesses;
+  return NewAccesses.release();
 }
 
 void IslNodeBuilder::createSubstitutions(__isl_take isl_ast_expr *Expr,


        


More information about the llvm-commits mailing list