[CIR] Upstream GenericSelectionExpr for ComplexType (#146265)
Upstream the GenericSelectionExpr for ComplexType https://github.com/llvm/llvm-project/issues/141365
This commit is contained in:
@@ -43,6 +43,7 @@ public:
|
||||
mlir::Value VisitCallExpr(const CallExpr *e);
|
||||
mlir::Value VisitChooseExpr(ChooseExpr *e);
|
||||
mlir::Value VisitDeclRefExpr(DeclRefExpr *e);
|
||||
mlir::Value VisitGenericSelectionExpr(GenericSelectionExpr *e);
|
||||
mlir::Value VisitImplicitCastExpr(ImplicitCastExpr *e);
|
||||
mlir::Value VisitInitListExpr(const InitListExpr *e);
|
||||
mlir::Value VisitImaginaryLiteral(const ImaginaryLiteral *il);
|
||||
@@ -151,6 +152,11 @@ mlir::Value ComplexExprEmitter::VisitDeclRefExpr(DeclRefExpr *e) {
|
||||
return emitLoadOfLValue(e);
|
||||
}
|
||||
|
||||
mlir::Value
|
||||
ComplexExprEmitter::VisitGenericSelectionExpr(GenericSelectionExpr *e) {
|
||||
return Visit(e->getResultExpr());
|
||||
}
|
||||
|
||||
mlir::Value ComplexExprEmitter::VisitImplicitCastExpr(ImplicitCastExpr *e) {
|
||||
// Unlike for scalars, we don't have to worry about function->ptr demotion
|
||||
// here.
|
||||
|
||||
@@ -442,3 +442,34 @@ bool foo19(double _Complex a, double _Complex b) {
|
||||
// OGCG: %[[CMP_IMAG:.*]] = fcmp oeq double %[[A_IMAG]], %[[B_IMAG]]
|
||||
// OGCG: %[[RESULT:.*]] = and i1 %[[CMP_REAL]], %[[CMP_IMAG]]
|
||||
|
||||
void foo23(int _Complex a, int _Complex b) {
|
||||
float _Complex f;
|
||||
int _Complex c = _Generic(a, int _Complex: b, default: f);
|
||||
}
|
||||
|
||||
// CIR: %[[COMPLEX_A:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["a", init]
|
||||
// CIR: %[[COMPLEX_B:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["b", init]
|
||||
// CIR: %[[COMPLEX_F:.*]] = cir.alloca !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>, ["f"]
|
||||
// CIR: %[[RESULT:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["c", init]
|
||||
// CIR: %[[TMP:.*]] = cir.load{{.*}} %[[COMPLEX_B]] : !cir.ptr<!cir.complex<!s32i>>, !cir.complex<!s32i>
|
||||
// CIR: cir.store{{.*}} %[[TMP]], %[[RESULT]] : !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>
|
||||
|
||||
// LLVM: %[[COMPLEX_A:.*]] = alloca { i32, i32 }, i64 1, align 4
|
||||
// LLVM: %[[COMPLEX_B:.*]] = alloca { i32, i32 }, i64 1, align 4
|
||||
// LLVM: %[[COMPLEX_F:.*]] = alloca { float, float }, i64 1, align 4
|
||||
// LLVM: %[[RESULT:.*]] = alloca { i32, i32 }, i64 1, align 4
|
||||
// LLVM: %[[TMP:.*]] = load { i32, i32 }, ptr %[[COMPLEX_B]], align 4
|
||||
// LLVM: store { i32, i32 } %[[TMP]], ptr %[[RESULT]], align 4
|
||||
|
||||
// OGCG: %[[COMPLEX_A:.*]] = alloca { i32, i32 }, align 4
|
||||
// OGCG: %[[COMPLEX_B:.*]] = alloca { i32, i32 }, align 4
|
||||
// OGCG: %[[COMPLEX_F:.*]] = alloca { float, float }, align 4
|
||||
// OGCG: %[[RESULT:.*]] = alloca { i32, i32 }, align 4
|
||||
// OGCG: %[[B_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX_B]], i32 0, i32 0
|
||||
// OGCG: %[[B_REAL:.*]] = load i32, ptr %[[B_REAL_PTR]], align 4
|
||||
// OGCG: %[[B_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX_B]], i32 0, i32 1
|
||||
// OGCG: %[[B_IMAG:.*]] = load i32, ptr %[[B_IMAG_PTR]], align 4
|
||||
// OGCG: %[[RESULT_REAL_PT:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[RESULT]], i32 0, i32 0
|
||||
// OGCG: %[[RESULT_IMAG_PT:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[RESULT]], i32 0, i32 1
|
||||
// OGCG: store i32 %[[B_REAL]], ptr %[[RESULT_REAL_PT]], align 4
|
||||
// OGCG: store i32 %[[B_IMAG]], ptr %[[RESULT_IMAG_PT]], align 4
|
||||
|
||||
Reference in New Issue
Block a user