From 74f4eaf4dc6631a59acaabcc52e90206fd0f2f44 Mon Sep 17 00:00:00 2001 From: Michael Liao Date: Tue, 26 Mar 2013 17:52:08 +0000 Subject: [PATCH] Add PRFCHW intrinsic support - Add head 'prfchwintrin.h' to define '_m_prefetchw' which is mapped to LLVM/clang prefetch builtin - Add option '-mprfchw' to enable PRFCHW feature and pre-define '__PRFCHW__' macro llvm-svn: 178041 --- clang/include/clang/Driver/Options.td | 2 ++ clang/lib/Basic/Targets.cpp | 19 ++++++++++++++++-- clang/lib/Headers/CMakeLists.txt | 1 + clang/lib/Headers/mm3dnow.h | 1 + clang/lib/Headers/prfchwintrin.h | 34 +++++++++++++++++++++++++++++++++ clang/lib/Headers/x86intrin.h | 4 ++++ clang/test/CodeGen/prefetchw-builtins.c | 12 ++++++++++++ 7 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 clang/lib/Headers/prfchwintrin.h create mode 100644 clang/test/CodeGen/prefetchw-builtins.c diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 22415ca..c9575c3 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -895,6 +895,7 @@ def mno_fma : Flag<["-"], "mno-fma">, Group; def mno_xop : Flag<["-"], "mno-xop">, Group; def mno_f16c : Flag<["-"], "mno-f16c">, Group; def mno_rtm : Flag<["-"], "mno-rtm">, Group; +def mno_prfchw : Flag<["-"], "mno-prfchw">, Group; def mno_thumb : Flag<["-"], "mno-thumb">, Group; def marm : Flag<["-"], "marm">, Alias; @@ -938,6 +939,7 @@ def mfma : Flag<["-"], "mfma">, Group; def mxop : Flag<["-"], "mxop">, Group; def mf16c : Flag<["-"], "mf16c">, Group; def mrtm : Flag<["-"], "mrtm">, Group; +def mprfchw : Flag<["-"], "mprfchw">, Group; def mips16 : Flag<["-"], "mips16">, Group; def mno_mips16 : Flag<["-"], "mno-mips16">, Group; def mxgot : Flag<["-"], "mxgot">, Group; diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp index b7cd3dc..09d8be6 100644 --- a/clang/lib/Basic/Targets.cpp +++ b/clang/lib/Basic/Targets.cpp @@ -1701,6 +1701,7 @@ class X86TargetInfo : public TargetInfo { bool HasBMI2; bool HasPOPCNT; bool HasRTM; + bool HasPRFCHW; bool HasSSE4a; bool HasFMA4; bool HasFMA; @@ -1852,8 +1853,8 @@ public: : TargetInfo(triple), SSELevel(NoSSE), MMX3DNowLevel(NoMMX3DNow), HasAES(false), HasPCLMUL(false), HasLZCNT(false), HasRDRND(false), HasBMI(false), HasBMI2(false), HasPOPCNT(false), HasRTM(false), - HasSSE4a(false), HasFMA4(false), HasFMA(false), HasXOP(false), - HasF16C(false), CPU(CK_Generic) { + HasPRFCHW(false), HasSSE4a(false), HasFMA4(false), + HasFMA(false), HasXOP(false), HasF16C(false), CPU(CK_Generic) { BigEndian = false; LongDoubleFormat = &llvm::APFloat::x87DoubleExtended; } @@ -2059,6 +2060,7 @@ void X86TargetInfo::getDefaultFeatures(llvm::StringMap &Features) const { Features["bmi2"] = false; Features["popcnt"] = false; Features["rtm"] = false; + Features["prfchw"] = false; Features["fma4"] = false; Features["fma"] = false; Features["xop"] = false; @@ -2281,6 +2283,8 @@ bool X86TargetInfo::setFeatureEnabled(llvm::StringMap &Features, Features["f16c"] = true; else if (Name == "rtm") Features["rtm"] = true; + else if (Name == "prfchw") + Features["prfchw"] = true; } else { if (Name == "mmx") Features["mmx"] = Features["3dnow"] = Features["3dnowa"] = false; @@ -2345,6 +2349,8 @@ bool X86TargetInfo::setFeatureEnabled(llvm::StringMap &Features, Features["f16c"] = false; else if (Name == "rtm") Features["rtm"] = false; + else if (Name == "prfchw") + Features["prfchw"] = false; } return true; @@ -2401,6 +2407,11 @@ void X86TargetInfo::HandleTargetFeatures(std::vector &Features) { continue; } + if (Feature == "prfchw") { + HasPRFCHW = true; + continue; + } + if (Feature == "sse4a") { HasSSE4a = true; continue; @@ -2625,6 +2636,9 @@ void X86TargetInfo::getTargetDefines(const LangOptions &Opts, if (HasRTM) Builder.defineMacro("__RTM__"); + if (HasPRFCHW) + Builder.defineMacro("__PRFCHW__"); + if (HasSSE4a) Builder.defineMacro("__SSE4A__"); @@ -2713,6 +2727,7 @@ bool X86TargetInfo::hasFeature(StringRef Feature) const { .Case("pclmul", HasPCLMUL) .Case("popcnt", HasPOPCNT) .Case("rtm", HasRTM) + .Case("prfchw", HasPRFCHW) .Case("sse", SSELevel >= SSE1) .Case("sse2", SSELevel >= SSE2) .Case("sse3", SSELevel >= SSE3) diff --git a/clang/lib/Headers/CMakeLists.txt b/clang/lib/Headers/CMakeLists.txt index ae689c3..96a6cf3 100644 --- a/clang/lib/Headers/CMakeLists.txt +++ b/clang/lib/Headers/CMakeLists.txt @@ -20,6 +20,7 @@ set(files nmmintrin.h pmmintrin.h popcntintrin.h + prfchwintrin.h rtmintrin.h smmintrin.h stdalign.h diff --git a/clang/lib/Headers/mm3dnow.h b/clang/lib/Headers/mm3dnow.h index d5236f8..5242d99 100644 --- a/clang/lib/Headers/mm3dnow.h +++ b/clang/lib/Headers/mm3dnow.h @@ -25,6 +25,7 @@ #define _MM3DNOW_H_INCLUDED #include +#include typedef float __v2sf __attribute__((__vector_size__(8))); diff --git a/clang/lib/Headers/prfchwintrin.h b/clang/lib/Headers/prfchwintrin.h new file mode 100644 index 0000000..2d529c6 --- /dev/null +++ b/clang/lib/Headers/prfchwintrin.h @@ -0,0 +1,34 @@ +/*===---- prfchwintrin.h - PREFETCHW intrinsic -----------------------------=== + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + *===-----------------------------------------------------------------------=== + */ + +#if !defined(__X86INTRIN_H) && !defined(_MM3DNOW_H_INCLUDED) +#error "Never use directly; include or instead." +#endif + +#if defined(__PRFCHW__) || defined(__3dNOW__) +static __inline__ void __attribute__((__always_inline__, __nodebug__)) +_m_prefetchw(void *__P) +{ + __builtin_prefetch (__P, 1, 3 /* _MM_HINT_T0 */); +} +#endif diff --git a/clang/lib/Headers/x86intrin.h b/clang/lib/Headers/x86intrin.h index 68ce106..441b38a 100644 --- a/clang/lib/Headers/x86intrin.h +++ b/clang/lib/Headers/x86intrin.h @@ -46,6 +46,10 @@ #include #endif +#ifdef __PRFCHW__ +#include +#endif + #ifdef __SSE4A__ #include #endif diff --git a/clang/test/CodeGen/prefetchw-builtins.c b/clang/test/CodeGen/prefetchw-builtins.c new file mode 100644 index 0000000..9c5fdc7 --- /dev/null +++ b/clang/test/CodeGen/prefetchw-builtins.c @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-unknown -target-feature +prfchw -emit-llvm -o - %s | FileCheck %s + +// Don't include mm_malloc.h, it's system specific. +#define __MM_MALLOC_H + +#include + +void prefetch_w(void *p) { + return _m_prefetchw(p); +// CHECK: @prefetch_w +// CHECK: call void @llvm.prefetch({{.*}}, i32 1, i32 3, i32 1) +} -- 2.7.4