[Mlir-commits] [mlir] 551cd1b - [MLIR][NFC] Speed up is valid symbol check (#154924)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Aug 22 05:49:07 PDT 2025
Author: William Moses
Date: 2025-08-22T14:49:04+02:00
New Revision: 551cd1b3068579f54aa4bcd906143ec07542385c
URL: https://github.com/llvm/llvm-project/commit/551cd1b3068579f54aa4bcd906143ec07542385c
DIFF: https://github.com/llvm/llvm-project/commit/551cd1b3068579f54aa4bcd906143ec07542385c.diff
LOG: [MLIR][NFC] Speed up is valid symbol check (#154924)
This removes the closure indirection, and removes the recursion on
isValidSymbol. The rewriting of the recursion is particularly helpful to
avoid redundant checks of isPure and checking the isValidSymbol of the
operands for each parent region check
---------
Co-authored-by: Mehdi Amini <joker.eph at gmail.com>
Added:
Modified:
mlir/lib/Dialect/Affine/IR/AffineOps.cpp
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
index 22608a16cc1ab..7e5ce26b5f733 100644
--- a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
+++ b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
@@ -427,6 +427,21 @@ bool mlir::affine::isValidSymbol(Value value) {
return false;
}
+/// A utility function to check if a value is defined at the top level of
+/// `region` or is an argument of `region` or is defined above the region.
+static bool isTopLevelValueOrAbove(Value value, Region *region) {
+ Region *parentRegion = value.getParentRegion();
+ do {
+ if (parentRegion == region)
+ return true;
+ Operation *regionOp = region->getParentOp();
+ if (regionOp->hasTrait<OpTrait::IsIsolatedFromAbove>())
+ break;
+ region = region->getParentOp()->getParentRegion();
+ } while (region);
+ return false;
+}
+
/// A value can be used as a symbol for `region` iff it meets one of the
/// following conditions:
/// *) It is a constant.
@@ -445,19 +460,12 @@ bool mlir::affine::isValidSymbol(Value value, Region *region) {
return false;
// A top-level value is a valid symbol.
- if (region && ::isTopLevelValue(value, region))
+ if (region && isTopLevelValueOrAbove(value, region))
return true;
auto *defOp = value.getDefiningOp();
- if (!defOp) {
- // A block argument that is not a top-level value is a valid symbol if it
- // dominates region's parent op.
- Operation *regionOp = region ? region->getParentOp() : nullptr;
- if (regionOp && !regionOp->hasTrait<OpTrait::IsIsolatedFromAbove>())
- if (auto *parentOpRegion = region->getParentOp()->getParentRegion())
- return isValidSymbol(value, parentOpRegion);
+ if (!defOp)
return false;
- }
// Constant operation is ok.
Attribute operandCst;
@@ -475,12 +483,6 @@ bool mlir::affine::isValidSymbol(Value value, Region *region) {
if (auto dimOp = dyn_cast<ShapedDimOpInterface>(defOp))
return isDimOpValidSymbol(dimOp, region);
- // Check for values dominating `region`'s parent op.
- Operation *regionOp = region ? region->getParentOp() : nullptr;
- if (regionOp && !regionOp->hasTrait<OpTrait::IsIsolatedFromAbove>())
- if (auto *parentRegion = region->getParentOp()->getParentRegion())
- return isValidSymbol(value, parentRegion);
-
return false;
}
More information about the Mlir-commits
mailing list