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