More work for C++ mode:
[cparser] / driver / firm_opt.c
index 004ef32..7b0e3a6 100644 (file)
@@ -19,6 +19,7 @@
 #include "firm_codegen.h"
 #include "firm_cmdline.h"
 #include "firm_timing.h"
+#include "ast2firm.h"
 
 #ifdef _WIN32
 #define snprintf _snprintf
@@ -309,6 +310,7 @@ static void do_optimize_funccalls(void)
 static void do_gcse(ir_graph *irg)
 {
        set_opt_global_cse(1);
+       optimize_graph_df(irg);
        place_code(irg);
        set_opt_global_cse(0);
 }
@@ -330,7 +332,7 @@ static void do_stred(ir_graph *irg)
 
 static void do_inline(void)
 {
-       inline_functions(500, 50);
+       inline_functions(firm_opt.inline_maxsize, firm_opt.inline_threshold);
 }
 
 static void do_cloning(void)
@@ -340,7 +342,7 @@ static void do_cloning(void)
 
 static void do_lower_switch(ir_graph *irg)
 {
-       lower_switch(irg, 128);
+       lower_switch(irg, firm_opt.spare_size);
 }
 
 typedef enum opt_target {
@@ -378,7 +380,7 @@ static opt_config_t opts[] = {
        { OPT_TARGET_IRG, "place",       (func_ptr_t) place_code,              true, true,  true,  TV_CODE_PLACE },
        { OPT_TARGET_IRG, "confirm",     (func_ptr_t) construct_confirms,      true, true,  true,  TV_CONFIRM_CREATE },
        { OPT_TARGET_IRG, "ldst",        (func_ptr_t) optimize_load_store,     true, true,  true,  TV_LOAD_STORE },
-       { OPT_TARGET_IRG, "ldst2",       (func_ptr_t) opt_ldst2,               true, true,  true,  -1 },
+       { OPT_TARGET_IRG, "sync",        (func_ptr_t) opt_sync,                true, true,  true,  -1 },
        { OPT_TARGET_IRG, "lower",       (func_ptr_t) do_lower_highlevel,      true, true,  true,  -1 },
        { OPT_TARGET_IRG, "deconv",      (func_ptr_t) conv_opt,                true, true,  true,  TV_DECONV },
        { OPT_TARGET_IRG, "condeval",    (func_ptr_t) opt_cond_eval,           true, true,  true,  TV_COND_EVAL },
@@ -386,6 +388,7 @@ static opt_config_t opts[] = {
        { OPT_TARGET_IRG, "gvnpre",      (func_ptr_t) do_gvn_pre,              true, true,  true,  -1 },
        { OPT_TARGET_IRG, "ifconv",      (func_ptr_t) do_if_conv,              true, true,  true,  TV_IF_CONV },
        { OPT_TARGET_IRG, "bool",        (func_ptr_t) opt_bool,                true, true,  true,  -1 },
+       { OPT_TARGET_IRG, "shape-blocks",(func_ptr_t) shape_blocks,            true, true,  true,  TV_END_MELT },
        { OPT_TARGET_IRG, "stred",       (func_ptr_t) do_stred,                true, true,  true,  TV_OSR },
        { OPT_TARGET_IRG, "dead",        (func_ptr_t) dead_node_elimination,   true, false, true,  TV_DEAD_NODE },
        { OPT_TARGET_IRP, "inline",      (func_ptr_t) do_inline,               true, true,  true,  -1 },
@@ -478,6 +481,7 @@ static void do_firm_optimizations(const char *input_filename)
   set_opt_scalar_replacement(firm_opt.scalar_replace);
   set_opt_auto_create_sync(firm_opt.auto_sync);
   set_opt_alias_analysis(firm_opt.alias_analysis);
+  set_opt_combo(firm_opt.combo);
 
   aa_opt = aa_opt_no_opt;
   if (firm_opt.strict_alias)
@@ -496,13 +500,14 @@ static void do_firm_optimizations(const char *input_filename)
   set_opt_enabled("place", !firm_opt.gcse);
   set_opt_enabled("confirm", firm_opt.confirm);
   set_opt_enabled("remove_confirms", firm_opt.confirm);
-  set_opt_enabled("ldst2", firm_opt.luffig);
+  set_opt_enabled("sync", firm_opt.sync);
   set_opt_enabled("ldst", firm_opt.load_store);
   set_opt_enabled("deconv", firm_opt.deconv);
   set_opt_enabled("condeval", firm_opt.cond_eval);
   set_opt_enabled("gvnpre", firm_opt.gvn_pre);
   set_opt_enabled("ifconv", firm_opt.if_conversion);
   set_opt_enabled("bool", firm_opt.bool_opt);
+  set_opt_enabled("shape-blocks", firm_opt.shape_blocks);
   set_opt_enabled("inline", firm_opt.do_inline);
   set_opt_enabled("clone", firm_opt.cloning);
   set_opt_enabled("combo", firm_opt.combo);
@@ -533,12 +538,6 @@ static void do_firm_optimizations(const char *input_filename)
   for (i = 0; i < get_irp_n_irgs(); i++) {
     ir_graph *irg = get_irp_irg(i);
 
-#ifdef FIRM_EXT_GRS
-    /* If SIMD optimization is on, make sure we have only 1 return */
-    if (firm_ext_grs.create_pattern || firm_ext_grs.simd_opt)
-      do_irg_opt("onereturn");
-#endif
-
     do_irg_opt(irg, "scalar");
     do_irg_opt(irg, "local");
     do_irg_opt(irg, "reassoc");
@@ -554,13 +553,11 @@ static void do_firm_optimizations(const char *input_filename)
       do_irg_opt(irg, "local");
     }
 
-    do_irg_opt(irg, "ldst2");
     do_irg_opt(irg, "controlflow");
     do_irg_opt(irg, "ldst");
     do_irg_opt(irg, "lower");
     do_irg_opt(irg, "deconv");
     do_irg_opt(irg, "condeval");
-    do_irg_opt(irg, "lower_switch");
     do_irg_opt(irg, "remove_confirms");
     do_irg_opt(irg, "gvnpre");
     do_irg_opt(irg, "place");
@@ -573,6 +570,8 @@ static void do_firm_optimizations(const char *input_filename)
     }
 
     do_irg_opt(irg, "bool");
+    do_irg_opt(irg, "shape-blocks");
+    do_irg_opt(irg, "lower_switch");
     do_irg_opt(irg, "stred");
     do_irg_opt(irg, "local");
     do_irg_opt(irg, "dead");
@@ -797,21 +796,14 @@ static void do_firm_lowering(const char *input_filename)
 {
   int i;
 
-  /* do class lowering and vtbl creation */
-//  lower_classes_to_struct("vtbl", "m");
-
-#if 0
-  timer_push(TV_LOWER);
-  lower_highlevel();
-  timer_pop();
-#endif
-
   if (firm_opt.lower_ll) {
     lwrdw_param_t init = {
       1,
       1,
-      mode_Ls, mode_Lu,
-      mode_Is, mode_Iu,
+      get_atomic_mode(ATOMIC_TYPE_LONGLONG),
+      get_atomic_mode(ATOMIC_TYPE_ULONGLONG),
+      get_atomic_mode(ATOMIC_TYPE_INT),
+      get_atomic_mode(ATOMIC_TYPE_UINT),
       def_create_intrinsic_fkt,
       NULL
     };
@@ -843,14 +835,9 @@ static void do_firm_lowering(const char *input_filename)
     /* run reassociation first on all graphs BEFORE the architecture dependent optimizations
        are enabled */
     for (i = get_irp_n_irgs() - 1; i >= 0; --i) {
-      current_ir_graph = get_irp_irg(i);
-
-      timer_push(TV_REASSOCIATION);
-        optimize_reassociation(current_ir_graph);
-      timer_pop();
-      DUMP_ONE_C(firm_dump.ir_graph && firm_dump.all_phases, current_ir_graph, "reassoc");
-      CHECK_ONE(firm_opt.check_all, current_ir_graph);
-    }
+      ir_graph *irg = get_irp_irg(i);
+         do_irg_opt(irg, "reassoc");
+       }
 
     /* enable architecture dependent optimizations */
     arch_dep_set_opts((arch_dep_opts_t)
@@ -859,61 +846,23 @@ static void do_firm_lowering(const char *input_filename)
                       (firm_opt.mods ? arch_dep_mod_by_const : arch_dep_none) ));
 
     for (i = get_irp_n_irgs() - 1; i >= 0; --i) {
-      current_ir_graph = get_irp_irg(i);
-
-      if (firm_opt.gcse)
-        set_opt_global_cse(1);
-
-      timer_push(TV_LOCAL_OPT);
-        optimize_graph_df(current_ir_graph);
-      timer_pop();
-      DUMP_ONE_C(firm_dump.ir_graph && firm_dump.all_phases, current_ir_graph, "lopt");
-      if (! firm_opt.gcse)
-        CHECK_ONE(firm_opt.check_all, current_ir_graph);
-
-      if (firm_opt.gcse) {
-        timer_push(TV_CODE_PLACE);
-          place_code(current_ir_graph);
-          set_opt_global_cse(0);
-        timer_pop();
-        DUMP_ONE_C(firm_dump.ir_graph && firm_dump.all_phases, current_ir_graph, "place");
-        CHECK_ONE(firm_opt.check_all, current_ir_graph);
-      }
-
-      timer_push(TV_LOAD_STORE);
-        optimize_load_store(current_ir_graph);
-      timer_pop();
-      DUMP_ONE_C(firm_dump.ir_graph && firm_dump.all_phases, current_ir_graph, "ldst");
-      CHECK_ONE(firm_opt.check_all, current_ir_graph);
-
+      ir_graph *irg = get_irp_irg(i);
 
-      timer_push(TV_LOCAL_OPT);
-        optimize_graph_df(current_ir_graph);
-      timer_pop();
-      DUMP_ONE_C(firm_dump.ir_graph && firm_dump.all_phases, current_ir_graph, "lopt");
+      current_ir_graph = irg;
 
-      timer_push(TV_CF_OPT);
-        optimize_cf(current_ir_graph);
-      timer_pop();
-      DUMP_ONE_C(firm_dump.ir_graph && firm_dump.all_phases, current_ir_graph, "cf");
-      CHECK_ONE(firm_opt.check_all, current_ir_graph);
+         do_irg_opt(irg, "local");
+         do_irg_opt(irg, "gcse");
+         do_irg_opt(irg, "ldst");
+         do_irg_opt(irg, "local");
+         do_irg_opt(irg, "controlflow");
 
       if (firm_opt.if_conversion) {
-        timer_push(TV_IF_CONV);
-          opt_if_conv(current_ir_graph, if_conv_info);
-        timer_pop();
-        DUMP_ONE_C(firm_dump.ir_graph && firm_dump.all_phases, current_ir_graph, "if");
-        CHECK_ONE(firm_opt.check_all, current_ir_graph);
-
-        timer_push(TV_LOCAL_OPT);
-          optimize_graph_df(current_ir_graph);
-        timer_pop();
-        timer_push(TV_CF_OPT);
-          optimize_cf(current_ir_graph);
-        timer_pop();
-        DUMP_ONE_C(firm_dump.ir_graph && firm_dump.all_phases, current_ir_graph, "after_if");
-        CHECK_ONE(firm_opt.check_all, current_ir_graph);
-      }
+                 do_irg_opt(irg, "ifconv");
+                 do_irg_opt(irg, "local");
+                 do_irg_opt(irg, "controlflow");
+         }
+
+         do_irg_opt(current_ir_graph, "sync");
     }
     timer_stop(TV_ALL_OPT);
 
@@ -960,13 +909,6 @@ void gen_firm_init(void)
   params.cc_mask               = 0; /* no regparam, cdecl */
   params.builtin_dbg           = NULL;
 
-  #ifdef FIRM_EXT_GRS
-  /* Activate Graph rewriting if SIMD optimization is turned on */
-  /* This has to be done before init_firm() is called! */
-  if (firm_ext_grs.simd_opt)
-    ext_grs_activate();
-#endif
-
   init_firm(&params);
 
   if (firm_be_opt.selection == BE_FIRM_BE) {
@@ -984,23 +926,9 @@ void gen_firm_init(void)
     if (be_params->has_imm_fp_mode)
       firm_imm_fp_mode = be_params->imm_fp_mode;
   }
-  /* OS option must be set to the backend */
-  switch (firm_opt.os_support) {
-  case OS_SUPPORT_MINGW:
-    firm_be_option("ia32-gasmode=mingw");
-    break;
-  case OS_SUPPORT_MACHO:
-    firm_be_option("ia32-gasmode=macho");
-    break;
-  case OS_SUPPORT_LINUX:
-  default:
-    firm_be_option("ia32-gasmode=linux");
-    break;
-  }
 
   dbg_init(NULL, NULL, dbg_snprint);
   edges_init_dbg(firm_opt.vrfy_edges);
-  //cbackend_set_debug_retrieve(dbg_retrieve);
 
   set_opt_precise_exc_context(firm_opt.precise_exc);
   set_opt_fragile_ops(firm_opt.fragile_ops);
@@ -1135,23 +1063,6 @@ void gen_firm_finish(FILE *out, const char *input_filename, int c_mode, int new_
   for (i = get_irp_n_irgs() - 1; i >= 0; --i)
     set_irg_phase_low(get_irp_irg(i));
 
-
-#ifdef FIRM_EXT_GRS
-  /** SIMD Optimization  Extensions **/
-
-  /* Pattern creation step. No code has to be generated, so
-     exit after pattern creation */
-  if (firm_ext_grs.create_pattern) {
-    ext_grs_create_pattern();
-    exit(0);
-  }
-
-  /* SIMD optimization step. Uses graph patterns to find
-     rich instructions and rewrite */
-  if (firm_ext_grs.simd_opt)
-    ext_grs_simd_opt();
-#endif
-
   if (firm_dump.statistic & STAT_FINAL_IR)
     stat_dump_snapshot(input_filename, "final-ir");
 
@@ -1161,18 +1072,14 @@ void gen_firm_finish(FILE *out, const char *input_filename, int c_mode, int new_
 
   if (firm_dump.statistic & STAT_FINAL)
     stat_dump_snapshot(input_filename, "final");
-
-#if 0
-  if (firm_opt.ycomp_dbg)
-    firm_finish_ycomp_debugger();
-#endif
-}  /* gen_firm_finish */
+}
 
 /**
  * Do very early initializations
  */
-void firm_early_init(void) {
+void firm_early_init(void)
+{
   /* arg: need this here for command line options */
   be_opt_register();
   firm_init_options(NULL, 0, NULL);
-}  /* firm_early_init */
+}