1f79470583759d20c20268711e6111461aefa8461Jim Grosbach// REQUIRES: arm-registered-target
2a71d3c65375114146bb515b31820c5bf5d670128Rafael Espindola// RUN: %clang_cc1 -Wall -Werror -triple thumbv7-eabi -target-cpu cortex-a8 -O3 -emit-llvm -o - %s | FileCheck %s
32752c0137d95aa2f4ee1cdff4b564bac842e041bChris Lattner
42752c0137d95aa2f4ee1cdff4b564bac842e041bChris Lattnervoid *f0()
52752c0137d95aa2f4ee1cdff4b564bac842e041bChris Lattner{
62752c0137d95aa2f4ee1cdff4b564bac842e041bChris Lattner  return __builtin_thread_pointer();
72752c0137d95aa2f4ee1cdff4b564bac842e041bChris Lattner}
8a71d3c65375114146bb515b31820c5bf5d670128Rafael Espindola
9a71d3c65375114146bb515b31820c5bf5d670128Rafael Espindolavoid f1(char *a, char *b) {
10a71d3c65375114146bb515b31820c5bf5d670128Rafael Espindola	__clear_cache(a,b);
11a71d3c65375114146bb515b31820c5bf5d670128Rafael Espindola}
12a71d3c65375114146bb515b31820c5bf5d670128Rafael Espindola
131058253c364b2c98e6cecfe15d18d3562db245f4Daniel Dunbar// CHECK: call {{.*}} @__clear_cache
14a8f7a97a22d1ed92fd3309f071c0121c22e52aa3Logan Chien
15a8f7a97a22d1ed92fd3309f071c0121c22e52aa3Logan Chienvoid test_eh_return_data_regno()
16a8f7a97a22d1ed92fd3309f071c0121c22e52aa3Logan Chien{
17a8f7a97a22d1ed92fd3309f071c0121c22e52aa3Logan Chien  volatile int res;
18a8f7a97a22d1ed92fd3309f071c0121c22e52aa3Logan Chien  res = __builtin_eh_return_data_regno(0);  // CHECK: store volatile i32 0
19a8f7a97a22d1ed92fd3309f071c0121c22e52aa3Logan Chien  res = __builtin_eh_return_data_regno(1);  // CHECK: store volatile i32 1
20a8f7a97a22d1ed92fd3309f071c0121c22e52aa3Logan Chien}
21594e193073fe36b9ecbce9a105c269e20f82b3c9Joey Gouly
22176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hinesvoid nop() {
23176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  __builtin_arm_nop();
24176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines}
25176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
26176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines// CHECK: call {{.*}} @llvm.arm.hint(i32 0)
27176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
286bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesvoid yield() {
29c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines  __builtin_arm_yield();
306bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines}
316bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines
326bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// CHECK: call {{.*}} @llvm.arm.hint(i32 1)
336bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines
346bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesvoid wfe() {
35c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines  __builtin_arm_wfe();
366bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines}
376bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines
386bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// CHECK: call {{.*}} @llvm.arm.hint(i32 2)
396bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines
406bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesvoid wfi() {
41c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines  __builtin_arm_wfi();
426bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines}
436bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines
446bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// CHECK: call {{.*}} @llvm.arm.hint(i32 3)
456bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines
466bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesvoid sev() {
47c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines  __builtin_arm_sev();
486bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines}
496bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines
506bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// CHECK: call {{.*}} @llvm.arm.hint(i32 4)
516bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines
52594e193073fe36b9ecbce9a105c269e20f82b3c9Joey Goulyvoid sevl() {
53c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines  __builtin_arm_sevl();
54594e193073fe36b9ecbce9a105c269e20f82b3c9Joey Gouly}
55c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines
566bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// CHECK: call {{.*}} @llvm.arm.hint(i32 5)
57186b26d01f2876e8b4b1f0f233e13fc4c613cddcWeiming Zhao
58176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hinesvoid dbg() {
59176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  __builtin_arm_dbg(0);
60176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines}
61176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
62176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines// CHECK: call {{.*}} @llvm.arm.dbg(i32 0)
63176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
64186b26d01f2876e8b4b1f0f233e13fc4c613cddcWeiming Zhaovoid test_barrier() {
65186b26d01f2876e8b4b1f0f233e13fc4c613cddcWeiming Zhao  __builtin_arm_dmb(1); //CHECK: call {{.*}} @llvm.arm.dmb(i32 1)
66186b26d01f2876e8b4b1f0f233e13fc4c613cddcWeiming Zhao  __builtin_arm_dsb(2); //CHECK: call {{.*}} @llvm.arm.dsb(i32 2)
67c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines  __builtin_arm_isb(3); //CHECK: call {{.*}} @llvm.arm.isb(i32 3)
68c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines}
69c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines
70c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines// CHECK: call {{.*}} @llvm.arm.rbit(i32 %a)
71c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines
72c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hinesunsigned rbit(unsigned a) {
73c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines  return __builtin_arm_rbit(a);
74186b26d01f2876e8b4b1f0f233e13fc4c613cddcWeiming Zhao}
75176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
76176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hinesvoid prefetch(int i) {
77176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  __builtin_arm_prefetch(&i, 0, 1);
78176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines// CHECK: call {{.*}} @llvm.prefetch(i8* %{{.*}}, i32 0, i32 3, i32 1)
79176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
80176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  __builtin_arm_prefetch(&i, 1, 1);
81176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines// CHECK: call {{.*}} @llvm.prefetch(i8* %{{.*}}, i32 1, i32 3, i32 1)
82176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
83176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
84176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  __builtin_arm_prefetch(&i, 1, 0);
85176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines// CHECK: call {{.*}} @llvm.prefetch(i8* %{{.*}}, i32 1, i32 3, i32 0)
86176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines}
87b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar
88a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainarunsigned mrc() {
89a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  // CHECK: define i32 @mrc()
90a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  // CHECK: [[R:%.*]] = {{.*}} call i32 @llvm.arm.mrc(i32 15, i32 0, i32 13, i32 0, i32 3)
91a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  // CHECK-NEXT: ret i32 [[R]]
92a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  return __builtin_arm_mrc(15, 0, 13, 0, 3);
93a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar}
94a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar
95a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainarunsigned mrc2() {
96a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  // CHECK: define i32 @mrc2()
97a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  // CHECK: [[R:%.*]] = {{.*}} call i32 @llvm.arm.mrc2(i32 15, i32 0, i32 13, i32 0, i32 3)
98a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  // CHECK-NEXT: ret i32 [[R]]
99a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  return __builtin_arm_mrc2(15, 0, 13, 0, 3);
100a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar}
101a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar
102a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainarvoid mcr(unsigned a) {
103a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  // CHECK: define void @mcr(i32 [[A:%.*]])
104a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  // CHECK: call void @llvm.arm.mcr(i32 15, i32 0, i32 [[A]], i32 13, i32 0, i32 3)
105a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  __builtin_arm_mcr(15, 0, a, 13, 0, 3);
106a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar}
107a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar
108a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainarvoid mcr2(unsigned a) {
109a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  // CHECK: define void @mcr2(i32 [[A:%.*]])
110a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  // CHECK: call void @llvm.arm.mcr2(i32 15, i32 0, i32 [[A]], i32 13, i32 0, i32 3)
111a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  __builtin_arm_mcr2(15, 0, a, 13, 0, 3);
112a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar}
113a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar
114a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainarvoid mcrr(unsigned a, unsigned b) {
115a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  // CHECK: define void @mcrr(i32 [[A:%.*]], i32 [[B:%.*]])
116a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  // CHECK: call void @llvm.arm.mcrr(i32 15, i32 0, i32 [[A]], i32 [[B]], i32 0)
117a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  __builtin_arm_mcrr(15, 0, a, b, 0);
118a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar}
119a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar
120a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainarvoid mcrr2(unsigned a, unsigned b) {
121a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  // CHECK: define void @mcrr2(i32 [[A:%.*]], i32 [[B:%.*]])
122a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  // CHECK: call void @llvm.arm.mcrr2(i32 15, i32 0, i32 [[A]], i32 [[B]], i32 0)
123a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  __builtin_arm_mcrr2(15, 0, a, b, 0);
124a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar}
125a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar
126b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainarunsigned rsr() {
127b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar  // CHECK: [[V0:[%A-Za-z0-9.]+]] = {{.*}} call i32 @llvm.read_register.i32(metadata !7)
128b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar  // CHECK-NEXT: ret i32 [[V0]]
129b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar  return __builtin_arm_rsr("cp1:2:c3:c4:5");
130b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar}
131b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar
132b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainarunsigned long long rsr64() {
133b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar  // CHECK: [[V0:[%A-Za-z0-9.]+]] = {{.*}} call i64 @llvm.read_register.i64(metadata !8)
134b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar  // CHECK-NEXT: ret i64 [[V0]]
135b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar  return __builtin_arm_rsr64("cp1:2:c3");
136b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar}
137b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar
138b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainarvoid *rsrp() {
139b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar  // CHECK: [[V0:[%A-Za-z0-9.]+]] = {{.*}} call i32 @llvm.read_register.i32(metadata !9)
140b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar  // CHECK-NEXT: [[V1:[%A-Za-z0-9.]+]] = inttoptr i32 [[V0]] to i8*
141b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar  // CHECK-NEXT: ret i8* [[V1]]
142b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar  return __builtin_arm_rsrp("sysreg");
143b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar}
144b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar
145b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainarvoid wsr(unsigned v) {
146b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar  // CHECK: call void @llvm.write_register.i32(metadata !7, i32 %v)
147b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar  __builtin_arm_wsr("cp1:2:c3:c4:5", v);
148b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar}
149b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar
150b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainarvoid wsr64(unsigned long long v) {
151b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar  // CHECK: call void @llvm.write_register.i64(metadata !8, i64 %v)
152b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar  __builtin_arm_wsr64("cp1:2:c3", v);
153b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar}
154b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar
155b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainarvoid wsrp(void *v) {
156b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar  // CHECK: [[V0:[%A-Za-z0-9.]+]] = ptrtoint i8* %v to i32
157b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar  // CHECK-NEXT: call void @llvm.write_register.i32(metadata !9, i32 [[V0]])
158b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar  __builtin_arm_wsrp("sysreg", v);
159b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar}
160b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar
161b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar// CHECK: !7 = !{!"cp1:2:c3:c4:5"}
162b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar// CHECK: !8 = !{!"cp1:2:c3"}
163b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar// CHECK: !9 = !{!"sysreg"}
164