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 { |
Matthias Braun | d04893f | 2015-05-07 21:33:59 +0000 | [diff] [blame] | 29 | enum NodeType : unsigned { |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 30 | OP_BEGIN = ISD::BUILTIN_OP_END, |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 31 | |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 32 | CONST32 = OP_BEGIN, |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 33 | CONST32_GP, // For marking data present in GP. |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 34 | FCONST32, |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 35 | ALLOCA, |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 36 | ARGEXTEND, |
| 37 | |
Colin LeMahieu | 60a99e6 | 2015-03-10 20:04:44 +0000 | [diff] [blame] | 38 | PIC_ADD, |
| 39 | AT_GOT, |
| 40 | AT_PCREL, |
| 41 | |
Colin LeMahieu | 2e3a26d | 2015-01-16 17:05:27 +0000 | [diff] [blame] | 42 | CALLv3, // A V3+ call instruction. |
| 43 | CALLv3nr, // A V3+ call instruction that doesn't return. |
| 44 | CALLR, |
| 45 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 46 | RET_FLAG, // Return with a flag operand. |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 47 | BR_JT, // Branch through jump table. |
| 48 | BARRIER, // Memory barrier. |
| 49 | JT, // Jump table. |
| 50 | CP, // Constant pool. |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 51 | |
Colin LeMahieu | 777abcb | 2015-01-07 20:07:28 +0000 | [diff] [blame] | 52 | POPCOUNT, |
Colin LeMahieu | 383c36e | 2014-12-05 18:24:06 +0000 | [diff] [blame] | 53 | COMBINE, |
Colin LeMahieu | bd8d0f3 | 2015-03-09 18:34:05 +0000 | [diff] [blame] | 54 | PACKHL, |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 55 | VSPLATB, |
| 56 | VSPLATH, |
| 57 | SHUFFEB, |
| 58 | SHUFFEH, |
| 59 | SHUFFOB, |
| 60 | SHUFFOH, |
| 61 | VSXTBH, |
| 62 | VSXTBW, |
| 63 | VSRAW, |
| 64 | VSRAH, |
| 65 | VSRLW, |
| 66 | VSRLH, |
| 67 | VSHLW, |
| 68 | VSHLH, |
| 69 | VCMPBEQ, |
| 70 | VCMPBGT, |
| 71 | VCMPBGTU, |
| 72 | VCMPHEQ, |
| 73 | VCMPHGT, |
| 74 | VCMPHGTU, |
| 75 | VCMPWEQ, |
| 76 | VCMPWGT, |
| 77 | VCMPWGTU, |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 78 | |
| 79 | INSERT, |
| 80 | INSERTRP, |
| 81 | EXTRACTU, |
| 82 | EXTRACTURP, |
Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 83 | TC_RETURN, |
Colin LeMahieu | 68b2e05 | 2015-01-06 19:03:20 +0000 | [diff] [blame] | 84 | EH_RETURN, |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 85 | DCFETCH, |
| 86 | |
| 87 | OP_END |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 88 | }; |
Alexander Kornienko | f00654e | 2015-06-23 09:49:53 +0000 | [diff] [blame] | 89 | } |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 90 | |
Eric Christopher | d737b76 | 2015-02-02 22:11:36 +0000 | [diff] [blame] | 91 | class HexagonSubtarget; |
| 92 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 93 | class HexagonTargetLowering : public TargetLowering { |
| 94 | int VarArgsFrameOffset; // Frame offset to start of varargs area. |
| 95 | |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 96 | bool CanReturnSmallStruct(const Function* CalleeFn, unsigned& RetSize) |
| 97 | const; |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 98 | void promoteLdStType(EVT VT, EVT PromotedLdStVT); |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 99 | const HexagonTargetMachine &HTM; |
| 100 | const HexagonSubtarget &Subtarget; |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 101 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 102 | public: |
Eric Christopher | d737b76 | 2015-02-02 22:11:36 +0000 | [diff] [blame] | 103 | explicit HexagonTargetLowering(const TargetMachine &TM, |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 104 | const HexagonSubtarget &ST); |
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. |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 109 | bool IsEligibleForTailCallOptimization(SDValue Callee, |
| 110 | CallingConv::ID CalleeCC, bool isVarArg, bool isCalleeStructRet, |
| 111 | bool isCallerStructRet, const SmallVectorImpl<ISD::OutputArg> &Outs, |
| 112 | const SmallVectorImpl<SDValue> &OutVals, |
| 113 | const SmallVectorImpl<ISD::InputArg> &Ins, SelectionDAG& DAG) const; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 114 | |
Craig Topper | 906c2cd | 2014-04-29 07:58:16 +0000 | [diff] [blame] | 115 | bool isTruncateFree(Type *Ty1, Type *Ty2) const override; |
| 116 | bool isTruncateFree(EVT VT1, EVT VT2) const override; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 117 | |
Craig Topper | 906c2cd | 2014-04-29 07:58:16 +0000 | [diff] [blame] | 118 | bool allowTruncateForTailCall(Type *Ty1, Type *Ty2) const override; |
Tim Northover | a441585 | 2013-08-06 09:12:35 +0000 | [diff] [blame] | 119 | |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 120 | // Should we expand the build vector with shuffles? |
| 121 | bool shouldExpandBuildVectorWithShuffles(EVT VT, |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 122 | unsigned DefinedValues) const override; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 123 | |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 124 | SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override; |
Craig Topper | 906c2cd | 2014-04-29 07:58:16 +0000 | [diff] [blame] | 125 | const char *getTargetNodeName(unsigned Opcode) const override; |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 126 | SDValue LowerCONCAT_VECTORS(SDValue Op, SelectionDAG &DAG) const; |
| 127 | SDValue LowerEXTRACT_VECTOR(SDValue Op, SelectionDAG &DAG) const; |
| 128 | SDValue LowerINSERT_VECTOR(SDValue Op, SelectionDAG &DAG) const; |
| 129 | SDValue LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG) const; |
| 130 | SDValue LowerBR_JT(SDValue Op, SelectionDAG &DAG) const; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 131 | SDValue LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) const; |
| 132 | SDValue LowerINLINEASM(SDValue Op, SelectionDAG &DAG) const; |
| 133 | SDValue LowerEH_LABEL(SDValue Op, SelectionDAG &DAG) const; |
Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 134 | SDValue LowerEH_RETURN(SDValue Op, SelectionDAG &DAG) const; |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 135 | SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv, |
| 136 | bool isVarArg, const SmallVectorImpl<ISD::InputArg> &Ins, SDLoc dl, |
| 137 | SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals) const override; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 138 | SDValue LowerGLOBALADDRESS(SDValue Op, SelectionDAG &DAG) const; |
Jyotsna Verma | 2ba0c0b | 2013-03-07 19:10:28 +0000 | [diff] [blame] | 139 | SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 140 | |
Justin Holewinski | aa58397 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 141 | SDValue LowerCall(TargetLowering::CallLoweringInfo &CLI, |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 142 | SmallVectorImpl<SDValue> &InVals) const override; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 143 | SDValue LowerCallResult(SDValue Chain, SDValue InFlag, |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 144 | CallingConv::ID CallConv, bool isVarArg, |
| 145 | const SmallVectorImpl<ISD::InputArg> &Ins, SDLoc dl, |
| 146 | SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals, |
| 147 | const SmallVectorImpl<SDValue> &OutVals, SDValue Callee) const; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 148 | |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 149 | SDValue LowerSETCC(SDValue Op, SelectionDAG &DAG) const; |
| 150 | SDValue LowerVSELECT(SDValue Op, SelectionDAG &DAG) const; |
| 151 | SDValue LowerCTPOP(SDValue Op, SelectionDAG &DAG) const; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 152 | SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 153 | SDValue LowerATOMIC_FENCE(SDValue Op, SelectionDAG& DAG) const; |
| 154 | SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const; |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 155 | SDValue LowerLOAD(SDValue Op, SelectionDAG &DAG) const; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 156 | |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 157 | SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, |
| 158 | bool isVarArg, const SmallVectorImpl<ISD::OutputArg> &Outs, |
| 159 | const SmallVectorImpl<SDValue> &OutVals, SDLoc dl, |
| 160 | SelectionDAG &DAG) const override; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 161 | |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 162 | bool mayBeEmittedAsTailCall(CallInst *CI) const override; |
| 163 | MachineBasicBlock * EmitInstrWithCustomInserter(MachineInstr *MI, |
| 164 | MachineBasicBlock *BB) const override; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 165 | |
Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 166 | SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const; |
| 167 | SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const; |
Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 168 | EVT getSetCCResultType(const DataLayout &, LLVMContext &C, |
| 169 | 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, |
Benjamin Kramer | 9bfb627 | 2015-07-05 19:29:18 +0000 | [diff] [blame] | 183 | StringRef Constraint, MVT VT) const override; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 184 | |
Benjamin Kramer | 9bfb627 | 2015-07-05 19:29:18 +0000 | [diff] [blame] | 185 | unsigned |
| 186 | getInlineAsmMemConstraint(StringRef ConstraintCode) const override { |
Daniel Sanders | 49f643c | 2015-03-17 14:37:39 +0000 | [diff] [blame] | 187 | if (ConstraintCode == "o") |
| 188 | return InlineAsm::Constraint_o; |
| 189 | else if (ConstraintCode == "v") |
| 190 | return InlineAsm::Constraint_v; |
| 191 | return TargetLowering::getInlineAsmMemConstraint(ConstraintCode); |
Daniel Sanders | bf5b80f | 2015-03-16 13:13:41 +0000 | [diff] [blame] | 192 | } |
| 193 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 194 | // Intrinsics |
Craig Topper | 906c2cd | 2014-04-29 07:58:16 +0000 | [diff] [blame] | 195 | SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 196 | /// isLegalAddressingMode - Return true if the addressing mode represented |
| 197 | /// by AM is legal for this target, for a load/store of the specified type. |
| 198 | /// The type may be VoidTy, in which case only return true if the addressing |
| 199 | /// mode is legal for a load/store of any legal type. |
| 200 | /// TODO: Handle pre/postinc as well. |
Mehdi Amini | 0cdec1e | 2015-07-09 02:09:40 +0000 | [diff] [blame^] | 201 | bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM, |
| 202 | Type *Ty, unsigned AS) const override; |
Craig Topper | 906c2cd | 2014-04-29 07:58:16 +0000 | [diff] [blame] | 203 | bool isFPImmLegal(const APFloat &Imm, EVT VT) const override; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 204 | |
| 205 | /// isLegalICmpImmediate - Return true if the specified immediate is legal |
| 206 | /// icmp immediate, that is the target has icmp instructions which can |
| 207 | /// compare a register against the immediate without having to materialize |
| 208 | /// the immediate into a register. |
Craig Topper | 906c2cd | 2014-04-29 07:58:16 +0000 | [diff] [blame] | 209 | bool isLegalICmpImmediate(int64_t Imm) const override; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 210 | }; |
| 211 | } // end namespace llvm |
| 212 | |
| 213 | #endif // Hexagon_ISELLOWERING_H |