1//===-- HexagonISelLowering.h - Hexagon 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 Hexagon uses to lower LLVM code into a
10// selection DAG.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_LIB_TARGET_HEXAGON_HEXAGONISELLOWERING_H
15#define LLVM_LIB_TARGET_HEXAGON_HEXAGONISELLOWERING_H
16
17#include "Hexagon.h"
18#include "MCTargetDesc/HexagonMCTargetDesc.h"
19#include "llvm/ADT/StringRef.h"
20#include "llvm/CodeGen/ISDOpcodes.h"
21#include "llvm/CodeGen/SelectionDAGNodes.h"
22#include "llvm/CodeGen/TargetLowering.h"
23#include "llvm/CodeGen/ValueTypes.h"
24#include "llvm/CodeGenTypes/MachineValueType.h"
25#include "llvm/IR/CallingConv.h"
26#include "llvm/IR/InlineAsm.h"
27#include <cstdint>
28#include <utility>
29
30namespace llvm {
31
32class HexagonSubtarget;
33
34class HexagonTargetLowering : public TargetLowering {
35 const HexagonTargetMachine &HTM;
36 const HexagonSubtarget &Subtarget;
37
38public:
39 explicit HexagonTargetLowering(const TargetMachine &TM,
40 const HexagonSubtarget &ST);
41
42 /// IsEligibleForTailCallOptimization - Check whether the call is eligible
43 /// for tail call optimization. Targets which want to do tail call
44 /// optimization should implement this function.
45 bool IsEligibleForTailCallOptimization(SDValue Callee,
46 CallingConv::ID CalleeCC, bool isVarArg, bool isCalleeStructRet,
47 bool isCallerStructRet, const SmallVectorImpl<ISD::OutputArg> &Outs,
48 const SmallVectorImpl<SDValue> &OutVals,
49 const SmallVectorImpl<ISD::InputArg> &Ins, SelectionDAG& DAG) const;
50
51 void getTgtMemIntrinsic(SmallVectorImpl<IntrinsicInfo> &Infos,
52 const CallBase &I, MachineFunction &MF,
53 unsigned Intrinsic) const override;
54
55 bool isTruncateFree(Type *Ty1, Type *Ty2) const override;
56 bool isTruncateFree(EVT VT1, EVT VT2) const override;
57
58 bool isCheapToSpeculateCttz(Type *) const override { return true; }
59 bool isCheapToSpeculateCtlz(Type *) const override { return true; }
60 bool isCtlzFast() const override { return true; }
61
62 bool hasBitTest(SDValue X, SDValue Y) const override;
63
64 bool allowTruncateForTailCall(Type *Ty1, Type *Ty2) const override;
65
66 bool isMaskAndCmp0FoldingBeneficial(const Instruction &AndI) const override;
67
68 bool isUsedByReturnOnly(SDNode *N, SDValue &Chain) const override;
69
70 /// Return true if an FMA operation is faster than a pair of mul and add
71 /// instructions. fmuladd intrinsics will be expanded to FMAs when this
72 /// method returns true (and FMAs are legal), otherwise fmuladd is
73 /// expanded to mul + add.
74 bool isFMAFasterThanFMulAndFAdd(const MachineFunction &,
75 EVT) const override;
76
77 // Should we expand the build vector with shuffles?
78 bool shouldExpandBuildVectorWithShuffles(EVT VT,
79 unsigned DefinedValues) const override;
80 ExtractSubvectorCost getExtractSubvectorCost(EVT ResVT, EVT SrcVT,
81 unsigned Index) const override;
82
83 bool isTargetCanonicalConstantNode(SDValue Op) const override;
84
85 bool isShuffleMaskLegal(ArrayRef<int> Mask, EVT VT) const override;
86 LegalizeTypeAction getPreferredVectorAction(MVT VT) const override;
87 LegalizeAction getCustomOperationAction(SDNode &Op) const override;
88
89 SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
90 void LowerOperationWrapper(SDNode *N, SmallVectorImpl<SDValue> &Results,
91 SelectionDAG &DAG) const override;
92 void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue> &Results,
93 SelectionDAG &DAG) const override;
94
95 std::pair<MVT, unsigned>
96 handleMaskRegisterForCallingConv(const HexagonSubtarget &Subtarget,
97 EVT VT) const;
98
99 SDValue LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG) const;
100 SDValue LowerCONCAT_VECTORS(SDValue Op, SelectionDAG &DAG) const;
101 SDValue LowerEXTRACT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) const;
102 SDValue LowerEXTRACT_SUBVECTOR(SDValue Op, SelectionDAG &DAG) const;
103 SDValue LowerINSERT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) const;
104 SDValue LowerINSERT_SUBVECTOR(SDValue Op, SelectionDAG &DAG) const;
105 SDValue LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) const;
106 SDValue LowerVECTOR_SHIFT(SDValue Op, SelectionDAG &DAG) const;
107 SDValue LowerROTL(SDValue Op, SelectionDAG &DAG) const;
108 SDValue LowerBITCAST(SDValue Op, SelectionDAG &DAG) const;
109 SDValue LowerLoad(SDValue Op, SelectionDAG &DAG) const;
110 SDValue LowerStore(SDValue Op, SelectionDAG &DAG) const;
111 SDValue LowerUnalignedLoad(SDValue Op, SelectionDAG &DAG) const;
112 SDValue LowerUAddSubO(SDValue Op, SelectionDAG &DAG) const;
113 SDValue LowerUAddSubOCarry(SDValue Op, SelectionDAG &DAG) const;
114
115 SDValue LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) const;
116 SDValue LowerFMINFMAX(SDValue Op, SelectionDAG &DAG) const;
117 SDValue LowerINLINEASM(SDValue Op, SelectionDAG &DAG) const;
118 SDValue LowerFDIV(SDValue Op, SelectionDAG &DAG) const;
119 SDValue LowerPREFETCH(SDValue Op, SelectionDAG &DAG) const;
120 SDValue LowerEH_RETURN(SDValue Op, SelectionDAG &DAG) const;
121 SDValue
122 LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
123 const SmallVectorImpl<ISD::InputArg> &Ins,
124 const SDLoc &dl, SelectionDAG &DAG,
125 SmallVectorImpl<SDValue> &InVals) const override;
126 SDValue LowerGLOBALADDRESS(SDValue Op, SelectionDAG &DAG) const;
127 SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;
128 SDValue LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const;
129 SDValue LowerToTLSGeneralDynamicModel(GlobalAddressSDNode *GA,
130 SelectionDAG &DAG) const;
131 SDValue LowerToTLSInitialExecModel(GlobalAddressSDNode *GA,
132 SelectionDAG &DAG) const;
133 SDValue LowerToTLSLocalExecModel(GlobalAddressSDNode *GA,
134 SelectionDAG &DAG) const;
135 SDValue GetDynamicTLSAddr(SelectionDAG &DAG, SDValue Chain,
136 GlobalAddressSDNode *GA, SDValue InGlue, EVT PtrVT,
137 unsigned ReturnReg, unsigned char OperandGlues) const;
138 SDValue LowerGLOBAL_OFFSET_TABLE(SDValue Op, SelectionDAG &DAG) const;
139
140 SDValue LowerCall(TargetLowering::CallLoweringInfo &CLI,
141 SmallVectorImpl<SDValue> &InVals) const override;
142 SDValue LowerCallResult(SDValue Chain, SDValue InGlue,
143 CallingConv::ID CallConv, bool isVarArg,
144 const SmallVectorImpl<ISD::InputArg> &Ins,
145 const SDLoc &dl, SelectionDAG &DAG,
146 SmallVectorImpl<SDValue> &InVals,
147 const SmallVectorImpl<SDValue> &OutVals,
148 SDValue Callee) const;
149
150 SDValue LowerSETCC(SDValue Op, SelectionDAG &DAG) const;
151 SDValue LowerVSELECT(SDValue Op, SelectionDAG &DAG) const;
152 SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
153 SDValue LowerATOMIC_FENCE(SDValue Op, SelectionDAG& DAG) const;
154 SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
155
156 bool CanLowerReturn(CallingConv::ID CallConv,
157 MachineFunction &MF, bool isVarArg,
158 const SmallVectorImpl<ISD::OutputArg> &Outs,
159 LLVMContext &Context, const Type *RetTy) const override;
160
161 SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
162 const SmallVectorImpl<ISD::OutputArg> &Outs,
163 const SmallVectorImpl<SDValue> &OutVals,
164 const SDLoc &dl, SelectionDAG &DAG) const override;
165
166 SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override;
167
168 bool mayBeEmittedAsTailCall(const CallInst *CI) const override;
169
170 Register getRegisterByName(const char* RegName, LLT VT,
171 const MachineFunction &MF) const override;
172
173 unsigned getVectorTypeBreakdownForCallingConv(LLVMContext &Context,
174 CallingConv::ID CC, EVT VT,
175 EVT &IntermediateVT,
176 unsigned &NumIntermediates,
177 MVT &RegisterVT) const override;
178
179 MVT getRegisterTypeForCallingConv(LLVMContext &Context, CallingConv::ID CC,
180 EVT VT) const override;
181 /// If a physical register, this returns the register that receives the
182 /// exception address on entry to an EH pad.
183 Register
184 getExceptionPointerRegister(ExceptionHandling EH,
185 const Constant *PersonalityFn) const override {
186 return Hexagon::R0;
187 }
188
189 /// If a physical register, this returns the register that receives the
190 /// exception typeid on entry to a landing pad.
191 Register
192 getExceptionSelectorRegister(ExceptionHandling EH,
193 const Constant *PersonalityFn) const override {
194 return Hexagon::R1;
195 }
196
197 SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const;
198 SDValue LowerVACOPY(SDValue Op, SelectionDAG &DAG) const;
199 SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const;
200 SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) const;
201
202 EVT getSetCCResultType(const DataLayout &, LLVMContext &C,
203 EVT VT) const override {
204 if (!VT.isVector())
205 return MVT::i1;
206 else
207 return EVT::getVectorVT(Context&: C, VT: MVT::i1, NumElements: VT.getVectorNumElements());
208 }
209
210 bool getPostIndexedAddressParts(SDNode *N, SDNode *Op,
211 SDValue &Base, SDValue &Offset,
212 ISD::MemIndexedMode &AM,
213 SelectionDAG &DAG) const override;
214
215 ConstraintType getConstraintType(StringRef Constraint) const override;
216
217 std::pair<unsigned, const TargetRegisterClass *>
218 getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
219 StringRef Constraint, MVT VT) const override;
220
221 // Intrinsics
222 SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const;
223 SDValue LowerINTRINSIC_VOID(SDValue Op, SelectionDAG &DAG) const;
224 /// isLegalAddressingMode - Return true if the addressing mode represented
225 /// by AM is legal for this target, for a load/store of the specified type.
226 /// The type may be VoidTy, in which case only return true if the addressing
227 /// mode is legal for a load/store of any legal type.
228 /// TODO: Handle pre/postinc as well.
229 bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM,
230 Type *Ty, unsigned AS,
231 Instruction *I = nullptr) const override;
232 /// Return true if folding a constant offset with the given GlobalAddress
233 /// is legal. It is frequently not legal in PIC relocation models.
234 bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override;
235
236 FPImmAction getFPImmAction(const APFloat &Imm, EVT VT,
237 bool ForCodeSize) const override;
238
239 /// isLegalICmpImmediate - Return true if the specified immediate is legal
240 /// icmp immediate, that is the target has icmp instructions which can
241 /// compare a register against the immediate without having to materialize
242 /// the immediate into a register.
243 bool isLegalICmpImmediate(int64_t Imm) const override;
244
245 EVT getOptimalMemOpType(LLVMContext &Context, const MemOp &Op,
246 const AttributeList &FuncAttributes) const override;
247
248 bool allowsMemoryAccess(LLVMContext &Context, const DataLayout &DL, EVT VT,
249 unsigned AddrSpace, Align Alignment,
250 MachineMemOperand::Flags Flags,
251 unsigned *Fast) const override;
252
253 bool allowsMisalignedMemoryAccesses(EVT VT, unsigned AddrSpace,
254 Align Alignment,
255 MachineMemOperand::Flags Flags,
256 unsigned *Fast) const override;
257
258 /// Returns relocation base for the given PIC jumptable.
259 SDValue getPICJumpTableRelocBase(SDValue Table, SelectionDAG &DAG)
260 const override;
261
262 /// Returns true if it is beneficial to convert a load of a constant
263 /// to just the constant itself.
264 bool shouldConvertConstantLoadToIntImm(const APInt &Imm,
265 Type *Ty) const override;
266
267 bool shouldReduceLoadWidth(SDNode *Load, ISD::LoadExtType ExtTy, EVT NewVT,
268 std::optional<unsigned> ByteOffset) const override;
269
270 void AdjustInstrPostInstrSelection(MachineInstr &MI,
271 SDNode *Node) const override;
272
273 // Handling of atomic RMW instructions.
274 Value *emitLoadLinked(IRBuilderBase &Builder, Type *ValueTy, Value *Addr,
275 AtomicOrdering Ord) const override;
276 Value *emitStoreConditional(IRBuilderBase &Builder, Value *Val, Value *Addr,
277 AtomicOrdering Ord) const override;
278 AtomicExpansionKind shouldExpandAtomicLoadInIR(LoadInst *LI) const override;
279 AtomicExpansionKind shouldExpandAtomicStoreInIR(StoreInst *SI) const override;
280 AtomicExpansionKind
281 shouldExpandAtomicCmpXchgInIR(const AtomicCmpXchgInst *AI) const override;
282
283 AtomicExpansionKind
284 shouldExpandAtomicRMWInIR(const AtomicRMWInst *AI) const override {
285 return AtomicExpansionKind::LLSC;
286 }
287
288 MachineBasicBlock *
289 EmitInstrWithCustomInserter(MachineInstr &MI,
290 MachineBasicBlock *BB) const override;
291
292 bool supportKCFIBundles() const override { return true; }
293
294 MachineInstr *EmitKCFICheck(MachineBasicBlock &MBB,
295 MachineBasicBlock::instr_iterator &MBBI,
296 const TargetInstrInfo *TII) const override;
297
298 bool hasInlineStackProbe(const MachineFunction &MF) const override;
299 unsigned getStackProbeSize(const MachineFunction &MF, Align StackAlign) const;
300
301private:
302 void initializeHVXLowering();
303 unsigned getPreferredHvxVectorAction(MVT VecTy) const;
304 unsigned getCustomHvxOperationAction(SDNode &Op) const;
305
306 bool validateConstPtrAlignment(SDValue Ptr, Align NeedAlign, const SDLoc &dl,
307 SelectionDAG &DAG) const;
308 SDValue replaceMemWithUndef(SDValue Op, SelectionDAG &DAG) const;
309
310 std::pair<SDValue,int> getBaseAndOffset(SDValue Addr) const;
311
312 bool getBuildVectorConstInts(ArrayRef<SDValue> Values, MVT VecTy,
313 SelectionDAG &DAG,
314 MutableArrayRef<ConstantInt*> Consts) const;
315 SDValue buildVector32(ArrayRef<SDValue> Elem, const SDLoc &dl, MVT VecTy,
316 SelectionDAG &DAG) const;
317 SDValue buildVector64(ArrayRef<SDValue> Elem, const SDLoc &dl, MVT VecTy,
318 SelectionDAG &DAG) const;
319 SDValue extractVector(SDValue VecV, SDValue IdxV, const SDLoc &dl,
320 MVT ValTy, MVT ResTy, SelectionDAG &DAG) const;
321 SDValue extractVectorPred(SDValue VecV, SDValue IdxV, const SDLoc &dl,
322 MVT ValTy, MVT ResTy, SelectionDAG &DAG) const;
323 SDValue insertVector(SDValue VecV, SDValue ValV, SDValue IdxV,
324 const SDLoc &dl, MVT ValTy, SelectionDAG &DAG) const;
325 SDValue insertVectorPred(SDValue VecV, SDValue ValV, SDValue IdxV,
326 const SDLoc &dl, MVT ValTy, SelectionDAG &DAG) const;
327 SDValue expandPredicate(SDValue Vec32, const SDLoc &dl,
328 SelectionDAG &DAG) const;
329 SDValue contractPredicate(SDValue Vec64, const SDLoc &dl,
330 SelectionDAG &DAG) const;
331 SDValue getSplatValue(SDValue Op, SelectionDAG &DAG) const;
332 SDValue getVectorShiftByInt(SDValue Op, SelectionDAG &DAG) const;
333 SDValue appendUndef(SDValue Val, MVT ResTy, SelectionDAG &DAG) const;
334 SDValue getCombine(SDValue Hi, SDValue Lo, const SDLoc &dl, MVT ResTy,
335 SelectionDAG &DAG) const;
336
337 bool isUndef(SDValue Op) const {
338 if (Op.isMachineOpcode())
339 return Op.getMachineOpcode() == TargetOpcode::IMPLICIT_DEF;
340 return Op.getOpcode() == ISD::UNDEF;
341 }
342 SDValue getInstr(unsigned MachineOpc, const SDLoc &dl, MVT Ty,
343 ArrayRef<SDValue> Ops, SelectionDAG &DAG) const {
344 SDNode *N = DAG.getMachineNode(Opcode: MachineOpc, dl, VT: Ty, Ops);
345 return SDValue(N, 0);
346 }
347 SDValue getZero(const SDLoc &dl, MVT Ty, SelectionDAG &DAG) const;
348
349 using VectorPair = std::pair<SDValue, SDValue>;
350 using TypePair = std::pair<MVT, MVT>;
351
352 SDValue getInt(unsigned IntId, MVT ResTy, ArrayRef<SDValue> Ops,
353 const SDLoc &dl, SelectionDAG &DAG) const;
354
355 MVT ty(SDValue Op) const {
356 return Op.getValueType().getSimpleVT();
357 }
358 TypePair ty(const VectorPair &Ops) const {
359 return { Ops.first.getValueType().getSimpleVT(),
360 Ops.second.getValueType().getSimpleVT() };
361 }
362 MVT tyScalar(MVT Ty) const {
363 if (!Ty.isVector())
364 return Ty;
365 return MVT::getIntegerVT(BitWidth: Ty.getSizeInBits());
366 }
367 MVT tyVector(MVT Ty, MVT ElemTy) const {
368 if (Ty.isVectorOf(EltVT: ElemTy))
369 return Ty;
370 unsigned TyWidth = Ty.getSizeInBits();
371 unsigned ElemWidth = ElemTy.getSizeInBits();
372 assert((TyWidth % ElemWidth) == 0);
373 return MVT::getVectorVT(VT: ElemTy, NumElements: TyWidth/ElemWidth);
374 }
375
376 MVT typeJoin(const TypePair &Tys) const;
377 TypePair typeSplit(MVT Ty) const;
378 MVT typeExtElem(MVT VecTy, unsigned Factor) const;
379 MVT typeTruncElem(MVT VecTy, unsigned Factor) const;
380 TypePair typeExtendToWider(MVT Ty0, MVT Ty1) const;
381 TypePair typeWidenToWider(MVT Ty0, MVT Ty1) const;
382 MVT typeLegalize(MVT Ty, SelectionDAG &DAG) const;
383 MVT typeWidenToHvx(MVT Ty) const;
384
385 SDValue opJoin(const VectorPair &Ops, const SDLoc &dl,
386 SelectionDAG &DAG) const;
387 VectorPair opSplit(SDValue Vec, const SDLoc &dl, SelectionDAG &DAG) const;
388 SDValue opCastElem(SDValue Vec, MVT ElemTy, SelectionDAG &DAG) const;
389
390 SDValue LoHalf(SDValue V, SelectionDAG &DAG) const {
391 MVT Ty = ty(Op: V);
392 const SDLoc &dl(V);
393 if (!Ty.isVector()) {
394 assert(Ty.getSizeInBits() == 64);
395 return DAG.getTargetExtractSubreg(SRIdx: Hexagon::isub_lo, DL: dl, VT: MVT::i32, Operand: V);
396 }
397 MVT HalfTy = typeSplit(Ty).first;
398 SDValue Idx = getZero(dl, Ty: MVT::i32, DAG);
399 return DAG.getNode(Opcode: ISD::EXTRACT_SUBVECTOR, DL: dl, VT: HalfTy, N1: V, N2: Idx);
400 }
401 SDValue HiHalf(SDValue V, SelectionDAG &DAG) const {
402 MVT Ty = ty(Op: V);
403 const SDLoc &dl(V);
404 if (!Ty.isVector()) {
405 assert(Ty.getSizeInBits() == 64);
406 return DAG.getTargetExtractSubreg(SRIdx: Hexagon::isub_hi, DL: dl, VT: MVT::i32, Operand: V);
407 }
408 MVT HalfTy = typeSplit(Ty).first;
409 SDValue Idx = DAG.getConstant(Val: HalfTy.getVectorNumElements(), DL: dl, VT: MVT::i32);
410 return DAG.getNode(Opcode: ISD::EXTRACT_SUBVECTOR, DL: dl, VT: HalfTy, N1: V, N2: Idx);
411 }
412
413 bool allowsHvxMemoryAccess(MVT VecTy, MachineMemOperand::Flags Flags,
414 unsigned *Fast) const;
415 bool allowsHvxMisalignedMemoryAccesses(MVT VecTy,
416 MachineMemOperand::Flags Flags,
417 unsigned *Fast) const;
418 void AdjustHvxInstrPostInstrSelection(MachineInstr &MI, SDNode *Node) const;
419
420 bool isHvxSingleTy(MVT Ty) const;
421 bool isHvxPairTy(MVT Ty) const;
422 bool isHvxBoolTy(MVT Ty) const;
423 SDValue convertToByteIndex(SDValue ElemIdx, MVT ElemTy,
424 SelectionDAG &DAG) const;
425 SDValue getIndexInWord32(SDValue Idx, MVT ElemTy, SelectionDAG &DAG) const;
426 SDValue getByteShuffle(const SDLoc &dl, SDValue Op0, SDValue Op1,
427 ArrayRef<int> Mask, SelectionDAG &DAG) const;
428
429 SDValue buildHvxVectorReg(ArrayRef<SDValue> Values, const SDLoc &dl,
430 MVT VecTy, SelectionDAG &DAG) const;
431 SDValue buildHvxVectorPred(ArrayRef<SDValue> Values, const SDLoc &dl,
432 MVT VecTy, SelectionDAG &DAG) const;
433 SDValue createHvxPrefixPred(SDValue PredV, const SDLoc &dl,
434 unsigned BitBytes, bool ZeroFill,
435 SelectionDAG &DAG) const;
436 SDValue extractHvxElementReg(SDValue VecV, SDValue IdxV, const SDLoc &dl,
437 MVT ResTy, SelectionDAG &DAG) const;
438 SDValue extractHvxElementPred(SDValue VecV, SDValue IdxV, const SDLoc &dl,
439 MVT ResTy, SelectionDAG &DAG) const;
440 SDValue insertHvxElementReg(SDValue VecV, SDValue IdxV, SDValue ValV,
441 const SDLoc &dl, SelectionDAG &DAG) const;
442 SDValue insertHvxElementPred(SDValue VecV, SDValue IdxV, SDValue ValV,
443 const SDLoc &dl, SelectionDAG &DAG) const;
444 SDValue extractHvxSubvectorReg(SDValue OrigOp, SDValue VecV, SDValue IdxV,
445 const SDLoc &dl, MVT ResTy, SelectionDAG &DAG)
446 const;
447 SDValue extractHvxSubvectorPred(SDValue VecV, SDValue IdxV, const SDLoc &dl,
448 MVT ResTy, SelectionDAG &DAG) const;
449 SDValue insertHvxSubvectorReg(SDValue VecV, SDValue SubV, SDValue IdxV,
450 const SDLoc &dl, SelectionDAG &DAG) const;
451 SDValue insertHvxSubvectorPred(SDValue VecV, SDValue SubV, SDValue IdxV,
452 const SDLoc &dl, SelectionDAG &DAG) const;
453 SDValue extendHvxVectorPred(SDValue VecV, const SDLoc &dl, MVT ResTy,
454 bool ZeroExt, SelectionDAG &DAG) const;
455 SDValue compressHvxPred(SDValue VecQ, const SDLoc &dl, MVT ResTy,
456 SelectionDAG &DAG) const;
457 SDValue resizeToWidth(SDValue VecV, MVT ResTy, bool Signed, const SDLoc &dl,
458 SelectionDAG &DAG) const;
459 SDValue extractSubvector(SDValue Vec, MVT SubTy, unsigned SubIdx,
460 SelectionDAG &DAG) const;
461 VectorPair emitHvxAddWithOverflow(SDValue A, SDValue B, const SDLoc &dl,
462 bool Signed, SelectionDAG &DAG) const;
463 VectorPair emitHvxShiftRightRnd(SDValue Val, unsigned Amt, bool Signed,
464 SelectionDAG &DAG) const;
465 SDValue emitHvxMulHsV60(SDValue A, SDValue B, const SDLoc &dl,
466 SelectionDAG &DAG) const;
467 SDValue emitHvxMulLoHiV60(SDValue A, bool SignedA, SDValue B, bool SignedB,
468 const SDLoc &dl, SelectionDAG &DAG) const;
469 SDValue emitHvxMulLoHiV62(SDValue A, bool SignedA, SDValue B, bool SignedB,
470 const SDLoc &dl, SelectionDAG &DAG) const;
471
472 SDValue LowerHvxBuildVector(SDValue Op, SelectionDAG &DAG) const;
473 SDValue LowerHvxSplatVector(SDValue Op, SelectionDAG &DAG) const;
474 SDValue LowerHvxConcatVectors(SDValue Op, SelectionDAG &DAG) const;
475 SDValue LowerHvxExtractElement(SDValue Op, SelectionDAG &DAG) const;
476 SDValue LowerHvxInsertElement(SDValue Op, SelectionDAG &DAG) const;
477 SDValue LowerHvxExtractSubvector(SDValue Op, SelectionDAG &DAG) const;
478 SDValue LowerHvxInsertSubvector(SDValue Op, SelectionDAG &DAG) const;
479 SDValue LowerHvxBitcast(SDValue Op, SelectionDAG &DAG) const;
480 SDValue LowerHvxAnyExt(SDValue Op, SelectionDAG &DAG) const;
481 SDValue LowerHvxSignExt(SDValue Op, SelectionDAG &DAG) const;
482 SDValue LowerHvxZeroExt(SDValue Op, SelectionDAG &DAG) const;
483 SDValue LowerHvxCttz(SDValue Op, SelectionDAG &DAG) const;
484 SDValue LowerHvxMulh(SDValue Op, SelectionDAG &DAG) const;
485 SDValue LowerHvxMulLoHi(SDValue Op, SelectionDAG &DAG) const;
486 SDValue LowerHvxExtend(SDValue Op, SelectionDAG &DAG) const;
487 SDValue LowerHvxSelect(SDValue Op, SelectionDAG &DAG) const;
488 SDValue LowerHvxShift(SDValue Op, SelectionDAG &DAG) const;
489 SDValue LowerHvxFunnelShift(SDValue Op, SelectionDAG &DAG) const;
490 SDValue LowerHvxIntrinsic(SDValue Op, SelectionDAG &DAG) const;
491 SDValue LowerHvxMaskedOp(SDValue Op, SelectionDAG &DAG) const;
492 SDValue LowerHvxFpExtend(SDValue Op, SelectionDAG &DAG) const;
493 SDValue LowerHvxFpToInt(SDValue Op, SelectionDAG &DAG) const;
494 SDValue LowerHvxIntToFp(SDValue Op, SelectionDAG &DAG) const;
495 SDValue LowerHvxPred32ToFp(SDValue Op, SelectionDAG &DAG) const;
496 SDValue LowerHvxPred64ToFp(SDValue Op, SelectionDAG &DAG) const;
497 SDValue LowerHvxPartialReduceMLA(SDValue Op, SelectionDAG &DAG) const;
498 SDValue LowerHvxFpSetoeq(SDValue Op, SelectionDAG &DAG) const;
499 SDValue LowerHvxVecReduceFMinMax(SDValue Op, unsigned PairwiseOpc,
500 bool IgnoreNaN, SelectionDAG &DAG) const;
501 SDValue LowerHvxVecReduceFMin(SDValue Op, SelectionDAG &DAG) const;
502 SDValue LowerHvxVecReduceFMax(SDValue Op, SelectionDAG &DAG) const;
503 SDValue LowerHvxVecReduceFMinimum(SDValue Op, SelectionDAG &DAG) const;
504 SDValue LowerHvxVecReduceFMaximum(SDValue Op, SelectionDAG &DAG) const;
505 SDValue LowerHvxFMinNum(SDValue Op, SelectionDAG &DAG) const;
506 SDValue LowerHvxFMaxNum(SDValue Op, SelectionDAG &DAG) const;
507 SDValue ExpandHvxFpToInt(SDValue Op, SelectionDAG &DAG) const;
508 SDValue ExpandHvxIntToFp(SDValue Op, SelectionDAG &DAG) const;
509 SDValue LowerHvxStore(SDValue Op, SelectionDAG &DAG) const;
510 SDValue LowerHvxLoad(SDValue Op, SelectionDAG &DAG) const;
511
512 VectorPair SplitVectorOp(SDValue Op, SelectionDAG &DAG) const;
513
514 SDValue SplitHvxMemOp(SDValue Op, SelectionDAG &DAG) const;
515 SDValue WidenHvxLoad(SDValue Op, SelectionDAG &DAG) const;
516 SDValue WidenHvxStore(SDValue Op, SelectionDAG &DAG) const;
517 SDValue WidenHvxSetCC(SDValue Op, SelectionDAG &DAG) const;
518 SDValue LegalizeHvxResize(SDValue Op, SelectionDAG &DAG) const;
519 SDValue ExpandHvxResizeIntoSteps(SDValue Op, SelectionDAG &DAG) const;
520 SDValue EqualizeFpIntConversion(SDValue Op, SelectionDAG &DAG) const;
521
522 SDValue CreateTLWrapper(SDValue Op, SelectionDAG &DAG) const;
523 SDValue RemoveTLWrapper(SDValue Op, SelectionDAG &DAG) const;
524 SDValue WidenHvxTruncateToBool(SDValue Op, SelectionDAG &DAG) const;
525
526 std::pair<const TargetRegisterClass*, uint8_t>
527 findRepresentativeClass(const TargetRegisterInfo *TRI, MVT VT)
528 const override;
529
530 bool shouldSplitToHvx(MVT Ty, SelectionDAG &DAG) const;
531 bool shouldWidenToHvx(MVT Ty, SelectionDAG &DAG) const;
532 bool isHvxOperation(SDNode *N, SelectionDAG &DAG) const;
533 SDValue LowerHvxOperation(SDValue Op, SelectionDAG &DAG) const;
534 void LowerHvxOperationWrapper(SDNode *N, SmallVectorImpl<SDValue> &Results,
535 SelectionDAG &DAG) const;
536 void ReplaceHvxNodeResults(SDNode *N, SmallVectorImpl<SDValue> &Results,
537 SelectionDAG &DAG) const;
538
539 void initializeHLXLowering();
540 bool isHlxSingleTy(MVT Ty) const;
541 bool isHlxPairTy(MVT Ty) const;
542 bool isHlxOperation(SDNode *N, SelectionDAG &DAG) const;
543 bool allowsHlxMemoryAccess(MVT VecTy, MachineMemOperand::Flags Flags,
544 unsigned *Fast) const;
545 TypePair typeHlxSplit(MVT VecTy) const;
546 SDValue splitHlxPairArgLoad(SelectionDAG &DAG, const SDLoc &dl, SDValue Chain,
547 SDValue BaseAddr, MVT PairTy,
548 MachinePointerInfo PtrInfo) const;
549 void splitHlxPairArgStore(SelectionDAG &DAG, const SDLoc &dl, SDValue Chain,
550 SDValue StoreVal, SDValue BaseAddr, MVT PairTy,
551 MachinePointerInfo PtrInfo,
552 SmallVectorImpl<SDValue> &MemOpChains) const;
553 SDValue LowerHlxPairIntrinsic(SDValue Op, SelectionDAG &DAG) const;
554 SDValue LowerHlxMaskedOp(SDValue Op, SelectionDAG &DAG) const;
555 SDValue LowerHlxSelect(SDValue Op, SelectionDAG &DAG) const;
556 SDValue LowerHlxOperation(SDValue Op, SelectionDAG &DAG) const;
557
558 SDValue combineTruncateBeforeLegal(SDValue Op, DAGCombinerInfo &DCI) const;
559
560 SDValue combineConcatOfShuffles(SDValue Op, SelectionDAG &DAG) const;
561 SDValue combineConcatOfScalarPreds(SDValue Op, unsigned BitBytes,
562 SelectionDAG &DAG) const;
563 SDValue combineConcatVectorsBeforeLegal(SDValue Op, DAGCombinerInfo & DCI)
564 const;
565 SDValue expandVecReduceAdd(SDNode *N, SelectionDAG &DAG) const;
566 SDValue createExtendingPartialReduceMLA(
567 unsigned Opcode, EVT AccEltType, unsigned AccNumElements, EVT InputType,
568 const SDValue &A, const SDValue &B, unsigned &RemainingReductionRatio,
569 const SDLoc &DL, SelectionDAG &DAG) const;
570 SDValue splitVecReduceAdd(SDNode *N, SelectionDAG &DAG) const;
571 SDValue splitExtendingPartialReduceMLA(SDNode *N, SelectionDAG &DAG) const;
572 SDValue PerformHvxDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const;
573};
574
575} // end namespace llvm
576
577#endif // LLVM_LIB_TARGET_HEXAGON_HEXAGONISELLOWERING_H
578