pin prolog/epilog nodes
[libfirm] / ir / be / ia32 / bearch_ia32.c
index 6f10e6c..3d6973a 100644 (file)
@@ -80,7 +80,6 @@
 #include "ia32_common_transform.h"
 #include "ia32_transform.h"
 #include "ia32_emitter.h"
-#include "ia32_map_regs.h"
 #include "ia32_optimize.h"
 #include "ia32_x87.h"
 #include "ia32_dbg_stat.h"
@@ -97,7 +96,7 @@ transformer_t be_transformer = TRANSFORMER_DEFAULT;
 
 DEBUG_ONLY(static firm_dbg_module_t *dbg = NULL;)
 
-ir_mode         *mode_fpcw       = NULL;
+ir_mode         *ia32_mode_fpcw       = NULL;
 
 /** The current omit-fp state */
 static unsigned ia32_curr_fp_ommitted  = 0;
@@ -147,28 +146,28 @@ ir_node *ia32_new_NoReg_gp(ir_graph *irg)
 {
        ia32_irg_data_t *irg_data = ia32_get_irg_data(irg);
        return create_const(irg, &irg_data->noreg_gp, new_bd_ia32_NoReg_GP,
-                           &ia32_gp_regs[REG_GP_NOREG]);
+                           &ia32_registers[REG_GP_NOREG]);
 }
 
 ir_node *ia32_new_NoReg_vfp(ir_graph *irg)
 {
        ia32_irg_data_t *irg_data = ia32_get_irg_data(irg);
        return create_const(irg, &irg_data->noreg_vfp, new_bd_ia32_NoReg_VFP,
-                           &ia32_vfp_regs[REG_VFP_NOREG]);
+                           &ia32_registers[REG_VFP_NOREG]);
 }
 
 ir_node *ia32_new_NoReg_xmm(ir_graph *irg)
 {
        ia32_irg_data_t *irg_data = ia32_get_irg_data(irg);
        return create_const(irg, &irg_data->noreg_xmm, new_bd_ia32_NoReg_XMM,
-                           &ia32_xmm_regs[REG_XMM_NOREG]);
+                           &ia32_registers[REG_XMM_NOREG]);
 }
 
 ir_node *ia32_new_Fpu_truncate(ir_graph *irg)
 {
        ia32_irg_data_t *irg_data = ia32_get_irg_data(irg);
        return create_const(irg, &irg_data->fpu_trunc_mode, new_bd_ia32_ChangeCW,
-                        &ia32_fp_cw_regs[REG_FPCW]);
+                        &ia32_registers[REG_FPCW]);
 }
 
 
@@ -193,7 +192,7 @@ static ir_node *ia32_get_admissible_noreg(ir_node *irn, int pos)
 
 static arch_irn_class_t ia32_classify(const ir_node *irn)
 {
-       arch_irn_class_t classification = 0;
+       arch_irn_class_t classification = arch_irn_class_none;
 
        assert(is_ia32_irn(irn));
 
@@ -259,6 +258,11 @@ static int ia32_get_sp_bias(const ir_node *node)
        if (is_ia32_Pop(node) || is_ia32_PopMem(node))
                return -4;
 
+       if (is_ia32_Leave(node) || (be_is_Copy(node)
+           && arch_get_irn_register(node) == &ia32_registers[REG_ESP])) {
+               return SP_BIAS_RESET;
+       }
+
        return 0;
 }
 
@@ -276,7 +280,7 @@ static int ia32_get_sp_bias(const ir_node *node)
  */
 static const arch_register_t *ia32_abi_prologue(void *self, ir_node **mem, pmap *reg_map, int *stack_bias)
 {
-       ia32_abi_env_t   *env      = self;
+       ia32_abi_env_t   *env      = (ia32_abi_env_t*)self;
        ir_graph         *irg      = env->irg;
        const arch_env_t *arch_env = be_get_irg_arch_env(irg);
 
@@ -294,8 +298,10 @@ static const arch_register_t *ia32_abi_prologue(void *self, ir_node **mem, pmap
 
                /* push ebp */
                push    = new_bd_ia32_Push(NULL, bl, noreg, noreg, *mem, curr_bp, curr_sp);
+               arch_irn_add_flags(push, arch_irn_flags_prolog);
                curr_sp = new_r_Proj(push, get_irn_mode(curr_sp), pn_ia32_Push_stack);
                *mem    = new_r_Proj(push, mode_M, pn_ia32_Push_M);
+               set_irn_pinned(push, op_pin_state_pinned);
 
                /* the push must have SP out register */
                arch_set_irn_register(curr_sp, arch_env->sp);
@@ -305,11 +311,14 @@ static const arch_register_t *ia32_abi_prologue(void *self, ir_node **mem, pmap
 
                /* move esp to ebp */
                curr_bp = be_new_Copy(arch_env->bp->reg_class, bl, curr_sp);
+               arch_irn_add_flags(curr_bp, arch_irn_flags_prolog);
                be_set_constr_single_reg_out(curr_bp, 0, arch_env->bp,
                                             arch_register_req_type_ignore);
+               set_irn_pinned(curr_bp, op_pin_state_pinned);
 
                /* beware: the copy must be done before any other sp use */
                curr_sp = be_new_CopyKeep_single(arch_env->sp->reg_class, bl, curr_sp, curr_bp, get_irn_mode(curr_sp));
+               arch_irn_add_flags(curr_sp, arch_irn_flags_prolog);
                be_set_constr_single_reg_out(curr_sp, 0, arch_env->sp,
                                                     arch_register_req_type_produces_sp);
 
@@ -334,7 +343,7 @@ static const arch_register_t *ia32_abi_prologue(void *self, ir_node **mem, pmap
  */
 static void ia32_abi_epilogue(void *self, ir_node *bl, ir_node **mem, pmap *reg_map)
 {
-       ia32_abi_env_t   *env      = self;
+       ia32_abi_env_t   *env      = (ia32_abi_env_t*)self;
        const arch_env_t *arch_env = be_get_irg_arch_env(env->irg);
        ir_node          *curr_sp  = be_abi_reg_map_get(reg_map, arch_env->sp);
        ir_node          *curr_bp  = be_abi_reg_map_get(reg_map, arch_env->bp);
@@ -342,6 +351,8 @@ static void ia32_abi_epilogue(void *self, ir_node *bl, ir_node **mem, pmap *reg_
        if (env->flags.try_omit_fp) {
                /* simply remove the stack frame here */
                curr_sp = be_new_IncSP(arch_env->sp, bl, curr_sp, BE_STACK_FRAME_SIZE_SHRINK, 0);
+               arch_irn_add_flags(curr_sp, arch_irn_flags_epilog);
+               set_irn_pinned(curr_sp, op_pin_state_pinned);
        } else {
                ir_mode *mode_bp = arch_env->bp->reg_class->mode;
 
@@ -352,23 +363,25 @@ static void ia32_abi_epilogue(void *self, ir_node *bl, ir_node **mem, pmap *reg_
                        leave   = new_bd_ia32_Leave(NULL, bl, curr_bp);
                        curr_bp = new_r_Proj(leave, mode_bp, pn_ia32_Leave_frame);
                        curr_sp = new_r_Proj(leave, get_irn_mode(curr_sp), pn_ia32_Leave_stack);
+                       arch_irn_add_flags(leave, arch_irn_flags_epilog);
+                       set_irn_pinned(leave, op_pin_state_pinned);
                } else {
                        ir_node *pop;
 
-                       /* the old SP is not needed anymore (kill the proj) */
-                       assert(is_Proj(curr_sp));
-                       kill_node(curr_sp);
-
                        /* copy ebp to esp */
                        curr_sp = be_new_Copy(&ia32_reg_classes[CLASS_ia32_gp], bl, curr_bp);
                        arch_set_irn_register(curr_sp, arch_env->sp);
                        be_set_constr_single_reg_out(curr_sp, 0, arch_env->sp,
                                                         arch_register_req_type_ignore);
+                       arch_irn_add_flags(curr_sp, arch_irn_flags_epilog);
+                       set_irn_pinned(curr_sp, op_pin_state_pinned);
 
                        /* pop ebp */
                        pop     = new_bd_ia32_PopEbp(NULL, bl, *mem, curr_sp);
                        curr_bp = new_r_Proj(pop, mode_bp, pn_ia32_Pop_res);
                        curr_sp = new_r_Proj(pop, get_irn_mode(curr_sp), pn_ia32_Pop_stack);
+                       arch_irn_add_flags(pop, arch_irn_flags_epilog);
+                       set_irn_pinned(pop, op_pin_state_pinned);
 
                        *mem = new_r_Proj(pop, mode_M, pn_ia32_Pop_M);
                }
@@ -440,7 +453,7 @@ static void ia32_build_between_type(void)
  */
 static ir_type *ia32_abi_get_between_type(void *self)
 {
-       ia32_abi_env_t *env = self;
+       ia32_abi_env_t *env = (ia32_abi_env_t*)self;
 
        ia32_build_between_type();
        return env->flags.try_omit_fp ? omit_fp_between_type : between_type;
@@ -558,7 +571,7 @@ static arch_inverse_t *ia32_get_inverse(const ir_node *irn, int i, arch_inverse_
        mode     = get_irn_mode(irn);
        irn_mode = get_irn_mode(irn);
        noreg    = get_irn_n(irn, 0);
-       nomem    = new_NoMem();
+       nomem    = new_r_NoMem(irg);
        dbg      = get_irn_dbg_info(irn);
 
        /* initialize structure */
@@ -791,10 +804,11 @@ static const arch_irn_ops_t ia32_irn_ops = {
 };
 
 static ir_entity *mcount = NULL;
+static int gprof = 0;
 
 static void ia32_before_abi(ir_graph *irg)
 {
-       if (be_get_irg_options(irg)->gprof) {
+       if (gprof) {
                if (mcount == NULL) {
                        ir_type *tp = new_type_method(0, 0);
                        ident   *id = new_id_from_str("mcount");
@@ -851,9 +865,10 @@ static void ia32_prepare_graph(ir_graph *irg)
                dump_ir_graph(irg, "place");
 }
 
-ir_node *turn_back_am(ir_node *node)
+ir_node *ia32_turn_back_am(ir_node *node)
 {
        dbg_info *dbgi  = get_irn_dbg_info(node);
+       ir_graph *irg   = get_irn_irg(node);
        ir_node  *block = get_nodes_block(node);
        ir_node  *base  = get_irn_n(node, n_ia32_base);
        ir_node  *index = get_irn_n(node, n_ia32_index);
@@ -866,7 +881,7 @@ ir_node *turn_back_am(ir_node *node)
        ia32_copy_am_attrs(load, node);
        if (is_ia32_is_reload(node))
                set_ia32_is_reload(load);
-       set_irn_n(node, n_ia32_mem, new_NoMem());
+       set_irn_n(node, n_ia32_mem, new_r_NoMem(irg));
 
        switch (get_ia32_am_support(node)) {
                case ia32_am_unary:
@@ -928,7 +943,7 @@ static ir_node *flags_remat(ir_node *node, ir_node *after)
        type = get_ia32_op_type(node);
        switch (type) {
                case ia32_AddrModeS:
-                       turn_back_am(node);
+                       ia32_turn_back_am(node);
                        break;
 
                case ia32_AddrModeD:
@@ -1033,7 +1048,7 @@ static void transform_to_Store(ir_node *node)
        const ir_node *spillval = get_irn_n(node, be_pos_Spill_val);
        ir_mode *mode  = get_spill_mode(spillval);
        ir_node *noreg = ia32_new_NoReg_gp(irg);
-       ir_node *nomem = new_NoMem();
+       ir_node *nomem = new_r_NoMem(irg);
        ir_node *ptr   = get_irg_frame(irg);
        ir_node *val   = get_irn_n(node, be_pos_Spill_val);
        ir_node *store;
@@ -1101,7 +1116,7 @@ static ir_node *create_pop(ir_node *node, ir_node *schedpoint, ir_node *sp, ir_e
        ir_node  *noreg = ia32_new_NoReg_gp(irg);
        ir_node  *frame = get_irg_frame(irg);
 
-       ir_node *pop = new_bd_ia32_PopMem(dbg, block, frame, noreg, new_NoMem(), sp);
+       ir_node *pop = new_bd_ia32_PopMem(dbg, block, frame, noreg, new_r_NoMem(irg), sp);
 
        set_ia32_frame_ent(pop, ent);
        set_ia32_use_frame(pop);
@@ -1118,7 +1133,7 @@ static ir_node* create_spproj(ir_node *node, ir_node *pred, int pos)
 {
        dbg_info *dbg = get_irn_dbg_info(node);
        ir_mode *spmode = mode_Iu;
-       const arch_register_t *spreg = &ia32_gp_regs[REG_ESP];
+       const arch_register_t *spreg = &ia32_registers[REG_ESP];
        ir_node *sp;
 
        sp = new_rd_Proj(dbg, pred, spmode, pos);
@@ -1136,7 +1151,7 @@ static void transform_MemPerm(ir_node *node)
 {
        ir_node         *block = get_nodes_block(node);
        ir_graph        *irg   = get_irn_irg(node);
-       ir_node         *sp    = be_abi_get_ignore_irn(be_get_irg_abi(irg), &ia32_gp_regs[REG_ESP]);
+       ir_node         *sp    = be_abi_get_ignore_irn(be_get_irg_abi(irg), &ia32_registers[REG_ESP]);
        int              arity = be_get_MemPerm_entity_arity(node);
        ir_node        **pops  = ALLOCAN(ir_node*, arity);
        ir_node         *in[1];
@@ -1169,7 +1184,7 @@ static void transform_MemPerm(ir_node *node)
                        sp = create_spproj(node, push, pn_ia32_Push_stack);
                }
 
-               set_irn_n(node, i, new_Bad());
+               set_irn_n(node, i, new_r_Bad(irg));
        }
 
        /* create pops */
@@ -1217,7 +1232,7 @@ static void transform_MemPerm(ir_node *node)
        /* remove memperm */
        arity = get_irn_arity(node);
        for (i = 0; i < arity; ++i) {
-               set_irn_n(node, i, new_Bad());
+               set_irn_n(node, i, new_r_Bad(irg));
        }
        sched_remove(node);
 }
@@ -1249,7 +1264,7 @@ static void ia32_after_ra_walker(ir_node *block, void *env)
  */
 static void ia32_collect_frame_entity_nodes(ir_node *node, void *data)
 {
-       be_fec_env_t  *env = data;
+       be_fec_env_t  *env = (be_fec_env_t*)data;
        const ir_mode *mode;
        int            align;
 
@@ -1324,11 +1339,13 @@ need_stackent:
  */
 static void ia32_after_ra(ir_graph *irg)
 {
-       be_fec_env_t *fec_env = be_new_frame_entity_coalescer(irg);
+       be_stack_layout_t *stack_layout = be_get_irg_stack_layout(irg);
+       bool               at_begin     = stack_layout->sp_relative ? true : false;
+       be_fec_env_t      *fec_env      = be_new_frame_entity_coalescer(irg);
 
        /* create and coalesce frame entities */
        irg_walk_graph(irg, NULL, ia32_collect_frame_entity_nodes, fec_env);
-       be_assign_entities(fec_env, ia32_set_frame_entity);
+       be_assign_entities(fec_env, ia32_set_frame_entity, at_begin);
        be_free_frame_entity_coalescer(fec_env);
 
        irg_block_walk_graph(irg, NULL, ia32_after_ra_walker, NULL);
@@ -1347,7 +1364,7 @@ static void ia32_finish(ir_graph *irg)
 
        /* we might have to rewrite x87 virtual registers */
        if (irg_data->do_x87_sim) {
-               x87_simulate_graph(irg);
+               ia32_x87_simulate_graph(irg);
        }
 
        /* do peephole optimisations */
@@ -1386,7 +1403,6 @@ static ir_node *ia32_get_pic_base(ir_graph *irg)
        get_eip           = new_bd_ia32_GetEIP(NULL, block);
        irg_data->get_eip = get_eip;
 
-       be_dep_on_frame(get_eip);
        return get_eip;
 }
 
@@ -1400,7 +1416,7 @@ static void ia32_init_graph(ir_graph *irg)
 
        irg_data->dump = (be_get_irg_options(irg)->dump_flags & DUMP_BE) ? 1 : 0;
 
-       if (be_get_irg_options(irg)->gprof) {
+       if (gprof) {
                /* Linux gprof implementation needs base pointer */
                be_get_irg_options(irg)->omit_fp = 0;
        }
@@ -1423,17 +1439,17 @@ static const tarval_mode_info mo_integer = {
  */
 static void set_tarval_output_modes(void)
 {
-       int i;
+       size_t i;
 
-       for (i = get_irp_n_modes() - 1; i >= 0; --i) {
-               ir_mode *mode = get_irp_mode(i);
+       for (i = get_irp_n_modes(); i > 0;) {
+               ir_mode *mode = get_irp_mode(--i);
 
                if (mode_is_int(mode))
                        set_tarval_mode_output_option(mode, &mo_integer);
        }
 }
 
-const arch_isa_if_t ia32_isa_if;
+extern const arch_isa_if_t ia32_isa_if;
 
 /**
  * The template that generates a new ISA object.
@@ -1443,8 +1459,12 @@ const arch_isa_if_t ia32_isa_if;
 static ia32_isa_t ia32_isa_template = {
        {
                &ia32_isa_if,            /* isa interface implementation */
-               &ia32_gp_regs[REG_ESP],  /* stack pointer register */
-               &ia32_gp_regs[REG_EBP],  /* base pointer register */
+               N_IA32_REGISTERS,
+               ia32_registers,
+               N_IA32_CLASSES,
+               ia32_reg_classes,
+               &ia32_registers[REG_ESP],  /* stack pointer register */
+               &ia32_registers[REG_EBP],  /* base pointer register */
                &ia32_reg_classes[CLASS_ia32_gp],  /* static link pointer register class */
                -1,                      /* stack direction */
                2,                       /* power of two stack alignment, 2^2 == 4 */
@@ -1453,9 +1473,6 @@ static ia32_isa_t ia32_isa_template = {
                5,                       /* costs for a reload instruction */
                false,                   /* no custom abi handling */
        },
-       NULL,                    /* 16bit register names */
-       NULL,                    /* 8bit register names */
-       NULL,                    /* 8bit register names high */
        NULL,                    /* types */
        NULL,                    /* tv_ents */
        NULL,                    /* abstract machine */
@@ -1513,54 +1530,27 @@ static void init_asm_constraints(void)
  */
 static arch_env_t *ia32_init(FILE *file_handle)
 {
-       static int inited = 0;
-       ia32_isa_t *isa;
-       int        i, n;
-
-       if (inited)
-               return NULL;
-       inited = 1;
+       ia32_isa_t *isa = XMALLOC(ia32_isa_t);
 
        set_tarval_output_modes();
 
-       isa = XMALLOC(ia32_isa_t);
        memcpy(isa, &ia32_isa_template, sizeof(*isa));
 
-       if (mode_fpcw == NULL) {
-               mode_fpcw = new_ir_mode("Fpcw", irms_int_number, 16, 0, irma_none, 0);
+       if (ia32_mode_fpcw == NULL) {
+               ia32_mode_fpcw = new_ir_mode("Fpcw", irms_int_number, 16, 0, irma_none, 0);
        }
 
        ia32_register_init();
        ia32_create_opcodes(&ia32_irn_ops);
 
        be_emit_init(file_handle);
-       isa->regs_16bit     = pmap_create();
-       isa->regs_8bit      = pmap_create();
-       isa->regs_8bit_high = pmap_create();
        isa->types          = pmap_create();
        isa->tv_ent         = pmap_create();
        isa->cpu            = ia32_init_machine_description();
 
-       ia32_build_16bit_reg_map(isa->regs_16bit);
-       ia32_build_8bit_reg_map(isa->regs_8bit);
-       ia32_build_8bit_reg_map_high(isa->regs_8bit_high);
-
        /* enter the ISA object into the intrinsic environment */
        intrinsic_env.isa = isa;
 
-       /* emit asm includes */
-       n = get_irp_n_asms();
-       for (i = 0; i < n; ++i) {
-               be_emit_cstring("#APP\n");
-               be_emit_ident(get_irp_asm(i));
-               be_emit_cstring("\n#NO_APP\n");
-       }
-
-       /* needed for the debug support */
-       be_gas_emit_switch_section(GAS_SECTION_TEXT);
-       be_emit_irprintf("%stext0:\n", be_gas_get_private_prefix());
-       be_emit_write_line();
-
        return &isa->base;
 }
 
@@ -1571,14 +1561,11 @@ static arch_env_t *ia32_init(FILE *file_handle)
  */
 static void ia32_done(void *self)
 {
-       ia32_isa_t *isa = self;
+       ia32_isa_t *isa = (ia32_isa_t*)self;
 
        /* emit now all global declarations */
        be_gas_emit_decls(isa->base.main_env);
 
-       pmap_destroy(isa->regs_16bit);
-       pmap_destroy(isa->regs_8bit);
-       pmap_destroy(isa->regs_8bit_high);
        pmap_destroy(isa->tv_ent);
        pmap_destroy(isa->types);
 
@@ -1588,28 +1575,6 @@ static void ia32_done(void *self)
 }
 
 
-/**
- * Return the number of register classes for this architecture.
- * We report always these:
- *  - the general purpose registers
- *  - the SSE floating point register set
- *  - the virtual floating point registers
- *  - the SSE vector register set
- */
-static unsigned ia32_get_n_reg_class(void)
-{
-       return N_CLASSES;
-}
-
-/**
- * Return the register class for index i.
- */
-static const arch_register_class_t *ia32_get_reg_class(unsigned i)
-{
-       assert(i < N_CLASSES);
-       return &ia32_reg_classes[i];
-}
-
 /**
  * Get the register class which shall be used to store a value of a given mode.
  * @param self The this pointer.
@@ -1632,33 +1597,33 @@ static const arch_register_t *ia32_get_RegParam_reg(unsigned cc, unsigned nr,
                                                     const ir_mode *mode)
 {
        static const arch_register_t *gpreg_param_reg_fastcall[] = {
-               &ia32_gp_regs[REG_ECX],
-               &ia32_gp_regs[REG_EDX],
+               &ia32_registers[REG_ECX],
+               &ia32_registers[REG_EDX],
                NULL
        };
        static const unsigned MAXNUM_GPREG_ARGS = 3;
 
        static const arch_register_t *gpreg_param_reg_regparam[] = {
-               &ia32_gp_regs[REG_EAX],
-               &ia32_gp_regs[REG_EDX],
-               &ia32_gp_regs[REG_ECX]
+               &ia32_registers[REG_EAX],
+               &ia32_registers[REG_EDX],
+               &ia32_registers[REG_ECX]
        };
 
        static const arch_register_t *gpreg_param_reg_this[] = {
-               &ia32_gp_regs[REG_ECX],
+               &ia32_registers[REG_ECX],
                NULL,
                NULL
        };
 
        static const arch_register_t *fpreg_sse_param_reg_std[] = {
-               &ia32_xmm_regs[REG_XMM0],
-               &ia32_xmm_regs[REG_XMM1],
-               &ia32_xmm_regs[REG_XMM2],
-               &ia32_xmm_regs[REG_XMM3],
-               &ia32_xmm_regs[REG_XMM4],
-               &ia32_xmm_regs[REG_XMM5],
-               &ia32_xmm_regs[REG_XMM6],
-               &ia32_xmm_regs[REG_XMM7]
+               &ia32_registers[REG_XMM0],
+               &ia32_registers[REG_XMM1],
+               &ia32_registers[REG_XMM2],
+               &ia32_registers[REG_XMM3],
+               &ia32_registers[REG_XMM4],
+               &ia32_registers[REG_XMM5],
+               &ia32_registers[REG_XMM6],
+               &ia32_registers[REG_XMM7]
        };
 
        static const arch_register_t *fpreg_sse_param_reg_this[] = {
@@ -1804,8 +1769,8 @@ static void ia32_get_call_abi(const void *self, ir_type *method_type,
 
                assert(!mode_is_float(mode) && "mixed INT, FP results not supported");
 
-               be_abi_call_res_reg(abi, 0, &ia32_gp_regs[REG_EAX], ABI_CONTEXT_BOTH);
-               be_abi_call_res_reg(abi, 1, &ia32_gp_regs[REG_EDX], ABI_CONTEXT_BOTH);
+               be_abi_call_res_reg(abi, 0, &ia32_registers[REG_EAX], ABI_CONTEXT_BOTH);
+               be_abi_call_res_reg(abi, 1, &ia32_registers[REG_EDX], ABI_CONTEXT_BOTH);
        }
        else if (n == 1) {
                const arch_register_t *reg;
@@ -1814,7 +1779,7 @@ static void ia32_get_call_abi(const void *self, ir_type *method_type,
                assert(is_atomic_type(tp));
                mode = get_type_mode(tp);
 
-               reg = mode_is_float(mode) ? &ia32_vfp_regs[REG_VF0] : &ia32_gp_regs[REG_EAX];
+               reg = mode_is_float(mode) ? &ia32_registers[REG_VF0] : &ia32_registers[REG_EAX];
 
                be_abi_call_res_reg(abi, 0, reg, ABI_CONTEXT_BOTH);
        }
@@ -1856,19 +1821,15 @@ static void ia32_mark_remat(ir_node *node)
 static bool mux_is_float_min_max(ir_node *sel, ir_node *mux_true,
                                  ir_node *mux_false)
 {
-       ir_node *cmp_l;
-       ir_node *cmp_r;
-       ir_node *cmp;
-       pn_Cmp  pnc;
+       ir_node    *cmp_l;
+       ir_node    *cmp_r;
+       ir_relation relation;
 
-       if (!is_Proj(sel))
-               return false;
-       cmp = get_Proj_pred(sel);
-       if (!is_Cmp(cmp))
+       if (!is_Cmp(sel))
                return false;
 
-       cmp_l = get_Cmp_left(cmp);
-       cmp_r = get_Cmp_right(cmp);
+       cmp_l = get_Cmp_left(sel);
+       cmp_r = get_Cmp_right(sel);
        if (!mode_is_float(get_irn_mode(cmp_l)))
                return false;
 
@@ -1879,28 +1840,28 @@ static bool mux_is_float_min_max(ir_node *sel, ir_node *mux_true,
         *  or max(a, b) = a >= b ? a : b
         * (Note we only handle float min/max here)
         */
-       pnc = get_Proj_proj(sel);
-       switch (pnc) {
-       case pn_Cmp_Ge:
-       case pn_Cmp_Gt:
+       relation = get_Cmp_relation(sel);
+       switch (relation) {
+       case ir_relation_greater_equal:
+       case ir_relation_greater:
                /* this is a max */
                if (cmp_l == mux_true && cmp_r == mux_false)
                        return true;
                break;
-       case pn_Cmp_Le:
-       case pn_Cmp_Lt:
+       case ir_relation_less_equal:
+       case ir_relation_less:
                /* this is a min */
                if (cmp_l == mux_true && cmp_r == mux_false)
                        return true;
                break;
-       case pn_Cmp_Uge:
-       case pn_Cmp_Ug:
+       case ir_relation_unordered_greater_equal:
+       case ir_relation_unordered_greater:
                /* this is a min */
                if (cmp_l == mux_false && cmp_r == mux_true)
                        return true;
                break;
-       case pn_Cmp_Ule:
-       case pn_Cmp_Ul:
+       case ir_relation_unordered_less_equal:
+       case ir_relation_unordered_less:
                /* this is a max */
                if (cmp_l == mux_false && cmp_r == mux_true)
                        return true;
@@ -1923,7 +1884,8 @@ static bool mux_is_set(ir_node *sel, ir_node *mux_true, ir_node *mux_false)
                return false;
 
        if (is_Const(mux_true) && is_Const(mux_false)) {
-               /* we can create a set plus up two 3 instructions for any combination of constants */
+               /* we can create a set plus up two 3 instructions for any combination
+                * of constants */
                return true;
        }
 
@@ -1943,35 +1905,30 @@ static bool mux_is_float_const_const(ir_node *sel, ir_node *mux_true,
 
 static bool mux_is_doz(ir_node *sel, ir_node *mux_true, ir_node *mux_false)
 {
-       ir_node *cmp;
-       ir_node *cmp_left;
-       ir_node *cmp_right;
-       ir_node *sub_left;
-       ir_node *sub_right;
-       ir_mode *mode;
-       long     pn;
+       ir_node    *cmp_left;
+       ir_node    *cmp_right;
+       ir_node    *sub_left;
+       ir_node    *sub_right;
+       ir_mode    *mode;
+       ir_relation relation;
 
-       if (!is_Proj(sel))
-               return false;
-
-       cmp = get_Proj_pred(sel);
-       if (!is_Cmp(cmp))
+       if (!is_Cmp(sel))
                return false;
 
        mode = get_irn_mode(mux_true);
        if (mode_is_signed(mode) || mode_is_float(mode))
                return false;
 
-       pn        = get_Proj_proj(sel);
-       cmp_left  = get_Cmp_left(cmp);
-       cmp_right = get_Cmp_right(cmp);
+       relation  = get_Cmp_relation(sel);
+       cmp_left  = get_Cmp_left(sel);
+       cmp_right = get_Cmp_right(sel);
 
        /* "move" zero constant to false input */
        if (is_Const(mux_true) && is_Const_null(mux_true)) {
                ir_node *tmp = mux_false;
                mux_false = mux_true;
                mux_true  = tmp;
-               pn = get_negated_pnc(pn, mode);
+               relation = get_negated_relation(relation);
        }
        if (!is_Const(mux_false) || !is_Const_null(mux_false))
                return false;
@@ -1981,11 +1938,11 @@ static bool mux_is_doz(ir_node *sel, ir_node *mux_true, ir_node *mux_false)
        sub_right = get_Sub_right(mux_true);
 
        /* Mux(a >=u b, 0, a-b) */
-       if ((pn == pn_Cmp_Gt || pn == pn_Cmp_Ge)
+       if ((relation & ir_relation_greater)
                        && sub_left == cmp_left && sub_right == cmp_right)
                return true;
        /* Mux(a <=u b, 0, b-a) */
-       if ((pn == pn_Cmp_Lt || pn == pn_Cmp_Le)
+       if ((relation & ir_relation_less)
                        && sub_left == cmp_right && sub_right == cmp_left)
                return true;
 
@@ -2031,19 +1988,16 @@ static int ia32_is_mux_allowed(ir_node *sel, ir_node *mux_false,
                return true;
 
        /* Check Cmp before the node */
-       if (is_Proj(sel)) {
-               ir_node *cmp = get_Proj_pred(sel);
-               if (is_Cmp(cmp)) {
-                       ir_mode *cmp_mode = get_irn_mode(get_Cmp_left(cmp));
-
-                       /* we can't handle 64bit compares */
-                       if (get_mode_size_bits(cmp_mode) > 32)
-                               return false;
-
-                       /* we can't handle float compares */
-                       if (mode_is_float(cmp_mode))
-                               return false;
-               }
+       if (is_Cmp(sel)) {
+               ir_mode *cmp_mode = get_irn_mode(get_Cmp_left(sel));
+
+               /* we can't handle 64bit compares */
+               if (get_mode_size_bits(cmp_mode) > 32)
+                       return false;
+
+               /* we can't handle float compares */
+               if (mode_is_float(cmp_mode))
+                       return false;
        }
 
        /* did we disable cmov generation? */
@@ -2078,13 +2032,19 @@ static ir_node *ia32_create_set(ir_node *cond)
 
 static void ia32_lower_for_target(void)
 {
-       int n_irgs = get_irp_n_irgs();
-       int i;
+       size_t i, n_irgs = get_irp_n_irgs();
        lower_mode_b_config_t lower_mode_b_config = {
                mode_Iu,  /* lowered mode */
                ia32_create_set,
                0,        /* don't lower direct compares */
        };
+       lower_params_t params = {
+               4,                                     /* def_ptr_alignment */
+               LF_COMPOUND_RETURN | LF_RETURN_HIDDEN, /* flags */
+               ADD_HIDDEN_ALWAYS_IN_FRONT,            /* hidden_params */
+               NULL,                                  /* find pointer type */
+               NULL,                                  /* ret_compound_in_regs */
+       };
 
        /* perform doubleword lowering */
        lwrdw_param_t lower_dw_params = {
@@ -2093,6 +2053,10 @@ static void ia32_lower_for_target(void)
                ia32_create_intrinsic_fkt,
                &intrinsic_env,
        };
+
+       /* lower compound param handling */
+       lower_calls_with_compounds(&params);
+
        lower_dw_ops(&lower_dw_params);
 
        for (i = 0; i < n_irgs; ++i) {
@@ -2109,23 +2073,25 @@ static void ia32_lower_for_target(void)
  */
 static ir_node *ia32_create_trampoline_fkt(ir_node *block, ir_node *mem, ir_node *trampoline, ir_node *env, ir_node *callee)
 {
-       ir_node  *st, *p = trampoline;
-       ir_mode *mode    = get_irn_mode(p);
+       ir_graph *irg  = get_irn_irg(block);
+       ir_node  *p    = trampoline;
+       ir_mode  *mode = get_irn_mode(p);
+       ir_node  *st;
 
        /* mov  ecx,<env> */
-       st  = new_r_Store(block, mem, p, new_Const_long(mode_Bu, 0xb9), 0);
+       st  = new_r_Store(block, mem, p, new_r_Const_long(irg, mode_Bu, 0xb9), cons_none);
        mem = new_r_Proj(st, mode_M, pn_Store_M);
-       p   = new_r_Add(block, p, new_Const_long(mode_Iu, 1), mode);
-       st  = new_r_Store(block, mem, p, env, 0);
+       p   = new_r_Add(block, p, new_r_Const_long(irg, mode_Iu, 1), mode);
+       st  = new_r_Store(block, mem, p, env, cons_none);
        mem = new_r_Proj(st, mode_M, pn_Store_M);
-       p   = new_r_Add(block, p, new_Const_long(mode_Iu, 4), mode);
+       p   = new_r_Add(block, p, new_r_Const_long(irg, mode_Iu, 4), mode);
        /* jmp  <callee> */
-       st  = new_r_Store(block, mem, p, new_Const_long(mode_Bu, 0xe9), 0);
+       st  = new_r_Store(block, mem, p, new_r_Const_long(irg, mode_Bu, 0xe9), cons_none);
        mem = new_r_Proj(st, mode_M, pn_Store_M);
-       p   = new_r_Add(block, p, new_Const_long(mode_Iu, 1), mode);
-       st  = new_r_Store(block, mem, p, callee, 0);
+       p   = new_r_Add(block, p, new_r_Const_long(irg, mode_Iu, 1), mode);
+       st  = new_r_Store(block, mem, p, callee, cons_none);
        mem = new_r_Proj(st, mode_M, pn_Store_M);
-       p   = new_r_Add(block, p, new_Const_long(mode_Iu, 4), mode);
+       p   = new_r_Add(block, p, new_r_Const_long(irg, mode_Iu, 4), mode);
 
        return mem;
 }
@@ -2138,7 +2104,7 @@ static const backend_params *ia32_get_libfirm_params(void)
        static const ir_settings_arch_dep_t ad = {
                1,                   /* also use subs */
                4,                   /* maximum shifts */
-               31,                  /* maximum shift amount */
+               63,                  /* maximum shift amount */
                ia32_evaluate_insn,  /* evaluate the instruction sequence */
 
                1,  /* allow Mulhs */
@@ -2149,7 +2115,6 @@ static const backend_params *ia32_get_libfirm_params(void)
                1,     /* support inline assembly */
                1,     /* support Rotl nodes */
                0,     /* little endian */
-               ia32_lower_for_target,
                NULL,  /* will be set later */
                ia32_is_mux_allowed,
                NULL,  /* float arithmetic mode, will be set below */
@@ -2200,17 +2165,17 @@ static const lc_opt_table_entry_t ia32_options[] = {
 #ifdef FIRM_GRGEN_BE
        LC_OPT_ENT_ENUM_INT("transformer", "the transformer used for code selection", &transformer_var),
 #endif
-       LC_OPT_ENT_INT("stackalign", "set power of two stack alignment for calls",
-                      &ia32_isa_template.base.stack_alignment),
+       LC_OPT_ENT_INT ("stackalign", "set power of two stack alignment for calls",
+                       &ia32_isa_template.base.stack_alignment),
+       LC_OPT_ENT_BOOL("gprof",      "create gprof profiling code",                                    &gprof),
        LC_OPT_LAST
 };
 
 const arch_isa_if_t ia32_isa_if = {
        ia32_init,
+       ia32_lower_for_target,
        ia32_done,
        ia32_handle_intrinsics,
-       ia32_get_n_reg_class,
-       ia32_get_reg_class,
        ia32_get_reg_class_for_mode,
        ia32_get_call_abi,
        ia32_get_reg_class_alignment,