1 //===- IA64InstrInfo.td - Describe the IA64 Instruction Set -----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by Duraid Madina and is distributed under the
6 // University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file describes the IA64 instruction set, defining the instructions, and
11 // properties of the instructions which are needed for code generation, machine
12 // code emission, and analysis.
14 //===----------------------------------------------------------------------===//
16 include "IA64InstrFormats.td"
18 //===----------------------------------------------------------------------===//
19 // IA-64 specific DAG Nodes.
22 def IA64getfd : SDNode<"IA64ISD::GETFD", SDTFPToIntOp, []>;
24 def SDT_IA64RetFlag : SDTypeProfile<0, 0, []>;
25 def retflag : SDNode<"IA64ISD::RET_FLAG", SDT_IA64RetFlag,
26 [SDNPHasChain, SDNPOptInFlag]>;
31 class isA { bit A=1; } // I or M unit
32 class isM { bit M=1; } // M unit
33 class isI { bit I=1; } // I unit
34 class isB { bit B=1; } // B unit
35 class isF { bit F=1; } // F unit
36 class isLX { bit LX=1; } // I/B
40 def u2imm : Operand<i8>;
41 def u6imm : Operand<i8>;
42 def s8imm : Operand<i8> {
43 let PrintMethod = "printS8ImmOperand";
45 def s14imm : Operand<i64> {
46 let PrintMethod = "printS14ImmOperand";
48 def s22imm : Operand<i64> {
49 let PrintMethod = "printS22ImmOperand";
51 def u64imm : Operand<i64> {
52 let PrintMethod = "printU64ImmOperand";
54 def s64imm : Operand<i64> {
55 let PrintMethod = "printS64ImmOperand";
58 let PrintMethod = "printGlobalOperand" in
59 def globaladdress : Operand<i64>;
61 // the asmprinter needs to know about calls
62 let PrintMethod = "printCallOperand" in
63 def calltarget : Operand<i64>;
65 /* new daggy action!!! */
67 def is32ones : PatLeaf<(i64 imm), [{
68 // is32ones predicate - True if the immediate is 0x00000000FFFFFFFF
69 // Used to create ZXT4s appropriately
70 uint64_t v = (uint64_t)N->getValue();
71 return (v == 0x00000000FFFFFFFFLL);
74 // isMIXable predicates - True if the immediate is
75 // 0xFF00FF00FF00FF00, 0x00FF00FF00FF00FF
76 // etc, through 0x00000000FFFFFFFF
77 // Used to test for the suitability of mix*
78 def isMIX1Lable: PatLeaf<(i64 imm), [{
79 return((uint64_t)N->getValue()==0xFF00FF00FF00FF00LL);
81 def isMIX1Rable: PatLeaf<(i64 imm), [{
82 return((uint64_t)N->getValue()==0x00FF00FF00FF00FFLL);
84 def isMIX2Lable: PatLeaf<(i64 imm), [{
85 return((uint64_t)N->getValue()==0xFFFF0000FFFF0000LL);
87 def isMIX2Rable: PatLeaf<(i64 imm), [{
88 return((uint64_t)N->getValue()==0x0000FFFF0000FFFFLL);
90 def isMIX4Lable: PatLeaf<(i64 imm), [{
91 return((uint64_t)N->getValue()==0xFFFFFFFF00000000LL);
93 def isMIX4Rable: PatLeaf<(i64 imm), [{
94 return((uint64_t)N->getValue()==0x00000000FFFFFFFFLL);
97 def isSHLADDimm: PatLeaf<(i64 imm), [{
98 // isSHLADDimm predicate - True if the immediate is exactly 1, 2, 3 or 4
100 // Used to create shladd instructions appropriately
101 int64_t v = (int64_t)N->getValue();
102 return (v >= 1 && v <= 4);
105 def immSExt14 : PatLeaf<(i64 imm), [{
106 // immSExt14 predicate - True if the immediate fits in a 14-bit sign extended
107 // field. Used by instructions like 'adds'.
108 int64_t v = (int64_t)N->getValue();
109 return (v <= 8191 && v >= -8192);
112 // imm64 predicate - True if the immediate fits in a 64-bit
113 // field - i.e., true. used to keep movl happy
114 def imm64 : PatLeaf<(i64 imm)>;
116 def ADD : AForm_DAG<0x03, 0x0b, (ops GR:$dst, GR:$src1, GR:$src2),
117 "add $dst = $src1, $src2",
118 [(set GR:$dst, (add GR:$src1, GR:$src2))]>, isA;
120 def ADD1 : AForm_DAG<0x03, 0x0b, (ops GR:$dst, GR:$src1, GR:$src2),
121 "add $dst = $src1, $src2, 1",
122 [(set GR:$dst, (add (add GR:$src1, GR:$src2), 1))]>, isA;
124 def ADDS : AForm_DAG<0x03, 0x0b, (ops GR:$dst, GR:$src1, s14imm:$imm),
125 "adds $dst = $imm, $src1",
126 [(set GR:$dst, (add GR:$src1, immSExt14:$imm))]>, isA;
128 def MOVL : AForm_DAG<0x03, 0x0b, (ops GR:$dst, s64imm:$imm),
130 [(set GR:$dst, imm64:$imm)]>, isLX;
132 def ADDL_GA : AForm_DAG<0x03, 0x0b, (ops GR:$dst, GR:$src1, globaladdress:$imm),
133 "addl $dst = $imm, $src1",
137 def ADDL_EA : AForm_DAG<0x03, 0x0b, (ops GR:$dst, GR:$src1, calltarget:$imm),
138 "addl $dst = $imm, $src1",
141 def SUB : AForm_DAG<0x03, 0x0b, (ops GR:$dst, GR:$src1, GR:$src2),
142 "sub $dst = $src1, $src2",
143 [(set GR:$dst, (sub GR:$src1, GR:$src2))]>, isA;
145 def SUB1 : AForm_DAG<0x03, 0x0b, (ops GR:$dst, GR:$src1, GR:$src2),
146 "sub $dst = $src1, $src2, 1",
147 [(set GR:$dst, (add (sub GR: $src1, GR:$src2), -1))]>, isA;
149 let isTwoAddress = 1 in {
150 def TPCADDIMM22 : AForm<0x03, 0x0b,
151 (ops GR:$dst, GR:$src1, s22imm:$imm, PR:$qp),
152 "($qp) add $dst = $imm, $dst">, isA;
153 def TPCADDS : AForm_DAG<0x03, 0x0b,
154 (ops GR:$dst, GR:$src1, s14imm:$imm, PR:$qp),
155 "($qp) adds $dst = $imm, $dst",
157 def TPCMPIMM8NE : AForm<0x03, 0x0b,
158 (ops PR:$dst, PR:$src1, s22imm:$imm, GR:$src2, PR:$qp),
159 "($qp) cmp.ne $dst , p0 = $imm, $src2">, isA;
162 // zero extend a bool (predicate reg) into an integer reg
163 def ZXTb : Pat<(zext PR:$src),
164 (TPCADDIMM22 (ADDS r0, 0), 1, PR:$src)>;
166 // normal sign/zero-extends
167 def SXT1 : AForm_DAG<0x03, 0x0b, (ops GR:$dst, GR:$src), "sxt1 $dst = $src",
168 [(set GR:$dst, (sext_inreg GR:$src, i8))]>, isI;
169 def ZXT1 : AForm_DAG<0x03, 0x0b, (ops GR:$dst, GR:$src), "zxt1 $dst = $src",
170 [(set GR:$dst, (and GR:$src, 255))]>, isI;
171 def SXT2 : AForm_DAG<0x03, 0x0b, (ops GR:$dst, GR:$src), "sxt2 $dst = $src",
172 [(set GR:$dst, (sext_inreg GR:$src, i16))]>, isI;
173 def ZXT2 : AForm_DAG<0x03, 0x0b, (ops GR:$dst, GR:$src), "zxt2 $dst = $src",
174 [(set GR:$dst, (and GR:$src, 65535))]>, isI;
175 def SXT4 : AForm_DAG<0x03, 0x0b, (ops GR:$dst, GR:$src), "sxt4 $dst = $src",
176 [(set GR:$dst, (sext_inreg GR:$src, i32))]>, isI;
177 def ZXT4 : AForm_DAG<0x03, 0x0b, (ops GR:$dst, GR:$src), "zxt4 $dst = $src",
178 [(set GR:$dst, (and GR:$src, is32ones))]>, isI;
180 // fixme: shrs vs shru?
181 def MIX1L : AForm_DAG<0x03, 0x0b, (ops GR:$dst, GR:$src1, GR:$src2),
182 "mix1.l $dst = $src1, $src2",
183 [(set GR:$dst, (or (and GR:$src1, isMIX1Lable),
184 (and (srl GR:$src2, (i64 8)), isMIX1Lable)))]>, isI;
186 def MIX2L : AForm_DAG<0x03, 0x0b, (ops GR:$dst, GR:$src1, GR:$src2),
187 "mix2.l $dst = $src1, $src2",
188 [(set GR:$dst, (or (and GR:$src1, isMIX2Lable),
189 (and (srl GR:$src2, (i64 16)), isMIX2Lable)))]>, isI;
191 def MIX4L : AForm_DAG<0x03, 0x0b, (ops GR:$dst, GR:$src1, GR:$src2),
192 "mix4.l $dst = $src1, $src2",
193 [(set GR:$dst, (or (and GR:$src1, isMIX4Lable),
194 (and (srl GR:$src2, (i64 32)), isMIX4Lable)))]>, isI;
196 def MIX1R : AForm_DAG<0x03, 0x0b, (ops GR:$dst, GR:$src1, GR:$src2),
197 "mix1.r $dst = $src1, $src2",
198 [(set GR:$dst, (or (and (shl GR:$src1, (i64 8)), isMIX1Rable),
199 (and GR:$src2, isMIX1Rable)))]>, isI;
201 def MIX2R : AForm_DAG<0x03, 0x0b, (ops GR:$dst, GR:$src1, GR:$src2),
202 "mix2.r $dst = $src1, $src2",
203 [(set GR:$dst, (or (and (shl GR:$src1, (i64 16)), isMIX2Rable),
204 (and GR:$src2, isMIX2Rable)))]>, isI;
206 def MIX4R : AForm_DAG<0x03, 0x0b, (ops GR:$dst, GR:$src1, GR:$src2),
207 "mix4.r $dst = $src1, $src2",
208 [(set GR:$dst, (or (and (shl GR:$src1, (i64 32)), isMIX4Rable),
209 (and GR:$src2, isMIX4Rable)))]>, isI;
211 def GETFSIGD : AForm_DAG<0x03, 0x0b, (ops GR:$dst, FP:$src),
212 "getf.sig $dst = $src",
215 def SETFSIGD : AForm_DAG<0x03, 0x0b, (ops FP:$dst, GR:$src),
216 "setf.sig $dst = $src",
219 def XMALD : AForm_DAG<0x03, 0x0b, (ops FP:$dst, FP:$src1, FP:$src2, FP:$src3),
220 "xma.l $dst = $src1, $src2, $src3",
222 def XMAHD : AForm_DAG<0x03, 0x0b, (ops FP:$dst, FP:$src1, FP:$src2, FP:$src3),
223 "xma.h $dst = $src1, $src2, $src3",
225 def XMAHUD : AForm_DAG<0x03, 0x0b, (ops FP:$dst, FP:$src1, FP:$src2, FP:$src3),
226 "xma.hu $dst = $src1, $src2, $src3",
229 // pseudocode for integer multiplication
230 def : Pat<(mul GR:$src1, GR:$src2),
231 (GETFSIGD (XMALD (SETFSIGD GR:$src1), (SETFSIGD GR:$src2), F0))>;
232 def : Pat<(mulhs GR:$src1, GR:$src2),
233 (GETFSIGD (XMAHD (SETFSIGD GR:$src1), (SETFSIGD GR:$src2), F0))>;
234 def : Pat<(mulhu GR:$src1, GR:$src2),
235 (GETFSIGD (XMAHUD (SETFSIGD GR:$src1), (SETFSIGD GR:$src2), F0))>;
237 // TODO: addp4 (addp4 dst = src, r0 is a 32-bit add)
240 // def ADDS : AForm<0x03, 0x0b, (ops GR:$dst, GR:$src1, s14imm:$imm),
241 // "adds $dst = $imm, $src1">;
243 def AND : AForm_DAG<0x03, 0x0b, (ops GR:$dst, GR:$src1, GR:$src2),
244 "and $dst = $src1, $src2",
245 [(set GR:$dst, (and GR:$src1, GR:$src2))]>, isA;
246 def ANDCM : AForm_DAG<0x03, 0x0b, (ops GR:$dst, GR:$src1, GR:$src2),
247 "andcm $dst = $src1, $src2",
248 [(set GR:$dst, (and GR:$src1, (not GR:$src2)))]>, isA;
249 // TODO: and/andcm/or/xor/add/sub/shift immediate forms
250 def OR : AForm_DAG<0x03, 0x0b, (ops GR:$dst, GR:$src1, GR:$src2),
251 "or $dst = $src1, $src2",
252 [(set GR:$dst, (or GR:$src1, GR:$src2))]>, isA;
254 def pOR : AForm<0x03, 0x0b, (ops GR:$dst, GR:$src1, GR:$src2, PR:$qp),
255 "($qp) or $dst = $src1, $src2">, isA;
257 // the following are all a bit unfortunate: we throw away the complement
259 def CMPEQ : AForm_DAG<0x03, 0x0b, (ops PR:$dst, GR:$src1, GR:$src2),
260 "cmp.eq $dst, p0 = $src1, $src2",
261 [(set PR:$dst, (seteq GR:$src1, GR:$src2))]>, isA;
262 def CMPGT : AForm_DAG<0x03, 0x0b, (ops PR:$dst, GR:$src1, GR:$src2),
263 "cmp.gt $dst, p0 = $src1, $src2",
264 [(set PR:$dst, (setgt GR:$src1, GR:$src2))]>, isA;
265 def CMPGE : AForm_DAG<0x03, 0x0b, (ops PR:$dst, GR:$src1, GR:$src2),
266 "cmp.ge $dst, p0 = $src1, $src2",
267 [(set PR:$dst, (setge GR:$src1, GR:$src2))]>, isA;
268 def CMPLT : AForm_DAG<0x03, 0x0b, (ops PR:$dst, GR:$src1, GR:$src2),
269 "cmp.lt $dst, p0 = $src1, $src2",
270 [(set PR:$dst, (setlt GR:$src1, GR:$src2))]>, isA;
271 def CMPLE : AForm_DAG<0x03, 0x0b, (ops PR:$dst, GR:$src1, GR:$src2),
272 "cmp.le $dst, p0 = $src1, $src2",
273 [(set PR:$dst, (setle GR:$src1, GR:$src2))]>, isA;
274 def CMPNE : AForm_DAG<0x03, 0x0b, (ops PR:$dst, GR:$src1, GR:$src2),
275 "cmp.ne $dst, p0 = $src1, $src2",
276 [(set PR:$dst, (setne GR:$src1, GR:$src2))]>, isA;
277 def CMPLTU: AForm_DAG<0x03, 0x0b, (ops PR:$dst, GR:$src1, GR:$src2),
278 "cmp.ltu $dst, p0 = $src1, $src2",
279 [(set PR:$dst, (setult GR:$src1, GR:$src2))]>, isA;
280 def CMPGTU: AForm_DAG<0x03, 0x0b, (ops PR:$dst, GR:$src1, GR:$src2),
281 "cmp.gtu $dst, p0 = $src1, $src2",
282 [(set PR:$dst, (setugt GR:$src1, GR:$src2))]>, isA;
283 def CMPLEU: AForm_DAG<0x03, 0x0b, (ops PR:$dst, GR:$src1, GR:$src2),
284 "cmp.leu $dst, p0 = $src1, $src2",
285 [(set PR:$dst, (setule GR:$src1, GR:$src2))]>, isA;
286 def CMPGEU: AForm_DAG<0x03, 0x0b, (ops PR:$dst, GR:$src1, GR:$src2),
287 "cmp.geu $dst, p0 = $src1, $src2",
288 [(set PR:$dst, (setuge GR:$src1, GR:$src2))]>, isA;
290 // and we do the whole thing again for FP compares!
291 def FCMPEQ : AForm_DAG<0x03, 0x0b, (ops PR:$dst, FP:$src1, FP:$src2),
292 "fcmp.eq $dst, p0 = $src1, $src2",
293 [(set PR:$dst, (seteq FP:$src1, FP:$src2))]>, isF;
294 def FCMPGT : AForm_DAG<0x03, 0x0b, (ops PR:$dst, FP:$src1, FP:$src2),
295 "fcmp.gt $dst, p0 = $src1, $src2",
296 [(set PR:$dst, (setgt FP:$src1, FP:$src2))]>, isF;
297 def FCMPGE : AForm_DAG<0x03, 0x0b, (ops PR:$dst, FP:$src1, FP:$src2),
298 "fcmp.ge $dst, p0 = $src1, $src2",
299 [(set PR:$dst, (setge FP:$src1, FP:$src2))]>, isF;
300 def FCMPLT : AForm_DAG<0x03, 0x0b, (ops PR:$dst, FP:$src1, FP:$src2),
301 "fcmp.lt $dst, p0 = $src1, $src2",
302 [(set PR:$dst, (setlt FP:$src1, FP:$src2))]>, isF;
303 def FCMPLE : AForm_DAG<0x03, 0x0b, (ops PR:$dst, FP:$src1, FP:$src2),
304 "fcmp.le $dst, p0 = $src1, $src2",
305 [(set PR:$dst, (setle FP:$src1, FP:$src2))]>, isF;
306 def FCMPNE : AForm_DAG<0x03, 0x0b, (ops PR:$dst, FP:$src1, FP:$src2),
307 "fcmp.neq $dst, p0 = $src1, $src2",
308 [(set PR:$dst, (setne FP:$src1, FP:$src2))]>, isF;
309 def FCMPLTU: AForm_DAG<0x03, 0x0b, (ops PR:$dst, FP:$src1, FP:$src2),
310 "fcmp.ltu $dst, p0 = $src1, $src2",
311 [(set PR:$dst, (setult FP:$src1, FP:$src2))]>, isF;
312 def FCMPGTU: AForm_DAG<0x03, 0x0b, (ops PR:$dst, FP:$src1, FP:$src2),
313 "fcmp.gtu $dst, p0 = $src1, $src2",
314 [(set PR:$dst, (setugt FP:$src1, FP:$src2))]>, isF;
315 def FCMPLEU: AForm_DAG<0x03, 0x0b, (ops PR:$dst, FP:$src1, FP:$src2),
316 "fcmp.leu $dst, p0 = $src1, $src2",
317 [(set PR:$dst, (setule FP:$src1, FP:$src2))]>, isF;
318 def FCMPGEU: AForm_DAG<0x03, 0x0b, (ops PR:$dst, FP:$src1, FP:$src2),
319 "fcmp.geu $dst, p0 = $src1, $src2",
320 [(set PR:$dst, (setuge FP:$src1, FP:$src2))]>, isF;
322 def PCMPEQUNCR0R0 : AForm<0x03, 0x0b, (ops PR:$dst, PR:$qp),
323 "($qp) cmp.eq.unc $dst, p0 = r0, r0">, isA;
325 def : Pat<(trunc GR:$src), // truncate i64 to i1
326 (CMPNE GR:$src, r0)>; // $src!=0? If so, PR:$dst=true
328 let isTwoAddress=1 in {
329 def TPCMPEQR0R0 : AForm<0x03, 0x0b, (ops PR:$dst, PR:$bogus, PR:$qp),
330 "($qp) cmp.eq $dst, p0 = r0, r0">, isA;
331 def TPCMPNER0R0 : AForm<0x03, 0x0b, (ops PR:$dst, PR:$bogus, PR:$qp),
332 "($qp) cmp.ne $dst, p0 = r0, r0">, isA;
335 /* our pseudocode for OR on predicates is:
338 (pA) cmp.eq.unc pC,p0 = r0,r0 // pC = pA
340 (pB) cmp.eq pC,p0 = r0,r0 // if (pB) pC = 1 */
342 def bOR : Pat<(or PR:$src1, PR:$src2),
343 (TPCMPEQR0R0 (PCMPEQUNCR0R0 PR:$src1), PR:$src2)>;
345 /* our pseudocode for AND on predicates is:
347 (pA) cmp.eq.unc pC,p0 = r0,r0 // pC = pA
348 cmp.eq pTemp,p0 = r0,r0 // pTemp = NOT pB
350 (pB) cmp.ne pTemp,p0 = r0,r0
352 (pTemp)cmp.ne pC,p0 = r0,r0 // if (NOT pB) pC = 0 */
354 def bAND : Pat<(and PR:$src1, PR:$src2),
355 ( TPCMPNER0R0 (PCMPEQUNCR0R0 PR:$src1),
356 (TPCMPNER0R0 (CMPEQ r0, r0), PR:$src2) )>;
358 /* one possible routine for XOR on predicates is:
360 // Compute px = py ^ pz
361 // using sum of products: px = (py & !pz) | (pz & !py)
362 // Uses 5 instructions in 3 cycles.
364 (pz) cmp.eq.unc px = r0, r0 // px = pz
365 (py) cmp.eq.unc pt = r0, r0 // pt = py
368 (pt) cmp.ne.and px = r0, r0 // px = px & !pt (px = pz & !pt)
369 (pz) cmp.ne.and pt = r0, r0 // pt = pt & !pz
373 (pt) cmp.eq.or px = r0, r0 // px = px | pt
375 *** Another, which we use here, requires one scratch GR. it is:
377 mov rt = 0 // initialize rt off critical path
381 (pz) cmp.eq.unc px = r0, r0 // px = pz
382 (pz) mov rt = 1 // rt = pz
385 (py) cmp.ne px = 1, rt // if (py) px = !pz
387 .. these routines kindly provided by Jim Hull
390 def bXOR : Pat<(xor PR:$src1, PR:$src2),
391 (TPCMPIMM8NE (PCMPEQUNCR0R0 PR:$src2), 1,
392 (TPCADDS (ADDS r0, 0), 1, PR:$src2),
395 def XOR : AForm_DAG<0x03, 0x0b, (ops GR:$dst, GR:$src1, GR:$src2),
396 "xor $dst = $src1, $src2",
397 [(set GR:$dst, (xor GR:$src1, GR:$src2))]>, isA;
399 def SHLADD: AForm_DAG<0x03, 0x0b, (ops GR:$dst,GR:$src1,s64imm:$imm,GR:$src2),
400 "shladd $dst = $src1, $imm, $src2",
401 [(set GR:$dst, (add GR:$src2, (shl GR:$src1, isSHLADDimm:$imm)))]>, isA;
403 def SHL : AForm_DAG<0x03, 0x0b, (ops GR:$dst, GR:$src1, GR:$src2),
404 "shl $dst = $src1, $src2",
405 [(set GR:$dst, (shl GR:$src1, GR:$src2))]>, isI;
407 def SHRU : AForm_DAG<0x03, 0x0b, (ops GR:$dst, GR:$src1, GR:$src2),
408 "shr.u $dst = $src1, $src2",
409 [(set GR:$dst, (srl GR:$src1, GR:$src2))]>, isI;
411 def SHRS : AForm_DAG<0x03, 0x0b, (ops GR:$dst, GR:$src1, GR:$src2),
412 "shr $dst = $src1, $src2",
413 [(set GR:$dst, (sra GR:$src1, GR:$src2))]>, isI;
415 def MOV : AForm<0x03, 0x0b, (ops GR:$dst, GR:$src), "mov $dst = $src">, isA;
416 def FMOV : AForm<0x03, 0x0b, (ops FP:$dst, FP:$src),
417 "mov $dst = $src">, isF; // XXX: there _is_ no fmov
418 def PMOV : AForm<0x03, 0x0b, (ops GR:$dst, GR:$src, PR:$qp),
419 "($qp) mov $dst = $src">, isA;
421 def SPILL_ALL_PREDICATES_TO_GR : AForm<0x03, 0x0b, (ops GR:$dst),
422 "mov $dst = pr">, isI;
423 def FILL_ALL_PREDICATES_FROM_GR : AForm<0x03, 0x0b, (ops GR:$src),
424 "mov pr = $src">, isI;
426 let isTwoAddress = 1 in {
427 def CMOV : AForm<0x03, 0x0b, (ops GR:$dst, GR:$src2, GR:$src, PR:$qp),
428 "($qp) mov $dst = $src">, isA;
431 def PFMOV : AForm<0x03, 0x0b, (ops FP:$dst, FP:$src, PR:$qp),
432 "($qp) mov $dst = $src">, isF;
434 let isTwoAddress = 1 in {
435 def CFMOV : AForm<0x03, 0x0b, (ops FP:$dst, FP:$src2, FP:$src, PR:$qp),
436 "($qp) mov $dst = $src">, isF;
439 def SELECTINT : Pat<(select PR:$which, GR:$src1, GR:$src2),
440 (CMOV (MOV GR:$src2), GR:$src1, PR:$which)>; // note order!
441 def SELECTFP : Pat<(select PR:$which, FP:$src1, FP:$src2),
442 (CFMOV (FMOV FP:$src2), FP:$src1, PR:$which)>; // note order!
443 // TODO: can do this faster, w/o using any integer regs (see pattern isel)
444 def SELECTBOOL : Pat<(select PR:$which, PR:$src1, PR:$src2), // note order!
446 (MOV (TPCADDIMM22 (ADDS r0, 0), 1, PR:$src2)),
447 (TPCADDIMM22 (ADDS r0, 0), 1, PR:$src1), PR:$which), r0)>;
449 // load constants of various sizes // FIXME: prettyprint -ve constants
450 def : Pat<(i64 immSExt14:$imm), (ADDS r0, immSExt14:$imm)>;
451 def : Pat<(i1 -1), (CMPEQ r0, r0)>; // TODO: this should just be a ref to p0
452 def : Pat<(i1 0), (CMPNE r0, r0)>; // TODO: any instruction actually *using*
453 // this predicate should be killed!
455 // TODO: support postincrement (reg, imm9) loads+stores - this needs more
458 def IDEF : PseudoInstIA64<(ops variable_ops), "// IDEF">;
460 def IDEF_GR_D : PseudoInstIA64_DAG<(ops GR:$reg), "// $reg = IDEF",
461 [(set GR:$reg, (undef))]>;
462 def IDEF_FP_D : PseudoInstIA64_DAG<(ops FP:$reg), "// $reg = IDEF",
463 [(set FP:$reg, (undef))]>;
464 def IDEF_PR_D : PseudoInstIA64_DAG<(ops PR:$reg), "// $reg = IDEF",
465 [(set PR:$reg, (undef))]>;
467 def IUSE : PseudoInstIA64<(ops variable_ops), "// IUSE">;
468 def ADJUSTCALLSTACKUP : PseudoInstIA64<(ops variable_ops),
469 "// ADJUSTCALLSTACKUP">;
470 def ADJUSTCALLSTACKDOWN : PseudoInstIA64<(ops variable_ops),
471 "// ADJUSTCALLSTACKDOWN">;
472 def PSEUDO_ALLOC : PseudoInstIA64<(ops GR:$foo), "// PSEUDO_ALLOC">;
474 def ALLOC : AForm<0x03, 0x0b,
475 (ops GR:$dst, i8imm:$inputs, i8imm:$locals, i8imm:$outputs, i8imm:$rotating),
476 "alloc $dst = ar.pfs,$inputs,$locals,$outputs,$rotating">, isM;
478 let isTwoAddress = 1 in {
479 def TCMPNE : AForm<0x03, 0x0b,
480 (ops PR:$dst, PR:$src2, GR:$src3, GR:$src4),
481 "cmp.ne $dst, p0 = $src3, $src4">, isA;
483 def TPCMPEQOR : AForm<0x03, 0x0b,
484 (ops PR:$dst, PR:$src2, GR:$src3, GR:$src4, PR:$qp),
485 "($qp) cmp.eq.or $dst, p0 = $src3, $src4">, isA;
487 def TPCMPNE : AForm<0x03, 0x0b,
488 (ops PR:$dst, PR:$src2, GR:$src3, GR:$src4, PR:$qp),
489 "($qp) cmp.ne $dst, p0 = $src3, $src4">, isA;
491 def TPCMPEQ : AForm<0x03, 0x0b,
492 (ops PR:$dst, PR:$src2, GR:$src3, GR:$src4, PR:$qp),
493 "($qp) cmp.eq $dst, p0 = $src3, $src4">, isA;
496 def MOVSIMM14 : AForm<0x03, 0x0b, (ops GR:$dst, s14imm:$imm),
497 "mov $dst = $imm">, isA;
498 def MOVSIMM22 : AForm<0x03, 0x0b, (ops GR:$dst, s22imm:$imm),
499 "mov $dst = $imm">, isA;
500 def MOVLIMM64 : AForm<0x03, 0x0b, (ops GR:$dst, s64imm:$imm),
501 "movl $dst = $imm">, isLX;
503 def SHLI : AForm<0x03, 0x0b, (ops GR:$dst, GR:$src1, u6imm:$imm),
504 "shl $dst = $src1, $imm">, isI;
505 def SHRUI : AForm<0x03, 0x0b, (ops GR:$dst, GR:$src1, u6imm:$imm),
506 "shr.u $dst = $src1, $imm">, isI;
507 def SHRSI : AForm<0x03, 0x0b, (ops GR:$dst, GR:$src1, u6imm:$imm),
508 "shr $dst = $src1, $imm">, isI;
510 def EXTRU : AForm<0x03, 0x0b,
511 (ops GR:$dst, GR:$src1, u6imm:$imm1, u6imm:$imm2),
512 "extr.u $dst = $src1, $imm1, $imm2">, isI;
514 def DEPZ : AForm<0x03, 0x0b,
515 (ops GR:$dst, GR:$src1, u6imm:$imm1, u6imm:$imm2),
516 "dep.z $dst = $src1, $imm1, $imm2">, isI;
518 def PCMPEQOR : AForm<0x03, 0x0b, (ops PR:$dst, GR:$src1, GR:$src2, PR:$qp),
519 "($qp) cmp.eq.or $dst, p0 = $src1, $src2">, isA;
520 def PCMPEQUNC : AForm<0x03, 0x0b, (ops PR:$dst, GR:$src1, GR:$src2, PR:$qp),
521 "($qp) cmp.eq.unc $dst, p0 = $src1, $src2">, isA;
522 def PCMPNE : AForm<0x03, 0x0b, (ops PR:$dst, GR:$src1, GR:$src2, PR:$qp),
523 "($qp) cmp.ne $dst, p0 = $src1, $src2">, isA;
526 def BCMPEQ : AForm<0x03, 0x0b, (ops PR:$dst1, PR:$dst2, GR:$src1, GR:$src2),
527 "cmp.eq $dst1, dst2 = $src1, $src2">, isA;
529 def ADDIMM14 : AForm<0x03, 0x0b, (ops GR:$dst, GR:$src1, s14imm:$imm),
530 "adds $dst = $imm, $src1">, isA;
532 def ADDIMM22 : AForm<0x03, 0x0b, (ops GR:$dst, GR:$src1, s22imm:$imm),
533 "add $dst = $imm, $src1">, isA;
534 def CADDIMM22 : AForm<0x03, 0x0b, (ops GR:$dst, GR:$src1, s22imm:$imm, PR:$qp),
535 "($qp) add $dst = $imm, $src1">, isA;
537 def SUBIMM8 : AForm<0x03, 0x0b, (ops GR:$dst, s8imm:$imm, GR:$src2),
538 "sub $dst = $imm, $src2">, isA;
540 let isStore = 1, noResults = 1 in {
541 def ST1 : AForm<0x03, 0x0b, (ops GR:$dstPtr, GR:$value),
542 "st1 [$dstPtr] = $value">, isM;
543 def ST2 : AForm<0x03, 0x0b, (ops GR:$dstPtr, GR:$value),
544 "st2 [$dstPtr] = $value">, isM;
545 def ST4 : AForm<0x03, 0x0b, (ops GR:$dstPtr, GR:$value),
546 "st4 [$dstPtr] = $value">, isM;
547 def ST8 : AForm<0x03, 0x0b, (ops GR:$dstPtr, GR:$value),
548 "st8 [$dstPtr] = $value">, isM;
549 def STF4 : AForm<0x03, 0x0b, (ops GR:$dstPtr, FP:$value),
550 "stfs [$dstPtr] = $value">, isM;
551 def STF8 : AForm<0x03, 0x0b, (ops GR:$dstPtr, FP:$value),
552 "stfd [$dstPtr] = $value">, isM;
553 def STF_SPILL : AForm<0x03, 0x0b, (ops GR:$dstPtr, FP:$value),
554 "stf.spill [$dstPtr] = $value">, isM;
558 def LD1 : AForm<0x03, 0x0b, (ops GR:$dst, GR:$srcPtr),
559 "ld1 $dst = [$srcPtr]">, isM;
560 def LD2 : AForm<0x03, 0x0b, (ops GR:$dst, GR:$srcPtr),
561 "ld2 $dst = [$srcPtr]">, isM;
562 def LD4 : AForm<0x03, 0x0b, (ops GR:$dst, GR:$srcPtr),
563 "ld4 $dst = [$srcPtr]">, isM;
564 def LD8 : AForm<0x03, 0x0b, (ops GR:$dst, GR:$srcPtr),
565 "ld8 $dst = [$srcPtr]">, isM;
566 def LDF4 : AForm<0x03, 0x0b, (ops FP:$dst, GR:$srcPtr),
567 "ldfs $dst = [$srcPtr]">, isM;
568 def LDF8 : AForm<0x03, 0x0b, (ops FP:$dst, GR:$srcPtr),
569 "ldfd $dst = [$srcPtr]">, isM;
570 def LDF_FILL : AForm<0x03, 0x0b, (ops FP:$dst, GR:$srcPtr),
571 "ldf.fill $dst = [$srcPtr]">, isM;
574 def POPCNT : AForm_DAG<0x03, 0x0b, (ops GR:$dst, GR:$src),
575 "popcnt $dst = $src",
576 [(set GR:$dst, (ctpop GR:$src))]>, isI;
578 // some FP stuff: // TODO: single-precision stuff?
579 def FADD : AForm_DAG<0x03, 0x0b, (ops FP:$dst, FP:$src1, FP:$src2),
580 "fadd $dst = $src1, $src2",
581 [(set FP:$dst, (fadd FP:$src1, FP:$src2))]>, isF;
582 def FADDS: AForm<0x03, 0x0b, (ops FP:$dst, FP:$src1, FP:$src2),
583 "fadd.s $dst = $src1, $src2">, isF;
584 def FSUB : AForm_DAG<0x03, 0x0b, (ops FP:$dst, FP:$src1, FP:$src2),
585 "fsub $dst = $src1, $src2",
586 [(set FP:$dst, (fsub FP:$src1, FP:$src2))]>, isF;
587 def FMPY : AForm_DAG<0x03, 0x0b, (ops FP:$dst, FP:$src1, FP:$src2),
588 "fmpy $dst = $src1, $src2",
589 [(set FP:$dst, (fmul FP:$src1, FP:$src2))]>, isF;
590 def FMA : AForm_DAG<0x03, 0x0b, (ops FP:$dst, FP:$src1, FP:$src2, FP:$src3),
591 "fma $dst = $src1, $src2, $src3",
592 [(set FP:$dst, (fadd (fmul FP:$src1, FP:$src2), FP:$src3))]>, isF;
593 def FMS : AForm_DAG<0x03, 0x0b, (ops FP:$dst, FP:$src1, FP:$src2, FP:$src3),
594 "fms $dst = $src1, $src2, $src3",
595 [(set FP:$dst, (fsub (fmul FP:$src1, FP:$src2), FP:$src3))]>, isF;
596 def FNMA : AForm_DAG<0x03, 0x0b, (ops FP:$dst, FP:$src1, FP:$src2, FP:$src3),
597 "fnma $dst = $src1, $src2, $src3",
598 [(set FP:$dst, (fneg (fadd (fmul FP:$src1, FP:$src2), FP:$src3)))]>, isF;
599 def FABS : AForm_DAG<0x03, 0x0b, (ops FP:$dst, FP:$src),
601 [(set FP:$dst, (fabs FP:$src))]>, isF;
602 def FNEG : AForm_DAG<0x03, 0x0b, (ops FP:$dst, FP:$src),
604 [(set FP:$dst, (fneg FP:$src))]>, isF;
605 def FNEGABS : AForm_DAG<0x03, 0x0b, (ops FP:$dst, FP:$src),
606 "fnegabs $dst = $src",
607 [(set FP:$dst, (fneg (fabs FP:$src)))]>, isF;
609 let isTwoAddress=1 in {
610 def TCFMAS1 : AForm<0x03, 0x0b,
611 (ops FP:$dst, FP:$bogussrc, FP:$src1, FP:$src2, FP:$src3, PR:$qp),
612 "($qp) fma.s1 $dst = $src1, $src2, $src3">, isF;
613 def TCFMADS0 : AForm<0x03, 0x0b,
614 (ops FP:$dst, FP:$bogussrc, FP:$src1, FP:$src2, FP:$src3, PR:$qp),
615 "($qp) fma.d.s0 $dst = $src1, $src2, $src3">, isF;
618 def CFMAS1 : AForm<0x03, 0x0b,
619 (ops FP:$dst, FP:$src1, FP:$src2, FP:$src3, PR:$qp),
620 "($qp) fma.s1 $dst = $src1, $src2, $src3">, isF;
621 def CFNMAS1 : AForm<0x03, 0x0b,
622 (ops FP:$dst, FP:$src1, FP:$src2, FP:$src3, PR:$qp),
623 "($qp) fnma.s1 $dst = $src1, $src2, $src3">, isF;
625 def CFMADS1 : AForm<0x03, 0x0b,
626 (ops FP:$dst, FP:$src1, FP:$src2, FP:$src3, PR:$qp),
627 "($qp) fma.d.s1 $dst = $src1, $src2, $src3">, isF;
628 def CFMADS0 : AForm<0x03, 0x0b,
629 (ops FP:$dst, FP:$src1, FP:$src2, FP:$src3, PR:$qp),
630 "($qp) fma.d.s0 $dst = $src1, $src2, $src3">, isF;
631 def CFNMADS1 : AForm<0x03, 0x0b,
632 (ops FP:$dst, FP:$src1, FP:$src2, FP:$src3, PR:$qp),
633 "($qp) fnma.d.s1 $dst = $src1, $src2, $src3">, isF;
635 def FRCPAS0 : AForm<0x03, 0x0b, (ops FP:$dstFR, PR:$dstPR, FP:$src1, FP:$src2),
636 "frcpa.s0 $dstFR, $dstPR = $src1, $src2">, isF;
637 def FRCPAS1 : AForm<0x03, 0x0b, (ops FP:$dstFR, PR:$dstPR, FP:$src1, FP:$src2),
638 "frcpa.s1 $dstFR, $dstPR = $src1, $src2">, isF;
640 def XMAL : AForm<0x03, 0x0b, (ops FP:$dst, FP:$src1, FP:$src2, FP:$src3),
641 "xma.l $dst = $src1, $src2, $src3">, isF;
643 def FCVTXF : AForm<0x03, 0x0b, (ops FP:$dst, FP:$src),
644 "fcvt.xf $dst = $src">, isF;
645 def FCVTXUF : AForm<0x03, 0x0b, (ops FP:$dst, FP:$src),
646 "fcvt.xuf $dst = $src">, isF;
647 def FCVTXUFS1 : AForm<0x03, 0x0b, (ops FP:$dst, FP:$src),
648 "fcvt.xuf.s1 $dst = $src">, isF;
649 def FCVTFX : AForm<0x03, 0x0b, (ops FP:$dst, FP:$src),
650 "fcvt.fx $dst = $src">, isF;
651 def FCVTFXU : AForm<0x03, 0x0b, (ops FP:$dst, FP:$src),
652 "fcvt.fxu $dst = $src">, isF;
654 def FCVTFXTRUNC : AForm<0x03, 0x0b, (ops FP:$dst, FP:$src),
655 "fcvt.fx.trunc $dst = $src">, isF;
656 def FCVTFXUTRUNC : AForm<0x03, 0x0b, (ops FP:$dst, FP:$src),
657 "fcvt.fxu.trunc $dst = $src">, isF;
659 def FCVTFXTRUNCS1 : AForm<0x03, 0x0b, (ops FP:$dst, FP:$src),
660 "fcvt.fx.trunc.s1 $dst = $src">, isF;
661 def FCVTFXUTRUNCS1 : AForm<0x03, 0x0b, (ops FP:$dst, FP:$src),
662 "fcvt.fxu.trunc.s1 $dst = $src">, isF;
664 def FNORMD : AForm<0x03, 0x0b, (ops FP:$dst, FP:$src),
665 "fnorm.d $dst = $src">, isF;
667 def GETFD : AForm<0x03, 0x0b, (ops GR:$dst, FP:$src),
668 "getf.d $dst = $src">, isM;
669 def SETFD : AForm<0x03, 0x0b, (ops FP:$dst, GR:$src),
670 "setf.d $dst = $src">, isM;
672 def GETFSIG : AForm<0x03, 0x0b, (ops GR:$dst, FP:$src),
673 "getf.sig $dst = $src">, isM;
674 def SETFSIG : AForm<0x03, 0x0b, (ops FP:$dst, GR:$src),
675 "setf.sig $dst = $src">, isM;
677 // these four FP<->int conversion patterns need checking/cleaning
678 def SINT_TO_FP : Pat<(sint_to_fp GR:$src),
679 (FNORMD (FCVTXF (SETFSIG GR:$src)))>;
680 def UINT_TO_FP : Pat<(uint_to_fp GR:$src),
681 (FNORMD (FCVTXUF (SETFSIG GR:$src)))>;
682 def FP_TO_SINT : Pat<(i64 (fp_to_sint FP:$src)),
683 (GETFSIG (FCVTFXTRUNC FP:$src))>;
684 def FP_TO_UINT : Pat<(i64 (fp_to_uint FP:$src)),
685 (GETFSIG (FCVTFXUTRUNC FP:$src))>;
688 let isTerminator = 1, isBranch = 1, noResults = 1 in {
689 def BRL_NOTCALL : RawForm<0x03, 0xb0, (ops i64imm:$dst),
690 "(p0) brl.cond.sptk $dst">, isB;
691 def BRLCOND_NOTCALL : RawForm<0x03, 0xb0, (ops PR:$qp, i64imm:$dst),
692 "($qp) brl.cond.sptk $dst">, isB;
693 def BRCOND_NOTCALL : RawForm<0x03, 0xb0, (ops PR:$qp, GR:$dst),
694 "($qp) br.cond.sptk $dst">, isB;
697 let isCall = 1, noResults = 1, /* isTerminator = 1, isBranch = 1, */
698 Uses = [out0,out1,out2,out3,out4,out5,out6,out7],
699 // all calls clobber non-callee-saved registers, and for now, they are these:
700 Defs = [r2,r3,r8,r9,r10,r11,r14,r15,r16,r17,r18,r19,r20,r21,r22,r23,r24,
701 r25,r26,r27,r28,r29,r30,r31,
702 p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,
703 F6,F7,F8,F9,F10,F11,F12,F13,F14,F15,
704 F32,F33,F34,F35,F36,F37,F38,F39,F40,F41,F42,F43,F44,F45,F46,F47,F48,F49,
705 F50,F51,F52,F53,F54,F55,F56,
706 F57,F58,F59,F60,F61,F62,F63,F64,F65,F66,F67,F68,F69,F70,F71,F72,F73,F74,
707 F75,F76,F77,F78,F79,F80,F81,
708 F82,F83,F84,F85,F86,F87,F88,F89,F90,F91,F92,F93,F94,F95,F96,F97,F98,F99,
709 F100,F101,F102,F103,F104,F105,
710 F106,F107,F108,F109,F110,F111,F112,F113,F114,F115,F116,F117,F118,F119,
711 F120,F121,F122,F123,F124,F125,F126,F127,
712 out0,out1,out2,out3,out4,out5,out6,out7] in {
714 def BRCALL: RawForm<0x03, 0xb0, (ops calltarget:$dst),
715 "br.call.sptk rp = $dst">, isB; // FIXME: teach llvm about branch regs?
718 // calls a globaladdress
719 def BRCALL_IPREL_GA : RawForm<0x03, 0xb0, (ops calltarget:$dst),
720 "br.call.sptk rp = $dst">, isB; // FIXME: teach llvm about branch regs?
721 // calls an externalsymbol
722 def BRCALL_IPREL_ES : RawForm<0x03, 0xb0, (ops calltarget:$dst),
723 "br.call.sptk rp = $dst">, isB; // FIXME: teach llvm about branch regs?
724 // calls through a function descriptor
725 def BRCALL_INDIRECT : RawForm<0x03, 0xb0, (ops GR:$branchreg),
726 "br.call.sptk rp = $branchreg">, isB; // FIXME: teach llvm about branch regs?
727 def BRLCOND_CALL : RawForm<0x03, 0xb0, (ops PR:$qp, i64imm:$dst),
728 "($qp) brl.cond.call.sptk $dst">, isB;
729 def BRCOND_CALL : RawForm<0x03, 0xb0, (ops PR:$qp, GR:$dst),
730 "($qp) br.cond.call.sptk $dst">, isB;
734 let isTerminator = 1, isReturn = 1, noResults = 1 in
735 def RET : AForm_DAG<0x03, 0x0b, (ops),
736 "br.ret.sptk.many rp",
737 [(retflag)]>, isB; // return
738 def : Pat<(ret), (RET)>;
740 // the evil stop bit of despair
741 def STOP : PseudoInstIA64<(ops variable_ops), ";;">;