added call emit
[libfirm] / ir / be / ia32 / bearch_ia32.c
1 #ifdef HAVE_CONFIG_H
2 #include "config.h"
3 #endif
4
5 #ifdef _WIN32
6 #include <malloc.h>
7 #else
8 #include <alloca.h>
9 #endif
10
11 #include "pseudo_irg.h"
12 #include "irgwalk.h"
13 #include "irprog.h"
14 #include "irprintf.h"
15 #include "iredges_t.h"
16 #include "ircons.h"
17 #include "irgmod.h"
18
19 #include "bitset.h"
20 #include "debug.h"
21
22 #include "../bearch.h"                /* the general register allocator interface */
23 #include "../benode_t.h"
24 #include "../belower.h"
25 #include "../besched_t.h"
26 #include "bearch_ia32_t.h"
27
28 #include "ia32_new_nodes.h"           /* ia32 nodes interface */
29 #include "gen_ia32_regalloc_if.h"     /* the generated interface (register type and class defenitions) */
30 #include "ia32_gen_decls.h"           /* interface declaration emitter */
31 #include "ia32_transform.h"
32 #include "ia32_emitter.h"
33 #include "ia32_map_regs.h"
34 #include "ia32_optimize.h"
35
36 #define DEBUG_MODULE "firm.be.ia32.isa"
37
38 /* TODO: ugly */
39 static set *cur_reg_set = NULL;
40
41 #undef is_Start
42 #define is_Start(irn) (get_irn_opcode(irn) == iro_Start)
43
44 /**************************************************
45  *                         _ _              _  __
46  *                        | | |            (_)/ _|
47  *  _ __ ___  __ _    __ _| | | ___   ___   _| |_
48  * | '__/ _ \/ _` |  / _` | | |/ _ \ / __| | |  _|
49  * | | |  __/ (_| | | (_| | | | (_) | (__  | | |
50  * |_|  \___|\__, |  \__,_|_|_|\___/ \___| |_|_|
51  *            __/ |
52  *           |___/
53  **************************************************/
54
55 static ir_node *my_skip_proj(const ir_node *n) {
56         while (is_Proj(n))
57                 n = get_Proj_pred(n);
58         return (ir_node *)n;
59 }
60
61 static int is_Call_Proj(const ir_node *n) {
62         if (is_Proj(n)                               &&
63                 is_Proj(get_Proj_pred(n))                &&
64                 get_irn_mode(get_Proj_pred(n)) == mode_T &&
65                 is_ia32_Call(get_Proj_pred(get_Proj_pred(n))))
66         {
67                 return 1;
68         }
69
70         return 0;
71 }
72
73 static int is_Start_Proj(const ir_node *n) {
74         if (is_Proj(n)                               &&
75                 is_Proj(get_Proj_pred(n))                &&
76                 get_irn_mode(get_Proj_pred(n)) == mode_T &&
77                 is_Start(get_Proj_pred(get_Proj_pred(n))))
78         {
79                 return 1;
80         }
81
82         return 0;
83 }
84
85 static int is_P_frame_base_Proj(const ir_node *n) {
86         if (is_Proj(n)                                    &&
87                 is_Start(get_Proj_pred(n)) &&
88                 get_Proj_proj(n) == pn_Start_P_frame_base)
89         {
90                 return 1;
91         }
92
93         return 0;
94 }
95
96 static int is_used_by_Keep(const ir_node *n) {
97         return be_is_Keep(get_edge_src_irn(get_irn_out_edge_first(n)));
98 }
99
100 /**
101  * Return register requirements for an ia32 node.
102  * If the node returns a tuple (mode_T) then the proj's
103  * will be asked for this information.
104  */
105 static const arch_register_req_t *ia32_get_irn_reg_req(const void *self, arch_register_req_t *req, const ir_node *irn, int pos) {
106         const ia32_register_req_t *irn_req;
107         long                       node_pos = pos == -1 ? 0 : pos;
108         ir_mode                   *mode     = get_irn_mode(irn);
109         firm_dbg_module_t         *mod      = firm_dbg_register(DEBUG_MODULE);
110         const ia32_irn_ops_t      *ops      = self;
111
112         if (mode == mode_T || mode == mode_M) {
113                 DBG((mod, LEVEL_1, "ignoring mode_T, mode_M node %+F\n", irn));
114                 return NULL;
115         }
116
117         DBG((mod, LEVEL_1, "get requirements at pos %d for %+F ... ", pos, irn));
118
119
120         if (is_Call_Proj(irn) && is_used_by_Keep(irn)) {
121                 if (pos >= 0) {
122                         req = NULL;
123                 }
124                 else {
125                         irn_req = ia32_projnum_reg_req_map[get_Proj_proj(irn)];
126                         memcpy(req, &(irn_req->req), sizeof(*req));
127                 }
128
129                 return req;
130         }
131         else if (is_Start_Proj(irn)) {
132                 irn_req = ops->cg->reg_param_req[get_Proj_proj(irn)];
133                 assert(irn_req && "missing requirement for regparam");
134                 memcpy(req, &(irn_req->req), sizeof(*req));
135                 return req;
136         }
137         else if (is_Proj(irn)) {
138                 if (pos == -1) {
139                         node_pos = ia32_translate_proj_pos(irn);
140                 }
141                 else {
142                         node_pos = pos;
143                 }
144
145                 irn = my_skip_proj(irn);
146
147                 DB((mod, LEVEL_1, "skipping Proj, going to %+F at pos %d ... ", irn, node_pos));
148         }
149
150         if (is_ia32_irn(irn)) {
151                 if (pos >= 0) {
152                         irn_req = get_ia32_in_req(irn, pos);
153                 }
154                 else {
155                         irn_req = get_ia32_out_req(irn, node_pos);
156                 }
157
158                 DB((mod, LEVEL_1, "returning reqs for %+F at pos %d\n", irn, pos));
159
160                 memcpy(req, &(irn_req->req), sizeof(*req));
161
162                 if (arch_register_req_is(&(irn_req->req), should_be_same) ||
163                         arch_register_req_is(&(irn_req->req), should_be_different)) {
164                         assert(irn_req->pos >= 0 && "should be same/different constraint for in -> out NYI");
165                         req->other = get_irn_n(irn, irn_req->pos);
166                 }
167         }
168         else {
169                 /* treat Phi like Const with default requirements */
170                 if (is_Phi(irn)) {
171                         DB((mod, LEVEL_1, "returning standard reqs for %+F\n", irn));
172                         if (mode_is_float(mode))
173                                 memcpy(req, &(ia32_default_req_ia32_floating_point.req), sizeof(*req));
174                         else if (mode_is_int(mode) || mode_is_reference(mode))
175                                 memcpy(req, &(ia32_default_req_ia32_general_purpose.req), sizeof(*req));
176                         else if (mode == mode_T || mode == mode_M) {
177                                 DBG((mod, LEVEL_1, "ignoring Phi node %+F\n", irn));
178                                 return NULL;
179                         }
180                         else
181                                 assert(0 && "unsupported Phi-Mode");
182                 }
183                 else if (is_Start(irn)) {
184                         DB((mod, LEVEL_1, "returning reqs none for ProjX -> Start (%+F )\n", irn));
185                         switch (node_pos) {
186                                 case pn_Start_X_initial_exec:
187                                 case pn_Start_P_value_arg_base:
188                                 case pn_Start_P_globals:
189                                 case pn_Start_P_frame_base:
190                                         memcpy(req, &(ia32_default_req_none.req), sizeof(*req));
191                                         break;
192                                 case pn_Start_T_args:
193                                         assert(0 && "ProjT(pn_Start_T_args) should not be asked");
194                         }
195                 }
196                 else if (get_irn_op(irn) == op_Return && pos > 0) {
197                         DB((mod, LEVEL_1, "returning reqs EAX for %+F\n", irn));
198                         memcpy(req, &(ia32_default_req_ia32_general_purpose_eax.req), sizeof(*req));
199                 }
200                 else {
201                         DB((mod, LEVEL_1, "returning NULL for %+F (not ia32)\n", irn));
202                         req = NULL;
203                 }
204         }
205
206         return req;
207 }
208
209 static void ia32_set_irn_reg(const void *self, ir_node *irn, const arch_register_t *reg) {
210         int pos = 0;
211
212         if ((is_Call_Proj(irn) && is_used_by_Keep(irn)) ||
213                 is_P_frame_base_Proj(irn)                   ||
214                 is_Start_Proj(irn))
215         {
216                 /* don't skip the proj, we want to take the else below */
217         }
218         else if (is_Proj(irn)) {
219                 pos = ia32_translate_proj_pos(irn);
220                 irn = my_skip_proj(irn);
221         }
222
223         if (is_ia32_irn(irn)) {
224                 const arch_register_t **slots;
225
226                 slots      = get_ia32_slots(irn);
227                 slots[pos] = reg;
228         }
229         else {
230                 ia32_set_firm_reg(irn, reg, cur_reg_set);
231         }
232 }
233
234 static const arch_register_t *ia32_get_irn_reg(const void *self, const ir_node *irn) {
235         int pos = 0;
236         const arch_register_t *reg = NULL;
237
238         if ((is_Call_Proj(irn) && is_used_by_Keep(irn)) ||
239                 is_P_frame_base_Proj(irn)                   ||
240                 is_Start_Proj(irn))
241         {
242                 /* don't skip the proj, we want to take the else below */
243         }
244         else if (is_Proj(irn)) {
245                 pos = ia32_translate_proj_pos(irn);
246                 irn = my_skip_proj(irn);
247         }
248
249         if (is_ia32_irn(irn)) {
250                 const arch_register_t **slots;
251                 slots = get_ia32_slots(irn);
252                 reg   = slots[pos];
253         }
254         else {
255                 reg = ia32_get_firm_reg(irn, cur_reg_set);
256         }
257
258         return reg;
259 }
260
261 static arch_irn_class_t ia32_classify(const void *self, const ir_node *irn) {
262         irn = my_skip_proj(irn);
263         if (is_cfop(irn))
264                 return arch_irn_class_branch;
265         else if (is_ia32_Call(irn))
266                 return arch_irn_class_call;
267         else if (is_ia32_irn(irn))
268                 return arch_irn_class_normal;
269         else
270                 return 0;
271 }
272
273 static arch_irn_flags_t ia32_get_flags(const void *self, const ir_node *irn) {
274         irn = my_skip_proj(irn);
275         if (is_ia32_irn(irn))
276                 return get_ia32_flags(irn);
277         else {
278                 if (is_Start_Proj(irn))
279                         return arch_irn_flags_ignore;
280
281                 return 0;
282         }
283 }
284
285 /* fill register allocator interface */
286
287 static const arch_irn_ops_if_t ia32_irn_ops_if = {
288         ia32_get_irn_reg_req,
289         ia32_set_irn_reg,
290         ia32_get_irn_reg,
291         ia32_classify,
292         ia32_get_flags
293 };
294
295 ia32_irn_ops_t ia32_irn_ops = {
296         &ia32_irn_ops_if,
297         NULL
298 };
299
300
301
302 /**************************************************
303  *                _                         _  __
304  *               | |                       (_)/ _|
305  *   ___ ___   __| | ___  __ _  ___ _ __    _| |_
306  *  / __/ _ \ / _` |/ _ \/ _` |/ _ \ '_ \  | |  _|
307  * | (_| (_) | (_| |  __/ (_| |  __/ | | | | | |
308  *  \___\___/ \__,_|\___|\__, |\___|_| |_| |_|_|
309  *                        __/ |
310  *                       |___/
311  **************************************************/
312
313 static void check_for_alloca(ir_node *irn, void *env) {
314         int *has_alloca = env;
315
316         if (get_irn_opcode(irn) == iro_Alloc) {
317                 if (get_Alloc_where(irn) == stack_alloc) {
318                         *has_alloca = 1;
319                 }
320         }
321 }
322
323 /**
324  * Transforms the standard firm graph into
325  * an ia32 firm graph
326  */
327 static void ia32_prepare_graph(void *self) {
328         ia32_code_gen_t *cg = self;
329
330         if (! is_pseudo_ir_graph(cg->irg)) {
331                 /* If there is a alloca in the irg, we use %ebp for stack addressing */
332                 /* instead of %esp, as alloca destroys %esp.                         */
333
334                 cg->has_alloca = 0;
335
336                 /* check for alloca node */
337                 irg_walk_blkwise_graph(cg->irg, check_for_alloca, NULL, &(cg->has_alloca));
338
339                 if (cg->has_alloca) {
340                         ia32_general_purpose_regs[REG_EBP].type = arch_register_type_ignore;
341                 }
342
343                 irg_walk_blkwise_graph(cg->irg, ia32_place_consts, ia32_transform_node, cg);
344         }
345 }
346
347
348
349 /**
350  * Stack reservation and StackParam lowering.
351  */
352 static void ia32_finish_irg(ir_graph *irg, ia32_code_gen_t *cg) {
353         firm_dbg_module_t *mod       = cg->mod;
354         ir_node           *frame     = get_irg_frame(irg);
355         ir_node           *end_block = get_irg_end_block(irg);
356         ir_node          **returns, **in, **new_in;
357         ir_node           *stack_reserve, *sched_point;
358         ir_node           *stack_free, *new_ret, *return_block;
359         int                stack_size = 0, i, n_res;
360         arch_register_t   *stack_reg;
361         tarval            *stack_size_tv;
362         dbg_info          *frame_dbg;
363
364         /* Determine stack register */
365         if (cg->has_alloca) {
366                 stack_reg = &ia32_general_purpose_regs[REG_EBP];
367         }
368         else {
369                 stack_reg = &ia32_general_purpose_regs[REG_ESP];
370         }
371
372         /* If frame is used, then we need to reserve some stackspace. */
373         if (get_irn_n_edges(frame) > 0) {
374                 /* The initial stack reservation. */
375                 frame_dbg     = get_irn_dbg_info(frame);
376                 stack_reserve = new_rd_ia32_Sub_i(frame_dbg, irg, get_nodes_block(frame), frame, mode_Is);
377                 stack_size_tv = new_tarval_from_long(stack_size, mode_Is);
378                 set_ia32_am_const(stack_reserve, stack_size_tv);
379                 edges_reroute(frame, stack_reserve, irg);
380
381                 /* set register */
382                 arch_set_irn_register(cg->arch_env, frame, stack_reg);
383                 arch_set_irn_register(cg->arch_env, stack_reserve, stack_reg);
384
385                 /* insert into schedule */
386                 sched_add_after(get_irg_start(irg), frame);
387                 sched_add_after(frame, stack_reserve);
388
389                 /* Free stack for each Return node */
390                 returns = get_Block_cfgpred_arr(end_block);
391                 for (i = 0; i < get_Block_n_cfgpreds(end_block); i++) {
392                         assert(get_irn_opcode(returns[i]) == iro_Return && "cfgpred of endblock is not a return");
393
394                         return_block = get_nodes_block(returns[i]);
395
396                         /* free the stack */
397                         stack_free = new_rd_ia32_Add_i(frame_dbg, irg, return_block, stack_reserve, mode_Is);
398                         set_ia32_am_const(stack_free, stack_size_tv);
399                         arch_set_irn_register(cg->arch_env, stack_free, stack_reg);
400
401                         DBG((mod, LEVEL_1, "examining %+F, %+F created, block %+F", returns[i], stack_free, return_block));
402
403                         /* get the old Return arguments */
404                         n_res  = get_Return_n_ress(returns[i]);
405                         in     = get_Return_res_arr(returns[i]);
406                         new_in = malloc((n_res + 1) * sizeof(new_in[0]));
407
408                         if (!new_in) {
409                                 printf("\nMUAAAAHAHAHAHAHAHAHAH\n");
410                                 exit(1);
411                         }
412
413                         /* copy the old to the new in's */
414                         memcpy(new_in, in, n_res * sizeof(in[0]));
415                         in[n_res] = stack_free;
416
417                         /* create the new return node */
418 //                      edges_deactivate(irg);
419                         new_ret     = new_rd_ia32_Return(get_irn_dbg_info(returns[i]), irg, return_block, n_res + 1, new_in);
420 //                      edges_activate(irg);
421                         sched_point = sched_prev(returns[i]);
422
423                         /* exchange the old return with the new one */
424                         exchange(returns[i], new_ret);
425
426                         DB((mod, LEVEL_1, " ... replaced with %+F\n", new_ret));
427
428                         /* remove the old one from schedule and add the new nodes properly */
429                         sched_remove(returns[i]);
430                         sched_add_after(sched_point, new_ret);
431                         sched_add_before(new_ret, stack_free);
432                 }
433         }
434 }
435
436
437
438 /**
439  * Dummy functions for hooks we don't need but which must be filled.
440  */
441 static void ia32_before_sched(void *self) {
442         ia32_code_gen_t *cg = self;
443
444         lower_nodes_before_sched(cg->irg, cg->arch_env);
445 }
446
447 static void ia32_before_ra(void *self) {
448 }
449
450
451 /**
452  * Creates a Store for a Spill
453  */
454 static ir_node *ia32_lower_spill(void *self, ir_node *spill) {
455         ia32_code_gen_t *cg    = self;
456         dbg_info        *dbg   = get_irn_dbg_info(spill);
457         ir_node         *block = get_nodes_block(spill);
458         ir_node         *ptr   = get_irg_frame(cg->irg);
459         ir_node         *val   = be_get_Spill_context(spill);
460         ir_node         *mem   = new_rd_NoMem(cg->irg);
461         ir_mode         *mode  = get_irn_mode(spill);
462         ir_node         *res;
463         entity          *ent   = be_get_spill_entity(spill);
464         unsigned         offs  = get_entity_offset_bytes(ent);
465
466         DB((cg->mod, LEVEL_1, "lower_spill: got offset %d for %+F\n", offs, ent));
467
468         res = new_rd_ia32_Store(dbg, cg->irg, block, ptr, val, mem, mode);
469         set_ia32_am_offs(res, new_tarval_from_long(offs, mode_Iu));
470
471         return res;
472 }
473
474 /**
475  * Create a Load for a Spill
476  */
477 static ir_node *ia32_lower_reload(void *self, ir_node *reload) {
478         ia32_code_gen_t *cg    = self;
479         dbg_info        *dbg   = get_irn_dbg_info(reload);
480         ir_node         *block = get_nodes_block(reload);
481         ir_node         *ptr   = get_irg_frame(cg->irg);
482         ir_mode         *mode  = get_irn_mode(reload);
483         ir_node         *pred  = get_irn_n(reload, 0);
484         tarval          *tv;
485         ir_node         *res;
486
487         if (be_is_Spill(pred)) {
488                 entity   *ent  = be_get_spill_entity(pred);
489                 unsigned  offs = get_entity_offset_bytes(ent);
490                 DB((cg->mod, LEVEL_1, "lower_reload: got offset %d for %+F\n", offs, ent));
491                 tv = new_tarval_from_long(offs, mode_Iu);
492         }
493         else if (is_ia32_Store(pred)) {
494                 tv = get_ia32_am_offs(pred);
495         }
496         else {
497                 assert(0 && "unsupported Reload predecessor");
498         }
499
500         res = new_rd_ia32_Load(dbg, cg->irg, block, ptr, pred, mode);
501         set_ia32_am_offs(res, tv);
502
503         return res;
504 }
505
506 /**
507  * Return the stack register for this irg.
508  */
509 static const arch_register_t *ia32_get_stack_register(void *self) {
510         ia32_code_gen_t *cg = self;
511
512         if (cg->has_alloca) {
513                 return &ia32_general_purpose_regs[REG_EBP];
514         }
515
516         return &ia32_general_purpose_regs[REG_ESP];
517 }
518
519 /**
520  * Emits the code, closes the output file and frees
521  * the code generator interface.
522  */
523 static void ia32_codegen(void *self) {
524         ia32_code_gen_t *cg = self;
525         ir_graph       *irg = cg->irg;
526         FILE           *out = cg->out;
527
528         if (cg->emit_decls) {
529                 ia32_gen_decls(cg->out);
530                 cg->emit_decls = 0;
531         }
532
533         ia32_finish_irg(irg, cg);
534         dump_ir_block_graph_sched(irg, "-finished");
535         ia32_gen_routine(out, irg, cg);
536
537         cur_reg_set = NULL;
538
539         /* de-allocate code generator */
540         del_set(cg->reg_set);
541         free(self);
542 }
543
544 static void *ia32_cg_init(FILE *F, ir_graph *irg, const arch_env_t *arch_env);
545
546 static const arch_code_generator_if_t ia32_code_gen_if = {
547         ia32_cg_init,
548         ia32_prepare_graph,
549         ia32_before_sched,   /* before scheduling hook */
550         ia32_before_ra,      /* before register allocation hook */
551         ia32_lower_spill,
552         ia32_lower_reload,
553         ia32_get_stack_register,
554         ia32_codegen         /* emit && done */
555 };
556
557 /**
558  * Initializes the code generator.
559  */
560 static void *ia32_cg_init(FILE *F, ir_graph *irg, const arch_env_t *arch_env) {
561         ia32_isa_t      *isa = (ia32_isa_t *)arch_env->isa;
562         ia32_code_gen_t *cg  = malloc(sizeof(*cg));
563
564         cg->impl       = &ia32_code_gen_if;
565         cg->irg        = irg;
566         cg->reg_set    = new_set(ia32_cmp_irn_reg_assoc, 1024);
567         cg->mod        = firm_dbg_register("firm.be.ia32.cg");
568         cg->out        = F;
569         cg->arch_env   = arch_env;
570
571         isa->num_codegens++;
572
573         if (isa->num_codegens > 1)
574                 cg->emit_decls = 0;
575         else
576                 cg->emit_decls = 1;
577
578         cur_reg_set = cg->reg_set;
579
580         ia32_irn_ops.cg = cg;
581
582         return (arch_code_generator_t *)cg;
583 }
584
585
586
587 /*****************************************************************
588  *  ____             _                  _   _____  _____
589  * |  _ \           | |                | | |_   _|/ ____|  /\
590  * | |_) | __ _  ___| | _____ _ __   __| |   | | | (___   /  \
591  * |  _ < / _` |/ __| |/ / _ \ '_ \ / _` |   | |  \___ \ / /\ \
592  * | |_) | (_| | (__|   <  __/ | | | (_| |  _| |_ ____) / ____ \
593  * |____/ \__,_|\___|_|\_\___|_| |_|\__,_| |_____|_____/_/    \_\
594  *
595  *****************************************************************/
596
597 /**
598  * Initializes the backend ISA and opens the output file.
599  */
600 static void *ia32_init(void) {
601         static int inited = 0;
602         ia32_isa_t *isa   = malloc(sizeof(*isa));
603
604         isa->impl = &ia32_isa_if;
605
606         if(inited)
607                 return NULL;
608
609         inited = 1;
610
611         isa->num_codegens    = 0;
612         isa->reg_projnum_map = new_set(ia32_cmp_reg_projnum_assoc, 1024);
613
614         ia32_register_init(isa);
615         ia32_create_opcodes();
616
617         return isa;
618 }
619
620
621
622 /**
623  * Closes the output file and frees the ISA structure.
624  */
625 static void ia32_done(void *self) {
626         free(self);
627 }
628
629
630
631 static int ia32_get_n_reg_class(const void *self) {
632         return N_CLASSES;
633 }
634
635 static const arch_register_class_t *ia32_get_reg_class(const void *self, int i) {
636         assert(i >= 0 && i < N_CLASSES && "Invalid ia32 register class requested.");
637         return &ia32_reg_classes[i];
638 }
639
640 static const void *ia32_get_irn_ops(const arch_irn_handler_t *self, const ir_node *irn) {
641         return &ia32_irn_ops;
642 }
643
644 const arch_irn_handler_t ia32_irn_handler = {
645         ia32_get_irn_ops
646 };
647
648 const arch_irn_handler_t *ia32_get_irn_handler(const void *self) {
649         return &ia32_irn_handler;
650 }
651
652 long ia32_handle_call_proj(const void *self, ir_node *proj, int is_keep) {
653         ia32_isa_t *isa = (ia32_isa_t *)self;
654         long        pn  = get_Proj_proj(proj);
655
656         if (!is_keep) {
657                 /* It's not a Keep proj, which means, that it is a result proj. */
658                 /* Possible result proj numbers are 0 and 1                     */
659                 /* Set the correct register (depends on the mode) and the       */
660                 /* corresponding proj number                                    */
661                 if (mode_is_float(get_irn_mode(proj))) {
662                         assert(pn == 0 && "only one floating point result supported");
663
664                         /* Get the proj number for the floating point result */
665                         pn = ia32_get_reg_projnum(&ia32_floating_point_regs[REG_XMM0], isa->reg_projnum_map);
666                 }
667                 else {
668                         /* In case of 64bit return value, the result is */
669                         /* in EDX:EAX and we have two result projs.     */
670                         switch (pn) {
671                                 case 0:
672                                         pn = ia32_get_reg_projnum(&ia32_floating_point_regs[REG_EAX], isa->reg_projnum_map);
673                                         break;
674                                 case 1:
675                                         pn = ia32_get_reg_projnum(&ia32_floating_point_regs[REG_EDX], isa->reg_projnum_map);
676                                         break;
677                                 default:
678                                         assert(0 && "only two int results supported");
679                         }
680                 }
681
682                 /* Set the correct proj number */
683                 set_Proj_proj(proj, pn);
684         }
685         else {
686                 /* Set mode to floating point if required */
687                 if (!strcmp(ia32_reg_classes[CLASS_ia32_floating_point].name,
688                                         ia32_projnum_reg_req_map[pn]->req.cls->name)) {
689                         set_irn_mode(proj, mode_F);
690                 }
691         }
692
693         return pn;
694 }
695
696 int ia32_to_appear_in_schedule(void *block_env, const ir_node *irn) {
697         return is_ia32_irn(irn);
698 }
699
700 /**
701  * Initializes the code generator interface.
702  */
703 static const arch_code_generator_if_t *ia32_get_code_generator_if(void *self) {
704         return &ia32_code_gen_if;
705 }
706
707 list_sched_selector_t ia32_sched_selector;
708
709 /**
710  * Returns the reg_pressure scheduler with to_appear_in_schedule() overloaded
711  */
712 static const list_sched_selector_t *ia32_get_list_sched_selector(const void *self) {
713         memcpy(&ia32_sched_selector, reg_pressure_selector, sizeof(list_sched_selector_t));
714         ia32_sched_selector.to_appear_in_schedule = ia32_to_appear_in_schedule;
715         return &ia32_sched_selector;
716 }
717
718 #ifdef WITH_LIBCORE
719 static void ia32_register_options(lc_opt_entry_t *ent)
720 {
721 }
722 #endif /* WITH_LIBCORE */
723
724 const arch_isa_if_t ia32_isa_if = {
725 #ifdef WITH_LIBCORE
726         ia32_register_options,
727 #endif
728         ia32_init,
729         ia32_done,
730         ia32_get_n_reg_class,
731         ia32_get_reg_class,
732         ia32_get_irn_handler,
733         ia32_get_code_generator_if,
734         ia32_get_list_sched_selector,
735         ia32_handle_call_proj
736 };