From 9d500f9aa4f5fe482e47417ce1190b9193856543 Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Wed, 16 Dec 2009 13:21:16 +0000 Subject: [PATCH] put optimisation module init function declarations into firm_init.h; make loop inversion and loop peeling available in the public API. [r26795] --- include/libfirm/iroptimize.h | 12 ++++++++++++ ir/common/firm.c | 7 ++----- ir/opt/funccall.c | 3 ++- ir/opt/loop.c | 24 ++++++++++++++++++----- ir/opt/{funccall_t.h => opt_init.h} | 21 +++++++++++++------- ir/opt/opt_inline.c | 2 +- ir/opt/opt_inline_t.h | 30 ----------------------------- ir/opt/reassoc.c | 1 + ir/opt/reassoc_t.h | 3 --- ir/opt/scalar_replace.c | 1 + ir/opt/scalar_replace.h | 2 -- ir/opt/tropt.c | 2 +- ir/opt/tropt.h | 30 ----------------------------- 13 files changed, 53 insertions(+), 85 deletions(-) rename ir/opt/{funccall_t.h => opt_init.h} (71%) delete mode 100644 ir/opt/opt_inline_t.h delete mode 100644 ir/opt/tropt.h diff --git a/include/libfirm/iroptimize.h b/include/libfirm/iroptimize.h index 4fae6e983..0bf07acff 100644 --- a/include/libfirm/iroptimize.h +++ b/include/libfirm/iroptimize.h @@ -878,4 +878,16 @@ int shape_blocks(ir_graph *irg); */ ir_graph_pass_t *shape_blocks_pass(const char *name); +/** + * Perform loop inversion on a given graph. + * Loop inversion transform a head controlled loop (like while(...) {} and + * for(...) {}) into a foot controlled loop (do {} while(...)). + */ +void do_loop_inversion(ir_graph *irg); + +/** + * Perform loop peeling on a given graph. + */ +void do_loop_peeling(ir_graph *irg); + #endif diff --git a/ir/common/firm.c b/ir/common/firm.c index 852297071..fbe300ce0 100644 --- a/ir/common/firm.c +++ b/ir/common/firm.c @@ -47,16 +47,12 @@ #include "irgraph_t.h" #include "type_t.h" #include "entity_t.h" -#include "opt_inline_t.h" -#include "scalar_replace.h" #include "firmstat.h" #include "irarch.h" -#include "reassoc_t.h" -#include "funccall_t.h" #include "irhooks.h" #include "iredges_t.h" #include "irmemory_t.h" -#include "tropt.h" +#include "opt_init.h" #include "debugger.h" #include "be_t.h" @@ -137,6 +133,7 @@ void ir_init(const firm_parameter_t *param) firm_init_class_casts_opt(); /* memory disambiguation */ firm_init_memory_disambiguator(); + firm_init_loop_opt(); /* Init architecture dependent optimizations. */ arch_dep_init(arch_dep_default_factory); diff --git a/ir/opt/funccall.c b/ir/opt/funccall.c index 25d3e929f..2822dae4f 100644 --- a/ir/opt/funccall.c +++ b/ir/opt/funccall.c @@ -27,7 +27,7 @@ #include -#include "funccall_t.h" +#include "opt_init.h" #include "irnode_t.h" #include "irgraph_t.h" @@ -40,6 +40,7 @@ #include "ircons.h" #include "iredges_t.h" #include "irpass_t.h" +#include "iroptimize.h" #include "analyze_irg_args.h" #include "irhooks.h" #include "debug.h" diff --git a/ir/opt/loop.c b/ir/opt/loop.c index e973bd4a1..5ba378bd9 100644 --- a/ir/opt/loop.c +++ b/ir/opt/loop.c @@ -1147,7 +1147,7 @@ static void decision_maker(void) unsigned do_peel = 0; unsigned do_inversion = 1; - unsigned max_loop_opnodes = 2000000; + /* unsigned max_loop_opnodes = 2000000; */ head_inversion_node_limit = 99910; @@ -1184,10 +1184,11 @@ static void decision_maker(void) if (loop_info.stores == 0 && loop_info.invariant_loads > 0) do_peel = 1; +#else + (void) get_invariants; #endif - - do_peel = 1; + do_peel = 0; do_inversion = 1; /* Loop peeling */ @@ -1300,7 +1301,6 @@ void loop_optimization(ir_graph *irg) int sons, nr; FIRM_DBG_REGISTER(dbg, "firm.opt.loop"); - firm_dbg_set_mask(dbg, -1); DB((dbg, LEVEL_1, " >>> loop optimization (Startnode %ld) <<<\n", get_irn_node_nr(get_irg_start(irg)))); @@ -1308,6 +1308,7 @@ void loop_optimization(ir_graph *irg) link_node_state_list = NULL; /* preconditions */ + edges_assure(irg); ir_reserve_resources(irg, IR_RESOURCE_IRN_LINK|IR_RESOURCE_PHI_LIST); collect_phiprojs(irg); ir_free_resources(irg, IR_RESOURCE_IRN_LINK); @@ -1333,6 +1334,19 @@ void loop_optimization(ir_graph *irg) DB((dbg, LEVEL_1, " >>> loop optimization done (Startnode %ld) <<<\n", get_irn_node_nr(get_irg_start(irg)))); } -void firm_init_loop(void) { +void do_loop_inversion(ir_graph *irg) +{ + /* TODO: add the code here that performs loop inversion only */ + loop_optimization(irg); +} + +void do_loop_peeling(ir_graph *irg) +{ + /* TODO: add the code here that performs loop peeling only */ + loop_optimization(irg); +} + +void firm_init_loop_opt(void) +{ FIRM_DBG_REGISTER(dbg, "firm.opt.loop"); } diff --git a/ir/opt/funccall_t.h b/ir/opt/opt_init.h similarity index 71% rename from ir/opt/funccall_t.h rename to ir/opt/opt_init.h index 9e5c60dfd..2f0293e14 100644 --- a/ir/opt/funccall_t.h +++ b/ir/opt/opt_init.h @@ -19,16 +19,23 @@ /** * @file - * @brief Optimization of function calls. - * @author Michael Beck + * @author Matthias Braun + * @brief Init functions for various optimisations * @version $Id$ */ -#ifndef FUNCCALL_T_H -#define FUNCCALL_T_H +#ifndef FIRM_OPT_INIT_H +#define FIRM_OPT_INIT_H -#include "iroptimize.h" +void firm_init_inline(void); -/** initialize the funccall optimization */ void firm_init_funccalls(void); -#endif /* FUNCCALL_T_H */ +void firm_init_reassociation(void); + +void firm_init_scalar_replace(void); + +void firm_init_class_casts_opt(void); + +void firm_init_loop_opt(void); + +#endif diff --git a/ir/opt/opt_inline.c b/ir/opt/opt_inline.c index 5ec85e6e6..86751d160 100644 --- a/ir/opt/opt_inline.c +++ b/ir/opt/opt_inline.c @@ -50,7 +50,7 @@ #include "irouts.h" #include "irloop_t.h" #include "irbackedge_t.h" -#include "opt_inline_t.h" +#include "opt_init.h" #include "cgana.h" #include "trouts.h" #include "error.h" diff --git a/ir/opt/opt_inline_t.h b/ir/opt/opt_inline_t.h deleted file mode 100644 index adf29d6fe..000000000 --- a/ir/opt/opt_inline_t.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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. - */ - -/** - * @file - * @brief Dead node elimination and Procedure Inlining. - * @version $Id: $ - */ -#ifndef FIRM_OPT_INLINE_T_H -#define FIRM_OPT_INLINE_T_H - -void firm_init_inline(void); - -#endif diff --git a/ir/opt/reassoc.c b/ir/opt/reassoc.c index 1f02100c4..07e96ccfd 100644 --- a/ir/opt/reassoc.c +++ b/ir/opt/reassoc.c @@ -36,6 +36,7 @@ #include "irgwalk.h" #include "irouts.h" #include "reassoc_t.h" +#include "opt_init.h" #include "irhooks.h" #include "irloop.h" #include "pdeq.h" diff --git a/ir/opt/reassoc_t.h b/ir/opt/reassoc_t.h index ce05e29f6..49dd8a758 100644 --- a/ir/opt/reassoc_t.h +++ b/ir/opt/reassoc_t.h @@ -48,7 +48,4 @@ */ ir_op_ops *firm_set_default_reassoc(ir_opcode code, ir_op_ops *ops); -/** Initialise the ressociation optimization */ -void firm_init_reassociation(void); - #endif /* _REASSOC_T_H_ */ diff --git a/ir/opt/scalar_replace.c b/ir/opt/scalar_replace.c index 59588da8b..34073f259 100644 --- a/ir/opt/scalar_replace.c +++ b/ir/opt/scalar_replace.c @@ -29,6 +29,7 @@ #include "iroptimize.h" #include "scalar_replace.h" +#include "opt_init.h" #include "irflag_t.h" #include "irouts.h" #include "set.h" diff --git a/ir/opt/scalar_replace.h b/ir/opt/scalar_replace.h index 0e256f6d7..e5482b938 100644 --- a/ir/opt/scalar_replace.h +++ b/ir/opt/scalar_replace.h @@ -36,6 +36,4 @@ */ int is_address_taken(ir_node *sel); -void firm_init_scalar_replace(void); - #endif /* FIRM_OPT_SCALAR_REPLACE_H */ diff --git a/ir/opt/tropt.c b/ir/opt/tropt.c index 435efb024..999735d1f 100644 --- a/ir/opt/tropt.c +++ b/ir/opt/tropt.c @@ -39,7 +39,7 @@ #include "irflag_t.h" #include "xmalloc.h" #include "debug.h" -#include "tropt.h" +#include "opt_init.h" DEBUG_ONLY(static firm_dbg_module_t *dbg;) diff --git a/ir/opt/tropt.h b/ir/opt/tropt.h deleted file mode 100644 index 2d0e9a658..000000000 --- a/ir/opt/tropt.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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. - */ - -/** - * @file - * @brief Perform optimizations of the type representation. - * @version $Id: $ - */ -#ifndef FIRM_OPT_TROPT_H -#define FIRM_OPT_TROPT_H - -void firm_init_class_casts_opt(void); - -#endif -- 2.20.1