[Hexagon] Adding nodes for vector insert/extract 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       PACKHL,
62       JT,
63       CP,
64       INSERT_ri,
65       INSERT_rd,
66       INSERT_riv,
67       INSERT_rdv,
68       EXTRACTU_ri,
69       EXTRACTU_rd,
70       EXTRACTU_riv,
71       EXTRACTU_rdv,
72       WrapperCombineII,
73       WrapperCombineRR,
74       WrapperCombineRI_V4,
75       WrapperCombineIR_V4,
76       WrapperPackhl,
77       WrapperSplatB,
78       WrapperSplatH,
79       WrapperShuffEB,
80       WrapperShuffEH,
81       WrapperShuffOB,
82       WrapperShuffOH,
83       TC_RETURN,
84       EH_RETURN,
85       DCFETCH
86     };
87   }
88
89   class HexagonSubtarget;
90
91   class HexagonTargetLowering : public TargetLowering {
92     int VarArgsFrameOffset;   // Frame offset to start of varargs area.
93
94     bool CanReturnSmallStruct(const Function* CalleeFn,
95                               unsigned& RetSize) const;
96
97   public:
98     const HexagonSubtarget *Subtarget;
99     explicit HexagonTargetLowering(const TargetMachine &TM,
100                                    const HexagonSubtarget &Subtarget);
101
102     /// IsEligibleForTailCallOptimization - Check whether the call is eligible
103     /// for tail call optimization. Targets which want to do tail call
104     /// optimization should implement this function.
105     bool
106     IsEligibleForTailCallOptimization(SDValue Callee,
107                                       CallingConv::ID CalleeCC,
108                                       bool isVarArg,
109                                       bool isCalleeStructRet,
110                                       bool isCallerStructRet,
111                                       const
112                                       SmallVectorImpl<ISD::OutputArg> &Outs,
113                                       const SmallVectorImpl<SDValue> &OutVals,
114                                       const SmallVectorImpl<ISD::InputArg> &Ins,
115                                       SelectionDAG& DAG) const;
116
117     bool isTruncateFree(Type *Ty1, Type *Ty2) const override;
118     bool isTruncateFree(EVT VT1, EVT VT2) const override;
119
120     bool allowTruncateForTailCall(Type *Ty1, Type *Ty2) const override;
121
122     SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
123
124     const char *getTargetNodeName(unsigned Opcode) const override;
125     SDValue  LowerBR_JT(SDValue Op, SelectionDAG &DAG) const;
126     SDValue LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) const;
127     SDValue LowerINLINEASM(SDValue Op, SelectionDAG &DAG) const;
128     SDValue LowerEH_LABEL(SDValue Op, SelectionDAG &DAG) const;
129     SDValue LowerEH_RETURN(SDValue Op, SelectionDAG &DAG) const;
130     SDValue LowerFormalArguments(SDValue Chain,
131                                  CallingConv::ID CallConv, bool isVarArg,
132                                  const SmallVectorImpl<ISD::InputArg> &Ins,
133                                  SDLoc dl, SelectionDAG &DAG,
134                                  SmallVectorImpl<SDValue> &InVals) const override;
135     SDValue LowerGLOBALADDRESS(SDValue Op, SelectionDAG &DAG) const;
136     SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;
137
138     SDValue LowerCall(TargetLowering::CallLoweringInfo &CLI,
139                       SmallVectorImpl<SDValue> &InVals) const override;
140
141     SDValue LowerCallResult(SDValue Chain, SDValue InFlag,
142                             CallingConv::ID CallConv, bool isVarArg,
143                             const SmallVectorImpl<ISD::InputArg> &Ins,
144                             SDLoc dl, SelectionDAG &DAG,
145                             SmallVectorImpl<SDValue> &InVals,
146                             const SmallVectorImpl<SDValue> &OutVals,
147                             SDValue Callee) const;
148
149     SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
150     SDValue LowerATOMIC_FENCE(SDValue Op, SelectionDAG& DAG) const;
151     SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
152
153     SDValue LowerReturn(SDValue Chain,
154                         CallingConv::ID CallConv, bool isVarArg,
155                         const SmallVectorImpl<ISD::OutputArg> &Outs,
156                         const SmallVectorImpl<SDValue> &OutVals,
157                         SDLoc dl, SelectionDAG &DAG) const override;
158
159     MachineBasicBlock *
160     EmitInstrWithCustomInserter(MachineInstr *MI,
161                                 MachineBasicBlock *BB) const override;
162
163     SDValue  LowerVASTART(SDValue Op, SelectionDAG &DAG) const;
164     SDValue  LowerConstantPool(SDValue Op, SelectionDAG &DAG) const;
165     EVT getSetCCResultType(LLVMContext &C, EVT VT) const override {
166       if (!VT.isVector())
167         return MVT::i1;
168       else
169         return EVT::getVectorVT(C, MVT::i1, VT.getVectorNumElements());
170     }
171
172     bool getPostIndexedAddressParts(SDNode *N, SDNode *Op,
173                                     SDValue &Base, SDValue &Offset,
174                                     ISD::MemIndexedMode &AM,
175                                     SelectionDAG &DAG) const override;
176
177     std::pair<unsigned, const TargetRegisterClass *>
178     getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
179                                  const std::string &Constraint,
180                                  MVT VT) const override;
181
182     // Intrinsics
183     SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const;
184     /// isLegalAddressingMode - Return true if the addressing mode represented
185     /// by AM is legal for this target, for a load/store of the specified type.
186     /// The type may be VoidTy, in which case only return true if the addressing
187     /// mode is legal for a load/store of any legal type.
188     /// TODO: Handle pre/postinc as well.
189     bool isLegalAddressingMode(const AddrMode &AM, Type *Ty) const override;
190     bool isFPImmLegal(const APFloat &Imm, EVT VT) const override;
191
192     /// isLegalICmpImmediate - Return true if the specified immediate is legal
193     /// icmp immediate, that is the target has icmp instructions which can
194     /// compare a register against the immediate without having to materialize
195     /// the immediate into a register.
196     bool isLegalICmpImmediate(int64_t Imm) const override;
197   };
198 } // end namespace llvm
199
200 #endif    // Hexagon_ISELLOWERING_H