Hexagon: Add V4 combine instructions and some more Def Pats for V2.
[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 Hexagon_ISELLOWERING_H
16 #define Hexagon_ISELLOWERING_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   namespace HexagonISD {
25     enum {
26       FIRST_NUMBER = ISD::BUILTIN_OP_END,
27
28       CONST32,
29       CONST32_GP,  // For marking data present in GP.
30       FCONST32,
31       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,
52       WrapperCP,
53       WrapperCombineII,
54       WrapperCombineRR,
55       WrapperCombineRI_V4,
56       WrapperCombineIR_V4,
57       WrapperPackhl,
58       WrapperSplatB,
59       WrapperSplatH,
60       WrapperShuffEB,
61       WrapperShuffEH,
62       WrapperShuffOB,
63       WrapperShuffOH,
64       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
110     SDValue LowerCall(TargetLowering::CallLoweringInfo &CLI,
111                       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;
138     SDValue  LowerConstantPool(SDValue Op, SelectionDAG &DAG) const;
139     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;
161     virtual bool isFPImmLegal(const APFloat &Imm, EVT VT) const;
162
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