[polly] 5bf32a0 - [Polly] Remove checkIslAstExprInt and use RAII instead of manually freeing Expr. NFC.

Michael Kruse via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 15 07:17:41 PDT 2021


Author: Max Fan
Date: 2021-10-15T09:17:00-05:00
New Revision: 5bf32a0e4841d56b481344fb4d074ac96a854261

URL: https://github.com/llvm/llvm-project/commit/5bf32a0e4841d56b481344fb4d074ac96a854261
DIFF: https://github.com/llvm/llvm-project/commit/5bf32a0e4841d56b481344fb4d074ac96a854261.diff

LOG: [Polly] Remove checkIslAstExprInt and use RAII instead of manually freeing Expr. NFC.

Polly is trying to move towards using isl::ast_expr / isl-noexceptions.h
(which implements RAII) where possible instead of manually managing memory.
checkIslAstExprInt manually frees Expr, so it has been removed to be
more idiomatic and consistent.

Reviewed By: Meinersbur

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

Added: 
    

Modified: 
    polly/lib/CodeGen/IslNodeBuilder.cpp

Removed: 
    


################################################################################
diff  --git a/polly/lib/CodeGen/IslNodeBuilder.cpp b/polly/lib/CodeGen/IslNodeBuilder.cpp
index 36864dbe51fa9..77c6cd4cadbcc 100644
--- a/polly/lib/CodeGen/IslNodeBuilder.cpp
+++ b/polly/lib/CodeGen/IslNodeBuilder.cpp
@@ -146,24 +146,6 @@ isl::ast_expr IslNodeBuilder::getUpperBound(isl::ast_node_for For,
   return Cond.get_op_arg(1);
 }
 
-/// Return true if a return value of Predicate is true for the value represented
-/// by passed isl_ast_expr_int.
-static bool checkIslAstExprInt(__isl_take isl_ast_expr *Expr,
-                               isl_bool (*Predicate)(__isl_keep isl_val *)) {
-  if (isl_ast_expr_get_type(Expr) != isl_ast_expr_int) {
-    isl_ast_expr_free(Expr);
-    return false;
-  }
-  auto ExprVal = isl_ast_expr_get_val(Expr);
-  isl_ast_expr_free(Expr);
-  if (Predicate(ExprVal) != isl_bool_true) {
-    isl_val_free(ExprVal);
-    return false;
-  }
-  isl_val_free(ExprVal);
-  return true;
-}
-
 int IslNodeBuilder::getNumberOfIterations(isl::ast_node_for For) {
   assert(isl_ast_node_get_type(For.get()) == isl_ast_node_for);
   isl::ast_node Body = For.body();
@@ -187,14 +169,14 @@ int IslNodeBuilder::getNumberOfIterations(isl::ast_node_for For) {
   }
 
   isl::ast_expr Init = For.init();
-  if (!checkIslAstExprInt(Init.release(), isl_val_is_zero))
+  if (!Init.isa<isl::ast_expr_int>() || !Init.val().is_zero())
     return -1;
   isl::ast_expr Inc = For.inc();
-  if (!checkIslAstExprInt(Inc.release(), isl_val_is_one))
+  if (!Inc.isa<isl::ast_expr_int>() || !Inc.val().is_one())
     return -1;
   CmpInst::Predicate Predicate;
   isl::ast_expr UB = getUpperBound(For, Predicate);
-  if (isl_ast_expr_get_type(UB.get()) != isl_ast_expr_int)
+  if (!UB.isa<isl::ast_expr_int>())
     return -1;
   isl::val UpVal = UB.get_val();
   int NumberIterations = UpVal.get_num_si();


        


More information about the llvm-commits mailing list