X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fir%2Firflag.c;h=69101501269814fd6f3efeef0f15b5901a35f3b3;hb=fafb74ae9d50370cd4e9e815cb545187f0f1f421;hp=fdfbd2df0b1eccbcc90f1db5a5eab538ac082a86;hpb=e570f00fb465d212dde403160e97ab45d36d1d7e;p=libfirm diff --git a/ir/ir/irflag.c b/ir/ir/irflag.c index fdfbd2df0..691015012 100644 --- a/ir/ir/irflag.c +++ b/ir/ir/irflag.c @@ -1,178 +1,127 @@ /* - * 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-2007 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. */ +/** + * @file + * @brief Flags to control optimizations. + * @author Christian Schaefer, Goetz Lindenmaier + * @version $Id$ + */ #ifdef HAVE_CONFIG_H -# include +# include "config.h" +#endif + +#include + +#ifdef WITH_LIBCORE +#include #endif #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); +#include "irflag_t.def" + 0; -/* 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; -} +#undef FLAG +#undef E_FLAG +#undef I_FLAG +#undef R_FLAG -void set_opt_global_cse(int value) -{ - if (value) - libFIRM_opt |= OPT_GLOBAL_CSE; - else - libFIRM_opt &= ~OPT_GLOBAL_CSE; -} +/** The bitset of currently running phases. */ +optimization_state_t libFIRM_running = 0; -void -set_opt_constant_folding(int value) -{ - if (value) - libFIRM_opt |= OPT_CONSTANT_FOLDING; - else - libFIRM_opt &= ~OPT_CONSTANT_FOLDING; -} +/* verbose is always off on default */ +optimization_state_t libFIRM_verb = 0; -void -set_opt_unreachable_code(int value) -{ - if (value) - libFIRM_opt |= OPT_UNREACHABLE_CODE; - else - libFIRM_opt &= ~OPT_UNREACHABLE_CODE; -} +/** The Firm verbosity level */ +int firm_verbosity_level; -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); -} - -/* 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; -} - -/* 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 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; \ +} \ +void set_opt_##name##_verbose(int flag) { \ + if (flag) libFIRM_verb |= irf_##name; \ + else libFIRM_verb &= ~irf_##name; \ +} \ +int (get_opt_##name)(void) { \ + return _get_opt_##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; +/* 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; \ +} \ +void set_opt_##name##_verbose(int flag) { \ + if (flag) libFIRM_verb |= irf_##name; \ + else libFIRM_verb &= ~irf_##name; \ } -void set_opt_critical_edges(int value) -{ - if (value) - libFIRM_opt |= OPT_CRITICAL_EDGES; - else - libFIRM_opt &= ~OPT_CRITICAL_EDGES; -} +#define R_FLAG(name, value) -void set_opt_reassociation(int value) -{ - if (value) - libFIRM_opt |= OPT_REASSOCIATION; - else - libFIRM_opt &= ~OPT_REASSOCIATION; -} +/* generate them */ +#include "irflag_t.def" -void set_opt_dead_node_elimination(int value) -{ - if (value) - libFIRM_opt |= OPT_DEAD_NODE_ELIMINATION; - else - libFIRM_opt &= ~OPT_DEAD_NODE_ELIMINATION; -} +#undef I_FLAG +#undef E_FLAG +#undef R_FLAG -void set_optimize(int value) -{ - if (value) - libFIRM_opt |= OPT_OPTIMIZED; - else - libFIRM_opt &= ~OPT_OPTIMIZED; +/* for compatibility reasons */ +void set_optimize(int value) { + if (value) libFIRM_opt |= irf_optimize; + else libFIRM_opt &= ~irf_optimize; } -int get_optimize(void) -{ +int (get_optimize)(void) { return get_opt_optimize(); } -void set_opt_inline(int value) +void set_opt_control_flow(int value) { - if (value) - libFIRM_opt |= OPT_INLINE; - else - libFIRM_opt &= ~OPT_INLINE; + set_opt_control_flow_straightening(value); + set_opt_control_flow_weak_simplification(value); + set_opt_control_flow_strong_simplification(value); } -/** 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) -{ - if (value) - libFIRM_opt |= OPT_DYN_METH_DISPATCH; - else - libFIRM_opt &= ~OPT_DYN_METH_DISPATCH; +void set_firm_verbosity (int value) { + firm_verbosity_level = value; } -void set_opt_normalize(int value) -{ - if (value) - libFIRM_opt |= OPT_NORMALIZE; - else - libFIRM_opt &= ~OPT_NORMALIZE; +int (get_firm_verbosity) (void) { + return _get_firm_verbosity(); } /* Save the current optimization state. */ @@ -187,90 +136,51 @@ void restore_optimization_state(const optimization_state_t *state) libFIRM_opt = *state; } -/* repeat 'inline' methods here */ - -# ifndef USE_GCC_INLINE - -/** Returns constant folding optimization setting. */ -int get_opt_cse(void) /* iropt.c */ +/* Switches ALL optimizations off */ +void all_optimizations_off(void) { - return libFIRM_opt & OPT_CSE; + libFIRM_opt = 0; } -/** Returns constant subexpression elimination setting. */ -int get_opt_global_cse(void) /* irgopt.c iropt.c */ -{ - return libFIRM_opt & OPT_GLOBAL_CSE; -} - -/** Returns global constant subexpression elimination setting. */ -int get_opt_constant_folding(void) /* iropt.c */ -{ - return libFIRM_opt & OPT_CONSTANT_FOLDING; -} - -/** Returns unreachable code elimination setting. */ -int get_opt_unreachable_code(void) /* iropt.c */ -{ - return libFIRM_opt & OPT_UNREACHABLE_CODE; -} - -/** Returns Straightening setting. */ -int get_opt_control_flow_straightening(void) /* iropt.c, irgopt.c */ -{ - return libFIRM_opt & OPT_CONTROL_FLOW_STRAIGHTENING; -} - -/** Returns if simplifications in local optimizations setting. */ -int get_opt_control_flow_weak_simplification(void) /* iropt.c, irgopt.c */ -{ - return libFIRM_opt & OPT_CONTROL_FLOW_WEAK_SIMPLIFICATION; -} - -/** Returns strong if and loop simplification setting */ -int get_opt_control_flow_strong_simplification(void) /* irgopt.c */ -{ - return libFIRM_opt & OPT_CONTROL_FLOW_STRONG_SIMPLIFICATION; -} - -/** Returns whether critical edges are removed */ -int get_opt_critical_edges(void) /* irgopt.c */ -{ - return libFIRM_opt & OPT_CRITICAL_EDGES; -} - -/** Returns reassociation setting. */ -int get_opt_reassociation(void) /* iropt.c */ -{ - return libFIRM_opt & OPT_REASSOCIATION; -} - -/** Returns dead node elimination setting. */ -int get_opt_dead_node_elimination(void) /* irgopt.c */ -{ - return libFIRM_opt & OPT_DEAD_NODE_ELIMINATION; +#ifdef _DEBUG +/* only for debugging */ +void firm_show_flags(FILE *f) { + 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 -/** Returns global optimization setting */ -int get_opt_optimize(void) /* iropt.c, irgopt.c */ -{ - return libFIRM_opt & OPT_OPTIMIZED; -} +#ifdef WITH_LIBCORE +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 -/** Returns inlining setting. */ /* how appropriate */ -int get_opt_inline(void) /* irgopt.c */ -{ - return libFIRM_opt & OPT_INLINE; +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); +#endif } -int get_opt_dyn_meth_dispatch(void) /* cgana.c */ -{ - return libFIRM_opt & OPT_DYN_METH_DISPATCH; -} +firm_verification_t opt_do_node_verification = FIRM_VERIFICATION_ON; -int get_opt_normalize(void) /* irgopt.c, irnode.c, iropt.c */ -{ - return libFIRM_opt & OPT_NORMALIZE; +void do_node_verification(firm_verification_t mode) { + opt_do_node_verification = mode; } - -# endif /* not defined USE_GCC_INLINE */