1//===-- PPCISelLowering.h - PPC32 DAG Lowering Interface --------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the interfaces that PPC uses to lower LLVM code into a
10// selection DAG.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_LIB_TARGET_POWERPC_PPCISELLOWERING_H
15#define LLVM_LIB_TARGET_POWERPC_PPCISELLOWERING_H
16
17#include "PPCInstrInfo.h"
18#include "llvm/CodeGen/CallingConvLower.h"
19#include "llvm/CodeGen/MachineFunction.h"
20#include "llvm/CodeGen/MachineMemOperand.h"
21#include "llvm/CodeGen/SelectionDAG.h"
22#include "llvm/CodeGen/SelectionDAGNodes.h"
23#include "llvm/CodeGen/TargetLowering.h"
24#include "llvm/CodeGen/ValueTypes.h"
25#include "llvm/CodeGenTypes/MachineValueType.h"
26#include "llvm/IR/Attributes.h"
27#include "llvm/IR/CallingConv.h"
28#include "llvm/IR/Function.h"
29#include "llvm/IR/InlineAsm.h"
30#include "llvm/IR/Metadata.h"
31#include "llvm/IR/Type.h"
32#include <optional>
33#include <utility>
34
35namespace llvm {
36
37 /// Define some predicates that are used for node matching.
38 namespace PPC {
39
40 /// isVPKUHUMShuffleMask - Return true if this is the shuffle mask for a
41 /// VPKUHUM instruction.
42 bool isVPKUHUMShuffleMask(ShuffleVectorSDNode *N, unsigned ShuffleKind,
43 SelectionDAG &DAG);
44
45 /// isVPKUWUMShuffleMask - Return true if this is the shuffle mask for a
46 /// VPKUWUM instruction.
47 bool isVPKUWUMShuffleMask(ShuffleVectorSDNode *N, unsigned ShuffleKind,
48 SelectionDAG &DAG);
49
50 /// isVPKUDUMShuffleMask - Return true if this is the shuffle mask for a
51 /// VPKUDUM instruction.
52 bool isVPKUDUMShuffleMask(ShuffleVectorSDNode *N, unsigned ShuffleKind,
53 SelectionDAG &DAG);
54
55 /// isVMRGLShuffleMask - Return true if this is a shuffle mask suitable for
56 /// a VRGL* instruction with the specified unit size (1,2 or 4 bytes).
57 bool isVMRGLShuffleMask(ShuffleVectorSDNode *N, unsigned UnitSize,
58 unsigned ShuffleKind, SelectionDAG &DAG);
59
60 /// isVMRGHShuffleMask - Return true if this is a shuffle mask suitable for
61 /// a VRGH* instruction with the specified unit size (1,2 or 4 bytes).
62 bool isVMRGHShuffleMask(ShuffleVectorSDNode *N, unsigned UnitSize,
63 unsigned ShuffleKind, SelectionDAG &DAG);
64
65 /// isVMRGEOShuffleMask - Return true if this is a shuffle mask suitable for
66 /// a VMRGEW or VMRGOW instruction
67 bool isVMRGEOShuffleMask(ShuffleVectorSDNode *N, bool CheckEven,
68 unsigned ShuffleKind, SelectionDAG &DAG);
69 /// isXXSLDWIShuffleMask - Return true if this is a shuffle mask suitable
70 /// for a XXSLDWI instruction.
71 bool isXXSLDWIShuffleMask(ShuffleVectorSDNode *N, unsigned &ShiftElts,
72 bool &Swap, bool IsLE);
73
74 /// isXXBRHShuffleMask - Return true if this is a shuffle mask suitable
75 /// for a XXBRH instruction.
76 bool isXXBRHShuffleMask(ShuffleVectorSDNode *N);
77
78 /// isXXBRWShuffleMask - Return true if this is a shuffle mask suitable
79 /// for a XXBRW instruction.
80 bool isXXBRWShuffleMask(ShuffleVectorSDNode *N);
81
82 /// isXXBRDShuffleMask - Return true if this is a shuffle mask suitable
83 /// for a XXBRD instruction.
84 bool isXXBRDShuffleMask(ShuffleVectorSDNode *N);
85
86 /// isXXBRQShuffleMask - Return true if this is a shuffle mask suitable
87 /// for a XXBRQ instruction.
88 bool isXXBRQShuffleMask(ShuffleVectorSDNode *N);
89
90 /// isXXPERMDIShuffleMask - Return true if this is a shuffle mask suitable
91 /// for a XXPERMDI instruction.
92 bool isXXPERMDIShuffleMask(ShuffleVectorSDNode *N, unsigned &ShiftElts,
93 bool &Swap, bool IsLE);
94
95 /// isVSLDOIShuffleMask - If this is a vsldoi shuffle mask, return the
96 /// shift amount, otherwise return -1.
97 int isVSLDOIShuffleMask(SDNode *N, unsigned ShuffleKind,
98 SelectionDAG &DAG);
99
100 /// isSplatShuffleMask - Return true if the specified VECTOR_SHUFFLE operand
101 /// specifies a splat of a single element that is suitable for input to
102 /// VSPLTB/VSPLTH/VSPLTW.
103 bool isSplatShuffleMask(ShuffleVectorSDNode *N, unsigned EltSize);
104
105 /// isXXINSERTWMask - Return true if this VECTOR_SHUFFLE can be handled by
106 /// the XXINSERTW instruction introduced in ISA 3.0. This is essentially any
107 /// shuffle of v4f32/v4i32 vectors that just inserts one element from one
108 /// vector into the other. This function will also set a couple of
109 /// output parameters for how much the source vector needs to be shifted and
110 /// what byte number needs to be specified for the instruction to put the
111 /// element in the desired location of the target vector.
112 bool isXXINSERTWMask(ShuffleVectorSDNode *N, unsigned &ShiftElts,
113 unsigned &InsertAtByte, bool &Swap, bool IsLE);
114
115 /// getSplatIdxForPPCMnemonics - Return the splat index as a value that is
116 /// appropriate for PPC mnemonics (which have a big endian bias - namely
117 /// elements are counted from the left of the vector register).
118 unsigned getSplatIdxForPPCMnemonics(SDNode *N, unsigned EltSize,
119 SelectionDAG &DAG);
120
121 /// get_VSPLTI_elt - If this is a build_vector of constants which can be
122 /// formed by using a vspltis[bhw] instruction of the specified element
123 /// size, return the constant being splatted. The ByteSize field indicates
124 /// the number of bytes of each element [124] -> [bhw].
125 SDValue get_VSPLTI_elt(SDNode *N, unsigned ByteSize, SelectionDAG &DAG);
126
127 // Flags for computing the optimal addressing mode for loads and stores.
128 enum MemOpFlags {
129 MOF_None = 0,
130
131 // Extension mode for integer loads.
132 MOF_SExt = 1,
133 MOF_ZExt = 1 << 1,
134 MOF_NoExt = 1 << 2,
135
136 // Address computation flags.
137 MOF_NotAddNorCst = 1 << 5, // Not const. or sum of ptr and scalar.
138 MOF_RPlusSImm16 = 1 << 6, // Reg plus signed 16-bit constant.
139 MOF_RPlusLo = 1 << 7, // Reg plus signed 16-bit relocation
140 MOF_RPlusSImm16Mult4 = 1 << 8, // Reg plus 16-bit signed multiple of 4.
141 MOF_RPlusSImm16Mult16 = 1 << 9, // Reg plus 16-bit signed multiple of 16.
142 MOF_RPlusSImm34 = 1 << 10, // Reg plus 34-bit signed constant.
143 MOF_RPlusR = 1 << 11, // Sum of two variables.
144 MOF_PCRel = 1 << 12, // PC-Relative relocation.
145 MOF_AddrIsSImm32 = 1 << 13, // A simple 32-bit constant.
146
147 // The in-memory type.
148 MOF_SubWordInt = 1 << 15,
149 MOF_WordInt = 1 << 16,
150 MOF_DoubleWordInt = 1 << 17,
151 MOF_ScalarFloat = 1 << 18, // Scalar single or double precision.
152 MOF_Vector = 1 << 19, // Vector types and quad precision scalars.
153 MOF_Vector256 = 1 << 20,
154
155 // Subtarget features.
156 MOF_SubtargetBeforeP9 = 1 << 22,
157 MOF_SubtargetP9 = 1 << 23,
158 MOF_SubtargetP10 = 1 << 24,
159 MOF_SubtargetSPE = 1 << 25
160 };
161
162 // The addressing modes for loads and stores.
163 enum AddrMode {
164 AM_None,
165 AM_DForm,
166 AM_DSForm,
167 AM_DQForm,
168 AM_PrefixDForm,
169 AM_XForm,
170 AM_PCRel
171 };
172 } // end namespace PPC
173
174 class PPCTargetLowering : public TargetLowering {
175 const PPCSubtarget &Subtarget;
176
177 public:
178 explicit PPCTargetLowering(const PPCTargetMachine &TM,
179 const PPCSubtarget &STI);
180
181 bool isSelectSupported(SelectSupportKind Kind) const override {
182 // PowerPC does not support scalar condition selects on vectors.
183 return (Kind != SelectSupportKind::ScalarCondVectorVal);
184 }
185
186 /// getPreferredVectorAction - The code we generate when vector types are
187 /// legalized by promoting the integer element type is often much worse
188 /// than code we generate if we widen the type for applicable vector types.
189 /// The issue with promoting is that the vector is scalaraized, individual
190 /// elements promoted and then the vector is rebuilt. So say we load a pair
191 /// of v4i8's and shuffle them. This will turn into a mess of 8 extending
192 /// loads, moves back into VSR's (or memory ops if we don't have moves) and
193 /// then the VPERM for the shuffle. All in all a very slow sequence.
194 TargetLoweringBase::LegalizeTypeAction getPreferredVectorAction(MVT VT)
195 const override {
196 // Default handling for scalable and single-element vectors.
197 if (VT.isScalableVector() || VT.getVectorNumElements() == 1)
198 return TargetLoweringBase::getPreferredVectorAction(VT);
199
200 // Split and promote vNi1 vectors so we don't produce v256i1/v512i1
201 // types as those are only for MMA instructions.
202 if (VT.getScalarSizeInBits() == 1 && VT.getSizeInBits() > 16)
203 return TypeSplitVector;
204 if (VT.getScalarSizeInBits() == 1)
205 return TypePromoteInteger;
206
207 // Widen vectors that have reasonably sized elements.
208 if (VT.getScalarSizeInBits() % 8 == 0)
209 return TypeWidenVector;
210 return TargetLoweringBase::getPreferredVectorAction(VT);
211 }
212
213 bool useSoftFloat() const override;
214
215 bool hasSPE() const;
216
217 MVT getScalarShiftAmountTy(const DataLayout &, EVT) const override {
218 return MVT::i32;
219 }
220
221 bool isCheapToSpeculateCttz(Type *Ty) const override {
222 return true;
223 }
224
225 bool isCheapToSpeculateCtlz(Type *Ty) const override {
226 return true;
227 }
228
229 bool
230 shallExtractConstSplatVectorElementToStore(Type *VectorTy,
231 unsigned ElemSizeInBits,
232 unsigned &Index) const override;
233
234 bool isCtlzFast() const override {
235 return true;
236 }
237
238 bool isEqualityCmpFoldedWithSignedCmp() const override {
239 return false;
240 }
241
242 bool hasAndNotCompare(SDValue) const override {
243 return true;
244 }
245
246 bool preferIncOfAddToSubOfNot(EVT VT) const override;
247
248 bool convertSetCCLogicToBitwiseLogic(EVT VT) const override {
249 return VT.isScalarInteger();
250 }
251
252 SDValue getNegatedExpression(SDValue Op, SelectionDAG &DAG, bool LegalOps,
253 bool OptForSize, NegatibleCost &Cost,
254 unsigned Depth = 0) const override;
255
256 /// getSetCCResultType - Return the ISD::SETCC ValueType
257 EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context,
258 EVT VT) const override;
259
260 /// Return true if target always benefits from combining into FMA for a
261 /// given value type. This must typically return false on targets where FMA
262 /// takes more cycles to execute than FADD.
263 bool enableAggressiveFMAFusion(EVT VT) const override;
264
265 /// getPreIndexedAddressParts - returns true by value, base pointer and
266 /// offset pointer and addressing mode by reference if the node's address
267 /// can be legally represented as pre-indexed load / store address.
268 bool getPreIndexedAddressParts(SDNode *N, SDValue &Base,
269 SDValue &Offset,
270 ISD::MemIndexedMode &AM,
271 SelectionDAG &DAG) const override;
272
273 /// SelectAddressEVXRegReg - Given the specified addressed, check to see if
274 /// it can be more efficiently represented as [r+imm].
275 bool SelectAddressEVXRegReg(SDValue N, SDValue &Base, SDValue &Index,
276 SelectionDAG &DAG) const;
277
278 /// SelectAddressRegReg - Given the specified addressed, check to see if it
279 /// can be more efficiently represented as [r+imm]. If \p EncodingAlignment
280 /// is non-zero, only accept displacement which is not suitable for [r+imm].
281 /// Returns false if it can be represented by [r+imm], which are preferred.
282 bool SelectAddressRegReg(SDValue N, SDValue &Base, SDValue &Index,
283 SelectionDAG &DAG,
284 MaybeAlign EncodingAlignment = std::nullopt) const;
285
286 /// SelectAddressRegImm - Returns true if the address N can be represented
287 /// by a base register plus a signed 16-bit displacement [r+imm], and if it
288 /// is not better represented as reg+reg. If \p EncodingAlignment is
289 /// non-zero, only accept displacements suitable for instruction encoding
290 /// requirement, i.e. multiples of 4 for DS form.
291 bool SelectAddressRegImm(SDValue N, SDValue &Disp, SDValue &Base,
292 SelectionDAG &DAG,
293 MaybeAlign EncodingAlignment) const;
294 bool SelectAddressRegImm34(SDValue N, SDValue &Disp, SDValue &Base,
295 SelectionDAG &DAG) const;
296
297 /// SelectAddressRegRegOnly - Given the specified addressed, force it to be
298 /// represented as an indexed [r+r] operation.
299 bool SelectAddressRegRegOnly(SDValue N, SDValue &Base, SDValue &Index,
300 SelectionDAG &DAG) const;
301
302 /// SelectAddressPCRel - Represent the specified address as pc relative to
303 /// be represented as [pc+imm]
304 bool SelectAddressPCRel(SDValue N, SDValue &Base) const;
305
306 Sched::Preference getSchedulingPreference(SDNode *N) const override;
307
308 /// LowerOperation - Provide custom lowering hooks for some operations.
309 ///
310 SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
311
312 /// ReplaceNodeResults - Replace the results of node with an illegal result
313 /// type with new values built out of custom code.
314 ///
315 void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue>&Results,
316 SelectionDAG &DAG) const override;
317
318 SDValue expandVSXLoadForLE(SDNode *N, DAGCombinerInfo &DCI) const;
319 SDValue expandVSXStoreForLE(SDNode *N, DAGCombinerInfo &DCI) const;
320
321 SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override;
322
323 SDValue BuildSDIVPow2(SDNode *N, const APInt &Divisor, SelectionDAG &DAG,
324 SmallVectorImpl<SDNode *> &Created) const override;
325
326 Register getRegisterByName(const char* RegName, LLT VT,
327 const MachineFunction &MF) const override;
328
329 void computeKnownBitsForTargetNode(const SDValue Op,
330 KnownBits &Known,
331 const APInt &DemandedElts,
332 const SelectionDAG &DAG,
333 unsigned Depth = 0) const override;
334
335 Align
336 getPrefLoopAlignment(MachineLoop *ML,
337 const MachineBasicBlock *BlockToAlign) const override;
338
339 bool shouldInsertFencesForAtomic(const Instruction *I) const override {
340 return true;
341 }
342
343 /// True unless the subtarget has FeatureFenceKeepsReservation.
344 bool fenceClearsLoadLinkedReservation() const override;
345
346 Value *emitLoadLinked(IRBuilderBase &Builder, Type *ValueTy, Value *Addr,
347 AtomicOrdering Ord) const override;
348
349 Value *emitStoreConditional(IRBuilderBase &Builder, Value *Val, Value *Addr,
350 AtomicOrdering Ord) const override;
351
352 Instruction *emitLeadingFence(IRBuilderBase &Builder, Instruction *Inst,
353 AtomicOrdering Ord) const override;
354 Instruction *emitTrailingFence(IRBuilderBase &Builder, Instruction *Inst,
355 AtomicOrdering Ord) const override;
356
357 bool shouldInlineQuadwordAtomics() const;
358
359 ISD::NodeType getExtendForAtomicCmpSwapArg() const override {
360 return ISD::ZERO_EXTEND;
361 }
362
363 TargetLowering::AtomicExpansionKind
364 shouldExpandAtomicRMWInIR(const AtomicRMWInst *AI) const override;
365
366 TargetLowering::AtomicExpansionKind
367 shouldExpandAtomicCmpXchgInIR(const AtomicCmpXchgInst *AI) const override;
368
369 Value *emitMaskedAtomicRMWIntrinsic(IRBuilderBase &Builder,
370 AtomicRMWInst *AI, Value *AlignedAddr,
371 Value *Incr, Value *Mask,
372 Value *ShiftAmt,
373 AtomicOrdering Ord) const override;
374 Value *emitMaskedAtomicCmpXchgIntrinsic(IRBuilderBase &Builder,
375 AtomicCmpXchgInst *CI,
376 Value *AlignedAddr, Value *CmpVal,
377 Value *NewVal, Value *Mask,
378 AtomicOrdering Ord) const override;
379
380 MachineBasicBlock *
381 EmitInstrWithCustomInserter(MachineInstr &MI,
382 MachineBasicBlock *MBB) const override;
383 MachineBasicBlock *EmitAtomicBinary(MachineInstr &MI,
384 MachineBasicBlock *MBB,
385 unsigned BinOpcode,
386 unsigned CmpOpcode = 0,
387 unsigned CmpPred = 0) const;
388 MachineBasicBlock *EmitPartwordAtomicBinary(MachineInstr &MI,
389 MachineBasicBlock *MBB,
390 unsigned Opcode,
391 unsigned CmpOpcode = 0,
392 unsigned CmpPred = 0) const;
393
394 MachineBasicBlock *emitEHSjLjSetJmp(MachineInstr &MI,
395 MachineBasicBlock *MBB) const;
396
397 MachineBasicBlock *emitEHSjLjLongJmp(MachineInstr &MI,
398 MachineBasicBlock *MBB) const;
399
400 MachineBasicBlock *emitProbedAlloca(MachineInstr &MI,
401 MachineBasicBlock *MBB) const;
402
403 bool hasInlineStackProbe(const MachineFunction &MF) const override;
404
405 unsigned getStackProbeSize(const MachineFunction &MF) const;
406
407 ConstraintType getConstraintType(StringRef Constraint) const override;
408
409 /// Examine constraint string and operand type and determine a weight value.
410 /// The operand object must already have been set up with the operand type.
411 ConstraintWeight getSingleConstraintMatchWeight(
412 AsmOperandInfo &info, const char *constraint) const override;
413
414 std::pair<unsigned, const TargetRegisterClass *>
415 getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
416 StringRef Constraint, MVT VT) const override;
417
418 /// getByValTypeAlignment - Return the desired alignment for ByVal aggregate
419 /// function arguments in the caller parameter area.
420 Align getByValTypeAlignment(Type *Ty, const DataLayout &DL) const override;
421
422 /// LowerAsmOperandForConstraint - Lower the specified operand into the Ops
423 /// vector. If it is invalid, don't add anything to Ops.
424 void LowerAsmOperandForConstraint(SDValue Op, StringRef Constraint,
425 std::vector<SDValue> &Ops,
426 SelectionDAG &DAG) const override;
427
428 InlineAsm::ConstraintCode
429 getInlineAsmMemConstraint(StringRef ConstraintCode) const override {
430 if (ConstraintCode == "es")
431 return InlineAsm::ConstraintCode::es;
432 else if (ConstraintCode == "Q")
433 return InlineAsm::ConstraintCode::Q;
434 else if (ConstraintCode == "Z")
435 return InlineAsm::ConstraintCode::Z;
436 else if (ConstraintCode == "Zy")
437 return InlineAsm::ConstraintCode::Zy;
438 return TargetLowering::getInlineAsmMemConstraint(ConstraintCode);
439 }
440
441 void CollectTargetIntrinsicOperands(const CallInst &I,
442 SmallVectorImpl<SDValue> &Ops,
443 SelectionDAG &DAG) const override;
444
445 /// isLegalAddressingMode - Return true if the addressing mode represented
446 /// by AM is legal for this target, for a load/store of the specified type.
447 bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM,
448 Type *Ty, unsigned AS,
449 Instruction *I = nullptr) const override;
450
451 /// isLegalICmpImmediate - Return true if the specified immediate is legal
452 /// icmp immediate, that is the target has icmp instructions which can
453 /// compare a register against the immediate without having to materialize
454 /// the immediate into a register.
455 bool isLegalICmpImmediate(int64_t Imm) const override;
456
457 /// isLegalAddImmediate - Return true if the specified immediate is legal
458 /// add immediate, that is the target has add instructions which can
459 /// add a register and the immediate without having to materialize
460 /// the immediate into a register.
461 bool isLegalAddImmediate(int64_t Imm) const override;
462
463 /// isTruncateFree - Return true if it's free to truncate a value of
464 /// type Ty1 to type Ty2. e.g. On PPC it's free to truncate a i64 value in
465 /// register X1 to i32 by referencing its sub-register R1.
466 bool isTruncateFree(Type *Ty1, Type *Ty2) const override;
467 bool isTruncateFree(EVT VT1, EVT VT2) const override;
468
469 bool isZExtFree(SDValue Val, EVT VT2) const override;
470
471 bool isFPExtFree(EVT DestVT, EVT SrcVT) const override;
472
473 /// Returns true if it is beneficial to convert a load of a constant
474 /// to just the constant itself.
475 bool shouldConvertConstantLoadToIntImm(const APInt &Imm,
476 Type *Ty) const override;
477
478 bool convertSelectOfConstantsToMath(EVT VT) const override {
479 return true;
480 }
481
482 bool decomposeMulByConstant(LLVMContext &Context, EVT VT,
483 SDValue C) const override;
484
485 bool isDesirableToTransformToIntegerOp(unsigned Opc,
486 EVT VT) const override {
487 // Only handle float load/store pair because float(fpr) load/store
488 // instruction has more cycles than integer(gpr) load/store in PPC.
489 if (Opc != ISD::LOAD && Opc != ISD::STORE)
490 return false;
491 if (VT != MVT::f32 && VT != MVT::f64)
492 return false;
493
494 return true;
495 }
496
497 // Returns true if the address of the global is stored in TOC entry.
498 bool isAccessedAsGotIndirect(SDValue N) const;
499
500 bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override;
501
502 void getTgtMemIntrinsic(SmallVectorImpl<IntrinsicInfo> &Infos,
503 const CallBase &I, MachineFunction &MF,
504 unsigned Intrinsic) const override;
505
506 /// It returns EVT::Other if the type should be determined using generic
507 /// target-independent logic.
508 EVT getOptimalMemOpType(LLVMContext &Context, const MemOp &Op,
509 const AttributeList &FuncAttributes) const override;
510
511 /// Is unaligned memory access allowed for the given type, and is it fast
512 /// relative to software emulation.
513 bool allowsMisalignedMemoryAccesses(
514 EVT VT, unsigned AddrSpace, Align Alignment = Align(1),
515 MachineMemOperand::Flags Flags = MachineMemOperand::MONone,
516 unsigned *Fast = nullptr) const override;
517
518 /// isFMAFasterThanFMulAndFAdd - Return true if an FMA operation is faster
519 /// than a pair of fmul and fadd instructions. fmuladd intrinsics will be
520 /// expanded to FMAs when this method returns true, otherwise fmuladd is
521 /// expanded to fmul + fadd.
522 bool isFMAFasterThanFMulAndFAdd(const MachineFunction &MF,
523 EVT VT) const override;
524
525 bool isFMAFasterThanFMulAndFAdd(const Function &F, Type *Ty) const override;
526
527 /// isProfitableToHoist - Check if it is profitable to hoist instruction
528 /// \p I to its dominator block.
529 /// For example, it is not profitable if \p I and it's only user can form a
530 /// FMA instruction, because Powerpc prefers FMADD.
531 bool isProfitableToHoist(Instruction *I) const override;
532
533 const MCPhysReg *getScratchRegisters(CallingConv::ID CC) const override;
534
535 // Should we expand the build vector with shuffles?
536 bool
537 shouldExpandBuildVectorWithShuffles(EVT VT,
538 unsigned DefinedValues) const override;
539
540 // Keep the zero-extensions for arguments to libcalls.
541 bool shouldKeepZExtForFP16Conv() const override { return true; }
542
543 /// createFastISel - This method returns a target-specific FastISel object,
544 /// or null if the target does not support "fast" instruction selection.
545 FastISel *
546 createFastISel(FunctionLoweringInfo &FuncInfo,
547 const TargetLibraryInfo *LibInfo,
548 const LibcallLoweringInfo *LibcallLowering) const override;
549
550 /// Returns true if an argument of type Ty needs to be passed in a
551 /// contiguous block of registers in calling convention CallConv.
552 bool functionArgumentNeedsConsecutiveRegisters(
553 Type *Ty, CallingConv::ID CallConv, bool isVarArg,
554 const DataLayout &DL) const override {
555 // We support any array type as "consecutive" block in the parameter
556 // save area. The element type defines the alignment requirement and
557 // whether the argument should go in GPRs, FPRs, or VRs if available.
558 //
559 // Note that clang uses this capability both to implement the ELFv2
560 // homogeneous float/vector aggregate ABI, and to avoid having to use
561 // "byval" when passing aggregates that might fully fit in registers.
562 return Ty->isArrayTy();
563 }
564
565 /// If a physical register, this returns the register that receives the
566 /// exception address on entry to an EH pad.
567 Register
568 getExceptionPointerRegister(ExceptionHandling EH,
569 const Constant *PersonalityFn) const override;
570
571 /// If a physical register, this returns the register that receives the
572 /// exception typeid on entry to a landing pad.
573 Register
574 getExceptionSelectorRegister(ExceptionHandling EH,
575 const Constant *PersonalityFn) const override;
576
577 /// Override to support customized stack guard loading.
578 bool useLoadStackGuardNode(const Module &M) const override;
579
580 FPImmAction getFPImmAction(const APFloat &Imm, EVT VT,
581 bool ForCodeSize) const override;
582
583 unsigned getJumpTableEncoding() const override;
584 bool isJumpTableRelative() const override;
585 SDValue getPICJumpTableRelocBase(SDValue Table,
586 SelectionDAG &DAG) const override;
587 const MCExpr *getPICJumpTableRelocBaseExpr(const MachineFunction *MF,
588 unsigned JTI,
589 MCContext &Ctx) const override;
590
591 /// SelectOptimalAddrMode - Based on a node N and it's Parent (a MemSDNode),
592 /// compute the address flags of the node, get the optimal address mode
593 /// based on the flags, and set the Base and Disp based on the address mode.
594 PPC::AddrMode SelectOptimalAddrMode(const SDNode *Parent, SDValue N,
595 SDValue &Disp, SDValue &Base,
596 SelectionDAG &DAG,
597 MaybeAlign Align) const;
598 /// SelectForceXFormMode - Given the specified address, force it to be
599 /// represented as an indexed [r+r] operation (an XForm instruction).
600 PPC::AddrMode SelectForceXFormMode(SDValue N, SDValue &Disp, SDValue &Base,
601 SelectionDAG &DAG) const;
602
603 bool splitValueIntoRegisterParts(
604 SelectionDAG & DAG, const SDLoc &DL, SDValue Val, SDValue *Parts,
605 unsigned NumParts, MVT PartVT, std::optional<CallingConv::ID> CC)
606 const override;
607 /// Structure that collects some common arguments that get passed around
608 /// between the functions for call lowering.
609 struct CallFlags {
610 const CallingConv::ID CallConv;
611 const bool IsTailCall : 1;
612 const bool IsVarArg : 1;
613 const bool IsPatchPoint : 1;
614 const bool IsIndirect : 1;
615 const bool HasNest : 1;
616 const bool NoMerge : 1;
617
618 CallFlags(CallingConv::ID CC, bool IsTailCall, bool IsVarArg,
619 bool IsPatchPoint, bool IsIndirect, bool HasNest, bool NoMerge)
620 : CallConv(CC), IsTailCall(IsTailCall), IsVarArg(IsVarArg),
621 IsPatchPoint(IsPatchPoint), IsIndirect(IsIndirect),
622 HasNest(HasNest), NoMerge(NoMerge) {}
623 };
624
625 CCAssignFn *ccAssignFnForCall(CallingConv::ID CC, bool Return,
626 bool IsVarArg) const;
627 bool supportsTailCallFor(const CallBase *CB) const;
628
629 bool hasMultipleConditionRegisters(EVT VT) const override;
630
631 private:
632 struct ReuseLoadInfo {
633 SDValue Ptr;
634 SDValue Chain;
635 SDValue ResChain;
636 MachinePointerInfo MPI;
637 bool IsDereferenceable = false;
638 bool IsInvariant = false;
639 Align Alignment;
640 AAMDNodes AAInfo;
641 const MDNode *Ranges = nullptr;
642
643 ReuseLoadInfo() = default;
644
645 MachineMemOperand::Flags MMOFlags() const {
646 MachineMemOperand::Flags F = MachineMemOperand::MONone;
647 if (IsDereferenceable)
648 F |= MachineMemOperand::MODereferenceable;
649 if (IsInvariant)
650 F |= MachineMemOperand::MOInvariant;
651 return F;
652 }
653 };
654
655 // Map that relates a set of common address flags to PPC addressing modes.
656 std::map<PPC::AddrMode, SmallVector<unsigned, 16>> AddrModesMap;
657 void initializeAddrModeMap();
658
659 bool canReuseLoadAddress(SDValue Op, EVT MemVT, ReuseLoadInfo &RLI,
660 SelectionDAG &DAG,
661 ISD::LoadExtType ET = ISD::NON_EXTLOAD) const;
662
663 void LowerFP_TO_INTForReuse(SDValue Op, ReuseLoadInfo &RLI,
664 SelectionDAG &DAG, const SDLoc &dl) const;
665 SDValue LowerFP_TO_INTDirectMove(SDValue Op, SelectionDAG &DAG,
666 const SDLoc &dl) const;
667
668 bool directMoveIsProfitable(const SDValue &Op) const;
669 SDValue LowerINT_TO_FPDirectMove(SDValue Op, SelectionDAG &DAG,
670 const SDLoc &dl) const;
671
672 SDValue LowerINT_TO_FPVector(SDValue Op, SelectionDAG &DAG,
673 const SDLoc &dl) const;
674
675 SDValue LowerTRUNCATEVector(SDValue Op, SelectionDAG &DAG) const;
676
677 SDValue getFramePointerFrameIndex(SelectionDAG & DAG) const;
678 SDValue getReturnAddrFrameIndex(SelectionDAG & DAG) const;
679
680 bool IsEligibleForTailCallOptimization(
681 const GlobalValue *CalleeGV, CallingConv::ID CalleeCC,
682 CallingConv::ID CallerCC, bool isVarArg,
683 const SmallVectorImpl<ISD::InputArg> &Ins) const;
684
685 bool IsEligibleForTailCallOptimization_64SVR4(
686 const GlobalValue *CalleeGV, CallingConv::ID CalleeCC,
687 CallingConv::ID CallerCC, const CallBase *CB, bool isVarArg,
688 const SmallVectorImpl<ISD::OutputArg> &Outs,
689 const SmallVectorImpl<ISD::InputArg> &Ins, const Function *CallerFunc,
690 bool isCalleeExternalSymbol) const;
691
692 bool isEligibleForTCO(const GlobalValue *CalleeGV, CallingConv::ID CalleeCC,
693 CallingConv::ID CallerCC, const CallBase *CB,
694 bool isVarArg,
695 const SmallVectorImpl<ISD::OutputArg> &Outs,
696 const SmallVectorImpl<ISD::InputArg> &Ins,
697 const Function *CallerFunc,
698 bool isCalleeExternalSymbol) const;
699
700 SDValue EmitTailCallLoadFPAndRetAddr(SelectionDAG &DAG, int SPDiff,
701 SDValue Chain, SDValue &LROpOut,
702 SDValue &FPOpOut,
703 const SDLoc &dl) const;
704
705 SDValue getTOCEntry(SelectionDAG &DAG, const SDLoc &dl, SDValue GA) const;
706
707 SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
708 SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
709 SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const;
710 SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;
711 SDValue LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const;
712 SDValue LowerGlobalTLSAddressAIX(SDValue Op, SelectionDAG &DAG) const;
713 SDValue LowerGlobalTLSAddressLinux(SDValue Op, SelectionDAG &DAG) const;
714 SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;
715 SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) const;
716 SDValue LowerSETCC(SDValue Op, SelectionDAG &DAG) const;
717 SDValue LowerBR_CC(SDValue Op, SelectionDAG &DAG) const;
718 SDValue LowerSSUBO(SDValue Op, SelectionDAG &DAG) const;
719 SDValue LowerSADDO(SDValue Op, SelectionDAG &DAG) const;
720 SDValue LowerINIT_TRAMPOLINE(SDValue Op, SelectionDAG &DAG) const;
721 SDValue LowerADJUST_TRAMPOLINE(SDValue Op, SelectionDAG &DAG) const;
722 SDValue LowerINLINEASM(SDValue Op, SelectionDAG &DAG) const;
723 SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const;
724 SDValue LowerVAARG(SDValue Op, SelectionDAG &DAG) const;
725 SDValue LowerVACOPY(SDValue Op, SelectionDAG &DAG) const;
726 SDValue LowerSTACKRESTORE(SDValue Op, SelectionDAG &DAG) const;
727 SDValue LowerGET_DYNAMIC_AREA_OFFSET(SDValue Op, SelectionDAG &DAG) const;
728 SDValue LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) const;
729 SDValue LowerEH_DWARF_CFA(SDValue Op, SelectionDAG &DAG) const;
730 SDValue LowerLOAD(SDValue Op, SelectionDAG &DAG) const;
731 SDValue LowerSTORE(SDValue Op, SelectionDAG &DAG) const;
732 SDValue LowerTRUNCATE(SDValue Op, SelectionDAG &DAG) const;
733 SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const;
734 SDValue LowerFP_TO_INT(SDValue Op, SelectionDAG &DAG,
735 const SDLoc &dl) const;
736 SDValue LowerINT_TO_FP(SDValue Op, SelectionDAG &DAG) const;
737 SDValue LowerGET_ROUNDING(SDValue Op, SelectionDAG &DAG) const;
738 SDValue LowerSET_ROUNDING(SDValue Op, SelectionDAG &DAG) const;
739 SDValue LowerSHL_PARTS(SDValue Op, SelectionDAG &DAG) const;
740 SDValue LowerSRL_PARTS(SDValue Op, SelectionDAG &DAG) const;
741 SDValue LowerSRA_PARTS(SDValue Op, SelectionDAG &DAG) const;
742 SDValue LowerFunnelShift(SDValue Op, SelectionDAG &DAG) const;
743 SDValue LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG) const;
744 SDValue LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) const;
745 SDValue LowerVPERM(SDValue Op, SelectionDAG &DAG, ArrayRef<int> PermMask,
746 EVT VT, SDValue V1, SDValue V2) const;
747 SDValue LowerINSERT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) const;
748 SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const;
749 SDValue LowerINTRINSIC_VOID(SDValue Op, SelectionDAG &DAG) const;
750 SDValue LowerBSWAP(SDValue Op, SelectionDAG &DAG) const;
751 SDValue LowerIS_FPCLASS(SDValue Op, SelectionDAG &DAG) const;
752 SDValue LowerADDSUBO_CARRY(SDValue Op, SelectionDAG &DAG) const;
753 SDValue LowerADDSUBO(SDValue Op, SelectionDAG &DAG) const;
754 SDValue LowerABDU(SDValue Op, SelectionDAG &DAG) const;
755 SDValue LowerUCMP(SDValue Op, SelectionDAG &DAG) const;
756 SDValue LowerSCMP(SDValue Op, SelectionDAG &DAG) const;
757 SDValue lowerToLibCall(const char *LibCallName, SDValue Op,
758 SelectionDAG &DAG) const;
759 SDValue lowerLibCallBasedOnType(const char *LibCallFloatName,
760 const char *LibCallDoubleName, SDValue Op,
761 SelectionDAG &DAG) const;
762 bool isLowringToMASSFiniteSafe(SDValue Op) const;
763 bool isLowringToMASSSafe(SDValue Op) const;
764 bool isScalarMASSConversionEnabled() const;
765 SDValue lowerLibCallBase(const char *LibCallDoubleName,
766 const char *LibCallFloatName,
767 const char *LibCallDoubleNameFinite,
768 const char *LibCallFloatNameFinite, SDValue Op,
769 SelectionDAG &DAG) const;
770 SDValue lowerPow(SDValue Op, SelectionDAG &DAG) const;
771 SDValue lowerSin(SDValue Op, SelectionDAG &DAG) const;
772 SDValue lowerCos(SDValue Op, SelectionDAG &DAG) const;
773 SDValue lowerLog(SDValue Op, SelectionDAG &DAG) const;
774 SDValue lowerLog10(SDValue Op, SelectionDAG &DAG) const;
775 SDValue lowerExp(SDValue Op, SelectionDAG &DAG) const;
776 SDValue LowerATOMIC_LOAD_STORE(SDValue Op, SelectionDAG &DAG) const;
777 SDValue LowerSCALAR_TO_VECTOR(SDValue Op, SelectionDAG &DAG) const;
778 SDValue LowerMUL(SDValue Op, SelectionDAG &DAG) const;
779 SDValue LowerFP_EXTEND(SDValue Op, SelectionDAG &DAG) const;
780 SDValue LowerFP_ROUND(SDValue Op, SelectionDAG &DAG) const;
781 SDValue LowerROTL(SDValue Op, SelectionDAG &DAG) const;
782
783 SDValue LowerVP_LOAD(SDValue Op, SelectionDAG &DAG) const;
784 SDValue LowerVP_STORE(SDValue Op, SelectionDAG &DAG) const;
785
786 SDValue LowerPartialReduce(SDValue Op, SelectionDAG &DAG) const;
787
788 SDValue LowerVectorLoad(SDValue Op, SelectionDAG &DAG) const;
789 SDValue LowerVectorStore(SDValue Op, SelectionDAG &DAG) const;
790 SDValue LowerDMFVectorLoad(SDValue Op, SelectionDAG &DAG) const;
791 SDValue LowerDMFVectorStore(SDValue Op, SelectionDAG &DAG) const;
792 SDValue DMFInsert1024(const SmallVectorImpl<SDValue> &Pairs,
793 const SDLoc &dl, SelectionDAG &DAG) const;
794
795 SDValue LowerCallResult(SDValue Chain, SDValue InGlue,
796 CallingConv::ID CallConv, bool isVarArg,
797 const SmallVectorImpl<ISD::InputArg> &Ins,
798 const SDLoc &dl, SelectionDAG &DAG,
799 SmallVectorImpl<SDValue> &InVals) const;
800
801 SDValue FinishCall(CallFlags CFlags, const SDLoc &dl, SelectionDAG &DAG,
802 SmallVector<std::pair<unsigned, SDValue>, 8> &RegsToPass,
803 SDValue InGlue, SDValue Chain, SDValue CallSeqStart,
804 SDValue &Callee, int SPDiff, unsigned NumBytes,
805 const SmallVectorImpl<ISD::InputArg> &Ins,
806 SmallVectorImpl<SDValue> &InVals,
807 const CallBase *CB) const;
808
809 SDValue
810 LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
811 const SmallVectorImpl<ISD::InputArg> &Ins,
812 const SDLoc &dl, SelectionDAG &DAG,
813 SmallVectorImpl<SDValue> &InVals) const override;
814
815 SDValue LowerCall(TargetLowering::CallLoweringInfo &CLI,
816 SmallVectorImpl<SDValue> &InVals) const override;
817
818 bool CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF,
819 bool isVarArg,
820 const SmallVectorImpl<ISD::OutputArg> &Outs,
821 LLVMContext &Context, const Type *RetTy) const override;
822
823 SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
824 const SmallVectorImpl<ISD::OutputArg> &Outs,
825 const SmallVectorImpl<SDValue> &OutVals,
826 const SDLoc &dl, SelectionDAG &DAG) const override;
827
828 SDValue extendArgForPPC64(ISD::ArgFlagsTy Flags, EVT ObjectVT,
829 SelectionDAG &DAG, SDValue ArgVal,
830 const SDLoc &dl) const;
831
832 SDValue LowerFormalArguments_AIX(
833 SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
834 const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &dl,
835 SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals) const;
836 SDValue LowerFormalArguments_64SVR4(
837 SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
838 const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &dl,
839 SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals) const;
840 SDValue LowerFormalArguments_32SVR4(
841 SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
842 const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &dl,
843 SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals) const;
844
845 SDValue createMemcpyOutsideCallSeq(SDValue Arg, SDValue PtrOff,
846 SDValue CallSeqStart,
847 ISD::ArgFlagsTy Flags, SelectionDAG &DAG,
848 const SDLoc &dl) const;
849
850 SDValue LowerCall_64SVR4(SDValue Chain, SDValue Callee, CallFlags CFlags,
851 const SmallVectorImpl<ISD::OutputArg> &Outs,
852 const SmallVectorImpl<SDValue> &OutVals,
853 const SmallVectorImpl<ISD::InputArg> &Ins,
854 const SDLoc &dl, SelectionDAG &DAG,
855 SmallVectorImpl<SDValue> &InVals,
856 const CallBase *CB) const;
857 SDValue LowerCall_32SVR4(SDValue Chain, SDValue Callee, CallFlags CFlags,
858 const SmallVectorImpl<ISD::OutputArg> &Outs,
859 const SmallVectorImpl<SDValue> &OutVals,
860 const SmallVectorImpl<ISD::InputArg> &Ins,
861 const SDLoc &dl, SelectionDAG &DAG,
862 SmallVectorImpl<SDValue> &InVals,
863 const CallBase *CB) const;
864 SDValue LowerCall_AIX(SDValue Chain, SDValue Callee, CallFlags CFlags,
865 const SmallVectorImpl<ISD::OutputArg> &Outs,
866 const SmallVectorImpl<SDValue> &OutVals,
867 const SmallVectorImpl<ISD::InputArg> &Ins,
868 const SDLoc &dl, SelectionDAG &DAG,
869 SmallVectorImpl<SDValue> &InVals,
870 const CallBase *CB) const;
871
872 SDValue lowerEH_SJLJ_SETJMP(SDValue Op, SelectionDAG &DAG) const;
873 SDValue lowerEH_SJLJ_LONGJMP(SDValue Op, SelectionDAG &DAG) const;
874 SDValue LowerBITCAST(SDValue Op, SelectionDAG &DAG) const;
875 SDValue LowerVecSplatSmallFP(SDValue Op, SelectionDAG &DAG,
876 bool BVNIsConstantSplat,
877 unsigned SplatBitSize) const;
878
879 SDValue DAGCombineExtBoolTrunc(SDNode *N, DAGCombinerInfo &DCI) const;
880 SDValue DAGCombineBuildVector(SDNode *N, DAGCombinerInfo &DCI) const;
881 SDValue DAGCombineTruncBoolExt(SDNode *N, DAGCombinerInfo &DCI) const;
882 SDValue combineStoreFPToInt(SDNode *N, DAGCombinerInfo &DCI) const;
883 SDValue combineFPToIntToFP(SDNode *N, DAGCombinerInfo &DCI) const;
884 SDValue combineSHL(SDNode *N, DAGCombinerInfo &DCI) const;
885 SDValue combineVectorShift(SDNode *N, DAGCombinerInfo &DCI) const;
886 SDValue combineSRA(SDNode *N, DAGCombinerInfo &DCI) const;
887 SDValue combineSRL(SDNode *N, DAGCombinerInfo &DCI) const;
888 SDValue combineMUL(SDNode *N, DAGCombinerInfo &DCI) const;
889 SDValue combineADD(SDNode *N, DAGCombinerInfo &DCI) const;
890 SDValue combineFMALike(SDNode *N, DAGCombinerInfo &DCI) const;
891 SDValue combineTRUNCATE(SDNode *N, DAGCombinerInfo &DCI) const;
892 SDValue combineSignExtendSetCC(SDNode *N, DAGCombinerInfo &DCI) const;
893 SDValue combineSetCC(SDNode *N, DAGCombinerInfo &DCI) const;
894 SDValue combineVectorShuffle(ShuffleVectorSDNode *SVN,
895 SelectionDAG &DAG) const;
896 SDValue combineVReverseMemOP(ShuffleVectorSDNode *SVN, LSBaseSDNode *LSBase,
897 DAGCombinerInfo &DCI) const;
898
899 /// ConvertSETCCToSubtract - looks at SETCC that compares ints. It replaces
900 /// SETCC with integer subtraction when (1) there is a legal way of doing it
901 /// (2) keeping the result of comparison in GPR has performance benefit.
902 SDValue ConvertSETCCToSubtract(SDNode *N, DAGCombinerInfo &DCI) const;
903
904 SDValue getSqrtEstimate(SDValue Operand, SelectionDAG &DAG, int Enabled,
905 int &RefinementSteps, bool &UseOneConstNR,
906 bool Reciprocal) const override;
907 SDValue getRecipEstimate(SDValue Operand, SelectionDAG &DAG, int Enabled,
908 int &RefinementSteps) const override;
909 SDValue getSqrtInputTest(SDValue Operand, SelectionDAG &DAG,
910 const DenormalMode &Mode,
911 SDNodeFlags Flags = {}) const override;
912 SDValue getSqrtResultForDenormInput(SDValue Operand,
913 SelectionDAG &DAG) const override;
914 unsigned combineRepeatedFPDivisors() const override;
915
916 SDValue
917 combineElementTruncationToVectorTruncation(SDNode *N,
918 DAGCombinerInfo &DCI) const;
919
920 SDValue combineBVLoadsSpecialValue(SDValue Operand,
921 SelectionDAG &DAG) const;
922
923 /// lowerToVINSERTH - Return the SDValue if this VECTOR_SHUFFLE can be
924 /// handled by the VINSERTH instruction introduced in ISA 3.0. This is
925 /// essentially any shuffle of v8i16 vectors that just inserts one element
926 /// from one vector into the other.
927 SDValue lowerToVINSERTH(ShuffleVectorSDNode *N, SelectionDAG &DAG) const;
928
929 /// lowerToVINSERTB - Return the SDValue if this VECTOR_SHUFFLE can be
930 /// handled by the VINSERTB instruction introduced in ISA 3.0. This is
931 /// essentially v16i8 vector version of VINSERTH.
932 SDValue lowerToVINSERTB(ShuffleVectorSDNode *N, SelectionDAG &DAG) const;
933
934 /// lowerToXXSPLTI32DX - Return the SDValue if this VECTOR_SHUFFLE can be
935 /// handled by the XXSPLTI32DX instruction introduced in ISA 3.1.
936 SDValue lowerToXXSPLTI32DX(ShuffleVectorSDNode *N, SelectionDAG &DAG) const;
937
938 // Return whether the call instruction can potentially be optimized to a
939 // tail call. This will cause the optimizers to attempt to move, or
940 // duplicate return instructions to help enable tail call optimizations.
941 bool mayBeEmittedAsTailCall(const CallInst *CI) const override;
942 bool isMaskAndCmp0FoldingBeneficial(const Instruction &AndI) const override;
943
944 bool isShuffleMaskLegal(ArrayRef<int> M, EVT VT) const override;
945
946 SDValue DAGCombineBitcast(SDNode *N, DAGCombinerInfo &DCI) const;
947 SDValue GenerateVBPERM(SelectionDAG &DAG, SDLoc dl, SDValue Src, EVT SrcVT,
948 EVT ResVT, bool IsLE) const;
949
950 /// getAddrModeForFlags - Based on the set of address flags, select the most
951 /// optimal instruction format to match by.
952 PPC::AddrMode getAddrModeForFlags(unsigned Flags) const;
953
954 /// computeMOFlags - Given a node N and it's Parent (a MemSDNode), compute
955 /// the address flags of the load/store instruction that is to be matched.
956 /// The address flags are stored in a map, which is then searched
957 /// through to determine the optimal load/store instruction format.
958 unsigned computeMOFlags(const SDNode *Parent, SDValue N,
959 SelectionDAG &DAG) const;
960 }; // end class PPCTargetLowering
961
962 namespace PPC {
963
964 FastISel *createFastISel(FunctionLoweringInfo &FuncInfo,
965 const TargetLibraryInfo *LibInfo,
966 const LibcallLoweringInfo *LibcallLowering);
967
968 } // end namespace PPC
969
970 bool isIntS16Immediate(SDNode *N, int16_t &Imm);
971 bool isIntS16Immediate(SDValue Op, int16_t &Imm);
972 bool isIntS34Immediate(SDNode *N, int64_t &Imm);
973 bool isIntS34Immediate(SDValue Op, int64_t &Imm);
974
975 bool convertToNonDenormSingle(APInt &ArgAPInt);
976 bool convertToNonDenormSingle(APFloat &ArgAPFloat);
977 bool checkConvertToNonDenormSingle(APFloat &ArgAPFloat);
978
979} // end namespace llvm
980
981#endif // LLVM_LIB_TARGET_POWERPC_PPCISELLOWERING_H
982