From c65b13d98017c671496ff61e970790bba264f375 Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Thu, 14 Dec 2006 15:24:10 +0000 Subject: [PATCH] move birg to an own file, use more of the birg analysis data --- ir/be/be.h | 2 +- ir/be/be_t.h | 21 +------------ ir/be/beabi.c | 1 + ir/be/bearch.h | 2 +- ir/be/bechordal.c | 1 + ir/be/bechordal_draw.c | 4 +-- ir/be/bechordal_main.c | 2 +- ir/be/bechordal_t.h | 1 + ir/be/becopyilp.c | 6 ++-- ir/be/becopyopt.c | 2 ++ ir/be/becopystat.c | 1 + ir/be/beifg.c | 6 ++-- ir/be/beirg.c | 61 ++++++++++++++++++++++++++++++++++++++ ir/be/beirg.h | 35 ++++++++++++++++++++++ ir/be/beirg_t.h | 53 +++++++++++++++++++++++++++++++++ ir/be/belive_t.h | 2 +- ir/be/bemain.c | 46 +--------------------------- ir/be/ia32/bearch_ia32.c | 14 +++++---- ir/be/ia32/bearch_ia32_t.h | 2 +- 19 files changed, 178 insertions(+), 84 deletions(-) create mode 100644 ir/be/beirg.c create mode 100644 ir/be/beirg.h create mode 100644 ir/be/beirg_t.h diff --git a/ir/be/be.h b/ir/be/be.h index 6b08e9dc0..48fd5e614 100644 --- a/ir/be/be.h +++ b/ir/be/be.h @@ -7,6 +7,7 @@ #include "lower_dw.h" #include "dbginfo.h" #include "ifconv.h" +#include "beirg.h" #define LC_STOP_AND_RESET_TIMER(timer) do { lc_timer_stop(timer); lc_timer_reset(timer); } while(0) @@ -73,7 +74,6 @@ void be_set_debug_retrieve(retrieve_dbg_func func); const char *be_retrieve_dbg_info(const dbg_info *dbg, unsigned *line); typedef struct _be_main_env_t be_main_env_t; -typedef struct _be_irg_t be_irg_t; typedef struct _be_options_t be_options_t; #endif /* _BE_MAIN_H */ diff --git a/ir/be/be_t.h b/ir/be/be_t.h index cb9c5664b..c0e87a6d5 100644 --- a/ir/be/be_t.h +++ b/ir/be/be_t.h @@ -16,6 +16,7 @@ #include "bearch.h" #include "beirgmod.h" #include "be_dbgout.h" +#include "beirg_t.h" #define DUMP_NONE 0 #define DUMP_INITIAL (1 << 0) @@ -67,26 +68,6 @@ struct _be_main_env_t { DEBUG_ONLY(firm_dbg_module_t *dbg;) }; -/** - * An irg with additional analysis data about this irg. Also includes some - * backend structures - */ -struct _be_irg_t { - ir_graph *irg; - struct _be_main_env_t *main_env; - struct _be_abi_irg_t *abi; - struct _arch_code_generator_t *cg; - ir_exec_freq *exec_freq; - be_dom_front_info_t *dom_front; - be_lv_t *lv; -}; - -void be_assure_liveness(be_irg_t *birg); -void be_invalidate_liveness(be_irg_t *birg); - -void be_assure_dom_front(be_irg_t *birg); -void be_invalidate_dom_front(be_irg_t *birg); - /** * Put the registers to be ignored in this IRG into a bitset. * @param birg The backend IRG data structure. diff --git a/ir/be/beabi.c b/ir/be/beabi.c index 6bfe665e4..0aeb25548 100644 --- a/ir/be/beabi.c +++ b/ir/be/beabi.c @@ -35,6 +35,7 @@ #include "benode_t.h" #include "belive_t.h" #include "besched_t.h" +#include "beirg.h" typedef struct _be_abi_call_arg_t { unsigned is_res : 1; /**< 1: the call argument is a return value. 0: it's a call parameter. */ diff --git a/ir/be/bearch.h b/ir/be/bearch.h index b23ebe29e..2dcf8a1f8 100644 --- a/ir/be/bearch.h +++ b/ir/be/bearch.h @@ -527,7 +527,7 @@ struct _arch_code_generator_if_t { * @param birg A backend IRG session. * @return A newly created code generator. */ - void *(*init)(const be_irg_t *birg); + void *(*init)(be_irg_t *birg); /** * Called before abi introduce. diff --git a/ir/be/bechordal.c b/ir/be/bechordal.c index 7f7058208..725e8d2f5 100644 --- a/ir/be/bechordal.c +++ b/ir/be/bechordal.c @@ -50,6 +50,7 @@ #include "beifg.h" #include "beinsn_t.h" #include "bestatevent.h" +#include "beirg_t.h" #include "bechordal_t.h" #include "bechordal_draw.h" diff --git a/ir/be/bechordal_draw.c b/ir/be/bechordal_draw.c index e3a3172a7..30aef630d 100644 --- a/ir/be/bechordal_draw.c +++ b/ir/be/bechordal_draw.c @@ -375,8 +375,8 @@ static void draw_block(ir_node *bl, void *data) static const color_t black = { 0, 0, 0 }; const draw_chordal_env_t *env = data; - pset *live_in = be_lv_pset_put_in(env->chordal_env->birg->lv, bl, pset_new_ptr_default()); - be_lv_t *lv = env->chordal_env->birg->lv; + const be_lv_t *lv = be_get_birg_liveness(env->chordal_env->birg); + pset *live_in = be_lv_pset_put_in(lv, bl, pset_new_ptr_default()); ir_node *irn; border_t *b; struct list_head *head = get_block_border_head(env->chordal_env, bl); diff --git a/ir/be/bechordal_main.c b/ir/be/bechordal_main.c index 1add6b5c5..342c89b7b 100644 --- a/ir/be/bechordal_main.c +++ b/ir/be/bechordal_main.c @@ -363,7 +363,7 @@ static void memory_operand_walker(ir_node *irn, void *env) { if (get_nodes_block(src) == block && arch_possible_memory_operand(aenv, src, pos)) { DBG((cenv->dbg, LEVEL_3, "performing memory operand %+F at %+F\n", irn, src)); - //arch_perform_memory_operand(aenv, src, spill, pos); + arch_perform_memory_operand(aenv, src, spill, pos); } } diff --git a/ir/be/bechordal_t.h b/ir/be/bechordal_t.h index db14962ff..bafedce7f 100644 --- a/ir/be/bechordal_t.h +++ b/ir/be/bechordal_t.h @@ -29,6 +29,7 @@ #include "bechordal.h" #include "beirgmod.h" #include "belive.h" +#include "beirg.h" typedef struct _be_ra_chordal_opts_t be_ra_chordal_opts_t; diff --git a/ir/be/becopyilp.c b/ir/be/becopyilp.c index 3c4b266a3..883ce50c0 100644 --- a/ir/be/becopyilp.c +++ b/ir/be/becopyilp.c @@ -7,13 +7,13 @@ * Common stuff used by all ILP fomulations. * */ - -#include "bestatevent.h" - #ifdef HAVE_CONFIG_H #include "config.h" #endif /* HAVE_CONFIG_H */ +#include "bestatevent.h" +#include "beirg_t.h" + #ifdef WITH_ILP #define DUMP_ILP 1 diff --git a/ir/be/becopyopt.c b/ir/be/becopyopt.c index 582c4e2cf..476034228 100644 --- a/ir/be/becopyopt.c +++ b/ir/be/becopyopt.c @@ -7,6 +7,7 @@ #ifdef HAVE_CONFIG_H #include "config.h" #endif + #ifdef HAVE_ALLOCA_H #include #endif @@ -41,6 +42,7 @@ #include "benodesets.h" #include "bejavacoal.h" #include "bestatevent.h" +#include "beirg_t.h" #ifdef WITH_LIBCORE #include diff --git a/ir/be/becopystat.c b/ir/be/becopystat.c index fa6ee3eb3..871e2369a 100644 --- a/ir/be/becopystat.c +++ b/ir/be/becopystat.c @@ -21,6 +21,7 @@ #include "beutil.h" #include "becopyopt_t.h" #include "becopystat.h" +#include "beirg_t.h" #define DEBUG_LVL SET_LEVEL_1 DEBUG_ONLY(static firm_dbg_module_t *dbg = NULL;) diff --git a/ir/be/beifg.c b/ir/be/beifg.c index 1b5a2dcdf..e42cc6ca6 100644 --- a/ir/be/beifg.c +++ b/ir/be/beifg.c @@ -6,13 +6,12 @@ * Copyright (C) 2005 Universitaet Karlsruhe * Released under the GPL */ - -#include - #ifdef HAVE_CONFIG_H #include "config.h" #endif +#include + #ifdef HAVE_MALLOC_H #include #endif @@ -46,6 +45,7 @@ #include "becopystat.h" #include "becopyopt.h" +#include "beirg_t.h" /** Defines values for the ifg performance test */ #define BE_CH_PERFORMANCETEST_MIN_NODES (50) diff --git a/ir/be/beirg.c b/ir/be/beirg.c new file mode 100644 index 000000000..42460def6 --- /dev/null +++ b/ir/be/beirg.c @@ -0,0 +1,61 @@ +/* + * Author: Matthias Braun + * Date: 13.12.2006 + * Copyright: (c) Universitaet Karlsruhe + * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE. + */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "execfreq.h" +#include "beirg_t.h" + +void be_assure_liveness(be_irg_t *birg) +{ + if(birg->lv != NULL) + return; + + birg->lv = be_liveness(birg->irg); +} + +void be_invalidate_liveness(be_irg_t *birg) +{ + if(birg->lv == NULL) + return; + + be_liveness_free(birg->lv); + birg->lv = NULL; +} + +void be_assure_dom_front(be_irg_t *birg) +{ + if(birg->dom_front != NULL) + return; + + birg->dom_front = be_compute_dominance_frontiers(birg->irg); +} + +void be_invalidate_dom_front(be_irg_t *birg) +{ + if(birg->dom_front == NULL) + return; + + be_free_dominance_frontiers(birg->dom_front); + birg->dom_front = NULL; +} + +void be_free_birg(be_irg_t *birg) +{ + free_execfreq(birg->exec_freq); + birg->exec_freq = NULL; + + if(birg->dom_front != NULL) { + be_free_dominance_frontiers(birg->dom_front); + birg->dom_front = NULL; + } + if(birg->lv != NULL) { + be_liveness_free(birg->lv); + birg->lv = NULL; + } +} diff --git a/ir/be/beirg.h b/ir/be/beirg.h new file mode 100644 index 000000000..7c80be6f6 --- /dev/null +++ b/ir/be/beirg.h @@ -0,0 +1,35 @@ +/** + * Author: Matthias Braun + * Date: 05.05.2006 + * Copyright: (c) Universitaet Karlsruhe + * License: This file is protected by GPL - GNU GENERAL PUBLIC LICENSE. + * + * Backend irg - a ir_graph with additional analysis information + */ +#ifndef BEIRG_H_ +#define BEIRG_H_ + +#include "belive.h" +#include "beirgmod.h" + +typedef struct _be_irg_t be_irg_t; + +ir_graph *be_get_ir_graph(be_irg_t *birg); + +void be_assure_liveness(be_irg_t *birg); +void be_invalidate_liveness(be_irg_t *birg); +be_lv_t *be_get_birg_liveness(be_irg_t *birg); + +void be_assure_dom_front(be_irg_t *birg); +void be_invalidate_dom_front(be_irg_t *birg); +be_dom_front_info_t *be_get_birg_dom_front(be_irg_t *birg); + +ir_exec_freq *be_get_birg_exec_freq(be_irg_t *birg); + +/** + * frees all memory allocated by birg structures (liveness, dom_front, ...). + * The memory of the birg structure itself is not freed. + */ +void be_free_birg(be_irg_t *birg); + +#endif diff --git a/ir/be/beirg_t.h b/ir/be/beirg_t.h new file mode 100644 index 000000000..71f5efb58 --- /dev/null +++ b/ir/be/beirg_t.h @@ -0,0 +1,53 @@ +/** + * Author: Matthias Braun + * Date: 05.05.2006 + * Copyright: (c) Universitaet Karlsruhe + * License: This file is protected by GPL - GNU GENERAL PUBLIC LICENSE. + * + * Backend irg - a ir_graph with additional analysis information + */ +#ifndef BEIRG_T_H_ +#define BEIRG_T_H_ + +#include "beirg.h" + +/** + * An ir_graph with additional analysis data about this irg. Also includes some + * backend structures + */ +struct _be_irg_t { + ir_graph *irg; + struct _be_main_env_t *main_env; + struct _be_abi_irg_t *abi; + struct _arch_code_generator_t *cg; + ir_exec_freq *exec_freq; + be_dom_front_info_t *dom_front; + be_lv_t *lv; +}; + +static INLINE be_lv_t * +_be_get_birg_liveness(const be_irg_t *birg) { + return birg->lv; +} + +static INLINE ir_exec_freq * +_be_get_birg_exec_freq(const be_irg_t *birg) { + return birg->exec_freq; +} + +static INLINE be_dom_front_info_t * +_be_get_birg_dom_front(const be_irg_t *birg) { + return birg->dom_front; +} + +static INLINE ir_graph * +_be_get_birg_irg(const be_irg_t *birg) { + return birg->irg; +} + +#define be_get_birg_exec_freq(birg) _be_get_birg_exec_freq(birg) +#define be_get_birg_liveness(birg) _be_get_birg_liveness(birg) +#define be_get_birg_dom_front(birg) _be_get_birg_dom_front(birg) +#define be_get_birg_irg(birg) _be_get_birg_irg(birg) + +#endif diff --git a/ir/be/belive_t.h b/ir/be/belive_t.h index 061826a20..6675f3c70 100644 --- a/ir/be/belive_t.h +++ b/ir/be/belive_t.h @@ -80,7 +80,7 @@ static INLINE int _be_is_live_xxx(const struct _be_lv_t *li, const ir_node *bloc for(i = _be_lv_next_irn(lv, bl, flags, 0); i >= 0; i = _be_lv_next_irn(lv, bl, flags, i + 1)) -static INLINE pset *_be_lv_pset_put(struct _be_lv_t *lv, const ir_node *block, int state, pset *s) +static INLINE pset *_be_lv_pset_put(const struct _be_lv_t *lv, const ir_node *block, int state, pset *s) { int i; be_lv_foreach(lv, block, state, i) diff --git a/ir/be/bemain.c b/ir/be/bemain.c index c717da818..81e731ea2 100644 --- a/ir/be/bemain.c +++ b/ir/be/bemain.c @@ -773,17 +773,7 @@ static void be_main_loop(FILE *file_handle, const char *cup_name) #undef LC_EMIT_RA #undef LC_EMIT - free_execfreq(birg->exec_freq); - birg->exec_freq = NULL; - - if(birg->dom_front != NULL) { - be_free_dominance_frontiers(birg->dom_front); - birg->dom_front = NULL; - } - if(birg->lv != NULL) { - be_liveness_free(birg->lv); - birg->lv = NULL; - } + be_free_birg(birg); /* switched off due to statistics (statistic module needs all irgs) */ #ifdef FIRM_STATISTICS @@ -889,37 +879,3 @@ int be_put_ignore_regs(const be_irg_t *birg, const arch_register_class_t *cls, b return bitset_popcnt(bs); } - -void be_assure_liveness(be_irg_t *birg) -{ - if(birg->lv != NULL) - return; - - birg->lv = be_liveness(birg->irg); -} - -void be_invalidate_liveness(be_irg_t *birg) -{ - if(birg->lv == NULL) - return; - - be_liveness_free(birg->lv); - birg->lv = NULL; -} - -void be_assure_dom_front(be_irg_t *birg) -{ - if(birg->dom_front != NULL) - return; - - birg->dom_front = be_compute_dominance_frontiers(birg->irg); -} - -void be_invalidate_dom_front(be_irg_t *birg) -{ - if(birg->dom_front == NULL) - return; - - be_free_dominance_frontiers(birg->dom_front); - birg->dom_front = NULL; -} diff --git a/ir/be/ia32/bearch_ia32.c b/ir/be/ia32/bearch_ia32.c index a8c64477a..a8c524019 100644 --- a/ir/be/ia32/bearch_ia32.c +++ b/ir/be/ia32/bearch_ia32.c @@ -1287,14 +1287,16 @@ static void ia32_finish(void *self) { ia32_code_gen_t *cg = self; ir_graph *irg = cg->irg; - //be_remove_empty_blocks(irg); - cg->blk_sched = be_create_block_schedule(irg, cg->birg->exec_freq); - /* if we do x87 code generation, rewrite all the virtual instructions and registers */ if (cg->used_fp == fp_x87 || cg->force_sim) { - x87_simulate_graph(cg->arch_env, irg, cg->blk_sched); + x87_simulate_graph(cg->arch_env, cg->birg); } + /* create block schedule, this also removes empty blocks which might + * produce critical edges */ + cg->blk_sched = be_create_block_schedule(irg, cg->birg->exec_freq); + + /* do peephole optimisations */ ia32_peephole_optimization(irg, cg); } @@ -1318,7 +1320,7 @@ static void ia32_codegen(void *self) { free(cg); } -static void *ia32_cg_init(const be_irg_t *birg); +static void *ia32_cg_init(be_irg_t *birg); static const arch_code_generator_if_t ia32_code_gen_if = { ia32_cg_init, @@ -1335,7 +1337,7 @@ static const arch_code_generator_if_t ia32_code_gen_if = { /** * Initializes a IA32 code generator. */ -static void *ia32_cg_init(const be_irg_t *birg) { +static void *ia32_cg_init(be_irg_t *birg) { ia32_isa_t *isa = (ia32_isa_t *)birg->main_env->arch_env->isa; ia32_code_gen_t *cg = xcalloc(1, sizeof(*cg)); diff --git a/ir/be/ia32/bearch_ia32_t.h b/ir/be/ia32/bearch_ia32_t.h index f1f46f50a..aa6832afa 100644 --- a/ir/be/ia32/bearch_ia32_t.h +++ b/ir/be/ia32/bearch_ia32_t.h @@ -96,7 +96,7 @@ typedef struct _ia32_code_gen_t { const arch_env_t *arch_env; /**< the arch env */ set *reg_set; /**< set to memorize registers for non-ia32 nodes (e.g. phi nodes) */ ia32_isa_t *isa; /**< for fast access to the isa object */ - const be_irg_t *birg; /**< The be-irg (contains additional information about the irg) */ + be_irg_t *birg; /**< The be-irg (contains additional information about the irg) */ ir_node **blk_sched; /**< an array containing the scheduled blocks */ ia32_optimize_t opt; /**< contains optimization information */ ir_entity *fp_to_gp; /**< allocated entity for fp to gp conversion */ -- 2.20.1