r246510 - [PowerPC] Support __builtin_ppc_get_timebase

Hal Finkel via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 31 16:55:19 PDT 2015


Author: hfinkel
Date: Mon Aug 31 18:55:19 2015
New Revision: 246510

URL: http://llvm.org/viewvc/llvm-project?rev=246510&view=rev
Log:
[PowerPC] Support __builtin_ppc_get_timebase

GCC 4.8+ has a PowerPC-specific intrinsic, __builtin_ppc_get_timebase, to do
what Clang's __builtin_readcyclecounter does. For compatibility with code that
uses GCC's spelling (including glibc), support it as well.

Partially fixes PR23681.

Modified:
    cfe/trunk/include/clang/Basic/BuiltinsPPC.def
    cfe/trunk/lib/CodeGen/CGBuiltin.cpp
    cfe/trunk/test/CodeGen/builtins-ppc.c

Modified: cfe/trunk/include/clang/Basic/BuiltinsPPC.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsPPC.def?rev=246510&r1=246509&r2=246510&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/BuiltinsPPC.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsPPC.def Mon Aug 31 18:55:19 2015
@@ -17,6 +17,8 @@
 
 // The format of this database matches clang/Basic/Builtins.def.
 
+BUILTIN(__builtin_ppc_get_timebase, "ULLi", "n")
+
 // This is just a placeholder, the types and attributes are wrong.
 BUILTIN(__builtin_altivec_vaddcuw, "V4UiV4UiV4Ui", "")
 

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=246510&r1=246509&r2=246510&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Mon Aug 31 18:55:19 2015
@@ -6414,6 +6414,11 @@ Value *CodeGenFunction::EmitPPCBuiltinEx
   switch (BuiltinID) {
   default: return nullptr;
 
+  // __builtin_ppc_get_timebase is GCC 4.8+'s PowerPC-specific name for what we
+  // call __builtin_readcyclecounter.
+  case PPC::BI__builtin_ppc_get_timebase:
+    return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::readcyclecounter));
+
   // vec_ld, vec_lvsl, vec_lvsr
   case PPC::BI__builtin_altivec_lvx:
   case PPC::BI__builtin_altivec_lvxl:

Modified: cfe/trunk/test/CodeGen/builtins-ppc.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtins-ppc.c?rev=246510&r1=246509&r2=246510&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/builtins-ppc.c (original)
+++ cfe/trunk/test/CodeGen/builtins-ppc.c Mon Aug 31 18:55:19 2015
@@ -7,3 +7,10 @@ void test_eh_return_data_regno()
   res = __builtin_eh_return_data_regno(0);  // CHECK: store volatile i32 3
   res = __builtin_eh_return_data_regno(1);  // CHECK: store volatile i32 4
 }
+
+// CHECK-LABEL: define i64 @test_builtin_ppc_get_timebase
+long long test_builtin_ppc_get_timebase() {
+  // CHECK: call i64 @llvm.readcyclecounter()
+  return __builtin_ppc_get_timebase();
+}
+




More information about the cfe-commits mailing list