Skip to content

Commit 9997e41

Browse files
authored
[CIR] Backport AtomicExpr for ComplexType (#1936)
Backport AtomicExpr for ComplexType from the upstream
1 parent d645aa7 commit 9997e41

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

clang/lib/CIR/CodeGen/CIRGenExpr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2717,13 +2717,13 @@ RValue CIRGenFunction::convertTempToRValue(Address addr, clang::QualType type,
27172717
LValue lvalue = makeAddrLValue(addr, type, AlignmentSource::Decl);
27182718
switch (getEvaluationKind(type)) {
27192719
case cir::TEK_Complex:
2720-
llvm_unreachable("NYI");
2720+
return RValue::getComplex(emitLoadOfComplex(lvalue, loc));
27212721
case cir::TEK_Aggregate:
27222722
return lvalue.asAggregateRValue();
27232723
case cir::TEK_Scalar:
27242724
return RValue::get(emitLoadOfScalar(lvalue, loc));
27252725
}
2726-
llvm_unreachable("NYI");
2726+
llvm_unreachable("bad evaluation kind");
27272727
}
27282728

27292729
/// An LValue is a candidate for having its loads and stores be made atomic if

clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,9 @@ class ComplexExprEmitter : public StmtVisitor<ComplexExprEmitter, mlir::Value> {
374374

375375
mlir::Value VisitVAArgExpr(VAArgExpr *E) { llvm_unreachable("NYI"); }
376376

377-
mlir::Value VisitAtomicExpr(AtomicExpr *E) { llvm_unreachable("NYI"); }
377+
mlir::Value VisitAtomicExpr(AtomicExpr *E) {
378+
return CGF.emitAtomicExpr(E).getComplexVal();
379+
}
378380

379381
mlir::Value VisitPackIndexingExpr(PackIndexingExpr *E) {
380382
llvm_unreachable("NYI");

clang/test/CIR/CodeGen/complex.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,3 +246,41 @@ void complex_opaque_value_expr() {
246246
// OGCG: %[[A_ADDR:.*]] = alloca { float, float }, align 4
247247
// OGCG: %[[B_ADDR:.*]] = alloca float, align 4
248248
// OGCG: store float 1.000000e+00, ptr %[[B_ADDR]], align 4
249+
250+
void atomic_complex_type() {
251+
_Atomic(float _Complex) a;
252+
float _Complex b = __c11_atomic_load(&a, __ATOMIC_RELAXED);
253+
}
254+
255+
// CIR: %[[A_ADDR:.*]] = cir.alloca !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>, ["a"]
256+
// CIR: %[[B_ADDR:.*]] = cir.alloca !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>, ["b", init]
257+
// CIR: %[[ATOMIC_TMP_ADDR:.*]] = cir.alloca !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>, ["atomic-temp"]
258+
// CIR: %[[A_PTR:.*]] = cir.cast bitcast %[[A_ADDR]] : !cir.ptr<!cir.complex<!cir.float>> -> !cir.ptr<!u64i>
259+
// CIR: %[[ATOMIC_TMP_PTR:.*]] = cir.cast bitcast %[[ATOMIC_TMP_ADDR]] : !cir.ptr<!cir.complex<!cir.float>> -> !cir.ptr<!u64i>
260+
// CIR: %[[TMP_A_ATOMIC:.*]] = cir.load{{.*}} atomic(relaxed) %[[A_PTR]] : !cir.ptr<!u64i>, !u64i
261+
// CIR: cir.store{{.*}} %[[TMP_A_ATOMIC]], %[[ATOMIC_TMP_PTR]] : !u64i, !cir.ptr<!u64i>
262+
// CIR: %[[TMP_ATOMIC_PTR:.*]] = cir.cast bitcast %[[ATOMIC_TMP_PTR]] : !cir.ptr<!u64i> -> !cir.ptr<!cir.complex<!cir.float>>
263+
// CIR: %[[TMP_ATOMIC:.*]] = cir.load{{.*}} %[[TMP_ATOMIC_PTR]] : !cir.ptr<!cir.complex<!cir.float>>, !cir.complex<!cir.float>
264+
// CIR: cir.store{{.*}} %[[TMP_ATOMIC]], %[[B_ADDR]] : !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>
265+
266+
// LLVM: %[[A_ADDR:.*]] = alloca { float, float }, i64 1, align 8
267+
// LLVM: %[[B_ADDR:.*]] = alloca { float, float }, i64 1, align 4
268+
// LLVM: %[[ATOMIC_TMP_ADDR:.*]] = alloca { float, float }, i64 1, align 8
269+
// LLVM: %[[TMP_A_ATOMIC:.*]] = load atomic i64, ptr %[[A_ADDR]] monotonic, align 8
270+
// LLVM: store i64 %[[TMP_A_ATOMIC]], ptr %[[ATOMIC_TMP_ADDR]], align 8
271+
// LLVM: %[[TMP_ATOMIC:.*]] = load { float, float }, ptr %[[ATOMIC_TMP_ADDR]], align 8
272+
// LLVM: store { float, float } %[[TMP_ATOMIC]], ptr %[[B_ADDR]], align 4
273+
274+
// OGCG: %[[A_ADDR:.*]] = alloca { float, float }, align 8
275+
// OGCG: %[[B_ADDR:.*]] = alloca { float, float }, align 4
276+
// OGCG: %[[ATOMIC_TMP_ADDR:.*]] = alloca { float, float }, align 8
277+
// OGCG: %[[TMP_A_ATOMIC:.*]] = load atomic i64, ptr %[[A_ADDR]] monotonic, align 8
278+
// OGCG: store i64 %[[TMP_A_ATOMIC]], ptr %[[ATOMIC_TMP_ADDR]], align 8
279+
// OGCG: %[[ATOMIC_TMP_REAL_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[ATOMIC_TMP_ADDR]], i32 0, i32 0
280+
// OGCG: %[[ATOMIC_TMP_REAL:.*]] = load float, ptr %[[ATOMIC_TMP_REAL_PTR]], align 8
281+
// OGCG: %[[ATOMIC_TMP_IMAG_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[ATOMIC_TMP_ADDR]], i32 0, i32 1
282+
// OGCG: %[[ATOMIC_TMP_IMAG:.*]] = load float, ptr %[[ATOMIC_TMP_IMAG_PTR]], align 4
283+
// OGCG: %[[B_REAL_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[B_ADDR]], i32 0, i32 0
284+
// OGCG: %[[B_IMAG_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[B_ADDR]], i32 0, i32 1
285+
// OGCG: store float %[[ATOMIC_TMP_REAL]], ptr %[[B_REAL_PTR]], align 4
286+
// OGCG: store float %[[ATOMIC_TMP_IMAG]], ptr %[[B_IMAG_PTR]], align 4

0 commit comments

Comments
 (0)