TargetSelectionDAG.td 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088
  1. //===- TargetSelectionDAG.td - Common code for DAG isels ---*- tablegen -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file defines the target-independent interfaces used by SelectionDAG
  11. // instruction selection generators.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. class SDTypeConstraint<int opnum> {
  15. int OperandNum = opnum;
  16. }
  17. // SDTCisVT - The specified operand has exactly this VT.
  18. class SDTCisVT<int OpNum, ValueType vt> : SDTypeConstraint<OpNum> {
  19. ValueType VT = vt;
  20. }
  21. class SDTCisPtrTy<int OpNum> : SDTypeConstraint<OpNum>;
  22. // SDTCisInt - The specified operand has integer type.
  23. class SDTCisInt<int OpNum> : SDTypeConstraint<OpNum>;
  24. // SDTCisFP - The specified operand has floating-point type.
  25. class SDTCisFP<int OpNum> : SDTypeConstraint<OpNum>;
  26. // SDTCisVec - The specified operand has a vector type.
  27. class SDTCisVec<int OpNum> : SDTypeConstraint<OpNum>;
  28. // SDTCisSameAs - The two specified operands have identical types.
  29. class SDTCisSameAs<int OpNum, int OtherOp> : SDTypeConstraint<OpNum> {
  30. int OtherOperandNum = OtherOp;
  31. }
  32. // SDTCisVTSmallerThanOp - The specified operand is a VT SDNode, and its type is
  33. // smaller than the 'Other' operand.
  34. class SDTCisVTSmallerThanOp<int OpNum, int OtherOp> : SDTypeConstraint<OpNum> {
  35. int OtherOperandNum = OtherOp;
  36. }
  37. class SDTCisOpSmallerThanOp<int SmallOp, int BigOp> : SDTypeConstraint<SmallOp>{
  38. int BigOperandNum = BigOp;
  39. }
  40. /// SDTCisEltOfVec - This indicates that ThisOp is a scalar type of the same
  41. /// type as the element type of OtherOp, which is a vector type.
  42. class SDTCisEltOfVec<int ThisOp, int OtherOp>
  43. : SDTypeConstraint<ThisOp> {
  44. int OtherOpNum = OtherOp;
  45. }
  46. /// SDTCisSubVecOfVec - This indicates that ThisOp is a vector type
  47. /// with length less that of OtherOp, which is a vector type.
  48. class SDTCisSubVecOfVec<int ThisOp, int OtherOp>
  49. : SDTypeConstraint<ThisOp> {
  50. int OtherOpNum = OtherOp;
  51. }
  52. // SDTCVecEltisVT - The specified operand is vector type with element type
  53. // of VT.
  54. class SDTCVecEltisVT<int OpNum, ValueType vt> : SDTypeConstraint<OpNum> {
  55. ValueType VT = vt;
  56. }
  57. // SDTCisSameNumEltsAs - The two specified operands have identical number
  58. // of elements.
  59. class SDTCisSameNumEltsAs<int OpNum, int OtherOp> : SDTypeConstraint<OpNum> {
  60. int OtherOperandNum = OtherOp;
  61. }
  62. //===----------------------------------------------------------------------===//
  63. // Selection DAG Type Profile definitions.
  64. //
  65. // These use the constraints defined above to describe the type requirements of
  66. // the various nodes. These are not hard coded into tblgen, allowing targets to
  67. // add their own if needed.
  68. //
  69. // SDTypeProfile - This profile describes the type requirements of a Selection
  70. // DAG node.
  71. class SDTypeProfile<int numresults, int numoperands,
  72. list<SDTypeConstraint> constraints> {
  73. int NumResults = numresults;
  74. int NumOperands = numoperands;
  75. list<SDTypeConstraint> Constraints = constraints;
  76. }
  77. // Builtin profiles.
  78. def SDTIntLeaf: SDTypeProfile<1, 0, [SDTCisInt<0>]>; // for 'imm'.
  79. def SDTFPLeaf : SDTypeProfile<1, 0, [SDTCisFP<0>]>; // for 'fpimm'.
  80. def SDTPtrLeaf: SDTypeProfile<1, 0, [SDTCisPtrTy<0>]>; // for '&g'.
  81. def SDTOther : SDTypeProfile<1, 0, [SDTCisVT<0, OtherVT>]>; // for 'vt'.
  82. def SDTUNDEF : SDTypeProfile<1, 0, []>; // for 'undef'.
  83. def SDTUnaryOp : SDTypeProfile<1, 1, []>; // for bitconvert.
  84. def SDTIntBinOp : SDTypeProfile<1, 2, [ // add, and, or, xor, udiv, etc.
  85. SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisInt<0>
  86. ]>;
  87. def SDTIntShiftOp : SDTypeProfile<1, 2, [ // shl, sra, srl
  88. SDTCisSameAs<0, 1>, SDTCisInt<0>, SDTCisInt<2>
  89. ]>;
  90. def SDTIntBinHiLoOp : SDTypeProfile<2, 2, [ // mulhi, mullo, sdivrem, udivrem
  91. SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisSameAs<0, 3>,SDTCisInt<0>
  92. ]>;
  93. def SDTFPBinOp : SDTypeProfile<1, 2, [ // fadd, fmul, etc.
  94. SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisFP<0>
  95. ]>;
  96. def SDTFPSignOp : SDTypeProfile<1, 2, [ // fcopysign.
  97. SDTCisSameAs<0, 1>, SDTCisFP<0>, SDTCisFP<2>
  98. ]>;
  99. def SDTFPTernaryOp : SDTypeProfile<1, 3, [ // fmadd, fnmsub, etc.
  100. SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisSameAs<0, 3>, SDTCisFP<0>
  101. ]>;
  102. def SDTIntUnaryOp : SDTypeProfile<1, 1, [ // ctlz
  103. SDTCisSameAs<0, 1>, SDTCisInt<0>
  104. ]>;
  105. def SDTIntExtendOp : SDTypeProfile<1, 1, [ // sext, zext, anyext
  106. SDTCisInt<0>, SDTCisInt<1>, SDTCisOpSmallerThanOp<1, 0>
  107. ]>;
  108. def SDTIntTruncOp : SDTypeProfile<1, 1, [ // trunc
  109. SDTCisInt<0>, SDTCisInt<1>, SDTCisOpSmallerThanOp<0, 1>
  110. ]>;
  111. def SDTFPUnaryOp : SDTypeProfile<1, 1, [ // fneg, fsqrt, etc
  112. SDTCisSameAs<0, 1>, SDTCisFP<0>
  113. ]>;
  114. def SDTFPRoundOp : SDTypeProfile<1, 1, [ // fround
  115. SDTCisFP<0>, SDTCisFP<1>, SDTCisOpSmallerThanOp<0, 1>
  116. ]>;
  117. def SDTFPExtendOp : SDTypeProfile<1, 1, [ // fextend
  118. SDTCisFP<0>, SDTCisFP<1>, SDTCisOpSmallerThanOp<1, 0>
  119. ]>;
  120. def SDTIntToFPOp : SDTypeProfile<1, 1, [ // [su]int_to_fp
  121. SDTCisFP<0>, SDTCisInt<1>
  122. ]>;
  123. def SDTFPToIntOp : SDTypeProfile<1, 1, [ // fp_to_[su]int
  124. SDTCisInt<0>, SDTCisFP<1>
  125. ]>;
  126. def SDTExtInreg : SDTypeProfile<1, 2, [ // sext_inreg
  127. SDTCisSameAs<0, 1>, SDTCisInt<0>, SDTCisVT<2, OtherVT>,
  128. SDTCisVTSmallerThanOp<2, 1>
  129. ]>;
  130. def SDTSetCC : SDTypeProfile<1, 3, [ // setcc
  131. SDTCisInt<0>, SDTCisSameAs<1, 2>, SDTCisVT<3, OtherVT>
  132. ]>;
  133. def SDTSelect : SDTypeProfile<1, 3, [ // select
  134. SDTCisInt<1>, SDTCisSameAs<0, 2>, SDTCisSameAs<2, 3>
  135. ]>;
  136. def SDTVSelect : SDTypeProfile<1, 3, [ // vselect
  137. SDTCisInt<1>, SDTCisSameAs<0, 2>, SDTCisSameAs<2, 3>
  138. ]>;
  139. def SDTSelectCC : SDTypeProfile<1, 5, [ // select_cc
  140. SDTCisSameAs<1, 2>, SDTCisSameAs<3, 4>, SDTCisSameAs<0, 3>,
  141. SDTCisVT<5, OtherVT>
  142. ]>;
  143. def SDTBr : SDTypeProfile<0, 1, [ // br
  144. SDTCisVT<0, OtherVT>
  145. ]>;
  146. def SDTBrCC : SDTypeProfile<0, 4, [ // brcc
  147. SDTCisVT<0, OtherVT>, SDTCisSameAs<1, 2>, SDTCisVT<3, OtherVT>
  148. ]>;
  149. def SDTBrcond : SDTypeProfile<0, 2, [ // brcond
  150. SDTCisInt<0>, SDTCisVT<1, OtherVT>
  151. ]>;
  152. def SDTBrind : SDTypeProfile<0, 1, [ // brind
  153. SDTCisPtrTy<0>
  154. ]>;
  155. def SDTNone : SDTypeProfile<0, 0, []>; // ret, trap
  156. def SDTLoad : SDTypeProfile<1, 1, [ // load
  157. SDTCisPtrTy<1>
  158. ]>;
  159. def SDTStore : SDTypeProfile<0, 2, [ // store
  160. SDTCisPtrTy<1>
  161. ]>;
  162. def SDTIStore : SDTypeProfile<1, 3, [ // indexed store
  163. SDTCisSameAs<0, 2>, SDTCisPtrTy<0>, SDTCisPtrTy<3>
  164. ]>;
  165. def SDTMaskedStore: SDTypeProfile<0, 3, [ // masked store
  166. SDTCisPtrTy<0>, SDTCisVec<1>, SDTCisVec<2>
  167. ]>;
  168. def SDTMaskedLoad: SDTypeProfile<1, 3, [ // masked load
  169. SDTCisVec<0>, SDTCisPtrTy<1>, SDTCisVec<2>, SDTCisSameAs<0, 3>
  170. ]>;
  171. def SDTMaskedGather: SDTypeProfile<2, 3, [ // masked gather
  172. SDTCisVec<0>, SDTCisVec<1>, SDTCisSameAs<0, 2>, SDTCisSameAs<1, 3>,
  173. SDTCisPtrTy<4>, SDTCVecEltisVT<1, i1>, SDTCisSameNumEltsAs<0, 1>
  174. ]>;
  175. def SDTMaskedScatter: SDTypeProfile<1, 3, [ // masked scatter
  176. SDTCisVec<0>, SDTCisVec<1>, SDTCisSameAs<0, 2>, SDTCisSameNumEltsAs<0, 1>,
  177. SDTCVecEltisVT<0, i1>, SDTCisPtrTy<3>
  178. ]>;
  179. def SDTVecShuffle : SDTypeProfile<1, 2, [
  180. SDTCisSameAs<0, 1>, SDTCisSameAs<1, 2>
  181. ]>;
  182. def SDTVecExtract : SDTypeProfile<1, 2, [ // vector extract
  183. SDTCisEltOfVec<0, 1>, SDTCisPtrTy<2>
  184. ]>;
  185. def SDTVecInsert : SDTypeProfile<1, 3, [ // vector insert
  186. SDTCisEltOfVec<2, 1>, SDTCisSameAs<0, 1>, SDTCisPtrTy<3>
  187. ]>;
  188. def SDTSubVecExtract : SDTypeProfile<1, 2, [// subvector extract
  189. SDTCisSubVecOfVec<0,1>, SDTCisInt<2>
  190. ]>;
  191. def SDTSubVecInsert : SDTypeProfile<1, 3, [ // subvector insert
  192. SDTCisSubVecOfVec<2, 1>, SDTCisSameAs<0,1>, SDTCisInt<3>
  193. ]>;
  194. def SDTPrefetch : SDTypeProfile<0, 4, [ // prefetch
  195. SDTCisPtrTy<0>, SDTCisSameAs<1, 2>, SDTCisSameAs<1, 3>, SDTCisInt<1>
  196. ]>;
  197. def SDTMemBarrier : SDTypeProfile<0, 5, [ // memory barrier
  198. SDTCisSameAs<0,1>, SDTCisSameAs<0,2>, SDTCisSameAs<0,3>, SDTCisSameAs<0,4>,
  199. SDTCisInt<0>
  200. ]>;
  201. def SDTAtomicFence : SDTypeProfile<0, 2, [
  202. SDTCisSameAs<0,1>, SDTCisPtrTy<0>
  203. ]>;
  204. def SDTAtomic3 : SDTypeProfile<1, 3, [
  205. SDTCisSameAs<0,2>, SDTCisSameAs<0,3>, SDTCisInt<0>, SDTCisPtrTy<1>
  206. ]>;
  207. def SDTAtomic2 : SDTypeProfile<1, 2, [
  208. SDTCisSameAs<0,2>, SDTCisInt<0>, SDTCisPtrTy<1>
  209. ]>;
  210. def SDTAtomicStore : SDTypeProfile<0, 2, [
  211. SDTCisPtrTy<0>, SDTCisInt<1>
  212. ]>;
  213. def SDTAtomicLoad : SDTypeProfile<1, 1, [
  214. SDTCisInt<0>, SDTCisPtrTy<1>
  215. ]>;
  216. def SDTConvertOp : SDTypeProfile<1, 5, [ //cvtss, su, us, uu, ff, fs, fu, sf, su
  217. SDTCisVT<2, OtherVT>, SDTCisVT<3, OtherVT>, SDTCisPtrTy<4>, SDTCisPtrTy<5>
  218. ]>;
  219. class SDCallSeqStart<list<SDTypeConstraint> constraints> :
  220. SDTypeProfile<0, 1, constraints>;
  221. class SDCallSeqEnd<list<SDTypeConstraint> constraints> :
  222. SDTypeProfile<0, 2, constraints>;
  223. //===----------------------------------------------------------------------===//
  224. // Selection DAG Node Properties.
  225. //
  226. // Note: These are hard coded into tblgen.
  227. //
  228. class SDNodeProperty;
  229. def SDNPCommutative : SDNodeProperty; // X op Y == Y op X
  230. def SDNPAssociative : SDNodeProperty; // (X op Y) op Z == X op (Y op Z)
  231. def SDNPHasChain : SDNodeProperty; // R/W chain operand and result
  232. def SDNPOutGlue : SDNodeProperty; // Write a flag result
  233. def SDNPInGlue : SDNodeProperty; // Read a flag operand
  234. def SDNPOptInGlue : SDNodeProperty; // Optionally read a flag operand
  235. def SDNPMayStore : SDNodeProperty; // May write to memory, sets 'mayStore'.
  236. def SDNPMayLoad : SDNodeProperty; // May read memory, sets 'mayLoad'.
  237. def SDNPSideEffect : SDNodeProperty; // Sets 'HasUnmodelledSideEffects'.
  238. def SDNPMemOperand : SDNodeProperty; // Touches memory, has assoc MemOperand
  239. def SDNPVariadic : SDNodeProperty; // Node has variable arguments.
  240. def SDNPWantRoot : SDNodeProperty; // ComplexPattern gets the root of match
  241. def SDNPWantParent : SDNodeProperty; // ComplexPattern gets the parent
  242. //===----------------------------------------------------------------------===//
  243. // Selection DAG Pattern Operations
  244. class SDPatternOperator;
  245. //===----------------------------------------------------------------------===//
  246. // Selection DAG Node definitions.
  247. //
  248. class SDNode<string opcode, SDTypeProfile typeprof,
  249. list<SDNodeProperty> props = [], string sdclass = "SDNode">
  250. : SDPatternOperator {
  251. string Opcode = opcode;
  252. string SDClass = sdclass;
  253. list<SDNodeProperty> Properties = props;
  254. SDTypeProfile TypeProfile = typeprof;
  255. }
  256. // Special TableGen-recognized dag nodes
  257. def set;
  258. def implicit;
  259. def node;
  260. def srcvalue;
  261. def imm : SDNode<"ISD::Constant" , SDTIntLeaf , [], "ConstantSDNode">;
  262. def timm : SDNode<"ISD::TargetConstant",SDTIntLeaf, [], "ConstantSDNode">;
  263. def fpimm : SDNode<"ISD::ConstantFP", SDTFPLeaf , [], "ConstantFPSDNode">;
  264. def vt : SDNode<"ISD::VALUETYPE" , SDTOther , [], "VTSDNode">;
  265. def bb : SDNode<"ISD::BasicBlock", SDTOther , [], "BasicBlockSDNode">;
  266. def cond : SDNode<"ISD::CONDCODE" , SDTOther , [], "CondCodeSDNode">;
  267. def undef : SDNode<"ISD::UNDEF" , SDTUNDEF , []>;
  268. def globaladdr : SDNode<"ISD::GlobalAddress", SDTPtrLeaf, [],
  269. "GlobalAddressSDNode">;
  270. def tglobaladdr : SDNode<"ISD::TargetGlobalAddress", SDTPtrLeaf, [],
  271. "GlobalAddressSDNode">;
  272. def globaltlsaddr : SDNode<"ISD::GlobalTLSAddress", SDTPtrLeaf, [],
  273. "GlobalAddressSDNode">;
  274. def tglobaltlsaddr : SDNode<"ISD::TargetGlobalTLSAddress", SDTPtrLeaf, [],
  275. "GlobalAddressSDNode">;
  276. def constpool : SDNode<"ISD::ConstantPool", SDTPtrLeaf, [],
  277. "ConstantPoolSDNode">;
  278. def tconstpool : SDNode<"ISD::TargetConstantPool", SDTPtrLeaf, [],
  279. "ConstantPoolSDNode">;
  280. def jumptable : SDNode<"ISD::JumpTable", SDTPtrLeaf, [],
  281. "JumpTableSDNode">;
  282. def tjumptable : SDNode<"ISD::TargetJumpTable", SDTPtrLeaf, [],
  283. "JumpTableSDNode">;
  284. def frameindex : SDNode<"ISD::FrameIndex", SDTPtrLeaf, [],
  285. "FrameIndexSDNode">;
  286. def tframeindex : SDNode<"ISD::TargetFrameIndex", SDTPtrLeaf, [],
  287. "FrameIndexSDNode">;
  288. def externalsym : SDNode<"ISD::ExternalSymbol", SDTPtrLeaf, [],
  289. "ExternalSymbolSDNode">;
  290. def texternalsym: SDNode<"ISD::TargetExternalSymbol", SDTPtrLeaf, [],
  291. "ExternalSymbolSDNode">;
  292. def mcsym: SDNode<"ISD::MCSymbol", SDTPtrLeaf, [], "MCSymbolSDNode">;
  293. def blockaddress : SDNode<"ISD::BlockAddress", SDTPtrLeaf, [],
  294. "BlockAddressSDNode">;
  295. def tblockaddress: SDNode<"ISD::TargetBlockAddress", SDTPtrLeaf, [],
  296. "BlockAddressSDNode">;
  297. def add : SDNode<"ISD::ADD" , SDTIntBinOp ,
  298. [SDNPCommutative, SDNPAssociative]>;
  299. def sub : SDNode<"ISD::SUB" , SDTIntBinOp>;
  300. def mul : SDNode<"ISD::MUL" , SDTIntBinOp,
  301. [SDNPCommutative, SDNPAssociative]>;
  302. def mulhs : SDNode<"ISD::MULHS" , SDTIntBinOp, [SDNPCommutative]>;
  303. def mulhu : SDNode<"ISD::MULHU" , SDTIntBinOp, [SDNPCommutative]>;
  304. def smullohi : SDNode<"ISD::SMUL_LOHI" , SDTIntBinHiLoOp, [SDNPCommutative]>;
  305. def umullohi : SDNode<"ISD::UMUL_LOHI" , SDTIntBinHiLoOp, [SDNPCommutative]>;
  306. def sdiv : SDNode<"ISD::SDIV" , SDTIntBinOp>;
  307. def udiv : SDNode<"ISD::UDIV" , SDTIntBinOp>;
  308. def srem : SDNode<"ISD::SREM" , SDTIntBinOp>;
  309. def urem : SDNode<"ISD::UREM" , SDTIntBinOp>;
  310. def sdivrem : SDNode<"ISD::SDIVREM" , SDTIntBinHiLoOp>;
  311. def udivrem : SDNode<"ISD::UDIVREM" , SDTIntBinHiLoOp>;
  312. def srl : SDNode<"ISD::SRL" , SDTIntShiftOp>;
  313. def sra : SDNode<"ISD::SRA" , SDTIntShiftOp>;
  314. def shl : SDNode<"ISD::SHL" , SDTIntShiftOp>;
  315. def rotl : SDNode<"ISD::ROTL" , SDTIntShiftOp>;
  316. def rotr : SDNode<"ISD::ROTR" , SDTIntShiftOp>;
  317. def and : SDNode<"ISD::AND" , SDTIntBinOp,
  318. [SDNPCommutative, SDNPAssociative]>;
  319. def or : SDNode<"ISD::OR" , SDTIntBinOp,
  320. [SDNPCommutative, SDNPAssociative]>;
  321. def xor : SDNode<"ISD::XOR" , SDTIntBinOp,
  322. [SDNPCommutative, SDNPAssociative]>;
  323. def addc : SDNode<"ISD::ADDC" , SDTIntBinOp,
  324. [SDNPCommutative, SDNPOutGlue]>;
  325. def adde : SDNode<"ISD::ADDE" , SDTIntBinOp,
  326. [SDNPCommutative, SDNPOutGlue, SDNPInGlue]>;
  327. def subc : SDNode<"ISD::SUBC" , SDTIntBinOp,
  328. [SDNPOutGlue]>;
  329. def sube : SDNode<"ISD::SUBE" , SDTIntBinOp,
  330. [SDNPOutGlue, SDNPInGlue]>;
  331. def smin : SDNode<"ISD::SMIN" , SDTIntBinOp>;
  332. def smax : SDNode<"ISD::SMAX" , SDTIntBinOp>;
  333. def umin : SDNode<"ISD::UMIN" , SDTIntBinOp>;
  334. def umax : SDNode<"ISD::UMAX" , SDTIntBinOp>;
  335. def sext_inreg : SDNode<"ISD::SIGN_EXTEND_INREG", SDTExtInreg>;
  336. def bswap : SDNode<"ISD::BSWAP" , SDTIntUnaryOp>;
  337. def ctlz : SDNode<"ISD::CTLZ" , SDTIntUnaryOp>;
  338. def cttz : SDNode<"ISD::CTTZ" , SDTIntUnaryOp>;
  339. def ctpop : SDNode<"ISD::CTPOP" , SDTIntUnaryOp>;
  340. def ctlz_zero_undef : SDNode<"ISD::CTLZ_ZERO_UNDEF", SDTIntUnaryOp>;
  341. def cttz_zero_undef : SDNode<"ISD::CTTZ_ZERO_UNDEF", SDTIntUnaryOp>;
  342. def sext : SDNode<"ISD::SIGN_EXTEND", SDTIntExtendOp>;
  343. def zext : SDNode<"ISD::ZERO_EXTEND", SDTIntExtendOp>;
  344. def anyext : SDNode<"ISD::ANY_EXTEND" , SDTIntExtendOp>;
  345. def trunc : SDNode<"ISD::TRUNCATE" , SDTIntTruncOp>;
  346. def bitconvert : SDNode<"ISD::BITCAST" , SDTUnaryOp>;
  347. def addrspacecast : SDNode<"ISD::ADDRSPACECAST", SDTUnaryOp>;
  348. def extractelt : SDNode<"ISD::EXTRACT_VECTOR_ELT", SDTVecExtract>;
  349. def insertelt : SDNode<"ISD::INSERT_VECTOR_ELT", SDTVecInsert>;
  350. def fadd : SDNode<"ISD::FADD" , SDTFPBinOp, [SDNPCommutative]>;
  351. def fsub : SDNode<"ISD::FSUB" , SDTFPBinOp>;
  352. def fmul : SDNode<"ISD::FMUL" , SDTFPBinOp, [SDNPCommutative]>;
  353. def fdiv : SDNode<"ISD::FDIV" , SDTFPBinOp>;
  354. def frem : SDNode<"ISD::FREM" , SDTFPBinOp>;
  355. def fma : SDNode<"ISD::FMA" , SDTFPTernaryOp>;
  356. def fmad : SDNode<"ISD::FMAD" , SDTFPTernaryOp>;
  357. def fabs : SDNode<"ISD::FABS" , SDTFPUnaryOp>;
  358. def fminnum : SDNode<"ISD::FMINNUM" , SDTFPBinOp>;
  359. def fmaxnum : SDNode<"ISD::FMAXNUM" , SDTFPBinOp>;
  360. def fgetsign : SDNode<"ISD::FGETSIGN" , SDTFPToIntOp>;
  361. def fneg : SDNode<"ISD::FNEG" , SDTFPUnaryOp>;
  362. def fsqrt : SDNode<"ISD::FSQRT" , SDTFPUnaryOp>;
  363. def fsin : SDNode<"ISD::FSIN" , SDTFPUnaryOp>;
  364. def fcos : SDNode<"ISD::FCOS" , SDTFPUnaryOp>;
  365. def fexp2 : SDNode<"ISD::FEXP2" , SDTFPUnaryOp>;
  366. def fpow : SDNode<"ISD::FPOW" , SDTFPBinOp>;
  367. def flog2 : SDNode<"ISD::FLOG2" , SDTFPUnaryOp>;
  368. def frint : SDNode<"ISD::FRINT" , SDTFPUnaryOp>;
  369. def ftrunc : SDNode<"ISD::FTRUNC" , SDTFPUnaryOp>;
  370. def fceil : SDNode<"ISD::FCEIL" , SDTFPUnaryOp>;
  371. def ffloor : SDNode<"ISD::FFLOOR" , SDTFPUnaryOp>;
  372. def fnearbyint : SDNode<"ISD::FNEARBYINT" , SDTFPUnaryOp>;
  373. def frnd : SDNode<"ISD::FROUND" , SDTFPUnaryOp>;
  374. def fround : SDNode<"ISD::FP_ROUND" , SDTFPRoundOp>;
  375. def fextend : SDNode<"ISD::FP_EXTEND" , SDTFPExtendOp>;
  376. def fcopysign : SDNode<"ISD::FCOPYSIGN" , SDTFPSignOp>;
  377. def sint_to_fp : SDNode<"ISD::SINT_TO_FP" , SDTIntToFPOp>;
  378. def uint_to_fp : SDNode<"ISD::UINT_TO_FP" , SDTIntToFPOp>;
  379. def fp_to_sint : SDNode<"ISD::FP_TO_SINT" , SDTFPToIntOp>;
  380. def fp_to_uint : SDNode<"ISD::FP_TO_UINT" , SDTFPToIntOp>;
  381. def f16_to_fp : SDNode<"ISD::FP16_TO_FP" , SDTIntToFPOp>;
  382. def fp_to_f16 : SDNode<"ISD::FP_TO_FP16" , SDTFPToIntOp>;
  383. def setcc : SDNode<"ISD::SETCC" , SDTSetCC>;
  384. def select : SDNode<"ISD::SELECT" , SDTSelect>;
  385. def vselect : SDNode<"ISD::VSELECT" , SDTVSelect>;
  386. def selectcc : SDNode<"ISD::SELECT_CC" , SDTSelectCC>;
  387. def brcc : SDNode<"ISD::BR_CC" , SDTBrCC, [SDNPHasChain]>;
  388. def brcond : SDNode<"ISD::BRCOND" , SDTBrcond, [SDNPHasChain]>;
  389. def brind : SDNode<"ISD::BRIND" , SDTBrind, [SDNPHasChain]>;
  390. def br : SDNode<"ISD::BR" , SDTBr, [SDNPHasChain]>;
  391. def trap : SDNode<"ISD::TRAP" , SDTNone,
  392. [SDNPHasChain, SDNPSideEffect]>;
  393. def debugtrap : SDNode<"ISD::DEBUGTRAP" , SDTNone,
  394. [SDNPHasChain, SDNPSideEffect]>;
  395. def prefetch : SDNode<"ISD::PREFETCH" , SDTPrefetch,
  396. [SDNPHasChain, SDNPMayLoad, SDNPMayStore,
  397. SDNPMemOperand]>;
  398. def readcyclecounter : SDNode<"ISD::READCYCLECOUNTER", SDTIntLeaf,
  399. [SDNPHasChain, SDNPSideEffect]>;
  400. def atomic_fence : SDNode<"ISD::ATOMIC_FENCE" , SDTAtomicFence,
  401. [SDNPHasChain, SDNPSideEffect]>;
  402. def atomic_cmp_swap : SDNode<"ISD::ATOMIC_CMP_SWAP" , SDTAtomic3,
  403. [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
  404. def atomic_load_add : SDNode<"ISD::ATOMIC_LOAD_ADD" , SDTAtomic2,
  405. [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
  406. def atomic_swap : SDNode<"ISD::ATOMIC_SWAP", SDTAtomic2,
  407. [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
  408. def atomic_load_sub : SDNode<"ISD::ATOMIC_LOAD_SUB" , SDTAtomic2,
  409. [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
  410. def atomic_load_and : SDNode<"ISD::ATOMIC_LOAD_AND" , SDTAtomic2,
  411. [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
  412. def atomic_load_or : SDNode<"ISD::ATOMIC_LOAD_OR" , SDTAtomic2,
  413. [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
  414. def atomic_load_xor : SDNode<"ISD::ATOMIC_LOAD_XOR" , SDTAtomic2,
  415. [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
  416. def atomic_load_nand: SDNode<"ISD::ATOMIC_LOAD_NAND", SDTAtomic2,
  417. [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
  418. def atomic_load_min : SDNode<"ISD::ATOMIC_LOAD_MIN", SDTAtomic2,
  419. [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
  420. def atomic_load_max : SDNode<"ISD::ATOMIC_LOAD_MAX", SDTAtomic2,
  421. [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
  422. def atomic_load_umin : SDNode<"ISD::ATOMIC_LOAD_UMIN", SDTAtomic2,
  423. [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
  424. def atomic_load_umax : SDNode<"ISD::ATOMIC_LOAD_UMAX", SDTAtomic2,
  425. [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
  426. def atomic_load : SDNode<"ISD::ATOMIC_LOAD", SDTAtomicLoad,
  427. [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
  428. def atomic_store : SDNode<"ISD::ATOMIC_STORE", SDTAtomicStore,
  429. [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
  430. def masked_store : SDNode<"ISD::MSTORE", SDTMaskedStore,
  431. [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
  432. def masked_load : SDNode<"ISD::MLOAD", SDTMaskedLoad,
  433. [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
  434. def masked_scatter : SDNode<"ISD::MSCATTER", SDTMaskedScatter,
  435. [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
  436. def masked_gather : SDNode<"ISD::MGATHER", SDTMaskedGather,
  437. [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
  438. // Do not use ld, st directly. Use load, extload, sextload, zextload, store,
  439. // and truncst (see below).
  440. def ld : SDNode<"ISD::LOAD" , SDTLoad,
  441. [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
  442. def st : SDNode<"ISD::STORE" , SDTStore,
  443. [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
  444. def ist : SDNode<"ISD::STORE" , SDTIStore,
  445. [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
  446. def vector_shuffle : SDNode<"ISD::VECTOR_SHUFFLE", SDTVecShuffle, []>;
  447. def build_vector : SDNode<"ISD::BUILD_VECTOR", SDTypeProfile<1, -1, []>, []>;
  448. def scalar_to_vector : SDNode<"ISD::SCALAR_TO_VECTOR", SDTypeProfile<1, 1, []>,
  449. []>;
  450. def vector_extract : SDNode<"ISD::EXTRACT_VECTOR_ELT",
  451. SDTypeProfile<1, 2, [SDTCisPtrTy<2>]>, []>;
  452. def vector_insert : SDNode<"ISD::INSERT_VECTOR_ELT",
  453. SDTypeProfile<1, 3, [SDTCisSameAs<0, 1>, SDTCisPtrTy<3>]>, []>;
  454. def concat_vectors : SDNode<"ISD::CONCAT_VECTORS",
  455. SDTypeProfile<1, 2, [SDTCisSubVecOfVec<1, 0>, SDTCisSameAs<1, 2>]>,[]>;
  456. // This operator does not do subvector type checking. The ARM
  457. // backend, at least, needs it.
  458. def vector_extract_subvec : SDNode<"ISD::EXTRACT_SUBVECTOR",
  459. SDTypeProfile<1, 2, [SDTCisInt<2>, SDTCisVec<1>, SDTCisVec<0>]>,
  460. []>;
  461. // This operator does subvector type checking.
  462. def extract_subvector : SDNode<"ISD::EXTRACT_SUBVECTOR", SDTSubVecExtract, []>;
  463. def insert_subvector : SDNode<"ISD::INSERT_SUBVECTOR", SDTSubVecInsert, []>;
  464. // Nodes for intrinsics, you should use the intrinsic itself and let tblgen use
  465. // these internally. Don't reference these directly.
  466. def intrinsic_void : SDNode<"ISD::INTRINSIC_VOID",
  467. SDTypeProfile<0, -1, [SDTCisPtrTy<0>]>,
  468. [SDNPHasChain]>;
  469. def intrinsic_w_chain : SDNode<"ISD::INTRINSIC_W_CHAIN",
  470. SDTypeProfile<1, -1, [SDTCisPtrTy<1>]>,
  471. [SDNPHasChain]>;
  472. def intrinsic_wo_chain : SDNode<"ISD::INTRINSIC_WO_CHAIN",
  473. SDTypeProfile<1, -1, [SDTCisPtrTy<1>]>, []>;
  474. // Do not use cvt directly. Use cvt forms below
  475. def cvt : SDNode<"ISD::CONVERT_RNDSAT", SDTConvertOp>;
  476. def SDT_assertext : SDTypeProfile<1, 1,
  477. [SDTCisInt<0>, SDTCisInt<1>, SDTCisSameAs<1, 0>]>;
  478. def assertsext : SDNode<"ISD::AssertSext", SDT_assertext>;
  479. def assertzext : SDNode<"ISD::AssertZext", SDT_assertext>;
  480. //===----------------------------------------------------------------------===//
  481. // Selection DAG Condition Codes
  482. class CondCode; // ISD::CondCode enums
  483. def SETOEQ : CondCode; def SETOGT : CondCode;
  484. def SETOGE : CondCode; def SETOLT : CondCode; def SETOLE : CondCode;
  485. def SETONE : CondCode; def SETO : CondCode; def SETUO : CondCode;
  486. def SETUEQ : CondCode; def SETUGT : CondCode; def SETUGE : CondCode;
  487. def SETULT : CondCode; def SETULE : CondCode; def SETUNE : CondCode;
  488. def SETEQ : CondCode; def SETGT : CondCode; def SETGE : CondCode;
  489. def SETLT : CondCode; def SETLE : CondCode; def SETNE : CondCode;
  490. //===----------------------------------------------------------------------===//
  491. // Selection DAG Node Transformation Functions.
  492. //
  493. // This mechanism allows targets to manipulate nodes in the output DAG once a
  494. // match has been formed. This is typically used to manipulate immediate
  495. // values.
  496. //
  497. class SDNodeXForm<SDNode opc, code xformFunction> {
  498. SDNode Opcode = opc;
  499. code XFormFunction = xformFunction;
  500. }
  501. def NOOP_SDNodeXForm : SDNodeXForm<imm, [{}]>;
  502. //===----------------------------------------------------------------------===//
  503. // PatPred Subclasses.
  504. //
  505. // These allow specifying different sorts of predicates that control whether a
  506. // node is matched.
  507. //
  508. class PatPred;
  509. class CodePatPred<code predicate> : PatPred {
  510. code PredicateCode = predicate;
  511. }
  512. //===----------------------------------------------------------------------===//
  513. // Selection DAG Pattern Fragments.
  514. //
  515. // Pattern fragments are reusable chunks of dags that match specific things.
  516. // They can take arguments and have C++ predicates that control whether they
  517. // match. They are intended to make the patterns for common instructions more
  518. // compact and readable.
  519. //
  520. /// PatFrag - Represents a pattern fragment. This can match something on the
  521. /// DAG, from a single node to multiple nested other fragments.
  522. ///
  523. class PatFrag<dag ops, dag frag, code pred = [{}],
  524. SDNodeXForm xform = NOOP_SDNodeXForm> : SDPatternOperator {
  525. dag Operands = ops;
  526. dag Fragment = frag;
  527. code PredicateCode = pred;
  528. code ImmediateCode = [{}];
  529. SDNodeXForm OperandTransform = xform;
  530. }
  531. // OutPatFrag is a pattern fragment that is used as part of an output pattern
  532. // (not an input pattern). These do not have predicates or transforms, but are
  533. // used to avoid repeated subexpressions in output patterns.
  534. class OutPatFrag<dag ops, dag frag>
  535. : PatFrag<ops, frag, [{}], NOOP_SDNodeXForm>;
  536. // PatLeaf's are pattern fragments that have no operands. This is just a helper
  537. // to define immediates and other common things concisely.
  538. class PatLeaf<dag frag, code pred = [{}], SDNodeXForm xform = NOOP_SDNodeXForm>
  539. : PatFrag<(ops), frag, pred, xform>;
  540. // ImmLeaf is a pattern fragment with a constraint on the immediate. The
  541. // constraint is a function that is run on the immediate (always with the value
  542. // sign extended out to an int64_t) as Imm. For example:
  543. //
  544. // def immSExt8 : ImmLeaf<i16, [{ return (char)Imm == Imm; }]>;
  545. //
  546. // this is a more convenient form to match 'imm' nodes in than PatLeaf and also
  547. // is preferred over using PatLeaf because it allows the code generator to
  548. // reason more about the constraint.
  549. //
  550. // If FastIsel should ignore all instructions that have an operand of this type,
  551. // the FastIselShouldIgnore flag can be set. This is an optimization to reduce
  552. // the code size of the generated fast instruction selector.
  553. class ImmLeaf<ValueType vt, code pred, SDNodeXForm xform = NOOP_SDNodeXForm>
  554. : PatFrag<(ops), (vt imm), [{}], xform> {
  555. let ImmediateCode = pred;
  556. bit FastIselShouldIgnore = 0;
  557. }
  558. // Leaf fragments.
  559. def vtInt : PatLeaf<(vt), [{ return N->getVT().isInteger(); }]>;
  560. def vtFP : PatLeaf<(vt), [{ return N->getVT().isFloatingPoint(); }]>;
  561. def immAllOnesV: PatLeaf<(build_vector), [{
  562. return ISD::isBuildVectorAllOnes(N);
  563. }]>;
  564. def immAllZerosV: PatLeaf<(build_vector), [{
  565. return ISD::isBuildVectorAllZeros(N);
  566. }]>;
  567. // Other helper fragments.
  568. def not : PatFrag<(ops node:$in), (xor node:$in, -1)>;
  569. def vnot : PatFrag<(ops node:$in), (xor node:$in, immAllOnesV)>;
  570. def ineg : PatFrag<(ops node:$in), (sub 0, node:$in)>;
  571. // null_frag - The null pattern operator is used in multiclass instantiations
  572. // which accept an SDPatternOperator for use in matching patterns for internal
  573. // definitions. When expanding a pattern, if the null fragment is referenced
  574. // in the expansion, the pattern is discarded and it is as-if '[]' had been
  575. // specified. This allows multiclasses to have the isel patterns be optional.
  576. def null_frag : SDPatternOperator;
  577. // load fragments.
  578. def unindexedload : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
  579. return cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
  580. }]>;
  581. def load : PatFrag<(ops node:$ptr), (unindexedload node:$ptr), [{
  582. return cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
  583. }]>;
  584. // extending load fragments.
  585. def extload : PatFrag<(ops node:$ptr), (unindexedload node:$ptr), [{
  586. return cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
  587. }]>;
  588. def sextload : PatFrag<(ops node:$ptr), (unindexedload node:$ptr), [{
  589. return cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
  590. }]>;
  591. def zextload : PatFrag<(ops node:$ptr), (unindexedload node:$ptr), [{
  592. return cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
  593. }]>;
  594. def extloadi1 : PatFrag<(ops node:$ptr), (extload node:$ptr), [{
  595. return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i1;
  596. }]>;
  597. def extloadi8 : PatFrag<(ops node:$ptr), (extload node:$ptr), [{
  598. return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i8;
  599. }]>;
  600. def extloadi16 : PatFrag<(ops node:$ptr), (extload node:$ptr), [{
  601. return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i16;
  602. }]>;
  603. def extloadi32 : PatFrag<(ops node:$ptr), (extload node:$ptr), [{
  604. return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i32;
  605. }]>;
  606. def extloadf32 : PatFrag<(ops node:$ptr), (extload node:$ptr), [{
  607. return cast<LoadSDNode>(N)->getMemoryVT() == MVT::f32;
  608. }]>;
  609. def extloadf64 : PatFrag<(ops node:$ptr), (extload node:$ptr), [{
  610. return cast<LoadSDNode>(N)->getMemoryVT() == MVT::f64;
  611. }]>;
  612. def sextloadi1 : PatFrag<(ops node:$ptr), (sextload node:$ptr), [{
  613. return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i1;
  614. }]>;
  615. def sextloadi8 : PatFrag<(ops node:$ptr), (sextload node:$ptr), [{
  616. return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i8;
  617. }]>;
  618. def sextloadi16 : PatFrag<(ops node:$ptr), (sextload node:$ptr), [{
  619. return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i16;
  620. }]>;
  621. def sextloadi32 : PatFrag<(ops node:$ptr), (sextload node:$ptr), [{
  622. return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i32;
  623. }]>;
  624. def zextloadi1 : PatFrag<(ops node:$ptr), (zextload node:$ptr), [{
  625. return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i1;
  626. }]>;
  627. def zextloadi8 : PatFrag<(ops node:$ptr), (zextload node:$ptr), [{
  628. return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i8;
  629. }]>;
  630. def zextloadi16 : PatFrag<(ops node:$ptr), (zextload node:$ptr), [{
  631. return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i16;
  632. }]>;
  633. def zextloadi32 : PatFrag<(ops node:$ptr), (zextload node:$ptr), [{
  634. return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i32;
  635. }]>;
  636. def extloadvi1 : PatFrag<(ops node:$ptr), (extload node:$ptr), [{
  637. return cast<LoadSDNode>(N)->getMemoryVT().getScalarType() == MVT::i1;
  638. }]>;
  639. def extloadvi8 : PatFrag<(ops node:$ptr), (extload node:$ptr), [{
  640. return cast<LoadSDNode>(N)->getMemoryVT().getScalarType() == MVT::i8;
  641. }]>;
  642. def extloadvi16 : PatFrag<(ops node:$ptr), (extload node:$ptr), [{
  643. return cast<LoadSDNode>(N)->getMemoryVT().getScalarType() == MVT::i16;
  644. }]>;
  645. def extloadvi32 : PatFrag<(ops node:$ptr), (extload node:$ptr), [{
  646. return cast<LoadSDNode>(N)->getMemoryVT().getScalarType() == MVT::i32;
  647. }]>;
  648. def extloadvf32 : PatFrag<(ops node:$ptr), (extload node:$ptr), [{
  649. return cast<LoadSDNode>(N)->getMemoryVT().getScalarType() == MVT::f32;
  650. }]>;
  651. def extloadvf64 : PatFrag<(ops node:$ptr), (extload node:$ptr), [{
  652. return cast<LoadSDNode>(N)->getMemoryVT().getScalarType() == MVT::f64;
  653. }]>;
  654. def sextloadvi1 : PatFrag<(ops node:$ptr), (sextload node:$ptr), [{
  655. return cast<LoadSDNode>(N)->getMemoryVT().getScalarType() == MVT::i1;
  656. }]>;
  657. def sextloadvi8 : PatFrag<(ops node:$ptr), (sextload node:$ptr), [{
  658. return cast<LoadSDNode>(N)->getMemoryVT().getScalarType() == MVT::i8;
  659. }]>;
  660. def sextloadvi16 : PatFrag<(ops node:$ptr), (sextload node:$ptr), [{
  661. return cast<LoadSDNode>(N)->getMemoryVT().getScalarType() == MVT::i16;
  662. }]>;
  663. def sextloadvi32 : PatFrag<(ops node:$ptr), (sextload node:$ptr), [{
  664. return cast<LoadSDNode>(N)->getMemoryVT().getScalarType() == MVT::i32;
  665. }]>;
  666. def zextloadvi1 : PatFrag<(ops node:$ptr), (zextload node:$ptr), [{
  667. return cast<LoadSDNode>(N)->getMemoryVT().getScalarType() == MVT::i1;
  668. }]>;
  669. def zextloadvi8 : PatFrag<(ops node:$ptr), (zextload node:$ptr), [{
  670. return cast<LoadSDNode>(N)->getMemoryVT().getScalarType() == MVT::i8;
  671. }]>;
  672. def zextloadvi16 : PatFrag<(ops node:$ptr), (zextload node:$ptr), [{
  673. return cast<LoadSDNode>(N)->getMemoryVT().getScalarType() == MVT::i16;
  674. }]>;
  675. def zextloadvi32 : PatFrag<(ops node:$ptr), (zextload node:$ptr), [{
  676. return cast<LoadSDNode>(N)->getMemoryVT().getScalarType() == MVT::i32;
  677. }]>;
  678. // store fragments.
  679. def unindexedstore : PatFrag<(ops node:$val, node:$ptr),
  680. (st node:$val, node:$ptr), [{
  681. return cast<StoreSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
  682. }]>;
  683. def store : PatFrag<(ops node:$val, node:$ptr),
  684. (unindexedstore node:$val, node:$ptr), [{
  685. return !cast<StoreSDNode>(N)->isTruncatingStore();
  686. }]>;
  687. // truncstore fragments.
  688. def truncstore : PatFrag<(ops node:$val, node:$ptr),
  689. (unindexedstore node:$val, node:$ptr), [{
  690. return cast<StoreSDNode>(N)->isTruncatingStore();
  691. }]>;
  692. def truncstorei8 : PatFrag<(ops node:$val, node:$ptr),
  693. (truncstore node:$val, node:$ptr), [{
  694. return cast<StoreSDNode>(N)->getMemoryVT() == MVT::i8;
  695. }]>;
  696. def truncstorei16 : PatFrag<(ops node:$val, node:$ptr),
  697. (truncstore node:$val, node:$ptr), [{
  698. return cast<StoreSDNode>(N)->getMemoryVT() == MVT::i16;
  699. }]>;
  700. def truncstorei32 : PatFrag<(ops node:$val, node:$ptr),
  701. (truncstore node:$val, node:$ptr), [{
  702. return cast<StoreSDNode>(N)->getMemoryVT() == MVT::i32;
  703. }]>;
  704. def truncstoref32 : PatFrag<(ops node:$val, node:$ptr),
  705. (truncstore node:$val, node:$ptr), [{
  706. return cast<StoreSDNode>(N)->getMemoryVT() == MVT::f32;
  707. }]>;
  708. def truncstoref64 : PatFrag<(ops node:$val, node:$ptr),
  709. (truncstore node:$val, node:$ptr), [{
  710. return cast<StoreSDNode>(N)->getMemoryVT() == MVT::f64;
  711. }]>;
  712. // indexed store fragments.
  713. def istore : PatFrag<(ops node:$val, node:$base, node:$offset),
  714. (ist node:$val, node:$base, node:$offset), [{
  715. return !cast<StoreSDNode>(N)->isTruncatingStore();
  716. }]>;
  717. def pre_store : PatFrag<(ops node:$val, node:$base, node:$offset),
  718. (istore node:$val, node:$base, node:$offset), [{
  719. ISD::MemIndexedMode AM = cast<StoreSDNode>(N)->getAddressingMode();
  720. return AM == ISD::PRE_INC || AM == ISD::PRE_DEC;
  721. }]>;
  722. def itruncstore : PatFrag<(ops node:$val, node:$base, node:$offset),
  723. (ist node:$val, node:$base, node:$offset), [{
  724. return cast<StoreSDNode>(N)->isTruncatingStore();
  725. }]>;
  726. def pre_truncst : PatFrag<(ops node:$val, node:$base, node:$offset),
  727. (itruncstore node:$val, node:$base, node:$offset), [{
  728. ISD::MemIndexedMode AM = cast<StoreSDNode>(N)->getAddressingMode();
  729. return AM == ISD::PRE_INC || AM == ISD::PRE_DEC;
  730. }]>;
  731. def pre_truncsti1 : PatFrag<(ops node:$val, node:$base, node:$offset),
  732. (pre_truncst node:$val, node:$base, node:$offset), [{
  733. return cast<StoreSDNode>(N)->getMemoryVT() == MVT::i1;
  734. }]>;
  735. def pre_truncsti8 : PatFrag<(ops node:$val, node:$base, node:$offset),
  736. (pre_truncst node:$val, node:$base, node:$offset), [{
  737. return cast<StoreSDNode>(N)->getMemoryVT() == MVT::i8;
  738. }]>;
  739. def pre_truncsti16 : PatFrag<(ops node:$val, node:$base, node:$offset),
  740. (pre_truncst node:$val, node:$base, node:$offset), [{
  741. return cast<StoreSDNode>(N)->getMemoryVT() == MVT::i16;
  742. }]>;
  743. def pre_truncsti32 : PatFrag<(ops node:$val, node:$base, node:$offset),
  744. (pre_truncst node:$val, node:$base, node:$offset), [{
  745. return cast<StoreSDNode>(N)->getMemoryVT() == MVT::i32;
  746. }]>;
  747. def pre_truncstf32 : PatFrag<(ops node:$val, node:$base, node:$offset),
  748. (pre_truncst node:$val, node:$base, node:$offset), [{
  749. return cast<StoreSDNode>(N)->getMemoryVT() == MVT::f32;
  750. }]>;
  751. def post_store : PatFrag<(ops node:$val, node:$ptr, node:$offset),
  752. (istore node:$val, node:$ptr, node:$offset), [{
  753. ISD::MemIndexedMode AM = cast<StoreSDNode>(N)->getAddressingMode();
  754. return AM == ISD::POST_INC || AM == ISD::POST_DEC;
  755. }]>;
  756. def post_truncst : PatFrag<(ops node:$val, node:$base, node:$offset),
  757. (itruncstore node:$val, node:$base, node:$offset), [{
  758. ISD::MemIndexedMode AM = cast<StoreSDNode>(N)->getAddressingMode();
  759. return AM == ISD::POST_INC || AM == ISD::POST_DEC;
  760. }]>;
  761. def post_truncsti1 : PatFrag<(ops node:$val, node:$base, node:$offset),
  762. (post_truncst node:$val, node:$base, node:$offset), [{
  763. return cast<StoreSDNode>(N)->getMemoryVT() == MVT::i1;
  764. }]>;
  765. def post_truncsti8 : PatFrag<(ops node:$val, node:$base, node:$offset),
  766. (post_truncst node:$val, node:$base, node:$offset), [{
  767. return cast<StoreSDNode>(N)->getMemoryVT() == MVT::i8;
  768. }]>;
  769. def post_truncsti16 : PatFrag<(ops node:$val, node:$base, node:$offset),
  770. (post_truncst node:$val, node:$base, node:$offset), [{
  771. return cast<StoreSDNode>(N)->getMemoryVT() == MVT::i16;
  772. }]>;
  773. def post_truncsti32 : PatFrag<(ops node:$val, node:$base, node:$offset),
  774. (post_truncst node:$val, node:$base, node:$offset), [{
  775. return cast<StoreSDNode>(N)->getMemoryVT() == MVT::i32;
  776. }]>;
  777. def post_truncstf32 : PatFrag<(ops node:$val, node:$base, node:$offset),
  778. (post_truncst node:$val, node:$base, node:$offset), [{
  779. return cast<StoreSDNode>(N)->getMemoryVT() == MVT::f32;
  780. }]>;
  781. // setcc convenience fragments.
  782. def setoeq : PatFrag<(ops node:$lhs, node:$rhs),
  783. (setcc node:$lhs, node:$rhs, SETOEQ)>;
  784. def setogt : PatFrag<(ops node:$lhs, node:$rhs),
  785. (setcc node:$lhs, node:$rhs, SETOGT)>;
  786. def setoge : PatFrag<(ops node:$lhs, node:$rhs),
  787. (setcc node:$lhs, node:$rhs, SETOGE)>;
  788. def setolt : PatFrag<(ops node:$lhs, node:$rhs),
  789. (setcc node:$lhs, node:$rhs, SETOLT)>;
  790. def setole : PatFrag<(ops node:$lhs, node:$rhs),
  791. (setcc node:$lhs, node:$rhs, SETOLE)>;
  792. def setone : PatFrag<(ops node:$lhs, node:$rhs),
  793. (setcc node:$lhs, node:$rhs, SETONE)>;
  794. def seto : PatFrag<(ops node:$lhs, node:$rhs),
  795. (setcc node:$lhs, node:$rhs, SETO)>;
  796. def setuo : PatFrag<(ops node:$lhs, node:$rhs),
  797. (setcc node:$lhs, node:$rhs, SETUO)>;
  798. def setueq : PatFrag<(ops node:$lhs, node:$rhs),
  799. (setcc node:$lhs, node:$rhs, SETUEQ)>;
  800. def setugt : PatFrag<(ops node:$lhs, node:$rhs),
  801. (setcc node:$lhs, node:$rhs, SETUGT)>;
  802. def setuge : PatFrag<(ops node:$lhs, node:$rhs),
  803. (setcc node:$lhs, node:$rhs, SETUGE)>;
  804. def setult : PatFrag<(ops node:$lhs, node:$rhs),
  805. (setcc node:$lhs, node:$rhs, SETULT)>;
  806. def setule : PatFrag<(ops node:$lhs, node:$rhs),
  807. (setcc node:$lhs, node:$rhs, SETULE)>;
  808. def setune : PatFrag<(ops node:$lhs, node:$rhs),
  809. (setcc node:$lhs, node:$rhs, SETUNE)>;
  810. def seteq : PatFrag<(ops node:$lhs, node:$rhs),
  811. (setcc node:$lhs, node:$rhs, SETEQ)>;
  812. def setgt : PatFrag<(ops node:$lhs, node:$rhs),
  813. (setcc node:$lhs, node:$rhs, SETGT)>;
  814. def setge : PatFrag<(ops node:$lhs, node:$rhs),
  815. (setcc node:$lhs, node:$rhs, SETGE)>;
  816. def setlt : PatFrag<(ops node:$lhs, node:$rhs),
  817. (setcc node:$lhs, node:$rhs, SETLT)>;
  818. def setle : PatFrag<(ops node:$lhs, node:$rhs),
  819. (setcc node:$lhs, node:$rhs, SETLE)>;
  820. def setne : PatFrag<(ops node:$lhs, node:$rhs),
  821. (setcc node:$lhs, node:$rhs, SETNE)>;
  822. def atomic_cmp_swap_8 :
  823. PatFrag<(ops node:$ptr, node:$cmp, node:$swap),
  824. (atomic_cmp_swap node:$ptr, node:$cmp, node:$swap), [{
  825. return cast<AtomicSDNode>(N)->getMemoryVT() == MVT::i8;
  826. }]>;
  827. def atomic_cmp_swap_16 :
  828. PatFrag<(ops node:$ptr, node:$cmp, node:$swap),
  829. (atomic_cmp_swap node:$ptr, node:$cmp, node:$swap), [{
  830. return cast<AtomicSDNode>(N)->getMemoryVT() == MVT::i16;
  831. }]>;
  832. def atomic_cmp_swap_32 :
  833. PatFrag<(ops node:$ptr, node:$cmp, node:$swap),
  834. (atomic_cmp_swap node:$ptr, node:$cmp, node:$swap), [{
  835. return cast<AtomicSDNode>(N)->getMemoryVT() == MVT::i32;
  836. }]>;
  837. def atomic_cmp_swap_64 :
  838. PatFrag<(ops node:$ptr, node:$cmp, node:$swap),
  839. (atomic_cmp_swap node:$ptr, node:$cmp, node:$swap), [{
  840. return cast<AtomicSDNode>(N)->getMemoryVT() == MVT::i64;
  841. }]>;
  842. multiclass binary_atomic_op<SDNode atomic_op> {
  843. def _8 : PatFrag<(ops node:$ptr, node:$val),
  844. (atomic_op node:$ptr, node:$val), [{
  845. return cast<AtomicSDNode>(N)->getMemoryVT() == MVT::i8;
  846. }]>;
  847. def _16 : PatFrag<(ops node:$ptr, node:$val),
  848. (atomic_op node:$ptr, node:$val), [{
  849. return cast<AtomicSDNode>(N)->getMemoryVT() == MVT::i16;
  850. }]>;
  851. def _32 : PatFrag<(ops node:$ptr, node:$val),
  852. (atomic_op node:$ptr, node:$val), [{
  853. return cast<AtomicSDNode>(N)->getMemoryVT() == MVT::i32;
  854. }]>;
  855. def _64 : PatFrag<(ops node:$ptr, node:$val),
  856. (atomic_op node:$ptr, node:$val), [{
  857. return cast<AtomicSDNode>(N)->getMemoryVT() == MVT::i64;
  858. }]>;
  859. }
  860. defm atomic_load_add : binary_atomic_op<atomic_load_add>;
  861. defm atomic_swap : binary_atomic_op<atomic_swap>;
  862. defm atomic_load_sub : binary_atomic_op<atomic_load_sub>;
  863. defm atomic_load_and : binary_atomic_op<atomic_load_and>;
  864. defm atomic_load_or : binary_atomic_op<atomic_load_or>;
  865. defm atomic_load_xor : binary_atomic_op<atomic_load_xor>;
  866. defm atomic_load_nand : binary_atomic_op<atomic_load_nand>;
  867. defm atomic_load_min : binary_atomic_op<atomic_load_min>;
  868. defm atomic_load_max : binary_atomic_op<atomic_load_max>;
  869. defm atomic_load_umin : binary_atomic_op<atomic_load_umin>;
  870. defm atomic_load_umax : binary_atomic_op<atomic_load_umax>;
  871. defm atomic_store : binary_atomic_op<atomic_store>;
  872. def atomic_load_8 :
  873. PatFrag<(ops node:$ptr),
  874. (atomic_load node:$ptr), [{
  875. return cast<AtomicSDNode>(N)->getMemoryVT() == MVT::i8;
  876. }]>;
  877. def atomic_load_16 :
  878. PatFrag<(ops node:$ptr),
  879. (atomic_load node:$ptr), [{
  880. return cast<AtomicSDNode>(N)->getMemoryVT() == MVT::i16;
  881. }]>;
  882. def atomic_load_32 :
  883. PatFrag<(ops node:$ptr),
  884. (atomic_load node:$ptr), [{
  885. return cast<AtomicSDNode>(N)->getMemoryVT() == MVT::i32;
  886. }]>;
  887. def atomic_load_64 :
  888. PatFrag<(ops node:$ptr),
  889. (atomic_load node:$ptr), [{
  890. return cast<AtomicSDNode>(N)->getMemoryVT() == MVT::i64;
  891. }]>;
  892. //===----------------------------------------------------------------------===//
  893. // Selection DAG CONVERT_RNDSAT patterns
  894. def cvtff : PatFrag<(ops node:$val, node:$dty, node:$sty, node:$rd, node:$sat),
  895. (cvt node:$val, node:$dty, node:$sty, node:$rd, node:$sat), [{
  896. return cast<CvtRndSatSDNode>(N)->getCvtCode() == ISD::CVT_FF;
  897. }]>;
  898. def cvtss : PatFrag<(ops node:$val, node:$dty, node:$sty, node:$rd, node:$sat),
  899. (cvt node:$val, node:$dty, node:$sty, node:$rd, node:$sat), [{
  900. return cast<CvtRndSatSDNode>(N)->getCvtCode() == ISD::CVT_SS;
  901. }]>;
  902. def cvtsu : PatFrag<(ops node:$val, node:$dty, node:$sty, node:$rd, node:$sat),
  903. (cvt node:$val, node:$dty, node:$sty, node:$rd, node:$sat), [{
  904. return cast<CvtRndSatSDNode>(N)->getCvtCode() == ISD::CVT_SU;
  905. }]>;
  906. def cvtus : PatFrag<(ops node:$val, node:$dty, node:$sty, node:$rd, node:$sat),
  907. (cvt node:$val, node:$dty, node:$sty, node:$rd, node:$sat), [{
  908. return cast<CvtRndSatSDNode>(N)->getCvtCode() == ISD::CVT_US;
  909. }]>;
  910. def cvtuu : PatFrag<(ops node:$val, node:$dty, node:$sty, node:$rd, node:$sat),
  911. (cvt node:$val, node:$dty, node:$sty, node:$rd, node:$sat), [{
  912. return cast<CvtRndSatSDNode>(N)->getCvtCode() == ISD::CVT_UU;
  913. }]>;
  914. def cvtsf : PatFrag<(ops node:$val, node:$dty, node:$sty, node:$rd, node:$sat),
  915. (cvt node:$val, node:$dty, node:$sty, node:$rd, node:$sat), [{
  916. return cast<CvtRndSatSDNode>(N)->getCvtCode() == ISD::CVT_SF;
  917. }]>;
  918. def cvtuf : PatFrag<(ops node:$val, node:$dty, node:$sty, node:$rd, node:$sat),
  919. (cvt node:$val, node:$dty, node:$sty, node:$rd, node:$sat), [{
  920. return cast<CvtRndSatSDNode>(N)->getCvtCode() == ISD::CVT_UF;
  921. }]>;
  922. def cvtfs : PatFrag<(ops node:$val, node:$dty, node:$sty, node:$rd, node:$sat),
  923. (cvt node:$val, node:$dty, node:$sty, node:$rd, node:$sat), [{
  924. return cast<CvtRndSatSDNode>(N)->getCvtCode() == ISD::CVT_FS;
  925. }]>;
  926. def cvtfu : PatFrag<(ops node:$val, node:$dty, node:$sty, node:$rd, node:$sat),
  927. (cvt node:$val, node:$dty, node:$sty, node:$rd, node:$sat), [{
  928. return cast<CvtRndSatSDNode>(N)->getCvtCode() == ISD::CVT_FU;
  929. }]>;
  930. //===----------------------------------------------------------------------===//
  931. // Selection DAG Pattern Support.
  932. //
  933. // Patterns are what are actually matched against by the target-flavored
  934. // instruction selection DAG. Instructions defined by the target implicitly
  935. // define patterns in most cases, but patterns can also be explicitly added when
  936. // an operation is defined by a sequence of instructions (e.g. loading a large
  937. // immediate value on RISC targets that do not support immediates as large as
  938. // their GPRs).
  939. //
  940. class Pattern<dag patternToMatch, list<dag> resultInstrs> {
  941. dag PatternToMatch = patternToMatch;
  942. list<dag> ResultInstrs = resultInstrs;
  943. list<Predicate> Predicates = []; // See class Instruction in Target.td.
  944. int AddedComplexity = 0; // See class Instruction in Target.td.
  945. }
  946. // Pat - A simple (but common) form of a pattern, which produces a simple result
  947. // not needing a full list.
  948. class Pat<dag pattern, dag result> : Pattern<pattern, [result]>;
  949. //===----------------------------------------------------------------------===//
  950. // Complex pattern definitions.
  951. //
  952. // Complex patterns, e.g. X86 addressing mode, requires pattern matching code
  953. // in C++. NumOperands is the number of operands returned by the select function;
  954. // SelectFunc is the name of the function used to pattern match the max. pattern;
  955. // RootNodes are the list of possible root nodes of the sub-dags to match.
  956. // e.g. X86 addressing mode - def addr : ComplexPattern<4, "SelectAddr", [add]>;
  957. //
  958. class ComplexPattern<ValueType ty, int numops, string fn,
  959. list<SDNode> roots = [], list<SDNodeProperty> props = []> {
  960. ValueType Ty = ty;
  961. int NumOperands = numops;
  962. string SelectFunc = fn;
  963. list<SDNode> RootNodes = roots;
  964. list<SDNodeProperty> Properties = props;
  965. }