Skip to content

Commit e5f485a

Browse files
committed
[Win/X86] Make _m_prefetch[w] builtins to avoid winnt.h conflicts
1 parent fa4af03 commit e5f485a

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

clang/include/clang/Basic/BuiltinsX86.td

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,15 @@ let Attributes = [Const, NoThrow, RequiredVectorWidth<256>], Features = "avx" in
146146
// current formulation is based on what was easiest to recognize from the
147147
// pre-TableGen version.
148148

149-
let Features = "mmx", Attributes = [NoThrow, Const] in {
149+
let Features = "mmx", Header = "immintrin.h", Attributes = [NoThrow, Const] in {
150150
def _mm_prefetch : X86NoPrefixBuiltin<"void(char const *, int)">;
151151
}
152152

153+
let Features = "mmx", Header = "intrin.h", Attributes = [NoThrow, Const] in {
154+
def _m_prefetch : X86NoPrefixBuiltin<"void(void *)">;
155+
def _m_prefetchw : X86NoPrefixBuiltin<"void(const void *)">;
156+
}
157+
153158
let Features = "sse", Attributes = [NoThrow] in {
154159
def ldmxcsr : X86Builtin<"void(unsigned int)">;
155160
}

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15254,6 +15254,16 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned BuiltinID,
1525415254
Function *F = CGM.getIntrinsic(Intrinsic::prefetch, Address->getType());
1525515255
return Builder.CreateCall(F, {Address, RW, Locality, Data});
1525615256
}
15257+
case X86::BI_m_prefetch:
15258+
case X86::BI_m_prefetchw: {
15259+
Value *Address = Ops[0];
15260+
// The 'w' suffix implies write.
15261+
Value *RW = ConstantInt::get(Int32Ty, BuiltinID == X86::BI_m_prefetchw ? 1 : 0);
15262+
Value *Locality = ConstantInt::get(Int32Ty, 0x3);
15263+
Value *Data = ConstantInt::get(Int32Ty, 1);
15264+
Function *F = CGM.getIntrinsic(Intrinsic::prefetch, Address->getType());
15265+
return Builder.CreateCall(F, {Address, RW, Locality, Data});
15266+
}
1525715267
case X86::BI_mm_clflush: {
1525815268
return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_sse2_clflush),
1525915269
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 */

0 commit comments

Comments
 (0)