2 * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
6 * This file may be distributed and/or modified under the terms of the
7 * GNU General Public License version 2 as published by the Free Software
8 * Foundation and appearing in the file LICENSE.GPL included in the
9 * packaging of this file.
11 * Licensees holding valid libFirm Professional Edition licenses may use
12 * this file in accordance with the libFirm Commercial License.
13 * Agreement provided with the Software.
15 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * @author Sebastian Buchwald
29 #include "adt/array.h"
35 #include "pbqp_edge.h"
36 #include "pbqp_edge_t.h"
37 #include "pbqp_node.h"
38 #include "pbqp_node_t.h"
41 pbqp_edge_t *alloc_edge(pbqp_t *pbqp, int src_index, int tgt_index,
45 pbqp_edge_t *edge = OALLOC(&pbqp->obstack, pbqp_edge_t);
46 pbqp_node_t *src_node;
47 pbqp_node_t *tgt_node;
49 if (tgt_index < src_index) {
51 src_index = tgt_index;
57 src_node = get_node(pbqp, src_index);
59 tgt_node = get_node(pbqp, tgt_index);
62 edge->costs = pbqp_matrix_copy_and_transpose(pbqp, costs);
64 edge->costs = pbqp_matrix_copy(pbqp, costs);
68 * Connect edge with incident nodes. Since the edge is allocated, we know
69 * that it don't appear in the edge lists of the nodes.
71 ARR_APP1(pbqp_edge_t *, src_node->edges, edge);
73 ARR_APP1(pbqp_edge_t *, tgt_node->edges, edge);
75 edge->bucket_index = UINT_MAX;
80 void delete_edge(pbqp_edge_t *edge)
82 pbqp_node_t *src_node;
83 pbqp_node_t *tgt_node;
88 disconnect_edge(src_node, edge);
89 disconnect_edge(tgt_node, edge);
94 reorder_node_after_edge_deletion(src_node);
95 reorder_node_after_edge_deletion(tgt_node);
98 unsigned is_deleted(pbqp_edge_t *edge)
102 deleted = (edge->src == NULL) && (edge-> tgt == NULL);
107 pbqp_edge_t *pbqp_edge_deep_copy(pbqp_t *pbqp, pbqp_edge_t *edge,
108 pbqp_node_t *src_node, pbqp_node_t *tgt_node)
110 pbqp_edge_t *copy = OALLOC(&pbqp->obstack, pbqp_edge_t);
114 copy->costs = pbqp_matrix_copy(pbqp, edge->costs);
116 /* Connect edge with incident nodes. */
117 copy->src = src_node;
118 copy->tgt = tgt_node;
119 copy->bucket_index = UINT_MAX;