add the FPUnaryOp and DFPUnaryOp classes
[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 def bcond      : InstARM<(ops brtarget:$dst, CCOp:$cc),
214                          "b$cc $dst",
215                          [(armbr bb:$dst, imm:$cc)]>;
216
217 def b      : InstARM<(ops brtarget:$dst),
218                          "b $dst",
219                          [(br bb:$dst)]>;
220
221 def cmp      : InstARM<(ops IntRegs:$a, op_addr_mode1:$b),
222                        "cmp $a, $b",
223                        [(armcmp IntRegs:$a, addr_mode1:$b)]>;
224
225 // Floating Point Compare
226 def fcmps   : InstARM<(ops FPRegs:$a, FPRegs:$b),
227                        "fcmps $a, $b",
228                        [(armcmp FPRegs:$a, FPRegs:$b)]>;
229
230 def fcmpd   : InstARM<(ops DFPRegs:$a, DFPRegs:$b),
231                        "fcmpd $a, $b",
232                        [(armcmp DFPRegs:$a, DFPRegs:$b)]>;
233
234 // Floating Point Copy
235 def FCPYS   : InstARM<(ops FPRegs:$dst, FPRegs:$src), "fcpys $dst, $src", []>;
236
237 def FCPYD   : InstARM<(ops DFPRegs:$dst, DFPRegs:$src), "fcpyd $dst, $src", []>;
238
239 // Floating Point Conversion
240 // We use bitconvert for moving the data between the register classes.
241 // The format conversion is done with ARM specific nodes
242
243 def FMSR    : InstARM<(ops FPRegs:$dst, IntRegs:$src),
244                        "fmsr $dst, $src", [(set FPRegs:$dst, (bitconvert IntRegs:$src))]>;
245
246 def FMRS    : InstARM<(ops IntRegs:$dst, FPRegs:$src),
247                        "fmrs $dst, $src", [(set IntRegs:$dst, (bitconvert FPRegs:$src))]>;
248
249 def FMRRD   : InstARM<(ops IntRegs:$i0, IntRegs:$i1, DFPRegs:$src),
250                        "fmrrd $i0, $i1, $src", [(armfmrrd IntRegs:$i0, IntRegs:$i1, DFPRegs:$src)]>;
251
252 def FMDRR   : InstARM<(ops DFPRegs:$dst, IntRegs:$i0, IntRegs:$i1),
253                        "fmdrr $dst, $i0, $i1", [(set DFPRegs:$dst, (armfmdrr IntRegs:$i0, IntRegs:$i1))]>;
254
255 def FSITOS  : InstARM<(ops FPRegs:$dst, FPRegs:$src),
256                        "fsitos $dst, $src", [(set FPRegs:$dst, (armfsitos FPRegs:$src))]>;
257
258 def FTOSIS  : InstARM<(ops FPRegs:$dst, FPRegs:$src),
259                        "ftosis $dst, $src", [(set FPRegs:$dst, (armftosis FPRegs:$src))]>;
260
261 def FSITOD  : InstARM<(ops DFPRegs:$dst, FPRegs:$src),
262                        "fsitod $dst, $src", [(set DFPRegs:$dst, (armfsitod FPRegs:$src))]>;
263
264 def FTOSID  : InstARM<(ops FPRegs:$dst, DFPRegs:$src),
265                        "ftosid $dst, $src", [(set FPRegs:$dst, (armftosid DFPRegs:$src))]>;
266
267 def FUITOS  : InstARM<(ops FPRegs:$dst, FPRegs:$src),
268                        "fuitos $dst, $src", [(set FPRegs:$dst, (armfuitos FPRegs:$src))]>;
269
270 def FTOUIS  : InstARM<(ops FPRegs:$dst, FPRegs:$src),
271                        "ftouis $dst, $src", [(set FPRegs:$dst, (armftouis FPRegs:$src))]>;
272
273 def FUITOD  : InstARM<(ops DFPRegs:$dst, FPRegs:$src),
274                        "fuitod $dst, $src", [(set DFPRegs:$dst, (armfuitod FPRegs:$src))]>;
275
276 def FTOUID  : InstARM<(ops FPRegs:$dst, DFPRegs:$src),
277                        "ftouid $dst, $src", [(set FPRegs:$dst, (armftouid DFPRegs:$src))]>;
278
279 def FCVTDS  : InstARM<(ops DFPRegs:$dst, FPRegs:$src),
280                        "fcvtds $dst, $src", [(set DFPRegs:$dst, (fextend FPRegs:$src))]>;
281
282 def FCVTSD  : InstARM<(ops FPRegs:$dst, DFPRegs:$src),
283                        "fcvtsd $dst, $src", [(set FPRegs:$dst, (fround DFPRegs:$src))]>;
284
285 def FMSTAT  : InstARM<(ops ), "fmstat", [(armfmstat)]>;
286
287 // Floating Point Arithmetic
288 def FADDS   : FPBinOp<"fadds",  fadd>;
289 def FADDD   : DFPBinOp<"faddd", fadd>;
290 def FSUBS   : FPBinOp<"fsubs",  fsub>;
291 def FSUBD   : DFPBinOp<"fsubd", fsub>;
292
293 def FNEGS   : FPUnaryOp<"fnegs",  fneg>;
294 def FNEGD   : DFPUnaryOp<"fnegd", fneg>;
295 def FABSS   : FPUnaryOp<"fabss",  fabs>;
296 def FABSD   : DFPUnaryOp<"fabsd", fabs>;
297
298 def FMULS   : FPBinOp<"fmuls", fmul>;
299 def FMULD   : DFPBinOp<"fmuld", fmul>;
300 def FDIVS   : FPBinOp<"fdivs", fdiv>;
301 def FDIVD   : DFPBinOp<"fdivd", fdiv>;
302
303 // Floating Point Load
304 def FLDS  : InstARM<(ops FPRegs:$dst, op_addr_mode5:$addr),
305                      "flds $dst, $addr",
306                      [(set FPRegs:$dst, (load addr_mode5:$addr))]>;
307
308 def FLDD  : InstARM<(ops DFPRegs:$dst, op_addr_mode5:$addr),
309                      "fldd $dst, $addr",
310                      [(set DFPRegs:$dst, (load addr_mode5:$addr))]>;
311
312 // Floating Point Store
313 def FSTS    : InstARM<(ops FPRegs:$src, op_addr_mode5:$addr),
314                        "fsts $src, $addr",
315                        [(store FPRegs:$src, addr_mode5:$addr)]>;
316
317 def FSTD    : InstARM<(ops DFPRegs:$src, op_addr_mode5:$addr),
318                        "fstd $src, $addr",
319                        [(store DFPRegs:$src, addr_mode5:$addr)]>;
320
321 def : Pat<(ARMcall tglobaladdr:$dst),
322           (bl tglobaladdr:$dst)>;
323
324 def : Pat<(ARMcall texternalsym:$dst),
325           (bl texternalsym:$dst)>;