- /*
- * If the target is NULL, the edge shall be deleted.
- */
- if (tgt == NULL) {
- /* search the edge in the set. */
- ir_edge_t *edge = ir_edgeset_find(edges, &templ);
-
- /* mark the edge invalid if it was found */
- if (edge) {
- msg = "deleting";
- list_del(&edge->list);
- ir_edgeset_remove(edges, edge);
- list_add(&edge->list, &info->free_edges);
- edge->invalid = 1;
- edge->pos = -2;
- edge->src = NULL;
- edge_change_cnt(old_tgt, kind, -1);
- } else {
- /* If the edge was not found issue a warning on the debug stream */
- msg = "edge to delete not found!\n";
- }
- } else {
- /*
- * The target is not NULL and the old target differs
- * from the new target, the edge shall be moved (if the
- * old target was != NULL) or added (if the old target was
- * NULL).
- */
- struct list_head *head = &get_irn_edge_info(tgt, kind)->outs_head;
-
- assert(head->next && head->prev &&
- "target list head must have been initialized");
-
- /* If the old target is not null, the edge is moved. */
- if (old_tgt) {
- ir_edge_t *edge = ir_edgeset_find(edges, &templ);
- assert(edge && "edge to redirect not found!");
- assert(! edge->invalid && "Invalid edge encountered");
-
- msg = "redirecting";
-
- list_move(&edge->list, head);
- edge_change_cnt(old_tgt, kind, -1);
- } else {
- /* The old target was NULL, thus, the edge is newly created. */
- ir_edge_t *new_edge;
- ir_edge_t *edge;
-
- if (list_empty(&info->free_edges)) {
- edge = OALLOC(&info->edges_obst, ir_edge_t);
- } else {
- edge = list_entry(info->free_edges.next, ir_edge_t, list);
- list_del(&edge->list);
- }
-
- edge->src = src;
- edge->pos = pos;
- edge->invalid = 0;
- edge->present = 0;
- edge->kind = kind;
- edge->list.next = NULL;
- edge->list.prev = NULL;
-
- new_edge = ir_edgeset_insert(edges, edge);
- if (new_edge != edge) {
- panic("new edge exists already");
- }