Skip to content

Commit 30d9fa3

Browse files
AmrDeveloperdvbuka
authored andcommitted
[CIR] Upstream CallOp with ComplexType as return type (llvm#164980)
Upstream support calling function that returns ComplexType Issue llvm#141365
1 parent 3aa2268 commit 30d9fa3

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

clang/lib/CIR/CodeGen/CIRGenCall.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -671,9 +671,12 @@ RValue CIRGenFunction::emitCall(const CIRGenFunctionInfo &funcInfo,
671671

672672
return RValue::get(results[0]);
673673
}
674-
case cir::TEK_Complex:
675-
cgm.errorNYI(loc, "unsupported evaluation kind of function call result");
676-
return getUndefRValue(retTy);
674+
case cir::TEK_Complex: {
675+
mlir::ResultRange results = theCall->getOpResults();
676+
assert(!results.empty() &&
677+
"Expected at least one result for complex rvalue");
678+
return RValue::getComplex(results[0]);
679+
}
677680
}
678681
llvm_unreachable("Invalid evaluation kind");
679682
}

clang/test/CIR/CodeGen/complex.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,3 +1468,30 @@ void calling_function_with_default_arg() {
14681468
// OGCG: store float 0x40019999A0000000, ptr %[[DEFAULT_ARG_IMAG_PTR]], align 4
14691469
// OGCG: %[[TMP_DEFAULT_ARG:.*]] = load <2 x float>, ptr %[[DEFAULT_ARG_ADDR]], align 4
14701470
// OGCG: call void @_Z33function_with_complex_default_argCf(<2 x float> {{.*}} %[[TMP_DEFAULT_ARG]])
1471+
1472+
void calling_function_that_return_complex() {
1473+
float _Complex a = complex_type_return_type();
1474+
}
1475+
1476+
// CIR: %[[A_ADDR:.*]] = cir.alloca !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>, ["a", init]
1477+
// CIR: %[[RESULT:.*]] = cir.call @_Z24complex_type_return_typev() : () -> !cir.complex<!cir.float>
1478+
// CIR: cir.store{{.*}} %[[RESULT]], %[[A_ADDR]] : !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>
1479+
1480+
// TODO(CIR): the difference between the CIR LLVM and OGCG is because the lack of calling convention lowering,
1481+
1482+
// LLVM: %[[A_ADDR:.*]] = alloca { float, float }, i64 1, align 4
1483+
// LLVM: %[[RESULT:.*]] = call { float, float } @_Z24complex_type_return_typev()
1484+
// LLVM: store { float, float } %[[RESULT]], ptr %[[A_ADDR]], align 4
1485+
1486+
// OGCG: %[[A_ADDR:.*]] = alloca { float, float }, align 4
1487+
// OGCG: %[[RESULT_ADDR:.*]] = alloca { float, float }, align 4
1488+
// OGCG: %[[RESULT:.*]] = call noundef <2 x float> @_Z24complex_type_return_typev()
1489+
// OGCG: store <2 x float> %[[RESULT]], ptr %[[RESULT_ADDR]], align 4
1490+
// OGCG: %[[RESULT_REAL_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[RESULT_ADDR]], i32 0, i32 0
1491+
// OGCG: %[[RESULT_REAL:.*]] = load float, ptr %[[RESULT_REAL_PTR]], align 4
1492+
// OGCG: %[[RESULT_IMAG_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[RESULT_ADDR]], i32 0, i32 1
1493+
// OGCG: %[[RESULT_IMAG:.*]] = load float, ptr %[[RESULT_IMAG_PTR]], align 4
1494+
// OGCG: %[[A_REAL_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[A_ADDR]], i32 0, i32 0
1495+
// OGCG: %[[A_IMAG_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[A_ADDR]], i32 0, i32 1
1496+
// OGCG: store float %[[RESULT_REAL]], ptr %[[A_REAL_PTR]], align 4
1497+
// OGCG: store float %[[RESULT_IMAG]], ptr %[[A_IMAG_PTR]], align 4

0 commit comments

Comments
 (0)