ptx: remove reg-reg addressing mode and st.const
[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
124 //===----------------------------------------------------------------------===//
125 // PTX Specific Node Definitions
126 //===----------------------------------------------------------------------===//
127
128 // PTX allow generic 3-reg shifts like shl r0, r1, r2
129 def PTXshl : SDNode<"ISD::SHL", SDTIntBinOp>;
130 def PTXsrl : SDNode<"ISD::SRL", SDTIntBinOp>;
131 def PTXsra : SDNode<"ISD::SRA", SDTIntBinOp>;
132
133 def PTXexit
134   : SDNode<"PTXISD::EXIT", SDTNone, [SDNPHasChain]>;
135 def PTXret
136   : SDNode<"PTXISD::RET",  SDTNone, [SDNPHasChain]>;
137
138 //===----------------------------------------------------------------------===//
139 // Instruction Class Templates
140 //===----------------------------------------------------------------------===//
141
142 multiclass INT3<string opcstr, SDNode opnode> {
143   def rr : InstPTX<(outs RRegs32:$d),
144                    (ins RRegs32:$a, RRegs32:$b),
145                    !strconcat(opcstr, ".%type\t$d, $a, $b"),
146                    [(set RRegs32:$d, (opnode RRegs32:$a, RRegs32:$b))]>;
147   def ri : InstPTX<(outs RRegs32:$d),
148                    (ins RRegs32:$a, i32imm:$b),
149                    !strconcat(opcstr, ".%type\t$d, $a, $b"),
150                    [(set RRegs32:$d, (opnode RRegs32:$a, imm:$b))]>;
151 }
152
153 // no %type directive, non-communtable
154 multiclass INT3ntnc<string opcstr, SDNode opnode> {
155   def rr : InstPTX<(outs RRegs32:$d),
156                    (ins RRegs32:$a, RRegs32:$b),
157                    !strconcat(opcstr, "\t$d, $a, $b"),
158                    [(set RRegs32:$d, (opnode RRegs32:$a, RRegs32:$b))]>;
159   def ri : InstPTX<(outs RRegs32:$d),
160                    (ins RRegs32:$a, i32imm:$b),
161                    !strconcat(opcstr, "\t$d, $a, $b"),
162                    [(set RRegs32:$d, (opnode RRegs32:$a, imm:$b))]>;
163   def ir : InstPTX<(outs RRegs32:$d),
164                    (ins i32imm:$a, RRegs32:$b),
165                    !strconcat(opcstr, "\t$d, $a, $b"),
166                    [(set RRegs32:$d, (opnode imm:$a, RRegs32:$b))]>;
167 }
168
169 multiclass PTX_LD<string opstr, RegisterClass RC, PatFrag pat_load> {
170   def rr : InstPTX<(outs RC:$d),
171                    (ins MEMri:$a),
172                    !strconcat(opstr, ".%type\t$d, [$a]"),
173                    [(set RC:$d, (pat_load ADDRrr:$a))]>;
174   def ri : InstPTX<(outs RC:$d),
175                    (ins MEMri:$a),
176                    !strconcat(opstr, ".%type\t$d, [$a]"),
177                    [(set RC:$d, (pat_load ADDRri:$a))]>;
178   def ii : InstPTX<(outs RC:$d),
179                    (ins MEMii:$a),
180                    !strconcat(opstr, ".%type\t$d, [$a]"),
181                    [(set RC:$d, (pat_load ADDRii:$a))]>;
182 }
183
184 multiclass PTX_ST<string opstr, RegisterClass RC, PatFrag pat_store> {
185   def rr : InstPTX<(outs),
186                    (ins RC:$d, MEMri:$a),
187                    !strconcat(opstr, ".%type\t[$a], $d"),
188                    [(pat_store RC:$d, ADDRrr:$a)]>;
189   def ri : InstPTX<(outs),
190                    (ins RC:$d, MEMri:$a),
191                    !strconcat(opstr, ".%type\t[$a], $d"),
192                    [(pat_store RC:$d, ADDRri:$a)]>;
193   def ii : InstPTX<(outs),
194                    (ins RC:$d, MEMii:$a),
195                    !strconcat(opstr, ".%type\t[$a], $d"),
196                    [(pat_store RC:$d, ADDRii:$a)]>;
197 }
198
199 //===----------------------------------------------------------------------===//
200 // Instructions
201 //===----------------------------------------------------------------------===//
202
203 ///===- Integer Arithmetic Instructions -----------------------------------===//
204
205 defm ADD : INT3<"add", add>;
206 defm SUB : INT3<"sub", sub>;
207
208 ///===- Logic and Shift Instructions --------------------------------------===//
209
210 defm SHL : INT3ntnc<"shl.b32", PTXshl>;
211 defm SRL : INT3ntnc<"shr.u32", PTXsrl>;
212 defm SRA : INT3ntnc<"shr.s32", PTXsra>;
213
214 ///===- Data Movement and Conversion Instructions -------------------------===//
215
216 let neverHasSideEffects = 1 in {
217   // rely on isMoveInstr to separate MOVpp, MOVrr, etc.
218   def MOVpp
219     : InstPTX<(outs Preds:$d), (ins Preds:$a), "mov.pred\t$d, $a", []>;
220   def MOVrr
221     : InstPTX<(outs RRegs32:$d), (ins RRegs32:$a), "mov.%type\t$d, $a", []>;
222 }
223
224 let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
225   def MOVpi
226     : InstPTX<(outs Preds:$d), (ins i1imm:$a), "mov.pred\t$d, $a",
227               [(set Preds:$d, imm:$a)]>;
228   def MOVri
229     : InstPTX<(outs RRegs32:$d), (ins i32imm:$a), "mov.s32\t$d, $a",
230               [(set RRegs32:$d, imm:$a)]>;
231 }
232
233 defm LDg : PTX_LD<"ld.global", RRegs32, load_global>;
234 defm LDc : PTX_LD<"ld.const",  RRegs32, load_constant>;
235 defm LDl : PTX_LD<"ld.local",  RRegs32, load_local>;
236 defm LDp : PTX_LD<"ld.param",  RRegs32, load_parameter>;
237 defm LDs : PTX_LD<"ld.shared", RRegs32, load_shared>;
238
239 defm STg : PTX_ST<"st.global", RRegs32, store_global>;
240 defm STl : PTX_ST<"st.local",  RRegs32, store_local>;
241 defm STp : PTX_ST<"st.param",  RRegs32, store_parameter>;
242 defm STs : PTX_ST<"st.shared", RRegs32, store_shared>;
243
244 ///===- Control Flow Instructions -----------------------------------------===//
245
246 let isReturn = 1, isTerminator = 1, isBarrier = 1 in {
247   def EXIT : InstPTX<(outs), (ins), "exit", [(PTXexit)]>;
248   def RET  : InstPTX<(outs), (ins), "ret",  [(PTXret)]>;
249 }