Skip to content

Commit e1331b2

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

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
lines changed

clang/include/clang/Basic/BuiltinsX86.def

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,14 @@ TARGET_BUILTIN(__builtin_ia32_writeeflags_u32, "vUi", "n", "")
4242
// All MMX instructions will be generated via builtins. Any MMX vector
4343
// types (<1 x i64>, <2 x i32>, etc.) that aren't used by these builtins will be
4444
// expanded by the back-end.
45+
//
4546
// FIXME: _mm_prefetch must be a built-in because it takes a compile-time constant
4647
// argument and our prior approach of using a #define to the current built-in
4748
// doesn't work in the presence of re-declaration of _mm_prefetch for windows.
48-
TARGET_BUILTIN(_mm_prefetch, "vcC*i", "nc", "mmx")
49+
TARGET_HEADER_BUILTIN(_mm_prefetch, "vcC*i", "nc", IMMINTRIN_H, ALL_LANGUAGES, "mmx")
50+
TARGET_HEADER_BUILTIN(_m_prefetch, "vv*", "nc", INTRIN_H, ALL_LANGUAGES, "")
51+
TARGET_HEADER_BUILTIN(_m_prefetchw, "vvDC*", "nc", INTRIN_H, ALL_LANGUAGES, "")
52+
4953
TARGET_BUILTIN(__builtin_ia32_emms, "v", "n", "mmx")
5054
TARGET_BUILTIN(__builtin_ia32_vec_ext_v4hi, "sV4sIi", "ncV:64:", "sse")
5155
TARGET_BUILTIN(__builtin_ia32_vec_set_v4hi, "V4sV4ssIi", "ncV:64:", "sse")

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14700,6 +14700,16 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned BuiltinID,
1470014700
Function *F = CGM.getIntrinsic(Intrinsic::prefetch, Address->getType());
1470114701
return Builder.CreateCall(F, {Address, RW, Locality, Data});
1470214702
}
14703+
case X86::BI_m_prefetch:
14704+
case X86::BI_m_prefetchw: {
14705+
Value *Address = Ops[0];
14706+
// The 'w' suffix implies write.
14707+
Value *RW = ConstantInt::get(Int32Ty, BuiltinID == X86::BI_m_prefetchw ? 1 : 0);
14708+
Value *Locality = ConstantInt::get(Int32Ty, 0x3);
14709+
Value *Data = ConstantInt::get(Int32Ty, 1);
14710+
Function *F = CGM.getIntrinsic(Intrinsic::prefetch, Address->getType());
14711+
return Builder.CreateCall(F, {Address, RW, Locality, Data});
14712+
}
1470314713
case X86::BI_mm_clflush: {
1470414714
return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_sse2_clflush),
1470514715
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)