fixed some requirements
[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) || is_Unknown(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_op(irn) == op_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_arg;
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                 stack_size    = get_type_size_bytes(get_irg_frame_type(irg));
376                 frame_dbg     = get_irn_dbg_info(frame);
377                 stack_reserve = new_rd_ia32_Sub_i(frame_dbg, irg, get_nodes_block(frame), new_NoMem(), mode_Is);
378                 stack_size_tv = new_tarval_from_long(stack_size, mode_Is);
379                 set_ia32_Immop_tarval(stack_reserve, stack_size_tv);
380
381                 assert(stack_size && "bOrken stack layout");
382
383                 /* reroute all edges from frame pointer to corrected frame pointer */
384                 edges_reroute(frame, stack_reserve, irg);
385                 set_irn_n(stack_reserve, 0, frame);
386
387                 /* schedule frame pointer */
388                 if (! sched_is_scheduled(frame)) {
389                         sched_add_after(get_irg_start(irg), frame);
390                 }
391
392                 /* set register */
393                 arch_set_irn_register(cg->arch_env, frame, stack_reg);
394                 arch_set_irn_register(cg->arch_env, stack_reserve, stack_reg);
395
396                 /* insert into schedule */
397                 sched_add_after(frame, stack_reserve);
398
399                 /* Free stack for each Return node */
400                 returns = get_Block_cfgpred_arr(end_block);
401                 for (i = 0; i < get_Block_n_cfgpreds(end_block); i++) {
402                         assert(get_irn_opcode(returns[i]) == iro_Return && "cfgpred of endblock is not a return");
403
404                         return_block = get_nodes_block(returns[i]);
405
406                         /* free the stack */
407                         stack_free = new_rd_ia32_Add_i(frame_dbg, irg, return_block, stack_reserve, mode_Is);
408                         set_ia32_Immop_tarval(stack_free, stack_size_tv);
409                         arch_set_irn_register(cg->arch_env, stack_free, stack_reg);
410
411                         DBG((mod, LEVEL_1, "examining %+F, %+F created, block %+F", returns[i], stack_free, return_block));
412
413                         /* get the old Return arguments */
414                         n_arg  = get_Return_n_ress(returns[i]);
415                         in     = get_Return_res_arr(returns[i]);
416                         new_in = alloca((n_arg + 2) * sizeof(new_in[0]));
417
418                         /* copy the old to the new in's */
419                         memcpy(new_in, in, n_arg * sizeof(in[0]));
420                         new_in[n_arg++] = stack_free;
421                         new_in[n_arg++] = get_Return_mem(returns[i]);
422
423                         /* create the new return node */
424                         new_ret = new_rd_ia32_Return(get_irn_dbg_info(returns[i]), irg, return_block, n_arg, new_in);
425
426                         /* In case the return node is the only node in the block, */
427                         /* it is not scheduled, so we need this work-around.      */
428                         if (! sched_is_scheduled(returns[i])) {
429                                 sched_point = return_block;
430                         }
431                         else {
432                                 sched_point = sched_prev(returns[i]);
433                                 sched_remove(returns[i]);
434                         }
435
436                         /* exchange the old return with the new one */
437                         exchange(returns[i], new_ret);
438
439                         DB((mod, LEVEL_1, " ... replaced with %+F\n", new_ret));
440
441                         /* remove the old one from schedule and add the new nodes properly */
442                         sched_add_after(sched_point, new_ret);
443                         sched_add_after(sched_point, stack_free);
444                 }
445         }
446 }
447
448
449
450 /**
451  * Dummy functions for hooks we don't need but which must be filled.
452  */
453 static void ia32_before_sched(void *self) {
454         ia32_code_gen_t *cg = self;
455
456         lower_nodes_before_sched(cg->irg, cg->arch_env);
457 }
458
459 static void ia32_before_ra(void *self) {
460 }
461
462
463 /**
464  * Creates a Store for a Spill
465  */
466 static ir_node *ia32_lower_spill(void *self, ir_node *spill) {
467         ia32_code_gen_t *cg    = self;
468         dbg_info        *dbg   = get_irn_dbg_info(spill);
469         ir_node         *block = get_nodes_block(spill);
470         ir_node         *ptr   = get_irg_frame(cg->irg);
471         ir_node         *val   = be_get_Spill_context(spill);
472         ir_node         *mem   = new_rd_NoMem(cg->irg);
473         ir_mode         *mode  = get_irn_mode(spill);
474         ir_node         *res;
475         entity          *ent   = be_get_spill_entity(spill);
476         unsigned         offs  = get_entity_offset_bytes(ent);
477
478         DB((cg->mod, LEVEL_1, "lower_spill: got offset %d for %+F\n", offs, ent));
479
480         res = new_rd_ia32_Store(dbg, cg->irg, block, ptr, val, mem, mode);
481         set_ia32_am_offs(res, new_tarval_from_long(offs, mode_Iu));
482
483         return res;
484 }
485
486 /**
487  * Create a Load for a Spill
488  */
489 static ir_node *ia32_lower_reload(void *self, ir_node *reload) {
490         ia32_code_gen_t *cg    = self;
491         dbg_info        *dbg   = get_irn_dbg_info(reload);
492         ir_node         *block = get_nodes_block(reload);
493         ir_node         *ptr   = get_irg_frame(cg->irg);
494         ir_mode         *mode  = get_irn_mode(reload);
495         ir_node         *pred  = get_irn_n(reload, 0);
496         tarval          *tv;
497         ir_node         *res;
498
499         if (be_is_Spill(pred)) {
500                 entity   *ent  = be_get_spill_entity(pred);
501                 unsigned  offs = get_entity_offset_bytes(ent);
502                 DB((cg->mod, LEVEL_1, "lower_reload: got offset %d for %+F\n", offs, ent));
503                 tv = new_tarval_from_long(offs, mode_Iu);
504         }
505         else if (is_ia32_Store(pred)) {
506                 tv = get_ia32_am_offs(pred);
507         }
508         else {
509                 assert(0 && "unsupported Reload predecessor");
510         }
511
512         res = new_rd_ia32_Load(dbg, cg->irg, block, ptr, pred, mode);
513         set_ia32_am_offs(res, tv);
514
515         return res;
516 }
517
518 /**
519  * Return the stack register for this irg.
520  */
521 static const arch_register_t *ia32_get_stack_register(void *self) {
522         ia32_code_gen_t *cg = self;
523
524         if (cg->has_alloca) {
525                 return &ia32_general_purpose_regs[REG_EBP];
526         }
527
528         return &ia32_general_purpose_regs[REG_ESP];
529 }
530
531 /**
532  * Emits the code, closes the output file and frees
533  * the code generator interface.
534  */
535 static void ia32_codegen(void *self) {
536         ia32_code_gen_t *cg = self;
537         ir_graph       *irg = cg->irg;
538         FILE           *out = cg->out;
539
540         if (cg->emit_decls) {
541                 ia32_gen_decls(cg->out);
542                 cg->emit_decls = 0;
543         }
544
545         ia32_finish_irg(irg, cg);
546         dump_ir_block_graph_sched(irg, "-finished");
547         ia32_gen_routine(out, irg, cg);
548
549         cur_reg_set = NULL;
550
551         /* de-allocate code generator */
552         del_set(cg->reg_set);
553         free(self);
554 }
555
556 static void *ia32_cg_init(FILE *F, ir_graph *irg, const arch_env_t *arch_env);
557
558 static const arch_code_generator_if_t ia32_code_gen_if = {
559         ia32_cg_init,
560         ia32_prepare_graph,
561         ia32_before_sched,   /* before scheduling hook */
562         ia32_before_ra,      /* before register allocation hook */
563         ia32_lower_spill,
564         ia32_lower_reload,
565         ia32_get_stack_register,
566         ia32_codegen         /* emit && done */
567 };
568
569 /**
570  * Initializes the code generator.
571  */
572 static void *ia32_cg_init(FILE *F, ir_graph *irg, const arch_env_t *arch_env) {
573         ia32_isa_t      *isa = (ia32_isa_t *)arch_env->isa;
574         ia32_code_gen_t *cg  = xmalloc(sizeof(*cg));
575
576         cg->impl       = &ia32_code_gen_if;
577         cg->irg        = irg;
578         cg->reg_set    = new_set(ia32_cmp_irn_reg_assoc, 1024);
579         cg->mod        = firm_dbg_register("firm.be.ia32.cg");
580         cg->out        = F;
581         cg->arch_env   = arch_env;
582
583         isa->num_codegens++;
584
585         if (isa->num_codegens > 1)
586                 cg->emit_decls = 0;
587         else
588                 cg->emit_decls = 1;
589
590         cur_reg_set = cg->reg_set;
591
592         ia32_irn_ops.cg = cg;
593
594         return (arch_code_generator_t *)cg;
595 }
596
597
598
599 /*****************************************************************
600  *  ____             _                  _   _____  _____
601  * |  _ \           | |                | | |_   _|/ ____|  /\
602  * | |_) | __ _  ___| | _____ _ __   __| |   | | | (___   /  \
603  * |  _ < / _` |/ __| |/ / _ \ '_ \ / _` |   | |  \___ \ / /\ \
604  * | |_) | (_| | (__|   <  __/ | | | (_| |  _| |_ ____) / ____ \
605  * |____/ \__,_|\___|_|\_\___|_| |_|\__,_| |_____|_____/_/    \_\
606  *
607  *****************************************************************/
608
609 /**
610  * Initializes the backend ISA and opens the output file.
611  */
612 static void *ia32_init(void) {
613         static int inited = 0;
614         ia32_isa_t *isa   = xmalloc(sizeof(*isa));
615
616         isa->impl = &ia32_isa_if;
617
618         if(inited)
619                 return NULL;
620
621         inited = 1;
622
623         isa->num_codegens    = 0;
624         isa->reg_projnum_map = new_set(ia32_cmp_reg_projnum_assoc, 1024);
625
626         ia32_register_init(isa);
627         ia32_create_opcodes();
628
629         return isa;
630 }
631
632
633
634 /**
635  * Closes the output file and frees the ISA structure.
636  */
637 static void ia32_done(void *self) {
638         free(self);
639 }
640
641
642
643 static int ia32_get_n_reg_class(const void *self) {
644         return N_CLASSES;
645 }
646
647 static const arch_register_class_t *ia32_get_reg_class(const void *self, int i) {
648         assert(i >= 0 && i < N_CLASSES && "Invalid ia32 register class requested.");
649         return &ia32_reg_classes[i];
650 }
651
652 static const void *ia32_get_irn_ops(const arch_irn_handler_t *self, const ir_node *irn) {
653         return &ia32_irn_ops;
654 }
655
656 const arch_irn_handler_t ia32_irn_handler = {
657         ia32_get_irn_ops
658 };
659
660 const arch_irn_handler_t *ia32_get_irn_handler(const void *self) {
661         return &ia32_irn_handler;
662 }
663
664 long ia32_handle_call_proj(const void *self, ir_node *proj, int is_keep) {
665         ia32_isa_t *isa = (ia32_isa_t *)self;
666         long        pn  = get_Proj_proj(proj);
667
668         if (!is_keep) {
669                 /* It's not a Keep proj, which means, that it is a result proj. */
670                 /* Possible result proj numbers are 0 and 1                     */
671                 /* Set the correct register (depends on the mode) and the       */
672                 /* corresponding proj number                                    */
673                 if (mode_is_float(get_irn_mode(proj))) {
674                         assert(pn == 0 && "only one floating point result supported");
675
676                         /* Get the proj number for the floating point result */
677                         pn = ia32_get_reg_projnum(&ia32_floating_point_regs[REG_XMM0], isa->reg_projnum_map);
678                 }
679                 else {
680                         /* In case of 64bit return value, the result is */
681                         /* in EDX:EAX and we have two result projs.     */
682                         switch (pn) {
683                                 case 0:
684                                         pn = ia32_get_reg_projnum(&ia32_general_purpose_regs[REG_EAX], isa->reg_projnum_map);
685                                         break;
686                                 case 1:
687                                         pn = ia32_get_reg_projnum(&ia32_general_purpose_regs[REG_EDX], isa->reg_projnum_map);
688                                         break;
689                                 default:
690                                         assert(0 && "only two int results supported");
691                         }
692                 }
693
694                 /* Set the correct proj number */
695                 set_Proj_proj(proj, pn);
696         }
697         else {
698                 /* Set mode to floating point if required */
699                 if (!strcmp(ia32_reg_classes[CLASS_ia32_floating_point].name,
700                                         ia32_projnum_reg_req_map[pn]->req.cls->name)) {
701                         set_irn_mode(proj, mode_F);
702                 }
703         }
704
705         return pn;
706 }
707
708 int ia32_to_appear_in_schedule(void *block_env, const ir_node *irn) {
709         return is_ia32_irn(irn);
710 }
711
712 /**
713  * Initializes the code generator interface.
714  */
715 static const arch_code_generator_if_t *ia32_get_code_generator_if(void *self) {
716         return &ia32_code_gen_if;
717 }
718
719 list_sched_selector_t ia32_sched_selector;
720
721 /**
722  * Returns the reg_pressure scheduler with to_appear_in_schedule() overloaded
723  */
724 static const list_sched_selector_t *ia32_get_list_sched_selector(const void *self) {
725         memcpy(&ia32_sched_selector, reg_pressure_selector, sizeof(list_sched_selector_t));
726         ia32_sched_selector.to_appear_in_schedule = ia32_to_appear_in_schedule;
727         return &ia32_sched_selector;
728 }
729
730 #ifdef WITH_LIBCORE
731 static void ia32_register_options(lc_opt_entry_t *ent)
732 {
733 }
734 #endif /* WITH_LIBCORE */
735
736 const arch_isa_if_t ia32_isa_if = {
737 #ifdef WITH_LIBCORE
738         ia32_register_options,
739 #endif
740         ia32_init,
741         ia32_done,
742         ia32_get_n_reg_class,
743         ia32_get_reg_class,
744         ia32_get_irn_handler,
745         ia32_get_code_generator_if,
746         ia32_get_list_sched_selector,
747         ia32_handle_call_proj
748 };