craig.topper created this revision.

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.


https://reviews.llvm.org/D36336

Files:
  include/clang/Basic/BuiltinsX86.def
  lib/CodeGen/CGBuiltin.cpp
  test/CodeGen/builtin-cpu-supports.c


Index: test/CodeGen/builtin-cpu-supports.c
===================================================================
--- test/CodeGen/builtin-cpu-supports.c
+++ 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");
 
Index: lib/CodeGen/CGBuiltin.cpp
===================================================================
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -7289,6 +7289,13 @@
 
 Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned BuiltinID,
                                            const CallExpr *E) {
+  if (BuiltinID == 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);
+  }
+
   SmallVector<Value*, 4> Ops;
 
   // Find out if any arguments are required to be integer constant expressions.
Index: include/clang/Basic/BuiltinsX86.def
===================================================================
--- include/clang/Basic/BuiltinsX86.def
+++ 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")
 
 // Undefined Values


Index: test/CodeGen/builtin-cpu-supports.c
===================================================================
--- test/CodeGen/builtin-cpu-supports.c
+++ 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");
 
Index: lib/CodeGen/CGBuiltin.cpp
===================================================================
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -7289,6 +7289,13 @@
 
 Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned BuiltinID,
                                            const CallExpr *E) {
+  if (BuiltinID == 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);
+  }
+
   SmallVector<Value*, 4> Ops;
 
   // Find out if any arguments are required to be integer constant expressions.
Index: include/clang/Basic/BuiltinsX86.def
===================================================================
--- include/clang/Basic/BuiltinsX86.def
+++ 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")
 
 // Undefined Values
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to