]> granicus.if.org Git - clang/commitdiff
CodeGen: make target builtins support languages
authorSaleem Abdulrasool <compnerd@compnerd.org>
Wed, 2 Jul 2014 17:41:27 +0000 (17:41 +0000)
committerSaleem Abdulrasool <compnerd@compnerd.org>
Wed, 2 Jul 2014 17:41:27 +0000 (17:41 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@212196 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/BuiltinsARM.def
lib/Basic/Builtins.cpp
lib/Basic/Targets.cpp
lib/CodeGen/CGBuiltin.cpp
test/CodeGen/builtins-arm-microsoft.c
test/CodeGen/builtins-arm.c

index bc8186f96a65f23f5b06ffaf98816cc3042a41e4..2197f5902e4c0ada0e96d729e7d32d9e812767d9 100644 (file)
 
 // The format of this database matches clang/Basic/Builtins.def.
 
+#if defined(BUILTIN) && !defined(LANGBUILTIN)
+#   define LANGBUILTIN(ID, TYPE, ATTRS, BUILTIN_LANG) BUILTIN(ID, TYPE, ATTRS)
+#endif
+
 // In libgcc
 BUILTIN(__clear_cache, "vv*v*", "i")
 BUILTIN(__builtin_thread_pointer, "v*", "")
@@ -64,14 +68,22 @@ BUILTIN(__builtin_arm_crc32d, "UiUiLLUi", "nc")
 BUILTIN(__builtin_arm_crc32cd, "UiUiLLUi", "nc")
 
 // HINT
-BUILTIN(__yield, "v", "")
-BUILTIN(__wfe, "v", "")
-BUILTIN(__wfi, "v", "")
-BUILTIN(__sev, "v", "")
-BUILTIN(__sevl, "v", "")
+BUILTIN(__builtin_yield, "v", "")
+BUILTIN(__builtin_wfe, "v", "")
+BUILTIN(__builtin_wfi, "v", "")
+BUILTIN(__builtin_sev, "v", "")
+BUILTIN(__builtin_sevl, "v", "")
 
 // Data barrier
 BUILTIN(__builtin_arm_dmb, "vUi", "nc")
 BUILTIN(__builtin_arm_dsb, "vUi", "nc")
 
+// MSVC
+LANGBUILTIN(__yield, "v", "", ALL_MS_LANGUAGES)
+LANGBUILTIN(__wfe, "v", "", ALL_MS_LANGUAGES)
+LANGBUILTIN(__wfi, "v", "", ALL_MS_LANGUAGES)
+LANGBUILTIN(__sev, "v", "", ALL_MS_LANGUAGES)
+LANGBUILTIN(__sevl, "v", "", ALL_MS_LANGUAGES)
+
 #undef BUILTIN
+#undef LANGBUILTIN
index 6c78dc359405f07f03d945ac591750f2a9936b17..8efcac6d7fe4dfb8e7e475b50df6ced010aaef69 100644 (file)
@@ -76,7 +76,7 @@ void Builtin::Context::InitializeBuiltins(IdentifierTable &Table,
 
   // Step #2: Register target-specific builtins.
   for (unsigned i = 0, e = NumTSRecords; i != e; ++i)
-    if (!LangOpts.NoBuiltin || !strchr(TSRecords[i].Attributes, 'f'))
+    if (BuiltinIsSupported(TSRecords[i], LangOpts))
       Table.get(TSRecords[i].Name).setBuiltinID(i+Builtin::FirstTSBuiltin);
 }
 
index b0dc3356386820ea618d98680bbef34e6fa76969..424ce6c54d6932fa36c8763dc07616208bbdd03b 100644 (file)
@@ -4170,6 +4170,7 @@ const Builtin::Info ARMTargetInfo::BuiltinInfo[] = {
 #include "clang/Basic/BuiltinsNEON.def"
 
 #define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES },
+#define LANGBUILTIN(ID, TYPE, ATTRS, LANG) { #ID, TYPE, ATTRS, 0, LANG },
 #define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\
                                               ALL_LANGUAGES },
 #include "clang/Basic/BuiltinsARM.def"
index fb71d1d830b10fc1dc1e152a01e6181b2c05cc61..ce53f0ad4b8cf26f4753ccbaca93ba83ab4da00f 100644 (file)
@@ -3033,18 +3033,23 @@ Value *CodeGenFunction::EmitARMBuiltinExpr(unsigned BuiltinID,
   unsigned HintID = static_cast<unsigned>(-1);
   switch (BuiltinID) {
   default: break;
+  case ARM::BI__builtin_yield:
   case ARM::BI__yield:
     HintID = 1;
     break;
+  case ARM::BI__builtin_wfe:
   case ARM::BI__wfe:
     HintID = 2;
     break;
+  case ARM::BI__builtin_wfi:
   case ARM::BI__wfi:
     HintID = 3;
     break;
+  case ARM::BI__builtin_sev:
   case ARM::BI__sev:
     HintID = 4;
     break;
+  case ARM::BI__builtin_sevl:
   case ARM::BI__sevl:
     HintID = 5;
     break;
index 682ec916a8ac4af9f9d954bf43895fab97ef5f32..6f7b3ea86e75ab8ea37ec43550d713e481ee811f 100644 (file)
@@ -1,10 +1,41 @@
-// RUN: %clang_cc1 -triple thumbv7-windows -emit-llvm -o - %s | FileCheck %s
-// RUN: %clang_cc1 -triple armv7-eabi -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple thumbv7-windows -fms-compatibility -emit-llvm -o - %s \
+// RUN:     | FileCheck %s -check-prefix CHECK-MSVC
+// RUN: %clang_cc1 -triple armv7-eabi -emit-llvm %s -o - \
+// RUN:     | FileCheck %s -check-prefix CHECK-EABI
 // REQUIRES: arm-registered-target
 
 void test_yield_intrinsic() {
   __yield();
 }
 
-// CHECK: call void @llvm.arm.hint(i32 1)
+// CHECK-MSVC: call void @llvm.arm.hint(i32 1)
+// CHECK-EABI-NOT: call void @llvm.arm.hint(i32 1)
+
+void wfe() {
+  __wfe();
+}
+
+// CHECK-MSVC: call {{.*}} @llvm.arm.hint(i32 2)
+// CHECK-EABI-NOT: call {{.*}} @llvm.arm.hint(i32 2)
+
+void wfi() {
+  __wfi();
+}
+
+// CHECK-MSVC: call {{.*}} @llvm.arm.hint(i32 3)
+// CHECK-EABI-NOT: call {{.*}} @llvm.arm.hint(i32 3)
+
+void sev() {
+  __sev();
+}
+
+// CHECK-MSVC: call {{.*}} @llvm.arm.hint(i32 4)
+// CHECK-EABI-NOT: call {{.*}} @llvm.arm.hint(i32 4)
+
+void sevl() {
+  __sevl();
+}
+
+// CHECK-MSVC: call {{.*}} @llvm.arm.hint(i32 5)
+// CHECK-EABI-NOT: call {{.*}} @llvm.arm.hint(i32 5)
 
index 13ffc607849dfb86d8a087cf705620745da14464..1d22bd595dfabac8ae84e0feb78543e2444cd8e6 100644 (file)
@@ -20,32 +20,33 @@ void test_eh_return_data_regno()
 }
 
 void yield() {
-  __yield();
+  __builtin_yield();
 }
 
 // CHECK: call {{.*}} @llvm.arm.hint(i32 1)
 
 void wfe() {
-  __wfe();
+  __builtin_wfe();
 }
 
 // CHECK: call {{.*}} @llvm.arm.hint(i32 2)
 
 void wfi() {
-  __wfi();
+  __builtin_wfi();
 }
 
 // CHECK: call {{.*}} @llvm.arm.hint(i32 3)
 
 void sev() {
-  __sev();
+  __builtin_sev();
 }
 
 // CHECK: call {{.*}} @llvm.arm.hint(i32 4)
 
 void sevl() {
-  __sevl();
+  __builtin_sevl();
 }
+
 // CHECK: call {{.*}} @llvm.arm.hint(i32 5)
 
 void test_barrier() {