- Added some SSE2 128-bit packed integer ops.
[oota-llvm.git] / lib / Target / SparcV9 / SparcV9.burg.in
1 %{               // -*- C++ -*-
2 /* ===----------------------------------------------------------------------===
3 // 
4 //                     The LLVM Compiler Infrastructure
5 //
6 // This file was developed by the LLVM research group and is distributed under
7 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 // 
9 //===----------------------------------------------------------------------===*/
10
11 Xinclude <cstdio>
12 Xinclude "SparcV9InstrForest.h"
13
14 typedef llvm::InstrTreeNode* NODEPTR_TYPE;
15 Xdefine OP_LABEL(p)     ((p)->opLabel)
16 Xdefine LEFT_CHILD(p)   ((p)->LeftChild)
17 Xdefine RIGHT_CHILD(p)  ((p)->RightChild)
18 Xdefine STATE_LABEL(p)  ((p)->state)
19 Xdefine PANIC           printf
20
21 // Get definitions for various instruction values that we will need...
22 #define HANDLE_TERM_INST(N, OPC, CLASS)   Ydefine OPC##OPCODE N
23 #define HANDLE_UNARY_INST(N, OPC, CLASS)  Ydefine OPC##OPCODE N
24 #define HANDLE_BINARY_INST(N, OPC, CLASS) Ydefine OPC##OPCODE N
25 #define HANDLE_MEMORY_INST(N, OPC, CLASS) Ydefine OPC##OPCODE N
26 #define HANDLE_OTHER_INST(N, OPC, CLASS)  Ydefine OPC##OPCODE N
27
28 #include "llvm/Instruction.def"
29
30 %}
31
32 %start stmt
33
34 %term Ret=RetOPCODE             /* return void from a function */
35 %term RetValue=101              /* return a value from a function */
36 %term BrUncond=BrOPCODE
37 %term BrCond=102
38 %term Switch=SwitchOPCODE
39                 /* 4 is unused */
40 %term Add=AddOPCODE
41 %term Sub=SubOPCODE
42 %term Mul=MulOPCODE
43 %term Div=DivOPCODE
44 %term Rem=RemOPCODE
45 %term And=AndOPCODE
46 %term Or=OrOPCODE
47 %term Xor=XorOPCODE
48                 /* Use the next 4 to distinguish bitwise operators from
49                  * logical operators.  This is no longer used for SparcV9,
50                  * but may be useful for other target machines.
51                  * The last one is the bitwise Not(val) == XOR val, 11..1.
52                  * Note that it is also a binary operator, not unary.
53                  */
54 %term BAnd=112
55 %term BOr=113
56 %term BXor=114
57 %term BNot=214
58                 /* The next one is the boolean Not(val) == bool XOR val, true
59                  * Note that it is also a binary operator, not unary.
60                  */
61 %term  Not=314
62
63 %term SetCC=115 /* use this to match all SetCC instructions */
64         /* %term SetEQ=13 */
65         /* %term SetNE=14 */
66         /* %term SetLE=15 */
67         /* %term SetGE=16 */
68         /* %term SetLT=17 */
69         /* %term SetGT=18 */
70 %term Malloc=MallocOPCODE
71 %term Free=FreeOPCODE
72 %term Alloca=AllocaOPCODE
73 %term AllocaN=123               /* alloca with arg N */
74 %term Load=LoadOPCODE
75 %term Store=StoreOPCODE
76 %term GetElemPtr=GetElementPtrOPCODE
77 %term GetElemPtrIdx=126         /* getElemPtr with index vector */
78
79 %term Phi=PHIOPCODE
80
81 %term Cast=CastOPCODE /* cast that will be ignored. others are made explicit */
82 %term ToBoolTy=128
83 %term ToUByteTy=129
84 %term ToSByteTy=130
85 %term ToUShortTy=131
86 %term ToShortTy=132
87 %term ToUIntTy=133
88 %term ToIntTy=134
89 %term ToULongTy=135
90 %term ToLongTy=136
91 %term ToFloatTy=137
92 %term ToDoubleTy=138
93 %term ToArrayTy=139
94 %term ToPointerTy=140
95
96 %term Call=CallOPCODE
97 %term Shl=ShlOPCODE
98 %term Shr=ShrOPCODE
99 %term VAArg=VAArgOPCODE
100                 /* 33...46 are unused */
101     /*
102      * The foll. values should match the constants in InstrForest.h
103      */
104 %term VRegList=97
105 %term VReg=98
106 %term Constant=99
107 %term Label=100
108                 /* 50+i is a variant of i, as defined above */
109
110
111 %%
112 /*-----------------------------------------------------------------------*
113  * The productions of the grammar.
114  * Note that all chain rules are numbered 101 and above.
115  * Also, a special case of production X is numbered 100+X, 200+X, etc.
116  * The cost of a 1-cycle operation is represented as 10, to allow
117  * finer comparisons of costs (effectively, fractions of 1/10).
118  *-----------------------------------------------------------------------*/
119
120         /*
121          * The top-level statements
122          */
123 stmt:   Ret                     =   1 (30);
124 stmt:   RetValue(reg)           =   2 (30);
125 stmt:   Store(reg,reg)          =   3 (10);
126 stmt:   Store(reg,ptrreg)       =   4 (10);
127 stmt:   BrUncond                =   5 (20);
128 stmt:   BrCond(setCC)           =   6 (20);     /* branch on cond. code */
129 stmt:   BrCond(setCCconst)      = 206 (10);     /* may save one instruction */
130 stmt:   BrCond(reg)             =   8 (20);     /* may avoid an extra instr */
131 stmt:   BrCond(Constant)        = 208 (20);     /* may avoid an extra instr */
132 stmt:   Switch(reg)             =   9 (30);     /* cost = load + branch */
133
134 stmt:   reg                     =  111 (0);
135
136         /*
137          * List node used for nodes with more than 2 children
138          */
139 reg:    VRegList(reg,reg)       =  10 (0);
140
141         /*
142          * Special case non-terminals to help combine unary instructions.
143          *      Eg1:  zdouble <- todouble(xfloat) * todouble(yfloat)
144          *      Eg2:  c       <- a AND (NOT b).
145          * Note that the costs are counted for the special non-terminals here,
146          * and should not be counted again for the reg productions later.
147          */
148 not:      Not(reg,reg)          =   21 (10);
149 tobool:   ToBoolTy(reg)         =   22 (10);
150 not:      Not(tobool, reg)      =  322 (10); // fold cast-to-bool into not
151 toubyte:  ToUByteTy(reg)        =   23 (10);
152 tosbyte:  ToSByteTy(reg)        =   24 (10);
153 toushort: ToUShortTy(reg)       =   25 (10);
154 toshort:  ToShortTy(reg)        =   26 (10);
155 touint:   ToUIntTy(reg)         =   27 (10);
156 toint:    ToIntTy(reg)          =   28 (10);
157 toulong:  ToULongTy(reg)        =   29 (10);
158 tolong:   ToLongTy(reg)         =   30 (10);
159 tofloat:  ToFloatTy(reg)        =   31 (10);
160 todouble: ToDoubleTy(reg)       =   32 (10);
161 todoubleConst: ToDoubleTy(Constant) = 232 (10);
162
163         /*
164          * All the ways to produce a boolean value (Not and ToBoolTy are above):
165          * -- boolean operators: Not, And, Or, ..., ToBoolTy, SetCC
166          * -- an existing boolean register not in the same tree
167          * -- a boolean constant
168          * 
169          * For And, Or, Xor, we add special cases for when:
170          * (a) one operand is a constant.
171          * (b) one operand is a NOT, to use the ANDN, ORN, and XORN instrns.
172          * We do not need the cases when both operands are constant
173          * because constant folding should take care of that beforehand.
174          */
175 reg:    And(reg,reg)            =   38 (10);
176 reg:    And(reg,not)            =  138 (0);     /* cost is counted for not */
177 reg:    And(reg,Constant)       =  238 (10);
178 reg:    Or (reg,reg)            =   39 (10);
179 reg:    Or (reg,not)            =  139 (0);     /* cost is counted for not */
180 reg:    Or (reg,Constant)       =  239 (10);
181 reg:    Xor(reg,reg)            =   40 (10);
182 reg:    Xor(reg,not)            =  140 (0);     /* cost is counted for not */
183 reg:    Xor(reg,Constant)       =  240 (10);
184
185         /* Special case non-terms for BrCond(setCC) and BrCond(setCCconst) */
186 setCCconst: SetCC(reg,Constant) =   41 (5);
187 setCC:      SetCC(reg,reg)      =   42 (10);
188
189 reg:    not                     =  221 (0);
190 reg:    tobool                  =  222 (0);
191 reg:    setCCconst              =  241 (0);
192 reg:    setCC                   =  242 (0);
193
194         /*
195          * Special case non-terminals for the unary cast operators.
196          * Some of these can be folded into other operations (e.g., todouble).
197          * The rest are just for uniformity.
198          */
199 reg:    toubyte                 =  123 (0);
200 reg:    tosbyte                 =  124 (0);
201 reg:    toushort                =  125 (0);
202 reg:    toshort                 =  126 (0);
203 reg:    touint                  =  127 (0);
204 reg:    toint                   =  128 (0);
205 reg:    toulong                 =  129 (0);
206 reg:    tolong                  =  130 (0);
207 reg:    tofloat                 =  131 (0);
208 reg:    todouble                =  132 (0);
209 reg:    todoubleConst           =  133 (0);
210
211 reg:    ToArrayTy(reg)          =  19 (10);
212 reg:    ToPointerTy(reg)        =  20 (10);
213
214         /*
215          * The binary arithmetic operators.
216          */
217 reg:    Add(reg,reg)            =   33 (10);
218 reg:    Sub(reg,reg)            =   34 (10);
219 reg:    Mul(reg,reg)            =   35 (30);
220 reg:    Mul(todouble,todouble)  =  135 (20);    /* avoids 1-2 type converts */
221 reg:    Div(reg,reg)            =   36 (60);
222 reg:    Rem(reg,reg)            =   37 (60);
223
224         /*
225          * The binary bitwise logical operators.
226          */
227 reg:    BAnd(reg,reg)           =  338 (10);
228 reg:    BAnd(reg,bnot)          =  438 ( 0);    /* cost is counted for not */
229 reg:    BOr( reg,reg)           =  339 (10);
230 reg:    BOr( reg,bnot)          =  439 ( 0);    /* cost is counted for not */
231 reg:    BXor(reg,reg)           =  340 (10);
232 reg:    BXor(reg,bnot)          =  440 ( 0);    /* cost is counted for not */
233
234 reg:    bnot                    =  321 ( 0);
235 bnot:   BNot(reg,reg)           =  421 (10);
236
237         /*
238          * Special cases for the binary operators with one constant argument.
239          * Not and BNot are effectively just one argument, so not needed here.
240          */
241 reg:    Add(reg,Constant)       =  233 (10);
242 reg:    Sub(reg,Constant)       =  234 (10);
243 reg:    Mul(reg,Constant)       =  235 (30);
244 reg:    Mul(todouble,todoubleConst) = 335 (20); /* avoids 1-2 type converts */
245 reg:    Div(reg,Constant)       =  236 (60);
246 reg:    Rem(reg,Constant)       =  237 (60);
247
248 reg:    BAnd(reg,Constant)      =  538 (0);
249 reg:    BOr( reg,Constant)      =  539 (0);
250 reg:    BXor(reg,Constant)      =  540 (0);
251
252         /*
253          * Memory access instructions
254          */
255 reg:    Load(reg)               =   51 (30);
256 reg:    Load(ptrreg)            =   52 (20);    /* 1 counted for ptrreg */
257 reg:    ptrreg                  =  155 (0);
258 ptrreg: GetElemPtr(reg)         =   55 (10);
259 ptrreg: GetElemPtrIdx(reg,reg)  =   56 (10);
260 reg:    Alloca                  =   57 (10);
261 reg:    AllocaN(reg)            =   58 (10);
262
263         /*
264          * Other operators producing register values
265          */
266 reg:    Call                    =   61 (20);    /* just ignore the operands! */
267 reg:    Shl(reg,reg)            =   62 (20);    /* 1 for issue restrictions */
268 reg:    Shr(reg,reg)            =   63 (20);    /* 1 for issue restrictions */
269 reg:    Phi(reg,reg)            =   64 (0);
270 reg:    VAArg(reg)              =   66 (40);    /* get a vararg */
271
272         /*
273          * Finally, leaf nodes of expression trees.
274          */
275 reg:    VReg                    =   71 (0);
276 reg:    Constant                =   72 (3);     /* prefer direct use */
277
278
279
280 %%
281 /*-----------------------------------------------------------------------*
282  * The rest of this file provides code to print the cover produced
283  * by BURG and information about computed tree cost and matches.
284  * This code was taken from sample.gr provided with BURG.
285  *-----------------------------------------------------------------------*/
286
287 void printcover(NODEPTR_TYPE p, int goalnt, int indent) {
288         int eruleno = burm_rule(STATE_LABEL(p), goalnt);
289         short *nts = burm_nts[eruleno];
290         NODEPTR_TYPE kids[10];
291         int i;
292         
293         if (eruleno == 0) {
294                 printf("no cover\n");
295                 return;
296         }
297         for (i = 0; i < indent; i++)
298                 printf(".");
299         printf("%s\n", burm_string[eruleno]);
300         burm_kids(p, eruleno, kids);
301         for (i = 0; nts[i]; i++)
302                 printcover(kids[i], nts[i], indent+1);
303 }
304
305 void printtree(NODEPTR_TYPE p) {
306         int op = burm_op_label(p);
307
308         printf("%s", burm_opname[op]);
309         switch (burm_arity[op]) {
310         case 0:
311                 break;
312         case 1:
313                 printf("(");
314                 printtree(burm_child(p, 0));
315                 printf(")");
316                 break;
317         case 2:
318                 printf("(");
319                 printtree(burm_child(p, 0));
320                 printf(", ");
321                 printtree(burm_child(p, 1));
322                 printf(")");
323                 break;
324         }
325 }
326
327 int treecost(NODEPTR_TYPE p, int goalnt, int costindex) {
328         int eruleno = burm_rule(STATE_LABEL(p), goalnt);
329         int cost = burm_cost[eruleno][costindex], i;
330         short *nts = burm_nts[eruleno];
331         NODEPTR_TYPE kids[10];
332
333         burm_kids(p, eruleno, kids);
334         for (i = 0; nts[i]; i++)
335                 cost += treecost(kids[i], nts[i], costindex);
336         return cost;
337 }
338
339 void printMatches(NODEPTR_TYPE p) {
340         int nt;
341         int eruleno;
342
343         printf("Node 0x%lx= ", (unsigned long)p);
344         printtree(p);
345         printf(" matched rules:\n");
346         for (nt = 1; burm_ntname[nt] != (char*)NULL; nt++)
347                 if ((eruleno = burm_rule(STATE_LABEL(p), nt)) != 0)
348                         printf("\t%s\n", burm_string[eruleno]);
349 }