35 #include "pips_config.h"
51 #include "resources.h"
84 #define IPARAM_INIT { \
85 ._inlined_module_=entity_undefined,\
86 ._inlined_module_statement_=statement_undefined,\
87 ._new_statements_=statement_undefined,\
88 ._has_static_declaration_=false,\
89 ._has_inlinable_calls_=false,\
90 ._laststmt_=statement_undefined,\
91 ._tail_ins_=instruction_undefined,\
92 ._returned_entity_=entity_undefined,\
95 #define inlined_module(p) (p)->_inlined_module_
96 #define inlined_module_statement(p) (p)->_inlined_module_statement_
97 #define new_statements(p) (p)->_new_statements_
98 #define has_static_declaration(p) (p)->_has_static_declaration_
99 #define has_inlinable_calls(p) (p)->_has_inlinable_calls_
100 #define laststmt(p) (p)->_laststmt_
101 #define tail_ins(p) (p)->_tail_ins_
102 #define returned_entity(p) (p)->_returned_entity_
103 #define use_effects(p) (p)->_use_effects_
182 CAR(l).p = (
void*)solve_clash;
263 static const unsigned int magic_block_number = (
unsigned int)-1;
272 const char* eprefix =
strndup(ename,euname-ename);
361 set_free(inlined_referenced_entities);
402 bool did_something =
false;
516 pips_assert(
"function call has enough arguments",n1 >= n2);
565 bool add_dereferencment =
false;
573 if( nb_indices == 0 )
589 add_dereferencment=
true;
637 add_dereferencment=
true;
676 for(
list iter = new_old_pairs;!
ENDP(iter);
POP(iter)) {
695 pips_debug(2,
"inlined statement after substitution\n");
698 return declaration_holder;
797 pips_debug(2,
"updated statement instruction\n");
825 if( !
ENDP(prelude) ||
841 pips_user_warning(
"only blocks and declaration statements should have declarations\n");
914 for(c_name = strtok(inlining_callers_name,
" ") ; c_name ; c_name=strtok(NULL,
" ") )
1003 "this should be a generated skeleton ...\n",
1040 list filtersname =
strsplit(unfolding_filter_names,
" ");
1052 string callee_name= NULL;
1053 for(callee_name = strtok(unfolding_callees_names,
" ") ; callee_name ; callee_name=strtok(NULL,
" ") )
1059 bool statement_has_callee =
false;
1061 statement_has_callee =
false;
1075 calls_name=
set_difference(calls_name,calls_name,unfolding_filters);
1080 if( (statement_has_callee=!
set_empty_p(calls_name)) )
1093 pips_user_warning(
"failed to remove useless labels after restructure_control in inlining");
1098 }
while(statement_has_callee);
1101 free(unfolding_filter_names);
instruction copy_instruction(instruction p)
INSTRUCTION.
call make_call(entity a1, list a2)
value make_value_unknown(void)
value make_value_expression(expression _field_)
syntax make_syntax_call(call _field_)
type copy_type(type p)
TYPE.
basic copy_basic(basic p)
BASIC.
instruction make_instruction_expression(expression _field_)
void free_callees(callees p)
expression copy_expression(expression p)
EXPRESSION.
statement copy_statement(statement p)
STATEMENT.
reference make_reference(entity a1, list a2)
bool statement_consistent_p(statement p)
test make_test(expression a1, statement a2, statement a3)
instruction make_instruction_sequence(sequence _field_)
instruction make_instruction_test(test _field_)
value copy_value(value p)
VALUE.
bool expression_consistent_p(expression p)
call copy_call(call p)
CALL.
void free_expression(expression p)
storage copy_storage(storage p)
STORAGE.
entity copy_entity(entity p)
ENTITY.
sequence make_sequence(list a)
instruction make_instruction_goto(statement _field_)
syntax make_syntax_reference(reference _field_)
bool db_resource_p(const char *rname, const char *oname)
true if exists and in loaded or stored state.
struct _newgen_struct_entity_ * entity
static const char * caller_name
void const char const char const int
callees compute_callees(const statement stat)
Recompute the callees of a module statement.
struct _newgen_struct_statement_ * statement
string compilation_unit_of_module(const char *)
The output is undefined if the module is referenced but not defined in the workspace,...
void set_cumulated_rw_effects(statement_effects)
bool find_write_effect_on_entity(statement, entity)
void reset_cumulated_rw_effects(void)
bool empty_string_p(const char *s)
const char * module_name(const char *s)
Return the module part of an entity name.
char * get_string_property(const char *)
bool get_bool_property(const string)
FC 2015-07-20: yuk, moved out to prevent an include cycle dependency include "properties....
#define gen_context_recurse(start, ctxt, domain_number, flt, rwt)
#define gen_recurse(start, domain_number, flt, rwt)
statement make_block_statement(list)
Make a block statement from a list of statement.
statement instruction_to_statement(instruction)
Build a statement from a give instruction.
statement make_empty_block_statement(void)
Build an empty statement (block/sequence)
void reset_current_module_entity(void)
Reset the current module entity.
void reset_current_module_statement(void)
Reset the current module statement.
const char * get_current_module_name(void)
Get the name of the current module.
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_entities(void *s, hash_table ht)
Recursively substitute a set of entities in a statement.
void replace_entity(void *s, entity old, entity new)
per variable version of replace_entities.
void replace_entity_by_expression(void *s, entity ent, expression exp)
replace all reference to entity ent by expression exp in s.
void gen_recurse_stop(void *obj)
Tells the recursion not to go in this object.
gen_chunk * gen_get_ancestor(int, const void *)
return the first ancestor object found of the given type.
bool gen_true2(__attribute__((unused)) gen_chunk *u1, __attribute__((unused)) void *u2)
bool gen_true(__attribute__((unused)) gen_chunk *unused)
Return true and ignore the argument.
#define ENDP(l)
Test if a list is empty.
#define POP(l)
Modify a list pointer to point on the next element of the list.
void gen_remove_once(list *pl, const void *o)
Remove the first occurence of o in list pl:
#define REFCAR(pc)
Get the adress of the first element of a list.
#define NIL
The empty list (nil in Lisp)
void gen_map(gen_iter_func_t fp, const list l)
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)
#define CAR(pcons)
Get the value of the first element of a list.
void gen_free_list(list l)
free the spine of the list
list gen_last(list l)
Return the last element of a list.
#define FOREACH(_fe_CASTER, _fe_item, _fe_list)
Apply/map an instruction block on all the elements of a list.
#define CDR(pcons)
Get the list less its first element.
list gen_append(list l1, const list l2)
list gen_full_copy_list(list l)
Copy a list structure with element copy.
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.
list statement_block(statement)
Get the list of block statements of a statement sequence.
loop statement_loop(statement)
Get the loop of a statement.
call statement_call(statement)
Get the call of a statement.
bool statement_loop_p(statement)
statement make_assign_statement(expression, expression)
void insert_comments_to_statement(statement, const char *)
Insert a comment string (if non empty) at the beginning of the comments of a statement.
statement update_statement_instruction(statement, instruction)
Replace the instruction in statement s by instruction i.
bool return_statement_p(statement)
Test if a statement is a C or Fortran "return".
bool continue_statement_p(statement)
Test if a statement is a CONTINUE, that is the FORTRAN nop, the ";" in C or the "pass" in Python....
void insert_statement(statement, statement, bool)
This is the normal entry point.
statement make_continue_statement(entity)
void fix_statement_attributes_if_sequence(statement)
Apply fix_sequence_statement_attributes() on the statement only if it really a sequence.
bool declaration_statement_p(statement)
Had to be optimized according to Beatrice Creusillet.
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 expression_constant_p(expression)
HPFC module by Fabien COELHO.
#define inlined_module(p)
static void inline_return_crawler(statement s, inlining_parameters p)
replace return instruction by an assignment and a goto
static bool inline_has_inlinable_calls(entity inlined_module, void *elem)
#define has_inlinable_calls(p)
static void do_slightly_rename_entities(statement s, hash_table old_new)
static void inline_has_inlinable_calls_crawler(call callee, inlining_parameters p)
check if a call has inlinable calls
static bool inline_should_inline(entity inlined_module, call callee)
helper function to check if a call is a call to the inlined function
static entity make_temporary_scalar_entity(expression from, statement *assign)
create a scalar similar to ‘efrom’ initialized with expression ‘from’
static void inline_split_declarations(statement s, entity inlined_module)
split the declarations from s from their initialization if they contain a call to inlined_module
static void solve_name_clashes(statement s, entity new)
look for entity locally named has ‘new’ in statements ‘s’ when found, find a new name and perform sub...
#define returned_entity(p)
static void statement_with_static_declarations_p(statement s, inlining_parameters p)
return true if an entity declared in the statement ‘s’ from ‘p->inlined_module’
bool unfolding(char *module_name)
perform unfolding using effect
static bool has_similar_entity(entity e, set se)
static statement expanded
static void inline_calls(inlining_parameters p, char *module)
this should replace all call to ‘inlined’ in ‘module’ by the expansion of ‘inlined’
bool has_entity_with_same_name(entity e, list l)
inlining.c
static bool do_inlining(inlining_parameters p, const char *module_name)
this should inline all calls to module ‘module_name’ in calling modules, if possible ....
static void inlining_regenerate_labels(statement s, entity new_module)
regenerate the label of each statement with a label.
static statement inline_expression_call(inlining_parameters p, expression modified_expression, call callee)
this should inline the call callee calling module inlined_module
bool inlining_simple(const char *module_name)
perform inlining without using effects
bool unfolding_simple(char *module_name)
perform unfolding without using effects
static void inline_statement_crawler(statement stmt, inlining_parameters p)
this is in charge of replacing instruction by new ones only apply if this instruction does not contai...
struct iparam * inlining_parameters
static void inline_return_remover(statement s, inlining_parameters p)
replace return instruction by a goto
bool inlining(const char *module_name)
perform inlining using effects
#define inlined_module_statement(p)
static bool inline_has_static_declaration(list iter)
return true if an entity declared in ‘iter’ is static to ‘module’
#define has_static_declaration(p)
static bool run_inlining(string caller_name, const char *module_name, inlining_parameters p)
get ressources for the call to inline and call apropriate inlining function
static void slightly_rename_entities(statement s)
sg: this is another inlining mostruosity it ensures all entities in s have new pointer and different ...
static bool do_unfolding(inlining_parameters p, char *module_name)
this should inline all call in module ‘module_name’ it does not works recursievly,...
static void inline_expression(expression expr, inlining_parameters p)
recursievly inline an expression if needed
#define new_statements(p)
struct _newgen_struct_control_ * control
#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 BLOCK_SEP_STRING
Scope separator.
list strsplit(const char *, const char *)
int gen_qsort_string_cmp(const void *, const void *)
Callback for sorting string with qsort.
#define HASH_UNDEFINED_VALUE
value returned by hash_get() when the key is not found; could also be called HASH_KEY_NOT_FOUND,...
#define HASH_FOREACH(key_type, k, value_type, v, ht)
#define HASH_DEFAULT_SIZE
#define same_string_p(s1, s2)
bool set_empty_p(const set)
tell whether set s is empty.
set set_assign_list(set, const list)
assigns a list contents to a set all duplicated elements are lost
set set_intersection(set, const set, const set)
list set_to_sorted_list(const set, gen_cmp_func_t)
set set_difference(set, const set, const set)
#define SET_FOREACH(type_name, the_item, the_set)
enumerate set elements in their internal order.
set set_make(set_type)
Create an empty set of any type but hash_private.
set set_add_element(set, const set, const void *)
int(* gen_cmp_func_t)(const void *, const void *)
void unnormalize_expression(void *st)
void unnormalize_expression(expression exp): puts all the normalized field of expressions in "st" to ...
bool recompile_module(const string module)
build a textual representation of the modified module and update db
void print_statement(statement)
Print a statement on stderr.
bool same_entity_lname_p(entity, entity)
#define statement_block_p(stat)
#define DEREFERENCING_OPERATOR_NAME
#define entity_declarations(e)
MISC: newgen shorthands.
#define ADDRESS_OF_OPERATOR_NAME
#define entity_variable_p(e)
An entity_variable_p(e) may hide a typedef and hence a functional type.
#define make_statement_list(stats...)
easy list constructor
#define entity_constant_p(e)
bool entity_area_p(entity e)
const char * entity_user_name(entity e)
Since entity_local_name may contain PIPS special characters such as prefixes (label,...
bool entity_enum_member_p(entity e)
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...
int compare_entities(const entity *pe1, const entity *pe2)
Comparison function for qsort.
bool entity_formal_p(entity p)
is p a formal parameter?
bool entity_subroutine_p(entity e)
bool c_module_p(entity m)
Test if a module "m" is written in C.
code entity_code(entity e)
entity module_name_to_entity(const char *mn)
This is an alias for local_name_to_top_level_entity.
bool extern_entity_p(entity module, entity e)
bool entity_function_p(entity e)
basic entity_basic(entity e)
return the basic associated to entity e if it's a function/variable/constant basic_undefined otherwis...
bool entity_field_p(entity e)
e is the field of a structure
const char * module_local_name(entity e)
Returns the module local user name.
bool entity_empty_label_p(entity e)
bool same_entity_name_p(entity e1, entity e2)
compare entity names
entity make_new_label(entity module)
This function returns a new label.
const char * entity_module_name(entity e)
See comments about module_name().
bool entity_pointer_p(entity e)
entity entity_field_to_entity_struct_or_union(entity f)
set get_referenced_entities(void *elem)
retrieves the set of entities used in elem beware that this entities may be formal parameters,...
entity entity_intrinsic(const char *name)
FI: I do not understand this function name (see next one!).
const char * label_local_name(entity e)
END_EOLE.
bool expression_call_p(expression e)
expression entity_to_expression(entity e)
if v is a constant, returns a constant call.
expression int_to_expression(_int i)
transform an int into an expression and generate the corresponding entity if necessary; it is not cle...
expression MakeUnaryCall(entity f, expression a)
Creates a call expression to a function with one argument.
expression call_to_expression(call c)
Build an expression that call a function or procedure.
list module_formal_parameters(entity func)
list module_formal_parameters(entity func) input : an entity representing a function.
void AddLocalEntityToDeclarations(entity, entity, statement)
Add the variable entity e to the list of variables of the function module.
bool entity_scalar_p(entity)
The concrete type of e is a scalar type.
entity make_new_array_variable_with_prefix(const char *, entity, basic, list)
J'ai ameliore la fonction make_new_scalar_variable_with_prefix
entity make_new_scalar_variable(entity, basic)
bool variable_entity_p(entity)
variable.c
entity make_temporary_pointer_to_array_entity(entity, expression, entity)
void AddEntityToDeclarations(entity, entity)
END_EOLE.
basic some_basic_of_any_expression(expression, bool, bool)
basic basic_of_any_expression(expression exp, bool apply_p): Makes a basic of the same basic as the e...
void AddEntityToCurrentModule(entity)
Add a variable entity to the current module declarations.
bool formal_parameter_p(entity)
entity make_new_scalar_variable_with_prefix(const char *, entity, basic)
Create a new scalar variable of type b in the given module.
entity find_label_entity(const char *, const char *)
util.c
bool implicit_c_variable_p(entity)
entity make_global_entity_from_local(entity)
bool variable_static_p(entity)
true if v appears in a SAVE statement, or in a DATA statement, or is declared static i C.
#define value_undefined_p(x)
struct _newgen_struct_callees_ * callees
#define expression_domain
newgen_execution_domain_defined
#define functional_result(x)
#define syntax_reference(x)
#define callees_callees(x)
#define reference_variable(x)
#define type_functional(x)
#define entity_storage(x)
#define statement_domain
newgen_sizeofexpression_domain_defined
#define control_domain
newgen_controlmap_domain_defined
#define code_declarations(x)
@ is_syntax_sizeofexpression
#define call_domain
newgen_callees_domain_defined
#define EXPRESSION(x)
EXPRESSION.
#define cast_expression(x)
#define statement_label(x)
#define entity_undefined_p(x)
#define expression_undefined
#define sequence_statements(x)
#define reference_indices(x)
#define instruction_sequence(x)
#define instruction_call_p(x)
#define expression_undefined_p(x)
#define variable_dimensions(x)
#define code_decls_text(x)
#define statement_declarations(x)
#define statement_instruction(x)
#define instruction_call(x)
#define call_arguments(x)
#define statement_undefined_p(x)
#define value_expression_p(x)
#define expression_syntax(x)
#define type_variable_p(x)
#define value_expression(x)
#define variable_basic(x)
#define statement_undefined
#define STATEMENT(x)
STATEMENT.
#define entity_initial(x)
char * strndup(char const *s, size_t n)
A replacement function, for systems that lack strndup.
FI: I do not understand why the type is duplicated at the set level.
The structure used to build lists in NewGen.
structure containing all the parameters needed by inlining.
statement _new_statements_
bool _has_inlinable_calls_
statement _inlined_module_statement_
bool _has_static_declaration_
void AddEntityToModuleCompilationUnit(entity e, entity module)