PIPS
graph.c File Reference
#include <stdio.h>
#include <strings.h>
#include "linear.h"
#include "genC.h"
#include "ri.h"
#include "text.h"
#include "text-util.h"
#include "database.h"
#include "misc.h"
#include "ri-util.h"
#include "resources.h"
#include "pipsdbm.h"
#include "control.h"
+ Include dependency graph for graph.c:

Go to the source code of this file.

Macros

#define bool_undefined   ((bool) (-15))
 TRAVELLING on the control graph. More...
 
#define bool_undefined_p(b)   ((b)==bool_undefined)
 

Functions

void clean_ctrl_graph ()
 global mapping from statements to their control in the full control graph More...
 
static void add_arrow_in_ctrl_graph (statement s1, statement s2)
 add (s1) --> (s2), that is s2 as successor of s1 and s1 as predecessor of s2. More...
 
static void add_arrows_in_ctrl_graph (statement s, list l)
 
list control_list_to_statement_list (list lc)
 of statement More...
 
static void statement_arrows (statement s, list next)
 
static void stmt_rewrite (statement s)
 
void build_full_ctrl_graph (statement s)
 
void full_control_graph (string name)
 FULL CONTROL GRAPH for module NAME. More...
 
static void push_if_necessary (statement s)
 
static void push (list l)
 it is pushed in reverse order to preserve the depth first view. More...
 
static void push_successors (statement s)
 
void init_ctrl_graph_travel (statement s, bool(*decision)(statement))
 
bool next_ctrl_graph_travel (statement *ps)
 
void close_ctrl_graph_travel (void)
 

Variables

static bool(* travel_decision )(statement)
 Static data for the travel. More...
 

Macro Definition Documentation

◆ bool_undefined

#define bool_undefined   ((bool) (-15))

TRAVELLING on the control graph.

init, next, close functions.

  • the init function is given a starting point (statement) s and a decision function decision. The function should say whether to go on with the successors of its arguments.
  • the next function gives the next visited statement.
  • the close function frees the static data.

Definition at line 279 of file graph.c.

◆ bool_undefined_p

#define bool_undefined_p (   b)    ((b)==bool_undefined)

Definition at line 280 of file graph.c.

Function Documentation

◆ add_arrow_in_ctrl_graph()

static void add_arrow_in_ctrl_graph ( statement  s1,
statement  s2 
)
static

add (s1) --> (s2), that is s2 as successor of s1 and s1 as predecessor of s2.

last added put in first place. this property is used for a depth first enumeration.

Definition at line 78 of file graph.c.

79 {
80  control
81  c1 = load_ctrl_graph(s1),
82  c2 = load_ctrl_graph(s2);
83 
84  pips_debug(7, "(%td,%td:%td) -> (%td,%td;%td)\n",
90  statement_number(s2));
91 
94 }
control load_ctrl_graph(statement)
list gen_once(const void *vo, list l)
Prepend an item to a list only if it is not already in the list.
Definition: list.c:722
#define pips_debug
these macros use the GNU extensions that allow variadic macros, including with an empty list.
Definition: misc-local.h:145
#define ORDERING_NUMBER(o)
#define ORDERING_STATEMENT(o)
#define control_predecessors(x)
Definition: ri.h:943
#define statement_ordering(x)
Definition: ri.h:2454
#define control_successors(x)
Definition: ri.h:945
#define statement_number(x)
Definition: ri.h:2452
s1
Definition: set.c:247

References control_predecessors, control_successors, gen_once(), load_ctrl_graph(), ORDERING_NUMBER, ORDERING_STATEMENT, pips_debug, s1, statement_number, and statement_ordering.

Referenced by add_arrows_in_ctrl_graph(), and statement_arrows().

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

◆ add_arrows_in_ctrl_graph()

static void add_arrows_in_ctrl_graph ( statement  s,
list  l 
)
static
Parameters
lstatement

Definition at line 96 of file graph.c.

97 {
98  for(; !ENDP(l); l=CDR(l))
100 }
static void add_arrow_in_ctrl_graph(statement s1, statement s2)
add (s1) --> (s2), that is s2 as successor of s1 and s1 as predecessor of s2.
Definition: graph.c:78
#define ENDP(l)
Test if a list is empty.
Definition: newgen_list.h:66
#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 STATEMENT(x)
STATEMENT.
Definition: ri.h:2413

References add_arrow_in_ctrl_graph(), CAR, CDR, ENDP, and STATEMENT.

Referenced by statement_arrows().

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

◆ build_full_ctrl_graph()

void build_full_ctrl_graph ( statement  s)

first pass to initialize the ctrl_graph controls

STATEMENT

second pass to link the statements

Definition at line 238 of file graph.c.

239 {
240  pips_debug(3, "statement (%td,%td:%td)\n",
243  statement_number(s));
244 
245  /* first pass to initialize the ctrl_graph controls
246  */
247  init_ctrl_graph();
249  statement_domain, gen_true, stmt_rewrite, /* STATEMENT */
250  NULL);
251 
252  /* second pass to link the statements
253  */
254  statement_arrows(s, NIL);
255 }
static void stmt_rewrite(statement s)
Definition: graph.c:232
static void statement_arrows(statement s, list next)
Definition: graph.c:110
void init_ctrl_graph(void)
void gen_multi_recurse(void *o,...)
Multi recursion visitor function.
Definition: genClib.c:3428
bool gen_true(__attribute__((unused)) gen_chunk *unused)
Return true and ignore the argument.
Definition: genClib.c:2780
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
#define statement_domain
newgen_sizeofexpression_domain_defined
Definition: ri.h:362

References gen_multi_recurse(), gen_true(), init_ctrl_graph(), NIL, ORDERING_NUMBER, ORDERING_STATEMENT, pips_debug, statement_arrows(), statement_domain, statement_number, statement_ordering, and stmt_rewrite().

Referenced by full_control_graph(), and handle_hpf_directives().

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

◆ clean_ctrl_graph()

void clean_ctrl_graph ( void  )

global mapping from statements to their control in the full control graph

the crtl_graph is freed by hand, because the default behavior is not convenient for my purpose. I would have needed a persistant statement in the control, but it is not desired in pips.

now it can be freed safely

Definition at line 53 of file graph.c.

54 {
55  CONTROLMAP_MAP(s, c,
56  {
57  pips_debug(7, "statement (%td,%td)\n",
60 
66  },
67  get_ctrl_graph());
68 
69  close_ctrl_graph(); /* now it can be freed safely */
70 }
controlmap get_ctrl_graph(void)
void close_ctrl_graph(void)
void gen_free_list(list l)
free the spine of the list
Definition: list.c:327
#define CONTROLMAP_MAP(k, v, c, f)
Definition: ri.h:900
#define control_statement(x)
Definition: ri.h:941
#define statement_undefined
Definition: ri.h:2419

References close_ctrl_graph(), control_predecessors, control_statement, control_successors, CONTROLMAP_MAP, gen_free_list(), get_ctrl_graph(), NIL, ORDERING_NUMBER, ORDERING_STATEMENT, pips_debug, statement_ordering, and statement_undefined.

Referenced by handle_hpf_directives().

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

◆ close_ctrl_graph_travel()

void close_ctrl_graph_travel ( void  )

Definition at line 340 of file graph.c.

341 {
342  free_to_see_stack();
343  free_stacked_map();
344 }

Referenced by handle_independent_directive(), handle_reduction_directive(), and propagate_synonym().

+ Here is the caller graph for this function:

◆ control_list_to_statement_list()

list control_list_to_statement_list ( list  lc)

of statement

of statements

Parameters
lccontrol

Definition at line 103 of file graph.c.

104 {
105  list /* of statements */ ls = NIL;
106  MAP(CONTROL, c, ls = CONS(STATEMENT, control_statement(c), ls), lc);
107  return ls;
108 }
#define CONS(_t_, _i_, _l_)
List element cell constructor (insert an element at the beginning of a list)
Definition: newgen_list.h:150
#define MAP(_map_CASTER, _map_item, _map_code, _map_list)
Apply/map an instruction block on all the elements of a list (old fashioned)
Definition: newgen_list.h:226
#define CONTROL(x)
CONTROL.
Definition: ri.h:910
The structure used to build lists in NewGen.
Definition: newgen_list.h:41

References CONS, CONTROL, control_statement, MAP, NIL, and STATEMENT.

Referenced by compute_cumulated_reductions(), and statement_arrows().

+ Here is the caller graph for this function:

◆ full_control_graph()

void full_control_graph ( string  name)

FULL CONTROL GRAPH for module NAME.

should put something in the db if made as a pass

Parameters
nameame

Definition at line 259 of file graph.c.

260 {
261  statement s = (statement) db_get_memory_resource(DBR_CODE, name, true);
263 
264  /* should put something in the db if made as a pass
265  */
266 }
void build_full_ctrl_graph(statement s)
Definition: graph.c:238
struct _newgen_struct_statement_ * statement
Definition: cloning.h:21
string db_get_memory_resource(const char *rname, const char *oname, bool pure)
Return the pointer to the resource, whatever it is.
Definition: database.c:755

References build_full_ctrl_graph(), and db_get_memory_resource().

+ Here is the call graph for this function:

◆ init_ctrl_graph_travel()

void init_ctrl_graph_travel ( statement  s,
bool(*)(statement decision 
)

initializations

no loop back

Definition at line 315 of file graph.c.

316 {
317  make_to_see_stack(); /* initializations */
318  make_stacked_map();
319  travel_decision = decision;
320 
321  store_statement_stacked(s, true); /* no loop back */
322  push_successors(s);
323 }
static void push_successors(statement s)
Definition: graph.c:310
static bool(* travel_decision)(statement)
Static data for the travel.
Definition: graph.c:290

References push_successors(), and travel_decision.

Referenced by handle_independent_directive(), handle_reduction_directive(), and propagate_synonym().

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

◆ next_ctrl_graph_travel()

bool next_ctrl_graph_travel ( statement ps)
Parameters
pss

Definition at line 325 of file graph.c.

326 {
327  while (!to_see_empty_p())
328  {
329  *ps = to_see_pop();
330  if ((*travel_decision)(*ps))
331  {
332  push_successors(*ps);
333  return true;
334  }
335  }
336 
337  return false;
338 }

References push_successors(), and travel_decision.

Referenced by handle_independent_directive(), handle_reduction_directive(), and propagate_synonym().

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

◆ push()

static void push ( list  l)
static

it is pushed in reverse order to preserve the depth first view.

Parameters
lcontrol

Definition at line 303 of file graph.c.

304 {
305  if (!ENDP(l))
306  push(CDR(l)),
308 }
static void push_if_necessary(statement s)
Definition: graph.c:292
static void push(list l)
it is pushed in reverse order to preserve the depth first view.
Definition: graph.c:303

References CAR, CDR, CONTROL, control_statement, ENDP, and push_if_necessary().

Referenced by push_successors().

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

◆ push_if_necessary()

static void push_if_necessary ( statement  s)
static

Definition at line 292 of file graph.c.

293 {
294  if (load_statement_stacked(s)!=true)
295  {
296  to_see_push(s);
297  store_statement_stacked(s, true);
298  }
299 }

Referenced by push().

+ Here is the caller graph for this function:

◆ push_successors()

static void push_successors ( statement  s)
static

Definition at line 310 of file graph.c.

311 {
313 }

References control_successors, load_ctrl_graph(), and push().

Referenced by init_ctrl_graph_travel(), and next_ctrl_graph_travel().

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

◆ statement_arrows()

static void statement_arrows ( statement  s,
list  next 
)
static

of statements

else

true is before false

of statements

no iteration

some iterations, first

of statements

hmmm... I'm not too confident in this loop. ??? what should be done with next? ??? should I trust the graph? I hope I can.

Parameters
nextstatement

Definition at line 110 of file graph.c.

111 {
113  tag t = instruction_tag(i);
114 
115  switch(t)
116  {
118  {
119  statement current, succ;
120  list /* of statements */
121  l = instruction_block(i),
122  just_next;
123 
124  if (ENDP(l))
125  {
126  add_arrows_in_ctrl_graph(s, next);
127  return;
128  }
129  /* else
130  */
132 
133  for(current = STATEMENT(CAR(l)),
134  l = CDR(l),
135  succ = ENDP(l) ? statement_undefined : STATEMENT(CAR(l)),
136  just_next = CONS(STATEMENT, succ, NIL);
137  !ENDP(l);
138  current = succ,
139  l = CDR(l),
140  succ = ENDP(l) ? statement_undefined : STATEMENT(CAR(l)),
141  STATEMENT_(CAR(just_next)) = succ)
142  {
143  statement_arrows(current, just_next);
144  }
145 
146  gen_free_list(just_next), just_next=NIL;
147 
148  statement_arrows(current, next);
149  break;
150  }
151  case is_instruction_test:
152  {
153  test
154  x = instruction_test(i);
155  statement
156  strue = test_true(x),
157  sfalse = test_false(x);
158 
159  add_arrow_in_ctrl_graph(s, sfalse),
160  statement_arrows(sfalse, next);
161 
162  add_arrow_in_ctrl_graph(s, strue), /* true is before false */
163  statement_arrows(strue, next);
164 
165  break;
166  }
168  case is_instruction_loop:
169  {
170  statement b;
171  list /* of statements */ just_next =
172  gen_nconc(gen_copy_seq(next), CONS(STATEMENT, s, NIL));
173 
174  if(instruction_loop_p(i)) {
175  loop l = instruction_loop(i);
176  b = loop_body(l);
177  }
178  else {
180  b = whileloop_body(l);
181  }
182 
183  add_arrows_in_ctrl_graph(s, next); /* no iteration */
184  add_arrow_in_ctrl_graph(s, b); /* some iterations, first */
185 
186  statement_arrows(b, just_next);
187 
188  gen_free_list(just_next), just_next=NIL;
189 
190  break;
191  }
192  case is_instruction_call:
193  add_arrows_in_ctrl_graph(s, next);
194  break;
196  {
198  list /* of statements */
199  blocks = NIL,
200  lstat = NIL;
201  statement x;
203 
205 
206  /* hmmm... I'm not too confident in this loop.
207  * ??? what should be done with next?
208  * ??? should I trust the graph? I hope I can.
209  */
210  CONTROL_MAP(c,
211  {
212  x = control_statement(c);
214  (control_successors(c));
215 
216  statement_arrows(x, lstat);
217  gen_free_list(lstat);
218  },
219  c_in,
220  blocks);
221 
223 
224  break;
225  }
226  case is_instruction_goto:
227  default:
228  pips_internal_error("unexpected instruction tag (%d)", t);
229  }
230 }
list control_list_to_statement_list(list lc)
of statement
Definition: graph.c:103
static void add_arrows_in_ctrl_graph(statement s, list l)
Definition: graph.c:96
FILE * c_in
Definition: c_syntax.h:291
static list blocks
lisp of loops
#define CONTROL_MAP(ctl, code, c, list)
Macro to walk through all the controls reachable from a given control node of an unstructured.
list gen_copy_seq(list l)
Copy a list structure.
Definition: list.c:501
list gen_nconc(list cp1, list cp2)
physically concatenates CP1 and CP2 but do not duplicates the elements
Definition: list.c:344
#define pips_internal_error
Definition: misc-local.h:149
int tag
TAG.
Definition: newgen_types.h:92
#define unstructured_control
After the modification in Newgen: unstructured = entry:control x exit:control we have create a macro ...
#define is_instruction_block
soft block->sequence transition
#define instruction_block(i)
#define STATEMENT_(x)
Definition: ri.h:2416
#define loop_body(x)
Definition: ri.h:1644
#define instruction_loop_p(x)
Definition: ri.h:1518
#define instruction_loop(x)
Definition: ri.h:1520
#define test_false(x)
Definition: ri.h:2837
@ is_instruction_goto
Definition: ri.h:1473
@ is_instruction_unstructured
Definition: ri.h:1475
@ is_instruction_whileloop
Definition: ri.h:1472
@ is_instruction_test
Definition: ri.h:1470
@ is_instruction_call
Definition: ri.h:1474
@ is_instruction_loop
Definition: ri.h:1471
#define instruction_tag(x)
Definition: ri.h:1511
#define test_true(x)
Definition: ri.h:2835
#define instruction_whileloop(x)
Definition: ri.h:1523
#define whileloop_body(x)
Definition: ri.h:3162
#define statement_instruction(x)
Definition: ri.h:2458
#define instruction_test(x)
Definition: ri.h:1517
#define instruction_unstructured(x)
Definition: ri.h:1532
static char * x
Definition: split_file.c:159
static size_t current
Definition: string.c:115

References add_arrow_in_ctrl_graph(), add_arrows_in_ctrl_graph(), blocks, c_in, CAR, CDR, CONS, control_list_to_statement_list(), CONTROL_MAP, control_statement, control_successors, current, ENDP, gen_copy_seq(), gen_free_list(), gen_nconc(), instruction_block, instruction_loop, instruction_loop_p, instruction_tag, instruction_test, instruction_unstructured, instruction_whileloop, is_instruction_block, is_instruction_call, is_instruction_goto, is_instruction_loop, is_instruction_test, is_instruction_unstructured, is_instruction_whileloop, loop_body, NIL, pips_internal_error, STATEMENT, STATEMENT_, statement_instruction, statement_undefined, test_false, test_true, unstructured_control, whileloop_body, and x.

Referenced by build_full_ctrl_graph().

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

◆ stmt_rewrite()

static void stmt_rewrite ( statement  s)
static

Definition at line 232 of file graph.c.

233 {
234  if (!bound_ctrl_graph_p(s))
236 }
control make_control(statement a1, list a2, list a3)
Definition: ri.c:523
void store_ctrl_graph(statement, control)
bool bound_ctrl_graph_p(statement)

References bound_ctrl_graph_p(), make_control(), NIL, and store_ctrl_graph().

Referenced by build_full_ctrl_graph(), and drop_dummy_loops().

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

Variable Documentation

◆ travel_decision

bool(* travel_decision) (statement) ( statement  )
static

Static data for the travel.

  • the stack stores the statements to see
  • the mapping stores the already stacked statements
  • decision function...

Definition at line 290 of file graph.c.

Referenced by init_ctrl_graph_travel(), and next_ctrl_graph_travel().