#endif
#include <stdarg.h>
-#include <mcheck.h>
#include "obst.h"
#include "bitset.h"
#include "irloop_t.h"
#include "be_t.h"
+#include "beifg.h"
#include "bechordal_t.h"
#include "benumb_t.h"
#include "besched_t.h"
#include "beasm_dump_globals.h"
#include "beasm_asm_gnu.h"
+#include "firm2arch.h"
+
#undef DUMP_BEGIN
#undef DUMP_PREPARED
+#define DUMP_TRANSFORM
#define DUMP_SCHED
#define DUMP_SPILL
#undef DUMP_ALLOCATED
#undef DUMP_SSADESTR
#undef DUMP_END
+#undef DO_SSADESTR
+
#define N_PHASES 256
void be_init(void)
env->node_factory = obstack_alloc(&env->obst, sizeof(*env->node_factory));
be_node_factory_init(env->node_factory, isa);
- arch_env_add_irn_handler(env->arch_env, &firm_irn_handler);
- arch_env_add_irn_handler(env->arch_env,
- be_node_get_irn_handler(env->node_factory));
+ /* Register the irn handler of the architecture */
+ if (isa->irn_handler)
+ arch_env_add_irn_handler(env->arch_env, isa->irn_handler);
+
+ /*
+ * Register the node handler of the back end infrastructure.
+ * This irn handler takes care of the platform independent
+ * spill, reload and perm nodes.
+ */
+ arch_env_add_irn_handler(env->arch_env, be_node_get_irn_handler(env->node_factory));
return env;
}
static void be_main_loop(void)
{
- int i, n;
+ int i, j, m, n;
be_main_env_t env;
const arch_isa_if_t *isa;
be_init_env(&env);
isa = arch_env_get_isa(env.arch_env);
+ /* create required irop's */
+ create_bearch_asm_opcodes();
+
/* For all graphs */
for(i = 0, n = get_irp_n_irgs(); i < n; ++i) {
- int j, m;
ir_graph *irg = get_irp_irg(i);
be_main_session_env_t session;
- DBG((env.dbg, LEVEL_1, "====> IRG: %F\n", irg));
+ DBG((env.dbg, LEVEL_2, "====> IRG: %F\n", irg));
#ifdef DUMP_BEGIN
dump_ir_block_graph(irg, "-begin");
#endif
/* Compute some analyses and prepare the graph for backend use. */
prepare_graph(&session);
+
+ transform_firm(irg);
+
+#ifdef DUMP_TRANSFORM
+ dump_ir_block_graph(irg, "-transformed");
+#endif
+
+
#ifdef DUMP_PREPARED
dump_dominator_information(true);
dump_ir_block_graph(irg, "-prepared");
/* Schedule the graphs. */
list_sched(irg, trivial_selector);
+ be_sched_imm(irg);
#ifdef DUMP_SCHED
dump_ir_block_graph_sched(irg, "-sched");
/* Perform the following for each register class. */
for(j = 0, m = isa->get_n_reg_class(); j < m; ++j) {
be_chordal_env_t *chordal_env;
+ be_ifg_t *ifg;
+
const arch_register_class_t *cls = isa->get_reg_class(j);
DBG((env.dbg, LEVEL_1, "----> Reg class: %s\n", cls->name));
/* spilling */
-// be_spill_ilp(&session, cls);
+ //be_spill_ilp(&session, cls);
be_spill_belady(&session, cls);
#ifdef DUMP_SPILL
dump_ir_block_graph_sched(session.irg, "-spill");
be_numbering(irg);
be_check_pressure(&session, cls);
-#if 0
- {
- FILE *f;
- char buf[128];
- ir_snprintf(buf, sizeof(buf), "%F_%s-live.txt", irg, cls->name);
- if((f = fopen(buf, "wt")) != NULL) {
- be_liveness_dump(session.irg, f);
- fclose(f);
- }
- }
-#endif
-
/* allocation */
chordal_env = be_ra_chordal(&session, cls);
#ifdef DUMP_ALLOCATED
dump_allocated_irg(env.arch_env, irg, "");
#endif
+ /* Build the interference graph. */
+ ifg = be_ifg_std_new(chordal_env);
+
+#ifdef DO_SSADESTR
/* copy minimization */
copystat_collect_cls(chordal_env);
be_copy_opt(chordal_env);
be_ra_chordal_check(chordal_env);
#ifdef DUMP_SSADESTR
dump_allocated_irg(env.arch_env, irg, "-ssadestr");
+#endif
#endif
+ be_ifg_free(ifg);
be_ra_chordal_done(chordal_env);
be_numbering_done(irg);
}
void be_main(int argc, const char *argv[])
{
- assembler_t *gnu_assembler;
- FILE *asm_output_file;
+ FILE *asm_output_file;
- be_main_loop();
+ be_main_loop();
-#if 0
- gnu_assembler = gnuasm_create_assembler();
- asm_output_file = fopen("asm_output.asm", "w");
-
- asm_dump_globals(gnu_assembler);
- gnuasm_dump(gnu_assembler, asm_output_file);
- gnuasm_delete_assembler(gnu_assembler);
- fclose(asm_output_file);
-#endif
+ asm_output_file = fopen(argv[0], "w");
+ firmbe_gen_code(asm_output_file);
+ fclose(asm_output_file);
}