Commit 60ade3bd authored by Matthias Braun's avatar Matthias Braun
Browse files

rework add_irn_dep, add delete_irn_dep

- Setting dep edges to NULL is illegal now
- add_irn_dep is simpler but does not check for duplicates anymore
parent 31d36dd3
......@@ -89,16 +89,12 @@ FIRM_API ir_node *get_irn_n(const ir_node *node, int n);
FIRM_API void set_irn_in(ir_node *node, int arity, ir_node *in[]);
/**
* Add a artificial dependency to the node.
* The dependency is only inserted if it is not there already.
* This is only allowed in phase_backend!
* Add an artificial dependency to the node.
*
* @param node The node.
* @param dep The dependency target.
*
* @return The index in the array (get_irn_dep with that index returns @p dep).
*/
FIRM_API int add_irn_dep(ir_node *node, ir_node *dep);
FIRM_API void add_irn_dep(ir_node *node, ir_node *dep);
/**
* Copy all dependencies from a node to another.
......@@ -132,6 +128,15 @@ FIRM_API ir_node *get_irn_dep(const ir_node *node, int pos);
*/
FIRM_API void set_irn_dep(ir_node *node, int pos, ir_node *dep);
/**
* Deletes the entry of the dependency array, that points to dep. Does nothing
* if no dependency exists.
*
* @param node the node to delete the dependency at
* @param dep the target of the dependency to delete
*/
FIRM_API void delete_irn_dep(ir_node *node, ir_node *dep);
/** Replaces the n-th predecessor of a node with a new one. */
FIRM_API void set_irn_n(ir_node *node, int n, ir_node *in);
/**
......
......@@ -309,39 +309,32 @@ void (set_irn_dep)(ir_node *node, int pos, ir_node *dep)
set_irn_dep_(node, pos, dep);
}
int add_irn_dep(ir_node *node, ir_node *dep)
void add_irn_dep(ir_node *node, ir_node *dep)
{
int res = 0;
/* DEP edges are only allowed in backend phase */
assert(get_irg_phase_state(get_irn_irg(node)) == phase_backend);
assert(dep != NULL);
if (node->deps == NULL) {
node->deps = NEW_ARR_F(ir_node *, 1);
node->deps[0] = dep;
} else {
int i, n;
int first_zero = -1;
for (i = 0, n = ARR_LEN(node->deps); i < n; ++i) {
if (node->deps[i] == NULL)
first_zero = i;
node->deps = NEW_ARR_F(ir_node *, 0);
}
ARR_APP1(ir_node*, node->deps, dep);
edges_notify_edge_kind(node, ARR_LEN(node->deps)-1, dep, NULL, EDGE_KIND_DEP, get_irn_irg(node));
}
if (node->deps[i] == dep)
return i;
}
void delete_irn_dep(ir_node *node, ir_node *dep)
{
size_t i;
size_t n_deps;
if (node->deps == NULL)
return;
if (first_zero >= 0) {
node->deps[first_zero] = dep;
res = first_zero;
} else {
ARR_APP1(ir_node *, node->deps, dep);
res = n;
n_deps = ARR_LEN(node->deps);
for (i = 0; i < n_deps; ++i) {
if (node->deps[i] == dep) {
set_irn_dep(node, i, node->deps[n_deps-1]);
edges_notify_edge(node, i, NULL, dep, get_irn_irg(node));
ARR_SHRINKLEN(node->deps, n_deps-1);
break;
}
}
edges_notify_edge_kind(node, res, dep, NULL, EDGE_KIND_DEP, get_irn_irg(node));
return res;
}
void add_irn_deps(ir_node *tgt, ir_node *src)
......
......@@ -159,6 +159,7 @@ static inline void set_irn_dep_(ir_node *node, int pos, ir_node *dep)
assert(node->deps && "dependency array node yet allocated. use add_irn_dep()");
assert(pos >= 0 && pos < (int)ARR_LEN(node->deps) && "dependency index out of range");
assert(dep != NULL);
old = node->deps[pos];
node->deps[pos] = dep;
edges_notify_edge_kind(node, pos, dep, old, EDGE_KIND_DEP, get_irn_irg(node));
......
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