<div dir="ltr">What about __cpuidex?<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Apr 17, 2013 at 11:40 PM, Peter Collingbourne <span dir="ltr"><<a href="mailto:peter@pcc.me.uk" target="_blank">peter@pcc.me.uk</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi rnk,<br>
<br>
<a href="http://llvm-reviews.chandlerc.com/D686" target="_blank">http://llvm-reviews.chandlerc.com/D686</a><br>
<br>
Files:<br>
include/clang/Basic/Builtins.def<br>
lib/CodeGen/CGBuiltin.cpp<br>
test/CodeGen/builtin-ms-cpuid.c<br>
<br>
Index: include/clang/Basic/Builtins.def<br>
===================================================================<br>
--- include/clang/Basic/Builtins.def<br>
+++ include/clang/Basic/Builtins.def<br>
@@ -668,6 +668,7 @@<br>
<br>
// Microsoft builtins.<br>
BUILTIN(__assume, "vb", "n")<br>
+BUILTIN(__cpuid, "vi*i", "n")<br>
BUILTIN(__noop, "v.", "n")<br>
BUILTIN(__debugbreak, "v", "n")<br>
<br>
Index: lib/CodeGen/CGBuiltin.cpp<br>
===================================================================<br>
--- lib/CodeGen/CGBuiltin.cpp<br>
+++ lib/CodeGen/CGBuiltin.cpp<br>
@@ -20,6 +20,7 @@<br>
#include "clang/Basic/TargetBuiltins.h"<br>
#include "clang/Basic/TargetInfo.h"<br>
#include "llvm/IR/DataLayout.h"<br>
+#include "llvm/IR/InlineAsm.h"<br>
#include "llvm/IR/Intrinsics.h"<br>
<br>
using namespace clang;<br>
@@ -1412,6 +1413,30 @@<br>
}<br>
case Builtin::BI__noop:<br>
return RValue::get(0);<br>
+<br>
+ case Builtin::BI__cpuid: {<br>
+ llvm::Type *Int32 = Builder.getInt32Ty();<br>
+ llvm::Type *Int32x4Elems[] = { Int32, Int32, Int32, Int32 };<br>
+ llvm::StructType *Int32x4 =<br>
+ llvm::StructType::get(getLLVMContext(),<br>
+ llvm::ArrayRef<llvm::Type *>(Int32x4Elems));<br>
+ llvm::FunctionType *CPUIDFunctionTy =<br>
+ llvm::FunctionType::get(Int32x4, Int32, false);<br>
+ llvm::InlineAsm *CPUIDAsm =<br>
+ llvm::InlineAsm::get(CPUIDFunctionTy,<br>
+ "cpuid", "={ax},={bx},={cx},={dx},{ax}",<br>
+ /*hasSideEffects=*/false);<br>
+<br>
+ llvm::Value *ResultPtr = EmitScalarExpr(E->getArg(0));<br>
+ llvm::Value *Result =<br>
+ Builder.CreateCall(CPUIDAsm, EmitScalarExpr(E->getArg(1)));<br>
+ for (unsigned i = 0; i != 4; ++i) {<br>
+ llvm::Value *ResultElem = Builder.CreateExtractValue(Result, i);<br>
+ llvm::Value *ResultElemPtr = Builder.CreateConstGEP1_32(ResultPtr, i);<br>
+ Builder.CreateStore(ResultElem, ResultElemPtr);<br>
+ }<br>
+ return RValue::get(0);<br>
+ }<br>
}<br>
<br>
// If this is an alias for a lib function (e.g. __builtin_sin), emit<br>
Index: test/CodeGen/builtin-ms-cpuid.c<br>
===================================================================<br>
--- /dev/null<br>
+++ test/CodeGen/builtin-ms-cpuid.c<br>
@@ -0,0 +1,11 @@<br>
+// RUN: %clang_cc1 -triple i686-pc-win32 -emit-llvm %s -o - -O | FileCheck %s<br>
+<br>
+int cid0(int eax) {<br>
+ // CHECK: @cid0<br>
+ // CHECK: asm "cpuid"<br>
+ // CHECK-NEXT: extractvalue<br>
+ // CHECK-NEXT: ret<br>
+ int r[4];<br>
+ __cpuid(r, eax);<br>
+ return r[0];<br>
+}<br>
<br>_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>~Craig
</div>