2564d3d9bf3abf1b31dcff9340766b8d6e779202
[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 {
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       /// Hi/Lo - These represent the high and low 16-bit parts of a global
65       /// address respectively.  These nodes have two operands, the first of
66       /// which must be a TargetGlobalAddress, and the second of which must be a
67       /// Constant.  Selected naively, these turn into 'lis G+C' and 'li G+C',
68       /// though these are usually folded into other nodes.
69       Hi, Lo,
70
71       TOC_ENTRY,
72
73       /// The following two target-specific nodes are used for calls through
74       /// function pointers in the 64-bit SVR4 ABI.
75
76       /// Like a regular LOAD but additionally taking/producing a flag.
77       LOAD,
78
79       /// Like LOAD (taking/producing a flag), but using r2 as hard-coded
80       /// destination.
81       LOAD_TOC,
82
83       /// OPRC, CHAIN = DYNALLOC(CHAIN, NEGSIZE, FRAME_INDEX)
84       /// This instruction is lowered in PPCRegisterInfo::eliminateFrameIndex to
85       /// compute an allocation on the stack.
86       DYNALLOC,
87
88       /// GlobalBaseReg - On Darwin, this node represents the result of the mflr
89       /// at function entry, used for PIC code.
90       GlobalBaseReg,
91
92       /// These nodes represent the 32-bit PPC shifts that operate on 6-bit
93       /// shift amounts.  These nodes are generated by the multi-precision shift
94       /// code.
95       SRL, SRA, SHL,
96
97       /// The combination of sra[wd]i and addze used to implemented signed
98       /// integer division by a power of 2. The first operand is the dividend,
99       /// and the second is the constant shift amount (representing the
100       /// divisor).
101       SRA_ADDZE,
102
103       /// CALL - A direct function call.
104       /// CALL_NOP is a call with the special NOP which follows 64-bit
105       /// SVR4 calls.
106       CALL, CALL_NOP,
107
108       /// CALL_TLS and CALL_NOP_TLS - Versions of CALL and CALL_NOP used
109       /// to access TLS variables.
110       CALL_TLS, CALL_NOP_TLS,
111
112       /// CHAIN,FLAG = MTCTR(VAL, CHAIN[, INFLAG]) - Directly corresponds to a
113       /// MTCTR instruction.
114       MTCTR,
115
116       /// CHAIN,FLAG = BCTRL(CHAIN, INFLAG) - Directly corresponds to a
117       /// BCTRL instruction.
118       BCTRL,
119
120       /// Return with a flag operand, matched by 'blr'
121       RET_FLAG,
122
123       /// R32 = MFOCRF(CRREG, INFLAG) - Represents the MFOCRF instruction.
124       /// This copies the bits corresponding to the specified CRREG into the
125       /// resultant GPR.  Bits corresponding to other CR regs are undefined.
126       MFOCRF,
127
128       // FIXME: Remove these once the ANDI glue bug is fixed:
129       /// i1 = ANDIo_1_[EQ|GT]_BIT(i32 or i64 x) - Represents the result of the
130       /// eq or gt bit of CR0 after executing andi. x, 1. This is used to
131       /// implement truncation of i32 or i64 to i1.
132       ANDIo_1_EQ_BIT, ANDIo_1_GT_BIT,
133
134       // READ_TIME_BASE - A read of the 64-bit time-base register on a 32-bit
135       // target (returns (Lo, Hi)). It takes a chain operand.
136       READ_TIME_BASE,
137
138       // EH_SJLJ_SETJMP - SjLj exception handling setjmp.
139       EH_SJLJ_SETJMP,
140
141       // EH_SJLJ_LONGJMP - SjLj exception handling longjmp.
142       EH_SJLJ_LONGJMP,
143
144       /// RESVEC = VCMP(LHS, RHS, OPC) - Represents one of the altivec VCMP*
145       /// instructions.  For lack of better number, we use the opcode number
146       /// encoding for the OPC field to identify the compare.  For example, 838
147       /// is VCMPGTSH.
148       VCMP,
149
150       /// RESVEC, OUTFLAG = VCMPo(LHS, RHS, OPC) - Represents one of the
151       /// altivec VCMP*o instructions.  For lack of better number, we use the
152       /// opcode number encoding for the OPC field to identify the compare.  For
153       /// example, 838 is VCMPGTSH.
154       VCMPo,
155
156       /// CHAIN = COND_BRANCH CHAIN, CRRC, OPC, DESTBB [, INFLAG] - This
157       /// corresponds to the COND_BRANCH pseudo instruction.  CRRC is the
158       /// condition register to branch on, OPC is the branch opcode to use (e.g.
159       /// PPC::BLE), DESTBB is the destination block to branch to, and INFLAG is
160       /// an optional input flag argument.
161       COND_BRANCH,
162
163       /// CHAIN = BDNZ CHAIN, DESTBB - These are used to create counter-based
164       /// loops.
165       BDNZ, BDZ,
166
167       /// F8RC = FADDRTZ F8RC, F8RC - This is an FADD done with rounding
168       /// towards zero.  Used only as part of the long double-to-int
169       /// conversion sequence.
170       FADDRTZ,
171
172       /// F8RC = MFFS - This moves the FPSCR (not modeled) into the register.
173       MFFS,
174
175       /// LARX = This corresponds to PPC l{w|d}arx instrcution: load and
176       /// reserve indexed. This is used to implement atomic operations.
177       LARX,
178
179       /// STCX = This corresponds to PPC stcx. instrcution: store conditional
180       /// indexed. This is used to implement atomic operations.
181       STCX,
182
183       /// TC_RETURN - A tail call return.
184       ///   operand #0 chain
185       ///   operand #1 callee (register or absolute)
186       ///   operand #2 stack adjustment
187       ///   operand #3 optional in flag
188       TC_RETURN,
189
190       /// ch, gl = CR6[UN]SET ch, inglue - Toggle CR bit 6 for SVR4 vararg calls
191       CR6SET,
192       CR6UNSET,
193
194       /// GPRC = address of _GLOBAL_OFFSET_TABLE_. Used by initial-exec TLS
195       /// on PPC32.
196       PPC32_GOT,
197
198       /// GPRC = address of _GLOBAL_OFFSET_TABLE_. Used by general dynamic and
199       /// local dynamic TLS  on PPC32.
200       PPC32_PICGOT,
201
202       /// G8RC = ADDIS_GOT_TPREL_HA %X2, Symbol - Used by the initial-exec
203       /// TLS model, produces an ADDIS8 instruction that adds the GOT
204       /// base to sym\@got\@tprel\@ha.
205       ADDIS_GOT_TPREL_HA,
206
207       /// G8RC = LD_GOT_TPREL_L Symbol, G8RReg - Used by the initial-exec
208       /// TLS model, produces a LD instruction with base register G8RReg
209       /// and offset sym\@got\@tprel\@l.  This completes the addition that
210       /// finds the offset of "sym" relative to the thread pointer.
211       LD_GOT_TPREL_L,
212
213       /// G8RC = ADD_TLS G8RReg, Symbol - Used by the initial-exec TLS
214       /// model, produces an ADD instruction that adds the contents of
215       /// G8RReg to the thread pointer.  Symbol contains a relocation
216       /// sym\@tls which is to be replaced by the thread pointer and
217       /// identifies to the linker that the instruction is part of a
218       /// TLS sequence.
219       ADD_TLS,
220
221       /// G8RC = ADDIS_TLSGD_HA %X2, Symbol - For the general-dynamic TLS
222       /// model, produces an ADDIS8 instruction that adds the GOT base
223       /// register to sym\@got\@tlsgd\@ha.
224       ADDIS_TLSGD_HA,
225
226       /// G8RC = ADDI_TLSGD_L G8RReg, Symbol - For the general-dynamic TLS
227       /// model, produces an ADDI8 instruction that adds G8RReg to
228       /// sym\@got\@tlsgd\@l.
229       ADDI_TLSGD_L,
230
231       /// G8RC = ADDIS_TLSLD_HA %X2, Symbol - For the local-dynamic TLS
232       /// model, produces an ADDIS8 instruction that adds the GOT base
233       /// register to sym\@got\@tlsld\@ha.
234       ADDIS_TLSLD_HA,
235
236       /// G8RC = ADDI_TLSLD_L G8RReg, Symbol - For the local-dynamic TLS
237       /// model, produces an ADDI8 instruction that adds G8RReg to
238       /// sym\@got\@tlsld\@l.
239       ADDI_TLSLD_L,
240
241       /// G8RC = ADDIS_DTPREL_HA %X3, Symbol, Chain - For the
242       /// local-dynamic TLS model, produces an ADDIS8 instruction
243       /// that adds X3 to sym\@dtprel\@ha. The Chain operand is needed
244       /// to tie this in place following a copy to %X3 from the result
245       /// of a GET_TLSLD_ADDR.
246       ADDIS_DTPREL_HA,
247
248       /// G8RC = ADDI_DTPREL_L G8RReg, Symbol - For the local-dynamic TLS
249       /// model, produces an ADDI8 instruction that adds G8RReg to
250       /// sym\@got\@dtprel\@l.
251       ADDI_DTPREL_L,
252
253       /// VRRC = VADD_SPLAT Elt, EltSize - Temporary node to be expanded
254       /// during instruction selection to optimize a BUILD_VECTOR into
255       /// operations on splats.  This is necessary to avoid losing these
256       /// optimizations due to constant folding.
257       VADD_SPLAT,
258
259       /// CHAIN = SC CHAIN, Imm128 - System call.  The 7-bit unsigned
260       /// operand identifies the operating system entry point.
261       SC,
262
263       /// VSRC, CHAIN = XXSWAPD CHAIN, VSRC - Occurs only for little
264       /// endian.  Maps to an xxswapd instruction that corrects an lxvd2x
265       /// or stxvd2x instruction.  The chain is necessary because the
266       /// sequence replaces a load and needs to provide the same number
267       /// of outputs.
268       XXSWAPD,
269
270       /// CHAIN = STBRX CHAIN, GPRC, Ptr, Type - This is a
271       /// byte-swapping store instruction.  It byte-swaps the low "Type" bits of
272       /// the GPRC input, then stores it through Ptr.  Type can be either i16 or
273       /// i32.
274       STBRX = ISD::FIRST_TARGET_MEMORY_OPCODE,
275
276       /// GPRC, CHAIN = LBRX CHAIN, Ptr, Type - This is a
277       /// byte-swapping load instruction.  It loads "Type" bits, byte swaps it,
278       /// then puts it in the bottom bits of the GPRC.  TYPE can be either i16
279       /// or i32.
280       LBRX,
281
282       /// STFIWX - The STFIWX instruction.  The first operand is an input token
283       /// chain, then an f64 value to store, then an address to store it to.
284       STFIWX,
285
286       /// GPRC, CHAIN = LFIWAX CHAIN, Ptr - This is a floating-point
287       /// load which sign-extends from a 32-bit integer value into the
288       /// destination 64-bit register.
289       LFIWAX,
290
291       /// GPRC, CHAIN = LFIWZX CHAIN, Ptr - This is a floating-point
292       /// load which zero-extends from a 32-bit integer value into the
293       /// destination 64-bit register.
294       LFIWZX,
295
296       /// G8RC = ADDIS_TOC_HA %X2, Symbol - For medium and large code model,
297       /// produces an ADDIS8 instruction that adds the TOC base register to
298       /// sym\@toc\@ha.
299       ADDIS_TOC_HA,
300
301       /// G8RC = LD_TOC_L Symbol, G8RReg - For medium and large code model,
302       /// produces a LD instruction with base register G8RReg and offset
303       /// sym\@toc\@l. Preceded by an ADDIS_TOC_HA to form a full 32-bit offset.
304       LD_TOC_L,
305
306       /// G8RC = ADDI_TOC_L G8RReg, Symbol - For medium code model, produces
307       /// an ADDI8 instruction that adds G8RReg to sym\@toc\@l.
308       /// Preceded by an ADDIS_TOC_HA to form a full 32-bit offset.
309       ADDI_TOC_L,
310
311       /// VSRC, CHAIN = LXVD2X_LE CHAIN, Ptr - Occurs only for little endian.
312       /// Maps directly to an lxvd2x instruction that will be followed by
313       /// an xxswapd.
314       LXVD2X,
315
316       /// CHAIN = STXVD2X CHAIN, VSRC, Ptr - Occurs only for little endian.
317       /// Maps directly to an stxvd2x instruction that will be preceded by
318       /// an xxswapd.
319       STXVD2X
320     };
321   }
322
323   /// Define some predicates that are used for node matching.
324   namespace PPC {
325     /// isVPKUHUMShuffleMask - Return true if this is the shuffle mask for a
326     /// VPKUHUM instruction.
327     bool isVPKUHUMShuffleMask(ShuffleVectorSDNode *N, unsigned ShuffleKind,
328                               SelectionDAG &DAG);
329
330     /// isVPKUWUMShuffleMask - Return true if this is the shuffle mask for a
331     /// VPKUWUM instruction.
332     bool isVPKUWUMShuffleMask(ShuffleVectorSDNode *N, unsigned ShuffleKind,
333                               SelectionDAG &DAG);
334
335     /// isVMRGLShuffleMask - Return true if this is a shuffle mask suitable for
336     /// a VRGL* instruction with the specified unit size (1,2 or 4 bytes).
337     bool isVMRGLShuffleMask(ShuffleVectorSDNode *N, unsigned UnitSize,
338                             unsigned ShuffleKind, SelectionDAG &DAG);
339
340     /// isVMRGHShuffleMask - Return true if this is a shuffle mask suitable for
341     /// a VRGH* instruction with the specified unit size (1,2 or 4 bytes).
342     bool isVMRGHShuffleMask(ShuffleVectorSDNode *N, unsigned UnitSize,
343                             unsigned ShuffleKind, SelectionDAG &DAG);
344
345     /// isVSLDOIShuffleMask - If this is a vsldoi shuffle mask, return the
346     /// shift amount, otherwise return -1.
347     int isVSLDOIShuffleMask(SDNode *N, unsigned ShuffleKind,
348                             SelectionDAG &DAG);
349
350     /// isSplatShuffleMask - Return true if the specified VECTOR_SHUFFLE operand
351     /// specifies a splat of a single element that is suitable for input to
352     /// VSPLTB/VSPLTH/VSPLTW.
353     bool isSplatShuffleMask(ShuffleVectorSDNode *N, unsigned EltSize);
354
355     /// isAllNegativeZeroVector - Returns true if all elements of build_vector
356     /// are -0.0.
357     bool isAllNegativeZeroVector(SDNode *N);
358
359     /// getVSPLTImmediate - Return the appropriate VSPLT* immediate to splat the
360     /// specified isSplatShuffleMask VECTOR_SHUFFLE mask.
361     unsigned getVSPLTImmediate(SDNode *N, unsigned EltSize, SelectionDAG &DAG);
362
363     /// get_VSPLTI_elt - If this is a build_vector of constants which can be
364     /// formed by using a vspltis[bhw] instruction of the specified element
365     /// size, return the constant being splatted.  The ByteSize field indicates
366     /// the number of bytes of each element [124] -> [bhw].
367     SDValue get_VSPLTI_elt(SDNode *N, unsigned ByteSize, SelectionDAG &DAG);
368   }
369
370   class PPCSubtarget;
371   class PPCTargetLowering : public TargetLowering {
372     const PPCSubtarget &Subtarget;
373
374   public:
375     explicit PPCTargetLowering(const PPCTargetMachine &TM);
376
377     /// getTargetNodeName() - This method returns the name of a target specific
378     /// DAG node.
379     const char *getTargetNodeName(unsigned Opcode) const override;
380
381     MVT getScalarShiftAmountTy(EVT LHSTy) const override { return MVT::i32; }
382
383     /// getSetCCResultType - Return the ISD::SETCC ValueType
384     EVT getSetCCResultType(LLVMContext &Context, EVT VT) const override;
385
386     /// Return true if target always beneficiates from combining into FMA for a
387     /// given value type. This must typically return false on targets where FMA
388     /// takes more cycles to execute than FADD.
389     bool enableAggressiveFMAFusion(EVT VT) const override;
390
391     /// getPreIndexedAddressParts - returns true by value, base pointer and
392     /// offset pointer and addressing mode by reference if the node's address
393     /// can be legally represented as pre-indexed load / store address.
394     bool getPreIndexedAddressParts(SDNode *N, SDValue &Base,
395                                    SDValue &Offset,
396                                    ISD::MemIndexedMode &AM,
397                                    SelectionDAG &DAG) const override;
398
399     /// SelectAddressRegReg - Given the specified addressed, check to see if it
400     /// can be represented as an indexed [r+r] operation.  Returns false if it
401     /// can be more efficiently represented with [r+imm].
402     bool SelectAddressRegReg(SDValue N, SDValue &Base, SDValue &Index,
403                              SelectionDAG &DAG) const;
404
405     /// SelectAddressRegImm - Returns true if the address N can be represented
406     /// by a base register plus a signed 16-bit displacement [r+imm], and if it
407     /// is not better represented as reg+reg.  If Aligned is true, only accept
408     /// displacements suitable for STD and friends, i.e. multiples of 4.
409     bool SelectAddressRegImm(SDValue N, SDValue &Disp, SDValue &Base,
410                              SelectionDAG &DAG, bool Aligned) const;
411
412     /// SelectAddressRegRegOnly - Given the specified addressed, force it to be
413     /// represented as an indexed [r+r] operation.
414     bool SelectAddressRegRegOnly(SDValue N, SDValue &Base, SDValue &Index,
415                                  SelectionDAG &DAG) const;
416
417     Sched::Preference getSchedulingPreference(SDNode *N) const override;
418
419     /// LowerOperation - Provide custom lowering hooks for some operations.
420     ///
421     SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
422
423     /// ReplaceNodeResults - Replace the results of node with an illegal result
424     /// type with new values built out of custom code.
425     ///
426     void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue>&Results,
427                             SelectionDAG &DAG) const override;
428
429     SDValue expandVSXLoadForLE(SDNode *N, DAGCombinerInfo &DCI) const;
430     SDValue expandVSXStoreForLE(SDNode *N, DAGCombinerInfo &DCI) const;
431
432     SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override;
433
434     SDValue BuildSDIVPow2(SDNode *N, const APInt &Divisor, SelectionDAG &DAG,
435                           std::vector<SDNode *> *Created) const override;
436
437     unsigned getRegisterByName(const char* RegName, EVT VT) const override;
438
439     void computeKnownBitsForTargetNode(const SDValue Op,
440                                        APInt &KnownZero,
441                                        APInt &KnownOne,
442                                        const SelectionDAG &DAG,
443                                        unsigned Depth = 0) const override;
444
445     Instruction* emitLeadingFence(IRBuilder<> &Builder, AtomicOrdering Ord,
446                                   bool IsStore, bool IsLoad) const override;
447     Instruction* emitTrailingFence(IRBuilder<> &Builder, AtomicOrdering Ord,
448                                    bool IsStore, bool IsLoad) const override;
449
450     MachineBasicBlock *
451       EmitInstrWithCustomInserter(MachineInstr *MI,
452                                   MachineBasicBlock *MBB) const override;
453     MachineBasicBlock *EmitAtomicBinary(MachineInstr *MI,
454                                         MachineBasicBlock *MBB, bool is64Bit,
455                                         unsigned BinOpcode) const;
456     MachineBasicBlock *EmitPartwordAtomicBinary(MachineInstr *MI,
457                                                 MachineBasicBlock *MBB,
458                                             bool is8bit, unsigned Opcode) const;
459
460     MachineBasicBlock *emitEHSjLjSetJmp(MachineInstr *MI,
461                                         MachineBasicBlock *MBB) const;
462
463     MachineBasicBlock *emitEHSjLjLongJmp(MachineInstr *MI,
464                                          MachineBasicBlock *MBB) const;
465
466     ConstraintType
467     getConstraintType(const std::string &Constraint) const override;
468
469     /// Examine constraint string and operand type and determine a weight value.
470     /// The operand object must already have been set up with the operand type.
471     ConstraintWeight getSingleConstraintMatchWeight(
472       AsmOperandInfo &info, const char *constraint) const override;
473
474     std::pair<unsigned, const TargetRegisterClass*>
475       getRegForInlineAsmConstraint(const std::string &Constraint,
476                                    MVT VT) const override;
477
478     /// getByValTypeAlignment - Return the desired alignment for ByVal aggregate
479     /// function arguments in the caller parameter area.  This is the actual
480     /// alignment, not its logarithm.
481     unsigned getByValTypeAlignment(Type *Ty) const override;
482
483     /// LowerAsmOperandForConstraint - Lower the specified operand into the Ops
484     /// vector.  If it is invalid, don't add anything to Ops.
485     void LowerAsmOperandForConstraint(SDValue Op,
486                                       std::string &Constraint,
487                                       std::vector<SDValue> &Ops,
488                                       SelectionDAG &DAG) const override;
489
490     /// isLegalAddressingMode - Return true if the addressing mode represented
491     /// by AM is legal for this target, for a load/store of the specified type.
492     bool isLegalAddressingMode(const AddrMode &AM, Type *Ty) const override;
493
494     /// isLegalICmpImmediate - Return true if the specified immediate is legal
495     /// icmp immediate, that is the target has icmp instructions which can
496     /// compare a register against the immediate without having to materialize
497     /// the immediate into a register.
498     bool isLegalICmpImmediate(int64_t Imm) const override;
499
500     /// isLegalAddImmediate - Return true if the specified immediate is legal
501     /// add immediate, that is the target has add instructions which can
502     /// add a register and the immediate without having to materialize
503     /// the immediate into a register.
504     bool isLegalAddImmediate(int64_t Imm) const override;
505
506     /// isTruncateFree - Return true if it's free to truncate a value of
507     /// type Ty1 to type Ty2. e.g. On PPC it's free to truncate a i64 value in
508     /// register X1 to i32 by referencing its sub-register R1.
509     bool isTruncateFree(Type *Ty1, Type *Ty2) const override;
510     bool isTruncateFree(EVT VT1, EVT VT2) const override;
511
512     /// \brief Returns true if it is beneficial to convert a load of a constant
513     /// to just the constant itself.
514     bool shouldConvertConstantLoadToIntImm(const APInt &Imm,
515                                            Type *Ty) const override;
516
517     bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override;
518
519     bool getTgtMemIntrinsic(IntrinsicInfo &Info,
520                             const CallInst &I,
521                             unsigned Intrinsic) const override;
522
523     /// getOptimalMemOpType - Returns the target specific optimal type for load
524     /// and store operations as a result of memset, memcpy, and memmove
525     /// lowering. If DstAlign is zero that means it's safe to destination
526     /// alignment can satisfy any constraint. Similarly if SrcAlign is zero it
527     /// means there isn't a need to check it against alignment requirement,
528     /// probably because the source does not need to be loaded. If 'IsMemset' is
529     /// true, that means it's expanding a memset. If 'ZeroMemset' is true, that
530     /// means it's a memset of zero. 'MemcpyStrSrc' indicates whether the memcpy
531     /// source is constant so it does not need to be loaded.
532     /// It returns EVT::Other if the type should be determined using generic
533     /// target-independent logic.
534     EVT
535     getOptimalMemOpType(uint64_t Size, unsigned DstAlign, unsigned SrcAlign,
536                         bool IsMemset, bool ZeroMemset, bool MemcpyStrSrc,
537                         MachineFunction &MF) const override;
538
539     /// Is unaligned memory access allowed for the given type, and is it fast
540     /// relative to software emulation.
541     bool allowsMisalignedMemoryAccesses(EVT VT,
542                                         unsigned AddrSpace,
543                                         unsigned Align = 1,
544                                         bool *Fast = nullptr) const override;
545
546     /// isFMAFasterThanFMulAndFAdd - Return true if an FMA operation is faster
547     /// than a pair of fmul and fadd instructions. fmuladd intrinsics will be
548     /// expanded to FMAs when this method returns true, otherwise fmuladd is
549     /// expanded to fmul + fadd.
550     bool isFMAFasterThanFMulAndFAdd(EVT VT) const override;
551
552     // Should we expand the build vector with shuffles?
553     bool
554     shouldExpandBuildVectorWithShuffles(EVT VT,
555                                         unsigned DefinedValues) const override;
556
557     /// createFastISel - This method returns a target-specific FastISel object,
558     /// or null if the target does not support "fast" instruction selection.
559     FastISel *createFastISel(FunctionLoweringInfo &FuncInfo,
560                              const TargetLibraryInfo *LibInfo) const override;
561
562     /// \brief Returns true if an argument of type Ty needs to be passed in a
563     /// contiguous block of registers in calling convention CallConv.
564     bool functionArgumentNeedsConsecutiveRegisters(
565       Type *Ty, CallingConv::ID CallConv, bool isVarArg) const override {
566       // We support any array type as "consecutive" block in the parameter
567       // save area.  The element type defines the alignment requirement and
568       // whether the argument should go in GPRs, FPRs, or VRs if available.
569       //
570       // Note that clang uses this capability both to implement the ELFv2
571       // homogeneous float/vector aggregate ABI, and to avoid having to use
572       // "byval" when passing aggregates that might fully fit in registers.
573       return Ty->isArrayTy();
574     }
575
576   private:
577     SDValue getFramePointerFrameIndex(SelectionDAG & DAG) const;
578     SDValue getReturnAddrFrameIndex(SelectionDAG & DAG) const;
579
580     bool
581     IsEligibleForTailCallOptimization(SDValue Callee,
582                                       CallingConv::ID CalleeCC,
583                                       bool isVarArg,
584                                       const SmallVectorImpl<ISD::InputArg> &Ins,
585                                       SelectionDAG& DAG) const;
586
587     SDValue EmitTailCallLoadFPAndRetAddr(SelectionDAG & DAG,
588                                          int SPDiff,
589                                          SDValue Chain,
590                                          SDValue &LROpOut,
591                                          SDValue &FPOpOut,
592                                          bool isDarwinABI,
593                                          SDLoc dl) const;
594
595     SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
596     SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
597     SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const;
598     SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;
599     std::pair<SDValue,SDValue> lowerTLSCall(SDValue Op, SDLoc dl,
600                                             SelectionDAG &DAG) const;
601     SDValue LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const;
602     SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;
603     SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) const;
604     SDValue LowerSETCC(SDValue Op, SelectionDAG &DAG) const;
605     SDValue LowerINIT_TRAMPOLINE(SDValue Op, SelectionDAG &DAG) const;
606     SDValue LowerADJUST_TRAMPOLINE(SDValue Op, SelectionDAG &DAG) const;
607     SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG,
608                          const PPCSubtarget &Subtarget) const;
609     SDValue LowerVAARG(SDValue Op, SelectionDAG &DAG,
610                        const PPCSubtarget &Subtarget) const;
611     SDValue LowerVACOPY(SDValue Op, SelectionDAG &DAG,
612                         const PPCSubtarget &Subtarget) const;
613     SDValue LowerSTACKRESTORE(SDValue Op, SelectionDAG &DAG,
614                                 const PPCSubtarget &Subtarget) const;
615     SDValue LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG,
616                                       const PPCSubtarget &Subtarget) const;
617     SDValue LowerLOAD(SDValue Op, SelectionDAG &DAG) const;
618     SDValue LowerSTORE(SDValue Op, SelectionDAG &DAG) const;
619     SDValue LowerTRUNCATE(SDValue Op, SelectionDAG &DAG) const;
620     SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const;
621     SDValue LowerFP_TO_INT(SDValue Op, SelectionDAG &DAG, SDLoc dl) const;
622     SDValue LowerINT_TO_FP(SDValue Op, SelectionDAG &DAG) const;
623     SDValue LowerFLT_ROUNDS_(SDValue Op, SelectionDAG &DAG) const;
624     SDValue LowerSHL_PARTS(SDValue Op, SelectionDAG &DAG) const;
625     SDValue LowerSRL_PARTS(SDValue Op, SelectionDAG &DAG) const;
626     SDValue LowerSRA_PARTS(SDValue Op, SelectionDAG &DAG) const;
627     SDValue LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG) const;
628     SDValue LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) const;
629     SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const;
630     SDValue LowerSCALAR_TO_VECTOR(SDValue Op, SelectionDAG &DAG) const;
631     SDValue LowerSIGN_EXTEND_INREG(SDValue Op, SelectionDAG &DAG) const;
632     SDValue LowerMUL(SDValue Op, SelectionDAG &DAG) const;
633
634     SDValue LowerCallResult(SDValue Chain, SDValue InFlag,
635                             CallingConv::ID CallConv, bool isVarArg,
636                             const SmallVectorImpl<ISD::InputArg> &Ins,
637                             SDLoc dl, SelectionDAG &DAG,
638                             SmallVectorImpl<SDValue> &InVals) const;
639     SDValue FinishCall(CallingConv::ID CallConv, SDLoc dl, bool isTailCall,
640                        bool isVarArg,
641                        SelectionDAG &DAG,
642                        SmallVector<std::pair<unsigned, SDValue>, 8>
643                          &RegsToPass,
644                        SDValue InFlag, SDValue Chain,
645                        SDValue &Callee,
646                        int SPDiff, unsigned NumBytes,
647                        const SmallVectorImpl<ISD::InputArg> &Ins,
648                        SmallVectorImpl<SDValue> &InVals) const;
649
650     SDValue
651       LowerFormalArguments(SDValue Chain,
652                            CallingConv::ID CallConv, bool isVarArg,
653                            const SmallVectorImpl<ISD::InputArg> &Ins,
654                            SDLoc dl, SelectionDAG &DAG,
655                            SmallVectorImpl<SDValue> &InVals) const override;
656
657     SDValue
658       LowerCall(TargetLowering::CallLoweringInfo &CLI,
659                 SmallVectorImpl<SDValue> &InVals) const override;
660
661     bool
662       CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF,
663                    bool isVarArg,
664                    const SmallVectorImpl<ISD::OutputArg> &Outs,
665                    LLVMContext &Context) const override;
666
667     SDValue
668       LowerReturn(SDValue Chain,
669                   CallingConv::ID CallConv, bool isVarArg,
670                   const SmallVectorImpl<ISD::OutputArg> &Outs,
671                   const SmallVectorImpl<SDValue> &OutVals,
672                   SDLoc dl, SelectionDAG &DAG) const override;
673
674     SDValue
675       extendArgForPPC64(ISD::ArgFlagsTy Flags, EVT ObjectVT, SelectionDAG &DAG,
676                         SDValue ArgVal, SDLoc dl) const;
677
678     SDValue
679       LowerFormalArguments_Darwin(SDValue Chain,
680                                   CallingConv::ID CallConv, bool isVarArg,
681                                   const SmallVectorImpl<ISD::InputArg> &Ins,
682                                   SDLoc dl, SelectionDAG &DAG,
683                                   SmallVectorImpl<SDValue> &InVals) const;
684     SDValue
685       LowerFormalArguments_64SVR4(SDValue Chain,
686                                   CallingConv::ID CallConv, bool isVarArg,
687                                   const SmallVectorImpl<ISD::InputArg> &Ins,
688                                   SDLoc dl, SelectionDAG &DAG,
689                                   SmallVectorImpl<SDValue> &InVals) const;
690     SDValue
691       LowerFormalArguments_32SVR4(SDValue Chain,
692                                   CallingConv::ID CallConv, bool isVarArg,
693                                   const SmallVectorImpl<ISD::InputArg> &Ins,
694                                   SDLoc dl, SelectionDAG &DAG,
695                                   SmallVectorImpl<SDValue> &InVals) const;
696
697     SDValue
698       createMemcpyOutsideCallSeq(SDValue Arg, SDValue PtrOff,
699                                  SDValue CallSeqStart, ISD::ArgFlagsTy Flags,
700                                  SelectionDAG &DAG, SDLoc dl) const;
701
702     SDValue
703       LowerCall_Darwin(SDValue Chain, SDValue Callee,
704                        CallingConv::ID CallConv,
705                        bool isVarArg, bool isTailCall,
706                        const SmallVectorImpl<ISD::OutputArg> &Outs,
707                        const SmallVectorImpl<SDValue> &OutVals,
708                        const SmallVectorImpl<ISD::InputArg> &Ins,
709                        SDLoc dl, SelectionDAG &DAG,
710                        SmallVectorImpl<SDValue> &InVals) const;
711     SDValue
712       LowerCall_64SVR4(SDValue Chain, SDValue Callee,
713                        CallingConv::ID CallConv,
714                        bool isVarArg, bool isTailCall,
715                        const SmallVectorImpl<ISD::OutputArg> &Outs,
716                        const SmallVectorImpl<SDValue> &OutVals,
717                        const SmallVectorImpl<ISD::InputArg> &Ins,
718                        SDLoc dl, SelectionDAG &DAG,
719                        SmallVectorImpl<SDValue> &InVals) const;
720     SDValue
721     LowerCall_32SVR4(SDValue Chain, SDValue Callee, CallingConv::ID CallConv,
722                      bool isVarArg, bool isTailCall,
723                      const SmallVectorImpl<ISD::OutputArg> &Outs,
724                      const SmallVectorImpl<SDValue> &OutVals,
725                      const SmallVectorImpl<ISD::InputArg> &Ins,
726                      SDLoc dl, SelectionDAG &DAG,
727                      SmallVectorImpl<SDValue> &InVals) const;
728
729     SDValue lowerEH_SJLJ_SETJMP(SDValue Op, SelectionDAG &DAG) const;
730     SDValue lowerEH_SJLJ_LONGJMP(SDValue Op, SelectionDAG &DAG) const;
731
732     SDValue DAGCombineExtBoolTrunc(SDNode *N, DAGCombinerInfo &DCI) const;
733     SDValue DAGCombineTruncBoolExt(SDNode *N, DAGCombinerInfo &DCI) const;
734
735     SDValue getRsqrtEstimate(SDValue Operand, DAGCombinerInfo &DCI,
736                              unsigned &RefinementSteps,
737                              bool &UseOneConstNR) const override;
738     SDValue getRecipEstimate(SDValue Operand, DAGCombinerInfo &DCI,
739                              unsigned &RefinementSteps) const override;
740     bool combineRepeatedFPDivisors(unsigned NumUsers) const override;
741
742     CCAssignFn *useFastISelCCs(unsigned Flag) const;
743   };
744
745   namespace PPC {
746     FastISel *createFastISel(FunctionLoweringInfo &FuncInfo,
747                              const TargetLibraryInfo *LibInfo);
748   }
749
750   bool CC_PPC32_SVR4_Custom_Dummy(unsigned &ValNo, MVT &ValVT, MVT &LocVT,
751                                   CCValAssign::LocInfo &LocInfo,
752                                   ISD::ArgFlagsTy &ArgFlags,
753                                   CCState &State);
754
755   bool CC_PPC32_SVR4_Custom_AlignArgRegs(unsigned &ValNo, MVT &ValVT,
756                                          MVT &LocVT,
757                                          CCValAssign::LocInfo &LocInfo,
758                                          ISD::ArgFlagsTy &ArgFlags,
759                                          CCState &State);
760
761   bool CC_PPC32_SVR4_Custom_AlignFPArgRegs(unsigned &ValNo, MVT &ValVT,
762                                            MVT &LocVT,
763                                            CCValAssign::LocInfo &LocInfo,
764                                            ISD::ArgFlagsTy &ArgFlags,
765                                            CCState &State);
766 }
767
768 #endif   // LLVM_TARGET_POWERPC_PPC32ISELLOWERING_H