25 #include "pips_config.h"
29 static char vcid[] =
"$Id: externalization.c 23495 2018-10-24 09:19:47Z coelho $";
52 if (strstr(comments,
context->searched_string) != NULL)
72 percent = strstr(
context.searched_string,
"%s");
75 pips_user_error(
"Malformed statement comment to search. Should be of the form 'BLAH_%%s'\n");
83 pips_debug(5,
"Searching statements with comments: %s\n",
context.searched_string);
92 return context.list_of_statements;
103 string searched_string;
105 char *function_name = NULL;
119 searched_string =
strdup(comment_portion);
120 searched_string[strcspn(comment_portion,
"%s")] =
'\0';
122 next_line = strtok(comments,
"\n");
124 if (next_line != NULL)
128 string first_occurence = strstr(next_line, searched_string);
130 if (first_occurence != NULL)
132 function_name =
malloc(256);
133 pips_debug(5,
"Scanning: [%s] with [%s]", first_occurence, comment_portion);
134 sscanf (first_occurence, comment_portion, function_name, stats_nb);
135 pips_debug(5,
"Found function: [%s] and %d stats \n", function_name, *stats_nb);
138 next_line = strtok(NULL,
"\n");
140 while (next_line != NULL);
143 free(searched_string);
147 free(comment_portion);
149 return function_name;
164 if (s2 ==
context->searched_statement)
166 context->found_sequence_statement = s;
180 context.searched_statement = searched_stat;
181 context.found_sequence_statement = NULL;
185 return context.found_sequence_statement;
196 pips_debug(4,
"BEGIN of computing regions UNION\n");
200 bool is_already_present =
false;
201 region reg_already_present = NULL;
208 is_already_present =
true;
209 reg_already_present = union_reg;
213 if (is_already_present)
253 pips_debug(4,
"END of computing regions UNION\n");
264 bool returned_value =
true;
265 list l_read, l_write, l_in, l_out;
310 pips_debug(2,
"Storing in hash_tables with key %s: \n", (
string)key_value);
315 hash_put(*ht_params, key_value, l_params);
320 returned_value =
false;
327 hash_put(*ht_private, key_value, l_priv);
332 returned_value =
false;
335 pips_debug(5,
"Storing in ht_in_regions: \n");
339 hash_put(*ht_in_regions, key_value, l_in);
344 returned_value =
false;
347 pips_debug(5,
"Storing in ht_out_regions: \n");
351 hash_put(*ht_out_regions, key_value, l_out);
356 returned_value =
false;
359 return returned_value;
368 bool returned_value =
true;
384 pips_debug(5,
"Funtion name: %s\n", function_name);
385 pips_debug(5,
"Number of statements: %d\n", stats_nb);
391 else if (stats_nb == 1)
393 externalized_code = s;
401 pips_debug(5,
"Register externalized function %s: \n", function_name);
405 hash_put(*ht_stats, function_name, externalized_code);
410 returned_value =
false;
413 pips_debug(3,
"ANALYSING function named [%s]..................\n", function_name);
417 returned_value =
false;
423 return returned_value;
515 list module_parameters;
594 pips_debug(5,
"[BEGIN] create_module_with_statement\n");
595 pips_debug(2,
"Creating new module: [%s]\n", new_module_name);
612 pips_debug(2,
"Making new module: [%s]\n", new_module_name);
623 pips_debug(5,
"[END] create_module_with_statement\n");
638 pips_debug(5,
"BEGIN replace_in_sequence_statement_with:\n");
639 pips_assert(
"Statement is contained in a sequence", sequence_statement != NULL);
664 pips_debug(7,
"I've got this for the sequence\n");
666 pips_debug(7,
"I've got this for the root statement\n");
670 pips_debug(5,
"END replace_in_sequence_statement_with:\n");
682 string call_comments;
692 char* new_tag =
malloc(256);
695 call_comments =
strdup(new_tag);
731 pips_debug(7,
"Code distribution for : [%s] is DONE\n", function_name);
801 debug_on(
"SAFESCALE_DISTRIBUTOR_DEBUG_LEVEL");
809 pips_debug(2,
"BEGIN of SAFESCALE_DISTRIBUTOR\n");
813 pips_debug(2,
"END of SAFESCALE_DISTRIBUTOR\n");
call make_call(entity a1, list a2)
parameter make_parameter(type a1, mode a2, dummy a3)
mode make_mode(enum mode_utype tag, void *val)
type copy_type(type p)
TYPE.
storage make_storage(enum storage_utype tag, void *val)
ram make_ram(entity a1, entity a2, intptr_t a3, list a4)
bool statement_consistent_p(statement p)
language copy_language(language p)
LANGUAGE.
statement make_statement(entity a1, intptr_t a2, intptr_t a3, string a4, instruction a5, list a6, string a7, extensions a8, synchronization a9)
value copy_value(value p)
VALUE.
storage make_storage_formal(formal _field_)
instruction make_instruction(enum instruction_utype tag, void *val)
dummy make_dummy_unknown(void)
synchronization make_synchronization_none(void)
formal make_formal(entity a1, intptr_t a2)
static reference ref
Current stmt (an integer)
bdt base
Current expression.
callees compute_callees(const statement stat)
Recompute the callees of a module statement.
struct _newgen_struct_statement_ * statement
int compare_effect_reference(effect *e1, effect *e2)
int compare_effect_reference(e1, e2):
void simple_restructure_statement(statement)
A simple cleaning of the control graph without major topological restructuring.
static entity new_variable
entity to be replaced, the primary?
#define region_entity(reg)
#define region
simulation of the type region
#define region_scalar_p(reg)
list region_must_union(region r1, region r2)
computes the must union of two combinable array regions
list RegionsEntitiesInfDifference(list l1, list l2, bool(*difference_combinable_p)(effect, effect))
list RegionsEntitiesInfDifference(list l1, l2) input : two lists of regions output : a list of region...
list regions_write_regions(list)
list regions_read_regions(list)
void get_regions_properties(void)
void set_rw_effects(statement_effects)
bool w_r_combinable_p(effect, effect)
void reset_out_effects(void)
void reset_proper_rw_effects(void)
void set_proper_rw_effects(statement_effects)
void set_cumulated_rw_effects(statement_effects)
void set_out_effects(statement_effects)
void set_in_effects(statement_effects)
void reset_in_effects(void)
bool w_w_combinable_p(effect, effect)
list load_statement_out_regions(statement)
list load_statement_in_regions(statement)
void reset_cumulated_rw_effects(void)
list load_statement_local_regions(statement)
void reset_rw_effects(void)
#define effect_any_reference(e)
FI: cannot be used as a left hand side.
const char * module_name(const char *s)
Return the module part of an entity name.
static void check_if_statement_contains_comment(statement s, void *a_context)
lint
static string get_externalized_function_param_name(entity variable, int param_nb)
Return EXTERNALIZED_FUNCTION_PARAM_NAME.
static entity dynamic_area
Main phase for block code externalization.
static entity create_module_with_statement(statement stat, string new_module_name, list l_params, list l_priv)
Dynamically build a new module with specified statement.
static list get_statements_with_comments_containing(string comment_portion, statement stat)
Building a list with statements containing comments.
static void add_parameter_variable_to_module(reference ref, entity module, statement stat, string new_module_name, int param_nb)
Declare in the newly created module a new variable and replace all occurences to the old variable by ...
static entity create_private_variable_for_new_module(entity a_variable, string new_name, string new_module_name, entity module)
Create a private variable in specified module.
static void replace_in_sequence_statement_with(statement old_stat, statement new_stat, statement root_stat)
Replace statement old_stat by statement new_stat and assert that this statement is contained in a seq...
static string get_externalized_function_private_param_name(entity variable)
Return EXTERNALIZED_FUNCTION_PRIVATE_PARAM_NAME.
static list references_for_regions(list l_regions)
Return a list of references corresponding to a list of regions.
static void distribute_code(string function_name, statement externalized_code, statement module_stat, list l_params, list l_priv)
Externalize a specified code portion.
static void search_sequence_containing(statement s, void *a_context)
Get sequence containing a searched context.
static list compute_regions_union(list l_in, list l_out)
Compute union of exact regions.
static bool compute_distribution_context(list l_stats, statement module_stat, entity module, hash_table *ht_stats, hash_table *ht_params, hash_table *ht_private, hash_table *ht_in_regions, hash_table *ht_out_regions)
Compute distribution context for statement externalized_code.
static string get_externalized_and_analyzed_function_name(statement stat, int *stats_nb)
Return the identified function name of the externalized portion of code by searching comment matching...
static void distribute(statement module_stat, entity module)
Distribute for main module module with root statement stat.
static entity create_parameter_variable_for_new_module(entity a_variable, string new_name, string new_module_name, entity module, int param_nb)
Create a variable declared as a parameter in specified module.
static statement sequence_statement_containing(statement root_statement, statement searched_stat)
Get statement containing a searched statement.
bool safescale_distributor(const char *module_name)
externalization.c
static void add_private_variable_to_module(reference ref, entity module, statement stat, string new_module_name)
Declare in the newly created module a new variable and replace all occurences to the old variable by ...
static bool internal_compute_distribution_context(statement externalized_code, hash_table *ht_params, hash_table *ht_private, hash_table *ht_in_regions, hash_table *ht_out_regions, void *key_value)
Compute internal distribution context for statement externalized_code.
#define gen_context_recurse(start, ctxt, domain_number, flt, rwt)
int gen_consistent_p(gen_chunk *obj)
GEN_CONSISTENT_P dynamically checks the type correctness of OBJ.
void reset_current_module_entity(void)
Reset the current module entity.
void reset_current_module_statement(void)
Reset the current module statement.
statement set_current_module_statement(statement)
Set the current module statement.
entity set_current_module_entity(entity)
static.c
entity get_current_module_entity(void)
Get the entity of the current module.
void replace_reference(void *s, reference old, entity new)
Replace an old reference by a reference to a new entity in a statement.
bool gen_true2(__attribute__((unused)) gen_chunk *u1, __attribute__((unused)) void *u2)
list gen_nreverse(list cp)
reverse a list in place
void gen_remove(list *cpp, const void *o)
remove all occurences of item o from list *cpp, which is thus modified.
#define NIL
The empty list (nil in Lisp)
list gen_copy_seq(list l)
Copy a list structure.
size_t gen_length(const list l)
#define CONS(_t_, _i_, _l_)
List element cell constructor (insert an element at the beginning of a list)
gen_chunk gen_nth(int n, const list l)
to be used as ENTITY(gen_nth(3, l))...
#define MAP(_map_CASTER, _map_item, _map_code, _map_list)
Apply/map an instruction block on all the elements of a list (old fashioned)
void gen_sort_list(list l, gen_cmp_func_t compare)
Sorts a list of gen_chunks in place, to avoid allocations...
string db_get_memory_resource(const char *rname, const char *oname, bool pure)
Return the pointer to the resource, whatever it is.
#define DB_PUT_MEMORY_RESOURCE(res_name, own_name, res_val)
conform to old interface.
bool statement_with_empty_comment_p(statement)
Return true if the statement has an empty statement:
hash_table hash_table_make(hash_key_type key_type, size_t size)
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.
void hash_put(hash_table htp, const void *key, const void *val)
This functions stores a couple (key,val) in the hash table pointed to by htp.
void hash_table_free(hash_table htp)
this function deletes a hash table that is no longer useful.
bool hash_defined_p(const hash_table htp, const void *key)
true if key has e value in htp.
bool add_new_module(const char *module_name, entity module, statement stat, bool is_fortran)
Add the new resource files associated to a module with its more-or-less correct code.
bool prettyprint_language_is_fortran_p()
#define pips_debug
these macros use the GNU extensions that allow variadic macros, including with an empty list.
#define pips_user_warning
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
#define pips_internal_error
#define DYNAMIC_AREA_LOCAL_NAME
#define MODULE_SEP_STRING
string concatenate(const char *,...)
Return the concatenation of the given strings.
#define HASH_MAP(k, v, code, ht)
void * gen_find_tabulated(const char *, int)
int(* gen_cmp_func_t)(const void *, const void *)
#define EXTERNALIZED_CODE_PRAGMA_CALL
#define EXTERNALIZED_FUNCTION_PRIVATE_PARAM_NAME
#define EXTERNALIZED_FUNCTION_PARAM_NAME
Stuff for distribution controlization.
void print_reference(reference r)
void print_statement(statement)
Print a statement on stderr.
void set_bool_property(const char *, bool)
bool module_reorder(statement body)
Reorder a module and recompute order to statement if any.
#define make_entity(n, t, s, i)
#define module_language(e)
implemented as a macro to allow lhs
#define module_functional_parameters(func)
const char * entity_user_name(entity e)
Since entity_local_name may contain PIPS special characters such as prefixes (label,...
entity FindEntity(const char *package, const char *name)
Retrieve an entity from its package/module name and its local name.
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...
entity FindOrCreateEntity(const char *package, const char *local_name)
Problem: A functional global entity may be referenced without parenthesis or CALL keyword in a functi...
bool same_entity_p(entity e1, entity e2)
predicates on entities
string entity_global_name(entity e)
Used instead of the macro to pass as formal argument.
entity module_name_to_entity(const char *mn)
This is an alias for local_name_to_top_level_entity.
entity make_empty_subroutine(const char *name, language l)
entity entity_empty_label(void)
const char * module_local_name(entity e)
Returns the module local user name.
bool entity_module_p(entity e)
expression make_entity_expression(entity e, cons *inds)
int add_variable_to_area(entity, entity)
#define REFERENCE(x)
REFERENCE.
#define reference_variable(x)
#define statement_ordering(x)
#define entity_storage(x)
#define statement_domain
newgen_sizeofexpression_domain_defined
#define code_declarations(x)
#define EXPRESSION(x)
EXPRESSION.
#define entity_undefined_p(x)
@ is_instruction_sequence
#define instruction_tag(x)
#define PARAMETER(x)
PARAMETER.
#define sequence_statements(x)
#define statement_extensions(x)
#define instruction_sequence(x)
#define statement_instruction(x)
#define statement_comments(x)
#define statement_number(x)
#define entity_domain
newgen_syntax_domain_defined
#define variable_basic(x)
#define STATEMENT(x)
STATEMENT.
#define storage_undefined
#define entity_initial(x)
#define EXTERNALIZED_CODE_PRAGMA_ANALYZED_TOP
char * variable_name(Variable v)
polynome_ri.c
void module_to_value_mappings(entity m)
void module_to_value_mappings(entity m): build hash tables between variables and values (old,...
The structure used to build lists in NewGen.
A gen_chunk is used to store every object.
list module_declarations(entity m)
High-level functions about modules, using pipsdbm and ri-util and some global variables assumed prope...