Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 9 additions & 9 deletions mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
});
}

Expand All @@ -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())
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
}
Expand Down
12 changes: 7 additions & 5 deletions mlir/lib/Dialect/LLVMIR/IR/LLVMTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() ==
Copy link
Contributor

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...

Copy link
Contributor Author

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.

Copy link
Contributor

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...

type.getAddressSpace()) {
currentEntry = entry.getValue();
break;
Expand Down Expand Up @@ -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())) {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Expand Down
Loading