-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Tensor] Migrate away from PointerUnion::{is,get} (NFC) #120679
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Tensor] Migrate away from PointerUnion::{is,get} (NFC) #120679
Conversation
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.
@llvm/pr-subscribers-mlir-tensor Author: Kazu Hirata (kazutakahirata) ChangesNote that PointerUnion::{is,get} have been soft deprecated in // FIXME: Replace the uses of is(), get() and dyn_cast() with I'm not touching PointerUnion::dyn_cast for now because it's a bit Full diff: https://github.com/llvm/llvm-project/pull/120679.diff 3 Files Affected:
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
|
@llvm/pr-subscribers-mlir Author: Kazu Hirata (kazutakahirata) ChangesNote that PointerUnion::{is,get} have been soft deprecated in // FIXME: Replace the uses of is(), get() and dyn_cast() with I'm not touching PointerUnion::dyn_cast for now because it's a bit Full diff: https://github.com/llvm/llvm-project/pull/120679.diff 3 Files Affected:
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
|
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.
Note that PointerUnion::{is,get} have been soft deprecated in
PointerUnion.h:
// FIXME: Replace the uses of is(), get() and dyn_cast() with
// isa, cast and the llvm::dyn_cast
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.