r178041 - Add PRFCHW intrinsic support

Michael Liao michael.liao at intel.com
Tue Mar 26 10:52:08 PDT 2013


Author: hliao
Date: Tue Mar 26 12:52:08 2013
New Revision: 178041

URL: http://llvm.org/viewvc/llvm-project?rev=178041&view=rev
Log:
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


Added:
    cfe/trunk/lib/Headers/prfchwintrin.h
    cfe/trunk/test/CodeGen/prefetchw-builtins.c
Modified:
    cfe/trunk/include/clang/Driver/Options.td
    cfe/trunk/lib/Basic/Targets.cpp
    cfe/trunk/lib/Headers/CMakeLists.txt
    cfe/trunk/lib/Headers/mm3dnow.h
    cfe/trunk/lib/Headers/x86intrin.h

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=178041&r1=178040&r2=178041&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Tue Mar 26 12:52:08 2013
@@ -895,6 +895,7 @@ def mno_fma : Flag<["-"], "mno-fma">, Gr
 def mno_xop : Flag<["-"], "mno-xop">, Group<m_x86_Features_Group>;
 def mno_f16c : Flag<["-"], "mno-f16c">, Group<m_x86_Features_Group>;
 def mno_rtm : Flag<["-"], "mno-rtm">, Group<m_x86_Features_Group>;
+def mno_prfchw : Flag<["-"], "mno-prfchw">, Group<m_x86_Features_Group>;
 
 def mno_thumb : Flag<["-"], "mno-thumb">, Group<m_Group>;
 def marm : Flag<["-"], "marm">, Alias<mno_thumb>;
@@ -938,6 +939,7 @@ def mfma : Flag<["-"], "mfma">, Group<m_
 def mxop : Flag<["-"], "mxop">, Group<m_x86_Features_Group>;
 def mf16c : Flag<["-"], "mf16c">, Group<m_x86_Features_Group>;
 def mrtm : Flag<["-"], "mrtm">, Group<m_x86_Features_Group>;
+def mprfchw : Flag<["-"], "mprfchw">, Group<m_x86_Features_Group>;
 def mips16 : Flag<["-"], "mips16">, Group<m_Group>;
 def mno_mips16 : Flag<["-"], "mno-mips16">, Group<m_Group>;
 def mxgot : Flag<["-"], "mxgot">, Group<m_Group>;

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=178041&r1=178040&r2=178041&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Tue Mar 26 12:52:08 2013
@@ -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(l
   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(ll
       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(ll
       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
       continue;
     }
 
+    if (Feature == "prfchw") {
+      HasPRFCHW = true;
+      continue;
+    }
+
     if (Feature == "sse4a") {
       HasSSE4a = true;
       continue;
@@ -2625,6 +2636,9 @@ void X86TargetInfo::getTargetDefines(con
   if (HasRTM)
     Builder.defineMacro("__RTM__");
 
+  if (HasPRFCHW)
+    Builder.defineMacro("__PRFCHW__");
+
   if (HasSSE4a)
     Builder.defineMacro("__SSE4A__");
 
@@ -2713,6 +2727,7 @@ bool X86TargetInfo::hasFeature(StringRef
       .Case("pclmul", HasPCLMUL)
       .Case("popcnt", HasPOPCNT)
       .Case("rtm", HasRTM)
+      .Case("prfchw", HasPRFCHW)
       .Case("sse", SSELevel >= SSE1)
       .Case("sse2", SSELevel >= SSE2)
       .Case("sse3", SSELevel >= SSE3)

Modified: cfe/trunk/lib/Headers/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/CMakeLists.txt?rev=178041&r1=178040&r2=178041&view=diff
==============================================================================
--- cfe/trunk/lib/Headers/CMakeLists.txt (original)
+++ cfe/trunk/lib/Headers/CMakeLists.txt Tue Mar 26 12:52:08 2013
@@ -20,6 +20,7 @@ set(files
   nmmintrin.h
   pmmintrin.h
   popcntintrin.h
+  prfchwintrin.h
   rtmintrin.h
   smmintrin.h
   stdalign.h

Modified: cfe/trunk/lib/Headers/mm3dnow.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/mm3dnow.h?rev=178041&r1=178040&r2=178041&view=diff
==============================================================================
--- cfe/trunk/lib/Headers/mm3dnow.h (original)
+++ cfe/trunk/lib/Headers/mm3dnow.h Tue Mar 26 12:52:08 2013
@@ -25,6 +25,7 @@
 #define _MM3DNOW_H_INCLUDED
 
 #include <mmintrin.h>
+#include <prfchwintrin.h>
 
 typedef float __v2sf __attribute__((__vector_size__(8)));
 

Added: cfe/trunk/lib/Headers/prfchwintrin.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/prfchwintrin.h?rev=178041&view=auto
==============================================================================
--- cfe/trunk/lib/Headers/prfchwintrin.h (added)
+++ cfe/trunk/lib/Headers/prfchwintrin.h Tue Mar 26 12:52:08 2013
@@ -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 <prfchwintrin.h> directly; include <x86intrin.h> or <mm3dnow.h> 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

Modified: cfe/trunk/lib/Headers/x86intrin.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/x86intrin.h?rev=178041&r1=178040&r2=178041&view=diff
==============================================================================
--- cfe/trunk/lib/Headers/x86intrin.h (original)
+++ cfe/trunk/lib/Headers/x86intrin.h Tue Mar 26 12:52:08 2013
@@ -46,6 +46,10 @@
 #include <popcntintrin.h>
 #endif
 
+#ifdef __PRFCHW__
+#include <prfchwintrin.h>
+#endif
+
 #ifdef __SSE4A__
 #include <ammintrin.h>
 #endif

Added: cfe/trunk/test/CodeGen/prefetchw-builtins.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/prefetchw-builtins.c?rev=178041&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/prefetchw-builtins.c (added)
+++ cfe/trunk/test/CodeGen/prefetchw-builtins.c Tue Mar 26 12:52:08 2013
@@ -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 <x86intrin.h>
+
+void prefetch_w(void *p) {
+  return _m_prefetchw(p);
+// CHECK: @prefetch_w
+// CHECK: call void @llvm.prefetch({{.*}}, i32 1, i32 3, i32 1)
+}





More information about the cfe-commits mailing list