blob: 822a191766ba28d6ec4296fdc405e2cfa5e88307 [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,
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 LeMahieu2e3a26d2015-01-16 17:05:27 +000052 CALLv3, // A V3+ call instruction.
53 CALLv3nr, // A V3+ call instruction that doesn't return.
54 CALLR,
55
Tony Linthicum1213a7a2011-12-12 21:14:40 +000056 RET_FLAG, // Return with a flag operand.
57 BR_JT, // Jump table.
Colin LeMahieu777abcb2015-01-07 20:07:28 +000058 BARRIER, // Memory barrier
59 POPCOUNT,
Colin LeMahieu383c36e2014-12-05 18:24:06 +000060 COMBINE,
Tony Linthicum1213a7a2011-12-12 21:14:40 +000061 WrapperJT,
Sirish Pande69295b82012-05-10 20:20:25 +000062 WrapperCP,
Jyotsna Vermadfd779e2012-12-04 18:05:01 +000063 WrapperCombineII,
64 WrapperCombineRR,
Jyotsna Verma7ab68fb2013-02-04 15:52:56 +000065 WrapperCombineRI_V4,
66 WrapperCombineIR_V4,
Jyotsna Vermadfd779e2012-12-04 18:05:01 +000067 WrapperPackhl,
68 WrapperSplatB,
69 WrapperSplatH,
70 WrapperShuffEB,
71 WrapperShuffEH,
72 WrapperShuffOB,
73 WrapperShuffOH,
Jyotsna Verma5ed51812013-05-01 21:37:34 +000074 TC_RETURN,
Colin LeMahieu68b2e052015-01-06 19:03:20 +000075 EH_RETURN,
76 DCFETCH
Tony Linthicum1213a7a2011-12-12 21:14:40 +000077 };
78 }
79
80 class HexagonTargetLowering : public TargetLowering {
81 int VarArgsFrameOffset; // Frame offset to start of varargs area.
82
83 bool CanReturnSmallStruct(const Function* CalleeFn,
84 unsigned& RetSize) const;
85
86 public:
Eric Christopherdbe1cb02014-06-27 00:13:52 +000087 const TargetMachine &TM;
88 explicit HexagonTargetLowering(const TargetMachine &targetmachine);
Tony Linthicum1213a7a2011-12-12 21:14:40 +000089
90 /// IsEligibleForTailCallOptimization - Check whether the call is eligible
91 /// for tail call optimization. Targets which want to do tail call
92 /// optimization should implement this function.
93 bool
94 IsEligibleForTailCallOptimization(SDValue Callee,
95 CallingConv::ID CalleeCC,
96 bool isVarArg,
97 bool isCalleeStructRet,
98 bool isCallerStructRet,
99 const
100 SmallVectorImpl<ISD::OutputArg> &Outs,
101 const SmallVectorImpl<SDValue> &OutVals,
102 const SmallVectorImpl<ISD::InputArg> &Ins,
103 SelectionDAG& DAG) const;
104
Craig Topper906c2cd2014-04-29 07:58:16 +0000105 bool isTruncateFree(Type *Ty1, Type *Ty2) const override;
106 bool isTruncateFree(EVT VT1, EVT VT2) const override;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000107
Craig Topper906c2cd2014-04-29 07:58:16 +0000108 bool allowTruncateForTailCall(Type *Ty1, Type *Ty2) const override;
Tim Northovera4415852013-08-06 09:12:35 +0000109
Craig Topper906c2cd2014-04-29 07:58:16 +0000110 SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000111
Craig Topper906c2cd2014-04-29 07:58:16 +0000112 const char *getTargetNodeName(unsigned Opcode) const override;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000113 SDValue LowerBR_JT(SDValue Op, SelectionDAG &DAG) const;
114 SDValue LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) const;
115 SDValue LowerINLINEASM(SDValue Op, SelectionDAG &DAG) const;
116 SDValue LowerEH_LABEL(SDValue Op, SelectionDAG &DAG) const;
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000117 SDValue LowerEH_RETURN(SDValue Op, SelectionDAG &DAG) const;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000118 SDValue LowerFormalArguments(SDValue Chain,
119 CallingConv::ID CallConv, bool isVarArg,
120 const SmallVectorImpl<ISD::InputArg> &Ins,
Andrew Trickef9de2a2013-05-25 02:42:55 +0000121 SDLoc dl, SelectionDAG &DAG,
Craig Topper906c2cd2014-04-29 07:58:16 +0000122 SmallVectorImpl<SDValue> &InVals) const override;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000123 SDValue LowerGLOBALADDRESS(SDValue Op, SelectionDAG &DAG) const;
Jyotsna Verma2ba0c0b2013-03-07 19:10:28 +0000124 SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000125
Justin Holewinskiaa583972012-05-25 16:35:28 +0000126 SDValue LowerCall(TargetLowering::CallLoweringInfo &CLI,
Craig Topper906c2cd2014-04-29 07:58:16 +0000127 SmallVectorImpl<SDValue> &InVals) const override;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000128
129 SDValue LowerCallResult(SDValue Chain, SDValue InFlag,
130 CallingConv::ID CallConv, bool isVarArg,
131 const SmallVectorImpl<ISD::InputArg> &Ins,
Andrew Trickef9de2a2013-05-25 02:42:55 +0000132 SDLoc dl, SelectionDAG &DAG,
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000133 SmallVectorImpl<SDValue> &InVals,
134 const SmallVectorImpl<SDValue> &OutVals,
135 SDValue Callee) const;
136
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000137 SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000138 SDValue LowerATOMIC_FENCE(SDValue Op, SelectionDAG& DAG) const;
139 SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
140
141 SDValue LowerReturn(SDValue Chain,
142 CallingConv::ID CallConv, bool isVarArg,
143 const SmallVectorImpl<ISD::OutputArg> &Outs,
144 const SmallVectorImpl<SDValue> &OutVals,
Craig Topper906c2cd2014-04-29 07:58:16 +0000145 SDLoc dl, SelectionDAG &DAG) const override;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000146
Craig Topper906c2cd2014-04-29 07:58:16 +0000147 MachineBasicBlock *
148 EmitInstrWithCustomInserter(MachineInstr *MI,
149 MachineBasicBlock *BB) const override;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000150
151 SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const;
Sirish Pande69295b82012-05-10 20:20:25 +0000152 SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const;
Craig Topper906c2cd2014-04-29 07:58:16 +0000153 EVT getSetCCResultType(LLVMContext &C, EVT VT) const override {
Juergen Ributzka34c652d2013-11-13 01:57:54 +0000154 if (!VT.isVector())
155 return MVT::i1;
156 else
157 return EVT::getVectorVT(C, MVT::i1, VT.getVectorNumElements());
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000158 }
159
Craig Topper906c2cd2014-04-29 07:58:16 +0000160 bool getPostIndexedAddressParts(SDNode *N, SDNode *Op,
161 SDValue &Base, SDValue &Offset,
162 ISD::MemIndexedMode &AM,
163 SelectionDAG &DAG) const override;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000164
165 std::pair<unsigned, const TargetRegisterClass*>
166 getRegForInlineAsmConstraint(const std::string &Constraint,
Craig Topper906c2cd2014-04-29 07:58:16 +0000167 MVT VT) const override;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000168
169 // Intrinsics
Craig Topper906c2cd2014-04-29 07:58:16 +0000170 SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000171 /// isLegalAddressingMode - Return true if the addressing mode represented
172 /// by AM is legal for this target, for a load/store of the specified type.
173 /// The type may be VoidTy, in which case only return true if the addressing
174 /// mode is legal for a load/store of any legal type.
175 /// TODO: Handle pre/postinc as well.
Craig Topper906c2cd2014-04-29 07:58:16 +0000176 bool isLegalAddressingMode(const AddrMode &AM, Type *Ty) const override;
177 bool isFPImmLegal(const APFloat &Imm, EVT VT) const override;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000178
179 /// isLegalICmpImmediate - Return true if the specified immediate is legal
180 /// icmp immediate, that is the target has icmp instructions which can
181 /// compare a register against the immediate without having to materialize
182 /// the immediate into a register.
Craig Topper906c2cd2014-04-29 07:58:16 +0000183 bool isLegalICmpImmediate(int64_t Imm) const override;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000184 };
185} // end namespace llvm
186
187#endif // Hexagon_ISELLOWERING_H