Skip to content

Commit 7da648b

Browse files
committed
Reapply "[Win/X86] Make _m_prefetch[w] builtins to avoid winnt.h conflicts (llvm#115099)"
This reverts commit 83ff9d4. Don't change the builtin signature of _mm_prefetch this time.
1 parent 123758b commit 7da648b

File tree

4 files changed

+34
-19
lines changed

4 files changed

+34
-19
lines changed

clang/include/clang/Basic/BuiltinsX86.td

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,12 @@ let Attributes = [Const, NoThrow, RequiredVectorWidth<256>], Features = "avx" in
138138
}
139139
}
140140

141+
// PRFCHW
142+
let Features = "prfchw", Header = "intrin.h", Attributes = [NoThrow, Const] in {
143+
def _m_prefetch : X86LibBuiltin<"void(void *)">;
144+
def _m_prefetchw : X86LibBuiltin<"void(void volatile const *)">;
145+
}
146+
141147

142148
// Mechanically ported builtins from the original `.def` file.
143149
//
@@ -146,8 +152,8 @@ let Attributes = [Const, NoThrow, RequiredVectorWidth<256>], Features = "avx" in
146152
// current formulation is based on what was easiest to recognize from the
147153
// pre-TableGen version.
148154

149-
let Features = "mmx", Attributes = [NoThrow, Const] in {
150-
def _mm_prefetch : X86NoPrefixBuiltin<"void(char const *, int)">;
155+
let Features = "sse", Header = "xmmintrin.h", Attributes = [NoThrow, Const] in {
156+
def _mm_prefetch : X86LibBuiltin<"void(char const *, int)">;
151157
}
152158

153159
let Features = "sse", Attributes = [NoThrow] in {

clang/lib/CodeGen/TargetBuiltins/X86.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,17 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned BuiltinID,
804804
Function *F = CGM.getIntrinsic(Intrinsic::prefetch, Address->getType());
805805
return Builder.CreateCall(F, {Address, RW, Locality, Data});
806806
}
807+
case X86::BI_m_prefetch:
808+
case X86::BI_m_prefetchw: {
809+
Value *Address = Ops[0];
810+
// The 'w' suffix implies write.
811+
Value *RW =
812+
ConstantInt::get(Int32Ty, BuiltinID == X86::BI_m_prefetchw ? 1 : 0);
813+
Value *Locality = ConstantInt::get(Int32Ty, 0x3);
814+
Value *Data = ConstantInt::get(Int32Ty, 1);
815+
Function *F = CGM.getIntrinsic(Intrinsic::prefetch, Address->getType());
816+
return Builder.CreateCall(F, {Address, RW, Locality, Data});
817+
}
807818
case X86::BI_mm_clflush: {
808819
return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_sse2_clflush),
809820
Ops[0]);

clang/lib/Headers/prfchwintrin.h

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
#ifndef __PRFCHWINTRIN_H
1515
#define __PRFCHWINTRIN_H
1616

17+
#if defined(__cplusplus)
18+
extern "C" {
19+
#endif
20+
1721
/// Loads a memory sequence containing the specified memory address into
1822
/// all data cache levels.
1923
///
@@ -26,11 +30,7 @@
2630
///
2731
/// \param __P
2832
/// A pointer specifying the memory address to be prefetched.
29-
static __inline__ void __attribute__((__always_inline__, __nodebug__))
30-
_m_prefetch(void *__P)
31-
{
32-
__builtin_prefetch (__P, 0, 3 /* _MM_HINT_T0 */);
33-
}
33+
void _m_prefetch(void *__P);
3434

3535
/// Loads a memory sequence containing the specified memory address into
3636
/// the L1 data cache and sets the cache-coherency state to modified.
@@ -48,13 +48,10 @@ _m_prefetch(void *__P)
4848
///
4949
/// \param __P
5050
/// A pointer specifying the memory address to be prefetched.
51-
static __inline__ void __attribute__((__always_inline__, __nodebug__))
52-
_m_prefetchw(volatile const void *__P)
53-
{
54-
#pragma clang diagnostic push
55-
#pragma clang diagnostic ignored "-Wcast-qual"
56-
__builtin_prefetch ((const void*)__P, 1, 3 /* _MM_HINT_T0 */);
57-
#pragma clang diagnostic pop
58-
}
51+
void _m_prefetchw(volatile const void *__P);
52+
53+
#if defined(__cplusplus)
54+
} // extern "C"
55+
#endif
5956

6057
#endif /* __PRFCHWINTRIN_H */

clang/lib/Headers/xmmintrin.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2197,10 +2197,7 @@ _mm_storer_ps(float *__p, __m128 __a)
21972197
#define _MM_HINT_T2 1
21982198
#define _MM_HINT_NTA 0
21992199

2200-
#ifndef _MSC_VER
2201-
/* FIXME: We have to #define this because "sel" must be a constant integer, and
2202-
Sema doesn't do any form of constant propagation yet. */
2203-
2200+
#if 0
22042201
/// Loads one cache line of data from the specified address to a location
22052202
/// closer to the processor.
22062203
///
@@ -2225,6 +2222,10 @@ _mm_storer_ps(float *__p, __m128 __a)
22252222
/// be generated. \n
22262223
/// _MM_HINT_T2: Move data using the T2 hint. The PREFETCHT2 instruction will
22272224
/// be generated.
2225+
///
2226+
/// _mm_prefetch is implemented as a "library builtin" directly in Clang,
2227+
/// similar to how it is done in MSVC. Clang will warn if the user doesn't
2228+
/// include xmmintrin.h or immintrin.h.
22282229
#define _mm_prefetch(a, sel) (__builtin_prefetch((const void *)(a), \
22292230
((sel) >> 2) & 1, (sel) & 0x3))
22302231
#endif

0 commit comments

Comments
 (0)