From b8f889ed4dfd8b2a198a34a81e86efd5e9437b8d Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Tue, 19 Apr 2011 16:33:21 +0200 Subject: [PATCH 1/1] hide cdep struct behind getter, make it more robust with an additional skip_Id --- include/libfirm/cdep.h | 14 +++++------- ir/ana/cdep.c | 22 ++++++++++++++---- ir/ana/cdep_t.h | 52 ++++++++++++++++++++++++++++++++++++++++++ ir/opt/ifconv.c | 6 ++--- 4 files changed, 79 insertions(+), 15 deletions(-) create mode 100644 ir/ana/cdep_t.h diff --git a/include/libfirm/cdep.h b/include/libfirm/cdep.h index 6e7def3ba..58e5d3f69 100644 --- a/include/libfirm/cdep.h +++ b/include/libfirm/cdep.h @@ -29,20 +29,18 @@ #include "firm_types.h" #include "begin.h" -/** - * An entry in the control dependence list. - */ -struct ir_cdep { - ir_node *node; /**< A node on which the current block is control dependent on. */ - ir_cdep *next; /**< Link to the next one if any. */ -}; - /** Compute the control dependence graph for a graph. */ FIRM_API void compute_cdep(ir_graph *irg); /** Free the control dependence info. */ FIRM_API void free_cdep(ir_graph *irg); +/** Return control dependent block */ +FIRM_API ir_node *get_cdep_node(const ir_cdep *cdep); + +/** Get next entry in a list of cdeps */ +FIRM_API ir_cdep *get_cdep_next(const ir_cdep *cdep); + /** * Return a list of all control dependences of a block. */ diff --git a/ir/ana/cdep.c b/ir/ana/cdep.c index c6c2cfccd..498ffbd9b 100644 --- a/ir/ana/cdep.c +++ b/ir/ana/cdep.c @@ -32,7 +32,7 @@ #include "pmap.h" #include "obst.h" #include "xmalloc.h" -#include "cdep.h" +#include "cdep_t.h" #include "irprintf.h" #include "irdump.h" @@ -43,14 +43,27 @@ typedef struct cdep_info { static cdep_info *cdep_data; +ir_node *(get_cdep_node)(const ir_cdep *cdep) +{ + return _get_cdep_node(cdep); +} + +ir_cdep *(get_cdep_next)(const ir_cdep *cdep) +{ + return _get_cdep_next(cdep); +} + +/* Return a list of all control dependences of a block. */ ir_cdep *find_cdep(const ir_node *block) { + assert(is_Block(block)); return (ir_cdep*) pmap_get(cdep_data->cdep_map, block); } void exchange_cdep(ir_node *old, const ir_node *nw) { ir_cdep *cdep = find_cdep(nw); + assert(is_Block(old)); pmap_insert(cdep_data->cdep_map, old, cdep); } @@ -61,6 +74,7 @@ static void add_cdep(ir_node *node, ir_node *dep_on) { ir_cdep *dep = find_cdep(node); + assert(is_Block(dep_on)); if (dep == NULL) { ir_cdep *newdep = OALLOC(&cdep_data->obst, ir_cdep); @@ -71,7 +85,7 @@ static void add_cdep(ir_node *node, ir_node *dep_on) ir_cdep *newdep; for (;;) { - if (dep->node == dep_on) return; + if (get_cdep_node(dep) == dep_on) return; if (dep->next == NULL) break; dep = dep->next; } @@ -189,7 +203,7 @@ int is_cdep_on(const ir_node *dependee, const ir_node *candidate) const ir_cdep *dep; for (dep = find_cdep(dependee); dep != NULL; dep = dep->next) { - if (dep->node == candidate) return 1; + if (get_cdep_node(dep) == candidate) return 1; } return 0; } @@ -198,7 +212,7 @@ ir_node *get_unique_cdep(const ir_node *block) { ir_cdep *cdep = find_cdep(block); - return cdep != NULL && cdep->next == NULL ? cdep->node : NULL; + return cdep != NULL && cdep->next == NULL ? get_cdep_node(cdep) : NULL; } int has_multiple_cdep(const ir_node *block) diff --git a/ir/ana/cdep_t.h b/ir/ana/cdep_t.h new file mode 100644 index 000000000..c79d5e0f8 --- /dev/null +++ b/ir/ana/cdep_t.h @@ -0,0 +1,52 @@ +/* + * 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 control dependence analysis + * @author Christoph Mallon + * @version $Id$ + */ +#ifndef FIRM_ANA_CDEP_T_H +#define FIRM_ANA_CDEP_T_H + +#include "cdep.h" + +/** + * An entry in the control dependence list. + */ +struct ir_cdep { + ir_node *node; /**< A node on which the current block is control dependent on. */ + ir_cdep *next; /**< Link to the next one if any. */ +}; + +static inline ir_node *_get_cdep_node(const ir_cdep *cdep) +{ + return skip_Id(cdep->node); +} + +static inline ir_cdep *_get_cdep_next(const ir_cdep *cdep) +{ + return cdep->next; +} + +#define get_cdep_node(cdep) _get_cdep_node(cdep) +#define get_cdep_next(cdep) _get_cdep_next(cdep) + +#endif diff --git a/ir/opt/ifconv.c b/ir/opt/ifconv.c index 7c2185fa8..15152abbf 100644 --- a/ir/opt/ifconv.c +++ b/ir/opt/ifconv.c @@ -31,7 +31,7 @@ #include "iroptimize.h" #include "obst.h" #include "irnode_t.h" -#include "cdep.h" +#include "cdep_t.h" #include "ircons.h" #include "irgmod.h" #include "irgopt.h" @@ -288,8 +288,8 @@ restart: ir_cdep* cdep; pred0 = get_Block_cfgpred_block(block, i); - for (cdep = find_cdep(pred0); cdep != NULL; cdep = cdep->next) { - const ir_node* dependency = cdep->node; + for (cdep = find_cdep(pred0); cdep != NULL; cdep = get_cdep_next(cdep)) { + const ir_node* dependency = get_cdep_node(cdep); ir_node* projx0 = walk_to_projx(pred0, dependency); ir_node* cond; int j; -- 2.20.1