[Mlir-commits] [mlir] [mlir][affine] Add Check for 'affine.for' Bound Map Results (PR #127105)
Ayokunle Amodu
llvmlistbot at llvm.org
Thu Feb 20 16:50:58 PST 2025
https://github.com/ayokunle321 updated https://github.com/llvm/llvm-project/pull/127105
>From bd1bb0055f8ca71327d08777953fc1a10d7caf92 Mon Sep 17 00:00:00 2001
From: Ayokunle Amodu <121697771+ayokunle321 at users.noreply.github.com>
Date: Thu, 13 Feb 2025 11:23:53 -0700
Subject: [PATCH 1/6] added check for affine.for bounds
---
mlir/lib/Dialect/Affine/IR/AffineOps.cpp | 6 ++++++
mlir/test/Dialect/Affine/invalid.mlir | 22 ++++++++++++++++++++++
2 files changed, 28 insertions(+)
diff --git a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
index cfc51ad2a1524..b79cc6850b6e0 100644
--- a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
+++ b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
@@ -1903,6 +1903,12 @@ LogicalResult AffineForOp::verifyRegions() {
getUpperBoundMap().getNumDims())))
return failure();
+ if (getLowerBoundMap().getNumResults() < 1)
+ return emitOpError("expected lower bound map to have at least one result");
+
+ if (getUpperBoundMap().getNumResults() < 1)
+ return emitOpError("expected upper bound map to have at least one result");
+
unsigned opNumResults = getNumResults();
if (opNumResults == 0)
return success();
diff --git a/mlir/test/Dialect/Affine/invalid.mlir b/mlir/test/Dialect/Affine/invalid.mlir
index da2913e3fec28..69d58ce1b5265 100644
--- a/mlir/test/Dialect/Affine/invalid.mlir
+++ b/mlir/test/Dialect/Affine/invalid.mlir
@@ -541,3 +541,25 @@ func.func @dynamic_dimension_index() {
}) : () -> ()
return
}
+
+// -----
+
+#map = affine_map<() -> ()>
+#map1 = affine_map<() -> (1)>
+func.func @no_lower_bound() {
+ // expected-error at +1 {{'affine.for' op expected lower bound map to have at least one result}}
+ affine.for %i = max #map() to min #map1() {
+ }
+ return
+}
+
+// -----
+
+#map = affine_map<() -> ()>
+#map1 = affine_map<() -> (1)>
+func.func @no_upper_bound() {
+ // expected-error at +1 {{'affine.for' op expected upper bound map to have at least one result}}
+ affine.for %i = max #map1() to min #map() {
+ }
+ return
+}
>From b076128b5d28802e0bf393789be5b7f9cfadfd11 Mon Sep 17 00:00:00 2001
From: Ayokunle Amodu <121697771+ayokunle321 at users.noreply.github.com>
Date: Thu, 13 Feb 2025 11:52:48 -0700
Subject: [PATCH 2/6] added comments
---
mlir/lib/Dialect/Affine/IR/AffineOps.cpp | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
index b79cc6850b6e0..e044470cb451c 100644
--- a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
+++ b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
@@ -1902,13 +1902,14 @@ LogicalResult AffineForOp::verifyRegions() {
if (failed(verifyDimAndSymbolIdentifiers(*this, getUpperBoundOperands(),
getUpperBoundMap().getNumDims())))
return failure();
-
+ // Verify that the bound maps produce at least one result.
+ /// Lower bound.
if (getLowerBoundMap().getNumResults() < 1)
return emitOpError("expected lower bound map to have at least one result");
-
+ /// Upper bound.
if (getUpperBoundMap().getNumResults() < 1)
return emitOpError("expected upper bound map to have at least one result");
-
+
unsigned opNumResults = getNumResults();
if (opNumResults == 0)
return success();
>From 552dc806848906377995209490c1170bc8ed5882 Mon Sep 17 00:00:00 2001
From: Ayokunle Amodu <121697771+ayokunle321 at users.noreply.github.com>
Date: Thu, 13 Feb 2025 11:59:08 -0700
Subject: [PATCH 3/6] fixed code style
---
mlir/lib/Dialect/Affine/IR/AffineOps.cpp | 1 +
1 file changed, 1 insertion(+)
diff --git a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
index e044470cb451c..ee7b1ac385304 100644
--- a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
+++ b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
@@ -1902,6 +1902,7 @@ LogicalResult AffineForOp::verifyRegions() {
if (failed(verifyDimAndSymbolIdentifiers(*this, getUpperBoundOperands(),
getUpperBoundMap().getNumDims())))
return failure();
+
// Verify that the bound maps produce at least one result.
/// Lower bound.
if (getLowerBoundMap().getNumResults() < 1)
>From 0eda2e42967837d235445ff9afe726b4d0044c9d Mon Sep 17 00:00:00 2001
From: Ayokunle Amodu <121697771+ayokunle321 at users.noreply.github.com>
Date: Thu, 13 Feb 2025 12:03:34 -0700
Subject: [PATCH 4/6] fix style
---
mlir/lib/Dialect/Affine/IR/AffineOps.cpp | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
index ee7b1ac385304..aa1d97dbbd23b 100644
--- a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
+++ b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
@@ -1901,8 +1901,7 @@ LogicalResult AffineForOp::verifyRegions() {
if (getUpperBoundMap().getNumInputs() > 0)
if (failed(verifyDimAndSymbolIdentifiers(*this, getUpperBoundOperands(),
getUpperBoundMap().getNumDims())))
- return failure();
-
+ return failure();
// Verify that the bound maps produce at least one result.
/// Lower bound.
if (getLowerBoundMap().getNumResults() < 1)
>From e462f378a21673643d7dfde81e3a9828fec719f4 Mon Sep 17 00:00:00 2001
From: Ayokunle Amodu <121697771+ayokunle321 at users.noreply.github.com>
Date: Thu, 13 Feb 2025 12:11:59 -0700
Subject: [PATCH 5/6] format code properly
---
mlir/lib/Dialect/Affine/IR/AffineOps.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
index aa1d97dbbd23b..e044470cb451c 100644
--- a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
+++ b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
@@ -1901,7 +1901,7 @@ LogicalResult AffineForOp::verifyRegions() {
if (getUpperBoundMap().getNumInputs() > 0)
if (failed(verifyDimAndSymbolIdentifiers(*this, getUpperBoundOperands(),
getUpperBoundMap().getNumDims())))
- return failure();
+ return failure();
// Verify that the bound maps produce at least one result.
/// Lower bound.
if (getLowerBoundMap().getNumResults() < 1)
>From 64b65662a3acdfa04e290ecb66259e40e8da7f8f Mon Sep 17 00:00:00 2001
From: Ayokunle Amodu <121697771+ayokunle321 at users.noreply.github.com>
Date: Thu, 13 Feb 2025 12:52:40 -0700
Subject: [PATCH 6/6] removed unnecessary comments
---
mlir/lib/Dialect/Affine/IR/AffineOps.cpp | 3 ---
1 file changed, 3 deletions(-)
diff --git a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
index e044470cb451c..c4891614662a1 100644
--- a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
+++ b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
@@ -1902,11 +1902,8 @@ LogicalResult AffineForOp::verifyRegions() {
if (failed(verifyDimAndSymbolIdentifiers(*this, getUpperBoundOperands(),
getUpperBoundMap().getNumDims())))
return failure();
- // Verify that the bound maps produce at least one result.
- /// Lower bound.
if (getLowerBoundMap().getNumResults() < 1)
return emitOpError("expected lower bound map to have at least one result");
- /// Upper bound.
if (getUpperBoundMap().getNumResults() < 1)
return emitOpError("expected upper bound map to have at least one result");
More information about the Mlir-commits
mailing list