blob: e4a9961a1bee4580df3c5f1944f575d1246b94c5 [file] [log] [blame]
Jia Liub22310f2012-02-18 12:03:15 +00001//===-- HexagonISelLowering.h - Hexagon DAG Lowering Interface --*- C++ -*-===//
Tony Linthicum1213a7a2011-12-12 21:14:40 +00002//
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
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000015#ifndef LLVM_LIB_TARGET_HEXAGON_HEXAGONISELLOWERING_H
16#define LLVM_LIB_TARGET_HEXAGON_HEXAGONISELLOWERING_H
Tony Linthicum1213a7a2011-12-12 21:14:40 +000017
Craig Topperb25fda92012-03-17 18:46:09 +000018#include "Hexagon.h"
Tony Linthicum1213a7a2011-12-12 21:14:40 +000019#include "llvm/CodeGen/CallingConvLower.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000020#include "llvm/IR/CallingConv.h"
Chandler Carruth802d7552012-12-04 07:12:27 +000021#include "llvm/Target/TargetLowering.h"
Tony Linthicum1213a7a2011-12-12 21:14:40 +000022
23namespace llvm {
Colin LeMahieu025f8602014-12-08 21:19:18 +000024
25// Return true when the given node fits in a positive half word.
26bool isPositiveHalfWord(SDNode *N);
27
Tony Linthicum1213a7a2011-12-12 21:14:40 +000028 namespace HexagonISD {
29 enum {
30 FIRST_NUMBER = ISD::BUILTIN_OP_END,
31
32 CONST32,
33 CONST32_GP, // For marking data present in GP.
Jyotsna Verma2ba0c0b2013-03-07 19:10:28 +000034 CONST32_Int_Real,
Sirish Pande69295b82012-05-10 20:20:25 +000035 FCONST32,
Tony Linthicum1213a7a2011-12-12 21:14:40 +000036 SETCC,
Krzysztof Parzyszek4fa2a9f2015-04-22 16:43:53 +000037 ALLOCA,
Tony Linthicum1213a7a2011-12-12 21:14:40 +000038 ARGEXTEND,
39
Colin LeMahieu60a99e62015-03-10 20:04:44 +000040 PIC_ADD,
41 AT_GOT,
42 AT_PCREL,
43
Tony Linthicum1213a7a2011-12-12 21:14:40 +000044 CMPICC, // Compare two GPR operands, set icc.
45 CMPFCC, // Compare two FP operands, set fcc.
46 BRICC, // Branch to dest on icc condition
47 BRFCC, // Branch to dest on fcc condition
48 SELECT_ICC, // Select between two values using the current ICC flags.
49 SELECT_FCC, // Select between two values using the current FCC flags.
50
51 Hi, Lo, // Hi/Lo operations, typically on a global address.
52
53 FTOI, // FP to Int within a FP register.
54 ITOF, // Int to FP within a FP register.
55
Colin LeMahieu2e3a26d2015-01-16 17:05:27 +000056 CALLv3, // A V3+ call instruction.
57 CALLv3nr, // A V3+ call instruction that doesn't return.
58 CALLR,
59
Tony Linthicum1213a7a2011-12-12 21:14:40 +000060 RET_FLAG, // Return with a flag operand.
Krzysztof Parzyszek42113342015-03-19 16:33:08 +000061 BR_JT, // Branch through jump table.
62 BARRIER, // Memory barrier.
63 JT, // Jump table.
64 CP, // Constant pool.
Colin LeMahieu777abcb2015-01-07 20:07:28 +000065 POPCOUNT,
Colin LeMahieu383c36e2014-12-05 18:24:06 +000066 COMBINE,
Colin LeMahieubd8d0f32015-03-09 18:34:05 +000067 PACKHL,
Krzysztof Parzyszek42113342015-03-19 16:33:08 +000068 VSPLATB,
69 VSPLATH,
70 SHUFFEB,
71 SHUFFEH,
72 SHUFFOB,
73 SHUFFOH,
74 VSXTBH,
75 VSXTBW,
76 VSRAW,
77 VSRAH,
78 VSRLW,
79 VSRLH,
80 VSHLW,
81 VSHLH,
82 VCMPBEQ,
83 VCMPBGT,
84 VCMPBGTU,
85 VCMPHEQ,
86 VCMPHGT,
87 VCMPHGTU,
88 VCMPWEQ,
89 VCMPWGT,
90 VCMPWGTU,
Colin LeMahieu3b6747d2015-03-10 19:40:03 +000091 INSERT_ri,
92 INSERT_rd,
93 INSERT_riv,
94 INSERT_rdv,
95 EXTRACTU_ri,
96 EXTRACTU_rd,
97 EXTRACTU_riv,
98 EXTRACTU_rdv,
Jyotsna Verma5ed51812013-05-01 21:37:34 +000099 TC_RETURN,
Colin LeMahieu68b2e052015-01-06 19:03:20 +0000100 EH_RETURN,
101 DCFETCH
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000102 };
103 }
104
Eric Christopherd737b762015-02-02 22:11:36 +0000105 class HexagonSubtarget;
106
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000107 class HexagonTargetLowering : public TargetLowering {
108 int VarArgsFrameOffset; // Frame offset to start of varargs area.
109
110 bool CanReturnSmallStruct(const Function* CalleeFn,
111 unsigned& RetSize) const;
112
Krzysztof Parzyszek42113342015-03-19 16:33:08 +0000113 void promoteLdStType(EVT VT, EVT PromotedLdStVT);
114
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000115 public:
Eric Christopherd737b762015-02-02 22:11:36 +0000116 const HexagonSubtarget *Subtarget;
117 explicit HexagonTargetLowering(const TargetMachine &TM,
118 const HexagonSubtarget &Subtarget);
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000119
120 /// IsEligibleForTailCallOptimization - Check whether the call is eligible
121 /// for tail call optimization. Targets which want to do tail call
122 /// optimization should implement this function.
123 bool
124 IsEligibleForTailCallOptimization(SDValue Callee,
125 CallingConv::ID CalleeCC,
126 bool isVarArg,
127 bool isCalleeStructRet,
128 bool isCallerStructRet,
129 const
130 SmallVectorImpl<ISD::OutputArg> &Outs,
131 const SmallVectorImpl<SDValue> &OutVals,
132 const SmallVectorImpl<ISD::InputArg> &Ins,
133 SelectionDAG& DAG) const;
134
Craig Topper906c2cd2014-04-29 07:58:16 +0000135 bool isTruncateFree(Type *Ty1, Type *Ty2) const override;
136 bool isTruncateFree(EVT VT1, EVT VT2) const override;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000137
Craig Topper906c2cd2014-04-29 07:58:16 +0000138 bool allowTruncateForTailCall(Type *Ty1, Type *Ty2) const override;
Tim Northovera4415852013-08-06 09:12:35 +0000139
Krzysztof Parzyszek42113342015-03-19 16:33:08 +0000140 // Should we expand the build vector with shuffles?
141 bool shouldExpandBuildVectorWithShuffles(EVT VT,
142 unsigned DefinedValues) const override;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000143
Krzysztof Parzyszek42113342015-03-19 16:33:08 +0000144 SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
Craig Topper906c2cd2014-04-29 07:58:16 +0000145 const char *getTargetNodeName(unsigned Opcode) const override;
Krzysztof Parzyszek42113342015-03-19 16:33:08 +0000146 SDValue LowerCONCAT_VECTORS(SDValue Op, SelectionDAG &DAG) const;
147 SDValue LowerEXTRACT_VECTOR(SDValue Op, SelectionDAG &DAG) const;
148 SDValue LowerINSERT_VECTOR(SDValue Op, SelectionDAG &DAG) const;
149 SDValue LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG) const;
150 SDValue LowerBR_JT(SDValue Op, SelectionDAG &DAG) const;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000151 SDValue LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) const;
152 SDValue LowerINLINEASM(SDValue Op, SelectionDAG &DAG) const;
153 SDValue LowerEH_LABEL(SDValue Op, SelectionDAG &DAG) const;
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000154 SDValue LowerEH_RETURN(SDValue Op, SelectionDAG &DAG) const;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000155 SDValue LowerFormalArguments(SDValue Chain,
156 CallingConv::ID CallConv, bool isVarArg,
157 const SmallVectorImpl<ISD::InputArg> &Ins,
Andrew Trickef9de2a2013-05-25 02:42:55 +0000158 SDLoc dl, SelectionDAG &DAG,
Craig Topper906c2cd2014-04-29 07:58:16 +0000159 SmallVectorImpl<SDValue> &InVals) const override;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000160 SDValue LowerGLOBALADDRESS(SDValue Op, SelectionDAG &DAG) const;
Jyotsna Verma2ba0c0b2013-03-07 19:10:28 +0000161 SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000162
Justin Holewinskiaa583972012-05-25 16:35:28 +0000163 SDValue LowerCall(TargetLowering::CallLoweringInfo &CLI,
Craig Topper906c2cd2014-04-29 07:58:16 +0000164 SmallVectorImpl<SDValue> &InVals) const override;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000165
166 SDValue LowerCallResult(SDValue Chain, SDValue InFlag,
167 CallingConv::ID CallConv, bool isVarArg,
168 const SmallVectorImpl<ISD::InputArg> &Ins,
Andrew Trickef9de2a2013-05-25 02:42:55 +0000169 SDLoc dl, SelectionDAG &DAG,
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000170 SmallVectorImpl<SDValue> &InVals,
171 const SmallVectorImpl<SDValue> &OutVals,
172 SDValue Callee) const;
173
Krzysztof Parzyszek42113342015-03-19 16:33:08 +0000174 SDValue LowerSETCC(SDValue Op, SelectionDAG &DAG) const;
175 SDValue LowerVSELECT(SDValue Op, SelectionDAG &DAG) const;
176 SDValue LowerCTPOP(SDValue Op, SelectionDAG &DAG) const;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000177 SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000178 SDValue LowerATOMIC_FENCE(SDValue Op, SelectionDAG& DAG) const;
179 SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
Krzysztof Parzyszek42113342015-03-19 16:33:08 +0000180 SDValue LowerLOAD(SDValue Op, SelectionDAG &DAG) const;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000181
182 SDValue LowerReturn(SDValue Chain,
183 CallingConv::ID CallConv, bool isVarArg,
184 const SmallVectorImpl<ISD::OutputArg> &Outs,
185 const SmallVectorImpl<SDValue> &OutVals,
Craig Topper906c2cd2014-04-29 07:58:16 +0000186 SDLoc dl, SelectionDAG &DAG) const override;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000187
Craig Topper906c2cd2014-04-29 07:58:16 +0000188 MachineBasicBlock *
189 EmitInstrWithCustomInserter(MachineInstr *MI,
190 MachineBasicBlock *BB) const override;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000191
192 SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const;
Sirish Pande69295b82012-05-10 20:20:25 +0000193 SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const;
Craig Topper906c2cd2014-04-29 07:58:16 +0000194 EVT getSetCCResultType(LLVMContext &C, EVT VT) const override {
Juergen Ributzka34c652d2013-11-13 01:57:54 +0000195 if (!VT.isVector())
196 return MVT::i1;
197 else
198 return EVT::getVectorVT(C, MVT::i1, VT.getVectorNumElements());
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000199 }
200
Craig Topper906c2cd2014-04-29 07:58:16 +0000201 bool getPostIndexedAddressParts(SDNode *N, SDNode *Op,
202 SDValue &Base, SDValue &Offset,
203 ISD::MemIndexedMode &AM,
204 SelectionDAG &DAG) const override;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000205
Eric Christopher11e4df72015-02-26 22:38:43 +0000206 std::pair<unsigned, const TargetRegisterClass *>
207 getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
208 const std::string &Constraint,
Craig Topper906c2cd2014-04-29 07:58:16 +0000209 MVT VT) const override;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000210
Daniel Sandersbf5b80f2015-03-16 13:13:41 +0000211 unsigned getInlineAsmMemConstraint(
212 const std::string &ConstraintCode) const override {
Daniel Sanders49f643c2015-03-17 14:37:39 +0000213 if (ConstraintCode == "o")
214 return InlineAsm::Constraint_o;
215 else if (ConstraintCode == "v")
216 return InlineAsm::Constraint_v;
217 return TargetLowering::getInlineAsmMemConstraint(ConstraintCode);
Daniel Sandersbf5b80f2015-03-16 13:13:41 +0000218 }
219
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000220 // Intrinsics
Craig Topper906c2cd2014-04-29 07:58:16 +0000221 SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000222 /// isLegalAddressingMode - Return true if the addressing mode represented
223 /// by AM is legal for this target, for a load/store of the specified type.
224 /// The type may be VoidTy, in which case only return true if the addressing
225 /// mode is legal for a load/store of any legal type.
226 /// TODO: Handle pre/postinc as well.
Craig Topper906c2cd2014-04-29 07:58:16 +0000227 bool isLegalAddressingMode(const AddrMode &AM, Type *Ty) const override;
228 bool isFPImmLegal(const APFloat &Imm, EVT VT) const override;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000229
230 /// isLegalICmpImmediate - Return true if the specified immediate is legal
231 /// icmp immediate, that is the target has icmp instructions which can
232 /// compare a register against the immediate without having to materialize
233 /// the immediate into a register.
Craig Topper906c2cd2014-04-29 07:58:16 +0000234 bool isLegalICmpImmediate(int64_t Imm) const override;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000235 };
236} // end namespace llvm
237
238#endif // Hexagon_ISELLOWERING_H