<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Mar 25, 2015 at 12:41 PM, Kit Barton <span dir="ltr"><<a href="mailto:kbarton@ca.ibm.com" target="_blank">kbarton@ca.ibm.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Author: kbarton<br>
Date: Wed Mar 25 14:41:41 2015<br>
New Revision: 233205<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=233205&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=233205&view=rev</a><br>
Log:<br>
Add Hardware Transactional Memory (HTM) Support<br>
<br>
This patch adds Hardware Transaction Memory (HTM) support supported by ISA 2.07<br>
(POWER8). The intrinsic support is based on GCC one [1], with both 'PowerPC HTM<br>
Low Level Built-in Functions' and 'PowerPC HTM High Level Inline Functions'<br>
implemented.<br>
<br>
Along with builtins a new driver switch is added to enable/disable HTM<br>
instruction support (-mhtm) and a header with common definitions (mostly to<br>
parse the TFHAR register value). The HTM switch also sets a preprocessor builtin<br>
HTM.<br>
<br>
The HTM usage requires a recently newer kernel with PPC HTM enabled. Tested on<br>
powerpc64 and powerpc64le.<br>
<br>
This is send along a llvm patch to enabled the builtins and option switch.<br>
<br>
[1]<br>
<a href="https://gcc.gnu.org/onlinedocs/gcc/PowerPC-Hardware-Transactional-Memory-Built-in-Functions.html" target="_blank">https://gcc.gnu.org/onlinedocs/gcc/PowerPC-Hardware-Transactional-Memory-Built-in-Functions.html</a><br>
<br>
Phabricator Review: <a href="http://reviews.llvm.org/D8248" target="_blank">http://reviews.llvm.org/D8248</a><br>
<br>
Added:<br>
    cfe/trunk/lib/Headers/htmintrin.h<br>
    cfe/trunk/lib/Headers/htmxlintrin.h<br>
    cfe/trunk/test/CodeGen/builtins-ppc-htm.c<br>
Modified:<br>
    cfe/trunk/include/clang/Basic/BuiltinsPPC.def<br>
    cfe/trunk/include/clang/Driver/Options.td<br>
    cfe/trunk/lib/Basic/Targets.cpp<br>
    cfe/trunk/lib/CodeGen/CGBuiltin.cpp<br>
<br>
Modified: cfe/trunk/include/clang/Basic/BuiltinsPPC.def<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsPPC.def?rev=233205&r1=233204&r2=233205&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsPPC.def?rev=233205&r1=233204&r2=233205&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Basic/BuiltinsPPC.def (original)<br>
+++ cfe/trunk/include/clang/Basic/BuiltinsPPC.def Wed Mar 25 14:41:41 2015<br>
@@ -252,6 +252,37 @@ BUILTIN(__builtin_vsx_xsmindp, "ddd", ""<br>
 BUILTIN(__builtin_vsx_xvdivdp, "V2dV2dV2d", "")<br>
 BUILTIN(__builtin_vsx_xvdivsp, "V4fV4fV4f", "")<br>
<br>
+// HTM builtins<br>
+BUILTIN(__builtin_tbegin, "UiUIi", "")<br>
+BUILTIN(__builtin_tend, "UiUIi", "")<br>
+<br>
+BUILTIN(__builtin_tabort, "UiUi", "")<br>
+BUILTIN(__builtin_tabortdc, "UiUiUiUi", "")<br>
+BUILTIN(__builtin_tabortdci, "UiUiUii", "")<br>
+BUILTIN(__builtin_tabortwc, "UiUiUiUi", "")<br>
+BUILTIN(__builtin_tabortwci, "UiUiUii", "")<br>
+<br>
+BUILTIN(__builtin_tcheck, "Ui", "")<br>
+BUILTIN(__builtin_treclaim, "UiUi", "")<br>
+BUILTIN(__builtin_trechkpt, "Ui", "")<br>
+BUILTIN(__builtin_tsr, "UiUi", "")<br>
+<br>
+BUILTIN(__builtin_tendall, "Ui", "")<br>
+BUILTIN(__builtin_tresume, "Ui", "")<br>
+BUILTIN(__builtin_tsuspend, "Ui", "")<br>
+<br>
+BUILTIN(__builtin_get_texasr, "LUi", "c")<br>
+BUILTIN(__builtin_get_texasru, "LUi", "c")<br>
+BUILTIN(__builtin_get_tfhar, "LUi", "c")<br>
+BUILTIN(__builtin_get_tfiar, "LUi", "c")<br>
+<br>
+BUILTIN(__builtin_set_texasr, "vLUi", "c")<br>
+BUILTIN(__builtin_set_texasru, "vLUi", "c")<br>
+BUILTIN(__builtin_set_tfhar, "vLUi", "c")<br>
+BUILTIN(__builtin_set_tfiar, "vLUi", "c")<br>
+<br>
+BUILTIN(__builtin_ttest, "LUi", "")<br>
+<br>
 // FIXME: Obviously incomplete.<br>
<br>
 #undef BUILTIN<br>
<br>
Modified: cfe/trunk/include/clang/Driver/Options.td<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=233205&r1=233204&r2=233205&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=233205&r1=233204&r2=233205&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Driver/Options.td (original)<br>
+++ cfe/trunk/include/clang/Driver/Options.td Wed Mar 25 14:41:41 2015<br>
@@ -1263,6 +1263,8 @@ def mpower8_crypto : Flag<["-"], "mcrypt<br>
     Group<m_ppc_Features_Group>;<br>
 def mnopower8_crypto : Flag<["-"], "mno-crypto">,<br>
     Group<m_ppc_Features_Group>;<br>
+def mhtm : Flag<["-"], "mhtm">, Group<m_ppc_Features_Group>;<br>
+def mno_htm : Flag<["-"], "mno-htm">, Group<m_ppc_Features_Group>;<br>
 def mfprnd : Flag<["-"], "mfprnd">, Group<m_ppc_Features_Group>;<br>
 def mno_fprnd : Flag<["-"], "mno-fprnd">, Group<m_ppc_Features_Group>;<br>
 def mcmpb : Flag<["-"], "mcmpb">, Group<m_ppc_Features_Group>;<br>
<br>
Modified: cfe/trunk/lib/Basic/Targets.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=233205&r1=233204&r2=233205&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=233205&r1=233204&r2=233205&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Basic/Targets.cpp (original)<br>
+++ cfe/trunk/lib/Basic/Targets.cpp Wed Mar 25 14:41:41 2015<br>
@@ -744,6 +744,7 @@ class PPCTargetInfo : public TargetInfo<br>
   bool HasP8Vector;<br>
   bool HasP8Crypto;<br>
   bool HasQPX;<br>
+  bool HasHTM;<br>
<br>
 protected:<br>
   std::string ABI;<br>
@@ -751,7 +752,7 @@ protected:<br>
 public:<br>
   PPCTargetInfo(const llvm::Triple &Triple)<br>
     : TargetInfo(Triple), HasVSX(false), HasP8Vector(false),<br>
-      HasP8Crypto(false), HasQPX(false) {<br>
+      HasP8Crypto(false), HasQPX(false), HasHTM(false) {<br>
     BigEndian = (Triple.getArch() != llvm::Triple::ppc64le);<br>
     LongDoubleWidth = LongDoubleAlign = 128;<br>
     LongDoubleFormat = &llvm::APFloat::PPCDoubleDouble;<br>
@@ -1026,6 +1027,11 @@ bool PPCTargetInfo::handleTargetFeatures<br>
       continue;<br>
     }<br>
<br>
+    if (Feature == "htm") {<br>
+      HasHTM = true;<br>
+      continue;<br>
+    }<br>
+<br>
     // TODO: Finish this list and add an assert that we've handled them<br>
     // all.<br>
   }<br>
@@ -1180,6 +1186,8 @@ void PPCTargetInfo::getTargetDefines(con<br>
     Builder.defineMacro("__POWER8_VECTOR__");<br>
   if (HasP8Crypto)<br>
     Builder.defineMacro("__CRYPTO__");<br>
+  if (HasHTM)<br>
+    Builder.defineMacro("__HTM__");<br>
<br>
   // FIXME: The following are not yet generated here by Clang, but are<br>
   //        generated by GCC:<br>
@@ -1235,6 +1243,7 @@ bool PPCTargetInfo::hasFeature(StringRef<br>
     .Case("power8-vector", HasP8Vector)<br>
     .Case("crypto", HasP8Crypto)<br>
     .Case("qpx", HasQPX)<br>
+    .Case("htm", HasHTM)<br>
     .Default(false);<br>
 }<br>
<br>
<br>
Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=233205&r1=233204&r2=233205&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=233205&r1=233204&r2=233205&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Wed Mar 25 14:41:41 2015<br>
@@ -26,6 +26,7 @@<br>
 #include "llvm/IR/DataLayout.h"<br>
 #include "llvm/IR/InlineAsm.h"<br>
 #include "llvm/IR/Intrinsics.h"<br>
+#include <sstream><br>
<br>
 using namespace clang;<br>
 using namespace CodeGen;<br>
@@ -6370,6 +6371,7 @@ Value *CodeGenFunction::EmitPPCBuiltinEx<br>
     llvm::Function *F = CGM.getIntrinsic(ID);<br>
     return Builder.CreateCall(F, Ops, "");<br>
   }<br>
+<br>
   // P8 Crypto builtins<br>
   case PPC::BI__builtin_altivec_crypto_vshasigmaw:<br>
   case PPC::BI__builtin_altivec_crypto_vshasigmad:<br>
@@ -6399,6 +6401,89 @@ Value *CodeGenFunction::EmitPPCBuiltinEx<br>
     llvm::Function *F = CGM.getIntrinsic(ID);<br>
     return Builder.CreateCall(F, Ops, "");<br>
   }<br>
+<br>
+  // HTM builtins<br>
+  case PPC::BI__builtin_tbegin:<br>
+  case PPC::BI__builtin_tend:<br>
+  case PPC::BI__builtin_tsr: {<br>
+    unsigned int MaxValue;<br>
+    // The HTM instructions only accept one argument and with limited range.<br>
+    ConstantInt *CI = dyn_cast<ConstantInt>(Ops[0]);<br>
+    assert(CI);<br>
+    switch (BuiltinID) {<br>
+    case PPC::BI__builtin_tbegin:<br>
+      ID = Intrinsic::ppc_tbegin;<br>
+      MaxValue = 1;<br>
+      break;<br>
+    case PPC::BI__builtin_tend:<br>
+      ID = Intrinsic::ppc_tend;<br>
+      MaxValue = 1;<br>
+      break;<br>
+    case PPC::BI__builtin_tsr:<br>
+      ID = Intrinsic::ppc_tsr;<br>
+      MaxValue = 7;<br>
+      break;<br>
+    }<br>
+    if (CI->getZExtValue() > MaxValue) {<br>
+      std::stringstream ss;<br>
+      ss << "argument out of range (should be 0 or " << MaxValue << ")";<br>
+      CGM.Error(E->getArg(0)->getExprLoc(), ss.str());<br>
+      return llvm::UndefValue::get(Ops[0]->getType());<br></blockquote><div><br></div><div><div>This constraint should be checked and diagnosed in Sema, not here, and should use a proper diagnostic.</div></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
+    }<br>
+<br>
+    llvm::Function *F = CGM.getIntrinsic(ID);<br>
+    return Builder.CreateCall(F, Ops, "");<br>
+  }<br>
+  case PPC::BI__builtin_tabortdc:<br>
+  case PPC::BI__builtin_tabortwc: {<br>
+    // For wd and dc variant of tabort first argument must be a 5-bit constant<br>
+    // integer<br>
+    ConstantInt *CI = dyn_cast<ConstantInt>(Ops[0]);<br>
+    assert(CI);<br>
+    if (CI->getZExtValue() > 31) {<br>
+      CGM.ErrorUnsupported(E->getArg(0), "argument out of range (should be 0-31)");<br>
+      return llvm::UndefValue::get(Ops[0]->getType());<br></blockquote><div><br></div><div>Likewise here and in the two cases below.</div><div><br></div><div>Please also add some test coverage for these diagnostics.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
+    }<br>
+    switch (BuiltinID) {<br>
+    case PPC::BI__builtin_tabortdc:<br>
+      ID = Intrinsic::ppc_tabortdc;<br>
+      break;<br>
+    case PPC::BI__builtin_tabortwc:<br>
+      ID = Intrinsic::ppc_tabortwc;<br>
+      break;<br>
+    }<br>
+    llvm::Function *F = CGM.getIntrinsic(ID);<br>
+    return Builder.CreateCall(F, Ops, "");<br>
+  }<br>
+  case PPC::BI__builtin_tabortdci:<br>
+  case PPC::BI__builtin_tabortwci: {<br>
+    // For wd and dc variant of tabort first and third argument must be a<br>
+    // 5-bit constant integer<br>
+    ConstantInt *CI = dyn_cast<ConstantInt>(Ops[0]);<br>
+    assert(CI);<br>
+    if (CI->getZExtValue() > 31) {<br>
+      CGM.ErrorUnsupported(E->getArg(0), "argument out of range (should be 0-31)");<br>
+      return llvm::UndefValue::get(Ops[0]->getType());<br>
+    }<br>
+    CI = dyn_cast<ConstantInt>(Ops[2]);<br>
+    assert(CI);<br>
+    if (CI->getZExtValue() > 31) {<br>
+      CGM.ErrorUnsupported(E->getArg(2), "argument out of range (should be 0-31)");<br>
+      return llvm::UndefValue::get(Ops[2]->getType());<br>
+    }<br>
+    switch (BuiltinID) {<br>
+    default: llvm_unreachable("Unsupported htm intrinsic!");<br>
+    case PPC::BI__builtin_tabortdci:<br>
+      ID = Intrinsic::ppc_tabortdci;<br>
+      break;<br>
+    case PPC::BI__builtin_tabortwci:<br>
+      ID = Intrinsic::ppc_tabortwci;<br>
+      break;<br>
+    }<br>
+    llvm::Function *F = CGM.getIntrinsic(ID);<br>
+    return Builder.CreateCall(F, Ops, "");<br>
+  }<br>
+<br>
   }<br>
 }<br>
<br>
<br>
Added: cfe/trunk/lib/Headers/htmintrin.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/htmintrin.h?rev=233205&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/htmintrin.h?rev=233205&view=auto</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Headers/htmintrin.h (added)<br>
+++ cfe/trunk/lib/Headers/htmintrin.h Wed Mar 25 14:41:41 2015<br>
@@ -0,0 +1,131 @@<br>
+/*===---- htmintrin.h - Standard header for PowerPC HTM ---------------===*\<br>
+ *<br>
+ * Permission is hereby granted, free of charge, to any person obtaining a copy<br>
+ * of this software and associated documentation files (the "Software"), to deal<br>
+ * in the Software without restriction, including without limitation the rights<br>
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell<br>
+ * copies of the Software, and to permit persons to whom the Software is<br>
+ * furnished to do so, subject to the following conditions:<br>
+ *<br>
+ * The above copyright notice and this permission notice shall be included in<br>
+ * all copies or substantial portions of the Software.<br>
+ *<br>
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE<br>
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,<br>
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN<br>
+ * THE SOFTWARE.<br>
+ *<br>
+\*===----------------------------------------------------------------------===*/<br>
+<br>
+#ifndef __HTMINTRIN_H<br>
+#define __HTMINTRIN_H<br>
+<br>
+#ifndef __HTM__<br>
+#error "HTM instruction set not enabled"<br>
+#endif<br>
+<br>
+#ifdef __powerpc__<br>
+<br>
+#include <stdint.h><br>
+<br>
+typedef uint64_t texasr_t;<br>
+typedef uint32_t texasru_t;<br>
+typedef uint32_t texasrl_t;<br>
+typedef uintptr_t tfiar_t;<br>
+typedef uintptr_t tfhar_t;<br>
+<br>
+#define _HTM_STATE(CR0) ((CR0 >> 1) & 0x3)<br>
+#define _HTM_NONTRANSACTIONAL 0x0<br>
+#define _HTM_SUSPENDED        0x1<br>
+#define _HTM_TRANSACTIONAL    0x2<br>
+<br>
+#define _TEXASR_EXTRACT_BITS(TEXASR,BITNUM,SIZE) \<br>
+  (((TEXASR) >> (63-(BITNUM))) & ((1<<(SIZE))-1))<br>
+#define _TEXASRU_EXTRACT_BITS(TEXASR,BITNUM,SIZE) \<br>
+  (((TEXASR) >> (31-(BITNUM))) & ((1<<(SIZE))-1))<br>
+<br>
+#define _TEXASR_FAILURE_CODE(TEXASR) \<br>
+  _TEXASR_EXTRACT_BITS(TEXASR, 7, 8)<br>
+#define _TEXASRU_FAILURE_CODE(TEXASRU) \<br>
+  _TEXASRU_EXTRACT_BITS(TEXASRU, 7, 8)<br>
+<br>
+#define _TEXASR_FAILURE_PERSISTENT(TEXASR) \<br>
+  _TEXASR_EXTRACT_BITS(TEXASR, 7, 1)<br>
+#define _TEXASRU_FAILURE_PERSISTENT(TEXASRU) \<br>
+  _TEXASRU_EXTRACT_BITS(TEXASRU, 7, 1)<br>
+<br>
+#define _TEXASR_DISALLOWED(TEXASR) \<br>
+  _TEXASR_EXTRACT_BITS(TEXASR, 8, 1)<br>
+#define _TEXASRU_DISALLOWED(TEXASRU) \<br>
+  _TEXASRU_EXTRACT_BITS(TEXASRU, 8, 1)<br>
+<br>
+#define _TEXASR_NESTING_OVERFLOW(TEXASR) \<br>
+  _TEXASR_EXTRACT_BITS(TEXASR, 9, 1)<br>
+#define _TEXASRU_NESTING_OVERFLOW(TEXASRU) \<br>
+  _TEXASRU_EXTRACT_BITS(TEXASRU, 9, 1)<br>
+<br>
+#define _TEXASR_FOOTPRINT_OVERFLOW(TEXASR) \<br>
+  _TEXASR_EXTRACT_BITS(TEXASR, 10, 1)<br>
+#define _TEXASRU_FOOTPRINT_OVERFLOW(TEXASRU) \<br>
+  _TEXASRU_EXTRACT_BITS(TEXASRU, 10, 1)<br>
+<br>
+#define _TEXASR_SELF_INDUCED_CONFLICT(TEXASR) \<br>
+  _TEXASR_EXTRACT_BITS(TEXASR, 11, 1)<br>
+#define _TEXASRU_SELF_INDUCED_CONFLICT(TEXASRU) \<br>
+  _TEXASRU_EXTRACT_BITS(TEXASRU, 11, 1)<br>
+<br>
+#define _TEXASR_NON_TRANSACTIONAL_CONFLICT(TEXASR) \<br>
+  _TEXASR_EXTRACT_BITS(TEXASR, 12, 1)<br>
+#define _TEXASRU_NON_TRANSACTIONAL_CONFLICT(TEXASRU) \<br>
+  _TEXASRU_EXTRACT_BITS(TEXASRU, 12, 1)<br>
+<br>
+#define _TEXASR_TRANSACTION_CONFLICT(TEXASR) \<br>
+  _TEXASR_EXTRACT_BITS(TEXASR, 13, 1)<br>
+#define _TEXASRU_TRANSACTION_CONFLICT(TEXASRU) \<br>
+  _TEXASRU_EXTRACT_BITS(TEXASRU, 13, 1)<br>
+<br>
+#define _TEXASR_TRANSLATION_INVALIDATION_CONFLICT(TEXASR) \<br>
+  _TEXASR_EXTRACT_BITS(TEXASR, 14, 1)<br>
+#define _TEXASRU_TRANSLATION_INVALIDATION_CONFLICT(TEXASRU) \<br>
+  _TEXASRU_EXTRACT_BITS(TEXASRU, 14, 1)<br>
+<br>
+#define _TEXASR_IMPLEMENTAION_SPECIFIC(TEXASR) \<br>
+  _TEXASR_EXTRACT_BITS(TEXASR, 15, 1)<br>
+#define _TEXASRU_IMPLEMENTAION_SPECIFIC(TEXASRU) \<br>
+  _TEXASRU_EXTRACT_BITS(TEXASRU, 15, 1)<br>
+<br>
+#define _TEXASR_INSTRUCTION_FETCH_CONFLICT(TEXASR) \<br>
+  _TEXASR_EXTRACT_BITS(TEXASR, 16, 1)<br>
+#define _TEXASRU_INSTRUCTION_FETCH_CONFLICT(TEXASRU) \<br>
+  _TEXASRU_EXTRACT_BITS(TEXASRU, 16, 1)<br>
+<br>
+#define _TEXASR_ABORT(TEXASR) \<br>
+  _TEXASR_EXTRACT_BITS(TEXASR, 31, 1)<br>
+#define _TEXASRU_ABORT(TEXASRU) \<br>
+  _TEXASRU_EXTRACT_BITS(TEXASRU, 31, 1)<br>
+<br>
+<br>
+#define _TEXASR_SUSPENDED(TEXASR) \<br>
+  _TEXASR_EXTRACT_BITS(TEXASR, 32, 1)<br>
+<br>
+#define _TEXASR_PRIVILEGE(TEXASR) \<br>
+  _TEXASR_EXTRACT_BITS(TEXASR, 35, 2)<br>
+<br>
+#define _TEXASR_FAILURE_SUMMARY(TEXASR) \<br>
+  _TEXASR_EXTRACT_BITS(TEXASR, 36, 1)<br>
+<br>
+#define _TEXASR_TFIAR_EXACT(TEXASR) \<br>
+  _TEXASR_EXTRACT_BITS(TEXASR, 37, 1)<br>
+<br>
+#define _TEXASR_ROT(TEXASR) \<br>
+  _TEXASR_EXTRACT_BITS(TEXASR, 38, 1)<br>
+<br>
+#define _TEXASR_TRANSACTION_LEVEL(TEXASR) \<br>
+  _TEXASR_EXTRACT_BITS(TEXASR, 63, 12)<br>
+<br>
+#endif /* __powerpc */<br>
+<br>
+#endif /* __HTMINTRIN_H */<br>
<br>
Added: cfe/trunk/lib/Headers/htmxlintrin.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/htmxlintrin.h?rev=233205&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/htmxlintrin.h?rev=233205&view=auto</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Headers/htmxlintrin.h (added)<br>
+++ cfe/trunk/lib/Headers/htmxlintrin.h Wed Mar 25 14:41:41 2015<br>
@@ -0,0 +1,215 @@<br>
+/*===---- htmxlintrin.h - XL compiler HTM execution intrinsics-------------===*\<br>
+ *<br>
+ * Permission is hereby granted, free of charge, to any person obtaining a copy<br>
+ * of this software and associated documentation files (the "Software"), to deal<br>
+ * in the Software without restriction, including without limitation the rights<br>
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell<br>
+ * copies of the Software, and to permit persons to whom the Software is<br>
+ * furnished to do so, subject to the following conditions:<br>
+ *<br>
+ * The above copyright notice and this permission notice shall be included in<br>
+ * all copies or substantial portions of the Software.<br>
+ *<br>
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE<br>
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,<br>
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN<br>
+ * THE SOFTWARE.<br>
+ *<br>
+\*===----------------------------------------------------------------------===*/<br>
+<br>
+#ifndef __HTMXLINTRIN_H<br>
+#define __HTMXLINTRIN_H<br>
+<br>
+#ifndef __HTM__<br>
+#error "HTM instruction set not enabled"<br>
+#endif<br>
+<br>
+#include <htmintrin.h><br>
+<br>
+#ifdef __powerpc__<br>
+<br>
+#ifdef __cplusplus<br>
+extern "C" {<br>
+#endif<br>
+<br>
+#define _TEXASR_PTR(TM_BUF) \<br>
+  ((texasr_t *)((TM_BUF)+0))<br>
+#define _TEXASRU_PTR(TM_BUF) \<br>
+  ((texasru_t *)((TM_BUF)+0))<br>
+#define _TEXASRL_PTR(TM_BUF) \<br>
+  ((texasrl_t *)((TM_BUF)+4))<br>
+#define _TFIAR_PTR(TM_BUF) \<br>
+  ((tfiar_t *)((TM_BUF)+8))<br>
+<br>
+typedef char TM_buff_type[16];<br>
+<br>
+/* This macro can be used to determine whether a transaction was successfully<br>
+   started from the __TM_begin() and __TM_simple_begin() intrinsic functions<br>
+   below.  */<br>
+#define _HTM_TBEGIN_STARTED     1<br>
+<br>
+extern __inline long<br>
+__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))<br>
+__TM_simple_begin (void)<br>
+{<br>
+  if (__builtin_expect (__builtin_tbegin (0), 1))<br>
+    return _HTM_TBEGIN_STARTED;<br>
+  return 0;<br>
+}<br>
+<br>
+extern __inline long<br>
+__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))<br>
+__TM_begin (void* const TM_buff)<br>
+{<br>
+  *_TEXASRL_PTR (TM_buff) = 0;<br>
+  if (__builtin_expect (__builtin_tbegin (0), 1))<br>
+    return _HTM_TBEGIN_STARTED;<br>
+#ifdef __powerpc64__<br>
+  *_TEXASR_PTR (TM_buff) = __builtin_get_texasr ();<br>
+#else<br>
+  *_TEXASRU_PTR (TM_buff) = __builtin_get_texasru ();<br>
+  *_TEXASRL_PTR (TM_buff) = __builtin_get_texasr ();<br>
+#endif<br>
+  *_TFIAR_PTR (TM_buff) = __builtin_get_tfiar ();<br>
+  return 0;<br>
+}<br>
+<br>
+extern __inline long<br>
+__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))<br>
+__TM_end (void)<br>
+{<br>
+  if (__builtin_expect (__builtin_tend (0), 1))<br>
+    return 1;<br>
+  return 0;<br>
+}<br>
+<br>
+extern __inline void<br>
+__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))<br>
+__TM_abort (void)<br>
+{<br>
+  __builtin_tabort (0);<br>
+}<br>
+<br>
+extern __inline void<br>
+__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))<br>
+__TM_named_abort (unsigned char const code)<br>
+{<br>
+  __builtin_tabort (code);<br>
+}<br>
+<br>
+extern __inline void<br>
+__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))<br>
+__TM_resume (void)<br>
+{<br>
+  __builtin_tresume ();<br>
+}<br>
+<br>
+extern __inline void<br>
+__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))<br>
+__TM_suspend (void)<br>
+{<br>
+  __builtin_tsuspend ();<br>
+}<br>
+<br>
+extern __inline long<br>
+__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))<br>
+__TM_is_user_abort (void* const TM_buff)<br>
+{<br>
+  texasru_t texasru = *_TEXASRU_PTR (TM_buff);<br>
+  return _TEXASRU_ABORT (texasru);<br>
+}<br>
+<br>
+extern __inline long<br>
+__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))<br>
+__TM_is_named_user_abort (void* const TM_buff, unsigned char *code)<br>
+{<br>
+  texasru_t texasru = *_TEXASRU_PTR (TM_buff);<br>
+<br>
+  *code = _TEXASRU_FAILURE_CODE (texasru);<br>
+  return _TEXASRU_ABORT (texasru);<br>
+}<br>
+<br>
+extern __inline long<br>
+__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))<br>
+__TM_is_illegal (void* const TM_buff)<br>
+{<br>
+  texasru_t texasru = *_TEXASRU_PTR (TM_buff);<br>
+  return _TEXASRU_DISALLOWED (texasru);<br>
+}<br>
+<br>
+extern __inline long<br>
+__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))<br>
+__TM_is_footprint_exceeded (void* const TM_buff)<br>
+{<br>
+  texasru_t texasru = *_TEXASRU_PTR (TM_buff);<br>
+  return _TEXASRU_FOOTPRINT_OVERFLOW (texasru);<br>
+}<br>
+<br>
+extern __inline long<br>
+__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))<br>
+__TM_nesting_depth (void* const TM_buff)<br>
+{<br>
+  texasrl_t texasrl;<br>
+<br>
+  if (_HTM_STATE (__builtin_ttest ()) == _HTM_NONTRANSACTIONAL)<br>
+    {<br>
+      texasrl = *_TEXASRL_PTR (TM_buff);<br>
+      if (!_TEXASR_FAILURE_SUMMARY (texasrl))<br>
+        texasrl = 0;<br>
+    }<br>
+  else<br>
+    texasrl = (texasrl_t) __builtin_get_texasr ();<br>
+<br>
+  return _TEXASR_TRANSACTION_LEVEL (texasrl);<br>
+}<br>
+<br>
+extern __inline long<br>
+__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))<br>
+__TM_is_nested_too_deep(void* const TM_buff)<br>
+{<br>
+  texasru_t texasru = *_TEXASRU_PTR (TM_buff);<br>
+  return _TEXASRU_NESTING_OVERFLOW (texasru);<br>
+}<br>
+<br>
+extern __inline long<br>
+__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))<br>
+__TM_is_conflict(void* const TM_buff)<br>
+{<br>
+  texasru_t texasru = *_TEXASRU_PTR (TM_buff);<br>
+  /* Return TEXASR bits 11 (Self-Induced Conflict) through<br>
+     14 (Translation Invalidation Conflict).  */<br>
+  return (_TEXASRU_EXTRACT_BITS (texasru, 14, 4)) ? 1 : 0;<br>
+}<br>
+<br>
+extern __inline long<br>
+__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))<br>
+__TM_is_failure_persistent(void* const TM_buff)<br>
+{<br>
+  texasru_t texasru = *_TEXASRU_PTR (TM_buff);<br>
+  return _TEXASRU_FAILURE_PERSISTENT (texasru);<br>
+}<br>
+<br>
+extern __inline long<br>
+__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))<br>
+__TM_failure_address(void* const TM_buff)<br>
+{<br>
+  return *_TFIAR_PTR (TM_buff);<br>
+}<br>
+<br>
+extern __inline long long<br>
+__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))<br>
+__TM_failure_code(void* const TM_buff)<br>
+{<br>
+  return *_TEXASR_PTR (TM_buff);<br>
+}<br>
+<br>
+#ifdef __cplusplus<br>
+}<br>
+#endif<br>
+<br>
+#endif /* __powerpc__ */<br>
+<br>
+#endif /* __HTMXLINTRIN_H  */<br>
<br>
Added: cfe/trunk/test/CodeGen/builtins-ppc-htm.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtins-ppc-htm.c?rev=233205&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtins-ppc-htm.c?rev=233205&view=auto</a><br>
==============================================================================<br>
--- cfe/trunk/test/CodeGen/builtins-ppc-htm.c (added)<br>
+++ cfe/trunk/test/CodeGen/builtins-ppc-htm.c Wed Mar 25 14:41:41 2015<br>
@@ -0,0 +1,62 @@<br>
+// REQUIRES: powerpc-registered-target<br>
+// RUN: %clang_cc1 -faltivec -target-feature +htm -triple powerpc64-unknown-unknown -emit-llvm %s -o - | FileCheck %s<br>
+<br>
+void test1(long int *r, int code, long int *a, long int *b) {<br>
+// CHECK-LABEL: define void @test1<br>
+<br>
+  r[0] = __builtin_tbegin (0);<br>
+// CHECK: @llvm.ppc.tbegin<br>
+  r[1] = __builtin_tbegin (1);<br>
+// CHECK: @llvm.ppc.tbegin<br>
+  r[2] = __builtin_tend (0);<br>
+// CHECK: @llvm.ppc.tend<br>
+  r[3] = __builtin_tendall ();<br>
+// CHECK: @llvm.ppc.tendall<br>
+<br>
+  r[4] = __builtin_tabort (code);<br>
+// CHECK: @llvm.ppc.tabort<br>
+  r[5] = __builtin_tabort (0x1);<br>
+// CHECK: @llvm.ppc.tabort<br>
+  r[6] = __builtin_tabortdc (0xf, a[0], b[0]);<br>
+// CHECK: @llvm.ppc.tabortdc<br>
+  r[7] = __builtin_tabortdci (0xf, a[1], 0x1);<br>
+// CHECK: @llvm.ppc.tabortdc<br>
+  r[8] = __builtin_tabortwc (0xf, a[2], b[2]);<br>
+// CHECK: @llvm.ppc.tabortwc<br>
+  r[9] = __builtin_tabortwci (0xf, a[3], 0x1);<br>
+// CHECK: @llvm.ppc.tabortwc<br>
+<br>
+  r[10] = __builtin_tcheck ();<br>
+// CHECK: @llvm.ppc.tcheck<br>
+  r[11] = __builtin_trechkpt ();<br>
+// CHECK: @llvm.ppc.trechkpt<br>
+  r[12] = __builtin_treclaim (0);<br>
+// CHECK: @llvm.ppc.treclaim<br>
+  r[13] = __builtin_tresume ();<br>
+// CHECK: @llvm.ppc.tresume<br>
+  r[14] = __builtin_tsuspend ();<br>
+// CHECK: @llvm.ppc.tsuspend<br>
+  r[15] = __builtin_tsr (0);<br>
+// CHECK: @llvm.ppc.tsr<br>
+<br>
+  r[16] = __builtin_ttest ();<br>
+// CHECK: @llvm.ppc.ttest<br>
+<br>
+  r[17] = __builtin_get_texasr ();<br>
+// CHECK: @llvm.ppc.get.texasr<br>
+  r[18] = __builtin_get_texasru ();<br>
+// CHECK: @llvm.ppc.get.texasru<br>
+  r[19] = __builtin_get_tfhar ();<br>
+// CHECK: @llvm.ppc.get.tfhar<br>
+  r[20] = __builtin_get_tfiar ();<br>
+// CHECK: @llvm.ppc.get.tfiar<br>
+<br>
+  __builtin_set_texasr (a[21]);<br>
+// CHECK: @llvm.ppc.set.texasr<br>
+  __builtin_set_texasru (a[22]);<br>
+// CHECK: @llvm.ppc.set.texasru<br>
+  __builtin_set_tfhar (a[23]);<br>
+// CHECK: @llvm.ppc.set.tfhar<br>
+  __builtin_set_tfiar (a[24]);<br>
+// CHECK: @llvm.ppc.set.tfiar<br>
+}<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div></div>