https://hal.archives-ouvertes.fr/hal-03445821
extk.c
/*
Copyright Universite de Versailles Saint-Quentin en Yvelines 2009
AUTHORS: Sebastien Briais, Sid Touati
This file is part of RS.
RS is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
RS is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with RS. If not, see
<http://www.gnu.org/licenses/>.
*/
#include "extk.h"
#include "util.h"
/** Build the order corresponding to the graph DAG associated with the
given killing function. Vertices are labelled by vertices of the
original DAG, while edges are unlabelled.
@param[in] ddg = acyclic DDG
@param[in] type = type
@param[in] pkg = potential killers graph
@param[in] killing_map = killing function
@return the order corresponding to the DAG associated with the
given killing function */
SCEDA_Graph *RS_ddag_extk_order(GDD_DAG *ddg, const char *type, SCEDA_Graph *pkg, SCEDA_HashMap *killing_map) {
SCEDA_Graph *g_extk = SCEDA_graph_create(NULL, NULL);
SCEDA_Graph *g = GDD_dag_get_ddg(ddg);
SCEDA_HashMap *g_to_g_extk = SCEDA_vertex_map_create(NULL);
// copy G vertices
{
SCEDA_VerticesIterator g_vertices;
SCEDA_vertices_iterator_init(g, &g_vertices);
while(SCEDA_vertices_iterator_has_next(&g_vertices)) {
SCEDA_Vertex *v = SCEDA_vertices_iterator_next(&g_vertices);
SCEDA_Vertex *v_extk = SCEDA_graph_add_vertex(g_extk, v);
SCEDA_hashmap_put(g_to_g_extk, v, v_extk, NULL);
}
SCEDA_vertices_iterator_cleanup(&g_vertices);
}
SCEDA_HashMap *g_to_pkg = SCEDA_vertex_map_create(NULL);
{
SCEDA_VerticesIterator pkg_vertices;
SCEDA_vertices_iterator_init(pkg, &pkg_vertices);
while(SCEDA_vertices_iterator_has_next(&pkg_vertices)) {
SCEDA_Vertex *v_pk = SCEDA_vertices_iterator_next(&pkg_vertices);
SCEDA_Vertex *v = SCEDA_vertex_get_data(SCEDA_Vertex *, v_pk);
SCEDA_hashmap_put(g_to_pkg, v, v_pk, NULL);
}
SCEDA_vertices_iterator_cleanup(&pkg_vertices);
}
// copy successor relation
{
SCEDA_VerticesIterator g_vertices;
SCEDA_vertices_iterator_init(g, &g_vertices);
while(SCEDA_vertices_iterator_has_next(&g_vertices)) {
SCEDA_Vertex *v = SCEDA_vertices_iterator_next(&g_vertices);
SCEDA_Vertex *v_extk = SCEDA_hashmap_get(g_to_g_extk, v);
SCEDA_VertexSuccIterator succ;
SCEDA_vertex_succ_iterator_init(v, &succ);
while(SCEDA_vertex_succ_iterator_has_next(&succ)) {
SCEDA_Vertex *w = SCEDA_vertex_succ_iterator_next(&succ);
SCEDA_Vertex *w_extk = SCEDA_hashmap_get(g_to_g_extk, w);
SCEDA_graph_add_edge(g_extk, v_extk, w_extk, NULL);
}
SCEDA_vertex_succ_iterator_cleanup(&succ);
}
SCEDA_vertices_iterator_cleanup(&g_vertices);
}
// add new edges
{
SCEDA_HashMapIterator killers;
SCEDA_hashmap_iterator_init(killing_map, &killers);
while(SCEDA_hashmap_iterator_has_next(&killers)) {
SCEDA_Vertex *u;
SCEDA_Vertex *ku = SCEDA_hashmap_iterator_next(&killers, &u);
//
SCEDA_Vertex *ku_extk = SCEDA_hashmap_get(g_to_g_extk, ku);
//
SCEDA_Vertex *u_pk = SCEDA_hashmap_get(g_to_pkg, u);
SCEDA_VertexSuccIterator pkillers;
SCEDA_vertex_succ_iterator_init(u_pk, &pkillers);
while(SCEDA_vertex_succ_iterator_has_next(&pkillers)) {
SCEDA_Vertex *v_pk = SCEDA_vertex_succ_iterator_next(&pkillers);
SCEDA_Vertex *v = SCEDA_vertex_get_data(SCEDA_Vertex *, v_pk);
if(v == ku) {
continue;
}
SCEDA_Vertex *v_extk = SCEDA_hashmap_get(g_to_g_extk, v);
if(!SCEDA_vertex_is_succ_of(ku_extk, v_extk)) {
SCEDA_graph_add_edge(g_extk, v_extk, ku_extk, NULL);
}
}
SCEDA_vertex_succ_iterator_cleanup(&pkillers);
}
SCEDA_hashmap_iterator_cleanup(&killers);
}
SCEDA_hashmap_delete(g_to_pkg);
SCEDA_hashmap_delete(g_to_g_extk);
return g_extk;
}