Skip to content

Commit 4bddd9d

Browse files
committed
CodeGen: make target builtins support languages
This extends the target builtin support to allow language specific annotations (i.e. LANGBUILTIN). This is to allow MSVC compatibility whilst retaining the ability to have EABI targets use a __builtin_ prefix. This is merely to allow uniformity in the EABI case where the unprefixed name is provided as an alias in the header. llvm-svn: 212196
1 parent c7e4457 commit 4bddd9d

File tree

6 files changed

+64
-14
lines changed

6 files changed

+64
-14
lines changed

clang/include/clang/Basic/BuiltinsARM.def

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414

1515
// The format of this database matches clang/Basic/Builtins.def.
1616

17+
#if defined(BUILTIN) && !defined(LANGBUILTIN)
18+
# define LANGBUILTIN(ID, TYPE, ATTRS, BUILTIN_LANG) BUILTIN(ID, TYPE, ATTRS)
19+
#endif
20+
1721
// In libgcc
1822
BUILTIN(__clear_cache, "vv*v*", "i")
1923
BUILTIN(__builtin_thread_pointer, "v*", "")
@@ -64,14 +68,22 @@ BUILTIN(__builtin_arm_crc32d, "UiUiLLUi", "nc")
6468
BUILTIN(__builtin_arm_crc32cd, "UiUiLLUi", "nc")
6569

6670
// HINT
67-
BUILTIN(__yield, "v", "")
68-
BUILTIN(__wfe, "v", "")
69-
BUILTIN(__wfi, "v", "")
70-
BUILTIN(__sev, "v", "")
71-
BUILTIN(__sevl, "v", "")
71+
BUILTIN(__builtin_yield, "v", "")
72+
BUILTIN(__builtin_wfe, "v", "")
73+
BUILTIN(__builtin_wfi, "v", "")
74+
BUILTIN(__builtin_sev, "v", "")
75+
BUILTIN(__builtin_sevl, "v", "")
7276

7377
// Data barrier
7478
BUILTIN(__builtin_arm_dmb, "vUi", "nc")
7579
BUILTIN(__builtin_arm_dsb, "vUi", "nc")
7680

81+
// MSVC
82+
LANGBUILTIN(__yield, "v", "", ALL_MS_LANGUAGES)
83+
LANGBUILTIN(__wfe, "v", "", ALL_MS_LANGUAGES)
84+
LANGBUILTIN(__wfi, "v", "", ALL_MS_LANGUAGES)
85+
LANGBUILTIN(__sev, "v", "", ALL_MS_LANGUAGES)
86+
LANGBUILTIN(__sevl, "v", "", ALL_MS_LANGUAGES)
87+
7788
#undef BUILTIN
89+
#undef LANGBUILTIN

clang/lib/Basic/Builtins.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ void Builtin::Context::InitializeBuiltins(IdentifierTable &Table,
7676

7777
// Step #2: Register target-specific builtins.
7878
for (unsigned i = 0, e = NumTSRecords; i != e; ++i)
79-
if (!LangOpts.NoBuiltin || !strchr(TSRecords[i].Attributes, 'f'))
79+
if (BuiltinIsSupported(TSRecords[i], LangOpts))
8080
Table.get(TSRecords[i].Name).setBuiltinID(i+Builtin::FirstTSBuiltin);
8181
}
8282

clang/lib/Basic/Targets.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4170,6 +4170,7 @@ const Builtin::Info ARMTargetInfo::BuiltinInfo[] = {
41704170
#include "clang/Basic/BuiltinsNEON.def"
41714171

41724172
#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES },
4173+
#define LANGBUILTIN(ID, TYPE, ATTRS, LANG) { #ID, TYPE, ATTRS, 0, LANG },
41734174
#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\
41744175
ALL_LANGUAGES },
41754176
#include "clang/Basic/BuiltinsARM.def"

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3033,18 +3033,23 @@ Value *CodeGenFunction::EmitARMBuiltinExpr(unsigned BuiltinID,
30333033
unsigned HintID = static_cast<unsigned>(-1);
30343034
switch (BuiltinID) {
30353035
default: break;
3036+
case ARM::BI__builtin_yield:
30363037
case ARM::BI__yield:
30373038
HintID = 1;
30383039
break;
3040+
case ARM::BI__builtin_wfe:
30393041
case ARM::BI__wfe:
30403042
HintID = 2;
30413043
break;
3044+
case ARM::BI__builtin_wfi:
30423045
case ARM::BI__wfi:
30433046
HintID = 3;
30443047
break;
3048+
case ARM::BI__builtin_sev:
30453049
case ARM::BI__sev:
30463050
HintID = 4;
30473051
break;
3052+
case ARM::BI__builtin_sevl:
30483053
case ARM::BI__sevl:
30493054
HintID = 5;
30503055
break;
Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,41 @@
1-
// RUN: %clang_cc1 -triple thumbv7-windows -emit-llvm -o - %s | FileCheck %s
2-
// RUN: %clang_cc1 -triple armv7-eabi -emit-llvm -o - %s | FileCheck %s
1+
// RUN: %clang_cc1 -triple thumbv7-windows -fms-compatibility -emit-llvm -o - %s \
2+
// RUN: | FileCheck %s -check-prefix CHECK-MSVC
3+
// RUN: %clang_cc1 -triple armv7-eabi -emit-llvm %s -o - \
4+
// RUN: | FileCheck %s -check-prefix CHECK-EABI
35
// REQUIRES: arm-registered-target
46

57
void test_yield_intrinsic() {
68
__yield();
79
}
810

9-
// CHECK: call void @llvm.arm.hint(i32 1)
11+
// CHECK-MSVC: call void @llvm.arm.hint(i32 1)
12+
// CHECK-EABI-NOT: call void @llvm.arm.hint(i32 1)
13+
14+
void wfe() {
15+
__wfe();
16+
}
17+
18+
// CHECK-MSVC: call {{.*}} @llvm.arm.hint(i32 2)
19+
// CHECK-EABI-NOT: call {{.*}} @llvm.arm.hint(i32 2)
20+
21+
void wfi() {
22+
__wfi();
23+
}
24+
25+
// CHECK-MSVC: call {{.*}} @llvm.arm.hint(i32 3)
26+
// CHECK-EABI-NOT: call {{.*}} @llvm.arm.hint(i32 3)
27+
28+
void sev() {
29+
__sev();
30+
}
31+
32+
// CHECK-MSVC: call {{.*}} @llvm.arm.hint(i32 4)
33+
// CHECK-EABI-NOT: call {{.*}} @llvm.arm.hint(i32 4)
34+
35+
void sevl() {
36+
__sevl();
37+
}
38+
39+
// CHECK-MSVC: call {{.*}} @llvm.arm.hint(i32 5)
40+
// CHECK-EABI-NOT: call {{.*}} @llvm.arm.hint(i32 5)
1041

clang/test/CodeGen/builtins-arm.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,33 @@ void test_eh_return_data_regno()
2020
}
2121

2222
void yield() {
23-
__yield();
23+
__builtin_yield();
2424
}
2525

2626
// CHECK: call {{.*}} @llvm.arm.hint(i32 1)
2727

2828
void wfe() {
29-
__wfe();
29+
__builtin_wfe();
3030
}
3131

3232
// CHECK: call {{.*}} @llvm.arm.hint(i32 2)
3333

3434
void wfi() {
35-
__wfi();
35+
__builtin_wfi();
3636
}
3737

3838
// CHECK: call {{.*}} @llvm.arm.hint(i32 3)
3939

4040
void sev() {
41-
__sev();
41+
__builtin_sev();
4242
}
4343

4444
// CHECK: call {{.*}} @llvm.arm.hint(i32 4)
4545

4646
void sevl() {
47-
__sevl();
47+
__builtin_sevl();
4848
}
49+
4950
// CHECK: call {{.*}} @llvm.arm.hint(i32 5)
5051

5152
void test_barrier() {

0 commit comments

Comments
 (0)