diff options
| author | Hans Wennborg <hans@hanshq.net> | 2017-03-22 19:13:13 +0000 |
|---|---|---|
| committer | Hans Wennborg <hans@hanshq.net> | 2017-03-22 19:13:13 +0000 |
| commit | 043f40258649bab71af75472e54b9fa08bd1da51 (patch) | |
| tree | 5f92e49c7b0a7615c009d8bd725c0c9ecb371d19 /clang/lib | |
| parent | dc13921fbc19bb9455a582e25bf520ab3eb1b991 (diff) | |
| download | bcm5719-llvm-043f40258649bab71af75472e54b9fa08bd1da51.tar.gz bcm5719-llvm-043f40258649bab71af75472e54b9fa08bd1da51.zip | |
[X86] Implement __readgsqword (and the rest) as builtins (PR32373)
It seems MS headers have started using __readgsqword, and since it's
used in a header that doesn't include intrin.h, we can't implement it as
an inline function anymore.
That was already the case for __readfsdword, which Saleem added support
for in r220859. This patch reuses that codegen to implement all of
__read[fg]s{byte,word,dword,qword}.
Differential Revision: https://reviews.llvm.org/D31248
llvm-svn: 298538
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/CodeGen/CGBuiltin.cpp | 34 | ||||
| -rw-r--r-- | clang/lib/Headers/intrin.h | 43 |
2 files changed, 24 insertions, 53 deletions
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 817589064a3..463dda4213a 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -2238,16 +2238,6 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD, case Builtin::BI_InterlockedXor16: case Builtin::BI_InterlockedXor: return RValue::get(EmitMSVCBuiltinExpr(MSVCIntrin::_InterlockedXor, E)); - case Builtin::BI__readfsdword: { - llvm::Type *IntTy = ConvertType(E->getType()); - Value *IntToPtr = - Builder.CreateIntToPtr(EmitScalarExpr(E->getArg(0)), - llvm::PointerType::get(IntTy, 257)); - LoadInst *Load = Builder.CreateAlignedLoad( - IntTy, IntToPtr, getContext().getTypeAlignInChars(E->getType())); - Load->setVolatile(true); - return RValue::get(Load); - } case Builtin::BI__exception_code: case Builtin::BI_exception_code: @@ -8005,6 +7995,30 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned BuiltinID, CS.setAttributes(NoReturnAttr); return CS.getInstruction(); } + case X86::BI__readfsbyte: + case X86::BI__readfsword: + case X86::BI__readfsdword: + case X86::BI__readfsqword: { + llvm::Type *IntTy = ConvertType(E->getType()); + Value *Ptr = Builder.CreateIntToPtr(EmitScalarExpr(E->getArg(0)), + llvm::PointerType::get(IntTy, 257)); + LoadInst *Load = Builder.CreateAlignedLoad( + IntTy, Ptr, getContext().getTypeAlignInChars(E->getType())); + Load->setVolatile(true); + return Load; + } + case X86::BI__readgsbyte: + case X86::BI__readgsword: + case X86::BI__readgsdword: + case X86::BI__readgsqword: { + llvm::Type *IntTy = ConvertType(E->getType()); + Value *Ptr = Builder.CreateIntToPtr(EmitScalarExpr(E->getArg(0)), + llvm::PointerType::get(IntTy, 256)); + LoadInst *Load = Builder.CreateAlignedLoad( + IntTy, Ptr, getContext().getTypeAlignInChars(E->getType())); + Load->setVolatile(true); + return Load; + } } } diff --git a/clang/lib/Headers/intrin.h b/clang/lib/Headers/intrin.h index af87914a9a0..16028d5c6b0 100644 --- a/clang/lib/Headers/intrin.h +++ b/clang/lib/Headers/intrin.h @@ -869,50 +869,7 @@ _InterlockedCompareExchange64_rel(__int64 volatile *_Destination, return _Comparand; } #endif -/*----------------------------------------------------------------------------*\ -|* readfs, readgs -|* (Pointers in address space #256 and #257 are relative to the GS and FS -|* segment registers, respectively.) -\*----------------------------------------------------------------------------*/ -#define __ptr_to_addr_space(__addr_space_nbr, __type, __offset) \ - ((volatile __type __attribute__((__address_space__(__addr_space_nbr)))*) \ - (__offset)) -#ifdef __i386__ -static __inline__ unsigned char __DEFAULT_FN_ATTRS -__readfsbyte(unsigned long __offset) { - return *__ptr_to_addr_space(257, unsigned char, __offset); -} -static __inline__ unsigned short __DEFAULT_FN_ATTRS -__readfsword(unsigned long __offset) { - return *__ptr_to_addr_space(257, unsigned short, __offset); -} -static __inline__ unsigned __int64 __DEFAULT_FN_ATTRS -__readfsqword(unsigned long __offset) { - return *__ptr_to_addr_space(257, unsigned __int64, __offset); -} -#endif -#ifdef __x86_64__ -static __inline__ unsigned char __DEFAULT_FN_ATTRS -__readgsbyte(unsigned long __offset) { - return *__ptr_to_addr_space(256, unsigned char, (unsigned long long)__offset); -} -static __inline__ unsigned short __DEFAULT_FN_ATTRS -__readgsword(unsigned long __offset) { - return *__ptr_to_addr_space(256, unsigned short, - (unsigned long long)__offset); -} -static __inline__ unsigned long __DEFAULT_FN_ATTRS -__readgsdword(unsigned long __offset) { - return *__ptr_to_addr_space(256, unsigned long, (unsigned long long)__offset); -} -static __inline__ unsigned __int64 __DEFAULT_FN_ATTRS -__readgsqword(unsigned long __offset) { - return *__ptr_to_addr_space(256, unsigned __int64, - (unsigned long long)__offset); -} -#endif -#undef __ptr_to_addr_space /*----------------------------------------------------------------------------*\ |* movs, stos \*----------------------------------------------------------------------------*/ |

