Extended public backend API.
[libfirm] / ir / be / bemain.c
index 918e887..d5977ad 100644 (file)
@@ -46,7 +46,7 @@
 #include "irprintf.h"
 #include "iroptimize.h"
 #include "firmstat.h"
-#include "execfreq.h"
+#include "execfreq_t.h"
 #include "irprofile.h"
 #include "irpass_t.h"
 #include "ircons.h"
@@ -70,7 +70,6 @@
 #include "belower.h"
 #include "bestat.h"
 #include "beverify.h"
-#include "be_dbgout.h"
 #include "beirg.h"
 #include "bestack.h"
 #include "beemitter.h"
@@ -78,7 +77,7 @@
 #define NEW_ID(s) new_id_from_chars(s, sizeof(s) - 1)
 
 /* options visible for anyone */
-static be_options_t be_options = {
+be_options_t be_options = {
        DUMP_NONE,                         /* dump flags */
        BE_TIME_OFF,                       /* no timing */
        false,                             /* profile_generate */
@@ -90,6 +89,7 @@ static be_options_t be_options = {
        "",                                /* ilp solver */
        0,                                 /* enable statistic event dumping */
        "",                                /* print stat events */
+       1,                                 /* verbose assembler output */
 };
 
 /* back end instruction set architecture to use */
@@ -135,6 +135,7 @@ static const lc_opt_table_entry_t be_main_options[] = {
        LC_OPT_ENT_BOOL     ("profileuse",      "use existing profile data",                           &be_options.opt_profile_use),
        LC_OPT_ENT_BOOL     ("statev",     "dump statistic events",                               &be_options.statev),
        LC_OPT_ENT_STR      ("filtev",     "filter for stat events (regex if support is active",   be_options.filtev),
+       LC_OPT_ENT_BOOL     ("verboseasm", "enable verbose assembler output",                     &be_options.verbose_asm),
 
        LC_OPT_ENT_STR("ilp.server", "the ilp server name", be_options.ilp_server),
        LC_OPT_ENT_STR("ilp.solver", "the ilp solver name", be_options.ilp_solver),
@@ -361,6 +362,36 @@ const backend_params *be_get_backend_param(void)
        return isa_if->get_params();
 }
 
+int be_is_big_endian(void)
+{
+       return be_get_backend_param()->byte_order_big_endian;
+}
+
+unsigned be_get_machine_size(void)
+{
+       return be_get_backend_param()->machine_size;
+}
+
+ir_mode *be_get_mode_float_arithmetic(void)
+{
+       return be_get_backend_param()->mode_float_arithmetic;
+}
+
+ir_type *be_get_type_long_long(void)
+{
+       return be_get_backend_param()->type_long_long;
+}
+
+ir_type *be_get_type_unsigned_long_long(void)
+{
+       return be_get_backend_param()->type_unsigned_long_long;
+}
+
+ir_type *be_get_type_long_double(void)
+{
+       return be_get_backend_param()->type_long_double;
+}
+
 /**
  * Initializes the main environment for the backend.
  *
@@ -371,7 +402,6 @@ static be_main_env_t *be_init_env(be_main_env_t *env, FILE *file_handle,
                                   const char *compilation_unit_name)
 {
        memset(env, 0, sizeof(*env));
-       env->options              = &be_options;
        env->file_handle          = file_handle;
        env->ent_trampoline_map   = pmap_create();
        env->pic_trampolines_type = new_type_class(NEW_ID("$PIC_TRAMPOLINE_TYPE"));
@@ -429,9 +459,10 @@ static void initialize_birg(be_irg_t *birg, ir_graph *irg, be_main_env_t *env)
        birg->irg = irg;
        birg->main_env = env;
        obstack_init(&birg->obst);
+       birg->lv = be_liveness_new(irg);
 
-       edges_deactivate_kind(irg, EDGE_KIND_DEP);
-       edges_activate_kind(irg, EDGE_KIND_DEP);
+       edges_deactivate(irg);
+       edges_activate(irg);
 
        /* set the current graph (this is important for several firm functions) */
        current_ir_graph = irg;
@@ -448,7 +479,7 @@ static void initialize_birg(be_irg_t *birg, ir_graph *irg, be_main_env_t *env)
        remove_bads(irg);
 
        /* Ensure, that the ir_edges are computed. */
-       edges_assure(irg);
+       assure_edges(irg);
 
        set_irg_phase_state(irg, phase_backend);
        be_info_init_irg(irg);
@@ -465,6 +496,7 @@ static const char *get_timer_name(be_timer_id_t id)
        case T_CODEGEN:        return "codegen";
        case T_RA_PREPARATION: return "ra_preparation";
        case T_SCHED:          return "sched";
+       case T_SPLIT:          return "split";
        case T_CONSTR:         return "constr";
        case T_FINISH:         return "finish";
        case T_EMIT:           return "emit";
@@ -519,7 +551,9 @@ static void be_main_loop(FILE *file_handle, const char *cup_name)
 {
        static const char suffix[] = ".prof";
 
-       size_t        i, num_birgs;
+       size_t        i;
+       size_t        num_irgs;
+       size_t        num_birgs;
        be_main_env_t env;
        char          prof_filename[256];
        be_irg_t      *birgs;
@@ -542,15 +576,19 @@ static void be_main_loop(FILE *file_handle, const char *cup_name)
        arch_env = env.arch_env;
 
        /* we might need 1 birg more for instrumentation constructor */
-       num_birgs = get_irp_n_irgs();
-       birgs     = ALLOCAN(be_irg_t, num_birgs + 1);
+       num_irgs = get_irp_n_irgs();
+       birgs    = ALLOCAN(be_irg_t, num_irgs + 1);
 
        be_info_init();
 
        /* First: initialize all birgs */
-       for (i = 0; i < num_birgs; ++i) {
-               ir_graph *irg = get_irp_irg(i);
-               initialize_birg(&birgs[i], irg, &env);
+       num_birgs = 0;
+       for (i = 0; i < num_irgs; ++i) {
+               ir_graph  *irg    = get_irp_irg(i);
+               ir_entity *entity = get_irg_entity(irg);
+               if (get_entity_linkage(entity) & IR_LINKAGE_NO_CODEGEN)
+                       continue;
+               initialize_birg(&birgs[num_birgs++], irg, &env);
        }
        arch_env_handle_intrinsics(arch_env);
 
@@ -561,18 +599,35 @@ static void be_main_loop(FILE *file_handle, const char *cup_name)
        sprintf(prof_filename, "%.*s%s",
                (int)(sizeof(prof_filename) - sizeof(suffix)), cup_name, suffix);
 
+       bool have_profile = false;
        if (be_options.opt_profile_use) {
                bool res = ir_profile_read(prof_filename);
                if (!res) {
                        fprintf(stderr, "Warning: Couldn't read profile data '%s'\n",
                                prof_filename);
+               } else {
+                       ir_create_execfreqs_from_profile();
+                       ir_profile_free();
+                       have_profile = true;
                }
        }
+
        if (num_birgs > 0 && be_options.opt_profile_generate) {
-               ir_graph *prof_init_irg
-                       = ir_profile_instrument(prof_filename);
+               ir_graph *const prof_init_irg = ir_profile_instrument(prof_filename);
+               assert(prof_init_irg->be_data == NULL);
                initialize_birg(&birgs[num_birgs], prof_init_irg, &env);
                num_birgs++;
+               num_irgs++;
+               assert(num_irgs == get_irp_n_irgs());
+       }
+
+       if (!have_profile) {
+               be_timer_push(T_EXECFREQ);
+               for (i = 0; i < num_irgs; ++i) {
+                       ir_graph *irg = get_irp_irg(i);
+                       ir_estimate_execfreq(irg);
+               }
+               be_timer_pop(T_EXECFREQ);
        }
 
        /* For all graphs */
@@ -653,21 +708,6 @@ static void be_main_loop(FILE *file_handle, const char *cup_name)
 
                dump(DUMP_PREPARED, irg, "code-selection");
 
-               be_timer_push(T_EXECFREQ);
-               /**
-                * Create execution frequencies from profile data or estimate some
-                */
-               if (ir_profile_has_data())
-                       birg->exec_freq = ir_create_execfreqs_from_profile(irg);
-               else {
-                       /* TODO: edges are corrupt for EDGE_KIND_BLOCK after the local
-                        * optimize graph phase merges blocks in the x86 backend */
-                       edges_deactivate(irg);
-                       birg->exec_freq = compute_execfreq(irg, 10);
-               }
-               be_timer_pop(T_EXECFREQ);
-
-
                /* disabled for now, fails for EmptyFor.c and XXEndless.c */
                /* be_live_chk_compare(irg); */
 
@@ -716,8 +756,7 @@ static void be_main_loop(FILE *file_handle, const char *cup_name)
                be_timer_pop(T_VERIFY);
 
                if (stat_ev_enabled) {
-                       stat_ev_dbl("bemain_costs_before_ra",
-                                       be_estimate_irg_costs(irg, birg->exec_freq));
+                       stat_ev_dbl("bemain_costs_before_ra", be_estimate_irg_costs(irg));
                        be_stat_ev("bemain_insns_before_ra", be_count_insns(irg));
                        be_stat_ev("bemain_blocks_before_ra", be_count_blocks(irg));
                }
@@ -725,7 +764,7 @@ static void be_main_loop(FILE *file_handle, const char *cup_name)
                /* Do register allocation */
                be_allocate_registers(irg);
 
-               stat_ev_dbl("bemain_costs_before_ra", be_estimate_irg_costs(irg, birg->exec_freq));
+               stat_ev_dbl("bemain_costs_before_ra", be_estimate_irg_costs(irg));
 
                dump(DUMP_RA, irg, "ra");
 
@@ -805,7 +844,6 @@ static void be_main_loop(FILE *file_handle, const char *cup_name)
 
        arch_env_end_codegeneration(arch_env);
 
-       ir_profile_free();
        be_done_env(&env);
 
        be_info_free();