Skip to content

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

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
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
17 changes: 8 additions & 9 deletions mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ static DiagnosedSilenceableFailure unpackSingleIndexResultPayloadOperations(
transform::TransformState &state, TransformOpInterface transformOp,
SmallVector<OpFoldResult> &result, ArrayRef<OpFoldResult> ofrs) {
for (OpFoldResult ofr : ofrs) {
if (ofr.is<Attribute>()) {
if (!isa<IntegerAttr>(ofr.get<Attribute>()))
if (auto attr = dyn_cast<Attribute>(ofr)) {
if (!isa<IntegerAttr>(attr))
return transformOp.emitDefiniteFailure() << "expected IntegerAttr";
result.push_back(ofr);
continue;
}

Value transformValue = ofr.get<Value>();
Value transformValue = cast<Value>(ofr);
if (isa<TransformParamTypeInterface>(transformValue.getType())) {
ArrayRef<Attribute> params = state.getParams(transformValue);
if (params.size() != 1)
Expand Down Expand Up @@ -180,20 +180,19 @@ static DiagnosedSilenceableFailure reifyMixedParamAndHandleResults(
TransformState &state, TransformOpInterface &transformOp,
ArrayRef<OpFoldResult> mixedResults, SmallVectorImpl<int64_t> &reified) {
for (OpFoldResult paramOrHandle : mixedResults) {
if (isa<Attribute>(paramOrHandle)) {
reified.push_back(
cast<IntegerAttr>(paramOrHandle.get<Attribute>()).getInt());
if (auto attr = dyn_cast<Attribute>(paramOrHandle)) {
reified.push_back(cast<IntegerAttr>(attr).getInt());
continue;
} else if (isa<ParamType>(paramOrHandle.get<Value>().getType())) {
ArrayRef<Attribute> params = state.getParams(paramOrHandle.get<Value>());
} else if (isa<ParamType>(cast<Value>(paramOrHandle).getType())) {
ArrayRef<Attribute> params = state.getParams(cast<Value>(paramOrHandle));
if (params.size() != 1)
return transformOp.emitSilenceableError() << "expected a single param";
reified.push_back(
cast<IntegerAttr>(params.front()).getValue().getSExtValue());
continue;
}

Value handle = paramOrHandle.get<Value>();
Value handle = cast<Value>(paramOrHandle);
if (!isa<TransformHandleTypeInterface>(handle.getType()))
return transformOp.emitSilenceableError() << "unexpected value handle";
auto payload = state.getPayloadOps(handle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,8 @@ static SmallVector<Value> reifyOrComputeDynamicSizes(OpBuilder &b,
SmallVector<Value> dynSizes;
for (int64_t i = 0; i < tensorType.getRank(); ++i) {
if (tensorType.isDynamicDim(i))
dynSizes.push_back(
reifiedShape[cast<OpResult>(value).getResultNumber()][i]
.get<Value>());
dynSizes.push_back(cast<Value>(
reifiedShape[cast<OpResult>(value).getResultNumber()][i]));
}
return dynSizes;
}
Expand Down Expand Up @@ -437,7 +436,7 @@ mlir::linalg::rewriteInDestinationPassingStyle(RewriterBase &rewriter,
SmallVector<Value> dynamicSizes;
for (int64_t i = 0; i < resultType.getRank(); ++i)
if (resultType.isDynamicDim(i))
dynamicSizes.push_back(reifiedShape[0][i].get<Value>());
dynamicSizes.push_back(cast<Value>(reifiedShape[0][i]));

// If the `padOp` has a nofold attribute and all paddings are known to be 0,
// explicitly insert a `linalg.copy`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1707,7 +1707,7 @@ FailureOr<CollapseResult> mlir::linalg::collapseOpIterationDims(
if (auto attr = llvm::dyn_cast_if_present<Attribute>(ofr))
return cast<IntegerAttr>(attr).getInt() == value;
llvm::APInt actual;
return matchPattern(ofr.get<Value>(), m_ConstantInt(&actual)) &&
return matchPattern(cast<Value>(ofr), m_ConstantInt(&actual)) &&
actual.getSExtValue() == value;
};
if (!llvm::all_of(loopRanges, [&](Range range) {
Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ static void emitIsPositiveIndexAssertion(ImplicitLocOpBuilder &b,

Value zero = b.create<arith::ConstantIndexOp>(0);
Value condition = b.create<arith::CmpIOp>(arith::CmpIPredicate::sgt,
value.get<Value>(), zero);
cast<Value>(value), zero);
b.create<cf::AssertOp>(
condition,
b.getStringAttr("expected strictly positive tile size and divisor"));
Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ DecomposePadOpPattern::matchAndRewrite(tensor::PadOp padOp,
return val;
return rewriter
.create<arith::ConstantIndexOp>(
padOp.getLoc(), cast<IntegerAttr>(ofr.get<Attribute>()).getInt())
padOp.getLoc(), cast<IntegerAttr>(cast<Attribute>(ofr)).getInt())
.getResult();
};

Expand Down
Loading