Skip to content

Commit f70d17f

Browse files
committed
[LoongArch] Define __GCC_HAVE_SYNC_COMPARE_AND_SWAP macros
Define __GCC_HAVE_SYNC_COMPARE_AND_SWAP macros Reviewed By: SixWeining, MaskRay Differential Revision: https://reviews.llvm.org/D141070
1 parent 1b82245 commit f70d17f

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

clang/lib/Basic/Targets/LoongArch.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,12 @@ void LoongArchTargetInfo::getTargetDefines(const LangOptions &Opts,
158158
} else if (ABI == "lp64s" || ABI == "ilp32s") {
159159
Builder.defineMacro("__loongarch_soft_float");
160160
}
161+
162+
Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
163+
Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
164+
Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
165+
if (GRLen == 64)
166+
Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8");
161167
}
162168

163169
static constexpr Builtin::Info BuiltinInfo[] = {

clang/test/Preprocessor/init-loongarch.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@
8181
// LA32: #define __GCC_ATOMIC_SHORT_LOCK_FREE 2
8282
// LA32: #define __GCC_ATOMIC_TEST_AND_SET_TRUEVAL 1
8383
// LA32: #define __GCC_ATOMIC_WCHAR_T_LOCK_FREE 2
84+
// LA32: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
85+
// LA32: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1
86+
// LA32: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1
8487
// LA32: #define __ILP32__ 1
8588
// LA32: #define __INT16_C_SUFFIX__
8689
// LA32: #define __INT16_FMTd__ "hd"
@@ -394,6 +397,10 @@
394397
// LA64: #define __GCC_ATOMIC_SHORT_LOCK_FREE 2
395398
// LA64: #define __GCC_ATOMIC_TEST_AND_SET_TRUEVAL 1
396399
// LA64: #define __GCC_ATOMIC_WCHAR_T_LOCK_FREE 2
400+
// LA64: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
401+
// LA64: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1
402+
// LA64: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1
403+
// LA64: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1
397404
// LA64: #define __INT16_C_SUFFIX__
398405
// LA64: #define __INT16_FMTd__ "hd"
399406
// LA64: #define __INT16_FMTi__ "hi"

clang/test/Preprocessor/predefined-arch-macros.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4372,3 +4372,20 @@
43724372
// CHECK_WASM_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1
43734373
// CHECK_WASM_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1
43744374
// CHECK_WASM_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1
4375+
4376+
// Begin LoongArch tests ----------------
4377+
4378+
// RUN: %clang -E -dM %s -o - 2>&1 \
4379+
// RUN: --target=loongarch32-unknown-linux-gnu \
4380+
// RUN: | FileCheck -match-full-lines %s -check-prefix=CHECK_LA32_ATOMICS
4381+
// CHECK_LA32_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
4382+
// CHECK_LA32_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1
4383+
// CHECK_LA32_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1
4384+
4385+
// RUN: %clang -E -dM %s -o - 2>&1 \
4386+
// RUN: --target=loongarch64-unknown-linux-gnu \
4387+
// RUN: | FileCheck -match-full-lines %s -check-prefix=CHECK_LA64_ATOMICS
4388+
// CHECK_LA64_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
4389+
// CHECK_LA64_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1
4390+
// CHECK_LA64_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1
4391+
// CHECK_LA64_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1

0 commit comments

Comments
 (0)