PIPS
array_resizing_statistic.c
Go to the documentation of this file.
1 /*
2 
3  $Id: array_resizing_statistic.c 23065 2016-03-02 09:05:50Z coelho $
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 
25 // do not compile unless required
26 #include "phases.h"
27 #ifdef BUILDER_ARRAY_RESIZING_STATISTIC
28 
29 #ifdef HAVE_CONFIG_H
30  #include "pips_config.h"
31 #endif
32 /*
33  This phase computes the number of pointer-type A(1) and assumed-size A(*)
34  array declarators in one program.
35  There are two cases: these unnormalized declarations are formal array
36  parameters or not
37 */
38 
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <string.h>
42 
43 #include "genC.h"
44 #include "linear.h"
45 
46 #include "ri.h"
47 #include "ri-util.h"
48 
49 #include "misc.h"
50 
51 static int number_of_pointer_type_and_formal_arrays = 0;
52 static int number_of_assumed_size_and_formal_arrays = 0;
53 static int number_of_formal_arrays = 0;
54 static int number_of_pointer_type_and_not_formal_arrays = 0;
55 static int number_of_assumed_size_and_not_formal_arrays = 0;
56 static int number_of_not_formal_arrays = 0;
57 
58 static int number_of_processed_modules = 0;
59 
60 bool array_resizing_statistic(const string module_name)
61 {
63  list l_decl = code_declarations(entity_code(module_ent));
64 
66 
67  debug_on("ARRAY_RESIZING_STATISTIC_DEBUG_LEVEL");
68  ifdebug(1)
69  fprintf(stderr, " \n Begin array resizing statistic for %s \n", module_name);
70 
71  /* search for unnormalized array declarations in the list */
72  while(!ENDP(l_decl))
73  {
74  entity e = ENTITY(CAR(l_decl));
75  if (entity_variable_p(e))
76  {
78  list l_dims = variable_dimensions(v);
79  if (l_dims != NIL)
80  {
81  int length = gen_length(l_dims);
82  dimension last_dim = find_ith_dimension(l_dims,length);
83  expression exp = dimension_upper(last_dim);
84  storage s = entity_storage(e);
85  if (storage_formal_p(s))
86  number_of_formal_arrays++;
87  else
88  number_of_not_formal_arrays++;
89  if (unbounded_dimension_p(last_dim))
90  {
91  if (storage_formal_p(s))
92  number_of_assumed_size_and_formal_arrays++;
93  else
94  number_of_assumed_size_and_not_formal_arrays++;
95  }
97  {
98  if (storage_formal_p(s))
99  number_of_pointer_type_and_formal_arrays++;
100  else
101  number_of_pointer_type_and_not_formal_arrays++;
102  }
103  }
104  }
105  l_decl = CDR(l_decl);
106  }
107 
108  user_log(" \n Number of pointer-type A(1), formal arrays : %d \n"
109  ,number_of_pointer_type_and_formal_arrays );
110  user_log(" \n Number of assumed-size A(*), formal arrays : %d \n"
111  ,number_of_assumed_size_and_formal_arrays );
112  user_log(" \n Number of formal array declarators : %d\n"
113  ,number_of_formal_arrays );
114  user_log(" \n Number of pointer-type A(1), local arrays : %d \n"
115  ,number_of_pointer_type_and_not_formal_arrays );
116  user_log(" \n Number of assumed-size A(*), local arrays : %d \n"
117  ,number_of_assumed_size_and_not_formal_arrays );
118  user_log(" \n Number of local array declarators : %d\n"
119  ,number_of_not_formal_arrays );
120  user_log(" \n Total number of pointer-type arrays : %d\n"
121  ,number_of_pointer_type_and_formal_arrays +
122  number_of_pointer_type_and_not_formal_arrays );
123  user_log(" \n Total number of assumed-size arrays : %d\n"
124  ,number_of_assumed_size_and_formal_arrays +
125  number_of_assumed_size_and_not_formal_arrays);
126  user_log(" \n Total number of arrays : %d\n"
127  ,number_of_formal_arrays +
128  number_of_not_formal_arrays);
129 
130  user_log("\n Number of processed modules: %d \n"
132 
133  ifdebug(1)
134  fprintf(stderr, " \n End array resizing statistic for %s \n", module_name);
135  debug_off();
136  return true;
137 }
138 
139 #endif // BUILDER_ARRAY_RESIZING_STATISTIC
void user_log(const char *format,...)
Definition: message.c:234
static int number_of_processed_modules
Definition: alias_check.c:136
const char * module_name(const char *s)
Return the module part of an entity name.
Definition: entity_names.c:296
#define ENDP(l)
Test if a list is empty.
Definition: newgen_list.h:66
#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 CAR(pcons)
Get the value of the first element of a list.
Definition: newgen_list.h:92
#define CDR(pcons)
Get the list less its first element.
Definition: newgen_list.h:111
#define debug_on(env)
Definition: misc-local.h:157
#define debug_off()
Definition: misc-local.h:160
#define true
Definition: newgen_types.h:81
#define entity_variable_p(e)
An entity_variable_p(e) may hide a typedef and hence a functional type.
code entity_code(entity e)
Definition: entity.c:1098
entity module_name_to_entity(const char *mn)
This is an alias for local_name_to_top_level_entity.
Definition: entity.c:1479
bool unbounded_dimension_p(dimension dim)
bool unbounded_dimension_p(dim) input : a dimension of an array entity.
Definition: expression.c:1130
bool expression_equal_integer_p(expression exp, int i)
================================================================
Definition: expression.c:1977
dimension find_ith_dimension(list, int)
This function returns the ith dimension of a list of dimensions.
Definition: type.c:5621
#define storage_formal_p(x)
Definition: ri.h:2522
#define ENTITY(x)
ENTITY.
Definition: ri.h:2755
#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 dimension_upper(x)
Definition: ri.h:982
#define variable_dimensions(x)
Definition: ri.h:3122
#define entity_type(x)
Definition: ri.h:2792
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
return(s1)
#define ifdebug(n)
Definition: sg.c:47
static entity array
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
bool array_resizing_statistic(const string)
array_resizing_statistic.c
#define exp
Avoid some warnings from "gcc -Wshadow".
Definition: vasnprintf.c:207