Fixed warnings introduced in 97080a1af7b7e8a4969d2fba25e065df417ff074.
[libfirm] / ir / ir / irflag.c
index 07004f2..dd4490f 100644 (file)
 /*
- * Project:     libFIRM
- * File name:   ir/ir/irflag.c
- * Purpose:     Flags to control optimizations.
- * Author:      Christian Schaefer, Goetz Lindenmaier
- * Modified by:
- * Created:
- * CVS-ID:      $Id$
- * Copyright:   (c) 1999-2003 Universität Karlsruhe
- * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
+ * 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.
  */
 
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
+/**
+ * @file
+ * @brief   Flags to control optimizations.
+ * @author  Michael Beck, Sebastian Hack
+ */
+#include "config.h"
+
+#include <stdio.h>
+
+#include "lc_opts.h"
 
 #include "firm_common.h"
+#include "irtools.h"
 #include "irflag_t.h"
 
 /* DISABLE - don't do this optimization
    ENABLE  - lets see, if there is a better graph */
-#define ENABLE(a)   a
-#define DISABLE(a)  0
+#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 R_FLAG(name, value)
 
 optimization_state_t libFIRM_opt =
-  ENABLE(OPT_OPTIMIZED)                          |
-  ENABLE(OPT_CSE)                                |
-  DISABLE(OPT_GLOBAL_CSE)                        |
-  ENABLE(OPT_CONSTANT_FOLDING)                   |
-  ENABLE(OPT_UNREACHABLE_CODE)                   |
-  ENABLE(OPT_CONTROL_FLOW_STRAIGHTENING)         |
-  ENABLE(OPT_CONTROL_FLOW_WEAK_SIMPLIFICATION)   |
-  ENABLE(OPT_CONTROL_FLOW_STRONG_SIMPLIFICATION) |
-  ENABLE(OPT_CRITICAL_EDGES)                     |
-  ENABLE(OPT_DEAD_NODE_ELIMINATION)              |
-  ENABLE(OPT_REASSOCIATION)                      |
-  ENABLE(OPT_INLINE)                             |
-  ENABLE(OPT_DYN_METH_DISPATCH)                  |
-  ENABLE(OPT_NORMALIZE);
-
-/* set the flags with set_flagname, get the flag with get_flagname */
-void set_opt_cse (int value)
-{
-  if (value)
-    libFIRM_opt |= OPT_CSE;
-  else
-    libFIRM_opt &= ~OPT_CSE;
-}
+#include "irflag_t.def"
+  0;
 
-void set_opt_global_cse(int value)
-{
-  if (value)
-    libFIRM_opt |= OPT_GLOBAL_CSE;
-  else
-    libFIRM_opt &= ~OPT_GLOBAL_CSE;
-}
+#undef FLAG
+#undef E_FLAG
+#undef I_FLAG
+#undef R_FLAG
 
-void
-set_opt_constant_folding(int value)
-{
-  if (value)
-    libFIRM_opt |= OPT_CONSTANT_FOLDING;
-  else
-    libFIRM_opt &= ~OPT_CONSTANT_FOLDING;
-}
+optimization_state_t libFIRM_running = 0;
 
-void
-set_opt_unreachable_code(int value)
-{
-  if (value)
-    libFIRM_opt |= OPT_UNREACHABLE_CODE;
-  else
-    libFIRM_opt &= ~OPT_UNREACHABLE_CODE;
-}
+optimization_state_t libFIRM_verb = 0;
 
-void set_opt_control_flow(int value)
-{
-  set_opt_control_flow_straightening(value);
-  set_opt_control_flow_weak_simplification(value);
-  set_opt_control_flow_strong_simplification(value);
-  set_opt_critical_edges(value);
-}
+void set_opt_optimize(int value);
 
-/* Performs Straightening */
-void set_opt_control_flow_straightening(int value)
-{
-  if (value)
-    libFIRM_opt |= OPT_CONTROL_FLOW_STRAIGHTENING;
-  else
-    libFIRM_opt &= ~OPT_CONTROL_FLOW_STRAIGHTENING;
+/* an external flag can be set and get from outside */
+#define E_FLAG(name, value, def)           \
+void set_opt_##name(int flag) {            \
+  if (flag) libFIRM_opt |= irf_##name;     \
+  else      libFIRM_opt &= ~irf_##name;    \
+}                                          \
+int (get_opt_##name)(void) {               \
+  return get_opt_##name##_();              \
 }
 
-/* Performs if simplifications in local optimizations. */
-void set_opt_control_flow_weak_simplification(int value)
-{
-  if (value)
-    libFIRM_opt |= OPT_CONTROL_FLOW_WEAK_SIMPLIFICATION;
-  else
-    libFIRM_opt &= ~OPT_CONTROL_FLOW_WEAK_SIMPLIFICATION;
-}
+/* an internal flag can only be set from outside */
+#define I_FLAG(name, value, def)          \
+void set_opt_##name(int flag) {           \
+  if (flag) libFIRM_opt |= irf_##name;    \
+  else      libFIRM_opt &= ~irf_##name;   \
+}                                         \
 
-/* Performs strong if and loop simplification (in optimize_cf). */
-void set_opt_control_flow_strong_simplification(int value)
-{
-  if (value)
-    libFIRM_opt |= OPT_CONTROL_FLOW_STRONG_SIMPLIFICATION;
-  else
-    libFIRM_opt &= ~OPT_CONTROL_FLOW_STRONG_SIMPLIFICATION;
-}
+#define R_FLAG(name, value)
 
-void set_opt_critical_edges(int value)
-{
-  if (value)
-    libFIRM_opt |= OPT_CRITICAL_EDGES;
-  else
-    libFIRM_opt &= ~OPT_CRITICAL_EDGES;
-}
+/* generate them */
+#include "irflag_t.def"
 
-void set_opt_reassociation(int value)
-{
-  if (value)
-    libFIRM_opt |= OPT_REASSOCIATION;
-  else
-    libFIRM_opt &= ~OPT_REASSOCIATION;
-}
+#undef I_FLAG
+#undef E_FLAG
+#undef R_FLAG
 
-void set_opt_dead_node_elimination(int value)
+void set_optimize(int value)
 {
-  if (value)
-    libFIRM_opt |= OPT_DEAD_NODE_ELIMINATION;
-  else
-    libFIRM_opt &= ~OPT_DEAD_NODE_ELIMINATION;
+       set_opt_optimize(value);
 }
 
-void set_optimize(int value)
+int (get_optimize)(void)
 {
-  if (value)
-    libFIRM_opt |= OPT_OPTIMIZED;
-  else
-    libFIRM_opt &= ~OPT_OPTIMIZED;
+       return get_opt_optimize();
 }
 
-int get_optimize(void)
+void save_optimization_state(optimization_state_t *state)
 {
-  return get_opt_optimize();
+       *state = libFIRM_opt;
 }
 
-void set_opt_inline(int value)
+void restore_optimization_state(const optimization_state_t *state)
 {
-  if (value)
-    libFIRM_opt |= OPT_INLINE;
-  else
-    libFIRM_opt &= ~OPT_INLINE;
+       libFIRM_opt = *state;
 }
 
-/** Enable/Disable optimization of dynamic method dispatch
- *
- * This flag enables/disables the optimization of dynamic method dispatch.
- * If the flag is turned on Sel nodes can be replaced by Const nodes representing
- * the address of a function.
- */
-void set_opt_dyn_meth_dispatch (int value)
+void all_optimizations_off(void)
 {
-  if (value)
-    libFIRM_opt |= OPT_DYN_METH_DISPATCH;
-  else
-    libFIRM_opt &= ~OPT_DYN_METH_DISPATCH;
+       libFIRM_opt = 0;
 }
 
-void set_opt_normalize(int value)
+#ifdef _DEBUG
+void firm_show_flags(FILE *f)
 {
-  if (value)
-    libFIRM_opt |= OPT_NORMALIZE;
-  else
-    libFIRM_opt &= ~OPT_NORMALIZE;
+       if (! f)
+               f = stdout;
+       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
 
-/* Save the current optimization state. */
-void save_optimization_state(optimization_state_t *state)
+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
+};
+
+void firm_init_flags(void)
 {
-  *state = libFIRM_opt;
+       lc_opt_entry_t *grp = lc_opt_get_grp(firm_opt_get_root(), "opt");
+       lc_opt_add_table(grp, firm_flags);
 }
 
-/* Restore the current optimization state. */
-void restore_optimization_state(const optimization_state_t *state)
+firm_verification_t opt_do_node_verification = FIRM_VERIFICATION_ON;
+
+void do_node_verification(firm_verification_t mode)
 {
-  libFIRM_opt = *state;
+       opt_do_node_verification = mode;
 }