1 //===- PTXInstrInfo.td - PTX Instruction defs -----------------*- tblgen-*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file describes the PTX instructions in TableGen format.
12 //===----------------------------------------------------------------------===//
14 //===----------------------------------------------------------------------===//
15 // Instruction format superclass
16 //===----------------------------------------------------------------------===//
18 include "PTXInstrFormats.td"
20 //===----------------------------------------------------------------------===//
21 // Instruction Pattern Stuff
22 //===----------------------------------------------------------------------===//
24 def load_global : PatFrag<(ops node:$ptr), (load node:$ptr), [{
26 const PointerType *PT;
27 if ((Src = cast<LoadSDNode>(N)->getSrcValue()) &&
28 (PT = dyn_cast<PointerType>(Src->getType())))
29 return PT->getAddressSpace() == PTX::GLOBAL;
33 def load_constant : PatFrag<(ops node:$ptr), (load node:$ptr), [{
35 const PointerType *PT;
36 if ((Src = cast<LoadSDNode>(N)->getSrcValue()) &&
37 (PT = dyn_cast<PointerType>(Src->getType())))
38 return PT->getAddressSpace() == PTX::CONSTANT;
42 def load_local : PatFrag<(ops node:$ptr), (load node:$ptr), [{
44 const PointerType *PT;
45 if ((Src = cast<LoadSDNode>(N)->getSrcValue()) &&
46 (PT = dyn_cast<PointerType>(Src->getType())))
47 return PT->getAddressSpace() == PTX::LOCAL;
51 def load_parameter : PatFrag<(ops node:$ptr), (load node:$ptr), [{
53 const PointerType *PT;
54 if ((Src = cast<LoadSDNode>(N)->getSrcValue()) &&
55 (PT = dyn_cast<PointerType>(Src->getType())))
56 return PT->getAddressSpace() == PTX::PARAMETER;
60 def load_shared : PatFrag<(ops node:$ptr), (load node:$ptr), [{
62 const PointerType *PT;
63 if ((Src = cast<LoadSDNode>(N)->getSrcValue()) &&
64 (PT = dyn_cast<PointerType>(Src->getType())))
65 return PT->getAddressSpace() == PTX::SHARED;
70 : PatFrag<(ops node:$d, node:$ptr), (store node:$d, node:$ptr), [{
72 const PointerType *PT;
73 if ((Src = cast<StoreSDNode>(N)->getSrcValue()) &&
74 (PT = dyn_cast<PointerType>(Src->getType())))
75 return PT->getAddressSpace() == PTX::GLOBAL;
80 : PatFrag<(ops node:$d, node:$ptr), (store node:$d, node:$ptr), [{
82 const PointerType *PT;
83 if ((Src = cast<StoreSDNode>(N)->getSrcValue()) &&
84 (PT = dyn_cast<PointerType>(Src->getType())))
85 return PT->getAddressSpace() == PTX::LOCAL;
90 : PatFrag<(ops node:$d, node:$ptr), (store node:$d, node:$ptr), [{
92 const PointerType *PT;
93 if ((Src = cast<StoreSDNode>(N)->getSrcValue()) &&
94 (PT = dyn_cast<PointerType>(Src->getType())))
95 return PT->getAddressSpace() == PTX::PARAMETER;
100 : PatFrag<(ops node:$d, node:$ptr), (store node:$d, node:$ptr), [{
102 const PointerType *PT;
103 if ((Src = cast<StoreSDNode>(N)->getSrcValue()) &&
104 (PT = dyn_cast<PointerType>(Src->getType())))
105 return PT->getAddressSpace() == PTX::SHARED;
110 def ADDRrr : ComplexPattern<i32, 2, "SelectADDRrr", [], []>;
111 def ADDRri : ComplexPattern<i32, 2, "SelectADDRri", [], []>;
112 def ADDRii : ComplexPattern<i32, 2, "SelectADDRii", [], []>;
115 def MEMri : Operand<i32> {
116 let PrintMethod = "printMemOperand";
117 let MIOperandInfo = (ops RRegs32, i32imm);
119 def MEMii : Operand<i32> {
120 let PrintMethod = "printMemOperand";
121 let MIOperandInfo = (ops i32imm, i32imm);
124 //===----------------------------------------------------------------------===//
125 // PTX Specific Node Definitions
126 //===----------------------------------------------------------------------===//
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>;
134 : SDNode<"PTXISD::EXIT", SDTNone, [SDNPHasChain]>;
136 : SDNode<"PTXISD::RET", SDTNone, [SDNPHasChain]>;
138 //===----------------------------------------------------------------------===//
139 // Instruction Class Templates
140 //===----------------------------------------------------------------------===//
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))]>;
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))]>;
169 multiclass PTX_LD<string opstr, RegisterClass RC, PatFrag pat_load> {
170 def rr : InstPTX<(outs RC:$d),
172 !strconcat(opstr, ".%type\t$d, [$a]"),
173 [(set RC:$d, (pat_load ADDRrr:$a))]>;
174 def ri : InstPTX<(outs RC:$d),
176 !strconcat(opstr, ".%type\t$d, [$a]"),
177 [(set RC:$d, (pat_load ADDRri:$a))]>;
178 def ii : InstPTX<(outs RC:$d),
180 !strconcat(opstr, ".%type\t$d, [$a]"),
181 [(set RC:$d, (pat_load ADDRii:$a))]>;
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)]>;
199 //===----------------------------------------------------------------------===//
201 //===----------------------------------------------------------------------===//
203 ///===- Integer Arithmetic Instructions -----------------------------------===//
205 defm ADD : INT3<"add", add>;
206 defm SUB : INT3<"sub", sub>;
208 ///===- Logic and Shift Instructions --------------------------------------===//
210 defm SHL : INT3ntnc<"shl.b32", PTXshl>;
211 defm SRL : INT3ntnc<"shr.u32", PTXsrl>;
212 defm SRA : INT3ntnc<"shr.s32", PTXsra>;
214 ///===- Data Movement and Conversion Instructions -------------------------===//
216 let neverHasSideEffects = 1 in {
217 // rely on isMoveInstr to separate MOVpp, MOVrr, etc.
219 : InstPTX<(outs Preds:$d), (ins Preds:$a), "mov.pred\t$d, $a", []>;
221 : InstPTX<(outs RRegs32:$d), (ins RRegs32:$a), "mov.%type\t$d, $a", []>;
224 let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
226 : InstPTX<(outs Preds:$d), (ins i1imm:$a), "mov.pred\t$d, $a",
227 [(set Preds:$d, imm:$a)]>;
229 : InstPTX<(outs RRegs32:$d), (ins i32imm:$a), "mov.s32\t$d, $a",
230 [(set RRegs32:$d, imm:$a)]>;
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>;
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>;
244 ///===- Control Flow Instructions -----------------------------------------===//
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)]>;