|
| 1 | +// RUN: %clang_cc1 -triple aarch64-none-linux-android21 -fclangir -emit-cir %s -o %t.cir |
| 2 | +// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s |
| 3 | +// UN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t.ll |
| 4 | +// UN: FileCheck --check-prefix=LLVM --input-file=%t.ll %s |
| 5 | + |
| 6 | + |
| 7 | +struct Data { |
| 8 | + int value; |
| 9 | + void *ptr; |
| 10 | +}; |
| 11 | + |
| 12 | +typedef struct Data *DataPtr; |
| 13 | + |
| 14 | +void applyThreadFence() { |
| 15 | + __atomic_thread_fence(5); |
| 16 | +} |
| 17 | + |
| 18 | +// CIR-LABEL: cir.func no_proto @applyThreadFence |
| 19 | +// CIR: %0 = cir.const #cir.int<5> : !s32i |
| 20 | +// CIR: cir.atomic.fence(sync_scope = system, ordering = seq_cst) |
| 21 | +// CIR: cir.return |
| 22 | + |
| 23 | +void applySignalFence() { |
| 24 | + __atomic_signal_fence(5); |
| 25 | +} |
| 26 | +// CIR-LABEL: cir.func no_proto @applySignalFence |
| 27 | +// CIR: %0 = cir.const #cir.int<5> : !s32i |
| 28 | +// CIR: cir.atomic.fence(sync_scope = single_thread, ordering = seq_cst) |
| 29 | +// CIR: cir.return |
| 30 | + |
| 31 | +void modifyWithThreadFence(DataPtr d) { |
| 32 | + __atomic_thread_fence(5); |
| 33 | + d->value = 42; |
| 34 | +} |
| 35 | +// CIR-LABEL: cir.func @modifyWithThreadFence |
| 36 | +// CIR: %0 = cir.alloca !cir.ptr<!ty_Data>, !cir.ptr<!cir.ptr<!ty_Data>>, ["d", init] {alignment = 8 : i64} |
| 37 | +// CIR: cir.store %arg0, %0 : !cir.ptr<!ty_Data>, !cir.ptr<!cir.ptr<!ty_Data>> |
| 38 | +// CIR: %1 = cir.const #cir.int<5> : !s32i |
| 39 | +// CIR: cir.atomic.fence(sync_scope = system, ordering = seq_cst) |
| 40 | +// CIR: %2 = cir.const #cir.int<42> : !s32i |
| 41 | +// CIR: %3 = cir.load %0 : !cir.ptr<!cir.ptr<!ty_Data>>, !cir.ptr<!ty_Data> |
| 42 | +// CIR: %4 = cir.get_member %3[0] {name = "value"} : !cir.ptr<!ty_Data> -> !cir.ptr<!s32i> |
| 43 | +// CIR: cir.store %2, %4 : !s32i, !cir.ptr<!s32i> |
| 44 | +// CIR: cir.return |
| 45 | + |
| 46 | +void modifyWithSignalFence(DataPtr d) { |
| 47 | + __atomic_signal_fence(5); |
| 48 | + d->value = 24; |
| 49 | +} |
| 50 | +// CIR-LABEL: cir.func @modifyWithSignalFence |
| 51 | +// CIR: %0 = cir.alloca !cir.ptr<!ty_Data>, !cir.ptr<!cir.ptr<!ty_Data>>, ["d", init] {alignment = 8 : i64} |
| 52 | +// CIR: cir.store %arg0, %0 : !cir.ptr<!ty_Data>, !cir.ptr<!cir.ptr<!ty_Data>> |
| 53 | +// CIR: %1 = cir.const #cir.int<5> : !s32i |
| 54 | +// CIR: cir.atomic.fence(sync_scope = single_thread, ordering = seq_cst) |
| 55 | +// CIR: %2 = cir.const #cir.int<24> : !s32i |
| 56 | +// CIR: %3 = cir.load %0 : !cir.ptr<!cir.ptr<!ty_Data>>, !cir.ptr<!ty_Data> |
| 57 | +// CIR: %4 = cir.get_member %3[0] {name = "value"} : !cir.ptr<!ty_Data> -> !cir.ptr<!s32i> |
| 58 | +// CIR: cir.store %2, %4 : !s32i, !cir.ptr<!s32i> |
| 59 | +// CIR: cir.return |
| 60 | + |
| 61 | +void loadWithThreadFence(DataPtr d) { |
| 62 | + __atomic_thread_fence(5); |
| 63 | + __atomic_load_n(&d->ptr, 5); |
| 64 | +} |
| 65 | +// CIR-LABEL: cir.func @loadWithThreadFence |
| 66 | +// CIR: %0 = cir.alloca !cir.ptr<!ty_Data>, !cir.ptr<!cir.ptr<!ty_Data>>, ["d", init] {alignment = 8 : i64} |
| 67 | +// CIR: %1 = cir.alloca !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>>, ["atomic-temp"] {alignment = 8 : i64} |
| 68 | +// CIR: cir.store %arg0, %0 : !cir.ptr<!ty_Data>, !cir.ptr<!cir.ptr<!ty_Data>> |
| 69 | +// CIR: %2 = cir.const #cir.int<5> : !s32i |
| 70 | +// CIR: cir.atomic.fence(sync_scope = system, ordering = seq_cst) |
| 71 | +// CIR: %3 = cir.load %0 : !cir.ptr<!cir.ptr<!ty_Data>>, !cir.ptr<!ty_Data> |
| 72 | +// CIR: %4 = cir.get_member %3[1] {name = "ptr"} : !cir.ptr<!ty_Data> -> !cir.ptr<!cir.ptr<!void>> |
| 73 | +// CIR: %5 = cir.const #cir.int<5> : !s32i |
| 74 | +// CIR: %6 = cir.cast(bitcast, %4 : !cir.ptr<!cir.ptr<!void>>), !cir.ptr<!u64i> |
| 75 | +// CIR: %7 = cir.load atomic(seq_cst) %6 : !cir.ptr<!u64i>, !u64i |
| 76 | +// CIR: %8 = cir.cast(bitcast, %1 : !cir.ptr<!cir.ptr<!void>>), !cir.ptr<!u64i> |
| 77 | +// CIR: cir.store %7, %8 : !u64i, !cir.ptr<!u64i> |
| 78 | +// CIR: %9 = cir.load %1 : !cir.ptr<!cir.ptr<!void>>, !cir.ptr<!void> |
| 79 | +// CIR: cir.return |
| 80 | + |
| 81 | +void loadWithSignalFence(DataPtr d) { |
| 82 | + __atomic_signal_fence(5); |
| 83 | + __atomic_load_n(&d->ptr, 5); |
| 84 | +} |
| 85 | +// CIR-LABEL: cir.func @loadWithSignalFence |
| 86 | +// CIR: %0 = cir.alloca !cir.ptr<!ty_Data>, !cir.ptr<!cir.ptr<!ty_Data>>, ["d", init] {alignment = 8 : i64} |
| 87 | +// CIR: %1 = cir.alloca !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>>, ["atomic-temp"] {alignment = 8 : i64} |
| 88 | +// CIR: cir.store %arg0, %0 : !cir.ptr<!ty_Data>, !cir.ptr<!cir.ptr<!ty_Data>> |
| 89 | +// CIR: %2 = cir.const #cir.int<5> : !s32i |
| 90 | +// CIR: cir.atomic.fence(sync_scope = single_thread, ordering = seq_cst) |
| 91 | +// CIR: %3 = cir.load %0 : !cir.ptr<!cir.ptr<!ty_Data>>, !cir.ptr<!ty_Data> |
| 92 | +// CIR: %4 = cir.get_member %3[1] {name = "ptr"} : !cir.ptr<!ty_Data> -> !cir.ptr<!cir.ptr<!void>> |
| 93 | +// CIR: %5 = cir.const #cir.int<5> : !s32i |
| 94 | +// CIR: %6 = cir.cast(bitcast, %4 : !cir.ptr<!cir.ptr<!void>>), !cir.ptr<!u64i> |
| 95 | +// CIR: %7 = cir.load atomic(seq_cst) %6 : !cir.ptr<!u64i>, !u64i |
| 96 | +// CIR: %8 = cir.cast(bitcast, %1 : !cir.ptr<!cir.ptr<!void>>), !cir.ptr<!u64i> |
| 97 | +// CIR: cir.store %7, %8 : !u64i, !cir.ptr<!u64i> |
| 98 | +// CIR: %9 = cir.load %1 : !cir.ptr<!cir.ptr<!void>>, !cir.ptr<!void> |
| 99 | +// CIR: cir.return |
0 commit comments