Added some casts to remove warnings
[libfirm] / ir / be / mips / mips_spec.pl
1 # Creation: 2006/02/13
2 # $Id$
3 # This is a template specification for the Firm-Backend
4
5 # the cpu architecture (ia32, ia64, mips, sparc, ppc, ...)
6
7 $arch = "mips";
8 $new_emit_syntax = 1;
9
10 # The node description is done as a perl hash initializer with the
11 # following structure:
12 #
13 # %nodes = (
14 #
15 # <op-name> => {
16 #   op_flags  => "N|L|C|X|I|F|Y|H|c|K",
17 #   "arity"     => "0|1|2|3 ... |variable|dynamic|any",
18 #   "state"     => "floats|pinned|mem_pinned|exc_pinned",
19 #   "args"      => [
20 #                    { "type" => "type 1", "name" => "name 1" },
21 #                    { "type" => "type 2", "name" => "name 2" },
22 #                    ...
23 #                  ],
24 #   "comment"   => "any comment for constructor",
25 #   reg_req   => { in => [ "reg_class|register" ], out => [ "reg_class|register|in_rX" ] },
26 #   "cmp_attr"  => "c source code for comparing node attributes",
27 #   emit      => "emit code with templates",
28 #   "rd_constructor" => "c source code which constructs an ir_node"
29 # },
30 #
31 # ... # (all nodes you need to describe)
32 #
33 # ); # close the %nodes initializer
34
35 # op_flags: flags for the operation, OPTIONAL (default is "N")
36 # the op_flags correspond to the firm irop_flags:
37 #   N   irop_flag_none
38 #   L   irop_flag_labeled
39 #   C   irop_flag_commutative
40 #   X   irop_flag_cfopcode
41 #   I   irop_flag_ip_cfopcode
42 #   F   irop_flag_fragile
43 #   Y   irop_flag_forking
44 #   H   irop_flag_highlevel
45 #   c   irop_flag_constlike
46 #   K   irop_flag_keep
47 #
48 #   R   rematerializeable
49 #   N   not spillable
50 #   I   ignore for register allocation
51 #
52 # state: state of the operation, OPTIONAL (default is "floats")
53 #
54 # arity: arity of the operation, MUST NOT BE OMITTED
55 #
56 # args:  the OPTIONAL arguments of the node constructor (debug, irg and block
57 #        are always the first 3 arguments and are always autmatically
58 #        created)
59 #        If this key is missing the following arguments will be created:
60 #        for i = 1 .. arity: ir_node *op_i
61 #        ir_mode *mode
62 #
63 # outs:  if a node defines more than one output, the names of the projections
64 #        nodes having outs having automatically the mode mode_T
65 #
66 # comment: OPTIONAL comment for the node constructor
67 #
68 # rd_constructor: for every operation there will be a
69 #      new_rd_<arch>_<op-name> function with the arguments from above
70 #      which creates the ir_node corresponding to the defined operation
71 #      you can either put the complete source code of this function here
72 #
73 #      This key is OPTIONAL. If omitted, the following constructor will
74 #      be created:
75 #      if (!op_<arch>_<op-name>) assert(0);
76 #      for i = 1 to arity
77 #         set in[i] = op_i
78 #      done
79 #      res = new_ir_node(db, irg, block, op_<arch>_<op-name>, mode, arity, in)
80 #      return res
81 #
82 # NOTE: rd_constructor and args are only optional if and only if arity is 0,1,2 or 3
83
84 # register types:
85 #   0 - no special type
86 #   1 - caller save (register must be saved by the caller of a function)
87 #   2 - callee save (register must be saved by the called function)
88 #   4 - ignore (do not assign this register)
89 # NOTE: Last entry of each class is the largest Firm-Mode a register can hold\
90 %reg_classes = (
91         "gp" => [
92                 { name => "zero", type => 4+2 },  # always zero
93                 { name => "at", type => 4 }, # reserved for assembler
94                 { name => "v0", realname => "2", type => 1 }, # first return value
95                 { name => "v1", realname => "3", type => 1 }, # second return value
96                 { name => "a0", realname => "4", type => 1 }, # first argument
97                 { name => "a1", realname => "5", type => 1 }, # second argument
98                 { name => "a2", realname => "6", type => 1 }, # third argument
99                 { name => "a3", realname => "7", type => 1 }, # fourth argument
100                 { name => "t0", realname => "8", type => 1 },
101                 { name => "t1", realname => "9", type => 1 },
102                 { name => "t2", realname => "10", type => 1 },
103                 { name => "t3", realname => "11", type => 1 },
104                 { name => "t4", realname => "12", type => 1 },
105                 { name => "t5", realname => "13", type => 1 },
106                 { name => "t6", realname => "14", type => 1 },
107                 { name => "t7", realname => "15", type => 1 },
108                 { name => "s0", realname => "16", type => 2 },
109                 { name => "s1", realname => "17", type => 2 },
110                 { name => "s2", realname => "18", type => 2 },
111                 { name => "s3", realname => "19", type => 2 },
112                 { name => "s4", realname => "20", type => 2 },
113                 { name => "s5", realname => "21", type => 2 },
114                 { name => "s6", realname => "22", type => 2 },
115                 { name => "s7", realname => "23", type => 2 },
116                 { name => "t8", realname => "24", type => 1 },
117                 { name => "t9", realname => "25", type => 1 },
118                 { name => "kt0", type => 4 }, # reserved for OS
119                 { name => "kt1", type => 4 }, # reserved for OS
120                 { name => "gp", type => 4 }, # general purpose
121                 { name => "sp", type => 4 }, # stack pointer
122                 { name => "fp", type => 4 }, # frame pointer
123                 { name => "ra", type => 2+1 }, # return address
124                 { mode => "mode_Iu" }
125         ],
126 ); # %reg_classes
127
128 %emit_templates = (
129     S0 => "${arch}_emit_source_register(env, node, 0);",
130     S1 => "${arch}_emit_source_register(env, node, 1);",
131     S2 => "${arch}_emit_source_register(env, node, 2);",
132     D0 => "${arch}_emit_dest_register(env, node, 0);",
133     D1 => "${arch}_emit_dest_register(env, node, 1);",
134     D2 => "${arch}_emit_dest_register(env, node, 2);",
135         C  => "${arch}_emit_immediate(env, node);",
136         JumpTarget => "${arch}_emit_jump_target(env, node);",
137         JumpTarget1 => "${arch}_emit_jump_target_proj(env, node, 1);",
138         JumpOrFallthrough => "${arch}_emit_jump_or_fallthrough(env, node, 0);",
139 );
140
141
142 #--------------------------------------------------#
143 #                        _                         #
144 #                       (_)                        #
145 #  _ __   _____      __  _ _ __    ___  _ __  ___  #
146 # | '_ \ / _ \ \ /\ / / | | '__|  / _ \| '_ \/ __| #
147 # | | | |  __/\ V  V /  | | |    | (_) | |_) \__ \ #
148 # |_| |_|\___| \_/\_/   |_|_|     \___/| .__/|___/ #
149 #                                      | |         #
150 #                                      |_|         #
151 #--------------------------------------------------#
152
153 %nodes = (
154
155 #-----------------------------------------------------------------#
156 #  _       _                                         _            #
157 # (_)     | |                                       | |           #
158 #  _ _ __ | |_ ___  __ _  ___ _ __   _ __   ___   __| | ___  ___  #
159 # | | '_ \| __/ _ \/ _` |/ _ \ '__| | '_ \ / _ \ / _` |/ _ \/ __| #
160 # | | | | | ||  __/ (_| |  __/ |    | | | | (_) | (_| |  __/\__ \ #
161 # |_|_| |_|\__\___|\__, |\___|_|    |_| |_|\___/ \__,_|\___||___/ #
162 #                   __/ |                                         #
163 #                  |___/                                          #
164 #-----------------------------------------------------------------#
165
166 # commutative operations
167
168 addu => {
169         op_flags  => "C",
170         reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
171         emit      => '. addu %D0, %S0, %S1',
172         mode      => "mode_Iu",
173 },
174
175 addiu => {
176         reg_req   => { in => [ "gp" ], out => [ "gp" ] },
177         emit      => '. addiu %D0, %S0, %C',
178         cmp_attr  => 'return attr_a->tv != attr_b->tv;',
179         mode      => "mode_Iu",
180 },
181
182 and => {
183         op_flags  => "C",
184         reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
185         emit      => '. and %D0, %S0, %S1',
186         mode      => "mode_Iu",
187 },
188
189 andi => {
190         reg_req   => { in => [ "gp" ], out => [ "gp" ] },
191         emit      => '. andi %D0, %S0, %C',
192         cmp_attr  => 'return attr_a->tv != attr_b->tv;',
193         mode      => "mode_Iu",
194 },
195
196 div => {
197         reg_req   => { in => [ "gp", "gp" ], out => [ "none" ] },
198         emit      => '. div %S0, %S1',
199         mode      => "mode_M",
200 },
201
202 divu => {
203         reg_req   => { in => [ "gp", "gp" ], out => [ "none" ] },
204         emit      => '. divu %S0, %S1',
205         mode      => "mode_M",
206 },
207
208 mult => {
209         op_flags  => "C",
210         reg_req   => { in => [ "gp", "gp" ], out => [ "none" ] },
211         emit      => '. mult %S0, %S1',
212         mode      => "mode_M"
213 },
214
215 multu => {
216         op_flags  => "C",
217         reg_req   => { in => [ "gp", "gp" ], out => [ "none" ] },
218         emit      => '. multu %S0, %S1',
219         mode      => "mode_M",
220 },
221
222 nor => {
223         op_flags  => "C",
224         reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
225         emit      => '. nor %D0, %S0, %S1',
226         mode      => "mode_Iu"
227 },
228
229 not => {
230         reg_req   => { in => [ "gp" ], out => [ "gp" ] },
231         emit      => '. nor %D0, %S0, $zero',
232         mode      => "mode_Iu"
233 },
234
235 or => {
236         op_flags  => "C",
237         reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
238         emit      => '. or %D0, %S0, %S1',
239         mode      => "mode_Iu"
240 },
241
242 ori => {
243         reg_req   => { in => [ "gp" ], out => [ "gp" ] },
244         emit      => '. ori %D0, %S0, %C',
245         cmp_attr  => 'return attr_a->tv != attr_b->tv;',
246         mode      => "mode_Iu"
247 },
248
249 sl => {
250         reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
251         emit      => '
252         if (mode_is_signed(get_irn_mode(node))) {
253                 . sal %D0, %S0, %S1
254         } else {
255                 . sll %D0, %S0, %S1
256         }
257 ',
258         mode      => "mode_Iu",
259 },
260
261 sli => {
262         reg_req   => { in => [ "gp" ], out => [ "gp" ] },
263         emit      => '
264         if (mode_is_signed(get_irn_mode(node))) {
265                 . sal %D0, %S0, %C
266         } else {
267                 . sll %D0, %S0, %C
268         }
269 ',
270         mode      => "mode_Iu",
271 },
272
273 sra => {
274         reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
275         emit      => '. sra %D0, %S0, %S1',
276         mode      => "mode_Iu"
277 },
278
279 srai => {
280         reg_req   => { in => [ "gp" ], out => [ "gp" ] },
281         emit      => '. sra %D0, %S0, %C',
282         cmp_attr  => 'return attr_a->tv != attr_b->tv;',
283         mode      => "mode_Iu",
284 },
285
286 sr => {
287         reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
288         emit      => '
289         if (mode_is_signed(get_irn_mode(node))) {
290                 . sra %D0, %S0, %S1
291         } else {
292                 . srl %D0, %S0, %S1
293         }
294 ',
295         mode      => "mode_Iu",
296 },
297
298 sri => {
299         reg_req   => { in => [ "gp" ], out => [ "gp" ] },
300         emit      => '
301         if (mode_is_signed(get_irn_mode(node))) {
302                 . sra %D0, %S0, %C
303         } else {
304                 . srl %D0, %S0, %C
305         }
306 ',
307         mode      => "mode_Iu"
308 },
309
310 srlv => {
311         reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
312         emit      => '. srlv %D0, %S0, %S1',
313         mode      => "mode_Iu"
314 },
315
316 sllv => {
317         reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
318         emit      => '. sllv %D0, %S0, %S1',
319         mode      => "mode_Iu"
320 },
321
322 sub => {
323         reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
324         emit      => '. subu %D0, %S0, %S1',
325         mode      => "mode_Iu"
326 },
327
328 subuzero => {
329         reg_req   => { in => [ "gp" ], out => [ "gp" ] },
330         emit      => '. subu %D0, $zero, %S0',
331         mode      => "mode_Iu",
332 },
333
334 xor => {
335         reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
336         emit      => '. xor %D0, %S0, %S1',
337         mode      => "mode_Iu",
338 },
339
340 xori => {
341         reg_req   => { in => [ "gp" ], out => [ "gp" ] },
342         emit      => '. xori %D0, %S0, %C',
343         cmp_attr  => 'return attr_a->tv != attr_b->tv;',
344         mode      => "mode_Iu",
345 },
346
347 #   ____                _              _
348 #  / ___|___  _ __  ___| |_ __ _ _ __ | |_ ___
349 # | |   / _ \| '_ \/ __| __/ _` | '_ \| __/ __|
350 # | |__| (_) | | | \__ \ || (_| | | | | |_\__ \
351 #  \____\___/|_| |_|___/\__\__,_|_| |_|\__|___/
352 #
353
354 # load upper imediate
355 lui => {
356         op_flags  => "c",
357         reg_req   => { out => [ "gp" ] },
358         emit      => '. lui %D0, %C',
359         cmp_attr  => 'return attr_a->tv != attr_b->tv;',
360         mode      => "mode_Iu",
361 },
362
363 mflo => {
364         reg_req   => { in => [ "none" ], out => [ "gp" ] },
365         emit      => '. mflo %D0',
366         mode      => "mode_Iu"
367 },
368
369 mfhi => {
370         reg_req   => { in => [ "none" ], out => [ "gp" ] },
371         emit      => '. mfhi %D0',
372         mode      => "mode_Iu"
373 },
374
375 zero => {
376         state     => "pinned",
377         op_flags  => "c",
378         irn_flags => "I",
379         reg_req   => { out => [ "zero" ] },
380         emit      => '',
381         mode      => "mode_Iu"
382 },
383
384 #
385 #  ____                       _        __  _
386 # | __ ) _ __ __ _ _ __   ___| |__    / / | |_   _ _ __ ___  _ __
387 # |  _ \| '__/ _` | '_ \ / __| '_ \  / /  | | | | | '_ ` _ \| '_ \
388 # | |_) | | | (_| | | | | (__| | | |/ / |_| | |_| | | | | | | |_) |
389 # |____/|_|  \__,_|_| |_|\___|_| |_/_/ \___/ \__,_|_| |_| |_| .__/
390 #                                                           |_|
391 #
392
393 slt => {
394         reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
395         emit    => '. slt %D0, %S0, %S1',
396         mode    => "mode_Iu",
397 },
398
399 sltu => {
400         reg_req => { in => [ "gp", "gp" ], out => [ "gp" ] },
401         emit    => '. sltu %D0, %S0, %S1',
402         mode    => "mode_Iu",
403 },
404
405 slti => {
406         reg_req => { in => [ "gp" ], out => [ "gp" ] },
407         emit    => '. slti %D0, %S0, %C',
408         mode    => "mode_Iu",
409 },
410
411 sltiu => {
412         reg_req => { in => [ "gp" ], out => [ "gp" ] },
413         emit    => '. slti %D0, %S0, %C',
414         mode    => "mode_Iu",
415 },
416
417 beq => {
418         op_flags => "X|Y",
419         reg_req  => { in => [ "gp", "gp" ], out => [ "none", "none" ] },
420         outs     => [ "false", "true" ],
421         emit     => '. beq %S0, %S1, %JumpTarget1
422                      . %JumpOrFallthrough'
423 },
424
425 bne => {
426         op_flags => "X|Y",
427         reg_req  => { in => [ "gp", "gp" ], out => [ "none", "none" ] },
428         outs     => [ "false", "true" ],
429         emit     => '. bne %S0, %S1, %JumpTarget1
430                      . %JumpOrFallthrough'
431 },
432
433 bgtz => {
434         op_flags => "X|Y",
435         reg_req  => { in => [ "gp" ], out => [ "none", "none" ] },
436         outs     => [ "false", "true" ],
437         emit     => '. bgtz %S0, %JumpTarget1
438                      . %JumpOrFallthrough'
439 },
440
441 blez => {
442         op_flags => "X|Y",
443         reg_req  => { in => [ "gp" ], out => [ "none", "none" ] },
444         outs     => [ "false", "true" ],
445         emit     => '. blez %S0, %JumpTarget1
446                      . %JumpOrFallthrough'
447 },
448
449 b => {
450         op_flags => "X",
451         reg_req  => { in => [ ], out => [ "none" ] },
452         emit     => '. b %JumpTarget',
453         mode     => 'mode_X'
454 },
455
456 jr => {
457         op_flags => "X",
458         reg_req  => { in => [ "gp" ], out => [ "none" ] },
459         emit     => '. jr %S0',
460         mode     => 'mode_X'
461 },
462
463 SwitchJump => {
464         op_flags => "X",
465         reg_req  => { in => [ "gp" ], out => [ "none" ] },
466         emit     => '. jr %S0'
467 },
468
469 #  _                    _    ______  _
470 # | |    ___   __ _  __| |  / / ___|| |_ ___  _ __ ___
471 # | |   / _ \ / _` |/ _` | / /\___ \| __/ _ \| '__/ _ \
472 # | |__| (_) | (_| | (_| |/ /  ___) | || (_) | | |  __/
473 # |_____\___/ \__,_|\__,_/_/  |____/ \__\___/|_|  \___|
474 #
475
476 lw => {
477         op_flags => "L|F",
478         state    => "exc_pinned",
479         reg_req  => { in => [ "none", "gp" ], out => [ "gp", "none" ] },
480         outs     => [ "res", "M" ],
481         emit     => '. lw %D0, %C(%S1)',
482 },
483
484 lh => {
485         op_flags => "L|F",
486         state    => "exc_pinned",
487         reg_req  => { in => [ "none", "gp" ], out => [ "gp", "none" ] },
488         outs     => [ "res", "M" ],
489         emit     => '. lh %D0, %C(%S1)',
490 },
491
492 lhu => {
493         op_flags => "L|F",
494         state    => "exc_pinned",
495         reg_req  => { in => [ "none", "gp" ], out => [ "gp", "none" ] },
496         outs     => [ "res", "M" ],
497         emit     => '. lhu %D0, %C(%S1)',
498 },
499
500 lb => {
501         op_flags => "L|F",
502         state    => "exc_pinned",
503         reg_req  => { in => [ "none", "gp" ], out => [ "gp", "none" ] },
504         outs     => [ "res", "M" ],
505         emit     => '. lb %D0, %C(%S1)',
506 },
507
508 lbu => {
509         op_flags => "L|F",
510         state    => "exc_pinned",
511         reg_req  => { in => [ "none", "gp" ], out => [ "gp", "none" ] },
512         outs     => [ "res", "M" ],
513         emit     => '. lbu %D0, %C(%S1)',
514 },
515
516 sw => {
517         op_flags => "L|F",
518         state    => "exc_pinned",
519         reg_req  => { in => [ "none", "gp", "gp" ], out => [ "none" ] },
520         emit     => '. sw %S2, %C(%S1)',
521         mode     => 'mode_M',
522 },
523
524 sh => {
525         op_flags => "L|F",
526         state    => "exc_pinned",
527         reg_req  => { in => [ "none", "gp", "gp" ], out => [ "none" ] },
528         emit     => '. sh %S2, %C(%S1)',
529         mode     => 'mode_M',
530 },
531
532 sb => {
533         op_flags => "L|F",
534         state    => "exc_pinned",
535         reg_req  => { in => [ "none", "gp", "gp" ], out => [ "none" ] },
536         emit     => '. sb %S2, %C(%S1)',
537         mode     => 'mode_M',
538 },
539
540 move => {
541         reg_req  => { in => [ "gp" ], out => [ "gp" ] },
542         emit     => '. move %D0, %S0',
543         mode     => "mode_Iu"
544 },
545
546 #
547 # Miscelaneous
548 #
549
550 nop => {
551         op_flags => "K",
552         reg_req  => { in => [], out => [ "none" ] },
553         emit     => '. nop',
554 },
555
556 ); # end of %nodes