]> granicus.if.org Git - clang/commitdiff
[X86] Add support for __builtin_cpu_init
authorCraig Topper <craig.topper@intel.com>
Mon, 28 Aug 2017 05:43:23 +0000 (05:43 +0000)
committerCraig Topper <craig.topper@intel.com>
Mon, 28 Aug 2017 05:43:23 +0000 (05:43 +0000)
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
lib/CodeGen/CGBuiltin.cpp
test/CodeGen/builtin-cpu-supports.c

index af9796e54bdd6313c4b7ae11979d3823f3516bba..f39048c1a56be9aade4d20ae2e8f5ee21d16ae21 100644 (file)
@@ -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")
 
index 585c27c181154633b13dd28b19c5a38cc7a4b225..9ced44b2e0e622ad767601952f689098904f9a59 100644 (file)
@@ -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<Value*, 4> 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<StringLiteral>(FeatureExpr)->getString();
index 96813923f279e75fa3aa3633f3282a0efca74ef8..b70f4aca9d4326a5d6b6b8769dbcbb523b7a64bd 100644 (file)
@@ -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");