9633ca4a6c528b9622ca04d7a57ca1e36032ba6b
[libfirm] / ir / be / ia32 / bearch_ia32.c
1 /**
2  * This is the main ia32 firm backend driver.
3  *
4  * $Id$
5  */
6
7 #ifdef HAVE_CONFIG_H
8 #include "config.h"
9 #endif
10
11 #ifdef HAVE_MALLOC_H
12 #include <malloc.h>
13 #endif
14
15 #ifdef HAVE_ALLOCA_H
16 #include <alloca.h>
17 #endif
18
19 #ifdef WITH_LIBCORE
20 #include <libcore/lc_opts.h>
21 #include <libcore/lc_opts_enum.h>
22 #endif /* WITH_LIBCORE */
23
24 #include "pseudo_irg.h"
25 #include "irgwalk.h"
26 #include "irprog.h"
27 #include "irprintf.h"
28 #include "iredges_t.h"
29 #include "ircons.h"
30 #include "irgmod.h"
31 #include "irgopt.h"
32
33 #include "bitset.h"
34 #include "debug.h"
35
36 #include "../beabi.h"                 /* the general register allocator interface */
37 #include "../benode_t.h"
38 #include "../belower.h"
39 #include "../besched_t.h"
40 #include "../be.h"
41 #include "bearch_ia32_t.h"
42
43 #include "ia32_new_nodes.h"           /* ia32 nodes interface */
44 #include "gen_ia32_regalloc_if.h"     /* the generated interface (register type and class defenitions) */
45 #include "ia32_gen_decls.h"           /* interface declaration emitter */
46 #include "ia32_transform.h"
47 #include "ia32_emitter.h"
48 #include "ia32_map_regs.h"
49 #include "ia32_optimize.h"
50 #include "ia32_x87.h"
51 #include "ia32_dbg_stat.h"
52
53 #define DEBUG_MODULE "firm.be.ia32.isa"
54
55 /* TODO: ugly */
56 static set *cur_reg_set = NULL;
57
58 #undef is_Start
59 #define is_Start(irn) (get_irn_opcode(irn) == iro_Start)
60
61 /* Creates the unique per irg GP NoReg node. */
62 ir_node *ia32_new_NoReg_gp(ia32_code_gen_t *cg) {
63         return be_abi_get_callee_save_irn(cg->birg->abi, &ia32_gp_regs[REG_GP_NOREG]);
64 }
65
66 /* Creates the unique per irg FP NoReg node. */
67 ir_node *ia32_new_NoReg_fp(ia32_code_gen_t *cg) {
68         return be_abi_get_callee_save_irn(cg->birg->abi,
69                 USE_SSE2(cg) ? &ia32_xmm_regs[REG_XMM_NOREG] : &ia32_vfp_regs[REG_VFP_NOREG]);
70 }
71
72 /**************************************************
73  *                         _ _              _  __
74  *                        | | |            (_)/ _|
75  *  _ __ ___  __ _    __ _| | | ___   ___   _| |_
76  * | '__/ _ \/ _` |  / _` | | |/ _ \ / __| | |  _|
77  * | | |  __/ (_| | | (_| | | | (_) | (__  | | |
78  * |_|  \___|\__, |  \__,_|_|_|\___/ \___| |_|_|
79  *            __/ |
80  *           |___/
81  **************************************************/
82
83 static ir_node *my_skip_proj(const ir_node *n) {
84         while (is_Proj(n))
85                 n = get_Proj_pred(n);
86         return (ir_node *)n;
87 }
88
89
90 /**
91  * Return register requirements for an ia32 node.
92  * If the node returns a tuple (mode_T) then the proj's
93  * will be asked for this information.
94  */
95 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) {
96         const ia32_irn_ops_t      *ops = self;
97         const ia32_register_req_t *irn_req;
98         long                       node_pos = pos == -1 ? 0 : pos;
99         ir_mode                   *mode     = is_Block(irn) ? NULL : get_irn_mode(irn);
100         FIRM_DBG_REGISTER(firm_dbg_module_t *mod, DEBUG_MODULE);
101
102         if (is_Block(irn) || mode == mode_M || mode == mode_X) {
103                 DBG((mod, LEVEL_1, "ignoring Block, mode_M, mode_X node %+F\n", irn));
104                 return NULL;
105         }
106
107         if (mode == mode_T && pos < 0) {
108                 DBG((mod, LEVEL_1, "ignoring request OUT requirements for node %+F\n", irn));
109                 return NULL;
110         }
111
112         DBG((mod, LEVEL_1, "get requirements at pos %d for %+F ... ", pos, irn));
113
114         if (is_Proj(irn)) {
115                 if (pos == -1) {
116                         node_pos = ia32_translate_proj_pos(irn);
117                 }
118                 else {
119                         node_pos = pos;
120                 }
121
122                 irn = my_skip_proj(irn);
123
124                 DB((mod, LEVEL_1, "skipping Proj, going to %+F at pos %d ... ", irn, node_pos));
125         }
126
127         if (is_ia32_irn(irn)) {
128                 if (pos >= 0) {
129                         irn_req = get_ia32_in_req(irn, pos);
130                 }
131                 else {
132                         irn_req = get_ia32_out_req(irn, node_pos);
133                 }
134
135                 DB((mod, LEVEL_1, "returning reqs for %+F at pos %d\n", irn, pos));
136
137                 memcpy(req, &(irn_req->req), sizeof(*req));
138
139                 if (arch_register_req_is(&(irn_req->req), should_be_same)) {
140                         assert(irn_req->same_pos >= 0 && "should be same constraint for in -> out NYI");
141                         req->other_same = get_irn_n(irn, irn_req->same_pos);
142                 }
143
144                 if (arch_register_req_is(&(irn_req->req), should_be_different)) {
145                         assert(irn_req->different_pos >= 0 && "should be different constraint for in -> out NYI");
146                         req->other_different = get_irn_n(irn, irn_req->different_pos);
147                 }
148         }
149         else {
150                 /* treat Phi like Const with default requirements */
151                 if (is_Phi(irn)) {
152                         DB((mod, LEVEL_1, "returning standard reqs for %+F\n", irn));
153                         if (mode_is_float(mode)) {
154                                 if (USE_SSE2(ops->cg))
155                                         memcpy(req, &(ia32_default_req_ia32_xmm.req), sizeof(*req));
156                                 else
157                                         memcpy(req, &(ia32_default_req_ia32_vfp.req), sizeof(*req));
158                         }
159                         else if (mode_is_int(mode) || mode_is_reference(mode))
160                                 memcpy(req, &(ia32_default_req_ia32_gp.req), sizeof(*req));
161                         else if (mode == mode_T || mode == mode_M) {
162                                 DBG((mod, LEVEL_1, "ignoring Phi node %+F\n", irn));
163                                 return NULL;
164                         }
165                         else
166                                 assert(0 && "unsupported Phi-Mode");
167                 }
168                 else {
169                         DB((mod, LEVEL_1, "returning NULL for %+F (not ia32)\n", irn));
170                         req = NULL;
171                 }
172         }
173
174         return req;
175 }
176
177 static void ia32_set_irn_reg(const void *self, ir_node *irn, const arch_register_t *reg) {
178         int                   pos = 0;
179         const ia32_irn_ops_t *ops = self;
180
181         if (get_irn_mode(irn) == mode_X) {
182                 return;
183         }
184
185         DBG((ops->cg->mod, LEVEL_1, "ia32 assigned register %s to node %+F\n", reg->name, irn));
186
187         if (is_Proj(irn)) {
188                 pos = ia32_translate_proj_pos(irn);
189                 irn = my_skip_proj(irn);
190         }
191
192         if (is_ia32_irn(irn)) {
193                 const arch_register_t **slots;
194
195                 slots      = get_ia32_slots(irn);
196                 slots[pos] = reg;
197         }
198         else {
199                 ia32_set_firm_reg(irn, reg, cur_reg_set);
200         }
201 }
202
203 static const arch_register_t *ia32_get_irn_reg(const void *self, const ir_node *irn) {
204         int pos = 0;
205         const arch_register_t *reg = NULL;
206
207         if (is_Proj(irn)) {
208
209                 if (get_irn_mode(irn) == mode_X) {
210                         return NULL;
211                 }
212
213                 pos = ia32_translate_proj_pos(irn);
214                 irn = my_skip_proj(irn);
215         }
216
217         if (is_ia32_irn(irn)) {
218                 const arch_register_t **slots;
219                 slots = get_ia32_slots(irn);
220                 reg   = slots[pos];
221         }
222         else {
223                 reg = ia32_get_firm_reg(irn, cur_reg_set);
224         }
225
226         return reg;
227 }
228
229 static arch_irn_class_t ia32_classify(const void *self, const ir_node *irn) {
230         irn = my_skip_proj(irn);
231         if (is_cfop(irn))
232                 return arch_irn_class_branch;
233         else if (is_ia32_irn(irn))
234                 return arch_irn_class_normal;
235         else
236                 return 0;
237 }
238
239 static arch_irn_flags_t ia32_get_flags(const void *self, const ir_node *irn) {
240         irn = my_skip_proj(irn);
241         if (is_ia32_irn(irn))
242                 return get_ia32_flags(irn);
243         else {
244                 return 0;
245         }
246 }
247
248 static entity *ia32_get_frame_entity(const void *self, const ir_node *irn) {
249         return is_ia32_irn(irn) ? get_ia32_frame_ent(irn) : NULL;
250 }
251
252 static void ia32_set_stack_bias(const void *self, ir_node *irn, int bias) {
253         char buf[64];
254         const ia32_irn_ops_t *ops = self;
255
256         if (get_ia32_frame_ent(irn)) {
257                 ia32_am_flavour_t am_flav = get_ia32_am_flavour(irn);
258
259                 DBG((ops->cg->mod, LEVEL_1, "stack biased %+F with %d\n", irn, bias));
260                 snprintf(buf, sizeof(buf), "%d", bias);
261
262                 if (get_ia32_op_type(irn) == ia32_Normal) {
263                         set_ia32_cnst(irn, buf);
264                 }
265                 else {
266                         add_ia32_am_offs(irn, buf);
267                         am_flav |= ia32_O;
268                         set_ia32_am_flavour(irn, am_flav);
269                 }
270         }
271 }
272
273 typedef struct {
274         be_abi_call_flags_bits_t flags;
275         const arch_isa_t *isa;
276         const arch_env_t *aenv;
277         ir_graph *irg;
278 } ia32_abi_env_t;
279
280 static void *ia32_abi_init(const be_abi_call_t *call, const arch_env_t *aenv, ir_graph *irg)
281 {
282         ia32_abi_env_t *env    = xmalloc(sizeof(env[0]));
283         be_abi_call_flags_t fl = be_abi_call_get_flags(call);
284         env->flags = fl.bits;
285         env->irg   = irg;
286         env->aenv  = aenv;
287         env->isa   = aenv->isa;
288         return env;
289 }
290
291 static void ia32_abi_dont_save_regs(void *self, pset *s)
292 {
293         ia32_abi_env_t *env = self;
294         if(env->flags.try_omit_fp)
295                 pset_insert_ptr(s, env->isa->bp);
296 }
297
298 /**
299  * Generate the prologue.
300  * @param self    The callback object.
301  * @param mem     A pointer to the mem node. Update this if you define new memory.
302  * @param reg_map A mapping mapping all callee_save/ignore/parameter registers to their defining nodes.
303  * @return        The register which shall be used as a stack frame base.
304  *
305  * All nodes which define registers in @p reg_map must keep @p reg_map current.
306  */
307 static const arch_register_t *ia32_abi_prologue(void *self, ir_node **mem, pmap *reg_map)
308 {
309         ia32_abi_env_t *env              = self;
310
311         if (!env->flags.try_omit_fp) {
312                 int reg_size         = get_mode_size_bytes(env->isa->bp->reg_class->mode);
313                 ir_node *bl          = get_irg_start_block(env->irg);
314                 ir_node *curr_sp     = be_abi_reg_map_get(reg_map, env->isa->sp);
315                 ir_node *curr_bp     = be_abi_reg_map_get(reg_map, env->isa->bp);
316                 ir_node *curr_no_reg = be_abi_reg_map_get(reg_map, &ia32_gp_regs[REG_GP_NOREG]);
317                 ir_node *store_bp;
318
319                 /* push ebp */
320                 curr_sp  = be_new_IncSP(env->isa->sp, env->irg, bl, curr_sp, *mem, reg_size, be_stack_dir_expand);
321                 store_bp = new_rd_ia32_Store(NULL, env->irg, bl, curr_sp, curr_no_reg, curr_bp, *mem, mode_T);
322                 set_ia32_am_support(store_bp, ia32_am_Dest);
323                 set_ia32_am_flavour(store_bp, ia32_B);
324                 set_ia32_op_type(store_bp, ia32_AddrModeD);
325                 set_ia32_ls_mode(store_bp, env->isa->bp->reg_class->mode);
326                 *mem     = new_r_Proj(env->irg, bl, store_bp, mode_M, 0);
327
328                 /* move esp to ebp */
329                 curr_bp  = be_new_Copy(env->isa->bp->reg_class, env->irg, bl, curr_sp);
330                 be_set_constr_single_reg(curr_bp, BE_OUT_POS(0), env->isa->bp);
331                 arch_set_irn_register(env->aenv, curr_bp, env->isa->bp);
332                 be_node_set_flags(curr_bp, BE_OUT_POS(0), arch_irn_flags_ignore);
333
334                 be_abi_reg_map_set(reg_map, env->isa->sp, curr_sp);
335                 be_abi_reg_map_set(reg_map, env->isa->bp, curr_bp);
336
337                 return env->isa->bp;
338         }
339
340         return env->isa->sp;
341 }
342
343 static void ia32_abi_epilogue(void *self, ir_node *bl, ir_node **mem, pmap *reg_map)
344 {
345         ia32_abi_env_t *env  = self;
346         ir_node *curr_sp     = be_abi_reg_map_get(reg_map, env->isa->sp);
347         ir_node *curr_bp     = be_abi_reg_map_get(reg_map, env->isa->bp);
348         ir_node *curr_no_reg = be_abi_reg_map_get(reg_map, &ia32_gp_regs[REG_GP_NOREG]);
349
350         if (env->flags.try_omit_fp) {
351                 /* simply remove the stack frame here */
352                 curr_sp = be_new_IncSP(env->isa->sp, env->irg, bl, curr_sp, *mem, BE_STACK_FRAME_SIZE, be_stack_dir_shrink);
353         }
354
355         else {
356                 ir_node *load_bp;
357                 ir_mode *mode_bp = env->isa->bp->reg_class->mode;
358                 int reg_size     = get_mode_size_bytes(env->isa->bp->reg_class->mode);
359
360                 /* copy ebp to esp */
361                 curr_sp = be_new_SetSP(env->isa->sp, env->irg, bl, curr_sp, curr_bp, *mem);
362
363                 /* pop ebp */
364                 load_bp = new_rd_ia32_Load(NULL, env->irg, bl, curr_sp, curr_no_reg, *mem, mode_T);
365                 set_ia32_am_support(load_bp, ia32_am_Source);
366                 set_ia32_am_flavour(load_bp, ia32_B);
367                 set_ia32_op_type(load_bp, ia32_AddrModeS);
368                 set_ia32_ls_mode(load_bp, mode_bp);
369                 curr_bp = new_r_Proj(env->irg, bl, load_bp, mode_bp, 0);
370                 *mem    = new_r_Proj(env->irg, bl, load_bp, mode_M, 1);
371                 arch_set_irn_register(env->aenv, curr_bp, env->isa->bp);
372
373                 curr_sp  = be_new_IncSP(env->isa->sp, env->irg, bl, curr_sp, *mem, reg_size, be_stack_dir_shrink);
374         }
375
376         be_abi_reg_map_set(reg_map, env->isa->sp, curr_sp);
377         be_abi_reg_map_set(reg_map, env->isa->bp, curr_bp);
378 }
379
380 /**
381  * Produces the type which sits between the stack args and the locals on the stack.
382  * it will contain the return address and space to store the old base pointer.
383  * @return The Firm type modeling the ABI between type.
384  */
385 static ir_type *ia32_abi_get_between_type(void *self)
386 {
387         static ir_type *omit_fp_between_type = NULL;
388         static ir_type *between_type         = NULL;
389
390         ia32_abi_env_t *env = self;
391
392         if(!between_type) {
393                 entity *old_bp_ent;
394                 entity *ret_addr_ent;
395                 entity *omit_fp_ret_addr_ent;
396
397                 ir_type *old_bp_type   = new_type_primitive(new_id_from_str("bp"), mode_P);
398                 ir_type *ret_addr_type = new_type_primitive(new_id_from_str("return_addr"), mode_P);
399
400                 between_type           = new_type_class(new_id_from_str("ia32_between_type"));
401                 old_bp_ent             = new_entity(between_type, new_id_from_str("old_bp"), old_bp_type);
402                 ret_addr_ent           = new_entity(between_type, new_id_from_str("ret_addr"), ret_addr_type);
403
404                 set_entity_offset_bytes(old_bp_ent, 0);
405                 set_entity_offset_bytes(ret_addr_ent, get_type_size_bytes(old_bp_type));
406                 set_type_size_bytes(between_type, get_type_size_bytes(old_bp_type) + get_type_size_bytes(ret_addr_type));
407
408                 omit_fp_between_type   = new_type_class(new_id_from_str("ia32_between_type_omit_fp"));
409                 omit_fp_ret_addr_ent   = new_entity(omit_fp_between_type, new_id_from_str("ret_addr"), ret_addr_type);
410
411                 set_entity_offset_bytes(omit_fp_ret_addr_ent, 0);
412                 set_type_size_bytes(omit_fp_between_type, get_type_size_bytes(ret_addr_type));
413         }
414
415         return env->flags.try_omit_fp ? omit_fp_between_type : between_type;
416 }
417
418 static const be_abi_callbacks_t ia32_abi_callbacks = {
419         ia32_abi_init,
420         free,
421         ia32_abi_get_between_type,
422         ia32_abi_dont_save_regs,
423         ia32_abi_prologue,
424         ia32_abi_epilogue,
425 };
426
427 /* fill register allocator interface */
428
429 static const arch_irn_ops_if_t ia32_irn_ops_if = {
430         ia32_get_irn_reg_req,
431         ia32_set_irn_reg,
432         ia32_get_irn_reg,
433         ia32_classify,
434         ia32_get_flags,
435         ia32_get_frame_entity,
436         ia32_set_stack_bias
437 };
438
439 ia32_irn_ops_t ia32_irn_ops = {
440         &ia32_irn_ops_if,
441         NULL
442 };
443
444
445
446 /**************************************************
447  *                _                         _  __
448  *               | |                       (_)/ _|
449  *   ___ ___   __| | ___  __ _  ___ _ __    _| |_
450  *  / __/ _ \ / _` |/ _ \/ _` |/ _ \ '_ \  | |  _|
451  * | (_| (_) | (_| |  __/ (_| |  __/ | | | | | |
452  *  \___\___/ \__,_|\___|\__, |\___|_| |_| |_|_|
453  *                        __/ |
454  *                       |___/
455  **************************************************/
456
457 /**
458  * Transforms the standard firm graph into
459  * an ia32 firm graph
460  */
461 static void ia32_prepare_graph(void *self) {
462         ia32_code_gen_t *cg = self;
463         DEBUG_ONLY(firm_dbg_module_t *old_mod = cg->mod;)
464
465         FIRM_DBG_REGISTER(cg->mod, "firm.be.ia32.transform");
466         ia32_register_transformers();
467         irg_walk_blkwise_graph(cg->irg, ia32_place_consts_set_modes, ia32_transform_node, cg);
468         be_dump(cg->irg, "-transformed", dump_ir_block_graph_sched);
469
470         if (cg->opt & IA32_OPT_DOAM) {
471                 edges_deactivate(cg->irg);
472                 //dead_node_elimination(cg->irg);
473                 edges_activate(cg->irg);
474
475                 FIRM_DBG_REGISTER(cg->mod, "firm.be.ia32.am");
476
477                 irg_walk_blkwise_graph(cg->irg, NULL, ia32_optimize_am, cg);
478                 be_dump(cg->irg, "-am", dump_ir_block_graph_sched);
479         }
480
481         DEBUG_ONLY(cg->mod = old_mod;)
482 }
483
484
485 /**
486  * Insert copies for all ia32 nodes where the should_be_same requirement
487  * is not fulfilled.
488  * Transform Sub into Neg -- Add if IN2 == OUT
489  */
490 static void ia32_finish_node(ir_node *irn, void *env) {
491         ia32_code_gen_t            *cg = env;
492         const ia32_register_req_t **reqs;
493         const arch_register_t      *out_reg, *in_reg, *in2_reg;
494         int                         n_res, i;
495         ir_node                    *copy, *in_node, *block, *in2_node;
496         ia32_op_type_t              op_tp;
497
498         if (is_ia32_irn(irn)) {
499                 /* AM Dest nodes don't produce any values  */
500                 op_tp = get_ia32_op_type(irn);
501                 if (op_tp == ia32_AddrModeD)
502                         goto end;
503
504                 reqs  = get_ia32_out_req_all(irn);
505                 n_res = get_ia32_n_res(irn);
506                 block = get_nodes_block(irn);
507
508                 /* check all OUT requirements, if there is a should_be_same */
509                 if (op_tp == ia32_Normal && ! is_ia32_Lea(irn) && ! is_ia32_Conv_I2I(irn) && ! is_ia32_Conv_I2I8Bit(irn)) {
510                         for (i = 0; i < n_res; i++) {
511                                 if (arch_register_req_is(&(reqs[i]->req), should_be_same)) {
512                                         /* get in and out register */
513                                         out_reg  = get_ia32_out_reg(irn, i);
514                                         in_node  = get_irn_n(irn, reqs[i]->same_pos);
515                                         in_reg   = arch_get_irn_register(cg->arch_env, in_node);
516
517                                         /* don't copy ignore nodes */
518                                         if (arch_irn_is(cg->arch_env, in_node, ignore) && is_Proj(in_node))
519                                                 continue;
520
521                                         /* check if in and out register are equal */
522                                         if (! REGS_ARE_EQUAL(out_reg, in_reg)) {
523                                                 /* in case of a commutative op: just exchange the in's */
524                                                 /* beware: the current op could be everything, so test for ia32 */
525                                                 /*         commutativity first before getting the second in     */
526                                                 if (is_ia32_commutative(irn)) {
527                                                         in2_node = get_irn_n(irn, reqs[i]->same_pos ^ 1);
528                                                         in2_reg  = arch_get_irn_register(cg->arch_env, in2_node);
529
530                                                         if (REGS_ARE_EQUAL(out_reg, in2_reg)) {
531                                                                 set_irn_n(irn, reqs[i]->same_pos, in2_node);
532                                                                 set_irn_n(irn, reqs[i]->same_pos ^ 1, in_node);
533                                                         }
534                                                         else
535                                                                 goto insert_copy;
536                                                 }
537                                                 else {
538 insert_copy:
539                                                         DBG((cg->mod, LEVEL_1, "inserting copy for %+F in_pos %d\n", irn, reqs[i]->same_pos));
540                                                         /* create copy from in register */
541                                                         copy = be_new_Copy(arch_register_get_class(in_reg), cg->irg, block, in_node);
542
543                                                         DBG_OPT_2ADDRCPY(copy);
544
545                                                         /* destination is the out register */
546                                                         arch_set_irn_register(cg->arch_env, copy, out_reg);
547
548                                                         /* insert copy before the node into the schedule */
549                                                         sched_add_before(irn, copy);
550
551                                                         /* set copy as in */
552                                                         set_irn_n(irn, reqs[i]->same_pos, copy);
553                                                 }
554                                         }
555                                 }
556                         }
557                 }
558
559                 /* If we have a CondJmp with immediate, we need to    */
560                 /* check if it's the right operand, otherwise we have */
561                 /* to change it, as CMP doesn't support immediate as  */
562                 /* left operands.                                     */
563                 if (is_ia32_CondJmp(irn) && (is_ia32_ImmConst(irn) || is_ia32_ImmSymConst(irn)) && op_tp == ia32_AddrModeS) {
564                         long pnc = get_negated_pnc(get_ia32_pncode(irn), get_ia32_res_mode(irn));
565                         set_ia32_op_type(irn, ia32_AddrModeD);
566                         set_ia32_pncode(irn, pnc);
567                 }
568
569                 /* check if there is a sub which need to be transformed */
570                 ia32_transform_sub_to_neg_add(irn, cg);
571
572                 /* transform a LEA into an Add if possible */
573                 ia32_transform_lea_to_add(irn, cg);
574         }
575 end:
576
577         /* check for peephole optimization */
578         ia32_peephole_optimization(irn, cg);
579 }
580
581 static void ia32_finish_irg_walker(ir_node *block, void *env) {
582         ir_node *irn, *next;
583
584         for (irn = sched_first(block); !sched_is_end(irn); irn = next) {
585                 next = sched_next(irn);
586                 ia32_finish_node(irn, env);
587         }
588 }
589
590 /**
591  * Add Copy nodes for not fulfilled should_be_equal constraints
592  */
593 static void ia32_finish_irg(ir_graph *irg, ia32_code_gen_t *cg) {
594         irg_block_walk_graph(irg, NULL, ia32_finish_irg_walker, cg);
595 }
596
597
598
599 /**
600  * Dummy functions for hooks we don't need but which must be filled.
601  */
602 static void ia32_before_sched(void *self) {
603 }
604
605 /**
606  * Called before the register allocator.
607  * Calculate a block schedule here. We need it for the x87
608  * simulator and the emitter.
609  */
610 static void ia32_before_ra(void *self) {
611         ia32_code_gen_t *cg = self;
612
613         cg->blk_sched = sched_create_block_schedule(cg->irg);
614 }
615
616
617 /**
618  * Transforms a be node into a Load.
619  */
620 static void transform_to_Load(ia32_transform_env_t *env) {
621         ir_node *irn         = env->irn;
622         entity  *ent         = be_get_frame_entity(irn);
623         ir_mode *mode        = env->mode;
624         ir_node *noreg       = ia32_new_NoReg_gp(env->cg);
625         ir_node *nomem       = new_rd_NoMem(env->irg);
626         ir_node *sched_point = NULL;
627         ir_node *ptr         = get_irn_n(irn, 0);
628         ir_node *mem         = be_is_Reload(irn) ? get_irn_n(irn, 1) : nomem;
629         ir_node *new_op, *proj;
630         const arch_register_t *reg;
631
632         if (sched_is_scheduled(irn)) {
633                 sched_point = sched_prev(irn);
634         }
635
636         if (mode_is_float(mode)) {
637                 if (USE_SSE2(env->cg))
638                         new_op = new_rd_ia32_fLoad(env->dbg, env->irg, env->block, ptr, noreg, mem, mode_T);
639                 else
640                         new_op = new_rd_ia32_vfld(env->dbg, env->irg, env->block, ptr, noreg, mem, mode_T);
641         }
642         else {
643                 new_op = new_rd_ia32_Load(env->dbg, env->irg, env->block, ptr, noreg, mem, mode_T);
644         }
645
646         set_ia32_am_support(new_op, ia32_am_Source);
647         set_ia32_op_type(new_op, ia32_AddrModeS);
648         set_ia32_am_flavour(new_op, ia32_B);
649         set_ia32_ls_mode(new_op, mode);
650         set_ia32_frame_ent(new_op, ent);
651         set_ia32_use_frame(new_op);
652
653         DBG_OPT_RELOAD2LD(irn, new_op);
654
655         proj = new_rd_Proj(env->dbg, env->irg, env->block, new_op, mode, pn_Load_res);
656
657         if (sched_point) {
658                 sched_add_after(sched_point, new_op);
659                 sched_add_after(new_op, proj);
660
661                 sched_remove(irn);
662         }
663
664         /* copy the register from the old node to the new Load */
665         reg = arch_get_irn_register(env->cg->arch_env, irn);
666         arch_set_irn_register(env->cg->arch_env, new_op, reg);
667
668         SET_IA32_ORIG_NODE(new_op, ia32_get_old_node_name(env->cg, new_op));
669
670         exchange(irn, proj);
671 }
672
673 /**
674  * Transforms a be node into a Store.
675  */
676 static void transform_to_Store(ia32_transform_env_t *env) {
677         ir_node *irn   = env->irn;
678         entity  *ent   = be_get_frame_entity(irn);
679         ir_mode *mode  = env->mode;
680         ir_node *noreg = ia32_new_NoReg_gp(env->cg);
681         ir_node *nomem = new_rd_NoMem(env->irg);
682         ir_node *ptr   = get_irn_n(irn, 0);
683         ir_node *val   = get_irn_n(irn, 1);
684         ir_node *new_op, *proj;
685         ir_node *sched_point = NULL;
686
687         if (sched_is_scheduled(irn)) {
688                 sched_point = sched_prev(irn);
689         }
690
691         if (mode_is_float(mode)) {
692                 if (USE_SSE2(env->cg))
693                         new_op = new_rd_ia32_fStore(env->dbg, env->irg, env->block, ptr, noreg, val, nomem, mode_T);
694                 else
695                         new_op = new_rd_ia32_vfst(env->dbg, env->irg, env->block, ptr, noreg, val, nomem, mode_T);
696         }
697         else if (get_mode_size_bits(mode) == 8) {
698                 new_op = new_rd_ia32_Store8Bit(env->dbg, env->irg, env->block, ptr, noreg, val, nomem, mode_T);
699         }
700         else {
701                 new_op = new_rd_ia32_Store(env->dbg, env->irg, env->block, ptr, noreg, val, nomem, mode_T);
702         }
703
704         set_ia32_am_support(new_op, ia32_am_Dest);
705         set_ia32_op_type(new_op, ia32_AddrModeD);
706         set_ia32_am_flavour(new_op, ia32_B);
707         set_ia32_ls_mode(new_op, mode);
708         set_ia32_frame_ent(new_op, ent);
709         set_ia32_use_frame(new_op);
710
711         DBG_OPT_SPILL2ST(irn, new_op);
712
713         proj = new_rd_Proj(env->dbg, env->irg, env->block, new_op, mode_M, 0);
714
715         if (sched_point) {
716                 sched_add_after(sched_point, new_op);
717                 sched_add_after(new_op, proj);
718
719                 sched_remove(irn);
720         }
721
722         SET_IA32_ORIG_NODE(new_op, ia32_get_old_node_name(env->cg, new_op));
723
724         exchange(irn, proj);
725 }
726
727 /**
728  * Fix the mode of Spill/Reload
729  */
730 static ir_mode *fix_spill_mode(ia32_code_gen_t *cg, ir_mode *mode)
731 {
732         if (mode_is_float(mode)) {
733                 if (USE_SSE2(cg))
734                         mode = mode_D;
735                 else
736                         mode = mode_E;
737         }
738         else
739                 mode = mode_Is;
740         return mode;
741 }
742
743 /**
744  * Block-Walker: Calls the transform functions Spill and Reload.
745  */
746 static void ia32_after_ra_walker(ir_node *block, void *env) {
747         ir_node *node, *prev;
748         ia32_code_gen_t *cg = env;
749         ia32_transform_env_t tenv;
750
751         tenv.block = block;
752         tenv.irg   = current_ir_graph;
753         tenv.cg    = cg;
754         DEBUG_ONLY(tenv.mod = cg->mod;)
755
756         /* beware: the schedule is changed here */
757         for (node = sched_last(block); !sched_is_begin(node); node = prev) {
758                 prev = sched_prev(node);
759                 if (be_is_Reload(node)) {
760                         /* we always reload the whole register  */
761                         tenv.dbg  = get_irn_dbg_info(node);
762                         tenv.irn  = node;
763                         tenv.mode = fix_spill_mode(cg, get_irn_mode(node));
764                         transform_to_Load(&tenv);
765                 }
766                 else if (be_is_Spill(node)) {
767                         /* we always spill the whole register  */
768                         tenv.dbg  = get_irn_dbg_info(node);
769                         tenv.irn  = node;
770                         tenv.mode = fix_spill_mode(cg, get_irn_mode(be_get_Spill_context(node)));
771                         transform_to_Store(&tenv);
772                 }
773         }
774 }
775
776 /**
777  * We transform Spill and Reload here. This needs to be done before
778  * stack biasing otherwise we would miss the corrected offset for these nodes.
779  *
780  * If x87 instruction should be emitted, run the x87 simulator and patch
781  * the virtual instructions. This must obviously be done after register allocation.
782  */
783 static void ia32_after_ra(void *self) {
784         ia32_code_gen_t *cg = self;
785         irg_block_walk_graph(cg->irg, NULL, ia32_after_ra_walker, self);
786
787         /* if we do x87 code generation, rewrite all the virtual instructions and registers */
788         if (cg->used_fp == fp_x87) {
789                 x87_simulate_graph(cg->arch_env, cg->irg, cg->blk_sched);
790         }
791 }
792
793
794 /**
795  * Emits the code, closes the output file and frees
796  * the code generator interface.
797  */
798 static void ia32_codegen(void *self) {
799         ia32_code_gen_t *cg = self;
800         ir_graph        *irg = cg->irg;
801
802         ia32_finish_irg(irg, cg);
803         be_dump(irg, "-finished", dump_ir_block_graph_sched);
804         ia32_gen_routine(cg->isa->out, irg, cg);
805
806         cur_reg_set = NULL;
807
808         /* remove it from the isa */
809         cg->isa->cg = NULL;
810
811         /* de-allocate code generator */
812         del_set(cg->reg_set);
813         free(self);
814
815 }
816
817 static void *ia32_cg_init(const be_irg_t *birg);
818
819 static const arch_code_generator_if_t ia32_code_gen_if = {
820         ia32_cg_init,
821         NULL,                /* before abi introduce hook */
822         ia32_prepare_graph,
823         ia32_before_sched,   /* before scheduling hook */
824         ia32_before_ra,      /* before register allocation hook */
825         ia32_after_ra,       /* after register allocation hook */
826         ia32_codegen         /* emit && done */
827 };
828
829 /**
830  * Initializes a IA32 code generator.
831  */
832 static void *ia32_cg_init(const be_irg_t *birg) {
833         ia32_isa_t      *isa = (ia32_isa_t *)birg->main_env->arch_env->isa;
834         ia32_code_gen_t *cg  = xcalloc(1, sizeof(*cg));
835
836         cg->impl      = &ia32_code_gen_if;
837         cg->irg       = birg->irg;
838         cg->reg_set   = new_set(ia32_cmp_irn_reg_assoc, 1024);
839         cg->arch_env  = birg->main_env->arch_env;
840         cg->isa       = isa;
841         cg->birg      = birg;
842         cg->blk_sched = NULL;
843         cg->fp_to_gp  = NULL;
844         cg->gp_to_fp  = NULL;
845         cg->fp_kind   = isa->fp_kind;
846         cg->used_fp   = fp_none;
847
848         FIRM_DBG_REGISTER(cg->mod, "firm.be.ia32.cg");
849
850         /* copy optimizations from isa for easier access */
851         cg->opt = isa->opt;
852
853         /* enter it */
854         isa->cg = cg;
855
856 #ifndef NDEBUG
857         if (isa->name_obst_size) {
858                 //printf("freed %d bytes from name obst\n", isa->name_obst_size);
859                 isa->name_obst_size = 0;
860                 obstack_free(isa->name_obst, NULL);
861                 obstack_init(isa->name_obst);
862         }
863 #endif /* NDEBUG */
864
865         isa->num_codegens++;
866
867         if (isa->num_codegens > 1)
868                 cg->emit_decls = 0;
869         else
870                 cg->emit_decls = 1;
871
872         cur_reg_set = cg->reg_set;
873
874         ia32_irn_ops.cg = cg;
875
876         return (arch_code_generator_t *)cg;
877 }
878
879
880
881 /*****************************************************************
882  *  ____             _                  _   _____  _____
883  * |  _ \           | |                | | |_   _|/ ____|  /\
884  * | |_) | __ _  ___| | _____ _ __   __| |   | | | (___   /  \
885  * |  _ < / _` |/ __| |/ / _ \ '_ \ / _` |   | |  \___ \ / /\ \
886  * | |_) | (_| | (__|   <  __/ | | | (_| |  _| |_ ____) / ____ \
887  * |____/ \__,_|\___|_|\_\___|_| |_|\__,_| |_____|_____/_/    \_\
888  *
889  *****************************************************************/
890
891 /**
892  * The template that generates a new ISA object.
893  * Note that this template can be changed by command line
894  * arguments.
895  */
896 static ia32_isa_t ia32_isa_template = {
897         &ia32_isa_if,            /* isa interface implementation */
898         &ia32_gp_regs[REG_ESP],  /* stack pointer register */
899         &ia32_gp_regs[REG_EBP],  /* base pointer register */
900         -1,                      /* stack direction */
901         0,                       /* number of code generator objects so far */
902         NULL,                    /* 16bit register names */
903         NULL,                    /* 8bit register names */
904         NULL,                    /* types */
905         NULL,                    /* tv_ents */
906         (0 |
907         IA32_OPT_DOAM      |     /* optimize address mode                            default: on  */
908         IA32_OPT_PLACECNST |     /* place constants immediately before instructions, default: on  */
909         IA32_OPT_IMMOPS    |     /* operations can use immediates,                   default: on  */
910         IA32_OPT_EXTBB),         /* use extended basic block scheduling,             default: on  */
911         arch_pentium_4,          /* instruction architecture */
912         arch_pentium_4,          /* optimize for architecture */
913         fp_sse2,                 /* use sse2 unit */
914         NULL,                    /* current code generator */
915 #ifndef NDEBUG
916         NULL,                    /* name obstack */
917         0                        /* name obst size */
918 #endif
919 };
920
921 /**
922  * Initializes the backend ISA.
923  */
924 static void *ia32_init(FILE *file_handle) {
925         static int inited = 0;
926         ia32_isa_t *isa;
927
928         if (inited)
929                 return NULL;
930
931         isa = xmalloc(sizeof(*isa));
932         memcpy(isa, &ia32_isa_template, sizeof(*isa));
933
934         ia32_register_init(isa);
935         ia32_create_opcodes();
936         ia32_register_copy_attr_func();
937
938         isa->regs_16bit = pmap_create();
939         isa->regs_8bit  = pmap_create();
940         isa->types      = pmap_create();
941         isa->tv_ent     = pmap_create();
942         isa->out        = file_handle;
943
944         ia32_build_16bit_reg_map(isa->regs_16bit);
945         ia32_build_8bit_reg_map(isa->regs_8bit);
946
947         /* patch register names of x87 registers */
948         if (USE_x87(isa)) {
949           ia32_st_regs[0].name = "st";
950           ia32_st_regs[1].name = "st(1)";
951           ia32_st_regs[2].name = "st(2)";
952           ia32_st_regs[3].name = "st(3)";
953           ia32_st_regs[4].name = "st(4)";
954           ia32_st_regs[5].name = "st(5)";
955           ia32_st_regs[6].name = "st(6)";
956           ia32_st_regs[7].name = "st(7)";
957         }
958
959 #ifndef NDEBUG
960         isa->name_obst = xmalloc(sizeof(*isa->name_obst));
961         obstack_init(isa->name_obst);
962         isa->name_obst_size = 0;
963 #endif /* NDEBUG */
964
965         fprintf(isa->out, "\t.intel_syntax\n");
966
967         inited = 1;
968
969         return isa;
970 }
971
972
973
974 /**
975  * Closes the output file and frees the ISA structure.
976  */
977 static void ia32_done(void *self) {
978         ia32_isa_t *isa = self;
979
980         /* emit now all global declarations */
981         ia32_gen_decls(isa->out);
982
983         pmap_destroy(isa->regs_16bit);
984         pmap_destroy(isa->regs_8bit);
985         pmap_destroy(isa->tv_ent);
986         pmap_destroy(isa->types);
987
988 #ifndef NDEBUG
989         //printf("name obst size = %d bytes\n", isa->name_obst_size);
990         obstack_free(isa->name_obst, NULL);
991 #endif /* NDEBUG */
992
993         free(self);
994 }
995
996
997 /**
998  * Return the number of register classes for this architecture.
999  * We report always these:
1000  *  - the general purpose registers
1001  *  - the floating point register set (depending on the unit used for FP)
1002  *  - MMX/SSE registers (currently not supported)
1003  */
1004 static int ia32_get_n_reg_class(const void *self) {
1005         return 2;
1006 }
1007
1008 /**
1009  * Return the register class for index i.
1010  */
1011 static const arch_register_class_t *ia32_get_reg_class(const void *self, int i) {
1012         const ia32_isa_t *isa = self;
1013         assert(i >= 0 && i < 2 && "Invalid ia32 register class requested.");
1014         if (i == 0)
1015                 return &ia32_reg_classes[CLASS_ia32_gp];
1016         return USE_SSE2(isa) ? &ia32_reg_classes[CLASS_ia32_xmm] : &ia32_reg_classes[CLASS_ia32_vfp];
1017 }
1018
1019 /**
1020  * Get the register class which shall be used to store a value of a given mode.
1021  * @param self The this pointer.
1022  * @param mode The mode in question.
1023  * @return A register class which can hold values of the given mode.
1024  */
1025 const arch_register_class_t *ia32_get_reg_class_for_mode(const void *self, const ir_mode *mode) {
1026         const ia32_isa_t *isa = self;
1027         if (mode_is_float(mode)) {
1028                 return USE_SSE2(isa) ? &ia32_reg_classes[CLASS_ia32_xmm] : &ia32_reg_classes[CLASS_ia32_vfp];
1029         }
1030         else
1031                 return &ia32_reg_classes[CLASS_ia32_gp];
1032 }
1033
1034 /**
1035  * Get the ABI restrictions for procedure calls.
1036  * @param self        The this pointer.
1037  * @param method_type The type of the method (procedure) in question.
1038  * @param abi         The abi object to be modified
1039  */
1040 static void ia32_get_call_abi(const void *self, ir_type *method_type, be_abi_call_t *abi) {
1041         const ia32_isa_t *isa = self;
1042         ir_type  *tp;
1043         ir_mode  *mode;
1044         unsigned  cc        = get_method_calling_convention(method_type);
1045         int       n         = get_method_n_params(method_type);
1046         int       biggest_n = -1;
1047         int       stack_idx = 0;
1048         int       i, ignore_1, ignore_2;
1049         ir_mode **modes;
1050         const arch_register_t *reg;
1051         be_abi_call_flags_t call_flags = be_abi_call_get_flags(abi);
1052
1053         /* set abi flags for calls */
1054         call_flags.bits.left_to_right         = 0;  /* always last arg first on stack */
1055         call_flags.bits.store_args_sequential = 0;  /* use stores instead of push */
1056         /* call_flags.bits.try_omit_fp                 not changed: can handle both settings */
1057         call_flags.bits.fp_free               = 0;  /* the frame pointer is fixed in IA32 */
1058         call_flags.bits.call_has_imm          = 1;  /* IA32 calls can have immediate address */
1059
1060         /* set stack parameter passing style */
1061         be_abi_call_set_flags(abi, call_flags, &ia32_abi_callbacks);
1062
1063         /* collect the mode for each type */
1064         modes = alloca(n * sizeof(modes[0]));
1065
1066         for (i = 0; i < n; i++) {
1067                 tp       = get_method_param_type(method_type, i);
1068                 modes[i] = get_type_mode(tp);
1069         }
1070
1071         /* set register parameters  */
1072         if (cc & cc_reg_param) {
1073                 /* determine the number of parameters passed via registers */
1074                 biggest_n = ia32_get_n_regparam_class(n, modes, &ignore_1, &ignore_2);
1075
1076                 /* loop over all parameters and set the register requirements */
1077                 for (i = 0; i <= biggest_n; i++) {
1078                         reg = ia32_get_RegParam_reg(n, modes, i, cc);
1079                         assert(reg && "kaputt");
1080                         be_abi_call_param_reg(abi, i, reg);
1081                 }
1082
1083                 stack_idx = i;
1084         }
1085
1086
1087         /* set stack parameters */
1088         for (i = stack_idx; i < n; i++) {
1089                 be_abi_call_param_stack(abi, i, 1, 0, 0);
1090         }
1091
1092
1093         /* set return registers */
1094         n = get_method_n_ress(method_type);
1095
1096         assert(n <= 2 && "more than two results not supported");
1097
1098         /* In case of 64bit returns, we will have two 32bit values */
1099         if (n == 2) {
1100                 tp   = get_method_res_type(method_type, 0);
1101                 mode = get_type_mode(tp);
1102
1103                 assert(!mode_is_float(mode) && "two FP results not supported");
1104
1105                 tp   = get_method_res_type(method_type, 1);
1106                 mode = get_type_mode(tp);
1107
1108                 assert(!mode_is_float(mode) && "two FP results not supported");
1109
1110                 be_abi_call_res_reg(abi, 0, &ia32_gp_regs[REG_EAX]);
1111                 be_abi_call_res_reg(abi, 1, &ia32_gp_regs[REG_EDX]);
1112         }
1113         else if (n == 1) {
1114                 const arch_register_t *reg;
1115
1116                 tp   = get_method_res_type(method_type, 0);
1117                 assert(is_atomic_type(tp));
1118                 mode = get_type_mode(tp);
1119
1120                 reg = mode_is_float(mode) ?
1121                         (USE_SSE2(isa) ? &ia32_xmm_regs[REG_XMM0] : &ia32_vfp_regs[REG_VF0]) :
1122                         &ia32_gp_regs[REG_EAX];
1123
1124                 be_abi_call_res_reg(abi, 0, reg);
1125         }
1126 }
1127
1128
1129 static const void *ia32_get_irn_ops(const arch_irn_handler_t *self, const ir_node *irn) {
1130         return &ia32_irn_ops;
1131 }
1132
1133 const arch_irn_handler_t ia32_irn_handler = {
1134         ia32_get_irn_ops
1135 };
1136
1137 const arch_irn_handler_t *ia32_get_irn_handler(const void *self) {
1138         return &ia32_irn_handler;
1139 }
1140
1141 int ia32_to_appear_in_schedule(void *block_env, const ir_node *irn) {
1142         return is_ia32_irn(irn);
1143 }
1144
1145 /**
1146  * Initializes the code generator interface.
1147  */
1148 static const arch_code_generator_if_t *ia32_get_code_generator_if(void *self) {
1149         return &ia32_code_gen_if;
1150 }
1151
1152 list_sched_selector_t ia32_sched_selector;
1153
1154 /**
1155  * Returns the reg_pressure scheduler with to_appear_in_schedule() overloaded
1156  */
1157 static const list_sched_selector_t *ia32_get_list_sched_selector(const void *self) {
1158 //      memcpy(&ia32_sched_selector, reg_pressure_selector, sizeof(list_sched_selector_t));
1159         memcpy(&ia32_sched_selector, trivial_selector, sizeof(list_sched_selector_t));
1160         ia32_sched_selector.to_appear_in_schedule = ia32_to_appear_in_schedule;
1161         return &ia32_sched_selector;
1162 }
1163
1164 /**
1165  * Returns the necessary byte alignment for storing a register of given class.
1166  */
1167 static int ia32_get_reg_class_alignment(const void *self, const arch_register_class_t *cls) {
1168         ir_mode *mode = arch_register_class_mode(cls);
1169         int bytes     = get_mode_size_bytes(mode);
1170
1171         if (mode_is_float(mode) && bytes > 8)
1172                 return 16;
1173         return bytes;
1174 }
1175
1176 #ifdef WITH_LIBCORE
1177
1178 /* instruction set architectures. */
1179 static const lc_opt_enum_int_items_t arch_items[] = {
1180         { "386",        arch_i386, },
1181         { "486",        arch_i486, },
1182         { "pentium",    arch_pentium, },
1183         { "586",        arch_pentium, },
1184         { "pentiumpro", arch_pentium_pro, },
1185         { "686",        arch_pentium_pro, },
1186         { "pentiummmx", arch_pentium_mmx, },
1187         { "pentium2",   arch_pentium_2, },
1188         { "p2",         arch_pentium_2, },
1189         { "pentium3",   arch_pentium_3, },
1190         { "p3",         arch_pentium_3, },
1191         { "pentium4",   arch_pentium_4, },
1192         { "p4",         arch_pentium_4, },
1193         { "pentiumm",   arch_pentium_m, },
1194         { "pm",         arch_pentium_m, },
1195         { "core",       arch_core, },
1196         { "k6",         arch_k6, },
1197         { "athlon",     arch_athlon, },
1198         { "athlon64",   arch_athlon_64, },
1199         { "opteron",    arch_opteron, },
1200         { NULL,         0 }
1201 };
1202
1203 static lc_opt_enum_int_var_t arch_var = {
1204         &ia32_isa_template.arch, arch_items
1205 };
1206
1207 static lc_opt_enum_int_var_t opt_arch_var = {
1208         &ia32_isa_template.opt_arch, arch_items
1209 };
1210
1211 static const lc_opt_enum_int_items_t fp_unit_items[] = {
1212         { "x87" ,    fp_x87 },
1213         { "sse2",    fp_sse2 },
1214         { NULL,      0 }
1215 };
1216
1217 static lc_opt_enum_int_var_t fp_unit_var = {
1218         &ia32_isa_template.fp_kind, fp_unit_items
1219 };
1220
1221 static const lc_opt_table_entry_t ia32_options[] = {
1222         LC_OPT_ENT_ENUM_INT("arch",   "select the instruction architecture", &arch_var),
1223         LC_OPT_ENT_ENUM_INT("opt",    "optimize for instruction architecture", &opt_arch_var),
1224         LC_OPT_ENT_ENUM_INT("fpunit", "select the floating point unit", &fp_unit_var),
1225         LC_OPT_ENT_BIT("incdec", "optimize for inc/dec", &ia32_isa_template.opt, IA32_OPT_INCDEC),
1226         LC_OPT_ENT_NEGBIT("noaddrmode", "do not use address mode", &ia32_isa_template.opt, IA32_OPT_DOAM),
1227         LC_OPT_ENT_NEGBIT("noplacecnst", "do not place constants", &ia32_isa_template.opt, IA32_OPT_PLACECNST),
1228         LC_OPT_ENT_NEGBIT("noimmop", "no operations with immediates", &ia32_isa_template.opt, IA32_OPT_IMMOPS),
1229         LC_OPT_ENT_NEGBIT("noextbb", "do not use extended basic block scheduling", &ia32_isa_template.opt, IA32_OPT_EXTBB),
1230         { NULL }
1231 };
1232
1233 /**
1234  * Register command line options for the ia32 backend.
1235  *
1236  * Options so far:
1237  *
1238  * ia32-arch=arch    create instruction for arch
1239  * ia32-opt=arch     optimize for run on arch
1240  * ia32-fpunit=unit  select floating point unit (x87 or SSE2)
1241  * ia32-incdec       optimize for inc/dec
1242  * ia32-noaddrmode   do not use address mode
1243  * ia32-noplacecnst  do not place constants,
1244  * ia32-noimmop      no operations with immediates
1245  * ia32-noextbb      do not use extended basic block scheduling
1246  */
1247 static void ia32_register_options(lc_opt_entry_t *ent)
1248 {
1249         lc_opt_entry_t *be_grp_ia32 = lc_opt_get_grp(ent, "ia32");
1250         lc_opt_add_table(be_grp_ia32, ia32_options);
1251 }
1252 #endif /* WITH_LIBCORE */
1253
1254 const arch_isa_if_t ia32_isa_if = {
1255         ia32_init,
1256         ia32_done,
1257         ia32_get_n_reg_class,
1258         ia32_get_reg_class,
1259         ia32_get_reg_class_for_mode,
1260         ia32_get_call_abi,
1261         ia32_get_irn_handler,
1262         ia32_get_code_generator_if,
1263         ia32_get_list_sched_selector,
1264         ia32_get_reg_class_alignment,
1265 #ifdef WITH_LIBCORE
1266         ia32_register_options
1267 #endif
1268 };