Skip to content

[MemRef] Migrate away from PointerUnion::{is,get} (NFC) #120382

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading