[PATCH] D112193: [Polly][NFC] Switch createSubstitutions and createSubstitutionsVector to use isl::ast_expr

Max Fan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 20 17:23:30 PDT 2021


InnovativeInventor created this revision.
InnovativeInventor added a reviewer: Meinersbur.
InnovativeInventor added a project: Polly.
Herald added a subscriber: tschuett.
Herald added a reviewer: bollu.
InnovativeInventor requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Polly is trying to reduce the amount of manual memory management and use isl::ast_expr, which implements RAII. This partially ports these two functions over to the preferred method of using isl.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D112193

Files:
  polly/include/polly/CodeGen/IslNodeBuilder.h
  polly/lib/CodeGen/IslNodeBuilder.cpp


Index: polly/lib/CodeGen/IslNodeBuilder.cpp
===================================================================
--- polly/lib/CodeGen/IslNodeBuilder.cpp
+++ polly/lib/CodeGen/IslNodeBuilder.cpp
@@ -408,7 +408,7 @@
   isl_map *S = isl_map_from_union_map(Schedule);
 
   auto *NewAccesses = createNewAccesses(Stmt, User);
-  createSubstitutionsVector(isl::manage(Expr), Stmt, VLTS, IVS, IteratorID);
+  createSubstitutionsVector(Expr, Stmt, VLTS, IVS, IteratorID);
   VectorBlockGenerator::generate(BlockGen, *Stmt, VLTS, S, NewAccesses);
   isl_id_to_ast_expr_free(NewAccesses);
   isl_map_free(S);
@@ -927,35 +927,41 @@
   return NewAccesses.release();
 }
 
-void IslNodeBuilder::createSubstitutions(isl::ast_expr Expr, ScopStmt *Stmt,
-                                         LoopToScevMapT &LTS) {
-  assert(isl_ast_expr_get_type(Expr.get()) == isl_ast_expr_op &&
+void IslNodeBuilder::createSubstitutions(__isl_take isl_ast_expr *Expr,
+                                         ScopStmt *Stmt, LoopToScevMapT &LTS) {
+  assert(isl_ast_expr_get_type(Expr) == isl_ast_expr_op &&
          "Expression of type 'op' expected");
-  assert(isl_ast_expr_get_op_type(Expr.get()) == isl_ast_op_call &&
+  assert(isl_ast_expr_get_op_type(Expr) == isl_ast_op_call &&
          "Operation of type 'call' expected");
-  for (int i = 0; i < isl_ast_expr_get_op_n_arg(Expr.get()) - 1; ++i) {
+  for (int i = 0; i < isl_ast_expr_get_op_n_arg(Expr) - 1; ++i) {
+    isl_ast_expr *SubExpr;
     Value *V;
 
-    V = ExprBuilder.create(isl_ast_expr_copy(Expr.op_arg(i + 1).get()));
+    SubExpr = isl_ast_expr_get_op_arg(Expr, i + 1);
+    V = ExprBuilder.create(SubExpr);
     ScalarEvolution *SE = Stmt->getParent()->getSE();
     LTS[Stmt->getLoopForDimension(i)] = SE->getUnknown(V);
   }
+
+  isl_ast_expr_free(Expr);
 }
 
 void IslNodeBuilder::createSubstitutionsVector(
-    isl::ast_expr Expr, ScopStmt *Stmt, std::vector<LoopToScevMapT> &VLTS,
-    std::vector<Value *> &IVS, __isl_take isl_id *IteratorID) {
+    __isl_take isl_ast_expr *Expr, ScopStmt *Stmt,
+    std::vector<LoopToScevMapT> &VLTS, std::vector<Value *> &IVS,
+    __isl_take isl_id *IteratorID) {
   int i = 0;
 
   Value *OldValue = IDToValue[IteratorID];
   for (Value *IV : IVS) {
     IDToValue[IteratorID] = IV;
-    createSubstitutions(Expr, Stmt, VLTS[i]);
+    createSubstitutions(isl_ast_expr_copy(Expr), Stmt, VLTS[i]);
     i++;
   }
 
   IDToValue[IteratorID] = OldValue;
   isl_id_free(IteratorID);
+  isl_ast_expr_free(Expr);
 }
 
 void IslNodeBuilder::generateCopyStmt(
@@ -1005,7 +1011,7 @@
     generateCopyStmt(Stmt, NewAccesses);
     isl_ast_expr_free(Expr);
   } else {
-    createSubstitutions(isl::manage(Expr), Stmt, LTS);
+    createSubstitutions(Expr, Stmt, LTS);
 
     if (Stmt->isBlockStmt())
       BlockGen.copyStmt(*Stmt, LTS, NewAccesses);
Index: polly/include/polly/CodeGen/IslNodeBuilder.h
===================================================================
--- polly/include/polly/CodeGen/IslNodeBuilder.h
+++ polly/include/polly/CodeGen/IslNodeBuilder.h
@@ -368,9 +368,9 @@
   ///             that counts the number of times a loop is executed. For each
   ///             original loop this count, expressed in function of the new
   ///             induction variables, is added to the LTS map.
-  void createSubstitutions(isl::ast_expr Expr, ScopStmt *Stmt,
+  void createSubstitutions(__isl_take isl_ast_expr *Expr, ScopStmt *Stmt,
                            LoopToScevMapT &LTS);
-  void createSubstitutionsVector(isl::ast_expr Expr, ScopStmt *Stmt,
+  void createSubstitutionsVector(__isl_take isl_ast_expr *Expr, ScopStmt *Stmt,
                                  std::vector<LoopToScevMapT> &VLTS,
                                  std::vector<Value *> &IVS,
                                  __isl_take isl_id *IteratorID);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112193.381118.patch
Type: text/x-patch
Size: 3833 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211021/c2ba3384/attachment.bin>


More information about the llvm-commits mailing list