Merge information about the number of zero, one, and sign bits of live-out registers
[oota-llvm.git] / lib / Target / PTX / PTXInstrInfo.td
1 //===- PTXInstrInfo.td - PTX Instruction defs -----------------*- tblgen-*-===//
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 describes the PTX instructions in TableGen format.
11 //
12 //===----------------------------------------------------------------------===//
13
14 //===----------------------------------------------------------------------===//
15 // Instruction format superclass
16 //===----------------------------------------------------------------------===//
17
18 include "PTXInstrFormats.td"
19
20 //===----------------------------------------------------------------------===//
21 // Instruction Pattern Stuff
22 //===----------------------------------------------------------------------===//
23
24 def load_global : PatFrag<(ops node:$ptr), (load node:$ptr), [{
25   const Value *Src;
26   const PointerType *PT;
27   if ((Src = cast<LoadSDNode>(N)->getSrcValue()) &&
28       (PT = dyn_cast<PointerType>(Src->getType())))
29     return PT->getAddressSpace() == PTX::GLOBAL;
30   return false;
31 }]>;
32
33 def load_constant : PatFrag<(ops node:$ptr), (load node:$ptr), [{
34   const Value *Src;
35   const PointerType *PT;
36   if ((Src = cast<LoadSDNode>(N)->getSrcValue()) &&
37       (PT = dyn_cast<PointerType>(Src->getType())))
38     return PT->getAddressSpace() == PTX::CONSTANT;
39   return false;
40 }]>;
41
42 def load_local : PatFrag<(ops node:$ptr), (load node:$ptr), [{
43   const Value *Src;
44   const PointerType *PT;
45   if ((Src = cast<LoadSDNode>(N)->getSrcValue()) &&
46       (PT = dyn_cast<PointerType>(Src->getType())))
47     return PT->getAddressSpace() == PTX::LOCAL;
48   return false;
49 }]>;
50
51 def load_parameter : PatFrag<(ops node:$ptr), (load node:$ptr), [{
52   const Value *Src;
53   const PointerType *PT;
54   if ((Src = cast<LoadSDNode>(N)->getSrcValue()) &&
55       (PT = dyn_cast<PointerType>(Src->getType())))
56     return PT->getAddressSpace() == PTX::PARAMETER;
57   return false;
58 }]>;
59
60 def load_shared : PatFrag<(ops node:$ptr), (load node:$ptr), [{
61   const Value *Src;
62   const PointerType *PT;
63   if ((Src = cast<LoadSDNode>(N)->getSrcValue()) &&
64       (PT = dyn_cast<PointerType>(Src->getType())))
65     return PT->getAddressSpace() == PTX::SHARED;
66   return false;
67 }]>;
68
69 def store_global
70   : PatFrag<(ops node:$d, node:$ptr), (store node:$d, node:$ptr), [{
71   const Value *Src;
72   const PointerType *PT;
73   if ((Src = cast<StoreSDNode>(N)->getSrcValue()) &&
74       (PT = dyn_cast<PointerType>(Src->getType())))
75     return PT->getAddressSpace() == PTX::GLOBAL;
76   return false;
77 }]>;
78
79 def store_local
80   : PatFrag<(ops node:$d, node:$ptr), (store node:$d, node:$ptr), [{
81   const Value *Src;
82   const PointerType *PT;
83   if ((Src = cast<StoreSDNode>(N)->getSrcValue()) &&
84       (PT = dyn_cast<PointerType>(Src->getType())))
85     return PT->getAddressSpace() == PTX::LOCAL;
86   return false;
87 }]>;
88
89 def store_parameter
90   : PatFrag<(ops node:$d, node:$ptr), (store node:$d, node:$ptr), [{
91   const Value *Src;
92   const PointerType *PT;
93   if ((Src = cast<StoreSDNode>(N)->getSrcValue()) &&
94       (PT = dyn_cast<PointerType>(Src->getType())))
95     return PT->getAddressSpace() == PTX::PARAMETER;
96   return false;
97 }]>;
98
99 def store_shared
100   : PatFrag<(ops node:$d, node:$ptr), (store node:$d, node:$ptr), [{
101   const Value *Src;
102   const PointerType *PT;
103   if ((Src = cast<StoreSDNode>(N)->getSrcValue()) &&
104       (PT = dyn_cast<PointerType>(Src->getType())))
105     return PT->getAddressSpace() == PTX::SHARED;
106   return false;
107 }]>;
108
109 // Addressing modes.
110 def ADDRrr : ComplexPattern<i32, 2, "SelectADDRrr", [], []>;
111 def ADDRri : ComplexPattern<i32, 2, "SelectADDRri", [], []>;
112 def ADDRii : ComplexPattern<i32, 2, "SelectADDRii", [], []>;
113
114 // Address operands
115 def MEMri : Operand<i32> {
116   let PrintMethod = "printMemOperand";
117   let MIOperandInfo = (ops RRegs32, i32imm);
118 }
119 def MEMii : Operand<i32> {
120   let PrintMethod = "printMemOperand";
121   let MIOperandInfo = (ops i32imm, i32imm);
122 }
123 def MEMpi : Operand<i32> {
124   let PrintMethod = "printParamOperand";
125   let MIOperandInfo = (ops i32imm);
126 }
127
128 //===----------------------------------------------------------------------===//
129 // PTX Specific Node Definitions
130 //===----------------------------------------------------------------------===//
131
132 // PTX allow generic 3-reg shifts like shl r0, r1, r2
133 def PTXshl : SDNode<"ISD::SHL", SDTIntBinOp>;
134 def PTXsrl : SDNode<"ISD::SRL", SDTIntBinOp>;
135 def PTXsra : SDNode<"ISD::SRA", SDTIntBinOp>;
136
137 def PTXexit
138   : SDNode<"PTXISD::EXIT", SDTNone, [SDNPHasChain]>;
139 def PTXret
140   : SDNode<"PTXISD::RET",  SDTNone, [SDNPHasChain]>;
141
142 //===----------------------------------------------------------------------===//
143 // Instruction Class Templates
144 //===----------------------------------------------------------------------===//
145
146 multiclass INT3<string opcstr, SDNode opnode> {
147   def rr : InstPTX<(outs RRegs32:$d),
148                    (ins RRegs32:$a, RRegs32:$b),
149                    !strconcat(opcstr, ".%type\t$d, $a, $b"),
150                    [(set RRegs32:$d, (opnode RRegs32:$a, RRegs32:$b))]>;
151   def ri : InstPTX<(outs RRegs32:$d),
152                    (ins RRegs32:$a, i32imm:$b),
153                    !strconcat(opcstr, ".%type\t$d, $a, $b"),
154                    [(set RRegs32:$d, (opnode RRegs32:$a, imm:$b))]>;
155 }
156
157 // no %type directive, non-communtable
158 multiclass INT3ntnc<string opcstr, SDNode opnode> {
159   def rr : InstPTX<(outs RRegs32:$d),
160                    (ins RRegs32:$a, RRegs32:$b),
161                    !strconcat(opcstr, "\t$d, $a, $b"),
162                    [(set RRegs32:$d, (opnode RRegs32:$a, RRegs32:$b))]>;
163   def ri : InstPTX<(outs RRegs32:$d),
164                    (ins RRegs32:$a, i32imm:$b),
165                    !strconcat(opcstr, "\t$d, $a, $b"),
166                    [(set RRegs32:$d, (opnode RRegs32:$a, imm:$b))]>;
167   def ir : InstPTX<(outs RRegs32:$d),
168                    (ins i32imm:$a, RRegs32:$b),
169                    !strconcat(opcstr, "\t$d, $a, $b"),
170                    [(set RRegs32:$d, (opnode imm:$a, RRegs32:$b))]>;
171 }
172
173 multiclass PTX_LD<string opstr, RegisterClass RC, PatFrag pat_load> {
174   def rr : InstPTX<(outs RC:$d),
175                    (ins MEMri:$a),
176                    !strconcat(opstr, ".%type\t$d, [$a]"),
177                    [(set RC:$d, (pat_load ADDRrr:$a))]>;
178   def ri : InstPTX<(outs RC:$d),
179                    (ins MEMri:$a),
180                    !strconcat(opstr, ".%type\t$d, [$a]"),
181                    [(set RC:$d, (pat_load ADDRri:$a))]>;
182   def ii : InstPTX<(outs RC:$d),
183                    (ins MEMii:$a),
184                    !strconcat(opstr, ".%type\t$d, [$a]"),
185                    [(set RC:$d, (pat_load ADDRii:$a))]>;
186 }
187
188 multiclass PTX_ST<string opstr, RegisterClass RC, PatFrag pat_store> {
189   def rr : InstPTX<(outs),
190                    (ins RC:$d, MEMri:$a),
191                    !strconcat(opstr, ".%type\t[$a], $d"),
192                    [(pat_store RC:$d, ADDRrr:$a)]>;
193   def ri : InstPTX<(outs),
194                    (ins RC:$d, MEMri:$a),
195                    !strconcat(opstr, ".%type\t[$a], $d"),
196                    [(pat_store RC:$d, ADDRri:$a)]>;
197   def ii : InstPTX<(outs),
198                    (ins RC:$d, MEMii:$a),
199                    !strconcat(opstr, ".%type\t[$a], $d"),
200                    [(pat_store RC:$d, ADDRii:$a)]>;
201 }
202
203 //===----------------------------------------------------------------------===//
204 // Instructions
205 //===----------------------------------------------------------------------===//
206
207 ///===- Integer Arithmetic Instructions -----------------------------------===//
208
209 defm ADD : INT3<"add", add>;
210 defm SUB : INT3<"sub", sub>;
211
212 ///===- Logic and Shift Instructions --------------------------------------===//
213
214 defm SHL : INT3ntnc<"shl.b32", PTXshl>;
215 defm SRL : INT3ntnc<"shr.u32", PTXsrl>;
216 defm SRA : INT3ntnc<"shr.s32", PTXsra>;
217
218 ///===- Data Movement and Conversion Instructions -------------------------===//
219
220 let neverHasSideEffects = 1 in {
221   // rely on isMoveInstr to separate MOVpp, MOVrr, etc.
222   def MOVpp
223     : InstPTX<(outs Preds:$d), (ins Preds:$a), "mov.pred\t$d, $a", []>;
224   def MOVrr
225     : InstPTX<(outs RRegs32:$d), (ins RRegs32:$a), "mov.%type\t$d, $a", []>;
226 }
227
228 let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
229   def MOVpi
230     : InstPTX<(outs Preds:$d), (ins i1imm:$a), "mov.pred\t$d, $a",
231               [(set Preds:$d, imm:$a)]>;
232   def MOVri
233     : InstPTX<(outs RRegs32:$d), (ins i32imm:$a), "mov.s32\t$d, $a",
234               [(set RRegs32:$d, imm:$a)]>;
235 }
236
237 defm LDg : PTX_LD<"ld.global", RRegs32, load_global>;
238 defm LDc : PTX_LD<"ld.const",  RRegs32, load_constant>;
239 defm LDl : PTX_LD<"ld.local",  RRegs32, load_local>;
240 defm LDp : PTX_LD<"ld.param",  RRegs32, load_parameter>;
241 defm LDs : PTX_LD<"ld.shared", RRegs32, load_shared>;
242
243 def LDpi : InstPTX<(outs RRegs32:$d), (ins MEMpi:$a),
244                    "ld.param.%type\t$d, [$a]", []>;
245
246 defm STg : PTX_ST<"st.global", RRegs32, store_global>;
247 defm STl : PTX_ST<"st.local",  RRegs32, store_local>;
248 // Store to parameter state space requires PTX 2.0 or higher?
249 // defm STp : PTX_ST<"st.param",  RRegs32, store_parameter>;
250 defm STs : PTX_ST<"st.shared", RRegs32, store_shared>;
251
252 ///===- Control Flow Instructions -----------------------------------------===//
253
254 let isReturn = 1, isTerminator = 1, isBarrier = 1 in {
255   def EXIT : InstPTX<(outs), (ins), "exit", [(PTXexit)]>;
256   def RET  : InstPTX<(outs), (ins), "ret",  [(PTXret)]>;
257 }