Cache and use the subtarget that owns the target lowering.
[oota-llvm.git] / lib / Target / Hexagon / HexagonISelLowering.h
1 //===-- HexagonISelLowering.h - Hexagon DAG Lowering Interface --*- C++ -*-===//
2 //
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 LLVM_LIB_TARGET_HEXAGON_HEXAGONISELLOWERING_H
16 #define LLVM_LIB_TARGET_HEXAGON_HEXAGONISELLOWERING_H
17
18 #include "Hexagon.h"
19 #include "llvm/CodeGen/CallingConvLower.h"
20 #include "llvm/IR/CallingConv.h"
21 #include "llvm/Target/TargetLowering.h"
22
23 namespace llvm {
24
25 // Return true when the given node fits in a positive half word.
26 bool isPositiveHalfWord(SDNode *N);
27
28   namespace HexagonISD {
29     enum {
30       FIRST_NUMBER = ISD::BUILTIN_OP_END,
31
32       CONST32,
33       CONST32_GP,  // For marking data present in GP.
34       CONST32_Int_Real,
35       FCONST32,
36       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       CALLv3,      // A V3+ call instruction.
53       CALLv3nr,    // A V3+ call instruction that doesn't return.
54       CALLR,
55
56       RET_FLAG,    // Return with a flag operand.
57       BR_JT,       // Jump table.
58       BARRIER,     // Memory barrier
59       POPCOUNT,
60       COMBINE,
61       WrapperJT,
62       WrapperCP,
63       WrapperCombineII,
64       WrapperCombineRR,
65       WrapperCombineRI_V4,
66       WrapperCombineIR_V4,
67       WrapperPackhl,
68       WrapperSplatB,
69       WrapperSplatH,
70       WrapperShuffEB,
71       WrapperShuffEH,
72       WrapperShuffOB,
73       WrapperShuffOH,
74       TC_RETURN,
75       EH_RETURN,
76       DCFETCH
77     };
78   }
79
80   class HexagonSubtarget;
81
82   class HexagonTargetLowering : public TargetLowering {
83     int VarArgsFrameOffset;   // Frame offset to start of varargs area.
84
85     bool CanReturnSmallStruct(const Function* CalleeFn,
86                               unsigned& RetSize) const;
87
88   public:
89     const HexagonSubtarget *Subtarget;
90     explicit HexagonTargetLowering(const TargetMachine &TM,
91                                    const HexagonSubtarget &Subtarget);
92
93     /// IsEligibleForTailCallOptimization - Check whether the call is eligible
94     /// for tail call optimization. Targets which want to do tail call
95     /// optimization should implement this function.
96     bool
97     IsEligibleForTailCallOptimization(SDValue Callee,
98                                       CallingConv::ID CalleeCC,
99                                       bool isVarArg,
100                                       bool isCalleeStructRet,
101                                       bool isCallerStructRet,
102                                       const
103                                       SmallVectorImpl<ISD::OutputArg> &Outs,
104                                       const SmallVectorImpl<SDValue> &OutVals,
105                                       const SmallVectorImpl<ISD::InputArg> &Ins,
106                                       SelectionDAG& DAG) const;
107
108     bool isTruncateFree(Type *Ty1, Type *Ty2) const override;
109     bool isTruncateFree(EVT VT1, EVT VT2) const override;
110
111     bool allowTruncateForTailCall(Type *Ty1, Type *Ty2) const override;
112
113     SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
114
115     const char *getTargetNodeName(unsigned Opcode) const override;
116     SDValue  LowerBR_JT(SDValue Op, SelectionDAG &DAG) const;
117     SDValue LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) const;
118     SDValue LowerINLINEASM(SDValue Op, SelectionDAG &DAG) const;
119     SDValue LowerEH_LABEL(SDValue Op, SelectionDAG &DAG) const;
120     SDValue LowerEH_RETURN(SDValue Op, SelectionDAG &DAG) const;
121     SDValue LowerFormalArguments(SDValue Chain,
122                                  CallingConv::ID CallConv, bool isVarArg,
123                                  const SmallVectorImpl<ISD::InputArg> &Ins,
124                                  SDLoc dl, SelectionDAG &DAG,
125                                  SmallVectorImpl<SDValue> &InVals) const override;
126     SDValue LowerGLOBALADDRESS(SDValue Op, SelectionDAG &DAG) const;
127     SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;
128
129     SDValue LowerCall(TargetLowering::CallLoweringInfo &CLI,
130                       SmallVectorImpl<SDValue> &InVals) const override;
131
132     SDValue LowerCallResult(SDValue Chain, SDValue InFlag,
133                             CallingConv::ID CallConv, bool isVarArg,
134                             const SmallVectorImpl<ISD::InputArg> &Ins,
135                             SDLoc dl, SelectionDAG &DAG,
136                             SmallVectorImpl<SDValue> &InVals,
137                             const SmallVectorImpl<SDValue> &OutVals,
138                             SDValue Callee) const;
139
140     SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
141     SDValue LowerATOMIC_FENCE(SDValue Op, SelectionDAG& DAG) const;
142     SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
143
144     SDValue LowerReturn(SDValue Chain,
145                         CallingConv::ID CallConv, bool isVarArg,
146                         const SmallVectorImpl<ISD::OutputArg> &Outs,
147                         const SmallVectorImpl<SDValue> &OutVals,
148                         SDLoc dl, SelectionDAG &DAG) const override;
149
150     MachineBasicBlock *
151     EmitInstrWithCustomInserter(MachineInstr *MI,
152                                 MachineBasicBlock *BB) const override;
153
154     SDValue  LowerVASTART(SDValue Op, SelectionDAG &DAG) const;
155     SDValue  LowerConstantPool(SDValue Op, SelectionDAG &DAG) const;
156     EVT getSetCCResultType(LLVMContext &C, EVT VT) const override {
157       if (!VT.isVector())
158         return MVT::i1;
159       else
160         return EVT::getVectorVT(C, MVT::i1, VT.getVectorNumElements());
161     }
162
163     bool getPostIndexedAddressParts(SDNode *N, SDNode *Op,
164                                     SDValue &Base, SDValue &Offset,
165                                     ISD::MemIndexedMode &AM,
166                                     SelectionDAG &DAG) const override;
167
168     std::pair<unsigned, const TargetRegisterClass*>
169     getRegForInlineAsmConstraint(const std::string &Constraint,
170                                  MVT VT) const override;
171
172     // Intrinsics
173     SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const;
174     /// isLegalAddressingMode - Return true if the addressing mode represented
175     /// by AM is legal for this target, for a load/store of the specified type.
176     /// The type may be VoidTy, in which case only return true if the addressing
177     /// mode is legal for a load/store of any legal type.
178     /// TODO: Handle pre/postinc as well.
179     bool isLegalAddressingMode(const AddrMode &AM, Type *Ty) const override;
180     bool isFPImmLegal(const APFloat &Imm, EVT VT) const override;
181
182     /// isLegalICmpImmediate - Return true if the specified immediate is legal
183     /// icmp immediate, that is the target has icmp instructions which can
184     /// compare a register against the immediate without having to materialize
185     /// the immediate into a register.
186     bool isLegalICmpImmediate(int64_t Imm) const override;
187   };
188 } // end namespace llvm
189
190 #endif    // Hexagon_ISELLOWERING_H