Commit 1a748f0b authored by Michael Beck's avatar Michael Beck
Browse files

reformateed and some comments added

[r7966]
parent 78c21f85
......@@ -11,17 +11,17 @@
typedef unsigned int uint;
static pmap* cdep_map;
static pmap *cdep_map;
cdep* find_cdep(const ir_node* block)
cdep *find_cdep(const ir_node *block)
{
return pmap_get(cdep_map, (void*)block);
return pmap_get(cdep_map, (void *)block);
}
void exchange_cdep(ir_node* old, const ir_node* new)
void exchange_cdep(ir_node *old, const ir_node *nw)
{
cdep* cdep = find_cdep(new);
cdep *cdep = find_cdep(nw);
pmap_insert(cdep_map, old, cdep);
}
......@@ -29,73 +29,80 @@ void exchange_cdep(ir_node* old, const ir_node* new)
static void add_cdep(ir_node* node, ir_node* dep_on)
{
cdep* dep = find_cdep(node);
cdep *dep = find_cdep(node);
#if 0
ir_fprintf(stderr, "Adding cdep of %+F on %+F\n", node, dep_on);
#endif
if (dep == NULL) {
cdep* newdep = xmalloc(sizeof(*newdep));
newdep->node = dep_on;
newdep->next = NULL;
pmap_insert(cdep_map, node, newdep);
} else {
cdep* newdep;
for (;;) {
if (dep->node == dep_on) return;
if (dep->next == NULL) break;
dep = dep->next;
}
newdep = xmalloc(sizeof(*newdep));
newdep->node = dep_on;
newdep->next = NULL;
dep->next = newdep;
}
if (dep == NULL) {
cdep *newdep = xmalloc(sizeof(*newdep));
newdep->node = dep_on;
newdep->next = NULL;
pmap_insert(cdep_map, node, newdep);
} else {
cdep *newdep;
for (;;) {
if (dep->node == dep_on) return;
if (dep->next == NULL) break;
dep = dep->next;
}
newdep = xmalloc(sizeof(*newdep));
newdep->node = dep_on;
newdep->next = NULL;
dep->next = newdep;
}
}
typedef struct cdep_env {
ir_node *start_block;
ir_node *end_block;
} cdep_env;
static void cdep_pre(ir_node* node, void* env)
/**
* Pre-block-walker: calculate the control dependence
*/
static void cdep_pre(ir_node *node, void *ctx)
{
uint n;
uint i;
/* special case:
* start and end block have no control depency
*/
if (node == get_irg_start_block(get_irn_irg(node))) return;
if (node == get_irg_end_block(get_irn_irg(node))) return;
n = get_Block_n_cfgpreds(node);
for (i = 0; i < n; i++) {
ir_node* pred = get_Block_cfgpred_block(node, i);
ir_node* pdom;
ir_node* dependee;
if (is_Bad(pred)) continue;
pdom = get_Block_ipostdom(pred);
for (dependee = node; dependee != pdom; dependee = get_Block_ipostdom(dependee)) {
assert(!is_Bad(pdom));
add_cdep(dependee, pred);
}
}
cdep_env *env = ctx;
uint n;
uint i;
/* special case:
* start and end block have no control dependency
*/
if (node == env->start_block) return;
if (node == env->end_block) return;
n = get_Block_n_cfgpreds(node);
for (i = 0; i < n; i++) {
ir_node *pred = get_Block_cfgpred_block(node, i);
ir_node *pdom;
ir_node *dependee;
if (is_Bad(pred)) continue;
pdom = get_Block_ipostdom(pred);
for (dependee = node; dependee != pdom; dependee = get_Block_ipostdom(dependee)) {
assert(!is_Bad(pdom));
add_cdep(dependee, pred);
}
}
}
#include "irdump.h"
static int cdep_edge_hook(FILE* F, ir_node* block)
/**
* A block edge hook: add all cdep edges of block.
*/
static int cdep_edge_hook(FILE *F, ir_node *block)
{
#if 0
ir_node* pdom;
#endif
cdep* cd;
cdep *cd;
#if 0
pdom = get_Block_ipostdom(block);
ir_node *pdom = get_Block_ipostdom(block);
if (pdom != NULL) {
fprintf(
F,
......@@ -105,47 +112,57 @@ static int cdep_edge_hook(FILE* F, ir_node* block)
}
#endif
for (cd = find_cdep(block); cd != NULL; cd = cd->next) {
fprintf(
F,
for (cd = find_cdep(block); cd != NULL; cd = cd->next) {
fprintf(
F,
"edge:{sourcename:\"n%ld\" targetname:\"n%ld\" "
"linestyle:dashed color:gold}\n",
get_irn_node_nr(block), get_irn_node_nr(cd->node)
);
}
}
return 0;
}
void compute_cdep(ir_graph* irg)
void compute_cdep(ir_graph *irg)
{
cdep_map = pmap_create();
ir_node *start_block, *rem;
cdep_env env;
cdep_map = pmap_create();
compute_postdoms(irg);
set_Block_ipostdom(get_irg_start_block(irg), get_irg_end_block(irg));
assure_postdoms(irg);
irg_block_walk_graph(irg, cdep_pre, NULL, NULL);
/* we must temporary change the post dominator relation */
start_block = get_irg_start_block(irg);
rem = get_Block_ipostdom(start_block);
set_Block_ipostdom(start_block, get_irg_end_block(irg));
#if 1
env.start_block = get_irg_start_block(irg);
env.end_block = get_irg_end_block(irg);
irg_block_walk_graph(irg, cdep_pre, NULL, &env);
#if 0
set_dump_block_edge_hook(cdep_edge_hook);
dump_ir_block_graph(irg, "_cdep");
dump_ir_block_graph(irg, "_cdep");
set_dump_block_edge_hook(NULL);
#endif
free_postdom(irg);
/* restore the post dominator relation */
set_Block_ipostdom(start_block, rem);
}
void free_cdep(ir_graph* irg)
void free_cdep(ir_graph *irg)
{
// TODO atm leaking more memory than a small memory leaking animal
// TODO atm leaking more memory than a small memory leaking animal
}
int is_cdep_on(const ir_node* dependee, const ir_node* candidate)
int is_cdep_on(const ir_node *dependee, const ir_node *candidate)
{
const cdep* dep;
const cdep *dep;
for (dep = find_cdep(dependee); dep != NULL; dep = dep->next) {
if (dep->node == candidate) return 1;
......@@ -154,9 +171,9 @@ int is_cdep_on(const ir_node* dependee, const ir_node* candidate)
}
int is_iterated_cdep_on(ir_node* dependee, ir_node* candidate)
int is_iterated_cdep_on(ir_node *dependee, ir_node *candidate)
{
const cdep* dep;
const cdep *dep;
while ((dep = find_cdep(dependee)) != NULL) {
if (dep->next != NULL) return 0;
......@@ -167,17 +184,17 @@ int is_iterated_cdep_on(ir_node* dependee, ir_node* candidate)
}
ir_node* get_unique_cdep(const ir_node* block)
ir_node *get_unique_cdep(const ir_node *block)
{
cdep* cdep = find_cdep(block);
cdep *cdep = find_cdep(block);
return cdep != NULL && cdep->next == NULL ? cdep->node : NULL;
}
int has_multiple_cdep(const ir_node* block)
int has_multiple_cdep(const ir_node *block)
{
cdep* cdep = find_cdep(block);
cdep *cdep = find_cdep(block);
return cdep != NULL && cdep->next != NULL;
}
#ifndef CDEP_H
#define CDEP_H
#include "irnode.h"
#include "firm_types.h"
typedef struct cdep cdep;
struct cdep {
ir_node* node;
cdep* next;
ir_node *node;
cdep *next;
};
void compute_cdep(ir_graph*);
void free_cdep(ir_graph*);
/** Compute the control dependence graph for a graph. */
void compute_cdep(ir_graph *irg);
void free_cdep(ir_graph *irg);
cdep* find_cdep(const ir_node* block);
cdep *find_cdep(const ir_node *block);
void exchange_cdep(ir_node* old, const ir_node* new);
void exchange_cdep(ir_node *old, const ir_node *nw);
int is_cdep_on(const ir_node* dependee, const ir_node* candidate);
int is_cdep_on(const ir_node *dependee, const ir_node *candidate);
int is_iterated_cdep_on(ir_node* dependee, ir_node* candidate);
int is_iterated_cdep_on(ir_node *dependee, ir_node *candidate);
ir_node* get_unique_cdep(const ir_node* block);
int has_multiple_cdep(const ir_node* block);
ir_node *get_unique_cdep(const ir_node *block);
int has_multiple_cdep(const ir_node *block);
#endif
#endif /* CDEP_H */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment