ptx: add ld instruction and test
[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   if (const Value *Src = cast<LoadSDNode>(N)->getSrcValue())
26     if (const PointerType *PT = dyn_cast<PointerType>(Src->getType()))
27       return PT->getAddressSpace() <= 255;
28   return false;
29 }]>;
30
31 // Addressing modes.
32 def ADDRrr : ComplexPattern<i32, 2, "SelectADDRrr", [], []>;
33 def ADDRri : ComplexPattern<i32, 2, "SelectADDRri", [], []>;
34 def ADDRii : ComplexPattern<i32, 2, "SelectADDRii", [], []>;
35
36 // Address operands
37 def MEMrr : Operand<i32> {
38   let PrintMethod = "printMemOperand";
39   let MIOperandInfo = (ops RRegs32, RRegs32);
40 }
41 def MEMri : Operand<i32> {
42   let PrintMethod = "printMemOperand";
43   let MIOperandInfo = (ops RRegs32, i32imm);
44 }
45 def MEMii : Operand<i32> {
46   let PrintMethod = "printMemOperand";
47   let MIOperandInfo = (ops i32imm, i32imm);
48 }
49
50 //===----------------------------------------------------------------------===//
51 // PTX Specific Node Definitions
52 //===----------------------------------------------------------------------===//
53
54 // PTX allow generic 3-reg shifts like shl r0, r1, r2
55 def PTXshl : SDNode<"ISD::SHL", SDTIntBinOp>;
56 def PTXsrl : SDNode<"ISD::SRL", SDTIntBinOp>;
57 def PTXsra : SDNode<"ISD::SRA", SDTIntBinOp>;
58
59 def PTXexit
60   : SDNode<"PTXISD::EXIT", SDTNone, [SDNPHasChain]>;
61 def PTXret
62   : SDNode<"PTXISD::RET",  SDTNone, [SDNPHasChain]>;
63
64 //===----------------------------------------------------------------------===//
65 // Instruction Class Templates
66 //===----------------------------------------------------------------------===//
67
68 multiclass INT3<string opcstr, SDNode opnode> {
69   def rr : InstPTX<(outs RRegs32:$d),
70                    (ins RRegs32:$a, RRegs32:$b),
71                    !strconcat(opcstr, ".%type\t$d, $a, $b"),
72                    [(set RRegs32:$d, (opnode RRegs32:$a, RRegs32:$b))]>;
73   def ri : InstPTX<(outs RRegs32:$d),
74                    (ins RRegs32:$a, i32imm:$b),
75                    !strconcat(opcstr, ".%type\t$d, $a, $b"),
76                    [(set RRegs32:$d, (opnode RRegs32:$a, imm:$b))]>;
77 }
78
79 // no %type directive, non-communtable
80 multiclass INT3ntnc<string opcstr, SDNode opnode> {
81   def rr : InstPTX<(outs RRegs32:$d),
82                    (ins RRegs32:$a, RRegs32:$b),
83                    !strconcat(opcstr, "\t$d, $a, $b"),
84                    [(set RRegs32:$d, (opnode RRegs32:$a, RRegs32:$b))]>;
85   def ri : InstPTX<(outs RRegs32:$d),
86                    (ins RRegs32:$a, i32imm:$b),
87                    !strconcat(opcstr, "\t$d, $a, $b"),
88                    [(set RRegs32:$d, (opnode RRegs32:$a, imm:$b))]>;
89   def ir : InstPTX<(outs RRegs32:$d),
90                    (ins i32imm:$a, RRegs32:$b),
91                    !strconcat(opcstr, "\t$d, $a, $b"),
92                    [(set RRegs32:$d, (opnode imm:$a, RRegs32:$b))]>;
93 }
94
95 multiclass PTX_LD<string opstr, RegisterClass RC, PatFrag pat_load> {
96   def rr : InstPTX<(outs RC:$d),
97                    (ins MEMrr:$a),
98                    !strconcat(opstr, ".%type\t$d, [$a]"),
99                    [(set RC:$d, (pat_load ADDRrr:$a))]>;
100   def ri : InstPTX<(outs RC:$d),
101                    (ins MEMri:$a),
102                    !strconcat(opstr, ".%type\t$d, [$a]"),
103                    [(set RC:$d, (pat_load ADDRri:$a))]>;
104   def ii : InstPTX<(outs RC:$d),
105                    (ins MEMii:$a),
106                    !strconcat(opstr, ".%type\t$d, [$a]"),
107                    [(set RC:$d, (pat_load ADDRii:$a))]>;
108 }
109
110 //===----------------------------------------------------------------------===//
111 // Instructions
112 //===----------------------------------------------------------------------===//
113
114 ///===- Integer Arithmetic Instructions -----------------------------------===//
115
116 defm ADD : INT3<"add", add>;
117 defm SUB : INT3<"sub", sub>;
118
119 ///===- Logic and Shift Instructions --------------------------------------===//
120
121 defm SHL : INT3ntnc<"shl.b32", PTXshl>;
122 defm SRL : INT3ntnc<"shr.u32", PTXsrl>;
123 defm SRA : INT3ntnc<"shr.s32", PTXsra>;
124
125 ///===- Data Movement and Conversion Instructions -------------------------===//
126
127 let neverHasSideEffects = 1 in {
128   // rely on isMoveInstr to separate MOVpp, MOVrr, etc.
129   def MOVpp
130     : InstPTX<(outs Preds:$d), (ins Preds:$a), "mov.pred\t$d, $a", []>;
131   def MOVrr
132     : InstPTX<(outs RRegs32:$d), (ins RRegs32:$a), "mov.%type\t$d, $a", []>;
133 }
134
135 let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
136   def MOVpi
137     : InstPTX<(outs Preds:$d), (ins i1imm:$a), "mov.pred\t$d, $a",
138               [(set Preds:$d, imm:$a)]>;
139   def MOVri
140     : InstPTX<(outs RRegs32:$d), (ins i32imm:$a), "mov.s32\t$d, $a",
141               [(set RRegs32:$d, imm:$a)]>;
142 }
143
144 defm LDg : PTX_LD<"ld.global", RRegs32, load_global>;
145
146 ///===- Control Flow Instructions -----------------------------------------===//
147
148 let isReturn = 1, isTerminator = 1, isBarrier = 1 in {
149   def EXIT : InstPTX<(outs), (ins), "exit", [(PTXexit)]>;
150   def RET  : InstPTX<(outs), (ins), "ret",  [(PTXret)]>;
151 }