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, |
| 37 | ADJDYNALLOC, |
| 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. |
| 61 | BR_JT, // Jump table. |
Colin LeMahieu | 777abcb | 2015-01-07 20:07:28 +0000 | [diff] [blame] | 62 | BARRIER, // Memory barrier |
| 63 | POPCOUNT, |
Colin LeMahieu | 383c36e | 2014-12-05 18:24:06 +0000 | [diff] [blame] | 64 | COMBINE, |
Colin LeMahieu | bd8d0f3 | 2015-03-09 18:34:05 +0000 | [diff] [blame] | 65 | PACKHL, |
Colin LeMahieu | ee77645 | 2015-03-10 19:29:53 +0000 | [diff] [blame] | 66 | JT, |
| 67 | CP, |
Colin LeMahieu | 3b6747d | 2015-03-10 19:40:03 +0000 | [diff] [blame] | 68 | INSERT_ri, |
| 69 | INSERT_rd, |
| 70 | INSERT_riv, |
| 71 | INSERT_rdv, |
| 72 | EXTRACTU_ri, |
| 73 | EXTRACTU_rd, |
| 74 | EXTRACTU_riv, |
| 75 | EXTRACTU_rdv, |
Jyotsna Verma | dfd779e | 2012-12-04 18:05:01 +0000 | [diff] [blame] | 76 | WrapperCombineII, |
| 77 | WrapperCombineRR, |
Jyotsna Verma | 7ab68fb | 2013-02-04 15:52:56 +0000 | [diff] [blame] | 78 | WrapperCombineRI_V4, |
| 79 | WrapperCombineIR_V4, |
Jyotsna Verma | dfd779e | 2012-12-04 18:05:01 +0000 | [diff] [blame] | 80 | WrapperPackhl, |
| 81 | WrapperSplatB, |
| 82 | WrapperSplatH, |
| 83 | WrapperShuffEB, |
| 84 | WrapperShuffEH, |
| 85 | WrapperShuffOB, |
| 86 | WrapperShuffOH, |
Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 87 | TC_RETURN, |
Colin LeMahieu | 68b2e05 | 2015-01-06 19:03:20 +0000 | [diff] [blame] | 88 | EH_RETURN, |
| 89 | DCFETCH |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 90 | }; |
| 91 | } |
| 92 | |
Eric Christopher | d737b76 | 2015-02-02 22:11:36 +0000 | [diff] [blame] | 93 | class HexagonSubtarget; |
| 94 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 95 | class HexagonTargetLowering : public TargetLowering { |
| 96 | int VarArgsFrameOffset; // Frame offset to start of varargs area. |
| 97 | |
| 98 | bool CanReturnSmallStruct(const Function* CalleeFn, |
| 99 | unsigned& RetSize) const; |
| 100 | |
| 101 | public: |
Eric Christopher | d737b76 | 2015-02-02 22:11:36 +0000 | [diff] [blame] | 102 | const HexagonSubtarget *Subtarget; |
| 103 | explicit HexagonTargetLowering(const TargetMachine &TM, |
| 104 | const HexagonSubtarget &Subtarget); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 105 | |
| 106 | /// IsEligibleForTailCallOptimization - Check whether the call is eligible |
| 107 | /// for tail call optimization. Targets which want to do tail call |
| 108 | /// optimization should implement this function. |
| 109 | bool |
| 110 | IsEligibleForTailCallOptimization(SDValue Callee, |
| 111 | CallingConv::ID CalleeCC, |
| 112 | bool isVarArg, |
| 113 | bool isCalleeStructRet, |
| 114 | bool isCallerStructRet, |
| 115 | const |
| 116 | SmallVectorImpl<ISD::OutputArg> &Outs, |
| 117 | const SmallVectorImpl<SDValue> &OutVals, |
| 118 | const SmallVectorImpl<ISD::InputArg> &Ins, |
| 119 | SelectionDAG& DAG) const; |
| 120 | |
Craig Topper | 906c2cd | 2014-04-29 07:58:16 +0000 | [diff] [blame] | 121 | bool isTruncateFree(Type *Ty1, Type *Ty2) const override; |
| 122 | bool isTruncateFree(EVT VT1, EVT VT2) const override; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 123 | |
Craig Topper | 906c2cd | 2014-04-29 07:58:16 +0000 | [diff] [blame] | 124 | bool allowTruncateForTailCall(Type *Ty1, Type *Ty2) const override; |
Tim Northover | a441585 | 2013-08-06 09:12:35 +0000 | [diff] [blame] | 125 | |
Craig Topper | 906c2cd | 2014-04-29 07:58:16 +0000 | [diff] [blame] | 126 | SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 127 | |
Craig Topper | 906c2cd | 2014-04-29 07:58:16 +0000 | [diff] [blame] | 128 | const char *getTargetNodeName(unsigned Opcode) const override; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 129 | SDValue LowerBR_JT(SDValue Op, SelectionDAG &DAG) const; |
| 130 | SDValue LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) const; |
| 131 | SDValue LowerINLINEASM(SDValue Op, SelectionDAG &DAG) const; |
| 132 | SDValue LowerEH_LABEL(SDValue Op, SelectionDAG &DAG) const; |
Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 133 | SDValue LowerEH_RETURN(SDValue Op, SelectionDAG &DAG) const; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 134 | SDValue LowerFormalArguments(SDValue Chain, |
| 135 | CallingConv::ID CallConv, bool isVarArg, |
| 136 | const SmallVectorImpl<ISD::InputArg> &Ins, |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 137 | SDLoc dl, SelectionDAG &DAG, |
Craig Topper | 906c2cd | 2014-04-29 07:58:16 +0000 | [diff] [blame] | 138 | SmallVectorImpl<SDValue> &InVals) const override; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 139 | SDValue LowerGLOBALADDRESS(SDValue Op, SelectionDAG &DAG) const; |
Jyotsna Verma | 2ba0c0b | 2013-03-07 19:10:28 +0000 | [diff] [blame] | 140 | SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 141 | |
Justin Holewinski | aa58397 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 142 | SDValue LowerCall(TargetLowering::CallLoweringInfo &CLI, |
Craig Topper | 906c2cd | 2014-04-29 07:58:16 +0000 | [diff] [blame] | 143 | SmallVectorImpl<SDValue> &InVals) const override; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 144 | |
| 145 | SDValue LowerCallResult(SDValue Chain, SDValue InFlag, |
| 146 | CallingConv::ID CallConv, bool isVarArg, |
| 147 | const SmallVectorImpl<ISD::InputArg> &Ins, |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 148 | SDLoc dl, SelectionDAG &DAG, |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 149 | SmallVectorImpl<SDValue> &InVals, |
| 150 | const SmallVectorImpl<SDValue> &OutVals, |
| 151 | SDValue Callee) const; |
| 152 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 153 | SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 154 | SDValue LowerATOMIC_FENCE(SDValue Op, SelectionDAG& DAG) const; |
| 155 | SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const; |
| 156 | |
| 157 | SDValue LowerReturn(SDValue Chain, |
| 158 | CallingConv::ID CallConv, bool isVarArg, |
| 159 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
| 160 | const SmallVectorImpl<SDValue> &OutVals, |
Craig Topper | 906c2cd | 2014-04-29 07:58:16 +0000 | [diff] [blame] | 161 | SDLoc dl, SelectionDAG &DAG) const override; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 162 | |
Craig Topper | 906c2cd | 2014-04-29 07:58:16 +0000 | [diff] [blame] | 163 | MachineBasicBlock * |
| 164 | EmitInstrWithCustomInserter(MachineInstr *MI, |
| 165 | MachineBasicBlock *BB) const override; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 166 | |
| 167 | SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const; |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 168 | SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const; |
Craig Topper | 906c2cd | 2014-04-29 07:58:16 +0000 | [diff] [blame] | 169 | EVT getSetCCResultType(LLVMContext &C, EVT VT) const override { |
Juergen Ributzka | 34c652d | 2013-11-13 01:57:54 +0000 | [diff] [blame] | 170 | if (!VT.isVector()) |
| 171 | return MVT::i1; |
| 172 | else |
| 173 | return EVT::getVectorVT(C, MVT::i1, VT.getVectorNumElements()); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 174 | } |
| 175 | |
Craig Topper | 906c2cd | 2014-04-29 07:58:16 +0000 | [diff] [blame] | 176 | bool getPostIndexedAddressParts(SDNode *N, SDNode *Op, |
| 177 | SDValue &Base, SDValue &Offset, |
| 178 | ISD::MemIndexedMode &AM, |
| 179 | SelectionDAG &DAG) const override; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 180 | |
Eric Christopher | 11e4df7 | 2015-02-26 22:38:43 +0000 | [diff] [blame] | 181 | std::pair<unsigned, const TargetRegisterClass *> |
| 182 | getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI, |
| 183 | const std::string &Constraint, |
Craig Topper | 906c2cd | 2014-04-29 07:58:16 +0000 | [diff] [blame] | 184 | MVT VT) const override; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 185 | |
| 186 | // Intrinsics |
Craig Topper | 906c2cd | 2014-04-29 07:58:16 +0000 | [diff] [blame] | 187 | SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 188 | /// isLegalAddressingMode - Return true if the addressing mode represented |
| 189 | /// by AM is legal for this target, for a load/store of the specified type. |
| 190 | /// The type may be VoidTy, in which case only return true if the addressing |
| 191 | /// mode is legal for a load/store of any legal type. |
| 192 | /// TODO: Handle pre/postinc as well. |
Craig Topper | 906c2cd | 2014-04-29 07:58:16 +0000 | [diff] [blame] | 193 | bool isLegalAddressingMode(const AddrMode &AM, Type *Ty) const override; |
| 194 | bool isFPImmLegal(const APFloat &Imm, EVT VT) const override; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 195 | |
| 196 | /// isLegalICmpImmediate - Return true if the specified immediate is legal |
| 197 | /// icmp immediate, that is the target has icmp instructions which can |
| 198 | /// compare a register against the immediate without having to materialize |
| 199 | /// the immediate into a register. |
Craig Topper | 906c2cd | 2014-04-29 07:58:16 +0000 | [diff] [blame] | 200 | bool isLegalICmpImmediate(int64_t Imm) const override; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 201 | }; |
| 202 | } // end namespace llvm |
| 203 | |
| 204 | #endif // Hexagon_ISELLOWERING_H |