blob: ec16cc8f894bdb3d7103c05f5e9ed5ed73e02bab [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
15#ifndef Hexagon_ISELLOWERING_H
16#define Hexagon_ISELLOWERING_H
17
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 {
24 namespace HexagonISD {
25 enum {
26 FIRST_NUMBER = ISD::BUILTIN_OP_END,
27
28 CONST32,
29 CONST32_GP, // For marking data present in GP.
Jyotsna Verma2ba0c0b2013-03-07 19:10:28 +000030 CONST32_Int_Real,
Sirish Pande69295b82012-05-10 20:20:25 +000031 FCONST32,
Tony Linthicum1213a7a2011-12-12 21:14:40 +000032 SETCC,
33 ADJDYNALLOC,
34 ARGEXTEND,
35
36 CMPICC, // Compare two GPR operands, set icc.
37 CMPFCC, // Compare two FP operands, set fcc.
38 BRICC, // Branch to dest on icc condition
39 BRFCC, // Branch to dest on fcc condition
40 SELECT_ICC, // Select between two values using the current ICC flags.
41 SELECT_FCC, // Select between two values using the current FCC flags.
42
43 Hi, Lo, // Hi/Lo operations, typically on a global address.
44
45 FTOI, // FP to Int within a FP register.
46 ITOF, // Int to FP within a FP register.
47
48 CALL, // A call instruction.
49 RET_FLAG, // Return with a flag operand.
50 BR_JT, // Jump table.
51 BARRIER, // Memory barrier.
52 WrapperJT,
Sirish Pande69295b82012-05-10 20:20:25 +000053 WrapperCP,
Jyotsna Vermadfd779e2012-12-04 18:05:01 +000054 WrapperCombineII,
55 WrapperCombineRR,
Jyotsna Verma7ab68fb2013-02-04 15:52:56 +000056 WrapperCombineRI_V4,
57 WrapperCombineIR_V4,
Jyotsna Vermadfd779e2012-12-04 18:05:01 +000058 WrapperPackhl,
59 WrapperSplatB,
60 WrapperSplatH,
61 WrapperShuffEB,
62 WrapperShuffEH,
63 WrapperShuffOB,
64 WrapperShuffOH,
Jyotsna Verma5ed51812013-05-01 21:37:34 +000065 TC_RETURN,
66 EH_RETURN
Tony Linthicum1213a7a2011-12-12 21:14:40 +000067 };
68 }
69
70 class HexagonTargetLowering : public TargetLowering {
71 int VarArgsFrameOffset; // Frame offset to start of varargs area.
72
73 bool CanReturnSmallStruct(const Function* CalleeFn,
74 unsigned& RetSize) const;
75
76 public:
Eric Christopherdbe1cb02014-06-27 00:13:52 +000077 const TargetMachine &TM;
78 explicit HexagonTargetLowering(const TargetMachine &targetmachine);
Tony Linthicum1213a7a2011-12-12 21:14:40 +000079
80 /// IsEligibleForTailCallOptimization - Check whether the call is eligible
81 /// for tail call optimization. Targets which want to do tail call
82 /// optimization should implement this function.
83 bool
84 IsEligibleForTailCallOptimization(SDValue Callee,
85 CallingConv::ID CalleeCC,
86 bool isVarArg,
87 bool isCalleeStructRet,
88 bool isCallerStructRet,
89 const
90 SmallVectorImpl<ISD::OutputArg> &Outs,
91 const SmallVectorImpl<SDValue> &OutVals,
92 const SmallVectorImpl<ISD::InputArg> &Ins,
93 SelectionDAG& DAG) const;
94
Craig Topper906c2cd2014-04-29 07:58:16 +000095 bool isTruncateFree(Type *Ty1, Type *Ty2) const override;
96 bool isTruncateFree(EVT VT1, EVT VT2) const override;
Tony Linthicum1213a7a2011-12-12 21:14:40 +000097
Craig Topper906c2cd2014-04-29 07:58:16 +000098 bool allowTruncateForTailCall(Type *Ty1, Type *Ty2) const override;
Tim Northovera4415852013-08-06 09:12:35 +000099
Craig Topper906c2cd2014-04-29 07:58:16 +0000100 SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000101
Craig Topper906c2cd2014-04-29 07:58:16 +0000102 const char *getTargetNodeName(unsigned Opcode) const override;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000103 SDValue LowerBR_JT(SDValue Op, SelectionDAG &DAG) const;
104 SDValue LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) const;
105 SDValue LowerINLINEASM(SDValue Op, SelectionDAG &DAG) const;
106 SDValue LowerEH_LABEL(SDValue Op, SelectionDAG &DAG) const;
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000107 SDValue LowerEH_RETURN(SDValue Op, SelectionDAG &DAG) const;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000108 SDValue LowerFormalArguments(SDValue Chain,
109 CallingConv::ID CallConv, bool isVarArg,
110 const SmallVectorImpl<ISD::InputArg> &Ins,
Andrew Trickef9de2a2013-05-25 02:42:55 +0000111 SDLoc dl, SelectionDAG &DAG,
Craig Topper906c2cd2014-04-29 07:58:16 +0000112 SmallVectorImpl<SDValue> &InVals) const override;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000113 SDValue LowerGLOBALADDRESS(SDValue Op, SelectionDAG &DAG) const;
Jyotsna Verma2ba0c0b2013-03-07 19:10:28 +0000114 SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000115
Justin Holewinskiaa583972012-05-25 16:35:28 +0000116 SDValue LowerCall(TargetLowering::CallLoweringInfo &CLI,
Craig Topper906c2cd2014-04-29 07:58:16 +0000117 SmallVectorImpl<SDValue> &InVals) const override;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000118
119 SDValue LowerCallResult(SDValue Chain, SDValue InFlag,
120 CallingConv::ID CallConv, bool isVarArg,
121 const SmallVectorImpl<ISD::InputArg> &Ins,
Andrew Trickef9de2a2013-05-25 02:42:55 +0000122 SDLoc dl, SelectionDAG &DAG,
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000123 SmallVectorImpl<SDValue> &InVals,
124 const SmallVectorImpl<SDValue> &OutVals,
125 SDValue Callee) const;
126
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000127 SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000128 SDValue LowerATOMIC_FENCE(SDValue Op, SelectionDAG& DAG) const;
129 SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
130
131 SDValue LowerReturn(SDValue Chain,
132 CallingConv::ID CallConv, bool isVarArg,
133 const SmallVectorImpl<ISD::OutputArg> &Outs,
134 const SmallVectorImpl<SDValue> &OutVals,
Craig Topper906c2cd2014-04-29 07:58:16 +0000135 SDLoc dl, SelectionDAG &DAG) const override;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000136
Craig Topper906c2cd2014-04-29 07:58:16 +0000137 MachineBasicBlock *
138 EmitInstrWithCustomInserter(MachineInstr *MI,
139 MachineBasicBlock *BB) const override;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000140
141 SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const;
Sirish Pande69295b82012-05-10 20:20:25 +0000142 SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const;
Craig Topper906c2cd2014-04-29 07:58:16 +0000143 EVT getSetCCResultType(LLVMContext &C, EVT VT) const override {
Juergen Ributzka34c652d2013-11-13 01:57:54 +0000144 if (!VT.isVector())
145 return MVT::i1;
146 else
147 return EVT::getVectorVT(C, MVT::i1, VT.getVectorNumElements());
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000148 }
149
Craig Topper906c2cd2014-04-29 07:58:16 +0000150 bool getPostIndexedAddressParts(SDNode *N, SDNode *Op,
151 SDValue &Base, SDValue &Offset,
152 ISD::MemIndexedMode &AM,
153 SelectionDAG &DAG) const override;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000154
155 std::pair<unsigned, const TargetRegisterClass*>
156 getRegForInlineAsmConstraint(const std::string &Constraint,
Craig Topper906c2cd2014-04-29 07:58:16 +0000157 MVT VT) const override;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000158
159 // Intrinsics
Craig Topper906c2cd2014-04-29 07:58:16 +0000160 SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000161 /// isLegalAddressingMode - Return true if the addressing mode represented
162 /// by AM is legal for this target, for a load/store of the specified type.
163 /// The type may be VoidTy, in which case only return true if the addressing
164 /// mode is legal for a load/store of any legal type.
165 /// TODO: Handle pre/postinc as well.
Craig Topper906c2cd2014-04-29 07:58:16 +0000166 bool isLegalAddressingMode(const AddrMode &AM, Type *Ty) const override;
167 bool isFPImmLegal(const APFloat &Imm, EVT VT) const override;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000168
169 /// isLegalICmpImmediate - Return true if the specified immediate is legal
170 /// icmp immediate, that is the target has icmp instructions which can
171 /// compare a register against the immediate without having to materialize
172 /// the immediate into a register.
Craig Topper906c2cd2014-04-29 07:58:16 +0000173 bool isLegalICmpImmediate(int64_t Imm) const override;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000174 };
175} // end namespace llvm
176
177#endif // Hexagon_ISELLOWERING_H