Skip to content

Commit cbbabc6

Browse files
[Dialect] Migrate away from PointerUnion::{is,get} (NFC) (#120679)
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 9ae92d7 commit cbbabc6

File tree

10 files changed

+34
-34
lines changed

10 files changed

+34
-34
lines changed

mlir/lib/Dialect/Arith/Utils/Utils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ mlir::inferExpandShapeOutputShape(OpBuilder &b, Location loc,
6666
int64_t inputIndex = it.index();
6767
// Call get<Value>() under the assumption that we're not casting
6868
// dynamism.
69-
Value indexGroupSize = inputShape[inputIndex].get<Value>();
69+
Value indexGroupSize = cast<Value>(inputShape[inputIndex]);
7070
Value indexGroupStaticSizesProduct =
7171
b.create<arith::ConstantIndexOp>(loc, indexGroupStaticSizesProductInt);
7272
Value dynamicDimSize = b.createOrFold<arith::DivUIOp>(

mlir/lib/Dialect/Bufferization/IR/BufferizableOpInterface.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ FailureOr<Value> bufferization::allocateTensorForShapedValue(
174174
resultDims[llvm::cast<OpResult>(shapedValue).getResultNumber()];
175175
for (const auto &dim : enumerate(tensorType.getShape()))
176176
if (ShapedType::isDynamic(dim.value()))
177-
dynamicSizes.push_back(shape[dim.index()].get<Value>());
177+
dynamicSizes.push_back(cast<Value>(shape[dim.index()]));
178178
}
179179
}
180180

mlir/lib/Dialect/DLTI/DLTI.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ combineOneSpec(DataLayoutSpecInterface spec,
312312
continue;
313313
}
314314

315-
Type typeSample = kvp.second.front().getKey().get<Type>();
315+
Type typeSample = cast<Type>(kvp.second.front().getKey());
316316
assert(&typeSample.getDialect() !=
317317
typeSample.getContext()->getLoadedDialect<BuiltinDialect>() &&
318318
"unexpected data layout entry for built-in type");
@@ -325,7 +325,7 @@ combineOneSpec(DataLayoutSpecInterface spec,
325325
}
326326

327327
for (const auto &kvp : newEntriesForID) {
328-
StringAttr id = kvp.second.getKey().get<StringAttr>();
328+
StringAttr id = cast<StringAttr>(kvp.second.getKey());
329329
Dialect *dialect = id.getReferencedDialect();
330330
if (!entriesForID.count(id)) {
331331
entriesForID[id] = kvp.second;
@@ -574,7 +574,7 @@ class TargetDataLayoutInterface : public DataLayoutDialectInterface {
574574

575575
LogicalResult verifyEntry(DataLayoutEntryInterface entry,
576576
Location loc) const final {
577-
StringRef entryName = entry.getKey().get<StringAttr>().strref();
577+
StringRef entryName = cast<StringAttr>(entry.getKey()).strref();
578578
if (entryName == DLTIDialect::kDataLayoutEndiannessKey) {
579579
auto value = dyn_cast<StringAttr>(entry.getValue());
580580
if (value &&

mlir/lib/Dialect/GPU/TransformOps/Utils.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,17 @@ static GpuIdBuilderFnType commonLinearIdBuilderFn(int64_t multiplicity = 1) {
113113
// clang-format on
114114

115115
// Return n-D ids for indexing and 1-D size + id for predicate generation.
116-
return IdBuilderResult{
117-
/*mappingIdOps=*/ids,
118-
/*availableMappingSizes=*/
119-
SmallVector<int64_t>{computeProduct(originalBasis)},
120-
// `forallMappingSizes` iterate in the scaled basis, they need to be
121-
// scaled back into the original basis to provide tight
122-
// activeMappingSizes quantities for predication.
123-
/*activeMappingSizes=*/
124-
SmallVector<int64_t>{computeProduct(forallMappingSizes) * multiplicity},
125-
/*activeIdOps=*/SmallVector<Value>{linearId.get<Value>()}};
116+
return IdBuilderResult{
117+
/*mappingIdOps=*/ids,
118+
/*availableMappingSizes=*/
119+
SmallVector<int64_t>{computeProduct(originalBasis)},
120+
// `forallMappingSizes` iterate in the scaled basis, they need to be
121+
// scaled back into the original basis to provide tight
122+
// activeMappingSizes quantities for predication.
123+
/*activeMappingSizes=*/
124+
SmallVector<int64_t>{computeProduct(forallMappingSizes) *
125+
multiplicity},
126+
/*activeIdOps=*/SmallVector<Value>{cast<Value>(linearId)}};
126127
};
127128

128129
return res;
@@ -144,9 +145,8 @@ static GpuIdBuilderFnType common3DIdBuilderFn(int64_t multiplicity = 1) {
144145
// In the 3-D mapping case, scale the first dimension by the multiplicity.
145146
SmallVector<Value> scaledIds = ids;
146147
AffineExpr d0 = getAffineDimExpr(0, rewriter.getContext());
147-
scaledIds[0] = affine::makeComposedFoldedAffineApply(
148-
rewriter, loc, d0.floorDiv(multiplicity), {scaledIds[0]})
149-
.get<Value>();
148+
scaledIds[0] = cast<Value>(affine::makeComposedFoldedAffineApply(
149+
rewriter, loc, d0.floorDiv(multiplicity), {scaledIds[0]}));
150150
// In the 3-D mapping case, unscale the first dimension by the multiplicity.
151151
SmallVector<int64_t> forallMappingSizeInOriginalBasis(forallMappingSizes);
152152
forallMappingSizeInOriginalBasis[0] *= multiplicity;

mlir/lib/Dialect/Mesh/Transforms/Transforms.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ TypedValue<IndexType> createProcessLinearIndex(StringRef mesh,
217217
OpFoldResult processInGroupLinearIndex = affine::linearizeIndex(
218218
llvm::to_vector_of<OpFoldResult>(processInGroupMultiIndex),
219219
llvm::to_vector_of<OpFoldResult>(processGroupShape), builder);
220-
return cast<TypedValue<IndexType>>(processInGroupLinearIndex.get<Value>());
220+
return cast<TypedValue<IndexType>>(cast<Value>(processInGroupLinearIndex));
221221
}
222222

223223
} // namespace mlir::mesh

mlir/lib/Dialect/Ptr/IR/PtrTypes.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static SpecAttr getPointerSpec(DataLayoutEntryListRef params, PtrType type) {
3333
for (DataLayoutEntryInterface entry : params) {
3434
if (!entry.isTypeEntry())
3535
continue;
36-
if (cast<PtrType>(entry.getKey().get<Type>()).getMemorySpace() ==
36+
if (cast<PtrType>(cast<Type>(entry.getKey())).getMemorySpace() ==
3737
type.getMemorySpace()) {
3838
if (auto spec = dyn_cast<SpecAttr>(entry.getValue()))
3939
return spec;
@@ -55,7 +55,7 @@ bool PtrType::areCompatible(DataLayoutEntryListRef oldLayout,
5555
continue;
5656
uint32_t size = kDefaultPointerSizeBits;
5757
uint32_t abi = kDefaultPointerAlignment;
58-
auto newType = llvm::cast<PtrType>(newEntry.getKey().get<Type>());
58+
auto newType = llvm::cast<PtrType>(llvm::cast<Type>(newEntry.getKey()));
5959
const auto *it =
6060
llvm::find_if(oldLayout, [&](DataLayoutEntryInterface entry) {
6161
if (auto type = llvm::dyn_cast_if_present<Type>(entry.getKey())) {
@@ -134,7 +134,7 @@ LogicalResult PtrType::verifyEntries(DataLayoutEntryListRef entries,
134134
for (DataLayoutEntryInterface entry : entries) {
135135
if (!entry.isTypeEntry())
136136
continue;
137-
auto key = entry.getKey().get<Type>();
137+
auto key = llvm::cast<Type>(entry.getKey());
138138
if (!llvm::isa<SpecAttr>(entry.getValue())) {
139139
return emitError(loc) << "expected layout attribute for " << key
140140
<< " to be a #ptr.spec attribute";

mlir/lib/Dialect/SPIRV/IR/ControlFlowOps.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ CallInterfaceCallable FunctionCallOp::getCallableForCallee() {
205205
}
206206

207207
void FunctionCallOp::setCalleeFromCallable(CallInterfaceCallable callee) {
208-
(*this)->setAttr(getCalleeAttrName(), callee.get<SymbolRefAttr>());
208+
(*this)->setAttr(getCalleeAttrName(), cast<SymbolRefAttr>(callee));
209209
}
210210

211211
Operation::operand_range FunctionCallOp::getArgOperands() {

mlir/lib/Dialect/SparseTensor/Transforms/Utils/LoopEmitter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static Value unFoldOpIntResult(OpBuilder &builder, Location loc,
8787
OpFoldResult ofr) {
8888
if (std::optional<int64_t> i = getConstantIntValue(ofr); i.has_value())
8989
return constantIndex(builder, loc, *i);
90-
return ofr.get<Value>();
90+
return cast<Value>(ofr);
9191
}
9292

9393
static Value tryFoldTensors(Value t) {

mlir/lib/Dialect/Transform/Interfaces/TransformInterfaces.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,19 +1475,19 @@ transform::detail::checkApplyToOne(Operation *transformOp,
14751475
if (ptr.isNull())
14761476
continue;
14771477
if (llvm::isa<TransformHandleTypeInterface>(res.getType()) &&
1478-
!ptr.is<Operation *>()) {
1478+
!isa<Operation *>(ptr)) {
14791479
return emitDiag() << "application of " << transformOpName
14801480
<< " expected to produce an Operation * for result #"
14811481
<< res.getResultNumber();
14821482
}
14831483
if (llvm::isa<TransformParamTypeInterface>(res.getType()) &&
1484-
!ptr.is<Attribute>()) {
1484+
!isa<Attribute>(ptr)) {
14851485
return emitDiag() << "application of " << transformOpName
14861486
<< " expected to produce an Attribute for result #"
14871487
<< res.getResultNumber();
14881488
}
14891489
if (llvm::isa<TransformValueHandleTypeInterface>(res.getType()) &&
1490-
!ptr.is<Value>()) {
1490+
!isa<Value>(ptr)) {
14911491
return emitDiag() << "application of " << transformOpName
14921492
<< " expected to produce a Value for result #"
14931493
<< res.getResultNumber();
@@ -1499,7 +1499,7 @@ transform::detail::checkApplyToOne(Operation *transformOp,
14991499
template <typename T>
15001500
static SmallVector<T> castVector(ArrayRef<transform::MappedValue> range) {
15011501
return llvm::to_vector(llvm::map_range(
1502-
range, [](transform::MappedValue value) { return value.get<T>(); }));
1502+
range, [](transform::MappedValue value) { return cast<T>(value); }));
15031503
}
15041504

15051505
void transform::detail::setApplyToOneResults(

mlir/lib/Dialect/Utils/StaticValueUtils.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void dispatchIndexOpFoldResult(OpFoldResult ofr,
5050
SmallVectorImpl<int64_t> &staticVec) {
5151
auto v = llvm::dyn_cast_if_present<Value>(ofr);
5252
if (!v) {
53-
APInt apInt = cast<IntegerAttr>(ofr.get<Attribute>()).getValue();
53+
APInt apInt = cast<IntegerAttr>(cast<Attribute>(ofr)).getValue();
5454
staticVec.push_back(apInt.getSExtValue());
5555
return;
5656
}
@@ -212,11 +212,11 @@ decomposeMixedValues(const SmallVectorImpl<OpFoldResult> &mixedValues) {
212212
SmallVector<int64_t> staticValues;
213213
SmallVector<Value> dynamicValues;
214214
for (const auto &it : mixedValues) {
215-
if (it.is<Attribute>()) {
216-
staticValues.push_back(cast<IntegerAttr>(it.get<Attribute>()).getInt());
215+
if (auto attr = dyn_cast<Attribute>(it)) {
216+
staticValues.push_back(cast<IntegerAttr>(attr).getInt());
217217
} else {
218218
staticValues.push_back(ShapedType::kDynamic);
219-
dynamicValues.push_back(it.get<Value>());
219+
dynamicValues.push_back(cast<Value>(it));
220220
}
221221
}
222222
return {staticValues, dynamicValues};
@@ -294,10 +294,10 @@ LogicalResult foldDynamicIndexList(SmallVectorImpl<OpFoldResult> &ofrs,
294294
bool onlyNonNegative, bool onlyNonZero) {
295295
bool valuesChanged = false;
296296
for (OpFoldResult &ofr : ofrs) {
297-
if (ofr.is<Attribute>())
297+
if (isa<Attribute>(ofr))
298298
continue;
299299
Attribute attr;
300-
if (matchPattern(ofr.get<Value>(), m_Constant(&attr))) {
300+
if (matchPattern(cast<Value>(ofr), m_Constant(&attr))) {
301301
// Note: All ofrs have index type.
302302
if (onlyNonNegative && *getConstantIntValue(attr) < 0)
303303
continue;

0 commit comments

Comments
 (0)