[Mlir-commits] [mlir] [LLVMIR] Migrate away from PointerUnion::{is, get} (NFC) (PR #120530)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Dec 19 00:09:52 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: Kazu Hirata (kazutakahirata)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/120530.diff
2 Files Affected:
- (modified) mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp (+9-9)
- (modified) mlir/lib/Dialect/LLVMIR/IR/LLVMTypes.cpp (+7-5)
``````````diff
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))
``````````
</details>
https://github.com/llvm/llvm-project/pull/120530
More information about the Mlir-commits
mailing list