Skip to content

Commit 4f279a5

Browse files
[Linalg] Migrate away from PointerUnion::{is,get} (NFC) (#120043)
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 4032ce3 commit 4f279a5

File tree

5 files changed

+14
-16
lines changed

5 files changed

+14
-16
lines changed

mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,14 @@ static DiagnosedSilenceableFailure unpackSingleIndexResultPayloadOperations(
9494
transform::TransformState &state, TransformOpInterface transformOp,
9595
SmallVector<OpFoldResult> &result, ArrayRef<OpFoldResult> ofrs) {
9696
for (OpFoldResult ofr : ofrs) {
97-
if (ofr.is<Attribute>()) {
98-
if (!isa<IntegerAttr>(ofr.get<Attribute>()))
97+
if (auto attr = dyn_cast<Attribute>(ofr)) {
98+
if (!isa<IntegerAttr>(attr))
9999
return transformOp.emitDefiniteFailure() << "expected IntegerAttr";
100100
result.push_back(ofr);
101101
continue;
102102
}
103103

104-
Value transformValue = ofr.get<Value>();
104+
Value transformValue = cast<Value>(ofr);
105105
if (isa<TransformParamTypeInterface>(transformValue.getType())) {
106106
ArrayRef<Attribute> params = state.getParams(transformValue);
107107
if (params.size() != 1)
@@ -180,20 +180,19 @@ static DiagnosedSilenceableFailure reifyMixedParamAndHandleResults(
180180
TransformState &state, TransformOpInterface &transformOp,
181181
ArrayRef<OpFoldResult> mixedResults, SmallVectorImpl<int64_t> &reified) {
182182
for (OpFoldResult paramOrHandle : mixedResults) {
183-
if (isa<Attribute>(paramOrHandle)) {
184-
reified.push_back(
185-
cast<IntegerAttr>(paramOrHandle.get<Attribute>()).getInt());
183+
if (auto attr = dyn_cast<Attribute>(paramOrHandle)) {
184+
reified.push_back(cast<IntegerAttr>(attr).getInt());
186185
continue;
187-
} else if (isa<ParamType>(paramOrHandle.get<Value>().getType())) {
188-
ArrayRef<Attribute> params = state.getParams(paramOrHandle.get<Value>());
186+
} else if (isa<ParamType>(cast<Value>(paramOrHandle).getType())) {
187+
ArrayRef<Attribute> params = state.getParams(cast<Value>(paramOrHandle));
189188
if (params.size() != 1)
190189
return transformOp.emitSilenceableError() << "expected a single param";
191190
reified.push_back(
192191
cast<IntegerAttr>(params.front()).getValue().getSExtValue());
193192
continue;
194193
}
195194

196-
Value handle = paramOrHandle.get<Value>();
195+
Value handle = cast<Value>(paramOrHandle);
197196
if (!isa<TransformHandleTypeInterface>(handle.getType()))
198197
return transformOp.emitSilenceableError() << "unexpected value handle";
199198
auto payload = state.getPayloadOps(handle);

mlir/lib/Dialect/Linalg/Transforms/ConvertToDestinationStyle.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,8 @@ static SmallVector<Value> reifyOrComputeDynamicSizes(OpBuilder &b,
170170
SmallVector<Value> dynSizes;
171171
for (int64_t i = 0; i < tensorType.getRank(); ++i) {
172172
if (tensorType.isDynamicDim(i))
173-
dynSizes.push_back(
174-
reifiedShape[cast<OpResult>(value).getResultNumber()][i]
175-
.get<Value>());
173+
dynSizes.push_back(cast<Value>(
174+
reifiedShape[cast<OpResult>(value).getResultNumber()][i]));
176175
}
177176
return dynSizes;
178177
}
@@ -437,7 +436,7 @@ mlir::linalg::rewriteInDestinationPassingStyle(RewriterBase &rewriter,
437436
SmallVector<Value> dynamicSizes;
438437
for (int64_t i = 0; i < resultType.getRank(); ++i)
439438
if (resultType.isDynamicDim(i))
440-
dynamicSizes.push_back(reifiedShape[0][i].get<Value>());
439+
dynamicSizes.push_back(cast<Value>(reifiedShape[0][i]));
441440

442441
// If the `padOp` has a nofold attribute and all paddings are known to be 0,
443442
// explicitly insert a `linalg.copy`.

mlir/lib/Dialect/Linalg/Transforms/ElementwiseOpFusion.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1707,7 +1707,7 @@ FailureOr<CollapseResult> mlir::linalg::collapseOpIterationDims(
17071707
if (auto attr = llvm::dyn_cast_if_present<Attribute>(ofr))
17081708
return cast<IntegerAttr>(attr).getInt() == value;
17091709
llvm::APInt actual;
1710-
return matchPattern(ofr.get<Value>(), m_ConstantInt(&actual)) &&
1710+
return matchPattern(cast<Value>(ofr), m_ConstantInt(&actual)) &&
17111711
actual.getSExtValue() == value;
17121712
};
17131713
if (!llvm::all_of(loopRanges, [&](Range range) {

mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ static void emitIsPositiveIndexAssertion(ImplicitLocOpBuilder &b,
101101

102102
Value zero = b.create<arith::ConstantIndexOp>(0);
103103
Value condition = b.create<arith::CmpIOp>(arith::CmpIPredicate::sgt,
104-
value.get<Value>(), zero);
104+
cast<Value>(value), zero);
105105
b.create<cf::AssertOp>(
106106
condition,
107107
b.getStringAttr("expected strictly positive tile size and divisor"));

mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ DecomposePadOpPattern::matchAndRewrite(tensor::PadOp padOp,
948948
return val;
949949
return rewriter
950950
.create<arith::ConstantIndexOp>(
951-
padOp.getLoc(), cast<IntegerAttr>(ofr.get<Attribute>()).getInt())
951+
padOp.getLoc(), cast<IntegerAttr>(cast<Attribute>(ofr)).getInt())
952952
.getResult();
953953
};
954954

0 commit comments

Comments
 (0)