[Mlir-commits] [mlir] fecf139 - [Tensor] Migrate away from PointerUnion::{is, get} (NFC) (#120679)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Fri Dec 20 10:41:57 PST 2024


Author: Kazu Hirata
Date: 2024-12-20T10:41:54-08:00
New Revision: fecf1397e32a89a928ebeeab07bfc7e38a318827

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

LOG: [Tensor] Migrate away from PointerUnion::{is,get} (NFC) (#120679)

Note that PointerUnion::{is,get} have been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //        isa<T>, cast<T> and the llvm::dyn_cast<T>

I'm not touching PointerUnion::dyn_cast for now because it's a bit
complicated; we could blindly migrate it to dyn_cast_if_present, but
we should probably use dyn_cast when the operand is known to be
non-null.

Added: 
    

Modified: 
    mlir/lib/Dialect/Tensor/IR/TensorOps.cpp
    mlir/lib/Dialect/Tensor/Transforms/BufferizableOpInterfaceImpl.cpp
    mlir/lib/Dialect/Tensor/Transforms/IndependenceTransforms.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp b/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp
index 21f78cf96c70e9..f79c774ceb3e9a 100644
--- a/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp
+++ b/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp
@@ -142,8 +142,8 @@ static llvm::SmallBitVector getDroppedDims(ArrayRef<int64_t> reducedShape,
     size_t idx = mixedSizes.size() - size.index() - 1;
     // Rank-reduced dims must have a static unit dimension.
     bool isStaticUnitSize =
-        size.value().is<Attribute>() &&
-        llvm::cast<IntegerAttr>(size.value().get<Attribute>()).getInt() == 1;
+        isa<Attribute>(size.value()) &&
+        llvm::cast<IntegerAttr>(cast<Attribute>(size.value())).getInt() == 1;
 
     if (shapePos < 0) {
       // There are no more dims in the reduced shape. All remaining sizes must

diff  --git a/mlir/lib/Dialect/Tensor/Transforms/BufferizableOpInterfaceImpl.cpp b/mlir/lib/Dialect/Tensor/Transforms/BufferizableOpInterfaceImpl.cpp
index 9797b73f534a96..1abcacd6d6db3d 100644
--- a/mlir/lib/Dialect/Tensor/Transforms/BufferizableOpInterfaceImpl.cpp
+++ b/mlir/lib/Dialect/Tensor/Transforms/BufferizableOpInterfaceImpl.cpp
@@ -761,8 +761,8 @@ struct PadOpInterface
     RankedTensorType srcType = padOp.getSourceType();
 
     auto toValue = [&](OpFoldResult ofr) {
-      if (ofr.is<Value>())
-        return ofr.get<Value>();
+      if (auto value = dyn_cast<Value>(ofr))
+        return value;
       return rewriter
           .create<arith::ConstantIndexOp>(loc, *getConstantIntValue(ofr))
           .getResult();

diff  --git a/mlir/lib/Dialect/Tensor/Transforms/IndependenceTransforms.cpp b/mlir/lib/Dialect/Tensor/Transforms/IndependenceTransforms.cpp
index a89ce20048dff3..4655fa3cf0d23e 100644
--- a/mlir/lib/Dialect/Tensor/Transforms/IndependenceTransforms.cpp
+++ b/mlir/lib/Dialect/Tensor/Transforms/IndependenceTransforms.cpp
@@ -21,9 +21,9 @@ using namespace mlir::tensor;
 static FailureOr<OpFoldResult> makeIndependent(OpBuilder &b, Location loc,
                                                OpFoldResult ofr,
                                                ValueRange independencies) {
-  if (ofr.is<Attribute>())
+  if (isa<Attribute>(ofr))
     return ofr;
-  Value value = ofr.get<Value>();
+  Value value = cast<Value>(ofr);
   AffineMap boundMap;
   ValueDimList mapOperands;
   if (failed(ValueBoundsConstraintSet::computeIndependentBound(
@@ -80,14 +80,14 @@ FailureOr<Value> tensor::buildIndependentOp(OpBuilder &b, tensor::PadOp padOp,
   for (int64_t i = 0, e = padOp.getResultType().getRank(); i < e; ++i) {
     // offset = ub(low_padding) - low_padding
     OpFoldResult prevLow = padOp.getMixedLowPad()[i];
-    if (prevLow.is<Attribute>()) {
+    if (isa<Attribute>(prevLow)) {
       offsets.push_back(b.getIndexAttr(0));
     } else {
       offsets.push_back(
           b.create<affine::AffineApplyOp>(
                loc, b.getAffineDimExpr(0) - b.getAffineDimExpr(1),
-               std::initializer_list<Value>{newMixedLow[i].get<Value>(),
-                                            prevLow.get<Value>()})
+               std::initializer_list<Value>{cast<Value>(newMixedLow[i]),
+                                            cast<Value>(prevLow)})
               .getResult());
     }
     // size = reified result size


        


More information about the Mlir-commits mailing list