X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=docs%2FCompilerDriver.html;h=253f4719a63269ba4730cbaaddd204d90159c3de;hb=a3355ffb3d30d19d226bbb75707991c60f236e37;hp=927ed766ca6972eac8272386f9ab8b7cec12a349;hpb=a2aa304bc4bbd22988eccd9d9be5c41293428a89;p=oota-llvm.git diff --git a/docs/CompilerDriver.html b/docs/CompilerDriver.html index 927ed766ca6..253f4719a63 100644 --- a/docs/CompilerDriver.html +++ b/docs/CompilerDriver.html @@ -4,15 +4,7 @@ The LLVM Compiler Driver (llvmc) - - + @@ -29,8 +21,14 @@
  • Actions
  • -
  • Details
  • Configuration +
      +
    1. Overview
    2. +
    3. Configuration Files
    4. +
    5. Syntax
    6. +
    7. Substitutions
    8. +
    9. Sample Config File
    10. +
  • Glossary
    @@ -56,9 +54,9 @@
    -

    The llvmc tool is a configurable compiler - driver. As such, it isn't the compiler, optimizer, - or linker itself but it drives (invokes) other software that perform those +

    The llvmc tool is a configurable compiler + driver. As such, it isn't a compiler, optimizer, + or a linker itself but it drives (invokes) other software that perform those tasks. If you are familiar with the GNU Compiler Collection's gcc tool, llvmc is very similar.

    The following introductory sections will help you understand why this tool @@ -68,8 +66,8 @@

    -

    llvmc was invented to make compilation with LLVM based compilers - easier. To accomplish this, llvmc strives to:

    +

    llvmc was invented to make compilation of user programs with + LLVM-based tools easier. To accomplish this, llvmc strives to:

    • Be the single point of access to most of the LLVM tool set.
    • Hide the complexities of the LLVM tools through a single interface.
    • @@ -79,15 +77,14 @@ with LLVM, because it:

      • Makes integration of existing non-LLVM tools simple.
      • -
      • Extends the capabilities of minimal front ends by optimizing their +
      • Extends the capabilities of minimal compiler tools by optimizing their output.
      • Reduces the number of interfaces a compiler writer must know about before a working compiler can be completed (essentially only the VMCore interfaces need to be understood).
      • Supports source language translator invocation via both dynamically loadable shared objects and invocation of an executable.
      • - -

        +
    @@ -96,7 +93,7 @@

    At a high level, llvmc operation is very simple. The basic action taken by llvmc is to simply invoke some tool or set of tools to fill the user's request for compilation. Every execution of llvmctakes the - following sequence of steps:
    + following sequence of steps:

    Collect Command Line Options
    The command line options provide the marching orders to llvmc @@ -107,10 +104,11 @@
    Read Configuration Files
    Based on the options and the suffixes of the filenames presented, a set of configuration files are read to configure the actions llvmc will - take. Configuration files are provided by either LLVM or the front end - compiler tools that B invokes. These files determine what actions - llvmc will take in response to the user's request. See the section - on configuration for more details.
    + take. Configuration files are provided by either LLVM or the + compiler tools that llvmc invokes. These files determine what + actions llvmc will take in response to the user's request. See + the section on configuration for more details. +
    Determine Phases To Execute
    Based on the command line options and configuration files, llvmc determines the compilation phases that @@ -132,18 +130,18 @@
    If any action fails (returns a non-zero result code), llvmc also fails and returns the result code from the failing action. If everything succeeds, llvmc will return a zero result code.
    -

    +

    llvmc's operation must be simple, regular and predictable. Developers need to be able to rely on it to take a consistent approach to compilation. For example, the invocation:

    -
    -   llvmc -O2 x.c y.c z.c -o xyz
    + + llvmc -O2 x.c y.c z.c -o xyz

    must produce exactly the same results as:

    -
    -   llvmc -O2 x.c
    -   llvmc -O2 y.c
    -   llvmc -O2 z.c
    -   llvmc -O2 x.o y.o z.o -o xyz
    +
    
    +    llvmc -O2 x.c -o x.o
    +    llvmc -O2 y.c -o y.o
    +    llvmc -O2 z.c -o z.o
    +    llvmc -O2 x.o y.o z.o -o xyz

    To accomplish this, llvmc uses a very simple goal oriented procedure to do its work. The overall goal is to produce a functioning executable. To accomplish this, llvmc always attempts to execute a @@ -178,7 +176,7 @@ program.

    The following table shows the inputs, outputs, and command line options - applicabe to each phase.

    + applicable to each phase.

    @@ -201,7 +199,7 @@
    Phase
    • LLVM Assembly
    • -
    • LLVM Bytecode
    • +
    • LLVM Bitcode
    • LLVM C++ IR
    @@ -217,27 +215,27 @@
    Optimization
    • LLVM Assembly
    • -
    • LLVM Bytecode
    • +
    • LLVM Bitcode
      -
    • LLVM Bytecode
    • +
    • LLVM Bitcode
    -Ox -
    This group of options affects the amount of optimization +
    This group of options controls the amount of optimization performed.
    Linking
      -
    • LLVM Bytecode
    • +
    • LLVM Bitcode
    • Native Object Code
    • LLVM Library
    • Native Library
      -
    • LLVM Bytecode Executable
    • +
    • LLVM Bitcode Executable
    • Native Executable
    @@ -254,16 +252,11 @@

    An action, with regard to llvmc is a basic operation that it takes in order to fulfill the user's request. Each phase of compilation will invoke zero or more actions in order to accomplish that phase.

    -

    Actions come in two forms:

      +

      Actions come in two forms:

      +
      • Invokable Executables
      • Functions in a shared library
      • -

      - - - - - -
      +
      @@ -272,11 +265,11 @@

      This section of the document describes the configuration files used by llvmc. Configuration information is relatively static for a - given release of LLVM and a front end compiler. However, the details may + given release of LLVM and a compiler tool. However, the details may change from release to release of either. Users are encouraged to simply use - the various options of the B command and ignore the configuration of - the tool. These configuration files are for compiler writers and LLVM - developers. Those wishing to simply use B don't need to understand + the various options of the llvmc command and ignore the configuration + of the tool. These configuration files are for compiler writers and LLVM + developers. Those wishing to simply use llvmc don't need to understand this section but it may be instructive on how the tool works.

      @@ -296,32 +289,32 @@ should be invoked. Users may but are not advised to alter the compiler's

      Because llvmc just invokes other programs, it must deal with the available command line options for those programs regardless of whether they -were written for LLVM or not. Furthermore, not all compilation front ends will -have the same capabilities. Some front ends will simply generate LLVM assembly -code, others will be able to generate fully optimized byte code. In general, +were written for LLVM or not. Furthermore, not all compiler tools will +have the same capabilities. Some compiler tools will simply generate LLVM assembly +code, others will be able to generate fully optimized bitcode. In general, llvmc doesn't make any assumptions about the capabilities or command -line options of a sub-tool. It simply uses the details found in the configuration -files and leaves it to the compiler writer to specify the configuration -correctly.

      - -

      This approach means that new compiler front ends can be up and working very -quickly. As a first cut, a front end can simply compile its source to raw -(unoptimized) bytecode or LLVM assembly and llvmc can be configured -to pick up the slack (translate LLVM assembly to bytecode, optimize the -bytecode, generate native assembly, link, etc.). In fact, the front end need -not use any LLVM libraries, and it could be written in any language (instead of -C++). The configuration data will allow the full range of optimization, -assembly, and linking capabilities that LLVM provides to be added to these kinds -of tools. Enabling the rapid development of front-ends is one of the primary -goals of llvmc.

      - -

      As a compiler front end matures, it may utilize the LLVM libraries and tools -to more efficiently produce optimized bytecode directly in a single compilation +line options of a sub-tool. It simply uses the details found in the +configuration files and leaves it to the compiler writer to specify the +configuration correctly.

      + +

      This approach means that new compiler tools can be up and working very +quickly. As a first cut, a tool can simply compile its source to raw +(unoptimized) bitcode or LLVM assembly and llvmc can be configured +to pick up the slack (translate LLVM assembly to bitcode, optimize the +bitcode, generate native assembly, link, etc.). In fact, the compiler tools +need not use any LLVM libraries, and it could be written in any language +(instead of C++). The configuration data will allow the full range of +optimization, assembly, and linking capabilities that LLVM provides to be added +to these kinds of tools. Enabling the rapid development of front-ends is one +of the primary goals of llvmc.

      + +

      As a compiler tool matures, it may utilize the LLVM libraries and tools +to more efficiently produce optimized bitcode directly in a single compilation and optimization program. In these cases, multiple tools would not be needed and the configuration data for the compiler would change.

      Configuring llvmc to the needs and capabilities of a source language -compiler is relatively straight forward. A compiler writer must provide a +compiler is relatively straight-forward. A compiler writer must provide a definition of what to do for each of the five compilation phases for each of the optimization levels. The specification consists simply of prototypical command lines into which llvmc can substitute command line @@ -334,24 +327,24 @@ optimization.

      -
      Configuration Files
      + + +
      +

      Each configuration file provides the details for a single source language + that is to be compiled. This configuration information tells llvmc + how to invoke the language's pre-processor, translator, optimizer, assembler + and linker. Note that a given source language needn't provide all these tools + as many of them exist in llvm currently.

      +
      + + +
      -

      File Types

      -

      There are two types of configuration files: the master configuration file - and the language specific configuration file. The master configuration file - contains the general configuration of llvmc itself and is supplied - with the tool. It contains information that is source language agnostic. - Language specific configuration files tell llvmc how to invoke the - language's compiler for a variety of different tasks and what other tools - are needed to backfill the compiler's missing features (e.g. - optimization).

      - -

      Directory Search

      llvmc always looks for files of a specific name. It uses the first file with the name its looking for by searching directories in the following order:

        -
      1. Any directory specified by the --config-dir option will be +
      2. Any directory specified by the -config-dir option will be checked first.
      3. If the environment variable LLVM_CONFIG_DIR is set, and it contains the name of a valid directory, that directory will be searched next.
      4. @@ -362,83 +355,403 @@ optimization.

      5. If the LLVM installation directory (typically /usr/local/llvm contains a sub-directory named etc then that directory will be tried last.
      6. +
      7. A standard "system" directory will be searched next. This is typically + /etc/llvm on UNIX™ and C:\WINNT on Microsoft + Windows™.
      8. If the configuration file sought still can't be found, llvmc will print an error message and exit.
      - The first file found in this search will be used. Other files with the same - name will be ignored even if they exist in one of the subsequent search +

      The first file found in this search will be used. Other files with the + same name will be ignored even if they exist in one of the subsequent search locations.

      +
      + + +
      +

      In the directories searched, each configuration file is given a specific + name to foster faster lookup (so llvmc doesn't have to do directory searches). + The name of a given language specific configuration file is simply the same + as the suffix used to identify files containing source in that language. + For example, a configuration file for C++ source might be named + cpp, C, or cxx. For languages that support multiple + file suffixes, multiple (probably identical) files (or symbolic links) will + need to be provided.

      +
      -

      File Names

      -

      In the directories searched, a file named master will be - recognized as the master configuration file for llvmc. Note that - users may override the master file with a copy in their home directory - but they are advised not to. This capability is only useful for compiler - implementers needing to alter the master configuration while developing - their compiler front end. When reading the configuration files, the master - files are always read first.

      -

      Language specific configuration files are given specific names to foster - faster lookup. The name of a given language specific configuration file is - the same as the suffix used to identify files containing source in that - language. For example, a configuration file for C++ source might be named - cpp, C, or cxx.

      - -

      What Gets Read

      -

      The master configuration file is always read. Which language specific - configuration files are read depends on the command line options and the - suffixes of the file names provided on llvmc's command line. Note - that the --x LANGUAGE option alters the language that llvmc - uses for the subsequent files on the command line. Only the language - specific configuration files actually needed to complete llvmc's - task are read. Other language specific files will be ignored.

      + +
      +

      Which configuration files are read depends on the command line options and + the suffixes of the file names provided on llvmc's command line. Note + that the -x LANGUAGE option alters the language that llvmc + uses for the subsequent files on the command line. Only the configuration + files actually needed to complete llvmc's task are read. Other + language specific files will be ignored.

      Syntax
      -

      The syntax of the configuration files is yet to be determined. There are - two viable options remaining:
      +

      The syntax of the configuration files is very simple and somewhat + compatible with Java's property files. Here are the syntax rules:

        -
      • XML DTD Specific To llvmc
      • -
      • Windows .ini style file with numerous sections
      • -

      +
    1. The file encoding is ASCII.
    2. +
    3. The file is line oriented. There should be one configuration definition + per line. Lines are terminated by the newline (0x0A) and/or carriage return + characters (0x0D)
    4. +
    5. A backslash (\) before a newline causes the newline to be + ignored. This is useful for line continuation of long definitions. A + backslash anywhere else is recognized as a backslash.
    6. +
    7. A configuration item consists of a name, an = and a value.
    8. +
    9. A name consists of a sequence of identifiers separated by period.
    10. +
    11. An identifier consists of specific keywords made up of only lower case + and upper case letters (e.g. lang.name).
    12. +
    13. Values come in four flavors: booleans, integers, commands and + strings.
    14. +
    15. Valid "false" boolean values are false False FALSE no No NO + off Off and OFF.
    16. +
    17. Valid "true" boolean values are true True TRUE yes Yes YES + on On and ON.
    18. +
    19. Integers are simply sequences of digits.
    20. +
    21. Commands start with a program name and are followed by a sequence of + words that are passed to that program as command line arguments. Program + arguments that begin and end with the % sign will have their value + substituted. Program names beginning with / are considered to be + absolute. Otherwise the PATH will be applied to find the program to + execute.
    22. +
    23. Strings are composed of multiple sequences of characters from the + character class [-A-Za-z0-9_:%+/\\|,] separated by white + space.
    24. +
    25. White space on a line is folded. Multiple blanks or tabs will be + reduced to a single blank.
    26. +
    27. White space before the configuration item's name is ignored.
    28. +
    29. White space on either side of the = is ignored.
    30. +
    31. White space in a string value is used to separate the individual + components of the string value but otherwise ignored.
    32. +
    33. Comments are introduced by the # character. Everything after a + # and before the end of line is ignored.
    34. +
      - +
      -

      The following description of configuration items is syntax-less and simply - uses a naming hierarchy to describe the configuration items. Whatever - syntax is chosen will need to map the hierarchy to the given syntax.

      +

      The table below provides definitions of the allowed configuration items + that may appear in a configuration file. Every item has a default value and + does not need to appear in the configuration file. Missing items will have the + default value. Each identifier may appear as all lower case, first letter + capitalized or all upper case.

      - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameValue TypeDescription
      Capabilities.hasPreProcessorbooleanThis item specifies whether the language has a - pre-processing phase or not. This controls whether the B<-E> option works - for the language or not.
      Capabilities.outputFormat"bc" or "ll"This item specifies the kind of output the language's - compiler generates. The choices are either bytecode (bc) or LLVM - assembly (ll).
      Capabilities.understandsOptimizationbooleanIndicates whether the compiler for this language understands the - -O options or not
      NameValue TypeDescriptionDefault

      LLVMC ITEMS

      versionstringProvides the version string for the contents of this + configuration file. What is accepted as a legal configuration file + will change over time and this item tells llvmc which version + should be expected.b

      LANG ITEMS

      lang.namestringProvides the common name for a language definition. + For example "C++", "Pascal", "FORTRAN", etc.blank
      lang.opt1stringSpecifies the parameters to give the optimizer when + -O1 is specified on the llvmc command line.-simplifycfg -instcombine -mem2reg
      lang.opt2stringSpecifies the parameters to give the optimizer when + -O2 is specified on the llvmc command line.TBD
      lang.opt3stringSpecifies the parameters to give the optimizer when + -O3 is specified on the llvmc command line.TBD
      lang.opt4stringSpecifies the parameters to give the optimizer when + -O4 is specified on the llvmc command line.TBD
      lang.opt5stringSpecifies the parameters to give the optimizer when + -O5 is specified on the llvmc command line.TBD

      PREPROCESSOR ITEMS

      preprocessor.commandcommandThis provides the command prototype that will be used + to run the preprocessor. This is generally only used with the + -E option.<blank>
      preprocessor.requiredbooleanThis item specifies whether the pre-processing phase + is required by the language. If the value is true, then the + preprocessor.command value must not be blank. With this option, + llvmc will always run the preprocessor as it assumes that the + translation and optimization phases don't know how to pre-process their + input.false

      TRANSLATOR ITEMS

      translator.commandcommandThis provides the command prototype that will be used + to run the translator. Valid substitutions are %in% for the + input file and %out% for the output file.<blank>
      translator.outputbitcode or assemblyThis item specifies the kind of output the language's + translator generates.bitcode
      translator.preprocessesbooleanIndicates that the translator also preprocesses. If + this is true, then llvmc will skip the pre-processing phase + whenever the final phase is not pre-processing.false

      OPTIMIZER ITEMS

      optimizer.commandcommandThis provides the command prototype that will be used + to run the optimizer. Valid substitutions are %in% for the + input file and %out% for the output file.<blank>
      optimizer.outputbitcode or assemblyThis item specifies the kind of output the language's + optimizer generates. Valid values are "assembly" and "bitcode"bitcode
      optimizer.preprocessesbooleanIndicates that the optimizer also preprocesses. If + this is true, then llvmc will skip the pre-processing phase + whenever the final phase is optimization or later.false
      optimizer.translatesbooleanIndicates that the optimizer also translates. If + this is true, then llvmc will skip the translation phase + whenever the final phase is optimization or later.false

      ASSEMBLER ITEMS

      assembler.commandcommandThis provides the command prototype that will be used + to run the assembler. Valid substitutions are %in% for the + input file and %out% for the output file.<blank>
      +
      + + + +
      +

      On any configuration item that ends in command, you must + specify substitution tokens. Substitution tokens begin and end with a percent + sign (%) and are replaced by the corresponding text. Any substitution + token may be given on any command line but some are more useful than + others. In particular each command should have both an %in% + and an %out% substitution. The table below provides definitions of + each of the allowed substitution tokens.

      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      Substitution TokenReplacement Description
      %args%Replaced with all the tool-specific arguments given + to llvmc via the -T set of options. This just allows + you to place these arguments in the correct place on the command line. + If the %args% option does not appear on your command line, + then you are explicitly disallowing the -T option for your + tool. +
      %force%Replaced with the -f option if it was + specified on the llvmc command line. This is intended to tell + the compiler tool to force the overwrite of output files. +
      %in%Replaced with the full path of the input file. You + needn't worry about the cascading of file names. llvmc will + create temporary files and ensure that the output of one phase is the + input to the next phase.
      %opt%Replaced with the optimization options for the + tool. If the tool understands the -O options then that will + be passed. Otherwise, the lang.optN series of configuration + items will specify which arguments are to be given.
      %out%Replaced with the full path of the output file. + Note that this is not necessarily the output file specified with the + -o option on llvmc's command line. It might be a + temporary file that will be passed to a subsequent phase's input. +
      %stats%If your command accepts the -stats option, + use this substitution token. If the user requested -stats + from the llvmc command line then this token will be replaced + with -stats, otherwise it will be ignored. +
      %target%Replaced with the name of the target "machine" for + which code should be generated. The value used here is taken from the + llvmc option -march. +
      %time%If your command accepts the -time-passes + option, use this substitution token. If the user requested + -time-passes from the llvmc command line then this + token will be replaced with -time-passes, otherwise it will + be ignored. +
      + + +
      +

      Since an example is always instructive, here's how the Stacker language + configuration file looks.

      +
      
      +# Stacker Configuration File For llvmc
      +
      +##########################################################
      +# Language definitions
      +##########################################################
      +  lang.name=Stacker 
      +  lang.opt1=-simplifycfg -instcombine -mem2reg
      +  lang.opt2=-simplifycfg -instcombine -mem2reg -load-vn \
      +    -gcse -dse -scalarrepl -sccp 
      +  lang.opt3=-simplifycfg -instcombine -mem2reg -load-vn \
      +    -gcse -dse -scalarrepl -sccp -branch-combine -adce \
      +    -globaldce -inline -licm 
      +  lang.opt4=-simplifycfg -instcombine -mem2reg -load-vn \
      +    -gcse -dse -scalarrepl -sccp -ipconstprop \
      +    -branch-combine -adce -globaldce -inline -licm 
      +  lang.opt5=-simplifycfg -instcombine -mem2reg --load-vn \
      +    -gcse -dse scalarrepl -sccp -ipconstprop \
      +    -branch-combine -adce -globaldce -inline -licm \
      +    -block-placement
      +
      +##########################################################
      +# Pre-processor definitions
      +##########################################################
      +
      +  # Stacker doesn't have a preprocessor but the following
      +  # allows the -E option to be supported
      +  preprocessor.command=cp %in% %out%
      +  preprocessor.required=false
      +
      +##########################################################
      +# Translator definitions
      +##########################################################
      +
      +  # To compile stacker source, we just run the stacker
      +  # compiler with a default stack size of 2048 entries.
      +  translator.command=stkrc -s 2048 %in% -o %out% %time% \
      +    %stats% %force% %args%
      +
      +  # stkrc doesn't preprocess but we set this to true so
      +  # that we don't run the cp command by default.
      +  translator.preprocesses=true
      +
      +  # The translator is required to run.
      +  translator.required=true
      +
      +  # stkrc doesn't handle the -On options
      +  translator.output=bitcode
      +
      +##########################################################
      +# Optimizer definitions
      +##########################################################
      +  
      +  # For optimization, we use the LLVM "opt" program
      +  optimizer.command=opt %in% -o %out% %opt% %time% %stats% \
      +    %force% %args%
      +
      +  optimizer.required = true
      +
      +  # opt doesn't translate
      +  optimizer.translates = no
      +
      +  # opt doesn't preprocess
      +  optimizer.preprocesses=no
      +
      +  # opt produces bitcode
      +  optimizer.output = bc
      +
      +##########################################################
      +# Assembler definitions
      +##########################################################
      +  assembler.command=llc %in% -o %out% %target% %time% %stats%
      +
      +
      + @@ -448,7 +761,7 @@ optimization.

      defined below.

      assembly
      -
      A compilation phase in which LLVM bytecode or +
      A compilation phase in which LLVM bitcode or LLVM assembly code is assembled to a native code format (either target specific aseembly language or the platform's native object file format).
      @@ -461,12 +774,12 @@ optimization.

      Refers to llvmc itself.
      linking
      -
      A compilation phase in which LLVM bytecode files +
      A compilation phase in which LLVM bitcode files and (optionally) native system libraries are combined to form a complete executable program.
      optimization
      -
      A compilation phase in which LLVM bytecode is +
      A compilation phase in which LLVM bitcode is optimized.
      phase
      @@ -491,7 +804,7 @@ optimization.

      translation
      A compilation phase in which source language code is translated into - either LLVM assembly language or LLVM bytecode.
      + either LLVM assembly language or LLVM bitcode.
      @@ -501,7 +814,7 @@ optimization.

      href="http://validator.w3.org/check/referer">Valid HTML 4.01!Reid Spencer
      -The LLVM Compiler Infrastructure
      +The LLVM Compiler Infrastructure
      Last modified: $Date$