Skip to content

Commit 2af97d5

Browse files
[LLVMIR] Migrate away from PointerUnion::{is,get} (NFC)
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 2c31262 commit 2af97d5

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

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

Lines changed: 9 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,11 @@ 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+
if (!isa<IntegerAttr>(indices[indexPos]))
825825
return emitOpError() << "expected index " << indexPos
826826
<< " indexing a struct to be constant";
827827

828-
int32_t gepIndex = indices[indexPos].get<IntegerAttr>().getInt();
828+
int32_t gepIndex = cast<IntegerAttr>(indices[indexPos]).getInt();
829829
ArrayRef<Type> elementTypes = structType.getBody();
830830
if (gepIndex < 0 ||
831831
static_cast<size_t>(gepIndex) >= elementTypes.size())
@@ -1100,11 +1100,11 @@ CallInterfaceCallable CallOp::getCallableForCallee() {
11001100
void CallOp::setCalleeFromCallable(CallInterfaceCallable callee) {
11011101
// Direct call.
11021102
if (FlatSymbolRefAttr calleeAttr = getCalleeAttr()) {
1103-
auto symRef = callee.get<SymbolRefAttr>();
1103+
auto symRef = cast<SymbolRefAttr>(callee);
11041104
return setCalleeAttr(cast<FlatSymbolRefAttr>(symRef));
11051105
}
11061106
// Indirect call, callee Value is the first operand.
1107-
return setOperand(0, callee.get<Value>());
1107+
return setOperand(0, cast<Value>(callee));
11081108
}
11091109

11101110
Operation::operand_range CallOp::getArgOperands() {
@@ -1564,11 +1564,11 @@ CallInterfaceCallable InvokeOp::getCallableForCallee() {
15641564
void InvokeOp::setCalleeFromCallable(CallInterfaceCallable callee) {
15651565
// Direct call.
15661566
if (FlatSymbolRefAttr calleeAttr = getCalleeAttr()) {
1567-
auto symRef = callee.get<SymbolRefAttr>();
1567+
auto symRef = cast<SymbolRefAttr>(callee);
15681568
return setCalleeAttr(cast<FlatSymbolRefAttr>(symRef));
15691569
}
15701570
// Indirect call, callee Value is the first operand.
1571-
return setOperand(0, callee.get<Value>());
1571+
return setOperand(0, cast<Value>(callee));
15721572
}
15731573

15741574
Operation::operand_range InvokeOp::getArgOperands() {
@@ -3259,7 +3259,7 @@ OpFoldResult LLVM::GEPOp::fold(FoldAdaptor adaptor) {
32593259
if (Value val = llvm::dyn_cast_if_present<Value>(existing))
32603260
gepArgs.emplace_back(val);
32613261
else
3262-
gepArgs.emplace_back(existing.get<IntegerAttr>().getInt());
3262+
gepArgs.emplace_back(cast<IntegerAttr>(existing).getInt());
32633263

32643264
continue;
32653265
}

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)