Skip to content

Commit 6e41483

Browse files
[MemRef] Migrate away from PointerUnion::{is,get} (NFC) (#120382)
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 d57230c commit 6e41483

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

mlir/lib/Dialect/Vector/IR/VectorOps.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,8 @@ SmallVector<int64_t> vector::getAsIntegers(ArrayRef<OpFoldResult> foldResults) {
327327
SmallVector<int64_t> ints;
328328
llvm::transform(
329329
foldResults, std::back_inserter(ints), [](OpFoldResult foldResult) {
330-
assert(foldResult.is<Attribute>() && "Unexpected non-constant index");
331-
return cast<IntegerAttr>(foldResult.get<Attribute>()).getInt();
330+
assert(isa<Attribute>(foldResult) && "Unexpected non-constant index");
331+
return cast<IntegerAttr>(cast<Attribute>(foldResult)).getInt();
332332
});
333333
return ints;
334334
}
@@ -346,7 +346,7 @@ SmallVector<Value> vector::getAsValues(OpBuilder &builder, Location loc,
346346
loc, cast<IntegerAttr>(attr).getInt())
347347
.getResult();
348348

349-
return foldResult.get<Value>();
349+
return cast<Value>(foldResult);
350350
});
351351
return values;
352352
}
@@ -1353,8 +1353,8 @@ LogicalResult vector::ExtractOp::verify() {
13531353
return emitOpError(
13541354
"expected position attribute of rank no greater than vector rank");
13551355
for (auto [idx, pos] : llvm::enumerate(position)) {
1356-
if (pos.is<Attribute>()) {
1357-
int64_t constIdx = cast<IntegerAttr>(pos.get<Attribute>()).getInt();
1356+
if (auto attr = dyn_cast<Attribute>(pos)) {
1357+
int64_t constIdx = cast<IntegerAttr>(attr).getInt();
13581358
if (constIdx < 0 || constIdx >= getSourceVectorType().getDimSize(idx)) {
13591359
return emitOpError("expected position attribute #")
13601360
<< (idx + 1)

mlir/lib/Dialect/Vector/Transforms/VectorTransferOpTransforms.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ static SmallVector<int64_t> getReducedShape(ArrayRef<OpFoldResult> mixedSizes) {
251251
continue;
252252
}
253253

254-
auto value = cast<IntegerAttr>(size.get<Attribute>()).getValue();
254+
auto value = cast<IntegerAttr>(cast<Attribute>(size)).getValue();
255255
if (value == 1)
256256
continue;
257257
reducedShape.push_back(value.getSExtValue());
@@ -570,8 +570,8 @@ static SmallVector<Value> getCollapsedIndices(RewriterBase &rewriter,
570570
collapsedOffset = affine::makeComposedFoldedAffineApply(
571571
rewriter, loc, collapsedExpr, collapsedVals);
572572

573-
if (collapsedOffset.is<Value>()) {
574-
indicesAfterCollapsing.push_back(collapsedOffset.get<Value>());
573+
if (auto value = dyn_cast<Value>(collapsedOffset)) {
574+
indicesAfterCollapsing.push_back(value);
575575
} else {
576576
indicesAfterCollapsing.push_back(rewriter.create<arith::ConstantIndexOp>(
577577
loc, *getConstantIntValue(collapsedOffset)));
@@ -841,8 +841,8 @@ class RewriteScalarExtractElementOfTransferRead
841841
OpFoldResult ofr = affine::makeComposedFoldedAffineApply(
842842
rewriter, loc, sym0 + sym1,
843843
{newIndices[newIndices.size() - 1], extractOp.getPosition()});
844-
if (ofr.is<Value>()) {
845-
newIndices[newIndices.size() - 1] = ofr.get<Value>();
844+
if (auto value = dyn_cast<Value>(ofr)) {
845+
newIndices[newIndices.size() - 1] = value;
846846
} else {
847847
newIndices[newIndices.size() - 1] =
848848
rewriter.create<arith::ConstantIndexOp>(loc,
@@ -879,14 +879,14 @@ class RewriteScalarExtractOfTransferRead
879879
SmallVector<Value> newIndices(xferOp.getIndices().begin(),
880880
xferOp.getIndices().end());
881881
for (auto [i, pos] : llvm::enumerate(extractOp.getMixedPosition())) {
882-
assert(pos.is<Attribute>() && "Unexpected non-constant index");
883-
int64_t offset = cast<IntegerAttr>(pos.get<Attribute>()).getInt();
882+
assert(isa<Attribute>(pos) && "Unexpected non-constant index");
883+
int64_t offset = cast<IntegerAttr>(cast<Attribute>(pos)).getInt();
884884
int64_t idx = newIndices.size() - extractOp.getNumIndices() + i;
885885
OpFoldResult ofr = affine::makeComposedFoldedAffineApply(
886886
rewriter, extractOp.getLoc(),
887887
rewriter.getAffineSymbolExpr(0) + offset, {newIndices[idx]});
888-
if (ofr.is<Value>()) {
889-
newIndices[idx] = ofr.get<Value>();
888+
if (auto value = dyn_cast<Value>(ofr)) {
889+
newIndices[idx] = value;
890890
} else {
891891
newIndices[idx] = rewriter.create<arith::ConstantIndexOp>(
892892
extractOp.getLoc(), *getConstantIntValue(ofr));

mlir/lib/Dialect/Vector/Transforms/VectorTransforms.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -598,9 +598,9 @@ struct BubbleDownVectorBitCastForExtract
598598

599599
// Get the first element of the mixed position as integer.
600600
auto mixedPos = extractOp.getMixedPosition();
601-
if (mixedPos.size() > 0 && !mixedPos[0].is<Attribute>())
601+
if (mixedPos.size() > 0 && !isa<Attribute>(mixedPos[0]))
602602
return failure();
603-
uint64_t index = cast<IntegerAttr>(mixedPos[0].get<Attribute>()).getInt();
603+
uint64_t index = cast<IntegerAttr>(cast<Attribute>(mixedPos[0])).getInt();
604604

605605
// Get the single scalar (as a vector) in the source value that packs the
606606
// desired scalar. E.g. extract vector<1xf32> from vector<4xf32>

0 commit comments

Comments
 (0)