bemain: Centrally call be_gas_end_compilation_unit() and be_emit_exit() instead of...
[libfirm] / ir / be / ia32 / bearch_ia32.c
index ba26ada..8b5a8ff 100644 (file)
@@ -53,9 +53,9 @@
 #include "lower_calls.h"
 #include "lower_mode_b.h"
 #include "lower_softfloat.h"
+#include "firmstat_t.h"
 
 #include "beabi.h"
-#include "beirg.h"
 #include "benode.h"
 #include "belower.h"
 #include "besched.h"
@@ -109,8 +109,6 @@ static ir_entity *omit_fp_ret_addr_ent = NULL;
  * The environment for the intrinsic mapping.
  */
 static ia32_intrinsic_env_t intrinsic_env = {
-       NULL,    /* the isa */
-       NULL,    /* the irg, these entities belong to */
        NULL,    /* entity for __divdi3 library call */
        NULL,    /* entity for __moddi3 library call */
        NULL,    /* entity for __udivdi3 library call */
@@ -349,133 +347,6 @@ static int ia32_get_op_estimated_cost(const ir_node *irn)
        return cost;
 }
 
-/**
- * Returns the inverse operation if @p irn, recalculating the argument at position @p i.
- *
- * @param irn       The original operation
- * @param i         Index of the argument we want the inverse operation to yield
- * @param inverse   struct to be filled with the resulting inverse op
- * @param obstack   The obstack to use for allocation of the returned nodes array
- * @return          The inverse operation or NULL if operation invertible
- */
-static arch_inverse_t *ia32_get_inverse(const ir_node *irn, int i, arch_inverse_t *inverse, struct obstack *obst)
-{
-       (void) irn;
-       (void) i;
-       (void) inverse;
-       (void) obst;
-       return NULL;
-
-#if 0
-       ir_mode  *mode;
-       ir_mode  *irn_mode;
-       ir_node  *block, *noreg, *nomem;
-       dbg_info *dbgi;
-
-       /* we cannot invert non-ia32 irns */
-       if (! is_ia32_irn(irn))
-               return NULL;
-
-       /* operand must always be a real operand (not base, index or mem) */
-       if (i != n_ia32_binary_left && i != n_ia32_binary_right)
-               return NULL;
-
-       /* we don't invert address mode operations */
-       if (get_ia32_op_type(irn) != ia32_Normal)
-               return NULL;
-
-       /* TODO: adjust for new immediates... */
-       ir_fprintf(stderr, "TODO: fix get_inverse for new immediates (%+F)\n",
-                  irn);
-       return NULL;
-
-       block    = get_nodes_block(irn);
-       mode     = get_irn_mode(irn);
-       irn_mode = get_irn_mode(irn);
-       noreg    = get_irn_n(irn, 0);
-       nomem    = get_irg_no_mem(irg);
-       dbgi     = get_irn_dbg_info(irn);
-
-       /* initialize structure */
-       inverse->nodes = obstack_alloc(obst, 2 * sizeof(inverse->nodes[0]));
-       inverse->costs = 0;
-       inverse->n     = 1;
-
-       switch (get_ia32_irn_opcode(irn)) {
-               case iro_ia32_Add:
-                       if (get_ia32_immop_type(irn) == ia32_ImmConst) {
-                               /* we have an add with a const here */
-                               /* invers == add with negated const */
-                               inverse->nodes[0] = new_bd_ia32_Add(dbgi, block, noreg, noreg, nomem, get_irn_n(irn, i), noreg);
-                               inverse->costs   += 1;
-                               copy_ia32_Immop_attr(inverse->nodes[0], (ir_node *)irn);
-                               set_ia32_Immop_tarval(inverse->nodes[0], tarval_neg(get_ia32_Immop_tarval(irn)));
-                               set_ia32_commutative(inverse->nodes[0]);
-                       }
-                       else if (get_ia32_immop_type(irn) == ia32_ImmSymConst) {
-                               /* we have an add with a symconst here */
-                               /* invers == sub with const */
-                               inverse->nodes[0] = new_bd_ia32_Sub(dbgi, block, noreg, noreg, nomem, get_irn_n(irn, i), noreg);
-                               inverse->costs   += 2;
-                               copy_ia32_Immop_attr(inverse->nodes[0], (ir_node *)irn);
-                       }
-                       else {
-                               /* normal add: inverse == sub */
-                               inverse->nodes[0] = new_bd_ia32_Sub(dbgi, block, noreg, noreg, nomem, (ir_node*) irn, get_irn_n(irn, i ^ 1));
-                               inverse->costs   += 2;
-                       }
-                       break;
-               case iro_ia32_Sub:
-                       if (get_ia32_immop_type(irn) != ia32_ImmNone) {
-                               /* we have a sub with a const/symconst here */
-                               /* invers == add with this const */
-                               inverse->nodes[0] = new_bd_ia32_Add(dbgi, block, noreg, noreg, nomem, get_irn_n(irn, i), noreg);
-                               inverse->costs   += (get_ia32_immop_type(irn) == ia32_ImmSymConst) ? 5 : 1;
-                               copy_ia32_Immop_attr(inverse->nodes[0], (ir_node *)irn);
-                       }
-                       else {
-                               /* normal sub */
-                               if (i == n_ia32_binary_left) {
-                                       inverse->nodes[0] = new_bd_ia32_Add(dbgi, block, noreg, noreg, nomem, (ir_node*) irn, get_irn_n(irn, 3));
-                               }
-                               else {
-                                       inverse->nodes[0] = new_bd_ia32_Sub(dbgi, block, noreg, noreg, nomem, get_irn_n(irn, n_ia32_binary_left), (ir_node*) irn);
-                               }
-                               inverse->costs += 1;
-                       }
-                       break;
-               case iro_ia32_Xor:
-                       if (get_ia32_immop_type(irn) != ia32_ImmNone) {
-                               /* xor with const: inverse = xor */
-                               inverse->nodes[0] = new_bd_ia32_Xor(dbgi, block, noreg, noreg, nomem, get_irn_n(irn, i), noreg);
-                               inverse->costs   += (get_ia32_immop_type(irn) == ia32_ImmSymConst) ? 5 : 1;
-                               copy_ia32_Immop_attr(inverse->nodes[0], (ir_node *)irn);
-                       }
-                       else {
-                               /* normal xor */
-                               inverse->nodes[0] = new_bd_ia32_Xor(dbgi, block, noreg, noreg, nomem, (ir_node *) irn, get_irn_n(irn, i));
-                               inverse->costs   += 1;
-                       }
-                       break;
-               case iro_ia32_Not: {
-                       inverse->nodes[0] = new_bd_ia32_Not(dbgi, block, (ir_node*) irn);
-                       inverse->costs   += 1;
-                       break;
-               }
-               case iro_ia32_Neg: {
-                       inverse->nodes[0] = new_bd_ia32_Neg(dbgi, block, (ir_node*) irn);
-                       inverse->costs   += 1;
-                       break;
-               }
-               default:
-                       /* inverse operation not supported */
-                       return NULL;
-       }
-
-       return inverse;
-#endif
-}
-
 static ir_mode *get_spill_mode_mode(const ir_mode *mode)
 {
        if (mode_is_float(mode))
@@ -532,15 +403,13 @@ static int ia32_possible_memory_operand(const ir_node *irn, unsigned int i)
                case ia32_am_binary:
                        switch (i) {
                                case n_ia32_binary_left: {
-                                       const arch_register_req_t *req;
                                        if (!is_ia32_commutative(irn))
                                                return 0;
 
                                        /* we can't swap left/right for limited registers
-                                        * (As this (currently) breaks constraint handling copies)
-                                        */
-                                       req = arch_get_irn_register_req_in(irn, n_ia32_binary_left);
-                                       if (req->type & arch_register_req_type_limited)
+                                        * (As this (currently) breaks constraint handling copies) */
+                                       arch_register_req_t const *const req = arch_get_irn_register_req_in(irn, n_ia32_binary_left);
+                                       if (arch_register_req_is(req, limited))
                                                return 0;
                                        break;
                                }
@@ -608,18 +477,17 @@ static const arch_irn_ops_t ia32_irn_ops = {
        ia32_get_frame_entity,
        ia32_set_frame_offset,
        ia32_get_sp_bias,
-       ia32_get_inverse,
        ia32_get_op_estimated_cost,
        ia32_possible_memory_operand,
        ia32_perform_memory_operand,
 };
 
-static ir_entity *mcount = NULL;
 static int gprof = 0;
 
 static void ia32_before_abi(ir_graph *irg)
 {
        if (gprof) {
+               static ir_entity *mcount = NULL;
                if (mcount == NULL) {
                        ir_type *tp = new_type_method(0, 0);
                        ident   *id = new_id_from_str("mcount");
@@ -714,7 +582,7 @@ ir_node *ia32_turn_back_am(ir_node *node)
                default:
                        panic("Unknown AM type");
        }
-       noreg = ia32_new_NoReg_gp(current_ir_graph);
+       noreg = ia32_new_NoReg_gp(irg);
        set_irn_n(node, n_ia32_base,  noreg);
        set_irn_n(node, n_ia32_index, noreg);
        set_ia32_am_offs_int(node, 0);
@@ -1772,7 +1640,6 @@ static ia32_isa_t ia32_isa_template = {
                &ia32_registers[REG_ESP], /* stack pointer register */
                &ia32_registers[REG_EBP], /* base pointer register */
                2,                        /* power of two stack alignment, 2^2 == 4 */
-               NULL,                     /* main environment */
                7,                        /* costs for a spill instruction */
                5,                        /* costs for a reload instruction */
                false,                    /* no custom abi handling */
@@ -1781,7 +1648,7 @@ static ia32_isa_t ia32_isa_template = {
        IA32_FPU_ARCH_X87,          /* FPU architecture */
 };
 
-static arch_env_t *ia32_begin_codegeneration(const be_main_env_t *env)
+static arch_env_t *ia32_begin_codegeneration(void)
 {
        ia32_isa_t *isa = XMALLOC(ia32_isa_t);
 
@@ -1790,12 +1657,6 @@ static arch_env_t *ia32_begin_codegeneration(const be_main_env_t *env)
        *isa        = ia32_isa_template;
        isa->tv_ent = pmap_create();
 
-       /* enter the ISA object into the intrinsic environment */
-       intrinsic_env.isa = isa;
-
-       be_emit_init(env->file_handle);
-       be_gas_begin_compilation_unit(env);
-
        return &isa->base;
 }
 
@@ -1805,12 +1666,6 @@ static arch_env_t *ia32_begin_codegeneration(const be_main_env_t *env)
 static void ia32_end_codegeneration(void *self)
 {
        ia32_isa_t *isa = (ia32_isa_t*)self;
-
-       /* emit now all global declarations */
-       be_gas_end_compilation_unit(isa->base.main_env);
-
-       be_emit_exit();
-
        pmap_destroy(isa->tv_ent);
        free(self);
 }
@@ -1908,8 +1763,8 @@ static void ia32_get_call_abi(ir_type *method_type, be_abi_call_t *abi)
        be_abi_call_flags_t call_flags = be_abi_call_get_flags(abi);
 
        /* set abi flags for calls */
-       /* call_flags.bits.try_omit_fp                 not changed: can handle both settings */
-       call_flags.bits.call_has_imm = false;  /* No call immediate, we handle this by ourselves */
+       /* call_flags.try_omit_fp                 not changed: can handle both settings */
+       call_flags.call_has_imm = false;  /* No call immediate, we handle this by ourselves */
 
        /* set parameter passing style */
        be_abi_call_set_flags(abi, call_flags, &ia32_abi_callbacks);