From 7cd2dbf37a3ced8d0113899618c88bc47eee0164 Mon Sep 17 00:00:00 2001 From: Michael Beck Date: Sat, 21 Mar 2009 10:36:45 +0000 Subject: [PATCH] - get_Block_cfgpred_arr() IS supported, but should not be in the official interface - get_Block_cfgpred_pos() added and used - more doxygen docu [r25718] --- include/libfirm/irnode.h | 38 +++++++++++++++++++++++++++++--------- ir/ir/irnode.c | 14 ++++++++++---- ir/ir/irnode_t.h | 8 ++++++++ ir/opt/gvn_pre.c | 9 ++------- 4 files changed, 49 insertions(+), 20 deletions(-) diff --git a/include/libfirm/irnode.h b/include/libfirm/irnode.h index 660e24ad5..f975c3728 100644 --- a/include/libfirm/irnode.h +++ b/include/libfirm/irnode.h @@ -334,11 +334,28 @@ ir_type *is_frame_pointer(const ir_node *n); * from Start. If so returns tls type, else Null. */ ir_type *is_tls_pointer(const ir_node *n); -/* @@@ no more supported */ -ir_node **get_Block_cfgpred_arr(ir_node *node); -int get_Block_n_cfgpreds(const ir_node *node); -ir_node *get_Block_cfgpred(const ir_node *node, int pos); -void set_Block_cfgpred(ir_node *node, int pos, ir_node *pred); +/** Return the number of control flow predecessors of a block. */ +int get_Block_n_cfgpreds(const ir_node *block); +/** Return the control flow predecessor of a block at a given position. */ +ir_node *get_Block_cfgpred(const ir_node *block, int pos); +/** Set the control flow predecessor of a block at a given position. */ +void set_Block_cfgpred(ir_node *block, int pos, ir_node *pred); + +/** + * Return the position of the predecessor block pred in the inputs + * of the block block. + * + * @param block the block + * @param pred a predecessor block of block + * + * @return the position of pred in block or -1 + * + * @note When using the old extended basic block form for blocks + * with exception exists, a predecessor block might have more + * than one position. In that case it is not specified, with is returned. + */ +int get_Block_cfgpred_pos(const ir_node *block, const ir_node *pred); + /** Get the predecessor block. * * Returns the block corresponding to the predecessor pos of block. @@ -351,13 +368,16 @@ void set_Block_cfgpred(ir_node *node, int pos, ir_node *pred); * Start block, but the Bad node. */ ir_node *get_Block_cfgpred_block(const ir_node *node, int pos); -int get_Block_matured(const ir_node *node); -void set_Block_matured(ir_node *node, int matured); + +/** Return the matured flag of a block */ +int get_Block_matured(const ir_node *block); +/** set the matured flag of a block. */ +void set_Block_matured(ir_node *block, int matured); /** A visited flag only for block nodes. * @see also: get_irn_visited() inc_irg_visited() inc_irg_block_visited()*/ -ir_visited_t get_Block_block_visited(const ir_node *node); -void set_Block_block_visited(ir_node *node, ir_visited_t visit); +ir_visited_t get_Block_block_visited(const ir_node *block); +void set_Block_block_visited(ir_node *block, ir_visited_t visit); /** * Marks a block as dead but do not replace it with a Bad node. diff --git a/ir/ir/irnode.c b/ir/ir/irnode.c index 204641dc3..f09e5e834 100644 --- a/ir/ir/irnode.c +++ b/ir/ir/irnode.c @@ -636,10 +636,6 @@ ir_type *is_tls_pointer(const ir_node *n) { return NULL; } -/* Returns an array with the predecessors of the Block. Depending on - the implementation of the graph data structure this can be a copy of - the internal representation of predecessors as well as the internal - array itself. Therefore writing to this array might obstruct the ir. */ ir_node **get_Block_cfgpred_arr(ir_node *node) { assert(is_Block(node)); return (ir_node **)&(get_irn_in(node)[1]); @@ -658,6 +654,16 @@ void set_Block_cfgpred(ir_node *node, int pos, ir_node *pred) { set_irn_n(node, pos, pred); } +int get_Block_cfgpred_pos(const ir_node *block, const ir_node *pred) { + int i; + + for (i = get_Block_n_cfgpreds(block) - 1; i >= 0; --i) { + if (get_Block_cfgpred_block(block, i) == pred) + return i; + } + return -1; +} + ir_node *(get_Block_cfgpred_block)(const ir_node *node, int pos) { return _get_Block_cfgpred_block(node, pos); } diff --git a/ir/ir/irnode_t.h b/ir/ir/irnode_t.h index 494b6ca92..98f635244 100644 --- a/ir/ir/irnode_t.h +++ b/ir/ir/irnode_t.h @@ -99,6 +99,14 @@ ir_op_ops *firm_set_default_get_type_attr(ir_opcode code, ir_op_ops *ops); */ ir_op_ops *firm_set_default_get_entity_attr(ir_opcode code, ir_op_ops *ops); +/** + * Returns an array with the predecessors of the Block. Depending on + * the implementation of the graph data structure this can be a copy of + * the internal representation of predecessors as well as the internal + * array itself. Therefore writing to this array might obstruct the IR. + */ +ir_node **get_Block_cfgpred_arr(ir_node *node); + /*-------------------------------------------------------------------*/ /* These function are most used in libfirm. Give them as static */ /* functions so they can be inlined. */ diff --git a/ir/opt/gvn_pre.c b/ir/opt/gvn_pre.c index 798aa36e5..3863ff8d0 100644 --- a/ir/opt/gvn_pre.c +++ b/ir/opt/gvn_pre.c @@ -454,16 +454,11 @@ static void compute_antic(ir_node *block, void *ctx) { n_succ = get_Block_n_cfg_outs(block); if (n_succ == 1) { - int i, pos = -1; + int pos = -1; /* find blocks position in succ's block predecessors */ succ = get_Block_cfg_out(block, 0); - for (i = get_Block_n_cfgpreds(succ) - 1; i >= 0; --i) { - if (get_Block_cfgpred_block(succ, i) == block) { - pos = i; - break; - } - } + pos = get_Block_cfgpred_pos(succ, block); assert(pos >= 0); succ_info = get_block_info(succ); -- 2.20.1