blob: 88743df8f282dda78a15ba8e3d0d5a5fcb396afa [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
52 CALL, // A call instruction.
53 RET_FLAG, // Return with a flag operand.
54 BR_JT, // Jump table.
55 BARRIER, // Memory barrier.
Colin LeMahieu383c36e2014-12-05 18:24:06 +000056 COMBINE,
Tony Linthicum1213a7a2011-12-12 21:14:40 +000057 WrapperJT,
Sirish Pande69295b82012-05-10 20:20:25 +000058 WrapperCP,
Jyotsna Vermadfd779e2012-12-04 18:05:01 +000059 WrapperCombineII,
60 WrapperCombineRR,
Jyotsna Verma7ab68fb2013-02-04 15:52:56 +000061 WrapperCombineRI_V4,
62 WrapperCombineIR_V4,
Jyotsna Vermadfd779e2012-12-04 18:05:01 +000063 WrapperPackhl,
64 WrapperSplatB,
65 WrapperSplatH,
66 WrapperShuffEB,
67 WrapperShuffEH,
68 WrapperShuffOB,
69 WrapperShuffOH,
Jyotsna Verma5ed51812013-05-01 21:37:34 +000070 TC_RETURN,
Colin LeMahieu68b2e052015-01-06 19:03:20 +000071 EH_RETURN,
72 DCFETCH
Tony Linthicum1213a7a2011-12-12 21:14:40 +000073 };
74 }
75
76 class HexagonTargetLowering : public TargetLowering {
77 int VarArgsFrameOffset; // Frame offset to start of varargs area.
78
79 bool CanReturnSmallStruct(const Function* CalleeFn,
80 unsigned& RetSize) const;
81
82 public:
Eric Christopherdbe1cb02014-06-27 00:13:52 +000083 const TargetMachine &TM;
84 explicit HexagonTargetLowering(const TargetMachine &targetmachine);
Tony Linthicum1213a7a2011-12-12 21:14:40 +000085
86 /// IsEligibleForTailCallOptimization - Check whether the call is eligible
87 /// for tail call optimization. Targets which want to do tail call
88 /// optimization should implement this function.
89 bool
90 IsEligibleForTailCallOptimization(SDValue Callee,
91 CallingConv::ID CalleeCC,
92 bool isVarArg,
93 bool isCalleeStructRet,
94 bool isCallerStructRet,
95 const
96 SmallVectorImpl<ISD::OutputArg> &Outs,
97 const SmallVectorImpl<SDValue> &OutVals,
98 const SmallVectorImpl<ISD::InputArg> &Ins,
99 SelectionDAG& DAG) const;
100
Craig Topper906c2cd2014-04-29 07:58:16 +0000101 bool isTruncateFree(Type *Ty1, Type *Ty2) const override;
102 bool isTruncateFree(EVT VT1, EVT VT2) const override;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000103
Craig Topper906c2cd2014-04-29 07:58:16 +0000104 bool allowTruncateForTailCall(Type *Ty1, Type *Ty2) const override;
Tim Northovera4415852013-08-06 09:12:35 +0000105
Craig Topper906c2cd2014-04-29 07:58:16 +0000106 SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000107
Craig Topper906c2cd2014-04-29 07:58:16 +0000108 const char *getTargetNodeName(unsigned Opcode) const override;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000109 SDValue LowerBR_JT(SDValue Op, SelectionDAG &DAG) const;
110 SDValue LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) const;
111 SDValue LowerINLINEASM(SDValue Op, SelectionDAG &DAG) const;
112 SDValue LowerEH_LABEL(SDValue Op, SelectionDAG &DAG) const;
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000113 SDValue LowerEH_RETURN(SDValue Op, SelectionDAG &DAG) const;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000114 SDValue LowerFormalArguments(SDValue Chain,
115 CallingConv::ID CallConv, bool isVarArg,
116 const SmallVectorImpl<ISD::InputArg> &Ins,
Andrew Trickef9de2a2013-05-25 02:42:55 +0000117 SDLoc dl, SelectionDAG &DAG,
Craig Topper906c2cd2014-04-29 07:58:16 +0000118 SmallVectorImpl<SDValue> &InVals) const override;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000119 SDValue LowerGLOBALADDRESS(SDValue Op, SelectionDAG &DAG) const;
Jyotsna Verma2ba0c0b2013-03-07 19:10:28 +0000120 SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000121
Justin Holewinskiaa583972012-05-25 16:35:28 +0000122 SDValue LowerCall(TargetLowering::CallLoweringInfo &CLI,
Craig Topper906c2cd2014-04-29 07:58:16 +0000123 SmallVectorImpl<SDValue> &InVals) const override;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000124
125 SDValue LowerCallResult(SDValue Chain, SDValue InFlag,
126 CallingConv::ID CallConv, bool isVarArg,
127 const SmallVectorImpl<ISD::InputArg> &Ins,
Andrew Trickef9de2a2013-05-25 02:42:55 +0000128 SDLoc dl, SelectionDAG &DAG,
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000129 SmallVectorImpl<SDValue> &InVals,
130 const SmallVectorImpl<SDValue> &OutVals,
131 SDValue Callee) const;
132
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000133 SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000134 SDValue LowerATOMIC_FENCE(SDValue Op, SelectionDAG& DAG) const;
135 SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
136
137 SDValue LowerReturn(SDValue Chain,
138 CallingConv::ID CallConv, bool isVarArg,
139 const SmallVectorImpl<ISD::OutputArg> &Outs,
140 const SmallVectorImpl<SDValue> &OutVals,
Craig Topper906c2cd2014-04-29 07:58:16 +0000141 SDLoc dl, SelectionDAG &DAG) const override;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000142
Craig Topper906c2cd2014-04-29 07:58:16 +0000143 MachineBasicBlock *
144 EmitInstrWithCustomInserter(MachineInstr *MI,
145 MachineBasicBlock *BB) const override;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000146
147 SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const;
Sirish Pande69295b82012-05-10 20:20:25 +0000148 SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const;
Craig Topper906c2cd2014-04-29 07:58:16 +0000149 EVT getSetCCResultType(LLVMContext &C, EVT VT) const override {
Juergen Ributzka34c652d2013-11-13 01:57:54 +0000150 if (!VT.isVector())
151 return MVT::i1;
152 else
153 return EVT::getVectorVT(C, MVT::i1, VT.getVectorNumElements());
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000154 }
155
Craig Topper906c2cd2014-04-29 07:58:16 +0000156 bool getPostIndexedAddressParts(SDNode *N, SDNode *Op,
157 SDValue &Base, SDValue &Offset,
158 ISD::MemIndexedMode &AM,
159 SelectionDAG &DAG) const override;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000160
161 std::pair<unsigned, const TargetRegisterClass*>
162 getRegForInlineAsmConstraint(const std::string &Constraint,
Craig Topper906c2cd2014-04-29 07:58:16 +0000163 MVT VT) const override;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000164
165 // Intrinsics
Craig Topper906c2cd2014-04-29 07:58:16 +0000166 SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000167 /// isLegalAddressingMode - Return true if the addressing mode represented
168 /// by AM is legal for this target, for a load/store of the specified type.
169 /// The type may be VoidTy, in which case only return true if the addressing
170 /// mode is legal for a load/store of any legal type.
171 /// TODO: Handle pre/postinc as well.
Craig Topper906c2cd2014-04-29 07:58:16 +0000172 bool isLegalAddressingMode(const AddrMode &AM, Type *Ty) const override;
173 bool isFPImmLegal(const APFloat &Imm, EVT VT) const override;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000174
175 /// isLegalICmpImmediate - Return true if the specified immediate is legal
176 /// icmp immediate, that is the target has icmp instructions which can
177 /// compare a register against the immediate without having to materialize
178 /// the immediate into a register.
Craig Topper906c2cd2014-04-29 07:58:16 +0000179 bool isLegalICmpImmediate(int64_t Imm) const override;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000180 };
181} // end namespace llvm
182
183#endif // Hexagon_ISELLOWERING_H