PIPS
instrumentation.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <ctype.h>
3 #include <string.h>
4 #include "boolean.h"
5 #include <stdbool.h>
6 
7 #include "genC.h"
8 #include "linear.h"
9 #include "ri.h"
10 #include "effects.h"
11 #include "database.h"
12 #include "misc.h"
13 #include "text.h"
14 #include "text-util.h"
15 #include "ri-util.h"
16 #include "prettyprint.h"
17 #include "effects-util.h"
18 #include "accel-util.h"
19 
20 #include "effects-generic.h"
21 #include "effects-simple.h"
22 
23 #include "pipsdbm.h"
24 #include "resources.h"
25 #include "control.h"
26 #include "conversion.h"
27 #include "properties.h"
28 #include "semantics.h"
29 #include "transformations.h"
30 
31 #include "effects-convex.h"
32 #include "genC.h"
33 #include "complexity_ri.h"
34 #include "complexity.h"
35 #include "dg.h"
36 
37 /* Instantiation of the dependence graph: */
40 #include "graph.h"
41 #include "ricedg.h"
42 #include "chains.h"
43 #include "task_parallelization.h"
44 
45 
46 
47 
48 //profiling using instrumentation
50 {
51  statement st_poly ;
53  {
54  string dir = strdup(concatenate("char *file_name = \"", "./instrumented_",get_current_module_name(),".in\";", NULL));
55  string mode = "\"w\"";
56  string new_name = strdup(concatenate("FILE *finstrumented;\n ", dir, "\n finstrumented = fopen(file_name,", mode, ");\n", NULL)) ;
57  entity new_ent = make_constant_entity(new_name, is_basic_string, 1000);
59  }
60  else{
62  string r;
63  if(stat_comp != (complexity) HASH_UNDEFINED_VALUE && !complexity_zero_p(stat_comp)) {
64  cons *pc = CHAIN_SWORD(NIL, complexity_sprint(stat_comp, false, true));
65  r = words_to_string(pc);
66  }
67  else
68  r = strdup("Undefined value");
69  string new_name3 = "finstrumented";
70  entity new_ent3 = make_constant_entity(new_name3, is_basic_string, 100);
71  expression exp3 = make_entity_expression(new_ent3, NIL);
72  string new_name = strdup(concatenate( "\"", i2a(statement_ordering(s)),"->-1 = %lf \\n", "\"", NULL));
73  entity new_ent = make_constant_entity(new_name, is_basic_string, 1000);
75  entity new_ent2 = make_constant_entity(r, is_basic_string, 100);
77  expression exp2 = make_entity_expression(new_ent2, NIL);
80  list args = CONS(EXPRESSION, exp3, CONS(EXPRESSION, exp,CONS(EXPRESSION, exp4, NIL)));
82  args,
85  }
86  statement new_s = copy_statement(s);
88  statement_instruction(s) = ins_seq;
93  return;
94 }
95 
97 {
98  Ppolynome transfer_time = POLYNOME_NUL;
99  string r;
102  list l_communications = RegionsIntersection(regions_dup(l_write_1), regions_dup(l_read_2), w_r_combinable_p);
103  FOREACH(REGION,reg,l_communications){
104  Ppolynome reg_footprint = region_enumerate(reg);
106  polynome_add(&transfer_time, reg_footprint);
107 
108  }
109  if(!POLYNOME_UNDEFINED_P(transfer_time)){
110  r = expression_to_string(polynome_to_expression(transfer_time));
111  }
112  else
113  r = "0";
114  string new_name3 = "finstrumented";
115  entity new_ent3 = make_constant_entity(new_name3, is_basic_string, 100);
116  expression exp3 = make_entity_expression(new_ent3, NIL);
117  string s2_ordering = strdup(concatenate( "\"", i2a(statement_ordering(s1)),NULL));
118  string new_name = strdup(concatenate( s2_ordering, "->", i2a(statement_ordering(s2))," = %lf \\n", "\"", NULL));
119  entity new_ent = make_constant_entity(new_name, is_basic_string, 1000);
121  entity new_ent2 = make_constant_entity(r, is_basic_string, 100);
123  expression exp2 = make_entity_expression(new_ent2, NIL);
125  //expression exp2 = make_entity_expression(new_ent2, NIL);
126  list args = CONS(EXPRESSION, exp3, CONS(EXPRESSION,exp,CONS(EXPRESSION,exp4,NIL)));
128  args,
131  statement new_s = copy_statement(s2);
133  statement_instruction(s2) = ins_seq;
138  return;
139 }
140 
142 {
143  statement module_stat = (statement)db_get_memory_resource(DBR_CODE, module_name, true);
144  set_ordering_to_statement(module_stat);
146  set_current_module_statement(module_stat);
149  db_get_memory_resource(DBR_TRANSFORMERS, module_name, true));
150  /* The proper effect to detect the I/O operations: */
155  db_get_memory_resource(DBR_REGIONS, module_name, true));
158 
159  kdg = (graph) db_get_memory_resource (DBR_SDG, module_name, true );
160 
161  /*Complexities (task processing time)*/
163 
164  /*first step is to cumulate dependences hierarchically (between
165  sequences) on granularities : loop, test and simple instruction*/
166  list vertices = graph_vertices(kdg);
167  FOREACH(VERTEX, v, vertices){
172  vertex s = successor_vertex(su);
173  statement child = vertex_to_statement(s);
174  edge_cost_polynome(stmt,child);
175  }
176  }
177  }
178  /* Reorder the module, because new statements have been generated. */
179  module_reorder(module_stat);
180  gen_consistent_p((gen_chunk*)module_stat);
181  DB_PUT_MEMORY_RESOURCE(DBR_CODE, strdup(module_name), module_stat);
192  return true;
193 }
194 
graph kdg
Global variables.
Definition: HBDSC.c:52
cast make_cast(type a1, expression a2)
Definition: ri.c:311
expression make_expression(syntax a1, normalized a2)
Definition: ri.c:886
basic make_basic(enum basic_utype tag, void *val)
Definition: ri.c:155
type copy_type(type p)
TYPE.
Definition: ri.c:2655
statement copy_statement(statement p)
STATEMENT.
Definition: ri.c:2186
void free_extensions(extensions p)
Definition: ri.c:950
instruction make_instruction_sequence(sequence _field_)
Definition: ri.c:1169
syntax make_syntax_cast(cast _field_)
Definition: ri.c:2503
sequence make_sequence(list a)
Definition: ri.c:2125
struct _newgen_struct_statement_ * statement
Definition: cloning.h:21
bool complexity_zero_p(complexity comp)
zero complexity check.
Definition: comp_math.c:244
char * complexity_sprint(complexity comp, bool print_stats_p, bool print_local_names_p)
Definition: comp_util.c:175
complexity load_statement_complexity(statement)
void reset_complexity_map(void)
void set_complexity_map(statement_mapping)
entity make_constant_entity(string name, tag bt, size_t size)
For historical reason, call the Fortran version.
Definition: constant.c:301
#define region_entity(reg)
#define REGION
list RegionsIntersection(list l1, list l2, bool(*intersection_combinable_p)(effect, effect))
list RegionsIntersection(list l1,l2, bool (*intersection_combinable_p)(effect, effect)) input : outpu...
list regions_write_regions(list)
list regions_read_regions(list)
void set_methods_for_convex_effects(void)
methods.c
Definition: methods.c:235
list regions_dup(list)
void init_convex_rw_prettyprint(const char *)
Ppolynome region_enumerate(effect)
void set_rw_effects(statement_effects)
bool w_r_combinable_p(effect, effect)
void reset_proper_rw_effects(void)
void set_proper_rw_effects(statement_effects)
void set_cumulated_rw_effects(statement_effects)
void reset_cumulated_rw_effects(void)
list load_statement_local_regions(statement)
void reset_rw_effects(void)
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 *)
#define successor_vertex(x)
Definition: graph.h:118
struct _newgen_struct_graph_ * graph
Definition: graph.h:31
#define vertex_successors(x)
Definition: graph.h:154
#define SUCCESSOR(x)
SUCCESSOR.
Definition: graph.h:86
#define graph_vertices(x)
Definition: graph.h:82
#define VERTEX(x)
VERTEX.
Definition: graph.h:122
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
#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
#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
statement make_expression_statement(expression)
Build a statement from a given expression.
Definition: statement.c:1308
statement make_call_statement(string, list, entity, string)
This function is limited to intrinsics calls...
Definition: statement.c:1274
bool declaration_statement_p(statement)
Had to be optimized according to Beatrice Creusillet.
Definition: statement.c:224
statement vertex_to_statement(vertex v)
Vertex_to_statement looks for the statement that is pointed to by vertex v.
Definition: util.c:45
static vertex statement_to_vertex(statement s, graph g)
Definition: impact_check.c:227
static void task_time_polynome(statement s)
dg_vertex_label vertex_label
dg_arc_label arc_label
Instantiation of the dependence graph:
bool bdsc_code_instrumentation(char *module_name)
instrumentation.c
static void edge_cost_polynome(statement s1, statement s2)
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
#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
#define UUINT(i)
Definition: newgen_types.h:99
#define string_undefined_p(s)
Definition: newgen_types.h:41
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
Ppolynome polynome_mult(Ppolynome pp1, Ppolynome pp2)
Ppolynome polynome_mult(Ppolynome pp1, Ppolynome pp2) returns pp1 * pp2.
Definition: pnome-bin.c:287
void polynome_add(Ppolynome *ppp, Ppolynome pp2)
void polynome_add(Ppolynome* ppp, Ppolynome pp2) (*ppp) = (*ppp) + pp2.
Definition: pnome-bin.c:171
static bool statement_equal_p(statement s1, statement s2)
Definition: unstructured.c:55
#define POLYNOME_NUL
#define POLYNOME_UNDEFINED_P(pp)
string expression_to_string(expression e)
Definition: expression.c:77
bool module_reorder(statement body)
Reorder a module and recompute order to statement if any.
Definition: reorder.c:244
#define FPRINTF_FUNCTION_NAME
#define make_statement_list(stats...)
easy list constructor
#define empty_comments
Empty comments (i.e.
entity module_name_to_entity(const char *mn)
This is an alias for local_name_to_top_level_entity.
Definition: entity.c:1479
expression make_entity_expression(entity e, cons *inds)
Definition: expression.c:176
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
Ppolynome expression_to_polynome(expression exp)
===========================================================================
Definition: expression.c:3650
expression polynome_to_expression(Ppolynome pp)
converts a polynomial to expression
Definition: expression.c:3622
extensions empty_extensions(void)
extension.c
Definition: extension.c:43
_int SizeOfElements(basic)
This function returns the length in bytes of the Fortran or C type represented by a basic,...
Definition: size.c:297
type MakeTypeVariable(basic, cons *)
BEGIN_EOLE.
Definition: type.c:116
@ is_basic_string
Definition: ri.h:576
@ is_basic_float
Definition: ri.h:572
#define normalized_undefined
Definition: ri.h:1745
#define statement_ordering(x)
Definition: ri.h:2454
#define type_variable(x)
Definition: ri.h:2949
#define EXPRESSION(x)
EXPRESSION.
Definition: ri.h:1217
#define entity_undefined
Definition: ri.h:2761
#define statement_extensions(x)
Definition: ri.h:2464
#define statement_instruction(x)
Definition: ri.h:2458
#define statement_comments(x)
Definition: ri.h:2456
#define entity_type(x)
Definition: ri.h:2792
#define variable_basic(x)
Definition: ri.h:3120
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
void set_transformer_map(statement_mapping)
void reset_precondition_map(void)
void set_precondition_map(statement_mapping)
void reset_transformer_map(void)
s1
Definition: set.c:247
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
Definition: statement.c:54
#define CHAIN_SWORD(l, s)
string words_to_string(cons *lw)
Definition: print.c:211
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
#define exp
Avoid some warnings from "gcc -Wshadow".
Definition: vasnprintf.c:207