Skip to content

Commit e504ece

Browse files
[LLVMIR] Migrate away from PointerUnion::{is,get} (NFC) (llvm#120530)
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 a03343d commit e504ece

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ static void destructureIndices(Type currType, ArrayRef<GEPArg> indices,
716716
dynamicIndices.push_back(val);
717717
}
718718
} else {
719-
rawConstantIndices.push_back(iter.get<GEPConstantIndex>());
719+
rawConstantIndices.push_back(cast<GEPConstantIndex>(iter));
720720
}
721721

722722
// 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,
805805
if (Value val = llvm::dyn_cast_if_present<Value>(cst))
806806
printer.printOperand(val);
807807
else
808-
printer << cst.get<IntegerAttr>().getInt();
808+
printer << cast<IntegerAttr>(cst).getInt();
809809
});
810810
}
811811

@@ -821,11 +821,12 @@ verifyStructIndices(Type baseGEPType, unsigned indexPos,
821821

822822
return TypeSwitch<Type, LogicalResult>(baseGEPType)
823823
.Case<LLVMStructType>([&](LLVMStructType structType) -> LogicalResult {
824-
if (!indices[indexPos].is<IntegerAttr>())
824+
auto attr = dyn_cast<IntegerAttr>(indices[indexPos]);
825+
if (!attr)
825826
return emitOpError() << "expected index " << indexPos
826827
<< " indexing a struct to be constant";
827828

828-
int32_t gepIndex = indices[indexPos].get<IntegerAttr>().getInt();
829+
int32_t gepIndex = attr.getInt();
829830
ArrayRef<Type> elementTypes = structType.getBody();
830831
if (gepIndex < 0 ||
831832
static_cast<size_t>(gepIndex) >= elementTypes.size())
@@ -1100,11 +1101,11 @@ CallInterfaceCallable CallOp::getCallableForCallee() {
11001101
void CallOp::setCalleeFromCallable(CallInterfaceCallable callee) {
11011102
// Direct call.
11021103
if (FlatSymbolRefAttr calleeAttr = getCalleeAttr()) {
1103-
auto symRef = callee.get<SymbolRefAttr>();
1104+
auto symRef = cast<SymbolRefAttr>(callee);
11041105
return setCalleeAttr(cast<FlatSymbolRefAttr>(symRef));
11051106
}
11061107
// Indirect call, callee Value is the first operand.
1107-
return setOperand(0, callee.get<Value>());
1108+
return setOperand(0, cast<Value>(callee));
11081109
}
11091110

11101111
Operation::operand_range CallOp::getArgOperands() {
@@ -1564,11 +1565,11 @@ CallInterfaceCallable InvokeOp::getCallableForCallee() {
15641565
void InvokeOp::setCalleeFromCallable(CallInterfaceCallable callee) {
15651566
// Direct call.
15661567
if (FlatSymbolRefAttr calleeAttr = getCalleeAttr()) {
1567-
auto symRef = callee.get<SymbolRefAttr>();
1568+
auto symRef = cast<SymbolRefAttr>(callee);
15681569
return setCalleeAttr(cast<FlatSymbolRefAttr>(symRef));
15691570
}
15701571
// Indirect call, callee Value is the first operand.
1571-
return setOperand(0, callee.get<Value>());
1572+
return setOperand(0, cast<Value>(callee));
15721573
}
15731574

15741575
Operation::operand_range InvokeOp::getArgOperands() {
@@ -3259,7 +3260,7 @@ OpFoldResult LLVM::GEPOp::fold(FoldAdaptor adaptor) {
32593260
if (Value val = llvm::dyn_cast_if_present<Value>(existing))
32603261
gepArgs.emplace_back(val);
32613262
else
3262-
gepArgs.emplace_back(existing.get<IntegerAttr>().getInt());
3263+
gepArgs.emplace_back(cast<IntegerAttr>(existing).getInt());
32633264

32643265
continue;
32653266
}

mlir/lib/Dialect/LLVMIR/IR/LLVMTypes.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ getPointerDataLayoutEntry(DataLayoutEntryListRef params, LLVMPointerType type,
280280
for (DataLayoutEntryInterface entry : params) {
281281
if (!entry.isTypeEntry())
282282
continue;
283-
if (cast<LLVMPointerType>(entry.getKey().get<Type>()).getAddressSpace() ==
283+
if (cast<LLVMPointerType>(cast<Type>(entry.getKey())).getAddressSpace() ==
284284
type.getAddressSpace()) {
285285
currentEntry = entry.getValue();
286286
break;
@@ -356,7 +356,8 @@ bool LLVMPointerType::areCompatible(DataLayoutEntryListRef oldLayout,
356356
continue;
357357
uint64_t size = kDefaultPointerSizeBits;
358358
uint64_t abi = kDefaultPointerAlignment;
359-
auto newType = llvm::cast<LLVMPointerType>(newEntry.getKey().get<Type>());
359+
auto newType =
360+
llvm::cast<LLVMPointerType>(llvm::cast<Type>(newEntry.getKey()));
360361
const auto *it =
361362
llvm::find_if(oldLayout, [&](DataLayoutEntryInterface entry) {
362363
if (auto type = llvm::dyn_cast_if_present<Type>(entry.getKey())) {
@@ -392,7 +393,7 @@ LogicalResult LLVMPointerType::verifyEntries(DataLayoutEntryListRef entries,
392393
for (DataLayoutEntryInterface entry : entries) {
393394
if (!entry.isTypeEntry())
394395
continue;
395-
auto key = entry.getKey().get<Type>();
396+
auto key = llvm::cast<Type>(entry.getKey());
396397
auto values = llvm::dyn_cast<DenseIntElementsAttr>(entry.getValue());
397398
if (!values || (values.size() != 3 && values.size() != 4)) {
398399
return emitError(loc)
@@ -625,11 +626,12 @@ LogicalResult LLVMStructType::verifyEntries(DataLayoutEntryListRef entries,
625626
if (!entry.isTypeEntry())
626627
continue;
627628

628-
auto key = llvm::cast<LLVMStructType>(entry.getKey().get<Type>());
629+
auto key = llvm::cast<LLVMStructType>(llvm::cast<Type>(entry.getKey()));
629630
auto values = llvm::dyn_cast<DenseIntElementsAttr>(entry.getValue());
630631
if (!values || (values.size() != 2 && values.size() != 1)) {
631632
return emitError(loc)
632-
<< "expected layout attribute for " << entry.getKey().get<Type>()
633+
<< "expected layout attribute for "
634+
<< llvm::cast<Type>(entry.getKey())
633635
<< " to be a dense integer elements attribute of 1 or 2 elements";
634636
}
635637
if (!values.getElementType().isInteger(64))

0 commit comments

Comments
 (0)