[Mlir-commits] [mlir] 25d6995 - [mlir] More support for detached regions in affine symbol checkers

Alex Zinenko llvmlistbot at llvm.org
Mon May 11 06:29:55 PDT 2020


Author: Alex Zinenko
Date: 2020-05-11T15:29:47+02:00
New Revision: 25d6995079431531c2c7c8955ebe9a3d1875180d

URL: https://github.com/llvm/llvm-project/commit/25d6995079431531c2c7c8955ebe9a3d1875180d
DIFF: https://github.com/llvm/llvm-project/commit/25d6995079431531c2c7c8955ebe9a3d1875180d.diff

LOG: [mlir] More support for detached regions in affine symbol checkers

Add documentation to `isToLevelValue` explaining its behavior for
detached regions, and fix the overloaded version that accepts `Region`.

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 1766728894fd..c6d67723ecd1 100644
--- a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
+++ b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
@@ -85,13 +85,18 @@ Operation *AffineDialect::materializeConstant(OpBuilder &builder,
 }
 
 /// A utility function to check if a value is defined at the top level of an
-/// op with trait `AffineScope`. A value of index type defined at the top
-/// level is always a valid symbol.
+/// op with trait `AffineScope`. If the value is defined in an unlinked region,
+/// conservatively assume it is not top-level. A value of index type defined at
+/// the top level is always a valid symbol.
 bool mlir::isTopLevelValue(Value value) {
   if (auto arg = value.dyn_cast<BlockArgument>()) {
+    // The block owning the argument may be unlinked, e.g. when the surrounding
+    // region has not yet been attached to an Op, at which point the parent Op
+    // is null.
     Operation *parentOp = arg.getOwner()->getParentOp();
     return parentOp && parentOp->hasTrait<OpTrait::AffineScope>();
   }
+  // The defining Op may live in an unlinked block so its parent Op may be null.
   Operation *parentOp = value.getDefiningOp()->getParentOp();
   return parentOp && parentOp->hasTrait<OpTrait::AffineScope>();
 }
@@ -103,7 +108,7 @@ bool mlir::isTopLevelValue(Value value) {
 static bool isTopLevelValue(Value value, Region *region) {
   if (auto arg = value.dyn_cast<BlockArgument>())
     return arg.getParentRegion() == region;
-  return value.getDefiningOp()->getParentOp() == region->getParentOp();
+  return value.getDefiningOp()->getParentRegion() == region;
 }
 
 /// Returns the closest region enclosing `op` that is held by an operation with


        


More information about the Mlir-commits mailing list