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