Jia Liu | b22310f | 2012-02-18 12:03:15 +0000 | [diff] [blame] | 1 | //===-- HexagonISelLowering.h - Hexagon DAG Lowering Interface --*- C++ -*-===// |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 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 | |
Benjamin Kramer | a7c40ef | 2014-08-13 16:26:38 +0000 | [diff] [blame] | 15 | #ifndef LLVM_LIB_TARGET_HEXAGON_HEXAGONISELLOWERING_H |
| 16 | #define LLVM_LIB_TARGET_HEXAGON_HEXAGONISELLOWERING_H |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 17 | |
Craig Topper | b25fda9 | 2012-03-17 18:46:09 +0000 | [diff] [blame] | 18 | #include "Hexagon.h" |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/CallingConvLower.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 20 | #include "llvm/IR/CallingConv.h" |
Chandler Carruth | 802d755 | 2012-12-04 07:12:27 +0000 | [diff] [blame] | 21 | #include "llvm/Target/TargetLowering.h" |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 22 | |
| 23 | namespace llvm { |
Colin LeMahieu | 025f860 | 2014-12-08 21:19:18 +0000 | [diff] [blame] | 24 | |
| 25 | // Return true when the given node fits in a positive half word. |
| 26 | bool isPositiveHalfWord(SDNode *N); |
| 27 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 28 | namespace HexagonISD { |
| 29 | enum { |
| 30 | FIRST_NUMBER = ISD::BUILTIN_OP_END, |
| 31 | |
| 32 | CONST32, |
| 33 | CONST32_GP, // For marking data present in GP. |
Jyotsna Verma | 2ba0c0b | 2013-03-07 19:10:28 +0000 | [diff] [blame] | 34 | CONST32_Int_Real, |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 35 | FCONST32, |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 36 | SETCC, |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame^] | 37 | ALLOCA, |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 38 | ARGEXTEND, |
| 39 | |
Colin LeMahieu | 60a99e6 | 2015-03-10 20:04:44 +0000 | [diff] [blame] | 40 | PIC_ADD, |
| 41 | AT_GOT, |
| 42 | AT_PCREL, |
| 43 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 44 | 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 LeMahieu | 2e3a26d | 2015-01-16 17:05:27 +0000 | [diff] [blame] | 56 | CALLv3, // A V3+ call instruction. |
| 57 | CALLv3nr, // A V3+ call instruction that doesn't return. |
| 58 | CALLR, |
| 59 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 60 | RET_FLAG, // Return with a flag operand. |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 61 | BR_JT, // Branch through jump table. |
| 62 | BARRIER, // Memory barrier. |
| 63 | JT, // Jump table. |
| 64 | CP, // Constant pool. |
Colin LeMahieu | 777abcb | 2015-01-07 20:07:28 +0000 | [diff] [blame] | 65 | POPCOUNT, |
Colin LeMahieu | 383c36e | 2014-12-05 18:24:06 +0000 | [diff] [blame] | 66 | COMBINE, |
Colin LeMahieu | bd8d0f3 | 2015-03-09 18:34:05 +0000 | [diff] [blame] | 67 | PACKHL, |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 68 | 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 LeMahieu | 3b6747d | 2015-03-10 19:40:03 +0000 | [diff] [blame] | 91 | INSERT_ri, |
| 92 | INSERT_rd, |
| 93 | INSERT_riv, |
| 94 | INSERT_rdv, |
| 95 | EXTRACTU_ri, |
| 96 | EXTRACTU_rd, |
| 97 | EXTRACTU_riv, |
| 98 | EXTRACTU_rdv, |
Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 99 | TC_RETURN, |
Colin LeMahieu | 68b2e05 | 2015-01-06 19:03:20 +0000 | [diff] [blame] | 100 | EH_RETURN, |
| 101 | DCFETCH |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 102 | }; |
| 103 | } |
| 104 | |
Eric Christopher | d737b76 | 2015-02-02 22:11:36 +0000 | [diff] [blame] | 105 | class HexagonSubtarget; |
| 106 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 107 | 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 Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 113 | void promoteLdStType(EVT VT, EVT PromotedLdStVT); |
| 114 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 115 | public: |
Eric Christopher | d737b76 | 2015-02-02 22:11:36 +0000 | [diff] [blame] | 116 | const HexagonSubtarget *Subtarget; |
| 117 | explicit HexagonTargetLowering(const TargetMachine &TM, |
| 118 | const HexagonSubtarget &Subtarget); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 119 | |
| 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 Topper | 906c2cd | 2014-04-29 07:58:16 +0000 | [diff] [blame] | 135 | bool isTruncateFree(Type *Ty1, Type *Ty2) const override; |
| 136 | bool isTruncateFree(EVT VT1, EVT VT2) const override; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 137 | |
Craig Topper | 906c2cd | 2014-04-29 07:58:16 +0000 | [diff] [blame] | 138 | bool allowTruncateForTailCall(Type *Ty1, Type *Ty2) const override; |
Tim Northover | a441585 | 2013-08-06 09:12:35 +0000 | [diff] [blame] | 139 | |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 140 | // Should we expand the build vector with shuffles? |
| 141 | bool shouldExpandBuildVectorWithShuffles(EVT VT, |
| 142 | unsigned DefinedValues) const override; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 143 | |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 144 | SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override; |
Craig Topper | 906c2cd | 2014-04-29 07:58:16 +0000 | [diff] [blame] | 145 | const char *getTargetNodeName(unsigned Opcode) const override; |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 146 | 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 Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 151 | 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 Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 154 | SDValue LowerEH_RETURN(SDValue Op, SelectionDAG &DAG) const; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 155 | SDValue LowerFormalArguments(SDValue Chain, |
| 156 | CallingConv::ID CallConv, bool isVarArg, |
| 157 | const SmallVectorImpl<ISD::InputArg> &Ins, |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 158 | SDLoc dl, SelectionDAG &DAG, |
Craig Topper | 906c2cd | 2014-04-29 07:58:16 +0000 | [diff] [blame] | 159 | SmallVectorImpl<SDValue> &InVals) const override; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 160 | SDValue LowerGLOBALADDRESS(SDValue Op, SelectionDAG &DAG) const; |
Jyotsna Verma | 2ba0c0b | 2013-03-07 19:10:28 +0000 | [diff] [blame] | 161 | SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 162 | |
Justin Holewinski | aa58397 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 163 | SDValue LowerCall(TargetLowering::CallLoweringInfo &CLI, |
Craig Topper | 906c2cd | 2014-04-29 07:58:16 +0000 | [diff] [blame] | 164 | SmallVectorImpl<SDValue> &InVals) const override; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 165 | |
| 166 | SDValue LowerCallResult(SDValue Chain, SDValue InFlag, |
| 167 | CallingConv::ID CallConv, bool isVarArg, |
| 168 | const SmallVectorImpl<ISD::InputArg> &Ins, |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 169 | SDLoc dl, SelectionDAG &DAG, |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 170 | SmallVectorImpl<SDValue> &InVals, |
| 171 | const SmallVectorImpl<SDValue> &OutVals, |
| 172 | SDValue Callee) const; |
| 173 | |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 174 | SDValue LowerSETCC(SDValue Op, SelectionDAG &DAG) const; |
| 175 | SDValue LowerVSELECT(SDValue Op, SelectionDAG &DAG) const; |
| 176 | SDValue LowerCTPOP(SDValue Op, SelectionDAG &DAG) const; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 177 | SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 178 | SDValue LowerATOMIC_FENCE(SDValue Op, SelectionDAG& DAG) const; |
| 179 | SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const; |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 180 | SDValue LowerLOAD(SDValue Op, SelectionDAG &DAG) const; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 181 | |
| 182 | SDValue LowerReturn(SDValue Chain, |
| 183 | CallingConv::ID CallConv, bool isVarArg, |
| 184 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
| 185 | const SmallVectorImpl<SDValue> &OutVals, |
Craig Topper | 906c2cd | 2014-04-29 07:58:16 +0000 | [diff] [blame] | 186 | SDLoc dl, SelectionDAG &DAG) const override; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 187 | |
Craig Topper | 906c2cd | 2014-04-29 07:58:16 +0000 | [diff] [blame] | 188 | MachineBasicBlock * |
| 189 | EmitInstrWithCustomInserter(MachineInstr *MI, |
| 190 | MachineBasicBlock *BB) const override; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 191 | |
| 192 | SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const; |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 193 | SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const; |
Craig Topper | 906c2cd | 2014-04-29 07:58:16 +0000 | [diff] [blame] | 194 | EVT getSetCCResultType(LLVMContext &C, EVT VT) const override { |
Juergen Ributzka | 34c652d | 2013-11-13 01:57:54 +0000 | [diff] [blame] | 195 | if (!VT.isVector()) |
| 196 | return MVT::i1; |
| 197 | else |
| 198 | return EVT::getVectorVT(C, MVT::i1, VT.getVectorNumElements()); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 199 | } |
| 200 | |
Craig Topper | 906c2cd | 2014-04-29 07:58:16 +0000 | [diff] [blame] | 201 | bool getPostIndexedAddressParts(SDNode *N, SDNode *Op, |
| 202 | SDValue &Base, SDValue &Offset, |
| 203 | ISD::MemIndexedMode &AM, |
| 204 | SelectionDAG &DAG) const override; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 205 | |
Eric Christopher | 11e4df7 | 2015-02-26 22:38:43 +0000 | [diff] [blame] | 206 | std::pair<unsigned, const TargetRegisterClass *> |
| 207 | getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI, |
| 208 | const std::string &Constraint, |
Craig Topper | 906c2cd | 2014-04-29 07:58:16 +0000 | [diff] [blame] | 209 | MVT VT) const override; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 210 | |
Daniel Sanders | bf5b80f | 2015-03-16 13:13:41 +0000 | [diff] [blame] | 211 | unsigned getInlineAsmMemConstraint( |
| 212 | const std::string &ConstraintCode) const override { |
Daniel Sanders | 49f643c | 2015-03-17 14:37:39 +0000 | [diff] [blame] | 213 | if (ConstraintCode == "o") |
| 214 | return InlineAsm::Constraint_o; |
| 215 | else if (ConstraintCode == "v") |
| 216 | return InlineAsm::Constraint_v; |
| 217 | return TargetLowering::getInlineAsmMemConstraint(ConstraintCode); |
Daniel Sanders | bf5b80f | 2015-03-16 13:13:41 +0000 | [diff] [blame] | 218 | } |
| 219 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 220 | // Intrinsics |
Craig Topper | 906c2cd | 2014-04-29 07:58:16 +0000 | [diff] [blame] | 221 | SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 222 | /// 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 Topper | 906c2cd | 2014-04-29 07:58:16 +0000 | [diff] [blame] | 227 | bool isLegalAddressingMode(const AddrMode &AM, Type *Ty) const override; |
| 228 | bool isFPImmLegal(const APFloat &Imm, EVT VT) const override; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 229 | |
| 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 Topper | 906c2cd | 2014-04-29 07:58:16 +0000 | [diff] [blame] | 234 | bool isLegalICmpImmediate(int64_t Imm) const override; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 235 | }; |
| 236 | } // end namespace llvm |
| 237 | |
| 238 | #endif // Hexagon_ISELLOWERING_H |