diff options
Diffstat (limited to 'docs')
60 files changed, 3942 insertions, 3540 deletions
diff --git a/docs/AliasAnalysis.rst b/docs/AliasAnalysis.rst index 2d4f291..fdaec89 100644 --- a/docs/AliasAnalysis.rst +++ b/docs/AliasAnalysis.rst @@ -230,7 +230,7 @@ any pass dependencies your pass has. Thus you should have something like this: .. code-block:: c++ - void getAnalysisUsage(AnalysisUsage &AU) const { + void getAnalysisUsage(AnalysisUsage &AU) const { AliasAnalysis::getAnalysisUsage(AU); // declare your dependencies here. } diff --git a/docs/BitCodeFormat.rst b/docs/BitCodeFormat.rst index d3995e7..bd26f7b 100644 --- a/docs/BitCodeFormat.rst +++ b/docs/BitCodeFormat.rst @@ -489,6 +489,8 @@ The magic number for LLVM IR files is: When combined with the bitcode magic number and viewed as bytes, this is ``"BC 0xC0DE"``. +.. _Signed VBRs: + Signed VBRs ^^^^^^^^^^^ @@ -507,6 +509,7 @@ As such, signed VBR values of a specific width are emitted as follows: With this encoding, small positive and small negative values can both be emitted efficiently. Signed VBR encoding is used in ``CST_CODE_INTEGER`` and ``CST_CODE_WIDE_INTEGER`` records within ``CONSTANTS_BLOCK`` blocks. +It is also used for phi instruction operands in `MODULE_CODE_VERSION`_ 1. LLVM IR Blocks ^^^^^^^^^^^^^^ @@ -553,13 +556,57 @@ block may contain the following sub-blocks: * `FUNCTION_BLOCK`_ * `METADATA_BLOCK`_ +.. _MODULE_CODE_VERSION: + MODULE_CODE_VERSION Record ^^^^^^^^^^^^^^^^^^^^^^^^^^ ``[VERSION, version#]`` The ``VERSION`` record (code 1) contains a single value indicating the format -version. Only version 0 is supported at this time. +version. Versions 0 and 1 are supported at this time. The difference between +version 0 and 1 is in the encoding of instruction operands in +each `FUNCTION_BLOCK`_. + +In version 0, each value defined by an instruction is assigned an ID +unique to the function. Function-level value IDs are assigned starting from +``NumModuleValues`` since they share the same namespace as module-level +values. The value enumerator resets after each function. When a value is +an operand of an instruction, the value ID is used to represent the operand. +For large functions or large modules, these operand values can be large. + +The encoding in version 1 attempts to avoid large operand values +in common cases. Instead of using the value ID directly, operands are +encoded as relative to the current instruction. Thus, if an operand +is the value defined by the previous instruction, the operand +will be encoded as 1. + +For example, instead of + +.. code-block:: llvm + + #n = load #n-1 + #n+1 = icmp eq #n, #const0 + br #n+1, label #(bb1), label #(bb2) + +version 1 will encode the instructions as + +.. code-block:: llvm + + #n = load #1 + #n+1 = icmp eq #1, (#n+1)-#const0 + br #1, label #(bb1), label #(bb2) + +Note in the example that operands which are constants also use +the relative encoding, while operands like basic block labels +do not use the relative encoding. + +Forward references will result in a negative value. +This can be inefficient, as operands are normally encoded +as unsigned VBRs. However, forward references are rare, except in the +case of phi instructions. For phi instructions, operands are encoded as +`Signed VBRs`_ to deal with forward references. + MODULE_CODE_TRIPLE Record ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/docs/CMake.rst b/docs/CMake.rst index e1761c5..7f0420c 100644 --- a/docs/CMake.rst +++ b/docs/CMake.rst @@ -273,11 +273,6 @@ LLVM-specific variables **LLVM_USE_INTEL_JITEVENTS**:BOOL Enable building support for Intel JIT Events API. Defaults to OFF -**LLVM_INTEL_JITEVENTS_DIR**:PATH - Path to installation of Intel(R) VTune(TM) Amplifier XE 2011, used to locate - the ``jitprofiling`` library. Default = ``%VTUNE_AMPLIFIER_XE_2011_DIR%`` - (Windows) | ``/opt/intel/vtune_amplifier_xe_2011`` (Linux) - Executing the test suite ======================== diff --git a/docs/CodeGenerator.rst b/docs/CodeGenerator.rst index d1d0231..5fab76e 100644 --- a/docs/CodeGenerator.rst +++ b/docs/CodeGenerator.rst @@ -81,7 +81,7 @@ Required components in the code generator The two pieces of the LLVM code generator are the high-level interface to the code generator and the set of reusable components that can be used to build target-specific backends. The two most important interfaces (:raw-html:`<tt>` -`TargetMachine`_ :raw-html:`</tt>` and :raw-html:`<tt>` `TargetData`_ +`TargetMachine`_ :raw-html:`</tt>` and :raw-html:`<tt>` `DataLayout`_ :raw-html:`</tt>`) are the only ones that are required to be defined for a backend to fit into the LLVM system, but the others must be defined if the reusable code generator components are going to be used. @@ -197,7 +197,7 @@ any particular client. These classes are designed to capture the *abstract* properties of the target (such as the instructions and registers it has), and do not incorporate any particular pieces of code generation algorithms. -All of the target description classes (except the :raw-html:`<tt>` `TargetData`_ +All of the target description classes (except the :raw-html:`<tt>` `DataLayout`_ :raw-html:`</tt>` class) are designed to be subclassed by the concrete target implementation, and have virtual methods implemented. To get to these implementations, the :raw-html:`<tt>` `TargetMachine`_ :raw-html:`</tt>` class @@ -214,18 +214,18 @@ the ``get*Info`` methods (``getInstrInfo``, ``getRegisterInfo``, ``getFrameInfo``, etc.). This class is designed to be specialized by a concrete target implementation (e.g., ``X86TargetMachine``) which implements the various virtual methods. The only required target description class is the -:raw-html:`<tt>` `TargetData`_ :raw-html:`</tt>` class, but if the code +:raw-html:`<tt>` `DataLayout`_ :raw-html:`</tt>` class, but if the code generator components are to be used, the other interfaces should be implemented as well. -.. _TargetData: +.. _DataLayout: -The ``TargetData`` class +The ``DataLayout`` class ------------------------ -The ``TargetData`` class is the only required target description class, and it -is the only class that is not extensible (you cannot derived a new class from -it). ``TargetData`` specifies information about how the target lays out memory +The ``DataLayout`` class is the only required target description class, and it +is the only class that is not extensible (you cannot derive a new class from +it). ``DataLayout`` specifies information about how the target lays out memory for structures, the alignment requirements for various data types, the size of pointers in the target, and whether the target is little-endian or big-endian. @@ -248,7 +248,7 @@ operations. Among other things, this class indicates: * the type to use for shift amounts, and * various high-level characteristics, like whether it is profitable to turn - division by a constant into a multiplication sequence + division by a constant into a multiplication sequence. The ``TargetRegisterInfo`` class -------------------------------- @@ -256,10 +256,10 @@ The ``TargetRegisterInfo`` class The ``TargetRegisterInfo`` class is used to describe the register file of the target and any interactions between the registers. -Registers in the code generator are represented in the code generator by -unsigned integers. Physical registers (those that actually exist in the target -description) are unique small numbers, and virtual registers are generally -large. Note that register ``#0`` is reserved as a flag value. +Registers are represented in the code generator by unsigned integers. Physical +registers (those that actually exist in the target description) are unique +small numbers, and virtual registers are generally large. Note that +register ``#0`` is reserved as a flag value. Each register in the processor description has an associated ``TargetRegisterDesc`` entry, which provides a textual name for the register @@ -390,7 +390,7 @@ functions make it easy to build arbitrary machine instructions. Usage of the MachineInstr *MI = BuildMI(X86::MOV32ri, 1, DestReg).addImm(42); // Create the same instr, but insert it at the end of a basic block. - MachineBasicBlock &MBB = ... + MachineBasicBlock &MBB = ... BuildMI(MBB, X86::MOV32ri, 1, DestReg).addImm(42); // Create the same instr, but insert it before a specified iterator point. @@ -404,7 +404,7 @@ functions make it easy to build arbitrary machine instructions. Usage of the MI = BuildMI(X86::SAHF, 0); // Create a self looping branch instruction. - BuildMI(MBB, X86::JNE, 1).addMBB(&MBB); + BuildMI(MBB, X86::JNE, 1).addMBB(&MBB); The key thing to remember with the ``BuildMI`` functions is that you have to specify the number of operands that the machine instruction will take. This @@ -838,8 +838,7 @@ Initial SelectionDAG Construction ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The initial SelectionDAG is na\ :raw-html:`ï`\ vely peephole expanded from -the LLVM input by the ``SelectionDAGLowering`` class in the -``lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp`` file. The intent of this pass +the LLVM input by the ``SelectionDAGBuilder`` class. The intent of this pass is to expose as much low-level, target-specific details to the SelectionDAG as possible. This pass is mostly hard-coded (e.g. an LLVM ``add`` turns into an ``SDNode add`` while a ``getelementptr`` is expanded into the obvious diff --git a/docs/CodingStandards.rst b/docs/CodingStandards.rst index a416a1e..9083530 100644 --- a/docs/CodingStandards.rst +++ b/docs/CodingStandards.rst @@ -79,10 +79,11 @@ tree. The standard header looks like this: // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// - // - // This file contains the declaration of the Instruction class, which is the - // base class for all of the VM instructions. - // + /// + /// \file + /// \brief This file contains the declaration of the Instruction class, which is + /// the base class for all of the VM instructions. + /// //===----------------------------------------------------------------------===// A few things to note about this particular format: The "``-*- C++ -*-``" string @@ -100,10 +101,12 @@ The next section in the file is a concise note that defines the license that the file is released under. This makes it perfectly clear what terms the source code can be distributed under and should not be modified in any way. -The main body of the description does not have to be very long in most cases. -Here it's only two lines. If an algorithm is being implemented or something -tricky is going on, a reference to the paper where it is published should be -included, as well as any notes or *gotchas* in the code to watch out for. +The main body is a ``doxygen`` comment describing the purpose of the file. It +should have a ``\brief`` command that describes the file in one or two +sentences. Any additional information should be separated by a blank line. If +an algorithm is being implemented or something tricky is going on, a reference +to the paper where it is published should be included, as well as any notes or +*gotchas* in the code to watch out for. Class overviews """"""""""""""" @@ -143,6 +146,132 @@ useful to use C style (``/* */``) comments however: To comment out a large block of code, use ``#if 0`` and ``#endif``. These nest properly and are better behaved in general than C style comments. +Doxygen Use in Documentation Comments +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Use the ``\file`` command to turn the standard file header into a file-level +comment. + +Include descriptive ``\brief`` paragraphs for all public interfaces (public +classes, member and non-member functions). Explain API use and purpose in +``\brief`` paragraphs, don't just restate the information that can be inferred +from the API name. Put detailed discussion into separate paragraphs. + +To refer to parameter names inside a paragraph, use the ``\p name`` command. +Don't use the ``\arg name`` command since it starts a new paragraph that +contains documentation for the parameter. + +Wrap non-inline code examples in ``\code ... \endcode``. + +To document a function parameter, start a new paragraph with the +``\param name`` command. If the parameter is used as an out or an in/out +parameter, use the ``\param [out] name`` or ``\param [in,out] name`` command, +respectively. + +To describe function return value, start a new paragraph with the ``\returns`` +command. + +A minimal documentation comment: + +.. code-block:: c++ + + /// \brief Does foo and bar. + void fooBar(bool Baz); + +A documentation comment that uses all Doxygen features in a preferred way: + +.. code-block:: c++ + + /// \brief Does foo and bar. + /// + /// Does not do foo the usual way if \p Baz is true. + /// + /// Typical usage: + /// \code + /// fooBar(false, "quux", Res); + /// \endcode + /// + /// \param Quux kind of foo to do. + /// \param [out] Result filled with bar sequence on foo success. + /// + /// \returns true on success. + bool fooBar(bool Baz, StringRef Quux, std::vector<int> &Result); + +Don't duplicate the documentation comment in the header file and in the +implementation file. Put the documentation comments for public APIs into the +header file. Documentation comments for private APIs can go to the +implementation file. In any case, implementation files can include additional +comments (not necessarily in Doxygen markup) to explain implementation details +as needed. + +Don't duplicate function or class name at the beginning of the comment. +For humans it is obvious which function or class is being documented; +automatic documentation processing tools are smart enough to bind the comment +to the correct declaration. + +Wrong: + +.. code-block:: c++ + + // In Something.h: + + /// Something - An abstraction for some complicated thing. + class Something { + public: + /// fooBar - Does foo and bar. + void fooBar(); + }; + + // In Something.cpp: + + /// fooBar - Does foo and bar. + void Something::fooBar() { ... } + +Correct: + +.. code-block:: c++ + + // In Something.h: + + /// \brief An abstraction for some complicated thing. + class Something { + public: + /// \brief Does foo and bar. + void fooBar(); + }; + + // In Something.cpp: + + // Builds a B-tree in order to do foo. See paper by... + void Something::fooBar() { ... } + +It is not required to use additional Doxygen features, but sometimes it might +be a good idea to do so. + +Consider: + +* adding comments to any narrow namespace containing a collection of + related functions or types; + +* using top-level groups to organize a collection of related functions at + namespace scope where the grouping is smaller than the namespace; + +* using member groups and additional comments attached to member + groups to organize within a class. + +For example: + +.. code-block:: c++ + + class Something { + /// \name Functions that do Foo. + /// @{ + void fooBar(); + void fooBaz(); + /// @} + ... + }; + ``#include`` Style ^^^^^^^^^^^^^^^^^^ @@ -421,9 +550,9 @@ exit from a function, consider this "bad" code: .. code-block:: c++ - Value *DoSomething(Instruction *I) { + Value *doSomething(Instruction *I) { if (!isa<TerminatorInst>(I) && - I->hasOneUse() && SomeOtherThing(I)) { + I->hasOneUse() && doOtherThing(I)) { ... some long code .... } @@ -445,7 +574,7 @@ It is much preferred to format the code like this: .. code-block:: c++ - Value *DoSomething(Instruction *I) { + Value *doSomething(Instruction *I) { // Terminators never need 'something' done to them because ... if (isa<TerminatorInst>(I)) return 0; @@ -456,7 +585,7 @@ It is much preferred to format the code like this: return 0; // This is really just here for example. - if (!SomeOtherThing(I)) + if (!doOtherThing(I)) return 0; ... some long code .... @@ -601,9 +730,8 @@ code to be structured like this: .. code-block:: c++ - /// ListContainsFoo - Return true if the specified list has an element that is - /// a foo. - static bool ListContainsFoo(const std::vector<Bar*> &List) { + /// \returns true if the specified list has an element that is a foo. + static bool containsFoo(const std::vector<Bar*> &List) { for (unsigned i = 0, e = List.size(); i != e; ++i) if (List[i]->isFoo()) return true; @@ -611,7 +739,7 @@ code to be structured like this: } ... - if (ListContainsFoo(BarList)) { + if (containsFoo(BarList)) { ... } @@ -714,7 +842,7 @@ enforced, and hopefully what to do about it. Here is one complete example: .. code-block:: c++ inline Value *getOperand(unsigned i) { - assert(i < Operands.size() && "getOperand() out of range!"); + assert(i < Operands.size() && "getOperand() out of range!"); return Operands[i]; } @@ -734,23 +862,28 @@ Here are more examples: You get the idea. -Please be aware that, when adding assert statements, not all compilers are aware -of the semantics of the assert. In some places, asserts are used to indicate a -piece of code that should not be reached. These are typically of the form: +In the past, asserts were used to indicate a piece of code that should not be +reached. These were typically of the form: .. code-block:: c++ - assert(0 && "Some helpful error message"); + assert(0 && "Invalid radix for integer literal"); -When used in a function that returns a value, they should be followed with a -return statement and a comment indicating that this line is never reached. This -will prevent a compiler which is unable to deduce that the assert statement -never returns from generating a warning. +This has a few issues, the main one being that some compilers might not +understand the assertion, or warn about a missing return in builds where +assertions are compiled out. + +Today, we have something much better: ``llvm_unreachable``: .. code-block:: c++ - assert(0 && "Some helpful error message"); - return 0; + llvm_unreachable("Invalid radix for integer literal"); + +When assertions are enabled, this will print the message if it's ever reached +and then exit the program. When assertions are disabled (i.e. in release +builds), ``llvm_unreachable`` becomes a hint to compilers to skip generating +code for this branch. If the compiler does not support this, it will fall back +to the "abort" implementation. Another issue is that values used only by assertions will produce an "unused value" warning when assertions are disabled. For example, this code will warn: @@ -818,6 +951,52 @@ least one out-of-line virtual method in the class. Without this, the compiler will copy the vtable and RTTI into every ``.o`` file that ``#include``\s the header, bloating ``.o`` file sizes and increasing link times. +Don't use default labels in fully covered switches over enumerations +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +``-Wswitch`` warns if a switch, without a default label, over an enumeration +does not cover every enumeration value. If you write a default label on a fully +covered switch over an enumeration then the ``-Wswitch`` warning won't fire +when new elements are added to that enumeration. To help avoid adding these +kinds of defaults, Clang has the warning ``-Wcovered-switch-default`` which is +off by default but turned on when building LLVM with a version of Clang that +supports the warning. + +A knock-on effect of this stylistic requirement is that when building LLVM with +GCC you may get warnings related to "control may reach end of non-void function" +if you return from each case of a covered switch-over-enum because GCC assumes +that the enum expression may take any representable value, not just those of +individual enumerators. To suppress this warning, use ``llvm_unreachable`` after +the switch. + +Use ``LLVM_DELETED_FUNCTION`` to mark uncallable methods +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Prior to C++11, a common pattern to make a class uncopyable was to declare an +unimplemented copy constructor and copy assignment operator and make them +private. This would give a compiler error for accessing a private method or a +linker error because it wasn't implemented. + +With C++11, we can mark methods that won't be implemented with ``= delete``. +This will trigger a much better error message and tell the compiler that the +method will never be implemented. This enables other checks like +``-Wunused-private-field`` to run correctly on classes that contain these +methods. + +To maintain compatibility with C++03, ``LLVM_DELETED_FUNCTION`` should be used +which will expand to ``= delete`` if the compiler supports it. These methods +should still be declared private. Example of the uncopyable pattern: + +.. code-block:: c++ + + class DontCopy { + private: + DontCopy(const DontCopy&) LLVM_DELETED_FUNCTION; + DontCopy &operator =(const DontCopy&) LLVM_DELETED_FUNCTION; + public: + ... + }; + Don't evaluate ``end()`` every time through a loop ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -1002,21 +1181,21 @@ If a namespace definition is small and *easily* fits on a screen (say, less than namespace llvm { namespace X86 { - /// RelocationType - An enum for the x86 relocation codes. Note that + /// \brief An enum for the x86 relocation codes. Note that /// the terminology here doesn't follow x86 convention - word means /// 32-bit and dword means 64-bit. enum RelocationType { - /// reloc_pcrel_word - PC relative relocation, add the relocated value to + /// \brief PC relative relocation, add the relocated value to /// the value already in memory, after we adjust it for where the PC is. reloc_pcrel_word = 0, - /// reloc_picrel_word - PIC base relative relocation, add the relocated - /// value to the value already in memory, after we adjust it for where the + /// \brief PIC base relative relocation, add the relocated value to + /// the value already in memory, after we adjust it for where the /// PIC base is. reloc_picrel_word = 1, - /// reloc_absolute_word, reloc_absolute_dword - Absolute relocation, just - /// add the relocated value to the value already in memory. + /// \brief Absolute relocation, just add the relocated value to the + /// value already in memory. reloc_absolute_word = 2, reloc_absolute_dword = 3 }; @@ -1035,7 +1214,7 @@ closed. For example: namespace llvm { namespace knowledge { - /// Grokable - This class represents things that Smith can have an intimate + /// This class represents things that Smith can have an intimate /// understanding of and contains the data associated with it. class Grokable { ... @@ -1092,7 +1271,7 @@ good: }; } // end anonymous namespace - static void Helper() { + static void runHelper() { ... } @@ -1112,7 +1291,7 @@ This is bad: bool operator<(const char *RHS) const; }; - void Helper() { + void runHelper() { ... } @@ -1122,7 +1301,7 @@ This is bad: } // end anonymous namespace -This is bad specifically because if you're looking at "``Helper``" in the middle +This is bad specifically because if you're looking at "``runHelper``" in the middle of a large C++ file, that you have no immediate way to tell if it is local to the file. When it is marked static explicitly, this is immediately obvious. Also, there is no reason to enclose the definition of "``operator<``" in the diff --git a/docs/CommandGuide/FileCheck.rst b/docs/CommandGuide/FileCheck.rst index 51a9bf6..1d7a462 100644 --- a/docs/CommandGuide/FileCheck.rst +++ b/docs/CommandGuide/FileCheck.rst @@ -45,6 +45,11 @@ OPTIONS +**--input-file** *filename* + + File to check (defaults to stdin). + + **--strict-whitespace** By default, FileCheck canonicalizes input horizontal whitespace (spaces and @@ -271,8 +276,9 @@ simple example: The first check line matches a regex (**%[a-z]+**) and captures it into the variable "REGISTER". The second line verifies that whatever is in REGISTER occurs later in the file after an "andw". FileCheck variable references are -always contained in **[[ ]]** pairs, are named, and their names can be -name, then it is a definition of the variable, if not, it is a use. +always contained in **[[ ]]** pairs, and their names can be formed with the +regex **[a-zA-Z][a-zA-Z0-9]***. If a colon follows the name, then it is a +definition of the variable; otherwise, it is a use. FileCheck variables can be defined multiple times, and uses always get the latest value. Note that variables are all read at the start of a "CHECK" line diff --git a/docs/CommandGuide/lit.rst b/docs/CommandGuide/lit.rst index 3eb0be9..9e96cd2 100644 --- a/docs/CommandGuide/lit.rst +++ b/docs/CommandGuide/lit.rst @@ -125,6 +125,10 @@ EXECUTION OPTIONS *--error-exitcode* argument for valgrind is used so that valgrind failures will cause the program to exit with a non-zero status. + When this option is enabled, **lit** will also automatically provide a + "valgrind" feature that can be used to conditionally disable (or expect failure + in) certain tests. + **--vg-arg**\ =\ *ARG* @@ -133,6 +137,15 @@ EXECUTION OPTIONS +**--vg-leak** + + When *--vg* is used, enable memory leak checks. When this option is enabled, + **lit** will also automatically provide a "vg_leak" feature that can be + used to conditionally disable (or expect failure in) certain tests. + + + + **--time-tests** Track the wall time individual tests take to execute and includes the results in diff --git a/docs/CompilerWriterInfo.html b/docs/CompilerWriterInfo.html deleted file mode 100644 index 67da783..0000000 --- a/docs/CompilerWriterInfo.html +++ /dev/null @@ -1,267 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" - "http://www.w3.org/TR/html4/strict.dtd"> -<html> -<head> - <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> - <title>Architecture/platform information for compiler writers</title> - <link rel="stylesheet" href="_static/llvm.css" type="text/css"> -</head> - -<body> - -<h1> - Architecture/platform information for compiler writers -</h1> - -<div class="doc_warning"> - <p>Note: This document is a work-in-progress. Additions and clarifications - are welcome.</p> -</div> - -<ol> - <li><a href="#hw">Hardware</a> - <ol> - <li><a href="#arm">ARM</a></li> - <li><a href="#ia64">Itanium</a></li> - <li><a href="#mips">MIPS</a></li> - <li><a href="#ppc">PowerPC</a></li> - <li><a href="#sparc">SPARC</a></li> - <li><a href="#x86">X86</a></li> - <li><a href="#other">Other lists</a></li> - </ol></li> - <li><a href="#abi">Application Binary Interface (ABI)</a> - <ol> - <li><a href="#linux">Linux</a></li> - <li><a href="#osx">OS X</a></li> - </ol></li> - <li><a href="#misc">Miscellaneous resources</a></li> -</ol> - -<div class="doc_author"> - <p>Compiled by <a href="http://misha.brukman.net">Misha Brukman</a></p> -</div> - -<!-- *********************************************************************** --> -<h2><a name="hw">Hardware</a></h2> -<!-- *********************************************************************** --> - -<div> - -<!-- ======================================================================= --> -<h3><a name="arm">ARM</a></h3> - -<div> -<ul> -<li><a href="http://www.arm.com/documentation/">ARM documentation</a> -(<a href="http://www.arm.com/documentation/ARMProcessor_Cores/">Processor -Cores</a>)</li> -<li><a href="http://www.arm.com/products/DevTools/ABI.html">ABI</a></li> -</ul> -</div> - -<!-- ======================================================================= --> -<h3><a name="ia64">Itanium (ia64)</a></h3> - -<div> -<ul> -<li><a -href="http://developer.intel.com/design/itanium2/documentation.htm">Itanium documentation</a> -</li> -</ul> -</div> - -<!-- ======================================================================= --> -<h3><a name="mips">MIPS</a></h3> - -<div> -<ul> -<li><a -href="http://mips.com/content/Documentation/MIPSDocumentation/ProcessorArchitecture/doclibrary">MIPS -Processor Architecture</a></li> -</ul> -</div> - -<!-- ======================================================================= --> -<h3><a name="ppc">PowerPC</a></h3> - -<div> - -<!-- _______________________________________________________________________ --> -<h4>IBM - Official manuals and docs</h4> - -<div> - -<ul> -<li><a -href="http://www-106.ibm.com/developerworks/eserver/articles/archguide.html">PowerPC -Architecture Book</a> -<ul> - <li>Book I: <a - href="http://www-106.ibm.com/developerworks/eserver/pdfs/archpub1.pdf">PowerPC - User Instruction Set Architecture</a></li> - <li>Book II: <a - href="http://www-106.ibm.com/developerworks/eserver/pdfs/archpub2.pdf">PowerPC - Virtual Environment Architecture</a></li> - <li>Book III: <a - href="http://www-106.ibm.com/developerworks/eserver/pdfs/archpub3.pdf">PowerPC - Operating Environment Architecture</a></li> -</ul></li> -<li><a -href="http://www-3.ibm.com/chips/techlib/techlib.nsf/techdocs/852569B20050FF7785256996007558C6">PowerPC -Compiler Writer's Guide</a></li> -<li><A -href="http://www-3.ibm.com/chips/techlib/techlib.nsf/products/PowerPC">PowerPC -Processor Manuals</a></li> -<li><a -href="http://www-106.ibm.com/developerworks/linux/library/l-powarch/">Intro to -PowerPC architecture</a></li> -<li><a href="http://publibn.boulder.ibm.com/doc_link/en_US/a_doc_lib/aixassem/alangref/alangreftfrm.htm">IBM AIX/5L for POWER Assembly reference</a></li> -</ul> - -</div> - -<!-- _______________________________________________________________________ --> -<h4>Other documents, collections, notes</h4> - -<div> - -<ul> -<li><a href="http://penguinppc.org/dev/#library">PowerPC ABI documents</a></li> -<li><a href="http://gcc.gnu.org/ml/gcc-patches/2003-09/msg00997.html">PowerPC64 -alignment of long doubles (from GCC)</a></li> -<li><a href="http://sources.redhat.com/ml/binutils/2002-04/msg00573.html">Long -branch stubs for powerpc64-linux (from binutils)</a></li> -</ul> - -</div> - -</div> - -<!-- ======================================================================= --> -<h3><a name="sparc">SPARC</a></h3> - -<div> - -<ul> -<li><a href="http://www.sparc.org/resource.htm">SPARC resources</a></li> -<li><a href="http://www.sparc.org/standards.html">SPARC standards</a></li> -</ul> - -</div> - -<!-- ======================================================================= --> -<h3><a name="x86">X86</a></h3> - -<div> - -<!-- _______________________________________________________________________ --> -<h4>AMD - Official manuals and docs</h4> - -<div> -<ul> -<li><a -href="http://www.amd.com/us-en/Processors/TechnicalResources/0,,30_182_739,00.html">AMD processor manuals</a></li> -<li><a href="http://www.x86-64.org/documentation">X86-64 ABI</a></li> -</ul> -</div> - -<!-- _______________________________________________________________________ --> -<h4>Intel - Official manuals and docs</h4> - -<div> -<ul> -<li><a -href="http://developer.intel.com/design/pentium4/manuals/index_new.htm">IA-32 -manuals</a></li> -<li><a -href="http://www.intel.com/design/itanium/documentation.htm?iid=ipp_srvr_proc_itanium2+techdocs">Intel -Itanium documentation</a></li> -</ul> -</div> - -<!-- _______________________________________________________________________ --> -<h4>Other x86-specific information</h4> - -<div> -<ul> -<li><a href="http://www.agner.org/assem/calling_conventions.pdf">Calling -conventions for different C++ compilers and operating systems</a></li> -</ul> -</div> - -</div> - -<!-- ======================================================================= --> -<h3><a name="other">Other relevant lists</a></h3> - -<div> - -<ul> -<li><a href="http://gcc.gnu.org/readings.html">GCC reading list</a></li> -</ul> - -</div> - -</div> - -<!-- *********************************************************************** --> -<h2><a name="abi">ABI</a></h2> -<!-- *********************************************************************** --> - -<div> - -<!-- ======================================================================= --> -<h3><a name="linux">Linux</a></h3> - -<div> -<ol> -<li><a href="http://www.linuxbase.org/spec/ELF/ppc64/">PowerPC 64-bit ELF ABI -Supplement</a></li> -</ol> -</div> - -<!-- ======================================================================= --> -<h3><a name="osx">OS X</a></h3> - -<div> -<ol> -<li><a -href="http://developer.apple.com/documentation/Darwin/RuntimeArchitecture-date.html">Mach-O -Runtime Architecture</a></li> -<li><a href="http://www.unsanity.org/archives/000044.php">Notes on Mach-O -ABI</a></li> -</ol> - -</div> - -</div> - -<!-- *********************************************************************** --> -<h2><a name="misc">Miscellaneous resources</a></h2> -<!-- *********************************************************************** --> - -<ul> -<li><a -href="http://www.nondot.org/sabre/os/articles/ExecutableFileFormats/">Executable -File Format library</a></li> -<li><a href="http://gcc.gnu.org/projects/prefetch.html">GCC prefetch project</a> -page has a good survey of the prefetching capabilities of a variety of modern -processors.</li> -</ul> - -<!-- *********************************************************************** --> - -<hr> -<address> - <a href="http://jigsaw.w3.org/css-validator/check/referer"><img - src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS"></a> - <a href="http://validator.w3.org/check/referer"><img - src="http://www.w3.org/Icons/valid-html401-blue" alt="Valid HTML 4.01"></a> - - <a href="http://misha.brukman.net">Misha Brukman</a><br> - <a href="http://llvm.org/">LLVM Compiler Infrastructure</a><br> - Last modified: $Date: 2012-04-19 22:20:34 +0200 (Thu, 19 Apr 2012) $ -</address> - -</body> -</html> diff --git a/docs/CompilerWriterInfo.rst b/docs/CompilerWriterInfo.rst new file mode 100644 index 0000000..e41f5f9 --- /dev/null +++ b/docs/CompilerWriterInfo.rst @@ -0,0 +1,118 @@ +.. _compiler_writer_info: + +======================================================== +Architecture & Platform Information for Compiler Writers +======================================================== + +.. contents:: + :local: + +.. note:: + + This document is a work-in-progress. Additions and clarifications are + welcome. + + Compiled by `Misha Brukman <http://misha.brukman.net>`_. + +Hardware +======== + +ARM +--- + +* `ARM documentation <http://www.arm.com/documentation/>`_ (`Processor Cores <http://www.arm.com/documentation/ARMProcessor_Cores/>`_ Cores) + +* `ABI <http://www.arm.com/products/DevTools/ABI.html>`_ + +Itanium (ia64) +-------------- + +* `Itanium documentation <http://developer.intel.com/design/itanium2/documentation.htm>`_ + +MIPS +---- + +* `MIPS Processor Architecture <http://mips.com/content/Documentation/MIPSDocumentation/ProcessorArchitecture/doclibrary>`_ + +PowerPC +------- + +IBM - Official manuals and docs +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +* `PowerPC Architecture Book <http://www-106.ibm.com/developerworks/eserver/articles/archguide.html>`_ + + * Book I: `PowerPC User Instruction Set Architecture <http://www-106.ibm.com/developerworks/eserver/pdfs/archpub1.pdf>`_ + + * Book II: `PowerPC Virtual Environment Architecture <http://www-106.ibm.com/developerworks/eserver/pdfs/archpub2.pdf>`_ + + * Book III: `PowerPC Operating Environment Architecture <http://www-106.ibm.com/developerworks/eserver/pdfs/archpub3.pdf>`_ + +* `PowerPC Compiler Writer's Guide <http://www-3.ibm.com/chips/techlib/techlib.nsf/techdocs/852569B20050FF7785256996007558C6>`_ + +* `PowerPC Processor Manuals <http://www-3.ibm.com/chips/techlib/techlib.nsf/products/PowerPC>`_ + +* `Intro to PowerPC Architecture <http://www-106.ibm.com/developerworks/linux/library/l-powarch/>`_ + +* `IBM AIX/5L for POWER Assembly Reference <http://publibn.boulder.ibm.com/doc_link/en_US/a_doc_lib/aixassem/alangref/alangreftfrm.htm>`_ + +Other documents, collections, notes +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +* `PowerPC ABI documents <http://penguinppc.org/dev/#library>`_ +* `PowerPC64 alignment of long doubles (from GCC) <http://gcc.gnu.org/ml/gcc-patches/2003-09/msg00997.html>`_ +* `Long branch stubs for powerpc64-linux (from binutils) <http://sources.redhat.com/ml/binutils/2002-04/msg00573.html>`_ + +SPARC +----- + +* `SPARC resources <http://www.sparc.org/resource.htm>`_ +* `SPARC standards <http://www.sparc.org/standards.html>`_ + +X86 +--- + +AMD - Official manuals and docs +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +* `AMD processor manuals <http://www.amd.com/us-en/Processors/TechnicalResources/0,,30_182_739,00.html>`_ +* `X86-64 ABI <http://www.x86-64.org/documentation>`_ + +Intel - Official manuals and docs +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +* `IA-32 manuals <http://developer.intel.com/design/pentium4/manuals/index_new.htm>`_ +* `Intel Itanium documentation <http://www.intel.com/design/itanium/documentation.htm?iid=ipp_srvr_proc_itanium2+techdocs>`_ + +Other x86-specific information +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +* `Calling conventions for different C++ compilers and operating systems <http://www.agner.org/assem/calling_conventions.pdf>`_ + +Other relevant lists +-------------------- + +* `GCC reading list <http://gcc.gnu.org/readings.html>`_ + +ABI +=== + +Linux +----- + +* `PowerPC 64-bit ELF ABI Supplement <http://www.linuxbase.org/spec/ELF/ppc64/>`_ + +OS X +---- + +* `Mach-O Runtime Architecture <http://developer.apple.com/documentation/Darwin/RuntimeArchitecture-date.html>`_ +* `Notes on Mach-O ABI <http://www.unsanity.org/archives/000044.php>`_ + +Miscellaneous Resources +======================= + +* `Executable File Format library <http://www.nondot.org/sabre/os/articles/ExecutableFileFormats/>`_ + +* `GCC prefetch project <http://gcc.gnu.org/projects/prefetch.html>`_ page has a + good survey of the prefetching capabilities of a variety of modern + processors. diff --git a/docs/DebuggingJITedCode.html b/docs/DebuggingJITedCode.html deleted file mode 100644 index 652572c..0000000 --- a/docs/DebuggingJITedCode.html +++ /dev/null @@ -1,184 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" - "http://www.w3.org/TR/html4/strict.dtd"> -<html> -<head> - <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> - <title>Debugging JITed Code With GDB</title> - <link rel="stylesheet" href="_static/llvm.css" type="text/css"> -</head> -<body> - -<h1>Debugging JIT-ed Code With GDB</h1> -<ol> - <li><a href="#background">Background</a></li> - <li><a href="#gdbversion">GDB Version</a></li> - <li><a href="#mcjitdebug">Debugging MCJIT-ed code</a></li> - <ul> - <li><a href="#mcjitdebug_example">Example</a></li> - </ul> -</ol> -<div class="doc_author">Written by Reid Kleckner and Eli Bendersky</div> - -<!--=========================================================================--> -<h2><a name="background">Background</a></h2> -<!--=========================================================================--> -<div> - -<p>Without special runtime support, debugging dynamically generated code with -GDB (as well as most debuggers) can be quite painful. Debuggers generally read -debug information from the object file of the code, but for JITed code, there is -no such file to look for. -</p> - -<p>In order to communicate the necessary debug info to GDB, an interface for -registering JITed code with debuggers has been designed and implemented for -GDB and LLVM MCJIT. At a high level, whenever MCJIT generates new machine code, -it does so in an in-memory object file that contains the debug information in -DWARF format. MCJIT then adds this in-memory object file to a global list of -dynamically generated object files and calls a special function -(<tt>__jit_debug_register_code</tt>) marked noinline that GDB knows about. When -GDB attaches to a process, it puts a breakpoint in this function and loads all -of the object files in the global list. When MCJIT calls the registration -function, GDB catches the breakpoint signal, loads the new object file from -the inferior's memory, and resumes the execution. In this way, GDB can get the -necessary debug information. -</p> -</div> - -<!--=========================================================================--> -<h2><a name="gdbversion">GDB Version</a></h2> -<!--=========================================================================--> - -<p>In order to debug code JIT-ed by LLVM, you need GDB 7.0 or newer, which is -available on most modern distributions of Linux. The version of GDB that Apple -ships with Xcode has been frozen at 6.3 for a while. LLDB may be a better -option for debugging JIT-ed code on Mac OS X. -</p> - - -<!--=========================================================================--> -<h2><a name="mcjitdebug">Debugging MCJIT-ed code</a></h2> -<!--=========================================================================--> -<div> - -<p>The emerging MCJIT component of LLVM allows full debugging of JIT-ed code with -GDB. This is due to MCJIT's ability to use the MC emitter to provide full -DWARF debugging information to GDB.</p> - -<p>Note that lli has to be passed the <tt>-use-mcjit</tt> flag to JIT the code -with MCJIT instead of the old JIT.</p> - -<h3><a name="mcjitdebug_example">Example</a></h3> - -<div> - -<p>Consider the following C code (with line numbers added to make the example -easier to follow):</p> - -<pre class="doc_code"> -1 int compute_factorial(int n) -2 { -3 if (n <= 1) -4 return 1; -5 -6 int f = n; -7 while (--n > 1) -8 f *= n; -9 return f; -10 } -11 -12 -13 int main(int argc, char** argv) -14 { -15 if (argc < 2) -16 return -1; -17 char firstletter = argv[1][0]; -18 int result = compute_factorial(firstletter - '0'); -19 -20 // Returned result is clipped at 255... -21 return result; -22 } -</pre> - -<p>Here is a sample command line session that shows how to build and run this -code via lli inside GDB: -</p> - -<pre class="doc_code"> -$ $BINPATH/clang -cc1 -O0 -g -emit-llvm showdebug.c -$ gdb --quiet --args $BINPATH/lli -use-mcjit showdebug.ll 5 -Reading symbols from $BINPATH/lli...done. -(gdb) b showdebug.c:6 -No source file named showdebug.c. -Make breakpoint pending on future shared library load? (y or [n]) y -Breakpoint 1 (showdebug.c:6) pending. -(gdb) r -Starting program: $BINPATH/lli -use-mcjit showdebug.ll 5 -[Thread debugging using libthread_db enabled] - -Breakpoint 1, compute_factorial (n=5) at showdebug.c:6 -6 int f = n; -(gdb) p n -$1 = 5 -(gdb) p f -$2 = 0 -(gdb) n -7 while (--n > 1) -(gdb) p f -$3 = 5 -(gdb) b showdebug.c:9 -Breakpoint 2 at 0x7ffff7ed404c: file showdebug.c, line 9. -(gdb) c -Continuing. - -Breakpoint 2, compute_factorial (n=1) at showdebug.c:9 -9 return f; -(gdb) p f -$4 = 120 -(gdb) bt -#0 compute_factorial (n=1) at showdebug.c:9 -#1 0x00007ffff7ed40a9 in main (argc=2, argv=0x16677e0) at showdebug.c:18 -#2 0x3500000001652748 in ?? () -#3 0x00000000016677e0 in ?? () -#4 0x0000000000000002 in ?? () -#5 0x0000000000d953b3 in llvm::MCJIT::runFunction (this=0x16151f0, F=0x1603020, ArgValues=...) at /home/ebenders_test/llvm_svn_rw/lib/ExecutionEngine/MCJIT/MCJIT.cpp:161 -#6 0x0000000000dc8872 in llvm::ExecutionEngine::runFunctionAsMain (this=0x16151f0, Fn=0x1603020, argv=..., envp=0x7fffffffe040) - at /home/ebenders_test/llvm_svn_rw/lib/ExecutionEngine/ExecutionEngine.cpp:397 -#7 0x000000000059c583 in main (argc=4, argv=0x7fffffffe018, envp=0x7fffffffe040) at /home/ebenders_test/llvm_svn_rw/tools/lli/lli.cpp:324 -(gdb) finish -Run till exit from #0 compute_factorial (n=1) at showdebug.c:9 -0x00007ffff7ed40a9 in main (argc=2, argv=0x16677e0) at showdebug.c:18 -18 int result = compute_factorial(firstletter - '0'); -Value returned is $5 = 120 -(gdb) p result -$6 = 23406408 -(gdb) n -21 return result; -(gdb) p result -$7 = 120 -(gdb) c -Continuing. - -Program exited with code 0170. -(gdb) - -</pre> - -</div> -</div> - - -<!-- *********************************************************************** --> -<hr> -<address> - <a href="http://jigsaw.w3.org/css-validator/check/referer"><img - src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS"></a> - <a href="http://validator.w3.org/check/referer"><img - src="http://www.w3.org/Icons/valid-html401-blue" alt="Valid HTML 4.01"></a> - <a href="mailto:reid.kleckner@gmail.com">Reid Kleckner</a>, - <a href="mailto:eliben@gmail.com">Eli Bendersky</a><br> - <a href="http://llvm.org/">The LLVM Compiler Infrastructure</a><br> - Last modified: $Date: 2012-05-13 16:36:15 +0200 (Sun, 13 May 2012) $ -</address> -</body> -</html> diff --git a/docs/DebuggingJITedCode.rst b/docs/DebuggingJITedCode.rst new file mode 100644 index 0000000..eeb2f77 --- /dev/null +++ b/docs/DebuggingJITedCode.rst @@ -0,0 +1,147 @@ +.. _debugging-jited-code: + +============================== +Debugging JIT-ed Code With GDB +============================== + +.. sectionauthor:: Reid Kleckner and Eli Bendersky + +Background +========== + +Without special runtime support, debugging dynamically generated code with +GDB (as well as most debuggers) can be quite painful. Debuggers generally +read debug information from the object file of the code, but for JITed +code, there is no such file to look for. + +In order to communicate the necessary debug info to GDB, an interface for +registering JITed code with debuggers has been designed and implemented for +GDB and LLVM MCJIT. At a high level, whenever MCJIT generates new machine code, +it does so in an in-memory object file that contains the debug information in +DWARF format. MCJIT then adds this in-memory object file to a global list of +dynamically generated object files and calls a special function +(``__jit_debug_register_code``) marked noinline that GDB knows about. When +GDB attaches to a process, it puts a breakpoint in this function and loads all +of the object files in the global list. When MCJIT calls the registration +function, GDB catches the breakpoint signal, loads the new object file from +the inferior's memory, and resumes the execution. In this way, GDB can get the +necessary debug information. + +GDB Version +=========== + +In order to debug code JIT-ed by LLVM, you need GDB 7.0 or newer, which is +available on most modern distributions of Linux. The version of GDB that +Apple ships with Xcode has been frozen at 6.3 for a while. LLDB may be a +better option for debugging JIT-ed code on Mac OS X. + + +Debugging MCJIT-ed code +======================= + +The emerging MCJIT component of LLVM allows full debugging of JIT-ed code with +GDB. This is due to MCJIT's ability to use the MC emitter to provide full +DWARF debugging information to GDB. + +Note that lli has to be passed the ``-use-mcjit`` flag to JIT the code with +MCJIT instead of the old JIT. + +Example +------- + +Consider the following C code (with line numbers added to make the example +easier to follow): + +.. + FIXME: + Sphinx has the ability to automatically number these lines by adding + :linenos: on the line immediately following the `.. code-block:: c`, but + it looks like garbage; the line numbers don't even line up with the + lines. Is this a Sphinx bug, or is it a CSS problem? + +.. code-block:: c + + 1 int compute_factorial(int n) + 2 { + 3 if (n <= 1) + 4 return 1; + 5 + 6 int f = n; + 7 while (--n > 1) + 8 f *= n; + 9 return f; + 10 } + 11 + 12 + 13 int main(int argc, char** argv) + 14 { + 15 if (argc < 2) + 16 return -1; + 17 char firstletter = argv[1][0]; + 18 int result = compute_factorial(firstletter - '0'); + 19 + 20 // Returned result is clipped at 255... + 21 return result; + 22 } + +Here is a sample command line session that shows how to build and run this +code via ``lli`` inside GDB: + +.. code-block:: bash + + $ $BINPATH/clang -cc1 -O0 -g -emit-llvm showdebug.c + $ gdb --quiet --args $BINPATH/lli -use-mcjit showdebug.ll 5 + Reading symbols from $BINPATH/lli...done. + (gdb) b showdebug.c:6 + No source file named showdebug.c. + Make breakpoint pending on future shared library load? (y or [n]) y + Breakpoint 1 (showdebug.c:6) pending. + (gdb) r + Starting program: $BINPATH/lli -use-mcjit showdebug.ll 5 + [Thread debugging using libthread_db enabled] + + Breakpoint 1, compute_factorial (n=5) at showdebug.c:6 + 6 int f = n; + (gdb) p n + $1 = 5 + (gdb) p f + $2 = 0 + (gdb) n + 7 while (--n > 1) + (gdb) p f + $3 = 5 + (gdb) b showdebug.c:9 + Breakpoint 2 at 0x7ffff7ed404c: file showdebug.c, line 9. + (gdb) c + Continuing. + + Breakpoint 2, compute_factorial (n=1) at showdebug.c:9 + 9 return f; + (gdb) p f + $4 = 120 + (gdb) bt + #0 compute_factorial (n=1) at showdebug.c:9 + #1 0x00007ffff7ed40a9 in main (argc=2, argv=0x16677e0) at showdebug.c:18 + #2 0x3500000001652748 in ?? () + #3 0x00000000016677e0 in ?? () + #4 0x0000000000000002 in ?? () + #5 0x0000000000d953b3 in llvm::MCJIT::runFunction (this=0x16151f0, F=0x1603020, ArgValues=...) at /home/ebenders_test/llvm_svn_rw/lib/ExecutionEngine/MCJIT/MCJIT.cpp:161 + #6 0x0000000000dc8872 in llvm::ExecutionEngine::runFunctionAsMain (this=0x16151f0, Fn=0x1603020, argv=..., envp=0x7fffffffe040) + at /home/ebenders_test/llvm_svn_rw/lib/ExecutionEngine/ExecutionEngine.cpp:397 + #7 0x000000000059c583 in main (argc=4, argv=0x7fffffffe018, envp=0x7fffffffe040) at /home/ebenders_test/llvm_svn_rw/tools/lli/lli.cpp:324 + (gdb) finish + Run till exit from #0 compute_factorial (n=1) at showdebug.c:9 + 0x00007ffff7ed40a9 in main (argc=2, argv=0x16677e0) at showdebug.c:18 + 18 int result = compute_factorial(firstletter - '0'); + Value returned is $5 = 120 + (gdb) p result + $6 = 23406408 + (gdb) n + 21 return result; + (gdb) p result + $7 = 120 + (gdb) c + Continuing. + + Program exited with code 0170. + (gdb) diff --git a/docs/DeveloperPolicy.rst b/docs/DeveloperPolicy.rst index cda281a..e35e729 100644 --- a/docs/DeveloperPolicy.rst +++ b/docs/DeveloperPolicy.rst @@ -137,6 +137,9 @@ reviewees. If someone is kind enough to review your code, you should return the favor for someone else. Note that anyone is welcome to review and give feedback on a patch, but only people with Subversion write access can approve it. +There is a web based code review tool that can optionally be used +for code reviews. See :doc:`Phabricator`. + Code Owners ----------- @@ -279,7 +282,7 @@ If you have recently been granted commit access, these policies apply: #. You are granted *commit-after-approval* to all parts of LLVM. To get approval, submit a `patch`_ to `llvm-commits <http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits>`_. When approved - you may commit it yourself.</li> + you may commit it yourself. #. You are allowed to commit patches without approval which you think are obvious. This is clearly a subjective decision --- we simply expect you to diff --git a/docs/ExtendingLLVM.html b/docs/ExtendingLLVM.html deleted file mode 100644 index 6782787..0000000 --- a/docs/ExtendingLLVM.html +++ /dev/null @@ -1,379 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" - "http://www.w3.org/TR/html4/strict.dtd"> -<html> -<head> - <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> - <title>Extending LLVM: Adding instructions, intrinsics, types, etc.</title> - <link rel="stylesheet" href="_static/llvm.css" type="text/css"> -</head> - -<body> - -<h1> - Extending LLVM: Adding instructions, intrinsics, types, etc. -</h1> - -<ol> - <li><a href="#introduction">Introduction and Warning</a></li> - <li><a href="#intrinsic">Adding a new intrinsic function</a></li> - <li><a href="#instruction">Adding a new instruction</a></li> - <li><a href="#sdnode">Adding a new SelectionDAG node</a></li> - <li><a href="#type">Adding a new type</a> - <ol> - <li><a href="#fund_type">Adding a new fundamental type</a></li> - <li><a href="#derived_type">Adding a new derived type</a></li> - </ol></li> -</ol> - -<div class="doc_author"> - <p>Written by <a href="http://misha.brukman.net">Misha Brukman</a>, - Brad Jones, Nate Begeman, - and <a href="http://nondot.org/sabre">Chris Lattner</a></p> -</div> - -<!-- *********************************************************************** --> -<h2> - <a name="introduction">Introduction and Warning</a> -</h2> -<!-- *********************************************************************** --> - -<div> - -<p>During the course of using LLVM, you may wish to customize it for your -research project or for experimentation. At this point, you may realize that -you need to add something to LLVM, whether it be a new fundamental type, a new -intrinsic function, or a whole new instruction.</p> - -<p>When you come to this realization, stop and think. Do you really need to -extend LLVM? Is it a new fundamental capability that LLVM does not support at -its current incarnation or can it be synthesized from already pre-existing LLVM -elements? If you are not sure, ask on the <a -href="http://mail.cs.uiuc.edu/mailman/listinfo/llvmdev">LLVM-dev</a> list. The -reason is that extending LLVM will get involved as you need to update all the -different passes that you intend to use with your extension, and there are -<em>many</em> LLVM analyses and transformations, so it may be quite a bit of -work.</p> - -<p>Adding an <a href="#intrinsic">intrinsic function</a> is far easier than -adding an instruction, and is transparent to optimization passes. If your added -functionality can be expressed as a -function call, an intrinsic function is the method of choice for LLVM -extension.</p> - -<p>Before you invest a significant amount of effort into a non-trivial -extension, <span class="doc_warning">ask on the list</span> if what you are -looking to do can be done with already-existing infrastructure, or if maybe -someone else is already working on it. You will save yourself a lot of time and -effort by doing so.</p> - -</div> - -<!-- *********************************************************************** --> -<h2> - <a name="intrinsic">Adding a new intrinsic function</a> -</h2> -<!-- *********************************************************************** --> - -<div> - -<p>Adding a new intrinsic function to LLVM is much easier than adding a new -instruction. Almost all extensions to LLVM should start as an intrinsic -function and then be turned into an instruction if warranted.</p> - -<ol> -<li><tt>llvm/docs/LangRef.html</tt>: - Document the intrinsic. Decide whether it is code generator specific and - what the restrictions are. Talk to other people about it so that you are - sure it's a good idea.</li> - -<li><tt>llvm/include/llvm/Intrinsics*.td</tt>: - Add an entry for your intrinsic. Describe its memory access characteristics - for optimization (this controls whether it will be DCE'd, CSE'd, etc). Note - that any intrinsic using the <tt>llvm_int_ty</tt> type for an argument will - be deemed by <tt>tblgen</tt> as overloaded and the corresponding suffix - will be required on the intrinsic's name.</li> - -<li><tt>llvm/lib/Analysis/ConstantFolding.cpp</tt>: If it is possible to - constant fold your intrinsic, add support to it in the - <tt>canConstantFoldCallTo</tt> and <tt>ConstantFoldCall</tt> functions.</li> - -<li><tt>llvm/test/Regression/*</tt>: Add test cases for your test cases to the - test suite</li> -</ol> - -<p>Once the intrinsic has been added to the system, you must add code generator -support for it. Generally you must do the following steps:</p> - -<dl> - -<dt>Add support to the .td file for the target(s) of your choice in - <tt>lib/Target/*/*.td</tt>.</dt> - -<dd>This is usually a matter of adding a pattern to the .td file that matches - the intrinsic, though it may obviously require adding the instructions you - want to generate as well. There are lots of examples in the PowerPC and X86 - backend to follow.</dd> -</dl> - -</div> - -<!-- *********************************************************************** --> -<h2> - <a name="sdnode">Adding a new SelectionDAG node</a> -</h2> -<!-- *********************************************************************** --> - -<div> - -<p>As with intrinsics, adding a new SelectionDAG node to LLVM is much easier -than adding a new instruction. New nodes are often added to help represent -instructions common to many targets. These nodes often map to an LLVM -instruction (add, sub) or intrinsic (byteswap, population count). In other -cases, new nodes have been added to allow many targets to perform a common task -(converting between floating point and integer representation) or capture more -complicated behavior in a single node (rotate).</p> - -<ol> -<li><tt>include/llvm/CodeGen/ISDOpcodes.h</tt>: - Add an enum value for the new SelectionDAG node.</li> -<li><tt>lib/CodeGen/SelectionDAG/SelectionDAG.cpp</tt>: - Add code to print the node to <tt>getOperationName</tt>. If your new node - can be evaluated at compile time when given constant arguments (such as an - add of a constant with another constant), find the <tt>getNode</tt> method - that takes the appropriate number of arguments, and add a case for your node - to the switch statement that performs constant folding for nodes that take - the same number of arguments as your new node.</li> -<li><tt>lib/CodeGen/SelectionDAG/LegalizeDAG.cpp</tt>: - Add code to <a href="CodeGenerator.html#selectiondag_legalize">legalize, - promote, and expand</a> the node as necessary. At a minimum, you will need - to add a case statement for your node in <tt>LegalizeOp</tt> which calls - LegalizeOp on the node's operands, and returns a new node if any of the - operands changed as a result of being legalized. It is likely that not all - targets supported by the SelectionDAG framework will natively support the - new node. In this case, you must also add code in your node's case - statement in <tt>LegalizeOp</tt> to Expand your node into simpler, legal - operations. The case for <tt>ISD::UREM</tt> for expanding a remainder into - a divide, multiply, and a subtract is a good example.</li> -<li><tt>lib/CodeGen/SelectionDAG/LegalizeDAG.cpp</tt>: - If targets may support the new node being added only at certain sizes, you - will also need to add code to your node's case statement in - <tt>LegalizeOp</tt> to Promote your node's operands to a larger size, and - perform the correct operation. You will also need to add code to - <tt>PromoteOp</tt> to do this as well. For a good example, see - <tt>ISD::BSWAP</tt>, - which promotes its operand to a wider size, performs the byteswap, and then - shifts the correct bytes right to emulate the narrower byteswap in the - wider type.</li> -<li><tt>lib/CodeGen/SelectionDAG/LegalizeDAG.cpp</tt>: - Add a case for your node in <tt>ExpandOp</tt> to teach the legalizer how to - perform the action represented by the new node on a value that has been - split into high and low halves. This case will be used to support your - node with a 64 bit operand on a 32 bit target.</li> -<li><tt>lib/CodeGen/SelectionDAG/DAGCombiner.cpp</tt>: - If your node can be combined with itself, or other existing nodes in a - peephole-like fashion, add a visit function for it, and call that function - from <tt></tt>. There are several good examples for simple combines you - can do; <tt>visitFABS</tt> and <tt>visitSRL</tt> are good starting places. - </li> -<li><tt>lib/Target/PowerPC/PPCISelLowering.cpp</tt>: - Each target has an implementation of the <tt>TargetLowering</tt> class, - usually in its own file (although some targets include it in the same - file as the DAGToDAGISel). The default behavior for a target is to - assume that your new node is legal for all types that are legal for - that target. If this target does not natively support your node, then - tell the target to either Promote it (if it is supported at a larger - type) or Expand it. This will cause the code you wrote in - <tt>LegalizeOp</tt> above to decompose your new node into other legal - nodes for this target.</li> -<li><tt>lib/Target/TargetSelectionDAG.td</tt>: - Most current targets supported by LLVM generate code using the DAGToDAG - method, where SelectionDAG nodes are pattern matched to target-specific - nodes, which represent individual instructions. In order for the targets - to match an instruction to your new node, you must add a def for that node - to the list in this file, with the appropriate type constraints. Look at - <tt>add</tt>, <tt>bswap</tt>, and <tt>fadd</tt> for examples.</li> -<li><tt>lib/Target/PowerPC/PPCInstrInfo.td</tt>: - Each target has a tablegen file that describes the target's instruction - set. For targets that use the DAGToDAG instruction selection framework, - add a pattern for your new node that uses one or more target nodes. - Documentation for this is a bit sparse right now, but there are several - decent examples. See the patterns for <tt>rotl</tt> in - <tt>PPCInstrInfo.td</tt>.</li> -<li>TODO: document complex patterns.</li> -<li><tt>llvm/test/Regression/CodeGen/*</tt>: Add test cases for your new node - to the test suite. <tt>llvm/test/Regression/CodeGen/X86/bswap.ll</tt> is - a good example.</li> -</ol> - -</div> - -<!-- *********************************************************************** --> -<h2> - <a name="instruction">Adding a new instruction</a> -</h2> -<!-- *********************************************************************** --> - -<div> - -<p><span class="doc_warning">WARNING: adding instructions changes the bitcode -format, and it will take some effort to maintain compatibility with -the previous version.</span> Only add an instruction if it is absolutely -necessary.</p> - -<ol> - -<li><tt>llvm/include/llvm/Instruction.def</tt>: - add a number for your instruction and an enum name</li> - -<li><tt>llvm/include/llvm/Instructions.h</tt>: - add a definition for the class that will represent your instruction</li> - -<li><tt>llvm/include/llvm/Support/InstVisitor.h</tt>: - add a prototype for a visitor to your new instruction type</li> - -<li><tt>llvm/lib/AsmParser/Lexer.l</tt>: - add a new token to parse your instruction from assembly text file</li> - -<li><tt>llvm/lib/AsmParser/llvmAsmParser.y</tt>: - add the grammar on how your instruction can be read and what it will - construct as a result</li> - -<li><tt>llvm/lib/Bitcode/Reader/Reader.cpp</tt>: - add a case for your instruction and how it will be parsed from bitcode</li> - -<li><tt>llvm/lib/VMCore/Instruction.cpp</tt>: - add a case for how your instruction will be printed out to assembly</li> - -<li><tt>llvm/lib/VMCore/Instructions.cpp</tt>: - implement the class you defined in - <tt>llvm/include/llvm/Instructions.h</tt></li> - -<li>Test your instruction</li> - -<li><tt>llvm/lib/Target/*</tt>: - Add support for your instruction to code generators, or add a lowering - pass.</li> - -<li><tt>llvm/test/Regression/*</tt>: add your test cases to the test suite.</li> - -</ol> - -<p>Also, you need to implement (or modify) any analyses or passes that you want -to understand this new instruction.</p> - -</div> - - -<!-- *********************************************************************** --> -<h2> - <a name="type">Adding a new type</a> -</h2> -<!-- *********************************************************************** --> - -<div> - -<p><span class="doc_warning">WARNING: adding new types changes the bitcode -format, and will break compatibility with currently-existing LLVM -installations.</span> Only add new types if it is absolutely necessary.</p> - -<!-- ======================================================================= --> -<h3> - <a name="fund_type">Adding a fundamental type</a> -</h3> - -<div> - -<ol> - -<li><tt>llvm/include/llvm/Type.h</tt>: - add enum for the new type; add static <tt>Type*</tt> for this type</li> - -<li><tt>llvm/lib/VMCore/Type.cpp</tt>: - add mapping from <tt>TypeID</tt> => <tt>Type*</tt>; - initialize the static <tt>Type*</tt></li> - -<li><tt>llvm/lib/AsmReader/Lexer.l</tt>: - add ability to parse in the type from text assembly</li> - -<li><tt>llvm/lib/AsmReader/llvmAsmParser.y</tt>: - add a token for that type</li> - -</ol> - -</div> - -<!-- ======================================================================= --> -<h3> - <a name="derived_type">Adding a derived type</a> -</h3> - -<div> - -<ol> -<li><tt>llvm/include/llvm/Type.h</tt>: - add enum for the new type; add a forward declaration of the type - also</li> - -<li><tt>llvm/include/llvm/DerivedTypes.h</tt>: - add new class to represent new class in the hierarchy; add forward - declaration to the TypeMap value type</li> - -<li><tt>llvm/lib/VMCore/Type.cpp</tt>: - add support for derived type to: -<div class="doc_code"> -<pre> -std::string getTypeDescription(const Type &Ty, - std::vector<const Type*> &TypeStack) -bool TypesEqual(const Type *Ty, const Type *Ty2, - std::map<const Type*, const Type*> & EqTypes) -</pre> -</div> - add necessary member functions for type, and factory methods</li> - -<li><tt>llvm/lib/AsmReader/Lexer.l</tt>: - add ability to parse in the type from text assembly</li> - -<li><tt>llvm/lib/BitCode/Writer/Writer.cpp</tt>: - modify <tt>void BitcodeWriter::outputType(const Type *T)</tt> to serialize - your type</li> - -<li><tt>llvm/lib/BitCode/Reader/Reader.cpp</tt>: - modify <tt>const Type *BitcodeReader::ParseType()</tt> to read your data - type</li> - -<li><tt>llvm/lib/VMCore/AsmWriter.cpp</tt>: - modify -<div class="doc_code"> -<pre> -void calcTypeName(const Type *Ty, - std::vector<const Type*> &TypeStack, - std::map<const Type*,std::string> &TypeNames, - std::string & Result) -</pre> -</div> - to output the new derived type -</li> - - -</ol> - -</div> - -</div> - -<!-- *********************************************************************** --> - -<hr> -<address> - <a href="http://jigsaw.w3.org/css-validator/check/referer"><img - src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS"></a> - <a href="http://validator.w3.org/check/referer"><img - src="http://www.w3.org/Icons/valid-html401-blue" alt="Valid HTML 4.01"></a> - - <a href="http://llvm.org/">The LLVM Compiler Infrastructure</a> - <br> - Last modified: $Date: 2012-04-19 22:20:34 +0200 (Thu, 19 Apr 2012) $ -</address> - -</body> -</html> diff --git a/docs/ExtendingLLVM.rst b/docs/ExtendingLLVM.rst new file mode 100644 index 0000000..6df08ee --- /dev/null +++ b/docs/ExtendingLLVM.rst @@ -0,0 +1,306 @@ +.. _extending_llvm: + +============================================================ +Extending LLVM: Adding instructions, intrinsics, types, etc. +============================================================ + +Introduction and Warning +======================== + + +During the course of using LLVM, you may wish to customize it for your research +project or for experimentation. At this point, you may realize that you need to +add something to LLVM, whether it be a new fundamental type, a new intrinsic +function, or a whole new instruction. + +When you come to this realization, stop and think. Do you really need to extend +LLVM? Is it a new fundamental capability that LLVM does not support at its +current incarnation or can it be synthesized from already pre-existing LLVM +elements? If you are not sure, ask on the `LLVM-dev +<http://mail.cs.uiuc.edu/mailman/listinfo/llvmdev>`_ list. The reason is that +extending LLVM will get involved as you need to update all the different passes +that you intend to use with your extension, and there are ``many`` LLVM analyses +and transformations, so it may be quite a bit of work. + +Adding an `intrinsic function`_ is far easier than adding an +instruction, and is transparent to optimization passes. If your added +functionality can be expressed as a function call, an intrinsic function is the +method of choice for LLVM extension. + +Before you invest a significant amount of effort into a non-trivial extension, +**ask on the list** if what you are looking to do can be done with +already-existing infrastructure, or if maybe someone else is already working on +it. You will save yourself a lot of time and effort by doing so. + +.. _intrinsic function: + +Adding a new intrinsic function +=============================== + +Adding a new intrinsic function to LLVM is much easier than adding a new +instruction. Almost all extensions to LLVM should start as an intrinsic +function and then be turned into an instruction if warranted. + +#. ``llvm/docs/LangRef.html``: + + Document the intrinsic. Decide whether it is code generator specific and + what the restrictions are. Talk to other people about it so that you are + sure it's a good idea. + +#. ``llvm/include/llvm/Intrinsics*.td``: + + Add an entry for your intrinsic. Describe its memory access characteristics + for optimization (this controls whether it will be DCE'd, CSE'd, etc). Note + that any intrinsic using the ``llvm_int_ty`` type for an argument will + be deemed by ``tblgen`` as overloaded and the corresponding suffix will + be required on the intrinsic's name. + +#. ``llvm/lib/Analysis/ConstantFolding.cpp``: + + If it is possible to constant fold your intrinsic, add support to it in the + ``canConstantFoldCallTo`` and ``ConstantFoldCall`` functions. + +#. ``llvm/test/Regression/*``: + + Add test cases for your test cases to the test suite + +Once the intrinsic has been added to the system, you must add code generator +support for it. Generally you must do the following steps: + +Add support to the .td file for the target(s) of your choice in +``lib/Target/*/*.td``. + + This is usually a matter of adding a pattern to the .td file that matches the + intrinsic, though it may obviously require adding the instructions you want to + generate as well. There are lots of examples in the PowerPC and X86 backend + to follow. + +Adding a new SelectionDAG node +============================== + +As with intrinsics, adding a new SelectionDAG node to LLVM is much easier than +adding a new instruction. New nodes are often added to help represent +instructions common to many targets. These nodes often map to an LLVM +instruction (add, sub) or intrinsic (byteswap, population count). In other +cases, new nodes have been added to allow many targets to perform a common task +(converting between floating point and integer representation) or capture more +complicated behavior in a single node (rotate). + +#. ``include/llvm/CodeGen/ISDOpcodes.h``: + + Add an enum value for the new SelectionDAG node. + +#. ``lib/CodeGen/SelectionDAG/SelectionDAG.cpp``: + + Add code to print the node to ``getOperationName``. If your new node can be + evaluated at compile time when given constant arguments (such as an add of a + constant with another constant), find the ``getNode`` method that takes the + appropriate number of arguments, and add a case for your node to the switch + statement that performs constant folding for nodes that take the same number + of arguments as your new node. + +#. ``lib/CodeGen/SelectionDAG/LegalizeDAG.cpp``: + + Add code to `legalize, promote, and expand + <CodeGenerator.html#selectiondag_legalize>`_ the node as necessary. At a + minimum, you will need to add a case statement for your node in + ``LegalizeOp`` which calls LegalizeOp on the node's operands, and returns a + new node if any of the operands changed as a result of being legalized. It + is likely that not all targets supported by the SelectionDAG framework will + natively support the new node. In this case, you must also add code in your + node's case statement in ``LegalizeOp`` to Expand your node into simpler, + legal operations. The case for ``ISD::UREM`` for expanding a remainder into + a divide, multiply, and a subtract is a good example. + +#. ``lib/CodeGen/SelectionDAG/LegalizeDAG.cpp``: + + If targets may support the new node being added only at certain sizes, you + will also need to add code to your node's case statement in ``LegalizeOp`` + to Promote your node's operands to a larger size, and perform the correct + operation. You will also need to add code to ``PromoteOp`` to do this as + well. For a good example, see ``ISD::BSWAP``, which promotes its operand to + a wider size, performs the byteswap, and then shifts the correct bytes right + to emulate the narrower byteswap in the wider type. + +#. ``lib/CodeGen/SelectionDAG/LegalizeDAG.cpp``: + + Add a case for your node in ``ExpandOp`` to teach the legalizer how to + perform the action represented by the new node on a value that has been split + into high and low halves. This case will be used to support your node with a + 64 bit operand on a 32 bit target. + +#. ``lib/CodeGen/SelectionDAG/DAGCombiner.cpp``: + + If your node can be combined with itself, or other existing nodes in a + peephole-like fashion, add a visit function for it, and call that function + from. There are several good examples for simple combines you can do; + ``visitFABS`` and ``visitSRL`` are good starting places. + +#. ``lib/Target/PowerPC/PPCISelLowering.cpp``: + + Each target has an implementation of the ``TargetLowering`` class, usually in + its own file (although some targets include it in the same file as the + DAGToDAGISel). The default behavior for a target is to assume that your new + node is legal for all types that are legal for that target. If this target + does not natively support your node, then tell the target to either Promote + it (if it is supported at a larger type) or Expand it. This will cause the + code you wrote in ``LegalizeOp`` above to decompose your new node into other + legal nodes for this target. + +#. ``lib/Target/TargetSelectionDAG.td``: + + Most current targets supported by LLVM generate code using the DAGToDAG + method, where SelectionDAG nodes are pattern matched to target-specific + nodes, which represent individual instructions. In order for the targets to + match an instruction to your new node, you must add a def for that node to + the list in this file, with the appropriate type constraints. Look at + ``add``, ``bswap``, and ``fadd`` for examples. + +#. ``lib/Target/PowerPC/PPCInstrInfo.td``: + + Each target has a tablegen file that describes the target's instruction set. + For targets that use the DAGToDAG instruction selection framework, add a + pattern for your new node that uses one or more target nodes. Documentation + for this is a bit sparse right now, but there are several decent examples. + See the patterns for ``rotl`` in ``PPCInstrInfo.td``. + +#. TODO: document complex patterns. + +#. ``llvm/test/Regression/CodeGen/*``: + + Add test cases for your new node to the test suite. + ``llvm/test/Regression/CodeGen/X86/bswap.ll`` is a good example. + +Adding a new instruction +======================== + +.. warning:: + + Adding instructions changes the bitcode format, and it will take some effort + to maintain compatibility with the previous version. Only add an instruction + if it is absolutely necessary. + +#. ``llvm/include/llvm/Instruction.def``: + + add a number for your instruction and an enum name + +#. ``llvm/include/llvm/Instructions.h``: + + add a definition for the class that will represent your instruction + +#. ``llvm/include/llvm/Support/InstVisitor.h``: + + add a prototype for a visitor to your new instruction type + +#. ``llvm/lib/AsmParser/Lexer.l``: + + add a new token to parse your instruction from assembly text file + +#. ``llvm/lib/AsmParser/llvmAsmParser.y``: + + add the grammar on how your instruction can be read and what it will + construct as a result + +#. ``llvm/lib/Bitcode/Reader/Reader.cpp``: + + add a case for your instruction and how it will be parsed from bitcode + +#. ``llvm/lib/VMCore/Instruction.cpp``: + + add a case for how your instruction will be printed out to assembly + +#. ``llvm/lib/VMCore/Instructions.cpp``: + + implement the class you defined in ``llvm/include/llvm/Instructions.h`` + +#. Test your instruction + +#. ``llvm/lib/Target/*``: + + add support for your instruction to code generators, or add a lowering pass. + +#. ``llvm/test/Regression/*``: + + add your test cases to the test suite. + +Also, you need to implement (or modify) any analyses or passes that you want to +understand this new instruction. + +Adding a new type +================= + +.. warning:: + + Adding new types changes the bitcode format, and will break compatibility with + currently-existing LLVM installations. Only add new types if it is absolutely + necessary. + +Adding a fundamental type +------------------------- + +#. ``llvm/include/llvm/Type.h``: + + add enum for the new type; add static ``Type*`` for this type + +#. ``llvm/lib/VMCore/Type.cpp``: + + add mapping from ``TypeID`` => ``Type*``; initialize the static ``Type*`` + +#. ``llvm/lib/AsmReader/Lexer.l``: + + add ability to parse in the type from text assembly + +#. ``llvm/lib/AsmReader/llvmAsmParser.y``: + + add a token for that type + +Adding a derived type +--------------------- + +#. ``llvm/include/llvm/Type.h``: + + add enum for the new type; add a forward declaration of the type also + +#. ``llvm/include/llvm/DerivedTypes.h``: + + add new class to represent new class in the hierarchy; add forward + declaration to the TypeMap value type + +#. ``llvm/lib/VMCore/Type.cpp``: + + add support for derived type to: + + .. code-block:: c++ + + std::string getTypeDescription(const Type &Ty, + std::vector<const Type*> &TypeStack) + bool TypesEqual(const Type *Ty, const Type *Ty2, + std::map<const Type*, const Type*> &EqTypes) + + add necessary member functions for type, and factory methods + +#. ``llvm/lib/AsmReader/Lexer.l``: + + add ability to parse in the type from text assembly + +#. ``llvm/lib/BitCode/Writer/Writer.cpp``: + + modify ``void BitcodeWriter::outputType(const Type *T)`` to serialize your + type + +#. ``llvm/lib/BitCode/Reader/Reader.cpp``: + + modify ``const Type *BitcodeReader::ParseType()`` to read your data type + +#. ``llvm/lib/VMCore/AsmWriter.cpp``: + + modify + + .. code-block:: c++ + + void calcTypeName(const Type *Ty, + std::vector<const Type*> &TypeStack, + std::map<const Type*,std::string> &TypeNames, + std::string &Result) + + to output the new derived type diff --git a/docs/GarbageCollection.html b/docs/GarbageCollection.html index 0b8f588..e124851 100644 --- a/docs/GarbageCollection.html +++ b/docs/GarbageCollection.html @@ -1253,7 +1253,7 @@ methods. Here's a realistic example:</p> >#include "llvm/CodeGen/AsmPrinter.h" #include "llvm/Function.h" #include "llvm/Target/TargetMachine.h" -#include "llvm/Target/TargetData.h" +#include "llvm/DataLayout.h" #include "llvm/Target/TargetAsmInfo.h" void MyGCPrinter::beginAssembly(std::ostream &OS, AsmPrinter &AP, @@ -1266,7 +1266,7 @@ void MyGCPrinter::finishAssembly(std::ostream &OS, AsmPrinter &AP, // Set up for emitting addresses. const char *AddressDirective; int AddressAlignLog; - if (AP.TM.getTargetData()->getPointerSize() == sizeof(int32_t)) { + if (AP.TM.getDataLayout()->getPointerSize() == sizeof(int32_t)) { AddressDirective = TAI.getData32bitsDirective(); AddressAlignLog = 2; } else { @@ -1382,7 +1382,7 @@ Fergus Henderson. International Symposium on Memory Management 2002.</p> <a href="mailto:sabre@nondot.org">Chris Lattner</a><br> <a href="http://llvm.org/">LLVM Compiler Infrastructure</a><br> - Last modified: $Date: 2012-05-03 17:25:19 +0200 (Thu, 03 May 2012) $ + Last modified: $Date: 2012-10-08 18:39:34 +0200 (Mon, 08 Oct 2012) $ </address> </body> diff --git a/docs/GettingStarted.html b/docs/GettingStarted.html deleted file mode 100644 index 61335af..0000000 --- a/docs/GettingStarted.html +++ /dev/null @@ -1,1760 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" - "http://www.w3.org/TR/html4/strict.dtd"> -<html> -<head> - <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> - <title>Getting Started with LLVM System</title> - <link rel="stylesheet" href="_static/llvm.css" type="text/css"> -</head> -<body> - -<h1> - Getting Started with the LLVM System -</h1> - -<ul> - <li><a href="#overview">Overview</a> - <li><a href="#quickstart">Getting Started Quickly (A Summary)</a> - <li><a href="#requirements">Requirements</a> - <ol> - <li><a href="#hardware">Hardware</a></li> - <li><a href="#software">Software</a></li> - <li><a href="#brokengcc">Broken versions of GCC and other tools</a></li> - </ol></li> - - <li><a href="#starting">Getting Started with LLVM</a> - <ol> - <li><a href="#terminology">Terminology and Notation</a></li> - <li><a href="#environment">Setting Up Your Environment</a></li> - <li><a href="#unpack">Unpacking the LLVM Archives</a></li> - <li><a href="#checkout">Checkout LLVM from Subversion</a></li> - <li><a href="#git_mirror">LLVM GIT mirror</a></li> - <li><a href="#config">Local LLVM Configuration</a></li> - <li><a href="#compile">Compiling the LLVM Suite Source Code</a></li> - <li><a href="#cross-compile">Cross-Compiling LLVM</a></li> - <li><a href="#objfiles">The Location of LLVM Object Files</a></li> - <li><a href="#optionalconfig">Optional Configuration Items</a></li> - </ol></li> - - <li><a href="#layout">Program layout</a> - <ol> - <li><a href="#examples"><tt>llvm/examples</tt></a></li> - <li><a href="#include"><tt>llvm/include</tt></a></li> - <li><a href="#lib"><tt>llvm/lib</tt></a></li> - <li><a href="#projects"><tt>llvm/projects</tt></a></li> - <li><a href="#runtime"><tt>llvm/runtime</tt></a></li> - <li><a href="#test"><tt>llvm/test</tt></a></li> - <li><a href="#test-suite"><tt>test-suite</tt></a></li> - <li><a href="#tools"><tt>llvm/tools</tt></a></li> - <li><a href="#utils"><tt>llvm/utils</tt></a></li> - </ol></li> - - <li><a href="#tutorial">An Example Using the LLVM Tool Chain</a> - <ol> - <li><a href="#tutorial4">Example with Clang</a></li> - </ol> - <li><a href="#problems">Common Problems</a> - <li><a href="#links">Links</a> -</ul> - -<div class="doc_author"> - <p>Written by: - <a href="mailto:criswell@uiuc.edu">John Criswell</a>, - <a href="mailto:sabre@nondot.org">Chris Lattner</a>, - <a href="http://misha.brukman.net/">Misha Brukman</a>, - <a href="http://www.cs.uiuc.edu/~vadve">Vikram Adve</a>, and - <a href="mailto:gshi1@uiuc.edu">Guochun Shi</a>. - </p> -</div> - - -<!-- *********************************************************************** --> -<h2> - <a name="overview">Overview</a> -</h2> -<!-- *********************************************************************** --> - -<div> - -<p>Welcome to LLVM! In order to get started, you first need to know some -basic information.</p> - -<p>First, LLVM comes in three pieces. The first piece is the LLVM -suite. This contains all of the tools, libraries, and header files -needed to use LLVM. It contains an assembler, disassembler, bitcode -analyzer and bitcode optimizer. It also contains basic regression tests that -can be used to test the LLVM tools and the Clang front end.</p> - -<p>The second piece is the <a href="http://clang.llvm.org/">Clang</a> front end. -This component compiles C, C++, Objective C, and Objective C++ code into LLVM -bitcode. Once compiled into LLVM bitcode, a program can be manipulated with the -LLVM tools from the LLVM suite. -</p> - -<p> -There is a third, optional piece called Test Suite. It is a suite of programs -with a testing harness that can be used to further test LLVM's functionality -and performance. -</p> - -</div> - -<!-- *********************************************************************** --> -<h2> - <a name="quickstart">Getting Started Quickly (A Summary)</a> -</h2> -<!-- *********************************************************************** --> - -<div> - -<p>The LLVM Getting Started documentation may be out of date. So, the Clang -<a href="http://clang.llvm.org/get_started.html">Getting Started</a> page might -also be a good place to start.</p> - -<p>Here's the short story for getting up and running quickly with LLVM:</p> - -<ol> - <li>Read the documentation.</li> - <li>Read the documentation.</li> - <li>Remember that you were warned twice about reading the documentation.</li> - - <li>Checkout LLVM: - <ul> - <li><tt>cd <i>where-you-want-llvm-to-live</i></tt> - <li><tt>svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm</tt></li> - </ul> - </li> - - <li>Checkout Clang: - <ul> - <li><tt>cd <i>where-you-want-llvm-to-live</i></tt> - <li><tt>cd llvm/tools</tt> - <li><tt>svn co http://llvm.org/svn/llvm-project/cfe/trunk clang</tt></li> - </ul> - </li> - - <li>Checkout Compiler-RT: - <ul> - <li><tt>cd <i>where-you-want-llvm-to-live</i></tt> - <li><tt>cd llvm/projects</tt> - <li><tt>svn co http://llvm.org/svn/llvm-project/compiler-rt/trunk - compiler-rt</tt></li> - </ul> - </li> - - <li>Get the Test Suite Source Code <b>[Optional]</b> - <ul> - <li><tt>cd <i>where-you-want-llvm-to-live</i></tt> - <li><tt>cd llvm/projects</tt> - <li><tt>svn co http://llvm.org/svn/llvm-project/test-suite/trunk test-suite</tt></li> - </ul> - </li> - - <li>Configure and build LLVM and Clang: - <ul> - <li><tt>cd <i>where-you-want-to-build-llvm</i></tt></li> - <li><tt>mkdir build</tt> (for building without polluting the source dir)</li> - <li><tt>cd build</tt></li> - <li><tt>../llvm/configure [options]</tt> - <br>Some common options: - - <ul> - <li><tt>--prefix=<i>directory</i></tt> - - Specify for <i>directory</i> the full pathname of where you - want the LLVM tools and libraries to be installed (default - <tt>/usr/local</tt>).</li> - </ul> - - <ul> - <li><tt>--enable-optimized</tt> - - Compile with optimizations enabled (default is NO).</li> - </ul> - - <ul> - <li><tt>--enable-assertions</tt> - - Compile with assertion checks enabled (default is YES).</li> - </ul> - </li> - <li><tt>make [-j]</tt> - The -j specifies the number of jobs (commands) to - run simultaneously. This builds both LLVM and Clang for Debug+Asserts mode. - The --enabled-optimized configure option is used to specify a Release build.</li> - <li><tt>make check-all</tt> - - This run the regression tests to ensure everything is in working order.</li> - <li><tt>make update</tt> - - This command is used to update all the svn repositories at once, rather then - having to <tt>cd</tt> into the individual repositories and running - <tt>svn update</tt>.</li> - <li>It is also possible to use CMake instead of the makefiles. With CMake - it is also possible to generate project files for several IDEs: Eclipse - CDT4, CodeBlocks, Qt-Creator (use the CodeBlocks generator), KDevelop3.</li> - <li>If you get an "internal compiler error (ICE)" or test failures, see - <a href="#brokengcc">below</a>.</li> - - </ul> - </li> - -</ol> - -<p>Consult the <a href="#starting">Getting Started with LLVM</a> section for -detailed information on configuring and compiling LLVM. See <a -href="#environment">Setting Up Your Environment</a> for tips that simplify -working with the Clang front end and LLVM tools. Go to <a href="#layout">Program -Layout</a> to learn about the layout of the source code tree.</p> - -</div> - -<!-- *********************************************************************** --> -<h2> - <a name="requirements">Requirements</a> -</h2> -<!-- *********************************************************************** --> - -<div> - -<p>Before you begin to use the LLVM system, review the requirements given below. -This may save you some trouble by knowing ahead of time what hardware and -software you will need.</p> - -<!-- ======================================================================= --> -<h3> - <a name="hardware">Hardware</a> -</h3> - -<div> - -<p>LLVM is known to work on the following platforms:</p> - -<table cellpadding="3" summary="Known LLVM platforms"> -<tr> - <th>OS</th> - <th>Arch</th> - <th>Compilers</th> -</tr> -<tr> - <td>AuroraUX</td> - <td>x86<sup><a href="#pf_1">1</a></sup></td> - <td>GCC</td> -</tr> -<tr> - <td>Linux</td> - <td>x86<sup><a href="#pf_1">1</a></sup></td> - <td>GCC</td> -</tr> -<tr> - <td>Linux</td> - <td>amd64</td> - <td>GCC</td> -</tr> -<tr> - <td>Solaris</td> - <td>V9 (Ultrasparc)</td> - <td>GCC</td> -</tr> -<tr> - <td>FreeBSD</td> - <td>x86<sup><a href="#pf_1">1</a></sup></td> - <td>GCC</td> -</tr> -<tr> - <td>FreeBSD</td> - <td>amd64</td> - <td>GCC</td> -</tr> -<tr> - <td>MacOS X<sup><a href="#pf_2">2</a></sup></td> - <td>PowerPC</td> - <td>GCC</td> -</tr> -<tr> - <td>MacOS X<sup><a href="#pf_2">2</a>,<a href="#pf_9">9</a></sup></td> - <td>x86</td> - <td>GCC</td> -</tr> -<tr> - <td>Cygwin/Win32</td> - <td>x86<sup><a href="#pf_1">1</a>,<a href="#pf_8">8</a>, - <a href="#pf_11">11</a></sup></td> - <td>GCC 3.4.X, binutils 2.20</td> -</tr> -<tr> - <td>MinGW/Win32</td> - <td>x86<sup><a href="#pf_1">1</a>,<a href="#pf_6">6</a>, - <a href="#pf_8">8</a>, <a href="#pf_10">10</a>, - <a href="#pf_11">11</a></sup></td> - <td>GCC 3.4.X, binutils 2.20</td> -</tr> -</table> - -<p>LLVM has partial support for the following platforms:</p> - -<table summary="LLVM partial platform support"> -<tr> - <th>OS</th> - <th>Arch</th> - <th>Compilers</th> -</tr> -<tr> - <td>Windows</td> - <td>x86<sup><a href="#pf_1">1</a></sup></td> - <td>Visual Studio 2008 or higher<sup><a href="#pf_4">4</a>,<a href="#pf_5">5</a></sup></td> -<tr> - <td>AIX<sup><a href="#pf_3">3</a>,<a href="#pf_4">4</a></sup></td> - <td>PowerPC</td> - <td>GCC</td> -</tr> -<tr> - <td>Linux<sup><a href="#pf_3">3</a>,<a href="#pf_5">5</a></sup></td> - <td>PowerPC</td> - <td>GCC</td> -</tr> - -<tr> - <td>Linux<sup><a href="#pf_7">7</a></sup></td> - <td>Alpha</td> - <td>GCC</td> -</tr> -<tr> - <td>Linux<sup><a href="#pf_7">7</a></sup></td> - <td>Itanium (IA-64)</td> - <td>GCC</td> -</tr> -<tr> - <td>HP-UX<sup><a href="#pf_7">7</a></sup></td> - <td>Itanium (IA-64)</td> - <td>HP aCC</td> -</tr> -<tr> - <td>Windows x64</td> - <td>x86-64</td> - <td>mingw-w64's GCC-4.5.x<sup><a href="#pf_12">12</a></sup></td> -</tr> -</table> - -<p><b>Notes:</b></p> - -<div class="doc_notes"> -<ol> -<li><a name="pf_1">Code generation supported for Pentium processors and -up</a></li> -<li><a name="pf_2">Code generation supported for 32-bit ABI only</a></li> -<li><a name="pf_3">No native code generation</a></li> -<li><a name="pf_4">Build is not complete: one or more tools do not link or function</a></li> -<li><a name="pf_5">The GCC-based C/C++ frontend does not build</a></li> -<li><a name="pf_6">The port is done using the MSYS shell.</a></li> -<li><a name="pf_7">Native code generation exists but is not complete.</a></li> -<li><a name="pf_8">Binutils 2.20 or later is required to build the assembler - generated by LLVM properly.</a></li> -<li><a name="pf_9">Xcode 2.5 and gcc 4.0.1</a> (Apple Build 5370) will trip - internal LLVM assert messages when compiled for Release at optimization - levels greater than 0 (i.e., <i>"-O1"</i> and higher). - Add <i>OPTIMIZE_OPTION="-O0"</i> to the build command line - if compiling for LLVM Release or bootstrapping the LLVM toolchain.</li> -<li><a name="pf_10">For MSYS/MinGW on Windows, be sure to install the MSYS - version of the perl package, and be sure it appears in your path - before any Windows-based versions such as Strawberry Perl and - ActivePerl, as these have Windows-specifics that will cause the - build to fail.</a></li> -<li><a name="pf_11">To use LLVM modules on Win32-based system, - you may configure LLVM with <i>"--enable-shared"</i>.</a></li> -<li><a name="pf_12">To compile SPU backend, you need to add - <tt>"LDFLAGS=-Wl,--stack,16777216"</tt> to configure.</a></li> -</ol> -</div> - -<p>Note that you will need about 1-3 GB of space for a full LLVM build in Debug -mode, depending on the system (it is so large because of all the debugging -information and the fact that the libraries are statically linked into multiple -tools). If you do not need many of the tools and you are space-conscious, you -can pass <tt>ONLY_TOOLS="tools you need"</tt> to make. The Release build -requires considerably less space.</p> - -<p>The LLVM suite <i>may</i> compile on other platforms, but it is not -guaranteed to do so. If compilation is successful, the LLVM utilities should be -able to assemble, disassemble, analyze, and optimize LLVM bitcode. Code -generation should work as well, although the generated native code may not work -on your platform.</p> - -</div> - -<!-- ======================================================================= --> -<h3> - <a name="software">Software</a> -</h3> -<div> - <p>Compiling LLVM requires that you have several software packages - installed. The table below lists those required packages. The Package column - is the usual name for the software package that LLVM depends on. The Version - column provides "known to work" versions of the package. The Notes column - describes how LLVM uses the package and provides other details.</p> - <table summary="Packages required to compile LLVM"> - <tr><th>Package</th><th>Version</th><th>Notes</th></tr> - - <tr> - <td><a href="http://savannah.gnu.org/projects/make">GNU Make</a></td> - <td>3.79, 3.79.1</td> - <td>Makefile/build processor</td> - </tr> - - <tr> - <td><a href="http://gcc.gnu.org/">GCC</a></td> - <td>3.4.2</td> - <td>C/C++ compiler<sup><a href="#sf1">1</a></sup></td> - </tr> - - <tr> - <td><a href="http://www.gnu.org/software/texinfo/">TeXinfo</a></td> - <td>4.5</td> - <td>For building the CFE</td> - </tr> - - <tr> - <td><a href="http://subversion.tigris.org/project_packages.html">SVN</a></td> - <td>≥1.3</td> - <td>Subversion access to LLVM<sup><a href="#sf2">2</a></sup></td> - </tr> - - <!-- FIXME: - Do we support dg? - Are DejaGnu and expect obsolete? - Shall we mention Python? --> - - <tr> - <td><a href="http://savannah.gnu.org/projects/dejagnu">DejaGnu</a></td> - <td>1.4.2</td> - <td>Automated test suite<sup><a href="#sf3">3</a></sup></td> - </tr> - - <tr> - <td><a href="http://www.tcl.tk/software/tcltk/">tcl</a></td> - <td>8.3, 8.4</td> - <td>Automated test suite<sup><a href="#sf3">3</a></sup></td> - </tr> - - <tr> - <td><a href="http://expect.nist.gov/">expect</a></td> - <td>5.38.0</td> - <td>Automated test suite<sup><a href="#sf3">3</a></sup></td> - </tr> - - <tr> - <td><a href="http://www.perl.com/download.csp">perl</a></td> - <td>≥5.6.0</td> - <td>Utilities</td> - </tr> - - <tr> - <td><a href="http://savannah.gnu.org/projects/m4">GNU M4</a> - <td>1.4</td> - <td>Macro processor for configuration<sup><a href="#sf4">4</a></sup></td> - </tr> - - <tr> - <td><a href="http://www.gnu.org/software/autoconf/">GNU Autoconf</a></td> - <td>2.60</td> - <td>Configuration script builder<sup><a href="#sf4">4</a></sup></td> - </tr> - - <tr> - <td><a href="http://www.gnu.org/software/automake/">GNU Automake</a></td> - <td>1.9.6</td> - <td>aclocal macro generator<sup><a href="#sf4">4</a></sup></td> - </tr> - - <tr> - <td><a href="http://savannah.gnu.org/projects/libtool">libtool</a></td> - <td>1.5.22</td> - <td>Shared library manager<sup><a href="#sf4">4</a></sup></td> - </tr> - - </table> - - <p><b>Notes:</b></p> - <div class="doc_notes"> - <ol> - <li><a name="sf1">Only the C and C++ languages are needed so there's no - need to build the other languages for LLVM's purposes.</a> See - <a href="#brokengcc">below</a> for specific version info.</li> - <li><a name="sf2">You only need Subversion if you intend to build from the - latest LLVM sources. If you're working from a release distribution, you - don't need Subversion.</a></li> - <li><a name="sf3">Only needed if you want to run the automated test - suite in the <tt>llvm/test</tt> directory.</a></li> - <li><a name="sf4">If you want to make changes to the configure scripts, - you will need GNU autoconf (2.60), and consequently, GNU M4 (version 1.4 - or higher). You will also need automake (1.9.6). We only use aclocal - from that package.</a></li> - </ol> - </div> - - <p>Additionally, your compilation host is expected to have the usual - plethora of Unix utilities. Specifically:</p> - <ul> - <li><b>ar</b> - archive library builder</li> - <li><b>bzip2*</b> - bzip2 command for distribution generation</li> - <li><b>bunzip2*</b> - bunzip2 command for distribution checking</li> - <li><b>chmod</b> - change permissions on a file</li> - <li><b>cat</b> - output concatenation utility</li> - <li><b>cp</b> - copy files</li> - <li><b>date</b> - print the current date/time </li> - <li><b>echo</b> - print to standard output</li> - <li><b>egrep</b> - extended regular expression search utility</li> - <li><b>find</b> - find files/dirs in a file system</li> - <li><b>grep</b> - regular expression search utility</li> - <li><b>gzip*</b> - gzip command for distribution generation</li> - <li><b>gunzip*</b> - gunzip command for distribution checking</li> - <li><b>install</b> - install directories/files </li> - <li><b>mkdir</b> - create a directory</li> - <li><b>mv</b> - move (rename) files</li> - <li><b>ranlib</b> - symbol table builder for archive libraries</li> - <li><b>rm</b> - remove (delete) files and directories</li> - <li><b>sed</b> - stream editor for transforming output</li> - <li><b>sh</b> - Bourne shell for make build scripts</li> - <li><b>tar</b> - tape archive for distribution generation</li> - <li><b>test</b> - test things in file system</li> - <li><b>unzip*</b> - unzip command for distribution checking</li> - <li><b>zip*</b> - zip command for distribution generation</li> - </ul> -</div> - -<!-- ======================================================================= --> -<h3> - <a name="brokengcc">Broken versions of GCC and other tools</a> -</h3> - -<div> - -<p>LLVM is very demanding of the host C++ compiler, and as such tends to expose -bugs in the compiler. In particular, several versions of GCC crash when trying -to compile LLVM. We routinely use GCC 4.2 (and higher) or Clang. -Other versions of GCC will probably work as well. GCC versions listed -here are known to not work. If you are using one of these versions, please try -to upgrade your GCC to something more recent. If you run into a problem with a -version of GCC not listed here, please <a href="mailto:llvmdev@cs.uiuc.edu">let -us know</a>. Please use the "<tt>gcc -v</tt>" command to find out which version -of GCC you are using. -</p> - -<p><b>GCC versions prior to 3.0</b>: GCC 2.96.x and before had several -problems in the STL that effectively prevent it from compiling LLVM. -</p> - -<p><b>GCC 3.2.2 and 3.2.3</b>: These versions of GCC fails to compile LLVM with -a bogus template error. This was fixed in later GCCs.</p> - -<p><b>GCC 3.3.2</b>: This version of GCC suffered from a <a -href="http://gcc.gnu.org/PR13392">serious bug</a> which causes it to crash in -the "<tt>convert_from_eh_region_ranges_1</tt>" GCC function.</p> - -<p><b>Cygwin GCC 3.3.3</b>: The version of GCC 3.3.3 commonly shipped with - Cygwin does not work.</p> -<p><b>SuSE GCC 3.3.3</b>: The version of GCC 3.3.3 shipped with SuSE 9.1 (and - possibly others) does not compile LLVM correctly (it appears that exception - handling is broken in some cases). Please download the FSF 3.3.3 or upgrade - to a newer version of GCC.</p> -<p><b>GCC 3.4.0 on linux/x86 (32-bit)</b>: GCC miscompiles portions of the - code generator, causing an infinite loop in the llvm-gcc build when built - with optimizations enabled (i.e. a release build).</p> -<p><b>GCC 3.4.2 on linux/x86 (32-bit)</b>: GCC miscompiles portions of the - code generator at -O3, as with 3.4.0. However gcc 3.4.2 (unlike 3.4.0) - correctly compiles LLVM at -O2. A work around is to build release LLVM - builds with "make ENABLE_OPTIMIZED=1 OPTIMIZE_OPTION=-O2 ..."</p> -<p><b>GCC 3.4.x on X86-64/amd64</b>: GCC <a href="http://llvm.org/PR1056"> - miscompiles portions of LLVM</a>.</p> -<p><b>GCC 3.4.4 (CodeSourcery ARM 2005q3-2)</b>: this compiler miscompiles LLVM - when building with optimizations enabled. It appears to work with - "<tt>make ENABLE_OPTIMIZED=1 OPTIMIZE_OPTION=-O1</tt>" or build a debug - build.</p> -<p><b>IA-64 GCC 4.0.0</b>: The IA-64 version of GCC 4.0.0 is known to - miscompile LLVM.</p> -<p><b>Apple Xcode 2.3</b>: GCC crashes when compiling LLVM at -O3 (which is the - default with ENABLE_OPTIMIZED=1. To work around this, build with - "ENABLE_OPTIMIZED=1 OPTIMIZE_OPTION=-O2".</p> -<p><b>GCC 4.1.1</b>: GCC fails to build LLVM with template concept check errors - compiling some files. At the time of this writing, GCC mainline (4.2) - did not share the problem.</p> -<p><b>GCC 4.1.1 on X86-64/amd64</b>: GCC <a href="http://llvm.org/PR1063"> - miscompiles portions of LLVM</a> when compiling llvm itself into 64-bit - code. LLVM will appear to mostly work but will be buggy, e.g. failing - portions of its testsuite.</p> -<p><b>GCC 4.1.2 on OpenSUSE</b>: Seg faults during libstdc++ build and on x86_64 -platforms compiling md5.c gets a mangled constant.</p> -<p><b>GCC 4.1.2 (20061115 (prerelease) (Debian 4.1.1-21)) on Debian</b>: Appears -to miscompile parts of LLVM 2.4. One symptom is ValueSymbolTable complaining -about symbols remaining in the table on destruction.</p> -<p><b>GCC 4.1.2 20071124 (Red Hat 4.1.2-42)</b>: Suffers from the same symptoms -as the previous one. It appears to work with ENABLE_OPTIMIZED=0 (the default).</p> -<p><b>Cygwin GCC 4.3.2 20080827 (beta) 2</b>: - Users <a href="http://llvm.org/PR4145">reported</a> various problems related - with link errors when using this GCC version.</p> -<p><b>Debian GCC 4.3.2 on X86</b>: Crashes building some files in LLVM 2.6.</p> -<p><b>GCC 4.3.3 (Debian 4.3.3-10) on ARM</b>: Miscompiles parts of LLVM 2.6 -when optimizations are turned on. The symptom is an infinite loop in -FoldingSetImpl::RemoveNode while running the code generator.</p> -<p><b>SUSE 11 GCC 4.3.4</b>: Miscompiles LLVM, causing crashes in ValueHandle logic.</p> -<p><b>GCC 4.3.5 and GCC 4.4.5 on ARM</b>: These can miscompile <tt>value >> -1</tt> even at -O0. A test failure in <tt>test/Assembler/alignstack.ll</tt> is -one symptom of the problem. -<p><b>GNU ld 2.16.X</b>. Some 2.16.X versions of the ld linker will produce very -long warning messages complaining that some ".gnu.linkonce.t.*" symbol was -defined in a discarded section. You can safely ignore these messages as they are -erroneous and the linkage is correct. These messages disappear using ld -2.17.</p> - -<p><b>GNU binutils 2.17</b>: Binutils 2.17 contains <a -href="http://sourceware.org/bugzilla/show_bug.cgi?id=3111">a bug</a> which -causes huge link times (minutes instead of seconds) when building LLVM. We -recommend upgrading to a newer version (2.17.50.0.4 or later).</p> - -<p><b>GNU Binutils 2.19.1 Gold</b>: This version of Gold contained -<a href="http://sourceware.org/bugzilla/show_bug.cgi?id=9836">a bug</a> -which causes intermittent failures when building LLVM with position independent -code. The symptom is an error about cyclic dependencies. We recommend -upgrading to a newer version of Gold.</p> - -</div> - -</div> - -<!-- *********************************************************************** --> -<h2> - <a name="starting">Getting Started with LLVM</a> -</h2> -<!-- *********************************************************************** --> - -<div> - -<p>The remainder of this guide is meant to get you up and running with -LLVM and to give you some basic information about the LLVM environment.</p> - -<p>The later sections of this guide describe the <a -href="#layout">general layout</a> of the LLVM source tree, a <a -href="#tutorial">simple example</a> using the LLVM tool chain, and <a -href="#links">links</a> to find more information about LLVM or to get -help via e-mail.</p> - -<!-- ======================================================================= --> -<h3> - <a name="terminology">Terminology and Notation</a> -</h3> - -<div> - -<p>Throughout this manual, the following names are used to denote paths -specific to the local system and working environment. <i>These are not -environment variables you need to set but just strings used in the rest -of this document below</i>. In any of the examples below, simply replace -each of these names with the appropriate pathname on your local system. -All these paths are absolute:</p> - -<dl> - <dt>SRC_ROOT - <dd> - This is the top level directory of the LLVM source tree. - <br><br> - - <dt>OBJ_ROOT - <dd> - This is the top level directory of the LLVM object tree (i.e. the - tree where object files and compiled programs will be placed. It - can be the same as SRC_ROOT). - <br><br> - -</dl> - -</div> - -<!-- ======================================================================= --> -<h3> - <a name="environment">Setting Up Your Environment</a> -</h3> - -<div> - -<p> -In order to compile and use LLVM, you may need to set some environment -variables. - -<dl> - <dt><tt>LLVM_LIB_SEARCH_PATH</tt>=<tt>/path/to/your/bitcode/libs</tt></dt> - <dd>[Optional] This environment variable helps LLVM linking tools find the - locations of your bitcode libraries. It is provided only as a - convenience since you can specify the paths using the -L options of the - tools and the C/C++ front-end will automatically use the bitcode files - installed in its - <tt>lib</tt> directory.</dd> -</dl> - -</div> - -<!-- ======================================================================= --> -<h3> - <a name="unpack">Unpacking the LLVM Archives</a> -</h3> - -<div> - -<p> -If you have the LLVM distribution, you will need to unpack it before you -can begin to compile it. LLVM is distributed as a set of two files: the LLVM -suite and the LLVM GCC front end compiled for your platform. There is an -additional test suite that is optional. Each file is a TAR archive that is -compressed with the gzip program. -</p> - -<p>The files are as follows, with <em>x.y</em> marking the version number: -<dl> - <dt><tt>llvm-x.y.tar.gz</tt></dt> - <dd>Source release for the LLVM libraries and tools.<br></dd> - - <dt><tt>llvm-test-x.y.tar.gz</tt></dt> - <dd>Source release for the LLVM test-suite.</dd> - - <dt><tt>llvm-gcc-4.2-x.y.source.tar.gz</tt></dt> - <dd>Source release of the llvm-gcc-4.2 front end. See README.LLVM in the root - directory for build instructions.<br></dd> - - <dt><tt>llvm-gcc-4.2-x.y-platform.tar.gz</tt></dt> - <dd>Binary release of the llvm-gcc-4.2 front end for a specific platform.<br></dd> - -</dl> - -</div> - -<!-- ======================================================================= --> -<h3> - <a name="checkout">Checkout LLVM from Subversion</a> -</h3> - -<div> - -<p>If you have access to our Subversion repository, you can get a fresh copy of -the entire source code. All you need to do is check it out from Subversion as -follows:</p> - -<ul> - <li><tt>cd <i>where-you-want-llvm-to-live</i></tt></li> - <li>Read-Only: <tt>svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm</tt></li> - <li>Read-Write:<tt>svn co https://user@llvm.org/svn/llvm-project/llvm/trunk - llvm</tt></li> -</ul> - - -<p>This will create an '<tt>llvm</tt>' directory in the current -directory and fully populate it with the LLVM source code, Makefiles, -test directories, and local copies of documentation files.</p> - -<p>If you want to get a specific release (as opposed to the most recent -revision), you can checkout it from the '<tt>tags</tt>' directory (instead of -'<tt>trunk</tt>'). The following releases are located in the following -subdirectories of the '<tt>tags</tt>' directory:</p> - -<ul> -<li>Release 3.1: <b>RELEASE_31/final</b></li> -<li>Release 3.0: <b>RELEASE_30/final</b></li> -<li>Release 2.9: <b>RELEASE_29/final</b></li> -<li>Release 2.8: <b>RELEASE_28</b></li> -<li>Release 2.7: <b>RELEASE_27</b></li> -<li>Release 2.6: <b>RELEASE_26</b></li> -<li>Release 2.5: <b>RELEASE_25</b></li> -<li>Release 2.4: <b>RELEASE_24</b></li> -<li>Release 2.3: <b>RELEASE_23</b></li> -<li>Release 2.2: <b>RELEASE_22</b></li> -<li>Release 2.1: <b>RELEASE_21</b></li> -<li>Release 2.0: <b>RELEASE_20</b></li> -<li>Release 1.9: <b>RELEASE_19</b></li> -<li>Release 1.8: <b>RELEASE_18</b></li> -<li>Release 1.7: <b>RELEASE_17</b></li> -<li>Release 1.6: <b>RELEASE_16</b></li> -<li>Release 1.5: <b>RELEASE_15</b></li> -<li>Release 1.4: <b>RELEASE_14</b></li> -<li>Release 1.3: <b>RELEASE_13</b></li> -<li>Release 1.2: <b>RELEASE_12</b></li> -<li>Release 1.1: <b>RELEASE_11</b></li> -<li>Release 1.0: <b>RELEASE_1</b></li> -</ul> - -<p>If you would like to get the LLVM test suite (a separate package as of 1.4), -you get it from the Subversion repository:</p> - -<div class="doc_code"> -<pre> -% cd llvm/projects -% svn co http://llvm.org/svn/llvm-project/test-suite/trunk test-suite -</pre> -</div> - -<p>By placing it in the <tt>llvm/projects</tt>, it will be automatically -configured by the LLVM configure script as well as automatically updated when -you run <tt>svn update</tt>.</p> - -</div> - -<!-- ======================================================================= --> -<h3> - <a name="git_mirror">GIT mirror</a> -</h3> - -<div> - -<p>GIT mirrors are available for a number of LLVM subprojects. These mirrors - sync automatically with each Subversion commit and contain all necessary - git-svn marks (so, you can recreate git-svn metadata locally). Note that right - now mirrors reflect only <tt>trunk</tt> for each project. You can do the - read-only GIT clone of LLVM via:</p> - -<pre class="doc_code"> -git clone http://llvm.org/git/llvm.git -</pre> - -<p>If you want to check out clang too, run:</p> - -<pre class="doc_code"> -git clone http://llvm.org/git/llvm.git -cd llvm/tools -git clone http://llvm.org/git/clang.git -</pre> - -<p> -Since the upstream repository is in Subversion, you should use -<tt>"git pull --rebase"</tt> -instead of <tt>"git pull"</tt> to avoid generating a non-linear -history in your clone. -To configure <tt>"git pull"</tt> to pass <tt>--rebase</tt> by default -on the master branch, run the following command: -</p> - -<pre class="doc_code"> -git config branch.master.rebase true -</pre> - -<h4>Sending patches with Git</h4> -<div> -<p> -Please read <a href="DeveloperPolicy.html#patches">Developer Policy</a>, too. -</p> - -<p> -Assume <tt>master</tt> points the upstream and <tt>mybranch</tt> points your -working branch, and <tt>mybranch</tt> is rebased onto <tt>master</tt>. -At first you may check sanity of whitespaces: -</p> - -<pre class="doc_code"> -git diff --check master..mybranch -</pre> - -<p> -The easiest way to generate a patch is as below: -</p> - -<pre class="doc_code"> -git diff master..mybranch > /path/to/mybranch.diff -</pre> - -<p> -It is a little different from svn-generated diff. git-diff-generated diff has -prefixes like <tt>a/</tt> and <tt>b/</tt>. Don't worry, most developers might -know it could be accepted with <tt>patch -p1 -N</tt>. -</p> - -<p> -But you may generate patchset with git-format-patch. It generates -by-each-commit patchset. To generate patch files to attach to your article: -</p> - -<pre class="doc_code"> -git format-patch --no-attach master..mybranch -o /path/to/your/patchset -</pre> - -<p> -If you would like to send patches directly, you may use git-send-email or -git-imap-send. Here is an example to generate the patchset in Gmail's [Drafts]. -</p> - -<pre class="doc_code"> -git format-patch --attach master..mybranch --stdout | git imap-send -</pre> - -<p> -Then, your .git/config should have [imap] sections. -</p> - -<pre class="doc_code"> -[imap] - host = imaps://imap.gmail.com - user = <em>your.gmail.account</em>@gmail.com - pass = <em>himitsu!</em> - port = 993 - sslverify = false -; in English - folder = "[Gmail]/Drafts" -; example for Japanese, "Modified UTF-7" encoded. - folder = "[Gmail]/&Tgtm+DBN-" -; example for Traditional Chinese - folder = "[Gmail]/&g0l6Pw-" -</pre> - -</div> - -<h4>For developers to work with git-svn</h4> -<div> - -<p>To set up clone from which you can submit code using - <tt>git-svn</tt>, run:</p> - -<pre class="doc_code"> -git clone http://llvm.org/git/llvm.git -cd llvm -git svn init https://llvm.org/svn/llvm-project/llvm/trunk --username=<username> -git config svn-remote.svn.fetch :refs/remotes/origin/master -git svn rebase -l # -l avoids fetching ahead of the git mirror. - -# If you have clang too: -cd tools -git clone http://llvm.org/git/clang.git -cd clang -git svn init https://llvm.org/svn/llvm-project/cfe/trunk --username=<username> -git config svn-remote.svn.fetch :refs/remotes/origin/master -git svn rebase -l -</pre> - -<p>To update this clone without generating git-svn tags that conflict -with the upstream git repo, run:</p> - -<pre class="doc_code"> -git fetch && (cd tools/clang && git fetch) # Get matching revisions of both trees. -git checkout master -git svn rebase -l -(cd tools/clang && - git checkout master && - git svn rebase -l) -</pre> - -<p>This leaves your working directories on their master branches, so -you'll need to <tt>checkout</tt> each working branch individually and -<tt>rebase</tt> it on top of its parent branch. (Note: This script is -intended for relative newbies to git. If you have more experience, -you can likely improve on it.)</p> - -<p>The git-svn metadata can get out of sync after you mess around with -branches and <code>dcommit</code>. When that happens, <code>git svn -dcommit</code> stops working, complaining about files with uncommitted -changes. The fix is to rebuild the metadata:</p> - -<pre class="doc_code"> -rm -rf .git/svn -git svn rebase -l -</pre> - -</div> - -</div> - -<!-- ======================================================================= --> -<h3> - <a name="config">Local LLVM Configuration</a> -</h3> - -<div> - - <p>Once checked out from the Subversion repository, the LLVM suite source - code must be -configured via the <tt>configure</tt> script. This script sets variables in the -various <tt>*.in</tt> files, most notably <tt>llvm/Makefile.config</tt> and -<tt>llvm/include/Config/config.h</tt>. It also populates <i>OBJ_ROOT</i> with -the Makefiles needed to begin building LLVM.</p> - -<p>The following environment variables are used by the <tt>configure</tt> -script to configure the build system:</p> - -<table summary="LLVM configure script environment variables"> - <tr><th>Variable</th><th>Purpose</th></tr> - <tr> - <td>CC</td> - <td>Tells <tt>configure</tt> which C compiler to use. By default, - <tt>configure</tt> will look for the first GCC C compiler in - <tt>PATH</tt>. Use this variable to override - <tt>configure</tt>'s default behavior.</td> - </tr> - <tr> - <td>CXX</td> - <td>Tells <tt>configure</tt> which C++ compiler to use. By default, - <tt>configure</tt> will look for the first GCC C++ compiler in - <tt>PATH</tt>. Use this variable to override - <tt>configure</tt>'s default behavior.</td> - </tr> -</table> - -<p>The following options can be used to set or enable LLVM specific options:</p> - -<dl> - <dt><i>--enable-optimized</i></dt> - <dd> - Enables optimized compilation (debugging symbols are removed - and GCC optimization flags are enabled). Note that this is the default - setting if you are using the LLVM distribution. The default behavior - of an Subversion checkout is to use an unoptimized build (also known as a - debug build). - <br><br> - </dd> - <dt><i>--enable-debug-runtime</i></dt> - <dd> - Enables debug symbols in the runtime libraries. The default is to strip - debug symbols from the runtime libraries. - </dd> - <dt><i>--enable-jit</i></dt> - <dd> - Compile the Just In Time (JIT) compiler functionality. This is not - available - on all platforms. The default is dependent on platform, so it is best - to explicitly enable it if you want it. - <br><br> - </dd> - <dt><i>--enable-targets=</i><tt>target-option</tt></dt> - <dd>Controls which targets will be built and linked into llc. The default - value for <tt>target_options</tt> is "all" which builds and links all - available targets. The value "host-only" can be specified to build only a - native compiler (no cross-compiler targets available). The "native" target is - selected as the target of the build host. You can also specify a comma - separated list of target names that you want available in llc. The target - names use all lower case. The current set of targets is: <br> - <tt>arm, cpp, hexagon, mblaze, mips, mipsel, msp430, powerpc, ptx, sparc, spu, x86, x86_64, xcore</tt>. - <br><br></dd> - <dt><i>--enable-doxygen</i></dt> - <dd>Look for the doxygen program and enable construction of doxygen based - documentation from the source code. This is disabled by default because - generating the documentation can take a long time and producess 100s of - megabytes of output.</dd> - <dt><i>--with-udis86</i></dt> - <dd>LLVM can use external disassembler library for various purposes (now it's - used only for examining code produced by JIT). This option will enable usage - of <a href="http://udis86.sourceforge.net/">udis86</a> x86 (both 32 and 64 - bits) disassembler library.</dd> -</dl> - -<p>To configure LLVM, follow these steps:</p> - -<ol> - <li><p>Change directory into the object root directory:</p> - - <div class="doc_code"><pre>% cd <i>OBJ_ROOT</i></pre></div></li> - - <li><p>Run the <tt>configure</tt> script located in the LLVM source - tree:</p> - - <div class="doc_code"> - <pre>% <i>SRC_ROOT</i>/configure --prefix=/install/path [other options]</pre> - </div></li> -</ol> - -</div> - -<!-- ======================================================================= --> -<h3> - <a name="compile">Compiling the LLVM Suite Source Code</a> -</h3> - -<div> - -<p>Once you have configured LLVM, you can build it. There are three types of -builds:</p> - -<dl> - <dt>Debug Builds - <dd> - These builds are the default when one is using an Subversion checkout and - types <tt>gmake</tt> (unless the <tt>--enable-optimized</tt> option was - used during configuration). The build system will compile the tools and - libraries with debugging information. To get a Debug Build using the - LLVM distribution the <tt>--disable-optimized</tt> option must be passed - to <tt>configure</tt>. - <br><br> - - <dt>Release (Optimized) Builds - <dd> - These builds are enabled with the <tt>--enable-optimized</tt> option to - <tt>configure</tt> or by specifying <tt>ENABLE_OPTIMIZED=1</tt> on the - <tt>gmake</tt> command line. For these builds, the build system will - compile the tools and libraries with GCC optimizations enabled and strip - debugging information from the libraries and executables it generates. - Note that Release Builds are default when using an LLVM distribution. - <br><br> - - <dt>Profile Builds - <dd> - These builds are for use with profiling. They compile profiling - information into the code for use with programs like <tt>gprof</tt>. - Profile builds must be started by specifying <tt>ENABLE_PROFILING=1</tt> - on the <tt>gmake</tt> command line. -</dl> - -<p>Once you have LLVM configured, you can build it by entering the -<i>OBJ_ROOT</i> directory and issuing the following command:</p> - -<div class="doc_code"><pre>% gmake</pre></div> - -<p>If the build fails, please <a href="#brokengcc">check here</a> to see if you -are using a version of GCC that is known not to compile LLVM.</p> - -<p> -If you have multiple processors in your machine, you may wish to use some of -the parallel build options provided by GNU Make. For example, you could use the -command:</p> - -<div class="doc_code"><pre>% gmake -j2</pre></div> - -<p>There are several special targets which are useful when working with the LLVM -source code:</p> - -<dl> - <dt><tt>gmake clean</tt> - <dd> - Removes all files generated by the build. This includes object files, - generated C/C++ files, libraries, and executables. - <br><br> - - <dt><tt>gmake dist-clean</tt> - <dd> - Removes everything that <tt>gmake clean</tt> does, but also removes files - generated by <tt>configure</tt>. It attempts to return the source tree to the - original state in which it was shipped. - <br><br> - - <dt><tt>gmake install</tt> - <dd> - Installs LLVM header files, libraries, tools, and documentation in a - hierarchy - under $PREFIX, specified with <tt>./configure --prefix=[dir]</tt>, which - defaults to <tt>/usr/local</tt>. - <br><br> - - <dt><tt>gmake -C runtime install-bytecode</tt> - <dd> - Assuming you built LLVM into $OBJDIR, when this command is run, it will - install bitcode libraries into the GCC front end's bitcode library - directory. If you need to update your bitcode libraries, - this is the target to use once you've built them. - <br><br> -</dl> - -<p>Please see the <a href="MakefileGuide.html">Makefile Guide</a> for further -details on these <tt>make</tt> targets and descriptions of other targets -available.</p> - -<p>It is also possible to override default values from <tt>configure</tt> by -declaring variables on the command line. The following are some examples:</p> - -<dl> - <dt><tt>gmake ENABLE_OPTIMIZED=1</tt> - <dd> - Perform a Release (Optimized) build. - <br><br> - - <dt><tt>gmake ENABLE_OPTIMIZED=1 DISABLE_ASSERTIONS=1</tt> - <dd> - Perform a Release (Optimized) build without assertions enabled. - <br><br> - - <dt><tt>gmake ENABLE_OPTIMIZED=0</tt> - <dd> - Perform a Debug build. - <br><br> - - <dt><tt>gmake ENABLE_PROFILING=1</tt> - <dd> - Perform a Profiling build. - <br><br> - - <dt><tt>gmake VERBOSE=1</tt> - <dd> - Print what <tt>gmake</tt> is doing on standard output. - <br><br> - - <dt><tt>gmake TOOL_VERBOSE=1</tt></dt> - <dd>Ask each tool invoked by the makefiles to print out what it is doing on - the standard output. This also implies <tt>VERBOSE=1</tt>. - <br><br></dd> -</dl> - -<p>Every directory in the LLVM object tree includes a <tt>Makefile</tt> to build -it and any subdirectories that it contains. Entering any directory inside the -LLVM object tree and typing <tt>gmake</tt> should rebuild anything in or below -that directory that is out of date.</p> - -</div> - -<!-- ======================================================================= --> -<h3> - <a name="cross-compile">Cross-Compiling LLVM</a> -</h3> - -<div> - <p>It is possible to cross-compile LLVM itself. That is, you can create LLVM - executables and libraries to be hosted on a platform different from the - platform where they are build (a Canadian Cross build). To configure a - cross-compile, supply the configure script with <tt>--build</tt> and - <tt>--host</tt> options that are different. The values of these options must - be legal target triples that your GCC compiler supports.</p> - - <p>The result of such a build is executables that are not runnable on - on the build host (--build option) but can be executed on the compile host - (--host option).</p> -</div> - -<!-- ======================================================================= --> -<h3> - <a name="objfiles">The Location of LLVM Object Files</a> -</h3> - -<div> - -<p>The LLVM build system is capable of sharing a single LLVM source tree among -several LLVM builds. Hence, it is possible to build LLVM for several different -platforms or configurations using the same source tree.</p> - -<p>This is accomplished in the typical autoconf manner:</p> - -<ul> - <li><p>Change directory to where the LLVM object files should live:</p> - - <div class="doc_code"><pre>% cd <i>OBJ_ROOT</i></pre></div></li> - - <li><p>Run the <tt>configure</tt> script found in the LLVM source - directory:</p> - - <div class="doc_code"><pre>% <i>SRC_ROOT</i>/configure</pre></div></li> -</ul> - -<p>The LLVM build will place files underneath <i>OBJ_ROOT</i> in directories -named after the build type:</p> - -<dl> - <dt>Debug Builds with assertions enabled (the default) - <dd> - <dl> - <dt>Tools - <dd><tt><i>OBJ_ROOT</i>/Debug+Asserts/bin</tt> - <dt>Libraries - <dd><tt><i>OBJ_ROOT</i>/Debug+Asserts/lib</tt> - </dl> - <br><br> - - <dt>Release Builds - <dd> - <dl> - <dt>Tools - <dd><tt><i>OBJ_ROOT</i>/Release/bin</tt> - <dt>Libraries - <dd><tt><i>OBJ_ROOT</i>/Release/lib</tt> - </dl> - <br><br> - - <dt>Profile Builds - <dd> - <dl> - <dt>Tools - <dd><tt><i>OBJ_ROOT</i>/Profile/bin</tt> - <dt>Libraries - <dd><tt><i>OBJ_ROOT</i>/Profile/lib</tt> - </dl> -</dl> - -</div> - -<!-- ======================================================================= --> -<h3> - <a name="optionalconfig">Optional Configuration Items</a> -</h3> - -<div> - -<p> -If you're running on a Linux system that supports the "<a -href="http://www.tat.physik.uni-tuebingen.de/~rguenth/linux/binfmt_misc.html">binfmt_misc</a>" -module, and you have root access on the system, you can set your system up to -execute LLVM bitcode files directly. To do this, use commands like this (the -first command may not be required if you are already using the module):</p> - -<div class="doc_code"> -<pre> -$ mount -t binfmt_misc none /proc/sys/fs/binfmt_misc -$ echo ':llvm:M::BC::/path/to/lli:' > /proc/sys/fs/binfmt_misc/register -$ chmod u+x hello.bc (if needed) -$ ./hello.bc -</pre> -</div> - -<p> -This allows you to execute LLVM bitcode files directly. On Debian, you -can also use this command instead of the 'echo' command above: -</p> - -<div class="doc_code"> -<pre> -$ sudo update-binfmts --install llvm /path/to/lli --magic 'BC' -</pre> -</div> - -</div> - -</div> - -<!-- *********************************************************************** --> -<h2> - <a name="layout">Program Layout</a> -</h2> -<!-- *********************************************************************** --> - -<div> - -<p>One useful source of information about the LLVM source base is the LLVM <a -href="http://www.doxygen.org/">doxygen</a> documentation available at <tt><a -href="http://llvm.org/doxygen/">http://llvm.org/doxygen/</a></tt>. -The following is a brief introduction to code layout:</p> - -<!-- ======================================================================= --> -<h3> - <a name="examples"><tt>llvm/examples</tt></a> -</h3> - -<div> - <p>This directory contains some simple examples of how to use the LLVM IR and - JIT.</p> -</div> - -<!-- ======================================================================= --> -<h3> - <a name="include"><tt>llvm/include</tt></a> -</h3> - -<div> - -<p>This directory contains public header files exported from the LLVM -library. The three main subdirectories of this directory are:</p> - -<dl> - <dt><tt><b>llvm/include/llvm</b></tt></dt> - <dd>This directory contains all of the LLVM specific header files. This - directory also has subdirectories for different portions of LLVM: - <tt>Analysis</tt>, <tt>CodeGen</tt>, <tt>Target</tt>, <tt>Transforms</tt>, - etc...</dd> - - <dt><tt><b>llvm/include/llvm/Support</b></tt></dt> - <dd>This directory contains generic support libraries that are provided with - LLVM but not necessarily specific to LLVM. For example, some C++ STL utilities - and a Command Line option processing library store their header files here. - </dd> - - <dt><tt><b>llvm/include/llvm/Config</b></tt></dt> - <dd>This directory contains header files configured by the <tt>configure</tt> - script. They wrap "standard" UNIX and C header files. Source code can - include these header files which automatically take care of the conditional - #includes that the <tt>configure</tt> script generates.</dd> -</dl> -</div> - -<!-- ======================================================================= --> -<h3> - <a name="lib"><tt>llvm/lib</tt></a> -</h3> - -<div> - -<p>This directory contains most of the source files of the LLVM system. In LLVM, -almost all code exists in libraries, making it very easy to share code among the -different <a href="#tools">tools</a>.</p> - -<dl> - <dt><tt><b>llvm/lib/VMCore/</b></tt></dt> - <dd> This directory holds the core LLVM source files that implement core - classes like Instruction and BasicBlock.</dd> - - <dt><tt><b>llvm/lib/AsmParser/</b></tt></dt> - <dd>This directory holds the source code for the LLVM assembly language parser - library.</dd> - - <dt><tt><b>llvm/lib/BitCode/</b></tt></dt> - <dd>This directory holds code for reading and write LLVM bitcode.</dd> - - <dt><tt><b>llvm/lib/Analysis/</b></tt><dd>This directory contains a variety of - different program analyses, such as Dominator Information, Call Graphs, - Induction Variables, Interval Identification, Natural Loop Identification, - etc.</dd> - - <dt><tt><b>llvm/lib/Transforms/</b></tt></dt> - <dd> This directory contains the source code for the LLVM to LLVM program - transformations, such as Aggressive Dead Code Elimination, Sparse Conditional - Constant Propagation, Inlining, Loop Invariant Code Motion, Dead Global - Elimination, and many others.</dd> - - <dt><tt><b>llvm/lib/Target/</b></tt></dt> - <dd> This directory contains files that describe various target architectures - for code generation. For example, the <tt>llvm/lib/Target/X86</tt> - directory holds the X86 machine description while - <tt>llvm/lib/Target/ARM</tt> implements the ARM backend.</dd> - - <dt><tt><b>llvm/lib/CodeGen/</b></tt></dt> - <dd> This directory contains the major parts of the code generator: Instruction - Selector, Instruction Scheduling, and Register Allocation.</dd> - - <dt><tt><b>llvm/lib/MC/</b></tt></dt> - <dd>(FIXME: T.B.D.)</dd> - - <!--FIXME: obsoleted --> - <dt><tt><b>llvm/lib/Debugger/</b></tt></dt> - <dd> This directory contains the source level debugger library that makes - it possible to instrument LLVM programs so that a debugger could identify - source code locations at which the program is executing.</dd> - - <dt><tt><b>llvm/lib/ExecutionEngine/</b></tt></dt> - <dd> This directory contains libraries for executing LLVM bitcode directly - at runtime in both interpreted and JIT compiled fashions.</dd> - - <dt><tt><b>llvm/lib/Support/</b></tt></dt> - <dd> This directory contains the source code that corresponds to the header - files located in <tt>llvm/include/ADT/</tt> - and <tt>llvm/include/Support/</tt>.</dd> -</dl> - -</div> - -<!-- ======================================================================= --> -<h3> - <a name="projects"><tt>llvm/projects</tt></a> -</h3> - -<div> - <p>This directory contains projects that are not strictly part of LLVM but are - shipped with LLVM. This is also the directory where you should create your own - LLVM-based projects. See <tt>llvm/projects/sample</tt> for an example of how - to set up your own project.</p> -</div> - -<!-- ======================================================================= --> -<h3> - <a name="runtime"><tt>llvm/runtime</tt></a> -</h3> - -<div> - -<p>This directory contains libraries which are compiled into LLVM bitcode and -used when linking programs with the Clang front end. Most of these libraries are -skeleton versions of real libraries; for example, libc is a stripped down -version of glibc.</p> - -<p>Unlike the rest of the LLVM suite, this directory needs the LLVM GCC front -end to compile.</p> - -</div> - -<!-- ======================================================================= --> -<h3> - <a name="test"><tt>llvm/test</tt></a> -</h3> - -<div> - <p>This directory contains feature and regression tests and other basic sanity - checks on the LLVM infrastructure. These are intended to run quickly and cover - a lot of territory without being exhaustive.</p> -</div> - -<!-- ======================================================================= --> -<h3> - <a name="test-suite"><tt>test-suite</tt></a> -</h3> - -<div> - <p>This is not a directory in the normal llvm module; it is a separate - Subversion - module that must be checked out (usually to <tt>projects/test-suite</tt>). - This - module contains a comprehensive correctness, performance, and benchmarking - test - suite for LLVM. It is a separate Subversion module because not every LLVM - user is - interested in downloading or building such a comprehensive test suite. For - further details on this test suite, please see the - <a href="TestingGuide.html">Testing Guide</a> document.</p> -</div> - -<!-- ======================================================================= --> -<h3> - <a name="tools"><tt>llvm/tools</tt></a> -</h3> - -<div> - -<p>The <b>tools</b> directory contains the executables built out of the -libraries above, which form the main part of the user interface. You can -always get help for a tool by typing <tt>tool_name -help</tt>. The -following is a brief introduction to the most important tools. More detailed -information is in the <a href="CommandGuide/index.html">Command Guide</a>.</p> - -<dl> - - <dt><tt><b>bugpoint</b></tt></dt> - <dd><tt>bugpoint</tt> is used to debug - optimization passes or code generation backends by narrowing down the - given test case to the minimum number of passes and/or instructions that - still cause a problem, whether it is a crash or miscompilation. See <a - href="HowToSubmitABug.html">HowToSubmitABug.html</a> for more information - on using <tt>bugpoint</tt>.</dd> - - <dt><tt><b>llvm-ar</b></tt></dt> - <dd>The archiver produces an archive containing - the given LLVM bitcode files, optionally with an index for faster - lookup.</dd> - - <dt><tt><b>llvm-as</b></tt></dt> - <dd>The assembler transforms the human readable LLVM assembly to LLVM - bitcode.</dd> - - <dt><tt><b>llvm-dis</b></tt></dt> - <dd>The disassembler transforms the LLVM bitcode to human readable - LLVM assembly.</dd> - - <dt><tt><b>llvm-link</b></tt></dt> - <dd><tt>llvm-link</tt>, not surprisingly, links multiple LLVM modules into - a single program.</dd> - - <dt><tt><b>lli</b></tt></dt> - <dd><tt>lli</tt> is the LLVM interpreter, which - can directly execute LLVM bitcode (although very slowly...). For architectures - that support it (currently x86, Sparc, and PowerPC), by default, <tt>lli</tt> - will function as a Just-In-Time compiler (if the functionality was compiled - in), and will execute the code <i>much</i> faster than the interpreter.</dd> - - <dt><tt><b>llc</b></tt></dt> - <dd> <tt>llc</tt> is the LLVM backend compiler, which - translates LLVM bitcode to a native code assembly file or to C code (with - the -march=c option).</dd> - - <dt><tt><b>llvm-gcc</b></tt></dt> - <dd><tt>llvm-gcc</tt> is a GCC-based C frontend that has been retargeted to - use LLVM as its backend instead of GCC's RTL backend. It can also emit LLVM - bitcode or assembly (with the <tt>-emit-llvm</tt> option) instead of the - usual machine code output. It works just like any other GCC compiler, - taking the typical <tt>-c, -S, -E, -o</tt> options that are typically used. - Additionally, the source code for <tt>llvm-gcc</tt> is available as a - separate Subversion module.</dd> - - <dt><tt><b>opt</b></tt></dt> - <dd><tt>opt</tt> reads LLVM bitcode, applies a series of LLVM to LLVM - transformations (which are specified on the command line), and then outputs - the resultant bitcode. The '<tt>opt -help</tt>' command is a good way to - get a list of the program transformations available in LLVM.<br> - <dd><tt>opt</tt> can also be used to run a specific analysis on an input - LLVM bitcode file and print out the results. It is primarily useful for - debugging analyses, or familiarizing yourself with what an analysis does.</dd> -</dl> -</div> - -<!-- ======================================================================= --> -<h3> - <a name="utils"><tt>llvm/utils</tt></a> -</h3> - -<div> - -<p>This directory contains utilities for working with LLVM source code, and some -of the utilities are actually required as part of the build process because they -are code generators for parts of LLVM infrastructure.</p> - -<dl> - <dt><tt><b>codegen-diff</b></tt> <dd><tt>codegen-diff</tt> is a script - that finds differences between code that LLC generates and code that LLI - generates. This is a useful tool if you are debugging one of them, - assuming that the other generates correct output. For the full user - manual, run <tt>`perldoc codegen-diff'</tt>.<br><br> - - <dt><tt><b>emacs/</b></tt> <dd>The <tt>emacs</tt> directory contains - syntax-highlighting files which will work with Emacs and XEmacs editors, - providing syntax highlighting support for LLVM assembly files and TableGen - description files. For information on how to use the syntax files, consult - the <tt>README</tt> file in that directory.<br><br> - - <dt><tt><b>getsrcs.sh</b></tt> <dd>The <tt>getsrcs.sh</tt> script finds - and outputs all non-generated source files, which is useful if one wishes - to do a lot of development across directories and does not want to - individually find each file. One way to use it is to run, for example: - <tt>xemacs `utils/getsources.sh`</tt> from the top of your LLVM source - tree.<br><br> - - <dt><tt><b>llvmgrep</b></tt></dt> - <dd>This little tool performs an "egrep -H -n" on each source file in LLVM and - passes to it a regular expression provided on <tt>llvmgrep</tt>'s command - line. This is a very efficient way of searching the source base for a - particular regular expression.</dd> - - <dt><tt><b>makellvm</b></tt> <dd>The <tt>makellvm</tt> script compiles all - files in the current directory and then compiles and links the tool that - is the first argument. For example, assuming you are in the directory - <tt>llvm/lib/Target/Sparc</tt>, if <tt>makellvm</tt> is in your path, - simply running <tt>makellvm llc</tt> will make a build of the current - directory, switch to directory <tt>llvm/tools/llc</tt> and build it, - causing a re-linking of LLC.<br><br> - - <dt><tt><b>TableGen/</b></tt> <dd>The <tt>TableGen</tt> directory contains - the tool used to generate register descriptions, instruction set - descriptions, and even assemblers from common TableGen description - files.<br><br> - - <dt><tt><b>vim/</b></tt> <dd>The <tt>vim</tt> directory contains - syntax-highlighting files which will work with the VIM editor, providing - syntax highlighting support for LLVM assembly files and TableGen - description files. For information on how to use the syntax files, consult - the <tt>README</tt> file in that directory.<br><br> - -</dl> - -</div> - -</div> - -<!-- *********************************************************************** --> -<h2> - <a name="tutorial">An Example Using the LLVM Tool Chain</a> -</h2> -<!-- *********************************************************************** --> - -<div> -<p>This section gives an example of using LLVM with the Clang front end.</p> - -<!-- ======================================================================= --> -<h3> - <a name="tutorial4">Example with clang</a> -</h3> - -<div> - -<ol> - <li><p>First, create a simple C file, name it 'hello.c':</p> - -<div class="doc_code"> -<pre> -#include <stdio.h> - -int main() { - printf("hello world\n"); - return 0; -} -</pre></div></li> - - <li><p>Next, compile the C file into a native executable:</p> - - <div class="doc_code"><pre>% clang hello.c -o hello</pre></div> - - <p>Note that clang works just like GCC by default. The standard -S and - -c arguments work as usual (producing a native .s or .o file, - respectively).</p></li> - - <li><p>Next, compile the C file into a LLVM bitcode file:</p> - - <div class="doc_code"> - <pre>% clang -O3 -emit-llvm hello.c -c -o hello.bc</pre></div> - - <p>The -emit-llvm option can be used with the -S or -c options to emit an - LLVM ".ll" or ".bc" file (respectively) for the code. This allows you - to use the <a href="CommandGuide/index.html">standard LLVM tools</a> on - the bitcode file.</p></li> - - <li><p>Run the program in both forms. To run the program, use:</p> - - <div class="doc_code"><pre>% ./hello</pre></div> - - <p>and</p> - - <div class="doc_code"><pre>% lli hello.bc</pre></div> - - <p>The second examples shows how to invoke the LLVM JIT, <a - href="CommandGuide/html/lli.html">lli</a>.</p></li> - - <li><p>Use the <tt>llvm-dis</tt> utility to take a look at the LLVM assembly - code:</p> - -<div class="doc_code"> -<pre>llvm-dis < hello.bc | less</pre> -</div></li> - - <li><p>Compile the program to native assembly using the LLC code - generator:</p> - - <div class="doc_code"><pre>% llc hello.bc -o hello.s</pre></div></li> - - <li><p>Assemble the native assembly language file into a program:</p> - -<div class="doc_code"> -<pre> -<b>Solaris:</b> % /opt/SUNWspro/bin/cc -xarch=v9 hello.s -o hello.native - -<b>Others:</b> % gcc hello.s -o hello.native -</pre> -</div></li> - - <li><p>Execute the native code program:</p> - - <div class="doc_code"><pre>% ./hello.native</pre></div> - - <p>Note that using clang to compile directly to native code (i.e. when - the -emit-llvm option is not present) does steps 6/7/8 for you.</p> - </li> - -</ol> - -</div> - -</div> - -<!-- *********************************************************************** --> -<h2> - <a name="problems">Common Problems</a> -</h2> -<!-- *********************************************************************** --> - -<div> - -<p>If you are having problems building or using LLVM, or if you have any other -general questions about LLVM, please consult the <a href="FAQ.html">Frequently -Asked Questions</a> page.</p> - -</div> - -<!-- *********************************************************************** --> -<h2> - <a name="links">Links</a> -</h2> -<!-- *********************************************************************** --> - -<div> - -<p>This document is just an <b>introduction</b> on how to use LLVM to do -some simple things... there are many more interesting and complicated things -that you can do that aren't documented here (but we'll gladly accept a patch -if you want to write something up!). For more information about LLVM, check -out:</p> - -<ul> - <li><a href="http://llvm.org/">LLVM homepage</a></li> - <li><a href="http://llvm.org/doxygen/">LLVM doxygen tree</a></li> - <li><a href="http://llvm.org/docs/Projects.html">Starting a Project - that Uses LLVM</a></li> -</ul> - -</div> - -<!-- *********************************************************************** --> - -<hr> -<address> - <a href="http://jigsaw.w3.org/css-validator/check/referer"><img - src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS"></a> - <a href="http://validator.w3.org/check/referer"><img - src="http://www.w3.org/Icons/valid-html401-blue" alt="Valid HTML 4.01"></a> - - <a href="mailto:sabre@nondot.org">Chris Lattner</a><br> - <a href="http://llvm.x10sys.com/rspencer/">Reid Spencer</a><br> - <a href="http://llvm.org/">The LLVM Compiler Infrastructure</a><br> - Last modified: $Date: 2012-07-23 10:51:15 +0200 (Mon, 23 Jul 2012) $ -</address> -</body> -</html> diff --git a/docs/GettingStarted.rst b/docs/GettingStarted.rst new file mode 100644 index 0000000..6876892 --- /dev/null +++ b/docs/GettingStarted.rst @@ -0,0 +1,1304 @@ +.. _getting_started: + +==================================== +Getting Started with the LLVM System +==================================== + +Overview +======== + +Welcome to LLVM! In order to get started, you first need to know some basic +information. + +First, LLVM comes in three pieces. The first piece is the LLVM suite. This +contains all of the tools, libraries, and header files needed to use LLVM. It +contains an assembler, disassembler, bitcode analyzer and bitcode optimizer. It +also contains basic regression tests that can be used to test the LLVM tools and +the Clang front end. + +The second piece is the `Clang <http://clang.llvm.org/>`_ front end. This +component compiles C, C++, Objective C, and Objective C++ code into LLVM +bitcode. Once compiled into LLVM bitcode, a program can be manipulated with the +LLVM tools from the LLVM suite. + +There is a third, optional piece called Test Suite. It is a suite of programs +with a testing harness that can be used to further test LLVM's functionality +and performance. + +Getting Started Quickly (A Summary) +=================================== + +The LLVM Getting Started documentation may be out of date. So, the `Clang +Getting Started <http://clang.llvm.org/get_started.html>`_ page might also be a +good place to start. + +Here's the short story for getting up and running quickly with LLVM: + +#. Read the documentation. +#. Read the documentation. +#. Remember that you were warned twice about reading the documentation. +#. Checkout LLVM: + + * ``cd where-you-want-llvm-to-live`` + * ``svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm`` + +#. Checkout Clang: + + * ``cd where-you-want-llvm-to-live`` + * ``cd llvm/tools`` + * ``svn co http://llvm.org/svn/llvm-project/cfe/trunk clang`` + +#. Checkout Compiler-RT: + + * ``cd where-you-want-llvm-to-live`` + * ``cd llvm/projects`` + * ``svn co http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt`` + +#. Get the Test Suite Source Code **[Optional]** + + * ``cd where-you-want-llvm-to-live`` + * ``cd llvm/projects`` + * ``svn co http://llvm.org/svn/llvm-project/test-suite/trunk test-suite`` + +#. Configure and build LLVM and Clang: + + * ``cd where-you-want-to-build-llvm`` + * ``mkdir build`` (for building without polluting the source dir) + * ``cd build`` + * ``../llvm/configure [options]`` + Some common options: + + * ``--prefix=directory`` --- + + Specify for *directory* the full pathname of where you want the LLVM + tools and libraries to be installed (default ``/usr/local``). + + * ``--enable-optimized`` --- + + Compile with optimizations enabled (default is NO). + + * ``--enable-assertions`` --- + + Compile with assertion checks enabled (default is YES). + + * ``make [-j]`` --- The ``-j`` specifies the number of jobs (commands) to run + simultaneously. This builds both LLVM and Clang for Debug+Asserts mode. + The --enabled-optimized configure option is used to specify a Release + build. + + * ``make check-all`` --- This run the regression tests to ensure everything + is in working order. + + * ``make update`` --- This command is used to update all the svn repositories + at once, rather then having to ``cd`` into the individual repositories and + running ``svn update``. + + * It is also possible to use CMake instead of the makefiles. With CMake it is + also possible to generate project files for several IDEs: Eclipse CDT4, + CodeBlocks, Qt-Creator (use the CodeBlocks generator), KDevelop3. + + * If you get an "internal compiler error (ICE)" or test failures, see + `below`. + +Consult the `Getting Started with LLVM`_ section for detailed information on +configuring and compiling LLVM. See `Setting Up Your Environment`_ for tips +that simplify working with the Clang front end and LLVM tools. Go to `Program +Layout`_ to learn about the layout of the source code tree. + +Requirements +============ + +Before you begin to use the LLVM system, review the requirements given below. +This may save you some trouble by knowing ahead of time what hardware and +software you will need. + +Hardware +-------- + +LLVM is known to work on the following platforms: + ++-----------------+----------------------+-------------------------+ +|OS | Arch | Compilers | ++=================+======================+=========================+ +|AuroraUX | x86\ :sup:`1` | GCC | ++-----------------+----------------------+-------------------------+ +|Linux | x86\ :sup:`1` | GCC | ++-----------------+----------------------+-------------------------+ +|Linux | amd64 | GCC | ++-----------------+----------------------+-------------------------+ +|Solaris | V9 (Ultrasparc) | GCC | ++-----------------+----------------------+-------------------------+ +|FreeBSD | x86\ :sup:`1` | GCC | ++-----------------+----------------------+-------------------------+ +|FreeBSD | amd64 | GCC | ++-----------------+----------------------+-------------------------+ +|MacOS X\ :sup:`2`| PowerPC | GCC | ++-----------------+----------------------+-------------------------+ +|MacOS X\ :sup:`9`| x86 | GCC | ++-----------------+----------------------+-------------------------+ +|Cygwin/Win32 | x86\ :sup:`1, 8, 11` | GCC 3.4.X, binutils 2.20| ++-----------------+----------------------+-------------------------+ + +LLVM has partial support for the following platforms: + ++-------------------+----------------------+-------------------------------------------+ +|OS | Arch | Compilers | ++===================+======================+===========================================+ +| Windows | x86\ :sup:`1` | Visual Studio 2000 or higher\ :sup:`4,5` | ++-------------------+----------------------+-------------------------------------------+ +| AIX\ :sup:`3,4` | PowerPC | GCC | ++-------------------+----------------------+-------------------------------------------+ +| Linux\ :sup:`3,5` | PowerPC | GCC | ++-------------------+----------------------+-------------------------------------------+ +| Linux\ :sup:`7` | Alpha | GCC | ++-------------------+----------------------+-------------------------------------------+ +| Linux\ :sup:`7` | Itanium (IA-64) | GCC | ++-------------------+----------------------+-------------------------------------------+ +| HP-UX\ :sup:`7` | Itanium (IA-64) | HP aCC | ++-------------------+----------------------+-------------------------------------------+ +| Windows x64 | x86-64 | mingw-w64's GCC-4.5.x\ :sup:`12` | ++-------------------+----------------------+-------------------------------------------+ + +.. note:: + + Code generation supported for Pentium processors and up + + #. Code generation supported for Pentium processors and up + #. Code generation supported for 32-bit ABI only + #. No native code generation + #. Build is not complete: one or more tools do not link or function + #. The GCC-based C/C++ frontend does not build + #. The port is done using the MSYS shell. + #. Native code generation exists but is not complete. + #. Binutils 2.20 or later is required to build the assembler generated by LLVM properly. + #. Xcode 2.5 and gcc 4.0.1 (Apple Build 5370) will trip internal LLVM assert + messages when compiled for Release at optimization levels greater than 0 + (i.e., ``-O1`` and higher). Add ``OPTIMIZE_OPTION="-O0"`` to the build + command line if compiling for LLVM Release or bootstrapping the LLVM + toolchain. + #. For MSYS/MinGW on Windows, be sure to install the MSYS version of the perl + package, and be sure it appears in your path before any Windows-based + versions such as Strawberry Perl and ActivePerl, as these have + Windows-specifics that will cause the build to fail. + #. To use LLVM modules on Win32-based system, you may configure LLVM + with ``--enable-shared``. + + #. To compile SPU backend, you need to add ``LDFLAGS=-Wl,--stack,16777216`` to + configure. + +Note that you will need about 1-3 GB of space for a full LLVM build in Debug +mode, depending on the system (it is so large because of all the debugging +information and the fact that the libraries are statically linked into multiple +tools). If you do not need many of the tools and you are space-conscious, you +can pass ``ONLY_TOOLS="tools you need"`` to make. The Release build requires +considerably less space. + +The LLVM suite *may* compile on other platforms, but it is not guaranteed to do +so. If compilation is successful, the LLVM utilities should be able to +assemble, disassemble, analyze, and optimize LLVM bitcode. Code generation +should work as well, although the generated native code may not work on your +platform. + +Software +-------- + +Compiling LLVM requires that you have several software packages installed. The +table below lists those required packages. The Package column is the usual name +for the software package that LLVM depends on. The Version column provides +"known to work" versions of the package. The Notes column describes how LLVM +uses the package and provides other details. + ++--------------------------------------------------------------+-----------------+---------------------------------------------+ +| Package | Version | Notes | ++==============================================================+=================+=============================================+ +| `GNU Make <http://savannah.gnu.org/projects/make>`_ | 3.79, 3.79.1 | Makefile/build processor | ++--------------------------------------------------------------+-----------------+---------------------------------------------+ +| `GCC <http://gcc.gnu.org/>`_ | 3.4.2 | C/C++ compiler\ :sup:`1` | ++--------------------------------------------------------------+-----------------+---------------------------------------------+ +| `TeXinfo <http://www.gnu.org/software/texinfo/>`_ | 4.5 | For building the CFE | ++--------------------------------------------------------------+-----------------+---------------------------------------------+ +| `SVN <http://subversion.tigris.org/project_packages.html>`_ | >=1.3 | Subversion access to LLVM\ :sup:`2` | ++--------------------------------------------------------------+-----------------+---------------------------------------------+ +| `DejaGnu <http://savannah.gnu.org/projects/dejagnu>`_ | 1.4.2 | Automated test suite\ :sup:`3` | ++--------------------------------------------------------------+-----------------+---------------------------------------------+ +| `tcl <http://www.tcl.tk/software/tcltk/>`_ | 8.3, 8.4 | Automated test suite\ :sup:`3` | ++--------------------------------------------------------------+-----------------+---------------------------------------------+ +| `expect <http://expect.nist.gov/>`_ | 5.38.0 | Automated test suite\ :sup:`3` | ++--------------------------------------------------------------+-----------------+---------------------------------------------+ +| `perl <http://www.perl.com/download.csp>`_ | >=5.6.0 | Utilities | ++--------------------------------------------------------------+-----------------+---------------------------------------------+ +| `GNU M4 <http://savannah.gnu.org/projects/m4>`_ | 1.4 | Macro processor for configuration\ :sup:`4` | ++--------------------------------------------------------------+-----------------+---------------------------------------------+ +| `GNU Autoconf <http://www.gnu.org/software/autoconf/>`_ | 2.60 | Configuration script builder\ :sup:`4` | ++--------------------------------------------------------------+-----------------+---------------------------------------------+ +| `GNU Automake <http://www.gnu.org/software/automake/>`_ | 1.9.6 | aclocal macro generator\ :sup:`4` | ++--------------------------------------------------------------+-----------------+---------------------------------------------+ +| `libtool <http://savannah.gnu.org/projects/libtool>`_ | 1.5.22 | Shared library manager\ :sup:`4` | ++--------------------------------------------------------------+-----------------+---------------------------------------------+ + +.. note:: + + #. Only the C and C++ languages are needed so there's no need to build the + other languages for LLVM's purposes. See `below` for specific version + info. + #. You only need Subversion if you intend to build from the latest LLVM + sources. If you're working from a release distribution, you don't need + Subversion. + #. Only needed if you want to run the automated test suite in the + ``llvm/test`` directory. + #. If you want to make changes to the configure scripts, you will need GNU + autoconf (2.60), and consequently, GNU M4 (version 1.4 or higher). You + will also need automake (1.9.6). We only use aclocal from that package. + +Additionally, your compilation host is expected to have the usual plethora of +Unix utilities. Specifically: + +* **ar** --- archive library builder +* **bzip2** --- bzip2 command for distribution generation +* **bunzip2** --- bunzip2 command for distribution checking +* **chmod** --- change permissions on a file +* **cat** --- output concatenation utility +* **cp** --- copy files +* **date** --- print the current date/time +* **echo** --- print to standard output +* **egrep** --- extended regular expression search utility +* **find** --- find files/dirs in a file system +* **grep** --- regular expression search utility +* **gzip** --- gzip command for distribution generation +* **gunzip** --- gunzip command for distribution checking +* **install** --- install directories/files +* **mkdir** --- create a directory +* **mv** --- move (rename) files +* **ranlib** --- symbol table builder for archive libraries +* **rm** --- remove (delete) files and directories +* **sed** --- stream editor for transforming output +* **sh** --- Bourne shell for make build scripts +* **tar** --- tape archive for distribution generation +* **test** --- test things in file system +* **unzip** --- unzip command for distribution checking +* **zip** --- zip command for distribution generation + +.. _below: +.. _check here: + +Broken versions of GCC and other tools +-------------------------------------- + +LLVM is very demanding of the host C++ compiler, and as such tends to expose +bugs in the compiler. In particular, several versions of GCC crash when trying +to compile LLVM. We routinely use GCC 4.2 (and higher) or Clang. Other +versions of GCC will probably work as well. GCC versions listed here are known +to not work. If you are using one of these versions, please try to upgrade your +GCC to something more recent. If you run into a problem with a version of GCC +not listed here, please `let us know <mailto:llvmdev@cs.uiuc.edu>`_. Please use +the "``gcc -v``" command to find out which version of GCC you are using. + +**GCC versions prior to 3.0**: GCC 2.96.x and before had several problems in the +STL that effectively prevent it from compiling LLVM. + +**GCC 3.2.2 and 3.2.3**: These versions of GCC fails to compile LLVM with a +bogus template error. This was fixed in later GCCs. + +**GCC 3.3.2**: This version of GCC suffered from a `serious bug +<http://gcc.gnu.org/PR13392>`_ which causes it to crash in the +"``convert_from_eh_region_ranges_1``" GCC function. + +**Cygwin GCC 3.3.3**: The version of GCC 3.3.3 commonly shipped with Cygwin does +not work. + +**SuSE GCC 3.3.3**: The version of GCC 3.3.3 shipped with SuSE 9.1 (and possibly +others) does not compile LLVM correctly (it appears that exception handling is +broken in some cases). Please download the FSF 3.3.3 or upgrade to a newer +version of GCC. + +**GCC 3.4.0 on linux/x86 (32-bit)**: GCC miscompiles portions of the code +generator, causing an infinite loop in the llvm-gcc build when built with +optimizations enabled (i.e. a release build). + +**GCC 3.4.2 on linux/x86 (32-bit)**: GCC miscompiles portions of the code +generator at -O3, as with 3.4.0. However gcc 3.4.2 (unlike 3.4.0) correctly +compiles LLVM at -O2. A work around is to build release LLVM builds with +"``make ENABLE_OPTIMIZED=1 OPTIMIZE_OPTION=-O2 ...``" + +**GCC 3.4.x on X86-64/amd64**: GCC `miscompiles portions of LLVM +<http://llvm.org/PR1056>`__. + +**GCC 3.4.4 (CodeSourcery ARM 2005q3-2)**: this compiler miscompiles LLVM when +building with optimizations enabled. It appears to work with "``make +ENABLE_OPTIMIZED=1 OPTIMIZE_OPTION=-O1``" or build a debug build. + +**IA-64 GCC 4.0.0**: The IA-64 version of GCC 4.0.0 is known to miscompile LLVM. + +**Apple Xcode 2.3**: GCC crashes when compiling LLVM at -O3 (which is the +default with ENABLE_OPTIMIZED=1. To work around this, build with +"``ENABLE_OPTIMIZED=1 OPTIMIZE_OPTION=-O2``". + +**GCC 4.1.1**: GCC fails to build LLVM with template concept check errors +compiling some files. At the time of this writing, GCC mainline (4.2) did not +share the problem. + +**GCC 4.1.1 on X86-64/amd64**: GCC `miscompiles portions of LLVM +<http://llvm.org/PR1063>`__ when compiling llvm itself into 64-bit code. LLVM +will appear to mostly work but will be buggy, e.g. failing portions of its +testsuite. + +**GCC 4.1.2 on OpenSUSE**: Seg faults during libstdc++ build and on x86_64 +platforms compiling md5.c gets a mangled constant. + +**GCC 4.1.2 (20061115 (prerelease) (Debian 4.1.1-21)) on Debian**: Appears to +miscompile parts of LLVM 2.4. One symptom is ValueSymbolTable complaining about +symbols remaining in the table on destruction. + +**GCC 4.1.2 20071124 (Red Hat 4.1.2-42)**: Suffers from the same symptoms as the +previous one. It appears to work with ENABLE_OPTIMIZED=0 (the default). + +**Cygwin GCC 4.3.2 20080827 (beta) 2**: Users `reported +<http://llvm.org/PR4145>`_ various problems related with link errors when using +this GCC version. + +**Debian GCC 4.3.2 on X86**: Crashes building some files in LLVM 2.6. + +**GCC 4.3.3 (Debian 4.3.3-10) on ARM**: Miscompiles parts of LLVM 2.6 when +optimizations are turned on. The symptom is an infinite loop in +``FoldingSetImpl::RemoveNode`` while running the code generator. + +**SUSE 11 GCC 4.3.4**: Miscompiles LLVM, causing crashes in ValueHandle logic. + +**GCC 4.3.5 and GCC 4.4.5 on ARM**: These can miscompile ``value >> 1`` even at +``-O0``. A test failure in ``test/Assembler/alignstack.ll`` is one symptom of +the problem. + +**GNU ld 2.16.X**. Some 2.16.X versions of the ld linker will produce very long +warning messages complaining that some "``.gnu.linkonce.t.*``" symbol was +defined in a discarded section. You can safely ignore these messages as they are +erroneous and the linkage is correct. These messages disappear using ld 2.17. + +**GNU binutils 2.17**: Binutils 2.17 contains `a bug +<http://sourceware.org/bugzilla/show_bug.cgi?id=3111>`__ which causes huge link +times (minutes instead of seconds) when building LLVM. We recommend upgrading +to a newer version (2.17.50.0.4 or later). + +**GNU Binutils 2.19.1 Gold**: This version of Gold contained `a bug +<http://sourceware.org/bugzilla/show_bug.cgi?id=9836>`__ which causes +intermittent failures when building LLVM with position independent code. The +symptom is an error about cyclic dependencies. We recommend upgrading to a +newer version of Gold. + +.. _Getting Started with LLVM: + +Getting Started with LLVM +========================= + +The remainder of this guide is meant to get you up and running with LLVM and to +give you some basic information about the LLVM environment. + +The later sections of this guide describe the `general layout`_ of the LLVM +source tree, a `simple example`_ using the LLVM tool chain, and `links`_ to find +more information about LLVM or to get help via e-mail. + +Terminology and Notation +------------------------ + +Throughout this manual, the following names are used to denote paths specific to +the local system and working environment. *These are not environment variables +you need to set but just strings used in the rest of this document below*. In +any of the examples below, simply replace each of these names with the +appropriate pathname on your local system. All these paths are absolute: + +``SRC_ROOT`` + + This is the top level directory of the LLVM source tree. + +``OBJ_ROOT`` + + This is the top level directory of the LLVM object tree (i.e. the tree where + object files and compiled programs will be placed. It can be the same as + SRC_ROOT). + +.. _Setting Up Your Environment: + +Setting Up Your Environment +--------------------------- + +In order to compile and use LLVM, you may need to set some environment +variables. + +``LLVM_LIB_SEARCH_PATH=/path/to/your/bitcode/libs`` + + [Optional] This environment variable helps LLVM linking tools find the + locations of your bitcode libraries. It is provided only as a convenience + since you can specify the paths using the -L options of the tools and the + C/C++ front-end will automatically use the bitcode files installed in its + ``lib`` directory. + +Unpacking the LLVM Archives +--------------------------- + +If you have the LLVM distribution, you will need to unpack it before you can +begin to compile it. LLVM is distributed as a set of two files: the LLVM suite +and the LLVM GCC front end compiled for your platform. There is an additional +test suite that is optional. Each file is a TAR archive that is compressed with +the gzip program. + +The files are as follows, with *x.y* marking the version number: + +``llvm-x.y.tar.gz`` + + Source release for the LLVM libraries and tools. + +``llvm-test-x.y.tar.gz`` + + Source release for the LLVM test-suite. + +``llvm-gcc-4.2-x.y.source.tar.gz`` + + Source release of the llvm-gcc-4.2 front end. See README.LLVM in the root + directory for build instructions. + +``llvm-gcc-4.2-x.y-platform.tar.gz`` + + Binary release of the llvm-gcc-4.2 front end for a specific platform. + +Checkout LLVM from Subversion +----------------------------- + +If you have access to our Subversion repository, you can get a fresh copy of the +entire source code. All you need to do is check it out from Subversion as +follows: + +* ``cd where-you-want-llvm-to-live`` +* Read-Only: ``svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm`` +* Read-Write:``svn co https://user@llvm.org/svn/llvm-project/llvm/trunk llvm`` + +This will create an '``llvm``' directory in the current directory and fully +populate it with the LLVM source code, Makefiles, test directories, and local +copies of documentation files. + +If you want to get a specific release (as opposed to the most recent revision), +you can checkout it from the '``tags``' directory (instead of '``trunk``'). The +following releases are located in the following subdirectories of the '``tags``' +directory: + +* Release 3.1: **RELEASE_31/final** +* Release 3.0: **RELEASE_30/final** +* Release 2.9: **RELEASE_29/final** +* Release 2.8: **RELEASE_28** +* Release 2.7: **RELEASE_27** +* Release 2.6: **RELEASE_26** +* Release 2.5: **RELEASE_25** +* Release 2.4: **RELEASE_24** +* Release 2.3: **RELEASE_23** +* Release 2.2: **RELEASE_22** +* Release 2.1: **RELEASE_21** +* Release 2.0: **RELEASE_20** +* Release 1.9: **RELEASE_19** +* Release 1.8: **RELEASE_18** +* Release 1.7: **RELEASE_17** +* Release 1.6: **RELEASE_16** +* Release 1.5: **RELEASE_15** +* Release 1.4: **RELEASE_14** +* Release 1.3: **RELEASE_13** +* Release 1.2: **RELEASE_12** +* Release 1.1: **RELEASE_11** +* Release 1.0: **RELEASE_1** + +If you would like to get the LLVM test suite (a separate package as of 1.4), you +get it from the Subversion repository: + +.. code-block:: bash + + % cd llvm/projects + % svn co http://llvm.org/svn/llvm-project/test-suite/trunk test-suite + +By placing it in the ``llvm/projects``, it will be automatically configured by +the LLVM configure script as well as automatically updated when you run ``svn +update``. + +GIT mirror +---------- + +GIT mirrors are available for a number of LLVM subprojects. These mirrors sync +automatically with each Subversion commit and contain all necessary git-svn +marks (so, you can recreate git-svn metadata locally). Note that right now +mirrors reflect only ``trunk`` for each project. You can do the read-only GIT +clone of LLVM via: + +.. code-block:: bash + + % git clone http://llvm.org/git/llvm.git + +If you want to check out clang too, run: + +.. code-block:: bash + + % git clone http://llvm.org/git/llvm.git + % cd llvm/tools + % git clone http://llvm.org/git/clang.git + +Since the upstream repository is in Subversion, you should use ``git +pull --rebase`` instead of ``git pull`` to avoid generating a non-linear history +in your clone. To configure ``git pull`` to pass ``--rebase`` by default on the +master branch, run the following command: + +.. code-block:: bash + + % git config branch.master.rebase true + +Sending patches with Git +^^^^^^^^^^^^^^^^^^^^^^^^ + +Please read `Developer Policy <DeveloperPolicy.html#one-off-patches>`_, too. + +Assume ``master`` points the upstream and ``mybranch`` points your working +branch, and ``mybranch`` is rebased onto ``master``. At first you may check +sanity of whitespaces: + +.. code-block:: bash + + % git diff --check master..mybranch + +The easiest way to generate a patch is as below: + +.. code-block:: bash + + % git diff master..mybranch > /path/to/mybranch.diff + +It is a little different from svn-generated diff. git-diff-generated diff has +prefixes like ``a/`` and ``b/``. Don't worry, most developers might know it +could be accepted with ``patch -p1 -N``. + +But you may generate patchset with git-format-patch. It generates by-each-commit +patchset. To generate patch files to attach to your article: + +.. code-block:: bash + + % git format-patch --no-attach master..mybranch -o /path/to/your/patchset + +If you would like to send patches directly, you may use git-send-email or +git-imap-send. Here is an example to generate the patchset in Gmail's [Drafts]. + +.. code-block:: bash + + % git format-patch --attach master..mybranch --stdout | git imap-send + +Then, your .git/config should have [imap] sections. + +.. code-block:: bash + + [imap] + host = imaps://imap.gmail.com + user = your.gmail.account@gmail.com + pass = himitsu! + port = 993 + sslverify = false + ; in English + folder = "[Gmail]/Drafts" + ; example for Japanese, "Modified UTF-7" encoded. + folder = "[Gmail]/&Tgtm+DBN-" + ; example for Traditional Chinese + folder = "[Gmail]/&g0l6Pw-" + +For developers to work with git-svn +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +To set up clone from which you can submit code using ``git-svn``, run: + +.. code-block:: bash + + % git clone http://llvm.org/git/llvm.git + % cd llvm + % git svn init https://llvm.org/svn/llvm-project/llvm/trunk --username=<username> + % git config svn-remote.svn.fetch :refs/remotes/origin/master + % git svn rebase -l # -l avoids fetching ahead of the git mirror. + + # If you have clang too: + % cd tools + % git clone http://llvm.org/git/clang.git + % cd clang + % git svn init https://llvm.org/svn/llvm-project/cfe/trunk --username=<username> + % git config svn-remote.svn.fetch :refs/remotes/origin/master + % git svn rebase -l + +To update this clone without generating git-svn tags that conflict with the +upstream git repo, run: + +.. code-block:: bash + + % git fetch && (cd tools/clang && git fetch) # Get matching revisions of both trees. + % git checkout master + % git svn rebase -l + % (cd tools/clang && + git checkout master && + git svn rebase -l) + +This leaves your working directories on their master branches, so you'll need to +``checkout`` each working branch individually and ``rebase`` it on top of its +parent branch. (Note: This script is intended for relative newbies to git. If +you have more experience, you can likely improve on it.) + +The git-svn metadata can get out of sync after you mess around with branches and +``dcommit``. When that happens, ``git svn dcommit`` stops working, complaining +about files with uncommitted changes. The fix is to rebuild the metadata: + +.. code-block:: bash + + % rm -rf .git/svn + % git svn rebase -l + +Local LLVM Configuration +------------------------ + +Once checked out from the Subversion repository, the LLVM suite source code must +be configured via the ``configure`` script. This script sets variables in the +various ``*.in`` files, most notably ``llvm/Makefile.config`` and +``llvm/include/Config/config.h``. It also populates *OBJ_ROOT* with the +Makefiles needed to begin building LLVM. + +The following environment variables are used by the ``configure`` script to +configure the build system: + ++------------+-----------------------------------------------------------+ +| Variable | Purpose | ++============+===========================================================+ +| CC | Tells ``configure`` which C compiler to use. By default, | +| | ``configure`` will look for the first GCC C compiler in | +| | ``PATH``. Use this variable to override ``configure``\'s | +| | default behavior. | ++------------+-----------------------------------------------------------+ +| CXX | Tells ``configure`` which C++ compiler to use. By | +| | default, ``configure`` will look for the first GCC C++ | +| | compiler in ``PATH``. Use this variable to override | +| | ``configure``'s default behavior. | ++------------+-----------------------------------------------------------+ + +The following options can be used to set or enable LLVM specific options: + +``--enable-optimized`` + + Enables optimized compilation (debugging symbols are removed and GCC + optimization flags are enabled). Note that this is the default setting if you + are using the LLVM distribution. The default behavior of an Subversion + checkout is to use an unoptimized build (also known as a debug build). + +``--enable-debug-runtime`` + + Enables debug symbols in the runtime libraries. The default is to strip debug + symbols from the runtime libraries. + +``--enable-jit`` + + Compile the Just In Time (JIT) compiler functionality. This is not available + on all platforms. The default is dependent on platform, so it is best to + explicitly enable it if you want it. + +``--enable-targets=target-option`` + + Controls which targets will be built and linked into llc. The default value + for ``target_options`` is "all" which builds and links all available targets. + The value "host-only" can be specified to build only a native compiler (no + cross-compiler targets available). The "native" target is selected as the + target of the build host. You can also specify a comma separated list of + target names that you want available in llc. The target names use all lower + case. The current set of targets is: + + ``arm, cpp, hexagon, mblaze, mips, mipsel, msp430, powerpc, ptx, sparc, spu, + x86, x86_64, xcore``. + +``--enable-doxygen`` + + Look for the doxygen program and enable construction of doxygen based + documentation from the source code. This is disabled by default because + generating the documentation can take a long time and producess 100s of + megabytes of output. + +``--with-udis86`` + + LLVM can use external disassembler library for various purposes (now it's used + only for examining code produced by JIT). This option will enable usage of + `udis86 <http://udis86.sourceforge.net/>`_ x86 (both 32 and 64 bits) + disassembler library. + +To configure LLVM, follow these steps: + +#. Change directory into the object root directory: + + .. code-block:: bash + + % cd OBJ_ROOT + +#. Run the ``configure`` script located in the LLVM source tree: + + .. code-block:: bash + + % SRC_ROOT/configure --prefix=/install/path [other options] + +Compiling the LLVM Suite Source Code +------------------------------------ + +Once you have configured LLVM, you can build it. There are three types of +builds: + +Debug Builds + + These builds are the default when one is using an Subversion checkout and + types ``gmake`` (unless the ``--enable-optimized`` option was used during + configuration). The build system will compile the tools and libraries with + debugging information. To get a Debug Build using the LLVM distribution the + ``--disable-optimized`` option must be passed to ``configure``. + +Release (Optimized) Builds + + These builds are enabled with the ``--enable-optimized`` option to + ``configure`` or by specifying ``ENABLE_OPTIMIZED=1`` on the ``gmake`` command + line. For these builds, the build system will compile the tools and libraries + with GCC optimizations enabled and strip debugging information from the + libraries and executables it generates. Note that Release Builds are default + when using an LLVM distribution. + +Profile Builds + + These builds are for use with profiling. They compile profiling information + into the code for use with programs like ``gprof``. Profile builds must be + started by specifying ``ENABLE_PROFILING=1`` on the ``gmake`` command line. + +Once you have LLVM configured, you can build it by entering the *OBJ_ROOT* +directory and issuing the following command: + +.. code-block:: bash + + % gmake + +If the build fails, please `check here`_ to see if you are using a version of +GCC that is known not to compile LLVM. + +If you have multiple processors in your machine, you may wish to use some of the +parallel build options provided by GNU Make. For example, you could use the +command: + +.. code-block:: bash + + % gmake -j2 + +There are several special targets which are useful when working with the LLVM +source code: + +``gmake clean`` + + Removes all files generated by the build. This includes object files, + generated C/C++ files, libraries, and executables. + +``gmake dist-clean`` + + Removes everything that ``gmake clean`` does, but also removes files generated + by ``configure``. It attempts to return the source tree to the original state + in which it was shipped. + +``gmake install`` + + Installs LLVM header files, libraries, tools, and documentation in a hierarchy + under ``$PREFIX``, specified with ``./configure --prefix=[dir]``, which + defaults to ``/usr/local``. + +``gmake -C runtime install-bytecode`` + + Assuming you built LLVM into $OBJDIR, when this command is run, it will + install bitcode libraries into the GCC front end's bitcode library directory. + If you need to update your bitcode libraries, this is the target to use once + you've built them. + +Please see the `Makefile Guide <MakefileGuide.html>`_ for further details on +these ``make`` targets and descriptions of other targets available. + +It is also possible to override default values from ``configure`` by declaring +variables on the command line. The following are some examples: + +``gmake ENABLE_OPTIMIZED=1`` + + Perform a Release (Optimized) build. + +``gmake ENABLE_OPTIMIZED=1 DISABLE_ASSERTIONS=1`` + + Perform a Release (Optimized) build without assertions enabled. + +``gmake ENABLE_OPTIMIZED=0`` + + Perform a Debug build. + +``gmake ENABLE_PROFILING=1`` + + Perform a Profiling build. + +``gmake VERBOSE=1`` + + Print what ``gmake`` is doing on standard output. + +``gmake TOOL_VERBOSE=1`` + + Ask each tool invoked by the makefiles to print out what it is doing on + the standard output. This also implies ``VERBOSE=1``. + +Every directory in the LLVM object tree includes a ``Makefile`` to build it and +any subdirectories that it contains. Entering any directory inside the LLVM +object tree and typing ``gmake`` should rebuild anything in or below that +directory that is out of date. + +Cross-Compiling LLVM +-------------------- + +It is possible to cross-compile LLVM itself. That is, you can create LLVM +executables and libraries to be hosted on a platform different from the platform +where they are build (a Canadian Cross build). To configure a cross-compile, +supply the configure script with ``--build`` and ``--host`` options that are +different. The values of these options must be legal target triples that your +GCC compiler supports. + +The result of such a build is executables that are not runnable on on the build +host (--build option) but can be executed on the compile host (--host option). + +The Location of LLVM Object Files +--------------------------------- + +The LLVM build system is capable of sharing a single LLVM source tree among +several LLVM builds. Hence, it is possible to build LLVM for several different +platforms or configurations using the same source tree. + +This is accomplished in the typical autoconf manner: + +* Change directory to where the LLVM object files should live: + + .. code-block:: bash + + % cd OBJ_ROOT + +* Run the ``configure`` script found in the LLVM source directory: + + .. code-block:: bash + + % SRC_ROOT/configure + +The LLVM build will place files underneath *OBJ_ROOT* in directories named after +the build type: + +Debug Builds with assertions enabled (the default) + + Tools + + ``OBJ_ROOT/Debug+Asserts/bin`` + + Libraries + + ``OBJ_ROOT/Debug+Asserts/lib`` + +Release Builds + + Tools + + ``OBJ_ROOT/Release/bin`` + + Libraries + + ``OBJ_ROOT/Release/lib`` + +Profile Builds + + Tools + + ``OBJ_ROOT/Profile/bin`` + + Libraries + + ``OBJ_ROOT/Profile/lib`` + +Optional Configuration Items +---------------------------- + +If you're running on a Linux system that supports the `binfmt_misc +<http://www.tat.physik.uni-tuebingen.de/~rguenth/linux/binfmt_misc.html>`_ +module, and you have root access on the system, you can set your system up to +execute LLVM bitcode files directly. To do this, use commands like this (the +first command may not be required if you are already using the module): + +.. code-block:: bash + + % mount -t binfmt_misc none /proc/sys/fs/binfmt_misc + % echo ':llvm:M::BC::/path/to/lli:' > /proc/sys/fs/binfmt_misc/register + % chmod u+x hello.bc (if needed) + % ./hello.bc + +This allows you to execute LLVM bitcode files directly. On Debian, you can also +use this command instead of the 'echo' command above: + +.. code-block:: bash + + % sudo update-binfmts --install llvm /path/to/lli --magic 'BC' + +.. _Program Layout: +.. _general layout: + +Program Layout +============== + +One useful source of information about the LLVM source base is the LLVM `doxygen +<http://www.doxygen.org/>`_ documentation available at +`<http://llvm.org/doxygen/>`_. The following is a brief introduction to code +layout: + +``llvm/examples`` +----------------- + +This directory contains some simple examples of how to use the LLVM IR and JIT. + +``llvm/include`` +---------------- + +This directory contains public header files exported from the LLVM library. The +three main subdirectories of this directory are: + +``llvm/include/llvm`` + + This directory contains all of the LLVM specific header files. This directory + also has subdirectories for different portions of LLVM: ``Analysis``, + ``CodeGen``, ``Target``, ``Transforms``, etc... + +``llvm/include/llvm/Support`` + + This directory contains generic support libraries that are provided with LLVM + but not necessarily specific to LLVM. For example, some C++ STL utilities and + a Command Line option processing library store their header files here. + +``llvm/include/llvm/Config`` + + This directory contains header files configured by the ``configure`` script. + They wrap "standard" UNIX and C header files. Source code can include these + header files which automatically take care of the conditional #includes that + the ``configure`` script generates. + +``llvm/lib`` +------------ + +This directory contains most of the source files of the LLVM system. In LLVM, +almost all code exists in libraries, making it very easy to share code among the +different `tools`_. + +``llvm/lib/VMCore/`` + + This directory holds the core LLVM source files that implement core classes + like Instruction and BasicBlock. + +``llvm/lib/AsmParser/`` + + This directory holds the source code for the LLVM assembly language parser + library. + +``llvm/lib/BitCode/`` + + This directory holds code for reading and write LLVM bitcode. + +``llvm/lib/Analysis/`` + + This directory contains a variety of different program analyses, such as + Dominator Information, Call Graphs, Induction Variables, Interval + Identification, Natural Loop Identification, etc. + +``llvm/lib/Transforms/`` + + This directory contains the source code for the LLVM to LLVM program + transformations, such as Aggressive Dead Code Elimination, Sparse Conditional + Constant Propagation, Inlining, Loop Invariant Code Motion, Dead Global + Elimination, and many others. + +``llvm/lib/Target/`` + + This directory contains files that describe various target architectures for + code generation. For example, the ``llvm/lib/Target/X86`` directory holds the + X86 machine description while ``llvm/lib/Target/ARM`` implements the ARM + backend. + +``llvm/lib/CodeGen/`` + + This directory contains the major parts of the code generator: Instruction + Selector, Instruction Scheduling, and Register Allocation. + +``llvm/lib/MC/`` + + (FIXME: T.B.D.) + +``llvm/lib/Debugger/`` + + This directory contains the source level debugger library that makes it + possible to instrument LLVM programs so that a debugger could identify source + code locations at which the program is executing. + +``llvm/lib/ExecutionEngine/`` + + This directory contains libraries for executing LLVM bitcode directly at + runtime in both interpreted and JIT compiled fashions. + +``llvm/lib/Support/`` + + This directory contains the source code that corresponds to the header files + located in ``llvm/include/ADT/`` and ``llvm/include/Support/``. + +``llvm/projects`` +----------------- + +This directory contains projects that are not strictly part of LLVM but are +shipped with LLVM. This is also the directory where you should create your own +LLVM-based projects. See ``llvm/projects/sample`` for an example of how to set +up your own project. + +``llvm/runtime`` +---------------- + +This directory contains libraries which are compiled into LLVM bitcode and used +when linking programs with the Clang front end. Most of these libraries are +skeleton versions of real libraries; for example, libc is a stripped down +version of glibc. + +Unlike the rest of the LLVM suite, this directory needs the LLVM GCC front end +to compile. + +``llvm/test`` +------------- + +This directory contains feature and regression tests and other basic sanity +checks on the LLVM infrastructure. These are intended to run quickly and cover a +lot of territory without being exhaustive. + +``test-suite`` +-------------- + +This is not a directory in the normal llvm module; it is a separate Subversion +module that must be checked out (usually to ``projects/test-suite``). This +module contains a comprehensive correctness, performance, and benchmarking test +suite for LLVM. It is a separate Subversion module because not every LLVM user +is interested in downloading or building such a comprehensive test suite. For +further details on this test suite, please see the `Testing +Guide <TestingGuide.html>`_ document. + +.. _tools: + +``llvm/tools`` +-------------- + +The **tools** directory contains the executables built out of the libraries +above, which form the main part of the user interface. You can always get help +for a tool by typing ``tool_name -help``. The following is a brief introduction +to the most important tools. More detailed information is in +the `Command Guide <CommandGuide/index.html>`_. + +``bugpoint`` + + ``bugpoint`` is used to debug optimization passes or code generation backends + by narrowing down the given test case to the minimum number of passes and/or + instructions that still cause a problem, whether it is a crash or + miscompilation. See `<HowToSubmitABug.html>`_ for more information on using + ``bugpoint``. + +``llvm-ar`` + + The archiver produces an archive containing the given LLVM bitcode files, + optionally with an index for faster lookup. + +``llvm-as`` + + The assembler transforms the human readable LLVM assembly to LLVM bitcode. + +``llvm-dis`` + + The disassembler transforms the LLVM bitcode to human readable LLVM assembly. + +``llvm-link`` + + ``llvm-link``, not surprisingly, links multiple LLVM modules into a single + program. + +``lli`` + + ``lli`` is the LLVM interpreter, which can directly execute LLVM bitcode + (although very slowly...). For architectures that support it (currently x86, + Sparc, and PowerPC), by default, ``lli`` will function as a Just-In-Time + compiler (if the functionality was compiled in), and will execute the code + *much* faster than the interpreter. + +``llc`` + + ``llc`` is the LLVM backend compiler, which translates LLVM bitcode to a + native code assembly file or to C code (with the ``-march=c`` option). + +``opt`` + + ``opt`` reads LLVM bitcode, applies a series of LLVM to LLVM transformations + (which are specified on the command line), and then outputs the resultant + bitcode. The '``opt -help``' command is a good way to get a list of the + program transformations available in LLVM. + + ``opt`` can also be used to run a specific analysis on an input LLVM bitcode + file and print out the results. It is primarily useful for debugging + analyses, or familiarizing yourself with what an analysis does. + +``llvm/utils`` +-------------- + +This directory contains utilities for working with LLVM source code, and some of +the utilities are actually required as part of the build process because they +are code generators for parts of LLVM infrastructure. + + +``codegen-diff`` + + ``codegen-diff`` is a script that finds differences between code that LLC + generates and code that LLI generates. This is a useful tool if you are + debugging one of them, assuming that the other generates correct output. For + the full user manual, run ```perldoc codegen-diff'``. + +``emacs/`` + + The ``emacs`` directory contains syntax-highlighting files which will work + with Emacs and XEmacs editors, providing syntax highlighting support for LLVM + assembly files and TableGen description files. For information on how to use + the syntax files, consult the ``README`` file in that directory. + +``getsrcs.sh`` + + The ``getsrcs.sh`` script finds and outputs all non-generated source files, + which is useful if one wishes to do a lot of development across directories + and does not want to individually find each file. One way to use it is to run, + for example: ``xemacs `utils/getsources.sh``` from the top of your LLVM source + tree. + +``llvmgrep`` + + This little tool performs an ``egrep -H -n`` on each source file in LLVM and + passes to it a regular expression provided on ``llvmgrep``'s command + line. This is a very efficient way of searching the source base for a + particular regular expression. + +``makellvm`` + + The ``makellvm`` script compiles all files in the current directory and then + compiles and links the tool that is the first argument. For example, assuming + you are in the directory ``llvm/lib/Target/Sparc``, if ``makellvm`` is in your + path, simply running ``makellvm llc`` will make a build of the current + directory, switch to directory ``llvm/tools/llc`` and build it, causing a + re-linking of LLC. + +``TableGen/`` + + The ``TableGen`` directory contains the tool used to generate register + descriptions, instruction set descriptions, and even assemblers from common + TableGen description files. + +``vim/`` + + The ``vim`` directory contains syntax-highlighting files which will work with + the VIM editor, providing syntax highlighting support for LLVM assembly files + and TableGen description files. For information on how to use the syntax + files, consult the ``README`` file in that directory. + +.. _simple example: + +An Example Using the LLVM Tool Chain +==================================== + +This section gives an example of using LLVM with the Clang front end. + +Example with clang +------------------ + +#. First, create a simple C file, name it 'hello.c': + + .. code-block:: c + + #include <stdio.h> + + int main() { + printf("hello world\n"); + return 0; + } + +#. Next, compile the C file into a native executable: + + .. code-block:: bash + + % clang hello.c -o hello + + .. note:: + + Clang works just like GCC by default. The standard -S and -c arguments + work as usual (producing a native .s or .o file, respectively). + +#. Next, compile the C file into a LLVM bitcode file: + + .. code-block:: bash + + % clang -O3 -emit-llvm hello.c -c -o hello.bc + + The -emit-llvm option can be used with the -S or -c options to emit an LLVM + ``.ll`` or ``.bc`` file (respectively) for the code. This allows you to use + the `standard LLVM tools <CommandGuide/index.html>`_ on the bitcode file. + +#. Run the program in both forms. To run the program, use: + + .. code-block:: bash + + % ./hello + + and + + .. code-block:: bash + + % lli hello.bc + + The second examples shows how to invoke the LLVM JIT, `lli + <CommandGuide/html/lli.html>`_. + +#. Use the ``llvm-dis`` utility to take a look at the LLVM assembly code: + + .. code-block:: bash + + % llvm-dis < hello.bc | less + +#. Compile the program to native assembly using the LLC code generator: + + .. code-block:: bash + + % llc hello.bc -o hello.s + +#. Assemble the native assembly language file into a program: + + .. code-block:: bash + + **Solaris:** % /opt/SUNWspro/bin/cc -xarch=v9 hello.s -o hello.native + + **Others:** % gcc hello.s -o hello.native + +#. Execute the native code program: + + .. code-block:: bash + + % ./hello.native + + Note that using clang to compile directly to native code (i.e. when the + ``-emit-llvm`` option is not present) does steps 6/7/8 for you. + +Common Problems +=============== + +If you are having problems building or using LLVM, or if you have any other +general questions about LLVM, please consult the `Frequently Asked +Questions <FAQ.html>`_ page. + +.. _links: + +Links +===== + +This document is just an **introduction** on how to use LLVM to do some simple +things... there are many more interesting and complicated things that you can do +that aren't documented here (but we'll gladly accept a patch if you want to +write something up!). For more information about LLVM, check out: + +* `LLVM Homepage <http://llvm.org/>`_ +* `LLVM Doxygen Tree <http://llvm.org/doxygen/>`_ +* `Starting a Project that Uses LLVM <http://llvm.org/docs/Projects.html>`_ diff --git a/docs/GoldPlugin.html b/docs/GoldPlugin.html deleted file mode 100644 index 1e99a5a..0000000 --- a/docs/GoldPlugin.html +++ /dev/null @@ -1,227 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" - "http://www.w3.org/TR/html4/strict.dtd"> -<html> -<head> - <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> - <title>LLVM gold plugin</title> - <link rel="stylesheet" href="_static/llvm.css" type="text/css"> -</head> -<body> - -<h1>LLVM gold plugin</h1> -<ol> - <li><a href="#introduction">Introduction</a></li> - <li><a href="#build">How to build it</a></li> - <li><a href="#usage">Usage</a> - <ul> - <li><a href="#example1">Example of link time optimization</a></li> - <li><a href="#lto_autotools">Quickstart for using LTO with autotooled projects</a></li> - </ul></li> - <li><a href="#licensing">Licensing</a></li> -</ol> -<div class="doc_author">Written by Nick Lewycky</div> - -<!--=========================================================================--> -<h2><a name="introduction">Introduction</a></h2> -<!--=========================================================================--> -<div> - <p>Building with link time optimization requires cooperation from the -system linker. LTO support on Linux systems requires that you use -the <a href="http://sourceware.org/binutils">gold linker</a> which supports -LTO via plugins. This is the same mechanism used by the -<a href="http://gcc.gnu.org/wiki/LinkTimeOptimization">GCC LTO</a> -project.</p> - <p>The LLVM gold plugin implements the -<a href="http://gcc.gnu.org/wiki/whopr/driver">gold plugin interface</a> -on top of -<a href="LinkTimeOptimization.html#lto">libLTO</a>. -The same plugin can also be used by other tools such as <tt>ar</tt> and -<tt>nm</tt>. -</div> -<!--=========================================================================--> -<h2><a name="build">How to build it</a></h2> -<!--=========================================================================--> -<div> - <p>You need to have gold with plugin support and build the LLVMgold -plugin. Check whether you have gold running <tt>/usr/bin/ld -v</tt>. It will -report “GNU gold” or else “GNU ld” if not. If you have -gold, check for plugin support by running <tt>/usr/bin/ld -plugin</tt>. If it -complains “missing argument” then you have plugin support. If not, -such as an “unknown option” error then you will either need to -build gold or install a version with plugin support.</p> -<ul> - <li>To build gold with plugin support: - <pre class="doc_code"> -mkdir binutils -cd binutils -cvs -z 9 -d :pserver:anoncvs@sourceware.org:/cvs/src login -<em>{enter "anoncvs" as the password}</em> -cvs -z 9 -d :pserver:anoncvs@sourceware.org:/cvs/src co binutils -mkdir build -cd build -../src/configure --enable-gold --enable-plugins -make all-gold -</pre> - That should leave you with <tt>binutils/build/gold/ld-new</tt> which supports the <tt>-plugin</tt> option. It also built would have -<tt>binutils/build/binutils/ar</tt> and <tt>nm-new</tt> which support plugins -but don't have a visible -plugin option, instead relying on the gold plugin -being present in <tt>../lib/bfd-plugins</tt> relative to where the binaries are -placed. - <li>Build the LLVMgold plugin: Configure LLVM with - <tt>--with-binutils-include=/path/to/binutils/src/include</tt> and run - <tt>make</tt>. -</ul> -</div> -<!--=========================================================================--> -<h2><a name="usage">Usage</a></h2> -<!--=========================================================================--> -<div> - - <p>The linker takes a <tt>-plugin</tt> option that points to the path of - the plugin <tt>.so</tt> file. To find out what link command <tt>gcc</tt> - would run in a given situation, run <tt>gcc -v <em>[...]</em></tt> and look - for the line where it runs <tt>collect2</tt>. Replace that with - <tt>ld-new -plugin /path/to/LLVMgold.so</tt> to test it out. Once you're - ready to switch to using gold, backup your existing <tt>/usr/bin/ld</tt> - then replace it with <tt>ld-new</tt>.</p> - - <p>You can produce bitcode files from <tt>clang</tt> using - <tt>-emit-llvm</tt> or <tt>-flto</tt>, or the <tt>-O4</tt> flag which is - synonymous with <tt>-O3 -flto</tt>.</p> - - <p>Any of these flags will also cause <tt>clang</tt> to look for the - gold plugin in the <tt>lib</tt> directory under its prefix and pass the - <tt>-plugin</tt> option to <tt>ld</tt>. It will not look for an alternate - linker, which is why you need gold to be the installed system linker in - your path.</p> - - <p>If you want <tt>ar</tt> and <tt>nm</tt> to work seamlessly as well, install - <tt>LLVMgold.so</tt> to <tt>/usr/lib/bfd-plugins</tt>. If you built your - own gold, be sure to install the <tt>ar</tt> and <tt>nm-new</tt> you built to - <tt>/usr/bin</tt>.<p> - -<!-- ======================================================================= --> -<h3> - <a name="example1">Example of link time optimization</a> -</h3> - -<div> - <p>The following example shows a worked example of the gold plugin mixing - LLVM bitcode and native code. -<pre class="doc_code"> ---- a.c --- -#include <stdio.h> - -extern void foo1(void); -extern void foo4(void); - -void foo2(void) { - printf("Foo2\n"); -} - -void foo3(void) { - foo4(); -} - -int main(void) { - foo1(); -} - ---- b.c --- -#include <stdio.h> - -extern void foo2(void); - -void foo1(void) { - foo2(); -} - -void foo4(void) { - printf("Foo4"); -} - ---- command lines --- -$ clang -flto a.c -c -o a.o # <-- a.o is LLVM bitcode file -$ ar q a.a a.o # <-- a.a is an archive with LLVM bitcode -$ clang b.c -c -o b.o # <-- b.o is native object file -$ clang -flto a.a b.o -o main # <-- link with LLVMgold plugin -</pre> - - <p>Gold informs the plugin that foo3 is never referenced outside the IR, - leading LLVM to delete that function. However, unlike in the - <a href="LinkTimeOptimization.html#example1">libLTO - example</a> gold does not currently eliminate foo4.</p> -</div> - -</div> - -<!--=========================================================================--> -<h2> - <a name="lto_autotools"> - Quickstart for using LTO with autotooled projects - </a> -</h2> -<!--=========================================================================--> -<div> - <p>Once your system <tt>ld</tt>, <tt>ar</tt>, and <tt>nm</tt> all support LLVM - bitcode, everything is in place for an easy to use LTO build of autotooled - projects:</p> - - <ul> - <li>Follow the instructions <a href="#build">on how to build LLVMgold.so</a>.</li> - <li>Install the newly built binutils to <tt>$PREFIX</tt></li> - <li>Copy <tt>Release/lib/LLVMgold.so</tt> to - <tt>$PREFIX/lib/bfd-plugins/</tt></li> - <li>Set environment variables (<tt>$PREFIX</tt> is where you installed clang and - binutils): -<pre class="doc_code"> -export CC="$PREFIX/bin/clang -flto" -export CXX="$PREFIX/bin/clang++ -flto" -export AR="$PREFIX/bin/ar" -export NM="$PREFIX/bin/nm" -export RANLIB=/bin/true #ranlib is not needed, and doesn't support .bc files in .a -export CFLAGS="-O4" -</pre> - </li> - <li>Or you can just set your path: -<pre class="doc_code"> -export PATH="$PREFIX/bin:$PATH" -export CC="clang -flto" -export CXX="clang++ -flto" -export RANLIB=/bin/true -export CFLAGS="-O4" -</pre></li> - <li>Configure & build the project as usual: -<pre class="doc_code"> -% ./configure && make && make check -</pre></li> - </ul> - - <p>The environment variable settings may work for non-autotooled projects - too, but you may need to set the <tt>LD</tt> environment variable as - well.</p> -</div> - -<!--=========================================================================--> -<h2><a name="licensing">Licensing</a></h2> -<!--=========================================================================--> -<div> - <p>Gold is licensed under the GPLv3. LLVMgold uses the interface file -<tt>plugin-api.h</tt> from gold which means that the resulting LLVMgold.so -binary is also GPLv3. This can still be used to link non-GPLv3 programs just -as much as gold could without the plugin.</p> -</div> - -<!-- *********************************************************************** --> -<hr> -<address> - <a href="http://jigsaw.w3.org/css-validator/check/referer"><img - src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS"></a> - <a href="http://validator.w3.org/check/referer"><img - src="http://www.w3.org/Icons/valid-html401-blue" alt="Valid HTML 4.01"></a> - <a href="mailto:nicholas@metrix.on.ca">Nick Lewycky</a><br> - <a href="http://llvm.org/">The LLVM Compiler Infrastructure</a><br> - Last modified: $Date: 2010-04-16 23:58:21 -0800 (Fri, 16 Apr 2010) $ -</address> -</body> -</html> diff --git a/docs/GoldPlugin.rst b/docs/GoldPlugin.rst new file mode 100644 index 0000000..300aea9 --- /dev/null +++ b/docs/GoldPlugin.rst @@ -0,0 +1,186 @@ +.. _gold-plugin: + +==================== +The LLVM gold plugin +==================== + +.. sectionauthor:: Nick Lewycky + +Introduction +============ + +Building with link time optimization requires cooperation from +the system linker. LTO support on Linux systems requires that you use the +`gold linker`_ which supports LTO via plugins. This is the same mechanism +used by the `GCC LTO`_ project. + +The LLVM gold plugin implements the gold plugin interface on top of +:ref:`libLTO`. The same plugin can also be used by other tools such as +``ar`` and ``nm``. + +.. _`gold linker`: http://sourceware.org/binutils +.. _`GCC LTO`: http://gcc.gnu.org/wiki/LinkTimeOptimization +.. _`gold plugin interface`: http://gcc.gnu.org/wiki/whopr/driver + +.. _lto-how-to-build: + +How to build it +=============== + +You need to have gold with plugin support and build the LLVMgold plugin. +Check whether you have gold running ``/usr/bin/ld -v``. It will report "GNU +gold" or else "GNU ld" if not. If you have gold, check for plugin support +by running ``/usr/bin/ld -plugin``. If it complains "missing argument" then +you have plugin support. If not, such as an "unknown option" error then you +will either need to build gold or install a version with plugin support. + +* To build gold with plugin support: + + .. code-block:: bash + + $ mkdir binutils + $ cd binutils + $ cvs -z 9 -d :pserver:anoncvs@sourceware.org:/cvs/src login + {enter "anoncvs" as the password} + $ cvs -z 9 -d :pserver:anoncvs@sourceware.org:/cvs/src co binutils + $ mkdir build + $ cd build + $ ../src/configure --enable-gold --enable-plugins + $ make all-gold + + That should leave you with ``binutils/build/gold/ld-new`` which supports + the ``-plugin`` option. It also built would have + ``binutils/build/binutils/ar`` and ``nm-new`` which support plugins but + don't have a visible -plugin option, instead relying on the gold plugin + being present in ``../lib/bfd-plugins`` relative to where the binaries + are placed. + +* Build the LLVMgold plugin: Configure LLVM with + ``--with-binutils-include=/path/to/binutils/src/include`` and run + ``make``. + +Usage +===== + +The linker takes a ``-plugin`` option that points to the path of +the plugin ``.so`` file. To find out what link command ``gcc`` +would run in a given situation, run ``gcc -v [...]`` and +look for the line where it runs ``collect2``. Replace that with +``ld-new -plugin /path/to/LLVMgold.so`` to test it out. Once you're +ready to switch to using gold, backup your existing ``/usr/bin/ld`` +then replace it with ``ld-new``. + +You can produce bitcode files from ``clang`` using ``-emit-llvm`` or +``-flto``, or the ``-O4`` flag which is synonymous with ``-O3 -flto``. + +Any of these flags will also cause ``clang`` to look for the gold plugin in +the ``lib`` directory under its prefix and pass the ``-plugin`` option to +``ld``. It will not look for an alternate linker, which is why you need +gold to be the installed system linker in your path. + +If you want ``ar`` and ``nm`` to work seamlessly as well, install +``LLVMgold.so`` to ``/usr/lib/bfd-plugins``. If you built your own gold, be +sure to install the ``ar`` and ``nm-new`` you built to ``/usr/bin``. + + +Example of link time optimization +--------------------------------- + +The following example shows a worked example of the gold plugin mixing LLVM +bitcode and native code. + +.. code-block:: c + + --- a.c --- + #include <stdio.h> + + extern void foo1(void); + extern void foo4(void); + + void foo2(void) { + printf("Foo2\n"); + } + + void foo3(void) { + foo4(); + } + + int main(void) { + foo1(); + } + + --- b.c --- + #include <stdio.h> + + extern void foo2(void); + + void foo1(void) { + foo2(); + } + + void foo4(void) { + printf("Foo4"); + } + +.. code-block:: bash + + --- command lines --- + $ clang -flto a.c -c -o a.o # <-- a.o is LLVM bitcode file + $ ar q a.a a.o # <-- a.a is an archive with LLVM bitcode + $ clang b.c -c -o b.o # <-- b.o is native object file + $ clang -flto a.a b.o -o main # <-- link with LLVMgold plugin + +Gold informs the plugin that foo3 is never referenced outside the IR, +leading LLVM to delete that function. However, unlike in the :ref:`libLTO +example <libLTO-example>` gold does not currently eliminate foo4. + +Quickstart for using LTO with autotooled projects +================================================= + +Once your system ``ld``, ``ar``, and ``nm`` all support LLVM bitcode, +everything is in place for an easy to use LTO build of autotooled projects: + +* Follow the instructions :ref:`on how to build LLVMgold.so + <lto-how-to-build>`. + +* Install the newly built binutils to ``$PREFIX`` + +* Copy ``Release/lib/LLVMgold.so`` to ``$PREFIX/lib/bfd-plugins/`` + +* Set environment variables (``$PREFIX`` is where you installed clang and + binutils): + + .. code-block:: bash + + export CC="$PREFIX/bin/clang -flto" + export CXX="$PREFIX/bin/clang++ -flto" + export AR="$PREFIX/bin/ar" + export NM="$PREFIX/bin/nm" + export RANLIB=/bin/true #ranlib is not needed, and doesn't support .bc files in .a + export CFLAGS="-O4" + +* Or you can just set your path: + + .. code-block:: bash + + export PATH="$PREFIX/bin:$PATH" + export CC="clang -flto" + export CXX="clang++ -flto" + export RANLIB=/bin/true + export CFLAGS="-O4" +* Configure and build the project as usual: + + .. code-block:: bash + + % ./configure && make && make check + +The environment variable settings may work for non-autotooled projects too, +but you may need to set the ``LD`` environment variable as well. + +Licensing +========= + +Gold is licensed under the GPLv3. LLVMgold uses the interface file +``plugin-api.h`` from gold which means that the resulting ``LLVMgold.so`` +binary is also GPLv3. This can still be used to link non-GPLv3 programs +just as much as gold could without the plugin. diff --git a/docs/HowToAddABuilder.html b/docs/HowToAddABuilder.html deleted file mode 100644 index 985b30e..0000000 --- a/docs/HowToAddABuilder.html +++ /dev/null @@ -1,142 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" - "http://www.w3.org/TR/html4/strict.dtd"> -<html> -<head> - <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> - <title> - How To Add Your Build Configuration To LLVM Buildbot Infrastructure - </title> - <link rel="stylesheet" href="_static/llvm.css" type="text/css"> -</head> -<body> - -<h1>How To Add Your Build Configuration To LLVM Buildbot Infrastructure</h1> -<ol> - <li><a href="#introduction">Introduction</a></li> - <li><a href="#steps">Steps To Add Builder To LLVM Buildbot</a></li> -</ol> -<div class="doc_author"> - <p>Written by <a href="mailto:gkistanova@gmail.com">Galina Kistanova</a></p> -</div> - -<!-- *********************************************************************** --> -<h2><a name="introduction">Introduction</a></h2> -<!-- *********************************************************************** --> - -<div> - -<p>This document contains information about adding a build configuration and - buildslave to private slave builder to LLVM Buildbot Infrastructure - <a href="http://lab.llvm.org:8011">http://lab.llvm.org:8011</a></p> - -</div> - -<!-- *********************************************************************** --> -<h2><a name="steps">Steps To Add Builder To LLVM Buildbot</a></h2> -<!-- *********************************************************************** --> - -<div> - -<p>Volunteers can provide their build machines to work as build slaves to - public LLVM Buildbot.</p> - -<p>Here are the steps you can follow to do so:</p> - -<ol> - <li><p>Check the existing build configurations to make sure the one you are - interested in is not covered yet or gets built on your computer much - faster than on the existing one. We prefer faster builds so developers - will get feedback sooner after changes get committed.</p></li> - - <li><p>The computer you will be registering with the LLVM buildbot - infrastructure should have all dependencies installed and you can - actually build your configuration successfully. Please check what degree - of parallelism (-j param) would give the fastest build. - You can build multiple configurations on one computer.</p></li> - - <li><p>Install buildslave (currently we are using buildbot version 0.8.5). - Depending on the platform, buildslave could be available to download and - install with your packet manager, or you can download it directly from - <a href="http://trac.buildbot.net">http://trac.buildbot.net</a> and - install it manually.</p></li> - - <li><p>Create a designated user account, your buildslave will be running - under, and set appropriate permissions.</p></li> - - <li><p>Choose the buildslave root directory (all builds will be placed under - it), buildslave access name and password the build master will be using - to authenticate your buildslave.</p></li> - - <li><p>Create a buildslave in context of that buildslave account. - Point it to the <b>lab.llvm.org</b> port <b>9990</b> (see - <a href="http://buildbot.net/buildbot/docs/current/full.html#creating-a-slave"> - Buildbot documentation, Creating a slave</a> - for more details) by running the following command:</p> - -<div class="doc_code"> -<pre> -$ buildslave create-slave <i>buildslave-root-directory</i> \ - lab.llvm.org:9990 \ - <i>buildslave-access-name buildslave-access-password</i> -</pre> -</div></li> - - <li><p>Fill the buildslave description and admin name/e-mail. - Here is an example of the buildslave description:</p> - -<div class="doc_code"> -<pre> -Windows 7 x64 -Core i7 (2.66GHz), 16GB of RAM - -g++.exe (TDM-1 mingw32) 4.4.0 -GNU Binutils 2.19.1 -cmake version 2.8.4 -Microsoft(R) 32-bit C/C++ Optimizing Compiler Version 16.00.40219.01 for 80x86 -</pre> -</div></li> - - <li><p>Make sure you can actually start the buildslave successfully. Then set - up your buildslave to start automatically at the start up time. - See the buildbot documentation for help. - You may want to restart your computer to see if it works.</p></li> - - <li><p>Send a patch which adds your build slave and your builder to zorg.</p> - <ul> - <li>slaves are added to - <tt>buildbot/osuosl/master/config/slaves.py</tt></li> - <li>builders are added to - <tt>buildbot/osuosl/master/config/builders.py</tt></li> - </ul></li> - - <li><p>Send the buildslave access name and the access password directly - to <a href="mailto:gkistanova@gmail.com">Galina Kistanova</a>, and wait - till she will let you know that your changes are applied and buildmaster - is reconfigured.</p> - - <li><p>Check the status of your buildslave on the - <a href="http://lab.llvm.org:8011/waterfall">Waterfall Display</a> - to make sure it is connected, and - <a href="http://lab.llvm.org:8011/buildslaves/your-buildslave-name"> - http://lab.llvm.org:8011/buildslaves/<your-buildslave-name></a> - to see if administrator contact and slave information are correct.</p> - </li> - - <li><p>Wait for the first build to succeed and enjoy.</p></li> -</ol> - -</div> - -<!-- *********************************************************************** --> -<hr> -<address> - <a href="http://jigsaw.w3.org/css-validator/check/referer"><img - src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS"></a> - <a href="http://validator.w3.org/check/referer"><img - src="http://www.w3.org/Icons/valid-html401-blue" alt="Valid HTML 4.01"></a> - <a href="http://llvm.org/">The LLVM Compiler Infrastructure</a> - <br> - Last modified: $Date: 2011-10-31 12:50:0 -0700 (Mon, 31 Oct 2011) $ -</address> -</body> -</html> diff --git a/docs/HowToAddABuilder.rst b/docs/HowToAddABuilder.rst new file mode 100644 index 0000000..b0cd290 --- /dev/null +++ b/docs/HowToAddABuilder.rst @@ -0,0 +1,90 @@ +.. _how_to_add_a_builder: + +=================================================================== +How To Add Your Build Configuration To LLVM Buildbot Infrastructure +=================================================================== + +.. sectionauthor:: Galina Kistanova <gkistanova@gmail.com> + +Introduction +============ + +This document contains information about adding a build configuration and +buildslave to private slave builder to LLVM Buildbot Infrastructure +`<http://lab.llvm.org:8011>`_. + + +Steps To Add Builder To LLVM Buildbot +===================================== +Volunteers can provide their build machines to work as build slaves to +public LLVM Buildbot. + +Here are the steps you can follow to do so: + +#. Check the existing build configurations to make sure the one you are + interested in is not covered yet or gets built on your computer much + faster than on the existing one. We prefer faster builds so developers + will get feedback sooner after changes get committed. + +#. The computer you will be registering with the LLVM buildbot + infrastructure should have all dependencies installed and you can + actually build your configuration successfully. Please check what degree + of parallelism (-j param) would give the fastest build. You can build + multiple configurations on one computer. + +#. Install buildslave (currently we are using buildbot version 0.8.5). + Depending on the platform, buildslave could be available to download and + install with your packet manager, or you can download it directly from + `<http://trac.buildbot.net>`_ and install it manually. + +#. Create a designated user account, your buildslave will be running under, + and set appropriate permissions. + +#. Choose the buildslave root directory (all builds will be placed under + it), buildslave access name and password the build master will be using + to authenticate your buildslave. + +#. Create a buildslave in context of that buildslave account. Point it to + the **lab.llvm.org** port **9990** (see `Buildbot documentation, + Creating a slave + <http://buildbot.net/buildbot/docs/current/full.html#creating-a-slave>`_ + for more details) by running the following command: + + .. code-block:: bash + + $ buildslave create-slave <buildslave-root-directory> \ + lab.llvm.org:9990 \ + <buildslave-access-name> <buildslave-access-password> + +#. Fill the buildslave description and admin name/e-mail. Here is an + example of the buildslave description:: + + Windows 7 x64 + Core i7 (2.66GHz), 16GB of RAM + + g++.exe (TDM-1 mingw32) 4.4.0 + GNU Binutils 2.19.1 + cmake version 2.8.4 + Microsoft(R) 32-bit C/C++ Optimizing Compiler Version 16.00.40219.01 for 80x86 + +#. Make sure you can actually start the buildslave successfully. Then set + up your buildslave to start automatically at the start up time. See the + buildbot documentation for help. You may want to restart your computer + to see if it works. + +#. Send a patch which adds your build slave and your builder to zorg. + + * slaves are added to ``buildbot/osuosl/master/config/slaves.py`` + * builders are added to ``buildbot/osuosl/master/config/builders.py`` + +#. Send the buildslave access name and the access password directly to + `Galina Kistanova <mailto:gkistanova@gmail.com>`_, and wait till she + will let you know that your changes are applied and buildmaster is + reconfigured. + +#. Check the status of your buildslave on the `Waterfall Display + <http://lab.llvm.org:8011/waterfall>`_ to make sure it is connected, and + ``http://lab.llvm.org:8011/buildslaves/<your-buildslave-name>`` to see + if administrator contact and slave information are correct. + +#. Wait for the first build to succeed and enjoy. diff --git a/docs/HowToBuildOnARM.rst b/docs/HowToBuildOnARM.rst new file mode 100644 index 0000000..d786a7d --- /dev/null +++ b/docs/HowToBuildOnARM.rst @@ -0,0 +1,47 @@ +.. _how_to_build_on_arm: + +=================================================================== +How To Build On ARM +=================================================================== + +.. sectionauthor:: Wei-Ren Chen (陳韋任) <chenwj@iis.sinica.edu.tw> + +Introduction +============ + +This document contains information about building/testing LLVM and +Clang on ARM. + +Notes On Building LLVM/Clang on ARM +===================================== +Here are some notes on building/testing LLVM/Clang on ARM. Note that +ARM encompasses a wide variety of CPUs; this advice is primarily based +on the ARMv6 and ARMv7 architectures and may be inapplicable to older chips. + +#. If you are building LLVM/Clang on an ARM board with 1G of memory or less, + please use ``gold`` rather then GNU ``ld``. + Building LLVM/Clang with ``--enable-optimized`` + is prefered since it consumes less memory. Otherwise, the building + process will very likely fail due to insufficient memory. In any + case it is probably a good idea to set up a swap partition. + +#. If you want to run ``make + check-all`` after building LLVM/Clang, to avoid false alarms (eg, ARCMT + failure) please use at least the following configuration: + + .. code-block:: bash + + $ ../$LLVM_SRC_DIR/configure --with-abi=aapcs-vfp + +#. The most popular linaro/ubuntu OS's for ARM boards, eg, the + Pandaboard, have become hard-float platforms. The following set + of configuration options appears to be a good choice for this + platform: + + .. code-block:: bash + + ./configure --build=armv7l-unknown-linux-gnueabihf + --host=armv7l-unknown-linux-gnueabihf + --target=armv7l-unknown-linux-gnueabihf --with-cpu=cortex-a9 + --with-float=hard --with-abi=aapcs-vfp --with-fpu=neon + --enable-targets=arm --disable-optimized --enable-assertions diff --git a/docs/HowToSetUpLLVMStyleRTTI.rst b/docs/HowToSetUpLLVMStyleRTTI.rst new file mode 100644 index 0000000..aa1ad84 --- /dev/null +++ b/docs/HowToSetUpLLVMStyleRTTI.rst @@ -0,0 +1,332 @@ +.. _how-to-set-up-llvm-style-rtti: + +====================================================== +How to set up LLVM-style RTTI for your class hierarchy +====================================================== + +.. sectionauthor:: Sean Silva <silvas@purdue.edu> + +.. contents:: + +Background +========== + +LLVM avoids using C++'s built in RTTI. Instead, it pervasively uses its +own hand-rolled form of RTTI which is much more efficient and flexible, +although it requires a bit more work from you as a class author. + +A description of how to use LLVM-style RTTI from a client's perspective is +given in the `Programmer's Manual <ProgrammersManual.html#isa>`_. This +document, in contrast, discusses the steps you need to take as a class +hierarchy author to make LLVM-style RTTI available to your clients. + +Before diving in, make sure that you are familiar with the Object Oriented +Programming concept of "`is-a`_". + +.. _is-a: http://en.wikipedia.org/wiki/Is-a + +Basic Setup +=========== + +This section describes how to set up the most basic form of LLVM-style RTTI +(which is sufficient for 99.9% of the cases). We will set up LLVM-style +RTTI for this class hierarchy: + +.. code-block:: c++ + + class Shape { + public: + Shape() {} + virtual double computeArea() = 0; + }; + + class Square : public Shape { + double SideLength; + public: + Square(double S) : SideLength(S) {} + double computeArea() /* override */; + }; + + class Circle : public Shape { + double Radius; + public: + Circle(double R) : Radius(R) {} + double computeArea() /* override */; + }; + +The most basic working setup for LLVM-style RTTI requires the following +steps: + +#. In the header where you declare ``Shape``, you will want to ``#include + "llvm/Support/Casting.h"``, which declares LLVM's RTTI templates. That + way your clients don't even have to think about it. + + .. code-block:: c++ + + #include "llvm/Support/Casting.h" + +#. In the base class, introduce an enum which discriminates all of the + different concrete classes in the hierarchy, and stash the enum value + somewhere in the base class. + + Here is the code after introducing this change: + + .. code-block:: c++ + + class Shape { + public: + + /// Discriminator for LLVM-style RTTI (dyn_cast<> et al.) + + enum ShapeKind { + + SK_Square, + + SK_Circle + + }; + +private: + + const ShapeKind Kind; + +public: + + ShapeKind getKind() const { return Kind; } + + + Shape() {} + virtual double computeArea() = 0; + }; + + You will usually want to keep the ``Kind`` member encapsulated and + private, but let the enum ``ShapeKind`` be public along with providing a + ``getKind()`` method. This is convenient for clients so that they can do + a ``switch`` over the enum. + + A common naming convention is that these enums are "kind"s, to avoid + ambiguity with the words "type" or "class" which have overloaded meanings + in many contexts within LLVM. Sometimes there will be a natural name for + it, like "opcode". Don't bikeshed over this; when in doubt use ``Kind``. + + You might wonder why the ``Kind`` enum doesn't have an entry for + ``Shape``. The reason for this is that since ``Shape`` is abstract + (``computeArea() = 0;``), you will never actually have non-derived + instances of exactly that class (only subclasses). See `Concrete Bases + and Deeper Hierarchies`_ for information on how to deal with + non-abstract bases. It's worth mentioning here that unlike + ``dynamic_cast<>``, LLVM-style RTTI can be used (and is often used) for + classes that don't have v-tables. + +#. Next, you need to make sure that the ``Kind`` gets initialized to the + value corresponding to the dynamic type of the class. Typically, you will + want to have it be an argument to the constructor of the base class, and + then pass in the respective ``XXXKind`` from subclass constructors. + + Here is the code after that change: + + .. code-block:: c++ + + class Shape { + public: + /// Discriminator for LLVM-style RTTI (dyn_cast<> et al.) + enum ShapeKind { + SK_Square, + SK_Circle + }; + private: + const ShapeKind Kind; + public: + ShapeKind getKind() const { return Kind; } + + - Shape() {} + + Shape(ShapeKind K) : Kind(K) {} + virtual double computeArea() = 0; + }; + + class Square : public Shape { + double SideLength; + public: + - Square(double S) : SideLength(S) {} + + Square(double S) : Shape(SK_Square), SideLength(S) {} + double computeArea() /* override */; + }; + + class Circle : public Shape { + double Radius; + public: + - Circle(double R) : Radius(R) {} + + Circle(double R) : Shape(SK_Circle), Radius(R) {} + double computeArea() /* override */; + }; + +#. Finally, you need to inform LLVM's RTTI templates how to dynamically + determine the type of a class (i.e. whether the ``isa<>``/``dyn_cast<>`` + should succeed). The default "99.9% of use cases" way to accomplish this + is through a small static member function ``classof``. In order to have + proper context for an explanation, we will display this code first, and + then below describe each part: + + .. code-block:: c++ + + class Shape { + public: + /// Discriminator for LLVM-style RTTI (dyn_cast<> et al.) + enum ShapeKind { + SK_Square, + SK_Circle + }; + private: + const ShapeKind Kind; + public: + ShapeKind getKind() const { return Kind; } + + Shape(ShapeKind K) : Kind(K) {} + virtual double computeArea() = 0; + }; + + class Square : public Shape { + double SideLength; + public: + Square(double S) : Shape(SK_Square), SideLength(S) {} + double computeArea() /* override */; + + + + static bool classof(const Shape *S) { + + return S->getKind() == SK_Square; + + } + }; + + class Circle : public Shape { + double Radius; + public: + Circle(double R) : Shape(SK_Circle), Radius(R) {} + double computeArea() /* override */; + + + + static bool classof(const Shape *S) { + + return S->getKind() == SK_Circle; + + } + }; + + The job of ``classof`` is to dynamically determine whether an object of + a base class is in fact of a particular derived class. In order to + downcast a type ``Base`` to a type ``Derived``, there needs to be a + ``classof`` in ``Derived`` which will accept an object of type ``Base``. + + To be concrete, consider the following code: + + .. code-block:: c++ + + Shape *S = ...; + if (isa<Circle>(S)) { + /* do something ... */ + } + + The code of the ``isa<>`` test in this code will eventually boil + down---after template instantiation and some other machinery---to a + check roughly like ``Circle::classof(S)``. For more information, see + :ref:`classof-contract`. + + The argument to ``classof`` should always be an *ancestor* class because + the implementation has logic to allow and optimize away + upcasts/up-``isa<>``'s automatically. It is as though every class + ``Foo`` automatically has a ``classof`` like: + + .. code-block:: c++ + + class Foo { + [...] + template <class T> + static bool classof(const T *, + ::llvm::enable_if_c< + ::llvm::is_base_of<Foo, T>::value + >::type* = 0) { return true; } + [...] + }; + + Note that this is the reason that we did not need to introduce a + ``classof`` into ``Shape``: all relevant classes derive from ``Shape``, + and ``Shape`` itself is abstract (has no entry in the ``Kind`` enum), + so this notional inferred ``classof`` is all we need. See `Concrete + Bases and Deeper Hierarchies`_ for more information about how to extend + this example to more general hierarchies. + +Although for this small example setting up LLVM-style RTTI seems like a lot +of "boilerplate", if your classes are doing anything interesting then this +will end up being a tiny fraction of the code. + +Concrete Bases and Deeper Hierarchies +===================================== + +For concrete bases (i.e. non-abstract interior nodes of the inheritance +tree), the ``Kind`` check inside ``classof`` needs to be a bit more +complicated. The situation differs from the example above in that + +* Since the class is concrete, it must itself have an entry in the ``Kind`` + enum because it is possible to have objects with this class as a dynamic + type. + +* Since the class has children, the check inside ``classof`` must take them + into account. + +Say that ``SpecialSquare`` and ``OtherSpecialSquare`` derive +from ``Square``, and so ``ShapeKind`` becomes: + +.. code-block:: c++ + + enum ShapeKind { + SK_Square, + + SK_SpecialSquare, + + SK_OtherSpecialSquare, + SK_Circle + } + +Then in ``Square``, we would need to modify the ``classof`` like so: + +.. code-block:: c++ + + - static bool classof(const Shape *S) { + - return S->getKind() == SK_Square; + - } + + static bool classof(const Shape *S) { + + return S->getKind() >= SK_Square && + + S->getKind() <= SK_OtherSpecialSquare; + + } + +The reason that we need to test a range like this instead of just equality +is that both ``SpecialSquare`` and ``OtherSpecialSquare`` "is-a" +``Square``, and so ``classof`` needs to return ``true`` for them. + +This approach can be made to scale to arbitrarily deep hierarchies. The +trick is that you arrange the enum values so that they correspond to a +preorder traversal of the class hierarchy tree. With that arrangement, all +subclass tests can be done with two comparisons as shown above. If you just +list the class hierarchy like a list of bullet points, you'll get the +ordering right:: + + | Shape + | Square + | SpecialSquare + | OtherSpecialSquare + | Circle + +.. _classof-contract: + +The Contract of ``classof`` +--------------------------- + +To be more precise, let ``classof`` be inside a class ``C``. Then the +contract for ``classof`` is "return ``true`` if the dynamic type of the +argument is-a ``C``". As long as your implementation fulfills this +contract, you can tweak and optimize it as much as you want. + +.. TODO:: + + Touch on some of the more advanced features, like ``isa_impl`` and + ``simplify_type``. However, those two need reference documentation in + the form of doxygen comments as well. We need the doxygen so that we can + say "for full details, see http://llvm.org/doxygen/..." + +Rules of Thumb +============== + +#. The ``Kind`` enum should have one entry per concrete class, ordered + according to a preorder traversal of the inheritance tree. +#. The argument to ``classof`` should be a ``const Base *``, where ``Base`` + is some ancestor in the inheritance hierarchy. The argument should + *never* be a derived class or the class itself: the template machinery + for ``isa<>`` already handles this case and optimizes it. +#. For each class in the hierarchy that has no children, implement a + ``classof`` that checks only against its ``Kind``. +#. For each class in the hierarchy that has children, implement a + ``classof`` that checks a range of the first child's ``Kind`` and the + last child's ``Kind``. diff --git a/docs/HowToSubmitABug.html b/docs/HowToSubmitABug.html deleted file mode 100644 index ef7cf9e..0000000 --- a/docs/HowToSubmitABug.html +++ /dev/null @@ -1,345 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" - "http://www.w3.org/TR/html4/strict.dtd"> -<html> -<head> - <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> - <title>How to submit an LLVM bug report</title> - <link rel="stylesheet" href="_static/llvm.css" type="text/css"> -</head> -<body> - -<h1> - How to submit an LLVM bug report -</h1> - -<table class="layout" style="width: 90%" > -<tr class="layout"> - <td class="left"> -<ol> - <li><a href="#introduction">Introduction - Got bugs?</a></li> - <li><a href="#crashers">Crashing Bugs</a> - <ul> - <li><a href="#front-end">Front-end bugs</a> - <li><a href="#ct_optimizer">Compile-time optimization bugs</a> - <li><a href="#ct_codegen">Code generator bugs</a> - </ul></li> - <li><a href="#miscompilations">Miscompilations</a></li> - <li><a href="#codegen">Incorrect code generation (JIT and LLC)</a></li> -</ol> -<div class="doc_author"> - <p>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a> and - <a href="http://misha.brukman.net">Misha Brukman</a></p> -</div> -</td> -</tr> -</table> - -<!-- *********************************************************************** --> -<h2> - <a name="introduction">Introduction - Got bugs?</a> -</h2> -<!-- *********************************************************************** --> - -<div> - -<p>If you're working with LLVM and run into a bug, we definitely want to know -about it. This document describes what you can do to increase the odds of -getting it fixed quickly.</p> - -<p>Basically you have to do two things at a minimum. First, decide whether the -bug <a href="#crashers">crashes the compiler</a> (or an LLVM pass), or if the -compiler is <a href="#miscompilations">miscompiling</a> the program (i.e., the -compiler successfully produces an executable, but it doesn't run right). Based -on -what type of bug it is, follow the instructions in the linked section to narrow -down the bug so that the person who fixes it will be able to find the problem -more easily.</p> - -<p>Once you have a reduced test-case, go to <a -href="http://llvm.org/bugs/enter_bug.cgi">the LLVM Bug Tracking -System</a> and fill out the form with the necessary details (note that you don't -need to pick a category, just use the "new-bugs" category if you're not sure). -The bug description should contain the following -information:</p> - -<ul> - <li>All information necessary to reproduce the problem.</li> - <li>The reduced test-case that triggers the bug.</li> - <li>The location where you obtained LLVM (if not from our Subversion - repository).</li> -</ul> - -<p>Thanks for helping us make LLVM better!</p> - -</div> - -<!-- *********************************************************************** --> -<h2> - <a name="crashers">Crashing Bugs</a> -</h2> -<!-- *********************************************************************** --> - -<div> - -<p>More often than not, bugs in the compiler cause it to crash—often due -to an assertion failure of some sort. The most important -piece of the puzzle is to figure out if it is crashing in the GCC front-end -or if it is one of the LLVM libraries (e.g. the optimizer or code generator) -that has problems.</p> - -<p>To figure out which component is crashing (the front-end, -optimizer or code generator), run the -<tt><b>llvm-gcc</b></tt> command line as you were when the crash occurred, but -with the following extra command line options:</p> - -<ul> - <li><tt><b>-O0 -emit-llvm</b></tt>: If <tt>llvm-gcc</tt> still crashes when - passed these options (which disable the optimizer and code generator), then - the crash is in the front-end. Jump ahead to the section on <a - href="#front-end">front-end bugs</a>.</li> - - <li><tt><b>-emit-llvm</b></tt>: If <tt>llvm-gcc</tt> crashes with this option - (which disables the code generator), you found an optimizer bug. Jump ahead - to <a href="#ct_optimizer"> compile-time optimization bugs</a>.</li> - - <li>Otherwise, you have a code generator crash. Jump ahead to <a - href="#ct_codegen">code generator bugs</a>.</li> - -</ul> - -<!-- ======================================================================= --> -<h3> - <a name="front-end">Front-end bugs</a> -</h3> - -<div> - -<p>If the problem is in the front-end, you should re-run the same -<tt>llvm-gcc</tt> command that resulted in the crash, but add the -<tt>-save-temps</tt> option. The compiler will crash again, but it will leave -behind a <tt><i>foo</i>.i</tt> file (containing preprocessed C source code) and -possibly <tt><i>foo</i>.s</tt> for each -compiled <tt><i>foo</i>.c</tt> file. Send us the <tt><i>foo</i>.i</tt> file, -along with the options you passed to llvm-gcc, and a brief description of the -error it caused.</p> - -<p>The <a href="http://delta.tigris.org/">delta</a> tool helps to reduce the -preprocessed file down to the smallest amount of code that still replicates the -problem. You're encouraged to use delta to reduce the code to make the -developers' lives easier. <a -href="http://gcc.gnu.org/wiki/A_guide_to_testcase_reduction">This website</a> -has instructions on the best way to use delta.</p> - -</div> - -<!-- ======================================================================= --> -<h3> - <a name="ct_optimizer">Compile-time optimization bugs</a> -</h3> - -<div> - -<p>If you find that a bug crashes in the optimizer, compile your test-case to a -<tt>.bc</tt> file by passing "<tt><b>-emit-llvm -O0 -c -o foo.bc</b></tt>". -Then run:</p> - -<div class="doc_code"> -<p><tt><b>opt</b> -std-compile-opts -debug-pass=Arguments foo.bc - -disable-output</tt></p> -</div> - -<p>This command should do two things: it should print out a list of passes, and -then it should crash in the same way as llvm-gcc. If it doesn't crash, please -follow the instructions for a <a href="#front-end">front-end bug</a>.</p> - -<p>If this does crash, then you should be able to debug this with the following -bugpoint command:</p> - -<div class="doc_code"> -<p><tt><b>bugpoint</b> foo.bc <list of passes printed by -<b>opt</b>></tt></p> -</div> - -<p>Please run this, then file a bug with the instructions and reduced .bc files -that bugpoint emits. If something goes wrong with bugpoint, please submit the -"foo.bc" file and the list of passes printed by <b>opt</b>.</p> - -</div> - -<!-- ======================================================================= --> -<h3> - <a name="ct_codegen">Code generator bugs</a> -</h3> - -<div> - -<p>If you find a bug that crashes llvm-gcc in the code generator, compile your -source file to a .bc file by passing "<tt><b>-emit-llvm -c -o foo.bc</b></tt>" -to llvm-gcc (in addition to the options you already pass). Once your have -foo.bc, one of the following commands should fail:</p> - -<ol> -<li><tt><b>llc</b> foo.bc</tt></li> -<li><tt><b>llc</b> foo.bc -relocation-model=pic</tt></li> -<li><tt><b>llc</b> foo.bc -relocation-model=static</tt></li> -</ol> - -<p>If none of these crash, please follow the instructions for a -<a href="#front-end">front-end bug</a>. If one of these do crash, you should -be able to reduce this with one of the following bugpoint command lines (use -the one corresponding to the command above that failed):</p> - -<ol> -<li><tt><b>bugpoint</b> -run-llc foo.bc</tt></li> -<li><tt><b>bugpoint</b> -run-llc foo.bc --tool-args - -relocation-model=pic</tt></li> -<li><tt><b>bugpoint</b> -run-llc foo.bc --tool-args - -relocation-model=static</tt></li> -</ol> - -<p>Please run this, then file a bug with the instructions and reduced .bc file -that bugpoint emits. If something goes wrong with bugpoint, please submit the -"foo.bc" file and the option that llc crashes with.</p> - -</div> - -</div> - -<!-- *********************************************************************** --> -<h2> - <a name="miscompilations">Miscompilations</a> -</h2> -<!-- *********************************************************************** --> - -<div> - -<p>If llvm-gcc successfully produces an executable, but that executable doesn't -run right, this is either a bug in the code or a bug in the -compiler. The first thing to check is to make sure it is not using undefined -behavior (e.g. reading a variable before it is defined). In particular, check -to see if the program <a href="http://valgrind.org/">valgrind</a>s clean, -passes purify, or some other memory checker tool. Many of the "LLVM bugs" that -we have chased down ended up being bugs in the program being compiled, not - LLVM.</p> - -<p>Once you determine that the program itself is not buggy, you should choose -which code generator you wish to compile the program with (e.g. LLC or the JIT) -and optionally a series of LLVM passes to run. For example:</p> - -<div class="doc_code"> -<p><tt> -<b>bugpoint</b> -run-llc [... optzn passes ...] file-to-test.bc --args -- [program arguments]</tt></p> -</div> - -<p><tt>bugpoint</tt> will try to narrow down your list of passes to the one pass -that causes an error, and simplify the bitcode file as much as it can to assist -you. It will print a message letting you know how to reproduce the resulting -error.</p> - -</div> - -<!-- *********************************************************************** --> -<h2> - <a name="codegen">Incorrect code generation</a> -</h2> -<!-- *********************************************************************** --> - -<div> - -<p>Similarly to debugging incorrect compilation by mis-behaving passes, you can -debug incorrect code generation by either LLC or the JIT, using -<tt>bugpoint</tt>. The process <tt>bugpoint</tt> follows in this case is to try -to narrow the code down to a function that is miscompiled by one or the other -method, but since for correctness, the entire program must be run, -<tt>bugpoint</tt> will compile the code it deems to not be affected with the C -Backend, and then link in the shared object it generates.</p> - -<p>To debug the JIT:</p> - -<div class="doc_code"> -<pre> -bugpoint -run-jit -output=[correct output file] [bitcode file] \ - --tool-args -- [arguments to pass to lli] \ - --args -- [program arguments] -</pre> -</div> - -<p>Similarly, to debug the LLC, one would run:</p> - -<div class="doc_code"> -<pre> -bugpoint -run-llc -output=[correct output file] [bitcode file] \ - --tool-args -- [arguments to pass to llc] \ - --args -- [program arguments] -</pre> -</div> - -<p><b>Special note:</b> if you are debugging MultiSource or SPEC tests that -already exist in the <tt>llvm/test</tt> hierarchy, there is an easier way to -debug the JIT, LLC, and CBE, using the pre-written Makefile targets, which -will pass the program options specified in the Makefiles:</p> - -<div class="doc_code"> -<p><tt> -cd llvm/test/../../program<br> -make bugpoint-jit -</tt></p> -</div> - -<p>At the end of a successful <tt>bugpoint</tt> run, you will be presented -with two bitcode files: a <em>safe</em> file which can be compiled with the C -backend and the <em>test</em> file which either LLC or the JIT -mis-codegenerates, and thus causes the error.</p> - -<p>To reproduce the error that <tt>bugpoint</tt> found, it is sufficient to do -the following:</p> - -<ol> - -<li><p>Regenerate the shared object from the safe bitcode file:</p> - -<div class="doc_code"> -<p><tt> -<b>llc</b> -march=c safe.bc -o safe.c<br> -<b>gcc</b> -shared safe.c -o safe.so -</tt></p> -</div></li> - -<li><p>If debugging LLC, compile test bitcode native and link with the shared - object:</p> - -<div class="doc_code"> -<p><tt> -<b>llc</b> test.bc -o test.s<br> -<b>gcc</b> test.s safe.so -o test.llc<br> -./test.llc [program options] -</tt></p> -</div></li> - -<li><p>If debugging the JIT, load the shared object and supply the test - bitcode:</p> - -<div class="doc_code"> -<p><tt><b>lli</b> -load=safe.so test.bc [program options]</tt></p> -</div></li> - -</ol> - -</div> - -<!-- *********************************************************************** --> -<hr> -<address> - <a href="http://jigsaw.w3.org/css-validator/check/referer"><img - src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS"></a> - <a href="http://validator.w3.org/check/referer"><img - src="http://www.w3.org/Icons/valid-html401-blue" alt="Valid HTML 4.01"></a> - - <a href="mailto:sabre@nondot.org">Chris Lattner</a><br> - <a href="http://llvm.org/">The LLVM Compiler Infrastructure</a> - <br> - Last modified: $Date: 2012-06-14 18:52:55 +0200 (Thu, 14 Jun 2012) $ -</address> - -</body> -</html> diff --git a/docs/HowToSubmitABug.rst b/docs/HowToSubmitABug.rst new file mode 100644 index 0000000..ff2d649 --- /dev/null +++ b/docs/HowToSubmitABug.rst @@ -0,0 +1,233 @@ +.. _how-to-submit-a-bug-report: + +================================ +How to submit an LLVM bug report +================================ + +.. sectionauthor:: Chris Lattner <sabre@nondot.org> and Misha Brukman <http://misha.brukman.net> + +Introduction - Got bugs? +======================== + + +If you're working with LLVM and run into a bug, we definitely want to know +about it. This document describes what you can do to increase the odds of +getting it fixed quickly. + +Basically you have to do two things at a minimum. First, decide whether +the bug `crashes the compiler`_ (or an LLVM pass), or if the +compiler is `miscompiling`_ the program (i.e., the +compiler successfully produces an executable, but it doesn't run right). +Based on what type of bug it is, follow the instructions in the linked +section to narrow down the bug so that the person who fixes it will be able +to find the problem more easily. + +Once you have a reduced test-case, go to `the LLVM Bug Tracking System +<http://llvm.org/bugs/enter_bug.cgi>`_ and fill out the form with the +necessary details (note that you don't need to pick a category, just use +the "new-bugs" category if you're not sure). The bug description should +contain the following information: + +* All information necessary to reproduce the problem. +* The reduced test-case that triggers the bug. +* The location where you obtained LLVM (if not from our Subversion + repository). + +Thanks for helping us make LLVM better! + +.. _crashes the compiler: + +Crashing Bugs +============= + +More often than not, bugs in the compiler cause it to crash---often due to +an assertion failure of some sort. The most important piece of the puzzle +is to figure out if it is crashing in the GCC front-end or if it is one of +the LLVM libraries (e.g. the optimizer or code generator) that has +problems. + +To figure out which component is crashing (the front-end, optimizer or code +generator), run the ``llvm-gcc`` command line as you were when the crash +occurred, but with the following extra command line options: + +* ``-O0 -emit-llvm``: If ``llvm-gcc`` still crashes when passed these + options (which disable the optimizer and code generator), then the crash + is in the front-end. Jump ahead to the section on :ref:`front-end bugs + <front-end>`. + +* ``-emit-llvm``: If ``llvm-gcc`` crashes with this option (which disables + the code generator), you found an optimizer bug. Jump ahead to + `compile-time optimization bugs`_. + +* Otherwise, you have a code generator crash. Jump ahead to `code + generator bugs`_. + +.. _front-end bug: +.. _front-end: + +Front-end bugs +-------------- + +If the problem is in the front-end, you should re-run the same ``llvm-gcc`` +command that resulted in the crash, but add the ``-save-temps`` option. +The compiler will crash again, but it will leave behind a ``foo.i`` file +(containing preprocessed C source code) and possibly ``foo.s`` for each +compiled ``foo.c`` file. Send us the ``foo.i`` file, along with the options +you passed to ``llvm-gcc``, and a brief description of the error it caused. + +The `delta <http://delta.tigris.org/>`_ tool helps to reduce the +preprocessed file down to the smallest amount of code that still replicates +the problem. You're encouraged to use delta to reduce the code to make the +developers' lives easier. `This website +<http://gcc.gnu.org/wiki/A_guide_to_testcase_reduction>`_ has instructions +on the best way to use delta. + +.. _compile-time optimization bugs: + +Compile-time optimization bugs +------------------------------ + +If you find that a bug crashes in the optimizer, compile your test-case to a +``.bc`` file by passing "``-emit-llvm -O0 -c -o foo.bc``". +Then run: + +.. code-block:: bash + + opt -std-compile-opts -debug-pass=Arguments foo.bc -disable-output + +This command should do two things: it should print out a list of passes, and +then it should crash in the same way as llvm-gcc. If it doesn't crash, please +follow the instructions for a `front-end bug`_. + +If this does crash, then you should be able to debug this with the following +bugpoint command: + +.. code-block:: bash + + bugpoint foo.bc <list of passes printed by opt> + +Please run this, then file a bug with the instructions and reduced .bc +files that bugpoint emits. If something goes wrong with bugpoint, please +submit the "foo.bc" file and the list of passes printed by ``opt``. + +.. _code generator bugs: + +Code generator bugs +------------------- + +If you find a bug that crashes llvm-gcc in the code generator, compile your +source file to a .bc file by passing "``-emit-llvm -c -o foo.bc``" to +llvm-gcc (in addition to the options you already pass). Once your have +foo.bc, one of the following commands should fail: + +#. ``llc foo.bc`` +#. ``llc foo.bc -relocation-model=pic`` +#. ``llc foo.bc -relocation-model=static`` + +If none of these crash, please follow the instructions for a `front-end +bug`_. If one of these do crash, you should be able to reduce this with +one of the following bugpoint command lines (use the one corresponding to +the command above that failed): + +#. ``bugpoint -run-llc foo.bc`` +#. ``bugpoint -run-llc foo.bc --tool-args -relocation-model=pic`` +#. ``bugpoint -run-llc foo.bc --tool-args -relocation-model=static`` + +Please run this, then file a bug with the instructions and reduced .bc file +that bugpoint emits. If something goes wrong with bugpoint, please submit +the "foo.bc" file and the option that llc crashes with. + +.. _miscompiling: + +Miscompilations +=============== + +If llvm-gcc successfully produces an executable, but that executable +doesn't run right, this is either a bug in the code or a bug in the +compiler. The first thing to check is to make sure it is not using +undefined behavior (e.g. reading a variable before it is defined). In +particular, check to see if the program `valgrind +<http://valgrind.org/>`_'s clean, passes purify, or some other memory +checker tool. Many of the "LLVM bugs" that we have chased down ended up +being bugs in the program being compiled, not LLVM. + +Once you determine that the program itself is not buggy, you should choose +which code generator you wish to compile the program with (e.g. LLC or the JIT) +and optionally a series of LLVM passes to run. For example: + +.. code-block:: bash + + bugpoint -run-llc [... optzn passes ...] file-to-test.bc --args -- [program arguments] + +bugpoint will try to narrow down your list of passes to the one pass that +causes an error, and simplify the bitcode file as much as it can to assist +you. It will print a message letting you know how to reproduce the +resulting error. + +Incorrect code generation +========================= + +Similarly to debugging incorrect compilation by mis-behaving passes, you +can debug incorrect code generation by either LLC or the JIT, using +``bugpoint``. The process ``bugpoint`` follows in this case is to try to +narrow the code down to a function that is miscompiled by one or the other +method, but since for correctness, the entire program must be run, +``bugpoint`` will compile the code it deems to not be affected with the C +Backend, and then link in the shared object it generates. + +To debug the JIT: + +.. code-block:: bash + + bugpoint -run-jit -output=[correct output file] [bitcode file] \ + --tool-args -- [arguments to pass to lli] \ + --args -- [program arguments] + +Similarly, to debug the LLC, one would run: + +.. code-block:: bash + + bugpoint -run-llc -output=[correct output file] [bitcode file] \ + --tool-args -- [arguments to pass to llc] \ + --args -- [program arguments] + +**Special note:** if you are debugging MultiSource or SPEC tests that +already exist in the ``llvm/test`` hierarchy, there is an easier way to +debug the JIT, LLC, and CBE, using the pre-written Makefile targets, which +will pass the program options specified in the Makefiles: + +.. code-block:: bash + + cd llvm/test/../../program + make bugpoint-jit + +At the end of a successful ``bugpoint`` run, you will be presented +with two bitcode files: a *safe* file which can be compiled with the C +backend and the *test* file which either LLC or the JIT +mis-codegenerates, and thus causes the error. + +To reproduce the error that ``bugpoint`` found, it is sufficient to do +the following: + +#. Regenerate the shared object from the safe bitcode file: + + .. code-block:: bash + + llc -march=c safe.bc -o safe.c + gcc -shared safe.c -o safe.so + +#. If debugging LLC, compile test bitcode native and link with the shared + object: + + .. code-block:: bash + + llc test.bc -o test.s + gcc test.s safe.so -o test.llc + ./test.llc [program options] + +#. If debugging the JIT, load the shared object and supply the test + bitcode: + + .. code-block:: bash + + lli -load=safe.so test.bc [program options] diff --git a/docs/HowToUseInstrMappings.rst b/docs/HowToUseInstrMappings.rst new file mode 100755 index 0000000..b51e74e --- /dev/null +++ b/docs/HowToUseInstrMappings.rst @@ -0,0 +1,179 @@ +.. _how_to_use_instruction_mappings: + +=============================== +How To Use Instruction Mappings +=============================== + +.. sectionauthor:: Jyotsna Verma <jverma@codeaurora.org> + +.. contents:: + :local: + +Introduction +============ + +This document contains information about adding instruction mapping support +for a target. The motivation behind this feature comes from the need to switch +between different instruction formats during various optimizations. One approach +could be to use switch cases which list all the instructions along with formats +they can transition to. However, it has large maintenance overhead +because of the hardcoded instruction names. Also, whenever a new instruction is +added in the .td files, all the relevant switch cases should be modified +accordingly. Instead, the same functionality could be achieved with TableGen and +some support from the .td files for a fraction of maintenance cost. + +``InstrMapping`` Class Overview +=============================== + +TableGen uses relationship models to map instructions with each other. These +models are described using ``InstrMapping`` class as a base. Each model sets +various fields of the ``InstrMapping`` class such that they can uniquely +describe all the instructions using that model. TableGen parses all the relation +models and uses the information to construct relation tables which relate +instructions with each other. These tables are emitted in the +``XXXInstrInfo.inc`` file along with the functions to query them. Following +is the definition of ``InstrMapping`` class definied in Target.td file: + +.. code-block:: llvm + + class InstrMapping { + // Used to reduce search space only to the instructions using this + // relation model. + string FilterClass; + + // List of fields/attributes that should be same for all the instructions in + // a row of the relation table. Think of this as a set of properties shared + // by all the instructions related by this relationship. + list<string> RowFields = []; + + // List of fields/attributes that are same for all the instructions + // in a column of the relation table. + list<string> ColFields = []; + + // Values for the fields/attributes listed in 'ColFields' corresponding to + // the key instruction. This is the instruction that will be transformed + // using this relation model. + list<string> KeyCol = []; + + // List of values for the fields/attributes listed in 'ColFields', one for + // each column in the relation table. These are the instructions a key + // instruction will be transformed into. + list<list<string> > ValueCols = []; + } + +Sample Example +-------------- + +Let's say that we want to have a function +``int getPredOpcode(uint16_t Opcode, enum PredSense inPredSense)`` which +takes a non-predicated instruction and returns its predicated true or false form +depending on some input flag, ``inPredSense``. The first step in the process is +to define a relationship model that relates predicated instructions to their +non-predicated form by assigning appropriate values to the ``InstrMapping`` +fields. For this relationship, non-predicated instructions are treated as key +instruction since they are the one used to query the interface function. + +.. code-block:: llvm + + def getPredOpcode : InstrMapping { + // Choose a FilterClass that is used as a base class for all the + // instructions modeling this relationship. This is done to reduce the + // search space only to these set of instructions. + let FilterClass = "PredRel"; + + // Instructions with same values for all the fields in RowFields form a + // row in the resulting relation table. + // For example, if we want to relate 'ADD' (non-predicated) with 'Add_pt' + // (predicated true) and 'Add_pf' (predicated false), then all 3 + // instructions need to have same value for BaseOpcode field. It can be any + // unique value (Ex: XYZ) and should not be shared with any other + // instruction not related to 'add'. + let RowFields = ["BaseOpcode"]; + + // List of attributes that can be used to define key and column instructions + // for a relation. Key instruction is passed as an argument + // to the function used for querying relation tables. Column instructions + // are the instructions they (key) can transform into. + // + // Here, we choose 'PredSense' as ColFields since this is the unique + // attribute of the key (non-predicated) and column (true/false) + // instructions involved in this relationship model. + let ColFields = ["PredSense"]; + + // The key column contains non-predicated instructions. + let KeyCol = ["none"]; + + // Two value columns - first column contains instructions with + // PredSense=true while second column has instructions with PredSense=false. + let ValueCols = [["true"], ["false"]]; + } + +TableGen uses the above relationship model to emit relation table that maps +non-predicated instructions with their predicated forms. It also outputs the +interface function +``int getPredOpcode(uint16_t Opcode, enum PredSense inPredSense)`` to query +the table. Here, Function ``getPredOpcode`` takes two arguments, opcode of the +current instruction and PredSense of the desired instruction, and returns +predicated form of the instruction, if found in the relation table. +In order for an instruction to be added into the relation table, it needs +to include relevant information in its definition. For example, consider +following to be the current definitions of ADD, ADD_pt (true) and ADD_pf (false) +instructions: + +.. code-block::llvm + + def ADD : ALU32_rr<(outs IntRegs:$dst), (ins IntRegs:$a, IntRegs:$b), + "$dst = add($a, $b)", + [(set (i32 IntRegs:$dst), (add (i32 IntRegs:$a), + (i32 IntRegs:$b)))]>; + + def ADD_Pt : ALU32_rr<(outs IntRegs:$dst), + (ins PredRegs:$p, IntRegs:$a, IntRegs:$b), + "if ($p) $dst = add($a, $b)", + []>; + + def ADD_Pf : ALU32_rr<(outs IntRegs:$dst), + (ins PredRegs:$p, IntRegs:$a, IntRegs:$b), + "if (!$p) $dst = add($a, $b)", + []>; + +In this step, we modify these instructions to include the information +required by the relationship model, <tt>getPredOpcode</tt>, so that they can +be related. + +.. code-block::llvm + + def ADD : PredRel, ALU32_rr<(outs IntRegs:$dst), (ins IntRegs:$a, IntRegs:$b), + "$dst = add($a, $b)", + [(set (i32 IntRegs:$dst), (add (i32 IntRegs:$a), + (i32 IntRegs:$b)))]> { + let BaseOpcode = "ADD"; + let PredSense = "none"; + } + + def ADD_Pt : PredRel, ALU32_rr<(outs IntRegs:$dst), + (ins PredRegs:$p, IntRegs:$a, IntRegs:$b), + "if ($p) $dst = add($a, $b)", + []> { + let BaseOpcode = "ADD"; + let PredSense = "true"; + } + + def ADD_Pf : PredRel, ALU32_rr<(outs IntRegs:$dst), + (ins PredRegs:$p, IntRegs:$a, IntRegs:$b), + "if (!$p) $dst = add($a, $b)", + []> { + let BaseOpcode = "ADD"; + let PredSense = "false"; + } + +Please note that all the above instructions use ``PredRel`` as a base class. +This is extremely important since TableGen uses it as a filter for selecting +instructions for ``getPredOpcode`` model. Any instruction not derived from +``PredRel`` is excluded from the analysis. ``BaseOpcode`` is another important +field. Since it's selected as a ``RowFields`` of the model, it is required +to have the same value for all 3 instructions in order to be related. Next, +``PredSense`` is used to determine their column positions by comparing its value +with ``KeyCol`` and ``ValueCols``. If an instruction sets its ``PredSense`` +value to something not used in the relation model, it will not be assigned +a column in the relation table. diff --git a/docs/LangRef.html b/docs/LangRef.html index 946380e..13daa65 100644 --- a/docs/LangRef.html +++ b/docs/LangRef.html @@ -25,7 +25,6 @@ <li><a href="#linkage_private">'<tt>private</tt>' Linkage</a></li> <li><a href="#linkage_linker_private">'<tt>linker_private</tt>' Linkage</a></li> <li><a href="#linkage_linker_private_weak">'<tt>linker_private_weak</tt>' Linkage</a></li> - <li><a href="#linkage_linker_private_weak_def_auto">'<tt>linker_private_weak_def_auto</tt>' Linkage</a></li> <li><a href="#linkage_internal">'<tt>internal</tt>' Linkage</a></li> <li><a href="#linkage_available_externally">'<tt>available_externally</tt>' Linkage</a></li> <li><a href="#linkage_linkonce">'<tt>linkonce</tt>' Linkage</a></li> @@ -34,6 +33,7 @@ <li><a href="#linkage_appending">'<tt>appending</tt>' Linkage</a></li> <li><a href="#linkage_externweak">'<tt>extern_weak</tt>' Linkage</a></li> <li><a href="#linkage_linkonce_odr">'<tt>linkonce_odr</tt>' Linkage</a></li> + <li><a href="#linkage_linkonce_odr_auto_hide">'<tt>linkonce_odr_auto_hide</tt>' Linkage</a></li> <li><a href="#linkage_weak">'<tt>weak_odr</tt>' Linkage</a></li> <li><a href="#linkage_external">'<tt>external</tt>' Linkage</a></li> <li><a href="#linkage_dllimport">'<tt>dllimport</tt>' Linkage</a></li> @@ -103,6 +103,7 @@ <li><a href="#metadata">Metadata Nodes and Metadata Strings</a> <ol> <li><a href="#tbaa">'<tt>tbaa</tt>' Metadata</a></li> + <li><a href="#tbaa.struct">'<tt>tbaa.struct</tt>' Metadata</a></li> <li><a href="#fpmath">'<tt>fpmath</tt>' Metadata</a></li> <li><a href="#range">'<tt>range</tt>' Metadata</a></li> </ol> @@ -576,15 +577,6 @@ define i32 @main() { <i>; i32()* </i> linker. The symbols are removed by the linker from the final linked image (executable or dynamic library).</dd> - <dt><tt><b><a name="linkage_linker_private_weak_def_auto">linker_private_weak_def_auto</a></b></tt></dt> - <dd>Similar to "<tt>linker_private_weak</tt>", but it's known that the address - of the object is not taken. For instance, functions that had an inline - definition, but the compiler decided not to inline it. Note, - unlike <tt>linker_private</tt> and <tt>linker_private_weak</tt>, - <tt>linker_private_weak_def_auto</tt> may have only <tt>default</tt> - visibility. The symbols are removed by the linker from the final linked - image (executable or dynamic library).</dd> - <dt><tt><b><a name="linkage_internal">internal</a></b></tt></dt> <dd>Similar to private, but the value shows as a local symbol (<tt>STB_LOCAL</tt> in the case of ELF) in the object file. This @@ -653,6 +645,14 @@ define i32 @main() { <i>; i32()* </i> be merged with equivalent globals. These linkage types are otherwise the same as their non-<tt>odr</tt> versions.</dd> + <dt><tt><b><a name="linkage_linkonce_odr_auto_hide">linkonce_odr_auto_hide</a></b></tt></dt> + <dd>Similar to "<tt>linkonce_odr</tt>", but nothing in the translation unit + takes the address of this definition. For instance, functions that had an + inline definition, but the compiler decided not to inline it. + <tt>linkonce_odr_auto_hide</tt> may have only <tt>default</tt> visibility. + The symbols are removed by the linker from the final linked image + (executable or dynamic library).</dd> + <dt><tt><b><a name="linkage_external">external</a></b></tt></dt> <dd>If none of the above identifiers are used, the global is externally visible, meaning that it participates in linkage and can be used to @@ -1107,9 +1107,9 @@ declare signext i8 @returns_signed_char() <dd>This indicates that the pointer parameter specifies the address of a structure that is the return value of the function in the source program. This pointer must be guaranteed by the caller to be valid: loads and - stores to the structure may be assumed by the callee to not to trap. This - may only be applied to the first parameter. This is not a valid attribute - for return values. </dd> + stores to the structure may be assumed by the callee to not to trap and + to be properly aligned. This may only be applied to the first parameter. + This is not a valid attribute for return values. </dd> <dt><tt><b><a name="noalias">noalias</a></b></tt></dt> <dd>This indicates that pointer values @@ -1208,13 +1208,6 @@ define void @f() optsize { ... } may make calls to the function faster, at the cost of extra program startup time if the function is not called during program startup.</dd> - <dt><tt><b>ia_nsdialect</b></tt></dt> - <dd>This attribute indicates the associated inline assembly call is using a - non-standard assembly dialect. The standard dialect is ATT, which is - assumed when this attribute is not present. When present, the dialect - is assumed to be Intel. Currently, ATT and Intel are the only supported - dialects.</dd> - <dt><tt><b>inlinehint</b></tt></dt> <dd>This attribute indicates that the source code contained a hint that inlining this function is desirable (such as the "inline" keyword in C/C++). It @@ -1371,11 +1364,13 @@ target datalayout = "<i>layout specification</i>" 8-bits. If omitted, the natural stack alignment defaults to "unspecified", which does not prevent any alignment promotions.</dd> - <dt><tt>p:<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt> + <dt><tt>p[n]:<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt> <dd>This specifies the <i>size</i> of a pointer and its <i>abi</i> and - <i>preferred</i> alignments. All sizes are in bits. Specifying - the <i>pref</i> alignment is optional. If omitted, the - preceding <tt>:</tt> should be omitted too.</dd> + <i>preferred</i> alignments for address space <i>n</i>. All sizes are in + bits. Specifying the <i>pref</i> alignment is optional. If omitted, the + preceding <tt>:</tt> should be omitted too. The address space, + <i>n</i> is optional, and if not specified, denotes the default address + space 0. The value of <i>n</i> must be in the range [1,2^23).</dd> <dt><tt>i<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt> <dd>This specifies the alignment for an integer type of a given bit @@ -1416,6 +1411,10 @@ target datalayout = "<i>layout specification</i>" <ul> <li><tt>E</tt> - big endian</li> <li><tt>p:64:64:64</tt> - 64-bit pointers with 64-bit alignment</li> + <li><tt>p1:32:32:32</tt> - 32-bit pointers with 32-bit alignment for + address space 1</li> + <li><tt>p2:16:32:32</tt> - 16-bit pointers with 32-bit alignment for + address space 2</li> <li><tt>i1:8:8</tt> - i1 is 8-bit (byte) aligned</li> <li><tt>i8:8:8</tt> - i8 is 8-bit (byte) aligned</li> <li><tt>i16:16:16</tt> - i16 is 16-bit aligned</li> @@ -2111,7 +2110,7 @@ in signal handlers).</p> <p>Structures may optionally be "packed" structures, which indicate that the alignment of the struct is one byte, and that there is no padding between the elements. In non-packed structs, padding between field types is inserted - as defined by the TargetData string in the module, which is required to match + as defined by the DataLayout string in the module, which is required to match what the underlying code generator expects.</p> <p>Structures can either be "literal" or "identified". A literal structure is @@ -2902,8 +2901,18 @@ call void asm sideeffect "eieio", ""() call void asm alignstack "eieio", ""() </pre> -<p>If both keywords appear the '<tt>sideeffect</tt>' keyword must come - first.</p> +<p>Inline asms also support using non-standard assembly dialects. The assumed + dialect is ATT. When the '<tt>inteldialect</tt>' keyword is present, the + inline asm is using the Intel dialect. Currently, ATT and Intel are the + only supported dialects. An example is:</p> + +<pre class="doc_code"> +call void asm inteldialect "eieio", ""() +</pre> + +<p>If multiple keywords appear the '<tt>sideeffect</tt>' keyword must come + first, the '<tt>alignstack</tt>' keyword second and the + '<tt>inteldialect</tt>' keyword last.</p> <!-- <p>TODO: The format of the asm and constraints string still need to be @@ -3050,6 +3059,44 @@ call void @llvm.dbg.value(metadata !24, i64 0, metadata !25) <!-- _______________________________________________________________________ --> <h4> + <a name="tbaa.struct">'<tt>tbaa.struct</tt>' Metadata</a> +</h4> + +<div> + +<p>The <a href="#int_memcpy"><tt>llvm.memcpy</tt></a> is often used to implement +aggregate assignment operations in C and similar languages, however it is +defined to copy a contiguous region of memory, which is more than strictly +necessary for aggregate types which contain holes due to padding. Also, it +doesn't contain any TBAA information about the fields of the aggregate.</p> + +<p><tt>!tbaa.struct</tt> metadata can describe which memory subregions in a memcpy +are padding and what the TBAA tags of the struct are.</p> + +<p>The current metadata format is very simple. <tt>!tbaa.struct</tt> metadata nodes + are a list of operands which are in conceptual groups of three. For each + group of three, the first operand gives the byte offset of a field in bytes, + the second gives its size in bytes, and the third gives its + tbaa tag. e.g.:</p> + +<div class="doc_code"> +<pre> +!4 = metadata !{ i64 0, i64 4, metadata !1, i64 8, i64 4, metadata !2 } +</pre> +</div> + +<p>This describes a struct with two fields. The first is at offset 0 bytes + with size 4 bytes, and has tbaa tag !1. The second is at offset 8 bytes + and has size 4 bytes and has tbaa tag !2.</p> + +<p>Note that the fields need not be contiguous. In this example, there is a + 4 byte gap between the two fields. This gap represents padding which + does not carry useful data and need not be preserved.</p> + +</div> + +<!-- _______________________________________________________________________ --> +<h4> <a name="fpmath">'<tt>fpmath</tt>' Metadata</a> </h4> @@ -5013,7 +5060,7 @@ IfUnequal: <p>The optional constant <tt>align</tt> argument specifies the alignment of the operation (that is, the alignment of the memory address). A value of 0 or an - omitted <tt>align</tt> argument means that the operation has the preferential + omitted <tt>align</tt> argument means that the operation has the abi alignment for the target. It is the responsibility of the code emitter to ensure that the alignment information is correct. Overestimating the alignment results in undefined behavior. Underestimating the alignment may @@ -5094,7 +5141,7 @@ IfUnequal: <p>The optional constant "align" argument specifies the alignment of the operation (that is, the alignment of the memory address). A value of 0 or an - omitted "align" argument means that the operation has the preferential + omitted "align" argument means that the operation has the abi alignment for the target. It is the responsibility of the code emitter to ensure that the alignment information is correct. Overestimating the alignment results in an undefined behavior. Underestimating the alignment may @@ -8722,7 +8769,7 @@ codegen.</p> <a href="mailto:sabre@nondot.org">Chris Lattner</a><br> <a href="http://llvm.org/">The LLVM Compiler Infrastructure</a><br> - Last modified: $Date: 2012-08-10 02:00:22 +0200 (Fri, 10 Aug 2012) $ + Last modified: $Date: 2012-10-29 15:12:44 +0100 (Mon, 29 Oct 2012) $ </address> </body> diff --git a/docs/Lexicon.rst b/docs/Lexicon.rst index 6ebe614..d568c0b 100644 --- a/docs/Lexicon.rst +++ b/docs/Lexicon.rst @@ -20,8 +20,10 @@ A B - -**BURS** +**BB Vectorization** + Basic Block Vectorization +**BURS** Bottom Up Rewriting System --- A method of instruction selection for code generation. An example is the `BURG <http://www.program-transformation.org/Transform/BURG>`_ tool. @@ -156,7 +158,7 @@ R In garbage collection, a pointer variable lying outside of the `heap`_ from which the collector begins its reachability analysis. In the context of code generation, "root" almost always refers to a "stack root" --- a local or - temporary variable within an executing function.</dd> + temporary variable within an executing function. **RPO** Reverse postorder @@ -192,3 +194,10 @@ S **Stack Map** In garbage collection, metadata emitted by the code generator which identifies `roots`_ within the stack frame of an executing function. + +T +- + +**TBAA** + Type-Based Alias Analysis + diff --git a/docs/LinkTimeOptimization.rst b/docs/LinkTimeOptimization.rst index 53d673e..7eacf0b 100644 --- a/docs/LinkTimeOptimization.rst +++ b/docs/LinkTimeOptimization.rst @@ -29,6 +29,8 @@ bitcode files. This tight integration between the linker and LLVM optimizer helps to do optimizations that are not possible in other models. The linker input allows the optimizer to avoid relying on conservative escape analysis. +.. _libLTO-example: + Example of link time optimization --------------------------------- diff --git a/docs/Makefile.sphinx b/docs/Makefile.sphinx index 21f6648..81c13de 100644 --- a/docs/Makefile.sphinx +++ b/docs/Makefile.sphinx @@ -46,6 +46,10 @@ clean: html: $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html @echo + @# FIXME: Remove this `cp` once HTML->Sphinx transition is completed. + @# Kind of a hack, but HTML-formatted docs are on the way out anyway. + @echo "Copying legacy HTML-formatted docs into $(BUILDDIR)/html" + @cp -a *.html tutorial $(BUILDDIR)/html @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." dirhtml: diff --git a/docs/MarkedUpDisassembly.rst b/docs/MarkedUpDisassembly.rst new file mode 100644 index 0000000..e1282e1 --- /dev/null +++ b/docs/MarkedUpDisassembly.rst @@ -0,0 +1,88 @@ +.. _marked_up_disassembly: + +======================================= +LLVM's Optional Rich Disassembly Output +======================================= + +.. contents:: + :local: + +Introduction +============ + +LLVM's default disassembly output is raw text. To allow consumers more ability +to introspect the instructions' textual representation or to reformat for a more +user friendly display there is an optional rich disassembly output. + +This optional output is sufficient to reference into individual portions of the +instruction text. This is intended for clients like disassemblers, list file +generators, and pretty-printers, which need more than the raw instructions and +the ability to print them. + +To provide this functionality the assembly text is marked up with annotations. +The markup is simple enough in syntax to be robust even in the case of version +mismatches between consumers and producers. That is, the syntax generally does +not carry semantics beyond "this text has an annotation," so consumers can +simply ignore annotations they do not understand or do not care about. + +After calling ``LLVMCreateDisasm()`` to create a disassembler context the +optional output is enable with this call: + +.. code-block:: c + + LLVMSetDisasmOptions(DC, LLVMDisassembler_Option_UseMarkup); + +Then subsequent calls to ``LLVMDisasmInstruction()`` will return output strings +with the marked up annotations. + +Instruction Annotations +======================= + +.. _contextual markups: + +Contextual markups +------------------ + +Annoated assembly display will supply contextual markup to help clients more +efficiently implement things like pretty printers. Most markup will be target +independent, so clients can effectively provide good display without any target +specific knowledge. + +Annotated assembly goes through the normal instruction printer, but optionally +includes contextual tags on portions of the instruction string. An annotation +is any '<' '>' delimited section of text(1). + +.. code-block:: bat + + annotation: '<' tag-name tag-modifier-list ':' annotated-text '>' + tag-name: identifier + tag-modifier-list: comma delimited identifier list + +The tag-name is an identifier which gives the type of the annotation. For the +first pass, this will be very simple, with memory references, registers, and +immediates having the tag names "mem", "reg", and "imm", respectively. + +The tag-modifier-list is typically additional target-specific context, such as +register class. + +Clients should accept and ignore any tag-names or tag-modifiers they do not +understand, allowing the annotations to grow in richness without breaking older +clients. + +For example, a possible annotation of an ARM load of a stack-relative location +might be annotated as: + +.. code-block:: nasm + + ldr <reg gpr:r0>, <mem regoffset:[<reg gpr:sp>, <imm:#4>]> + + +1: For assembly dialects in which '<' and/or '>' are legal tokens, a literal token is escaped by following immediately with a repeat of the character. For example, a literal '<' character is output as '<<' in an annotated assembly string. + +C API Details +------------- + +The intended consumers of this information use the C API, therefore the new C +API function for the disassembler will be added to provide an option to produce +disassembled instructions with annotations, ``LLVMSetDisasmOptions()`` and the +``LLVMDisassembler_Option_UseMarkup`` option (see above). diff --git a/docs/Passes.html b/docs/Passes.html index e8048d5..16e8bd6 100644 --- a/docs/Passes.html +++ b/docs/Passes.html @@ -77,6 +77,7 @@ perl -e '$/ = undef; for (split(/\n/, <>)) { s:^ *///? ?::; print " <p>\n" if ! <tr><td><a href="#basicaa">-basicaa</a></td><td>Basic Alias Analysis (stateless AA impl)</td></tr> <tr><td><a href="#basiccg">-basiccg</a></td><td>Basic CallGraph Construction</td></tr> <tr><td><a href="#count-aa">-count-aa</a></td><td>Count Alias Analysis Query Responses</td></tr> +<tr><td><a href="#da">-da</a></td><td>Dependence Analysis</td></tr> <tr><td><a href="#debug-aa">-debug-aa</a></td><td>AA use debugger</td></tr> <tr><td><a href="#domfrontier">-domfrontier</a></td><td>Dominance Frontier Construction</td></tr> <tr><td><a href="#domtree">-domtree</a></td><td>Dominator Tree Construction</td></tr> @@ -92,7 +93,6 @@ perl -e '$/ = undef; for (split(/\n/, <>)) { s:^ *///? ?::; print " <p>\n" if ! <tr><td><a href="#intervals">-intervals</a></td><td>Interval Partition Construction</td></tr> <tr><td><a href="#iv-users">-iv-users</a></td><td>Induction Variable Users</td></tr> <tr><td><a href="#lazy-value-info">-lazy-value-info</a></td><td>Lazy Value Information Analysis</td></tr> -<tr><td><a href="#lda">-lda</a></td><td>Loop Dependence Analysis</td></tr> <tr><td><a href="#libcall-aa">-libcall-aa</a></td><td>LibCall Alias Analysis</td></tr> <tr><td><a href="#lint">-lint</a></td><td>Statically lint-checks LLVM IR</td></tr> <tr><td><a href="#loops">-loops</a></td><td>Natural Loop Information</td></tr> @@ -182,7 +182,6 @@ perl -e '$/ = undef; for (split(/\n/, <>)) { s:^ *///? ?::; print " <p>\n" if ! <tr><td><a href="#strip-debug-declare">-strip-debug-declare</a></td><td>Strip all llvm.dbg.declare intrinsics</td></tr> <tr><td><a href="#strip-nondebug">-strip-nondebug</a></td><td>Strip all symbols, except dbg symbols, from a module</td></tr> <tr><td><a href="#tailcallelim">-tailcallelim</a></td><td>Tail Call Elimination</td></tr> -<tr><td><a href="#tailduplicate">-tailduplicate</a></td><td>Tail Duplication</td></tr> <tr><th colspan="2"><b>UTILITY PASSES</b></th></tr> @@ -251,6 +250,15 @@ perl -e '$/ = undef; for (split(/\n/, <>)) { s:^ *///? ?::; print " <p>\n" if ! <!-------------------------------------------------------------------------- --> <h3> + <a name="da">-da: Dependence Analysis</a> +</h3> +<div> + <p>Dependence analysis framework, which is used to detect dependences in + memory accesses.</p> +</div> + +<!-------------------------------------------------------------------------- --> +<h3> <a name="debug-aa">-debug-aa: AA use debugger</a> </h3> <div> @@ -433,15 +441,6 @@ perl -e '$/ = undef; for (split(/\n/, <>)) { s:^ *///? ?::; print " <p>\n" if ! <!-------------------------------------------------------------------------- --> <h3> - <a name="lda">-lda: Loop Dependence Analysis</a> -</h3> -<div> - <p>Loop dependence analysis framework, which is used to detect dependences in - memory accesses in loops.</p> -</div> - -<!-------------------------------------------------------------------------- --> -<h3> <a name="libcall-aa">-libcall-aa: LibCall Alias Analysis</a> </h3> <div> @@ -1862,22 +1861,6 @@ if (X < 3) {</pre> </ul> </div> -<!-------------------------------------------------------------------------- --> -<h3> - <a name="tailduplicate">-tailduplicate: Tail Duplication</a> -</h3> -<div> - <p> - This pass performs a limited form of tail duplication, intended to simplify - CFGs by removing some unconditional branches. This pass is necessary to - straighten out loops created by the C front-end, but also is capable of - making other code nicer. After this pass is run, the CFG simplify pass - should be run to clean up the mess. - </p> -</div> - -</div> - <!-- ======================================================================= --> <h2><a name="utilities">Utility Passes</a></h2> <div> @@ -2059,7 +2042,7 @@ if (X < 3) {</pre> <a href="mailto:rspencer@x10sys.com">Reid Spencer</a><br> <a href="http://llvm.org/">LLVM Compiler Infrastructure</a><br> - Last modified: $Date: 2012-07-26 00:01:31 +0200 (Thu, 26 Jul 2012) $ + Last modified: $Date: 2012-10-31 18:25:31 +0100 (Wed, 31 Oct 2012) $ </address> </body> diff --git a/docs/Phabricator.rst b/docs/Phabricator.rst new file mode 100644 index 0000000..b454497 --- /dev/null +++ b/docs/Phabricator.rst @@ -0,0 +1,100 @@ +============================= +Code Reviews with Phabricator +============================= + +.. contents:: + :local: + +If you prefer to use a web user interface for code reviews, +you can now submit your patches for Clang and LLVM at +`LLVM's Phabricator`_. + +Sign up +------- + +There are two options to get an account on Phabricator. You can sign up +immediately with one of the supported OAuth account types if you're comfortable +with OAuth, but you can also email chandlerc@gmail.com to request an account to +be created manually without using OAuth. We're working to get support in +Phabricator to directly create new accounts, but currently this is a manual +process. + +Note that if you use your Subversion user name as Phabricator user name, +Phabricator will automatically connect your submits to your Phabricator user in +the `Code Repository Browser`_. + + +Requesting a review via the command line +---------------------------------------- + +Phabricator has a tool called *Arcanist* to upload patches from +the command line. To get you set up, follow the +`Arcanist Quick Start`_ instructions. + +You can learn more about how to use arc to interact with +Phabricator in the `Arcanist User Guide`_. + +Requesting a review via the web interface +----------------------------------------- + +The tool to create and review patches in Phabricator is called +*Differential*. + +Note that you can upload patches created through various diff tools, +including git and svn. To make reviews easier, please always include +**as much context as possible** with your diff! Don't worry, Phabricator +will automatically send a diff with a smaller context in the review +email, but having the full file in the web interface will help the +reviewer understand your code. + +To get a full diff, use one of the following commands (or just use Arcanist +to upload your patch): + +* ``git diff -U999999 other-branch`` +* ``svn diff --diff-cmd=diff -x -U999999`` + +To upload a new patch: + +* Click *Differential*. +* Click *Create Revision*. +* Paste the text diff or upload the patch file. + Note that TODO +* Leave the drop down on *Create a new Revision...* and click *Continue*. +* Enter a descriptive title and summary; add reviewers and mailing + lists that you want to be included in the review. If your patch is + for LLVM, cc llvm-commits; if your patch is for Clang, cc cfe-commits. +* Click *Save*. + +To submit an updated patch: + +* Click *Differential*. +* Click *Create Revision*. +* Paste the updated diff. +* Select the review you want to from the *Attach To* dropdown and click + *Continue*. +* Click *Save*. + +Reviewing code with Phabricator +------------------------------- + +Phabricator allows you to add inline comments as well as overall comments +to a revision. To add an inline comment, select the lines of code you want +to comment on by clicking and dragging the line numbers in the diff pane. + +You can add overall comments or submit your comments at the bottom of the page. + +Phabricator has many useful features, for example allowing you to select +diffs between different versions of the patch as it was reviewed in the +*Revision Update History*. Most features are self descriptive - explore, and +if you have a question, drop by on #llvm in IRC to get help. + +Status +------ + +Currently, we're testing Phabricator for use with Clang/LLVM. Please let us +know whether you like it and what could be improved! + +.. _LLVM's Phabricator: http://llvm-reviews.chandlerc.com +.. _Code Repository Browser: http://llvm-reviews.chandlerc.com/diffusion/ +.. _Arcanist Quick Start: http://www.phabricator.com/docs/phabricator/article/Arcanist_Quick_Start.html +.. _Arcanist User Guide: http://www.phabricator.com/docs/phabricator/article/Arcanist_User_Guide.html diff --git a/docs/ProgrammersManual.html b/docs/ProgrammersManual.html index 5bf499b..7c2e6c8 100644 --- a/docs/ProgrammersManual.html +++ b/docs/ProgrammersManual.html @@ -98,6 +98,7 @@ option</a></li> <li><a href="#dss_valuemap">"llvm/ADT/ValueMap.h"</a></li> <li><a href="#dss_intervalmap">"llvm/ADT/IntervalMap.h"</a></li> <li><a href="#dss_map"><map></a></li> + <li><a href="#dss_mapvector">"llvm/ADT/MapVector.h"</a></li> <li><a href="#dss_inteqclasses">"llvm/ADT/IntEqClasses.h"</a></li> <li><a href="#dss_immutablemap">"llvm/ADT/ImmutableMap.h"</a></li> <li><a href="#dss_othermap">Other Map-Like Container Options</a></li> @@ -432,10 +433,10 @@ if (<a href="#AllocationInst">AllocationInst</a> *AI = dyn_cast<<a href="#All </dl> <p>These five templates can be used with any classes, whether they have a -v-table or not. To add support for these templates, you simply need to add -<tt>classof</tt> static methods to the class you are interested casting -to. Describing this is currently outside the scope of this document, but there -are lots of examples in the LLVM source base.</p> +v-table or not. If you want to add support for these templates, see the +document <a href="HowToSetUpLLVMStyleRTTI.html">How to set up LLVM-style +RTTI for your class hierarchy </a>. +</p> </div> @@ -1848,6 +1849,24 @@ another element takes place).</p> </div> + +<!-- _______________________________________________________________________ --> +<h4> + <a name="dss_mapvector">"llvm/ADT/MapVector.h"</a> +</h4> +<div> + +<p> MapVector<KeyT,ValueT> provides a subset of the DenseMap interface. + The main difference is that the iteration order is guaranteed to be + the insertion order, making it an easy (but somewhat expensive) solution + for non-deterministic iteration over maps of pointers. </p> + +<p> It is implemented by mapping from key to an index in a vector of key,value + pairs. This provides fast lookup and iteration, but has two main drawbacks: + The key is stored twice and it doesn't support removing elements. </p> + +</div> + <!-- _______________________________________________________________________ --> <h4> <a name="dss_inteqclasses">"llvm/ADT/IntEqClasses.h"</a> @@ -4130,7 +4149,7 @@ arguments. An argument has a pointer to the parent Function.</p> <a href="mailto:dhurjati@cs.uiuc.edu">Dinakar Dhurjati</a> and <a href="mailto:sabre@nondot.org">Chris Lattner</a><br> <a href="http://llvm.org/">The LLVM Compiler Infrastructure</a><br> - Last modified: $Date: 2012-07-25 15:46:11 +0200 (Wed, 25 Jul 2012) $ + Last modified: $Date: 2012-10-07 02:56:09 +0200 (Sun, 07 Oct 2012) $ </address> </body> diff --git a/docs/README.txt b/docs/README.txt index 2fbbf98..5ddd599 100644 --- a/docs/README.txt +++ b/docs/README.txt @@ -6,7 +6,7 @@ The LLVM documentation is currently written in two formats: * Plain HTML documentation. * reStructured Text documentation using the Sphinx documentation generator. It - is currently tested with Sphinx 1.1.3. + is currently tested with Sphinx 1.1.3. For more information, see the "Sphinx Introduction for LLVM Developers" document. diff --git a/docs/ReleaseNotes.html b/docs/ReleaseNotes.html index 85448a5..a4b1d58 100644 --- a/docs/ReleaseNotes.html +++ b/docs/ReleaseNotes.html @@ -466,7 +466,45 @@ Release Notes</a>.</h1> <p>In addition to many minor performance tweaks and bug fixes, this release includes a few major enhancements and additions to the optimizers:</p> +<p> Loop Vectorizer - We've added a loop vectorizer and we are now able to + vectorize small loops. The loop vectorizer is disabled by default and + can be enabled using the <b>-mllvm -vectorize-loops</b> flag. + The SIMD vector width can be specified using the flag + <b>-mllvm -force-vector-width=4</b>. + The default value is <b>0</b> which means auto-select. + <br/> + We can now vectorize this function: + + <pre class="doc_code"> + unsigned sum_arrays(int *A, int *B, int start, int end) { + unsigned sum = 0; + for (int i = start; i < end; ++i) + sum += A[i] + B[i] + i; + + return sum; + } + </pre> + + We vectorize under the following loops: + <ul> + <li>The inner most loops must have a single basic block.</li> + <li>The number of iterations are known before the loop starts to execute.</li> + <li>The loop counter needs to be incrimented by one.</li> + <li>The loop trip count <b>can</b> be a variable.</li> + <li>Loops do <b>not</b> need to start at zero.</li> + <li>The induction variable can be used inside the loop.</li> + <li>Loop reductions are supported.</li> + <li>Arrays with affine access pattern do <b>not</b> need to be marked as 'noalias' and are checked at runtime.</li> + <li>...</li> + </ul> + +</p> + +<p>SROA - We've re-written SROA to be significantly more powerful. +<!-- FIXME: Add more text here... --></p> + <ul> + <li>Branch weight metadata is preseved through more of the optimizer.</li> <li>...</li> </ul> @@ -499,13 +537,14 @@ Release Notes</a>.</h1> <div> -<p>We have changed the way that the Type Legalizer legalizes vectors. The type - legalizer now attempts to promote integer elements. This enabled the - implementation of vector-select. Additionally, we see a performance boost on - workloads which use vectors of chars and shorts, since they are now promoted - to 32-bit types, which are better supported by the SIMD instruction set. - Floating point types are still widened as before.</p> +<p>Stack Coloring - We have implemented a new optimization pass + to merge stack objects which are used in disjoin areas of the code. + This optimization reduces the required stack space significantly, in cases + where it is clear to the optimizer that the stack slot is not shared. + We use the lifetime markers to tell the codegen that a certain alloca + is used within a region.</p> +<p> We now merge consecutive loads and stores. </p> <p>We have put a significant amount of work into the code generator infrastructure, which allows us to implement more aggressive algorithms and @@ -608,6 +647,46 @@ Release Notes</a>.</h1> <!--=========================================================================--> <h3> +<a name="PowerPC">PowerPC Target Improvements</a> +</h3> + +<div> + +<ul> +<p>Many fixes and changes across LLVM (and Clang) for better compliance with + the 64-bit PowerPC ELF Application Binary Interface, interoperability with + GCC, and overall 64-bit PowerPC support. Some highlights include:</p> +<ul> + <li> MCJIT support added.</li> + <li> PPC64 relocation support and (small code model) TOC handling + added.</li> + <li> Parameter passing and return value fixes (alignment issues, + padding, varargs support, proper register usage, odd-sized + structure support, float support, extension of return values + for i32 return values).</li> + <li> Fixes in spill and reload code for vector registers.</li> + <li> C++ exception handling enabled.</li> + <li> Changes to remediate double-rounding compatibility issues with + respect to GCC behavior.</li> + <li> Refactoring to disentangle ppc64-elf-linux ABI from Darwin + ppc64 ABI support.</li> + <li> Assorted new test cases and test case fixes (endian and word + size issues).</li> + <li> Fixes for big-endian codegen bugs, instruction encodings, and + instruction constraints.</li> + <li> Implemented -integrated-as support.</li> + <li> Additional support for Altivec compare operations.</li> + <li> IBM long double support.</li> +</ul> +<p>There have also been code generation improvements for both 32- and 64-bit + code. Instruction scheduling support for the Freescale e500mc and e5500 + cores has been added.</p> +</ul> + +</div> + +<!--=========================================================================--> +<h3> <a name="OtherTS">Other Target Specific Improvements</a> </h3> @@ -646,6 +725,14 @@ Release Notes</a>.</h1> <p>In addition, many APIs have changed in this release. Some of the major LLVM API changes are:</p> +<p> We've added a new interface for allowing IR-level passes to access + target-specific information. A new IR-level pass, called + "TargetTransformInfo" provides a number of low-level interfaces. + LSR and LowerInvoke already use the new interface. </p> + +<p> The TargetData structure has been renamed to DataLayout and moved to VMCore +to remove a dependency on Target. </p> + <ul> <li>...</li> </ul> @@ -749,7 +836,7 @@ Release Notes</a>.</h1> src="http://www.w3.org/Icons/valid-html401-blue" alt="Valid HTML 4.01"></a> <a href="http://llvm.org/">LLVM Compiler Infrastructure</a><br> - Last modified: $Date: 2012-07-13 14:44:23 +0200 (Fri, 13 Jul 2012) $ + Last modified: $Date: 2012-11-20 05:22:44 +0100 (Tue, 20 Nov 2012) $ </address> </body> diff --git a/docs/SourceLevelDebugging.html b/docs/SourceLevelDebugging.html index bb72bf3..1dcee54 100644 --- a/docs/SourceLevelDebugging.html +++ b/docs/SourceLevelDebugging.html @@ -2367,11 +2367,11 @@ bucket contents: | HEADER.header_data_len | uint32_t | HEADER_DATA | HeaderData |-------------------------| -| BUCKETS | uint32_t[n_buckets] // 32 bit hash indexes +| BUCKETS | uint32_t[bucket_count] // 32 bit hash indexes |-------------------------| -| HASHES | uint32_t[n_buckets] // 32 bit hash values +| HASHES | uint32_t[hashes_count] // 32 bit hash values |-------------------------| -| OFFSETS | uint32_t[n_buckets] // 32 bit offsets to hash value data +| OFFSETS | uint32_t[hashes_count] // 32 bit offsets to hash value data |-------------------------| | ALL HASH DATA | `-------------------------' @@ -2851,7 +2851,7 @@ int main () <a href="mailto:sabre@nondot.org">Chris Lattner</a><br> <a href="http://llvm.org/">LLVM Compiler Infrastructure</a><br> - Last modified: $Date: 2012-06-02 12:20:22 +0200 (Sat, 02 Jun 2012) $ + Last modified: $Date: 2012-10-09 01:54:10 +0200 (Tue, 09 Oct 2012) $ </address> </body> diff --git a/docs/SphinxQuickstartTemplate.rst b/docs/SphinxQuickstartTemplate.rst new file mode 100644 index 0000000..75d9163 --- /dev/null +++ b/docs/SphinxQuickstartTemplate.rst @@ -0,0 +1,125 @@ +========================== +Sphinx Quickstart Template +========================== + +.. sectionauthor:: Sean Silva <silvas@purdue.edu> + +Introduction and Quickstart +=========================== + +This document is meant to get you writing documentation as fast as possible +even if you have no previous experience with Sphinx. The goal is to take +someone in the state of "I want to write documentation and get it added to +LLVM's docs" and turn that into useful documentation mailed to llvm-commits +with as little nonsense as possible. + +You can find this document in ``docs/SphinxQuickstartTemplate.rst``. You +should copy it, open the new file in your text editor, write your docs, and +then send the new document to llvm-commits for review. + +Focus on *content*. It is easy to fix the Sphinx (reStructuredText) syntax +later if necessary, although reStructuredText tries to imitate common +plain-text conventions so it should be quite natural. A basic knowledge of +reStructuredText syntax is useful when writing the document, so the last +~half of this document (starting with `Example Section`_) gives examples +which should cover 99% of use cases. + +Let me say that again: focus on *content*. + +Once you have finished with the content, please send the ``.rst`` file to +llvm-commits for review. + +Guidelines +========== + +Try to answer the following questions in your first section: + +#. Why would I want to read this document? + +#. What should I know to be able to follow along with this document? + +#. What will I have learned by the end of this document? + +Common names for the first section are ``Introduction``, ``Overview``, or +``Background``. + +If possible, make your document a "how to". Give it a name ``HowTo*.rst`` +like the other "how to" documents. This format is usually the easiest +for another person to understand and also the most useful. + +You generally should not be writing documentation other than a "how to" +unless there is already a "how to" about your topic. The reason for this +is that without a "how to" document to read first, it is difficult for a +person to understand a more advanced document. + +Focus on content (yes, I had to say it again). + +The rest of this document shows example reStructuredText markup constructs +that are meant to be read by you in your text editor after you have copied +this file into a new file for the documentation you are about to write. + +Example Section +=============== + +Your text can be *emphasized*, **bold**, or ``monospace``. + +Use blank lines to separate paragraphs. + +Headings (like ``Example Section`` just above) give your document +structure. Use the same kind of adornments (e.g. ``======`` vs. ``------``) +as are used in this document. The adornment must be the same length as the +text above it. For Vim users, variations of ``yypVr=`` might be handy. + +Example Subsection +------------------ + +Make a link `like this <http://llvm.org/>`_. There is also a more +sophisticated syntax which `can be more readable`_ for longer links since +it disrupts the flow less. You can put the ``.. _`link text`: <URL>`` block +pretty much anywhere later in the document. + +.. _`can be more readable`: http://en.wikipedia.org/wiki/LLVM + +Lists can be made like this: + +#. A list starting with ``#.`` will be automatically numbered. + +#. This is a second list element. + + #. They nest too. + +You can also use unordered lists. + +* Stuff. + + + Deeper stuff. + +* More stuff. + +Example Subsubsection +^^^^^^^^^^^^^^^^^^^^^ + +You can make blocks of code like this: + +.. code-block:: c++ + + int main() { + return 0 + } + +For a shell session, use a ``bash`` code block: + +.. code-block:: bash + + $ echo "Goodbye cruel world!" + $ rm -rf / + +If you need to show LLVM IR use the ``llvm`` code block. + +Hopefully you won't need to be this deep +"""""""""""""""""""""""""""""""""""""""" + +If you need to do fancier things than what has been shown in this document, +you can mail the list or check Sphinx's `reStructuredText Primer`_. + +.. _`reStructuredText Primer`: http://sphinx.pocoo.org/rest.html diff --git a/docs/TestingGuide.html b/docs/TestingGuide.html index 804e929..c313083 100644 --- a/docs/TestingGuide.html +++ b/docs/TestingGuide.html @@ -218,11 +218,11 @@ you can run the LLVM and Clang tests simultaneously using:</p> <p>To run individual tests or subsets of tests, you can use the 'llvm-lit' script which is built as part of LLVM. For example, to run the -'Integer/BitCast.ll' test by itself you can run:</p> +'Integer/BitPacked.ll' test by itself you can run:</p> <div class="doc_code"> <pre> -% llvm-lit ~/llvm/test/Integer/BitCast.ll +% llvm-lit ~/llvm/test/Integer/BitPacked.ll </pre> </div> @@ -798,14 +798,15 @@ define two separate CHECK lines that match on the same line. <p>Sometimes it is necessary to mark a test case as "expected fail" or XFAIL. You can easily mark a test as XFAIL just by including <tt>XFAIL: </tt> on a line near the top of the file. This signals that the test case should succeed - if the test fails. Such test cases are counted separately by the testing tool. To - specify an expected fail, use the XFAIL keyword in the comments of the test - program followed by a colon and one or more regular expressions (separated by - a comma). The regular expressions allow you to XFAIL the test conditionally by - host platform. The regular expressions following the : are matched against the - target triplet for the host machine. If there is a match, the test is expected - to fail. If not, the test is expected to succeed. To XFAIL everywhere just - specify <tt>XFAIL: *</tt>. Here is an example of an <tt>XFAIL</tt> line:</p> + if the test fails. Such test cases are counted separately by the testing + tool. To specify an expected fail, use the XFAIL keyword in the comments of + the test program followed by a colon and one or more failure patterns. Each + failure pattern can be either '*' (to specify fail everywhere), or a part of a + target triple (indicating the test should fail on that platform), or the name + of a configurable feature (for example, "loadable_module"). If there is a + match, the test is expected to fail. If not, the test is expected to + succeed. To XFAIL everywhere just specify <tt>XFAIL: *</tt>. Here is an + example of an <tt>XFAIL</tt> line:</p> <div class="doc_code"> <pre> @@ -909,7 +910,7 @@ the <a href="TestSuiteMakefileGuide.html">Test Suite Makefile Guide.</a></p> John T. Criswell, Daniel Dunbar, Reid Spencer, and Tanya Lattner<br> <a href="http://llvm.org/">The LLVM Compiler Infrastructure</a><br> - Last modified: $Date: 2012-05-08 20:26:07 +0200 (Tue, 08 May 2012) $ + Last modified: $Date: 2012-11-07 18:00:18 +0100 (Wed, 07 Nov 2012) $ </address> </body> </html> diff --git a/docs/WritingAnLLVMBackend.html b/docs/WritingAnLLVMBackend.html index 11517c2..b7fdce4 100644 --- a/docs/WritingAnLLVMBackend.html +++ b/docs/WritingAnLLVMBackend.html @@ -32,6 +32,7 @@ <li><a href="#InstructionSet">Instruction Set</a> <ul> <li><a href="#operandMapping">Instruction Operand Mapping</a></li> + <li><a href="#relationMapping">Instruction Relation Mapping</a></li> <li><a href="#implementInstr">Implement a subclass of TargetInstrInfo</a></li> <li><a href="#branchFolding">Branch Folding and If Conversion</a></li> </ul></li> @@ -314,14 +315,14 @@ represent target components. These methods are named <tt>get*Info</tt>, and are intended to obtain the instruction set (<tt>getInstrInfo</tt>), register set (<tt>getRegisterInfo</tt>), stack frame layout (<tt>getFrameInfo</tt>), and similar information. <tt>XXXTargetMachine</tt> must also implement the -<tt>getTargetData</tt> method to access an object with target-specific data +<tt>getDataLayout</tt> method to access an object with target-specific data characteristics, such as data type size and alignment requirements. </p> <p> For instance, for the SPARC target, the header file <tt>SparcTargetMachine.h</tt> declares prototypes for several <tt>get*Info</tt> -and <tt>getTargetData</tt> methods that simply return a class member. +and <tt>getDataLayout</tt> methods that simply return a class member. </p> <div class="doc_code"> @@ -331,7 +332,7 @@ namespace llvm { class Module; class SparcTargetMachine : public LLVMTargetMachine { - const TargetData DataLayout; // Calculates type size & alignment + const DataLayout DataLayout; // Calculates type size & alignment SparcSubtarget Subtarget; SparcInstrInfo InstrInfo; TargetFrameInfo FrameInfo; @@ -348,7 +349,7 @@ public: virtual const TargetRegisterInfo *getRegisterInfo() const { return &InstrInfo.getRegisterInfo(); } - virtual const TargetData *getTargetData() const { return &DataLayout; } + virtual const DataLayout *getDataLayout() const { return &DataLayout; } static unsigned getModuleMatchQuality(const Module &M); // Pass Pipeline Configuration @@ -364,7 +365,7 @@ public: <li><tt>getInstrInfo()</tt></li> <li><tt>getRegisterInfo()</tt></li> <li><tt>getFrameInfo()</tt></li> -<li><tt>getTargetData()</tt></li> +<li><tt>getDataLayout()</tt></li> <li><tt>getSubtargetImpl()</tt></li> </ul> @@ -1259,6 +1260,29 @@ the <tt>rd</tt>, <tt>rs1</tt>, and <tt>rs2</tt> fields respectively. <!-- ======================================================================= --> <h3> + <a name="relationMapping">Instruction Relation Mapping</a> +</h3> + +<div> + +<p> +This TableGen feature is used to relate instructions with each other. It is +particularly useful when you have multiple instruction formats and need to +switch between them after instruction selection. This entire feature is driven +by relation models which can be defined in <tt>XXXInstrInfo.td</tt> files +according to the target-specific instruction set. Relation models are defined +using <tt>InstrMapping</tt> class as a base. TableGen parses all the models +and generates instruction relation maps using the specified information. +Relation maps are emitted as tables in the <tt>XXXGenInstrInfo.inc</tt> file +along with the functions to query them. For the detailed information on how to +use this feature, please refer to +<a href="HowToUseInstrMappings.html">How to add Instruction Mappings</a> +document. +</p> +</div> + +<!-- ======================================================================= --> +<h3> <a name="implementInstr">Implement a subclass of </a> <a href="CodeGenerator.html#targetinstrinfo">TargetInstrInfo</a> </h3> @@ -2526,7 +2550,7 @@ with assembler. <a href="http://www.woo.com">Mason Woo</a> and <a href="http://misha.brukman.net">Misha Brukman</a><br> <a href="http://llvm.org/">The LLVM Compiler Infrastructure</a> <br> - Last modified: $Date: 2012-04-19 22:20:34 +0200 (Thu, 19 Apr 2012) $ + Last modified: $Date: 2012-10-25 17:54:06 +0200 (Thu, 25 Oct 2012) $ </address> </body> diff --git a/docs/llvm-theme/layout.html b/docs/_themes/llvm-theme/layout.html index 746c2f5..746c2f5 100644 --- a/docs/llvm-theme/layout.html +++ b/docs/_themes/llvm-theme/layout.html diff --git a/docs/llvm-theme/static/contents.png b/docs/_themes/llvm-theme/static/contents.png Binary files differindex 7fb8215..7fb8215 100644 --- a/docs/llvm-theme/static/contents.png +++ b/docs/_themes/llvm-theme/static/contents.png diff --git a/docs/llvm-theme/static/llvm-theme.css b/docs/_themes/llvm-theme/static/llvm-theme.css index f684d00..beab2ca 100644 --- a/docs/llvm-theme/static/llvm-theme.css +++ b/docs/_themes/llvm-theme/static/llvm-theme.css @@ -18,7 +18,6 @@ body { font-family: 'Lucida Grande', 'Lucida Sans Unicode', 'Geneva', 'Verdana', sans-serif; font-size: 14px; - letter-spacing: -0.01em; line-height: 150%; text-align: center; background-color: #BFD1D4; @@ -239,7 +238,6 @@ cite, code, tt { font-family: 'Consolas', 'Deja Vu Sans Mono', 'Bitstream Vera Sans Mono', monospace; font-size: 0.95em; - letter-spacing: 0.01em; } :not(a.reference) > tt { @@ -274,7 +272,6 @@ pre { font-family: 'Consolas', 'Deja Vu Sans Mono', 'Bitstream Vera Sans Mono', monospace; font-size: 0.95em; - letter-spacing: 0.015em; line-height: 120%; padding: 0.5em; border: 1px solid #ccc; diff --git a/docs/llvm-theme/static/logo.png b/docs/_themes/llvm-theme/static/logo.png Binary files differindex 18d424c..18d424c 100644 --- a/docs/llvm-theme/static/logo.png +++ b/docs/_themes/llvm-theme/static/logo.png diff --git a/docs/llvm-theme/static/navigation.png b/docs/_themes/llvm-theme/static/navigation.png Binary files differindex 1081dc1..1081dc1 100644 --- a/docs/llvm-theme/static/navigation.png +++ b/docs/_themes/llvm-theme/static/navigation.png diff --git a/docs/llvm-theme/theme.conf b/docs/_themes/llvm-theme/theme.conf index 573fd78..573fd78 100644 --- a/docs/llvm-theme/theme.conf +++ b/docs/_themes/llvm-theme/theme.conf diff --git a/docs/conf.py b/docs/conf.py index de0585d..a1e9b5f 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -98,7 +98,7 @@ html_theme = 'llvm-theme' #html_theme_options = {} # Add any paths that contain custom themes here, relative to this directory. -html_theme_path = ["."] +html_theme_path = ["_themes"] # The name for this set of Sphinx documents. If None, it defaults to # "<project> v<release> documentation". @@ -134,18 +134,7 @@ html_sidebars = {'index': 'indexsidebar.html'} # Additional templates that should be rendered to pages, maps page names to # template names. -# -# We load all the old-school HTML documentation pages into Sphinx here. -basedir = os.path.dirname(__file__) -html_additional_pages = {} -for directory in ('', 'tutorial'): - for file in os.listdir(os.path.join(basedir, directory)): - if not file.endswith('.html'): - continue - - subpath = os.path.join(directory, file) - name,_ = os.path.splitext(subpath) - html_additional_pages[name] = subpath +#html_additional_pages = {} # If false, no module index is generated. #html_domain_indices = True @@ -226,6 +215,7 @@ man_pages = [] # Automatically derive the list of man pages from the contents of the command # guide subdirectory. +basedir = os.path.dirname(__file__) man_page_authors = "Maintained by The LLVM Team (http://llvm.org/)." command_guide_subpath = 'CommandGuide' command_guide_path = os.path.join(basedir, command_guide_subpath) @@ -237,9 +227,8 @@ for name in os.listdir(command_guide_path): # Otherwise, automatically extract the description. file_subpath = os.path.join(command_guide_subpath, name) with open(os.path.join(command_guide_path, name)) as f: - it = iter(f) - title = it.next()[:-1] - header = it.next()[:-1] + title = f.readline().rstrip('\n') + header = f.readline().rstrip('\n') if len(header) != len(title): print >>sys.stderr, ( diff --git a/docs/index.rst b/docs/index.rst index 53d3e7c..d406b52 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -15,43 +15,43 @@ research projects. Similarly, documentation is broken down into several high-level groupings targeted at different audiences: - * **Design & Overview** +* **Design & Overview** - Several introductory papers and presentations are available at - :ref:`design_and_overview`. + Several introductory papers and presentations are available at + :ref:`design_and_overview`. - * **Publications** +* **Publications** - The list of `publications <http://llvm.org/pubs>`_ based on LLVM. + The list of `publications <http://llvm.org/pubs>`_ based on LLVM. - * **User Guides** +* **User Guides** - Those new to the LLVM system should first vist the :ref:`userguides`. + Those new to the LLVM system should first visit the :ref:`userguides`. - NOTE: If you are a user who is only interested in using LLVM-based - compilers, you should look into `Clang <http://clang.llvm.org>`_ or - `DragonEgg <http://dragonegg.llvm.org>`_ instead. The documentation here is - intended for users who have a need to work with the intermediate LLVM - representation. + NOTE: If you are a user who is only interested in using LLVM-based + compilers, you should look into `Clang <http://clang.llvm.org>`_ or + `DragonEgg <http://dragonegg.llvm.org>`_ instead. The documentation here is + intended for users who have a need to work with the intermediate LLVM + representation. - * **API Clients** +* **API Clients** - Developers of applications which use LLVM as a library should visit the - :ref:`programming`. + Developers of applications which use LLVM as a library should visit the + :ref:`programming`. - * **Subsystems** +* **Subsystems** - API clients and LLVM developers may be interested in the - :ref:`subsystems` documentation. + API clients and LLVM developers may be interested in the + :ref:`subsystems` documentation. - * **Development Process** +* **Development Process** - Additional documentation on the LLVM project can be found at - :ref:`development_process`. + Additional documentation on the LLVM project can be found at + :ref:`development_process`. - * **Mailing Lists** +* **Mailing Lists** - For more information, consider consulting the LLVM :ref:`mailing_lists`. + For more information, consider consulting the LLVM :ref:`mailing_lists`. .. toctree:: :maxdepth: 2 diff --git a/docs/programming.rst b/docs/programming.rst index 27e4301..c4eec59 100644 --- a/docs/programming.rst +++ b/docs/programming.rst @@ -6,14 +6,22 @@ Programming Documentation .. toctree:: :hidden: + Atomics CodingStandards CommandLine + CompilerWriterInfo + ExtendingLLVM + HowToSetUpLLVMStyleRTTI * `LLVM Language Reference Manual <LangRef.html>`_ Defines the LLVM intermediate representation and the assembly form of the different nodes. +* :ref:`atomics` + + Information about LLVM's concurrency model. + * `The LLVM Programmers Manual <ProgrammersManual.html>`_ Introduction to the general layout of the LLVM sourcebase, important classes @@ -28,7 +36,12 @@ Programming Documentation Details the LLVM coding standards and provides useful information on writing efficient C++ code. -* `Extending LLVM <ExtendingLLVM.html>`_ +* :doc:`HowToSetUpLLVMStyleRTTI` + + How to make ``isa<>``, ``dyn_cast<>``, etc. available for clients of your + class hierarchy. + +* :ref:`extending_llvm` Look here to see how to add instructions and intrinsics to LLVM. @@ -38,3 +51,7 @@ Programming Documentation (`tarball <http://llvm.org/doxygen/doxygen.tar.gz>`_) * `ViewVC Repository Browser <http://llvm.org/viewvc/>`_ + +* :ref:`compiler_writer_info` + + A list of helpful links for compiler writers. diff --git a/docs/subsystems.rst b/docs/subsystems.rst index be33295..80d0eed 100644 --- a/docs/subsystems.rst +++ b/docs/subsystems.rst @@ -15,6 +15,9 @@ Subsystem Documentation LinkTimeOptimization SegmentedStacks TableGenFundamentals + DebuggingJITedCode + GoldPlugin + MarkedUpDisassembly * `Writing an LLVM Pass <WritingAnLLVMPass.html>`_ @@ -74,11 +77,11 @@ Subsystem Documentation This document describes the interface between LLVM intermodular optimizer and the linker and its design -* `The LLVM gold plugin <GoldPlugin.html>`_ +* :ref:`gold-plugin` How to build your programs with link-time optimization on Linux. -* `The GDB JIT interface <DebuggingJITedCode.html>`_ +* :ref:`debugging-jited-code` How to debug JITed code with GDB. @@ -89,3 +92,15 @@ Subsystem Documentation * :ref:`segmented_stacks` This document describes segmented stacks and how they are used in LLVM. + +* `Howto: Implementing LLVM Integrated Assembler`_ + + A simple guide for how to implement an LLVM integrated assembler for an + architecture. + +.. _`Howto: Implementing LLVM Integrated Assembler`: http://www.embecosm.com/download/ean10.html + +* :ref:`marked_up_disassembly` + + This document describes the optional rich disassembly output syntax. + diff --git a/docs/tutorial/LangImpl4.html b/docs/tutorial/LangImpl4.html index 3f8d4a4..5e9c656 100644 --- a/docs/tutorial/LangImpl4.html +++ b/docs/tutorial/LangImpl4.html @@ -173,7 +173,7 @@ add a set of optimizations to run. The code looks like this:</p> // Set up the optimizer pipeline. Start with registering info about how the // target lays out data structures. - OurFPM.add(new TargetData(*TheExecutionEngine->getTargetData())); + OurFPM.add(new DataLayout(*TheExecutionEngine->getDataLayout())); // Provide basic AliasAnalysis support for GVN. OurFPM.add(createBasicAliasAnalysisPass()); // Do simple "peephole" optimizations and bit-twiddling optzns. @@ -523,7 +523,7 @@ at runtime.</p> #include "llvm/PassManager.h" #include "llvm/Analysis/Verifier.h" #include "llvm/Analysis/Passes.h" -#include "llvm/Target/TargetData.h" +#include "llvm/DataLayout.h" #include "llvm/Transforms/Scalar.h" #include "llvm/Support/TargetSelect.h" #include <cstdio> @@ -1103,7 +1103,7 @@ int main() { // Set up the optimizer pipeline. Start with registering info about how the // target lays out data structures. - OurFPM.add(new TargetData(*TheExecutionEngine->getTargetData())); + OurFPM.add(new DataLayout(*TheExecutionEngine->getDataLayout())); // Provide basic AliasAnalysis support for GVN. OurFPM.add(createBasicAliasAnalysisPass()); // Do simple "peephole" optimizations and bit-twiddling optzns. @@ -1146,7 +1146,7 @@ int main() { <a href="mailto:sabre@nondot.org">Chris Lattner</a><br> <a href="http://llvm.org/">The LLVM Compiler Infrastructure</a><br> - Last modified: $Date: 2012-06-29 14:38:19 +0200 (Fri, 29 Jun 2012) $ + Last modified: $Date: 2012-10-08 18:39:34 +0200 (Mon, 08 Oct 2012) $ </address> </body> </html> diff --git a/docs/tutorial/LangImpl5.html b/docs/tutorial/LangImpl5.html index a7a3737..9a9fd8c 100644 --- a/docs/tutorial/LangImpl5.html +++ b/docs/tutorial/LangImpl5.html @@ -901,7 +901,7 @@ clang++ -g toy.cpp `llvm-config --cppflags --ldflags --libs core jit native` -O3 #include "llvm/PassManager.h" #include "llvm/Analysis/Verifier.h" #include "llvm/Analysis/Passes.h" -#include "llvm/Target/TargetData.h" +#include "llvm/DataLayout.h" #include "llvm/Transforms/Scalar.h" #include "llvm/Support/TargetSelect.h" #include <cstdio> @@ -1723,7 +1723,7 @@ int main() { // Set up the optimizer pipeline. Start with registering info about how the // target lays out data structures. - OurFPM.add(new TargetData(*TheExecutionEngine->getTargetData())); + OurFPM.add(new DataLayout(*TheExecutionEngine->getDataLayout())); // Provide basic AliasAnalysis support for GVN. OurFPM.add(createBasicAliasAnalysisPass()); // Do simple "peephole" optimizations and bit-twiddling optzns. @@ -1766,7 +1766,7 @@ int main() { <a href="mailto:sabre@nondot.org">Chris Lattner</a><br> <a href="http://llvm.org/">The LLVM Compiler Infrastructure</a><br> - Last modified: $Date: 2012-06-29 14:38:19 +0200 (Fri, 29 Jun 2012) $ + Last modified: $Date: 2012-10-08 18:39:34 +0200 (Mon, 08 Oct 2012) $ </address> </body> </html> diff --git a/docs/tutorial/LangImpl6.html b/docs/tutorial/LangImpl6.html index 1128893..7cd87da 100644 --- a/docs/tutorial/LangImpl6.html +++ b/docs/tutorial/LangImpl6.html @@ -840,7 +840,7 @@ library, although doing that will cause problems on Windows.</p> #include "llvm/PassManager.h" #include "llvm/Analysis/Verifier.h" #include "llvm/Analysis/Passes.h" -#include "llvm/Target/TargetData.h" +#include "llvm/DataLayout.h" #include "llvm/Transforms/Scalar.h" #include "llvm/Support/TargetSelect.h" #include <cstdio> @@ -1780,7 +1780,7 @@ int main() { // Set up the optimizer pipeline. Start with registering info about how the // target lays out data structures. - OurFPM.add(new TargetData(*TheExecutionEngine->getTargetData())); + OurFPM.add(new DataLayout(*TheExecutionEngine->getDataLayout())); // Provide basic AliasAnalysis support for GVN. OurFPM.add(createBasicAliasAnalysisPass()); // Do simple "peephole" optimizations and bit-twiddling optzns. @@ -1823,7 +1823,7 @@ int main() { <a href="mailto:sabre@nondot.org">Chris Lattner</a><br> <a href="http://llvm.org/">The LLVM Compiler Infrastructure</a><br> - Last modified: $Date: 2012-07-31 09:05:57 +0200 (Tue, 31 Jul 2012) $ + Last modified: $Date: 2012-10-08 18:39:34 +0200 (Mon, 08 Oct 2012) $ </address> </body> </html> diff --git a/docs/tutorial/LangImpl7.html b/docs/tutorial/LangImpl7.html index f1fe404..4d5a4aa 100644 --- a/docs/tutorial/LangImpl7.html +++ b/docs/tutorial/LangImpl7.html @@ -524,7 +524,7 @@ good codegen once again:</p> <pre> // Set up the optimizer pipeline. Start with registering info about how the // target lays out data structures. - OurFPM.add(new TargetData(*TheExecutionEngine->getTargetData())); + OurFPM.add(new DataLayout(*TheExecutionEngine->getDataLayout())); <b>// Promote allocas to registers. OurFPM.add(createPromoteMemoryToRegisterPass());</b> // Do simple "peephole" optimizations and bit-twiddling optzns. @@ -1008,7 +1008,7 @@ clang++ -g toy.cpp `llvm-config --cppflags --ldflags --libs core jit native` -O3 #include "llvm/PassManager.h" #include "llvm/Analysis/Verifier.h" #include "llvm/Analysis/Passes.h" -#include "llvm/Target/TargetData.h" +#include "llvm/DataLayout.h" #include "llvm/Transforms/Scalar.h" #include "llvm/Support/TargetSelect.h" #include <cstdio> @@ -2113,7 +2113,7 @@ int main() { // Set up the optimizer pipeline. Start with registering info about how the // target lays out data structures. - OurFPM.add(new TargetData(*TheExecutionEngine->getTargetData())); + OurFPM.add(new DataLayout(*TheExecutionEngine->getDataLayout())); // Provide basic AliasAnalysis support for GVN. OurFPM.add(createBasicAliasAnalysisPass()); // Promote allocas to registers. @@ -2158,7 +2158,7 @@ int main() { <a href="mailto:sabre@nondot.org">Chris Lattner</a><br> <a href="http://llvm.org/">The LLVM Compiler Infrastructure</a><br> - Last modified: $Date: 2012-06-29 14:38:19 +0200 (Fri, 29 Jun 2012) $ + Last modified: $Date: 2012-10-08 18:39:34 +0200 (Mon, 08 Oct 2012) $ </address> </body> </html> diff --git a/docs/tutorial/OCamlLangImpl4.html b/docs/tutorial/OCamlLangImpl4.html index e3e2469..d3cfd3d 100644 --- a/docs/tutorial/OCamlLangImpl4.html +++ b/docs/tutorial/OCamlLangImpl4.html @@ -189,7 +189,7 @@ add a set of optimizations to run. The code looks like this:</p> (* Set up the optimizer pipeline. Start with registering info about how the * target lays out data structures. *) - TargetData.add (ExecutionEngine.target_data the_execution_engine) the_fpm; + DataLayout.add (ExecutionEngine.target_data the_execution_engine) the_fpm; (* Do simple "peephole" optimizations and bit-twiddling optzn. *) add_instruction_combining the_fpm; @@ -965,7 +965,7 @@ let main () = (* Set up the optimizer pipeline. Start with registering info about how the * target lays out data structures. *) - TargetData.add (ExecutionEngine.target_data the_execution_engine) the_fpm; + DataLayout.add (ExecutionEngine.target_data the_execution_engine) the_fpm; (* Do simple "peephole" optimizations and bit-twiddling optzn. *) add_instruction_combination the_fpm; @@ -1020,7 +1020,7 @@ extern double putchard(double X) { <a href="mailto:sabre@nondot.org">Chris Lattner</a><br> <a href="mailto:idadesub@users.sourceforge.net">Erick Tryzelaar</a><br> <a href="http://llvm.org/">The LLVM Compiler Infrastructure</a><br> - Last modified: $Date: 2012-05-03 00:46:36 +0200 (Thu, 03 May 2012) $ + Last modified: $Date: 2012-10-08 18:39:34 +0200 (Mon, 08 Oct 2012) $ </address> </body> </html> diff --git a/docs/tutorial/OCamlLangImpl5.html b/docs/tutorial/OCamlLangImpl5.html index 994957e..0a759ac 100644 --- a/docs/tutorial/OCamlLangImpl5.html +++ b/docs/tutorial/OCamlLangImpl5.html @@ -1498,7 +1498,7 @@ let main () = (* Set up the optimizer pipeline. Start with registering info about how the * target lays out data structures. *) - TargetData.add (ExecutionEngine.target_data the_execution_engine) the_fpm; + DataLayout.add (ExecutionEngine.target_data the_execution_engine) the_fpm; (* Do simple "peephole" optimizations and bit-twiddling optzn. *) add_instruction_combination the_fpm; @@ -1554,7 +1554,7 @@ operators</a> <a href="mailto:sabre@nondot.org">Chris Lattner</a><br> <a href="mailto:idadesub@users.sourceforge.net">Erick Tryzelaar</a><br> <a href="http://llvm.org/">The LLVM Compiler Infrastructure</a><br> - Last modified: $Date: 2012-05-03 00:46:36 +0200 (Thu, 03 May 2012) $ + Last modified: $Date: 2012-10-08 18:39:34 +0200 (Mon, 08 Oct 2012) $ </address> </body> </html> diff --git a/docs/tutorial/OCamlLangImpl6.html b/docs/tutorial/OCamlLangImpl6.html index cef3884..db25240 100644 --- a/docs/tutorial/OCamlLangImpl6.html +++ b/docs/tutorial/OCamlLangImpl6.html @@ -1506,7 +1506,7 @@ let main () = (* Set up the optimizer pipeline. Start with registering info about how the * target lays out data structures. *) - TargetData.add (ExecutionEngine.target_data the_execution_engine) the_fpm; + DataLayout.add (ExecutionEngine.target_data the_execution_engine) the_fpm; (* Do simple "peephole" optimizations and bit-twiddling optzn. *) add_instruction_combination the_fpm; @@ -1568,7 +1568,7 @@ SSA construction</a> <a href="mailto:sabre@nondot.org">Chris Lattner</a><br> <a href="mailto:idadesub@users.sourceforge.net">Erick Tryzelaar</a><br> <a href="http://llvm.org/">The LLVM Compiler Infrastructure</a><br> - Last modified: $Date: 2012-07-31 09:05:57 +0200 (Tue, 31 Jul 2012) $ + Last modified: $Date: 2012-10-08 18:39:34 +0200 (Mon, 08 Oct 2012) $ </address> </body> </html> diff --git a/docs/tutorial/OCamlLangImpl7.html b/docs/tutorial/OCamlLangImpl7.html index abe8913..aa30555 100644 --- a/docs/tutorial/OCamlLangImpl7.html +++ b/docs/tutorial/OCamlLangImpl7.html @@ -545,7 +545,7 @@ let main () = (* Set up the optimizer pipeline. Start with registering info about how the * target lays out data structures. *) - TargetData.add (ExecutionEngine.target_data the_execution_engine) the_fpm; + DataLayout.add (ExecutionEngine.target_data the_execution_engine) the_fpm; <b>(* Promote allocas to registers. *) add_memory_to_register_promotion the_fpm;</b> @@ -1834,7 +1834,7 @@ let main () = (* Set up the optimizer pipeline. Start with registering info about how the * target lays out data structures. *) - TargetData.add (ExecutionEngine.target_data the_execution_engine) the_fpm; + DataLayout.add (ExecutionEngine.target_data the_execution_engine) the_fpm; (* Promote allocas to registers. *) add_memory_to_register_promotion the_fpm; @@ -1898,7 +1898,7 @@ extern double printd(double X) { <a href="mailto:sabre@nondot.org">Chris Lattner</a><br> <a href="http://llvm.org/">The LLVM Compiler Infrastructure</a><br> <a href="mailto:idadesub@users.sourceforge.net">Erick Tryzelaar</a><br> - Last modified: $Date: 2012-05-03 00:46:36 +0200 (Thu, 03 May 2012) $ + Last modified: $Date: 2012-10-08 18:39:34 +0200 (Mon, 08 Oct 2012) $ </address> </body> </html> diff --git a/docs/userguides.rst b/docs/userguides.rst index 26a5a8c..8c1554d 100644 --- a/docs/userguides.rst +++ b/docs/userguides.rst @@ -7,14 +7,21 @@ User Guides :hidden: CMake + HowToBuildOnARM CommandGuide/index DeveloperPolicy + GettingStarted GettingStartedVS FAQ Lexicon Packaging + HowToAddABuilder + yaml2obj + HowToSubmitABug + SphinxQuickstartTemplate + Phabricator -* `The LLVM Getting Started Guide <GettingStarted.html>`_ +* :ref:`getting_started` Discusses how to get up and running quickly with the LLVM infrastructure. Everything from unpacking and compilation of the distribution to execution @@ -24,7 +31,11 @@ User Guides An addendum to the main Getting Started guide for those using the `CMake build system <http://www.cmake.org>`_. - + +* :ref:`how_to_build_on_arm` + + Notes on building and testing LLVM/Clang on ARM. + * `Getting Started with the LLVM System using Microsoft Visual Studio <GettingStartedVS.html>`_ @@ -57,10 +68,14 @@ User Guides This describes new features, known bugs, and other limitations. -* `How to Submit A Bug Report <HowToSubmitABug.html>`_ +* :ref:`how-to-submit-a-bug-report` Instructions for properly submitting information about any bugs you run into in the LLVM system. +* :doc:`SphinxQuickstartTemplate` + + A template + tutorial for writing new Sphinx documentation. It is meant + to be read in source form. * `LLVM Testing Infrastructure Guide <TestingGuide.html>`_ @@ -78,7 +93,7 @@ User Guides Definition of acronyms, terms and concepts used in LLVM. -* `How To Add Your Build Configuration To LLVM Buildbot Infrastructure <HowToAddABuilder.html>`_ +* :ref:`how_to_add_a_builder` Instructions for adding new builder to LLVM buildbot master. diff --git a/docs/yaml2obj.rst b/docs/yaml2obj.rst index cb59162..d051e7e 100644 --- a/docs/yaml2obj.rst +++ b/docs/yaml2obj.rst @@ -6,9 +6,9 @@ yaml2obj yaml2obj takes a YAML description of an object file and converts it to a binary file. - $ yaml2py input-file + $ yaml2obj input-file -.. program:: yaml2py +.. program:: yaml2obj Outputs the binary to stdout. |