PIPS
sccdfg.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include "genC.h"
#include "boolean.h"
#include "vecteur.h"
#include "contrainte.h"
#include "sc.h"
#include "ray_dte.h"
#include "sommet.h"
#include "sg.h"
#include "polyedre.h"
#include "union.h"
#include "matrix.h"
#include "ri.h"
#include "graph.h"
#include "dg.h"
#include "misc.h"
#include "ri-util.h"
#include "properties.h"
#include "constants.h"
#include "rice.h"
#include "ricedg.h"
#include "complexity_ri.h"
#include "database.h"
#include "parser_private.h"
#include "property.h"
#include "reduction.h"
#include "tiling.h"
#include "text.h"
#include "text-util.h"
#include "pipsdbm.h"
#include "paf_ri.h"
#include "paf-util.h"
#include "resources.h"
#include "scheduling.h"
+ Include dependency graph for sccdfg.c:

Go to the source code of this file.

Macros

#define MY_MIN(a, b)   ((a)>(b)?(b):(a))
 =================================================================== More...
 
#define NEW_MARK   1
 
#define OLD_MARK   2
 
#define DFG_MARK_OLD(v)
 
#define DFG_MARK_NEW(v)
 
#define DFG_MARKED_NEW_P(v)
 
#define DFG_VERTEX_ENCLOSING_SCC(v)
 

Typedefs

typedef dfg_arc_label arc_label
 lint More...
 
typedef dfg_vertex_label vertex_label
 

Functions

int dfg_is_in_stack (vertex v)
 ================================================================= More...
 
void dfg_low_link_compute (graph g, vertex v)
 ================================================================= More...
 
sccs dfg_find_sccs (graph g)
 ================================================================= More...
 
void fprint_sccs (FILE *fp, sccs obj)
 =========================================================================== More...
 
vertex dfg_in_vertex_list (list l, vertex v)
 ================================================================= More...
 
graph dfg_reverse_graph (graph g)
 ====================================================================== More...
 

Variables

char vcid_scheduling_sccdfg [] = "$Id: sccdfg.c 23065 2016-03-02 09:05:50Z coelho $"
 
static int Count
 A set of variables shared by the functions of this package. More...
 
static int StackPointer
 
static vertexStack
 
static sccs Components
 

Macro Definition Documentation

◆ DFG_MARK_NEW

#define DFG_MARK_NEW (   v)
Value:
#define sccflags_mark(x)
Definition: dg.h:275
#define vertex_vertex_label(x)
Definition: graph.h:152
#define dfg_vertex_label_sccflags(x)
Definition: paf_ri.h:417
#define NEW_MARK
Definition: sccdfg.c:103

Definition at line 108 of file sccdfg.c.

◆ DFG_MARK_OLD

#define DFG_MARK_OLD (   v)
Value:

Definition at line 105 of file sccdfg.c.

◆ DFG_MARKED_NEW_P

#define DFG_MARKED_NEW_P (   v)

◆ DFG_VERTEX_ENCLOSING_SCC

#define DFG_VERTEX_ENCLOSING_SCC (   v)
Value:

Definition at line 115 of file sccdfg.c.

◆ MY_MIN

#define MY_MIN (   a,
 
)    ((a)>(b)?(b):(a))

===================================================================

This collection of functions implements Tarjan's algorithm to find the strongly connected components of a directed graph.

this algorithm is presented in: Types de Donnees et Algorithmes Recherche, Tri, Algorithmes sur les Graphes Marie-Claude Gaudel, Michele Soria, Christine Froidevaux Collection Didactique

INRIA

A set of macros to mark a vertex as 'not visited' or 'visited' and to check if a node has already been visited.

Definition at line 101 of file sccdfg.c.

◆ NEW_MARK

#define NEW_MARK   1

Definition at line 103 of file sccdfg.c.

◆ OLD_MARK

#define OLD_MARK   2

Definition at line 104 of file sccdfg.c.

Typedef Documentation

◆ arc_label

lint

instantiation of the dependence graph

Definition at line 82 of file sccdfg.c.

◆ vertex_label

Definition at line 83 of file sccdfg.c.

Function Documentation

◆ dfg_find_sccs()

sccs dfg_find_sccs ( graph  g)

=================================================================

dfg_find_sccs is the interface function to compute the SCCs of a graph. It marks all nodes as 'not visited' and then apply the main function dfg_low_link_compute() on all vertices.

AC 93/10/19

Definition at line 223 of file sccdfg.c.

226 {
227  cons *vertices = graph_vertices(g), *pv;
228 
229  Count = 1;
230  StackPointer = 0;
231  Stack = (vertex *)malloc(sizeof(vertex) * gen_length(vertices));
233 
234  for (pv = vertices; pv != NIL; pv = CDR(pv))
235  {
236  vertex v = VERTEX(CAR(pv));
239  }
240 
241  MAPL(pv, {
242  vertex v = VERTEX(CAR(pv));
244  }, vertices);
245 
246  free(Stack);
247 
248  return(Components);
249 }
sccs make_sccs(list a)
Definition: dg.c:264
sccflags make_sccflags(scc a1, intptr_t a2, intptr_t a3, intptr_t a4)
Definition: dg.c:222
#define scc_undefined
Definition: dg.h:321
void * malloc(YYSIZE_T)
void free(void *)
#define graph_vertices(x)
Definition: graph.h:82
#define VERTEX(x)
VERTEX.
Definition: graph.h:122
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
size_t gen_length(const list l)
Definition: list.c:150
#define CAR(pcons)
Get the value of the first element of a list.
Definition: newgen_list.h:92
#define CDR(pcons)
Get the list less its first element.
Definition: newgen_list.h:111
#define MAPL(_map_list_cp, _code, _l)
Apply some code on the addresses of all the elements of a list.
Definition: newgen_list.h:203
struct _newgen_struct_dfg_vertex_label_ * dfg_vertex_label
Definition: paf_ri.h:112
static sccs Components
Definition: sccdfg.c:126
void dfg_low_link_compute(graph g, vertex v)
=================================================================
Definition: sccdfg.c:154
static vertex * Stack
Definition: sccdfg.c:125
#define DFG_MARKED_NEW_P(v)
Definition: sccdfg.c:111
static int Count
A set of variables shared by the functions of this package.
Definition: sccdfg.c:124
static int StackPointer
Definition: sccdfg.c:124
The structure used to build lists in NewGen.
Definition: newgen_list.h:41

References CAR, CDR, Components, Count, dfg_low_link_compute(), DFG_MARKED_NEW_P, dfg_vertex_label_sccflags, free(), gen_length(), graph_vertices, make_sccflags(), make_sccs(), malloc(), MAPL, NIL, scc_undefined, Stack, StackPointer, VERTEX, and vertex_vertex_label.

Referenced by scheduling().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dfg_in_vertex_list()

vertex dfg_in_vertex_list ( list  l,
vertex  v 
)

=================================================================

The following functions are used to build the reverse graph of a

dataflow graph

================================================================= vertex dfg_in_vertex_list((list) l, (vertex) v): Input : A list l of vertices. A vertex v of a dataflow graph. Returns vertex_undefined if v is not in list l. Returns v' that has the same statement_ordering than v.

AC 93/10/19

Definition at line 308 of file sccdfg.c.

312 {
313  vertex ver;
314  int p, i;
315 
318  for ( ; !ENDP(l); POP(l))
319  {
320  ver = VERTEX(CAR(l));
322  vertex_vertex_label(ver));
323  if (p == i) return(ver);
324  }
325 
326  return (vertex_undefined);
327 }
#define vertex_undefined
Definition: graph.h:128
#define ENDP(l)
Test if a list is empty.
Definition: newgen_list.h:66
#define POP(l)
Modify a list pointer to point on the next element of the list.
Definition: newgen_list.h:59
#define dfg_vertex_label_statement(x)
Definition: paf_ri.h:413

References CAR, dfg_vertex_label_statement, ENDP, POP, VERTEX, vertex_undefined, and vertex_vertex_label.

Referenced by dfg_reverse_graph().

+ Here is the caller graph for this function:

◆ dfg_is_in_stack()

int dfg_is_in_stack ( vertex  v)

=================================================================

int dfg_is_in_stack(v) : this function checks if vertex v is in the stack.

AC 93/10/18

Definition at line 135 of file sccdfg.c.

138 {
139  int i;
140 
141  for (i = 0; i < StackPointer; i++)
142  if (Stack[i] == v) return(true);
143 
144  return(false);
145 }

References Stack, and StackPointer.

Referenced by dfg_low_link_compute().

+ Here is the caller graph for this function:

◆ dfg_low_link_compute()

void dfg_low_link_compute ( graph  g,
vertex  v 
)

=================================================================

dfg_low_link_compute() is the main function. Its behavior is explained in the book mentionned ealier.

AC 93/10/18

Definition at line 154 of file sccdfg.c.

158 {
161 
162  DFG_MARK_OLD(v);
163 
164  sccflags_lowlink(fv) = Count;
165  sccflags_dfnumber(fv) = Count;
166 
167  Count ++;
168 
169  Stack[StackPointer++] = v;
170 
171  MAPL(ps, {
173  if (s != (vertex)NIL)
174  {
177  if (DFG_MARKED_NEW_P(s))
178  {
179  dfg_low_link_compute(g, s);
181  sccflags_lowlink(fs));
182  }
183  else
184  {
185  if ((sccflags_dfnumber(fs) < sccflags_dfnumber(fv)) &&\
186  dfg_is_in_stack(s))
188  sccflags_lowlink(fv));
189  }
190  }
191  }, vertex_successors(v));
192 
193  if (sccflags_lowlink(fv) == sccflags_dfnumber(fv))
194  {
195  scc ns = make_scc(NIL, 0);
196  vertex p;
197  sccflags fp;
198  cons *pv = NIL;
199 
200  do
201  {
202  p = Stack[--StackPointer];
205  sccflags_enclosing_scc(fp) = ns;
206  pv = gen_nconc(pv, CONS(VERTEX, p, NIL));
207  } while (v != p);
208 
209  scc_vertices(ns) = pv;
211  CONS(SCC, ns, NIL));
212  }
213 }
scc make_scc(list a1, intptr_t a2)
Definition: dg.c:306
#define SCC(x)
SCC.
Definition: dg.h:315
#define sccflags_lowlink(x)
Definition: dg.h:279
#define scc_vertices(x)
Definition: dg.h:345
#define sccflags_dfnumber(x)
Definition: dg.h:277
#define sccs_sccs(x)
Definition: dg.h:311
#define successor_vertex(x)
Definition: graph.h:118
#define vertex_successors(x)
Definition: graph.h:154
#define SUCCESSOR(x)
SUCCESSOR.
Definition: graph.h:86
#define CONS(_t_, _i_, _l_)
List element cell constructor (insert an element at the beginning of a list)
Definition: newgen_list.h:150
list gen_nconc(list cp1, list cp2)
physically concatenates CP1 and CP2 but do not duplicates the elements
Definition: list.c:344
#define DFG_MARK_OLD(v)
Definition: sccdfg.c:105
#define MY_MIN(a, b)
===================================================================
Definition: sccdfg.c:101
int dfg_is_in_stack(vertex v)
=================================================================
Definition: sccdfg.c:135

References CAR, Components, CONS, Count, dfg_is_in_stack(), DFG_MARK_OLD, DFG_MARKED_NEW_P, dfg_vertex_label_sccflags, gen_nconc(), make_scc(), MAPL, MY_MIN, NIL, SCC, scc_vertices, sccflags_dfnumber, sccflags_enclosing_scc, sccflags_lowlink, sccs_sccs, Stack, StackPointer, SUCCESSOR, successor_vertex, VERTEX, vertex_successors, and vertex_vertex_label.

Referenced by dfg_find_sccs().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dfg_reverse_graph()

graph dfg_reverse_graph ( graph  g)

======================================================================

graph dfg_reverse_graph((graph) g): This function is used to reverse Pips's graph in order to have all possible sources directly (Feautrier's dependance graph).

AC 93/10/19

Definition at line 339 of file sccdfg.c.

342 {
343  graph rev_graph = graph_undefined;
344  list vlist = NIL, li = NIL;
345  successor succ, succ2;
346  vertex v1, v2, v3, v4, v5;
347 
348  MAPL(ver_ptr,{
349  v1 = VERTEX(CAR(ver_ptr));
350  v5 = dfg_in_vertex_list(vlist, v1);
351  if (v5 == vertex_undefined)
352  {
354  vertex_vertex_label(v1)), NIL);
355  ADD_ELEMENT_TO_LIST(vlist, VERTEX, v2);
356  }
357  else v2 = v5;
358 
359  MAPL(succ_ptr, {
360  li = NIL;
361  succ = SUCCESSOR(CAR(succ_ptr));
362  v3 = successor_vertex(succ);
363  v5 = dfg_in_vertex_list(vlist, v3);
364  succ2 = make_successor((dfg_arc_label)\
365  successor_arc_label(succ), v2);
366  if (v5 == vertex_undefined)
367  {
368  ADD_ELEMENT_TO_LIST(li, SUCCESSOR, succ2);
370  vertex_vertex_label(v3)), li);
371  ADD_ELEMENT_TO_LIST(vlist, VERTEX, v4);
372  }
373  else
375  SUCCESSOR, succ2);
376  }, vertex_successors(v1));
377  }, graph_vertices(g));
378  rev_graph = make_graph(vlist);
379 
380  return(rev_graph);
381 }
graph make_graph(list a)
Definition: graph.c:56
successor make_successor(arc_label a1, vertex a2)
Definition: graph.c:98
vertex make_vertex(vertex_label a1, list a2)
Definition: graph.c:140
dfg_vertex_label copy_dfg_vertex_label(dfg_vertex_label p)
DFG_VERTEX_LABEL.
Definition: paf_ri.c:228
#define successor_arc_label(x)
Definition: graph.h:116
#define graph_undefined
Definition: graph.h:60
#define ADD_ELEMENT_TO_LIST(_list, _type, _element)
Definition: icfg-local.h:50
vertex dfg_in_vertex_list(list l, vertex v)
=================================================================
Definition: sccdfg.c:308

References ADD_ELEMENT_TO_LIST, CAR, copy_dfg_vertex_label(), dfg_in_vertex_list(), graph_undefined, graph_vertices, make_graph(), make_successor(), make_vertex(), MAPL, NIL, SUCCESSOR, successor_arc_label, successor_vertex, VERTEX, vertex_successors, vertex_undefined, and vertex_vertex_label.

Referenced by scheduling().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fprint_sccs()

void fprint_sccs ( FILE *  fp,
sccs  obj 
)

===========================================================================

void fprint_sccs(FILE *fp, sccs obj): prints in the file "fp" the list of strongly connected components "obj".

AC 93/10/20

Definition at line 258 of file sccdfg.c.

262 {
263  list nodes_l, su_l, df_l, scc_l;
264  int source_stmt, sink_stmt;
265  int iter = 0;
266 
267  fprintf(fp,"\n Graphe des Composantes Connexes :\n");
268  fprintf(fp,"==================================\n");
269 
270  for(scc_l = sccs_sccs(obj); scc_l != NIL; scc_l = CDR(scc_l))
271  {
272  scc scc_an = SCC(CAR(scc_l));
273  iter++;
274  fprintf(fp,"\ncomposante %d :\n",iter);
275  for(nodes_l=scc_vertices(scc_an);nodes_l !=NIL;nodes_l=CDR(nodes_l))
276  {
277  vertex crt_v = VERTEX(CAR(nodes_l));
278  source_stmt = vertex_int_stmt(crt_v);
279  fprintf(fp,"\tins_%d:\n", source_stmt);
280  su_l = vertex_successors(crt_v);
281  for( ; su_l != NIL; su_l = CDR(su_l))
282  {
283  successor su = SUCCESSOR(CAR(su_l));
286  for ( ; df_l != NIL; df_l = CDR(df_l))
287  fprint_dataflow(fp, sink_stmt, DATAFLOW(CAR(df_l)));
288  }
289  }
290  }
291 }
static int sink_stmt
Current source node.
Definition: adg_read_paf.c:160
static int source_stmt
Current sink statement.
Definition: adg_read_paf.c:161
int vertex_int_stmt(vertex)
===========================================================================
Definition: utils.c:866
void fprint_dataflow(FILE *, int, dataflow)
===========================================================================
Definition: print.c:229
#define DATAFLOW(x)
DATAFLOW.
Definition: paf_ri.h:308
#define dfg_arc_label_dataflows(x)
Definition: paf_ri.h:378
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...

References CAR, CDR, DATAFLOW, dfg_arc_label_dataflows, fprint_dataflow(), fprintf(), NIL, SCC, scc_vertices, sccs_sccs, sink_stmt, source_stmt, SUCCESSOR, successor_arc_label, successor_vertex, VERTEX, vertex_int_stmt(), and vertex_successors.

Referenced by scheduling().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ Components

sccs Components
static

◆ Count

int Count
static

A set of variables shared by the functions of this package.

The
stack contains the current SCC, i.e. the SCC currently being
built. Components is the result, i.e. a set of scc.

Definition at line 124 of file sccdfg.c.

Referenced by dfg_find_sccs(), and dfg_low_link_compute().

◆ Stack

vertex* Stack
static

Definition at line 125 of file sccdfg.c.

Referenced by dfg_find_sccs(), dfg_is_in_stack(), and dfg_low_link_compute().

◆ StackPointer

int StackPointer
static

Definition at line 124 of file sccdfg.c.

Referenced by dfg_find_sccs(), dfg_is_in_stack(), and dfg_low_link_compute().

◆ vcid_scheduling_sccdfg

char vcid_scheduling_sccdfg[] = "$Id: sccdfg.c 23065 2016-03-02 09:05:50Z coelho $"

Definition at line 29 of file sccdfg.c.