fe28214e95880ec70ec1e2438b2499249f76fb40
[oota-llvm.git] / lib / Target / NVPTX / NVPTX.h
1 //===-- NVPTX.h - Top-level interface for NVPTX representation --*- 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 contains the entry points for global functions defined in
11 // the LLVM NVPTX back-end.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_LIB_TARGET_NVPTX_NVPTX_H
16 #define LLVM_LIB_TARGET_NVPTX_NVPTX_H
17
18 #include "MCTargetDesc/NVPTXBaseInfo.h"
19 #include "llvm/ADT/StringMap.h"
20 #include "llvm/IR/Module.h"
21 #include "llvm/IR/Value.h"
22 #include "llvm/Support/ErrorHandling.h"
23 #include "llvm/Target/TargetMachine.h"
24 #include <cassert>
25 #include <iosfwd>
26
27 namespace llvm {
28 class NVPTXTargetMachine;
29 class FunctionPass;
30 class MachineFunctionPass;
31 class formatted_raw_ostream;
32
33 namespace NVPTXCC {
34 enum CondCodes {
35   EQ,
36   NE,
37   LT,
38   LE,
39   GT,
40   GE
41 };
42 }
43
44 inline static const char *NVPTXCondCodeToString(NVPTXCC::CondCodes CC) {
45   switch (CC) {
46   case NVPTXCC::NE:
47     return "ne";
48   case NVPTXCC::EQ:
49     return "eq";
50   case NVPTXCC::LT:
51     return "lt";
52   case NVPTXCC::LE:
53     return "le";
54   case NVPTXCC::GT:
55     return "gt";
56   case NVPTXCC::GE:
57     return "ge";
58   }
59   llvm_unreachable("Unknown condition code");
60 }
61
62 FunctionPass *createNVPTXISelDag(NVPTXTargetMachine &TM,
63                                  llvm::CodeGenOpt::Level OptLevel);
64 ModulePass *createNVPTXAssignValidGlobalNamesPass();
65 ModulePass *createGenericToNVVMPass();
66 FunctionPass *createNVPTXFavorNonGenericAddrSpacesPass();
67 ModulePass *createNVVMReflectPass();
68 ModulePass *createNVVMReflectPass(const StringMap<int>& Mapping);
69 MachineFunctionPass *createNVPTXPrologEpilogPass();
70 MachineFunctionPass *createNVPTXReplaceImageHandlesPass();
71 FunctionPass *createNVPTXImageOptimizerPass();
72 FunctionPass *createNVPTXLowerKernelArgsPass(const NVPTXTargetMachine *TM);
73 BasicBlockPass *createNVPTXLowerAllocaPass();
74 MachineFunctionPass *createNVPTXPeephole();
75
76 bool isImageOrSamplerVal(const Value *, const Module *);
77
78 extern Target TheNVPTXTarget32;
79 extern Target TheNVPTXTarget64;
80
81 namespace NVPTX {
82 enum DrvInterface {
83   NVCL,
84   CUDA
85 };
86
87 // A field inside TSFlags needs a shift and a mask. The usage is
88 // always as follows :
89 // ((TSFlags & fieldMask) >> fieldShift)
90 // The enum keeps the mask, the shift, and all valid values of the
91 // field in one place.
92 enum VecInstType {
93   VecInstTypeShift = 0,
94   VecInstTypeMask = 0xF,
95
96   VecNOP = 0,
97   VecLoad = 1,
98   VecStore = 2,
99   VecBuild = 3,
100   VecShuffle = 4,
101   VecExtract = 5,
102   VecInsert = 6,
103   VecDest = 7,
104   VecOther = 15
105 };
106
107 enum SimpleMove {
108   SimpleMoveMask = 0x10,
109   SimpleMoveShift = 4
110 };
111 enum LoadStore {
112   isLoadMask = 0x20,
113   isLoadShift = 5,
114   isStoreMask = 0x40,
115   isStoreShift = 6
116 };
117
118 namespace PTXLdStInstCode {
119 enum AddressSpace {
120   GENERIC = 0,
121   GLOBAL = 1,
122   CONSTANT = 2,
123   SHARED = 3,
124   PARAM = 4,
125   LOCAL = 5
126 };
127 enum FromType {
128   Unsigned = 0,
129   Signed,
130   Float
131 };
132 enum VecType {
133   Scalar = 1,
134   V2 = 2,
135   V4 = 4
136 };
137 }
138
139 /// PTXCvtMode - Conversion code enumeration
140 namespace PTXCvtMode {
141 enum CvtMode {
142   NONE = 0,
143   RNI,
144   RZI,
145   RMI,
146   RPI,
147   RN,
148   RZ,
149   RM,
150   RP,
151
152   BASE_MASK = 0x0F,
153   FTZ_FLAG = 0x10,
154   SAT_FLAG = 0x20
155 };
156 }
157
158 /// PTXCmpMode - Comparison mode enumeration
159 namespace PTXCmpMode {
160 enum CmpMode {
161   EQ = 0,
162   NE,
163   LT,
164   LE,
165   GT,
166   GE,
167   LO,
168   LS,
169   HI,
170   HS,
171   EQU,
172   NEU,
173   LTU,
174   LEU,
175   GTU,
176   GEU,
177   NUM,
178   // NAN is a MACRO
179   NotANumber,
180
181   BASE_MASK = 0xFF,
182   FTZ_FLAG = 0x100
183 };
184 }
185 }
186 } // end namespace llvm;
187
188 // Defines symbolic names for NVPTX registers.  This defines a mapping from
189 // register name to register number.
190 #define GET_REGINFO_ENUM
191 #include "NVPTXGenRegisterInfo.inc"
192
193 // Defines symbolic names for the NVPTX instructions.
194 #define GET_INSTRINFO_ENUM
195 #include "NVPTXGenInstrInfo.inc"
196
197 #endif