]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/Target/Hexagon/HexagonISelLowering.h
Merge llvm, clang, lld, lldb, compiler-rt and libc++ r305575, and update
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / Target / Hexagon / HexagonISelLowering.h
1 //===-- HexagonISelLowering.h - Hexagon DAG Lowering Interface --*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the interfaces that Hexagon uses to lower LLVM code into a
11 // selection DAG.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_LIB_TARGET_HEXAGON_HEXAGONISELLOWERING_H
16 #define LLVM_LIB_TARGET_HEXAGON_HEXAGONISELLOWERING_H
17
18 #include "Hexagon.h"
19 #include "llvm/ADT/StringRef.h"
20 #include "llvm/CodeGen/ISDOpcodes.h"
21 #include "llvm/CodeGen/MachineValueType.h"
22 #include "llvm/CodeGen/SelectionDAGNodes.h"
23 #include "llvm/CodeGen/ValueTypes.h"
24 #include "llvm/IR/CallingConv.h"
25 #include "llvm/IR/InlineAsm.h"
26 #include "llvm/Target/TargetLowering.h"
27 #include <cstdint>
28 #include <utility>
29
30 namespace llvm {
31
32 namespace HexagonISD {
33
34     enum NodeType : unsigned {
35       OP_BEGIN = ISD::BUILTIN_OP_END,
36
37       CONST32 = OP_BEGIN,
38       CONST32_GP,  // For marking data present in GP.
39       ALLOCA,
40
41       AT_GOT,      // Index in GOT.
42       AT_PCREL,    // Offset relative to PC.
43
44       CALL,        // Function call.
45       CALLnr,      // Function call that does not return.
46       CALLR,
47
48       RET_FLAG,    // Return with a flag operand.
49       BARRIER,     // Memory barrier.
50       JT,          // Jump table.
51       CP,          // Constant pool.
52
53       COMBINE,
54       PACKHL,
55       VSPLATB,
56       VSPLATH,
57       SHUFFEB,
58       SHUFFEH,
59       SHUFFOB,
60       SHUFFOH,
61       VSXTBH,
62       VSXTBW,
63       VSRAW,
64       VSRAH,
65       VSRLW,
66       VSRLH,
67       VSHLW,
68       VSHLH,
69       VCMPBEQ,
70       VCMPBGT,
71       VCMPBGTU,
72       VCMPHEQ,
73       VCMPHGT,
74       VCMPHGTU,
75       VCMPWEQ,
76       VCMPWGT,
77       VCMPWGTU,
78
79       INSERT,
80       INSERTRP,
81       EXTRACTU,
82       EXTRACTURP,
83       VCOMBINE,
84       VPACK,
85       TC_RETURN,
86       EH_RETURN,
87       DCFETCH,
88       READCYCLE,
89
90       OP_END
91     };
92
93 } // end namespace HexagonISD
94
95   class HexagonSubtarget;
96
97   class HexagonTargetLowering : public TargetLowering {
98     int VarArgsFrameOffset;   // Frame offset to start of varargs area.
99     const HexagonTargetMachine &HTM;
100     const HexagonSubtarget &Subtarget;
101
102     bool CanReturnSmallStruct(const Function* CalleeFn, unsigned& RetSize)
103         const;
104     void promoteLdStType(MVT VT, MVT PromotedLdStVT);
105
106   public:
107     explicit HexagonTargetLowering(const TargetMachine &TM,
108                                    const HexagonSubtarget &ST);
109
110     /// IsEligibleForTailCallOptimization - Check whether the call is eligible
111     /// for tail call optimization. Targets which want to do tail call
112     /// optimization should implement this function.
113     bool IsEligibleForTailCallOptimization(SDValue Callee,
114         CallingConv::ID CalleeCC, bool isVarArg, bool isCalleeStructRet,
115         bool isCallerStructRet, const SmallVectorImpl<ISD::OutputArg> &Outs,
116         const SmallVectorImpl<SDValue> &OutVals,
117         const SmallVectorImpl<ISD::InputArg> &Ins, SelectionDAG& DAG) const;
118
119     bool isTruncateFree(Type *Ty1, Type *Ty2) const override;
120     bool isTruncateFree(EVT VT1, EVT VT2) const override;
121
122     bool allowTruncateForTailCall(Type *Ty1, Type *Ty2) const override;
123
124     /// Return true if an FMA operation is faster than a pair of mul and add
125     /// instructions. fmuladd intrinsics will be expanded to FMAs when this
126     /// method returns true (and FMAs are legal), otherwise fmuladd is
127     /// expanded to mul + add.
128     bool isFMAFasterThanFMulAndFAdd(EVT) const override;
129
130     // Should we expand the build vector with shuffles?
131     bool shouldExpandBuildVectorWithShuffles(EVT VT,
132         unsigned DefinedValues) const override;
133
134     bool isShuffleMaskLegal(const SmallVectorImpl<int> &Mask, EVT VT)
135         const override;
136
137     SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
138     const char *getTargetNodeName(unsigned Opcode) const override;
139     SDValue LowerCONCAT_VECTORS(SDValue Op, SelectionDAG &DAG) const;
140     SDValue LowerEXTRACT_VECTOR(SDValue Op, SelectionDAG &DAG) const;
141     SDValue LowerEXTRACT_SUBVECTOR_HVX(SDValue Op, SelectionDAG &DAG) const;
142     SDValue LowerINSERT_VECTOR(SDValue Op, SelectionDAG &DAG) const;
143     SDValue LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) const;
144     SDValue LowerVECTOR_SHIFT(SDValue Op, SelectionDAG &DAG) const;
145     SDValue LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG) const;
146     SDValue LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) const;
147     SDValue LowerINLINEASM(SDValue Op, SelectionDAG &DAG) const;
148     SDValue LowerPREFETCH(SDValue Op, SelectionDAG &DAG) const;
149     SDValue LowerREADCYCLECOUNTER(SDValue Op, SelectionDAG &DAG) const;
150     SDValue LowerEH_LABEL(SDValue Op, SelectionDAG &DAG) const;
151     SDValue LowerEH_RETURN(SDValue Op, SelectionDAG &DAG) const;
152     SDValue
153     LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
154                          const SmallVectorImpl<ISD::InputArg> &Ins,
155                          const SDLoc &dl, SelectionDAG &DAG,
156                          SmallVectorImpl<SDValue> &InVals) const override;
157     SDValue LowerGLOBALADDRESS(SDValue Op, SelectionDAG &DAG) const;
158     SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;
159     SDValue LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const;
160     SDValue LowerToTLSGeneralDynamicModel(GlobalAddressSDNode *GA,
161         SelectionDAG &DAG) const;
162     SDValue LowerToTLSInitialExecModel(GlobalAddressSDNode *GA,
163         SelectionDAG &DAG) const;
164     SDValue LowerToTLSLocalExecModel(GlobalAddressSDNode *GA,
165         SelectionDAG &DAG) const;
166     SDValue GetDynamicTLSAddr(SelectionDAG &DAG, SDValue Chain,
167         GlobalAddressSDNode *GA, SDValue InFlag, EVT PtrVT,
168         unsigned ReturnReg, unsigned char OperandFlags) const;
169     SDValue LowerGLOBAL_OFFSET_TABLE(SDValue Op, SelectionDAG &DAG) const;
170
171     SDValue LowerCall(TargetLowering::CallLoweringInfo &CLI,
172         SmallVectorImpl<SDValue> &InVals) const override;
173     SDValue LowerCallResult(SDValue Chain, SDValue InFlag,
174                             CallingConv::ID CallConv, bool isVarArg,
175                             const SmallVectorImpl<ISD::InputArg> &Ins,
176                             const SDLoc &dl, SelectionDAG &DAG,
177                             SmallVectorImpl<SDValue> &InVals,
178                             const SmallVectorImpl<SDValue> &OutVals,
179                             SDValue Callee) const;
180
181     SDValue LowerSETCC(SDValue Op, SelectionDAG &DAG) const;
182     SDValue LowerVSELECT(SDValue Op, SelectionDAG &DAG) const;
183     SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
184     SDValue LowerATOMIC_FENCE(SDValue Op, SelectionDAG& DAG) const;
185     SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
186     SDValue LowerLOAD(SDValue Op, SelectionDAG &DAG) const;
187
188     bool CanLowerReturn(CallingConv::ID CallConv,
189                         MachineFunction &MF, bool isVarArg,
190                         const SmallVectorImpl<ISD::OutputArg> &Outs,
191                         LLVMContext &Context) const override;
192
193     SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
194                         const SmallVectorImpl<ISD::OutputArg> &Outs,
195                         const SmallVectorImpl<SDValue> &OutVals,
196                         const SDLoc &dl, SelectionDAG &DAG) const override;
197
198     bool mayBeEmittedAsTailCall(const CallInst *CI) const override;
199
200     /// If a physical register, this returns the register that receives the
201     /// exception address on entry to an EH pad.
202     unsigned
203     getExceptionPointerRegister(const Constant *PersonalityFn) const override {
204       return Hexagon::R0;
205     }
206
207     /// If a physical register, this returns the register that receives the
208     /// exception typeid on entry to a landing pad.
209     unsigned
210     getExceptionSelectorRegister(const Constant *PersonalityFn) const override {
211       return Hexagon::R1;
212     }
213
214     SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const;
215     SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const;
216     SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) const;
217
218     EVT getSetCCResultType(const DataLayout &, LLVMContext &C,
219                            EVT VT) const override {
220       if (!VT.isVector())
221         return MVT::i1;
222       else
223         return EVT::getVectorVT(C, MVT::i1, VT.getVectorNumElements());
224     }
225
226     bool getPostIndexedAddressParts(SDNode *N, SDNode *Op,
227                                     SDValue &Base, SDValue &Offset,
228                                     ISD::MemIndexedMode &AM,
229                                     SelectionDAG &DAG) const override;
230
231     ConstraintType getConstraintType(StringRef Constraint) const override;
232
233     std::pair<unsigned, const TargetRegisterClass *>
234     getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
235                                  StringRef Constraint, MVT VT) const override;
236
237     unsigned
238     getInlineAsmMemConstraint(StringRef ConstraintCode) const override {
239       if (ConstraintCode == "o")
240         return InlineAsm::Constraint_o;
241       return TargetLowering::getInlineAsmMemConstraint(ConstraintCode);
242     }
243
244     // Intrinsics
245     SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const;
246     SDValue LowerINTRINSIC_VOID(SDValue Op, SelectionDAG &DAG) const;
247     /// isLegalAddressingMode - Return true if the addressing mode represented
248     /// by AM is legal for this target, for a load/store of the specified type.
249     /// The type may be VoidTy, in which case only return true if the addressing
250     /// mode is legal for a load/store of any legal type.
251     /// TODO: Handle pre/postinc as well.
252     bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM,
253                                Type *Ty, unsigned AS) const override;
254     /// Return true if folding a constant offset with the given GlobalAddress
255     /// is legal.  It is frequently not legal in PIC relocation models.
256     bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override;
257
258     bool isFPImmLegal(const APFloat &Imm, EVT VT) const override;
259
260     /// isLegalICmpImmediate - Return true if the specified immediate is legal
261     /// icmp immediate, that is the target has icmp instructions which can
262     /// compare a register against the immediate without having to materialize
263     /// the immediate into a register.
264     bool isLegalICmpImmediate(int64_t Imm) const override;
265
266     EVT getOptimalMemOpType(uint64_t Size, unsigned DstAlign,
267         unsigned SrcAlign, bool IsMemset, bool ZeroMemset, bool MemcpyStrSrc,
268         MachineFunction &MF) const override;
269
270     bool allowsMisalignedMemoryAccesses(EVT VT, unsigned AddrSpace,
271         unsigned Align, bool *Fast) const override;
272
273     /// Returns relocation base for the given PIC jumptable.
274     SDValue getPICJumpTableRelocBase(SDValue Table, SelectionDAG &DAG)
275                                      const override;
276
277     // Handling of atomic RMW instructions.
278     Value *emitLoadLinked(IRBuilder<> &Builder, Value *Addr,
279         AtomicOrdering Ord) const override;
280     Value *emitStoreConditional(IRBuilder<> &Builder, Value *Val,
281         Value *Addr, AtomicOrdering Ord) const override;
282     AtomicExpansionKind shouldExpandAtomicLoadInIR(LoadInst *LI) const override;
283     bool shouldExpandAtomicStoreInIR(StoreInst *SI) const override;
284     bool shouldExpandAtomicCmpXchgInIR(AtomicCmpXchgInst *AI) const override;
285
286     AtomicExpansionKind
287     shouldExpandAtomicRMWInIR(AtomicRMWInst *AI) const override {
288       return AtomicExpansionKind::LLSC;
289     }
290
291   protected:
292     std::pair<const TargetRegisterClass*, uint8_t>
293     findRepresentativeClass(const TargetRegisterInfo *TRI, MVT VT)
294         const override;
295   };
296
297 } // end namespace llvm
298
299 #endif // LLVM_LIB_TARGET_HEXAGON_HEXAGONISELLOWERING_H