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.
75 } // end namespace HexagonISD
77 class HexagonSubtarget;
79 class HexagonTargetLowering : public TargetLowering {
80 int VarArgsFrameOffset; // Frame offset to start of varargs area.
81 const HexagonTargetMachine &HTM;
82 const HexagonSubtarget &Subtarget;
84 bool CanReturnSmallStruct(const Function* CalleeFn, unsigned& RetSize)
86 void promoteLdStType(MVT VT, MVT PromotedLdStVT);
89 explicit HexagonTargetLowering(const TargetMachine &TM,
90 const HexagonSubtarget &ST);
92 /// IsEligibleForTailCallOptimization - Check whether the call is eligible
93 /// for tail call optimization. Targets which want to do tail call
94 /// optimization should implement this function.
95 bool IsEligibleForTailCallOptimization(SDValue Callee,
96 CallingConv::ID CalleeCC, bool isVarArg, bool isCalleeStructRet,
97 bool isCallerStructRet, const SmallVectorImpl<ISD::OutputArg> &Outs,
98 const SmallVectorImpl<SDValue> &OutVals,
99 const SmallVectorImpl<ISD::InputArg> &Ins, SelectionDAG& DAG) const;
101 bool isTruncateFree(Type *Ty1, Type *Ty2) const override;
102 bool isTruncateFree(EVT VT1, EVT VT2) const override;
104 bool allowTruncateForTailCall(Type *Ty1, Type *Ty2) const override;
106 /// Return true if an FMA operation is faster than a pair of mul and add
107 /// instructions. fmuladd intrinsics will be expanded to FMAs when this
108 /// method returns true (and FMAs are legal), otherwise fmuladd is
109 /// expanded to mul + add.
110 bool isFMAFasterThanFMulAndFAdd(EVT) const override;
112 // Should we expand the build vector with shuffles?
113 bool shouldExpandBuildVectorWithShuffles(EVT VT,
114 unsigned DefinedValues) const override;
116 bool isShuffleMaskLegal(const SmallVectorImpl<int> &Mask, EVT VT)
119 SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
120 const char *getTargetNodeName(unsigned Opcode) const override;
121 SDValue LowerCONCAT_VECTORS(SDValue Op, SelectionDAG &DAG) const;
122 SDValue LowerEXTRACT_VECTOR(SDValue Op, SelectionDAG &DAG) const;
123 SDValue LowerEXTRACT_SUBVECTOR_HVX(SDValue Op, SelectionDAG &DAG) const;
124 SDValue LowerINSERT_VECTOR(SDValue Op, SelectionDAG &DAG) const;
125 SDValue LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) const;
126 SDValue LowerVECTOR_SHIFT(SDValue Op, SelectionDAG &DAG) const;
127 SDValue LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG) const;
128 SDValue LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) const;
129 SDValue LowerINLINEASM(SDValue Op, SelectionDAG &DAG) const;
130 SDValue LowerPREFETCH(SDValue Op, SelectionDAG &DAG) const;
131 SDValue LowerREADCYCLECOUNTER(SDValue Op, SelectionDAG &DAG) const;
132 SDValue LowerEH_LABEL(SDValue Op, SelectionDAG &DAG) const;
133 SDValue LowerEH_RETURN(SDValue Op, SelectionDAG &DAG) const;
135 LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
136 const SmallVectorImpl<ISD::InputArg> &Ins,
137 const SDLoc &dl, SelectionDAG &DAG,
138 SmallVectorImpl<SDValue> &InVals) const override;
139 SDValue LowerGLOBALADDRESS(SDValue Op, SelectionDAG &DAG) const;
140 SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;
141 SDValue LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const;
142 SDValue LowerToTLSGeneralDynamicModel(GlobalAddressSDNode *GA,
143 SelectionDAG &DAG) const;
144 SDValue LowerToTLSInitialExecModel(GlobalAddressSDNode *GA,
145 SelectionDAG &DAG) const;
146 SDValue LowerToTLSLocalExecModel(GlobalAddressSDNode *GA,
147 SelectionDAG &DAG) const;
148 SDValue GetDynamicTLSAddr(SelectionDAG &DAG, SDValue Chain,
149 GlobalAddressSDNode *GA, SDValue InFlag, EVT PtrVT,
150 unsigned ReturnReg, unsigned char OperandFlags) const;
151 SDValue LowerGLOBAL_OFFSET_TABLE(SDValue Op, SelectionDAG &DAG) const;
153 SDValue LowerCall(TargetLowering::CallLoweringInfo &CLI,
154 SmallVectorImpl<SDValue> &InVals) const override;
155 SDValue LowerCallResult(SDValue Chain, SDValue InFlag,
156 CallingConv::ID CallConv, bool isVarArg,
157 const SmallVectorImpl<ISD::InputArg> &Ins,
158 const SDLoc &dl, SelectionDAG &DAG,
159 SmallVectorImpl<SDValue> &InVals,
160 const SmallVectorImpl<SDValue> &OutVals,
161 SDValue Callee) const;
163 SDValue LowerSETCC(SDValue Op, SelectionDAG &DAG) const;
164 SDValue LowerVSELECT(SDValue Op, SelectionDAG &DAG) const;
165 SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
166 SDValue LowerATOMIC_FENCE(SDValue Op, SelectionDAG& DAG) const;
167 SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
169 bool CanLowerReturn(CallingConv::ID CallConv,
170 MachineFunction &MF, bool isVarArg,
171 const SmallVectorImpl<ISD::OutputArg> &Outs,
172 LLVMContext &Context) const override;
174 SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
175 const SmallVectorImpl<ISD::OutputArg> &Outs,
176 const SmallVectorImpl<SDValue> &OutVals,
177 const SDLoc &dl, SelectionDAG &DAG) const override;
179 bool mayBeEmittedAsTailCall(const CallInst *CI) const override;
181 /// If a physical register, this returns the register that receives the
182 /// exception address on entry to an EH pad.
184 getExceptionPointerRegister(const Constant *PersonalityFn) const override {
188 /// If a physical register, this returns the register that receives the
189 /// exception typeid on entry to a landing pad.
191 getExceptionSelectorRegister(const Constant *PersonalityFn) const override {
195 SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const;
196 SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const;
197 SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) const;
199 EVT getSetCCResultType(const DataLayout &, LLVMContext &C,
200 EVT VT) const override {
204 return EVT::getVectorVT(C, MVT::i1, VT.getVectorNumElements());
207 bool getPostIndexedAddressParts(SDNode *N, SDNode *Op,
208 SDValue &Base, SDValue &Offset,
209 ISD::MemIndexedMode &AM,
210 SelectionDAG &DAG) const override;
212 ConstraintType getConstraintType(StringRef Constraint) const override;
214 std::pair<unsigned, const TargetRegisterClass *>
215 getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
216 StringRef Constraint, MVT VT) const override;
219 getInlineAsmMemConstraint(StringRef ConstraintCode) const override {
220 if (ConstraintCode == "o")
221 return InlineAsm::Constraint_o;
222 return TargetLowering::getInlineAsmMemConstraint(ConstraintCode);
226 SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const;
227 SDValue LowerINTRINSIC_VOID(SDValue Op, SelectionDAG &DAG) const;
228 /// isLegalAddressingMode - Return true if the addressing mode represented
229 /// by AM is legal for this target, for a load/store of the specified type.
230 /// The type may be VoidTy, in which case only return true if the addressing
231 /// mode is legal for a load/store of any legal type.
232 /// TODO: Handle pre/postinc as well.
233 bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM,
234 Type *Ty, unsigned AS) const override;
235 /// Return true if folding a constant offset with the given GlobalAddress
236 /// is legal. It is frequently not legal in PIC relocation models.
237 bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override;
239 bool isFPImmLegal(const APFloat &Imm, EVT VT) const override;
241 /// isLegalICmpImmediate - Return true if the specified immediate is legal
242 /// icmp immediate, that is the target has icmp instructions which can
243 /// compare a register against the immediate without having to materialize
244 /// the immediate into a register.
245 bool isLegalICmpImmediate(int64_t Imm) const override;
247 EVT getOptimalMemOpType(uint64_t Size, unsigned DstAlign,
248 unsigned SrcAlign, bool IsMemset, bool ZeroMemset, bool MemcpyStrSrc,
249 MachineFunction &MF) const override;
251 bool allowsMisalignedMemoryAccesses(EVT VT, unsigned AddrSpace,
252 unsigned Align, bool *Fast) const override;
254 /// Returns relocation base for the given PIC jumptable.
255 SDValue getPICJumpTableRelocBase(SDValue Table, SelectionDAG &DAG)
258 // Handling of atomic RMW instructions.
259 Value *emitLoadLinked(IRBuilder<> &Builder, Value *Addr,
260 AtomicOrdering Ord) const override;
261 Value *emitStoreConditional(IRBuilder<> &Builder, Value *Val,
262 Value *Addr, AtomicOrdering Ord) const override;
263 AtomicExpansionKind shouldExpandAtomicLoadInIR(LoadInst *LI) const override;
264 bool shouldExpandAtomicStoreInIR(StoreInst *SI) const override;
265 bool shouldExpandAtomicCmpXchgInIR(AtomicCmpXchgInst *AI) const override;
268 shouldExpandAtomicRMWInIR(AtomicRMWInst *AI) const override {
269 return AtomicExpansionKind::LLSC;
273 std::pair<const TargetRegisterClass*, uint8_t>
274 findRepresentativeClass(const TargetRegisterInfo *TRI, MVT VT)
278 } // end namespace llvm
280 #endif // LLVM_LIB_TARGET_HEXAGON_HEXAGONISELLOWERING_H