Skip to content

Commit 96efab1

Browse files
authored
[CIR] Implement Atomic init for ComplexType (#1873)
Implement Atomic init for ComplexType
1 parent 31700c8 commit 96efab1

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

clang/lib/CIR/CodeGen/CIRGenAtomic.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,9 @@ bool AtomicInfo::requiresMemSetZero(mlir::Type ty) const {
290290
case cir::TEK_Scalar:
291291
return !isFullSizeType(CGF.CGM, ty, AtomicSizeInBits);
292292
case cir::TEK_Complex:
293-
llvm_unreachable("NYI");
293+
return !isFullSizeType(CGF.CGM,
294+
mlir::cast<cir::ComplexType>(ty).getElementType(),
295+
AtomicSizeInBits / 2);
294296

295297
// Padding in structs has an undefined bit pattern. User beware.
296298
case cir::TEK_Aggregate:
@@ -1499,7 +1501,8 @@ void CIRGenFunction::emitAtomicInit(Expr *init, LValue dest) {
14991501
}
15001502

15011503
case cir::TEK_Complex: {
1502-
llvm_unreachable("NYI");
1504+
mlir::Value value = emitComplexExpr(init);
1505+
atomics.emitCopyIntoMemory(RValue::get(value));
15031506
return;
15041507
}
15051508

clang/test/CIR/CodeGen/complex.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,3 +210,21 @@ void complex_cxx_default_init_expr() {
210210
// OGCG: %[[C_IMAG_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[C_ADDR]], i32 0, i32 1
211211
// OGCG: store float 0.000000e+00, ptr %[[C_REAL_PTR]], align 4
212212
// OGCG: store float 0.000000e+00, ptr %[[C_IMAG_PTR]], align 4
213+
214+
void complex_init_atomic() {
215+
_Atomic(float _Complex) a;
216+
__c11_atomic_init(&a, {1.0f, 2.0f});
217+
}
218+
219+
// CIR: %[[A_ADDR:.*]] = cir.alloca !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>, ["a"]
220+
// CIR: %[[CONST_COMPLEX:.*]] = cir.const #cir.complex<#cir.fp<1.000000e+00> : !cir.float, #cir.fp<2.000000e+00> : !cir.float> : !cir.complex<!cir.float>
221+
// CIR: cir.store{{.*}} %[[CONST_COMPLEX]], %[[A_ADDR]] : !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>
222+
223+
// LLVM: %[[A_ADDR:.*]] = alloca { float, float }, i64 1, align 8
224+
// LLVM: store { float, float } { float 1.000000e+00, float 2.000000e+00 }, ptr %[[A_ADDR]], align 8
225+
226+
// OGCG: %[[A_ADDR:.*]] = alloca { float, float }, align 8
227+
// OGCG: %[[A_REAL_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[A_ADDR]], i32 0, i32 0
228+
// OGCG: %[[A_IMAG_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[A_ADDR]], i32 0, i32 1
229+
// OGCG: store float 1.000000e+00, ptr %[[A_REAL_PTR]], align 8
230+
// OGCG: store float 2.000000e+00, ptr %[[A_IMAG_PTR]], align 4

0 commit comments

Comments
 (0)