27 #if defined(BUILDER_CLONE) || \
28 defined(BUILDER_CLONE_ONLY) || \
29 defined(BUILDER_CLONE_ON_ARGUMENT) || \
30 defined(BUILDER_CLONE_SUBSTITUTE)
33 #include "pips_config.h"
65 #define DEBUG_ON debug_on("CLONE_DEBUG_LEVEL")
66 #define ALL_DECLS "PRETTYPRINT_ALL_DECLARATIONS"
67 #define STAT_ORDER "PRETTYPRINT_STATEMENT_NUMBER"
68 #define undefined_number_p(n) ((n)==STATEMENT_NUMBER_UNDEFINED)
77 build_statement_for_clone(
99 "!! PIPS: " :
"// PIPS: ",
101 " is assumed a constant reaching value\n", NULL));
122 char* comments, *new_name;
125 bool saved_b1, saved_b2;
132 pips_debug(2,
"building a version of %s with arg %d val=%d\n",
144 size = strlen(name) + strlen(suffix) + 1;
145 new_name = (
char*)
malloc(
sizeof(
char)*size);
147 new_name = strcat(new_name, name);
148 new_name = strcat(new_name,
"_");
149 new_name = strcat(new_name, suffix);
162 stat = build_statement_for_clone(cloned, argn, val);
174 comment_prefix,
" PIPS: please caution!\n",
176 comment_prefix,
" this routine has been generated as a clone of ", name,
"\n",
177 comment_prefix,
" the code may change significantly with respect to the original\n",
178 comment_prefix,
" version, especially after program transformations such as dead\n",
179 comment_prefix,
" code elimination and partial evaluation, hence the function may\n",
180 comment_prefix,
" not have the initial behavior, if called under some other context.\n",
181 comment_prefix,
"\n", NULL));
214 static int clones_index = 0 , clones_size = 0;
215 static clone_t * clones = (clone_t*) NULL;
217 #define INITIALIZED pips_assert("clones initialized", clones && clones_size>0)
222 pips_assert(
"clones undefined", clones==NULL && clones_size==0);
225 clones = (clone_t*)
malloc(
sizeof(clone_t)*clones_size);
233 free(clones), clones = NULL;
239 get_clone(
entity the_ref,
int argn,
int val)
244 for (i=0; i<clones_index; i++)
246 if (clones[i].the_ref == the_ref &&
247 clones[i].argn == argn &&
248 clones[i].val == val)
249 return clones[i].the_clone;
255 set_clone(
entity the_ref,
entity the_clone,
int argn,
int val)
261 if (clones_index==clones_size)
264 clones = (clone_t*) realloc(clones,
sizeof(clone_t)*clones_size);
268 clones[clones_index].the_ref = the_ref;
269 clones[clones_index].the_clone = the_clone;
270 clones[clones_index].argn = argn;
271 clones[clones_index].val = val;
284 static int argument_to_clone = 0;
287 static bool some_cloning_performed =
false;
289 static void clone_error_handler()
291 error_reset_stmt_stack();
293 argument_to_clone = 0;
296 some_cloning_performed =
false;
302 this_expression_constant_p(
333 prec = sc_projection_optim_along_vecteur(prec, b);
339 else pips_debug(7,
"not an integer scalar reference\n");
354 else pips_debug(7,
"not a symbolic integer constant\n");
356 else pips_debug(7,
"not a constant nor a reference not a parameter\n");
358 pips_debug(5,
"ok = %s, val = %d\n",
ok?
"TRUE":
"FALSE",
ok? *pval: 0);
371 pips_debug(3,
"%s cloned on argument %d for value %d\n",
378 clonee = get_clone(cloned, argn, val);
381 clonee = build_a_clone_for(cloned, argn, val);
382 if (argn!=0) set_clone(cloned, clonee, argn, val);
386 some_cloning_performed =
true;
399 if (argument_to_clone)
402 if (this_expression_constant_p(nth_arg, &val))
405 else if (!undefined_number_p(statement_to_clone) &&
408 do_clone(c, 0, 0, clonee_to_substitute);
428 (argn!=0 && undefined_number_p(number) &&
430 (argn==0 && !undefined_number_p(number)));
445 argument_to_clone = argn;
446 statement_to_clone = number;
447 clonee_to_substitute = substitute;
448 some_cloning_performed =
false;
461 if (some_cloning_performed)
472 argument_to_clone = 0;
478 return some_cloning_performed;
486 set_currents(
string name)
491 pips_debug(1,
"considering module %s\n", name);
506 reset_currents(
const char* name)
517 is_a_caller_or_error(
526 reset_currents(name);
530 #define invalid_request_result(s) \
531 (!(s) || string_undefined_p((s) || (strlen((s))==0))
534 checked_string_user_request(
535 string fmt,
string arg,
549 checked_int_user_request(
550 string fmt,
string arg,
554 string si = checked_string_user_request(fmt, arg,
error);
556 if (sscanf(si,
"%d", &result)!=1)
568 #define ARG_TO_CLONE "TRANSFORMATION_CLONE_ON_ARGUMENT"
598 argn = checked_int_user_request(
"argument of %s to clone", name,
599 "argument number to clone");
612 reset_currents(name);
624 reset_currents(name);
635 reset_currents(name);
652 clone_or_clone_substitute(
654 bool clone_substitute_p)
665 caller = checked_string_user_request(
"%s caller to update?", name,
669 is_a_caller_or_error(name, caller);
671 number = checked_int_user_request(
672 "statement number of %s to clone?", caller,
673 "statement number to clone");
675 if (clone_substitute_p)
677 string substitute_s =
678 checked_string_user_request(
"replacement for %s?", name,
679 "replacement function");
686 reset_currents(name);
695 okay = perform_clone(
module, caller, 0, number, substitute);
707 reset_currents(name);
714 bool clone(
const string name)
716 return clone_or_clone_substitute(name,
false);
723 return clone_or_clone_substitute(name,
true);
731 clone_current_entity()
747 entity cloned_entity = clone_current_entity();
static void stmt_rewrite(statement s)
int get_int_property(const string)
call make_call(entity a1, list a2)
type copy_type(type p)
TYPE.
statement copy_statement(statement p)
STATEMENT.
value make_value(enum value_utype tag, void *val)
language copy_language(language p)
LANGUAGE.
test make_test(expression a1, statement a2, statement a3)
code make_code(list a1, string a2, sequence a3, list a4, language a5)
storage copy_storage(storage p)
STORAGE.
sequence make_sequence(list a)
void free_statement(statement p)
sentence make_sentence(enum sentence_utype tag, void *val)
#define error(fun, msg)
NewGen interface with C3 type Psysteme for PIPS project.
static reference ref
Current stmt (an integer)
static const char * caller_name
static bool stmt_filter(statement s)
modifies global var current_caller_stmt
#define VALUE_TO_INT(val)
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,...
bool empty_string_p(const char *s)
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....
statement make_block_statement(list)
Make a block statement from a list of statement.
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.
statement get_current_module_statement(void)
Get 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 gen_multi_recurse(void *o,...)
Multi recursion visitor function.
bool gen_true(__attribute__((unused)) gen_chunk *unused)
Return true and ignore the argument.
#define NIL
The empty list (nil in Lisp)
#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)
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.
statement make_continue_statement(entity)
bool expression_constant_p(expression)
HPFC module by Fabien COELHO.
bool add_new_module_from_text(const char *module_name, text code_text, bool is_fortran, const char *compilation_unit_name)
Add the new resource files associated to a module with its more-or-less correct code.
#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
string user_request(const char *,...)
void reset_hooks_unregister(reset_func_t)
remove registered cleanup hook.
void reset_hooks_register(reset_func_t)
reset_hooks.c
#define TOP_LEVEL_MODULE_NAME
Module containing the global variables in Fortran and C.
string concatenate(const char *,...)
Return the concatenation of the given strings.
#define DEFINE_LOCAL_STACK(name, type)
#define same_string_p(s1, s2)
#define string_undefined_p(s)
text text_named_module(entity, entity, statement)
void set_bool_property(const char *, bool)
#define test_to_statement(t)
#define STATEMENT_NUMBER_UNDEFINED
default values
#define call_to_statement(c)
#define module_language(e)
implemented as a macro to allow lhs
#define STOP_FUNCTION_NAME
#define make_statement_list(stats...)
easy list constructor
#define NON_EQUAL_OPERATOR_NAME
const char * entity_user_name(entity e)
Since entity_local_name may contain PIPS special characters such as prefixes (label,...
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...
entity module_name_to_entity(const char *mn)
This is an alias for local_name_to_top_level_entity.
bool fortran_module_p(entity m)
Test if a module is in Fortran.
entity entity_intrinsic(const char *name)
FI: I do not understand this function name (see next one!).
bool expression_call_p(expression e)
int expression_to_int(expression exp)
================================================================
expression entity_to_expression(entity e)
if v is a constant, returns a constant call.
expression MakeBinaryCall(entity f, expression eg, expression ed)
Creates a call expression to a function with 2 arguments.
expression int_to_expression(_int i)
transform an int into an expression and generate the corresponding entity if necessary; it is not cle...
bool expression_reference_p(expression e)
Test if an expression is a reference.
reference expression_reference(expression e)
Short cut, meaningful only if expression_reference_p(e) holds.
string build_new_top_level_module_name(const char *prefix, bool prevent_suffix)
Get a new name for a module built from a prefix.
bool entity_integer_scalar_p(entity)
for variables (like I), not constants (like 1)! use integer_constant_p() for constants
entity find_ith_parameter(entity, int)
#define type_functional_p(x)
struct _newgen_struct_callees_ * callees
#define callees_callees(x)
#define reference_variable(x)
#define symbolic_constant(x)
#define entity_storage(x)
#define statement_domain
newgen_sizeofexpression_domain_defined
#define call_domain
newgen_callees_domain_defined
#define value_symbolic(x)
#define EXPRESSION(x)
EXPRESSION.
#define entity_undefined_p(x)
#define constant_int_p(x)
#define value_symbolic_p(x)
#define transformer_relation(x)
#define variable_dimensions(x)
#define statement_comments(x)
#define call_arguments(x)
#define statement_number(x)
#define expression_syntax(x)
#define type_variable_p(x)
#define predicate_system(x)
#define variable_basic(x)
#define entity_initial(x)
void sc_rm(Psysteme ps)
void sc_rm(Psysteme ps): liberation de l'espace memoire occupe par le systeme de contraintes ps;
Psysteme sc_dup(Psysteme ps)
Psysteme sc_dup(Psysteme ps): should becomes a link.
bool sc_value_of_variable(Psysteme ps, Variable var, Value *pval)
bool sc_value_for_variable(Psysteme ps, Variable var, Value *pval): examine les egalites du systeme p...
transformer load_statement_precondition(statement)
void reset_precondition_map(void)
void set_precondition_map(statement_mapping)
le type des coefficients dans les vecteurs: Value est defini dans le package arithmetique
bool clone_on_argument(const string)
clone.c
bool clone_only(const string)
bool clone_substitute(const string)
#define SENTENCE(x)
newgen_unformatted_domain_defined
#define text_sentences(x)
void * Variable
arithmetique is a requirement for vecteur, but I do not want to inforce it in all pips files....
Pbase base_dup(Pbase b)
Pbase base_dup(Pbase b) Note: this function changes the value of the pointer.
void vect_erase_var(Pvecteur *ppv, Variable v)
void vect_erase_var(Pvecteur * ppv, Variable v): projection du vecteur *ppv selon la direction v (i....
void AddEntityToModuleCompilationUnit(entity e, entity module)