Make getByValTypeAlignment() taking DataLayout as an argument
[oota-llvm.git] / lib / Target / PowerPC / PPCISelLowering.h
1 //===-- PPCISelLowering.h - PPC32 DAG Lowering Interface --------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the interfaces that PPC uses to lower LLVM code into a
11 // selection DAG.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_LIB_TARGET_POWERPC_PPCISELLOWERING_H
16 #define LLVM_LIB_TARGET_POWERPC_PPCISELLOWERING_H
17
18 #include "PPC.h"
19 #include "PPCInstrInfo.h"
20 #include "PPCRegisterInfo.h"
21 #include "llvm/CodeGen/CallingConvLower.h"
22 #include "llvm/CodeGen/SelectionDAG.h"
23 #include "llvm/Target/TargetLowering.h"
24
25 namespace llvm {
26   namespace PPCISD {
27     enum NodeType : unsigned {
28       // Start the numbering where the builtin ops and target ops leave off.
29       FIRST_NUMBER = ISD::BUILTIN_OP_END,
30
31       /// FSEL - Traditional three-operand fsel node.
32       ///
33       FSEL,
34
35       /// FCFID - The FCFID instruction, taking an f64 operand and producing
36       /// and f64 value containing the FP representation of the integer that
37       /// was temporarily in the f64 operand.
38       FCFID,
39
40       /// Newer FCFID[US] integer-to-floating-point conversion instructions for
41       /// unsigned integers and single-precision outputs.
42       FCFIDU, FCFIDS, FCFIDUS,
43
44       /// FCTI[D,W]Z - The FCTIDZ and FCTIWZ instructions, taking an f32 or f64
45       /// operand, producing an f64 value containing the integer representation
46       /// of that FP value.
47       FCTIDZ, FCTIWZ,
48
49       /// Newer FCTI[D,W]UZ floating-point-to-integer conversion instructions for
50       /// unsigned integers.
51       FCTIDUZ, FCTIWUZ,
52
53       /// Reciprocal estimate instructions (unary FP ops).
54       FRE, FRSQRTE,
55
56       // VMADDFP, VNMSUBFP - The VMADDFP and VNMSUBFP instructions, taking
57       // three v4f32 operands and producing a v4f32 result.
58       VMADDFP, VNMSUBFP,
59
60       /// VPERM - The PPC VPERM Instruction.
61       ///
62       VPERM,
63
64       /// The CMPB instruction (takes two operands of i32 or i64).
65       CMPB,
66
67       /// Hi/Lo - These represent the high and low 16-bit parts of a global
68       /// address respectively.  These nodes have two operands, the first of
69       /// which must be a TargetGlobalAddress, and the second of which must be a
70       /// Constant.  Selected naively, these turn into 'lis G+C' and 'li G+C',
71       /// though these are usually folded into other nodes.
72       Hi, Lo,
73
74       /// The following two target-specific nodes are used for calls through
75       /// function pointers in the 64-bit SVR4 ABI.
76
77       /// OPRC, CHAIN = DYNALLOC(CHAIN, NEGSIZE, FRAME_INDEX)
78       /// This instruction is lowered in PPCRegisterInfo::eliminateFrameIndex to
79       /// compute an allocation on the stack.
80       DYNALLOC,
81
82       /// GlobalBaseReg - On Darwin, this node represents the result of the mflr
83       /// at function entry, used for PIC code.
84       GlobalBaseReg,
85
86       /// These nodes represent the 32-bit PPC shifts that operate on 6-bit
87       /// shift amounts.  These nodes are generated by the multi-precision shift
88       /// code.
89       SRL, SRA, SHL,
90
91       /// The combination of sra[wd]i and addze used to implemented signed
92       /// integer division by a power of 2. The first operand is the dividend,
93       /// and the second is the constant shift amount (representing the
94       /// divisor).
95       SRA_ADDZE,
96
97       /// CALL - A direct function call.
98       /// CALL_NOP is a call with the special NOP which follows 64-bit
99       /// SVR4 calls.
100       CALL, CALL_NOP,
101
102       /// CHAIN,FLAG = MTCTR(VAL, CHAIN[, INFLAG]) - Directly corresponds to a
103       /// MTCTR instruction.
104       MTCTR,
105
106       /// CHAIN,FLAG = BCTRL(CHAIN, INFLAG) - Directly corresponds to a
107       /// BCTRL instruction.
108       BCTRL,
109
110       /// CHAIN,FLAG = BCTRL(CHAIN, ADDR, INFLAG) - The combination of a bctrl
111       /// instruction and the TOC reload required on SVR4 PPC64.
112       BCTRL_LOAD_TOC,
113
114       /// Return with a flag operand, matched by 'blr'
115       RET_FLAG,
116
117       /// R32 = MFOCRF(CRREG, INFLAG) - Represents the MFOCRF instruction.
118       /// This copies the bits corresponding to the specified CRREG into the
119       /// resultant GPR.  Bits corresponding to other CR regs are undefined.
120       MFOCRF,
121
122       /// Direct move from a VSX register to a GPR
123       MFVSR,
124
125       /// Direct move from a GPR to a VSX register (algebraic)
126       MTVSRA,
127
128       /// Direct move from a GPR to a VSX register (zero)
129       MTVSRZ,
130
131       // FIXME: Remove these once the ANDI glue bug is fixed:
132       /// i1 = ANDIo_1_[EQ|GT]_BIT(i32 or i64 x) - Represents the result of the
133       /// eq or gt bit of CR0 after executing andi. x, 1. This is used to
134       /// implement truncation of i32 or i64 to i1.
135       ANDIo_1_EQ_BIT, ANDIo_1_GT_BIT,
136
137       // READ_TIME_BASE - A read of the 64-bit time-base register on a 32-bit
138       // target (returns (Lo, Hi)). It takes a chain operand.
139       READ_TIME_BASE,
140
141       // EH_SJLJ_SETJMP - SjLj exception handling setjmp.
142       EH_SJLJ_SETJMP,
143
144       // EH_SJLJ_LONGJMP - SjLj exception handling longjmp.
145       EH_SJLJ_LONGJMP,
146
147       /// RESVEC = VCMP(LHS, RHS, OPC) - Represents one of the altivec VCMP*
148       /// instructions.  For lack of better number, we use the opcode number
149       /// encoding for the OPC field to identify the compare.  For example, 838
150       /// is VCMPGTSH.
151       VCMP,
152
153       /// RESVEC, OUTFLAG = VCMPo(LHS, RHS, OPC) - Represents one of the
154       /// altivec VCMP*o instructions.  For lack of better number, we use the
155       /// opcode number encoding for the OPC field to identify the compare.  For
156       /// example, 838 is VCMPGTSH.
157       VCMPo,
158
159       /// CHAIN = COND_BRANCH CHAIN, CRRC, OPC, DESTBB [, INFLAG] - This
160       /// corresponds to the COND_BRANCH pseudo instruction.  CRRC is the
161       /// condition register to branch on, OPC is the branch opcode to use (e.g.
162       /// PPC::BLE), DESTBB is the destination block to branch to, and INFLAG is
163       /// an optional input flag argument.
164       COND_BRANCH,
165
166       /// CHAIN = BDNZ CHAIN, DESTBB - These are used to create counter-based
167       /// loops.
168       BDNZ, BDZ,
169
170       /// F8RC = FADDRTZ F8RC, F8RC - This is an FADD done with rounding
171       /// towards zero.  Used only as part of the long double-to-int
172       /// conversion sequence.
173       FADDRTZ,
174
175       /// F8RC = MFFS - This moves the FPSCR (not modeled) into the register.
176       MFFS,
177
178       /// TC_RETURN - A tail call return.
179       ///   operand #0 chain
180       ///   operand #1 callee (register or absolute)
181       ///   operand #2 stack adjustment
182       ///   operand #3 optional in flag
183       TC_RETURN,
184
185       /// ch, gl = CR6[UN]SET ch, inglue - Toggle CR bit 6 for SVR4 vararg calls
186       CR6SET,
187       CR6UNSET,
188
189       /// GPRC = address of _GLOBAL_OFFSET_TABLE_. Used by initial-exec TLS
190       /// on PPC32.
191       PPC32_GOT,
192
193       /// GPRC = address of _GLOBAL_OFFSET_TABLE_. Used by general dynamic and
194       /// local dynamic TLS on PPC32.
195       PPC32_PICGOT,
196
197       /// G8RC = ADDIS_GOT_TPREL_HA %X2, Symbol - Used by the initial-exec
198       /// TLS model, produces an ADDIS8 instruction that adds the GOT
199       /// base to sym\@got\@tprel\@ha.
200       ADDIS_GOT_TPREL_HA,
201
202       /// G8RC = LD_GOT_TPREL_L Symbol, G8RReg - Used by the initial-exec
203       /// TLS model, produces a LD instruction with base register G8RReg
204       /// and offset sym\@got\@tprel\@l.  This completes the addition that
205       /// finds the offset of "sym" relative to the thread pointer.
206       LD_GOT_TPREL_L,
207
208       /// G8RC = ADD_TLS G8RReg, Symbol - Used by the initial-exec TLS
209       /// model, produces an ADD instruction that adds the contents of
210       /// G8RReg to the thread pointer.  Symbol contains a relocation
211       /// sym\@tls which is to be replaced by the thread pointer and
212       /// identifies to the linker that the instruction is part of a
213       /// TLS sequence.
214       ADD_TLS,
215
216       /// G8RC = ADDIS_TLSGD_HA %X2, Symbol - For the general-dynamic TLS
217       /// model, produces an ADDIS8 instruction that adds the GOT base
218       /// register to sym\@got\@tlsgd\@ha.
219       ADDIS_TLSGD_HA,
220
221       /// %X3 = ADDI_TLSGD_L G8RReg, Symbol - For the general-dynamic TLS
222       /// model, produces an ADDI8 instruction that adds G8RReg to
223       /// sym\@got\@tlsgd\@l and stores the result in X3.  Hidden by
224       /// ADDIS_TLSGD_L_ADDR until after register assignment.
225       ADDI_TLSGD_L,
226
227       /// %X3 = GET_TLS_ADDR %X3, Symbol - For the general-dynamic TLS
228       /// model, produces a call to __tls_get_addr(sym\@tlsgd).  Hidden by
229       /// ADDIS_TLSGD_L_ADDR until after register assignment.
230       GET_TLS_ADDR,
231
232       /// G8RC = ADDI_TLSGD_L_ADDR G8RReg, Symbol, Symbol - Op that
233       /// combines ADDI_TLSGD_L and GET_TLS_ADDR until expansion following
234       /// register assignment.
235       ADDI_TLSGD_L_ADDR,
236
237       /// G8RC = ADDIS_TLSLD_HA %X2, Symbol - For the local-dynamic TLS
238       /// model, produces an ADDIS8 instruction that adds the GOT base
239       /// register to sym\@got\@tlsld\@ha.
240       ADDIS_TLSLD_HA,
241
242       /// %X3 = ADDI_TLSLD_L G8RReg, Symbol - For the local-dynamic TLS
243       /// model, produces an ADDI8 instruction that adds G8RReg to
244       /// sym\@got\@tlsld\@l and stores the result in X3.  Hidden by
245       /// ADDIS_TLSLD_L_ADDR until after register assignment.
246       ADDI_TLSLD_L,
247
248       /// %X3 = GET_TLSLD_ADDR %X3, Symbol - For the local-dynamic TLS
249       /// model, produces a call to __tls_get_addr(sym\@tlsld).  Hidden by
250       /// ADDIS_TLSLD_L_ADDR until after register assignment.
251       GET_TLSLD_ADDR,
252
253       /// G8RC = ADDI_TLSLD_L_ADDR G8RReg, Symbol, Symbol - Op that
254       /// combines ADDI_TLSLD_L and GET_TLSLD_ADDR until expansion
255       /// following register assignment.
256       ADDI_TLSLD_L_ADDR,
257
258       /// G8RC = ADDIS_DTPREL_HA %X3, Symbol - For the local-dynamic TLS
259       /// model, produces an ADDIS8 instruction that adds X3 to
260       /// sym\@dtprel\@ha.
261       ADDIS_DTPREL_HA,
262
263       /// G8RC = ADDI_DTPREL_L G8RReg, Symbol - For the local-dynamic TLS
264       /// model, produces an ADDI8 instruction that adds G8RReg to
265       /// sym\@got\@dtprel\@l.
266       ADDI_DTPREL_L,
267
268       /// VRRC = VADD_SPLAT Elt, EltSize - Temporary node to be expanded
269       /// during instruction selection to optimize a BUILD_VECTOR into
270       /// operations on splats.  This is necessary to avoid losing these
271       /// optimizations due to constant folding.
272       VADD_SPLAT,
273
274       /// CHAIN = SC CHAIN, Imm128 - System call.  The 7-bit unsigned
275       /// operand identifies the operating system entry point.
276       SC,
277
278       /// CHAIN = CLRBHRB CHAIN - Clear branch history rolling buffer.
279       CLRBHRB,
280
281       /// GPRC, CHAIN = MFBHRBE CHAIN, Entry, Dummy - Move from branch
282       /// history rolling buffer entry.
283       MFBHRBE,
284
285       /// CHAIN = RFEBB CHAIN, State - Return from event-based branch.
286       RFEBB,
287
288       /// VSRC, CHAIN = XXSWAPD CHAIN, VSRC - Occurs only for little
289       /// endian.  Maps to an xxswapd instruction that corrects an lxvd2x
290       /// or stxvd2x instruction.  The chain is necessary because the
291       /// sequence replaces a load and needs to provide the same number
292       /// of outputs.
293       XXSWAPD,
294
295       /// QVFPERM = This corresponds to the QPX qvfperm instruction.
296       QVFPERM,
297
298       /// QVGPCI = This corresponds to the QPX qvgpci instruction.
299       QVGPCI,
300
301       /// QVALIGNI = This corresponds to the QPX qvaligni instruction.
302       QVALIGNI,
303
304       /// QVESPLATI = This corresponds to the QPX qvesplati instruction.
305       QVESPLATI,
306
307       /// QBFLT = Access the underlying QPX floating-point boolean
308       /// representation.
309       QBFLT,
310
311       /// CHAIN = STBRX CHAIN, GPRC, Ptr, Type - This is a
312       /// byte-swapping store instruction.  It byte-swaps the low "Type" bits of
313       /// the GPRC input, then stores it through Ptr.  Type can be either i16 or
314       /// i32.
315       STBRX = ISD::FIRST_TARGET_MEMORY_OPCODE,
316
317       /// GPRC, CHAIN = LBRX CHAIN, Ptr, Type - This is a
318       /// byte-swapping load instruction.  It loads "Type" bits, byte swaps it,
319       /// then puts it in the bottom bits of the GPRC.  TYPE can be either i16
320       /// or i32.
321       LBRX,
322
323       /// STFIWX - The STFIWX instruction.  The first operand is an input token
324       /// chain, then an f64 value to store, then an address to store it to.
325       STFIWX,
326
327       /// GPRC, CHAIN = LFIWAX CHAIN, Ptr - This is a floating-point
328       /// load which sign-extends from a 32-bit integer value into the
329       /// destination 64-bit register.
330       LFIWAX,
331
332       /// GPRC, CHAIN = LFIWZX CHAIN, Ptr - This is a floating-point
333       /// load which zero-extends from a 32-bit integer value into the
334       /// destination 64-bit register.
335       LFIWZX,
336
337       /// VSRC, CHAIN = LXVD2X_LE CHAIN, Ptr - Occurs only for little endian.
338       /// Maps directly to an lxvd2x instruction that will be followed by
339       /// an xxswapd.
340       LXVD2X,
341
342       /// CHAIN = STXVD2X CHAIN, VSRC, Ptr - Occurs only for little endian.
343       /// Maps directly to an stxvd2x instruction that will be preceded by
344       /// an xxswapd.
345       STXVD2X,
346
347       /// QBRC, CHAIN = QVLFSb CHAIN, Ptr
348       /// The 4xf32 load used for v4i1 constants.
349       QVLFSb,
350
351       /// GPRC = TOC_ENTRY GA, TOC
352       /// Loads the entry for GA from the TOC, where the TOC base is given by
353       /// the last operand.
354       TOC_ENTRY
355     };
356   }
357
358   /// Define some predicates that are used for node matching.
359   namespace PPC {
360     /// isVPKUHUMShuffleMask - Return true if this is the shuffle mask for a
361     /// VPKUHUM instruction.
362     bool isVPKUHUMShuffleMask(ShuffleVectorSDNode *N, unsigned ShuffleKind,
363                               SelectionDAG &DAG);
364
365     /// isVPKUWUMShuffleMask - Return true if this is the shuffle mask for a
366     /// VPKUWUM instruction.
367     bool isVPKUWUMShuffleMask(ShuffleVectorSDNode *N, unsigned ShuffleKind,
368                               SelectionDAG &DAG);
369
370     /// isVPKUDUMShuffleMask - Return true if this is the shuffle mask for a
371     /// VPKUDUM instruction.
372     bool isVPKUDUMShuffleMask(ShuffleVectorSDNode *N, unsigned ShuffleKind,
373                               SelectionDAG &DAG);
374
375     /// isVMRGLShuffleMask - Return true if this is a shuffle mask suitable for
376     /// a VRGL* instruction with the specified unit size (1,2 or 4 bytes).
377     bool isVMRGLShuffleMask(ShuffleVectorSDNode *N, unsigned UnitSize,
378                             unsigned ShuffleKind, SelectionDAG &DAG);
379
380     /// isVMRGHShuffleMask - Return true if this is a shuffle mask suitable for
381     /// a VRGH* instruction with the specified unit size (1,2 or 4 bytes).
382     bool isVMRGHShuffleMask(ShuffleVectorSDNode *N, unsigned UnitSize,
383                             unsigned ShuffleKind, SelectionDAG &DAG);
384
385     /// isVMRGEOShuffleMask - Return true if this is a shuffle mask suitable for
386     /// a VMRGEW or VMRGOW instruction
387     bool isVMRGEOShuffleMask(ShuffleVectorSDNode *N, bool CheckEven,
388                              unsigned ShuffleKind, SelectionDAG &DAG);
389   
390     /// isVSLDOIShuffleMask - If this is a vsldoi shuffle mask, return the
391     /// shift amount, otherwise return -1.
392     int isVSLDOIShuffleMask(SDNode *N, unsigned ShuffleKind,
393                             SelectionDAG &DAG);
394
395     /// isSplatShuffleMask - Return true if the specified VECTOR_SHUFFLE operand
396     /// specifies a splat of a single element that is suitable for input to
397     /// VSPLTB/VSPLTH/VSPLTW.
398     bool isSplatShuffleMask(ShuffleVectorSDNode *N, unsigned EltSize);
399
400     /// getVSPLTImmediate - Return the appropriate VSPLT* immediate to splat the
401     /// specified isSplatShuffleMask VECTOR_SHUFFLE mask.
402     unsigned getVSPLTImmediate(SDNode *N, unsigned EltSize, SelectionDAG &DAG);
403
404     /// get_VSPLTI_elt - If this is a build_vector of constants which can be
405     /// formed by using a vspltis[bhw] instruction of the specified element
406     /// size, return the constant being splatted.  The ByteSize field indicates
407     /// the number of bytes of each element [124] -> [bhw].
408     SDValue get_VSPLTI_elt(SDNode *N, unsigned ByteSize, SelectionDAG &DAG);
409
410     /// If this is a qvaligni shuffle mask, return the shift
411     /// amount, otherwise return -1.
412     int isQVALIGNIShuffleMask(SDNode *N);
413   }
414
415   class PPCTargetLowering : public TargetLowering {
416     const PPCSubtarget &Subtarget;
417
418   public:
419     explicit PPCTargetLowering(const PPCTargetMachine &TM,
420                                const PPCSubtarget &STI);
421
422     /// getTargetNodeName() - This method returns the name of a target specific
423     /// DAG node.
424     const char *getTargetNodeName(unsigned Opcode) const override;
425
426     MVT getScalarShiftAmountTy(const DataLayout &) const override {
427       return MVT::i32;
428     }
429
430     bool isCheapToSpeculateCttz() const override {
431       return true;
432     }
433
434     bool isCheapToSpeculateCtlz() const override {
435       return true;
436     }
437
438     /// getSetCCResultType - Return the ISD::SETCC ValueType
439     EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context,
440                            EVT VT) const override;
441
442     /// Return true if target always beneficiates from combining into FMA for a
443     /// given value type. This must typically return false on targets where FMA
444     /// takes more cycles to execute than FADD.
445     bool enableAggressiveFMAFusion(EVT VT) const override;
446
447     /// getPreIndexedAddressParts - returns true by value, base pointer and
448     /// offset pointer and addressing mode by reference if the node's address
449     /// can be legally represented as pre-indexed load / store address.
450     bool getPreIndexedAddressParts(SDNode *N, SDValue &Base,
451                                    SDValue &Offset,
452                                    ISD::MemIndexedMode &AM,
453                                    SelectionDAG &DAG) const override;
454
455     /// SelectAddressRegReg - Given the specified addressed, check to see if it
456     /// can be represented as an indexed [r+r] operation.  Returns false if it
457     /// can be more efficiently represented with [r+imm].
458     bool SelectAddressRegReg(SDValue N, SDValue &Base, SDValue &Index,
459                              SelectionDAG &DAG) const;
460
461     /// SelectAddressRegImm - Returns true if the address N can be represented
462     /// by a base register plus a signed 16-bit displacement [r+imm], and if it
463     /// is not better represented as reg+reg.  If Aligned is true, only accept
464     /// displacements suitable for STD and friends, i.e. multiples of 4.
465     bool SelectAddressRegImm(SDValue N, SDValue &Disp, SDValue &Base,
466                              SelectionDAG &DAG, bool Aligned) const;
467
468     /// SelectAddressRegRegOnly - Given the specified addressed, force it to be
469     /// represented as an indexed [r+r] operation.
470     bool SelectAddressRegRegOnly(SDValue N, SDValue &Base, SDValue &Index,
471                                  SelectionDAG &DAG) const;
472
473     Sched::Preference getSchedulingPreference(SDNode *N) const override;
474
475     /// LowerOperation - Provide custom lowering hooks for some operations.
476     ///
477     SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
478
479     /// ReplaceNodeResults - Replace the results of node with an illegal result
480     /// type with new values built out of custom code.
481     ///
482     void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue>&Results,
483                             SelectionDAG &DAG) const override;
484
485     SDValue expandVSXLoadForLE(SDNode *N, DAGCombinerInfo &DCI) const;
486     SDValue expandVSXStoreForLE(SDNode *N, DAGCombinerInfo &DCI) const;
487
488     SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override;
489
490     SDValue BuildSDIVPow2(SDNode *N, const APInt &Divisor, SelectionDAG &DAG,
491                           std::vector<SDNode *> *Created) const override;
492
493     unsigned getRegisterByName(const char* RegName, EVT VT) const override;
494
495     void computeKnownBitsForTargetNode(const SDValue Op,
496                                        APInt &KnownZero,
497                                        APInt &KnownOne,
498                                        const SelectionDAG &DAG,
499                                        unsigned Depth = 0) const override;
500
501     unsigned getPrefLoopAlignment(MachineLoop *ML) const override;
502
503     Instruction* emitLeadingFence(IRBuilder<> &Builder, AtomicOrdering Ord,
504                                   bool IsStore, bool IsLoad) const override;
505     Instruction* emitTrailingFence(IRBuilder<> &Builder, AtomicOrdering Ord,
506                                    bool IsStore, bool IsLoad) const override;
507
508     MachineBasicBlock *
509       EmitInstrWithCustomInserter(MachineInstr *MI,
510                                   MachineBasicBlock *MBB) const override;
511     MachineBasicBlock *EmitAtomicBinary(MachineInstr *MI,
512                                         MachineBasicBlock *MBB,
513                                         unsigned AtomicSize,
514                                         unsigned BinOpcode) const;
515     MachineBasicBlock *EmitPartwordAtomicBinary(MachineInstr *MI,
516                                                 MachineBasicBlock *MBB,
517                                             bool is8bit, unsigned Opcode) const;
518
519     MachineBasicBlock *emitEHSjLjSetJmp(MachineInstr *MI,
520                                         MachineBasicBlock *MBB) const;
521
522     MachineBasicBlock *emitEHSjLjLongJmp(MachineInstr *MI,
523                                          MachineBasicBlock *MBB) const;
524
525     ConstraintType getConstraintType(StringRef Constraint) const override;
526
527     /// Examine constraint string and operand type and determine a weight value.
528     /// The operand object must already have been set up with the operand type.
529     ConstraintWeight getSingleConstraintMatchWeight(
530       AsmOperandInfo &info, const char *constraint) const override;
531
532     std::pair<unsigned, const TargetRegisterClass *>
533     getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
534                                  StringRef Constraint, MVT VT) const override;
535
536     /// getByValTypeAlignment - Return the desired alignment for ByVal aggregate
537     /// function arguments in the caller parameter area.  This is the actual
538     /// alignment, not its logarithm.
539     unsigned getByValTypeAlignment(Type *Ty,
540                                    const DataLayout &DL) const override;
541
542     /// LowerAsmOperandForConstraint - Lower the specified operand into the Ops
543     /// vector.  If it is invalid, don't add anything to Ops.
544     void LowerAsmOperandForConstraint(SDValue Op,
545                                       std::string &Constraint,
546                                       std::vector<SDValue> &Ops,
547                                       SelectionDAG &DAG) const override;
548
549     unsigned
550     getInlineAsmMemConstraint(StringRef ConstraintCode) const override {
551       if (ConstraintCode == "es")
552         return InlineAsm::Constraint_es;
553       else if (ConstraintCode == "o")
554         return InlineAsm::Constraint_o;
555       else if (ConstraintCode == "Q")
556         return InlineAsm::Constraint_Q;
557       else if (ConstraintCode == "Z")
558         return InlineAsm::Constraint_Z;
559       else if (ConstraintCode == "Zy")
560         return InlineAsm::Constraint_Zy;
561       return TargetLowering::getInlineAsmMemConstraint(ConstraintCode);
562     }
563
564     /// isLegalAddressingMode - Return true if the addressing mode represented
565     /// by AM is legal for this target, for a load/store of the specified type.
566     bool isLegalAddressingMode(const AddrMode &AM, Type *Ty,
567                                unsigned AS) const override;
568
569     /// isLegalICmpImmediate - Return true if the specified immediate is legal
570     /// icmp immediate, that is the target has icmp instructions which can
571     /// compare a register against the immediate without having to materialize
572     /// the immediate into a register.
573     bool isLegalICmpImmediate(int64_t Imm) const override;
574
575     /// isLegalAddImmediate - Return true if the specified immediate is legal
576     /// add immediate, that is the target has add instructions which can
577     /// add a register and the immediate without having to materialize
578     /// the immediate into a register.
579     bool isLegalAddImmediate(int64_t Imm) const override;
580
581     /// isTruncateFree - Return true if it's free to truncate a value of
582     /// type Ty1 to type Ty2. e.g. On PPC it's free to truncate a i64 value in
583     /// register X1 to i32 by referencing its sub-register R1.
584     bool isTruncateFree(Type *Ty1, Type *Ty2) const override;
585     bool isTruncateFree(EVT VT1, EVT VT2) const override;
586
587     bool isZExtFree(SDValue Val, EVT VT2) const override;
588
589     bool isFPExtFree(EVT VT) const override;
590
591     /// \brief Returns true if it is beneficial to convert a load of a constant
592     /// to just the constant itself.
593     bool shouldConvertConstantLoadToIntImm(const APInt &Imm,
594                                            Type *Ty) const override;
595
596     bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override;
597
598     bool getTgtMemIntrinsic(IntrinsicInfo &Info,
599                             const CallInst &I,
600                             unsigned Intrinsic) const override;
601
602     /// getOptimalMemOpType - Returns the target specific optimal type for load
603     /// and store operations as a result of memset, memcpy, and memmove
604     /// lowering. If DstAlign is zero that means it's safe to destination
605     /// alignment can satisfy any constraint. Similarly if SrcAlign is zero it
606     /// means there isn't a need to check it against alignment requirement,
607     /// probably because the source does not need to be loaded. If 'IsMemset' is
608     /// true, that means it's expanding a memset. If 'ZeroMemset' is true, that
609     /// means it's a memset of zero. 'MemcpyStrSrc' indicates whether the memcpy
610     /// source is constant so it does not need to be loaded.
611     /// It returns EVT::Other if the type should be determined using generic
612     /// target-independent logic.
613     EVT
614     getOptimalMemOpType(uint64_t Size, unsigned DstAlign, unsigned SrcAlign,
615                         bool IsMemset, bool ZeroMemset, bool MemcpyStrSrc,
616                         MachineFunction &MF) const override;
617
618     /// Is unaligned memory access allowed for the given type, and is it fast
619     /// relative to software emulation.
620     bool allowsMisalignedMemoryAccesses(EVT VT,
621                                         unsigned AddrSpace,
622                                         unsigned Align = 1,
623                                         bool *Fast = nullptr) const override;
624
625     /// isFMAFasterThanFMulAndFAdd - Return true if an FMA operation is faster
626     /// than a pair of fmul and fadd instructions. fmuladd intrinsics will be
627     /// expanded to FMAs when this method returns true, otherwise fmuladd is
628     /// expanded to fmul + fadd.
629     bool isFMAFasterThanFMulAndFAdd(EVT VT) const override;
630
631     const MCPhysReg *getScratchRegisters(CallingConv::ID CC) const override;
632
633     // Should we expand the build vector with shuffles?
634     bool
635     shouldExpandBuildVectorWithShuffles(EVT VT,
636                                         unsigned DefinedValues) const override;
637
638     /// createFastISel - This method returns a target-specific FastISel object,
639     /// or null if the target does not support "fast" instruction selection.
640     FastISel *createFastISel(FunctionLoweringInfo &FuncInfo,
641                              const TargetLibraryInfo *LibInfo) const override;
642
643     /// \brief Returns true if an argument of type Ty needs to be passed in a
644     /// contiguous block of registers in calling convention CallConv.
645     bool functionArgumentNeedsConsecutiveRegisters(
646       Type *Ty, CallingConv::ID CallConv, bool isVarArg) const override {
647       // We support any array type as "consecutive" block in the parameter
648       // save area.  The element type defines the alignment requirement and
649       // whether the argument should go in GPRs, FPRs, or VRs if available.
650       //
651       // Note that clang uses this capability both to implement the ELFv2
652       // homogeneous float/vector aggregate ABI, and to avoid having to use
653       // "byval" when passing aggregates that might fully fit in registers.
654       return Ty->isArrayTy();
655     }
656
657   private:
658
659     struct ReuseLoadInfo {
660       SDValue Ptr;
661       SDValue Chain;
662       SDValue ResChain;
663       MachinePointerInfo MPI;
664       bool IsInvariant;
665       unsigned Alignment;
666       AAMDNodes AAInfo;
667       const MDNode *Ranges;
668
669       ReuseLoadInfo() : IsInvariant(false), Alignment(0), Ranges(nullptr) {}
670     };
671
672     bool canReuseLoadAddress(SDValue Op, EVT MemVT, ReuseLoadInfo &RLI,
673                              SelectionDAG &DAG,
674                              ISD::LoadExtType ET = ISD::NON_EXTLOAD) const;
675     void spliceIntoChain(SDValue ResChain, SDValue NewResChain,
676                          SelectionDAG &DAG) const;
677
678     void LowerFP_TO_INTForReuse(SDValue Op, ReuseLoadInfo &RLI,
679                                 SelectionDAG &DAG, SDLoc dl) const;
680     SDValue LowerFP_TO_INTDirectMove(SDValue Op, SelectionDAG &DAG,
681                                      SDLoc dl) const;
682     SDValue LowerINT_TO_FPDirectMove(SDValue Op, SelectionDAG &DAG,
683                                      SDLoc dl) const;
684
685     SDValue getFramePointerFrameIndex(SelectionDAG & DAG) const;
686     SDValue getReturnAddrFrameIndex(SelectionDAG & DAG) const;
687
688     bool
689     IsEligibleForTailCallOptimization(SDValue Callee,
690                                       CallingConv::ID CalleeCC,
691                                       bool isVarArg,
692                                       const SmallVectorImpl<ISD::InputArg> &Ins,
693                                       SelectionDAG& DAG) const;
694
695     SDValue EmitTailCallLoadFPAndRetAddr(SelectionDAG & DAG,
696                                          int SPDiff,
697                                          SDValue Chain,
698                                          SDValue &LROpOut,
699                                          SDValue &FPOpOut,
700                                          bool isDarwinABI,
701                                          SDLoc dl) const;
702
703     SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
704     SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
705     SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const;
706     SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;
707     SDValue LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const;
708     SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;
709     SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) const;
710     SDValue LowerSETCC(SDValue Op, SelectionDAG &DAG) const;
711     SDValue LowerINIT_TRAMPOLINE(SDValue Op, SelectionDAG &DAG) const;
712     SDValue LowerADJUST_TRAMPOLINE(SDValue Op, SelectionDAG &DAG) const;
713     SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG,
714                          const PPCSubtarget &Subtarget) const;
715     SDValue LowerVAARG(SDValue Op, SelectionDAG &DAG,
716                        const PPCSubtarget &Subtarget) const;
717     SDValue LowerVACOPY(SDValue Op, SelectionDAG &DAG,
718                         const PPCSubtarget &Subtarget) const;
719     SDValue LowerSTACKRESTORE(SDValue Op, SelectionDAG &DAG,
720                                 const PPCSubtarget &Subtarget) const;
721     SDValue LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG,
722                                       const PPCSubtarget &Subtarget) const;
723     SDValue LowerLOAD(SDValue Op, SelectionDAG &DAG) const;
724     SDValue LowerSTORE(SDValue Op, SelectionDAG &DAG) const;
725     SDValue LowerTRUNCATE(SDValue Op, SelectionDAG &DAG) const;
726     SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const;
727     SDValue LowerFP_TO_INT(SDValue Op, SelectionDAG &DAG, SDLoc dl) const;
728     SDValue LowerINT_TO_FP(SDValue Op, SelectionDAG &DAG) const;
729     SDValue LowerFLT_ROUNDS_(SDValue Op, SelectionDAG &DAG) const;
730     SDValue LowerSHL_PARTS(SDValue Op, SelectionDAG &DAG) const;
731     SDValue LowerSRL_PARTS(SDValue Op, SelectionDAG &DAG) const;
732     SDValue LowerSRA_PARTS(SDValue Op, SelectionDAG &DAG) const;
733     SDValue LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG) const;
734     SDValue LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) const;
735     SDValue LowerEXTRACT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) const;
736     SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const;
737     SDValue LowerSCALAR_TO_VECTOR(SDValue Op, SelectionDAG &DAG) const;
738     SDValue LowerSIGN_EXTEND_INREG(SDValue Op, SelectionDAG &DAG) const;
739     SDValue LowerMUL(SDValue Op, SelectionDAG &DAG) const;
740
741     SDValue LowerVectorLoad(SDValue Op, SelectionDAG &DAG) const;
742     SDValue LowerVectorStore(SDValue Op, SelectionDAG &DAG) const;
743
744     SDValue LowerCallResult(SDValue Chain, SDValue InFlag,
745                             CallingConv::ID CallConv, bool isVarArg,
746                             const SmallVectorImpl<ISD::InputArg> &Ins,
747                             SDLoc dl, SelectionDAG &DAG,
748                             SmallVectorImpl<SDValue> &InVals) const;
749     SDValue FinishCall(CallingConv::ID CallConv, SDLoc dl, bool isTailCall,
750                        bool isVarArg, bool IsPatchPoint,
751                        SelectionDAG &DAG,
752                        SmallVector<std::pair<unsigned, SDValue>, 8>
753                          &RegsToPass,
754                        SDValue InFlag, SDValue Chain, SDValue CallSeqStart,
755                        SDValue &Callee,
756                        int SPDiff, unsigned NumBytes,
757                        const SmallVectorImpl<ISD::InputArg> &Ins,
758                        SmallVectorImpl<SDValue> &InVals,
759                        ImmutableCallSite *CS) const;
760
761     SDValue
762       LowerFormalArguments(SDValue Chain,
763                            CallingConv::ID CallConv, bool isVarArg,
764                            const SmallVectorImpl<ISD::InputArg> &Ins,
765                            SDLoc dl, SelectionDAG &DAG,
766                            SmallVectorImpl<SDValue> &InVals) const override;
767
768     SDValue
769       LowerCall(TargetLowering::CallLoweringInfo &CLI,
770                 SmallVectorImpl<SDValue> &InVals) const override;
771
772     bool
773       CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF,
774                    bool isVarArg,
775                    const SmallVectorImpl<ISD::OutputArg> &Outs,
776                    LLVMContext &Context) const override;
777
778     SDValue
779       LowerReturn(SDValue Chain,
780                   CallingConv::ID CallConv, bool isVarArg,
781                   const SmallVectorImpl<ISD::OutputArg> &Outs,
782                   const SmallVectorImpl<SDValue> &OutVals,
783                   SDLoc dl, SelectionDAG &DAG) const override;
784
785     SDValue
786       extendArgForPPC64(ISD::ArgFlagsTy Flags, EVT ObjectVT, SelectionDAG &DAG,
787                         SDValue ArgVal, SDLoc dl) const;
788
789     SDValue
790       LowerFormalArguments_Darwin(SDValue Chain,
791                                   CallingConv::ID CallConv, bool isVarArg,
792                                   const SmallVectorImpl<ISD::InputArg> &Ins,
793                                   SDLoc dl, SelectionDAG &DAG,
794                                   SmallVectorImpl<SDValue> &InVals) const;
795     SDValue
796       LowerFormalArguments_64SVR4(SDValue Chain,
797                                   CallingConv::ID CallConv, bool isVarArg,
798                                   const SmallVectorImpl<ISD::InputArg> &Ins,
799                                   SDLoc dl, SelectionDAG &DAG,
800                                   SmallVectorImpl<SDValue> &InVals) const;
801     SDValue
802       LowerFormalArguments_32SVR4(SDValue Chain,
803                                   CallingConv::ID CallConv, bool isVarArg,
804                                   const SmallVectorImpl<ISD::InputArg> &Ins,
805                                   SDLoc dl, SelectionDAG &DAG,
806                                   SmallVectorImpl<SDValue> &InVals) const;
807
808     SDValue
809       createMemcpyOutsideCallSeq(SDValue Arg, SDValue PtrOff,
810                                  SDValue CallSeqStart, ISD::ArgFlagsTy Flags,
811                                  SelectionDAG &DAG, SDLoc dl) const;
812
813     SDValue
814       LowerCall_Darwin(SDValue Chain, SDValue Callee,
815                        CallingConv::ID CallConv,
816                        bool isVarArg, bool isTailCall, bool IsPatchPoint,
817                        const SmallVectorImpl<ISD::OutputArg> &Outs,
818                        const SmallVectorImpl<SDValue> &OutVals,
819                        const SmallVectorImpl<ISD::InputArg> &Ins,
820                        SDLoc dl, SelectionDAG &DAG,
821                        SmallVectorImpl<SDValue> &InVals,
822                        ImmutableCallSite *CS) const;
823     SDValue
824       LowerCall_64SVR4(SDValue Chain, SDValue Callee,
825                        CallingConv::ID CallConv,
826                        bool isVarArg, bool isTailCall, bool IsPatchPoint,
827                        const SmallVectorImpl<ISD::OutputArg> &Outs,
828                        const SmallVectorImpl<SDValue> &OutVals,
829                        const SmallVectorImpl<ISD::InputArg> &Ins,
830                        SDLoc dl, SelectionDAG &DAG,
831                        SmallVectorImpl<SDValue> &InVals,
832                        ImmutableCallSite *CS) const;
833     SDValue
834     LowerCall_32SVR4(SDValue Chain, SDValue Callee, CallingConv::ID CallConv,
835                      bool isVarArg, bool isTailCall, bool IsPatchPoint,
836                      const SmallVectorImpl<ISD::OutputArg> &Outs,
837                      const SmallVectorImpl<SDValue> &OutVals,
838                      const SmallVectorImpl<ISD::InputArg> &Ins,
839                      SDLoc dl, SelectionDAG &DAG,
840                      SmallVectorImpl<SDValue> &InVals,
841                      ImmutableCallSite *CS) const;
842
843     SDValue lowerEH_SJLJ_SETJMP(SDValue Op, SelectionDAG &DAG) const;
844     SDValue lowerEH_SJLJ_LONGJMP(SDValue Op, SelectionDAG &DAG) const;
845
846     SDValue DAGCombineExtBoolTrunc(SDNode *N, DAGCombinerInfo &DCI) const;
847     SDValue DAGCombineTruncBoolExt(SDNode *N, DAGCombinerInfo &DCI) const;
848     SDValue combineFPToIntToFP(SDNode *N, DAGCombinerInfo &DCI) const;
849
850     SDValue getRsqrtEstimate(SDValue Operand, DAGCombinerInfo &DCI,
851                              unsigned &RefinementSteps,
852                              bool &UseOneConstNR) const override;
853     SDValue getRecipEstimate(SDValue Operand, DAGCombinerInfo &DCI,
854                              unsigned &RefinementSteps) const override;
855     bool combineRepeatedFPDivisors(unsigned NumUsers) const override;
856
857     CCAssignFn *useFastISelCCs(unsigned Flag) const;
858   };
859
860   namespace PPC {
861     FastISel *createFastISel(FunctionLoweringInfo &FuncInfo,
862                              const TargetLibraryInfo *LibInfo);
863   }
864
865   bool CC_PPC32_SVR4_Custom_Dummy(unsigned &ValNo, MVT &ValVT, MVT &LocVT,
866                                   CCValAssign::LocInfo &LocInfo,
867                                   ISD::ArgFlagsTy &ArgFlags,
868                                   CCState &State);
869
870   bool CC_PPC32_SVR4_Custom_AlignArgRegs(unsigned &ValNo, MVT &ValVT,
871                                          MVT &LocVT,
872                                          CCValAssign::LocInfo &LocInfo,
873                                          ISD::ArgFlagsTy &ArgFlags,
874                                          CCState &State);
875
876   bool CC_PPC32_SVR4_Custom_AlignFPArgRegs(unsigned &ValNo, MVT &ValVT,
877                                            MVT &LocVT,
878                                            CCValAssign::LocInfo &LocInfo,
879                                            ISD::ArgFlagsTy &ArgFlags,
880                                            CCState &State);
881 }
882
883 #endif   // LLVM_TARGET_POWERPC_PPC32ISELLOWERING_H