PIPS
phrase_tools.c File Reference
#include <stdio.h>
#include <ctype.h>
#include "genC.h"
#include "linear.h"
#include "ri.h"
#include "effects.h"
#include "resources.h"
#include "misc.h"
#include "ri-util.h"
#include "prettyprint.h"
#include "effects-util.h"
#include "text-util.h"
#include "dg.h"
#include "phrase_tools.h"
+ Include dependency graph for phrase_tools.c:

Go to the source code of this file.

Data Structures

struct  statement_checking_context
 
struct  sequence_searching_context
 

Functions

string statement_type_as_string (statement stat)
 DEBUG FUNCTION: return a string representing the type of the statement (SEQUENCE, CALL, etc...) More...
 
void debug_statement (const char *comments, statement stat, int debug_level)
 DEBUG FUNCTION: print debugging informations for a statement stat. More...
 
void debug_control (const char *comments, control a_control, int debug_level)
 DEBUG FUNCTION: print debugging informations for a control a_control. More...
 
void debug_unstructured (unstructured an_unstructured, int debug_level)
 DEBUG FUNCTION: print debugging informations for an unstructured an_unstructured. More...
 
void short_debug_unstructured (unstructured an_unstructured, int debug_level)
 DEBUG FUNCTION: print debugging informations for an unstructured an_unstructured (short version) More...
 
entity clone_variable_with_new_name (entity a_variable, const char *new_name, const char *module_name)
 This function build and return new variable from a variable a_variable, with name new_name. More...
 
entity make_variable_from_name_and_entity (entity cloned_variable, const char *base_name, statement stat, const char *module_name)
 Build and return new entity obtained by cloning variable cloned_variable, with a name obtained by the concatenation of base_name and the statement ordering of statement stat. More...
 
statement make_binary_call_statement (const char *operator_name, expression expression1, expression expression2, statement stat)
 Build and return new statement which is a binary call with the 2 expressions expression1 and expression2, with empty label, statement number and ordering of statement stat, and empty comments. More...
 
statement make_assignement_statement (entity a_variable, expression an_expression, statement stat)
 Build and return new statement which is a assignement of variable a_variable with expression an_expression, with empty label, statement number and ordering of statement stat, and empty comments. More...
 
int beautify_ordering (int an_ordering)
 Special function made for Ronan Keryell who likes a lot when a integer number is coded on 3 bits :-) More...
 
void clean_statement_from_tags (const char *comment_portion, statement stat)
 
static void check_if_statement_contains_comment (statement s, void *a_context)
 
list get_statements_with_comments_containing (const char *comment_portion, statement stat)
 
bool statement_is_contained_in_a_sequence_p (statement root_statement, statement searched_stat)
 
static void search_sequence_containing (statement s, void *a_context)
 
statement sequence_statement_containing (statement root_statement, statement searched_stat)
 
void replace_in_sequence_statement_with (statement old_stat, statement new_stat, statement root_stat)
 Replace statement old_stat by statement new_stat, asserting that this statement is contained in a sequence. More...
 
list references_for_regions (list l_regions)
 Return a list of references corresponding to a list of regions. More...
 

Function Documentation

◆ beautify_ordering()

int beautify_ordering ( int  an_ordering)

Special function made for Ronan Keryell who likes a lot when a integer number is coded on 3 bits :-)

Parameters
an_orderingn_ordering

Definition at line 407 of file phrase_tools.c.

408 {
409  int ordering_up = (an_ordering & 0xffff0000) >> 16;
410  int ordering_down = (an_ordering & 0x0000ffff);
411  return ordering_up + ((ordering_down-1) << 16);
412 }

Referenced by debug_unstructured(), entry_state_variable_value_for_unstructured(), and make_transition_statement().

+ Here is the caller graph for this function:

◆ check_if_statement_contains_comment()

static void check_if_statement_contains_comment ( statement  s,
void *  a_context 
)
static

ips_debug(5, "Searching comment: [%s] in [%s]\n", context->searched_string, comments);

Definition at line 459 of file phrase_tools.c.

460 {
462  string comments;
463 
465 
466  comments = strdup(statement_comments(s));
467 
468  /*pips_debug(5, "Searching comment: [%s] in [%s]\n",
469  context->searched_string, comments);*/
470 
471  if (strstr(comments,context->searched_string) != NULL) {
472  context->list_of_statements
473  = CONS(STATEMENT,s,context->list_of_statements);
474  }
475  }
476 }
#define CONS(_t_, _i_, _l_)
List element cell constructor (insert an element at the beginning of a list)
Definition: newgen_list.h:150
bool statement_with_empty_comment_p(statement)
Return true if the statement has an empty statement:
Definition: statement.c:126
#define statement_comments(x)
Definition: ri.h:2456
#define STATEMENT(x)
STATEMENT.
Definition: ri.h:2413
char * strdup()
Definition: delay.c:253

References CONS, STATEMENT, statement_comments, statement_with_empty_comment_p(), and strdup().

Referenced by get_statements_with_comments_containing().

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

◆ clean_statement_from_tags()

void clean_statement_from_tags ( const char *  comment_portion,
statement  stat 
)
Parameters
comment_portionomment_portion
stattat

Definition at line 414 of file phrase_tools.c.

416 {
417  string comments;
418  char* next_line;
419  string searched_string;
420 
421  if (!statement_with_empty_comment_p(stat)) {
422 
423  string new_comments = NULL;
424 
425  searched_string = strdup(comment_portion);
426  searched_string[strcspn(comment_portion, "%s")] = '\0';
427  comments = strdup(statement_comments(stat));
428  next_line = strtok (comments, "\n");
429  if (next_line != NULL) {
430  do {
431  if (strstr(next_line,searched_string) == NULL) {
432  if (new_comments != NULL) {
433  new_comments = strdup(concatenate(new_comments, next_line, "\n", NULL));
434  }
435  else {
436  new_comments = strdup(concatenate("", next_line, "\n", NULL));
437  }
438  }
439  next_line = strtok(NULL, "\n");
440  }
441  while (next_line != NULL);
442  }
443 
444  if (new_comments != NULL) {
445  statement_comments(stat) = new_comments;
446  }
447  else {
449  }
450  }
451 
452 }
string concatenate(const char *,...)
Return the concatenation of the given strings.
Definition: string.c:183
#define empty_comments
Empty comments (i.e.

References concatenate(), empty_comments, statement_comments, statement_with_empty_comment_p(), and strdup().

Referenced by remove_begin_tag(), and remove_end_tag().

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

◆ clone_variable_with_new_name()

entity clone_variable_with_new_name ( entity  a_variable,
const char *  new_name,
const char *  module_name 
)

This function build and return new variable from a variable a_variable, with name new_name.

If an entity called new_name already exists, return NULL. New variable is added to declarations

Assert that module represent a value code

This entity does not exist, we can safely create it

new_variable = copy_entity (a_variable); entity_name(new_variable) = strdup(concatenate(module_name, MODULE_SEP_STRING, new_name, NULL));

ew_variable = find_or_create_scalar_entity (strdup(concatenate(module_name, MODULE_SEP_STRING, new_name, NULL)),module_name, is_basic_int);

This entity already exist, we return null

Parameters
a_variable_variable
new_nameew_name
module_nameodule_name

Definition at line 269 of file phrase_tools.c.

272 {
273  entity module;
275 
277  /* Assert that module represent a value code */
278  pips_assert("it is a code", value_code_p(entity_initial(module)));
279 
282  new_name,
283  NULL),
285  {
286  /* This entity does not exist, we can safely create it */
287 
288  /* new_variable = copy_entity (a_variable);
289  entity_name(new_variable)
290  = strdup(concatenate(module_name,
291  MODULE_SEP_STRING,
292  new_name, NULL)); */
293 
296  new_name, NULL)),
300 
301  /*new_variable
302  = find_or_create_scalar_entity (strdup(concatenate(module_name,
303  MODULE_SEP_STRING,
304  new_name, NULL)),module_name,
305  is_basic_int);*/
306 
308  return new_variable;
309  }
310  else
311  {
312  /* This entity already exist, we return null */
313  return NULL;
314  }
315 }
type copy_type(type p)
TYPE.
Definition: ri.c:2655
value copy_value(value p)
VALUE.
Definition: ri.c:2784
storage copy_storage(storage p)
STORAGE.
Definition: ri.c:2228
static entity new_variable
entity to be replaced, the primary?
Definition: dynamic.c:860
const char * module_name(const char *s)
Return the module part of an entity name.
Definition: entity_names.c:296
static entity a_variable
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
#define MODULE_SEP_STRING
Definition: naming-local.h:30
void * gen_find_tabulated(const char *, int)
Definition: tabulated.c:218
static char * module
Definition: pips.c:74
#define make_entity(n, t, s, i)
entity module_name_to_entity(const char *mn)
This is an alias for local_name_to_top_level_entity.
Definition: entity.c:1479
void AddEntityToDeclarations(entity, entity)
END_EOLE.
Definition: variable.c:108
#define value_code_p(x)
Definition: ri.h:3065
#define entity_storage(x)
Definition: ri.h:2794
#define entity_undefined
Definition: ri.h:2761
#define entity_type(x)
Definition: ri.h:2792
#define entity_domain
newgen_syntax_domain_defined
Definition: ri.h:410
#define entity_initial(x)
Definition: ri.h:2796

References a_variable, AddEntityToDeclarations(), concatenate(), copy_storage(), copy_type(), copy_value(), entity_domain, entity_initial, entity_storage, entity_type, entity_undefined, gen_find_tabulated(), make_entity, module, module_name(), module_name_to_entity(), MODULE_SEP_STRING, new_variable, pips_assert, strdup(), and value_code_p.

Referenced by make_variable_from_name_and_entity(), and new_local_image_variable().

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

◆ debug_control()

void debug_control ( const char *  comments,
control  a_control,
int  debug_level 
)

DEBUG FUNCTION: print debugging informations for a control a_control.

Parameters
commentsomments
a_control_control
debug_levelebug_level

Definition at line 134 of file phrase_tools.c.

134  {
135 
136  debug_statement (comments, control_statement(a_control), debug_level);
137  pips_debug(debug_level," predecessors = %zd\n", gen_length(control_predecessors(a_control)));
138  pips_debug(debug_level," successors = %zd\n", gen_length(control_successors(a_control)));
139 
140 }
size_t gen_length(const list l)
Definition: list.c:150
#define pips_debug
these macros use the GNU extensions that allow variadic macros, including with an empty list.
Definition: misc-local.h:145
void debug_statement(const char *comments, statement stat, int debug_level)
DEBUG FUNCTION: print debugging informations for a statement stat.
Definition: phrase_tools.c:111
#define control_predecessors(x)
Definition: ri.h:943
#define control_successors(x)
Definition: ri.h:945
#define control_statement(x)
Definition: ri.h:941

References control_predecessors, control_statement, control_successors, debug_statement(), gen_length(), and pips_debug.

Referenced by flatten_unstructured(), full_spaghettify_module(), and make_transition_statement().

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

◆ debug_statement()

void debug_statement ( const char *  comments,
statement  stat,
int  debug_level 
)

DEBUG FUNCTION: print debugging informations for a statement stat.

Parameters
commentsomments
stattat
debug_levelebug_level

Definition at line 111 of file phrase_tools.c.

112 {
114  pips_debug(debug_level,"%s\n",comments);
115  print_statement(stat);
116  pips_debug(debug_level,"domain number = %"PRIdPTR"\n", statement_domain_number(stat));
117  pips_debug(debug_level,"entity = UNDEFINED\n");
118  pips_debug(debug_level,"statement number = %"PRIdPTR"\n", statement_number(stat));
119  pips_debug(debug_level,"statement ordering = %"PRIdPTR"\n", statement_ordering(stat));
120  if (statement_with_empty_comment_p(stat)) {
121  pips_debug(debug_level,"statement comments = EMPTY\n");
122  }
123  else {
124  pips_debug(debug_level,"statement comments = %s\n", statement_comments(stat));
125  }
126  pips_debug(debug_level,"statement instruction = %s\n", statement_type_as_string(stat));
127  }
128 }
string statement_type_as_string(statement stat)
DEBUG FUNCTION: return a string representing the type of the statement (SEQUENCE, CALL,...
Definition: phrase_tools.c:65
void print_statement(statement)
Print a statement on stderr.
Definition: statement.c:98
#define statement_ordering(x)
Definition: ri.h:2454
#define statement_domain_number(x)
Definition: ri.h:2448
#define statement_number(x)
Definition: ri.h:2452
#define ifdebug(n)
Definition: sg.c:47

References ifdebug, pips_debug, print_statement(), statement_comments, statement_domain_number, statement_number, statement_ordering, statement_type_as_string(), and statement_with_empty_comment_p().

Referenced by debug_control(), and full_spaghettify_statement().

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

◆ debug_unstructured()

void debug_unstructured ( unstructured  an_unstructured,
int  debug_level 
)

DEBUG FUNCTION: print debugging informations for an unstructured an_unstructured.

f (ordering > 65535) ordering = ordering >> 16;

f (ordering > 65535) ordering = ordering >> 16;

f (ordering > 65535) ordering = ordering >> 16;

Parameters
an_unstructuredn_unstructured
debug_levelebug_level

Definition at line 146 of file phrase_tools.c.

148 {
149  list blocs = NIL ;
150  string line = "***********************************************************************\n";
151 
152  ifdebug (debug_level) {
153  CONTROL_MAP (current_control, {
154  statement s = control_statement (current_control);
155  string next_nodes_as_string = "";
156  string previous_nodes_as_string = "";
157  char *title;
158  list predecessors = control_predecessors(current_control);
159  list successors = control_successors(current_control);
160  char *temp;
161  size_t i;
162  int ordering = 0;
163 
164  for (i=0; i<gen_length(predecessors); i++) {
167  ordering = beautify_ordering (ordering);
168  /*if (ordering > 65535) ordering = ordering >> 16;*/
169  asprintf (&temp, "[%d] ",ordering);
170  previous_nodes_as_string = strdup (concatenate(previous_nodes_as_string,
171  temp,
172  NULL));
173  free(temp);
174  }
175 
176  for (i=0; i<gen_length(successors); i++) {
178  (CONTROL(gen_nth(i,successors))));
179  ordering = beautify_ordering (ordering);
180  /*if (ordering > 65535) ordering = ordering >> 16;*/
181  asprintf (&temp, "[%d] ",ordering);
182  next_nodes_as_string = strdup (concatenate(next_nodes_as_string,
183  (temp),
184  NULL));
185  free(temp);
186  }
187 
188  ordering = beautify_ordering (ordering);
189  ordering = statement_ordering(s);
190  /*if (ordering > 65535) ordering = ordering >> 16;*/
192  asprintf (&title, "CONTROL: %d\n", ordering);
193  pips_debug(debug_level, "%s\n",
194  strdup(concatenate("\n", line,
195  "* ", (title),
196  line, NULL)));
197  print_statement(s);
198  pips_debug(debug_level, "%s\n",
199  strdup(concatenate("\n", line,
200  "NEXT: ", next_nodes_as_string, "\n",
201  "PREVIOUS: ", previous_nodes_as_string, "\n",
202  line, NULL)));
203  free(title);
204  }
205  }, unstructured_entry(an_unstructured), blocs);
206  }
207 }
static list predecessors(statement st, graph tg)
static list successors(list l)
void free(void *)
#define CONTROL_MAP(ctl, code, c, list)
Macro to walk through all the controls reachable from a given control node of an unstructured.
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
gen_chunk gen_nth(int n, const list l)
to be used as ENTITY(gen_nth(3, l))...
Definition: list.c:710
#define asprintf
Definition: misc-local.h:225
int beautify_ordering(int an_ordering)
Special function made for Ronan Keryell who likes a lot when a integer number is coded on 3 bits :-)
Definition: phrase_tools.c:407
#define CONTROL(x)
CONTROL.
Definition: ri.h:910
#define unstructured_entry(x)
Definition: ri.h:3004
static int line
FLEX_SCANNER.
Definition: scanner.c:852
The structure used to build lists in NewGen.
Definition: newgen_list.h:41

References asprintf, beautify_ordering(), concatenate(), CONTROL, CONTROL_MAP, control_predecessors, control_statement, control_successors, free(), gen_length(), gen_nth(), ifdebug, line, NIL, pips_debug, predecessors(), print_statement(), statement_ordering, strdup(), successors(), and unstructured_entry.

+ Here is the call graph for this function:

◆ get_statements_with_comments_containing()

list get_statements_with_comments_containing ( const char *  comment_portion,
statement  stat 
)

First, set searched_string (we remove format information)

Reset list

fdebug(5) { pips_debug(5, "Searching statements with comments: %s\n", context.searched_string);
pips_debug(5, "In statement:\n");
print_statement(stat); }

Parameters
comment_portionomment_portion
stattat

Definition at line 481 of file phrase_tools.c.

483 {
485 
486  /* First, set searched_string (we remove format information)*/
487  context.searched_string = strdup(comment_portion);
488  context.searched_string[strcspn(comment_portion, "%s")] = '\0';
489 
490  /* Reset list */
491  context.list_of_statements = NIL;
492 
493  /*ifdebug(5) {
494  pips_debug(5, "Searching statements with comments: %s\n",
495  context.searched_string);
496  pips_debug(5, "In statement:\n");
497  print_statement(stat);
498  }*/
499 
502 
503  return context.list_of_statements;
504 
505 }
#define gen_context_recurse(start, ctxt, domain_number, flt, rwt)
Definition: genC.h:285
bool gen_true2(__attribute__((unused)) gen_chunk *u1, __attribute__((unused)) void *u2)
Definition: genClib.c:2785
static void check_if_statement_contains_comment(statement s, void *a_context)
Definition: phrase_tools.c:459
#define statement_domain
newgen_sizeofexpression_domain_defined
Definition: ri.h:362

References check_if_statement_contains_comment(), gen_context_recurse, gen_true2(), NIL, statement_domain, and strdup().

Referenced by controlize_distribution(), identify_analyzed_statements_to_distribute(), and identify_statements_to_distribute().

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

◆ make_assignement_statement()

statement make_assignement_statement ( entity  a_variable,
expression  an_expression,
statement  stat 
)

Build and return new statement which is a assignement of variable a_variable with expression an_expression, with empty label, statement number and ordering of statement stat, and empty comments.

Parameters
a_variable_variable
an_expressionn_expression
stattat

Definition at line 392 of file phrase_tools.c.

395 {
398  an_expression,
399  stat);
400 }
statement make_binary_call_statement(const char *operator_name, expression expression1, expression expression2, statement stat)
Build and return new statement which is a binary call with the 2 expressions expression1 and expressi...
Definition: phrase_tools.c:354
#define ASSIGN_OPERATOR_NAME
Definition: ri-util-local.h:95
expression entity_to_expression(entity e)
if v is a constant, returns a constant call.
Definition: expression.c:165

References a_variable, ASSIGN_OPERATOR_NAME, entity_to_expression(), and make_binary_call_statement().

Referenced by make_body_from_loop(), make_global_common_and_initialize(), and make_initialization_from_loop().

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

◆ make_binary_call_statement()

statement make_binary_call_statement ( const char *  operator_name,
expression  expression1,
expression  expression2,
statement  stat 
)

Build and return new statement which is a binary call with the 2 expressions expression1 and expression2, with empty label, statement number and ordering of statement stat, and empty comments.

Parameters
operator_nameperator_name
expression1xpression1
expression2xpression2
stattat

Definition at line 354 of file phrase_tools.c.

358 {
359  call assignment_call
360  = make_call (entity_intrinsic(operator_name),
362  expression1,
363  CONS(EXPRESSION, expression2, NIL)));
364 
365  if (stat == NULL) {
371  assignment_call),
372  NIL,NULL,
374  }
375  else {
377  statement_number(stat),
378  statement_ordering(stat),
381  assignment_call),
382  NIL,NULL,
384  }
385 }
call make_call(entity a1, list a2)
Definition: ri.c:269
statement make_statement(entity a1, intptr_t a2, intptr_t a3, string a4, instruction a5, list a6, string a7, extensions a8, synchronization a9)
Definition: ri.c:2222
instruction make_instruction(enum instruction_utype tag, void *val)
Definition: ri.c:1166
synchronization make_synchronization_none(void)
Definition: ri.c:2424
#define STATEMENT_ORDERING_UNDEFINED
mapping.h inclusion
Definition: newgen-local.h:35
#define STATEMENT_NUMBER_UNDEFINED
default values
entity entity_empty_label(void)
Definition: entity.c:1105
entity entity_intrinsic(const char *name)
FI: I do not understand this function name (see next one!).
Definition: entity.c:1292
extensions empty_extensions(void)
extension.c
Definition: extension.c:43
#define EXPRESSION(x)
EXPRESSION.
Definition: ri.h:1217
@ is_instruction_call
Definition: ri.h:1474
#define statement_extensions(x)
Definition: ri.h:2464

References CONS, empty_comments, empty_extensions(), entity_empty_label(), entity_intrinsic(), EXPRESSION, is_instruction_call, make_call(), make_instruction(), make_statement(), make_synchronization_none(), NIL, statement_extensions, statement_number, STATEMENT_NUMBER_UNDEFINED, statement_ordering, and STATEMENT_ORDERING_UNDEFINED.

Referenced by make_array_communication_statement(), make_assignement_statement(), and make_communication_statement().

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

◆ make_variable_from_name_and_entity()

entity make_variable_from_name_and_entity ( entity  cloned_variable,
const char *  base_name,
statement  stat,
const char *  module_name 
)

Build and return new entity obtained by cloning variable cloned_variable, with a name obtained by the concatenation of base_name and the statement ordering of statement stat.

If such entity already exist, increment statement ordering to get first free name. We assume then that created entity's name is unique.

Parameters
cloned_variableloned_variable
base_namease_name
stattat
module_nameodule_name

Definition at line 325 of file phrase_tools.c.

329 {
330  string variable_name;
331  entity returned_variable = NULL;
332  int index = statement_ordering(stat);
333  //char *buffer;
334 
335  while (returned_variable == NULL) {
336 
337  asprintf(&variable_name, base_name, index++);
338  returned_variable
339  = clone_variable_with_new_name (cloned_variable,
341  module_name);
342  }
343 
344  return returned_variable;
345 
346 }
entity clone_variable_with_new_name(entity a_variable, const char *new_name, const char *module_name)
This function build and return new variable from a variable a_variable, with name new_name.
Definition: phrase_tools.c:269
char * variable_name(Variable v)
polynome_ri.c
Definition: polynome_ri.c:73

References asprintf, clone_variable_with_new_name(), module_name(), statement_ordering, and variable_name().

Referenced by make_begin_variable(), make_end_variable(), make_increment_variable(), and make_index_variable().

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

◆ references_for_regions()

list references_for_regions ( list  l_regions)

Return a list of references corresponding to a list of regions.

Parameters
l_regions_regions

Definition at line 603 of file phrase_tools.c.

604 {
605  list l_ref = NIL;
606 
607  MAP (EFFECT, reg, {
609  l_ref = CONS (REFERENCE, ref, l_ref);
611  pips_debug(4,"Entity: %s\n", entity_local_name(reference_variable(ref)));
612  },l_regions);
613 
614  return l_ref;
615 }
static reference ref
Current stmt (an integer)
Definition: adg_read_paf.c:163
#define effect_any_reference(e)
FI: cannot be used as a left hand side.
#define EFFECT(x)
EFFECT.
Definition: effects.h:608
#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
void print_reference(reference r)
Definition: expression.c:142
const char * entity_local_name(entity e)
entity_local_name modified so that it does not core when used in vect_fprint, since someone thought t...
Definition: entity.c:453
#define REFERENCE(x)
REFERENCE.
Definition: ri.h:2296
#define reference_variable(x)
Definition: ri.h:2326

References CONS, EFFECT, effect_any_reference, entity_local_name(), MAP, NIL, pips_debug, print_reference(), ref, REFERENCE, and reference_variable.

Referenced by create_module_with_statement(), and distribute_code().

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

◆ replace_in_sequence_statement_with()

void replace_in_sequence_statement_with ( statement  old_stat,
statement  new_stat,
statement  root_stat 
)

Replace statement old_stat by statement new_stat, asserting that this statement is contained in a sequence.

en_insert_after (new_stat, old_stat, stats_list); gen_remove (&stats_list, old_stat);

Parameters
old_statld_stat
new_statew_stat
root_statoot_stat

Definition at line 554 of file phrase_tools.c.

557 {
558  statement sequence_statement = sequence_statement_containing (root_stat,
559  old_stat);
560  list stats_list;
561  list new_stats_list = NIL;
562 
563  pips_debug(5, "BEGIN replace_in_sequence_statement_with:\n");
564 
565  pips_assert("Statement is contained in a sequence",
566  sequence_statement != NULL);
567 
568  stats_list = sequence_statements(instruction_sequence(statement_instruction(sequence_statement)));
569 
570  MAP (STATEMENT, s, {
571  ifdebug(7) {
572  pips_debug(7, "Iterate on statement:\n");
573  print_statement(s);
574  }
575  if (s == old_stat) {
576  pips_debug(7, "Replace this statement:\n");
577  new_stats_list = CONS(STATEMENT,new_stat,new_stats_list);
578  }
579  else {
580  pips_debug(7, "Keep this statement:\n");
581  new_stats_list = CONS(STATEMENT,s,new_stats_list);
582  }
583  }, stats_list);
584 
585  sequence_statements(instruction_sequence(statement_instruction(sequence_statement))) = gen_nreverse(new_stats_list);
586 
587  /*gen_insert_after (new_stat, old_stat, stats_list);
588  gen_remove (&stats_list, old_stat);*/
589 
590  ifdebug(7) {
591  pips_debug(7, "I've got this for the sequence\n");
592  print_statement(sequence_statement);
593  pips_debug(7, "I've got this for the root statement\n");
594  print_statement(root_stat);
595  }
596 
597  pips_debug(5, "END replace_in_sequence_statement_with:\n");
598 }
list gen_nreverse(list cp)
reverse a list in place
Definition: list.c:304
statement sequence_statement_containing(statement root_statement, statement searched_stat)
Definition: phrase_tools.c:536
#define sequence_statements(x)
Definition: ri.h:2360
#define instruction_sequence(x)
Definition: ri.h:1514
#define statement_instruction(x)
Definition: ri.h:2458

References CONS, gen_nreverse(), ifdebug, instruction_sequence, MAP, NIL, pips_assert, pips_debug, print_statement(), sequence_statement_containing(), sequence_statements, STATEMENT, and statement_instruction.

Referenced by distribute_code().

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

◆ search_sequence_containing()

static void search_sequence_containing ( statement  s,
void *  a_context 
)
static

Definition at line 520 of file phrase_tools.c.

522 {
524  = (sequence_searching_context*)a_context;
526 
528  MAP (STATEMENT, s2, {
529  if (s2 == context->searched_statement) {
530  context->found_sequence_statement = s;
531  }
533  }
534 }
@ is_instruction_sequence
Definition: ri.h:1469
#define instruction_tag(x)
Definition: ri.h:1511

References instruction_sequence, instruction_tag, is_instruction_sequence, MAP, sequence_statements, STATEMENT, and statement_instruction.

Referenced by sequence_statement_containing().

+ Here is the caller graph for this function:

◆ sequence_statement_containing()

statement sequence_statement_containing ( statement  root_statement,
statement  searched_stat 
)
Parameters
root_statementoot_statement
searched_statearched_stat

Definition at line 536 of file phrase_tools.c.

538 {
540 
541  context.searched_statement = searched_stat;
542  context.found_sequence_statement = NULL;
543 
544  gen_context_recurse(root_statement, &context,
546 
547  return context.found_sequence_statement;
548 }
static void search_sequence_containing(statement s, void *a_context)
Definition: phrase_tools.c:520

References gen_context_recurse, gen_true2(), search_sequence_containing(), and statement_domain.

Referenced by compute_distribution_context(), identify_statements_to_distribute(), replace_in_sequence_statement_with(), and statement_is_contained_in_a_sequence_p().

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

◆ short_debug_unstructured()

void short_debug_unstructured ( unstructured  an_unstructured,
int  debug_level 
)

DEBUG FUNCTION: print debugging informations for an unstructured an_unstructured (short version)

Parameters
an_unstructuredn_unstructured
debug_levelebug_level

Definition at line 213 of file phrase_tools.c.

215 {
216  ifdebug (debug_level) {
217 
218  list blocs = NIL;
219  string entry_as_string, exit_as_string, temp;
220  asprintf (&temp, "[%p] ",unstructured_entry(an_unstructured));
221  entry_as_string = strdup(temp);
222  asprintf (&temp, "[%p] ",unstructured_exit(an_unstructured));
223  exit_as_string = strdup(temp);
224  pips_debug(debug_level, "%s\n",
225  strdup(concatenate("UNSTRUCTURED\n",
226  "ENTRY: ", entry_as_string, "\n",
227  "PREVIOUS: ", exit_as_string, "\n",
228  NULL)));
229 
230  CONTROL_MAP (current_control, {
231  string next_nodes_as_string = "";
232  string previous_nodes_as_string = "";
233  char *title;
234 
235  MAP(CONTROL, c, {
236  asprintf (&temp, "[%p] ",c);
237  previous_nodes_as_string = strdup (concatenate(previous_nodes_as_string,
238  (temp),
239  NULL));
240  free(temp);
241  }, control_predecessors(current_control));
242 
243  MAP(CONTROL, c, {
244  asprintf (&temp, "[%p] ",c);
245  next_nodes_as_string = strdup (concatenate(next_nodes_as_string,
246  (temp),
247  NULL));
248  free(temp);
249  }, control_successors(current_control));
250 
251  asprintf (&title, "CONTROL: %p\n", current_control);
252  pips_debug(debug_level, "%s\n",
253  strdup(concatenate(title,
254  "NEXT: ", next_nodes_as_string, "\n",
255  "PREVIOUS: ", previous_nodes_as_string, "\n",
256  NULL)));
257  free(title);
258  }, unstructured_entry(an_unstructured), blocs);
259  }
260 }
#define unstructured_exit(x)
Definition: ri.h:3006

References asprintf, concatenate(), CONTROL, CONTROL_MAP, control_predecessors, control_successors, free(), ifdebug, MAP, NIL, pips_debug, strdup(), unstructured_entry, and unstructured_exit.

Referenced by flatten_unstructured().

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

◆ statement_is_contained_in_a_sequence_p()

bool statement_is_contained_in_a_sequence_p ( statement  root_statement,
statement  searched_stat 
)
Parameters
root_statementoot_statement
searched_statearched_stat

Definition at line 507 of file phrase_tools.c.

509 {
510  return (sequence_statement_containing (root_statement,
511  searched_stat) != NULL);
512 }

References sequence_statement_containing().

Referenced by identify_statements_to_distribute().

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

◆ statement_type_as_string()

string statement_type_as_string ( statement  stat)

DEBUG FUNCTION: return a string representing the type of the statement (SEQUENCE, CALL, etc...)

phrase_tools.c

Parameters
stattat

Definition at line 65 of file phrase_tools.c.

66 {
68  switch (instruction_tag(i)) {
69  case is_instruction_test: {
70  return strdup("TEST");
71  break;
72  }
74  return strdup("SEQUENCE");
75  break;
76  }
77  case is_instruction_loop: {
78  return strdup("LOOP");
79  break;
80  }
82  return strdup("WHILELOOP");
83  break;
84  }
86  return strdup("FORLOOP");
87  break;
88  }
89  case is_instruction_call: {
90  return strdup("CALL");
91  break;
92  }
94  return strdup("UNSTRUCTURED");
95  break;
96  }
97  case is_instruction_goto: {
98  return strdup("GOTO");
99  break;
100  }
101  default:
102  return strdup("UNDEFINED");
103  break;
104  }
105 }
@ 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_forloop
Definition: ri.h:1477
@ is_instruction_loop
Definition: ri.h:1471

References instruction_tag, is_instruction_call, is_instruction_forloop, is_instruction_goto, is_instruction_loop, is_instruction_sequence, is_instruction_test, is_instruction_unstructured, is_instruction_whileloop, statement_instruction, and strdup().

Referenced by debug_statement(), fsmize_statement(), and spaghettify_statement().

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