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