PIPS
outlining.c File Reference

add outlining support to pips, with two flavors More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "genC.h"
#include "linear.h"
#include "ri.h"
#include "effects.h"
#include "ri-util.h"
#include "prettyprint.h"
#include "effects-util.h"
#include "text.h"
#include "pipsdbm.h"
#include "syntheses.h"
#include "pipsmake.h"
#include "resources.h"
#include "properties.h"
#include "misc.h"
#include "control.h"
#include "callgraph.h"
#include "effects-generic.h"
#include "effects-convex.h"
#include "preprocessor.h"
#include "expressions.h"
#include "text-util.h"
#include "parser_private.h"
#include "accel-util.h"
#include "transformations.h"
+ Include dependency graph for outlining.c:

Go to the source code of this file.

Data Structures

struct  cpv
 
struct  ocontext_t
 

outlining

#define STAT_ORDER   "PRETTYPRINT_STATEMENT_NUMBER"
 
static string outlining_variable_commenter (__attribute__((unused)) entity e)
 
static string outlining_patched_variable_commenter (__attribute__((unused)) entity e)
 
static void get_loop_locals_and_remove_walker (statement st, set s)
 
static set get_loop_locals_and_remove (statement st)
 
static set get_private_entities (statement st)
 try hard to reproduce in / out regions with only loop_locals it is time to move to regions ... More...
 
static bool skip_values (void *v)
 
static bool skip_constants_intrinsics_members (entity e)
 
static void sort_entities_with_dep (list *l)
 
static void check_private_variables_call_walker (call c, struct cpv *p)
 
static bool check_private_variables_loop_walker (loop l, struct cpv *p)
 
static list private_variables (statement stat)
 
static void do_outliner_smart_replacment (reference r, ocontext_t *ctxt)
 
static void outliner_smart_replacment (statement in, entity old, entity new, size_t nb_dims)
 
list outliner_statements_referenced_entities (list statements)
 outlining.c More...
 
static hash_table outliner_smart_references_computation (list outlined_statements, entity new_module)
 purge the list of referenced entities by replacing calls to a[i][j] where i is a constant in statements outlined_statements by a call to a single (new) variable More...
 
static list statements_localize_declarations (list statements, entity module, statement module_statement)
 
static void outliner_extract_loop_bound (statement sloop, hash_table entity_to_effective_parameter)
 
static void convert_pointer_to_array_aux (expression exp, entity e)
 
static void convert_pointer_to_array_aux2 (statement s, entity e)
 
static void convert_pointer_to_array (entity e, entity re, expression x, list statements)
 
static void outline_remove_duplicates (list *entities)
 
hash_table outliner_init (entity new_fun, list statements_to_outline)
 
list outliner_scan (entity new_fun, list statements_to_outline, statement new_body)
 
static type type_to_named_type (type t, entity cu)
 create a new type from given type, eventually renaming unnamed structures inside all new entities generated in the process are added to cu More...
 
bool is_entity_in_list (entity e, list l)
 Checks if an entity is in a list. More...
 
void outliner_parameters (entity new_fun, statement new_body, list referenced_entities, hash_table entity_to_effective_parameter, list *effective_parameters_, list *formal_parameters_)
 
void outliner_patch_parameters (list statements_to_outline, list referenced_entities, list effective_parameters, list formal_parameters, statement new_body, statement begin, statement end)
 we need to patch parameters , effective parameters and body in C because parameters are passed by copy in function call it's not needed if More...
 
static void do_remove_entity_from_private (loop l, entity e)
 
static void do_remove_entity_from_decl (statement s, entity e)
 
static void outliner_compilation_unit (entity new_fun, list formal_parameters __attribute__((unused)))
 
static bool entity_not_undefined_nor_constant_nor_intrinsic_p (entity e)
 
static bool anonymous_type_p (entity e)
 skipping anonymous enum ... More...
 
static entity recursive_rename_types (entity e, const char *cun)
 
static void outliner_independent_recursively (entity module, const char *cun, statement s)
 
static void outliner_independent (const char *module_name, statement body)
 redeclare all callees of outlined function in the same compilation unit More...
 
void outliner_file (entity new_fun, list formal_parameters, statement *new_body)
 
statement outliner_call (entity new_fun, list statements_to_outline, list effective_parameters)
 
void remove_from_formal_parameters (list induction_var, list *formal_parameters)
 
void remove_from_effective_parameters (list induction_var, list *effective_parameters)
 
void add_induction_var_to_local_declarations (statement *new_body, list induction_var)
 
statement outliner (const char *outline_module_name, list statements_to_outline)
 outline the statements in statements_to_outline into a module named outline_module_name the outlined statements are replaced by a call to the newly generated module statements_to_outline is modified in place to represent that call More...
 
bool outline (const string module_name)
 entry point for outline module outlining will be performed using either comment recognition or interactively More...
 

Detailed Description

add outlining support to pips, with two flavors

Author
Serge Guelton serge.nosp@m..gue.nosp@m.lton@.nosp@m.enst.nosp@m.-bret.nosp@m.agne.nosp@m..fr
Date
2009-01-07

Definition in file outlining.c.

Macro Definition Documentation

◆ STAT_ORDER

#define STAT_ORDER   "PRETTYPRINT_STATEMENT_NUMBER"

Definition at line 75 of file outlining.c.

Function Documentation

◆ add_induction_var_to_local_declarations()

void add_induction_var_to_local_declarations ( statement new_body,
list  induction_var 
)
Parameters
new_bodyew_body
induction_varnduction_var

Definition at line 1307 of file outlining.c.

1307  {
1309  FOREACH(entity, ent, induction_var) {
1310  *new_body = add_declaration_statement(*new_body, ent);
1311  }
1313 }
#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 pop_generated_variable_commenter(void)
Definition: statement.c:2623
statement add_declaration_statement(statement, entity)
Definition: statement.c:2790
void push_generated_variable_commenter(string(*)(entity))
Definition: statement.c:2616
static string outlining_variable_commenter(__attribute__((unused)) entity e)
Definition: outlining.c:65

References add_declaration_statement(), FOREACH, outlining_variable_commenter(), pop_generated_variable_commenter(), and push_generated_variable_commenter().

Referenced by outliner_parameters().

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

◆ anonymous_type_p()

static bool anonymous_type_p ( entity  e)
static

skipping anonymous enum ...

Definition at line 943 of file outlining.c.

943  {
944  const char * eln = entity_local_name(e);
945  return strstr(eln, DUMMY_STRUCT_PREFIX) || strstr(eln, DUMMY_UNION_PREFIX);
946 }
#define DUMMY_STRUCT_PREFIX
Definition: naming-local.h:87
#define DUMMY_UNION_PREFIX
Definition: naming-local.h:88
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

References DUMMY_STRUCT_PREFIX, DUMMY_UNION_PREFIX, and entity_local_name().

Referenced by outliner_independent_recursively().

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

◆ check_private_variables_call_walker()

static void check_private_variables_call_walker ( call  c,
struct cpv p 
)
static

Definition at line 169 of file outlining.c.

170 {
172  if(set_belong_p(s,p->e)){
173  p->rm=true;
174  gen_recurse_stop(0);
175  }
176  set_free(s);
177 }
void gen_recurse_stop(void *obj)
Tells the recursion not to go in this object.
Definition: genClib.c:3251
void set_free(set)
Definition: set.c:332
bool set_belong_p(const set, const void *)
Definition: set.c:194
set get_referenced_entities(void *elem)
retrieves the set of entities used in elem beware that this entities may be formal parameters,...
Definition: entity.c:3063
FI: I do not understand why the type is duplicated at the set level.
Definition: set.c:59
entity e
Definition: outlining.c:163
bool rm
Definition: outlining.c:164

References cpv::e, gen_recurse_stop(), get_referenced_entities(), cpv::rm, set_belong_p(), and set_free().

Referenced by private_variables().

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

◆ check_private_variables_loop_walker()

static bool check_private_variables_loop_walker ( loop  l,
struct cpv p 
)
static

Definition at line 179 of file outlining.c.

180 {
181  return !has_entity_with_same_name(p->e,loop_locals(l));
182 }
bool has_entity_with_same_name(entity, list)
inlining.c
Definition: inlining.c:256
#define loop_locals(x)
Definition: ri.h:1650

References cpv::e, has_entity_with_same_name(), and loop_locals.

Referenced by private_variables().

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

◆ convert_pointer_to_array()

static void convert_pointer_to_array ( entity  e,
entity  re,
expression  x,
list  statements 
)
static

crado

Definition at line 494 of file outlining.c.

494  {
495  type t =entity_type(e);
498  type_variable(t)
499  )
500  );
503  type_variable(t)
504  )
505  )=type_undefined;
506  free_type(t);
508  FOREACH(STATEMENT,s,statements) {
511  NULL);
513  }
514 
515  /* crado */
516  syntax syn = expression_syntax(x);
519  make_call(
524  ),
525  NIL)
526  )
527  );
529 }
call make_call(entity a1, list a2)
Definition: ri.c:269
syntax make_syntax_call(call _field_)
Definition: ri.c:2500
expression make_expression(syntax a1, normalized a2)
Definition: ri.c:886
void free_type(type p)
Definition: ri.c:2658
void cleanup_subscripts(void *)
void gen_context_multi_recurse(void *o, void *context,...)
Multi-recursion with context function visitor.
Definition: genClib.c:3373
bool gen_true(__attribute__((unused)) gen_chunk *unused)
Return true and ignore the argument.
Definition: genClib.c:2780
#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
static void convert_pointer_to_array_aux2(statement s, entity e)
Definition: outlining.c:489
static void convert_pointer_to_array_aux(expression exp, entity e)
Definition: outlining.c:469
#define DEREFERENCING_OPERATOR_NAME
Definition: ri-util-local.h:93
entity entity_intrinsic(const char *name)
FI: I do not understand this function name (see next one!).
Definition: entity.c:1292
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
type pointed_type(type)
returns the type pointed by the input type if it is a pointer or an array of pointers
Definition: type.c:3035
#define basic_pointer(x)
Definition: ri.h:637
#define normalized_undefined
Definition: ri.h:1745
#define expression_domain
newgen_execution_domain_defined
Definition: ri.h:154
#define type_variable(x)
Definition: ri.h:2949
#define statement_domain
newgen_sizeofexpression_domain_defined
Definition: ri.h:362
#define EXPRESSION(x)
EXPRESSION.
Definition: ri.h:1217
#define syntax_undefined
Definition: ri.h:2676
#define type_undefined
Definition: ri.h:2883
#define entity_type(x)
Definition: ri.h:2792
#define expression_syntax(x)
Definition: ri.h:1247
#define variable_basic(x)
Definition: ri.h:3120
#define STATEMENT(x)
STATEMENT.
Definition: ri.h:2413
static char * x
Definition: split_file.c:159

References basic_pointer, cleanup_subscripts(), CONS, convert_pointer_to_array_aux(), convert_pointer_to_array_aux2(), DEREFERENCING_OPERATOR_NAME, entity_intrinsic(), entity_type, EXPRESSION, expression_domain, expression_syntax, FOREACH, free_type(), gen_context_multi_recurse(), gen_true(), make_call(), make_expression(), make_syntax_call(), NIL, normalized_undefined, pointed_type(), STATEMENT, statement_domain, syntax_undefined, type_undefined, type_variable, update_expression_syntax(), variable_basic, and x.

Referenced by outliner_patch_parameters().

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

◆ convert_pointer_to_array_aux()

static void convert_pointer_to_array_aux ( expression  exp,
entity  e 
)
static

Definition at line 469 of file outlining.c.

469  {
476  make_call(
481  ),
482  NIL)
483  )
484  );
486  }
487  }
488 }
#define ADDRESS_OF_OPERATOR_NAME
bool same_entity_p(entity e1, entity e2)
predicates on entities
Definition: entity.c:1321
bool expression_reference_p(expression e)
Test if an expression is a reference.
Definition: expression.c:528
reference expression_reference(expression e)
Short cut, meaningful only if expression_reference_p(e) holds.
Definition: expression.c:1832
#define reference_variable(x)
Definition: ri.h:2326
#define exp
Avoid some warnings from "gcc -Wshadow".
Definition: vasnprintf.c:207

References ADDRESS_OF_OPERATOR_NAME, CONS, entity_intrinsic(), exp, EXPRESSION, expression_reference(), expression_reference_p(), expression_syntax, make_call(), make_expression(), make_syntax_call(), NIL, normalized_undefined, reference_variable, same_entity_p(), syntax_undefined, and update_expression_syntax().

Referenced by convert_pointer_to_array(), and convert_pointer_to_array_aux2().

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

◆ convert_pointer_to_array_aux2()

static void convert_pointer_to_array_aux2 ( statement  s,
entity  e 
)
static

Definition at line 489 of file outlining.c.

489  {
492 }
#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
#define ENTITY(x)
ENTITY.
Definition: ri.h:2755
#define statement_declarations(x)
Definition: ri.h:2460
#define entity_initial(x)
Definition: ri.h:2796

References convert_pointer_to_array_aux(), ENTITY, entity_initial, expression_domain, FOREACH, gen_context_recurse, gen_true2(), and statement_declarations.

Referenced by convert_pointer_to_array().

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

◆ do_outliner_smart_replacment()

static void do_outliner_smart_replacment ( reference  r,
ocontext_t ctxt 
)
static

g:may cause issues if basic_pointer_p(old) ?

Definition at line 209 of file outlining.c.

210 {
211  if(same_entity_p(ctxt->old,reference_variable(r)))
212  {
213  size_t nb_dims = ctxt->nb_dims;
215  while (nb_dims--) POP(indices);
218  unnormalize_expression(parent);
219  if(basic_pointer_p(entity_basic(ctxt->new))) /*sg:may cause issues if basic_pointer_p(old) ? */
220  {
221  pips_assert("parent exist",parent);
222  //free_syntax(expression_syntax(parent)); /* sg a small leak is better than a crash :) */
223  if(!ENDP(indices))
224  expression_syntax(parent)=
228  indices)
229  );
230  else
231  expression_syntax(parent)=
234  );
235 
236  }
237  else {
238  reference_variable(r)=ctxt->new;
241  }
242  }
243 }
subscript make_subscript(expression a1, list a2)
Definition: ri.c:2327
syntax make_syntax_subscript(subscript _field_)
Definition: ri.c:2509
struct _newgen_struct_expression_ * expression
Definition: alias_private.h:21
void gen_full_free_list(list l)
Definition: genClib.c:1023
gen_chunk * gen_get_ancestor(int, const void *)
return the first ancestor object found of the given type.
Definition: genClib.c:3560
#define ENDP(l)
Test if a list is empty.
Definition: newgen_list.h:66
#define POP(l)
Modify a list pointer to point on the next element of the list.
Definition: newgen_list.h:59
list gen_full_copy_list(list l)
Copy a list structure with element copy.
Definition: list.c:535
static list indices
Definition: icm.c:204
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
void unnormalize_expression(void *st)
void unnormalize_expression(expression exp): puts all the normalized field of expressions in "st" to ...
Definition: normalize.c:452
#define make_expression_list(stats...)
basic entity_basic(entity e)
return the basic associated to entity e if it's a function/variable/constant basic_undefined otherwis...
Definition: entity.c:1380
expression entity_to_expression(entity e)
if v is a constant, returns a constant call.
Definition: expression.c:165
expression MakeUnaryCall(entity f, expression a)
Creates a call expression to a function with one argument.
Definition: expression.c:342
#define basic_pointer_p(x)
Definition: ri.h:635
#define reference_indices(x)
Definition: ri.h:2328
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
size_t nb_dims
Definition: outlining.c:207
entity old
Definition: outlining.c:205
entity new
Definition: outlining.c:206

References basic_pointer_p, DEREFERENCING_OPERATOR_NAME, ENDP, entity_basic(), entity_intrinsic(), entity_to_expression(), expression_domain, expression_syntax, gen_full_copy_list(), gen_full_free_list(), gen_get_ancestor(), indices, make_call(), make_expression_list, make_subscript(), make_syntax_call(), make_syntax_subscript(), MakeUnaryCall(), ocontext_t::nb_dims, ocontext_t::new, ocontext_t::old, pips_assert, POP, reference_indices, reference_variable, same_entity_p(), and unnormalize_expression().

Referenced by outliner_smart_replacment().

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

◆ do_remove_entity_from_decl()

static void do_remove_entity_from_decl ( statement  s,
entity  e 
)
static

Definition at line 918 of file outlining.c.

918  {
920 }
void gen_remove(list *cpp, const void *o)
remove all occurences of item o from list *cpp, which is thus modified.
Definition: list.c:685

References gen_remove(), and statement_declarations.

Referenced by outliner().

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

◆ do_remove_entity_from_private()

static void do_remove_entity_from_private ( loop  l,
entity  e 
)
static

Definition at line 914 of file outlining.c.

914  {
915  gen_remove(&loop_locals(l),e);
917 }
#define entity_undefined
Definition: ri.h:2761
#define loop_index(x)
Definition: ri.h:1640

References entity_undefined, gen_remove(), loop_index, loop_locals, and same_entity_p().

Referenced by outliner().

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

◆ entity_not_undefined_nor_constant_nor_intrinsic_p()

static bool entity_not_undefined_nor_constant_nor_intrinsic_p ( entity  e)
static

Definition at line 937 of file outlining.c.

937  {
938  return !type_undefined_p(entity_type(e)) &&
940 }
bool entity_not_constant_or_intrinsic_p(entity e)
Default entity filter for get_referenced_entities()
Definition: entity.c:3050
#define type_undefined_p(x)
Definition: ri.h:2884

References entity_not_constant_or_intrinsic_p(), entity_type, and type_undefined_p.

Referenced by outliner_independent_recursively().

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

◆ get_loop_locals_and_remove()

static set get_loop_locals_and_remove ( statement  st)
static

Definition at line 105 of file outlining.c.

105  {
106  set locals = set_make(set_pointer);
108  return locals;
109 }
@ set_pointer
Definition: newgen_set.h:44
set set_make(set_type)
Create an empty set of any type but hash_private.
Definition: set.c:102
static void get_loop_locals_and_remove_walker(statement st, set s)
Definition: outlining.c:77

References gen_context_recurse, gen_true2(), get_loop_locals_and_remove_walker(), set_make(), set_pointer, and statement_domain.

Referenced by get_private_entities().

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

◆ get_loop_locals_and_remove_walker()

static void get_loop_locals_and_remove_walker ( statement  st,
set  s 
)
static

loop_locals is sometimes too big, mainly due to the way gpu_ify is done ...

validate everything

remove instructions for later processing

Definition at line 77 of file outlining.c.

77  {
78  if(statement_loop_p(st)) {
79  loop l = statement_loop(st);
80  list locals = loop_locals(l);
81 
82  /* loop_locals is sometimes too big,
83  * mainly due to the way gpu_ify is done ...
84  */
87  set_add_element(re0,re0,loop_index(l));
88  set_union(re0,re0,re1);
89  set_free(re1);
90 
91  /* validate everything */
92  FOREACH(ENTITY,el,locals) {
93  if(set_belong_p(re0,el))
94  set_add_element(s,s,el);
95  }
96  set_free(re0);
97 
98  /* remove instructions for later processing */
101  }
102 }
void free_instruction(instruction p)
Definition: ri.c:1118
loop statement_loop(statement)
Get the loop of a statement.
Definition: statement.c:1374
bool statement_loop_p(statement)
Definition: statement.c:349
set set_union(set, const set, const set)
Definition: set.c:211
set set_add_element(set, const set, const void *)
Definition: set.c:152
#define loop_body(x)
Definition: ri.h:1644
#define instruction_undefined
Definition: ri.h:1454
#define statement_instruction(x)
Definition: ri.h:2458
#define loop_range(x)
Definition: ri.h:1642

References ENTITY, FOREACH, free_instruction(), get_referenced_entities(), instruction_undefined, loop_body, loop_index, loop_locals, loop_range, set_add_element(), set_belong_p(), set_free(), set_union(), statement_instruction, statement_loop(), and statement_loop_p().

Referenced by get_loop_locals_and_remove().

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

◆ get_private_entities()

static set get_private_entities ( statement  st)
static

try hard to reproduce in / out regions with only loop_locals it is time to move to regions ...

are they stable enough ?

Definition at line 115 of file outlining.c.

115  {
119  set_difference(locals,locals,re);
120  set_free(re);
122  return locals;
123 }
statement copy_statement(statement p)
STATEMENT.
Definition: ri.c:2186
void free_statement(statement p)
Definition: ri.c:2189
set set_difference(set, const set, const set)
Definition: set.c:256
static set get_loop_locals_and_remove(statement st)
Definition: outlining.c:105
bool clone(const string)

References clone(), copy_statement(), free_statement(), get_loop_locals_and_remove(), get_referenced_entities(), set_difference(), and set_free().

Referenced by private_variables().

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

◆ is_entity_in_list()

bool is_entity_in_list ( entity  e,
list  l 
)

Checks if an entity is in a list.

Done by comparing the minimal user name.

Definition at line 688 of file outlining.c.

688  {
689  if (ENDP(l))
690  return false;
691  FOREACH(entity, ent, l) {
693  return true;
694  }
695  return false;
696 }
const char * entity_minimal_user_name(entity e)
Do not preserve scope information.
Definition: naming.c:223

References ENDP, entity_minimal_user_name(), and FOREACH.

Referenced by outliner_parameters().

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

◆ outline()

bool outline ( const string  module_name)

entry point for outline module outlining will be performed using either comment recognition or interactively

Parameters
module_namename of the module containing the statements to outline

prelude

retrieve name of the outlined module

retrieve statement to outline

apply outlining

validate

ostlude

Parameters
module_nameodule_name

Definition at line 1385 of file outlining.c.

1386 {
1387  /* prelude */
1392 
1393  debug_on("OUTLINE_DEBUG_LEVEL");
1394 
1395  /* retrieve name of the outlined module */
1396  const char* outline_module_name = get_string_property_or_ask("OUTLINE_MODULE_NAME","outline module name ?\n");
1397 
1398  // Check the language. In case of Fortran the module name must be in
1399  // capital letters.
1400  char * omn=strdup(outline_module_name);
1402  omn=strupper(omn,omn);
1403 
1404  /* retrieve statement to outline */
1405  list statements_to_outline = find_statements_with_pragma(get_current_module_statement(),get_string_property("OUTLINE_PRAGMA")) ;
1406  if(ENDP(statements_to_outline)) {
1407  const char* label_name = get_string_property("OUTLINE_LABEL");
1408  if( empty_string_p(label_name) ) {
1410  }
1411  else {
1414  pips_user_error("Could not find loop labeled %s\n",label_name);
1415  if(statement_loop_p(statement_to_outline) && get_bool_property("OUTLINE_LOOP_STATEMENT"))
1417  statements_to_outline=make_statement_list(statement_to_outline);
1418  }
1419  }
1420 
1421  /* apply outlining */
1422  (void)outliner(omn,statements_to_outline);
1423  free(omn);
1424 
1425 
1426  debug_off();
1427 
1428  /* validate */
1433 
1434  /*postlude*/
1436  reset_rw_effects();
1439 
1440  return true;
1441 }
callees compute_callees(const statement stat)
Recompute the callees of a module statement.
Definition: callgraph.c:355
void set_rw_effects(statement_effects)
void set_cumulated_rw_effects(statement_effects)
void reset_cumulated_rw_effects(void)
void reset_rw_effects(void)
bool empty_string_p(const char *s)
Definition: entity_names.c:239
const char * module_name(const char *s)
Return the module part of an entity name.
Definition: entity_names.c:296
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....
void free(void *)
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
const char * get_current_module_name(void)
Get the name of the current module.
Definition: static.c:121
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
entity get_current_module_entity(void)
Get the entity of the current module.
Definition: static.c:85
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
list find_statements_with_pragma(statement, const char *)
Get a list of statements with pragma begining with a prefix.
Definition: statement.c:3912
statement find_statement_from_label_name(statement, const char *, const char *)
Definition: statement.c:3816
#define debug_on(env)
Definition: misc-local.h:157
#define debug_off()
Definition: misc-local.h:160
#define pips_user_error
Definition: misc-local.h:147
string strupper(string, const char *)
Definition: string.c:213
statement outliner(const char *outline_module_name, list statements_to_outline)
outline the statements in statements_to_outline into a module named outline_module_name the outlined ...
Definition: outlining.c:1327
list find_statements_interactively(statement)
prompt the user to select contiguous statement in s
Definition: statement.c:258
const char * get_string_property_or_ask(const char *, const char[])
bool module_reorder(statement body)
Reorder a module and recompute order to statement if any.
Definition: reorder.c:244
#define make_statement_list(stats...)
easy list constructor
entity module_name_to_entity(const char *mn)
This is an alias for local_name_to_top_level_entity.
Definition: entity.c:1479
bool fortran_module_p(entity m)
Test if a module is in Fortran.
Definition: entity.c:2799
#define statement_undefined_p(x)
Definition: ri.h:2420
char * strdup()
list statement_to_outline
scalopragma.c
Definition: scalopragma.c:25

References compute_callees(), db_get_memory_resource(), DB_PUT_MEMORY_RESOURCE, debug_off, debug_on, empty_string_p(), ENDP, find_statement_from_label_name(), find_statements_interactively(), find_statements_with_pragma(), fortran_module_p(), free(), get_bool_property(), get_current_module_entity(), get_current_module_name(), get_current_module_statement(), get_string_property(), get_string_property_or_ask(), loop_body, make_statement_list, module_name(), module_name_to_entity(), module_reorder(), outliner(), pips_user_error, reset_cumulated_rw_effects(), reset_current_module_entity(), reset_current_module_statement(), reset_rw_effects(), set_cumulated_rw_effects(), set_current_module_entity(), set_current_module_statement(), set_rw_effects(), statement_loop(), statement_loop_p(), statement_to_outline, statement_undefined_p, strdup(), and strupper().

+ Here is the call graph for this function:

◆ outline_remove_duplicates()

static void outline_remove_duplicates ( list entities)
static

Definition at line 531 of file outlining.c.

531  {
532  list tentities = gen_copy_seq(*entities);
533  for(list iter=tentities;!ENDP(iter);POP(iter)) {
534  entity e0 = ENTITY(CAR(iter));
535  FOREACH(ENTITY,e1,CDR(iter)) {
536  if( !same_entity_p(e0,e1) &&
537  same_entity_lname_p(e0,e1)) {
539  break;
540  }
541  }
542  }
543  gen_free_list(tentities);
544 }
void gen_remove_once(list *pl, const void *o)
Remove the first occurence of o in list pl:
Definition: list.c:691
list gen_copy_seq(list l)
Copy a list structure.
Definition: list.c:501
#define CAR(pcons)
Get the value of the first element of a list.
Definition: newgen_list.h:92
void gen_free_list(list l)
free the spine of the list
Definition: list.c:327
#define CDR(pcons)
Get the list less its first element.
Definition: newgen_list.h:111
bool same_entity_lname_p(entity, entity)
Definition: same_names.c:64

References CAR, CDR, ENDP, ENTITY, FOREACH, gen_copy_seq(), gen_free_list(), gen_remove_once(), POP, same_entity_lname_p(), and same_entity_p().

Referenced by outliner_scan().

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

◆ outliner()

statement outliner ( const char *  outline_module_name,
list  statements_to_outline 
)

outline the statements in statements_to_outline into a module named outline_module_name the outlined statements are replaced by a call to the newly generated module statements_to_outline is modified in place to represent that call

Parameters
outline_module_namename of the new module
statements_to_outlineis a list of consecutive statements to outline into outline_module_name
Returns
pointer to the newly generated statement (already inserted in statements_to_outline)

1 : init

pass loop bounds as parameters if required

2 : scan

3 : parameters

4 : patch parameters

5 : file

6 : call

7: remove obsolete entities, this is needed otherwise the IR keeps some obsolete data

Parameters
outline_module_nameutline_module_name
statements_to_outlinetatements_to_outline

Definition at line 1327 of file outlining.c.

1328 {
1329  pips_assert("there are some statements to outline",!ENDP(statements_to_outline));
1331 
1332  statement new_body = make_block_statement(statements_to_outline);
1333 
1334  /* 1 : init */
1335  hash_table entity_to_effective_parameter = outliner_init(new_fun, statements_to_outline);
1336 
1337  /* pass loop bounds as parameters if required */
1338  const char* loop_label = get_string_property("OUTLINE_LOOP_BOUND_AS_PARAMETER");
1340  if(!statement_undefined_p(theloop) && statement_loop(theloop))
1341  outliner_extract_loop_bound(theloop,entity_to_effective_parameter);
1342 
1343  /* 2 : scan */
1344  list referenced_entities = outliner_scan(new_fun, statements_to_outline, new_body);
1345 
1346  /* 3 : parameters */
1347  list effective_parameters = NIL;
1348  list formal_parameters = NIL;
1349  outliner_parameters(new_fun, new_body, referenced_entities, entity_to_effective_parameter, &effective_parameters, &formal_parameters);
1350 
1351  /* 4 : patch parameters */
1353  && get_bool_property("OUTLINE_WRITTEN_SCALAR_BY_REFERENCE"))
1354  outliner_patch_parameters(statements_to_outline, referenced_entities, effective_parameters, formal_parameters, new_body, new_body, new_body);
1355 
1356  /* 5 : file */
1357  outliner_file(new_fun, formal_parameters, &new_body );
1358 
1359  /* 6 : call */
1360  statement new_stmt = outliner_call(new_fun, statements_to_outline, effective_parameters);
1361 
1362  /* 7: remove obsolete entities, this is needed otherwise the IR keeps some obsolete data */
1363  list declared_entities = statements_to_declarations(statements_to_outline);
1364  FOREACH(ENTITY,de,declared_entities) {
1365  FOREACH(STATEMENT, sde, statements_to_outline) {
1366  gen_context_multi_recurse(sde, de,
1369  NULL);
1371  free_entity(de);
1372  }
1373  }
1374  gen_free_list(declared_entities);
1375  return new_stmt;
1376 }
void free_entity(entity p)
Definition: ri.c:2524
language copy_language(language p)
LANGUAGE.
Definition: ri.c:1202
statement make_block_statement(list)
Make a block statement from a list of statement.
Definition: statement.c:616
list statements_to_declarations(list)
Returns the declarations contained in a list of statement.
Definition: statement.c:3265
void outliner_patch_parameters(list statements_to_outline, list referenced_entities, list effective_parameters, list formal_parameters, statement new_body, statement begin, statement end)
we need to patch parameters , effective parameters and body in C because parameters are passed by cop...
Definition: outlining.c:809
static void do_remove_entity_from_decl(statement s, entity e)
Definition: outlining.c:918
hash_table outliner_init(entity new_fun, list statements_to_outline)
Definition: outlining.c:546
static void outliner_extract_loop_bound(statement sloop, hash_table entity_to_effective_parameter)
Definition: outlining.c:453
list outliner_scan(entity new_fun, list statements_to_outline, statement new_body)
Definition: outlining.c:555
statement outliner_call(entity new_fun, list statements_to_outline, list effective_parameters)
Definition: outlining.c:1235
void outliner_file(entity new_fun, list formal_parameters, statement *new_body)
Definition: outlining.c:1138
void outliner_parameters(entity new_fun, statement new_body, list referenced_entities, hash_table entity_to_effective_parameter, list *effective_parameters_, list *formal_parameters_)
Definition: outlining.c:698
static void do_remove_entity_from_private(loop l, entity e)
Definition: outlining.c:914
#define entity_declarations(e)
MISC: newgen shorthands.
#define module_language(e)
implemented as a macro to allow lhs
bool c_module_p(entity m)
Test if a module "m" is written in C.
Definition: entity.c:2777
entity make_empty_subroutine(const char *name, language l)
Definition: entity.c:268
#define loop_domain
newgen_language_domain_defined
Definition: ri.h:218
#define loop_label(x)
Definition: ri.h:1646

References c_module_p(), copy_language(), do_remove_entity_from_decl(), do_remove_entity_from_private(), ENDP, ENTITY, entity_declarations, find_statement_from_label_name(), FOREACH, free_entity(), gen_context_multi_recurse(), gen_free_list(), gen_remove(), gen_true(), get_bool_property(), get_current_module_entity(), get_current_module_name(), get_current_module_statement(), get_string_property(), loop_domain, loop_label, make_block_statement(), make_empty_subroutine(), module_language, NIL, outliner_call(), outliner_extract_loop_bound(), outliner_file(), outliner_init(), outliner_parameters(), outliner_patch_parameters(), outliner_scan(), pips_assert, STATEMENT, statement_domain, statement_loop(), statement_undefined_p, and statements_to_declarations().

Referenced by do_kernelize(), gpu_ify_statement(), gpu_memory_apply(), outline(), outline_stmts_between_pragmas_in_sequence(), scalopragma(), and taskify_statement().

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

◆ outliner_call()

statement outliner_call ( entity  new_fun,
list  statements_to_outline,
list  effective_parameters 
)

and return the replacement statement

perform substitution : replace the original statements by a single call and patch the remaining statement (yes it's ugly)

trash any extensions|comments, they may not be valid now

Parameters
new_funew_fun
statements_to_outlinetatements_to_outline
effective_parametersffective_parameters

Definition at line 1235 of file outlining.c.

1236 {
1237 
1238  /* and return the replacement statement */
1239  instruction new_inst = make_instruction_call(make_call(new_fun,effective_parameters));
1240  statement new_stmt = statement_undefined;
1241 
1242  /* perform substitution :
1243  * replace the original statements by a single call
1244  * and patch the remaining statement (yes it's ugly)
1245  */
1246  FOREACH(STATEMENT,old_statement,statements_to_outline)
1247  {
1248  //free_instruction(statement_instruction(old_statement));
1249  if(statement_undefined_p(new_stmt))
1250  {
1251  statement_instruction(old_statement)=new_inst;
1252  new_stmt=old_statement;
1253  }
1254  else
1256  gen_free_list(statement_declarations(old_statement));
1257  statement_declarations(old_statement)=NIL;
1258  /* trash any extensions|comments, they may not be valid now */
1259  free_extensions(statement_extensions(old_statement));
1260  statement_extensions(old_statement)=empty_extensions();
1261  if(!string_undefined_p(statement_comments(old_statement))) free(statement_comments(old_statement));
1262  statement_comments(old_statement)=empty_comments;
1263 
1264  }
1265  return new_stmt;
1266 }
void free_extensions(extensions p)
Definition: ri.c:950
instruction make_instruction_call(call _field_)
Definition: ri.c:1184
instruction make_continue_instruction()
Creates a CONTINUE instruction, that is the FORTRAN nop, the ";" in C or the "pass" in Python for exa...
Definition: instruction.c:79
#define string_undefined_p(s)
Definition: newgen_types.h:41
#define empty_comments
Empty comments (i.e.
extensions empty_extensions(void)
extension.c
Definition: extension.c:43
#define statement_extensions(x)
Definition: ri.h:2464
#define statement_comments(x)
Definition: ri.h:2456
#define statement_undefined
Definition: ri.h:2419

References empty_comments, empty_extensions(), FOREACH, free(), free_extensions(), gen_free_list(), make_call(), make_continue_instruction(), make_instruction_call(), NIL, STATEMENT, statement_comments, statement_declarations, statement_extensions, statement_instruction, statement_undefined, statement_undefined_p, and string_undefined_p.

Referenced by compile_mpi(), and outliner().

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

◆ outliner_compilation_unit()

static void outliner_compilation_unit ( entity  new_fun,
list formal_parameters   __attribute__(unused) 
)
static

Definition at line 922 of file outlining.c.

923  {
924  if(get_bool_property("OUTLINE_INDEPENDENT_COMPILATION_UNIT")
926  string outline_module_name = (string)entity_user_name(new_fun);
927  char * the_cu = NULL,*iter, *cun;
928  if((iter=strchr(outline_module_name,FILE_SEP))) {
929  the_cu = strndup(outline_module_name,iter-outline_module_name);
930  }
931  else the_cu = strdup(outline_module_name);
932  asprintf(&cun,"%s" FILE_SEP_STRING, the_cu);
934  free(cun);
935  }
936 }
void add_new_compilation_unit(const char *compilation_unit_name, bool is_fortran, entity module)
Warning! Do not modify this file that is automatically generated!
Definition: initializer.c:367
#define asprintf
Definition: misc-local.h:225
#define FILE_SEP_STRING
Definition: naming-local.h:41
#define FILE_SEP
Definition: naming-local.h:39
char * string
STRING.
Definition: newgen_types.h:39
const char * entity_user_name(entity e)
Since entity_local_name may contain PIPS special characters such as prefixes (label,...
Definition: entity.c:487
char * strndup(char const *s, size_t n)
A replacement function, for systems that lack strndup.
Definition: strndup.c:26

References add_new_compilation_unit(), asprintf, entity_user_name(), FILE_SEP, FILE_SEP_STRING, fortran_module_p(), free(), get_bool_property(), get_current_module_entity(), strdup(), and strndup().

Referenced by outliner_file().

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

◆ outliner_extract_loop_bound()

static void outliner_extract_loop_bound ( statement  sloop,
hash_table  entity_to_effective_parameter 
)
static

Definition at line 453 of file outlining.c.

454 {
455  loop l =statement_loop(sloop);
456  range r = loop_range(l);
457  expression upper = range_upper(r);
458  if(!expression_scalar_p(upper))
459  {
460  basic b = basic_of_expression(upper);
463  hash_put(entity_to_effective_parameter,holder,
465  range_upper(r)=
467  }
468 }
basic make_basic_int(intptr_t _field_)
Definition: ri.c:158
void free_basic(basic p)
Definition: ri.c:107
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.
Definition: hash.c:364
#define MINUS_OPERATOR_NAME
#define PLUS_OPERATOR_NAME
#define DEFAULT_INTEGER_TYPE_SIZE
#define expression_scalar_p(e)
expression MakeBinaryCall(entity f, expression eg, expression ed)
Creates a call expression to a function with 2 arguments.
Definition: expression.c:354
expression int_to_expression(_int i)
transform an int into an expression and generate the corresponding entity if necessary; it is not cle...
Definition: expression.c:1188
basic basic_of_expression(expression)
basic basic_of_expression(expression exp): Makes a basic of the same basic as the expression "exp".
Definition: type.c:1383
entity make_new_scalar_variable(entity, basic)
Definition: variable.c:741
#define range_upper(x)
Definition: ri.h:2290
#define basic_overloaded_p(x)
Definition: ri.h:623

References basic_of_expression(), basic_overloaded_p, DEFAULT_INTEGER_TYPE_SIZE, entity_intrinsic(), entity_to_expression(), expression_scalar_p, free_basic(), get_current_module_entity(), hash_put(), int_to_expression(), loop_range, make_basic_int(), make_new_scalar_variable(), MakeBinaryCall(), MINUS_OPERATOR_NAME, PLUS_OPERATOR_NAME, range_upper, and statement_loop().

Referenced by outliner().

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

◆ outliner_file()

void outliner_file ( entity  new_fun,
list  formal_parameters,
statement new_body 
)

prepare parameters and body

5-0 : create new compilation unit

5-1 : add all callees to the same foreign compilation units

5-2: fix the types of the formal parameter in case a new compilation unit is used. Make sure that the function type and the types of the formal parameters are consistent. The function type is correct because the compilation unit has just been parsed.

add a return at the end of the body, in all cases

we can now begin the outlining

et_current_module_entity()

horrible hack to prevent declaration duplication signed : Serge Guelton

we need to free them now, otherwise recompilation fails

Parameters
new_funew_fun
formal_parametersormal_parameters
new_bodyew_body

Definition at line 1138 of file outlining.c.

1139 {
1140  string outline_module_name = (string)entity_user_name(new_fun);
1141 
1142  /* prepare parameters and body*/
1143  module_functional_parameters(new_fun)=formal_parameters;
1144  FOREACH(PARAMETER,p,formal_parameters) {
1148  }
1149 
1150  /* 5-0 : create new compilation unit */
1151  outliner_compilation_unit(new_fun, formal_parameters);
1152 
1155 
1156  /* 5-1 : add all callees to the same foreign compilation units */
1157  outliner_independent(outline_module_name, *new_body);
1158 
1159  /* 5-2: fix the types of the formal parameter in case a new
1160  compilation unit is used. Make sure that the function type and
1161  the types of the formal parameters are consistent. The function
1162  type is correct because the compilation unit has just been
1163  parsed. */
1164  if(false) {
1165  functional ft = type_functional(entity_type(new_fun));
1166  list fpl = functional_parameters(ft);
1167  int i, nparams = gen_length(fpl);
1168 
1169  for (i = 1; i <= nparams; i++) {
1170  entity param = find_ith_parameter(new_fun, i);
1171  type formal_pt = entity_type(param);
1172  type functional_pt = parameter_type(PARAMETER(CAR(fpl)));
1173  if(!type_equal_p(formal_pt, functional_pt)) {
1174  entity_type(param) = copy_type(functional_pt);
1175  }
1176  fpl = CDR(fpl);
1177  }
1178  }
1179 
1180  // In fortran we always want to generate the outline function
1181  // in its own new file
1182  char * cun = string_undefined;
1184  ;
1185  } else if(get_bool_property("OUTLINE_INDEPENDENT_COMPILATION_UNIT")) {
1186  // Declare in current module so that it's not undefined at call site
1187  char * the_cu = NULL,*iter;
1188  if((iter=strchr(outline_module_name,FILE_SEP))) {
1189  the_cu = strndup(outline_module_name,iter-outline_module_name);
1190  }
1191  else the_cu = strdup(outline_module_name);
1192  asprintf(&cun,"%s" FILE_SEP_STRING, the_cu);
1193  free(the_cu);
1194  }
1195  else {
1197  }
1198  /* add a return at the end of the body, in all cases */
1199  insert_statement(*new_body, make_return_statement(new_fun), false);
1200 
1201  /* we can now begin the outlining */
1202  bool saved_order = get_bool_property(STAT_ORDER),
1203  saved_block = get_bool_property("PRETTYPRINT_BLOCKS");
1205  set_bool_property("PRETTYPRINT_BLOCKS",false);
1206  text t = text_named_module(new_fun, new_fun /*get_current_module_entity()*/, *new_body);
1207 
1208 
1210  if(!string_undefined_p(cun)) free(cun);
1211  free_text(t);
1212 
1213  set_bool_property(STAT_ORDER,saved_order);
1214  set_bool_property("PRETTYPRINT_BLOCKS",saved_block);
1215 
1216 
1217 
1218  /* horrible hack to prevent declaration duplication
1219  * signed : Serge Guelton
1220  */
1222  code_declarations(EntityCode(new_fun))=NIL;
1223 
1224  /* we need to free them now, otherwise recompilation fails */
1225  FOREACH(PARAMETER,p,formal_parameters) {
1227  if(!type_undefined_p(entity_type(e)) &&
1228  entity_variable_p(e)) {
1229  free_type(entity_type(e));
1231  }
1232  }
1233 }
type copy_type(type p)
TYPE.
Definition: ri.c:2655
void free_text(text p)
Definition: text.c:74
string compilation_unit_of_module(const char *)
The output is undefined if the module is referenced but not defined in the workspace,...
Definition: module.c:350
size_t gen_length(const list l)
Definition: list.c:150
list gen_nconc(list cp1, list cp2)
physically concatenates CP1 and CP2 but do not duplicates the elements
Definition: list.c:344
void insert_statement(statement, statement, bool)
This is the normal entry point.
Definition: statement.c:2570
statement make_return_statement(entity)
Definition: statement.c:779
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.
Definition: initializer.c:431
#define string_undefined
Definition: newgen_types.h:40
static void outliner_independent(const char *module_name, statement body)
redeclare all callees of outlined function in the same compilation unit
Definition: outlining.c:1065
static void outliner_compilation_unit(entity new_fun, list formal_parameters __attribute__((unused)))
Definition: outlining.c:922
#define STAT_ORDER
Definition: outlining.c:75
text text_named_module(entity, entity, statement)
void set_bool_property(const char *, bool)
#define entity_variable_p(e)
An entity_variable_p(e) may hide a typedef and hence a functional type.
#define module_functional_parameters(func)
code EntityCode(entity e)
this function checks that e has an initial value code.
Definition: entity.c:301
bool type_equal_p(type, type)
Definition: type.c:547
entity find_ith_parameter(entity, int)
Definition: util.c:93
#define dummy_identifier(x)
Definition: ri.h:1033
#define parameter_dummy(x)
Definition: ri.h:1823
#define parameter_type(x)
Definition: ri.h:1819
#define type_functional(x)
Definition: ri.h:2952
#define code_declarations(x)
Definition: ri.h:784
#define functional_parameters(x)
Definition: ri.h:1442
#define PARAMETER(x)
PARAMETER.
Definition: ri.h:1788
#define value_code(x)
Definition: ri.h:3067
Definition: replace.c:135
void AddEntityToModuleCompilationUnit(entity e, entity module)
Definition: module.c:301

References add_new_module_from_text(), AddEntityToModuleCompilationUnit(), asprintf, c_module_p(), CAR, CDR, code_declarations, compilation_unit_of_module(), CONS, copy_type(), dummy_identifier, ENTITY, entity_initial, entity_type, entity_user_name(), entity_variable_p, EntityCode(), FILE_SEP, FILE_SEP_STRING, find_ith_parameter(), FOREACH, fortran_module_p(), free(), free_text(), free_type(), functional_parameters, gen_free_list(), gen_length(), gen_nconc(), get_bool_property(), get_current_module_entity(), get_current_module_name(), insert_statement(), make_return_statement(), module_functional_parameters, NIL, outliner_compilation_unit(), outliner_independent(), PARAMETER, parameter_dummy, parameter_type, set_bool_property(), STAT_ORDER, strdup(), string_undefined, string_undefined_p, strndup(), text_named_module(), type_equal_p(), type_functional, type_undefined, type_undefined_p, and value_code.

Referenced by compile_mpi(), and outliner().

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

◆ outliner_independent()

static void outliner_independent ( const char *  module_name,
statement  body 
)
static

redeclare all callees of outlined function in the same compilation unit

Definition at line 1065 of file outlining.c.

1065  {
1066  if(get_bool_property("OUTLINE_INDEPENDENT_COMPILATION_UNIT")) {
1067  string cun;
1069  cun = strdup("");
1070  else {
1071  char * the_cu = NULL,*iter;
1072  if((iter=strchr(module_name,FILE_SEP))) {
1073  the_cu = strndup(module_name,iter-module_name);
1074  }
1075  else the_cu = strdup(module_name);
1076  asprintf(&cun,"%s" FILE_SEP_STRING, the_cu);
1077  free(the_cu);
1079  if(entity_undefined_p(cu))
1080  cu=MakeCompilationUnitEntity(cun);
1081  }
1083 
1085  {
1086  // Get DBR_CODE for the compilation unit
1087  if(!db_resource_required_or_available_p(DBR_PARSED_CODE,cun))
1088  {
1089  bool compilation_unit_parser(const char*);
1095  if(!entity_undefined_p(tmp))
1099  }
1100  if(!db_resource_required_or_available_p(DBR_CODE,cun))
1101  {
1102  bool controlizer(const char*);
1107  controlizer(cun);
1108  if(!entity_undefined_p(tmp))
1112  }
1113  statement cun_s=(statement)db_get_memory_resource(DBR_CODE, cun, true);
1114 
1115  // Update C_SOURCE_FILE from DBR_CODE
1117  text code_text = text_named_module(cu, cu, cun_s);
1118  string init_name = db_get_file_resource(DBR_C_SOURCE_FILE, cun, true);
1119  char *dir_name = db_get_current_workspace_directory();
1120 
1121  char *finit_name;
1122  asprintf(&finit_name,"%s/%s" ,dir_name, init_name);
1123  FILE *f = safe_fopen(finit_name, "w");
1124  print_text(f, code_text);
1125  safe_fclose(f, finit_name);
1126 
1127  db_touch_resource(DBR_C_SOURCE_FILE, cun);
1128  db_touch_resource(DBR_USER_FILE, cun);
1129 
1130  // Remove DBR_DECLARATIONS to force parsing from pipsmake
1131  db_delete_resource(DBR_DECLARATIONS, cun);
1132  }
1133  free(cun);
1134  }
1135 }
bool db_resource_required_or_available_p(const char *rname, const char *oname)
from now on we must not know about the database internals?
Definition: database.c:505
bool db_touch_resource(const char *rname, const char *oname)
touch logical time for resource[owner], possibly behind the back of pipsdbm.
Definition: database.c:538
void db_delete_resource(const char *rname, const char *oname)
Delete a resource.
Definition: database.c:353
bool compilation_unit_parser(const char *module_name)
Definition: c_parser.c:746
struct _newgen_struct_statement_ * statement
Definition: cloning.h:21
bool controlizer(const char *)
The old controlizer user interface.
Definition: module.c:224
FILE * safe_fopen(const char *filename, const char *what)
Definition: file.c:67
int safe_fclose(FILE *stream, const char *filename)
Definition: file.c:77
#define TOP_LEVEL_MODULE_NAME
Module containing the global variables in Fortran and C.
Definition: naming-local.h:101
int f(int off1, int off2, int n, float r[n], float a[n], float b[n])
Definition: offsets.c:15
static void outliner_independent_recursively(entity module, const char *cun, statement s)
Definition: outlining.c:959
#define db_get_file_resource
string db_get_current_workspace_directory(void)
Definition: workspace.c:96
entity FindEntity(const char *package, const char *name)
Retrieve an entity from its package/module name and its local name.
Definition: entity.c:1503
entity MakeCompilationUnitEntity(const char *name)
This is useful for the C language only.
Definition: entity.c:1954
#define entity_undefined_p(x)
Definition: ri.h:2762
Definition: statement.c:54
void print_text(FILE *fd, text t)
Definition: print.c:195

References asprintf, c_module_p(), compilation_unit_parser(), controlizer(), db_delete_resource(), db_get_current_workspace_directory(), db_get_file_resource, db_get_memory_resource(), db_resource_required_or_available_p(), db_touch_resource(), entity_undefined_p, f(), FILE_SEP, FILE_SEP_STRING, FindEntity(), fortran_module_p(), free(), get_bool_property(), get_current_module_entity(), get_current_module_statement(), MakeCompilationUnitEntity(), module_name(), module_name_to_entity(), outliner_independent_recursively(), print_text(), reset_current_module_entity(), reset_current_module_statement(), safe_fclose(), safe_fopen(), set_current_module_entity(), set_current_module_statement(), statement_undefined_p, strdup(), strndup(), text_named_module(), and TOP_LEVEL_MODULE_NAME.

Referenced by outliner_file().

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

◆ outliner_independent_recursively()

static void outliner_independent_recursively ( entity  module,
const char *  cun,
statement  s 
)
static

first step : bring all typedefs and global declarations with you

special hook for struct member : consider their structure instead of the field

SG : part of this code is duplicated from inlining

enum member cannot be added to declarations

formal parameters are not considered

second step : bring all callers with you

horrible hack to prevent declaration duplication signed : Serge Guelton

Definition at line 959 of file outlining.c.

959  {
960  callees c = compute_callees(s);
961  entity cu = module_name_to_entity(cun);
962  /* first step : bring all typedefs and global declarations with you */
965  // do not forget dependent types ...
966  set tmp = set_dup(re);
967  SET_FOREACH(entity, rer, tmp) {
968  list of_entities = type_supporting_types(entity_type(rer));
969  FOREACH(ENTITY,e,of_entities) {
970  if( entity_field_p(e) ) /* special hook for struct member : consider their structure instead of the field */
972  set_add_element(re, re, e);
973  }
974  gen_free_list(of_entities);
975  }
976  set_free(tmp);
977  list lre = set_to_list(re);
979  set_free(re);
980  /* SG : part of this code is duplicated from inlining */
982  FOREACH(ENTITY, e, lre) {
983  if(!entity_enum_member_p(e) && /* enum member cannot be added to declarations */
984  !entity_formal_p(e) ) /* formal parameters are not considered */
985  {
988  {
989  if(anonymous_type_p(e)) continue;
990  if(top_level_entity_p(e)) {
991  if(get_bool_property("OUTLINE_ALLOW_GLOBALS")) {
994  }
995  }
996  else if(variable_static_p(e))
997  pips_internal_error("unhandled case : outlining a static variable\n");
998  else if(typedef_entity_p(e)) {
999  #if 0
1000  basic b = variable_basic(
1001  type_variable(
1002  entity_type(
1003  e
1004  )
1005  )
1006  );
1007  if(basic_derived_p(b)) {
1008  entity *et = &basic_derived(b);
1009  *et = recursive_rename_types(*et,cun);
1010  if(!anonymous_type_p(*et))
1011  AddEntityToCompilationUnit(*et, cu );
1012  }
1013  #endif
1014  e=recursive_rename_types(e,cun);
1016  }
1017  }
1018  }
1019  }
1020  }
1021  gen_free_list(lre);
1022 
1023  /* second step : bring all callers with you */
1025  char* new_name;
1027  asprintf(&new_name, "%s" MODULE_SEP_STRING"%s%s%s", cun, cun, get_string_property("OUTLINE_CALLEES_PREFIX"),entity_user_name(old_fun) );
1028  entity new_fun = make_entity(new_name,
1029  copy_type(entity_type(old_fun)),
1030  copy_storage(entity_storage(old_fun)),
1031  copy_value(entity_initial(old_fun))
1032  );
1035  replace_entity(s,old_fun, new_fun);
1036 
1037 
1039  outliner_independent_recursively(old_fun, cun, body);
1040 
1041  bool saved_order = get_bool_property(STAT_ORDER),
1042  saved_block = get_bool_property("PRETTYPRINT_BLOCKS");
1044  set_bool_property("PRETTYPRINT_BLOCKS",false);
1045  text t = text_named_module(new_fun, new_fun , body);
1046 
1048 
1049  /* horrible hack to prevent declaration duplication
1050  * signed : Serge Guelton
1051  */
1053  code_declarations(EntityCode(new_fun))=NIL;
1054 
1055  set_bool_property(STAT_ORDER,saved_order);
1056  set_bool_property("PRETTYPRINT_BLOCKS",saved_block);
1057  free_statement(body);
1058  }
1059  free_callees(c);
1060 }
void free_callees(callees p)
Definition: ri.c:194
value copy_value(value p)
VALUE.
Definition: ri.c:2784
storage copy_storage(storage p)
STORAGE.
Definition: ri.c:2228
#define STRING(x)
Definition: genC.h:87
void replace_entity(void *s, entity old, entity new)
per variable version of replace_entities.
Definition: replace.c:113
list gen_append(list l1, const list l2)
Definition: list.c:471
#define pips_internal_error
Definition: misc-local.h:149
#define MODULE_SEP_STRING
Definition: naming-local.h:30
list set_to_list(const set)
create a list from a set the set is not freed
Definition: set.c:436
#define SET_FOREACH(type_name, the_item, the_set)
enumerate set elements in their internal order.
Definition: newgen_set.h:78
set set_dup(const set)
Definition: set.c:143
static bool entity_not_undefined_nor_constant_nor_intrinsic_p(entity e)
Definition: outlining.c:937
static bool anonymous_type_p(entity e)
skipping anonymous enum ...
Definition: outlining.c:943
static entity recursive_rename_types(entity e, const char *cun)
Definition: outlining.c:948
static void sort_entities_with_dep(list *l)
Definition: outlining.c:136
static char * module
Definition: pips.c:74
#define make_entity(n, t, s, i)
bool entity_enum_member_p(entity e)
Definition: entity.c:980
bool entity_formal_p(entity p)
is p a formal parameter?
Definition: entity.c:1935
code entity_code(entity e)
Definition: entity.c:1098
set get_referenced_entities_filtered(void *elem, bool(*chunk_filter)(void *), bool(*entity_filter)(entity))
Same as get_referenced_entities, but will only consider entities that fulfills entity_filter and will...
Definition: entity.c:2982
bool typedef_entity_p(entity e)
Definition: entity.c:1902
bool entity_field_p(entity e)
e is the field of a structure
Definition: entity.c:857
bool top_level_entity_p(entity e)
Check if the scope of entity e is global.
Definition: entity.c:1130
entity entity_field_to_entity_struct_or_union(entity f)
Definition: entity.c:925
list type_supporting_types(type)
Return the list of types used to define type t.
Definition: type.c:5203
bool variable_static_p(entity)
true if v appears in a SAVE statement, or in a DATA statement, or is declared static i C.
Definition: variable.c:1579
#define callees_callees(x)
Definition: ri.h:675
#define basic_derived(x)
Definition: ri.h:640
#define code_externs(x)
Definition: ri.h:790
#define basic_derived_p(x)
Definition: ri.h:638
#define entity_storage(x)
Definition: ri.h:2794
#define language_fortran_p(x)
Definition: ri.h:1591
void AddEntityToCompilationUnit(entity e, entity cu)
Add an entity to the current's module compilation unit declarations we have to generate its statement...
Definition: module.c:198

References add_new_module_from_text(), AddEntityToCompilationUnit(), AddEntityToModuleCompilationUnit(), anonymous_type_p(), asprintf, basic_derived, basic_derived_p, c_module_p(), callees_callees, code_declarations, code_externs, compute_callees(), CONS, copy_statement(), copy_storage(), copy_type(), copy_value(), db_get_memory_resource(), ENTITY, entity_code(), entity_declarations, entity_enum_member_p(), entity_field_p(), entity_field_to_entity_struct_or_union(), entity_formal_p(), entity_initial, entity_local_name(), entity_not_undefined_nor_constant_nor_intrinsic_p(), entity_storage, entity_type, entity_user_name(), EntityCode(), FOREACH, free_callees(), free_statement(), gen_append(), gen_free_list(), gen_true(), get_bool_property(), get_current_module_entity(), get_referenced_entities_filtered(), get_string_property(), has_entity_with_same_name(), language_fortran_p, make_entity, module, module_language, module_name(), module_name_to_entity(), MODULE_SEP_STRING, NIL, pips_internal_error, recursive_rename_types(), replace_entity(), set_add_element(), set_bool_property(), set_dup(), SET_FOREACH, set_free(), set_to_list(), sort_entities_with_dep(), STAT_ORDER, STRING, text_named_module(), top_level_entity_p(), type_supporting_types(), type_variable, typedef_entity_p(), variable_basic, and variable_static_p().

Referenced by outliner_independent().

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

◆ outliner_init()

hash_table outliner_init ( entity  new_fun,
list  statements_to_outline 
)

try to be smart concerning array references

Parameters
new_funew_fun
statements_to_outlinetatements_to_outline

Definition at line 546 of file outlining.c.

547 {
548  /* try to be smart concerning array references */
549  if(get_bool_property("OUTLINE_SMART_REFERENCE_COMPUTATION"))
550  return outliner_smart_references_computation(statements_to_outline, new_fun);
551  else
552  return hash_table_make(hash_pointer,1);
553 }
hash_table hash_table_make(hash_key_type key_type, size_t size)
Definition: hash.c:294
@ hash_pointer
Definition: newgen_hash.h:32
static hash_table outliner_smart_references_computation(list outlined_statements, entity new_module)
purge the list of referenced entities by replacing calls to a[i][j] where i is a constant in statemen...
Definition: outlining.c:291

References get_bool_property(), hash_pointer, hash_table_make(), and outliner_smart_references_computation().

Referenced by compile_mpi(), and outliner().

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

◆ outliner_parameters()

void outliner_parameters ( entity  new_fun,
statement  new_body,
list  referenced_entities,
hash_table  entity_to_effective_parameter,
list effective_parameters_,
list formal_parameters_ 
)

all variables are promoted parameters

this create the dummy parameter

FI: when a new compilation unit is used, why declare type in the initial compilation unit? It generates derived types within the wrong compilation unit... and back fires in the prettyprinter

this adds the effective parameter

this is a constant variable or fortran function result

Parameters
new_funew_fun
new_bodyew_body
referenced_entitieseferenced_entities
entity_to_effective_parameterntity_to_effective_parameter
effective_parameters_ffective_parameters_
formal_parameters_ormal_parameters_

Definition at line 698 of file outlining.c.

701 {
702  string outline_module_name = (string)entity_user_name(new_fun);
703 
704 
705  /* all variables are promoted parameters */
706  list effective_parameters = *effective_parameters_;
707  list formal_parameters = *formal_parameters_;
708  intptr_t i=0;
709 
710  // Addition for R-Stream compatibility
711  // Prevent from adding a parameter if the entity is in the list
712  list induction_var = NIL;
713  // If no property activated then induction_var should stay to NIL
714  bool is_rstream = get_bool_property("OUTLINE_REMOVE_VARIABLE_RSTREAM_IMAGE") || get_bool_property("OUTLINE_REMOVE_VARIABLE_RSTREAM_SCOP");
715  if (is_rstream) {
716  // Enclosing loops map needed for get_variables_to_remove
718  get_variables_to_remove(referenced_entities, new_body, &induction_var);
720  // Adding the declarations to the new body
721  add_induction_var_to_local_declarations(&new_body, induction_var);
722  }
723 
724  FOREACH(ENTITY,e,referenced_entities)
725  {
726  if( (entity_variable_p(e) || entity_symbolic_p(e)) && (!is_entity_in_list(e, induction_var)))
727  {
728  pips_debug(6,"Add %s to outlined function parameters\n",entity_name(e));
729 
730  /* this create the dummy parameter */
731  entity dummy_entity = FindOrCreateEntity(
732  outline_module_name,
734  );
735  entity_initial(dummy_entity)=make_value_unknown();
736 
737  if(entity_symbolic_p(e))
738  entity_type(dummy_entity) = fortran_module_p(new_fun)?
741  else {
743  /* FI: when a new compilation unit is used, why
744  declare type in the *initial* compilation unit?
745  It generates derived types within the wrong
746  compilation unit... and back fires in the prettyprinter */
748  entity_type(dummy_entity)=copy_type(entity_type(e));
749  }
750 
751 
752  entity_storage(dummy_entity)=make_storage_formal(make_formal(dummy_entity,++i));
753 
754 
755  formal_parameters=CONS(PARAMETER,make_parameter(
756  copy_type(entity_type(dummy_entity)),
758  make_dummy_identifier(dummy_entity)),formal_parameters);
759 
760  /* this adds the effective parameter */
761  expression effective_parameter = (expression)hash_get(entity_to_effective_parameter,e);
762  if(effective_parameter == HASH_UNDEFINED_VALUE)
763  effective_parameter = entity_to_expression(e);
764 
765  effective_parameters=CONS(EXPRESSION,effective_parameter,effective_parameters);
766  }
767  /* this is a constant variable or fortran function result */
768  else if(entity_constant_p(e)||(fortran_module_p(new_fun) && entity_function_p(e))) {
769  AddLocalEntityToDeclarations(e,new_fun,new_body);
770  }
771 
772  }
773  *formal_parameters_= gen_nreverse(formal_parameters);
774  *effective_parameters_= gen_nreverse(effective_parameters);
775  hash_table_free(entity_to_effective_parameter);
776  gen_free_list(induction_var);
777  ifdebug(5) {
778  pips_debug(5,"Formals : \n");
779  print_parameters(*formal_parameters_);
780  pips_debug(5,"Effectives : \n");
781  print_expressions(*effective_parameters_);
782  }
783 }
dummy make_dummy_identifier(entity _field_)
Definition: ri.c:620
value make_value_unknown(void)
Definition: ri.c:2847
parameter make_parameter(type a1, mode a2, dummy a3)
Definition: ri.c:1495
type make_type_variable(variable _field_)
Definition: ri.c:2715
mode make_mode_reference(void)
Definition: ri.c:1356
variable make_variable(basic a1, list a2, list a3)
Definition: ri.c:2895
storage make_storage_formal(formal _field_)
Definition: ri.c:2282
mode make_mode_value(void)
Definition: ri.c:1353
formal make_formal(entity a1, intptr_t a2)
Definition: ri.c:1067
void get_variables_to_remove(list, statement, list *)
misc.c
Definition: misc.c:58
void clean_enclosing_loops(void)
Definition: loop.c:58
statement_mapping loops_mapping_of_statement(statement stat)
Definition: loop.c:155
list gen_nreverse(list cp)
reverse a list in place
Definition: list.c:304
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_debug
these macros use the GNU extensions that allow variadic macros, including with an empty list.
Definition: misc-local.h:145
#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
void add_induction_var_to_local_declarations(statement *new_body, list induction_var)
Definition: outlining.c:1307
static type type_to_named_type(type t, entity cu)
create a new type from given type, eventually renaming unnamed structures inside all new entities gen...
Definition: outlining.c:631
bool is_entity_in_list(entity e, list l)
Checks if an entity is in a list.
Definition: outlining.c:688
void print_parameters(list lp)
Display a parameter on stderr, useful for debugging.
Definition: parameter.c:63
void print_expressions(list le)
Definition: expression.c:98
#define entity_symbolic_p(e)
#define entity_constant_p(e)
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...
Definition: entity.c:1586
bool entity_function_p(entity e)
Definition: entity.c:724
void AddLocalEntityToDeclarations(entity, entity, statement)
Add the variable entity e to the list of variables of the function module.
Definition: variable.c:233
void set_enclosing_loops_map(statement_mapping)
#define functional_result(x)
Definition: ri.h:1444
#define entity_name(x)
Definition: ri.h:2790
#define ifdebug(n)
Definition: sg.c:47
#define intptr_t
Definition: stdint.in.h:294
entity module_entity_to_compilation_unit_entity(entity m)
Retrieve the compilation unit containing a module definition.
Definition: module.c:116

References add_induction_var_to_local_declarations(), AddLocalEntityToDeclarations(), clean_enclosing_loops(), CONS, copy_type(), DEFAULT_INTEGER_TYPE_SIZE, ENTITY, entity_constant_p, entity_function_p(), entity_initial, entity_name, entity_storage, entity_symbolic_p, entity_to_expression(), entity_type, entity_user_name(), entity_variable_p, EXPRESSION, FindOrCreateEntity(), FOREACH, fortran_module_p(), functional_result, gen_free_list(), gen_nreverse(), get_bool_property(), get_current_module_entity(), get_variables_to_remove(), hash_get(), hash_table_free(), HASH_UNDEFINED_VALUE, ifdebug, intptr_t, is_entity_in_list(), loops_mapping_of_statement(), make_basic_int(), make_dummy_identifier(), make_formal(), make_mode_reference(), make_mode_value(), make_parameter(), make_storage_formal(), make_type_variable(), make_value_unknown(), make_variable(), module_entity_to_compilation_unit_entity(), NIL, PARAMETER, pips_debug, print_expressions(), print_parameters(), set_enclosing_loops_map(), type_functional, and type_to_named_type().

Referenced by compile_mpi(), and outliner().

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

◆ outliner_patch_parameters()

void outliner_patch_parameters ( list  statements_to_outline,
list  referenced_entities,
list  effective_parameters,
list  formal_parameters,
statement  new_body,
statement  begin,
statement  end 
)

we need to patch parameters , effective parameters and body in C because parameters are passed by copy in function call it's not needed if

  • the parameter is only read (FI: or if it is written before it is read?)
  • it's an array / pointer

Here a scalar will be passed by address and a prelude/postlude will be used in the outlined module as below :

void new_module( int *scalar_0 ) { int scalar; scalar = *scalar_0; ... // Work on scalar ... *scalar_0 = scalar; }

Note FI: this is also useless when the variable does not appear in the out region of the outlined piece of code. However, the out effets and out regions are not available for every piece of code.

e is no longer a formal parameter, but a local variable

storage eos = entity_storage(e); // e's old storage

pips_assert("eos is a formal storage", storage_formal_p(eos));

formal fs = storage_formal(eos);

entity f = formal_function(fs); // In fact, f is not a function but a variable!

entity a = module_to_dynamic_area(f);

ram r = make_ram(f, a, UNKNOWN_RAM_OFFSET, NIL);

storage ens = make_storage_ram(r);

entity_storage(e) = ens;

free_storage(eos);

Parameters
statements_to_outlinetatements_to_outline
referenced_entitieseferenced_entities
effective_parametersffective_parameters
formal_parametersormal_parameters
new_bodyew_body
beginegin
endnd

Definition at line 809 of file outlining.c.

811 {
812  list iter = effective_parameters;
813  list riter = referenced_entities;
814 
815  FOREACH(PARAMETER,p,formal_parameters)
816  {
817  expression x = EXPRESSION(CAR(iter));
818  entity re = ENTITY(CAR(riter));
822 
826  bool entity_written=false;
827  FOREACH(STATEMENT,stmt,statements_to_outline) {
828  bool write_p = find_write_effect_on_entity(stmt,ex);
829  ifdebug(5) {
830  if(write_p) {
831  pips_debug(5,"Entity %s written by statement (%d) : \n",entity_name(ex),the_current_debug_level);
833  }
834  }
835  entity_written|=write_p;
836  }
837 
838  if( (!basic_pointer_p(variable_basic(v))) &&
840  entity_written
841  )
842  {
846  CONS(DIMENSION,
849  NIL),
850  NIL)
851  );
852 
855 
856  //Change at call site (scalar=>&scalar)
857  syntax s = expression_syntax(x); // FIXME Leak ?
860 
861 
862  //Create prelude && postlude
864 
865  // FIXME : is it ok to alias dereferenced expression in 2 statements ?
868 
869  // Cheat on effects
872 
873 
874  insert_statement(begin,in,true);
875  insert_statement(end,out,false);
876 
877  /* e is no longer a formal parameter, but a local variable */
878  pips_debug(4,"Add declaration for %s",entity_name(e));
879 
880  /* storage eos = entity_storage(e); // e's old storage */
881  /* pips_assert("eos is a formal storage", storage_formal_p(eos)); */
882  /* formal fs = storage_formal(eos); */
883  /* entity f = formal_function(fs); // In fact, f is *not* a function but a variable! */
884  /* // No dependent type assumed, should be a scalar type */
885  /* // since a pointer had to be introduced */
886  /* entity a = module_to_dynamic_area(f); */
887  /* ram r = make_ram(f, a, UNKNOWN_RAM_OFFSET, NIL); */
888  /* storage ens = make_storage_ram(r); */
889  /* // add_C_variable_to_area() to fix the offset? */
890  /* entity_storage(e) = ens; */
891  /* free_storage(eos); */
892 
893  // We could add a push_generated_variable_commenter()
894  // to explain the generation
896  add_declaration_statement(new_body,e);
898  }
899  }
900  if(type_variable_p(entity_type(re))) {
904  convert_pointer_to_array(e,re,x,statements_to_outline);
905 
906  }
907  }
908  POP(iter);
909  POP(riter);
910  }
911  pips_assert("no effective parameter left", ENDP(iter));
912 }
dimension make_dimension(expression a1, expression a2, list a3)
Definition: ri.c:565
static FILE * out
Definition: alias_check.c:128
void store_cumulated_rw_effects_list(statement, list)
bool find_write_effect_on_entity(statement, entity)
statement make_assign_statement(expression, expression)
Definition: statement.c:583
char end
Definition: gtk_status.c:82
int the_current_debug_level
Debugging functions.
Definition: debug.c:53
static void convert_pointer_to_array(entity e, entity re, expression x, list statements)
Definition: outlining.c:494
static string outlining_patched_variable_commenter(__attribute__((unused)) entity e)
Definition: outlining.c:70
void print_statement(statement)
Print a statement on stderr.
Definition: statement.c:98
#define X
Definition: r1.c:42
entity make_entity_copy_with_new_name(entity e, string global_new_name, bool move_initialization_p)
Create a copy of an entity, with (almost) identical type, storage and initial value if move_initializ...
Definition: entity.c:2463
bool array_type_p(type)
Definition: type.c:2942
#define variable_dimensions(x)
Definition: ri.h:3122
#define type_variable_p(x)
Definition: ri.h:2947

References add_C_variable_to_area(), add_declaration_statement(), ADDRESS_OF_OPERATOR_NAME, array_type_p(), basic_pointer, basic_pointer_p, CAR, CONS, convert_pointer_to_array(), copy_type(), DEREFERENCING_OPERATOR_NAME, DIMENSION, dummy_identifier, end, ENDP, ENTITY, entity_intrinsic(), entity_name, entity_to_expression(), entity_type, entity_undefined, entity_undefined_p, EXPRESSION, expression_reference(), expression_reference_p(), expression_syntax, find_write_effect_on_entity(), FOREACH, gen_append(), ifdebug, insert_statement(), int_to_expression(), make_assign_statement(), make_call(), make_dimension(), make_entity_copy_with_new_name(), make_expression(), make_syntax_call(), MakeUnaryCall(), NIL, normalized_undefined, offset, out, outlining_patched_variable_commenter(), PARAMETER, parameter_dummy, parameter_type, pips_assert, pips_debug, POP, pop_generated_variable_commenter(), print_statement(), push_generated_variable_commenter(), reference_variable, STATEMENT, store_cumulated_rw_effects_list(), the_current_debug_level, type_variable, type_variable_p, variable_basic, variable_dimensions, X, and x.

Referenced by compile_mpi(), and outliner().

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

◆ outliner_scan()

list outliner_scan ( entity  new_fun,
list  statements_to_outline,
statement  new_body 
)

Retrieve referenced entities

Retrieve declared entities

get the relative complements and create the parameter list

purge the functions from the parameter list, we assume they are declared externally also purge the formal parameters from other modules, gathered by get_referenced_entities but wrong here

function should be added to compilation unit

fortran function results must be declared in the new function

remove global variables if needed

sort list, and put parameters first

in some rare case, we can have too functions with the same local name

Parameters
new_funew_fun
statements_to_outlinetatements_to_outline
new_bodyew_body

Definition at line 555 of file outlining.c.

556 {
557  /* Retrieve referenced entities */
558  list referenced_entities = outliner_statements_referenced_entities(statements_to_outline);
559 
560  ifdebug(5) {
561  pips_debug(5,"Referenced entities :\n");
562  print_entities(referenced_entities);
563  }
564 
565  /* Retrieve declared entities */
567  list localized = statements_localize_declarations(statements_to_outline,new_fun,new_body);
569  list declared_entities = statements_to_declarations(statements_to_outline);
570  FOREACH(ENTITY,e,declared_entities)
572  declared_entities=gen_nconc(declared_entities,localized);
573 
574  /* get the relative complements and create the parameter list*/
575  gen_list_and_not(&referenced_entities,declared_entities);
576  gen_free_list(declared_entities);
577 
578 
579  /* purge the functions from the parameter list, we assume they are declared externally
580  * also purge the formal parameters from other modules, gathered by get_referenced_entities but wrong here
581  */
582  list tmp = gen_copy_seq(referenced_entities);
583  FOREACH(ENTITY,e,referenced_entities)
584  {
585  //basic b = entity_basic(e);
586  /* function should be added to compilation unit */
587  if(entity_function_p(e))
588  {
589  ;//AddEntityToModuleCompilationUnit(e,get_current_module_entity());
590  if(!fortran_module_p(new_fun)) /* fortran function results must be declared in the new function */
591  gen_remove_once(&referenced_entities,e);
592  }
593  }
594  gen_free_list(tmp);
595 
596 
597 
598  /* remove global variables if needed */
599  if(get_bool_property("OUTLINE_ALLOW_GLOBALS"))
600  {
602  entity cu = module_name_to_entity(cu_name);
603  list cu_decls = entity_declarations(cu);
604 
605  list tmp_list=NIL;
606 
607  FOREACH(ENTITY,e,referenced_entities)
608  {
609  if( !top_level_entity_p(e) && gen_chunk_undefined_p(gen_find_eq(e,cu_decls) ) )
610  tmp_list=CONS(ENTITY,e,tmp_list);
611  else if (gen_chunk_undefined_p(gen_find_eq(e,cu_decls)))
612  {
613  AddLocalEntityToDeclarations(e,new_fun,new_body);
614  }
615  }
616  gen_free_list(referenced_entities);
617  referenced_entities=tmp_list;
618  }
619 
620  /* sort list, and put parameters first */
621  sort_entities_with_dep(&referenced_entities);
622 
623 
624  /* in some rare case, we can have too functions with the same local name */
625  outline_remove_duplicates(&referenced_entities);
626  return referenced_entities;
627 }
#define gen_chunk_undefined_p(c)
Definition: genC.h:75
void gen_list_and_not(list *a, const list b)
Compute A = A inter non B:
Definition: list.c:963
void * gen_find_eq(const void *item, const list seq)
Definition: list.c:422
static void outline_remove_duplicates(list *entities)
Definition: outlining.c:531
list outliner_statements_referenced_entities(list statements)
outlining.c
Definition: outlining.c:251
static list statements_localize_declarations(list statements, entity module, statement module_statement)
Definition: outlining.c:420
void print_entities(list l)
Definition: entity.c:167

References AddLocalEntityToDeclarations(), compilation_unit_of_module(), CONS, ENTITY, entity_declarations, entity_function_p(), FOREACH, fortran_module_p(), gen_chunk_undefined_p, gen_copy_seq(), gen_find_eq(), gen_free_list(), gen_list_and_not(), gen_nconc(), gen_remove_once(), get_bool_property(), get_current_module_entity(), get_current_module_name(), ifdebug, module_name_to_entity(), NIL, outline_remove_duplicates(), outliner_statements_referenced_entities(), outlining_variable_commenter(), pips_debug, pop_generated_variable_commenter(), print_entities(), push_generated_variable_commenter(), sort_entities_with_dep(), statements_localize_declarations(), statements_to_declarations(), and top_level_entity_p().

Referenced by compile_mpi(), and outliner().

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

◆ outliner_smart_references_computation()

static hash_table outliner_smart_references_computation ( list  outlined_statements,
entity  new_module 
)
static

purge the list of referenced entities by replacing calls to a[i][j] where i is a constant in statements outlined_statements by a call to a single (new) variable

this will hold new referenced_entities list

first check candidates, that is array entities accessed by a constant index

we are looking for constant index, so only check equalities

it's ok, we can keep on finding constant indices

check for clashes

abort there , we could be smarter

we have gathered a sub array of e that is constant and we know its mode get ready for substitution in the statement

compute new dimensions

Definition at line 291 of file outlining.c.

292 {
293  list referenced_entities = outliner_statements_referenced_entities(outlined_statements);
294 
295  /* this will hold new referenced_entities list */
297  /* first check candidates, that is array entities accessed by a constant index */
298  FOREACH(ENTITY,e,referenced_entities)
299  {
300  FOREACH(STATEMENT,st,outlined_statements)
301  {
302  list regions = load_rw_effects_list(st);
303  list the_constant_indices = NIL;
305  FOREACH(REGION,reg,regions)
306  {
309  {
310  list constant_indices = NIL;
311  Psysteme sc = region_system(reg);
313  {
314  Variable phi = expression_to_entity(index);
315  expression index_value = expression_undefined;
316  /* we are looking for constant index, so only check equalities */
317  for(Pcontrainte iter = sc_egalites(sc);iter;iter=contrainte_succ(iter))
318  {
319  Pvecteur cvect = contrainte_vecteur(iter);
320  Value phi_coeff = vect_coeff(phi,cvect);
321  if(phi_coeff != VALUE_ZERO )
322  {
323  pips_assert("phi coef should be one",phi_coeff == VALUE_ONE);
324  Pvecteur lhs_vect = vect_del_var(cvect,phi);
325  vect_chg_sgn(lhs_vect);
326  pips_assert("phi coef should be mentioned only once",expression_undefined_p(index_value));
327  index_value = VECTEUR_NUL_P(lhs_vect) ? int_to_expression(0) : Pvecteur_to_expression(lhs_vect);
328  vect_rm(lhs_vect);
329  }
330  }
331  if(!expression_undefined_p(index_value))
332  {
333  /* it's ok, we can keep on finding constant indices */
334  constant_indices=CONS(EXPRESSION,index_value,constant_indices);
335  }
336  else break;
337  }
338  constant_indices=gen_nreverse(constant_indices);
339  /* check for clashes */
340  if(!ENDP(the_constant_indices) && ! gen_equals(constant_indices,the_constant_indices,(gen_eq_func_t)same_expression_p))
341  {
342  /* abort there , we could be smarter */
343  gen_full_free_list(the_constant_indices);
344  gen_full_free_list(constant_indices);
345  the_constant_indices=constant_indices=NIL;
346  break;
347  }
348  else if( ENDP(the_constant_indices) )
349  {
350  the_constant_indices=constant_indices;
351  mode=region_action(reg);
352  }
353  else if( action_read_p(mode) && action_write_p(region_action(reg)))
354  {
355  mode =region_action(reg);
356  }
357  }
358  }
359  /* we have gathered a sub array of e that is constant and we know its mode
360  * get ready for substitution in the statement */
361  if(!ENDP(the_constant_indices))
362  {
363  size_t nb_constant_indices = gen_length(the_constant_indices);
364  list entity_dimensions = variable_dimensions(type_variable(entity_type(e)));
365  size_t nb_dimensions = gen_length(entity_dimensions);
366 
367  /* compute new dimensions */
368  list new_dimensions = NIL;
369  size_t count_dims = 0;
370  for(list iter = entity_dimensions;!ENDP(iter);POP(iter))
371  {
372  ++count_dims;
373  if(count_dims==nb_constant_indices) { new_dimensions=gen_full_copy_list(CDR(iter));break; }
374  }
375 
376 
377  basic new_basic;
378  if(action_read_p(mode)&&nb_constant_indices==nb_dimensions)
379  new_basic=copy_basic(entity_basic(e));
380  else
381  {
382  type new_type = make_type_variable(
385  new_dimensions,
387  )
388  );
389  new_basic=make_basic_pointer(new_type);
390  }
391 
392  entity new_entity;
393  if(action_read_p(mode)&&nb_constant_indices==nb_dimensions)
394  {
396  entity_user_name(e),
397  new_module,
398  new_basic,
399  new_dimensions);
400  }
401  else
402  {
404  entity_user_name(e),
405  new_module,
406  new_basic);
407  }
408  outliner_smart_replacment(st,e,new_entity,nb_constant_indices);
409  expression effective_parameter = reference_to_expression(make_reference(e,the_constant_indices));
410  if(!(action_read_p(mode)&&nb_constant_indices==nb_dimensions))
411  effective_parameter=MakeUnaryCall(entity_intrinsic(ADDRESS_OF_OPERATOR_NAME),effective_parameter);
412  hash_put(entity_to_init,new_entity,effective_parameter);
413  }
414  }
415  }
416  gen_free_list(referenced_entities);
417 
418  return entity_to_init;
419 }
basic copy_basic(basic p)
BASIC.
Definition: ri.c:104
basic make_basic_pointer(type _field_)
Definition: ri.c:179
reference make_reference(entity a1, list a2)
Definition: ri.c:2083
#define VALUE_ZERO
int Value
#define VALUE_ONE
#define contrainte_succ(c)
#define contrainte_vecteur(c)
passage au champ vecteur d'une contrainte "a la Newgen"
#define region_any_reference(reg)
To be avoided.
#define region_action(reg)
#define region_system(reg)
#define REGION
list load_rw_effects_list(statement)
#define action_undefined
Definition: effects.h:277
#define action_write_p(x)
Definition: effects.h:314
#define action_read_p(x)
Definition: effects.h:311
bool gen_equals(const list l0, const list l1, gen_eq_func_t equals)
compares two lists using the functor given in parameters returns true if for all n,...
Definition: list.c:192
#define HASH_DEFAULT_SIZE
Definition: newgen_hash.h:26
bool(* gen_eq_func_t)(const void *, const void *)
Definition: newgen_types.h:115
static void outliner_smart_replacment(statement in, entity old, entity new, size_t nb_dims)
Definition: outlining.c:245
expression reference_to_expression(reference r)
Definition: expression.c:196
expression Pvecteur_to_expression(Pvecteur vect)
AP, sep 25th 95 : some usefull functions moved from static_controlize/utils.c.
Definition: expression.c:1825
entity expression_to_entity(expression e)
just returns the entity of an expression, or entity_undefined
Definition: expression.c:3140
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
entity make_new_array_variable_with_prefix(const char *, entity, basic, list)
J'ai ameliore la fonction make_new_scalar_variable_with_prefix
Definition: variable.c:785
entity make_new_scalar_variable_with_prefix(const char *, entity, basic)
Create a new scalar variable of type b in the given module.
Definition: variable.c:592
#define expression_undefined
Definition: ri.h:1223
#define variable_qualifiers(x)
Definition: ri.h:3124
#define expression_undefined_p(x)
Definition: ri.h:1224
void vect_chg_sgn(Pvecteur v)
void vect_chg_sgn(Pvecteur v): multiplie v par -1
Definition: scalaires.c:151
le type des coefficients dans les vecteurs: Value est defini dans le package arithmetique
Definition: vecteur-local.h:89
#define VECTEUR_NUL_P(v)
void * Variable
arithmetique is a requirement for vecteur, but I do not want to inforce it in all pips files....
Definition: vecteur-local.h:60
void vect_rm(Pvecteur v)
void vect_rm(Pvecteur v): desallocation des couples de v;
Definition: alloc.c:78
Pvecteur vect_del_var(Pvecteur v_in, Variable var)
Pvecteur vect_del_var(Pvecteur v_in, Variable var): allocation d'un nouveau vecteur egal a la project...
Definition: unaires.c:206
Value vect_coeff(Variable var, Pvecteur vect)
Variable vect_coeff(Variable var, Pvecteur vect): coefficient de coordonnee var du vecteur vect —> So...
Definition: unaires.c:228

References action_read_p, action_undefined, action_write_p, ADDRESS_OF_OPERATOR_NAME, CDR, CONS, contrainte_succ, contrainte_vecteur, copy_basic(), ENDP, ENTITY, entity_basic(), entity_intrinsic(), entity_type, entity_user_name(), EXPRESSION, expression_to_entity(), expression_undefined, expression_undefined_p, FOREACH, gen_equals(), gen_free_list(), gen_full_copy_list(), gen_full_free_list(), gen_length(), gen_nreverse(), HASH_DEFAULT_SIZE, hash_pointer, hash_put(), hash_table_make(), int_to_expression(), load_rw_effects_list(), make_basic_pointer(), make_new_array_variable_with_prefix(), make_new_scalar_variable_with_prefix(), make_reference(), make_type_variable(), make_variable(), MakeUnaryCall(), NIL, outliner_smart_replacment(), outliner_statements_referenced_entities(), pips_assert, POP, Pvecteur_to_expression(), reference_indices, reference_to_expression(), reference_variable, REGION, region_action, region_any_reference, region_system, same_entity_p(), same_expression_p(), STATEMENT, type_variable, VALUE_ONE, VALUE_ZERO, variable_dimensions, variable_qualifiers, vect_chg_sgn(), vect_coeff(), vect_del_var(), vect_rm(), and VECTEUR_NUL_P.

Referenced by outliner_init().

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

◆ outliner_smart_replacment()

static void outliner_smart_replacment ( statement  in,
entity  old,
entity  new,
size_t  nb_dims 
)
static

Definition at line 245 of file outlining.c.

246 {
247  ocontext_t ctxt = { old,new,nb_dims };
249 }
static void do_outliner_smart_replacment(reference r, ocontext_t *ctxt)
Definition: outlining.c:209
#define reference_domain
newgen_range_domain_defined
Definition: ri.h:338

References do_outliner_smart_replacment(), gen_context_recurse, gen_true2(), and reference_domain.

Referenced by outliner_smart_references_computation().

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

◆ outliner_statements_referenced_entities()

list outliner_statements_referenced_entities ( list  statements)

outlining.c

we don't want initial values of outer entities

gather local initial values skipped by the previous call

set to list

Parameters
statementstatements

Definition at line 251 of file outlining.c.

252 {
253  list referenced_entities = NIL;
254  set sreferenced_entities = set_make(set_pointer);
255 
256  FOREACH(STATEMENT, s, statements)
257  {
258  /* we don't want initial values of outer entities */
260  /* gather local initial values skipped by the previous call*/
262  FOREACH(ENTITY,e,decl) {
264  set_union(tmp,tmp,se);
265  set_free(se);
267  set_union(tmp,tmp,se);
268  set_free(se);
269  }
270 
271  ifdebug(7) {
272  pips_debug(7,"Statement :");
273  print_statement(s);
274  pips_debug(7,"referenced entities :");
276  fprintf(stderr,"\n");
277  }
278 
279  set_union(sreferenced_entities,tmp,sreferenced_entities);
280  set_free(tmp);
281  }
282  /* set to list */
283  referenced_entities=set_to_list(sreferenced_entities);
284  set_free(sreferenced_entities);
285  return referenced_entities;
286 }
list statement_to_declarations(void *)
Get a list of all variables declared recursively within a statement.
Definition: statement.c:3253
static bool skip_constants_intrinsics_members(entity e)
Definition: outlining.c:129
static bool skip_values(void *v)
Definition: outlining.c:125
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...

References ENTITY, entity_initial, entity_type, FOREACH, fprintf(), get_referenced_entities_filtered(), ifdebug, NIL, pips_debug, print_entities(), print_statement(), set_free(), set_make(), set_pointer, set_to_list(), set_union(), skip_constants_intrinsics_members(), skip_values(), STATEMENT, and statement_to_declarations().

Referenced by outliner_scan(), outliner_smart_references_computation(), and update_referenced_entities().

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

◆ outlining_patched_variable_commenter()

static string outlining_patched_variable_commenter ( __attribute__((unused)) entity  e)
static

Definition at line 70 of file outlining.c.

71 {
72  return strdup(" Declared as a patch variable by Pass Outlining\n");
73 }

References strdup().

Referenced by outliner_patch_parameters().

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

◆ outlining_variable_commenter()

static string outlining_variable_commenter ( __attribute__((unused)) entity  e)
static

Definition at line 65 of file outlining.c.

66 {
67  return strdup(" Declared by Pass Outlining\n");
68 }

References strdup().

Referenced by add_induction_var_to_local_declarations(), and outliner_scan().

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

◆ private_variables()

static list private_variables ( statement  stat)
static

Definition at line 185 of file outlining.c.

186 {
187  set s = get_private_entities(stat);
188 
189  list l =NIL;
190  SET_FOREACH(entity,e,s) {
191  struct cpv p = { .e=e, .rm=false };
195  0);
196  if(!p.rm)
197  l=CONS(ENTITY,e,l);
198  }
199  set_free(s);
200 
201  return l;
202 }
void gen_null(__attribute__((unused)) void *unused)
Ignore the argument.
Definition: genClib.c:2752
static void check_private_variables_call_walker(call c, struct cpv *p)
Definition: outlining.c:169
static bool check_private_variables_loop_walker(loop l, struct cpv *p)
Definition: outlining.c:179
static set get_private_entities(statement st)
try hard to reproduce in / out regions with only loop_locals it is time to move to regions ....
Definition: outlining.c:115
#define call_domain
newgen_callees_domain_defined
Definition: ri.h:58
Definition: outlining.c:162

References call_domain, check_private_variables_call_walker(), check_private_variables_loop_walker(), CONS, cpv::e, ENTITY, gen_context_multi_recurse(), gen_null(), gen_true(), get_private_entities(), loop_domain, NIL, cpv::rm, SET_FOREACH, and set_free().

Referenced by statements_localize_declarations().

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

◆ recursive_rename_types()

static entity recursive_rename_types ( entity  e,
const char *  cun 
)
static

Definition at line 948 of file outlining.c.

948  {
949  char * new_name;
950  asprintf(&new_name,"%s" MODULE_SEP_STRING "%s", cun, entity_local_name(e));
951  entity ne = gen_find_tabulated(new_name, entity_domain);
952  if(entity_undefined_p(ne))
953  ne = make_entity_copy_with_new_name(e, new_name, false);
954  free(new_name);
955  return ne;
956 }
void * gen_find_tabulated(const char *, int)
Definition: tabulated.c:218
#define entity_domain
newgen_syntax_domain_defined
Definition: ri.h:410

References asprintf, entity_domain, entity_local_name(), entity_undefined_p, free(), gen_find_tabulated(), make_entity_copy_with_new_name(), and MODULE_SEP_STRING.

Referenced by outliner_independent_recursively().

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

◆ remove_from_effective_parameters()

void remove_from_effective_parameters ( list  induction_var,
list effective_parameters 
)
Parameters
induction_varnduction_var
effective_parametersffective_parameters

Definition at line 1288 of file outlining.c.

1288  {
1289  list eff_par = gen_copy_seq(*effective_parameters);
1290  FOREACH(entity, ent, induction_var) {
1291  FOREACH(expression, exp, eff_par) {
1292  entity exp_ent = expression_to_entity(exp);
1293  if (!entity_undefined_p(exp_ent) && !strcmp(entity_minimal_user_name(exp_ent), entity_minimal_user_name(ent))) {
1294  printf("removing : \n");
1295  printf("effective parameter \n");
1296  printf("%s\n", entity_minimal_user_name(exp_ent));
1297  printf("induction var\n");
1298  printf("%s\n", entity_minimal_user_name(ent));
1299  printf("\n\n");
1300  gen_remove_once(effective_parameters, exp);
1301  }
1302  }
1303  }
1304  gen_free_list(eff_par);
1305 }
int printf()

References entity_minimal_user_name(), entity_undefined_p, exp, expression_to_entity(), FOREACH, gen_copy_seq(), gen_free_list(), gen_remove_once(), and printf().

+ Here is the call graph for this function:

◆ remove_from_formal_parameters()

void remove_from_formal_parameters ( list  induction_var,
list formal_parameters 
)
Parameters
induction_varnduction_var
formal_parametersormal_parameters

Definition at line 1268 of file outlining.c.

1268  {
1269  list form_par = gen_copy_seq(*formal_parameters);
1270  FOREACH(entity, ent, induction_var) {
1271  FOREACH(parameter, param, form_par) {
1272  dummy dum = parameter_dummy(param);
1273  entity param_ent = dummy_identifier(dum);
1274  if (!entity_undefined_p(ent) && !strcmp(entity_minimal_user_name(param_ent), entity_minimal_user_name(ent))) {
1275  printf("removing : \n");
1276  printf("formal parameter \n");
1277  printf("%s\n", entity_minimal_user_name(param_ent));
1278  printf("induction var\n");
1279  printf("%s\n", entity_minimal_user_name(ent));
1280  printf("\n\n");
1281  gen_remove_once(formal_parameters, param);
1282  }
1283  }
1284  }
1285  gen_free_list(form_par);
1286 }
int dummy
A dummy file, to prevent empty libraries from breaking builds.
Definition: dummy.c:41

References dummy_identifier, entity_minimal_user_name(), entity_undefined_p, FOREACH, gen_copy_seq(), gen_free_list(), gen_remove_once(), parameter_dummy, and printf().

+ Here is the call graph for this function:

◆ skip_constants_intrinsics_members()

static bool skip_constants_intrinsics_members ( entity  e)
static

Definition at line 129 of file outlining.c.

129  {
131  !member_entity_p(e);
132 }
bool member_entity_p(entity e)
Definition: entity.c:1921

References entity_not_constant_or_intrinsic_p(), and member_entity_p().

Referenced by outliner_statements_referenced_entities(), and sort_entities_with_dep().

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

◆ skip_values()

static bool skip_values ( void *  v)
static

Definition at line 125 of file outlining.c.

125  {
126  return !INSTANCE_OF(value,(gen_chunkp)v);
127 }
#define INSTANCE_OF(type, value)
polymorhism thanks to newgen !
A gen_chunk is used to store every object.
Definition: genC.h:58

References INSTANCE_OF.

Referenced by outliner_statements_referenced_entities(), and sort_entities_with_dep().

+ Here is the caller graph for this function:

◆ sort_entities_with_dep()

static void sort_entities_with_dep ( list l)
static

Definition at line 136 of file outlining.c.

137 {
139  FOREACH(ENTITY,e,*l)
140  {
141  if(!storage_rom_p(entity_storage(e))) { //<< to avoid gathering useless variables, unsure of the validity
143  set_del_element(e_ref,e_ref,e);
144  set_union(params,params,e_ref);
145  set_free(e_ref);
146  }
147  }
148 
150  set_assign_list(base,*l);
152 
155 
157  gen_free_list(*l);
158 
159  *l=gen_nconc(l_params,l_base);
160 }
struct paramStruct params
bdt base
Current expression.
Definition: bdt_read_paf.c:100
set set_assign_list(set, const list)
assigns a list contents to a set all duplicated elements are lost
Definition: set.c:474
set set_del_element(set, const set, const void *)
Definition: set.c:265
list set_to_sorted_list(const set, gen_cmp_func_t)
Definition: set.c:447
int(* gen_cmp_func_t)(const void *, const void *)
Definition: newgen_types.h:114
int compare_entities(const entity *pe1, const entity *pe2)
Comparison function for qsort.
Definition: entity.c:1328
#define storage_rom_p(x)
Definition: ri.h:2525

References base, compare_entities(), ENTITY, entity_storage, entity_type, FOREACH, gen_free_list(), gen_nconc(), get_referenced_entities_filtered(), params, set_assign_list(), set_del_element(), set_difference(), set_free(), set_make(), set_pointer, set_to_sorted_list(), set_union(), skip_constants_intrinsics_members(), skip_values(), and storage_rom_p.

Referenced by outliner_independent_recursively(), and outliner_scan().

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

◆ statements_localize_declarations()

static list statements_localize_declarations ( list  statements,
entity  module,
statement  module_statement 
)
static

We want to declare private variables that are never used else where as locals, but it may not be valid

Definition at line 420 of file outlining.c.

421 {
422  list sd = statements_to_declarations(statements);
423  list localized = NIL;
424  FOREACH(STATEMENT, s, statements)
425  {
426  /* We want to declare private variables **that are never used else where** as locals, but it may not
427  be valid */
428  list private_ents = private_variables(s);
430  FOREACH(ENTITY,e,private_ents)
431  {
433  if(formal_parameter_p(e) ||
434  (!get_bool_property("OUTLINE_ALLOW_GLOBALS") && top_level_entity_p(e) )) { // otherwise bad interaction with formal parameter pretty printing
435  localized=CONS(ENTITY,e,localized); // this is to make sure that the original `e' is removed from the referenced entities too
437  entity_user_name(e),
438  module,
440  );
441  replace_entity(s,e,ep);
442  e=ep;
443  }
445  localized=CONS(ENTITY,e,localized);
446  }
447  }
448  gen_free_list(private_ents);
449  }
450  gen_free_list(sd);
451  return localized;
452 }
static statement module_statement
Definition: alias_check.c:125
void gen_sort_list(list l, gen_cmp_func_t compare)
Sorts a list of gen_chunks in place, to avoid allocations...
Definition: list.c:796
static list private_variables(statement stat)
Definition: outlining.c:185
bool formal_parameter_p(entity)
Definition: variable.c:1489

References AddLocalEntityToDeclarations(), compare_entities(), CONS, copy_basic(), ENTITY, entity_basic(), entity_user_name(), FOREACH, formal_parameter_p(), gen_chunk_undefined_p, gen_find_eq(), gen_free_list(), gen_sort_list(), get_bool_property(), make_new_scalar_variable_with_prefix(), module, module_statement, NIL, private_variables(), replace_entity(), STATEMENT, statements_to_declarations(), and top_level_entity_p().

Referenced by outliner_scan().

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

◆ type_to_named_type()

static type type_to_named_type ( type  t,
entity  cu 
)
static

create a new type from given type, eventually renaming unnamed structures inside all new entities generated in the process are added to cu

create a new named type

Definition at line 631 of file outlining.c.

631  {
632  type tp = t;
633  variable tv = type_variable(tp);
634  basic b = variable_basic(tv);
635  if(basic_derived_p(b)) {
636  entity at = basic_derived(b);
637  bool is_struct = false;
638  if( (is_struct=strncmp(entity_user_name(at),DUMMY_STRUCT_PREFIX,sizeof(DUMMY_STRUCT_PREFIX)-1)==0)
639  || strncmp(entity_user_name(at),DUMMY_UNION_PREFIX, sizeof(DUMMY_UNION_PREFIX)-1)==0 )
640  {
641  /* create a new named type */
642  int index = 0;
643  char* name = strdup("");;
644  do {
645  free(name);
646  asprintf(&name, "%s" MODULE_SEP_STRING "%cstruct_%d", entity_local_name(cu), is_struct?STRUCT_PREFIX_CHAR:UNION_PREFIX_CHAR,index++);
648 
649  FOREACH(ENTITY,filed,is_struct?type_struct(entity_type(at)):type_union(entity_type(at))) {
650  }
651  list newfields = NIL;
652  list fields = is_struct ? type_struct(entity_type(at)) : type_union(entity_type(at));
653  FOREACH(ENTITY, field, fields) {
654  char * ename;
655  asprintf(&ename,"%s" MODULE_SEP_STRING "struct_%d%s" , entity_local_name(cu), index -1, strrchr(entity_name(field),MEMBER_SEP_CHAR));
656  entity e = make_entity(ename,
657  copy_type(entity_type(field)),
659  copy_value(entity_initial(field))
660  );
661  newfields=CONS(ENTITY,e,newfields);
662  }
663  newfields=gen_nreverse(newfields);
664  type newet;
665  if(is_struct) newet = make_type_struct(newfields);
666  else newet = make_type_union(newfields);
667 
668  entity newe = make_entity(name, newet, copy_storage(entity_storage(at)), copy_value(entity_initial(at)));
670  type newt =
673  make_basic_derived(newe),
676  )
677  );
678  return newt;
679  }
680  }
681  return copy_type(t);
682 }
basic make_basic_derived(entity _field_)
Definition: ri.c:182
type make_type_union(list _field_)
Definition: ri.c:2733
type make_type_struct(list _field_)
Definition: ri.c:2730
#define STRUCT_PREFIX_CHAR
Definition: naming-local.h:57
#define MEMBER_SEP_CHAR
Definition: naming-local.h:54
#define UNION_PREFIX_CHAR
Definition: naming-local.h:59
#define type_struct(x)
Definition: ri.h:2964
#define type_union(x)
Definition: ri.h:2967

References AddEntityToCompilationUnit(), asprintf, basic_derived, basic_derived_p, CONS, copy_storage(), copy_type(), copy_value(), DUMMY_STRUCT_PREFIX, DUMMY_UNION_PREFIX, ENTITY, entity_domain, entity_initial, entity_local_name(), entity_name, entity_storage, entity_type, entity_user_name(), FOREACH, free(), gen_chunk_undefined_p, gen_find_tabulated(), gen_full_copy_list(), gen_nreverse(), make_basic_derived(), make_entity, make_type_struct(), make_type_union(), make_type_variable(), make_variable(), MEMBER_SEP_CHAR, MODULE_SEP_STRING, NIL, strdup(), STRUCT_PREFIX_CHAR, type_struct, type_union, type_variable, UNION_PREFIX_CHAR, variable_basic, variable_dimensions, and variable_qualifiers.

Referenced by outliner_parameters().

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