Skip to content

Commit 934aafa

Browse files
gitolegbcardosolopes
authored andcommitted
[CIR][Lowering][Bugfix] explicit lowering for the indirect call
1 parent 7f438ee commit 934aafa

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -873,12 +873,28 @@ class CIRCallLowering : public mlir::OpConversionPattern<mlir::cir::CallOp> {
873873
mlir::ConversionPatternRewriter &rewriter) const override {
874874
llvm::SmallVector<mlir::Type, 8> llvmResults;
875875
auto cirResults = op.getResultTypes();
876+
auto* converter = getTypeConverter();
876877

877-
if (getTypeConverter()->convertTypes(cirResults, llvmResults).failed())
878+
if (converter->convertTypes(cirResults, llvmResults).failed())
878879
return mlir::failure();
879880

880-
rewriter.replaceOpWithNewOp<mlir::LLVM::CallOp>(
881+
if (auto callee = op.getCalleeAttr()) { // direct call
882+
rewriter.replaceOpWithNewOp<mlir::LLVM::CallOp>(
881883
op, llvmResults, op.getCalleeAttr(), adaptor.getOperands());
884+
} else { // indirect call
885+
assert(op.getOperands().size()
886+
&& "operands list must no be empty for the indirect call");
887+
auto typ = op.getOperands().front().getType();
888+
assert(isa<mlir::cir::PointerType>(typ) && "expected pointer type");
889+
auto ptyp = dyn_cast<mlir::cir::PointerType>(typ);
890+
auto ftyp = dyn_cast<mlir::cir::FuncType>(ptyp.getPointee());
891+
assert(ftyp && "expected a pointer to a function as the first operand");
892+
893+
rewriter.replaceOpWithNewOp<mlir::LLVM::CallOp>(
894+
op,
895+
dyn_cast<mlir::LLVM::LLVMFunctionType>(converter->convertType(ftyp)),
896+
adaptor.getOperands());
897+
}
882898
return mlir::success();
883899
}
884900
};

0 commit comments

Comments
 (0)