1 //===-- HexagonISelLowering.h - Hexagon 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 Hexagon uses to lower LLVM code into a
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_LIB_TARGET_HEXAGON_HEXAGONISELLOWERING_H
16 #define LLVM_LIB_TARGET_HEXAGON_HEXAGONISELLOWERING_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"
32 namespace HexagonISD {
34 enum NodeType : unsigned {
35 OP_BEGIN = ISD::BUILTIN_OP_END,
38 CONST32_GP, // For marking data present in GP.
41 AT_GOT, // Index in GOT.
42 AT_PCREL, // Offset relative to PC.
44 CALL, // Function call.
45 CALLnr, // Function call that does not return.
48 RET_FLAG, // Return with a flag operand.
49 BARRIER, // Memory barrier.
93 } // end namespace HexagonISD
95 class HexagonSubtarget;
97 class HexagonTargetLowering : public TargetLowering {
98 int VarArgsFrameOffset; // Frame offset to start of varargs area.
99 const HexagonTargetMachine &HTM;
100 const HexagonSubtarget &Subtarget;
102 bool CanReturnSmallStruct(const Function* CalleeFn, unsigned& RetSize)
104 void promoteLdStType(MVT VT, MVT PromotedLdStVT);
107 explicit HexagonTargetLowering(const TargetMachine &TM,
108 const HexagonSubtarget &ST);
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;
119 bool isTruncateFree(Type *Ty1, Type *Ty2) const override;
120 bool isTruncateFree(EVT VT1, EVT VT2) const override;
122 bool allowTruncateForTailCall(Type *Ty1, Type *Ty2) const override;
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;
130 // Should we expand the build vector with shuffles?
131 bool shouldExpandBuildVectorWithShuffles(EVT VT,
132 unsigned DefinedValues) const override;
134 bool isShuffleMaskLegal(const SmallVectorImpl<int> &Mask, EVT VT)
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;
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;
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;
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;
188 bool CanLowerReturn(CallingConv::ID CallConv,
189 MachineFunction &MF, bool isVarArg,
190 const SmallVectorImpl<ISD::OutputArg> &Outs,
191 LLVMContext &Context) const override;
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;
198 bool mayBeEmittedAsTailCall(const CallInst *CI) const override;
200 /// If a physical register, this returns the register that receives the
201 /// exception address on entry to an EH pad.
203 getExceptionPointerRegister(const Constant *PersonalityFn) const override {
207 /// If a physical register, this returns the register that receives the
208 /// exception typeid on entry to a landing pad.
210 getExceptionSelectorRegister(const Constant *PersonalityFn) const override {
214 SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const;
215 SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const;
216 SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) const;
218 EVT getSetCCResultType(const DataLayout &, LLVMContext &C,
219 EVT VT) const override {
223 return EVT::getVectorVT(C, MVT::i1, VT.getVectorNumElements());
226 bool getPostIndexedAddressParts(SDNode *N, SDNode *Op,
227 SDValue &Base, SDValue &Offset,
228 ISD::MemIndexedMode &AM,
229 SelectionDAG &DAG) const override;
231 ConstraintType getConstraintType(StringRef Constraint) const override;
233 std::pair<unsigned, const TargetRegisterClass *>
234 getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
235 StringRef Constraint, MVT VT) const override;
238 getInlineAsmMemConstraint(StringRef ConstraintCode) const override {
239 if (ConstraintCode == "o")
240 return InlineAsm::Constraint_o;
241 return TargetLowering::getInlineAsmMemConstraint(ConstraintCode);
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;
258 bool isFPImmLegal(const APFloat &Imm, EVT VT) const override;
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;
266 EVT getOptimalMemOpType(uint64_t Size, unsigned DstAlign,
267 unsigned SrcAlign, bool IsMemset, bool ZeroMemset, bool MemcpyStrSrc,
268 MachineFunction &MF) const override;
270 bool allowsMisalignedMemoryAccesses(EVT VT, unsigned AddrSpace,
271 unsigned Align, bool *Fast) const override;
273 /// Returns relocation base for the given PIC jumptable.
274 SDValue getPICJumpTableRelocBase(SDValue Table, SelectionDAG &DAG)
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;
287 shouldExpandAtomicRMWInIR(AtomicRMWInst *AI) const override {
288 return AtomicExpansionKind::LLSC;
292 std::pair<const TargetRegisterClass*, uint8_t>
293 findRepresentativeClass(const TargetRegisterInfo *TRI, MVT VT)
297 } // end namespace llvm
299 #endif // LLVM_LIB_TARGET_HEXAGON_HEXAGONISELLOWERING_H