Skip to content

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

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
2 changes: 1 addition & 1 deletion mlir/lib/Interfaces/CallInterfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ call_interface_impl::resolveCallable(CallOpInterface call,
return symbolVal.getDefiningOp();

// If the callable isn't a value, lookup the symbol reference.
auto symbolRef = callable.get<SymbolRefAttr>();
auto symbolRef = cast<SymbolRefAttr>(callable);
if (symbolTable)
return symbolTable->lookupNearestSymbolFrom(call.getOperation(), symbolRef);
return SymbolTable::lookupNearestSymbolFrom(call.getOperation(), symbolRef);
Expand Down
16 changes: 8 additions & 8 deletions mlir/lib/Interfaces/DataLayoutInterfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ findEntryForIntegerType(IntegerType intType,
std::map<unsigned, DataLayoutEntryInterface> sortedParams;
for (DataLayoutEntryInterface entry : params) {
sortedParams.insert(std::make_pair(
entry.getKey().get<Type>().getIntOrFloatBitWidth(), entry));
cast<Type>(entry.getKey()).getIntOrFloatBitWidth(), entry));
}
auto iter = sortedParams.lower_bound(intType.getWidth());
if (iter == sortedParams.end())
Expand Down Expand Up @@ -315,9 +315,9 @@ DataLayoutEntryInterface
mlir::detail::filterEntryForIdentifier(DataLayoutEntryListRef entries,
StringAttr id) {
const auto *it = llvm::find_if(entries, [id](DataLayoutEntryInterface entry) {
if (!entry.getKey().is<StringAttr>())
return false;
return entry.getKey().get<StringAttr>() == id;
if (auto attr = dyn_cast<StringAttr>(entry.getKey()))
return attr == id;
return false;
});
return it == entries.end() ? DataLayoutEntryInterface() : *it;
}
Expand Down Expand Up @@ -691,7 +691,7 @@ void DataLayoutSpecInterface::bucketEntriesByType(
if (auto type = llvm::dyn_cast_if_present<Type>(entry.getKey()))
types[type.getTypeID()].push_back(entry);
else
ids[entry.getKey().get<StringAttr>()] = entry;
ids[llvm::cast<StringAttr>(entry.getKey())] = entry;
}
}

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

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

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

// Ignore attributes that belong to an unknown dialect, the dialect may
Expand Down Expand Up @@ -816,7 +816,7 @@ mlir::detail::verifyTargetSystemSpec(TargetSystemSpecInterface spec,
// targetDeviceSpec does not support Type as a key.
return failure();
} else {
deviceDescKeys[entry.getKey().get<StringAttr>()] = entry;
deviceDescKeys[cast<StringAttr>(entry.getKey())] = entry;
}
}
}
Expand Down
20 changes: 10 additions & 10 deletions mlir/lib/Interfaces/InferTypeOpInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ mlir::reifyResultShapes(OpBuilder &b, Operation *op,
// * Attribute for static dimensions
// * Value for dynamic dimensions
assert(shapedType.isDynamicDim(dim) ==
reifiedReturnShapes[resultIdx][dim].is<Value>() &&
isa<Value>(reifiedReturnShapes[resultIdx][dim]) &&
"incorrect implementation of ReifyRankedShapedTypeOpInterface");
}
++resultIdx;
Expand All @@ -70,19 +70,19 @@ bool ShapeAdaptor::hasRank() const {
return false;
if (auto t = llvm::dyn_cast_if_present<Type>(val))
return cast<ShapedType>(t).hasRank();
if (val.is<Attribute>())
if (isa<Attribute>(val))
return true;
return val.get<ShapedTypeComponents *>()->hasRank();
return cast<ShapedTypeComponents *>(val)->hasRank();
}

Type ShapeAdaptor::getElementType() const {
if (val.isNull())
return nullptr;
if (auto t = llvm::dyn_cast_if_present<Type>(val))
return cast<ShapedType>(t).getElementType();
if (val.is<Attribute>())
if (isa<Attribute>(val))
return nullptr;
return val.get<ShapedTypeComponents *>()->getElementType();
return cast<ShapedTypeComponents *>(val)->getElementType();
}

void ShapeAdaptor::getDims(SmallVectorImpl<int64_t> &res) const {
Expand All @@ -97,7 +97,7 @@ void ShapeAdaptor::getDims(SmallVectorImpl<int64_t> &res) const {
for (auto it : dattr.getValues<APInt>())
res.push_back(it.getSExtValue());
} else {
auto vals = val.get<ShapedTypeComponents *>()->getDims();
auto vals = cast<ShapedTypeComponents *>(val)->getDims();
res.assign(vals.begin(), vals.end());
}
}
Expand All @@ -116,7 +116,7 @@ int64_t ShapeAdaptor::getDimSize(int index) const {
return cast<DenseIntElementsAttr>(attr)
.getValues<APInt>()[index]
.getSExtValue();
auto *stc = val.get<ShapedTypeComponents *>();
auto *stc = cast<ShapedTypeComponents *>(val);
return stc->getDims()[index];
}

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

bool ShapeAdaptor::hasStaticShape() const {
Expand All @@ -142,7 +142,7 @@ bool ShapeAdaptor::hasStaticShape() const {
return false;
return true;
}
auto *stc = val.get<ShapedTypeComponents *>();
auto *stc = cast<ShapedTypeComponents *>(val);
return llvm::none_of(stc->getDims(), ShapedType::isDynamic);
}

Expand All @@ -162,7 +162,7 @@ int64_t ShapeAdaptor::getNumElements() const {
return num;
}

auto *stc = val.get<ShapedTypeComponents *>();
auto *stc = cast<ShapedTypeComponents *>(val);
int64_t num = 1;
for (int64_t dim : stc->getDims()) {
num *= dim;
Expand Down
Loading