cleanup backend: make pre_spill_prepare_constraint independent of chordal allocator...
[libfirm] / ir / be / beilpsched.c
index ffb2384..4381594 100644 (file)
@@ -1,17 +1,35 @@
+/*
+ * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
+ *
+ * This file is part of libFirm.
+ *
+ * This file may be distributed and/or modified under the terms of the
+ * GNU General Public License version 2 as published by the Free Software
+ * Foundation and appearing in the file LICENSE.GPL included in the
+ * packaging of this file.
+ *
+ * Licensees holding valid libFirm Professional Edition licenses may use
+ * this file in accordance with the libFirm Commercial License.
+ * Agreement provided with the Software.
+ *
+ * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+ * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE.
+ */
+
 /**
- * Scheduling algorithms.
+ * @file
+ * @brief       ILP based instruction scheduling.
+ * @author      Christian Wuerdig
+ * @date        22.10.2006
+ * @version     $Id$
+ *
  * An ILP scheduler based on
  * "ILP-based Instruction Scheduling for IA-64"
  * by Daniel Kaestner and Sebastian Winkel
  * extended with register pressure constraints by Christian Wuerdig
- *
- * @date   22.10.2005
- * @author Christian Wuerdig
- * @cvs-id $Id$
  */
-#ifdef HAVE_CONFIG_H
 #include "config.h"
-#endif
 
 #ifdef WITH_ILP
 
 #include "irprintf.h"
 #include "plist.h"
 #include "irprintf.h"
+#include "timing.h"
 
 #include <lpp/lpp.h>
 #include <lpp/lpp_net.h>
 
-#include <libcore/lc_opts.h>
-#include <libcore/lc_opts_enum.h>
-#include <libcore/lc_timing.h>
+#include "lc_opts.h"
+#include "lc_opts_enum.h"
 
 #include "be.h"
 #include "benode_t.h"
@@ -117,7 +135,7 @@ typedef union _ilpsched_attr_ {
 
 /* A irn for the phase and it's attributes (either node or block) */
 typedef struct {
-       ir_node         *irn;
+       const ir_node   *irn;
        ilpsched_attr_t attr;
 } be_ilpsched_irn_t;
 
@@ -129,7 +147,6 @@ typedef struct {
        void                 *irg_env;      /**< An environment for the irg scheduling, provided by the backend */
        void                 *block_env;    /**< An environment for scheduling a block, provided by the backend */
        const arch_env_t     *arch_env;
-       const arch_isa_t     *isa;          /**< The ISA */
        const be_main_env_t  *main_env;
        const be_machine_t   *cpu;          /**< the current abstract machine */
        ilpsched_options_t   *opts;         /**< the ilp options for current irg */
@@ -146,9 +163,9 @@ typedef struct {
 #define get_ilpsched_node_attr(node)        (&(node)->attr.node_attr)
 
 /* check if node is considered for ILP scheduling */
-#define consider_for_sched(isa, irn) \
+#define consider_for_sched(env, irn) \
        (! (is_Block(irn)            ||  \
-               is_normal_Proj(isa, irn) ||  \
+               is_normal_Proj(env, irn) ||  \
                is_Phi(irn)              ||  \
                is_NoMem(irn)            ||  \
                is_Unknown(irn)          ||  \
@@ -172,9 +189,9 @@ typedef struct {
 /* check if a double value is within an epsilon environment of 0 */
 #define LPP_VALUE_IS_0(dbl) (fabs((dbl)) <= 1e-10)
 
-#define ilp_timer_push(t)         lc_timer_push((t))
-#define ilp_timer_pop()           lc_timer_pop()
-#define ilp_timer_elapsed_usec(t) lc_timer_elapsed_usec((t))
+#define ilp_timer_push(t)         ir_timer_push((t))
+#define ilp_timer_pop()           ir_timer_pop()
+#define ilp_timer_elapsed_usec(t) ir_timer_elapsed_usec((t))
 
 /* option variable */
 static ilpsched_options_t ilp_opts = {
@@ -188,7 +205,7 @@ static const lc_opt_table_entry_t ilpsched_option_table[] = {
        LC_OPT_ENT_BOOL("regpress",  "Use register pressure constraints", &ilp_opts.regpress),
        LC_OPT_ENT_INT("time_limit", "ILP time limit per block", &ilp_opts.time_limit),
        LC_OPT_ENT_STR("lpp_log",    "LPP logfile (stderr and stdout are supported)", ilp_opts.log_file, sizeof(ilp_opts.log_file)),
-       { NULL }
+       LC_OPT_LAST
 };
 
 /*
@@ -201,21 +218,21 @@ static heights_t *glob_heights;
  * Check if irn is a Proj, which has no execution units assigned.
  * @return 1 if irn is a Proj having no execution units assigned, 0 otherwise
  */
-static INLINE int is_normal_Proj(const arch_isa_t *isa, const ir_node *irn) {
-       return is_Proj(irn) && (arch_isa_get_allowed_execution_units(isa, irn) == NULL);
+static inline int is_normal_Proj(const arch_env_t *env, const ir_node *irn) {
+       return is_Proj(irn) && (arch_env_get_allowed_execution_units(env, irn) == NULL);
 }
 
 /**
  * Skips normal Projs.
  * @return predecessor if irn is a normal Proj, otherwise irn.
  */
-static INLINE ir_node *skip_normal_Proj(const arch_isa_t *isa, ir_node *irn) {
-       if (is_normal_Proj(isa, irn))
+static inline ir_node *skip_normal_Proj(const arch_env_t *env, ir_node *irn) {
+       if (is_normal_Proj(env, irn))
                return get_Proj_pred(irn);
        return irn;
 }
 
-static INLINE int fixed_latency(const ilp_sched_selector_t *sel, ir_node *irn, void *env) {
+static inline int fixed_latency(const ilp_sched_selector_t *sel, ir_node *irn, void *env) {
        unsigned lat = be_ilp_sched_latency(sel, irn, env);
        if (lat == 0 && ! is_Proj(irn) && ! be_is_Keep(irn))
                lat = 1;
@@ -239,8 +256,8 @@ static int cmp_ilpsched_irn(const void *a, const void *b) {
        ilpsched_node_attr_t *n2_a = get_ilpsched_node_attr(n2);
 
        if (n1_a->sched_point == n2_a->sched_point) {
-               ir_node *irn_a = n1->irn;
-               ir_node *irn_b = n2->irn;
+               const ir_node *irn_a = n1->irn;
+               const ir_node *irn_b = n2->irn;
 
                if (heights_reachable_in_block(glob_heights, irn_a, irn_b))
                        return 1;
@@ -260,7 +277,7 @@ static int cmp_ilpsched_irn(const void *a, const void *b) {
 /**
  * In case there is no phase information for irn, initialize it.
  */
-static void *init_ilpsched_irn(ir_phase *ph, ir_node *irn, void *old) {
+static void *init_ilpsched_irn(ir_phase *ph, const ir_node *irn, void *old) {
        be_ilpsched_irn_t *res = old ? old : phase_alloc(ph, sizeof(res[0]));
 
        if (res == old) {
@@ -318,7 +335,7 @@ static void build_block_idx(ir_node *irn, void *walk_env) {
        ilpsched_block_attr_t *ba;
 
        set_irn_link(irn, NULL);
-       if (! consider_for_sched(env->arch_env->isa, irn))
+       if (! consider_for_sched(env->arch_env, irn))
                return;
 
        node       = get_ilpsched_irn(env, irn);
@@ -355,9 +372,9 @@ static void collect_alap_root_nodes(ir_node *irn, void *walk_env) {
        unsigned              n_consumer     = 0;
        ir_edge_kind_t        ekind[2]       = { EDGE_KIND_NORMAL, EDGE_KIND_DEP };
        ir_node               **consumer;
-       int                   idx;
+       unsigned              idx;
 
-       if (! consider_for_sched(env->arch_env->isa, irn))
+       if (! consider_for_sched(env->arch_env, irn))
                return;
 
        block    = get_nodes_block(irn);
@@ -371,7 +388,7 @@ static void collect_alap_root_nodes(ir_node *irn, void *walk_env) {
                foreach_out_edge_kind(irn, edge, ekind[i]) {
                        ir_node *user = get_edge_src_irn(edge);
 
-                       if (is_normal_Proj(env->arch_env->isa, user)) {
+                       if (is_normal_Proj(env->arch_env, user)) {
                                const ir_edge_t *user_edge;
 
                                if (get_irn_mode(user) == mode_X)
@@ -473,7 +490,7 @@ static void calculate_irn_asap(ir_node *irn, void *walk_env) {
        ilpsched_block_attr_t *ba;
 
        /* These nodes are handled separate */
-       if (! consider_for_sched(env->arch_env->isa, irn))
+       if (! consider_for_sched(env->arch_env, irn))
                return;
 
        DBG((env->dbg, LEVEL_2, "Calculating ASAP of node %+F ... ", irn));
@@ -484,7 +501,7 @@ static void calculate_irn_asap(ir_node *irn, void *walk_env) {
        na->asap = 1;
 
        for (i = get_irn_ins_or_deps(irn) - 1; i >= 0; --i) {
-               ir_node *pred = skip_normal_Proj(env->arch_env->isa, get_irn_in_or_dep(irn, i));
+               ir_node *pred = skip_normal_Proj(env->arch_env, get_irn_in_or_dep(irn, i));
 
                /* check for greatest distance to top */
                if (! is_Phi(pred) && ! is_NoMem(pred) && get_nodes_block(pred) == block) {
@@ -557,7 +574,7 @@ static void calculate_block_alap(ir_node *block, void *walk_env) {
 
                        /* set the alap's of all predecessors */
                        for (i = get_irn_ins_or_deps(cur_irn) - 1; i >= 0; --i) {
-                               ir_node *pred = skip_normal_Proj(env->arch_env->isa, get_irn_in_or_dep(cur_irn, i));
+                               ir_node *pred = skip_normal_Proj(env->arch_env, get_irn_in_or_dep(cur_irn, i));
 
                                /* check for greatest distance to bottom */
                                if (! is_Phi(pred) && ! is_NoMem(pred) && get_nodes_block(pred) == block) {
@@ -627,7 +644,7 @@ static void refine_asap_alap_times(ir_node *irn, void *walk_env) {
        be_ilpsched_irn_t    *node, *pred_node;
        ilpsched_node_attr_t *na, *pna;
 
-       if (! consider_for_sched(env->arch_env->isa, irn))
+       if (! consider_for_sched(env->arch_env, irn))
                return;
 
        if (! is_Proj(irn) && ! be_is_Keep(irn))
@@ -664,8 +681,9 @@ static void refine_asap_alap_times(ir_node *irn, void *walk_env) {
  *
  *******************************************/
 
-static INLINE void check_for_keeps(waitq *keeps, ir_node *block, ir_node *irn) {
+static inline void check_for_keeps(waitq *keeps, const ir_node *block, const ir_node *irn) {
        const ir_edge_t *edge;
+        (void) block;
 
        foreach_out_edge(irn, edge) {
                ir_node *user = get_edge_src_irn(edge);
@@ -680,18 +698,18 @@ static INLINE void check_for_keeps(waitq *keeps, ir_node *block, ir_node *irn) {
 /**
  * Inserts @p irn before @p before into schedule and notifies backend.
  */
-static INLINE void notified_sched_add_before(be_ilpsched_env_t *env,
-       ir_node *before, ir_node *irn, unsigned cycle)
+static inline void notified_sched_add_before(be_ilpsched_env_t *env,
+       const ir_node *before, const ir_node *irn, unsigned cycle)
 {
        be_ilp_sched_node_scheduled(env->sel, irn, cycle, env->block_env);
-       sched_add_before(before, irn);
+       sched_add_before((ir_node*) before, (ir_node*) irn);
 }
 
 /**
  * Adds a node, it's Projs (in case of mode_T nodes) and
  * it's Keeps to schedule.
  */
-static void add_to_sched(be_ilpsched_env_t *env, ir_node *block, ir_node *irn, unsigned cycle) {
+static void add_to_sched(be_ilpsched_env_t *env, const ir_node *block, const ir_node *irn, unsigned cycle) {
        const ir_edge_t *edge;
        waitq           *keeps = new_waitq();
 
@@ -736,15 +754,13 @@ static void add_to_sched(be_ilpsched_env_t *env, ir_node *block, ir_node *irn, u
 static void apply_solution(be_ilpsched_env_t *env, lpp_t *lpp, ir_node *block) {
        be_ilpsched_irn_t     *block_node = get_ilpsched_irn(env, block);
        ilpsched_block_attr_t *ba         = get_ilpsched_block_attr(block_node);
-       sched_info_t          *info       = get_irn_sched_info(block);
        be_ilpsched_irn_t     **sched_nodes;
        unsigned              i, l;
        ir_node               *cfop, *irn;
        const ir_edge_t       *edge;
 
        /* init block schedule list */
-       INIT_LIST_HEAD(&info->list);
-       info->scheduled = 1;
+       sched_init_block(block);
 
        /* collect nodes and their scheduling time step */
        sched_nodes = NEW_ARR_F(be_ilpsched_irn_t *, 0);
@@ -857,7 +873,7 @@ static void apply_solution(be_ilpsched_env_t *env, lpp_t *lpp, ir_node *block) {
 /**
  * Check if node can be executed on given unit type.
  */
-static INLINE int is_valid_unit_type_for_node(const be_execution_unit_type_t *tp, be_ilpsched_irn_t *node) {
+static inline int is_valid_unit_type_for_node(const be_execution_unit_type_t *tp, be_ilpsched_irn_t *node) {
        int                  i;
        ilpsched_node_attr_t *na = get_ilpsched_node_attr(node);
 
@@ -880,7 +896,7 @@ static INLINE int is_valid_unit_type_for_node(const be_execution_unit_type_t *tp
  ************************************************/
 
 static int be_ilpsched_set_type_info(be_ilpsched_env_t *env, ir_node *irn, struct obstack *obst) {
-       const be_execution_unit_t ***execunits = arch_isa_get_allowed_execution_units(env->arch_env->isa, irn);
+       const be_execution_unit_t ***execunits = arch_env_get_allowed_execution_units(env->arch_env, irn);
        unsigned                  n_unit_types = 0;
        be_ilpsched_irn_t         *node;
        ilpsched_node_attr_t      *na;
@@ -917,7 +933,7 @@ static int be_ilpsched_set_type_info(be_ilpsched_env_t *env, ir_node *irn, struc
  * Returns the largest alap time of a user of @p irn.
  * The user must be in block @p block.
  */
-static unsigned be_ilpsched_get_max_alap_user(be_ilpsched_env_t *env, ir_node *irn, ir_node *block) {
+static unsigned be_ilpsched_get_max_alap_user(be_ilpsched_env_t *env, const ir_node *irn, const ir_node *block) {
        const ir_edge_t *edge;
        unsigned        max_alap = 0;
 
@@ -957,7 +973,7 @@ static void create_variables(be_ilpsched_env_t *env, lpp_t *lpp, be_ilpsched_irn
        ilp_livein_node_t     *livein;
        ilpsched_block_attr_t *ba      = get_ilpsched_block_attr(block_node);
        unsigned              weigth_y = ba->n_interesting_nodes * ba->n_interesting_nodes;
-       lc_timer_t            *t_var   = lc_timer_register("beilpsched_var", "create ilp variables");
+       ir_timer_t            *t_var   = ir_timer_register("beilpsched_var", "create ilp variables");
 
        ilp_timer_push(t_var);
        num_block_var = num_nodes = 0;
@@ -1037,7 +1053,7 @@ static void create_variables(be_ilpsched_env_t *env, lpp_t *lpp, be_ilpsched_irn
                        for (i = get_irn_arity(irn) - 1; i >= 0; --i) {
                                ir_node *pred = get_irn_n(irn, i);
 
-                               if (get_nodes_block(pred) != block_node->irn && consider_for_sched(env->arch_env->isa, pred)) {
+                               if (get_nodes_block(pred) != block_node->irn && consider_for_sched(env->arch_env, pred)) {
                                        be_ilpsched_set_type_info(env, pred, var_obst);
                                        if (! na->is_dummy_node) {
                                                ilp_livein_node_t *entry = obstack_alloc(var_obst, sizeof(*entry));
@@ -1103,7 +1119,7 @@ static void create_variables(be_ilpsched_env_t *env, lpp_t *lpp, be_ilpsched_irn
  * Collect all operands and nodes @p irn depends on.
  * If there is a Proj within the dependencies, all other Projs of the parent node are added as well.
  */
-static nodeset *sta_collect_in_deps(ir_node *irn, nodeset *deps) {
+static void sta_collect_in_deps(ir_node *irn, ir_nodeset_t *deps) {
        int i;
 
        for (i = get_irn_ins_or_deps(irn) - 1; i >= 0; --i) {
@@ -1115,15 +1131,13 @@ static nodeset *sta_collect_in_deps(ir_node *irn, nodeset *deps) {
                        p = get_Proj_pred(p);
                        foreach_out_edge(p, edge) {
                                ir_node *src = get_edge_src_irn(edge);
-                               nodeset_insert(deps, src);
+                               ir_nodeset_insert(deps, src);
                        }
                }
                else {
-                       nodeset_insert(deps, p);
+                       ir_nodeset_insert(deps, p);
                }
        }
-
-       return deps;
 }
 
 /**
@@ -1141,8 +1155,8 @@ static void create_assignment_and_precedence_constraints(be_ilpsched_env_t *env,
        ir_node               *irn;
        ilpsched_block_attr_t *ba            = get_ilpsched_block_attr(block_node);
        bitset_t              *bs_block_irns = bitset_alloca(ba->block_last_idx);
-       lc_timer_t            *t_cst_assign  = lc_timer_register("beilpsched_cst_assign", "create assignment constraints");
-       lc_timer_t            *t_cst_prec    = lc_timer_register("beilpsched_cst_prec",   "create precedence constraints");
+       ir_timer_t            *t_cst_assign  = ir_timer_register("beilpsched_cst_assign", "create assignment constraints");
+       ir_timer_t            *t_cst_prec    = ir_timer_register("beilpsched_cst_prec",   "create precedence constraints");
 
        num_cst_assign = num_cst_prec = num_cst_dead = 0;
        foreach_linked_irns(ba->head_ilp_nodes, irn) {
@@ -1151,7 +1165,10 @@ static void create_assignment_and_precedence_constraints(be_ilpsched_env_t *env,
                be_ilpsched_irn_t    *node;
                ilpsched_node_attr_t *na;
                ir_node              *pred;
-               nodeset              *deps = new_nodeset(16);
+               ir_nodeset_t          deps;
+               ir_nodeset_iterator_t iter;
+
+               ir_nodeset_init(&deps);
 
                node    = get_ilpsched_irn(env, irn);
                na      = get_ilpsched_node_attr(node);
@@ -1176,14 +1193,14 @@ static void create_assignment_and_precedence_constraints(be_ilpsched_env_t *env,
                ilp_timer_push(t_cst_prec);
                bs_block_irns = bitset_clear_all(bs_block_irns);
 
-               deps = sta_collect_in_deps(irn, deps);
-               foreach_nodeset(deps, pred) {
+               sta_collect_in_deps(irn, &deps);
+               foreach_ir_nodeset(&deps, pred, iter) {
                        unsigned             t_low, t_high, t;
                        be_ilpsched_irn_t    *pred_node;
                        ilpsched_node_attr_t *pna;
                        unsigned             delay;
 
-                       pred = skip_normal_Proj(env->arch_env->isa, pred);
+                       pred = skip_normal_Proj(env->arch_env, pred);
                        if (is_Phi(pred) || block_node->irn != get_nodes_block(pred) || is_NoMem(pred))
                                continue;
 
@@ -1250,7 +1267,7 @@ static void create_assignment_and_precedence_constraints(be_ilpsched_env_t *env,
                                DEL_ARR_F(tmp_var_idx);
                        }
                }
-               del_nodeset(deps);
+               ir_nodeset_destroy(&deps);
                ilp_timer_pop();
        }
        DBG((env->dbg, LEVEL_1, "\t%u assignement constraints (%g sec)\n",
@@ -1269,7 +1286,7 @@ static void create_ressource_constraints(be_ilpsched_env_t *env, lpp_t *lpp, be_
        char                  buf[1024];
        unsigned              num_cst_resrc = 0;
        ilpsched_block_attr_t *ba           = get_ilpsched_block_attr(block_node);
-       lc_timer_t            *t_cst_rsrc   = lc_timer_register("beilpsched_cst_rsrc",   "create resource constraints");
+       ir_timer_t            *t_cst_rsrc   = ir_timer_register("beilpsched_cst_rsrc",   "create resource constraints");
 
        ilp_timer_push(t_cst_rsrc);
        for (glob_type_idx = env->cpu->n_unit_types - 1; glob_type_idx >= 0; --glob_type_idx) {
@@ -1325,7 +1342,7 @@ static void create_bundle_constraints(be_ilpsched_env_t *env, lpp_t *lpp, be_ilp
        unsigned              num_cst_bundle = 0;
        unsigned              n_instr_max    = env->cpu->bundle_size * env->cpu->bundels_per_cycle;
        ilpsched_block_attr_t *ba            = get_ilpsched_block_attr(block_node);
-       lc_timer_t            *t_cst_bundle  = lc_timer_register("beilpsched_cst_bundle", "create bundle constraints");
+       ir_timer_t            *t_cst_bundle  = ir_timer_register("beilpsched_cst_bundle", "create bundle constraints");
 
        ilp_timer_push(t_cst_bundle);
        for (t = 0; t < ba->max_steps; ++t) {
@@ -1381,7 +1398,7 @@ static void create_alive_nodes_constraint(be_ilpsched_env_t *env, lpp_t *lpp, be
        ir_node               *irn;
        unsigned              num_cst = 0;
        ilpsched_block_attr_t *ba     = get_ilpsched_block_attr(block_node);
-       lc_timer_t            *t_cst  = lc_timer_register("beilpsched_cst_alive_nodes", "create alive nodes constraints");
+       ir_timer_t            *t_cst  = ir_timer_register("beilpsched_cst_alive_nodes", "create alive nodes constraints");
 
        ilp_timer_push(t_cst);
        /* for each node */
@@ -1463,7 +1480,7 @@ static void create_alive_livein_nodes_constraint(be_ilpsched_env_t *env, lpp_t *
        ilp_livein_node_t     *livein;
        unsigned              num_cst = 0;
        ilpsched_block_attr_t *ba     = get_ilpsched_block_attr(block_node);
-       lc_timer_t            *t_cst  = lc_timer_register("beilpsched_cst_alive_livein_nodes", "create alive livein nodes constraints");
+       ir_timer_t            *t_cst  = ir_timer_register("beilpsched_cst_alive_livein_nodes", "create alive livein nodes constraints");
 
        ilp_timer_push(t_cst);
        /* for each node */
@@ -1542,7 +1559,7 @@ static void create_pressure_alive_constraint(be_ilpsched_env_t *env, lpp_t *lpp,
        ir_node               *cur_irn;
        unsigned              num_cst = 0;
        ilpsched_block_attr_t *ba     = get_ilpsched_block_attr(block_node);
-       lc_timer_t            *t_cst  = lc_timer_register("beilpsched_cst_pressure", "create pressure constraints");
+       ir_timer_t            *t_cst  = ir_timer_register("beilpsched_cst_pressure", "create pressure constraints");
 
        ilp_timer_push(t_cst);
        /* y_{nt}^k is set for each node and timestep and unit type */
@@ -1645,7 +1662,7 @@ static void create_branch_constraint(be_ilpsched_env_t *env, lpp_t *lpp, be_ilps
        unsigned              num_cst          = 0;
        unsigned              num_non_branches = 0;
        ilpsched_block_attr_t *ba     = get_ilpsched_block_attr(block_node);
-       lc_timer_t            *t_cst  = lc_timer_register("beilpsched_cst_branch", "create branch constraints");
+       ir_timer_t            *t_cst  = ir_timer_register("beilpsched_cst_branch", "create branch constraints");
 
        ilp_timer_push(t_cst);
        cfop = NULL;
@@ -1737,7 +1754,7 @@ static void create_proj_keep_constraints(be_ilpsched_env_t *env, lpp_t *lpp, be_
        ir_node               *irn;
        unsigned              num_cst = 0;
        ilpsched_block_attr_t *ba     = get_ilpsched_block_attr(block_node);
-       lc_timer_t            *t_cst  = lc_timer_register("beilpsched_cst_projkeep", "create proj and keep constraints");
+       ir_timer_t            *t_cst  = ir_timer_register("beilpsched_cst_projkeep", "create proj and keep constraints");
 
        ilp_timer_push(t_cst);
        /* check all nodes */
@@ -1848,6 +1865,7 @@ static void create_ilp(ir_node *block, void *walk_env) {
 
                DBG((env->dbg, LEVEL_1, "Creating LPP with estimated numbers: %d vars, %d cst\n",
                        estimated_n_var, estimated_n_cst));
+                (void) estimated_n_var;
 
                /* set up the LPP object */
                snprintf(name, sizeof(name), "ilp scheduling IRG %s", get_entity_ld_name(get_irg_entity(env->irg)));
@@ -1880,7 +1898,7 @@ static void create_ilp(ir_node *block, void *walk_env) {
                DBG((env->dbg, LEVEL_1, "ILP to solve: %u variables, %u constraints\n", lpp->var_next, lpp->cst_next));
 
                /* debug stuff, dump lpp when debugging is on  */
-               DEBUG_ONLY(
+               DEBUG_ONLY({
                        if (firm_dbg_get_mask(env->dbg) > 1) {
                                char buf[1024];
                                FILE *f;
@@ -1892,7 +1910,7 @@ static void create_ilp(ir_node *block, void *walk_env) {
                                snprintf(buf, sizeof(buf), "lpp_block_%lu.mps", get_irn_node_nr(block));
                                lpp_dump(lpp, buf);
                        }
-               );
+               })
 
                /* set solve time limit */
                lpp_set_time_limit(lpp, env->opts->time_limit);
@@ -1920,20 +1938,20 @@ static void create_ilp(ir_node *block, void *walk_env) {
 
                /* check for valid solution */
                if (! lpp_is_sol_valid(lpp)) {
-                       char buf[1024];
-                       FILE *f;
-
-                       DEBUG_ONLY(
-                               if (firm_dbg_get_mask(env->dbg) >= 2) {
-                                       snprintf(buf, sizeof(buf), "lpp_block_%lu.infeasible.txt", get_irn_node_nr(block));
-                                       f = fopen(buf, "w");
-                                       lpp_dump_plain(lpp, f);
-                                       fclose(f);
-                                       snprintf(buf, sizeof(buf), "lpp_block_%lu.infeasible.mps", get_irn_node_nr(block));
-                                       lpp_dump(lpp, buf);
-                                       dump_ir_block_graph(env->irg, "-infeasible");
-                               }
-                       )
+                       DEBUG_ONLY({
+                            char buf[1024];
+                            FILE *f;
+
+                            if (firm_dbg_get_mask(env->dbg) >= 2) {
+                              snprintf(buf, sizeof(buf), "lpp_block_%lu.infeasible.txt", get_irn_node_nr(block));
+                              f = fopen(buf, "w");
+                              lpp_dump_plain(lpp, f);
+                              fclose(f);
+                              snprintf(buf, sizeof(buf), "lpp_block_%lu.infeasible.mps", get_irn_node_nr(block));
+                              lpp_dump(lpp, buf);
+                              dump_ir_block_graph(env->irg, "-infeasible");
+                           }
+                       })
 
                        ir_fprintf(stderr, "ILP found no solution within time (%+F, %+F), falling back to heuristics.\n", block, env->irg);
                        need_heur = 1;
@@ -1952,36 +1970,24 @@ static void create_ilp(ir_node *block, void *walk_env) {
        }
 
        /* apply solution */
-#ifdef FIRM_STATISTICS
-       if (be_stat_ev_is_active()) {
-               be_stat_ev("nodes", ba->block_last_idx);
-               be_stat_ev("vars", lpp ? lpp->var_next : 0);
-               be_stat_ev("csts", lpp ? lpp->cst_next : 0);
-       }
-#endif /* FIRM_STATISTICS */
+       be_stat_ev("nodes", ba->block_last_idx);
+       be_stat_ev("vars", lpp ? lpp->var_next : 0);
+       be_stat_ev("csts", lpp ? lpp->cst_next : 0);
        if (need_heur) {
-#ifdef FIRM_STATISTICS
-               if (be_stat_ev_is_active()) {
                        be_stat_ev("time", -1);
                        be_stat_ev_dbl("opt", 0.0);
-               }
-#endif /* FIRM_STATISTICS */
                list_sched_single_block(env->birg, block, env->be_opts);
        }
        else {
-#ifdef FIRM_STATISTICS
-               if (be_stat_ev_is_active()) {
-                       if (lpp) {
-                               double opt = lpp->sol_state == lpp_optimal ? 100.0 : 100.0 * lpp->best_bound / lpp->objval;
-                               be_stat_ev_dbl("time", lpp->sol_time);
-                               be_stat_ev_dbl("opt", opt);
-                       }
-                       else {
-                               be_stat_ev_dbl("time", 0.0);
-                               be_stat_ev_dbl("opt", 100.0);
-                       }
+               if (lpp) {
+                       double opt = lpp->sol_state == lpp_optimal ? 100.0 : 100.0 * lpp->best_bound / lpp->objval;
+                       be_stat_ev_dbl("time", lpp->sol_time);
+                       be_stat_ev_dbl("opt", opt);
+               }
+               else {
+                       be_stat_ev_dbl("time", 0.0);
+                       be_stat_ev_dbl("opt", 100.0);
                }
-#endif /* FIRM_STATISTICS */
                apply_solution(env, lpp, block);
        }
 
@@ -2000,17 +2006,11 @@ void be_ilp_sched(const be_irg_t *birg, be_options_t *be_opts) {
        const char                 *name     = "be ilp scheduling";
        ir_graph                   *irg      = be_get_birg_irg(birg);
        const arch_env_t           *arch_env = be_get_birg_arch_env(birg);
-       const arch_isa_t           *isa      = arch_env->isa;
-       const ilp_sched_selector_t *sel      = isa->impl->get_ilp_sched_selector(isa);
+       const ilp_sched_selector_t *sel      = arch_env->impl->get_ilp_sched_selector(arch_env);
 
        FIRM_DBG_REGISTER(env.dbg, "firm.be.sched.ilp");
 
-#ifdef FIRM_STATISTICS
-       if (be_stat_ev_is_active()) {
-               be_stat_tags[STAT_TAG_CLS] = "ilpsched";
-               be_stat_ev_push(be_stat_tags, STAT_TAG_LAST, be_stat_file);
-       }
-#endif /* FIRM_STATISTICS */
+       stat_ev_ctx_push("ilpsched");
 
 //     firm_dbg_set_mask(env.dbg, 1);
 
@@ -2020,7 +2020,7 @@ void be_ilp_sched(const be_irg_t *birg, be_options_t *be_opts) {
        env.height     = heights_new(irg);
        env.main_env   = birg->main_env;
        env.arch_env   = arch_env;
-       env.cpu        = arch_isa_get_machine(arch_env->isa);
+       env.cpu        = arch_env_get_machine(arch_env);
        env.opts       = &ilp_opts;
        env.birg       = birg;
        env.be_opts    = be_opts;
@@ -2067,11 +2067,7 @@ void be_ilp_sched(const be_irg_t *birg, be_options_t *be_opts) {
        /* notify backend */
        be_ilp_sched_finish_irg_ilp_schedule(sel, birg->irg, env.irg_env);
 
-#ifdef FIRM_STATISTICS
-       if (be_stat_ev_is_active()) {
-               be_stat_ev_pop();
-       }
-#endif /* FIRM_STATISTICS */
+       stat_ev_ctx_pop("ilpsched");
 }
 
 /**
@@ -2087,7 +2083,7 @@ void be_init_ilpsched(void)
 
 #else /* WITH_ILP */
 
-static INLINE void some_picky_compiler_do_not_allow_empty_files(void)
+static inline void some_picky_compiler_do_not_allow_empty_files(void)
 {}
 
 #endif /* WITH_ILP */