hide cdep struct behind getter, make it more robust with an additional skip_Id
authorMatthias Braun <matze@braunis.de>
Tue, 19 Apr 2011 14:33:21 +0000 (16:33 +0200)
committerMatthias Braun <matze@braunis.de>
Wed, 20 Apr 2011 10:27:29 +0000 (12:27 +0200)
include/libfirm/cdep.h
ir/ana/cdep.c
ir/ana/cdep_t.h [new file with mode: 0644]
ir/opt/ifconv.c

index 6e7def3..58e5d3f 100644 (file)
 #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.
  */
index c6c2cfc..498ffbd 100644 (file)
@@ -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 (file)
index 0000000..c79d5e0
--- /dev/null
@@ -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
index 7c2185f..15152ab 100644 (file)
@@ -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;