From 86736b95f3e34f044d831247121e39ce6542741f Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Mon, 28 Aug 2017 05:43:23 +0000 Subject: [PATCH] [X86] Add support for __builtin_cpu_init This adds builtin_cpu_init which will emit a call to cpu_indicator_init in libgcc or compiler-rt. This is needed to support builtin_cpu_supports/builtin_cpu_is in an ifunc resolver. Differential Revision: https://reviews.llvm.org/D36336 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@311874 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/BuiltinsX86.def | 1 + lib/CodeGen/CGBuiltin.cpp | 12 +++++++++--- test/CodeGen/builtin-cpu-supports.c | 4 ++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/include/clang/Basic/BuiltinsX86.def b/include/clang/Basic/BuiltinsX86.def index af9796e54b..f39048c1a5 100644 --- a/include/clang/Basic/BuiltinsX86.def +++ b/include/clang/Basic/BuiltinsX86.def @@ -32,6 +32,7 @@ // Miscellaneous builtin for checking x86 cpu features. // TODO: Make this somewhat generic so that other backends // can use it? +BUILTIN(__builtin_cpu_init, "v", "n") BUILTIN(__builtin_cpu_supports, "bcC*", "nc") BUILTIN(__builtin_cpu_is, "bcC*", "nc") diff --git a/lib/CodeGen/CGBuiltin.cpp b/lib/CodeGen/CGBuiltin.cpp index 585c27c181..9ced44b2e0 100644 --- a/lib/CodeGen/CGBuiltin.cpp +++ b/lib/CodeGen/CGBuiltin.cpp @@ -7404,9 +7404,6 @@ static Value *EmitX86CpuIs(CodeGenFunction &CGF, const CallExpr *E) { Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned BuiltinID, const CallExpr *E) { - if (BuiltinID == X86::BI__builtin_cpu_is) - return EmitX86CpuIs(*this, E); - SmallVector Ops; // Find out if any arguments are required to be integer constant expressions. @@ -7457,6 +7454,15 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned BuiltinID, switch (BuiltinID) { default: return nullptr; + case X86::BI__builtin_cpu_init: { + llvm::FunctionType *FTy = llvm::FunctionType::get(VoidTy, + /*Variadic*/false); + llvm::Constant *Func = CGM.CreateRuntimeFunction(FTy, + "__cpu_indicator_init"); + return Builder.CreateCall(Func); + } + case X86::BI__builtin_cpu_is: + return EmitX86CpuIs(*this, E); case X86::BI__builtin_cpu_supports: { const Expr *FeatureExpr = E->getArg(0)->IgnoreParenCasts(); StringRef FeatureStr = cast(FeatureExpr)->getString(); diff --git a/test/CodeGen/builtin-cpu-supports.c b/test/CodeGen/builtin-cpu-supports.c index 96813923f2..b70f4aca9d 100644 --- a/test/CodeGen/builtin-cpu-supports.c +++ b/test/CodeGen/builtin-cpu-supports.c @@ -5,6 +5,10 @@ extern void a(const char *); int main() { + __builtin_cpu_init(); + + // CHECK: call void @__cpu_indicator_init + if (__builtin_cpu_supports("sse4.2")) a("sse4.2"); -- 2.40.0