PPCISelLowering.h 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328
  1. //===-- PPCISelLowering.h - PPC32 DAG Lowering Interface --------*- C++ -*-===//
  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 defines the interfaces that PPC uses to lower LLVM code into a
  10. // selection DAG.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_LIB_TARGET_POWERPC_PPCISELLOWERING_H
  14. #define LLVM_LIB_TARGET_POWERPC_PPCISELLOWERING_H
  15. #include "PPCInstrInfo.h"
  16. #include "llvm/CodeGen/CallingConvLower.h"
  17. #include "llvm/CodeGen/MachineFunction.h"
  18. #include "llvm/CodeGen/MachineMemOperand.h"
  19. #include "llvm/CodeGen/SelectionDAG.h"
  20. #include "llvm/CodeGen/SelectionDAGNodes.h"
  21. #include "llvm/CodeGen/TargetLowering.h"
  22. #include "llvm/CodeGen/ValueTypes.h"
  23. #include "llvm/IR/Attributes.h"
  24. #include "llvm/IR/CallingConv.h"
  25. #include "llvm/IR/Function.h"
  26. #include "llvm/IR/InlineAsm.h"
  27. #include "llvm/IR/Metadata.h"
  28. #include "llvm/IR/Type.h"
  29. #include "llvm/Support/MachineValueType.h"
  30. #include <utility>
  31. namespace llvm {
  32. namespace PPCISD {
  33. // When adding a NEW PPCISD node please add it to the correct position in
  34. // the enum. The order of elements in this enum matters!
  35. // Values that are added after this entry:
  36. // STBRX = ISD::FIRST_TARGET_MEMORY_OPCODE
  37. // are considered memory opcodes and are treated differently than entries
  38. // that come before it. For example, ADD or MUL should be placed before
  39. // the ISD::FIRST_TARGET_MEMORY_OPCODE while a LOAD or STORE should come
  40. // after it.
  41. enum NodeType : unsigned {
  42. // Start the numbering where the builtin ops and target ops leave off.
  43. FIRST_NUMBER = ISD::BUILTIN_OP_END,
  44. /// FSEL - Traditional three-operand fsel node.
  45. ///
  46. FSEL,
  47. /// XSMAXCDP, XSMINCDP - C-type min/max instructions.
  48. XSMAXCDP,
  49. XSMINCDP,
  50. /// FCFID - The FCFID instruction, taking an f64 operand and producing
  51. /// and f64 value containing the FP representation of the integer that
  52. /// was temporarily in the f64 operand.
  53. FCFID,
  54. /// Newer FCFID[US] integer-to-floating-point conversion instructions for
  55. /// unsigned integers and single-precision outputs.
  56. FCFIDU,
  57. FCFIDS,
  58. FCFIDUS,
  59. /// FCTI[D,W]Z - The FCTIDZ and FCTIWZ instructions, taking an f32 or f64
  60. /// operand, producing an f64 value containing the integer representation
  61. /// of that FP value.
  62. FCTIDZ,
  63. FCTIWZ,
  64. /// Newer FCTI[D,W]UZ floating-point-to-integer conversion instructions for
  65. /// unsigned integers with round toward zero.
  66. FCTIDUZ,
  67. FCTIWUZ,
  68. /// Floating-point-to-interger conversion instructions
  69. FP_TO_UINT_IN_VSR,
  70. FP_TO_SINT_IN_VSR,
  71. /// VEXTS, ByteWidth - takes an input in VSFRC and produces an output in
  72. /// VSFRC that is sign-extended from ByteWidth to a 64-byte integer.
  73. VEXTS,
  74. /// Reciprocal estimate instructions (unary FP ops).
  75. FRE,
  76. FRSQRTE,
  77. /// Test instruction for software square root.
  78. FTSQRT,
  79. /// Square root instruction.
  80. FSQRT,
  81. /// VPERM - The PPC VPERM Instruction.
  82. ///
  83. VPERM,
  84. /// XXSPLT - The PPC VSX splat instructions
  85. ///
  86. XXSPLT,
  87. /// XXSPLTI_SP_TO_DP - The PPC VSX splat instructions for immediates for
  88. /// converting immediate single precision numbers to double precision
  89. /// vector or scalar.
  90. XXSPLTI_SP_TO_DP,
  91. /// XXSPLTI32DX - The PPC XXSPLTI32DX instruction.
  92. ///
  93. XXSPLTI32DX,
  94. /// VECINSERT - The PPC vector insert instruction
  95. ///
  96. VECINSERT,
  97. /// VECSHL - The PPC vector shift left instruction
  98. ///
  99. VECSHL,
  100. /// XXPERMDI - The PPC XXPERMDI instruction
  101. ///
  102. XXPERMDI,
  103. /// The CMPB instruction (takes two operands of i32 or i64).
  104. CMPB,
  105. /// Hi/Lo - These represent the high and low 16-bit parts of a global
  106. /// address respectively. These nodes have two operands, the first of
  107. /// which must be a TargetGlobalAddress, and the second of which must be a
  108. /// Constant. Selected naively, these turn into 'lis G+C' and 'li G+C',
  109. /// though these are usually folded into other nodes.
  110. Hi,
  111. Lo,
  112. /// The following two target-specific nodes are used for calls through
  113. /// function pointers in the 64-bit SVR4 ABI.
  114. /// OPRC, CHAIN = DYNALLOC(CHAIN, NEGSIZE, FRAME_INDEX)
  115. /// This instruction is lowered in PPCRegisterInfo::eliminateFrameIndex to
  116. /// compute an allocation on the stack.
  117. DYNALLOC,
  118. /// This instruction is lowered in PPCRegisterInfo::eliminateFrameIndex to
  119. /// compute an offset from native SP to the address of the most recent
  120. /// dynamic alloca.
  121. DYNAREAOFFSET,
  122. /// To avoid stack clash, allocation is performed by block and each block is
  123. /// probed.
  124. PROBED_ALLOCA,
  125. /// The result of the mflr at function entry, used for PIC code.
  126. GlobalBaseReg,
  127. /// These nodes represent PPC shifts.
  128. ///
  129. /// For scalar types, only the last `n + 1` bits of the shift amounts
  130. /// are used, where n is log2(sizeof(element) * 8). See sld/slw, etc.
  131. /// for exact behaviors.
  132. ///
  133. /// For vector types, only the last n bits are used. See vsld.
  134. SRL,
  135. SRA,
  136. SHL,
  137. /// FNMSUB - Negated multiply-subtract instruction.
  138. FNMSUB,
  139. /// EXTSWSLI = The PPC extswsli instruction, which does an extend-sign
  140. /// word and shift left immediate.
  141. EXTSWSLI,
  142. /// The combination of sra[wd]i and addze used to implemented signed
  143. /// integer division by a power of 2. The first operand is the dividend,
  144. /// and the second is the constant shift amount (representing the
  145. /// divisor).
  146. SRA_ADDZE,
  147. /// CALL - A direct function call.
  148. /// CALL_NOP is a call with the special NOP which follows 64-bit
  149. /// CALL_NOTOC the caller does not use the TOC.
  150. /// SVR4 calls and 32-bit/64-bit AIX calls.
  151. CALL,
  152. CALL_NOP,
  153. CALL_NOTOC,
  154. /// CHAIN,FLAG = MTCTR(VAL, CHAIN[, INFLAG]) - Directly corresponds to a
  155. /// MTCTR instruction.
  156. MTCTR,
  157. /// CHAIN,FLAG = BCTRL(CHAIN, INFLAG) - Directly corresponds to a
  158. /// BCTRL instruction.
  159. BCTRL,
  160. /// CHAIN,FLAG = BCTRL(CHAIN, ADDR, INFLAG) - The combination of a bctrl
  161. /// instruction and the TOC reload required on 64-bit ELF, 32-bit AIX
  162. /// and 64-bit AIX.
  163. BCTRL_LOAD_TOC,
  164. /// Return with a flag operand, matched by 'blr'
  165. RET_FLAG,
  166. /// R32 = MFOCRF(CRREG, INFLAG) - Represents the MFOCRF instruction.
  167. /// This copies the bits corresponding to the specified CRREG into the
  168. /// resultant GPR. Bits corresponding to other CR regs are undefined.
  169. MFOCRF,
  170. /// Direct move from a VSX register to a GPR
  171. MFVSR,
  172. /// Direct move from a GPR to a VSX register (algebraic)
  173. MTVSRA,
  174. /// Direct move from a GPR to a VSX register (zero)
  175. MTVSRZ,
  176. /// Direct move of 2 consecutive GPR to a VSX register.
  177. BUILD_FP128,
  178. /// BUILD_SPE64 and EXTRACT_SPE are analogous to BUILD_PAIR and
  179. /// EXTRACT_ELEMENT but take f64 arguments instead of i64, as i64 is
  180. /// unsupported for this target.
  181. /// Merge 2 GPRs to a single SPE register.
  182. BUILD_SPE64,
  183. /// Extract SPE register component, second argument is high or low.
  184. EXTRACT_SPE,
  185. /// Extract a subvector from signed integer vector and convert to FP.
  186. /// It is primarily used to convert a (widened) illegal integer vector
  187. /// type to a legal floating point vector type.
  188. /// For example v2i32 -> widened to v4i32 -> v2f64
  189. SINT_VEC_TO_FP,
  190. /// Extract a subvector from unsigned integer vector and convert to FP.
  191. /// As with SINT_VEC_TO_FP, used for converting illegal types.
  192. UINT_VEC_TO_FP,
  193. /// PowerPC instructions that have SCALAR_TO_VECTOR semantics tend to
  194. /// place the value into the least significant element of the most
  195. /// significant doubleword in the vector. This is not element zero for
  196. /// anything smaller than a doubleword on either endianness. This node has
  197. /// the same semantics as SCALAR_TO_VECTOR except that the value remains in
  198. /// the aforementioned location in the vector register.
  199. SCALAR_TO_VECTOR_PERMUTED,
  200. // FIXME: Remove these once the ANDI glue bug is fixed:
  201. /// i1 = ANDI_rec_1_[EQ|GT]_BIT(i32 or i64 x) - Represents the result of the
  202. /// eq or gt bit of CR0 after executing andi. x, 1. This is used to
  203. /// implement truncation of i32 or i64 to i1.
  204. ANDI_rec_1_EQ_BIT,
  205. ANDI_rec_1_GT_BIT,
  206. // READ_TIME_BASE - A read of the 64-bit time-base register on a 32-bit
  207. // target (returns (Lo, Hi)). It takes a chain operand.
  208. READ_TIME_BASE,
  209. // EH_SJLJ_SETJMP - SjLj exception handling setjmp.
  210. EH_SJLJ_SETJMP,
  211. // EH_SJLJ_LONGJMP - SjLj exception handling longjmp.
  212. EH_SJLJ_LONGJMP,
  213. /// RESVEC = VCMP(LHS, RHS, OPC) - Represents one of the altivec VCMP*
  214. /// instructions. For lack of better number, we use the opcode number
  215. /// encoding for the OPC field to identify the compare. For example, 838
  216. /// is VCMPGTSH.
  217. VCMP,
  218. /// RESVEC, OUTFLAG = VCMP_rec(LHS, RHS, OPC) - Represents one of the
  219. /// altivec VCMP*_rec instructions. For lack of better number, we use the
  220. /// opcode number encoding for the OPC field to identify the compare. For
  221. /// example, 838 is VCMPGTSH.
  222. VCMP_rec,
  223. /// CHAIN = COND_BRANCH CHAIN, CRRC, OPC, DESTBB [, INFLAG] - This
  224. /// corresponds to the COND_BRANCH pseudo instruction. CRRC is the
  225. /// condition register to branch on, OPC is the branch opcode to use (e.g.
  226. /// PPC::BLE), DESTBB is the destination block to branch to, and INFLAG is
  227. /// an optional input flag argument.
  228. COND_BRANCH,
  229. /// CHAIN = BDNZ CHAIN, DESTBB - These are used to create counter-based
  230. /// loops.
  231. BDNZ,
  232. BDZ,
  233. /// F8RC = FADDRTZ F8RC, F8RC - This is an FADD done with rounding
  234. /// towards zero. Used only as part of the long double-to-int
  235. /// conversion sequence.
  236. FADDRTZ,
  237. /// F8RC = MFFS - This moves the FPSCR (not modeled) into the register.
  238. MFFS,
  239. /// TC_RETURN - A tail call return.
  240. /// operand #0 chain
  241. /// operand #1 callee (register or absolute)
  242. /// operand #2 stack adjustment
  243. /// operand #3 optional in flag
  244. TC_RETURN,
  245. /// ch, gl = CR6[UN]SET ch, inglue - Toggle CR bit 6 for SVR4 vararg calls
  246. CR6SET,
  247. CR6UNSET,
  248. /// GPRC = address of _GLOBAL_OFFSET_TABLE_. Used by initial-exec TLS
  249. /// for non-position independent code on PPC32.
  250. PPC32_GOT,
  251. /// GPRC = address of _GLOBAL_OFFSET_TABLE_. Used by general dynamic and
  252. /// local dynamic TLS and position indendepent code on PPC32.
  253. PPC32_PICGOT,
  254. /// G8RC = ADDIS_GOT_TPREL_HA %x2, Symbol - Used by the initial-exec
  255. /// TLS model, produces an ADDIS8 instruction that adds the GOT
  256. /// base to sym\@got\@tprel\@ha.
  257. ADDIS_GOT_TPREL_HA,
  258. /// G8RC = LD_GOT_TPREL_L Symbol, G8RReg - Used by the initial-exec
  259. /// TLS model, produces a LD instruction with base register G8RReg
  260. /// and offset sym\@got\@tprel\@l. This completes the addition that
  261. /// finds the offset of "sym" relative to the thread pointer.
  262. LD_GOT_TPREL_L,
  263. /// G8RC = ADD_TLS G8RReg, Symbol - Used by the initial-exec TLS
  264. /// model, produces an ADD instruction that adds the contents of
  265. /// G8RReg to the thread pointer. Symbol contains a relocation
  266. /// sym\@tls which is to be replaced by the thread pointer and
  267. /// identifies to the linker that the instruction is part of a
  268. /// TLS sequence.
  269. ADD_TLS,
  270. /// G8RC = ADDIS_TLSGD_HA %x2, Symbol - For the general-dynamic TLS
  271. /// model, produces an ADDIS8 instruction that adds the GOT base
  272. /// register to sym\@got\@tlsgd\@ha.
  273. ADDIS_TLSGD_HA,
  274. /// %x3 = ADDI_TLSGD_L G8RReg, Symbol - For the general-dynamic TLS
  275. /// model, produces an ADDI8 instruction that adds G8RReg to
  276. /// sym\@got\@tlsgd\@l and stores the result in X3. Hidden by
  277. /// ADDIS_TLSGD_L_ADDR until after register assignment.
  278. ADDI_TLSGD_L,
  279. /// %x3 = GET_TLS_ADDR %x3, Symbol - For the general-dynamic TLS
  280. /// model, produces a call to __tls_get_addr(sym\@tlsgd). Hidden by
  281. /// ADDIS_TLSGD_L_ADDR until after register assignment.
  282. GET_TLS_ADDR,
  283. /// G8RC = ADDI_TLSGD_L_ADDR G8RReg, Symbol, Symbol - Op that
  284. /// combines ADDI_TLSGD_L and GET_TLS_ADDR until expansion following
  285. /// register assignment.
  286. ADDI_TLSGD_L_ADDR,
  287. /// G8RC = ADDIS_TLSLD_HA %x2, Symbol - For the local-dynamic TLS
  288. /// model, produces an ADDIS8 instruction that adds the GOT base
  289. /// register to sym\@got\@tlsld\@ha.
  290. ADDIS_TLSLD_HA,
  291. /// %x3 = ADDI_TLSLD_L G8RReg, Symbol - For the local-dynamic TLS
  292. /// model, produces an ADDI8 instruction that adds G8RReg to
  293. /// sym\@got\@tlsld\@l and stores the result in X3. Hidden by
  294. /// ADDIS_TLSLD_L_ADDR until after register assignment.
  295. ADDI_TLSLD_L,
  296. /// %x3 = GET_TLSLD_ADDR %x3, Symbol - For the local-dynamic TLS
  297. /// model, produces a call to __tls_get_addr(sym\@tlsld). Hidden by
  298. /// ADDIS_TLSLD_L_ADDR until after register assignment.
  299. GET_TLSLD_ADDR,
  300. /// G8RC = ADDI_TLSLD_L_ADDR G8RReg, Symbol, Symbol - Op that
  301. /// combines ADDI_TLSLD_L and GET_TLSLD_ADDR until expansion
  302. /// following register assignment.
  303. ADDI_TLSLD_L_ADDR,
  304. /// G8RC = ADDIS_DTPREL_HA %x3, Symbol - For the local-dynamic TLS
  305. /// model, produces an ADDIS8 instruction that adds X3 to
  306. /// sym\@dtprel\@ha.
  307. ADDIS_DTPREL_HA,
  308. /// G8RC = ADDI_DTPREL_L G8RReg, Symbol - For the local-dynamic TLS
  309. /// model, produces an ADDI8 instruction that adds G8RReg to
  310. /// sym\@got\@dtprel\@l.
  311. ADDI_DTPREL_L,
  312. /// G8RC = PADDI_DTPREL %x3, Symbol - For the pc-rel based local-dynamic TLS
  313. /// model, produces a PADDI8 instruction that adds X3 to sym\@dtprel.
  314. PADDI_DTPREL,
  315. /// VRRC = VADD_SPLAT Elt, EltSize - Temporary node to be expanded
  316. /// during instruction selection to optimize a BUILD_VECTOR into
  317. /// operations on splats. This is necessary to avoid losing these
  318. /// optimizations due to constant folding.
  319. VADD_SPLAT,
  320. /// CHAIN = SC CHAIN, Imm128 - System call. The 7-bit unsigned
  321. /// operand identifies the operating system entry point.
  322. SC,
  323. /// CHAIN = CLRBHRB CHAIN - Clear branch history rolling buffer.
  324. CLRBHRB,
  325. /// GPRC, CHAIN = MFBHRBE CHAIN, Entry, Dummy - Move from branch
  326. /// history rolling buffer entry.
  327. MFBHRBE,
  328. /// CHAIN = RFEBB CHAIN, State - Return from event-based branch.
  329. RFEBB,
  330. /// VSRC, CHAIN = XXSWAPD CHAIN, VSRC - Occurs only for little
  331. /// endian. Maps to an xxswapd instruction that corrects an lxvd2x
  332. /// or stxvd2x instruction. The chain is necessary because the
  333. /// sequence replaces a load and needs to provide the same number
  334. /// of outputs.
  335. XXSWAPD,
  336. /// An SDNode for swaps that are not associated with any loads/stores
  337. /// and thereby have no chain.
  338. SWAP_NO_CHAIN,
  339. /// An SDNode for Power9 vector absolute value difference.
  340. /// operand #0 vector
  341. /// operand #1 vector
  342. /// operand #2 constant i32 0 or 1, to indicate whether needs to patch
  343. /// the most significant bit for signed i32
  344. ///
  345. /// Power9 VABSD* instructions are designed to support unsigned integer
  346. /// vectors (byte/halfword/word), if we want to make use of them for signed
  347. /// integer vectors, we have to flip their sign bits first. To flip sign bit
  348. /// for byte/halfword integer vector would become inefficient, but for word
  349. /// integer vector, we can leverage XVNEGSP to make it efficiently. eg:
  350. /// abs(sub(a,b)) => VABSDUW(a+0x80000000, b+0x80000000)
  351. /// => VABSDUW((XVNEGSP a), (XVNEGSP b))
  352. VABSD,
  353. /// FP_EXTEND_HALF(VECTOR, IDX) - Custom extend upper (IDX=0) half or
  354. /// lower (IDX=1) half of v4f32 to v2f64.
  355. FP_EXTEND_HALF,
  356. /// MAT_PCREL_ADDR = Materialize a PC Relative address. This can be done
  357. /// either through an add like PADDI or through a PC Relative load like
  358. /// PLD.
  359. MAT_PCREL_ADDR,
  360. /// TLS_DYNAMIC_MAT_PCREL_ADDR = Materialize a PC Relative address for
  361. /// TLS global address when using dynamic access models. This can be done
  362. /// through an add like PADDI.
  363. TLS_DYNAMIC_MAT_PCREL_ADDR,
  364. /// TLS_LOCAL_EXEC_MAT_ADDR = Materialize an address for TLS global address
  365. /// when using local exec access models, and when prefixed instructions are
  366. /// available. This is used with ADD_TLS to produce an add like PADDI.
  367. TLS_LOCAL_EXEC_MAT_ADDR,
  368. /// ACC_BUILD = Build an accumulator register from 4 VSX registers.
  369. ACC_BUILD,
  370. /// PAIR_BUILD = Build a vector pair register from 2 VSX registers.
  371. PAIR_BUILD,
  372. /// EXTRACT_VSX_REG = Extract one of the underlying vsx registers of
  373. /// an accumulator or pair register. This node is needed because
  374. /// EXTRACT_SUBVECTOR expects the input and output vectors to have the same
  375. /// element type.
  376. EXTRACT_VSX_REG,
  377. /// XXMFACC = This corresponds to the xxmfacc instruction.
  378. XXMFACC,
  379. // Constrained conversion from floating point to int
  380. STRICT_FCTIDZ = ISD::FIRST_TARGET_STRICTFP_OPCODE,
  381. STRICT_FCTIWZ,
  382. STRICT_FCTIDUZ,
  383. STRICT_FCTIWUZ,
  384. /// Constrained integer-to-floating-point conversion instructions.
  385. STRICT_FCFID,
  386. STRICT_FCFIDU,
  387. STRICT_FCFIDS,
  388. STRICT_FCFIDUS,
  389. /// Constrained floating point add in round-to-zero mode.
  390. STRICT_FADDRTZ,
  391. /// CHAIN = STBRX CHAIN, GPRC, Ptr, Type - This is a
  392. /// byte-swapping store instruction. It byte-swaps the low "Type" bits of
  393. /// the GPRC input, then stores it through Ptr. Type can be either i16 or
  394. /// i32.
  395. STBRX = ISD::FIRST_TARGET_MEMORY_OPCODE,
  396. /// GPRC, CHAIN = LBRX CHAIN, Ptr, Type - This is a
  397. /// byte-swapping load instruction. It loads "Type" bits, byte swaps it,
  398. /// then puts it in the bottom bits of the GPRC. TYPE can be either i16
  399. /// or i32.
  400. LBRX,
  401. /// STFIWX - The STFIWX instruction. The first operand is an input token
  402. /// chain, then an f64 value to store, then an address to store it to.
  403. STFIWX,
  404. /// GPRC, CHAIN = LFIWAX CHAIN, Ptr - This is a floating-point
  405. /// load which sign-extends from a 32-bit integer value into the
  406. /// destination 64-bit register.
  407. LFIWAX,
  408. /// GPRC, CHAIN = LFIWZX CHAIN, Ptr - This is a floating-point
  409. /// load which zero-extends from a 32-bit integer value into the
  410. /// destination 64-bit register.
  411. LFIWZX,
  412. /// GPRC, CHAIN = LXSIZX, CHAIN, Ptr, ByteWidth - This is a load of an
  413. /// integer smaller than 64 bits into a VSR. The integer is zero-extended.
  414. /// This can be used for converting loaded integers to floating point.
  415. LXSIZX,
  416. /// STXSIX - The STXSI[bh]X instruction. The first operand is an input
  417. /// chain, then an f64 value to store, then an address to store it to,
  418. /// followed by a byte-width for the store.
  419. STXSIX,
  420. /// VSRC, CHAIN = LXVD2X_LE CHAIN, Ptr - Occurs only for little endian.
  421. /// Maps directly to an lxvd2x instruction that will be followed by
  422. /// an xxswapd.
  423. LXVD2X,
  424. /// LXVRZX - Load VSX Vector Rightmost and Zero Extend
  425. /// This node represents v1i128 BUILD_VECTOR of a zero extending load
  426. /// instruction from <byte, halfword, word, or doubleword> to i128.
  427. /// Allows utilization of the Load VSX Vector Rightmost Instructions.
  428. LXVRZX,
  429. /// VSRC, CHAIN = LOAD_VEC_BE CHAIN, Ptr - Occurs only for little endian.
  430. /// Maps directly to one of lxvd2x/lxvw4x/lxvh8x/lxvb16x depending on
  431. /// the vector type to load vector in big-endian element order.
  432. LOAD_VEC_BE,
  433. /// VSRC, CHAIN = LD_VSX_LH CHAIN, Ptr - This is a floating-point load of a
  434. /// v2f32 value into the lower half of a VSR register.
  435. LD_VSX_LH,
  436. /// VSRC, CHAIN = LD_SPLAT, CHAIN, Ptr - a splatting load memory
  437. /// instructions such as LXVDSX, LXVWSX.
  438. LD_SPLAT,
  439. /// CHAIN = STXVD2X CHAIN, VSRC, Ptr - Occurs only for little endian.
  440. /// Maps directly to an stxvd2x instruction that will be preceded by
  441. /// an xxswapd.
  442. STXVD2X,
  443. /// CHAIN = STORE_VEC_BE CHAIN, VSRC, Ptr - Occurs only for little endian.
  444. /// Maps directly to one of stxvd2x/stxvw4x/stxvh8x/stxvb16x depending on
  445. /// the vector type to store vector in big-endian element order.
  446. STORE_VEC_BE,
  447. /// Store scalar integers from VSR.
  448. ST_VSR_SCAL_INT,
  449. /// ATOMIC_CMP_SWAP - the exact same as the target-independent nodes
  450. /// except they ensure that the compare input is zero-extended for
  451. /// sub-word versions because the atomic loads zero-extend.
  452. ATOMIC_CMP_SWAP_8,
  453. ATOMIC_CMP_SWAP_16,
  454. /// GPRC = TOC_ENTRY GA, TOC
  455. /// Loads the entry for GA from the TOC, where the TOC base is given by
  456. /// the last operand.
  457. TOC_ENTRY
  458. };
  459. } // end namespace PPCISD
  460. /// Define some predicates that are used for node matching.
  461. namespace PPC {
  462. /// isVPKUHUMShuffleMask - Return true if this is the shuffle mask for a
  463. /// VPKUHUM instruction.
  464. bool isVPKUHUMShuffleMask(ShuffleVectorSDNode *N, unsigned ShuffleKind,
  465. SelectionDAG &DAG);
  466. /// isVPKUWUMShuffleMask - Return true if this is the shuffle mask for a
  467. /// VPKUWUM instruction.
  468. bool isVPKUWUMShuffleMask(ShuffleVectorSDNode *N, unsigned ShuffleKind,
  469. SelectionDAG &DAG);
  470. /// isVPKUDUMShuffleMask - Return true if this is the shuffle mask for a
  471. /// VPKUDUM instruction.
  472. bool isVPKUDUMShuffleMask(ShuffleVectorSDNode *N, unsigned ShuffleKind,
  473. SelectionDAG &DAG);
  474. /// isVMRGLShuffleMask - Return true if this is a shuffle mask suitable for
  475. /// a VRGL* instruction with the specified unit size (1,2 or 4 bytes).
  476. bool isVMRGLShuffleMask(ShuffleVectorSDNode *N, unsigned UnitSize,
  477. unsigned ShuffleKind, SelectionDAG &DAG);
  478. /// isVMRGHShuffleMask - Return true if this is a shuffle mask suitable for
  479. /// a VRGH* instruction with the specified unit size (1,2 or 4 bytes).
  480. bool isVMRGHShuffleMask(ShuffleVectorSDNode *N, unsigned UnitSize,
  481. unsigned ShuffleKind, SelectionDAG &DAG);
  482. /// isVMRGEOShuffleMask - Return true if this is a shuffle mask suitable for
  483. /// a VMRGEW or VMRGOW instruction
  484. bool isVMRGEOShuffleMask(ShuffleVectorSDNode *N, bool CheckEven,
  485. unsigned ShuffleKind, SelectionDAG &DAG);
  486. /// isXXSLDWIShuffleMask - Return true if this is a shuffle mask suitable
  487. /// for a XXSLDWI instruction.
  488. bool isXXSLDWIShuffleMask(ShuffleVectorSDNode *N, unsigned &ShiftElts,
  489. bool &Swap, bool IsLE);
  490. /// isXXBRHShuffleMask - Return true if this is a shuffle mask suitable
  491. /// for a XXBRH instruction.
  492. bool isXXBRHShuffleMask(ShuffleVectorSDNode *N);
  493. /// isXXBRWShuffleMask - Return true if this is a shuffle mask suitable
  494. /// for a XXBRW instruction.
  495. bool isXXBRWShuffleMask(ShuffleVectorSDNode *N);
  496. /// isXXBRDShuffleMask - Return true if this is a shuffle mask suitable
  497. /// for a XXBRD instruction.
  498. bool isXXBRDShuffleMask(ShuffleVectorSDNode *N);
  499. /// isXXBRQShuffleMask - Return true if this is a shuffle mask suitable
  500. /// for a XXBRQ instruction.
  501. bool isXXBRQShuffleMask(ShuffleVectorSDNode *N);
  502. /// isXXPERMDIShuffleMask - Return true if this is a shuffle mask suitable
  503. /// for a XXPERMDI instruction.
  504. bool isXXPERMDIShuffleMask(ShuffleVectorSDNode *N, unsigned &ShiftElts,
  505. bool &Swap, bool IsLE);
  506. /// isVSLDOIShuffleMask - If this is a vsldoi shuffle mask, return the
  507. /// shift amount, otherwise return -1.
  508. int isVSLDOIShuffleMask(SDNode *N, unsigned ShuffleKind,
  509. SelectionDAG &DAG);
  510. /// isSplatShuffleMask - Return true if the specified VECTOR_SHUFFLE operand
  511. /// specifies a splat of a single element that is suitable for input to
  512. /// VSPLTB/VSPLTH/VSPLTW.
  513. bool isSplatShuffleMask(ShuffleVectorSDNode *N, unsigned EltSize);
  514. /// isXXINSERTWMask - Return true if this VECTOR_SHUFFLE can be handled by
  515. /// the XXINSERTW instruction introduced in ISA 3.0. This is essentially any
  516. /// shuffle of v4f32/v4i32 vectors that just inserts one element from one
  517. /// vector into the other. This function will also set a couple of
  518. /// output parameters for how much the source vector needs to be shifted and
  519. /// what byte number needs to be specified for the instruction to put the
  520. /// element in the desired location of the target vector.
  521. bool isXXINSERTWMask(ShuffleVectorSDNode *N, unsigned &ShiftElts,
  522. unsigned &InsertAtByte, bool &Swap, bool IsLE);
  523. /// getSplatIdxForPPCMnemonics - Return the splat index as a value that is
  524. /// appropriate for PPC mnemonics (which have a big endian bias - namely
  525. /// elements are counted from the left of the vector register).
  526. unsigned getSplatIdxForPPCMnemonics(SDNode *N, unsigned EltSize,
  527. SelectionDAG &DAG);
  528. /// get_VSPLTI_elt - If this is a build_vector of constants which can be
  529. /// formed by using a vspltis[bhw] instruction of the specified element
  530. /// size, return the constant being splatted. The ByteSize field indicates
  531. /// the number of bytes of each element [124] -> [bhw].
  532. SDValue get_VSPLTI_elt(SDNode *N, unsigned ByteSize, SelectionDAG &DAG);
  533. } // end namespace PPC
  534. class PPCTargetLowering : public TargetLowering {
  535. const PPCSubtarget &Subtarget;
  536. public:
  537. explicit PPCTargetLowering(const PPCTargetMachine &TM,
  538. const PPCSubtarget &STI);
  539. /// getTargetNodeName() - This method returns the name of a target specific
  540. /// DAG node.
  541. const char *getTargetNodeName(unsigned Opcode) const override;
  542. bool isSelectSupported(SelectSupportKind Kind) const override {
  543. // PowerPC does not support scalar condition selects on vectors.
  544. return (Kind != SelectSupportKind::ScalarCondVectorVal);
  545. }
  546. /// getPreferredVectorAction - The code we generate when vector types are
  547. /// legalized by promoting the integer element type is often much worse
  548. /// than code we generate if we widen the type for applicable vector types.
  549. /// The issue with promoting is that the vector is scalaraized, individual
  550. /// elements promoted and then the vector is rebuilt. So say we load a pair
  551. /// of v4i8's and shuffle them. This will turn into a mess of 8 extending
  552. /// loads, moves back into VSR's (or memory ops if we don't have moves) and
  553. /// then the VPERM for the shuffle. All in all a very slow sequence.
  554. TargetLoweringBase::LegalizeTypeAction getPreferredVectorAction(MVT VT)
  555. const override {
  556. if (VT.getVectorNumElements() != 1 && VT.getScalarSizeInBits() % 8 == 0)
  557. return TypeWidenVector;
  558. return TargetLoweringBase::getPreferredVectorAction(VT);
  559. }
  560. bool useSoftFloat() const override;
  561. bool hasSPE() const;
  562. MVT getScalarShiftAmountTy(const DataLayout &, EVT) const override {
  563. return MVT::i32;
  564. }
  565. bool isCheapToSpeculateCttz() const override {
  566. return true;
  567. }
  568. bool isCheapToSpeculateCtlz() const override {
  569. return true;
  570. }
  571. bool isCtlzFast() const override {
  572. return true;
  573. }
  574. bool isEqualityCmpFoldedWithSignedCmp() const override {
  575. return false;
  576. }
  577. bool hasAndNotCompare(SDValue) const override {
  578. return true;
  579. }
  580. bool preferIncOfAddToSubOfNot(EVT VT) const override;
  581. bool convertSetCCLogicToBitwiseLogic(EVT VT) const override {
  582. return VT.isScalarInteger();
  583. }
  584. SDValue getNegatedExpression(SDValue Op, SelectionDAG &DAG, bool LegalOps,
  585. bool OptForSize, NegatibleCost &Cost,
  586. unsigned Depth = 0) const override;
  587. /// getSetCCResultType - Return the ISD::SETCC ValueType
  588. EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context,
  589. EVT VT) const override;
  590. /// Return true if target always beneficiates from combining into FMA for a
  591. /// given value type. This must typically return false on targets where FMA
  592. /// takes more cycles to execute than FADD.
  593. bool enableAggressiveFMAFusion(EVT VT) const override;
  594. /// getPreIndexedAddressParts - returns true by value, base pointer and
  595. /// offset pointer and addressing mode by reference if the node's address
  596. /// can be legally represented as pre-indexed load / store address.
  597. bool getPreIndexedAddressParts(SDNode *N, SDValue &Base,
  598. SDValue &Offset,
  599. ISD::MemIndexedMode &AM,
  600. SelectionDAG &DAG) const override;
  601. /// SelectAddressEVXRegReg - Given the specified addressed, check to see if
  602. /// it can be more efficiently represented as [r+imm].
  603. bool SelectAddressEVXRegReg(SDValue N, SDValue &Base, SDValue &Index,
  604. SelectionDAG &DAG) const;
  605. /// SelectAddressRegReg - Given the specified addressed, check to see if it
  606. /// can be more efficiently represented as [r+imm]. If \p EncodingAlignment
  607. /// is non-zero, only accept displacement which is not suitable for [r+imm].
  608. /// Returns false if it can be represented by [r+imm], which are preferred.
  609. bool SelectAddressRegReg(SDValue N, SDValue &Base, SDValue &Index,
  610. SelectionDAG &DAG,
  611. MaybeAlign EncodingAlignment = None) const;
  612. /// SelectAddressRegImm - Returns true if the address N can be represented
  613. /// by a base register plus a signed 16-bit displacement [r+imm], and if it
  614. /// is not better represented as reg+reg. If \p EncodingAlignment is
  615. /// non-zero, only accept displacements suitable for instruction encoding
  616. /// requirement, i.e. multiples of 4 for DS form.
  617. bool SelectAddressRegImm(SDValue N, SDValue &Disp, SDValue &Base,
  618. SelectionDAG &DAG,
  619. MaybeAlign EncodingAlignment) const;
  620. bool SelectAddressRegImm34(SDValue N, SDValue &Disp, SDValue &Base,
  621. SelectionDAG &DAG) const;
  622. /// SelectAddressRegRegOnly - Given the specified addressed, force it to be
  623. /// represented as an indexed [r+r] operation.
  624. bool SelectAddressRegRegOnly(SDValue N, SDValue &Base, SDValue &Index,
  625. SelectionDAG &DAG) const;
  626. /// SelectAddressPCRel - Represent the specified address as pc relative to
  627. /// be represented as [pc+imm]
  628. bool SelectAddressPCRel(SDValue N, SDValue &Base) const;
  629. Sched::Preference getSchedulingPreference(SDNode *N) const override;
  630. /// LowerOperation - Provide custom lowering hooks for some operations.
  631. ///
  632. SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
  633. /// ReplaceNodeResults - Replace the results of node with an illegal result
  634. /// type with new values built out of custom code.
  635. ///
  636. void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue>&Results,
  637. SelectionDAG &DAG) const override;
  638. SDValue expandVSXLoadForLE(SDNode *N, DAGCombinerInfo &DCI) const;
  639. SDValue expandVSXStoreForLE(SDNode *N, DAGCombinerInfo &DCI) const;
  640. SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override;
  641. SDValue BuildSDIVPow2(SDNode *N, const APInt &Divisor, SelectionDAG &DAG,
  642. SmallVectorImpl<SDNode *> &Created) const override;
  643. Register getRegisterByName(const char* RegName, LLT VT,
  644. const MachineFunction &MF) const override;
  645. void computeKnownBitsForTargetNode(const SDValue Op,
  646. KnownBits &Known,
  647. const APInt &DemandedElts,
  648. const SelectionDAG &DAG,
  649. unsigned Depth = 0) const override;
  650. Align getPrefLoopAlignment(MachineLoop *ML) const override;
  651. bool shouldInsertFencesForAtomic(const Instruction *I) const override {
  652. return true;
  653. }
  654. Instruction *emitLeadingFence(IRBuilder<> &Builder, Instruction *Inst,
  655. AtomicOrdering Ord) const override;
  656. Instruction *emitTrailingFence(IRBuilder<> &Builder, Instruction *Inst,
  657. AtomicOrdering Ord) const override;
  658. MachineBasicBlock *
  659. EmitInstrWithCustomInserter(MachineInstr &MI,
  660. MachineBasicBlock *MBB) const override;
  661. MachineBasicBlock *EmitAtomicBinary(MachineInstr &MI,
  662. MachineBasicBlock *MBB,
  663. unsigned AtomicSize,
  664. unsigned BinOpcode,
  665. unsigned CmpOpcode = 0,
  666. unsigned CmpPred = 0) const;
  667. MachineBasicBlock *EmitPartwordAtomicBinary(MachineInstr &MI,
  668. MachineBasicBlock *MBB,
  669. bool is8bit,
  670. unsigned Opcode,
  671. unsigned CmpOpcode = 0,
  672. unsigned CmpPred = 0) const;
  673. MachineBasicBlock *emitEHSjLjSetJmp(MachineInstr &MI,
  674. MachineBasicBlock *MBB) const;
  675. MachineBasicBlock *emitEHSjLjLongJmp(MachineInstr &MI,
  676. MachineBasicBlock *MBB) const;
  677. MachineBasicBlock *emitProbedAlloca(MachineInstr &MI,
  678. MachineBasicBlock *MBB) const;
  679. bool hasInlineStackProbe(MachineFunction &MF) const override;
  680. unsigned getStackProbeSize(MachineFunction &MF) const;
  681. ConstraintType getConstraintType(StringRef Constraint) const override;
  682. /// Examine constraint string and operand type and determine a weight value.
  683. /// The operand object must already have been set up with the operand type.
  684. ConstraintWeight getSingleConstraintMatchWeight(
  685. AsmOperandInfo &info, const char *constraint) const override;
  686. std::pair<unsigned, const TargetRegisterClass *>
  687. getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
  688. StringRef Constraint, MVT VT) const override;
  689. /// getByValTypeAlignment - Return the desired alignment for ByVal aggregate
  690. /// function arguments in the caller parameter area. This is the actual
  691. /// alignment, not its logarithm.
  692. unsigned getByValTypeAlignment(Type *Ty,
  693. const DataLayout &DL) const override;
  694. /// LowerAsmOperandForConstraint - Lower the specified operand into the Ops
  695. /// vector. If it is invalid, don't add anything to Ops.
  696. void LowerAsmOperandForConstraint(SDValue Op,
  697. std::string &Constraint,
  698. std::vector<SDValue> &Ops,
  699. SelectionDAG &DAG) const override;
  700. unsigned
  701. getInlineAsmMemConstraint(StringRef ConstraintCode) const override {
  702. if (ConstraintCode == "es")
  703. return InlineAsm::Constraint_es;
  704. else if (ConstraintCode == "o")
  705. return InlineAsm::Constraint_o;
  706. else if (ConstraintCode == "Q")
  707. return InlineAsm::Constraint_Q;
  708. else if (ConstraintCode == "Z")
  709. return InlineAsm::Constraint_Z;
  710. else if (ConstraintCode == "Zy")
  711. return InlineAsm::Constraint_Zy;
  712. return TargetLowering::getInlineAsmMemConstraint(ConstraintCode);
  713. }
  714. /// isLegalAddressingMode - Return true if the addressing mode represented
  715. /// by AM is legal for this target, for a load/store of the specified type.
  716. bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM,
  717. Type *Ty, unsigned AS,
  718. Instruction *I = nullptr) const override;
  719. /// isLegalICmpImmediate - Return true if the specified immediate is legal
  720. /// icmp immediate, that is the target has icmp instructions which can
  721. /// compare a register against the immediate without having to materialize
  722. /// the immediate into a register.
  723. bool isLegalICmpImmediate(int64_t Imm) const override;
  724. /// isLegalAddImmediate - Return true if the specified immediate is legal
  725. /// add immediate, that is the target has add instructions which can
  726. /// add a register and the immediate without having to materialize
  727. /// the immediate into a register.
  728. bool isLegalAddImmediate(int64_t Imm) const override;
  729. /// isTruncateFree - Return true if it's free to truncate a value of
  730. /// type Ty1 to type Ty2. e.g. On PPC it's free to truncate a i64 value in
  731. /// register X1 to i32 by referencing its sub-register R1.
  732. bool isTruncateFree(Type *Ty1, Type *Ty2) const override;
  733. bool isTruncateFree(EVT VT1, EVT VT2) const override;
  734. bool isZExtFree(SDValue Val, EVT VT2) const override;
  735. bool isFPExtFree(EVT DestVT, EVT SrcVT) const override;
  736. /// Returns true if it is beneficial to convert a load of a constant
  737. /// to just the constant itself.
  738. bool shouldConvertConstantLoadToIntImm(const APInt &Imm,
  739. Type *Ty) const override;
  740. bool convertSelectOfConstantsToMath(EVT VT) const override {
  741. return true;
  742. }
  743. bool decomposeMulByConstant(LLVMContext &Context, EVT VT,
  744. SDValue C) const override;
  745. bool isDesirableToTransformToIntegerOp(unsigned Opc,
  746. EVT VT) const override {
  747. // Only handle float load/store pair because float(fpr) load/store
  748. // instruction has more cycles than integer(gpr) load/store in PPC.
  749. if (Opc != ISD::LOAD && Opc != ISD::STORE)
  750. return false;
  751. if (VT != MVT::f32 && VT != MVT::f64)
  752. return false;
  753. return true;
  754. }
  755. // Returns true if the address of the global is stored in TOC entry.
  756. bool isAccessedAsGotIndirect(SDValue N) const;
  757. bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override;
  758. bool getTgtMemIntrinsic(IntrinsicInfo &Info,
  759. const CallInst &I,
  760. MachineFunction &MF,
  761. unsigned Intrinsic) const override;
  762. /// It returns EVT::Other if the type should be determined using generic
  763. /// target-independent logic.
  764. EVT getOptimalMemOpType(const MemOp &Op,
  765. const AttributeList &FuncAttributes) const override;
  766. /// Is unaligned memory access allowed for the given type, and is it fast
  767. /// relative to software emulation.
  768. bool allowsMisalignedMemoryAccesses(
  769. EVT VT, unsigned AddrSpace, unsigned Align = 1,
  770. MachineMemOperand::Flags Flags = MachineMemOperand::MONone,
  771. bool *Fast = nullptr) const override;
  772. /// isFMAFasterThanFMulAndFAdd - Return true if an FMA operation is faster
  773. /// than a pair of fmul and fadd instructions. fmuladd intrinsics will be
  774. /// expanded to FMAs when this method returns true, otherwise fmuladd is
  775. /// expanded to fmul + fadd.
  776. bool isFMAFasterThanFMulAndFAdd(const MachineFunction &MF,
  777. EVT VT) const override;
  778. bool isFMAFasterThanFMulAndFAdd(const Function &F, Type *Ty) const override;
  779. /// isProfitableToHoist - Check if it is profitable to hoist instruction
  780. /// \p I to its dominator block.
  781. /// For example, it is not profitable if \p I and it's only user can form a
  782. /// FMA instruction, because Powerpc prefers FMADD.
  783. bool isProfitableToHoist(Instruction *I) const override;
  784. const MCPhysReg *getScratchRegisters(CallingConv::ID CC) const override;
  785. // Should we expand the build vector with shuffles?
  786. bool
  787. shouldExpandBuildVectorWithShuffles(EVT VT,
  788. unsigned DefinedValues) const override;
  789. // Keep the zero-extensions for arguments to libcalls.
  790. bool shouldKeepZExtForFP16Conv() const override { return true; }
  791. /// createFastISel - This method returns a target-specific FastISel object,
  792. /// or null if the target does not support "fast" instruction selection.
  793. FastISel *createFastISel(FunctionLoweringInfo &FuncInfo,
  794. const TargetLibraryInfo *LibInfo) const override;
  795. /// Returns true if an argument of type Ty needs to be passed in a
  796. /// contiguous block of registers in calling convention CallConv.
  797. bool functionArgumentNeedsConsecutiveRegisters(
  798. Type *Ty, CallingConv::ID CallConv, bool isVarArg) const override {
  799. // We support any array type as "consecutive" block in the parameter
  800. // save area. The element type defines the alignment requirement and
  801. // whether the argument should go in GPRs, FPRs, or VRs if available.
  802. //
  803. // Note that clang uses this capability both to implement the ELFv2
  804. // homogeneous float/vector aggregate ABI, and to avoid having to use
  805. // "byval" when passing aggregates that might fully fit in registers.
  806. return Ty->isArrayTy();
  807. }
  808. /// If a physical register, this returns the register that receives the
  809. /// exception address on entry to an EH pad.
  810. Register
  811. getExceptionPointerRegister(const Constant *PersonalityFn) const override;
  812. /// If a physical register, this returns the register that receives the
  813. /// exception typeid on entry to a landing pad.
  814. Register
  815. getExceptionSelectorRegister(const Constant *PersonalityFn) const override;
  816. /// Override to support customized stack guard loading.
  817. bool useLoadStackGuardNode() const override;
  818. void insertSSPDeclarations(Module &M) const override;
  819. bool isFPImmLegal(const APFloat &Imm, EVT VT,
  820. bool ForCodeSize) const override;
  821. unsigned getJumpTableEncoding() const override;
  822. bool isJumpTableRelative() const override;
  823. SDValue getPICJumpTableRelocBase(SDValue Table,
  824. SelectionDAG &DAG) const override;
  825. const MCExpr *getPICJumpTableRelocBaseExpr(const MachineFunction *MF,
  826. unsigned JTI,
  827. MCContext &Ctx) const override;
  828. /// Structure that collects some common arguments that get passed around
  829. /// between the functions for call lowering.
  830. struct CallFlags {
  831. const CallingConv::ID CallConv;
  832. const bool IsTailCall : 1;
  833. const bool IsVarArg : 1;
  834. const bool IsPatchPoint : 1;
  835. const bool IsIndirect : 1;
  836. const bool HasNest : 1;
  837. const bool NoMerge : 1;
  838. CallFlags(CallingConv::ID CC, bool IsTailCall, bool IsVarArg,
  839. bool IsPatchPoint, bool IsIndirect, bool HasNest, bool NoMerge)
  840. : CallConv(CC), IsTailCall(IsTailCall), IsVarArg(IsVarArg),
  841. IsPatchPoint(IsPatchPoint), IsIndirect(IsIndirect),
  842. HasNest(HasNest), NoMerge(NoMerge) {}
  843. };
  844. private:
  845. struct ReuseLoadInfo {
  846. SDValue Ptr;
  847. SDValue Chain;
  848. SDValue ResChain;
  849. MachinePointerInfo MPI;
  850. bool IsDereferenceable = false;
  851. bool IsInvariant = false;
  852. Align Alignment;
  853. AAMDNodes AAInfo;
  854. const MDNode *Ranges = nullptr;
  855. ReuseLoadInfo() = default;
  856. MachineMemOperand::Flags MMOFlags() const {
  857. MachineMemOperand::Flags F = MachineMemOperand::MONone;
  858. if (IsDereferenceable)
  859. F |= MachineMemOperand::MODereferenceable;
  860. if (IsInvariant)
  861. F |= MachineMemOperand::MOInvariant;
  862. return F;
  863. }
  864. };
  865. bool canReuseLoadAddress(SDValue Op, EVT MemVT, ReuseLoadInfo &RLI,
  866. SelectionDAG &DAG,
  867. ISD::LoadExtType ET = ISD::NON_EXTLOAD) const;
  868. void spliceIntoChain(SDValue ResChain, SDValue NewResChain,
  869. SelectionDAG &DAG) const;
  870. void LowerFP_TO_INTForReuse(SDValue Op, ReuseLoadInfo &RLI,
  871. SelectionDAG &DAG, const SDLoc &dl) const;
  872. SDValue LowerFP_TO_INTDirectMove(SDValue Op, SelectionDAG &DAG,
  873. const SDLoc &dl) const;
  874. bool directMoveIsProfitable(const SDValue &Op) const;
  875. SDValue LowerINT_TO_FPDirectMove(SDValue Op, SelectionDAG &DAG,
  876. const SDLoc &dl) const;
  877. SDValue LowerINT_TO_FPVector(SDValue Op, SelectionDAG &DAG,
  878. const SDLoc &dl) const;
  879. SDValue LowerTRUNCATEVector(SDValue Op, SelectionDAG &DAG) const;
  880. SDValue getFramePointerFrameIndex(SelectionDAG & DAG) const;
  881. SDValue getReturnAddrFrameIndex(SelectionDAG & DAG) const;
  882. bool
  883. IsEligibleForTailCallOptimization(SDValue Callee,
  884. CallingConv::ID CalleeCC,
  885. bool isVarArg,
  886. const SmallVectorImpl<ISD::InputArg> &Ins,
  887. SelectionDAG& DAG) const;
  888. bool IsEligibleForTailCallOptimization_64SVR4(
  889. SDValue Callee, CallingConv::ID CalleeCC, const CallBase *CB,
  890. bool isVarArg, const SmallVectorImpl<ISD::OutputArg> &Outs,
  891. const SmallVectorImpl<ISD::InputArg> &Ins, SelectionDAG &DAG) const;
  892. SDValue EmitTailCallLoadFPAndRetAddr(SelectionDAG &DAG, int SPDiff,
  893. SDValue Chain, SDValue &LROpOut,
  894. SDValue &FPOpOut,
  895. const SDLoc &dl) const;
  896. SDValue getTOCEntry(SelectionDAG &DAG, const SDLoc &dl, SDValue GA) const;
  897. SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
  898. SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
  899. SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const;
  900. SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;
  901. SDValue LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const;
  902. SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;
  903. SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) const;
  904. SDValue LowerSETCC(SDValue Op, SelectionDAG &DAG) const;
  905. SDValue LowerINIT_TRAMPOLINE(SDValue Op, SelectionDAG &DAG) const;
  906. SDValue LowerADJUST_TRAMPOLINE(SDValue Op, SelectionDAG &DAG) const;
  907. SDValue LowerINLINEASM(SDValue Op, SelectionDAG &DAG) const;
  908. SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const;
  909. SDValue LowerVAARG(SDValue Op, SelectionDAG &DAG) const;
  910. SDValue LowerVACOPY(SDValue Op, SelectionDAG &DAG) const;
  911. SDValue LowerSTACKRESTORE(SDValue Op, SelectionDAG &DAG) const;
  912. SDValue LowerGET_DYNAMIC_AREA_OFFSET(SDValue Op, SelectionDAG &DAG) const;
  913. SDValue LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) const;
  914. SDValue LowerEH_DWARF_CFA(SDValue Op, SelectionDAG &DAG) const;
  915. SDValue LowerLOAD(SDValue Op, SelectionDAG &DAG) const;
  916. SDValue LowerSTORE(SDValue Op, SelectionDAG &DAG) const;
  917. SDValue LowerTRUNCATE(SDValue Op, SelectionDAG &DAG) const;
  918. SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const;
  919. SDValue LowerFP_TO_INT(SDValue Op, SelectionDAG &DAG,
  920. const SDLoc &dl) const;
  921. SDValue LowerINT_TO_FP(SDValue Op, SelectionDAG &DAG) const;
  922. SDValue LowerFLT_ROUNDS_(SDValue Op, SelectionDAG &DAG) const;
  923. SDValue LowerSHL_PARTS(SDValue Op, SelectionDAG &DAG) const;
  924. SDValue LowerSRL_PARTS(SDValue Op, SelectionDAG &DAG) const;
  925. SDValue LowerSRA_PARTS(SDValue Op, SelectionDAG &DAG) const;
  926. SDValue LowerFunnelShift(SDValue Op, SelectionDAG &DAG) const;
  927. SDValue LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG) const;
  928. SDValue LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) const;
  929. SDValue LowerINSERT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) const;
  930. SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const;
  931. SDValue LowerINTRINSIC_VOID(SDValue Op, SelectionDAG &DAG) const;
  932. SDValue LowerBSWAP(SDValue Op, SelectionDAG &DAG) const;
  933. SDValue LowerATOMIC_CMP_SWAP(SDValue Op, SelectionDAG &DAG) const;
  934. SDValue LowerSCALAR_TO_VECTOR(SDValue Op, SelectionDAG &DAG) const;
  935. SDValue LowerMUL(SDValue Op, SelectionDAG &DAG) const;
  936. SDValue LowerFP_EXTEND(SDValue Op, SelectionDAG &DAG) const;
  937. SDValue LowerFP_ROUND(SDValue Op, SelectionDAG &DAG) const;
  938. SDValue LowerROTL(SDValue Op, SelectionDAG &DAG) const;
  939. SDValue LowerVectorLoad(SDValue Op, SelectionDAG &DAG) const;
  940. SDValue LowerVectorStore(SDValue Op, SelectionDAG &DAG) const;
  941. SDValue LowerCallResult(SDValue Chain, SDValue InFlag,
  942. CallingConv::ID CallConv, bool isVarArg,
  943. const SmallVectorImpl<ISD::InputArg> &Ins,
  944. const SDLoc &dl, SelectionDAG &DAG,
  945. SmallVectorImpl<SDValue> &InVals) const;
  946. SDValue FinishCall(CallFlags CFlags, const SDLoc &dl, SelectionDAG &DAG,
  947. SmallVector<std::pair<unsigned, SDValue>, 8> &RegsToPass,
  948. SDValue InFlag, SDValue Chain, SDValue CallSeqStart,
  949. SDValue &Callee, int SPDiff, unsigned NumBytes,
  950. const SmallVectorImpl<ISD::InputArg> &Ins,
  951. SmallVectorImpl<SDValue> &InVals,
  952. const CallBase *CB) const;
  953. SDValue
  954. LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
  955. const SmallVectorImpl<ISD::InputArg> &Ins,
  956. const SDLoc &dl, SelectionDAG &DAG,
  957. SmallVectorImpl<SDValue> &InVals) const override;
  958. SDValue LowerCall(TargetLowering::CallLoweringInfo &CLI,
  959. SmallVectorImpl<SDValue> &InVals) const override;
  960. bool CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF,
  961. bool isVarArg,
  962. const SmallVectorImpl<ISD::OutputArg> &Outs,
  963. LLVMContext &Context) const override;
  964. SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
  965. const SmallVectorImpl<ISD::OutputArg> &Outs,
  966. const SmallVectorImpl<SDValue> &OutVals,
  967. const SDLoc &dl, SelectionDAG &DAG) const override;
  968. SDValue extendArgForPPC64(ISD::ArgFlagsTy Flags, EVT ObjectVT,
  969. SelectionDAG &DAG, SDValue ArgVal,
  970. const SDLoc &dl) const;
  971. SDValue LowerFormalArguments_AIX(
  972. SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
  973. const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &dl,
  974. SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals) const;
  975. SDValue LowerFormalArguments_64SVR4(
  976. SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
  977. const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &dl,
  978. SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals) const;
  979. SDValue LowerFormalArguments_32SVR4(
  980. SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
  981. const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &dl,
  982. SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals) const;
  983. SDValue createMemcpyOutsideCallSeq(SDValue Arg, SDValue PtrOff,
  984. SDValue CallSeqStart,
  985. ISD::ArgFlagsTy Flags, SelectionDAG &DAG,
  986. const SDLoc &dl) const;
  987. SDValue LowerCall_64SVR4(SDValue Chain, SDValue Callee, CallFlags CFlags,
  988. const SmallVectorImpl<ISD::OutputArg> &Outs,
  989. const SmallVectorImpl<SDValue> &OutVals,
  990. const SmallVectorImpl<ISD::InputArg> &Ins,
  991. const SDLoc &dl, SelectionDAG &DAG,
  992. SmallVectorImpl<SDValue> &InVals,
  993. const CallBase *CB) const;
  994. SDValue LowerCall_32SVR4(SDValue Chain, SDValue Callee, CallFlags CFlags,
  995. const SmallVectorImpl<ISD::OutputArg> &Outs,
  996. const SmallVectorImpl<SDValue> &OutVals,
  997. const SmallVectorImpl<ISD::InputArg> &Ins,
  998. const SDLoc &dl, SelectionDAG &DAG,
  999. SmallVectorImpl<SDValue> &InVals,
  1000. const CallBase *CB) const;
  1001. SDValue LowerCall_AIX(SDValue Chain, SDValue Callee, CallFlags CFlags,
  1002. const SmallVectorImpl<ISD::OutputArg> &Outs,
  1003. const SmallVectorImpl<SDValue> &OutVals,
  1004. const SmallVectorImpl<ISD::InputArg> &Ins,
  1005. const SDLoc &dl, SelectionDAG &DAG,
  1006. SmallVectorImpl<SDValue> &InVals,
  1007. const CallBase *CB) const;
  1008. SDValue lowerEH_SJLJ_SETJMP(SDValue Op, SelectionDAG &DAG) const;
  1009. SDValue lowerEH_SJLJ_LONGJMP(SDValue Op, SelectionDAG &DAG) const;
  1010. SDValue LowerBITCAST(SDValue Op, SelectionDAG &DAG) const;
  1011. SDValue DAGCombineExtBoolTrunc(SDNode *N, DAGCombinerInfo &DCI) const;
  1012. SDValue DAGCombineBuildVector(SDNode *N, DAGCombinerInfo &DCI) const;
  1013. SDValue DAGCombineTruncBoolExt(SDNode *N, DAGCombinerInfo &DCI) const;
  1014. SDValue combineStoreFPToInt(SDNode *N, DAGCombinerInfo &DCI) const;
  1015. SDValue combineFPToIntToFP(SDNode *N, DAGCombinerInfo &DCI) const;
  1016. SDValue combineSHL(SDNode *N, DAGCombinerInfo &DCI) const;
  1017. SDValue combineSRA(SDNode *N, DAGCombinerInfo &DCI) const;
  1018. SDValue combineSRL(SDNode *N, DAGCombinerInfo &DCI) const;
  1019. SDValue combineMUL(SDNode *N, DAGCombinerInfo &DCI) const;
  1020. SDValue combineADD(SDNode *N, DAGCombinerInfo &DCI) const;
  1021. SDValue combineFMALike(SDNode *N, DAGCombinerInfo &DCI) const;
  1022. SDValue combineTRUNCATE(SDNode *N, DAGCombinerInfo &DCI) const;
  1023. SDValue combineSetCC(SDNode *N, DAGCombinerInfo &DCI) const;
  1024. SDValue combineABS(SDNode *N, DAGCombinerInfo &DCI) const;
  1025. SDValue combineVSelect(SDNode *N, DAGCombinerInfo &DCI) const;
  1026. SDValue combineVectorShuffle(ShuffleVectorSDNode *SVN,
  1027. SelectionDAG &DAG) const;
  1028. SDValue combineVReverseMemOP(ShuffleVectorSDNode *SVN, LSBaseSDNode *LSBase,
  1029. DAGCombinerInfo &DCI) const;
  1030. /// ConvertSETCCToSubtract - looks at SETCC that compares ints. It replaces
  1031. /// SETCC with integer subtraction when (1) there is a legal way of doing it
  1032. /// (2) keeping the result of comparison in GPR has performance benefit.
  1033. SDValue ConvertSETCCToSubtract(SDNode *N, DAGCombinerInfo &DCI) const;
  1034. SDValue getSqrtEstimate(SDValue Operand, SelectionDAG &DAG, int Enabled,
  1035. int &RefinementSteps, bool &UseOneConstNR,
  1036. bool Reciprocal) const override;
  1037. SDValue getRecipEstimate(SDValue Operand, SelectionDAG &DAG, int Enabled,
  1038. int &RefinementSteps) const override;
  1039. SDValue getSqrtInputTest(SDValue Operand, SelectionDAG &DAG,
  1040. const DenormalMode &Mode) const override;
  1041. SDValue getSqrtResultForDenormInput(SDValue Operand,
  1042. SelectionDAG &DAG) const override;
  1043. unsigned combineRepeatedFPDivisors() const override;
  1044. SDValue
  1045. combineElementTruncationToVectorTruncation(SDNode *N,
  1046. DAGCombinerInfo &DCI) const;
  1047. /// lowerToVINSERTH - Return the SDValue if this VECTOR_SHUFFLE can be
  1048. /// handled by the VINSERTH instruction introduced in ISA 3.0. This is
  1049. /// essentially any shuffle of v8i16 vectors that just inserts one element
  1050. /// from one vector into the other.
  1051. SDValue lowerToVINSERTH(ShuffleVectorSDNode *N, SelectionDAG &DAG) const;
  1052. /// lowerToVINSERTB - Return the SDValue if this VECTOR_SHUFFLE can be
  1053. /// handled by the VINSERTB instruction introduced in ISA 3.0. This is
  1054. /// essentially v16i8 vector version of VINSERTH.
  1055. SDValue lowerToVINSERTB(ShuffleVectorSDNode *N, SelectionDAG &DAG) const;
  1056. /// lowerToXXSPLTI32DX - Return the SDValue if this VECTOR_SHUFFLE can be
  1057. /// handled by the XXSPLTI32DX instruction introduced in ISA 3.1.
  1058. SDValue lowerToXXSPLTI32DX(ShuffleVectorSDNode *N, SelectionDAG &DAG) const;
  1059. // Return whether the call instruction can potentially be optimized to a
  1060. // tail call. This will cause the optimizers to attempt to move, or
  1061. // duplicate return instructions to help enable tail call optimizations.
  1062. bool mayBeEmittedAsTailCall(const CallInst *CI) const override;
  1063. bool hasBitPreservingFPLogic(EVT VT) const override;
  1064. bool isMaskAndCmp0FoldingBeneficial(const Instruction &AndI) const override;
  1065. }; // end class PPCTargetLowering
  1066. namespace PPC {
  1067. FastISel *createFastISel(FunctionLoweringInfo &FuncInfo,
  1068. const TargetLibraryInfo *LibInfo);
  1069. } // end namespace PPC
  1070. bool isIntS16Immediate(SDNode *N, int16_t &Imm);
  1071. bool isIntS16Immediate(SDValue Op, int16_t &Imm);
  1072. bool isIntS34Immediate(SDNode *N, int64_t &Imm);
  1073. bool isIntS34Immediate(SDValue Op, int64_t &Imm);
  1074. bool convertToNonDenormSingle(APInt &ArgAPInt);
  1075. bool convertToNonDenormSingle(APFloat &ArgAPFloat);
  1076. } // end namespace llvm
  1077. #endif // LLVM_TARGET_POWERPC_PPC32ISELLOWERING_H