[NVPTX] Remove i8 register class. PTX support for i8 (.b8, .u8, .s8) is rather poor...
[oota-llvm.git] / lib / Target / NVPTX / NVPTXISelLowering.h
1 //===-- NVPTXISelLowering.h - NVPTX 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 NVPTX uses to lower LLVM code into a
11 // selection DAG.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef NVPTXISELLOWERING_H
16 #define NVPTXISELLOWERING_H
17
18 #include "NVPTX.h"
19 #include "NVPTXSubtarget.h"
20 #include "llvm/CodeGen/SelectionDAG.h"
21 #include "llvm/Target/TargetLowering.h"
22
23 namespace llvm {
24 namespace NVPTXISD {
25 enum NodeType {
26   // Start the numbering from where ISD NodeType finishes.
27   FIRST_NUMBER = ISD::BUILTIN_OP_END,
28   Wrapper,
29   CALL,
30   RET_FLAG,
31   LOAD_PARAM,
32   NVBuiltin,
33   DeclareParam,
34   DeclareScalarParam,
35   DeclareRetParam,
36   DeclareRet,
37   DeclareScalarRet,
38   MoveToParam,
39   PrintCall,
40   PrintCallUni,
41   CallArgBegin,
42   CallArg,
43   LastCallArg,
44   CallArgEnd,
45   CallVoid,
46   CallVal,
47   CallSymbol,
48   Prototype,
49   MoveParam,
50   MoveRetval,
51   MoveToRetval,
52   PseudoUseParam,
53   RETURN,
54   CallSeqBegin,
55   CallSeqEnd,
56   Dummy,
57
58   LoadV2 = ISD::FIRST_TARGET_MEMORY_OPCODE,
59   LoadV4,
60   LDGV2, // LDG.v2
61   LDGV4, // LDG.v4
62   LDUV2, // LDU.v2
63   LDUV4, // LDU.v4
64   StoreV2,
65   StoreV4,
66   LoadParam,
67   LoadParamV2,
68   LoadParamV4,
69   StoreParam,
70   StoreParamV2,
71   StoreParamV4,
72   StoreParamS32, // to sext and store a <32bit value, not used currently
73   StoreParamU32, // to zext and store a <32bit value, not used currently 
74   StoreRetval,
75   StoreRetvalV2,
76   StoreRetvalV4
77 };
78 }
79
80 //===--------------------------------------------------------------------===//
81 // TargetLowering Implementation
82 //===--------------------------------------------------------------------===//
83 class NVPTXTargetLowering : public TargetLowering {
84 public:
85   explicit NVPTXTargetLowering(NVPTXTargetMachine &TM);
86   virtual SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const;
87
88   SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;
89   SDValue LowerGlobalAddress(const GlobalValue *GV, int64_t Offset,
90                              SelectionDAG &DAG) const;
91
92   virtual const char *getTargetNodeName(unsigned Opcode) const;
93
94   bool isTypeSupportedInIntrinsic(MVT VT) const;
95
96   bool getTgtMemIntrinsic(IntrinsicInfo &Info, const CallInst &I,
97                           unsigned Intrinsic) const;
98
99   /// isLegalAddressingMode - Return true if the addressing mode represented
100   /// by AM is legal for this target, for a load/store of the specified type
101   /// Used to guide target specific optimizations, like loop strength
102   /// reduction (LoopStrengthReduce.cpp) and memory optimization for
103   /// address mode (CodeGenPrepare.cpp)
104   virtual bool isLegalAddressingMode(const AddrMode &AM, Type *Ty) const;
105
106   /// getFunctionAlignment - Return the Log2 alignment of this function.
107   virtual unsigned getFunctionAlignment(const Function *F) const;
108
109   virtual EVT getSetCCResultType(LLVMContext &, EVT VT) const {
110     if (VT.isVector())
111       return MVT::getVectorVT(MVT::i1, VT.getVectorNumElements());
112     return MVT::i1;
113   }
114
115   ConstraintType getConstraintType(const std::string &Constraint) const;
116   std::pair<unsigned, const TargetRegisterClass *>
117   getRegForInlineAsmConstraint(const std::string &Constraint, MVT VT) const;
118
119   virtual SDValue LowerFormalArguments(
120       SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
121       const SmallVectorImpl<ISD::InputArg> &Ins, SDLoc dl, SelectionDAG &DAG,
122       SmallVectorImpl<SDValue> &InVals) const;
123
124   virtual SDValue
125   LowerCall(CallLoweringInfo &CLI, SmallVectorImpl<SDValue> &InVals) const;
126
127   std::string getPrototype(Type *, const ArgListTy &,
128                            const SmallVectorImpl<ISD::OutputArg> &,
129                            unsigned retAlignment,
130                            const ImmutableCallSite *CS) const;
131
132   virtual SDValue
133   LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
134               const SmallVectorImpl<ISD::OutputArg> &Outs,
135               const SmallVectorImpl<SDValue> &OutVals, SDLoc dl,
136               SelectionDAG &DAG) const;
137
138   virtual void LowerAsmOperandForConstraint(SDValue Op, std::string &Constraint,
139                                             std::vector<SDValue> &Ops,
140                                             SelectionDAG &DAG) const;
141
142   NVPTXTargetMachine *nvTM;
143
144   // PTX always uses 32-bit shift amounts
145   virtual MVT getScalarShiftAmountTy(EVT LHSTy) const { return MVT::i32; }
146
147   virtual bool shouldSplitVectorElementType(EVT VT) const;
148
149 private:
150   const NVPTXSubtarget &nvptxSubtarget; // cache the subtarget here
151
152   SDValue getExtSymb(SelectionDAG &DAG, const char *name, int idx,
153                      EVT = MVT::i32) const;
154   SDValue getParamSymbol(SelectionDAG &DAG, int idx, EVT) const;
155   SDValue getParamHelpSymbol(SelectionDAG &DAG, int idx);
156
157   SDValue LowerCONCAT_VECTORS(SDValue Op, SelectionDAG &DAG) const;
158
159   SDValue LowerLOAD(SDValue Op, SelectionDAG &DAG) const;
160   SDValue LowerLOADi1(SDValue Op, SelectionDAG &DAG) const;
161
162   SDValue LowerSTORE(SDValue Op, SelectionDAG &DAG) const;
163   SDValue LowerSTOREi1(SDValue Op, SelectionDAG &DAG) const;
164   SDValue LowerSTOREVector(SDValue Op, SelectionDAG &DAG) const;
165
166   virtual void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue> &Results,
167                                   SelectionDAG &DAG) const;
168
169   unsigned getArgumentAlignment(SDValue Callee, const ImmutableCallSite *CS,
170                                 Type *Ty, unsigned Idx) const;
171 };
172 } // namespace llvm
173
174 #endif // NVPTXISELLOWERING_H