add isTerminatortto b and bcond
[oota-llvm.git] / lib / Target / ARM / ARMInstrInfo.td
1 //===- ARMInstrInfo.td - Target Description for ARM Target ----------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the "Instituto Nokia de Tecnologia" and
6 // is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
8 //
9 //===----------------------------------------------------------------------===//
10 //
11 // This file describes the ARM instructions in TableGen format.
12 //
13 //===----------------------------------------------------------------------===//
14
15 // Address operands
16 def op_addr_mode1 : Operand<iPTR> {
17   let PrintMethod = "printAddrMode1";
18   let NumMIOperands = 3;
19   let MIOperandInfo = (ops ptr_rc, ptr_rc, i32imm);
20 }
21
22 def op_addr_mode5 : Operand<iPTR> {
23   let PrintMethod = "printAddrMode5";
24   let NumMIOperands = 2;
25   let MIOperandInfo = (ops ptr_rc, i32imm);
26 }
27
28 def memri : Operand<iPTR> {
29   let PrintMethod = "printMemRegImm";
30   let NumMIOperands = 2;
31   let MIOperandInfo = (ops i32imm, ptr_rc);
32 }
33
34 // Define ARM specific addressing mode.
35 //Addressing Mode 1: data processing operands
36 def addr_mode1 : ComplexPattern<iPTR, 3, "SelectAddrMode1", [imm, sra, shl, srl],
37                                 []>;
38
39 //Addressing Mode 5: VFP load/store
40 def addr_mode5 : ComplexPattern<iPTR, 2, "SelectAddrMode5", [], []>;
41
42 //register plus/minus 12 bit offset
43 def iaddr  : ComplexPattern<iPTR, 2, "SelectAddrRegImm", [frameindex], []>;
44 //register plus scaled register
45 //def raddr  : ComplexPattern<iPTR, 2, "SelectAddrRegReg", [], []>;
46
47 //===----------------------------------------------------------------------===//
48 // Instruction Class Templates
49 //===----------------------------------------------------------------------===//
50 class InstARM<dag ops, string asmstr, list<dag> pattern> : Instruction {
51   let Namespace = "ARM";
52
53   dag OperandList = ops;
54   let AsmString   = asmstr;
55   let Pattern = pattern;
56 }
57
58 class IntBinOp<string OpcStr, SDNode OpNode> :
59         InstARM<(ops IntRegs:$dst, IntRegs:$a, IntRegs:$b),
60                  !strconcat(OpcStr, " $dst, $a, $b"),
61                  [(set IntRegs:$dst, (OpNode IntRegs:$a, IntRegs:$b))]>;
62
63 class FPBinOp<string OpcStr, SDNode OpNode> :
64         InstARM<(ops FPRegs:$dst, FPRegs:$a, FPRegs:$b),
65                  !strconcat(OpcStr, " $dst, $a, $b"),
66                  [(set FPRegs:$dst, (OpNode FPRegs:$a, FPRegs:$b))]>;
67
68 class DFPBinOp<string OpcStr, SDNode OpNode> :
69         InstARM<(ops DFPRegs:$dst, DFPRegs:$a, DFPRegs:$b),
70                  !strconcat(OpcStr, " $dst, $a, $b"),
71                  [(set DFPRegs:$dst, (OpNode DFPRegs:$a, DFPRegs:$b))]>;
72
73 class FPUnaryOp<string OpcStr, SDNode OpNode> :
74         InstARM<(ops FPRegs:$dst, FPRegs:$src),
75                  !strconcat(OpcStr, " $dst, $src"),
76                  [(set FPRegs:$dst, (OpNode FPRegs:$src))]>;
77
78 class DFPUnaryOp<string OpcStr, SDNode OpNode> :
79         InstARM<(ops DFPRegs:$dst, DFPRegs:$src),
80                  !strconcat(OpcStr, " $dst, $src"),
81                  [(set DFPRegs:$dst, (OpNode DFPRegs:$src))]>;
82
83 class Addr1BinOp<string OpcStr, SDNode OpNode> :
84         InstARM<(ops IntRegs:$dst, IntRegs:$a, op_addr_mode1:$b),
85                  !strconcat(OpcStr, " $dst, $a, $b"),
86                  [(set IntRegs:$dst, (OpNode IntRegs:$a, addr_mode1:$b))]>;
87
88 //===----------------------------------------------------------------------===//
89 // Instructions
90 //===----------------------------------------------------------------------===//
91
92 def brtarget : Operand<OtherVT>;
93
94 // Operand for printing out a condition code.
95 let PrintMethod = "printCCOperand" in
96   def CCOp : Operand<i32>;
97
98 def SDT_ARMCallSeq : SDTypeProfile<0, 1, [ SDTCisVT<0, i32> ]>;
99 def callseq_start  : SDNode<"ISD::CALLSEQ_START", SDT_ARMCallSeq,
100                              [SDNPHasChain, SDNPOutFlag]>;
101 def callseq_end    : SDNode<"ISD::CALLSEQ_END",   SDT_ARMCallSeq,
102                              [SDNPHasChain, SDNPOutFlag]>;
103
104 def SDT_ARMcall    : SDTypeProfile<0, -1, [SDTCisInt<0>]>;
105 def ARMcall        : SDNode<"ARMISD::CALL", SDT_ARMcall,
106                            [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
107 def retflag        : SDNode<"ARMISD::RET_FLAG", SDTRet,
108                            [SDNPHasChain, SDNPOptInFlag]>;
109
110 def SDTarmselect   : SDTypeProfile<1, 3, [SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisInt<0>, SDTCisVT<2, i32>]>;
111 def armselect      : SDNode<"ARMISD::SELECT", SDTarmselect, [SDNPInFlag, SDNPOutFlag]>;
112
113 def SDTarmfmstat   : SDTypeProfile<0, 0, []>;
114 def armfmstat      : SDNode<"ARMISD::FMSTAT", SDTarmfmstat, [SDNPInFlag, SDNPOutFlag]>;
115
116 def SDTarmbr       : SDTypeProfile<0, 2, [SDTCisVT<0, OtherVT>, SDTCisVT<1, i32>]>;
117 def armbr          : SDNode<"ARMISD::BR", SDTarmbr, [SDNPHasChain, SDNPInFlag]>;
118
119 def SDTVoidBinOp : SDTypeProfile<0, 2, [SDTCisSameAs<0, 1>]>;
120 def armcmp       : SDNode<"ARMISD::CMP",  SDTVoidBinOp, [SDNPOutFlag]>;
121
122 def armfsitos      : SDNode<"ARMISD::FSITOS", SDTUnaryOp>;
123 def armftosis      : SDNode<"ARMISD::FTOSIS", SDTUnaryOp>;
124 def armfsitod      : SDNode<"ARMISD::FSITOD", SDTUnaryOp>;
125 def armftosid      : SDNode<"ARMISD::FTOSID", SDTUnaryOp>;
126 def armfuitos      : SDNode<"ARMISD::FUITOS", SDTUnaryOp>;
127 def armftouis      : SDNode<"ARMISD::FTOUIS", SDTUnaryOp>;
128 def armfuitod      : SDNode<"ARMISD::FUITOD", SDTUnaryOp>;
129 def armftouid      : SDNode<"ARMISD::FTOUID", SDTUnaryOp>;
130
131 def SDTarmfmrrd    : SDTypeProfile<0, 3, [SDTCisInt<0>, SDTCisInt<1>, SDTCisFP<2>]>;
132 def armfmrrd       : SDNode<"ARMISD::FMRRD", SDTarmfmrrd,
133                             [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
134
135 def SDTarmfmdrr    : SDTypeProfile<1, 2, [SDTCisFP<0>, SDTCisInt<1>, SDTCisInt<2>]>;
136 def armfmdrr       : SDNode<"ARMISD::FMDRR", SDTarmfmdrr, []>;
137
138 def ADJCALLSTACKUP : InstARM<(ops i32imm:$amt),
139                             "!ADJCALLSTACKUP $amt",
140                             [(callseq_end imm:$amt)]>, Imp<[R13],[R13]>;
141
142 def ADJCALLSTACKDOWN : InstARM<(ops i32imm:$amt),
143                                "!ADJCALLSTACKDOWN $amt",
144                                [(callseq_start imm:$amt)]>, Imp<[R13],[R13]>;
145
146 let isReturn = 1 in {
147   def bx: InstARM<(ops), "bx r14", [(retflag)]>;
148 }
149
150 let noResults = 1, Defs = [R0, R1, R2, R3, R14] in {
151   def bl: InstARM<(ops i32imm:$func, variable_ops), "bl $func", []>;
152 }
153
154 def ldr   : InstARM<(ops IntRegs:$dst, memri:$addr),
155                      "ldr $dst, $addr",
156                      [(set IntRegs:$dst, (load iaddr:$addr))]>;
157
158 def LDRB    : InstARM<(ops IntRegs:$dst, IntRegs:$addr),
159                        "ldrb $dst, [$addr]",
160                        [(set IntRegs:$dst, (zextloadi8 IntRegs:$addr))]>;
161
162 def LDRSB   : InstARM<(ops IntRegs:$dst, IntRegs:$addr),
163                        "ldrsb $dst, [$addr]",
164                        [(set IntRegs:$dst, (sextloadi8 IntRegs:$addr))]>;
165
166 def LDRH    : InstARM<(ops IntRegs:$dst, IntRegs:$addr),
167                        "ldrh $dst, [$addr]",
168                        [(set IntRegs:$dst, (zextloadi16 IntRegs:$addr))]>;
169
170 def LDRSH   : InstARM<(ops IntRegs:$dst, IntRegs:$addr),
171                        "ldrsh $dst, [$addr]",
172                        [(set IntRegs:$dst, (sextloadi16 IntRegs:$addr))]>;
173
174 def str  : InstARM<(ops IntRegs:$src, memri:$addr),
175                     "str $src, $addr",
176                     [(store IntRegs:$src, iaddr:$addr)]>;
177
178 def MOV   : InstARM<(ops IntRegs:$dst, op_addr_mode1:$src),
179                     "mov $dst, $src", [(set IntRegs:$dst, addr_mode1:$src)]>;
180
181 def ADD     : Addr1BinOp<"add",  add>;
182 def ADCS    : Addr1BinOp<"adcs", adde>;
183 def ADDS    : Addr1BinOp<"adds", addc>;
184
185 // "LEA" forms of add
186 def lea_addri : InstARM<(ops IntRegs:$dst, memri:$addr),
187                          "add $dst, ${addr:arith}",
188                          [(set IntRegs:$dst, iaddr:$addr)]>;
189
190
191 def SUB     : Addr1BinOp<"sub",  sub>;
192 def SBCS    : Addr1BinOp<"sbcs", sube>;
193 def SUBS    : Addr1BinOp<"subs", subc>;
194 def AND     : Addr1BinOp<"and",  and>;
195 def EOR     : Addr1BinOp<"eor",  xor>;
196 def ORR     : Addr1BinOp<"orr",  or>;
197
198 let isTwoAddress = 1 in {
199   def movcond : InstARM<(ops IntRegs:$dst, IntRegs:$false,
200                          op_addr_mode1:$true, CCOp:$cc),
201                          "mov$cc $dst, $true",
202                          [(set IntRegs:$dst, (armselect addr_mode1:$true,
203                            IntRegs:$false, imm:$cc))]>;
204 }
205
206 def MUL     : IntBinOp<"mul", mul>;
207
208 let Defs = [R0] in {
209   def SMULL   : IntBinOp<"smull r12,", mulhs>;
210   def UMULL   : IntBinOp<"umull r12,", mulhu>;
211 }
212
213 let isTerminator = 1 in {
214   def bcond   : InstARM<(ops brtarget:$dst, CCOp:$cc),
215                             "b$cc $dst",
216                             [(armbr bb:$dst, imm:$cc)]>;
217
218   def b       : InstARM<(ops brtarget:$dst),
219                         "b $dst",
220                         [(br bb:$dst)]>;
221 }
222
223 def cmp      : InstARM<(ops IntRegs:$a, op_addr_mode1:$b),
224                        "cmp $a, $b",
225                        [(armcmp IntRegs:$a, addr_mode1:$b)]>;
226
227 // Floating Point Compare
228 def fcmps   : InstARM<(ops FPRegs:$a, FPRegs:$b),
229                        "fcmps $a, $b",
230                        [(armcmp FPRegs:$a, FPRegs:$b)]>;
231
232 def fcmpd   : InstARM<(ops DFPRegs:$a, DFPRegs:$b),
233                        "fcmpd $a, $b",
234                        [(armcmp DFPRegs:$a, DFPRegs:$b)]>;
235
236 // Floating Point Copy
237 def FCPYS   : InstARM<(ops FPRegs:$dst, FPRegs:$src), "fcpys $dst, $src", []>;
238
239 def FCPYD   : InstARM<(ops DFPRegs:$dst, DFPRegs:$src), "fcpyd $dst, $src", []>;
240
241 // Floating Point Conversion
242 // We use bitconvert for moving the data between the register classes.
243 // The format conversion is done with ARM specific nodes
244
245 def FMSR    : InstARM<(ops FPRegs:$dst, IntRegs:$src),
246                        "fmsr $dst, $src", [(set FPRegs:$dst, (bitconvert IntRegs:$src))]>;
247
248 def FMRS    : InstARM<(ops IntRegs:$dst, FPRegs:$src),
249                        "fmrs $dst, $src", [(set IntRegs:$dst, (bitconvert FPRegs:$src))]>;
250
251 def FMRRD   : InstARM<(ops IntRegs:$i0, IntRegs:$i1, DFPRegs:$src),
252                        "fmrrd $i0, $i1, $src", [(armfmrrd IntRegs:$i0, IntRegs:$i1, DFPRegs:$src)]>;
253
254 def FMDRR   : InstARM<(ops DFPRegs:$dst, IntRegs:$i0, IntRegs:$i1),
255                        "fmdrr $dst, $i0, $i1", [(set DFPRegs:$dst, (armfmdrr IntRegs:$i0, IntRegs:$i1))]>;
256
257 def FSITOS  : InstARM<(ops FPRegs:$dst, FPRegs:$src),
258                        "fsitos $dst, $src", [(set FPRegs:$dst, (armfsitos FPRegs:$src))]>;
259
260 def FTOSIS  : InstARM<(ops FPRegs:$dst, FPRegs:$src),
261                        "ftosis $dst, $src", [(set FPRegs:$dst, (armftosis FPRegs:$src))]>;
262
263 def FSITOD  : InstARM<(ops DFPRegs:$dst, FPRegs:$src),
264                        "fsitod $dst, $src", [(set DFPRegs:$dst, (armfsitod FPRegs:$src))]>;
265
266 def FTOSID  : InstARM<(ops FPRegs:$dst, DFPRegs:$src),
267                        "ftosid $dst, $src", [(set FPRegs:$dst, (armftosid DFPRegs:$src))]>;
268
269 def FUITOS  : InstARM<(ops FPRegs:$dst, FPRegs:$src),
270                        "fuitos $dst, $src", [(set FPRegs:$dst, (armfuitos FPRegs:$src))]>;
271
272 def FTOUIS  : InstARM<(ops FPRegs:$dst, FPRegs:$src),
273                        "ftouis $dst, $src", [(set FPRegs:$dst, (armftouis FPRegs:$src))]>;
274
275 def FUITOD  : InstARM<(ops DFPRegs:$dst, FPRegs:$src),
276                        "fuitod $dst, $src", [(set DFPRegs:$dst, (armfuitod FPRegs:$src))]>;
277
278 def FTOUID  : InstARM<(ops FPRegs:$dst, DFPRegs:$src),
279                        "ftouid $dst, $src", [(set FPRegs:$dst, (armftouid DFPRegs:$src))]>;
280
281 def FCVTDS  : InstARM<(ops DFPRegs:$dst, FPRegs:$src),
282                        "fcvtds $dst, $src", [(set DFPRegs:$dst, (fextend FPRegs:$src))]>;
283
284 def FCVTSD  : InstARM<(ops FPRegs:$dst, DFPRegs:$src),
285                        "fcvtsd $dst, $src", [(set FPRegs:$dst, (fround DFPRegs:$src))]>;
286
287 def FMSTAT  : InstARM<(ops ), "fmstat", [(armfmstat)]>;
288
289 // Floating Point Arithmetic
290 def FADDS   : FPBinOp<"fadds",  fadd>;
291 def FADDD   : DFPBinOp<"faddd", fadd>;
292 def FSUBS   : FPBinOp<"fsubs",  fsub>;
293 def FSUBD   : DFPBinOp<"fsubd", fsub>;
294
295 def FNEGS   : FPUnaryOp<"fnegs",  fneg>;
296 def FNEGD   : DFPUnaryOp<"fnegd", fneg>;
297 def FABSS   : FPUnaryOp<"fabss",  fabs>;
298 def FABSD   : DFPUnaryOp<"fabsd", fabs>;
299
300 def FMULS   : FPBinOp<"fmuls", fmul>;
301 def FMULD   : DFPBinOp<"fmuld", fmul>;
302 def FDIVS   : FPBinOp<"fdivs", fdiv>;
303 def FDIVD   : DFPBinOp<"fdivd", fdiv>;
304
305 // Floating Point Load
306 def FLDS  : InstARM<(ops FPRegs:$dst, op_addr_mode5:$addr),
307                      "flds $dst, $addr",
308                      [(set FPRegs:$dst, (load addr_mode5:$addr))]>;
309
310 def FLDD  : InstARM<(ops DFPRegs:$dst, op_addr_mode5:$addr),
311                      "fldd $dst, $addr",
312                      [(set DFPRegs:$dst, (load addr_mode5:$addr))]>;
313
314 // Floating Point Store
315 def FSTS    : InstARM<(ops FPRegs:$src, op_addr_mode5:$addr),
316                        "fsts $src, $addr",
317                        [(store FPRegs:$src, addr_mode5:$addr)]>;
318
319 def FSTD    : InstARM<(ops DFPRegs:$src, op_addr_mode5:$addr),
320                        "fstd $src, $addr",
321                        [(store DFPRegs:$src, addr_mode5:$addr)]>;
322
323 def : Pat<(ARMcall tglobaladdr:$dst),
324           (bl tglobaladdr:$dst)>;
325
326 def : Pat<(ARMcall texternalsym:$dst),
327           (bl texternalsym:$dst)>;