1 //===-- PPCISelLowering.h - PPC32 DAG Lowering Interface --------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the interfaces that PPC uses to lower LLVM code into a
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_LIB_TARGET_POWERPC_PPCISELLOWERING_H
16 #define LLVM_LIB_TARGET_POWERPC_PPCISELLOWERING_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"
27 enum NodeType : unsigned {
28 // Start the numbering where the builtin ops and target ops leave off.
29 FIRST_NUMBER = ISD::BUILTIN_OP_END,
31 /// FSEL - Traditional three-operand fsel node.
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.
40 /// Newer FCFID[US] integer-to-floating-point conversion instructions for
41 /// unsigned integers and single-precision outputs.
42 FCFIDU, FCFIDS, FCFIDUS,
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
49 /// Newer FCTI[D,W]UZ floating-point-to-integer conversion instructions for
50 /// unsigned integers.
53 /// Reciprocal estimate instructions (unary FP ops).
56 // VMADDFP, VNMSUBFP - The VMADDFP and VNMSUBFP instructions, taking
57 // three v4f32 operands and producing a v4f32 result.
60 /// VPERM - The PPC VPERM Instruction.
64 /// The CMPB instruction (takes two operands of i32 or i64).
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.
74 /// The following two target-specific nodes are used for calls through
75 /// function pointers in the 64-bit SVR4 ABI.
77 /// OPRC, CHAIN = DYNALLOC(CHAIN, NEGSIZE, FRAME_INDEX)
78 /// This instruction is lowered in PPCRegisterInfo::eliminateFrameIndex to
79 /// compute an allocation on the stack.
82 /// GlobalBaseReg - On Darwin, this node represents the result of the mflr
83 /// at function entry, used for PIC code.
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
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
97 /// CALL - A direct function call.
98 /// CALL_NOP is a call with the special NOP which follows 64-bit
102 /// CHAIN,FLAG = MTCTR(VAL, CHAIN[, INFLAG]) - Directly corresponds to a
103 /// MTCTR instruction.
106 /// CHAIN,FLAG = BCTRL(CHAIN, INFLAG) - Directly corresponds to a
107 /// BCTRL instruction.
110 /// CHAIN,FLAG = BCTRL(CHAIN, ADDR, INFLAG) - The combination of a bctrl
111 /// instruction and the TOC reload required on SVR4 PPC64.
114 /// Return with a flag operand, matched by 'blr'
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.
122 /// Direct move from a VSX register to a GPR
125 /// Direct move from a GPR to a VSX register (algebraic)
128 /// Direct move from a GPR to a VSX register (zero)
131 // FIXME: Remove these once the ANDI glue bug is fixed:
132 /// i1 = ANDIo_1_[EQ|GT]_BIT(i32 or i64 x) - Represents the result of the
133 /// eq or gt bit of CR0 after executing andi. x, 1. This is used to
134 /// implement truncation of i32 or i64 to i1.
135 ANDIo_1_EQ_BIT, ANDIo_1_GT_BIT,
137 // READ_TIME_BASE - A read of the 64-bit time-base register on a 32-bit
138 // target (returns (Lo, Hi)). It takes a chain operand.
141 // EH_SJLJ_SETJMP - SjLj exception handling setjmp.
144 // EH_SJLJ_LONGJMP - SjLj exception handling longjmp.
147 /// RESVEC = VCMP(LHS, RHS, OPC) - Represents one of the altivec VCMP*
148 /// instructions. For lack of better number, we use the opcode number
149 /// encoding for the OPC field to identify the compare. For example, 838
153 /// RESVEC, OUTFLAG = VCMPo(LHS, RHS, OPC) - Represents one of the
154 /// altivec VCMP*o instructions. For lack of better number, we use the
155 /// opcode number encoding for the OPC field to identify the compare. For
156 /// example, 838 is VCMPGTSH.
159 /// CHAIN = COND_BRANCH CHAIN, CRRC, OPC, DESTBB [, INFLAG] - This
160 /// corresponds to the COND_BRANCH pseudo instruction. CRRC is the
161 /// condition register to branch on, OPC is the branch opcode to use (e.g.
162 /// PPC::BLE), DESTBB is the destination block to branch to, and INFLAG is
163 /// an optional input flag argument.
166 /// CHAIN = BDNZ CHAIN, DESTBB - These are used to create counter-based
170 /// F8RC = FADDRTZ F8RC, F8RC - This is an FADD done with rounding
171 /// towards zero. Used only as part of the long double-to-int
172 /// conversion sequence.
175 /// F8RC = MFFS - This moves the FPSCR (not modeled) into the register.
178 /// TC_RETURN - A tail call return.
180 /// operand #1 callee (register or absolute)
181 /// operand #2 stack adjustment
182 /// operand #3 optional in flag
185 /// ch, gl = CR6[UN]SET ch, inglue - Toggle CR bit 6 for SVR4 vararg calls
189 /// GPRC = address of _GLOBAL_OFFSET_TABLE_. Used by initial-exec TLS
193 /// GPRC = address of _GLOBAL_OFFSET_TABLE_. Used by general dynamic and
194 /// local dynamic TLS on PPC32.
197 /// G8RC = ADDIS_GOT_TPREL_HA %X2, Symbol - Used by the initial-exec
198 /// TLS model, produces an ADDIS8 instruction that adds the GOT
199 /// base to sym\@got\@tprel\@ha.
202 /// G8RC = LD_GOT_TPREL_L Symbol, G8RReg - Used by the initial-exec
203 /// TLS model, produces a LD instruction with base register G8RReg
204 /// and offset sym\@got\@tprel\@l. This completes the addition that
205 /// finds the offset of "sym" relative to the thread pointer.
208 /// G8RC = ADD_TLS G8RReg, Symbol - Used by the initial-exec TLS
209 /// model, produces an ADD instruction that adds the contents of
210 /// G8RReg to the thread pointer. Symbol contains a relocation
211 /// sym\@tls which is to be replaced by the thread pointer and
212 /// identifies to the linker that the instruction is part of a
216 /// G8RC = ADDIS_TLSGD_HA %X2, Symbol - For the general-dynamic TLS
217 /// model, produces an ADDIS8 instruction that adds the GOT base
218 /// register to sym\@got\@tlsgd\@ha.
221 /// %X3 = ADDI_TLSGD_L G8RReg, Symbol - For the general-dynamic TLS
222 /// model, produces an ADDI8 instruction that adds G8RReg to
223 /// sym\@got\@tlsgd\@l and stores the result in X3. Hidden by
224 /// ADDIS_TLSGD_L_ADDR until after register assignment.
227 /// %X3 = GET_TLS_ADDR %X3, Symbol - For the general-dynamic TLS
228 /// model, produces a call to __tls_get_addr(sym\@tlsgd). Hidden by
229 /// ADDIS_TLSGD_L_ADDR until after register assignment.
232 /// G8RC = ADDI_TLSGD_L_ADDR G8RReg, Symbol, Symbol - Op that
233 /// combines ADDI_TLSGD_L and GET_TLS_ADDR until expansion following
234 /// register assignment.
237 /// G8RC = ADDIS_TLSLD_HA %X2, Symbol - For the local-dynamic TLS
238 /// model, produces an ADDIS8 instruction that adds the GOT base
239 /// register to sym\@got\@tlsld\@ha.
242 /// %X3 = ADDI_TLSLD_L G8RReg, Symbol - For the local-dynamic TLS
243 /// model, produces an ADDI8 instruction that adds G8RReg to
244 /// sym\@got\@tlsld\@l and stores the result in X3. Hidden by
245 /// ADDIS_TLSLD_L_ADDR until after register assignment.
248 /// %X3 = GET_TLSLD_ADDR %X3, Symbol - For the local-dynamic TLS
249 /// model, produces a call to __tls_get_addr(sym\@tlsld). Hidden by
250 /// ADDIS_TLSLD_L_ADDR until after register assignment.
253 /// G8RC = ADDI_TLSLD_L_ADDR G8RReg, Symbol, Symbol - Op that
254 /// combines ADDI_TLSLD_L and GET_TLSLD_ADDR until expansion
255 /// following register assignment.
258 /// G8RC = ADDIS_DTPREL_HA %X3, Symbol - For the local-dynamic TLS
259 /// model, produces an ADDIS8 instruction that adds X3 to
263 /// G8RC = ADDI_DTPREL_L G8RReg, Symbol - For the local-dynamic TLS
264 /// model, produces an ADDI8 instruction that adds G8RReg to
265 /// sym\@got\@dtprel\@l.
268 /// VRRC = VADD_SPLAT Elt, EltSize - Temporary node to be expanded
269 /// during instruction selection to optimize a BUILD_VECTOR into
270 /// operations on splats. This is necessary to avoid losing these
271 /// optimizations due to constant folding.
274 /// CHAIN = SC CHAIN, Imm128 - System call. The 7-bit unsigned
275 /// operand identifies the operating system entry point.
278 /// CHAIN = CLRBHRB CHAIN - Clear branch history rolling buffer.
281 /// GPRC, CHAIN = MFBHRBE CHAIN, Entry, Dummy - Move from branch
282 /// history rolling buffer entry.
285 /// CHAIN = RFEBB CHAIN, State - Return from event-based branch.
288 /// VSRC, CHAIN = XXSWAPD CHAIN, VSRC - Occurs only for little
289 /// endian. Maps to an xxswapd instruction that corrects an lxvd2x
290 /// or stxvd2x instruction. The chain is necessary because the
291 /// sequence replaces a load and needs to provide the same number
295 /// QVFPERM = This corresponds to the QPX qvfperm instruction.
298 /// QVGPCI = This corresponds to the QPX qvgpci instruction.
301 /// QVALIGNI = This corresponds to the QPX qvaligni instruction.
304 /// QVESPLATI = This corresponds to the QPX qvesplati instruction.
307 /// QBFLT = Access the underlying QPX floating-point boolean
311 /// CHAIN = STBRX CHAIN, GPRC, Ptr, Type - This is a
312 /// byte-swapping store instruction. It byte-swaps the low "Type" bits of
313 /// the GPRC input, then stores it through Ptr. Type can be either i16 or
315 STBRX = ISD::FIRST_TARGET_MEMORY_OPCODE,
317 /// GPRC, CHAIN = LBRX CHAIN, Ptr, Type - This is a
318 /// byte-swapping load instruction. It loads "Type" bits, byte swaps it,
319 /// then puts it in the bottom bits of the GPRC. TYPE can be either i16
323 /// STFIWX - The STFIWX instruction. The first operand is an input token
324 /// chain, then an f64 value to store, then an address to store it to.
327 /// GPRC, CHAIN = LFIWAX CHAIN, Ptr - This is a floating-point
328 /// load which sign-extends from a 32-bit integer value into the
329 /// destination 64-bit register.
332 /// GPRC, CHAIN = LFIWZX CHAIN, Ptr - This is a floating-point
333 /// load which zero-extends from a 32-bit integer value into the
334 /// destination 64-bit register.
337 /// VSRC, CHAIN = LXVD2X_LE CHAIN, Ptr - Occurs only for little endian.
338 /// Maps directly to an lxvd2x instruction that will be followed by
342 /// CHAIN = STXVD2X CHAIN, VSRC, Ptr - Occurs only for little endian.
343 /// Maps directly to an stxvd2x instruction that will be preceded by
347 /// QBRC, CHAIN = QVLFSb CHAIN, Ptr
348 /// The 4xf32 load used for v4i1 constants.
351 /// GPRC = TOC_ENTRY GA, TOC
352 /// Loads the entry for GA from the TOC, where the TOC base is given by
353 /// the last operand.
358 /// Define some predicates that are used for node matching.
360 /// isVPKUHUMShuffleMask - Return true if this is the shuffle mask for a
361 /// VPKUHUM instruction.
362 bool isVPKUHUMShuffleMask(ShuffleVectorSDNode *N, unsigned ShuffleKind,
365 /// isVPKUWUMShuffleMask - Return true if this is the shuffle mask for a
366 /// VPKUWUM instruction.
367 bool isVPKUWUMShuffleMask(ShuffleVectorSDNode *N, unsigned ShuffleKind,
370 /// isVPKUDUMShuffleMask - Return true if this is the shuffle mask for a
371 /// VPKUDUM instruction.
372 bool isVPKUDUMShuffleMask(ShuffleVectorSDNode *N, unsigned ShuffleKind,
375 /// isVMRGLShuffleMask - Return true if this is a shuffle mask suitable for
376 /// a VRGL* instruction with the specified unit size (1,2 or 4 bytes).
377 bool isVMRGLShuffleMask(ShuffleVectorSDNode *N, unsigned UnitSize,
378 unsigned ShuffleKind, SelectionDAG &DAG);
380 /// isVMRGHShuffleMask - Return true if this is a shuffle mask suitable for
381 /// a VRGH* instruction with the specified unit size (1,2 or 4 bytes).
382 bool isVMRGHShuffleMask(ShuffleVectorSDNode *N, unsigned UnitSize,
383 unsigned ShuffleKind, SelectionDAG &DAG);
385 /// isVSLDOIShuffleMask - If this is a vsldoi shuffle mask, return the
386 /// shift amount, otherwise return -1.
387 int isVSLDOIShuffleMask(SDNode *N, unsigned ShuffleKind,
390 /// isSplatShuffleMask - Return true if the specified VECTOR_SHUFFLE operand
391 /// specifies a splat of a single element that is suitable for input to
392 /// VSPLTB/VSPLTH/VSPLTW.
393 bool isSplatShuffleMask(ShuffleVectorSDNode *N, unsigned EltSize);
395 /// getVSPLTImmediate - Return the appropriate VSPLT* immediate to splat the
396 /// specified isSplatShuffleMask VECTOR_SHUFFLE mask.
397 unsigned getVSPLTImmediate(SDNode *N, unsigned EltSize, SelectionDAG &DAG);
399 /// get_VSPLTI_elt - If this is a build_vector of constants which can be
400 /// formed by using a vspltis[bhw] instruction of the specified element
401 /// size, return the constant being splatted. The ByteSize field indicates
402 /// the number of bytes of each element [124] -> [bhw].
403 SDValue get_VSPLTI_elt(SDNode *N, unsigned ByteSize, SelectionDAG &DAG);
405 /// If this is a qvaligni shuffle mask, return the shift
406 /// amount, otherwise return -1.
407 int isQVALIGNIShuffleMask(SDNode *N);
410 class PPCTargetLowering : public TargetLowering {
411 const PPCSubtarget &Subtarget;
414 explicit PPCTargetLowering(const PPCTargetMachine &TM,
415 const PPCSubtarget &STI);
417 /// getTargetNodeName() - This method returns the name of a target specific
419 const char *getTargetNodeName(unsigned Opcode) const override;
421 MVT getScalarShiftAmountTy(EVT LHSTy) const override { return MVT::i32; }
423 bool isCheapToSpeculateCttz() const override {
427 bool isCheapToSpeculateCtlz() const override {
431 /// getSetCCResultType - Return the ISD::SETCC ValueType
432 EVT getSetCCResultType(LLVMContext &Context, EVT VT) const override;
434 /// Return true if target always beneficiates from combining into FMA for a
435 /// given value type. This must typically return false on targets where FMA
436 /// takes more cycles to execute than FADD.
437 bool enableAggressiveFMAFusion(EVT VT) const override;
439 /// getPreIndexedAddressParts - returns true by value, base pointer and
440 /// offset pointer and addressing mode by reference if the node's address
441 /// can be legally represented as pre-indexed load / store address.
442 bool getPreIndexedAddressParts(SDNode *N, SDValue &Base,
444 ISD::MemIndexedMode &AM,
445 SelectionDAG &DAG) const override;
447 /// SelectAddressRegReg - Given the specified addressed, check to see if it
448 /// can be represented as an indexed [r+r] operation. Returns false if it
449 /// can be more efficiently represented with [r+imm].
450 bool SelectAddressRegReg(SDValue N, SDValue &Base, SDValue &Index,
451 SelectionDAG &DAG) const;
453 /// SelectAddressRegImm - Returns true if the address N can be represented
454 /// by a base register plus a signed 16-bit displacement [r+imm], and if it
455 /// is not better represented as reg+reg. If Aligned is true, only accept
456 /// displacements suitable for STD and friends, i.e. multiples of 4.
457 bool SelectAddressRegImm(SDValue N, SDValue &Disp, SDValue &Base,
458 SelectionDAG &DAG, bool Aligned) const;
460 /// SelectAddressRegRegOnly - Given the specified addressed, force it to be
461 /// represented as an indexed [r+r] operation.
462 bool SelectAddressRegRegOnly(SDValue N, SDValue &Base, SDValue &Index,
463 SelectionDAG &DAG) const;
465 Sched::Preference getSchedulingPreference(SDNode *N) const override;
467 /// LowerOperation - Provide custom lowering hooks for some operations.
469 SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
471 /// ReplaceNodeResults - Replace the results of node with an illegal result
472 /// type with new values built out of custom code.
474 void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue>&Results,
475 SelectionDAG &DAG) const override;
477 SDValue expandVSXLoadForLE(SDNode *N, DAGCombinerInfo &DCI) const;
478 SDValue expandVSXStoreForLE(SDNode *N, DAGCombinerInfo &DCI) const;
480 SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override;
482 SDValue BuildSDIVPow2(SDNode *N, const APInt &Divisor, SelectionDAG &DAG,
483 std::vector<SDNode *> *Created) const override;
485 unsigned getRegisterByName(const char* RegName, EVT VT) const override;
487 void computeKnownBitsForTargetNode(const SDValue Op,
490 const SelectionDAG &DAG,
491 unsigned Depth = 0) const override;
493 unsigned getPrefLoopAlignment(MachineLoop *ML) const override;
495 Instruction* emitLeadingFence(IRBuilder<> &Builder, AtomicOrdering Ord,
496 bool IsStore, bool IsLoad) const override;
497 Instruction* emitTrailingFence(IRBuilder<> &Builder, AtomicOrdering Ord,
498 bool IsStore, bool IsLoad) const override;
501 EmitInstrWithCustomInserter(MachineInstr *MI,
502 MachineBasicBlock *MBB) const override;
503 MachineBasicBlock *EmitAtomicBinary(MachineInstr *MI,
504 MachineBasicBlock *MBB,
506 unsigned BinOpcode) const;
507 MachineBasicBlock *EmitPartwordAtomicBinary(MachineInstr *MI,
508 MachineBasicBlock *MBB,
509 bool is8bit, unsigned Opcode) const;
511 MachineBasicBlock *emitEHSjLjSetJmp(MachineInstr *MI,
512 MachineBasicBlock *MBB) const;
514 MachineBasicBlock *emitEHSjLjLongJmp(MachineInstr *MI,
515 MachineBasicBlock *MBB) const;
518 getConstraintType(const std::string &Constraint) const override;
520 /// Examine constraint string and operand type and determine a weight value.
521 /// The operand object must already have been set up with the operand type.
522 ConstraintWeight getSingleConstraintMatchWeight(
523 AsmOperandInfo &info, const char *constraint) const override;
525 std::pair<unsigned, const TargetRegisterClass *>
526 getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
527 const std::string &Constraint,
528 MVT VT) const override;
530 /// getByValTypeAlignment - Return the desired alignment for ByVal aggregate
531 /// function arguments in the caller parameter area. This is the actual
532 /// alignment, not its logarithm.
533 unsigned getByValTypeAlignment(Type *Ty) const override;
535 /// LowerAsmOperandForConstraint - Lower the specified operand into the Ops
536 /// vector. If it is invalid, don't add anything to Ops.
537 void LowerAsmOperandForConstraint(SDValue Op,
538 std::string &Constraint,
539 std::vector<SDValue> &Ops,
540 SelectionDAG &DAG) const override;
542 unsigned getInlineAsmMemConstraint(
543 const std::string &ConstraintCode) const override {
544 if (ConstraintCode == "es")
545 return InlineAsm::Constraint_es;
546 else if (ConstraintCode == "o")
547 return InlineAsm::Constraint_o;
548 else if (ConstraintCode == "Q")
549 return InlineAsm::Constraint_Q;
550 else if (ConstraintCode == "Z")
551 return InlineAsm::Constraint_Z;
552 else if (ConstraintCode == "Zy")
553 return InlineAsm::Constraint_Zy;
554 return TargetLowering::getInlineAsmMemConstraint(ConstraintCode);
557 /// isLegalAddressingMode - Return true if the addressing mode represented
558 /// by AM is legal for this target, for a load/store of the specified type.
559 bool isLegalAddressingMode(const AddrMode &AM, Type *Ty,
560 unsigned AS) const override;
562 /// isLegalICmpImmediate - Return true if the specified immediate is legal
563 /// icmp immediate, that is the target has icmp instructions which can
564 /// compare a register against the immediate without having to materialize
565 /// the immediate into a register.
566 bool isLegalICmpImmediate(int64_t Imm) const override;
568 /// isLegalAddImmediate - Return true if the specified immediate is legal
569 /// add immediate, that is the target has add instructions which can
570 /// add a register and the immediate without having to materialize
571 /// the immediate into a register.
572 bool isLegalAddImmediate(int64_t Imm) const override;
574 /// isTruncateFree - Return true if it's free to truncate a value of
575 /// type Ty1 to type Ty2. e.g. On PPC it's free to truncate a i64 value in
576 /// register X1 to i32 by referencing its sub-register R1.
577 bool isTruncateFree(Type *Ty1, Type *Ty2) const override;
578 bool isTruncateFree(EVT VT1, EVT VT2) const override;
580 bool isZExtFree(SDValue Val, EVT VT2) const override;
582 bool isFPExtFree(EVT VT) const override;
584 /// \brief Returns true if it is beneficial to convert a load of a constant
585 /// to just the constant itself.
586 bool shouldConvertConstantLoadToIntImm(const APInt &Imm,
587 Type *Ty) const override;
589 bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override;
591 bool getTgtMemIntrinsic(IntrinsicInfo &Info,
593 unsigned Intrinsic) const override;
595 /// getOptimalMemOpType - Returns the target specific optimal type for load
596 /// and store operations as a result of memset, memcpy, and memmove
597 /// lowering. If DstAlign is zero that means it's safe to destination
598 /// alignment can satisfy any constraint. Similarly if SrcAlign is zero it
599 /// means there isn't a need to check it against alignment requirement,
600 /// probably because the source does not need to be loaded. If 'IsMemset' is
601 /// true, that means it's expanding a memset. If 'ZeroMemset' is true, that
602 /// means it's a memset of zero. 'MemcpyStrSrc' indicates whether the memcpy
603 /// source is constant so it does not need to be loaded.
604 /// It returns EVT::Other if the type should be determined using generic
605 /// target-independent logic.
607 getOptimalMemOpType(uint64_t Size, unsigned DstAlign, unsigned SrcAlign,
608 bool IsMemset, bool ZeroMemset, bool MemcpyStrSrc,
609 MachineFunction &MF) const override;
611 /// Is unaligned memory access allowed for the given type, and is it fast
612 /// relative to software emulation.
613 bool allowsMisalignedMemoryAccesses(EVT VT,
616 bool *Fast = nullptr) const override;
618 /// isFMAFasterThanFMulAndFAdd - Return true if an FMA operation is faster
619 /// than a pair of fmul and fadd instructions. fmuladd intrinsics will be
620 /// expanded to FMAs when this method returns true, otherwise fmuladd is
621 /// expanded to fmul + fadd.
622 bool isFMAFasterThanFMulAndFAdd(EVT VT) const override;
624 const MCPhysReg *getScratchRegisters(CallingConv::ID CC) const override;
626 // Should we expand the build vector with shuffles?
628 shouldExpandBuildVectorWithShuffles(EVT VT,
629 unsigned DefinedValues) const override;
631 /// createFastISel - This method returns a target-specific FastISel object,
632 /// or null if the target does not support "fast" instruction selection.
633 FastISel *createFastISel(FunctionLoweringInfo &FuncInfo,
634 const TargetLibraryInfo *LibInfo) const override;
636 /// \brief Returns true if an argument of type Ty needs to be passed in a
637 /// contiguous block of registers in calling convention CallConv.
638 bool functionArgumentNeedsConsecutiveRegisters(
639 Type *Ty, CallingConv::ID CallConv, bool isVarArg) const override {
640 // We support any array type as "consecutive" block in the parameter
641 // save area. The element type defines the alignment requirement and
642 // whether the argument should go in GPRs, FPRs, or VRs if available.
644 // Note that clang uses this capability both to implement the ELFv2
645 // homogeneous float/vector aggregate ABI, and to avoid having to use
646 // "byval" when passing aggregates that might fully fit in registers.
647 return Ty->isArrayTy();
652 struct ReuseLoadInfo {
656 MachinePointerInfo MPI;
660 const MDNode *Ranges;
662 ReuseLoadInfo() : IsInvariant(false), Alignment(0), Ranges(nullptr) {}
665 bool canReuseLoadAddress(SDValue Op, EVT MemVT, ReuseLoadInfo &RLI,
667 ISD::LoadExtType ET = ISD::NON_EXTLOAD) const;
668 void spliceIntoChain(SDValue ResChain, SDValue NewResChain,
669 SelectionDAG &DAG) const;
671 void LowerFP_TO_INTForReuse(SDValue Op, ReuseLoadInfo &RLI,
672 SelectionDAG &DAG, SDLoc dl) const;
673 SDValue LowerFP_TO_INTDirectMove(SDValue Op, SelectionDAG &DAG,
675 SDValue LowerINT_TO_FPDirectMove(SDValue Op, SelectionDAG &DAG,
678 SDValue getFramePointerFrameIndex(SelectionDAG & DAG) const;
679 SDValue getReturnAddrFrameIndex(SelectionDAG & DAG) const;
682 IsEligibleForTailCallOptimization(SDValue Callee,
683 CallingConv::ID CalleeCC,
685 const SmallVectorImpl<ISD::InputArg> &Ins,
686 SelectionDAG& DAG) const;
688 SDValue EmitTailCallLoadFPAndRetAddr(SelectionDAG & DAG,
696 SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
697 SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
698 SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const;
699 SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;
700 SDValue LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const;
701 SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;
702 SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) const;
703 SDValue LowerSETCC(SDValue Op, SelectionDAG &DAG) const;
704 SDValue LowerINIT_TRAMPOLINE(SDValue Op, SelectionDAG &DAG) const;
705 SDValue LowerADJUST_TRAMPOLINE(SDValue Op, SelectionDAG &DAG) const;
706 SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG,
707 const PPCSubtarget &Subtarget) const;
708 SDValue LowerVAARG(SDValue Op, SelectionDAG &DAG,
709 const PPCSubtarget &Subtarget) const;
710 SDValue LowerVACOPY(SDValue Op, SelectionDAG &DAG,
711 const PPCSubtarget &Subtarget) const;
712 SDValue LowerSTACKRESTORE(SDValue Op, SelectionDAG &DAG,
713 const PPCSubtarget &Subtarget) const;
714 SDValue LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG,
715 const PPCSubtarget &Subtarget) const;
716 SDValue LowerLOAD(SDValue Op, SelectionDAG &DAG) const;
717 SDValue LowerSTORE(SDValue Op, SelectionDAG &DAG) const;
718 SDValue LowerTRUNCATE(SDValue Op, SelectionDAG &DAG) const;
719 SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const;
720 SDValue LowerFP_TO_INT(SDValue Op, SelectionDAG &DAG, SDLoc dl) const;
721 SDValue LowerINT_TO_FP(SDValue Op, SelectionDAG &DAG) const;
722 SDValue LowerFLT_ROUNDS_(SDValue Op, SelectionDAG &DAG) const;
723 SDValue LowerSHL_PARTS(SDValue Op, SelectionDAG &DAG) const;
724 SDValue LowerSRL_PARTS(SDValue Op, SelectionDAG &DAG) const;
725 SDValue LowerSRA_PARTS(SDValue Op, SelectionDAG &DAG) const;
726 SDValue LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG) const;
727 SDValue LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) const;
728 SDValue LowerEXTRACT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) const;
729 SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const;
730 SDValue LowerSCALAR_TO_VECTOR(SDValue Op, SelectionDAG &DAG) const;
731 SDValue LowerSIGN_EXTEND_INREG(SDValue Op, SelectionDAG &DAG) const;
732 SDValue LowerMUL(SDValue Op, SelectionDAG &DAG) const;
734 SDValue LowerVectorLoad(SDValue Op, SelectionDAG &DAG) const;
735 SDValue LowerVectorStore(SDValue Op, SelectionDAG &DAG) const;
737 SDValue LowerCallResult(SDValue Chain, SDValue InFlag,
738 CallingConv::ID CallConv, bool isVarArg,
739 const SmallVectorImpl<ISD::InputArg> &Ins,
740 SDLoc dl, SelectionDAG &DAG,
741 SmallVectorImpl<SDValue> &InVals) const;
742 SDValue FinishCall(CallingConv::ID CallConv, SDLoc dl, bool isTailCall,
743 bool isVarArg, bool IsPatchPoint,
745 SmallVector<std::pair<unsigned, SDValue>, 8>
747 SDValue InFlag, SDValue Chain, SDValue CallSeqStart,
749 int SPDiff, unsigned NumBytes,
750 const SmallVectorImpl<ISD::InputArg> &Ins,
751 SmallVectorImpl<SDValue> &InVals,
752 ImmutableCallSite *CS) const;
755 LowerFormalArguments(SDValue Chain,
756 CallingConv::ID CallConv, bool isVarArg,
757 const SmallVectorImpl<ISD::InputArg> &Ins,
758 SDLoc dl, SelectionDAG &DAG,
759 SmallVectorImpl<SDValue> &InVals) const override;
762 LowerCall(TargetLowering::CallLoweringInfo &CLI,
763 SmallVectorImpl<SDValue> &InVals) const override;
766 CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF,
768 const SmallVectorImpl<ISD::OutputArg> &Outs,
769 LLVMContext &Context) const override;
772 LowerReturn(SDValue Chain,
773 CallingConv::ID CallConv, bool isVarArg,
774 const SmallVectorImpl<ISD::OutputArg> &Outs,
775 const SmallVectorImpl<SDValue> &OutVals,
776 SDLoc dl, SelectionDAG &DAG) const override;
779 extendArgForPPC64(ISD::ArgFlagsTy Flags, EVT ObjectVT, SelectionDAG &DAG,
780 SDValue ArgVal, SDLoc dl) const;
783 LowerFormalArguments_Darwin(SDValue Chain,
784 CallingConv::ID CallConv, bool isVarArg,
785 const SmallVectorImpl<ISD::InputArg> &Ins,
786 SDLoc dl, SelectionDAG &DAG,
787 SmallVectorImpl<SDValue> &InVals) const;
789 LowerFormalArguments_64SVR4(SDValue Chain,
790 CallingConv::ID CallConv, bool isVarArg,
791 const SmallVectorImpl<ISD::InputArg> &Ins,
792 SDLoc dl, SelectionDAG &DAG,
793 SmallVectorImpl<SDValue> &InVals) const;
795 LowerFormalArguments_32SVR4(SDValue Chain,
796 CallingConv::ID CallConv, bool isVarArg,
797 const SmallVectorImpl<ISD::InputArg> &Ins,
798 SDLoc dl, SelectionDAG &DAG,
799 SmallVectorImpl<SDValue> &InVals) const;
802 createMemcpyOutsideCallSeq(SDValue Arg, SDValue PtrOff,
803 SDValue CallSeqStart, ISD::ArgFlagsTy Flags,
804 SelectionDAG &DAG, SDLoc dl) const;
807 LowerCall_Darwin(SDValue Chain, SDValue Callee,
808 CallingConv::ID CallConv,
809 bool isVarArg, bool isTailCall, bool IsPatchPoint,
810 const SmallVectorImpl<ISD::OutputArg> &Outs,
811 const SmallVectorImpl<SDValue> &OutVals,
812 const SmallVectorImpl<ISD::InputArg> &Ins,
813 SDLoc dl, SelectionDAG &DAG,
814 SmallVectorImpl<SDValue> &InVals,
815 ImmutableCallSite *CS) const;
817 LowerCall_64SVR4(SDValue Chain, SDValue Callee,
818 CallingConv::ID CallConv,
819 bool isVarArg, bool isTailCall, bool IsPatchPoint,
820 const SmallVectorImpl<ISD::OutputArg> &Outs,
821 const SmallVectorImpl<SDValue> &OutVals,
822 const SmallVectorImpl<ISD::InputArg> &Ins,
823 SDLoc dl, SelectionDAG &DAG,
824 SmallVectorImpl<SDValue> &InVals,
825 ImmutableCallSite *CS) const;
827 LowerCall_32SVR4(SDValue Chain, SDValue Callee, CallingConv::ID CallConv,
828 bool isVarArg, bool isTailCall, bool IsPatchPoint,
829 const SmallVectorImpl<ISD::OutputArg> &Outs,
830 const SmallVectorImpl<SDValue> &OutVals,
831 const SmallVectorImpl<ISD::InputArg> &Ins,
832 SDLoc dl, SelectionDAG &DAG,
833 SmallVectorImpl<SDValue> &InVals,
834 ImmutableCallSite *CS) const;
836 SDValue lowerEH_SJLJ_SETJMP(SDValue Op, SelectionDAG &DAG) const;
837 SDValue lowerEH_SJLJ_LONGJMP(SDValue Op, SelectionDAG &DAG) const;
839 SDValue DAGCombineExtBoolTrunc(SDNode *N, DAGCombinerInfo &DCI) const;
840 SDValue DAGCombineTruncBoolExt(SDNode *N, DAGCombinerInfo &DCI) const;
841 SDValue combineFPToIntToFP(SDNode *N, DAGCombinerInfo &DCI) const;
843 SDValue getRsqrtEstimate(SDValue Operand, DAGCombinerInfo &DCI,
844 unsigned &RefinementSteps,
845 bool &UseOneConstNR) const override;
846 SDValue getRecipEstimate(SDValue Operand, DAGCombinerInfo &DCI,
847 unsigned &RefinementSteps) const override;
848 bool combineRepeatedFPDivisors(unsigned NumUsers) const override;
850 CCAssignFn *useFastISelCCs(unsigned Flag) const;
854 FastISel *createFastISel(FunctionLoweringInfo &FuncInfo,
855 const TargetLibraryInfo *LibInfo);
858 bool CC_PPC32_SVR4_Custom_Dummy(unsigned &ValNo, MVT &ValVT, MVT &LocVT,
859 CCValAssign::LocInfo &LocInfo,
860 ISD::ArgFlagsTy &ArgFlags,
863 bool CC_PPC32_SVR4_Custom_AlignArgRegs(unsigned &ValNo, MVT &ValVT,
865 CCValAssign::LocInfo &LocInfo,
866 ISD::ArgFlagsTy &ArgFlags,
869 bool CC_PPC32_SVR4_Custom_AlignFPArgRegs(unsigned &ValNo, MVT &ValVT,
871 CCValAssign::LocInfo &LocInfo,
872 ISD::ArgFlagsTy &ArgFlags,
876 #endif // LLVM_TARGET_POWERPC_PPC32ISELLOWERING_H