* Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
*/
-
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
-#include "irflag.h"
#include "firm_common.h"
-
-
-/* 0 - don't do this optimization
- 1 - lets see, if there is a better graph */
-int optimized = 1; /* Turn off all optimizations. */
-
-int opt_cse = 1; /* Hash the nodes. */
-int opt_global_cse = 0; /* Don't use block predecessor for comparison.
- Default must be zero as code placement must
- be run right after a local optimize walk with
- opt_global_cse on. */
-int opt_constant_folding = 1; /* Evaluate operations. */
-int opt_unreachable_code = 1; /* Bad node propagation. */
-int opt_control_flow_straightening = 1; /* */
-int opt_control_flow_weak_simplification = 1; /* */
-int opt_control_flow_strong_simplification = 1; /* */
-int opt_critical_edges = 1;
-int opt_dead_node_elimination = 1; /* Reclaim memory. */
-int opt_reassociation = 1; /* Reassociate nodes. */
-int opt_inline = 1; /* Do inlining transformation. */
-int opt_dyn_meth_dispatch = 1; /* Remove dynamic method dispatch. */
-
-int opt_normalize = 1; /* Transformations that normalize the firm representation
- as removing Ids and Tuples, useless Phis, SymConst(id) ->
- Const(entity) ... */
+#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
+
+optimization_state_t libFIRM_opt =
+ ENABLE(OPT_OPTIMIZED) |
+ ENABLE(OPT_CSE) |
+ DISABLE(OPT_GLOBAL_CSE) |
+ ENABLE(OPT_STRENGTH_RED) |
+ ENABLE(OPT_CONSTANT_FOLDING) |
+ ENABLE(OPT_REDUNDANT_LOADSTORE) |
+ 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_DEAD_METHOD_ELIMINATION) |
+ ENABLE(OPT_REASSOCIATION) |
+ ENABLE(OPT_INLINE) |
+ ENABLE(OPT_DYN_METH_DISPATCH) |
+ ENABLE(OPT_NORMALIZE) |
+ ENABLE(OPT_TAIL_RECURSION) |
+ ENABLE(OPT_PRECISE_EXC_CONTEXT) |
+ 0;
/* set the flags with set_flagname, get the flag with get_flagname */
-INLINE void
-set_opt_cse (int value)
+void set_opt_cse (int value)
{
- opt_cse = value;
+ if (value)
+ libFIRM_opt |= OPT_CSE;
+ else
+ libFIRM_opt &= ~OPT_CSE;
}
-INLINE int
-get_opt_cse (void)
+void set_opt_global_cse(int value)
{
- return opt_cse;
+ if (value)
+ libFIRM_opt |= OPT_GLOBAL_CSE;
+ else
+ libFIRM_opt &= ~OPT_GLOBAL_CSE;
}
-void set_opt_global_cse (int value)
+void set_opt_strength_red (int value)
{
- opt_global_cse = value;
+ if (value)
+ libFIRM_opt |= OPT_STRENGTH_RED;
+ else
+ libFIRM_opt &= ~OPT_STRENGTH_RED;
}
-int get_opt_global_cse (void)
+void
+set_opt_constant_folding(int value)
{
- return opt_global_cse;
+ if (value)
+ libFIRM_opt |= OPT_CONSTANT_FOLDING;
+ else
+ libFIRM_opt &= ~OPT_CONSTANT_FOLDING;
}
-INLINE void
-set_opt_constant_folding (int value)
-{
- opt_constant_folding=value;
+void
+set_opt_redundant_LoadStore(int value) {
+ if (value)
+ libFIRM_opt |= OPT_REDUNDANT_LOADSTORE;
+ else
+ libFIRM_opt &= ~OPT_REDUNDANT_LOADSTORE;
}
-INLINE int
-get_opt_constant_folding (void)
-{
- return opt_constant_folding;
-}
-
-INLINE void
+void
set_opt_unreachable_code(int value)
{
- opt_unreachable_code = value;
+ if (value)
+ libFIRM_opt |= OPT_UNREACHABLE_CODE;
+ else
+ libFIRM_opt &= ~OPT_UNREACHABLE_CODE;
}
-INLINE int
-get_opt_unreachable_code(void)
+void set_opt_control_flow(int value)
{
- return opt_unreachable_code;
-}
-
-INLINE 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);
}
/* Performs Straightening */
-void set_opt_control_flow_straightening(int value) {
- opt_control_flow_straightening = value;
-}
-int get_opt_control_flow_straightening(void) {
- return opt_control_flow_straightening;
+void set_opt_control_flow_straightening(int value)
+{
+ if (value)
+ libFIRM_opt |= OPT_CONTROL_FLOW_STRAIGHTENING;
+ else
+ libFIRM_opt &= ~OPT_CONTROL_FLOW_STRAIGHTENING;
}
+
/* Performs if simplifications in local optimizations. */
-void set_opt_control_flow_weak_simplification(int value) {
- opt_control_flow_weak_simplification = value;
-}
-int get_opt_control_flow_weak_simplification(void) {
- return opt_control_flow_weak_simplification;
+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;
}
+
/* Performs strong if and loop simplification (in optimize_cf). */
-void set_opt_control_flow_strong_simplification(int value) {
- opt_control_flow_strong_simplification = value;
-}
-int get_opt_control_flow_strong_simplification(void) {
- return opt_control_flow_strong_simplification;
+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;
}
-void set_opt_critical_edges(int value) {
- opt_critical_edges = value;
-}
-int get_opt_critical_edges(void) {
- return opt_critical_edges;
+void set_opt_critical_edges(int value)
+{
+ if (value)
+ libFIRM_opt |= OPT_CRITICAL_EDGES;
+ else
+ libFIRM_opt &= ~OPT_CRITICAL_EDGES;
}
-
-INLINE void
-set_opt_reassociation(int value)
+void set_opt_reassociation(int value)
{
- opt_reassociation = value;
+ if (value)
+ libFIRM_opt |= OPT_REASSOCIATION;
+ else
+ libFIRM_opt &= ~OPT_REASSOCIATION;
}
-INLINE int
-get_opt_reassociation(void)
+void set_opt_dead_node_elimination(int value)
{
- return opt_reassociation;
+ if (value)
+ libFIRM_opt |= OPT_DEAD_NODE_ELIMINATION;
+ else
+ libFIRM_opt &= ~OPT_DEAD_NODE_ELIMINATION;
}
-INLINE void
-set_opt_dead_node_elimination (int value)
-{
- opt_dead_node_elimination = value;
+void set_opt_dead_method_elimination (int value) {
+ if (value)
+ libFIRM_opt |= OPT_DEAD_METHOD_ELIMINATION;
+ else
+ libFIRM_opt &= ~OPT_DEAD_METHOD_ELIMINATION;
}
-INLINE int
-get_opt_dead_node_elimination (void)
-{
- return opt_dead_node_elimination;
+void set_opt_dead_method_elimination_verbose (int value) {
+ if (value)
+ libFIRM_opt |= OPT_DEAD_METHOD_ELIMINATION_VERBOSE;
+ else
+ libFIRM_opt &= ~OPT_DEAD_METHOD_ELIMINATION_VERBOSE;
}
-INLINE void
-set_optimize (int value)
+void set_optimize(int value)
{
- optimized = value;
+ if (value)
+ libFIRM_opt |= OPT_OPTIMIZED;
+ else
+ libFIRM_opt &= ~OPT_OPTIMIZED;
}
-INLINE int
-get_optimize (void)
+int get_optimize(void)
{
- return optimized;
+ return get_opt_optimize();
}
-
-INLINE void set_opt_inline (int value) {
- opt_inline = value;
+/* Enable/Disables inlining. */
+void set_opt_inline(int value)
+{
+ if (value)
+ libFIRM_opt |= OPT_INLINE;
+ else
+ libFIRM_opt &= ~OPT_INLINE;
}
-INLINE int get_opt_inline (void) {
- return opt_inline;
+/* Enable/Disable optimization of dynamic method dispatch */
+void set_opt_dyn_meth_dispatch (int value)
+{
+ if (value)
+ libFIRM_opt |= OPT_DYN_METH_DISPATCH;
+ else
+ libFIRM_opt &= ~OPT_DYN_METH_DISPATCH;
}
-/** 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) {
- opt_dyn_meth_dispatch = value;
-}
-int get_opt_dyn_meth_dispatch (void) {
- return opt_dyn_meth_dispatch;
+/* Enable/Disable normalizations of the firm representation. */
+void set_opt_normalize(int value)
+{
+ if (value)
+ libFIRM_opt |= OPT_NORMALIZE;
+ else
+ libFIRM_opt &= ~OPT_NORMALIZE;
}
+/* Enable/Disable optimization of tail-recursion calls. */
+void set_opt_tail_recursion(int value)
+{
+ if (value)
+ libFIRM_opt |= OPT_TAIL_RECURSION;
+ else
+ libFIRM_opt &= ~OPT_TAIL_RECURSION;
+}
+/* Enable/Disable precise exception context. */
+void set_opt_precise_exc_context(int value)
+{
+#if PRECISE_EXC_CONTEXT
+ if (value)
+ libFIRM_opt |= OPT_PRECISE_EXC_CONTEXT;
+ else
+ libFIRM_opt &= ~OPT_PRECISE_EXC_CONTEXT;
+#endif
+}
-INLINE void set_opt_normalize (int value) {
- opt_normalize = value;
+/* Save the current optimization state. */
+void save_optimization_state(optimization_state_t *state)
+{
+ *state = libFIRM_opt;
}
-INLINE int get_opt_normalize (void) {
- return opt_normalize;
+/* Restore the current optimization state. */
+void restore_optimization_state(const optimization_state_t *state)
+{
+ libFIRM_opt = *state;
}