PIPS
expression_substitution.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include "genC.h"
#include "linear.h"
#include "ri.h"
#include "effects.h"
#include "database.h"
#include "ri-util.h"
#include "effects-util.h"
#include "pipsdbm.h"
#include "control.h"
#include "callgraph.h"
#include "misc.h"
#include "resources.h"
#include "properties.h"
#include "expressions.h"
+ Include dependency graph for expression_substitution.c:

Go to the source code of this file.

Functions

static bool set_pattern ()
 retrieves the expression used as a pattern based on the one - statement function given in a property and sets static variables accordingly More...
 
static void substitute_expression_walker (expression e, expression *pi)
 
void substitute_expression (void *in, expression pattern, expression into)
 expression_substitution.c More...
 
static bool replace_expression_similar_to_pattern (expression e)
 
static bool replace_instruction_similar_to_pattern (instruction i)
 
bool expression_substitution (const char *module_name)
 simple pass that performs substitution of expression by module call More...
 

Variables

static expression pattern = expression_undefined
 
static const char * pattern_module_name = string_undefined
 

Function Documentation

◆ expression_substitution()

bool expression_substitution ( const char *  module_name)

simple pass that performs substitution of expression by module call

prelude

search pattern

validate

ostlude

Parameters
module_nameodule_name

Definition at line 157 of file expression_substitution.c.

158 {
159  /* prelude */
162 
163  /* search pattern*/
164  bool pattern_set_p = set_pattern();
165  if( pattern_set_p )
166  {
174  0
175  );
176  }
177 
178  /* validate */
182 
183  /*postlude*/
186  return pattern_set_p;
187 }
callees compute_callees(const statement stat)
Recompute the callees of a module statement.
Definition: callgraph.c:355
const char * module_name(const char *s)
Return the module part of an entity name.
Definition: entity_names.c:296
static bool replace_instruction_similar_to_pattern(instruction i)
static bool set_pattern()
retrieves the expression used as a pattern based on the one - statement function given in a property ...
static bool replace_expression_similar_to_pattern(expression e)
void convert_to_standard_operators(void *)
Definition: optimize.c:1364
void reset_current_module_entity(void)
Reset the current module entity.
Definition: static.c:97
void reset_current_module_statement(void)
Reset the current module statement.
Definition: static.c:221
statement set_current_module_statement(statement)
Set the current module statement.
Definition: static.c:165
statement get_current_module_statement(void)
Get the current module statement.
Definition: static.c:208
entity set_current_module_entity(entity)
static.c
Definition: static.c:66
void gen_multi_recurse(void *o,...)
Multi recursion visitor function.
Definition: genClib.c:3428
bool gen_false(__attribute__((unused)) gen_chunk *unused)
Return false and ignore the argument.
Definition: genClib.c:2796
void gen_null(__attribute__((unused)) void *unused)
Ignore the argument.
Definition: genClib.c:2752
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
#define DB_PUT_MEMORY_RESOURCE(res_name, own_name, res_val)
conform to old interface.
Definition: pipsdbm-local.h:66
bool module_reorder(statement body)
Reorder a module and recompute order to statement if any.
Definition: reorder.c:244
entity module_name_to_entity(const char *mn)
This is an alias for local_name_to_top_level_entity.
Definition: entity.c:1479
#define expression_domain
newgen_execution_domain_defined
Definition: ri.h:154
#define instruction_domain
newgen_functional_domain_defined
Definition: ri.h:202
#define reference_domain
newgen_range_domain_defined
Definition: ri.h:338
#define range_domain
newgen_ram_domain_defined
Definition: ri.h:330

References compute_callees(), convert_to_standard_operators(), db_get_memory_resource(), DB_PUT_MEMORY_RESOURCE, expression_domain, gen_false(), gen_multi_recurse(), gen_null(), get_current_module_statement(), instruction_domain, module_name(), module_name_to_entity(), module_reorder(), range_domain, reference_domain, replace_expression_similar_to_pattern(), replace_instruction_similar_to_pattern(), reset_current_module_entity(), reset_current_module_statement(), set_current_module_entity(), set_current_module_statement(), and set_pattern().

+ Here is the call graph for this function:

◆ replace_expression_similar_to_pattern()

static bool replace_expression_similar_to_pattern ( expression  e)
static

recover pattern's arguments

fill the arguments

fix the expression field

Definition at line 101 of file expression_substitution.c.

102 {
103  hash_table symbols; // contains the symbols gathered during the matching
104  // match e against pattern and stocks symbols in hash_table
106  {
109 
110  /* recover pattern's arguments */
111  list iter = NIL;
113  if(entity_formal_p(e))
114  iter=CONS(ENTITY,e,iter);
115  iter=gen_nreverse(iter);
116 
117  /* fill the arguments */
118  list args = NIL;
119  FOREACH(ENTITY, arg, iter)
120  {
121  expression arge = hash_get(symbols,entity_name(arg));
122  pips_assert("created map consistant with dynamic decl",arge != HASH_UNDEFINED_VALUE);
123  args=CONS(EXPRESSION,copy_expression(arge),args);
124 
125  }
126 
128 
129  /* fix the expression field*/
131  make_call(pattern_entity,gen_nreverse(args))
132  );
133  hash_table_free(symbols);
134  return false;
135  }
136  return true;
137 }
call make_call(entity a1, list a2)
Definition: ri.c:269
syntax make_syntax_call(call _field_)
Definition: ri.c:2500
expression copy_expression(expression p)
EXPRESSION.
Definition: ri.c:850
void free_syntax(syntax p)
Definition: ri.c:2445
static const char * pattern_module_name
list gen_nreverse(list cp)
reverse a list in place
Definition: list.c:304
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
#define CONS(_t_, _i_, _l_)
List element cell constructor (insert an element at the beginning of a list)
Definition: newgen_list.h:150
#define FOREACH(_fe_CASTER, _fe_item, _fe_list)
Apply/map an instruction block on all the elements of a list.
Definition: newgen_list.h:179
void * hash_get(const hash_table htp, const void *key)
this function retrieves in the hash table pointed to by htp the couple whose key is equal to key.
Definition: hash.c:449
void hash_table_free(hash_table htp)
this function deletes a hash table that is no longer useful.
Definition: hash.c:327
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
#define TOP_LEVEL_MODULE_NAME
Module containing the global variables in Fortran and C.
Definition: naming-local.h:101
#define HASH_UNDEFINED_VALUE
value returned by hash_get() when the key is not found; could also be called HASH_KEY_NOT_FOUND,...
Definition: newgen_hash.h:56
entity FindEntity(const char *package, const char *name)
Retrieve an entity from its package/module name and its local name.
Definition: entity.c:1503
bool entity_formal_p(entity p)
is p a formal parameter?
Definition: entity.c:1935
bool expression_similar_get_context_p(expression target, expression pattern, hash_table *symbol_table)
similar to expression_similar_p but the hash_map containing the crossref value is retured for further...
Definition: expression.c:3339
#define normalized_undefined
Definition: ri.h:1745
#define ENTITY(x)
ENTITY.
Definition: ri.h:2755
#define code_declarations(x)
Definition: ri.h:784
#define EXPRESSION(x)
EXPRESSION.
Definition: ri.h:1217
#define entity_name(x)
Definition: ri.h:2790
#define expression_normalized(x)
Definition: ri.h:1249
#define value_code(x)
Definition: ri.h:3067
#define expression_syntax(x)
Definition: ri.h:1247
#define entity_initial(x)
Definition: ri.h:2796
The structure used to build lists in NewGen.
Definition: newgen_list.h:41

References code_declarations, CONS, copy_expression(), ENTITY, entity_formal_p(), entity_initial, entity_name, EXPRESSION, expression_normalized, expression_similar_get_context_p(), expression_syntax, FindEntity(), FOREACH, free_syntax(), gen_nreverse(), hash_get(), hash_table_free(), HASH_UNDEFINED_VALUE, make_call(), make_syntax_call(), NIL, normalized_undefined, pattern_module_name, pips_assert, TOP_LEVEL_MODULE_NAME, and value_code.

Referenced by expression_substitution(), and replace_instruction_similar_to_pattern().

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

◆ replace_instruction_similar_to_pattern()

static bool replace_instruction_similar_to_pattern ( instruction  i)
static

replacement successfull

Definition at line 139 of file expression_substitution.c.

140 {
141  if(instruction_call_p(i))
142  {
144  if( !replace_expression_similar_to_pattern(exp) ) /* replacement successfull */
145  {
149  return false;
150  }
151  }
152  return true;
153 }
void free_expression(expression p)
Definition: ri.c:853
call expression_call(expression e)
Definition: expression.c:445
expression call_to_expression(call c)
Build an expression that call a function or procedure.
Definition: expression.c:309
#define instruction_call_p(x)
Definition: ri.h:1527
#define syntax_undefined
Definition: ri.h:2676
#define instruction_call(x)
Definition: ri.h:1529
#define exp
Avoid some warnings from "gcc -Wshadow".
Definition: vasnprintf.c:207

References call_to_expression(), exp, expression_call(), expression_syntax, free_expression(), instruction_call, instruction_call_p, replace_expression_similar_to_pattern(), and syntax_undefined.

Referenced by expression_substitution().

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

◆ set_pattern()

static bool set_pattern ( )
static

retrieves the expression used as a pattern based on the one - statement function given in a property and sets static variables accordingly

Definition at line 58 of file expression_substitution.c.

59 {
60  pattern_module_name = get_string_property("EXPRESSION_SUBSTITUTION_PATTERN");
62  {
63 
66  if( instruction_block_p(i))
67  {
68  list l = instruction_block(i);
69  if(!ENDP(l)) i = statement_instruction(STATEMENT(CAR(l)));
70  }
71  if( return_instruction_p(i) )
73  else {
74  pips_user_warning("%s used as pattern for expression substitution, but is not a module with a single return !\n", pattern_module_name);
75  return false;
76  }
78 
79  }
80  else
81  {
82  pips_user_warning("EXPRESSION_SUBSTITUTION_PATTERN undefined, but needed to perform expression substitution\n");
83  return false;
84  }
85  return true;
86 }
struct _newgen_struct_statement_ * statement
Definition: cloning.h:21
char * get_string_property(const char *)
bool return_instruction_p(instruction i)
Test if an instruction is a C or Fortran "return".
Definition: instruction.c:185
#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 pips_user_warning
Definition: misc-local.h:146
#define string_undefined_p(s)
Definition: newgen_types.h:41
#define instruction_block_p(i)
#define instruction_block(i)
#define statement_instruction(x)
Definition: ri.h:2458
#define call_arguments(x)
Definition: ri.h:711
#define STATEMENT(x)
STATEMENT.
Definition: ri.h:2413

References call_arguments, CAR, convert_to_standard_operators(), db_get_memory_resource(), ENDP, EXPRESSION, get_string_property(), instruction_block, instruction_block_p, instruction_call, pattern_module_name, pips_user_warning, return_instruction_p(), STATEMENT, statement_instruction, and string_undefined_p.

Referenced by expression_substitution().

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

◆ substitute_expression()

void substitute_expression ( void *  in,
expression  pattern,
expression  into 
)

expression_substitution.c

Parameters
inn
patternattern
intonto

Definition at line 94 of file expression_substitution.c.

95 {
96  expression arge [] = { pattern, into };
98 }
static void substitute_expression_walker(expression e, expression *pi)
static expression pattern
#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

References expression_domain, gen_context_recurse, gen_true2(), pattern, and substitute_expression_walker().

Referenced by do_terapix_argument_handler().

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

◆ substitute_expression_walker()

static void substitute_expression_walker ( expression  e,
expression pi 
)
static

Definition at line 88 of file expression_substitution.c.

89 {
90  if(same_expression_p(e,pi[0]))
92 }
syntax copy_syntax(syntax p)
SYNTAX.
Definition: ri.c:2442
void update_expression_syntax(expression e, syntax s)
frees expression syntax of e and replace it by the new syntax s
Definition: expression.c:3564
bool same_expression_p(expression e1, expression e2)
this is slightly different from expression_equal_p, as it will return true for a+b vs b+a
Definition: expression.c:1426

References copy_syntax(), expression_syntax, same_expression_p(), and update_expression_syntax().

Referenced by substitute_expression().

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

Variable Documentation

◆ pattern

Definition at line 50 of file expression_substitution.c.

Referenced by substitute_expression().

◆ pattern_module_name

const char* pattern_module_name = string_undefined
static

Definition at line 51 of file expression_substitution.c.

Referenced by replace_expression_similar_to_pattern(), and set_pattern().