[PATCH] Implement MSVC intrinsics for reading from FS and GS segments.
Peter Collingbourne
peter at pcc.me.uk
Wed Apr 17 23:41:02 PDT 2013
Hi rnk,
http://llvm-reviews.chandlerc.com/D687
Files:
include/clang/Basic/Builtins.def
lib/CodeGen/CGBuiltin.cpp
test/CodeGen/builtin-ms-fsgs.c
Index: include/clang/Basic/Builtins.def
===================================================================
--- include/clang/Basic/Builtins.def
+++ include/clang/Basic/Builtins.def
@@ -670,6 +670,14 @@
BUILTIN(__assume, "vb", "n")
BUILTIN(__noop, "v.", "n")
BUILTIN(__debugbreak, "v", "n")
+BUILTIN(__readfsbyte, "UcULi", "n")
+BUILTIN(__readfsword, "UsULi", "n")
+BUILTIN(__readfsdword, "ULiULi", "n")
+BUILTIN(__readfsqword, "ULLiULi", "n")
+BUILTIN(__readgsbyte, "UcULi", "n")
+BUILTIN(__readgsword, "UsULi", "n")
+BUILTIN(__readgsdword, "ULiULi", "n")
+BUILTIN(__readgsqword, "ULLiULi", "n")
// C99 library functions
Index: lib/CodeGen/CGBuiltin.cpp
===================================================================
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -1412,6 +1412,27 @@
}
case Builtin::BI__noop:
return RValue::get(0);
+
+ case Builtin::BI__readfsbyte:
+ case Builtin::BI__readfsword:
+ case Builtin::BI__readfsdword:
+ case Builtin::BI__readfsqword:
+ case Builtin::BI__readgsbyte:
+ case Builtin::BI__readgsword:
+ case Builtin::BI__readgsdword:
+ case Builtin::BI__readgsqword: {
+ unsigned AddrSpace = (BuiltinID == Builtin::BI__readfsbyte ||
+ BuiltinID == Builtin::BI__readfsword ||
+ BuiltinID == Builtin::BI__readfsdword ||
+ BuiltinID == Builtin::BI__readfsqword) ? 257 : 256;
+ llvm::Type *ResultType = ConvertType(E->getType());
+
+ llvm::Value *Addr = EmitScalarExpr(E->getArg(0));
+ llvm::Type *AddrPtrType = llvm::PointerType::get(ResultType, AddrSpace);
+ llvm::Value *AddrPtr = Builder.CreateIntToPtr(Addr, AddrPtrType);
+
+ return RValue::get(Builder.CreateLoad(AddrPtr));
+ }
}
// If this is an alias for a lib function (e.g. __builtin_sin), emit
Index: test/CodeGen/builtin-ms-fsgs.c
===================================================================
--- /dev/null
+++ test/CodeGen/builtin-ms-fsgs.c
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -triple i686-pc-win32 -emit-llvm %s -o - | FileCheck %s
+
+unsigned fsint() {
+ // CHECK: @fsint
+ // CHECK: load i32 addrspace(257)* inttoptr (i32 1 to i32 addrspace(257)*)
+ return __readfsdword(1);
+}
+
+unsigned gsint() {
+ // CHECK: @gsint
+ // CHECK: load i32 addrspace(256)* inttoptr (i32 1 to i32 addrspace(256)*)
+ return __readgsdword(1);
+}
+
+unsigned long fslong(unsigned long x) {
+ // CHECK: @fslong
+ // CHECK: inttoptr i32 {{.*}} to i64 addrspace(257)*
+ // CHECK-NEXT: load i64 addrspace(257)*
+ return __readfsqword(x);
+}
+
+unsigned long gslong(unsigned long x) {
+ // CHECK: @gslong
+ // CHECK: inttoptr i32 {{.*}} to i64 addrspace(256)*
+ // CHECK-NEXT: load i64 addrspace(256)*
+ return __readgsqword(x);
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D687.1.patch
Type: text/x-patch
Size: 2768 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130417/b2e5ac21/attachment.bin>
More information about the cfe-commits
mailing list