[PowerPC] Loosen ELFv1 PPC64 func descriptor loads for indirect calls
[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       /// 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       TOC_ENTRY,
75
76       /// The following two target-specific nodes are used for calls through
77       /// function pointers in the 64-bit SVR4 ABI.
78
79       /// OPRC, CHAIN = DYNALLOC(CHAIN, NEGSIZE, FRAME_INDEX)
80       /// This instruction is lowered in PPCRegisterInfo::eliminateFrameIndex to
81       /// compute an allocation on the stack.
82       DYNALLOC,
83
84       /// GlobalBaseReg - On Darwin, this node represents the result of the mflr
85       /// at function entry, used for PIC code.
86       GlobalBaseReg,
87
88       /// These nodes represent the 32-bit PPC shifts that operate on 6-bit
89       /// shift amounts.  These nodes are generated by the multi-precision shift
90       /// code.
91       SRL, SRA, SHL,
92
93       /// The combination of sra[wd]i and addze used to implemented signed
94       /// integer division by a power of 2. The first operand is the dividend,
95       /// and the second is the constant shift amount (representing the
96       /// divisor).
97       SRA_ADDZE,
98
99       /// CALL - A direct function call.
100       /// CALL_NOP is a call with the special NOP which follows 64-bit
101       /// SVR4 calls.
102       CALL, CALL_NOP,
103
104       /// CALL_TLS and CALL_NOP_TLS - Versions of CALL and CALL_NOP used
105       /// to access TLS variables.
106       CALL_TLS, CALL_NOP_TLS,
107
108       /// CHAIN,FLAG = MTCTR(VAL, CHAIN[, INFLAG]) - Directly corresponds to a
109       /// MTCTR instruction.
110       MTCTR,
111
112       /// CHAIN,FLAG = BCTRL(CHAIN, INFLAG) - Directly corresponds to a
113       /// BCTRL instruction.
114       BCTRL,
115
116       /// CHAIN,FLAG = BCTRL(CHAIN, ADDR, INFLAG) - The combination of a bctrl
117       /// instruction and the TOC reload required on SVR4 PPC64.
118       BCTRL_LOAD_TOC,
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     bool isCheapToSpeculateCttz() const override {
384       return true;
385     }
386
387     bool isCheapToSpeculateCtlz() const override {
388       return true;
389     }
390
391     /// getSetCCResultType - Return the ISD::SETCC ValueType
392     EVT getSetCCResultType(LLVMContext &Context, EVT VT) const override;
393
394     /// Return true if target always beneficiates from combining into FMA for a
395     /// given value type. This must typically return false on targets where FMA
396     /// takes more cycles to execute than FADD.
397     bool enableAggressiveFMAFusion(EVT VT) const override;
398
399     /// getPreIndexedAddressParts - returns true by value, base pointer and
400     /// offset pointer and addressing mode by reference if the node's address
401     /// can be legally represented as pre-indexed load / store address.
402     bool getPreIndexedAddressParts(SDNode *N, SDValue &Base,
403                                    SDValue &Offset,
404                                    ISD::MemIndexedMode &AM,
405                                    SelectionDAG &DAG) const override;
406
407     /// SelectAddressRegReg - Given the specified addressed, check to see if it
408     /// can be represented as an indexed [r+r] operation.  Returns false if it
409     /// can be more efficiently represented with [r+imm].
410     bool SelectAddressRegReg(SDValue N, SDValue &Base, SDValue &Index,
411                              SelectionDAG &DAG) const;
412
413     /// SelectAddressRegImm - Returns true if the address N can be represented
414     /// by a base register plus a signed 16-bit displacement [r+imm], and if it
415     /// is not better represented as reg+reg.  If Aligned is true, only accept
416     /// displacements suitable for STD and friends, i.e. multiples of 4.
417     bool SelectAddressRegImm(SDValue N, SDValue &Disp, SDValue &Base,
418                              SelectionDAG &DAG, bool Aligned) const;
419
420     /// SelectAddressRegRegOnly - Given the specified addressed, force it to be
421     /// represented as an indexed [r+r] operation.
422     bool SelectAddressRegRegOnly(SDValue N, SDValue &Base, SDValue &Index,
423                                  SelectionDAG &DAG) const;
424
425     Sched::Preference getSchedulingPreference(SDNode *N) const override;
426
427     /// LowerOperation - Provide custom lowering hooks for some operations.
428     ///
429     SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
430
431     /// ReplaceNodeResults - Replace the results of node with an illegal result
432     /// type with new values built out of custom code.
433     ///
434     void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue>&Results,
435                             SelectionDAG &DAG) const override;
436
437     SDValue expandVSXLoadForLE(SDNode *N, DAGCombinerInfo &DCI) const;
438     SDValue expandVSXStoreForLE(SDNode *N, DAGCombinerInfo &DCI) const;
439
440     SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override;
441
442     SDValue BuildSDIVPow2(SDNode *N, const APInt &Divisor, SelectionDAG &DAG,
443                           std::vector<SDNode *> *Created) const override;
444
445     unsigned getRegisterByName(const char* RegName, EVT VT) const override;
446
447     void computeKnownBitsForTargetNode(const SDValue Op,
448                                        APInt &KnownZero,
449                                        APInt &KnownOne,
450                                        const SelectionDAG &DAG,
451                                        unsigned Depth = 0) const override;
452
453     unsigned getPrefLoopAlignment(MachineLoop *ML) const override;
454
455     Instruction* emitLeadingFence(IRBuilder<> &Builder, AtomicOrdering Ord,
456                                   bool IsStore, bool IsLoad) const override;
457     Instruction* emitTrailingFence(IRBuilder<> &Builder, AtomicOrdering Ord,
458                                    bool IsStore, bool IsLoad) const override;
459
460     MachineBasicBlock *
461       EmitInstrWithCustomInserter(MachineInstr *MI,
462                                   MachineBasicBlock *MBB) const override;
463     MachineBasicBlock *EmitAtomicBinary(MachineInstr *MI,
464                                         MachineBasicBlock *MBB, bool is64Bit,
465                                         unsigned BinOpcode) const;
466     MachineBasicBlock *EmitPartwordAtomicBinary(MachineInstr *MI,
467                                                 MachineBasicBlock *MBB,
468                                             bool is8bit, unsigned Opcode) const;
469
470     MachineBasicBlock *emitEHSjLjSetJmp(MachineInstr *MI,
471                                         MachineBasicBlock *MBB) const;
472
473     MachineBasicBlock *emitEHSjLjLongJmp(MachineInstr *MI,
474                                          MachineBasicBlock *MBB) const;
475
476     ConstraintType
477     getConstraintType(const std::string &Constraint) const override;
478
479     /// Examine constraint string and operand type and determine a weight value.
480     /// The operand object must already have been set up with the operand type.
481     ConstraintWeight getSingleConstraintMatchWeight(
482       AsmOperandInfo &info, const char *constraint) const override;
483
484     std::pair<unsigned, const TargetRegisterClass*>
485       getRegForInlineAsmConstraint(const std::string &Constraint,
486                                    MVT VT) const override;
487
488     /// getByValTypeAlignment - Return the desired alignment for ByVal aggregate
489     /// function arguments in the caller parameter area.  This is the actual
490     /// alignment, not its logarithm.
491     unsigned getByValTypeAlignment(Type *Ty) const override;
492
493     /// LowerAsmOperandForConstraint - Lower the specified operand into the Ops
494     /// vector.  If it is invalid, don't add anything to Ops.
495     void LowerAsmOperandForConstraint(SDValue Op,
496                                       std::string &Constraint,
497                                       std::vector<SDValue> &Ops,
498                                       SelectionDAG &DAG) const override;
499
500     /// isLegalAddressingMode - Return true if the addressing mode represented
501     /// by AM is legal for this target, for a load/store of the specified type.
502     bool isLegalAddressingMode(const AddrMode &AM, Type *Ty) const override;
503
504     /// isLegalICmpImmediate - Return true if the specified immediate is legal
505     /// icmp immediate, that is the target has icmp instructions which can
506     /// compare a register against the immediate without having to materialize
507     /// the immediate into a register.
508     bool isLegalICmpImmediate(int64_t Imm) const override;
509
510     /// isLegalAddImmediate - Return true if the specified immediate is legal
511     /// add immediate, that is the target has add instructions which can
512     /// add a register and the immediate without having to materialize
513     /// the immediate into a register.
514     bool isLegalAddImmediate(int64_t Imm) const override;
515
516     /// isTruncateFree - Return true if it's free to truncate a value of
517     /// type Ty1 to type Ty2. e.g. On PPC it's free to truncate a i64 value in
518     /// register X1 to i32 by referencing its sub-register R1.
519     bool isTruncateFree(Type *Ty1, Type *Ty2) const override;
520     bool isTruncateFree(EVT VT1, EVT VT2) const override;
521
522     bool isZExtFree(SDValue Val, EVT VT2) const override;
523
524     bool isFPExtFree(EVT VT) const override;
525
526     /// \brief Returns true if it is beneficial to convert a load of a constant
527     /// to just the constant itself.
528     bool shouldConvertConstantLoadToIntImm(const APInt &Imm,
529                                            Type *Ty) const override;
530
531     bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override;
532
533     bool getTgtMemIntrinsic(IntrinsicInfo &Info,
534                             const CallInst &I,
535                             unsigned Intrinsic) const override;
536
537     /// getOptimalMemOpType - Returns the target specific optimal type for load
538     /// and store operations as a result of memset, memcpy, and memmove
539     /// lowering. If DstAlign is zero that means it's safe to destination
540     /// alignment can satisfy any constraint. Similarly if SrcAlign is zero it
541     /// means there isn't a need to check it against alignment requirement,
542     /// probably because the source does not need to be loaded. If 'IsMemset' is
543     /// true, that means it's expanding a memset. If 'ZeroMemset' is true, that
544     /// means it's a memset of zero. 'MemcpyStrSrc' indicates whether the memcpy
545     /// source is constant so it does not need to be loaded.
546     /// It returns EVT::Other if the type should be determined using generic
547     /// target-independent logic.
548     EVT
549     getOptimalMemOpType(uint64_t Size, unsigned DstAlign, unsigned SrcAlign,
550                         bool IsMemset, bool ZeroMemset, bool MemcpyStrSrc,
551                         MachineFunction &MF) const override;
552
553     /// Is unaligned memory access allowed for the given type, and is it fast
554     /// relative to software emulation.
555     bool allowsMisalignedMemoryAccesses(EVT VT,
556                                         unsigned AddrSpace,
557                                         unsigned Align = 1,
558                                         bool *Fast = nullptr) const override;
559
560     /// isFMAFasterThanFMulAndFAdd - Return true if an FMA operation is faster
561     /// than a pair of fmul and fadd instructions. fmuladd intrinsics will be
562     /// expanded to FMAs when this method returns true, otherwise fmuladd is
563     /// expanded to fmul + fadd.
564     bool isFMAFasterThanFMulAndFAdd(EVT VT) const override;
565
566     const MCPhysReg *getScratchRegisters(CallingConv::ID CC) const override;
567
568     // Should we expand the build vector with shuffles?
569     bool
570     shouldExpandBuildVectorWithShuffles(EVT VT,
571                                         unsigned DefinedValues) const override;
572
573     /// createFastISel - This method returns a target-specific FastISel object,
574     /// or null if the target does not support "fast" instruction selection.
575     FastISel *createFastISel(FunctionLoweringInfo &FuncInfo,
576                              const TargetLibraryInfo *LibInfo) const override;
577
578     /// \brief Returns true if an argument of type Ty needs to be passed in a
579     /// contiguous block of registers in calling convention CallConv.
580     bool functionArgumentNeedsConsecutiveRegisters(
581       Type *Ty, CallingConv::ID CallConv, bool isVarArg) const override {
582       // We support any array type as "consecutive" block in the parameter
583       // save area.  The element type defines the alignment requirement and
584       // whether the argument should go in GPRs, FPRs, or VRs if available.
585       //
586       // Note that clang uses this capability both to implement the ELFv2
587       // homogeneous float/vector aggregate ABI, and to avoid having to use
588       // "byval" when passing aggregates that might fully fit in registers.
589       return Ty->isArrayTy();
590     }
591
592   private:
593
594     struct ReuseLoadInfo {
595       SDValue Ptr;
596       SDValue Chain;
597       SDValue ResChain;
598       MachinePointerInfo MPI;
599       bool IsInvariant;
600       unsigned Alignment;
601       AAMDNodes AAInfo;
602       const MDNode *Ranges;
603
604       ReuseLoadInfo() : IsInvariant(false), Alignment(0), Ranges(nullptr) {}
605     };
606
607     bool canReuseLoadAddress(SDValue Op, EVT MemVT, ReuseLoadInfo &RLI,
608                              SelectionDAG &DAG,
609                              ISD::LoadExtType ET = ISD::NON_EXTLOAD) const;
610     void spliceIntoChain(SDValue ResChain, SDValue NewResChain,
611                          SelectionDAG &DAG) const;
612
613     void LowerFP_TO_INTForReuse(SDValue Op, ReuseLoadInfo &RLI,
614                                 SelectionDAG &DAG, SDLoc dl) const;
615
616     SDValue getFramePointerFrameIndex(SelectionDAG & DAG) const;
617     SDValue getReturnAddrFrameIndex(SelectionDAG & DAG) const;
618
619     bool
620     IsEligibleForTailCallOptimization(SDValue Callee,
621                                       CallingConv::ID CalleeCC,
622                                       bool isVarArg,
623                                       const SmallVectorImpl<ISD::InputArg> &Ins,
624                                       SelectionDAG& DAG) const;
625
626     SDValue EmitTailCallLoadFPAndRetAddr(SelectionDAG & DAG,
627                                          int SPDiff,
628                                          SDValue Chain,
629                                          SDValue &LROpOut,
630                                          SDValue &FPOpOut,
631                                          bool isDarwinABI,
632                                          SDLoc dl) const;
633
634     SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
635     SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
636     SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const;
637     SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;
638     std::pair<SDValue,SDValue> lowerTLSCall(SDValue Op, SDLoc dl,
639                                             SelectionDAG &DAG) const;
640     SDValue LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const;
641     SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;
642     SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) const;
643     SDValue LowerSETCC(SDValue Op, SelectionDAG &DAG) const;
644     SDValue LowerINIT_TRAMPOLINE(SDValue Op, SelectionDAG &DAG) const;
645     SDValue LowerADJUST_TRAMPOLINE(SDValue Op, SelectionDAG &DAG) const;
646     SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG,
647                          const PPCSubtarget &Subtarget) const;
648     SDValue LowerVAARG(SDValue Op, SelectionDAG &DAG,
649                        const PPCSubtarget &Subtarget) const;
650     SDValue LowerVACOPY(SDValue Op, SelectionDAG &DAG,
651                         const PPCSubtarget &Subtarget) const;
652     SDValue LowerSTACKRESTORE(SDValue Op, SelectionDAG &DAG,
653                                 const PPCSubtarget &Subtarget) const;
654     SDValue LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG,
655                                       const PPCSubtarget &Subtarget) const;
656     SDValue LowerLOAD(SDValue Op, SelectionDAG &DAG) const;
657     SDValue LowerSTORE(SDValue Op, SelectionDAG &DAG) const;
658     SDValue LowerTRUNCATE(SDValue Op, SelectionDAG &DAG) const;
659     SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const;
660     SDValue LowerFP_TO_INT(SDValue Op, SelectionDAG &DAG, SDLoc dl) const;
661     SDValue LowerINT_TO_FP(SDValue Op, SelectionDAG &DAG) const;
662     SDValue LowerFLT_ROUNDS_(SDValue Op, SelectionDAG &DAG) const;
663     SDValue LowerSHL_PARTS(SDValue Op, SelectionDAG &DAG) const;
664     SDValue LowerSRL_PARTS(SDValue Op, SelectionDAG &DAG) const;
665     SDValue LowerSRA_PARTS(SDValue Op, SelectionDAG &DAG) const;
666     SDValue LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG) const;
667     SDValue LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) const;
668     SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const;
669     SDValue LowerSCALAR_TO_VECTOR(SDValue Op, SelectionDAG &DAG) const;
670     SDValue LowerSIGN_EXTEND_INREG(SDValue Op, SelectionDAG &DAG) const;
671     SDValue LowerMUL(SDValue Op, SelectionDAG &DAG) const;
672
673     SDValue LowerCallResult(SDValue Chain, SDValue InFlag,
674                             CallingConv::ID CallConv, bool isVarArg,
675                             const SmallVectorImpl<ISD::InputArg> &Ins,
676                             SDLoc dl, SelectionDAG &DAG,
677                             SmallVectorImpl<SDValue> &InVals) const;
678     SDValue FinishCall(CallingConv::ID CallConv, SDLoc dl, bool isTailCall,
679                        bool isVarArg, bool IsPatchPoint,
680                        SelectionDAG &DAG,
681                        SmallVector<std::pair<unsigned, SDValue>, 8>
682                          &RegsToPass,
683                        SDValue InFlag, SDValue Chain, SDValue CallSeqStart,
684                        SDValue &Callee,
685                        int SPDiff, unsigned NumBytes,
686                        const SmallVectorImpl<ISD::InputArg> &Ins,
687                        SmallVectorImpl<SDValue> &InVals,
688                        ImmutableCallSite *CS) const;
689
690     SDValue
691       LowerFormalArguments(SDValue Chain,
692                            CallingConv::ID CallConv, bool isVarArg,
693                            const SmallVectorImpl<ISD::InputArg> &Ins,
694                            SDLoc dl, SelectionDAG &DAG,
695                            SmallVectorImpl<SDValue> &InVals) const override;
696
697     SDValue
698       LowerCall(TargetLowering::CallLoweringInfo &CLI,
699                 SmallVectorImpl<SDValue> &InVals) const override;
700
701     bool
702       CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF,
703                    bool isVarArg,
704                    const SmallVectorImpl<ISD::OutputArg> &Outs,
705                    LLVMContext &Context) const override;
706
707     SDValue
708       LowerReturn(SDValue Chain,
709                   CallingConv::ID CallConv, bool isVarArg,
710                   const SmallVectorImpl<ISD::OutputArg> &Outs,
711                   const SmallVectorImpl<SDValue> &OutVals,
712                   SDLoc dl, SelectionDAG &DAG) const override;
713
714     SDValue
715       extendArgForPPC64(ISD::ArgFlagsTy Flags, EVT ObjectVT, SelectionDAG &DAG,
716                         SDValue ArgVal, SDLoc dl) const;
717
718     SDValue
719       LowerFormalArguments_Darwin(SDValue Chain,
720                                   CallingConv::ID CallConv, bool isVarArg,
721                                   const SmallVectorImpl<ISD::InputArg> &Ins,
722                                   SDLoc dl, SelectionDAG &DAG,
723                                   SmallVectorImpl<SDValue> &InVals) const;
724     SDValue
725       LowerFormalArguments_64SVR4(SDValue Chain,
726                                   CallingConv::ID CallConv, bool isVarArg,
727                                   const SmallVectorImpl<ISD::InputArg> &Ins,
728                                   SDLoc dl, SelectionDAG &DAG,
729                                   SmallVectorImpl<SDValue> &InVals) const;
730     SDValue
731       LowerFormalArguments_32SVR4(SDValue Chain,
732                                   CallingConv::ID CallConv, bool isVarArg,
733                                   const SmallVectorImpl<ISD::InputArg> &Ins,
734                                   SDLoc dl, SelectionDAG &DAG,
735                                   SmallVectorImpl<SDValue> &InVals) const;
736
737     SDValue
738       createMemcpyOutsideCallSeq(SDValue Arg, SDValue PtrOff,
739                                  SDValue CallSeqStart, ISD::ArgFlagsTy Flags,
740                                  SelectionDAG &DAG, SDLoc dl) const;
741
742     SDValue
743       LowerCall_Darwin(SDValue Chain, SDValue Callee,
744                        CallingConv::ID CallConv,
745                        bool isVarArg, bool isTailCall, bool IsPatchPoint,
746                        const SmallVectorImpl<ISD::OutputArg> &Outs,
747                        const SmallVectorImpl<SDValue> &OutVals,
748                        const SmallVectorImpl<ISD::InputArg> &Ins,
749                        SDLoc dl, SelectionDAG &DAG,
750                        SmallVectorImpl<SDValue> &InVals,
751                        ImmutableCallSite *CS) const;
752     SDValue
753       LowerCall_64SVR4(SDValue Chain, SDValue Callee,
754                        CallingConv::ID CallConv,
755                        bool isVarArg, bool isTailCall, bool IsPatchPoint,
756                        const SmallVectorImpl<ISD::OutputArg> &Outs,
757                        const SmallVectorImpl<SDValue> &OutVals,
758                        const SmallVectorImpl<ISD::InputArg> &Ins,
759                        SDLoc dl, SelectionDAG &DAG,
760                        SmallVectorImpl<SDValue> &InVals,
761                        ImmutableCallSite *CS) const;
762     SDValue
763     LowerCall_32SVR4(SDValue Chain, SDValue Callee, CallingConv::ID CallConv,
764                      bool isVarArg, bool isTailCall, bool IsPatchPoint,
765                      const SmallVectorImpl<ISD::OutputArg> &Outs,
766                      const SmallVectorImpl<SDValue> &OutVals,
767                      const SmallVectorImpl<ISD::InputArg> &Ins,
768                      SDLoc dl, SelectionDAG &DAG,
769                      SmallVectorImpl<SDValue> &InVals,
770                      ImmutableCallSite *CS) const;
771
772     SDValue lowerEH_SJLJ_SETJMP(SDValue Op, SelectionDAG &DAG) const;
773     SDValue lowerEH_SJLJ_LONGJMP(SDValue Op, SelectionDAG &DAG) const;
774
775     SDValue DAGCombineExtBoolTrunc(SDNode *N, DAGCombinerInfo &DCI) const;
776     SDValue DAGCombineTruncBoolExt(SDNode *N, DAGCombinerInfo &DCI) const;
777     SDValue combineFPToIntToFP(SDNode *N, DAGCombinerInfo &DCI) const;
778
779     SDValue getRsqrtEstimate(SDValue Operand, DAGCombinerInfo &DCI,
780                              unsigned &RefinementSteps,
781                              bool &UseOneConstNR) const override;
782     SDValue getRecipEstimate(SDValue Operand, DAGCombinerInfo &DCI,
783                              unsigned &RefinementSteps) const override;
784     bool combineRepeatedFPDivisors(unsigned NumUsers) const override;
785
786     CCAssignFn *useFastISelCCs(unsigned Flag) const;
787   };
788
789   namespace PPC {
790     FastISel *createFastISel(FunctionLoweringInfo &FuncInfo,
791                              const TargetLibraryInfo *LibInfo);
792   }
793
794   bool CC_PPC32_SVR4_Custom_Dummy(unsigned &ValNo, MVT &ValVT, MVT &LocVT,
795                                   CCValAssign::LocInfo &LocInfo,
796                                   ISD::ArgFlagsTy &ArgFlags,
797                                   CCState &State);
798
799   bool CC_PPC32_SVR4_Custom_AlignArgRegs(unsigned &ValNo, MVT &ValVT,
800                                          MVT &LocVT,
801                                          CCValAssign::LocInfo &LocInfo,
802                                          ISD::ArgFlagsTy &ArgFlags,
803                                          CCState &State);
804
805   bool CC_PPC32_SVR4_Custom_AlignFPArgRegs(unsigned &ValNo, MVT &ValVT,
806                                            MVT &LocVT,
807                                            CCValAssign::LocInfo &LocInfo,
808                                            ISD::ArgFlagsTy &ArgFlags,
809                                            CCState &State);
810 }
811
812 #endif   // LLVM_TARGET_POWERPC_PPC32ISELLOWERING_H