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