Skip to content

Commit 9192367

Browse files
[Interfaces] Migrate away from PointerUnion::{is,get} (NFC) (#120845)
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 c9df8da commit 9192367

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

mlir/lib/Interfaces/CallInterfaces.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ call_interface_impl::resolveCallable(CallOpInterface call,
2222
return symbolVal.getDefiningOp();
2323

2424
// If the callable isn't a value, lookup the symbol reference.
25-
auto symbolRef = callable.get<SymbolRefAttr>();
25+
auto symbolRef = cast<SymbolRefAttr>(callable);
2626
if (symbolTable)
2727
return symbolTable->lookupNearestSymbolFrom(call.getOperation(), symbolRef);
2828
return SymbolTable::lookupNearestSymbolFrom(call.getOperation(), symbolRef);

mlir/lib/Interfaces/DataLayoutInterfaces.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ findEntryForIntegerType(IntegerType intType,
9595
std::map<unsigned, DataLayoutEntryInterface> sortedParams;
9696
for (DataLayoutEntryInterface entry : params) {
9797
sortedParams.insert(std::make_pair(
98-
entry.getKey().get<Type>().getIntOrFloatBitWidth(), entry));
98+
cast<Type>(entry.getKey()).getIntOrFloatBitWidth(), entry));
9999
}
100100
auto iter = sortedParams.lower_bound(intType.getWidth());
101101
if (iter == sortedParams.end())
@@ -315,9 +315,9 @@ DataLayoutEntryInterface
315315
mlir::detail::filterEntryForIdentifier(DataLayoutEntryListRef entries,
316316
StringAttr id) {
317317
const auto *it = llvm::find_if(entries, [id](DataLayoutEntryInterface entry) {
318-
if (!entry.getKey().is<StringAttr>())
319-
return false;
320-
return entry.getKey().get<StringAttr>() == id;
318+
if (auto attr = dyn_cast<StringAttr>(entry.getKey()))
319+
return attr == id;
320+
return false;
321321
});
322322
return it == entries.end() ? DataLayoutEntryInterface() : *it;
323323
}
@@ -691,7 +691,7 @@ void DataLayoutSpecInterface::bucketEntriesByType(
691691
if (auto type = llvm::dyn_cast_if_present<Type>(entry.getKey()))
692692
types[type.getTypeID()].push_back(entry);
693693
else
694-
ids[entry.getKey().get<StringAttr>()] = entry;
694+
ids[llvm::cast<StringAttr>(entry.getKey())] = entry;
695695
}
696696
}
697697

@@ -709,7 +709,7 @@ LogicalResult mlir::detail::verifyDataLayoutSpec(DataLayoutSpecInterface spec,
709709
spec.bucketEntriesByType(types, ids);
710710

711711
for (const auto &kvp : types) {
712-
auto sampleType = kvp.second.front().getKey().get<Type>();
712+
auto sampleType = cast<Type>(kvp.second.front().getKey());
713713
if (isa<IndexType>(sampleType)) {
714714
assert(kvp.second.size() == 1 &&
715715
"expected one data layout entry for non-parametric 'index' type");
@@ -763,7 +763,7 @@ LogicalResult mlir::detail::verifyDataLayoutSpec(DataLayoutSpecInterface spec,
763763
}
764764

765765
for (const auto &kvp : ids) {
766-
StringAttr identifier = kvp.second.getKey().get<StringAttr>();
766+
StringAttr identifier = cast<StringAttr>(kvp.second.getKey());
767767
Dialect *dialect = identifier.getReferencedDialect();
768768

769769
// Ignore attributes that belong to an unknown dialect, the dialect may
@@ -816,7 +816,7 @@ mlir::detail::verifyTargetSystemSpec(TargetSystemSpecInterface spec,
816816
// targetDeviceSpec does not support Type as a key.
817817
return failure();
818818
} else {
819-
deviceDescKeys[entry.getKey().get<StringAttr>()] = entry;
819+
deviceDescKeys[cast<StringAttr>(entry.getKey())] = entry;
820820
}
821821
}
822822
}

mlir/lib/Interfaces/InferTypeOpInterface.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ mlir::reifyResultShapes(OpBuilder &b, Operation *op,
5353
// * Attribute for static dimensions
5454
// * Value for dynamic dimensions
5555
assert(shapedType.isDynamicDim(dim) ==
56-
reifiedReturnShapes[resultIdx][dim].is<Value>() &&
56+
isa<Value>(reifiedReturnShapes[resultIdx][dim]) &&
5757
"incorrect implementation of ReifyRankedShapedTypeOpInterface");
5858
}
5959
++resultIdx;
@@ -70,19 +70,19 @@ bool ShapeAdaptor::hasRank() const {
7070
return false;
7171
if (auto t = llvm::dyn_cast_if_present<Type>(val))
7272
return cast<ShapedType>(t).hasRank();
73-
if (val.is<Attribute>())
73+
if (isa<Attribute>(val))
7474
return true;
75-
return val.get<ShapedTypeComponents *>()->hasRank();
75+
return cast<ShapedTypeComponents *>(val)->hasRank();
7676
}
7777

7878
Type ShapeAdaptor::getElementType() const {
7979
if (val.isNull())
8080
return nullptr;
8181
if (auto t = llvm::dyn_cast_if_present<Type>(val))
8282
return cast<ShapedType>(t).getElementType();
83-
if (val.is<Attribute>())
83+
if (isa<Attribute>(val))
8484
return nullptr;
85-
return val.get<ShapedTypeComponents *>()->getElementType();
85+
return cast<ShapedTypeComponents *>(val)->getElementType();
8686
}
8787

8888
void ShapeAdaptor::getDims(SmallVectorImpl<int64_t> &res) const {
@@ -97,7 +97,7 @@ void ShapeAdaptor::getDims(SmallVectorImpl<int64_t> &res) const {
9797
for (auto it : dattr.getValues<APInt>())
9898
res.push_back(it.getSExtValue());
9999
} else {
100-
auto vals = val.get<ShapedTypeComponents *>()->getDims();
100+
auto vals = cast<ShapedTypeComponents *>(val)->getDims();
101101
res.assign(vals.begin(), vals.end());
102102
}
103103
}
@@ -116,7 +116,7 @@ int64_t ShapeAdaptor::getDimSize(int index) const {
116116
return cast<DenseIntElementsAttr>(attr)
117117
.getValues<APInt>()[index]
118118
.getSExtValue();
119-
auto *stc = val.get<ShapedTypeComponents *>();
119+
auto *stc = cast<ShapedTypeComponents *>(val);
120120
return stc->getDims()[index];
121121
}
122122

@@ -126,7 +126,7 @@ int64_t ShapeAdaptor::getRank() const {
126126
return cast<ShapedType>(t).getRank();
127127
if (auto attr = llvm::dyn_cast_if_present<Attribute>(val))
128128
return cast<DenseIntElementsAttr>(attr).size();
129-
return val.get<ShapedTypeComponents *>()->getDims().size();
129+
return cast<ShapedTypeComponents *>(val)->getDims().size();
130130
}
131131

132132
bool ShapeAdaptor::hasStaticShape() const {
@@ -142,7 +142,7 @@ bool ShapeAdaptor::hasStaticShape() const {
142142
return false;
143143
return true;
144144
}
145-
auto *stc = val.get<ShapedTypeComponents *>();
145+
auto *stc = cast<ShapedTypeComponents *>(val);
146146
return llvm::none_of(stc->getDims(), ShapedType::isDynamic);
147147
}
148148

@@ -162,7 +162,7 @@ int64_t ShapeAdaptor::getNumElements() const {
162162
return num;
163163
}
164164

165-
auto *stc = val.get<ShapedTypeComponents *>();
165+
auto *stc = cast<ShapedTypeComponents *>(val);
166166
int64_t num = 1;
167167
for (int64_t dim : stc->getDims()) {
168168
num *= dim;

0 commit comments

Comments
 (0)