blob: 65dab8597be2f8643c88e191f698c31738202822 [file] [log] [blame]
Jia Liu31d157a2012-02-18 12:03:15 +00001//===-- HexagonISelLowering.h - Hexagon DAG Lowering Interface --*- C++ -*-===//
Tony Linthicumb4b54152011-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 Topper79aa3412012-03-17 18:46:09 +000018#include "Hexagon.h"
Tony Linthicumb4b54152011-12-12 21:14:40 +000019#include "llvm/CodeGen/CallingConvLower.h"
Chandler Carruth0b8c9a82013-01-02 11:36:10 +000020#include "llvm/IR/CallingConv.h"
Chandler Carrutha1514e22012-12-04 07:12:27 +000021#include "llvm/Target/TargetLowering.h"
Tony Linthicumb4b54152011-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.
Sirish Pande7517bbc2012-05-10 20:20:25 +000030 FCONST32,
Tony Linthicumb4b54152011-12-12 21:14:40 +000031 SETCC,
32 ADJDYNALLOC,
33 ARGEXTEND,
34
35 CMPICC, // Compare two GPR operands, set icc.
36 CMPFCC, // Compare two FP operands, set fcc.
37 BRICC, // Branch to dest on icc condition
38 BRFCC, // Branch to dest on fcc condition
39 SELECT_ICC, // Select between two values using the current ICC flags.
40 SELECT_FCC, // Select between two values using the current FCC flags.
41
42 Hi, Lo, // Hi/Lo operations, typically on a global address.
43
44 FTOI, // FP to Int within a FP register.
45 ITOF, // Int to FP within a FP register.
46
47 CALL, // A call instruction.
48 RET_FLAG, // Return with a flag operand.
49 BR_JT, // Jump table.
50 BARRIER, // Memory barrier.
51 WrapperJT,
Sirish Pande7517bbc2012-05-10 20:20:25 +000052 WrapperCP,
Jyotsna Verma4b3aafb2012-12-04 18:05:01 +000053 WrapperCombineII,
54 WrapperCombineRR,
Jyotsna Verma3e1635d2013-02-04 15:52:56 +000055 WrapperCombineRI_V4,
56 WrapperCombineIR_V4,
Jyotsna Verma4b3aafb2012-12-04 18:05:01 +000057 WrapperPackhl,
58 WrapperSplatB,
59 WrapperSplatH,
60 WrapperShuffEB,
61 WrapperShuffEH,
62 WrapperShuffOB,
63 WrapperShuffOH,
Tony Linthicumb4b54152011-12-12 21:14:40 +000064 TC_RETURN
65 };
66 }
67
68 class HexagonTargetLowering : public TargetLowering {
69 int VarArgsFrameOffset; // Frame offset to start of varargs area.
70
71 bool CanReturnSmallStruct(const Function* CalleeFn,
72 unsigned& RetSize) const;
73
74 public:
75 HexagonTargetMachine &TM;
76 explicit HexagonTargetLowering(HexagonTargetMachine &targetmachine);
77
78 /// IsEligibleForTailCallOptimization - Check whether the call is eligible
79 /// for tail call optimization. Targets which want to do tail call
80 /// optimization should implement this function.
81 bool
82 IsEligibleForTailCallOptimization(SDValue Callee,
83 CallingConv::ID CalleeCC,
84 bool isVarArg,
85 bool isCalleeStructRet,
86 bool isCallerStructRet,
87 const
88 SmallVectorImpl<ISD::OutputArg> &Outs,
89 const SmallVectorImpl<SDValue> &OutVals,
90 const SmallVectorImpl<ISD::InputArg> &Ins,
91 SelectionDAG& DAG) const;
92
93 virtual bool isTruncateFree(Type *Ty1, Type *Ty2) const;
94 virtual bool isTruncateFree(EVT VT1, EVT VT2) const;
95
96 virtual SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const;
97
98 virtual const char *getTargetNodeName(unsigned Opcode) const;
99 SDValue LowerBR_JT(SDValue Op, SelectionDAG &DAG) const;
100 SDValue LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) const;
101 SDValue LowerINLINEASM(SDValue Op, SelectionDAG &DAG) const;
102 SDValue LowerEH_LABEL(SDValue Op, SelectionDAG &DAG) const;
103 SDValue LowerFormalArguments(SDValue Chain,
104 CallingConv::ID CallConv, bool isVarArg,
105 const SmallVectorImpl<ISD::InputArg> &Ins,
106 DebugLoc dl, SelectionDAG &DAG,
107 SmallVectorImpl<SDValue> &InVals) const;
108 SDValue LowerGLOBALADDRESS(SDValue Op, SelectionDAG &DAG) const;
109
Justin Holewinskid2ea0e12012-05-25 16:35:28 +0000110 SDValue LowerCall(TargetLowering::CallLoweringInfo &CLI,
Tony Linthicumb4b54152011-12-12 21:14:40 +0000111 SmallVectorImpl<SDValue> &InVals) const;
112
113 SDValue LowerCallResult(SDValue Chain, SDValue InFlag,
114 CallingConv::ID CallConv, bool isVarArg,
115 const SmallVectorImpl<ISD::InputArg> &Ins,
116 DebugLoc dl, SelectionDAG &DAG,
117 SmallVectorImpl<SDValue> &InVals,
118 const SmallVectorImpl<SDValue> &OutVals,
119 SDValue Callee) const;
120
121 SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const;
122 SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
123 SDValue LowerMEMBARRIER(SDValue Op, SelectionDAG& DAG) const;
124 SDValue LowerATOMIC_FENCE(SDValue Op, SelectionDAG& DAG) const;
125 SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
126
127 SDValue LowerReturn(SDValue Chain,
128 CallingConv::ID CallConv, bool isVarArg,
129 const SmallVectorImpl<ISD::OutputArg> &Outs,
130 const SmallVectorImpl<SDValue> &OutVals,
131 DebugLoc dl, SelectionDAG &DAG) const;
132
133 virtual MachineBasicBlock
134 *EmitInstrWithCustomInserter(MachineInstr *MI,
135 MachineBasicBlock *BB) const;
136
137 SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const;
Sirish Pande7517bbc2012-05-10 20:20:25 +0000138 SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const;
Tony Linthicumb4b54152011-12-12 21:14:40 +0000139 virtual EVT getSetCCResultType(EVT VT) const {
140 return MVT::i1;
141 }
142
143 virtual bool getPostIndexedAddressParts(SDNode *N, SDNode *Op,
144 SDValue &Base, SDValue &Offset,
145 ISD::MemIndexedMode &AM,
146 SelectionDAG &DAG) const;
147
148 std::pair<unsigned, const TargetRegisterClass*>
149 getRegForInlineAsmConstraint(const std::string &Constraint,
150 EVT VT) const;
151
152 // Intrinsics
153 virtual SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op,
154 SelectionDAG &DAG) const;
155 /// isLegalAddressingMode - Return true if the addressing mode represented
156 /// by AM is legal for this target, for a load/store of the specified type.
157 /// The type may be VoidTy, in which case only return true if the addressing
158 /// mode is legal for a load/store of any legal type.
159 /// TODO: Handle pre/postinc as well.
160 virtual bool isLegalAddressingMode(const AddrMode &AM, Type *Ty) const;
Sirish Pande7517bbc2012-05-10 20:20:25 +0000161 virtual bool isFPImmLegal(const APFloat &Imm, EVT VT) const;
Tony Linthicumb4b54152011-12-12 21:14:40 +0000162
163 /// isLegalICmpImmediate - Return true if the specified immediate is legal
164 /// icmp immediate, that is the target has icmp instructions which can
165 /// compare a register against the immediate without having to materialize
166 /// the immediate into a register.
167 virtual bool isLegalICmpImmediate(int64_t Imm) const;
168 };
169} // end namespace llvm
170
171#endif // Hexagon_ISELLOWERING_H