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