OSDN Git Service

Factor out common tests in 8-byte reg/reg move splitters on 32-bit sparc.
[pf3gnuchains/gcc-fork.git] / gcc / input.c
1 /* Data and functions related to line maps and input files.
2    Copyright (C) 2004, 2007, 2008, 2009, 2010, 2011
3    Free Software Foundation, Inc.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
11
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3.  If not see
19 <http://www.gnu.org/licenses/>.  */
20
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "intl.h"
25 #include "input.h"
26
27 /* Current position in real source file.  */
28
29 location_t input_location;
30
31 struct line_maps *line_table;
32
33 expanded_location
34 expand_location (source_location loc)
35 {
36   expanded_location xloc;
37   if (loc <= BUILTINS_LOCATION)
38     {
39       xloc.file = loc == UNKNOWN_LOCATION ? NULL : _("<built-in>");
40       xloc.line = 0;
41       xloc.column = 0;
42       xloc.sysp = 0;
43     }
44   else
45     xloc = linemap_expand_location_full (line_table, loc,
46                                          LRK_SPELLING_LOCATION);
47   return xloc;
48 }
49
50 #define ONE_K 1024
51 #define ONE_M (ONE_K * ONE_K)
52
53 /* Display a number as an integer multiple of either:
54    - 1024, if said integer is >= to 10 K (in base 2)
55    - 1024 * 1024, if said integer is >= 10 M in (base 2)
56  */
57 #define SCALE(x) ((unsigned long) ((x) < 10 * ONE_K \
58                   ? (x) \
59                   : ((x) < 10 * ONE_M \
60                      ? (x) / ONE_K \
61                      : (x) / ONE_M)))
62
63 /* For a given integer, display either:
64    - the character 'k', if the number is higher than 10 K (in base 2)
65      but strictly lower than 10 M (in base 2)
66    - the character 'M' if the number is higher than 10 M (in base2)
67    - the charcter ' ' if the number is strictly lower  than 10 K  */
68 #define STAT_LABEL(x) ((x) < 10 * ONE_K ? ' ' : ((x) < 10 * ONE_M ? 'k' : 'M'))
69
70 /* Display an integer amount as multiple of 1K or 1M (in base 2).
71    Display the correct unit (either k, M, or ' ') after the amout, as
72    well.  */
73 #define FORMAT_AMOUNT(size) SCALE (size), STAT_LABEL (size)
74
75 /* Dump statistics to stderr about the memory usage of the line_table
76    set of line maps.  This also displays some statistics about macro
77    expansion.  */
78
79 void
80 dump_line_table_statistics (void)
81 {
82   struct linemap_stats s;
83   long total_used_map_size,
84     macro_maps_size,
85     total_allocated_map_size;
86
87   memset (&s, 0, sizeof (s));
88
89   linemap_get_statistics (line_table, &s);
90
91   macro_maps_size = s.macro_maps_used_size
92     + s.macro_maps_locations_size;
93
94   total_allocated_map_size = s.ordinary_maps_allocated_size
95     + s.macro_maps_allocated_size
96     + s.macro_maps_locations_size;
97
98   total_used_map_size = s.ordinary_maps_used_size
99     + s.macro_maps_used_size
100     + s.macro_maps_locations_size;
101
102   fprintf (stderr, "Number of expanded macros:                     %5ld\n",
103            s.num_expanded_macros);
104   if (s.num_expanded_macros != 0)
105     fprintf (stderr, "Average number of tokens per macro expansion:  %5ld\n",
106              s.num_macro_tokens / s.num_expanded_macros);
107   fprintf (stderr,
108            "\nLine Table allocations during the "
109            "compilation process\n");
110   fprintf (stderr, "Number of ordinary maps used:        %5ld%c\n",
111            SCALE (s.num_ordinary_maps_used),
112            STAT_LABEL (s.num_ordinary_maps_used));
113   fprintf (stderr, "Ordinary map used size:              %5ld%c\n",
114            SCALE (s.ordinary_maps_used_size),
115            STAT_LABEL (s.ordinary_maps_used_size));
116   fprintf (stderr, "Number of ordinary maps allocated:   %5ld%c\n",
117            SCALE (s.num_ordinary_maps_allocated),
118            STAT_LABEL (s.num_ordinary_maps_allocated));
119   fprintf (stderr, "Ordinary maps allocated size:        %5ld%c\n",
120            SCALE (s.ordinary_maps_allocated_size),
121            STAT_LABEL (s.ordinary_maps_allocated_size));
122   fprintf (stderr, "Number of macro maps used:           %5ld%c\n",
123            SCALE (s.num_macro_maps_used),
124            STAT_LABEL (s.num_macro_maps_used));
125   fprintf (stderr, "Macro maps used size:                %5ld%c\n",
126            SCALE (s.macro_maps_used_size),
127            STAT_LABEL (s.macro_maps_used_size));
128   fprintf (stderr, "Macro maps locations size:           %5ld%c\n",
129            SCALE (s.macro_maps_locations_size),
130            STAT_LABEL (s.macro_maps_locations_size));
131   fprintf (stderr, "Macro maps size:                     %5ld%c\n",
132            SCALE (macro_maps_size),
133            STAT_LABEL (macro_maps_size));
134   fprintf (stderr, "Duplicated maps locations size:      %5ld%c\n",
135            SCALE (s.duplicated_macro_maps_locations_size),
136            STAT_LABEL (s.duplicated_macro_maps_locations_size));
137   fprintf (stderr, "Total allocated maps size:           %5ld%c\n",
138            SCALE (total_allocated_map_size),
139            STAT_LABEL (total_allocated_map_size));
140   fprintf (stderr, "Total used maps size:                %5ld%c\n",
141            SCALE (total_used_map_size),
142            STAT_LABEL (total_used_map_size));
143   fprintf (stderr, "\n");
144 }