blob: 51f436e3b49ab686200a1442eb66ba59a0898c01 [file] [log] [blame]
Reid Spencerbe65afb2004-08-06 16:58:48 +00001=pod
2
3=head1 NAME
4
5llvmc - The LLVM Compiler Driver
6
7=head1 SYNOPSIS
8
9B<llvmc> [I<options>] [I<filenames>...]
10
11=head1 DESCRIPTION
12
13The B<llvmc> command is a configurable driver for invoking other
14LLVM (and non-LLVM) tools in order to compile, optimize and link software
15for multiple languages. For those familiar with the GNU Compiler
16Collection's B<gcc> tool, it is very similar. This tool has the
17following main goals or purposes:
18
19=over
20
21=item * A Single point of access to the LLVM tool set.
22
23=item * Hide the complexities of the LLVM tools through a single interface.
24
25=item * Make integration of existing non-LLVM tools simple.
26
27=item * Extend the capabilities of minimal front ends.
28
29=item * Make the interface for compiling consistent for all languages.
30
31=back
32
33The tool itself does nothing with a user's program. It merely invokes other
34tools to get the compilation tasks done.
35
Reid Spencerf2edda02004-08-06 22:28:47 +000036The options supported by B<llvmc> generalize the compilation process and
37provide a consistent and simple interface for multiple programming languages.
38This makes it easier for developers to get their software compiled with LLVM.
39Without B<llvmc>, developers would need to understand how to invoke the
40front-end compiler, optimizer, assembler, and linker in order to compile their
41programs. B<llvmc>'s sole mission is to trivialize that process.
42
Reid Spencerbe65afb2004-08-06 16:58:48 +000043=head2 Basic Operation
44
45B<llvmc> always takes the following basic actions:
46
47=over
48
49=item * Command line options and filenames are collected.
50
Reid Spencerf2edda02004-08-06 22:28:47 +000051The command line options provide the marching orders to B<llvmc> on what actions
52it should perform. This is the I<request> the user is making of B<llvmc> and it
53is interpreted first.
Reid Spencerbe65afb2004-08-06 16:58:48 +000054
55=item * Configuration files are read.
56
Reid Spencerf2edda02004-08-06 22:28:47 +000057Based on the options and the suffixes of the filenames presented, a set of
58configuration files are read to configure the actions B<llvmc> will take
59(more on this later).
Reid Spencerbe65afb2004-08-06 16:58:48 +000060
61=item * Determine actions to take.
62
Reid Spencerf2edda02004-08-06 22:28:47 +000063The tool chain needed to complete the task is determined. This is the primary
64work of B<llvmc>. It breaks the request specified by the command line options
65into a set of basic actions to be done:
66
67=over
68
69=item * Pre-processing: gathering/filtering compiler input
70
71=item * Compilation: source language to bytecode conversion
72
73=item * Assembly: bytecode to native code conversion
74
75=item * Optimization: conversion of bytecode to something that runs faster
76
77=item * Linking: combining multiple bytecodes to produce executable program
78
79=back
Reid Spencerbe65afb2004-08-06 16:58:48 +000080
81=item * Execute actions.
82
83The actions determined previously are executed sequentially and then
84B<llvmc> terminates.
85
86=back
87
Reid Spencerbe65afb2004-08-06 16:58:48 +000088=head1 OPTIONS
89
90=head2 Control Options
91
92Control options tell B<llvmc> what to do at a high level. The
93following control options are defined:
94
95=over
96
97=item B<-c> or B<--compile>
98
99This option specifies that the linking phase is not to be run. All
100previous phases, if applicable will run. This is generally how a given
101bytecode file is compiled and optimized for a source language module.
102
103=item B<-k> or B<--link> or default
104
105This option (or the lack of any control option) specifies that all stages
106of compilation, optimization, and linking should be attempted. Source files
107specified on the command line will be compiled and linked with objects and
108libraries also specified.
109
110=item B<-S> or B<--assemble>
111
112This option specifies that compilation should end in the creation of
113an LLVM assembly file that can be later converted to an LLVM object
114file.
115
116=item B<-E> or B<--preprocess>
117
118This option specifies that no compilation or linking should be
Reid Spencerf9cdefb2004-08-06 22:56:49 +0000119performed. Only pre-processing, if applicable to the language being
Reid Spencerbe65afb2004-08-06 16:58:48 +0000120compiled, is performed. For languages that support it, this will
121result in the output containing the raw input to the compiler.
122
123=back
124
125=head2 Optimization Options
126
127Optimization with B<llvmc> is based on goals and specified with
128the following -O options. The specific details of which
129optimizations run is controlled by the configuration files because
130each source language will have different needs.
131
132=over
133
134=item B<-O1> or B<-O0> (default, fast compilation)
135
Reid Spencerf9cdefb2004-08-06 22:56:49 +0000136Only those optimizations that will hasten the compilation (mostly by reducing
Reid Spencerbe65afb2004-08-06 16:58:48 +0000137the output) are applied. In general these are extremely fast and simple
138optimizations that reduce emitted code size. The goal here is not to make the
139resulting program fast but to make the compilation fast. If not specified,
140this is the default level of optimization.
141
142=item B<-O2> (basic optimization)
143
144This level of optimization specifies a balance between generating good code
Reid Spencerf9cdefb2004-08-06 22:56:49 +0000145that will execute reasonably quickly and not spending too much time optimizing
Reid Spencerbe65afb2004-08-06 16:58:48 +0000146the code to get there. For example, this level of optimization may include
Reid Spencerf9cdefb2004-08-06 22:56:49 +0000147things like global common subexpression elimination, aggressive dead code
Reid Spencerbe65afb2004-08-06 16:58:48 +0000148elimination, and scalar replication.
149
150=item B<-O3> (aggressive optimization)
151
152This level of optimization aggressively optimizes each set of files compiled
153together. However, no link-time inter-procedural optimization is performed.
154This level implies all the optimizations of the B<-O1> and B<-O2> optimization
Reid Spencerf9cdefb2004-08-06 22:56:49 +0000155levels, and should also provide loop optimizations and compile time
Reid Spencerbe65afb2004-08-06 16:58:48 +0000156inter-procedural optimizations. Essentially, this level tries to do as much
157as it can with the input it is given but doesn't do any link time IPO.
158
Reid Spencerf9cdefb2004-08-06 22:56:49 +0000159=item B<-O4> (link time optimization)
Reid Spencerbe65afb2004-08-06 16:58:48 +0000160
161In addition to the previous three levels of optimization, this level of
162optimization aggressively optimizes each program at link time. It employs
163basic analysis and basic link-time inter-procedural optimizations,
164considering the program as a whole.
165
Reid Spencerf9cdefb2004-08-06 22:56:49 +0000166=item B<-O5> (aggressive link time optimization)
Reid Spencerbe65afb2004-08-06 16:58:48 +0000167
168This is the same as B<-O4> except it employs aggressive analyses and
169aggressive inter-procedural optimization.
170
Reid Spencerf2edda02004-08-06 22:28:47 +0000171=item B<-O6> (profile guided optimization: not implemented)
Reid Spencerbe65afb2004-08-06 16:58:48 +0000172
Reid Spencerf9cdefb2004-08-06 22:56:49 +0000173This is the same as B<-O5> except that it employs profile-guided
174re-optimization of the program after it has executed. Note that this implies
175a single level of re-optimization based on runtime profile analysis. Once
Reid Spencerbe65afb2004-08-06 16:58:48 +0000176the re-optimization has completed, the profiling instrumentation is
177removed and final optimizations are employed.
178
Reid Spencerf2edda02004-08-06 22:28:47 +0000179=item B<-O7> (lifelong optimization: not implemented)
Reid Spencerbe65afb2004-08-06 16:58:48 +0000180
Reid Spencerf9cdefb2004-08-06 22:56:49 +0000181This is the same as B<-O5> and similar to B<-O6> except that re-optimization
Reid Spencerbe65afb2004-08-06 16:58:48 +0000182is performed through the life of the program. That is, each run will update
Reid Spencerf9cdefb2004-08-06 22:56:49 +0000183the profile by which future re-optimizations are directed.
Reid Spencerbe65afb2004-08-06 16:58:48 +0000184
185=back
186
187=head2 Input Options
188
189=over
190
191=item B<-l> I<LIBRARY>
192
193This option instructs B<llvmc> to locate a library named I<LIBRARY> and search
194it for unresolved symbols when linking the program.
195
196=item B<-L> F<path>
197
198This option instructs B<llvmc> to add F<path> to the list of places in which
199the linker will
200
201=item B<-x> I<LANGUAGE>
202
203This option instructs B<llvmc> to regard the following input files as
204containing programs in the language I<LANGUAGE>. Normally, input file languages
205are identified by their suffix but this option will override that default
206behavior. The B<-x> option stays in effect until the end of the options or
207a new B<-x> option is encountered.
208
209=back
210
211=head2 Output Options
212
213=over
214
215=item B<-m>I<arch>
216
217This option selects the back end code generator to use. The I<arch> portion
218of the option names the back end to use.
219
220=item B<--native>
221
222Normally, B<llvmc> produces bytecode files at most stages of compilation.
223With this option, B<llvmc> will arrange for native object files to be
224generated with the B<-c> option, native assembly files to be generated
225with the B<-S> option, and native executables to be generated with the
226B<--link> option. In the case of the B<-E> option, the output will not
227differ as there is no I<native> version of pre-processed output.
228
229=item B<-o> F<filename>
230
231Specify the output file name. The contents of the file depend on other
232options.
233
234=back
235
Reid Spencerbe65afb2004-08-06 16:58:48 +0000236=head2 Information Options
237
238=over
239
Reid Spencerf9cdefb2004-08-06 22:56:49 +0000240=item B<-n> or B<--no-op>
Reid Spencerbe65afb2004-08-06 16:58:48 +0000241
242This option tells B<llvmc> to do everything but actually execute the
243resulting tools. In combination with the B<-v> option, this causes B<llvmc>
244to merely print out what it would have done.
245
246=item B<-v> or B<--verbose>
247
248This option will cause B<llvmc> to print out (on standard output) each of the
249actions it takes to accomplish the objective. The output will immediately
250precede the invocation of other tools.
251
252=item B<--stats>
253
254Print all statistics gathered during the compilation to the standard error.
255Note that this option is merely passed through to the sub-tools to do with
256as they please.
257
258=item B<--time-passes>
259
260Record the amount of time needed for each optimization pass and print it
261to standard error. Like B<--stats> this option is just passed through to
262the sub-tools to do with as they please.
263
264=item B<--time-programs>
265
266Record the amount of time each program (compilation tool) takes and print
267it to the standard error.
268
269=back
270
271=head2 Language Specific Options
272
273=over
274
275
276=item B<-Tool,opt>=I<options>
277
278Pass an arbitrary option to the optimizer.
279
280=item B<-Tool,link>=I<options>
281
282Pass an arbitrary option to the linker.
283
284=item B<-Tool,asm>=I<options>
285
Reid Spencerf9cdefb2004-08-06 22:56:49 +0000286Pass an arbitrary option to the code generator.
Reid Spencerbe65afb2004-08-06 16:58:48 +0000287
288=back
289
290=head3 C/C++ Specific Options
291
292=over
293
Reid Spencerf2edda02004-08-06 22:28:47 +0000294=item B<-I>F<path>
Reid Spencerbe65afb2004-08-06 16:58:48 +0000295
296This option is just passed through to a C or C++ front end compiler to tell it
297where include files can be found.
298
299=back
300
Reid Spencerbe65afb2004-08-06 16:58:48 +0000301=head2 Miscellaneous Options
302
303=over
304
305=item B<--help>
306
307Print a summary of command line options.
308
309=item B<-V> or B<--version>
310
311This option will cause B<llvmc> to print out its version number
312and terminate.
313
314=back
315
Reid Spencerf2edda02004-08-06 22:28:47 +0000316=head2 Advanced Options
317
318You better know what you're doing if you use these options. Improper use
319of these options can produce drastically wrong results.
320
321=over
322
323=item B<--show-config> I<[suffixes...]>
324
325When this option is given, the only action taken by B<llvmc> is to show its
326final configuration state in the form of a configuration file. No compilation
327tasks will be conducted when this option is given; processing will stop once
328the configuration has been printed. The optional (comma separated) list of
329suffixes controls what is printed. Without any suffixes, the configuration
330for all languages is printed. With suffixes, only the languages pertaining
331to those file suffixes will be printed. The configuration information is
332printed after all command line options and configuration files have been
333read and processed. This allows the user to verify that the correct
334configuration data has been read by B<llvmc>.
335
336=item B<--config> :I<section>:I<name>=I<value>
337
338This option instructs B<llvmc> to accept I<value> as the value for configuration
339item I<name> in the section named I<section>. This is a quick way to override
340a configuration item on the command line without resorting to changing the
341configuration files.
342
343=item B<--config-file> F<dirname>
344
345This option tells B<llvmc> to read configuration data from the I<directory>
346named F<dirname>. Data from such directories will be read in the order
Reid Spencerf9cdefb2004-08-06 22:56:49 +0000347specified on the command line after all other standard configuration files have
Reid Spencerf2edda02004-08-06 22:28:47 +0000348been read. This allows users or groups of users to conveniently create
349their own configuration directories in addition to the standard ones to which
350they may not have write access.
351
352=item B<--config-only-from> F<dirname>
353
354This option tells B<llvmc> to skip the normal processing of configuration
355files and only configure from the contents of the F<dirname> directory. Multiple
356B<--config-only-from> options may be given in which case the directories are
357read in the order given on the command line.
358
359
360=item B<--emit-raw-code>
361
362No optimization is done whatsoever. The compilers invoked by B<llvmc> with
363this option given will be instructed to produce raw, unoptimized code. This
364option is useful only to front end language developers and therefore does not
365participate in the list of B<-O> options. This is distinctly different from
366the B<-O0> option (a synonym for B<-O1>) because those optimizations will
367reduce code size to make compilation faster. With B<--emit-raw-code>, only
368the full raw code produced by the compiler will be generated.
369
370=back
371
372=head1 CONFIGURATION
373
374=head2 Warning
375
376Configuration information is relatively static for a given release of LLVM and
377a front end compiler. However, the details may change from release to release.
378Users are encouraged to simply use the various options of the B<llvmc> command
379and ignore the configuration of the tool. These configuration files are for
380compiler writers and LLVM developers. Those wishing to simply use B<llvmc>
381don't need to understand this section but it may be instructive on what the tool
382does.
383
384=head2 Introduction
385
386B<llvmc> is highly configurable both on the command line and in configuration
387files. The options it understands are generic, consistent and simple by design.
388Furthermore, the B<llvmc> options apply to the compilation of any LLVM enabled
389programming language. To be enabled as a supported source language compiler, a
390compiler writer must provide a configuration file that tells B<llvmc> how to
391invoke the compiler and what its capabilities are. The purpose of the
392configuration files then is to allow compiler writers to specify to B<llvmc> how
393the compiler should be invoked. Users may but are not advised to alter the
394compiler's B<llvmc> configuration.
395
396Because B<llvmc> just invokes other programs, it must deal with the
397available command line options for those programs regardless of whether they
398were written for LLVM or not. Furthermore, not all compilation front ends will
399have the same capabilities. Some front ends will simply generate LLVM assembly
400code, others will be able to generate fully optimized byte code. In general,
401B<llvmc> doesn't make any assumptions about the capabilities or command line
402options of a sub-tool. It simply uses the details found in the configuration
403files and leaves it to the compiler writer to specify the configuration
404correctly.
405
Reid Spencerf9cdefb2004-08-06 22:56:49 +0000406This approach means that new compiler front ends can be up and working very
Reid Spencerf2edda02004-08-06 22:28:47 +0000407quickly. As a first cut, a front end can simply compile its source to raw
408(unoptimized) bytecode or LLVM assembly and B<llvmc> can be configured to pick
Reid Spencerf9cdefb2004-08-06 22:56:49 +0000409up the slack (translate LLVM assembly to bytecode, optimize the bytecode,
Reid Spencerf2edda02004-08-06 22:28:47 +0000410generate native assembly, link, etc.). In fact, the front end need not use
411any LLVM libraries, and it could be written in any language (instead of C++).
412The configuration data will allow the full range of optimization, assembly,
413and linking capabilities that LLVM provides to be added to these kinds of tools.
414Enabling the rapid development of front-ends is one of the primary goals of
415B<llvmc>.
416
417As a compiler front end matures, it may utilize the LLVM libraries and tools to
418more efficiently produce optimized bytecode directly in a single compilation and
419optimization program. In these cases, multiple tools would not be needed and
420the configuration data for the compiler would change.
421
422Configuring B<llvmc> to the needs and capabilities of a source language compiler
423is relatively straight forward. The compilation process is broken down into five
424phases:
425
426=over
427
428=item * Pre-processing (filter and combine source files)
429
430=item * Translation (translate source language to LLVM assembly or bytecode)
431
432=item * Optimization (make bytecode execute quickly)
433
434=item * Assembly (converting bytecode to object code)
435
436=item * Linking (converting translated code to an executable)
437
438=back
439
440A compiler writer must provide a definition of what to do for each of these five
441phases for each of the optimization levels. The specification consists simply of
442prototypical command lines into which B<llvmc> can substitute command line
443arguments and file names. Note that any given phase can be completely blank if
444the source language's compiler combines multiple phases into a single program.
Reid Spencerf9cdefb2004-08-06 22:56:49 +0000445For example, quite often pre-processing, translation, and optimization are
Reid Spencerf2edda02004-08-06 22:28:47 +0000446combined into a single program. The specification for such a compiler would have
447blank entries for pre-processing and translation but a full command line for
448optimization.
449
450=head2 Configuration File Types
451
452There are two types of configuration files: the master configuration file
453and the language specific configuration file.
454
455The master configuration file contains the general configuration of B<llvmc>
456itself. This includes things like the mapping between file extensions and
457source languages. This mapping is needed in order to quickly read only the
Reid Spencerf9cdefb2004-08-06 22:56:49 +0000458applicable language-specific configuration files (avoiding reading every
459configuration file for every compilation task).
Reid Spencerf2edda02004-08-06 22:28:47 +0000460
461Language specific configuration files tell B<llvmc> how to invoke the language's
462compiler for a variety of different tasks and what other tools are needed to
463I<backfill> the compiler's missing features (e.g. optimization).
464
465Language specific configuration files are placed in directories and given
466specific names to foster faster lookup. The name of a given configuration file
467is the name of the source language.
468
469=head2 Default Directory Locations
470
471B<llvmc> will look for configuration files in two standard locations: the
472LLVM installation directory (typically C</usr/local/llvm/etc>) and the user's
Reid Spencerf9cdefb2004-08-06 22:56:49 +0000473home directory (typically C</home/user/.llvm>). In these directories a file
474named C<master> provides the master configuration for B<llvmc>. Language
475specific files will have a language specific name (e.g. C++, Stacker, Scheme,
476FORTRAN). When reading the configuration files, the master files are always
477read first in the following order:
Reid Spencerf2edda02004-08-06 22:28:47 +0000478
479=over
480
481=item 1 C<master> in LLVM installation directory
482
483=item 2 C<master> in the user's home directory.
484
485=back
486
487Then, based on the command line options and the suffixes of the file names
488provided on B<llvmc>'s command line, one or more language specific configuration
489files are read. Only the language specific configuration files actually needed
490to complete B<llvmc>'s task are read. Other language specific files will be
491ignored.
492
493Note that the user can affect this process in several ways using the various
494B<--config-*> options and with the B<--x LANGUAGE> option.
495
496Although a user I<can> override the master configuration file, this is not
497advised. The capability is retained so that compiler writers can affect the
498master configuration (such as adding new file suffixes) while developing a new
499compiler front end since they might not have write access to the installed
500master configuration.
501
502=head2 Syntax
503
504The syntax of the configuration files is yet to be determined. There are three
505viable options:
506
507=over
508
509=item XML
510=item Windows .ini
511=item specific to B<llvmc>
512
513=back
514
Reid Spencerbe65afb2004-08-06 16:58:48 +0000515=head1 EXIT STATUS
516
517If B<llvmc> succeeds, it will exit with 0. Otherwise, if an error
518occurs, it will exit with a non-zero value and no compilation actions
519will be taken. If one of the compilation tools returns a non-zero
520status, pending actions will be discarded and B<llvmc> will return the
521same result code as the failing compilation tool.
522
523=head1 SEE ALSO
524
525L<gccas|gccas>, L<gccld|gccld>, L<llvm-as|llvm-as>, L<llvm-dis|llvm-dis>,
526L<llc|llc>, L<llvm-link|llvm-link>
527
528=head1 AUTHORS
529
530Reid Spencer
531
532=cut