PIPS
phrase_distributor_control_code.c
Go to the documentation of this file.
1 /*
2 
3  $Id: phrase_distributor_control_code.c 23412 2017-08-09 15:07:09Z irigoin $
4 
5  Copyright 1989-2016 MINES ParisTech
6 
7  This file is part of PIPS.
8 
9  PIPS is free software: you can redistribute it and/or modify it
10  under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  any later version.
13 
14  PIPS is distributed in the hope that it will be useful, but WITHOUT ANY
15  WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  FITNESS FOR A PARTICULAR PURPOSE.
17 
18  See the GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with PIPS. If not, see <http://www.gnu.org/licenses/>.
22 
23 */
24 #ifdef HAVE_CONFIG_H
25  #include "pips_config.h"
26 #endif
27 #include <stdio.h>
28 #include <ctype.h>
29 
30 #include "genC.h"
31 #include "linear.h"
32 #include "ri.h"
33 #include "effects.h"
34 
35 #include "resources.h"
36 
37 #include "misc.h"
38 #include "ri-util.h"
39 #include "effects-util.h"
40 #include "pipsdbm.h"
41 
42 #include "text-util.h"
43 #include "properties.h"
44 #include "prettyprint.h"
45 
46 #include "dg.h"
47 
50 
51 #include "graph.h"
52 
53 #include "ray_dte.h"
54 #include "sommet.h"
55 #include "sg.h"
56 #include "polyedre.h"
57 #include "semantics.h"
58 #include "control.h"
59 #include "callgraph.h"
60 
61 #include "phrase_tools.h"
62 
63 #include "effects-generic.h"
64 #include "effects-simple.h"
65 #include "effects-convex.h"
66 
67 #include "transformer.h"
68 
69 #include "phrase_distribution.h"
70 
71 /**
72  * Create new variable parameter for a newly created module
73  */
75  const char* parameter_name,
76  const char* module_name,
77  entity module,
78  int param_nb)
79 {
81  parameter new_parameter;
83  list module_parameters;
84 
87  parameter_name,
88  NULL),
90  {
91  /* This entity does not exist, we can safely create it */
92 
95  parameter_name, NULL)),
99 
101 
104 
105  new_parameter = make_parameter (entity_type(new_variable),
107  make_dummy_identifier(new_variable)/*SG used to be strdup("")*/);
108 
110 
112  = CONS(PARAMETER, new_parameter, module_parameters);
113 
114  return new_variable;
115  }
116  else
117  {
118  pips_internal_error("Entity already exist: %s", parameter_name);
119  return NULL;
120  }
121 }
122 
123 /**
124  * Create new integer variable parameter for a newly created module
125  */
127  const char* module_name,
128  entity module,
129  int param_nb)
130 {
133  parameter_name,
134  module_name,
135  module,
136  param_nb);
137 }
138 
139 /**
140  * Store (PIPDBM) newly created module module with module_statement
141  * as USER_FILE by saving pretty printing
142  */
143 void store_new_module (const char* module_name,
144  entity module,
146 {
147  string source_file;
148  text code;
149 
150  pips_debug(2, "[BEGIN] store_new_module [%s]\n", module_name);
151  ifdebug(2) {
152  entity set_entity = get_current_module_entity();
155  pips_debug(2, "Statement for module: ");
157  pips_debug(7, "Declarations for module: \n");
158  MAP (ENTITY, e, {
159  pips_debug(2, "Declared entity %s\n", entity_global_name(e));
161  fprint_environment(stderr, module);
163  set_current_module_entity(set_entity);
164  }
165 
169  DBR_SOURCE_FILE,
170  ".f",
171  code);
173 
174  source_file = db_build_file_resource_name(DBR_SOURCE_FILE, module_name, ".f");
175 
176  pips_debug(5, "Source file : [%s]\n", source_file);
177 
178  DB_PUT_NEW_FILE_RESOURCE (DBR_USER_FILE, module_name, source_file);
179  DB_PUT_NEW_FILE_RESOURCE (DBR_INITIAL_FILE, module_name, source_file);
180 
183  DBR_INITIAL_FILE,
184  ".f_initial",
185  code);
187 
188  pips_debug(2, "[END] store_new_module [%s]\n", module_name);
189 }
190 
191 /**
192  * Creates and declares a new variable for a newly created common
193  */
195 {
196  int old_size, variable_size;
197 
198  string var_global_name = strdup(concatenate(module_local_name(module),MODULE_SEP_STRING,
199  name,NULL));
200  type var_type = make_type(is_type_variable, var);
201  storage var_storage = storage_undefined;
202  value var_value = make_value_unknown();
203  entity e = make_entity(var_global_name,var_type,var_storage,var_value);
204  list old_layout = area_layout(type_area(entity_type(common)));
205  old_size = area_size(type_area(entity_type(common)));
206  variable_size = storage_space_of_variable(e);
207  pips_debug(2, "New variable %s created with size %d (old_size was:%d)\n", name, variable_size, old_size);
209  (make_ram(module,common,old_size,NIL)));
210  area_layout(type_area(entity_type(common))) = gen_nconc(old_layout,CONS(ENTITY,e,NIL));
211  /* gen_nreverse(CONS(ENTITY,e,old_layout)); */
212  area_size(type_area(entity_type(common))) = old_size+variable_size;
214  return e;
215 }
216 
217 /**
218  * Creates and declares a new scalar variable for a newly created common
219  */
221 {
222  return create_new_common_variable( name, module, common, make_variable(b, NIL,NIL));
223 }
224 
225 /**
226  * Creates and declares a new integer scalar variable for a newly created common
227  */
229 {
231 }
232 
233 /**
234  * Creates all the things that need to be created in order to declare common
235  * in module (all the variable are created)
236  */
238 {
239  list new_variables = NIL;
240  list primary_variables = NIL;
241  bool is_primary_area = true;
242  int totalized_offset = -1;
243 
244  /* Compute the primary variables */
245  MAP (ENTITY, v, {
246  if (is_primary_area) {
248  if (offset > totalized_offset) {
249  totalized_offset = offset;
250  primary_variables = CONS (ENTITY,v,primary_variables);
251  }
252  else {
253  is_primary_area = false;
254  }
255  }
256  }, area_layout(type_area(entity_type(common))));
257 
258  primary_variables = gen_nreverse(primary_variables);
259 
260  ifdebug(4) {
261  pips_debug(4, "Current layout for %s\n", entity_global_name(common));
262  MAP(ENTITY, v, {
263  pips_debug(4, "[%s] offset %"PRIdPTR"\n", entity_global_name(v),ram_offset(storage_ram(entity_storage(v))));
264  }, area_layout(type_area(entity_type(common))));
265  pips_debug(4, "Primary variables for %s\n", entity_global_name(common));
266  MAP(ENTITY, v, {
267  pips_debug(4, "[%s] offset %"PRIdPTR" PRIMARY\n", entity_global_name(v),ram_offset(storage_ram(entity_storage(v))));
268  }, primary_variables);
269  }
270 
271  MAP (ENTITY, v, {
272 
273  /* We iterate on the primary variables declared in the common and
274  create a new variable mapping the one declared in common */
275 
277  const char* name = entity_local_name(v);
278  int v_offset = ram_offset(storage_ram(entity_storage(v)));
279 
280  /* Creates the name for the new variable */
281  string var_global_name = strdup(concatenate(module_local_name(module),
283  name,NULL));
284 
285  /* Copy type of variable */
286  type var_type = copy_type(entity_type(v));
287 
288  /* Create storage for new variable */
289  storage var_storage = make_storage(is_storage_ram,
290  (make_ram(module,
291  common,
292  v_offset,
293  NIL)));
294  /* Copy initial value of variable */
295  value var_value = copy_value(entity_initial(v));
296 
297  pips_debug(7, "Build variable %s\n", var_global_name);
298 
299  /* Build the new variable */
300  new_variable = make_entity(var_global_name,var_type,var_storage,var_value);
301 
302  /* Mark for addition */
303  new_variables = gen_nconc(new_variables,CONS(ENTITY,new_variable,NIL));
304 
305  pips_debug(7, "Add to declarations %s\n", var_global_name);
306 
307  /* Add to declarations.... */
309 
310  pips_debug(7, "New common variable %s declared\n", var_global_name);
311 
312  }, primary_variables);
313 
314  /* Add those new variable to common layout */
315  {
316  list old_layout = area_layout(type_area(entity_type(common)));
317  area_layout(type_area(entity_type(common))) = gen_nconc(old_layout,new_variables);
318  }
319 
321  pips_debug(3, "Common %s declared in module %s\n",
322  entity_local_name(common),
324 }
325 
326 /*
327  * Return CONTROLIZED_STATEMENT_COMMENT
328  */
330 {
331  char *buffer;
332  asprintf(&buffer,
334  entity_local_name(function));
335  return (buffer);
336 }
337 
338 /*
339  * Return IN_PARAM_ID_NAME
340  */
342 {
343  char *buffer;
344  asprintf(&buffer,
347  entity_local_name(function));
348  return (buffer);
349 }
350 
351 /*
352  * Return OUT_PARAM_ID_NAME
353  */
355 {
356  char *buffer;
357  asprintf(&buffer,
360  entity_local_name(function));
361  return (buffer);
362 }
363 
364 /*
365  * Return FUNCTION_ID_NAME
366  */
367 string get_function_id_name (entity function)
368 {
369  char *buffer;
370  asprintf(&buffer,
372  entity_local_name(function));
373  return strdup(buffer);
374 }
375 
376 /*
377  * Return FUNCTION_COMMON_NAME
378  */
379 static string get_function_common_name (entity function)
380 {
381  char *buffer;
382  asprintf(&buffer,
384  entity_local_name(function));
385  return strdup(buffer);
386 }
387 
388 /*
389  * Return COMMON_PARAM_NAME
390  */
392 {
393  char *buffer;
394  asprintf(&buffer,
397  entity_local_name(function));
398  return strdup(buffer);
399 }
400 
401 /*
402  * Return UNIT_ID_NAME
403  */
404 static string get_unit_id_name (int unit)
405 {
406  char *buffer;
408  return strdup(buffer);
409 }
410 
411 /*
412  * Return SEND_PARAMETER_MODULE_NAME
413  */
415 {
416  char *buffer;
418  return strdup(buffer);
419 }
420 
421 /*
422  * Return RECEIVE_PARAMETER_MODULE_NAME
423  */
425 {
426  char *buffer;
428  return strdup(buffer);
429 }
430 
431 /**
432  * Return entity named name in specified module
433  */
435 {
436  /* Is it the main module ? */
437  if (strchr(entity_local_name(module),'%') != NULL) {
438  return FindEntity(entity_local_name(module)+1,name);
439  }
440  else {
441  return FindEntity(entity_local_name(module),name);
442  }
443 
444 }
445 
446 /**
447  * Build and return CONTROL_DATA global common used to store global
448  * information on phrase distribution controlization and initialization of
449  * values contained in CONTROL_DATA common
450  */
451 static statement
453  statement module_stat,
454  entity *global_common,
455  int number_of_deployment_units,
456  hash_table ht_calls,
457  hash_table ht_in_regions,
458  hash_table ht_out_regions)
459 {
460  list stats_list = CONS(STATEMENT,module_stat,NIL);
461  statement new_stat;
462  sequence new_sequence;
463  int i;
464  list l_in, l_out;
465  const char* function_name;
466  int id_function, id_param;
467  entity units_nb_variable;
468  entity functions_nb_variable;
469 
470  *global_common = make_new_common(CONTROL_DATA_COMMON_NAME,
471  main_module);
473  main_module,
474  *global_common);
475  new_stat = make_assignement_statement
476  (units_nb_variable,
477  int_to_expression (number_of_deployment_units), NULL);
478  stats_list = CONS (STATEMENT, new_stat,stats_list);
479 
480  if (number_of_deployment_units > 1) {
481  for (i=1; i<= number_of_deployment_units; i++) {
482  entity unit_id_variable =
484  main_module,
485  *global_common);
486  new_stat = make_assignement_statement
487  (unit_id_variable,
488  int_to_expression (i), NULL);
489  stats_list = CONS (STATEMENT, new_stat,stats_list);
490  }
491  }
492 
493 
494  functions_nb_variable =
496  main_module,
497  *global_common);
498 
499  new_stat = make_assignement_statement
500  (functions_nb_variable,
501  int_to_expression (hash_table_entry_count(ht_calls)), NULL);
502  stats_list = CONS (STATEMENT, new_stat,stats_list);
503 
504  id_function = 1;
505 
506  HASH_MAP (externalized_function, l_calls_for_function, {
507 
508  entity function = (entity)externalized_function;
509  entity function_id_variable;
510  function_name = entity_local_name(function);
511  pips_debug(2, "Function [%s]\n",function_name);
512 
513  function_id_variable =
515  (get_function_id_name(function),
516  main_module,
517  *global_common);
518  new_stat = make_assignement_statement
519  (function_id_variable,
520  int_to_expression (id_function++), NULL);
521  stats_list = CONS (STATEMENT, new_stat,stats_list);
522 
523  id_param = 1;
524 
525  l_in = (list)hash_get(ht_in_regions,function);
526  l_out = (list)hash_get(ht_out_regions,function);
527 
528  /*l_in = regions_dup(load_statement_in_regions(s));
529  l_out = regions_dup(load_statement_out_regions(s));*/
530 
531  MAP (REGION, reg, {
534  entity param_id_variable =
536  (get_in_param_id_name(variable,function),
537  main_module,
538  *global_common);
539  new_stat = make_assignement_statement
540  (param_id_variable,
541  int_to_expression (id_param++), NULL);
542  stats_list = CONS (STATEMENT, new_stat,stats_list);
543  }, l_in);
544 
545  MAP (REGION, reg, {
548  entity param_id_variable =
550  (get_out_param_id_name(variable,function),
551  main_module,
552  *global_common);
553  new_stat = make_assignement_statement
554  (param_id_variable,
555  int_to_expression (id_param++), NULL);
556  stats_list = CONS (STATEMENT, new_stat,stats_list);
557  }, l_out);
558 
559  }, ht_calls);
560 
561  new_sequence = make_sequence (stats_list);
562 
568  new_sequence),
569  NIL,NULL,
571 
572 }
573 
574 /**
575  * Creates and returns a common used to store variable for communications
576  * between control code and externalized code
577  */
579  entity externalized_function,
580  list params_regions,
581  int number_of_deployment_units)
582 {
583  entity returned_common;
584 
585  returned_common
586  = make_new_common(get_function_common_name (externalized_function),
587  main_module);
588 
589  /* Creates params variables */
590  MAP (REGION, reg, {
591  entity in_variable = region_entity(reg);
592  variable var = copy_variable(type_variable(entity_type(in_variable)));
593  /* If many deployment units, add dimension to handle those different units */
594  if (number_of_deployment_units > 1) {
595  list l_dimensions = variable_dimensions(var);
597  = gen_nconc(l_dimensions,
598  CONS(DIMENSION,
599  make_dimension (int_to_expression(1),int_to_expression (number_of_deployment_units), NIL),
600  NIL));
601  }
602  create_new_common_variable(get_common_param_name(in_variable,externalized_function),
603  main_module,
604  returned_common,
605  var);
606  }, params_regions);
607 
608  return returned_common;
609 }
610 
611 
612 /**
613  * Main function for PHRASE_DISTRIBUTION_CONTROL_CODE
614  */
616  entity module)
617 {
618  statement returned_statement = module_stat;
619  list l_calls;
620  const char* function_name;
621 
622  entity start_ru_module;
623  entity wait_ru_module;
624  statement start_ru_module_statement;
625  statement wait_ru_module_statement;
626 
627  entity global_common;
628  entity externalized_fonction_common;
629  list l_commons = NIL;
630 
631  hash_table ht_calls;
632  hash_table ht_params;
633  hash_table ht_private;
634  hash_table ht_in_regions;
635  hash_table ht_out_regions;
636 
637  hash_table ht_in_communications = hash_table_make(hash_pointer, 0);
638  hash_table ht_out_communications = hash_table_make(hash_pointer, 0);
639 
640  int number_of_deployment_units;
641  int unit_id;
642 
643  /* We identify all the statements containing an externalized-call tag */
645  module_stat);
646 
647  /* Compute the context of distribution, before to controlize */
649  module_stat,
650  module,
651  &ht_calls,
652  &ht_params,
653  &ht_private,
654  &ht_in_regions,
655  &ht_out_regions);
656 
657 
658  if (hash_table_entry_count (ht_calls)) {
659 
660  /* OK, be begin deployement... */
661 
662  string resp;
663 
664  /* Get the loop label form the user */
665  resp = user_request("Deployment on how many externalized units ?\n"
666  "(give its number > 0): ");
667 
668  if (sscanf(resp,"%d",&number_of_deployment_units) > 0) {
669 
670  pips_debug(2, "Deployment on %d units\n", number_of_deployment_units);
671 
672  /* Declare global common for controlization and make initializations */
673  returned_statement
675  module_stat,
676  &global_common,
677  number_of_deployment_units,
678  ht_calls,
679  ht_in_regions,
680  ht_out_regions);
681 
682  /* Let's begin to iterate on all externalized functions,
683  * in order to build commons and controlization modules */
684 
685  pips_debug(2, "Found %d externalized functions\n", hash_table_entry_count(ht_calls));
686 
687  HASH_MAP (externalized_function, calls_for_f, {
688 
689  entity f = (entity)externalized_function;
690 
691  /* Get the function name */
692  function_name = entity_local_name(f);
693 
694  pips_debug(2, "Found %zd calls for externalized function %s\n",
695  gen_length((list)calls_for_f),
696  function_name);
697 
698  /* Creates a common used to store variable for communications
699  * between control code and externalized code */
700  externalized_fonction_common =
702  f,
703  (list)hash_get(ht_params,f),
704  number_of_deployment_units);
705 
706  /* And register it to the list of commons */
707  l_commons = CONS(ENTITY, externalized_fonction_common, l_commons);
708 
709  pips_debug(2, "Register input communications\n");
710  register_scalar_communications (&ht_in_communications,
711  f,
712  (list)hash_get(ht_in_regions,f));
713 
714  pips_debug(2, "Register output communications\n");
715  register_scalar_communications (&ht_out_communications,
716  f,
717  (list)hash_get(ht_out_regions,f));
718 
719  pips_debug(2, "Register and create ARRAY input communications\n");
721  (list)hash_get(ht_in_regions,f),
722  global_common,
723  externalized_fonction_common,
724  number_of_deployment_units);
725 
726  pips_debug(2, "Register and create ARRAY output communications\n");
728  (list)hash_get(ht_out_regions,f),
729  global_common,
730  externalized_fonction_common,
731  number_of_deployment_units);
732 
733  }, ht_calls);
734 
735  /* Build START_RU module */
736  start_ru_module = make_start_ru_module (ht_params,
737  &start_ru_module_statement,
738  number_of_deployment_units,
739  global_common,
740  l_commons);
741 
742  /* Build WAIT_RU module */
743  wait_ru_module = make_wait_ru_module (&wait_ru_module_statement,
744  number_of_deployment_units,
745  global_common,
746  l_commons);
747 
748 #if 0
749  /* Build SEND_PARAMS modules */
750  list send_params_modules = make_send_scalar_params_modules (ht_in_communications,
751  number_of_deployment_units,
752  global_common,
753  l_commons);
754 
755  /* Build RECEIVE_PARAMS modules */
756  list receive_params_modules = make_receive_scalar_params_modules (ht_out_communications,
757  number_of_deployment_units,
758  global_common,
759  l_commons);
760 #endif
761 
762  /* Let's begin to iterate on all externalized functions and statements,
763  * in order to add controlization code */
764 
765  HASH_MAP (externalized_function, calls_for_f, {
766 
767  entity f = (entity)externalized_function;
768  list l_stats = NIL;
769  entity func_id_variable;
770  entity unit_id_variable = NULL;
771 
772  /* Get the function name */
773  function_name = entity_local_name(f);
774 
775  /* Retrieve variables func_id_variable and unit_id_variable */
776  func_id_variable = entity_in_module(get_function_id_name(f), module);
777 
778  /* Iterate on all the statements where externalized function is called */
779 
780  MAP (STATEMENT, s, {
781 
782  l_stats = NIL;
783  unit_id = 0;
784 
785  if (number_of_deployment_units > 1) {
786  char *question;
787  unit_id = 0;
788  do {
789  asprintf (&question, "Deployment of function %s on which units ?\n(give its number 1-%d):", function_name, number_of_deployment_units);
790  resp = user_request(question);
791  sscanf(resp,"%d",&unit_id);
792  free(question);
793  }
794  while ((unit_id <1) || (unit_id > number_of_deployment_units));
795 
796  /* Some debug */
797  pips_debug(2, "Externalized function [%s] being executed on unit %d:\n", function_name, unit_id);
798  ifdebug(2) {
799  pips_debug(2, "Current statement is:\n");
800  print_statement(s);
801  }
802 
803  unit_id_variable = entity_in_module (get_unit_id_name(unit_id), module);
804 
805  }
806 
807 #if 0
808  /* Get the called module */
809  statement called_module_stat = (statement) db_get_memory_resource(DBR_CODE,
810  function_name,
811  true);
812  entity called_module = module_name_to_entity(function_name);
813 #endif
814 
815 
816  /* SEND PARAMS calls */
817  MAP (REGION, reg, {
818 
820  entity send_param_module;
821  entity param_id_variable;
822  statement new_stat;
823 
824  list call_params = NIL;
825 
826  send_param_module = module_name_to_entity(get_send_param_module_name(f, reg));
827  pips_debug(7, "Call to [%s]\n", entity_local_name(send_param_module));
828  pips_debug(7, "Concerned entity is [%s]\n", entity_local_name(param));
829 
830  call_params = CONS (EXPRESSION,
831  entity_to_expression(func_id_variable),
832  call_params);
833  if (number_of_deployment_units > 1) {
834  call_params = CONS (EXPRESSION,
835  entity_to_expression(unit_id_variable),
836  call_params);
837  }
838  param_id_variable = entity_in_module (get_in_param_id_name(param,f),
839  module);
840  call_params = CONS (EXPRESSION,
841  entity_to_expression(param_id_variable),
842  call_params);
843  call_params = CONS (EXPRESSION,
845  call_params);
846 
847 
848  if (!region_scalar_p(reg))
849  {
850  /* Add dynamic variables */
851 
852  list l_reg_params; /* list of entities: phi1, phi2,... */
853  list l_reg_variables; /* list of dynamic variables....*/
854  compute_region_variables(reg,&l_reg_params,&l_reg_variables);
855 
856  MAP (ENTITY, dyn_var, {
857  call_params = CONS (EXPRESSION,
858  entity_to_expression(dyn_var),
859  call_params);
860  }, l_reg_variables);
861  }
862 
863 
864  new_stat = make_statement(entity_empty_label(),
869  make_call(send_param_module,
870  gen_nreverse(call_params))),
871  NIL,NULL,
873 
874  l_stats = CONS (STATEMENT,
875  new_stat,
876  l_stats);
877 
878  }, (list)hash_get(ht_in_regions,f));
879 
880  /* START_RU_CALL */
881  {
882  list start_ru_call_params = CONS(EXPRESSION,
883  entity_to_expression(func_id_variable),
884  (number_of_deployment_units>1)?CONS(EXPRESSION,
885  entity_to_expression(unit_id_variable),
886  NIL):NIL);
887  l_stats = CONS (STATEMENT,
893  make_call(start_ru_module,
894  start_ru_call_params)),
895  NIL,NULL,
897  l_stats);
898  }
899 
900  /* WAIT_RU_CALL */
901  {
902  list wait_ru_call_params = CONS(EXPRESSION,
903  entity_to_expression(func_id_variable),
904  (number_of_deployment_units>1)?CONS(EXPRESSION,
905  entity_to_expression(unit_id_variable),
906  NIL):NIL);
907  l_stats = CONS (STATEMENT,
913  make_call(wait_ru_module,
914  wait_ru_call_params)),
915  NIL,NULL,
917  l_stats);
918  }
919 
920  /* RECEIVE PARAMS calls */
921 
922  MAP (REGION, reg, {
923 
925  entity receive_param_module;
926  entity param_id_variable;
927  statement new_stat;
928 
929  list call_params = NIL;
930 
931  receive_param_module = module_name_to_entity(get_receive_param_module_name(f, reg));
932  pips_debug(7, "Call to [%s]\n", entity_local_name(receive_param_module));
933  pips_debug(7, "Concerned entity is [%s]\n", entity_local_name(param));
934 
935  call_params = CONS (EXPRESSION,
936  entity_to_expression(func_id_variable),
937  call_params);
938  if (number_of_deployment_units > 1) {
939  call_params = CONS (EXPRESSION,
940  entity_to_expression(unit_id_variable),
941  call_params);
942  }
943  param_id_variable = entity_in_module (get_out_param_id_name(param,f),
944  module);
945  call_params = CONS (EXPRESSION,
946  entity_to_expression(param_id_variable),
947  call_params);
948  call_params = CONS (EXPRESSION,
950  call_params);
951 
952 
953  if (!region_scalar_p(reg))
954  {
955  /* Add dynamic variables */
956 
957  list l_reg_params; /* list of entities: phi1, phi2,... */
958  list l_reg_variables; /* list of dynamic variables....*/
959  compute_region_variables(reg,&l_reg_params,&l_reg_variables);
960 
961  MAP (ENTITY, dyn_var, {
962  call_params = CONS (EXPRESSION,
963  entity_to_expression(dyn_var),
964  call_params);
965  }, l_reg_variables);
966  }
967 
968  new_stat = make_statement(entity_empty_label(),
973  make_call(receive_param_module,
974  gen_nreverse(call_params))),
975  NIL,NULL,
977 
978  l_stats = CONS (STATEMENT,
979  new_stat,
980  l_stats);
981 
982  }, (list)hash_get(ht_out_regions,f));
983 
984  /* Now, just inverse list of statements */
985 
986  l_stats = gen_nreverse(l_stats);
987 
988  /* And replace CALL instruction by SEQUENCE instruction */
989 
992  make_sequence(l_stats));
993 
994  ifdebug(7) {
995  pips_debug(7, "After controlization, statement is\n");
996  print_statement(s);
997  }
998 
999  }, (list)calls_for_f);
1000 
1001  pips_debug(2, "Controlization is done on [%s]\n", entity_local_name(f));
1002 
1003  }, ht_calls);
1004 
1005 
1006  hash_table_free(ht_calls);
1007  hash_table_free(ht_params);
1008  hash_table_free(ht_private);
1009  hash_table_free(ht_in_regions);
1010  hash_table_free(ht_out_regions);
1011 
1012  HASH_MAP(k,v,{
1013  hash_table_free(v);
1014  },ht_in_communications);
1015  hash_table_free(ht_in_communications);
1016 
1017  HASH_MAP(k,v,{
1018  hash_table_free(v);
1019  },ht_out_communications);
1020  hash_table_free(ht_out_communications);
1021 
1022  }
1023 
1024  else {
1025  pips_debug(2, "Invalid number. Operation aborted\n");
1026  }
1027 
1028  }
1029  return returned_statement;
1030 }
1031 
1032 
1033 /*********************************************************
1034  * Phase main for PHRASE_DISTRIBUTOR_CONTROL_CODE
1035  *********************************************************/
1036 
1038 
1040 {
1041  statement module_stat;
1042  entity module;
1043 
1044  /* set and get the current properties concerning regions */
1045  set_bool_property("MUST_REGIONS", true);
1046  set_bool_property("EXACT_REGIONS", true);
1048 
1049  /* get the resources */
1050  module_stat = (statement) db_get_memory_resource(DBR_CODE,
1051  module_name,
1052  true);
1053 
1055 
1056  set_current_module_statement(module_stat);
1058 
1060  db_get_memory_resource(DBR_CUMULATED_EFFECTS, module_name, true));
1062  db_get_memory_resource(DBR_PROPER_EFFECTS, module_name, true));
1064 
1065  /* sets dynamic_area */
1069  }
1070 
1071  debug_on("PHRASE_DISTRIBUTOR_DEBUG_LEVEL");
1072 
1073  /* Get the READ, WRITE, IN and OUT regions of the module
1074  */
1076  db_get_memory_resource(DBR_REGIONS, module_name, true));
1078  db_get_memory_resource(DBR_IN_REGIONS, module_name, true));
1080  db_get_memory_resource(DBR_OUT_REGIONS, module_name, true));
1081 
1082  /* Now do the job */
1083 
1084  pips_debug(2, "BEGIN of PHRASE_DISTRIBUTOR_CONTROL_CODE\n");
1085  module_stat = controlize_distribution (module_stat, module);
1086  pips_debug(2, "END of PHRASE_DISTRIBUTOR_CONTROL_CODE\n");
1087 
1088  /* Display the statement before to check consistency */
1089  ifdebug(4) {
1090  print_statement(module_stat);
1091  }
1092 
1093  /* Check the coherency of data */
1094 
1095  pips_assert("Statement structure is consistent after PHRASE_DISTRIBUTOR_CONTROL_CODE",
1096  gen_consistent_p((gen_chunk*)module_stat));
1097 
1098  pips_assert("Statement is consistent after PHRASE_DISTRIBUTOR_CONTROL_CODE",
1099  statement_consistent_p(module_stat));
1100 
1101 
1102  /* Reorder the module, because new statements have been added */
1103  module_reorder(module_stat);
1104  DB_PUT_MEMORY_RESOURCE(DBR_CODE, module_name, module_stat);
1105  DB_PUT_MEMORY_RESOURCE(DBR_CALLEES, module_name,
1106  compute_callees(module_stat));
1107 
1108  /* update/release resources */
1114  reset_rw_effects();
1115  reset_in_effects();
1118 
1119  debug_off();
1120 
1121  return true;
1122 }
1123 
dummy make_dummy_identifier(entity _field_)
Definition: ri.c:620
call make_call(entity a1, list a2)
Definition: ri.c:269
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
type copy_type(type p)
TYPE.
Definition: ri.c:2655
storage make_storage(enum storage_utype tag, void *val)
Definition: ri.c:2273
ram make_ram(entity a1, entity a2, intptr_t a3, list a4)
Definition: ri.c:1999
variable copy_variable(variable p)
VARIABLE.
Definition: ri.c:2859
bool statement_consistent_p(statement p)
Definition: ri.c:2195
dimension make_dimension(expression a1, expression a2, list a3)
Definition: ri.c:565
statement make_statement(entity a1, intptr_t a2, intptr_t a3, string a4, instruction a5, list a6, string a7, extensions a8, synchronization a9)
Definition: ri.c:2222
variable make_variable(basic a1, list a2, list a3)
Definition: ri.c:2895
value copy_value(value p)
VALUE.
Definition: ri.c:2784
storage make_storage_formal(formal _field_)
Definition: ri.c:2282
instruction make_instruction(enum instruction_utype tag, void *val)
Definition: ri.c:1166
synchronization make_synchronization_none(void)
Definition: ri.c:2424
sequence make_sequence(list a)
Definition: ri.c:2125
type make_type(enum type_utype tag, void *val)
Definition: ri.c:2706
formal make_formal(entity a1, intptr_t a2)
Definition: ri.c:1067
struct _newgen_struct_entity_ * entity
Definition: abc_private.h:14
static reference ref
Current stmt (an integer)
Definition: adg_read_paf.c:163
static statement module_statement
Definition: alias_check.c:125
static list l_commons
callees compute_callees(const statement stat)
Recompute the callees of a module statement.
Definition: callgraph.c:355
struct _newgen_struct_statement_ * statement
Definition: cloning.h:21
string variable_to_string(variable var)
Return a unique (regarding variable_equal_p(var1,var2)) string representation of a variable var.
void register_scalar_communications(hash_table *ht_communications, entity function, list l_regions)
Build an HASHTABLE where keys are VARIABLE and values are HASHTABLE where keys are modules or externa...
bool compute_distribution_controlization_context(list l_calls, statement module_stat, entity module, hash_table *ht_calls, hash_table *ht_params, hash_table *ht_private, hash_table *ht_in_regions, hash_table *ht_out_regions)
This function is called during PHRASE distribution controlization.
static entity new_variable
entity to be replaced, the primary?
Definition: dynamic.c:860
#define region_entity(reg)
#define REGION
#define region_scalar_p(reg)
static Value offset
Definition: translation.c:283
void get_regions_properties(void)
void set_rw_effects(statement_effects)
void reset_out_effects(void)
void reset_proper_rw_effects(void)
void set_proper_rw_effects(statement_effects)
void set_cumulated_rw_effects(statement_effects)
void set_out_effects(statement_effects)
void set_in_effects(statement_effects)
void reset_in_effects(void)
void reset_cumulated_rw_effects(void)
void reset_rw_effects(void)
#define effect_any_reference(e)
FI: cannot be used as a left hand side.
const char * module_name(const char *s)
Return the module part of an entity name.
Definition: entity_names.c:296
int gen_consistent_p(gen_chunk *obj)
GEN_CONSISTENT_P dynamically checks the type correctness of OBJ.
Definition: genClib.c:2398
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
statement set_current_module_statement(statement)
Set the current module statement.
Definition: static.c:165
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
list gen_nreverse(list cp)
reverse a list in place
Definition: list.c:304
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
size_t gen_length(const list l)
Definition: list.c:150
#define CONS(_t_, _i_, _l_)
List element cell constructor (insert an element at the beginning of a list)
Definition: newgen_list.h:150
list gen_nconc(list cp1, list cp2)
physically concatenates CP1 and CP2 but do not duplicates the elements
Definition: list.c:344
#define MAP(_map_CASTER, _map_item, _map_code, _map_list)
Apply/map an instruction block on all the elements of a list (old fashioned)
Definition: newgen_list.h:226
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
#define DB_PUT_NEW_FILE_RESOURCE(res_name, own_name, res_val)
Put a new file resource into the current workspace database.
hash_table hash_table_make(hash_key_type key_type, size_t size)
Definition: hash.c:294
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
int hash_table_entry_count(hash_table htp)
now we define observers in order to hide the hash_table type...
Definition: hash.c:818
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
#define debug_on(env)
Definition: misc-local.h:157
#define pips_debug
these macros use the GNU extensions that allow variadic macros, including with an empty list.
Definition: misc-local.h:145
#define asprintf
Definition: misc-local.h:225
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
#define pips_internal_error
Definition: misc-local.h:149
#define debug_off()
Definition: misc-local.h:160
string user_request(const char *,...)
#define DYNAMIC_AREA_LOCAL_NAME
Definition: naming-local.h:69
#define MODULE_SEP_STRING
Definition: naming-local.h:30
#define STATEMENT_ORDERING_UNDEFINED
mapping.h inclusion
Definition: newgen-local.h:35
string concatenate(const char *,...)
Return the concatenation of the given strings.
Definition: string.c:183
#define HASH_MAP(k, v, code, ht)
Definition: newgen_hash.h:60
@ hash_pointer
Definition: newgen_hash.h:32
void * gen_find_tabulated(const char *, int)
Definition: tabulated.c:218
int unit
UNIT.
Definition: newgen_types.h:97
struct cons * list
Definition: newgen_types.h:106
int f(int off1, int off2, int n, float r[n], float a[n], float b[n])
Definition: offsets.c:15
entity make_start_ru_module(hash_table, statement *, int, entity, list)
phrase_distributor_communication.c
list get_statements_with_comments_containing(const char *, statement)
Definition: phrase_tools.c:481
list make_send_array_params_modules(entity, list, entity, entity, int)
Make all SEND_PARAM communication modules for non-scalar regions for a given function.
list make_receive_array_params_modules(entity, list, entity, entity, int)
Make all RECEIVE_PARAM communication modules for non-scalar regions for a given function.
list make_send_scalar_params_modules(hash_table, int, entity, list)
Build and return list of modules used for INPUT communications (SEND_PARAMETERS......
list make_receive_scalar_params_modules(hash_table, int, entity, list)
Build and return list of modules used for OUTPUT communications (RECEIVE_PARAMETERS....
string get_send_param_module_name(entity, effect)
statement make_assignement_statement(entity, expression, statement)
Build and return new statement which is a assignement of variable a_variable with expression an_expre...
Definition: phrase_tools.c:392
void compute_region_variables(effect, list *, list *)
entity make_wait_ru_module(statement *, int, entity, list)
string get_receive_param_module_name(entity, effect)
#define COMMON_PARAM_NAME
#define RECEIVE_PARAMETER_MODULE_NAME
#define IN_PARAM_ID_NAME
#define EXTERNALIZED_CODE_PRAGMA_CALL
#define FUNCTIONS_NB_NAME
#define CONTROLIZED_STATEMENT_COMMENT
#define CONTROL_DATA_COMMON_NAME
#define FUNCTION_ID_NAME
#define UNITS_NB_NAME
#define UNIT_ID_NAME
#define FUNCTION_COMMON_NAME
#define SEND_PARAMETER_MODULE_NAME
#define OUT_PARAM_ID_NAME
entity create_new_scalar_common_variable(string name, entity module, entity common, basic b)
Creates and declares a new scalar variable for a newly created common.
entity entity_in_module(const char *name, entity module)
Return entity named name in specified module.
static entity dynamic_area
entity create_integer_parameter_for_new_module(const char *parameter_name, const char *module_name, entity module, int param_nb)
Create new integer variable parameter for a newly created module.
bool phrase_distributor_control_code(const char *module_name)
string get_common_param_name(entity variable, entity function)
entity create_new_common_variable(string name, entity module, entity common, variable var)
Creates and declares a new variable for a newly created common.
static string get_function_common_name(entity function)
entity create_new_integer_scalar_common_variable(string name, entity module, entity common)
Creates and declares a new integer scalar variable for a newly created common.
dg_vertex_label vertex_label
string get_controlized_statement_comment(entity function)
void store_new_module(const char *module_name, entity module, statement module_statement)
Store (PIPDBM) newly created module module with module_statement as USER_FILE by saving pretty printi...
void declare_common_variables_in_module(entity common, entity module)
Creates all the things that need to be created in order to declare common in module (all the variable...
static string get_unit_id_name(int unit)
string get_out_param_id_name(entity variable, entity function)
string get_send_parameter_module_name(variable var)
dg_arc_label arc_label
static statement controlize_distribution(statement module_stat, entity module)
Main function for PHRASE_DISTRIBUTION_CONTROL_CODE.
static entity create_externalized_function_common(entity main_module, entity externalized_function, list params_regions, int number_of_deployment_units)
Creates and returns a common used to store variable for communications between control code and exter...
entity create_parameter_for_new_module(variable var, const char *parameter_name, const char *module_name, entity module, int param_nb)
Create new variable parameter for a newly created module.
string get_function_id_name(entity function)
string get_in_param_id_name(entity variable, entity function)
string get_receive_parameter_module_name(variable var)
static statement make_global_common_and_initialize(entity main_module, statement module_stat, entity *global_common, int number_of_deployment_units, hash_table ht_calls, hash_table ht_in_regions, hash_table ht_out_regions)
Build and return CONTROL_DATA global common used to store global information on phrase distribution c...
static char * module
Definition: pips.c:74
text empty_text(entity __attribute__((unused)) e, int __attribute__((unused)) m, statement __attribute__((unused)) s)
Definition: misc.c:219
void close_prettyprint()
because some prettyprint functions may be used for debug, so the last hook set by somebody may have s...
Definition: misc.c:242
void init_prettyprint(text(*hook)(entity, int, statement))
checks that the prettyprint hook was actually reset...
Definition: misc.c:231
text text_module(entity, statement)
void print_statement(statement)
Print a statement on stderr.
Definition: statement.c:98
bool make_text_resource(const char *, const char *, const char *, text)
print.c
Definition: print.c:55
void set_bool_property(const char *, bool)
bool module_reorder(statement body)
Reorder a module and recompute order to statement if any.
Definition: reorder.c:244
#define make_entity(n, t, s, i)
#define STATEMENT_NUMBER_UNDEFINED
default values
#define empty_comments
Empty comments (i.e.
void fprint_environment(FILE *fd, entity m)
Definition: declarations.c:287
entity FindEntity(const char *package, const char *name)
Retrieve an entity from its package/module name and its local name.
Definition: entity.c:1503
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
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
string entity_global_name(entity e)
Used instead of the macro to pass as formal argument.
Definition: entity.c:464
entity module_name_to_entity(const char *mn)
This is an alias for local_name_to_top_level_entity.
Definition: entity.c:1479
entity entity_empty_label(void)
Definition: entity.c:1105
entity make_new_common(string name, entity mod)
This function creates a common for a given name in a given module.
Definition: entity.c:1806
const char * module_local_name(entity e)
Returns the module local user name.
Definition: entity.c:582
expression entity_to_expression(entity e)
if v is a constant, returns a constant call.
Definition: expression.c:165
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
extensions empty_extensions(void)
extension.c
Definition: extension.c:43
int storage_space_of_variable(entity)
Definition: size.c:656
basic MakeBasic(int)
END_EOLE.
Definition: type.c:128
void AddEntityToDeclarations(entity, entity)
END_EOLE.
Definition: variable.c:108
@ is_basic_int
Definition: ri.h:571
#define area_size(x)
Definition: ri.h:544
#define reference_variable(x)
Definition: ri.h:2326
#define ENTITY(x)
ENTITY.
Definition: ri.h:2755
#define type_functional(x)
Definition: ri.h:2952
#define type_variable(x)
Definition: ri.h:2949
#define entity_storage(x)
Definition: ri.h:2794
#define code_declarations(x)
Definition: ri.h:784
#define EXPRESSION(x)
EXPRESSION.
Definition: ri.h:1217
@ is_storage_ram
Definition: ri.h:2492
#define entity_undefined_p(x)
Definition: ri.h:2762
#define entity_undefined
Definition: ri.h:2761
@ is_instruction_call
Definition: ri.h:1474
@ is_instruction_sequence
Definition: ri.h:1469
#define area_layout(x)
Definition: ri.h:546
#define functional_parameters(x)
Definition: ri.h:1442
#define PARAMETER(x)
PARAMETER.
Definition: ri.h:1788
#define value_code(x)
Definition: ri.h:3067
#define type_area(x)
Definition: ri.h:2946
#define variable_dimensions(x)
Definition: ri.h:3122
#define statement_instruction(x)
Definition: ri.h:2458
#define statement_comments(x)
Definition: ri.h:2456
#define storage_ram(x)
Definition: ri.h:2521
@ is_type_variable
Definition: ri.h:2900
#define entity_type(x)
Definition: ri.h:2792
struct _newgen_struct_code_ * code
Definition: ri.h:79
#define entity_domain
newgen_syntax_domain_defined
Definition: ri.h:410
#define ram_offset(x)
Definition: ri.h:2251
#define STATEMENT(x)
STATEMENT.
Definition: ri.h:2413
#define storage_undefined
Definition: ri.h:2476
#define entity_initial(x)
Definition: ri.h:2796
char * strdup()
void module_to_value_mappings(entity m)
void module_to_value_mappings(entity m): build hash tables between variables and values (old,...
Definition: mappings.c:624
#define ifdebug(n)
Definition: sg.c:47
static string buffer
Definition: string.c:113
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
Definition: replace.c:135
void free_value_mappings(void)
Normal call to free the mappings.
Definition: value.c:1212
A gen_chunk is used to store every object.
Definition: genC.h:58
list module_declarations(entity m)
High-level functions about modules, using pipsdbm and ri-util and some global variables assumed prope...
Definition: module.c:58