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