- introduced better running flags
authorMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Thu, 20 Sep 2007 09:36:48 +0000 (09:36 +0000)
committerMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Thu, 20 Sep 2007 09:36:48 +0000 (09:36 +0000)
- fixed wrong condition in iropt.c

[r15896]

include/libfirm/irflag.h
ir/ir/irarch.c
ir/ir/irflag.c
ir/ir/irflag_t.def
ir/ir/irflag_t.h
ir/ir/iropt.c
ir/opt/reassoc.c

index 90beacc..ca907ef 100644 (file)
@@ -335,12 +335,6 @@ void set_opt_precise_exc_context(int value);
  */
 void set_opt_alias_analysis(int value);
 
-/** Internal Flag, set if architecture dependent Mul to SASL chain was running.
- *
- * If set, some local optimizations that collide with the SASL conversion are disabled.
- */
-void set_opt_arch_dep_running(int value);
-
 /** Enable/Disable closed world assumption.
  *
  * If enabled, optimizations expect to know the "whole world", i.e. no
index 2431931..55db089 100644 (file)
@@ -79,9 +79,6 @@ void arch_dep_init(arch_dep_params_factory_t factory) {
 
 void arch_dep_set_opts(arch_dep_opts_t the_opts) {
        opts = the_opts;
-
-       if (opts & arch_dep_mul_to_shift)
-               set_opt_arch_dep_running(1);
 }
 
 /** check, whether a mode allows a Mulh instruction. */
@@ -570,30 +567,34 @@ ir_node *arch_dep_replace_mul_with_shifts(ir_node *irn) {
        if (params == NULL || (opts & arch_dep_mul_to_shift) == 0)
                return irn;
 
-       if (is_Mul(irn) && mode_is_int(mode)) {
-               ir_node *left    = get_binop_left(irn);
-               ir_node *right   = get_binop_right(irn);
-               tarval *tv       = NULL;
-               ir_node *operand = NULL;
-
-               /* Look, if one operand is a constant. */
-               if (is_Const(left)) {
-                       tv = get_Const_tarval(left);
-                       operand = right;
-               } else if (is_Const(right)) {
-                       tv = get_Const_tarval(right);
-                       operand = left;
-               }
+       set_arch_dep_running(1);
+       {
+               if (is_Mul(irn) && mode_is_int(mode)) {
+                       ir_node *left    = get_binop_left(irn);
+                       ir_node *right   = get_binop_right(irn);
+                       tarval *tv       = NULL;
+                       ir_node *operand = NULL;
+
+                       /* Look, if one operand is a constant. */
+                       if (is_Const(left)) {
+                               tv = get_Const_tarval(left);
+                               operand = right;
+                       } else if (is_Const(right)) {
+                               tv = get_Const_tarval(right);
+                               operand = left;
+                       }
 
-               if (tv != NULL) {
-                       res = do_decomposition(irn, operand, tv);
+                       if (tv != NULL) {
+                               res = do_decomposition(irn, operand, tv);
 
-                       if (res != irn) {
-                               hook_arch_dep_replace_mul_with_shifts(irn);
-                               exchange(irn, res);
+                               if (res != irn) {
+                                       hook_arch_dep_replace_mul_with_shifts(irn);
+                                       exchange(irn, res);
+                               }
                        }
                }
        }
+       set_arch_dep_running(0);
 
        return res;
 }
index 92cfcb4..6910150 100644 (file)
 #define ON     (-1)
 #define OFF  (0)
 
-#define FLAG(name, value, def) (irf_##name & def) |
-#define E_FLAG(name, value, def)       FLAG(name, value, def)
-#define I_FLAG(name, value, def)       FLAG(name, value, def)
+#define FLAG(name, value, def)     (irf_##name & def) |
+#define E_FLAG(name, value, def)    FLAG(name, value, def)
+#define I_FLAG(name, value, def)    FLAG(name, value, def)
+#define R_FLAG(name, value)
 
 optimization_state_t libFIRM_opt =
 #include "irflag_t.def"
@@ -53,7 +54,10 @@ optimization_state_t libFIRM_opt =
 #undef FLAG
 #undef E_FLAG
 #undef I_FLAG
+#undef R_FLAG
 
+/** The bitset of currently running phases. */
+optimization_state_t libFIRM_running = 0;
 
 /* verbose is always off on default */
 optimization_state_t libFIRM_verb = 0;
@@ -86,11 +90,14 @@ void set_opt_##name##_verbose(int flag) { \
   else      libFIRM_verb &= ~irf_##name;  \
 }
 
+#define R_FLAG(name, value)
+
 /* generate them */
 #include "irflag_t.def"
 
 #undef I_FLAG
 #undef E_FLAG
+#undef R_FLAG
 
 /* for compatibility reasons */
 void set_optimize(int value) {
@@ -143,9 +150,11 @@ void firm_show_flags(FILE *f) {
   printf("Firm optimization state:\n");
 #define E_FLAG(name, value, def) printf(" %-20s = %s\n", #name, get_opt_##name() ? "ON" : "OFF");
 #define I_FLAG(name, value, def) printf(" %-20s = %s\n", #name, get_opt_##name() ? "ON" : "OFF");
+#define R_FLAG(name, value)      printf(" %-20s = %s\n", #name, is_##name##_running() ? "is running" : "not running");
 #include "irflag_t.def"
 #undef I_FLAG
 #undef E_FLAG
+#undef R_FLAG
   printf("\n");
 }
 #endif
@@ -154,15 +163,16 @@ void firm_show_flags(FILE *f) {
 static const lc_opt_table_entry_t firm_flags[] = {
 #define I_FLAG(name, val, def) LC_OPT_ENT_BIT(#name, #name, &libFIRM_opt, (1 << val)),
 #define E_FLAG(name, val, def) LC_OPT_ENT_BIT(#name, #name, &libFIRM_opt, (1 << val)),
+#define R_FLAG(name, val)
 #include "irflag_t.def"
 #undef I_FLAG
 #undef E_FLAG
+#undef R_FLAG
        LC_OPT_LAST
 };
 #endif
 
-void firm_init_flags(void)
-{
+void firm_init_flags(void) {
 #ifdef WITH_LIBCORE
        lc_opt_entry_t *grp = lc_opt_get_grp(firm_opt_get_root(), "opt");
        lc_opt_add_table(grp, firm_flags);
index c64bb3b..7283319 100644 (file)
  * @version   $Id$
  */
 
+/*
+ * We have 3 kinds of flags:
+ * I_FLAGS are INTERNAL flags: The is only a public set_opt_<flag> function
+ * E_FLAGS are EXTERNAL flags: Public get_opt_<flag> and set_opt_<flag> fucntions exists
+ * R_FLAGS are RUNNING flags: Use only internally in libfirm to indicate running states
+ */
+
 /** Turn off all optimizations. */
 I_FLAG(optimize                           , 0, ON)
 
@@ -114,11 +121,13 @@ I_FLAG(auto_create_sync                   , 27, OFF)
 /** Enable Alias-analysis. */
 I_FLAG(alias_analysis                     , 28, ON)
 
+/** Closed world assumption. */
+I_FLAG(closed_world                       , 31, OFF)
+
+/* -------------------- RUNNING flags ------------------- */
+
 /** This flag is set while the reassociation optimizations are running */
-I_FLAG(reassoc_running                    , 29, OFF)
+R_FLAG(reassoc                            , 0)
 
 /** This flag is set while architecture dependent optimizations are running */
-I_FLAG(arch_dep_running                   , 30, OFF)
-
-/** Closed world assumption. */
-I_FLAG(closed_world                       , 31, OFF)
+R_FLAG(arch_dep                           , 0)
index 8880c1d..92041a1 100644 (file)
 #include "irflag.h"
 
 /**
- * current libFIRM optimizations
+ * libFIRM optimizations flags
  */
 typedef enum {
-#define E_FLAG(name, value, def)       irf_##name = (1 << value),
-#define I_FLAG(name, value, def)       irf_##name = (1 << value),
+#define E_FLAG(name, value, def)    irf_##name = (1 << value),
+#define I_FLAG(name, value, def)    irf_##name = (1 << value),
+#define R_FLAG(name, value)
 
 #include "irflag_t.def"
        irf_last
 #undef I_FLAG
 #undef E_FLAG
+#undef R_FLAG
 } libfirm_opts_t;
 
-extern optimization_state_t libFIRM_opt;
-extern optimization_state_t libFIRM_verb;
+/**
+ * libFIRM running flags
+ */
+typedef enum {
+#define E_FLAG(name, value, def)
+#define I_FLAG(name, value, def)
+#define R_FLAG(name, value)         ir_rf_##name = (1 << value),
+
+#include "irflag_t.def"
+       ir_rf_last
+#undef I_FLAG
+#undef E_FLAG
+#undef R_FLAG
+} libfirm_opts_t;
+
+extern optimization_state_t libFIRM_opt, libFIRM_running, libFIRM_verb;
 extern firm_verification_t opt_do_node_verification;
 
 extern int firm_verbosity_level;
@@ -70,10 +86,21 @@ static INLINE int get_opt_##name##_verbose(void) { \
   return libFIRM_verb & irf_##name;                \
 }
 
+/* generate getter and setter functions for running flags */
+#define R_FLAG(name, value)                        \
+static INLINE int is_##name##_running(void) {      \
+  return libFIRM_running & ir_rf_##name;           \
+}                                                  \
+static INLINE void set_##name##_running(int flag) {\
+  if (flag) libFIRM_running |= ir_rf_##name;       \
+  else      libFIRM_running &= ~ir_rf_##name;      \
+}
+
 #include "irflag_t.def"
 
 #undef I_FLAG
 #undef E_FLAG
+#undef R_FLAG
 
 static INLINE int _get_firm_verbosity (void) {
        return firm_verbosity_level;
index a16a2b0..724a634 100644 (file)
@@ -1908,7 +1908,7 @@ static ir_node *transform_node_Add(ir_node *n) {
 
        if (mode_is_num(mode)) {
                /* the following code leads to endless recursion when Mul are replaced by a simple instruction chain */
-               if (!get_opt_arch_dep_running() && a == b && mode_is_int(mode)) {
+               if (!is_arch_dep_running() && a == b && mode_is_int(mode)) {
                        ir_node *block = get_irn_n(n, -1);
 
                        n = new_rd_Mul(
@@ -1943,7 +1943,7 @@ static ir_node *transform_node_Add(ir_node *n) {
                        DBG_OPT_ALGSIM0(oldn, n, FS_OPT_ADD_A_MINUS_B);
                        return n;
                }
-               if (! get_opt_reassoc_running()) {
+               if (! is_reassoc_running()) {
                        /* do NOT execute this code if reassociation is enabled, it does the inverse! */
                        if (is_Mul(a)) {
                                ir_node *ma = get_Mul_left(a);
@@ -2247,7 +2247,7 @@ restart:
                }
        }
        /* do NOT execute this code if reassociation is enabled, it does the inverse! */
-       if (get_opt_reassoc_running() && is_Mul(a)) {
+       if (!is_reassoc_running() && is_Mul(a)) {
                ir_node *ma = get_Mul_left(a);
                ir_node *mb = get_Mul_right(a);
 
index 1890716..4e267df 100644 (file)
@@ -762,7 +762,7 @@ void optimize_reassociation(ir_graph *irg)
        env.wq      = new_waitq();
 
        /* disable some optimizations while reassoc is running to prevent endless loops */
-       set_opt_reassoc_running(1);
+       set_reassoc_running(1);
        {
                /* now we have collected enough information, optimize */
                irg_walk_graph(irg, NULL, wq_walker, &env);
@@ -771,7 +771,7 @@ void optimize_reassociation(ir_graph *irg)
                /* reverse those rules that do not result in collapsed constants */
                irg_walk_graph(irg, NULL, reverse_rules, &env);
        }
-       set_opt_reassoc_running(0);
+       set_reassoc_running(0);
 
        /* Handle graph state */
        if (env.changes) {