PPCISelLowering.h 65 KB

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