Skip to content

Commit 2e95edb

Browse files
committed
Address review feedback
1 parent 88039a4 commit 2e95edb

File tree

2 files changed

+17
-20
lines changed

2 files changed

+17
-20
lines changed

clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -927,24 +927,23 @@ rewriteCallOrInvoke(mlir::Operation *op, mlir::ValueRange callOperands,
927927
if (calleeAttr) { // direct call
928928
mlir::Operation *callee =
929929
mlir::SymbolTable::lookupNearestSymbolFrom(op, calleeAttr);
930-
if (auto fn = dyn_cast<mlir::FunctionOpInterface>(callee)) {
931-
llvmFnTy = cast<mlir::LLVM::LLVMFunctionType>(
932-
converter->convertType(fn.getFunctionType()));
933-
} else if (auto alias = cast<mlir::LLVM::AliasOp>(callee)) {
930+
if (auto fn = mlir::dyn_cast<mlir::FunctionOpInterface>(callee)) {
931+
llvmFnTy = converter->convertType<mlir::LLVM::LLVMFunctionType>(
932+
fn.getFunctionType());
933+
assert(llvmFnTy && "Failed to convert function type");
934+
} else if (auto alias = mlir::cast<mlir::LLVM::AliasOp>(callee)) {
934935
// If the callee wasan alias. In that case,
935936
// we need to prepend the address of the alias to the operands. The
936937
// way aliases work in the LLVM dialect is a little counter-intuitive.
937938
// The AliasOp itself is a pseudo-function that returns the address of
938939
// the global value being aliased, but when we generate the call we
939940
// need to insert an operation that gets the address of the AliasOp.
940941
// This all gets sorted out when the LLVM dialect is lowered to LLVM IR.
941-
auto symAttr = cast<mlir::FlatSymbolRefAttr>(calleeAttr);
942+
auto symAttr = mlir::cast<mlir::FlatSymbolRefAttr>(calleeAttr);
942943
auto addrOfAlias =
943-
rewriter
944-
.create<mlir::LLVM::AddressOfOp>(
945-
op->getLoc(),
946-
mlir::LLVM::LLVMPointerType::get(rewriter.getContext()),
947-
symAttr)
944+
mlir::LLVM::AddressOfOp::create(
945+
rewriter, op->getLoc(),
946+
mlir::LLVM::LLVMPointerType::get(rewriter.getContext()), symAttr)
948947
.getResult();
949948
adjustedCallOperands.push_back(addrOfAlias);
950949

@@ -954,7 +953,7 @@ rewriteCallOrInvoke(mlir::Operation *op, mlir::ValueRange callOperands,
954953

955954
// Clear the callee attribute because we're calling an alias.
956955
calleeAttr = {};
957-
llvmFnTy = cast<mlir::LLVM::LLVMFunctionType>(alias.getType());
956+
llvmFnTy = mlir::cast<mlir::LLVM::LLVMFunctionType>(alias.getType());
958957
} else {
959958
// Was this an ifunc?
960959
return op->emitError("Unexpected callee type!");
@@ -1200,8 +1199,8 @@ void CIRToLLVMFuncOpLowering::lowerFuncAttributes(
12001199
}
12011200

12021201
mlir::LogicalResult CIRToLLVMFuncOpLowering::matchAndRewriteAlias(
1203-
cir::FuncOp op, mlir::FlatSymbolRefAttr aliasee, mlir::Type ty,
1204-
OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const {
1202+
cir::FuncOp op, llvm::StringRef aliasee, mlir::Type ty, OpAdaptor adaptor,
1203+
mlir::ConversionPatternRewriter &rewriter) const {
12051204
SmallVector<mlir::NamedAttribute, 4> attributes;
12061205
lowerFuncAttributes(op, /*filterArgAndResAttrs=*/false, attributes);
12071206

@@ -1217,9 +1216,8 @@ mlir::LogicalResult CIRToLLVMFuncOpLowering::matchAndRewriteAlias(
12171216
// The type of AddressOfOp is always a pointer.
12181217
assert(!cir::MissingFeatures::addressSpace());
12191218
mlir::Type ptrTy = mlir::LLVM::LLVMPointerType::get(ty.getContext());
1220-
auto addrOp =
1221-
builder.create<mlir::LLVM::AddressOfOp>(loc, ptrTy, aliasee.getValue());
1222-
builder.create<mlir::LLVM::ReturnOp>(loc, addrOp);
1219+
auto addrOp = mlir::LLVM::AddressOfOp::create(builder, loc, ptrTy, aliasee);
1220+
mlir::LLVM::ReturnOp::create(builder, loc, addrOp);
12231221

12241222
return mlir::success();
12251223
}
@@ -1250,8 +1248,7 @@ mlir::LogicalResult CIRToLLVMFuncOpLowering::matchAndRewrite(
12501248
/*isVarArg=*/fnType.isVarArg());
12511249

12521250
// If this is an alias, it needs to be lowered to llvm::AliasOp.
1253-
std::optional<mlir::FlatSymbolRefAttr> aliasee = op.getAliaseeAttr();
1254-
if (aliasee && *aliasee)
1251+
if (std::optional<llvm::StringRef> aliasee = op.getAliasee())
12551252
return matchAndRewriteAlias(op, *aliasee, llvmFnTy, adaptor, rewriter);
12561253

12571254
// LLVMFuncOp expects a single FileLine Location instead of a fused

clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,8 @@ class CIRToLLVMFuncOpLowering : public mlir::OpConversionPattern<cir::FuncOp> {
258258
mlir::SmallVectorImpl<mlir::NamedAttribute> &result) const;
259259

260260
mlir::LogicalResult
261-
matchAndRewriteAlias(cir::FuncOp op, mlir::FlatSymbolRefAttr aliasee,
262-
mlir::Type ty, OpAdaptor adaptor,
261+
matchAndRewriteAlias(cir::FuncOp op, llvm::StringRef aliasee, mlir::Type ty,
262+
OpAdaptor adaptor,
263263
mlir::ConversionPatternRewriter &rewriter) const;
264264

265265
public:

0 commit comments

Comments
 (0)