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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@212196 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Saleem Abdulrasool 2014-07-02 17:41:27 +00:00
parent d2aaf2f173
commit 38b6a39b0e
6 changed files with 64 additions and 14 deletions

View File

@ -14,6 +14,10 @@
// 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

View 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);
}

View 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"

View 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;

View 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)

View 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() {