Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Zwinkau
libfirm
Commits
2672e202
Commit
2672e202
authored
Mar 14, 2013
by
Matthias Braun
Browse files
coding style cleanup, use C99
parent
9697d318
Changes
18
Expand all
Show whitespace changes
Inline
Side-by-side
ir/ana/analyze_irg_args.c
View file @
2672e202
...
...
@@ -31,16 +31,11 @@
*/
static
ptr_access_kind
analyze_arg
(
ir_node
*
arg
,
ptr_access_kind
bits
)
{
int
i
,
p
;
ir_node
*
succ
;
/* We must visit a node once to avoid endless recursion.*/
mark_irn_visited
(
arg
);
for
(
i
=
get_irn_n_outs
(
arg
)
-
1
;
i
>=
0
;
--
i
)
{
succ
=
get_irn_out
(
arg
,
i
);
/* We was here.*/
for
(
int
i
=
get_irn_n_outs
(
arg
);
i
--
>
0
;
)
{
ir_node
*
succ
=
get_irn_out
(
arg
,
i
);
if
(
irn_visited
(
succ
))
continue
;
...
...
@@ -68,7 +63,7 @@ static ptr_access_kind analyze_arg(ir_node *arg, ptr_access_kind bits)
if
(
is_SymConst_addr_ent
(
ptr
))
{
meth_ent
=
get_SymConst_entity
(
ptr
);
for
(
p
=
get_Call_n_params
(
succ
)
-
1
;
p
>
=
0
;
--
p
)
{
for
(
int
p
=
get_Call_n_params
(
succ
);
p
--
>
0
;
)
{
if
(
get_Call_param
(
succ
,
p
)
==
arg
)
{
/* an arg can be used more than once ! */
bits
|=
get_method_param_access
(
meth_ent
,
p
);
...
...
@@ -76,11 +71,10 @@ static ptr_access_kind analyze_arg(ir_node *arg, ptr_access_kind bits)
}
}
else
if
(
is_Sel
(
ptr
)
&&
get_irp_callee_info_state
()
==
irg_callee_info_consistent
)
{
/* is be a polymorphic call but callee information is available */
int
n_params
=
get_Call_n_params
(
succ
);
int
c
;
size_t
n_params
=
get_Call_n_params
(
succ
);
/* simply look into ALL possible callees */
for
(
c
=
get_Call_n_callees
(
succ
)
-
1
;
c
>
=
0
;
--
c
)
{
for
(
int
c
=
get_Call_n_callees
(
succ
);
c
--
>
0
;
)
{
meth_ent
=
get_Call_callee
(
succ
,
c
);
/* unknown_entity is used to signal that we don't know what is called */
...
...
@@ -89,7 +83,7 @@ static ptr_access_kind analyze_arg(ir_node *arg, ptr_access_kind bits)
break
;
}
for
(
p
=
n_params
-
1
;
p
>
=
0
;
--
p
)
{
for
(
size_t
p
=
n_params
;
p
--
>
0
;
)
{
if
(
get_Call_param
(
succ
,
p
)
==
arg
)
{
/* an arg can be used more than once ! */
bits
|=
get_method_param_access
(
meth_ent
,
p
);
...
...
@@ -162,16 +156,8 @@ static ptr_access_kind analyze_arg(ir_node *arg, ptr_access_kind bits)
*/
static
void
analyze_ent_args
(
ir_entity
*
ent
)
{
ir_graph
*
irg
;
ir_node
*
irg_args
,
*
arg
;
ir_mode
*
arg_mode
;
int
nparams
,
i
;
long
proj_nr
;
ir_type
*
mtp
;
ptr_access_kind
*
rw_info
;
mtp
=
get_entity_type
(
ent
);
nparams
=
get_method_n_params
(
mtp
);
ir_type
*
mtp
=
get_entity_type
(
ent
);
size_t
nparams
=
get_method_n_params
(
mtp
);
ent
->
attr
.
mtd_attr
.
param_access
=
NEW_ARR_F
(
ptr_access_kind
,
nparams
);
...
...
@@ -181,37 +167,36 @@ static void analyze_ent_args(ir_entity *ent)
if
(
nparams
<=
0
)
return
;
irg
=
get_entity_irg
(
ent
);
/* we have not yet analyzed the graph, set ALL access for pointer args */
for
(
i
=
nparams
-
1
;
i
>
=
0
;
--
i
)
{
for
(
size_t
i
=
nparams
;
i
--
>
0
;
)
{
ir_type
*
type
=
get_method_param_type
(
mtp
,
i
);
ent
->
attr
.
mtd_attr
.
param_access
[
i
]
=
is_Pointer_type
(
type
)
?
ptr_access_all
:
ptr_access_none
;
}
if
(
!
irg
)
{
ir_graph
*
irg
=
get_entity_irg
(
ent
);
if
(
irg
==
NULL
)
{
/* no graph, no better info */
return
;
}
assure_irg_outs
(
irg
);
irg_args
=
get_irg_args
(
irg
);
ir_node
*
irg_args
=
get_irg_args
(
irg
);
/* A array to save the information for each argument with
mode reference.*/
ptr_access_kind
*
rw_info
;
NEW_ARR_A
(
ptr_access_kind
,
rw_info
,
nparams
);
/* We initialize the element with none state. */
for
(
i
=
nparams
-
1
;
i
>
=
0
;
--
i
)
for
(
size_t
i
=
nparams
;
i
--
>
0
;
)
rw_info
[
i
]
=
ptr_access_none
;
/* search for arguments with mode reference
to analyze them.*/
for
(
i
=
get_irn_n_outs
(
irg_args
)
-
1
;
i
>
=
0
;
--
i
)
{
arg
=
get_irn_out
(
irg_args
,
i
);
arg_mode
=
get_irn_mode
(
arg
);
proj_nr
=
get_Proj_proj
(
arg
);
for
(
int
i
=
get_irn_n_outs
(
irg_args
);
i
--
>
0
;
)
{
ir_node
*
arg
=
get_irn_out
(
irg_args
,
i
);
ir_mode
*
arg_mode
=
get_irn_mode
(
arg
);
long
proj_nr
=
get_Proj_proj
(
arg
);
if
(
mode_is_reference
(
arg_mode
))
rw_info
[
proj_nr
]
|=
analyze_arg
(
arg
,
rw_info
[
proj_nr
]);
...
...
@@ -224,25 +209,22 @@ static void analyze_ent_args(ir_entity *ent)
void
analyze_irg_args
(
ir_graph
*
irg
)
{
ir_entity
*
ent
;
if
(
irg
==
get_const_code_irg
())
return
;
ent
=
get_irg_entity
(
irg
);
if
(
!
ent
)
ir_entity
*
entity
=
get_irg_entity
(
irg
);
if
(
!
ent
ity
)
return
;
if
(
!
ent
->
attr
.
mtd_attr
.
param_access
)
analyze_ent_args
(
ent
);
if
(
!
ent
ity
->
attr
.
mtd_attr
.
param_access
)
analyze_ent_args
(
ent
ity
);
}
ptr_access_kind
get_method_param_access
(
ir_entity
*
ent
,
size_t
pos
)
{
#ifndef NDEBUG
ir_type
*
mtp
=
get_entity_type
(
ent
);
int
is_variadic
=
get_method_variadicity
(
mtp
)
==
variadicity_variadic
;
bool
is_variadic
=
get_method_variadicity
(
mtp
)
==
variadicity_variadic
;
assert
(
is_variadic
||
pos
<
get_method_n_params
(
mtp
));
#endif
...
...
@@ -278,17 +260,12 @@ enum args_weight {
*/
static
unsigned
calc_method_param_weight
(
ir_node
*
arg
)
{
int
i
,
j
,
k
;
ir_node
*
succ
,
*
op
;
unsigned
weight
=
null_weight
;
/* We mark the nodes to avoid endless recursion */
mark_irn_visited
(
arg
);
for
(
i
=
get_irn_n_outs
(
arg
)
-
1
;
i
>=
0
;
i
--
)
{
succ
=
get_irn_out
(
arg
,
i
);
/* We was here.*/
unsigned
weight
=
null_weight
;
for
(
int
i
=
get_irn_n_outs
(
arg
);
i
--
>
0
;
)
{
ir_node
*
succ
=
get_irn_out
(
arg
,
i
);
if
(
irn_visited
(
succ
))
continue
;
...
...
@@ -304,9 +281,10 @@ static unsigned calc_method_param_weight(ir_node *arg)
weight
+=
indirect_call_weight
;
}
break
;
case
iro_Cmp
:
case
iro_Cmp
:
{
/* We have reached a cmp and we must increase the
weight with the cmp_weight. */
ir_node
*
op
;
if
(
get_Cmp_left
(
succ
)
==
arg
)
op
=
get_Cmp_right
(
succ
);
else
...
...
@@ -317,6 +295,7 @@ static unsigned calc_method_param_weight(ir_node *arg)
}
else
weight
+=
cmp_weight
;
break
;
}
case
iro_Cond
:
/* the argument is used for a SwitchCond, a big win */
weight
+=
const_cmp_weight
*
get_irn_n_outs
(
succ
);
...
...
@@ -327,11 +306,11 @@ static unsigned calc_method_param_weight(ir_node *arg)
break
;
case
iro_Tuple
:
/* unoptimized tuple */
for
(
j
=
get_Tuple_n_preds
(
succ
)
-
1
;
j
>
=
0
;
--
j
)
{
for
(
int
j
=
get_Tuple_n_preds
(
succ
);
j
--
>
0
;
)
{
ir_node
*
pred
=
get_Tuple_pred
(
succ
,
j
);
if
(
pred
==
arg
)
{
/* look for Proj(j) */
for
(
k
=
get_irn_n_outs
(
succ
)
-
1
;
k
>
=
0
;
--
k
)
{
for
(
int
k
=
get_irn_n_outs
(
succ
);
k
--
>
0
;
)
{
ir_node
*
succ_succ
=
get_irn_out
(
succ
,
k
);
if
(
is_Proj
(
succ_succ
))
{
if
(
get_Proj_proj
(
succ_succ
)
==
j
)
{
...
...
@@ -352,6 +331,7 @@ static unsigned calc_method_param_weight(ir_node *arg)
BinOp is a constant we increase the weight with const_binop_weight
and call the function recursive.
*/
ir_node
*
op
;
if
(
get_binop_left
(
succ
)
==
arg
)
op
=
get_binop_right
(
succ
);
else
...
...
@@ -383,15 +363,9 @@ static unsigned calc_method_param_weight(ir_node *arg)
*/
static
void
analyze_method_params_weight
(
ir_entity
*
ent
)
{
ir_type
*
mtp
;
ir_graph
*
irg
;
int
nparams
,
i
,
proj_nr
;
ir_node
*
irg_args
,
*
arg
;
mtp
=
get_entity_type
(
ent
);
nparams
=
get_method_n_params
(
mtp
);
/* allocate a new array. currently used as 'analysed' flag */
ir_type
*
mtp
=
get_entity_type
(
ent
);
size_t
nparams
=
get_method_n_params
(
mtp
);
ent
->
attr
.
mtd_attr
.
param_weight
=
NEW_ARR_F
(
unsigned
,
nparams
);
/* If the method haven't parameters we have nothing to do. */
...
...
@@ -399,10 +373,10 @@ static void analyze_method_params_weight(ir_entity *ent)
return
;
/* First we initialize the parameter weights with 0. */
for
(
i
=
nparams
-
1
;
i
>
=
0
;
i
--
)
for
(
size_t
i
=
nparams
;
i
--
>
0
;
)
ent
->
attr
.
mtd_attr
.
param_weight
[
i
]
=
null_weight
;
irg
=
get_entity_irg
(
ent
);
ir_graph
*
irg
=
get_entity_irg
(
ent
);
if
(
irg
==
NULL
)
{
/* no graph, no better info */
return
;
...
...
@@ -411,10 +385,10 @@ static void analyze_method_params_weight(ir_entity *ent)
/* Call algorithm that computes the out edges */
assure_irg_outs
(
irg
);
irg_args
=
get_irg_args
(
irg
);
for
(
i
=
get_irn_n_outs
(
irg_args
)
-
1
;
i
>
=
0
;
--
i
)
{
arg
=
get_irn_out
(
irg_args
,
i
);
proj_nr
=
get_Proj_proj
(
arg
);
ir_node
*
irg_args
=
get_irg_args
(
irg
);
for
(
int
i
=
get_irn_n_outs
(
irg_args
);
i
--
>
0
;
)
{
ir_node
*
arg
=
get_irn_out
(
irg_args
,
i
);
long
proj_nr
=
get_Proj_proj
(
arg
);
ent
->
attr
.
mtd_attr
.
param_weight
[
proj_nr
]
+=
calc_method_param_weight
(
arg
);
}
}
...
...
ir/ana/callgraph.c
View file @
2672e202
...
...
@@ -26,12 +26,11 @@
#include "pmap.h"
#include "hashptr.h"
#include "raw_bitset.h"
#include "error.h"
#include "irgwalk.h"
static
ir_visited_t
master_cg_visited
=
0
;
static
inline
int
cg_irg_visited
(
ir_graph
*
n
);
static
inline
void
mark_cg_irg_visited
(
ir_graph
*
n
);
irp_callgraph_state
get_irp_callgraph_state
(
void
)
{
...
...
@@ -45,7 +44,7 @@ void set_irp_callgraph_state(irp_callgraph_state s)
size_t
get_irg_n_callers
(
const
ir_graph
*
irg
)
{
assert
(
irg
->
callers
);
assert
(
irg
->
callers
!=
NULL
);
return
irg
->
callers
?
ARR_LEN
(
irg
->
callers
)
:
0
;
}
...
...
@@ -64,12 +63,11 @@ int is_irg_caller_backedge(const ir_graph *irg, size_t pos)
/** Search the caller in the list of all callers and set its backedge property. */
static
void
set_irg_caller_backedge
(
ir_graph
*
irg
,
const
ir_graph
*
caller
)
{
size_t
i
,
n_callers
=
get_irg_n_callers
(
irg
);
/* allocate a new array on demand */
size_t
n_callers
=
get_irg_n_callers
(
irg
);
if
(
irg
->
caller_isbe
==
NULL
)
irg
->
caller_isbe
=
rbitset_malloc
(
n_callers
);
for
(
i
=
0
;
i
<
n_callers
;
++
i
)
{
for
(
size_t
i
=
0
;
i
<
n_callers
;
++
i
)
{
if
(
get_irg_caller
(
irg
,
i
)
==
caller
)
{
rbitset_set
(
irg
->
caller_isbe
,
i
);
break
;
...
...
@@ -79,10 +77,9 @@ static void set_irg_caller_backedge(ir_graph *irg, const ir_graph *caller)
int
has_irg_caller_backedge
(
const
ir_graph
*
irg
)
{
size_t
i
,
n_callers
=
get_irg_n_callers
(
irg
);
if
(
irg
->
caller_isbe
!=
NULL
)
{
for
(
i
=
0
;
i
<
n_callers
;
++
i
)
for
(
size_t
i
=
0
,
n_callers
=
get_irg_n_callers
(
irg
);
i
<
n_callers
;
++
i
)
if
(
rbitset_is_set
(
irg
->
caller_isbe
,
i
))
return
1
;
}
...
...
@@ -98,30 +95,26 @@ static size_t reverse_pos(const ir_graph *callee, size_t pos_caller)
{
ir_graph
*
caller
=
get_irg_caller
(
callee
,
pos_caller
);
/* search the other relation for the corresponding edge. */
size_t
i
,
n_callees
=
get_irg_n_callees
(
caller
);
for
(
i
=
0
;
i
<
n_callees
;
++
i
)
{
for
(
size_t
i
=
0
,
n_callees
=
get_irg_n_callees
(
caller
);
i
<
n_callees
;
++
i
)
{
if
(
get_irg_callee
(
caller
,
i
)
==
callee
)
{
return
i
;
}
}
assert
(
!
"reverse_pos() did not find position"
);
return
0
;
panic
(
"reverse_pos() did not find position"
);
}
size_t
get_irg_caller_loop_depth
(
const
ir_graph
*
irg
,
size_t
pos
)
{
ir_graph
*
caller
=
get_irg_caller
(
irg
,
pos
);
size_t
pos_callee
=
reverse_pos
(
irg
,
pos
);
return
get_irg_callee_loop_depth
(
caller
,
pos_callee
);
}
size_t
get_irg_n_callees
(
const
ir_graph
*
irg
)
{
assert
(
irg
->
callees
);
return
irg
->
callees
?
ARR_LEN
(
irg
->
callees
)
:
0
;
assert
(
irg
->
callees
!=
NULL
);
return
ARR_LEN
(
irg
->
callees
);
}
ir_graph
*
get_irg_callee
(
const
ir_graph
*
irg
,
size_t
pos
)
...
...
@@ -138,10 +131,9 @@ int is_irg_callee_backedge(const ir_graph *irg, size_t pos)
int
has_irg_callee_backedge
(
const
ir_graph
*
irg
)
{
size_t
i
,
n_callees
=
get_irg_n_callees
(
irg
);
if
(
irg
->
callee_isbe
!=
NULL
)
{
for
(
i
=
0
;
i
<
n_callees
;
++
i
)
for
(
size_t
i
=
0
,
n_callees
=
get_irg_n_callees
(
irg
);
i
<
n_callees
;
++
i
)
if
(
rbitset_is_set
(
irg
->
callee_isbe
,
i
))
return
1
;
}
...
...
@@ -153,9 +145,8 @@ int has_irg_callee_backedge(const ir_graph *irg)
*/
static
void
set_irg_callee_backedge
(
ir_graph
*
irg
,
size_t
pos
)
{
size_t
n
=
get_irg_n_callees
(
irg
);
/* allocate a new array on demand */
size_t
n
=
get_irg_n_callees
(
irg
);
if
(
irg
->
callee_isbe
==
NULL
)
irg
->
callee_isbe
=
rbitset_malloc
(
n
);
assert
(
pos
<
n
);
...
...
@@ -174,27 +165,20 @@ size_t get_irg_callee_loop_depth(const ir_graph *irg, size_t pos)
*/
static
void
ana_Call
(
ir_node
*
n
,
void
*
env
)
{
size_t
i
,
n_callees
;
ir_graph
*
irg
;
(
void
)
env
;
if
(
!
is_Call
(
n
))
return
;
if
(
!
is_Call
(
n
))
return
;
irg
=
get_irn_irg
(
n
);
n_callees
=
get_Call_n_callees
(
n
);
for
(
i
=
0
;
i
<
n_callees
;
++
i
)
{
ir_graph
*
irg
=
get_irn_irg
(
n
);
for
(
size_t
i
=
0
,
n_callees
=
get_Call_n_callees
(
n
);
i
<
n_callees
;
++
i
)
{
ir_entity
*
callee_e
=
get_Call_callee
(
n
,
i
);
ir_graph
*
callee
=
get_entity_irg
(
callee_e
);
if
(
callee
)
{
cg_callee_entry
buf
;
cg_callee_entry
*
found
;
unsigned
depth
;
buf
.
irg
=
callee
;
pset_insert
((
pset
*
)
callee
->
callers
,
irg
,
hash_ptr
(
irg
));
found
=
(
cg_callee_entry
*
)
pset_find
((
pset
*
)
irg
->
callees
,
&
buf
,
hash_ptr
(
callee
));
cg_callee_entry
*
found
=
(
cg_callee_entry
*
)
pset_find
((
pset
*
)
irg
->
callees
,
&
buf
,
hash_ptr
(
callee
));
if
(
found
)
{
/* add Call node to list, compute new nesting. */
ir_node
**
arr
=
found
->
call_list
;
ARR_APP1
(
ir_node
*
,
arr
,
n
);
...
...
@@ -207,7 +191,7 @@ static void ana_Call(ir_node *n, void *env)
found
->
max_depth
=
0
;
pset_insert
((
pset
*
)
irg
->
callees
,
found
,
hash_ptr
(
callee
));
}
depth
=
get_loop_depth
(
get_irn_loop
(
get_nodes_block
(
n
)));
unsigned
depth
=
get_loop_depth
(
get_irn_loop
(
get_nodes_block
(
n
)));
found
->
max_depth
=
(
depth
>
found
->
max_depth
)
?
depth
:
found
->
max_depth
;
}
}
...
...
@@ -231,13 +215,11 @@ static int graph_cmp(const void *elt, const void *key)
void
compute_callgraph
(
void
)
{
size_t
i
,
n_irgs
;
/* initialize */
free_callgraph
();
n_irgs
=
get_irp_n_irgs
();
for
(
i
=
0
;
i
<
n_irgs
;
++
i
)
{
size_t
n_irgs
=
get_irp_n_irgs
();
for
(
size_t
i
=
0
;
i
<
n_irgs
;
++
i
)
{
ir_graph
*
irg
=
get_irp_irg
(
i
);
assert
(
get_irg_callee_info_state
(
irg
)
==
irg_callee_info_consistent
);
irg
->
callees
=
(
cg_callee_entry
**
)
new_pset
(
cg_callee_entry_cmp
,
8
);
...
...
@@ -246,30 +228,28 @@ void compute_callgraph(void)
}
/* Compute the call graph */
for
(
i
=
0
;
i
<
n_irgs
;
++
i
)
{
for
(
size_t
i
=
0
;
i
<
n_irgs
;
++
i
)
{
ir_graph
*
irg
=
get_irp_irg
(
i
);
construct_cf_backedges
(
irg
);
// We also find the maximal loop depth of a call.
irg_walk_graph
(
irg
,
ana_Call
,
NULL
,
NULL
);
}
/* Change the sets to arrays. */
for
(
i
=
0
;
i
<
n_irgs
;
++
i
)
{
size_t
j
,
count
;
for
(
size_t
i
=
0
;
i
<
n_irgs
;
++
i
)
{
ir_graph
*
irg
=
get_irp_irg
(
i
);
pset
*
callee_set
,
*
caller_set
;
callee_set
=
(
pset
*
)
irg
->
callees
;
count
=
pset_count
(
callee_set
);
pset
*
callee_set
=
(
pset
*
)
irg
->
callees
;
size_t
count
=
pset_count
(
callee_set
);
irg
->
callees
=
NEW_ARR_F
(
cg_callee_entry
*
,
count
);
irg
->
callee_isbe
=
NULL
;
j
=
0
;
size_t
j
=
0
;
foreach_pset
(
callee_set
,
cg_callee_entry
,
callee
)
{
irg
->
callees
[
j
++
]
=
callee
;
}
del_pset
(
callee_set
);
assert
(
j
==
count
);
caller_set
=
(
pset
*
)
irg
->
callers
;
pset
*
caller_set
=
(
pset
*
)
irg
->
callers
;
count
=
pset_count
(
caller_set
);
irg
->
callers
=
NEW_ARR_F
(
ir_graph
*
,
count
);
irg
->
caller_isbe
=
NULL
;
...
...
@@ -285,8 +265,7 @@ void compute_callgraph(void)
void
free_callgraph
(
void
)
{
size_t
i
,
n_irgs
=
get_irp_n_irgs
();
for
(
i
=
0
;
i
<
n_irgs
;
++
i
)
{
for
(
size_t
i
=
0
,
n_irgs
=
get_irp_n_irgs
();
i
<
n_irgs
;
++
i
)
{
ir_graph
*
irg
=
get_irp_irg
(
i
);
if
(
irg
->
callees
)
DEL_ARR_F
(
irg
->
callees
);
if
(
irg
->
callers
)
DEL_ARR_F
(
irg
->
callers
);
...
...
@@ -300,43 +279,55 @@ void free_callgraph(void)
set_irp_callgraph_state
(
irp_callgraph_none
);
}
/**
* Returns non-zero if a graph was already visited.
*/
static
inline
int
cg_irg_visited
(
ir_graph
*
irg
)
{
return
irg
->
self_visited
>=
master_cg_visited
;
}
static
void
do_walk
(
ir_graph
*
irg
,
callgraph_walk_func
*
pre
,
callgraph_walk_func
*
post
,
void
*
env
)
/**
* Marks a graph as visited.
*/
static
inline
void
mark_cg_irg_visited
(
ir_graph
*
irg
)
{
size_t
i
,
n_callees
;
irg
->
self_visited
=
master_cg_visited
;
}
static
void
do_walk
(
ir_graph
*
irg
,
callgraph_walk_func
*
pre
,
callgraph_walk_func
*
post
,
void
*
env
)
{
if
(
cg_irg_visited
(
irg
))
return
;
mark_cg_irg_visited
(
irg
);
if
(
pre
)
if
(
pre
!=
NULL
)
pre
(
irg
,
env
);
n_callees
=
get_irg_n_callees
(
irg
);
for
(
i
=
0
;
i
<
n_callees
;
i
++
)
{
for
(
size_t
i
=
0
,
n_callees
=
get_irg_n_callees
(
irg
);
i
<
n_callees
;
i
++
)
{
ir_graph
*
m
=
get_irg_callee
(
irg
,
i
);
do_walk
(
m
,
pre
,
post
,
env
);
}
if
(
post
)
if
(
post
!=
NULL
)
post
(
irg
,
env
);
}
void
callgraph_walk
(
callgraph_walk_func
*
pre
,
callgraph_walk_func
*
post
,
void
*
env
)
{
size_t
i
,
n_irgs
=
get_irp_n_irgs
();
++
master_cg_visited
;
/* roots are methods which have no callers in the current program */
for
(
i
=
0
;
i
<
n_irgs
;
++
i
)
{
size_t
n_irgs
=
get_irp_n_irgs
();
for
(
size_t
i
=
0
;
i
<
n_irgs
;
++
i
)
{
ir_graph
*
irg
=
get_irp_irg
(
i
);
if
(
get_irg_n_callers
(
irg
)
==
0
)
do_walk
(
irg
,
pre
,
post
,
env
);
}
/* in case of unreachable call loops we haven't visited some irgs yet */
for
(
i
=
0
;
i
<
n_irgs
;
i
++
)
{
for
(
size_t
i
=
0
;
i
<
n_irgs
;
i
++
)
{
ir_graph
*
irg
=
get_irp_irg
(
i
);
do_walk
(
irg
,
pre
,
post
,
env
);
}
...
...
@@ -367,22 +358,6 @@ static inline scc_info *new_scc_info(struct obstack *obst)
return
OALLOCZ
(
obst
,
scc_info
);
}
/**
* Returns non-zero if a graph was already visited.
*/
static
inline
int
cg_irg_visited
(
ir_graph
*
irg
)
{
return
irg
->
self_visited
>=
master_cg_visited
;
}
/**
* Marks a graph as visited.
*/
static
inline
void
mark_cg_irg_visited
(
ir_graph
*
irg
)
{
irg
->
self_visited
=
master_cg_visited
;
}
/**
* Set a graphs visited flag to i.
*/
...
...
@@ -402,49 +377,49 @@ static inline ir_visited_t get_cg_irg_visited(const ir_graph *irg)
static
inline
void
mark_irg_in_stack
(
ir_graph
*
irg
)
{
scc_info
*
info
=
(
scc_info
*
)
get_irg_link
(
irg
);
assert
(
info
&&
"missing call to init_scc()"
);
assert
(
info
!=
NULL
);
info
->
in_stack
=
1
;
}
static
inline
void
mark_irg_not_in_stack
(
ir_graph
*
irg
)
{
scc_info
*
info
=
(
scc_info
*
)
get_irg_link
(
irg
);
assert
(
info
&&
"missing call to init_scc()"
);
assert
(
info
!=
NULL
);
info
->
in_stack
=
0
;
}
static
inline
int
irg_is_in_stack
(
const
ir_graph
*
irg
)
{
scc_info
*
info
=
(
scc_info
*
)
get_irg_link
(
irg
);
assert
(
info
&&
"missing call to init_scc()"
);
assert
(
info
!=
NULL
);
return
info
->
in_stack
;
}
static
inline
void
set_irg_uplink
(
ir_graph
*
irg
,
size_t
uplink
)
{
scc_info
*
info
=
(
scc_info
*
)
get_irg_link
(
irg
);
assert
(
info
&&
"missing call to init_scc()"
);
assert
(
info
!=
NULL
);
info
->
uplink
=
uplink
;
}
static
inline
size_t
get_irg_uplink
(
const
ir_graph
*
irg
)
{
const
scc_info
*
info
=
(
scc_info
*
)
get_irg_link
(
irg
);
assert
(
info
&&
"missing call to init_scc()"
);
assert
(
info
!=
NULL
);
return
info
->
uplink
;
}
static
inline
void
set_irg_dfn
(
ir_graph
*
irg
,
size_t
dfn
)
{
scc_info
*
info
=
(
scc_info
*
)
get_irg_link
(
irg
);
assert
(
info
&&
"missing call to init_scc()"
);
assert
(
info
!=
NULL
);
info
->
dfn
=
dfn
;
}
static
inline
size_t
get_irg_dfn
(
const
ir_graph
*
irg
)
{
const
scc_info
*
info
=
(
scc_info
*
)
get_irg_link
(
irg
);
assert
(
info
&&
"missing call to init_scc()"
);
assert
(
info
!=
NULL
);
return
info
->
dfn
;
}
...
...
@@ -474,7 +449,7 @@ static inline void push(ir_graph *irg)
size_t
nlen
=
ARR_LEN
(
stack
)
*
2
;
ARR_RESIZE
(
ir_graph
*
,
stack
,
nlen
);
}
stack
[
tos
++
]
=
irg
;
stack
[
tos
++
]
=
irg
;
mark_irg_in_stack
(
irg
);
}
...
...
@@ -483,10 +458,8 @@ static inline void push(ir_graph *irg)