[cfe-commits] r161310 - in /cfe/trunk: docs/LanguageExtensions.html include/clang/Basic/Builtins.def lib/CodeGen/CGBuiltin.cpp test/CodeGen/builtins.c
Hal Finkel
hfinkel at anl.gov
Sun Aug 5 15:03:08 PDT 2012
Author: hfinkel
Date: Sun Aug 5 17:03:08 2012
New Revision: 161310
URL: http://llvm.org/viewvc/llvm-project?rev=161310&view=rev
Log:
Add __builtin_readcyclecounter() to produce the @llvm.readcyclecounter() intrinsic.
Modified:
cfe/trunk/docs/LanguageExtensions.html
cfe/trunk/include/clang/Basic/Builtins.def
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/test/CodeGen/builtins.c
Modified: cfe/trunk/docs/LanguageExtensions.html
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LanguageExtensions.html?rev=161310&r1=161309&r2=161310&view=diff
==============================================================================
--- cfe/trunk/docs/LanguageExtensions.html (original)
+++ cfe/trunk/docs/LanguageExtensions.html Sun Aug 5 17:03:08 2012
@@ -98,6 +98,7 @@
<li><a href="#complex-list-init">Initializer lists for complex numbers in C</a></li>
<li><a href="#builtins">Builtin Functions</a>
<ul>
+ <li><a href="#__builtin_readcyclecounter">__builtin_readcyclecounter</a></li>
<li><a href="#__builtin_shufflevector">__builtin_shufflevector</a></li>
<li><a href="#__builtin_unreachable">__builtin_unreachable</a></li>
<li><a href="#__sync_swap">__sync_swap</a></li>
@@ -1367,6 +1368,42 @@
builtins that we need to implement.</p>
<!-- ======================================================================= -->
+<h3><a name="__builtin_readcyclecounter">__builtin_readcyclecounter</a></h3>
+<!-- ======================================================================= -->
+
+<p><tt>__builtin_readcyclecounter</tt> is used to access the cycle counter
+register (or a similar low-latency, high-accuracy clock) on those targets that
+support it.
+</p>
+
+<p><b>Syntax:</b></p>
+
+<pre>
+__builtin_readcyclecounter()
+</pre>
+
+<p><b>Example of Use:</b></p>
+
+<pre>
+unsigned long long t0 = __builtin_readcyclecounter();
+do_something();
+unsigned long long t1 = __builtin_readcyclecounter();
+unsigned long long cycles_to_do_something = t1 - t0; // assuming no overflow
+</pre>
+
+<p><b>Description:</b></p>
+
+<p>The __builtin_readcyclecounter() builtin returns the cycle counter value,
+which may be either global or process/thread-specific depending on the target.
+As the backing counters often overflow quickly (on the order of
+seconds) this should only be used for timing small intervals. When not
+supported by the target, the return value is always zero. This builtin
+takes no arguments and produces an unsigned long long result.
+</p>
+
+<p>Query for this feature with __has_builtin(__builtin_readcyclecounter).</p>
+
+<!-- ======================================================================= -->
<h3><a name="__builtin_shufflevector">__builtin_shufflevector</a></h3>
<!-- ======================================================================= -->
Modified: cfe/trunk/include/clang/Basic/Builtins.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Builtins.def?rev=161310&r1=161309&r2=161310&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Builtins.def (original)
+++ cfe/trunk/include/clang/Basic/Builtins.def Sun Aug 5 17:03:08 2012
@@ -476,6 +476,7 @@
BUILTIN(__builtin_expect, "LiLiLi" , "nc")
BUILTIN(__builtin_prefetch, "vvC*.", "nc")
+BUILTIN(__builtin_readcyclecounter, "ULLi", "n")
BUILTIN(__builtin_trap, "v", "nr")
BUILTIN(__builtin_unreachable, "v", "nr")
BUILTIN(__builtin_shufflevector, "v." , "nc")
Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=161310&r1=161309&r2=161310&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Sun Aug 5 17:03:08 2012
@@ -365,6 +365,10 @@
Value *F = CGM.getIntrinsic(Intrinsic::prefetch);
return RValue::get(Builder.CreateCall4(F, Address, RW, Locality, Data));
}
+ case Builtin::BI__builtin_readcyclecounter: {
+ Value *F = CGM.getIntrinsic(Intrinsic::readcyclecounter);
+ return RValue::get(Builder.CreateCall(F));
+ }
case Builtin::BI__builtin_trap: {
Value *F = CGM.getIntrinsic(Intrinsic::trap);
return RValue::get(Builder.CreateCall(F));
Modified: cfe/trunk/test/CodeGen/builtins.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtins.c?rev=161310&r1=161309&r2=161310&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/builtins.c (original)
+++ cfe/trunk/test/CodeGen/builtins.c Sun Aug 5 17:03:08 2012
@@ -203,3 +203,9 @@
__builtin_longjmp(buffer, 1);
// CHECK-NEXT: unreachable
}
+
+// CHECK: define i64 @test_builtin_readcyclecounter
+long long test_builtin_readcyclecounter() {
+ // CHECK: call i64 @llvm.readcyclecounter()
+ return __builtin_readcyclecounter();
+}
More information about the cfe-commits
mailing list