Define a statistic for the number of slots that were filled with useful
[oota-llvm.git] / lib / Target / Mips / Mips64InstrInfo.td
1 //===- Mips64InstrInfo.td - Mips64 Instruction Information -*- tablegen -*-===//
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 Mips64 instructions.
11 //
12 //===----------------------------------------------------------------------===//
13
14 //===----------------------------------------------------------------------===//
15 // Mips64 Instruction Predicate Definitions.
16 //===----------------------------------------------------------------------===//
17 def HasMips64    : Predicate<"Subtarget.hasMips64()">;
18 def HasMips64r2  : Predicate<"Subtarget.hasMips64r2()">;
19
20 //===----------------------------------------------------------------------===//
21 // Mips Operand, Complex Patterns and Transformations Definitions.
22 //===----------------------------------------------------------------------===//
23
24 // Instruction operand types
25 def simm16_64      : Operand<i64>;
26 def shamt_64       : Operand<i64>;
27
28 // Unsigned Operand
29 def uimm16_64      : Operand<i64> {
30   let PrintMethod = "printUnsignedImm";
31 }
32
33 // Transformation Function - get Imm - 32.
34 def Subtract32 : SDNodeXForm<imm, [{
35   return getI32Imm((unsigned)N->getZExtValue() - 32);
36 }]>;
37
38 // imm32_63 predicate - True if imm is in range [32, 63].
39 def imm32_63 : ImmLeaf<i64,
40                        [{return (int32_t)Imm >= 32 && (int32_t)Imm < 64;}],
41                        Subtract32>;
42
43 //===----------------------------------------------------------------------===//
44 // Instructions specific format
45 //===----------------------------------------------------------------------===//
46
47 // Arithmetic 3 register operands
48 class ArithR64<bits<6> op, bits<6> func, string instr_asm, SDNode OpNode,
49                InstrItinClass itin, bit isComm = 0>:
50   FR<op, func, (outs CPU64Regs:$dst), (ins CPU64Regs:$b, CPU64Regs:$c),
51      !strconcat(instr_asm, "\t$dst, $b, $c"),
52      [(set CPU64Regs:$dst, (OpNode CPU64Regs:$b, CPU64Regs:$c))], itin> {
53   let isCommutable = isComm;
54 }
55
56 // Arithmetic 2 register operands
57 class ArithI64<bits<6> op, string instr_asm, SDNode OpNode,
58                Operand Od, PatLeaf imm_type> :
59   FI<op, (outs CPU64Regs:$dst), (ins CPU64Regs:$b, Od:$c),
60      !strconcat(instr_asm, "\t$dst, $b, $c"),
61      [(set CPU64Regs:$dst, (OpNode CPU64Regs:$b, imm_type:$c))], IIAlu>;
62
63 //  Logical
64 let isCommutable = 1 in
65 class LogicR64<bits<6> func, string instr_asm, SDNode OpNode>:
66   FR<0x00, func, (outs CPU64Regs:$dst), (ins CPU64Regs:$b, CPU64Regs:$c),
67      !strconcat(instr_asm, "\t$dst, $b, $c"),
68      [(set CPU64Regs:$dst, (OpNode CPU64Regs:$b, CPU64Regs:$c))], IIAlu>;
69
70 class LogicI64<bits<6> op, string instr_asm, SDNode OpNode>:
71   FI<op, (outs CPU64Regs:$dst), (ins CPU64Regs:$b, uimm16_64:$c),
72      !strconcat(instr_asm, "\t$dst, $b, $c"),
73      [(set CPU64Regs:$dst, (OpNode CPU64Regs:$b, immZExt16:$c))], IIAlu>;
74
75 let isCommutable = 1 in
76 class LogicNOR64<bits<6> op, bits<6> func, string instr_asm>:
77   FR<op, func, (outs CPU64Regs:$dst), (ins CPU64Regs:$b, CPU64Regs:$c),
78      !strconcat(instr_asm, "\t$dst, $b, $c"),
79      [(set CPU64Regs:$dst, (not (or CPU64Regs:$b, CPU64Regs:$c)))], IIAlu>;
80
81 // Shifts
82 class LogicR_shift_rotate_imm64<bits<6> func, bits<5> _rs, string instr_asm,
83                                 SDNode OpNode, PatFrag PF>:
84   FR<0x00, func, (outs CPU64Regs:$dst), (ins CPU64Regs:$b, shamt_64:$c),
85      !strconcat(instr_asm, "\t$dst, $b, $c"),
86      [(set CPU64Regs:$dst, (OpNode CPU64Regs:$b, (i64 PF:$c)))],
87      IIAlu> {
88   let rs = _rs;
89 }
90
91 class LogicR_shift_rotate_reg64<bits<6> func, bits<5> _shamt, string instr_asm,
92                                 SDNode OpNode>:
93   FR<0x00, func, (outs CPU64Regs:$dst), (ins CPU64Regs:$c, CPU64Regs:$b),
94      !strconcat(instr_asm, "\t$dst, $b, $c"),
95      [(set CPU64Regs:$dst, (OpNode CPU64Regs:$b, CPU64Regs:$c))], IIAlu> {
96   let shamt = _shamt;
97 }
98
99 // Mul, Div
100 let Defs = [HI64, LO64] in {
101   let isCommutable = 1 in
102   class Mul64<bits<6> func, string instr_asm, InstrItinClass itin>:
103     FR<0x00, func, (outs), (ins CPU64Regs:$a, CPU64Regs:$b),
104        !strconcat(instr_asm, "\t$a, $b"), [], itin>;
105
106   class Div64<SDNode op, bits<6> func, string instr_asm, InstrItinClass itin>:
107               FR<0x00, func, (outs), (ins CPU64Regs:$a, CPU64Regs:$b),
108               !strconcat(instr_asm, "\t$$zero, $a, $b"),
109               [(op CPU64Regs:$a, CPU64Regs:$b)], itin>;
110 }
111
112 // Move from Hi/Lo
113 let shamt = 0 in {
114 let rs = 0, rt = 0 in
115 class MoveFromLOHI64<bits<6> func, string instr_asm>:
116   FR<0x00, func, (outs CPU64Regs:$dst), (ins),
117      !strconcat(instr_asm, "\t$dst"), [], IIHiLo>;
118
119 let rt = 0, rd = 0 in
120 class MoveToLOHI64<bits<6> func, string instr_asm>:
121   FR<0x00, func, (outs), (ins CPU64Regs:$src),
122      !strconcat(instr_asm, "\t$src"), [], IIHiLo>;
123 }
124
125 // Count Leading Ones/Zeros in Word
126 class CountLeading64<bits<6> func, string instr_asm, list<dag> pattern>:
127   FR<0x1c, func, (outs CPU64Regs:$dst), (ins CPU64Regs:$src),
128      !strconcat(instr_asm, "\t$dst, $src"), pattern, IIAlu>,
129      Requires<[HasBitCount]> {
130   let shamt = 0;
131   let rt = rd;
132 }
133
134 //===----------------------------------------------------------------------===//
135 // Instruction definition
136 //===----------------------------------------------------------------------===//
137
138 /// Arithmetic Instructions (ALU Immediate)
139 def DADDiu   : ArithI64<0x19, "daddiu", add, simm16_64, immSExt16>;
140 def DANDi    : LogicI64<0x0c, "andi", and>;
141 def DORi     : LogicI64<0x0d, "ori",  or>;
142 def DXORi    : LogicI64<0x0e, "xori",  xor>;
143
144 /// Arithmetic Instructions (3-Operand, R-Type)
145 def DADDu    : ArithR64<0x00, 0x2d, "daddu", add, IIAlu, 1>;
146 def DSUBu    : ArithR64<0x00, 0x2f, "dsubu", sub, IIAlu>;
147 def DAND     : LogicR64<0x24, "and", and>;
148 def DOR      : LogicR64<0x25, "or", or>;
149 def DXOR     : LogicR64<0x26, "xor", xor>;
150 def DNOR     : LogicNOR64<0x00, 0x27, "nor">;
151
152 /// Shift Instructions
153 def DSLL     : LogicR_shift_rotate_imm64<0x38, 0x00, "dsll", shl, immZExt5>;
154 def DSRL     : LogicR_shift_rotate_imm64<0x3a, 0x00, "dsrl", srl, immZExt5>;
155 def DSRA     : LogicR_shift_rotate_imm64<0x3b, 0x00, "dsra", sra, immZExt5>;
156 def DSLL32   : LogicR_shift_rotate_imm64<0x3c, 0x00, "dsll32", shl, imm32_63>;
157 def DSRL32   : LogicR_shift_rotate_imm64<0x3e, 0x00, "dsrl32", srl, imm32_63>;
158 def DSRA32   : LogicR_shift_rotate_imm64<0x3f, 0x00, "dsra32", sra, imm32_63>;
159 def DSLLV    : LogicR_shift_rotate_reg64<0x24, 0x00, "dsllv", shl>;
160 def DSRLV    : LogicR_shift_rotate_reg64<0x26, 0x00, "dsrlv", srl>;
161 def DSRAV    : LogicR_shift_rotate_reg64<0x27, 0x00, "dsrav", sra>;
162
163 // Rotate Instructions
164 let Predicates = [HasMips64r2] in {
165   def DROTR    : LogicR_shift_rotate_imm64<0x3a, 0x01, "drotr", rotr, immZExt5>;
166   def DROTR32  : LogicR_shift_rotate_imm64<0x3e, 0x01, "drotr32", rotr,
167                                            imm32_63>;
168   def DROTRV   : LogicR_shift_rotate_reg64<0x16, 0x01, "drotrv", rotr>;
169 }
170
171 /// Multiply and Divide Instructions.
172 def DMULT    : Mul64<0x1c, "dmult", IIImul>;
173 def DMULTu   : Mul64<0x1d, "dmultu", IIImul>;
174 def DSDIV    : Div64<MipsDivRem, 0x1e, "ddiv", IIIdiv>;
175 def DUDIV    : Div64<MipsDivRemU, 0x1f, "ddivu", IIIdiv>;
176
177 let Defs = [HI64] in
178   def MTHI64  : MoveToLOHI64<0x11, "mthi">;
179 let Defs = [LO64] in
180   def MTLO64  : MoveToLOHI64<0x13, "mtlo">;
181
182 let Uses = [HI64] in
183   def MFHI64  : MoveFromLOHI64<0x10, "mfhi">;
184 let Uses = [LO64] in
185   def MFLO64  : MoveFromLOHI64<0x12, "mflo">;
186
187 /// Count Leading
188 def DCLZ : CountLeading64<0x24, "dclz",
189                           [(set CPU64Regs:$dst, (ctlz CPU64Regs:$src))]>;
190 def DCLO : CountLeading64<0x25, "dclo",
191                           [(set CPU64Regs:$dst, (ctlz (not CPU64Regs:$src)))]>;
192
193 //===----------------------------------------------------------------------===//
194 //  Arbitrary patterns that map to one or more instructions
195 //===----------------------------------------------------------------------===//
196
197 // Small immediates
198 def : Pat<(i64 immSExt16:$in),
199           (DADDiu ZERO_64, imm:$in)>;
200 def : Pat<(i64 immZExt16:$in),
201           (DORi ZERO_64, imm:$in)>;