annotate contrib/header-tools/README @ 136:4627f235cf2a

fix c-next example
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Thu, 08 Nov 2018 14:11:56 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 Quick start documentation for the header file utilities.
kono
parents:
diff changeset
2
kono
parents:
diff changeset
3 This isn't a full breakdown of the tools, just they typical use scenarios.
kono
parents:
diff changeset
4
kono
parents:
diff changeset
5 - Each tool accepts -h to show it's usage. Usually no parameters will also
kono
parents:
diff changeset
6 trigger the help message. Help may specify additional functionality to what is
kono
parents:
diff changeset
7 listed here.
kono
parents:
diff changeset
8
kono
parents:
diff changeset
9 - For all tools, option format for specifying filenames must have no spaces
kono
parents:
diff changeset
10 between the option and filename.
kono
parents:
diff changeset
11 ie.: tool -lfilename.h target.h
kono
parents:
diff changeset
12
kono
parents:
diff changeset
13 - Many of the tools are required to be run from the core gcc source directory
kono
parents:
diff changeset
14 containing coretypes.h. Typically that is in gcc/gcc from a source checkout.
kono
parents:
diff changeset
15 For these tools to work on files not in this directory, their path needs to be
kono
parents:
diff changeset
16 specified on the command line.
kono
parents:
diff changeset
17 ie.: tool c/c-decl.c lto/lto.c
kono
parents:
diff changeset
18
kono
parents:
diff changeset
19 - options can be intermixed with filenames anywhere on the command line
kono
parents:
diff changeset
20 ie. tool ssa.h rtl.h -a is equivalent to
kono
parents:
diff changeset
21 tool ssa.h -a rtl.h
kono
parents:
diff changeset
22
kono
parents:
diff changeset
23
kono
parents:
diff changeset
24
kono
parents:
diff changeset
25
kono
parents:
diff changeset
26
kono
parents:
diff changeset
27 gcc-order-headers
kono
parents:
diff changeset
28 -----------------
kono
parents:
diff changeset
29 This will reorder any primary backend headers files known to the tool into a
kono
parents:
diff changeset
30 canonical order which will resolve any hidden dependencies they may have.
kono
parents:
diff changeset
31 Any unknown headers will simply be placed after the recognized files, and
kono
parents:
diff changeset
32 retain the same relative ordering they had.
kono
parents:
diff changeset
33
kono
parents:
diff changeset
34 This tool must be run in the core gcc source directory.
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36 Simply execute the command listing any files you wish to process on the
kono
parents:
diff changeset
37 command line.
kono
parents:
diff changeset
38
kono
parents:
diff changeset
39 Any files which are changed are output, and the original is saved with a
kono
parents:
diff changeset
40 .bak extention.
kono
parents:
diff changeset
41
kono
parents:
diff changeset
42 ex.: gcc-order-headers tree-ssa.c c/c-decl.c
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 -s will list all of the known headers in their canonical order. It does not
kono
parents:
diff changeset
45 show which of those headers include other headers, just the final canonical
kono
parents:
diff changeset
46 ordering.
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 if any header files are included within a conditional code block, the tool
kono
parents:
diff changeset
49 will issue a message and not change the file. When this happens, you can
kono
parents:
diff changeset
50 manually inspect the file to determine if reordering it is actually OK. Then
kono
parents:
diff changeset
51 rerun the command with the -i option. This will ignore the conditional error
kono
parents:
diff changeset
52 condition and perform the re-ordering anyway.
kono
parents:
diff changeset
53
kono
parents:
diff changeset
54 If any #include line has the beginning of a multi-line comment, it will also
kono
parents:
diff changeset
55 refuse to process the file until that is resolved by terminating the comment
kono
parents:
diff changeset
56 on the same line, or removing it.
kono
parents:
diff changeset
57
kono
parents:
diff changeset
58
kono
parents:
diff changeset
59 show-headers
kono
parents:
diff changeset
60 ------------
kono
parents:
diff changeset
61 This will show the include structure for any given file. Each level of nesting
kono
parents:
diff changeset
62 is indented, and when any duplicate headers are seen, they have their
kono
parents:
diff changeset
63 duplicate number shown
kono
parents:
diff changeset
64
kono
parents:
diff changeset
65 -i may be used to specify additional search directories for headers to parse.
kono
parents:
diff changeset
66 -s specifies headers to look for and emphasize in the output.
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 This tool must be run in the core gcc source directory.
kono
parents:
diff changeset
69
kono
parents:
diff changeset
70 ex.: show-headers -sansidecl.h tree-ssa.c
kono
parents:
diff changeset
71 tree-ssa.c
kono
parents:
diff changeset
72 config.h
kono
parents:
diff changeset
73 auto-host.h
kono
parents:
diff changeset
74 ansidecl.h (1) <<-------
kono
parents:
diff changeset
75 system.h
kono
parents:
diff changeset
76 safe-ctype.h
kono
parents:
diff changeset
77 filenames.h
kono
parents:
diff changeset
78 hashtab.h (1)
kono
parents:
diff changeset
79 ansidecl.h (2) <<-------
kono
parents:
diff changeset
80 libiberty.h
kono
parents:
diff changeset
81 ansidecl.h (3) <<-------
kono
parents:
diff changeset
82 hwint.h
kono
parents:
diff changeset
83 coretypes.h
kono
parents:
diff changeset
84 machmode.h (1)
kono
parents:
diff changeset
85 insn-modes.h (1)
kono
parents:
diff changeset
86 signop.h
kono
parents:
diff changeset
87 <...>
kono
parents:
diff changeset
88
kono
parents:
diff changeset
89
kono
parents:
diff changeset
90
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 count-headers
kono
parents:
diff changeset
93 -------------
kono
parents:
diff changeset
94 simply count all the headers found in the specified files. A summary is
kono
parents:
diff changeset
95 printed showing occurrences from high to low.
kono
parents:
diff changeset
96
kono
parents:
diff changeset
97 ex.: count-headers tree*.c
kono
parents:
diff changeset
98 86 : coretypes.h
kono
parents:
diff changeset
99 86 : config.h
kono
parents:
diff changeset
100 86 : system.h
kono
parents:
diff changeset
101 86 : tree.h
kono
parents:
diff changeset
102 82 : backend.h
kono
parents:
diff changeset
103 80 : gimple.h
kono
parents:
diff changeset
104 72 : gimple-iterator.h
kono
parents:
diff changeset
105 70 : ssa.h
kono
parents:
diff changeset
106 68 : fold-const.h
kono
parents:
diff changeset
107 <...>
kono
parents:
diff changeset
108
kono
parents:
diff changeset
109
kono
parents:
diff changeset
110
kono
parents:
diff changeset
111 included-by
kono
parents:
diff changeset
112 -----------
kono
parents:
diff changeset
113 This tool will search all the .c,.cc and .h files and output a list of files
kono
parents:
diff changeset
114 which include the specified header(s).
kono
parents:
diff changeset
115
kono
parents:
diff changeset
116 A 4 level deep 'find' of all source files is performed from the current
kono
parents:
diff changeset
117 directory and each of those is inspected for a #include of the specified
kono
parents:
diff changeset
118 headers. So expect a little bit of slowness.
kono
parents:
diff changeset
119
kono
parents:
diff changeset
120 -i limits the search to only other header files.
kono
parents:
diff changeset
121 -c limits the search to .c and .cc files.
kono
parents:
diff changeset
122 -a shows only source files which include all specified headers.
kono
parents:
diff changeset
123 -f allows you to specify a file which contains a list of source files to
kono
parents:
diff changeset
124 check rather than performing the much slower find command.
kono
parents:
diff changeset
125
kono
parents:
diff changeset
126 ex: included-by tree-vectorizer.h
kono
parents:
diff changeset
127 config/aarch64/aarch64.c
kono
parents:
diff changeset
128 config/i386/i386.c
kono
parents:
diff changeset
129 config/rs6000/rs6000.c
kono
parents:
diff changeset
130 tree-loop-distribution.c
kono
parents:
diff changeset
131 tree-parloops.c
kono
parents:
diff changeset
132 tree-ssa-loop-ivopts.c
kono
parents:
diff changeset
133 tree-ssa-loop.c
kono
parents:
diff changeset
134
kono
parents:
diff changeset
135
kono
parents:
diff changeset
136
kono
parents:
diff changeset
137
kono
parents:
diff changeset
138 replace-header
kono
parents:
diff changeset
139 --------------
kono
parents:
diff changeset
140 This tool simply replaces a single header file with one or more other headers.
kono
parents:
diff changeset
141 -r specifies the include to replace, and one or more -f options specify the
kono
parents:
diff changeset
142 replacement headers, in the order they occur.
kono
parents:
diff changeset
143
kono
parents:
diff changeset
144 This is commonly used in conjunction with 'included-by' to change all
kono
parents:
diff changeset
145 occurrences of a header file to something else, or to insert new headers
kono
parents:
diff changeset
146 before or after.
kono
parents:
diff changeset
147
kono
parents:
diff changeset
148 ex: to insert #include "before.h" before every occurence of tree.h in all
kono
parents:
diff changeset
149 .c and .cc source files:
kono
parents:
diff changeset
150
kono
parents:
diff changeset
151 replace-header -rtree.h -fbefore.h -ftree.h `included-by -c tree.h`
kono
parents:
diff changeset
152
kono
parents:
diff changeset
153
kono
parents:
diff changeset
154
kono
parents:
diff changeset
155
kono
parents:
diff changeset
156 reduce-headers
kono
parents:
diff changeset
157 --------------
kono
parents:
diff changeset
158
kono
parents:
diff changeset
159 This tool removes any header files which are not needed from a source file.
kono
parents:
diff changeset
160
kono
parents:
diff changeset
161 This tool must be run for the core gcc source directory, and requires either
kono
parents:
diff changeset
162 a native build and sometimes target builds, depending on what you are trying
kono
parents:
diff changeset
163 to reduce.
kono
parents:
diff changeset
164
kono
parents:
diff changeset
165 it is good practice to run 'gcc-order-headers' on a source file before trying
kono
parents:
diff changeset
166 to reduce it. This removes duplicates and performs some simplifications
kono
parents:
diff changeset
167 which reduce the chances of the reduction tool missing things.
kono
parents:
diff changeset
168
kono
parents:
diff changeset
169 start with a completely bootstrapped native compiler.
kono
parents:
diff changeset
170
kono
parents:
diff changeset
171 Any desired target builds should be built in one directory using a modified
kono
parents:
diff changeset
172 config-list.mk file which does not delete the build directory when it is done.
kono
parents:
diff changeset
173 any target directories which do not successfully complete a 'make all-gcc'
kono
parents:
diff changeset
174 may cause the tool to not reduce anything.
kono
parents:
diff changeset
175 (todo - provide a config-list.mk that leaves successful target builds, but
kono
parents:
diff changeset
176 deletes ones which do not compile)
kono
parents:
diff changeset
177
kono
parents:
diff changeset
178 The tool will examine all the target builds to determine which targets build
kono
parents:
diff changeset
179 the file, and include those targets in the testing.
kono
parents:
diff changeset
180
kono
parents:
diff changeset
181
kono
parents:
diff changeset
182
kono
parents:
diff changeset
183 The tool will analyze a source file and attempt to remove each non-conditional
kono
parents:
diff changeset
184 header from last to first in the file.:
kono
parents:
diff changeset
185 It will first attempt to build the native all-gcc target.
kono
parents:
diff changeset
186 If that succeeds, it will attempt to build any target build .o files
kono
parents:
diff changeset
187 If that succeeds, it will check to see if there are any conditional
kono
parents:
diff changeset
188 compilation dependencies between this header file and the source file or
kono
parents:
diff changeset
189 any header which have already been determined as non-removable.
kono
parents:
diff changeset
190 If all these tests are passed, the header file is determined to be removable
kono
parents:
diff changeset
191 and is removed from the source file.
kono
parents:
diff changeset
192 This continues until all headers have been checked.
kono
parents:
diff changeset
193 At this point, a bootstrap is attempted in the native build, and if that
kono
parents:
diff changeset
194 passes the file is considered reduced.
kono
parents:
diff changeset
195
kono
parents:
diff changeset
196 Any files from the config subdirectory require target builds to be present
kono
parents:
diff changeset
197 in order to proceed.
kono
parents:
diff changeset
198
kono
parents:
diff changeset
199 A small subset of targets has been determined to provide excellent coverage,
kono
parents:
diff changeset
200 at least as of Aug 31/15 . They were found by reducing all the files
kono
parents:
diff changeset
201 contained in libbackend.a oer a full set of targets(207). All conditions
kono
parents:
diff changeset
202 which disallowed removal of a header file were triggered by one or more of
kono
parents:
diff changeset
203 these targets. They are also known to the tool. When building targets it
kono
parents:
diff changeset
204 will check those targets before the rest.
kono
parents:
diff changeset
205 This coverage can be achieved by building config-list.mk with :
kono
parents:
diff changeset
206 LIST="aarch64-linux-gnu arm-netbsdelf c6x-elf epiphany-elf hppa2.0-hpux10.1 i686-mingw32crt i686-pc-msdosdjgpp mipsel-elf powerpc-eabisimaltivec rs6000-ibm-aix5.1.0 sh-superh-elf sparc64-elf spu-elf"
kono
parents:
diff changeset
207
kono
parents:
diff changeset
208 -b specifies the native bootstrapped build root directory
kono
parents:
diff changeset
209 -t specifies a target build root directory that config-list.mk was run from
kono
parents:
diff changeset
210 -f is used to limit the headers for consideration.
kono
parents:
diff changeset
211
kono
parents:
diff changeset
212 example:
kono
parents:
diff changeset
213
kono
parents:
diff changeset
214 mkdir gcc // checkout gcc in subdir gcc
kono
parents:
diff changeset
215 mdsir build // boostrap gcc in subdir build
kono
parents:
diff changeset
216 mkdir target // create target directory and run config-list.mk
kono
parents:
diff changeset
217 cd gcc/gcc
kono
parents:
diff changeset
218
kono
parents:
diff changeset
219 reduce-headers -b../../build -t../../targets -falias.h -fexpr.h tree*.c (1)
kono
parents:
diff changeset
220 # This will attempt to remove only alias.h and expr.h from tree*.c
kono
parents:
diff changeset
221
kono
parents:
diff changeset
222 reduce-headers -b../../build -t../../targets tree-ssa-live.c
kono
parents:
diff changeset
223 # This will attempt to remove all header files from tree-ssa-live.c
kono
parents:
diff changeset
224
kono
parents:
diff changeset
225
kono
parents:
diff changeset
226 the tool will generate a number of log files:
kono
parents:
diff changeset
227
kono
parents:
diff changeset
228 reduce-headers.log : All compilation failures from attempted reductions.
kono
parents:
diff changeset
229 reduce-headers.sum : One line summary of what happened to each source file.
kono
parents:
diff changeset
230
kono
parents:
diff changeset
231 (All the remaining logs are appended to, so if the tool is run multiple times
kono
parents:
diff changeset
232 these files are just added to. You must physically remove them yourself in
kono
parents:
diff changeset
233 order to reset the logs.)
kono
parents:
diff changeset
234
kono
parents:
diff changeset
235 reduce-headers-kept.log: List of all the successful compiles that were
kono
parents:
diff changeset
236 ignored because of conditional macro dependencies
kono
parents:
diff changeset
237 and why it thinks that is the case
kono
parents:
diff changeset
238 $src.c.log : for each failed header removal, the compilation
kono
parents:
diff changeset
239 messages as to why it failed.
kono
parents:
diff changeset
240 $header.h.log: The same log is put into the relevant header log as well.
kono
parents:
diff changeset
241
kono
parents:
diff changeset
242
kono
parents:
diff changeset
243 a sample output from ira.c.log:
kono
parents:
diff changeset
244
kono
parents:
diff changeset
245 Compilation failed:
kono
parents:
diff changeset
246 for shrink-wrap.h:
kono
parents:
diff changeset
247
kono
parents:
diff changeset
248 ============================================
kono
parents:
diff changeset
249 /gcc/2015-09-09/gcc/gcc/ira.c: In function ‘bool split_live_ranges_for_shrink_wrap()’:
kono
parents:
diff changeset
250 /gcc/2015-09-09/gcc/gcc/ira.c:4839:8: error: ‘SHRINK_WRAPPING_ENABLED’ was not declared in this scope
kono
parents:
diff changeset
251 if (!SHRINK_WRAPPING_ENABLED)
kono
parents:
diff changeset
252 ^
kono
parents:
diff changeset
253 make: *** [ira.o] Error 1
kono
parents:
diff changeset
254
kono
parents:
diff changeset
255
kono
parents:
diff changeset
256 the same message would be put into shrink-wrap.h.log.
kono
parents:
diff changeset
257
kono
parents:
diff changeset
258
kono
parents:
diff changeset
259
kono
parents:
diff changeset
260 graph-header-logs
kono
parents:
diff changeset
261 -----------------
kono
parents:
diff changeset
262 This tool will parse all the messages from the .C files, looking for failures
kono
parents:
diff changeset
263 that show up in other headers... meaning there is a compilation dependency
kono
parents:
diff changeset
264 between the 2 header files.
kono
parents:
diff changeset
265
kono
parents:
diff changeset
266 The tool will aggregate all these and generate a graph of the dependencies
kono
parents:
diff changeset
267 exposed during compilation. Red lines indicate dependencies that are
kono
parents:
diff changeset
268 present because a header file physically includes another file. Black lines
kono
parents:
diff changeset
269 represent data dependencies causing compilation failures if the header is
kono
parents:
diff changeset
270 not present.
kono
parents:
diff changeset
271
kono
parents:
diff changeset
272 ex.: graph-header-logs *.c.log
kono
parents:
diff changeset
273
kono
parents:
diff changeset
274
kono
parents:
diff changeset
275
kono
parents:
diff changeset
276 graph-include-web
kono
parents:
diff changeset
277 -----------------
kono
parents:
diff changeset
278 This tool can be used to visualize the include structure in files. It is
kono
parents:
diff changeset
279 rapidly turned useless if you specify too many things, but it can be
kono
parents:
diff changeset
280 useful for finding cycles and redundancies, or simply to see what a single
kono
parents:
diff changeset
281 file looks like.
kono
parents:
diff changeset
282
kono
parents:
diff changeset
283 ex.: graph-include-web tree.c