PIPS
variable_replication.c
Go to the documentation of this file.
1 /*
2 
3  $Id$
4 
5  Copyright 1989-2014 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 
28 /**
29  * Pass: VARIABLE_REPLICATION
30  * Debug mode: MPI_GENERATION_DEBUG_LEVEL
31  * Properties used:
32  * - MPI_NBR_CLUSTER
33  * - MPI_DUPLICATE_VARIABLE_PREFIX
34  * Resource needed:
35  * - DBR_TASK
36  *
37  */
38 
39 #include <stdlib.h>
40 #include <stdio.h>
41 
42 #include "genC.h"
43 #include "linear.h"
44 
45 #include "resources.h"
46 #include "database.h"
47 #include "ri.h"
48 #include "ri-util.h"
49 #include "pipsdbm.h"
50 
51 #include "control.h"
52 
53 #include "misc.h"
54 
55 #include "properties.h"
56 
57 #include "task_parallelization.h"
58 #include "prettyprint.h"
61 }
62 
64  ifdebug(4) {
65  pips_debug(4, "begin\n");
66  pips_debug(4, "declaration statement to replicated\n");
67  print_statement(st);
68  }
69  const char * prefix = get_string_property((const char *) MPI_GENERATION_PREFIX);
71  statement declaration=statement_undefined;
72 
74  for (int i=0; i<nbr_copy; i++) {
75  string new_name = "";
76  entity new_entity = entity_undefined;
77  new_name = concatenate(
80  prefix, entity_user_name(decl), "_", i2a(i),
81  NULL);
82 
84  pips_user_error("The entity %s already exist\n", new_name);
85  return;
86  }
87  new_entity = make_entity_copy_with_new_name(decl, new_name, true);
88 
89  declaration = add_declaration_statement_here(module_statement, st, new_entity, true);
90 
91  //statement_declarations(module_statement) = CONS(ENTITY, new_entity, statement_declarations(module_statement));
92  }
94 
95  pips_assert("module_statement is consistent\n", statement_consistent_p(module_statement));
96  ifdebug(4) {
97  pips_debug(4, "declaration statement that be added\n");
98  print_statement(declaration);
99  print_statement(st);
100  pips_debug(4, "end\n");
101  }
102 }
103 
104 /**
105  *
106  */
108  pips_user_warning("global variable not implemented yet.\n");
109  return true;
110 }
111 
112 
113 /**
114  * only replicate declaration declare at the first scope of the function.
115  * The sub-scope has to be some pragma and don't have to be replicate.
116  * \pragma module_statement statement to work on
117  */
120  pips_internal_error("module_statement have to be the statement of the module/function\n");
121  return false;
122  }
123 
124  // FOREACH statement of the module/function,
125  // check if it's a declaration
126  // then FOREACH declaration generate new variables (depend of the number of proc) and declare them
128  if (declaration_statement_p(st)) {
130  // declarations list of entity declared
131  list declarations = statement_declarations(st);
132  FOREACH(ENTITY, decl, declarations) {
133  // test if the entity decl is not in the private list of the task, if so no replication
134  if (gen_position(decl, task_private_data(t)) == 0) {
136  }
137  }
138  }
139  }
140 
141  return true;
142 }
143 
144 
145 /**
146  * PIPS pass
147  */
149  //entity module;
151  bool good_result_p = true;
152 
153  debug_on("MPI_GENERATION_DEBUG_LEVEL");
154  pips_debug(1, "begin\n");
155 
156  //-- configure environment --//
158  //module = get_current_module_entity();
159 
161  db_get_memory_resource(DBR_CODE, module_name, true) );
163 
164  pips_assert("Statement should be OK before...",
166 
168 
169  //-- get dependencies --//
171  db_get_memory_resource(DBR_TASK, module_name, true));
172 
173  //-- Make the job -- //
176 
177  /* Reorder the module, because some statements have been added.
178  Well, the order on the remaining statements should be the same,
179  but by reordering the statements, the number are consecutive. Just
180  for pretty print... :-) */
182 
183  pips_assert("Statement should be OK after...",
185 
186  //-- Save modified code to database --//
188 
193 
194  pips_debug(1, "end\n");
195  debug_off();
196 
197  return (good_result_p);
198 }
199 
float a2sf[2] __attribute__((aligned(16)))
USER generates a user error (i.e., non fatal) by printing the given MSG according to the FMT.
Definition: 3dnow.h:3
int get_int_property(const string)
bool statement_consistent_p(statement p)
Definition: ri.c:2195
static statement module_statement
Definition: alias_check.c:125
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 *)
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
int gen_position(const void *item, const list l)
Element ranks are strictly positive as for first, second, and so on.
Definition: list.c:995
#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
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
sequence statement_sequence(statement)
Get the sequence of a statement sequence.
Definition: statement.c:1328
bool statement_sequence_p(statement)
Statement classes induced from instruction type.
Definition: statement.c:335
void pop_generated_variable_commenter(void)
Definition: statement.c:2623
statement add_declaration_statement_here(statement, statement, entity, bool)
Add a new declaration statement (inspired by generic_add_declaration_statement)
Definition: statement.c:2839
void push_generated_variable_commenter(string(*)(entity))
Definition: statement.c:2616
bool declaration_statement_p(statement)
Had to be optimized according to Beatrice Creusillet.
Definition: statement.c:224
#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 pips_user_warning
Definition: misc-local.h:146
#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
#define pips_user_error
Definition: misc-local.h:147
#define MODULE_SEP_STRING
Definition: naming-local.h:30
char * i2a(int)
I2A (Integer TO Ascii) yields a string for a given Integer.
Definition: string.c:121
string concatenate(const char *,...)
Return the concatenation of the given strings.
Definition: string.c:183
void * gen_find_tabulated(const char *, int)
Definition: tabulated.c:218
hash_table set_ordering_to_statement(statement s)
To be used instead of initialize_ordering_to_statement() to make sure that the hash table ots is in s...
Definition: ordering.c:172
void reset_ordering_to_statement(void)
Reset the mapping from ordering to statement.
Definition: ordering.c:185
void print_statement(statement)
Print a statement on stderr.
Definition: statement.c:98
static const char * prefix
bool module_reorder(statement body)
Reorder a module and recompute order to statement if any.
Definition: reorder.c:244
const char * entity_user_name(entity e)
Since entity_local_name may contain PIPS special characters such as prefixes (label,...
Definition: entity.c:487
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 module_name_to_entity(const char *mn)
This is an alias for local_name_to_top_level_entity.
Definition: entity.c:1479
string local_name_to_scope(const char *ln)
allocates a new string
Definition: entity.c:563
const char * entity_module_name(entity e)
See comments about module_name().
Definition: entity.c:1092
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
#define ENTITY(x)
ENTITY.
Definition: ri.h:2755
#define entity_undefined
Definition: ri.h:2761
#define sequence_statements(x)
Definition: ri.h:2360
#define statement_declarations(x)
Definition: ri.h:2460
#define entity_domain
newgen_syntax_domain_defined
Definition: ri.h:410
#define statement_undefined
Definition: ri.h:2419
#define STATEMENT(x)
STATEMENT.
Definition: ri.h:2413
char * strdup()
#define ifdebug(n)
Definition: sg.c:47
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
#define MPI_GENERATION_NBR_CLUSTER
#define COMMENT_VARIABLE_REPLICATION
#define MPI_GENERATION_PREFIX
task load_parallel_task_mapping(statement)
void set_parallel_task_mapping(statement_task)
void reset_parallel_task_mapping(void)
#define task_private_data(x)
Definition: task_private.h:117
bool variable_replication(const char *module_name)
PIPS pass.
static void replicate_declaration(entity decl, statement module_statement, statement st)
static bool make_global_variable_declaration_replication()
static bool make_declaration_replication(statement module_statement)
only replicate declaration declare at the first scope of the function.
static string variable_replication_declaration_commenter(__attribute__((unused)) entity e)
Pass: VARIABLE_REPLICATION Debug mode: MPI_GENERATION_DEBUG_LEVEL Properties used: