PPCInstrHTM.td 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. //===-- PPCInstrHTM.td - The PowerPC Hardware Transactional Memory -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file describes the Hardware Transactional Memory extension to the
  10. // PowerPC instruction set.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. def HasHTM : Predicate<"Subtarget->hasHTM()">;
  14. def HTM_get_imm : SDNodeXForm<imm, [{
  15. return getI32Imm (N->getZExtValue(), SDLoc(N));
  16. }]>;
  17. let hasSideEffects = 1 in {
  18. def TCHECK_RET : PPCCustomInserterPseudo<(outs gprc:$out), (ins), "#TCHECK_RET", []>;
  19. def TBEGIN_RET : PPCCustomInserterPseudo<(outs gprc:$out), (ins u1imm:$R), "#TBEGIN_RET", []>;
  20. }
  21. let Predicates = [HasHTM] in {
  22. let Defs = [CR0] in {
  23. def TBEGIN : XForm_htm0 <31, 654,
  24. (outs), (ins u1imm:$R), "tbegin. $R", IIC_SprMTSPR>;
  25. def TEND : XForm_htm1 <31, 686,
  26. (outs), (ins u1imm:$A), "tend. $A", IIC_SprMTSPR>;
  27. def TABORT : XForm_base_r3xo <31, 910,
  28. (outs), (ins gprc:$A), "tabort. $A", IIC_SprMTSPR,
  29. []>, isRecordForm {
  30. let RST = 0;
  31. let B = 0;
  32. }
  33. def TABORTWC : XForm_base_r3xo <31, 782,
  34. (outs), (ins u5imm:$RTS, gprc:$A, gprc:$B),
  35. "tabortwc. $RTS, $A, $B", IIC_SprMTSPR, []>,
  36. isRecordForm;
  37. def TABORTWCI : XForm_base_r3xo <31, 846,
  38. (outs), (ins u5imm:$RTS, gprc:$A, u5imm:$B),
  39. "tabortwci. $RTS, $A, $B", IIC_SprMTSPR, []>,
  40. isRecordForm;
  41. def TABORTDC : XForm_base_r3xo <31, 814,
  42. (outs), (ins u5imm:$RTS, gprc:$A, gprc:$B),
  43. "tabortdc. $RTS, $A, $B", IIC_SprMTSPR, []>,
  44. isRecordForm;
  45. def TABORTDCI : XForm_base_r3xo <31, 878,
  46. (outs), (ins u5imm:$RTS, gprc:$A, u5imm:$B),
  47. "tabortdci. $RTS, $A, $B", IIC_SprMTSPR, []>,
  48. isRecordForm;
  49. def TSR : XForm_htm2 <31, 750,
  50. (outs), (ins u1imm:$L), "tsr. $L", IIC_SprMTSPR>,
  51. isRecordForm;
  52. def TRECLAIM : XForm_base_r3xo <31, 942,
  53. (outs), (ins gprc:$A), "treclaim. $A",
  54. IIC_SprMTSPR, []>,
  55. isRecordForm {
  56. let RST = 0;
  57. let B = 0;
  58. }
  59. def TRECHKPT : XForm_base_r3xo <31, 1006,
  60. (outs), (ins), "trechkpt.", IIC_SprMTSPR, []>,
  61. isRecordForm {
  62. let RST = 0;
  63. let A = 0;
  64. let B = 0;
  65. }
  66. }
  67. def TCHECK : XForm_htm3 <31, 718,
  68. (outs crrc:$BF), (ins), "tcheck $BF", IIC_SprMTSPR>;
  69. // Builtins
  70. // All HTM instructions, with the exception of tcheck, set CR0 with the
  71. // value of the MSR Transaction State (TS) bits that exist before the
  72. // instruction is executed. For tbegin., the EQ bit in CR0 can be used
  73. // to determine whether the transaction was successfully started (0) or
  74. // failed (1). We use an XORI pattern to 'flip' the bit to match the
  75. // tbegin builtin API which defines a return value of 1 as success.
  76. def : Pat<(int_ppc_tbegin i32:$R),
  77. (XORI (TBEGIN_RET(HTM_get_imm imm:$R)), 1)>;
  78. def : Pat<(int_ppc_tend i32:$R),
  79. (TEND (HTM_get_imm imm:$R))>;
  80. def : Pat<(int_ppc_tabort i32:$R),
  81. (TABORT $R)>;
  82. def : Pat<(int_ppc_tabortwc i32:$TO, i32:$RA, i32:$RB),
  83. (TABORTWC (HTM_get_imm imm:$TO), $RA, $RB)>;
  84. def : Pat<(int_ppc_tabortwci i32:$TO, i32:$RA, i32:$SI),
  85. (TABORTWCI (HTM_get_imm imm:$TO), $RA, (HTM_get_imm imm:$SI))>;
  86. def : Pat<(int_ppc_tabortdc i32:$TO, i32:$RA, i32:$RB),
  87. (TABORTDC (HTM_get_imm imm:$TO), $RA, $RB)>;
  88. def : Pat<(int_ppc_tabortdci i32:$TO, i32:$RA, i32:$SI),
  89. (TABORTDCI (HTM_get_imm imm:$TO), $RA, (HTM_get_imm imm:$SI))>;
  90. def : Pat<(int_ppc_tcheck),
  91. (TCHECK_RET)>;
  92. def : Pat<(int_ppc_treclaim i32:$RA),
  93. (TRECLAIM $RA)>;
  94. def : Pat<(int_ppc_trechkpt),
  95. (TRECHKPT)>;
  96. def : Pat<(int_ppc_tsr i32:$L),
  97. (TSR (HTM_get_imm imm:$L))>;
  98. def : Pat<(int_ppc_get_texasr),
  99. (MFSPR8 130)>;
  100. def : Pat<(int_ppc_get_texasru),
  101. (MFSPR8 131)>;
  102. def : Pat<(int_ppc_get_tfhar),
  103. (MFSPR8 128)>;
  104. def : Pat<(int_ppc_get_tfiar),
  105. (MFSPR8 129)>;
  106. def : Pat<(int_ppc_set_texasr i64:$V),
  107. (MTSPR8 130, $V)>;
  108. def : Pat<(int_ppc_set_texasru i64:$V),
  109. (MTSPR8 131, $V)>;
  110. def : Pat<(int_ppc_set_tfhar i64:$V),
  111. (MTSPR8 128, $V)>;
  112. def : Pat<(int_ppc_set_tfiar i64:$V),
  113. (MTSPR8 129, $V)>;
  114. // Extended mnemonics
  115. def : Pat<(int_ppc_tendall),
  116. (TEND 1)>;
  117. def : Pat<(int_ppc_tresume),
  118. (TSR 1)>;
  119. def : Pat<(int_ppc_tsuspend),
  120. (TSR 0)>;
  121. def : Pat<(i64 (int_ppc_ttest)),
  122. (i64 (INSERT_SUBREG
  123. (i64 (IMPLICIT_DEF)), (TABORTWCI 0, (LI 0), 0), sub_32))>;
  124. } // [HasHTM]
  125. def : InstAlias<"tend.", (TEND 0)>, Requires<[HasHTM]>;
  126. def : InstAlias<"tendall.", (TEND 1)>, Requires<[HasHTM]>;
  127. def : InstAlias<"tsuspend.", (TSR 0)>, Requires<[HasHTM]>;
  128. def : InstAlias<"tresume.", (TSR 1)>, Requires<[HasHTM]>;