blob: 99ac0eebd1807f6c5616485bba385588d014b40d [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 {
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.
Colin LeMahieu383c36e2014-12-05 18:24:06 +000052 COMBINE,
Tony Linthicum1213a7a2011-12-12 21:14:40 +000053 WrapperJT,
Sirish Pande69295b82012-05-10 20:20:25 +000054 WrapperCP,
Jyotsna Vermadfd779e2012-12-04 18:05:01 +000055 WrapperCombineII,
56 WrapperCombineRR,
Jyotsna Verma7ab68fb2013-02-04 15:52:56 +000057 WrapperCombineRI_V4,
58 WrapperCombineIR_V4,
Jyotsna Vermadfd779e2012-12-04 18:05:01 +000059 WrapperPackhl,
60 WrapperSplatB,
61 WrapperSplatH,
62 WrapperShuffEB,
63 WrapperShuffEH,
64 WrapperShuffOB,
65 WrapperShuffOH,
Jyotsna Verma5ed51812013-05-01 21:37:34 +000066 TC_RETURN,
67 EH_RETURN
Tony Linthicum1213a7a2011-12-12 21:14:40 +000068 };
69 }
70
71 class HexagonTargetLowering : public TargetLowering {
72 int VarArgsFrameOffset; // Frame offset to start of varargs area.
73
74 bool CanReturnSmallStruct(const Function* CalleeFn,
75 unsigned& RetSize) const;
76
77 public:
Eric Christopherdbe1cb02014-06-27 00:13:52 +000078 const TargetMachine &TM;
79 explicit HexagonTargetLowering(const TargetMachine &targetmachine);
Tony Linthicum1213a7a2011-12-12 21:14:40 +000080
81 /// IsEligibleForTailCallOptimization - Check whether the call is eligible
82 /// for tail call optimization. Targets which want to do tail call
83 /// optimization should implement this function.
84 bool
85 IsEligibleForTailCallOptimization(SDValue Callee,
86 CallingConv::ID CalleeCC,
87 bool isVarArg,
88 bool isCalleeStructRet,
89 bool isCallerStructRet,
90 const
91 SmallVectorImpl<ISD::OutputArg> &Outs,
92 const SmallVectorImpl<SDValue> &OutVals,
93 const SmallVectorImpl<ISD::InputArg> &Ins,
94 SelectionDAG& DAG) const;
95
Craig Topper906c2cd2014-04-29 07:58:16 +000096 bool isTruncateFree(Type *Ty1, Type *Ty2) const override;
97 bool isTruncateFree(EVT VT1, EVT VT2) const override;
Tony Linthicum1213a7a2011-12-12 21:14:40 +000098
Craig Topper906c2cd2014-04-29 07:58:16 +000099 bool allowTruncateForTailCall(Type *Ty1, Type *Ty2) const override;
Tim Northovera4415852013-08-06 09:12:35 +0000100
Craig Topper906c2cd2014-04-29 07:58:16 +0000101 SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000102
Craig Topper906c2cd2014-04-29 07:58:16 +0000103 const char *getTargetNodeName(unsigned Opcode) const override;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000104 SDValue LowerBR_JT(SDValue Op, SelectionDAG &DAG) const;
105 SDValue LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) const;
106 SDValue LowerINLINEASM(SDValue Op, SelectionDAG &DAG) const;
107 SDValue LowerEH_LABEL(SDValue Op, SelectionDAG &DAG) const;
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000108 SDValue LowerEH_RETURN(SDValue Op, SelectionDAG &DAG) const;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000109 SDValue LowerFormalArguments(SDValue Chain,
110 CallingConv::ID CallConv, bool isVarArg,
111 const SmallVectorImpl<ISD::InputArg> &Ins,
Andrew Trickef9de2a2013-05-25 02:42:55 +0000112 SDLoc dl, SelectionDAG &DAG,
Craig Topper906c2cd2014-04-29 07:58:16 +0000113 SmallVectorImpl<SDValue> &InVals) const override;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000114 SDValue LowerGLOBALADDRESS(SDValue Op, SelectionDAG &DAG) const;
Jyotsna Verma2ba0c0b2013-03-07 19:10:28 +0000115 SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000116
Justin Holewinskiaa583972012-05-25 16:35:28 +0000117 SDValue LowerCall(TargetLowering::CallLoweringInfo &CLI,
Craig Topper906c2cd2014-04-29 07:58:16 +0000118 SmallVectorImpl<SDValue> &InVals) const override;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000119
120 SDValue LowerCallResult(SDValue Chain, SDValue InFlag,
121 CallingConv::ID CallConv, bool isVarArg,
122 const SmallVectorImpl<ISD::InputArg> &Ins,
Andrew Trickef9de2a2013-05-25 02:42:55 +0000123 SDLoc dl, SelectionDAG &DAG,
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000124 SmallVectorImpl<SDValue> &InVals,
125 const SmallVectorImpl<SDValue> &OutVals,
126 SDValue Callee) const;
127
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000128 SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000129 SDValue LowerATOMIC_FENCE(SDValue Op, SelectionDAG& DAG) const;
130 SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
131
132 SDValue LowerReturn(SDValue Chain,
133 CallingConv::ID CallConv, bool isVarArg,
134 const SmallVectorImpl<ISD::OutputArg> &Outs,
135 const SmallVectorImpl<SDValue> &OutVals,
Craig Topper906c2cd2014-04-29 07:58:16 +0000136 SDLoc dl, SelectionDAG &DAG) const override;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000137
Craig Topper906c2cd2014-04-29 07:58:16 +0000138 MachineBasicBlock *
139 EmitInstrWithCustomInserter(MachineInstr *MI,
140 MachineBasicBlock *BB) const override;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000141
142 SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const;
Sirish Pande69295b82012-05-10 20:20:25 +0000143 SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const;
Craig Topper906c2cd2014-04-29 07:58:16 +0000144 EVT getSetCCResultType(LLVMContext &C, EVT VT) const override {
Juergen Ributzka34c652d2013-11-13 01:57:54 +0000145 if (!VT.isVector())
146 return MVT::i1;
147 else
148 return EVT::getVectorVT(C, MVT::i1, VT.getVectorNumElements());
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000149 }
150
Craig Topper906c2cd2014-04-29 07:58:16 +0000151 bool getPostIndexedAddressParts(SDNode *N, SDNode *Op,
152 SDValue &Base, SDValue &Offset,
153 ISD::MemIndexedMode &AM,
154 SelectionDAG &DAG) const override;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000155
156 std::pair<unsigned, const TargetRegisterClass*>
157 getRegForInlineAsmConstraint(const std::string &Constraint,
Craig Topper906c2cd2014-04-29 07:58:16 +0000158 MVT VT) const override;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000159
160 // Intrinsics
Craig Topper906c2cd2014-04-29 07:58:16 +0000161 SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000162 /// isLegalAddressingMode - Return true if the addressing mode represented
163 /// by AM is legal for this target, for a load/store of the specified type.
164 /// The type may be VoidTy, in which case only return true if the addressing
165 /// mode is legal for a load/store of any legal type.
166 /// TODO: Handle pre/postinc as well.
Craig Topper906c2cd2014-04-29 07:58:16 +0000167 bool isLegalAddressingMode(const AddrMode &AM, Type *Ty) const override;
168 bool isFPImmLegal(const APFloat &Imm, EVT VT) const override;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000169
170 /// isLegalICmpImmediate - Return true if the specified immediate is legal
171 /// icmp immediate, that is the target has icmp instructions which can
172 /// compare a register against the immediate without having to materialize
173 /// the immediate into a register.
Craig Topper906c2cd2014-04-29 07:58:16 +0000174 bool isLegalICmpImmediate(int64_t Imm) const override;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000175 };
176} // end namespace llvm
177
178#endif // Hexagon_ISELLOWERING_H