- implemented ia32 inport, outport for ir_bk_(in|out)port
[libfirm] / ir / be / ppc32 / bearch_ppc32.c
1 /*
2  * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
6  * This file may be distributed and/or modified under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation and appearing in the file LICENSE.GPL included in the
9  * packaging of this file.
10  *
11  * Licensees holding valid libFirm Professional Edition licenses may use
12  * this file in accordance with the libFirm Commercial License.
13  * Agreement provided with the Software.
14  *
15  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @brief   The main ppc backend driver file.
23  * @author  Moritz Kroll, Jens Mueller
24  * @version $Id$
25  */
26 #include "config.h"
27
28 #include "pseudo_irg.h"
29 #include "irgwalk.h"
30 #include "irprog.h"
31 #include "irprintf.h"
32 #include "ircons.h"
33 #include "irgmod.h"
34 #include "irdump.h"
35
36 #include "bitset.h"
37 #include "debug.h"
38 #include "error.h"
39
40 #include "../bearch_t.h"                /* the general register allocator interface */
41 #include "../benode_t.h"
42 #include "../belower.h"
43 #include "../besched_t.h"
44 #include "be.h"
45 #include "../beabi.h"
46 #include "../bemachine.h"
47 #include "../bemodule.h"
48 #include "../bespillslots.h"
49 #include "../beblocksched.h"
50 #include "../beirg_t.h"
51 #include "../begnuas.h"
52
53 #include "pset.h"
54
55 #include "bearch_ppc32_t.h"
56
57 #include "ppc32_new_nodes.h"           /* ppc nodes interface */
58 #include "gen_ppc32_regalloc_if.h"     /* the generated interface (register type and class defenitions) */
59 #include "ppc32_transform.h"
60 #include "ppc32_transform_conv.h"
61 #include "ppc32_emitter.h"
62 #include "ppc32_map_regs.h"
63
64 #define DEBUG_MODULE "firm.be.ppc.isa"
65
66 int isleaf;
67
68 /* TODO: ugly, but we need it to get access to the registers assigned to Phi nodes */
69 static set *cur_reg_set = NULL;
70
71 /**************************************************
72  *                         _ _              _  __
73  *                        | | |            (_)/ _|
74  *  _ __ ___  __ _    __ _| | | ___   ___   _| |_
75  * | '__/ _ \/ _` |  / _` | | |/ _ \ / __| | |  _|
76  * | | |  __/ (_| | | (_| | | | (_) | (__  | | |
77  * |_|  \___|\__, |  \__,_|_|_|\___/ \___| |_|_|
78  *            __/ |
79  *           |___/
80  **************************************************/
81
82 /**
83  * Return register requirements for a ppc node.
84  * If the node returns a tuple (mode_T) then the proj's
85  * will be asked for this information.
86  */
87 static const arch_register_req_t *ppc32_get_irn_reg_req(const ir_node *irn,
88                                                         int pos)
89 {
90         long               node_pos = pos == -1 ? 0 : pos;
91         ir_mode           *mode     = get_irn_mode(irn);
92         FIRM_DBG_REGISTER(firm_dbg_module_t *mod, DEBUG_MODULE);
93
94         if (is_Block(irn) || mode == mode_X || mode == mode_M) {
95                 DBG((mod, LEVEL_1, "ignoring block, mode_X or mode_M node %+F\n", irn));
96                 return arch_no_register_req;
97         }
98
99         if (mode == mode_T && pos < 0) {
100                 DBG((mod, LEVEL_1, "ignoring request for OUT requirements at %+F", irn));
101                 return arch_no_register_req;
102         }
103
104         DBG((mod, LEVEL_1, "get requirements at pos %d for %+F ... ", pos, irn));
105
106         if (is_Proj(irn)) {
107                 /* in case of a proj, we need to get the correct OUT slot */
108                 /* of the node corresponding to the proj number */
109                 if (pos == -1) {
110                         node_pos = ppc32_translate_proj_pos(irn);
111                 } else {
112                         node_pos = pos;
113                 }
114
115                 irn = skip_Proj_const(irn);
116
117                 DB((mod, LEVEL_1, "skipping Proj, going to %+F at pos %d ... ", irn, node_pos));
118         }
119
120         /* get requirements for our own nodes */
121         if (is_ppc32_irn(irn)) {
122                 const arch_register_req_t *req;
123                 if (pos >= 0) {
124                         req = get_ppc32_in_req(irn, pos);
125                 } else {
126                         req = get_ppc32_out_req(irn, node_pos);
127                 }
128
129                 DB((mod, LEVEL_1, "returning reqs for %+F at pos %d\n", irn, pos));
130                 return req;
131         }
132
133         /* unknowns should be transformed by now */
134         assert(!is_Unknown(irn));
135
136         DB((mod, LEVEL_1, "returning NULL for %+F (node not supported)\n", irn));
137         return arch_no_register_req;
138 }
139
140 static arch_irn_class_t ppc32_classify(const ir_node *irn)
141 {
142         irn = skip_Proj_const(irn);
143
144         if (is_cfop(irn)) {
145                 return arch_irn_class_branch;
146         }
147
148         return 0;
149 }
150
151 static ir_entity *ppc32_get_frame_entity(const ir_node *irn)
152 {
153         if(!is_ppc32_irn(irn)) return NULL;
154         if(get_ppc32_type(irn)!=ppc32_ac_FrameEntity) return NULL;
155         return get_ppc32_frame_entity(irn);
156 }
157
158 static void ppc32_set_frame_entity(ir_node *irn, ir_entity *ent)
159 {
160         if (! is_ppc32_irn(irn) || get_ppc32_type(irn) != ppc32_ac_FrameEntity)
161                 return;
162         set_ppc32_frame_entity(irn, ent);
163 }
164
165 /**
166  * This function is called by the generic backend to correct offsets for
167  * nodes accessing the stack.
168  */
169 static void ppc32_set_stack_bias(ir_node *irn, int bias)
170 {
171         set_ppc32_offset(irn, bias);
172 }
173
174 static int ppc32_get_sp_bias(const ir_node *irn)
175 {
176         (void) irn;
177         return 0;
178 }
179
180 typedef struct
181 {
182         const be_abi_call_t *call;
183         ir_graph *irg;
184 } ppc32_abi_env;
185
186 /**
187  * Initialize the callback object.
188  * @param call The call object.
189  * @param aenv The architecture environment.
190  * @param irg  The graph with the method.
191  * @return     Some pointer. This pointer is passed to all other callback functions as self object.
192  */
193 static void *ppc32_abi_init(const be_abi_call_t *call, const arch_env_t *aenv, ir_graph *irg)
194 {
195         ppc32_abi_env *env = XMALLOC(ppc32_abi_env);
196         (void) aenv;
197
198         env->call = call;
199         env->irg = irg;
200         return env;
201 }
202
203 /**
204  * Destroy the callback object.
205  * @param self The callback object.
206  */
207 static void ppc32_abi_done(void *self)
208 {
209         free(self);
210 }
211
212 /**
213  * Get the between type for that call.
214  * @param self The callback object.
215  * @return The between type of for that call.
216  */
217 static ir_type *ppc32_abi_get_between_type(void *self)
218 {
219         static ir_type *between_type = NULL;
220         static ir_entity *old_bp_ent = NULL;
221         (void) self;
222
223         if(!between_type) {
224                 ir_entity *ret_addr_ent;
225                 ir_type *ret_addr_type = new_type_primitive(new_id_from_str("return_addr"), mode_P);
226                 ir_type *old_bp_type   = new_type_primitive(new_id_from_str("bp"), mode_P);
227
228                 between_type           = new_type_class(new_id_from_str("ppc32_between_type"));
229                 old_bp_ent             = new_entity(between_type, new_id_from_str("old_bp"), old_bp_type);
230                 ret_addr_ent           = new_entity(between_type, new_id_from_str("old_bp"), ret_addr_type);
231
232                 set_entity_offset(old_bp_ent, 0);
233                 set_entity_offset(ret_addr_ent, get_type_size_bytes(old_bp_type));
234                 set_type_size_bytes(between_type, get_type_size_bytes(old_bp_type) + get_type_size_bytes(ret_addr_type));
235         }
236
237         return between_type;
238 }
239
240 /**
241  * Generate the prologue.
242  * @param self       The callback object.
243  * @param mem        A pointer to the mem node. Update this if you define new memory.
244  * @param reg_map    A mapping mapping all callee_save/ignore/parameter registers to their defining nodes.
245  * @param stack_bias Points to the current stack bias, can be modified if needed.
246  *
247  * @return        The register which shall be used as a stack frame base.
248  *
249  * All nodes which define registers in @p reg_map must keep @p reg_map current.
250  */
251 static const arch_register_t *ppc32_abi_prologue(void *self, ir_node **mem, pmap *reg_map, int *stack_bias)
252 {
253         ppc32_abi_env *env = (ppc32_abi_env *) self;
254         be_abi_call_flags_t flags = be_abi_call_get_flags(env->call);
255         (void) mem;
256         (void) reg_map;
257         (void) stack_bias;
258         isleaf = flags.bits.irg_is_leaf;
259
260         if (flags.bits.try_omit_fp)
261                 return &ppc32_gp_regs[REG_R1];
262         else
263                 return &ppc32_gp_regs[REG_R31];
264 }
265
266 /**
267  * Generate the epilogue.
268  * @param self    The callback object.
269  * @param mem     Memory one can attach to.
270  * @param reg_map A mapping mapping all callee_save/ignore/return registers to their defining nodes.
271  *
272  * All nodes which define registers in @p reg_map must keep @p reg_map current.
273  * Also, the @p mem variable must be updated, if memory producing nodes are inserted.
274  */
275 static void ppc32_abi_epilogue(void *self, ir_node *bl, ir_node **mem, pmap *reg_map)
276 {
277         (void) self;
278         (void) bl;
279         (void) mem;
280         (void) reg_map;
281 }
282
283 static const be_abi_callbacks_t ppc32_abi_callbacks = {
284         ppc32_abi_init,
285         ppc32_abi_done,
286         ppc32_abi_get_between_type,
287         ppc32_abi_prologue,
288         ppc32_abi_epilogue,
289 };
290
291 /* fill register allocator interface */
292
293 static const arch_irn_ops_t ppc32_irn_ops = {
294         ppc32_get_irn_reg_req,
295         ppc32_classify,
296         ppc32_get_frame_entity,
297         ppc32_set_frame_entity,
298         ppc32_set_stack_bias,
299         ppc32_get_sp_bias,
300         NULL,    /* get_inverse             */
301         NULL,    /* get_op_estimated_cost   */
302         NULL,    /* possible_memory_operand */
303         NULL,    /* perform_memory_operand  */
304 };
305
306 /**************************************************
307  *                _                         _  __
308  *               | |                       (_)/ _|
309  *   ___ ___   __| | ___  __ _  ___ _ __    _| |_
310  *  / __/ _ \ / _` |/ _ \/ _` |/ _ \ '_ \  | |  _|
311  * | (_| (_) | (_| |  __/ (_| |  __/ | | | | | |
312  *  \___\___/ \__,_|\___|\__, |\___|_| |_| |_|_|
313  *                        __/ |
314  *                       |___/
315  **************************************************/
316
317 static void ppc32_before_abi(void *self) {
318         ppc32_code_gen_t *cg = self;
319         ir_type *frame_type = get_irg_frame_type(cg->irg);
320
321         frame_alloc_area(frame_type, 24, 4, 1);
322
323         ppc32_init_conv_walk();
324         irg_walk_blkwise_graph(cg->irg, NULL, ppc32_conv_walk, cg);
325
326         if (cg->area_size) {
327                 if(cg->area_size < 32) cg->area_size = 32;
328                 cg->area = frame_alloc_area(get_irg_frame_type(cg->irg), cg->area_size+24, 16, 1);
329         }
330 }
331
332 static void ppc32_search_start_successor(ir_node *block, void *env) {
333         ppc32_code_gen_t *cg = env;
334         int n = get_Block_n_cfgpreds(block);
335         ir_node *startblock = get_irg_start_block(cg->irg);
336         if(block == startblock) return;
337
338         for (n--; n >= 0; n--) {
339                 ir_node *predblock = get_irn_n(get_Block_cfgpred(block, n), -1);
340                 if(predblock == startblock)
341                 {
342                         cg->start_succ_block = block;
343                         return;
344                 }
345         }
346 }
347
348 /**
349  * Transforms the standard firm graph into
350  * a ppc firm graph
351  */
352 static void ppc32_prepare_graph(void *self) {
353         ppc32_code_gen_t *cg = self;
354
355         irg_block_walk_graph(cg->irg, NULL, ppc32_search_start_successor, cg);
356         irg_walk_blkwise_graph(cg->irg, NULL, ppc32_pretransform_walk, cg);
357         be_dump(cg->irg, "-pretransformed", dump_ir_block_graph);
358
359         ppc32_register_transformers();
360         irg_walk_blkwise_graph(cg->irg, NULL, ppc32_transform_node, cg);
361         be_dump(cg->irg, "-transformed", dump_ir_block_graph);
362         irg_walk_blkwise_graph(cg->irg, NULL, ppc32_transform_const, cg);
363 }
364
365
366
367 /**
368  * Called immediatly before emit phase.
369  */
370 static void ppc32_finish_irg(void *self) {
371         (void) self;
372         /* TODO: - fix offsets for nodes accessing stack
373                          - ...
374         */
375 }
376
377
378 /**
379  * Called before the register allocator.
380  * Calculate a block schedule here. We need it for the x87
381  * simulator and the emitter.
382  */
383 static void ppc32_before_ra(void *self) {
384         ppc32_code_gen_t *cg = self;
385         cg->blk_sched = be_create_block_schedule(cg->irg, cg->birg->exec_freq);
386 }
387
388 static void ppc32_transform_spill(ir_node *node, void *env)
389 {
390         (void)env;
391
392         if(be_is_Spill(node))
393         {
394                 ir_node  *store, *proj;
395                 dbg_info *dbg   = get_irn_dbg_info(node);
396                 ir_node  *block = get_nodes_block(node);
397
398                 const arch_register_class_t *regclass = arch_get_irn_reg_class(node, 1);
399
400                 if (regclass == &ppc32_reg_classes[CLASS_ppc32_gp])
401                 {
402                         store = new_bd_ppc32_Stw(dbg, block,
403                                 get_irn_n(node, 0), get_irn_n(node, 1), new_NoMem());
404                 }
405                 else if (regclass == &ppc32_reg_classes[CLASS_ppc32_fp])
406                 {
407                         store = new_bd_ppc32_Stfd(dbg, block,
408                                 get_irn_n(node, 0), get_irn_n(node, 1), new_NoMem());
409                 }
410                 else panic("Spill for register class not supported yet!");
411
412                 set_ppc32_frame_entity(store, be_get_frame_entity(node));
413
414                 proj = new_rd_Proj(dbg, current_ir_graph, block, store, mode_M, pn_Store_M);
415
416                 if (sched_is_scheduled(node)) {
417                         sched_add_after(sched_prev(node), store);
418                         sched_add_after(store, proj);
419
420                         sched_remove(node);
421                 }
422
423                 exchange(node, proj);
424         }
425
426         if(be_is_Reload(node))
427         {
428                 ir_node *load, *proj;
429                 const arch_register_t *reg;
430                 dbg_info *dbg   = get_irn_dbg_info(node);
431                 ir_node  *block = get_nodes_block(node);
432                 ir_mode  *mode  = get_irn_mode(node);
433
434                 const arch_register_class_t *regclass = arch_get_irn_reg_class_out(node);
435
436                 if (regclass == &ppc32_reg_classes[CLASS_ppc32_gp])
437                 {
438                         load = new_bd_ppc32_Lwz(dbg, block,     get_irn_n(node, 0), get_irn_n(node, 1));
439                 }
440                 else if (regclass == &ppc32_reg_classes[CLASS_ppc32_fp])
441                 {
442                         load = new_bd_ppc32_Lfd(dbg, block,     get_irn_n(node, 0), get_irn_n(node, 1));
443                 }
444                 else panic("Reload for register class not supported yet!");
445
446                 set_ppc32_frame_entity(load, be_get_frame_entity(node));
447
448                 proj = new_rd_Proj(dbg, current_ir_graph, block, load, mode, pn_Load_res);
449
450                 if (sched_is_scheduled(node)) {
451                         sched_add_after(sched_prev(node), load);
452                         sched_add_after(load, proj);
453
454                         sched_remove(node);
455                 }
456
457                 /* copy the register from the old node to the new Load */
458                 reg = arch_get_irn_register(node);
459                 arch_set_irn_register(load, reg);
460
461                 exchange(node, proj);
462         }
463 }
464
465 /**
466  * Some stuff to do immediately after register allocation
467  */
468 static void ppc32_after_ra(void *self) {
469         ppc32_code_gen_t *cg = self;
470         be_coalesce_spillslots(cg->birg);
471         irg_walk_blkwise_graph(cg->irg, NULL, ppc32_transform_spill, NULL);
472 }
473
474 /**
475  * Emits the code, closes the output file and frees
476  * the code generator interface.
477  */
478 static void ppc32_emit_and_done(void *self) {
479         ppc32_code_gen_t *cg = self;
480         ir_graph         *irg = cg->irg;
481
482         dump_ir_block_graph_sched(irg, "-ppc-finished");
483         ppc32_gen_routine(cg, irg);
484
485         cur_reg_set = NULL;
486
487         /* de-allocate code generator */
488         del_set(cg->reg_set);
489         free(self);
490 }
491
492 int is_direct_entity(ir_entity *ent);
493
494 static void *ppc32_cg_init(be_irg_t *birg);
495
496 static const arch_code_generator_if_t ppc32_code_gen_if = {
497         ppc32_cg_init,
498         NULL,                 /* get_pic_base */
499         ppc32_before_abi,
500         ppc32_prepare_graph,
501         NULL,                 /* spill */
502         ppc32_before_ra,      /* before register allocation hook */
503         ppc32_after_ra,
504         ppc32_finish_irg,
505         ppc32_emit_and_done
506 };
507
508 /**
509  * Initializes the code generator.
510  */
511 static void *ppc32_cg_init(be_irg_t *birg) {
512         ppc32_isa_t      *isa = (ppc32_isa_t *)birg->main_env->arch_env;
513         ppc32_code_gen_t *cg  = XMALLOC(ppc32_code_gen_t);
514
515         cg->impl      = &ppc32_code_gen_if;
516         cg->irg       = birg->irg;
517         cg->reg_set   = new_set(ppc32_cmp_irn_reg_assoc, 1024);
518         cg->isa       = isa;
519         cg->birg      = birg;
520         cg->area_size = 0;
521         cg->area      = NULL;
522         cg->start_succ_block = NULL;
523         cg->blk_sched = NULL;
524         FIRM_DBG_REGISTER(cg->mod, "firm.be.ppc.cg");
525
526         cur_reg_set = cg->reg_set;
527
528         return (arch_code_generator_t *)cg;
529 }
530
531
532
533 /*****************************************************************
534  *  ____             _                  _   _____  _____
535  * |  _ \           | |                | | |_   _|/ ____|  /\
536  * | |_) | __ _  ___| | _____ _ __   __| |   | | | (___   /  \
537  * |  _ < / _` |/ __| |/ / _ \ '_ \ / _` |   | |  \___ \ / /\ \
538  * | |_) | (_| | (__|   <  __/ | | | (_| |  _| |_ ____) / ____ \
539  * |____/ \__,_|\___|_|\_\___|_| |_|\__,_| |_____|_____/_/    \_\
540  *
541  *****************************************************************/
542
543 static ppc32_isa_t ppc32_isa_template = {
544         {
545                 &ppc32_isa_if,           /* isa interface */
546                 &ppc32_gp_regs[REG_R1],  /* stack pointer */
547                 &ppc32_gp_regs[REG_R31], /* base pointer */
548                 -1,                      /* stack is decreasing */
549                 2,                       /* power of two stack alignment for calls, 2^2 == 4 */
550                 NULL,                    /* main environment */
551                 7,                       /* spill costs */
552                 5,                       /* reload costs */
553         },
554         NULL                    /* symbol set */
555 };
556
557 /**
558  * Collects all SymConsts which need to be accessed "indirectly"
559  *
560  * @param node    the firm node
561  * @param env     the symbol set
562  */
563 static void ppc32_collect_symconsts_walk(ir_node *node, void *env) {
564         pset *symbol_set = env;
565
566         if (is_SymConst(node)) {
567                 ir_entity *ent = get_SymConst_entity(node);
568                 set_entity_backend_marked(ent, 1);
569                 if (! is_direct_entity(ent))
570                         pset_insert_ptr(symbol_set, ent);
571         }
572 }
573
574 /**
575  * Initializes the backend ISA and opens the output file.
576  */
577 static arch_env_t *ppc32_init(FILE *file_handle) {
578         static int inited = 0;
579         ppc32_isa_t *isa;
580         int i;
581
582         if (inited)
583                 return NULL;
584
585         isa = XMALLOC(ppc32_isa_t);
586         memcpy(isa, &ppc32_isa_template, sizeof(*isa));
587
588         be_emit_init(file_handle);
589
590         ppc32_register_init();
591         ppc32_create_opcodes(&ppc32_irn_ops);
592
593         inited = 1;
594
595         isa->symbol_set = pset_new_ptr(8);
596         for (i = 0; i < get_irp_n_irgs(); ++i) {
597                 ir_graph *irg = get_irp_irg(i);
598                 irg_walk_blkwise_graph(irg, NULL, ppc32_collect_symconsts_walk, isa->symbol_set);
599         }
600
601         /* we mark referenced global entities, so we can only emit those which
602          * are actually referenced. (Note: you mustn't use the type visited flag
603          * elsewhere in the backend)
604          */
605         inc_master_type_visited();
606
607         return &isa->arch_env;
608 }
609
610 static void ppc32_dump_indirect_symbols(ppc32_isa_t *isa) {
611         ir_entity *ent;
612
613         foreach_pset(isa->symbol_set, ent) {
614                 const char *ld_name = get_entity_ld_name(ent);
615                 be_emit_irprintf(".non_lazy_symbol_pointer\n%s:\n\t.indirect_symbol _%s\n\t.long 0\n\n", ld_name, ld_name);
616                 be_emit_write_line();
617         }
618 }
619
620 /**
621  * Closes the output file and frees the ISA structure.
622  */
623 static void ppc32_done(void *self) {
624         ppc32_isa_t *isa = self;
625
626         be_gas_emit_decls(isa->arch_env.main_env, 1);
627         be_gas_emit_switch_section(GAS_SECTION_DATA);
628         ppc32_dump_indirect_symbols(isa);
629
630         be_emit_exit();
631         del_pset(isa->symbol_set);
632
633         free(self);
634 }
635
636
637
638 static unsigned ppc32_get_n_reg_class(const void *self) {
639         (void) self;
640         return N_CLASSES;
641 }
642
643 static const arch_register_class_t *ppc32_get_reg_class(const void *self,
644                                                         unsigned i) {
645         (void) self;
646         assert(i < N_CLASSES && "Invalid ppc register class requested.");
647         return &ppc32_reg_classes[i];
648 }
649
650
651
652 /**
653  * Get the register class which shall be used to store a value of a given mode.
654  * @param self The this pointer.
655  * @param mode The mode in question.
656  * @return A register class which can hold values of the given mode.
657  */
658 const arch_register_class_t *ppc32_get_reg_class_for_mode(const void *self, const ir_mode *mode) {
659         (void) self;
660         if (mode_is_float(mode))
661                 return &ppc32_reg_classes[CLASS_ppc32_fp];
662         else
663                 return &ppc32_reg_classes[CLASS_ppc32_gp];
664 }
665
666
667 /**
668  * Get the ABI restrictions for procedure calls.
669  * @param self        The this pointer.
670  * @param method_type The type of the method (procedure) in question.
671  * @param abi         The abi object to be modified
672  */
673 static void ppc32_get_call_abi(const void *self, ir_type *method_type, be_abi_call_t *abi) {
674         ir_type  *tp;
675         ir_mode  *mode;
676         int       i, n = get_method_n_params(method_type);
677         int               stackoffs = 0, lastoffs = 0, stackparamsize;
678
679         int               gpregi = REG_R3;
680         int               fpregi = REG_F1;
681
682         const arch_register_t *reg;
683         be_abi_call_flags_t call_flags = { { 0, 0, 1, 0, 0, 0, 1 } };
684
685         (void) self;
686         if(get_type_visibility(method_type)!=visibility_external_allocated)
687                 call_flags.bits.call_has_imm = 1;
688
689         /* set stack parameter passing style */
690         be_abi_call_set_flags(abi, call_flags, &ppc32_abi_callbacks);
691
692         for (i = 0; i < n; i++) {
693                 tp   = get_method_param_type(method_type, i);
694                 mode = get_type_mode(tp);
695                 if(is_atomic_type(tp))
696                 {
697                         if(mode_is_float(mode))
698                         {
699                                 if(fpregi <= REG_F13)
700                                 {
701                                         if(get_mode_size_bits(mode) == 32) gpregi++, stackparamsize=4;
702                                         else gpregi += 2, stackparamsize=8;                                                             // mode == irm_D
703                                         reg = &ppc32_fp_regs[fpregi++];
704                                 }
705                                 else
706                                 {
707                                         if(get_mode_size_bits(mode) == 32) stackparamsize=4;
708                                         else stackparamsize=8;                                                          // mode == irm_D
709                                         reg = NULL;
710                                 }
711                         }
712                         else
713                         {
714                                 if(gpregi <= REG_R10)
715                                         reg = &ppc32_gp_regs[gpregi++];
716                                 else
717                                         reg = NULL;
718                                 stackparamsize=4;
719                         }
720
721                         if(reg)
722                                 be_abi_call_param_reg(abi, i, reg);
723                         else
724                         {
725                                 be_abi_call_param_stack(abi, i, mode, 4, stackoffs - lastoffs, 0);
726                                 lastoffs = stackoffs+stackparamsize;
727                         }
728                         stackoffs += stackparamsize;
729                 }
730                 else
731                 {
732                         be_abi_call_param_stack(abi, i, mode, 4, stackoffs - lastoffs, 0);
733                         stackoffs += (get_type_size_bytes(tp)+3) & -4;
734                         lastoffs = stackoffs;
735                 }
736         }
737
738         /* explain where result can be found if any */
739         if (get_method_n_ress(method_type) > 0) {
740                 tp   = get_method_res_type(method_type, 0);
741                 mode = get_type_mode(tp);
742
743                 be_abi_call_res_reg(abi, 0,
744                         mode_is_float(mode) ? &ppc32_fp_regs[REG_F1] : &ppc32_gp_regs[REG_R3]);
745         }
746 }
747
748 int ppc32_to_appear_in_schedule(void *block_env, const ir_node *irn) {
749         (void) block_env;
750         if(!is_ppc32_irn(irn))
751                 return -1;
752
753         return 1;
754 }
755
756 /**
757  * Initializes the code generator interface.
758  */
759 static const arch_code_generator_if_t *ppc32_get_code_generator_if(void *self) {
760         (void) self;
761         return &ppc32_code_gen_if;
762 }
763
764 list_sched_selector_t ppc32_sched_selector;
765
766 /**
767  * Returns the reg_pressure scheduler with to_appear_in_schedule() overloaded
768  */
769 static const list_sched_selector_t *ppc32_get_list_sched_selector(const void *self, list_sched_selector_t *selector) {
770         (void) self;
771         (void) selector;
772         ppc32_sched_selector = trivial_selector;
773         ppc32_sched_selector.to_appear_in_schedule = ppc32_to_appear_in_schedule;
774         return &ppc32_sched_selector;
775 }
776
777 static const ilp_sched_selector_t *ppc32_get_ilp_sched_selector(const void *self) {
778         (void) self;
779         return NULL;
780 }
781
782 /**
783  * Returns the necessary byte alignment for storing a register of given class.
784  */
785 static int ppc32_get_reg_class_alignment(const void *self, const arch_register_class_t *cls) {
786         ir_mode *mode = arch_register_class_mode(cls);
787         (void) self;
788
789         return get_mode_size_bytes(mode);
790 }
791
792 static const be_execution_unit_t ***ppc32_get_allowed_execution_units(const void *self, const ir_node *irn) {
793         (void) self;
794         (void) irn;
795         /* TODO */
796         panic("Unimplemented ppc32_get_allowed_execution_units()");
797         return NULL;
798 }
799
800 static const be_machine_t *ppc32_get_machine(const void *self) {
801         (void) self;
802         /* TODO */
803         panic("Unimplemented ppc32_get_machine()");
804         return NULL;
805 }
806
807 /**
808  * Return irp irgs in the desired order.
809  */
810 static ir_graph **ppc32_get_irg_list(const void *self, ir_graph ***irg_list) {
811         (void) self;
812         (void) irg_list;
813         return NULL;
814 }
815
816 /**
817  * Returns the libFirm configuration parameter for this backend.
818  */
819 static const backend_params *ppc32_get_libfirm_params(void) {
820         static backend_params p = {
821                 1,     /* need dword lowering */
822                 0,     /* don't support inline assembler yet */
823                 NULL,  /* will be set later */
824                 NULL,  /* but yet no creator function */
825                 NULL,  /* context for create_intrinsic_fkt */
826                 NULL,  /* no if conversion settings */
827                 NULL,  /* no float arithmetic mode (TODO) */
828                 0,     /* no trampoline support: size 0 */
829                 0,     /* no trampoline support: align 0 */
830                 NULL   /* no trampoline support: no trampoline builder */
831         };
832
833         return &p;
834 }
835
836 static asm_constraint_flags_t ppc32_parse_asm_constraint(const void *self, const char **c)
837 {
838         /* no asm support yet */
839         (void) self;
840         (void) c;
841         return ASM_CONSTRAINT_FLAG_INVALID;
842 }
843
844 static int ppc32_is_valid_clobber(const void *self, const char *clobber)
845 {
846         /* no asm support yet */
847         (void) self;
848         (void) clobber;
849         return 0;
850 }
851
852 const arch_isa_if_t ppc32_isa_if = {
853         ppc32_init,
854         ppc32_done,
855         NULL,             /* handle intrinsics */
856         ppc32_get_n_reg_class,
857         ppc32_get_reg_class,
858         ppc32_get_reg_class_for_mode,
859         ppc32_get_call_abi,
860         ppc32_get_code_generator_if,
861         ppc32_get_list_sched_selector,
862         ppc32_get_ilp_sched_selector,
863         ppc32_get_reg_class_alignment,
864         ppc32_get_libfirm_params,
865         ppc32_get_allowed_execution_units,
866         ppc32_get_machine,
867         ppc32_get_irg_list,
868         NULL,                 /* mark remat */
869         ppc32_parse_asm_constraint,
870         ppc32_is_valid_clobber
871 };
872
873 void be_init_arch_ppc32(void)
874 {
875         be_register_isa_if("ppc32", &ppc32_isa_if);
876 }
877
878 BE_REGISTER_MODULE_CONSTRUCTOR(be_init_arch_ppc32);