[SparcV9] Add support for parsing branch instructions with prediction.
[oota-llvm.git] / lib / Target / Sparc / SparcInstrAliases.td
1 //===-- SparcInstrAliases.td - Instruction Aliases for Sparc Target -------===//
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 contains instruction aliases for Sparc.
11 //===----------------------------------------------------------------------===//
12
13 // Instruction aliases for conditional moves.
14
15 // mov<cond> <ccreg> rs2, rd
16 multiclass cond_mov_alias<string cond, int condVal, string ccreg,
17                           Instruction movrr, Instruction movri,
18                           Instruction fmovs, Instruction fmovd> {
19
20   // mov<cond> (%icc|%xcc|%fcc0), rs2, rd
21   def : InstAlias<!strconcat(!strconcat(!strconcat("mov", cond), ccreg),
22                              ", $rs2, $rd"),
23                   (movrr IntRegs:$rd, IntRegs:$rs2, condVal)>;
24
25   // mov<cond> (%icc|%xcc|%fcc0), simm11, rd
26   def : InstAlias<!strconcat(!strconcat(!strconcat("mov", cond), ccreg),
27                              ", $simm11, $rd"),
28                   (movri IntRegs:$rd, i32imm:$simm11, condVal)>;
29
30   // fmovs<cond> (%icc|%xcc|%fcc0), $rs2, $rd
31   def : InstAlias<!strconcat(!strconcat(!strconcat("fmovs", cond), ccreg),
32                              ", $rs2, $rd"),
33                   (fmovs FPRegs:$rd, FPRegs:$rs2, condVal)>;
34
35   // fmovd<cond> (%icc|%xcc|%fcc0), $rs2, $rd
36   def : InstAlias<!strconcat(!strconcat(!strconcat("fmovd", cond), ccreg),
37                              ", $rs2, $rd"),
38                   (fmovd DFPRegs:$rd, DFPRegs:$rs2, condVal)>;
39 }
40
41
42 // Instruction aliases for integer conditional branches and moves.
43 multiclass int_cond_alias<string cond, int condVal> {
44
45   // b<cond> $imm
46   def : InstAlias<!strconcat(!strconcat("b", cond), " $imm"),
47                   (BCOND brtarget:$imm, condVal)>;
48
49   // b<cond>,a $imm
50   def : InstAlias<!strconcat(!strconcat("b", cond), ",a $imm"),
51                   (BCONDA brtarget:$imm, condVal)>;
52
53   // b<cond> %icc, $imm
54   def : InstAlias<!strconcat(!strconcat("b", cond), " %icc, $imm"),
55                   (BPICC brtarget:$imm, condVal)>, Requires<[HasV9]>;
56
57   // b<cond>,pt %icc, $imm
58   def : InstAlias<!strconcat(!strconcat("b", cond), ",pt %icc, $imm"),
59                   (BPICC brtarget:$imm, condVal)>, Requires<[HasV9]>;
60
61   // b<cond>,a %icc, $imm
62   def : InstAlias<!strconcat(!strconcat("b", cond), ",a %icc, $imm"),
63                   (BPICCA brtarget:$imm, condVal)>, Requires<[HasV9]>;
64
65   // b<cond>,a,pt %icc, $imm
66   def : InstAlias<!strconcat(!strconcat("b", cond), ",a,pt %icc, $imm"),
67                   (BPICCA brtarget:$imm, condVal)>, Requires<[HasV9]>;
68
69   // b<cond>,pn %icc, $imm
70   def : InstAlias<!strconcat(!strconcat("b", cond), ",pn %icc, $imm"),
71                   (BPICCNT brtarget:$imm, condVal)>, Requires<[HasV9]>;
72
73   // b<cond>,a,pn %icc, $imm
74   def : InstAlias<!strconcat(!strconcat("b", cond), ",a,pn %icc, $imm"),
75                   (BPICCANT brtarget:$imm, condVal)>, Requires<[HasV9]>;
76
77   // b<cond> %xcc, $imm
78   def : InstAlias<!strconcat(!strconcat("b", cond), " %xcc, $imm"),
79                   (BPXCC brtarget:$imm, condVal)>, Requires<[Is64Bit]>;
80
81   // b<cond>,pt %xcc, $imm
82   def : InstAlias<!strconcat(!strconcat("b", cond), ",pt %xcc, $imm"),
83                   (BPXCC brtarget:$imm, condVal)>, Requires<[Is64Bit]>;
84
85   // b<cond>,a %xcc, $imm
86   def : InstAlias<!strconcat(!strconcat("b", cond), ",a %xcc, $imm"),
87                   (BPXCCA brtarget:$imm, condVal)>, Requires<[Is64Bit]>;
88
89   // b<cond>,a,pt %xcc, $imm
90   def : InstAlias<!strconcat(!strconcat("b", cond), ",a,pt %xcc, $imm"),
91                   (BPXCCA brtarget:$imm, condVal)>, Requires<[Is64Bit]>;
92
93   // b<cond>,pn %xcc, $imm
94   def : InstAlias<!strconcat(!strconcat("b", cond), ",pn %xcc, $imm"),
95                   (BPXCCNT brtarget:$imm, condVal)>, Requires<[Is64Bit]>;
96
97   // b<cond>,a,pn %xcc, $imm
98   def : InstAlias<!strconcat(!strconcat("b", cond), ",a,pn %xcc, $imm"),
99                   (BPXCCANT brtarget:$imm, condVal)>, Requires<[Is64Bit]>;
100
101
102   defm : cond_mov_alias<cond, condVal, " %icc",
103                             MOVICCrr, MOVICCri,
104                             FMOVS_ICC, FMOVD_ICC>, Requires<[HasV9]>;
105
106   defm : cond_mov_alias<cond, condVal, " %xcc",
107                             MOVXCCrr, MOVXCCri,
108                             FMOVS_XCC, FMOVD_XCC>, Requires<[Is64Bit]>;
109
110   // fmovq<cond> (%icc|%xcc), $rs2, $rd
111   def : InstAlias<!strconcat(!strconcat("fmovq", cond), " %icc, $rs2, $rd"),
112                   (FMOVQ_ICC QFPRegs:$rd, QFPRegs:$rs2, condVal)>,
113                   Requires<[HasV9, HasHardQuad]>;
114   def : InstAlias<!strconcat(!strconcat("fmovq", cond), " %xcc, $rs2, $rd"),
115                   (FMOVQ_XCC QFPRegs:$rd, QFPRegs:$rs2, condVal)>,
116                   Requires<[Is64Bit, HasHardQuad]>;
117
118 }
119
120
121 // Instruction aliases for floating point conditional branches and moves.
122 multiclass fp_cond_alias<string cond, int condVal> {
123
124   // fb<cond> $imm
125   def : InstAlias<!strconcat(!strconcat("fb", cond), " $imm"),
126                   (FBCOND brtarget:$imm, condVal), 0>;
127
128   // fb<cond>,a $imm
129   def : InstAlias<!strconcat(!strconcat("fb", cond), ",a $imm"),
130                   (FBCONDA brtarget:$imm, condVal), 0>;
131
132   // fb<cond> %fcc0, $imm
133   def : InstAlias<!strconcat(!strconcat("fb", cond), " %fcc0, $imm"),
134                   (BPFCC brtarget:$imm, condVal)>, Requires<[HasV9]>;
135
136   // fb<cond>,pt %fcc0, $imm
137   def : InstAlias<!strconcat(!strconcat("fb", cond), ",pt %fcc0, $imm"),
138                   (BPFCC brtarget:$imm, condVal)>, Requires<[HasV9]>;
139
140   // fb<cond>,a %fcc0, $imm
141   def : InstAlias<!strconcat(!strconcat("fb", cond), ",a %fcc0, $imm"),
142                   (BPFCCA brtarget:$imm, condVal)>, Requires<[HasV9]>;
143
144   // fb<cond>,a,pt %fcc0, $imm
145   def : InstAlias<!strconcat(!strconcat("fb", cond), ",a,pt %fcc0, $imm"),
146                   (BPFCCA brtarget:$imm, condVal)>, Requires<[HasV9]>;
147
148   // fb<cond>,pn %fcc0, $imm
149   def : InstAlias<!strconcat(!strconcat("fb", cond), ",pn %fcc0, $imm"),
150                   (BPFCCNT brtarget:$imm, condVal)>, Requires<[HasV9]>;
151
152   // fb<cond>,a,pn %fcc0, $imm
153   def : InstAlias<!strconcat(!strconcat("fb", cond), ",a,pn %fcc0, $imm"),
154                   (BPFCCANT brtarget:$imm, condVal)>, Requires<[HasV9]>;
155
156   defm : cond_mov_alias<cond, condVal, " %fcc0",
157                         MOVFCCrr, MOVFCCri,
158                         FMOVS_FCC, FMOVD_FCC>, Requires<[HasV9]>;
159
160   // fmovq<cond> %fcc0, $rs2, $rd
161   def : InstAlias<!strconcat(!strconcat("fmovq", cond), " %fcc0, $rs2, $rd"),
162                   (FMOVQ_ICC QFPRegs:$rd, QFPRegs:$rs2, condVal)>,
163                   Requires<[HasV9, HasHardQuad]>;
164 }
165
166 defm : int_cond_alias<"a",    0b1000>;
167 defm : int_cond_alias<"n",    0b0000>;
168 defm : int_cond_alias<"ne",   0b1001>;
169 defm : int_cond_alias<"e",    0b0001>;
170 defm : int_cond_alias<"g",    0b1010>;
171 defm : int_cond_alias<"le",   0b0010>;
172 defm : int_cond_alias<"ge",   0b1011>;
173 defm : int_cond_alias<"l",    0b0011>;
174 defm : int_cond_alias<"gu",   0b1100>;
175 defm : int_cond_alias<"leu",  0b0100>;
176 defm : int_cond_alias<"cc",   0b1101>;
177 defm : int_cond_alias<"cs",   0b0101>;
178 defm : int_cond_alias<"pos",  0b1110>;
179 defm : int_cond_alias<"neg",  0b0110>;
180 defm : int_cond_alias<"vc",   0b1111>;
181 defm : int_cond_alias<"vs",   0b0111>;
182
183 defm : fp_cond_alias<"a",     0b0000>;
184 defm : fp_cond_alias<"n",     0b1000>;
185 defm : fp_cond_alias<"u",     0b0111>;
186 defm : fp_cond_alias<"g",     0b0110>;
187 defm : fp_cond_alias<"ug",    0b0101>;
188 defm : fp_cond_alias<"l",     0b0100>;
189 defm : fp_cond_alias<"ul",    0b0011>;
190 defm : fp_cond_alias<"lg",    0b0010>;
191 defm : fp_cond_alias<"ne",    0b0001>;
192 defm : fp_cond_alias<"e",     0b1001>;
193 defm : fp_cond_alias<"ue",    0b1010>;
194 defm : fp_cond_alias<"ge",    0b1011>;
195 defm : fp_cond_alias<"uge",   0b1100>;
196 defm : fp_cond_alias<"le",    0b1101>;
197 defm : fp_cond_alias<"ule",   0b1110>;
198 defm : fp_cond_alias<"o",     0b1111>;
199
200
201 // Instruction aliases for JMPL.
202
203 // jmp addr -> jmpl addr, %g0
204 def : InstAlias<"jmp $addr", (JMPLrr G0, MEMrr:$addr)>;
205 def : InstAlias<"jmp $addr", (JMPLri G0, MEMri:$addr)>;
206
207 // call addr -> jmpl addr, %o7
208 def : InstAlias<"call $addr", (JMPLrr O7, MEMrr:$addr)>;
209 def : InstAlias<"call $addr", (JMPLri O7, MEMri:$addr)>;
210
211 // retl -> RETL 8
212 def : InstAlias<"retl", (RETL 8)>;
213
214 // ret -> RET 8
215 def : InstAlias<"ret", (RET 8)>;
216
217 // mov reg, rd -> or %g0, reg, rd
218 def : InstAlias<"mov $rs2, $rd", (ORrr IntRegs:$rd, G0, IntRegs:$rs2)>;
219
220 // mov simm13, rd -> or %g0, simm13, rd
221 def : InstAlias<"mov $simm13, $rd", (ORri IntRegs:$rd, G0, i32imm:$simm13)>;
222
223 // restore -> restore %g0, %g0, %g0
224 def : InstAlias<"restore", (RESTORErr G0, G0, G0)>;
225
226 def : MnemonicAlias<"addc", "addx">, Requires<[HasV9]>;
227 def : MnemonicAlias<"addccc", "addxcc">, Requires<[HasV9]>;
228
229 def : MnemonicAlias<"subc", "subx">, Requires<[HasV9]>;
230 def : MnemonicAlias<"subccc", "subxcc">, Requires<[HasV9]>;