-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CIR][CIRGen] Support for builtin __atomic_thread_fence
Resolves #1274 Implements atomic thread fence synchronization primitive corresponding to `atomic.thread_fence` CIR.
- Loading branch information
1 parent
d329c96
commit 97fb189
Showing
5 changed files
with
189 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// RUN: %clang_cc1 -triple aarch64-none-linux-android21 -fclangir -emit-cir %s -o %t.cir | ||
// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s | ||
// UN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t.ll | ||
// UN: FileCheck --check-prefix=LLVM --input-file=%t.ll %s | ||
|
||
|
||
struct Data { | ||
int value; | ||
void *ptr; | ||
}; | ||
|
||
typedef struct Data *DataPtr; | ||
|
||
void applyThreadFence() { | ||
__atomic_thread_fence(5); | ||
} | ||
|
||
// CIR-LABEL: cir.func no_proto @applyThreadFence | ||
// CIR: %0 = cir.const #cir.int<5> : !s32i | ||
// CIR: cir.return | ||
|
||
void applySignalFence() { | ||
__atomic_signal_fence(5); | ||
} | ||
// CIR-LABEL: cir.func no_proto @applySignalFence | ||
// CIR: %0 = cir.const #cir.int<5> : !s32i | ||
// CIR: cir.return | ||
|
||
void modifyWithThreadFence(DataPtr d) { | ||
__atomic_thread_fence(5); | ||
d->value = 42; | ||
} | ||
// CIR-LABEL: cir.func @modifyWithThreadFence | ||
// CIR: %0 = cir.alloca !cir.ptr<!ty_Data>, !cir.ptr<!cir.ptr<!ty_Data>>, ["d", init] {alignment = 8 : i64} | ||
// CIR: cir.store %arg0, %0 : !cir.ptr<!ty_Data>, !cir.ptr<!cir.ptr<!ty_Data>> | ||
// CIR: %1 = cir.const #cir.int<5> : !s32i | ||
// CIR: %2 = cir.const #cir.int<42> : !s32i | ||
// CIR: %3 = cir.load %0 : !cir.ptr<!cir.ptr<!ty_Data>>, !cir.ptr<!ty_Data> | ||
// CIR: %4 = cir.get_member %3[0] {name = "value"} : !cir.ptr<!ty_Data> -> !cir.ptr<!s32i> | ||
// CIR: cir.store %2, %4 : !s32i, !cir.ptr<!s32i> | ||
// CIR: cir.return | ||
|
||
void modifyWithSignalFence(DataPtr d) { | ||
__atomic_signal_fence(5); | ||
d->value = 24; | ||
} | ||
// CIR-LABEL: cir.func @modifyWithSignalFence | ||
// %0 = cir.alloca !cir.ptr<!ty_Data>, !cir.ptr<!cir.ptr<!ty_Data>>, ["d", init] {alignment = 8 : i64} | ||
// cir.store %arg0, %0 : !cir.ptr<!ty_Data>, !cir.ptr<!cir.ptr<!ty_Data>> | ||
// %1 = cir.const #cir.int<5> : !s32i | ||
// %2 = cir.const #cir.int<24> : !s32i | ||
// %3 = cir.load %0 : !cir.ptr<!cir.ptr<!ty_Data>>, !cir.ptr<!ty_Data> | ||
// %4 = cir.get_member %3[0] {name = "value"} : !cir.ptr<!ty_Data> -> !cir.ptr<!s32i> | ||
// cir.store %2, %4 : !s32i, !cir.ptr<!s32i> | ||
// cir.return | ||
|
||
void loadWithThreadFence(DataPtr d) { | ||
__atomic_thread_fence(5); | ||
__atomic_load_n(&d->ptr, 5); | ||
} | ||
// CIR-LABEL: cir.func @loadWithThreadFence | ||
// %0 = cir.alloca !cir.ptr<!ty_Data>, !cir.ptr<!cir.ptr<!ty_Data>>, ["d", init] {alignment = 8 : i64} | ||
// %1 = cir.alloca !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>>, ["atomic-temp"] {alignment = 8 : i64} | ||
// cir.store %arg0, %0 : !cir.ptr<!ty_Data>, !cir.ptr<!cir.ptr<!ty_Data>> | ||
// %2 = cir.const #cir.int<5> : !s32i | ||
// %3 = cir.load %0 : !cir.ptr<!cir.ptr<!ty_Data>>, !cir.ptr<!ty_Data> | ||
// %4 = cir.get_member %3[1] {name = "ptr"} : !cir.ptr<!ty_Data> -> !cir.ptr<!cir.ptr<!void>> | ||
// %5 = cir.const #cir.int<5> : !s32i | ||
// %6 = cir.cast(bitcast, %4 : !cir.ptr<!cir.ptr<!void>>), !cir.ptr<!u64i> | ||
// %7 = cir.load atomic(seq_cst) %6 : !cir.ptr<!u64i>, !u64i | ||
// %8 = cir.cast(bitcast, %1 : !cir.ptr<!cir.ptr<!void>>), !cir.ptr<!u64i> | ||
// cir.store %7, %8 : !u64i, !cir.ptr<!u64i> | ||
// %9 = cir.load %1 : !cir.ptr<!cir.ptr<!void>>, !cir.ptr<!void> | ||
// cir.return | ||
|
||
void loadWithSignalFence(DataPtr d) { | ||
__atomic_signal_fence(5); | ||
__atomic_load_n(&d->ptr, 5); | ||
} | ||
// CIR-LABEL: cir.func @loadWithSignalFence | ||
// %0 = cir.alloca !cir.ptr<!ty_Data>, !cir.ptr<!cir.ptr<!ty_Data>>, ["d", init] {alignment = 8 : i64} | ||
// %1 = cir.alloca !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>>, ["atomic-temp"] {alignment = 8 : i64} | ||
// cir.store %arg0, %0 : !cir.ptr<!ty_Data>, !cir.ptr<!cir.ptr<!ty_Data>> | ||
// %2 = cir.const #cir.int<5> : !s32i | ||
// %3 = cir.load %0 : !cir.ptr<!cir.ptr<!ty_Data>>, !cir.ptr<!ty_Data> | ||
// %4 = cir.get_member %3[1] {name = "ptr"} : !cir.ptr<!ty_Data> -> !cir.ptr<!cir.ptr<!void>> | ||
// %5 = cir.const #cir.int<5> : !s32i | ||
// %6 = cir.cast(bitcast, %4 : !cir.ptr<!cir.ptr<!void>>), !cir.ptr<!u64i> | ||
// %7 = cir.load atomic(seq_cst) %6 : !cir.ptr<!u64i>, !u64i | ||
// %8 = cir.cast(bitcast, %1 : !cir.ptr<!cir.ptr<!void>>), !cir.ptr<!u64i> | ||
// cir.store %7, %8 : !u64i, !cir.ptr<!u64i> | ||
// %9 = cir.load %1 : !cir.ptr<!cir.ptr<!void>>, !cir.ptr<!void> | ||
// cir.return |