[polly] [polly][ScheduleOptimizer] Use IslMaxOperationsGuard helper instead of explicit restoration (PR #79303)

Karthika Devi C via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 24 07:13:53 PST 2024


https://github.com/kartcq created https://github.com/llvm/llvm-project/pull/79303

To fix long compile time issue of Schedule optimizer, patch #77280 sets the upper cap on max ISL operations. In case of bailing out when ISL quota is hit, error handling behavior was restored manually. This commit replaces the restoration code with IslMaxOperationsGuard helper and also removes redundant early return.

>From 2b2445fb5d5a17b19ddaf0f8ec51c3fb0e98ff66 Mon Sep 17 00:00:00 2001
From: kartcq <quic_kartc at quicinc.com>
Date: Wed, 24 Jan 2024 06:06:35 -0800
Subject: [PATCH] [polly][ScheduleOptimizer] Use IslMaxOperationsGuard helper
 instead of explicit restoration

To fix long compile time issue of Schedule optimizer, patch #77280 sets
the upper cap on max ISL operations. In case of bailing out when isl
quota is hit, error handling behavior was restored manually. This
commit replaces the restoration code with IslMaxOperationsGuard helper
and also removes redundant early return.
---
 polly/lib/Transform/ScheduleOptimizer.cpp | 23 +++++++----------------
 1 file changed, 7 insertions(+), 16 deletions(-)

diff --git a/polly/lib/Transform/ScheduleOptimizer.cpp b/polly/lib/Transform/ScheduleOptimizer.cpp
index 8ee2b66339adbce..5a0ea3b40675429 100644
--- a/polly/lib/Transform/ScheduleOptimizer.cpp
+++ b/polly/lib/Transform/ScheduleOptimizer.cpp
@@ -868,23 +868,14 @@ static void runIslScheduleOptimizer(
     SC = SC.set_validity(Validity);
     SC = SC.set_coincidence(Validity);
 
-    // Save error handling behavior
-    long MaxOperations = isl_ctx_get_max_operations(Ctx);
-    isl_ctx_set_max_operations(Ctx, ScheduleComputeOut);
-    Schedule = SC.compute_schedule();
-    bool ScheduleQuota = false;
-    if (isl_ctx_last_error(Ctx) == isl_error_quota) {
-      isl_ctx_reset_error(Ctx);
-      LLVM_DEBUG(
-          dbgs() << "Schedule optimizer calculation exceeds ISL quota\n");
-      ScheduleQuota = true;
-    }
-    isl_options_set_on_error(Ctx, ISL_ON_ERROR_ABORT);
-    isl_ctx_reset_operations(Ctx);
-    isl_ctx_set_max_operations(Ctx, MaxOperations);
+    {
+      IslMaxOperationsGuard MaxOpGuard(Ctx, ScheduleComputeOut);
+      Schedule = SC.compute_schedule();
 
-    if (ScheduleQuota)
-      return;
+      if (MaxOpGuard.hasQuotaExceeded())
+        LLVM_DEBUG(
+            dbgs() << "Schedule optimizer calculation exceeds ISL quota\n");
+    }
 
     isl_options_set_on_error(Ctx, OnErrorStatus);
 



More information about the llvm-commits mailing list