ptx: add ld instruction
[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 ADDRri : ComplexPattern<i32, 2, "SelectADDRri", [], []>;
33 def ADDRii : ComplexPattern<i32, 2, "SelectADDRii", [], []>;
34
35 // Address operands
36 def MEMri : Operand<i32> {
37   let PrintMethod = "printMemOperand";
38   let MIOperandInfo = (ops RRegs32, i32imm);
39 }
40 def MEMii : Operand<i32> {
41   let PrintMethod = "printMemOperand";
42   let MIOperandInfo = (ops i32imm, i32imm);
43 }
44
45 //===----------------------------------------------------------------------===//
46 // PTX Specific Node Definitions
47 //===----------------------------------------------------------------------===//
48
49 def PTXexit
50   : SDNode<"PTXISD::EXIT", SDTNone, [SDNPHasChain]>;
51 def PTXret
52   : SDNode<"PTXISD::RET",  SDTNone, [SDNPHasChain]>;
53
54 //===----------------------------------------------------------------------===//
55 // Instruction Class Templates
56 //===----------------------------------------------------------------------===//
57
58 multiclass INT3<string opcstr, SDNode opnode> {
59   def rr : InstPTX<(outs RRegs32:$d),
60                    (ins RRegs32:$a, RRegs32:$b),
61                    !strconcat(opcstr, ".%type\t$d, $a, $b"),
62                    [(set RRegs32:$d, (opnode RRegs32:$a, RRegs32:$b))]>;
63   def ri : InstPTX<(outs RRegs32:$d),
64                    (ins RRegs32:$a, i32imm:$b),
65                    !strconcat(opcstr, ".%type\t$d, $a, $b"),
66                    [(set RRegs32:$d, (opnode RRegs32:$a, imm:$b))]>;
67 }
68
69 multiclass PTX_LD<string opstr, RegisterClass RC, PatFrag pat_load> {
70   def ri : InstPTX<(outs RC:$d),
71                    (ins MEMri:$a),
72                    !strconcat(opstr, ".%type\t$d, [$a]"),
73                    [(set RC:$d, (pat_load ADDRri:$a))]>;
74   def ii : InstPTX<(outs RC:$d),
75                    (ins MEMii:$a),
76                    !strconcat(opstr, ".%type\t$d, [$a]"),
77                    [(set RC:$d, (pat_load ADDRii:$a))]>;
78 }
79
80 //===----------------------------------------------------------------------===//
81 // Instructions
82 //===----------------------------------------------------------------------===//
83
84 ///===- Integer Arithmetic Instructions -----------------------------------===//
85
86 defm ADD : INT3<"add", add>;
87 defm SUB : INT3<"sub", sub>;
88
89 ///===- Data Movement and Conversion Instructions -------------------------===//
90
91 let neverHasSideEffects = 1 in {
92   // rely on isMoveInstr to separate MOVpp, MOVrr, etc.
93   def MOVpp
94     : InstPTX<(outs Preds:$d), (ins Preds:$a), "mov.pred\t$d, $a", []>;
95   def MOVrr
96     : InstPTX<(outs RRegs32:$d), (ins RRegs32:$a), "mov.%type\t$d, $a", []>;
97 }
98
99 let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
100   def MOVpi
101     : InstPTX<(outs Preds:$d), (ins i1imm:$a), "mov.pred\t$d, $a",
102               [(set Preds:$d, imm:$a)]>;
103   def MOVri
104     : InstPTX<(outs RRegs32:$d), (ins i32imm:$a), "mov.s32\t$d, $a",
105               [(set RRegs32:$d, imm:$a)]>;
106 }
107
108 defm LDg : PTX_LD<"ld.global", RRegs32, load_global>;
109
110 ///===- Control Flow Instructions -----------------------------------------===//
111
112 let isReturn = 1, isTerminator = 1, isBarrier = 1 in {
113   def EXIT : InstPTX<(outs), (ins), "exit", [(PTXexit)]>;
114   def RET  : InstPTX<(outs), (ins), "ret",  [(PTXret)]>;
115 }