[www-releases] r257950 - Add 3.7.1 docs
Tom Stellard via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 15 15:13:20 PST 2016
Added: www-releases/trunk/3.7.1/docs/LinkTimeOptimization.html
URL: http://llvm.org/viewvc/llvm-project/www-releases/trunk/3.7.1/docs/LinkTimeOptimization.html?rev=257950&view=auto
==============================================================================
--- www-releases/trunk/3.7.1/docs/LinkTimeOptimization.html (added)
+++ www-releases/trunk/3.7.1/docs/LinkTimeOptimization.html Fri Jan 15 17:13:16 2016
@@ -0,0 +1,370 @@
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
+ <title>LLVM Link Time Optimization: Design and Implementation — LLVM 3.7 documentation</title>
+
+ <link rel="stylesheet" href="_static/llvm-theme.css" type="text/css" />
+ <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
+
+ <script type="text/javascript">
+ var DOCUMENTATION_OPTIONS = {
+ URL_ROOT: './',
+ VERSION: '3.7',
+ COLLAPSE_INDEX: false,
+ FILE_SUFFIX: '.html',
+ HAS_SOURCE: true
+ };
+ </script>
+ <script type="text/javascript" src="_static/jquery.js"></script>
+ <script type="text/javascript" src="_static/underscore.js"></script>
+ <script type="text/javascript" src="_static/doctools.js"></script>
+ <link rel="top" title="LLVM 3.7 documentation" href="index.html" />
+ <link rel="next" title="Segmented Stacks in LLVM" href="SegmentedStacks.html" />
+ <link rel="prev" title="Exception Handling in LLVM" href="ExceptionHandling.html" />
+<style type="text/css">
+ table.right { float: right; margin-left: 20px; }
+ table.right td { border: 1px solid #ccc; }
+</style>
+
+ </head>
+ <body>
+<div class="logo">
+ <a href="index.html">
+ <img src="_static/logo.png"
+ alt="LLVM Logo" width="250" height="88"/></a>
+</div>
+
+ <div class="related">
+ <h3>Navigation</h3>
+ <ul>
+ <li class="right" style="margin-right: 10px">
+ <a href="genindex.html" title="General Index"
+ accesskey="I">index</a></li>
+ <li class="right" >
+ <a href="SegmentedStacks.html" title="Segmented Stacks in LLVM"
+ accesskey="N">next</a> |</li>
+ <li class="right" >
+ <a href="ExceptionHandling.html" title="Exception Handling in LLVM"
+ accesskey="P">previous</a> |</li>
+ <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+ <li><a href="index.html">Documentation</a>»</li>
+
+ </ul>
+ </div>
+
+
+ <div class="document">
+ <div class="documentwrapper">
+ <div class="body">
+
+ <div class="section" id="llvm-link-time-optimization-design-and-implementation">
+<h1>LLVM Link Time Optimization: Design and Implementation<a class="headerlink" href="#llvm-link-time-optimization-design-and-implementation" title="Permalink to this headline">¶</a></h1>
+<div class="contents local topic" id="contents">
+<ul class="simple">
+<li><a class="reference internal" href="#description" id="id2">Description</a></li>
+<li><a class="reference internal" href="#design-philosophy" id="id3">Design Philosophy</a><ul>
+<li><a class="reference internal" href="#example-of-link-time-optimization" id="id4">Example of link time optimization</a></li>
+<li><a class="reference internal" href="#alternative-approaches" id="id5">Alternative Approaches</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#multi-phase-communication-between-liblto-and-linker" id="id6">Multi-phase communication between <tt class="docutils literal"><span class="pre">libLTO</span></tt> and linker</a><ul>
+<li><a class="reference internal" href="#phase-1-read-llvm-bitcode-files" id="id7">Phase 1 : Read LLVM Bitcode Files</a></li>
+<li><a class="reference internal" href="#phase-2-symbol-resolution" id="id8">Phase 2 : Symbol Resolution</a></li>
+<li><a class="reference internal" href="#phase-3-optimize-bitcode-files" id="id9">Phase 3 : Optimize Bitcode Files</a></li>
+<li><a class="reference internal" href="#phase-4-symbol-resolution-after-optimization" id="id10">Phase 4 : Symbol Resolution after optimization</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#liblto" id="id11"><tt class="docutils literal"><span class="pre">libLTO</span></tt></a><ul>
+<li><a class="reference internal" href="#lto-module-t" id="id12"><tt class="docutils literal"><span class="pre">lto_module_t</span></tt></a></li>
+<li><a class="reference internal" href="#lto-code-gen-t" id="id13"><tt class="docutils literal"><span class="pre">lto_code_gen_t</span></tt></a></li>
+</ul>
+</li>
+</ul>
+</div>
+<div class="section" id="description">
+<h2><a class="toc-backref" href="#id2">Description</a><a class="headerlink" href="#description" title="Permalink to this headline">¶</a></h2>
+<p>LLVM features powerful intermodular optimizations which can be used at link
+time. Link Time Optimization (LTO) is another name for intermodular
+optimization when performed during the link stage. This document describes the
+interface and design between the LTO optimizer and the linker.</p>
+</div>
+<div class="section" id="design-philosophy">
+<h2><a class="toc-backref" href="#id3">Design Philosophy</a><a class="headerlink" href="#design-philosophy" title="Permalink to this headline">¶</a></h2>
+<p>The LLVM Link Time Optimizer provides complete transparency, while doing
+intermodular optimization, in the compiler tool chain. Its main goal is to let
+the developer take advantage of intermodular optimizations without making any
+significant changes to the developer’s makefiles or build system. This is
+achieved through tight integration with the linker. In this model, the linker
+treates LLVM bitcode files like native object files and allows mixing and
+matching among them. The linker uses <a class="reference internal" href="#liblto">libLTO</a>, a shared object, to handle LLVM
+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.</p>
+<div class="section" id="example-of-link-time-optimization">
+<span id="liblto-example"></span><h3><a class="toc-backref" href="#id4">Example of link time optimization</a><a class="headerlink" href="#example-of-link-time-optimization" title="Permalink to this headline">¶</a></h3>
+<p>The following example illustrates the advantages of LTO’s integrated approach
+and clean interface. This example requires a system linker which supports LTO
+through the interface described in this document. Here, clang transparently
+invokes system linker.</p>
+<ul class="simple">
+<li>Input source file <tt class="docutils literal"><span class="pre">a.c</span></tt> is compiled into LLVM bitcode form.</li>
+<li>Input source file <tt class="docutils literal"><span class="pre">main.c</span></tt> is compiled into native object code.</li>
+</ul>
+<div class="highlight-c++"><div class="highlight"><pre><span class="o">---</span> <span class="n">a</span><span class="p">.</span><span class="n">h</span> <span class="o">---</span>
+<span class="k">extern</span> <span class="kt">int</span> <span class="n">foo1</span><span class="p">(</span><span class="kt">void</span><span class="p">);</span>
+<span class="k">extern</span> <span class="kt">void</span> <span class="nf">foo2</span><span class="p">(</span><span class="kt">void</span><span class="p">);</span>
+<span class="k">extern</span> <span class="kt">void</span> <span class="nf">foo4</span><span class="p">(</span><span class="kt">void</span><span class="p">);</span>
+
+<span class="o">---</span> <span class="n">a</span><span class="p">.</span><span class="n">c</span> <span class="o">---</span>
+<span class="cp">#include "a.h"</span>
+
+<span class="k">static</span> <span class="kt">signed</span> <span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
+
+<span class="kt">void</span> <span class="nf">foo2</span><span class="p">(</span><span class="kt">void</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">i</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span><span class="p">;</span>
+<span class="p">}</span>
+
+<span class="k">static</span> <span class="kt">int</span> <span class="nf">foo3</span><span class="p">()</span> <span class="p">{</span>
+ <span class="n">foo4</span><span class="p">();</span>
+ <span class="k">return</span> <span class="mi">10</span><span class="p">;</span>
+<span class="p">}</span>
+
+<span class="kt">int</span> <span class="nf">foo1</span><span class="p">(</span><span class="kt">void</span><span class="p">)</span> <span class="p">{</span>
+ <span class="kt">int</span> <span class="n">data</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="n">i</span> <span class="o"><</span> <span class="mi">0</span><span class="p">)</span>
+ <span class="n">data</span> <span class="o">=</span> <span class="n">foo3</span><span class="p">();</span>
+
+ <span class="n">data</span> <span class="o">=</span> <span class="n">data</span> <span class="o">+</span> <span class="mi">42</span><span class="p">;</span>
+ <span class="k">return</span> <span class="n">data</span><span class="p">;</span>
+<span class="p">}</span>
+
+<span class="o">---</span> <span class="n">main</span><span class="p">.</span><span class="n">c</span> <span class="o">---</span>
+<span class="cp">#include <stdio.h></span>
+<span class="cp">#include "a.h"</span>
+
+<span class="kt">void</span> <span class="n">foo4</span><span class="p">(</span><span class="kt">void</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">printf</span><span class="p">(</span><span class="s">"Hi</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span>
+<span class="p">}</span>
+
+<span class="kt">int</span> <span class="n">main</span><span class="p">()</span> <span class="p">{</span>
+ <span class="k">return</span> <span class="n">foo1</span><span class="p">();</span>
+<span class="p">}</span>
+</pre></div>
+</div>
+<p>To compile, run:</p>
+<div class="highlight-console"><div class="highlight"><pre><span class="gp">%</span> clang -emit-llvm -c a.c -o a.o <span class="c"># <-- a.o is LLVM bitcode file</span>
+<span class="gp">%</span> clang -c main.c -o main.o <span class="c"># <-- main.o is native object file</span>
+<span class="gp">%</span> clang a.o main.o -o main <span class="c"># <-- standard link command without modifications</span>
+</pre></div>
+</div>
+<ul class="simple">
+<li>In this example, the linker recognizes that <tt class="docutils literal"><span class="pre">foo2()</span></tt> is an externally
+visible symbol defined in LLVM bitcode file. The linker completes its usual
+symbol resolution pass and finds that <tt class="docutils literal"><span class="pre">foo2()</span></tt> is not used
+anywhere. This information is used by the LLVM optimizer and it
+removes <tt class="docutils literal"><span class="pre">foo2()</span></tt>.</li>
+<li>As soon as <tt class="docutils literal"><span class="pre">foo2()</span></tt> is removed, the optimizer recognizes that condition <tt class="docutils literal"><span class="pre">i</span>
+<span class="pre"><</span> <span class="pre">0</span></tt> is always false, which means <tt class="docutils literal"><span class="pre">foo3()</span></tt> is never used. Hence, the
+optimizer also removes <tt class="docutils literal"><span class="pre">foo3()</span></tt>.</li>
+<li>And this in turn, enables linker to remove <tt class="docutils literal"><span class="pre">foo4()</span></tt>.</li>
+</ul>
+<p>This example illustrates the advantage of tight integration with the
+linker. Here, the optimizer can not remove <tt class="docutils literal"><span class="pre">foo3()</span></tt> without the linker’s
+input.</p>
+</div>
+<div class="section" id="alternative-approaches">
+<h3><a class="toc-backref" href="#id5">Alternative Approaches</a><a class="headerlink" href="#alternative-approaches" title="Permalink to this headline">¶</a></h3>
+<dl class="docutils">
+<dt><strong>Compiler driver invokes link time optimizer separately.</strong></dt>
+<dd>In this model the link time optimizer is not able to take advantage of
+information collected during the linker’s normal symbol resolution phase.
+In the above example, the optimizer can not remove <tt class="docutils literal"><span class="pre">foo2()</span></tt> without the
+linker’s input because it is externally visible. This in turn prohibits the
+optimizer from removing <tt class="docutils literal"><span class="pre">foo3()</span></tt>.</dd>
+<dt><strong>Use separate tool to collect symbol information from all object files.</strong></dt>
+<dd>In this model, a new, separate, tool or library replicates the linker’s
+capability to collect information for link time optimization. Not only is
+this code duplication difficult to justify, but it also has several other
+disadvantages. For example, the linking semantics and the features provided
+by the linker on various platform are not unique. This means, this new tool
+needs to support all such features and platforms in one super tool or a
+separate tool per platform is required. This increases maintenance cost for
+link time optimizer significantly, which is not necessary. This approach
+also requires staying synchronized with linker developements on various
+platforms, which is not the main focus of the link time optimizer. Finally,
+this approach increases end user’s build time due to the duplication of work
+done by this separate tool and the linker itself.</dd>
+</dl>
+</div>
+</div>
+<div class="section" id="multi-phase-communication-between-liblto-and-linker">
+<h2><a class="toc-backref" href="#id6">Multi-phase communication between <tt class="docutils literal"><span class="pre">libLTO</span></tt> and linker</a><a class="headerlink" href="#multi-phase-communication-between-liblto-and-linker" title="Permalink to this headline">¶</a></h2>
+<p>The linker collects information about symbol definitions and uses in various
+link objects which is more accurate than any information collected by other
+tools during typical build cycles. The linker collects this information by
+looking at the definitions and uses of symbols in native .o files and using
+symbol visibility information. The linker also uses user-supplied information,
+such as a list of exported symbols. LLVM optimizer collects control flow
+information, data flow information and knows much more about program structure
+from the optimizer’s point of view. Our goal is to take advantage of tight
+integration between the linker and the optimizer by sharing this information
+during various linking phases.</p>
+<div class="section" id="phase-1-read-llvm-bitcode-files">
+<h3><a class="toc-backref" href="#id7">Phase 1 : Read LLVM Bitcode Files</a><a class="headerlink" href="#phase-1-read-llvm-bitcode-files" title="Permalink to this headline">¶</a></h3>
+<p>The linker first reads all object files in natural order and collects symbol
+information. This includes native object files as well as LLVM bitcode files.
+To minimize the cost to the linker in the case that all .o files are native
+object files, the linker only calls <tt class="docutils literal"><span class="pre">lto_module_create()</span></tt> when a supplied
+object file is found to not be a native object file. If <tt class="docutils literal"><span class="pre">lto_module_create()</span></tt>
+returns that the file is an LLVM bitcode file, the linker then iterates over the
+module using <tt class="docutils literal"><span class="pre">lto_module_get_symbol_name()</span></tt> and
+<tt class="docutils literal"><span class="pre">lto_module_get_symbol_attribute()</span></tt> to get all symbols defined and referenced.
+This information is added to the linker’s global symbol table.</p>
+<p>The lto* functions are all implemented in a shared object libLTO. This allows
+the LLVM LTO code to be updated independently of the linker tool. On platforms
+that support it, the shared object is lazily loaded.</p>
+</div>
+<div class="section" id="phase-2-symbol-resolution">
+<h3><a class="toc-backref" href="#id8">Phase 2 : Symbol Resolution</a><a class="headerlink" href="#phase-2-symbol-resolution" title="Permalink to this headline">¶</a></h3>
+<p>In this stage, the linker resolves symbols using global symbol table. It may
+report undefined symbol errors, read archive members, replace weak symbols, etc.
+The linker is able to do this seamlessly even though it does not know the exact
+content of input LLVM bitcode files. If dead code stripping is enabled then the
+linker collects the list of live symbols.</p>
+</div>
+<div class="section" id="phase-3-optimize-bitcode-files">
+<h3><a class="toc-backref" href="#id9">Phase 3 : Optimize Bitcode Files</a><a class="headerlink" href="#phase-3-optimize-bitcode-files" title="Permalink to this headline">¶</a></h3>
+<p>After symbol resolution, the linker tells the LTO shared object which symbols
+are needed by native object files. In the example above, the linker reports
+that only <tt class="docutils literal"><span class="pre">foo1()</span></tt> is used by native object files using
+<tt class="docutils literal"><span class="pre">lto_codegen_add_must_preserve_symbol()</span></tt>. Next the linker invokes the LLVM
+optimizer and code generators using <tt class="docutils literal"><span class="pre">lto_codegen_compile()</span></tt> which returns a
+native object file creating by merging the LLVM bitcode files and applying
+various optimization passes.</p>
+</div>
+<div class="section" id="phase-4-symbol-resolution-after-optimization">
+<h3><a class="toc-backref" href="#id10">Phase 4 : Symbol Resolution after optimization</a><a class="headerlink" href="#phase-4-symbol-resolution-after-optimization" title="Permalink to this headline">¶</a></h3>
+<p>In this phase, the linker reads optimized a native object file and updates the
+internal global symbol table to reflect any changes. The linker also collects
+information about any changes in use of external symbols by LLVM bitcode
+files. In the example above, the linker notes that <tt class="docutils literal"><span class="pre">foo4()</span></tt> is not used any
+more. If dead code stripping is enabled then the linker refreshes the live
+symbol information appropriately and performs dead code stripping.</p>
+<p>After this phase, the linker continues linking as if it never saw LLVM bitcode
+files.</p>
+</div>
+</div>
+<div class="section" id="liblto">
+<span id="id1"></span><h2><a class="toc-backref" href="#id11"><tt class="docutils literal"><span class="pre">libLTO</span></tt></a><a class="headerlink" href="#liblto" title="Permalink to this headline">¶</a></h2>
+<p><tt class="docutils literal"><span class="pre">libLTO</span></tt> is a shared object that is part of the LLVM tools, and is intended
+for use by a linker. <tt class="docutils literal"><span class="pre">libLTO</span></tt> provides an abstract C interface to use the LLVM
+interprocedural optimizer without exposing details of LLVM’s internals. The
+intention is to keep the interface as stable as possible even when the LLVM
+optimizer continues to evolve. It should even be possible for a completely
+different compilation technology to provide a different libLTO that works with
+their object files and the standard linker tool.</p>
+<div class="section" id="lto-module-t">
+<h3><a class="toc-backref" href="#id12"><tt class="docutils literal"><span class="pre">lto_module_t</span></tt></a><a class="headerlink" href="#lto-module-t" title="Permalink to this headline">¶</a></h3>
+<p>A non-native object file is handled via an <tt class="docutils literal"><span class="pre">lto_module_t</span></tt>. The following
+functions allow the linker to check if a file (on disk or in a memory buffer) is
+a file which libLTO can process:</p>
+<div class="highlight-c"><div class="highlight"><pre><span class="n">lto_module_is_object_file</span><span class="p">(</span><span class="k">const</span> <span class="kt">char</span><span class="o">*</span><span class="p">)</span>
+<span class="n">lto_module_is_object_file_for_target</span><span class="p">(</span><span class="k">const</span> <span class="kt">char</span><span class="o">*</span><span class="p">,</span> <span class="k">const</span> <span class="kt">char</span><span class="o">*</span><span class="p">)</span>
+<span class="n">lto_module_is_object_file_in_memory</span><span class="p">(</span><span class="k">const</span> <span class="kt">void</span><span class="o">*</span><span class="p">,</span> <span class="kt">size_t</span><span class="p">)</span>
+<span class="n">lto_module_is_object_file_in_memory_for_target</span><span class="p">(</span><span class="k">const</span> <span class="kt">void</span><span class="o">*</span><span class="p">,</span> <span class="kt">size_t</span><span class="p">,</span> <span class="k">const</span> <span class="kt">char</span><span class="o">*</span><span class="p">)</span>
+</pre></div>
+</div>
+<p>If the object file can be processed by <tt class="docutils literal"><span class="pre">libLTO</span></tt>, the linker creates a
+<tt class="docutils literal"><span class="pre">lto_module_t</span></tt> by using one of:</p>
+<div class="highlight-c"><div class="highlight"><pre><span class="n">lto_module_create</span><span class="p">(</span><span class="k">const</span> <span class="kt">char</span><span class="o">*</span><span class="p">)</span>
+<span class="n">lto_module_create_from_memory</span><span class="p">(</span><span class="k">const</span> <span class="kt">void</span><span class="o">*</span><span class="p">,</span> <span class="kt">size_t</span><span class="p">)</span>
+</pre></div>
+</div>
+<p>and when done, the handle is released via</p>
+<div class="highlight-c"><div class="highlight"><pre><span class="n">lto_module_dispose</span><span class="p">(</span><span class="kt">lto_module_t</span><span class="p">)</span>
+</pre></div>
+</div>
+<p>The linker can introspect the non-native object file by getting the number of
+symbols and getting the name and attributes of each symbol via:</p>
+<div class="highlight-c"><div class="highlight"><pre><span class="n">lto_module_get_num_symbols</span><span class="p">(</span><span class="kt">lto_module_t</span><span class="p">)</span>
+<span class="n">lto_module_get_symbol_name</span><span class="p">(</span><span class="kt">lto_module_t</span><span class="p">,</span> <span class="kt">unsigned</span> <span class="kt">int</span><span class="p">)</span>
+<span class="n">lto_module_get_symbol_attribute</span><span class="p">(</span><span class="kt">lto_module_t</span><span class="p">,</span> <span class="kt">unsigned</span> <span class="kt">int</span><span class="p">)</span>
+</pre></div>
+</div>
+<p>The attributes of a symbol include the alignment, visibility, and kind.</p>
+</div>
+<div class="section" id="lto-code-gen-t">
+<h3><a class="toc-backref" href="#id13"><tt class="docutils literal"><span class="pre">lto_code_gen_t</span></tt></a><a class="headerlink" href="#lto-code-gen-t" title="Permalink to this headline">¶</a></h3>
+<p>Once the linker has loaded each non-native object files into an
+<tt class="docutils literal"><span class="pre">lto_module_t</span></tt>, it can request <tt class="docutils literal"><span class="pre">libLTO</span></tt> to process them all and generate a
+native object file. This is done in a couple of steps. First, a code generator
+is created with:</p>
+<div class="highlight-c"><div class="highlight"><pre><span class="n">lto_codegen_create</span><span class="p">()</span>
+</pre></div>
+</div>
+<p>Then, each non-native object file is added to the code generator with:</p>
+<div class="highlight-c"><div class="highlight"><pre><span class="n">lto_codegen_add_module</span><span class="p">(</span><span class="kt">lto_code_gen_t</span><span class="p">,</span> <span class="kt">lto_module_t</span><span class="p">)</span>
+</pre></div>
+</div>
+<p>The linker then has the option of setting some codegen options. Whether or not
+to generate DWARF debug info is set with:</p>
+<div class="highlight-c"><div class="highlight"><pre><span class="n">lto_codegen_set_debug_model</span><span class="p">(</span><span class="kt">lto_code_gen_t</span><span class="p">)</span>
+</pre></div>
+</div>
+<p>Which kind of position independence is set with:</p>
+<div class="highlight-c"><div class="highlight"><pre><span class="n">lto_codegen_set_pic_model</span><span class="p">(</span><span class="kt">lto_code_gen_t</span><span class="p">)</span>
+</pre></div>
+</div>
+<p>And each symbol that is referenced by a native object file or otherwise must not
+be optimized away is set with:</p>
+<div class="highlight-c"><div class="highlight"><pre><span class="n">lto_codegen_add_must_preserve_symbol</span><span class="p">(</span><span class="kt">lto_code_gen_t</span><span class="p">,</span> <span class="k">const</span> <span class="kt">char</span><span class="o">*</span><span class="p">)</span>
+</pre></div>
+</div>
+<p>After all these settings are done, the linker requests that a native object file
+be created from the modules with the settings using:</p>
+<div class="highlight-c"><div class="highlight"><pre><span class="n">lto_codegen_compile</span><span class="p">(</span><span class="kt">lto_code_gen_t</span><span class="p">,</span> <span class="n">size</span><span class="o">*</span><span class="p">)</span>
+</pre></div>
+</div>
+<p>which returns a pointer to a buffer containing the generated native object file.
+The linker then parses that and links it with the rest of the native object
+files.</p>
+</div>
+</div>
+</div>
+
+
+ </div>
+ </div>
+ <div class="clearer"></div>
+ </div>
+ <div class="related">
+ <h3>Navigation</h3>
+ <ul>
+ <li class="right" style="margin-right: 10px">
+ <a href="genindex.html" title="General Index"
+ >index</a></li>
+ <li class="right" >
+ <a href="SegmentedStacks.html" title="Segmented Stacks in LLVM"
+ >next</a> |</li>
+ <li class="right" >
+ <a href="ExceptionHandling.html" title="Exception Handling in LLVM"
+ >previous</a> |</li>
+ <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+ <li><a href="index.html">Documentation</a>»</li>
+
+ </ul>
+ </div>
+ <div class="footer">
+ © Copyright 2003-2016, LLVM Project.
+ Last updated on 2016-01-04.
+ Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.3.
+ </div>
+ </body>
+</html>
\ No newline at end of file
Added: www-releases/trunk/3.7.1/docs/MCJITDesignAndImplementation.html
URL: http://llvm.org/viewvc/llvm-project/www-releases/trunk/3.7.1/docs/MCJITDesignAndImplementation.html?rev=257950&view=auto
==============================================================================
--- www-releases/trunk/3.7.1/docs/MCJITDesignAndImplementation.html (added)
+++ www-releases/trunk/3.7.1/docs/MCJITDesignAndImplementation.html Fri Jan 15 17:13:16 2016
@@ -0,0 +1,245 @@
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
+ <title>MCJIT Design and Implementation — LLVM 3.7 documentation</title>
+
+ <link rel="stylesheet" href="_static/llvm-theme.css" type="text/css" />
+ <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
+
+ <script type="text/javascript">
+ var DOCUMENTATION_OPTIONS = {
+ URL_ROOT: './',
+ VERSION: '3.7',
+ COLLAPSE_INDEX: false,
+ FILE_SUFFIX: '.html',
+ HAS_SOURCE: true
+ };
+ </script>
+ <script type="text/javascript" src="_static/jquery.js"></script>
+ <script type="text/javascript" src="_static/underscore.js"></script>
+ <script type="text/javascript" src="_static/doctools.js"></script>
+ <link rel="top" title="LLVM 3.7 documentation" href="index.html" />
+ <link rel="next" title="LLVM Atomic Instructions and Concurrency Guide" href="Atomics.html" />
+ <link rel="prev" title="Performance Tips for Frontend Authors" href="Frontend/PerformanceTips.html" />
+<style type="text/css">
+ table.right { float: right; margin-left: 20px; }
+ table.right td { border: 1px solid #ccc; }
+</style>
+
+ </head>
+ <body>
+<div class="logo">
+ <a href="index.html">
+ <img src="_static/logo.png"
+ alt="LLVM Logo" width="250" height="88"/></a>
+</div>
+
+ <div class="related">
+ <h3>Navigation</h3>
+ <ul>
+ <li class="right" style="margin-right: 10px">
+ <a href="genindex.html" title="General Index"
+ accesskey="I">index</a></li>
+ <li class="right" >
+ <a href="Atomics.html" title="LLVM Atomic Instructions and Concurrency Guide"
+ accesskey="N">next</a> |</li>
+ <li class="right" >
+ <a href="Frontend/PerformanceTips.html" title="Performance Tips for Frontend Authors"
+ accesskey="P">previous</a> |</li>
+ <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+ <li><a href="index.html">Documentation</a>»</li>
+
+ </ul>
+ </div>
+
+
+ <div class="document">
+ <div class="documentwrapper">
+ <div class="body">
+
+ <div class="section" id="mcjit-design-and-implementation">
+<h1>MCJIT Design and Implementation<a class="headerlink" href="#mcjit-design-and-implementation" title="Permalink to this headline">¶</a></h1>
+<div class="section" id="introduction">
+<h2>Introduction<a class="headerlink" href="#introduction" title="Permalink to this headline">¶</a></h2>
+<p>This document describes the internal workings of the MCJIT execution
+engine and the RuntimeDyld component. It is intended as a high level
+overview of the implementation, showing the flow and interactions of
+objects throughout the code generation and dynamic loading process.</p>
+</div>
+<div class="section" id="engine-creation">
+<h2>Engine Creation<a class="headerlink" href="#engine-creation" title="Permalink to this headline">¶</a></h2>
+<p>In most cases, an EngineBuilder object is used to create an instance of
+the MCJIT execution engine. The EngineBuilder takes an llvm::Module
+object as an argument to its constructor. The client may then set various
+options that we control the later be passed along to the MCJIT engine,
+including the selection of MCJIT as the engine type to be created.
+Of particular interest is the EngineBuilder::setMCJITMemoryManager
+function. If the client does not explicitly create a memory manager at
+this time, a default memory manager (specifically SectionMemoryManager)
+will be created when the MCJIT engine is instantiated.</p>
+<p>Once the options have been set, a client calls EngineBuilder::create to
+create an instance of the MCJIT engine. If the client does not use the
+form of this function that takes a TargetMachine as a parameter, a new
+TargetMachine will be created based on the target triple associated with
+the Module that was used to create the EngineBuilder.</p>
+<img alt="_images/MCJIT-engine-builder.png" src="_images/MCJIT-engine-builder.png" />
+<p>EngineBuilder::create will call the static MCJIT::createJIT function,
+passing in its pointers to the module, memory manager and target machine
+objects, all of which will subsequently be owned by the MCJIT object.</p>
+<p>The MCJIT class has a member variable, Dyld, which contains an instance of
+the RuntimeDyld wrapper class. This member will be used for
+communications between MCJIT and the actual RuntimeDyldImpl object that
+gets created when an object is loaded.</p>
+<img alt="_images/MCJIT-creation.png" src="_images/MCJIT-creation.png" />
+<p>Upon creation, MCJIT holds a pointer to the Module object that it received
+from EngineBuilder but it does not immediately generate code for this
+module. Code generation is deferred until either the
+MCJIT::finalizeObject method is called explicitly or a function such as
+MCJIT::getPointerToFunction is called which requires the code to have been
+generated.</p>
+</div>
+<div class="section" id="code-generation">
+<h2>Code Generation<a class="headerlink" href="#code-generation" title="Permalink to this headline">¶</a></h2>
+<p>When code generation is triggered, as described above, MCJIT will first
+attempt to retrieve an object image from its ObjectCache member, if one
+has been set. If a cached object image cannot be retrieved, MCJIT will
+call its emitObject method. MCJIT::emitObject uses a local PassManager
+instance and creates a new ObjectBufferStream instance, both of which it
+passes to TargetMachine::addPassesToEmitMC before calling PassManager::run
+on the Module with which it was created.</p>
+<img alt="_images/MCJIT-load.png" src="_images/MCJIT-load.png" />
+<p>The PassManager::run call causes the MC code generation mechanisms to emit
+a complete relocatable binary object image (either in either ELF or MachO
+format, depending on the target) into the ObjectBufferStream object, which
+is flushed to complete the process. If an ObjectCache is being used, the
+image will be passed to the ObjectCache here.</p>
+<p>At this point, the ObjectBufferStream contains the raw object image.
+Before the code can be executed, the code and data sections from this
+image must be loaded into suitable memory, relocations must be applied and
+memory permission and code cache invalidation (if required) must be completed.</p>
+</div>
+<div class="section" id="object-loading">
+<h2>Object Loading<a class="headerlink" href="#object-loading" title="Permalink to this headline">¶</a></h2>
+<p>Once an object image has been obtained, either through code generation or
+having been retrieved from an ObjectCache, it is passed to RuntimeDyld to
+be loaded. The RuntimeDyld wrapper class examines the object to determine
+its file format and creates an instance of either RuntimeDyldELF or
+RuntimeDyldMachO (both of which derive from the RuntimeDyldImpl base
+class) and calls the RuntimeDyldImpl::loadObject method to perform that
+actual loading.</p>
+<img alt="_images/MCJIT-dyld-load.png" src="_images/MCJIT-dyld-load.png" />
+<p>RuntimeDyldImpl::loadObject begins by creating an ObjectImage instance
+from the ObjectBuffer it received. ObjectImage, which wraps the
+ObjectFile class, is a helper class which parses the binary object image
+and provides access to the information contained in the format-specific
+headers, including section, symbol and relocation information.</p>
+<p>RuntimeDyldImpl::loadObject then iterates through the symbols in the
+image. Information about common symbols is collected for later use. For
+each function or data symbol, the associated section is loaded into memory
+and the symbol is stored in a symbol table map data structure. When the
+iteration is complete, a section is emitted for the common symbols.</p>
+<p>Next, RuntimeDyldImpl::loadObject iterates through the sections in the
+object image and for each section iterates through the relocations for
+that sections. For each relocation, it calls the format-specific
+processRelocationRef method, which will examine the relocation and store
+it in one of two data structures, a section-based relocation list map and
+an external symbol relocation map.</p>
+<img alt="_images/MCJIT-load-object.png" src="_images/MCJIT-load-object.png" />
+<p>When RuntimeDyldImpl::loadObject returns, all of the code and data
+sections for the object will have been loaded into memory allocated by the
+memory manager and relocation information will have been prepared, but the
+relocations have not yet been applied and the generated code is still not
+ready to be executed.</p>
+<p>[Currently (as of August 2013) the MCJIT engine will immediately apply
+relocations when loadObject completes. However, this shouldn’t be
+happening. Because the code may have been generated for a remote target,
+the client should be given a chance to re-map the section addresses before
+relocations are applied. It is possible to apply relocations multiple
+times, but in the case where addresses are to be re-mapped, this first
+application is wasted effort.]</p>
+</div>
+<div class="section" id="address-remapping">
+<h2>Address Remapping<a class="headerlink" href="#address-remapping" title="Permalink to this headline">¶</a></h2>
+<p>At any time after initial code has been generated and before
+finalizeObject is called, the client can remap the address of sections in
+the object. Typically this is done because the code was generated for an
+external process and is being mapped into that process’ address space.
+The client remaps the section address by calling MCJIT::mapSectionAddress.
+This should happen before the section memory is copied to its new
+location.</p>
+<p>When MCJIT::mapSectionAddress is called, MCJIT passes the call on to
+RuntimeDyldImpl (via its Dyld member). RuntimeDyldImpl stores the new
+address in an internal data structure but does not update the code at this
+time, since other sections are likely to change.</p>
+<p>When the client is finished remapping section addresses, it will call
+MCJIT::finalizeObject to complete the remapping process.</p>
+</div>
+<div class="section" id="final-preparations">
+<h2>Final Preparations<a class="headerlink" href="#final-preparations" title="Permalink to this headline">¶</a></h2>
+<p>When MCJIT::finalizeObject is called, MCJIT calls
+RuntimeDyld::resolveRelocations. This function will attempt to locate any
+external symbols and then apply all relocations for the object.</p>
+<p>External symbols are resolved by calling the memory manager’s
+getPointerToNamedFunction method. The memory manager will return the
+address of the requested symbol in the target address space. (Note, this
+may not be a valid pointer in the host process.) RuntimeDyld will then
+iterate through the list of relocations it has stored which are associated
+with this symbol and invoke the resolveRelocation method which, through an
+format-specific implementation, will apply the relocation to the loaded
+section memory.</p>
+<p>Next, RuntimeDyld::resolveRelocations iterates through the list of
+sections and for each section iterates through a list of relocations that
+have been saved which reference that symbol and call resolveRelocation for
+each entry in this list. The relocation list here is a list of
+relocations for which the symbol associated with the relocation is located
+in the section associated with the list. Each of these locations will
+have a target location at which the relocation will be applied that is
+likely located in a different section.</p>
+<img alt="_images/MCJIT-resolve-relocations.png" src="_images/MCJIT-resolve-relocations.png" />
+<p>Once relocations have been applied as described above, MCJIT calls
+RuntimeDyld::getEHFrameSection, and if a non-zero result is returned
+passes the section data to the memory manager’s registerEHFrames method.
+This allows the memory manager to call any desired target-specific
+functions, such as registering the EH frame information with a debugger.</p>
+<p>Finally, MCJIT calls the memory manager’s finalizeMemory method. In this
+method, the memory manager will invalidate the target code cache, if
+necessary, and apply final permissions to the memory pages it has
+allocated for code and data memory.</p>
+</div>
+</div>
+
+
+ </div>
+ </div>
+ <div class="clearer"></div>
+ </div>
+ <div class="related">
+ <h3>Navigation</h3>
+ <ul>
+ <li class="right" style="margin-right: 10px">
+ <a href="genindex.html" title="General Index"
+ >index</a></li>
+ <li class="right" >
+ <a href="Atomics.html" title="LLVM Atomic Instructions and Concurrency Guide"
+ >next</a> |</li>
+ <li class="right" >
+ <a href="Frontend/PerformanceTips.html" title="Performance Tips for Frontend Authors"
+ >previous</a> |</li>
+ <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+ <li><a href="index.html">Documentation</a>»</li>
+
+ </ul>
+ </div>
+ <div class="footer">
+ © Copyright 2003-2016, LLVM Project.
+ Last updated on 2016-01-04.
+ Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.3.
+ </div>
+ </body>
+</html>
\ No newline at end of file
Added: www-releases/trunk/3.7.1/docs/MakefileGuide.html
URL: http://llvm.org/viewvc/llvm-project/www-releases/trunk/3.7.1/docs/MakefileGuide.html?rev=257950&view=auto
==============================================================================
--- www-releases/trunk/3.7.1/docs/MakefileGuide.html (added)
+++ www-releases/trunk/3.7.1/docs/MakefileGuide.html Fri Jan 15 17:13:16 2016
@@ -0,0 +1,973 @@
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
+ <title>LLVM Makefile Guide — LLVM 3.7 documentation</title>
+
+ <link rel="stylesheet" href="_static/llvm-theme.css" type="text/css" />
+ <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
+
+ <script type="text/javascript">
+ var DOCUMENTATION_OPTIONS = {
+ URL_ROOT: './',
+ VERSION: '3.7',
+ COLLAPSE_INDEX: false,
+ FILE_SUFFIX: '.html',
+ HAS_SOURCE: true
+ };
+ </script>
+ <script type="text/javascript" src="_static/jquery.js"></script>
+ <script type="text/javascript" src="_static/underscore.js"></script>
+ <script type="text/javascript" src="_static/doctools.js"></script>
+ <link rel="top" title="LLVM 3.7 documentation" href="index.html" />
+ <link rel="next" title="Creating an LLVM Project" href="Projects.html" />
+ <link rel="prev" title="LLVM Developer Policy" href="DeveloperPolicy.html" />
+<style type="text/css">
+ table.right { float: right; margin-left: 20px; }
+ table.right td { border: 1px solid #ccc; }
+</style>
+
+ </head>
+ <body>
+<div class="logo">
+ <a href="index.html">
+ <img src="_static/logo.png"
+ alt="LLVM Logo" width="250" height="88"/></a>
+</div>
+
+ <div class="related">
+ <h3>Navigation</h3>
+ <ul>
+ <li class="right" style="margin-right: 10px">
+ <a href="genindex.html" title="General Index"
+ accesskey="I">index</a></li>
+ <li class="right" >
+ <a href="Projects.html" title="Creating an LLVM Project"
+ accesskey="N">next</a> |</li>
+ <li class="right" >
+ <a href="DeveloperPolicy.html" title="LLVM Developer Policy"
+ accesskey="P">previous</a> |</li>
+ <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+ <li><a href="index.html">Documentation</a>»</li>
+
+ </ul>
+ </div>
+
+
+ <div class="document">
+ <div class="documentwrapper">
+ <div class="body">
+
+ <div class="section" id="llvm-makefile-guide">
+<h1>LLVM Makefile Guide<a class="headerlink" href="#llvm-makefile-guide" title="Permalink to this headline">¶</a></h1>
+<div class="contents local topic" id="contents">
+<ul class="simple">
+<li><a class="reference internal" href="#introduction" id="id3">Introduction</a></li>
+<li><a class="reference internal" href="#general-concepts" id="id4">General Concepts</a><ul>
+<li><a class="reference internal" href="#projects" id="id5">Projects</a></li>
+<li><a class="reference internal" href="#variable-values" id="id6">Variable Values</a></li>
+<li><a class="reference internal" href="#including-makefiles" id="id7">Including Makefiles</a><ul>
+<li><a class="reference internal" href="#makefile" id="id8"><tt class="docutils literal"><span class="pre">Makefile</span></tt></a></li>
+<li><a class="reference internal" href="#makefile-common" id="id9"><tt class="docutils literal"><span class="pre">Makefile.common</span></tt></a></li>
+<li><a class="reference internal" href="#makefile-config" id="id10"><tt class="docutils literal"><span class="pre">Makefile.config</span></tt></a></li>
+<li><a class="reference internal" href="#makefile-rules" id="id11"><tt class="docutils literal"><span class="pre">Makefile.rules</span></tt></a></li>
+<li><a class="reference internal" href="#comments" id="id12">Comments</a></li>
+</ul>
+</li>
+</ul>
+</li>
+<li><a class="reference internal" href="#tutorial" id="id13">Tutorial</a><ul>
+<li><a class="reference internal" href="#libraries" id="id14">Libraries</a><ul>
+<li><a class="reference internal" href="#loadable-modules" id="id15">Loadable Modules</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#tools" id="id16">Tools</a><ul>
+<li><a class="reference internal" href="#jit-tools" id="id17">JIT Tools</a></li>
+</ul>
+</li>
+</ul>
+</li>
+<li><a class="reference internal" href="#targets-supported" id="id18">Targets Supported</a><ul>
+<li><a class="reference internal" href="#all-default" id="id19"><tt class="docutils literal"><span class="pre">all</span></tt> (default)</a></li>
+<li><a class="reference internal" href="#all-local" id="id20"><tt class="docutils literal"><span class="pre">all-local</span></tt></a></li>
+<li><a class="reference internal" href="#check" id="id21"><tt class="docutils literal"><span class="pre">check</span></tt></a></li>
+<li><a class="reference internal" href="#check-local" id="id22"><tt class="docutils literal"><span class="pre">check-local</span></tt></a></li>
+<li><a class="reference internal" href="#clean" id="id23"><tt class="docutils literal"><span class="pre">clean</span></tt></a></li>
+<li><a class="reference internal" href="#clean-local" id="id24"><tt class="docutils literal"><span class="pre">clean-local</span></tt></a></li>
+<li><a class="reference internal" href="#dist" id="id25"><tt class="docutils literal"><span class="pre">dist</span></tt></a></li>
+<li><a class="reference internal" href="#dist-check" id="id26"><tt class="docutils literal"><span class="pre">dist-check</span></tt></a></li>
+<li><a class="reference internal" href="#dist-clean" id="id27"><tt class="docutils literal"><span class="pre">dist-clean</span></tt></a></li>
+<li><a class="reference internal" href="#install" id="id28"><tt class="docutils literal"><span class="pre">install</span></tt></a></li>
+<li><a class="reference internal" href="#preconditions" id="id29"><tt class="docutils literal"><span class="pre">preconditions</span></tt></a></li>
+<li><a class="reference internal" href="#printvars" id="id30"><tt class="docutils literal"><span class="pre">printvars</span></tt></a></li>
+<li><a class="reference internal" href="#reconfigure" id="id31"><tt class="docutils literal"><span class="pre">reconfigure</span></tt></a></li>
+<li><a class="reference internal" href="#spotless" id="id32"><tt class="docutils literal"><span class="pre">spotless</span></tt></a></li>
+<li><a class="reference internal" href="#tags" id="id33"><tt class="docutils literal"><span class="pre">tags</span></tt></a></li>
+<li><a class="reference internal" href="#uninstall" id="id34"><tt class="docutils literal"><span class="pre">uninstall</span></tt></a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#variables" id="id35">Variables</a><ul>
+<li><a class="reference internal" href="#control-variables" id="id36">Control Variables</a></li>
+<li><a class="reference internal" href="#override-variables" id="id37">Override Variables</a></li>
+<li><a class="reference internal" href="#readable-variables" id="id38">Readable Variables</a></li>
+<li><a class="reference internal" href="#internal-variables" id="id39">Internal Variables</a></li>
+</ul>
+</li>
+</ul>
+</div>
+<div class="section" id="introduction">
+<h2><a class="toc-backref" href="#id3">Introduction</a><a class="headerlink" href="#introduction" title="Permalink to this headline">¶</a></h2>
+<p>This document provides <em>usage</em> information about the LLVM makefile system. While
+loosely patterned after the BSD makefile system, LLVM has taken a departure from
+BSD in order to implement additional features needed by LLVM. Although makefile
+systems, such as <tt class="docutils literal"><span class="pre">automake</span></tt>, were attempted at one point, it has become clear
+that the features needed by LLVM and the <tt class="docutils literal"><span class="pre">Makefile</span></tt> norm are too great to use
+a more limited tool. Consequently, LLVM requires simply GNU Make 3.79, a widely
+portable makefile processor. LLVM unabashedly makes heavy use of the features of
+GNU Make so the dependency on GNU Make is firm. If you’re not familiar with
+<tt class="docutils literal"><span class="pre">make</span></tt>, it is recommended that you read the <a class="reference external" href="http://www.gnu.org/software/make/manual/make.html">GNU Makefile Manual</a>.</p>
+<p>While this document is rightly part of the <a class="reference external" href="ProgrammersManual.html">LLVM Programmer’s
+Manual</a>, it is treated separately here because of the
+volume of content and because it is often an early source of bewilderment for
+new developers.</p>
+</div>
+<div class="section" id="general-concepts">
+<h2><a class="toc-backref" href="#id4">General Concepts</a><a class="headerlink" href="#general-concepts" title="Permalink to this headline">¶</a></h2>
+<p>The LLVM Makefile System is the component of LLVM that is responsible for
+building the software, testing it, generating distributions, checking those
+distributions, installing and uninstalling, etc. It consists of a several files
+throughout the source tree. These files and other general concepts are described
+in this section.</p>
+<div class="section" id="projects">
+<h3><a class="toc-backref" href="#id5">Projects</a><a class="headerlink" href="#projects" title="Permalink to this headline">¶</a></h3>
+<p>The LLVM Makefile System is quite generous. It not only builds its own software,
+but it can build yours too. Built into the system is knowledge of the
+<tt class="docutils literal"><span class="pre">llvm/projects</span></tt> directory. Any directory under <tt class="docutils literal"><span class="pre">projects</span></tt> that has both a
+<tt class="docutils literal"><span class="pre">configure</span></tt> script and a <tt class="docutils literal"><span class="pre">Makefile</span></tt> is assumed to be a project that uses the
+LLVM Makefile system. Building software that uses LLVM does not require the
+LLVM Makefile System nor even placement in the <tt class="docutils literal"><span class="pre">llvm/projects</span></tt>
+directory. However, doing so will allow your project to get up and running
+quickly by utilizing the built-in features that are used to compile LLVM. LLVM
+compiles itself using the same features of the makefile system as used for
+projects.</p>
+<p>For further details, consult the <a class="reference external" href="Projects.html">Projects</a> page.</p>
+</div>
+<div class="section" id="variable-values">
+<h3><a class="toc-backref" href="#id6">Variable Values</a><a class="headerlink" href="#variable-values" title="Permalink to this headline">¶</a></h3>
+<p>To use the makefile system, you simply create a file named <tt class="docutils literal"><span class="pre">Makefile</span></tt> in your
+directory and declare values for certain variables. The variables and values
+that you select determine what the makefile system will do. These variables
+enable rules and processing in the makefile system that automatically Do The
+Right Thing (C).</p>
+</div>
+<div class="section" id="including-makefiles">
+<h3><a class="toc-backref" href="#id7">Including Makefiles</a><a class="headerlink" href="#including-makefiles" title="Permalink to this headline">¶</a></h3>
+<p>Setting variables alone is not enough. You must include into your Makefile
+additional files that provide the rules of the LLVM Makefile system. The various
+files involved are described in the sections that follow.</p>
+<div class="section" id="makefile">
+<h4><a class="toc-backref" href="#id8"><tt class="docutils literal"><span class="pre">Makefile</span></tt></a><a class="headerlink" href="#makefile" title="Permalink to this headline">¶</a></h4>
+<p>Each directory to participate in the build needs to have a file named
+<tt class="docutils literal"><span class="pre">Makefile</span></tt>. This is the file first read by <tt class="docutils literal"><span class="pre">make</span></tt>. It has three
+sections:</p>
+<ol class="arabic simple">
+<li>Settable Variables — Required that must be set first.</li>
+<li><tt class="docutils literal"><span class="pre">include</span> <span class="pre">$(LEVEL)/Makefile.common</span></tt> — include the LLVM Makefile system.</li>
+<li>Override Variables — Override variables set by the LLVM Makefile system.</li>
+</ol>
+</div>
+<div class="section" id="makefile-common">
+<span id="level-makefile-common"></span><h4><a class="toc-backref" href="#id9"><tt class="docutils literal"><span class="pre">Makefile.common</span></tt></a><a class="headerlink" href="#makefile-common" title="Permalink to this headline">¶</a></h4>
+<p>Every project must have a <tt class="docutils literal"><span class="pre">Makefile.common</span></tt> file at its top source
+directory. This file serves three purposes:</p>
+<ol class="arabic simple">
+<li>It includes the project’s configuration makefile to obtain values determined
+by the <tt class="docutils literal"><span class="pre">configure</span></tt> script. This is done by including the
+<a class="reference internal" href="#level-makefile-config">$(LEVEL)/Makefile.config</a> file.</li>
+<li>It specifies any other (static) values that are needed throughout the
+project. Only values that are used in all or a large proportion of the
+project’s directories should be placed here.</li>
+<li>It includes the standard rules for the LLVM Makefile system,
+<a class="reference internal" href="#llvm-src-root-makefile-rules">$(LLVM_SRC_ROOT)/Makefile.rules</a>. This file is the <em>guts</em> of the LLVM
+<tt class="docutils literal"><span class="pre">Makefile</span></tt> system.</li>
+</ol>
+</div>
+<div class="section" id="makefile-config">
+<span id="level-makefile-config"></span><h4><a class="toc-backref" href="#id10"><tt class="docutils literal"><span class="pre">Makefile.config</span></tt></a><a class="headerlink" href="#makefile-config" title="Permalink to this headline">¶</a></h4>
+<p>Every project must have a <tt class="docutils literal"><span class="pre">Makefile.config</span></tt> at the top of its <em>build</em>
+directory. This file is <strong>generated</strong> by the <tt class="docutils literal"><span class="pre">configure</span></tt> script from the
+pattern provided by the <tt class="docutils literal"><span class="pre">Makefile.config.in</span></tt> file located at the top of the
+project’s <em>source</em> directory. The contents of this file depend largely on what
+configuration items the project uses, however most projects can get what they
+need by just relying on LLVM’s configuration found in
+<tt class="docutils literal"><span class="pre">$(LLVM_OBJ_ROOT)/Makefile.config</span></tt>.</p>
+</div>
+<div class="section" id="makefile-rules">
+<span id="llvm-src-root-makefile-rules"></span><h4><a class="toc-backref" href="#id11"><tt class="docutils literal"><span class="pre">Makefile.rules</span></tt></a><a class="headerlink" href="#makefile-rules" title="Permalink to this headline">¶</a></h4>
+<p>This file, located at <tt class="docutils literal"><span class="pre">$(LLVM_SRC_ROOT)/Makefile.rules</span></tt> is the heart of the
+LLVM Makefile System. It provides all the logic, dependencies, and rules for
+building the targets supported by the system. What it does largely depends on
+the values of <tt class="docutils literal"><span class="pre">make</span></tt> <a class="reference internal" href="#variables">variables</a> that have been set <em>before</em>
+<tt class="docutils literal"><span class="pre">Makefile.rules</span></tt> is included.</p>
+</div>
+<div class="section" id="comments">
+<h4><a class="toc-backref" href="#id12">Comments</a><a class="headerlink" href="#comments" title="Permalink to this headline">¶</a></h4>
+<p>User <tt class="docutils literal"><span class="pre">Makefile</span></tt>s need not have comments in them unless the construction is
+unusual or it does not strictly follow the rules and patterns of the LLVM
+makefile system. Makefile comments are invoked with the pound (<tt class="docutils literal"><span class="pre">#</span></tt>) character.
+The <tt class="docutils literal"><span class="pre">#</span></tt> character and any text following it, to the end of the line, are
+ignored by <tt class="docutils literal"><span class="pre">make</span></tt>.</p>
+</div>
+</div>
+</div>
+<div class="section" id="tutorial">
+<h2><a class="toc-backref" href="#id13">Tutorial</a><a class="headerlink" href="#tutorial" title="Permalink to this headline">¶</a></h2>
+<p>This section provides some examples of the different kinds of modules you can
+build with the LLVM makefile system. In general, each directory you provide will
+build a single object although that object may be composed of additionally
+compiled components.</p>
+<div class="section" id="libraries">
+<h3><a class="toc-backref" href="#id14">Libraries</a><a class="headerlink" href="#libraries" title="Permalink to this headline">¶</a></h3>
+<p>Only a few variable definitions are needed to build a regular library.
+Normally, the makefile system will build all the software into a single
+<tt class="docutils literal"><span class="pre">libname.o</span></tt> (pre-linked) object. This means the library is not searchable and
+that the distinction between compilation units has been dissolved. Optionally,
+you can ask for a shared library (.so) or archive library (.a) built. Archive
+libraries are the default. For example:</p>
+<div class="highlight-makefile"><div class="highlight"><pre><span class="nv">LIBRARYNAME</span> <span class="o">=</span> mylib
+<span class="nv">SHARED_LIBRARY</span> <span class="o">=</span> 1
+<span class="nv">BUILD_ARCHIVE</span> <span class="o">=</span> 1
+</pre></div>
+</div>
+<p>says to build a library named <tt class="docutils literal"><span class="pre">mylib</span></tt> with both a shared library
+(<tt class="docutils literal"><span class="pre">mylib.so</span></tt>) and an archive library (<tt class="docutils literal"><span class="pre">mylib.a</span></tt>) version. The contents of all
+the libraries produced will be the same, they are just constructed differently.
+Note that you normally do not need to specify the sources involved. The LLVM
+Makefile system will infer the source files from the contents of the source
+directory.</p>
+<p>The <tt class="docutils literal"><span class="pre">LOADABLE_MODULE=1</span></tt> directive can be used in conjunction with
+<tt class="docutils literal"><span class="pre">SHARED_LIBRARY=1</span></tt> to indicate that the resulting shared library should be
+openable with the <tt class="docutils literal"><span class="pre">dlopen</span></tt> function and searchable with the <tt class="docutils literal"><span class="pre">dlsym</span></tt> function
+(or your operating system’s equivalents). While this isn’t strictly necessary on
+Linux and a few other platforms, it is required on systems like HP-UX and
+Darwin. You should use <tt class="docutils literal"><span class="pre">LOADABLE_MODULE</span></tt> for any shared library that you
+intend to be loaded into an tool via the <tt class="docutils literal"><span class="pre">-load</span></tt> option. <a class="reference internal" href="WritingAnLLVMPass.html#writing-an-llvm-pass-makefile"><em>Pass
+documentation</em></a> has an example of why you might
+want to do this.</p>
+<div class="section" id="loadable-modules">
+<h4><a class="toc-backref" href="#id15">Loadable Modules</a><a class="headerlink" href="#loadable-modules" title="Permalink to this headline">¶</a></h4>
+<p>In some situations, you need to create a loadable module. Loadable modules can
+be loaded into programs like <tt class="docutils literal"><span class="pre">opt</span></tt> or <tt class="docutils literal"><span class="pre">llc</span></tt> to specify additional passes to
+run or targets to support. Loadable modules are also useful for debugging a
+pass or providing a pass with another package if that pass can’t be included in
+LLVM.</p>
+<p>LLVM provides complete support for building such a module. All you need to do is
+use the <tt class="docutils literal"><span class="pre">LOADABLE_MODULE</span></tt> variable in your <tt class="docutils literal"><span class="pre">Makefile</span></tt>. For example, to build
+a loadable module named <tt class="docutils literal"><span class="pre">MyMod</span></tt> that uses the LLVM libraries <tt class="docutils literal"><span class="pre">LLVMSupport.a</span></tt>
+and <tt class="docutils literal"><span class="pre">LLVMSystem.a</span></tt>, you would specify:</p>
+<div class="highlight-makefile"><div class="highlight"><pre><span class="nv">LIBRARYNAME</span> <span class="o">:=</span> MyMod
+<span class="nv">LOADABLE_MODULE</span> <span class="o">:=</span> 1
+<span class="nv">LINK_COMPONENTS</span> <span class="o">:=</span> support system
+</pre></div>
+</div>
+<p>Use of the <tt class="docutils literal"><span class="pre">LOADABLE_MODULE</span></tt> facility implies several things:</p>
+<ol class="arabic">
+<li><dl class="first docutils">
+<dt>There will be no “<tt class="docutils literal"><span class="pre">lib</span></tt>” prefix on the module. This differentiates it from</dt>
+<dd><p class="first last">a standard shared library of the same name.</p>
+</dd>
+</dl>
+</li>
+<li><p class="first">The <a class="reference internal" href="#shared-library">SHARED_LIBRARY</a> variable is turned on.</p>
+</li>
+<li><p class="first">The <a class="reference internal" href="#link-libs-in-shared">LINK_LIBS_IN_SHARED</a> variable is turned on.</p>
+</li>
+</ol>
+<p>A loadable module is loaded by LLVM via the facilities of libtool’s libltdl
+library which is part of <tt class="docutils literal"><span class="pre">lib/System</span></tt> implementation.</p>
+</div>
+</div>
+<div class="section" id="tools">
+<h3><a class="toc-backref" href="#id16">Tools</a><a class="headerlink" href="#tools" title="Permalink to this headline">¶</a></h3>
+<p>For building executable programs (tools), you must provide the name of the tool
+and the names of the libraries you wish to link with the tool. For example:</p>
+<div class="highlight-makefile"><div class="highlight"><pre><span class="nv">TOOLNAME</span> <span class="o">=</span> mytool
+<span class="nv">USEDLIBS</span> <span class="o">=</span> mylib
+<span class="nv">LINK_COMPONENTS</span> <span class="o">=</span> support system
+</pre></div>
+</div>
+<p>says that we are to build a tool name <tt class="docutils literal"><span class="pre">mytool</span></tt> and that it requires three
+libraries: <tt class="docutils literal"><span class="pre">mylib</span></tt>, <tt class="docutils literal"><span class="pre">LLVMSupport.a</span></tt> and <tt class="docutils literal"><span class="pre">LLVMSystem.a</span></tt>.</p>
+<p>Note that two different variables are used to indicate which libraries are
+linked: <tt class="docutils literal"><span class="pre">USEDLIBS</span></tt> and <tt class="docutils literal"><span class="pre">LLVMLIBS</span></tt>. This distinction is necessary to support
+projects. <tt class="docutils literal"><span class="pre">LLVMLIBS</span></tt> refers to the LLVM libraries found in the LLVM object
+directory. <tt class="docutils literal"><span class="pre">USEDLIBS</span></tt> refers to the libraries built by your project. In the
+case of building LLVM tools, <tt class="docutils literal"><span class="pre">USEDLIBS</span></tt> and <tt class="docutils literal"><span class="pre">LLVMLIBS</span></tt> can be used
+interchangeably since the “project” is LLVM itself and <tt class="docutils literal"><span class="pre">USEDLIBS</span></tt> refers to
+the same place as <tt class="docutils literal"><span class="pre">LLVMLIBS</span></tt>.</p>
+<p>Also note that there are two different ways of specifying a library: with a
+<tt class="docutils literal"><span class="pre">.a</span></tt> suffix and without. Without the suffix, the entry refers to the re-linked
+(.o) file which will include <em>all</em> symbols of the library. This is
+useful, for example, to include all passes from a library of passes. If the
+<tt class="docutils literal"><span class="pre">.a</span></tt> suffix is used then the library is linked as a searchable library (with
+the <tt class="docutils literal"><span class="pre">-l</span></tt> option). In this case, only the symbols that are unresolved <em>at
+that point</em> will be resolved from the library, if they exist. Other
+(unreferenced) symbols will not be included when the <tt class="docutils literal"><span class="pre">.a</span></tt> syntax is used. Note
+that in order to use the <tt class="docutils literal"><span class="pre">.a</span></tt> suffix, the library in question must have been
+built with the <tt class="docutils literal"><span class="pre">BUILD_ARCHIVE</span></tt> option set.</p>
+<div class="section" id="jit-tools">
+<h4><a class="toc-backref" href="#id17">JIT Tools</a><a class="headerlink" href="#jit-tools" title="Permalink to this headline">¶</a></h4>
+<p>Many tools will want to use the JIT features of LLVM. To do this, you simply
+specify that you want an execution ‘engine’, and the makefiles will
+automatically link in the appropriate JIT for the host or an interpreter if none
+is available:</p>
+<div class="highlight-makefile"><div class="highlight"><pre><span class="nv">TOOLNAME</span> <span class="o">=</span> my_jit_tool
+<span class="nv">USEDLIBS</span> <span class="o">=</span> mylib
+<span class="nv">LINK_COMPONENTS</span> <span class="o">=</span> engine
+</pre></div>
+</div>
+<p>Of course, any additional libraries may be listed as other components. To get a
+full understanding of how this changes the linker command, it is recommended
+that you:</p>
+<div class="highlight-bash"><div class="highlight"><pre>% <span class="nb">cd </span>examples/Fibonacci
+% make <span class="nv">VERBOSE</span><span class="o">=</span>1
+</pre></div>
+</div>
+</div>
+</div>
+</div>
+<div class="section" id="targets-supported">
+<h2><a class="toc-backref" href="#id18">Targets Supported</a><a class="headerlink" href="#targets-supported" title="Permalink to this headline">¶</a></h2>
+<p>This section describes each of the targets that can be built using the LLVM
+Makefile system. Any target can be invoked from any directory but not all are
+applicable to a given directory (e.g. “check”, “dist” and “install” will always
+operate as if invoked from the top level directory).</p>
+<table border="1" class="docutils">
+<colgroup>
+<col width="12%" />
+<col width="10%" />
+<col width="78%" />
+</colgroup>
+<thead valign="bottom">
+<tr class="row-odd"><th class="head">Target Name</th>
+<th class="head">Implied Targets</th>
+<th class="head">Target Description</th>
+</tr>
+</thead>
+<tbody valign="top">
+<tr class="row-even"><td><tt class="docutils literal"><span class="pre">all</span></tt></td>
+<td></td>
+<td>Compile the software recursively. Default target.</td>
+</tr>
+<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">all-local</span></tt></td>
+<td></td>
+<td>Compile the software in the local directory only.</td>
+</tr>
+<tr class="row-even"><td><tt class="docutils literal"><span class="pre">check</span></tt></td>
+<td></td>
+<td>Change to the <tt class="docutils literal"><span class="pre">test</span></tt> directory in a project and run the test suite there.</td>
+</tr>
+<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">check-local</span></tt></td>
+<td></td>
+<td>Run a local test suite. Generally this is only defined in the <tt class="docutils literal"><span class="pre">Makefile</span></tt> of the project’s <tt class="docutils literal"><span class="pre">test</span></tt> directory.</td>
+</tr>
+<tr class="row-even"><td><tt class="docutils literal"><span class="pre">clean</span></tt></td>
+<td></td>
+<td>Remove built objects recursively.</td>
+</tr>
+<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">clean-local</span></tt></td>
+<td></td>
+<td>Remove built objects from the local directory only.</td>
+</tr>
+<tr class="row-even"><td><tt class="docutils literal"><span class="pre">dist</span></tt></td>
+<td><tt class="docutils literal"><span class="pre">all</span></tt></td>
+<td>Prepare a source distribution tarball.</td>
+</tr>
+<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">dist-check</span></tt></td>
+<td><tt class="docutils literal"><span class="pre">all</span></tt></td>
+<td>Prepare a source distribution tarball and check that it builds.</td>
+</tr>
+<tr class="row-even"><td><tt class="docutils literal"><span class="pre">dist-clean</span></tt></td>
+<td><tt class="docutils literal"><span class="pre">clean</span></tt></td>
+<td>Clean source distribution tarball temporary files.</td>
+</tr>
+<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">install</span></tt></td>
+<td><tt class="docutils literal"><span class="pre">all</span></tt></td>
+<td>Copy built objects to installation directory.</td>
+</tr>
+<tr class="row-even"><td><tt class="docutils literal"><span class="pre">preconditions</span></tt></td>
+<td><tt class="docutils literal"><span class="pre">all</span></tt></td>
+<td>Check to make sure configuration and makefiles are up to date.</td>
+</tr>
+<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">printvars</span></tt></td>
+<td><tt class="docutils literal"><span class="pre">all</span></tt></td>
+<td>Prints variables defined by the makefile system (for debugging).</td>
+</tr>
+<tr class="row-even"><td><tt class="docutils literal"><span class="pre">tags</span></tt></td>
+<td></td>
+<td>Make C and C++ tags files for emacs and vi.</td>
+</tr>
+<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">uninstall</span></tt></td>
+<td></td>
+<td>Remove built objects from installation directory.</td>
+</tr>
+</tbody>
+</table>
+<div class="section" id="all-default">
+<span id="all"></span><h3><a class="toc-backref" href="#id19"><tt class="docutils literal"><span class="pre">all</span></tt> (default)</a><a class="headerlink" href="#all-default" title="Permalink to this headline">¶</a></h3>
+<p>When you invoke <tt class="docutils literal"><span class="pre">make</span></tt> with no arguments, you are implicitly instructing it to
+seek the <tt class="docutils literal"><span class="pre">all</span></tt> target (goal). This target is used for building the software
+recursively and will do different things in different directories. For example,
+in a <tt class="docutils literal"><span class="pre">lib</span></tt> directory, the <tt class="docutils literal"><span class="pre">all</span></tt> target will compile source files and
+generate libraries. But, in a <tt class="docutils literal"><span class="pre">tools</span></tt> directory, it will link libraries and
+generate executables.</p>
+</div>
+<div class="section" id="all-local">
+<h3><a class="toc-backref" href="#id20"><tt class="docutils literal"><span class="pre">all-local</span></tt></a><a class="headerlink" href="#all-local" title="Permalink to this headline">¶</a></h3>
+<p>This target is the same as <a class="reference internal" href="#all">all</a> but it operates only on the current directory
+instead of recursively.</p>
+</div>
+<div class="section" id="check">
+<h3><a class="toc-backref" href="#id21"><tt class="docutils literal"><span class="pre">check</span></tt></a><a class="headerlink" href="#check" title="Permalink to this headline">¶</a></h3>
+<p>This target can be invoked from anywhere within a project’s directories but
+always invokes the <a class="reference internal" href="#check-local">check-local</a> target in the project’s <tt class="docutils literal"><span class="pre">test</span></tt> directory, if
+it exists and has a <tt class="docutils literal"><span class="pre">Makefile</span></tt>. A warning is produced otherwise. If
+<a class="reference internal" href="#testsuite">TESTSUITE</a> is defined on the <tt class="docutils literal"><span class="pre">make</span></tt> command line, it will be passed down to
+the invocation of <tt class="docutils literal"><span class="pre">make</span> <span class="pre">check-local</span></tt> in the <tt class="docutils literal"><span class="pre">test</span></tt> directory. The intended
+usage for this is to assist in running specific suites of tests. If
+<tt class="docutils literal"><span class="pre">TESTSUITE</span></tt> is not set, the implementation of <tt class="docutils literal"><span class="pre">check-local</span></tt> should run all
+normal tests. It is up to the project to define what different values for
+<tt class="docutils literal"><span class="pre">TESTSUTE</span></tt> will do. See the <a class="reference internal" href="TestingGuide.html"><em>Testing Guide</em></a> for further
+details.</p>
+</div>
+<div class="section" id="check-local">
+<h3><a class="toc-backref" href="#id22"><tt class="docutils literal"><span class="pre">check-local</span></tt></a><a class="headerlink" href="#check-local" title="Permalink to this headline">¶</a></h3>
+<p>This target should be implemented by the <tt class="docutils literal"><span class="pre">Makefile</span></tt> in the project’s <tt class="docutils literal"><span class="pre">test</span></tt>
+directory. It is invoked by the <tt class="docutils literal"><span class="pre">check</span></tt> target elsewhere. Each project is
+free to define the actions of <tt class="docutils literal"><span class="pre">check-local</span></tt> as appropriate for that
+project. The LLVM project itself uses the <a class="reference internal" href="CommandGuide/lit.html"><em>Lit</em></a> testing
+tool to run a suite of feature and regression tests. Other projects may choose
+to use <strong class="program">lit</strong> or any other testing mechanism.</p>
+</div>
+<div class="section" id="clean">
+<h3><a class="toc-backref" href="#id23"><tt class="docutils literal"><span class="pre">clean</span></tt></a><a class="headerlink" href="#clean" title="Permalink to this headline">¶</a></h3>
+<p>This target cleans the build directory, recursively removing all things that the
+Makefile builds. The cleaning rules have been made guarded so they shouldn’t go
+awry (via <tt class="docutils literal"><span class="pre">rm</span> <span class="pre">-f</span> <span class="pre">$(UNSET_VARIABLE)/*</span></tt> which will attempt to erase the entire
+directory structure).</p>
+</div>
+<div class="section" id="clean-local">
+<h3><a class="toc-backref" href="#id24"><tt class="docutils literal"><span class="pre">clean-local</span></tt></a><a class="headerlink" href="#clean-local" title="Permalink to this headline">¶</a></h3>
+<p>This target does the same thing as <tt class="docutils literal"><span class="pre">clean</span></tt> but only for the current (local)
+directory.</p>
+</div>
+<div class="section" id="dist">
+<h3><a class="toc-backref" href="#id25"><tt class="docutils literal"><span class="pre">dist</span></tt></a><a class="headerlink" href="#dist" title="Permalink to this headline">¶</a></h3>
+<p>This target builds a distribution tarball. It first builds the entire project
+using the <tt class="docutils literal"><span class="pre">all</span></tt> target and then tars up the necessary files and compresses
+it. The generated tarball is sufficient for a casual source distribution, but
+probably not for a release (see <tt class="docutils literal"><span class="pre">dist-check</span></tt>).</p>
+</div>
+<div class="section" id="dist-check">
+<h3><a class="toc-backref" href="#id26"><tt class="docutils literal"><span class="pre">dist-check</span></tt></a><a class="headerlink" href="#dist-check" title="Permalink to this headline">¶</a></h3>
+<p>This target does the same thing as the <tt class="docutils literal"><span class="pre">dist</span></tt> target but also checks the
+distribution tarball. The check is made by unpacking the tarball to a new
+directory, configuring it, building it, installing it, and then verifying that
+the installation results are correct (by comparing to the original build). This
+target can take a long time to run but should be done before a release goes out
+to make sure that the distributed tarball can actually be built into a working
+release.</p>
+</div>
+<div class="section" id="dist-clean">
+<h3><a class="toc-backref" href="#id27"><tt class="docutils literal"><span class="pre">dist-clean</span></tt></a><a class="headerlink" href="#dist-clean" title="Permalink to this headline">¶</a></h3>
+<p>This is a special form of the <tt class="docutils literal"><span class="pre">clean</span></tt> clean target. It performs a normal
+<tt class="docutils literal"><span class="pre">clean</span></tt> but also removes things pertaining to building the distribution.</p>
+</div>
+<div class="section" id="install">
+<h3><a class="toc-backref" href="#id28"><tt class="docutils literal"><span class="pre">install</span></tt></a><a class="headerlink" href="#install" title="Permalink to this headline">¶</a></h3>
+<p>This target finalizes shared objects and executables and copies all libraries,
+headers, executables and documentation to the directory given with the
+<tt class="docutils literal"><span class="pre">--prefix</span></tt> option to <tt class="docutils literal"><span class="pre">configure</span></tt>. When completed, the prefix directory will
+have everything needed to <strong>use</strong> LLVM.</p>
+<p>The LLVM makefiles can generate complete <strong>internal</strong> documentation for all the
+classes by using <tt class="docutils literal"><span class="pre">doxygen</span></tt>. By default, this feature is <strong>not</strong> enabled
+because it takes a long time and generates a massive amount of data (>100MB). If
+you want this feature, you must configure LLVM with the –enable-doxygen switch
+and ensure that a modern version of doxygen (1.3.7 or later) is available in
+your <tt class="docutils literal"><span class="pre">PATH</span></tt>. You can download doxygen from <a class="reference external" href="http://www.stack.nl/~dimitri/doxygen/download.html#latestsrc">here</a>.</p>
+</div>
+<div class="section" id="preconditions">
+<h3><a class="toc-backref" href="#id29"><tt class="docutils literal"><span class="pre">preconditions</span></tt></a><a class="headerlink" href="#preconditions" title="Permalink to this headline">¶</a></h3>
+<p>This utility target checks to see if the <tt class="docutils literal"><span class="pre">Makefile</span></tt> in the object directory is
+older than the <tt class="docutils literal"><span class="pre">Makefile</span></tt> in the source directory and copies it if so. It also
+reruns the <tt class="docutils literal"><span class="pre">configure</span></tt> script if that needs to be done and rebuilds the
+<tt class="docutils literal"><span class="pre">Makefile.config</span></tt> file similarly. Users may overload this target to ensure
+that sanity checks are run <em>before</em> any building of targets as all the targets
+depend on <tt class="docutils literal"><span class="pre">preconditions</span></tt>.</p>
+</div>
+<div class="section" id="printvars">
+<h3><a class="toc-backref" href="#id30"><tt class="docutils literal"><span class="pre">printvars</span></tt></a><a class="headerlink" href="#printvars" title="Permalink to this headline">¶</a></h3>
+<p>This utility target just causes the LLVM makefiles to print out some of the
+makefile variables so that you can double check how things are set.</p>
+</div>
+<div class="section" id="reconfigure">
+<h3><a class="toc-backref" href="#id31"><tt class="docutils literal"><span class="pre">reconfigure</span></tt></a><a class="headerlink" href="#reconfigure" title="Permalink to this headline">¶</a></h3>
+<p>This utility target will force a reconfigure of LLVM or your project. It simply
+runs <tt class="docutils literal"><span class="pre">$(PROJ_OBJ_ROOT)/config.status</span> <span class="pre">--recheck</span></tt> to rerun the configuration
+tests and rebuild the configured files. This isn’t generally useful as the
+makefiles will reconfigure themselves whenever its necessary.</p>
+</div>
+<div class="section" id="spotless">
+<h3><a class="toc-backref" href="#id32"><tt class="docutils literal"><span class="pre">spotless</span></tt></a><a class="headerlink" href="#spotless" title="Permalink to this headline">¶</a></h3>
+<div class="admonition warning">
+<p class="first admonition-title">Warning</p>
+<p class="last">Use with caution!</p>
+</div>
+<p>This utility target, only available when <tt class="docutils literal"><span class="pre">$(PROJ_OBJ_ROOT)</span></tt> is not the same as
+<tt class="docutils literal"><span class="pre">$(PROJ_SRC_ROOT)</span></tt>, will completely clean the <tt class="docutils literal"><span class="pre">$(PROJ_OBJ_ROOT)</span></tt> directory
+by removing its content entirely and reconfiguring the directory. This returns
+the <tt class="docutils literal"><span class="pre">$(PROJ_OBJ_ROOT)</span></tt> directory to a completely fresh state. All content in
+the directory except configured files and top-level makefiles will be lost.</p>
+</div>
+<div class="section" id="tags">
+<h3><a class="toc-backref" href="#id33"><tt class="docutils literal"><span class="pre">tags</span></tt></a><a class="headerlink" href="#tags" title="Permalink to this headline">¶</a></h3>
+<p>This target will generate a <tt class="docutils literal"><span class="pre">TAGS</span></tt> file in the top-level source directory. It
+is meant for use with emacs, XEmacs, or ViM. The TAGS file provides an index of
+symbol definitions so that the editor can jump you to the definition
+quickly.</p>
+</div>
+<div class="section" id="uninstall">
+<h3><a class="toc-backref" href="#id34"><tt class="docutils literal"><span class="pre">uninstall</span></tt></a><a class="headerlink" href="#uninstall" title="Permalink to this headline">¶</a></h3>
+<p>This target is the opposite of the <tt class="docutils literal"><span class="pre">install</span></tt> target. It removes the header,
+library and executable files from the installation directories. Note that the
+directories themselves are not removed because it is not guaranteed that LLVM is
+the only thing installing there (e.g. <tt class="docutils literal"><span class="pre">--prefix=/usr</span></tt>).</p>
+</div>
+</div>
+<div class="section" id="variables">
+<span id="id2"></span><h2><a class="toc-backref" href="#id35">Variables</a><a class="headerlink" href="#variables" title="Permalink to this headline">¶</a></h2>
+<p>Variables are used to tell the LLVM Makefile System what to do and to obtain
+information from it. Variables are also used internally by the LLVM Makefile
+System. Variable names that contain only the upper case alphabetic letters and
+underscore are intended for use by the end user. All other variables are
+internal to the LLVM Makefile System and should not be relied upon nor
+modified. The sections below describe how to use the LLVM Makefile
+variables.</p>
+<div class="section" id="control-variables">
+<h3><a class="toc-backref" href="#id36">Control Variables</a><a class="headerlink" href="#control-variables" title="Permalink to this headline">¶</a></h3>
+<p>Variables listed in the table below should be set <em>before</em> the inclusion of
+<a class="reference internal" href="#level-makefile-common">$(LEVEL)/Makefile.common</a>. These variables provide input to the LLVM make
+system that tell it what to do for the current directory.</p>
+<dl class="docutils">
+<dt><tt class="docutils literal"><span class="pre">BUILD_ARCHIVE</span></tt></dt>
+<dd>If set to any value, causes an archive (.a) library to be built.</dd>
+<dt><tt class="docutils literal"><span class="pre">BUILT_SOURCES</span></tt></dt>
+<dd>Specifies a set of source files that are generated from other source
+files. These sources will be built before any other target processing to
+ensure they are present.</dd>
+<dt><tt class="docutils literal"><span class="pre">CONFIG_FILES</span></tt></dt>
+<dd>Specifies a set of configuration files to be installed.</dd>
+<dt><tt class="docutils literal"><span class="pre">DEBUG_SYMBOLS</span></tt></dt>
+<dd>If set to any value, causes the build to include debugging symbols even in
+optimized objects, libraries and executables. This alters the flags
+specified to the compilers and linkers. Debugging isn’t fun in an optimized
+build, but it is possible.</dd>
+<dt><tt class="docutils literal"><span class="pre">DIRS</span></tt></dt>
+<dd>Specifies a set of directories, usually children of the current directory,
+that should also be made using the same goal. These directories will be
+built serially.</dd>
+<dt><tt class="docutils literal"><span class="pre">DISABLE_AUTO_DEPENDENCIES</span></tt></dt>
+<dd>If set to any value, causes the makefiles to <strong>not</strong> automatically generate
+dependencies when running the compiler. Use of this feature is discouraged
+and it may be removed at a later date.</dd>
+<dt><tt class="docutils literal"><span class="pre">ENABLE_OPTIMIZED</span></tt></dt>
+<dd>If set to 1, causes the build to generate optimized objects, libraries and
+executables. This alters the flags specified to the compilers and
+linkers. Generally debugging won’t be a fun experience with an optimized
+build.</dd>
+<dt><tt class="docutils literal"><span class="pre">ENABLE_PROFILING</span></tt></dt>
+<dd>If set to 1, causes the build to generate both optimized and profiled
+objects, libraries and executables. This alters the flags specified to the
+compilers and linkers to ensure that profile data can be collected from the
+tools built. Use the <tt class="docutils literal"><span class="pre">gprof</span></tt> tool to analyze the output from the profiled
+tools (<tt class="docutils literal"><span class="pre">gmon.out</span></tt>).</dd>
+<dt><tt class="docutils literal"><span class="pre">DISABLE_ASSERTIONS</span></tt></dt>
+<dd>If set to 1, causes the build to disable assertions, even if building a
+debug or profile build. This will exclude all assertion check code from the
+build. LLVM will execute faster, but with little help when things go
+wrong.</dd>
+<dt><tt class="docutils literal"><span class="pre">EXPERIMENTAL_DIRS</span></tt></dt>
+<dd>Specify a set of directories that should be built, but if they fail, it
+should not cause the build to fail. Note that this should only be used
+temporarily while code is being written.</dd>
+<dt><tt class="docutils literal"><span class="pre">EXPORTED_SYMBOL_FILE</span></tt></dt>
+<dd>Specifies the name of a single file that contains a list of the symbols to
+be exported by the linker. One symbol per line.</dd>
+<dt><tt class="docutils literal"><span class="pre">EXPORTED_SYMBOL_LIST</span></tt></dt>
+<dd>Specifies a set of symbols to be exported by the linker.</dd>
+<dt><tt class="docutils literal"><span class="pre">EXTRA_DIST</span></tt></dt>
+<dd>Specifies additional files that should be distributed with LLVM. All source
+files, all built sources, all Makefiles, and most documentation files will
+be automatically distributed. Use this variable to distribute any files that
+are not automatically distributed.</dd>
+<dt><tt class="docutils literal"><span class="pre">KEEP_SYMBOLS</span></tt></dt>
+<dd>If set to any value, specifies that when linking executables the makefiles
+should retain debug symbols in the executable. Normally, symbols are
+stripped from the executable.</dd>
+<dt><tt class="docutils literal"><span class="pre">LEVEL</span></tt> (required)</dt>
+<dd>Specify the level of nesting from the top level. This variable must be set
+in each makefile as it is used to find the top level and thus the other
+makefiles.</dd>
+<dt><tt class="docutils literal"><span class="pre">LIBRARYNAME</span></tt></dt>
+<dd>Specify the name of the library to be built. (Required For Libraries)</dd>
+<dt><tt class="docutils literal"><span class="pre">LINK_COMPONENTS</span></tt></dt>
+<dd>When specified for building a tool, the value of this variable will be
+passed to the <tt class="docutils literal"><span class="pre">llvm-config</span></tt> tool to generate a link line for the
+tool. Unlike <tt class="docutils literal"><span class="pre">USEDLIBS</span></tt> and <tt class="docutils literal"><span class="pre">LLVMLIBS</span></tt>, not all libraries need to be
+specified. The <tt class="docutils literal"><span class="pre">llvm-config</span></tt> tool will figure out the library dependencies
+and add any libraries that are needed. The <tt class="docutils literal"><span class="pre">USEDLIBS</span></tt> variable can still
+be used in conjunction with <tt class="docutils literal"><span class="pre">LINK_COMPONENTS</span></tt> so that additional
+project-specific libraries can be linked with the LLVM libraries specified
+by <tt class="docutils literal"><span class="pre">LINK_COMPONENTS</span></tt>.</dd>
+</dl>
+<dl class="docutils" id="link-libs-in-shared">
+<dt><tt class="docutils literal"><span class="pre">LINK_LIBS_IN_SHARED</span></tt></dt>
+<dd>By default, shared library linking will ignore any libraries specified with
+the <a class="reference internal" href="#llvmlibs">LLVMLIBS</a> or <a class="reference internal" href="#usedlibs">USEDLIBS</a>. This prevents shared libs from including
+things that will be in the LLVM tool the shared library will be loaded
+into. However, sometimes it is useful to link certain libraries into your
+shared library and this option enables that feature.</dd>
+</dl>
+<dl class="docutils" id="llvmlibs">
+<dt><tt class="docutils literal"><span class="pre">LLVMLIBS</span></tt></dt>
+<dd>Specifies the set of libraries from the LLVM <tt class="docutils literal"><span class="pre">$(ObjDir)</span></tt> that will be
+linked into the tool or library.</dd>
+<dt><tt class="docutils literal"><span class="pre">LOADABLE_MODULE</span></tt></dt>
+<dd>If set to any value, causes the shared library being built to also be a
+loadable module. Loadable modules can be opened with the dlopen() function
+and searched with dlsym (or the operating system’s equivalent). Note that
+setting this variable without also setting <tt class="docutils literal"><span class="pre">SHARED_LIBRARY</span></tt> will have no
+effect.</dd>
+<dt><tt class="docutils literal"><span class="pre">NO_INSTALL</span></tt></dt>
+<dd>Specifies that the build products of the directory should not be installed
+but should be built even if the <tt class="docutils literal"><span class="pre">install</span></tt> target is given. This is handy
+for directories that build libraries or tools that are only used as part of
+the build process, such as code generators (e.g. <tt class="docutils literal"><span class="pre">tblgen</span></tt>).</dd>
+<dt><tt class="docutils literal"><span class="pre">OPTIONAL_DIRS</span></tt></dt>
+<dd>Specify a set of directories that may be built, if they exist, but it is
+not an error for them not to exist.</dd>
+<dt><tt class="docutils literal"><span class="pre">PARALLEL_DIRS</span></tt></dt>
+<dd>Specify a set of directories to build recursively and in parallel if the
+<tt class="docutils literal"><span class="pre">-j</span></tt> option was used with <tt class="docutils literal"><span class="pre">make</span></tt>.</dd>
+</dl>
+<dl class="docutils" id="shared-library">
+<dt><tt class="docutils literal"><span class="pre">SHARED_LIBRARY</span></tt></dt>
+<dd>If set to any value, causes a shared library (<tt class="docutils literal"><span class="pre">.so</span></tt>) to be built in
+addition to any other kinds of libraries. Note that this option will cause
+all source files to be built twice: once with options for position
+independent code and once without. Use it only where you really need a
+shared library.</dd>
+<dt><tt class="docutils literal"><span class="pre">SOURCES</span></tt> (optional)</dt>
+<dd>Specifies the list of source files in the current directory to be
+built. Source files of any type may be specified (programs, documentation,
+config files, etc.). If not specified, the makefile system will infer the
+set of source files from the files present in the current directory.</dd>
+<dt><tt class="docutils literal"><span class="pre">SUFFIXES</span></tt></dt>
+<dd>Specifies a set of filename suffixes that occur in suffix match rules. Only
+set this if your local <tt class="docutils literal"><span class="pre">Makefile</span></tt> specifies additional suffix match
+rules.</dd>
+<dt><tt class="docutils literal"><span class="pre">TARGET</span></tt></dt>
+<dd>Specifies the name of the LLVM code generation target that the current
+directory builds. Setting this variable enables additional rules to build
+<tt class="docutils literal"><span class="pre">.inc</span></tt> files from <tt class="docutils literal"><span class="pre">.td</span></tt> files.</dd>
+</dl>
+<dl class="docutils" id="testsuite">
+<dt><tt class="docutils literal"><span class="pre">TESTSUITE</span></tt></dt>
+<dd>Specifies the directory of tests to run in <tt class="docutils literal"><span class="pre">llvm/test</span></tt>.</dd>
+<dt><tt class="docutils literal"><span class="pre">TOOLNAME</span></tt></dt>
+<dd>Specifies the name of the tool that the current directory should build.</dd>
+<dt><tt class="docutils literal"><span class="pre">TOOL_VERBOSE</span></tt></dt>
+<dd>Implies <tt class="docutils literal"><span class="pre">VERBOSE</span></tt> and also tells each tool invoked to be verbose. This is
+handy when you’re trying to see the sub-tools invoked by each tool invoked
+by the makefile. For example, this will pass <tt class="docutils literal"><span class="pre">-v</span></tt> to the GCC compilers
+which causes it to print out the command lines it uses to invoke sub-tools
+(compiler, assembler, linker).</dd>
+</dl>
+<dl class="docutils" id="usedlibs">
+<dt><tt class="docutils literal"><span class="pre">USEDLIBS</span></tt></dt>
+<dd>Specifies the list of project libraries that will be linked into the tool or
+library.</dd>
+<dt><tt class="docutils literal"><span class="pre">VERBOSE</span></tt></dt>
+<dd>Tells the Makefile system to produce detailed output of what it is doing
+instead of just summary comments. This will generate a LOT of output.</dd>
+</dl>
+</div>
+<div class="section" id="override-variables">
+<h3><a class="toc-backref" href="#id37">Override Variables</a><a class="headerlink" href="#override-variables" title="Permalink to this headline">¶</a></h3>
+<p>Override variables can be used to override the default values provided by the
+LLVM makefile system. These variables can be set in several ways:</p>
+<ul class="simple">
+<li>In the environment (e.g. setenv, export) — not recommended.</li>
+<li>On the <tt class="docutils literal"><span class="pre">make</span></tt> command line — recommended.</li>
+<li>On the <tt class="docutils literal"><span class="pre">configure</span></tt> command line.</li>
+<li>In the Makefile (only <em>after</em> the inclusion of <a class="reference internal" href="#level-makefile-common">$(LEVEL)/Makefile.common</a>).</li>
+</ul>
+<p>The override variables are given below:</p>
+<dl class="docutils">
+<dt><tt class="docutils literal"><span class="pre">AR</span></tt> (defaulted)</dt>
+<dd>Specifies the path to the <tt class="docutils literal"><span class="pre">ar</span></tt> tool.</dd>
+<dt><tt class="docutils literal"><span class="pre">PROJ_OBJ_DIR</span></tt></dt>
+<dd>The directory into which the products of build rules will be placed. This
+might be the same as <a class="reference internal" href="#proj-src-dir">PROJ_SRC_DIR</a> but typically is not.</dd>
+</dl>
+<dl class="docutils" id="proj-src-dir">
+<dt><tt class="docutils literal"><span class="pre">PROJ_SRC_DIR</span></tt></dt>
+<dd>The directory which contains the source files to be built.</dd>
+<dt><tt class="docutils literal"><span class="pre">BUILD_EXAMPLES</span></tt></dt>
+<dd>If set to 1, build examples in <tt class="docutils literal"><span class="pre">examples</span></tt> and (if building Clang)
+<tt class="docutils literal"><span class="pre">tools/clang/examples</span></tt> directories.</dd>
+<dt><tt class="docutils literal"><span class="pre">BZIP2</span></tt> (configured)</dt>
+<dd>The path to the <tt class="docutils literal"><span class="pre">bzip2</span></tt> tool.</dd>
+<dt><tt class="docutils literal"><span class="pre">CC</span></tt> (configured)</dt>
+<dd>The path to the ‘C’ compiler.</dd>
+<dt><tt class="docutils literal"><span class="pre">CFLAGS</span></tt></dt>
+<dd>Additional flags to be passed to the ‘C’ compiler.</dd>
+<dt><tt class="docutils literal"><span class="pre">CPPFLAGS</span></tt></dt>
+<dd>Additional flags passed to the C/C++ preprocessor.</dd>
+<dt><tt class="docutils literal"><span class="pre">CXX</span></tt></dt>
+<dd>Specifies the path to the C++ compiler.</dd>
+<dt><tt class="docutils literal"><span class="pre">CXXFLAGS</span></tt></dt>
+<dd>Additional flags to be passed to the C++ compiler.</dd>
+<dt><tt class="docutils literal"><span class="pre">DATE</span></tt> (configured)</dt>
+<dd>Specifies the path to the <tt class="docutils literal"><span class="pre">date</span></tt> program or any program that can generate
+the current date and time on its standard output.</dd>
+<dt><tt class="docutils literal"><span class="pre">DOT</span></tt> (configured)</dt>
+<dd>Specifies the path to the <tt class="docutils literal"><span class="pre">dot</span></tt> tool or <tt class="docutils literal"><span class="pre">false</span></tt> if there isn’t one.</dd>
+<dt><tt class="docutils literal"><span class="pre">ECHO</span></tt> (configured)</dt>
+<dd>Specifies the path to the <tt class="docutils literal"><span class="pre">echo</span></tt> tool for printing output.</dd>
+<dt><tt class="docutils literal"><span class="pre">EXEEXT</span></tt> (configured)</dt>
+<dd>Provides the extension to be used on executables built by the makefiles.
+The value may be empty on platforms that do not use file extensions for
+executables (e.g. Unix).</dd>
+<dt><tt class="docutils literal"><span class="pre">INSTALL</span></tt> (configured)</dt>
+<dd>Specifies the path to the <tt class="docutils literal"><span class="pre">install</span></tt> tool.</dd>
+<dt><tt class="docutils literal"><span class="pre">LDFLAGS</span></tt> (configured)</dt>
+<dd>Allows users to specify additional flags to pass to the linker.</dd>
+<dt><tt class="docutils literal"><span class="pre">LIBS</span></tt> (configured)</dt>
+<dd>The list of libraries that should be linked with each tool.</dd>
+<dt><tt class="docutils literal"><span class="pre">LIBTOOL</span></tt> (configured)</dt>
+<dd>Specifies the path to the <tt class="docutils literal"><span class="pre">libtool</span></tt> tool. This tool is renamed <tt class="docutils literal"><span class="pre">mklib</span></tt>
+by the <tt class="docutils literal"><span class="pre">configure</span></tt> script.</dd>
+<dt><tt class="docutils literal"><span class="pre">LLVMAS</span></tt> (defaulted)</dt>
+<dd>Specifies the path to the <tt class="docutils literal"><span class="pre">llvm-as</span></tt> tool.</dd>
+<dt><tt class="docutils literal"><span class="pre">LLVMGCC</span></tt> (defaulted)</dt>
+<dd>Specifies the path to the LLVM version of the GCC ‘C’ Compiler.</dd>
+<dt><tt class="docutils literal"><span class="pre">LLVMGXX</span></tt> (defaulted)</dt>
+<dd>Specifies the path to the LLVM version of the GCC C++ Compiler.</dd>
+<dt><tt class="docutils literal"><span class="pre">LLVMLD</span></tt> (defaulted)</dt>
+<dd>Specifies the path to the LLVM bitcode linker tool</dd>
+<dt><tt class="docutils literal"><span class="pre">LLVM_OBJ_ROOT</span></tt> (configured)</dt>
+<dd>Specifies the top directory into which the output of the build is placed.</dd>
+<dt><tt class="docutils literal"><span class="pre">LLVM_SRC_ROOT</span></tt> (configured)</dt>
+<dd>Specifies the top directory in which the sources are found.</dd>
+<dt><tt class="docutils literal"><span class="pre">LLVM_TARBALL_NAME</span></tt> (configured)</dt>
+<dd>Specifies the name of the distribution tarball to create. This is configured
+from the name of the project and its version number.</dd>
+<dt><tt class="docutils literal"><span class="pre">MKDIR</span></tt> (defaulted)</dt>
+<dd>Specifies the path to the <tt class="docutils literal"><span class="pre">mkdir</span></tt> tool that creates directories.</dd>
+<dt><tt class="docutils literal"><span class="pre">ONLY_TOOLS</span></tt></dt>
+<dd>If set, specifies the list of tools to build.</dd>
+<dt><tt class="docutils literal"><span class="pre">PLATFORMSTRIPOPTS</span></tt></dt>
+<dd>The options to provide to the linker to specify that a stripped (no symbols)
+executable should be built.</dd>
+<dt><tt class="docutils literal"><span class="pre">RANLIB</span></tt> (defaulted)</dt>
+<dd>Specifies the path to the <tt class="docutils literal"><span class="pre">ranlib</span></tt> tool.</dd>
+<dt><tt class="docutils literal"><span class="pre">RM</span></tt> (defaulted)</dt>
+<dd>Specifies the path to the <tt class="docutils literal"><span class="pre">rm</span></tt> tool.</dd>
+<dt><tt class="docutils literal"><span class="pre">SED</span></tt> (defaulted)</dt>
+<dd>Specifies the path to the <tt class="docutils literal"><span class="pre">sed</span></tt> tool.</dd>
+<dt><tt class="docutils literal"><span class="pre">SHLIBEXT</span></tt> (configured)</dt>
+<dd>Provides the filename extension to use for shared libraries.</dd>
+<dt><tt class="docutils literal"><span class="pre">TBLGEN</span></tt> (defaulted)</dt>
+<dd>Specifies the path to the <tt class="docutils literal"><span class="pre">tblgen</span></tt> tool.</dd>
+<dt><tt class="docutils literal"><span class="pre">TAR</span></tt> (defaulted)</dt>
+<dd>Specifies the path to the <tt class="docutils literal"><span class="pre">tar</span></tt> tool.</dd>
+<dt><tt class="docutils literal"><span class="pre">ZIP</span></tt> (defaulted)</dt>
+<dd>Specifies the path to the <tt class="docutils literal"><span class="pre">zip</span></tt> tool.</dd>
+</dl>
+</div>
+<div class="section" id="readable-variables">
+<h3><a class="toc-backref" href="#id38">Readable Variables</a><a class="headerlink" href="#readable-variables" title="Permalink to this headline">¶</a></h3>
+<p>Variables listed in the table below can be used by the user’s Makefile but
+should not be changed. Changing the value will generally cause the build to go
+wrong, so don’t do it.</p>
+<dl class="docutils">
+<dt><tt class="docutils literal"><span class="pre">bindir</span></tt></dt>
+<dd>The directory into which executables will ultimately be installed. This
+value is derived from the <tt class="docutils literal"><span class="pre">--prefix</span></tt> option given to <tt class="docutils literal"><span class="pre">configure</span></tt>.</dd>
+<dt><tt class="docutils literal"><span class="pre">BuildMode</span></tt></dt>
+<dd>The name of the type of build being performed: Debug, Release, or
+Profile.</dd>
+<dt><tt class="docutils literal"><span class="pre">bytecode_libdir</span></tt></dt>
+<dd>The directory into which bitcode libraries will ultimately be installed.
+This value is derived from the <tt class="docutils literal"><span class="pre">--prefix</span></tt> option given to <tt class="docutils literal"><span class="pre">configure</span></tt>.</dd>
+<dt><tt class="docutils literal"><span class="pre">ConfigureScriptFLAGS</span></tt></dt>
+<dd>Additional flags given to the <tt class="docutils literal"><span class="pre">configure</span></tt> script when reconfiguring.</dd>
+<dt><tt class="docutils literal"><span class="pre">DistDir</span></tt></dt>
+<dd>The <em>current</em> directory for which a distribution copy is being made.</dd>
+</dl>
+<dl class="docutils" id="echo">
+<dt><tt class="docutils literal"><span class="pre">Echo</span></tt></dt>
+<dd>The LLVM Makefile System output command. This provides the <tt class="docutils literal"><span class="pre">llvm[n]</span></tt>
+prefix and starts with <tt class="docutils literal"><span class="pre">@</span></tt> so the command itself is not printed by
+<tt class="docutils literal"><span class="pre">make</span></tt>.</dd>
+<dt><tt class="docutils literal"><span class="pre">EchoCmd</span></tt></dt>
+<dd>Same as <a class="reference internal" href="#echo">Echo</a> but without the leading <tt class="docutils literal"><span class="pre">@</span></tt>.</dd>
+<dt><tt class="docutils literal"><span class="pre">includedir</span></tt></dt>
+<dd>The directory into which include files will ultimately be installed. This
+value is derived from the <tt class="docutils literal"><span class="pre">--prefix</span></tt> option given to <tt class="docutils literal"><span class="pre">configure</span></tt>.</dd>
+<dt><tt class="docutils literal"><span class="pre">libdir</span></tt></dt>
+<dd>The directory into which native libraries will ultimately be installed.
+This value is derived from the <tt class="docutils literal"><span class="pre">--prefix</span></tt> option given to
+<tt class="docutils literal"><span class="pre">configure</span></tt>.</dd>
+<dt><tt class="docutils literal"><span class="pre">LibDir</span></tt></dt>
+<dd>The configuration specific directory into which libraries are placed before
+installation.</dd>
+<dt><tt class="docutils literal"><span class="pre">MakefileConfig</span></tt></dt>
+<dd>Full path of the <tt class="docutils literal"><span class="pre">Makefile.config</span></tt> file.</dd>
+<dt><tt class="docutils literal"><span class="pre">MakefileConfigIn</span></tt></dt>
+<dd>Full path of the <tt class="docutils literal"><span class="pre">Makefile.config.in</span></tt> file.</dd>
+<dt><tt class="docutils literal"><span class="pre">ObjDir</span></tt></dt>
+<dd>The configuration and directory specific directory where build objects
+(compilation results) are placed.</dd>
+<dt><tt class="docutils literal"><span class="pre">SubDirs</span></tt></dt>
+<dd>The complete list of sub-directories of the current directory as
+specified by other variables.</dd>
+<dt><tt class="docutils literal"><span class="pre">Sources</span></tt></dt>
+<dd>The complete list of source files.</dd>
+<dt><tt class="docutils literal"><span class="pre">sysconfdir</span></tt></dt>
+<dd>The directory into which configuration files will ultimately be
+installed. This value is derived from the <tt class="docutils literal"><span class="pre">--prefix</span></tt> option given to
+<tt class="docutils literal"><span class="pre">configure</span></tt>.</dd>
+<dt><tt class="docutils literal"><span class="pre">ToolDir</span></tt></dt>
+<dd>The configuration specific directory into which executables are placed
+before they are installed.</dd>
+<dt><tt class="docutils literal"><span class="pre">TopDistDir</span></tt></dt>
+<dd>The top most directory into which the distribution files are copied.</dd>
+<dt><tt class="docutils literal"><span class="pre">Verb</span></tt></dt>
+<dd>Use this as the first thing on your build script lines to enable or disable
+verbose mode. It expands to either an <tt class="docutils literal"><span class="pre">@</span></tt> (quiet mode) or nothing (verbose
+mode).</dd>
+</dl>
+</div>
+<div class="section" id="internal-variables">
+<h3><a class="toc-backref" href="#id39">Internal Variables</a><a class="headerlink" href="#internal-variables" title="Permalink to this headline">¶</a></h3>
+<p>Variables listed below are used by the LLVM Makefile System and considered
+internal. You should not use these variables under any circumstances.</p>
+<div class="highlight-makefile"><div class="highlight"><pre>Archive
+AR.Flags
+BaseNameSources
+BCLinkLib
+C.Flags
+Compile.C
+CompileCommonOpts
+Compile.CXX
+ConfigStatusScript
+ConfigureScript
+CPP.Flags
+CPP.Flags
+CXX.Flags
+DependFiles
+DestArchiveLib
+DestBitcodeLib
+DestModule
+DestSharedLib
+DestTool
+DistAlways
+DistCheckDir
+DistCheckTop
+DistFiles
+DistName
+DistOther
+DistSources
+DistSubDirs
+DistTarBZ2
+DistTarGZip
+DistZip
+ExtraLibs
+FakeSources
+INCFiles
+InternalTargets
+LD.Flags
+LibName.A
+LibName.BC
+LibName.LA
+LibName.O
+LibTool.Flags
+Link
+LinkModule
+LLVMLibDir
+LLVMLibsOptions
+LLVMLibsPaths
+LLVMToolDir
+LLVMUsedLibs
+LocalTargets
+Module
+ObjectsLO
+ObjectsO
+ObjMakefiles
+ParallelTargets
+PreConditions
+ProjLibsOptions
+ProjLibsPaths
+ProjUsedLibs
+Ranlib
+RecursiveTargets
+SrcMakefiles
+Strip
+StripWarnMsg
+TableGen
+TDFiles
+ToolBuildPath
+TopLevelTargets
+UserTargets
+</pre></div>
+</div>
+</div>
+</div>
+</div>
+
+
+ </div>
+ </div>
+ <div class="clearer"></div>
+ </div>
+ <div class="related">
+ <h3>Navigation</h3>
+ <ul>
+ <li class="right" style="margin-right: 10px">
+ <a href="genindex.html" title="General Index"
+ >index</a></li>
+ <li class="right" >
+ <a href="Projects.html" title="Creating an LLVM Project"
+ >next</a> |</li>
+ <li class="right" >
+ <a href="DeveloperPolicy.html" title="LLVM Developer Policy"
+ >previous</a> |</li>
+ <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+ <li><a href="index.html">Documentation</a>»</li>
+
+ </ul>
+ </div>
+ <div class="footer">
+ © Copyright 2003-2016, LLVM Project.
+ Last updated on 2016-01-04.
+ Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.3.
+ </div>
+ </body>
+</html>
\ No newline at end of file
Added: www-releases/trunk/3.7.1/docs/MarkedUpDisassembly.html
URL: http://llvm.org/viewvc/llvm-project/www-releases/trunk/3.7.1/docs/MarkedUpDisassembly.html?rev=257950&view=auto
==============================================================================
--- www-releases/trunk/3.7.1/docs/MarkedUpDisassembly.html (added)
+++ www-releases/trunk/3.7.1/docs/MarkedUpDisassembly.html Fri Jan 15 17:13:16 2016
@@ -0,0 +1,169 @@
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
+ <title>LLVMâs Optional Rich Disassembly Output — LLVM 3.7 documentation</title>
+
+ <link rel="stylesheet" href="_static/llvm-theme.css" type="text/css" />
+ <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
+
+ <script type="text/javascript">
+ var DOCUMENTATION_OPTIONS = {
+ URL_ROOT: './',
+ VERSION: '3.7',
+ COLLAPSE_INDEX: false,
+ FILE_SUFFIX: '.html',
+ HAS_SOURCE: true
+ };
+ </script>
+ <script type="text/javascript" src="_static/jquery.js"></script>
+ <script type="text/javascript" src="_static/underscore.js"></script>
+ <script type="text/javascript" src="_static/doctools.js"></script>
+ <link rel="top" title="LLVM 3.7 documentation" href="index.html" />
+ <link rel="next" title="System Library" href="SystemLibrary.html" />
+ <link rel="prev" title="The LLVM gold plugin" href="GoldPlugin.html" />
+<style type="text/css">
+ table.right { float: right; margin-left: 20px; }
+ table.right td { border: 1px solid #ccc; }
+</style>
+
+ </head>
+ <body>
+<div class="logo">
+ <a href="index.html">
+ <img src="_static/logo.png"
+ alt="LLVM Logo" width="250" height="88"/></a>
+</div>
+
+ <div class="related">
+ <h3>Navigation</h3>
+ <ul>
+ <li class="right" style="margin-right: 10px">
+ <a href="genindex.html" title="General Index"
+ accesskey="I">index</a></li>
+ <li class="right" >
+ <a href="SystemLibrary.html" title="System Library"
+ accesskey="N">next</a> |</li>
+ <li class="right" >
+ <a href="GoldPlugin.html" title="The LLVM gold plugin"
+ accesskey="P">previous</a> |</li>
+ <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+ <li><a href="index.html">Documentation</a>»</li>
+
+ </ul>
+ </div>
+
+
+ <div class="document">
+ <div class="documentwrapper">
+ <div class="body">
+
+ <div class="section" id="llvm-s-optional-rich-disassembly-output">
+<h1>LLVM’s Optional Rich Disassembly Output<a class="headerlink" href="#llvm-s-optional-rich-disassembly-output" title="Permalink to this headline">¶</a></h1>
+<div class="contents local topic" id="contents">
+<ul class="simple">
+<li><a class="reference internal" href="#introduction" id="id2">Introduction</a></li>
+<li><a class="reference internal" href="#instruction-annotations" id="id3">Instruction Annotations</a><ul>
+<li><a class="reference internal" href="#contextual-markups" id="id4">Contextual markups</a></li>
+<li><a class="reference internal" href="#c-api-details" id="id5">C API Details</a></li>
+</ul>
+</li>
+</ul>
+</div>
+<div class="section" id="introduction">
+<h2><a class="toc-backref" href="#id2">Introduction</a><a class="headerlink" href="#introduction" title="Permalink to this headline">¶</a></h2>
+<p>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.</p>
+<p>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.</p>
+<p>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.</p>
+<p>After calling <tt class="docutils literal"><span class="pre">LLVMCreateDisasm()</span></tt> to create a disassembler context the
+optional output is enable with this call:</p>
+<div class="highlight-c"><div class="highlight"><pre><span class="n">LLVMSetDisasmOptions</span><span class="p">(</span><span class="n">DC</span><span class="p">,</span> <span class="n">LLVMDisassembler_Option_UseMarkup</span><span class="p">);</span>
+</pre></div>
+</div>
+<p>Then subsequent calls to <tt class="docutils literal"><span class="pre">LLVMDisasmInstruction()</span></tt> will return output strings
+with the marked up annotations.</p>
+</div>
+<div class="section" id="instruction-annotations">
+<h2><a class="toc-backref" href="#id3">Instruction Annotations</a><a class="headerlink" href="#instruction-annotations" title="Permalink to this headline">¶</a></h2>
+<div class="section" id="contextual-markups">
+<span id="id1"></span><h3><a class="toc-backref" href="#id4">Contextual markups</a><a class="headerlink" href="#contextual-markups" title="Permalink to this headline">¶</a></h3>
+<p>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.</p>
+<p>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).</p>
+<div class="highlight-bat"><div class="highlight"><pre>annotation: <span class="s1">'<'</span> tag-name tag-modifier-list <span class="s1">':'</span> annotated-text <span class="s1">'>'</span>
+tag-name: identifier
+tag-modifier-list: comma delimited identifier list
+</pre></div>
+</div>
+<p>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.</p>
+<p>The tag-modifier-list is typically additional target-specific context, such as
+register class.</p>
+<p>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.</p>
+<p>For example, a possible annotation of an ARM load of a stack-relative location
+might be annotated as:</p>
+<div class="highlight-nasm"><div class="highlight"><pre>ldr <reg gpr:r0>, <mem regoffset:[<reg gpr:sp>, <imm:#4>]>
+</pre></div>
+</div>
+<p>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.</p>
+</div>
+<div class="section" id="c-api-details">
+<h3><a class="toc-backref" href="#id5">C API Details</a><a class="headerlink" href="#c-api-details" title="Permalink to this headline">¶</a></h3>
+<p>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, <tt class="docutils literal"><span class="pre">LLVMSetDisasmOptions()</span></tt> and the
+<tt class="docutils literal"><span class="pre">LLVMDisassembler_Option_UseMarkup</span></tt> option (see above).</p>
+</div>
+</div>
+</div>
+
+
+ </div>
+ </div>
+ <div class="clearer"></div>
+ </div>
+ <div class="related">
+ <h3>Navigation</h3>
+ <ul>
+ <li class="right" style="margin-right: 10px">
+ <a href="genindex.html" title="General Index"
+ >index</a></li>
+ <li class="right" >
+ <a href="SystemLibrary.html" title="System Library"
+ >next</a> |</li>
+ <li class="right" >
+ <a href="GoldPlugin.html" title="The LLVM gold plugin"
+ >previous</a> |</li>
+ <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+ <li><a href="index.html">Documentation</a>»</li>
+
+ </ul>
+ </div>
+ <div class="footer">
+ © Copyright 2003-2016, LLVM Project.
+ Last updated on 2016-01-04.
+ Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.3.
+ </div>
+ </body>
+</html>
\ No newline at end of file
Added: www-releases/trunk/3.7.1/docs/MergeFunctions.html
URL: http://llvm.org/viewvc/llvm-project/www-releases/trunk/3.7.1/docs/MergeFunctions.html?rev=257950&view=auto
==============================================================================
--- www-releases/trunk/3.7.1/docs/MergeFunctions.html (added)
+++ www-releases/trunk/3.7.1/docs/MergeFunctions.html Fri Jan 15 17:13:16 2016
@@ -0,0 +1,819 @@
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
+ <title>MergeFunctions pass, how it works — LLVM 3.7 documentation</title>
+
+ <link rel="stylesheet" href="_static/llvm-theme.css" type="text/css" />
+ <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
+
+ <script type="text/javascript">
+ var DOCUMENTATION_OPTIONS = {
+ URL_ROOT: './',
+ VERSION: '3.7',
+ COLLAPSE_INDEX: false,
+ FILE_SUFFIX: '.html',
+ HAS_SOURCE: true
+ };
+ </script>
+ <script type="text/javascript" src="_static/jquery.js"></script>
+ <script type="text/javascript" src="_static/underscore.js"></script>
+ <script type="text/javascript" src="_static/doctools.js"></script>
+ <link rel="top" title="LLVM 3.7 documentation" href="index.html" />
+ <link rel="next" title="Bitsets" href="BitSets.html" />
+ <link rel="prev" title="Garbage Collection Safepoints in LLVM" href="Statepoints.html" />
+<style type="text/css">
+ table.right { float: right; margin-left: 20px; }
+ table.right td { border: 1px solid #ccc; }
+</style>
+
+ </head>
+ <body>
+<div class="logo">
+ <a href="index.html">
+ <img src="_static/logo.png"
+ alt="LLVM Logo" width="250" height="88"/></a>
+</div>
+
+ <div class="related">
+ <h3>Navigation</h3>
+ <ul>
+ <li class="right" style="margin-right: 10px">
+ <a href="genindex.html" title="General Index"
+ accesskey="I">index</a></li>
+ <li class="right" >
+ <a href="BitSets.html" title="Bitsets"
+ accesskey="N">next</a> |</li>
+ <li class="right" >
+ <a href="Statepoints.html" title="Garbage Collection Safepoints in LLVM"
+ accesskey="P">previous</a> |</li>
+ <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+ <li><a href="index.html">Documentation</a>»</li>
+
+ </ul>
+ </div>
+
+
+ <div class="document">
+ <div class="documentwrapper">
+ <div class="body">
+
+ <div class="section" id="mergefunctions-pass-how-it-works">
+<h1>MergeFunctions pass, how it works<a class="headerlink" href="#mergefunctions-pass-how-it-works" title="Permalink to this headline">¶</a></h1>
+<div class="contents local topic" id="contents">
+<ul class="simple">
+<li><a class="reference internal" href="#introduction" id="id1">Introduction</a><ul>
+<li><a class="reference internal" href="#why-would-i-want-to-read-this-document" id="id2">Why would I want to read this document?</a></li>
+<li><a class="reference internal" href="#what-should-i-know-to-be-able-to-follow-along-with-this-document" id="id3">What should I know to be able to follow along with this document?</a></li>
+<li><a class="reference internal" href="#what-i-gain-by-reading-this-document" id="id4">What I gain by reading this document?</a></li>
+<li><a class="reference internal" href="#narrative-structure" id="id5">Narrative structure</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#basics" id="id6">Basics</a><ul>
+<li><a class="reference internal" href="#how-to-do-it" id="id7">How to do it?</a><ul>
+<li><a class="reference internal" href="#possible-solutions" id="id8">Possible solutions</a><ul>
+<li><a class="reference internal" href="#random-access" id="id9">Random-access</a></li>
+<li><a class="reference internal" href="#logarithmical-search" id="id10">Logarithmical search</a></li>
+<li><a class="reference internal" href="#present-state" id="id11">Present state</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#mergefunctions-main-fields-and-runonmodule" id="id12">MergeFunctions, main fields and runOnModule</a><ul>
+<li><a class="reference internal" href="#runonmodule" id="id13">runOnModule</a></li>
+<li><a class="reference internal" href="#comparison-and-logarithmical-search" id="id14">Comparison and logarithmical search</a></li>
+</ul>
+</li>
+</ul>
+</li>
+</ul>
+</li>
+<li><a class="reference internal" href="#functions-comparison" id="id15">Functions comparison</a><ul>
+<li><a class="reference internal" href="#functioncomparator-compare-void" id="id16">FunctionComparator::compare(void)</a></li>
+<li><a class="reference internal" href="#functioncomparator-cmptype" id="id17">FunctionComparator::cmpType</a></li>
+<li><a class="reference internal" href="#cmpvalues-const-value-const-value" id="id18">cmpValues(const Value*, const Value*)</a><ul>
+<li><a class="reference internal" href="#what-we-assiciate-in-cmpvalues" id="id19">What we assiciate in cmpValues?</a></li>
+<li><a class="reference internal" href="#how-to-implement-cmpvalues" id="id20">How to implement cmpValues?</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#cmpconstants" id="id21">cmpConstants</a></li>
+<li><a class="reference internal" href="#compare-const-basicblock-const-basicblock" id="id22">compare(const BasicBlock*, const BasicBlock*)</a></li>
+<li><a class="reference internal" href="#cmpgep" id="id23">cmpGEP</a></li>
+<li><a class="reference internal" href="#cmpoperation" id="id24">cmpOperation</a></li>
+<li><a class="reference internal" href="#o-log-n" id="id25">O(log(N))</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#merging-process-mergetwofunctions" id="id26">Merging process, mergeTwoFunctions</a><ul>
+<li><a class="reference internal" href="#if-f-may-be-overridden" id="id27">If âFâ may be overridden</a><ul>
+<li><a class="reference internal" href="#hasglobalaliases-removeusers" id="id28">HasGlobalAliases, removeUsers</a></li>
+<li><a class="reference internal" href="#no-global-aliases-replacedirectcallers" id="id29">No global aliases, replaceDirectCallers</a><ul>
+<li><a class="reference internal" href="#if-f-could-not-be-overridden-fix-it" id="id30">If âFâ could not be overridden, fix it!</a></li>
+</ul>
+</li>
+</ul>
+</li>
+</ul>
+</li>
+<li><a class="reference internal" href="#that-s-it" id="id31">That’s it.</a></li>
+</ul>
+</div>
+<div class="section" id="introduction">
+<h2><a class="toc-backref" href="#id1">Introduction</a><a class="headerlink" href="#introduction" title="Permalink to this headline">¶</a></h2>
+<p>Sometimes code contains equal functions, or functions that does exactly the same
+thing even though they are non-equal on the IR level (e.g.: multiplication on 2
+and ‘shl 1’). It could happen due to several reasons: mainly, the usage of
+templates and automatic code generators. Though, sometimes user itself could
+write the same thing twice :-)</p>
+<p>The main purpose of this pass is to recognize such functions and merge them.</p>
+<div class="section" id="why-would-i-want-to-read-this-document">
+<h3><a class="toc-backref" href="#id2">Why would I want to read this document?</a><a class="headerlink" href="#why-would-i-want-to-read-this-document" title="Permalink to this headline">¶</a></h3>
+<p>Document is the extension to pass comments and describes the pass logic. It
+describes algorithm that is used in order to compare functions, it also
+explains how we could combine equal functions correctly, keeping module valid.</p>
+<p>Material is brought in top-down form, so reader could start learn pass from
+ideas and end up with low-level algorithm details, thus preparing him for
+reading the sources.</p>
+<p>So main goal is do describe algorithm and logic here; the concept. This document
+is good for you, if you <em>don’t want</em> to read the source code, but want to
+understand pass algorithms. Author tried not to repeat the source-code and
+cover only common cases, and thus avoid cases when after minor code changes we
+need to update this document.</p>
+</div>
+<div class="section" id="what-should-i-know-to-be-able-to-follow-along-with-this-document">
+<h3><a class="toc-backref" href="#id3">What should I know to be able to follow along with this document?</a><a class="headerlink" href="#what-should-i-know-to-be-able-to-follow-along-with-this-document" title="Permalink to this headline">¶</a></h3>
+<p>Reader should be familiar with common compile-engineering principles and LLVM
+code fundamentals. In this article we suppose reader is familiar with
+<a class="reference external" href="http://en.wikipedia.org/wiki/Static_single_assignment_form">Single Static Assingment</a>
+concepts. Understanding of
+<a class="reference external" href="http://llvm.org/docs/LangRef.html#high-level-structure">IR structure</a> is
+also important.</p>
+<p>We will use such terms as
+“<a class="reference external" href="http://llvm.org/docs/LangRef.html#high-level-structure">module</a>”,
+“<a class="reference external" href="http://llvm.org/docs/ProgrammersManual.html#the-function-class">function</a>”,
+“<a class="reference external" href="http://en.wikipedia.org/wiki/Basic_block">basic block</a>”,
+“<a class="reference external" href="http://llvm.org/docs/ProgrammersManual.html#the-user-class">user</a>”,
+“<a class="reference external" href="http://llvm.org/docs/ProgrammersManual.html#the-value-class">value</a>”,
+“<a class="reference external" href="http://llvm.org/docs/ProgrammersManual.html#the-instruction-class">instruction</a>”.</p>
+<p>As a good start point, Kaleidoscope tutorial could be used:</p>
+<p><a class="reference internal" href="tutorial/index.html"><em>LLVM Tutorial: Table of Contents</em></a></p>
+<p>Especially it’s important to understand chapter 3 of tutorial:</p>
+<p><a class="reference internal" href="tutorial/LangImpl3.html"><em>Kaleidoscope: Code generation to LLVM IR</em></a></p>
+<p>Reader also should know how passes work in LLVM, they could use next article as
+a reference and start point here:</p>
+<p><a class="reference internal" href="WritingAnLLVMPass.html"><em>Writing an LLVM Pass</em></a></p>
+<p>What else? Well perhaps reader also should have some experience in LLVM pass
+debugging and bug-fixing.</p>
+</div>
+<div class="section" id="what-i-gain-by-reading-this-document">
+<h3><a class="toc-backref" href="#id4">What I gain by reading this document?</a><a class="headerlink" href="#what-i-gain-by-reading-this-document" title="Permalink to this headline">¶</a></h3>
+<p>Main purpose is to provide reader with comfortable form of algorithms
+description, namely the human reading text. Since it could be hard to
+understand algorithm straight from the source code: pass uses some principles
+that have to be explained first.</p>
+<p>Author wishes to everybody to avoid case, when you read code from top to bottom
+again and again, and yet you don’t understand why we implemented it that way.</p>
+<p>We hope that after this article reader could easily debug and improve
+MergeFunctions pass and thus help LLVM project.</p>
+</div>
+<div class="section" id="narrative-structure">
+<h3><a class="toc-backref" href="#id5">Narrative structure</a><a class="headerlink" href="#narrative-structure" title="Permalink to this headline">¶</a></h3>
+<p>Article consists of three parts. First part explains pass functionality on the
+top-level. Second part describes the comparison procedure itself. The third
+part describes the merging process.</p>
+<p>In every part author also tried to put the contents into the top-down form.
+First, the top-level methods will be described, while the terminal ones will be
+at the end, in the tail of each part. If reader will see the reference to the
+method that wasn’t described yet, they will find its description a bit below.</p>
+</div>
+</div>
+<div class="section" id="basics">
+<h2><a class="toc-backref" href="#id6">Basics</a><a class="headerlink" href="#basics" title="Permalink to this headline">¶</a></h2>
+<div class="section" id="how-to-do-it">
+<h3><a class="toc-backref" href="#id7">How to do it?</a><a class="headerlink" href="#how-to-do-it" title="Permalink to this headline">¶</a></h3>
+<p>Do we need to merge functions? Obvious thing is: yes that’s a quite possible
+case, since usually we <em>do</em> have duplicates. And it would be good to get rid of
+them. But how to detect such a duplicates? The idea is next: we split functions
+onto small bricks (parts), then we compare “bricks” amount, and if it equal,
+compare “bricks” themselves, and then do our conclusions about functions
+themselves.</p>
+<p>What the difference it could be? For example, on machine with 64-bit pointers
+(let’s assume we have only one address space), one function stores 64-bit
+integer, while another one stores a pointer. So if the target is a machine
+mentioned above, and if functions are identical, except the parameter type (we
+could consider it as a part of function type), then we can treat <tt class="docutils literal"><span class="pre">uint64_t</span></tt>
+and``void*`` as equal.</p>
+<p>It was just an example; possible details are described a bit below.</p>
+<p>As another example reader may imagine two more functions. First function
+performs multiplication on 2, while the second one performs arithmetic right
+shift on 1.</p>
+<div class="section" id="possible-solutions">
+<h4><a class="toc-backref" href="#id8">Possible solutions</a><a class="headerlink" href="#possible-solutions" title="Permalink to this headline">¶</a></h4>
+<p>Let’s briefly consider possible options about how and what we have to implement
+in order to create full-featured functions merging, and also what it would
+meant for us.</p>
+<p>Equal functions detection, obviously supposes “detector” method to be
+implemented, latter should answer the question “whether functions are equal”.
+This “detector” method consists of tiny “sub-detectors”, each of them answers
+exactly the same question, but for function parts.</p>
+<p>As the second step, we should merge equal functions. So it should be a “merger”
+method. “Merger” accepts two functions <em>F1</em> and <em>F2</em>, and produces <em>F1F2</em>
+function, the result of merging.</p>
+<p>Having such a routines in our hands, we can process whole module, and merge all
+equal functions.</p>
+<p>In this case, we have to compare every function with every another function. As
+reader could notice, this way seems to be quite expensive. Of course we could
+introduce hashing and other helpers, but it is still just an optimization, and
+thus the level of O(N*N) complexity.</p>
+<p>Can we reach another level? Could we introduce logarithmical search, or random
+access lookup? The answer is: “yes”.</p>
+<div class="section" id="random-access">
+<h5><a class="toc-backref" href="#id9">Random-access</a><a class="headerlink" href="#random-access" title="Permalink to this headline">¶</a></h5>
+<p>How it could be done? Just convert each function to number, and gather all of
+them in special hash-table. Functions with equal hash are equal. Good hashing
+means, that every function part must be taken into account. That means we have
+to convert every function part into some number, and then add it into hash.
+Lookup-up time would be small, but such approach adds some delay due to hashing
+routine.</p>
+</div>
+<div class="section" id="logarithmical-search">
+<h5><a class="toc-backref" href="#id10">Logarithmical search</a><a class="headerlink" href="#logarithmical-search" title="Permalink to this headline">¶</a></h5>
+<p>We could introduce total ordering among the functions set, once we had it we
+could then implement a logarithmical search. Lookup time still depends on N,
+but adds a little of delay (<em>log(N)</em>).</p>
+</div>
+<div class="section" id="present-state">
+<h5><a class="toc-backref" href="#id11">Present state</a><a class="headerlink" href="#present-state" title="Permalink to this headline">¶</a></h5>
+<p>Both of approaches (random-access and logarithmical) has been implemented and
+tested. And both of them gave a very good improvement. And what was most
+surprising, logarithmical search was faster; sometimes up to 15%. Hashing needs
+some extra CPU time, and it is the main reason why it works slower; in most of
+cases total “hashing” time was greater than total “logarithmical-search” time.</p>
+<p>So, preference has been granted to the “logarithmical search”.</p>
+<p>Though in the case of need, <em>logarithmical-search</em> (read “total-ordering”) could
+be used as a milestone on our way to the <em>random-access</em> implementation.</p>
+<p>Every comparison is based either on the numbers or on flags comparison. In
+<em>random-access</em> approach we could use the same comparison algorithm. During
+comparison we exit once we find the difference, but here we might have to scan
+whole function body every time (note, it could be slower). Like in
+“total-ordering”, we will track every numbers and flags, but instead of
+comparison, we should get numbers sequence and then create the hash number. So,
+once again, <em>total-ordering</em> could be considered as a milestone for even faster
+(in theory) random-access approach.</p>
+</div>
+</div>
+<div class="section" id="mergefunctions-main-fields-and-runonmodule">
+<h4><a class="toc-backref" href="#id12">MergeFunctions, main fields and runOnModule</a><a class="headerlink" href="#mergefunctions-main-fields-and-runonmodule" title="Permalink to this headline">¶</a></h4>
+<p>There are two most important fields in class:</p>
+<p><tt class="docutils literal"><span class="pre">FnTree</span></tt> â the set of all unique functions. It keeps items that couldn’t be
+merged with each other. It is defined as:</p>
+<p><tt class="docutils literal"><span class="pre">std::set<FunctionNode></span> <span class="pre">FnTree;</span></tt></p>
+<p>Here <tt class="docutils literal"><span class="pre">FunctionNode</span></tt> is a wrapper for <tt class="docutils literal"><span class="pre">llvm::Function</span></tt> class, with
+implemented â<â operator among the functions set (below we explain how it works
+exactly; this is a key point in fast functions comparison).</p>
+<p><tt class="docutils literal"><span class="pre">Deferred</span></tt> â merging process can affect bodies of functions that are in
+<tt class="docutils literal"><span class="pre">FnTree</span></tt> already. Obviously such functions should be rechecked again. In this
+case we remove them from <tt class="docutils literal"><span class="pre">FnTree</span></tt>, and mark them as to be rescanned, namely
+put them into <tt class="docutils literal"><span class="pre">Deferred</span></tt> list.</p>
+<div class="section" id="runonmodule">
+<h5><a class="toc-backref" href="#id13">runOnModule</a><a class="headerlink" href="#runonmodule" title="Permalink to this headline">¶</a></h5>
+<p>The algorithm is pretty simple:</p>
+<ol class="arabic simple">
+<li>Put all module’s functions into the <em>worklist</em>.</li>
+</ol>
+<p>2. Scan <em>worklist</em>‘s functions twice: first enumerate only strong functions and
+then only weak ones:</p>
+<blockquote>
+<div>2.1. Loop body: take function from <em>worklist</em> (call it <em>FCur</em>) and try to
+insert it into <em>FnTree</em>: check whether <em>FCur</em> is equal to one of functions
+in <em>FnTree</em>. If there <em>is</em> equal function in <em>FnTree</em> (call it <em>FExists</em>):
+merge function <em>FCur</em> with <em>FExists</em>. Otherwise add function from <em>worklist</em>
+to <em>FnTree</em>.</div></blockquote>
+<p>3. Once <em>worklist</em> scanning and merging operations is complete, check <em>Deferred</em>
+list. If it is not empty: refill <em>worklist</em> contents with <em>Deferred</em> list and
+do step 2 again, if <em>Deferred</em> is empty, then exit from method.</p>
+</div>
+<div class="section" id="comparison-and-logarithmical-search">
+<h5><a class="toc-backref" href="#id14">Comparison and logarithmical search</a><a class="headerlink" href="#comparison-and-logarithmical-search" title="Permalink to this headline">¶</a></h5>
+<p>Let’s recall our task: for every function <em>F</em> from module <em>M</em>, we have to find
+equal functions <em>F`</em> in shortest time, and merge them into the single function.</p>
+<p>Defining total ordering among the functions set allows to organize functions
+into the binary tree. The lookup procedure complexity would be estimated as
+O(log(N)) in this case. But how to define <em>total-ordering</em>?</p>
+<p>We have to introduce a single rule applicable to every pair of functions, and
+following this rule then evaluate which of them is greater. What kind of rule
+it could be? Let’s declare it as “compare” method, that returns one of 3
+possible values:</p>
+<p>-1, left is <em>less</em> than right,</p>
+<p>0, left and right are <em>equal</em>,</p>
+<p>1, left is <em>greater</em> than right.</p>
+<p>Of course it means, that we have to maintain
+<em>strict and non-strict order relation properties</em>:</p>
+<ul class="simple">
+<li>reflexivity (<tt class="docutils literal"><span class="pre">a</span> <span class="pre"><=</span> <span class="pre">a</span></tt>, <tt class="docutils literal"><span class="pre">a</span> <span class="pre">==</span> <span class="pre">a</span></tt>, <tt class="docutils literal"><span class="pre">a</span> <span class="pre">>=</span> <span class="pre">a</span></tt>),</li>
+<li>antisymmetry (if <tt class="docutils literal"><span class="pre">a</span> <span class="pre"><=</span> <span class="pre">b</span></tt> and <tt class="docutils literal"><span class="pre">b</span> <span class="pre"><=</span> <span class="pre">a</span></tt> then <tt class="docutils literal"><span class="pre">a</span> <span class="pre">==</span> <span class="pre">b</span></tt>),</li>
+<li>transitivity (<tt class="docutils literal"><span class="pre">a</span> <span class="pre"><=</span> <span class="pre">b</span></tt> and <tt class="docutils literal"><span class="pre">b</span> <span class="pre"><=</span> <span class="pre">c</span></tt>, then <tt class="docutils literal"><span class="pre">a</span> <span class="pre"><=</span> <span class="pre">c</span></tt>)</li>
+<li>asymmetry (if <tt class="docutils literal"><span class="pre">a</span> <span class="pre"><</span> <span class="pre">b</span></tt>, then <tt class="docutils literal"><span class="pre">a</span> <span class="pre">></span> <span class="pre">b</span></tt> or <tt class="docutils literal"><span class="pre">a</span> <span class="pre">==</span> <span class="pre">b</span></tt>).</li>
+</ul>
+<p>As it was mentioned before, comparison routine consists of
+“sub-comparison-routines”, each of them also consists
+“sub-comparison-routines”, and so on, finally it ends up with a primitives
+comparison.</p>
+<p>Below, we will use the next operations:</p>
+<ol class="arabic simple">
+<li><tt class="docutils literal"><span class="pre">cmpNumbers(number1,</span> <span class="pre">number2)</span></tt> is method that returns -1 if left is less
+than right; 0, if left and right are equal; and 1 otherwise.</li>
+<li><tt class="docutils literal"><span class="pre">cmpFlags(flag1,</span> <span class="pre">flag2)</span></tt> is hypothetical method that compares two flags.
+The logic is the same as in <tt class="docutils literal"><span class="pre">cmpNumbers</span></tt>, where <tt class="docutils literal"><span class="pre">true</span></tt> is 1, and
+<tt class="docutils literal"><span class="pre">false</span></tt> is 0.</li>
+</ol>
+<p>The rest of article is based on <em>MergeFunctions.cpp</em> source code
+(<em><llvm_dir>/lib/Transforms/IPO/MergeFunctions.cpp</em>). We would like to ask
+reader to keep this file open nearby, so we could use it as a reference for
+further explanations.</p>
+<p>Now we’re ready to proceed to the next chapter and see how it works.</p>
+</div>
+</div>
+</div>
+</div>
+<div class="section" id="functions-comparison">
+<h2><a class="toc-backref" href="#id15">Functions comparison</a><a class="headerlink" href="#functions-comparison" title="Permalink to this headline">¶</a></h2>
+<p>At first, let’s define how exactly we compare complex objects.</p>
+<p>Complex objects comparison (function, basic-block, etc) is mostly based on its
+sub-objects comparison results. So it is similar to the next “tree” objects
+comparison:</p>
+<ol class="arabic simple">
+<li>For two trees <em>T1</em> and <em>T2</em> we perform <em>depth-first-traversal</em> and have
+two sequences as a product: “<em>T1Items</em>” and “<em>T2Items</em>”.</li>
+<li>Then compare chains “<em>T1Items</em>” and “<em>T2Items</em>” in
+most-significant-item-first order. Result of items comparison would be the
+result of <em>T1</em> and <em>T2</em> comparison itself.</li>
+</ol>
+<div class="section" id="functioncomparator-compare-void">
+<h3><a class="toc-backref" href="#id16">FunctionComparator::compare(void)</a><a class="headerlink" href="#functioncomparator-compare-void" title="Permalink to this headline">¶</a></h3>
+<p>Brief look at the source code tells us, that comparison starts in
+â<tt class="docutils literal"><span class="pre">int</span> <span class="pre">FunctionComparator::compare(void)</span></tt>â method.</p>
+<p>1. First parts to be compared are function’s attributes and some properties that
+outsides âattributesâ term, but still could make function different without
+changing its body. This part of comparison is usually done within simple
+<em>cmpNumbers</em> or <em>cmpFlags</em> operations (e.g.
+<tt class="docutils literal"><span class="pre">cmpFlags(F1->hasGC(),</span> <span class="pre">F2->hasGC())</span></tt>). Below is full list of function’s
+properties to be compared on this stage:</p>
+<blockquote>
+<div><ul class="simple">
+<li><em>Attributes</em> (those are returned by <tt class="docutils literal"><span class="pre">Function::getAttributes()</span></tt>
+method).</li>
+<li><em>GC</em>, for equivalence, <em>RHS</em> and <em>LHS</em> should be both either without
+<em>GC</em> or with the same one.</li>
+<li><em>Section</em>, just like a <em>GC</em>: <em>RHS</em> and <em>LHS</em> should be defined in the
+same section.</li>
+<li><em>Variable arguments</em>. <em>LHS</em> and <em>RHS</em> should be both either with or
+without <em>var-args</em>.</li>
+<li><em>Calling convention</em> should be the same.</li>
+</ul>
+</div></blockquote>
+<p>2. Function type. Checked by <tt class="docutils literal"><span class="pre">FunctionComparator::cmpType(Type*,</span> <span class="pre">Type*)</span></tt>
+method. It checks return type and parameters type; the method itself will be
+described later.</p>
+<p>3. Associate function formal parameters with each other. Then comparing function
+bodies, if we see the usage of <em>LHS</em>‘s <em>i</em>-th argument in <em>LHS</em>‘s body, then,
+we want to see usage of <em>RHS</em>‘s <em>i</em>-th argument at the same place in <em>RHS</em>‘s
+body, otherwise functions are different. On this stage we grant the preference
+to those we met later in function body (value we met first would be <em>less</em>).
+This is done by â<tt class="docutils literal"><span class="pre">FunctionComparator::cmpValues(const</span> <span class="pre">Value*,</span> <span class="pre">const</span> <span class="pre">Value*)</span></tt>â
+method (will be described a bit later).</p>
+<ol class="arabic simple" start="4">
+<li>Function body comparison. As it written in method comments:</li>
+</ol>
+<p>âWe do a CFG-ordered walk since the actual ordering of the blocks in the linked
+list is immaterial. Our walk starts at the entry block for both functions, then
+takes each block from each terminator in order. As an artifact, this also means
+that unreachable blocks are ignored.â</p>
+<p>So, using this walk we get BBs from <em>left</em> and <em>right</em> in the same order, and
+compare them by â<tt class="docutils literal"><span class="pre">FunctionComparator::compare(const</span> <span class="pre">BasicBlock*,</span> <span class="pre">const</span>
+<span class="pre">BasicBlock*)</span></tt>â method.</p>
+<p>We also associate BBs with each other, like we did it with function formal
+arguments (see <tt class="docutils literal"><span class="pre">cmpValues</span></tt> method below).</p>
+</div>
+<div class="section" id="functioncomparator-cmptype">
+<h3><a class="toc-backref" href="#id17">FunctionComparator::cmpType</a><a class="headerlink" href="#functioncomparator-cmptype" title="Permalink to this headline">¶</a></h3>
+<p>Consider how types comparison works.</p>
+<p>1. Coerce pointer to integer. If left type is a pointer, try to coerce it to the
+integer type. It could be done if its address space is 0, or if address spaces
+are ignored at all. Do the same thing for the right type.</p>
+<p>2. If left and right types are equal, return 0. Otherwise we need to give
+preference to one of them. So proceed to the next step.</p>
+<p>3. If types are of different kind (different type IDs). Return result of type
+IDs comparison, treating them as a numbers (use <tt class="docutils literal"><span class="pre">cmpNumbers</span></tt> operation).</p>
+<p>4. If types are vectors or integers, return result of their pointers comparison,
+comparing them as numbers.</p>
+<ol class="arabic" start="5">
+<li><p class="first">Check whether type ID belongs to the next group (call it equivalent-group):</p>
+<ul class="simple">
+<li>Void</li>
+<li>Float</li>
+<li>Double</li>
+<li>X86_FP80</li>
+<li>FP128</li>
+<li>PPC_FP128</li>
+<li>Label</li>
+<li>Metadata.</li>
+</ul>
+<p>If ID belongs to group above, return 0. Since it’s enough to see that
+types has the same <tt class="docutils literal"><span class="pre">TypeID</span></tt>. No additional information is required.</p>
+</li>
+</ol>
+<p>6. Left and right are pointers. Return result of address space comparison
+(numbers comparison).</p>
+<p>7. Complex types (structures, arrays, etc.). Follow complex objects comparison
+technique (see the very first paragraph of this chapter). Both <em>left</em> and
+<em>right</em> are to be expanded and their element types will be checked the same
+way. If we get -1 or 1 on some stage, return it. Otherwise return 0.</p>
+<p>8. Steps 1-6 describe all the possible cases, if we passed steps 1-6 and didn’t
+get any conclusions, then invoke <tt class="docutils literal"><span class="pre">llvm_unreachable</span></tt>, since it’s quite
+unexpectable case.</p>
+</div>
+<div class="section" id="cmpvalues-const-value-const-value">
+<h3><a class="toc-backref" href="#id18">cmpValues(const Value*, const Value*)</a><a class="headerlink" href="#cmpvalues-const-value-const-value" title="Permalink to this headline">¶</a></h3>
+<p>Method that compares local values.</p>
+<p>This method gives us an answer on a very curious quesion: whether we could treat
+local values as equal, and which value is greater otherwise. It’s better to
+start from example:</p>
+<p>Consider situation when we’re looking at the same place in left function “<em>FL</em>”
+and in right function “<em>FR</em>”. And every part of <em>left</em> place is equal to the
+corresponding part of <em>right</em> place, and (!) both parts use <em>Value</em> instances,
+for example:</p>
+<div class="highlight-llvm"><div class="highlight"><pre>instr0 i32 %LV ; left side, function FL
+instr0 i32 %RV ; right side, function FR
+</pre></div>
+</div>
+<p>So, now our conclusion depends on <em>Value</em> instances comparison.</p>
+<p>Main purpose of this method is to determine relation between such values.</p>
+<p>What we expect from equal functions? At the same place, in functions “<em>FL</em>” and
+“<em>FR</em>” we expect to see <em>equal</em> values, or values <em>defined</em> at the same place
+in “<em>FL</em>” and “<em>FR</em>”.</p>
+<p>Consider small example here:</p>
+<div class="highlight-llvm"><div class="highlight"><pre>define void %f(i32 %pf0, i32 %pf1) {
+ instr0 i32 %pf0 instr1 i32 %pf1 instr2 i32 123
+}
+</pre></div>
+</div>
+<div class="highlight-llvm"><div class="highlight"><pre>define void %g(i32 %pg0, i32 %pg1) {
+ instr0 i32 %pg0 instr1 i32 %pg0 instr2 i32 123
+}
+</pre></div>
+</div>
+<p>In this example, <em>pf0</em> is associated with <em>pg0</em>, <em>pf1</em> is associated with <em>pg1</em>,
+and we also declare that <em>pf0</em> < <em>pf1</em>, and thus <em>pg0</em> < <em>pf1</em>.</p>
+<p>Instructions with opcode “<em>instr0</em>” would be <em>equal</em>, since their types and
+opcodes are equal, and values are <em>associated</em>.</p>
+<p>Instruction with opcode “<em>instr1</em>” from <em>f</em> is <em>greater</em> than instruction with
+opcode “<em>instr1</em>” from <em>g</em>; here we have equal types and opcodes, but “<em>pf1</em> is
+greater than “<em>pg0</em>”.</p>
+<p>And instructions with opcode “<em>instr2</em>” are equal, because their opcodes and
+types are equal, and the same constant is used as a value.</p>
+<div class="section" id="what-we-assiciate-in-cmpvalues">
+<h4><a class="toc-backref" href="#id19">What we assiciate in cmpValues?</a><a class="headerlink" href="#what-we-assiciate-in-cmpvalues" title="Permalink to this headline">¶</a></h4>
+<ul class="simple">
+<li>Function arguments. <em>i</em>-th argument from left function associated with
+<em>i</em>-th argument from right function.</li>
+<li>BasicBlock instances. In basic-block enumeration loop we associate <em>i</em>-th
+BasicBlock from the left function with <em>i</em>-th BasicBlock from the right
+function.</li>
+<li>Instructions.</li>
+<li>Instruction operands. Note, we can meet <em>Value</em> here we have never seen
+before. In this case it is not a function argument, nor <em>BasicBlock</em>, nor
+<em>Instruction</em>. It is global value. It is constant, since its the only
+supposed global here. Method also compares:</li>
+<li>Constants that are of the same type.</li>
+<li>If right constant could be losslessly bit-casted to the left one, then we
+also compare them.</li>
+</ul>
+</div>
+<div class="section" id="how-to-implement-cmpvalues">
+<h4><a class="toc-backref" href="#id20">How to implement cmpValues?</a><a class="headerlink" href="#how-to-implement-cmpvalues" title="Permalink to this headline">¶</a></h4>
+<p><em>Association</em> is a case of equality for us. We just treat such values as equal.
+But, in general, we need to implement antisymmetric relation. As it was
+mentioned above, to understand what is <em>less</em>, we can use order in which we
+meet values. If both of values has the same order in function (met at the same
+time), then treat values as <em>associated</em>. Otherwise â it depends on who was
+first.</p>
+<p>Every time we run top-level compare method, we initialize two identical maps
+(one for the left side, another one for the right side):</p>
+<p><tt class="docutils literal"><span class="pre">map<Value,</span> <span class="pre">int></span> <span class="pre">sn_mapL,</span> <span class="pre">sn_mapR;</span></tt></p>
+<p>The key of the map is the <em>Value</em> itself, the <em>value</em> â is its order (call it
+<em>serial number</em>).</p>
+<p>To add value <em>V</em> we need to perform the next procedure:</p>
+<p><tt class="docutils literal"><span class="pre">sn_map.insert(std::make_pair(V,</span> <span class="pre">sn_map.size()));</span></tt></p>
+<p>For the first <em>Value</em>, map will return <em>0</em>, for second <em>Value</em> map will return
+<em>1</em>, and so on.</p>
+<p>Then we can check whether left and right values met at the same time with simple
+comparison:</p>
+<p><tt class="docutils literal"><span class="pre">cmpNumbers(sn_mapL[Left],</span> <span class="pre">sn_mapR[Right]);</span></tt></p>
+<p>Of course, we can combine insertion and comparison:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">std</span><span class="o">::</span><span class="n">pair</span><span class="o"><</span><span class="n">iterator</span><span class="p">,</span> <span class="kt">bool</span><span class="o">></span>
+ <span class="n">LeftRes</span> <span class="o">=</span> <span class="n">sn_mapL</span><span class="p">.</span><span class="n">insert</span><span class="p">(</span><span class="n">std</span><span class="o">::</span><span class="n">make_pair</span><span class="p">(</span><span class="n">Left</span><span class="p">,</span> <span class="n">sn_mapL</span><span class="p">.</span><span class="n">size</span><span class="p">())),</span> <span class="n">RightRes</span>
+ <span class="o">=</span> <span class="n">sn_mapR</span><span class="p">.</span><span class="n">insert</span><span class="p">(</span><span class="n">std</span><span class="o">::</span><span class="n">make_pair</span><span class="p">(</span><span class="n">Right</span><span class="p">,</span> <span class="n">sn_mapR</span><span class="p">.</span><span class="n">size</span><span class="p">()));</span>
+<span class="k">return</span> <span class="nf">cmpNumbers</span><span class="p">(</span><span class="n">LeftRes</span><span class="p">.</span><span class="n">first</span><span class="o">-></span><span class="n">second</span><span class="p">,</span> <span class="n">RightRes</span><span class="p">.</span><span class="n">first</span><span class="o">-></span><span class="n">second</span><span class="p">);</span>
+</pre></div>
+</div>
+<p>Let’s look, how whole method could be implemented.</p>
+<p>1. we have to start from the bad news. Consider function self and
+cross-referencing cases:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="c1">// self-reference unsigned fact0(unsigned n) { return n > 1 ? n</span>
+<span class="o">*</span> <span class="n">fact0</span><span class="p">(</span><span class="n">n</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span> <span class="o">:</span> <span class="mi">1</span><span class="p">;</span> <span class="p">}</span> <span class="kt">unsigned</span> <span class="n">fact1</span><span class="p">(</span><span class="kt">unsigned</span> <span class="n">n</span><span class="p">)</span> <span class="p">{</span> <span class="k">return</span> <span class="n">n</span> <span class="o">></span> <span class="mi">1</span> <span class="o">?</span> <span class="n">n</span> <span class="o">*</span>
+<span class="n">fact1</span><span class="p">(</span><span class="n">n</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span> <span class="o">:</span> <span class="mi">1</span><span class="p">;</span> <span class="p">}</span>
+
+<span class="c1">// cross-reference unsigned ping(unsigned n) { return n!= 0 ? pong(n-1) : 0;</span>
+<span class="p">}</span> <span class="kt">unsigned</span> <span class="n">pong</span><span class="p">(</span><span class="kt">unsigned</span> <span class="n">n</span><span class="p">)</span> <span class="p">{</span> <span class="k">return</span> <span class="n">n</span><span class="o">!=</span> <span class="mi">0</span> <span class="o">?</span> <span class="n">ping</span><span class="p">(</span><span class="n">n</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span> <span class="o">:</span> <span class="mi">0</span><span class="p">;</span> <span class="p">}</span>
+</pre></div>
+</div>
+<blockquote>
+<div>This comparison has been implemented in initial <em>MergeFunctions</em> pass
+version. But, unfortunately, it is not transitive. And this is the only case
+we can’t convert to less-equal-greater comparison. It is a seldom case, 4-5
+functions of 10000 (checked on test-suite), and, we hope, reader would
+forgive us for such a sacrifice in order to get the O(log(N)) pass time.</div></blockquote>
+<p>2. If left/right <em>Value</em> is a constant, we have to compare them. Return 0 if it
+is the same constant, or use <tt class="docutils literal"><span class="pre">cmpConstants</span></tt> method otherwise.</p>
+<p>3. If left/right is <em>InlineAsm</em> instance. Return result of <em>Value</em> pointers
+comparison.</p>
+<p>4. Explicit association of <em>L</em> (left value) and <em>R</em> (right value). We need to
+find out whether values met at the same time, and thus are <em>associated</em>. Or we
+need to put the rule: when we treat <em>L</em> < <em>R</em>. Now it is easy: just return
+result of numbers comparison:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">std</span><span class="o">::</span><span class="n">pair</span><span class="o"><</span><span class="n">iterator</span><span class="p">,</span> <span class="kt">bool</span><span class="o">></span>
+ <span class="n">LeftRes</span> <span class="o">=</span> <span class="n">sn_mapL</span><span class="p">.</span><span class="n">insert</span><span class="p">(</span><span class="n">std</span><span class="o">::</span><span class="n">make_pair</span><span class="p">(</span><span class="n">Left</span><span class="p">,</span> <span class="n">sn_mapL</span><span class="p">.</span><span class="n">size</span><span class="p">())),</span>
+ <span class="n">RightRes</span> <span class="o">=</span> <span class="n">sn_mapR</span><span class="p">.</span><span class="n">insert</span><span class="p">(</span><span class="n">std</span><span class="o">::</span><span class="n">make_pair</span><span class="p">(</span><span class="n">Right</span><span class="p">,</span> <span class="n">sn_mapR</span><span class="p">.</span><span class="n">size</span><span class="p">()));</span>
+<span class="k">if</span> <span class="p">(</span><span class="n">LeftRes</span><span class="p">.</span><span class="n">first</span><span class="o">-></span><span class="n">second</span> <span class="o">==</span> <span class="n">RightRes</span><span class="p">.</span><span class="n">first</span><span class="o">-></span><span class="n">second</span><span class="p">)</span> <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
+<span class="k">if</span> <span class="p">(</span><span class="n">LeftRes</span><span class="p">.</span><span class="n">first</span><span class="o">-></span><span class="n">second</span> <span class="o"><</span> <span class="n">RightRes</span><span class="p">.</span><span class="n">first</span><span class="o">-></span><span class="n">second</span><span class="p">)</span> <span class="k">return</span> <span class="o">-</span><span class="mi">1</span><span class="p">;</span>
+<span class="k">return</span> <span class="mi">1</span><span class="p">;</span>
+</pre></div>
+</div>
+<p>Now when <em>cmpValues</em> returns 0, we can proceed comparison procedure. Otherwise,
+if we get (-1 or 1), we need to pass this result to the top level, and finish
+comparison procedure.</p>
+</div>
+</div>
+<div class="section" id="cmpconstants">
+<h3><a class="toc-backref" href="#id21">cmpConstants</a><a class="headerlink" href="#cmpconstants" title="Permalink to this headline">¶</a></h3>
+<p>Performs constants comparison as follows:</p>
+<p>1. Compare constant types using <tt class="docutils literal"><span class="pre">cmpType</span></tt> method. If result is -1 or 1, goto
+step 2, otherwise proceed to step 3.</p>
+<p>2. If types are different, we still can check whether constants could be
+losslessly bitcasted to each other. The further explanation is modification of
+<tt class="docutils literal"><span class="pre">canLosslesslyBitCastTo</span></tt> method.</p>
+<blockquote>
+<div><p>2.1 Check whether constants are of the first class types
+(<tt class="docutils literal"><span class="pre">isFirstClassType</span></tt> check):</p>
+<p>2.1.1. If both constants are <em>not</em> of the first class type: return result
+of <tt class="docutils literal"><span class="pre">cmpType</span></tt>.</p>
+<p>2.1.2. Otherwise, if left type is not of the first class, return -1. If
+right type is not of the first class, return 1.</p>
+<p>2.1.3. If both types are of the first class type, proceed to the next step
+(2.1.3.1).</p>
+<p>2.1.3.1. If types are vectors, compare their bitwidth using the
+<em>cmpNumbers</em>. If result is not 0, return it.</p>
+<p>2.1.3.2. Different types, but not a vectors:</p>
+<ul class="simple">
+<li>if both of them are pointers, good for us, we can proceed to step 3.</li>
+<li>if one of types is pointer, return result of <em>isPointer</em> flags
+comparison (<em>cmpFlags</em> operation).</li>
+<li>otherwise we have no methods to prove bitcastability, and thus return
+result of types comparison (-1 or 1).</li>
+</ul>
+</div></blockquote>
+<p>Steps below are for the case when types are equal, or case when constants are
+bitcastable:</p>
+<p>3. One of constants is a “<em>null</em>” value. Return the result of
+<tt class="docutils literal"><span class="pre">cmpFlags(L->isNullValue,</span> <span class="pre">R->isNullValue)</span></tt> comparison.</p>
+<ol class="arabic simple" start="4">
+<li>Compare value IDs, and return result if it is not 0:</li>
+</ol>
+<div class="highlight-c++"><div class="highlight"><pre><span class="k">if</span> <span class="p">(</span><span class="kt">int</span> <span class="n">Res</span> <span class="o">=</span> <span class="n">cmpNumbers</span><span class="p">(</span><span class="n">L</span><span class="o">-></span><span class="n">getValueID</span><span class="p">(),</span> <span class="n">R</span><span class="o">-></span><span class="n">getValueID</span><span class="p">()))</span>
+ <span class="k">return</span> <span class="n">Res</span><span class="p">;</span>
+</pre></div>
+</div>
+<p>5. Compare the contents of constants. The comparison depends on kind of
+constants, but on this stage it is just a lexicographical comparison. Just see
+how it was described in the beginning of “<em>Functions comparison</em>” paragraph.
+Mathematically it is equal to the next case: we encode left constant and right
+constant (with similar way <em>bitcode-writer</em> does). Then compare left code
+sequence and right code sequence.</p>
+</div>
+<div class="section" id="compare-const-basicblock-const-basicblock">
+<h3><a class="toc-backref" href="#id22">compare(const BasicBlock*, const BasicBlock*)</a><a class="headerlink" href="#compare-const-basicblock-const-basicblock" title="Permalink to this headline">¶</a></h3>
+<p>Compares two <em>BasicBlock</em> instances.</p>
+<p>It enumerates instructions from left <em>BB</em> and right <em>BB</em>.</p>
+<p>1. It assigns serial numbers to the left and right instructions, using
+<tt class="docutils literal"><span class="pre">cmpValues</span></tt> method.</p>
+<p>2. If one of left or right is <em>GEP</em> (<tt class="docutils literal"><span class="pre">GetElementPtr</span></tt>), then treat <em>GEP</em> as
+greater than other instructions, if both instructions are <em>GEPs</em> use <tt class="docutils literal"><span class="pre">cmpGEP</span></tt>
+method for comparison. If result is -1 or 1, pass it to the top-level
+comparison (return it).</p>
+<blockquote>
+<div><p>3.1. Compare operations. Call <tt class="docutils literal"><span class="pre">cmpOperation</span></tt> method. If result is -1 or
+1, return it.</p>
+<p>3.2. Compare number of operands, if result is -1 or 1, return it.</p>
+<p>3.3. Compare operands themselves, use <tt class="docutils literal"><span class="pre">cmpValues</span></tt> method. Return result
+if it is -1 or 1.</p>
+<p>3.4. Compare type of operands, using <tt class="docutils literal"><span class="pre">cmpType</span></tt> method. Return result if
+it is -1 or 1.</p>
+<p>3.5. Proceed to the next instruction.</p>
+</div></blockquote>
+<ol class="arabic" start="4">
+<li><p class="first">We can finish instruction enumeration in 3 cases:</p>
+<p>4.1. We reached the end of both left and right basic-blocks. We didn’t
+exit on steps 1-3, so contents is equal, return 0.</p>
+<p>4.2. We have reached the end of the left basic-block. Return -1.</p>
+<p>4.3. Return 1 (the end of the right basic block).</p>
+</li>
+</ol>
+</div>
+<div class="section" id="cmpgep">
+<h3><a class="toc-backref" href="#id23">cmpGEP</a><a class="headerlink" href="#cmpgep" title="Permalink to this headline">¶</a></h3>
+<p>Compares two GEPs (<tt class="docutils literal"><span class="pre">getelementptr</span></tt> instructions).</p>
+<p>It differs from regular operations comparison with the only thing: possibility
+to use <tt class="docutils literal"><span class="pre">accumulateConstantOffset</span></tt> method.</p>
+<p>So, if we get constant offset for both left and right <em>GEPs</em>, then compare it as
+numbers, and return comparison result.</p>
+<p>Otherwise treat it like a regular operation (see previous paragraph).</p>
+</div>
+<div class="section" id="cmpoperation">
+<h3><a class="toc-backref" href="#id24">cmpOperation</a><a class="headerlink" href="#cmpoperation" title="Permalink to this headline">¶</a></h3>
+<p>Compares instruction opcodes and some important operation properties.</p>
+<ol class="arabic simple">
+<li>Compare opcodes, if it differs return the result.</li>
+<li>Compare number of operands. If it differs â return the result.</li>
+</ol>
+<p>3. Compare operation types, use <em>cmpType</em>. All the same â if types are
+different, return result.</p>
+<p>4. Compare <em>subclassOptionalData</em>, get it with <tt class="docutils literal"><span class="pre">getRawSubclassOptionalData</span></tt>
+method, and compare it like a numbers.</p>
+<ol class="arabic simple" start="5">
+<li>Compare operand types.</li>
+</ol>
+<p>6. For some particular instructions check equivalence (relation in our case) of
+some significant attributes. For example we have to compare alignment for
+<tt class="docutils literal"><span class="pre">load</span></tt> instructions.</p>
+</div>
+<div class="section" id="o-log-n">
+<h3><a class="toc-backref" href="#id25">O(log(N))</a><a class="headerlink" href="#o-log-n" title="Permalink to this headline">¶</a></h3>
+<p>Methods described above implement order relationship. And latter, could be used
+for nodes comparison in a binary tree. So we can organize functions set into
+the binary tree and reduce the cost of lookup procedure from
+O(N*N) to O(log(N)).</p>
+</div>
+</div>
+<div class="section" id="merging-process-mergetwofunctions">
+<h2><a class="toc-backref" href="#id26">Merging process, mergeTwoFunctions</a><a class="headerlink" href="#merging-process-mergetwofunctions" title="Permalink to this headline">¶</a></h2>
+<p>Once <em>MergeFunctions</em> detected that current function (<em>G</em>) is equal to one that
+were analyzed before (function <em>F</em>) it calls <tt class="docutils literal"><span class="pre">mergeTwoFunctions(Function*,</span>
+<span class="pre">Function*)</span></tt>.</p>
+<p>Operation affects <tt class="docutils literal"><span class="pre">FnTree</span></tt> contents with next way: <em>F</em> will stay in
+<tt class="docutils literal"><span class="pre">FnTree</span></tt>. <em>G</em> being equal to <em>F</em> will not be added to <tt class="docutils literal"><span class="pre">FnTree</span></tt>. Calls of
+<em>G</em> would be replaced with something else. It changes bodies of callers. So,
+functions that calls <em>G</em> would be put into <tt class="docutils literal"><span class="pre">Deferred</span></tt> set and removed from
+<tt class="docutils literal"><span class="pre">FnTree</span></tt>, and analyzed again.</p>
+<p>The approach is next:</p>
+<p>1. Most wished case: when we can use alias and both of <em>F</em> and <em>G</em> are weak. We
+make both of them with aliases to the third strong function <em>H</em>. Actually <em>H</em>
+is <em>F</em>. See below how it’s made (but it’s better to look straight into the
+source code). Well, this is a case when we can just replace <em>G</em> with <em>F</em>
+everywhere, we use <tt class="docutils literal"><span class="pre">replaceAllUsesWith</span></tt> operation here (<em>RAUW</em>).</p>
+<p>2. <em>F</em> could not be overridden, while <em>G</em> could. It would be good to do the
+next: after merging the places where overridable function were used, still use
+overridable stub. So try to make <em>G</em> alias to <em>F</em>, or create overridable tail
+call wrapper around <em>F</em> and replace <em>G</em> with that call.</p>
+<p>3. Neither <em>F</em> nor <em>G</em> could be overridden. We can’t use <em>RAUW</em>. We can just
+change the callers: call <em>F</em> instead of <em>G</em>. That’s what
+<tt class="docutils literal"><span class="pre">replaceDirectCallers</span></tt> does.</p>
+<p>Below is detailed body description.</p>
+<div class="section" id="if-f-may-be-overridden">
+<h3><a class="toc-backref" href="#id27">If âFâ may be overridden</a><a class="headerlink" href="#if-f-may-be-overridden" title="Permalink to this headline">¶</a></h3>
+<p>As follows from <tt class="docutils literal"><span class="pre">mayBeOverridden</span></tt> comments: âwhether the definition of this
+global may be replaced by something non-equivalent at link timeâ. If so, thats
+ok: we can use alias to <em>F</em> instead of <em>G</em> or change call instructions itself.</p>
+<div class="section" id="hasglobalaliases-removeusers">
+<h4><a class="toc-backref" href="#id28">HasGlobalAliases, removeUsers</a><a class="headerlink" href="#hasglobalaliases-removeusers" title="Permalink to this headline">¶</a></h4>
+<p>First consider the case when we have global aliases of one function name to
+another. Our purpose is make both of them with aliases to the third strong
+function. Though if we keep <em>F</em> alive and without major changes we can leave it
+in <tt class="docutils literal"><span class="pre">FnTree</span></tt>. Try to combine these two goals.</p>
+<p>Do stub replacement of <em>F</em> itself with an alias to <em>F</em>.</p>
+<p>1. Create stub function <em>H</em>, with the same name and attributes like function
+<em>F</em>. It takes maximum alignment of <em>F</em> and <em>G</em>.</p>
+<p>2. Replace all uses of function <em>F</em> with uses of function <em>H</em>. It is the two
+steps procedure instead. First of all, we must take into account, all functions
+from whom <em>F</em> is called would be changed: since we change the call argument
+(from <em>F</em> to <em>H</em>). If so we must to review these caller functions again after
+this procedure. We remove callers from <tt class="docutils literal"><span class="pre">FnTree</span></tt>, method with name
+<tt class="docutils literal"><span class="pre">removeUsers(F)</span></tt> does that (don’t confuse with <tt class="docutils literal"><span class="pre">replaceAllUsesWith</span></tt>):</p>
+<blockquote>
+<div><p>2.1. <tt class="docutils literal"><span class="pre">Inside</span> <span class="pre">removeUsers(Value*</span>
+<span class="pre">V)</span></tt> we go through the all values that use value <em>V</em> (or <em>F</em> in our context).
+If value is instruction, we go to function that holds this instruction and
+mark it as to-be-analyzed-again (put to <tt class="docutils literal"><span class="pre">Deferred</span></tt> set), we also remove
+caller from <tt class="docutils literal"><span class="pre">FnTree</span></tt>.</p>
+<p>2.2. Now we can do the replacement: call <tt class="docutils literal"><span class="pre">F->replaceAllUsesWith(H)</span></tt>.</p>
+</div></blockquote>
+<p>3. <em>H</em> (that now “officially” plays <em>F</em>‘s role) is replaced with alias to <em>F</em>.
+Do the same with <em>G</em>: replace it with alias to <em>F</em>. So finally everywhere <em>F</em>
+was used, we use <em>H</em> and it is alias to <em>F</em>, and everywhere <em>G</em> was used we
+also have alias to <em>F</em>.</p>
+<ol class="arabic simple" start="4">
+<li>Set <em>F</em> linkage to private. Make it strong :-)</li>
+</ol>
+</div>
+<div class="section" id="no-global-aliases-replacedirectcallers">
+<h4><a class="toc-backref" href="#id29">No global aliases, replaceDirectCallers</a><a class="headerlink" href="#no-global-aliases-replacedirectcallers" title="Permalink to this headline">¶</a></h4>
+<p>If global aliases are not supported. We call <tt class="docutils literal"><span class="pre">replaceDirectCallers</span></tt> then. Just
+go through all calls of <em>G</em> and replace it with calls of <em>F</em>. If you look into
+method you will see that it scans all uses of <em>G</em> too, and if use is callee (if
+user is call instruction and <em>G</em> is used as what to be called), we replace it
+with use of <em>F</em>.</p>
+<div class="section" id="if-f-could-not-be-overridden-fix-it">
+<h5><a class="toc-backref" href="#id30">If âFâ could not be overridden, fix it!</a><a class="headerlink" href="#if-f-could-not-be-overridden-fix-it" title="Permalink to this headline">¶</a></h5>
+<p>We call <tt class="docutils literal"><span class="pre">writeThunkOrAlias(Function</span> <span class="pre">*F,</span> <span class="pre">Function</span> <span class="pre">*G)</span></tt>. Here we try to replace
+<em>G</em> with alias to <em>F</em> first. Next conditions are essential:</p>
+<ul class="simple">
+<li>target should support global aliases,</li>
+<li>the address itself of <em>G</em> should be not significant, not named and not
+referenced anywhere,</li>
+<li>function should come with external, local or weak linkage.</li>
+</ul>
+<p>Otherwise we write thunk: some wrapper that has <em>G’s</em> interface and calls <em>F</em>,
+so <em>G</em> could be replaced with this wrapper.</p>
+<p><em>writeAlias</em></p>
+<p>As follows from <em>llvm</em> reference:</p>
+<p>âAliases act as <em>second name</em> for the aliasee valueâ. So we just want to create
+second name for <em>F</em> and use it instead of <em>G</em>:</p>
+<ol class="arabic">
+<li><p class="first">create global alias itself (<em>GA</em>),</p>
+</li>
+<li><p class="first">adjust alignment of <em>F</em> so it must be maximum of current and <em>G’s</em> alignment;</p>
+</li>
+<li><p class="first">replace uses of <em>G</em>:</p>
+<p>3.1. first mark all callers of <em>G</em> as to-be-analyzed-again, using
+<tt class="docutils literal"><span class="pre">removeUsers</span></tt> method (see chapter above),</p>
+<p>3.2. call <tt class="docutils literal"><span class="pre">G->replaceAllUsesWith(GA)</span></tt>.</p>
+</li>
+<li><p class="first">Get rid of <em>G</em>.</p>
+</li>
+</ol>
+<p><em>writeThunk</em></p>
+<p>As it written in method comments:</p>
+<p>âReplace G with a simple tail call to bitcast(F). Also replace direct uses of G
+with bitcast(F). Deletes G.â</p>
+<p>In general it does the same as usual when we want to replace callee, except the
+first point:</p>
+<p>1. We generate tail call wrapper around <em>F</em>, but with interface that allows use
+it instead of <em>G</em>.</p>
+<ol class="arabic simple" start="2">
+<li>âAs-usualâ: <tt class="docutils literal"><span class="pre">removeUsers</span></tt> and <tt class="docutils literal"><span class="pre">replaceAllUsesWith</span></tt> then.</li>
+<li>Get rid of <em>G</em>.</li>
+</ol>
+</div>
+</div>
+</div>
+</div>
+<div class="section" id="that-s-it">
+<h2><a class="toc-backref" href="#id31">That’s it.</a><a class="headerlink" href="#that-s-it" title="Permalink to this headline">¶</a></h2>
+<p>We have described how to detect equal functions, and how to merge them, and in
+first chapter we have described how it works all-together. Author hopes, reader
+have some picture from now, and it helps him improve and debug Âthis pass.</p>
+<p>Reader is welcomed to send us any questions and proposals ;-)</p>
+</div>
+</div>
+
+
+ </div>
+ </div>
+ <div class="clearer"></div>
+ </div>
+ <div class="related">
+ <h3>Navigation</h3>
+ <ul>
+ <li class="right" style="margin-right: 10px">
+ <a href="genindex.html" title="General Index"
+ >index</a></li>
+ <li class="right" >
+ <a href="BitSets.html" title="Bitsets"
+ >next</a> |</li>
+ <li class="right" >
+ <a href="Statepoints.html" title="Garbage Collection Safepoints in LLVM"
+ >previous</a> |</li>
+ <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+ <li><a href="index.html">Documentation</a>»</li>
+
+ </ul>
+ </div>
+ <div class="footer">
+ © Copyright 2003-2016, LLVM Project.
+ Last updated on 2016-01-04.
+ Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.3.
+ </div>
+ </body>
+</html>
\ No newline at end of file
Added: www-releases/trunk/3.7.1/docs/NVPTXUsage.html
URL: http://llvm.org/viewvc/llvm-project/www-releases/trunk/3.7.1/docs/NVPTXUsage.html?rev=257950&view=auto
==============================================================================
--- www-releases/trunk/3.7.1/docs/NVPTXUsage.html (added)
+++ www-releases/trunk/3.7.1/docs/NVPTXUsage.html Fri Jan 15 17:13:16 2016
@@ -0,0 +1,1064 @@
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
+ <title>User Guide for NVPTX Back-end — LLVM 3.7 documentation</title>
+
+ <link rel="stylesheet" href="_static/llvm-theme.css" type="text/css" />
+ <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
+
+ <script type="text/javascript">
+ var DOCUMENTATION_OPTIONS = {
+ URL_ROOT: './',
+ VERSION: '3.7',
+ COLLAPSE_INDEX: false,
+ FILE_SUFFIX: '.html',
+ HAS_SOURCE: true
+ };
+ </script>
+ <script type="text/javascript" src="_static/jquery.js"></script>
+ <script type="text/javascript" src="_static/underscore.js"></script>
+ <script type="text/javascript" src="_static/doctools.js"></script>
+ <link rel="top" title="LLVM 3.7 documentation" href="index.html" />
+ <link rel="next" title="User Guide for AMDGPU Back-end" href="AMDGPUUsage.html" />
+ <link rel="prev" title="How To Use Attributes" href="HowToUseAttributes.html" />
+<style type="text/css">
+ table.right { float: right; margin-left: 20px; }
+ table.right td { border: 1px solid #ccc; }
+</style>
+
+ </head>
+ <body>
+<div class="logo">
+ <a href="index.html">
+ <img src="_static/logo.png"
+ alt="LLVM Logo" width="250" height="88"/></a>
+</div>
+
+ <div class="related">
+ <h3>Navigation</h3>
+ <ul>
+ <li class="right" style="margin-right: 10px">
+ <a href="genindex.html" title="General Index"
+ accesskey="I">index</a></li>
+ <li class="right" >
+ <a href="AMDGPUUsage.html" title="User Guide for AMDGPU Back-end"
+ accesskey="N">next</a> |</li>
+ <li class="right" >
+ <a href="HowToUseAttributes.html" title="How To Use Attributes"
+ accesskey="P">previous</a> |</li>
+ <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+ <li><a href="index.html">Documentation</a>»</li>
+
+ </ul>
+ </div>
+
+
+ <div class="document">
+ <div class="documentwrapper">
+ <div class="body">
+
+ <div class="section" id="user-guide-for-nvptx-back-end">
+<h1>User Guide for NVPTX Back-end<a class="headerlink" href="#user-guide-for-nvptx-back-end" title="Permalink to this headline">¶</a></h1>
+<div class="contents local topic" id="contents">
+<ul class="simple">
+<li><a class="reference internal" href="#introduction" id="id11">Introduction</a></li>
+<li><a class="reference internal" href="#conventions" id="id12">Conventions</a><ul>
+<li><a class="reference internal" href="#marking-functions-as-kernels" id="id13">Marking Functions as Kernels</a></li>
+<li><a class="reference internal" href="#address-spaces" id="id14">Address Spaces</a></li>
+<li><a class="reference internal" href="#triples" id="id15">Triples</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#nvptx-intrinsics" id="id16">NVPTX Intrinsics</a><ul>
+<li><a class="reference internal" href="#address-space-conversion" id="id17">Address Space Conversion</a><ul>
+<li><a class="reference internal" href="#llvm-nvvm-ptr-to-gen-intrinsics" id="id18">‘<tt class="docutils literal"><span class="pre">llvm.nvvm.ptr.*.to.gen</span></tt>‘ Intrinsics</a></li>
+<li><a class="reference internal" href="#llvm-nvvm-ptr-gen-to-intrinsics" id="id19">‘<tt class="docutils literal"><span class="pre">llvm.nvvm.ptr.gen.to.*</span></tt>‘ Intrinsics</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#reading-ptx-special-registers" id="id20">Reading PTX Special Registers</a><ul>
+<li><a class="reference internal" href="#llvm-nvvm-read-ptx-sreg" id="id21">‘<tt class="docutils literal"><span class="pre">llvm.nvvm.read.ptx.sreg.*</span></tt>‘</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#barriers" id="id22">Barriers</a><ul>
+<li><a class="reference internal" href="#llvm-nvvm-barrier0" id="id23">‘<tt class="docutils literal"><span class="pre">llvm.nvvm.barrier0</span></tt>‘</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#other-intrinsics" id="id24">Other Intrinsics</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#linking-with-libdevice" id="id25">Linking with Libdevice</a><ul>
+<li><a class="reference internal" href="#reflection-parameters" id="id26">Reflection Parameters</a></li>
+<li><a class="reference internal" href="#invoking-nvvmreflect" id="id27">Invoking NVVMReflect</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#executing-ptx" id="id28">Executing PTX</a></li>
+<li><a class="reference internal" href="#common-issues" id="id29">Common Issues</a><ul>
+<li><a class="reference internal" href="#ptxas-complains-of-undefined-function-nvvm-reflect" id="id30">ptxas complains of undefined function: __nvvm_reflect</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#tutorial-a-simple-compute-kernel" id="id31">Tutorial: A Simple Compute Kernel</a><ul>
+<li><a class="reference internal" href="#the-kernel" id="id32">The Kernel</a></li>
+<li><a class="reference internal" href="#dissecting-the-kernel" id="id33">Dissecting the Kernel</a><ul>
+<li><a class="reference internal" href="#data-layout" id="id34">Data Layout</a></li>
+<li><a class="reference internal" href="#target-intrinsics" id="id35">Target Intrinsics</a></li>
+<li><a class="reference internal" href="#id10" id="id36">Address Spaces</a></li>
+<li><a class="reference internal" href="#kernel-metadata" id="id37">Kernel Metadata</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#running-the-kernel" id="id38">Running the Kernel</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#tutorial-linking-with-libdevice" id="id39">Tutorial: Linking with Libdevice</a></li>
+</ul>
+</div>
+<div class="section" id="introduction">
+<h2><a class="toc-backref" href="#id11">Introduction</a><a class="headerlink" href="#introduction" title="Permalink to this headline">¶</a></h2>
+<p>To support GPU programming, the NVPTX back-end supports a subset of LLVM IR
+along with a defined set of conventions used to represent GPU programming
+concepts. This document provides an overview of the general usage of the back-
+end, including a description of the conventions used and the set of accepted
+LLVM IR.</p>
+<div class="admonition note">
+<p class="first admonition-title">Note</p>
+<p class="last">This document assumes a basic familiarity with CUDA and the PTX
+assembly language. Information about the CUDA Driver API and the PTX assembly
+language can be found in the <a class="reference external" href="http://docs.nvidia.com/cuda/index.html">CUDA documentation</a>.</p>
+</div>
+</div>
+<div class="section" id="conventions">
+<h2><a class="toc-backref" href="#id12">Conventions</a><a class="headerlink" href="#conventions" title="Permalink to this headline">¶</a></h2>
+<div class="section" id="marking-functions-as-kernels">
+<h3><a class="toc-backref" href="#id13">Marking Functions as Kernels</a><a class="headerlink" href="#marking-functions-as-kernels" title="Permalink to this headline">¶</a></h3>
+<p>In PTX, there are two types of functions: <em>device functions</em>, which are only
+callable by device code, and <em>kernel functions</em>, which are callable by host
+code. By default, the back-end will emit device functions. Metadata is used to
+declare a function as a kernel function. This metadata is attached to the
+<tt class="docutils literal"><span class="pre">nvvm.annotations</span></tt> named metadata object, and has the following format:</p>
+<div class="highlight-llvm"><div class="highlight"><pre>!0 = metadata !{<function-ref>, metadata !"kernel", i32 1}
+</pre></div>
+</div>
+<p>The first parameter is a reference to the kernel function. The following
+example shows a kernel function calling a device function in LLVM IR. The
+function <tt class="docutils literal"><span class="pre">@my_kernel</span></tt> is callable from host code, but <tt class="docutils literal"><span class="pre">@my_fmad</span></tt> is not.</p>
+<div class="highlight-llvm"><div class="highlight"><pre><span class="k">define</span> <span class="kt">float</span> <span class="vg">@my_fmad</span><span class="p">(</span><span class="kt">float</span> <span class="nv">%x</span><span class="p">,</span> <span class="kt">float</span> <span class="nv">%y</span><span class="p">,</span> <span class="kt">float</span> <span class="nv">%z</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nv">%mul</span> <span class="p">=</span> <span class="k">fmul</span> <span class="kt">float</span> <span class="nv">%x</span><span class="p">,</span> <span class="nv">%y</span>
+ <span class="nv">%add</span> <span class="p">=</span> <span class="k">fadd</span> <span class="kt">float</span> <span class="nv">%mul</span><span class="p">,</span> <span class="nv">%z</span>
+ <span class="k">ret</span> <span class="kt">float</span> <span class="nv">%add</span>
+<span class="p">}</span>
+
+<span class="k">define</span> <span class="kt">void</span> <span class="vg">@my_kernel</span><span class="p">(</span><span class="kt">float</span><span class="p">*</span> <span class="nv">%ptr</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nv">%val</span> <span class="p">=</span> <span class="k">load</span> <span class="kt">float</span><span class="p">*</span> <span class="nv">%ptr</span>
+ <span class="nv">%ret</span> <span class="p">=</span> <span class="k">call</span> <span class="kt">float</span> <span class="vg">@my_fmad</span><span class="p">(</span><span class="kt">float</span> <span class="nv">%val</span><span class="p">,</span> <span class="kt">float</span> <span class="nv">%val</span><span class="p">,</span> <span class="kt">float</span> <span class="nv">%val</span><span class="p">)</span>
+ <span class="k">store</span> <span class="kt">float</span> <span class="nv">%ret</span><span class="p">,</span> <span class="kt">float</span><span class="p">*</span> <span class="nv">%ptr</span>
+ <span class="k">ret</span> <span class="kt">void</span>
+<span class="p">}</span>
+
+<span class="nv">!nvvm.annotations</span> <span class="p">=</span> <span class="p">!{</span><span class="nv-Anonymous">!1</span><span class="p">}</span>
+<span class="nv-Anonymous">!1</span> <span class="p">=</span> <span class="kt">metadata</span> <span class="p">!{</span><span class="kt">void</span> <span class="p">(</span><span class="kt">float</span><span class="p">*)*</span> <span class="vg">@my_kernel</span><span class="p">,</span> <span class="kt">metadata</span> <span class="nv">!"kernel"</span><span class="p">,</span> <span class="k">i32</span> <span class="m">1</span><span class="p">}</span>
+</pre></div>
+</div>
+<p>When compiled, the PTX kernel functions are callable by host-side code.</p>
+</div>
+<div class="section" id="address-spaces">
+<span id="id1"></span><h3><a class="toc-backref" href="#id14">Address Spaces</a><a class="headerlink" href="#address-spaces" title="Permalink to this headline">¶</a></h3>
+<p>The NVPTX back-end uses the following address space mapping:</p>
+<blockquote>
+<div><table border="1" class="docutils">
+<colgroup>
+<col width="37%" />
+<col width="63%" />
+</colgroup>
+<thead valign="bottom">
+<tr class="row-odd"><th class="head">Address Space</th>
+<th class="head">Memory Space</th>
+</tr>
+</thead>
+<tbody valign="top">
+<tr class="row-even"><td>0</td>
+<td>Generic</td>
+</tr>
+<tr class="row-odd"><td>1</td>
+<td>Global</td>
+</tr>
+<tr class="row-even"><td>2</td>
+<td>Internal Use</td>
+</tr>
+<tr class="row-odd"><td>3</td>
+<td>Shared</td>
+</tr>
+<tr class="row-even"><td>4</td>
+<td>Constant</td>
+</tr>
+<tr class="row-odd"><td>5</td>
+<td>Local</td>
+</tr>
+</tbody>
+</table>
+</div></blockquote>
+<p>Every global variable and pointer type is assigned to one of these address
+spaces, with 0 being the default address space. Intrinsics are provided which
+can be used to convert pointers between the generic and non-generic address
+spaces.</p>
+<p>As an example, the following IR will define an array <tt class="docutils literal"><span class="pre">@g</span></tt> that resides in
+global device memory.</p>
+<div class="highlight-llvm"><div class="highlight"><pre><span class="vg">@g</span> <span class="p">=</span> <span class="k">internal</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">1</span><span class="p">)</span> <span class="k">global</span> <span class="p">[</span><span class="m">4</span> <span class="k">x</span> <span class="k">i32</span><span class="p">]</span> <span class="p">[</span> <span class="k">i32</span> <span class="m">0</span><span class="p">,</span> <span class="k">i32</span> <span class="m">1</span><span class="p">,</span> <span class="k">i32</span> <span class="m">2</span><span class="p">,</span> <span class="k">i32</span> <span class="m">3</span> <span class="p">]</span>
+</pre></div>
+</div>
+<p>LLVM IR functions can read and write to this array, and host-side code can
+copy data to it by name with the CUDA Driver API.</p>
+<p>Note that since address space 0 is the generic space, it is illegal to have
+global variables in address space 0. Address space 0 is the default address
+space in LLVM, so the <tt class="docutils literal"><span class="pre">addrspace(N)</span></tt> annotation is <em>required</em> for global
+variables.</p>
+</div>
+<div class="section" id="triples">
+<h3><a class="toc-backref" href="#id15">Triples</a><a class="headerlink" href="#triples" title="Permalink to this headline">¶</a></h3>
+<p>The NVPTX target uses the module triple to select between 32/64-bit code
+generation and the driver-compiler interface to use. The triple architecture
+can be one of <tt class="docutils literal"><span class="pre">nvptx</span></tt> (32-bit PTX) or <tt class="docutils literal"><span class="pre">nvptx64</span></tt> (64-bit PTX). The
+operating system should be one of <tt class="docutils literal"><span class="pre">cuda</span></tt> or <tt class="docutils literal"><span class="pre">nvcl</span></tt>, which determines the
+interface used by the generated code to communicate with the driver. Most
+users will want to use <tt class="docutils literal"><span class="pre">cuda</span></tt> as the operating system, which makes the
+generated PTX compatible with the CUDA Driver API.</p>
+<p>Example: 32-bit PTX for CUDA Driver API: <tt class="docutils literal"><span class="pre">nvptx-nvidia-cuda</span></tt></p>
+<p>Example: 64-bit PTX for CUDA Driver API: <tt class="docutils literal"><span class="pre">nvptx64-nvidia-cuda</span></tt></p>
+</div>
+</div>
+<div class="section" id="nvptx-intrinsics">
+<span id="id2"></span><h2><a class="toc-backref" href="#id16">NVPTX Intrinsics</a><a class="headerlink" href="#nvptx-intrinsics" title="Permalink to this headline">¶</a></h2>
+<div class="section" id="address-space-conversion">
+<h3><a class="toc-backref" href="#id17">Address Space Conversion</a><a class="headerlink" href="#address-space-conversion" title="Permalink to this headline">¶</a></h3>
+<div class="section" id="llvm-nvvm-ptr-to-gen-intrinsics">
+<h4><a class="toc-backref" href="#id18">‘<tt class="docutils literal"><span class="pre">llvm.nvvm.ptr.*.to.gen</span></tt>‘ Intrinsics</a><a class="headerlink" href="#llvm-nvvm-ptr-to-gen-intrinsics" title="Permalink to this headline">¶</a></h4>
+<div class="section" id="syntax">
+<h5>Syntax:<a class="headerlink" href="#syntax" title="Permalink to this headline">¶</a></h5>
+<p>These are overloaded intrinsics. You can use these on any pointer types.</p>
+<div class="highlight-llvm"><div class="highlight"><pre><span class="k">declare</span> <span class="k">i8</span><span class="p">*</span> <span class="vg">@llvm.nvvm.ptr.global.to.gen.p0i8.p1i8</span><span class="p">(</span><span class="k">i8</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">1</span><span class="p">)*)</span>
+<span class="k">declare</span> <span class="k">i8</span><span class="p">*</span> <span class="vg">@llvm.nvvm.ptr.shared.to.gen.p0i8.p3i8</span><span class="p">(</span><span class="k">i8</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">3</span><span class="p">)*)</span>
+<span class="k">declare</span> <span class="k">i8</span><span class="p">*</span> <span class="vg">@llvm.nvvm.ptr.constant.to.gen.p0i8.p4i8</span><span class="p">(</span><span class="k">i8</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">4</span><span class="p">)*)</span>
+<span class="k">declare</span> <span class="k">i8</span><span class="p">*</span> <span class="vg">@llvm.nvvm.ptr.local.to.gen.p0i8.p5i8</span><span class="p">(</span><span class="k">i8</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">5</span><span class="p">)*)</span>
+</pre></div>
+</div>
+</div>
+<div class="section" id="overview">
+<h5>Overview:<a class="headerlink" href="#overview" title="Permalink to this headline">¶</a></h5>
+<p>The ‘<tt class="docutils literal"><span class="pre">llvm.nvvm.ptr.*.to.gen</span></tt>‘ intrinsics convert a pointer in a non-generic
+address space to a generic address space pointer.</p>
+</div>
+<div class="section" id="semantics">
+<h5>Semantics:<a class="headerlink" href="#semantics" title="Permalink to this headline">¶</a></h5>
+<p>These intrinsics modify the pointer value to be a valid generic address space
+pointer.</p>
+</div>
+</div>
+<div class="section" id="llvm-nvvm-ptr-gen-to-intrinsics">
+<h4><a class="toc-backref" href="#id19">‘<tt class="docutils literal"><span class="pre">llvm.nvvm.ptr.gen.to.*</span></tt>‘ Intrinsics</a><a class="headerlink" href="#llvm-nvvm-ptr-gen-to-intrinsics" title="Permalink to this headline">¶</a></h4>
+<div class="section" id="id3">
+<h5>Syntax:<a class="headerlink" href="#id3" title="Permalink to this headline">¶</a></h5>
+<p>These are overloaded intrinsics. You can use these on any pointer types.</p>
+<div class="highlight-llvm"><div class="highlight"><pre><span class="k">declare</span> <span class="k">i8</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">1</span><span class="p">)*</span> <span class="vg">@llvm.nvvm.ptr.gen.to.global.p1i8.p0i8</span><span class="p">(</span><span class="k">i8</span><span class="p">*)</span>
+<span class="k">declare</span> <span class="k">i8</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">3</span><span class="p">)*</span> <span class="vg">@llvm.nvvm.ptr.gen.to.shared.p3i8.p0i8</span><span class="p">(</span><span class="k">i8</span><span class="p">*)</span>
+<span class="k">declare</span> <span class="k">i8</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">4</span><span class="p">)*</span> <span class="vg">@llvm.nvvm.ptr.gen.to.constant.p4i8.p0i8</span><span class="p">(</span><span class="k">i8</span><span class="p">*)</span>
+<span class="k">declare</span> <span class="k">i8</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">5</span><span class="p">)*</span> <span class="vg">@llvm.nvvm.ptr.gen.to.local.p5i8.p0i8</span><span class="p">(</span><span class="k">i8</span><span class="p">*)</span>
+</pre></div>
+</div>
+</div>
+<div class="section" id="id4">
+<h5>Overview:<a class="headerlink" href="#id4" title="Permalink to this headline">¶</a></h5>
+<p>The ‘<tt class="docutils literal"><span class="pre">llvm.nvvm.ptr.gen.to.*</span></tt>‘ intrinsics convert a pointer in the generic
+address space to a pointer in the target address space. Note that these
+intrinsics are only useful if the address space of the target address space of
+the pointer is known. It is not legal to use address space conversion
+intrinsics to convert a pointer from one non-generic address space to another
+non-generic address space.</p>
+</div>
+<div class="section" id="id5">
+<h5>Semantics:<a class="headerlink" href="#id5" title="Permalink to this headline">¶</a></h5>
+<p>These intrinsics modify the pointer value to be a valid pointer in the target
+non-generic address space.</p>
+</div>
+</div>
+</div>
+<div class="section" id="reading-ptx-special-registers">
+<h3><a class="toc-backref" href="#id20">Reading PTX Special Registers</a><a class="headerlink" href="#reading-ptx-special-registers" title="Permalink to this headline">¶</a></h3>
+<div class="section" id="llvm-nvvm-read-ptx-sreg">
+<h4><a class="toc-backref" href="#id21">‘<tt class="docutils literal"><span class="pre">llvm.nvvm.read.ptx.sreg.*</span></tt>‘</a><a class="headerlink" href="#llvm-nvvm-read-ptx-sreg" title="Permalink to this headline">¶</a></h4>
+<div class="section" id="id6">
+<h5>Syntax:<a class="headerlink" href="#id6" title="Permalink to this headline">¶</a></h5>
+<div class="highlight-llvm"><div class="highlight"><pre><span class="k">declare</span> <span class="k">i32</span> <span class="vg">@llvm.nvvm.read.ptx.sreg.tid.x</span><span class="p">()</span>
+<span class="k">declare</span> <span class="k">i32</span> <span class="vg">@llvm.nvvm.read.ptx.sreg.tid.y</span><span class="p">()</span>
+<span class="k">declare</span> <span class="k">i32</span> <span class="vg">@llvm.nvvm.read.ptx.sreg.tid.z</span><span class="p">()</span>
+<span class="k">declare</span> <span class="k">i32</span> <span class="vg">@llvm.nvvm.read.ptx.sreg.ntid.x</span><span class="p">()</span>
+<span class="k">declare</span> <span class="k">i32</span> <span class="vg">@llvm.nvvm.read.ptx.sreg.ntid.y</span><span class="p">()</span>
+<span class="k">declare</span> <span class="k">i32</span> <span class="vg">@llvm.nvvm.read.ptx.sreg.ntid.z</span><span class="p">()</span>
+<span class="k">declare</span> <span class="k">i32</span> <span class="vg">@llvm.nvvm.read.ptx.sreg.ctaid.x</span><span class="p">()</span>
+<span class="k">declare</span> <span class="k">i32</span> <span class="vg">@llvm.nvvm.read.ptx.sreg.ctaid.y</span><span class="p">()</span>
+<span class="k">declare</span> <span class="k">i32</span> <span class="vg">@llvm.nvvm.read.ptx.sreg.ctaid.z</span><span class="p">()</span>
+<span class="k">declare</span> <span class="k">i32</span> <span class="vg">@llvm.nvvm.read.ptx.sreg.nctaid.x</span><span class="p">()</span>
+<span class="k">declare</span> <span class="k">i32</span> <span class="vg">@llvm.nvvm.read.ptx.sreg.nctaid.y</span><span class="p">()</span>
+<span class="k">declare</span> <span class="k">i32</span> <span class="vg">@llvm.nvvm.read.ptx.sreg.nctaid.z</span><span class="p">()</span>
+<span class="k">declare</span> <span class="k">i32</span> <span class="vg">@llvm.nvvm.read.ptx.sreg.warpsize</span><span class="p">()</span>
+</pre></div>
+</div>
+</div>
+<div class="section" id="id7">
+<h5>Overview:<a class="headerlink" href="#id7" title="Permalink to this headline">¶</a></h5>
+<p>The ‘<tt class="docutils literal"><span class="pre">@llvm.nvvm.read.ptx.sreg.*</span></tt>‘ intrinsics provide access to the PTX
+special registers, in particular the kernel launch bounds. These registers
+map in the following way to CUDA builtins:</p>
+<blockquote>
+<div><table border="1" class="docutils">
+<colgroup>
+<col width="24%" />
+<col width="76%" />
+</colgroup>
+<thead valign="bottom">
+<tr class="row-odd"><th class="head">CUDA Builtin</th>
+<th class="head">PTX Special Register Intrinsic</th>
+</tr>
+</thead>
+<tbody valign="top">
+<tr class="row-even"><td><tt class="docutils literal"><span class="pre">threadId</span></tt></td>
+<td><tt class="docutils literal"><span class="pre">@llvm.nvvm.read.ptx.sreg.tid.*</span></tt></td>
+</tr>
+<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">blockIdx</span></tt></td>
+<td><tt class="docutils literal"><span class="pre">@llvm.nvvm.read.ptx.sreg.ctaid.*</span></tt></td>
+</tr>
+<tr class="row-even"><td><tt class="docutils literal"><span class="pre">blockDim</span></tt></td>
+<td><tt class="docutils literal"><span class="pre">@llvm.nvvm.read.ptx.sreg.ntid.*</span></tt></td>
+</tr>
+<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">gridDim</span></tt></td>
+<td><tt class="docutils literal"><span class="pre">@llvm.nvvm.read.ptx.sreg.nctaid.*</span></tt></td>
+</tr>
+</tbody>
+</table>
+</div></blockquote>
+</div>
+</div>
+</div>
+<div class="section" id="barriers">
+<h3><a class="toc-backref" href="#id22">Barriers</a><a class="headerlink" href="#barriers" title="Permalink to this headline">¶</a></h3>
+<div class="section" id="llvm-nvvm-barrier0">
+<h4><a class="toc-backref" href="#id23">‘<tt class="docutils literal"><span class="pre">llvm.nvvm.barrier0</span></tt>‘</a><a class="headerlink" href="#llvm-nvvm-barrier0" title="Permalink to this headline">¶</a></h4>
+<div class="section" id="id8">
+<h5>Syntax:<a class="headerlink" href="#id8" title="Permalink to this headline">¶</a></h5>
+<div class="highlight-llvm"><div class="highlight"><pre><span class="k">declare</span> <span class="kt">void</span> <span class="vg">@llvm.nvvm.barrier0</span><span class="p">()</span>
+</pre></div>
+</div>
+</div>
+<div class="section" id="id9">
+<h5>Overview:<a class="headerlink" href="#id9" title="Permalink to this headline">¶</a></h5>
+<p>The ‘<tt class="docutils literal"><span class="pre">@llvm.nvvm.barrier0()</span></tt>‘ intrinsic emits a PTX <tt class="docutils literal"><span class="pre">bar.sync</span> <span class="pre">0</span></tt>
+instruction, equivalent to the <tt class="docutils literal"><span class="pre">__syncthreads()</span></tt> call in CUDA.</p>
+</div>
+</div>
+</div>
+<div class="section" id="other-intrinsics">
+<h3><a class="toc-backref" href="#id24">Other Intrinsics</a><a class="headerlink" href="#other-intrinsics" title="Permalink to this headline">¶</a></h3>
+<p>For the full set of NVPTX intrinsics, please see the
+<tt class="docutils literal"><span class="pre">include/llvm/IR/IntrinsicsNVVM.td</span></tt> file in the LLVM source tree.</p>
+</div>
+</div>
+<div class="section" id="linking-with-libdevice">
+<span id="libdevice"></span><h2><a class="toc-backref" href="#id25">Linking with Libdevice</a><a class="headerlink" href="#linking-with-libdevice" title="Permalink to this headline">¶</a></h2>
+<p>The CUDA Toolkit comes with an LLVM bitcode library called <tt class="docutils literal"><span class="pre">libdevice</span></tt> that
+implements many common mathematical functions. This library can be used as a
+high-performance math library for any compilers using the LLVM NVPTX target.
+The library can be found under <tt class="docutils literal"><span class="pre">nvvm/libdevice/</span></tt> in the CUDA Toolkit and
+there is a separate version for each compute architecture.</p>
+<p>For a list of all math functions implemented in libdevice, see
+<a class="reference external" href="http://docs.nvidia.com/cuda/libdevice-users-guide/index.html">libdevice Users Guide</a>.</p>
+<p>To accommodate various math-related compiler flags that can affect code
+generation of libdevice code, the library code depends on a special LLVM IR
+pass (<tt class="docutils literal"><span class="pre">NVVMReflect</span></tt>) to handle conditional compilation within LLVM IR. This
+pass looks for calls to the <tt class="docutils literal"><span class="pre">@__nvvm_reflect</span></tt> function and replaces them
+with constants based on the defined reflection parameters. Such conditional
+code often follows a pattern:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="kt">float</span> <span class="nf">my_function</span><span class="p">(</span><span class="kt">float</span> <span class="n">a</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">__nvvm_reflect</span><span class="p">(</span><span class="s">"FASTMATH"</span><span class="p">))</span>
+ <span class="k">return</span> <span class="n">my_function_fast</span><span class="p">(</span><span class="n">a</span><span class="p">);</span>
+ <span class="k">else</span>
+ <span class="k">return</span> <span class="n">my_function_precise</span><span class="p">(</span><span class="n">a</span><span class="p">);</span>
+<span class="p">}</span>
+</pre></div>
+</div>
+<p>The default value for all unspecified reflection parameters is zero.</p>
+<p>The <tt class="docutils literal"><span class="pre">NVVMReflect</span></tt> pass should be executed early in the optimization
+pipeline, immediately after the link stage. The <tt class="docutils literal"><span class="pre">internalize</span></tt> pass is also
+recommended to remove unused math functions from the resulting PTX. For an
+input IR module <tt class="docutils literal"><span class="pre">module.bc</span></tt>, the following compilation flow is recommended:</p>
+<ol class="arabic simple">
+<li>Save list of external functions in <tt class="docutils literal"><span class="pre">module.bc</span></tt></li>
+<li>Link <tt class="docutils literal"><span class="pre">module.bc</span></tt> with <tt class="docutils literal"><span class="pre">libdevice.compute_XX.YY.bc</span></tt></li>
+<li>Internalize all functions not in list from (1)</li>
+<li>Eliminate all unused internal functions</li>
+<li>Run <tt class="docutils literal"><span class="pre">NVVMReflect</span></tt> pass</li>
+<li>Run standard optimization pipeline</li>
+</ol>
+<div class="admonition note">
+<p class="first admonition-title">Note</p>
+<p class="last"><tt class="docutils literal"><span class="pre">linkonce</span></tt> and <tt class="docutils literal"><span class="pre">linkonce_odr</span></tt> linkage types are not suitable for the
+libdevice functions. It is possible to link two IR modules that have been
+linked against libdevice using different reflection variables.</p>
+</div>
+<p>Since the <tt class="docutils literal"><span class="pre">NVVMReflect</span></tt> pass replaces conditionals with constants, it will
+often leave behind dead code of the form:</p>
+<div class="highlight-llvm"><div class="highlight"><pre><span class="nl">entry:</span>
+ <span class="p">..</span>
+ <span class="k">br</span> <span class="k">i1</span> <span class="k">true</span><span class="p">,</span> <span class="kt">label</span> <span class="nv">%foo</span><span class="p">,</span> <span class="kt">label</span> <span class="nv">%bar</span>
+<span class="nl">foo:</span>
+ <span class="p">..</span>
+<span class="nl">bar:</span>
+ <span class="c">; Dead code</span>
+ <span class="p">..</span>
+</pre></div>
+</div>
+<p>Therefore, it is recommended that <tt class="docutils literal"><span class="pre">NVVMReflect</span></tt> is executed early in the
+optimization pipeline before dead-code elimination.</p>
+<div class="section" id="reflection-parameters">
+<h3><a class="toc-backref" href="#id26">Reflection Parameters</a><a class="headerlink" href="#reflection-parameters" title="Permalink to this headline">¶</a></h3>
+<p>The libdevice library currently uses the following reflection parameters to
+control code generation:</p>
+<table border="1" class="docutils">
+<colgroup>
+<col width="27%" />
+<col width="73%" />
+</colgroup>
+<thead valign="bottom">
+<tr class="row-odd"><th class="head">Flag</th>
+<th class="head">Description</th>
+</tr>
+</thead>
+<tbody valign="top">
+<tr class="row-even"><td><tt class="docutils literal"><span class="pre">__CUDA_FTZ=[0,1]</span></tt></td>
+<td>Use optimized code paths that flush subnormals to zero</td>
+</tr>
+</tbody>
+</table>
+</div>
+<div class="section" id="invoking-nvvmreflect">
+<h3><a class="toc-backref" href="#id27">Invoking NVVMReflect</a><a class="headerlink" href="#invoking-nvvmreflect" title="Permalink to this headline">¶</a></h3>
+<p>To ensure that all dead code caused by the reflection pass is eliminated, it
+is recommended that the reflection pass is executed early in the LLVM IR
+optimization pipeline. The pass takes an optional mapping of reflection
+parameter name to an integer value. This mapping can be specified as either a
+command-line option to <tt class="docutils literal"><span class="pre">opt</span></tt> or as an LLVM <tt class="docutils literal"><span class="pre">StringMap<int></span></tt> object when
+programmatically creating a pass pipeline.</p>
+<p>With <tt class="docutils literal"><span class="pre">opt</span></tt>:</p>
+<div class="highlight-text"><div class="highlight"><pre># opt -nvvm-reflect -nvvm-reflect-list=<var>=<value>,<var>=<value> module.bc -o module.reflect.bc
+</pre></div>
+</div>
+<p>With programmatic pass pipeline:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="k">extern</span> <span class="n">ModulePass</span> <span class="o">*</span><span class="n">llvm</span><span class="o">::</span><span class="n">createNVVMReflectPass</span><span class="p">(</span><span class="k">const</span> <span class="n">StringMap</span><span class="o"><</span><span class="kt">int</span><span class="o">>&</span> <span class="n">Mapping</span><span class="p">);</span>
+
+<span class="n">StringMap</span><span class="o"><</span><span class="kt">int</span><span class="o">></span> <span class="n">ReflectParams</span><span class="p">;</span>
+<span class="n">ReflectParams</span><span class="p">[</span><span class="s">"__CUDA_FTZ"</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
+<span class="n">Passes</span><span class="p">.</span><span class="n">add</span><span class="p">(</span><span class="n">createNVVMReflectPass</span><span class="p">(</span><span class="n">ReflectParams</span><span class="p">));</span>
+</pre></div>
+</div>
+</div>
+</div>
+<div class="section" id="executing-ptx">
+<h2><a class="toc-backref" href="#id28">Executing PTX</a><a class="headerlink" href="#executing-ptx" title="Permalink to this headline">¶</a></h2>
+<p>The most common way to execute PTX assembly on a GPU device is to use the CUDA
+Driver API. This API is a low-level interface to the GPU driver and allows for
+JIT compilation of PTX code to native GPU machine code.</p>
+<p>Initializing the Driver API:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">CUdevice</span> <span class="n">device</span><span class="p">;</span>
+<span class="n">CUcontext</span> <span class="n">context</span><span class="p">;</span>
+
+<span class="c1">// Initialize the driver API</span>
+<span class="n">cuInit</span><span class="p">(</span><span class="mi">0</span><span class="p">);</span>
+<span class="c1">// Get a handle to the first compute device</span>
+<span class="n">cuDeviceGet</span><span class="p">(</span><span class="o">&</span><span class="n">device</span><span class="p">,</span> <span class="mi">0</span><span class="p">);</span>
+<span class="c1">// Create a compute device context</span>
+<span class="n">cuCtxCreate</span><span class="p">(</span><span class="o">&</span><span class="n">context</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">device</span><span class="p">);</span>
+</pre></div>
+</div>
+<p>JIT compiling a PTX string to a device binary:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">CUmodule</span> <span class="n">module</span><span class="p">;</span>
+<span class="n">CUfunction</span> <span class="n">funcion</span><span class="p">;</span>
+
+<span class="c1">// JIT compile a null-terminated PTX string</span>
+<span class="n">cuModuleLoadData</span><span class="p">(</span><span class="o">&</span><span class="n">module</span><span class="p">,</span> <span class="p">(</span><span class="kt">void</span><span class="o">*</span><span class="p">)</span><span class="n">PTXString</span><span class="p">);</span>
+
+<span class="c1">// Get a handle to the "myfunction" kernel function</span>
+<span class="n">cuModuleGetFunction</span><span class="p">(</span><span class="o">&</span><span class="n">function</span><span class="p">,</span> <span class="n">module</span><span class="p">,</span> <span class="s">"myfunction"</span><span class="p">);</span>
+</pre></div>
+</div>
+<p>For full examples of executing PTX assembly, please see the <a class="reference external" href="https://developer.nvidia.com/cuda-downloads">CUDA Samples</a> distribution.</p>
+</div>
+<div class="section" id="common-issues">
+<h2><a class="toc-backref" href="#id29">Common Issues</a><a class="headerlink" href="#common-issues" title="Permalink to this headline">¶</a></h2>
+<div class="section" id="ptxas-complains-of-undefined-function-nvvm-reflect">
+<h3><a class="toc-backref" href="#id30">ptxas complains of undefined function: __nvvm_reflect</a><a class="headerlink" href="#ptxas-complains-of-undefined-function-nvvm-reflect" title="Permalink to this headline">¶</a></h3>
+<p>When linking with libdevice, the <tt class="docutils literal"><span class="pre">NVVMReflect</span></tt> pass must be used. See
+<a class="reference internal" href="#libdevice"><em>Linking with Libdevice</em></a> for more information.</p>
+</div>
+</div>
+<div class="section" id="tutorial-a-simple-compute-kernel">
+<h2><a class="toc-backref" href="#id31">Tutorial: A Simple Compute Kernel</a><a class="headerlink" href="#tutorial-a-simple-compute-kernel" title="Permalink to this headline">¶</a></h2>
+<p>To start, let us take a look at a simple compute kernel written directly in
+LLVM IR. The kernel implements vector addition, where each thread computes one
+element of the output vector C from the input vectors A and B. To make this
+easier, we also assume that only a single CTA (thread block) will be launched,
+and that it will be one dimensional.</p>
+<div class="section" id="the-kernel">
+<h3><a class="toc-backref" href="#id32">The Kernel</a><a class="headerlink" href="#the-kernel" title="Permalink to this headline">¶</a></h3>
+<div class="highlight-llvm"><div class="highlight"><pre><span class="k">target</span> <span class="k">datalayout</span> <span class="p">=</span> <span class="s">"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v32:32:32-v64:64:64-v128:128:128-n16:32:64"</span>
+<span class="k">target</span> <span class="k">triple</span> <span class="p">=</span> <span class="s">"nvptx64-nvidia-cuda"</span>
+
+<span class="c">; Intrinsic to read X component of thread ID</span>
+<span class="k">declare</span> <span class="k">i32</span> <span class="vg">@llvm.nvvm.read.ptx.sreg.tid.x</span><span class="p">()</span> <span class="k">readnone</span> <span class="k">nounwind</span>
+
+<span class="k">define</span> <span class="kt">void</span> <span class="vg">@kernel</span><span class="p">(</span><span class="kt">float</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">1</span><span class="p">)*</span> <span class="nv">%A</span><span class="p">,</span>
+ <span class="kt">float</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">1</span><span class="p">)*</span> <span class="nv">%B</span><span class="p">,</span>
+ <span class="kt">float</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">1</span><span class="p">)*</span> <span class="nv">%C</span><span class="p">)</span> <span class="p">{</span>
+<span class="nl">entry:</span>
+ <span class="c">; What is my ID?</span>
+ <span class="nv">%id</span> <span class="p">=</span> <span class="k">tail</span> <span class="k">call</span> <span class="k">i32</span> <span class="vg">@llvm.nvvm.read.ptx.sreg.tid.x</span><span class="p">()</span> <span class="k">readnone</span> <span class="k">nounwind</span>
+
+ <span class="c">; Compute pointers into A, B, and C</span>
+ <span class="nv">%ptrA</span> <span class="p">=</span> <span class="k">getelementptr</span> <span class="kt">float</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">1</span><span class="p">)*</span> <span class="nv">%A</span><span class="p">,</span> <span class="k">i32</span> <span class="nv">%id</span>
+ <span class="nv">%ptrB</span> <span class="p">=</span> <span class="k">getelementptr</span> <span class="kt">float</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">1</span><span class="p">)*</span> <span class="nv">%B</span><span class="p">,</span> <span class="k">i32</span> <span class="nv">%id</span>
+ <span class="nv">%ptrC</span> <span class="p">=</span> <span class="k">getelementptr</span> <span class="kt">float</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">1</span><span class="p">)*</span> <span class="nv">%C</span><span class="p">,</span> <span class="k">i32</span> <span class="nv">%id</span>
+
+ <span class="c">; Read A, B</span>
+ <span class="nv">%valA</span> <span class="p">=</span> <span class="k">load</span> <span class="kt">float</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">1</span><span class="p">)*</span> <span class="nv">%ptrA</span><span class="p">,</span> <span class="k">align</span> <span class="m">4</span>
+ <span class="nv">%valB</span> <span class="p">=</span> <span class="k">load</span> <span class="kt">float</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">1</span><span class="p">)*</span> <span class="nv">%ptrB</span><span class="p">,</span> <span class="k">align</span> <span class="m">4</span>
+
+ <span class="c">; Compute C = A + B</span>
+ <span class="nv">%valC</span> <span class="p">=</span> <span class="k">fadd</span> <span class="kt">float</span> <span class="nv">%valA</span><span class="p">,</span> <span class="nv">%valB</span>
+
+ <span class="c">; Store back to C</span>
+ <span class="k">store</span> <span class="kt">float</span> <span class="nv">%valC</span><span class="p">,</span> <span class="kt">float</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">1</span><span class="p">)*</span> <span class="nv">%ptrC</span><span class="p">,</span> <span class="k">align</span> <span class="m">4</span>
+
+ <span class="k">ret</span> <span class="kt">void</span>
+<span class="p">}</span>
+
+<span class="nv">!nvvm.annotations</span> <span class="p">=</span> <span class="p">!{</span><span class="nv-Anonymous">!0</span><span class="p">}</span>
+<span class="nv-Anonymous">!0</span> <span class="p">=</span> <span class="kt">metadata</span> <span class="p">!{</span><span class="kt">void</span> <span class="p">(</span><span class="kt">float</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">1</span><span class="p">)*,</span>
+ <span class="kt">float</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">1</span><span class="p">)*,</span>
+ <span class="kt">float</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">1</span><span class="p">)*)*</span> <span class="vg">@kernel</span><span class="p">,</span> <span class="kt">metadata</span> <span class="nv">!"kernel"</span><span class="p">,</span> <span class="k">i32</span> <span class="m">1</span><span class="p">}</span>
+</pre></div>
+</div>
+<p>We can use the LLVM <tt class="docutils literal"><span class="pre">llc</span></tt> tool to directly run the NVPTX code generator:</p>
+<div class="highlight-text"><div class="highlight"><pre># llc -mcpu=sm_20 kernel.ll -o kernel.ptx
+</pre></div>
+</div>
+<div class="admonition note">
+<p class="first admonition-title">Note</p>
+<p class="last">If you want to generate 32-bit code, change <tt class="docutils literal"><span class="pre">p:64:64:64</span></tt> to <tt class="docutils literal"><span class="pre">p:32:32:32</span></tt>
+in the module data layout string and use <tt class="docutils literal"><span class="pre">nvptx-nvidia-cuda</span></tt> as the
+target triple.</p>
+</div>
+<p>The output we get from <tt class="docutils literal"><span class="pre">llc</span></tt> (as of LLVM 3.4):</p>
+<div class="highlight-text"><div class="highlight"><pre>//
+// Generated by LLVM NVPTX Back-End
+//
+
+.version 3.1
+.target sm_20
+.address_size 64
+
+ // .globl kernel
+ // @kernel
+.visible .entry kernel(
+ .param .u64 kernel_param_0,
+ .param .u64 kernel_param_1,
+ .param .u64 kernel_param_2
+)
+{
+ .reg .f32 %f<4>;
+ .reg .s32 %r<2>;
+ .reg .s64 %rl<8>;
+
+// BB#0: // %entry
+ ld.param.u64 %rl1, [kernel_param_0];
+ mov.u32 %r1, %tid.x;
+ mul.wide.s32 %rl2, %r1, 4;
+ add.s64 %rl3, %rl1, %rl2;
+ ld.param.u64 %rl4, [kernel_param_1];
+ add.s64 %rl5, %rl4, %rl2;
+ ld.param.u64 %rl6, [kernel_param_2];
+ add.s64 %rl7, %rl6, %rl2;
+ ld.global.f32 %f1, [%rl3];
+ ld.global.f32 %f2, [%rl5];
+ add.f32 %f3, %f1, %f2;
+ st.global.f32 [%rl7], %f3;
+ ret;
+}
+</pre></div>
+</div>
+</div>
+<div class="section" id="dissecting-the-kernel">
+<h3><a class="toc-backref" href="#id33">Dissecting the Kernel</a><a class="headerlink" href="#dissecting-the-kernel" title="Permalink to this headline">¶</a></h3>
+<p>Now let us dissect the LLVM IR that makes up this kernel.</p>
+<div class="section" id="data-layout">
+<h4><a class="toc-backref" href="#id34">Data Layout</a><a class="headerlink" href="#data-layout" title="Permalink to this headline">¶</a></h4>
+<p>The data layout string determines the size in bits of common data types, their
+ABI alignment, and their storage size. For NVPTX, you should use one of the
+following:</p>
+<p>32-bit PTX:</p>
+<div class="highlight-llvm"><div class="highlight"><pre><span class="k">target</span> <span class="k">datalayout</span> <span class="p">=</span> <span class="s">"e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v32:32:32-v64:64:64-v128:128:128-n16:32:64"</span>
+</pre></div>
+</div>
+<p>64-bit PTX:</p>
+<div class="highlight-llvm"><div class="highlight"><pre><span class="k">target</span> <span class="k">datalayout</span> <span class="p">=</span> <span class="s">"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v32:32:32-v64:64:64-v128:128:128-n16:32:64"</span>
+</pre></div>
+</div>
+</div>
+<div class="section" id="target-intrinsics">
+<h4><a class="toc-backref" href="#id35">Target Intrinsics</a><a class="headerlink" href="#target-intrinsics" title="Permalink to this headline">¶</a></h4>
+<p>In this example, we use the <tt class="docutils literal"><span class="pre">@llvm.nvvm.read.ptx.sreg.tid.x</span></tt> intrinsic to
+read the X component of the current thread’s ID, which corresponds to a read
+of register <tt class="docutils literal"><span class="pre">%tid.x</span></tt> in PTX. The NVPTX back-end supports a large set of
+intrinsics. A short list is shown below; please see
+<tt class="docutils literal"><span class="pre">include/llvm/IR/IntrinsicsNVVM.td</span></tt> for the full list.</p>
+<table border="1" class="docutils">
+<colgroup>
+<col width="71%" />
+<col width="29%" />
+</colgroup>
+<thead valign="bottom">
+<tr class="row-odd"><th class="head">Intrinsic</th>
+<th class="head">CUDA Equivalent</th>
+</tr>
+</thead>
+<tbody valign="top">
+<tr class="row-even"><td><tt class="docutils literal"><span class="pre">i32</span> <span class="pre">@llvm.nvvm.read.ptx.sreg.tid.{x,y,z}</span></tt></td>
+<td>threadIdx.{x,y,z}</td>
+</tr>
+<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">i32</span> <span class="pre">@llvm.nvvm.read.ptx.sreg.ctaid.{x,y,z}</span></tt></td>
+<td>blockIdx.{x,y,z}</td>
+</tr>
+<tr class="row-even"><td><tt class="docutils literal"><span class="pre">i32</span> <span class="pre">@llvm.nvvm.read.ptx.sreg.ntid.{x,y,z}</span></tt></td>
+<td>blockDim.{x,y,z}</td>
+</tr>
+<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">i32</span> <span class="pre">@llvm.nvvm.read.ptx.sreg.nctaid.{x,y,z}</span></tt></td>
+<td>gridDim.{x,y,z}</td>
+</tr>
+<tr class="row-even"><td><tt class="docutils literal"><span class="pre">void</span> <span class="pre">@llvm.cuda.syncthreads()</span></tt></td>
+<td>__syncthreads()</td>
+</tr>
+</tbody>
+</table>
+</div>
+<div class="section" id="id10">
+<h4><a class="toc-backref" href="#id36">Address Spaces</a><a class="headerlink" href="#id10" title="Permalink to this headline">¶</a></h4>
+<p>You may have noticed that all of the pointer types in the LLVM IR example had
+an explicit address space specifier. What is address space 1? NVIDIA GPU
+devices (generally) have four types of memory:</p>
+<ul class="simple">
+<li>Global: Large, off-chip memory</li>
+<li>Shared: Small, on-chip memory shared among all threads in a CTA</li>
+<li>Local: Per-thread, private memory</li>
+<li>Constant: Read-only memory shared across all threads</li>
+</ul>
+<p>These different types of memory are represented in LLVM IR as address spaces.
+There is also a fifth address space used by the NVPTX code generator that
+corresponds to the “generic” address space. This address space can represent
+addresses in any other address space (with a few exceptions). This allows
+users to write IR functions that can load/store memory using the same
+instructions. Intrinsics are provided to convert pointers between the generic
+and non-generic address spaces.</p>
+<p>See <a class="reference internal" href="#address-spaces"><em>Address Spaces</em></a> and <a class="reference internal" href="#nvptx-intrinsics"><em>NVPTX Intrinsics</em></a> for more information.</p>
+</div>
+<div class="section" id="kernel-metadata">
+<h4><a class="toc-backref" href="#id37">Kernel Metadata</a><a class="headerlink" href="#kernel-metadata" title="Permalink to this headline">¶</a></h4>
+<p>In PTX, a function can be either a <cite>kernel</cite> function (callable from the host
+program), or a <cite>device</cite> function (callable only from GPU code). You can think
+of <cite>kernel</cite> functions as entry-points in the GPU program. To mark an LLVM IR
+function as a <cite>kernel</cite> function, we make use of special LLVM metadata. The
+NVPTX back-end will look for a named metadata node called
+<tt class="docutils literal"><span class="pre">nvvm.annotations</span></tt>. This named metadata must contain a list of metadata that
+describe the IR. For our purposes, we need to declare a metadata node that
+assigns the “kernel” attribute to the LLVM IR function that should be emitted
+as a PTX <cite>kernel</cite> function. These metadata nodes take the form:</p>
+<div class="highlight-text"><div class="highlight"><pre>metadata !{<function ref>, metadata !"kernel", i32 1}
+</pre></div>
+</div>
+<p>For the previous example, we have:</p>
+<div class="highlight-llvm"><div class="highlight"><pre><span class="nv">!nvvm.annotations</span> <span class="p">=</span> <span class="p">!{</span><span class="nv-Anonymous">!0</span><span class="p">}</span>
+<span class="nv-Anonymous">!0</span> <span class="p">=</span> <span class="kt">metadata</span> <span class="p">!{</span><span class="kt">void</span> <span class="p">(</span><span class="kt">float</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">1</span><span class="p">)*,</span>
+ <span class="kt">float</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">1</span><span class="p">)*,</span>
+ <span class="kt">float</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">1</span><span class="p">)*)*</span> <span class="vg">@kernel</span><span class="p">,</span> <span class="kt">metadata</span> <span class="nv">!"kernel"</span><span class="p">,</span> <span class="k">i32</span> <span class="m">1</span><span class="p">}</span>
+</pre></div>
+</div>
+<p>Here, we have a single metadata declaration in <tt class="docutils literal"><span class="pre">nvvm.annotations</span></tt>. This
+metadata annotates our <tt class="docutils literal"><span class="pre">@kernel</span></tt> function with the <tt class="docutils literal"><span class="pre">kernel</span></tt> attribute.</p>
+</div>
+</div>
+<div class="section" id="running-the-kernel">
+<h3><a class="toc-backref" href="#id38">Running the Kernel</a><a class="headerlink" href="#running-the-kernel" title="Permalink to this headline">¶</a></h3>
+<p>Generating PTX from LLVM IR is all well and good, but how do we execute it on
+a real GPU device? The CUDA Driver API provides a convenient mechanism for
+loading and JIT compiling PTX to a native GPU device, and launching a kernel.
+The API is similar to OpenCL. A simple example showing how to load and
+execute our vector addition code is shown below. Note that for brevity this
+code does not perform much error checking!</p>
+<div class="admonition note">
+<p class="first admonition-title">Note</p>
+<p class="last">You can also use the <tt class="docutils literal"><span class="pre">ptxas</span></tt> tool provided by the CUDA Toolkit to offline
+compile PTX to machine code (SASS) for a specific GPU architecture. Such
+binaries can be loaded by the CUDA Driver API in the same way as PTX. This
+can be useful for reducing startup time by precompiling the PTX kernels.</p>
+</div>
+<div class="highlight-c++"><div class="highlight"><pre><span class="cp">#include <iostream></span>
+<span class="cp">#include <fstream></span>
+<span class="cp">#include <cassert></span>
+<span class="cp">#include "cuda.h"</span>
+
+
+<span class="kt">void</span> <span class="nf">checkCudaErrors</span><span class="p">(</span><span class="n">CUresult</span> <span class="n">err</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">assert</span><span class="p">(</span><span class="n">err</span> <span class="o">==</span> <span class="n">CUDA_SUCCESS</span><span class="p">);</span>
+<span class="p">}</span>
+
+<span class="c1">/// main - Program entry point</span>
+<span class="kt">int</span> <span class="nf">main</span><span class="p">(</span><span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="kt">char</span> <span class="o">**</span><span class="n">argv</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">CUdevice</span> <span class="n">device</span><span class="p">;</span>
+ <span class="n">CUmodule</span> <span class="n">cudaModule</span><span class="p">;</span>
+ <span class="n">CUcontext</span> <span class="n">context</span><span class="p">;</span>
+ <span class="n">CUfunction</span> <span class="n">function</span><span class="p">;</span>
+ <span class="n">CUlinkState</span> <span class="n">linker</span><span class="p">;</span>
+ <span class="kt">int</span> <span class="n">devCount</span><span class="p">;</span>
+
+ <span class="c1">// CUDA initialization</span>
+ <span class="n">checkCudaErrors</span><span class="p">(</span><span class="n">cuInit</span><span class="p">(</span><span class="mi">0</span><span class="p">));</span>
+ <span class="n">checkCudaErrors</span><span class="p">(</span><span class="n">cuDeviceGetCount</span><span class="p">(</span><span class="o">&</span><span class="n">devCount</span><span class="p">));</span>
+ <span class="n">checkCudaErrors</span><span class="p">(</span><span class="n">cuDeviceGet</span><span class="p">(</span><span class="o">&</span><span class="n">device</span><span class="p">,</span> <span class="mi">0</span><span class="p">));</span>
+
+ <span class="kt">char</span> <span class="n">name</span><span class="p">[</span><span class="mi">128</span><span class="p">];</span>
+ <span class="n">checkCudaErrors</span><span class="p">(</span><span class="n">cuDeviceGetName</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="mi">128</span><span class="p">,</span> <span class="n">device</span><span class="p">));</span>
+ <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o"><<</span> <span class="s">"Using CUDA Device [0]: "</span> <span class="o"><<</span> <span class="n">name</span> <span class="o"><<</span> <span class="s">"</span><span class="se">\n</span><span class="s">"</span><span class="p">;</span>
+
+ <span class="kt">int</span> <span class="n">devMajor</span><span class="p">,</span> <span class="n">devMinor</span><span class="p">;</span>
+ <span class="n">checkCudaErrors</span><span class="p">(</span><span class="n">cuDeviceComputeCapability</span><span class="p">(</span><span class="o">&</span><span class="n">devMajor</span><span class="p">,</span> <span class="o">&</span><span class="n">devMinor</span><span class="p">,</span> <span class="n">device</span><span class="p">));</span>
+ <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o"><<</span> <span class="s">"Device Compute Capability: "</span>
+ <span class="o"><<</span> <span class="n">devMajor</span> <span class="o"><<</span> <span class="s">"."</span> <span class="o"><<</span> <span class="n">devMinor</span> <span class="o"><<</span> <span class="s">"</span><span class="se">\n</span><span class="s">"</span><span class="p">;</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">devMajor</span> <span class="o"><</span> <span class="mi">2</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">std</span><span class="o">::</span><span class="n">cerr</span> <span class="o"><<</span> <span class="s">"ERROR: Device 0 is not SM 2.0 or greater</span><span class="se">\n</span><span class="s">"</span><span class="p">;</span>
+ <span class="k">return</span> <span class="mi">1</span><span class="p">;</span>
+ <span class="p">}</span>
+
+ <span class="n">std</span><span class="o">::</span><span class="n">ifstream</span> <span class="n">t</span><span class="p">(</span><span class="s">"kernel.ptx"</span><span class="p">);</span>
+ <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">t</span><span class="p">.</span><span class="n">is_open</span><span class="p">())</span> <span class="p">{</span>
+ <span class="n">std</span><span class="o">::</span><span class="n">cerr</span> <span class="o"><<</span> <span class="s">"kernel.ptx not found</span><span class="se">\n</span><span class="s">"</span><span class="p">;</span>
+ <span class="k">return</span> <span class="mi">1</span><span class="p">;</span>
+ <span class="p">}</span>
+ <span class="n">std</span><span class="o">::</span><span class="n">string</span> <span class="n">str</span><span class="p">((</span><span class="n">std</span><span class="o">::</span><span class="n">istreambuf_iterator</span><span class="o"><</span><span class="kt">char</span><span class="o">></span><span class="p">(</span><span class="n">t</span><span class="p">)),</span>
+ <span class="n">std</span><span class="o">::</span><span class="n">istreambuf_iterator</span><span class="o"><</span><span class="kt">char</span><span class="o">></span><span class="p">());</span>
+
+ <span class="c1">// Create driver context</span>
+ <span class="n">checkCudaErrors</span><span class="p">(</span><span class="n">cuCtxCreate</span><span class="p">(</span><span class="o">&</span><span class="n">context</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">device</span><span class="p">));</span>
+
+ <span class="c1">// Create module for object</span>
+ <span class="n">checkCudaErrors</span><span class="p">(</span><span class="n">cuModuleLoadDataEx</span><span class="p">(</span><span class="o">&</span><span class="n">cudaModule</span><span class="p">,</span> <span class="n">str</span><span class="p">.</span><span class="n">c_str</span><span class="p">(),</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">));</span>
+
+ <span class="c1">// Get kernel function</span>
+ <span class="n">checkCudaErrors</span><span class="p">(</span><span class="n">cuModuleGetFunction</span><span class="p">(</span><span class="o">&</span><span class="n">function</span><span class="p">,</span> <span class="n">cudaModule</span><span class="p">,</span> <span class="s">"kernel"</span><span class="p">));</span>
+
+ <span class="c1">// Device data</span>
+ <span class="n">CUdeviceptr</span> <span class="n">devBufferA</span><span class="p">;</span>
+ <span class="n">CUdeviceptr</span> <span class="n">devBufferB</span><span class="p">;</span>
+ <span class="n">CUdeviceptr</span> <span class="n">devBufferC</span><span class="p">;</span>
+
+ <span class="n">checkCudaErrors</span><span class="p">(</span><span class="n">cuMemAlloc</span><span class="p">(</span><span class="o">&</span><span class="n">devBufferA</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="kt">float</span><span class="p">)</span><span class="o">*</span><span class="mi">16</span><span class="p">));</span>
+ <span class="n">checkCudaErrors</span><span class="p">(</span><span class="n">cuMemAlloc</span><span class="p">(</span><span class="o">&</span><span class="n">devBufferB</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="kt">float</span><span class="p">)</span><span class="o">*</span><span class="mi">16</span><span class="p">));</span>
+ <span class="n">checkCudaErrors</span><span class="p">(</span><span class="n">cuMemAlloc</span><span class="p">(</span><span class="o">&</span><span class="n">devBufferC</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="kt">float</span><span class="p">)</span><span class="o">*</span><span class="mi">16</span><span class="p">));</span>
+
+ <span class="kt">float</span><span class="o">*</span> <span class="n">hostA</span> <span class="o">=</span> <span class="k">new</span> <span class="kt">float</span><span class="p">[</span><span class="mi">16</span><span class="p">];</span>
+ <span class="kt">float</span><span class="o">*</span> <span class="n">hostB</span> <span class="o">=</span> <span class="k">new</span> <span class="kt">float</span><span class="p">[</span><span class="mi">16</span><span class="p">];</span>
+ <span class="kt">float</span><span class="o">*</span> <span class="n">hostC</span> <span class="o">=</span> <span class="k">new</span> <span class="kt">float</span><span class="p">[</span><span class="mi">16</span><span class="p">];</span>
+
+ <span class="c1">// Populate input</span>
+ <span class="k">for</span> <span class="p">(</span><span class="kt">unsigned</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">!=</span> <span class="mi">16</span><span class="p">;</span> <span class="o">++</span><span class="n">i</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">hostA</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="kt">float</span><span class="p">)</span><span class="n">i</span><span class="p">;</span>
+ <span class="n">hostB</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="kt">float</span><span class="p">)(</span><span class="mi">2</span><span class="o">*</span><span class="n">i</span><span class="p">);</span>
+ <span class="n">hostC</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="mf">0.0f</span><span class="p">;</span>
+ <span class="p">}</span>
+
+ <span class="n">checkCudaErrors</span><span class="p">(</span><span class="n">cuMemcpyHtoD</span><span class="p">(</span><span class="n">devBufferA</span><span class="p">,</span> <span class="o">&</span><span class="n">hostA</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="k">sizeof</span><span class="p">(</span><span class="kt">float</span><span class="p">)</span><span class="o">*</span><span class="mi">16</span><span class="p">));</span>
+ <span class="n">checkCudaErrors</span><span class="p">(</span><span class="n">cuMemcpyHtoD</span><span class="p">(</span><span class="n">devBufferB</span><span class="p">,</span> <span class="o">&</span><span class="n">hostB</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="k">sizeof</span><span class="p">(</span><span class="kt">float</span><span class="p">)</span><span class="o">*</span><span class="mi">16</span><span class="p">));</span>
+
+
+ <span class="kt">unsigned</span> <span class="n">blockSizeX</span> <span class="o">=</span> <span class="mi">16</span><span class="p">;</span>
+ <span class="kt">unsigned</span> <span class="n">blockSizeY</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
+ <span class="kt">unsigned</span> <span class="n">blockSizeZ</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
+ <span class="kt">unsigned</span> <span class="n">gridSizeX</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
+ <span class="kt">unsigned</span> <span class="n">gridSizeY</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
+ <span class="kt">unsigned</span> <span class="n">gridSizeZ</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
+
+ <span class="c1">// Kernel parameters</span>
+ <span class="kt">void</span> <span class="o">*</span><span class="n">KernelParams</span><span class="p">[]</span> <span class="o">=</span> <span class="p">{</span> <span class="o">&</span><span class="n">devBufferA</span><span class="p">,</span> <span class="o">&</span><span class="n">devBufferB</span><span class="p">,</span> <span class="o">&</span><span class="n">devBufferC</span> <span class="p">};</span>
+
+ <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o"><<</span> <span class="s">"Launching kernel</span><span class="se">\n</span><span class="s">"</span><span class="p">;</span>
+
+ <span class="c1">// Kernel launch</span>
+ <span class="n">checkCudaErrors</span><span class="p">(</span><span class="n">cuLaunchKernel</span><span class="p">(</span><span class="n">function</span><span class="p">,</span> <span class="n">gridSizeX</span><span class="p">,</span> <span class="n">gridSizeY</span><span class="p">,</span> <span class="n">gridSizeZ</span><span class="p">,</span>
+ <span class="n">blockSizeX</span><span class="p">,</span> <span class="n">blockSizeY</span><span class="p">,</span> <span class="n">blockSizeZ</span><span class="p">,</span>
+ <span class="mi">0</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">,</span> <span class="n">KernelParams</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">));</span>
+
+ <span class="c1">// Retrieve device data</span>
+ <span class="n">checkCudaErrors</span><span class="p">(</span><span class="n">cuMemcpyDtoH</span><span class="p">(</span><span class="o">&</span><span class="n">hostC</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">devBufferC</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="kt">float</span><span class="p">)</span><span class="o">*</span><span class="mi">16</span><span class="p">));</span>
+
+
+ <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o"><<</span> <span class="s">"Results:</span><span class="se">\n</span><span class="s">"</span><span class="p">;</span>
+ <span class="k">for</span> <span class="p">(</span><span class="kt">unsigned</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">!=</span> <span class="mi">16</span><span class="p">;</span> <span class="o">++</span><span class="n">i</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o"><<</span> <span class="n">hostA</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o"><<</span> <span class="s">" + "</span> <span class="o"><<</span> <span class="n">hostB</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o"><<</span> <span class="s">" = "</span> <span class="o"><<</span> <span class="n">hostC</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o"><<</span> <span class="s">"</span><span class="se">\n</span><span class="s">"</span><span class="p">;</span>
+ <span class="p">}</span>
+
+
+ <span class="c1">// Clean up after ourselves</span>
+ <span class="k">delete</span> <span class="p">[]</span> <span class="n">hostA</span><span class="p">;</span>
+ <span class="k">delete</span> <span class="p">[]</span> <span class="n">hostB</span><span class="p">;</span>
+ <span class="k">delete</span> <span class="p">[]</span> <span class="n">hostC</span><span class="p">;</span>
+
+ <span class="c1">// Clean-up</span>
+ <span class="n">checkCudaErrors</span><span class="p">(</span><span class="n">cuMemFree</span><span class="p">(</span><span class="n">devBufferA</span><span class="p">));</span>
+ <span class="n">checkCudaErrors</span><span class="p">(</span><span class="n">cuMemFree</span><span class="p">(</span><span class="n">devBufferB</span><span class="p">));</span>
+ <span class="n">checkCudaErrors</span><span class="p">(</span><span class="n">cuMemFree</span><span class="p">(</span><span class="n">devBufferC</span><span class="p">));</span>
+ <span class="n">checkCudaErrors</span><span class="p">(</span><span class="n">cuModuleUnload</span><span class="p">(</span><span class="n">cudaModule</span><span class="p">));</span>
+ <span class="n">checkCudaErrors</span><span class="p">(</span><span class="n">cuCtxDestroy</span><span class="p">(</span><span class="n">context</span><span class="p">));</span>
+
+ <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
+<span class="p">}</span>
+</pre></div>
+</div>
+<p>You will need to link with the CUDA driver and specify the path to cuda.h.</p>
+<div class="highlight-text"><div class="highlight"><pre># clang++ sample.cpp -o sample -O2 -g -I/usr/local/cuda-5.5/include -lcuda
+</pre></div>
+</div>
+<p>We don’t need to specify a path to <tt class="docutils literal"><span class="pre">libcuda.so</span></tt> since this is installed in a
+system location by the driver, not the CUDA toolkit.</p>
+<p>If everything goes as planned, you should see the following output when
+running the compiled program:</p>
+<div class="highlight-text"><div class="highlight"><pre>Using CUDA Device [0]: GeForce GTX 680
+Device Compute Capability: 3.0
+Launching kernel
+Results:
+0 + 0 = 0
+1 + 2 = 3
+2 + 4 = 6
+3 + 6 = 9
+4 + 8 = 12
+5 + 10 = 15
+6 + 12 = 18
+7 + 14 = 21
+8 + 16 = 24
+9 + 18 = 27
+10 + 20 = 30
+11 + 22 = 33
+12 + 24 = 36
+13 + 26 = 39
+14 + 28 = 42
+15 + 30 = 45
+</pre></div>
+</div>
+<div class="admonition note">
+<p class="first admonition-title">Note</p>
+<p class="last">You will likely see a different device identifier based on your hardware</p>
+</div>
+</div>
+</div>
+<div class="section" id="tutorial-linking-with-libdevice">
+<h2><a class="toc-backref" href="#id39">Tutorial: Linking with Libdevice</a><a class="headerlink" href="#tutorial-linking-with-libdevice" title="Permalink to this headline">¶</a></h2>
+<p>In this tutorial, we show a simple example of linking LLVM IR with the
+libdevice library. We will use the same kernel as the previous tutorial,
+except that we will compute <tt class="docutils literal"><span class="pre">C</span> <span class="pre">=</span> <span class="pre">pow(A,</span> <span class="pre">B)</span></tt> instead of <tt class="docutils literal"><span class="pre">C</span> <span class="pre">=</span> <span class="pre">A</span> <span class="pre">+</span> <span class="pre">B</span></tt>.
+Libdevice provides an <tt class="docutils literal"><span class="pre">__nv_powf</span></tt> function that we will use.</p>
+<div class="highlight-llvm"><div class="highlight"><pre><span class="k">target</span> <span class="k">datalayout</span> <span class="p">=</span> <span class="s">"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v32:32:32-v64:64:64-v128:128:128-n16:32:64"</span>
+<span class="k">target</span> <span class="k">triple</span> <span class="p">=</span> <span class="s">"nvptx64-nvidia-cuda"</span>
+
+<span class="c">; Intrinsic to read X component of thread ID</span>
+<span class="k">declare</span> <span class="k">i32</span> <span class="vg">@llvm.nvvm.read.ptx.sreg.tid.x</span><span class="p">()</span> <span class="k">readnone</span> <span class="k">nounwind</span>
+<span class="c">; libdevice function</span>
+<span class="k">declare</span> <span class="kt">float</span> <span class="vg">@__nv_powf</span><span class="p">(</span><span class="kt">float</span><span class="p">,</span> <span class="kt">float</span><span class="p">)</span>
+
+<span class="k">define</span> <span class="kt">void</span> <span class="vg">@kernel</span><span class="p">(</span><span class="kt">float</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">1</span><span class="p">)*</span> <span class="nv">%A</span><span class="p">,</span>
+ <span class="kt">float</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">1</span><span class="p">)*</span> <span class="nv">%B</span><span class="p">,</span>
+ <span class="kt">float</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">1</span><span class="p">)*</span> <span class="nv">%C</span><span class="p">)</span> <span class="p">{</span>
+<span class="nl">entry:</span>
+ <span class="c">; What is my ID?</span>
+ <span class="nv">%id</span> <span class="p">=</span> <span class="k">tail</span> <span class="k">call</span> <span class="k">i32</span> <span class="vg">@llvm.nvvm.read.ptx.sreg.tid.x</span><span class="p">()</span> <span class="k">readnone</span> <span class="k">nounwind</span>
+
+ <span class="c">; Compute pointers into A, B, and C</span>
+ <span class="nv">%ptrA</span> <span class="p">=</span> <span class="k">getelementptr</span> <span class="kt">float</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">1</span><span class="p">)*</span> <span class="nv">%A</span><span class="p">,</span> <span class="k">i32</span> <span class="nv">%id</span>
+ <span class="nv">%ptrB</span> <span class="p">=</span> <span class="k">getelementptr</span> <span class="kt">float</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">1</span><span class="p">)*</span> <span class="nv">%B</span><span class="p">,</span> <span class="k">i32</span> <span class="nv">%id</span>
+ <span class="nv">%ptrC</span> <span class="p">=</span> <span class="k">getelementptr</span> <span class="kt">float</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">1</span><span class="p">)*</span> <span class="nv">%C</span><span class="p">,</span> <span class="k">i32</span> <span class="nv">%id</span>
+
+ <span class="c">; Read A, B</span>
+ <span class="nv">%valA</span> <span class="p">=</span> <span class="k">load</span> <span class="kt">float</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">1</span><span class="p">)*</span> <span class="nv">%ptrA</span><span class="p">,</span> <span class="k">align</span> <span class="m">4</span>
+ <span class="nv">%valB</span> <span class="p">=</span> <span class="k">load</span> <span class="kt">float</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">1</span><span class="p">)*</span> <span class="nv">%ptrB</span><span class="p">,</span> <span class="k">align</span> <span class="m">4</span>
+
+ <span class="c">; Compute C = pow(A, B)</span>
+ <span class="nv">%valC</span> <span class="p">=</span> <span class="k">call</span> <span class="kt">float</span> <span class="vg">@__nv_powf</span><span class="p">(</span><span class="kt">float</span> <span class="nv">%valA</span><span class="p">,</span> <span class="kt">float</span> <span class="nv">%valB</span><span class="p">)</span>
+
+ <span class="c">; Store back to C</span>
+ <span class="k">store</span> <span class="kt">float</span> <span class="nv">%valC</span><span class="p">,</span> <span class="kt">float</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">1</span><span class="p">)*</span> <span class="nv">%ptrC</span><span class="p">,</span> <span class="k">align</span> <span class="m">4</span>
+
+ <span class="k">ret</span> <span class="kt">void</span>
+<span class="p">}</span>
+
+<span class="nv">!nvvm.annotations</span> <span class="p">=</span> <span class="p">!{</span><span class="nv-Anonymous">!0</span><span class="p">}</span>
+<span class="nv-Anonymous">!0</span> <span class="p">=</span> <span class="kt">metadata</span> <span class="p">!{</span><span class="kt">void</span> <span class="p">(</span><span class="kt">float</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">1</span><span class="p">)*,</span>
+ <span class="kt">float</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">1</span><span class="p">)*,</span>
+ <span class="kt">float</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">1</span><span class="p">)*)*</span> <span class="vg">@kernel</span><span class="p">,</span> <span class="kt">metadata</span> <span class="nv">!"kernel"</span><span class="p">,</span> <span class="k">i32</span> <span class="m">1</span><span class="p">}</span>
+</pre></div>
+</div>
+<p>To compile this kernel, we perform the following steps:</p>
+<ol class="arabic simple">
+<li>Link with libdevice</li>
+<li>Internalize all but the public kernel function</li>
+<li>Run <tt class="docutils literal"><span class="pre">NVVMReflect</span></tt> and set <tt class="docutils literal"><span class="pre">__CUDA_FTZ</span></tt> to 0</li>
+<li>Optimize the linked module</li>
+<li>Codegen the module</li>
+</ol>
+<p>These steps can be performed by the LLVM <tt class="docutils literal"><span class="pre">llvm-link</span></tt>, <tt class="docutils literal"><span class="pre">opt</span></tt>, and <tt class="docutils literal"><span class="pre">llc</span></tt>
+tools. In a complete compiler, these steps can also be performed entirely
+programmatically by setting up an appropriate pass configuration (see
+<a class="reference internal" href="#libdevice"><em>Linking with Libdevice</em></a>).</p>
+<div class="highlight-text"><div class="highlight"><pre># llvm-link t2.bc libdevice.compute_20.10.bc -o t2.linked.bc
+# opt -internalize -internalize-public-api-list=kernel -nvvm-reflect-list=__CUDA_FTZ=0 -nvvm-reflect -O3 t2.linked.bc -o t2.opt.bc
+# llc -mcpu=sm_20 t2.opt.bc -o t2.ptx
+</pre></div>
+</div>
+<div class="admonition note">
+<p class="first admonition-title">Note</p>
+<p class="last">The <tt class="docutils literal"><span class="pre">-nvvm-reflect-list=_CUDA_FTZ=0</span></tt> is not strictly required, as any
+undefined variables will default to zero. It is shown here for evaluation
+purposes.</p>
+</div>
+<p>This gives us the following PTX (excerpt):</p>
+<div class="highlight-text"><div class="highlight"><pre>//
+// Generated by LLVM NVPTX Back-End
+//
+
+.version 3.1
+.target sm_20
+.address_size 64
+
+ // .globl kernel
+ // @kernel
+.visible .entry kernel(
+ .param .u64 kernel_param_0,
+ .param .u64 kernel_param_1,
+ .param .u64 kernel_param_2
+)
+{
+ .reg .pred %p<30>;
+ .reg .f32 %f<111>;
+ .reg .s32 %r<21>;
+ .reg .s64 %rl<8>;
+
+// BB#0: // %entry
+ ld.param.u64 %rl2, [kernel_param_0];
+ mov.u32 %r3, %tid.x;
+ ld.param.u64 %rl3, [kernel_param_1];
+ mul.wide.s32 %rl4, %r3, 4;
+ add.s64 %rl5, %rl2, %rl4;
+ ld.param.u64 %rl6, [kernel_param_2];
+ add.s64 %rl7, %rl3, %rl4;
+ add.s64 %rl1, %rl6, %rl4;
+ ld.global.f32 %f1, [%rl5];
+ ld.global.f32 %f2, [%rl7];
+ setp.eq.f32 %p1, %f1, 0f3F800000;
+ setp.eq.f32 %p2, %f2, 0f00000000;
+ or.pred %p3, %p1, %p2;
+ @%p3 bra BB0_1;
+ bra.uni BB0_2;
+BB0_1:
+ mov.f32 %f110, 0f3F800000;
+ st.global.f32 [%rl1], %f110;
+ ret;
+BB0_2: // %__nv_isnanf.exit.i
+ abs.f32 %f4, %f1;
+ setp.gtu.f32 %p4, %f4, 0f7F800000;
+ @%p4 bra BB0_4;
+// BB#3: // %__nv_isnanf.exit5.i
+ abs.f32 %f5, %f2;
+ setp.le.f32 %p5, %f5, 0f7F800000;
+ @%p5 bra BB0_5;
+BB0_4: // %.critedge1.i
+ add.f32 %f110, %f1, %f2;
+ st.global.f32 [%rl1], %f110;
+ ret;
+BB0_5: // %__nv_isinff.exit.i
+
+ ...
+
+BB0_26: // %__nv_truncf.exit.i.i.i.i.i
+ mul.f32 %f90, %f107, 0f3FB8AA3B;
+ cvt.rzi.f32.f32 %f91, %f90;
+ mov.f32 %f92, 0fBF317200;
+ fma.rn.f32 %f93, %f91, %f92, %f107;
+ mov.f32 %f94, 0fB5BFBE8E;
+ fma.rn.f32 %f95, %f91, %f94, %f93;
+ mul.f32 %f89, %f95, 0f3FB8AA3B;
+ // inline asm
+ ex2.approx.ftz.f32 %f88,%f89;
+ // inline asm
+ add.f32 %f96, %f91, 0f00000000;
+ ex2.approx.f32 %f97, %f96;
+ mul.f32 %f98, %f88, %f97;
+ setp.lt.f32 %p15, %f107, 0fC2D20000;
+ selp.f32 %f99, 0f00000000, %f98, %p15;
+ setp.gt.f32 %p16, %f107, 0f42D20000;
+ selp.f32 %f110, 0f7F800000, %f99, %p16;
+ setp.eq.f32 %p17, %f110, 0f7F800000;
+ @%p17 bra BB0_28;
+// BB#27:
+ fma.rn.f32 %f110, %f110, %f108, %f110;
+BB0_28: // %__internal_accurate_powf.exit.i
+ setp.lt.f32 %p18, %f1, 0f00000000;
+ setp.eq.f32 %p19, %f3, 0f3F800000;
+ and.pred %p20, %p18, %p19;
+ @!%p20 bra BB0_30;
+ bra.uni BB0_29;
+BB0_29:
+ mov.b32 %r9, %f110;
+ xor.b32 %r10, %r9, -2147483648;
+ mov.b32 %f110, %r10;
+BB0_30: // %__nv_powf.exit
+ st.global.f32 [%rl1], %f110;
+ ret;
+}
+</pre></div>
+</div>
+</div>
+</div>
+
+
+ </div>
+ </div>
+ <div class="clearer"></div>
+ </div>
+ <div class="related">
+ <h3>Navigation</h3>
+ <ul>
+ <li class="right" style="margin-right: 10px">
+ <a href="genindex.html" title="General Index"
+ >index</a></li>
+ <li class="right" >
+ <a href="AMDGPUUsage.html" title="User Guide for AMDGPU Back-end"
+ >next</a> |</li>
+ <li class="right" >
+ <a href="HowToUseAttributes.html" title="How To Use Attributes"
+ >previous</a> |</li>
+ <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+ <li><a href="index.html">Documentation</a>»</li>
+
+ </ul>
+ </div>
+ <div class="footer">
+ © Copyright 2003-2016, LLVM Project.
+ Last updated on 2016-01-04.
+ Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.3.
+ </div>
+ </body>
+</html>
\ No newline at end of file
Added: www-releases/trunk/3.7.1/docs/Packaging.html
URL: http://llvm.org/viewvc/llvm-project/www-releases/trunk/3.7.1/docs/Packaging.html?rev=257950&view=auto
==============================================================================
--- www-releases/trunk/3.7.1/docs/Packaging.html (added)
+++ www-releases/trunk/3.7.1/docs/Packaging.html Fri Jan 15 17:13:16 2016
@@ -0,0 +1,169 @@
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
+ <title>Advice on Packaging LLVM — LLVM 3.7 documentation</title>
+
+ <link rel="stylesheet" href="_static/llvm-theme.css" type="text/css" />
+ <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
+
+ <script type="text/javascript">
+ var DOCUMENTATION_OPTIONS = {
+ URL_ROOT: './',
+ VERSION: '3.7',
+ COLLAPSE_INDEX: false,
+ FILE_SUFFIX: '.html',
+ HAS_SOURCE: true
+ };
+ </script>
+ <script type="text/javascript" src="_static/jquery.js"></script>
+ <script type="text/javascript" src="_static/underscore.js"></script>
+ <script type="text/javascript" src="_static/doctools.js"></script>
+ <link rel="top" title="LLVM 3.7 documentation" href="index.html" />
+ <link rel="next" title="How To Validate a New Release" href="ReleaseProcess.html" />
+ <link rel="prev" title="How To Release LLVM To The Public" href="HowToReleaseLLVM.html" />
+<style type="text/css">
+ table.right { float: right; margin-left: 20px; }
+ table.right td { border: 1px solid #ccc; }
+</style>
+
+ </head>
+ <body>
+<div class="logo">
+ <a href="index.html">
+ <img src="_static/logo.png"
+ alt="LLVM Logo" width="250" height="88"/></a>
+</div>
+
+ <div class="related">
+ <h3>Navigation</h3>
+ <ul>
+ <li class="right" style="margin-right: 10px">
+ <a href="genindex.html" title="General Index"
+ accesskey="I">index</a></li>
+ <li class="right" >
+ <a href="ReleaseProcess.html" title="How To Validate a New Release"
+ accesskey="N">next</a> |</li>
+ <li class="right" >
+ <a href="HowToReleaseLLVM.html" title="How To Release LLVM To The Public"
+ accesskey="P">previous</a> |</li>
+ <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+ <li><a href="index.html">Documentation</a>»</li>
+
+ </ul>
+ </div>
+
+
+ <div class="document">
+ <div class="documentwrapper">
+ <div class="body">
+
+ <div class="section" id="advice-on-packaging-llvm">
+<h1>Advice on Packaging LLVM<a class="headerlink" href="#advice-on-packaging-llvm" title="Permalink to this headline">¶</a></h1>
+<div class="contents local topic" id="contents">
+<ul class="simple">
+<li><a class="reference internal" href="#overview" id="id1">Overview</a></li>
+<li><a class="reference internal" href="#compile-flags" id="id2">Compile Flags</a></li>
+<li><a class="reference internal" href="#c-features" id="id3">C++ Features</a></li>
+<li><a class="reference internal" href="#shared-library" id="id4">Shared Library</a></li>
+<li><a class="reference internal" href="#dependencies" id="id5">Dependencies</a></li>
+</ul>
+</div>
+<div class="section" id="overview">
+<h2><a class="toc-backref" href="#id1">Overview</a><a class="headerlink" href="#overview" title="Permalink to this headline">¶</a></h2>
+<p>LLVM sets certain default configure options to make sure our developers don’t
+break things for constrained platforms. These settings are not optimal for most
+desktop systems, and we hope that packagers (e.g., Redhat, Debian, MacPorts,
+etc.) will tweak them. This document lists settings we suggest you tweak.</p>
+<p>LLVM’s API changes with each release, so users are likely to want, for example,
+both LLVM-2.6 and LLVM-2.7 installed at the same time to support apps developed
+against each.</p>
+</div>
+<div class="section" id="compile-flags">
+<h2><a class="toc-backref" href="#id2">Compile Flags</a><a class="headerlink" href="#compile-flags" title="Permalink to this headline">¶</a></h2>
+<p>LLVM runs much more quickly when it’s optimized and assertions are removed.
+However, such a build is currently incompatible with users who build without
+defining <tt class="docutils literal"><span class="pre">NDEBUG</span></tt>, and the lack of assertions makes it hard to debug problems
+in user code. We recommend allowing users to install both optimized and debug
+versions of LLVM in parallel. The following configure flags are relevant:</p>
+<dl class="docutils">
+<dt><tt class="docutils literal"><span class="pre">--disable-assertions</span></tt></dt>
+<dd>Builds LLVM with <tt class="docutils literal"><span class="pre">NDEBUG</span></tt> defined. Changes the LLVM ABI. Also available
+by setting <tt class="docutils literal"><span class="pre">DISABLE_ASSERTIONS=0|1</span></tt> in <tt class="docutils literal"><span class="pre">make</span></tt>‘s environment. This
+defaults to enabled regardless of the optimization setting, but it slows
+things down.</dd>
+<dt><tt class="docutils literal"><span class="pre">--enable-debug-symbols</span></tt></dt>
+<dd>Builds LLVM with <tt class="docutils literal"><span class="pre">-g</span></tt>. Also available by setting <tt class="docutils literal"><span class="pre">DEBUG_SYMBOLS=0|1</span></tt> in
+<tt class="docutils literal"><span class="pre">make</span></tt>‘s environment. This defaults to disabled when optimizing, so you
+should turn it back on to let users debug their programs.</dd>
+<dt><tt class="docutils literal"><span class="pre">--enable-optimized</span></tt></dt>
+<dd>(For svn checkouts) Builds LLVM with <tt class="docutils literal"><span class="pre">-O2</span></tt> and, by default, turns off
+debug symbols. Also available by setting <tt class="docutils literal"><span class="pre">ENABLE_OPTIMIZED=0|1</span></tt> in
+<tt class="docutils literal"><span class="pre">make</span></tt>‘s environment. This defaults to enabled when not in a
+checkout.</dd>
+</dl>
+</div>
+<div class="section" id="c-features">
+<h2><a class="toc-backref" href="#id3">C++ Features</a><a class="headerlink" href="#c-features" title="Permalink to this headline">¶</a></h2>
+<dl class="docutils">
+<dt>RTTI</dt>
+<dd>LLVM disables RTTI by default. Add <tt class="docutils literal"><span class="pre">REQUIRES_RTTI=1</span></tt> to your environment
+while running <tt class="docutils literal"><span class="pre">make</span></tt> to re-enable it. This will allow users to build with
+RTTI enabled and still inherit from LLVM classes.</dd>
+</dl>
+</div>
+<div class="section" id="shared-library">
+<h2><a class="toc-backref" href="#id4">Shared Library</a><a class="headerlink" href="#shared-library" title="Permalink to this headline">¶</a></h2>
+<p>Configure with <tt class="docutils literal"><span class="pre">--enable-shared</span></tt> to build
+<tt class="docutils literal"><span class="pre">libLLVM-<major>.<minor>.(so|dylib)</span></tt> and link the tools against it. This
+saves lots of binary size at the cost of some startup time.</p>
+</div>
+<div class="section" id="dependencies">
+<h2><a class="toc-backref" href="#id5">Dependencies</a><a class="headerlink" href="#dependencies" title="Permalink to this headline">¶</a></h2>
+<dl class="docutils">
+<dt><tt class="docutils literal"><span class="pre">--enable-libffi</span></tt></dt>
+<dd>Depend on <a class="reference external" href="http://sources.redhat.com/libffi/">libffi</a> to allow the LLVM
+interpreter to call external functions.</dd>
+</dl>
+<p><tt class="docutils literal"><span class="pre">--with-oprofile</span></tt></p>
+<blockquote>
+<div>Depend on <a class="reference external" href="http://oprofile.sourceforge.net/doc/devel/index.html">libopagent</a> (>=version 0.9.4)
+to let the LLVM JIT tell oprofile about function addresses and line
+numbers.</div></blockquote>
+</div>
+</div>
+
+
+ </div>
+ </div>
+ <div class="clearer"></div>
+ </div>
+ <div class="related">
+ <h3>Navigation</h3>
+ <ul>
+ <li class="right" style="margin-right: 10px">
+ <a href="genindex.html" title="General Index"
+ >index</a></li>
+ <li class="right" >
+ <a href="ReleaseProcess.html" title="How To Validate a New Release"
+ >next</a> |</li>
+ <li class="right" >
+ <a href="HowToReleaseLLVM.html" title="How To Release LLVM To The Public"
+ >previous</a> |</li>
+ <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+ <li><a href="index.html">Documentation</a>»</li>
+
+ </ul>
+ </div>
+ <div class="footer">
+ © Copyright 2003-2016, LLVM Project.
+ Last updated on 2016-01-04.
+ Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.3.
+ </div>
+ </body>
+</html>
\ No newline at end of file
Added: www-releases/trunk/3.7.1/docs/Passes.html
URL: http://llvm.org/viewvc/llvm-project/www-releases/trunk/3.7.1/docs/Passes.html?rev=257950&view=auto
==============================================================================
--- www-releases/trunk/3.7.1/docs/Passes.html (added)
+++ www-releases/trunk/3.7.1/docs/Passes.html Fri Jan 15 17:13:16 2016
@@ -0,0 +1,1184 @@
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
+ <title>LLVMâs Analysis and Transform Passes — LLVM 3.7 documentation</title>
+
+ <link rel="stylesheet" href="_static/llvm-theme.css" type="text/css" />
+ <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
+
+ <script type="text/javascript">
+ var DOCUMENTATION_OPTIONS = {
+ URL_ROOT: './',
+ VERSION: '3.7',
+ COLLAPSE_INDEX: false,
+ FILE_SUFFIX: '.html',
+ HAS_SOURCE: true
+ };
+ </script>
+ <script type="text/javascript" src="_static/jquery.js"></script>
+ <script type="text/javascript" src="_static/underscore.js"></script>
+ <script type="text/javascript" src="_static/doctools.js"></script>
+ <link rel="top" title="LLVM 3.7 documentation" href="index.html" />
+ <link rel="next" title="YAML I/O" href="YamlIO.html" />
+ <link rel="prev" title="LLVM 3.7 Release Notes" href="ReleaseNotes.html" />
+<style type="text/css">
+ table.right { float: right; margin-left: 20px; }
+ table.right td { border: 1px solid #ccc; }
+</style>
+
+ </head>
+ <body>
+<div class="logo">
+ <a href="index.html">
+ <img src="_static/logo.png"
+ alt="LLVM Logo" width="250" height="88"/></a>
+</div>
+
+ <div class="related">
+ <h3>Navigation</h3>
+ <ul>
+ <li class="right" style="margin-right: 10px">
+ <a href="genindex.html" title="General Index"
+ accesskey="I">index</a></li>
+ <li class="right" >
+ <a href="YamlIO.html" title="YAML I/O"
+ accesskey="N">next</a> |</li>
+ <li class="right" >
+ <a href="ReleaseNotes.html" title="LLVM 3.7 Release Notes"
+ accesskey="P">previous</a> |</li>
+ <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+ <li><a href="index.html">Documentation</a>»</li>
+
+ </ul>
+ </div>
+
+
+ <div class="document">
+ <div class="documentwrapper">
+ <div class="body">
+
+ <div class="section" id="llvm-s-analysis-and-transform-passes">
+<h1>LLVM’s Analysis and Transform Passes<a class="headerlink" href="#llvm-s-analysis-and-transform-passes" title="Permalink to this headline">¶</a></h1>
+<div class="contents local topic" id="contents">
+<ul class="simple">
+<li><a class="reference internal" href="#introduction" id="id1">Introduction</a></li>
+<li><a class="reference internal" href="#analysis-passes" id="id2">Analysis Passes</a><ul>
+<li><a class="reference internal" href="#aa-eval-exhaustive-alias-analysis-precision-evaluator" id="id3"><tt class="docutils literal"><span class="pre">-aa-eval</span></tt>: Exhaustive Alias Analysis Precision Evaluator</a></li>
+<li><a class="reference internal" href="#basicaa-basic-alias-analysis-stateless-aa-impl" id="id4"><tt class="docutils literal"><span class="pre">-basicaa</span></tt>: Basic Alias Analysis (stateless AA impl)</a></li>
+<li><a class="reference internal" href="#basiccg-basic-callgraph-construction" id="id5"><tt class="docutils literal"><span class="pre">-basiccg</span></tt>: Basic CallGraph Construction</a></li>
+<li><a class="reference internal" href="#count-aa-count-alias-analysis-query-responses" id="id6"><tt class="docutils literal"><span class="pre">-count-aa</span></tt>: Count Alias Analysis Query Responses</a></li>
+<li><a class="reference internal" href="#da-dependence-analysis" id="id7"><tt class="docutils literal"><span class="pre">-da</span></tt>: Dependence Analysis</a></li>
+<li><a class="reference internal" href="#debug-aa-aa-use-debugger" id="id8"><tt class="docutils literal"><span class="pre">-debug-aa</span></tt>: AA use debugger</a></li>
+<li><a class="reference internal" href="#domfrontier-dominance-frontier-construction" id="id9"><tt class="docutils literal"><span class="pre">-domfrontier</span></tt>: Dominance Frontier Construction</a></li>
+<li><a class="reference internal" href="#domtree-dominator-tree-construction" id="id10"><tt class="docutils literal"><span class="pre">-domtree</span></tt>: Dominator Tree Construction</a></li>
+<li><a class="reference internal" href="#dot-callgraph-print-call-graph-to-dot-file" id="id11"><tt class="docutils literal"><span class="pre">-dot-callgraph</span></tt>: Print Call Graph to “dot” file</a></li>
+<li><a class="reference internal" href="#dot-cfg-print-cfg-of-function-to-dot-file" id="id12"><tt class="docutils literal"><span class="pre">-dot-cfg</span></tt>: Print CFG of function to “dot” file</a></li>
+<li><a class="reference internal" href="#dot-cfg-only-print-cfg-of-function-to-dot-file-with-no-function-bodies" id="id13"><tt class="docutils literal"><span class="pre">-dot-cfg-only</span></tt>: Print CFG of function to “dot” file (with no function bodies)</a></li>
+<li><a class="reference internal" href="#dot-dom-print-dominance-tree-of-function-to-dot-file" id="id14"><tt class="docutils literal"><span class="pre">-dot-dom</span></tt>: Print dominance tree of function to “dot” file</a></li>
+<li><a class="reference internal" href="#dot-dom-only-print-dominance-tree-of-function-to-dot-file-with-no-function-bodies" id="id15"><tt class="docutils literal"><span class="pre">-dot-dom-only</span></tt>: Print dominance tree of function to “dot” file (with no function bodies)</a></li>
+<li><a class="reference internal" href="#dot-postdom-print-postdominance-tree-of-function-to-dot-file" id="id16"><tt class="docutils literal"><span class="pre">-dot-postdom</span></tt>: Print postdominance tree of function to “dot” file</a></li>
+<li><a class="reference internal" href="#dot-postdom-only-print-postdominance-tree-of-function-to-dot-file-with-no-function-bodies" id="id17"><tt class="docutils literal"><span class="pre">-dot-postdom-only</span></tt>: Print postdominance tree of function to “dot” file (with no function bodies)</a></li>
+<li><a class="reference internal" href="#globalsmodref-aa-simple-mod-ref-analysis-for-globals" id="id18"><tt class="docutils literal"><span class="pre">-globalsmodref-aa</span></tt>: Simple mod/ref analysis for globals</a></li>
+<li><a class="reference internal" href="#instcount-counts-the-various-types-of-instructions" id="id19"><tt class="docutils literal"><span class="pre">-instcount</span></tt>: Counts the various types of <tt class="docutils literal"><span class="pre">Instruction</span></tt>s</a></li>
+<li><a class="reference internal" href="#intervals-interval-partition-construction" id="id20"><tt class="docutils literal"><span class="pre">-intervals</span></tt>: Interval Partition Construction</a></li>
+<li><a class="reference internal" href="#iv-users-induction-variable-users" id="id21"><tt class="docutils literal"><span class="pre">-iv-users</span></tt>: Induction Variable Users</a></li>
+<li><a class="reference internal" href="#lazy-value-info-lazy-value-information-analysis" id="id22"><tt class="docutils literal"><span class="pre">-lazy-value-info</span></tt>: Lazy Value Information Analysis</a></li>
+<li><a class="reference internal" href="#libcall-aa-libcall-alias-analysis" id="id23"><tt class="docutils literal"><span class="pre">-libcall-aa</span></tt>: LibCall Alias Analysis</a></li>
+<li><a class="reference internal" href="#lint-statically-lint-checks-llvm-ir" id="id24"><tt class="docutils literal"><span class="pre">-lint</span></tt>: Statically lint-checks LLVM IR</a></li>
+<li><a class="reference internal" href="#loops-natural-loop-information" id="id25"><tt class="docutils literal"><span class="pre">-loops</span></tt>: Natural Loop Information</a></li>
+<li><a class="reference internal" href="#memdep-memory-dependence-analysis" id="id26"><tt class="docutils literal"><span class="pre">-memdep</span></tt>: Memory Dependence Analysis</a></li>
+<li><a class="reference internal" href="#module-debuginfo-decodes-module-level-debug-info" id="id27"><tt class="docutils literal"><span class="pre">-module-debuginfo</span></tt>: Decodes module-level debug info</a></li>
+<li><a class="reference internal" href="#no-aa-no-alias-analysis-always-returns-may-alias" id="id28"><tt class="docutils literal"><span class="pre">-no-aa</span></tt>: No Alias Analysis (always returns ‘may’ alias)</a></li>
+<li><a class="reference internal" href="#postdomfrontier-post-dominance-frontier-construction" id="id29"><tt class="docutils literal"><span class="pre">-postdomfrontier</span></tt>: Post-Dominance Frontier Construction</a></li>
+<li><a class="reference internal" href="#postdomtree-post-dominator-tree-construction" id="id30"><tt class="docutils literal"><span class="pre">-postdomtree</span></tt>: Post-Dominator Tree Construction</a></li>
+<li><a class="reference internal" href="#print-alias-sets-alias-set-printer" id="id31"><tt class="docutils literal"><span class="pre">-print-alias-sets</span></tt>: Alias Set Printer</a></li>
+<li><a class="reference internal" href="#print-callgraph-print-a-call-graph" id="id32"><tt class="docutils literal"><span class="pre">-print-callgraph</span></tt>: Print a call graph</a></li>
+<li><a class="reference internal" href="#print-callgraph-sccs-print-sccs-of-the-call-graph" id="id33"><tt class="docutils literal"><span class="pre">-print-callgraph-sccs</span></tt>: Print SCCs of the Call Graph</a></li>
+<li><a class="reference internal" href="#print-cfg-sccs-print-sccs-of-each-function-cfg" id="id34"><tt class="docutils literal"><span class="pre">-print-cfg-sccs</span></tt>: Print SCCs of each function CFG</a></li>
+<li><a class="reference internal" href="#print-dom-info-dominator-info-printer" id="id35"><tt class="docutils literal"><span class="pre">-print-dom-info</span></tt>: Dominator Info Printer</a></li>
+<li><a class="reference internal" href="#print-externalfnconstants-print-external-fn-callsites-passed-constants" id="id36"><tt class="docutils literal"><span class="pre">-print-externalfnconstants</span></tt>: Print external fn callsites passed constants</a></li>
+<li><a class="reference internal" href="#print-function-print-function-to-stderr" id="id37"><tt class="docutils literal"><span class="pre">-print-function</span></tt>: Print function to stderr</a></li>
+<li><a class="reference internal" href="#print-module-print-module-to-stderr" id="id38"><tt class="docutils literal"><span class="pre">-print-module</span></tt>: Print module to stderr</a></li>
+<li><a class="reference internal" href="#print-used-types-find-used-types" id="id39"><tt class="docutils literal"><span class="pre">-print-used-types</span></tt>: Find Used Types</a></li>
+<li><a class="reference internal" href="#regions-detect-single-entry-single-exit-regions" id="id40"><tt class="docutils literal"><span class="pre">-regions</span></tt>: Detect single entry single exit regions</a></li>
+<li><a class="reference internal" href="#scalar-evolution-scalar-evolution-analysis" id="id41"><tt class="docutils literal"><span class="pre">-scalar-evolution</span></tt>: Scalar Evolution Analysis</a></li>
+<li><a class="reference internal" href="#scev-aa-scalarevolution-based-alias-analysis" id="id42"><tt class="docutils literal"><span class="pre">-scev-aa</span></tt>: ScalarEvolution-based Alias Analysis</a></li>
+<li><a class="reference internal" href="#targetdata-target-data-layout" id="id43"><tt class="docutils literal"><span class="pre">-targetdata</span></tt>: Target Data Layout</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#transform-passes" id="id44">Transform Passes</a><ul>
+<li><a class="reference internal" href="#adce-aggressive-dead-code-elimination" id="id45"><tt class="docutils literal"><span class="pre">-adce</span></tt>: Aggressive Dead Code Elimination</a></li>
+<li><a class="reference internal" href="#always-inline-inliner-for-always-inline-functions" id="id46"><tt class="docutils literal"><span class="pre">-always-inline</span></tt>: Inliner for <tt class="docutils literal"><span class="pre">always_inline</span></tt> functions</a></li>
+<li><a class="reference internal" href="#argpromotion-promote-by-reference-arguments-to-scalars" id="id47"><tt class="docutils literal"><span class="pre">-argpromotion</span></tt>: Promote ‘by reference’ arguments to scalars</a></li>
+<li><a class="reference internal" href="#bb-vectorize-basic-block-vectorization" id="id48"><tt class="docutils literal"><span class="pre">-bb-vectorize</span></tt>: Basic-Block Vectorization</a></li>
+<li><a class="reference internal" href="#block-placement-profile-guided-basic-block-placement" id="id49"><tt class="docutils literal"><span class="pre">-block-placement</span></tt>: Profile Guided Basic Block Placement</a></li>
+<li><a class="reference internal" href="#break-crit-edges-break-critical-edges-in-cfg" id="id50"><tt class="docutils literal"><span class="pre">-break-crit-edges</span></tt>: Break critical edges in CFG</a></li>
+<li><a class="reference internal" href="#codegenprepare-optimize-for-code-generation" id="id51"><tt class="docutils literal"><span class="pre">-codegenprepare</span></tt>: Optimize for code generation</a></li>
+<li><a class="reference internal" href="#constmerge-merge-duplicate-global-constants" id="id52"><tt class="docutils literal"><span class="pre">-constmerge</span></tt>: Merge Duplicate Global Constants</a></li>
+<li><a class="reference internal" href="#constprop-simple-constant-propagation" id="id53"><tt class="docutils literal"><span class="pre">-constprop</span></tt>: Simple constant propagation</a></li>
+<li><a class="reference internal" href="#dce-dead-code-elimination" id="id54"><tt class="docutils literal"><span class="pre">-dce</span></tt>: Dead Code Elimination</a></li>
+<li><a class="reference internal" href="#deadargelim-dead-argument-elimination" id="id55"><tt class="docutils literal"><span class="pre">-deadargelim</span></tt>: Dead Argument Elimination</a></li>
+<li><a class="reference internal" href="#deadtypeelim-dead-type-elimination" id="id56"><tt class="docutils literal"><span class="pre">-deadtypeelim</span></tt>: Dead Type Elimination</a></li>
+<li><a class="reference internal" href="#die-dead-instruction-elimination" id="id57"><tt class="docutils literal"><span class="pre">-die</span></tt>: Dead Instruction Elimination</a></li>
+<li><a class="reference internal" href="#dse-dead-store-elimination" id="id58"><tt class="docutils literal"><span class="pre">-dse</span></tt>: Dead Store Elimination</a></li>
+<li><a class="reference internal" href="#functionattrs-deduce-function-attributes" id="id59"><tt class="docutils literal"><span class="pre">-functionattrs</span></tt>: Deduce function attributes</a></li>
+<li><a class="reference internal" href="#globaldce-dead-global-elimination" id="id60"><tt class="docutils literal"><span class="pre">-globaldce</span></tt>: Dead Global Elimination</a></li>
+<li><a class="reference internal" href="#globalopt-global-variable-optimizer" id="id61"><tt class="docutils literal"><span class="pre">-globalopt</span></tt>: Global Variable Optimizer</a></li>
+<li><a class="reference internal" href="#gvn-global-value-numbering" id="id62"><tt class="docutils literal"><span class="pre">-gvn</span></tt>: Global Value Numbering</a></li>
+<li><a class="reference internal" href="#indvars-canonicalize-induction-variables" id="id63"><tt class="docutils literal"><span class="pre">-indvars</span></tt>: Canonicalize Induction Variables</a></li>
+<li><a class="reference internal" href="#inline-function-integration-inlining" id="id64"><tt class="docutils literal"><span class="pre">-inline</span></tt>: Function Integration/Inlining</a></li>
+<li><a class="reference internal" href="#instcombine-combine-redundant-instructions" id="id65"><tt class="docutils literal"><span class="pre">-instcombine</span></tt>: Combine redundant instructions</a></li>
+<li><a class="reference internal" href="#internalize-internalize-global-symbols" id="id66"><tt class="docutils literal"><span class="pre">-internalize</span></tt>: Internalize Global Symbols</a></li>
+<li><a class="reference internal" href="#ipconstprop-interprocedural-constant-propagation" id="id67"><tt class="docutils literal"><span class="pre">-ipconstprop</span></tt>: Interprocedural constant propagation</a></li>
+<li><a class="reference internal" href="#ipsccp-interprocedural-sparse-conditional-constant-propagation" id="id68"><tt class="docutils literal"><span class="pre">-ipsccp</span></tt>: Interprocedural Sparse Conditional Constant Propagation</a></li>
+<li><a class="reference internal" href="#jump-threading-jump-threading" id="id69"><tt class="docutils literal"><span class="pre">-jump-threading</span></tt>: Jump Threading</a></li>
+<li><a class="reference internal" href="#lcssa-loop-closed-ssa-form-pass" id="id70"><tt class="docutils literal"><span class="pre">-lcssa</span></tt>: Loop-Closed SSA Form Pass</a></li>
+<li><a class="reference internal" href="#licm-loop-invariant-code-motion" id="id71"><tt class="docutils literal"><span class="pre">-licm</span></tt>: Loop Invariant Code Motion</a></li>
+<li><a class="reference internal" href="#loop-deletion-delete-dead-loops" id="id72"><tt class="docutils literal"><span class="pre">-loop-deletion</span></tt>: Delete dead loops</a></li>
+<li><a class="reference internal" href="#loop-extract-extract-loops-into-new-functions" id="id73"><tt class="docutils literal"><span class="pre">-loop-extract</span></tt>: Extract loops into new functions</a></li>
+<li><a class="reference internal" href="#loop-extract-single-extract-at-most-one-loop-into-a-new-function" id="id74"><tt class="docutils literal"><span class="pre">-loop-extract-single</span></tt>: Extract at most one loop into a new function</a></li>
+<li><a class="reference internal" href="#loop-reduce-loop-strength-reduction" id="id75"><tt class="docutils literal"><span class="pre">-loop-reduce</span></tt>: Loop Strength Reduction</a></li>
+<li><a class="reference internal" href="#loop-rotate-rotate-loops" id="id76"><tt class="docutils literal"><span class="pre">-loop-rotate</span></tt>: Rotate Loops</a></li>
+<li><a class="reference internal" href="#loop-simplify-canonicalize-natural-loops" id="id77"><tt class="docutils literal"><span class="pre">-loop-simplify</span></tt>: Canonicalize natural loops</a></li>
+<li><a class="reference internal" href="#loop-unroll-unroll-loops" id="id78"><tt class="docutils literal"><span class="pre">-loop-unroll</span></tt>: Unroll loops</a></li>
+<li><a class="reference internal" href="#loop-unswitch-unswitch-loops" id="id79"><tt class="docutils literal"><span class="pre">-loop-unswitch</span></tt>: Unswitch loops</a></li>
+<li><a class="reference internal" href="#loweratomic-lower-atomic-intrinsics-to-non-atomic-form" id="id80"><tt class="docutils literal"><span class="pre">-loweratomic</span></tt>: Lower atomic intrinsics to non-atomic form</a></li>
+<li><a class="reference internal" href="#lowerinvoke-lower-invokes-to-calls-for-unwindless-code-generators" id="id81"><tt class="docutils literal"><span class="pre">-lowerinvoke</span></tt>: Lower invokes to calls, for unwindless code generators</a></li>
+<li><a class="reference internal" href="#lowerswitch-lower-switchinsts-to-branches" id="id82"><tt class="docutils literal"><span class="pre">-lowerswitch</span></tt>: Lower <tt class="docutils literal"><span class="pre">SwitchInst</span></tt>s to branches</a></li>
+<li><a class="reference internal" href="#mem2reg-promote-memory-to-register" id="id83"><tt class="docutils literal"><span class="pre">-mem2reg</span></tt>: Promote Memory to Register</a></li>
+<li><a class="reference internal" href="#memcpyopt-memcpy-optimization" id="id84"><tt class="docutils literal"><span class="pre">-memcpyopt</span></tt>: MemCpy Optimization</a></li>
+<li><a class="reference internal" href="#mergefunc-merge-functions" id="id85"><tt class="docutils literal"><span class="pre">-mergefunc</span></tt>: Merge Functions</a></li>
+<li><a class="reference internal" href="#mergereturn-unify-function-exit-nodes" id="id86"><tt class="docutils literal"><span class="pre">-mergereturn</span></tt>: Unify function exit nodes</a></li>
+<li><a class="reference internal" href="#partial-inliner-partial-inliner" id="id87"><tt class="docutils literal"><span class="pre">-partial-inliner</span></tt>: Partial Inliner</a></li>
+<li><a class="reference internal" href="#prune-eh-remove-unused-exception-handling-info" id="id88"><tt class="docutils literal"><span class="pre">-prune-eh</span></tt>: Remove unused exception handling info</a></li>
+<li><a class="reference internal" href="#reassociate-reassociate-expressions" id="id89"><tt class="docutils literal"><span class="pre">-reassociate</span></tt>: Reassociate expressions</a></li>
+<li><a class="reference internal" href="#reg2mem-demote-all-values-to-stack-slots" id="id90"><tt class="docutils literal"><span class="pre">-reg2mem</span></tt>: Demote all values to stack slots</a></li>
+<li><a class="reference internal" href="#scalarrepl-scalar-replacement-of-aggregates-dt" id="id91"><tt class="docutils literal"><span class="pre">-scalarrepl</span></tt>: Scalar Replacement of Aggregates (DT)</a></li>
+<li><a class="reference internal" href="#sccp-sparse-conditional-constant-propagation" id="id92"><tt class="docutils literal"><span class="pre">-sccp</span></tt>: Sparse Conditional Constant Propagation</a></li>
+<li><a class="reference internal" href="#simplifycfg-simplify-the-cfg" id="id93"><tt class="docutils literal"><span class="pre">-simplifycfg</span></tt>: Simplify the CFG</a></li>
+<li><a class="reference internal" href="#sink-code-sinking" id="id94"><tt class="docutils literal"><span class="pre">-sink</span></tt>: Code sinking</a></li>
+<li><a class="reference internal" href="#strip-strip-all-symbols-from-a-module" id="id95"><tt class="docutils literal"><span class="pre">-strip</span></tt>: Strip all symbols from a module</a></li>
+<li><a class="reference internal" href="#strip-dead-debug-info-strip-debug-info-for-unused-symbols" id="id96"><tt class="docutils literal"><span class="pre">-strip-dead-debug-info</span></tt>: Strip debug info for unused symbols</a></li>
+<li><a class="reference internal" href="#strip-dead-prototypes-strip-unused-function-prototypes" id="id97"><tt class="docutils literal"><span class="pre">-strip-dead-prototypes</span></tt>: Strip Unused Function Prototypes</a></li>
+<li><a class="reference internal" href="#strip-debug-declare-strip-all-llvm-dbg-declare-intrinsics" id="id98"><tt class="docutils literal"><span class="pre">-strip-debug-declare</span></tt>: Strip all <tt class="docutils literal"><span class="pre">llvm.dbg.declare</span></tt> intrinsics</a></li>
+<li><a class="reference internal" href="#strip-nondebug-strip-all-symbols-except-dbg-symbols-from-a-module" id="id99"><tt class="docutils literal"><span class="pre">-strip-nondebug</span></tt>: Strip all symbols, except dbg symbols, from a module</a></li>
+<li><a class="reference internal" href="#tailcallelim-tail-call-elimination" id="id100"><tt class="docutils literal"><span class="pre">-tailcallelim</span></tt>: Tail Call Elimination</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#utility-passes" id="id101">Utility Passes</a><ul>
+<li><a class="reference internal" href="#deadarghax0r-dead-argument-hacking-bugpoint-use-only-do-not-use" id="id102"><tt class="docutils literal"><span class="pre">-deadarghaX0r</span></tt>: Dead Argument Hacking (BUGPOINT USE ONLY; DO NOT USE)</a></li>
+<li><a class="reference internal" href="#extract-blocks-extract-basic-blocks-from-module-for-bugpoint-use" id="id103"><tt class="docutils literal"><span class="pre">-extract-blocks</span></tt>: Extract Basic Blocks From Module (for bugpoint use)</a></li>
+<li><a class="reference internal" href="#instnamer-assign-names-to-anonymous-instructions" id="id104"><tt class="docutils literal"><span class="pre">-instnamer</span></tt>: Assign names to anonymous instructions</a></li>
+<li><a class="reference internal" href="#verify-module-verifier" id="id105"><tt class="docutils literal"><span class="pre">-verify</span></tt>: Module Verifier</a></li>
+<li><a class="reference internal" href="#view-cfg-view-cfg-of-function" id="id106"><tt class="docutils literal"><span class="pre">-view-cfg</span></tt>: View CFG of function</a></li>
+<li><a class="reference internal" href="#view-cfg-only-view-cfg-of-function-with-no-function-bodies" id="id107"><tt class="docutils literal"><span class="pre">-view-cfg-only</span></tt>: View CFG of function (with no function bodies)</a></li>
+<li><a class="reference internal" href="#view-dom-view-dominance-tree-of-function" id="id108"><tt class="docutils literal"><span class="pre">-view-dom</span></tt>: View dominance tree of function</a></li>
+<li><a class="reference internal" href="#view-dom-only-view-dominance-tree-of-function-with-no-function-bodies" id="id109"><tt class="docutils literal"><span class="pre">-view-dom-only</span></tt>: View dominance tree of function (with no function bodies)</a></li>
+<li><a class="reference internal" href="#view-postdom-view-postdominance-tree-of-function" id="id110"><tt class="docutils literal"><span class="pre">-view-postdom</span></tt>: View postdominance tree of function</a></li>
+<li><a class="reference internal" href="#view-postdom-only-view-postdominance-tree-of-function-with-no-function-bodies" id="id111"><tt class="docutils literal"><span class="pre">-view-postdom-only</span></tt>: View postdominance tree of function (with no function bodies)</a></li>
+</ul>
+</li>
+</ul>
+</div>
+<div class="section" id="introduction">
+<h2><a class="toc-backref" href="#id1">Introduction</a><a class="headerlink" href="#introduction" title="Permalink to this headline">¶</a></h2>
+<p>This document serves as a high level summary of the optimization features that
+LLVM provides. Optimizations are implemented as Passes that traverse some
+portion of a program to either collect information or transform the program.
+The table below divides the passes that LLVM provides into three categories.
+Analysis passes compute information that other passes can use or for debugging
+or program visualization purposes. Transform passes can use (or invalidate)
+the analysis passes. Transform passes all mutate the program in some way.
+Utility passes provides some utility but don’t otherwise fit categorization.
+For example passes to extract functions to bitcode or write a module to bitcode
+are neither analysis nor transform passes. The table of contents above
+provides a quick summary of each pass and links to the more complete pass
+description later in the document.</p>
+</div>
+<div class="section" id="analysis-passes">
+<h2><a class="toc-backref" href="#id2">Analysis Passes</a><a class="headerlink" href="#analysis-passes" title="Permalink to this headline">¶</a></h2>
+<p>This section describes the LLVM Analysis Passes.</p>
+<div class="section" id="aa-eval-exhaustive-alias-analysis-precision-evaluator">
+<h3><a class="toc-backref" href="#id3"><tt class="docutils literal"><span class="pre">-aa-eval</span></tt>: Exhaustive Alias Analysis Precision Evaluator</a><a class="headerlink" href="#aa-eval-exhaustive-alias-analysis-precision-evaluator" title="Permalink to this headline">¶</a></h3>
+<p>This is a simple N^2 alias analysis accuracy evaluator. Basically, for each
+function in the program, it simply queries to see how the alias analysis
+implementation answers alias queries between each pair of pointers in the
+function.</p>
+<p>This is inspired and adapted from code by: Naveen Neelakantam, Francesco
+Spadini, and Wojciech Stryjewski.</p>
+</div>
+<div class="section" id="basicaa-basic-alias-analysis-stateless-aa-impl">
+<h3><a class="toc-backref" href="#id4"><tt class="docutils literal"><span class="pre">-basicaa</span></tt>: Basic Alias Analysis (stateless AA impl)</a><a class="headerlink" href="#basicaa-basic-alias-analysis-stateless-aa-impl" title="Permalink to this headline">¶</a></h3>
+<p>A basic alias analysis pass that implements identities (two different globals
+cannot alias, etc), but does no stateful analysis.</p>
+</div>
+<div class="section" id="basiccg-basic-callgraph-construction">
+<h3><a class="toc-backref" href="#id5"><tt class="docutils literal"><span class="pre">-basiccg</span></tt>: Basic CallGraph Construction</a><a class="headerlink" href="#basiccg-basic-callgraph-construction" title="Permalink to this headline">¶</a></h3>
+<p>Yet to be written.</p>
+</div>
+<div class="section" id="count-aa-count-alias-analysis-query-responses">
+<h3><a class="toc-backref" href="#id6"><tt class="docutils literal"><span class="pre">-count-aa</span></tt>: Count Alias Analysis Query Responses</a><a class="headerlink" href="#count-aa-count-alias-analysis-query-responses" title="Permalink to this headline">¶</a></h3>
+<p>A pass which can be used to count how many alias queries are being made and how
+the alias analysis implementation being used responds.</p>
+</div>
+<div class="section" id="da-dependence-analysis">
+<h3><a class="toc-backref" href="#id7"><tt class="docutils literal"><span class="pre">-da</span></tt>: Dependence Analysis</a><a class="headerlink" href="#da-dependence-analysis" title="Permalink to this headline">¶</a></h3>
+<p>Dependence analysis framework, which is used to detect dependences in memory
+accesses.</p>
+</div>
+<div class="section" id="debug-aa-aa-use-debugger">
+<h3><a class="toc-backref" href="#id8"><tt class="docutils literal"><span class="pre">-debug-aa</span></tt>: AA use debugger</a><a class="headerlink" href="#debug-aa-aa-use-debugger" title="Permalink to this headline">¶</a></h3>
+<p>This simple pass checks alias analysis users to ensure that if they create a
+new value, they do not query AA without informing it of the value. It acts as
+a shim over any other AA pass you want.</p>
+<p>Yes keeping track of every value in the program is expensive, but this is a
+debugging pass.</p>
+</div>
+<div class="section" id="domfrontier-dominance-frontier-construction">
+<h3><a class="toc-backref" href="#id9"><tt class="docutils literal"><span class="pre">-domfrontier</span></tt>: Dominance Frontier Construction</a><a class="headerlink" href="#domfrontier-dominance-frontier-construction" title="Permalink to this headline">¶</a></h3>
+<p>This pass is a simple dominator construction algorithm for finding forward
+dominator frontiers.</p>
+</div>
+<div class="section" id="domtree-dominator-tree-construction">
+<h3><a class="toc-backref" href="#id10"><tt class="docutils literal"><span class="pre">-domtree</span></tt>: Dominator Tree Construction</a><a class="headerlink" href="#domtree-dominator-tree-construction" title="Permalink to this headline">¶</a></h3>
+<p>This pass is a simple dominator construction algorithm for finding forward
+dominators.</p>
+</div>
+<div class="section" id="dot-callgraph-print-call-graph-to-dot-file">
+<h3><a class="toc-backref" href="#id11"><tt class="docutils literal"><span class="pre">-dot-callgraph</span></tt>: Print Call Graph to “dot” file</a><a class="headerlink" href="#dot-callgraph-print-call-graph-to-dot-file" title="Permalink to this headline">¶</a></h3>
+<p>This pass, only available in <tt class="docutils literal"><span class="pre">opt</span></tt>, prints the call graph into a <tt class="docutils literal"><span class="pre">.dot</span></tt>
+graph. This graph can then be processed with the “dot” tool to convert it to
+postscript or some other suitable format.</p>
+</div>
+<div class="section" id="dot-cfg-print-cfg-of-function-to-dot-file">
+<h3><a class="toc-backref" href="#id12"><tt class="docutils literal"><span class="pre">-dot-cfg</span></tt>: Print CFG of function to “dot” file</a><a class="headerlink" href="#dot-cfg-print-cfg-of-function-to-dot-file" title="Permalink to this headline">¶</a></h3>
+<p>This pass, only available in <tt class="docutils literal"><span class="pre">opt</span></tt>, prints the control flow graph into a
+<tt class="docutils literal"><span class="pre">.dot</span></tt> graph. This graph can then be processed with the <strong class="program">dot</strong> tool
+to convert it to postscript or some other suitable format.</p>
+</div>
+<div class="section" id="dot-cfg-only-print-cfg-of-function-to-dot-file-with-no-function-bodies">
+<h3><a class="toc-backref" href="#id13"><tt class="docutils literal"><span class="pre">-dot-cfg-only</span></tt>: Print CFG of function to “dot” file (with no function bodies)</a><a class="headerlink" href="#dot-cfg-only-print-cfg-of-function-to-dot-file-with-no-function-bodies" title="Permalink to this headline">¶</a></h3>
+<p>This pass, only available in <tt class="docutils literal"><span class="pre">opt</span></tt>, prints the control flow graph into a
+<tt class="docutils literal"><span class="pre">.dot</span></tt> graph, omitting the function bodies. This graph can then be processed
+with the <strong class="program">dot</strong> tool to convert it to postscript or some other suitable
+format.</p>
+</div>
+<div class="section" id="dot-dom-print-dominance-tree-of-function-to-dot-file">
+<h3><a class="toc-backref" href="#id14"><tt class="docutils literal"><span class="pre">-dot-dom</span></tt>: Print dominance tree of function to “dot” file</a><a class="headerlink" href="#dot-dom-print-dominance-tree-of-function-to-dot-file" title="Permalink to this headline">¶</a></h3>
+<p>This pass, only available in <tt class="docutils literal"><span class="pre">opt</span></tt>, prints the dominator tree into a <tt class="docutils literal"><span class="pre">.dot</span></tt>
+graph. This graph can then be processed with the <strong class="program">dot</strong> tool to
+convert it to postscript or some other suitable format.</p>
+</div>
+<div class="section" id="dot-dom-only-print-dominance-tree-of-function-to-dot-file-with-no-function-bodies">
+<h3><a class="toc-backref" href="#id15"><tt class="docutils literal"><span class="pre">-dot-dom-only</span></tt>: Print dominance tree of function to “dot” file (with no function bodies)</a><a class="headerlink" href="#dot-dom-only-print-dominance-tree-of-function-to-dot-file-with-no-function-bodies" title="Permalink to this headline">¶</a></h3>
+<p>This pass, only available in <tt class="docutils literal"><span class="pre">opt</span></tt>, prints the dominator tree into a <tt class="docutils literal"><span class="pre">.dot</span></tt>
+graph, omitting the function bodies. This graph can then be processed with the
+<strong class="program">dot</strong> tool to convert it to postscript or some other suitable format.</p>
+</div>
+<div class="section" id="dot-postdom-print-postdominance-tree-of-function-to-dot-file">
+<h3><a class="toc-backref" href="#id16"><tt class="docutils literal"><span class="pre">-dot-postdom</span></tt>: Print postdominance tree of function to “dot” file</a><a class="headerlink" href="#dot-postdom-print-postdominance-tree-of-function-to-dot-file" title="Permalink to this headline">¶</a></h3>
+<p>This pass, only available in <tt class="docutils literal"><span class="pre">opt</span></tt>, prints the post dominator tree into a
+<tt class="docutils literal"><span class="pre">.dot</span></tt> graph. This graph can then be processed with the <strong class="program">dot</strong> tool
+to convert it to postscript or some other suitable format.</p>
+</div>
+<div class="section" id="dot-postdom-only-print-postdominance-tree-of-function-to-dot-file-with-no-function-bodies">
+<h3><a class="toc-backref" href="#id17"><tt class="docutils literal"><span class="pre">-dot-postdom-only</span></tt>: Print postdominance tree of function to “dot” file (with no function bodies)</a><a class="headerlink" href="#dot-postdom-only-print-postdominance-tree-of-function-to-dot-file-with-no-function-bodies" title="Permalink to this headline">¶</a></h3>
+<p>This pass, only available in <tt class="docutils literal"><span class="pre">opt</span></tt>, prints the post dominator tree into a
+<tt class="docutils literal"><span class="pre">.dot</span></tt> graph, omitting the function bodies. This graph can then be processed
+with the <strong class="program">dot</strong> tool to convert it to postscript or some other suitable
+format.</p>
+</div>
+<div class="section" id="globalsmodref-aa-simple-mod-ref-analysis-for-globals">
+<h3><a class="toc-backref" href="#id18"><tt class="docutils literal"><span class="pre">-globalsmodref-aa</span></tt>: Simple mod/ref analysis for globals</a><a class="headerlink" href="#globalsmodref-aa-simple-mod-ref-analysis-for-globals" title="Permalink to this headline">¶</a></h3>
+<p>This simple pass provides alias and mod/ref information for global values that
+do not have their address taken, and keeps track of whether functions read or
+write memory (are “pure”). For this simple (but very common) case, we can
+provide pretty accurate and useful information.</p>
+</div>
+<div class="section" id="instcount-counts-the-various-types-of-instructions">
+<h3><a class="toc-backref" href="#id19"><tt class="docutils literal"><span class="pre">-instcount</span></tt>: Counts the various types of <tt class="docutils literal"><span class="pre">Instruction</span></tt>s</a><a class="headerlink" href="#instcount-counts-the-various-types-of-instructions" title="Permalink to this headline">¶</a></h3>
+<p>This pass collects the count of all instructions and reports them.</p>
+</div>
+<div class="section" id="intervals-interval-partition-construction">
+<h3><a class="toc-backref" href="#id20"><tt class="docutils literal"><span class="pre">-intervals</span></tt>: Interval Partition Construction</a><a class="headerlink" href="#intervals-interval-partition-construction" title="Permalink to this headline">¶</a></h3>
+<p>This analysis calculates and represents the interval partition of a function,
+or a preexisting interval partition.</p>
+<p>In this way, the interval partition may be used to reduce a flow graph down to
+its degenerate single node interval partition (unless it is irreducible).</p>
+</div>
+<div class="section" id="iv-users-induction-variable-users">
+<h3><a class="toc-backref" href="#id21"><tt class="docutils literal"><span class="pre">-iv-users</span></tt>: Induction Variable Users</a><a class="headerlink" href="#iv-users-induction-variable-users" title="Permalink to this headline">¶</a></h3>
+<p>Bookkeeping for “interesting” users of expressions computed from induction
+variables.</p>
+</div>
+<div class="section" id="lazy-value-info-lazy-value-information-analysis">
+<h3><a class="toc-backref" href="#id22"><tt class="docutils literal"><span class="pre">-lazy-value-info</span></tt>: Lazy Value Information Analysis</a><a class="headerlink" href="#lazy-value-info-lazy-value-information-analysis" title="Permalink to this headline">¶</a></h3>
+<p>Interface for lazy computation of value constraint information.</p>
+</div>
+<div class="section" id="libcall-aa-libcall-alias-analysis">
+<h3><a class="toc-backref" href="#id23"><tt class="docutils literal"><span class="pre">-libcall-aa</span></tt>: LibCall Alias Analysis</a><a class="headerlink" href="#libcall-aa-libcall-alias-analysis" title="Permalink to this headline">¶</a></h3>
+<p>LibCall Alias Analysis.</p>
+</div>
+<div class="section" id="lint-statically-lint-checks-llvm-ir">
+<h3><a class="toc-backref" href="#id24"><tt class="docutils literal"><span class="pre">-lint</span></tt>: Statically lint-checks LLVM IR</a><a class="headerlink" href="#lint-statically-lint-checks-llvm-ir" title="Permalink to this headline">¶</a></h3>
+<p>This pass statically checks for common and easily-identified constructs which
+produce undefined or likely unintended behavior in LLVM IR.</p>
+<p>It is not a guarantee of correctness, in two ways. First, it isn’t
+comprehensive. There are checks which could be done statically which are not
+yet implemented. Some of these are indicated by TODO comments, but those
+aren’t comprehensive either. Second, many conditions cannot be checked
+statically. This pass does no dynamic instrumentation, so it can’t check for
+all possible problems.</p>
+<p>Another limitation is that it assumes all code will be executed. A store
+through a null pointer in a basic block which is never reached is harmless, but
+this pass will warn about it anyway.</p>
+<p>Optimization passes may make conditions that this pass checks for more or less
+obvious. If an optimization pass appears to be introducing a warning, it may
+be that the optimization pass is merely exposing an existing condition in the
+code.</p>
+<p>This code may be run before <a class="reference internal" href="#passes-instcombine"><em>instcombine</em></a>. In many
+cases, instcombine checks for the same kinds of things and turns instructions
+with undefined behavior into unreachable (or equivalent). Because of this,
+this pass makes some effort to look through bitcasts and so on.</p>
+</div>
+<div class="section" id="loops-natural-loop-information">
+<h3><a class="toc-backref" href="#id25"><tt class="docutils literal"><span class="pre">-loops</span></tt>: Natural Loop Information</a><a class="headerlink" href="#loops-natural-loop-information" title="Permalink to this headline">¶</a></h3>
+<p>This analysis is used to identify natural loops and determine the loop depth of
+various nodes of the CFG. Note that the loops identified may actually be
+several natural loops that share the same header node... not just a single
+natural loop.</p>
+</div>
+<div class="section" id="memdep-memory-dependence-analysis">
+<h3><a class="toc-backref" href="#id26"><tt class="docutils literal"><span class="pre">-memdep</span></tt>: Memory Dependence Analysis</a><a class="headerlink" href="#memdep-memory-dependence-analysis" title="Permalink to this headline">¶</a></h3>
+<p>An analysis that determines, for a given memory operation, what preceding
+memory operations it depends on. It builds on alias analysis information, and
+tries to provide a lazy, caching interface to a common kind of alias
+information query.</p>
+</div>
+<div class="section" id="module-debuginfo-decodes-module-level-debug-info">
+<h3><a class="toc-backref" href="#id27"><tt class="docutils literal"><span class="pre">-module-debuginfo</span></tt>: Decodes module-level debug info</a><a class="headerlink" href="#module-debuginfo-decodes-module-level-debug-info" title="Permalink to this headline">¶</a></h3>
+<p>This pass decodes the debug info metadata in a module and prints in a
+(sufficiently-prepared-) human-readable form.</p>
+<p>For example, run this pass from <tt class="docutils literal"><span class="pre">opt</span></tt> along with the <tt class="docutils literal"><span class="pre">-analyze</span></tt> option, and
+it’ll print to standard output.</p>
+</div>
+<div class="section" id="no-aa-no-alias-analysis-always-returns-may-alias">
+<h3><a class="toc-backref" href="#id28"><tt class="docutils literal"><span class="pre">-no-aa</span></tt>: No Alias Analysis (always returns ‘may’ alias)</a><a class="headerlink" href="#no-aa-no-alias-analysis-always-returns-may-alias" title="Permalink to this headline">¶</a></h3>
+<p>This is the default implementation of the Alias Analysis interface. It always
+returns “I don’t know” for alias queries. NoAA is unlike other alias analysis
+implementations, in that it does not chain to a previous analysis. As such it
+doesn’t follow many of the rules that other alias analyses must.</p>
+</div>
+<div class="section" id="postdomfrontier-post-dominance-frontier-construction">
+<h3><a class="toc-backref" href="#id29"><tt class="docutils literal"><span class="pre">-postdomfrontier</span></tt>: Post-Dominance Frontier Construction</a><a class="headerlink" href="#postdomfrontier-post-dominance-frontier-construction" title="Permalink to this headline">¶</a></h3>
+<p>This pass is a simple post-dominator construction algorithm for finding
+post-dominator frontiers.</p>
+</div>
+<div class="section" id="postdomtree-post-dominator-tree-construction">
+<h3><a class="toc-backref" href="#id30"><tt class="docutils literal"><span class="pre">-postdomtree</span></tt>: Post-Dominator Tree Construction</a><a class="headerlink" href="#postdomtree-post-dominator-tree-construction" title="Permalink to this headline">¶</a></h3>
+<p>This pass is a simple post-dominator construction algorithm for finding
+post-dominators.</p>
+</div>
+<div class="section" id="print-alias-sets-alias-set-printer">
+<h3><a class="toc-backref" href="#id31"><tt class="docutils literal"><span class="pre">-print-alias-sets</span></tt>: Alias Set Printer</a><a class="headerlink" href="#print-alias-sets-alias-set-printer" title="Permalink to this headline">¶</a></h3>
+<p>Yet to be written.</p>
+</div>
+<div class="section" id="print-callgraph-print-a-call-graph">
+<h3><a class="toc-backref" href="#id32"><tt class="docutils literal"><span class="pre">-print-callgraph</span></tt>: Print a call graph</a><a class="headerlink" href="#print-callgraph-print-a-call-graph" title="Permalink to this headline">¶</a></h3>
+<p>This pass, only available in <tt class="docutils literal"><span class="pre">opt</span></tt>, prints the call graph to standard error
+in a human-readable form.</p>
+</div>
+<div class="section" id="print-callgraph-sccs-print-sccs-of-the-call-graph">
+<h3><a class="toc-backref" href="#id33"><tt class="docutils literal"><span class="pre">-print-callgraph-sccs</span></tt>: Print SCCs of the Call Graph</a><a class="headerlink" href="#print-callgraph-sccs-print-sccs-of-the-call-graph" title="Permalink to this headline">¶</a></h3>
+<p>This pass, only available in <tt class="docutils literal"><span class="pre">opt</span></tt>, prints the SCCs of the call graph to
+standard error in a human-readable form.</p>
+</div>
+<div class="section" id="print-cfg-sccs-print-sccs-of-each-function-cfg">
+<h3><a class="toc-backref" href="#id34"><tt class="docutils literal"><span class="pre">-print-cfg-sccs</span></tt>: Print SCCs of each function CFG</a><a class="headerlink" href="#print-cfg-sccs-print-sccs-of-each-function-cfg" title="Permalink to this headline">¶</a></h3>
+<p>This pass, only available in <tt class="docutils literal"><span class="pre">opt</span></tt>, printsthe SCCs of each function CFG to
+standard error in a human-readable fom.</p>
+</div>
+<div class="section" id="print-dom-info-dominator-info-printer">
+<h3><a class="toc-backref" href="#id35"><tt class="docutils literal"><span class="pre">-print-dom-info</span></tt>: Dominator Info Printer</a><a class="headerlink" href="#print-dom-info-dominator-info-printer" title="Permalink to this headline">¶</a></h3>
+<p>Dominator Info Printer.</p>
+</div>
+<div class="section" id="print-externalfnconstants-print-external-fn-callsites-passed-constants">
+<h3><a class="toc-backref" href="#id36"><tt class="docutils literal"><span class="pre">-print-externalfnconstants</span></tt>: Print external fn callsites passed constants</a><a class="headerlink" href="#print-externalfnconstants-print-external-fn-callsites-passed-constants" title="Permalink to this headline">¶</a></h3>
+<p>This pass, only available in <tt class="docutils literal"><span class="pre">opt</span></tt>, prints out call sites to external
+functions that are called with constant arguments. This can be useful when
+looking for standard library functions we should constant fold or handle in
+alias analyses.</p>
+</div>
+<div class="section" id="print-function-print-function-to-stderr">
+<h3><a class="toc-backref" href="#id37"><tt class="docutils literal"><span class="pre">-print-function</span></tt>: Print function to stderr</a><a class="headerlink" href="#print-function-print-function-to-stderr" title="Permalink to this headline">¶</a></h3>
+<p>The <tt class="docutils literal"><span class="pre">PrintFunctionPass</span></tt> class is designed to be pipelined with other
+<tt class="docutils literal"><span class="pre">FunctionPasses</span></tt>, and prints out the functions of the module as they are
+processed.</p>
+</div>
+<div class="section" id="print-module-print-module-to-stderr">
+<h3><a class="toc-backref" href="#id38"><tt class="docutils literal"><span class="pre">-print-module</span></tt>: Print module to stderr</a><a class="headerlink" href="#print-module-print-module-to-stderr" title="Permalink to this headline">¶</a></h3>
+<p>This pass simply prints out the entire module when it is executed.</p>
+</div>
+<div class="section" id="print-used-types-find-used-types">
+<span id="passes-print-used-types"></span><h3><a class="toc-backref" href="#id39"><tt class="docutils literal"><span class="pre">-print-used-types</span></tt>: Find Used Types</a><a class="headerlink" href="#print-used-types-find-used-types" title="Permalink to this headline">¶</a></h3>
+<p>This pass is used to seek out all of the types in use by the program. Note
+that this analysis explicitly does not include types only used by the symbol
+table.</p>
+</div>
+<div class="section" id="regions-detect-single-entry-single-exit-regions">
+<h3><a class="toc-backref" href="#id40"><tt class="docutils literal"><span class="pre">-regions</span></tt>: Detect single entry single exit regions</a><a class="headerlink" href="#regions-detect-single-entry-single-exit-regions" title="Permalink to this headline">¶</a></h3>
+<p>The <tt class="docutils literal"><span class="pre">RegionInfo</span></tt> pass detects single entry single exit regions in a function,
+where a region is defined as any subgraph that is connected to the remaining
+graph at only two spots. Furthermore, an hierarchical region tree is built.</p>
+</div>
+<div class="section" id="scalar-evolution-scalar-evolution-analysis">
+<h3><a class="toc-backref" href="#id41"><tt class="docutils literal"><span class="pre">-scalar-evolution</span></tt>: Scalar Evolution Analysis</a><a class="headerlink" href="#scalar-evolution-scalar-evolution-analysis" title="Permalink to this headline">¶</a></h3>
+<p>The <tt class="docutils literal"><span class="pre">ScalarEvolution</span></tt> analysis can be used to analyze and catagorize scalar
+expressions in loops. It specializes in recognizing general induction
+variables, representing them with the abstract and opaque <tt class="docutils literal"><span class="pre">SCEV</span></tt> class.
+Given this analysis, trip counts of loops and other important properties can be
+obtained.</p>
+<p>This analysis is primarily useful for induction variable substitution and
+strength reduction.</p>
+</div>
+<div class="section" id="scev-aa-scalarevolution-based-alias-analysis">
+<h3><a class="toc-backref" href="#id42"><tt class="docutils literal"><span class="pre">-scev-aa</span></tt>: ScalarEvolution-based Alias Analysis</a><a class="headerlink" href="#scev-aa-scalarevolution-based-alias-analysis" title="Permalink to this headline">¶</a></h3>
+<p>Simple alias analysis implemented in terms of <tt class="docutils literal"><span class="pre">ScalarEvolution</span></tt> queries.</p>
+<p>This differs from traditional loop dependence analysis in that it tests for
+dependencies within a single iteration of a loop, rather than dependencies
+between different iterations.</p>
+<p><tt class="docutils literal"><span class="pre">ScalarEvolution</span></tt> has a more complete understanding of pointer arithmetic
+than <tt class="docutils literal"><span class="pre">BasicAliasAnalysis</span></tt>‘ collection of ad-hoc analyses.</p>
+</div>
+<div class="section" id="targetdata-target-data-layout">
+<h3><a class="toc-backref" href="#id43"><tt class="docutils literal"><span class="pre">-targetdata</span></tt>: Target Data Layout</a><a class="headerlink" href="#targetdata-target-data-layout" title="Permalink to this headline">¶</a></h3>
+<p>Provides other passes access to information on how the size and alignment
+required by the target ABI for various data types.</p>
+</div>
+</div>
+<div class="section" id="transform-passes">
+<h2><a class="toc-backref" href="#id44">Transform Passes</a><a class="headerlink" href="#transform-passes" title="Permalink to this headline">¶</a></h2>
+<p>This section describes the LLVM Transform Passes.</p>
+<div class="section" id="adce-aggressive-dead-code-elimination">
+<h3><a class="toc-backref" href="#id45"><tt class="docutils literal"><span class="pre">-adce</span></tt>: Aggressive Dead Code Elimination</a><a class="headerlink" href="#adce-aggressive-dead-code-elimination" title="Permalink to this headline">¶</a></h3>
+<p>ADCE aggressively tries to eliminate code. This pass is similar to <a class="reference internal" href="#passes-dce"><em>DCE</em></a> but it assumes that values are dead until proven otherwise. This
+is similar to <a class="reference internal" href="#passes-sccp"><em>SCCP</em></a>, except applied to the liveness of
+values.</p>
+</div>
+<div class="section" id="always-inline-inliner-for-always-inline-functions">
+<h3><a class="toc-backref" href="#id46"><tt class="docutils literal"><span class="pre">-always-inline</span></tt>: Inliner for <tt class="docutils literal"><span class="pre">always_inline</span></tt> functions</a><a class="headerlink" href="#always-inline-inliner-for-always-inline-functions" title="Permalink to this headline">¶</a></h3>
+<p>A custom inliner that handles only functions that are marked as “always
+inline”.</p>
+</div>
+<div class="section" id="argpromotion-promote-by-reference-arguments-to-scalars">
+<h3><a class="toc-backref" href="#id47"><tt class="docutils literal"><span class="pre">-argpromotion</span></tt>: Promote ‘by reference’ arguments to scalars</a><a class="headerlink" href="#argpromotion-promote-by-reference-arguments-to-scalars" title="Permalink to this headline">¶</a></h3>
+<p>This pass promotes “by reference” arguments to be “by value” arguments. In
+practice, this means looking for internal functions that have pointer
+arguments. If it can prove, through the use of alias analysis, that an
+argument is <em>only</em> loaded, then it can pass the value into the function instead
+of the address of the value. This can cause recursive simplification of code
+and lead to the elimination of allocas (especially in C++ template code like
+the STL).</p>
+<p>This pass also handles aggregate arguments that are passed into a function,
+scalarizing them if the elements of the aggregate are only loaded. Note that
+it refuses to scalarize aggregates which would require passing in more than
+three operands to the function, because passing thousands of operands for a
+large array or structure is unprofitable!</p>
+<p>Note that this transformation could also be done for arguments that are only
+stored to (returning the value instead), but does not currently. This case
+would be best handled when and if LLVM starts supporting multiple return values
+from functions.</p>
+</div>
+<div class="section" id="bb-vectorize-basic-block-vectorization">
+<h3><a class="toc-backref" href="#id48"><tt class="docutils literal"><span class="pre">-bb-vectorize</span></tt>: Basic-Block Vectorization</a><a class="headerlink" href="#bb-vectorize-basic-block-vectorization" title="Permalink to this headline">¶</a></h3>
+<p>This pass combines instructions inside basic blocks to form vector
+instructions. It iterates over each basic block, attempting to pair compatible
+instructions, repeating this process until no additional pairs are selected for
+vectorization. When the outputs of some pair of compatible instructions are
+used as inputs by some other pair of compatible instructions, those pairs are
+part of a potential vectorization chain. Instruction pairs are only fused into
+vector instructions when they are part of a chain longer than some threshold
+length. Moreover, the pass attempts to find the best possible chain for each
+pair of compatible instructions. These heuristics are intended to prevent
+vectorization in cases where it would not yield a performance increase of the
+resulting code.</p>
+</div>
+<div class="section" id="block-placement-profile-guided-basic-block-placement">
+<h3><a class="toc-backref" href="#id49"><tt class="docutils literal"><span class="pre">-block-placement</span></tt>: Profile Guided Basic Block Placement</a><a class="headerlink" href="#block-placement-profile-guided-basic-block-placement" title="Permalink to this headline">¶</a></h3>
+<p>This pass is a very simple profile guided basic block placement algorithm. The
+idea is to put frequently executed blocks together at the start of the function
+and hopefully increase the number of fall-through conditional branches. If
+there is no profile information for a particular function, this pass basically
+orders blocks in depth-first order.</p>
+</div>
+<div class="section" id="break-crit-edges-break-critical-edges-in-cfg">
+<h3><a class="toc-backref" href="#id50"><tt class="docutils literal"><span class="pre">-break-crit-edges</span></tt>: Break critical edges in CFG</a><a class="headerlink" href="#break-crit-edges-break-critical-edges-in-cfg" title="Permalink to this headline">¶</a></h3>
+<p>Break all of the critical edges in the CFG by inserting a dummy basic block.
+It may be “required” by passes that cannot deal with critical edges. This
+transformation obviously invalidates the CFG, but can update forward dominator
+(set, immediate dominators, tree, and frontier) information.</p>
+</div>
+<div class="section" id="codegenprepare-optimize-for-code-generation">
+<h3><a class="toc-backref" href="#id51"><tt class="docutils literal"><span class="pre">-codegenprepare</span></tt>: Optimize for code generation</a><a class="headerlink" href="#codegenprepare-optimize-for-code-generation" title="Permalink to this headline">¶</a></h3>
+<p>This pass munges the code in the input function to better prepare it for
+SelectionDAG-based code generation. This works around limitations in its
+basic-block-at-a-time approach. It should eventually be removed.</p>
+</div>
+<div class="section" id="constmerge-merge-duplicate-global-constants">
+<h3><a class="toc-backref" href="#id52"><tt class="docutils literal"><span class="pre">-constmerge</span></tt>: Merge Duplicate Global Constants</a><a class="headerlink" href="#constmerge-merge-duplicate-global-constants" title="Permalink to this headline">¶</a></h3>
+<p>Merges duplicate global constants together into a single constant that is
+shared. This is useful because some passes (i.e., TraceValues) insert a lot of
+string constants into the program, regardless of whether or not an existing
+string is available.</p>
+</div>
+<div class="section" id="constprop-simple-constant-propagation">
+<h3><a class="toc-backref" href="#id53"><tt class="docutils literal"><span class="pre">-constprop</span></tt>: Simple constant propagation</a><a class="headerlink" href="#constprop-simple-constant-propagation" title="Permalink to this headline">¶</a></h3>
+<p>This pass implements constant propagation and merging. It looks for
+instructions involving only constant operands and replaces them with a constant
+value instead of an instruction. For example:</p>
+<div class="highlight-llvm"><div class="highlight"><pre><span class="k">add</span> <span class="k">i32</span> <span class="m">1</span><span class="p">,</span> <span class="m">2</span>
+</pre></div>
+</div>
+<p>becomes</p>
+<div class="highlight-llvm"><div class="highlight"><pre><span class="k">i32</span> <span class="m">3</span>
+</pre></div>
+</div>
+<p>NOTE: this pass has a habit of making definitions be dead. It is a good idea
+to run a <a class="reference internal" href="#passes-die"><em>Dead Instruction Elimination</em></a> pass sometime after
+running this pass.</p>
+</div>
+<div class="section" id="dce-dead-code-elimination">
+<span id="passes-dce"></span><h3><a class="toc-backref" href="#id54"><tt class="docutils literal"><span class="pre">-dce</span></tt>: Dead Code Elimination</a><a class="headerlink" href="#dce-dead-code-elimination" title="Permalink to this headline">¶</a></h3>
+<p>Dead code elimination is similar to <a class="reference internal" href="#passes-die"><em>dead instruction elimination</em></a>, but it rechecks instructions that were used by removed
+instructions to see if they are newly dead.</p>
+</div>
+<div class="section" id="deadargelim-dead-argument-elimination">
+<h3><a class="toc-backref" href="#id55"><tt class="docutils literal"><span class="pre">-deadargelim</span></tt>: Dead Argument Elimination</a><a class="headerlink" href="#deadargelim-dead-argument-elimination" title="Permalink to this headline">¶</a></h3>
+<p>This pass deletes dead arguments from internal functions. Dead argument
+elimination removes arguments which are directly dead, as well as arguments
+only passed into function calls as dead arguments of other functions. This
+pass also deletes dead arguments in a similar way.</p>
+<p>This pass is often useful as a cleanup pass to run after aggressive
+interprocedural passes, which add possibly-dead arguments.</p>
+</div>
+<div class="section" id="deadtypeelim-dead-type-elimination">
+<h3><a class="toc-backref" href="#id56"><tt class="docutils literal"><span class="pre">-deadtypeelim</span></tt>: Dead Type Elimination</a><a class="headerlink" href="#deadtypeelim-dead-type-elimination" title="Permalink to this headline">¶</a></h3>
+<p>This pass is used to cleanup the output of GCC. It eliminate names for types
+that are unused in the entire translation unit, using the <a class="reference internal" href="#passes-print-used-types"><em>find used types</em></a> pass.</p>
+</div>
+<div class="section" id="die-dead-instruction-elimination">
+<span id="passes-die"></span><h3><a class="toc-backref" href="#id57"><tt class="docutils literal"><span class="pre">-die</span></tt>: Dead Instruction Elimination</a><a class="headerlink" href="#die-dead-instruction-elimination" title="Permalink to this headline">¶</a></h3>
+<p>Dead instruction elimination performs a single pass over the function, removing
+instructions that are obviously dead.</p>
+</div>
+<div class="section" id="dse-dead-store-elimination">
+<h3><a class="toc-backref" href="#id58"><tt class="docutils literal"><span class="pre">-dse</span></tt>: Dead Store Elimination</a><a class="headerlink" href="#dse-dead-store-elimination" title="Permalink to this headline">¶</a></h3>
+<p>A trivial dead store elimination that only considers basic-block local
+redundant stores.</p>
+</div>
+<div class="section" id="functionattrs-deduce-function-attributes">
+<span id="passes-functionattrs"></span><h3><a class="toc-backref" href="#id59"><tt class="docutils literal"><span class="pre">-functionattrs</span></tt>: Deduce function attributes</a><a class="headerlink" href="#functionattrs-deduce-function-attributes" title="Permalink to this headline">¶</a></h3>
+<p>A simple interprocedural pass which walks the call-graph, looking for functions
+which do not access or only read non-local memory, and marking them
+<tt class="docutils literal"><span class="pre">readnone</span></tt>/<tt class="docutils literal"><span class="pre">readonly</span></tt>. In addition, it marks function arguments (of
+pointer type) “<tt class="docutils literal"><span class="pre">nocapture</span></tt>” if a call to the function does not create any
+copies of the pointer value that outlive the call. This more or less means
+that the pointer is only dereferenced, and not returned from the function or
+stored in a global. This pass is implemented as a bottom-up traversal of the
+call-graph.</p>
+</div>
+<div class="section" id="globaldce-dead-global-elimination">
+<h3><a class="toc-backref" href="#id60"><tt class="docutils literal"><span class="pre">-globaldce</span></tt>: Dead Global Elimination</a><a class="headerlink" href="#globaldce-dead-global-elimination" title="Permalink to this headline">¶</a></h3>
+<p>This transform is designed to eliminate unreachable internal globals from the
+program. It uses an aggressive algorithm, searching out globals that are known
+to be alive. After it finds all of the globals which are needed, it deletes
+whatever is left over. This allows it to delete recursive chunks of the
+program which are unreachable.</p>
+</div>
+<div class="section" id="globalopt-global-variable-optimizer">
+<h3><a class="toc-backref" href="#id61"><tt class="docutils literal"><span class="pre">-globalopt</span></tt>: Global Variable Optimizer</a><a class="headerlink" href="#globalopt-global-variable-optimizer" title="Permalink to this headline">¶</a></h3>
+<p>This pass transforms simple global variables that never have their address
+taken. If obviously true, it marks read/write globals as constant, deletes
+variables only stored to, etc.</p>
+</div>
+<div class="section" id="gvn-global-value-numbering">
+<h3><a class="toc-backref" href="#id62"><tt class="docutils literal"><span class="pre">-gvn</span></tt>: Global Value Numbering</a><a class="headerlink" href="#gvn-global-value-numbering" title="Permalink to this headline">¶</a></h3>
+<p>This pass performs global value numbering to eliminate fully and partially
+redundant instructions. It also performs redundant load elimination.</p>
+</div>
+<div class="section" id="indvars-canonicalize-induction-variables">
+<span id="passes-indvars"></span><h3><a class="toc-backref" href="#id63"><tt class="docutils literal"><span class="pre">-indvars</span></tt>: Canonicalize Induction Variables</a><a class="headerlink" href="#indvars-canonicalize-induction-variables" title="Permalink to this headline">¶</a></h3>
+<p>This transformation analyzes and transforms the induction variables (and
+computations derived from them) into simpler forms suitable for subsequent
+analysis and transformation.</p>
+<p>This transformation makes the following changes to each loop with an
+identifiable induction variable:</p>
+<ul class="simple">
+<li>All loops are transformed to have a <em>single</em> canonical induction variable
+which starts at zero and steps by one.</li>
+<li>The canonical induction variable is guaranteed to be the first PHI node in
+the loop header block.</li>
+<li>Any pointer arithmetic recurrences are raised to use array subscripts.</li>
+</ul>
+<p>If the trip count of a loop is computable, this pass also makes the following
+changes:</p>
+<ul>
+<li><p class="first">The exit condition for the loop is canonicalized to compare the induction
+value against the exit value. This turns loops like:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="k">for</span> <span class="p">(</span><span class="n">i</span> <span class="o">=</span> <span class="mi">7</span><span class="p">;</span> <span class="n">i</span><span class="o">*</span><span class="n">i</span> <span class="o"><</span> <span class="mi">1000</span><span class="p">;</span> <span class="o">++</span><span class="n">i</span><span class="p">)</span>
+
+<span class="n">into</span>
+</pre></div>
+</div>
+<div class="highlight-c++"><div class="highlight"><pre><span class="k">for</span> <span class="p">(</span><span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">!=</span> <span class="mi">25</span><span class="p">;</span> <span class="o">++</span><span class="n">i</span><span class="p">)</span>
+</pre></div>
+</div>
+</li>
+<li><p class="first">Any use outside of the loop of an expression derived from the indvar is
+changed to compute the derived value outside of the loop, eliminating the
+dependence on the exit value of the induction variable. If the only purpose
+of the loop is to compute the exit value of some derived expression, this
+transformation will make the loop dead.</p>
+</li>
+</ul>
+<p>This transformation should be followed by strength reduction after all of the
+desired loop transformations have been performed. Additionally, on targets
+where it is profitable, the loop could be transformed to count down to zero
+(the “do loop” optimization).</p>
+</div>
+<div class="section" id="inline-function-integration-inlining">
+<h3><a class="toc-backref" href="#id64"><tt class="docutils literal"><span class="pre">-inline</span></tt>: Function Integration/Inlining</a><a class="headerlink" href="#inline-function-integration-inlining" title="Permalink to this headline">¶</a></h3>
+<p>Bottom-up inlining of functions into callees.</p>
+</div>
+<div class="section" id="instcombine-combine-redundant-instructions">
+<span id="passes-instcombine"></span><h3><a class="toc-backref" href="#id65"><tt class="docutils literal"><span class="pre">-instcombine</span></tt>: Combine redundant instructions</a><a class="headerlink" href="#instcombine-combine-redundant-instructions" title="Permalink to this headline">¶</a></h3>
+<p>Combine instructions to form fewer, simple instructions. This pass does not
+modify the CFG. This pass is where algebraic simplification happens.</p>
+<p>This pass combines things like:</p>
+<div class="highlight-llvm"><div class="highlight"><pre><span class="nv">%Y</span> <span class="p">=</span> <span class="k">add</span> <span class="k">i32</span> <span class="nv">%X</span><span class="p">,</span> <span class="m">1</span>
+<span class="nv">%Z</span> <span class="p">=</span> <span class="k">add</span> <span class="k">i32</span> <span class="nv">%Y</span><span class="p">,</span> <span class="m">1</span>
+</pre></div>
+</div>
+<p>into:</p>
+<div class="highlight-llvm"><div class="highlight"><pre><span class="nv">%Z</span> <span class="p">=</span> <span class="k">add</span> <span class="k">i32</span> <span class="nv">%X</span><span class="p">,</span> <span class="m">2</span>
+</pre></div>
+</div>
+<p>This is a simple worklist driven algorithm.</p>
+<p>This pass guarantees that the following canonicalizations are performed on the
+program:</p>
+<ol class="arabic simple">
+<li>If a binary operator has a constant operand, it is moved to the right-hand
+side.</li>
+<li>Bitwise operators with constant operands are always grouped so that shifts
+are performed first, then <tt class="docutils literal"><span class="pre">or</span></tt>s, then <tt class="docutils literal"><span class="pre">and</span></tt>s, then <tt class="docutils literal"><span class="pre">xor</span></tt>s.</li>
+<li>Compare instructions are converted from <tt class="docutils literal"><span class="pre"><</span></tt>, <tt class="docutils literal"><span class="pre">></span></tt>, <tt class="docutils literal"><span class="pre">â¤</span></tt>, or <tt class="docutils literal"><span class="pre">â¥</span></tt> to
+<tt class="docutils literal"><span class="pre">=</span></tt> or <tt class="docutils literal"><span class="pre">â </span></tt> if possible.</li>
+<li>All <tt class="docutils literal"><span class="pre">cmp</span></tt> instructions on boolean values are replaced with logical
+operations.</li>
+<li><tt class="docutils literal"><span class="pre">add</span> <span class="pre">X,</span> <span class="pre">X</span></tt> is represented as <tt class="docutils literal"><span class="pre">mul</span> <span class="pre">X,</span> <span class="pre">2</span></tt> â <tt class="docutils literal"><span class="pre">shl</span> <span class="pre">X,</span> <span class="pre">1</span></tt></li>
+<li>Multiplies with a constant power-of-two argument are transformed into
+shifts.</li>
+<li>⦠etc.</li>
+</ol>
+<p>This pass can also simplify calls to specific well-known function calls (e.g.
+runtime library functions). For example, a call <tt class="docutils literal"><span class="pre">exit(3)</span></tt> that occurs within
+the <tt class="docutils literal"><span class="pre">main()</span></tt> function can be transformed into simply <tt class="docutils literal"><span class="pre">return</span> <span class="pre">3</span></tt>. Whether or
+not library calls are simplified is controlled by the
+<a class="reference internal" href="#passes-functionattrs"><em>-functionattrs</em></a> pass and LLVM’s knowledge of
+library calls on different targets.</p>
+</div>
+<div class="section" id="internalize-internalize-global-symbols">
+<h3><a class="toc-backref" href="#id66"><tt class="docutils literal"><span class="pre">-internalize</span></tt>: Internalize Global Symbols</a><a class="headerlink" href="#internalize-internalize-global-symbols" title="Permalink to this headline">¶</a></h3>
+<p>This pass loops over all of the functions in the input module, looking for a
+main function. If a main function is found, all other functions and all global
+variables with initializers are marked as internal.</p>
+</div>
+<div class="section" id="ipconstprop-interprocedural-constant-propagation">
+<h3><a class="toc-backref" href="#id67"><tt class="docutils literal"><span class="pre">-ipconstprop</span></tt>: Interprocedural constant propagation</a><a class="headerlink" href="#ipconstprop-interprocedural-constant-propagation" title="Permalink to this headline">¶</a></h3>
+<p>This pass implements an <em>extremely</em> simple interprocedural constant propagation
+pass. It could certainly be improved in many different ways, like using a
+worklist. This pass makes arguments dead, but does not remove them. The
+existing dead argument elimination pass should be run after this to clean up
+the mess.</p>
+</div>
+<div class="section" id="ipsccp-interprocedural-sparse-conditional-constant-propagation">
+<h3><a class="toc-backref" href="#id68"><tt class="docutils literal"><span class="pre">-ipsccp</span></tt>: Interprocedural Sparse Conditional Constant Propagation</a><a class="headerlink" href="#ipsccp-interprocedural-sparse-conditional-constant-propagation" title="Permalink to this headline">¶</a></h3>
+<p>An interprocedural variant of <a class="reference internal" href="#passes-sccp"><em>Sparse Conditional Constant Propagation</em></a>.</p>
+</div>
+<div class="section" id="jump-threading-jump-threading">
+<h3><a class="toc-backref" href="#id69"><tt class="docutils literal"><span class="pre">-jump-threading</span></tt>: Jump Threading</a><a class="headerlink" href="#jump-threading-jump-threading" title="Permalink to this headline">¶</a></h3>
+<p>Jump threading tries to find distinct threads of control flow running through a
+basic block. This pass looks at blocks that have multiple predecessors and
+multiple successors. If one or more of the predecessors of the block can be
+proven to always cause a jump to one of the successors, we forward the edge
+from the predecessor to the successor by duplicating the contents of this
+block.</p>
+<p>An example of when this can occur is code like this:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="k">if</span> <span class="p">()</span> <span class="p">{</span> <span class="p">...</span>
+ <span class="n">X</span> <span class="o">=</span> <span class="mi">4</span><span class="p">;</span>
+<span class="p">}</span>
+<span class="k">if</span> <span class="p">(</span><span class="n">X</span> <span class="o"><</span> <span class="mi">3</span><span class="p">)</span> <span class="p">{</span>
+</pre></div>
+</div>
+<p>In this case, the unconditional branch at the end of the first if can be
+revectored to the false side of the second if.</p>
+</div>
+<div class="section" id="lcssa-loop-closed-ssa-form-pass">
+<h3><a class="toc-backref" href="#id70"><tt class="docutils literal"><span class="pre">-lcssa</span></tt>: Loop-Closed SSA Form Pass</a><a class="headerlink" href="#lcssa-loop-closed-ssa-form-pass" title="Permalink to this headline">¶</a></h3>
+<p>This pass transforms loops by placing phi nodes at the end of the loops for all
+values that are live across the loop boundary. For example, it turns the left
+into the right code:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="k">for</span> <span class="p">(...)</span> <span class="k">for</span> <span class="p">(...)</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">c</span><span class="p">)</span> <span class="k">if</span> <span class="p">(</span><span class="n">c</span><span class="p">)</span>
+ <span class="n">X1</span> <span class="o">=</span> <span class="p">...</span> <span class="n">X1</span> <span class="o">=</span> <span class="p">...</span>
+ <span class="k">else</span> <span class="k">else</span>
+ <span class="n">X2</span> <span class="o">=</span> <span class="p">...</span> <span class="n">X2</span> <span class="o">=</span> <span class="p">...</span>
+ <span class="n">X3</span> <span class="o">=</span> <span class="n">phi</span><span class="p">(</span><span class="n">X1</span><span class="p">,</span> <span class="n">X2</span><span class="p">)</span> <span class="n">X3</span> <span class="o">=</span> <span class="n">phi</span><span class="p">(</span><span class="n">X1</span><span class="p">,</span> <span class="n">X2</span><span class="p">)</span>
+<span class="p">...</span> <span class="o">=</span> <span class="n">X3</span> <span class="o">+</span> <span class="mi">4</span> <span class="n">X4</span> <span class="o">=</span> <span class="n">phi</span><span class="p">(</span><span class="n">X3</span><span class="p">)</span>
+ <span class="p">...</span> <span class="o">=</span> <span class="n">X4</span> <span class="o">+</span> <span class="mi">4</span>
+</pre></div>
+</div>
+<p>This is still valid LLVM; the extra phi nodes are purely redundant, and will be
+trivially eliminated by <tt class="docutils literal"><span class="pre">InstCombine</span></tt>. The major benefit of this
+transformation is that it makes many other loop optimizations, such as
+<tt class="docutils literal"><span class="pre">LoopUnswitch</span></tt>ing, simpler.</p>
+</div>
+<div class="section" id="licm-loop-invariant-code-motion">
+<span id="passes-licm"></span><h3><a class="toc-backref" href="#id71"><tt class="docutils literal"><span class="pre">-licm</span></tt>: Loop Invariant Code Motion</a><a class="headerlink" href="#licm-loop-invariant-code-motion" title="Permalink to this headline">¶</a></h3>
+<p>This pass performs loop invariant code motion, attempting to remove as much
+code from the body of a loop as possible. It does this by either hoisting code
+into the preheader block, or by sinking code to the exit blocks if it is safe.
+This pass also promotes must-aliased memory locations in the loop to live in
+registers, thus hoisting and sinking “invariant” loads and stores.</p>
+<p>This pass uses alias analysis for two purposes:</p>
+<ol class="arabic">
+<li><p class="first">Moving loop invariant loads and calls out of loops. If we can determine
+that a load or call inside of a loop never aliases anything stored to, we
+can hoist it or sink it like any other instruction.</p>
+</li>
+<li><p class="first">Scalar Promotion of Memory. If there is a store instruction inside of the
+loop, we try to move the store to happen AFTER the loop instead of inside of
+the loop. This can only happen if a few conditions are true:</p>
+<ol class="arabic simple">
+<li>The pointer stored through is loop invariant.</li>
+<li>There are no stores or loads in the loop which <em>may</em> alias the pointer.
+There are no calls in the loop which mod/ref the pointer.</li>
+</ol>
+<p>If these conditions are true, we can promote the loads and stores in the
+loop of the pointer to use a temporary alloca’d variable. We then use the
+<a class="reference internal" href="#passes-mem2reg"><em>mem2reg</em></a> functionality to construct the appropriate
+SSA form for the variable.</p>
+</li>
+</ol>
+</div>
+<div class="section" id="loop-deletion-delete-dead-loops">
+<h3><a class="toc-backref" href="#id72"><tt class="docutils literal"><span class="pre">-loop-deletion</span></tt>: Delete dead loops</a><a class="headerlink" href="#loop-deletion-delete-dead-loops" title="Permalink to this headline">¶</a></h3>
+<p>This file implements the Dead Loop Deletion Pass. This pass is responsible for
+eliminating loops with non-infinite computable trip counts that have no side
+effects or volatile instructions, and do not contribute to the computation of
+the function’s return value.</p>
+</div>
+<div class="section" id="loop-extract-extract-loops-into-new-functions">
+<span id="passes-loop-extract"></span><h3><a class="toc-backref" href="#id73"><tt class="docutils literal"><span class="pre">-loop-extract</span></tt>: Extract loops into new functions</a><a class="headerlink" href="#loop-extract-extract-loops-into-new-functions" title="Permalink to this headline">¶</a></h3>
+<p>A pass wrapper around the <tt class="docutils literal"><span class="pre">ExtractLoop()</span></tt> scalar transformation to extract
+each top-level loop into its own new function. If the loop is the <em>only</em> loop
+in a given function, it is not touched. This is a pass most useful for
+debugging via bugpoint.</p>
+</div>
+<div class="section" id="loop-extract-single-extract-at-most-one-loop-into-a-new-function">
+<h3><a class="toc-backref" href="#id74"><tt class="docutils literal"><span class="pre">-loop-extract-single</span></tt>: Extract at most one loop into a new function</a><a class="headerlink" href="#loop-extract-single-extract-at-most-one-loop-into-a-new-function" title="Permalink to this headline">¶</a></h3>
+<p>Similar to <a class="reference internal" href="#passes-loop-extract"><em>Extract loops into new functions</em></a>, this
+pass extracts one natural loop from the program into a function if it can.
+This is used by <strong class="program">bugpoint</strong>.</p>
+</div>
+<div class="section" id="loop-reduce-loop-strength-reduction">
+<h3><a class="toc-backref" href="#id75"><tt class="docutils literal"><span class="pre">-loop-reduce</span></tt>: Loop Strength Reduction</a><a class="headerlink" href="#loop-reduce-loop-strength-reduction" title="Permalink to this headline">¶</a></h3>
+<p>This pass performs a strength reduction on array references inside loops that
+have as one or more of their components the loop induction variable. This is
+accomplished by creating a new value to hold the initial value of the array
+access for the first iteration, and then creating a new GEP instruction in the
+loop to increment the value by the appropriate amount.</p>
+</div>
+<div class="section" id="loop-rotate-rotate-loops">
+<h3><a class="toc-backref" href="#id76"><tt class="docutils literal"><span class="pre">-loop-rotate</span></tt>: Rotate Loops</a><a class="headerlink" href="#loop-rotate-rotate-loops" title="Permalink to this headline">¶</a></h3>
+<p>A simple loop rotation transformation.</p>
+</div>
+<div class="section" id="loop-simplify-canonicalize-natural-loops">
+<h3><a class="toc-backref" href="#id77"><tt class="docutils literal"><span class="pre">-loop-simplify</span></tt>: Canonicalize natural loops</a><a class="headerlink" href="#loop-simplify-canonicalize-natural-loops" title="Permalink to this headline">¶</a></h3>
+<p>This pass performs several transformations to transform natural loops into a
+simpler form, which makes subsequent analyses and transformations simpler and
+more effective.</p>
+<p>Loop pre-header insertion guarantees that there is a single, non-critical entry
+edge from outside of the loop to the loop header. This simplifies a number of
+analyses and transformations, such as <a class="reference internal" href="#passes-licm"><em>LICM</em></a>.</p>
+<p>Loop exit-block insertion guarantees that all exit blocks from the loop (blocks
+which are outside of the loop that have predecessors inside of the loop) only
+have predecessors from inside of the loop (and are thus dominated by the loop
+header). This simplifies transformations such as store-sinking that are built
+into LICM.</p>
+<p>This pass also guarantees that loops will have exactly one backedge.</p>
+<p>Note that the <a class="reference internal" href="#passes-simplifycfg"><em>simplifycfg</em></a> pass will clean up blocks
+which are split out but end up being unnecessary, so usage of this pass should
+not pessimize generated code.</p>
+<p>This pass obviously modifies the CFG, but updates loop information and
+dominator information.</p>
+</div>
+<div class="section" id="loop-unroll-unroll-loops">
+<h3><a class="toc-backref" href="#id78"><tt class="docutils literal"><span class="pre">-loop-unroll</span></tt>: Unroll loops</a><a class="headerlink" href="#loop-unroll-unroll-loops" title="Permalink to this headline">¶</a></h3>
+<p>This pass implements a simple loop unroller. It works best when loops have
+been canonicalized by the <a class="reference internal" href="#passes-indvars"><em>indvars</em></a> pass, allowing it to
+determine the trip counts of loops easily.</p>
+</div>
+<div class="section" id="loop-unswitch-unswitch-loops">
+<h3><a class="toc-backref" href="#id79"><tt class="docutils literal"><span class="pre">-loop-unswitch</span></tt>: Unswitch loops</a><a class="headerlink" href="#loop-unswitch-unswitch-loops" title="Permalink to this headline">¶</a></h3>
+<p>This pass transforms loops that contain branches on loop-invariant conditions
+to have multiple loops. For example, it turns the left into the right code:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="k">for</span> <span class="p">(...)</span> <span class="k">if</span> <span class="p">(</span><span class="n">lic</span><span class="p">)</span>
+ <span class="n">A</span> <span class="k">for</span> <span class="p">(...)</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">lic</span><span class="p">)</span> <span class="n">A</span><span class="p">;</span> <span class="n">B</span><span class="p">;</span> <span class="n">C</span>
+ <span class="n">B</span> <span class="k">else</span>
+ <span class="n">C</span> <span class="k">for</span> <span class="p">(...)</span>
+ <span class="n">A</span><span class="p">;</span> <span class="n">C</span>
+</pre></div>
+</div>
+<p>This can increase the size of the code exponentially (doubling it every time a
+loop is unswitched) so we only unswitch if the resultant code will be smaller
+than a threshold.</p>
+<p>This pass expects <a class="reference internal" href="#passes-licm"><em>LICM</em></a> to be run before it to hoist
+invariant conditions out of the loop, to make the unswitching opportunity
+obvious.</p>
+</div>
+<div class="section" id="loweratomic-lower-atomic-intrinsics-to-non-atomic-form">
+<h3><a class="toc-backref" href="#id80"><tt class="docutils literal"><span class="pre">-loweratomic</span></tt>: Lower atomic intrinsics to non-atomic form</a><a class="headerlink" href="#loweratomic-lower-atomic-intrinsics-to-non-atomic-form" title="Permalink to this headline">¶</a></h3>
+<p>This pass lowers atomic intrinsics to non-atomic form for use in a known
+non-preemptible environment.</p>
+<p>The pass does not verify that the environment is non-preemptible (in general
+this would require knowledge of the entire call graph of the program including
+any libraries which may not be available in bitcode form); it simply lowers
+every atomic intrinsic.</p>
+</div>
+<div class="section" id="lowerinvoke-lower-invokes-to-calls-for-unwindless-code-generators">
+<h3><a class="toc-backref" href="#id81"><tt class="docutils literal"><span class="pre">-lowerinvoke</span></tt>: Lower invokes to calls, for unwindless code generators</a><a class="headerlink" href="#lowerinvoke-lower-invokes-to-calls-for-unwindless-code-generators" title="Permalink to this headline">¶</a></h3>
+<p>This transformation is designed for use by code generators which do not yet
+support stack unwinding. This pass converts <tt class="docutils literal"><span class="pre">invoke</span></tt> instructions to
+<tt class="docutils literal"><span class="pre">call</span></tt> instructions, so that any exception-handling <tt class="docutils literal"><span class="pre">landingpad</span></tt> blocks
+become dead code (which can be removed by running the <tt class="docutils literal"><span class="pre">-simplifycfg</span></tt> pass
+afterwards).</p>
+</div>
+<div class="section" id="lowerswitch-lower-switchinsts-to-branches">
+<h3><a class="toc-backref" href="#id82"><tt class="docutils literal"><span class="pre">-lowerswitch</span></tt>: Lower <tt class="docutils literal"><span class="pre">SwitchInst</span></tt>s to branches</a><a class="headerlink" href="#lowerswitch-lower-switchinsts-to-branches" title="Permalink to this headline">¶</a></h3>
+<p>Rewrites switch instructions with a sequence of branches, which allows targets
+to get away with not implementing the switch instruction until it is
+convenient.</p>
+</div>
+<div class="section" id="mem2reg-promote-memory-to-register">
+<span id="passes-mem2reg"></span><h3><a class="toc-backref" href="#id83"><tt class="docutils literal"><span class="pre">-mem2reg</span></tt>: Promote Memory to Register</a><a class="headerlink" href="#mem2reg-promote-memory-to-register" title="Permalink to this headline">¶</a></h3>
+<p>This file promotes memory references to be register references. It promotes
+alloca instructions which only have loads and stores as uses. An <tt class="docutils literal"><span class="pre">alloca</span></tt> is
+transformed by using dominator frontiers to place phi nodes, then traversing
+the function in depth-first order to rewrite loads and stores as appropriate.
+This is just the standard SSA construction algorithm to construct “pruned” SSA
+form.</p>
+</div>
+<div class="section" id="memcpyopt-memcpy-optimization">
+<h3><a class="toc-backref" href="#id84"><tt class="docutils literal"><span class="pre">-memcpyopt</span></tt>: MemCpy Optimization</a><a class="headerlink" href="#memcpyopt-memcpy-optimization" title="Permalink to this headline">¶</a></h3>
+<p>This pass performs various transformations related to eliminating <tt class="docutils literal"><span class="pre">memcpy</span></tt>
+calls, or transforming sets of stores into <tt class="docutils literal"><span class="pre">memset</span></tt>s.</p>
+</div>
+<div class="section" id="mergefunc-merge-functions">
+<h3><a class="toc-backref" href="#id85"><tt class="docutils literal"><span class="pre">-mergefunc</span></tt>: Merge Functions</a><a class="headerlink" href="#mergefunc-merge-functions" title="Permalink to this headline">¶</a></h3>
+<p>This pass looks for equivalent functions that are mergable and folds them.</p>
+<p>Total-ordering is introduced among the functions set: we define comparison
+that answers for every two functions which of them is greater. It allows to
+arrange functions into the binary tree.</p>
+<p>For every new function we check for equivalent in tree.</p>
+<p>If equivalent exists we fold such functions. If both functions are overridable,
+we move the functionality into a new internal function and leave two
+overridable thunks to it.</p>
+<p>If there is no equivalent, then we add this function to tree.</p>
+<p>Lookup routine has O(log(n)) complexity, while whole merging process has
+complexity of O(n*log(n)).</p>
+<p>Read
+<a class="reference internal" href="MergeFunctions.html"><em>this</em></a>
+article for more details.</p>
+</div>
+<div class="section" id="mergereturn-unify-function-exit-nodes">
+<h3><a class="toc-backref" href="#id86"><tt class="docutils literal"><span class="pre">-mergereturn</span></tt>: Unify function exit nodes</a><a class="headerlink" href="#mergereturn-unify-function-exit-nodes" title="Permalink to this headline">¶</a></h3>
+<p>Ensure that functions have at most one <tt class="docutils literal"><span class="pre">ret</span></tt> instruction in them.
+Additionally, it keeps track of which node is the new exit node of the CFG.</p>
+</div>
+<div class="section" id="partial-inliner-partial-inliner">
+<h3><a class="toc-backref" href="#id87"><tt class="docutils literal"><span class="pre">-partial-inliner</span></tt>: Partial Inliner</a><a class="headerlink" href="#partial-inliner-partial-inliner" title="Permalink to this headline">¶</a></h3>
+<p>This pass performs partial inlining, typically by inlining an <tt class="docutils literal"><span class="pre">if</span></tt> statement
+that surrounds the body of the function.</p>
+</div>
+<div class="section" id="prune-eh-remove-unused-exception-handling-info">
+<h3><a class="toc-backref" href="#id88"><tt class="docutils literal"><span class="pre">-prune-eh</span></tt>: Remove unused exception handling info</a><a class="headerlink" href="#prune-eh-remove-unused-exception-handling-info" title="Permalink to this headline">¶</a></h3>
+<p>This file implements a simple interprocedural pass which walks the call-graph,
+turning invoke instructions into call instructions if and only if the callee
+cannot throw an exception. It implements this as a bottom-up traversal of the
+call-graph.</p>
+</div>
+<div class="section" id="reassociate-reassociate-expressions">
+<h3><a class="toc-backref" href="#id89"><tt class="docutils literal"><span class="pre">-reassociate</span></tt>: Reassociate expressions</a><a class="headerlink" href="#reassociate-reassociate-expressions" title="Permalink to this headline">¶</a></h3>
+<p>This pass reassociates commutative expressions in an order that is designed to
+promote better constant propagation, GCSE, <a class="reference internal" href="#passes-licm"><em>LICM</em></a>, PRE, etc.</p>
+<p>For example: 4 + (x + 5) â x + (4 + 5)</p>
+<p>In the implementation of this algorithm, constants are assigned rank = 0,
+function arguments are rank = 1, and other values are assigned ranks
+corresponding to the reverse post order traversal of current function (starting
+at 2), which effectively gives values in deep loops higher rank than values not
+in loops.</p>
+</div>
+<div class="section" id="reg2mem-demote-all-values-to-stack-slots">
+<h3><a class="toc-backref" href="#id90"><tt class="docutils literal"><span class="pre">-reg2mem</span></tt>: Demote all values to stack slots</a><a class="headerlink" href="#reg2mem-demote-all-values-to-stack-slots" title="Permalink to this headline">¶</a></h3>
+<p>This file demotes all registers to memory references. It is intended to be the
+inverse of <a class="reference internal" href="#passes-mem2reg"><em>mem2reg</em></a>. By converting to <tt class="docutils literal"><span class="pre">load</span></tt>
+instructions, the only values live across basic blocks are <tt class="docutils literal"><span class="pre">alloca</span></tt>
+instructions and <tt class="docutils literal"><span class="pre">load</span></tt> instructions before <tt class="docutils literal"><span class="pre">phi</span></tt> nodes. It is intended
+that this should make CFG hacking much easier. To make later hacking easier,
+the entry block is split into two, such that all introduced <tt class="docutils literal"><span class="pre">alloca</span></tt>
+instructions (and nothing else) are in the entry block.</p>
+</div>
+<div class="section" id="scalarrepl-scalar-replacement-of-aggregates-dt">
+<h3><a class="toc-backref" href="#id91"><tt class="docutils literal"><span class="pre">-scalarrepl</span></tt>: Scalar Replacement of Aggregates (DT)</a><a class="headerlink" href="#scalarrepl-scalar-replacement-of-aggregates-dt" title="Permalink to this headline">¶</a></h3>
+<p>The well-known scalar replacement of aggregates transformation. This transform
+breaks up <tt class="docutils literal"><span class="pre">alloca</span></tt> instructions of aggregate type (structure or array) into
+individual <tt class="docutils literal"><span class="pre">alloca</span></tt> instructions for each member if possible. Then, if
+possible, it transforms the individual <tt class="docutils literal"><span class="pre">alloca</span></tt> instructions into nice clean
+scalar SSA form.</p>
+<p>This combines a simple scalar replacement of aggregates algorithm with the
+<a class="reference internal" href="#passes-mem2reg"><em>mem2reg</em></a> algorithm because they often interact,
+especially for C++ programs. As such, iterating between <tt class="docutils literal"><span class="pre">scalarrepl</span></tt>, then
+<a class="reference internal" href="#passes-mem2reg"><em>mem2reg</em></a> until we run out of things to promote works
+well.</p>
+</div>
+<div class="section" id="sccp-sparse-conditional-constant-propagation">
+<span id="passes-sccp"></span><h3><a class="toc-backref" href="#id92"><tt class="docutils literal"><span class="pre">-sccp</span></tt>: Sparse Conditional Constant Propagation</a><a class="headerlink" href="#sccp-sparse-conditional-constant-propagation" title="Permalink to this headline">¶</a></h3>
+<p>Sparse conditional constant propagation and merging, which can be summarized
+as:</p>
+<ul class="simple">
+<li>Assumes values are constant unless proven otherwise</li>
+<li>Assumes BasicBlocks are dead unless proven otherwise</li>
+<li>Proves values to be constant, and replaces them with constants</li>
+<li>Proves conditional branches to be unconditional</li>
+</ul>
+<p>Note that this pass has a habit of making definitions be dead. It is a good
+idea to run a <a class="reference internal" href="#passes-dce"><em>DCE</em></a> pass sometime after running this pass.</p>
+</div>
+<div class="section" id="simplifycfg-simplify-the-cfg">
+<span id="passes-simplifycfg"></span><h3><a class="toc-backref" href="#id93"><tt class="docutils literal"><span class="pre">-simplifycfg</span></tt>: Simplify the CFG</a><a class="headerlink" href="#simplifycfg-simplify-the-cfg" title="Permalink to this headline">¶</a></h3>
+<p>Performs dead code elimination and basic block merging. Specifically:</p>
+<ul class="simple">
+<li>Removes basic blocks with no predecessors.</li>
+<li>Merges a basic block into its predecessor if there is only one and the
+predecessor only has one successor.</li>
+<li>Eliminates PHI nodes for basic blocks with a single predecessor.</li>
+<li>Eliminates a basic block that only contains an unconditional branch.</li>
+</ul>
+</div>
+<div class="section" id="sink-code-sinking">
+<h3><a class="toc-backref" href="#id94"><tt class="docutils literal"><span class="pre">-sink</span></tt>: Code sinking</a><a class="headerlink" href="#sink-code-sinking" title="Permalink to this headline">¶</a></h3>
+<p>This pass moves instructions into successor blocks, when possible, so that they
+aren’t executed on paths where their results aren’t needed.</p>
+</div>
+<div class="section" id="strip-strip-all-symbols-from-a-module">
+<h3><a class="toc-backref" href="#id95"><tt class="docutils literal"><span class="pre">-strip</span></tt>: Strip all symbols from a module</a><a class="headerlink" href="#strip-strip-all-symbols-from-a-module" title="Permalink to this headline">¶</a></h3>
+<p>Performs code stripping. This transformation can delete:</p>
+<ul class="simple">
+<li>names for virtual registers</li>
+<li>symbols for internal globals and functions</li>
+<li>debug information</li>
+</ul>
+<p>Note that this transformation makes code much less readable, so it should only
+be used in situations where the strip utility would be used, such as reducing
+code size or making it harder to reverse engineer code.</p>
+</div>
+<div class="section" id="strip-dead-debug-info-strip-debug-info-for-unused-symbols">
+<h3><a class="toc-backref" href="#id96"><tt class="docutils literal"><span class="pre">-strip-dead-debug-info</span></tt>: Strip debug info for unused symbols</a><a class="headerlink" href="#strip-dead-debug-info-strip-debug-info-for-unused-symbols" title="Permalink to this headline">¶</a></h3>
+<p>performs code stripping. this transformation can delete:</p>
+<ul class="simple">
+<li>names for virtual registers</li>
+<li>symbols for internal globals and functions</li>
+<li>debug information</li>
+</ul>
+<p>note that this transformation makes code much less readable, so it should only
+be used in situations where the strip utility would be used, such as reducing
+code size or making it harder to reverse engineer code.</p>
+</div>
+<div class="section" id="strip-dead-prototypes-strip-unused-function-prototypes">
+<h3><a class="toc-backref" href="#id97"><tt class="docutils literal"><span class="pre">-strip-dead-prototypes</span></tt>: Strip Unused Function Prototypes</a><a class="headerlink" href="#strip-dead-prototypes-strip-unused-function-prototypes" title="Permalink to this headline">¶</a></h3>
+<p>This pass loops over all of the functions in the input module, looking for dead
+declarations and removes them. Dead declarations are declarations of functions
+for which no implementation is available (i.e., declarations for unused library
+functions).</p>
+</div>
+<div class="section" id="strip-debug-declare-strip-all-llvm-dbg-declare-intrinsics">
+<h3><a class="toc-backref" href="#id98"><tt class="docutils literal"><span class="pre">-strip-debug-declare</span></tt>: Strip all <tt class="docutils literal"><span class="pre">llvm.dbg.declare</span></tt> intrinsics</a><a class="headerlink" href="#strip-debug-declare-strip-all-llvm-dbg-declare-intrinsics" title="Permalink to this headline">¶</a></h3>
+<p>This pass implements code stripping. Specifically, it can delete:</p>
+<ol class="arabic simple">
+<li>names for virtual registers</li>
+<li>symbols for internal globals and functions</li>
+<li>debug information</li>
+</ol>
+<p>Note that this transformation makes code much less readable, so it should only
+be used in situations where the ‘strip’ utility would be used, such as reducing
+code size or making it harder to reverse engineer code.</p>
+</div>
+<div class="section" id="strip-nondebug-strip-all-symbols-except-dbg-symbols-from-a-module">
+<h3><a class="toc-backref" href="#id99"><tt class="docutils literal"><span class="pre">-strip-nondebug</span></tt>: Strip all symbols, except dbg symbols, from a module</a><a class="headerlink" href="#strip-nondebug-strip-all-symbols-except-dbg-symbols-from-a-module" title="Permalink to this headline">¶</a></h3>
+<p>This pass implements code stripping. Specifically, it can delete:</p>
+<ol class="arabic simple">
+<li>names for virtual registers</li>
+<li>symbols for internal globals and functions</li>
+<li>debug information</li>
+</ol>
+<p>Note that this transformation makes code much less readable, so it should only
+be used in situations where the ‘strip’ utility would be used, such as reducing
+code size or making it harder to reverse engineer code.</p>
+</div>
+<div class="section" id="tailcallelim-tail-call-elimination">
+<h3><a class="toc-backref" href="#id100"><tt class="docutils literal"><span class="pre">-tailcallelim</span></tt>: Tail Call Elimination</a><a class="headerlink" href="#tailcallelim-tail-call-elimination" title="Permalink to this headline">¶</a></h3>
+<p>This file transforms calls of the current function (self recursion) followed by
+a return instruction with a branch to the entry of the function, creating a
+loop. This pass also implements the following extensions to the basic
+algorithm:</p>
+<ol class="arabic simple">
+<li>Trivial instructions between the call and return do not prevent the
+transformation from taking place, though currently the analysis cannot
+support moving any really useful instructions (only dead ones).</li>
+<li>This pass transforms functions that are prevented from being tail recursive
+by an associative expression to use an accumulator variable, thus compiling
+the typical naive factorial or fib implementation into efficient code.</li>
+<li>TRE is performed if the function returns void, if the return returns the
+result returned by the call, or if the function returns a run-time constant
+on all exits from the function. It is possible, though unlikely, that the
+return returns something else (like constant 0), and can still be TRE’d. It
+can be TRE’d if <em>all other</em> return instructions in the function return the
+exact same value.</li>
+<li>If it can prove that callees do not access theier caller stack frame, they
+are marked as eligible for tail call elimination (by the code generator).</li>
+</ol>
+</div>
+</div>
+<div class="section" id="utility-passes">
+<h2><a class="toc-backref" href="#id101">Utility Passes</a><a class="headerlink" href="#utility-passes" title="Permalink to this headline">¶</a></h2>
+<p>This section describes the LLVM Utility Passes.</p>
+<div class="section" id="deadarghax0r-dead-argument-hacking-bugpoint-use-only-do-not-use">
+<h3><a class="toc-backref" href="#id102"><tt class="docutils literal"><span class="pre">-deadarghaX0r</span></tt>: Dead Argument Hacking (BUGPOINT USE ONLY; DO NOT USE)</a><a class="headerlink" href="#deadarghax0r-dead-argument-hacking-bugpoint-use-only-do-not-use" title="Permalink to this headline">¶</a></h3>
+<p>Same as dead argument elimination, but deletes arguments to functions which are
+external. This is only for use by <a class="reference internal" href="Bugpoint.html"><em>bugpoint</em></a>.</p>
+</div>
+<div class="section" id="extract-blocks-extract-basic-blocks-from-module-for-bugpoint-use">
+<h3><a class="toc-backref" href="#id103"><tt class="docutils literal"><span class="pre">-extract-blocks</span></tt>: Extract Basic Blocks From Module (for bugpoint use)</a><a class="headerlink" href="#extract-blocks-extract-basic-blocks-from-module-for-bugpoint-use" title="Permalink to this headline">¶</a></h3>
+<p>This pass is used by bugpoint to extract all blocks from the module into their
+own functions.</p>
+</div>
+<div class="section" id="instnamer-assign-names-to-anonymous-instructions">
+<h3><a class="toc-backref" href="#id104"><tt class="docutils literal"><span class="pre">-instnamer</span></tt>: Assign names to anonymous instructions</a><a class="headerlink" href="#instnamer-assign-names-to-anonymous-instructions" title="Permalink to this headline">¶</a></h3>
+<p>This is a little utility pass that gives instructions names, this is mostly
+useful when diffing the effect of an optimization because deleting an unnamed
+instruction can change all other instruction numbering, making the diff very
+noisy.</p>
+</div>
+<div class="section" id="verify-module-verifier">
+<span id="passes-verify"></span><h3><a class="toc-backref" href="#id105"><tt class="docutils literal"><span class="pre">-verify</span></tt>: Module Verifier</a><a class="headerlink" href="#verify-module-verifier" title="Permalink to this headline">¶</a></h3>
+<p>Verifies an LLVM IR code. This is useful to run after an optimization which is
+undergoing testing. Note that llvm-as verifies its input before emitting
+bitcode, and also that malformed bitcode is likely to make LLVM crash. All
+language front-ends are therefore encouraged to verify their output before
+performing optimizing transformations.</p>
+<ol class="arabic simple">
+<li>Both of a binary operator’s parameters are of the same type.</li>
+<li>Verify that the indices of mem access instructions match other operands.</li>
+<li>Verify that arithmetic and other things are only performed on first-class
+types. Verify that shifts and logicals only happen on integrals f.e.</li>
+<li>All of the constants in a switch statement are of the correct type.</li>
+<li>The code is in valid SSA form.</li>
+<li>It is illegal to put a label into any other type (like a structure) or to
+return one.</li>
+<li>Only phi nodes can be self referential: <tt class="docutils literal"><span class="pre">%x</span> <span class="pre">=</span> <span class="pre">add</span> <span class="pre">i32</span> <span class="pre">%x</span></tt>, <tt class="docutils literal"><span class="pre">%x</span></tt> is
+invalid.</li>
+<li>PHI nodes must have an entry for each predecessor, with no extras.</li>
+<li>PHI nodes must be the first thing in a basic block, all grouped together.</li>
+<li>PHI nodes must have at least one entry.</li>
+<li>All basic blocks should only end with terminator insts, not contain them.</li>
+<li>The entry node to a function must not have predecessors.</li>
+<li>All Instructions must be embedded into a basic block.</li>
+<li>Functions cannot take a void-typed parameter.</li>
+<li>Verify that a function’s argument list agrees with its declared type.</li>
+<li>It is illegal to specify a name for a void value.</li>
+<li>It is illegal to have an internal global value with no initializer.</li>
+<li>It is illegal to have a <tt class="docutils literal"><span class="pre">ret</span></tt> instruction that returns a value that does
+not agree with the function return value type.</li>
+<li>Function call argument types match the function prototype.</li>
+<li>All other things that are tested by asserts spread about the code.</li>
+</ol>
+<p>Note that this does not provide full security verification (like Java), but
+instead just tries to ensure that code is well-formed.</p>
+</div>
+<div class="section" id="view-cfg-view-cfg-of-function">
+<h3><a class="toc-backref" href="#id106"><tt class="docutils literal"><span class="pre">-view-cfg</span></tt>: View CFG of function</a><a class="headerlink" href="#view-cfg-view-cfg-of-function" title="Permalink to this headline">¶</a></h3>
+<p>Displays the control flow graph using the GraphViz tool.</p>
+</div>
+<div class="section" id="view-cfg-only-view-cfg-of-function-with-no-function-bodies">
+<h3><a class="toc-backref" href="#id107"><tt class="docutils literal"><span class="pre">-view-cfg-only</span></tt>: View CFG of function (with no function bodies)</a><a class="headerlink" href="#view-cfg-only-view-cfg-of-function-with-no-function-bodies" title="Permalink to this headline">¶</a></h3>
+<p>Displays the control flow graph using the GraphViz tool, but omitting function
+bodies.</p>
+</div>
+<div class="section" id="view-dom-view-dominance-tree-of-function">
+<h3><a class="toc-backref" href="#id108"><tt class="docutils literal"><span class="pre">-view-dom</span></tt>: View dominance tree of function</a><a class="headerlink" href="#view-dom-view-dominance-tree-of-function" title="Permalink to this headline">¶</a></h3>
+<p>Displays the dominator tree using the GraphViz tool.</p>
+</div>
+<div class="section" id="view-dom-only-view-dominance-tree-of-function-with-no-function-bodies">
+<h3><a class="toc-backref" href="#id109"><tt class="docutils literal"><span class="pre">-view-dom-only</span></tt>: View dominance tree of function (with no function bodies)</a><a class="headerlink" href="#view-dom-only-view-dominance-tree-of-function-with-no-function-bodies" title="Permalink to this headline">¶</a></h3>
+<p>Displays the dominator tree using the GraphViz tool, but omitting function
+bodies.</p>
+</div>
+<div class="section" id="view-postdom-view-postdominance-tree-of-function">
+<h3><a class="toc-backref" href="#id110"><tt class="docutils literal"><span class="pre">-view-postdom</span></tt>: View postdominance tree of function</a><a class="headerlink" href="#view-postdom-view-postdominance-tree-of-function" title="Permalink to this headline">¶</a></h3>
+<p>Displays the post dominator tree using the GraphViz tool.</p>
+</div>
+<div class="section" id="view-postdom-only-view-postdominance-tree-of-function-with-no-function-bodies">
+<h3><a class="toc-backref" href="#id111"><tt class="docutils literal"><span class="pre">-view-postdom-only</span></tt>: View postdominance tree of function (with no function bodies)</a><a class="headerlink" href="#view-postdom-only-view-postdominance-tree-of-function-with-no-function-bodies" title="Permalink to this headline">¶</a></h3>
+<p>Displays the post dominator tree using the GraphViz tool, but omitting function
+bodies.</p>
+</div>
+</div>
+</div>
+
+
+ </div>
+ </div>
+ <div class="clearer"></div>
+ </div>
+ <div class="related">
+ <h3>Navigation</h3>
+ <ul>
+ <li class="right" style="margin-right: 10px">
+ <a href="genindex.html" title="General Index"
+ >index</a></li>
+ <li class="right" >
+ <a href="YamlIO.html" title="YAML I/O"
+ >next</a> |</li>
+ <li class="right" >
+ <a href="ReleaseNotes.html" title="LLVM 3.7 Release Notes"
+ >previous</a> |</li>
+ <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+ <li><a href="index.html">Documentation</a>»</li>
+
+ </ul>
+ </div>
+ <div class="footer">
+ © Copyright 2003-2016, LLVM Project.
+ Last updated on 2016-01-04.
+ Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.3.
+ </div>
+ </body>
+</html>
\ No newline at end of file
Added: www-releases/trunk/3.7.1/docs/Phabricator.html
URL: http://llvm.org/viewvc/llvm-project/www-releases/trunk/3.7.1/docs/Phabricator.html?rev=257950&view=auto
==============================================================================
--- www-releases/trunk/3.7.1/docs/Phabricator.html (added)
+++ www-releases/trunk/3.7.1/docs/Phabricator.html Fri Jan 15 17:13:16 2016
@@ -0,0 +1,233 @@
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
+ <title>Code Reviews with Phabricator — LLVM 3.7 documentation</title>
+
+ <link rel="stylesheet" href="_static/llvm-theme.css" type="text/css" />
+ <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
+
+ <script type="text/javascript">
+ var DOCUMENTATION_OPTIONS = {
+ URL_ROOT: './',
+ VERSION: '3.7',
+ COLLAPSE_INDEX: false,
+ FILE_SUFFIX: '.html',
+ HAS_SOURCE: true
+ };
+ </script>
+ <script type="text/javascript" src="_static/jquery.js"></script>
+ <script type="text/javascript" src="_static/underscore.js"></script>
+ <script type="text/javascript" src="_static/doctools.js"></script>
+ <link rel="top" title="LLVM 3.7 documentation" href="index.html" />
+ <link rel="prev" title="How To Validate a New Release" href="ReleaseProcess.html" />
+<style type="text/css">
+ table.right { float: right; margin-left: 20px; }
+ table.right td { border: 1px solid #ccc; }
+</style>
+
+ </head>
+ <body>
+<div class="logo">
+ <a href="index.html">
+ <img src="_static/logo.png"
+ alt="LLVM Logo" width="250" height="88"/></a>
+</div>
+
+ <div class="related">
+ <h3>Navigation</h3>
+ <ul>
+ <li class="right" style="margin-right: 10px">
+ <a href="genindex.html" title="General Index"
+ accesskey="I">index</a></li>
+ <li class="right" >
+ <a href="ReleaseProcess.html" title="How To Validate a New Release"
+ accesskey="P">previous</a> |</li>
+ <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+ <li><a href="index.html">Documentation</a>»</li>
+
+ </ul>
+ </div>
+
+
+ <div class="document">
+ <div class="documentwrapper">
+ <div class="body">
+
+ <div class="section" id="code-reviews-with-phabricator">
+<h1>Code Reviews with Phabricator<a class="headerlink" href="#code-reviews-with-phabricator" title="Permalink to this headline">¶</a></h1>
+<div class="contents local topic" id="contents">
+<ul class="simple">
+<li><a class="reference internal" href="#sign-up" id="id1">Sign up</a></li>
+<li><a class="reference internal" href="#requesting-a-review-via-the-command-line" id="id2">Requesting a review via the command line</a></li>
+<li><a class="reference internal" href="#requesting-a-review-via-the-web-interface" id="id3">Requesting a review via the web interface</a></li>
+<li><a class="reference internal" href="#reviewing-code-with-phabricator" id="id4">Reviewing code with Phabricator</a></li>
+<li><a class="reference internal" href="#committing-a-change" id="id5">Committing a change</a></li>
+<li><a class="reference internal" href="#abandoning-a-change" id="id6">Abandoning a change</a></li>
+<li><a class="reference internal" href="#status" id="id7">Status</a></li>
+</ul>
+</div>
+<p>If you prefer to use a web user interface for code reviews, you can now submit
+your patches for Clang and LLVM at <a class="reference external" href="http://reviews.llvm.org">LLVM’s Phabricator</a> instance.</p>
+<p>While Phabricator is a useful tool for some, the relevant -commits mailing list
+is the system of record for all LLVM code review. The mailing list should be
+added as a subscriber on all reviews, and Phabricator users should be prepared
+to respond to free-form comments in mail sent to the commits list.</p>
+<div class="section" id="sign-up">
+<h2><a class="toc-backref" href="#id1">Sign up</a><a class="headerlink" href="#sign-up" title="Permalink to this headline">¶</a></h2>
+<p>To get started with Phabricator, navigate to <a class="reference external" href="http://reviews.llvm.org">http://reviews.llvm.org</a> and
+click the power icon in the top right. You can register with a GitHub account,
+a Google account, or you can create your own profile.</p>
+<p>Make <em>sure</em> that the email address registered with Phabricator is subscribed
+to the relevant -commits mailing list. If your are not subscribed to the commit
+list, all mail sent by Phabricator on your behalf will be held for moderation.</p>
+<p>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 <a class="reference external" href="http://reviews.llvm.org/diffusion/">Code Repository Browser</a>.</p>
+</div>
+<div class="section" id="requesting-a-review-via-the-command-line">
+<h2><a class="toc-backref" href="#id2">Requesting a review via the command line</a><a class="headerlink" href="#requesting-a-review-via-the-command-line" title="Permalink to this headline">¶</a></h2>
+<p>Phabricator has a tool called <em>Arcanist</em> to upload patches from
+the command line. To get you set up, follow the
+<a class="reference external" href="http://www.phabricator.com/docs/phabricator/article/Arcanist_Quick_Start.html">Arcanist Quick Start</a> instructions.</p>
+<p>You can learn more about how to use arc to interact with
+Phabricator in the <a class="reference external" href="http://www.phabricator.com/docs/phabricator/article/Arcanist_User_Guide.html">Arcanist User Guide</a>.</p>
+</div>
+<div class="section" id="requesting-a-review-via-the-web-interface">
+<h2><a class="toc-backref" href="#id3">Requesting a review via the web interface</a><a class="headerlink" href="#requesting-a-review-via-the-web-interface" title="Permalink to this headline">¶</a></h2>
+<p>The tool to create and review patches in Phabricator is called
+<em>Differential</em>.</p>
+<p>Note that you can upload patches created through various diff tools,
+including git and svn. To make reviews easier, please always include
+<strong>as much context as possible</strong> 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.</p>
+<p>To get a full diff, use one of the following commands (or just use Arcanist
+to upload your patch):</p>
+<ul class="simple">
+<li><tt class="docutils literal"><span class="pre">git</span> <span class="pre">diff</span> <span class="pre">-U999999</span> <span class="pre">other-branch</span></tt></li>
+<li><tt class="docutils literal"><span class="pre">svn</span> <span class="pre">diff</span> <span class="pre">--diff-cmd=diff</span> <span class="pre">-x</span> <span class="pre">-U999999</span></tt></li>
+</ul>
+<p>To upload a new patch:</p>
+<ul class="simple">
+<li>Click <em>Differential</em>.</li>
+<li>Click <em>+ Create Diff</em>.</li>
+<li>Paste the text diff or browse to the patch file. Click <em>Create Diff</em>.</li>
+<li>Leave the Repository field blank.</li>
+<li>Leave the drop down on <em>Create a new Revision...</em> and click <em>Continue</em>.</li>
+<li>Enter a descriptive title and summary. The title and summary are usually
+in the form of a <a class="reference internal" href="DeveloperPolicy.html#commit-messages"><em>commit message</em></a>.</li>
+<li>Add reviewers and mailing
+lists that you want to be included in the review. If your patch is
+for LLVM, add llvm-commits as a Subscriber; if your patch is for Clang,
+add cfe-commits.</li>
+<li>Leave the Repository and Project fields blank.</li>
+<li>Click <em>Save</em>.</li>
+</ul>
+<p>To submit an updated patch:</p>
+<ul class="simple">
+<li>Click <em>Differential</em>.</li>
+<li>Click <em>+ Create Diff</em>.</li>
+<li>Paste the updated diff or browse to the updated patch file. Click <em>Create Diff</em>.</li>
+<li>Select the review you want to from the <em>Attach To</em> dropdown and click
+<em>Continue</em>.</li>
+<li>Leave the Repository and Project fields blank.</li>
+<li>Add comments about the changes in the new diff. Click <em>Save</em>.</li>
+</ul>
+</div>
+<div class="section" id="reviewing-code-with-phabricator">
+<h2><a class="toc-backref" href="#id4">Reviewing code with Phabricator</a><a class="headerlink" href="#reviewing-code-with-phabricator" title="Permalink to this headline">¶</a></h2>
+<p>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.
+When you have added all your comments, scroll to the bottom of the page and
+click the Submit button.</p>
+<p>You can add overall comments in the text box at the bottom of the page.
+When you’re done, click the Submit button.</p>
+<p>Phabricator has many useful features, for example allowing you to select
+diffs between different versions of the patch as it was reviewed in the
+<em>Revision Update History</em>. Most features are self descriptive - explore, and
+if you have a question, drop by on #llvm in IRC to get help.</p>
+<p>Note that as e-mail is the system of reference for code reviews, and some
+people prefer it over a web interface, we do not generate automated mail
+when a review changes state, for example by clicking “Accept Revision” in
+the web interface. Thus, please type LGTM into the comment box to accept
+a change from Phabricator.</p>
+</div>
+<div class="section" id="committing-a-change">
+<h2><a class="toc-backref" href="#id5">Committing a change</a><a class="headerlink" href="#committing-a-change" title="Permalink to this headline">¶</a></h2>
+<p>Arcanist can manage the commit transparently. It will retrieve the description,
+reviewers, the <tt class="docutils literal"><span class="pre">Differential</span> <span class="pre">Revision</span></tt>, etc from the review and commit it to the repository.</p>
+<div class="highlight-python"><div class="highlight"><pre>arc patch D<Revision>
+arc commit --revision D<Revision>
+</pre></div>
+</div>
+<p>When committing an LLVM change that has been reviewed using
+Phabricator, the convention is for the commit message to end with the
+line:</p>
+<div class="highlight-python"><div class="highlight"><pre>Differential Revision: <URL>
+</pre></div>
+</div>
+<p>where <tt class="docutils literal"><span class="pre"><URL></span></tt> is the URL for the code review, starting with
+<tt class="docutils literal"><span class="pre">http://reviews.llvm.org/</span></tt>.</p>
+<p>Note that Arcanist will add this automatically.</p>
+<p>This allows people reading the version history to see the review for
+context. This also allows Phabricator to detect the commit, close the
+review, and add a link from the review to the commit.</p>
+</div>
+<div class="section" id="abandoning-a-change">
+<h2><a class="toc-backref" href="#id6">Abandoning a change</a><a class="headerlink" href="#abandoning-a-change" title="Permalink to this headline">¶</a></h2>
+<p>If you decide you should not commit the patch, you should explicitly abandon
+the review so that reviewers don’t think it is still open. In the web UI,
+scroll to the bottom of the page where normally you would enter an overall
+comment. In the drop-down Action list, which defaults to “Comment,” you should
+select “Abandon Revision” and then enter a comment explaining why. Click the
+Submit button to finish closing the review.</p>
+</div>
+<div class="section" id="status">
+<h2><a class="toc-backref" href="#id7">Status</a><a class="headerlink" href="#status" title="Permalink to this headline">¶</a></h2>
+<p>Please let us know whether you like it and what could be improved! We’re still
+working on setting up a bug tracker, but you can email klimek-at-google-dot-com
+and chandlerc-at-gmail-dot-com and CC the llvm-dev mailing list with questions
+until then. We also could use help implementing improvements. This sadly is
+really painful and hard because the Phabricator codebase is in PHP and not as
+testable as you might like. However, we’ve put exactly what we’re deploying up
+on an <a class="reference external" href="https://github.com/r4nt/llvm-reviews/">llvm-reviews GitHub project</a> where folks can hack on it and post pull
+requests. We’re looking into what the right long-term hosting for this is, but
+note that it is a derivative of an existing open source project, and so not
+trivially a good fit for an official LLVM project.</p>
+</div>
+</div>
+
+
+ </div>
+ </div>
+ <div class="clearer"></div>
+ </div>
+ <div class="related">
+ <h3>Navigation</h3>
+ <ul>
+ <li class="right" style="margin-right: 10px">
+ <a href="genindex.html" title="General Index"
+ >index</a></li>
+ <li class="right" >
+ <a href="ReleaseProcess.html" title="How To Validate a New Release"
+ >previous</a> |</li>
+ <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+ <li><a href="index.html">Documentation</a>»</li>
+
+ </ul>
+ </div>
+ <div class="footer">
+ © Copyright 2003-2016, LLVM Project.
+ Last updated on 2016-01-04.
+ Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.3.
+ </div>
+ </body>
+</html>
\ No newline at end of file
Added: www-releases/trunk/3.7.1/docs/ProgrammersManual.html
URL: http://llvm.org/viewvc/llvm-project/www-releases/trunk/3.7.1/docs/ProgrammersManual.html?rev=257950&view=auto
==============================================================================
--- www-releases/trunk/3.7.1/docs/ProgrammersManual.html (added)
+++ www-releases/trunk/3.7.1/docs/ProgrammersManual.html Fri Jan 15 17:13:16 2016
@@ -0,0 +1,2959 @@
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
+ <title>LLVM Programmerâs Manual — LLVM 3.7 documentation</title>
+
+ <link rel="stylesheet" href="_static/llvm-theme.css" type="text/css" />
+ <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
+
+ <script type="text/javascript">
+ var DOCUMENTATION_OPTIONS = {
+ URL_ROOT: './',
+ VERSION: '3.7',
+ COLLAPSE_INDEX: false,
+ FILE_SUFFIX: '.html',
+ HAS_SOURCE: true
+ };
+ </script>
+ <script type="text/javascript" src="_static/jquery.js"></script>
+ <script type="text/javascript" src="_static/underscore.js"></script>
+ <script type="text/javascript" src="_static/doctools.js"></script>
+ <link rel="top" title="LLVM 3.7 documentation" href="index.html" />
+ <link rel="next" title="LLVM Extensions" href="Extensions.html" />
+ <link rel="prev" title="How to set up LLVM-style RTTI for your class hierarchy" href="HowToSetUpLLVMStyleRTTI.html" />
+<style type="text/css">
+ table.right { float: right; margin-left: 20px; }
+ table.right td { border: 1px solid #ccc; }
+</style>
+
+ </head>
+ <body>
+<div class="logo">
+ <a href="index.html">
+ <img src="_static/logo.png"
+ alt="LLVM Logo" width="250" height="88"/></a>
+</div>
+
+ <div class="related">
+ <h3>Navigation</h3>
+ <ul>
+ <li class="right" style="margin-right: 10px">
+ <a href="genindex.html" title="General Index"
+ accesskey="I">index</a></li>
+ <li class="right" >
+ <a href="Extensions.html" title="LLVM Extensions"
+ accesskey="N">next</a> |</li>
+ <li class="right" >
+ <a href="HowToSetUpLLVMStyleRTTI.html" title="How to set up LLVM-style RTTI for your class hierarchy"
+ accesskey="P">previous</a> |</li>
+ <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+ <li><a href="index.html">Documentation</a>»</li>
+
+ </ul>
+ </div>
+
+
+ <div class="document">
+ <div class="documentwrapper">
+ <div class="body">
+
+ <div class="section" id="llvm-programmer-s-manual">
+<h1>LLVM Programmer’s Manual<a class="headerlink" href="#llvm-programmer-s-manual" title="Permalink to this headline">¶</a></h1>
+<div class="contents local topic" id="contents">
+<ul class="simple">
+<li><a class="reference internal" href="#introduction" id="id7">Introduction</a></li>
+<li><a class="reference internal" href="#general-information" id="id8">General Information</a><ul>
+<li><a class="reference internal" href="#the-c-standard-template-library" id="id9">The C++ Standard Template Library</a></li>
+<li><a class="reference internal" href="#other-useful-references" id="id10">Other useful references</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#important-and-useful-llvm-apis" id="id11">Important and useful LLVM APIs</a><ul>
+<li><a class="reference internal" href="#the-isa-cast-and-dyn-cast-templates" id="id12">The <tt class="docutils literal"><span class="pre">isa<></span></tt>, <tt class="docutils literal"><span class="pre">cast<></span></tt> and <tt class="docutils literal"><span class="pre">dyn_cast<></span></tt> templates</a></li>
+<li><a class="reference internal" href="#passing-strings-the-stringref-and-twine-classes" id="id13">Passing strings (the <tt class="docutils literal"><span class="pre">StringRef</span></tt> and <tt class="docutils literal"><span class="pre">Twine</span></tt> classes)</a><ul>
+<li><a class="reference internal" href="#the-stringref-class" id="id14">The <tt class="docutils literal"><span class="pre">StringRef</span></tt> class</a></li>
+<li><a class="reference internal" href="#the-twine-class" id="id15">The <tt class="docutils literal"><span class="pre">Twine</span></tt> class</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#passing-functions-and-other-callable-objects" id="id16">Passing functions and other callable objects</a><ul>
+<li><a class="reference internal" href="#function-template" id="id17">Function template</a></li>
+<li><a class="reference internal" href="#the-function-ref-class-template" id="id18">The <tt class="docutils literal"><span class="pre">function_ref</span></tt> class template</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#the-debug-macro-and-debug-option" id="id19">The <tt class="docutils literal"><span class="pre">DEBUG()</span></tt> macro and <tt class="docutils literal"><span class="pre">-debug</span></tt> option</a><ul>
+<li><a class="reference internal" href="#fine-grained-debug-info-with-debug-type-and-the-debug-only-option" id="id20">Fine grained debug info with <tt class="docutils literal"><span class="pre">DEBUG_TYPE</span></tt> and the <tt class="docutils literal"><span class="pre">-debug-only</span></tt> option</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#the-statistic-class-stats-option" id="id21">The <tt class="docutils literal"><span class="pre">Statistic</span></tt> class & <tt class="docutils literal"><span class="pre">-stats</span></tt> option</a></li>
+<li><a class="reference internal" href="#viewing-graphs-while-debugging-code" id="id22">Viewing graphs while debugging code</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#picking-the-right-data-structure-for-a-task" id="id23">Picking the Right Data Structure for a Task</a><ul>
+<li><a class="reference internal" href="#sequential-containers-std-vector-std-list-etc" id="id24">Sequential Containers (std::vector, std::list, etc)</a><ul>
+<li><a class="reference internal" href="#llvm-adt-arrayref-h" id="id25">llvm/ADT/ArrayRef.h</a></li>
+<li><a class="reference internal" href="#fixed-size-arrays" id="id26">Fixed Size Arrays</a></li>
+<li><a class="reference internal" href="#heap-allocated-arrays" id="id27">Heap Allocated Arrays</a></li>
+<li><a class="reference internal" href="#llvm-adt-tinyptrvector-h" id="id28">llvm/ADT/TinyPtrVector.h</a></li>
+<li><a class="reference internal" href="#llvm-adt-smallvector-h" id="id29">llvm/ADT/SmallVector.h</a></li>
+<li><a class="reference internal" href="#vector" id="id30"><vector></a></li>
+<li><a class="reference internal" href="#deque" id="id31"><deque></a></li>
+<li><a class="reference internal" href="#list" id="id32"><list></a></li>
+<li><a class="reference internal" href="#llvm-adt-ilist-h" id="id33">llvm/ADT/ilist.h</a></li>
+<li><a class="reference internal" href="#llvm-adt-packedvector-h" id="id34">llvm/ADT/PackedVector.h</a></li>
+<li><a class="reference internal" href="#ilist-traits" id="id35">ilist_traits</a></li>
+<li><a class="reference internal" href="#iplist" id="id36">iplist</a></li>
+<li><a class="reference internal" href="#llvm-adt-ilist-node-h" id="id37">llvm/ADT/ilist_node.h</a></li>
+<li><a class="reference internal" href="#sentinels" id="id38">Sentinels</a></li>
+<li><a class="reference internal" href="#other-sequential-container-options" id="id39">Other Sequential Container options</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#string-like-containers" id="id40">String-like containers</a><ul>
+<li><a class="reference internal" href="#llvm-adt-stringref-h" id="id41">llvm/ADT/StringRef.h</a></li>
+<li><a class="reference internal" href="#llvm-adt-twine-h" id="id42">llvm/ADT/Twine.h</a></li>
+<li><a class="reference internal" href="#llvm-adt-smallstring-h" id="id43">llvm/ADT/SmallString.h</a></li>
+<li><a class="reference internal" href="#std-string" id="id44">std::string</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#set-like-containers-std-set-smallset-setvector-etc" id="id45">Set-Like Containers (std::set, SmallSet, SetVector, etc)</a><ul>
+<li><a class="reference internal" href="#a-sorted-vector" id="id46">A sorted ‘vector’</a></li>
+<li><a class="reference internal" href="#llvm-adt-smallset-h" id="id47">llvm/ADT/SmallSet.h</a></li>
+<li><a class="reference internal" href="#llvm-adt-smallptrset-h" id="id48">llvm/ADT/SmallPtrSet.h</a></li>
+<li><a class="reference internal" href="#llvm-adt-stringset-h" id="id49">llvm/ADT/StringSet.h</a></li>
+<li><a class="reference internal" href="#llvm-adt-denseset-h" id="id50">llvm/ADT/DenseSet.h</a></li>
+<li><a class="reference internal" href="#llvm-adt-sparseset-h" id="id51">llvm/ADT/SparseSet.h</a></li>
+<li><a class="reference internal" href="#llvm-adt-sparsemultiset-h" id="id52">llvm/ADT/SparseMultiSet.h</a></li>
+<li><a class="reference internal" href="#llvm-adt-foldingset-h" id="id53">llvm/ADT/FoldingSet.h</a></li>
+<li><a class="reference internal" href="#set" id="id54"><set></a></li>
+<li><a class="reference internal" href="#llvm-adt-setvector-h" id="id55">llvm/ADT/SetVector.h</a></li>
+<li><a class="reference internal" href="#llvm-adt-uniquevector-h" id="id56">llvm/ADT/UniqueVector.h</a></li>
+<li><a class="reference internal" href="#llvm-adt-immutableset-h" id="id57">llvm/ADT/ImmutableSet.h</a></li>
+<li><a class="reference internal" href="#other-set-like-container-options" id="id58">Other Set-Like Container Options</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#map-like-containers-std-map-densemap-etc" id="id59">Map-Like Containers (std::map, DenseMap, etc)</a><ul>
+<li><a class="reference internal" href="#dss-sortedvectormap" id="id60">A sorted ‘vector’</a></li>
+<li><a class="reference internal" href="#llvm-adt-stringmap-h" id="id61">llvm/ADT/StringMap.h</a></li>
+<li><a class="reference internal" href="#llvm-adt-indexedmap-h" id="id62">llvm/ADT/IndexedMap.h</a></li>
+<li><a class="reference internal" href="#llvm-adt-densemap-h" id="id63">llvm/ADT/DenseMap.h</a></li>
+<li><a class="reference internal" href="#llvm-ir-valuemap-h" id="id64">llvm/IR/ValueMap.h</a></li>
+<li><a class="reference internal" href="#llvm-adt-intervalmap-h" id="id65">llvm/ADT/IntervalMap.h</a></li>
+<li><a class="reference internal" href="#map" id="id66"><map></a></li>
+<li><a class="reference internal" href="#llvm-adt-mapvector-h" id="id67">llvm/ADT/MapVector.h</a></li>
+<li><a class="reference internal" href="#llvm-adt-inteqclasses-h" id="id68">llvm/ADT/IntEqClasses.h</a></li>
+<li><a class="reference internal" href="#llvm-adt-immutablemap-h" id="id69">llvm/ADT/ImmutableMap.h</a></li>
+<li><a class="reference internal" href="#other-map-like-container-options" id="id70">Other Map-Like Container Options</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#bit-storage-containers-bitvector-sparsebitvector" id="id71">Bit storage containers (BitVector, SparseBitVector)</a><ul>
+<li><a class="reference internal" href="#bitvector" id="id72">BitVector</a></li>
+<li><a class="reference internal" href="#smallbitvector" id="id73">SmallBitVector</a></li>
+<li><a class="reference internal" href="#sparsebitvector" id="id74">SparseBitVector</a></li>
+</ul>
+</li>
+</ul>
+</li>
+<li><a class="reference internal" href="#helpful-hints-for-common-operations" id="id75">Helpful Hints for Common Operations</a><ul>
+<li><a class="reference internal" href="#basic-inspection-and-traversal-routines" id="id76">Basic Inspection and Traversal Routines</a><ul>
+<li><a class="reference internal" href="#iterating-over-the-basicblock-in-a-function" id="id77">Iterating over the <tt class="docutils literal"><span class="pre">BasicBlock</span></tt> in a <tt class="docutils literal"><span class="pre">Function</span></tt></a></li>
+<li><a class="reference internal" href="#iterating-over-the-instruction-in-a-basicblock" id="id78">Iterating over the <tt class="docutils literal"><span class="pre">Instruction</span></tt> in a <tt class="docutils literal"><span class="pre">BasicBlock</span></tt></a></li>
+<li><a class="reference internal" href="#iterating-over-the-instruction-in-a-function" id="id79">Iterating over the <tt class="docutils literal"><span class="pre">Instruction</span></tt> in a <tt class="docutils literal"><span class="pre">Function</span></tt></a></li>
+<li><a class="reference internal" href="#turning-an-iterator-into-a-class-pointer-and-vice-versa" id="id80">Turning an iterator into a class pointer (and vice-versa)</a></li>
+<li><a class="reference internal" href="#finding-call-sites-a-slightly-more-complex-example" id="id81">Finding call sites: a slightly more complex example</a></li>
+<li><a class="reference internal" href="#treating-calls-and-invokes-the-same-way" id="id82">Treating calls and invokes the same way</a></li>
+<li><a class="reference internal" href="#iterating-over-def-use-use-def-chains" id="id83">Iterating over def-use & use-def chains</a></li>
+<li><a class="reference internal" href="#iterating-over-predecessors-successors-of-blocks" id="id84">Iterating over predecessors & successors of blocks</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#making-simple-changes" id="id85">Making simple changes</a><ul>
+<li><a class="reference internal" href="#creating-and-inserting-new-instructions" id="id86">Creating and inserting new <tt class="docutils literal"><span class="pre">Instruction</span></tt>s</a></li>
+<li><a class="reference internal" href="#deleting-instructions" id="id87">Deleting Instructions</a></li>
+<li><a class="reference internal" href="#replacing-an-instruction-with-another-value" id="id88">Replacing an Instruction with another Value</a><ul>
+<li><a class="reference internal" href="#replacing-individual-instructions" id="id89">Replacing individual instructions</a></li>
+<li><a class="reference internal" href="#schanges-deleting-sub" id="id90">Deleting Instructions</a></li>
+<li><a class="reference internal" href="#replacing-multiple-uses-of-users-and-values" id="id91">Replacing multiple uses of Users and Values</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#deleting-globalvariables" id="id92">Deleting GlobalVariables</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#how-to-create-types" id="id93">How to Create Types</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#threads-and-llvm" id="id94">Threads and LLVM</a><ul>
+<li><a class="reference internal" href="#ending-execution-with-llvm-shutdown" id="id95">Ending Execution with <tt class="docutils literal"><span class="pre">llvm_shutdown()</span></tt></a></li>
+<li><a class="reference internal" href="#lazy-initialization-with-managedstatic" id="id96">Lazy Initialization with <tt class="docutils literal"><span class="pre">ManagedStatic</span></tt></a></li>
+<li><a class="reference internal" href="#achieving-isolation-with-llvmcontext" id="id97">Achieving Isolation with <tt class="docutils literal"><span class="pre">LLVMContext</span></tt></a></li>
+<li><a class="reference internal" href="#threads-and-the-jit" id="id98">Threads and the JIT</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#advanced-topics" id="id99">Advanced Topics</a><ul>
+<li><a class="reference internal" href="#the-valuesymboltable-class" id="id100">The <tt class="docutils literal"><span class="pre">ValueSymbolTable</span></tt> class</a></li>
+<li><a class="reference internal" href="#the-user-and-owned-use-classes-memory-layout" id="id101">The <tt class="docutils literal"><span class="pre">User</span></tt> and owned <tt class="docutils literal"><span class="pre">Use</span></tt> classes’ memory layout</a><ul>
+<li><a class="reference internal" href="#interaction-and-relationship-between-user-and-use-objects" id="id102">Interaction and relationship between <tt class="docutils literal"><span class="pre">User</span></tt> and <tt class="docutils literal"><span class="pre">Use</span></tt> objects</a></li>
+<li><a class="reference internal" href="#the-waymarking-algorithm" id="id103">The waymarking algorithm</a></li>
+<li><a class="reference internal" href="#reference-implementation" id="id104">Reference implementation</a></li>
+<li><a class="reference internal" href="#tagging-considerations" id="id105">Tagging considerations</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#designing-type-hiercharies-and-polymorphic-interfaces" id="id106">Designing Type Hiercharies and Polymorphic Interfaces</a></li>
+<li><a class="reference internal" href="#abi-breaking-checks" id="id107">ABI Breaking Checks</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#the-core-llvm-class-hierarchy-reference" id="id108">The Core LLVM Class Hierarchy Reference</a><ul>
+<li><a class="reference internal" href="#the-type-class-and-derived-types" id="id109">The Type class and Derived Types</a><ul>
+<li><a class="reference internal" href="#important-public-methods" id="id110">Important Public Methods</a></li>
+<li><a class="reference internal" href="#important-derived-types" id="id111">Important Derived Types</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#the-module-class" id="id112">The <tt class="docutils literal"><span class="pre">Module</span></tt> class</a><ul>
+<li><a class="reference internal" href="#important-public-members-of-the-module-class" id="id113">Important Public Members of the <tt class="docutils literal"><span class="pre">Module</span></tt> class</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#the-value-class" id="id114">The <tt class="docutils literal"><span class="pre">Value</span></tt> class</a><ul>
+<li><a class="reference internal" href="#important-public-members-of-the-value-class" id="id115">Important Public Members of the <tt class="docutils literal"><span class="pre">Value</span></tt> class</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#the-user-class" id="id116">The <tt class="docutils literal"><span class="pre">User</span></tt> class</a><ul>
+<li><a class="reference internal" href="#important-public-members-of-the-user-class" id="id117">Important Public Members of the <tt class="docutils literal"><span class="pre">User</span></tt> class</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#the-instruction-class" id="id118">The <tt class="docutils literal"><span class="pre">Instruction</span></tt> class</a><ul>
+<li><a class="reference internal" href="#important-subclasses-of-the-instruction-class" id="id119">Important Subclasses of the <tt class="docutils literal"><span class="pre">Instruction</span></tt> class</a></li>
+<li><a class="reference internal" href="#important-public-members-of-the-instruction-class" id="id120">Important Public Members of the <tt class="docutils literal"><span class="pre">Instruction</span></tt> class</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#the-constant-class-and-subclasses" id="id121">The <tt class="docutils literal"><span class="pre">Constant</span></tt> class and subclasses</a><ul>
+<li><a class="reference internal" href="#important-subclasses-of-constant" id="id122">Important Subclasses of Constant</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#the-globalvalue-class" id="id123">The <tt class="docutils literal"><span class="pre">GlobalValue</span></tt> class</a><ul>
+<li><a class="reference internal" href="#important-public-members-of-the-globalvalue-class" id="id124">Important Public Members of the <tt class="docutils literal"><span class="pre">GlobalValue</span></tt> class</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#the-function-class" id="id125">The <tt class="docutils literal"><span class="pre">Function</span></tt> class</a><ul>
+<li><a class="reference internal" href="#important-public-members-of-the-function" id="id126">Important Public Members of the <tt class="docutils literal"><span class="pre">Function</span></tt></a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#the-globalvariable-class" id="id127">The <tt class="docutils literal"><span class="pre">GlobalVariable</span></tt> class</a><ul>
+<li><a class="reference internal" href="#important-public-members-of-the-globalvariable-class" id="id128">Important Public Members of the <tt class="docutils literal"><span class="pre">GlobalVariable</span></tt> class</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#the-basicblock-class" id="id129">The <tt class="docutils literal"><span class="pre">BasicBlock</span></tt> class</a><ul>
+<li><a class="reference internal" href="#important-public-members-of-the-basicblock-class" id="id130">Important Public Members of the <tt class="docutils literal"><span class="pre">BasicBlock</span></tt> class</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#the-argument-class" id="id131">The <tt class="docutils literal"><span class="pre">Argument</span></tt> class</a></li>
+</ul>
+</li>
+</ul>
+</div>
+<div class="admonition warning">
+<p class="first admonition-title">Warning</p>
+<p class="last">This is always a work in progress.</p>
+</div>
+<div class="section" id="introduction">
+<span id="id1"></span><h2><a class="toc-backref" href="#id7">Introduction</a><a class="headerlink" href="#introduction" title="Permalink to this headline">¶</a></h2>
+<p>This document is meant to highlight some of the important classes and interfaces
+available in the LLVM source-base. This manual is not intended to explain what
+LLVM is, how it works, and what LLVM code looks like. It assumes that you know
+the basics of LLVM and are interested in writing transformations or otherwise
+analyzing or manipulating the code.</p>
+<p>This document should get you oriented so that you can find your way in the
+continuously growing source code that makes up the LLVM infrastructure. Note
+that this manual is not intended to serve as a replacement for reading the
+source code, so if you think there should be a method in one of these classes to
+do something, but it’s not listed, check the source. Links to the <a class="reference external" href="http://llvm.org/doxygen/">doxygen</a> sources are provided to make this as easy as
+possible.</p>
+<p>The first section of this document describes general information that is useful
+to know when working in the LLVM infrastructure, and the second describes the
+Core LLVM classes. In the future this manual will be extended with information
+describing how to use extension libraries, such as dominator information, CFG
+traversal routines, and useful utilities like the <tt class="docutils literal"><span class="pre">InstVisitor</span></tt> (<a class="reference external" href="http://llvm.org/doxygen/InstVisitor_8h-source.html">doxygen</a>) template.</p>
+</div>
+<div class="section" id="general-information">
+<span id="general"></span><h2><a class="toc-backref" href="#id8">General Information</a><a class="headerlink" href="#general-information" title="Permalink to this headline">¶</a></h2>
+<p>This section contains general information that is useful if you are working in
+the LLVM source-base, but that isn’t specific to any particular API.</p>
+<div class="section" id="the-c-standard-template-library">
+<span id="stl"></span><h3><a class="toc-backref" href="#id9">The C++ Standard Template Library</a><a class="headerlink" href="#the-c-standard-template-library" title="Permalink to this headline">¶</a></h3>
+<p>LLVM makes heavy use of the C++ Standard Template Library (STL), perhaps much
+more than you are used to, or have seen before. Because of this, you might want
+to do a little background reading in the techniques used and capabilities of the
+library. There are many good pages that discuss the STL, and several books on
+the subject that you can get, so it will not be discussed in this document.</p>
+<p>Here are some useful links:</p>
+<ol class="arabic simple">
+<li><a class="reference external" href="http://en.cppreference.com/w/">cppreference.com</a> - an excellent
+reference for the STL and other parts of the standard C++ library.</li>
+<li><a class="reference external" href="http://www.tempest-sw.com/cpp/">C++ In a Nutshell</a> - This is an O’Reilly
+book in the making. It has a decent Standard Library Reference that rivals
+Dinkumware’s, and is unfortunately no longer free since the book has been
+published.</li>
+<li><a class="reference external" href="http://www.parashift.com/c++-faq-lite/">C++ Frequently Asked Questions</a>.</li>
+<li><a class="reference external" href="http://www.sgi.com/tech/stl/">SGI’s STL Programmer’s Guide</a> - Contains a
+useful <a class="reference external" href="http://www.sgi.com/tech/stl/stl_introduction.html">Introduction to the STL</a>.</li>
+<li><a class="reference external" href="http://www.research.att.com/%7Ebs/C++.html">Bjarne Stroustrup’s C++ Page</a>.</li>
+<li><a class="reference external" href="http://www.mindview.net/Books/TICPP/ThinkingInCPP2e.html">Bruce Eckel’s Thinking in C++, 2nd ed. Volume 2 Revision 4.0
+(even better, get the book)</a>.</li>
+</ol>
+<p>You are also encouraged to take a look at the <a class="reference internal" href="CodingStandards.html"><em>LLVM Coding Standards</em></a> guide which focuses on how to write maintainable code more
+than where to put your curly braces.</p>
+</div>
+<div class="section" id="other-useful-references">
+<span id="resources"></span><h3><a class="toc-backref" href="#id10">Other useful references</a><a class="headerlink" href="#other-useful-references" title="Permalink to this headline">¶</a></h3>
+<ol class="arabic simple">
+<li><a class="reference external" href="http://www.fortran-2000.com/ArnaudRecipes/sharedlib.html">Using static and shared libraries across platforms</a></li>
+</ol>
+</div>
+</div>
+<div class="section" id="important-and-useful-llvm-apis">
+<span id="apis"></span><h2><a class="toc-backref" href="#id11">Important and useful LLVM APIs</a><a class="headerlink" href="#important-and-useful-llvm-apis" title="Permalink to this headline">¶</a></h2>
+<p>Here we highlight some LLVM APIs that are generally useful and good to know
+about when writing transformations.</p>
+<div class="section" id="the-isa-cast-and-dyn-cast-templates">
+<span id="isa"></span><h3><a class="toc-backref" href="#id12">The <tt class="docutils literal"><span class="pre">isa<></span></tt>, <tt class="docutils literal"><span class="pre">cast<></span></tt> and <tt class="docutils literal"><span class="pre">dyn_cast<></span></tt> templates</a><a class="headerlink" href="#the-isa-cast-and-dyn-cast-templates" title="Permalink to this headline">¶</a></h3>
+<p>The LLVM source-base makes extensive use of a custom form of RTTI. These
+templates have many similarities to the C++ <tt class="docutils literal"><span class="pre">dynamic_cast<></span></tt> operator, but
+they don’t have some drawbacks (primarily stemming from the fact that
+<tt class="docutils literal"><span class="pre">dynamic_cast<></span></tt> only works on classes that have a v-table). Because they are
+used so often, you must know what they do and how they work. All of these
+templates are defined in the <tt class="docutils literal"><span class="pre">llvm/Support/Casting.h</span></tt> (<a class="reference external" href="http://llvm.org/doxygen/Casting_8h-source.html">doxygen</a>) file (note that you very
+rarely have to include this file directly).</p>
+<dl class="docutils">
+<dt><tt class="docutils literal"><span class="pre">isa<></span></tt>:</dt>
+<dd>The <tt class="docutils literal"><span class="pre">isa<></span></tt> operator works exactly like the Java “<tt class="docutils literal"><span class="pre">instanceof</span></tt>” operator.
+It returns true or false depending on whether a reference or pointer points to
+an instance of the specified class. This can be very useful for constraint
+checking of various sorts (example below).</dd>
+<dt><tt class="docutils literal"><span class="pre">cast<></span></tt>:</dt>
+<dd><p class="first">The <tt class="docutils literal"><span class="pre">cast<></span></tt> operator is a “checked cast” operation. It converts a pointer
+or reference from a base class to a derived class, causing an assertion
+failure if it is not really an instance of the right type. This should be
+used in cases where you have some information that makes you believe that
+something is of the right type. An example of the <tt class="docutils literal"><span class="pre">isa<></span></tt> and <tt class="docutils literal"><span class="pre">cast<></span></tt>
+template is:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="k">static</span> <span class="kt">bool</span> <span class="nf">isLoopInvariant</span><span class="p">(</span><span class="k">const</span> <span class="n">Value</span> <span class="o">*</span><span class="n">V</span><span class="p">,</span> <span class="k">const</span> <span class="n">Loop</span> <span class="o">*</span><span class="n">L</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">isa</span><span class="o"><</span><span class="n">Constant</span><span class="o">></span><span class="p">(</span><span class="n">V</span><span class="p">)</span> <span class="o">||</span> <span class="n">isa</span><span class="o"><</span><span class="n">Argument</span><span class="o">></span><span class="p">(</span><span class="n">V</span><span class="p">)</span> <span class="o">||</span> <span class="n">isa</span><span class="o"><</span><span class="n">GlobalValue</span><span class="o">></span><span class="p">(</span><span class="n">V</span><span class="p">))</span>
+ <span class="k">return</span> <span class="nb">true</span><span class="p">;</span>
+
+ <span class="c1">// Otherwise, it must be an instruction...</span>
+ <span class="k">return</span> <span class="o">!</span><span class="n">L</span><span class="o">-></span><span class="n">contains</span><span class="p">(</span><span class="n">cast</span><span class="o"><</span><span class="n">Instruction</span><span class="o">></span><span class="p">(</span><span class="n">V</span><span class="p">)</span><span class="o">-></span><span class="n">getParent</span><span class="p">());</span>
+<span class="p">}</span>
+</pre></div>
+</div>
+<p class="last">Note that you should <strong>not</strong> use an <tt class="docutils literal"><span class="pre">isa<></span></tt> test followed by a <tt class="docutils literal"><span class="pre">cast<></span></tt>,
+for that use the <tt class="docutils literal"><span class="pre">dyn_cast<></span></tt> operator.</p>
+</dd>
+<dt><tt class="docutils literal"><span class="pre">dyn_cast<></span></tt>:</dt>
+<dd><p class="first">The <tt class="docutils literal"><span class="pre">dyn_cast<></span></tt> operator is a “checking cast” operation. It checks to see
+if the operand is of the specified type, and if so, returns a pointer to it
+(this operator does not work with references). If the operand is not of the
+correct type, a null pointer is returned. Thus, this works very much like
+the <tt class="docutils literal"><span class="pre">dynamic_cast<></span></tt> operator in C++, and should be used in the same
+circumstances. Typically, the <tt class="docutils literal"><span class="pre">dyn_cast<></span></tt> operator is used in an <tt class="docutils literal"><span class="pre">if</span></tt>
+statement or some other flow control statement like this:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="k">if</span> <span class="p">(</span><span class="n">AllocationInst</span> <span class="o">*</span><span class="n">AI</span> <span class="o">=</span> <span class="n">dyn_cast</span><span class="o"><</span><span class="n">AllocationInst</span><span class="o">></span><span class="p">(</span><span class="n">Val</span><span class="p">))</span> <span class="p">{</span>
+ <span class="c1">// ...</span>
+<span class="p">}</span>
+</pre></div>
+</div>
+<p>This form of the <tt class="docutils literal"><span class="pre">if</span></tt> statement effectively combines together a call to
+<tt class="docutils literal"><span class="pre">isa<></span></tt> and a call to <tt class="docutils literal"><span class="pre">cast<></span></tt> into one statement, which is very
+convenient.</p>
+<p class="last">Note that the <tt class="docutils literal"><span class="pre">dyn_cast<></span></tt> operator, like C++’s <tt class="docutils literal"><span class="pre">dynamic_cast<></span></tt> or Java’s
+<tt class="docutils literal"><span class="pre">instanceof</span></tt> operator, can be abused. In particular, you should not use big
+chained <tt class="docutils literal"><span class="pre">if/then/else</span></tt> blocks to check for lots of different variants of
+classes. If you find yourself wanting to do this, it is much cleaner and more
+efficient to use the <tt class="docutils literal"><span class="pre">InstVisitor</span></tt> class to dispatch over the instruction
+type directly.</p>
+</dd>
+<dt><tt class="docutils literal"><span class="pre">cast_or_null<></span></tt>:</dt>
+<dd>The <tt class="docutils literal"><span class="pre">cast_or_null<></span></tt> operator works just like the <tt class="docutils literal"><span class="pre">cast<></span></tt> operator,
+except that it allows for a null pointer as an argument (which it then
+propagates). This can sometimes be useful, allowing you to combine several
+null checks into one.</dd>
+<dt><tt class="docutils literal"><span class="pre">dyn_cast_or_null<></span></tt>:</dt>
+<dd>The <tt class="docutils literal"><span class="pre">dyn_cast_or_null<></span></tt> operator works just like the <tt class="docutils literal"><span class="pre">dyn_cast<></span></tt>
+operator, except that it allows for a null pointer as an argument (which it
+then propagates). This can sometimes be useful, allowing you to combine
+several null checks into one.</dd>
+</dl>
+<p>These five templates can be used with any classes, whether they have a v-table
+or not. If you want to add support for these templates, see the document
+<a class="reference internal" href="HowToSetUpLLVMStyleRTTI.html"><em>How to set up LLVM-style RTTI for your class hierarchy</em></a></p>
+</div>
+<div class="section" id="passing-strings-the-stringref-and-twine-classes">
+<span id="string-apis"></span><h3><a class="toc-backref" href="#id13">Passing strings (the <tt class="docutils literal"><span class="pre">StringRef</span></tt> and <tt class="docutils literal"><span class="pre">Twine</span></tt> classes)</a><a class="headerlink" href="#passing-strings-the-stringref-and-twine-classes" title="Permalink to this headline">¶</a></h3>
+<p>Although LLVM generally does not do much string manipulation, we do have several
+important APIs which take strings. Two important examples are the Value class
+– which has names for instructions, functions, etc. – and the <tt class="docutils literal"><span class="pre">StringMap</span></tt>
+class which is used extensively in LLVM and Clang.</p>
+<p>These are generic classes, and they need to be able to accept strings which may
+have embedded null characters. Therefore, they cannot simply take a <tt class="docutils literal"><span class="pre">const</span>
+<span class="pre">char</span> <span class="pre">*</span></tt>, and taking a <tt class="docutils literal"><span class="pre">const</span> <span class="pre">std::string&</span></tt> requires clients to perform a heap
+allocation which is usually unnecessary. Instead, many LLVM APIs use a
+<tt class="docutils literal"><span class="pre">StringRef</span></tt> or a <tt class="docutils literal"><span class="pre">const</span> <span class="pre">Twine&</span></tt> for passing strings efficiently.</p>
+<div class="section" id="the-stringref-class">
+<span id="stringref"></span><h4><a class="toc-backref" href="#id14">The <tt class="docutils literal"><span class="pre">StringRef</span></tt> class</a><a class="headerlink" href="#the-stringref-class" title="Permalink to this headline">¶</a></h4>
+<p>The <tt class="docutils literal"><span class="pre">StringRef</span></tt> data type represents a reference to a constant string (a
+character array and a length) and supports the common operations available on
+<tt class="docutils literal"><span class="pre">std::string</span></tt>, but does not require heap allocation.</p>
+<p>It can be implicitly constructed using a C style null-terminated string, an
+<tt class="docutils literal"><span class="pre">std::string</span></tt>, or explicitly with a character pointer and length. For
+example, the <tt class="docutils literal"><span class="pre">StringRef</span></tt> find function is declared as:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">iterator</span> <span class="nf">find</span><span class="p">(</span><span class="n">StringRef</span> <span class="n">Key</span><span class="p">);</span>
+</pre></div>
+</div>
+<p>and clients can call it using any one of:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">Map</span><span class="p">.</span><span class="n">find</span><span class="p">(</span><span class="s">"foo"</span><span class="p">);</span> <span class="c1">// Lookup "foo"</span>
+<span class="n">Map</span><span class="p">.</span><span class="n">find</span><span class="p">(</span><span class="n">std</span><span class="o">::</span><span class="n">string</span><span class="p">(</span><span class="s">"bar"</span><span class="p">));</span> <span class="c1">// Lookup "bar"</span>
+<span class="n">Map</span><span class="p">.</span><span class="n">find</span><span class="p">(</span><span class="n">StringRef</span><span class="p">(</span><span class="s">"</span><span class="se">\0</span><span class="s">baz"</span><span class="p">,</span> <span class="mi">4</span><span class="p">));</span> <span class="c1">// Lookup "\0baz"</span>
+</pre></div>
+</div>
+<p>Similarly, APIs which need to return a string may return a <tt class="docutils literal"><span class="pre">StringRef</span></tt>
+instance, which can be used directly or converted to an <tt class="docutils literal"><span class="pre">std::string</span></tt> using
+the <tt class="docutils literal"><span class="pre">str</span></tt> member function. See <tt class="docutils literal"><span class="pre">llvm/ADT/StringRef.h</span></tt> (<a class="reference external" href="http://llvm.org/doxygen/classllvm_1_1StringRef_8h-source.html">doxygen</a>) for more
+information.</p>
+<p>You should rarely use the <tt class="docutils literal"><span class="pre">StringRef</span></tt> class directly, because it contains
+pointers to external memory it is not generally safe to store an instance of the
+class (unless you know that the external storage will not be freed).
+<tt class="docutils literal"><span class="pre">StringRef</span></tt> is small and pervasive enough in LLVM that it should always be
+passed by value.</p>
+</div>
+<div class="section" id="the-twine-class">
+<h4><a class="toc-backref" href="#id15">The <tt class="docutils literal"><span class="pre">Twine</span></tt> class</a><a class="headerlink" href="#the-twine-class" title="Permalink to this headline">¶</a></h4>
+<p>The <tt class="docutils literal"><span class="pre">Twine</span></tt> (<a class="reference external" href="http://llvm.org/doxygen/classllvm_1_1Twine.html">doxygen</a>)
+class is an efficient way for APIs to accept concatenated strings. For example,
+a common LLVM paradigm is to name one instruction based on the name of another
+instruction with a suffix, for example:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">New</span> <span class="o">=</span> <span class="n">CmpInst</span><span class="o">::</span><span class="n">Create</span><span class="p">(...,</span> <span class="n">SO</span><span class="o">-></span><span class="n">getName</span><span class="p">()</span> <span class="o">+</span> <span class="s">".cmp"</span><span class="p">);</span>
+</pre></div>
+</div>
+<p>The <tt class="docutils literal"><span class="pre">Twine</span></tt> class is effectively a lightweight <a class="reference external" href="http://en.wikipedia.org/wiki/Rope_(computer_science)">rope</a> which points to
+temporary (stack allocated) objects. Twines can be implicitly constructed as
+the result of the plus operator applied to strings (i.e., a C strings, an
+<tt class="docutils literal"><span class="pre">std::string</span></tt>, or a <tt class="docutils literal"><span class="pre">StringRef</span></tt>). The twine delays the actual concatenation
+of strings until it is actually required, at which point it can be efficiently
+rendered directly into a character array. This avoids unnecessary heap
+allocation involved in constructing the temporary results of string
+concatenation. See <tt class="docutils literal"><span class="pre">llvm/ADT/Twine.h</span></tt> (<a class="reference external" href="http://llvm.org/doxygen/Twine_8h_source.html">doxygen</a>) and <a class="reference internal" href="#dss-twine"><em>here</em></a>
+for more information.</p>
+<p>As with a <tt class="docutils literal"><span class="pre">StringRef</span></tt>, <tt class="docutils literal"><span class="pre">Twine</span></tt> objects point to external memory and should
+almost never be stored or mentioned directly. They are intended solely for use
+when defining a function which should be able to efficiently accept concatenated
+strings.</p>
+</div>
+</div>
+<div class="section" id="passing-functions-and-other-callable-objects">
+<span id="function-apis"></span><h3><a class="toc-backref" href="#id16">Passing functions and other callable objects</a><a class="headerlink" href="#passing-functions-and-other-callable-objects" title="Permalink to this headline">¶</a></h3>
+<p>Sometimes you may want a function to be passed a callback object. In order to
+support lambda expressions and other function objects, you should not use the
+traditional C approach of taking a function pointer and an opaque cookie:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="kt">void</span> <span class="nf">takeCallback</span><span class="p">(</span><span class="kt">bool</span> <span class="p">(</span><span class="o">*</span><span class="n">Callback</span><span class="p">)(</span><span class="n">Function</span> <span class="o">*</span><span class="p">,</span> <span class="kt">void</span> <span class="o">*</span><span class="p">),</span> <span class="kt">void</span> <span class="o">*</span><span class="n">Cookie</span><span class="p">);</span>
+</pre></div>
+</div>
+<p>Instead, use one of the following approaches:</p>
+<div class="section" id="function-template">
+<h4><a class="toc-backref" href="#id17">Function template</a><a class="headerlink" href="#function-template" title="Permalink to this headline">¶</a></h4>
+<p>If you don’t mind putting the definition of your function into a header file,
+make it a function template that is templated on the callable type.</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="k">template</span><span class="o"><</span><span class="k">typename</span> <span class="n">Callable</span><span class="o">></span>
+<span class="kt">void</span> <span class="n">takeCallback</span><span class="p">(</span><span class="n">Callable</span> <span class="n">Callback</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">Callback</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">);</span>
+<span class="p">}</span>
+</pre></div>
+</div>
+</div>
+<div class="section" id="the-function-ref-class-template">
+<h4><a class="toc-backref" href="#id18">The <tt class="docutils literal"><span class="pre">function_ref</span></tt> class template</a><a class="headerlink" href="#the-function-ref-class-template" title="Permalink to this headline">¶</a></h4>
+<p>The <tt class="docutils literal"><span class="pre">function_ref</span></tt>
+(<a class="reference external" href="http://llvm.org/doxygen/classllvm_1_1function_ref.html">doxygen</a>) class
+template represents a reference to a callable object, templated over the type
+of the callable. This is a good choice for passing a callback to a function,
+if you don’t need to hold onto the callback after the function returns. In this
+way, <tt class="docutils literal"><span class="pre">function_ref</span></tt> is to <tt class="docutils literal"><span class="pre">std::function</span></tt> as <tt class="docutils literal"><span class="pre">StringRef</span></tt> is to
+<tt class="docutils literal"><span class="pre">std::string</span></tt>.</p>
+<p><tt class="docutils literal"><span class="pre">function_ref<Ret(Param1,</span> <span class="pre">Param2,</span> <span class="pre">...)></span></tt> can be implicitly constructed from
+any callable object that can be called with arguments of type <tt class="docutils literal"><span class="pre">Param1</span></tt>,
+<tt class="docutils literal"><span class="pre">Param2</span></tt>, ..., and returns a value that can be converted to type <tt class="docutils literal"><span class="pre">Ret</span></tt>.
+For example:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="kt">void</span> <span class="nf">visitBasicBlocks</span><span class="p">(</span><span class="n">Function</span> <span class="o">*</span><span class="n">F</span><span class="p">,</span> <span class="n">function_ref</span><span class="o"><</span><span class="kt">bool</span> <span class="p">(</span><span class="n">BasicBlock</span><span class="o">*</span><span class="p">)</span><span class="o">></span> <span class="n">Callback</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">for</span> <span class="p">(</span><span class="n">BasicBlock</span> <span class="o">&</span><span class="n">BB</span> <span class="o">:</span> <span class="o">*</span><span class="n">F</span><span class="p">)</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">Callback</span><span class="p">(</span><span class="o">&</span><span class="n">BB</span><span class="p">))</span>
+ <span class="k">return</span><span class="p">;</span>
+<span class="p">}</span>
+</pre></div>
+</div>
+<p>can be called using:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">visitBasicBlocks</span><span class="p">(</span><span class="n">F</span><span class="p">,</span> <span class="p">[</span><span class="o">&</span><span class="p">](</span><span class="n">BasicBlock</span> <span class="o">*</span><span class="n">BB</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">process</span><span class="p">(</span><span class="n">BB</span><span class="p">))</span>
+ <span class="k">return</span> <span class="n">isEmpty</span><span class="p">(</span><span class="n">BB</span><span class="p">);</span>
+ <span class="k">return</span> <span class="nb">false</span><span class="p">;</span>
+<span class="p">});</span>
+</pre></div>
+</div>
+<p>Note that a <tt class="docutils literal"><span class="pre">function_ref</span></tt> object contains pointers to external memory, so it
+is not generally safe to store an instance of the class (unless you know that
+the external storage will not be freed). If you need this ability, consider
+using <tt class="docutils literal"><span class="pre">std::function</span></tt>. <tt class="docutils literal"><span class="pre">function_ref</span></tt> is small enough that it should always
+be passed by value.</p>
+</div>
+</div>
+<div class="section" id="the-debug-macro-and-debug-option">
+<span id="debug"></span><h3><a class="toc-backref" href="#id19">The <tt class="docutils literal"><span class="pre">DEBUG()</span></tt> macro and <tt class="docutils literal"><span class="pre">-debug</span></tt> option</a><a class="headerlink" href="#the-debug-macro-and-debug-option" title="Permalink to this headline">¶</a></h3>
+<p>Often when working on your pass you will put a bunch of debugging printouts and
+other code into your pass. After you get it working, you want to remove it, but
+you may need it again in the future (to work out new bugs that you run across).</p>
+<p>Naturally, because of this, you don’t want to delete the debug printouts, but
+you don’t want them to always be noisy. A standard compromise is to comment
+them out, allowing you to enable them if you need them in the future.</p>
+<p>The <tt class="docutils literal"><span class="pre">llvm/Support/Debug.h</span></tt> (<a class="reference external" href="http://llvm.org/doxygen/Debug_8h-source.html">doxygen</a>) file provides a macro named
+<tt class="docutils literal"><span class="pre">DEBUG()</span></tt> that is a much nicer solution to this problem. Basically, you can
+put arbitrary code into the argument of the <tt class="docutils literal"><span class="pre">DEBUG</span></tt> macro, and it is only
+executed if ‘<tt class="docutils literal"><span class="pre">opt</span></tt>‘ (or any other tool) is run with the ‘<tt class="docutils literal"><span class="pre">-debug</span></tt>‘ command
+line argument:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">DEBUG</span><span class="p">(</span><span class="n">errs</span><span class="p">()</span> <span class="o"><<</span> <span class="s">"I am here!</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span>
+</pre></div>
+</div>
+<p>Then you can run your pass like this:</p>
+<div class="highlight-none"><div class="highlight"><pre>$ opt < a.bc > /dev/null -mypass
+<no output>
+$ opt < a.bc > /dev/null -mypass -debug
+I am here!
+</pre></div>
+</div>
+<p>Using the <tt class="docutils literal"><span class="pre">DEBUG()</span></tt> macro instead of a home-brewed solution allows you to not
+have to create “yet another” command line option for the debug output for your
+pass. Note that <tt class="docutils literal"><span class="pre">DEBUG()</span></tt> macros are disabled for optimized builds, so they
+do not cause a performance impact at all (for the same reason, they should also
+not contain side-effects!).</p>
+<p>One additional nice thing about the <tt class="docutils literal"><span class="pre">DEBUG()</span></tt> macro is that you can enable or
+disable it directly in gdb. Just use “<tt class="docutils literal"><span class="pre">set</span> <span class="pre">DebugFlag=0</span></tt>” or “<tt class="docutils literal"><span class="pre">set</span>
+<span class="pre">DebugFlag=1</span></tt>” from the gdb if the program is running. If the program hasn’t
+been started yet, you can always just run it with <tt class="docutils literal"><span class="pre">-debug</span></tt>.</p>
+<div class="section" id="fine-grained-debug-info-with-debug-type-and-the-debug-only-option">
+<span id="debug-type"></span><h4><a class="toc-backref" href="#id20">Fine grained debug info with <tt class="docutils literal"><span class="pre">DEBUG_TYPE</span></tt> and the <tt class="docutils literal"><span class="pre">-debug-only</span></tt> option</a><a class="headerlink" href="#fine-grained-debug-info-with-debug-type-and-the-debug-only-option" title="Permalink to this headline">¶</a></h4>
+<p>Sometimes you may find yourself in a situation where enabling <tt class="docutils literal"><span class="pre">-debug</span></tt> just
+turns on <strong>too much</strong> information (such as when working on the code generator).
+If you want to enable debug information with more fine-grained control, you
+can define the <tt class="docutils literal"><span class="pre">DEBUG_TYPE</span></tt> macro and use the <tt class="docutils literal"><span class="pre">-debug-only</span></tt> option as
+follows:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="cp">#undef DEBUG_TYPE</span>
+<span class="n">DEBUG</span><span class="p">(</span><span class="n">errs</span><span class="p">()</span> <span class="o"><<</span> <span class="s">"No debug type</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span>
+<span class="cp">#define DEBUG_TYPE "foo"</span>
+<span class="n">DEBUG</span><span class="p">(</span><span class="n">errs</span><span class="p">()</span> <span class="o"><<</span> <span class="s">"'foo' debug type</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span>
+<span class="cp">#undef DEBUG_TYPE</span>
+<span class="cp">#define DEBUG_TYPE "bar"</span>
+<span class="n">DEBUG</span><span class="p">(</span><span class="n">errs</span><span class="p">()</span> <span class="o"><<</span> <span class="s">"'bar' debug type</span><span class="se">\n</span><span class="s">"</span><span class="p">));</span>
+<span class="cp">#undef DEBUG_TYPE</span>
+<span class="cp">#define DEBUG_TYPE ""</span>
+<span class="n">DEBUG</span><span class="p">(</span><span class="n">errs</span><span class="p">()</span> <span class="o"><<</span> <span class="s">"No debug type (2)</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span>
+</pre></div>
+</div>
+<p>Then you can run your pass like this:</p>
+<div class="highlight-none"><div class="highlight"><pre>$ opt < a.bc > /dev/null -mypass
+<no output>
+$ opt < a.bc > /dev/null -mypass -debug
+No debug type
+'foo' debug type
+'bar' debug type
+No debug type (2)
+$ opt < a.bc > /dev/null -mypass -debug-only=foo
+'foo' debug type
+$ opt < a.bc > /dev/null -mypass -debug-only=bar
+'bar' debug type
+</pre></div>
+</div>
+<p>Of course, in practice, you should only set <tt class="docutils literal"><span class="pre">DEBUG_TYPE</span></tt> at the top of a file,
+to specify the debug type for the entire module (if you do this before you
+<tt class="docutils literal"><span class="pre">#include</span> <span class="pre">"llvm/Support/Debug.h"</span></tt>, you don’t have to insert the ugly
+<tt class="docutils literal"><span class="pre">#undef</span></tt>‘s). Also, you should use names more meaningful than “foo” and “bar”,
+because there is no system in place to ensure that names do not conflict. If
+two different modules use the same string, they will all be turned on when the
+name is specified. This allows, for example, all debug information for
+instruction scheduling to be enabled with <tt class="docutils literal"><span class="pre">-debug-only=InstrSched</span></tt>, even if
+the source lives in multiple files.</p>
+<p>For performance reasons, -debug-only is not available in optimized build
+(<tt class="docutils literal"><span class="pre">--enable-optimized</span></tt>) of LLVM.</p>
+<p>The <tt class="docutils literal"><span class="pre">DEBUG_WITH_TYPE</span></tt> macro is also available for situations where you would
+like to set <tt class="docutils literal"><span class="pre">DEBUG_TYPE</span></tt>, but only for one specific <tt class="docutils literal"><span class="pre">DEBUG</span></tt> statement. It
+takes an additional first parameter, which is the type to use. For example, the
+preceding example could be written as:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">DEBUG_WITH_TYPE</span><span class="p">(</span><span class="s">""</span><span class="p">,</span> <span class="n">errs</span><span class="p">()</span> <span class="o"><<</span> <span class="s">"No debug type</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span>
+<span class="n">DEBUG_WITH_TYPE</span><span class="p">(</span><span class="s">"foo"</span><span class="p">,</span> <span class="n">errs</span><span class="p">()</span> <span class="o"><<</span> <span class="s">"'foo' debug type</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span>
+<span class="n">DEBUG_WITH_TYPE</span><span class="p">(</span><span class="s">"bar"</span><span class="p">,</span> <span class="n">errs</span><span class="p">()</span> <span class="o"><<</span> <span class="s">"'bar' debug type</span><span class="se">\n</span><span class="s">"</span><span class="p">));</span>
+<span class="n">DEBUG_WITH_TYPE</span><span class="p">(</span><span class="s">""</span><span class="p">,</span> <span class="n">errs</span><span class="p">()</span> <span class="o"><<</span> <span class="s">"No debug type (2)</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span>
+</pre></div>
+</div>
+</div>
+</div>
+<div class="section" id="the-statistic-class-stats-option">
+<span id="statistic"></span><h3><a class="toc-backref" href="#id21">The <tt class="docutils literal"><span class="pre">Statistic</span></tt> class & <tt class="docutils literal"><span class="pre">-stats</span></tt> option</a><a class="headerlink" href="#the-statistic-class-stats-option" title="Permalink to this headline">¶</a></h3>
+<p>The <tt class="docutils literal"><span class="pre">llvm/ADT/Statistic.h</span></tt> (<a class="reference external" href="http://llvm.org/doxygen/Statistic_8h-source.html">doxygen</a>) file provides a class
+named <tt class="docutils literal"><span class="pre">Statistic</span></tt> that is used as a unified way to keep track of what the LLVM
+compiler is doing and how effective various optimizations are. It is useful to
+see what optimizations are contributing to making a particular program run
+faster.</p>
+<p>Often you may run your pass on some big program, and you’re interested to see
+how many times it makes a certain transformation. Although you can do this with
+hand inspection, or some ad-hoc method, this is a real pain and not very useful
+for big programs. Using the <tt class="docutils literal"><span class="pre">Statistic</span></tt> class makes it very easy to keep
+track of this information, and the calculated information is presented in a
+uniform manner with the rest of the passes being executed.</p>
+<p>There are many examples of <tt class="docutils literal"><span class="pre">Statistic</span></tt> uses, but the basics of using it are as
+follows:</p>
+<ol class="arabic simple">
+<li>Define your statistic like this:</li>
+</ol>
+<blockquote>
+<div><div class="highlight-c++"><div class="highlight"><pre><span class="cp">#define DEBUG_TYPE "mypassname" </span><span class="c1">// This goes before any #includes.</span>
+<span class="n">STATISTIC</span><span class="p">(</span><span class="n">NumXForms</span><span class="p">,</span> <span class="s">"The # of times I did stuff"</span><span class="p">);</span>
+</pre></div>
+</div>
+<p>The <tt class="docutils literal"><span class="pre">STATISTIC</span></tt> macro defines a static variable, whose name is specified by
+the first argument. The pass name is taken from the <tt class="docutils literal"><span class="pre">DEBUG_TYPE</span></tt> macro, and
+the description is taken from the second argument. The variable defined
+(“NumXForms” in this case) acts like an unsigned integer.</p>
+</div></blockquote>
+<ol class="arabic simple">
+<li>Whenever you make a transformation, bump the counter:</li>
+</ol>
+<blockquote>
+<div><div class="highlight-c++"><div class="highlight"><pre><span class="o">++</span><span class="n">NumXForms</span><span class="p">;</span> <span class="c1">// I did stuff!</span>
+</pre></div>
+</div>
+</div></blockquote>
+<p>That’s all you have to do. To get ‘<tt class="docutils literal"><span class="pre">opt</span></tt>‘ to print out the statistics
+gathered, use the ‘<tt class="docutils literal"><span class="pre">-stats</span></tt>‘ option:</p>
+<div class="highlight-none"><div class="highlight"><pre>$ opt -stats -mypassname < program.bc > /dev/null
+... statistics output ...
+</pre></div>
+</div>
+<p>Note that in order to use the ‘<tt class="docutils literal"><span class="pre">-stats</span></tt>‘ option, LLVM must be
+compiled with assertions enabled.</p>
+<p>When running <tt class="docutils literal"><span class="pre">opt</span></tt> on a C file from the SPEC benchmark suite, it gives a
+report that looks like this:</p>
+<div class="highlight-none"><div class="highlight"><pre> 7646 bitcodewriter - Number of normal instructions
+ 725 bitcodewriter - Number of oversized instructions
+129996 bitcodewriter - Number of bitcode bytes written
+ 2817 raise - Number of insts DCEd or constprop'd
+ 3213 raise - Number of cast-of-self removed
+ 5046 raise - Number of expression trees converted
+ 75 raise - Number of other getelementptr's formed
+ 138 raise - Number of load/store peepholes
+ 42 deadtypeelim - Number of unused typenames removed from symtab
+ 392 funcresolve - Number of varargs functions resolved
+ 27 globaldce - Number of global variables removed
+ 2 adce - Number of basic blocks removed
+ 134 cee - Number of branches revectored
+ 49 cee - Number of setcc instruction eliminated
+ 532 gcse - Number of loads removed
+ 2919 gcse - Number of instructions removed
+ 86 indvars - Number of canonical indvars added
+ 87 indvars - Number of aux indvars removed
+ 25 instcombine - Number of dead inst eliminate
+ 434 instcombine - Number of insts combined
+ 248 licm - Number of load insts hoisted
+ 1298 licm - Number of insts hoisted to a loop pre-header
+ 3 licm - Number of insts hoisted to multiple loop preds (bad, no loop pre-header)
+ 75 mem2reg - Number of alloca's promoted
+ 1444 cfgsimplify - Number of blocks simplified
+</pre></div>
+</div>
+<p>Obviously, with so many optimizations, having a unified framework for this stuff
+is very nice. Making your pass fit well into the framework makes it more
+maintainable and useful.</p>
+</div>
+<div class="section" id="viewing-graphs-while-debugging-code">
+<span id="viewgraph"></span><h3><a class="toc-backref" href="#id22">Viewing graphs while debugging code</a><a class="headerlink" href="#viewing-graphs-while-debugging-code" title="Permalink to this headline">¶</a></h3>
+<p>Several of the important data structures in LLVM are graphs: for example CFGs
+made out of LLVM <a class="reference internal" href="#basicblock"><em>BasicBlocks</em></a>, CFGs made out of LLVM
+<a class="reference internal" href="CodeGenerator.html#machinebasicblock"><em>MachineBasicBlocks</em></a>, and <a class="reference internal" href="CodeGenerator.html#selectiondag"><em>Instruction Selection
+DAGs</em></a>. In many cases, while debugging various parts of the
+compiler, it is nice to instantly visualize these graphs.</p>
+<p>LLVM provides several callbacks that are available in a debug build to do
+exactly that. If you call the <tt class="docutils literal"><span class="pre">Function::viewCFG()</span></tt> method, for example, the
+current LLVM tool will pop up a window containing the CFG for the function where
+each basic block is a node in the graph, and each node contains the instructions
+in the block. Similarly, there also exists <tt class="docutils literal"><span class="pre">Function::viewCFGOnly()</span></tt> (does
+not include the instructions), the <tt class="docutils literal"><span class="pre">MachineFunction::viewCFG()</span></tt> and
+<tt class="docutils literal"><span class="pre">MachineFunction::viewCFGOnly()</span></tt>, and the <tt class="docutils literal"><span class="pre">SelectionDAG::viewGraph()</span></tt>
+methods. Within GDB, for example, you can usually use something like <tt class="docutils literal"><span class="pre">call</span>
+<span class="pre">DAG.viewGraph()</span></tt> to pop up a window. Alternatively, you can sprinkle calls to
+these functions in your code in places you want to debug.</p>
+<p>Getting this to work requires a small amount of setup. On Unix systems
+with X11, install the <a class="reference external" href="http://www.graphviz.org">graphviz</a> toolkit, and make
+sure ‘dot’ and ‘gv’ are in your path. If you are running on Mac OS X, download
+and install the Mac OS X <a class="reference external" href="http://www.pixelglow.com/graphviz/">Graphviz program</a> and add
+<tt class="docutils literal"><span class="pre">/Applications/Graphviz.app/Contents/MacOS/</span></tt> (or wherever you install it) to
+your path. The programs need not be present when configuring, building or
+running LLVM and can simply be installed when needed during an active debug
+session.</p>
+<p><tt class="docutils literal"><span class="pre">SelectionDAG</span></tt> has been extended to make it easier to locate <em>interesting</em>
+nodes in large complex graphs. From gdb, if you <tt class="docutils literal"><span class="pre">call</span> <span class="pre">DAG.setGraphColor(node,</span>
+<span class="pre">"color")</span></tt>, then the next <tt class="docutils literal"><span class="pre">call</span> <span class="pre">DAG.viewGraph()</span></tt> would highlight the node in
+the specified color (choices of colors can be found at <a class="reference external" href="http://www.graphviz.org/doc/info/colors.html">colors</a>.) More complex node attributes
+can be provided with <tt class="docutils literal"><span class="pre">call</span> <span class="pre">DAG.setGraphAttrs(node,</span> <span class="pre">"attributes")</span></tt> (choices can
+be found at <a class="reference external" href="http://www.graphviz.org/doc/info/attrs.html">Graph attributes</a>.)
+If you want to restart and clear all the current graph attributes, then you can
+<tt class="docutils literal"><span class="pre">call</span> <span class="pre">DAG.clearGraphAttrs()</span></tt>.</p>
+<p>Note that graph visualization features are compiled out of Release builds to
+reduce file size. This means that you need a Debug+Asserts or Release+Asserts
+build to use these features.</p>
+</div>
+</div>
+<div class="section" id="picking-the-right-data-structure-for-a-task">
+<span id="datastructure"></span><h2><a class="toc-backref" href="#id23">Picking the Right Data Structure for a Task</a><a class="headerlink" href="#picking-the-right-data-structure-for-a-task" title="Permalink to this headline">¶</a></h2>
+<p>LLVM has a plethora of data structures in the <tt class="docutils literal"><span class="pre">llvm/ADT/</span></tt> directory, and we
+commonly use STL data structures. This section describes the trade-offs you
+should consider when you pick one.</p>
+<p>The first step is a choose your own adventure: do you want a sequential
+container, a set-like container, or a map-like container? The most important
+thing when choosing a container is the algorithmic properties of how you plan to
+access the container. Based on that, you should use:</p>
+<ul class="simple">
+<li>a <a class="reference internal" href="#ds-map"><em>map-like</em></a> container if you need efficient look-up of a
+value based on another value. Map-like containers also support efficient
+queries for containment (whether a key is in the map). Map-like containers
+generally do not support efficient reverse mapping (values to keys). If you
+need that, use two maps. Some map-like containers also support efficient
+iteration through the keys in sorted order. Map-like containers are the most
+expensive sort, only use them if you need one of these capabilities.</li>
+<li>a <a class="reference internal" href="#ds-set"><em>set-like</em></a> container if you need to put a bunch of stuff into
+a container that automatically eliminates duplicates. Some set-like
+containers support efficient iteration through the elements in sorted order.
+Set-like containers are more expensive than sequential containers.</li>
+<li>a <a class="reference internal" href="#ds-sequential"><em>sequential</em></a> container provides the most efficient way
+to add elements and keeps track of the order they are added to the collection.
+They permit duplicates and support efficient iteration, but do not support
+efficient look-up based on a key.</li>
+<li>a <a class="reference internal" href="#ds-string"><em>string</em></a> container is a specialized sequential container or
+reference structure that is used for character or byte arrays.</li>
+<li>a <a class="reference internal" href="#ds-bit"><em>bit</em></a> container provides an efficient way to store and
+perform set operations on sets of numeric id’s, while automatically
+eliminating duplicates. Bit containers require a maximum of 1 bit for each
+identifier you want to store.</li>
+</ul>
+<p>Once the proper category of container is determined, you can fine tune the
+memory use, constant factors, and cache behaviors of access by intelligently
+picking a member of the category. Note that constant factors and cache behavior
+can be a big deal. If you have a vector that usually only contains a few
+elements (but could contain many), for example, it’s much better to use
+<a class="reference internal" href="#dss-smallvector"><em>SmallVector</em></a> than <a class="reference internal" href="#dss-vector"><em>vector</em></a>. Doing so
+avoids (relatively) expensive malloc/free calls, which dwarf the cost of adding
+the elements to the container.</p>
+<div class="section" id="sequential-containers-std-vector-std-list-etc">
+<span id="ds-sequential"></span><h3><a class="toc-backref" href="#id24">Sequential Containers (std::vector, std::list, etc)</a><a class="headerlink" href="#sequential-containers-std-vector-std-list-etc" title="Permalink to this headline">¶</a></h3>
+<p>There are a variety of sequential containers available for you, based on your
+needs. Pick the first in this section that will do what you want.</p>
+<div class="section" id="llvm-adt-arrayref-h">
+<span id="dss-arrayref"></span><h4><a class="toc-backref" href="#id25">llvm/ADT/ArrayRef.h</a><a class="headerlink" href="#llvm-adt-arrayref-h" title="Permalink to this headline">¶</a></h4>
+<p>The <tt class="docutils literal"><span class="pre">llvm::ArrayRef</span></tt> class is the preferred class to use in an interface that
+accepts a sequential list of elements in memory and just reads from them. By
+taking an <tt class="docutils literal"><span class="pre">ArrayRef</span></tt>, the API can be passed a fixed size array, an
+<tt class="docutils literal"><span class="pre">std::vector</span></tt>, an <tt class="docutils literal"><span class="pre">llvm::SmallVector</span></tt> and anything else that is contiguous
+in memory.</p>
+</div>
+<div class="section" id="fixed-size-arrays">
+<span id="dss-fixedarrays"></span><h4><a class="toc-backref" href="#id26">Fixed Size Arrays</a><a class="headerlink" href="#fixed-size-arrays" title="Permalink to this headline">¶</a></h4>
+<p>Fixed size arrays are very simple and very fast. They are good if you know
+exactly how many elements you have, or you have a (low) upper bound on how many
+you have.</p>
+</div>
+<div class="section" id="heap-allocated-arrays">
+<span id="dss-heaparrays"></span><h4><a class="toc-backref" href="#id27">Heap Allocated Arrays</a><a class="headerlink" href="#heap-allocated-arrays" title="Permalink to this headline">¶</a></h4>
+<p>Heap allocated arrays (<tt class="docutils literal"><span class="pre">new[]</span></tt> + <tt class="docutils literal"><span class="pre">delete[]</span></tt>) are also simple. They are good
+if the number of elements is variable, if you know how many elements you will
+need before the array is allocated, and if the array is usually large (if not,
+consider a <a class="reference internal" href="#dss-smallvector"><em>SmallVector</em></a>). The cost of a heap allocated
+array is the cost of the new/delete (aka malloc/free). Also note that if you
+are allocating an array of a type with a constructor, the constructor and
+destructors will be run for every element in the array (re-sizable vectors only
+construct those elements actually used).</p>
+</div>
+<div class="section" id="llvm-adt-tinyptrvector-h">
+<span id="dss-tinyptrvector"></span><h4><a class="toc-backref" href="#id28">llvm/ADT/TinyPtrVector.h</a><a class="headerlink" href="#llvm-adt-tinyptrvector-h" title="Permalink to this headline">¶</a></h4>
+<p><tt class="docutils literal"><span class="pre">TinyPtrVector<Type></span></tt> is a highly specialized collection class that is
+optimized to avoid allocation in the case when a vector has zero or one
+elements. It has two major restrictions: 1) it can only hold values of pointer
+type, and 2) it cannot hold a null pointer.</p>
+<p>Since this container is highly specialized, it is rarely used.</p>
+</div>
+<div class="section" id="llvm-adt-smallvector-h">
+<span id="dss-smallvector"></span><h4><a class="toc-backref" href="#id29">llvm/ADT/SmallVector.h</a><a class="headerlink" href="#llvm-adt-smallvector-h" title="Permalink to this headline">¶</a></h4>
+<p><tt class="docutils literal"><span class="pre">SmallVector<Type,</span> <span class="pre">N></span></tt> is a simple class that looks and smells just like
+<tt class="docutils literal"><span class="pre">vector<Type></span></tt>: it supports efficient iteration, lays out elements in memory
+order (so you can do pointer arithmetic between elements), supports efficient
+push_back/pop_back operations, supports efficient random access to its elements,
+etc.</p>
+<p>The advantage of SmallVector is that it allocates space for some number of
+elements (N) <strong>in the object itself</strong>. Because of this, if the SmallVector is
+dynamically smaller than N, no malloc is performed. This can be a big win in
+cases where the malloc/free call is far more expensive than the code that
+fiddles around with the elements.</p>
+<p>This is good for vectors that are “usually small” (e.g. the number of
+predecessors/successors of a block is usually less than 8). On the other hand,
+this makes the size of the SmallVector itself large, so you don’t want to
+allocate lots of them (doing so will waste a lot of space). As such,
+SmallVectors are most useful when on the stack.</p>
+<p>SmallVector also provides a nice portable and efficient replacement for
+<tt class="docutils literal"><span class="pre">alloca</span></tt>.</p>
+<div class="admonition note">
+<p class="first admonition-title">Note</p>
+<p>Prefer to use <tt class="docutils literal"><span class="pre">SmallVectorImpl<T></span></tt> as a parameter type.</p>
+<p>In APIs that don’t care about the “small size” (most?), prefer to use
+the <tt class="docutils literal"><span class="pre">SmallVectorImpl<T></span></tt> class, which is basically just the “vector
+header” (and methods) without the elements allocated after it. Note that
+<tt class="docutils literal"><span class="pre">SmallVector<T,</span> <span class="pre">N></span></tt> inherits from <tt class="docutils literal"><span class="pre">SmallVectorImpl<T></span></tt> so the
+conversion is implicit and costs nothing. E.g.</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="c1">// BAD: Clients cannot pass e.g. SmallVector<Foo, 4>.</span>
+<span class="n">hardcodedSmallSize</span><span class="p">(</span><span class="n">SmallVector</span><span class="o"><</span><span class="n">Foo</span><span class="p">,</span> <span class="mi">2</span><span class="o">></span> <span class="o">&</span><span class="n">Out</span><span class="p">);</span>
+<span class="c1">// GOOD: Clients can pass any SmallVector<Foo, N>.</span>
+<span class="n">allowsAnySmallSize</span><span class="p">(</span><span class="n">SmallVectorImpl</span><span class="o"><</span><span class="n">Foo</span><span class="o">></span> <span class="o">&</span><span class="n">Out</span><span class="p">);</span>
+
+<span class="kt">void</span> <span class="nf">someFunc</span><span class="p">()</span> <span class="p">{</span>
+ <span class="n">SmallVector</span><span class="o"><</span><span class="n">Foo</span><span class="p">,</span> <span class="mi">8</span><span class="o">></span> <span class="n">Vec</span><span class="p">;</span>
+ <span class="n">hardcodedSmallSize</span><span class="p">(</span><span class="n">Vec</span><span class="p">);</span> <span class="c1">// Error.</span>
+ <span class="n">allowsAnySmallSize</span><span class="p">(</span><span class="n">Vec</span><span class="p">);</span> <span class="c1">// Works.</span>
+<span class="p">}</span>
+</pre></div>
+</div>
+<p class="last">Even though it has “<tt class="docutils literal"><span class="pre">Impl</span></tt>” in the name, this is so widely used that
+it really isn’t “private to the implementation” anymore. A name like
+<tt class="docutils literal"><span class="pre">SmallVectorHeader</span></tt> would be more appropriate.</p>
+</div>
+</div>
+<div class="section" id="vector">
+<span id="dss-vector"></span><h4><a class="toc-backref" href="#id30"><vector></a><a class="headerlink" href="#vector" title="Permalink to this headline">¶</a></h4>
+<p><tt class="docutils literal"><span class="pre">std::vector</span></tt> is well loved and respected. It is useful when SmallVector
+isn’t: when the size of the vector is often large (thus the small optimization
+will rarely be a benefit) or if you will be allocating many instances of the
+vector itself (which would waste space for elements that aren’t in the
+container). vector is also useful when interfacing with code that expects
+vectors :).</p>
+<p>One worthwhile note about std::vector: avoid code like this:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="k">for</span> <span class="p">(</span> <span class="p">...</span> <span class="p">)</span> <span class="p">{</span>
+ <span class="n">std</span><span class="o">::</span><span class="n">vector</span><span class="o"><</span><span class="n">foo</span><span class="o">></span> <span class="n">V</span><span class="p">;</span>
+ <span class="c1">// make use of V.</span>
+<span class="p">}</span>
+</pre></div>
+</div>
+<p>Instead, write this as:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">std</span><span class="o">::</span><span class="n">vector</span><span class="o"><</span><span class="n">foo</span><span class="o">></span> <span class="n">V</span><span class="p">;</span>
+<span class="k">for</span> <span class="p">(</span> <span class="p">...</span> <span class="p">)</span> <span class="p">{</span>
+ <span class="c1">// make use of V.</span>
+ <span class="n">V</span><span class="p">.</span><span class="n">clear</span><span class="p">();</span>
+<span class="p">}</span>
+</pre></div>
+</div>
+<p>Doing so will save (at least) one heap allocation and free per iteration of the
+loop.</p>
+</div>
+<div class="section" id="deque">
+<span id="dss-deque"></span><h4><a class="toc-backref" href="#id31"><deque></a><a class="headerlink" href="#deque" title="Permalink to this headline">¶</a></h4>
+<p><tt class="docutils literal"><span class="pre">std::deque</span></tt> is, in some senses, a generalized version of <tt class="docutils literal"><span class="pre">std::vector</span></tt>.
+Like <tt class="docutils literal"><span class="pre">std::vector</span></tt>, it provides constant time random access and other similar
+properties, but it also provides efficient access to the front of the list. It
+does not guarantee continuity of elements within memory.</p>
+<p>In exchange for this extra flexibility, <tt class="docutils literal"><span class="pre">std::deque</span></tt> has significantly higher
+constant factor costs than <tt class="docutils literal"><span class="pre">std::vector</span></tt>. If possible, use <tt class="docutils literal"><span class="pre">std::vector</span></tt> or
+something cheaper.</p>
+</div>
+<div class="section" id="list">
+<span id="dss-list"></span><h4><a class="toc-backref" href="#id32"><list></a><a class="headerlink" href="#list" title="Permalink to this headline">¶</a></h4>
+<p><tt class="docutils literal"><span class="pre">std::list</span></tt> is an extremely inefficient class that is rarely useful. It
+performs a heap allocation for every element inserted into it, thus having an
+extremely high constant factor, particularly for small data types.
+<tt class="docutils literal"><span class="pre">std::list</span></tt> also only supports bidirectional iteration, not random access
+iteration.</p>
+<p>In exchange for this high cost, std::list supports efficient access to both ends
+of the list (like <tt class="docutils literal"><span class="pre">std::deque</span></tt>, but unlike <tt class="docutils literal"><span class="pre">std::vector</span></tt> or
+<tt class="docutils literal"><span class="pre">SmallVector</span></tt>). In addition, the iterator invalidation characteristics of
+std::list are stronger than that of a vector class: inserting or removing an
+element into the list does not invalidate iterator or pointers to other elements
+in the list.</p>
+</div>
+<div class="section" id="llvm-adt-ilist-h">
+<span id="dss-ilist"></span><h4><a class="toc-backref" href="#id33">llvm/ADT/ilist.h</a><a class="headerlink" href="#llvm-adt-ilist-h" title="Permalink to this headline">¶</a></h4>
+<p><tt class="docutils literal"><span class="pre">ilist<T></span></tt> implements an ‘intrusive’ doubly-linked list. It is intrusive,
+because it requires the element to store and provide access to the prev/next
+pointers for the list.</p>
+<p><tt class="docutils literal"><span class="pre">ilist</span></tt> has the same drawbacks as <tt class="docutils literal"><span class="pre">std::list</span></tt>, and additionally requires an
+<tt class="docutils literal"><span class="pre">ilist_traits</span></tt> implementation for the element type, but it provides some novel
+characteristics. In particular, it can efficiently store polymorphic objects,
+the traits class is informed when an element is inserted or removed from the
+list, and <tt class="docutils literal"><span class="pre">ilist</span></tt>s are guaranteed to support a constant-time splice
+operation.</p>
+<p>These properties are exactly what we want for things like <tt class="docutils literal"><span class="pre">Instruction</span></tt>s and
+basic blocks, which is why these are implemented with <tt class="docutils literal"><span class="pre">ilist</span></tt>s.</p>
+<p>Related classes of interest are explained in the following subsections:</p>
+<ul class="simple">
+<li><a class="reference internal" href="#dss-ilist-traits"><em>ilist_traits</em></a></li>
+<li><a class="reference internal" href="#dss-iplist"><em>iplist</em></a></li>
+<li><a class="reference internal" href="#dss-ilist-node"><em>llvm/ADT/ilist_node.h</em></a></li>
+<li><a class="reference internal" href="#dss-ilist-sentinel"><em>Sentinels</em></a></li>
+</ul>
+</div>
+<div class="section" id="llvm-adt-packedvector-h">
+<span id="dss-packedvector"></span><h4><a class="toc-backref" href="#id34">llvm/ADT/PackedVector.h</a><a class="headerlink" href="#llvm-adt-packedvector-h" title="Permalink to this headline">¶</a></h4>
+<p>Useful for storing a vector of values using only a few number of bits for each
+value. Apart from the standard operations of a vector-like container, it can
+also perform an ‘or’ set operation.</p>
+<p>For example:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="k">enum</span> <span class="n">State</span> <span class="p">{</span>
+ <span class="n">None</span> <span class="o">=</span> <span class="mh">0x0</span><span class="p">,</span>
+ <span class="n">FirstCondition</span> <span class="o">=</span> <span class="mh">0x1</span><span class="p">,</span>
+ <span class="n">SecondCondition</span> <span class="o">=</span> <span class="mh">0x2</span><span class="p">,</span>
+ <span class="n">Both</span> <span class="o">=</span> <span class="mh">0x3</span>
+<span class="p">};</span>
+
+<span class="n">State</span> <span class="nf">get</span><span class="p">()</span> <span class="p">{</span>
+ <span class="n">PackedVector</span><span class="o"><</span><span class="n">State</span><span class="p">,</span> <span class="mi">2</span><span class="o">></span> <span class="n">Vec1</span><span class="p">;</span>
+ <span class="n">Vec1</span><span class="p">.</span><span class="n">push_back</span><span class="p">(</span><span class="n">FirstCondition</span><span class="p">);</span>
+
+ <span class="n">PackedVector</span><span class="o"><</span><span class="n">State</span><span class="p">,</span> <span class="mi">2</span><span class="o">></span> <span class="n">Vec2</span><span class="p">;</span>
+ <span class="n">Vec2</span><span class="p">.</span><span class="n">push_back</span><span class="p">(</span><span class="n">SecondCondition</span><span class="p">);</span>
+
+ <span class="n">Vec1</span> <span class="o">|=</span> <span class="n">Vec2</span><span class="p">;</span>
+ <span class="k">return</span> <span class="n">Vec1</span><span class="p">[</span><span class="mi">0</span><span class="p">];</span> <span class="c1">// returns 'Both'.</span>
+<span class="p">}</span>
+</pre></div>
+</div>
+</div>
+<div class="section" id="ilist-traits">
+<span id="dss-ilist-traits"></span><h4><a class="toc-backref" href="#id35">ilist_traits</a><a class="headerlink" href="#ilist-traits" title="Permalink to this headline">¶</a></h4>
+<p><tt class="docutils literal"><span class="pre">ilist_traits<T></span></tt> is <tt class="docutils literal"><span class="pre">ilist<T></span></tt>‘s customization mechanism. <tt class="docutils literal"><span class="pre">iplist<T></span></tt>
+(and consequently <tt class="docutils literal"><span class="pre">ilist<T></span></tt>) publicly derive from this traits class.</p>
+</div>
+<div class="section" id="iplist">
+<span id="dss-iplist"></span><h4><a class="toc-backref" href="#id36">iplist</a><a class="headerlink" href="#iplist" title="Permalink to this headline">¶</a></h4>
+<p><tt class="docutils literal"><span class="pre">iplist<T></span></tt> is <tt class="docutils literal"><span class="pre">ilist<T></span></tt>‘s base and as such supports a slightly narrower
+interface. Notably, inserters from <tt class="docutils literal"><span class="pre">T&</span></tt> are absent.</p>
+<p><tt class="docutils literal"><span class="pre">ilist_traits<T></span></tt> is a public base of this class and can be used for a wide
+variety of customizations.</p>
+</div>
+<div class="section" id="llvm-adt-ilist-node-h">
+<span id="dss-ilist-node"></span><h4><a class="toc-backref" href="#id37">llvm/ADT/ilist_node.h</a><a class="headerlink" href="#llvm-adt-ilist-node-h" title="Permalink to this headline">¶</a></h4>
+<p><tt class="docutils literal"><span class="pre">ilist_node<T></span></tt> implements the forward and backward links that are expected
+by the <tt class="docutils literal"><span class="pre">ilist<T></span></tt> (and analogous containers) in the default manner.</p>
+<p><tt class="docutils literal"><span class="pre">ilist_node<T></span></tt>s are meant to be embedded in the node type <tt class="docutils literal"><span class="pre">T</span></tt>, usually
+<tt class="docutils literal"><span class="pre">T</span></tt> publicly derives from <tt class="docutils literal"><span class="pre">ilist_node<T></span></tt>.</p>
+</div>
+<div class="section" id="sentinels">
+<span id="dss-ilist-sentinel"></span><h4><a class="toc-backref" href="#id38">Sentinels</a><a class="headerlink" href="#sentinels" title="Permalink to this headline">¶</a></h4>
+<p><tt class="docutils literal"><span class="pre">ilist</span></tt>s have another specialty that must be considered. To be a good
+citizen in the C++ ecosystem, it needs to support the standard container
+operations, such as <tt class="docutils literal"><span class="pre">begin</span></tt> and <tt class="docutils literal"><span class="pre">end</span></tt> iterators, etc. Also, the
+<tt class="docutils literal"><span class="pre">operator--</span></tt> must work correctly on the <tt class="docutils literal"><span class="pre">end</span></tt> iterator in the case of
+non-empty <tt class="docutils literal"><span class="pre">ilist</span></tt>s.</p>
+<p>The only sensible solution to this problem is to allocate a so-called <em>sentinel</em>
+along with the intrusive list, which serves as the <tt class="docutils literal"><span class="pre">end</span></tt> iterator, providing
+the back-link to the last element. However conforming to the C++ convention it
+is illegal to <tt class="docutils literal"><span class="pre">operator++</span></tt> beyond the sentinel and it also must not be
+dereferenced.</p>
+<p>These constraints allow for some implementation freedom to the <tt class="docutils literal"><span class="pre">ilist</span></tt> how to
+allocate and store the sentinel. The corresponding policy is dictated by
+<tt class="docutils literal"><span class="pre">ilist_traits<T></span></tt>. By default a <tt class="docutils literal"><span class="pre">T</span></tt> gets heap-allocated whenever the need
+for a sentinel arises.</p>
+<p>While the default policy is sufficient in most cases, it may break down when
+<tt class="docutils literal"><span class="pre">T</span></tt> does not provide a default constructor. Also, in the case of many
+instances of <tt class="docutils literal"><span class="pre">ilist</span></tt>s, the memory overhead of the associated sentinels is
+wasted. To alleviate the situation with numerous and voluminous
+<tt class="docutils literal"><span class="pre">T</span></tt>-sentinels, sometimes a trick is employed, leading to <em>ghostly sentinels</em>.</p>
+<p>Ghostly sentinels are obtained by specially-crafted <tt class="docutils literal"><span class="pre">ilist_traits<T></span></tt> which
+superpose the sentinel with the <tt class="docutils literal"><span class="pre">ilist</span></tt> instance in memory. Pointer
+arithmetic is used to obtain the sentinel, which is relative to the <tt class="docutils literal"><span class="pre">ilist</span></tt>‘s
+<tt class="docutils literal"><span class="pre">this</span></tt> pointer. The <tt class="docutils literal"><span class="pre">ilist</span></tt> is augmented by an extra pointer, which serves
+as the back-link of the sentinel. This is the only field in the ghostly
+sentinel which can be legally accessed.</p>
+</div>
+<div class="section" id="other-sequential-container-options">
+<span id="dss-other"></span><h4><a class="toc-backref" href="#id39">Other Sequential Container options</a><a class="headerlink" href="#other-sequential-container-options" title="Permalink to this headline">¶</a></h4>
+<p>Other STL containers are available, such as <tt class="docutils literal"><span class="pre">std::string</span></tt>.</p>
+<p>There are also various STL adapter classes such as <tt class="docutils literal"><span class="pre">std::queue</span></tt>,
+<tt class="docutils literal"><span class="pre">std::priority_queue</span></tt>, <tt class="docutils literal"><span class="pre">std::stack</span></tt>, etc. These provide simplified access
+to an underlying container but don’t affect the cost of the container itself.</p>
+</div>
+</div>
+<div class="section" id="string-like-containers">
+<span id="ds-string"></span><h3><a class="toc-backref" href="#id40">String-like containers</a><a class="headerlink" href="#string-like-containers" title="Permalink to this headline">¶</a></h3>
+<p>There are a variety of ways to pass around and use strings in C and C++, and
+LLVM adds a few new options to choose from. Pick the first option on this list
+that will do what you need, they are ordered according to their relative cost.</p>
+<p>Note that it is generally preferred to <em>not</em> pass strings around as <tt class="docutils literal"><span class="pre">const</span>
+<span class="pre">char*</span></tt>‘s. These have a number of problems, including the fact that they
+cannot represent embedded nul (“0”) characters, and do not have a length
+available efficiently. The general replacement for ‘<tt class="docutils literal"><span class="pre">const</span> <span class="pre">char*</span></tt>‘ is
+StringRef.</p>
+<p>For more information on choosing string containers for APIs, please see
+<a class="reference internal" href="#string-apis"><em>Passing Strings</em></a>.</p>
+<div class="section" id="llvm-adt-stringref-h">
+<span id="dss-stringref"></span><h4><a class="toc-backref" href="#id41">llvm/ADT/StringRef.h</a><a class="headerlink" href="#llvm-adt-stringref-h" title="Permalink to this headline">¶</a></h4>
+<p>The StringRef class is a simple value class that contains a pointer to a
+character and a length, and is quite related to the <a class="reference internal" href="#dss-arrayref"><em>ArrayRef</em></a> class (but specialized for arrays of characters). Because
+StringRef carries a length with it, it safely handles strings with embedded nul
+characters in it, getting the length does not require a strlen call, and it even
+has very convenient APIs for slicing and dicing the character range that it
+represents.</p>
+<p>StringRef is ideal for passing simple strings around that are known to be live,
+either because they are C string literals, std::string, a C array, or a
+SmallVector. Each of these cases has an efficient implicit conversion to
+StringRef, which doesn’t result in a dynamic strlen being executed.</p>
+<p>StringRef has a few major limitations which make more powerful string containers
+useful:</p>
+<ol class="arabic simple">
+<li>You cannot directly convert a StringRef to a ‘const char*’ because there is
+no way to add a trailing nul (unlike the .c_str() method on various stronger
+classes).</li>
+<li>StringRef doesn’t own or keep alive the underlying string bytes.
+As such it can easily lead to dangling pointers, and is not suitable for
+embedding in datastructures in most cases (instead, use an std::string or
+something like that).</li>
+<li>For the same reason, StringRef cannot be used as the return value of a
+method if the method “computes” the result string. Instead, use std::string.</li>
+<li>StringRef’s do not allow you to mutate the pointed-to string bytes and it
+doesn’t allow you to insert or remove bytes from the range. For editing
+operations like this, it interoperates with the <a class="reference internal" href="#dss-twine"><em>Twine</em></a>
+class.</li>
+</ol>
+<p>Because of its strengths and limitations, it is very common for a function to
+take a StringRef and for a method on an object to return a StringRef that points
+into some string that it owns.</p>
+</div>
+<div class="section" id="llvm-adt-twine-h">
+<span id="dss-twine"></span><h4><a class="toc-backref" href="#id42">llvm/ADT/Twine.h</a><a class="headerlink" href="#llvm-adt-twine-h" title="Permalink to this headline">¶</a></h4>
+<p>The Twine class is used as an intermediary datatype for APIs that want to take a
+string that can be constructed inline with a series of concatenations. Twine
+works by forming recursive instances of the Twine datatype (a simple value
+object) on the stack as temporary objects, linking them together into a tree
+which is then linearized when the Twine is consumed. Twine is only safe to use
+as the argument to a function, and should always be a const reference, e.g.:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="kt">void</span> <span class="nf">foo</span><span class="p">(</span><span class="k">const</span> <span class="n">Twine</span> <span class="o">&</span><span class="n">T</span><span class="p">);</span>
+<span class="p">...</span>
+<span class="n">StringRef</span> <span class="n">X</span> <span class="o">=</span> <span class="p">...</span>
+<span class="kt">unsigned</span> <span class="n">i</span> <span class="o">=</span> <span class="p">...</span>
+<span class="n">foo</span><span class="p">(</span><span class="n">X</span> <span class="o">+</span> <span class="s">"."</span> <span class="o">+</span> <span class="n">Twine</span><span class="p">(</span><span class="n">i</span><span class="p">));</span>
+</pre></div>
+</div>
+<p>This example forms a string like “blarg.42” by concatenating the values
+together, and does not form intermediate strings containing “blarg” or “blarg.”.</p>
+<p>Because Twine is constructed with temporary objects on the stack, and because
+these instances are destroyed at the end of the current statement, it is an
+inherently dangerous API. For example, this simple variant contains undefined
+behavior and will probably crash:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="kt">void</span> <span class="nf">foo</span><span class="p">(</span><span class="k">const</span> <span class="n">Twine</span> <span class="o">&</span><span class="n">T</span><span class="p">);</span>
+<span class="p">...</span>
+<span class="n">StringRef</span> <span class="n">X</span> <span class="o">=</span> <span class="p">...</span>
+<span class="kt">unsigned</span> <span class="n">i</span> <span class="o">=</span> <span class="p">...</span>
+<span class="k">const</span> <span class="n">Twine</span> <span class="o">&</span><span class="n">Tmp</span> <span class="o">=</span> <span class="n">X</span> <span class="o">+</span> <span class="s">"."</span> <span class="o">+</span> <span class="n">Twine</span><span class="p">(</span><span class="n">i</span><span class="p">);</span>
+<span class="n">foo</span><span class="p">(</span><span class="n">Tmp</span><span class="p">);</span>
+</pre></div>
+</div>
+<p>... because the temporaries are destroyed before the call. That said, Twine’s
+are much more efficient than intermediate std::string temporaries, and they work
+really well with StringRef. Just be aware of their limitations.</p>
+</div>
+<div class="section" id="llvm-adt-smallstring-h">
+<span id="dss-smallstring"></span><h4><a class="toc-backref" href="#id43">llvm/ADT/SmallString.h</a><a class="headerlink" href="#llvm-adt-smallstring-h" title="Permalink to this headline">¶</a></h4>
+<p>SmallString is a subclass of <a class="reference internal" href="#dss-smallvector"><em>SmallVector</em></a> that adds some
+convenience APIs like += that takes StringRef’s. SmallString avoids allocating
+memory in the case when the preallocated space is enough to hold its data, and
+it calls back to general heap allocation when required. Since it owns its data,
+it is very safe to use and supports full mutation of the string.</p>
+<p>Like SmallVector’s, the big downside to SmallString is their sizeof. While they
+are optimized for small strings, they themselves are not particularly small.
+This means that they work great for temporary scratch buffers on the stack, but
+should not generally be put into the heap: it is very rare to see a SmallString
+as the member of a frequently-allocated heap data structure or returned
+by-value.</p>
+</div>
+<div class="section" id="std-string">
+<span id="dss-stdstring"></span><h4><a class="toc-backref" href="#id44">std::string</a><a class="headerlink" href="#std-string" title="Permalink to this headline">¶</a></h4>
+<p>The standard C++ std::string class is a very general class that (like
+SmallString) owns its underlying data. sizeof(std::string) is very reasonable
+so it can be embedded into heap data structures and returned by-value. On the
+other hand, std::string is highly inefficient for inline editing (e.g.
+concatenating a bunch of stuff together) and because it is provided by the
+standard library, its performance characteristics depend a lot of the host
+standard library (e.g. libc++ and MSVC provide a highly optimized string class,
+GCC contains a really slow implementation).</p>
+<p>The major disadvantage of std::string is that almost every operation that makes
+them larger can allocate memory, which is slow. As such, it is better to use
+SmallVector or Twine as a scratch buffer, but then use std::string to persist
+the result.</p>
+</div>
+</div>
+<div class="section" id="set-like-containers-std-set-smallset-setvector-etc">
+<span id="ds-set"></span><h3><a class="toc-backref" href="#id45">Set-Like Containers (std::set, SmallSet, SetVector, etc)</a><a class="headerlink" href="#set-like-containers-std-set-smallset-setvector-etc" title="Permalink to this headline">¶</a></h3>
+<p>Set-like containers are useful when you need to canonicalize multiple values
+into a single representation. There are several different choices for how to do
+this, providing various trade-offs.</p>
+<div class="section" id="a-sorted-vector">
+<span id="dss-sortedvectorset"></span><h4><a class="toc-backref" href="#id46">A sorted ‘vector’</a><a class="headerlink" href="#a-sorted-vector" title="Permalink to this headline">¶</a></h4>
+<p>If you intend to insert a lot of elements, then do a lot of queries, a great
+approach is to use a vector (or other sequential container) with
+std::sort+std::unique to remove duplicates. This approach works really well if
+your usage pattern has these two distinct phases (insert then query), and can be
+coupled with a good choice of <a class="reference internal" href="#ds-sequential"><em>sequential container</em></a>.</p>
+<p>This combination provides the several nice properties: the result data is
+contiguous in memory (good for cache locality), has few allocations, is easy to
+address (iterators in the final vector are just indices or pointers), and can be
+efficiently queried with a standard binary search (e.g.
+<tt class="docutils literal"><span class="pre">std::lower_bound</span></tt>; if you want the whole range of elements comparing
+equal, use <tt class="docutils literal"><span class="pre">std::equal_range</span></tt>).</p>
+</div>
+<div class="section" id="llvm-adt-smallset-h">
+<span id="dss-smallset"></span><h4><a class="toc-backref" href="#id47">llvm/ADT/SmallSet.h</a><a class="headerlink" href="#llvm-adt-smallset-h" title="Permalink to this headline">¶</a></h4>
+<p>If you have a set-like data structure that is usually small and whose elements
+are reasonably small, a <tt class="docutils literal"><span class="pre">SmallSet<Type,</span> <span class="pre">N></span></tt> is a good choice. This set has
+space for N elements in place (thus, if the set is dynamically smaller than N,
+no malloc traffic is required) and accesses them with a simple linear search.
+When the set grows beyond N elements, it allocates a more expensive
+representation that guarantees efficient access (for most types, it falls back
+to <a class="reference internal" href="#dss-set"><em>std::set</em></a>, but for pointers it uses something far better,
+<a class="reference internal" href="#dss-smallptrset"><em>SmallPtrSet</em></a>.</p>
+<p>The magic of this class is that it handles small sets extremely efficiently, but
+gracefully handles extremely large sets without loss of efficiency. The
+drawback is that the interface is quite small: it supports insertion, queries
+and erasing, but does not support iteration.</p>
+</div>
+<div class="section" id="llvm-adt-smallptrset-h">
+<span id="dss-smallptrset"></span><h4><a class="toc-backref" href="#id48">llvm/ADT/SmallPtrSet.h</a><a class="headerlink" href="#llvm-adt-smallptrset-h" title="Permalink to this headline">¶</a></h4>
+<p><tt class="docutils literal"><span class="pre">SmallPtrSet</span></tt> has all the advantages of <tt class="docutils literal"><span class="pre">SmallSet</span></tt> (and a <tt class="docutils literal"><span class="pre">SmallSet</span></tt> of
+pointers is transparently implemented with a <tt class="docutils literal"><span class="pre">SmallPtrSet</span></tt>), but also supports
+iterators. If more than N insertions are performed, a single quadratically
+probed hash table is allocated and grows as needed, providing extremely
+efficient access (constant time insertion/deleting/queries with low constant
+factors) and is very stingy with malloc traffic.</p>
+<p>Note that, unlike <a class="reference internal" href="#dss-set"><em>std::set</em></a>, the iterators of <tt class="docutils literal"><span class="pre">SmallPtrSet</span></tt>
+are invalidated whenever an insertion occurs. Also, the values visited by the
+iterators are not visited in sorted order.</p>
+</div>
+<div class="section" id="llvm-adt-stringset-h">
+<span id="dss-stringset"></span><h4><a class="toc-backref" href="#id49">llvm/ADT/StringSet.h</a><a class="headerlink" href="#llvm-adt-stringset-h" title="Permalink to this headline">¶</a></h4>
+<p><tt class="docutils literal"><span class="pre">StringSet</span></tt> is a thin wrapper around <a class="reference internal" href="#dss-stringmap"><em>StringMap<char></em></a>,
+and it allows efficient storage and retrieval of unique strings.</p>
+<p>Functionally analogous to <tt class="docutils literal"><span class="pre">SmallSet<StringRef></span></tt>, <tt class="docutils literal"><span class="pre">StringSet</span></tt> also suports
+iteration. (The iterator dereferences to a <tt class="docutils literal"><span class="pre">StringMapEntry<char></span></tt>, so you
+need to call <tt class="docutils literal"><span class="pre">i->getKey()</span></tt> to access the item of the StringSet.) On the
+other hand, <tt class="docutils literal"><span class="pre">StringSet</span></tt> doesn’t support range-insertion and
+copy-construction, which <a class="reference internal" href="#dss-smallset"><em>SmallSet</em></a> and <a class="reference internal" href="#dss-smallptrset"><em>SmallPtrSet</em></a> do support.</p>
+</div>
+<div class="section" id="llvm-adt-denseset-h">
+<span id="dss-denseset"></span><h4><a class="toc-backref" href="#id50">llvm/ADT/DenseSet.h</a><a class="headerlink" href="#llvm-adt-denseset-h" title="Permalink to this headline">¶</a></h4>
+<p>DenseSet is a simple quadratically probed hash table. It excels at supporting
+small values: it uses a single allocation to hold all of the pairs that are
+currently inserted in the set. DenseSet is a great way to unique small values
+that are not simple pointers (use <a class="reference internal" href="#dss-smallptrset"><em>SmallPtrSet</em></a> for
+pointers). Note that DenseSet has the same requirements for the value type that
+<a class="reference internal" href="#dss-densemap"><em>DenseMap</em></a> has.</p>
+</div>
+<div class="section" id="llvm-adt-sparseset-h">
+<span id="dss-sparseset"></span><h4><a class="toc-backref" href="#id51">llvm/ADT/SparseSet.h</a><a class="headerlink" href="#llvm-adt-sparseset-h" title="Permalink to this headline">¶</a></h4>
+<p>SparseSet holds a small number of objects identified by unsigned keys of
+moderate size. It uses a lot of memory, but provides operations that are almost
+as fast as a vector. Typical keys are physical registers, virtual registers, or
+numbered basic blocks.</p>
+<p>SparseSet is useful for algorithms that need very fast clear/find/insert/erase
+and fast iteration over small sets. It is not intended for building composite
+data structures.</p>
+</div>
+<div class="section" id="llvm-adt-sparsemultiset-h">
+<span id="dss-sparsemultiset"></span><h4><a class="toc-backref" href="#id52">llvm/ADT/SparseMultiSet.h</a><a class="headerlink" href="#llvm-adt-sparsemultiset-h" title="Permalink to this headline">¶</a></h4>
+<p>SparseMultiSet adds multiset behavior to SparseSet, while retaining SparseSet’s
+desirable attributes. Like SparseSet, it typically uses a lot of memory, but
+provides operations that are almost as fast as a vector. Typical keys are
+physical registers, virtual registers, or numbered basic blocks.</p>
+<p>SparseMultiSet is useful for algorithms that need very fast
+clear/find/insert/erase of the entire collection, and iteration over sets of
+elements sharing a key. It is often a more efficient choice than using composite
+data structures (e.g. vector-of-vectors, map-of-vectors). It is not intended for
+building composite data structures.</p>
+</div>
+<div class="section" id="llvm-adt-foldingset-h">
+<span id="dss-foldingset"></span><h4><a class="toc-backref" href="#id53">llvm/ADT/FoldingSet.h</a><a class="headerlink" href="#llvm-adt-foldingset-h" title="Permalink to this headline">¶</a></h4>
+<p>FoldingSet is an aggregate class that is really good at uniquing
+expensive-to-create or polymorphic objects. It is a combination of a chained
+hash table with intrusive links (uniqued objects are required to inherit from
+FoldingSetNode) that uses <a class="reference internal" href="#dss-smallvector"><em>SmallVector</em></a> as part of its ID
+process.</p>
+<p>Consider a case where you want to implement a “getOrCreateFoo” method for a
+complex object (for example, a node in the code generator). The client has a
+description of <strong>what</strong> it wants to generate (it knows the opcode and all the
+operands), but we don’t want to ‘new’ a node, then try inserting it into a set
+only to find out it already exists, at which point we would have to delete it
+and return the node that already exists.</p>
+<p>To support this style of client, FoldingSet perform a query with a
+FoldingSetNodeID (which wraps SmallVector) that can be used to describe the
+element that we want to query for. The query either returns the element
+matching the ID or it returns an opaque ID that indicates where insertion should
+take place. Construction of the ID usually does not require heap traffic.</p>
+<p>Because FoldingSet uses intrusive links, it can support polymorphic objects in
+the set (for example, you can have SDNode instances mixed with LoadSDNodes).
+Because the elements are individually allocated, pointers to the elements are
+stable: inserting or removing elements does not invalidate any pointers to other
+elements.</p>
+</div>
+<div class="section" id="set">
+<span id="dss-set"></span><h4><a class="toc-backref" href="#id54"><set></a><a class="headerlink" href="#set" title="Permalink to this headline">¶</a></h4>
+<p><tt class="docutils literal"><span class="pre">std::set</span></tt> is a reasonable all-around set class, which is decent at many
+things but great at nothing. std::set allocates memory for each element
+inserted (thus it is very malloc intensive) and typically stores three pointers
+per element in the set (thus adding a large amount of per-element space
+overhead). It offers guaranteed log(n) performance, which is not particularly
+fast from a complexity standpoint (particularly if the elements of the set are
+expensive to compare, like strings), and has extremely high constant factors for
+lookup, insertion and removal.</p>
+<p>The advantages of std::set are that its iterators are stable (deleting or
+inserting an element from the set does not affect iterators or pointers to other
+elements) and that iteration over the set is guaranteed to be in sorted order.
+If the elements in the set are large, then the relative overhead of the pointers
+and malloc traffic is not a big deal, but if the elements of the set are small,
+std::set is almost never a good choice.</p>
+</div>
+<div class="section" id="llvm-adt-setvector-h">
+<span id="dss-setvector"></span><h4><a class="toc-backref" href="#id55">llvm/ADT/SetVector.h</a><a class="headerlink" href="#llvm-adt-setvector-h" title="Permalink to this headline">¶</a></h4>
+<p>LLVM’s <tt class="docutils literal"><span class="pre">SetVector<Type></span></tt> is an adapter class that combines your choice of a
+set-like container along with a <a class="reference internal" href="#ds-sequential"><em>Sequential Container</em></a> The
+important property that this provides is efficient insertion with uniquing
+(duplicate elements are ignored) with iteration support. It implements this by
+inserting elements into both a set-like container and the sequential container,
+using the set-like container for uniquing and the sequential container for
+iteration.</p>
+<p>The difference between SetVector and other sets is that the order of iteration
+is guaranteed to match the order of insertion into the SetVector. This property
+is really important for things like sets of pointers. Because pointer values
+are non-deterministic (e.g. vary across runs of the program on different
+machines), iterating over the pointers in the set will not be in a well-defined
+order.</p>
+<p>The drawback of SetVector is that it requires twice as much space as a normal
+set and has the sum of constant factors from the set-like container and the
+sequential container that it uses. Use it <strong>only</strong> if you need to iterate over
+the elements in a deterministic order. SetVector is also expensive to delete
+elements out of (linear time), unless you use its “pop_back” method, which is
+faster.</p>
+<p><tt class="docutils literal"><span class="pre">SetVector</span></tt> is an adapter class that defaults to using <tt class="docutils literal"><span class="pre">std::vector</span></tt> and a
+size 16 <tt class="docutils literal"><span class="pre">SmallSet</span></tt> for the underlying containers, so it is quite expensive.
+However, <tt class="docutils literal"><span class="pre">"llvm/ADT/SetVector.h"</span></tt> also provides a <tt class="docutils literal"><span class="pre">SmallSetVector</span></tt> class,
+which defaults to using a <tt class="docutils literal"><span class="pre">SmallVector</span></tt> and <tt class="docutils literal"><span class="pre">SmallSet</span></tt> of a specified size.
+If you use this, and if your sets are dynamically smaller than <tt class="docutils literal"><span class="pre">N</span></tt>, you will
+save a lot of heap traffic.</p>
+</div>
+<div class="section" id="llvm-adt-uniquevector-h">
+<span id="dss-uniquevector"></span><h4><a class="toc-backref" href="#id56">llvm/ADT/UniqueVector.h</a><a class="headerlink" href="#llvm-adt-uniquevector-h" title="Permalink to this headline">¶</a></h4>
+<p>UniqueVector is similar to <a class="reference internal" href="#dss-setvector"><em>SetVector</em></a> but it retains a
+unique ID for each element inserted into the set. It internally contains a map
+and a vector, and it assigns a unique ID for each value inserted into the set.</p>
+<p>UniqueVector is very expensive: its cost is the sum of the cost of maintaining
+both the map and vector, it has high complexity, high constant factors, and
+produces a lot of malloc traffic. It should be avoided.</p>
+</div>
+<div class="section" id="llvm-adt-immutableset-h">
+<span id="dss-immutableset"></span><h4><a class="toc-backref" href="#id57">llvm/ADT/ImmutableSet.h</a><a class="headerlink" href="#llvm-adt-immutableset-h" title="Permalink to this headline">¶</a></h4>
+<p>ImmutableSet is an immutable (functional) set implementation based on an AVL
+tree. Adding or removing elements is done through a Factory object and results
+in the creation of a new ImmutableSet object. If an ImmutableSet already exists
+with the given contents, then the existing one is returned; equality is compared
+with a FoldingSetNodeID. The time and space complexity of add or remove
+operations is logarithmic in the size of the original set.</p>
+<p>There is no method for returning an element of the set, you can only check for
+membership.</p>
+</div>
+<div class="section" id="other-set-like-container-options">
+<span id="dss-otherset"></span><h4><a class="toc-backref" href="#id58">Other Set-Like Container Options</a><a class="headerlink" href="#other-set-like-container-options" title="Permalink to this headline">¶</a></h4>
+<p>The STL provides several other options, such as std::multiset and the various
+“hash_set” like containers (whether from C++ TR1 or from the SGI library). We
+never use hash_set and unordered_set because they are generally very expensive
+(each insertion requires a malloc) and very non-portable.</p>
+<p>std::multiset is useful if you’re not interested in elimination of duplicates,
+but has all the drawbacks of <a class="reference internal" href="#dss-set"><em>std::set</em></a>. A sorted vector
+(where you don’t delete duplicate entries) or some other approach is almost
+always better.</p>
+</div>
+</div>
+<div class="section" id="map-like-containers-std-map-densemap-etc">
+<span id="ds-map"></span><h3><a class="toc-backref" href="#id59">Map-Like Containers (std::map, DenseMap, etc)</a><a class="headerlink" href="#map-like-containers-std-map-densemap-etc" title="Permalink to this headline">¶</a></h3>
+<p>Map-like containers are useful when you want to associate data to a key. As
+usual, there are a lot of different ways to do this. :)</p>
+<div class="section" id="dss-sortedvectormap">
+<span id="id2"></span><h4><a class="toc-backref" href="#id60">A sorted ‘vector’</a><a class="headerlink" href="#dss-sortedvectormap" title="Permalink to this headline">¶</a></h4>
+<p>If your usage pattern follows a strict insert-then-query approach, you can
+trivially use the same approach as <a class="reference internal" href="#dss-sortedvectorset"><em>sorted vectors for set-like containers</em></a>. The only difference is that your query function (which
+uses std::lower_bound to get efficient log(n) lookup) should only compare the
+key, not both the key and value. This yields the same advantages as sorted
+vectors for sets.</p>
+</div>
+<div class="section" id="llvm-adt-stringmap-h">
+<span id="dss-stringmap"></span><h4><a class="toc-backref" href="#id61">llvm/ADT/StringMap.h</a><a class="headerlink" href="#llvm-adt-stringmap-h" title="Permalink to this headline">¶</a></h4>
+<p>Strings are commonly used as keys in maps, and they are difficult to support
+efficiently: they are variable length, inefficient to hash and compare when
+long, expensive to copy, etc. StringMap is a specialized container designed to
+cope with these issues. It supports mapping an arbitrary range of bytes to an
+arbitrary other object.</p>
+<p>The StringMap implementation uses a quadratically-probed hash table, where the
+buckets store a pointer to the heap allocated entries (and some other stuff).
+The entries in the map must be heap allocated because the strings are variable
+length. The string data (key) and the element object (value) are stored in the
+same allocation with the string data immediately after the element object.
+This container guarantees the “<tt class="docutils literal"><span class="pre">(char*)(&Value+1)</span></tt>” points to the key string
+for a value.</p>
+<p>The StringMap is very fast for several reasons: quadratic probing is very cache
+efficient for lookups, the hash value of strings in buckets is not recomputed
+when looking up an element, StringMap rarely has to touch the memory for
+unrelated objects when looking up a value (even when hash collisions happen),
+hash table growth does not recompute the hash values for strings already in the
+table, and each pair in the map is store in a single allocation (the string data
+is stored in the same allocation as the Value of a pair).</p>
+<p>StringMap also provides query methods that take byte ranges, so it only ever
+copies a string if a value is inserted into the table.</p>
+<p>StringMap iteratation order, however, is not guaranteed to be deterministic, so
+any uses which require that should instead use a std::map.</p>
+</div>
+<div class="section" id="llvm-adt-indexedmap-h">
+<span id="dss-indexmap"></span><h4><a class="toc-backref" href="#id62">llvm/ADT/IndexedMap.h</a><a class="headerlink" href="#llvm-adt-indexedmap-h" title="Permalink to this headline">¶</a></h4>
+<p>IndexedMap is a specialized container for mapping small dense integers (or
+values that can be mapped to small dense integers) to some other type. It is
+internally implemented as a vector with a mapping function that maps the keys
+to the dense integer range.</p>
+<p>This is useful for cases like virtual registers in the LLVM code generator: they
+have a dense mapping that is offset by a compile-time constant (the first
+virtual register ID).</p>
+</div>
+<div class="section" id="llvm-adt-densemap-h">
+<span id="dss-densemap"></span><h4><a class="toc-backref" href="#id63">llvm/ADT/DenseMap.h</a><a class="headerlink" href="#llvm-adt-densemap-h" title="Permalink to this headline">¶</a></h4>
+<p>DenseMap is a simple quadratically probed hash table. It excels at supporting
+small keys and values: it uses a single allocation to hold all of the pairs
+that are currently inserted in the map. DenseMap is a great way to map
+pointers to pointers, or map other small types to each other.</p>
+<p>There are several aspects of DenseMap that you should be aware of, however.
+The iterators in a DenseMap are invalidated whenever an insertion occurs,
+unlike map. Also, because DenseMap allocates space for a large number of
+key/value pairs (it starts with 64 by default), it will waste a lot of space if
+your keys or values are large. Finally, you must implement a partial
+specialization of DenseMapInfo for the key that you want, if it isn’t already
+supported. This is required to tell DenseMap about two special marker values
+(which can never be inserted into the map) that it needs internally.</p>
+<p>DenseMap’s find_as() method supports lookup operations using an alternate key
+type. This is useful in cases where the normal key type is expensive to
+construct, but cheap to compare against. The DenseMapInfo is responsible for
+defining the appropriate comparison and hashing methods for each alternate key
+type used.</p>
+</div>
+<div class="section" id="llvm-ir-valuemap-h">
+<span id="dss-valuemap"></span><h4><a class="toc-backref" href="#id64">llvm/IR/ValueMap.h</a><a class="headerlink" href="#llvm-ir-valuemap-h" title="Permalink to this headline">¶</a></h4>
+<p>ValueMap is a wrapper around a <a class="reference internal" href="#dss-densemap"><em>DenseMap</em></a> mapping
+<tt class="docutils literal"><span class="pre">Value*</span></tt>s (or subclasses) to another type. When a Value is deleted or
+RAUW’ed, ValueMap will update itself so the new version of the key is mapped to
+the same value, just as if the key were a WeakVH. You can configure exactly how
+this happens, and what else happens on these two events, by passing a <tt class="docutils literal"><span class="pre">Config</span></tt>
+parameter to the ValueMap template.</p>
+</div>
+<div class="section" id="llvm-adt-intervalmap-h">
+<span id="dss-intervalmap"></span><h4><a class="toc-backref" href="#id65">llvm/ADT/IntervalMap.h</a><a class="headerlink" href="#llvm-adt-intervalmap-h" title="Permalink to this headline">¶</a></h4>
+<p>IntervalMap is a compact map for small keys and values. It maps key intervals
+instead of single keys, and it will automatically coalesce adjacent intervals.
+When the map only contains a few intervals, they are stored in the map object
+itself to avoid allocations.</p>
+<p>The IntervalMap iterators are quite big, so they should not be passed around as
+STL iterators. The heavyweight iterators allow a smaller data structure.</p>
+</div>
+<div class="section" id="map">
+<span id="dss-map"></span><h4><a class="toc-backref" href="#id66"><map></a><a class="headerlink" href="#map" title="Permalink to this headline">¶</a></h4>
+<p>std::map has similar characteristics to <a class="reference internal" href="#dss-set"><em>std::set</em></a>: it uses a
+single allocation per pair inserted into the map, it offers log(n) lookup with
+an extremely large constant factor, imposes a space penalty of 3 pointers per
+pair in the map, etc.</p>
+<p>std::map is most useful when your keys or values are very large, if you need to
+iterate over the collection in sorted order, or if you need stable iterators
+into the map (i.e. they don’t get invalidated if an insertion or deletion of
+another element takes place).</p>
+</div>
+<div class="section" id="llvm-adt-mapvector-h">
+<span id="dss-mapvector"></span><h4><a class="toc-backref" href="#id67">llvm/ADT/MapVector.h</a><a class="headerlink" href="#llvm-adt-mapvector-h" title="Permalink to this headline">¶</a></h4>
+<p><tt class="docutils literal"><span class="pre">MapVector<KeyT,ValueT></span></tt> 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 removing elements takes linear time. If it is
+necessary to remove elements, it’s best to remove them in bulk using
+<tt class="docutils literal"><span class="pre">remove_if()</span></tt>.</p>
+</div>
+<div class="section" id="llvm-adt-inteqclasses-h">
+<span id="dss-inteqclasses"></span><h4><a class="toc-backref" href="#id68">llvm/ADT/IntEqClasses.h</a><a class="headerlink" href="#llvm-adt-inteqclasses-h" title="Permalink to this headline">¶</a></h4>
+<p>IntEqClasses provides a compact representation of equivalence classes of small
+integers. Initially, each integer in the range 0..n-1 has its own equivalence
+class. Classes can be joined by passing two class representatives to the
+join(a, b) method. Two integers are in the same class when findLeader() returns
+the same representative.</p>
+<p>Once all equivalence classes are formed, the map can be compressed so each
+integer 0..n-1 maps to an equivalence class number in the range 0..m-1, where m
+is the total number of equivalence classes. The map must be uncompressed before
+it can be edited again.</p>
+</div>
+<div class="section" id="llvm-adt-immutablemap-h">
+<span id="dss-immutablemap"></span><h4><a class="toc-backref" href="#id69">llvm/ADT/ImmutableMap.h</a><a class="headerlink" href="#llvm-adt-immutablemap-h" title="Permalink to this headline">¶</a></h4>
+<p>ImmutableMap is an immutable (functional) map implementation based on an AVL
+tree. Adding or removing elements is done through a Factory object and results
+in the creation of a new ImmutableMap object. If an ImmutableMap already exists
+with the given key set, then the existing one is returned; equality is compared
+with a FoldingSetNodeID. The time and space complexity of add or remove
+operations is logarithmic in the size of the original map.</p>
+</div>
+<div class="section" id="other-map-like-container-options">
+<span id="dss-othermap"></span><h4><a class="toc-backref" href="#id70">Other Map-Like Container Options</a><a class="headerlink" href="#other-map-like-container-options" title="Permalink to this headline">¶</a></h4>
+<p>The STL provides several other options, such as std::multimap and the various
+“hash_map” like containers (whether from C++ TR1 or from the SGI library). We
+never use hash_set and unordered_set because they are generally very expensive
+(each insertion requires a malloc) and very non-portable.</p>
+<p>std::multimap is useful if you want to map a key to multiple values, but has all
+the drawbacks of std::map. A sorted vector or some other approach is almost
+always better.</p>
+</div>
+</div>
+<div class="section" id="bit-storage-containers-bitvector-sparsebitvector">
+<span id="ds-bit"></span><h3><a class="toc-backref" href="#id71">Bit storage containers (BitVector, SparseBitVector)</a><a class="headerlink" href="#bit-storage-containers-bitvector-sparsebitvector" title="Permalink to this headline">¶</a></h3>
+<p>Unlike the other containers, there are only two bit storage containers, and
+choosing when to use each is relatively straightforward.</p>
+<p>One additional option is <tt class="docutils literal"><span class="pre">std::vector<bool></span></tt>: we discourage its use for two
+reasons 1) the implementation in many common compilers (e.g. commonly
+available versions of GCC) is extremely inefficient and 2) the C++ standards
+committee is likely to deprecate this container and/or change it significantly
+somehow. In any case, please don’t use it.</p>
+<div class="section" id="bitvector">
+<span id="dss-bitvector"></span><h4><a class="toc-backref" href="#id72">BitVector</a><a class="headerlink" href="#bitvector" title="Permalink to this headline">¶</a></h4>
+<p>The BitVector container provides a dynamic size set of bits for manipulation.
+It supports individual bit setting/testing, as well as set operations. The set
+operations take time O(size of bitvector), but operations are performed one word
+at a time, instead of one bit at a time. This makes the BitVector very fast for
+set operations compared to other containers. Use the BitVector when you expect
+the number of set bits to be high (i.e. a dense set).</p>
+</div>
+<div class="section" id="smallbitvector">
+<span id="dss-smallbitvector"></span><h4><a class="toc-backref" href="#id73">SmallBitVector</a><a class="headerlink" href="#smallbitvector" title="Permalink to this headline">¶</a></h4>
+<p>The SmallBitVector container provides the same interface as BitVector, but it is
+optimized for the case where only a small number of bits, less than 25 or so,
+are needed. It also transparently supports larger bit counts, but slightly less
+efficiently than a plain BitVector, so SmallBitVector should only be used when
+larger counts are rare.</p>
+<p>At this time, SmallBitVector does not support set operations (and, or, xor), and
+its operator[] does not provide an assignable lvalue.</p>
+</div>
+<div class="section" id="sparsebitvector">
+<span id="dss-sparsebitvector"></span><h4><a class="toc-backref" href="#id74">SparseBitVector</a><a class="headerlink" href="#sparsebitvector" title="Permalink to this headline">¶</a></h4>
+<p>The SparseBitVector container is much like BitVector, with one major difference:
+Only the bits that are set, are stored. This makes the SparseBitVector much
+more space efficient than BitVector when the set is sparse, as well as making
+set operations O(number of set bits) instead of O(size of universe). The
+downside to the SparseBitVector is that setting and testing of random bits is
+O(N), and on large SparseBitVectors, this can be slower than BitVector. In our
+implementation, setting or testing bits in sorted order (either forwards or
+reverse) is O(1) worst case. Testing and setting bits within 128 bits (depends
+on size) of the current bit is also O(1). As a general statement,
+testing/setting bits in a SparseBitVector is O(distance away from last set bit).</p>
+</div>
+</div>
+</div>
+<div class="section" id="helpful-hints-for-common-operations">
+<span id="common"></span><h2><a class="toc-backref" href="#id75">Helpful Hints for Common Operations</a><a class="headerlink" href="#helpful-hints-for-common-operations" title="Permalink to this headline">¶</a></h2>
+<p>This section describes how to perform some very simple transformations of LLVM
+code. This is meant to give examples of common idioms used, showing the
+practical side of LLVM transformations.</p>
+<p>Because this is a “how-to” section, you should also read about the main classes
+that you will be working with. The <a class="reference internal" href="#coreclasses"><em>Core LLVM Class Hierarchy Reference</em></a> contains details and descriptions of the main classes that you
+should know about.</p>
+<div class="section" id="basic-inspection-and-traversal-routines">
+<span id="inspection"></span><h3><a class="toc-backref" href="#id76">Basic Inspection and Traversal Routines</a><a class="headerlink" href="#basic-inspection-and-traversal-routines" title="Permalink to this headline">¶</a></h3>
+<p>The LLVM compiler infrastructure have many different data structures that may be
+traversed. Following the example of the C++ standard template library, the
+techniques used to traverse these various data structures are all basically the
+same. For a enumerable sequence of values, the <tt class="docutils literal"><span class="pre">XXXbegin()</span></tt> function (or
+method) returns an iterator to the start of the sequence, the <tt class="docutils literal"><span class="pre">XXXend()</span></tt>
+function returns an iterator pointing to one past the last valid element of the
+sequence, and there is some <tt class="docutils literal"><span class="pre">XXXiterator</span></tt> data type that is common between the
+two operations.</p>
+<p>Because the pattern for iteration is common across many different aspects of the
+program representation, the standard template library algorithms may be used on
+them, and it is easier to remember how to iterate. First we show a few common
+examples of the data structures that need to be traversed. Other data
+structures are traversed in very similar ways.</p>
+<div class="section" id="iterating-over-the-basicblock-in-a-function">
+<span id="iterate-function"></span><h4><a class="toc-backref" href="#id77">Iterating over the <tt class="docutils literal"><span class="pre">BasicBlock</span></tt> in a <tt class="docutils literal"><span class="pre">Function</span></tt></a><a class="headerlink" href="#iterating-over-the-basicblock-in-a-function" title="Permalink to this headline">¶</a></h4>
+<p>It’s quite common to have a <tt class="docutils literal"><span class="pre">Function</span></tt> instance that you’d like to transform
+in some way; in particular, you’d like to manipulate its <tt class="docutils literal"><span class="pre">BasicBlock</span></tt>s. To
+facilitate this, you’ll need to iterate over all of the <tt class="docutils literal"><span class="pre">BasicBlock</span></tt>s that
+constitute the <tt class="docutils literal"><span class="pre">Function</span></tt>. The following is an example that prints the name
+of a <tt class="docutils literal"><span class="pre">BasicBlock</span></tt> and the number of <tt class="docutils literal"><span class="pre">Instruction</span></tt>s it contains:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="c1">// func is a pointer to a Function instance</span>
+<span class="k">for</span> <span class="p">(</span><span class="n">Function</span><span class="o">::</span><span class="n">iterator</span> <span class="n">i</span> <span class="o">=</span> <span class="n">func</span><span class="o">-></span><span class="n">begin</span><span class="p">(),</span> <span class="n">e</span> <span class="o">=</span> <span class="n">func</span><span class="o">-></span><span class="n">end</span><span class="p">();</span> <span class="n">i</span> <span class="o">!=</span> <span class="n">e</span><span class="p">;</span> <span class="o">++</span><span class="n">i</span><span class="p">)</span>
+ <span class="c1">// Print out the name of the basic block if it has one, and then the</span>
+ <span class="c1">// number of instructions that it contains</span>
+ <span class="n">errs</span><span class="p">()</span> <span class="o"><<</span> <span class="s">"Basic block (name="</span> <span class="o"><<</span> <span class="n">i</span><span class="o">-></span><span class="n">getName</span><span class="p">()</span> <span class="o"><<</span> <span class="s">") has "</span>
+ <span class="o"><<</span> <span class="n">i</span><span class="o">-></span><span class="n">size</span><span class="p">()</span> <span class="o"><<</span> <span class="s">" instructions.</span><span class="se">\n</span><span class="s">"</span><span class="p">;</span>
+</pre></div>
+</div>
+<p>Note that i can be used as if it were a pointer for the purposes of invoking
+member functions of the <tt class="docutils literal"><span class="pre">Instruction</span></tt> class. This is because the indirection
+operator is overloaded for the iterator classes. In the above code, the
+expression <tt class="docutils literal"><span class="pre">i->size()</span></tt> is exactly equivalent to <tt class="docutils literal"><span class="pre">(*i).size()</span></tt> just like
+you’d expect.</p>
+</div>
+<div class="section" id="iterating-over-the-instruction-in-a-basicblock">
+<span id="iterate-basicblock"></span><h4><a class="toc-backref" href="#id78">Iterating over the <tt class="docutils literal"><span class="pre">Instruction</span></tt> in a <tt class="docutils literal"><span class="pre">BasicBlock</span></tt></a><a class="headerlink" href="#iterating-over-the-instruction-in-a-basicblock" title="Permalink to this headline">¶</a></h4>
+<p>Just like when dealing with <tt class="docutils literal"><span class="pre">BasicBlock</span></tt>s in <tt class="docutils literal"><span class="pre">Function</span></tt>s, it’s easy to
+iterate over the individual instructions that make up <tt class="docutils literal"><span class="pre">BasicBlock</span></tt>s. Here’s
+a code snippet that prints out each instruction in a <tt class="docutils literal"><span class="pre">BasicBlock</span></tt>:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="c1">// blk is a pointer to a BasicBlock instance</span>
+<span class="k">for</span> <span class="p">(</span><span class="n">BasicBlock</span><span class="o">::</span><span class="n">iterator</span> <span class="n">i</span> <span class="o">=</span> <span class="n">blk</span><span class="o">-></span><span class="n">begin</span><span class="p">(),</span> <span class="n">e</span> <span class="o">=</span> <span class="n">blk</span><span class="o">-></span><span class="n">end</span><span class="p">();</span> <span class="n">i</span> <span class="o">!=</span> <span class="n">e</span><span class="p">;</span> <span class="o">++</span><span class="n">i</span><span class="p">)</span>
+ <span class="c1">// The next statement works since operator<<(ostream&,...)</span>
+ <span class="c1">// is overloaded for Instruction&</span>
+ <span class="n">errs</span><span class="p">()</span> <span class="o"><<</span> <span class="o">*</span><span class="n">i</span> <span class="o"><<</span> <span class="s">"</span><span class="se">\n</span><span class="s">"</span><span class="p">;</span>
+</pre></div>
+</div>
+<p>However, this isn’t really the best way to print out the contents of a
+<tt class="docutils literal"><span class="pre">BasicBlock</span></tt>! Since the ostream operators are overloaded for virtually
+anything you’ll care about, you could have just invoked the print routine on the
+basic block itself: <tt class="docutils literal"><span class="pre">errs()</span> <span class="pre"><<</span> <span class="pre">*blk</span> <span class="pre"><<</span> <span class="pre">"\n";</span></tt>.</p>
+</div>
+<div class="section" id="iterating-over-the-instruction-in-a-function">
+<span id="iterate-insiter"></span><h4><a class="toc-backref" href="#id79">Iterating over the <tt class="docutils literal"><span class="pre">Instruction</span></tt> in a <tt class="docutils literal"><span class="pre">Function</span></tt></a><a class="headerlink" href="#iterating-over-the-instruction-in-a-function" title="Permalink to this headline">¶</a></h4>
+<p>If you’re finding that you commonly iterate over a <tt class="docutils literal"><span class="pre">Function</span></tt>‘s
+<tt class="docutils literal"><span class="pre">BasicBlock</span></tt>s and then that <tt class="docutils literal"><span class="pre">BasicBlock</span></tt>‘s <tt class="docutils literal"><span class="pre">Instruction</span></tt>s,
+<tt class="docutils literal"><span class="pre">InstIterator</span></tt> should be used instead. You’ll need to include
+<tt class="docutils literal"><span class="pre">llvm/IR/InstIterator.h</span></tt> (<a class="reference external" href="http://llvm.org/doxygen/InstIterator_8h.html">doxygen</a>) and then instantiate
+<tt class="docutils literal"><span class="pre">InstIterator</span></tt>s explicitly in your code. Here’s a small example that shows
+how to dump all instructions in a function to the standard error stream:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="cp">#include "llvm/IR/InstIterator.h"</span>
+
+<span class="c1">// F is a pointer to a Function instance</span>
+<span class="k">for</span> <span class="p">(</span><span class="n">inst_iterator</span> <span class="n">I</span> <span class="o">=</span> <span class="n">inst_begin</span><span class="p">(</span><span class="n">F</span><span class="p">),</span> <span class="n">E</span> <span class="o">=</span> <span class="n">inst_end</span><span class="p">(</span><span class="n">F</span><span class="p">);</span> <span class="n">I</span> <span class="o">!=</span> <span class="n">E</span><span class="p">;</span> <span class="o">++</span><span class="n">I</span><span class="p">)</span>
+ <span class="n">errs</span><span class="p">()</span> <span class="o"><<</span> <span class="o">*</span><span class="n">I</span> <span class="o"><<</span> <span class="s">"</span><span class="se">\n</span><span class="s">"</span><span class="p">;</span>
+</pre></div>
+</div>
+<p>Easy, isn’t it? You can also use <tt class="docutils literal"><span class="pre">InstIterator</span></tt>s to fill a work list with
+its initial contents. For example, if you wanted to initialize a work list to
+contain all instructions in a <tt class="docutils literal"><span class="pre">Function</span></tt> F, all you would need to do is
+something like:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">std</span><span class="o">::</span><span class="n">set</span><span class="o"><</span><span class="n">Instruction</span><span class="o">*></span> <span class="n">worklist</span><span class="p">;</span>
+<span class="c1">// or better yet, SmallPtrSet<Instruction*, 64> worklist;</span>
+
+<span class="k">for</span> <span class="p">(</span><span class="n">inst_iterator</span> <span class="n">I</span> <span class="o">=</span> <span class="n">inst_begin</span><span class="p">(</span><span class="n">F</span><span class="p">),</span> <span class="n">E</span> <span class="o">=</span> <span class="n">inst_end</span><span class="p">(</span><span class="n">F</span><span class="p">);</span> <span class="n">I</span> <span class="o">!=</span> <span class="n">E</span><span class="p">;</span> <span class="o">++</span><span class="n">I</span><span class="p">)</span>
+ <span class="n">worklist</span><span class="p">.</span><span class="n">insert</span><span class="p">(</span><span class="o">&*</span><span class="n">I</span><span class="p">);</span>
+</pre></div>
+</div>
+<p>The STL set <tt class="docutils literal"><span class="pre">worklist</span></tt> would now contain all instructions in the <tt class="docutils literal"><span class="pre">Function</span></tt>
+pointed to by F.</p>
+</div>
+<div class="section" id="turning-an-iterator-into-a-class-pointer-and-vice-versa">
+<span id="iterate-convert"></span><h4><a class="toc-backref" href="#id80">Turning an iterator into a class pointer (and vice-versa)</a><a class="headerlink" href="#turning-an-iterator-into-a-class-pointer-and-vice-versa" title="Permalink to this headline">¶</a></h4>
+<p>Sometimes, it’ll be useful to grab a reference (or pointer) to a class instance
+when all you’ve got at hand is an iterator. Well, extracting a reference or a
+pointer from an iterator is very straight-forward. Assuming that <tt class="docutils literal"><span class="pre">i</span></tt> is a
+<tt class="docutils literal"><span class="pre">BasicBlock::iterator</span></tt> and <tt class="docutils literal"><span class="pre">j</span></tt> is a <tt class="docutils literal"><span class="pre">BasicBlock::const_iterator</span></tt>:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">Instruction</span><span class="o">&</span> <span class="n">inst</span> <span class="o">=</span> <span class="o">*</span><span class="n">i</span><span class="p">;</span> <span class="c1">// Grab reference to instruction reference</span>
+<span class="n">Instruction</span><span class="o">*</span> <span class="n">pinst</span> <span class="o">=</span> <span class="o">&*</span><span class="n">i</span><span class="p">;</span> <span class="c1">// Grab pointer to instruction reference</span>
+<span class="k">const</span> <span class="n">Instruction</span><span class="o">&</span> <span class="n">inst</span> <span class="o">=</span> <span class="o">*</span><span class="n">j</span><span class="p">;</span>
+</pre></div>
+</div>
+<p>However, the iterators you’ll be working with in the LLVM framework are special:
+they will automatically convert to a ptr-to-instance type whenever they need to.
+Instead of derferencing the iterator and then taking the address of the result,
+you can simply assign the iterator to the proper pointer type and you get the
+dereference and address-of operation as a result of the assignment (behind the
+scenes, this is a result of overloading casting mechanisms). Thus the second
+line of the last example,</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">Instruction</span> <span class="o">*</span><span class="n">pinst</span> <span class="o">=</span> <span class="o">&*</span><span class="n">i</span><span class="p">;</span>
+</pre></div>
+</div>
+<p>is semantically equivalent to</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">Instruction</span> <span class="o">*</span><span class="n">pinst</span> <span class="o">=</span> <span class="n">i</span><span class="p">;</span>
+</pre></div>
+</div>
+<p>It’s also possible to turn a class pointer into the corresponding iterator, and
+this is a constant time operation (very efficient). The following code snippet
+illustrates use of the conversion constructors provided by LLVM iterators. By
+using these, you can explicitly grab the iterator of something without actually
+obtaining it via iteration over some structure:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="kt">void</span> <span class="nf">printNextInstruction</span><span class="p">(</span><span class="n">Instruction</span><span class="o">*</span> <span class="n">inst</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">BasicBlock</span><span class="o">::</span><span class="n">iterator</span> <span class="n">it</span><span class="p">(</span><span class="n">inst</span><span class="p">);</span>
+ <span class="o">++</span><span class="n">it</span><span class="p">;</span> <span class="c1">// After this line, it refers to the instruction after *inst</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">it</span> <span class="o">!=</span> <span class="n">inst</span><span class="o">-></span><span class="n">getParent</span><span class="p">()</span><span class="o">-></span><span class="n">end</span><span class="p">())</span> <span class="n">errs</span><span class="p">()</span> <span class="o"><<</span> <span class="o">*</span><span class="n">it</span> <span class="o"><<</span> <span class="s">"</span><span class="se">\n</span><span class="s">"</span><span class="p">;</span>
+<span class="p">}</span>
+</pre></div>
+</div>
+<p>Unfortunately, these implicit conversions come at a cost; they prevent these
+iterators from conforming to standard iterator conventions, and thus from being
+usable with standard algorithms and containers. For example, they prevent the
+following code, where <tt class="docutils literal"><span class="pre">B</span></tt> is a <tt class="docutils literal"><span class="pre">BasicBlock</span></tt>, from compiling:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">llvm</span><span class="o">::</span><span class="n">SmallVector</span><span class="o"><</span><span class="n">llvm</span><span class="o">::</span><span class="n">Instruction</span> <span class="o">*</span><span class="p">,</span> <span class="mi">16</span><span class="o">></span><span class="p">(</span><span class="n">B</span><span class="o">-></span><span class="n">begin</span><span class="p">(),</span> <span class="n">B</span><span class="o">-></span><span class="n">end</span><span class="p">());</span>
+</pre></div>
+</div>
+<p>Because of this, these implicit conversions may be removed some day, and
+<tt class="docutils literal"><span class="pre">operator*</span></tt> changed to return a pointer instead of a reference.</p>
+</div>
+<div class="section" id="finding-call-sites-a-slightly-more-complex-example">
+<span id="iterate-complex"></span><h4><a class="toc-backref" href="#id81">Finding call sites: a slightly more complex example</a><a class="headerlink" href="#finding-call-sites-a-slightly-more-complex-example" title="Permalink to this headline">¶</a></h4>
+<p>Say that you’re writing a FunctionPass and would like to count all the locations
+in the entire module (that is, across every <tt class="docutils literal"><span class="pre">Function</span></tt>) where a certain
+function (i.e., some <tt class="docutils literal"><span class="pre">Function</span> <span class="pre">*</span></tt>) is already in scope. As you’ll learn
+later, you may want to use an <tt class="docutils literal"><span class="pre">InstVisitor</span></tt> to accomplish this in a much more
+straight-forward manner, but this example will allow us to explore how you’d do
+it if you didn’t have <tt class="docutils literal"><span class="pre">InstVisitor</span></tt> around. In pseudo-code, this is what we
+want to do:</p>
+<div class="highlight-none"><div class="highlight"><pre>initialize callCounter to zero
+for each Function f in the Module
+ for each BasicBlock b in f
+ for each Instruction i in b
+ if (i is a CallInst and calls the given function)
+ increment callCounter
+</pre></div>
+</div>
+<p>And the actual code is (remember, because we’re writing a <tt class="docutils literal"><span class="pre">FunctionPass</span></tt>, our
+<tt class="docutils literal"><span class="pre">FunctionPass</span></tt>-derived class simply has to override the <tt class="docutils literal"><span class="pre">runOnFunction</span></tt>
+method):</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">Function</span><span class="o">*</span> <span class="n">targetFunc</span> <span class="o">=</span> <span class="p">...;</span>
+
+<span class="k">class</span> <span class="nc">OurFunctionPass</span> <span class="o">:</span> <span class="k">public</span> <span class="n">FunctionPass</span> <span class="p">{</span>
+ <span class="nl">public:</span>
+ <span class="n">OurFunctionPass</span><span class="p">()</span><span class="o">:</span> <span class="n">callCounter</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span> <span class="p">{</span> <span class="p">}</span>
+
+ <span class="k">virtual</span> <span class="n">runOnFunction</span><span class="p">(</span><span class="n">Function</span><span class="o">&</span> <span class="n">F</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">for</span> <span class="p">(</span><span class="n">Function</span><span class="o">::</span><span class="n">iterator</span> <span class="n">b</span> <span class="o">=</span> <span class="n">F</span><span class="p">.</span><span class="n">begin</span><span class="p">(),</span> <span class="n">be</span> <span class="o">=</span> <span class="n">F</span><span class="p">.</span><span class="n">end</span><span class="p">();</span> <span class="n">b</span> <span class="o">!=</span> <span class="n">be</span><span class="p">;</span> <span class="o">++</span><span class="n">b</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">for</span> <span class="p">(</span><span class="n">BasicBlock</span><span class="o">::</span><span class="n">iterator</span> <span class="n">i</span> <span class="o">=</span> <span class="n">b</span><span class="o">-></span><span class="n">begin</span><span class="p">(),</span> <span class="n">ie</span> <span class="o">=</span> <span class="n">b</span><span class="o">-></span><span class="n">end</span><span class="p">();</span> <span class="n">i</span> <span class="o">!=</span> <span class="n">ie</span><span class="p">;</span> <span class="o">++</span><span class="n">i</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">CallInst</span><span class="o">*</span> <span class="n">callInst</span> <span class="o">=</span> <span class="n">dyn_cast</span><span class="o"><</span><span class="n">CallInst</span><span class="o">></span><span class="p">(</span><span class="o">&*</span><span class="n">i</span><span class="p">))</span> <span class="p">{</span>
+ <span class="c1">// We know we've encountered a call instruction, so we</span>
+ <span class="c1">// need to determine if it's a call to the</span>
+ <span class="c1">// function pointed to by m_func or not.</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">callInst</span><span class="o">-></span><span class="n">getCalledFunction</span><span class="p">()</span> <span class="o">==</span> <span class="n">targetFunc</span><span class="p">)</span>
+ <span class="o">++</span><span class="n">callCounter</span><span class="p">;</span>
+ <span class="p">}</span>
+ <span class="p">}</span>
+ <span class="p">}</span>
+ <span class="p">}</span>
+
+ <span class="nl">private:</span>
+ <span class="kt">unsigned</span> <span class="n">callCounter</span><span class="p">;</span>
+<span class="p">};</span>
+</pre></div>
+</div>
+</div>
+<div class="section" id="treating-calls-and-invokes-the-same-way">
+<span id="calls-and-invokes"></span><h4><a class="toc-backref" href="#id82">Treating calls and invokes the same way</a><a class="headerlink" href="#treating-calls-and-invokes-the-same-way" title="Permalink to this headline">¶</a></h4>
+<p>You may have noticed that the previous example was a bit oversimplified in that
+it did not deal with call sites generated by ‘invoke’ instructions. In this,
+and in other situations, you may find that you want to treat <tt class="docutils literal"><span class="pre">CallInst</span></tt>s and
+<tt class="docutils literal"><span class="pre">InvokeInst</span></tt>s the same way, even though their most-specific common base
+class is <tt class="docutils literal"><span class="pre">Instruction</span></tt>, which includes lots of less closely-related things.
+For these cases, LLVM provides a handy wrapper class called <tt class="docutils literal"><span class="pre">CallSite</span></tt>
+(<a class="reference external" href="http://llvm.org/doxygen/classllvm_1_1CallSite.html">doxygen</a>) It is
+essentially a wrapper around an <tt class="docutils literal"><span class="pre">Instruction</span></tt> pointer, with some methods that
+provide functionality common to <tt class="docutils literal"><span class="pre">CallInst</span></tt>s and <tt class="docutils literal"><span class="pre">InvokeInst</span></tt>s.</p>
+<p>This class has “value semantics”: it should be passed by value, not by reference
+and it should not be dynamically allocated or deallocated using <tt class="docutils literal"><span class="pre">operator</span> <span class="pre">new</span></tt>
+or <tt class="docutils literal"><span class="pre">operator</span> <span class="pre">delete</span></tt>. It is efficiently copyable, assignable and
+constructable, with costs equivalents to that of a bare pointer. If you look at
+its definition, it has only a single pointer member.</p>
+</div>
+<div class="section" id="iterating-over-def-use-use-def-chains">
+<span id="iterate-chains"></span><h4><a class="toc-backref" href="#id83">Iterating over def-use & use-def chains</a><a class="headerlink" href="#iterating-over-def-use-use-def-chains" title="Permalink to this headline">¶</a></h4>
+<p>Frequently, we might have an instance of the <tt class="docutils literal"><span class="pre">Value</span></tt> class (<a class="reference external" href="http://llvm.org/doxygen/classllvm_1_1Value.html">doxygen</a>) and we want to determine
+which <tt class="docutils literal"><span class="pre">User</span></tt> s use the <tt class="docutils literal"><span class="pre">Value</span></tt>. The list of all <tt class="docutils literal"><span class="pre">User</span></tt>s of a particular
+<tt class="docutils literal"><span class="pre">Value</span></tt> is called a <em>def-use</em> chain. For example, let’s say we have a
+<tt class="docutils literal"><span class="pre">Function*</span></tt> named <tt class="docutils literal"><span class="pre">F</span></tt> to a particular function <tt class="docutils literal"><span class="pre">foo</span></tt>. Finding all of the
+instructions that <em>use</em> <tt class="docutils literal"><span class="pre">foo</span></tt> is as simple as iterating over the <em>def-use</em>
+chain of <tt class="docutils literal"><span class="pre">F</span></tt>:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">Function</span> <span class="o">*</span><span class="n">F</span> <span class="o">=</span> <span class="p">...;</span>
+
+<span class="k">for</span> <span class="p">(</span><span class="n">User</span> <span class="o">*</span><span class="n">U</span> <span class="o">:</span> <span class="n">F</span><span class="o">-></span><span class="n">users</span><span class="p">())</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">Instruction</span> <span class="o">*</span><span class="n">Inst</span> <span class="o">=</span> <span class="n">dyn_cast</span><span class="o"><</span><span class="n">Instruction</span><span class="o">></span><span class="p">(</span><span class="n">U</span><span class="p">))</span> <span class="p">{</span>
+ <span class="n">errs</span><span class="p">()</span> <span class="o"><<</span> <span class="s">"F is used in instruction:</span><span class="se">\n</span><span class="s">"</span><span class="p">;</span>
+ <span class="n">errs</span><span class="p">()</span> <span class="o"><<</span> <span class="o">*</span><span class="n">Inst</span> <span class="o"><<</span> <span class="s">"</span><span class="se">\n</span><span class="s">"</span><span class="p">;</span>
+ <span class="p">}</span>
+</pre></div>
+</div>
+<p>Alternatively, it’s common to have an instance of the <tt class="docutils literal"><span class="pre">User</span></tt> Class (<a class="reference external" href="http://llvm.org/doxygen/classllvm_1_1User.html">doxygen</a>) and need to know what
+<tt class="docutils literal"><span class="pre">Value</span></tt>s are used by it. The list of all <tt class="docutils literal"><span class="pre">Value</span></tt>s used by a <tt class="docutils literal"><span class="pre">User</span></tt> is
+known as a <em>use-def</em> chain. Instances of class <tt class="docutils literal"><span class="pre">Instruction</span></tt> are common
+<tt class="docutils literal"><span class="pre">User</span></tt> s, so we might want to iterate over all of the values that a particular
+instruction uses (that is, the operands of the particular <tt class="docutils literal"><span class="pre">Instruction</span></tt>):</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">Instruction</span> <span class="o">*</span><span class="n">pi</span> <span class="o">=</span> <span class="p">...;</span>
+
+<span class="k">for</span> <span class="p">(</span><span class="n">Use</span> <span class="o">&</span><span class="n">U</span> <span class="o">:</span> <span class="n">pi</span><span class="o">-></span><span class="n">operands</span><span class="p">())</span> <span class="p">{</span>
+ <span class="n">Value</span> <span class="o">*</span><span class="n">v</span> <span class="o">=</span> <span class="n">U</span><span class="p">.</span><span class="n">get</span><span class="p">();</span>
+ <span class="c1">// ...</span>
+<span class="p">}</span>
+</pre></div>
+</div>
+<p>Declaring objects as <tt class="docutils literal"><span class="pre">const</span></tt> is an important tool of enforcing mutation free
+algorithms (such as analyses, etc.). For this purpose above iterators come in
+constant flavors as <tt class="docutils literal"><span class="pre">Value::const_use_iterator</span></tt> and
+<tt class="docutils literal"><span class="pre">Value::const_op_iterator</span></tt>. They automatically arise when calling
+<tt class="docutils literal"><span class="pre">use/op_begin()</span></tt> on <tt class="docutils literal"><span class="pre">const</span> <span class="pre">Value*</span></tt>s or <tt class="docutils literal"><span class="pre">const</span> <span class="pre">User*</span></tt>s respectively.
+Upon dereferencing, they return <tt class="docutils literal"><span class="pre">const</span> <span class="pre">Use*</span></tt>s. Otherwise the above patterns
+remain unchanged.</p>
+</div>
+<div class="section" id="iterating-over-predecessors-successors-of-blocks">
+<span id="iterate-preds"></span><h4><a class="toc-backref" href="#id84">Iterating over predecessors & successors of blocks</a><a class="headerlink" href="#iterating-over-predecessors-successors-of-blocks" title="Permalink to this headline">¶</a></h4>
+<p>Iterating over the predecessors and successors of a block is quite easy with the
+routines defined in <tt class="docutils literal"><span class="pre">"llvm/IR/CFG.h"</span></tt>. Just use code like this to
+iterate over all predecessors of BB:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="cp">#include "llvm/Support/CFG.h"</span>
+<span class="n">BasicBlock</span> <span class="o">*</span><span class="n">BB</span> <span class="o">=</span> <span class="p">...;</span>
+
+<span class="k">for</span> <span class="p">(</span><span class="n">pred_iterator</span> <span class="n">PI</span> <span class="o">=</span> <span class="n">pred_begin</span><span class="p">(</span><span class="n">BB</span><span class="p">),</span> <span class="n">E</span> <span class="o">=</span> <span class="n">pred_end</span><span class="p">(</span><span class="n">BB</span><span class="p">);</span> <span class="n">PI</span> <span class="o">!=</span> <span class="n">E</span><span class="p">;</span> <span class="o">++</span><span class="n">PI</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">BasicBlock</span> <span class="o">*</span><span class="n">Pred</span> <span class="o">=</span> <span class="o">*</span><span class="n">PI</span><span class="p">;</span>
+ <span class="c1">// ...</span>
+<span class="p">}</span>
+</pre></div>
+</div>
+<p>Similarly, to iterate over successors use <tt class="docutils literal"><span class="pre">succ_iterator/succ_begin/succ_end</span></tt>.</p>
+</div>
+</div>
+<div class="section" id="making-simple-changes">
+<span id="simplechanges"></span><h3><a class="toc-backref" href="#id85">Making simple changes</a><a class="headerlink" href="#making-simple-changes" title="Permalink to this headline">¶</a></h3>
+<p>There are some primitive transformation operations present in the LLVM
+infrastructure that are worth knowing about. When performing transformations,
+it’s fairly common to manipulate the contents of basic blocks. This section
+describes some of the common methods for doing so and gives example code.</p>
+<div class="section" id="creating-and-inserting-new-instructions">
+<span id="schanges-creating"></span><h4><a class="toc-backref" href="#id86">Creating and inserting new <tt class="docutils literal"><span class="pre">Instruction</span></tt>s</a><a class="headerlink" href="#creating-and-inserting-new-instructions" title="Permalink to this headline">¶</a></h4>
+<p><em>Instantiating Instructions</em></p>
+<p>Creation of <tt class="docutils literal"><span class="pre">Instruction</span></tt>s is straight-forward: simply call the constructor
+for the kind of instruction to instantiate and provide the necessary parameters.
+For example, an <tt class="docutils literal"><span class="pre">AllocaInst</span></tt> only <em>requires</em> a (const-ptr-to) <tt class="docutils literal"><span class="pre">Type</span></tt>. Thus:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">AllocaInst</span><span class="o">*</span> <span class="n">ai</span> <span class="o">=</span> <span class="k">new</span> <span class="n">AllocaInst</span><span class="p">(</span><span class="n">Type</span><span class="o">::</span><span class="n">Int32Ty</span><span class="p">);</span>
+</pre></div>
+</div>
+<p>will create an <tt class="docutils literal"><span class="pre">AllocaInst</span></tt> instance that represents the allocation of one
+integer in the current stack frame, at run time. Each <tt class="docutils literal"><span class="pre">Instruction</span></tt> subclass
+is likely to have varying default parameters which change the semantics of the
+instruction, so refer to the <a class="reference external" href="http://llvm.org/doxygen/classllvm_1_1Instruction.html">doxygen documentation for the subclass of
+Instruction</a> that
+you’re interested in instantiating.</p>
+<p><em>Naming values</em></p>
+<p>It is very useful to name the values of instructions when you’re able to, as
+this facilitates the debugging of your transformations. If you end up looking
+at generated LLVM machine code, you definitely want to have logical names
+associated with the results of instructions! By supplying a value for the
+<tt class="docutils literal"><span class="pre">Name</span></tt> (default) parameter of the <tt class="docutils literal"><span class="pre">Instruction</span></tt> constructor, you associate a
+logical name with the result of the instruction’s execution at run time. For
+example, say that I’m writing a transformation that dynamically allocates space
+for an integer on the stack, and that integer is going to be used as some kind
+of index by some other code. To accomplish this, I place an <tt class="docutils literal"><span class="pre">AllocaInst</span></tt> at
+the first point in the first <tt class="docutils literal"><span class="pre">BasicBlock</span></tt> of some <tt class="docutils literal"><span class="pre">Function</span></tt>, and I’m
+intending to use it within the same <tt class="docutils literal"><span class="pre">Function</span></tt>. I might do:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">AllocaInst</span><span class="o">*</span> <span class="n">pa</span> <span class="o">=</span> <span class="k">new</span> <span class="n">AllocaInst</span><span class="p">(</span><span class="n">Type</span><span class="o">::</span><span class="n">Int32Ty</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="s">"indexLoc"</span><span class="p">);</span>
+</pre></div>
+</div>
+<p>where <tt class="docutils literal"><span class="pre">indexLoc</span></tt> is now the logical name of the instruction’s execution value,
+which is a pointer to an integer on the run time stack.</p>
+<p><em>Inserting instructions</em></p>
+<p>There are essentially three ways to insert an <tt class="docutils literal"><span class="pre">Instruction</span></tt> into an existing
+sequence of instructions that form a <tt class="docutils literal"><span class="pre">BasicBlock</span></tt>:</p>
+<ul>
+<li><p class="first">Insertion into an explicit instruction list</p>
+<p>Given a <tt class="docutils literal"><span class="pre">BasicBlock*</span> <span class="pre">pb</span></tt>, an <tt class="docutils literal"><span class="pre">Instruction*</span> <span class="pre">pi</span></tt> within that <tt class="docutils literal"><span class="pre">BasicBlock</span></tt>,
+and a newly-created instruction we wish to insert before <tt class="docutils literal"><span class="pre">*pi</span></tt>, we do the
+following:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">BasicBlock</span> <span class="o">*</span><span class="n">pb</span> <span class="o">=</span> <span class="p">...;</span>
+<span class="n">Instruction</span> <span class="o">*</span><span class="n">pi</span> <span class="o">=</span> <span class="p">...;</span>
+<span class="n">Instruction</span> <span class="o">*</span><span class="n">newInst</span> <span class="o">=</span> <span class="k">new</span> <span class="n">Instruction</span><span class="p">(...);</span>
+
+<span class="n">pb</span><span class="o">-></span><span class="n">getInstList</span><span class="p">().</span><span class="n">insert</span><span class="p">(</span><span class="n">pi</span><span class="p">,</span> <span class="n">newInst</span><span class="p">);</span> <span class="c1">// Inserts newInst before pi in pb</span>
+</pre></div>
+</div>
+<p>Appending to the end of a <tt class="docutils literal"><span class="pre">BasicBlock</span></tt> is so common that the <tt class="docutils literal"><span class="pre">Instruction</span></tt>
+class and <tt class="docutils literal"><span class="pre">Instruction</span></tt>-derived classes provide constructors which take a
+pointer to a <tt class="docutils literal"><span class="pre">BasicBlock</span></tt> to be appended to. For example code that looked
+like:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">BasicBlock</span> <span class="o">*</span><span class="n">pb</span> <span class="o">=</span> <span class="p">...;</span>
+<span class="n">Instruction</span> <span class="o">*</span><span class="n">newInst</span> <span class="o">=</span> <span class="k">new</span> <span class="n">Instruction</span><span class="p">(...);</span>
+
+<span class="n">pb</span><span class="o">-></span><span class="n">getInstList</span><span class="p">().</span><span class="n">push_back</span><span class="p">(</span><span class="n">newInst</span><span class="p">);</span> <span class="c1">// Appends newInst to pb</span>
+</pre></div>
+</div>
+<p>becomes:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">BasicBlock</span> <span class="o">*</span><span class="n">pb</span> <span class="o">=</span> <span class="p">...;</span>
+<span class="n">Instruction</span> <span class="o">*</span><span class="n">newInst</span> <span class="o">=</span> <span class="k">new</span> <span class="n">Instruction</span><span class="p">(...,</span> <span class="n">pb</span><span class="p">);</span>
+</pre></div>
+</div>
+<p>which is much cleaner, especially if you are creating long instruction
+streams.</p>
+</li>
+<li><p class="first">Insertion into an implicit instruction list</p>
+<p><tt class="docutils literal"><span class="pre">Instruction</span></tt> instances that are already in <tt class="docutils literal"><span class="pre">BasicBlock</span></tt>s are implicitly
+associated with an existing instruction list: the instruction list of the
+enclosing basic block. Thus, we could have accomplished the same thing as the
+above code without being given a <tt class="docutils literal"><span class="pre">BasicBlock</span></tt> by doing:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">Instruction</span> <span class="o">*</span><span class="n">pi</span> <span class="o">=</span> <span class="p">...;</span>
+<span class="n">Instruction</span> <span class="o">*</span><span class="n">newInst</span> <span class="o">=</span> <span class="k">new</span> <span class="n">Instruction</span><span class="p">(...);</span>
+
+<span class="n">pi</span><span class="o">-></span><span class="n">getParent</span><span class="p">()</span><span class="o">-></span><span class="n">getInstList</span><span class="p">().</span><span class="n">insert</span><span class="p">(</span><span class="n">pi</span><span class="p">,</span> <span class="n">newInst</span><span class="p">);</span>
+</pre></div>
+</div>
+<p>In fact, this sequence of steps occurs so frequently that the <tt class="docutils literal"><span class="pre">Instruction</span></tt>
+class and <tt class="docutils literal"><span class="pre">Instruction</span></tt>-derived classes provide constructors which take (as
+a default parameter) a pointer to an <tt class="docutils literal"><span class="pre">Instruction</span></tt> which the newly-created
+<tt class="docutils literal"><span class="pre">Instruction</span></tt> should precede. That is, <tt class="docutils literal"><span class="pre">Instruction</span></tt> constructors are
+capable of inserting the newly-created instance into the <tt class="docutils literal"><span class="pre">BasicBlock</span></tt> of a
+provided instruction, immediately before that instruction. Using an
+<tt class="docutils literal"><span class="pre">Instruction</span></tt> constructor with a <tt class="docutils literal"><span class="pre">insertBefore</span></tt> (default) parameter, the
+above code becomes:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">Instruction</span><span class="o">*</span> <span class="n">pi</span> <span class="o">=</span> <span class="p">...;</span>
+<span class="n">Instruction</span><span class="o">*</span> <span class="n">newInst</span> <span class="o">=</span> <span class="k">new</span> <span class="n">Instruction</span><span class="p">(...,</span> <span class="n">pi</span><span class="p">);</span>
+</pre></div>
+</div>
+<p>which is much cleaner, especially if you’re creating a lot of instructions and
+adding them to <tt class="docutils literal"><span class="pre">BasicBlock</span></tt>s.</p>
+</li>
+<li><p class="first">Insertion using an instance of <tt class="docutils literal"><span class="pre">IRBuilder</span></tt></p>
+<p>Inserting several <tt class="docutils literal"><span class="pre">Instruction</span></tt>s can be quite laborious using the previous
+methods. The <tt class="docutils literal"><span class="pre">IRBuilder</span></tt> is a convenience class that can be used to add
+several instructions to the end of a <tt class="docutils literal"><span class="pre">BasicBlock</span></tt> or before a particular
+<tt class="docutils literal"><span class="pre">Instruction</span></tt>. It also supports constant folding and renaming named
+registers (see <tt class="docutils literal"><span class="pre">IRBuilder</span></tt>‘s template arguments).</p>
+<p>The example below demonstrates a very simple use of the <tt class="docutils literal"><span class="pre">IRBuilder</span></tt> where
+three instructions are inserted before the instruction <tt class="docutils literal"><span class="pre">pi</span></tt>. The first two
+instructions are Call instructions and third instruction multiplies the return
+value of the two calls.</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">Instruction</span> <span class="o">*</span><span class="n">pi</span> <span class="o">=</span> <span class="p">...;</span>
+<span class="n">IRBuilder</span><span class="o"><></span> <span class="n">Builder</span><span class="p">(</span><span class="n">pi</span><span class="p">);</span>
+<span class="n">CallInst</span><span class="o">*</span> <span class="n">callOne</span> <span class="o">=</span> <span class="n">Builder</span><span class="p">.</span><span class="n">CreateCall</span><span class="p">(...);</span>
+<span class="n">CallInst</span><span class="o">*</span> <span class="n">callTwo</span> <span class="o">=</span> <span class="n">Builder</span><span class="p">.</span><span class="n">CreateCall</span><span class="p">(...);</span>
+<span class="n">Value</span><span class="o">*</span> <span class="n">result</span> <span class="o">=</span> <span class="n">Builder</span><span class="p">.</span><span class="n">CreateMul</span><span class="p">(</span><span class="n">callOne</span><span class="p">,</span> <span class="n">callTwo</span><span class="p">);</span>
+</pre></div>
+</div>
+<p>The example below is similar to the above example except that the created
+<tt class="docutils literal"><span class="pre">IRBuilder</span></tt> inserts instructions at the end of the <tt class="docutils literal"><span class="pre">BasicBlock</span></tt> <tt class="docutils literal"><span class="pre">pb</span></tt>.</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">BasicBlock</span> <span class="o">*</span><span class="n">pb</span> <span class="o">=</span> <span class="p">...;</span>
+<span class="n">IRBuilder</span><span class="o"><></span> <span class="n">Builder</span><span class="p">(</span><span class="n">pb</span><span class="p">);</span>
+<span class="n">CallInst</span><span class="o">*</span> <span class="n">callOne</span> <span class="o">=</span> <span class="n">Builder</span><span class="p">.</span><span class="n">CreateCall</span><span class="p">(...);</span>
+<span class="n">CallInst</span><span class="o">*</span> <span class="n">callTwo</span> <span class="o">=</span> <span class="n">Builder</span><span class="p">.</span><span class="n">CreateCall</span><span class="p">(...);</span>
+<span class="n">Value</span><span class="o">*</span> <span class="n">result</span> <span class="o">=</span> <span class="n">Builder</span><span class="p">.</span><span class="n">CreateMul</span><span class="p">(</span><span class="n">callOne</span><span class="p">,</span> <span class="n">callTwo</span><span class="p">);</span>
+</pre></div>
+</div>
+<p>See <a class="reference internal" href="tutorial/LangImpl3.html"><em>Kaleidoscope: Code generation to LLVM IR</em></a> for a practical use of the <tt class="docutils literal"><span class="pre">IRBuilder</span></tt>.</p>
+</li>
+</ul>
+</div>
+<div class="section" id="deleting-instructions">
+<span id="schanges-deleting"></span><h4><a class="toc-backref" href="#id87">Deleting Instructions</a><a class="headerlink" href="#deleting-instructions" title="Permalink to this headline">¶</a></h4>
+<p>Deleting an instruction from an existing sequence of instructions that form a
+<a class="reference internal" href="#basicblock">BasicBlock</a> is very straight-forward: just call the instruction’s
+<tt class="docutils literal"><span class="pre">eraseFromParent()</span></tt> method. For example:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">Instruction</span> <span class="o">*</span><span class="n">I</span> <span class="o">=</span> <span class="p">..</span> <span class="p">;</span>
+<span class="n">I</span><span class="o">-></span><span class="n">eraseFromParent</span><span class="p">();</span>
+</pre></div>
+</div>
+<p>This unlinks the instruction from its containing basic block and deletes it. If
+you’d just like to unlink the instruction from its containing basic block but
+not delete it, you can use the <tt class="docutils literal"><span class="pre">removeFromParent()</span></tt> method.</p>
+</div>
+<div class="section" id="replacing-an-instruction-with-another-value">
+<span id="schanges-replacing"></span><h4><a class="toc-backref" href="#id88">Replacing an Instruction with another Value</a><a class="headerlink" href="#replacing-an-instruction-with-another-value" title="Permalink to this headline">¶</a></h4>
+<div class="section" id="replacing-individual-instructions">
+<h5><a class="toc-backref" href="#id89">Replacing individual instructions</a><a class="headerlink" href="#replacing-individual-instructions" title="Permalink to this headline">¶</a></h5>
+<p>Including “<a class="reference external" href="http://llvm.org/doxygen/BasicBlockUtils_8h-source.html">llvm/Transforms/Utils/BasicBlockUtils.h</a>” permits use of two
+very useful replace functions: <tt class="docutils literal"><span class="pre">ReplaceInstWithValue</span></tt> and
+<tt class="docutils literal"><span class="pre">ReplaceInstWithInst</span></tt>.</p>
+</div>
+<div class="section" id="schanges-deleting-sub">
+<span id="id3"></span><h5><a class="toc-backref" href="#id90">Deleting Instructions</a><a class="headerlink" href="#schanges-deleting-sub" title="Permalink to this headline">¶</a></h5>
+<ul>
+<li><p class="first"><tt class="docutils literal"><span class="pre">ReplaceInstWithValue</span></tt></p>
+<p>This function replaces all uses of a given instruction with a value, and then
+removes the original instruction. The following example illustrates the
+replacement of the result of a particular <tt class="docutils literal"><span class="pre">AllocaInst</span></tt> that allocates memory
+for a single integer with a null pointer to an integer.</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">AllocaInst</span><span class="o">*</span> <span class="n">instToReplace</span> <span class="o">=</span> <span class="p">...;</span>
+<span class="n">BasicBlock</span><span class="o">::</span><span class="n">iterator</span> <span class="n">ii</span><span class="p">(</span><span class="n">instToReplace</span><span class="p">);</span>
+
+<span class="n">ReplaceInstWithValue</span><span class="p">(</span><span class="n">instToReplace</span><span class="o">-></span><span class="n">getParent</span><span class="p">()</span><span class="o">-></span><span class="n">getInstList</span><span class="p">(),</span> <span class="n">ii</span><span class="p">,</span>
+ <span class="n">Constant</span><span class="o">::</span><span class="n">getNullValue</span><span class="p">(</span><span class="n">PointerType</span><span class="o">::</span><span class="n">getUnqual</span><span class="p">(</span><span class="n">Type</span><span class="o">::</span><span class="n">Int32Ty</span><span class="p">)));</span>
+</pre></div>
+</div>
+</li>
+<li><p class="first"><tt class="docutils literal"><span class="pre">ReplaceInstWithInst</span></tt></p>
+<p>This function replaces a particular instruction with another instruction,
+inserting the new instruction into the basic block at the location where the
+old instruction was, and replacing any uses of the old instruction with the
+new instruction. The following example illustrates the replacement of one
+<tt class="docutils literal"><span class="pre">AllocaInst</span></tt> with another.</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">AllocaInst</span><span class="o">*</span> <span class="n">instToReplace</span> <span class="o">=</span> <span class="p">...;</span>
+<span class="n">BasicBlock</span><span class="o">::</span><span class="n">iterator</span> <span class="n">ii</span><span class="p">(</span><span class="n">instToReplace</span><span class="p">);</span>
+
+<span class="n">ReplaceInstWithInst</span><span class="p">(</span><span class="n">instToReplace</span><span class="o">-></span><span class="n">getParent</span><span class="p">()</span><span class="o">-></span><span class="n">getInstList</span><span class="p">(),</span> <span class="n">ii</span><span class="p">,</span>
+ <span class="k">new</span> <span class="n">AllocaInst</span><span class="p">(</span><span class="n">Type</span><span class="o">::</span><span class="n">Int32Ty</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="s">"ptrToReplacedInt"</span><span class="p">));</span>
+</pre></div>
+</div>
+</li>
+</ul>
+</div>
+<div class="section" id="replacing-multiple-uses-of-users-and-values">
+<h5><a class="toc-backref" href="#id91">Replacing multiple uses of Users and Values</a><a class="headerlink" href="#replacing-multiple-uses-of-users-and-values" title="Permalink to this headline">¶</a></h5>
+<p>You can use <tt class="docutils literal"><span class="pre">Value::replaceAllUsesWith</span></tt> and <tt class="docutils literal"><span class="pre">User::replaceUsesOfWith</span></tt> to
+change more than one use at a time. See the doxygen documentation for the
+<a class="reference external" href="http://llvm.org/doxygen/classllvm_1_1Value.html">Value Class</a> and <a class="reference external" href="http://llvm.org/doxygen/classllvm_1_1User.html">User Class</a>, respectively, for more
+information.</p>
+</div>
+</div>
+<div class="section" id="deleting-globalvariables">
+<span id="schanges-deletinggv"></span><h4><a class="toc-backref" href="#id92">Deleting GlobalVariables</a><a class="headerlink" href="#deleting-globalvariables" title="Permalink to this headline">¶</a></h4>
+<p>Deleting a global variable from a module is just as easy as deleting an
+Instruction. First, you must have a pointer to the global variable that you
+wish to delete. You use this pointer to erase it from its parent, the module.
+For example:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">GlobalVariable</span> <span class="o">*</span><span class="n">GV</span> <span class="o">=</span> <span class="p">..</span> <span class="p">;</span>
+
+<span class="n">GV</span><span class="o">-></span><span class="n">eraseFromParent</span><span class="p">();</span>
+</pre></div>
+</div>
+</div>
+</div>
+<div class="section" id="how-to-create-types">
+<span id="create-types"></span><h3><a class="toc-backref" href="#id93">How to Create Types</a><a class="headerlink" href="#how-to-create-types" title="Permalink to this headline">¶</a></h3>
+<p>In generating IR, you may need some complex types. If you know these types
+statically, you can use <tt class="docutils literal"><span class="pre">TypeBuilder<...>::get()</span></tt>, defined in
+<tt class="docutils literal"><span class="pre">llvm/Support/TypeBuilder.h</span></tt>, to retrieve them. <tt class="docutils literal"><span class="pre">TypeBuilder</span></tt> has two forms
+depending on whether you’re building types for cross-compilation or native
+library use. <tt class="docutils literal"><span class="pre">TypeBuilder<T,</span> <span class="pre">true></span></tt> requires that <tt class="docutils literal"><span class="pre">T</span></tt> be independent of the
+host environment, meaning that it’s built out of types from the <tt class="docutils literal"><span class="pre">llvm::types</span></tt>
+(<a class="reference external" href="http://llvm.org/doxygen/namespacellvm_1_1types.html">doxygen</a>) namespace
+and pointers, functions, arrays, etc. built of those. <tt class="docutils literal"><span class="pre">TypeBuilder<T,</span> <span class="pre">false></span></tt>
+additionally allows native C types whose size may depend on the host compiler.
+For example,</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">FunctionType</span> <span class="o">*</span><span class="n">ft</span> <span class="o">=</span> <span class="n">TypeBuilder</span><span class="o"><</span><span class="n">types</span><span class="o">::</span><span class="n">i</span><span class="o"><</span><span class="mi">8</span><span class="o">></span><span class="p">(</span><span class="n">types</span><span class="o">::</span><span class="n">i</span><span class="o"><</span><span class="mi">32</span><span class="o">>*</span><span class="p">),</span> <span class="nb">true</span><span class="o">>::</span><span class="n">get</span><span class="p">();</span>
+</pre></div>
+</div>
+<p>is easier to read and write than the equivalent</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">std</span><span class="o">::</span><span class="n">vector</span><span class="o"><</span><span class="k">const</span> <span class="n">Type</span><span class="o">*></span> <span class="n">params</span><span class="p">;</span>
+<span class="n">params</span><span class="p">.</span><span class="n">push_back</span><span class="p">(</span><span class="n">PointerType</span><span class="o">::</span><span class="n">getUnqual</span><span class="p">(</span><span class="n">Type</span><span class="o">::</span><span class="n">Int32Ty</span><span class="p">));</span>
+<span class="n">FunctionType</span> <span class="o">*</span><span class="n">ft</span> <span class="o">=</span> <span class="n">FunctionType</span><span class="o">::</span><span class="n">get</span><span class="p">(</span><span class="n">Type</span><span class="o">::</span><span class="n">Int8Ty</span><span class="p">,</span> <span class="n">params</span><span class="p">,</span> <span class="nb">false</span><span class="p">);</span>
+</pre></div>
+</div>
+<p>See the <a class="reference external" href="http://llvm.org/doxygen/TypeBuilder_8h-source.html#l00001">class comment</a> for more details.</p>
+</div>
+</div>
+<div class="section" id="threads-and-llvm">
+<span id="threading"></span><h2><a class="toc-backref" href="#id94">Threads and LLVM</a><a class="headerlink" href="#threads-and-llvm" title="Permalink to this headline">¶</a></h2>
+<p>This section describes the interaction of the LLVM APIs with multithreading,
+both on the part of client applications, and in the JIT, in the hosted
+application.</p>
+<p>Note that LLVM’s support for multithreading is still relatively young. Up
+through version 2.5, the execution of threaded hosted applications was
+supported, but not threaded client access to the APIs. While this use case is
+now supported, clients <em>must</em> adhere to the guidelines specified below to ensure
+proper operation in multithreaded mode.</p>
+<p>Note that, on Unix-like platforms, LLVM requires the presence of GCC’s atomic
+intrinsics in order to support threaded operation. If you need a
+multhreading-capable LLVM on a platform without a suitably modern system
+compiler, consider compiling LLVM and LLVM-GCC in single-threaded mode, and
+using the resultant compiler to build a copy of LLVM with multithreading
+support.</p>
+<div class="section" id="ending-execution-with-llvm-shutdown">
+<span id="shutdown"></span><h3><a class="toc-backref" href="#id95">Ending Execution with <tt class="docutils literal"><span class="pre">llvm_shutdown()</span></tt></a><a class="headerlink" href="#ending-execution-with-llvm-shutdown" title="Permalink to this headline">¶</a></h3>
+<p>When you are done using the LLVM APIs, you should call <tt class="docutils literal"><span class="pre">llvm_shutdown()</span></tt> to
+deallocate memory used for internal structures.</p>
+</div>
+<div class="section" id="lazy-initialization-with-managedstatic">
+<span id="managedstatic"></span><h3><a class="toc-backref" href="#id96">Lazy Initialization with <tt class="docutils literal"><span class="pre">ManagedStatic</span></tt></a><a class="headerlink" href="#lazy-initialization-with-managedstatic" title="Permalink to this headline">¶</a></h3>
+<p><tt class="docutils literal"><span class="pre">ManagedStatic</span></tt> is a utility class in LLVM used to implement static
+initialization of static resources, such as the global type tables. In a
+single-threaded environment, it implements a simple lazy initialization scheme.
+When LLVM is compiled with support for multi-threading, however, it uses
+double-checked locking to implement thread-safe lazy initialization.</p>
+</div>
+<div class="section" id="achieving-isolation-with-llvmcontext">
+<span id="llvmcontext"></span><h3><a class="toc-backref" href="#id97">Achieving Isolation with <tt class="docutils literal"><span class="pre">LLVMContext</span></tt></a><a class="headerlink" href="#achieving-isolation-with-llvmcontext" title="Permalink to this headline">¶</a></h3>
+<p><tt class="docutils literal"><span class="pre">LLVMContext</span></tt> is an opaque class in the LLVM API which clients can use to
+operate multiple, isolated instances of LLVM concurrently within the same
+address space. For instance, in a hypothetical compile-server, the compilation
+of an individual translation unit is conceptually independent from all the
+others, and it would be desirable to be able to compile incoming translation
+units concurrently on independent server threads. Fortunately, <tt class="docutils literal"><span class="pre">LLVMContext</span></tt>
+exists to enable just this kind of scenario!</p>
+<p>Conceptually, <tt class="docutils literal"><span class="pre">LLVMContext</span></tt> provides isolation. Every LLVM entity
+(<tt class="docutils literal"><span class="pre">Module</span></tt>s, <tt class="docutils literal"><span class="pre">Value</span></tt>s, <tt class="docutils literal"><span class="pre">Type</span></tt>s, <tt class="docutils literal"><span class="pre">Constant</span></tt>s, etc.) in LLVM’s
+in-memory IR belongs to an <tt class="docutils literal"><span class="pre">LLVMContext</span></tt>. Entities in different contexts
+<em>cannot</em> interact with each other: <tt class="docutils literal"><span class="pre">Module</span></tt>s in different contexts cannot be
+linked together, <tt class="docutils literal"><span class="pre">Function</span></tt>s cannot be added to <tt class="docutils literal"><span class="pre">Module</span></tt>s in different
+contexts, etc. What this means is that is is safe to compile on multiple
+threads simultaneously, as long as no two threads operate on entities within the
+same context.</p>
+<p>In practice, very few places in the API require the explicit specification of a
+<tt class="docutils literal"><span class="pre">LLVMContext</span></tt>, other than the <tt class="docutils literal"><span class="pre">Type</span></tt> creation/lookup APIs. Because every
+<tt class="docutils literal"><span class="pre">Type</span></tt> carries a reference to its owning context, most other entities can
+determine what context they belong to by looking at their own <tt class="docutils literal"><span class="pre">Type</span></tt>. If you
+are adding new entities to LLVM IR, please try to maintain this interface
+design.</p>
+<p>For clients that do <em>not</em> require the benefits of isolation, LLVM provides a
+convenience API <tt class="docutils literal"><span class="pre">getGlobalContext()</span></tt>. This returns a global, lazily
+initialized <tt class="docutils literal"><span class="pre">LLVMContext</span></tt> that may be used in situations where isolation is
+not a concern.</p>
+</div>
+<div class="section" id="threads-and-the-jit">
+<span id="jitthreading"></span><h3><a class="toc-backref" href="#id98">Threads and the JIT</a><a class="headerlink" href="#threads-and-the-jit" title="Permalink to this headline">¶</a></h3>
+<p>LLVM’s “eager” JIT compiler is safe to use in threaded programs. Multiple
+threads can call <tt class="docutils literal"><span class="pre">ExecutionEngine::getPointerToFunction()</span></tt> or
+<tt class="docutils literal"><span class="pre">ExecutionEngine::runFunction()</span></tt> concurrently, and multiple threads can run
+code output by the JIT concurrently. The user must still ensure that only one
+thread accesses IR in a given <tt class="docutils literal"><span class="pre">LLVMContext</span></tt> while another thread might be
+modifying it. One way to do that is to always hold the JIT lock while accessing
+IR outside the JIT (the JIT <em>modifies</em> the IR by adding <tt class="docutils literal"><span class="pre">CallbackVH</span></tt>s).
+Another way is to only call <tt class="docutils literal"><span class="pre">getPointerToFunction()</span></tt> from the
+<tt class="docutils literal"><span class="pre">LLVMContext</span></tt>‘s thread.</p>
+<p>When the JIT is configured to compile lazily (using
+<tt class="docutils literal"><span class="pre">ExecutionEngine::DisableLazyCompilation(false)</span></tt>), there is currently a <a class="reference external" href="http://llvm.org/bugs/show_bug.cgi?id=5184">race
+condition</a> in updating call sites
+after a function is lazily-jitted. It’s still possible to use the lazy JIT in a
+threaded program if you ensure that only one thread at a time can call any
+particular lazy stub and that the JIT lock guards any IR access, but we suggest
+using only the eager JIT in threaded programs.</p>
+</div>
+</div>
+<div class="section" id="advanced-topics">
+<span id="advanced"></span><h2><a class="toc-backref" href="#id99">Advanced Topics</a><a class="headerlink" href="#advanced-topics" title="Permalink to this headline">¶</a></h2>
+<p>This section describes some of the advanced or obscure API’s that most clients
+do not need to be aware of. These API’s tend manage the inner workings of the
+LLVM system, and only need to be accessed in unusual circumstances.</p>
+<div class="section" id="the-valuesymboltable-class">
+<span id="symboltable"></span><h3><a class="toc-backref" href="#id100">The <tt class="docutils literal"><span class="pre">ValueSymbolTable</span></tt> class</a><a class="headerlink" href="#the-valuesymboltable-class" title="Permalink to this headline">¶</a></h3>
+<p>The <tt class="docutils literal"><span class="pre">ValueSymbolTable</span></tt> (<a class="reference external" href="http://llvm.org/doxygen/classllvm_1_1ValueSymbolTable.html">doxygen</a>) class provides
+a symbol table that the <a class="reference internal" href="#c-function"><em>Function</em></a> and <a class="reference internal" href="#module">Module</a> classes use for
+naming value definitions. The symbol table can provide a name for any <a class="reference internal" href="#value">Value</a>.</p>
+<p>Note that the <tt class="docutils literal"><span class="pre">SymbolTable</span></tt> class should not be directly accessed by most
+clients. It should only be used when iteration over the symbol table names
+themselves are required, which is very special purpose. Note that not all LLVM
+<a class="reference internal" href="#value">Value</a>s have names, and those without names (i.e. they have an empty name) do
+not exist in the symbol table.</p>
+<p>Symbol tables support iteration over the values in the symbol table with
+<tt class="docutils literal"><span class="pre">begin/end/iterator</span></tt> and supports querying to see if a specific name is in the
+symbol table (with <tt class="docutils literal"><span class="pre">lookup</span></tt>). The <tt class="docutils literal"><span class="pre">ValueSymbolTable</span></tt> class exposes no
+public mutator methods, instead, simply call <tt class="docutils literal"><span class="pre">setName</span></tt> on a value, which will
+autoinsert it into the appropriate symbol table.</p>
+</div>
+<div class="section" id="the-user-and-owned-use-classes-memory-layout">
+<span id="userlayout"></span><h3><a class="toc-backref" href="#id101">The <tt class="docutils literal"><span class="pre">User</span></tt> and owned <tt class="docutils literal"><span class="pre">Use</span></tt> classes’ memory layout</a><a class="headerlink" href="#the-user-and-owned-use-classes-memory-layout" title="Permalink to this headline">¶</a></h3>
+<p>The <tt class="docutils literal"><span class="pre">User</span></tt> (<a class="reference external" href="http://llvm.org/doxygen/classllvm_1_1User.html">doxygen</a>)
+class provides a basis for expressing the ownership of <tt class="docutils literal"><span class="pre">User</span></tt> towards other
+<a class="reference external" href="http://llvm.org/doxygen/classllvm_1_1Value.html">Value instance</a>s. The
+<tt class="docutils literal"><span class="pre">Use</span></tt> (<a class="reference external" href="http://llvm.org/doxygen/classllvm_1_1Use.html">doxygen</a>) helper
+class is employed to do the bookkeeping and to facilitate <em>O(1)</em> addition and
+removal.</p>
+<div class="section" id="interaction-and-relationship-between-user-and-use-objects">
+<span id="use2user"></span><h4><a class="toc-backref" href="#id102">Interaction and relationship between <tt class="docutils literal"><span class="pre">User</span></tt> and <tt class="docutils literal"><span class="pre">Use</span></tt> objects</a><a class="headerlink" href="#interaction-and-relationship-between-user-and-use-objects" title="Permalink to this headline">¶</a></h4>
+<p>A subclass of <tt class="docutils literal"><span class="pre">User</span></tt> can choose between incorporating its <tt class="docutils literal"><span class="pre">Use</span></tt> objects or
+refer to them out-of-line by means of a pointer. A mixed variant (some <tt class="docutils literal"><span class="pre">Use</span></tt>
+s inline others hung off) is impractical and breaks the invariant that the
+<tt class="docutils literal"><span class="pre">Use</span></tt> objects belonging to the same <tt class="docutils literal"><span class="pre">User</span></tt> form a contiguous array.</p>
+<p>We have 2 different layouts in the <tt class="docutils literal"><span class="pre">User</span></tt> (sub)classes:</p>
+<ul>
+<li><p class="first">Layout a)</p>
+<p>The <tt class="docutils literal"><span class="pre">Use</span></tt> object(s) are inside (resp. at fixed offset) of the <tt class="docutils literal"><span class="pre">User</span></tt>
+object and there are a fixed number of them.</p>
+</li>
+<li><p class="first">Layout b)</p>
+<p>The <tt class="docutils literal"><span class="pre">Use</span></tt> object(s) are referenced by a pointer to an array from the
+<tt class="docutils literal"><span class="pre">User</span></tt> object and there may be a variable number of them.</p>
+</li>
+</ul>
+<p>As of v2.4 each layout still possesses a direct pointer to the start of the
+array of <tt class="docutils literal"><span class="pre">Use</span></tt>s. Though not mandatory for layout a), we stick to this
+redundancy for the sake of simplicity. The <tt class="docutils literal"><span class="pre">User</span></tt> object also stores the
+number of <tt class="docutils literal"><span class="pre">Use</span></tt> objects it has. (Theoretically this information can also be
+calculated given the scheme presented below.)</p>
+<p>Special forms of allocation operators (<tt class="docutils literal"><span class="pre">operator</span> <span class="pre">new</span></tt>) enforce the following
+memory layouts:</p>
+<ul>
+<li><p class="first">Layout a) is modelled by prepending the <tt class="docutils literal"><span class="pre">User</span></tt> object by the <tt class="docutils literal"><span class="pre">Use[]</span></tt>
+array.</p>
+<div class="highlight-none"><div class="highlight"><pre>...---.---.---.---.-------...
+ | P | P | P | P | User
+'''---'---'---'---'-------'''
+</pre></div>
+</div>
+</li>
+<li><p class="first">Layout b) is modelled by pointing at the <tt class="docutils literal"><span class="pre">Use[]</span></tt> array.</p>
+<div class="highlight-none"><div class="highlight"><pre>.-------...
+| User
+'-------'''
+ |
+ v
+ .---.---.---.---...
+ | P | P | P | P |
+ '---'---'---'---'''
+</pre></div>
+</div>
+</li>
+</ul>
+<p><em>(In the above figures</em> ‘<tt class="docutils literal"><span class="pre">P</span></tt>‘ <em>stands for the</em> <tt class="docutils literal"><span class="pre">Use**</span></tt> <em>that is stored in
+each</em> <tt class="docutils literal"><span class="pre">Use</span></tt> <em>object in the member</em> <tt class="docutils literal"><span class="pre">Use::Prev</span></tt> <em>)</em></p>
+</div>
+<div class="section" id="the-waymarking-algorithm">
+<span id="waymarking"></span><h4><a class="toc-backref" href="#id103">The waymarking algorithm</a><a class="headerlink" href="#the-waymarking-algorithm" title="Permalink to this headline">¶</a></h4>
+<p>Since the <tt class="docutils literal"><span class="pre">Use</span></tt> objects are deprived of the direct (back)pointer to their
+<tt class="docutils literal"><span class="pre">User</span></tt> objects, there must be a fast and exact method to recover it. This is
+accomplished by the following scheme:</p>
+<p>A bit-encoding in the 2 LSBits (least significant bits) of the <tt class="docutils literal"><span class="pre">Use::Prev</span></tt>
+allows to find the start of the <tt class="docutils literal"><span class="pre">User</span></tt> object:</p>
+<ul class="simple">
+<li><tt class="docutils literal"><span class="pre">00</span></tt> — binary digit 0</li>
+<li><tt class="docutils literal"><span class="pre">01</span></tt> — binary digit 1</li>
+<li><tt class="docutils literal"><span class="pre">10</span></tt> — stop and calculate (<tt class="docutils literal"><span class="pre">s</span></tt>)</li>
+<li><tt class="docutils literal"><span class="pre">11</span></tt> — full stop (<tt class="docutils literal"><span class="pre">S</span></tt>)</li>
+</ul>
+<p>Given a <tt class="docutils literal"><span class="pre">Use*</span></tt>, all we have to do is to walk till we get a stop and we either
+have a <tt class="docutils literal"><span class="pre">User</span></tt> immediately behind or we have to walk to the next stop picking
+up digits and calculating the offset:</p>
+<div class="highlight-none"><div class="highlight"><pre>.---.---.---.---.---.---.---.---.---.---.---.---.---.---.---.---.----------------
+| 1 | s | 1 | 0 | 1 | 0 | s | 1 | 1 | 0 | s | 1 | 1 | s | 1 | S | User (or User*)
+'---'---'---'---'---'---'---'---'---'---'---'---'---'---'---'---'----------------
+ |+15 |+10 |+6 |+3 |+1
+ | | | | | __>
+ | | | | __________>
+ | | | ______________________>
+ | | ______________________________________>
+ | __________________________________________________________>
+</pre></div>
+</div>
+<p>Only the significant number of bits need to be stored between the stops, so that
+the <em>worst case is 20 memory accesses</em> when there are 1000 <tt class="docutils literal"><span class="pre">Use</span></tt> objects
+associated with a <tt class="docutils literal"><span class="pre">User</span></tt>.</p>
+</div>
+<div class="section" id="reference-implementation">
+<span id="referenceimpl"></span><h4><a class="toc-backref" href="#id104">Reference implementation</a><a class="headerlink" href="#reference-implementation" title="Permalink to this headline">¶</a></h4>
+<p>The following literate Haskell fragment demonstrates the concept:</p>
+<div class="highlight-haskell"><div class="highlight"><pre><span class="o">></span> <span class="kr">import</span> <span class="nn">Test.QuickCheck</span>
+<span class="o">></span>
+<span class="o">></span> <span class="n">digits</span> <span class="ow">::</span> <span class="kt">Int</span> <span class="ow">-></span> <span class="p">[</span><span class="kt">Char</span><span class="p">]</span> <span class="ow">-></span> <span class="p">[</span><span class="kt">Char</span><span class="p">]</span>
+<span class="o">></span> <span class="n">digits</span> <span class="mi">0</span> <span class="n">acc</span> <span class="ow">=</span> <span class="sc">'0'</span> <span class="kt">:</span> <span class="n">acc</span>
+<span class="o">></span> <span class="n">digits</span> <span class="mi">1</span> <span class="n">acc</span> <span class="ow">=</span> <span class="sc">'1'</span> <span class="kt">:</span> <span class="n">acc</span>
+<span class="o">></span> <span class="n">digits</span> <span class="n">n</span> <span class="n">acc</span> <span class="ow">=</span> <span class="n">digits</span> <span class="p">(</span><span class="n">n</span> <span class="p">`</span><span class="n">div</span><span class="p">`</span> <span class="mi">2</span><span class="p">)</span> <span class="o">$</span> <span class="n">digits</span> <span class="p">(</span><span class="n">n</span> <span class="p">`</span><span class="n">mod</span><span class="p">`</span> <span class="mi">2</span><span class="p">)</span> <span class="n">acc</span>
+<span class="o">></span>
+<span class="o">></span> <span class="n">dist</span> <span class="ow">::</span> <span class="kt">Int</span> <span class="ow">-></span> <span class="p">[</span><span class="kt">Char</span><span class="p">]</span> <span class="ow">-></span> <span class="p">[</span><span class="kt">Char</span><span class="p">]</span>
+<span class="o">></span> <span class="n">dist</span> <span class="mi">0</span> <span class="kt">[]</span> <span class="ow">=</span> <span class="p">[</span><span class="sc">'S'</span><span class="p">]</span>
+<span class="o">></span> <span class="n">dist</span> <span class="mi">0</span> <span class="n">acc</span> <span class="ow">=</span> <span class="n">acc</span>
+<span class="o">></span> <span class="n">dist</span> <span class="mi">1</span> <span class="n">acc</span> <span class="ow">=</span> <span class="kr">let</span> <span class="n">r</span> <span class="ow">=</span> <span class="n">dist</span> <span class="mi">0</span> <span class="n">acc</span> <span class="kr">in</span> <span class="n">'s'</span> <span class="kt">:</span> <span class="n">digits</span> <span class="p">(</span><span class="n">length</span> <span class="n">r</span><span class="p">)</span> <span class="n">r</span>
+<span class="o">></span> <span class="n">dist</span> <span class="n">n</span> <span class="n">acc</span> <span class="ow">=</span> <span class="n">dist</span> <span class="p">(</span><span class="n">n</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span> <span class="o">$</span> <span class="n">dist</span> <span class="mi">1</span> <span class="n">acc</span>
+<span class="o">></span>
+<span class="o">></span> <span class="n">takeLast</span> <span class="n">n</span> <span class="n">ss</span> <span class="ow">=</span> <span class="n">reverse</span> <span class="o">$</span> <span class="n">take</span> <span class="n">n</span> <span class="o">$</span> <span class="n">reverse</span> <span class="n">ss</span>
+<span class="o">></span>
+<span class="o">></span> <span class="n">test</span> <span class="ow">=</span> <span class="n">takeLast</span> <span class="mi">40</span> <span class="o">$</span> <span class="n">dist</span> <span class="mi">20</span> <span class="kt">[]</span>
+<span class="o">></span>
+</pre></div>
+</div>
+<p>Printing <test> gives: <tt class="docutils literal"><span class="pre">"1s100000s11010s10100s1111s1010s110s11s1S"</span></tt></p>
+<p>The reverse algorithm computes the length of the string just by examining a
+certain prefix:</p>
+<div class="highlight-haskell"><div class="highlight"><pre><span class="o">></span> <span class="n">pref</span> <span class="ow">::</span> <span class="p">[</span><span class="kt">Char</span><span class="p">]</span> <span class="ow">-></span> <span class="kt">Int</span>
+<span class="o">></span> <span class="n">pref</span> <span class="s">"S"</span> <span class="ow">=</span> <span class="mi">1</span>
+<span class="o">></span> <span class="n">pref</span> <span class="p">(</span><span class="n">'s'</span><span class="kt">:</span><span class="sc">'1'</span><span class="kt">:</span><span class="n">rest</span><span class="p">)</span> <span class="ow">=</span> <span class="n">decode</span> <span class="mi">2</span> <span class="mi">1</span> <span class="n">rest</span>
+<span class="o">></span> <span class="n">pref</span> <span class="p">(</span><span class="kr">_</span><span class="kt">:</span><span class="n">rest</span><span class="p">)</span> <span class="ow">=</span> <span class="mi">1</span> <span class="o">+</span> <span class="n">pref</span> <span class="n">rest</span>
+<span class="o">></span>
+<span class="o">></span> <span class="n">decode</span> <span class="n">walk</span> <span class="n">acc</span> <span class="p">(</span><span class="sc">'0'</span><span class="kt">:</span><span class="n">rest</span><span class="p">)</span> <span class="ow">=</span> <span class="n">decode</span> <span class="p">(</span><span class="n">walk</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="p">(</span><span class="n">acc</span> <span class="o">*</span> <span class="mi">2</span><span class="p">)</span> <span class="n">rest</span>
+<span class="o">></span> <span class="n">decode</span> <span class="n">walk</span> <span class="n">acc</span> <span class="p">(</span><span class="sc">'1'</span><span class="kt">:</span><span class="n">rest</span><span class="p">)</span> <span class="ow">=</span> <span class="n">decode</span> <span class="p">(</span><span class="n">walk</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="p">(</span><span class="n">acc</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="n">rest</span>
+<span class="o">></span> <span class="n">decode</span> <span class="n">walk</span> <span class="n">acc</span> <span class="kr">_</span> <span class="ow">=</span> <span class="n">walk</span> <span class="o">+</span> <span class="n">acc</span>
+<span class="o">></span>
+</pre></div>
+</div>
+<p>Now, as expected, printing <pref test> gives <tt class="docutils literal"><span class="pre">40</span></tt>.</p>
+<p>We can <em>quickCheck</em> this with following property:</p>
+<div class="highlight-haskell"><div class="highlight"><pre><span class="o">></span> <span class="n">testcase</span> <span class="ow">=</span> <span class="n">dist</span> <span class="mi">2000</span> <span class="kt">[]</span>
+<span class="o">></span> <span class="n">testcaseLength</span> <span class="ow">=</span> <span class="n">length</span> <span class="n">testcase</span>
+<span class="o">></span>
+<span class="o">></span> <span class="n">identityProp</span> <span class="n">n</span> <span class="ow">=</span> <span class="n">n</span> <span class="o">></span> <span class="mi">0</span> <span class="o">&&</span> <span class="n">n</span> <span class="o"><=</span> <span class="n">testcaseLength</span> <span class="o">==></span> <span class="n">length</span> <span class="n">arr</span> <span class="o">==</span> <span class="n">pref</span> <span class="n">arr</span>
+<span class="o">></span> <span class="kr">where</span> <span class="n">arr</span> <span class="ow">=</span> <span class="n">takeLast</span> <span class="n">n</span> <span class="n">testcase</span>
+<span class="o">></span>
+</pre></div>
+</div>
+<p>As expected <quickCheck identityProp> gives:</p>
+<div class="highlight-python"><div class="highlight"><pre>*Main> quickCheck identityProp
+OK, passed 100 tests.
+</pre></div>
+</div>
+<p>Let’s be a bit more exhaustive:</p>
+<div class="highlight-haskell"><div class="highlight"><pre><span class="o">></span>
+<span class="o">></span> <span class="n">deepCheck</span> <span class="n">p</span> <span class="ow">=</span> <span class="n">check</span> <span class="p">(</span><span class="n">defaultConfig</span> <span class="p">{</span> <span class="n">configMaxTest</span> <span class="ow">=</span> <span class="mi">500</span> <span class="p">})</span> <span class="n">p</span>
+<span class="o">></span>
+</pre></div>
+</div>
+<p>And here is the result of <deepCheck identityProp>:</p>
+<div class="highlight-python"><div class="highlight"><pre>*Main> deepCheck identityProp
+OK, passed 500 tests.
+</pre></div>
+</div>
+</div>
+<div class="section" id="tagging-considerations">
+<span id="tagging"></span><h4><a class="toc-backref" href="#id105">Tagging considerations</a><a class="headerlink" href="#tagging-considerations" title="Permalink to this headline">¶</a></h4>
+<p>To maintain the invariant that the 2 LSBits of each <tt class="docutils literal"><span class="pre">Use**</span></tt> in <tt class="docutils literal"><span class="pre">Use</span></tt> never
+change after being set up, setters of <tt class="docutils literal"><span class="pre">Use::Prev</span></tt> must re-tag the new
+<tt class="docutils literal"><span class="pre">Use**</span></tt> on every modification. Accordingly getters must strip the tag bits.</p>
+<p>For layout b) instead of the <tt class="docutils literal"><span class="pre">User</span></tt> we find a pointer (<tt class="docutils literal"><span class="pre">User*</span></tt> with LSBit
+set). Following this pointer brings us to the <tt class="docutils literal"><span class="pre">User</span></tt>. A portable trick
+ensures that the first bytes of <tt class="docutils literal"><span class="pre">User</span></tt> (if interpreted as a pointer) never has
+the LSBit set. (Portability is relying on the fact that all known compilers
+place the <tt class="docutils literal"><span class="pre">vptr</span></tt> in the first word of the instances.)</p>
+</div>
+</div>
+<div class="section" id="designing-type-hiercharies-and-polymorphic-interfaces">
+<span id="polymorphism"></span><h3><a class="toc-backref" href="#id106">Designing Type Hiercharies and Polymorphic Interfaces</a><a class="headerlink" href="#designing-type-hiercharies-and-polymorphic-interfaces" title="Permalink to this headline">¶</a></h3>
+<p>There are two different design patterns that tend to result in the use of
+virtual dispatch for methods in a type hierarchy in C++ programs. The first is
+a genuine type hierarchy where different types in the hierarchy model
+a specific subset of the functionality and semantics, and these types nest
+strictly within each other. Good examples of this can be seen in the <tt class="docutils literal"><span class="pre">Value</span></tt>
+or <tt class="docutils literal"><span class="pre">Type</span></tt> type hierarchies.</p>
+<p>A second is the desire to dispatch dynamically across a collection of
+polymorphic interface implementations. This latter use case can be modeled with
+virtual dispatch and inheritance by defining an abstract interface base class
+which all implementations derive from and override. However, this
+implementation strategy forces an <strong>“is-a”</strong> relationship to exist that is not
+actually meaningful. There is often not some nested hierarchy of useful
+generalizations which code might interact with and move up and down. Instead,
+there is a singular interface which is dispatched across a range of
+implementations.</p>
+<p>The preferred implementation strategy for the second use case is that of
+generic programming (sometimes called “compile-time duck typing” or “static
+polymorphism”). For example, a template over some type parameter <tt class="docutils literal"><span class="pre">T</span></tt> can be
+instantiated across any particular implementation that conforms to the
+interface or <em>concept</em>. A good example here is the highly generic properties of
+any type which models a node in a directed graph. LLVM models these primarily
+through templates and generic programming. Such templates include the
+<tt class="docutils literal"><span class="pre">LoopInfoBase</span></tt> and <tt class="docutils literal"><span class="pre">DominatorTreeBase</span></tt>. When this type of polymorphism
+truly needs <strong>dynamic</strong> dispatch you can generalize it using a technique
+called <em>concept-based polymorphism</em>. This pattern emulates the interfaces and
+behaviors of templates using a very limited form of virtual dispatch for type
+erasure inside its implementation. You can find examples of this technique in
+the <tt class="docutils literal"><span class="pre">PassManager.h</span></tt> system, and there is a more detailed introduction to it
+by Sean Parent in several of his talks and papers:</p>
+<ol class="arabic simple">
+<li><a class="reference external" href="http://channel9.msdn.com/Events/GoingNative/2013/Inheritance-Is-The-Base-Class-of-Evil">Inheritance Is The Base Class of Evil</a>
+- The GoingNative 2013 talk describing this technique, and probably the best
+place to start.</li>
+<li><a class="reference external" href="http://www.youtube.com/watch?v=_BpMYeUFXv8">Value Semantics and Concepts-based Polymorphism</a> - The C++Now! 2012 talk
+describing this technique in more detail.</li>
+<li><a class="reference external" href="http://github.com/sean-parent/sean-parent.github.com/wiki/Papers-and-Presentations">Sean Parent’s Papers and Presentations</a>
+- A Github project full of links to slides, video, and sometimes code.</li>
+</ol>
+<p>When deciding between creating a type hierarchy (with either tagged or virtual
+dispatch) and using templates or concepts-based polymorphism, consider whether
+there is some refinement of an abstract base class which is a semantically
+meaningful type on an interface boundary. If anything more refined than the
+root abstract interface is meaningless to talk about as a partial extension of
+the semantic model, then your use case likely fits better with polymorphism and
+you should avoid using virtual dispatch. However, there may be some exigent
+circumstances that require one technique or the other to be used.</p>
+<p>If you do need to introduce a type hierarchy, we prefer to use explicitly
+closed type hierarchies with manual tagged dispatch and/or RTTI rather than the
+open inheritance model and virtual dispatch that is more common in C++ code.
+This is because LLVM rarely encourages library consumers to extend its core
+types, and leverages the closed and tag-dispatched nature of its hierarchies to
+generate significantly more efficient code. We have also found that a large
+amount of our usage of type hierarchies fits better with tag-based pattern
+matching rather than dynamic dispatch across a common interface. Within LLVM we
+have built custom helpers to facilitate this design. See this document’s
+section on <a class="reference internal" href="#isa"><em>isa and dyn_cast</em></a> and our <a class="reference internal" href="HowToSetUpLLVMStyleRTTI.html"><em>detailed document</em></a> which describes how you can implement this
+pattern for use with the LLVM helpers.</p>
+</div>
+<div class="section" id="abi-breaking-checks">
+<span id="id4"></span><h3><a class="toc-backref" href="#id107">ABI Breaking Checks</a><a class="headerlink" href="#abi-breaking-checks" title="Permalink to this headline">¶</a></h3>
+<p>Checks and asserts that alter the LLVM C++ ABI are predicated on the
+preprocessor symbol <cite>LLVM_ENABLE_ABI_BREAKING_CHECKS</cite> – LLVM
+libraries built with <cite>LLVM_ENABLE_ABI_BREAKING_CHECKS</cite> are not ABI
+compatible LLVM libraries built without it defined. By default,
+turning on assertions also turns on <cite>LLVM_ENABLE_ABI_BREAKING_CHECKS</cite>
+so a default +Asserts build is not ABI compatible with a
+default -Asserts build. Clients that want ABI compatibility
+between +Asserts and -Asserts builds should use the CMake or autoconf
+build systems to set <cite>LLVM_ENABLE_ABI_BREAKING_CHECKS</cite> independently
+of <cite>LLVM_ENABLE_ASSERTIONS</cite>.</p>
+</div>
+</div>
+<div class="section" id="the-core-llvm-class-hierarchy-reference">
+<span id="coreclasses"></span><h2><a class="toc-backref" href="#id108">The Core LLVM Class Hierarchy Reference</a><a class="headerlink" href="#the-core-llvm-class-hierarchy-reference" title="Permalink to this headline">¶</a></h2>
+<p><tt class="docutils literal"><span class="pre">#include</span> <span class="pre">"llvm/IR/Type.h"</span></tt></p>
+<p>header source: <a class="reference external" href="http://llvm.org/doxygen/Type_8h-source.html">Type.h</a></p>
+<p>doxygen info: <a class="reference external" href="http://llvm.org/doxygen/classllvm_1_1Type.html">Type Clases</a></p>
+<p>The Core LLVM classes are the primary means of representing the program being
+inspected or transformed. The core LLVM classes are defined in header files in
+the <tt class="docutils literal"><span class="pre">include/llvm/IR</span></tt> directory, and implemented in the <tt class="docutils literal"><span class="pre">lib/IR</span></tt>
+directory. It’s worth noting that, for historical reasons, this library is
+called <tt class="docutils literal"><span class="pre">libLLVMCore.so</span></tt>, not <tt class="docutils literal"><span class="pre">libLLVMIR.so</span></tt> as you might expect.</p>
+<div class="section" id="the-type-class-and-derived-types">
+<span id="type"></span><h3><a class="toc-backref" href="#id109">The Type class and Derived Types</a><a class="headerlink" href="#the-type-class-and-derived-types" title="Permalink to this headline">¶</a></h3>
+<p><tt class="docutils literal"><span class="pre">Type</span></tt> is a superclass of all type classes. Every <tt class="docutils literal"><span class="pre">Value</span></tt> has a <tt class="docutils literal"><span class="pre">Type</span></tt>.
+<tt class="docutils literal"><span class="pre">Type</span></tt> cannot be instantiated directly but only through its subclasses.
+Certain primitive types (<tt class="docutils literal"><span class="pre">VoidType</span></tt>, <tt class="docutils literal"><span class="pre">LabelType</span></tt>, <tt class="docutils literal"><span class="pre">FloatType</span></tt> and
+<tt class="docutils literal"><span class="pre">DoubleType</span></tt>) have hidden subclasses. They are hidden because they offer no
+useful functionality beyond what the <tt class="docutils literal"><span class="pre">Type</span></tt> class offers except to distinguish
+themselves from other subclasses of <tt class="docutils literal"><span class="pre">Type</span></tt>.</p>
+<p>All other types are subclasses of <tt class="docutils literal"><span class="pre">DerivedType</span></tt>. Types can be named, but this
+is not a requirement. There exists exactly one instance of a given shape at any
+one time. This allows type equality to be performed with address equality of
+the Type Instance. That is, given two <tt class="docutils literal"><span class="pre">Type*</span></tt> values, the types are identical
+if the pointers are identical.</p>
+<div class="section" id="important-public-methods">
+<span id="m-type"></span><h4><a class="toc-backref" href="#id110">Important Public Methods</a><a class="headerlink" href="#important-public-methods" title="Permalink to this headline">¶</a></h4>
+<ul class="simple">
+<li><tt class="docutils literal"><span class="pre">bool</span> <span class="pre">isIntegerTy()</span> <span class="pre">const</span></tt>: Returns true for any integer type.</li>
+<li><tt class="docutils literal"><span class="pre">bool</span> <span class="pre">isFloatingPointTy()</span></tt>: Return true if this is one of the five
+floating point types.</li>
+<li><tt class="docutils literal"><span class="pre">bool</span> <span class="pre">isSized()</span></tt>: Return true if the type has known size. Things
+that don’t have a size are abstract types, labels and void.</li>
+</ul>
+</div>
+<div class="section" id="important-derived-types">
+<span id="derivedtypes"></span><h4><a class="toc-backref" href="#id111">Important Derived Types</a><a class="headerlink" href="#important-derived-types" title="Permalink to this headline">¶</a></h4>
+<dl class="docutils">
+<dt><tt class="docutils literal"><span class="pre">IntegerType</span></tt></dt>
+<dd><p class="first">Subclass of DerivedType that represents integer types of any bit width. Any
+bit width between <tt class="docutils literal"><span class="pre">IntegerType::MIN_INT_BITS</span></tt> (1) and
+<tt class="docutils literal"><span class="pre">IntegerType::MAX_INT_BITS</span></tt> (~8 million) can be represented.</p>
+<ul class="last simple">
+<li><tt class="docutils literal"><span class="pre">static</span> <span class="pre">const</span> <span class="pre">IntegerType*</span> <span class="pre">get(unsigned</span> <span class="pre">NumBits)</span></tt>: get an integer
+type of a specific bit width.</li>
+<li><tt class="docutils literal"><span class="pre">unsigned</span> <span class="pre">getBitWidth()</span> <span class="pre">const</span></tt>: Get the bit width of an integer type.</li>
+</ul>
+</dd>
+<dt><tt class="docutils literal"><span class="pre">SequentialType</span></tt></dt>
+<dd><p class="first">This is subclassed by ArrayType, PointerType and VectorType.</p>
+<ul class="last simple">
+<li><tt class="docutils literal"><span class="pre">const</span> <span class="pre">Type</span> <span class="pre">*</span> <span class="pre">getElementType()</span> <span class="pre">const</span></tt>: Returns the type of each
+of the elements in the sequential type.</li>
+</ul>
+</dd>
+<dt><tt class="docutils literal"><span class="pre">ArrayType</span></tt></dt>
+<dd><p class="first">This is a subclass of SequentialType and defines the interface for array
+types.</p>
+<ul class="last simple">
+<li><tt class="docutils literal"><span class="pre">unsigned</span> <span class="pre">getNumElements()</span> <span class="pre">const</span></tt>: Returns the number of elements
+in the array.</li>
+</ul>
+</dd>
+<dt><tt class="docutils literal"><span class="pre">PointerType</span></tt></dt>
+<dd>Subclass of SequentialType for pointer types.</dd>
+<dt><tt class="docutils literal"><span class="pre">VectorType</span></tt></dt>
+<dd>Subclass of SequentialType for vector types. A vector type is similar to an
+ArrayType but is distinguished because it is a first class type whereas
+ArrayType is not. Vector types are used for vector operations and are usually
+small vectors of an integer or floating point type.</dd>
+<dt><tt class="docutils literal"><span class="pre">StructType</span></tt></dt>
+<dd>Subclass of DerivedTypes for struct types.</dd>
+</dl>
+<dl class="docutils" id="functiontype">
+<dt><tt class="docutils literal"><span class="pre">FunctionType</span></tt></dt>
+<dd><p class="first">Subclass of DerivedTypes for function types.</p>
+<ul class="last simple">
+<li><tt class="docutils literal"><span class="pre">bool</span> <span class="pre">isVarArg()</span> <span class="pre">const</span></tt>: Returns true if it’s a vararg function.</li>
+<li><tt class="docutils literal"><span class="pre">const</span> <span class="pre">Type</span> <span class="pre">*</span> <span class="pre">getReturnType()</span> <span class="pre">const</span></tt>: Returns the return type of the
+function.</li>
+<li><tt class="docutils literal"><span class="pre">const</span> <span class="pre">Type</span> <span class="pre">*</span> <span class="pre">getParamType</span> <span class="pre">(unsigned</span> <span class="pre">i)</span></tt>: Returns the type of the ith
+parameter.</li>
+<li><tt class="docutils literal"><span class="pre">const</span> <span class="pre">unsigned</span> <span class="pre">getNumParams()</span> <span class="pre">const</span></tt>: Returns the number of formal
+parameters.</li>
+</ul>
+</dd>
+</dl>
+</div>
+</div>
+<div class="section" id="the-module-class">
+<span id="module"></span><h3><a class="toc-backref" href="#id112">The <tt class="docutils literal"><span class="pre">Module</span></tt> class</a><a class="headerlink" href="#the-module-class" title="Permalink to this headline">¶</a></h3>
+<p><tt class="docutils literal"><span class="pre">#include</span> <span class="pre">"llvm/IR/Module.h"</span></tt></p>
+<p>header source: <a class="reference external" href="http://llvm.org/doxygen/Module_8h-source.html">Module.h</a></p>
+<p>doxygen info: <a class="reference external" href="http://llvm.org/doxygen/classllvm_1_1Module.html">Module Class</a></p>
+<p>The <tt class="docutils literal"><span class="pre">Module</span></tt> class represents the top level structure present in LLVM
+programs. An LLVM module is effectively either a translation unit of the
+original program or a combination of several translation units merged by the
+linker. The <tt class="docutils literal"><span class="pre">Module</span></tt> class keeps track of a list of <a class="reference internal" href="#c-function"><em>Function</em></a>s, a list of <a class="reference internal" href="#globalvariable">GlobalVariable</a>s, and a <a class="reference internal" href="#symboltable">SymbolTable</a>.
+Additionally, it contains a few helpful member functions that try to make common
+operations easy.</p>
+<div class="section" id="important-public-members-of-the-module-class">
+<span id="m-module"></span><h4><a class="toc-backref" href="#id113">Important Public Members of the <tt class="docutils literal"><span class="pre">Module</span></tt> class</a><a class="headerlink" href="#important-public-members-of-the-module-class" title="Permalink to this headline">¶</a></h4>
+<ul>
+<li><p class="first"><tt class="docutils literal"><span class="pre">Module::Module(std::string</span> <span class="pre">name</span> <span class="pre">=</span> <span class="pre">"")</span></tt></p>
+<p>Constructing a <a class="reference internal" href="#module">Module</a> is easy. You can optionally provide a name for it
+(probably based on the name of the translation unit).</p>
+</li>
+<li><div class="first line-block">
+<div class="line"><tt class="docutils literal"><span class="pre">Module::iterator</span></tt> - Typedef for function list iterator</div>
+<div class="line"><tt class="docutils literal"><span class="pre">Module::const_iterator</span></tt> - Typedef for const_iterator.</div>
+<div class="line"><tt class="docutils literal"><span class="pre">begin()</span></tt>, <tt class="docutils literal"><span class="pre">end()</span></tt>, <tt class="docutils literal"><span class="pre">size()</span></tt>, <tt class="docutils literal"><span class="pre">empty()</span></tt></div>
+</div>
+<p>These are forwarding methods that make it easy to access the contents of a
+<tt class="docutils literal"><span class="pre">Module</span></tt> object’s <a class="reference internal" href="#c-function"><em>Function</em></a> list.</p>
+</li>
+<li><p class="first"><tt class="docutils literal"><span class="pre">Module::FunctionListType</span> <span class="pre">&getFunctionList()</span></tt></p>
+<p>Returns the list of <a class="reference internal" href="#c-function"><em>Function</em></a>s. This is necessary to use
+when you need to update the list or perform a complex action that doesn’t have
+a forwarding method.</p>
+</li>
+</ul>
+<hr class="docutils" />
+<ul>
+<li><div class="first line-block">
+<div class="line"><tt class="docutils literal"><span class="pre">Module::global_iterator</span></tt> - Typedef for global variable list iterator</div>
+<div class="line"><tt class="docutils literal"><span class="pre">Module::const_global_iterator</span></tt> - Typedef for const_iterator.</div>
+<div class="line"><tt class="docutils literal"><span class="pre">global_begin()</span></tt>, <tt class="docutils literal"><span class="pre">global_end()</span></tt>, <tt class="docutils literal"><span class="pre">global_size()</span></tt>, <tt class="docutils literal"><span class="pre">global_empty()</span></tt></div>
+</div>
+<p>These are forwarding methods that make it easy to access the contents of a
+<tt class="docutils literal"><span class="pre">Module</span></tt> object’s <a class="reference internal" href="#globalvariable">GlobalVariable</a> list.</p>
+</li>
+<li><p class="first"><tt class="docutils literal"><span class="pre">Module::GlobalListType</span> <span class="pre">&getGlobalList()</span></tt></p>
+<p>Returns the list of <a class="reference internal" href="#globalvariable">GlobalVariable</a>s. This is necessary to use when you
+need to update the list or perform a complex action that doesn’t have a
+forwarding method.</p>
+</li>
+</ul>
+<hr class="docutils" />
+<ul>
+<li><p class="first"><tt class="docutils literal"><span class="pre">SymbolTable</span> <span class="pre">*getSymbolTable()</span></tt></p>
+<p>Return a reference to the <a class="reference internal" href="#symboltable">SymbolTable</a> for this <tt class="docutils literal"><span class="pre">Module</span></tt>.</p>
+</li>
+</ul>
+<hr class="docutils" />
+<ul>
+<li><p class="first"><tt class="docutils literal"><span class="pre">Function</span> <span class="pre">*getFunction(StringRef</span> <span class="pre">Name)</span> <span class="pre">const</span></tt></p>
+<p>Look up the specified function in the <tt class="docutils literal"><span class="pre">Module</span></tt> <a class="reference internal" href="#symboltable">SymbolTable</a>. If it does not
+exist, return <tt class="docutils literal"><span class="pre">null</span></tt>.</p>
+</li>
+<li><p class="first"><tt class="docutils literal"><span class="pre">Function</span> <span class="pre">*getOrInsertFunction(const</span> <span class="pre">std::string</span> <span class="pre">&Name,</span> <span class="pre">const</span> <span class="pre">FunctionType</span>
+<span class="pre">*T)</span></tt></p>
+<p>Look up the specified function in the <tt class="docutils literal"><span class="pre">Module</span></tt> <a class="reference internal" href="#symboltable">SymbolTable</a>. If it does not
+exist, add an external declaration for the function and return it.</p>
+</li>
+<li><p class="first"><tt class="docutils literal"><span class="pre">std::string</span> <span class="pre">getTypeName(const</span> <span class="pre">Type</span> <span class="pre">*Ty)</span></tt></p>
+<p>If there is at least one entry in the <a class="reference internal" href="#symboltable">SymbolTable</a> for the specified <a class="reference internal" href="#type">Type</a>,
+return it. Otherwise return the empty string.</p>
+</li>
+<li><p class="first"><tt class="docutils literal"><span class="pre">bool</span> <span class="pre">addTypeName(const</span> <span class="pre">std::string</span> <span class="pre">&Name,</span> <span class="pre">const</span> <span class="pre">Type</span> <span class="pre">*Ty)</span></tt></p>
+<p>Insert an entry in the <a class="reference internal" href="#symboltable">SymbolTable</a> mapping <tt class="docutils literal"><span class="pre">Name</span></tt> to <tt class="docutils literal"><span class="pre">Ty</span></tt>. If there is
+already an entry for this name, true is returned and the <a class="reference internal" href="#symboltable">SymbolTable</a> is not
+modified.</p>
+</li>
+</ul>
+</div>
+</div>
+<div class="section" id="the-value-class">
+<span id="value"></span><h3><a class="toc-backref" href="#id114">The <tt class="docutils literal"><span class="pre">Value</span></tt> class</a><a class="headerlink" href="#the-value-class" title="Permalink to this headline">¶</a></h3>
+<p><tt class="docutils literal"><span class="pre">#include</span> <span class="pre">"llvm/IR/Value.h"</span></tt></p>
+<p>header source: <a class="reference external" href="http://llvm.org/doxygen/Value_8h-source.html">Value.h</a></p>
+<p>doxygen info: <a class="reference external" href="http://llvm.org/doxygen/classllvm_1_1Value.html">Value Class</a></p>
+<p>The <tt class="docutils literal"><span class="pre">Value</span></tt> class is the most important class in the LLVM Source base. It
+represents a typed value that may be used (among other things) as an operand to
+an instruction. There are many different types of <tt class="docutils literal"><span class="pre">Value</span></tt>s, such as
+<a class="reference internal" href="#constant">Constant</a>s, <a class="reference internal" href="#argument">Argument</a>s. Even <a class="reference internal" href="#instruction">Instruction</a>s and <a class="reference internal" href="#c-function"><em>Function</em></a>s are <tt class="docutils literal"><span class="pre">Value</span></tt>s.</p>
+<p>A particular <tt class="docutils literal"><span class="pre">Value</span></tt> may be used many times in the LLVM representation for a
+program. For example, an incoming argument to a function (represented with an
+instance of the <a class="reference internal" href="#argument">Argument</a> class) is “used” by every instruction in the function
+that references the argument. To keep track of this relationship, the <tt class="docutils literal"><span class="pre">Value</span></tt>
+class keeps a list of all of the <tt class="docutils literal"><span class="pre">User</span></tt>s that is using it (the <a class="reference internal" href="#user">User</a> class
+is a base class for all nodes in the LLVM graph that can refer to <tt class="docutils literal"><span class="pre">Value</span></tt>s).
+This use list is how LLVM represents def-use information in the program, and is
+accessible through the <tt class="docutils literal"><span class="pre">use_*</span></tt> methods, shown below.</p>
+<p>Because LLVM is a typed representation, every LLVM <tt class="docutils literal"><span class="pre">Value</span></tt> is typed, and this
+<a class="reference internal" href="#type">Type</a> is available through the <tt class="docutils literal"><span class="pre">getType()</span></tt> method. In addition, all LLVM
+values can be named. The “name” of the <tt class="docutils literal"><span class="pre">Value</span></tt> is a symbolic string printed
+in the LLVM code:</p>
+<div class="highlight-llvm"><div class="highlight"><pre><span class="nv">%foo</span> <span class="p">=</span> <span class="k">add</span> <span class="k">i32</span> <span class="m">1</span><span class="p">,</span> <span class="m">2</span>
+</pre></div>
+</div>
+<p id="namewarning">The name of this instruction is “foo”. <strong>NOTE</strong> that the name of any value may
+be missing (an empty string), so names should <strong>ONLY</strong> be used for debugging
+(making the source code easier to read, debugging printouts), they should not be
+used to keep track of values or map between them. For this purpose, use a
+<tt class="docutils literal"><span class="pre">std::map</span></tt> of pointers to the <tt class="docutils literal"><span class="pre">Value</span></tt> itself instead.</p>
+<p>One important aspect of LLVM is that there is no distinction between an SSA
+variable and the operation that produces it. Because of this, any reference to
+the value produced by an instruction (or the value available as an incoming
+argument, for example) is represented as a direct pointer to the instance of the
+class that represents this value. Although this may take some getting used to,
+it simplifies the representation and makes it easier to manipulate.</p>
+<div class="section" id="important-public-members-of-the-value-class">
+<span id="m-value"></span><h4><a class="toc-backref" href="#id115">Important Public Members of the <tt class="docutils literal"><span class="pre">Value</span></tt> class</a><a class="headerlink" href="#important-public-members-of-the-value-class" title="Permalink to this headline">¶</a></h4>
+<ul>
+<li><div class="first line-block">
+<div class="line"><tt class="docutils literal"><span class="pre">Value::use_iterator</span></tt> - Typedef for iterator over the use-list</div>
+<div class="line"><tt class="docutils literal"><span class="pre">Value::const_use_iterator</span></tt> - Typedef for const_iterator over the
+use-list</div>
+<div class="line"><tt class="docutils literal"><span class="pre">unsigned</span> <span class="pre">use_size()</span></tt> - Returns the number of users of the value.</div>
+<div class="line"><tt class="docutils literal"><span class="pre">bool</span> <span class="pre">use_empty()</span></tt> - Returns true if there are no users.</div>
+<div class="line"><tt class="docutils literal"><span class="pre">use_iterator</span> <span class="pre">use_begin()</span></tt> - Get an iterator to the start of the
+use-list.</div>
+<div class="line"><tt class="docutils literal"><span class="pre">use_iterator</span> <span class="pre">use_end()</span></tt> - Get an iterator to the end of the use-list.</div>
+<div class="line"><tt class="docutils literal"><span class="pre">User</span> <span class="pre">*use_back()</span></tt> - Returns the last element in the list.</div>
+</div>
+<p>These methods are the interface to access the def-use information in LLVM.
+As with all other iterators in LLVM, the naming conventions follow the
+conventions defined by the <a class="reference internal" href="#stl">STL</a>.</p>
+</li>
+<li><p class="first"><tt class="docutils literal"><span class="pre">Type</span> <span class="pre">*getType()</span> <span class="pre">const</span></tt>
+This method returns the Type of the Value.</p>
+</li>
+<li><div class="first line-block">
+<div class="line"><tt class="docutils literal"><span class="pre">bool</span> <span class="pre">hasName()</span> <span class="pre">const</span></tt></div>
+<div class="line"><tt class="docutils literal"><span class="pre">std::string</span> <span class="pre">getName()</span> <span class="pre">const</span></tt></div>
+<div class="line"><tt class="docutils literal"><span class="pre">void</span> <span class="pre">setName(const</span> <span class="pre">std::string</span> <span class="pre">&Name)</span></tt></div>
+</div>
+<p>This family of methods is used to access and assign a name to a <tt class="docutils literal"><span class="pre">Value</span></tt>, be
+aware of the <a class="reference internal" href="#namewarning"><em>precaution above</em></a>.</p>
+</li>
+<li><p class="first"><tt class="docutils literal"><span class="pre">void</span> <span class="pre">replaceAllUsesWith(Value</span> <span class="pre">*V)</span></tt></p>
+<p>This method traverses the use list of a <tt class="docutils literal"><span class="pre">Value</span></tt> changing all <a class="reference internal" href="#user">User</a>s of the
+current value to refer to “<tt class="docutils literal"><span class="pre">V</span></tt>” instead. For example, if you detect that an
+instruction always produces a constant value (for example through constant
+folding), you can replace all uses of the instruction with the constant like
+this:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">Inst</span><span class="o">-></span><span class="n">replaceAllUsesWith</span><span class="p">(</span><span class="n">ConstVal</span><span class="p">);</span>
+</pre></div>
+</div>
+</li>
+</ul>
+</div>
+</div>
+<div class="section" id="the-user-class">
+<span id="user"></span><h3><a class="toc-backref" href="#id116">The <tt class="docutils literal"><span class="pre">User</span></tt> class</a><a class="headerlink" href="#the-user-class" title="Permalink to this headline">¶</a></h3>
+<p><tt class="docutils literal"><span class="pre">#include</span> <span class="pre">"llvm/IR/User.h"</span></tt></p>
+<p>header source: <a class="reference external" href="http://llvm.org/doxygen/User_8h-source.html">User.h</a></p>
+<p>doxygen info: <a class="reference external" href="http://llvm.org/doxygen/classllvm_1_1User.html">User Class</a></p>
+<p>Superclass: <a class="reference internal" href="#value">Value</a></p>
+<p>The <tt class="docutils literal"><span class="pre">User</span></tt> class is the common base class of all LLVM nodes that may refer to
+<tt class="docutils literal"><span class="pre">Value</span></tt>s. It exposes a list of “Operands” that are all of the <tt class="docutils literal"><span class="pre">Value</span></tt>s
+that the User is referring to. The <tt class="docutils literal"><span class="pre">User</span></tt> class itself is a subclass of
+<tt class="docutils literal"><span class="pre">Value</span></tt>.</p>
+<p>The operands of a <tt class="docutils literal"><span class="pre">User</span></tt> point directly to the LLVM <tt class="docutils literal"><span class="pre">Value</span></tt> that it refers
+to. Because LLVM uses Static Single Assignment (SSA) form, there can only be
+one definition referred to, allowing this direct connection. This connection
+provides the use-def information in LLVM.</p>
+<div class="section" id="important-public-members-of-the-user-class">
+<span id="m-user"></span><h4><a class="toc-backref" href="#id117">Important Public Members of the <tt class="docutils literal"><span class="pre">User</span></tt> class</a><a class="headerlink" href="#important-public-members-of-the-user-class" title="Permalink to this headline">¶</a></h4>
+<p>The <tt class="docutils literal"><span class="pre">User</span></tt> class exposes the operand list in two ways: through an index access
+interface and through an iterator based interface.</p>
+<ul>
+<li><div class="first line-block">
+<div class="line"><tt class="docutils literal"><span class="pre">Value</span> <span class="pre">*getOperand(unsigned</span> <span class="pre">i)</span></tt></div>
+<div class="line"><tt class="docutils literal"><span class="pre">unsigned</span> <span class="pre">getNumOperands()</span></tt></div>
+</div>
+<p>These two methods expose the operands of the <tt class="docutils literal"><span class="pre">User</span></tt> in a convenient form for
+direct access.</p>
+</li>
+<li><div class="first line-block">
+<div class="line"><tt class="docutils literal"><span class="pre">User::op_iterator</span></tt> - Typedef for iterator over the operand list</div>
+<div class="line"><tt class="docutils literal"><span class="pre">op_iterator</span> <span class="pre">op_begin()</span></tt> - Get an iterator to the start of the operand
+list.</div>
+<div class="line"><tt class="docutils literal"><span class="pre">op_iterator</span> <span class="pre">op_end()</span></tt> - Get an iterator to the end of the operand list.</div>
+</div>
+<p>Together, these methods make up the iterator based interface to the operands
+of a <tt class="docutils literal"><span class="pre">User</span></tt>.</p>
+</li>
+</ul>
+</div>
+</div>
+<div class="section" id="the-instruction-class">
+<span id="instruction"></span><h3><a class="toc-backref" href="#id118">The <tt class="docutils literal"><span class="pre">Instruction</span></tt> class</a><a class="headerlink" href="#the-instruction-class" title="Permalink to this headline">¶</a></h3>
+<p><tt class="docutils literal"><span class="pre">#include</span> <span class="pre">"llvm/IR/Instruction.h"</span></tt></p>
+<p>header source: <a class="reference external" href="http://llvm.org/doxygen/Instruction_8h-source.html">Instruction.h</a></p>
+<p>doxygen info: <a class="reference external" href="http://llvm.org/doxygen/classllvm_1_1Instruction.html">Instruction Class</a></p>
+<p>Superclasses: <a class="reference internal" href="#user">User</a>, <a class="reference internal" href="#value">Value</a></p>
+<p>The <tt class="docutils literal"><span class="pre">Instruction</span></tt> class is the common base class for all LLVM instructions.
+It provides only a few methods, but is a very commonly used class. The primary
+data tracked by the <tt class="docutils literal"><span class="pre">Instruction</span></tt> class itself is the opcode (instruction
+type) and the parent <a class="reference internal" href="#basicblock">BasicBlock</a> the <tt class="docutils literal"><span class="pre">Instruction</span></tt> is embedded into. To
+represent a specific type of instruction, one of many subclasses of
+<tt class="docutils literal"><span class="pre">Instruction</span></tt> are used.</p>
+<p>Because the <tt class="docutils literal"><span class="pre">Instruction</span></tt> class subclasses the <a class="reference internal" href="#user">User</a> class, its operands can
+be accessed in the same way as for other <tt class="docutils literal"><span class="pre">User</span></tt>s (with the
+<tt class="docutils literal"><span class="pre">getOperand()</span></tt>/<tt class="docutils literal"><span class="pre">getNumOperands()</span></tt> and <tt class="docutils literal"><span class="pre">op_begin()</span></tt>/<tt class="docutils literal"><span class="pre">op_end()</span></tt> methods).
+An important file for the <tt class="docutils literal"><span class="pre">Instruction</span></tt> class is the <tt class="docutils literal"><span class="pre">llvm/Instruction.def</span></tt>
+file. This file contains some meta-data about the various different types of
+instructions in LLVM. It describes the enum values that are used as opcodes
+(for example <tt class="docutils literal"><span class="pre">Instruction::Add</span></tt> and <tt class="docutils literal"><span class="pre">Instruction::ICmp</span></tt>), as well as the
+concrete sub-classes of <tt class="docutils literal"><span class="pre">Instruction</span></tt> that implement the instruction (for
+example <a class="reference internal" href="#binaryoperator">BinaryOperator</a> and <a class="reference internal" href="#cmpinst">CmpInst</a>). Unfortunately, the use of macros in this
+file confuses doxygen, so these enum values don’t show up correctly in the
+<a class="reference external" href="http://llvm.org/doxygen/classllvm_1_1Instruction.html">doxygen output</a>.</p>
+<div class="section" id="important-subclasses-of-the-instruction-class">
+<span id="s-instruction"></span><h4><a class="toc-backref" href="#id119">Important Subclasses of the <tt class="docutils literal"><span class="pre">Instruction</span></tt> class</a><a class="headerlink" href="#important-subclasses-of-the-instruction-class" title="Permalink to this headline">¶</a></h4>
+<ul id="binaryoperator">
+<li><p class="first"><tt class="docutils literal"><span class="pre">BinaryOperator</span></tt></p>
+<p>This subclasses represents all two operand instructions whose operands must be
+the same type, except for the comparison instructions.</p>
+</li>
+</ul>
+<ul class="simple" id="castinst">
+<li><tt class="docutils literal"><span class="pre">CastInst</span></tt>
+This subclass is the parent of the 12 casting instructions. It provides
+common operations on cast instructions.</li>
+</ul>
+<ul id="cmpinst">
+<li><p class="first"><tt class="docutils literal"><span class="pre">CmpInst</span></tt></p>
+<p>This subclass respresents the two comparison instructions,
+<a class="reference external" href="LangRef.html#i_icmp">ICmpInst</a> (integer opreands), and
+<a class="reference external" href="LangRef.html#i_fcmp">FCmpInst</a> (floating point operands).</p>
+</li>
+</ul>
+<ul id="terminatorinst">
+<li><p class="first"><tt class="docutils literal"><span class="pre">TerminatorInst</span></tt></p>
+<p>This subclass is the parent of all terminator instructions (those which can
+terminate a block).</p>
+</li>
+</ul>
+</div>
+<div class="section" id="important-public-members-of-the-instruction-class">
+<span id="m-instruction"></span><h4><a class="toc-backref" href="#id120">Important Public Members of the <tt class="docutils literal"><span class="pre">Instruction</span></tt> class</a><a class="headerlink" href="#important-public-members-of-the-instruction-class" title="Permalink to this headline">¶</a></h4>
+<ul>
+<li><p class="first"><tt class="docutils literal"><span class="pre">BasicBlock</span> <span class="pre">*getParent()</span></tt></p>
+<p>Returns the <a class="reference internal" href="#basicblock">BasicBlock</a> that this
+<tt class="docutils literal"><span class="pre">Instruction</span></tt> is embedded into.</p>
+</li>
+<li><p class="first"><tt class="docutils literal"><span class="pre">bool</span> <span class="pre">mayWriteToMemory()</span></tt></p>
+<p>Returns true if the instruction writes to memory, i.e. it is a <tt class="docutils literal"><span class="pre">call</span></tt>,
+<tt class="docutils literal"><span class="pre">free</span></tt>, <tt class="docutils literal"><span class="pre">invoke</span></tt>, or <tt class="docutils literal"><span class="pre">store</span></tt>.</p>
+</li>
+<li><p class="first"><tt class="docutils literal"><span class="pre">unsigned</span> <span class="pre">getOpcode()</span></tt></p>
+<p>Returns the opcode for the <tt class="docutils literal"><span class="pre">Instruction</span></tt>.</p>
+</li>
+<li><p class="first"><tt class="docutils literal"><span class="pre">Instruction</span> <span class="pre">*clone()</span> <span class="pre">const</span></tt></p>
+<p>Returns another instance of the specified instruction, identical in all ways
+to the original except that the instruction has no parent (i.e. it’s not
+embedded into a <a class="reference internal" href="#basicblock">BasicBlock</a>), and it has no name.</p>
+</li>
+</ul>
+</div>
+</div>
+<div class="section" id="the-constant-class-and-subclasses">
+<span id="constant"></span><h3><a class="toc-backref" href="#id121">The <tt class="docutils literal"><span class="pre">Constant</span></tt> class and subclasses</a><a class="headerlink" href="#the-constant-class-and-subclasses" title="Permalink to this headline">¶</a></h3>
+<p>Constant represents a base class for different types of constants. It is
+subclassed by ConstantInt, ConstantArray, etc. for representing the various
+types of Constants. <a class="reference internal" href="#globalvalue">GlobalValue</a> is also a subclass, which represents the
+address of a global variable or function.</p>
+<div class="section" id="important-subclasses-of-constant">
+<span id="s-constant"></span><h4><a class="toc-backref" href="#id122">Important Subclasses of Constant</a><a class="headerlink" href="#important-subclasses-of-constant" title="Permalink to this headline">¶</a></h4>
+<ul class="simple">
+<li>ConstantInt : This subclass of Constant represents an integer constant of
+any width.<ul>
+<li><tt class="docutils literal"><span class="pre">const</span> <span class="pre">APInt&</span> <span class="pre">getValue()</span> <span class="pre">const</span></tt>: Returns the underlying
+value of this constant, an APInt value.</li>
+<li><tt class="docutils literal"><span class="pre">int64_t</span> <span class="pre">getSExtValue()</span> <span class="pre">const</span></tt>: Converts the underlying APInt value to an
+int64_t via sign extension. If the value (not the bit width) of the APInt
+is too large to fit in an int64_t, an assertion will result. For this
+reason, use of this method is discouraged.</li>
+<li><tt class="docutils literal"><span class="pre">uint64_t</span> <span class="pre">getZExtValue()</span> <span class="pre">const</span></tt>: Converts the underlying APInt value
+to a uint64_t via zero extension. IF the value (not the bit width) of the
+APInt is too large to fit in a uint64_t, an assertion will result. For this
+reason, use of this method is discouraged.</li>
+<li><tt class="docutils literal"><span class="pre">static</span> <span class="pre">ConstantInt*</span> <span class="pre">get(const</span> <span class="pre">APInt&</span> <span class="pre">Val)</span></tt>: Returns the ConstantInt
+object that represents the value provided by <tt class="docutils literal"><span class="pre">Val</span></tt>. The type is implied
+as the IntegerType that corresponds to the bit width of <tt class="docutils literal"><span class="pre">Val</span></tt>.</li>
+<li><tt class="docutils literal"><span class="pre">static</span> <span class="pre">ConstantInt*</span> <span class="pre">get(const</span> <span class="pre">Type</span> <span class="pre">*Ty,</span> <span class="pre">uint64_t</span> <span class="pre">Val)</span></tt>: Returns the
+ConstantInt object that represents the value provided by <tt class="docutils literal"><span class="pre">Val</span></tt> for integer
+type <tt class="docutils literal"><span class="pre">Ty</span></tt>.</li>
+</ul>
+</li>
+<li>ConstantFP : This class represents a floating point constant.<ul>
+<li><tt class="docutils literal"><span class="pre">double</span> <span class="pre">getValue()</span> <span class="pre">const</span></tt>: Returns the underlying value of this constant.</li>
+</ul>
+</li>
+<li>ConstantArray : This represents a constant array.<ul>
+<li><tt class="docutils literal"><span class="pre">const</span> <span class="pre">std::vector<Use></span> <span class="pre">&getValues()</span> <span class="pre">const</span></tt>: Returns a vector of
+component constants that makeup this array.</li>
+</ul>
+</li>
+<li>ConstantStruct : This represents a constant struct.<ul>
+<li><tt class="docutils literal"><span class="pre">const</span> <span class="pre">std::vector<Use></span> <span class="pre">&getValues()</span> <span class="pre">const</span></tt>: Returns a vector of
+component constants that makeup this array.</li>
+</ul>
+</li>
+<li>GlobalValue : This represents either a global variable or a function. In
+either case, the value is a constant fixed address (after linking).</li>
+</ul>
+</div>
+</div>
+<div class="section" id="the-globalvalue-class">
+<span id="globalvalue"></span><h3><a class="toc-backref" href="#id123">The <tt class="docutils literal"><span class="pre">GlobalValue</span></tt> class</a><a class="headerlink" href="#the-globalvalue-class" title="Permalink to this headline">¶</a></h3>
+<p><tt class="docutils literal"><span class="pre">#include</span> <span class="pre">"llvm/IR/GlobalValue.h"</span></tt></p>
+<p>header source: <a class="reference external" href="http://llvm.org/doxygen/GlobalValue_8h-source.html">GlobalValue.h</a></p>
+<p>doxygen info: <a class="reference external" href="http://llvm.org/doxygen/classllvm_1_1GlobalValue.html">GlobalValue Class</a></p>
+<p>Superclasses: <a class="reference internal" href="#constant">Constant</a>, <a class="reference internal" href="#user">User</a>, <a class="reference internal" href="#value">Value</a></p>
+<p>Global values ( <a class="reference internal" href="#globalvariable">GlobalVariable</a>s or <a class="reference internal" href="#c-function"><em>Function</em></a>s) are the
+only LLVM values that are visible in the bodies of all <a class="reference internal" href="#c-function"><em>Function</em></a>s. Because they are visible at global scope, they are also
+subject to linking with other globals defined in different translation units.
+To control the linking process, <tt class="docutils literal"><span class="pre">GlobalValue</span></tt>s know their linkage rules.
+Specifically, <tt class="docutils literal"><span class="pre">GlobalValue</span></tt>s know whether they have internal or external
+linkage, as defined by the <tt class="docutils literal"><span class="pre">LinkageTypes</span></tt> enumeration.</p>
+<p>If a <tt class="docutils literal"><span class="pre">GlobalValue</span></tt> has internal linkage (equivalent to being <tt class="docutils literal"><span class="pre">static</span></tt> in C),
+it is not visible to code outside the current translation unit, and does not
+participate in linking. If it has external linkage, it is visible to external
+code, and does participate in linking. In addition to linkage information,
+<tt class="docutils literal"><span class="pre">GlobalValue</span></tt>s keep track of which <a class="reference internal" href="#module">Module</a> they are currently part of.</p>
+<p>Because <tt class="docutils literal"><span class="pre">GlobalValue</span></tt>s are memory objects, they are always referred to by
+their <strong>address</strong>. As such, the <a class="reference internal" href="#type">Type</a> of a global is always a pointer to its
+contents. It is important to remember this when using the <tt class="docutils literal"><span class="pre">GetElementPtrInst</span></tt>
+instruction because this pointer must be dereferenced first. For example, if
+you have a <tt class="docutils literal"><span class="pre">GlobalVariable</span></tt> (a subclass of <tt class="docutils literal"><span class="pre">GlobalValue)</span></tt> that is an array
+of 24 ints, type <tt class="docutils literal"><span class="pre">[24</span> <span class="pre">x</span> <span class="pre">i32]</span></tt>, then the <tt class="docutils literal"><span class="pre">GlobalVariable</span></tt> is a pointer to
+that array. Although the address of the first element of this array and the
+value of the <tt class="docutils literal"><span class="pre">GlobalVariable</span></tt> are the same, they have different types. The
+<tt class="docutils literal"><span class="pre">GlobalVariable</span></tt>‘s type is <tt class="docutils literal"><span class="pre">[24</span> <span class="pre">x</span> <span class="pre">i32]</span></tt>. The first element’s type is
+<tt class="docutils literal"><span class="pre">i32.</span></tt> Because of this, accessing a global value requires you to dereference
+the pointer with <tt class="docutils literal"><span class="pre">GetElementPtrInst</span></tt> first, then its elements can be accessed.
+This is explained in the <a class="reference external" href="LangRef.html#globalvars">LLVM Language Reference Manual</a>.</p>
+<div class="section" id="important-public-members-of-the-globalvalue-class">
+<span id="m-globalvalue"></span><h4><a class="toc-backref" href="#id124">Important Public Members of the <tt class="docutils literal"><span class="pre">GlobalValue</span></tt> class</a><a class="headerlink" href="#important-public-members-of-the-globalvalue-class" title="Permalink to this headline">¶</a></h4>
+<ul>
+<li><div class="first line-block">
+<div class="line"><tt class="docutils literal"><span class="pre">bool</span> <span class="pre">hasInternalLinkage()</span> <span class="pre">const</span></tt></div>
+<div class="line"><tt class="docutils literal"><span class="pre">bool</span> <span class="pre">hasExternalLinkage()</span> <span class="pre">const</span></tt></div>
+<div class="line"><tt class="docutils literal"><span class="pre">void</span> <span class="pre">setInternalLinkage(bool</span> <span class="pre">HasInternalLinkage)</span></tt></div>
+</div>
+<p>These methods manipulate the linkage characteristics of the <tt class="docutils literal"><span class="pre">GlobalValue</span></tt>.</p>
+</li>
+<li><p class="first"><tt class="docutils literal"><span class="pre">Module</span> <span class="pre">*getParent()</span></tt></p>
+<p>This returns the <a class="reference internal" href="#module">Module</a> that the
+GlobalValue is currently embedded into.</p>
+</li>
+</ul>
+</div>
+</div>
+<div class="section" id="the-function-class">
+<span id="c-function"></span><h3><a class="toc-backref" href="#id125">The <tt class="docutils literal"><span class="pre">Function</span></tt> class</a><a class="headerlink" href="#the-function-class" title="Permalink to this headline">¶</a></h3>
+<p><tt class="docutils literal"><span class="pre">#include</span> <span class="pre">"llvm/IR/Function.h"</span></tt></p>
+<p>header source: <a class="reference external" href="http://llvm.org/doxygen/Function_8h-source.html">Function.h</a></p>
+<p>doxygen info: <a class="reference external" href="http://llvm.org/doxygen/classllvm_1_1Function.html">Function Class</a></p>
+<p>Superclasses: <a class="reference internal" href="#globalvalue">GlobalValue</a>, <a class="reference internal" href="#constant">Constant</a>, <a class="reference internal" href="#user">User</a>, <a class="reference internal" href="#value">Value</a></p>
+<p>The <tt class="docutils literal"><span class="pre">Function</span></tt> class represents a single procedure in LLVM. It is actually
+one of the more complex classes in the LLVM hierarchy because it must keep track
+of a large amount of data. The <tt class="docutils literal"><span class="pre">Function</span></tt> class keeps track of a list of
+<a class="reference internal" href="#basicblock">BasicBlock</a>s, a list of formal <a class="reference internal" href="#argument">Argument</a>s, and a <a class="reference internal" href="#symboltable">SymbolTable</a>.</p>
+<p>The list of <a class="reference internal" href="#basicblock">BasicBlock</a>s is the most commonly used part of <tt class="docutils literal"><span class="pre">Function</span></tt>
+objects. The list imposes an implicit ordering of the blocks in the function,
+which indicate how the code will be laid out by the backend. Additionally, the
+first <a class="reference internal" href="#basicblock">BasicBlock</a> is the implicit entry node for the <tt class="docutils literal"><span class="pre">Function</span></tt>. It is not
+legal in LLVM to explicitly branch to this initial block. There are no implicit
+exit nodes, and in fact there may be multiple exit nodes from a single
+<tt class="docutils literal"><span class="pre">Function</span></tt>. If the <a class="reference internal" href="#basicblock">BasicBlock</a> list is empty, this indicates that the
+<tt class="docutils literal"><span class="pre">Function</span></tt> is actually a function declaration: the actual body of the function
+hasn’t been linked in yet.</p>
+<p>In addition to a list of <a class="reference internal" href="#basicblock">BasicBlock</a>s, the <tt class="docutils literal"><span class="pre">Function</span></tt> class also keeps track
+of the list of formal <a class="reference internal" href="#argument">Argument</a>s that the function receives. This container
+manages the lifetime of the <a class="reference internal" href="#argument">Argument</a> nodes, just like the <a class="reference internal" href="#basicblock">BasicBlock</a> list does
+for the <a class="reference internal" href="#basicblock">BasicBlock</a>s.</p>
+<p>The <a class="reference internal" href="#symboltable">SymbolTable</a> is a very rarely used LLVM feature that is only used when you
+have to look up a value by name. Aside from that, the <a class="reference internal" href="#symboltable">SymbolTable</a> is used
+internally to make sure that there are not conflicts between the names of
+<a class="reference internal" href="#instruction">Instruction</a>s, <a class="reference internal" href="#basicblock">BasicBlock</a>s, or <a class="reference internal" href="#argument">Argument</a>s in the function body.</p>
+<p>Note that <tt class="docutils literal"><span class="pre">Function</span></tt> is a <a class="reference internal" href="#globalvalue">GlobalValue</a> and therefore also a <a class="reference internal" href="#constant">Constant</a>. The
+value of the function is its address (after linking) which is guaranteed to be
+constant.</p>
+<div class="section" id="important-public-members-of-the-function">
+<span id="m-function"></span><h4><a class="toc-backref" href="#id126">Important Public Members of the <tt class="docutils literal"><span class="pre">Function</span></tt></a><a class="headerlink" href="#important-public-members-of-the-function" title="Permalink to this headline">¶</a></h4>
+<ul>
+<li><p class="first"><tt class="docutils literal"><span class="pre">Function(const</span> <span class="pre">FunctionType</span> <span class="pre">*Ty,</span> <span class="pre">LinkageTypes</span> <span class="pre">Linkage,</span>
+<span class="pre">const</span> <span class="pre">std::string</span> <span class="pre">&N</span> <span class="pre">=</span> <span class="pre">"",</span> <span class="pre">Module*</span> <span class="pre">Parent</span> <span class="pre">=</span> <span class="pre">0)</span></tt></p>
+<p>Constructor used when you need to create new <tt class="docutils literal"><span class="pre">Function</span></tt>s to add the
+program. The constructor must specify the type of the function to create and
+what type of linkage the function should have. The <a class="reference internal" href="#functiontype">FunctionType</a> argument
+specifies the formal arguments and return value for the function. The same
+<a class="reference internal" href="#functiontype">FunctionType</a> value can be used to create multiple functions. The <tt class="docutils literal"><span class="pre">Parent</span></tt>
+argument specifies the Module in which the function is defined. If this
+argument is provided, the function will automatically be inserted into that
+module’s list of functions.</p>
+</li>
+<li><p class="first"><tt class="docutils literal"><span class="pre">bool</span> <span class="pre">isDeclaration()</span></tt></p>
+<p>Return whether or not the <tt class="docutils literal"><span class="pre">Function</span></tt> has a body defined. If the function is
+“external”, it does not have a body, and thus must be resolved by linking with
+a function defined in a different translation unit.</p>
+</li>
+<li><div class="first line-block">
+<div class="line"><tt class="docutils literal"><span class="pre">Function::iterator</span></tt> - Typedef for basic block list iterator</div>
+<div class="line"><tt class="docutils literal"><span class="pre">Function::const_iterator</span></tt> - Typedef for const_iterator.</div>
+<div class="line"><tt class="docutils literal"><span class="pre">begin()</span></tt>, <tt class="docutils literal"><span class="pre">end()</span></tt>, <tt class="docutils literal"><span class="pre">size()</span></tt>, <tt class="docutils literal"><span class="pre">empty()</span></tt></div>
+</div>
+<p>These are forwarding methods that make it easy to access the contents of a
+<tt class="docutils literal"><span class="pre">Function</span></tt> object’s <a class="reference internal" href="#basicblock">BasicBlock</a> list.</p>
+</li>
+<li><p class="first"><tt class="docutils literal"><span class="pre">Function::BasicBlockListType</span> <span class="pre">&getBasicBlockList()</span></tt></p>
+<p>Returns the list of <a class="reference internal" href="#basicblock">BasicBlock</a>s. This is necessary to use when you need to
+update the list or perform a complex action that doesn’t have a forwarding
+method.</p>
+</li>
+<li><div class="first line-block">
+<div class="line"><tt class="docutils literal"><span class="pre">Function::arg_iterator</span></tt> - Typedef for the argument list iterator</div>
+<div class="line"><tt class="docutils literal"><span class="pre">Function::const_arg_iterator</span></tt> - Typedef for const_iterator.</div>
+<div class="line"><tt class="docutils literal"><span class="pre">arg_begin()</span></tt>, <tt class="docutils literal"><span class="pre">arg_end()</span></tt>, <tt class="docutils literal"><span class="pre">arg_size()</span></tt>, <tt class="docutils literal"><span class="pre">arg_empty()</span></tt></div>
+</div>
+<p>These are forwarding methods that make it easy to access the contents of a
+<tt class="docutils literal"><span class="pre">Function</span></tt> object’s <a class="reference internal" href="#argument">Argument</a> list.</p>
+</li>
+<li><p class="first"><tt class="docutils literal"><span class="pre">Function::ArgumentListType</span> <span class="pre">&getArgumentList()</span></tt></p>
+<p>Returns the list of <a class="reference internal" href="#argument">Argument</a>. This is necessary to use when you need to
+update the list or perform a complex action that doesn’t have a forwarding
+method.</p>
+</li>
+<li><p class="first"><tt class="docutils literal"><span class="pre">BasicBlock</span> <span class="pre">&getEntryBlock()</span></tt></p>
+<p>Returns the entry <tt class="docutils literal"><span class="pre">BasicBlock</span></tt> for the function. Because the entry block
+for the function is always the first block, this returns the first block of
+the <tt class="docutils literal"><span class="pre">Function</span></tt>.</p>
+</li>
+<li><div class="first line-block">
+<div class="line"><tt class="docutils literal"><span class="pre">Type</span> <span class="pre">*getReturnType()</span></tt></div>
+<div class="line"><tt class="docutils literal"><span class="pre">FunctionType</span> <span class="pre">*getFunctionType()</span></tt></div>
+</div>
+<p>This traverses the <a class="reference internal" href="#type">Type</a> of the <tt class="docutils literal"><span class="pre">Function</span></tt> and returns the return type of
+the function, or the <a class="reference internal" href="#functiontype">FunctionType</a> of the actual function.</p>
+</li>
+<li><p class="first"><tt class="docutils literal"><span class="pre">SymbolTable</span> <span class="pre">*getSymbolTable()</span></tt></p>
+<p>Return a pointer to the <a class="reference internal" href="#symboltable">SymbolTable</a> for this <tt class="docutils literal"><span class="pre">Function</span></tt>.</p>
+</li>
+</ul>
+</div>
+</div>
+<div class="section" id="the-globalvariable-class">
+<span id="globalvariable"></span><h3><a class="toc-backref" href="#id127">The <tt class="docutils literal"><span class="pre">GlobalVariable</span></tt> class</a><a class="headerlink" href="#the-globalvariable-class" title="Permalink to this headline">¶</a></h3>
+<p><tt class="docutils literal"><span class="pre">#include</span> <span class="pre">"llvm/IR/GlobalVariable.h"</span></tt></p>
+<p>header source: <a class="reference external" href="http://llvm.org/doxygen/GlobalVariable_8h-source.html">GlobalVariable.h</a></p>
+<p>doxygen info: <a class="reference external" href="http://llvm.org/doxygen/classllvm_1_1GlobalVariable.html">GlobalVariable Class</a></p>
+<p>Superclasses: <a class="reference internal" href="#globalvalue">GlobalValue</a>, <a class="reference internal" href="#constant">Constant</a>, <a class="reference internal" href="#user">User</a>, <a class="reference internal" href="#value">Value</a></p>
+<p>Global variables are represented with the (surprise surprise) <tt class="docutils literal"><span class="pre">GlobalVariable</span></tt>
+class. Like functions, <tt class="docutils literal"><span class="pre">GlobalVariable</span></tt>s are also subclasses of
+<a class="reference internal" href="#globalvalue">GlobalValue</a>, and as such are always referenced by their address (global values
+must live in memory, so their “name” refers to their constant address). See
+<a class="reference internal" href="#globalvalue">GlobalValue</a> for more on this. Global variables may have an initial value
+(which must be a <a class="reference internal" href="#constant">Constant</a>), and if they have an initializer, they may be marked
+as “constant” themselves (indicating that their contents never change at
+runtime).</p>
+<div class="section" id="important-public-members-of-the-globalvariable-class">
+<span id="m-globalvariable"></span><h4><a class="toc-backref" href="#id128">Important Public Members of the <tt class="docutils literal"><span class="pre">GlobalVariable</span></tt> class</a><a class="headerlink" href="#important-public-members-of-the-globalvariable-class" title="Permalink to this headline">¶</a></h4>
+<ul>
+<li><p class="first"><tt class="docutils literal"><span class="pre">GlobalVariable(const</span> <span class="pre">Type</span> <span class="pre">*Ty,</span> <span class="pre">bool</span> <span class="pre">isConstant,</span> <span class="pre">LinkageTypes</span> <span class="pre">&Linkage,</span>
+<span class="pre">Constant</span> <span class="pre">*Initializer</span> <span class="pre">=</span> <span class="pre">0,</span> <span class="pre">const</span> <span class="pre">std::string</span> <span class="pre">&Name</span> <span class="pre">=</span> <span class="pre">"",</span> <span class="pre">Module*</span> <span class="pre">Parent</span> <span class="pre">=</span> <span class="pre">0)</span></tt></p>
+<p>Create a new global variable of the specified type. If <tt class="docutils literal"><span class="pre">isConstant</span></tt> is true
+then the global variable will be marked as unchanging for the program. The
+Linkage parameter specifies the type of linkage (internal, external, weak,
+linkonce, appending) for the variable. If the linkage is InternalLinkage,
+WeakAnyLinkage, WeakODRLinkage, LinkOnceAnyLinkage or LinkOnceODRLinkage, then
+the resultant global variable will have internal linkage. AppendingLinkage
+concatenates together all instances (in different translation units) of the
+variable into a single variable but is only applicable to arrays. See the
+<a class="reference external" href="LangRef.html#modulestructure">LLVM Language Reference</a> for further details
+on linkage types. Optionally an initializer, a name, and the module to put
+the variable into may be specified for the global variable as well.</p>
+</li>
+<li><p class="first"><tt class="docutils literal"><span class="pre">bool</span> <span class="pre">isConstant()</span> <span class="pre">const</span></tt></p>
+<p>Returns true if this is a global variable that is known not to be modified at
+runtime.</p>
+</li>
+<li><p class="first"><tt class="docutils literal"><span class="pre">bool</span> <span class="pre">hasInitializer()</span></tt></p>
+<p>Returns true if this <tt class="docutils literal"><span class="pre">GlobalVariable</span></tt> has an intializer.</p>
+</li>
+<li><p class="first"><tt class="docutils literal"><span class="pre">Constant</span> <span class="pre">*getInitializer()</span></tt></p>
+<p>Returns the initial value for a <tt class="docutils literal"><span class="pre">GlobalVariable</span></tt>. It is not legal to call
+this method if there is no initializer.</p>
+</li>
+</ul>
+</div>
+</div>
+<div class="section" id="the-basicblock-class">
+<span id="basicblock"></span><h3><a class="toc-backref" href="#id129">The <tt class="docutils literal"><span class="pre">BasicBlock</span></tt> class</a><a class="headerlink" href="#the-basicblock-class" title="Permalink to this headline">¶</a></h3>
+<p><tt class="docutils literal"><span class="pre">#include</span> <span class="pre">"llvm/IR/BasicBlock.h"</span></tt></p>
+<p>header source: <a class="reference external" href="http://llvm.org/doxygen/BasicBlock_8h-source.html">BasicBlock.h</a></p>
+<p>doxygen info: <a class="reference external" href="http://llvm.org/doxygen/classllvm_1_1BasicBlock.html">BasicBlock Class</a></p>
+<p>Superclass: <a class="reference internal" href="#value">Value</a></p>
+<p>This class represents a single entry single exit section of the code, commonly
+known as a basic block by the compiler community. The <tt class="docutils literal"><span class="pre">BasicBlock</span></tt> class
+maintains a list of <a class="reference internal" href="#instruction">Instruction</a>s, which form the body of the block. Matching
+the language definition, the last element of this list of instructions is always
+a terminator instruction (a subclass of the <a class="reference internal" href="#terminatorinst">TerminatorInst</a> class).</p>
+<p>In addition to tracking the list of instructions that make up the block, the
+<tt class="docutils literal"><span class="pre">BasicBlock</span></tt> class also keeps track of the <a class="reference internal" href="#c-function"><em>Function</em></a> that
+it is embedded into.</p>
+<p>Note that <tt class="docutils literal"><span class="pre">BasicBlock</span></tt>s themselves are <a class="reference internal" href="#value">Value</a>s, because they are
+referenced by instructions like branches and can go in the switch tables.
+<tt class="docutils literal"><span class="pre">BasicBlock</span></tt>s have type <tt class="docutils literal"><span class="pre">label</span></tt>.</p>
+<div class="section" id="important-public-members-of-the-basicblock-class">
+<span id="m-basicblock"></span><h4><a class="toc-backref" href="#id130">Important Public Members of the <tt class="docutils literal"><span class="pre">BasicBlock</span></tt> class</a><a class="headerlink" href="#important-public-members-of-the-basicblock-class" title="Permalink to this headline">¶</a></h4>
+<ul>
+<li><p class="first"><tt class="docutils literal"><span class="pre">BasicBlock(const</span> <span class="pre">std::string</span> <span class="pre">&Name</span> <span class="pre">=</span> <span class="pre">"",</span> <span class="pre">Function</span> <span class="pre">*Parent</span> <span class="pre">=</span> <span class="pre">0)</span></tt></p>
+<p>The <tt class="docutils literal"><span class="pre">BasicBlock</span></tt> constructor is used to create new basic blocks for
+insertion into a function. The constructor optionally takes a name for the
+new block, and a <a class="reference internal" href="#c-function"><em>Function</em></a> to insert it into. If the
+<tt class="docutils literal"><span class="pre">Parent</span></tt> parameter is specified, the new <tt class="docutils literal"><span class="pre">BasicBlock</span></tt> is automatically
+inserted at the end of the specified <a class="reference internal" href="#c-function"><em>Function</em></a>, if not
+specified, the BasicBlock must be manually inserted into the <a class="reference internal" href="#c-function"><em>Function</em></a>.</p>
+</li>
+<li><div class="first line-block">
+<div class="line"><tt class="docutils literal"><span class="pre">BasicBlock::iterator</span></tt> - Typedef for instruction list iterator</div>
+<div class="line"><tt class="docutils literal"><span class="pre">BasicBlock::const_iterator</span></tt> - Typedef for const_iterator.</div>
+<div class="line"><tt class="docutils literal"><span class="pre">begin()</span></tt>, <tt class="docutils literal"><span class="pre">end()</span></tt>, <tt class="docutils literal"><span class="pre">front()</span></tt>, <tt class="docutils literal"><span class="pre">back()</span></tt>,
+<tt class="docutils literal"><span class="pre">size()</span></tt>, <tt class="docutils literal"><span class="pre">empty()</span></tt>
+STL-style functions for accessing the instruction list.</div>
+</div>
+<p>These methods and typedefs are forwarding functions that have the same
+semantics as the standard library methods of the same names. These methods
+expose the underlying instruction list of a basic block in a way that is easy
+to manipulate. To get the full complement of container operations (including
+operations to update the list), you must use the <tt class="docutils literal"><span class="pre">getInstList()</span></tt> method.</p>
+</li>
+<li><p class="first"><tt class="docutils literal"><span class="pre">BasicBlock::InstListType</span> <span class="pre">&getInstList()</span></tt></p>
+<p>This method is used to get access to the underlying container that actually
+holds the Instructions. This method must be used when there isn’t a
+forwarding function in the <tt class="docutils literal"><span class="pre">BasicBlock</span></tt> class for the operation that you
+would like to perform. Because there are no forwarding functions for
+“updating” operations, you need to use this if you want to update the contents
+of a <tt class="docutils literal"><span class="pre">BasicBlock</span></tt>.</p>
+</li>
+<li><p class="first"><tt class="docutils literal"><span class="pre">Function</span> <span class="pre">*getParent()</span></tt></p>
+<p>Returns a pointer to <a class="reference internal" href="#c-function"><em>Function</em></a> the block is embedded into,
+or a null pointer if it is homeless.</p>
+</li>
+<li><p class="first"><tt class="docutils literal"><span class="pre">TerminatorInst</span> <span class="pre">*getTerminator()</span></tt></p>
+<p>Returns a pointer to the terminator instruction that appears at the end of the
+<tt class="docutils literal"><span class="pre">BasicBlock</span></tt>. If there is no terminator instruction, or if the last
+instruction in the block is not a terminator, then a null pointer is returned.</p>
+</li>
+</ul>
+</div>
+</div>
+<div class="section" id="the-argument-class">
+<span id="argument"></span><h3><a class="toc-backref" href="#id131">The <tt class="docutils literal"><span class="pre">Argument</span></tt> class</a><a class="headerlink" href="#the-argument-class" title="Permalink to this headline">¶</a></h3>
+<p>This subclass of Value defines the interface for incoming formal arguments to a
+function. A Function maintains a list of its formal arguments. An argument has
+a pointer to the parent Function.</p>
+</div>
+</div>
+</div>
+
+
+ </div>
+ </div>
+ <div class="clearer"></div>
+ </div>
+ <div class="related">
+ <h3>Navigation</h3>
+ <ul>
+ <li class="right" style="margin-right: 10px">
+ <a href="genindex.html" title="General Index"
+ >index</a></li>
+ <li class="right" >
+ <a href="Extensions.html" title="LLVM Extensions"
+ >next</a> |</li>
+ <li class="right" >
+ <a href="HowToSetUpLLVMStyleRTTI.html" title="How to set up LLVM-style RTTI for your class hierarchy"
+ >previous</a> |</li>
+ <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+ <li><a href="index.html">Documentation</a>»</li>
+
+ </ul>
+ </div>
+ <div class="footer">
+ © Copyright 2003-2016, LLVM Project.
+ Last updated on 2016-01-04.
+ Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.3.
+ </div>
+ </body>
+</html>
\ No newline at end of file
Added: www-releases/trunk/3.7.1/docs/Projects.html
URL: http://llvm.org/viewvc/llvm-project/www-releases/trunk/3.7.1/docs/Projects.html?rev=257950&view=auto
==============================================================================
--- www-releases/trunk/3.7.1/docs/Projects.html (added)
+++ www-releases/trunk/3.7.1/docs/Projects.html Fri Jan 15 17:13:16 2016
@@ -0,0 +1,337 @@
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
+ <title>Creating an LLVM Project — LLVM 3.7 documentation</title>
+
+ <link rel="stylesheet" href="_static/llvm-theme.css" type="text/css" />
+ <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
+
+ <script type="text/javascript">
+ var DOCUMENTATION_OPTIONS = {
+ URL_ROOT: './',
+ VERSION: '3.7',
+ COLLAPSE_INDEX: false,
+ FILE_SUFFIX: '.html',
+ HAS_SOURCE: true
+ };
+ </script>
+ <script type="text/javascript" src="_static/jquery.js"></script>
+ <script type="text/javascript" src="_static/underscore.js"></script>
+ <script type="text/javascript" src="_static/doctools.js"></script>
+ <link rel="top" title="LLVM 3.7 documentation" href="index.html" />
+ <link rel="next" title="LLVMBuild Guide" href="LLVMBuild.html" />
+ <link rel="prev" title="LLVM Makefile Guide" href="MakefileGuide.html" />
+<style type="text/css">
+ table.right { float: right; margin-left: 20px; }
+ table.right td { border: 1px solid #ccc; }
+</style>
+
+ </head>
+ <body>
+<div class="logo">
+ <a href="index.html">
+ <img src="_static/logo.png"
+ alt="LLVM Logo" width="250" height="88"/></a>
+</div>
+
+ <div class="related">
+ <h3>Navigation</h3>
+ <ul>
+ <li class="right" style="margin-right: 10px">
+ <a href="genindex.html" title="General Index"
+ accesskey="I">index</a></li>
+ <li class="right" >
+ <a href="LLVMBuild.html" title="LLVMBuild Guide"
+ accesskey="N">next</a> |</li>
+ <li class="right" >
+ <a href="MakefileGuide.html" title="LLVM Makefile Guide"
+ accesskey="P">previous</a> |</li>
+ <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+ <li><a href="index.html">Documentation</a>»</li>
+
+ </ul>
+ </div>
+
+
+ <div class="document">
+ <div class="documentwrapper">
+ <div class="body">
+
+ <div class="section" id="creating-an-llvm-project">
+<h1>Creating an LLVM Project<a class="headerlink" href="#creating-an-llvm-project" title="Permalink to this headline">¶</a></h1>
+<div class="contents local topic" id="contents">
+<ul class="simple">
+<li><a class="reference internal" href="#overview" id="id1">Overview</a></li>
+<li><a class="reference internal" href="#source-tree-layout" id="id2">Source Tree Layout</a></li>
+<li><a class="reference internal" href="#writing-llvm-style-makefiles" id="id3">Writing LLVM Style Makefiles</a><ul>
+<li><a class="reference internal" href="#required-variables" id="id4">Required Variables</a></li>
+<li><a class="reference internal" href="#variables-for-building-subdirectories" id="id5">Variables for Building Subdirectories</a></li>
+<li><a class="reference internal" href="#variables-for-building-libraries" id="id6">Variables for Building Libraries</a></li>
+<li><a class="reference internal" href="#variables-for-building-programs" id="id7">Variables for Building Programs</a></li>
+<li><a class="reference internal" href="#miscellaneous-variables" id="id8">Miscellaneous Variables</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#placement-of-object-code" id="id9">Placement of Object Code</a></li>
+<li><a class="reference internal" href="#further-help" id="id10">Further Help</a></li>
+</ul>
+</div>
+<div class="section" id="overview">
+<h2><a class="toc-backref" href="#id1">Overview</a><a class="headerlink" href="#overview" title="Permalink to this headline">¶</a></h2>
+<p>The LLVM build system is designed to facilitate the building of third party
+projects that use LLVM header files, libraries, and tools. In order to use
+these facilities, a <tt class="docutils literal"><span class="pre">Makefile</span></tt> from a project must do the following things:</p>
+<ul class="simple">
+<li>Set <tt class="docutils literal"><span class="pre">make</span></tt> variables. There are several variables that a <tt class="docutils literal"><span class="pre">Makefile</span></tt> needs
+to set to use the LLVM build system:<ul>
+<li><tt class="docutils literal"><span class="pre">PROJECT_NAME</span></tt> - The name by which your project is known.</li>
+<li><tt class="docutils literal"><span class="pre">LLVM_SRC_ROOT</span></tt> - The root of the LLVM source tree.</li>
+<li><tt class="docutils literal"><span class="pre">LLVM_OBJ_ROOT</span></tt> - The root of the LLVM object tree.</li>
+<li><tt class="docutils literal"><span class="pre">PROJ_SRC_ROOT</span></tt> - The root of the project’s source tree.</li>
+<li><tt class="docutils literal"><span class="pre">PROJ_OBJ_ROOT</span></tt> - The root of the project’s object tree.</li>
+<li><tt class="docutils literal"><span class="pre">PROJ_INSTALL_ROOT</span></tt> - The root installation directory.</li>
+<li><tt class="docutils literal"><span class="pre">LEVEL</span></tt> - The relative path from the current directory to the
+project’s root <tt class="docutils literal"><span class="pre">($PROJ_OBJ_ROOT)</span></tt>.</li>
+</ul>
+</li>
+<li>Include <tt class="docutils literal"><span class="pre">Makefile.config</span></tt> from <tt class="docutils literal"><span class="pre">$(LLVM_OBJ_ROOT)</span></tt>.</li>
+<li>Include <tt class="docutils literal"><span class="pre">Makefile.rules</span></tt> from <tt class="docutils literal"><span class="pre">$(LLVM_SRC_ROOT)</span></tt>.</li>
+</ul>
+<p>There are two ways that you can set all of these variables:</p>
+<ul class="simple">
+<li>You can write your own <tt class="docutils literal"><span class="pre">Makefiles</span></tt> which hard-code these values.</li>
+<li>You can use the pre-made LLVM sample project. This sample project includes
+<tt class="docutils literal"><span class="pre">Makefiles</span></tt>, a configure script that can be used to configure the location
+of LLVM, and the ability to support multiple object directories from a single
+source directory.</li>
+</ul>
+<p>If you want to devise your own build system, studying other projects and LLVM
+<tt class="docutils literal"><span class="pre">Makefiles</span></tt> will probably provide enough information on how to write your own
+<tt class="docutils literal"><span class="pre">Makefiles</span></tt>.</p>
+</div>
+<div class="section" id="source-tree-layout">
+<h2><a class="toc-backref" href="#id2">Source Tree Layout</a><a class="headerlink" href="#source-tree-layout" title="Permalink to this headline">¶</a></h2>
+<p>In order to use the LLVM build system, you will want to organize your source
+code so that it can benefit from the build system’s features. Mainly, you want
+your source tree layout to look similar to the LLVM source tree layout.</p>
+<p>Underneath your top level directory, you should have the following directories:</p>
+<p><strong>lib</strong></p>
+<blockquote>
+<div><p>This subdirectory should contain all of your library source code. For each
+library that you build, you will have one directory in <strong>lib</strong> that will
+contain that library’s source code.</p>
+<p>Libraries can be object files, archives, or dynamic libraries. The <strong>lib</strong>
+directory is just a convenient place for libraries as it places them all in
+a directory from which they can be linked later.</p>
+</div></blockquote>
+<p><strong>include</strong></p>
+<blockquote>
+<div><p>This subdirectory should contain any header files that are global to your
+project. By global, we mean that they are used by more than one library or
+executable of your project.</p>
+<p>By placing your header files in <strong>include</strong>, they will be found
+automatically by the LLVM build system. For example, if you have a file
+<strong>include/jazz/note.h</strong>, then your source files can include it simply with
+<strong>#include “jazz/note.h”</strong>.</p>
+</div></blockquote>
+<p><strong>tools</strong></p>
+<blockquote>
+<div>This subdirectory should contain all of your source code for executables.
+For each program that you build, you will have one directory in <strong>tools</strong>
+that will contain that program’s source code.</div></blockquote>
+<p><strong>test</strong></p>
+<blockquote>
+<div><p>This subdirectory should contain tests that verify that your code works
+correctly. Automated tests are especially useful.</p>
+<p>Currently, the LLVM build system provides basic support for tests. The LLVM
+system provides the following:</p>
+</div></blockquote>
+<ul>
+<li><p class="first">LLVM contains regression tests in <tt class="docutils literal"><span class="pre">llvm/test</span></tt>. These tests are run by the
+<a class="reference internal" href="CommandGuide/lit.html"><em>Lit</em></a> testing tool. This test procedure uses <tt class="docutils literal"><span class="pre">RUN</span></tt>
+lines in the actual test case to determine how to run the test. See the
+<a class="reference internal" href="TestingGuide.html"><em>LLVM Testing Infrastructure Guide</em></a> for more details.</p>
+</li>
+<li><p class="first">LLVM contains an optional package called <tt class="docutils literal"><span class="pre">llvm-test</span></tt>, which provides
+benchmarks and programs that are known to compile with the Clang front
+end. You can use these programs to test your code, gather statistical
+information, and compare it to the current LLVM performance statistics.</p>
+<p>Currently, there is no way to hook your tests directly into the <tt class="docutils literal"><span class="pre">llvm/test</span></tt>
+testing harness. You will simply need to find a way to use the source
+provided within that directory on your own.</p>
+</li>
+</ul>
+<p>Typically, you will want to build your <strong>lib</strong> directory first followed by your
+<strong>tools</strong> directory.</p>
+</div>
+<div class="section" id="writing-llvm-style-makefiles">
+<h2><a class="toc-backref" href="#id3">Writing LLVM Style Makefiles</a><a class="headerlink" href="#writing-llvm-style-makefiles" title="Permalink to this headline">¶</a></h2>
+<p>The LLVM build system provides a convenient way to build libraries and
+executables. Most of your project Makefiles will only need to define a few
+variables. Below is a list of the variables one can set and what they can
+do:</p>
+<div class="section" id="required-variables">
+<h3><a class="toc-backref" href="#id4">Required Variables</a><a class="headerlink" href="#required-variables" title="Permalink to this headline">¶</a></h3>
+<p><tt class="docutils literal"><span class="pre">LEVEL</span></tt></p>
+<blockquote>
+<div>This variable is the relative path from this <tt class="docutils literal"><span class="pre">Makefile</span></tt> to the top
+directory of your project’s source code. For example, if your source code
+is in <tt class="docutils literal"><span class="pre">/tmp/src</span></tt>, then the <tt class="docutils literal"><span class="pre">Makefile</span></tt> in <tt class="docutils literal"><span class="pre">/tmp/src/jump/high</span></tt>
+would set <tt class="docutils literal"><span class="pre">LEVEL</span></tt> to <tt class="docutils literal"><span class="pre">"../.."</span></tt>.</div></blockquote>
+</div>
+<div class="section" id="variables-for-building-subdirectories">
+<h3><a class="toc-backref" href="#id5">Variables for Building Subdirectories</a><a class="headerlink" href="#variables-for-building-subdirectories" title="Permalink to this headline">¶</a></h3>
+<p><tt class="docutils literal"><span class="pre">DIRS</span></tt></p>
+<blockquote>
+<div>This is a space separated list of subdirectories that should be built. They
+will be built, one at a time, in the order specified.</div></blockquote>
+<p><tt class="docutils literal"><span class="pre">PARALLEL_DIRS</span></tt></p>
+<blockquote>
+<div>This is a list of directories that can be built in parallel. These will be
+built after the directories in DIRS have been built.</div></blockquote>
+<p><tt class="docutils literal"><span class="pre">OPTIONAL_DIRS</span></tt></p>
+<blockquote>
+<div>This is a list of directories that can be built if they exist, but will not
+cause an error if they do not exist. They are built serially in the order
+in which they are listed.</div></blockquote>
+</div>
+<div class="section" id="variables-for-building-libraries">
+<h3><a class="toc-backref" href="#id6">Variables for Building Libraries</a><a class="headerlink" href="#variables-for-building-libraries" title="Permalink to this headline">¶</a></h3>
+<p><tt class="docutils literal"><span class="pre">LIBRARYNAME</span></tt></p>
+<blockquote>
+<div>This variable contains the base name of the library that will be built. For
+example, to build a library named <tt class="docutils literal"><span class="pre">libsample.a</span></tt>, <tt class="docutils literal"><span class="pre">LIBRARYNAME</span></tt> should
+be set to <tt class="docutils literal"><span class="pre">sample</span></tt>.</div></blockquote>
+<p><tt class="docutils literal"><span class="pre">BUILD_ARCHIVE</span></tt></p>
+<blockquote>
+<div>By default, a library is a <tt class="docutils literal"><span class="pre">.o</span></tt> file that is linked directly into a
+program. To build an archive (also known as a static library), set the
+<tt class="docutils literal"><span class="pre">BUILD_ARCHIVE</span></tt> variable.</div></blockquote>
+<p><tt class="docutils literal"><span class="pre">SHARED_LIBRARY</span></tt></p>
+<blockquote>
+<div>If <tt class="docutils literal"><span class="pre">SHARED_LIBRARY</span></tt> is defined in your Makefile, a shared (or dynamic)
+library will be built.</div></blockquote>
+</div>
+<div class="section" id="variables-for-building-programs">
+<h3><a class="toc-backref" href="#id7">Variables for Building Programs</a><a class="headerlink" href="#variables-for-building-programs" title="Permalink to this headline">¶</a></h3>
+<p><tt class="docutils literal"><span class="pre">TOOLNAME</span></tt></p>
+<blockquote>
+<div>This variable contains the name of the program that will be built. For
+example, to build an executable named <tt class="docutils literal"><span class="pre">sample</span></tt>, <tt class="docutils literal"><span class="pre">TOOLNAME</span></tt> should be set
+to <tt class="docutils literal"><span class="pre">sample</span></tt>.</div></blockquote>
+<p><tt class="docutils literal"><span class="pre">USEDLIBS</span></tt></p>
+<blockquote>
+<div><p>This variable holds a space separated list of libraries that should be
+linked into the program. These libraries must be libraries that come from
+your <strong>lib</strong> directory. The libraries must be specified without their
+<tt class="docutils literal"><span class="pre">lib</span></tt> prefix. For example, to link <tt class="docutils literal"><span class="pre">libsample.a</span></tt>, you would set
+<tt class="docutils literal"><span class="pre">USEDLIBS</span></tt> to <tt class="docutils literal"><span class="pre">sample.a</span></tt>.</p>
+<p>Note that this works only for statically linked libraries.</p>
+</div></blockquote>
+<p><tt class="docutils literal"><span class="pre">LLVMLIBS</span></tt></p>
+<blockquote>
+<div><p>This variable holds a space separated list of libraries that should be
+linked into the program. These libraries must be LLVM libraries. The
+libraries must be specified without their <tt class="docutils literal"><span class="pre">lib</span></tt> prefix. For example, to
+link with a driver that performs an IR transformation you might set
+<tt class="docutils literal"><span class="pre">LLVMLIBS</span></tt> to this minimal set of libraries <tt class="docutils literal"><span class="pre">LLVMSupport.a</span> <span class="pre">LLVMCore.a</span>
+<span class="pre">LLVMBitReader.a</span> <span class="pre">LLVMAsmParser.a</span> <span class="pre">LLVMAnalysis.a</span> <span class="pre">LLVMTransformUtils.a</span>
+<span class="pre">LLVMScalarOpts.a</span> <span class="pre">LLVMTarget.a</span></tt>.</p>
+<p>Note that this works only for statically linked libraries. LLVM is split
+into a large number of static libraries, and the list of libraries you
+require may be much longer than the list above. To see a full list of
+libraries use: <tt class="docutils literal"><span class="pre">llvm-config</span> <span class="pre">--libs</span> <span class="pre">all</span></tt>. Using <tt class="docutils literal"><span class="pre">LINK_COMPONENTS</span></tt> as
+described below, obviates the need to set <tt class="docutils literal"><span class="pre">LLVMLIBS</span></tt>.</p>
+</div></blockquote>
+<p><tt class="docutils literal"><span class="pre">LINK_COMPONENTS</span></tt></p>
+<blockquote>
+<div>This variable holds a space separated list of components that the LLVM
+<tt class="docutils literal"><span class="pre">Makefiles</span></tt> pass to the <tt class="docutils literal"><span class="pre">llvm-config</span></tt> tool to generate a link line for
+the program. For example, to link with all LLVM libraries use
+<tt class="docutils literal"><span class="pre">LINK_COMPONENTS</span> <span class="pre">=</span> <span class="pre">all</span></tt>.</div></blockquote>
+<p><tt class="docutils literal"><span class="pre">LIBS</span></tt></p>
+<blockquote>
+<div><p>To link dynamic libraries, add <tt class="docutils literal"><span class="pre">-l<library</span> <span class="pre">base</span> <span class="pre">name></span></tt> to the <tt class="docutils literal"><span class="pre">LIBS</span></tt>
+variable. The LLVM build system will look in the same places for dynamic
+libraries as it does for static libraries.</p>
+<p>For example, to link <tt class="docutils literal"><span class="pre">libsample.so</span></tt>, you would have the following line in
+your <tt class="docutils literal"><span class="pre">Makefile</span></tt>:</p>
+<blockquote>
+<div><div class="highlight-makefile"><div class="highlight"><pre><span class="nv">LIBS</span> <span class="o">+=</span> -lsample
+</pre></div>
+</div>
+</div></blockquote>
+</div></blockquote>
+<p>Note that <tt class="docutils literal"><span class="pre">LIBS</span></tt> must occur in the Makefile after the inclusion of
+<tt class="docutils literal"><span class="pre">Makefile.common</span></tt>.</p>
+</div>
+<div class="section" id="miscellaneous-variables">
+<h3><a class="toc-backref" href="#id8">Miscellaneous Variables</a><a class="headerlink" href="#miscellaneous-variables" title="Permalink to this headline">¶</a></h3>
+<p><tt class="docutils literal"><span class="pre">CFLAGS</span></tt> & <tt class="docutils literal"><span class="pre">CPPFLAGS</span></tt></p>
+<blockquote>
+<div><p>This variable can be used to add options to the C and C++ compiler,
+respectively. It is typically used to add options that tell the compiler
+the location of additional directories to search for header files.</p>
+<p>It is highly suggested that you append to <tt class="docutils literal"><span class="pre">CFLAGS</span></tt> and <tt class="docutils literal"><span class="pre">CPPFLAGS</span></tt> as
+opposed to overwriting them. The master <tt class="docutils literal"><span class="pre">Makefiles</span></tt> may already have
+useful options in them that you may not want to overwrite.</p>
+</div></blockquote>
+</div>
+</div>
+<div class="section" id="placement-of-object-code">
+<h2><a class="toc-backref" href="#id9">Placement of Object Code</a><a class="headerlink" href="#placement-of-object-code" title="Permalink to this headline">¶</a></h2>
+<p>The final location of built libraries and executables will depend upon whether
+you do a <tt class="docutils literal"><span class="pre">Debug</span></tt>, <tt class="docutils literal"><span class="pre">Release</span></tt>, or <tt class="docutils literal"><span class="pre">Profile</span></tt> build.</p>
+<p>Libraries</p>
+<blockquote>
+<div>All libraries (static and dynamic) will be stored in
+<tt class="docutils literal"><span class="pre">PROJ_OBJ_ROOT/<type>/lib</span></tt>, where <em>type</em> is <tt class="docutils literal"><span class="pre">Debug</span></tt>, <tt class="docutils literal"><span class="pre">Release</span></tt>, or
+<tt class="docutils literal"><span class="pre">Profile</span></tt> for a debug, optimized, or profiled build, respectively.</div></blockquote>
+<p>Executables</p>
+<blockquote>
+<div>All executables will be stored in <tt class="docutils literal"><span class="pre">PROJ_OBJ_ROOT/<type>/bin</span></tt>, where <em>type</em>
+is <tt class="docutils literal"><span class="pre">Debug</span></tt>, <tt class="docutils literal"><span class="pre">Release</span></tt>, or <tt class="docutils literal"><span class="pre">Profile</span></tt> for a debug, optimized, or
+profiled build, respectively.</div></blockquote>
+</div>
+<div class="section" id="further-help">
+<h2><a class="toc-backref" href="#id10">Further Help</a><a class="headerlink" href="#further-help" title="Permalink to this headline">¶</a></h2>
+<p>If you have any questions or need any help creating an LLVM project, the LLVM
+team would be more than happy to help. You can always post your questions to
+the <a class="reference external" href="http://lists.llvm.org/pipermail/llvm-dev/">LLVM Developers Mailing List</a>.</p>
+</div>
+</div>
+
+
+ </div>
+ </div>
+ <div class="clearer"></div>
+ </div>
+ <div class="related">
+ <h3>Navigation</h3>
+ <ul>
+ <li class="right" style="margin-right: 10px">
+ <a href="genindex.html" title="General Index"
+ >index</a></li>
+ <li class="right" >
+ <a href="LLVMBuild.html" title="LLVMBuild Guide"
+ >next</a> |</li>
+ <li class="right" >
+ <a href="MakefileGuide.html" title="LLVM Makefile Guide"
+ >previous</a> |</li>
+ <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+ <li><a href="index.html">Documentation</a>»</li>
+
+ </ul>
+ </div>
+ <div class="footer">
+ © Copyright 2003-2016, LLVM Project.
+ Last updated on 2016-01-04.
+ Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.3.
+ </div>
+ </body>
+</html>
\ No newline at end of file
Added: www-releases/trunk/3.7.1/docs/R600Usage.html
URL: http://llvm.org/viewvc/llvm-project/www-releases/trunk/3.7.1/docs/R600Usage.html?rev=257950&view=auto
==============================================================================
--- www-releases/trunk/3.7.1/docs/R600Usage.html (added)
+++ www-releases/trunk/3.7.1/docs/R600Usage.html Fri Jan 15 17:13:16 2016
@@ -0,0 +1,131 @@
+
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
+ <title>User Guide for R600 Back-end — LLVM 3.6 documentation</title>
+
+ <link rel="stylesheet" href="_static/llvm-theme.css" type="text/css" />
+ <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
+
+ <script type="text/javascript">
+ var DOCUMENTATION_OPTIONS = {
+ URL_ROOT: '',
+ VERSION: '3.6',
+ COLLAPSE_INDEX: false,
+ FILE_SUFFIX: '.html',
+ HAS_SOURCE: true
+ };
+ </script>
+ <script type="text/javascript" src="_static/jquery.js"></script>
+ <script type="text/javascript" src="_static/underscore.js"></script>
+ <script type="text/javascript" src="_static/doctools.js"></script>
+ <link rel="top" title="LLVM 3.6 documentation" href="index.html" />
+ <link rel="next" title="Stack maps and patch points in LLVM" href="StackMaps.html" />
+ <link rel="prev" title="User Guide for NVPTX Back-end" href="NVPTXUsage.html" />
+<style type="text/css">
+ table.right { float: right; margin-left: 20px; }
+ table.right td { border: 1px solid #ccc; }
+</style>
+
+ </head>
+ <body>
+<div class="logo">
+ <a href="index.html">
+ <img src="_static/logo.png"
+ alt="LLVM Logo" width="250" height="88"/></a>
+</div>
+
+ <div class="related">
+ <h3>Navigation</h3>
+ <ul>
+ <li class="right" style="margin-right: 10px">
+ <a href="genindex.html" title="General Index"
+ accesskey="I">index</a></li>
+ <li class="right" >
+ <a href="StackMaps.html" title="Stack maps and patch points in LLVM"
+ accesskey="N">next</a> |</li>
+ <li class="right" >
+ <a href="NVPTXUsage.html" title="User Guide for NVPTX Back-end"
+ accesskey="P">previous</a> |</li>
+ <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+ <li><a href="index.html">Documentation</a>»</li>
+
+ </ul>
+ </div>
+
+
+ <div class="document">
+ <div class="documentwrapper">
+ <div class="body">
+
+ <div class="section" id="user-guide-for-r600-back-end">
+<h1>User Guide for R600 Back-end<a class="headerlink" href="#user-guide-for-r600-back-end" title="Permalink to this headline">¶</a></h1>
+<div class="section" id="introduction">
+<h2>Introduction<a class="headerlink" href="#introduction" title="Permalink to this headline">¶</a></h2>
+<p>The R600 back-end provides ISA code generation for AMD GPUs, starting with
+the R600 family up until the current Sea Islands (GCN Gen 2).</p>
+</div>
+<div class="section" id="assembler">
+<h2>Assembler<a class="headerlink" href="#assembler" title="Permalink to this headline">¶</a></h2>
+<p>The assembler is currently a work in progress and not yet complete. Below
+are the currently supported features.</p>
+<div class="section" id="sopp-instructions">
+<h3>SOPP Instructions<a class="headerlink" href="#sopp-instructions" title="Permalink to this headline">¶</a></h3>
+<p>Unless otherwise mentioned, all SOPP instructions that with an operand
+accept a integer operand(s) only. No verification is performed on the
+operands, so it is up to the programmer to be familiar with the range
+or acceptable values.</p>
+<div class="section" id="s-waitcnt">
+<h4>s_waitcnt<a class="headerlink" href="#s-waitcnt" title="Permalink to this headline">¶</a></h4>
+<p>s_waitcnt accepts named arguments to specify which memory counter(s) to
+wait for.</p>
+<div class="highlight-nasm"><pre>// Wait for all counters to be 0
+s_waitcnt 0
+
+// Equivalent to s_waitcnt 0. Counter names can also be delimited by
+// '&' or ','.
+s_waitcnt vmcnt(0) expcnt(0) lgkcmt(0)
+
+// Wait for vmcnt counter to be 1.
+s_waitcnt vmcnt(1)</pre>
+</div>
+</div>
+</div>
+</div>
+</div>
+
+
+ </div>
+ </div>
+ <div class="clearer"></div>
+ </div>
+ <div class="related">
+ <h3>Navigation</h3>
+ <ul>
+ <li class="right" style="margin-right: 10px">
+ <a href="genindex.html" title="General Index"
+ >index</a></li>
+ <li class="right" >
+ <a href="StackMaps.html" title="Stack maps and patch points in LLVM"
+ >next</a> |</li>
+ <li class="right" >
+ <a href="NVPTXUsage.html" title="User Guide for NVPTX Back-end"
+ >previous</a> |</li>
+ <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+ <li><a href="index.html">Documentation</a>»</li>
+
+ </ul>
+ </div>
+ <div class="footer">
+ © Copyright 2003-2014, LLVM Project.
+ Last updated on 2015-07-13.
+ Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
+ </div>
+ </body>
+</html>
\ No newline at end of file
Added: www-releases/trunk/3.7.1/docs/ReleaseNotes.html
URL: http://llvm.org/viewvc/llvm-project/www-releases/trunk/3.7.1/docs/ReleaseNotes.html?rev=257950&view=auto
==============================================================================
--- www-releases/trunk/3.7.1/docs/ReleaseNotes.html (added)
+++ www-releases/trunk/3.7.1/docs/ReleaseNotes.html Fri Jan 15 17:13:16 2016
@@ -0,0 +1,561 @@
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
+ <title>LLVM 3.7 Release Notes — LLVM 3.7 documentation</title>
+
+ <link rel="stylesheet" href="_static/llvm-theme.css" type="text/css" />
+ <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
+
+ <script type="text/javascript">
+ var DOCUMENTATION_OPTIONS = {
+ URL_ROOT: './',
+ VERSION: '3.7',
+ COLLAPSE_INDEX: false,
+ FILE_SUFFIX: '.html',
+ HAS_SOURCE: true
+ };
+ </script>
+ <script type="text/javascript" src="_static/jquery.js"></script>
+ <script type="text/javascript" src="_static/underscore.js"></script>
+ <script type="text/javascript" src="_static/doctools.js"></script>
+ <link rel="top" title="LLVM 3.7 documentation" href="index.html" />
+ <link rel="next" title="LLVMâs Analysis and Transform Passes" href="Passes.html" />
+ <link rel="prev" title="8. Kaleidoscope: Conclusion and other useful LLVM tidbits" href="tutorial/OCamlLangImpl8.html" />
+<style type="text/css">
+ table.right { float: right; margin-left: 20px; }
+ table.right td { border: 1px solid #ccc; }
+</style>
+
+ </head>
+ <body>
+<div class="logo">
+ <a href="index.html">
+ <img src="_static/logo.png"
+ alt="LLVM Logo" width="250" height="88"/></a>
+</div>
+
+ <div class="related">
+ <h3>Navigation</h3>
+ <ul>
+ <li class="right" style="margin-right: 10px">
+ <a href="genindex.html" title="General Index"
+ accesskey="I">index</a></li>
+ <li class="right" >
+ <a href="Passes.html" title="LLVMâs Analysis and Transform Passes"
+ accesskey="N">next</a> |</li>
+ <li class="right" >
+ <a href="tutorial/OCamlLangImpl8.html" title="8. Kaleidoscope: Conclusion and other useful LLVM tidbits"
+ accesskey="P">previous</a> |</li>
+ <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+ <li><a href="index.html">Documentation</a>»</li>
+
+ </ul>
+ </div>
+
+
+ <div class="document">
+ <div class="documentwrapper">
+ <div class="body">
+
+ <div class="section" id="llvm-3-7-release-notes">
+<h1>LLVM 3.7 Release Notes<a class="headerlink" href="#llvm-3-7-release-notes" title="Permalink to this headline">¶</a></h1>
+<div class="contents local topic" id="contents">
+<ul class="simple">
+<li><a class="reference internal" href="#introduction" id="id2">Introduction</a></li>
+<li><a class="reference internal" href="#major-changes-in-3-7-1" id="id3">Major changes in 3.7.1</a></li>
+<li><a class="reference internal" href="#non-comprehensive-list-of-changes-in-3-7-0" id="id4">Non-comprehensive list of changes in 3.7.0</a><ul>
+<li><a class="reference internal" href="#changes-to-the-mips-target" id="id5">Changes to the MIPS Target</a></li>
+<li><a class="reference internal" href="#changes-to-the-powerpc-target" id="id6">Changes to the PowerPC Target</a></li>
+<li><a class="reference internal" href="#changes-to-the-systemz-target" id="id7">Changes to the SystemZ Target</a></li>
+<li><a class="reference internal" href="#changes-to-the-jit-apis" id="id8">Changes to the JIT APIs</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#sub-project-status-update" id="id9">Sub-project Status Update</a><ul>
+<li><a class="reference internal" href="#polly-the-polyhedral-loop-optimizer-in-llvm" id="id10">Polly - The Polyhedral Loop Optimizer in LLVM</a></li>
+<li><a class="reference internal" href="#libunwind" id="id11">libunwind</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#external-open-source-projects-using-llvm-3-7" id="id12">External Open Source Projects Using LLVM 3.7</a><ul>
+<li><a class="reference internal" href="#ldc-the-llvm-based-d-compiler" id="id13">LDC - the LLVM-based D compiler</a></li>
+<li><a class="reference internal" href="#portable-computing-language-pocl" id="id14">Portable Computing Language (pocl)</a></li>
+<li><a class="reference internal" href="#tta-based-co-design-environment-tce" id="id15">TTA-based Co-design Environment (TCE)</a></li>
+<li><a class="reference internal" href="#bpf-compiler-collection-bcc" id="id16">BPF Compiler Collection (BCC)</a></li>
+<li><a class="reference internal" href="#llvmsharp-clangsharp" id="id17">LLVMSharp & ClangSharp</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#additional-information" id="id18">Additional Information</a></li>
+</ul>
+</div>
+<div class="section" id="introduction">
+<h2><a class="toc-backref" href="#id2">Introduction</a><a class="headerlink" href="#introduction" title="Permalink to this headline">¶</a></h2>
+<p>This document contains the release notes for the LLVM Compiler Infrastructure,
+release 3.7. Here we describe the status of LLVM, including major improvements
+from the previous release, improvements in various subprojects of LLVM, and
+some of the current users of the code. All LLVM releases may be downloaded
+from the <a class="reference external" href="http://llvm.org/releases/">LLVM releases web site</a>.</p>
+<p>For more information about LLVM, including information about the latest
+release, please check out the <a class="reference external" href="http://llvm.org/">main LLVM web site</a>. If you
+have questions or comments, the <a class="reference external" href="http://lists.llvm.org/mailman/listinfo/llvm-dev">LLVM Developer’s Mailing List</a> is a good place to send
+them.</p>
+<p>Note that if you are reading this file from a Subversion checkout or the main
+LLVM web page, this document applies to the <em>next</em> release, not the current
+one. To see the release notes for a specific release, please see the <a class="reference external" href="http://llvm.org/releases/">releases
+page</a>.</p>
+</div>
+<div class="section" id="major-changes-in-3-7-1">
+<h2><a class="toc-backref" href="#id3">Major changes in 3.7.1</a><a class="headerlink" href="#major-changes-in-3-7-1" title="Permalink to this headline">¶</a></h2>
+<ul>
+<li><p class="first">3.7.0 was released with an inadvertent change to the signature of the C
+API function: LLVMBuildLandingPad, which made the C API incompatible with
+prior releases. This has been corrected in LLVM 3.7.1.</p>
+<p>As a result of this change, 3.7.0 is not ABI compatible with 3.7.1.</p>
+<table border="1" class="docutils">
+<colgroup>
+<col width="36%" />
+<col width="64%" />
+</colgroup>
+<thead valign="bottom">
+<tr class="row-odd"><th class="head" colspan="2">History of the LLVMBuildLandingPad() function</th>
+</tr>
+</thead>
+<tbody valign="top">
+<tr class="row-even"><td>3.6.2 and prior releases</td>
+<td><dl class="first last docutils">
+<dt>LLVMBuildLandingPad(LLVMBuilderRef,</dt>
+<dd>LLVMTypeRef,
+LLVMValueRef,
+unsigned, const char*)</dd>
+</dl>
+</td>
+</tr>
+<tr class="row-odd"><td>3.7.0</td>
+<td><dl class="first last docutils">
+<dt>LLVMBuildLandingPad(LLVMBuilderRef,</dt>
+<dd>LLVMTypeRef,
+unsigned, const char*)</dd>
+</dl>
+</td>
+</tr>
+<tr class="row-even"><td>3.7.1 and future releases</td>
+<td><dl class="first last docutils">
+<dt>LLVMBuildLandingPad(LLVMBuilderRef,</dt>
+<dd>LLVMTypeRef,
+LLVMValueRef,
+unsigned, const char*)</dd>
+</dl>
+</td>
+</tr>
+</tbody>
+</table>
+</li>
+</ul>
+</div>
+<div class="section" id="non-comprehensive-list-of-changes-in-3-7-0">
+<h2><a class="toc-backref" href="#id4">Non-comprehensive list of changes in 3.7.0</a><a class="headerlink" href="#non-comprehensive-list-of-changes-in-3-7-0" title="Permalink to this headline">¶</a></h2>
+<ul>
+<li><p class="first">The minimum required Visual Studio version for building LLVM is now 2013
+Update 4.</p>
+</li>
+<li><p class="first">A new documentation page, <a class="reference internal" href="Frontend/PerformanceTips.html"><em>Performance Tips for Frontend Authors</em></a>, contains a
+collection of tips for frontend authors on how to generate IR which LLVM is
+able to effectively optimize.</p>
+</li>
+<li><p class="first">The <tt class="docutils literal"><span class="pre">DataLayout</span></tt> is no longer optional. All the IR level optimizations expects
+it to be present and the API has been changed to use a reference instead of
+a pointer to make it explicit. The Module owns the datalayout and it has to
+match the one attached to the TargetMachine for generating code.</p>
+<dl class="docutils">
+<dt>In 3.6, a pass was inserted in the pipeline to make the <tt class="docutils literal"><span class="pre">DataLayout</span></tt> accessible:</dt>
+<dd><p class="first last"><tt class="docutils literal"><span class="pre">MyPassManager->add(new</span> <span class="pre">DataLayoutPass(MyTargetMachine->getDataLayout()));</span></tt></p>
+</dd>
+<dt>In 3.7, you don’t need a pass, you set the <tt class="docutils literal"><span class="pre">DataLayout</span></tt> on the <tt class="docutils literal"><span class="pre">Module</span></tt>:</dt>
+<dd><p class="first last"><tt class="docutils literal"><span class="pre">MyModule->setDataLayout(MyTargetMachine->createDataLayout());</span></tt></p>
+</dd>
+</dl>
+<p>The LLVM C API <tt class="docutils literal"><span class="pre">LLVMGetTargetMachineData</span></tt> is deprecated to reflect the fact
+that it won’t be available anymore from <tt class="docutils literal"><span class="pre">TargetMachine</span></tt> in 3.8.</p>
+</li>
+<li><p class="first">Comdats are now orthogonal to the linkage. LLVM will not create
+comdats for weak linkage globals and the frontends are responsible
+for explicitly adding them.</p>
+</li>
+<li><p class="first">On ELF we now support multiple sections with the same name and
+comdat. This allows for smaller object files since multiple
+sections can have a simple name (<cite>.text</cite>, <cite>.rodata</cite>, etc).</p>
+</li>
+<li><p class="first">LLVM now lazily loads metadata in some cases. Creating archives
+with IR files with debug info is now 25X faster.</p>
+</li>
+<li><p class="first">llvm-ar can create archives in the BSD format used by OS X.</p>
+</li>
+<li><p class="first">LLVM received a backend for the extended Berkely Packet Filter
+instruction set that can be dynamically loaded into the Linux kernel via the
+<a class="reference external" href="http://man7.org/linux/man-pages/man2/bpf.2.html">bpf(2)</a> syscall.</p>
+<p>Support for BPF has been present in the kernel for some time, but starting
+from 3.18 has been extended with such features as: 64-bit registers, 8
+additional registers registers, conditional backwards jumps, call
+instruction, shift instructions, map (hash table, array, etc.), 1-8 byte
+load/store from stack, and more.</p>
+<p>Up until now, users of BPF had to write bytecode by hand, or use
+custom generators. This release adds a proper LLVM backend target for the BPF
+bytecode architecture.</p>
+<p>The BPF target is now available by default, and options exist in both Clang
+(-target bpf) or llc (-march=bpf) to pick eBPF as a backend.</p>
+</li>
+<li><p class="first">Switch-case lowering was rewritten to avoid generating unbalanced search trees
+(<a class="reference external" href="http://llvm.org/pr22262">PR22262</a>) and to exploit profile information
+when available. Some lowering strategies are now disabled when optimizations
+are turned off, to save compile time.</p>
+</li>
+<li><p class="first">The debug info IR class hierarchy now inherits from <tt class="docutils literal"><span class="pre">Metadata</span></tt> and has its
+own bitcode records and assembly syntax
+(<a class="reference external" href="LangRef.html#specialized-metadata-nodes">documented in LangRef</a>). The debug
+info verifier has been merged with the main verifier.</p>
+</li>
+<li><p class="first">LLVM IR and APIs are in a period of transition to aid in the removal of
+pointer types (the end goal being that pointers are typeless/opaque - void*,
+if you will). Some APIs and IR constructs have been modified to take
+explicit types that are currently checked to match the target type of their
+pre-existing pointer type operands. Further changes are still needed, but the
+more you can avoid using <tt class="docutils literal"><span class="pre">PointerType::getPointeeType</span></tt>, the easier the
+migration will be.</p>
+</li>
+<li><p class="first">Argument-less <tt class="docutils literal"><span class="pre">TargetMachine::getSubtarget</span></tt> and
+<tt class="docutils literal"><span class="pre">TargetMachine::getSubtargetImpl</span></tt> have been removed from the tree. Updating
+out of tree ports is as simple as implementing a non-virtual version in the
+target, but implementing full <tt class="docutils literal"><span class="pre">Function</span></tt> based <tt class="docutils literal"><span class="pre">TargetSubtargetInfo</span></tt>
+support is recommended.</p>
+</li>
+<li><p class="first">This is expected to be the last major release of LLVM that supports being
+run on Windows XP and Windows Vista. For the next major release the minimum
+Windows version requirement will be Windows 7.</p>
+</li>
+</ul>
+<div class="section" id="changes-to-the-mips-target">
+<h3><a class="toc-backref" href="#id5">Changes to the MIPS Target</a><a class="headerlink" href="#changes-to-the-mips-target" title="Permalink to this headline">¶</a></h3>
+<p>During this release the MIPS target has:</p>
+<ul class="simple">
+<li>Added support for MIPS32R3, MIPS32R5, MIPS32R3, MIPS32R5, and microMIPS32.</li>
+<li>Added support for dynamic stack realignment. This is of particular importance
+to MSA on 32-bit subtargets since vectors always exceed the stack alignment on
+the O32 ABI.</li>
+<li>Added support for compiler-rt including:<ul>
+<li>Support for the Address, and Undefined Behaviour Sanitizers for all MIPS
+subtargets.</li>
+<li>Support for the Data Flow, and Memory Sanitizer for 64-bit subtargets.</li>
+<li>Support for the Profiler for all MIPS subtargets.</li>
+</ul>
+</li>
+<li>Added support for libcxx, and libcxxabi.</li>
+<li>Improved inline assembly support such that memory constraints may now make use
+of the appropriate address offsets available to the instructions. Also, added
+support for the <tt class="docutils literal"><span class="pre">ZC</span></tt> constraint.</li>
+<li>Added support for 128-bit integers on 64-bit subtargets and 16-bit floating
+point conversions on all subtargets.</li>
+<li>Added support for read-only <tt class="docutils literal"><span class="pre">.eh_frame</span></tt> sections by storing type information
+indirectly.</li>
+<li>Added support for MCJIT on all 64-bit subtargets as well as MIPS32R6.</li>
+<li>Added support for fast instruction selection on MIPS32 and MIPS32R2 with PIC.</li>
+<li>Various bug fixes. Including the following notable fixes:<ul>
+<li>Fixed ‘jumpy’ debug line info around calls where calculation of the address
+of the function would inappropriately change the line number.</li>
+<li>Fixed missing <tt class="docutils literal"><span class="pre">__mips_isa_rev</span></tt> macro on the MIPS32R6 and MIPS32R6
+subtargets.</li>
+<li>Fixed representation of NaN when targeting systems using traditional
+encodings. Traditionally, MIPS has used NaN encodings that were compatible
+with IEEE754-1985 but would later be found incompatible with IEEE754-2008.</li>
+<li>Fixed multiple segfaults and assertions in the disassembler when
+disassembling instructions that have memory operands.</li>
+<li>Fixed multiple cases of suboptimal code generation involving $zero.</li>
+<li>Fixed code generation of 128-bit shifts on 64-bit subtargets.</li>
+<li>Prevented the delay slot filler from filling call delay slots with
+instructions that modify or use $ra.</li>
+<li>Fixed some remaining N32/N64 calling convention bugs when using small
+structures on big-endian subtargets.</li>
+<li>Fixed missing sign-extensions that are required by the N32/N64 calling
+convention when generating calls to library functions with 32-bit
+parameters.</li>
+<li>Corrected the <tt class="docutils literal"><span class="pre">int64_t</span></tt> typedef to be <tt class="docutils literal"><span class="pre">long</span></tt> for N64.</li>
+<li><tt class="docutils literal"><span class="pre">-mno-odd-spreg</span></tt> is now honoured for vector insertion/extraction
+operations when using -mmsa.</li>
+<li>Fixed vector insertion and extraction for MSA on 64-bit subtargets.</li>
+<li>Corrected the representation of member function pointers. This makes them
+usable on microMIPS subtargets.</li>
+</ul>
+</li>
+</ul>
+</div>
+<div class="section" id="changes-to-the-powerpc-target">
+<h3><a class="toc-backref" href="#id6">Changes to the PowerPC Target</a><a class="headerlink" href="#changes-to-the-powerpc-target" title="Permalink to this headline">¶</a></h3>
+<p>There are numerous improvements to the PowerPC target in this release:</p>
+<ul class="simple">
+<li>LLVM now supports the ISA 2.07B (POWER8) instruction set, including
+direct moves between general registers and vector registers, and
+built-in support for hardware transactional memory (HTM). Some missing
+instructions from ISA 2.06 (POWER7) were also added.</li>
+<li>Code generation for the local-dynamic and global-dynamic thread-local
+storage models has been improved.</li>
+<li>Loops may be restructured to leverage pre-increment loads and stores.</li>
+<li>QPX - The vector instruction set used by the IBM Blue Gene/Q supercomputers
+is now supported.</li>
+<li>Loads from the TOC area are now correctly treated as invariant.</li>
+<li>PowerPC now has support for i128 and v1i128 types. The types differ
+in how they are passed in registers for the ELFv2 ABI.</li>
+<li>Disassembly will now print shorter mnemonic aliases when available.</li>
+<li>Optional register name prefixes for VSX and QPX registers are now
+supported in the assembly parser.</li>
+<li>The back end now contains a pass to remove unnecessary vector swaps
+from POWER8 little-endian code generation. Additional improvements
+are planned for release 3.8.</li>
+<li>The undefined-behavior sanitizer (UBSan) is now supported for PowerPC.</li>
+<li>Many new vector programming APIs have been added to altivec.h.
+Additional ones are planned for release 3.8.</li>
+<li>PowerPC now supports __builtin_call_with_static_chain.</li>
+<li>PowerPC now supports the revised -mrecip option that permits finer
+control over reciprocal estimates.</li>
+<li>Many bugs have been identified and fixed.</li>
+</ul>
+</div>
+<div class="section" id="changes-to-the-systemz-target">
+<h3><a class="toc-backref" href="#id7">Changes to the SystemZ Target</a><a class="headerlink" href="#changes-to-the-systemz-target" title="Permalink to this headline">¶</a></h3>
+<ul class="simple">
+<li>LLVM no longer attempts to automatically detect the current host CPU when
+invoked natively.</li>
+<li>Support for all thread-local storage models. (Previous releases would support
+only the local-exec TLS model.)</li>
+<li>The POPCNT instruction is now used on z196 and above.</li>
+<li>The RISBGN instruction is now used on zEC12 and above.</li>
+<li>Support for the transactional-execution facility on zEC12 and above.</li>
+<li>Support for the z13 processor and its vector facility.</li>
+</ul>
+</div>
+<div class="section" id="changes-to-the-jit-apis">
+<h3><a class="toc-backref" href="#id8">Changes to the JIT APIs</a><a class="headerlink" href="#changes-to-the-jit-apis" title="Permalink to this headline">¶</a></h3>
+<ul>
+<li><p class="first">Added a new C++ JIT API called On Request Compilation, or ORC.</p>
+<p>ORC is a new JIT API inspired by MCJIT but designed to be more testable, and
+easier to extend with new features. A key new feature already in tree is lazy,
+function-at-a-time compilation for X86. Also included is a reimplementation of
+MCJIT’s API and behavior (OrcMCJITReplacement). MCJIT itself remains in tree,
+and continues to be the default JIT ExecutionEngine, though new users are
+encouraged to try ORC out for their projects. (A good place to start is the
+new ORC tutorials under llvm/examples/kaleidoscope/orc).</p>
+</li>
+</ul>
+</div>
+</div>
+<div class="section" id="sub-project-status-update">
+<h2><a class="toc-backref" href="#id9">Sub-project Status Update</a><a class="headerlink" href="#sub-project-status-update" title="Permalink to this headline">¶</a></h2>
+<p>In addition to the core LLVM 3.7 distribution of production-quality compiler
+infrastructure, the LLVM project includes sub-projects that use the LLVM core
+and share the same distribution license. This section provides updates on these
+sub-projects.</p>
+<div class="section" id="polly-the-polyhedral-loop-optimizer-in-llvm">
+<h3><a class="toc-backref" href="#id10">Polly - The Polyhedral Loop Optimizer in LLVM</a><a class="headerlink" href="#polly-the-polyhedral-loop-optimizer-in-llvm" title="Permalink to this headline">¶</a></h3>
+<p><a class="reference external" href="http://polly.llvm.org">Polly</a> is a polyhedral loop optimization
+infrastructure that provides data-locality optimizations to LLVM-based
+compilers. When compiled as part of clang or loaded as a module into clang,
+it can perform loop optimizations such as tiling, loop fusion or outer-loop
+vectorization. As a generic loop optimization infrastructure it allows
+developers to get a per-loop-iteration model of a loop nest on which detailed
+analysis and transformations can be performed.</p>
+<p>Changes since the last release:</p>
+<ul>
+<li><p class="first">isl imported into Polly distribution</p>
+<p><a class="reference external" href="http://repo.or.cz/w/isl.git">isl</a>, the math library Polly uses, has been
+imported into the source code repository of Polly and is now distributed as part
+of Polly. As this was the last external library dependency of Polly, Polly can
+now be compiled right after checking out the Polly source code without the need
+for any additional libraries to be pre-installed.</p>
+</li>
+<li><p class="first">Small integer optimization of isl</p>
+<p>The MIT licensed imath backend using in <a class="reference external" href="http://repo.or.cz/w/isl.git">isl</a> for
+arbitrary width integer computations has been optimized to use native integer
+operations for the common case where the operands of a computation fit into 32
+bit and to only fall back to large arbitrary precision integers for the
+remaining cases. This optimization has greatly improved the compile-time
+performance of Polly, both due to faster native operations also due to a
+reduction in malloc traffic and pointer indirections. As a result, computations
+that use arbitrary precision integers heavily have been speed up by almost 6x.
+As a result, the compile-time of Polly on the Polybench test kernels in the LNT
+suite has been reduced by 20% on average with compile time reductions between
+9-43%.</p>
+</li>
+<li><p class="first">Schedule Trees</p>
+<p>Polly now uses internally so-called > Schedule Trees < to model the loop
+structure it optimizes. Schedule trees are an easy to understand tree structure
+that describes a loop nest using integer constraint sets to keep track of
+execution constraints. It allows the developer to use per-tree-node operations
+to modify the loop tree. Programatic analysis that work on the schedule tree
+(e.g., as dependence analysis) also show a visible speedup as they can exploit
+the tree structure of the schedule and need to fall back to ILP based
+optimization problems less often. Section 6 of <a class="reference external" href="http://www.grosser.es/#pub-polyhedral-AST-generation">Polyhedral AST generation is
+more than scanning polyhedra</a> gives a detailed
+explanation of this schedule trees.</p>
+</li>
+<li><p class="first">Scalar and PHI node modeling - Polly as an analysis</p>
+<p>Polly now requires almost no preprocessing to analyse LLVM-IR, which makes it
+easier to use Polly as a pure analysis pass e.g. to provide more precise
+dependence information to non-polyhedral transformation passes. Originally,
+Polly required the input LLVM-IR to be preprocessed such that all scalar and
+PHI-node dependences are translated to in-memory operations. Since this release,
+Polly has full support for scalar and PHI node dependences and requires no
+scalar-to-memory translation for such kind of dependences.</p>
+</li>
+<li><p class="first">Modeling of modulo and non-affine conditions</p>
+<p>Polly can now supports modulo operations such as A[t%2][i][j] as they appear
+often in stencil computations and also allows data-dependent conditional
+branches as they result e.g. from ternary conditions ala A[i] > 255 ? 255 :
+A[i].</p>
+</li>
+<li><p class="first">Delinearization</p>
+<p>Polly now support the analysis of manually linearized multi-dimensional arrays
+as they result form macros such as
+“#define 2DARRAY(A,i,j) (A.data[(i) * A.size + (j)]”. Similar constructs appear
+in old C code written before C99, C++ code such as boost::ublas, LLVM exported
+from Julia, Matlab generated code and many others. Our work titled
+<a class="reference external" href="http://www.grosser.es/#pub-optimistic-delinerization">Optimistic Delinearization of Parametrically Sized Arrays</a> gives details.</p>
+</li>
+<li><p class="first">Compile time improvements</p>
+<p>Pratik Bahtu worked on compile-time performance tuning of Polly. His work
+together with the support for schedule trees and the small integer optimization
+in isl notably reduced the compile time.</p>
+</li>
+<li><p class="first">Increased compute timeouts</p>
+<p>As Polly’s compile time has been notabily improved, we were able to increase
+the compile time saveguards in Polly. As a result, the default configuration
+of Polly can now analyze larger loop nests without running into compile time
+restrictions.</p>
+</li>
+<li><p class="first">Export Debug Locations via JSCoP file</p>
+<p>Polly’s JSCoP import/export format gained support for debug locations that show
+to the user the source code location of detected scops.</p>
+</li>
+<li><p class="first">Improved windows support</p>
+<p>The compilation of Polly on windows using cmake has been improved and several
+visual studio build issues have been addressed.</p>
+</li>
+<li><p class="first">Many bug fixes</p>
+</li>
+</ul>
+</div>
+<div class="section" id="libunwind">
+<h3><a class="toc-backref" href="#id11">libunwind</a><a class="headerlink" href="#libunwind" title="Permalink to this headline">¶</a></h3>
+<p>The unwind implementation which use to reside in <cite>libc++abi</cite> has been moved into
+a separate repository. This implementation can still be used for <cite>libc++abi</cite> by
+specifying <cite>-DLIBCXXABI_USE_LLVM_UNWINDER=YES</cite> and
+<cite>-DLIBCXXABI_LIBUNWIND_PATH=<path to libunwind source></cite> when configuring
+<cite>libc++abi</cite>, which defaults to <cite>true</cite> when building on ARM.</p>
+<p>The new repository can also be built standalone if just <cite>libunwind</cite> is desired.</p>
+</div>
+</div>
+<div class="section" id="external-open-source-projects-using-llvm-3-7">
+<h2><a class="toc-backref" href="#id12">External Open Source Projects Using LLVM 3.7</a><a class="headerlink" href="#external-open-source-projects-using-llvm-3-7" title="Permalink to this headline">¶</a></h2>
+<p>An exciting aspect of LLVM is that it is used as an enabling technology for
+a lot of other language and tools projects. This section lists some of the
+projects that have already been updated to work with LLVM 3.7.</p>
+<div class="section" id="ldc-the-llvm-based-d-compiler">
+<h3><a class="toc-backref" href="#id13">LDC - the LLVM-based D compiler</a><a class="headerlink" href="#ldc-the-llvm-based-d-compiler" title="Permalink to this headline">¶</a></h3>
+<p><a class="reference external" href="http://dlang.org">D</a> is a language with C-like syntax and static typing. It
+pragmatically combines efficiency, control, and modeling power, with safety and
+programmer productivity. D supports powerful concepts like Compile-Time Function
+Execution (CTFE) and Template Meta-Programming, provides an innovative approach
+to concurrency and offers many classical paradigms.</p>
+<p><a class="reference external" href="http://wiki.dlang.org/LDC">LDC</a> uses the frontend from the reference compiler
+combined with LLVM as backend to produce efficient native code. LDC targets
+x86/x86_64 systems like Linux, OS X, FreeBSD and Windows and also Linux on
+PowerPC (32/64 bit). Ports to other architectures like ARM, AArch64 and MIPS64
+are underway.</p>
+</div>
+<div class="section" id="portable-computing-language-pocl">
+<h3><a class="toc-backref" href="#id14">Portable Computing Language (pocl)</a><a class="headerlink" href="#portable-computing-language-pocl" title="Permalink to this headline">¶</a></h3>
+<p>In addition to producing an easily portable open source OpenCL
+implementation, another major goal of <a class="reference external" href="http://portablecl.org/">pocl</a>
+is improving performance portability of OpenCL programs with
+compiler optimizations, reducing the need for target-dependent manual
+optimizations. An important part of pocl is a set of LLVM passes used to
+statically parallelize multiple work-items with the kernel compiler, even in
+the presence of work-group barriers.</p>
+</div>
+<div class="section" id="tta-based-co-design-environment-tce">
+<h3><a class="toc-backref" href="#id15">TTA-based Co-design Environment (TCE)</a><a class="headerlink" href="#tta-based-co-design-environment-tce" title="Permalink to this headline">¶</a></h3>
+<p><a class="reference external" href="http://tce.cs.tut.fi/">TCE</a> is a toolset for designing customized
+exposed datapath processors based on the Transport triggered
+architecture (TTA).</p>
+<p>The toolset provides a complete co-design flow from C/C++
+programs down to synthesizable VHDL/Verilog and parallel program binaries.
+Processor customization points include the register files, function units,
+supported operations, and the interconnection network.</p>
+<p>TCE uses Clang and LLVM for C/C++/OpenCL C language support, target independent
+optimizations and also for parts of code generation. It generates
+new LLVM-based code generators “on the fly” for the designed processors and
+loads them in to the compiler backend as runtime libraries to avoid
+per-target recompilation of larger parts of the compiler chain.</p>
+</div>
+<div class="section" id="bpf-compiler-collection-bcc">
+<h3><a class="toc-backref" href="#id16">BPF Compiler Collection (BCC)</a><a class="headerlink" href="#bpf-compiler-collection-bcc" title="Permalink to this headline">¶</a></h3>
+<p><a class="reference external" href="https://github.com/iovisor/bcc">BCC</a> is a Python + C framework for tracing and
+networking that is using Clang rewriter + 2nd pass of Clang + BPF backend to
+generate eBPF and push it into the kernel.</p>
+</div>
+<div class="section" id="llvmsharp-clangsharp">
+<h3><a class="toc-backref" href="#id17">LLVMSharp & ClangSharp</a><a class="headerlink" href="#llvmsharp-clangsharp" title="Permalink to this headline">¶</a></h3>
+<p><a class="reference external" href="http://www.llvmsharp.org">LLVMSharp</a> and
+<a class="reference external" href="http://www.clangsharp.org">ClangSharp</a> are type-safe C# bindings for
+Microsoft.NET and Mono that Platform Invoke into the native libraries.
+ClangSharp is self-hosted and is used to generated LLVMSharp using the
+LLVM-C API.</p>
+<p><a class="reference external" href="http://www.llvmsharp.org/Kaleidoscope/">LLVMSharp Kaleidoscope Tutorials</a>
+are instructive examples of writing a compiler in C#, with certain improvements
+like using the visitor pattern to generate LLVM IR.</p>
+<p><a class="reference external" href="http://www.clangsharp.org/PInvoke/">ClangSharp PInvoke Generator</a> is the
+self-hosting mechanism for LLVM/ClangSharp and is demonstrative of using
+LibClang to generate Platform Invoke (PInvoke) signatures for C APIs.</p>
+</div>
+</div>
+<div class="section" id="additional-information">
+<h2><a class="toc-backref" href="#id18">Additional Information</a><a class="headerlink" href="#additional-information" title="Permalink to this headline">¶</a></h2>
+<p>A wide variety of additional information is available on the <a class="reference external" href="http://llvm.org/">LLVM web page</a>, in particular in the <a class="reference external" href="http://llvm.org/docs/">documentation</a> section. The web page also contains versions of the
+API documentation which is up-to-date with the Subversion version of the source
+code. You can access versions of these documents specific to this release by
+going into the <tt class="docutils literal"><span class="pre">llvm/docs/</span></tt> directory in the LLVM tree.</p>
+<p>If you have any questions or comments about LLVM, please feel free to contact
+us via the <a class="reference external" href="http://llvm.org/docs/#maillist">mailing lists</a>.</p>
+</div>
+</div>
+
+
+ </div>
+ </div>
+ <div class="clearer"></div>
+ </div>
+ <div class="related">
+ <h3>Navigation</h3>
+ <ul>
+ <li class="right" style="margin-right: 10px">
+ <a href="genindex.html" title="General Index"
+ >index</a></li>
+ <li class="right" >
+ <a href="Passes.html" title="LLVMâs Analysis and Transform Passes"
+ >next</a> |</li>
+ <li class="right" >
+ <a href="tutorial/OCamlLangImpl8.html" title="8. Kaleidoscope: Conclusion and other useful LLVM tidbits"
+ >previous</a> |</li>
+ <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+ <li><a href="index.html">Documentation</a>»</li>
+
+ </ul>
+ </div>
+ <div class="footer">
+ © Copyright 2003-2016, LLVM Project.
+ Last updated on 2016-01-04.
+ Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.3.
+ </div>
+ </body>
+</html>
\ No newline at end of file
Added: www-releases/trunk/3.7.1/docs/ReleaseProcess.html
URL: http://llvm.org/viewvc/llvm-project/www-releases/trunk/3.7.1/docs/ReleaseProcess.html?rev=257950&view=auto
==============================================================================
--- www-releases/trunk/3.7.1/docs/ReleaseProcess.html (added)
+++ www-releases/trunk/3.7.1/docs/ReleaseProcess.html Fri Jan 15 17:13:16 2016
@@ -0,0 +1,255 @@
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
+ <title>How To Validate a New Release — LLVM 3.7 documentation</title>
+
+ <link rel="stylesheet" href="_static/llvm-theme.css" type="text/css" />
+ <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
+
+ <script type="text/javascript">
+ var DOCUMENTATION_OPTIONS = {
+ URL_ROOT: './',
+ VERSION: '3.7',
+ COLLAPSE_INDEX: false,
+ FILE_SUFFIX: '.html',
+ HAS_SOURCE: true
+ };
+ </script>
+ <script type="text/javascript" src="_static/jquery.js"></script>
+ <script type="text/javascript" src="_static/underscore.js"></script>
+ <script type="text/javascript" src="_static/doctools.js"></script>
+ <link rel="top" title="LLVM 3.7 documentation" href="index.html" />
+ <link rel="next" title="Code Reviews with Phabricator" href="Phabricator.html" />
+ <link rel="prev" title="Advice on Packaging LLVM" href="Packaging.html" />
+<style type="text/css">
+ table.right { float: right; margin-left: 20px; }
+ table.right td { border: 1px solid #ccc; }
+</style>
+
+ </head>
+ <body>
+<div class="logo">
+ <a href="index.html">
+ <img src="_static/logo.png"
+ alt="LLVM Logo" width="250" height="88"/></a>
+</div>
+
+ <div class="related">
+ <h3>Navigation</h3>
+ <ul>
+ <li class="right" style="margin-right: 10px">
+ <a href="genindex.html" title="General Index"
+ accesskey="I">index</a></li>
+ <li class="right" >
+ <a href="Phabricator.html" title="Code Reviews with Phabricator"
+ accesskey="N">next</a> |</li>
+ <li class="right" >
+ <a href="Packaging.html" title="Advice on Packaging LLVM"
+ accesskey="P">previous</a> |</li>
+ <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+ <li><a href="index.html">Documentation</a>»</li>
+
+ </ul>
+ </div>
+
+
+ <div class="document">
+ <div class="documentwrapper">
+ <div class="body">
+
+ <div class="section" id="how-to-validate-a-new-release">
+<h1>How To Validate a New Release<a class="headerlink" href="#how-to-validate-a-new-release" title="Permalink to this headline">¶</a></h1>
+<div class="contents local topic" id="contents">
+<ul class="simple">
+<li><a class="reference internal" href="#introduction" id="id9">Introduction</a></li>
+<li><a class="reference internal" href="#scripts" id="id10">Scripts</a></li>
+<li><a class="reference internal" href="#test-suite" id="id11">Test Suite</a></li>
+<li><a class="reference internal" href="#pre-release-process" id="id12">Pre-Release Process</a></li>
+<li><a class="reference internal" href="#release-process" id="id13">Release Process</a></li>
+<li><a class="reference internal" href="#bug-reporting-process" id="id14">Bug Reporting Process</a></li>
+</ul>
+</div>
+<div class="section" id="introduction">
+<h2><a class="toc-backref" href="#id9">Introduction</a><a class="headerlink" href="#introduction" title="Permalink to this headline">¶</a></h2>
+<p>This document contains information about testing the release candidates that will
+ultimately be the next LLVM release. For more information on how to manage the
+actual release, please refer to <a class="reference internal" href="HowToReleaseLLVM.html"><em>How To Release LLVM To The Public</em></a>.</p>
+<div class="section" id="overview-of-the-release-process">
+<h3>Overview of the Release Process<a class="headerlink" href="#overview-of-the-release-process" title="Permalink to this headline">¶</a></h3>
+<p>Once the release process starts, the Release Manager will ask for volunteers,
+and it’ll be the role of each volunteer to:</p>
+<ul class="simple">
+<li>Test and benchmark the previous release</li>
+<li>Test and benchmark each release candidate, comparing to the previous release and candidates</li>
+<li>Identify, reduce and report every regression found during tests and benchmarks</li>
+<li>Make sure the critical bugs get fixed and merged to the next release candidate</li>
+</ul>
+<p>Not all bugs or regressions are show-stoppers and it’s a bit of a grey area what
+should be fixed before the next candidate and what can wait until the next release.</p>
+<p>It’ll depend on:</p>
+<ul class="simple">
+<li>The severity of the bug, how many people it affects and if it’s a regression or a
+known bug. Known bugs are “unsupported features” and some bugs can be disabled if
+they have been implemented recently.</li>
+<li>The stage in the release. Less critical bugs should be considered to be fixed between
+RC1 and RC2, but not so much at the end of it.</li>
+<li>If it’s a correctness or a performance regression. Performance regression tends to be
+taken more lightly than correctness.</li>
+</ul>
+</div>
+</div>
+<div class="section" id="scripts">
+<span id="id1"></span><h2><a class="toc-backref" href="#id10">Scripts</a><a class="headerlink" href="#scripts" title="Permalink to this headline">¶</a></h2>
+<p>The scripts are in the <tt class="docutils literal"><span class="pre">utils/release</span></tt> directory.</p>
+<div class="section" id="test-release-sh">
+<h3>test-release.sh<a class="headerlink" href="#test-release-sh" title="Permalink to this headline">¶</a></h3>
+<p>This script will check-out, configure and compile LLVM+Clang (+ most add-ons, like <tt class="docutils literal"><span class="pre">compiler-rt</span></tt>,
+<tt class="docutils literal"><span class="pre">libcxx</span></tt> and <tt class="docutils literal"><span class="pre">clang-extra-tools</span></tt>) in three stages, and will test the final stage.
+It’ll have installed the final binaries on the Phase3/Releasei(+Asserts) directory, and
+that’s the one you should use for the test-suite and other external tests.</p>
+<p>To run the script on a specific release candidate run:</p>
+<div class="highlight-python"><div class="highlight"><pre>./test-release.sh \
+ -release 3.3 \
+ -rc 1 \
+ -no-64bit \
+ -test-asserts \
+ -no-compare-files
+</pre></div>
+</div>
+<p>Each system will require different options. For instance, x86_64 will obviously not need
+<tt class="docutils literal"><span class="pre">-no-64bit</span></tt> while 32-bit systems will, or the script will fail.</p>
+<p>The important flags to get right are:</p>
+<ul class="simple">
+<li>On the pre-release, you should change <tt class="docutils literal"><span class="pre">-rc</span> <span class="pre">1</span></tt> to <tt class="docutils literal"><span class="pre">-final</span></tt>. On RC2, change it to <tt class="docutils literal"><span class="pre">-rc</span> <span class="pre">2</span></tt> and so on.</li>
+<li>On non-release testing, you can use <tt class="docutils literal"><span class="pre">-final</span></tt> in conjunction with <tt class="docutils literal"><span class="pre">-no-checkout</span></tt>, but you’ll have to
+create the <tt class="docutils literal"><span class="pre">final</span></tt> directory by hand and link the correct source dir to <tt class="docutils literal"><span class="pre">final/llvm.src</span></tt>.</li>
+<li>For release candidates, you need <tt class="docutils literal"><span class="pre">-test-asserts</span></tt>, or it won’t create a “Release+Asserts” directory,
+which is needed for release testing and benchmarking. This will take twice as long.</li>
+<li>On the final candidate you just need Release builds, and that’s the binary directory you’ll have to pack.</li>
+</ul>
+<p>This script builds three phases of Clang+LLVM twice each (Release and Release+Asserts), so use
+screen or nohup to avoid headaches, since it’ll take a long time.</p>
+<p>Use the <tt class="docutils literal"><span class="pre">--help</span></tt> option to see all the options and chose it according to your needs.</p>
+</div>
+<div class="section" id="findregressions-nightly-py">
+<h3>findRegressions-nightly.py<a class="headerlink" href="#findregressions-nightly-py" title="Permalink to this headline">¶</a></h3>
+<p>TODO</p>
+</div>
+</div>
+<div class="section" id="test-suite">
+<span id="id2"></span><h2><a class="toc-backref" href="#id11">Test Suite</a><a class="headerlink" href="#test-suite" title="Permalink to this headline">¶</a></h2>
+<p>Follow the <a class="reference external" href="http://llvm.org/docs/lnt/quickstart.html">LNT Quick Start Guide</a> link on how to set-up the test-suite</p>
+<p>The binary location you’ll have to use for testing is inside the <tt class="docutils literal"><span class="pre">rcN/Phase3/Release+Asserts/llvmCore-REL-RC.install</span></tt>.
+Link that directory to an easier location and run the test-suite.</p>
+<p>An example on the run command line, assuming you created a link from the correct
+install directory to <tt class="docutils literal"><span class="pre">~/devel/llvm/install</span></tt>:</p>
+<div class="highlight-python"><div class="highlight"><pre>./sandbox/bin/python sandbox/bin/lnt runtest \
+ nt \
+ -j4 \
+ --sandbox sandbox \
+ --test-suite ~/devel/llvm/test/test-suite \
+ --cc ~/devel/llvm/install/bin/clang \
+ --cxx ~/devel/llvm/install/bin/clang++
+</pre></div>
+</div>
+<p>It should have no new regressions, compared to the previous release or release candidate. You don’t need to fix
+all the bugs in the test-suite, since they’re not necessarily meant to pass on all architectures all the time. This is
+due to the nature of the result checking, which relies on direct comparison, and most of the time, the failures are
+related to bad output checking, rather than bad code generation.</p>
+<p>If the errors are in LLVM itself, please report every single regression found as blocker, and all the other bugs
+as important, but not necessarily blocking the release to proceed. They can be set as “known failures” and to be
+fix on a future date.</p>
+</div>
+<div class="section" id="pre-release-process">
+<span id="id4"></span><h2><a class="toc-backref" href="#id12">Pre-Release Process</a><a class="headerlink" href="#pre-release-process" title="Permalink to this headline">¶</a></h2>
+<p>When the release process is announced on the mailing list, you should prepare
+for the testing, by applying the same testing you’ll do on the release candidates,
+on the previous release.</p>
+<p>You should:</p>
+<ul class="simple">
+<li>Download the previous release sources from <a class="reference external" href="http://llvm.org/releases/download.html">http://llvm.org/releases/download.html</a>.</li>
+<li>Run the test-release.sh script on <tt class="docutils literal"><span class="pre">final</span></tt> mode (change <tt class="docutils literal"><span class="pre">-rc</span> <span class="pre">1</span></tt> to <tt class="docutils literal"><span class="pre">-final</span></tt>).</li>
+<li>Once all three stages are done, it’ll test the final stage.</li>
+<li>Using the <tt class="docutils literal"><span class="pre">Phase3/Release+Asserts/llvmCore-MAJ.MIN-final.install</span></tt> base, run the test-suite.</li>
+</ul>
+<p>If the final phase’s <tt class="docutils literal"><span class="pre">make</span> <span class="pre">check-all</span></tt> failed, it’s a good idea to also test the
+intermediate stages by going on the obj directory and running <tt class="docutils literal"><span class="pre">make</span> <span class="pre">check-all</span></tt> to find
+if there’s at least one stage that passes (helps when reducing the error for bug report
+purposes).</p>
+</div>
+<div class="section" id="release-process">
+<span id="id6"></span><h2><a class="toc-backref" href="#id13">Release Process</a><a class="headerlink" href="#release-process" title="Permalink to this headline">¶</a></h2>
+<p>When the Release Manager sends you the release candidate, download all sources,
+unzip on the same directory (there will be sym-links from the appropriate places
+to them), and run the release test as above.</p>
+<p>You should:</p>
+<ul class="simple">
+<li>Download the current candidate sources from where the release manager points you
+(ex. <a class="reference external" href="http://llvm.org/pre-releases/3.3/rc1/">http://llvm.org/pre-releases/3.3/rc1/</a>).</li>
+<li>Repeat the steps above with <tt class="docutils literal"><span class="pre">-rc</span> <span class="pre">1</span></tt>, <tt class="docutils literal"><span class="pre">-rc</span> <span class="pre">2</span></tt> etc modes and run the test-suite
+the same way.</li>
+<li>Compare the results, report all errors on Bugzilla and publish the binary blob
+where the release manager can grab it.</li>
+</ul>
+<p>Once the release manages announces that the latest candidate is the good one, you
+have to pack the <tt class="docutils literal"><span class="pre">Release</span></tt> (no Asserts) install directory on <tt class="docutils literal"><span class="pre">Phase3</span></tt> and that
+will be the official binary.</p>
+<ul class="simple">
+<li>Rename (or link) <tt class="docutils literal"><span class="pre">clang+llvm-REL-ARCH-ENV</span></tt> to the .install directory</li>
+<li>Tar that into the same name with <tt class="docutils literal"><span class="pre">.tar.gz</span></tt> extensioan from outside the directory</li>
+<li>Make it available for the release manager to download</li>
+</ul>
+</div>
+<div class="section" id="bug-reporting-process">
+<span id="bug-reporting"></span><h2><a class="toc-backref" href="#id14">Bug Reporting Process</a><a class="headerlink" href="#bug-reporting-process" title="Permalink to this headline">¶</a></h2>
+<p>If you found regressions or failures when comparing a release candidate with the
+previous release, follow the rules below:</p>
+<ul class="simple">
+<li>Critical bugs on compilation should be fixed as soon as possible, possibly before
+releasing the binary blobs.</li>
+<li>Check-all tests should be fixed before the next release candidate, but can wait
+until the test-suite run is finished.</li>
+<li>Bugs in the test suite or unimportant check-all tests can be fixed in between
+release candidates.</li>
+<li>New features or recent big changes, when close to the release, should have done
+in a way that it’s easy to disable. If they misbehave, prefer disabling them than
+releasing an unstable (but untested) binary package.</li>
+</ul>
+</div>
+</div>
+
+
+ </div>
+ </div>
+ <div class="clearer"></div>
+ </div>
+ <div class="related">
+ <h3>Navigation</h3>
+ <ul>
+ <li class="right" style="margin-right: 10px">
+ <a href="genindex.html" title="General Index"
+ >index</a></li>
+ <li class="right" >
+ <a href="Phabricator.html" title="Code Reviews with Phabricator"
+ >next</a> |</li>
+ <li class="right" >
+ <a href="Packaging.html" title="Advice on Packaging LLVM"
+ >previous</a> |</li>
+ <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+ <li><a href="index.html">Documentation</a>»</li>
+
+ </ul>
+ </div>
+ <div class="footer">
+ © Copyright 2003-2016, LLVM Project.
+ Last updated on 2016-01-04.
+ Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.3.
+ </div>
+ </body>
+</html>
\ No newline at end of file
Added: www-releases/trunk/3.7.1/docs/SegmentedStacks.html
URL: http://llvm.org/viewvc/llvm-project/www-releases/trunk/3.7.1/docs/SegmentedStacks.html?rev=257950&view=auto
==============================================================================
--- www-releases/trunk/3.7.1/docs/SegmentedStacks.html (added)
+++ www-releases/trunk/3.7.1/docs/SegmentedStacks.html Fri Jan 15 17:13:16 2016
@@ -0,0 +1,169 @@
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
+ <title>Segmented Stacks in LLVM — LLVM 3.7 documentation</title>
+
+ <link rel="stylesheet" href="_static/llvm-theme.css" type="text/css" />
+ <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
+
+ <script type="text/javascript">
+ var DOCUMENTATION_OPTIONS = {
+ URL_ROOT: './',
+ VERSION: '3.7',
+ COLLAPSE_INDEX: false,
+ FILE_SUFFIX: '.html',
+ HAS_SOURCE: true
+ };
+ </script>
+ <script type="text/javascript" src="_static/jquery.js"></script>
+ <script type="text/javascript" src="_static/underscore.js"></script>
+ <script type="text/javascript" src="_static/doctools.js"></script>
+ <link rel="top" title="LLVM 3.7 documentation" href="index.html" />
+ <link rel="next" title="TableGen Fundamentals" href="TableGenFundamentals.html" />
+ <link rel="prev" title="LLVM Link Time Optimization: Design and Implementation" href="LinkTimeOptimization.html" />
+<style type="text/css">
+ table.right { float: right; margin-left: 20px; }
+ table.right td { border: 1px solid #ccc; }
+</style>
+
+ </head>
+ <body>
+<div class="logo">
+ <a href="index.html">
+ <img src="_static/logo.png"
+ alt="LLVM Logo" width="250" height="88"/></a>
+</div>
+
+ <div class="related">
+ <h3>Navigation</h3>
+ <ul>
+ <li class="right" style="margin-right: 10px">
+ <a href="genindex.html" title="General Index"
+ accesskey="I">index</a></li>
+ <li class="right" >
+ <a href="TableGenFundamentals.html" title="TableGen Fundamentals"
+ accesskey="N">next</a> |</li>
+ <li class="right" >
+ <a href="LinkTimeOptimization.html" title="LLVM Link Time Optimization: Design and Implementation"
+ accesskey="P">previous</a> |</li>
+ <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+ <li><a href="index.html">Documentation</a>»</li>
+
+ </ul>
+ </div>
+
+
+ <div class="document">
+ <div class="documentwrapper">
+ <div class="body">
+
+ <div class="section" id="segmented-stacks-in-llvm">
+<h1>Segmented Stacks in LLVM<a class="headerlink" href="#segmented-stacks-in-llvm" title="Permalink to this headline">¶</a></h1>
+<div class="contents local topic" id="contents">
+<ul class="simple">
+<li><a class="reference internal" href="#introduction" id="id2">Introduction</a></li>
+<li><a class="reference internal" href="#implementation-details" id="id3">Implementation Details</a><ul>
+<li><a class="reference internal" href="#allocating-stacklets" id="id4">Allocating Stacklets</a></li>
+<li><a class="reference internal" href="#variable-sized-allocas" id="id5">Variable Sized Allocas</a></li>
+</ul>
+</li>
+</ul>
+</div>
+<div class="section" id="introduction">
+<h2><a class="toc-backref" href="#id2">Introduction</a><a class="headerlink" href="#introduction" title="Permalink to this headline">¶</a></h2>
+<p>Segmented stack allows stack space to be allocated incrementally than as a
+monolithic chunk (of some worst case size) at thread initialization. This is
+done by allocating stack blocks (henceforth called <em>stacklets</em>) and linking them
+into a doubly linked list. The function prologue is responsible for checking if
+the current stacklet has enough space for the function to execute; and if not,
+call into the libgcc runtime to allocate more stack space. Segmented stacks are
+enabled with the <tt class="docutils literal"><span class="pre">"split-stack"</span></tt> attribute on LLVM functions.</p>
+<p>The runtime functionality is <a class="reference external" href="http://gcc.gnu.org/wiki/SplitStacks">already there in libgcc</a>.</p>
+</div>
+<div class="section" id="implementation-details">
+<h2><a class="toc-backref" href="#id3">Implementation Details</a><a class="headerlink" href="#implementation-details" title="Permalink to this headline">¶</a></h2>
+<div class="section" id="allocating-stacklets">
+<span id="id1"></span><h3><a class="toc-backref" href="#id4">Allocating Stacklets</a><a class="headerlink" href="#allocating-stacklets" title="Permalink to this headline">¶</a></h3>
+<p>As mentioned above, the function prologue checks if the current stacklet has
+enough space. The current approach is to use a slot in the TCB to store the
+current stack limit (minus the amount of space needed to allocate a new block) -
+this slot’s offset is again dictated by <tt class="docutils literal"><span class="pre">libgcc</span></tt>. The generated
+assembly looks like this on x86-64:</p>
+<div class="highlight-nasm"><div class="highlight"><pre> leaq -8(%rsp), %r10
+ cmpq %fs:112, %r10
+ jg .LBB0_2
+
+ # More stack space needs to be allocated
+ movabsq $8, %r10 # The amount of space needed
+ movabsq $0, %r11 # The total size of arguments passed on stack
+ callq __morestack
+ ret # The reason for this extra return is explained below
+.LBB0_2:
+ # Usual prologue continues here
+</pre></div>
+</div>
+<p>The size of function arguments on the stack needs to be passed to
+<tt class="docutils literal"><span class="pre">__morestack</span></tt> (this function is implemented in <tt class="docutils literal"><span class="pre">libgcc</span></tt>) since that number
+of bytes has to be copied from the previous stacklet to the current one. This is
+so that SP (and FP) relative addressing of function arguments work as expected.</p>
+<p>The unusual <tt class="docutils literal"><span class="pre">ret</span></tt> is needed to have the function which made a call to
+<tt class="docutils literal"><span class="pre">__morestack</span></tt> return correctly. <tt class="docutils literal"><span class="pre">__morestack</span></tt>, instead of returning, calls
+into <tt class="docutils literal"><span class="pre">.LBB0_2</span></tt>. This is possible since both, the size of the <tt class="docutils literal"><span class="pre">ret</span></tt>
+instruction and the PC of call to <tt class="docutils literal"><span class="pre">__morestack</span></tt> are known. When the function
+body returns, control is transferred back to <tt class="docutils literal"><span class="pre">__morestack</span></tt>. <tt class="docutils literal"><span class="pre">__morestack</span></tt>
+then de-allocates the new stacklet, restores the correct SP value, and does a
+second return, which returns control to the correct caller.</p>
+</div>
+<div class="section" id="variable-sized-allocas">
+<h3><a class="toc-backref" href="#id5">Variable Sized Allocas</a><a class="headerlink" href="#variable-sized-allocas" title="Permalink to this headline">¶</a></h3>
+<p>The section on <a class="reference internal" href="#allocating-stacklets">allocating stacklets</a> automatically assumes that every stack
+frame will be of fixed size. However, LLVM allows the use of the <tt class="docutils literal"><span class="pre">llvm.alloca</span></tt>
+intrinsic to allocate dynamically sized blocks of memory on the stack. When
+faced with such a variable-sized alloca, code is generated to:</p>
+<ul class="simple">
+<li>Check if the current stacklet has enough space. If yes, just bump the SP, like
+in the normal case.</li>
+<li>If not, generate a call to <tt class="docutils literal"><span class="pre">libgcc</span></tt>, which allocates the memory from the
+heap.</li>
+</ul>
+<p>The memory allocated from the heap is linked into a list in the current
+stacklet, and freed along with the same. This prevents a memory leak.</p>
+</div>
+</div>
+</div>
+
+
+ </div>
+ </div>
+ <div class="clearer"></div>
+ </div>
+ <div class="related">
+ <h3>Navigation</h3>
+ <ul>
+ <li class="right" style="margin-right: 10px">
+ <a href="genindex.html" title="General Index"
+ >index</a></li>
+ <li class="right" >
+ <a href="TableGenFundamentals.html" title="TableGen Fundamentals"
+ >next</a> |</li>
+ <li class="right" >
+ <a href="LinkTimeOptimization.html" title="LLVM Link Time Optimization: Design and Implementation"
+ >previous</a> |</li>
+ <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+ <li><a href="index.html">Documentation</a>»</li>
+
+ </ul>
+ </div>
+ <div class="footer">
+ © Copyright 2003-2016, LLVM Project.
+ Last updated on 2016-01-04.
+ Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.3.
+ </div>
+ </body>
+</html>
\ No newline at end of file
Added: www-releases/trunk/3.7.1/docs/SourceLevelDebugging.html
URL: http://llvm.org/viewvc/llvm-project/www-releases/trunk/3.7.1/docs/SourceLevelDebugging.html?rev=257950&view=auto
==============================================================================
--- www-releases/trunk/3.7.1/docs/SourceLevelDebugging.html (added)
+++ www-releases/trunk/3.7.1/docs/SourceLevelDebugging.html Fri Jan 15 17:13:16 2016
@@ -0,0 +1,1375 @@
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
+ <title>Source Level Debugging with LLVM — LLVM 3.7 documentation</title>
+
+ <link rel="stylesheet" href="_static/llvm-theme.css" type="text/css" />
+ <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
+
+ <script type="text/javascript">
+ var DOCUMENTATION_OPTIONS = {
+ URL_ROOT: './',
+ VERSION: '3.7',
+ COLLAPSE_INDEX: false,
+ FILE_SUFFIX: '.html',
+ HAS_SOURCE: true
+ };
+ </script>
+ <script type="text/javascript" src="_static/jquery.js"></script>
+ <script type="text/javascript" src="_static/underscore.js"></script>
+ <script type="text/javascript" src="_static/doctools.js"></script>
+ <link rel="top" title="LLVM 3.7 documentation" href="index.html" />
+ <link rel="next" title="Auto-Vectorization in LLVM" href="Vectorizers.html" />
+ <link rel="prev" title="System Library" href="SystemLibrary.html" />
+<style type="text/css">
+ table.right { float: right; margin-left: 20px; }
+ table.right td { border: 1px solid #ccc; }
+</style>
+
+ </head>
+ <body>
+<div class="logo">
+ <a href="index.html">
+ <img src="_static/logo.png"
+ alt="LLVM Logo" width="250" height="88"/></a>
+</div>
+
+ <div class="related">
+ <h3>Navigation</h3>
+ <ul>
+ <li class="right" style="margin-right: 10px">
+ <a href="genindex.html" title="General Index"
+ accesskey="I">index</a></li>
+ <li class="right" >
+ <a href="Vectorizers.html" title="Auto-Vectorization in LLVM"
+ accesskey="N">next</a> |</li>
+ <li class="right" >
+ <a href="SystemLibrary.html" title="System Library"
+ accesskey="P">previous</a> |</li>
+ <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+ <li><a href="index.html">Documentation</a>»</li>
+
+ </ul>
+ </div>
+
+
+ <div class="document">
+ <div class="documentwrapper">
+ <div class="body">
+
+ <div class="section" id="source-level-debugging-with-llvm">
+<h1>Source Level Debugging with LLVM<a class="headerlink" href="#source-level-debugging-with-llvm" title="Permalink to this headline">¶</a></h1>
+<div class="contents local topic" id="contents">
+<ul class="simple">
+<li><a class="reference internal" href="#introduction" id="id7">Introduction</a><ul>
+<li><a class="reference internal" href="#philosophy-behind-llvm-debugging-information" id="id8">Philosophy behind LLVM debugging information</a></li>
+<li><a class="reference internal" href="#debug-information-consumers" id="id9">Debug information consumers</a></li>
+<li><a class="reference internal" href="#debugging-optimized-code" id="id10">Debugging optimized code</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#debugging-information-format" id="id11">Debugging information format</a><ul>
+<li><a class="reference internal" href="#debugger-intrinsic-functions" id="id12">Debugger intrinsic functions</a><ul>
+<li><a class="reference internal" href="#llvm-dbg-declare" id="id13"><tt class="docutils literal"><span class="pre">llvm.dbg.declare</span></tt></a></li>
+<li><a class="reference internal" href="#llvm-dbg-value" id="id14"><tt class="docutils literal"><span class="pre">llvm.dbg.value</span></tt></a></li>
+</ul>
+</li>
+</ul>
+</li>
+<li><a class="reference internal" href="#object-lifetimes-and-scoping" id="id15">Object lifetimes and scoping</a></li>
+<li><a class="reference internal" href="#c-c-front-end-specific-debug-information" id="id16">C/C++ front-end specific debug information</a><ul>
+<li><a class="reference internal" href="#c-c-source-file-information" id="id17">C/C++ source file information</a></li>
+<li><a class="reference internal" href="#c-c-global-variable-information" id="id18">C/C++ global variable information</a></li>
+<li><a class="reference internal" href="#c-c-function-information" id="id19">C/C++ function information</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#id3" id="id20">Debugging information format</a><ul>
+<li><a class="reference internal" href="#debugging-information-extension-for-objective-c-properties" id="id21">Debugging Information Extension for Objective C Properties</a><ul>
+<li><a class="reference internal" href="#id4" id="id22">Introduction</a></li>
+<li><a class="reference internal" href="#proposal" id="id23">Proposal</a></li>
+<li><a class="reference internal" href="#new-dwarf-tags" id="id24">New DWARF Tags</a></li>
+<li><a class="reference internal" href="#new-dwarf-attributes" id="id25">New DWARF Attributes</a></li>
+<li><a class="reference internal" href="#new-dwarf-constants" id="id26">New DWARF Constants</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#name-accelerator-tables" id="id27">Name Accelerator Tables</a><ul>
+<li><a class="reference internal" href="#id5" id="id28">Introduction</a></li>
+<li><a class="reference internal" href="#hash-tables" id="id29">Hash Tables</a><ul>
+<li><a class="reference internal" href="#standard-hash-tables" id="id30">Standard Hash Tables</a></li>
+<li><a class="reference internal" href="#name-hash-tables" id="id31">Name Hash Tables</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#details" id="id32">Details</a><ul>
+<li><a class="reference internal" href="#header-layout" id="id33">Header Layout</a></li>
+<li><a class="reference internal" href="#fixed-lookup" id="id34">Fixed Lookup</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#id6" id="id35">Contents</a></li>
+<li><a class="reference internal" href="#language-extensions-and-file-format-changes" id="id36">Language Extensions and File Format Changes</a><ul>
+<li><a class="reference internal" href="#objective-c-extensions" id="id37">Objective-C Extensions</a></li>
+<li><a class="reference internal" href="#mach-o-changes" id="id38">Mach-O Changes</a></li>
+</ul>
+</li>
+</ul>
+</li>
+</ul>
+</li>
+</ul>
+</div>
+<div class="section" id="introduction">
+<h2><a class="toc-backref" href="#id7">Introduction</a><a class="headerlink" href="#introduction" title="Permalink to this headline">¶</a></h2>
+<p>This document is the central repository for all information pertaining to debug
+information in LLVM. It describes the <a class="reference internal" href="#format"><em>actual format that the LLVM debug
+information takes</em></a>, which is useful for those interested in creating
+front-ends or dealing directly with the information. Further, this document
+provides specific examples of what debug information for C/C++ looks like.</p>
+<div class="section" id="philosophy-behind-llvm-debugging-information">
+<h3><a class="toc-backref" href="#id8">Philosophy behind LLVM debugging information</a><a class="headerlink" href="#philosophy-behind-llvm-debugging-information" title="Permalink to this headline">¶</a></h3>
+<p>The idea of the LLVM debugging information is to capture how the important
+pieces of the source-language’s Abstract Syntax Tree map onto LLVM code.
+Several design aspects have shaped the solution that appears here. The
+important ones are:</p>
+<ul class="simple">
+<li>Debugging information should have very little impact on the rest of the
+compiler. No transformations, analyses, or code generators should need to
+be modified because of debugging information.</li>
+<li>LLVM optimizations should interact in <a class="reference internal" href="#intro-debugopt"><em>well-defined and easily described
+ways</em></a> with the debugging information.</li>
+<li>Because LLVM is designed to support arbitrary programming languages,
+LLVM-to-LLVM tools should not need to know anything about the semantics of
+the source-level-language.</li>
+<li>Source-level languages are often <strong>widely</strong> different from one another.
+LLVM should not put any restrictions of the flavor of the source-language,
+and the debugging information should work with any language.</li>
+<li>With code generator support, it should be possible to use an LLVM compiler
+to compile a program to native machine code and standard debugging
+formats. This allows compatibility with traditional machine-code level
+debuggers, like GDB or DBX.</li>
+</ul>
+<p>The approach used by the LLVM implementation is to use a small set of
+<a class="reference internal" href="#format-common-intrinsics"><em>intrinsic functions</em></a> to define a mapping
+between LLVM program objects and the source-level objects. The description of
+the source-level program is maintained in LLVM metadata in an
+<a class="reference internal" href="#ccxx-frontend"><em>implementation-defined format</em></a> (the C/C++ front-end
+currently uses working draft 7 of the <a class="reference external" href="http://www.eagercon.com/dwarf/dwarf3std.htm">DWARF 3 standard</a>).</p>
+<p>When a program is being debugged, a debugger interacts with the user and turns
+the stored debug information into source-language specific information. As
+such, a debugger must be aware of the source-language, and is thus tied to a
+specific language or family of languages.</p>
+</div>
+<div class="section" id="debug-information-consumers">
+<h3><a class="toc-backref" href="#id9">Debug information consumers</a><a class="headerlink" href="#debug-information-consumers" title="Permalink to this headline">¶</a></h3>
+<p>The role of debug information is to provide meta information normally stripped
+away during the compilation process. This meta information provides an LLVM
+user a relationship between generated code and the original program source
+code.</p>
+<p>Currently, debug information is consumed by DwarfDebug to produce dwarf
+information used by the gdb debugger. Other targets could use the same
+information to produce stabs or other debug forms.</p>
+<p>It would also be reasonable to use debug information to feed profiling tools
+for analysis of generated code, or, tools for reconstructing the original
+source from generated code.</p>
+<p>TODO - expound a bit more.</p>
+</div>
+<div class="section" id="debugging-optimized-code">
+<span id="intro-debugopt"></span><h3><a class="toc-backref" href="#id10">Debugging optimized code</a><a class="headerlink" href="#debugging-optimized-code" title="Permalink to this headline">¶</a></h3>
+<p>An extremely high priority of LLVM debugging information is to make it interact
+well with optimizations and analysis. In particular, the LLVM debug
+information provides the following guarantees:</p>
+<ul class="simple">
+<li>LLVM debug information <strong>always provides information to accurately read
+the source-level state of the program</strong>, regardless of which LLVM
+optimizations have been run, and without any modification to the
+optimizations themselves. However, some optimizations may impact the
+ability to modify the current state of the program with a debugger, such
+as setting program variables, or calling functions that have been
+deleted.</li>
+<li>As desired, LLVM optimizations can be upgraded to be aware of the LLVM
+debugging information, allowing them to update the debugging information
+as they perform aggressive optimizations. This means that, with effort,
+the LLVM optimizers could optimize debug code just as well as non-debug
+code.</li>
+<li>LLVM debug information does not prevent optimizations from
+happening (for example inlining, basic block reordering/merging/cleanup,
+tail duplication, etc).</li>
+<li>LLVM debug information is automatically optimized along with the rest of
+the program, using existing facilities. For example, duplicate
+information is automatically merged by the linker, and unused information
+is automatically removed.</li>
+</ul>
+<p>Basically, the debug information allows you to compile a program with
+“<tt class="docutils literal"><span class="pre">-O0</span> <span class="pre">-g</span></tt>” and get full debug information, allowing you to arbitrarily modify
+the program as it executes from a debugger. Compiling a program with
+“<tt class="docutils literal"><span class="pre">-O3</span> <span class="pre">-g</span></tt>” gives you full debug information that is always available and
+accurate for reading (e.g., you get accurate stack traces despite tail call
+elimination and inlining), but you might lose the ability to modify the program
+and call functions where were optimized out of the program, or inlined away
+completely.</p>
+<p><a class="reference internal" href="TestingGuide.html#test-suite-quickstart"><em>LLVM test suite</em></a> provides a framework to test
+optimizer’s handling of debugging information. It can be run like this:</p>
+<div class="highlight-bash"><div class="highlight"><pre>% <span class="nb">cd </span>llvm/projects/test-suite/MultiSource/Benchmarks <span class="c"># or some other level</span>
+% make <span class="nv">TEST</span><span class="o">=</span>dbgopt
+</pre></div>
+</div>
+<p>This will test impact of debugging information on optimization passes. If
+debugging information influences optimization passes then it will be reported
+as a failure. See <a class="reference internal" href="TestingGuide.html"><em>LLVM Testing Infrastructure Guide</em></a> for more information on LLVM test
+infrastructure and how to run various tests.</p>
+</div>
+</div>
+<div class="section" id="debugging-information-format">
+<span id="format"></span><h2><a class="toc-backref" href="#id11">Debugging information format</a><a class="headerlink" href="#debugging-information-format" title="Permalink to this headline">¶</a></h2>
+<p>LLVM debugging information has been carefully designed to make it possible for
+the optimizer to optimize the program and debugging information without
+necessarily having to know anything about debugging information. In
+particular, the use of metadata avoids duplicated debugging information from
+the beginning, and the global dead code elimination pass automatically deletes
+debugging information for a function if it decides to delete the function.</p>
+<p>To do this, most of the debugging information (descriptors for types,
+variables, functions, source files, etc) is inserted by the language front-end
+in the form of LLVM metadata.</p>
+<p>Debug information is designed to be agnostic about the target debugger and
+debugging information representation (e.g. DWARF/Stabs/etc). It uses a generic
+pass to decode the information that represents variables, types, functions,
+namespaces, etc: this allows for arbitrary source-language semantics and
+type-systems to be used, as long as there is a module written for the target
+debugger to interpret the information.</p>
+<p>To provide basic functionality, the LLVM debugger does have to make some
+assumptions about the source-level language being debugged, though it keeps
+these to a minimum. The only common features that the LLVM debugger assumes
+exist are <a class="reference external" href="LangRef.html#difile">source files</a>, and <a class="reference external" href="LangRef.html#diglobalvariable">program objects</a>. These abstract objects are used by a
+debugger to form stack traces, show information about local variables, etc.</p>
+<p>This section of the documentation first describes the representation aspects
+common to any source-language. <a class="reference internal" href="#ccxx-frontend"><em>C/C++ front-end specific debug information</em></a> describes the data layout
+conventions used by the C and C++ front-ends.</p>
+<p>Debug information descriptors are <a class="reference external" href="LangRef.html#specialized-metadata">specialized metadata nodes</a>, first-class subclasses of <tt class="docutils literal"><span class="pre">Metadata</span></tt>.</p>
+<div class="section" id="debugger-intrinsic-functions">
+<span id="format-common-intrinsics"></span><h3><a class="toc-backref" href="#id12">Debugger intrinsic functions</a><a class="headerlink" href="#debugger-intrinsic-functions" title="Permalink to this headline">¶</a></h3>
+<p>LLVM uses several intrinsic functions (name prefixed with “<tt class="docutils literal"><span class="pre">llvm.dbg</span></tt>”) to
+provide debug information at various points in generated code.</p>
+<div class="section" id="llvm-dbg-declare">
+<h4><a class="toc-backref" href="#id13"><tt class="docutils literal"><span class="pre">llvm.dbg.declare</span></tt></a><a class="headerlink" href="#llvm-dbg-declare" title="Permalink to this headline">¶</a></h4>
+<div class="highlight-llvm"><div class="highlight"><pre><span class="kt">void</span> <span class="vg">@llvm.dbg.declare</span><span class="p">(</span><span class="kt">metadata</span><span class="p">,</span> <span class="kt">metadata</span><span class="p">,</span> <span class="kt">metadata</span><span class="p">)</span>
+</pre></div>
+</div>
+<p>This intrinsic provides information about a local element (e.g., variable).
+The first argument is metadata holding the alloca for the variable. The second
+argument is a <a class="reference external" href="LangRef.html#dilocalvariable">local variable</a> containing a
+description of the variable. The third argument is a <a class="reference external" href="LangRef.html#diexpression">complex expression</a>.</p>
+</div>
+<div class="section" id="llvm-dbg-value">
+<h4><a class="toc-backref" href="#id14"><tt class="docutils literal"><span class="pre">llvm.dbg.value</span></tt></a><a class="headerlink" href="#llvm-dbg-value" title="Permalink to this headline">¶</a></h4>
+<div class="highlight-llvm"><div class="highlight"><pre><span class="kt">void</span> <span class="vg">@llvm.dbg.value</span><span class="p">(</span><span class="kt">metadata</span><span class="p">,</span> <span class="k">i64</span><span class="p">,</span> <span class="kt">metadata</span><span class="p">,</span> <span class="kt">metadata</span><span class="p">)</span>
+</pre></div>
+</div>
+<p>This intrinsic provides information when a user source variable is set to a new
+value. The first argument is the new value (wrapped as metadata). The second
+argument is the offset in the user source variable where the new value is
+written. The third argument is a <a class="reference external" href="LangRef.html#dilocalvariable">local variable</a> containing a description of the variable. The
+third argument is a <a class="reference external" href="LangRef.html#diexpression">complex expression</a>.</p>
+</div>
+</div>
+</div>
+<div class="section" id="object-lifetimes-and-scoping">
+<h2><a class="toc-backref" href="#id15">Object lifetimes and scoping</a><a class="headerlink" href="#object-lifetimes-and-scoping" title="Permalink to this headline">¶</a></h2>
+<p>In many languages, the local variables in functions can have their lifetimes or
+scopes limited to a subset of a function. In the C family of languages, for
+example, variables are only live (readable and writable) within the source
+block that they are defined in. In functional languages, values are only
+readable after they have been defined. Though this is a very obvious concept,
+it is non-trivial to model in LLVM, because it has no notion of scoping in this
+sense, and does not want to be tied to a language’s scoping rules.</p>
+<p>In order to handle this, the LLVM debug format uses the metadata attached to
+llvm instructions to encode line number and scoping information. Consider the
+following C fragment, for example:</p>
+<div class="highlight-c"><div class="highlight"><pre><span class="mf">1.</span> <span class="kt">void</span> <span class="n">foo</span><span class="p">()</span> <span class="p">{</span>
+<span class="mf">2.</span> <span class="kt">int</span> <span class="n">X</span> <span class="o">=</span> <span class="mi">21</span><span class="p">;</span>
+<span class="mf">3.</span> <span class="kt">int</span> <span class="n">Y</span> <span class="o">=</span> <span class="mi">22</span><span class="p">;</span>
+<span class="mf">4.</span> <span class="p">{</span>
+<span class="mf">5.</span> <span class="kt">int</span> <span class="n">Z</span> <span class="o">=</span> <span class="mi">23</span><span class="p">;</span>
+<span class="mf">6.</span> <span class="n">Z</span> <span class="o">=</span> <span class="n">X</span><span class="p">;</span>
+<span class="mf">7.</span> <span class="p">}</span>
+<span class="mf">8.</span> <span class="n">X</span> <span class="o">=</span> <span class="n">Y</span><span class="p">;</span>
+<span class="mf">9.</span> <span class="p">}</span>
+</pre></div>
+</div>
+<p>Compiled to LLVM, this function would be represented like this:</p>
+<div class="highlight-llvm"><div class="highlight"><pre>; Function Attrs: nounwind ssp uwtable
+define void @foo() #0 {
+entry:
+ %X = alloca i32, align 4
+ %Y = alloca i32, align 4
+ %Z = alloca i32, align 4
+ call void @llvm.dbg.declare(metadata i32* %X, metadata !11, metadata !13), !dbg !14
+ store i32 21, i32* %X, align 4, !dbg !14
+ call void @llvm.dbg.declare(metadata i32* %Y, metadata !15, metadata !13), !dbg !16
+ store i32 22, i32* %Y, align 4, !dbg !16
+ call void @llvm.dbg.declare(metadata i32* %Z, metadata !17, metadata !13), !dbg !19
+ store i32 23, i32* %Z, align 4, !dbg !19
+ %0 = load i32, i32* %X, align 4, !dbg !20
+ store i32 %0, i32* %Z, align 4, !dbg !21
+ %1 = load i32, i32* %Y, align 4, !dbg !22
+ store i32 %1, i32* %X, align 4, !dbg !23
+ ret void, !dbg !24
+}
+
+; Function Attrs: nounwind readnone
+declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
+
+attributes #0 = { nounwind ssp uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #1 = { nounwind readnone }
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!7, !8, !9}
+!llvm.ident = !{!10}
+
+!0 = !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.7.0 (trunk 231150) (llvm/trunk 231154)", isOptimized: false, runtimeVersion: 0, emissionKind: 1, enums: !2, retainedTypes: !2, subprograms: !3, globals: !2, imports: !2)
+!1 = !DIFile(filename: "/dev/stdin", directory: "/Users/dexonsmith/data/llvm/debug-info")
+!2 = !{}
+!3 = !{!4}
+!4 = !DISubprogram(name: "foo", scope: !1, file: !1, line: 1, type: !5, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: false, function: void ()* @foo, variables: !2)
+!5 = !DISubroutineType(types: !6)
+!6 = !{null}
+!7 = !{i32 2, !"Dwarf Version", i32 2}
+!8 = !{i32 2, !"Debug Info Version", i32 3}
+!9 = !{i32 1, !"PIC Level", i32 2}
+!10 = !{!"clang version 3.7.0 (trunk 231150) (llvm/trunk 231154)"}
+!11 = !DILocalVariable(tag: DW_TAG_auto_variable, name: "X", scope: !4, file: !1, line: 2, type: !12)
+!12 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
+!13 = !DIExpression()
+!14 = !DILocation(line: 2, column: 9, scope: !4)
+!15 = !DILocalVariable(tag: DW_TAG_auto_variable, name: "Y", scope: !4, file: !1, line: 3, type: !12)
+!16 = !DILocation(line: 3, column: 9, scope: !4)
+!17 = !DILocalVariable(tag: DW_TAG_auto_variable, name: "Z", scope: !18, file: !1, line: 5, type: !12)
+!18 = distinct !DILexicalBlock(scope: !4, file: !1, line: 4, column: 5)
+!19 = !DILocation(line: 5, column: 11, scope: !18)
+!20 = !DILocation(line: 6, column: 11, scope: !18)
+!21 = !DILocation(line: 6, column: 9, scope: !18)
+!22 = !DILocation(line: 8, column: 9, scope: !4)
+!23 = !DILocation(line: 8, column: 7, scope: !4)
+!24 = !DILocation(line: 9, column: 3, scope: !4)
+</pre></div>
+</div>
+<p>This example illustrates a few important details about LLVM debugging
+information. In particular, it shows how the <tt class="docutils literal"><span class="pre">llvm.dbg.declare</span></tt> intrinsic and
+location information, which are attached to an instruction, are applied
+together to allow a debugger to analyze the relationship between statements,
+variable definitions, and the code used to implement the function.</p>
+<div class="highlight-llvm"><div class="highlight"><pre><span class="k">call</span> <span class="kt">void</span> <span class="vg">@llvm.dbg.declare</span><span class="p">(</span><span class="kt">metadata</span> <span class="k">i32</span><span class="p">*</span> <span class="nv">%X</span><span class="p">,</span> <span class="kt">metadata</span> <span class="nv-Anonymous">!11</span><span class="p">,</span> <span class="kt">metadata</span> <span class="nv-Anonymous">!13</span><span class="p">),</span> <span class="nv">!dbg</span> <span class="nv-Anonymous">!14</span>
+ <span class="c">; [debug line = 2:7] [debug variable = X]</span>
+</pre></div>
+</div>
+<p>The first intrinsic <tt class="docutils literal"><span class="pre">%llvm.dbg.declare</span></tt> encodes debugging information for the
+variable <tt class="docutils literal"><span class="pre">X</span></tt>. The metadata <tt class="docutils literal"><span class="pre">!dbg</span> <span class="pre">!14</span></tt> attached to the intrinsic provides
+scope information for the variable <tt class="docutils literal"><span class="pre">X</span></tt>.</p>
+<div class="highlight-llvm"><div class="highlight"><pre><span class="nv-Anonymous">!14</span> <span class="p">=</span> <span class="nv">!DILocation</span><span class="p">(</span><span class="nl">line:</span> <span class="m">2</span><span class="p">,</span> <span class="nl">column:</span> <span class="m">9</span><span class="p">,</span> <span class="nl">scope:</span> <span class="nv-Anonymous">!4</span><span class="p">)</span>
+<span class="nv-Anonymous">!4</span> <span class="p">=</span> <span class="nv">!DISubprogram</span><span class="p">(</span><span class="nl">name:</span> <span class="s">"foo"</span><span class="p">,</span> <span class="nl">scope:</span> <span class="nv-Anonymous">!1</span><span class="p">,</span> <span class="nl">file:</span> <span class="nv-Anonymous">!1</span><span class="p">,</span> <span class="nl">line:</span> <span class="m">1</span><span class="p">,</span> <span class="nl">type:</span> <span class="nv-Anonymous">!5</span><span class="p">,</span>
+ <span class="nl">isLocal:</span> <span class="k">false</span><span class="p">,</span> <span class="nl">isDefinition:</span> <span class="k">true</span><span class="p">,</span> <span class="nl">scopeLine:</span> <span class="m">1</span><span class="p">,</span>
+ <span class="nl">isOptimized:</span> <span class="k">false</span><span class="p">,</span> <span class="nl">function:</span> <span class="kt">void</span> <span class="p">()*</span> <span class="vg">@foo</span><span class="p">,</span>
+ <span class="nl">variables:</span> <span class="nv-Anonymous">!2</span><span class="p">)</span>
+</pre></div>
+</div>
+<p>Here <tt class="docutils literal"><span class="pre">!14</span></tt> is metadata providing <a class="reference external" href="LangRef.html#dilocation">location information</a>. In this example, scope is encoded by <tt class="docutils literal"><span class="pre">!4</span></tt>, a
+<a class="reference external" href="LangRef.html#disubprogram">subprogram descriptor</a>. This way the location
+information attached to the intrinsics indicates that the variable <tt class="docutils literal"><span class="pre">X</span></tt> is
+declared at line number 2 at a function level scope in function <tt class="docutils literal"><span class="pre">foo</span></tt>.</p>
+<p>Now lets take another example.</p>
+<div class="highlight-llvm"><div class="highlight"><pre><span class="k">call</span> <span class="kt">void</span> <span class="vg">@llvm.dbg.declare</span><span class="p">(</span><span class="kt">metadata</span> <span class="k">i32</span><span class="p">*</span> <span class="nv">%Z</span><span class="p">,</span> <span class="kt">metadata</span> <span class="nv-Anonymous">!17</span><span class="p">,</span> <span class="kt">metadata</span> <span class="nv-Anonymous">!13</span><span class="p">),</span> <span class="nv">!dbg</span> <span class="nv-Anonymous">!19</span>
+ <span class="c">; [debug line = 5:9] [debug variable = Z]</span>
+</pre></div>
+</div>
+<p>The third intrinsic <tt class="docutils literal"><span class="pre">%llvm.dbg.declare</span></tt> encodes debugging information for
+variable <tt class="docutils literal"><span class="pre">Z</span></tt>. The metadata <tt class="docutils literal"><span class="pre">!dbg</span> <span class="pre">!19</span></tt> attached to the intrinsic provides
+scope information for the variable <tt class="docutils literal"><span class="pre">Z</span></tt>.</p>
+<div class="highlight-llvm"><div class="highlight"><pre>!18 = distinct !DILexicalBlock(scope: !4, file: !1, line: 4, column: 5)
+!19 = !DILocation(line: 5, column: 11, scope: !18)
+</pre></div>
+</div>
+<p>Here <tt class="docutils literal"><span class="pre">!19</span></tt> indicates that <tt class="docutils literal"><span class="pre">Z</span></tt> is declared at line number 5 and column
+number 0 inside of lexical scope <tt class="docutils literal"><span class="pre">!18</span></tt>. The lexical scope itself resides
+inside of subprogram <tt class="docutils literal"><span class="pre">!4</span></tt> described above.</p>
+<p>The scope information attached with each instruction provides a straightforward
+way to find instructions covered by a scope.</p>
+</div>
+<div class="section" id="c-c-front-end-specific-debug-information">
+<span id="ccxx-frontend"></span><h2><a class="toc-backref" href="#id16">C/C++ front-end specific debug information</a><a class="headerlink" href="#c-c-front-end-specific-debug-information" title="Permalink to this headline">¶</a></h2>
+<p>The C and C++ front-ends represent information about the program in a format
+that is effectively identical to <a class="reference external" href="http://www.eagercon.com/dwarf/dwarf3std.htm">DWARF 3.0</a> in terms of information
+content. This allows code generators to trivially support native debuggers by
+generating standard dwarf information, and contains enough information for
+non-dwarf targets to translate it as needed.</p>
+<p>This section describes the forms used to represent C and C++ programs. Other
+languages could pattern themselves after this (which itself is tuned to
+representing programs in the same way that DWARF 3 does), or they could choose
+to provide completely different forms if they don’t fit into the DWARF model.
+As support for debugging information gets added to the various LLVM
+source-language front-ends, the information used should be documented here.</p>
+<p>The following sections provide examples of a few C/C++ constructs and the debug
+information that would best describe those constructs. The canonical
+references are the <tt class="docutils literal"><span class="pre">DIDescriptor</span></tt> classes defined in
+<tt class="docutils literal"><span class="pre">include/llvm/IR/DebugInfo.h</span></tt> and the implementations of the helper functions
+in <tt class="docutils literal"><span class="pre">lib/IR/DIBuilder.cpp</span></tt>.</p>
+<div class="section" id="c-c-source-file-information">
+<h3><a class="toc-backref" href="#id17">C/C++ source file information</a><a class="headerlink" href="#c-c-source-file-information" title="Permalink to this headline">¶</a></h3>
+<p><tt class="docutils literal"><span class="pre">llvm::Instruction</span></tt> provides easy access to metadata attached with an
+instruction. One can extract line number information encoded in LLVM IR using
+<tt class="docutils literal"><span class="pre">Instruction::getMetadata()</span></tt> and <tt class="docutils literal"><span class="pre">DILocation::getLineNumber()</span></tt>.</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="k">if</span> <span class="p">(</span><span class="n">MDNode</span> <span class="o">*</span><span class="n">N</span> <span class="o">=</span> <span class="n">I</span><span class="o">-></span><span class="n">getMetadata</span><span class="p">(</span><span class="s">"dbg"</span><span class="p">))</span> <span class="p">{</span> <span class="c1">// Here I is an LLVM instruction</span>
+ <span class="n">DILocation</span> <span class="n">Loc</span><span class="p">(</span><span class="n">N</span><span class="p">);</span> <span class="c1">// DILocation is in DebugInfo.h</span>
+ <span class="kt">unsigned</span> <span class="n">Line</span> <span class="o">=</span> <span class="n">Loc</span><span class="p">.</span><span class="n">getLineNumber</span><span class="p">();</span>
+ <span class="n">StringRef</span> <span class="n">File</span> <span class="o">=</span> <span class="n">Loc</span><span class="p">.</span><span class="n">getFilename</span><span class="p">();</span>
+ <span class="n">StringRef</span> <span class="n">Dir</span> <span class="o">=</span> <span class="n">Loc</span><span class="p">.</span><span class="n">getDirectory</span><span class="p">();</span>
+<span class="p">}</span>
+</pre></div>
+</div>
+</div>
+<div class="section" id="c-c-global-variable-information">
+<h3><a class="toc-backref" href="#id18">C/C++ global variable information</a><a class="headerlink" href="#c-c-global-variable-information" title="Permalink to this headline">¶</a></h3>
+<p>Given an integer global variable declared as follows:</p>
+<div class="highlight-c"><div class="highlight"><pre><span class="kt">int</span> <span class="n">MyGlobal</span> <span class="o">=</span> <span class="mi">100</span><span class="p">;</span>
+</pre></div>
+</div>
+<p>a C/C++ front-end would generate the following descriptors:</p>
+<div class="highlight-llvm"><div class="highlight"><pre>;;
+;; Define the global itself.
+;;
+ at MyGlobal = global i32 100, align 4
+
+;;
+;; List of debug info of globals
+;;
+!llvm.dbg.cu = !{!0}
+
+;; Some unrelated metadata.
+!llvm.module.flags = !{!6, !7}
+
+;; Define the compile unit.
+!0 = !DICompileUnit(language: DW_LANG_C99, file: !1,
+ producer:
+ "clang version 3.7.0 (trunk 231150) (llvm/trunk 231154)",
+ isOptimized: false, runtimeVersion: 0, emissionKind: 1,
+ enums: !2, retainedTypes: !2, subprograms: !2, globals:
+ !3, imports: !2)
+
+;;
+;; Define the file
+;;
+!1 = !DIFile(filename: "/dev/stdin",
+ directory: "/Users/dexonsmith/data/llvm/debug-info")
+
+;; An empty array.
+!2 = !{}
+
+;; The Array of Global Variables
+!3 = !{!4}
+
+;;
+;; Define the global variable itself.
+;;
+!4 = !DIGlobalVariable(name: "MyGlobal", scope: !0, file: !1, line: 1,
+ type: !5, isLocal: false, isDefinition: true,
+ variable: i32* @MyGlobal)
+
+;;
+;; Define the type
+;;
+!5 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
+
+;; Dwarf version to output.
+!6 = !{i32 2, !"Dwarf Version", i32 2}
+
+;; Debug info schema version.
+!7 = !{i32 2, !"Debug Info Version", i32 3}
+</pre></div>
+</div>
+</div>
+<div class="section" id="c-c-function-information">
+<h3><a class="toc-backref" href="#id19">C/C++ function information</a><a class="headerlink" href="#c-c-function-information" title="Permalink to this headline">¶</a></h3>
+<p>Given a function declared as follows:</p>
+<div class="highlight-c"><div class="highlight"><pre><span class="kt">int</span> <span class="nf">main</span><span class="p">(</span><span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="kt">char</span> <span class="o">*</span><span class="n">argv</span><span class="p">[])</span> <span class="p">{</span>
+ <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
+<span class="p">}</span>
+</pre></div>
+</div>
+<p>a C/C++ front-end would generate the following descriptors:</p>
+<div class="highlight-llvm"><div class="highlight"><pre>;;
+;; Define the anchor for subprograms.
+;;
+!4 = !DISubprogram(name: "main", scope: !1, file: !1, line: 1, type: !5,
+ isLocal: false, isDefinition: true, scopeLine: 1,
+ flags: DIFlagPrototyped, isOptimized: false,
+ function: i32 (i32, i8**)* @main, variables: !2)
+
+;;
+;; Define the subprogram itself.
+;;
+define i32 @main(i32 %argc, i8** %argv) {
+...
+}
+</pre></div>
+</div>
+</div>
+</div>
+<div class="section" id="id3">
+<h2><a class="toc-backref" href="#id20">Debugging information format</a><a class="headerlink" href="#id3" title="Permalink to this headline">¶</a></h2>
+<div class="section" id="debugging-information-extension-for-objective-c-properties">
+<h3><a class="toc-backref" href="#id21">Debugging Information Extension for Objective C Properties</a><a class="headerlink" href="#debugging-information-extension-for-objective-c-properties" title="Permalink to this headline">¶</a></h3>
+<div class="section" id="id4">
+<h4><a class="toc-backref" href="#id22">Introduction</a><a class="headerlink" href="#id4" title="Permalink to this headline">¶</a></h4>
+<p>Objective C provides a simpler way to declare and define accessor methods using
+declared properties. The language provides features to declare a property and
+to let compiler synthesize accessor methods.</p>
+<p>The debugger lets developer inspect Objective C interfaces and their instance
+variables and class variables. However, the debugger does not know anything
+about the properties defined in Objective C interfaces. The debugger consumes
+information generated by compiler in DWARF format. The format does not support
+encoding of Objective C properties. This proposal describes DWARF extensions to
+encode Objective C properties, which the debugger can use to let developers
+inspect Objective C properties.</p>
+</div>
+<div class="section" id="proposal">
+<h4><a class="toc-backref" href="#id23">Proposal</a><a class="headerlink" href="#proposal" title="Permalink to this headline">¶</a></h4>
+<p>Objective C properties exist separately from class members. A property can be
+defined only by “setter” and “getter” selectors, and be calculated anew on each
+access. Or a property can just be a direct access to some declared ivar.
+Finally it can have an ivar “automatically synthesized” for it by the compiler,
+in which case the property can be referred to in user code directly using the
+standard C dereference syntax as well as through the property “dot” syntax, but
+there is no entry in the <tt class="docutils literal"><span class="pre">@interface</span></tt> declaration corresponding to this ivar.</p>
+<p>To facilitate debugging, these properties we will add a new DWARF TAG into the
+<tt class="docutils literal"><span class="pre">DW_TAG_structure_type</span></tt> definition for the class to hold the description of a
+given property, and a set of DWARF attributes that provide said description.
+The property tag will also contain the name and declared type of the property.</p>
+<p>If there is a related ivar, there will also be a DWARF property attribute placed
+in the <tt class="docutils literal"><span class="pre">DW_TAG_member</span></tt> DIE for that ivar referring back to the property TAG
+for that property. And in the case where the compiler synthesizes the ivar
+directly, the compiler is expected to generate a <tt class="docutils literal"><span class="pre">DW_TAG_member</span></tt> for that
+ivar (with the <tt class="docutils literal"><span class="pre">DW_AT_artificial</span></tt> set to 1), whose name will be the name used
+to access this ivar directly in code, and with the property attribute pointing
+back to the property it is backing.</p>
+<p>The following examples will serve as illustration for our discussion:</p>
+<div class="highlight-objc"><div class="highlight"><pre><span class="k">@interface</span> <span class="nc">I1</span> <span class="p">{</span>
+ <span class="kt">int</span> <span class="n">n2</span><span class="p">;</span>
+<span class="p">}</span>
+
+<span class="k">@property</span> <span class="kt">int</span> <span class="n">p1</span><span class="p">;</span>
+<span class="k">@property</span> <span class="kt">int</span> <span class="n">p2</span><span class="p">;</span>
+<span class="k">@end</span>
+
+<span class="k">@implementation</span> <span class="nc">I1</span>
+<span class="k">@synthesize</span> <span class="n">p1</span><span class="p">;</span>
+<span class="k">@synthesize</span> <span class="n">p2</span> <span class="o">=</span> <span class="n">n2</span><span class="p">;</span>
+<span class="k">@end</span>
+</pre></div>
+</div>
+<p>This produces the following DWARF (this is a “pseudo dwarfdump” output):</p>
+<div class="highlight-none"><div class="highlight"><pre>0x00000100: TAG_structure_type [7] *
+ AT_APPLE_runtime_class( 0x10 )
+ AT_name( "I1" )
+ AT_decl_file( "Objc_Property.m" )
+ AT_decl_line( 3 )
+
+0x00000110 TAG_APPLE_property
+ AT_name ( "p1" )
+ AT_type ( {0x00000150} ( int ) )
+
+0x00000120: TAG_APPLE_property
+ AT_name ( "p2" )
+ AT_type ( {0x00000150} ( int ) )
+
+0x00000130: TAG_member [8]
+ AT_name( "_p1" )
+ AT_APPLE_property ( {0x00000110} "p1" )
+ AT_type( {0x00000150} ( int ) )
+ AT_artificial ( 0x1 )
+
+0x00000140: TAG_member [8]
+ AT_name( "n2" )
+ AT_APPLE_property ( {0x00000120} "p2" )
+ AT_type( {0x00000150} ( int ) )
+
+0x00000150: AT_type( ( int ) )
+</pre></div>
+</div>
+<p>Note, the current convention is that the name of the ivar for an
+auto-synthesized property is the name of the property from which it derives
+with an underscore prepended, as is shown in the example. But we actually
+don’t need to know this convention, since we are given the name of the ivar
+directly.</p>
+<p>Also, it is common practice in ObjC to have different property declarations in
+the @interface and @implementation - e.g. to provide a read-only property in
+the interface,and a read-write interface in the implementation. In that case,
+the compiler should emit whichever property declaration will be in force in the
+current translation unit.</p>
+<p>Developers can decorate a property with attributes which are encoded using
+<tt class="docutils literal"><span class="pre">DW_AT_APPLE_property_attribute</span></tt>.</p>
+<div class="highlight-objc"><div class="highlight"><pre><span class="k">@property</span> <span class="p">(</span><span class="n">readonly</span><span class="p">,</span> <span class="n">nonatomic</span><span class="p">)</span> <span class="kt">int</span> <span class="n">pr</span><span class="p">;</span>
+</pre></div>
+</div>
+<div class="highlight-none"><div class="highlight"><pre>TAG_APPLE_property [8]
+ AT_name( "pr" )
+ AT_type ( {0x00000147} (int) )
+ AT_APPLE_property_attribute (DW_APPLE_PROPERTY_readonly, DW_APPLE_PROPERTY_nonatomic)
+</pre></div>
+</div>
+<p>The setter and getter method names are attached to the property using
+<tt class="docutils literal"><span class="pre">DW_AT_APPLE_property_setter</span></tt> and <tt class="docutils literal"><span class="pre">DW_AT_APPLE_property_getter</span></tt> attributes.</p>
+<div class="highlight-objc"><div class="highlight"><pre><span class="k">@interface</span> <span class="nc">I1</span>
+<span class="k">@property</span> <span class="p">(</span><span class="n">setter</span><span class="o">=</span><span class="n">myOwnP3Setter</span><span class="o">:</span><span class="p">)</span> <span class="kt">int</span> <span class="n">p3</span><span class="p">;</span>
+<span class="k">-</span><span class="p">(</span><span class="kt">void</span><span class="p">)</span><span class="nf">myOwnP3Setter:</span><span class="p">(</span><span class="kt">int</span><span class="p">)</span><span class="nv">a</span><span class="p">;</span>
+<span class="k">@end</span>
+
+<span class="k">@implementation</span> <span class="nc">I1</span>
+<span class="k">@synthesize</span> <span class="n">p3</span><span class="p">;</span>
+<span class="k">-</span><span class="p">(</span><span class="kt">void</span><span class="p">)</span><span class="nf">myOwnP3Setter:</span><span class="p">(</span><span class="kt">int</span><span class="p">)</span><span class="nv">a</span><span class="p">{</span> <span class="p">}</span>
+<span class="k">@end</span>
+</pre></div>
+</div>
+<p>The DWARF for this would be:</p>
+<div class="highlight-none"><div class="highlight"><pre>0x000003bd: TAG_structure_type [7] *
+ AT_APPLE_runtime_class( 0x10 )
+ AT_name( "I1" )
+ AT_decl_file( "Objc_Property.m" )
+ AT_decl_line( 3 )
+
+0x000003cd TAG_APPLE_property
+ AT_name ( "p3" )
+ AT_APPLE_property_setter ( "myOwnP3Setter:" )
+ AT_type( {0x00000147} ( int ) )
+
+0x000003f3: TAG_member [8]
+ AT_name( "_p3" )
+ AT_type ( {0x00000147} ( int ) )
+ AT_APPLE_property ( {0x000003cd} )
+ AT_artificial ( 0x1 )
+</pre></div>
+</div>
+</div>
+<div class="section" id="new-dwarf-tags">
+<h4><a class="toc-backref" href="#id24">New DWARF Tags</a><a class="headerlink" href="#new-dwarf-tags" title="Permalink to this headline">¶</a></h4>
+<table border="1" class="docutils">
+<colgroup>
+<col width="74%" />
+<col width="26%" />
+</colgroup>
+<thead valign="bottom">
+<tr class="row-odd"><th class="head">TAG</th>
+<th class="head">Value</th>
+</tr>
+</thead>
+<tbody valign="top">
+<tr class="row-even"><td>DW_TAG_APPLE_property</td>
+<td>0x4200</td>
+</tr>
+</tbody>
+</table>
+</div>
+<div class="section" id="new-dwarf-attributes">
+<h4><a class="toc-backref" href="#id25">New DWARF Attributes</a><a class="headerlink" href="#new-dwarf-attributes" title="Permalink to this headline">¶</a></h4>
+<table border="1" class="docutils">
+<colgroup>
+<col width="63%" />
+<col width="16%" />
+<col width="22%" />
+</colgroup>
+<thead valign="bottom">
+<tr class="row-odd"><th class="head">Attribute</th>
+<th class="head">Value</th>
+<th class="head">Classes</th>
+</tr>
+</thead>
+<tbody valign="top">
+<tr class="row-even"><td>DW_AT_APPLE_property</td>
+<td>0x3fed</td>
+<td>Reference</td>
+</tr>
+<tr class="row-odd"><td>DW_AT_APPLE_property_getter</td>
+<td>0x3fe9</td>
+<td>String</td>
+</tr>
+<tr class="row-even"><td>DW_AT_APPLE_property_setter</td>
+<td>0x3fea</td>
+<td>String</td>
+</tr>
+<tr class="row-odd"><td>DW_AT_APPLE_property_attribute</td>
+<td>0x3feb</td>
+<td>Constant</td>
+</tr>
+</tbody>
+</table>
+</div>
+<div class="section" id="new-dwarf-constants">
+<h4><a class="toc-backref" href="#id26">New DWARF Constants</a><a class="headerlink" href="#new-dwarf-constants" title="Permalink to this headline">¶</a></h4>
+<table border="1" class="docutils">
+<colgroup>
+<col width="73%" />
+<col width="11%" />
+<col width="16%" />
+</colgroup>
+<thead valign="bottom">
+<tr class="row-odd"><th class="head" colspan="2">Name</th>
+<th class="head">Value</th>
+</tr>
+</thead>
+<tbody valign="top">
+<tr class="row-even"><td colspan="2">DW_APPLE_PROPERTY_readonly</td>
+<td>0x01</td>
+</tr>
+<tr class="row-odd"><td colspan="2">DW_APPLE_PROPERTY_getter</td>
+<td>0x02</td>
+</tr>
+<tr class="row-even"><td colspan="2">DW_APPLE_PROPERTY_assign</td>
+<td>0x04</td>
+</tr>
+<tr class="row-odd"><td colspan="2">DW_APPLE_PROPERTY_readwrite</td>
+<td>0x08</td>
+</tr>
+<tr class="row-even"><td colspan="2">DW_APPLE_PROPERTY_retain</td>
+<td>0x10</td>
+</tr>
+<tr class="row-odd"><td colspan="2">DW_APPLE_PROPERTY_copy</td>
+<td>0x20</td>
+</tr>
+<tr class="row-even"><td colspan="2">DW_APPLE_PROPERTY_nonatomic</td>
+<td>0x40</td>
+</tr>
+<tr class="row-odd"><td colspan="2">DW_APPLE_PROPERTY_setter</td>
+<td>0x80</td>
+</tr>
+<tr class="row-even"><td colspan="2">DW_APPLE_PROPERTY_atomic</td>
+<td>0x100</td>
+</tr>
+<tr class="row-odd"><td colspan="2">DW_APPLE_PROPERTY_weak</td>
+<td>0x200</td>
+</tr>
+<tr class="row-even"><td colspan="2">DW_APPLE_PROPERTY_strong</td>
+<td>0x400</td>
+</tr>
+<tr class="row-odd"><td colspan="2">DW_APPLE_PROPERTY_unsafe_unretained</td>
+<td>0x800</td>
+</tr>
+</tbody>
+</table>
+</div>
+</div>
+<div class="section" id="name-accelerator-tables">
+<h3><a class="toc-backref" href="#id27">Name Accelerator Tables</a><a class="headerlink" href="#name-accelerator-tables" title="Permalink to this headline">¶</a></h3>
+<div class="section" id="id5">
+<h4><a class="toc-backref" href="#id28">Introduction</a><a class="headerlink" href="#id5" title="Permalink to this headline">¶</a></h4>
+<p>The “<tt class="docutils literal"><span class="pre">.debug_pubnames</span></tt>” and “<tt class="docutils literal"><span class="pre">.debug_pubtypes</span></tt>” formats are not what a
+debugger needs. The “<tt class="docutils literal"><span class="pre">pub</span></tt>” in the section name indicates that the entries
+in the table are publicly visible names only. This means no static or hidden
+functions show up in the “<tt class="docutils literal"><span class="pre">.debug_pubnames</span></tt>”. No static variables or private
+class variables are in the “<tt class="docutils literal"><span class="pre">.debug_pubtypes</span></tt>”. Many compilers add different
+things to these tables, so we can’t rely upon the contents between gcc, icc, or
+clang.</p>
+<p>The typical query given by users tends not to match up with the contents of
+these tables. For example, the DWARF spec states that “In the case of the name
+of a function member or static data member of a C++ structure, class or union,
+the name presented in the “<tt class="docutils literal"><span class="pre">.debug_pubnames</span></tt>” section is not the simple name
+given by the <tt class="docutils literal"><span class="pre">DW_AT_name</span> <span class="pre">attribute</span></tt> of the referenced debugging information
+entry, but rather the fully qualified name of the data or function member.”
+So the only names in these tables for complex C++ entries is a fully
+qualified name. Debugger users tend not to enter their search strings as
+“<tt class="docutils literal"><span class="pre">a::b::c(int,const</span> <span class="pre">Foo&)</span> <span class="pre">const</span></tt>”, but rather as “<tt class="docutils literal"><span class="pre">c</span></tt>”, “<tt class="docutils literal"><span class="pre">b::c</span></tt>” , or
+“<tt class="docutils literal"><span class="pre">a::b::c</span></tt>”. So the name entered in the name table must be demangled in
+order to chop it up appropriately and additional names must be manually entered
+into the table to make it effective as a name lookup table for debuggers to
+se.</p>
+<p>All debuggers currently ignore the “<tt class="docutils literal"><span class="pre">.debug_pubnames</span></tt>” table as a result of
+its inconsistent and useless public-only name content making it a waste of
+space in the object file. These tables, when they are written to disk, are not
+sorted in any way, leaving every debugger to do its own parsing and sorting.
+These tables also include an inlined copy of the string values in the table
+itself making the tables much larger than they need to be on disk, especially
+for large C++ programs.</p>
+<p>Can’t we just fix the sections by adding all of the names we need to this
+table? No, because that is not what the tables are defined to contain and we
+won’t know the difference between the old bad tables and the new good tables.
+At best we could make our own renamed sections that contain all of the data we
+need.</p>
+<p>These tables are also insufficient for what a debugger like LLDB needs. LLDB
+uses clang for its expression parsing where LLDB acts as a PCH. LLDB is then
+often asked to look for type “<tt class="docutils literal"><span class="pre">foo</span></tt>” or namespace “<tt class="docutils literal"><span class="pre">bar</span></tt>”, or list items in
+namespace “<tt class="docutils literal"><span class="pre">baz</span></tt>”. Namespaces are not included in the pubnames or pubtypes
+tables. Since clang asks a lot of questions when it is parsing an expression,
+we need to be very fast when looking up names, as it happens a lot. Having new
+accelerator tables that are optimized for very quick lookups will benefit this
+type of debugging experience greatly.</p>
+<p>We would like to generate name lookup tables that can be mapped into memory
+from disk, and used as is, with little or no up-front parsing. We would also
+be able to control the exact content of these different tables so they contain
+exactly what we need. The Name Accelerator Tables were designed to fix these
+issues. In order to solve these issues we need to:</p>
+<ul class="simple">
+<li>Have a format that can be mapped into memory from disk and used as is</li>
+<li>Lookups should be very fast</li>
+<li>Extensible table format so these tables can be made by many producers</li>
+<li>Contain all of the names needed for typical lookups out of the box</li>
+<li>Strict rules for the contents of tables</li>
+</ul>
+<p>Table size is important and the accelerator table format should allow the reuse
+of strings from common string tables so the strings for the names are not
+duplicated. We also want to make sure the table is ready to be used as-is by
+simply mapping the table into memory with minimal header parsing.</p>
+<p>The name lookups need to be fast and optimized for the kinds of lookups that
+debuggers tend to do. Optimally we would like to touch as few parts of the
+mapped table as possible when doing a name lookup and be able to quickly find
+the name entry we are looking for, or discover there are no matches. In the
+case of debuggers we optimized for lookups that fail most of the time.</p>
+<p>Each table that is defined should have strict rules on exactly what is in the
+accelerator tables and documented so clients can rely on the content.</p>
+</div>
+<div class="section" id="hash-tables">
+<h4><a class="toc-backref" href="#id29">Hash Tables</a><a class="headerlink" href="#hash-tables" title="Permalink to this headline">¶</a></h4>
+<div class="section" id="standard-hash-tables">
+<h5><a class="toc-backref" href="#id30">Standard Hash Tables</a><a class="headerlink" href="#standard-hash-tables" title="Permalink to this headline">¶</a></h5>
+<p>Typical hash tables have a header, buckets, and each bucket points to the
+bucket contents:</p>
+<div class="highlight-none"><div class="highlight"><pre>.------------.
+| HEADER |
+|------------|
+| BUCKETS |
+|------------|
+| DATA |
+`------------'
+</pre></div>
+</div>
+<p>The BUCKETS are an array of offsets to DATA for each hash:</p>
+<div class="highlight-none"><div class="highlight"><pre>.------------.
+| 0x00001000 | BUCKETS[0]
+| 0x00002000 | BUCKETS[1]
+| 0x00002200 | BUCKETS[2]
+| 0x000034f0 | BUCKETS[3]
+| | ...
+| 0xXXXXXXXX | BUCKETS[n_buckets]
+'------------'
+</pre></div>
+</div>
+<p>So for <tt class="docutils literal"><span class="pre">bucket[3]</span></tt> in the example above, we have an offset into the table
+0x000034f0 which points to a chain of entries for the bucket. Each bucket must
+contain a next pointer, full 32 bit hash value, the string itself, and the data
+for the current string value.</p>
+<div class="highlight-none"><div class="highlight"><pre> .------------.
+0x000034f0: | 0x00003500 | next pointer
+ | 0x12345678 | 32 bit hash
+ | "erase" | string value
+ | data[n] | HashData for this bucket
+ |------------|
+0x00003500: | 0x00003550 | next pointer
+ | 0x29273623 | 32 bit hash
+ | "dump" | string value
+ | data[n] | HashData for this bucket
+ |------------|
+0x00003550: | 0x00000000 | next pointer
+ | 0x82638293 | 32 bit hash
+ | "main" | string value
+ | data[n] | HashData for this bucket
+ `------------'
+</pre></div>
+</div>
+<p>The problem with this layout for debuggers is that we need to optimize for the
+negative lookup case where the symbol we’re searching for is not present. So
+if we were to lookup “<tt class="docutils literal"><span class="pre">printf</span></tt>” in the table above, we would make a 32 hash
+for “<tt class="docutils literal"><span class="pre">printf</span></tt>”, it might match <tt class="docutils literal"><span class="pre">bucket[3]</span></tt>. We would need to go to the
+offset 0x000034f0 and start looking to see if our 32 bit hash matches. To do
+so, we need to read the next pointer, then read the hash, compare it, and skip
+to the next bucket. Each time we are skipping many bytes in memory and
+touching new cache pages just to do the compare on the full 32 bit hash. All
+of these accesses then tell us that we didn’t have a match.</p>
+</div>
+<div class="section" id="name-hash-tables">
+<h5><a class="toc-backref" href="#id31">Name Hash Tables</a><a class="headerlink" href="#name-hash-tables" title="Permalink to this headline">¶</a></h5>
+<p>To solve the issues mentioned above we have structured the hash tables a bit
+differently: a header, buckets, an array of all unique 32 bit hash values,
+followed by an array of hash value data offsets, one for each hash value, then
+the data for all hash values:</p>
+<div class="highlight-none"><div class="highlight"><pre>.-------------.
+| HEADER |
+|-------------|
+| BUCKETS |
+|-------------|
+| HASHES |
+|-------------|
+| OFFSETS |
+|-------------|
+| DATA |
+`-------------'
+</pre></div>
+</div>
+<p>The <tt class="docutils literal"><span class="pre">BUCKETS</span></tt> in the name tables are an index into the <tt class="docutils literal"><span class="pre">HASHES</span></tt> array. By
+making all of the full 32 bit hash values contiguous in memory, we allow
+ourselves to efficiently check for a match while touching as little memory as
+possible. Most often checking the 32 bit hash values is as far as the lookup
+goes. If it does match, it usually is a match with no collisions. So for a
+table with “<tt class="docutils literal"><span class="pre">n_buckets</span></tt>” buckets, and “<tt class="docutils literal"><span class="pre">n_hashes</span></tt>” unique 32 bit hash
+values, we can clarify the contents of the <tt class="docutils literal"><span class="pre">BUCKETS</span></tt>, <tt class="docutils literal"><span class="pre">HASHES</span></tt> and
+<tt class="docutils literal"><span class="pre">OFFSETS</span></tt> as:</p>
+<div class="highlight-none"><div class="highlight"><pre>.-------------------------.
+| HEADER.magic | uint32_t
+| HEADER.version | uint16_t
+| HEADER.hash_function | uint16_t
+| HEADER.bucket_count | uint32_t
+| HEADER.hashes_count | uint32_t
+| HEADER.header_data_len | uint32_t
+| HEADER_DATA | HeaderData
+|-------------------------|
+| BUCKETS | uint32_t[n_buckets] // 32 bit hash indexes
+|-------------------------|
+| HASHES | uint32_t[n_hashes] // 32 bit hash values
+|-------------------------|
+| OFFSETS | uint32_t[n_hashes] // 32 bit offsets to hash value data
+|-------------------------|
+| ALL HASH DATA |
+`-------------------------'
+</pre></div>
+</div>
+<p>So taking the exact same data from the standard hash example above we end up
+with:</p>
+<div class="highlight-none"><div class="highlight"><pre> .------------.
+ | HEADER |
+ |------------|
+ | 0 | BUCKETS[0]
+ | 2 | BUCKETS[1]
+ | 5 | BUCKETS[2]
+ | 6 | BUCKETS[3]
+ | | ...
+ | ... | BUCKETS[n_buckets]
+ |------------|
+ | 0x........ | HASHES[0]
+ | 0x........ | HASHES[1]
+ | 0x........ | HASHES[2]
+ | 0x........ | HASHES[3]
+ | 0x........ | HASHES[4]
+ | 0x........ | HASHES[5]
+ | 0x12345678 | HASHES[6] hash for BUCKETS[3]
+ | 0x29273623 | HASHES[7] hash for BUCKETS[3]
+ | 0x82638293 | HASHES[8] hash for BUCKETS[3]
+ | 0x........ | HASHES[9]
+ | 0x........ | HASHES[10]
+ | 0x........ | HASHES[11]
+ | 0x........ | HASHES[12]
+ | 0x........ | HASHES[13]
+ | 0x........ | HASHES[n_hashes]
+ |------------|
+ | 0x........ | OFFSETS[0]
+ | 0x........ | OFFSETS[1]
+ | 0x........ | OFFSETS[2]
+ | 0x........ | OFFSETS[3]
+ | 0x........ | OFFSETS[4]
+ | 0x........ | OFFSETS[5]
+ | 0x000034f0 | OFFSETS[6] offset for BUCKETS[3]
+ | 0x00003500 | OFFSETS[7] offset for BUCKETS[3]
+ | 0x00003550 | OFFSETS[8] offset for BUCKETS[3]
+ | 0x........ | OFFSETS[9]
+ | 0x........ | OFFSETS[10]
+ | 0x........ | OFFSETS[11]
+ | 0x........ | OFFSETS[12]
+ | 0x........ | OFFSETS[13]
+ | 0x........ | OFFSETS[n_hashes]
+ |------------|
+ | |
+ | |
+ | |
+ | |
+ | |
+ |------------|
+0x000034f0: | 0x00001203 | .debug_str ("erase")
+ | 0x00000004 | A 32 bit array count - number of HashData with name "erase"
+ | 0x........ | HashData[0]
+ | 0x........ | HashData[1]
+ | 0x........ | HashData[2]
+ | 0x........ | HashData[3]
+ | 0x00000000 | String offset into .debug_str (terminate data for hash)
+ |------------|
+0x00003500: | 0x00001203 | String offset into .debug_str ("collision")
+ | 0x00000002 | A 32 bit array count - number of HashData with name "collision"
+ | 0x........ | HashData[0]
+ | 0x........ | HashData[1]
+ | 0x00001203 | String offset into .debug_str ("dump")
+ | 0x00000003 | A 32 bit array count - number of HashData with name "dump"
+ | 0x........ | HashData[0]
+ | 0x........ | HashData[1]
+ | 0x........ | HashData[2]
+ | 0x00000000 | String offset into .debug_str (terminate data for hash)
+ |------------|
+0x00003550: | 0x00001203 | String offset into .debug_str ("main")
+ | 0x00000009 | A 32 bit array count - number of HashData with name "main"
+ | 0x........ | HashData[0]
+ | 0x........ | HashData[1]
+ | 0x........ | HashData[2]
+ | 0x........ | HashData[3]
+ | 0x........ | HashData[4]
+ | 0x........ | HashData[5]
+ | 0x........ | HashData[6]
+ | 0x........ | HashData[7]
+ | 0x........ | HashData[8]
+ | 0x00000000 | String offset into .debug_str (terminate data for hash)
+ `------------'
+</pre></div>
+</div>
+<p>So we still have all of the same data, we just organize it more efficiently for
+debugger lookup. If we repeat the same “<tt class="docutils literal"><span class="pre">printf</span></tt>” lookup from above, we
+would hash “<tt class="docutils literal"><span class="pre">printf</span></tt>” and find it matches <tt class="docutils literal"><span class="pre">BUCKETS[3]</span></tt> by taking the 32 bit
+hash value and modulo it by <tt class="docutils literal"><span class="pre">n_buckets</span></tt>. <tt class="docutils literal"><span class="pre">BUCKETS[3]</span></tt> contains “6” which
+is the index into the <tt class="docutils literal"><span class="pre">HASHES</span></tt> table. We would then compare any consecutive
+32 bit hashes values in the <tt class="docutils literal"><span class="pre">HASHES</span></tt> array as long as the hashes would be in
+<tt class="docutils literal"><span class="pre">BUCKETS[3]</span></tt>. We do this by verifying that each subsequent hash value modulo
+<tt class="docutils literal"><span class="pre">n_buckets</span></tt> is still 3. In the case of a failed lookup we would access the
+memory for <tt class="docutils literal"><span class="pre">BUCKETS[3]</span></tt>, and then compare a few consecutive 32 bit hashes
+before we know that we have no match. We don’t end up marching through
+multiple words of memory and we really keep the number of processor data cache
+lines being accessed as small as possible.</p>
+<p>The string hash that is used for these lookup tables is the Daniel J.
+Bernstein hash which is also used in the ELF <tt class="docutils literal"><span class="pre">GNU_HASH</span></tt> sections. It is a
+very good hash for all kinds of names in programs with very few hash
+collisions.</p>
+<p>Empty buckets are designated by using an invalid hash index of <tt class="docutils literal"><span class="pre">UINT32_MAX</span></tt>.</p>
+</div>
+</div>
+<div class="section" id="details">
+<h4><a class="toc-backref" href="#id32">Details</a><a class="headerlink" href="#details" title="Permalink to this headline">¶</a></h4>
+<p>These name hash tables are designed to be generic where specializations of the
+table get to define additional data that goes into the header (“<tt class="docutils literal"><span class="pre">HeaderData</span></tt>”),
+how the string value is stored (“<tt class="docutils literal"><span class="pre">KeyType</span></tt>”) and the content of the data for each
+hash value.</p>
+<div class="section" id="header-layout">
+<h5><a class="toc-backref" href="#id33">Header Layout</a><a class="headerlink" href="#header-layout" title="Permalink to this headline">¶</a></h5>
+<p>The header has a fixed part, and the specialized part. The exact format of the
+header is:</p>
+<div class="highlight-c"><div class="highlight"><pre><span class="k">struct</span> <span class="n">Header</span>
+<span class="p">{</span>
+ <span class="kt">uint32_t</span> <span class="n">magic</span><span class="p">;</span> <span class="c1">// 'HASH' magic value to allow endian detection</span>
+ <span class="kt">uint16_t</span> <span class="n">version</span><span class="p">;</span> <span class="c1">// Version number</span>
+ <span class="kt">uint16_t</span> <span class="n">hash_function</span><span class="p">;</span> <span class="c1">// The hash function enumeration that was used</span>
+ <span class="kt">uint32_t</span> <span class="n">bucket_count</span><span class="p">;</span> <span class="c1">// The number of buckets in this hash table</span>
+ <span class="kt">uint32_t</span> <span class="n">hashes_count</span><span class="p">;</span> <span class="c1">// The total number of unique hash values and hash data offsets in this table</span>
+ <span class="kt">uint32_t</span> <span class="n">header_data_len</span><span class="p">;</span> <span class="c1">// The bytes to skip to get to the hash indexes (buckets) for correct alignment</span>
+ <span class="c1">// Specifically the length of the following HeaderData field - this does not</span>
+ <span class="c1">// include the size of the preceding fields</span>
+ <span class="n">HeaderData</span> <span class="n">header_data</span><span class="p">;</span> <span class="c1">// Implementation specific header data</span>
+<span class="p">};</span>
+</pre></div>
+</div>
+<p>The header starts with a 32 bit “<tt class="docutils literal"><span class="pre">magic</span></tt>” value which must be <tt class="docutils literal"><span class="pre">'HASH'</span></tt>
+encoded as an ASCII integer. This allows the detection of the start of the
+hash table and also allows the table’s byte order to be determined so the table
+can be correctly extracted. The “<tt class="docutils literal"><span class="pre">magic</span></tt>” value is followed by a 16 bit
+<tt class="docutils literal"><span class="pre">version</span></tt> number which allows the table to be revised and modified in the
+future. The current version number is 1. <tt class="docutils literal"><span class="pre">hash_function</span></tt> is a <tt class="docutils literal"><span class="pre">uint16_t</span></tt>
+enumeration that specifies which hash function was used to produce this table.
+The current values for the hash function enumerations include:</p>
+<div class="highlight-c"><div class="highlight"><pre><span class="k">enum</span> <span class="n">HashFunctionType</span>
+<span class="p">{</span>
+ <span class="n">eHashFunctionDJB</span> <span class="o">=</span> <span class="mi">0u</span><span class="p">,</span> <span class="c1">// Daniel J Bernstein hash function</span>
+<span class="p">};</span>
+</pre></div>
+</div>
+<p><tt class="docutils literal"><span class="pre">bucket_count</span></tt> is a 32 bit unsigned integer that represents how many buckets
+are in the <tt class="docutils literal"><span class="pre">BUCKETS</span></tt> array. <tt class="docutils literal"><span class="pre">hashes_count</span></tt> is the number of unique 32 bit
+hash values that are in the <tt class="docutils literal"><span class="pre">HASHES</span></tt> array, and is the same number of offsets
+are contained in the <tt class="docutils literal"><span class="pre">OFFSETS</span></tt> array. <tt class="docutils literal"><span class="pre">header_data_len</span></tt> specifies the size
+in bytes of the <tt class="docutils literal"><span class="pre">HeaderData</span></tt> that is filled in by specialized versions of
+this table.</p>
+</div>
+<div class="section" id="fixed-lookup">
+<h5><a class="toc-backref" href="#id34">Fixed Lookup</a><a class="headerlink" href="#fixed-lookup" title="Permalink to this headline">¶</a></h5>
+<p>The header is followed by the buckets, hashes, offsets, and hash value data.</p>
+<div class="highlight-c"><div class="highlight"><pre><span class="k">struct</span> <span class="n">FixedTable</span>
+<span class="p">{</span>
+ <span class="kt">uint32_t</span> <span class="n">buckets</span><span class="p">[</span><span class="n">Header</span><span class="p">.</span><span class="n">bucket_count</span><span class="p">];</span> <span class="c1">// An array of hash indexes into the "hashes[]" array below</span>
+ <span class="kt">uint32_t</span> <span class="n">hashes</span> <span class="p">[</span><span class="n">Header</span><span class="p">.</span><span class="n">hashes_count</span><span class="p">];</span> <span class="c1">// Every unique 32 bit hash for the entire table is in this table</span>
+ <span class="kt">uint32_t</span> <span class="n">offsets</span><span class="p">[</span><span class="n">Header</span><span class="p">.</span><span class="n">hashes_count</span><span class="p">];</span> <span class="c1">// An offset that corresponds to each item in the "hashes[]" array above</span>
+<span class="p">};</span>
+</pre></div>
+</div>
+<p><tt class="docutils literal"><span class="pre">buckets</span></tt> is an array of 32 bit indexes into the <tt class="docutils literal"><span class="pre">hashes</span></tt> array. The
+<tt class="docutils literal"><span class="pre">hashes</span></tt> array contains all of the 32 bit hash values for all names in the
+hash table. Each hash in the <tt class="docutils literal"><span class="pre">hashes</span></tt> table has an offset in the <tt class="docutils literal"><span class="pre">offsets</span></tt>
+array that points to the data for the hash value.</p>
+<p>This table setup makes it very easy to repurpose these tables to contain
+different data, while keeping the lookup mechanism the same for all tables.
+This layout also makes it possible to save the table to disk and map it in
+later and do very efficient name lookups with little or no parsing.</p>
+<p>DWARF lookup tables can be implemented in a variety of ways and can store a lot
+of information for each name. We want to make the DWARF tables extensible and
+able to store the data efficiently so we have used some of the DWARF features
+that enable efficient data storage to define exactly what kind of data we store
+for each name.</p>
+<p>The <tt class="docutils literal"><span class="pre">HeaderData</span></tt> contains a definition of the contents of each HashData chunk.
+We might want to store an offset to all of the debug information entries (DIEs)
+for each name. To keep things extensible, we create a list of items, or
+Atoms, that are contained in the data for each name. First comes the type of
+the data in each atom:</p>
+<div class="highlight-c"><div class="highlight"><pre><span class="k">enum</span> <span class="n">AtomType</span>
+<span class="p">{</span>
+ <span class="n">eAtomTypeNULL</span> <span class="o">=</span> <span class="mi">0u</span><span class="p">,</span>
+ <span class="n">eAtomTypeDIEOffset</span> <span class="o">=</span> <span class="mi">1u</span><span class="p">,</span> <span class="c1">// DIE offset, check form for encoding</span>
+ <span class="n">eAtomTypeCUOffset</span> <span class="o">=</span> <span class="mi">2u</span><span class="p">,</span> <span class="c1">// DIE offset of the compiler unit header that contains the item in question</span>
+ <span class="n">eAtomTypeTag</span> <span class="o">=</span> <span class="mi">3u</span><span class="p">,</span> <span class="c1">// DW_TAG_xxx value, should be encoded as DW_FORM_data1 (if no tags exceed 255) or DW_FORM_data2</span>
+ <span class="n">eAtomTypeNameFlags</span> <span class="o">=</span> <span class="mi">4u</span><span class="p">,</span> <span class="c1">// Flags from enum NameFlags</span>
+ <span class="n">eAtomTypeTypeFlags</span> <span class="o">=</span> <span class="mi">5u</span><span class="p">,</span> <span class="c1">// Flags from enum TypeFlags</span>
+<span class="p">};</span>
+</pre></div>
+</div>
+<p>The enumeration values and their meanings are:</p>
+<div class="highlight-none"><div class="highlight"><pre>eAtomTypeNULL - a termination atom that specifies the end of the atom list
+eAtomTypeDIEOffset - an offset into the .debug_info section for the DWARF DIE for this name
+eAtomTypeCUOffset - an offset into the .debug_info section for the CU that contains the DIE
+eAtomTypeDIETag - The DW_TAG_XXX enumeration value so you don't have to parse the DWARF to see what it is
+eAtomTypeNameFlags - Flags for functions and global variables (isFunction, isInlined, isExternal...)
+eAtomTypeTypeFlags - Flags for types (isCXXClass, isObjCClass, ...)
+</pre></div>
+</div>
+<p>Then we allow each atom type to define the atom type and how the data for each
+atom type data is encoded:</p>
+<div class="highlight-c"><div class="highlight"><pre><span class="k">struct</span> <span class="n">Atom</span>
+<span class="p">{</span>
+ <span class="kt">uint16_t</span> <span class="n">type</span><span class="p">;</span> <span class="c1">// AtomType enum value</span>
+ <span class="kt">uint16_t</span> <span class="n">form</span><span class="p">;</span> <span class="c1">// DWARF DW_FORM_XXX defines</span>
+<span class="p">};</span>
+</pre></div>
+</div>
+<p>The <tt class="docutils literal"><span class="pre">form</span></tt> type above is from the DWARF specification and defines the exact
+encoding of the data for the Atom type. See the DWARF specification for the
+<tt class="docutils literal"><span class="pre">DW_FORM_</span></tt> definitions.</p>
+<div class="highlight-c"><div class="highlight"><pre><span class="k">struct</span> <span class="n">HeaderData</span>
+<span class="p">{</span>
+ <span class="kt">uint32_t</span> <span class="n">die_offset_base</span><span class="p">;</span>
+ <span class="kt">uint32_t</span> <span class="n">atom_count</span><span class="p">;</span>
+ <span class="n">Atoms</span> <span class="n">atoms</span><span class="p">[</span><span class="n">atom_count0</span><span class="p">];</span>
+<span class="p">};</span>
+</pre></div>
+</div>
+<p><tt class="docutils literal"><span class="pre">HeaderData</span></tt> defines the base DIE offset that should be added to any atoms
+that are encoded using the <tt class="docutils literal"><span class="pre">DW_FORM_ref1</span></tt>, <tt class="docutils literal"><span class="pre">DW_FORM_ref2</span></tt>,
+<tt class="docutils literal"><span class="pre">DW_FORM_ref4</span></tt>, <tt class="docutils literal"><span class="pre">DW_FORM_ref8</span></tt> or <tt class="docutils literal"><span class="pre">DW_FORM_ref_udata</span></tt>. It also defines
+what is contained in each <tt class="docutils literal"><span class="pre">HashData</span></tt> object – <tt class="docutils literal"><span class="pre">Atom.form</span></tt> tells us how large
+each field will be in the <tt class="docutils literal"><span class="pre">HashData</span></tt> and the <tt class="docutils literal"><span class="pre">Atom.type</span></tt> tells us how this data
+should be interpreted.</p>
+<p>For the current implementations of the “<tt class="docutils literal"><span class="pre">.apple_names</span></tt>” (all functions +
+globals), the “<tt class="docutils literal"><span class="pre">.apple_types</span></tt>” (names of all types that are defined), and
+the “<tt class="docutils literal"><span class="pre">.apple_namespaces</span></tt>” (all namespaces), we currently set the <tt class="docutils literal"><span class="pre">Atom</span></tt>
+array to be:</p>
+<div class="highlight-c"><div class="highlight"><pre><span class="n">HeaderData</span><span class="p">.</span><span class="n">atom_count</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
+<span class="n">HeaderData</span><span class="p">.</span><span class="n">atoms</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="n">type</span> <span class="o">=</span> <span class="n">eAtomTypeDIEOffset</span><span class="p">;</span>
+<span class="n">HeaderData</span><span class="p">.</span><span class="n">atoms</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="n">form</span> <span class="o">=</span> <span class="n">DW_FORM_data4</span><span class="p">;</span>
+</pre></div>
+</div>
+<p>This defines the contents to be the DIE offset (eAtomTypeDIEOffset) that is
+encoded as a 32 bit value (DW_FORM_data4). This allows a single name to have
+multiple matching DIEs in a single file, which could come up with an inlined
+function for instance. Future tables could include more information about the
+DIE such as flags indicating if the DIE is a function, method, block,
+or inlined.</p>
+<p>The KeyType for the DWARF table is a 32 bit string table offset into the
+”.debug_str” table. The ”.debug_str” is the string table for the DWARF which
+may already contain copies of all of the strings. This helps make sure, with
+help from the compiler, that we reuse the strings between all of the DWARF
+sections and keeps the hash table size down. Another benefit to having the
+compiler generate all strings as DW_FORM_strp in the debug info, is that
+DWARF parsing can be made much faster.</p>
+<p>After a lookup is made, we get an offset into the hash data. The hash data
+needs to be able to deal with 32 bit hash collisions, so the chunk of data
+at the offset in the hash data consists of a triple:</p>
+<div class="highlight-c"><div class="highlight"><pre><span class="kt">uint32_t</span> <span class="n">str_offset</span>
+<span class="kt">uint32_t</span> <span class="n">hash_data_count</span>
+<span class="n">HashData</span><span class="p">[</span><span class="n">hash_data_count</span><span class="p">]</span>
+</pre></div>
+</div>
+<p>If “str_offset” is zero, then the bucket contents are done. 99.9% of the
+hash data chunks contain a single item (no 32 bit hash collision):</p>
+<div class="highlight-none"><div class="highlight"><pre>.------------.
+| 0x00001023 | uint32_t KeyType (.debug_str[0x0001023] => "main")
+| 0x00000004 | uint32_t HashData count
+| 0x........ | uint32_t HashData[0] DIE offset
+| 0x........ | uint32_t HashData[1] DIE offset
+| 0x........ | uint32_t HashData[2] DIE offset
+| 0x........ | uint32_t HashData[3] DIE offset
+| 0x00000000 | uint32_t KeyType (end of hash chain)
+`------------'
+</pre></div>
+</div>
+<p>If there are collisions, you will have multiple valid string offsets:</p>
+<div class="highlight-none"><div class="highlight"><pre>.------------.
+| 0x00001023 | uint32_t KeyType (.debug_str[0x0001023] => "main")
+| 0x00000004 | uint32_t HashData count
+| 0x........ | uint32_t HashData[0] DIE offset
+| 0x........ | uint32_t HashData[1] DIE offset
+| 0x........ | uint32_t HashData[2] DIE offset
+| 0x........ | uint32_t HashData[3] DIE offset
+| 0x00002023 | uint32_t KeyType (.debug_str[0x0002023] => "print")
+| 0x00000002 | uint32_t HashData count
+| 0x........ | uint32_t HashData[0] DIE offset
+| 0x........ | uint32_t HashData[1] DIE offset
+| 0x00000000 | uint32_t KeyType (end of hash chain)
+`------------'
+</pre></div>
+</div>
+<p>Current testing with real world C++ binaries has shown that there is around 1
+32 bit hash collision per 100,000 name entries.</p>
+</div>
+</div>
+<div class="section" id="id6">
+<h4><a class="toc-backref" href="#id35">Contents</a><a class="headerlink" href="#id6" title="Permalink to this headline">¶</a></h4>
+<p>As we said, we want to strictly define exactly what is included in the
+different tables. For DWARF, we have 3 tables: “<tt class="docutils literal"><span class="pre">.apple_names</span></tt>”,
+“<tt class="docutils literal"><span class="pre">.apple_types</span></tt>”, and “<tt class="docutils literal"><span class="pre">.apple_namespaces</span></tt>”.</p>
+<p>“<tt class="docutils literal"><span class="pre">.apple_names</span></tt>” sections should contain an entry for each DWARF DIE whose
+<tt class="docutils literal"><span class="pre">DW_TAG</span></tt> is a <tt class="docutils literal"><span class="pre">DW_TAG_label</span></tt>, <tt class="docutils literal"><span class="pre">DW_TAG_inlined_subroutine</span></tt>, or
+<tt class="docutils literal"><span class="pre">DW_TAG_subprogram</span></tt> that has address attributes: <tt class="docutils literal"><span class="pre">DW_AT_low_pc</span></tt>,
+<tt class="docutils literal"><span class="pre">DW_AT_high_pc</span></tt>, <tt class="docutils literal"><span class="pre">DW_AT_ranges</span></tt> or <tt class="docutils literal"><span class="pre">DW_AT_entry_pc</span></tt>. It also contains
+<tt class="docutils literal"><span class="pre">DW_TAG_variable</span></tt> DIEs that have a <tt class="docutils literal"><span class="pre">DW_OP_addr</span></tt> in the location (global and
+static variables). All global and static variables should be included,
+including those scoped within functions and classes. For example using the
+following code:</p>
+<div class="highlight-c"><div class="highlight"><pre><span class="k">static</span> <span class="kt">int</span> <span class="n">var</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
+
+<span class="kt">void</span> <span class="nf">f</span> <span class="p">()</span>
+<span class="p">{</span>
+ <span class="k">static</span> <span class="kt">int</span> <span class="n">var</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
+<span class="p">}</span>
+</pre></div>
+</div>
+<p>Both of the static <tt class="docutils literal"><span class="pre">var</span></tt> variables would be included in the table. All
+functions should emit both their full names and their basenames. For C or C++,
+the full name is the mangled name (if available) which is usually in the
+<tt class="docutils literal"><span class="pre">DW_AT_MIPS_linkage_name</span></tt> attribute, and the <tt class="docutils literal"><span class="pre">DW_AT_name</span></tt> contains the
+function basename. If global or static variables have a mangled name in a
+<tt class="docutils literal"><span class="pre">DW_AT_MIPS_linkage_name</span></tt> attribute, this should be emitted along with the
+simple name found in the <tt class="docutils literal"><span class="pre">DW_AT_name</span></tt> attribute.</p>
+<p>“<tt class="docutils literal"><span class="pre">.apple_types</span></tt>” sections should contain an entry for each DWARF DIE whose
+tag is one of:</p>
+<ul class="simple">
+<li>DW_TAG_array_type</li>
+<li>DW_TAG_class_type</li>
+<li>DW_TAG_enumeration_type</li>
+<li>DW_TAG_pointer_type</li>
+<li>DW_TAG_reference_type</li>
+<li>DW_TAG_string_type</li>
+<li>DW_TAG_structure_type</li>
+<li>DW_TAG_subroutine_type</li>
+<li>DW_TAG_typedef</li>
+<li>DW_TAG_union_type</li>
+<li>DW_TAG_ptr_to_member_type</li>
+<li>DW_TAG_set_type</li>
+<li>DW_TAG_subrange_type</li>
+<li>DW_TAG_base_type</li>
+<li>DW_TAG_const_type</li>
+<li>DW_TAG_file_type</li>
+<li>DW_TAG_namelist</li>
+<li>DW_TAG_packed_type</li>
+<li>DW_TAG_volatile_type</li>
+<li>DW_TAG_restrict_type</li>
+<li>DW_TAG_interface_type</li>
+<li>DW_TAG_unspecified_type</li>
+<li>DW_TAG_shared_type</li>
+</ul>
+<p>Only entries with a <tt class="docutils literal"><span class="pre">DW_AT_name</span></tt> attribute are included, and the entry must
+not be a forward declaration (<tt class="docutils literal"><span class="pre">DW_AT_declaration</span></tt> attribute with a non-zero
+value). For example, using the following code:</p>
+<div class="highlight-c"><div class="highlight"><pre><span class="kt">int</span> <span class="nf">main</span> <span class="p">()</span>
+<span class="p">{</span>
+ <span class="kt">int</span> <span class="o">*</span><span class="n">b</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
+ <span class="k">return</span> <span class="o">*</span><span class="n">b</span><span class="p">;</span>
+<span class="p">}</span>
+</pre></div>
+</div>
+<p>We get a few type DIEs:</p>
+<div class="highlight-none"><div class="highlight"><pre>0x00000067: TAG_base_type [5]
+ AT_encoding( DW_ATE_signed )
+ AT_name( "int" )
+ AT_byte_size( 0x04 )
+
+0x0000006e: TAG_pointer_type [6]
+ AT_type( {0x00000067} ( int ) )
+ AT_byte_size( 0x08 )
+</pre></div>
+</div>
+<p>The DW_TAG_pointer_type is not included because it does not have a <tt class="docutils literal"><span class="pre">DW_AT_name</span></tt>.</p>
+<p>“<tt class="docutils literal"><span class="pre">.apple_namespaces</span></tt>” section should contain all <tt class="docutils literal"><span class="pre">DW_TAG_namespace</span></tt> DIEs.
+If we run into a namespace that has no name this is an anonymous namespace, and
+the name should be output as “<tt class="docutils literal"><span class="pre">(anonymous</span> <span class="pre">namespace)</span></tt>” (without the quotes).
+Why? This matches the output of the <tt class="docutils literal"><span class="pre">abi::cxa_demangle()</span></tt> that is in the
+standard C++ library that demangles mangled names.</p>
+</div>
+<div class="section" id="language-extensions-and-file-format-changes">
+<h4><a class="toc-backref" href="#id36">Language Extensions and File Format Changes</a><a class="headerlink" href="#language-extensions-and-file-format-changes" title="Permalink to this headline">¶</a></h4>
+<div class="section" id="objective-c-extensions">
+<h5><a class="toc-backref" href="#id37">Objective-C Extensions</a><a class="headerlink" href="#objective-c-extensions" title="Permalink to this headline">¶</a></h5>
+<p>“<tt class="docutils literal"><span class="pre">.apple_objc</span></tt>” section should contain all <tt class="docutils literal"><span class="pre">DW_TAG_subprogram</span></tt> DIEs for an
+Objective-C class. The name used in the hash table is the name of the
+Objective-C class itself. If the Objective-C class has a category, then an
+entry is made for both the class name without the category, and for the class
+name with the category. So if we have a DIE at offset 0x1234 with a name of
+method “<tt class="docutils literal"><span class="pre">-[NSString(my_additions)</span> <span class="pre">stringWithSpecialString:]</span></tt>”, we would add
+an entry for “<tt class="docutils literal"><span class="pre">NSString</span></tt>” that points to DIE 0x1234, and an entry for
+“<tt class="docutils literal"><span class="pre">NSString(my_additions)</span></tt>” that points to 0x1234. This allows us to quickly
+track down all Objective-C methods for an Objective-C class when doing
+expressions. It is needed because of the dynamic nature of Objective-C where
+anyone can add methods to a class. The DWARF for Objective-C methods is also
+emitted differently from C++ classes where the methods are not usually
+contained in the class definition, they are scattered about across one or more
+compile units. Categories can also be defined in different shared libraries.
+So we need to be able to quickly find all of the methods and class functions
+given the Objective-C class name, or quickly find all methods and class
+functions for a class + category name. This table does not contain any
+selector names, it just maps Objective-C class names (or class names +
+category) to all of the methods and class functions. The selectors are added
+as function basenames in the “<tt class="docutils literal"><span class="pre">.debug_names</span></tt>” section.</p>
+<p>In the “<tt class="docutils literal"><span class="pre">.apple_names</span></tt>” section for Objective-C functions, the full name is
+the entire function name with the brackets (“<tt class="docutils literal"><span class="pre">-[NSString</span>
+<span class="pre">stringWithCString:]</span></tt>”) and the basename is the selector only
+(“<tt class="docutils literal"><span class="pre">stringWithCString:</span></tt>”).</p>
+</div>
+<div class="section" id="mach-o-changes">
+<h5><a class="toc-backref" href="#id38">Mach-O Changes</a><a class="headerlink" href="#mach-o-changes" title="Permalink to this headline">¶</a></h5>
+<p>The sections names for the apple hash tables are for non-mach-o files. For
+mach-o files, the sections should be contained in the <tt class="docutils literal"><span class="pre">__DWARF</span></tt> segment with
+names as follows:</p>
+<ul class="simple">
+<li>“<tt class="docutils literal"><span class="pre">.apple_names</span></tt>” -> “<tt class="docutils literal"><span class="pre">__apple_names</span></tt>“</li>
+<li>“<tt class="docutils literal"><span class="pre">.apple_types</span></tt>” -> “<tt class="docutils literal"><span class="pre">__apple_types</span></tt>“</li>
+<li>“<tt class="docutils literal"><span class="pre">.apple_namespaces</span></tt>” -> “<tt class="docutils literal"><span class="pre">__apple_namespac</span></tt>” (16 character limit)</li>
+<li>“<tt class="docutils literal"><span class="pre">.apple_objc</span></tt>” -> “<tt class="docutils literal"><span class="pre">__apple_objc</span></tt>“</li>
+</ul>
+</div>
+</div>
+</div>
+</div>
+</div>
+
+
+ </div>
+ </div>
+ <div class="clearer"></div>
+ </div>
+ <div class="related">
+ <h3>Navigation</h3>
+ <ul>
+ <li class="right" style="margin-right: 10px">
+ <a href="genindex.html" title="General Index"
+ >index</a></li>
+ <li class="right" >
+ <a href="Vectorizers.html" title="Auto-Vectorization in LLVM"
+ >next</a> |</li>
+ <li class="right" >
+ <a href="SystemLibrary.html" title="System Library"
+ >previous</a> |</li>
+ <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+ <li><a href="index.html">Documentation</a>»</li>
+
+ </ul>
+ </div>
+ <div class="footer">
+ © Copyright 2003-2016, LLVM Project.
+ Last updated on 2016-01-04.
+ Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.3.
+ </div>
+ </body>
+</html>
\ No newline at end of file
Added: www-releases/trunk/3.7.1/docs/SphinxQuickstartTemplate.html
URL: http://llvm.org/viewvc/llvm-project/www-releases/trunk/3.7.1/docs/SphinxQuickstartTemplate.html?rev=257950&view=auto
==============================================================================
--- www-releases/trunk/3.7.1/docs/SphinxQuickstartTemplate.html (added)
+++ www-releases/trunk/3.7.1/docs/SphinxQuickstartTemplate.html Fri Jan 15 17:13:16 2016
@@ -0,0 +1,223 @@
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
+ <title>Sphinx Quickstart Template — LLVM 3.7 documentation</title>
+
+ <link rel="stylesheet" href="_static/llvm-theme.css" type="text/css" />
+ <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
+
+ <script type="text/javascript">
+ var DOCUMENTATION_OPTIONS = {
+ URL_ROOT: './',
+ VERSION: '3.7',
+ COLLAPSE_INDEX: false,
+ FILE_SUFFIX: '.html',
+ HAS_SOURCE: true
+ };
+ </script>
+ <script type="text/javascript" src="_static/jquery.js"></script>
+ <script type="text/javascript" src="_static/underscore.js"></script>
+ <script type="text/javascript" src="_static/doctools.js"></script>
+ <link rel="top" title="LLVM 3.7 documentation" href="index.html" />
+ <link rel="next" title="Code Reviews with Phabricator" href="Phabricator.html" />
+ <link rel="prev" title="How to submit an LLVM bug report" href="HowToSubmitABug.html" />
+<style type="text/css">
+ table.right { float: right; margin-left: 20px; }
+ table.right td { border: 1px solid #ccc; }
+</style>
+
+ </head>
+ <body>
+<div class="logo">
+ <a href="index.html">
+ <img src="_static/logo.png"
+ alt="LLVM Logo" width="250" height="88"/></a>
+</div>
+
+ <div class="related">
+ <h3>Navigation</h3>
+ <ul>
+ <li class="right" style="margin-right: 10px">
+ <a href="genindex.html" title="General Index"
+ accesskey="I">index</a></li>
+ <li class="right" >
+ <a href="Phabricator.html" title="Code Reviews with Phabricator"
+ accesskey="N">next</a> |</li>
+ <li class="right" >
+ <a href="HowToSubmitABug.html" title="How to submit an LLVM bug report"
+ accesskey="P">previous</a> |</li>
+ <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+ <li><a href="index.html">Documentation</a>»</li>
+
+ </ul>
+ </div>
+
+
+ <div class="document">
+ <div class="documentwrapper">
+ <div class="body">
+
+ <div class="section" id="sphinx-quickstart-template">
+<h1>Sphinx Quickstart Template<a class="headerlink" href="#sphinx-quickstart-template" title="Permalink to this headline">¶</a></h1>
+<div class="section" id="introduction-and-quickstart">
+<h2>Introduction and Quickstart<a class="headerlink" href="#introduction-and-quickstart" title="Permalink to this headline">¶</a></h2>
+<p>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.</p>
+<p>You can find this document in <tt class="docutils literal"><span class="pre">docs/SphinxQuickstartTemplate.rst</span></tt>. 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.</p>
+<p>Focus on <em>content</em>. 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 <a class="reference internal" href="#example-section">Example Section</a>) gives examples
+which should cover 99% of use cases.</p>
+<p>Let me say that again: focus on <em>content</em>. But if you really need to verify
+Sphinx’s output, see <tt class="docutils literal"><span class="pre">docs/README.txt</span></tt> for information.</p>
+<p>Once you have finished with the content, please send the <tt class="docutils literal"><span class="pre">.rst</span></tt> file to
+llvm-commits for review.</p>
+</div>
+<div class="section" id="guidelines">
+<h2>Guidelines<a class="headerlink" href="#guidelines" title="Permalink to this headline">¶</a></h2>
+<p>Try to answer the following questions in your first section:</p>
+<ol class="arabic simple">
+<li>Why would I want to read this document?</li>
+<li>What should I know to be able to follow along with this document?</li>
+<li>What will I have learned by the end of this document?</li>
+</ol>
+<p>Common names for the first section are <tt class="docutils literal"><span class="pre">Introduction</span></tt>, <tt class="docutils literal"><span class="pre">Overview</span></tt>, or
+<tt class="docutils literal"><span class="pre">Background</span></tt>.</p>
+<p>If possible, make your document a “how to”. Give it a name <tt class="docutils literal"><span class="pre">HowTo*.rst</span></tt>
+like the other “how to” documents. This format is usually the easiest
+for another person to understand and also the most useful.</p>
+<p>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.</p>
+<p>Focus on content (yes, I had to say it again).</p>
+<p>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.</p>
+</div>
+<div class="section" id="example-section">
+<h2>Example Section<a class="headerlink" href="#example-section" title="Permalink to this headline">¶</a></h2>
+<p>Your text can be <em>emphasized</em>, <strong>bold</strong>, or <tt class="docutils literal"><span class="pre">monospace</span></tt>.</p>
+<p>Use blank lines to separate paragraphs.</p>
+<p>Headings (like <tt class="docutils literal"><span class="pre">Example</span> <span class="pre">Section</span></tt> just above) give your document its
+structure. Use the same kind of adornments (e.g. <tt class="docutils literal"><span class="pre">======</span></tt> vs. <tt class="docutils literal"><span class="pre">------</span></tt>)
+as are used in this document. The adornment must be the same length as the
+text above it. For Vim users, variations of <tt class="docutils literal"><span class="pre">yypVr=</span></tt> might be handy.</p>
+<div class="section" id="example-subsection">
+<h3>Example Subsection<a class="headerlink" href="#example-subsection" title="Permalink to this headline">¶</a></h3>
+<p>Make a link <a class="reference external" href="http://llvm.org/">like this</a>. There is also a more
+sophisticated syntax which <a class="reference external" href="http://en.wikipedia.org/wiki/LLVM">can be more readable</a> for longer links since
+it disrupts the flow less. You can put the <tt class="docutils literal"><span class="pre">..</span> <span class="pre">_`link</span> <span class="pre">text`:</span> <span class="pre"><URL></span></tt> block
+pretty much anywhere later in the document.</p>
+<p>Lists can be made like this:</p>
+<ol class="arabic simple">
+<li>A list starting with <tt class="docutils literal"><span class="pre">#.</span></tt> will be automatically numbered.</li>
+<li>This is a second list element.<ol class="arabic">
+<li>Use indentation to create nested lists.</li>
+</ol>
+</li>
+</ol>
+<p>You can also use unordered lists.</p>
+<ul class="simple">
+<li>Stuff.<ul>
+<li>Deeper stuff.</li>
+</ul>
+</li>
+<li>More stuff.</li>
+</ul>
+<div class="section" id="example-subsubsection">
+<h4>Example Subsubsection<a class="headerlink" href="#example-subsubsection" title="Permalink to this headline">¶</a></h4>
+<p>You can make blocks of code like this:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="kt">int</span> <span class="nf">main</span><span class="p">()</span> <span class="p">{</span>
+ <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
+<span class="p">}</span>
+</pre></div>
+</div>
+<p>For a shell session, use a <tt class="docutils literal"><span class="pre">console</span></tt> code block (some existing docs use
+<tt class="docutils literal"><span class="pre">bash</span></tt>):</p>
+<div class="highlight-console"><div class="highlight"><pre><span class="gp">$</span> <span class="nb">echo</span> <span class="s2">"Goodbye cruel world!"</span>
+<span class="gp">$</span> rm -rf /
+</pre></div>
+</div>
+<p>If you need to show LLVM IR use the <tt class="docutils literal"><span class="pre">llvm</span></tt> code block.</p>
+<div class="highlight-llvm"><div class="highlight"><pre><span class="k">define</span> <span class="k">i32</span> <span class="vg">@test1</span><span class="p">()</span> <span class="p">{</span>
+<span class="nl">entry:</span>
+ <span class="k">ret</span> <span class="k">i32</span> <span class="m">0</span>
+<span class="p">}</span>
+</pre></div>
+</div>
+<p>Some other common code blocks you might need are <tt class="docutils literal"><span class="pre">c</span></tt>, <tt class="docutils literal"><span class="pre">objc</span></tt>, <tt class="docutils literal"><span class="pre">make</span></tt>,
+and <tt class="docutils literal"><span class="pre">cmake</span></tt>. If you need something beyond that, you can look at the <a class="reference external" href="http://pygments.org/docs/lexers/">full
+list</a> of supported code blocks.</p>
+<p>However, don’t waste time fiddling with syntax highlighting when you could
+be adding meaningful content. When in doubt, show preformatted text
+without any syntax highlighting like this:</p>
+<div class="highlight-python"><div class="highlight"><pre> .
+ +:.
+ ..:: ::
+ .++:+:: ::+:.:.
+ .:+ :
+ ::.::..:: .+.
+ ..:+ :: :
+......+:. ..
+ :++. .. :
+ .+:::+:: :
+ .. . .+ ::
+ +.: .::+.
+ ...+. .: .
+ .++:..
+ ...
+</pre></div>
+</div>
+<div class="section" id="hopefully-you-won-t-need-to-be-this-deep">
+<h5>Hopefully you won’t need to be this deep<a class="headerlink" href="#hopefully-you-won-t-need-to-be-this-deep" title="Permalink to this headline">¶</a></h5>
+<p>If you need to do fancier things than what has been shown in this document,
+you can mail the list or check Sphinx’s <a class="reference external" href="http://sphinx.pocoo.org/rest.html">reStructuredText Primer</a>.</p>
+</div>
+</div>
+</div>
+</div>
+</div>
+
+
+ </div>
+ </div>
+ <div class="clearer"></div>
+ </div>
+ <div class="related">
+ <h3>Navigation</h3>
+ <ul>
+ <li class="right" style="margin-right: 10px">
+ <a href="genindex.html" title="General Index"
+ >index</a></li>
+ <li class="right" >
+ <a href="Phabricator.html" title="Code Reviews with Phabricator"
+ >next</a> |</li>
+ <li class="right" >
+ <a href="HowToSubmitABug.html" title="How to submit an LLVM bug report"
+ >previous</a> |</li>
+ <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+ <li><a href="index.html">Documentation</a>»</li>
+
+ </ul>
+ </div>
+ <div class="footer">
+ © Copyright 2003-2016, LLVM Project.
+ Last updated on 2016-01-04.
+ Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.3.
+ </div>
+ </body>
+</html>
\ No newline at end of file
Added: www-releases/trunk/3.7.1/docs/StackMaps.html
URL: http://llvm.org/viewvc/llvm-project/www-releases/trunk/3.7.1/docs/StackMaps.html?rev=257950&view=auto
==============================================================================
--- www-releases/trunk/3.7.1/docs/StackMaps.html (added)
+++ www-releases/trunk/3.7.1/docs/StackMaps.html Fri Jan 15 17:13:16 2016
@@ -0,0 +1,574 @@
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
+ <title>Stack maps and patch points in LLVM — LLVM 3.7 documentation</title>
+
+ <link rel="stylesheet" href="_static/llvm-theme.css" type="text/css" />
+ <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
+
+ <script type="text/javascript">
+ var DOCUMENTATION_OPTIONS = {
+ URL_ROOT: './',
+ VERSION: '3.7',
+ COLLAPSE_INDEX: false,
+ FILE_SUFFIX: '.html',
+ HAS_SOURCE: true
+ };
+ </script>
+ <script type="text/javascript" src="_static/jquery.js"></script>
+ <script type="text/javascript" src="_static/underscore.js"></script>
+ <script type="text/javascript" src="_static/doctools.js"></script>
+ <link rel="top" title="LLVM 3.7 documentation" href="index.html" />
+ <link rel="next" title="Design and Usage of the InAlloca Attribute" href="InAlloca.html" />
+ <link rel="prev" title="User Guide for AMDGPU Back-end" href="AMDGPUUsage.html" />
+<style type="text/css">
+ table.right { float: right; margin-left: 20px; }
+ table.right td { border: 1px solid #ccc; }
+</style>
+
+ </head>
+ <body>
+<div class="logo">
+ <a href="index.html">
+ <img src="_static/logo.png"
+ alt="LLVM Logo" width="250" height="88"/></a>
+</div>
+
+ <div class="related">
+ <h3>Navigation</h3>
+ <ul>
+ <li class="right" style="margin-right: 10px">
+ <a href="genindex.html" title="General Index"
+ accesskey="I">index</a></li>
+ <li class="right" >
+ <a href="InAlloca.html" title="Design and Usage of the InAlloca Attribute"
+ accesskey="N">next</a> |</li>
+ <li class="right" >
+ <a href="AMDGPUUsage.html" title="User Guide for AMDGPU Back-end"
+ accesskey="P">previous</a> |</li>
+ <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+ <li><a href="index.html">Documentation</a>»</li>
+
+ </ul>
+ </div>
+
+
+ <div class="document">
+ <div class="documentwrapper">
+ <div class="body">
+
+ <div class="section" id="stack-maps-and-patch-points-in-llvm">
+<h1>Stack maps and patch points in LLVM<a class="headerlink" href="#stack-maps-and-patch-points-in-llvm" title="Permalink to this headline">¶</a></h1>
+<div class="contents local topic" id="contents">
+<ul class="simple">
+<li><a class="reference internal" href="#definitions" id="id5">Definitions</a></li>
+<li><a class="reference internal" href="#motivation" id="id6">Motivation</a></li>
+<li><a class="reference internal" href="#intrinsics" id="id7">Intrinsics</a><ul>
+<li><a class="reference internal" href="#llvm-experimental-stackmap-intrinsic" id="id8">‘<tt class="docutils literal"><span class="pre">llvm.experimental.stackmap</span></tt>‘ Intrinsic</a></li>
+<li><a class="reference internal" href="#llvm-experimental-patchpoint-intrinsic" id="id9">‘<tt class="docutils literal"><span class="pre">llvm.experimental.patchpoint.*</span></tt>‘ Intrinsic</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#stack-map-format" id="id10">Stack Map Format</a><ul>
+<li><a class="reference internal" href="#stack-map-section" id="id11">Stack Map Section</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#stack-map-usage" id="id12">Stack Map Usage</a><ul>
+<li><a class="reference internal" href="#direct-stack-map-entries" id="id13">Direct Stack Map Entries</a></li>
+</ul>
+</li>
+</ul>
+</div>
+<div class="section" id="definitions">
+<h2><a class="toc-backref" href="#id5">Definitions</a><a class="headerlink" href="#definitions" title="Permalink to this headline">¶</a></h2>
+<p>In this document we refer to the “runtime” collectively as all
+components that serve as the LLVM client, including the LLVM IR
+generator, object code consumer, and code patcher.</p>
+<p>A stack map records the location of <tt class="docutils literal"><span class="pre">live</span> <span class="pre">values</span></tt> at a particular
+instruction address. These <tt class="docutils literal"><span class="pre">live</span> <span class="pre">values</span></tt> do not refer to all the
+LLVM values live across the stack map. Instead, they are only the
+values that the runtime requires to be live at this point. For
+example, they may be the values the runtime will need to resume
+program execution at that point independent of the compiled function
+containing the stack map.</p>
+<p>LLVM emits stack map data into the object code within a designated
+<a class="reference internal" href="#stackmap-section"><em>Stack Map Section</em></a>. This stack map data contains a record for
+each stack map. The record stores the stack map’s instruction address
+and contains a entry for each mapped value. Each entry encodes a
+value’s location as a register, stack offset, or constant.</p>
+<p>A patch point is an instruction address at which space is reserved for
+patching a new instruction sequence at run time. Patch points look
+much like calls to LLVM. They take arguments that follow a calling
+convention and may return a value. They also imply stack map
+generation, which allows the runtime to locate the patchpoint and
+find the location of <tt class="docutils literal"><span class="pre">live</span> <span class="pre">values</span></tt> at that point.</p>
+</div>
+<div class="section" id="motivation">
+<h2><a class="toc-backref" href="#id6">Motivation</a><a class="headerlink" href="#motivation" title="Permalink to this headline">¶</a></h2>
+<p>This functionality is currently experimental but is potentially useful
+in a variety of settings, the most obvious being a runtime (JIT)
+compiler. Example applications of the patchpoint intrinsics are
+implementing an inline call cache for polymorphic method dispatch or
+optimizing the retrieval of properties in dynamically typed languages
+such as JavaScript.</p>
+<p>The intrinsics documented here are currently used by the JavaScript
+compiler within the open source WebKit project, see the <a class="reference external" href="https://trac.webkit.org/wiki/FTLJIT">FTL JIT</a>, but they are designed to be
+used whenever stack maps or code patching are needed. Because the
+intrinsics have experimental status, compatibility across LLVM
+releases is not guaranteed.</p>
+<p>The stack map functionality described in this document is separate
+from the functionality described in
+<a class="reference internal" href="GarbageCollection.html#stack-map"><em>Computing stack maps</em></a>. <cite>GCFunctionMetadata</cite> provides the location of
+pointers into a collected heap captured by the <cite>GCRoot</cite> intrinsic,
+which can also be considered a “stack map”. Unlike the stack maps
+defined above, the <cite>GCFunctionMetadata</cite> stack map interface does not
+provide a way to associate live register values of arbitrary type with
+an instruction address, nor does it specify a format for the resulting
+stack map. The stack maps described here could potentially provide
+richer information to a garbage collecting runtime, but that usage
+will not be discussed in this document.</p>
+</div>
+<div class="section" id="intrinsics">
+<h2><a class="toc-backref" href="#id7">Intrinsics</a><a class="headerlink" href="#intrinsics" title="Permalink to this headline">¶</a></h2>
+<p>The following two kinds of intrinsics can be used to implement stack
+maps and patch points: <tt class="docutils literal"><span class="pre">llvm.experimental.stackmap</span></tt> and
+<tt class="docutils literal"><span class="pre">llvm.experimental.patchpoint</span></tt>. Both kinds of intrinsics generate a
+stack map record, and they both allow some form of code patching. They
+can be used independently (i.e. <tt class="docutils literal"><span class="pre">llvm.experimental.patchpoint</span></tt>
+implicitly generates a stack map without the need for an additional
+call to <tt class="docutils literal"><span class="pre">llvm.experimental.stackmap</span></tt>). The choice of which to use
+depends on whether it is necessary to reserve space for code patching
+and whether any of the intrinsic arguments should be lowered according
+to calling conventions. <tt class="docutils literal"><span class="pre">llvm.experimental.stackmap</span></tt> does not
+reserve any space, nor does it expect any call arguments. If the
+runtime patches code at the stack map’s address, it will destructively
+overwrite the program text. This is unlike
+<tt class="docutils literal"><span class="pre">llvm.experimental.patchpoint</span></tt>, which reserves space for in-place
+patching without overwriting surrounding code. The
+<tt class="docutils literal"><span class="pre">llvm.experimental.patchpoint</span></tt> intrinsic also lowers a specified
+number of arguments according to its calling convention. This allows
+patched code to make in-place function calls without marshaling.</p>
+<p>Each instance of one of these intrinsics generates a stack map record
+in the <a class="reference internal" href="#stackmap-section"><em>Stack Map Section</em></a>. The record includes an ID, allowing
+the runtime to uniquely identify the stack map, and the offset within
+the code from the beginning of the enclosing function.</p>
+<div class="section" id="llvm-experimental-stackmap-intrinsic">
+<h3><a class="toc-backref" href="#id8">‘<tt class="docutils literal"><span class="pre">llvm.experimental.stackmap</span></tt>‘ Intrinsic</a><a class="headerlink" href="#llvm-experimental-stackmap-intrinsic" title="Permalink to this headline">¶</a></h3>
+<div class="section" id="syntax">
+<h4>Syntax:<a class="headerlink" href="#syntax" title="Permalink to this headline">¶</a></h4>
+<div class="highlight-python"><div class="highlight"><pre>declare void
+ @llvm.experimental.stackmap(i64 <id>, i32 <numShadowBytes>, ...)
+</pre></div>
+</div>
+</div>
+<div class="section" id="overview">
+<h4>Overview:<a class="headerlink" href="#overview" title="Permalink to this headline">¶</a></h4>
+<p>The ‘<tt class="docutils literal"><span class="pre">llvm.experimental.stackmap</span></tt>‘ intrinsic records the location of
+specified values in the stack map without generating any code.</p>
+</div>
+<div class="section" id="operands">
+<h4>Operands:<a class="headerlink" href="#operands" title="Permalink to this headline">¶</a></h4>
+<p>The first operand is an ID to be encoded within the stack map. The
+second operand is the number of shadow bytes following the
+intrinsic. The variable number of operands that follow are the <tt class="docutils literal"><span class="pre">live</span>
+<span class="pre">values</span></tt> for which locations will be recorded in the stack map.</p>
+<p>To use this intrinsic as a bare-bones stack map, with no code patching
+support, the number of shadow bytes can be set to zero.</p>
+</div>
+<div class="section" id="semantics">
+<h4>Semantics:<a class="headerlink" href="#semantics" title="Permalink to this headline">¶</a></h4>
+<p>The stack map intrinsic generates no code in place, unless nops are
+needed to cover its shadow (see below). However, its offset from
+function entry is stored in the stack map. This is the relative
+instruction address immediately following the instructions that
+precede the stack map.</p>
+<p>The stack map ID allows a runtime to locate the desired stack map
+record. LLVM passes this ID through directly to the stack map
+record without checking uniqueness.</p>
+<p>LLVM guarantees a shadow of instructions following the stack map’s
+instruction offset during which neither the end of the basic block nor
+another call to <tt class="docutils literal"><span class="pre">llvm.experimental.stackmap</span></tt> or
+<tt class="docutils literal"><span class="pre">llvm.experimental.patchpoint</span></tt> may occur. This allows the runtime to
+patch the code at this point in response to an event triggered from
+outside the code. The code for instructions following the stack map
+may be emitted in the stack map’s shadow, and these instructions may
+be overwritten by destructive patching. Without shadow bytes, this
+destructive patching could overwrite program text or data outside the
+current function. We disallow overlapping stack map shadows so that
+the runtime does not need to consider this corner case.</p>
+<p>For example, a stack map with 8 byte shadow:</p>
+<div class="highlight-llvm"><div class="highlight"><pre><span class="k">call</span> <span class="kt">void</span> <span class="vg">@runtime</span><span class="p">()</span>
+<span class="k">call</span> <span class="kt">void</span> <span class="p">(</span><span class="k">i64</span><span class="p">,</span> <span class="k">i32</span><span class="p">,</span> <span class="p">...)*</span> <span class="vg">@llvm.experimental.stackmap</span><span class="p">(</span><span class="k">i64</span> <span class="m">77</span><span class="p">,</span> <span class="k">i32</span> <span class="m">8</span><span class="p">,</span>
+ <span class="k">i64</span><span class="p">*</span> <span class="nv">%ptr</span><span class="p">)</span>
+<span class="nv">%val</span> <span class="p">=</span> <span class="k">load</span> <span class="k">i64</span><span class="p">*</span> <span class="nv">%ptr</span>
+<span class="nv">%add</span> <span class="p">=</span> <span class="k">add</span> <span class="k">i64</span> <span class="nv">%val</span><span class="p">,</span> <span class="m">3</span>
+<span class="k">ret</span> <span class="k">i64</span> <span class="nv">%add</span>
+</pre></div>
+</div>
+<p>May require one byte of nop-padding:</p>
+<div class="highlight-none"><div class="highlight"><pre>0x00 callq _runtime
+0x05 nop <--- stack map address
+0x06 movq (%rdi), %rax
+0x07 addq $3, %rax
+0x0a popq %rdx
+0x0b ret <---- end of 8-byte shadow
+</pre></div>
+</div>
+<p>Now, if the runtime needs to invalidate the compiled code, it may
+patch 8 bytes of code at the stack map’s address at follows:</p>
+<div class="highlight-none"><div class="highlight"><pre>0x00 callq _runtime
+0x05 movl $0xffff, %rax <--- patched code at stack map address
+0x0a callq *%rax <---- end of 8-byte shadow
+</pre></div>
+</div>
+<p>This way, after the normal call to the runtime returns, the code will
+execute a patched call to a special entry point that can rebuild a
+stack frame from the values located by the stack map.</p>
+</div>
+</div>
+<div class="section" id="llvm-experimental-patchpoint-intrinsic">
+<h3><a class="toc-backref" href="#id9">‘<tt class="docutils literal"><span class="pre">llvm.experimental.patchpoint.*</span></tt>‘ Intrinsic</a><a class="headerlink" href="#llvm-experimental-patchpoint-intrinsic" title="Permalink to this headline">¶</a></h3>
+<div class="section" id="id1">
+<h4>Syntax:<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h4>
+<div class="highlight-python"><div class="highlight"><pre>declare void
+ @llvm.experimental.patchpoint.void(i64 <id>, i32 <numBytes>,
+ i8* <target>, i32 <numArgs>, ...)
+declare i64
+ @llvm.experimental.patchpoint.i64(i64 <id>, i32 <numBytes>,
+ i8* <target>, i32 <numArgs>, ...)
+</pre></div>
+</div>
+</div>
+<div class="section" id="id2">
+<h4>Overview:<a class="headerlink" href="#id2" title="Permalink to this headline">¶</a></h4>
+<p>The ‘<tt class="docutils literal"><span class="pre">llvm.experimental.patchpoint.*</span></tt>‘ intrinsics creates a function
+call to the specified <tt class="docutils literal"><span class="pre"><target></span></tt> and records the location of specified
+values in the stack map.</p>
+</div>
+<div class="section" id="id3">
+<h4>Operands:<a class="headerlink" href="#id3" title="Permalink to this headline">¶</a></h4>
+<p>The first operand is an ID, the second operand is the number of bytes
+reserved for the patchable region, the third operand is the target
+address of a function (optionally null), and the fourth operand
+specifies how many of the following variable operands are considered
+function call arguments. The remaining variable number of operands are
+the <tt class="docutils literal"><span class="pre">live</span> <span class="pre">values</span></tt> for which locations will be recorded in the stack
+map.</p>
+</div>
+<div class="section" id="id4">
+<h4>Semantics:<a class="headerlink" href="#id4" title="Permalink to this headline">¶</a></h4>
+<p>The patch point intrinsic generates a stack map. It also emits a
+function call to the address specified by <tt class="docutils literal"><span class="pre"><target></span></tt> if the address
+is not a constant null. The function call and its arguments are
+lowered according to the calling convention specified at the
+intrinsic’s callsite. Variants of the intrinsic with non-void return
+type also return a value according to calling convention.</p>
+<p>On PowerPC, note that <tt class="docutils literal"><span class="pre"><target></span></tt> must be the ABI function pointer for the
+intended target of the indirect call. Specifically, when compiling for the
+ELF V1 ABI, <tt class="docutils literal"><span class="pre"><target></span></tt> is the function-descriptor address normally used as
+the C/C++ function-pointer representation.</p>
+<p>Requesting zero patch point arguments is valid. In this case, all
+variable operands are handled just like
+<tt class="docutils literal"><span class="pre">llvm.experimental.stackmap.*</span></tt>. The difference is that space will
+still be reserved for patching, a call will be emitted, and a return
+value is allowed.</p>
+<p>The location of the arguments are not normally recorded in the stack
+map because they are already fixed by the calling convention. The
+remaining <tt class="docutils literal"><span class="pre">live</span> <span class="pre">values</span></tt> will have their location recorded, which
+could be a register, stack location, or constant. A special calling
+convention has been introduced for use with stack maps, anyregcc,
+which forces the arguments to be loaded into registers but allows
+those register to be dynamically allocated. These argument registers
+will have their register locations recorded in the stack map in
+addition to the remaining <tt class="docutils literal"><span class="pre">live</span> <span class="pre">values</span></tt>.</p>
+<p>The patch point also emits nops to cover at least <tt class="docutils literal"><span class="pre"><numBytes></span></tt> of
+instruction encoding space. Hence, the client must ensure that
+<tt class="docutils literal"><span class="pre"><numBytes></span></tt> is enough to encode a call to the target address on the
+supported targets. If the call target is constant null, then there is
+no minimum requirement. A zero-byte null target patchpoint is
+valid.</p>
+<p>The runtime may patch the code emitted for the patch point, including
+the call sequence and nops. However, the runtime may not assume
+anything about the code LLVM emits within the reserved space. Partial
+patching is not allowed. The runtime must patch all reserved bytes,
+padding with nops if necessary.</p>
+<p>This example shows a patch point reserving 15 bytes, with one argument
+in $rdi, and a return value in $rax per native calling convention:</p>
+<div class="highlight-llvm"><div class="highlight"><pre><span class="nv">%target</span> <span class="p">=</span> <span class="k">inttoptr</span> <span class="k">i64</span> <span class="m">-281474976710654</span> <span class="k">to</span> <span class="k">i8</span><span class="p">*</span>
+<span class="nv">%val</span> <span class="p">=</span> <span class="k">call</span> <span class="k">i64</span> <span class="p">(</span><span class="k">i64</span><span class="p">,</span> <span class="k">i32</span><span class="p">,</span> <span class="p">...)*</span>
+ <span class="vg">@llvm.experimental.patchpoint.i64</span><span class="p">(</span><span class="k">i64</span> <span class="m">78</span><span class="p">,</span> <span class="k">i32</span> <span class="m">15</span><span class="p">,</span>
+ <span class="k">i8</span><span class="p">*</span> <span class="nv">%target</span><span class="p">,</span> <span class="k">i32</span> <span class="m">1</span><span class="p">,</span> <span class="k">i64</span><span class="p">*</span> <span class="nv">%ptr</span><span class="p">)</span>
+<span class="nv">%add</span> <span class="p">=</span> <span class="k">add</span> <span class="k">i64</span> <span class="nv">%val</span><span class="p">,</span> <span class="m">3</span>
+<span class="k">ret</span> <span class="k">i64</span> <span class="nv">%add</span>
+</pre></div>
+</div>
+<p>May generate:</p>
+<div class="highlight-none"><div class="highlight"><pre>0x00 movabsq $0xffff000000000002, %r11 <--- patch point address
+0x0a callq *%r11
+0x0d nop
+0x0e nop <--- end of reserved 15-bytes
+0x0f addq $0x3, %rax
+0x10 movl %rax, 8(%rsp)
+</pre></div>
+</div>
+<p>Note that no stack map locations will be recorded. If the patched code
+sequence does not need arguments fixed to specific calling convention
+registers, then the <tt class="docutils literal"><span class="pre">anyregcc</span></tt> convention may be used:</p>
+<div class="highlight-none"><div class="highlight"><pre>%val = call anyregcc @llvm.experimental.patchpoint(i64 78, i32 15,
+ i8* %target, i32 1,
+ i64* %ptr)
+</pre></div>
+</div>
+<p>The stack map now indicates the location of the %ptr argument and
+return value:</p>
+<div class="highlight-none"><div class="highlight"><pre>Stack Map: ID=78, Loc0=%r9 Loc1=%r8
+</pre></div>
+</div>
+<p>The patch code sequence may now use the argument that happened to be
+allocated in %r8 and return a value allocated in %r9:</p>
+<div class="highlight-none"><div class="highlight"><pre>0x00 movslq 4(%r8) %r9 <--- patched code at patch point address
+0x03 nop
+...
+0x0e nop <--- end of reserved 15-bytes
+0x0f addq $0x3, %r9
+0x10 movl %r9, 8(%rsp)
+</pre></div>
+</div>
+</div>
+</div>
+</div>
+<div class="section" id="stack-map-format">
+<span id="stackmap-format"></span><h2><a class="toc-backref" href="#id10">Stack Map Format</a><a class="headerlink" href="#stack-map-format" title="Permalink to this headline">¶</a></h2>
+<p>The existence of a stack map or patch point intrinsic within an LLVM
+Module forces code emission to create a <a class="reference internal" href="#stackmap-section"><em>Stack Map Section</em></a>. The
+format of this section follows:</p>
+<div class="highlight-none"><div class="highlight"><pre>Header {
+ uint8 : Stack Map Version (current version is 1)
+ uint8 : Reserved (expected to be 0)
+ uint16 : Reserved (expected to be 0)
+}
+uint32 : NumFunctions
+uint32 : NumConstants
+uint32 : NumRecords
+StkSizeRecord[NumFunctions] {
+ uint64 : Function Address
+ uint64 : Stack Size
+}
+Constants[NumConstants] {
+ uint64 : LargeConstant
+}
+StkMapRecord[NumRecords] {
+ uint64 : PatchPoint ID
+ uint32 : Instruction Offset
+ uint16 : Reserved (record flags)
+ uint16 : NumLocations
+ Location[NumLocations] {
+ uint8 : Register | Direct | Indirect | Constant | ConstantIndex
+ uint8 : Reserved (location flags)
+ uint16 : Dwarf RegNum
+ int32 : Offset or SmallConstant
+ }
+ uint16 : Padding
+ uint16 : NumLiveOuts
+ LiveOuts[NumLiveOuts]
+ uint16 : Dwarf RegNum
+ uint8 : Reserved
+ uint8 : Size in Bytes
+ }
+ uint32 : Padding (only if required to align to 8 byte)
+}
+</pre></div>
+</div>
+<p>The first byte of each location encodes a type that indicates how to
+interpret the <tt class="docutils literal"><span class="pre">RegNum</span></tt> and <tt class="docutils literal"><span class="pre">Offset</span></tt> fields as follows:</p>
+<table border="1" class="docutils">
+<colgroup>
+<col width="13%" />
+<col width="16%" />
+<col width="30%" />
+<col width="42%" />
+</colgroup>
+<tbody valign="top">
+<tr class="row-odd"><td>Encoding</td>
+<td>Type</td>
+<td>Value</td>
+<td>Description</td>
+</tr>
+<tr class="row-even"><td>0x1</td>
+<td>Register</td>
+<td>Reg</td>
+<td>Value in a register</td>
+</tr>
+<tr class="row-odd"><td>0x2</td>
+<td>Direct</td>
+<td>Reg + Offset</td>
+<td>Frame index value</td>
+</tr>
+<tr class="row-even"><td>0x3</td>
+<td>Indirect</td>
+<td>[Reg + Offset]</td>
+<td>Spilled value</td>
+</tr>
+<tr class="row-odd"><td>0x4</td>
+<td>Constant</td>
+<td>Offset</td>
+<td>Small constant</td>
+</tr>
+<tr class="row-even"><td>0x5</td>
+<td>ConstIndex</td>
+<td>Constants[Offset]</td>
+<td>Large constant</td>
+</tr>
+</tbody>
+</table>
+<p>In the common case, a value is available in a register, and the
+<tt class="docutils literal"><span class="pre">Offset</span></tt> field will be zero. Values spilled to the stack are encoded
+as <tt class="docutils literal"><span class="pre">Indirect</span></tt> locations. The runtime must load those values from a
+stack address, typically in the form <tt class="docutils literal"><span class="pre">[BP</span> <span class="pre">+</span> <span class="pre">Offset]</span></tt>. If an
+<tt class="docutils literal"><span class="pre">alloca</span></tt> value is passed directly to a stack map intrinsic, then
+LLVM may fold the frame index into the stack map as an optimization to
+avoid allocating a register or stack slot. These frame indices will be
+encoded as <tt class="docutils literal"><span class="pre">Direct</span></tt> locations in the form <tt class="docutils literal"><span class="pre">BP</span> <span class="pre">+</span> <span class="pre">Offset</span></tt>. LLVM may
+also optimize constants by emitting them directly in the stack map,
+either in the <tt class="docutils literal"><span class="pre">Offset</span></tt> of a <tt class="docutils literal"><span class="pre">Constant</span></tt> location or in the constant
+pool, referred to by <tt class="docutils literal"><span class="pre">ConstantIndex</span></tt> locations.</p>
+<p>At each callsite, a “liveout” register list is also recorded. These
+are the registers that are live across the stackmap and therefore must
+be saved by the runtime. This is an important optimization when the
+patchpoint intrinsic is used with a calling convention that by default
+preserves most registers as callee-save.</p>
+<p>Each entry in the liveout register list contains a DWARF register
+number and size in bytes. The stackmap format deliberately omits
+specific subregister information. Instead the runtime must interpret
+this information conservatively. For example, if the stackmap reports
+one byte at <tt class="docutils literal"><span class="pre">%rax</span></tt>, then the value may be in either <tt class="docutils literal"><span class="pre">%al</span></tt> or
+<tt class="docutils literal"><span class="pre">%ah</span></tt>. It doesn’t matter in practice, because the runtime will
+simply save <tt class="docutils literal"><span class="pre">%rax</span></tt>. However, if the stackmap reports 16 bytes at
+<tt class="docutils literal"><span class="pre">%ymm0</span></tt>, then the runtime can safely optimize by saving only
+<tt class="docutils literal"><span class="pre">%xmm0</span></tt>.</p>
+<p>The stack map format is a contract between an LLVM SVN revision and
+the runtime. It is currently experimental and may change in the short
+term, but minimizing the need to update the runtime is
+important. Consequently, the stack map design is motivated by
+simplicity and extensibility. Compactness of the representation is
+secondary because the runtime is expected to parse the data
+immediately after compiling a module and encode the information in its
+own format. Since the runtime controls the allocation of sections, it
+can reuse the same stack map space for multiple modules.</p>
+<p>Stackmap support is currently only implemented for 64-bit
+platforms. However, a 32-bit implementation should be able to use the
+same format with an insignificant amount of wasted space.</p>
+<div class="section" id="stack-map-section">
+<span id="stackmap-section"></span><h3><a class="toc-backref" href="#id11">Stack Map Section</a><a class="headerlink" href="#stack-map-section" title="Permalink to this headline">¶</a></h3>
+<p>A JIT compiler can easily access this section by providing its own
+memory manager via the LLVM C API
+<tt class="docutils literal"><span class="pre">LLVMCreateSimpleMCJITMemoryManager()</span></tt>. When creating the memory
+manager, the JIT provides a callback:
+<tt class="docutils literal"><span class="pre">LLVMMemoryManagerAllocateDataSectionCallback()</span></tt>. When LLVM creates
+this section, it invokes the callback and passes the section name. The
+JIT can record the in-memory address of the section at this time and
+later parse it to recover the stack map data.</p>
+<p>On Darwin, the stack map section name is “__llvm_stackmaps”. The
+segment name is “__LLVM_STACKMAPS”.</p>
+</div>
+</div>
+<div class="section" id="stack-map-usage">
+<h2><a class="toc-backref" href="#id12">Stack Map Usage</a><a class="headerlink" href="#stack-map-usage" title="Permalink to this headline">¶</a></h2>
+<p>The stack map support described in this document can be used to
+precisely determine the location of values at a specific position in
+the code. LLVM does not maintain any mapping between those values and
+any higher-level entity. The runtime must be able to interpret the
+stack map record given only the ID, offset, and the order of the
+locations, which LLVM preserves.</p>
+<p>Note that this is quite different from the goal of debug information,
+which is a best-effort attempt to track the location of named
+variables at every instruction.</p>
+<p>An important motivation for this design is to allow a runtime to
+commandeer a stack frame when execution reaches an instruction address
+associated with a stack map. The runtime must be able to rebuild a
+stack frame and resume program execution using the information
+provided by the stack map. For example, execution may resume in an
+interpreter or a recompiled version of the same function.</p>
+<p>This usage restricts LLVM optimization. Clearly, LLVM must not move
+stores across a stack map. However, loads must also be handled
+conservatively. If the load may trigger an exception, hoisting it
+above a stack map could be invalid. For example, the runtime may
+determine that a load is safe to execute without a type check given
+the current state of the type system. If the type system changes while
+some activation of the load’s function exists on the stack, the load
+becomes unsafe. The runtime can prevent subsequent execution of that
+load by immediately patching any stack map location that lies between
+the current call site and the load (typically, the runtime would
+simply patch all stack map locations to invalidate the function). If
+the compiler had hoisted the load above the stack map, then the
+program could crash before the runtime could take back control.</p>
+<p>To enforce these semantics, stackmap and patchpoint intrinsics are
+considered to potentially read and write all memory. This may limit
+optimization more than some clients desire. This limitation may be
+avoided by marking the call site as “readonly”. In the future we may
+also allow meta-data to be added to the intrinsic call to express
+aliasing, thereby allowing optimizations to hoist certain loads above
+stack maps.</p>
+<div class="section" id="direct-stack-map-entries">
+<h3><a class="toc-backref" href="#id13">Direct Stack Map Entries</a><a class="headerlink" href="#direct-stack-map-entries" title="Permalink to this headline">¶</a></h3>
+<p>As shown in <a class="reference internal" href="#stackmap-section"><em>Stack Map Section</em></a>, a Direct stack map location
+records the address of frame index. This address is itself the value
+that the runtime requested. This differs from Indirect locations,
+which refer to a stack locations from which the requested values must
+be loaded. Direct locations can communicate the address if an alloca,
+while Indirect locations handle register spills.</p>
+<p>For example:</p>
+<div class="highlight-none"><div class="highlight"><pre>entry:
+ %a = alloca i64...
+ llvm.experimental.stackmap(i64 <ID>, i32 <shadowBytes>, i64* %a)
+</pre></div>
+</div>
+<p>The runtime can determine this alloca’s relative location on the
+stack immediately after compilation, or at any time thereafter. This
+differs from Register and Indirect locations, because the runtime can
+only read the values in those locations when execution reaches the
+instruction address of the stack map.</p>
+<p>This functionality requires LLVM to treat entry-block allocas
+specially when they are directly consumed by an intrinsics. (This is
+the same requirement imposed by the llvm.gcroot intrinsic.) LLVM
+transformations must not substitute the alloca with any intervening
+value. This can be verified by the runtime simply by checking that the
+stack map’s location is a Direct location type.</p>
+</div>
+</div>
+</div>
+
+
+ </div>
+ </div>
+ <div class="clearer"></div>
+ </div>
+ <div class="related">
+ <h3>Navigation</h3>
+ <ul>
+ <li class="right" style="margin-right: 10px">
+ <a href="genindex.html" title="General Index"
+ >index</a></li>
+ <li class="right" >
+ <a href="InAlloca.html" title="Design and Usage of the InAlloca Attribute"
+ >next</a> |</li>
+ <li class="right" >
+ <a href="AMDGPUUsage.html" title="User Guide for AMDGPU Back-end"
+ >previous</a> |</li>
+ <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+ <li><a href="index.html">Documentation</a>»</li>
+
+ </ul>
+ </div>
+ <div class="footer">
+ © Copyright 2003-2016, LLVM Project.
+ Last updated on 2016-01-04.
+ Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.3.
+ </div>
+ </body>
+</html>
\ No newline at end of file
Added: www-releases/trunk/3.7.1/docs/Statepoints.html
URL: http://llvm.org/viewvc/llvm-project/www-releases/trunk/3.7.1/docs/Statepoints.html?rev=257950&view=auto
==============================================================================
--- www-releases/trunk/3.7.1/docs/Statepoints.html (added)
+++ www-releases/trunk/3.7.1/docs/Statepoints.html Fri Jan 15 17:13:16 2016
@@ -0,0 +1,738 @@
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
+ <title>Garbage Collection Safepoints in LLVM — LLVM 3.7 documentation</title>
+
+ <link rel="stylesheet" href="_static/llvm-theme.css" type="text/css" />
+ <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
+
+ <script type="text/javascript">
+ var DOCUMENTATION_OPTIONS = {
+ URL_ROOT: './',
+ VERSION: '3.7',
+ COLLAPSE_INDEX: false,
+ FILE_SUFFIX: '.html',
+ HAS_SOURCE: true
+ };
+ </script>
+ <script type="text/javascript" src="_static/jquery.js"></script>
+ <script type="text/javascript" src="_static/underscore.js"></script>
+ <script type="text/javascript" src="_static/doctools.js"></script>
+ <link rel="top" title="LLVM 3.7 documentation" href="index.html" />
+ <link rel="next" title="MergeFunctions pass, how it works" href="MergeFunctions.html" />
+ <link rel="prev" title="LLVM Code Coverage Mapping Format" href="CoverageMappingFormat.html" />
+<style type="text/css">
+ table.right { float: right; margin-left: 20px; }
+ table.right td { border: 1px solid #ccc; }
+</style>
+
+ </head>
+ <body>
+<div class="logo">
+ <a href="index.html">
+ <img src="_static/logo.png"
+ alt="LLVM Logo" width="250" height="88"/></a>
+</div>
+
+ <div class="related">
+ <h3>Navigation</h3>
+ <ul>
+ <li class="right" style="margin-right: 10px">
+ <a href="genindex.html" title="General Index"
+ accesskey="I">index</a></li>
+ <li class="right" >
+ <a href="MergeFunctions.html" title="MergeFunctions pass, how it works"
+ accesskey="N">next</a> |</li>
+ <li class="right" >
+ <a href="CoverageMappingFormat.html" title="LLVM Code Coverage Mapping Format"
+ accesskey="P">previous</a> |</li>
+ <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+ <li><a href="index.html">Documentation</a>»</li>
+
+ </ul>
+ </div>
+
+
+ <div class="document">
+ <div class="documentwrapper">
+ <div class="body">
+
+ <div class="section" id="garbage-collection-safepoints-in-llvm">
+<h1>Garbage Collection Safepoints in LLVM<a class="headerlink" href="#garbage-collection-safepoints-in-llvm" title="Permalink to this headline">¶</a></h1>
+<div class="contents local topic" id="contents">
+<ul class="simple">
+<li><a class="reference internal" href="#status" id="id12">Status</a></li>
+<li><a class="reference internal" href="#overview" id="id13">Overview</a><ul>
+<li><a class="reference internal" href="#gc-transitions" id="id14">GC Transitions</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#intrinsics" id="id15">Intrinsics</a><ul>
+<li><a class="reference internal" href="#llvm-experimental-gc-statepoint-intrinsic" id="id16">‘llvm.experimental.gc.statepoint’ Intrinsic</a></li>
+<li><a class="reference internal" href="#llvm-experimental-gc-result-intrinsic" id="id17">‘llvm.experimental.gc.result’ Intrinsic</a></li>
+<li><a class="reference internal" href="#llvm-experimental-gc-relocate-intrinsic" id="id18">‘llvm.experimental.gc.relocate’ Intrinsic</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#stack-map-format" id="id19">Stack Map Format</a></li>
+<li><a class="reference internal" href="#safepoint-semantics-verification" id="id20">Safepoint Semantics & Verification</a></li>
+<li><a class="reference internal" href="#utility-passes-for-safepoint-insertion" id="id21">Utility Passes for Safepoint Insertion</a><ul>
+<li><a class="reference internal" href="#rewritestatepointsforgc" id="id22">RewriteStatepointsForGC</a></li>
+<li><a class="reference internal" href="#placesafepoints" id="id23">PlaceSafepoints</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#bugs-and-enhancements" id="id24">Bugs and Enhancements</a></li>
+</ul>
+</div>
+<div class="section" id="status">
+<h2><a class="toc-backref" href="#id12">Status</a><a class="headerlink" href="#status" title="Permalink to this headline">¶</a></h2>
+<p>This document describes a set of experimental extensions to LLVM. Use
+with caution. Because the intrinsics have experimental status,
+compatibility across LLVM releases is not guaranteed.</p>
+<p>LLVM currently supports an alternate mechanism for conservative
+garbage collection support using the <tt class="docutils literal"><span class="pre">gcroot</span></tt> intrinsic. The mechanism
+described here shares little in common with the alternate <tt class="docutils literal"><span class="pre">gcroot</span></tt>
+implementation and it is hoped that this mechanism will eventually
+replace the gc_root mechanism.</p>
+</div>
+<div class="section" id="overview">
+<h2><a class="toc-backref" href="#id13">Overview</a><a class="headerlink" href="#overview" title="Permalink to this headline">¶</a></h2>
+<p>To collect dead objects, garbage collectors must be able to identify
+any references to objects contained within executing code, and,
+depending on the collector, potentially update them. The collector
+does not need this information at all points in code - that would make
+the problem much harder - but only at well-defined points in the
+execution known as ‘safepoints’ For most collectors, it is sufficient
+to track at least one copy of each unique pointer value. However, for
+a collector which wishes to relocate objects directly reachable from
+running code, a higher standard is required.</p>
+<p>One additional challenge is that the compiler may compute intermediate
+results (“derived pointers”) which point outside of the allocation or
+even into the middle of another allocation. The eventual use of this
+intermediate value must yield an address within the bounds of the
+allocation, but such “exterior derived pointers” may be visible to the
+collector. Given this, a garbage collector can not safely rely on the
+runtime value of an address to indicate the object it is associated
+with. If the garbage collector wishes to move any object, the
+compiler must provide a mapping, for each pointer, to an indication of
+its allocation.</p>
+<p>To simplify the interaction between a collector and the compiled code,
+most garbage collectors are organized in terms of three abstractions:
+load barriers, store barriers, and safepoints.</p>
+<ol class="arabic simple">
+<li>A load barrier is a bit of code executed immediately after the
+machine load instruction, but before any use of the value loaded.
+Depending on the collector, such a barrier may be needed for all
+loads, merely loads of a particular type (in the original source
+language), or none at all.</li>
+<li>Analogously, a store barrier is a code fragement that runs
+immediately before the machine store instruction, but after the
+computation of the value stored. The most common use of a store
+barrier is to update a ‘card table’ in a generational garbage
+collector.</li>
+<li>A safepoint is a location at which pointers visible to the compiled
+code (i.e. currently in registers or on the stack) are allowed to
+change. After the safepoint completes, the actual pointer value
+may differ, but the ‘object’ (as seen by the source language)
+pointed to will not.</li>
+</ol>
+<blockquote>
+<div>Note that the term ‘safepoint’ is somewhat overloaded. It refers to
+both the location at which the machine state is parsable and the
+coordination protocol involved in bring application threads to a
+point at which the collector can safely use that information. The
+term “statepoint” as used in this document refers exclusively to the
+former.</div></blockquote>
+<p>This document focuses on the last item - compiler support for
+safepoints in generated code. We will assume that an outside
+mechanism has decided where to place safepoints. From our
+perspective, all safepoints will be function calls. To support
+relocation of objects directly reachable from values in compiled code,
+the collector must be able to:</p>
+<ol class="arabic simple">
+<li>identify every copy of a pointer (including copies introduced by
+the compiler itself) at the safepoint,</li>
+<li>identify which object each pointer relates to, and</li>
+<li>potentially update each of those copies.</li>
+</ol>
+<p>This document describes the mechanism by which an LLVM based compiler
+can provide this information to a language runtime/collector, and
+ensure that all pointers can be read and updated if desired. The
+heart of the approach is to construct (or rewrite) the IR in a manner
+where the possible updates performed by the garbage collector are
+explicitly visible in the IR. Doing so requires that we:</p>
+<ol class="arabic simple">
+<li>create a new SSA value for each potentially relocated pointer, and
+ensure that no uses of the original (non relocated) value is
+reachable after the safepoint,</li>
+<li>specify the relocation in a way which is opaque to the compiler to
+ensure that the optimizer can not introduce new uses of an
+unrelocated value after a statepoint. This prevents the optimizer
+from performing unsound optimizations.</li>
+<li>recording a mapping of live pointers (and the allocation they’re
+associated with) for each statepoint.</li>
+</ol>
+<p>At the most abstract level, inserting a safepoint can be thought of as
+replacing a call instruction with a call to a multiple return value
+function which both calls the original target of the call, returns
+it’s result, and returns updated values for any live pointers to
+garbage collected objects.</p>
+<blockquote>
+<div>Note that the task of identifying all live pointers to garbage
+collected values, transforming the IR to expose a pointer giving the
+base object for every such live pointer, and inserting all the
+intrinsics correctly is explicitly out of scope for this document.
+The recommended approach is to use the <a class="reference internal" href="#statepoint-utilities"><em>utility passes</em></a> described below.</div></blockquote>
+<p>This abstract function call is concretely represented by a sequence of
+intrinsic calls known collectively as a “statepoint relocation sequence”.</p>
+<p>Let’s consider a simple call in LLVM IR:</p>
+<div class="highlight-llvm"><div class="highlight"><pre><span class="k">define</span> <span class="k">i8</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">1</span><span class="p">)*</span> <span class="vg">@test1</span><span class="p">(</span><span class="k">i8</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">1</span><span class="p">)*</span> <span class="nv">%obj</span><span class="p">)</span>
+ <span class="k">gc</span> <span class="s">"statepoint-example"</span> <span class="p">{</span>
+ <span class="k">call</span> <span class="kt">void</span> <span class="p">()*</span> <span class="vg">@foo</span><span class="p">()</span>
+ <span class="k">ret</span> <span class="k">i8</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">1</span><span class="p">)*</span> <span class="nv">%obj</span>
+<span class="p">}</span>
+</pre></div>
+</div>
+<p>Depending on our language we may need to allow a safepoint during the execution
+of <tt class="docutils literal"><span class="pre">foo</span></tt>. If so, we need to let the collector update local values in the
+current frame. If we don’t, we’ll be accessing a potential invalid reference
+once we eventually return from the call.</p>
+<p>In this example, we need to relocate the SSA value <tt class="docutils literal"><span class="pre">%obj</span></tt>. Since we can’t
+actually change the value in the SSA value <tt class="docutils literal"><span class="pre">%obj</span></tt>, we need to introduce a new
+SSA value <tt class="docutils literal"><span class="pre">%obj.relocated</span></tt> which represents the potentially changed value of
+<tt class="docutils literal"><span class="pre">%obj</span></tt> after the safepoint and update any following uses appropriately. The
+resulting relocation sequence is:</p>
+<div class="highlight-llvm"><div class="highlight"><pre><span class="k">define</span> <span class="k">i8</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">1</span><span class="p">)*</span> <span class="vg">@test1</span><span class="p">(</span><span class="k">i8</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">1</span><span class="p">)*</span> <span class="nv">%obj</span><span class="p">)</span>
+ <span class="k">gc</span> <span class="s">"statepoint-example"</span> <span class="p">{</span>
+ <span class="nv-Anonymous">%0</span> <span class="p">=</span> <span class="k">call</span> <span class="k">i32</span> <span class="p">(</span><span class="k">i64</span><span class="p">,</span> <span class="k">i32</span><span class="p">,</span> <span class="kt">void</span> <span class="p">()*,</span> <span class="k">i32</span><span class="p">,</span> <span class="k">i32</span><span class="p">,</span> <span class="p">...)*</span> <span class="vg">@llvm.experimental.gc.statepoint.p0f_isVoidf</span><span class="p">(</span><span class="k">i64</span> <span class="m">0</span><span class="p">,</span> <span class="k">i32</span> <span class="m">0</span><span class="p">,</span> <span class="kt">void</span> <span class="p">()*</span> <span class="vg">@foo</span><span class="p">,</span> <span class="k">i32</span> <span class="m">0</span><span class="p">,</span> <span class="k">i32</span> <span class="m">0</span><span class="p">,</span> <span class="k">i32</span> <span class="m">0</span><span cl
ass="p">,</span> <span class="k">i32</span> <span class="m">0</span><span class="p">,</span> <span class="k">i8</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">1</span><span class="p">)*</span> <span class="nv">%obj</span><span class="p">)</span>
+ <span class="nv">%obj.relocated</span> <span class="p">=</span> <span class="k">call</span> <span class="k">coldcc</span> <span class="k">i8</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">1</span><span class="p">)*</span> <span class="vg">@llvm.experimental.gc.relocate.p1i8</span><span class="p">(</span><span class="k">i32</span> <span class="nv-Anonymous">%0</span><span class="p">,</span> <span class="k">i32</span> <span class="m">7</span><span class="p">,</span> <span class="k">i32</span> <span class="m">7</span><span class="p">)</span>
+ <span class="k">ret</span> <span class="k">i8</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">1</span><span class="p">)*</span> <span class="nv">%obj.relocated</span>
+<span class="p">}</span>
+</pre></div>
+</div>
+<p>Ideally, this sequence would have been represented as a M argument, N
+return value function (where M is the number of values being
+relocated + the original call arguments and N is the original return
+value + each relocated value), but LLVM does not easily support such a
+representation.</p>
+<p>Instead, the statepoint intrinsic marks the actual site of the
+safepoint or statepoint. The statepoint returns a token value (which
+exists only at compile time). To get back the original return value
+of the call, we use the <tt class="docutils literal"><span class="pre">gc.result</span></tt> intrinsic. To get the relocation
+of each pointer in turn, we use the <tt class="docutils literal"><span class="pre">gc.relocate</span></tt> intrinsic with the
+appropriate index. Note that both the <tt class="docutils literal"><span class="pre">gc.relocate</span></tt> and <tt class="docutils literal"><span class="pre">gc.result</span></tt> are
+tied to the statepoint. The combination forms a “statepoint relocation
+sequence” and represents the entitety of a parseable call or ‘statepoint’.</p>
+<p>When lowered, this example would generate the following x86 assembly:</p>
+<div class="highlight-gas"><div class="highlight"><pre> <span class="na">.globl</span> <span class="no">test1</span>
+ <span class="na">.align</span> <span class="mi">16</span><span class="p">,</span> <span class="mi">0x90</span>
+ <span class="nf">pushq</span> <span class="nv">%rax</span>
+ <span class="nf">callq</span> <span class="no">foo</span>
+<span class="nl">.Ltmp1:</span>
+ <span class="nf">movq</span> <span class="p">(</span><span class="nv">%rsp</span><span class="p">),</span> <span class="nv">%rax</span> <span class="c"># This load is redundant (oops!)</span>
+ <span class="nf">popq</span> <span class="nv">%rdx</span>
+ <span class="nf">retq</span>
+</pre></div>
+</div>
+<p>Each of the potentially relocated values has been spilled to the
+stack, and a record of that location has been recorded to the
+<a class="reference internal" href="StackMaps.html#stackmap-section"><em>Stack Map section</em></a>. If the garbage collector
+needs to update any of these pointers during the call, it knows
+exactly what to change.</p>
+<p>The relevant parts of the StackMap section for our example are:</p>
+<div class="highlight-gas"><div class="highlight"><pre><span class="c"># This describes the call site</span>
+<span class="c"># Stack Maps: callsite 2882400000</span>
+ <span class="na">.quad</span> <span class="mi">2882400000</span>
+ <span class="na">.long</span> <span class="no">.Ltmp1-test1</span>
+ <span class="na">.short</span> <span class="mi">0</span>
+<span class="c"># .. 8 entries skipped ..</span>
+<span class="c"># This entry describes the spill slot which is directly addressable</span>
+<span class="c"># off RSP with offset 0. Given the value was spilled with a pushq,</span>
+<span class="c"># that makes sense.</span>
+<span class="c"># Stack Maps: Loc 8: Direct RSP [encoding: .byte 2, .byte 8, .short 7, .int 0]</span>
+ <span class="na">.byte</span> <span class="mi">2</span>
+ <span class="na">.byte</span> <span class="mi">8</span>
+ <span class="na">.short</span> <span class="mi">7</span>
+ <span class="na">.long</span> <span class="mi">0</span>
+</pre></div>
+</div>
+<p>This example was taken from the tests for the <a class="reference internal" href="#rewritestatepointsforgc"><em>RewriteStatepointsForGC</em></a> utility pass. As such, it’s full StackMap can be easily examined with the following command.</p>
+<div class="highlight-bash"><div class="highlight"><pre>opt -rewrite-statepoints-for-gc <span class="nb">test</span>/Transforms/RewriteStatepointsForGC/basics.ll -S | llc -debug-only<span class="o">=</span>stackmaps
+</pre></div>
+</div>
+<div class="section" id="gc-transitions">
+<h3><a class="toc-backref" href="#id14">GC Transitions</a><a class="headerlink" href="#gc-transitions" title="Permalink to this headline">¶</a></h3>
+<p>As a practical consideration, many garbage-collected systems allow code that is
+collector-aware (“managed code”) to call code that is not collector-aware
+(“unmanaged code”). It is common that such calls must also be safepoints, since
+it is desirable to allow the collector to run during the execution of
+unmanaged code. Futhermore, it is common that coordinating the transition from
+managed to unmanaged code requires extra code generation at the call site to
+inform the collector of the transition. In order to support these needs, a
+statepoint may be marked as a GC transition, and data that is necessary to
+perform the transition (if any) may be provided as additional arguments to the
+statepoint.</p>
+<blockquote>
+<div>Note that although in many cases statepoints may be inferred to be GC
+transitions based on the function symbols involved (e.g. a call from a
+function with GC strategy “foo” to a function with GC strategy “bar”),
+indirect calls that are also GC transitions must also be supported. This
+requirement is the driving force behing the decision to require that GC
+transitions are explicitly marked.</div></blockquote>
+<p>Let’s revisit the sample given above, this time treating the call to <tt class="docutils literal"><span class="pre">@foo</span></tt>
+as a GC transition. Depending on our target, the transition code may need to
+access some extra state in order to inform the collector of the transition.
+Let’s assume a hypothetical GC–somewhat unimaginatively named “hypothetical-gc”
+–that requires that a TLS variable must be written to before and after a call
+to unmanaged code. The resulting relocation sequence is:</p>
+<div class="highlight-llvm"><div class="highlight"><pre><span class="vg">@flag</span> <span class="p">=</span> <span class="k">thread_local</span> <span class="k">global</span> <span class="k">i32</span> <span class="m">0</span><span class="p">,</span> <span class="k">align</span> <span class="m">4</span>
+
+<span class="k">define</span> <span class="k">i8</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">1</span><span class="p">)*</span> <span class="vg">@test1</span><span class="p">(</span><span class="k">i8</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">1</span><span class="p">)</span> <span class="p">*</span><span class="nv">%obj</span><span class="p">)</span>
+ <span class="k">gc</span> <span class="s">"hypothetical-gc"</span> <span class="p">{</span>
+
+ <span class="nv-Anonymous">%0</span> <span class="p">=</span> <span class="k">call</span> <span class="k">i32</span> <span class="p">(</span><span class="k">i64</span><span class="p">,</span> <span class="k">i32</span><span class="p">,</span> <span class="kt">void</span> <span class="p">()*,</span> <span class="k">i32</span><span class="p">,</span> <span class="k">i32</span><span class="p">,</span> <span class="p">...)*</span> <span class="vg">@llvm.experimental.gc.statepoint.p0f_isVoidf</span><span class="p">(</span><span class="k">i64</span> <span class="m">0</span><span class="p">,</span> <span class="k">i32</span> <span class="m">0</span><span class="p">,</span> <span class="kt">void</span> <span class="p">()*</span> <span class="vg">@foo</span><span class="p">,</span> <span class="k">i32</span> <span class="m">0</span><span class="p">,</span> <span class="k">i32</span> <span class="m">1</span><span class="p">,</span> <span class="k">i32</span><span class="p">*</span> <span cl
ass="vg">@Flag</span><span class="p">,</span> <span class="k">i32</span> <span class="m">0</span><span class="p">,</span> <span class="k">i8</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">1</span><span class="p">)*</span> <span class="nv">%obj</span><span class="p">)</span>
+ <span class="nv">%obj.relocated</span> <span class="p">=</span> <span class="k">call</span> <span class="k">coldcc</span> <span class="k">i8</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">1</span><span class="p">)*</span> <span class="vg">@llvm.experimental.gc.relocate.p1i8</span><span class="p">(</span><span class="k">i32</span> <span class="nv-Anonymous">%0</span><span class="p">,</span> <span class="k">i32</span> <span class="m">7</span><span class="p">,</span> <span class="k">i32</span> <span class="m">7</span><span class="p">)</span>
+ <span class="k">ret</span> <span class="k">i8</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">1</span><span class="p">)*</span> <span class="nv">%obj.relocated</span>
+<span class="p">}</span>
+</pre></div>
+</div>
+<p>During lowering, this will result in a instruction selection DAG that looks
+something like:</p>
+<div class="highlight-python"><div class="highlight"><pre>CALLSEQ_START
+...
+GC_TRANSITION_START (lowered i32 *@Flag), SRCVALUE i32* Flag
+STATEPOINT
+GC_TRANSITION_END (lowered i32 *@Flag), SRCVALUE i32 *Flag
+...
+CALLSEQ_END
+</pre></div>
+</div>
+<p>In order to generate the necessary transition code, the backend for each target
+supported by “hypothetical-gc” must be modified to lower <tt class="docutils literal"><span class="pre">GC_TRANSITION_START</span></tt>
+and <tt class="docutils literal"><span class="pre">GC_TRANSITION_END</span></tt> nodes appropriately when the “hypothetical-gc”
+strategy is in use for a particular function. Assuming that such lowering has
+been added for X86, the generated assembly would be:</p>
+<div class="highlight-gas"><div class="highlight"><pre> <span class="na">.globl</span> <span class="no">test1</span>
+ <span class="na">.align</span> <span class="mi">16</span><span class="p">,</span> <span class="mi">0x90</span>
+ <span class="nf">pushq</span> <span class="nv">%rax</span>
+ <span class="nf">movl</span> <span class="no">$1</span><span class="p">,</span> <span class="nv">%fs</span><span class="p">:</span><span class="no">Flag at TPOFF</span>
+ <span class="nf">callq</span> <span class="no">foo</span>
+ <span class="nf">movl</span> <span class="no">$0</span><span class="p">,</span> <span class="nv">%fs</span><span class="p">:</span><span class="no">Flag at TPOFF</span>
+<span class="nl">.Ltmp1:</span>
+ <span class="nf">movq</span> <span class="p">(</span><span class="nv">%rsp</span><span class="p">),</span> <span class="nv">%rax</span> <span class="c"># This load is redundant (oops!)</span>
+ <span class="nf">popq</span> <span class="nv">%rdx</span>
+ <span class="nf">retq</span>
+</pre></div>
+</div>
+<p>Note that the design as presented above is not fully implemented: in particular,
+strategy-specific lowering is not present, and all GC transitions are emitted as
+as single no-op before and after the call instruction. These no-ops are often
+removed by the backend during dead machine instruction elimination.</p>
+</div>
+</div>
+<div class="section" id="intrinsics">
+<h2><a class="toc-backref" href="#id15">Intrinsics</a><a class="headerlink" href="#intrinsics" title="Permalink to this headline">¶</a></h2>
+<div class="section" id="llvm-experimental-gc-statepoint-intrinsic">
+<h3><a class="toc-backref" href="#id16">‘llvm.experimental.gc.statepoint’ Intrinsic</a><a class="headerlink" href="#llvm-experimental-gc-statepoint-intrinsic" title="Permalink to this headline">¶</a></h3>
+<div class="section" id="syntax">
+<h4>Syntax:<a class="headerlink" href="#syntax" title="Permalink to this headline">¶</a></h4>
+<div class="highlight-python"><div class="highlight"><pre>declare i32
+ @llvm.experimental.gc.statepoint(i64 <id>, i32 <num patch bytes>,
+ func_type <target>,
+ i64 <#call args>, i64 <flags>,
+ ... (call parameters),
+ i64 <# transition args>, ... (transition parameters),
+ i64 <# deopt args>, ... (deopt parameters),
+ ... (gc parameters))
+</pre></div>
+</div>
+</div>
+<div class="section" id="id1">
+<h4>Overview:<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h4>
+<p>The statepoint intrinsic represents a call which is parse-able by the
+runtime.</p>
+</div>
+<div class="section" id="operands">
+<h4>Operands:<a class="headerlink" href="#operands" title="Permalink to this headline">¶</a></h4>
+<p>The ‘id’ operand is a constant integer that is reported as the ID
+field in the generated stackmap. LLVM does not interpret this
+parameter in any way and its meaning is up to the statepoint user to
+decide. Note that LLVM is free to duplicate code containing
+statepoint calls, and this may transform IR that had a unique ‘id’ per
+lexical call to statepoint to IR that does not.</p>
+<p>If ‘num patch bytes’ is non-zero then the call instruction
+corresponding to the statepoint is not emitted and LLVM emits ‘num
+patch bytes’ bytes of nops in its place. LLVM will emit code to
+prepare the function arguments and retrieve the function return value
+in accordance to the calling convention; the former before the nop
+sequence and the latter after the nop sequence. It is expected that
+the user will patch over the ‘num patch bytes’ bytes of nops with a
+calling sequence specific to their runtime before executing the
+generated machine code. There are no guarantees with respect to the
+alignment of the nop sequence. Unlike <a class="reference internal" href="StackMaps.html"><em>Stack maps and patch points in LLVM</em></a> statepoints do
+not have a concept of shadow bytes.</p>
+<p>The ‘target’ operand is the function actually being called. The
+target can be specified as either a symbolic LLVM function, or as an
+arbitrary Value of appropriate function type. Note that the function
+type must match the signature of the callee and the types of the ‘call
+parameters’ arguments. If ‘num patch bytes’ is non-zero then ‘target’
+has to be the constant pointer null of the appropriate function type.</p>
+<p>The ‘#call args’ operand is the number of arguments to the actual
+call. It must exactly match the number of arguments passed in the
+‘call parameters’ variable length section.</p>
+<p>The ‘flags’ operand is used to specify extra information about the
+statepoint. This is currently only used to mark certain statepoints
+as GC transitions. This operand is a 64-bit integer with the following
+layout, where bit 0 is the least significant bit:</p>
+<blockquote>
+<div><table border="1" class="docutils">
+<colgroup>
+<col width="12%" />
+<col width="88%" />
+</colgroup>
+<thead valign="bottom">
+<tr class="row-odd"><th class="head">Bit #</th>
+<th class="head">Usage</th>
+</tr>
+</thead>
+<tbody valign="top">
+<tr class="row-even"><td>0</td>
+<td>Set if the statepoint is a GC transition, cleared
+otherwise.</td>
+</tr>
+<tr class="row-odd"><td>1-63</td>
+<td>Reserved for future use; must be cleared.</td>
+</tr>
+</tbody>
+</table>
+</div></blockquote>
+<p>The ‘call parameters’ arguments are simply the arguments which need to
+be passed to the call target. They will be lowered according to the
+specified calling convention and otherwise handled like a normal call
+instruction. The number of arguments must exactly match what is
+specified in ‘# call args’. The types must match the signature of
+‘target’.</p>
+<p>The ‘transition parameters’ arguments contain an arbitrary list of
+Values which need to be passed to GC transition code. They will be
+lowered and passed as operands to the appropriate GC_TRANSITION nodes
+in the selection DAG. It is assumed that these arguments must be
+available before and after (but not necessarily during) the execution
+of the callee. The ‘# transition args’ field indicates how many operands
+are to be interpreted as ‘transition parameters’.</p>
+<p>The ‘deopt parameters’ arguments contain an arbitrary list of Values
+which is meaningful to the runtime. The runtime may read any of these
+values, but is assumed not to modify them. If the garbage collector
+might need to modify one of these values, it must also be listed in
+the ‘gc pointer’ argument list. The ‘# deopt args’ field indicates
+how many operands are to be interpreted as ‘deopt parameters’.</p>
+<p>The ‘gc parameters’ arguments contain every pointer to a garbage
+collector object which potentially needs to be updated by the garbage
+collector. Note that the argument list must explicitly contain a base
+pointer for every derived pointer listed. The order of arguments is
+unimportant. Unlike the other variable length parameter sets, this
+list is not length prefixed.</p>
+</div>
+<div class="section" id="semantics">
+<h4>Semantics:<a class="headerlink" href="#semantics" title="Permalink to this headline">¶</a></h4>
+<p>A statepoint is assumed to read and write all memory. As a result,
+memory operations can not be reordered past a statepoint. It is
+illegal to mark a statepoint as being either ‘readonly’ or ‘readnone’.</p>
+<p>Note that legal IR can not perform any memory operation on a ‘gc
+pointer’ argument of the statepoint in a location statically reachable
+from the statepoint. Instead, the explicitly relocated value (from a
+<tt class="docutils literal"><span class="pre">gc.relocate</span></tt>) must be used.</p>
+</div>
+</div>
+<div class="section" id="llvm-experimental-gc-result-intrinsic">
+<h3><a class="toc-backref" href="#id17">‘llvm.experimental.gc.result’ Intrinsic</a><a class="headerlink" href="#llvm-experimental-gc-result-intrinsic" title="Permalink to this headline">¶</a></h3>
+<div class="section" id="id2">
+<h4>Syntax:<a class="headerlink" href="#id2" title="Permalink to this headline">¶</a></h4>
+<div class="highlight-python"><div class="highlight"><pre>declare type*
+ @llvm.experimental.gc.result(i32 %statepoint_token)
+</pre></div>
+</div>
+</div>
+<div class="section" id="id3">
+<h4>Overview:<a class="headerlink" href="#id3" title="Permalink to this headline">¶</a></h4>
+<p><tt class="docutils literal"><span class="pre">gc.result</span></tt> extracts the result of the original call instruction
+which was replaced by the <tt class="docutils literal"><span class="pre">gc.statepoint</span></tt>. The <tt class="docutils literal"><span class="pre">gc.result</span></tt>
+intrinsic is actually a family of three intrinsics due to an
+implementation limitation. Other than the type of the return value,
+the semantics are the same.</p>
+</div>
+<div class="section" id="id4">
+<h4>Operands:<a class="headerlink" href="#id4" title="Permalink to this headline">¶</a></h4>
+<p>The first and only argument is the <tt class="docutils literal"><span class="pre">gc.statepoint</span></tt> which starts
+the safepoint sequence of which this <tt class="docutils literal"><span class="pre">gc.result</span></tt> is a part.
+Despite the typing of this as a generic i32, <em>only</em> the value defined
+by a <tt class="docutils literal"><span class="pre">gc.statepoint</span></tt> is legal here.</p>
+</div>
+<div class="section" id="id5">
+<h4>Semantics:<a class="headerlink" href="#id5" title="Permalink to this headline">¶</a></h4>
+<p>The <tt class="docutils literal"><span class="pre">gc.result</span></tt> represents the return value of the call target of
+the <tt class="docutils literal"><span class="pre">statepoint</span></tt>. The type of the <tt class="docutils literal"><span class="pre">gc.result</span></tt> must exactly match
+the type of the target. If the call target returns void, there will
+be no <tt class="docutils literal"><span class="pre">gc.result</span></tt>.</p>
+<p>A <tt class="docutils literal"><span class="pre">gc.result</span></tt> is modeled as a ‘readnone’ pure function. It has no
+side effects since it is just a projection of the return value of the
+previous call represented by the <tt class="docutils literal"><span class="pre">gc.statepoint</span></tt>.</p>
+</div>
+</div>
+<div class="section" id="llvm-experimental-gc-relocate-intrinsic">
+<h3><a class="toc-backref" href="#id18">‘llvm.experimental.gc.relocate’ Intrinsic</a><a class="headerlink" href="#llvm-experimental-gc-relocate-intrinsic" title="Permalink to this headline">¶</a></h3>
+<div class="section" id="id6">
+<h4>Syntax:<a class="headerlink" href="#id6" title="Permalink to this headline">¶</a></h4>
+<div class="highlight-python"><div class="highlight"><pre>declare <pointer type>
+ @llvm.experimental.gc.relocate(i32 %statepoint_token,
+ i32 %base_offset,
+ i32 %pointer_offset)
+</pre></div>
+</div>
+</div>
+<div class="section" id="id7">
+<h4>Overview:<a class="headerlink" href="#id7" title="Permalink to this headline">¶</a></h4>
+<p>A <tt class="docutils literal"><span class="pre">gc.relocate</span></tt> returns the potentially relocated value of a pointer
+at the safepoint.</p>
+</div>
+<div class="section" id="id8">
+<h4>Operands:<a class="headerlink" href="#id8" title="Permalink to this headline">¶</a></h4>
+<p>The first argument is the <tt class="docutils literal"><span class="pre">gc.statepoint</span></tt> which starts the
+safepoint sequence of which this <tt class="docutils literal"><span class="pre">gc.relocation</span></tt> is a part.
+Despite the typing of this as a generic i32, <em>only</em> the value defined
+by a <tt class="docutils literal"><span class="pre">gc.statepoint</span></tt> is legal here.</p>
+<p>The second argument is an index into the statepoints list of arguments
+which specifies the base pointer for the pointer being relocated.
+This index must land within the ‘gc parameter’ section of the
+statepoint’s argument list.</p>
+<p>The third argument is an index into the statepoint’s list of arguments
+which specify the (potentially) derived pointer being relocated. It
+is legal for this index to be the same as the second argument
+if-and-only-if a base pointer is being relocated. This index must land
+within the ‘gc parameter’ section of the statepoint’s argument list.</p>
+</div>
+<div class="section" id="id9">
+<h4>Semantics:<a class="headerlink" href="#id9" title="Permalink to this headline">¶</a></h4>
+<p>The return value of <tt class="docutils literal"><span class="pre">gc.relocate</span></tt> is the potentially relocated value
+of the pointer specified by it’s arguments. It is unspecified how the
+value of the returned pointer relates to the argument to the
+<tt class="docutils literal"><span class="pre">gc.statepoint</span></tt> other than that a) it points to the same source
+language object with the same offset, and b) the ‘based-on’
+relationship of the newly relocated pointers is a projection of the
+unrelocated pointers. In particular, the integer value of the pointer
+returned is unspecified.</p>
+<p>A <tt class="docutils literal"><span class="pre">gc.relocate</span></tt> is modeled as a <tt class="docutils literal"><span class="pre">readnone</span></tt> pure function. It has no
+side effects since it is just a way to extract information about work
+done during the actual call modeled by the <tt class="docutils literal"><span class="pre">gc.statepoint</span></tt>.</p>
+</div>
+</div>
+</div>
+<div class="section" id="stack-map-format">
+<span id="statepoint-stackmap-format"></span><h2><a class="toc-backref" href="#id19">Stack Map Format</a><a class="headerlink" href="#stack-map-format" title="Permalink to this headline">¶</a></h2>
+<p>Locations for each pointer value which may need read and/or updated by
+the runtime or collector are provided via the <a class="reference internal" href="StackMaps.html#stackmap-format"><em>Stack Map format</em></a> specified in the PatchPoint documentation.</p>
+<p>Each statepoint generates the following Locations:</p>
+<ul class="simple">
+<li>Constant which describes the calling convention of the call target. This
+constant is a valid <a class="reference internal" href="LangRef.html#callingconv"><em>calling convention identifier</em></a> for
+the version of LLVM used to generate the stackmap. No additional compatibility
+guarantees are made for this constant over what LLVM provides elsewhere w.r.t.
+these identifiers.</li>
+<li>Constant which describes the flags passed to the statepoint intrinsic</li>
+<li>Constant which describes number of following deopt <em>Locations</em> (not
+operands)</li>
+<li>Variable number of Locations, one for each deopt parameter listed in
+the IR statepoint (same number as described by previous Constant)</li>
+<li>Variable number of Locations pairs, one pair for each unique pointer
+which needs relocated. The first Location in each pair describes
+the base pointer for the object. The second is the derived pointer
+actually being relocated. It is guaranteed that the base pointer
+must also appear explicitly as a relocation pair if used after the
+statepoint. There may be fewer pairs then gc parameters in the IR
+statepoint. Each <em>unique</em> pair will occur at least once; duplicates
+are possible.</li>
+</ul>
+<p>Note that the Locations used in each section may describe the same
+physical location. e.g. A stack slot may appear as a deopt location,
+a gc base pointer, and a gc derived pointer.</p>
+<p>The LiveOut section of the StkMapRecord will be empty for a statepoint
+record.</p>
+</div>
+<div class="section" id="safepoint-semantics-verification">
+<h2><a class="toc-backref" href="#id20">Safepoint Semantics & Verification</a><a class="headerlink" href="#safepoint-semantics-verification" title="Permalink to this headline">¶</a></h2>
+<p>The fundamental correctness property for the compiled code’s
+correctness w.r.t. the garbage collector is a dynamic one. It must be
+the case that there is no dynamic trace such that a operation
+involving a potentially relocated pointer is observably-after a
+safepoint which could relocate it. ‘observably-after’ is this usage
+means that an outside observer could observe this sequence of events
+in a way which precludes the operation being performed before the
+safepoint.</p>
+<p>To understand why this ‘observable-after’ property is required,
+consider a null comparison performed on the original copy of a
+relocated pointer. Assuming that control flow follows the safepoint,
+there is no way to observe externally whether the null comparison is
+performed before or after the safepoint. (Remember, the original
+Value is unmodified by the safepoint.) The compiler is free to make
+either scheduling choice.</p>
+<p>The actual correctness property implemented is slightly stronger than
+this. We require that there be no <em>static path</em> on which a
+potentially relocated pointer is ‘observably-after’ it may have been
+relocated. This is slightly stronger than is strictly necessary (and
+thus may disallow some otherwise valid programs), but greatly
+simplifies reasoning about correctness of the compiled code.</p>
+<p>By construction, this property will be upheld by the optimizer if
+correctly established in the source IR. This is a key invariant of
+the design.</p>
+<p>The existing IR Verifier pass has been extended to check most of the
+local restrictions on the intrinsics mentioned in their respective
+documentation. The current implementation in LLVM does not check the
+key relocation invariant, but this is ongoing work on developing such
+a verifier. Please ask on llvm-dev if you’re interested in
+experimenting with the current version.</p>
+</div>
+<div class="section" id="utility-passes-for-safepoint-insertion">
+<span id="statepoint-utilities"></span><h2><a class="toc-backref" href="#id21">Utility Passes for Safepoint Insertion</a><a class="headerlink" href="#utility-passes-for-safepoint-insertion" title="Permalink to this headline">¶</a></h2>
+<div class="section" id="rewritestatepointsforgc">
+<span id="id10"></span><h3><a class="toc-backref" href="#id22">RewriteStatepointsForGC</a><a class="headerlink" href="#rewritestatepointsforgc" title="Permalink to this headline">¶</a></h3>
+<p>The pass RewriteStatepointsForGC transforms a functions IR by replacing a
+<tt class="docutils literal"><span class="pre">gc.statepoint</span></tt> (with an optional <tt class="docutils literal"><span class="pre">gc.result</span></tt>) with a full relocation
+sequence, including all required <tt class="docutils literal"><span class="pre">gc.relocates</span></tt>. To function, the pass
+requires that the GC strategy specified for the function be able to reliably
+distinguish between GC references and non-GC references in IR it is given.</p>
+<p>As an example, given this code:</p>
+<div class="highlight-llvm"><div class="highlight"><pre><span class="k">define</span> <span class="k">i8</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">1</span><span class="p">)*</span> <span class="vg">@test1</span><span class="p">(</span><span class="k">i8</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">1</span><span class="p">)*</span> <span class="nv">%obj</span><span class="p">)</span>
+ <span class="k">gc</span> <span class="s">"statepoint-example"</span> <span class="p">{</span>
+ <span class="k">call</span> <span class="k">i32</span> <span class="p">(</span><span class="k">i64</span><span class="p">,</span> <span class="k">i32</span><span class="p">,</span> <span class="kt">void</span> <span class="p">()*,</span> <span class="k">i32</span><span class="p">,</span> <span class="k">i32</span><span class="p">,</span> <span class="p">...)*</span> <span class="vg">@llvm.experimental.gc.statepoint.p0f_isVoidf</span><span class="p">(</span><span class="k">i64</span> <span class="m">2882400000</span><span class="p">,</span> <span class="k">i32</span> <span class="m">0</span><span class="p">,</span> <span class="kt">void</span> <span class="p">()*</span> <span class="vg">@foo</span><span class="p">,</span> <span class="k">i32</span> <span class="m">0</span><span class="p">,</span> <span class="k">i32</span> <span class="m">0</span><span class="p">,</span> <span class="k">i32</span> <span class="m">0</span><span class="p">,</span> <span class="k">i32</span> <span cla
ss="m">5</span><span class="p">,</span> <span class="k">i32</span> <span class="m">0</span><span class="p">,</span> <span class="k">i32</span> <span class="m">-1</span><span class="p">,</span> <span class="k">i32</span> <span class="m">0</span><span class="p">,</span> <span class="k">i32</span> <span class="m">0</span><span class="p">,</span> <span class="k">i32</span> <span class="m">0</span><span class="p">)</span>
+ <span class="k">ret</span> <span class="k">i8</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">1</span><span class="p">)*</span> <span class="nv">%obj</span>
+<span class="p">}</span>
+</pre></div>
+</div>
+<p>The pass would produce this IR:</p>
+<div class="highlight-llvm"><div class="highlight"><pre><span class="k">define</span> <span class="k">i8</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">1</span><span class="p">)*</span> <span class="vg">@test1</span><span class="p">(</span><span class="k">i8</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">1</span><span class="p">)*</span> <span class="nv">%obj</span><span class="p">)</span>
+ <span class="k">gc</span> <span class="s">"statepoint-example"</span> <span class="p">{</span>
+ <span class="nv-Anonymous">%0</span> <span class="p">=</span> <span class="k">call</span> <span class="k">i32</span> <span class="p">(</span><span class="k">i64</span><span class="p">,</span> <span class="k">i32</span><span class="p">,</span> <span class="kt">void</span> <span class="p">()*,</span> <span class="k">i32</span><span class="p">,</span> <span class="k">i32</span><span class="p">,</span> <span class="p">...)*</span> <span class="vg">@llvm.experimental.gc.statepoint.p0f_isVoidf</span><span class="p">(</span><span class="k">i64</span> <span class="m">2882400000</span><span class="p">,</span> <span class="k">i32</span> <span class="m">0</span><span class="p">,</span> <span class="kt">void</span> <span class="p">()*</span> <span class="vg">@foo</span><span class="p">,</span> <span class="k">i32</span> <span class="m">0</span><span class="p">,</span> <span class="k">i32</span> <span class="m">0</span><span class="p">,</span> <span class="k">i32</span> <span class="m">0</span
><span class="p">,</span> <span class="k">i32</span> <span class="m">5</span><span class="p">,</span> <span class="k">i32</span> <span class="m">0</span><span class="p">,</span> <span class="k">i32</span> <span class="m">-1</span><span class="p">,</span> <span class="k">i32</span> <span class="m">0</span><span class="p">,</span> <span class="k">i32</span> <span class="m">0</span><span class="p">,</span> <span class="k">i32</span> <span class="m">0</span><span class="p">,</span> <span class="k">i8</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">1</span><span class="p">)*</span> <span class="nv">%obj</span><span class="p">)</span>
+ <span class="nv">%obj.relocated</span> <span class="p">=</span> <span class="k">call</span> <span class="k">coldcc</span> <span class="k">i8</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">1</span><span class="p">)*</span> <span class="vg">@llvm.experimental.gc.relocate.p1i8</span><span class="p">(</span><span class="k">i32</span> <span class="nv-Anonymous">%0</span><span class="p">,</span> <span class="k">i32</span> <span class="m">12</span><span class="p">,</span> <span class="k">i32</span> <span class="m">12</span><span class="p">)</span>
+ <span class="k">ret</span> <span class="k">i8</span> <span class="k">addrspace</span><span class="p">(</span><span class="m">1</span><span class="p">)*</span> <span class="nv">%obj.relocated</span>
+<span class="p">}</span>
+</pre></div>
+</div>
+<p>In the above examples, the addrspace(1) marker on the pointers is the mechanism
+that the <tt class="docutils literal"><span class="pre">statepoint-example</span></tt> GC strategy uses to distinguish references from
+non references. Address space 1 is not globally reserved for this purpose.</p>
+<p>This pass can be used an utility function by a language frontend that doesn’t
+want to manually reason about liveness, base pointers, or relocation when
+constructing IR. As currently implemented, RewriteStatepointsForGC must be
+run after SSA construction (i.e. mem2ref).</p>
+<p>In practice, RewriteStatepointsForGC can be run much later in the pass
+pipeline, after most optimization is already done. This helps to improve
+the quality of the generated code when compiled with garbage collection support.
+In the long run, this is the intended usage model. At this time, a few details
+have yet to be worked out about the semantic model required to guarantee this
+is always correct. As such, please use with caution and report bugs.</p>
+</div>
+<div class="section" id="placesafepoints">
+<span id="id11"></span><h3><a class="toc-backref" href="#id23">PlaceSafepoints</a><a class="headerlink" href="#placesafepoints" title="Permalink to this headline">¶</a></h3>
+<p>The pass PlaceSafepoints transforms a function’s IR by replacing any call or
+invoke instructions with appropriate <tt class="docutils literal"><span class="pre">gc.statepoint</span></tt> and <tt class="docutils literal"><span class="pre">gc.result</span></tt> pairs,
+and inserting safepoint polls sufficient to ensure running code checks for a
+safepoint request on a timely manner. This pass is expected to be run before
+RewriteStatepointsForGC and thus does not produce full relocation sequences.</p>
+<p>As an example, given input IR of the following:</p>
+<div class="highlight-llvm"><div class="highlight"><pre><span class="k">define</span> <span class="kt">void</span> <span class="vg">@test</span><span class="p">()</span> <span class="k">gc</span> <span class="s">"statepoint-example"</span> <span class="p">{</span>
+ <span class="k">call</span> <span class="kt">void</span> <span class="vg">@foo</span><span class="p">()</span>
+ <span class="k">ret</span> <span class="kt">void</span>
+<span class="p">}</span>
+
+<span class="k">declare</span> <span class="kt">void</span> <span class="vg">@do_safepoint</span><span class="p">()</span>
+<span class="k">define</span> <span class="kt">void</span> <span class="vg">@gc.safepoint_poll</span><span class="p">()</span> <span class="p">{</span>
+ <span class="k">call</span> <span class="kt">void</span> <span class="vg">@do_safepoint</span><span class="p">()</span>
+ <span class="k">ret</span> <span class="kt">void</span>
+<span class="p">}</span>
+</pre></div>
+</div>
+<p>This pass would produce the following IR:</p>
+<div class="highlight-llvm"><div class="highlight"><pre><span class="k">define</span> <span class="kt">void</span> <span class="vg">@test</span><span class="p">()</span> <span class="k">gc</span> <span class="s">"statepoint-example"</span> <span class="p">{</span>
+ <span class="nv">%safepoint_token</span> <span class="p">=</span> <span class="k">call</span> <span class="k">i32</span> <span class="p">(</span><span class="k">i64</span><span class="p">,</span> <span class="k">i32</span><span class="p">,</span> <span class="kt">void</span> <span class="p">()*,</span> <span class="k">i32</span><span class="p">,</span> <span class="k">i32</span><span class="p">,</span> <span class="p">...)*</span> <span class="vg">@llvm.experimental.gc.statepoint.p0f_isVoidf</span><span class="p">(</span><span class="k">i64</span> <span class="m">2882400000</span><span class="p">,</span> <span class="k">i32</span> <span class="m">0</span><span class="p">,</span> <span class="kt">void</span> <span class="p">()*</span> <span class="vg">@do_safepoint</span><span class="p">,</span> <span class="k">i32</span> <span class="m">0</span><span class="p">,</span> <span class="k">i32</span> <span class="m">0</span><span class="p">,</span> <span class="k">i32</span> <span clas
s="m">0</span><span class="p">,</span> <span class="k">i32</span> <span class="m">0</span><span class="p">)</span>
+ <span class="nv">%safepoint_token1</span> <span class="p">=</span> <span class="k">call</span> <span class="k">i32</span> <span class="p">(</span><span class="k">i64</span><span class="p">,</span> <span class="k">i32</span><span class="p">,</span> <span class="kt">void</span> <span class="p">()*,</span> <span class="k">i32</span><span class="p">,</span> <span class="k">i32</span><span class="p">,</span> <span class="p">...)*</span> <span class="vg">@llvm.experimental.gc.statepoint.p0f_isVoidf</span><span class="p">(</span><span class="k">i64</span> <span class="m">2882400000</span><span class="p">,</span> <span class="k">i32</span> <span class="m">0</span><span class="p">,</span> <span class="kt">void</span> <span class="p">()*</span> <span class="vg">@foo</span><span class="p">,</span> <span class="k">i32</span> <span class="m">0</span><span class="p">,</span> <span class="k">i32</span> <span class="m">0</span><span class="p">,</span> <span class="k">i32</span> <span class="m">0<
/span><span class="p">,</span> <span class="k">i32</span> <span class="m">0</span><span class="p">)</span>
+ <span class="k">ret</span> <span class="kt">void</span>
+<span class="p">}</span>
+</pre></div>
+</div>
+<p>In this case, we’ve added an (unconditional) entry safepoint poll and converted the call into a <tt class="docutils literal"><span class="pre">gc.statepoint</span></tt>. Note that despite appearances, the entry poll is not necessarily redundant. We’d have to know that <tt class="docutils literal"><span class="pre">foo</span></tt> and <tt class="docutils literal"><span class="pre">test</span></tt> were not mutually recursive for the poll to be redundant. In practice, you’d probably want to your poll definition to contain a conditional branch of some form.</p>
+<p>At the moment, PlaceSafepoints can insert safepoint polls at method entry and
+loop backedges locations. Extending this to work with return polls would be
+straight forward if desired.</p>
+<p>PlaceSafepoints includes a number of optimizations to avoid placing safepoint
+polls at particular sites unless needed to ensure timely execution of a poll
+under normal conditions. PlaceSafepoints does not attempt to ensure timely
+execution of a poll under worst case conditions such as heavy system paging.</p>
+<p>The implementation of a safepoint poll action is specified by looking up a
+function of the name <tt class="docutils literal"><span class="pre">gc.safepoint_poll</span></tt> in the containing Module. The body
+of this function is inserted at each poll site desired. While calls or invokes
+inside this method are transformed to a <tt class="docutils literal"><span class="pre">gc.statepoints</span></tt>, recursive poll
+insertion is not performed.</p>
+<p>By default PlaceSafepoints passes in <tt class="docutils literal"><span class="pre">0xABCDEF00</span></tt> as the statepoint
+ID and <tt class="docutils literal"><span class="pre">0</span></tt> as the number of patchable bytes to the newly constructed
+<tt class="docutils literal"><span class="pre">gc.statepoint</span></tt>. These values can be configured on a per-callsite
+basis using the attributes <tt class="docutils literal"><span class="pre">"statepoint-id"</span></tt> and
+<tt class="docutils literal"><span class="pre">"statepoint-num-patch-bytes"</span></tt>. If a call site is marked with a
+<tt class="docutils literal"><span class="pre">"statepoint-id"</span></tt> function attribute and its value is a positive
+integer (represented as a string), then that value is used as the ID
+of the newly constructed <tt class="docutils literal"><span class="pre">gc.statepoint</span></tt>. If a call site is marked
+with a <tt class="docutils literal"><span class="pre">"statepoint-num-patch-bytes"</span></tt> function attribute and its
+value is a positive integer, then that value is used as the ‘num patch
+bytes’ parameter of the newly constructed <tt class="docutils literal"><span class="pre">gc.statepoint</span></tt>. The
+<tt class="docutils literal"><span class="pre">"statepoint-id"</span></tt> and <tt class="docutils literal"><span class="pre">"statepoint-num-patch-bytes"</span></tt> attributes
+are not propagated to the <tt class="docutils literal"><span class="pre">gc.statepoint</span></tt> call or invoke if they
+could be successfully parsed.</p>
+<p>If you are scheduling the RewriteStatepointsForGC pass late in the pass order,
+you should probably schedule this pass immediately before it. The exception
+would be if you need to preserve abstract frame information (e.g. for
+deoptimization or introspection) at safepoints. In that case, ask on the
+llvm-dev mailing list for suggestions.</p>
+</div>
+</div>
+<div class="section" id="bugs-and-enhancements">
+<h2><a class="toc-backref" href="#id24">Bugs and Enhancements</a><a class="headerlink" href="#bugs-and-enhancements" title="Permalink to this headline">¶</a></h2>
+<p>Currently known bugs and enhancements under consideration can be
+tracked by performing a <a class="reference external" href="http://llvm.org/bugs/buglist.cgi?cmdtype=runnamed&namedcmd=Statepoint%20Bugs&list_id=64342">bugzilla search</a>
+for [Statepoint] in the summary field. When filing new bugs, please
+use this tag so that interested parties see the newly filed bug. As
+with most LLVM features, design discussions take place on <a class="reference external" href="http://lists.llvm.org/mailman/listinfo/llvm-dev">llvm-dev</a>, and patches
+should be sent to <a class="reference external" href="http://lists.llvm.org/mailman/listinfo/llvm-commits">llvm-commits</a> for review.</p>
+</div>
+</div>
+
+
+ </div>
+ </div>
+ <div class="clearer"></div>
+ </div>
+ <div class="related">
+ <h3>Navigation</h3>
+ <ul>
+ <li class="right" style="margin-right: 10px">
+ <a href="genindex.html" title="General Index"
+ >index</a></li>
+ <li class="right" >
+ <a href="MergeFunctions.html" title="MergeFunctions pass, how it works"
+ >next</a> |</li>
+ <li class="right" >
+ <a href="CoverageMappingFormat.html" title="LLVM Code Coverage Mapping Format"
+ >previous</a> |</li>
+ <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+ <li><a href="index.html">Documentation</a>»</li>
+
+ </ul>
+ </div>
+ <div class="footer">
+ © Copyright 2003-2016, LLVM Project.
+ Last updated on 2016-01-04.
+ Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.3.
+ </div>
+ </body>
+</html>
\ No newline at end of file
More information about the llvm-commits
mailing list