blob: 735a30cb823ba68c4aa153e9fac809fac8c6e4b1 [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
Reid Spenceraf2f9242004-08-07 16:30:14 +0000275=item B<-T,pp>=I<options>
Reid Spencerbe65afb2004-08-06 16:58:48 +0000276
Reid Spenceraf2f9242004-08-07 16:30:14 +0000277Pass an arbitrary option to the pre-processor.
278
279=item B<-T,opt>=I<options>
Reid Spencerbe65afb2004-08-06 16:58:48 +0000280
281Pass an arbitrary option to the optimizer.
282
Reid Spenceraf2f9242004-08-07 16:30:14 +0000283=item B<-T,link>=I<options>
Reid Spencerbe65afb2004-08-06 16:58:48 +0000284
285Pass an arbitrary option to the linker.
286
Reid Spenceraf2f9242004-08-07 16:30:14 +0000287=item B<-T,asm>=I<options>
Reid Spencerbe65afb2004-08-06 16:58:48 +0000288
Reid Spencerf9cdefb2004-08-06 22:56:49 +0000289Pass an arbitrary option to the code generator.
Reid Spencerbe65afb2004-08-06 16:58:48 +0000290
291=back
292
293=head3 C/C++ Specific Options
294
295=over
296
Reid Spencerf2edda02004-08-06 22:28:47 +0000297=item B<-I>F<path>
Reid Spencerbe65afb2004-08-06 16:58:48 +0000298
299This option is just passed through to a C or C++ front end compiler to tell it
300where include files can be found.
301
302=back
303
Reid Spencerbe65afb2004-08-06 16:58:48 +0000304=head2 Miscellaneous Options
305
306=over
307
308=item B<--help>
309
310Print a summary of command line options.
311
312=item B<-V> or B<--version>
313
314This option will cause B<llvmc> to print out its version number
315and terminate.
316
317=back
318
Reid Spencerf2edda02004-08-06 22:28:47 +0000319=head2 Advanced Options
320
321You better know what you're doing if you use these options. Improper use
322of these options can produce drastically wrong results.
323
324=over
325
326=item B<--show-config> I<[suffixes...]>
327
328When this option is given, the only action taken by B<llvmc> is to show its
329final configuration state in the form of a configuration file. No compilation
330tasks will be conducted when this option is given; processing will stop once
331the configuration has been printed. The optional (comma separated) list of
332suffixes controls what is printed. Without any suffixes, the configuration
333for all languages is printed. With suffixes, only the languages pertaining
334to those file suffixes will be printed. The configuration information is
335printed after all command line options and configuration files have been
336read and processed. This allows the user to verify that the correct
337configuration data has been read by B<llvmc>.
338
339=item B<--config> :I<section>:I<name>=I<value>
340
341This option instructs B<llvmc> to accept I<value> as the value for configuration
342item I<name> in the section named I<section>. This is a quick way to override
343a configuration item on the command line without resorting to changing the
344configuration files.
345
346=item B<--config-file> F<dirname>
347
348This option tells B<llvmc> to read configuration data from the I<directory>
349named F<dirname>. Data from such directories will be read in the order
Reid Spencerf9cdefb2004-08-06 22:56:49 +0000350specified on the command line after all other standard configuration files have
Reid Spencerf2edda02004-08-06 22:28:47 +0000351been read. This allows users or groups of users to conveniently create
352their own configuration directories in addition to the standard ones to which
353they may not have write access.
354
355=item B<--config-only-from> F<dirname>
356
357This option tells B<llvmc> to skip the normal processing of configuration
358files and only configure from the contents of the F<dirname> directory. Multiple
359B<--config-only-from> options may be given in which case the directories are
360read in the order given on the command line.
361
362
363=item B<--emit-raw-code>
364
365No optimization is done whatsoever. The compilers invoked by B<llvmc> with
366this option given will be instructed to produce raw, unoptimized code. This
367option is useful only to front end language developers and therefore does not
368participate in the list of B<-O> options. This is distinctly different from
369the B<-O0> option (a synonym for B<-O1>) because those optimizations will
370reduce code size to make compilation faster. With B<--emit-raw-code>, only
371the full raw code produced by the compiler will be generated.
372
373=back
374
375=head1 CONFIGURATION
376
377=head2 Warning
378
379Configuration information is relatively static for a given release of LLVM and
380a front end compiler. However, the details may change from release to release.
381Users are encouraged to simply use the various options of the B<llvmc> command
382and ignore the configuration of the tool. These configuration files are for
383compiler writers and LLVM developers. Those wishing to simply use B<llvmc>
384don't need to understand this section but it may be instructive on what the tool
385does.
386
387=head2 Introduction
388
389B<llvmc> is highly configurable both on the command line and in configuration
390files. The options it understands are generic, consistent and simple by design.
391Furthermore, the B<llvmc> options apply to the compilation of any LLVM enabled
392programming language. To be enabled as a supported source language compiler, a
393compiler writer must provide a configuration file that tells B<llvmc> how to
394invoke the compiler and what its capabilities are. The purpose of the
395configuration files then is to allow compiler writers to specify to B<llvmc> how
396the compiler should be invoked. Users may but are not advised to alter the
397compiler's B<llvmc> configuration.
398
399Because B<llvmc> just invokes other programs, it must deal with the
400available command line options for those programs regardless of whether they
401were written for LLVM or not. Furthermore, not all compilation front ends will
402have the same capabilities. Some front ends will simply generate LLVM assembly
403code, others will be able to generate fully optimized byte code. In general,
404B<llvmc> doesn't make any assumptions about the capabilities or command line
405options of a sub-tool. It simply uses the details found in the configuration
406files and leaves it to the compiler writer to specify the configuration
407correctly.
408
Reid Spencerf9cdefb2004-08-06 22:56:49 +0000409This approach means that new compiler front ends can be up and working very
Reid Spencerf2edda02004-08-06 22:28:47 +0000410quickly. As a first cut, a front end can simply compile its source to raw
411(unoptimized) bytecode or LLVM assembly and B<llvmc> can be configured to pick
Reid Spencerf9cdefb2004-08-06 22:56:49 +0000412up the slack (translate LLVM assembly to bytecode, optimize the bytecode,
Reid Spencerf2edda02004-08-06 22:28:47 +0000413generate native assembly, link, etc.). In fact, the front end need not use
414any LLVM libraries, and it could be written in any language (instead of C++).
415The configuration data will allow the full range of optimization, assembly,
416and linking capabilities that LLVM provides to be added to these kinds of tools.
417Enabling the rapid development of front-ends is one of the primary goals of
418B<llvmc>.
419
420As a compiler front end matures, it may utilize the LLVM libraries and tools to
421more efficiently produce optimized bytecode directly in a single compilation and
422optimization program. In these cases, multiple tools would not be needed and
423the configuration data for the compiler would change.
424
425Configuring B<llvmc> to the needs and capabilities of a source language compiler
426is relatively straight forward. The compilation process is broken down into five
427phases:
428
429=over
430
431=item * Pre-processing (filter and combine source files)
432
433=item * Translation (translate source language to LLVM assembly or bytecode)
434
435=item * Optimization (make bytecode execute quickly)
436
437=item * Assembly (converting bytecode to object code)
438
439=item * Linking (converting translated code to an executable)
440
441=back
442
443A compiler writer must provide a definition of what to do for each of these five
444phases for each of the optimization levels. The specification consists simply of
445prototypical command lines into which B<llvmc> can substitute command line
446arguments and file names. Note that any given phase can be completely blank if
447the source language's compiler combines multiple phases into a single program.
Reid Spencerf9cdefb2004-08-06 22:56:49 +0000448For example, quite often pre-processing, translation, and optimization are
Reid Spencerf2edda02004-08-06 22:28:47 +0000449combined into a single program. The specification for such a compiler would have
450blank entries for pre-processing and translation but a full command line for
451optimization.
452
453=head2 Configuration File Types
454
455There are two types of configuration files: the master configuration file
456and the language specific configuration file.
457
458The master configuration file contains the general configuration of B<llvmc>
459itself. This includes things like the mapping between file extensions and
460source languages. This mapping is needed in order to quickly read only the
Reid Spencerf9cdefb2004-08-06 22:56:49 +0000461applicable language-specific configuration files (avoiding reading every
462configuration file for every compilation task).
Reid Spencerf2edda02004-08-06 22:28:47 +0000463
464Language specific configuration files tell B<llvmc> how to invoke the language's
465compiler for a variety of different tasks and what other tools are needed to
466I<backfill> the compiler's missing features (e.g. optimization).
467
468Language specific configuration files are placed in directories and given
469specific names to foster faster lookup. The name of a given configuration file
470is the name of the source language.
471
472=head2 Default Directory Locations
473
474B<llvmc> will look for configuration files in two standard locations: the
475LLVM installation directory (typically C</usr/local/llvm/etc>) and the user's
Reid Spencerf9cdefb2004-08-06 22:56:49 +0000476home directory (typically C</home/user/.llvm>). In these directories a file
477named C<master> provides the master configuration for B<llvmc>. Language
478specific files will have a language specific name (e.g. C++, Stacker, Scheme,
479FORTRAN). When reading the configuration files, the master files are always
480read first in the following order:
Reid Spencerf2edda02004-08-06 22:28:47 +0000481
482=over
483
484=item 1 C<master> in LLVM installation directory
485
486=item 2 C<master> in the user's home directory.
487
488=back
489
490Then, based on the command line options and the suffixes of the file names
491provided on B<llvmc>'s command line, one or more language specific configuration
492files are read. Only the language specific configuration files actually needed
493to complete B<llvmc>'s task are read. Other language specific files will be
494ignored.
495
496Note that the user can affect this process in several ways using the various
497B<--config-*> options and with the B<--x LANGUAGE> option.
498
499Although a user I<can> override the master configuration file, this is not
500advised. The capability is retained so that compiler writers can affect the
501master configuration (such as adding new file suffixes) while developing a new
502compiler front end since they might not have write access to the installed
503master configuration.
504
505=head2 Syntax
506
507The syntax of the configuration files is yet to be determined. There are three
508viable options:
509
510=over
511
512=item XML
Reid Spenceraf2f9242004-08-07 16:30:14 +0000513
Reid Spencerf2edda02004-08-06 22:28:47 +0000514=item Windows .ini
Reid Spenceraf2f9242004-08-07 16:30:14 +0000515
Reid Spencerf2edda02004-08-06 22:28:47 +0000516=item specific to B<llvmc>
517
518=back
519
Reid Spenceraf2f9242004-08-07 16:30:14 +0000520=head2 Master Configuration Items
521
522=head3 Section: [lang=I<LANGUAGE>]
523
524This section provides the master configuration data for a given language. The
525language specific data will be found in a file named I<LANGUAGE>.
526
527=over
528
529=item C<suffix=>I<suffix>
530
531This adds the I<suffix> specified to the list of recognized suffixes for
532the I<LANGUAGE> identified in the section. As many suffixes as are commonly used
533for source files for the I<LANGUAGE> should be specified.
534
535=back
536
537=begin html
538
539<p>For example, the following might appear for C++:
540<pre><tt>
541[lang=C++]
542suffix=.cpp
543suffix=.cxx
544suffix=.C
545</tt></pre></p>
546
547=end html
548
549=head2 Language Specific Configuration Items
550
551=head3 Section: [general]
552
553=over
554
555=item C<hasPreProcessor=yes|no>
556
557This item specifies whether the language has a pre-processing phase or not. This
558controls whether the B<-E> option works for the language or not.
559
560=item C<output=bc|ll>
561
562This item specifies the kind of output the language's compiler generates. The
563choices are either bytecode (C<bc>) or LLVM assembly (C<ll>).
564
565=back
566
567=head3 Section: [-O0]
568
569=over
570
571=item C<preprocess=>I<commandline>
572
573This item specifies the I<commandline> to use for pre-processing the input.
574
575=over
576
577Valid substitutions for this item are:
578
579=item %in%
580
581The input source file.
582
583=item %out%
584
585The output file.
586
587=item %options%
588
589Any pre-processing specific options (e.g. B<-I>).
590
591=back
592
593=item C<translate=>I<commandline>
594
595This item specifies the I<commandline> to use for translating the source
596language input into the output format given by the C<output> item.
597
598=item C<optimize=>I<commandline>
599
600This item specifies the I<commandline> for optimizing the translator's output.
601
602=back
603
Reid Spencerbe65afb2004-08-06 16:58:48 +0000604=head1 EXIT STATUS
605
606If B<llvmc> succeeds, it will exit with 0. Otherwise, if an error
607occurs, it will exit with a non-zero value and no compilation actions
608will be taken. If one of the compilation tools returns a non-zero
609status, pending actions will be discarded and B<llvmc> will return the
610same result code as the failing compilation tool.
611
612=head1 SEE ALSO
613
614L<gccas|gccas>, L<gccld|gccld>, L<llvm-as|llvm-as>, L<llvm-dis|llvm-dis>,
615L<llc|llc>, L<llvm-link|llvm-link>
616
617=head1 AUTHORS
618
Reid Spenceraf2f9242004-08-07 16:30:14 +0000619Reid Spencer, L<rspencer@x10sys.com>
Reid Spencerbe65afb2004-08-06 16:58:48 +0000620
621=cut