PIPS
interactive_loop_transformation.c File Reference
#include <stdio.h>
#include <string.h>
#include "genC.h"
#include "linear.h"
#include "misc.h"
#include "pipsdbm.h"
#include "properties.h"
#include "ri.h"
#include "ri-util.h"
#include "text-util.h"
#include "control.h"
#include "conversion.h"
#include "pipsmake.h"
#include "prettyprint.h"
#include "transformations.h"
+ Include dependency graph for interactive_loop_transformation.c:

Go to the source code of this file.

Data Structures

struct  flag_loop_param_t
 

Functions

bool selected_loop_p (statement s)
 
bool interactive_loop_transformation (const char *module_name, statement(*loop_transformation)(list, bool(*)(statement)))
 
static void flag_loop (statement st, flag_loop_param_t *flp)
 
bool print_loops (const string module_name)
 
bool flag_loops (const string module_name)
 put a label on each doloop without label More...
 
static bool module_loops_walker (statement s, list *l)
 
char * loop_pragma (const char *module_name, const char *parent_loop)
 
char * module_loops (const char *module_name, const char *parent_loop)
 gather the list of enclosing loops expect flag_loops has been called before More...
 

Variables

entity selected_label
 Interface with pipsmake for interactive loop transformations: loop interchange, hyperplane method,... More...
 

Function Documentation

◆ flag_loop()

static void flag_loop ( statement  st,
flag_loop_param_t flp 
)
static

Definition at line 133 of file interactive_loop_transformation.c.

134 {
137  {
139  flp->new_label_created=true;
140  }
141  if( !get_bool_property("FLAG_LOOPS_DO_LOOPS_ONLY")
142  && instruction_forloop_p(i))
143  {
146  flp->new_label_created=true;
147  }
149  }
150 }
bool get_bool_property(const string)
FC 2015-07-20: yuk, moved out to prevent an include cycle dependency include "properties....
#define STRING(x)
Definition: genC.h:87
entity get_current_module_entity(void)
Get the entity of the current module.
Definition: static.c:85
#define CONS(_t_, _i_, _l_)
List element cell constructor (insert an element at the beginning of a list)
Definition: newgen_list.h:150
const char * entity_user_name(entity e)
Since entity_local_name may contain PIPS special characters such as prefixes (label,...
Definition: entity.c:487
bool entity_empty_label_p(entity e)
Definition: entity.c:666
entity make_new_label(entity module)
This function returns a new label.
Definition: entity.c:357
#define instruction_loop_p(x)
Definition: ri.h:1518
#define instruction_forloop_p(x)
Definition: ri.h:1536
#define statement_label(x)
Definition: ri.h:2450
#define statement_instruction(x)
Definition: ri.h:2458
char * strdup()

References CONS, entity_empty_label_p(), entity_user_name(), get_bool_property(), get_current_module_entity(), instruction_forloop_p, instruction_loop_p, flag_loop_param_t::loops, make_new_label(), flag_loop_param_t::new_label_created, statement_instruction, statement_label, strdup(), and STRING.

Referenced by flag_loops().

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

◆ flag_loops()

bool flag_loops ( const string  module_name)

put a label on each doloop without label

Parameters
module_name
Returns

prelude

run loop labeler

validate

ostlude

Parameters
module_nameodule_name

Definition at line 191 of file interactive_loop_transformation.c.

192 {
193  /* prelude */
196  ((statement) db_get_memory_resource(DBR_CODE, module_name, true) );
197  flag_loop_param_t flp = { .loops = NIL, .new_label_created = false };
198 
199  /* run loop labeler */
202 
203  /* validate */
206 
207  /*postlude*/
210  return true;
211 }
callees make_callees(list a)
Definition: ri.c:227
const char * module_name(const char *s)
Return the module part of an entity name.
Definition: entity_names.c:296
#define gen_context_recurse(start, ctxt, domain_number, flt, rwt)
Definition: genC.h:285
void reset_current_module_entity(void)
Reset the current module entity.
Definition: static.c:97
void reset_current_module_statement(void)
Reset the current module statement.
Definition: static.c:221
statement set_current_module_statement(statement)
Set the current module statement.
Definition: static.c:165
statement get_current_module_statement(void)
Get the current module statement.
Definition: static.c:208
entity set_current_module_entity(entity)
static.c
Definition: static.c:66
bool gen_true2(__attribute__((unused)) gen_chunk *u1, __attribute__((unused)) void *u2)
Definition: genClib.c:2785
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
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
static void flag_loop(statement st, flag_loop_param_t *flp)
entity module_name_to_entity(const char *mn)
This is an alias for local_name_to_top_level_entity.
Definition: entity.c:1479
#define statement_domain
newgen_sizeofexpression_domain_defined
Definition: ri.h:362

References db_get_memory_resource(), DB_PUT_MEMORY_RESOURCE, flag_loop(), gen_context_recurse, gen_true2(), get_current_module_statement(), flag_loop_param_t::loops, make_callees(), module_name(), module_name_to_entity(), flag_loop_param_t::new_label_created, NIL, reset_current_module_entity(), reset_current_module_statement(), set_current_module_entity(), set_current_module_statement(), and statement_domain.

+ Here is the call graph for this function:

◆ interactive_loop_transformation()

bool interactive_loop_transformation ( const char *  module_name,
statement(*)(list, bool(*)(statement))  loop_transformation 
)

DBR_CODE will be changed: argument "pure" should take false but this would be useless since there is only one version of code; a new version will be put back in the data base after transforming the loops

Get the loop label from the user

Reorder the module, because new statements have been generated.

Parameters
module_nameodule_name

Definition at line 73 of file interactive_loop_transformation.c.

77 {
78  const char *lp_label=NULL;
81  bool return_status = false;
82 
83  pips_assert("interactive_loop_transformation", entity_module_p(module));
84 
85  /* DBR_CODE will be changed: argument "pure" should take false but
86  this would be useless since there is only *one* version of code;
87  a new version will be put back in the data base after transforming
88  the loops */
89  s = (statement) db_get_memory_resource(DBR_CODE, module_name, true);
92 
93  /* Get the loop label from the user */
94  lp_label = get_string_property_or_ask("LOOP_LABEL","Which loop do you want to transform?\n"
95  "(give its label): ");
96  if( string_undefined_p( lp_label ) )
97  {
98  pips_user_error("please set %s property to a valid label\n","LOOP_LABEL");
99  }
100 
101  if(lp_label)
102  {
105  pips_user_error("loop label `%s' does not exist\n", lp_label);
106  }
107 
108  debug_on("INTERACTIVE_LOOP_TRANSFORMATION_DEBUG_LEVEL");
109 
110  look_for_nested_loop_statements(s, loop_transformation, selected_loop_p);
111 
112  debug_off();
113 
114  /* Reorder the module, because new statements have been generated. */
115  module_reorder(s);
116 
117  DB_PUT_MEMORY_RESOURCE(DBR_CODE,
119  (char*) s);
120  return_status = true;
121  }
124 
125  return return_status;
126 }
struct _newgen_struct_statement_ * statement
Definition: cloning.h:21
void look_for_nested_loop_statements(statement, statement(*)(list, bool(*)(statement)), bool(*)(statement))
look_for_nested_loops.c
entity selected_label
Interface with pipsmake for interactive loop transformations: loop interchange, hyperplane method,...
bool selected_loop_p(statement s)
#define debug_on(env)
Definition: misc-local.h:157
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
#define debug_off()
Definition: misc-local.h:160
#define pips_user_error
Definition: misc-local.h:147
#define string_undefined_p(s)
Definition: newgen_types.h:41
static char * module
Definition: pips.c:74
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
bool entity_module_p(entity e)
Definition: entity.c:683
entity find_label_entity(const char *, const char *)
util.c
Definition: util.c:43
#define entity_undefined_p(x)
Definition: ri.h:2762
#define statement_undefined
Definition: ri.h:2419

References db_get_memory_resource(), DB_PUT_MEMORY_RESOURCE, debug_off, debug_on, entity_module_p(), entity_undefined_p, find_label_entity(), get_string_property_or_ask(), look_for_nested_loop_statements(), module, module_name(), module_name_to_entity(), module_reorder(), pips_assert, pips_user_error, reset_current_module_entity(), reset_current_module_statement(), selected_label, selected_loop_p(), set_current_module_entity(), set_current_module_statement(), statement_undefined, strdup(), and string_undefined_p.

Referenced by loop_hyperplane(), loop_tiling(), and parallel_loop_tiling().

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

◆ loop_pragma()

char* loop_pragma ( const char *  module_name,
const char *  parent_loop 
)
Parameters
module_nameodule_name
parent_looparent_loop

Definition at line 225 of file interactive_loop_transformation.c.

226 {
227  // ensure pipsmake is ok with what we ask for
228  safe_make(DBR_LOOPS,module_name);
229 
230  // prelude
233  ((statement) db_get_memory_resource(DBR_CODE, module_name, true) );
234 
235  entity label = find_label_entity(module_name,parent_loop);
236  if(entity_undefined_p(label))
237  pips_user_error("label '%s' does not exist\n",parent_loop);
240  pips_user_error("label '%s' is not on a loop\n",parent_loop);
242  if(string_undefined_p(s)) s = strdup("");
245  return s;
246 }
bool safe_make(const char *res_n, const char *module_n)
Definition: pipsmake.c:1717
string extensions_to_string(extensions es, bool nl)
return a new allocated string with the string representation of the extensions.
Definition: extension.c:111
#define statement_extensions(x)
Definition: ri.h:2464
#define statement_undefined_p(x)
Definition: ri.h:2420
Definition: statement.c:54
statement find_loop_from_label(statement, entity)
Definition: util.c:218

References db_get_memory_resource(), entity_undefined_p, extensions_to_string(), find_label_entity(), find_loop_from_label(), get_current_module_statement(), module_name(), module_name_to_entity(), pips_user_error, reset_current_module_entity(), reset_current_module_statement(), safe_make(), set_current_module_entity(), set_current_module_statement(), statement_extensions, statement_undefined_p, strdup(), and string_undefined_p.

+ Here is the call graph for this function:

◆ module_loops()

char* module_loops ( const char *  module_name,
const char *  parent_loop 
)

gather the list of enclosing loops expect flag_loops has been called before

Parameters
module_namemodule we want the loops of
parent_loopnull if we wat to gather outer loops, a loop_label if we want to gather enclosed loops
Returns
list of strings, one string per loop label

this function is needed by pyps?

Parameters
module_nameodule_name
parent_looparent_loop

Definition at line 259 of file interactive_loop_transformation.c.

260 {
261  // ensure pipsmake is ok with what we ask for
262  safe_make(DBR_LOOPS,module_name);
263 
264  // prelude
267  ((statement) db_get_memory_resource(DBR_CODE, module_name, true) );
268  list loops = NIL;
269 
271  if(empty_string_p(parent_loop))
273  else {
274  entity label = find_label_entity(module_name,parent_loop);
275  if(entity_undefined_p(label))
276  pips_user_error("label '%s' does not exist\n",parent_loop);
279  pips_user_error("label '%s' is not on a loop\n",parent_loop);
281  }
282 
283  // run loop gatherer
284  gen_context_recurse(seed, &loops,
287 
288  // postlude
291  string out = list_to_string(loops);
293  if(out) out[strlen(out)-1]=0;
294  return out;
295 }
static FILE * out
Definition: alias_check.c:128
string list_to_string(list l)
Return the malloc()ed version of the concatenation of all the strings in the list.
Definition: args.c:74
static list loops
bool empty_string_p(const char *s)
Definition: entity_names.c:239
void gen_null2(__attribute__((unused)) void *u1, __attribute__((unused)) void *u2)
idem with 2 args, to please overpeaky compiler checks
Definition: genClib.c:2758
list gen_nreverse(list cp)
reverse a list in place
Definition: list.c:304
void gen_free_list(list l)
free the spine of the list
Definition: list.c:327
loop statement_loop(statement)
Get the loop of a statement.
Definition: statement.c:1374
static bool module_loops_walker(statement s, list *l)
#define loop_body(x)
Definition: ri.h:1644
The structure used to build lists in NewGen.
Definition: newgen_list.h:41

References db_get_memory_resource(), empty_string_p(), entity_undefined_p, find_label_entity(), find_loop_from_label(), gen_context_recurse, gen_free_list(), gen_nreverse(), gen_null2(), get_current_module_statement(), list_to_string(), loop_body, loops, module_loops_walker(), module_name(), module_name_to_entity(), NIL, out, pips_user_error, reset_current_module_entity(), reset_current_module_statement(), safe_make(), set_current_module_entity(), set_current_module_statement(), statement_domain, statement_loop(), statement_undefined, and statement_undefined_p.

+ Here is the call graph for this function:

◆ module_loops_walker()

static bool module_loops_walker ( statement  s,
list l 
)
static

Definition at line 213 of file interactive_loop_transformation.c.

214 {
215  if(statement_loop_p(s))
216  {
217  string tmp;
218  asprintf(&tmp,"%s ",label_local_name(statement_label(s)));
219  *l=CONS(STRING,tmp,*l);
220  return false;
221  }
222  return true;
223 }
bool statement_loop_p(statement)
Definition: statement.c:349
#define asprintf
Definition: misc-local.h:225
const char * label_local_name(entity e)
END_EOLE.
Definition: entity.c:604

References asprintf, CONS, label_local_name(), statement_label, statement_loop_p(), and STRING.

Referenced by module_loops().

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

◆ print_loops()

bool print_loops ( const string  module_name)

prelude

do the job

ostlude

Parameters
module_nameodule_name

Definition at line 152 of file interactive_loop_transformation.c.

153 {
154  /* prelude */
158 
159  /* do the job */
160  {
161  string local = db_build_file_resource_name(DBR_LOOPS_FILE, module_name, ".loops");
162  string dir = db_get_current_workspace_directory();
163  string full = strdup(concatenate(dir,"/",local, NULL));
164  free(dir);
165  FILE * fp = safe_fopen(full,"w");
166  text r = make_text(NIL);
168  {
170  }
171  print_text(fp,r);
172  free_text(r);
173  safe_fclose(fp,full);
174  free(full);
175  DB_PUT_FILE_RESOURCE(DBR_LOOPS_FILE, module_name, local);
176  }
177 
178  /*postlude*/
181  return true;
182 }
text make_text(list a)
Definition: text.c:107
void free_text(text p)
Definition: text.c:74
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
void free(void *)
#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
#define DB_PUT_FILE_RESOURCE
Put a file resource into the current workspace database.
Definition: pipsdbm-local.h:85
string db_build_file_resource_name(const char *rname, const char *oname, const char *suffix)
returns an allocated file name for a file resource.
Definition: lowlevel.c:169
string concatenate(const char *,...)
Return the concatenation of the given strings.
Definition: string.c:183
string db_get_current_workspace_directory(void)
Definition: workspace.c:96
struct _newgen_struct_callees_ * callees
Definition: ri.h:55
#define callees_callees(x)
Definition: ri.h:675
#define MAKE_ONE_WORD_SENTENCE(m, s)
#define ADD_SENTENCE_TO_TEXT(t, p)
void print_text(FILE *fd, text t)
Definition: print.c:195
@ full
Definition: union-local.h:65

References ADD_SENTENCE_TO_TEXT, callees_callees, concatenate(), db_build_file_resource_name(), db_get_current_workspace_directory(), db_get_memory_resource(), DB_PUT_FILE_RESOURCE, FOREACH, free(), free_text(), full, loops, MAKE_ONE_WORD_SENTENCE, make_text(), module_name(), module_name_to_entity(), NIL, print_text(), reset_current_module_entity(), reset_current_module_statement(), safe_fclose(), safe_fopen(), set_current_module_entity(), set_current_module_statement(), strdup(), and STRING.

+ Here is the call graph for this function:

◆ selected_loop_p()

bool selected_loop_p ( statement  s)

SG+EC 2010: The loop_label(statement_loop(s)) is kept for compatibility reasons but is invalid and should eventually be removed

Definition at line 63 of file interactive_loop_transformation.c.

64 {
65  /* SG+EC 2010:
66  The loop_label(statement_loop(s)) is kept for compatibility reasons
67  but is invalid and should eventually be removed */
68  return statement_loop_p(s) &&
71 }
#define loop_label(x)
Definition: ri.h:1646

References loop_label, selected_label, statement_label, statement_loop(), and statement_loop_p().

Referenced by interactive_loop_transformation(), and strip_mine().

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

Variable Documentation

◆ selected_label

entity selected_label

Interface with pipsmake for interactive loop transformations: loop interchange, hyperplane method,...

interactive_loop_transformation.c

Definition at line 61 of file interactive_loop_transformation.c.

Referenced by interactive_loop_transformation(), print_loopnest_dependence_cone(), selected_loop_p(), and strip_mine().