-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[LLVMIR] Migrate away from PointerUnion::{is,get} (NFC) #120530
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
[LLVMIR] Migrate away from PointerUnion::{is,get} (NFC) #120530
Conversation
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.
|
@llvm/pr-subscribers-mlir-llvm @llvm/pr-subscribers-mlir Author: Kazu Hirata (kazutakahirata) ChangesNote that PointerUnion::{is,get} have been soft deprecated in // FIXME: Replace the uses of is(), get() and dyn_cast() with I'm not touching PointerUnion::dyn_cast for now because it's a bit Full diff: https://github.com/llvm/llvm-project/pull/120530.diff 2 Files Affected:
diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
index d30a6b8398f064..bc5c698e0e5a9c 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
@@ -716,7 +716,7 @@ static void destructureIndices(Type currType, ArrayRef<GEPArg> indices,
dynamicIndices.push_back(val);
}
} else {
- rawConstantIndices.push_back(iter.get<GEPConstantIndex>());
+ rawConstantIndices.push_back(cast<GEPConstantIndex>(iter));
}
// Skip for very first iteration of this loop. First index does not index
@@ -805,7 +805,7 @@ static void printGEPIndices(OpAsmPrinter &printer, LLVM::GEPOp gepOp,
if (Value val = llvm::dyn_cast_if_present<Value>(cst))
printer.printOperand(val);
else
- printer << cst.get<IntegerAttr>().getInt();
+ printer << cast<IntegerAttr>(cst).getInt();
});
}
@@ -821,11 +821,11 @@ verifyStructIndices(Type baseGEPType, unsigned indexPos,
return TypeSwitch<Type, LogicalResult>(baseGEPType)
.Case<LLVMStructType>([&](LLVMStructType structType) -> LogicalResult {
- if (!indices[indexPos].is<IntegerAttr>())
+ if (!isa<IntegerAttr>(indices[indexPos]))
return emitOpError() << "expected index " << indexPos
<< " indexing a struct to be constant";
- int32_t gepIndex = indices[indexPos].get<IntegerAttr>().getInt();
+ int32_t gepIndex = cast<IntegerAttr>(indices[indexPos]).getInt();
ArrayRef<Type> elementTypes = structType.getBody();
if (gepIndex < 0 ||
static_cast<size_t>(gepIndex) >= elementTypes.size())
@@ -1100,11 +1100,11 @@ CallInterfaceCallable CallOp::getCallableForCallee() {
void CallOp::setCalleeFromCallable(CallInterfaceCallable callee) {
// Direct call.
if (FlatSymbolRefAttr calleeAttr = getCalleeAttr()) {
- auto symRef = callee.get<SymbolRefAttr>();
+ auto symRef = cast<SymbolRefAttr>(callee);
return setCalleeAttr(cast<FlatSymbolRefAttr>(symRef));
}
// Indirect call, callee Value is the first operand.
- return setOperand(0, callee.get<Value>());
+ return setOperand(0, cast<Value>(callee));
}
Operation::operand_range CallOp::getArgOperands() {
@@ -1564,11 +1564,11 @@ CallInterfaceCallable InvokeOp::getCallableForCallee() {
void InvokeOp::setCalleeFromCallable(CallInterfaceCallable callee) {
// Direct call.
if (FlatSymbolRefAttr calleeAttr = getCalleeAttr()) {
- auto symRef = callee.get<SymbolRefAttr>();
+ auto symRef = cast<SymbolRefAttr>(callee);
return setCalleeAttr(cast<FlatSymbolRefAttr>(symRef));
}
// Indirect call, callee Value is the first operand.
- return setOperand(0, callee.get<Value>());
+ return setOperand(0, cast<Value>(callee));
}
Operation::operand_range InvokeOp::getArgOperands() {
@@ -3259,7 +3259,7 @@ OpFoldResult LLVM::GEPOp::fold(FoldAdaptor adaptor) {
if (Value val = llvm::dyn_cast_if_present<Value>(existing))
gepArgs.emplace_back(val);
else
- gepArgs.emplace_back(existing.get<IntegerAttr>().getInt());
+ gepArgs.emplace_back(cast<IntegerAttr>(existing).getInt());
continue;
}
diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMTypes.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMTypes.cpp
index 4e5600c715915c..453b206de294e4 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMTypes.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMTypes.cpp
@@ -280,7 +280,7 @@ getPointerDataLayoutEntry(DataLayoutEntryListRef params, LLVMPointerType type,
for (DataLayoutEntryInterface entry : params) {
if (!entry.isTypeEntry())
continue;
- if (cast<LLVMPointerType>(entry.getKey().get<Type>()).getAddressSpace() ==
+ if (cast<LLVMPointerType>(cast<Type>(entry.getKey())).getAddressSpace() ==
type.getAddressSpace()) {
currentEntry = entry.getValue();
break;
@@ -356,7 +356,8 @@ bool LLVMPointerType::areCompatible(DataLayoutEntryListRef oldLayout,
continue;
uint64_t size = kDefaultPointerSizeBits;
uint64_t abi = kDefaultPointerAlignment;
- auto newType = llvm::cast<LLVMPointerType>(newEntry.getKey().get<Type>());
+ auto newType =
+ llvm::cast<LLVMPointerType>(llvm::cast<Type>(newEntry.getKey()));
const auto *it =
llvm::find_if(oldLayout, [&](DataLayoutEntryInterface entry) {
if (auto type = llvm::dyn_cast_if_present<Type>(entry.getKey())) {
@@ -392,7 +393,7 @@ LogicalResult LLVMPointerType::verifyEntries(DataLayoutEntryListRef entries,
for (DataLayoutEntryInterface entry : entries) {
if (!entry.isTypeEntry())
continue;
- auto key = entry.getKey().get<Type>();
+ auto key = llvm::cast<Type>(entry.getKey());
auto values = llvm::dyn_cast<DenseIntElementsAttr>(entry.getValue());
if (!values || (values.size() != 3 && values.size() != 4)) {
return emitError(loc)
@@ -625,11 +626,12 @@ LogicalResult LLVMStructType::verifyEntries(DataLayoutEntryListRef entries,
if (!entry.isTypeEntry())
continue;
- auto key = llvm::cast<LLVMStructType>(entry.getKey().get<Type>());
+ auto key = llvm::cast<LLVMStructType>(llvm::cast<Type>(entry.getKey()));
auto values = llvm::dyn_cast<DenseIntElementsAttr>(entry.getValue());
if (!values || (values.size() != 2 && values.size() != 1)) {
return emitError(loc)
- << "expected layout attribute for " << entry.getKey().get<Type>()
+ << "expected layout attribute for "
+ << llvm::cast<Type>(entry.getKey())
<< " to be a dense integer elements attribute of 1 or 2 elements";
}
if (!values.getElementType().isInteger(64))
|
| if (!entry.isTypeEntry()) | ||
| continue; | ||
| if (cast<LLVMPointerType>(entry.getKey().get<Type>()).getAddressSpace() == | ||
| if (cast<LLVMPointerType>(cast<Type>(entry.getKey())).getAddressSpace() == |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pre-existing issue, but the mix of llvm::cast and unqualified cast in this file is weird...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. If I drop llvm::, the host compiler tries (but fails) to bind to:
template <typename U>
U Type::cast() const {
return llvm::cast<U>(*this);
}
in mlir/include/mlir/IR/Types.h.
Perhaps, we should get rid of Type::cast and its friends, and solely rely on:
using llvm::cast;
mlir/include/mlir/Support/LLVM.h.
I'm happy to address this in a subsequent patch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's already marked as deprecated, so maybe it's time to drop it...
Note that PointerUnion::{is,get} have been soft deprecated in
PointerUnion.h:
// FIXME: Replace the uses of is(), get() and dyn_cast() with
// isa, cast and the llvm::dyn_cast
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.