forked from OSchip/llvm-project
Implement MS read/write barriers and __faststorefence intrinsic
Reviewers: hans, rnk, majnemer Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D25442 llvm-svn: 283793
This commit is contained in:
parent
f9ff04c56a
commit
fcea61c563
clang
include/clang/Basic
lib
test/CodeGen
|
@ -2071,6 +2071,10 @@ TARGET_BUILTIN(__builtin_ia32_selectpd_512, "V8dUcV8dV8d", "", "")
|
||||||
TARGET_BUILTIN(__builtin_ia32_monitorx, "vv*UiUi", "", "mwaitx")
|
TARGET_BUILTIN(__builtin_ia32_monitorx, "vv*UiUi", "", "mwaitx")
|
||||||
TARGET_BUILTIN(__builtin_ia32_mwaitx, "vUiUiUi", "", "mwaitx")
|
TARGET_BUILTIN(__builtin_ia32_mwaitx, "vUiUiUi", "", "mwaitx")
|
||||||
|
|
||||||
|
TARGET_HEADER_BUILTIN(_ReadWriteBarrier, "v", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
|
||||||
|
TARGET_HEADER_BUILTIN(_ReadBarrier, "v", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
|
||||||
|
TARGET_HEADER_BUILTIN(_WriteBarrier, "v", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
|
||||||
|
|
||||||
TARGET_HEADER_BUILTIN(__emul, "LLiii", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
|
TARGET_HEADER_BUILTIN(__emul, "LLiii", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
|
||||||
TARGET_HEADER_BUILTIN(__emulu, "ULLiUiUi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
|
TARGET_HEADER_BUILTIN(__emulu, "ULLiUiUi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
|
||||||
|
|
||||||
|
|
|
@ -23,5 +23,8 @@ TARGET_HEADER_BUILTIN(__umulh, "ULLiULLiULLi", "nch", "intrin.h", ALL_MS_LANGUAG
|
||||||
TARGET_HEADER_BUILTIN(_mul128, "LLiLLiLLiLLi*", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
|
TARGET_HEADER_BUILTIN(_mul128, "LLiLLiLLiLLi*", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
|
||||||
TARGET_HEADER_BUILTIN(_umul128, "ULLiULLiULLiULLi*", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
|
TARGET_HEADER_BUILTIN(_umul128, "ULLiULLiULLiULLi*", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
|
||||||
|
|
||||||
|
TARGET_HEADER_BUILTIN(__faststorefence, "v", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
|
||||||
|
|
||||||
|
|
||||||
#undef BUILTIN
|
#undef BUILTIN
|
||||||
#undef TARGET_HEADER_BUILTIN
|
#undef TARGET_HEADER_BUILTIN
|
||||||
|
|
|
@ -7612,6 +7612,17 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned BuiltinID,
|
||||||
Builder.CreateStore(HigherBits, HighBitsAddress);
|
Builder.CreateStore(HigherBits, HighBitsAddress);
|
||||||
return Builder.CreateIntCast(MulResult, ResType, IsSigned);
|
return Builder.CreateIntCast(MulResult, ResType, IsSigned);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case X86::BI__faststorefence: {
|
||||||
|
return Builder.CreateFence(llvm::AtomicOrdering::SequentiallyConsistent,
|
||||||
|
llvm::CrossThread);
|
||||||
|
}
|
||||||
|
case X86::BI_ReadWriteBarrier:
|
||||||
|
case X86::BI_ReadBarrier:
|
||||||
|
case X86::BI_WriteBarrier: {
|
||||||
|
return Builder.CreateFence(llvm::AtomicOrdering::SequentiallyConsistent,
|
||||||
|
llvm::SingleThread);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -256,10 +256,12 @@ static __inline__
|
||||||
unsigned long __cdecl _lrotl(unsigned long, int);
|
unsigned long __cdecl _lrotl(unsigned long, int);
|
||||||
static __inline__
|
static __inline__
|
||||||
unsigned long __cdecl _lrotr(unsigned long, int);
|
unsigned long __cdecl _lrotr(unsigned long, int);
|
||||||
static __inline__
|
static __inline__ void
|
||||||
void _ReadBarrier(void);
|
__attribute__((__deprecated__("use other intrinsics or C++11 atomics instead")))
|
||||||
static __inline__
|
_ReadBarrier(void);
|
||||||
void _ReadWriteBarrier(void);
|
static __inline__ void
|
||||||
|
__attribute__((__deprecated__("use other intrinsics or C++11 atomics instead")))
|
||||||
|
_ReadWriteBarrier(void);
|
||||||
static __inline__
|
static __inline__
|
||||||
void *_ReturnAddress(void);
|
void *_ReturnAddress(void);
|
||||||
unsigned int _rorx_u32(unsigned int, const unsigned int);
|
unsigned int _rorx_u32(unsigned int, const unsigned int);
|
||||||
|
@ -288,8 +290,9 @@ unsigned int _shrx_u32(unsigned int, unsigned int);
|
||||||
void _Store_HLERelease(long volatile *, long);
|
void _Store_HLERelease(long volatile *, long);
|
||||||
void _Store64_HLERelease(__int64 volatile *, __int64);
|
void _Store64_HLERelease(__int64 volatile *, __int64);
|
||||||
void _StorePointer_HLERelease(void *volatile *, void *);
|
void _StorePointer_HLERelease(void *volatile *, void *);
|
||||||
static __inline__
|
static __inline__ void
|
||||||
void _WriteBarrier(void);
|
__attribute__((__deprecated__("use other intrinsics or C++11 atomics instead")))
|
||||||
|
_WriteBarrier(void);
|
||||||
unsigned __int32 xbegin(void);
|
unsigned __int32 xbegin(void);
|
||||||
void _xend(void);
|
void _xend(void);
|
||||||
static __inline__
|
static __inline__
|
||||||
|
@ -1045,30 +1048,6 @@ _InterlockedCompareExchange64_rel(__int64 volatile *_Destination,
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
/*----------------------------------------------------------------------------*\
|
/*----------------------------------------------------------------------------*\
|
||||||
|* Barriers
|
|
||||||
\*----------------------------------------------------------------------------*/
|
|
||||||
static __inline__ void __DEFAULT_FN_ATTRS
|
|
||||||
__attribute__((__deprecated__("use other intrinsics or C++11 atomics instead")))
|
|
||||||
_ReadWriteBarrier(void) {
|
|
||||||
__atomic_signal_fence(__ATOMIC_SEQ_CST);
|
|
||||||
}
|
|
||||||
static __inline__ void __DEFAULT_FN_ATTRS
|
|
||||||
__attribute__((__deprecated__("use other intrinsics or C++11 atomics instead")))
|
|
||||||
_ReadBarrier(void) {
|
|
||||||
__atomic_signal_fence(__ATOMIC_SEQ_CST);
|
|
||||||
}
|
|
||||||
static __inline__ void __DEFAULT_FN_ATTRS
|
|
||||||
__attribute__((__deprecated__("use other intrinsics or C++11 atomics instead")))
|
|
||||||
_WriteBarrier(void) {
|
|
||||||
__atomic_signal_fence(__ATOMIC_SEQ_CST);
|
|
||||||
}
|
|
||||||
#ifdef __x86_64__
|
|
||||||
static __inline__ void __DEFAULT_FN_ATTRS
|
|
||||||
__faststorefence(void) {
|
|
||||||
__atomic_thread_fence(__ATOMIC_SEQ_CST);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
/*----------------------------------------------------------------------------*\
|
|
||||||
|* readfs, readgs
|
|* readfs, readgs
|
||||||
|* (Pointers in address space #256 and #257 are relative to the GS and FS
|
|* (Pointers in address space #256 and #257 are relative to the GS and FS
|
||||||
|* segment registers, respectively.)
|
|* segment registers, respectively.)
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
// RUN: %clang_cc1 -ffreestanding -fms-extensions -fms-compatibility -fms-compatibility-version=17.00 \
|
||||||
|
// RUN: -triple i686--windows -emit-llvm %s -o - \
|
||||||
|
// RUN: | FileCheck %s -check-prefix=CHECK -check-prefix=CHECK-I386
|
||||||
|
// RUN: %clang_cc1 -ffreestanding -fms-extensions -fms-compatibility -fms-compatibility-version=17.00 \
|
||||||
|
// RUN: -triple x86_64--windows -emit-llvm %s -o - \
|
||||||
|
// RUN: | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-X64
|
||||||
|
|
||||||
|
// intrin.h needs size_t, but -ffreestanding prevents us from getting it from
|
||||||
|
// stddef.h. Work around it with this typedef.
|
||||||
|
typedef __SIZE_TYPE__ size_t;
|
||||||
|
|
||||||
|
#include <intrin.h>
|
||||||
|
|
||||||
|
void test_ReadWriteBarrier() { _ReadWriteBarrier(); }
|
||||||
|
// CHECK-LABEL: define void @test_ReadWriteBarrier
|
||||||
|
// CHECK: fence singlethread seq_cst
|
||||||
|
// CHECK: ret void
|
||||||
|
// CHECK: }
|
||||||
|
|
||||||
|
void test_ReadBarrier() { _ReadBarrier(); }
|
||||||
|
// CHECK-LABEL: define void @test_ReadBarrier
|
||||||
|
// CHECK: fence singlethread seq_cst
|
||||||
|
// CHECK: ret void
|
||||||
|
// CHECK: }
|
||||||
|
|
||||||
|
void test_WriteBarrier() { _WriteBarrier(); }
|
||||||
|
// CHECK-LABEL: define void @test_WriteBarrier
|
||||||
|
// CHECK: fence singlethread seq_cst
|
||||||
|
// CHECK: ret void
|
||||||
|
// CHECK: }
|
||||||
|
|
||||||
|
#if defined(__x86_64__)
|
||||||
|
void test__faststorefence() { __faststorefence(); }
|
||||||
|
// CHECK-X64-LABEL: define void @test__faststorefence
|
||||||
|
// CHECK-X64: fence seq_cst
|
||||||
|
// CHECK-X64: ret void
|
||||||
|
// CHECK-X64: }
|
||||||
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue