projects
/
libfirm
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
always dump additional method props
[libfirm]
/
ir
/
ir
/
irgwalk.c
diff --git
a/ir/ir/irgwalk.c
b/ir/ir/irgwalk.c
index
104ca35
..
b523e4d
100644
(file)
--- a/
ir/ir/irgwalk.c
+++ b/
ir/ir/irgwalk.c
@@
-1,5
+1,5
@@
/*
/*
- * Copyright (C) 1995-20
08
University of Karlsruhe. All right reserved.
+ * Copyright (C) 1995-20
11
University of Karlsruhe. All right reserved.
*
* This file is part of libFirm.
*
*
* This file is part of libFirm.
*
@@
-21,7
+21,6
@@
* @file
* @brief Functions for traversing ir graphs
* @author Boris Boesler, Goetz Lindenmaier, Michael Beck
* @file
* @brief Functions for traversing ir graphs
* @author Boris Boesler, Goetz Lindenmaier, Michael Beck
- * @version $Id$
* @brief
* traverse an ir graph
* - execute the pre function before recursion
* @brief
* traverse an ir graph
* - execute the pre function before recursion
@@
-37,6
+36,7
@@
#include "irgwalk.h"
#include "irhooks.h"
#include "entity_t.h"
#include "irgwalk.h"
#include "irhooks.h"
#include "entity_t.h"
+#include "ircons.h"
#include "error.h"
#include "pset_new.h"
#include "error.h"
#include "pset_new.h"
@@
-57,8
+57,8
@@
static unsigned irg_walk_2_pre(ir_node *node, irg_walk_func *pre, void *env)
pre(node, env);
pre(node, env);
- if (
node->op != op_Block
) {
- ir_node *pred = get_
irn_n(node, -1
);
+ if (
!is_Block(node)
) {
+ ir_node *pred = get_
nodes_block(node
);
if (pred->visited < irg->visited)
cnt += irg_walk_2_pre(pred, pre, env);
}
if (pred->visited < irg->visited)
cnt += irg_walk_2_pre(pred, pre, env);
}
@@
-83,8
+83,8
@@
static unsigned irg_walk_2_post(ir_node *node, irg_walk_func *post, void *env)
set_irn_visited(node, irg->visited);
set_irn_visited(node, irg->visited);
- if (
node->op != op_Block
) {
- ir_node *pred = get_
irn_n(node, -1
);
+ if (
!is_Block(node)
) {
+ ir_node *pred = get_
nodes_block(node
);
if (pred->visited < irg->visited)
cnt += irg_walk_2_post(pred, post, env);
}
if (pred->visited < irg->visited)
cnt += irg_walk_2_post(pred, post, env);
}
@@
-115,8
+115,8
@@
static unsigned irg_walk_2_both(ir_node *node, irg_walk_func *pre,
pre(node, env);
pre(node, env);
- if (
node->op != op_Block
) {
- ir_node *pred = get_
irn_n(node, -1
);
+ if (
!is_Block(node)
) {
+ ir_node *pred = get_
nodes_block(node
);
if (pred->visited < irg->visited)
cnt += irg_walk_2_both(pred, pre, post, env);
}
if (pred->visited < irg->visited)
cnt += irg_walk_2_both(pred, pre, post, env);
}
@@
-131,11
+131,6
@@
static unsigned irg_walk_2_both(ir_node *node, irg_walk_func *pre,
return cnt;
}
return cnt;
}
-/**
- * Intraprozedural graph walker.
- *
- * @return number of visited nodes
- */
unsigned irg_walk_2(ir_node *node, irg_walk_func *pre, irg_walk_func *post,
void *env)
{
unsigned irg_walk_2(ir_node *node, irg_walk_func *pre, irg_walk_func *post,
void *env)
{
@@
-171,9
+166,6
@@
void irg_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post,
current_ir_graph = rem;
}
current_ir_graph = rem;
}
-/*
- * walk over a graph
- */
void irg_walk_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env)
{
ir_graph * rem = current_ir_graph;
void irg_walk_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env)
{
ir_graph * rem = current_ir_graph;
@@
-185,12
+177,9
@@
void irg_walk_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void
current_ir_graph = rem;
}
current_ir_graph = rem;
}
-/* Executes irg_walk(end, pre, post, env) for all irgraphs in irprog.
- Sets current_ir_graph properly for each walk. Conserves current
- current_ir_graph. */
void all_irg_walk(irg_walk_func *pre, irg_walk_func *post, void *env)
{
void all_irg_walk(irg_walk_func *pre, irg_walk_func *post, void *env)
{
-
in
t i, n;
+
size_
t i, n;
ir_graph *irg;
for (i = 0, n = get_irp_n_irgs(); i < n; i++) {
ir_graph *irg;
for (i = 0, n = get_irp_n_irgs(); i < n; i++) {
@@
-199,8
+188,6
@@
void all_irg_walk(irg_walk_func *pre, irg_walk_func *post, void *env)
}
}
}
}
-/***************************************************************************/
-
/**
* specialized version of irg_walk_in_or_dep_2, called if only pre callback exists
*
/**
* specialized version of irg_walk_in_or_dep_2, called if only pre callback exists
*
@@
-216,8
+203,8
@@
static unsigned irg_walk_in_or_dep_2_pre(ir_node *node, irg_walk_func *pre, void
pre(node, env);
pre(node, env);
- if (
node->op != op_Block
) {
- ir_node *pred = get_
irn_n(node, -1
);
+ if (
!is_Block(node)
) {
+ ir_node *pred = get_
nodes_block(node
);
if (pred->visited < irg->visited)
cnt += irg_walk_in_or_dep_2_pre(pred, pre, env);
}
if (pred->visited < irg->visited)
cnt += irg_walk_in_or_dep_2_pre(pred, pre, env);
}
@@
-242,8
+229,8
@@
static unsigned irg_walk_in_or_dep_2_post(ir_node *node, irg_walk_func *post, vo
set_irn_visited(node, irg->visited);
set_irn_visited(node, irg->visited);
- if (
node->op != op_Block
) {
- ir_node *pred = get_
irn_n(node, -1
);
+ if (
!is_Block(node)
) {
+ ir_node *pred = get_
nodes_block(node
);
if (pred->visited < irg->visited)
cnt += irg_walk_in_or_dep_2_post(pred, post, env);
}
if (pred->visited < irg->visited)
cnt += irg_walk_in_or_dep_2_post(pred, post, env);
}
@@
-273,8
+260,8
@@
static unsigned irg_walk_in_or_dep_2_both(ir_node *node, irg_walk_func *pre, irg
pre(node, env);
pre(node, env);
- if (
node->op != op_Block
) {
- ir_node *pred = get_
irn_n(node, -1
);
+ if (
!is_Block(node)
) {
+ ir_node *pred = get_
nodes_block(node
);
if (pred->visited < irg->visited)
cnt += irg_walk_in_or_dep_2_both(pred, pre, post, env);
}
if (pred->visited < irg->visited)
cnt += irg_walk_in_or_dep_2_both(pred, pre, post, env);
}
@@
-304,9
+291,6
@@
static unsigned irg_walk_in_or_dep_2(ir_node *node, irg_walk_func *pre, irg_walk
else return irg_walk_in_or_dep_2_both(node, pre, post, env);
}
else return irg_walk_in_or_dep_2_both(node, pre, post, env);
}
-/*
- * Generic graph walker. Follows dependency edges as well.
- */
void irg_walk_in_or_dep(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env)
{
assert(is_ir_node(node));
void irg_walk_in_or_dep(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env)
{
assert(is_ir_node(node));
@@
-317,9
+301,6
@@
void irg_walk_in_or_dep(ir_node *node, irg_walk_func *pre, irg_walk_func *post,
ir_free_resources(current_ir_graph, IR_RESOURCE_IRN_VISITED);
}
ir_free_resources(current_ir_graph, IR_RESOURCE_IRN_VISITED);
}
-/*
- * Walk over a graph. Follow all edges (including dependencies)
- */
void irg_walk_in_or_dep_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env)
{
ir_graph * rem = current_ir_graph;
void irg_walk_in_or_dep_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env)
{
ir_graph * rem = current_ir_graph;
@@
-331,8
+312,6
@@
void irg_walk_in_or_dep_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *
current_ir_graph = rem;
}
current_ir_graph = rem;
}
-/***************************************************************************/
-
/* Walks back from n until it finds a real cf op. */
static ir_node *get_cf_op(ir_node *n)
{
/* Walks back from n until it finds a real cf op. */
static ir_node *get_cf_op(ir_node *n)
{
@@
-372,38
+351,26
@@
static void irg_block_walk_2(ir_node *node, irg_walk_func *pre,
post(node, env);
}
post(node, env);
}
-
-/* walks only over Block nodes in the graph. Has it's own visited
- flag, so that it can be interleaved with the other walker. */
-void irg_block_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env)
+void irg_block_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post,
+ void *env)
{
{
- ir_graph *irg = get_irn_irg(node);
- ir_node *block, *pred;
- int i;
+ ir_graph *irg = get_irn_irg(node);
+ ir_node *block = is_Block(node) ? node : get_nodes_block(node);
hook_irg_block_walk(irg, node, (generic_func *)pre, (generic_func *)post);
hook_irg_block_walk(irg, node, (generic_func *)pre, (generic_func *)post);
- assert(node);
ir_reserve_resources(irg, IR_RESOURCE_BLOCK_VISITED);
inc_irg_block_visited(irg);
ir_reserve_resources(irg, IR_RESOURCE_BLOCK_VISITED);
inc_irg_block_visited(irg);
- block = is_Block(node) ? node : get_nodes_block(node);
- assert(is_Block(block));
irg_block_walk_2(block, pre, post, env);
irg_block_walk_2(block, pre, post, env);
- /*
keepalive: the endless loops ...
*/
+ /*
Some blocks might be only reachable through keep-alive edges
*/
if (is_End(node)) {
int arity = get_irn_arity(node);
if (is_End(node)) {
int arity = get_irn_arity(node);
+ int i;
for (i = 0; i < arity; i++) {
for (i = 0; i < arity; i++) {
- pred = get_irn_n(node, i);
- if (!is_Block(pred)) {
- pred = get_nodes_block(pred);
- if (!is_Block(pred)) {
- /* if rare cases a kept node might have a bad block input */
- continue;
- }
- }
- /* Sometimes the blocks died, but are still reachable through kept nodes.
- * Make sure the algorithms that try to remove these reach them. */
+ ir_node *pred = get_irn_n(node, i);
+ if (!is_Block(pred))
+ continue;
irg_block_walk_2(pred, pre, post, env);
}
}
irg_block_walk_2(pred, pre, post, env);
}
}
@@
-411,9
+378,6
@@
void irg_block_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void
ir_free_resources(irg, IR_RESOURCE_BLOCK_VISITED);
}
ir_free_resources(irg, IR_RESOURCE_BLOCK_VISITED);
}
-/*
- * walk over a graph block wise
- */
void irg_block_walk_graph(ir_graph *irg, irg_walk_func *pre,
irg_walk_func *post, void *env)
{
void irg_block_walk_graph(ir_graph *irg, irg_walk_func *pre,
irg_walk_func *post, void *env)
{
@@
-423,22
+387,19
@@
void irg_block_walk_graph(ir_graph *irg, irg_walk_func *pre,
current_ir_graph = rem;
}
current_ir_graph = rem;
}
-/*
- * Additionally walk over all anchors. Do NOT increase the visit flag.
- */
void irg_walk_anchors(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env)
{
ir_graph * rem = current_ir_graph;
current_ir_graph = irg;
void irg_walk_anchors(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env)
{
ir_graph * rem = current_ir_graph;
current_ir_graph = irg;
+ ir_reserve_resources(irg, IR_RESOURCE_IRN_VISITED);
inc_irg_visited(irg);
irg_walk_2(irg->anchor, pre, post, env);
inc_irg_visited(irg);
irg_walk_2(irg->anchor, pre, post, env);
+ ir_free_resources(irg, IR_RESOURCE_IRN_VISITED);
current_ir_graph = rem;
}
current_ir_graph = rem;
}
-/********************************************************************/
-
typedef struct walk_env {
irg_walk_func *pre;
irg_walk_func *post;
typedef struct walk_env {
irg_walk_func *pre;
irg_walk_func *post;
@@
-477,20
+438,15
@@
static void walk_entity(ir_entity *ent, void *env)
if (ent->initializer != NULL) {
walk_initializer(ent->initializer, my_env);
if (ent->initializer != NULL) {
walk_initializer(ent->initializer, my_env);
- } else if (entity_has_compound_ent_values(ent)) {
- int i, n_vals = get_compound_ent_n_values(ent);
-
- for (i = 0; i < n_vals; i++)
- irg_walk(get_compound_ent_value(ent, i), my_env->pre, my_env->post, my_env->env);
}
}
}
}
-/* Walks over all code in const_code_irg. */
void walk_const_code(irg_walk_func *pre, irg_walk_func *post, void *env)
{
void walk_const_code(irg_walk_func *pre, irg_walk_func *post, void *env)
{
- int i, j, n_types;
walk_env my_env;
ir_segment_t s;
walk_env my_env;
ir_segment_t s;
+ size_t i;
+ size_t n_types;
ir_graph *rem = current_ir_graph;
current_ir_graph = get_const_code_irg();
ir_graph *rem = current_ir_graph;
current_ir_graph = get_const_code_irg();
@@
-513,7
+469,7
@@
void walk_const_code(irg_walk_func *pre, irg_walk_func *post, void *env)
for (i = 0; i < n_types; i++) {
ir_type *tp = get_irp_type(i);
if (is_Array_type(tp)) {
for (i = 0; i < n_types; i++) {
ir_type *tp = get_irp_type(i);
if (is_Array_type(tp)) {
-
int
n_dim = get_array_n_dimensions(tp);
+
size_t j,
n_dim = get_array_n_dimensions(tp);
for (j = 0; j < n_dim; j++) {
ir_node *n = get_array_lower_bound(tp, j);
if (n) irg_walk(n, pre, post, env);
for (j = 0; j < n_dim; j++) {
ir_node *n = get_array_lower_bound(tp, j);
if (n) irg_walk(n, pre, post, env);