Skip to content

Commit 30916b6

Browse files
[MemRef] Migrate away from PointerUnion::{is,get} (NFC) (#120202)
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.
1 parent 345a352 commit 30916b6

File tree

4 files changed

+11
-13
lines changed

4 files changed

+11
-13
lines changed

mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ static void constifyIndexValues(
125125
values[it.index()] = builder.getIndexAttr(constValue);
126126
}
127127
for (OpFoldResult &ofr : values) {
128-
if (ofr.is<Attribute>()) {
128+
if (auto attr = dyn_cast<Attribute>(ofr)) {
129129
// FIXME: We shouldn't need to do that, but right now, the static indices
130130
// are created with the wrong type: `i64` instead of `index`.
131131
// As a result, if we were to keep the attribute as is, we may fail to see
@@ -139,12 +139,11 @@ static void constifyIndexValues(
139139
// The workaround here is to stick to the IndexAttr type for all the
140140
// values, hence we recreate the attribute even when it is already static
141141
// to make sure the type is consistent.
142-
ofr = builder.getIndexAttr(
143-
llvm::cast<IntegerAttr>(ofr.get<Attribute>()).getInt());
142+
ofr = builder.getIndexAttr(llvm::cast<IntegerAttr>(attr).getInt());
144143
continue;
145144
}
146145
std::optional<int64_t> maybeConstant =
147-
getConstantIntValue(ofr.get<Value>());
146+
getConstantIntValue(cast<Value>(ofr));
148147
if (maybeConstant)
149148
ofr = builder.getIndexAttr(*maybeConstant);
150149
}
@@ -1406,12 +1405,11 @@ static bool replaceConstantUsesOf(OpBuilder &rewriter, Location loc,
14061405
// infinite loops in the driver.
14071406
if (result.use_empty() || maybeConstant == getAsOpFoldResult(result))
14081407
continue;
1409-
assert(maybeConstant.template is<Attribute>() &&
1408+
assert(isa<Attribute>(maybeConstant) &&
14101409
"The constified value should be either unchanged (i.e., == result) "
14111410
"or a constant");
14121411
Value constantVal = rewriter.create<arith::ConstantIndexOp>(
1413-
loc, llvm::cast<IntegerAttr>(maybeConstant.template get<Attribute>())
1414-
.getInt());
1412+
loc, llvm::cast<IntegerAttr>(cast<Attribute>(maybeConstant)).getInt());
14151413
for (Operation *op : llvm::make_early_inc_range(result.getUsers())) {
14161414
// modifyOpInPlace: lambda cannot capture structured bindings in C++17
14171415
// yet.

mlir/lib/Dialect/MemRef/Transforms/ComposeSubView.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ struct ComposeSubViewOpPattern : public OpRewritePattern<memref::SubViewOp> {
8282
llvm::zip(op.getMixedOffsets(), sourceOp.getMixedOffsets(),
8383
sourceOp.getMixedStrides(), op.getMixedSizes())) {
8484
// We only support static sizes.
85-
if (opSize.is<Value>()) {
85+
if (isa<Value>(opSize)) {
8686
return failure();
8787
}
8888
sizes.push_back(opSize);
@@ -109,7 +109,7 @@ struct ComposeSubViewOpPattern : public OpRewritePattern<memref::SubViewOp> {
109109
rewriter.getAffineConstantExpr(cast<IntegerAttr>(attr).getInt());
110110
} else {
111111
expr = rewriter.getAffineSymbolExpr(affineApplyOperands.size());
112-
affineApplyOperands.push_back(sourceOffset.get<Value>());
112+
affineApplyOperands.push_back(cast<Value>(sourceOffset));
113113
}
114114

115115
// Multiply 'opOffset' by 'sourceStride' and make the 'expr' add the
@@ -121,7 +121,7 @@ struct ComposeSubViewOpPattern : public OpRewritePattern<memref::SubViewOp> {
121121
expr =
122122
expr + rewriter.getAffineSymbolExpr(affineApplyOperands.size()) *
123123
cast<IntegerAttr>(sourceStrideAttr).getInt();
124-
affineApplyOperands.push_back(opOffset.get<Value>());
124+
affineApplyOperands.push_back(cast<Value>(opOffset));
125125
}
126126

127127
AffineMap map = AffineMap::get(0, affineApplyOperands.size(), expr);

mlir/lib/Dialect/MemRef/Transforms/ExpandStridedMetadata.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ SmallVector<OpFoldResult> getExpandedStrides(memref::ExpandShapeOp expandShape,
383383
AffineExpr s1 = builder.getAffineSymbolExpr(1);
384384
for (; doneStrideIdx < *dynSizeIdx; ++doneStrideIdx) {
385385
int64_t baseExpandedStride =
386-
cast<IntegerAttr>(expandedStrides[doneStrideIdx].get<Attribute>())
386+
cast<IntegerAttr>(cast<Attribute>(expandedStrides[doneStrideIdx]))
387387
.getInt();
388388
expandedStrides[doneStrideIdx] = makeComposedFoldedAffineApply(
389389
builder, expandShape.getLoc(),
@@ -396,7 +396,7 @@ SmallVector<OpFoldResult> getExpandedStrides(memref::ExpandShapeOp expandShape,
396396
AffineExpr s0 = builder.getAffineSymbolExpr(0);
397397
for (; doneStrideIdx < groupSize; ++doneStrideIdx) {
398398
int64_t baseExpandedStride =
399-
cast<IntegerAttr>(expandedStrides[doneStrideIdx].get<Attribute>())
399+
cast<IntegerAttr>(cast<Attribute>(expandedStrides[doneStrideIdx]))
400400
.getInt();
401401
expandedStrides[doneStrideIdx] = makeComposedFoldedAffineApply(
402402
builder, expandShape.getLoc(), s0 * baseExpandedStride, {origStride});

mlir/lib/Dialect/MemRef/Transforms/IndependenceTransforms.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ using namespace mlir::memref;
2121
static FailureOr<OpFoldResult> makeIndependent(OpBuilder &b, Location loc,
2222
OpFoldResult ofr,
2323
ValueRange independencies) {
24-
if (ofr.is<Attribute>())
24+
if (isa<Attribute>(ofr))
2525
return ofr;
2626
AffineMap boundMap;
2727
ValueDimList mapOperands;

0 commit comments

Comments
 (0)