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