Skip to content

Commit

Permalink
[MemRef] Migrate away from PointerUnion::{is,get} (NFC) (#120382)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kazutakahirata authored Dec 18, 2024
1 parent d57230c commit 6e41483
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
10 changes: 5 additions & 5 deletions mlir/lib/Dialect/Vector/IR/VectorOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,8 @@ SmallVector<int64_t> vector::getAsIntegers(ArrayRef<OpFoldResult> foldResults) {
SmallVector<int64_t> ints;
llvm::transform(
foldResults, std::back_inserter(ints), [](OpFoldResult foldResult) {
assert(foldResult.is<Attribute>() && "Unexpected non-constant index");
return cast<IntegerAttr>(foldResult.get<Attribute>()).getInt();
assert(isa<Attribute>(foldResult) && "Unexpected non-constant index");
return cast<IntegerAttr>(cast<Attribute>(foldResult)).getInt();
});
return ints;
}
Expand All @@ -346,7 +346,7 @@ SmallVector<Value> vector::getAsValues(OpBuilder &builder, Location loc,
loc, cast<IntegerAttr>(attr).getInt())
.getResult();

return foldResult.get<Value>();
return cast<Value>(foldResult);
});
return values;
}
Expand Down Expand Up @@ -1353,8 +1353,8 @@ LogicalResult vector::ExtractOp::verify() {
return emitOpError(
"expected position attribute of rank no greater than vector rank");
for (auto [idx, pos] : llvm::enumerate(position)) {
if (pos.is<Attribute>()) {
int64_t constIdx = cast<IntegerAttr>(pos.get<Attribute>()).getInt();
if (auto attr = dyn_cast<Attribute>(pos)) {
int64_t constIdx = cast<IntegerAttr>(attr).getInt();
if (constIdx < 0 || constIdx >= getSourceVectorType().getDimSize(idx)) {
return emitOpError("expected position attribute #")
<< (idx + 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ static SmallVector<int64_t> getReducedShape(ArrayRef<OpFoldResult> mixedSizes) {
continue;
}

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

if (collapsedOffset.is<Value>()) {
indicesAfterCollapsing.push_back(collapsedOffset.get<Value>());
if (auto value = dyn_cast<Value>(collapsedOffset)) {
indicesAfterCollapsing.push_back(value);
} else {
indicesAfterCollapsing.push_back(rewriter.create<arith::ConstantIndexOp>(
loc, *getConstantIntValue(collapsedOffset)));
Expand Down Expand Up @@ -841,8 +841,8 @@ class RewriteScalarExtractElementOfTransferRead
OpFoldResult ofr = affine::makeComposedFoldedAffineApply(
rewriter, loc, sym0 + sym1,
{newIndices[newIndices.size() - 1], extractOp.getPosition()});
if (ofr.is<Value>()) {
newIndices[newIndices.size() - 1] = ofr.get<Value>();
if (auto value = dyn_cast<Value>(ofr)) {
newIndices[newIndices.size() - 1] = value;
} else {
newIndices[newIndices.size() - 1] =
rewriter.create<arith::ConstantIndexOp>(loc,
Expand Down Expand Up @@ -879,14 +879,14 @@ class RewriteScalarExtractOfTransferRead
SmallVector<Value> newIndices(xferOp.getIndices().begin(),
xferOp.getIndices().end());
for (auto [i, pos] : llvm::enumerate(extractOp.getMixedPosition())) {
assert(pos.is<Attribute>() && "Unexpected non-constant index");
int64_t offset = cast<IntegerAttr>(pos.get<Attribute>()).getInt();
assert(isa<Attribute>(pos) && "Unexpected non-constant index");
int64_t offset = cast<IntegerAttr>(cast<Attribute>(pos)).getInt();
int64_t idx = newIndices.size() - extractOp.getNumIndices() + i;
OpFoldResult ofr = affine::makeComposedFoldedAffineApply(
rewriter, extractOp.getLoc(),
rewriter.getAffineSymbolExpr(0) + offset, {newIndices[idx]});
if (ofr.is<Value>()) {
newIndices[idx] = ofr.get<Value>();
if (auto value = dyn_cast<Value>(ofr)) {
newIndices[idx] = value;
} else {
newIndices[idx] = rewriter.create<arith::ConstantIndexOp>(
extractOp.getLoc(), *getConstantIntValue(ofr));
Expand Down
4 changes: 2 additions & 2 deletions mlir/lib/Dialect/Vector/Transforms/VectorTransforms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -598,9 +598,9 @@ struct BubbleDownVectorBitCastForExtract

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

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

0 comments on commit 6e41483

Please sign in to comment.