[www-releases] r331981 - Add 5.0.2 docs and update download.html

Tom Stellard via llvm-commits llvm-commits at lists.llvm.org
Thu May 10 06:54:19 PDT 2018


Added: www-releases/trunk/5.0.2/docs/Lexicon.html
URL: http://llvm.org/viewvc/llvm-project/www-releases/trunk/5.0.2/docs/Lexicon.html?rev=331981&view=auto
==============================================================================
--- www-releases/trunk/5.0.2/docs/Lexicon.html (added)
+++ www-releases/trunk/5.0.2/docs/Lexicon.html Thu May 10 06:54:16 2018
@@ -0,0 +1,350 @@
+
+
+<!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>The LLVM Lexicon — LLVM 5 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:     '5',
+        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 5 documentation" href="index.html" />
+    <link rel="next" title="How To Add Your Build Configuration To LLVM Buildbot Infrastructure" href="HowToAddABuilder.html" />
+    <link rel="prev" title="Frequently Asked Questions (FAQ)" href="FAQ.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="HowToAddABuilder.html" title="How To Add Your Build Configuration To LLVM Buildbot Infrastructure"
+             accesskey="N">next</a> |</li>
+        <li class="right" >
+          <a href="FAQ.html" title="Frequently Asked Questions (FAQ)"
+             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="the-llvm-lexicon">
+<h1>The LLVM Lexicon<a class="headerlink" href="#the-llvm-lexicon" title="Permalink to this headline">¶</a></h1>
+<div class="admonition note">
+<p class="first admonition-title">Note</p>
+<p class="last">This document is a work in progress!</p>
+</div>
+<div class="section" id="definitions">
+<h2>Definitions<a class="headerlink" href="#definitions" title="Permalink to this headline">¶</a></h2>
+<div class="section" id="a">
+<h3>A<a class="headerlink" href="#a" title="Permalink to this headline">¶</a></h3>
+<dl class="docutils">
+<dt><strong>ADCE</strong></dt>
+<dd>Aggressive Dead Code Elimination</dd>
+<dt><strong>AST</strong></dt>
+<dd><p class="first">Abstract Syntax Tree.</p>
+<p>Due to Clang’s influence (mostly the fact that parsing and semantic
+analysis are so intertwined for C and especially C++), the typical
+working definition of AST in the LLVM community is roughly “the
+compiler’s first complete symbolic (as opposed to textual)
+representation of an input program”.
+As such, an “AST” might be a more general graph instead of a “tree”
+(consider the symbolic representation for the type of a typical “linked
+list node”). This working definition is closer to what some authors
+call an “annotated abstract syntax tree”.</p>
+<p class="last">Consult your favorite compiler book or search engine for more details.</p>
+</dd>
+</dl>
+</div>
+<div class="section" id="b">
+<h3>B<a class="headerlink" href="#b" title="Permalink to this headline">¶</a></h3>
+<dl class="docutils" id="lexicon-bb-vectorization">
+<dt><strong>BB Vectorization</strong></dt>
+<dd>Basic-Block Vectorization</dd>
+<dt><strong>BDCE</strong></dt>
+<dd>Bit-tracking dead code elimination. Some bit-wise instructions (shifts,
+ands, ors, etc.) “kill” some of their input bits – that is, they make it
+such that those bits can be either zero or one without affecting control or
+data flow of a program. The BDCE pass removes instructions that only
+compute these dead bits.</dd>
+<dt><strong>BURS</strong></dt>
+<dd>Bottom Up Rewriting System — A method of instruction selection for code
+generation.  An example is the <a class="reference external" href="http://www.program-transformation.org/Transform/BURG">BURG</a> tool.</dd>
+</dl>
+</div>
+<div class="section" id="c">
+<h3>C<a class="headerlink" href="#c" title="Permalink to this headline">¶</a></h3>
+<dl class="docutils">
+<dt><strong>CFI</strong></dt>
+<dd>Call Frame Information. Used in DWARF debug info and in C++ unwind info
+to show how the function prolog lays out the stack frame.</dd>
+<dt><strong>CIE</strong></dt>
+<dd>Common Information Entry.  A kind of CFI used to reduce the size of FDEs.
+The compiler creates a CIE which contains the information common across all
+the FDEs.  Each FDE then points to its CIE.</dd>
+<dt><strong>CSE</strong></dt>
+<dd>Common Subexpression Elimination. An optimization that removes common
+subexpression compuation. For example <tt class="docutils literal"><span class="pre">(a+b)*(a+b)</span></tt> has two subexpressions
+that are the same: <tt class="docutils literal"><span class="pre">(a+b)</span></tt>. This optimization would perform the addition
+only once and then perform the multiply (but only if it’s computationally
+correct/safe).</dd>
+</dl>
+</div>
+<div class="section" id="d">
+<h3>D<a class="headerlink" href="#d" title="Permalink to this headline">¶</a></h3>
+<dl class="docutils">
+<dt><strong>DAG</strong></dt>
+<dd>Directed Acyclic Graph</dd>
+</dl>
+<dl class="docutils" id="derived-pointers">
+<span id="derived-pointer"></span><dt><strong>Derived Pointer</strong></dt>
+<dd>A pointer to the interior of an object, such that a garbage collector is
+unable to use the pointer for reachability analysis. While a derived pointer
+is live, the corresponding object pointer must be kept in a root, otherwise
+the collector might free the referenced object. With copying collectors,
+derived pointers pose an additional hazard that they may be invalidated at
+any <a class="reference internal" href="#safe-point">safe point</a>. This term is used in opposition to <a class="reference internal" href="#object-pointer">object pointer</a>.</dd>
+<dt><strong>DSA</strong></dt>
+<dd>Data Structure Analysis</dd>
+<dt><strong>DSE</strong></dt>
+<dd>Dead Store Elimination</dd>
+</dl>
+</div>
+<div class="section" id="f">
+<h3>F<a class="headerlink" href="#f" title="Permalink to this headline">¶</a></h3>
+<dl class="docutils">
+<dt><strong>FCA</strong></dt>
+<dd>First Class Aggregate</dd>
+<dt><strong>FDE</strong></dt>
+<dd>Frame Description Entry. A kind of CFI used to describe the stack frame of
+one function.</dd>
+</dl>
+</div>
+<div class="section" id="g">
+<h3>G<a class="headerlink" href="#g" title="Permalink to this headline">¶</a></h3>
+<dl class="docutils">
+<dt><strong>GC</strong></dt>
+<dd>Garbage Collection. The practice of using reachability analysis instead of
+explicit memory management to reclaim unused memory.</dd>
+<dt><strong>GVN</strong></dt>
+<dd>Global Value Numbering. GVN is a pass that partitions values computed by a
+function into congruence classes. Values ending up in the same congruence
+class are guaranteed to be the same for every execution of the program.
+In that respect, congruency is a compile-time approximation of equivalence
+of values at runtime.</dd>
+</dl>
+</div>
+<div class="section" id="h">
+<h3>H<a class="headerlink" href="#h" title="Permalink to this headline">¶</a></h3>
+<dl class="docutils" id="heap">
+<dt><strong>Heap</strong></dt>
+<dd>In garbage collection, the region of memory which is managed using
+reachability analysis.</dd>
+</dl>
+</div>
+<div class="section" id="i">
+<h3>I<a class="headerlink" href="#i" title="Permalink to this headline">¶</a></h3>
+<dl class="docutils">
+<dt><strong>IPA</strong></dt>
+<dd>Inter-Procedural Analysis. Refers to any variety of code analysis that
+occurs between procedures, functions or compilation units (modules).</dd>
+<dt><strong>IPO</strong></dt>
+<dd>Inter-Procedural Optimization. Refers to any variety of code optimization
+that occurs between procedures, functions or compilation units (modules).</dd>
+<dt><strong>ISel</strong></dt>
+<dd>Instruction Selection</dd>
+</dl>
+</div>
+<div class="section" id="l">
+<h3>L<a class="headerlink" href="#l" title="Permalink to this headline">¶</a></h3>
+<dl class="docutils">
+<dt><strong>LCSSA</strong></dt>
+<dd>Loop-Closed Static Single Assignment Form</dd>
+<dt><strong>LGTM</strong></dt>
+<dd>“Looks Good To Me”. In a review thread, this indicates that the
+reviewer thinks that the patch is okay to commit.</dd>
+<dt><strong>LICM</strong></dt>
+<dd>Loop Invariant Code Motion</dd>
+<dt><strong>LSDA</strong></dt>
+<dd>Language Specific Data Area.  C++ “zero cost” unwinding is built on top a
+generic unwinding mechanism.  As the unwinder walks each frame, it calls
+a “personality” function to do language specific analysis.  Each function’s
+FDE points to an optional LSDA which is passed to the personality function.
+For C++, the LSDA contain info about the type and location of catch
+statements in that function.</dd>
+<dt><strong>Load-VN</strong></dt>
+<dd>Load Value Numbering</dd>
+<dt><strong>LTO</strong></dt>
+<dd>Link-Time Optimization</dd>
+</dl>
+</div>
+<div class="section" id="m">
+<h3>M<a class="headerlink" href="#m" title="Permalink to this headline">¶</a></h3>
+<dl class="docutils">
+<dt><strong>MC</strong></dt>
+<dd>Machine Code</dd>
+</dl>
+</div>
+<div class="section" id="n">
+<h3>N<a class="headerlink" href="#n" title="Permalink to this headline">¶</a></h3>
+<dl class="docutils">
+<dt><strong>NFC</strong></dt>
+<dd>“No functional change”. Used in a commit message to indicate that a patch
+is a pure refactoring/cleanup.
+Usually used in the first line, so it is visible without opening the
+actual commit email.</dd>
+</dl>
+</div>
+<div class="section" id="o">
+<h3>O<a class="headerlink" href="#o" title="Permalink to this headline">¶</a></h3>
+<dl class="docutils" id="object-pointers">
+<span id="object-pointer"></span><dt><strong>Object Pointer</strong></dt>
+<dd>A pointer to an object such that the garbage collector is able to trace
+references contained within the object. This term is used in opposition to
+<a class="reference internal" href="#derived-pointer">derived pointer</a>.</dd>
+</dl>
+</div>
+<div class="section" id="p">
+<h3>P<a class="headerlink" href="#p" title="Permalink to this headline">¶</a></h3>
+<dl class="docutils">
+<dt><strong>PR</strong></dt>
+<dd>Problem report. A bug filed on <a class="reference external" href="https://bugs.llvm.org/enter_bug.cgi">the LLVM Bug Tracking System</a>.</dd>
+<dt><strong>PRE</strong></dt>
+<dd>Partial Redundancy Elimination</dd>
+</dl>
+</div>
+<div class="section" id="r">
+<h3>R<a class="headerlink" href="#r" title="Permalink to this headline">¶</a></h3>
+<p><strong>RAUW</strong></p>
+<blockquote>
+<div>Replace All Uses With. The functions <tt class="docutils literal"><span class="pre">User::replaceUsesOfWith()</span></tt>,
+<tt class="docutils literal"><span class="pre">Value::replaceAllUsesWith()</span></tt>, and
+<tt class="docutils literal"><span class="pre">Constant::replaceUsesOfWithOnConstant()</span></tt> implement the replacement of one
+Value with another by iterating over its def/use chain and fixing up all of
+the pointers to point to the new value.  See
+also <a class="reference external" href="ProgrammersManual.html#iterating-over-def-use-use-def-chains">def/use chains</a>.</div></blockquote>
+<dl class="docutils">
+<dt><strong>Reassociation</strong></dt>
+<dd>Rearranging associative expressions to promote better redundancy elimination
+and other optimization.  For example, changing <tt class="docutils literal"><span class="pre">(A+B-A)</span></tt> into <tt class="docutils literal"><span class="pre">(B+A-A)</span></tt>,
+permitting it to be optimized into <tt class="docutils literal"><span class="pre">(B+0)</span></tt> then <tt class="docutils literal"><span class="pre">(B)</span></tt>.</dd>
+</dl>
+<dl class="docutils" id="stack-roots">
+<span id="roots"></span><dt><strong>Root</strong></dt>
+<dd>In garbage collection, a pointer variable lying outside of the <a class="reference internal" href="#heap">heap</a> from
+which the collector begins its reachability analysis. In the context of code
+generation, “root” almost always refers to a “stack root” — a local or
+temporary variable within an executing function.</dd>
+<dt><strong>RPO</strong></dt>
+<dd>Reverse postorder</dd>
+</dl>
+</div>
+<div class="section" id="s">
+<h3>S<a class="headerlink" href="#s" title="Permalink to this headline">¶</a></h3>
+<dl class="docutils" id="safe-point">
+<dt><strong>Safe Point</strong></dt>
+<dd>In garbage collection, it is necessary to identify <a class="reference internal" href="#stack-roots">stack roots</a> so that
+reachability analysis may proceed. It may be infeasible to provide this
+information for every instruction, so instead the information may is
+calculated only at designated safe points. With a copying collector,
+<a class="reference internal" href="#derived-pointers">derived pointers</a> must not be retained across safe points and <a class="reference internal" href="#object-pointers">object
+pointers</a> must be reloaded from stack roots.</dd>
+<dt><strong>SDISel</strong></dt>
+<dd>Selection DAG Instruction Selection.</dd>
+<dt><strong>SCC</strong></dt>
+<dd>Strongly Connected Component</dd>
+<dt><strong>SCCP</strong></dt>
+<dd>Sparse Conditional Constant Propagation</dd>
+<dt><strong>SLP</strong></dt>
+<dd>Superword-Level Parallelism, same as <a class="reference internal" href="#lexicon-bb-vectorization"><em>Basic-Block Vectorization</em></a>.</dd>
+<dt><strong>Splat</strong></dt>
+<dd><p class="first">Splat refers to a vector of identical scalar elements.</p>
+<p class="last">The term is based on the PowerPC Altivec instructions that provided
+this functionality in hardware. For example, “vsplth” and the corresponding
+software intrinsic “vec_splat()”. Examples of other hardware names for this
+action include “duplicate” (ARM) and “broadcast” (x86).</p>
+</dd>
+<dt><strong>SRoA</strong></dt>
+<dd>Scalar Replacement of Aggregates</dd>
+<dt><strong>SSA</strong></dt>
+<dd>Static Single Assignment</dd>
+<dt><strong>Stack Map</strong></dt>
+<dd>In garbage collection, metadata emitted by the code generator which
+identifies <a class="reference internal" href="#roots">roots</a> within the stack frame of an executing function.</dd>
+</dl>
+</div>
+<div class="section" id="t">
+<h3>T<a class="headerlink" href="#t" title="Permalink to this headline">¶</a></h3>
+<dl class="docutils">
+<dt><strong>TBAA</strong></dt>
+<dd>Type-Based Alias Analysis</dd>
+</dl>
+</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="HowToAddABuilder.html" title="How To Add Your Build Configuration To LLVM Buildbot Infrastructure"
+             >next</a> |</li>
+        <li class="right" >
+          <a href="FAQ.html" title="Frequently Asked Questions (FAQ)"
+             >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-2018, LLVM Project.
+      Last updated on 2018-05-10.
+      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/5.0.2/docs/LibFuzzer.html
URL: http://llvm.org/viewvc/llvm-project/www-releases/trunk/5.0.2/docs/LibFuzzer.html?rev=331981&view=auto
==============================================================================
--- www-releases/trunk/5.0.2/docs/LibFuzzer.html (added)
+++ www-releases/trunk/5.0.2/docs/LibFuzzer.html Thu May 10 06:54:16 2018
@@ -0,0 +1,818 @@
+
+
+<!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>libFuzzer – a library for coverage-guided fuzz testing. — LLVM 5 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:     '5',
+        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 5 documentation" href="index.html" />
+    <link rel="next" title="Scudo Hardened Allocator" href="ScudoHardenedAllocator.html" />
+    <link rel="prev" title="LLVM Extensions" href="Extensions.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="ScudoHardenedAllocator.html" title="Scudo Hardened Allocator"
+             accesskey="N">next</a> |</li>
+        <li class="right" >
+          <a href="Extensions.html" title="LLVM Extensions"
+             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="libfuzzer-a-library-for-coverage-guided-fuzz-testing">
+<h1>libFuzzer – a library for coverage-guided fuzz testing.<a class="headerlink" href="#libfuzzer-a-library-for-coverage-guided-fuzz-testing" 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="id13">Introduction</a></li>
+<li><a class="reference internal" href="#versions" id="id14">Versions</a></li>
+<li><a class="reference internal" href="#getting-started" id="id15">Getting Started</a></li>
+<li><a class="reference internal" href="#options" id="id16">Options</a></li>
+<li><a class="reference internal" href="#output" id="id17">Output</a></li>
+<li><a class="reference internal" href="#examples" id="id18">Examples</a></li>
+<li><a class="reference internal" href="#advanced-features" id="id19">Advanced features</a></li>
+<li><a class="reference internal" href="#developing-libfuzzer" id="id20">Developing libFuzzer</a></li>
+<li><a class="reference internal" href="#fuzzing-components-of-llvm" id="id21">Fuzzing components of LLVM</a></li>
+<li><a class="reference internal" href="#faq" id="id22">FAQ</a></li>
+<li><a class="reference internal" href="#trophies" id="id23">Trophies</a></li>
+</ul>
+</div>
+<div class="section" id="introduction">
+<h2><a class="toc-backref" href="#id13">Introduction</a><a class="headerlink" href="#introduction" title="Permalink to this headline">¶</a></h2>
+<p>LibFuzzer is in-process, coverage-guided, evolutionary fuzzing engine.</p>
+<p>LibFuzzer is linked with the library under test, and feeds fuzzed inputs to the
+library via a specific fuzzing entrypoint (aka “target function”); the fuzzer
+then tracks which areas of the code are reached, and generates mutations on the
+corpus of input data in order to maximize the code coverage.
+The code coverage
+information for libFuzzer is provided by LLVM’s <a class="reference external" href="http://clang.llvm.org/docs/SanitizerCoverage.html">SanitizerCoverage</a>
+instrumentation.</p>
+<p>Contact: libfuzzer(#)googlegroups.com</p>
+</div>
+<div class="section" id="versions">
+<h2><a class="toc-backref" href="#id14">Versions</a><a class="headerlink" href="#versions" title="Permalink to this headline">¶</a></h2>
+<p>LibFuzzer is under active development so you will need the current
+(or at least a very recent) version of the Clang compiler.</p>
+<p>(If <a class="reference external" href="http://clang.llvm.org/get_started.html">building Clang from trunk</a> is too time-consuming or difficult, then
+the Clang binaries that the Chromium developers build are likely to be
+fairly recent:</p>
+<div class="highlight-console"><div class="highlight"><pre><span class="go">mkdir TMP_CLANG</span>
+<span class="go">cd TMP_CLANG</span>
+<span class="go">git clone https://chromium.googlesource.com/chromium/src/tools/clang</span>
+<span class="go">cd ..</span>
+<span class="go">TMP_CLANG/clang/scripts/update.py</span>
+</pre></div>
+</div>
+<p>This installs the Clang binary as
+<tt class="docutils literal"><span class="pre">./third_party/llvm-build/Release+Asserts/bin/clang</span></tt>)</p>
+<p>The libFuzzer code resides in the LLVM repository, and requires a recent Clang
+compiler to build (and is used to <a class="reference internal" href="#fuzzing-components-of-llvm">fuzz various parts of LLVM itself</a>).
+However the fuzzer itself does not (and should not) depend on any part of LLVM
+infrastructure and can be used for other projects without requiring the rest
+of LLVM.</p>
+</div>
+<div class="section" id="getting-started">
+<h2><a class="toc-backref" href="#id15">Getting Started</a><a class="headerlink" href="#getting-started" title="Permalink to this headline">¶</a></h2>
+<div class="contents local topic" id="id1">
+<ul class="simple">
+<li><a class="reference internal" href="#fuzz-target" id="id24">Fuzz Target</a></li>
+<li><a class="reference internal" href="#fuzzer-usage" id="id25">Fuzzer Usage</a></li>
+<li><a class="reference internal" href="#corpus" id="id26">Corpus</a></li>
+<li><a class="reference internal" href="#running" id="id27">Running</a></li>
+<li><a class="reference internal" href="#parallel-fuzzing" id="id28">Parallel Fuzzing</a></li>
+</ul>
+</div>
+<div class="section" id="fuzz-target">
+<h3><a class="toc-backref" href="#id24">Fuzz Target</a><a class="headerlink" href="#fuzz-target" title="Permalink to this headline">¶</a></h3>
+<p>The first step in using libFuzzer on a library is to implement a
+<em>fuzz target</em> – a function that accepts an array of bytes and
+does something interesting with these bytes using the API under test.
+Like this:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="c1">// fuzz_target.cc</span>
+<span class="k">extern</span> <span class="s">"C"</span> <span class="kt">int</span> <span class="n">LLVMFuzzerTestOneInput</span><span class="p">(</span><span class="k">const</span> <span class="n">uint8_t</span> <span class="o">*</span><span class="n">Data</span><span class="p">,</span> <span class="n">size_t</span> <span class="n">Size</span><span class="p">)</span> <span class="p">{</span>
+  <span class="n">DoSomethingInterestingWithMyAPI</span><span class="p">(</span><span class="n">Data</span><span class="p">,</span> <span class="n">Size</span><span class="p">);</span>
+  <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>  <span class="c1">// Non-zero return values are reserved for future use.</span>
+<span class="p">}</span>
+</pre></div>
+</div>
+<p>Note that this fuzz target does not depend on libFuzzer in any way
+and so it is possible and even desirable to use it with other fuzzing engines
+e.g. <a class="reference external" href="http://lcamtuf.coredump.cx/afl/">AFL</a> and/or <a class="reference external" href="https://github.com/aoh/radamsa">Radamsa</a>.</p>
+<p>Some important things to remember about fuzz targets:</p>
+<ul class="simple">
+<li>The fuzzing engine will execute the fuzz target many times with different inputs in the same process.</li>
+<li>It must tolerate any kind of input (empty, huge, malformed, etc).</li>
+<li>It must not <cite>exit()</cite> on any input.</li>
+<li>It may use threads but ideally all threads should be joined at the end of the function.</li>
+<li>It must be as deterministic as possible. Non-determinism (e.g. random decisions not based on the input bytes) will make fuzzing inefficient.</li>
+<li>It must be fast. Try avoiding cubic or greater complexity, logging, or excessive memory consumption.</li>
+<li>Ideally, it should not modify any global state (although that’s not strict).</li>
+<li>Usually, the narrower the target the better. E.g. if your target can parse several data formats, split it into several targets, one per format.</li>
+</ul>
+</div>
+<div class="section" id="fuzzer-usage">
+<h3><a class="toc-backref" href="#id25">Fuzzer Usage</a><a class="headerlink" href="#fuzzer-usage" title="Permalink to this headline">¶</a></h3>
+<p>Very recent versions of Clang (> April 20 2017) include libFuzzer,
+and no installation is necessary.
+In order to fuzz your binary, use the <cite>-fsanitize=fuzzer</cite> flag during the compilation:</p>
+<div class="highlight-python"><pre>clang -fsanitize=fuzzer,address mytarget.c</pre>
+</div>
+<p>Otherwise, build the libFuzzer library as a static archive, without any sanitizer
+options. Note that the libFuzzer library contains the <tt class="docutils literal"><span class="pre">main()</span></tt> function:</p>
+<div class="highlight-console"><div class="highlight"><pre><span class="go">svn co http://llvm.org/svn/llvm-project/llvm/trunk/lib/Fuzzer  # or git clone https://chromium.googlesource.com/chromium/llvm-project/llvm/lib/Fuzzer</span>
+<span class="go">./Fuzzer/build.sh  # Produces libFuzzer.a</span>
+</pre></div>
+</div>
+<p>Then build the fuzzing target function and the library under test using
+the <a class="reference external" href="http://clang.llvm.org/docs/SanitizerCoverage.html">SanitizerCoverage</a> option, which instruments the code so that the fuzzer
+can retrieve code coverage information (to guide the fuzzing).  Linking with
+the libFuzzer code then gives a fuzzer executable.</p>
+<p>You should also enable one or more of the <em>sanitizers</em>, which help to expose
+latent bugs by making incorrect behavior generate errors at runtime:</p>
+<blockquote>
+<div><ul class="simple">
+<li><a class="reference external" href="http://clang.llvm.org/docs/AddressSanitizer.html">AddressSanitizer</a> (ASAN) detects memory access errors. Use <cite>-fsanitize=address</cite>.</li>
+<li><a class="reference external" href="http://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html">UndefinedBehaviorSanitizer</a> (UBSAN) detects the use of various features of C/C++ that are explicitly
+listed as resulting in undefined behavior.  Use <cite>-fsanitize=undefined -fno-sanitize-recover=undefined</cite>
+or any individual UBSAN check, e.g.  <cite>-fsanitize=signed-integer-overflow -fno-sanitize-recover=undefined</cite>.
+You may combine ASAN and UBSAN in one build.</li>
+<li><a class="reference external" href="http://clang.llvm.org/docs/MemorySanitizer.html">MemorySanitizer</a> (MSAN) detects uninitialized reads: code whose behavior relies on memory
+contents that have not been initialized to a specific value. Use <cite>-fsanitize=memory</cite>.
+MSAN can not be combined with other sanirizers and should be used as a seprate build.</li>
+</ul>
+</div></blockquote>
+<p>Finally, link with <tt class="docutils literal"><span class="pre">libFuzzer.a</span></tt>:</p>
+<div class="highlight-python"><pre>clang -fsanitize-coverage=trace-pc-guard -fsanitize=address your_lib.cc fuzz_target.cc libFuzzer.a -o my_fuzzer</pre>
+</div>
+</div>
+<div class="section" id="corpus">
+<h3><a class="toc-backref" href="#id26">Corpus</a><a class="headerlink" href="#corpus" title="Permalink to this headline">¶</a></h3>
+<p>Coverage-guided fuzzers like libFuzzer rely on a corpus of sample inputs for the
+code under test.  This corpus should ideally be seeded with a varied collection
+of valid and invalid inputs for the code under test; for example, for a graphics
+library the initial corpus might hold a variety of different small PNG/JPG/GIF
+files.  The fuzzer generates random mutations based around the sample inputs in
+the current corpus.  If a mutation triggers execution of a previously-uncovered
+path in the code under test, then that mutation is saved to the corpus for
+future variations.</p>
+<p>LibFuzzer will work without any initial seeds, but will be less
+efficient if the library under test accepts complex,
+structured inputs.</p>
+<p>The corpus can also act as a sanity/regression check, to confirm that the
+fuzzing entrypoint still works and that all of the sample inputs run through
+the code under test without problems.</p>
+<p>If you have a large corpus (either generated by fuzzing or acquired by other means)
+you may want to minimize it while still preserving the full coverage. One way to do that
+is to use the <cite>-merge=1</cite> flag:</p>
+<div class="highlight-console"><div class="highlight"><pre><span class="go">mkdir NEW_CORPUS_DIR  # Store minimized corpus here.</span>
+<span class="go">./my_fuzzer -merge=1 NEW_CORPUS_DIR FULL_CORPUS_DIR</span>
+</pre></div>
+</div>
+<p>You may use the same flag to add more interesting items to an existing corpus.
+Only the inputs that trigger new coverage will be added to the first corpus.</p>
+<div class="highlight-console"><div class="highlight"><pre><span class="go">./my_fuzzer -merge=1 CURRENT_CORPUS_DIR NEW_POTENTIALLY_INTERESTING_INPUTS_DIR</span>
+</pre></div>
+</div>
+</div>
+<div class="section" id="running">
+<h3><a class="toc-backref" href="#id27">Running</a><a class="headerlink" href="#running" title="Permalink to this headline">¶</a></h3>
+<p>To run the fuzzer, first create a <a class="reference internal" href="#corpus">Corpus</a> directory that holds the
+initial “seed” sample inputs:</p>
+<div class="highlight-console"><div class="highlight"><pre><span class="go">mkdir CORPUS_DIR</span>
+<span class="go">cp /some/input/samples/* CORPUS_DIR</span>
+</pre></div>
+</div>
+<p>Then run the fuzzer on the corpus directory:</p>
+<div class="highlight-console"><div class="highlight"><pre><span class="go">./my_fuzzer CORPUS_DIR  # -max_len=1000 -jobs=20 ...</span>
+</pre></div>
+</div>
+<p>As the fuzzer discovers new interesting test cases (i.e. test cases that
+trigger coverage of new paths through the code under test), those test cases
+will be added to the corpus directory.</p>
+<p>By default, the fuzzing process will continue indefinitely – at least until
+a bug is found.  Any crashes or sanitizer failures will be reported as usual,
+stopping the fuzzing process, and the particular input that triggered the bug
+will be written to disk (typically as <tt class="docutils literal"><span class="pre">crash-<sha1></span></tt>, <tt class="docutils literal"><span class="pre">leak-<sha1></span></tt>,
+or <tt class="docutils literal"><span class="pre">timeout-<sha1></span></tt>).</p>
+</div>
+<div class="section" id="parallel-fuzzing">
+<h3><a class="toc-backref" href="#id28">Parallel Fuzzing</a><a class="headerlink" href="#parallel-fuzzing" title="Permalink to this headline">¶</a></h3>
+<p>Each libFuzzer process is single-threaded, unless the library under test starts
+its own threads.  However, it is possible to run multiple libFuzzer processes in
+parallel with a shared corpus directory; this has the advantage that any new
+inputs found by one fuzzer process will be available to the other fuzzer
+processes (unless you disable this with the <tt class="docutils literal"><span class="pre">-reload=0</span></tt> option).</p>
+<p>This is primarily controlled by the <tt class="docutils literal"><span class="pre">-jobs=N</span></tt> option, which indicates that
+that <cite>N</cite> fuzzing jobs should be run to completion (i.e. until a bug is found or
+time/iteration limits are reached).  These jobs will be run across a set of
+worker processes, by default using half of the available CPU cores; the count of
+worker processes can be overridden by the <tt class="docutils literal"><span class="pre">-workers=N</span></tt> option.  For example,
+running with <tt class="docutils literal"><span class="pre">-jobs=30</span></tt> on a 12-core machine would run 6 workers by default,
+with each worker averaging 5 bugs by completion of the entire process.</p>
+</div>
+</div>
+<div class="section" id="options">
+<h2><a class="toc-backref" href="#id16">Options</a><a class="headerlink" href="#options" title="Permalink to this headline">¶</a></h2>
+<p>To run the fuzzer, pass zero or more corpus directories as command line
+arguments.  The fuzzer will read test inputs from each of these corpus
+directories, and any new test inputs that are generated will be written
+back to the first corpus directory:</p>
+<div class="highlight-console"><div class="highlight"><pre><span class="go">./fuzzer [-flag1=val1 [-flag2=val2 ...] ] [dir1 [dir2 ...] ]</span>
+</pre></div>
+</div>
+<p>If a list of files (rather than directories) are passed to the fuzzer program,
+then it will re-run those files as test inputs but will not perform any fuzzing.
+In this mode the fuzzer binary can be used as a regression test (e.g. on a
+continuous integration system) to check the target function and saved inputs
+still work.</p>
+<p>The most important command line options are:</p>
+<dl class="docutils">
+<dt><tt class="docutils literal"><span class="pre">-help</span></tt></dt>
+<dd>Print help message.</dd>
+<dt><tt class="docutils literal"><span class="pre">-seed</span></tt></dt>
+<dd>Random seed. If 0 (the default), the seed is generated.</dd>
+<dt><tt class="docutils literal"><span class="pre">-runs</span></tt></dt>
+<dd>Number of individual test runs, -1 (the default) to run indefinitely.</dd>
+<dt><tt class="docutils literal"><span class="pre">-max_len</span></tt></dt>
+<dd>Maximum length of a test input. If 0 (the default), libFuzzer tries to guess
+a good value based on the corpus (and reports it).</dd>
+<dt><tt class="docutils literal"><span class="pre">-timeout</span></tt></dt>
+<dd>Timeout in seconds, default 1200. If an input takes longer than this timeout,
+the process is treated as a failure case.</dd>
+<dt><tt class="docutils literal"><span class="pre">-rss_limit_mb</span></tt></dt>
+<dd>Memory usage limit in Mb, default 2048. Use 0 to disable the limit.
+If an input requires more than this amount of RSS memory to execute,
+the process is treated as a failure case.
+The limit is checked in a separate thread every second.
+If running w/o ASAN/MSAN, you may use ‘ulimit -v’ instead.</dd>
+<dt><tt class="docutils literal"><span class="pre">-timeout_exitcode</span></tt></dt>
+<dd>Exit code (default 77) used if libFuzzer reports a timeout.</dd>
+<dt><tt class="docutils literal"><span class="pre">-error_exitcode</span></tt></dt>
+<dd>Exit code (default 77) used if libFuzzer itself (not a sanitizer) reports a bug (leak, OOM, etc).</dd>
+<dt><tt class="docutils literal"><span class="pre">-max_total_time</span></tt></dt>
+<dd>If positive, indicates the maximum total time in seconds to run the fuzzer.
+If 0 (the default), run indefinitely.</dd>
+<dt><tt class="docutils literal"><span class="pre">-merge</span></tt></dt>
+<dd>If set to 1, any corpus inputs from the 2nd, 3rd etc. corpus directories
+that trigger new code coverage will be merged into the first corpus
+directory.  Defaults to 0. This flag can be used to minimize a corpus.</dd>
+<dt><tt class="docutils literal"><span class="pre">-minimize_crash</span></tt></dt>
+<dd>If 1, minimizes the provided crash input.
+Use with -runs=N or -max_total_time=N to limit the number of attempts.</dd>
+<dt><tt class="docutils literal"><span class="pre">-reload</span></tt></dt>
+<dd>If set to 1 (the default), the corpus directory is re-read periodically to
+check for new inputs; this allows detection of new inputs that were discovered
+by other fuzzing processes.</dd>
+<dt><tt class="docutils literal"><span class="pre">-jobs</span></tt></dt>
+<dd>Number of fuzzing jobs to run to completion. Default value is 0, which runs a
+single fuzzing process until completion.  If the value is >= 1, then this
+number of jobs performing fuzzing are run, in a collection of parallel
+separate worker processes; each such worker process has its
+<tt class="docutils literal"><span class="pre">stdout</span></tt>/<tt class="docutils literal"><span class="pre">stderr</span></tt> redirected to <tt class="docutils literal"><span class="pre">fuzz-<JOB>.log</span></tt>.</dd>
+<dt><tt class="docutils literal"><span class="pre">-workers</span></tt></dt>
+<dd>Number of simultaneous worker processes to run the fuzzing jobs to completion
+in. If 0 (the default), <tt class="docutils literal"><span class="pre">min(jobs,</span> <span class="pre">NumberOfCpuCores()/2)</span></tt> is used.</dd>
+<dt><tt class="docutils literal"><span class="pre">-dict</span></tt></dt>
+<dd>Provide a dictionary of input keywords; see <a class="reference internal" href="#dictionaries">Dictionaries</a>.</dd>
+<dt><tt class="docutils literal"><span class="pre">-use_counters</span></tt></dt>
+<dd>Use <a class="reference external" href="http://clang.llvm.org/docs/SanitizerCoverage.html#coverage-counters">coverage counters</a> to generate approximate counts of how often code
+blocks are hit; defaults to 1.</dd>
+<dt><tt class="docutils literal"><span class="pre">-use_value_profile</span></tt></dt>
+<dd>Use <a class="reference external" href="#value-profile">value profile</a> to guide corpus expansion; defaults to 0.</dd>
+<dt><tt class="docutils literal"><span class="pre">-only_ascii</span></tt></dt>
+<dd>If 1, generate only ASCII (<tt class="docutils literal"><span class="pre">isprint``+``isspace</span></tt>) inputs. Defaults to 0.</dd>
+<dt><tt class="docutils literal"><span class="pre">-artifact_prefix</span></tt></dt>
+<dd>Provide a prefix to use when saving fuzzing artifacts (crash, timeout, or
+slow inputs) as <tt class="docutils literal"><span class="pre">$(artifact_prefix)file</span></tt>.  Defaults to empty.</dd>
+<dt><tt class="docutils literal"><span class="pre">-exact_artifact_path</span></tt></dt>
+<dd>Ignored if empty (the default).  If non-empty, write the single artifact on
+failure (crash, timeout) as <tt class="docutils literal"><span class="pre">$(exact_artifact_path)</span></tt>. This overrides
+<tt class="docutils literal"><span class="pre">-artifact_prefix</span></tt> and will not use checksum in the file name. Do not use
+the same path for several parallel processes.</dd>
+<dt><tt class="docutils literal"><span class="pre">-print_pcs</span></tt></dt>
+<dd>If 1, print out newly covered PCs. Defaults to 0.</dd>
+<dt><tt class="docutils literal"><span class="pre">-print_final_stats</span></tt></dt>
+<dd>If 1, print statistics at exit.  Defaults to 0.</dd>
+<dt><tt class="docutils literal"><span class="pre">-detect_leaks</span></tt></dt>
+<dd>If 1 (default) and if LeakSanitizer is enabled
+try to detect memory leaks during fuzzing (i.e. not only at shut down).</dd>
+<dt><tt class="docutils literal"><span class="pre">-close_fd_mask</span></tt></dt>
+<dd><p class="first">Indicate output streams to close at startup. Be careful, this will
+remove diagnostic output from target code (e.g. messages on assert failure).</p>
+<blockquote class="last">
+<div><ul class="simple">
+<li>0 (default): close neither <tt class="docutils literal"><span class="pre">stdout</span></tt> nor <tt class="docutils literal"><span class="pre">stderr</span></tt></li>
+<li>1 : close <tt class="docutils literal"><span class="pre">stdout</span></tt></li>
+<li>2 : close <tt class="docutils literal"><span class="pre">stderr</span></tt></li>
+<li>3 : close both <tt class="docutils literal"><span class="pre">stdout</span></tt> and <tt class="docutils literal"><span class="pre">stderr</span></tt>.</li>
+</ul>
+</div></blockquote>
+</dd>
+<dt><tt class="docutils literal"><span class="pre">-print_coverage</span></tt></dt>
+<dd>If 1, print coverage information as text at exit.</dd>
+<dt><tt class="docutils literal"><span class="pre">-dump_coverage</span></tt></dt>
+<dd>If 1, dump coverage information as a .sancov file at exit.</dd>
+</dl>
+<p>For the full list of flags run the fuzzer binary with <tt class="docutils literal"><span class="pre">-help=1</span></tt>.</p>
+</div>
+<div class="section" id="output">
+<h2><a class="toc-backref" href="#id17">Output</a><a class="headerlink" href="#output" title="Permalink to this headline">¶</a></h2>
+<p>During operation the fuzzer prints information to <tt class="docutils literal"><span class="pre">stderr</span></tt>, for example:</p>
+<div class="highlight-python"><pre>INFO: Seed: 1523017872
+INFO: Loaded 1 modules (16 guards): [0x744e60, 0x744ea0),
+INFO: -max_len is not provided, using 64
+INFO: A corpus is not provided, starting from an empty corpus
+#0    READ units: 1
+#1    INITED cov: 3 ft: 2 corp: 1/1b exec/s: 0 rss: 24Mb
+#3811 NEW    cov: 4 ft: 3 corp: 2/2b exec/s: 0 rss: 25Mb L: 1 MS: 5 ChangeBit-ChangeByte-ChangeBit-ShuffleBytes-ChangeByte-
+#3827 NEW    cov: 5 ft: 4 corp: 3/4b exec/s: 0 rss: 25Mb L: 2 MS: 1 CopyPart-
+#3963 NEW    cov: 6 ft: 5 corp: 4/6b exec/s: 0 rss: 25Mb L: 2 MS: 2 ShuffleBytes-ChangeBit-
+#4167 NEW    cov: 7 ft: 6 corp: 5/9b exec/s: 0 rss: 25Mb L: 3 MS: 1 InsertByte-
+...</pre>
+</div>
+<p>The early parts of the output include information about the fuzzer options and
+configuration, including the current random seed (in the <tt class="docutils literal"><span class="pre">Seed:</span></tt> line; this
+can be overridden with the <tt class="docutils literal"><span class="pre">-seed=N</span></tt> flag).</p>
+<p>Further output lines have the form of an event code and statistics.  The
+possible event codes are:</p>
+<dl class="docutils">
+<dt><tt class="docutils literal"><span class="pre">READ</span></tt></dt>
+<dd>The fuzzer has read in all of the provided input samples from the corpus
+directories.</dd>
+<dt><tt class="docutils literal"><span class="pre">INITED</span></tt></dt>
+<dd>The fuzzer has completed initialization, which includes running each of
+the initial input samples through the code under test.</dd>
+<dt><tt class="docutils literal"><span class="pre">NEW</span></tt></dt>
+<dd>The fuzzer has created a test input that covers new areas of the code
+under test.  This input will be saved to the primary corpus directory.</dd>
+<dt><tt class="docutils literal"><span class="pre">pulse</span></tt></dt>
+<dd>The fuzzer has generated 2<sup>n</sup> inputs (generated periodically to reassure
+the user that the fuzzer is still working).</dd>
+<dt><tt class="docutils literal"><span class="pre">DONE</span></tt></dt>
+<dd>The fuzzer has completed operation because it has reached the specified
+iteration limit (<tt class="docutils literal"><span class="pre">-runs</span></tt>) or time limit (<tt class="docutils literal"><span class="pre">-max_total_time</span></tt>).</dd>
+<dt><tt class="docutils literal"><span class="pre">RELOAD</span></tt></dt>
+<dd>The fuzzer is performing a periodic reload of inputs from the corpus
+directory; this allows it to discover any inputs discovered by other
+fuzzer processes (see <a class="reference internal" href="#parallel-fuzzing">Parallel Fuzzing</a>).</dd>
+</dl>
+<p>Each output line also reports the following statistics (when non-zero):</p>
+<dl class="docutils">
+<dt><tt class="docutils literal"><span class="pre">cov:</span></tt></dt>
+<dd>Total number of code blocks or edges covered by the executing the current
+corpus.</dd>
+<dt><tt class="docutils literal"><span class="pre">ft:</span></tt></dt>
+<dd>libFuzzer uses different signals to evaluate the code coverage:
+edge coverage, edge counters, value profiles, indirect caller/callee pairs, etc.
+These signals combined are called <em>features</em> (<cite>ft:</cite>).</dd>
+<dt><tt class="docutils literal"><span class="pre">corp:</span></tt></dt>
+<dd>Number of entries in the current in-memory test corpus and its size in bytes.</dd>
+<dt><tt class="docutils literal"><span class="pre">exec/s:</span></tt></dt>
+<dd>Number of fuzzer iterations per second.</dd>
+<dt><tt class="docutils literal"><span class="pre">rss:</span></tt></dt>
+<dd>Current memory consumption.</dd>
+</dl>
+<p>For <tt class="docutils literal"><span class="pre">NEW</span></tt> events, the output line also includes information about the mutation
+operation that produced the new input:</p>
+<dl class="docutils">
+<dt><tt class="docutils literal"><span class="pre">L:</span></tt></dt>
+<dd>Size of the new input in bytes.</dd>
+<dt><tt class="docutils literal"><span class="pre">MS:</span> <span class="pre"><n></span> <span class="pre"><operations></span></tt></dt>
+<dd>Count and list of the mutation operations used to generate the input.</dd>
+</dl>
+</div>
+<div class="section" id="examples">
+<h2><a class="toc-backref" href="#id18">Examples</a><a class="headerlink" href="#examples" title="Permalink to this headline">¶</a></h2>
+<div class="contents local topic" id="id2">
+<ul class="simple">
+<li><a class="reference internal" href="#toy-example" id="id29">Toy example</a></li>
+<li><a class="reference internal" href="#more-examples" id="id30">More examples</a></li>
+</ul>
+</div>
+<div class="section" id="toy-example">
+<h3><a class="toc-backref" href="#id29">Toy example</a><a class="headerlink" href="#toy-example" title="Permalink to this headline">¶</a></h3>
+<p>A simple function that does something interesting if it receives the input
+“HI!”:</p>
+<div class="highlight-python"><pre>cat << EOF > test_fuzzer.cc
+#include <stdint.h>
+#include <stddef.h>
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
+  if (size > 0 && data[0] == 'H')
+    if (size > 1 && data[1] == 'I')
+       if (size > 2 && data[2] == '!')
+       __builtin_trap();
+  return 0;
+}
+EOF
+# Build test_fuzzer.cc with asan and link against libFuzzer.a
+clang++ -fsanitize=address -fsanitize-coverage=trace-pc-guard test_fuzzer.cc libFuzzer.a
+# Run the fuzzer with no corpus.
+./a.out</pre>
+</div>
+<p>You should get an error pretty quickly:</p>
+<div class="highlight-python"><pre>INFO: Seed: 1523017872
+INFO: Loaded 1 modules (16 guards): [0x744e60, 0x744ea0),
+INFO: -max_len is not provided, using 64
+INFO: A corpus is not provided, starting from an empty corpus
+#0    READ units: 1
+#1    INITED cov: 3 ft: 2 corp: 1/1b exec/s: 0 rss: 24Mb
+#3811 NEW    cov: 4 ft: 3 corp: 2/2b exec/s: 0 rss: 25Mb L: 1 MS: 5 ChangeBit-ChangeByte-ChangeBit-ShuffleBytes-ChangeByte-
+#3827 NEW    cov: 5 ft: 4 corp: 3/4b exec/s: 0 rss: 25Mb L: 2 MS: 1 CopyPart-
+#3963 NEW    cov: 6 ft: 5 corp: 4/6b exec/s: 0 rss: 25Mb L: 2 MS: 2 ShuffleBytes-ChangeBit-
+#4167 NEW    cov: 7 ft: 6 corp: 5/9b exec/s: 0 rss: 25Mb L: 3 MS: 1 InsertByte-
+==31511== ERROR: libFuzzer: deadly signal
+...
+artifact_prefix='./'; Test unit written to ./crash-b13e8756b13a00cf168300179061fb4b91fefbed</pre>
+</div>
+</div>
+<div class="section" id="more-examples">
+<h3><a class="toc-backref" href="#id30">More examples</a><a class="headerlink" href="#more-examples" title="Permalink to this headline">¶</a></h3>
+<p>Examples of real-life fuzz targets and the bugs they find can be found
+at <a class="reference external" href="http://tutorial.libfuzzer.info">http://tutorial.libfuzzer.info</a>. Among other things you can learn how
+to detect <a class="reference external" href="http://en.wikipedia.org/wiki/Heartbleed">Heartbleed</a> in one second.</p>
+</div>
+</div>
+<div class="section" id="advanced-features">
+<h2><a class="toc-backref" href="#id19">Advanced features</a><a class="headerlink" href="#advanced-features" title="Permalink to this headline">¶</a></h2>
+<div class="contents local topic" id="id3">
+<ul class="simple">
+<li><a class="reference internal" href="#dictionaries" id="id31">Dictionaries</a></li>
+<li><a class="reference internal" href="#tracing-cmp-instructions" id="id32">Tracing CMP instructions</a></li>
+<li><a class="reference internal" href="#value-profile" id="id33">Value Profile</a></li>
+<li><a class="reference internal" href="#fuzzer-friendly-build-mode" id="id34">Fuzzer-friendly build mode</a></li>
+<li><a class="reference internal" href="#afl-compatibility" id="id35">AFL compatibility</a></li>
+<li><a class="reference internal" href="#how-good-is-my-fuzzer" id="id36">How good is my fuzzer?</a></li>
+<li><a class="reference internal" href="#user-supplied-mutators" id="id37">User-supplied mutators</a></li>
+<li><a class="reference internal" href="#startup-initialization" id="id38">Startup initialization</a></li>
+<li><a class="reference internal" href="#leaks" id="id39">Leaks</a></li>
+</ul>
+</div>
+<div class="section" id="dictionaries">
+<h3><a class="toc-backref" href="#id31">Dictionaries</a><a class="headerlink" href="#dictionaries" title="Permalink to this headline">¶</a></h3>
+<p>LibFuzzer supports user-supplied dictionaries with input language keywords
+or other interesting byte sequences (e.g. multi-byte magic values).
+Use <tt class="docutils literal"><span class="pre">-dict=DICTIONARY_FILE</span></tt>. For some input languages using a dictionary
+may significantly improve the search speed.
+The dictionary syntax is similar to that used by <a class="reference external" href="http://lcamtuf.coredump.cx/afl/">AFL</a> for its <tt class="docutils literal"><span class="pre">-x</span></tt> option:</p>
+<div class="highlight-python"><div class="highlight"><pre><span class="c"># Lines starting with '#' and empty lines are ignored.</span>
+
+<span class="c"># Adds "blah" (w/o quotes) to the dictionary.</span>
+<span class="n">kw1</span><span class="o">=</span><span class="s">"blah"</span>
+<span class="c"># Use \\ for backslash and \" for quotes.</span>
+<span class="n">kw2</span><span class="o">=</span><span class="s">"</span><span class="se">\"</span><span class="s">ac</span><span class="se">\\</span><span class="s">dc</span><span class="se">\"</span><span class="s">"</span>
+<span class="c"># Use \xAB for hex values</span>
+<span class="n">kw3</span><span class="o">=</span><span class="s">"</span><span class="se">\xF7\xF8</span><span class="s">"</span>
+<span class="c"># the name of the keyword followed by '=' may be omitted:</span>
+<span class="s">"foo</span><span class="se">\x0A</span><span class="s">bar"</span>
+</pre></div>
+</div>
+</div>
+<div class="section" id="tracing-cmp-instructions">
+<h3><a class="toc-backref" href="#id32">Tracing CMP instructions</a><a class="headerlink" href="#tracing-cmp-instructions" title="Permalink to this headline">¶</a></h3>
+<p>With an additional compiler flag <tt class="docutils literal"><span class="pre">-fsanitize-coverage=trace-cmp</span></tt>
+(see <a class="reference external" href="http://clang.llvm.org/docs/SanitizerCoverage.html#tracing-data-flow">SanitizerCoverageTraceDataFlow</a>)
+libFuzzer will intercept CMP instructions and guide mutations based
+on the arguments of intercepted CMP instructions. This may slow down
+the fuzzing but is very likely to improve the results.</p>
+</div>
+<div class="section" id="value-profile">
+<h3><a class="toc-backref" href="#id33">Value Profile</a><a class="headerlink" href="#value-profile" title="Permalink to this headline">¶</a></h3>
+<p><em>EXPERIMENTAL</em>.
+With  <tt class="docutils literal"><span class="pre">-fsanitize-coverage=trace-cmp</span></tt>
+and extra run-time flag <tt class="docutils literal"><span class="pre">-use_value_profile=1</span></tt> the fuzzer will
+collect value profiles for the parameters of compare instructions
+and treat some new values as new coverage.</p>
+<p>The current imlpementation does roughly the following:</p>
+<ul class="simple">
+<li>The compiler instruments all CMP instructions with a callback that receives both CMP arguments.</li>
+<li>The callback computes <cite>(caller_pc&4095) | (popcnt(Arg1 ^ Arg2) << 12)</cite> and uses this value to set a bit in a bitset.</li>
+<li>Every new observed bit in the bitset is treated as new coverage.</li>
+</ul>
+<p>This feature has a potential to discover many interesting inputs,
+but there are two downsides.
+First, the extra instrumentation may bring up to 2x additional slowdown.
+Second, the corpus may grow by several times.</p>
+</div>
+<div class="section" id="fuzzer-friendly-build-mode">
+<h3><a class="toc-backref" href="#id34">Fuzzer-friendly build mode</a><a class="headerlink" href="#fuzzer-friendly-build-mode" title="Permalink to this headline">¶</a></h3>
+<p>Sometimes the code under test is not fuzzing-friendly. Examples:</p>
+<blockquote>
+<div><ul class="simple">
+<li>The target code uses a PRNG seeded e.g. by system time and
+thus two consequent invocations may potentially execute different code paths
+even if the end result will be the same. This will cause a fuzzer to treat
+two similar inputs as significantly different and it will blow up the test corpus.
+E.g. libxml uses <tt class="docutils literal"><span class="pre">rand()</span></tt> inside its hash table.</li>
+<li>The target code uses checksums to protect from invalid inputs.
+E.g. png checks CRC for every chunk.</li>
+</ul>
+</div></blockquote>
+<p>In many cases it makes sense to build a special fuzzing-friendly build
+with certain fuzzing-unfriendly features disabled. We propose to use a common build macro
+for all such cases for consistency: <tt class="docutils literal"><span class="pre">FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION</span></tt>.</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="kt">void</span> <span class="n">MyInitPRNG</span><span class="p">()</span> <span class="p">{</span>
+<span class="cp">#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION</span>
+  <span class="c1">// In fuzzing mode the behavior of the code should be deterministic.</span>
+  <span class="n">srand</span><span class="p">(</span><span class="mi">0</span><span class="p">);</span>
+<span class="cp">#else</span>
+  <span class="n">srand</span><span class="p">(</span><span class="n">time</span><span class="p">(</span><span class="mi">0</span><span class="p">));</span>
+<span class="cp">#endif</span>
+<span class="p">}</span>
+</pre></div>
+</div>
+</div>
+<div class="section" id="afl-compatibility">
+<h3><a class="toc-backref" href="#id35">AFL compatibility</a><a class="headerlink" href="#afl-compatibility" title="Permalink to this headline">¶</a></h3>
+<p>LibFuzzer can be used together with <a class="reference external" href="http://lcamtuf.coredump.cx/afl/">AFL</a> on the same test corpus.
+Both fuzzers expect the test corpus to reside in a directory, one file per input.
+You can run both fuzzers on the same corpus, one after another:</p>
+<div class="highlight-console"><div class="highlight"><pre><span class="go">./afl-fuzz -i testcase_dir -o findings_dir /path/to/program @@</span>
+<span class="go">./llvm-fuzz testcase_dir findings_dir  # Will write new tests to testcase_dir</span>
+</pre></div>
+</div>
+<p>Periodically restart both fuzzers so that they can use each other’s findings.
+Currently, there is no simple way to run both fuzzing engines in parallel while sharing the same corpus dir.</p>
+<p>You may also use AFL on your target function <tt class="docutils literal"><span class="pre">LLVMFuzzerTestOneInput</span></tt>:
+see an example <a class="reference external" href="https://github.com/llvm-mirror/llvm/blob/master/lib/Fuzzer/afl/afl_driver.cpp">here</a>.</p>
+</div>
+<div class="section" id="how-good-is-my-fuzzer">
+<h3><a class="toc-backref" href="#id36">How good is my fuzzer?</a><a class="headerlink" href="#how-good-is-my-fuzzer" title="Permalink to this headline">¶</a></h3>
+<p>Once you implement your target function <tt class="docutils literal"><span class="pre">LLVMFuzzerTestOneInput</span></tt> and fuzz it to death,
+you will want to know whether the function or the corpus can be improved further.
+One easy to use metric is, of course, code coverage.
+You can get the coverage for your corpus like this:</p>
+<div class="highlight-console"><div class="highlight"><pre><span class="go">./fuzzer CORPUS_DIR -runs=0 -print_coverage=1</span>
+</pre></div>
+</div>
+<p>This will run all tests in the CORPUS_DIR but will not perform any fuzzing.
+At the end of the process it will print text describing what code has been covered and what hasn’t.</p>
+<p>Alternatively, use</p>
+<div class="highlight-console"><div class="highlight"><pre><span class="go">./fuzzer CORPUS_DIR -runs=0 -dump_coverage=1</span>
+</pre></div>
+</div>
+<p>which will dump a <tt class="docutils literal"><span class="pre">.sancov</span></tt> file with coverage information.
+See <a class="reference external" href="http://clang.llvm.org/docs/SanitizerCoverage.html">SanitizerCoverage</a> for details on querying the file using the <tt class="docutils literal"><span class="pre">sancov</span></tt> tool.</p>
+<p>You may also use other ways to visualize coverage,
+e.g. using <a class="reference external" href="http://clang.llvm.org/docs/SourceBasedCodeCoverage.html">Clang coverage</a>,
+but those will require
+you to rebuild the code with different compiler flags.</p>
+</div>
+<div class="section" id="user-supplied-mutators">
+<h3><a class="toc-backref" href="#id37">User-supplied mutators</a><a class="headerlink" href="#user-supplied-mutators" title="Permalink to this headline">¶</a></h3>
+<p>LibFuzzer allows to use custom (user-supplied) mutators,
+see <a class="reference external" href="https://github.com/llvm-mirror/llvm/blob/master/lib/Fuzzer/FuzzerInterface.h">FuzzerInterface.h</a></p>
+</div>
+<div class="section" id="startup-initialization">
+<h3><a class="toc-backref" href="#id38">Startup initialization</a><a class="headerlink" href="#startup-initialization" title="Permalink to this headline">¶</a></h3>
+<p>If the library being tested needs to be initialized, there are several options.</p>
+<p>The simplest way is to have a statically initialized global object inside
+<cite>LLVMFuzzerTestOneInput</cite> (or in global scope if that works for you):</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="k">extern</span> <span class="s">"C"</span> <span class="kt">int</span> <span class="n">LLVMFuzzerTestOneInput</span><span class="p">(</span><span class="k">const</span> <span class="n">uint8_t</span> <span class="o">*</span><span class="n">Data</span><span class="p">,</span> <span class="n">size_t</span> <span class="n">Size</span><span class="p">)</span> <span class="p">{</span>
+  <span class="k">static</span> <span class="kt">bool</span> <span class="n">Initialized</span> <span class="o">=</span> <span class="n">DoInitialization</span><span class="p">();</span>
+  <span class="p">...</span>
+</pre></div>
+</div>
+<p>Alternatively, you may define an optional init function and it will receive
+the program arguments that you can read and modify. Do this <strong>only</strong> if you
+really need to access <tt class="docutils literal"><span class="pre">argv</span></tt>/<tt class="docutils literal"><span class="pre">argc</span></tt>.</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="k">extern</span> <span class="s">"C"</span> <span class="kt">int</span> <span class="n">LLVMFuzzerInitialize</span><span class="p">(</span><span class="kt">int</span> <span class="o">*</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">ReadAndMaybeModify</span><span class="p">(</span><span class="n">argc</span><span class="p">,</span> <span class="n">argv</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>
+</div>
+<div class="section" id="leaks">
+<h3><a class="toc-backref" href="#id39">Leaks</a><a class="headerlink" href="#leaks" title="Permalink to this headline">¶</a></h3>
+<p>Binaries built with <a class="reference external" href="http://clang.llvm.org/docs/AddressSanitizer.html">AddressSanitizer</a> or <a class="reference external" href="http://clang.llvm.org/docs/LeakSanitizer.html">LeakSanitizer</a> will try to detect
+memory leaks at the process shutdown.
+For in-process fuzzing this is inconvenient
+since the fuzzer needs to report a leak with a reproducer as soon as the leaky
+mutation is found. However, running full leak detection after every mutation
+is expensive.</p>
+<p>By default (<tt class="docutils literal"><span class="pre">-detect_leaks=1</span></tt>) libFuzzer will count the number of
+<tt class="docutils literal"><span class="pre">malloc</span></tt> and <tt class="docutils literal"><span class="pre">free</span></tt> calls when executing every mutation.
+If the numbers don’t match (which by itself doesn’t mean there is a leak)
+libFuzzer will invoke the more expensive <a class="reference external" href="http://clang.llvm.org/docs/LeakSanitizer.html">LeakSanitizer</a>
+pass and if the actual leak is found, it will be reported with the reproducer
+and the process will exit.</p>
+<p>If your target has massive leaks and the leak detection is disabled
+you will eventually run out of RAM (see the <tt class="docutils literal"><span class="pre">-rss_limit_mb</span></tt> flag).</p>
+</div>
+</div>
+<div class="section" id="developing-libfuzzer">
+<h2><a class="toc-backref" href="#id20">Developing libFuzzer</a><a class="headerlink" href="#developing-libfuzzer" title="Permalink to this headline">¶</a></h2>
+<p>Building libFuzzer as a part of LLVM project and running its test requires
+fresh clang as the host compiler and special CMake configuration:</p>
+<div class="highlight-console"><div class="highlight"><pre><span class="go">cmake -GNinja  -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DLLVM_USE_SANITIZER=Address -DLLVM_USE_SANITIZE_COVERAGE=YES -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=ON /path/to/llvm</span>
+<span class="go">ninja check-fuzzer</span>
+</pre></div>
+</div>
+</div>
+<div class="section" id="fuzzing-components-of-llvm">
+<h2><a class="toc-backref" href="#id21">Fuzzing components of LLVM</a><a class="headerlink" href="#fuzzing-components-of-llvm" title="Permalink to this headline">¶</a></h2>
+<div class="contents local topic" id="id4">
+<ul class="simple">
+<li><a class="reference internal" href="#clang-format-fuzzer" id="id40">clang-format-fuzzer</a></li>
+<li><a class="reference internal" href="#clang-fuzzer" id="id41">clang-fuzzer</a></li>
+<li><a class="reference internal" href="#llvm-as-fuzzer" id="id42">llvm-as-fuzzer</a></li>
+<li><a class="reference internal" href="#llvm-mc-fuzzer" id="id43">llvm-mc-fuzzer</a></li>
+<li><a class="reference internal" href="#buildbot" id="id44">Buildbot</a></li>
+</ul>
+</div>
+<p>To build any of the LLVM fuzz targets use the build instructions above.</p>
+<div class="section" id="clang-format-fuzzer">
+<h3><a class="toc-backref" href="#id40">clang-format-fuzzer</a><a class="headerlink" href="#clang-format-fuzzer" title="Permalink to this headline">¶</a></h3>
+<p>The inputs are random pieces of C++-like text.</p>
+<div class="highlight-console"><div class="highlight"><pre><span class="go">ninja clang-format-fuzzer</span>
+<span class="go">mkdir CORPUS_DIR</span>
+<span class="go">./bin/clang-format-fuzzer CORPUS_DIR</span>
+</pre></div>
+</div>
+<p>Optionally build other kinds of binaries (ASan+Debug, MSan, UBSan, etc).</p>
+<p>Tracking bug: <a class="reference external" href="https://llvm.org/bugs/show_bug.cgi?id=23052">https://llvm.org/bugs/show_bug.cgi?id=23052</a></p>
+</div>
+<div class="section" id="clang-fuzzer">
+<h3><a class="toc-backref" href="#id41">clang-fuzzer</a><a class="headerlink" href="#clang-fuzzer" title="Permalink to this headline">¶</a></h3>
+<p>The behavior is very similar to <tt class="docutils literal"><span class="pre">clang-format-fuzzer</span></tt>.</p>
+<p>Tracking bug: <a class="reference external" href="https://llvm.org/bugs/show_bug.cgi?id=23057">https://llvm.org/bugs/show_bug.cgi?id=23057</a></p>
+</div>
+<div class="section" id="llvm-as-fuzzer">
+<h3><a class="toc-backref" href="#id42">llvm-as-fuzzer</a><a class="headerlink" href="#llvm-as-fuzzer" title="Permalink to this headline">¶</a></h3>
+<p>Tracking bug: <a class="reference external" href="https://llvm.org/bugs/show_bug.cgi?id=24639">https://llvm.org/bugs/show_bug.cgi?id=24639</a></p>
+</div>
+<div class="section" id="llvm-mc-fuzzer">
+<h3><a class="toc-backref" href="#id43">llvm-mc-fuzzer</a><a class="headerlink" href="#llvm-mc-fuzzer" title="Permalink to this headline">¶</a></h3>
+<p>This tool fuzzes the MC layer. Currently it is only able to fuzz the
+disassembler but it is hoped that assembly, and round-trip verification will be
+added in future.</p>
+<p>When run in dissassembly mode, the inputs are opcodes to be disassembled. The
+fuzzer will consume as many instructions as possible and will stop when it
+finds an invalid instruction or runs out of data.</p>
+<p>Please note that the command line interface differs slightly from that of other
+fuzzers. The fuzzer arguments should follow <tt class="docutils literal"><span class="pre">--fuzzer-args</span></tt> and should have
+a single dash, while other arguments control the operation mode and target in a
+similar manner to <tt class="docutils literal"><span class="pre">llvm-mc</span></tt> and should have two dashes. For example:</p>
+<div class="highlight-console"><div class="highlight"><pre><span class="go">llvm-mc-fuzzer --triple=aarch64-linux-gnu --disassemble --fuzzer-args -max_len=4 -jobs=10</span>
+</pre></div>
+</div>
+</div>
+<div class="section" id="buildbot">
+<h3><a class="toc-backref" href="#id44">Buildbot</a><a class="headerlink" href="#buildbot" title="Permalink to this headline">¶</a></h3>
+<p>A buildbot continuously runs the above fuzzers for LLVM components, with results
+shown at <a class="reference external" href="http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fuzzer">http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fuzzer</a> .</p>
+</div>
+</div>
+<div class="section" id="faq">
+<h2><a class="toc-backref" href="#id22">FAQ</a><a class="headerlink" href="#faq" title="Permalink to this headline">¶</a></h2>
+<div class="section" id="q-why-doesn-t-libfuzzer-use-any-of-the-llvm-support">
+<h3>Q. Why doesn’t libFuzzer use any of the LLVM support?<a class="headerlink" href="#q-why-doesn-t-libfuzzer-use-any-of-the-llvm-support" title="Permalink to this headline">¶</a></h3>
+<p>There are two reasons.</p>
+<p>First, we want this library to be used outside of the LLVM without users having to
+build the rest of LLVM. This may sound unconvincing for many LLVM folks,
+but in practice the need for building the whole LLVM frightens many potential
+users – and we want more users to use this code.</p>
+<p>Second, there is a subtle technical reason not to rely on the rest of LLVM, or
+any other large body of code (maybe not even STL). When coverage instrumentation
+is enabled, it will also instrument the LLVM support code which will blow up the
+coverage set of the process (since the fuzzer is in-process). In other words, by
+using more external dependencies we will slow down the fuzzer while the main
+reason for it to exist is extreme speed.</p>
+</div>
+<div class="section" id="q-what-about-windows-then-the-fuzzer-contains-code-that-does-not-build-on-windows">
+<h3>Q. What about Windows then? The fuzzer contains code that does not build on Windows.<a class="headerlink" href="#q-what-about-windows-then-the-fuzzer-contains-code-that-does-not-build-on-windows" title="Permalink to this headline">¶</a></h3>
+<p>Volunteers are welcome.</p>
+</div>
+<div class="section" id="q-when-libfuzzer-is-not-a-good-solution-for-a-problem">
+<h3>Q. When libFuzzer is not a good solution for a problem?<a class="headerlink" href="#q-when-libfuzzer-is-not-a-good-solution-for-a-problem" title="Permalink to this headline">¶</a></h3>
+<ul class="simple">
+<li>If the test inputs are validated by the target library and the validator
+asserts/crashes on invalid inputs, in-process fuzzing is not applicable.</li>
+<li>Bugs in the target library may accumulate without being detected. E.g. a memory
+corruption that goes undetected at first and then leads to a crash while
+testing another input. This is why it is highly recommended to run this
+in-process fuzzer with all sanitizers to detect most bugs on the spot.</li>
+<li>It is harder to protect the in-process fuzzer from excessive memory
+consumption and infinite loops in the target library (still possible).</li>
+<li>The target library should not have significant global state that is not
+reset between the runs.</li>
+<li>Many interesting target libraries are not designed in a way that supports
+the in-process fuzzer interface (e.g. require a file path instead of a
+byte array).</li>
+<li>If a single test run takes a considerable fraction of a second (or
+more) the speed benefit from the in-process fuzzer is negligible.</li>
+<li>If the target library runs persistent threads (that outlive
+execution of one test) the fuzzing results will be unreliable.</li>
+</ul>
+</div>
+<div class="section" id="q-so-what-exactly-this-fuzzer-is-good-for">
+<h3>Q. So, what exactly this Fuzzer is good for?<a class="headerlink" href="#q-so-what-exactly-this-fuzzer-is-good-for" title="Permalink to this headline">¶</a></h3>
+<p>This Fuzzer might be a good choice for testing libraries that have relatively
+small inputs, each input takes < 10ms to run, and the library code is not expected
+to crash on invalid inputs.
+Examples: regular expression matchers, text or binary format parsers, compression,
+network, crypto.</p>
+</div>
+</div>
+<div class="section" id="trophies">
+<h2><a class="toc-backref" href="#id23">Trophies</a><a class="headerlink" href="#trophies" title="Permalink to this headline">¶</a></h2>
+<ul class="simple">
+<li>GLIBC: <a class="reference external" href="https://sourceware.org/glibc/wiki/FuzzingLibc">https://sourceware.org/glibc/wiki/FuzzingLibc</a></li>
+<li>MUSL LIBC: <a class="reference external" href="http://git.musl-libc.org/cgit/musl/commit/?id=39dfd58417ef642307d90306e1c7e50aaec5a35c">[1]</a> <a class="reference external" href="http://www.openwall.com/lists/oss-security/2015/03/30/3">[2]</a></li>
+<li><a class="reference external" href="https://github.com/zeux/pugixml/issues/39">pugixml</a></li>
+<li>PCRE: Search for “LLVM fuzzer” in <a class="reference external" href="http://vcs.pcre.org/pcre2/code/trunk/ChangeLog?view=markup">http://vcs.pcre.org/pcre2/code/trunk/ChangeLog?view=markup</a>;
+also in <a class="reference external" href="https://bugs.exim.org/buglist.cgi?bug_status=__all__&content=libfuzzer&no_redirect=1&order=Importance&product=PCRE&query_format=specific">bugzilla</a></li>
+<li><a class="reference external" href="http://bugs.icu-project.org/trac/ticket/11838">ICU</a></li>
+<li><a class="reference external" href="https://savannah.nongnu.org/search/?words=LibFuzzer&type_of_search=bugs&Search=Search&exact=1#options">Freetype</a></li>
+<li><a class="reference external" href="https://github.com/behdad/harfbuzz/issues/139">Harfbuzz</a></li>
+<li><a class="reference external" href="http://www3.sqlite.org/cgi/src/info/088009efdd56160b">SQLite</a></li>
+<li><a class="reference external" href="http://bugs.python.org/issue25388">Python</a></li>
+<li>OpenSSL/BoringSSL: <a class="reference external" href="https://boringssl.googlesource.com/boringssl/+/cb852981cd61733a7a1ae4fd8755b7ff950e857d">[1]</a> <a class="reference external" href="https://openssl.org/news/secadv/20160301.txt">[2]</a> <a class="reference external" href="https://boringssl.googlesource.com/boringssl/+/2b07fa4b22198ac02e0cee8f37f3337c3dba91bc">[3]</a> <a class="reference external" href="https://boringssl.googlesource.com/boringssl/+/6b6e0b20893e2be0e68af605a60ffa2cbb0ffa64">[4]</a>  <a class="reference external" href="https://github.com/openssl/openssl/pull/931/commits/dd5ac557f052cc2b7f718ac44a8cb7ac6f77dca8">[5]</a> <a class="reference external" href="https://github.com/openssl/openssl/pull/931/commits/19b5b9194071d1d84e38ac9a952e715afbc85a81">[6]</a></li>
+<li><a class="reference external" href="https://bugzilla.gnome.org/buglist.cgi?bug_status=__all__&content=libFuzzer&list_id=68957&order=Importance&product=libxml2&query_format=specific">Libxml2</a> and <a class="reference external" href="https://support.apple.com/en-gb/HT206167">[HT206167]</a> (CVE-2015-5312, CVE-2015-7500, CVE-2015-7942)</li>
+<li><a class="reference external" href="https://github.com/iovisor/bpf-fuzzer">Linux Kernel’s BPF verifier</a></li>
+<li>Capstone: <a class="reference external" href="https://github.com/aquynh/capstone/issues/600">[1]</a> <a class="reference external" href="https://github.com/aquynh/capstone/commit/6b88d1d51eadf7175a8f8a11b690684443b11359">[2]</a></li>
+<li>file:<a class="reference external" href="http://bugs.gw.com/view.php?id=550">[1]</a>  <a class="reference external" href="http://bugs.gw.com/view.php?id=551">[2]</a>  <a class="reference external" href="http://bugs.gw.com/view.php?id=553">[3]</a>  <a class="reference external" href="http://bugs.gw.com/view.php?id=554">[4]</a></li>
+<li>Radare2: <a class="reference external" href="https://github.com/revskills?tab=contributions&from=2016-04-09">[1]</a></li>
+<li>gRPC: <a class="reference external" href="https://github.com/grpc/grpc/pull/6071/commits/df04c1f7f6aec6e95722ec0b023a6b29b6ea871c">[1]</a> <a class="reference external" href="https://github.com/grpc/grpc/pull/6071/commits/22a3dfd95468daa0db7245a4e8e6679a52847579">[2]</a> <a class="reference external" href="https://github.com/grpc/grpc/pull/6071/commits/9cac2a12d9e181d130841092e9d40fa3309d7aa7">[3]</a> <a class="reference external" href="https://github.com/grpc/grpc/pull/6012/commits/82a91c91d01ce9b999c8821ed13515883468e203">[4]</a> <a class="reference external" href="https://github.com/grpc/grpc/pull/6202/commits/2e3e0039b30edaf89fb93bfb2c1d0909098519fa">[5]</a> <a class="reference external" href="https://github.com/grpc/grpc/pull/6106/files">[6]</a></li>
+<li>WOFF2: <a class="reference external" href="https://github.com/google/woff2/commit/a15a8ab">[1]</a></li>
+<li>LLVM: <a class="reference external" href="https://llvm.org/bugs/show_bug.cgi?id=23057">Clang</a>, <a class="reference external" href="https://llvm.org/bugs/show_bug.cgi?id=23052">Clang-format</a>, <a class="reference external" href="https://llvm.org/bugs/show_bug.cgi?id=24411">libc++</a>, <a class="reference external" href="https://llvm.org/bugs/show_bug.cgi?id=24639">llvm-as</a>, <a class="reference external" href="https://bugs.chromium.org/p/chromium/issues/detail?id=606626">Demangler</a>, Disassembler: <a class="reference external" href="http://reviews.llvm.org/rL247405">http://reviews.llvm.org/rL247405</a>, <a class="reference external" href="http://reviews.llvm.org/rL247414">http://reviews.llvm.org/rL247414</a>, <a class="reference external" href="http://reviews.llvm.org/rL247416">http://reviews.llvm.org/rL247416</a>, <a class="reference external" href="http://reviews.llvm.org/rL247417">http://reviews.llvm.org/rL247417</a>, <a class="reference external" href="http://reviews.llvm.org/rL247420">http://reviews.llvm.org/rL247420</a>, <a class="reference external" href="http://reviews.llvm.org/rL247422">http://reviews.llvm.org/rL247422</a>.</li>
+<li>Tensorflow: <a class="reference external" href="https://da-data.blogspot.com/2017/01/finding-bugs-in-tensorflow-with.html">[1]</a></li>
+<li>Ffmpeg: <a class="reference external" href="https://github.com/FFmpeg/FFmpeg/commit/c92f55847a3d9cd12db60bfcd0831ff7f089c37c">[1]</a>  <a class="reference external" href="https://github.com/FFmpeg/FFmpeg/commit/25ab1a65f3acb5ec67b53fb7a2463a7368f1ad16">[2]</a>  <a class="reference external" href="https://github.com/FFmpeg/FFmpeg/commit/85d23e5cbc9ad6835eef870a5b4247de78febe56">[3]</a> <a class="reference external" href="https://github.com/FFmpeg/FFmpeg/commit/04bd1b38ee6b8df410d0ab8d4949546b6c4af26a">[4]</a></li>
+<li><a class="reference external" href="https://bugs.wireshark.org/bugzilla/buglist.cgi?bug_status=UNCONFIRMED&bug_status=CONFIRMED&bug_status=IN_PROGRESS&bug_status=INCOMPLETE&bug_status=RESOLVED&bug_status=VERIFIED&f0=OP&f1=OP&f2=product&f3=component&f4=alias&f5=short_desc&f7=content&f8=CP&f9=CP&j1=OR&o2=substring&o3=substring&o4=substring&o5=substring&o6=substring&o7=matches&order=bug_id%20DESC&query_format=advanced&v2=libfuzzer&v3=libfuzzer&v4=libfuzzer&v5=libfuzzer&v6=libfuzzer&v7=%22libfuzzer%22">Wireshark</a></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="ScudoHardenedAllocator.html" title="Scudo Hardened Allocator"
+             >next</a> |</li>
+        <li class="right" >
+          <a href="Extensions.html" title="LLVM Extensions"
+             >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-2018, LLVM Project.
+      Last updated on 2018-05-10.
+      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/5.0.2/docs/LinkTimeOptimization.html
URL: http://llvm.org/viewvc/llvm-project/www-releases/trunk/5.0.2/docs/LinkTimeOptimization.html?rev=331981&view=auto
==============================================================================
--- www-releases/trunk/5.0.2/docs/LinkTimeOptimization.html (added)
+++ www-releases/trunk/5.0.2/docs/LinkTimeOptimization.html Thu May 10 06:54:16 2018
@@ -0,0 +1,371 @@
+
+
+<!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 5 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:     '5',
+        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 5 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
+treats 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="n">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="n">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="n">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="n">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="n">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 -flto -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 -flto a.o main.o -o main   <span class="c"># <-- standard link command with -flto</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 developments 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="n">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="n">lto_module_t</span><span class="p">)</span>
+<span class="n">lto_module_get_symbol_name</span><span class="p">(</span><span class="n">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="n">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="n">lto_code_gen_t</span><span class="p">,</span> <span class="n">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="n">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="n">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="n">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="n">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-2018, LLVM Project.
+      Last updated on 2018-05-10.
+      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/5.0.2/docs/MCJITDesignAndImplementation.html
URL: http://llvm.org/viewvc/llvm-project/www-releases/trunk/5.0.2/docs/MCJITDesignAndImplementation.html?rev=331981&view=auto
==============================================================================
--- www-releases/trunk/5.0.2/docs/MCJITDesignAndImplementation.html (added)
+++ www-releases/trunk/5.0.2/docs/MCJITDesignAndImplementation.html Thu May 10 06:54:16 2018
@@ -0,0 +1,246 @@
+
+
+<!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 5 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:     '5',
+        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 5 documentation" href="index.html" />
+    <link rel="next" title="LLVM Community Code of Conduct" href="CodeOfConduct.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="CodeOfConduct.html" title="LLVM Community Code of Conduct"
+             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="CodeOfConduct.html" title="LLVM Community Code of Conduct"
+             >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-2018, LLVM Project.
+      Last updated on 2018-05-10.
+      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/5.0.2/docs/MIRLangRef.html
URL: http://llvm.org/viewvc/llvm-project/www-releases/trunk/5.0.2/docs/MIRLangRef.html?rev=331981&view=auto
==============================================================================
--- www-releases/trunk/5.0.2/docs/MIRLangRef.html (added)
+++ www-releases/trunk/5.0.2/docs/MIRLangRef.html Thu May 10 06:54:16 2018
@@ -0,0 +1,558 @@
+
+
+<!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>Machine IR (MIR) Format Reference Manual — LLVM 5 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:     '5',
+        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 5 documentation" href="index.html" />
+    <link rel="next" title="Coroutines in LLVM" href="Coroutines.html" />
+    <link rel="prev" title="FaultMaps and implicit checks" href="FaultMaps.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="Coroutines.html" title="Coroutines in LLVM"
+             accesskey="N">next</a> |</li>
+        <li class="right" >
+          <a href="FaultMaps.html" title="FaultMaps and implicit checks"
+             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="machine-ir-mir-format-reference-manual">
+<h1>Machine IR (MIR) Format Reference Manual<a class="headerlink" href="#machine-ir-mir-format-reference-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="id8">Introduction</a></li>
+<li><a class="reference internal" href="#overview" id="id9">Overview</a></li>
+<li><a class="reference internal" href="#mir-testing-guide" id="id10">MIR Testing Guide</a><ul>
+<li><a class="reference internal" href="#testing-individual-code-generation-passes" id="id11">Testing Individual Code Generation Passes</a><ul>
+<li><a class="reference internal" href="#simplifying-mir-files" id="id12">Simplifying MIR files</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#limitations" id="id13">Limitations</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#high-level-structure" id="id14">High Level Structure</a><ul>
+<li><a class="reference internal" href="#embedded-module" id="id15">Embedded Module</a></li>
+<li><a class="reference internal" href="#machine-functions" id="id16">Machine Functions</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#machine-instructions-format-reference" id="id17">Machine Instructions Format Reference</a><ul>
+<li><a class="reference internal" href="#machine-basic-blocks" id="id18">Machine Basic Blocks</a><ul>
+<li><a class="reference internal" href="#block-references" id="id19">Block References</a></li>
+<li><a class="reference internal" href="#successors" id="id20">Successors</a></li>
+<li><a class="reference internal" href="#live-in-registers" id="id21">Live In Registers</a></li>
+<li><a class="reference internal" href="#miscellaneous-attributes" id="id22">Miscellaneous Attributes</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#machine-instructions" id="id23">Machine Instructions</a><ul>
+<li><a class="reference internal" href="#instruction-flags" id="id24">Instruction Flags</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#registers" id="id25">Registers</a></li>
+<li><a class="reference internal" href="#machine-operands" id="id26">Machine Operands</a><ul>
+<li><a class="reference internal" href="#immediate-operands" id="id27">Immediate Operands</a></li>
+<li><a class="reference internal" href="#register-operands" id="id28">Register Operands</a><ul>
+<li><a class="reference internal" href="#register-flags" id="id29">Register Flags</a></li>
+<li><a class="reference internal" href="#subregister-indices" id="id30">Subregister Indices</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#global-value-operands" id="id31">Global Value Operands</a></li>
+</ul>
+</li>
+</ul>
+</li>
+</ul>
+</div>
+<div class="admonition warning">
+<p class="first admonition-title">Warning</p>
+<p class="last">This is a work in progress.</p>
+</div>
+<div class="section" id="introduction">
+<h2><a class="toc-backref" href="#id8">Introduction</a><a class="headerlink" href="#introduction" title="Permalink to this headline">¶</a></h2>
+<p>This document is a reference manual for the Machine IR (MIR) serialization
+format. MIR is a human readable serialization format that is used to represent
+LLVM’s <a class="reference internal" href="CodeGenerator.html#machine-code-representation"><em>machine specific intermediate representation</em></a>.</p>
+<p>The MIR serialization format is designed to be used for testing the code
+generation passes in LLVM.</p>
+</div>
+<div class="section" id="overview">
+<h2><a class="toc-backref" href="#id9">Overview</a><a class="headerlink" href="#overview" title="Permalink to this headline">¶</a></h2>
+<p>The MIR serialization format uses a YAML container. YAML is a standard
+data serialization language, and the full YAML language spec can be read at
+<a class="reference external" href="http://www.yaml.org/spec/1.2/spec.html#Introduction">yaml.org</a>.</p>
+<p>A MIR file is split up into a series of <a class="reference external" href="http://www.yaml.org/spec/1.2/spec.html#id2800132">YAML documents</a>. The first document
+can contain an optional embedded LLVM IR module, and the rest of the documents
+contain the serialized machine functions.</p>
+</div>
+<div class="section" id="mir-testing-guide">
+<h2><a class="toc-backref" href="#id10">MIR Testing Guide</a><a class="headerlink" href="#mir-testing-guide" title="Permalink to this headline">¶</a></h2>
+<p>You can use the MIR format for testing in two different ways:</p>
+<ul class="simple">
+<li>You can write MIR tests that invoke a single code generation pass using the
+<tt class="docutils literal"><span class="pre">-run-pass</span></tt> option in llc.</li>
+<li>You can use llc’s <tt class="docutils literal"><span class="pre">-stop-after</span></tt> option with existing or new LLVM assembly
+tests and check the MIR output of a specific code generation pass.</li>
+</ul>
+<div class="section" id="testing-individual-code-generation-passes">
+<h3><a class="toc-backref" href="#id11">Testing Individual Code Generation Passes</a><a class="headerlink" href="#testing-individual-code-generation-passes" title="Permalink to this headline">¶</a></h3>
+<p>The <tt class="docutils literal"><span class="pre">-run-pass</span></tt> option in llc allows you to create MIR tests that invoke just
+a single code generation pass. When this option is used, llc will parse an
+input MIR file, run the specified code generation pass(es), and output the
+resulting MIR code.</p>
+<p>You can generate an input MIR file for the test by using the <tt class="docutils literal"><span class="pre">-stop-after</span></tt> or
+<tt class="docutils literal"><span class="pre">-stop-before</span></tt> option in llc. For example, if you would like to write a test
+for the post register allocation pseudo instruction expansion pass, you can
+specify the machine copy propagation pass in the <tt class="docutils literal"><span class="pre">-stop-after</span></tt> option, as it
+runs just before the pass that we are trying to test:</p>
+<blockquote>
+<div><tt class="docutils literal"><span class="pre">llc</span> <span class="pre">-stop-after=machine-cp</span> <span class="pre">bug-trigger.ll</span> <span class="pre">></span> <span class="pre">test.mir</span></tt></div></blockquote>
+<p>After generating the input MIR file, you’ll have to add a run line that uses
+the <tt class="docutils literal"><span class="pre">-run-pass</span></tt> option to it. In order to test the post register allocation
+pseudo instruction expansion pass on X86-64, a run line like the one shown
+below can be used:</p>
+<blockquote>
+<div><tt class="docutils literal"><span class="pre">#</span> <span class="pre">RUN:</span> <span class="pre">llc</span> <span class="pre">-o</span> <span class="pre">-</span> <span class="pre">%s</span> <span class="pre">-mtriple=x86_64--</span> <span class="pre">-run-pass=postrapseudos</span> <span class="pre">|</span> <span class="pre">FileCheck</span> <span class="pre">%s</span></tt></div></blockquote>
+<p>The MIR files are target dependent, so they have to be placed in the target
+specific test directories (<tt class="docutils literal"><span class="pre">lib/CodeGen/TARGETNAME</span></tt>). They also need to
+specify a target triple or a target architecture either in the run line or in
+the embedded LLVM IR module.</p>
+<div class="section" id="simplifying-mir-files">
+<h4><a class="toc-backref" href="#id12">Simplifying MIR files</a><a class="headerlink" href="#simplifying-mir-files" title="Permalink to this headline">¶</a></h4>
+<p>The MIR code coming out of <tt class="docutils literal"><span class="pre">-stop-after</span></tt>/<tt class="docutils literal"><span class="pre">-stop-before</span></tt> is very verbose;
+Tests are more accessible and future proof when simplified:</p>
+<ul class="simple">
+<li>Use the <tt class="docutils literal"><span class="pre">-simplify-mir</span></tt> option with llc.</li>
+<li>Machine function attributes often have default values or the test works just
+as well with default values. Typical candidates for this are: <cite>alignment:</cite>,
+<cite>exposesReturnsTwice</cite>, <cite>legalized</cite>, <cite>regBankSelected</cite>, <cite>selected</cite>.
+The whole <cite>frameInfo</cite> section is often unnecessary if there is no special
+frame usage in the function. <cite>tracksRegLiveness</cite> on the other hand is often
+necessary for some passes that care about block livein lists.</li>
+<li>The (global) <cite>liveins:</cite> list is typically only interesting for early
+instruction selection passes and can be removed when testing later passes.
+The per-block <cite>liveins:</cite> on the other hand are necessary if
+<cite>tracksRegLiveness</cite> is true.</li>
+<li>Branch probability data in block <cite>successors:</cite> lists can be dropped if the
+test doesn’t depend on it. Example:
+<cite>successors: %bb.1(0x40000000), %bb.2(0x40000000)</cite> can be replaced with
+<cite>successors: %bb.1, %bb.2</cite>.</li>
+<li>MIR code contains a whole IR module. This is necessary because there are
+no equivalents in MIR for global variables, references to external functions,
+function attributes, metadata, debug info. Instead some MIR data references
+the IR constructs. You can often remove them if the test doesn’t depend on
+them.</li>
+<li>Alias Analysis is performed on IR values. These are referenced by memory
+operands in MIR. Example: <cite>:: (load 8 from %ir.foobar, !alias.scope !9)</cite>.
+If the test doesn’t depend on (good) alias analysis the references can be
+dropped: <cite>:: (load 8)</cite></li>
+<li>MIR blocks can reference IR blocks for debug printing, profile information
+or debug locations. Example: <cite>bb.42.myblock</cite> in MIR references the IR block
+<cite>myblock</cite>. It is usually possible to drop the <cite>.myblock</cite> reference and simply
+use <cite>bb.42</cite>.</li>
+<li>If there are no memory operands or blocks referencing the IR then the
+IR function can be replaced by a parameterless dummy function like
+<cite>define @func() { ret void }</cite>.</li>
+<li>It is possible to drop the whole IR section of the MIR file if it only
+contains dummy functions (see above). The .mir loader will create the
+IR functions automatically in this case.</li>
+</ul>
+</div>
+</div>
+<div class="section" id="limitations">
+<h3><a class="toc-backref" href="#id13">Limitations</a><a class="headerlink" href="#limitations" title="Permalink to this headline">¶</a></h3>
+<p>Currently the MIR format has several limitations in terms of which state it
+can serialize:</p>
+<ul class="simple">
+<li>The target-specific state in the target-specific <tt class="docutils literal"><span class="pre">MachineFunctionInfo</span></tt>
+subclasses isn’t serialized at the moment.</li>
+<li>The target-specific <tt class="docutils literal"><span class="pre">MachineConstantPoolValue</span></tt> subclasses (in the ARM and
+SystemZ backends) aren’t serialized at the moment.</li>
+<li>The <tt class="docutils literal"><span class="pre">MCSymbol</span></tt> machine operands are only printed, they can’t be parsed.</li>
+<li>A lot of the state in <tt class="docutils literal"><span class="pre">MachineModuleInfo</span></tt> isn’t serialized - only the CFI
+instructions and the variable debug information from MMI is serialized right
+now.</li>
+</ul>
+<p>These limitations impose restrictions on what you can test with the MIR format.
+For now, tests that would like to test some behaviour that depends on the state
+of certain <tt class="docutils literal"><span class="pre">MCSymbol</span></tt>  operands or the exception handling state in MMI, can’t
+use the MIR format. As well as that, tests that test some behaviour that
+depends on the state of the target specific <tt class="docutils literal"><span class="pre">MachineFunctionInfo</span></tt> or
+<tt class="docutils literal"><span class="pre">MachineConstantPoolValue</span></tt> subclasses can’t use the MIR format at the moment.</p>
+</div>
+</div>
+<div class="section" id="high-level-structure">
+<h2><a class="toc-backref" href="#id14">High Level Structure</a><a class="headerlink" href="#high-level-structure" title="Permalink to this headline">¶</a></h2>
+<div class="section" id="embedded-module">
+<span id="id1"></span><h3><a class="toc-backref" href="#id15">Embedded Module</a><a class="headerlink" href="#embedded-module" title="Permalink to this headline">¶</a></h3>
+<p>When the first YAML document contains a <a class="reference external" href="http://www.yaml.org/spec/1.2/spec.html#id2795688">YAML block literal string</a>, the MIR
+parser will treat this string as an LLVM assembly language string that
+represents an embedded LLVM IR module.
+Here is an example of a YAML document that contains an LLVM module:</p>
+<div class="highlight-llvm"><div class="highlight"><pre><span class="k">define</span> <span class="k">i32</span> <span class="vg">@inc</span><span class="p">(</span><span class="k">i32</span><span class="p">*</span> <span class="nv">%x</span><span class="p">)</span> <span class="p">{</span>
+<span class="nl">entry:</span>
+  <span class="nv-Anonymous">%0</span> <span class="p">=</span> <span class="k">load</span> <span class="k">i32</span><span class="p">,</span> <span class="k">i32</span><span class="p">*</span> <span class="nv">%x</span>
+  <span class="nv-Anonymous">%1</span> <span class="p">=</span> <span class="k">add</span> <span class="k">i32</span> <span class="nv-Anonymous">%0</span><span class="p">,</span> <span class="m">1</span>
+  <span class="k">store</span> <span class="k">i32</span> <span class="nv-Anonymous">%1</span><span class="p">,</span> <span class="k">i32</span><span class="p">*</span> <span class="nv">%x</span>
+  <span class="k">ret</span> <span class="k">i32</span> <span class="nv-Anonymous">%1</span>
+<span class="p">}</span>
+</pre></div>
+</div>
+</div>
+<div class="section" id="machine-functions">
+<h3><a class="toc-backref" href="#id16">Machine Functions</a><a class="headerlink" href="#machine-functions" title="Permalink to this headline">¶</a></h3>
+<p>The remaining YAML documents contain the machine functions. This is an example
+of such YAML document:</p>
+<div class="highlight-text"><div class="highlight"><pre>---
+name:            inc
+tracksRegLiveness: true
+liveins:
+  - { reg: '%rdi' }
+body: |
+  bb.0.entry:
+    liveins: %rdi
+
+    %eax = MOV32rm %rdi, 1, _, 0, _
+    %eax = INC32r killed %eax, implicit-def dead %eflags
+    MOV32mr killed %rdi, 1, _, 0, _, %eax
+    RETQ %eax
+...
+</pre></div>
+</div>
+<p>The document above consists of attributes that represent the various
+properties and data structures in a machine function.</p>
+<p>The attribute <tt class="docutils literal"><span class="pre">name</span></tt> is required, and its value should be identical to the
+name of a function that this machine function is based on.</p>
+<p>The attribute <tt class="docutils literal"><span class="pre">body</span></tt> is a <a class="reference external" href="http://www.yaml.org/spec/1.2/spec.html#id2795688">YAML block literal string</a>. Its value represents
+the function’s machine basic blocks and their machine instructions.</p>
+</div>
+</div>
+<div class="section" id="machine-instructions-format-reference">
+<h2><a class="toc-backref" href="#id17">Machine Instructions Format Reference</a><a class="headerlink" href="#machine-instructions-format-reference" title="Permalink to this headline">¶</a></h2>
+<p>The machine basic blocks and their instructions are represented using a custom,
+human readable serialization language. This language is used in the
+<a class="reference external" href="http://www.yaml.org/spec/1.2/spec.html#id2795688">YAML block literal string</a> that corresponds to the machine function’s body.</p>
+<p>A source string that uses this language contains a list of machine basic
+blocks, which are described in the section below.</p>
+<div class="section" id="machine-basic-blocks">
+<h3><a class="toc-backref" href="#id18">Machine Basic Blocks</a><a class="headerlink" href="#machine-basic-blocks" title="Permalink to this headline">¶</a></h3>
+<p>A machine basic block is defined in a single block definition source construct
+that contains the block’s ID.
+The example below defines two blocks that have an ID of zero and one:</p>
+<div class="highlight-text"><div class="highlight"><pre>bb.0:
+  <instructions>
+bb.1:
+  <instructions>
+</pre></div>
+</div>
+<p>A machine basic block can also have a name. It should be specified after the ID
+in the block’s definition:</p>
+<div class="highlight-text"><div class="highlight"><pre>bb.0.entry:       ; This block's name is "entry"
+   <instructions>
+</pre></div>
+</div>
+<p>The block’s name should be identical to the name of the IR block that this
+machine block is based on.</p>
+<div class="section" id="block-references">
+<h4><a class="toc-backref" href="#id19">Block References</a><a class="headerlink" href="#block-references" title="Permalink to this headline">¶</a></h4>
+<p>The machine basic blocks are identified by their ID numbers. Individual
+blocks are referenced using the following syntax:</p>
+<div class="highlight-text"><div class="highlight"><pre>%bb.<id>[.<name>]
+</pre></div>
+</div>
+<p>Examples:</p>
+<div class="highlight-llvm"><div class="highlight"><pre><span class="nv">%bb.0</span>
+<span class="nv">%bb.1.then</span>
+</pre></div>
+</div>
+</div>
+<div class="section" id="successors">
+<h4><a class="toc-backref" href="#id20">Successors</a><a class="headerlink" href="#successors" title="Permalink to this headline">¶</a></h4>
+<p>The machine basic block’s successors have to be specified before any of the
+instructions:</p>
+<div class="highlight-text"><div class="highlight"><pre>bb.0.entry:
+  successors: %bb.1.then, %bb.2.else
+  <instructions>
+bb.1.then:
+  <instructions>
+bb.2.else:
+  <instructions>
+</pre></div>
+</div>
+<p>The branch weights can be specified in brackets after the successor blocks.
+The example below defines a block that has two successors with branch weights
+of 32 and 16:</p>
+<div class="highlight-text"><div class="highlight"><pre>bb.0.entry:
+  successors: %bb.1.then(32), %bb.2.else(16)
+</pre></div>
+</div>
+</div>
+<div class="section" id="live-in-registers">
+<span id="bb-liveins"></span><h4><a class="toc-backref" href="#id21">Live In Registers</a><a class="headerlink" href="#live-in-registers" title="Permalink to this headline">¶</a></h4>
+<p>The machine basic block’s live in registers have to be specified before any of
+the instructions:</p>
+<div class="highlight-text"><div class="highlight"><pre>bb.0.entry:
+  liveins: %edi, %esi
+</pre></div>
+</div>
+<p>The list of live in registers and successors can be empty. The language also
+allows multiple live in register and successor lists - they are combined into
+one list by the parser.</p>
+</div>
+<div class="section" id="miscellaneous-attributes">
+<h4><a class="toc-backref" href="#id22">Miscellaneous Attributes</a><a class="headerlink" href="#miscellaneous-attributes" title="Permalink to this headline">¶</a></h4>
+<p>The attributes <tt class="docutils literal"><span class="pre">IsAddressTaken</span></tt>, <tt class="docutils literal"><span class="pre">IsLandingPad</span></tt> and <tt class="docutils literal"><span class="pre">Alignment</span></tt> can be
+specified in brackets after the block’s definition:</p>
+<div class="highlight-text"><div class="highlight"><pre>bb.0.entry (address-taken):
+  <instructions>
+bb.2.else (align 4):
+  <instructions>
+bb.3(landing-pad, align 4):
+  <instructions>
+</pre></div>
+</div>
+</div>
+</div>
+<div class="section" id="machine-instructions">
+<h3><a class="toc-backref" href="#id23">Machine Instructions</a><a class="headerlink" href="#machine-instructions" title="Permalink to this headline">¶</a></h3>
+<p>A machine instruction is composed of a name,
+<a class="reference internal" href="#machine-operands"><em>machine operands</em></a>,
+<a class="reference internal" href="#instruction-flags"><em>instruction flags</em></a>, and machine memory operands.</p>
+<p>The instruction’s name is usually specified before the operands. The example
+below shows an instance of the X86 <tt class="docutils literal"><span class="pre">RETQ</span></tt> instruction with a single machine
+operand:</p>
+<div class="highlight-text"><div class="highlight"><pre>RETQ %eax
+</pre></div>
+</div>
+<p>However, if the machine instruction has one or more explicitly defined register
+operands, the instruction’s name has to be specified after them. The example
+below shows an instance of the AArch64 <tt class="docutils literal"><span class="pre">LDPXpost</span></tt> instruction with three
+defined register operands:</p>
+<div class="highlight-text"><div class="highlight"><pre>%sp, %fp, %lr = LDPXpost %sp, 2
+</pre></div>
+</div>
+<p>The instruction names are serialized using the exact definitions from the
+target’s <tt class="docutils literal"><span class="pre">*InstrInfo.td</span></tt> files, and they are case sensitive. This means that
+similar instruction names like <tt class="docutils literal"><span class="pre">TSTri</span></tt> and <tt class="docutils literal"><span class="pre">tSTRi</span></tt> represent different
+machine instructions.</p>
+<div class="section" id="instruction-flags">
+<span id="id2"></span><h4><a class="toc-backref" href="#id24">Instruction Flags</a><a class="headerlink" href="#instruction-flags" title="Permalink to this headline">¶</a></h4>
+<p>The flag <tt class="docutils literal"><span class="pre">frame-setup</span></tt> can be specified before the instruction’s name:</p>
+<div class="highlight-text"><div class="highlight"><pre>%fp = frame-setup ADDXri %sp, 0, 0
+</pre></div>
+</div>
+</div>
+</div>
+<div class="section" id="registers">
+<span id="id3"></span><h3><a class="toc-backref" href="#id25">Registers</a><a class="headerlink" href="#registers" title="Permalink to this headline">¶</a></h3>
+<p>Registers are one of the key primitives in the machine instructions
+serialization language. They are primarly used in the
+<a class="reference internal" href="#register-operands"><em>register machine operands</em></a>,
+but they can also be used in a number of other places, like the
+<a class="reference internal" href="#bb-liveins"><em>basic block’s live in list</em></a>.</p>
+<p>The physical registers are identified by their name. They use the following
+syntax:</p>
+<div class="highlight-text"><div class="highlight"><pre>%<name>
+</pre></div>
+</div>
+<p>The example below shows three X86 physical registers:</p>
+<div class="highlight-text"><div class="highlight"><pre>%eax
+%r15
+%eflags
+</pre></div>
+</div>
+<p>The virtual registers are identified by their ID number. They use the following
+syntax:</p>
+<div class="highlight-text"><div class="highlight"><pre>%<id>
+</pre></div>
+</div>
+<p>Example:</p>
+<div class="highlight-text"><div class="highlight"><pre>%0
+</pre></div>
+</div>
+<p>The null registers are represented using an underscore (‘<tt class="docutils literal"><span class="pre">_</span></tt>‘). They can also be
+represented using a ‘<tt class="docutils literal"><span class="pre">%noreg</span></tt>‘ named register, although the former syntax
+is preferred.</p>
+</div>
+<div class="section" id="machine-operands">
+<span id="id4"></span><h3><a class="toc-backref" href="#id26">Machine Operands</a><a class="headerlink" href="#machine-operands" title="Permalink to this headline">¶</a></h3>
+<p>There are seventeen different kinds of machine operands, and all of them, except
+the <tt class="docutils literal"><span class="pre">MCSymbol</span></tt> operand, can be serialized. The <tt class="docutils literal"><span class="pre">MCSymbol</span></tt> operands are
+just printed out - they can’t be parsed back yet.</p>
+<div class="section" id="immediate-operands">
+<h4><a class="toc-backref" href="#id27">Immediate Operands</a><a class="headerlink" href="#immediate-operands" title="Permalink to this headline">¶</a></h4>
+<p>The immediate machine operands are untyped, 64-bit signed integers. The
+example below shows an instance of the X86 <tt class="docutils literal"><span class="pre">MOV32ri</span></tt> instruction that has an
+immediate machine operand <tt class="docutils literal"><span class="pre">-42</span></tt>:</p>
+<div class="highlight-text"><div class="highlight"><pre>%eax = MOV32ri -42
+</pre></div>
+</div>
+</div>
+<div class="section" id="register-operands">
+<span id="id5"></span><h4><a class="toc-backref" href="#id28">Register Operands</a><a class="headerlink" href="#register-operands" title="Permalink to this headline">¶</a></h4>
+<p>The <a class="reference internal" href="#registers"><em>register</em></a> primitive is used to represent the register
+machine operands. The register operands can also have optional
+<a class="reference internal" href="#register-flags"><em>register flags</em></a>,
+<a class="reference internal" href="#subregister-indices"><em>a subregister index</em></a>,
+and a reference to the tied register operand.
+The full syntax of a register operand is shown below:</p>
+<div class="highlight-text"><div class="highlight"><pre>[<flags>] <register> [ :<subregister-idx-name> ] [ (tied-def <tied-op>) ]
+</pre></div>
+</div>
+<p>This example shows an instance of the X86 <tt class="docutils literal"><span class="pre">XOR32rr</span></tt> instruction that has
+5 register operands with different register flags:</p>
+<div class="highlight-text"><div class="highlight"><pre>dead %eax = XOR32rr undef %eax, undef %eax, implicit-def dead %eflags, implicit-def %al
+</pre></div>
+</div>
+<div class="section" id="register-flags">
+<span id="id6"></span><h5><a class="toc-backref" href="#id29">Register Flags</a><a class="headerlink" href="#register-flags" title="Permalink to this headline">¶</a></h5>
+<p>The table below shows all of the possible register flags along with the
+corresponding internal <tt class="docutils literal"><span class="pre">llvm::RegState</span></tt> representation:</p>
+<table border="1" class="docutils">
+<colgroup>
+<col width="50%" />
+<col width="50%" />
+</colgroup>
+<thead valign="bottom">
+<tr class="row-odd"><th class="head">Flag</th>
+<th class="head">Internal Value</th>
+</tr>
+</thead>
+<tbody valign="top">
+<tr class="row-even"><td><tt class="docutils literal"><span class="pre">implicit</span></tt></td>
+<td><tt class="docutils literal"><span class="pre">RegState::Implicit</span></tt></td>
+</tr>
+<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">implicit-def</span></tt></td>
+<td><tt class="docutils literal"><span class="pre">RegState::ImplicitDefine</span></tt></td>
+</tr>
+<tr class="row-even"><td><tt class="docutils literal"><span class="pre">def</span></tt></td>
+<td><tt class="docutils literal"><span class="pre">RegState::Define</span></tt></td>
+</tr>
+<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">dead</span></tt></td>
+<td><tt class="docutils literal"><span class="pre">RegState::Dead</span></tt></td>
+</tr>
+<tr class="row-even"><td><tt class="docutils literal"><span class="pre">killed</span></tt></td>
+<td><tt class="docutils literal"><span class="pre">RegState::Kill</span></tt></td>
+</tr>
+<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">undef</span></tt></td>
+<td><tt class="docutils literal"><span class="pre">RegState::Undef</span></tt></td>
+</tr>
+<tr class="row-even"><td><tt class="docutils literal"><span class="pre">internal</span></tt></td>
+<td><tt class="docutils literal"><span class="pre">RegState::InternalRead</span></tt></td>
+</tr>
+<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">early-clobber</span></tt></td>
+<td><tt class="docutils literal"><span class="pre">RegState::EarlyClobber</span></tt></td>
+</tr>
+<tr class="row-even"><td><tt class="docutils literal"><span class="pre">debug-use</span></tt></td>
+<td><tt class="docutils literal"><span class="pre">RegState::Debug</span></tt></td>
+</tr>
+</tbody>
+</table>
+</div>
+<div class="section" id="subregister-indices">
+<span id="id7"></span><h5><a class="toc-backref" href="#id30">Subregister Indices</a><a class="headerlink" href="#subregister-indices" title="Permalink to this headline">¶</a></h5>
+<p>The register machine operands can reference a portion of a register by using
+the subregister indices. The example below shows an instance of the <tt class="docutils literal"><span class="pre">COPY</span></tt>
+pseudo instruction that uses the X86 <tt class="docutils literal"><span class="pre">sub_8bit</span></tt> subregister index to copy 8
+lower bits from the 32-bit virtual register 0 to the 8-bit virtual register 1:</p>
+<div class="highlight-text"><div class="highlight"><pre>%1 = COPY %0:sub_8bit
+</pre></div>
+</div>
+<p>The names of the subregister indices are target specific, and are typically
+defined in the target’s <tt class="docutils literal"><span class="pre">*RegisterInfo.td</span></tt> file.</p>
+</div>
+</div>
+<div class="section" id="global-value-operands">
+<h4><a class="toc-backref" href="#id31">Global Value Operands</a><a class="headerlink" href="#global-value-operands" title="Permalink to this headline">¶</a></h4>
+<p>The global value machine operands reference the global values from the
+<a class="reference internal" href="#embedded-module"><em>embedded LLVM IR module</em></a>.
+The example below shows an instance of the X86 <tt class="docutils literal"><span class="pre">MOV64rm</span></tt> instruction that has
+a global value operand named <tt class="docutils literal"><span class="pre">G</span></tt>:</p>
+<div class="highlight-text"><div class="highlight"><pre>%rax = MOV64rm %rip, 1, _, @G, _
+</pre></div>
+</div>
+<p>The named global values are represented using an identifier with the ‘@’ prefix.
+If the identifier doesn’t match the regular expression
+<cite>[-a-zA-Z$._][-a-zA-Z$._0-9]*</cite>, then this identifier must be quoted.</p>
+<p>The unnamed global values are represented using an unsigned numeric value with
+the ‘@’ prefix, like in the following examples: <tt class="docutils literal"><span class="pre">@0</span></tt>, <tt class="docutils literal"><span class="pre">@989</span></tt>.</p>
+</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="Coroutines.html" title="Coroutines in LLVM"
+             >next</a> |</li>
+        <li class="right" >
+          <a href="FaultMaps.html" title="FaultMaps and implicit checks"
+             >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-2018, LLVM Project.
+      Last updated on 2018-05-10.
+      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/5.0.2/docs/MarkedUpDisassembly.html
URL: http://llvm.org/viewvc/llvm-project/www-releases/trunk/5.0.2/docs/MarkedUpDisassembly.html?rev=331981&view=auto
==============================================================================
--- www-releases/trunk/5.0.2/docs/MarkedUpDisassembly.html (added)
+++ www-releases/trunk/5.0.2/docs/MarkedUpDisassembly.html Thu May 10 06:54:16 2018
@@ -0,0 +1,170 @@
+
+
+<!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 5 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:     '5',
+        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 5 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-text"><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-2018, LLVM Project.
+      Last updated on 2018-05-10.
+      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/5.0.2/docs/MemorySSA.html
URL: http://llvm.org/viewvc/llvm-project/www-releases/trunk/5.0.2/docs/MemorySSA.html?rev=331981&view=auto
==============================================================================
--- www-releases/trunk/5.0.2/docs/MemorySSA.html (added)
+++ www-releases/trunk/5.0.2/docs/MemorySSA.html Thu May 10 06:54:16 2018
@@ -0,0 +1,434 @@
+
+
+<!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>MemorySSA — LLVM 5 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:     '5',
+        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 5 documentation" href="index.html" />
+    <link rel="next" title="LLVM Bitcode File Format" href="BitCodeFormat.html" />
+    <link rel="prev" title="LLVM Alias Analysis Infrastructure" href="AliasAnalysis.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="BitCodeFormat.html" title="LLVM Bitcode File Format"
+             accesskey="N">next</a> |</li>
+        <li class="right" >
+          <a href="AliasAnalysis.html" title="LLVM Alias Analysis Infrastructure"
+             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="memoryssa">
+<h1>MemorySSA<a class="headerlink" href="#memoryssa" 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="#memoryssa-structure" id="id2">MemorySSA Structure</a></li>
+<li><a class="reference internal" href="#design-of-memoryssa" id="id3">Design of MemorySSA</a><ul>
+<li><a class="reference internal" href="#the-walker" id="id4">The walker</a><ul>
+<li><a class="reference internal" href="#locating-clobbers-yourself" id="id5">Locating clobbers yourself</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#build-time-use-optimization" id="id6">Build-time use optimization</a></li>
+<li><a class="reference internal" href="#invalidation-and-updating" id="id7">Invalidation and updating</a><ul>
+<li><a class="reference internal" href="#phi-placement" id="id8">Phi placement</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#non-goals" id="id9">Non-Goals</a></li>
+<li><a class="reference internal" href="#design-tradeoffs" id="id10">Design tradeoffs</a><ul>
+<li><a class="reference internal" href="#precision" id="id11">Precision</a></li>
+<li><a class="reference internal" href="#use-optimization" id="id12">Use Optimization</a></li>
+</ul>
+</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><tt class="docutils literal"><span class="pre">MemorySSA</span></tt> is an analysis that allows us to cheaply reason about the
+interactions between various memory operations. Its goal is to replace
+<tt class="docutils literal"><span class="pre">MemoryDependenceAnalysis</span></tt> for most (if not all) use-cases. This is because,
+unless you’re very careful, use of <tt class="docutils literal"><span class="pre">MemoryDependenceAnalysis</span></tt> can easily
+result in quadratic-time algorithms in LLVM. Additionally, <tt class="docutils literal"><span class="pre">MemorySSA</span></tt> doesn’t
+have as many arbitrary limits as <tt class="docutils literal"><span class="pre">MemoryDependenceAnalysis</span></tt>, so you should get
+better results, too.</p>
+<p>At a high level, one of the goals of <tt class="docutils literal"><span class="pre">MemorySSA</span></tt> is to provide an SSA based
+form for memory, complete with def-use and use-def chains, which
+enables users to quickly find may-def and may-uses of memory operations.
+It can also be thought of as a way to cheaply give versions to the complete
+state of heap memory, and associate memory operations with those versions.</p>
+<p>This document goes over how <tt class="docutils literal"><span class="pre">MemorySSA</span></tt> is structured, and some basic
+intuition on how <tt class="docutils literal"><span class="pre">MemorySSA</span></tt> works.</p>
+<p>A paper on MemorySSA (with notes about how it’s implemented in GCC) <a class="reference external" href="http://www.airs.com/dnovillo/Papers/mem-ssa.pdf">can be
+found here</a>. Though, it’s
+relatively out-of-date; the paper references multiple heap partitions, but GCC
+eventually swapped to just using one, like we now have in LLVM.  Like
+GCC’s, LLVM’s MemorySSA is intraprocedural.</p>
+</div>
+<div class="section" id="memoryssa-structure">
+<h2><a class="toc-backref" href="#id2">MemorySSA Structure</a><a class="headerlink" href="#memoryssa-structure" title="Permalink to this headline">¶</a></h2>
+<p>MemorySSA is a virtual IR. After it’s built, <tt class="docutils literal"><span class="pre">MemorySSA</span></tt> will contain a
+structure that maps <tt class="docutils literal"><span class="pre">Instruction</span></tt>s to <tt class="docutils literal"><span class="pre">MemoryAccess</span></tt>es, which are
+<tt class="docutils literal"><span class="pre">MemorySSA</span></tt>‘s parallel to LLVM <tt class="docutils literal"><span class="pre">Instruction</span></tt>s.</p>
+<p>Each <tt class="docutils literal"><span class="pre">MemoryAccess</span></tt> can be one of three types:</p>
+<ul class="simple">
+<li><tt class="docutils literal"><span class="pre">MemoryPhi</span></tt></li>
+<li><tt class="docutils literal"><span class="pre">MemoryUse</span></tt></li>
+<li><tt class="docutils literal"><span class="pre">MemoryDef</span></tt></li>
+</ul>
+<p><tt class="docutils literal"><span class="pre">MemoryPhi</span></tt>s are <tt class="docutils literal"><span class="pre">PhiNode</span></tt>s, but for memory operations. If at any
+point we have two (or more) <tt class="docutils literal"><span class="pre">MemoryDef</span></tt>s that could flow into a
+<tt class="docutils literal"><span class="pre">BasicBlock</span></tt>, the block’s top <tt class="docutils literal"><span class="pre">MemoryAccess</span></tt> will be a
+<tt class="docutils literal"><span class="pre">MemoryPhi</span></tt>. As in LLVM IR, <tt class="docutils literal"><span class="pre">MemoryPhi</span></tt>s don’t correspond to any
+concrete operation. As such, <tt class="docutils literal"><span class="pre">BasicBlock</span></tt>s are mapped to <tt class="docutils literal"><span class="pre">MemoryPhi</span></tt>s
+inside <tt class="docutils literal"><span class="pre">MemorySSA</span></tt>, whereas <tt class="docutils literal"><span class="pre">Instruction</span></tt>s are mapped to <tt class="docutils literal"><span class="pre">MemoryUse</span></tt>s
+and <tt class="docutils literal"><span class="pre">MemoryDef</span></tt>s.</p>
+<p>Note also that in SSA, Phi nodes merge must-reach definitions (that is,
+definitions that <em>must</em> be new versions of variables). In MemorySSA, PHI nodes
+merge may-reach definitions (that is, until disambiguated, the versions that
+reach a phi node may or may not clobber a given variable).</p>
+<p><tt class="docutils literal"><span class="pre">MemoryUse</span></tt>s are operations which use but don’t modify memory. An example of
+a <tt class="docutils literal"><span class="pre">MemoryUse</span></tt> is a <tt class="docutils literal"><span class="pre">load</span></tt>, or a <tt class="docutils literal"><span class="pre">readonly</span></tt> function call.</p>
+<p><tt class="docutils literal"><span class="pre">MemoryDef</span></tt>s are operations which may either modify memory, or which
+introduce some kind of ordering constraints. Examples of <tt class="docutils literal"><span class="pre">MemoryDef</span></tt>s
+include <tt class="docutils literal"><span class="pre">store</span></tt>s, function calls, <tt class="docutils literal"><span class="pre">load</span></tt>s with <tt class="docutils literal"><span class="pre">acquire</span></tt> (or higher)
+ordering, volatile operations, memory fences, etc.</p>
+<p>Every function that exists has a special <tt class="docutils literal"><span class="pre">MemoryDef</span></tt> called <tt class="docutils literal"><span class="pre">liveOnEntry</span></tt>.
+It dominates every <tt class="docutils literal"><span class="pre">MemoryAccess</span></tt> in the function that <tt class="docutils literal"><span class="pre">MemorySSA</span></tt> is being
+run on, and implies that we’ve hit the top of the function. It’s the only
+<tt class="docutils literal"><span class="pre">MemoryDef</span></tt> that maps to no <tt class="docutils literal"><span class="pre">Instruction</span></tt> in LLVM IR. Use of
+<tt class="docutils literal"><span class="pre">liveOnEntry</span></tt> implies that the memory being used is either undefined or
+defined before the function begins.</p>
+<p>An example of all of this overlaid on LLVM IR (obtained by running <tt class="docutils literal"><span class="pre">opt</span>
+<span class="pre">-passes='print<memoryssa>'</span> <span class="pre">-disable-output</span></tt> on an <tt class="docutils literal"><span class="pre">.ll</span></tt> file) is below. When
+viewing this example, it may be helpful to view it in terms of clobbers. The
+operands of a given <tt class="docutils literal"><span class="pre">MemoryAccess</span></tt> are all (potential) clobbers of said
+MemoryAccess, and the value produced by a <tt class="docutils literal"><span class="pre">MemoryAccess</span></tt> can act as a clobber
+for other <tt class="docutils literal"><span class="pre">MemoryAccess</span></tt>es. Another useful way of looking at it is in
+terms of heap versions.  In that view, operands of of a given
+<tt class="docutils literal"><span class="pre">MemoryAccess</span></tt> are the version of the heap before the operation, and
+if the access produces a value, the value is the new version of the heap
+after the operation.</p>
+<div class="highlight-llvm"><div class="highlight"><pre><span class="k">define</span> <span class="kt">void</span> <span class="vg">@foo</span><span class="p">()</span> <span class="p">{</span>
+<span class="nl">entry:</span>
+  <span class="nv">%p1</span> <span class="p">=</span> <span class="k">alloca</span> <span class="k">i8</span>
+  <span class="nv">%p2</span> <span class="p">=</span> <span class="k">alloca</span> <span class="k">i8</span>
+  <span class="nv">%p3</span> <span class="p">=</span> <span class="k">alloca</span> <span class="k">i8</span>
+  <span class="c">; 1 = MemoryDef(liveOnEntry)</span>
+  <span class="k">store</span> <span class="k">i8</span> <span class="m">0</span><span class="p">,</span> <span class="k">i8</span><span class="p">*</span> <span class="nv">%p3</span>
+  <span class="k">br</span> <span class="kt">label</span> <span class="nv">%while.cond</span>
+
+<span class="nl">while.cond:</span>
+  <span class="c">; 6 = MemoryPhi({%0,1},{if.end,4})</span>
+  <span class="k">br</span> <span class="k">i1</span> <span class="k">undef</span><span class="p">,</span> <span class="kt">label</span> <span class="nv">%if.then</span><span class="p">,</span> <span class="kt">label</span> <span class="nv">%if.else</span>
+
+<span class="nl">if.then:</span>
+  <span class="c">; 2 = MemoryDef(6)</span>
+  <span class="k">store</span> <span class="k">i8</span> <span class="m">0</span><span class="p">,</span> <span class="k">i8</span><span class="p">*</span> <span class="nv">%p1</span>
+  <span class="k">br</span> <span class="kt">label</span> <span class="nv">%if.end</span>
+
+<span class="nl">if.else:</span>
+  <span class="c">; 3 = MemoryDef(6)</span>
+  <span class="k">store</span> <span class="k">i8</span> <span class="m">1</span><span class="p">,</span> <span class="k">i8</span><span class="p">*</span> <span class="nv">%p2</span>
+  <span class="k">br</span> <span class="kt">label</span> <span class="nv">%if.end</span>
+
+<span class="nl">if.end:</span>
+  <span class="c">; 5 = MemoryPhi({if.then,2},{if.else,3})</span>
+  <span class="c">; MemoryUse(5)</span>
+  <span class="nv-Anonymous">%1</span> <span class="p">=</span> <span class="k">load</span> <span class="k">i8</span><span class="p">,</span> <span class="k">i8</span><span class="p">*</span> <span class="nv">%p1</span>
+  <span class="c">; 4 = MemoryDef(5)</span>
+  <span class="k">store</span> <span class="k">i8</span> <span class="m">2</span><span class="p">,</span> <span class="k">i8</span><span class="p">*</span> <span class="nv">%p2</span>
+  <span class="c">; MemoryUse(1)</span>
+  <span class="nv-Anonymous">%2</span> <span class="p">=</span> <span class="k">load</span> <span class="k">i8</span><span class="p">,</span> <span class="k">i8</span><span class="p">*</span> <span class="nv">%p3</span>
+  <span class="k">br</span> <span class="kt">label</span> <span class="nv">%while.cond</span>
+<span class="p">}</span>
+</pre></div>
+</div>
+<p>The <tt class="docutils literal"><span class="pre">MemorySSA</span></tt> IR is shown in comments that precede the instructions they map
+to (if such an instruction exists). For example, <tt class="docutils literal"><span class="pre">1</span> <span class="pre">=</span> <span class="pre">MemoryDef(liveOnEntry)</span></tt>
+is a <tt class="docutils literal"><span class="pre">MemoryAccess</span></tt> (specifically, a <tt class="docutils literal"><span class="pre">MemoryDef</span></tt>), and it describes the LLVM
+instruction <tt class="docutils literal"><span class="pre">store</span> <span class="pre">i8</span> <span class="pre">0,</span> <span class="pre">i8*</span> <span class="pre">%p3</span></tt>. Other places in <tt class="docutils literal"><span class="pre">MemorySSA</span></tt> refer to this
+particular <tt class="docutils literal"><span class="pre">MemoryDef</span></tt> as <tt class="docutils literal"><span class="pre">1</span></tt> (much like how one can refer to <tt class="docutils literal"><span class="pre">load</span> <span class="pre">i8,</span> <span class="pre">i8*</span>
+<span class="pre">%p1</span></tt> in LLVM with <tt class="docutils literal"><span class="pre">%1</span></tt>). Again, <tt class="docutils literal"><span class="pre">MemoryPhi</span></tt>s don’t correspond to any LLVM
+Instruction, so the line directly below a <tt class="docutils literal"><span class="pre">MemoryPhi</span></tt> isn’t special.</p>
+<p>Going from the top down:</p>
+<ul class="simple">
+<li><tt class="docutils literal"><span class="pre">6</span> <span class="pre">=</span> <span class="pre">MemoryPhi({entry,1},{if.end,4})</span></tt> notes that, when entering
+<tt class="docutils literal"><span class="pre">while.cond</span></tt>, the reaching definition for it is either <tt class="docutils literal"><span class="pre">1</span></tt> or <tt class="docutils literal"><span class="pre">4</span></tt>. This
+<tt class="docutils literal"><span class="pre">MemoryPhi</span></tt> is referred to in the textual IR by the number <tt class="docutils literal"><span class="pre">6</span></tt>.</li>
+<li><tt class="docutils literal"><span class="pre">2</span> <span class="pre">=</span> <span class="pre">MemoryDef(6)</span></tt> notes that <tt class="docutils literal"><span class="pre">store</span> <span class="pre">i8</span> <span class="pre">0,</span> <span class="pre">i8*</span> <span class="pre">%p1</span></tt> is a definition,
+and its reaching definition before it is <tt class="docutils literal"><span class="pre">6</span></tt>, or the <tt class="docutils literal"><span class="pre">MemoryPhi</span></tt> after
+<tt class="docutils literal"><span class="pre">while.cond</span></tt>. (See the <a class="reference internal" href="#build-time-use-optimization">Build-time use optimization</a> and <a class="reference internal" href="#precision">Precision</a>
+sections below for why this <tt class="docutils literal"><span class="pre">MemoryDef</span></tt> isn’t linked to a separate,
+disambiguated <tt class="docutils literal"><span class="pre">MemoryPhi</span></tt>.)</li>
+<li><tt class="docutils literal"><span class="pre">3</span> <span class="pre">=</span> <span class="pre">MemoryDef(6)</span></tt> notes that <tt class="docutils literal"><span class="pre">store</span> <span class="pre">i8</span> <span class="pre">0,</span> <span class="pre">i8*</span> <span class="pre">%p2</span></tt> is a definition; its
+reaching definition is also <tt class="docutils literal"><span class="pre">6</span></tt>.</li>
+<li><tt class="docutils literal"><span class="pre">5</span> <span class="pre">=</span> <span class="pre">MemoryPhi({if.then,2},{if.else,3})</span></tt> notes that the clobber before
+this block could either be <tt class="docutils literal"><span class="pre">2</span></tt> or <tt class="docutils literal"><span class="pre">3</span></tt>.</li>
+<li><tt class="docutils literal"><span class="pre">MemoryUse(5)</span></tt> notes that <tt class="docutils literal"><span class="pre">load</span> <span class="pre">i8,</span> <span class="pre">i8*</span> <span class="pre">%p1</span></tt> is a use of memory, and that
+it’s clobbered by <tt class="docutils literal"><span class="pre">5</span></tt>.</li>
+<li><tt class="docutils literal"><span class="pre">4</span> <span class="pre">=</span> <span class="pre">MemoryDef(5)</span></tt> notes that <tt class="docutils literal"><span class="pre">store</span> <span class="pre">i8</span> <span class="pre">2,</span> <span class="pre">i8*</span> <span class="pre">%p2</span></tt> is a definition; it’s
+reaching definition is <tt class="docutils literal"><span class="pre">5</span></tt>.</li>
+<li><tt class="docutils literal"><span class="pre">MemoryUse(1)</span></tt> notes that <tt class="docutils literal"><span class="pre">load</span> <span class="pre">i8,</span> <span class="pre">i8*</span> <span class="pre">%p3</span></tt> is just a user of memory,
+and the last thing that could clobber this use is above <tt class="docutils literal"><span class="pre">while.cond</span></tt> (e.g.
+the store to <tt class="docutils literal"><span class="pre">%p3</span></tt>). In heap versioning parlance, it really only depends on
+the heap version 1, and is unaffected by the new heap versions generated since
+then.</li>
+</ul>
+<p>As an aside, <tt class="docutils literal"><span class="pre">MemoryAccess</span></tt> is a <tt class="docutils literal"><span class="pre">Value</span></tt> mostly for convenience; it’s not
+meant to interact with LLVM IR.</p>
+</div>
+<div class="section" id="design-of-memoryssa">
+<h2><a class="toc-backref" href="#id3">Design of MemorySSA</a><a class="headerlink" href="#design-of-memoryssa" title="Permalink to this headline">¶</a></h2>
+<p><tt class="docutils literal"><span class="pre">MemorySSA</span></tt> is an analysis that can be built for any arbitrary function. When
+it’s built, it does a pass over the function’s IR in order to build up its
+mapping of <tt class="docutils literal"><span class="pre">MemoryAccess</span></tt>es. You can then query <tt class="docutils literal"><span class="pre">MemorySSA</span></tt> for things
+like the dominance relation between <tt class="docutils literal"><span class="pre">MemoryAccess</span></tt>es, and get the
+<tt class="docutils literal"><span class="pre">MemoryAccess</span></tt> for any given <tt class="docutils literal"><span class="pre">Instruction</span></tt> .</p>
+<p>When <tt class="docutils literal"><span class="pre">MemorySSA</span></tt> is done building, it also hands you a <tt class="docutils literal"><span class="pre">MemorySSAWalker</span></tt>
+that you can use (see below).</p>
+<div class="section" id="the-walker">
+<h3><a class="toc-backref" href="#id4">The walker</a><a class="headerlink" href="#the-walker" title="Permalink to this headline">¶</a></h3>
+<p>A structure that helps <tt class="docutils literal"><span class="pre">MemorySSA</span></tt> do its job is the <tt class="docutils literal"><span class="pre">MemorySSAWalker</span></tt>, or
+the walker, for short. The goal of the walker is to provide answers to clobber
+queries beyond what’s represented directly by <tt class="docutils literal"><span class="pre">MemoryAccess</span></tt>es. For example,
+given:</p>
+<div class="highlight-llvm"><div class="highlight"><pre><span class="k">define</span> <span class="kt">void</span> <span class="vg">@foo</span><span class="p">()</span> <span class="p">{</span>
+  <span class="nv">%a</span> <span class="p">=</span> <span class="k">alloca</span> <span class="k">i8</span>
+  <span class="nv">%b</span> <span class="p">=</span> <span class="k">alloca</span> <span class="k">i8</span>
+
+  <span class="c">; 1 = MemoryDef(liveOnEntry)</span>
+  <span class="k">store</span> <span class="k">i8</span> <span class="m">0</span><span class="p">,</span> <span class="k">i8</span><span class="p">*</span> <span class="nv">%a</span>
+  <span class="c">; 2 = MemoryDef(1)</span>
+  <span class="k">store</span> <span class="k">i8</span> <span class="m">0</span><span class="p">,</span> <span class="k">i8</span><span class="p">*</span> <span class="nv">%b</span>
+<span class="p">}</span>
+</pre></div>
+</div>
+<p>The store to <tt class="docutils literal"><span class="pre">%a</span></tt> is clearly not a clobber for the store to <tt class="docutils literal"><span class="pre">%b</span></tt>. It would
+be the walker’s goal to figure this out, and return <tt class="docutils literal"><span class="pre">liveOnEntry</span></tt> when queried
+for the clobber of <tt class="docutils literal"><span class="pre">MemoryAccess</span></tt> <tt class="docutils literal"><span class="pre">2</span></tt>.</p>
+<p>By default, <tt class="docutils literal"><span class="pre">MemorySSA</span></tt> provides a walker that can optimize <tt class="docutils literal"><span class="pre">MemoryDef</span></tt>s
+and <tt class="docutils literal"><span class="pre">MemoryUse</span></tt>s by consulting whatever alias analysis stack you happen to
+be using. Walkers were built to be flexible, though, so it’s entirely reasonable
+(and expected) to create more specialized walkers (e.g. one that specifically
+queries <tt class="docutils literal"><span class="pre">GlobalsAA</span></tt>, one that always stops at <tt class="docutils literal"><span class="pre">MemoryPhi</span></tt> nodes, etc).</p>
+<div class="section" id="locating-clobbers-yourself">
+<h4><a class="toc-backref" href="#id5">Locating clobbers yourself</a><a class="headerlink" href="#locating-clobbers-yourself" title="Permalink to this headline">¶</a></h4>
+<p>If you choose to make your own walker, you can find the clobber for a
+<tt class="docutils literal"><span class="pre">MemoryAccess</span></tt> by walking every <tt class="docutils literal"><span class="pre">MemoryDef</span></tt> that dominates said
+<tt class="docutils literal"><span class="pre">MemoryAccess</span></tt>. The structure of <tt class="docutils literal"><span class="pre">MemoryDef</span></tt>s makes this relatively simple;
+they ultimately form a linked list of every clobber that dominates the
+<tt class="docutils literal"><span class="pre">MemoryAccess</span></tt> that you’re trying to optimize. In other words, the
+<tt class="docutils literal"><span class="pre">definingAccess</span></tt> of a <tt class="docutils literal"><span class="pre">MemoryDef</span></tt> is always the nearest dominating
+<tt class="docutils literal"><span class="pre">MemoryDef</span></tt> or <tt class="docutils literal"><span class="pre">MemoryPhi</span></tt> of said <tt class="docutils literal"><span class="pre">MemoryDef</span></tt>.</p>
+</div>
+</div>
+<div class="section" id="build-time-use-optimization">
+<h3><a class="toc-backref" href="#id6">Build-time use optimization</a><a class="headerlink" href="#build-time-use-optimization" title="Permalink to this headline">¶</a></h3>
+<p><tt class="docutils literal"><span class="pre">MemorySSA</span></tt> will optimize some <tt class="docutils literal"><span class="pre">MemoryAccess</span></tt>es at build-time.
+Specifically, we optimize the operand of every <tt class="docutils literal"><span class="pre">MemoryUse</span></tt> to point to the
+actual clobber of said <tt class="docutils literal"><span class="pre">MemoryUse</span></tt>. This can be seen in the above example; the
+second <tt class="docutils literal"><span class="pre">MemoryUse</span></tt> in <tt class="docutils literal"><span class="pre">if.end</span></tt> has an operand of <tt class="docutils literal"><span class="pre">1</span></tt>, which is a
+<tt class="docutils literal"><span class="pre">MemoryDef</span></tt> from the entry block.  This is done to make walking,
+value numbering, etc, faster and easier.</p>
+<p>It is not possible to optimize <tt class="docutils literal"><span class="pre">MemoryDef</span></tt> in the same way, as we
+restrict <tt class="docutils literal"><span class="pre">MemorySSA</span></tt> to one heap variable and, thus, one Phi node
+per block.</p>
+</div>
+<div class="section" id="invalidation-and-updating">
+<h3><a class="toc-backref" href="#id7">Invalidation and updating</a><a class="headerlink" href="#invalidation-and-updating" title="Permalink to this headline">¶</a></h3>
+<p>Because <tt class="docutils literal"><span class="pre">MemorySSA</span></tt> keeps track of LLVM IR, it needs to be updated whenever
+the IR is updated. “Update”, in this case, includes the addition, deletion, and
+motion of <tt class="docutils literal"><span class="pre">Instructions</span></tt>. The update API is being made on an as-needed basis.
+If you’d like examples, <tt class="docutils literal"><span class="pre">GVNHoist</span></tt> is a user of <tt class="docutils literal"><span class="pre">MemorySSA</span></tt>s update API.</p>
+<div class="section" id="phi-placement">
+<h4><a class="toc-backref" href="#id8">Phi placement</a><a class="headerlink" href="#phi-placement" title="Permalink to this headline">¶</a></h4>
+<p><tt class="docutils literal"><span class="pre">MemorySSA</span></tt> only places <tt class="docutils literal"><span class="pre">MemoryPhi</span></tt>s where they’re actually
+needed. That is, it is a pruned SSA form, like LLVM’s SSA form.  For
+example, consider:</p>
+<div class="highlight-llvm"><div class="highlight"><pre><span class="k">define</span> <span class="kt">void</span> <span class="vg">@foo</span><span class="p">()</span> <span class="p">{</span>
+<span class="nl">entry:</span>
+  <span class="nv">%p1</span> <span class="p">=</span> <span class="k">alloca</span> <span class="k">i8</span>
+  <span class="nv">%p2</span> <span class="p">=</span> <span class="k">alloca</span> <span class="k">i8</span>
+  <span class="nv">%p3</span> <span class="p">=</span> <span class="k">alloca</span> <span class="k">i8</span>
+  <span class="c">; 1 = MemoryDef(liveOnEntry)</span>
+  <span class="k">store</span> <span class="k">i8</span> <span class="m">0</span><span class="p">,</span> <span class="k">i8</span><span class="p">*</span> <span class="nv">%p3</span>
+  <span class="k">br</span> <span class="kt">label</span> <span class="nv">%while.cond</span>
+
+<span class="nl">while.cond:</span>
+  <span class="c">; 3 = MemoryPhi({%0,1},{if.end,2})</span>
+  <span class="k">br</span> <span class="k">i1</span> <span class="k">undef</span><span class="p">,</span> <span class="kt">label</span> <span class="nv">%if.then</span><span class="p">,</span> <span class="kt">label</span> <span class="nv">%if.else</span>
+
+<span class="nl">if.then:</span>
+  <span class="k">br</span> <span class="kt">label</span> <span class="nv">%if.end</span>
+
+<span class="nl">if.else:</span>
+  <span class="k">br</span> <span class="kt">label</span> <span class="nv">%if.end</span>
+
+<span class="nl">if.end:</span>
+  <span class="c">; MemoryUse(1)</span>
+  <span class="nv-Anonymous">%1</span> <span class="p">=</span> <span class="k">load</span> <span class="k">i8</span><span class="p">,</span> <span class="k">i8</span><span class="p">*</span> <span class="nv">%p1</span>
+  <span class="c">; 2 = MemoryDef(3)</span>
+  <span class="k">store</span> <span class="k">i8</span> <span class="m">2</span><span class="p">,</span> <span class="k">i8</span><span class="p">*</span> <span class="nv">%p2</span>
+  <span class="c">; MemoryUse(1)</span>
+  <span class="nv-Anonymous">%2</span> <span class="p">=</span> <span class="k">load</span> <span class="k">i8</span><span class="p">,</span> <span class="k">i8</span><span class="p">*</span> <span class="nv">%p3</span>
+  <span class="k">br</span> <span class="kt">label</span> <span class="nv">%while.cond</span>
+<span class="p">}</span>
+</pre></div>
+</div>
+<p>Because we removed the stores from <tt class="docutils literal"><span class="pre">if.then</span></tt> and <tt class="docutils literal"><span class="pre">if.else</span></tt>, a <tt class="docutils literal"><span class="pre">MemoryPhi</span></tt>
+for <tt class="docutils literal"><span class="pre">if.end</span></tt> would be pointless, so we don’t place one. So, if you need to
+place a <tt class="docutils literal"><span class="pre">MemoryDef</span></tt> in <tt class="docutils literal"><span class="pre">if.then</span></tt> or <tt class="docutils literal"><span class="pre">if.else</span></tt>, you’ll need to also create
+a <tt class="docutils literal"><span class="pre">MemoryPhi</span></tt> for <tt class="docutils literal"><span class="pre">if.end</span></tt>.</p>
+<p>If it turns out that this is a large burden, we can just place <tt class="docutils literal"><span class="pre">MemoryPhi</span></tt>s
+everywhere. Because we have Walkers that are capable of optimizing above said
+phis, doing so shouldn’t prohibit optimizations.</p>
+</div>
+</div>
+<div class="section" id="non-goals">
+<h3><a class="toc-backref" href="#id9">Non-Goals</a><a class="headerlink" href="#non-goals" title="Permalink to this headline">¶</a></h3>
+<p><tt class="docutils literal"><span class="pre">MemorySSA</span></tt> is meant to reason about the relation between memory
+operations, and enable quicker querying.
+It isn’t meant to be the single source of truth for all potential memory-related
+optimizations. Specifically, care must be taken when trying to use <tt class="docutils literal"><span class="pre">MemorySSA</span></tt>
+to reason about atomic or volatile operations, as in:</p>
+<div class="highlight-llvm"><div class="highlight"><pre><span class="k">define</span> <span class="k">i8</span> <span class="vg">@foo</span><span class="p">(</span><span class="k">i8</span><span class="p">*</span> <span class="nv">%a</span><span class="p">)</span> <span class="p">{</span>
+<span class="nl">entry:</span>
+  <span class="k">br</span> <span class="k">i1</span> <span class="k">undef</span><span class="p">,</span> <span class="kt">label</span> <span class="nv">%if.then</span><span class="p">,</span> <span class="kt">label</span> <span class="nv">%if.end</span>
+
+<span class="nl">if.then:</span>
+  <span class="c">; 1 = MemoryDef(liveOnEntry)</span>
+  <span class="nv-Anonymous">%0</span> <span class="p">=</span> <span class="k">load</span> <span class="k">volatile</span> <span class="k">i8</span><span class="p">,</span> <span class="k">i8</span><span class="p">*</span> <span class="nv">%a</span>
+  <span class="k">br</span> <span class="kt">label</span> <span class="nv">%if.end</span>
+
+<span class="nl">if.end:</span>
+  <span class="nv">%av</span> <span class="p">=</span> <span class="k">phi</span> <span class="k">i8</span> <span class="p">[</span><span class="m">0</span><span class="p">,</span> <span class="nv">%entry</span><span class="p">],</span> <span class="p">[</span><span class="nv-Anonymous">%0</span><span class="p">,</span> <span class="nv">%if.then</span><span class="p">]</span>
+  <span class="k">ret</span> <span class="k">i8</span> <span class="nv">%av</span>
+<span class="p">}</span>
+</pre></div>
+</div>
+<p>Going solely by <tt class="docutils literal"><span class="pre">MemorySSA</span></tt>‘s analysis, hoisting the <tt class="docutils literal"><span class="pre">load</span></tt> to <tt class="docutils literal"><span class="pre">entry</span></tt> may
+seem legal. Because it’s a volatile load, though, it’s not.</p>
+</div>
+<div class="section" id="design-tradeoffs">
+<h3><a class="toc-backref" href="#id10">Design tradeoffs</a><a class="headerlink" href="#design-tradeoffs" title="Permalink to this headline">¶</a></h3>
+<div class="section" id="precision">
+<h4><a class="toc-backref" href="#id11">Precision</a><a class="headerlink" href="#precision" title="Permalink to this headline">¶</a></h4>
+<p><tt class="docutils literal"><span class="pre">MemorySSA</span></tt> in LLVM deliberately trades off precision for speed.
+Let us think about memory variables as if they were disjoint partitions of the
+heap (that is, if you have one variable, as above, it represents the entire
+heap, and if you have multiple variables, each one represents some
+disjoint portion of the heap)</p>
+<p>First, because alias analysis results conflict with each other, and
+each result may be what an analysis wants (IE
+TBAA may say no-alias, and something else may say must-alias), it is
+not possible to partition the heap the way every optimization wants.
+Second, some alias analysis results are not transitive (IE A noalias B,
+and B noalias C, does not mean A noalias C), so it is not possible to
+come up with a precise partitioning in all cases without variables to
+represent every pair of possible aliases.  Thus, partitioning
+precisely may require introducing at least N^2 new virtual variables,
+phi nodes, etc.</p>
+<p>Each of these variables may be clobbered at multiple def sites.</p>
+<p>To give an example, if you were to split up struct fields into
+individual variables, all aliasing operations that may-def multiple struct
+fields, will may-def more than one of them.  This is pretty common (calls,
+copies, field stores, etc).</p>
+<p>Experience with SSA forms for memory in other compilers has shown that
+it is simply not possible to do this precisely, and in fact, doing it
+precisely is not worth it, because now all the optimizations have to
+walk tons and tons of virtual variables and phi nodes.</p>
+<p>So we partition.  At the point at which you partition, again,
+experience has shown us there is no point in partitioning to more than
+one variable.  It simply generates more IR, and optimizations still
+have to query something to disambiguate further anyway.</p>
+<p>As a result, LLVM partitions to one variable.</p>
+</div>
+<div class="section" id="use-optimization">
+<h4><a class="toc-backref" href="#id12">Use Optimization</a><a class="headerlink" href="#use-optimization" title="Permalink to this headline">¶</a></h4>
+<p>Unlike other partitioned forms, LLVM’s <tt class="docutils literal"><span class="pre">MemorySSA</span></tt> does make one
+useful guarantee - all loads are optimized to point at the thing that
+actually clobbers them. This gives some nice properties.  For example,
+for a given store, you can find all loads actually clobbered by that
+store by walking the immediate uses of the store.</p>
+</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="BitCodeFormat.html" title="LLVM Bitcode File Format"
+             >next</a> |</li>
+        <li class="right" >
+          <a href="AliasAnalysis.html" title="LLVM Alias Analysis Infrastructure"
+             >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-2018, LLVM Project.
+      Last updated on 2018-05-10.
+      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/5.0.2/docs/MergeFunctions.html
URL: http://llvm.org/viewvc/llvm-project/www-releases/trunk/5.0.2/docs/MergeFunctions.html?rev=331981&view=auto
==============================================================================
--- www-releases/trunk/5.0.2/docs/MergeFunctions.html (added)
+++ www-releases/trunk/5.0.2/docs/MergeFunctions.html Thu May 10 06:54:16 2018
@@ -0,0 +1,820 @@
+
+
+<!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 5 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:     '5',
+        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 5 documentation" href="index.html" />
+    <link rel="next" title="Type Metadata" href="TypeMetadata.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="TypeMetadata.html" title="Type Metadata"
+             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/LangImpl03.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-text"><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-text"><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-text"><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="n">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, that’s
+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="TypeMetadata.html" title="Type Metadata"
+             >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-2018, LLVM Project.
+      Last updated on 2018-05-10.
+      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/5.0.2/docs/NVPTXUsage.html
URL: http://llvm.org/viewvc/llvm-project/www-releases/trunk/5.0.2/docs/NVPTXUsage.html?rev=331981&view=auto
==============================================================================
--- www-releases/trunk/5.0.2/docs/NVPTXUsage.html (added)
+++ www-releases/trunk/5.0.2/docs/NVPTXUsage.html Thu May 10 06:54:16 2018
@@ -0,0 +1,1061 @@
+
+
+<!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 5 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:     '5',
+        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 5 documentation" href="index.html" />
+    <link rel="next" title="User Guide for AMDGPU Backend" 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 Backend"
+             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>
+</ul>
+</li>
+<li><a class="reference internal" href="#executing-ptx" id="id27">Executing PTX</a></li>
+<li><a class="reference internal" href="#common-issues" id="id28">Common Issues</a><ul>
+<li><a class="reference internal" href="#ptxas-complains-of-undefined-function-nvvm-reflect" id="id29">ptxas complains of undefined function: __nvvm_reflect</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#tutorial-a-simple-compute-kernel" id="id30">Tutorial: A Simple Compute Kernel</a><ul>
+<li><a class="reference internal" href="#the-kernel" id="id31">The Kernel</a></li>
+<li><a class="reference internal" href="#dissecting-the-kernel" id="id32">Dissecting the Kernel</a><ul>
+<li><a class="reference internal" href="#data-layout" id="id33">Data Layout</a></li>
+<li><a class="reference internal" href="#target-intrinsics" id="id34">Target Intrinsics</a></li>
+<li><a class="reference internal" href="#id10" id="id35">Address Spaces</a></li>
+<li><a class="reference internal" href="#kernel-metadata" id="id36">Kernel Metadata</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#running-the-kernel" id="id37">Running the Kernel</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#tutorial-linking-with-libdevice" id="id38">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-text"><div class="highlight"><pre>!0 = !{<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="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="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="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="n">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>
+<p>The NVPTX TargetMachine knows how to schedule <tt class="docutils literal"><span class="pre">NVVMReflect</span></tt> at the beginning
+of your pass manager; just use the following code when setting up your pass
+manager:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">std</span><span class="o">::</span><span class="n">unique_ptr</span><span class="o"><</span><span class="n">TargetMachine</span><span class="o">></span> <span class="n">TM</span> <span class="o">=</span> <span class="p">...;</span>
+<span class="n">PassManagerBuilder</span> <span class="n">PMBuilder</span><span class="p">(...);</span>
+<span class="k">if</span> <span class="p">(</span><span class="n">TM</span><span class="p">)</span>
+  <span class="n">TM</span><span class="o">-></span><span class="n">adjustPassManager</span><span class="p">(</span><span class="n">PMBuilder</span><span class="p">);</span>
+</pre></div>
+</div>
+<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>
+<p>The value of this flag is determined by the “nvvm-reflect-ftz” module flag.
+The following sets the ftz flag to 1.</p>
+<div class="highlight-llvm"><div class="highlight"><pre><span class="nv">!llvm.module.flag</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="p">!{</span><span class="k">i32</span> <span class="m">4</span><span class="p">,</span> <span class="nv">!"nvvm-reflect-ftz"</span><span class="p">,</span> <span class="k">i32</span> <span class="m">1</span><span class="p">}</span>
+</pre></div>
+</div>
+<p>(<tt class="docutils literal"><span class="pre">i32</span> <span class="pre">4</span></tt> indicates that the value set here overrides the value in another
+module we link with.  See the <cite>LangRef <LangRef.html#module-flags-metadata></cite>
+for details.)</p>
+</div>
+</div>
+<div class="section" id="executing-ptx">
+<h2><a class="toc-backref" href="#id27">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">function</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="#id28">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="#id29">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="#id30">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="#id31">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="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="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="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="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="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="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="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">%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="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">%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="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="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="#id32">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="#id33">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="#id34">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.nvvm.barrier0()</span></tt></td>
+<td>__syncthreads()</td>
+</tr>
+</tbody>
+</table>
+</div>
+<div class="section" id="id10">
+<h4><a class="toc-backref" href="#id35">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="#id36">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>!{<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="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="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="#id37">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="n">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="n">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="#id38">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="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="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="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="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="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="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="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">%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="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">%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="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="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 Backend"
+             >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-2018, LLVM Project.
+      Last updated on 2018-05-10.
+      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/5.0.2/docs/OptBisect.html
URL: http://llvm.org/viewvc/llvm-project/www-releases/trunk/5.0.2/docs/OptBisect.html?rev=331981&view=auto
==============================================================================
--- www-releases/trunk/5.0.2/docs/OptBisect.html (added)
+++ www-releases/trunk/5.0.2/docs/OptBisect.html Thu May 10 06:54:16 2018
@@ -0,0 +1,263 @@
+
+
+<!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>Using -opt-bisect-limit to debug optimization errors — LLVM 5 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:     '5',
+        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 5 documentation" href="index.html" />
+    <link rel="next" title="LLVM Alias Analysis Infrastructure" href="AliasAnalysis.html" />
+    <link rel="prev" title="Scudo Hardened Allocator" href="ScudoHardenedAllocator.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="AliasAnalysis.html" title="LLVM Alias Analysis Infrastructure"
+             accesskey="N">next</a> |</li>
+        <li class="right" >
+          <a href="ScudoHardenedAllocator.html" title="Scudo Hardened Allocator"
+             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="using-opt-bisect-limit-to-debug-optimization-errors">
+<h1>Using -opt-bisect-limit to debug optimization errors<a class="headerlink" href="#using-opt-bisect-limit-to-debug-optimization-errors" 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="#getting-started" id="id2">Getting Started</a></li>
+<li><a class="reference internal" href="#bisection-index-values" id="id3">Bisection Index Values</a></li>
+<li><a class="reference internal" href="#example-usage" id="id4">Example Usage</a></li>
+<li><a class="reference internal" href="#pass-skipping-implementation" id="id5">Pass Skipping Implementation</a></li>
+<li><a class="reference internal" href="#adding-finer-granularity" id="id6">Adding Finer Granularity</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>The -opt-bisect-limit option provides a way to disable all optimization passes
+above a specified limit without modifying the way in which the Pass Managers
+are populated.  The intention of this option is to assist in tracking down
+problems where incorrect transformations during optimization result in incorrect
+run-time behavior.</p>
+<p>This feature is implemented on an opt-in basis.  Passes which can be safely
+skipped while still allowing correct code generation call a function to
+check the opt-bisect limit before performing optimizations.  Passes which
+either must be run or do not modify the IR do not perform this check and are
+therefore never skipped.  Generally, this means analysis passes, passes
+that are run at CodeGenOpt::None and passes which are required for register
+allocation.</p>
+<p>The -opt-bisect-limit option can be used with any tool, including front ends
+such as clang, that uses the core LLVM library for optimization and code
+generation.  The exact syntax for invoking the option is discussed below.</p>
+<p>This feature is not intended to replace other debugging tools such as bugpoint.
+Rather it provides an alternate course of action when reproducing the problem
+requires a complex build infrastructure that would make using bugpoint
+impractical or when reproducing the failure requires a sequence of
+transformations that is difficult to replicate with tools like opt and llc.</p>
+</div>
+<div class="section" id="getting-started">
+<h2><a class="toc-backref" href="#id2">Getting Started</a><a class="headerlink" href="#getting-started" title="Permalink to this headline">¶</a></h2>
+<p>The -opt-bisect-limit command line option can be passed directly to tools such
+as opt, llc and lli.  The syntax is as follows:</p>
+<div class="highlight-python"><pre><tool name> [other options] -opt-bisect-limit=<limit></pre>
+</div>
+<p>If a value of -1 is used the tool will perform all optimizations but a message
+will be printed to stderr for each optimization that could be skipped
+indicating the index value that is associated with that optimization.  To skip
+optimizations, pass the value of the last optimization to be performed as the
+opt-bisect-limit.  All optimizations with a higher index value will be skipped.</p>
+<p>In order to use the -opt-bisect-limit option with a driver that provides a
+wrapper around the LLVM core library, an additional prefix option may be
+required, as defined by the driver.  For example, to use this option with
+clang, the “-mllvm” prefix must be used.  A typical clang invocation would look
+like this:</p>
+<div class="highlight-python"><pre>clang -O2 -mllvm -opt-bisect-limit=256 my_file.c</pre>
+</div>
+<p>The -opt-bisect-limit option may also be applied to link-time optimizations by
+using a prefix to indicate that this is a plug-in option for the linker. The
+following syntax will set a bisect limit for LTO transformations:</p>
+<div class="highlight-python"><pre># When using lld, or ld64 (macOS)
+clang -flto -Wl,-mllvm,-opt-bisect-limit=256 my_file.o my_other_file.o
+# When using Gold
+clang -flto -Wl,-plugin-opt,-opt-bisect-limit=256 my_file.o my_other_file.o</pre>
+</div>
+<p>LTO passes are run by a library instance invoked by the linker. Therefore any
+passes run in the primary driver compilation phase are not affected by options
+passed via ‘-Wl,-plugin-opt’ and LTO passes are not affected by options
+passed to the driver-invoked LLVM invocation via ‘-mllvm’.</p>
+</div>
+<div class="section" id="bisection-index-values">
+<h2><a class="toc-backref" href="#id3">Bisection Index Values</a><a class="headerlink" href="#bisection-index-values" title="Permalink to this headline">¶</a></h2>
+<p>The granularity of the optimizations associated with a single index value is
+variable.  Depending on how the optimization pass has been instrumented the
+value may be associated with as much as all transformations that would have
+been performed by an optimization pass on an IR unit for which it is invoked
+(for instance, during a single call of runOnFunction for a FunctionPass) or as
+little as a single transformation. The index values may also be nested so that
+if an invocation of the pass is not skipped individual transformations within
+that invocation may still be skipped.</p>
+<p>The order of the values assigned is guaranteed to remain stable and consistent
+from one run to the next up to and including the value specified as the limit.
+Above the limit value skipping of optimizations can cause a change in the
+numbering, but because all optimizations above the limit are skipped this
+is not a problem.</p>
+<p>When an opt-bisect index value refers to an entire invocation of the run
+function for a pass, the pass will query whether or not it should be skipped
+each time it is invoked and each invocation will be assigned a unique value.
+For example, if a FunctionPass is used with a module containing three functions
+a different index value will be assigned to the pass for each of the functions
+as the pass is run. The pass may be run on two functions but skipped for the
+third.</p>
+<p>If the pass internally performs operations on a smaller IR unit the pass must be
+specifically instrumented to enable bisection at this finer level of granularity
+(see below for details).</p>
+</div>
+<div class="section" id="example-usage">
+<h2><a class="toc-backref" href="#id4">Example Usage</a><a class="headerlink" href="#example-usage" title="Permalink to this headline">¶</a></h2>
+<div class="highlight-console"><div class="highlight"><pre><span class="gp">$</span> opt -O2 -o <span class="nb">test</span>-opt.bc -opt-bisect-limit<span class="o">=</span>16 test.ll
+
+<span class="go">BISECT: running pass (1) Simplify the CFG on function (g)</span>
+<span class="go">BISECT: running pass (2) SROA on function (g)</span>
+<span class="go">BISECT: running pass (3) Early CSE on function (g)</span>
+<span class="go">BISECT: running pass (4) Infer set function attributes on module (test.ll)</span>
+<span class="go">BISECT: running pass (5) Interprocedural Sparse Conditional Constant Propagation on module (test.ll)</span>
+<span class="go">BISECT: running pass (6) Global Variable Optimizer on module (test.ll)</span>
+<span class="go">BISECT: running pass (7) Promote Memory to Register on function (g)</span>
+<span class="go">BISECT: running pass (8) Dead Argument Elimination on module (test.ll)</span>
+<span class="go">BISECT: running pass (9) Combine redundant instructions on function (g)</span>
+<span class="go">BISECT: running pass (10) Simplify the CFG on function (g)</span>
+<span class="go">BISECT: running pass (11) Remove unused exception handling info on SCC (<<null function>>)</span>
+<span class="go">BISECT: running pass (12) Function Integration/Inlining on SCC (<<null function>>)</span>
+<span class="go">BISECT: running pass (13) Deduce function attributes on SCC (<<null function>>)</span>
+<span class="go">BISECT: running pass (14) Remove unused exception handling info on SCC (f)</span>
+<span class="go">BISECT: running pass (15) Function Integration/Inlining on SCC (f)</span>
+<span class="go">BISECT: running pass (16) Deduce function attributes on SCC (f)</span>
+<span class="go">BISECT: NOT running pass (17) Remove unused exception handling info on SCC (g)</span>
+<span class="go">BISECT: NOT running pass (18) Function Integration/Inlining on SCC (g)</span>
+<span class="go">BISECT: NOT running pass (19) Deduce function attributes on SCC (g)</span>
+<span class="go">BISECT: NOT running pass (20) SROA on function (g)</span>
+<span class="go">BISECT: NOT running pass (21) Early CSE on function (g)</span>
+<span class="go">BISECT: NOT running pass (22) Speculatively execute instructions if target has divergent branches on function (g)</span>
+<span class="go">... etc. ...</span>
+</pre></div>
+</div>
+</div>
+<div class="section" id="pass-skipping-implementation">
+<h2><a class="toc-backref" href="#id5">Pass Skipping Implementation</a><a class="headerlink" href="#pass-skipping-implementation" title="Permalink to this headline">¶</a></h2>
+<p>The -opt-bisect-limit implementation depends on individual passes opting in to
+the opt-bisect process.  The OptBisect object that manages the process is
+entirely passive and has no knowledge of how any pass is implemented.  When a
+pass is run if the pass may be skipped, it should call the OptBisect object to
+see if it should be skipped.</p>
+<p>The OptBisect object is intended to be accessed through LLVMContext and each
+Pass base class contains a helper function that abstracts the details in order
+to make this check uniform across all passes.  These helper functions are:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="kt">bool</span> <span class="n">ModulePass</span><span class="o">::</span><span class="n">skipModule</span><span class="p">(</span><span class="n">Module</span> <span class="o">&</span><span class="n">M</span><span class="p">);</span>
+<span class="kt">bool</span> <span class="n">CallGraphSCCPass</span><span class="o">::</span><span class="n">skipSCC</span><span class="p">(</span><span class="n">CallGraphSCC</span> <span class="o">&</span><span class="n">SCC</span><span class="p">);</span>
+<span class="kt">bool</span> <span class="n">FunctionPass</span><span class="o">::</span><span class="n">skipFunction</span><span class="p">(</span><span class="k">const</span> <span class="n">Function</span> <span class="o">&</span><span class="n">F</span><span class="p">);</span>
+<span class="kt">bool</span> <span class="n">BasicBlockPass</span><span class="o">::</span><span class="n">skipBasicBlock</span><span class="p">(</span><span class="k">const</span> <span class="n">BasicBlock</span> <span class="o">&</span><span class="n">BB</span><span class="p">);</span>
+<span class="kt">bool</span> <span class="n">LoopPass</span><span class="o">::</span><span class="n">skipLoop</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>
+</pre></div>
+</div>
+<p>A MachineFunctionPass should use FunctionPass::skipFunction() as such:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="kt">bool</span> <span class="n">MyMachineFunctionPass</span><span class="o">::</span><span class="n">runOnMachineFunction</span><span class="p">(</span><span class="n">Function</span> <span class="o">&</span><span class="n">MF</span><span class="p">)</span> <span class="p">{</span>
+  <span class="k">if</span> <span class="p">(</span><span class="n">skipFunction</span><span class="p">(</span><span class="o">*</span><span class="n">MF</span><span class="p">.</span><span class="n">getFunction</span><span class="p">())</span>
+        <span class="k">return</span> <span class="kc">false</span><span class="p">;</span>
+  <span class="c1">// Otherwise, run the pass normally.</span>
+<span class="p">}</span>
+</pre></div>
+</div>
+<p>In addition to checking with the OptBisect class to see if the pass should be
+skipped, the skipFunction(), skipLoop() and skipBasicBlock() helper functions
+also look for the presence of the “optnone” function attribute.  The calling
+pass will be unable to determine whether it is being skipped because the
+“optnone” attribute is present or because the opt-bisect-limit has been
+reached.  This is desirable because the behavior should be the same in either
+case.</p>
+<p>The majority of LLVM passes which can be skipped have already been instrumented
+in the manner described above.  If you are adding a new pass or believe you
+have found a pass which is not being included in the opt-bisect process but
+should be, you can add it as described above.</p>
+</div>
+<div class="section" id="adding-finer-granularity">
+<h2><a class="toc-backref" href="#id6">Adding Finer Granularity</a><a class="headerlink" href="#adding-finer-granularity" title="Permalink to this headline">¶</a></h2>
+<p>Once the pass in which an incorrect transformation is performed has been
+determined, it may be useful to perform further analysis in order to determine
+which specific transformation is causing the problem.  Debug counters
+can be used for this purpose.</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="AliasAnalysis.html" title="LLVM Alias Analysis Infrastructure"
+             >next</a> |</li>
+        <li class="right" >
+          <a href="ScudoHardenedAllocator.html" title="Scudo Hardened Allocator"
+             >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-2018, LLVM Project.
+      Last updated on 2018-05-10.
+      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/5.0.2/docs/PDB/CodeViewSymbols.html
URL: http://llvm.org/viewvc/llvm-project/www-releases/trunk/5.0.2/docs/PDB/CodeViewSymbols.html?rev=331981&view=auto
==============================================================================
--- www-releases/trunk/5.0.2/docs/PDB/CodeViewSymbols.html (added)
+++ www-releases/trunk/5.0.2/docs/PDB/CodeViewSymbols.html Thu May 10 06:54:16 2018
@@ -0,0 +1,102 @@
+
+
+<!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>CodeView Symbol Records — LLVM 5 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:     '5',
+        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 5 documentation" href="../index.html" />
+    <link rel="up" title="The PDB File Format" href="index.html" />
+    <link rel="next" title="CodeView Type Records" href="CodeViewTypes.html" />
+    <link rel="prev" title="The TPI & IPI Hash Streams" href="HashStream.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="CodeViewTypes.html" title="CodeView Type Records"
+             accesskey="N">next</a> |</li>
+        <li class="right" >
+          <a href="HashStream.html" title="The TPI & IPI Hash Streams"
+             accesskey="P">previous</a> |</li>
+  <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+  <li><a href="../index.html">Documentation</a>»</li>
+
+          <li><a href="index.html" accesskey="U">The PDB File Format</a> »</li> 
+      </ul>
+    </div>
+
+
+    <div class="document">
+      <div class="documentwrapper">
+          <div class="body">
+            
+  <div class="section" id="codeview-symbol-records">
+<h1>CodeView Symbol Records<a class="headerlink" href="#codeview-symbol-records" title="Permalink to this headline">¶</a></h1>
+</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="CodeViewTypes.html" title="CodeView Type Records"
+             >next</a> |</li>
+        <li class="right" >
+          <a href="HashStream.html" title="The TPI & IPI Hash Streams"
+             >previous</a> |</li>
+  <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+  <li><a href="../index.html">Documentation</a>»</li>
+
+          <li><a href="index.html" >The PDB File Format</a> »</li> 
+      </ul>
+    </div>
+    <div class="footer">
+        © Copyright 2003-2018, LLVM Project.
+      Last updated on 2018-05-10.
+      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/5.0.2/docs/PDB/CodeViewTypes.html
URL: http://llvm.org/viewvc/llvm-project/www-releases/trunk/5.0.2/docs/PDB/CodeViewTypes.html?rev=331981&view=auto
==============================================================================
--- www-releases/trunk/5.0.2/docs/PDB/CodeViewTypes.html (added)
+++ www-releases/trunk/5.0.2/docs/PDB/CodeViewTypes.html Thu May 10 06:54:16 2018
@@ -0,0 +1,102 @@
+
+
+<!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>CodeView Type Records — LLVM 5 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:     '5',
+        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 5 documentation" href="../index.html" />
+    <link rel="up" title="The PDB File Format" href="index.html" />
+    <link rel="next" title="LLVM Developer Policy" href="../DeveloperPolicy.html" />
+    <link rel="prev" title="CodeView Symbol Records" href="CodeViewSymbols.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="../DeveloperPolicy.html" title="LLVM Developer Policy"
+             accesskey="N">next</a> |</li>
+        <li class="right" >
+          <a href="CodeViewSymbols.html" title="CodeView Symbol Records"
+             accesskey="P">previous</a> |</li>
+  <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+  <li><a href="../index.html">Documentation</a>»</li>
+
+          <li><a href="index.html" accesskey="U">The PDB File Format</a> »</li> 
+      </ul>
+    </div>
+
+
+    <div class="document">
+      <div class="documentwrapper">
+          <div class="body">
+            
+  <div class="section" id="codeview-type-records">
+<h1>CodeView Type Records<a class="headerlink" href="#codeview-type-records" title="Permalink to this headline">¶</a></h1>
+</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="../DeveloperPolicy.html" title="LLVM Developer Policy"
+             >next</a> |</li>
+        <li class="right" >
+          <a href="CodeViewSymbols.html" title="CodeView Symbol Records"
+             >previous</a> |</li>
+  <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+  <li><a href="../index.html">Documentation</a>»</li>
+
+          <li><a href="index.html" >The PDB File Format</a> »</li> 
+      </ul>
+    </div>
+    <div class="footer">
+        © Copyright 2003-2018, LLVM Project.
+      Last updated on 2018-05-10.
+      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/5.0.2/docs/PDB/DbiStream.html
URL: http://llvm.org/viewvc/llvm-project/www-releases/trunk/5.0.2/docs/PDB/DbiStream.html?rev=331981&view=auto
==============================================================================
--- www-releases/trunk/5.0.2/docs/PDB/DbiStream.html (added)
+++ www-releases/trunk/5.0.2/docs/PDB/DbiStream.html Thu May 10 06:54:16 2018
@@ -0,0 +1,479 @@
+
+
+<!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>The PDB DBI (Debug Info) Stream — LLVM 5 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:     '5',
+        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 5 documentation" href="../index.html" />
+    <link rel="up" title="The PDB File Format" href="index.html" />
+    <link rel="next" title="The Module Information Stream" href="ModiStream.html" />
+    <link rel="prev" title="The PDB TPI Stream" href="TpiStream.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="ModiStream.html" title="The Module Information Stream"
+             accesskey="N">next</a> |</li>
+        <li class="right" >
+          <a href="TpiStream.html" title="The PDB TPI Stream"
+             accesskey="P">previous</a> |</li>
+  <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+  <li><a href="../index.html">Documentation</a>»</li>
+
+          <li><a href="index.html" accesskey="U">The PDB File Format</a> »</li> 
+      </ul>
+    </div>
+
+
+    <div class="document">
+      <div class="documentwrapper">
+          <div class="body">
+            
+  <div class="section" id="the-pdb-dbi-debug-info-stream">
+<h1>The PDB DBI (Debug Info) Stream<a class="headerlink" href="#the-pdb-dbi-debug-info-stream" 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="#stream-header" id="id2">Stream Header</a></li>
+<li><a class="reference internal" href="#substreams" id="id3">Substreams</a><ul>
+<li><a class="reference internal" href="#module-info-substream" id="id4">Module Info Substream</a></li>
+<li><a class="reference internal" href="#section-contribution-substream" id="id5">Section Contribution Substream</a></li>
+<li><a class="reference internal" href="#section-map-substream" id="id6">Section Map Substream</a></li>
+<li><a class="reference internal" href="#file-info-substream" id="id7">File Info Substream</a></li>
+<li><a class="reference internal" href="#type-server-substream" id="id8">Type Server Substream</a></li>
+<li><a class="reference internal" href="#ec-substream" id="id9">EC Substream</a></li>
+<li><a class="reference internal" href="#optional-debug-header-stream" id="id10">Optional Debug Header Stream</a></li>
+</ul>
+</li>
+</ul>
+</div>
+<div class="section" id="introduction">
+<span id="dbi-intro"></span><h2><a class="toc-backref" href="#id1">Introduction</a><a class="headerlink" href="#introduction" title="Permalink to this headline">¶</a></h2>
+<p>The PDB DBI Stream (Index 3) is one of the largest and most important streams
+in a PDB file.  It contains information about how the program was compiled,
+(e.g. compilation flags, etc), the compilands (e.g. object files) that
+were used to link together the program, the source files which were used
+to build the program, as well as references to other streams that contain more
+detailed information about each compiland, such as the CodeView symbol records
+contained within each compiland and the source and line information for
+functions and other symbols within each compiland.</p>
+</div>
+<div class="section" id="stream-header">
+<span id="dbi-header"></span><h2><a class="toc-backref" href="#id2">Stream Header</a><a class="headerlink" href="#stream-header" title="Permalink to this headline">¶</a></h2>
+<p>At offset 0 of the DBI Stream is a header with the following layout:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="k">struct</span> <span class="n">DbiStreamHeader</span> <span class="p">{</span>
+  <span class="n">int32_t</span> <span class="n">VersionSignature</span><span class="p">;</span>
+  <span class="n">uint32_t</span> <span class="n">VersionHeader</span><span class="p">;</span>
+  <span class="n">uint32_t</span> <span class="n">Age</span><span class="p">;</span>
+  <span class="n">uint16_t</span> <span class="n">GlobalStreamIndex</span><span class="p">;</span>
+  <span class="n">uint16_t</span> <span class="n">BuildNumber</span><span class="p">;</span>
+  <span class="n">uint16_t</span> <span class="n">PublicStreamIndex</span><span class="p">;</span>
+  <span class="n">uint16_t</span> <span class="n">PdbDllVersion</span><span class="p">;</span>
+  <span class="n">uint16_t</span> <span class="n">SymRecordStream</span><span class="p">;</span>
+  <span class="n">uint16_t</span> <span class="n">PdbDllRbld</span><span class="p">;</span>
+  <span class="n">int32_t</span> <span class="n">ModInfoSize</span><span class="p">;</span>
+  <span class="n">int32_t</span> <span class="n">SectionContributionSize</span><span class="p">;</span>
+  <span class="n">int32_t</span> <span class="n">SectionMapSize</span><span class="p">;</span>
+  <span class="n">int32_t</span> <span class="n">SourceInfoSize</span><span class="p">;</span>
+  <span class="n">int32_t</span> <span class="n">TypeServerSize</span><span class="p">;</span>
+  <span class="n">uint32_t</span> <span class="n">MFCTypeServerIndex</span><span class="p">;</span>
+  <span class="n">int32_t</span> <span class="n">OptionalDbgHeaderSize</span><span class="p">;</span>
+  <span class="n">int32_t</span> <span class="n">ECSubstreamSize</span><span class="p">;</span>
+  <span class="n">uint16_t</span> <span class="n">Flags</span><span class="p">;</span>
+  <span class="n">uint16_t</span> <span class="n">Machine</span><span class="p">;</span>
+  <span class="n">uint32_t</span> <span class="n">Padding</span><span class="p">;</span>
+<span class="p">};</span>
+</pre></div>
+</div>
+<ul class="simple">
+<li><strong>VersionSignature</strong> - Unknown meaning.  Appears to always be <tt class="docutils literal"><span class="pre">-1</span></tt>.</li>
+<li><strong>VersionHeader</strong> - A value from the following enum.</li>
+</ul>
+<div class="highlight-c++"><div class="highlight"><pre><span class="k">enum</span> <span class="k">class</span> <span class="nc">DbiStreamVersion</span> <span class="o">:</span> <span class="n">uint32_t</span> <span class="p">{</span>
+  <span class="n">VC41</span> <span class="o">=</span> <span class="mi">930803</span><span class="p">,</span>
+  <span class="n">V50</span> <span class="o">=</span> <span class="mi">19960307</span><span class="p">,</span>
+  <span class="n">V60</span> <span class="o">=</span> <span class="mi">19970606</span><span class="p">,</span>
+  <span class="n">V70</span> <span class="o">=</span> <span class="mi">19990903</span><span class="p">,</span>
+  <span class="n">V110</span> <span class="o">=</span> <span class="mi">20091201</span>
+<span class="p">};</span>
+</pre></div>
+</div>
+<p>Similar to the <a class="reference internal" href="PdbStream.html"><em>PDB Stream</em></a>, this value always appears to be
+<tt class="docutils literal"><span class="pre">V70</span></tt>, and it is not clear what the other values are for.</p>
+<ul class="simple">
+<li><strong>Age</strong> - The number of times the PDB has been written.  Equal to the same
+field from the <a class="reference internal" href="PdbStream.html#pdb-stream-header"><em>PDB Stream header</em></a>.</li>
+<li><strong>GlobalStreamIndex</strong> - The index of the <a class="reference internal" href="GlobalStream.html"><em>Global Symbol Stream</em></a>,
+which contains CodeView symbol records for all global symbols.  Actual records
+are stored in the symbol record stream, and are referenced from this stream.</li>
+<li><strong>BuildNumber</strong> - A bitfield containing values representing the major and minor
+version number of the toolchain (e.g. 12.0 for MSVC 2013) used to build the
+program, with the following layout:</li>
+</ul>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">uint16_t</span> <span class="n">MinorVersion</span> <span class="o">:</span> <span class="mi">8</span><span class="p">;</span>
+<span class="n">uint16_t</span> <span class="n">MajorVersion</span> <span class="o">:</span> <span class="mi">7</span><span class="p">;</span>
+<span class="n">uint16_t</span> <span class="n">NewVersionFormat</span> <span class="o">:</span> <span class="mi">1</span><span class="p">;</span>
+</pre></div>
+</div>
+<p>For the purposes of LLVM, we assume <tt class="docutils literal"><span class="pre">NewVersionFormat</span></tt> to be always <tt class="docutils literal"><span class="pre">true</span></tt>.
+If it is <tt class="docutils literal"><span class="pre">false</span></tt>, the layout above does not apply and the reader should consult
+the <a class="reference external" href="https://github.com/Microsoft/microsoft-pdb">Microsoft Source Code</a> for
+further guidance.</p>
+<ul class="simple">
+<li><strong>PublicStreamIndex</strong> - The index of the <a class="reference internal" href="PublicStream.html"><em>Public Symbol Stream</em></a>,
+which contains CodeView symbol records for all public symbols.  Actual records
+are stored in the symbol record stream, and are referenced from this stream.</li>
+<li><strong>PdbDllVersion</strong> - The version number of <tt class="docutils literal"><span class="pre">mspdbXXXX.dll</span></tt> used to produce this
+PDB.  Note this obviously does not apply for LLVM as LLVM does not use <tt class="docutils literal"><span class="pre">mspdb.dll</span></tt>.</li>
+<li><strong>SymRecordStream</strong> - The stream containing all CodeView symbol records used
+by the program.  This is used for deduplication, so that many different
+compilands can refer to the same symbols without having to include the full record
+content inside of each module stream.</li>
+<li><strong>PdbDllRbld</strong> - Unknown</li>
+<li><strong>MFCTypeServerIndex</strong> - The length of the :ref:dbi_mfc_type_server_substream</li>
+<li><strong>Flags</strong> - A bitfield with the following layout, containing various
+information about how the program was built:</li>
+</ul>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">uint16_t</span> <span class="n">WasIncrementallyLinked</span> <span class="o">:</span> <span class="mi">1</span><span class="p">;</span>
+<span class="n">uint16_t</span> <span class="n">ArePrivateSymbolsStripped</span> <span class="o">:</span> <span class="mi">1</span><span class="p">;</span>
+<span class="n">uint16_t</span> <span class="n">HasConflictingTypes</span> <span class="o">:</span> <span class="mi">1</span><span class="p">;</span>
+<span class="n">uint16_t</span> <span class="n">Reserved</span> <span class="o">:</span> <span class="mi">13</span><span class="p">;</span>
+</pre></div>
+</div>
+<p>The only one of these that is not self-explanatory is <tt class="docutils literal"><span class="pre">HasConflictingTypes</span></tt>.
+Although undocumented, <tt class="docutils literal"><span class="pre">link.exe</span></tt> contains a hidden flag <tt class="docutils literal"><span class="pre">/DEBUG:CTYPES</span></tt>.
+If it is passed to <tt class="docutils literal"><span class="pre">link.exe</span></tt>, this field will be set.  Otherwise it will
+not be set.  It is unclear what this flag does, although it seems to have
+subtle implications on the algorithm used to look up type records.</p>
+<ul class="simple">
+<li><strong>Machine</strong> - A value from the <a class="reference external" href="https://msdn.microsoft.com/en-us/library/b2fc64ek.aspx">CV_CPU_TYPE_e</a>
+enumeration.  Common values are <tt class="docutils literal"><span class="pre">0x8664</span></tt> (x86-64) and <tt class="docutils literal"><span class="pre">0x14C</span></tt> (x86).</li>
+</ul>
+<p>Immediately after the fixed-size DBI Stream header are <tt class="docutils literal"><span class="pre">7</span></tt> variable-length
+<cite>substreams</cite>.  The following <tt class="docutils literal"><span class="pre">7</span></tt> fields of the DBI Stream header specify the
+number of bytes of the corresponding substream.  Each substream’s contents will
+be described in detail <a class="reference internal" href="#dbi-substreams"><em>below</em></a>.  The length of the entire
+DBI Stream should equal <tt class="docutils literal"><span class="pre">64</span></tt> (the length of the header above) plus the value
+of each of the following <tt class="docutils literal"><span class="pre">7</span></tt> fields.</p>
+<ul class="simple">
+<li><strong>ModInfoSize</strong> - The length of the <a class="reference internal" href="#dbi-mod-info-substream"><em>Module Info Substream</em></a>.</li>
+<li><strong>SectionContributionSize</strong> - The length of the <a class="reference internal" href="#dbi-sec-contr-substream"><em>Section Contribution Substream</em></a>.</li>
+<li><strong>SectionMapSize</strong> - The length of the <a class="reference internal" href="#dbi-section-map-substream"><em>Section Map Substream</em></a>.</li>
+<li><strong>SourceInfoSize</strong> - The length of the <a class="reference internal" href="#dbi-file-info-substream"><em>File Info Substream</em></a>.</li>
+<li><strong>TypeServerSize</strong> - The length of the <a class="reference internal" href="#dbi-type-server-substream"><em>Type Server Substream</em></a>.</li>
+<li><strong>OptionalDbgHeaderSize</strong> - The length of the <a class="reference internal" href="#dbi-optional-dbg-stream"><em>Optional Debug Header Stream</em></a>.</li>
+<li><strong>ECSubstreamSize</strong> - The length of the <a class="reference internal" href="#dbi-ec-substream"><em>EC Substream</em></a>.</li>
+</ul>
+</div>
+<div class="section" id="substreams">
+<span id="dbi-substreams"></span><h2><a class="toc-backref" href="#id3">Substreams</a><a class="headerlink" href="#substreams" title="Permalink to this headline">¶</a></h2>
+<div class="section" id="module-info-substream">
+<span id="dbi-mod-info-substream"></span><h3><a class="toc-backref" href="#id4">Module Info Substream</a><a class="headerlink" href="#module-info-substream" title="Permalink to this headline">¶</a></h3>
+<p>Begins at offset <tt class="docutils literal"><span class="pre">0</span></tt> immediately after the <a class="reference internal" href="#dbi-header"><em>header</em></a>.  The
+module info substream is an array of variable-length records, each one
+describing a single module (e.g. object file) linked into the program.  Each
+record in the array has the format:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="k">struct</span> <span class="n">SectionContribEntry</span> <span class="p">{</span>
+  <span class="n">uint16_t</span> <span class="n">Section</span><span class="p">;</span>
+  <span class="kt">char</span> <span class="n">Padding1</span><span class="p">[</span><span class="mi">2</span><span class="p">];</span>
+  <span class="n">int32_t</span> <span class="n">Offset</span><span class="p">;</span>
+  <span class="n">int32_t</span> <span class="n">Size</span><span class="p">;</span>
+  <span class="n">uint32_t</span> <span class="n">Characteristics</span><span class="p">;</span>
+  <span class="n">uint16_t</span> <span class="n">ModuleIndex</span><span class="p">;</span>
+  <span class="kt">char</span> <span class="n">Padding2</span><span class="p">[</span><span class="mi">2</span><span class="p">];</span>
+  <span class="n">uint32_t</span> <span class="n">DataCrc</span><span class="p">;</span>
+  <span class="n">uint32_t</span> <span class="n">RelocCrc</span><span class="p">;</span>
+<span class="p">};</span>
+</pre></div>
+</div>
+<p>While most of these are self-explanatory, the <tt class="docutils literal"><span class="pre">Characteristics</span></tt> field
+warrants some elaboration.  It corresponds to the <tt class="docutils literal"><span class="pre">Characteristics</span></tt>
+field of the <a class="reference external" href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms680341(v=vs.85).aspx">IMAGE_SECTION_HEADER</a>
+structure.</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="k">struct</span> <span class="n">ModInfo</span> <span class="p">{</span>
+  <span class="n">uint32_t</span> <span class="n">Unused1</span><span class="p">;</span>
+  <span class="n">SectionContribEntry</span> <span class="n">SectionContr</span><span class="p">;</span>
+  <span class="n">uint16_t</span> <span class="n">Flags</span><span class="p">;</span>
+  <span class="n">uint16_t</span> <span class="n">ModuleSymStream</span><span class="p">;</span>
+  <span class="n">uint32_t</span> <span class="n">SymByteSize</span><span class="p">;</span>
+  <span class="n">uint32_t</span> <span class="n">C11ByteSize</span><span class="p">;</span>
+  <span class="n">uint32_t</span> <span class="n">C13ByteSize</span><span class="p">;</span>
+  <span class="n">uint16_t</span> <span class="n">SourceFileCount</span><span class="p">;</span>
+  <span class="kt">char</span> <span class="n">Padding</span><span class="p">[</span><span class="mi">2</span><span class="p">];</span>
+  <span class="n">uint32_t</span> <span class="n">Unused2</span><span class="p">;</span>
+  <span class="n">uint32_t</span> <span class="n">SourceFileNameIndex</span><span class="p">;</span>
+  <span class="n">uint32_t</span> <span class="n">PdbFilePathNameIndex</span><span class="p">;</span>
+  <span class="kt">char</span> <span class="n">ModuleName</span><span class="p">[];</span>
+  <span class="kt">char</span> <span class="n">ObjFileName</span><span class="p">[];</span>
+<span class="p">};</span>
+</pre></div>
+</div>
+<ul class="simple">
+<li><strong>SectionContr</strong> - Describes the properties of the section in the final binary
+which contain the code and data from this module.</li>
+<li><strong>Flags</strong> - A bitfield with the following format:</li>
+</ul>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">uint16_t</span> <span class="n">Dirty</span> <span class="o">:</span> <span class="mi">1</span><span class="p">;</span>  <span class="c1">// ``true`` if this ModInfo has been written since reading the PDB.</span>
+<span class="n">uint16_t</span> <span class="n">EC</span> <span class="o">:</span> <span class="mi">1</span><span class="p">;</span>     <span class="c1">// ``true`` if EC information is present for this module. It is unknown what EC actually is.</span>
+<span class="n">uint16_t</span> <span class="n">Unused</span> <span class="o">:</span> <span class="mi">6</span><span class="p">;</span>
+<span class="n">uint16_t</span> <span class="n">TSM</span> <span class="o">:</span> <span class="mi">8</span><span class="p">;</span>    <span class="c1">// Type Server Index for this module.  It is unknown what this is used for, but it is not used by LLVM.</span>
+</pre></div>
+</div>
+<ul class="simple">
+<li><strong>ModuleSymStream</strong> - The index of the stream that contains symbol information
+for this module.  This includes CodeView symbol information as well as source
+and line information.</li>
+<li><strong>SymByteSize</strong> - The number of bytes of data from the stream identified by
+<tt class="docutils literal"><span class="pre">ModuleSymStream</span></tt> that represent CodeView symbol records.</li>
+<li><strong>C11ByteSize</strong> - The number of bytes of data from the stream identified by
+<tt class="docutils literal"><span class="pre">ModuleSymStream</span></tt> that represent C11-style CodeView line information.</li>
+<li><strong>C13ByteSize</strong> - The number of bytes of data from the stream identified by
+<tt class="docutils literal"><span class="pre">ModuleSymStream</span></tt> that represent C13-style CodeView line information.  At
+most one of <tt class="docutils literal"><span class="pre">C11ByteSize</span></tt> and <tt class="docutils literal"><span class="pre">C13ByteSize</span></tt> will be non-zero.</li>
+<li><strong>SourceFileCount</strong> - The number of source files that contributed to this
+module during compilation.</li>
+<li><strong>SourceFileNameIndex</strong> - The offset in the names buffer of the primary
+translation unit used to build this module.  All PDB files observed to date
+always have this value equal to 0.</li>
+<li><strong>PdbFilePathNameIndex</strong> - The offset in the names buffer of the PDB file
+containing this module’s symbol information.  This has only been observed
+to be non-zero for the special <tt class="docutils literal"><span class="pre">*</span> <span class="pre">Linker</span> <span class="pre">*</span></tt> module.</li>
+<li><strong>ModuleName</strong> - The module name.  This is usually either a full path to an
+object file (either directly passed to <tt class="docutils literal"><span class="pre">link.exe</span></tt> or from an archive) or
+a string of the form <tt class="docutils literal"><span class="pre">Import:<dll</span> <span class="pre">name></span></tt>.</li>
+<li><strong>ObjFileName</strong> - The object file name.  In the case of an module that is
+linked directly passed to <tt class="docutils literal"><span class="pre">link.exe</span></tt>, this is the same as <strong>ModuleName</strong>.
+In the case of a module that comes from an archive, this is usually the full
+path to the archive.</li>
+</ul>
+</div>
+<div class="section" id="section-contribution-substream">
+<span id="dbi-sec-contr-substream"></span><h3><a class="toc-backref" href="#id5">Section Contribution Substream</a><a class="headerlink" href="#section-contribution-substream" title="Permalink to this headline">¶</a></h3>
+<p>Begins at offset <tt class="docutils literal"><span class="pre">0</span></tt> immediately after the <a class="reference internal" href="#dbi-mod-info-substream"><em>Module Info Substream</em></a> ends,
+and consumes <tt class="docutils literal"><span class="pre">Header->SectionContributionSize</span></tt> bytes.  This substream begins
+with a single <tt class="docutils literal"><span class="pre">uint32_t</span></tt> which will be one of the following values:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="k">enum</span> <span class="k">class</span> <span class="nc">SectionContrSubstreamVersion</span> <span class="o">:</span> <span class="n">uint32_t</span> <span class="p">{</span>
+  <span class="n">Ver60</span> <span class="o">=</span> <span class="mh">0xeffe0000</span> <span class="o">+</span> <span class="mi">19970605</span><span class="p">,</span>
+  <span class="n">V2</span> <span class="o">=</span> <span class="mh">0xeffe0000</span> <span class="o">+</span> <span class="mi">20140516</span>
+<span class="p">};</span>
+</pre></div>
+</div>
+<p><tt class="docutils literal"><span class="pre">Ver60</span></tt> is the only value which has been observed in a PDB so far.  Following
+this <tt class="docutils literal"><span class="pre">4</span></tt> byte field is an array of fixed-length structures.  If the version
+is <tt class="docutils literal"><span class="pre">Ver60</span></tt>, it is an array of <tt class="docutils literal"><span class="pre">SectionContribEntry</span></tt> structures.  If the
+version is <tt class="docutils literal"><span class="pre">V2</span></tt>, it is an array of <tt class="docutils literal"><span class="pre">SectionContribEntry2</span></tt> structures,
+defined as follows:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="k">struct</span> <span class="n">SectionContribEntry2</span> <span class="p">{</span>
+  <span class="n">SectionContribEntry</span> <span class="n">SC</span><span class="p">;</span>
+  <span class="n">uint32_t</span> <span class="n">ISectCoff</span><span class="p">;</span>
+<span class="p">};</span>
+</pre></div>
+</div>
+<p>The purpose of the second field is not well understood.</p>
+</div>
+<div class="section" id="section-map-substream">
+<span id="dbi-section-map-substream"></span><h3><a class="toc-backref" href="#id6">Section Map Substream</a><a class="headerlink" href="#section-map-substream" title="Permalink to this headline">¶</a></h3>
+<p>Begins at offset <tt class="docutils literal"><span class="pre">0</span></tt> immediately after the <a class="reference internal" href="#dbi-sec-contr-substream"><em>Section Contribution Substream</em></a> ends,
+and consumes <tt class="docutils literal"><span class="pre">Header->SectionMapSize</span></tt> bytes.  This substream begins with an <tt class="docutils literal"><span class="pre">8</span></tt>
+byte header followed by an array of fixed-length records.  The header and records
+have the following layout:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="k">struct</span> <span class="n">SectionMapHeader</span> <span class="p">{</span>
+  <span class="n">uint16_t</span> <span class="n">Count</span><span class="p">;</span>    <span class="c1">// Number of segment descriptors</span>
+  <span class="n">uint16_t</span> <span class="n">LogCount</span><span class="p">;</span> <span class="c1">// Number of logical segment descriptors</span>
+<span class="p">};</span>
+
+<span class="k">struct</span> <span class="n">SectionMapEntry</span> <span class="p">{</span>
+  <span class="n">uint16_t</span> <span class="n">Flags</span><span class="p">;</span>         <span class="c1">// See the SectionMapEntryFlags enum below.</span>
+  <span class="n">uint16_t</span> <span class="n">Ovl</span><span class="p">;</span>           <span class="c1">// Logical overlay number</span>
+  <span class="n">uint16_t</span> <span class="n">Group</span><span class="p">;</span>         <span class="c1">// Group index into descriptor array.</span>
+  <span class="n">uint16_t</span> <span class="n">Frame</span><span class="p">;</span>
+  <span class="n">uint16_t</span> <span class="n">SectionName</span><span class="p">;</span>   <span class="c1">// Byte index of segment / group name in string table, or 0xFFFF.</span>
+  <span class="n">uint16_t</span> <span class="n">ClassName</span><span class="p">;</span>     <span class="c1">// Byte index of class in string table, or 0xFFFF.</span>
+  <span class="n">uint32_t</span> <span class="n">Offset</span><span class="p">;</span>        <span class="c1">// Byte offset of the logical segment within physical segment.  If group is set in flags, this is the offset of the group.</span>
+  <span class="n">uint32_t</span> <span class="n">SectionLength</span><span class="p">;</span> <span class="c1">// Byte count of the segment or group.</span>
+<span class="p">};</span>
+
+<span class="k">enum</span> <span class="k">class</span> <span class="nc">SectionMapEntryFlags</span> <span class="o">:</span> <span class="n">uint16_t</span> <span class="p">{</span>
+  <span class="n">Read</span> <span class="o">=</span> <span class="mi">1</span> <span class="o"><<</span> <span class="mi">0</span><span class="p">,</span>              <span class="c1">// Segment is readable.</span>
+  <span class="n">Write</span> <span class="o">=</span> <span class="mi">1</span> <span class="o"><<</span> <span class="mi">1</span><span class="p">,</span>             <span class="c1">// Segment is writable.</span>
+  <span class="n">Execute</span> <span class="o">=</span> <span class="mi">1</span> <span class="o"><<</span> <span class="mi">2</span><span class="p">,</span>           <span class="c1">// Segment is executable.</span>
+  <span class="n">AddressIs32Bit</span> <span class="o">=</span> <span class="mi">1</span> <span class="o"><<</span> <span class="mi">3</span><span class="p">,</span>    <span class="c1">// Descriptor describes a 32-bit linear address.</span>
+  <span class="n">IsSelector</span> <span class="o">=</span> <span class="mi">1</span> <span class="o"><<</span> <span class="mi">8</span><span class="p">,</span>        <span class="c1">// Frame represents a selector.</span>
+  <span class="n">IsAbsoluteAddress</span> <span class="o">=</span> <span class="mi">1</span> <span class="o"><<</span> <span class="mi">9</span><span class="p">,</span> <span class="c1">// Frame represents an absolute address.</span>
+  <span class="n">IsGroup</span> <span class="o">=</span> <span class="mi">1</span> <span class="o"><<</span> <span class="mi">10</span>           <span class="c1">// If set, descriptor represents a group.</span>
+<span class="p">};</span>
+</pre></div>
+</div>
+<p>Many of these fields are not well understood, so will not be discussed further.</p>
+</div>
+<div class="section" id="file-info-substream">
+<span id="dbi-file-info-substream"></span><h3><a class="toc-backref" href="#id7">File Info Substream</a><a class="headerlink" href="#file-info-substream" title="Permalink to this headline">¶</a></h3>
+<p>Begins at offset <tt class="docutils literal"><span class="pre">0</span></tt> immediately after the <a class="reference internal" href="#dbi-section-map-substream"><em>Section Map Substream</em></a> ends,
+and consumes <tt class="docutils literal"><span class="pre">Header->SourceInfoSize</span></tt> bytes.  This substream defines the mapping
+from module to the source files that contribute to that module.  Since multiple
+modules can use the same source file (for example, a header file), this substream
+uses a string table to store each unique file name only once, and then have each
+module use offsets into the string table rather than embedding the string’s value
+directly.  The format of this substream is as follows:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="k">struct</span> <span class="n">FileInfoSubstream</span> <span class="p">{</span>
+  <span class="n">uint16_t</span> <span class="n">NumModules</span><span class="p">;</span>
+  <span class="n">uint16_t</span> <span class="n">NumSourceFiles</span><span class="p">;</span>
+
+  <span class="n">uint16_t</span> <span class="n">ModIndices</span><span class="p">[</span><span class="n">NumModules</span><span class="p">];</span>
+  <span class="n">uint16_t</span> <span class="n">ModFileCounts</span><span class="p">[</span><span class="n">NumModules</span><span class="p">];</span>
+  <span class="n">uint32_t</span> <span class="n">FileNameOffsets</span><span class="p">[</span><span class="n">NumSourceFiles</span><span class="p">];</span>
+  <span class="kt">char</span> <span class="n">NamesBuffer</span><span class="p">[][</span><span class="n">NumSourceFiles</span><span class="p">];</span>
+<span class="p">};</span>
+</pre></div>
+</div>
+<p><strong>NumModules</strong> - The number of modules for which source file information is
+contained within this substream.  Should match the corresponding value from the
+ref:<cite>dbi_header</cite>.</p>
+<p><strong>NumSourceFiles</strong>: In theory this is supposed to contain the number of source
+files for which this substream contains information.  But that would present a
+problem in that the width of this field being <tt class="docutils literal"><span class="pre">16</span></tt>-bits would prevent one from
+having more than 64K source files in a program.  In early versions of the file
+format, this seems to have been the case.  In order to support more than this, this
+field of the is simply ignored, and computed dynamically by summing up the values of
+the <tt class="docutils literal"><span class="pre">ModFileCounts</span></tt> array (discussed below).  In short, this value should be
+ignored.</p>
+<p><strong>ModIndices</strong> - This array is present, but does not appear to be useful.</p>
+<p><strong>ModFileCountArray</strong> - An array of <tt class="docutils literal"><span class="pre">NumModules</span></tt> integers, each one containing
+the number of source files which contribute to the module at the specified index.
+While each individual module is limited to 64K contributing source files, the
+union of all modules’ source files may be greater than 64K.  The real number of
+source files is thus computed by summing this array.  Note that summing this array
+does not give the number of <cite>unique</cite> source files, only the total number of source
+file contributions to modules.</p>
+<p><strong>FileNameOffsets</strong> - An array of <strong>NumSourceFiles</strong> integers (where <strong>NumSourceFiles</strong>
+here refers to the 32-bit value obtained from summing <strong>ModFileCountArray</strong>), where
+each integer is an offset into <strong>NamesBuffer</strong> pointing to a null terminated string.</p>
+<p><strong>NamesBuffer</strong> - An array of null terminated strings containing the actual source
+file names.</p>
+</div>
+<div class="section" id="type-server-substream">
+<span id="dbi-type-server-substream"></span><h3><a class="toc-backref" href="#id8">Type Server Substream</a><a class="headerlink" href="#type-server-substream" title="Permalink to this headline">¶</a></h3>
+<p>Begins at offset <tt class="docutils literal"><span class="pre">0</span></tt> immediately after the <a class="reference internal" href="#dbi-file-info-substream"><em>File Info Substream</em></a> ends,
+and consumes <tt class="docutils literal"><span class="pre">Header->TypeServerSize</span></tt> bytes.  Neither the purpose nor the layout
+of this substream is understood, although it is assumed to related somehow to the
+usage of <tt class="docutils literal"><span class="pre">/Zi</span></tt> and <tt class="docutils literal"><span class="pre">mspdbsrv.exe</span></tt>.  This substream will not be discussed further.</p>
+</div>
+<div class="section" id="ec-substream">
+<span id="dbi-ec-substream"></span><h3><a class="toc-backref" href="#id9">EC Substream</a><a class="headerlink" href="#ec-substream" title="Permalink to this headline">¶</a></h3>
+<p>Begins at offset <tt class="docutils literal"><span class="pre">0</span></tt> immediately after the <a class="reference internal" href="#dbi-type-server-substream"><em>Type Server Substream</em></a> ends,
+and consumes <tt class="docutils literal"><span class="pre">Header->ECSubstreamSize</span></tt> bytes.  Neither the purpose nor the layout
+of this substream is understood, and it will not be discussed further.</p>
+</div>
+<div class="section" id="optional-debug-header-stream">
+<span id="dbi-optional-dbg-stream"></span><h3><a class="toc-backref" href="#id10">Optional Debug Header Stream</a><a class="headerlink" href="#optional-debug-header-stream" title="Permalink to this headline">¶</a></h3>
+<p>Begins at offset <tt class="docutils literal"><span class="pre">0</span></tt> immediately after the <a class="reference internal" href="#dbi-ec-substream"><em>EC Substream</em></a> ends, and
+consumes <tt class="docutils literal"><span class="pre">Header->OptionalDbgHeaderSize</span></tt> bytes.  This field is an array of
+stream indices (e.g. <tt class="docutils literal"><span class="pre">uint16_t</span></tt>‘s), each of which identifies a stream
+index in the larger MSF file which contains some additional debug information.
+Each position of this array has a special meaning, allowing one to determine
+what kind of debug information is at the referenced stream.  <tt class="docutils literal"><span class="pre">11</span></tt> indices
+are currently understood, although it’s possible there may be more.  The
+layout of each stream generally corresponds exactly to a particular type
+of debug data directory from the PE/COFF file.  The format of these fields
+can be found in the <a class="reference external" href="https://www.microsoft.com/en-us/download/details.aspx?id=19509">Microsoft PE/COFF Specification</a>.</p>
+<p><strong>FPO Data</strong> - <tt class="docutils literal"><span class="pre">DbgStreamArray[0]</span></tt>.  The data in the referenced stream is a
+debug data directory of type <tt class="docutils literal"><span class="pre">IMAGE_DEBUG_TYPE_FPO</span></tt></p>
+<p><strong>Exception Data</strong> - <tt class="docutils literal"><span class="pre">DbgStreamArray[1]</span></tt>.  The data in the referenced stream
+is a debug data directory of type <tt class="docutils literal"><span class="pre">IMAGE_DEBUG_TYPE_EXCEPTION</span></tt>.</p>
+<p><strong>Fixup Data</strong> - <tt class="docutils literal"><span class="pre">DbgStreamArray[2]</span></tt>.  The data in the referenced stream is a
+debug data directory of type <tt class="docutils literal"><span class="pre">IMAGE_DEBUG_TYPE_FIXUP</span></tt>.</p>
+<p><strong>Omap To Src Data</strong> - <tt class="docutils literal"><span class="pre">DbgStreamArray[3]</span></tt>.  The data in the referenced stream
+is a debug data directory of type <tt class="docutils literal"><span class="pre">IMAGE_DEBUG_TYPE_OMAP_TO_SRC</span></tt>.  This
+is used for mapping addresses between instrumented and uninstrumented code.</p>
+<p><strong>Omap From Src Data</strong> - <tt class="docutils literal"><span class="pre">DbgStreamArray[4]</span></tt>.  The data in the referenced stream
+is a debug data directory of type <tt class="docutils literal"><span class="pre">IMAGE_DEBUG_TYPE_OMAP_FROM_SRC</span></tt>.  This
+is used for mapping addresses between instrumented and uninstrumented code.</p>
+<p><strong>Section Header Data</strong> - <tt class="docutils literal"><span class="pre">DbgStreamArray[5]</span></tt>.  A dump of all section headers from
+the original executable.</p>
+<p><strong>Token / RID Map</strong> - <tt class="docutils literal"><span class="pre">DbgStreamArray[6]</span></tt>.  The layout of this stream is not
+understood, but it is assumed to be a mapping from <tt class="docutils literal"><span class="pre">CLR</span> <span class="pre">Token</span></tt> to
+<tt class="docutils literal"><span class="pre">CLR</span> <span class="pre">Record</span> <span class="pre">ID</span></tt>.  Refer to <a class="reference external" href="http://www.ecma-international.org/publications/standards/Ecma-335.htm">ECMA 335</a>
+for more information.</p>
+<p><strong>Xdata</strong> - <tt class="docutils literal"><span class="pre">DbgStreamArray[7]</span></tt>.  A copy of the <tt class="docutils literal"><span class="pre">.xdata</span></tt> section from the
+executable.</p>
+<p><strong>Pdata</strong> - <tt class="docutils literal"><span class="pre">DbgStreamArray[8]</span></tt>. This is assumed to be a copy of the <tt class="docutils literal"><span class="pre">.pdata</span></tt>
+section from the executable, but that would make it identical to
+<tt class="docutils literal"><span class="pre">DbgStreamArray[1]</span></tt>.  The difference between these two indices is not well
+understood.</p>
+<p><strong>New FPO Data</strong> - <tt class="docutils literal"><span class="pre">DbgStreamArray[9]</span></tt>.  The data in the referenced stream is a
+debug data directory of type <tt class="docutils literal"><span class="pre">IMAGE_DEBUG_TYPE_FPO</span></tt>.  It is not clear how this
+differs from <tt class="docutils literal"><span class="pre">DbgStreamArray[0]</span></tt>, but in practice all observed PDB files have
+used the “new” format rather than the “old” format.</p>
+<p><strong>Original Section Header Data</strong> - <tt class="docutils literal"><span class="pre">DbgStreamArray[10]</span></tt>.  Assumed to be similar
+to <tt class="docutils literal"><span class="pre">DbgStreamArray[5]</span></tt>, but has not been observed in practice.</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="ModiStream.html" title="The Module Information Stream"
+             >next</a> |</li>
+        <li class="right" >
+          <a href="TpiStream.html" title="The PDB TPI Stream"
+             >previous</a> |</li>
+  <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+  <li><a href="../index.html">Documentation</a>»</li>
+
+          <li><a href="index.html" >The PDB File Format</a> »</li> 
+      </ul>
+    </div>
+    <div class="footer">
+        © Copyright 2003-2018, LLVM Project.
+      Last updated on 2018-05-10.
+      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/5.0.2/docs/PDB/GlobalStream.html
URL: http://llvm.org/viewvc/llvm-project/www-releases/trunk/5.0.2/docs/PDB/GlobalStream.html?rev=331981&view=auto
==============================================================================
--- www-releases/trunk/5.0.2/docs/PDB/GlobalStream.html (added)
+++ www-releases/trunk/5.0.2/docs/PDB/GlobalStream.html Thu May 10 06:54:16 2018
@@ -0,0 +1,102 @@
+
+
+<!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>The PDB Global Symbol Stream — LLVM 5 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:     '5',
+        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 5 documentation" href="../index.html" />
+    <link rel="up" title="The PDB File Format" href="index.html" />
+    <link rel="next" title="The TPI & IPI Hash Streams" href="HashStream.html" />
+    <link rel="prev" title="The PDB Public Symbol Stream" href="PublicStream.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="HashStream.html" title="The TPI & IPI Hash Streams"
+             accesskey="N">next</a> |</li>
+        <li class="right" >
+          <a href="PublicStream.html" title="The PDB Public Symbol Stream"
+             accesskey="P">previous</a> |</li>
+  <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+  <li><a href="../index.html">Documentation</a>»</li>
+
+          <li><a href="index.html" accesskey="U">The PDB File Format</a> »</li> 
+      </ul>
+    </div>
+
+
+    <div class="document">
+      <div class="documentwrapper">
+          <div class="body">
+            
+  <div class="section" id="the-pdb-global-symbol-stream">
+<h1>The PDB Global Symbol Stream<a class="headerlink" href="#the-pdb-global-symbol-stream" title="Permalink to this headline">¶</a></h1>
+</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="HashStream.html" title="The TPI & IPI Hash Streams"
+             >next</a> |</li>
+        <li class="right" >
+          <a href="PublicStream.html" title="The PDB Public Symbol Stream"
+             >previous</a> |</li>
+  <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+  <li><a href="../index.html">Documentation</a>»</li>
+
+          <li><a href="index.html" >The PDB File Format</a> »</li> 
+      </ul>
+    </div>
+    <div class="footer">
+        © Copyright 2003-2018, LLVM Project.
+      Last updated on 2018-05-10.
+      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/5.0.2/docs/PDB/HashStream.html
URL: http://llvm.org/viewvc/llvm-project/www-releases/trunk/5.0.2/docs/PDB/HashStream.html?rev=331981&view=auto
==============================================================================
--- www-releases/trunk/5.0.2/docs/PDB/HashStream.html (added)
+++ www-releases/trunk/5.0.2/docs/PDB/HashStream.html Thu May 10 06:54:16 2018
@@ -0,0 +1,102 @@
+
+
+<!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>The TPI & IPI Hash Streams — LLVM 5 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:     '5',
+        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 5 documentation" href="../index.html" />
+    <link rel="up" title="The PDB File Format" href="index.html" />
+    <link rel="next" title="CodeView Symbol Records" href="CodeViewSymbols.html" />
+    <link rel="prev" title="The PDB Global Symbol Stream" href="GlobalStream.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="CodeViewSymbols.html" title="CodeView Symbol Records"
+             accesskey="N">next</a> |</li>
+        <li class="right" >
+          <a href="GlobalStream.html" title="The PDB Global Symbol Stream"
+             accesskey="P">previous</a> |</li>
+  <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+  <li><a href="../index.html">Documentation</a>»</li>
+
+          <li><a href="index.html" accesskey="U">The PDB File Format</a> »</li> 
+      </ul>
+    </div>
+
+
+    <div class="document">
+      <div class="documentwrapper">
+          <div class="body">
+            
+  <div class="section" id="the-tpi-ipi-hash-streams">
+<h1>The TPI & IPI Hash Streams<a class="headerlink" href="#the-tpi-ipi-hash-streams" title="Permalink to this headline">¶</a></h1>
+</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="CodeViewSymbols.html" title="CodeView Symbol Records"
+             >next</a> |</li>
+        <li class="right" >
+          <a href="GlobalStream.html" title="The PDB Global Symbol Stream"
+             >previous</a> |</li>
+  <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+  <li><a href="../index.html">Documentation</a>»</li>
+
+          <li><a href="index.html" >The PDB File Format</a> »</li> 
+      </ul>
+    </div>
+    <div class="footer">
+        © Copyright 2003-2018, LLVM Project.
+      Last updated on 2018-05-10.
+      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/5.0.2/docs/PDB/ModiStream.html
URL: http://llvm.org/viewvc/llvm-project/www-releases/trunk/5.0.2/docs/PDB/ModiStream.html?rev=331981&view=auto
==============================================================================
--- www-releases/trunk/5.0.2/docs/PDB/ModiStream.html (added)
+++ www-releases/trunk/5.0.2/docs/PDB/ModiStream.html Thu May 10 06:54:16 2018
@@ -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>The Module Information Stream — LLVM 5 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:     '5',
+        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 5 documentation" href="../index.html" />
+    <link rel="up" title="The PDB File Format" href="index.html" />
+    <link rel="next" title="The PDB Public Symbol Stream" href="PublicStream.html" />
+    <link rel="prev" title="The PDB DBI (Debug Info) Stream" href="DbiStream.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="PublicStream.html" title="The PDB Public Symbol Stream"
+             accesskey="N">next</a> |</li>
+        <li class="right" >
+          <a href="DbiStream.html" title="The PDB DBI (Debug Info) Stream"
+             accesskey="P">previous</a> |</li>
+  <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+  <li><a href="../index.html">Documentation</a>»</li>
+
+          <li><a href="index.html" accesskey="U">The PDB File Format</a> »</li> 
+      </ul>
+    </div>
+
+
+    <div class="document">
+      <div class="documentwrapper">
+          <div class="body">
+            
+  <div class="section" id="the-module-information-stream">
+<h1>The Module Information Stream<a class="headerlink" href="#the-module-information-stream" 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="#stream-layout" id="id2">Stream Layout</a></li>
+<li><a class="reference internal" href="#the-codeview-symbol-substream" id="id3">The CodeView Symbol Substream</a></li>
+</ul>
+</div>
+<div class="section" id="introduction">
+<span id="modi-stream-intro"></span><h2><a class="toc-backref" href="#id1">Introduction</a><a class="headerlink" href="#introduction" title="Permalink to this headline">¶</a></h2>
+<p>The Module Info Stream (henceforth referred to as the Modi stream) contains
+information about a single module (object file, import library, etc that
+contributes to the binary this PDB contains debug information about.  There
+is one modi stream for each module, and the mapping between modi stream index
+and module is contained in the <a class="reference internal" href="DbiStream.html"><em>DBI Stream</em></a>.  The modi stream
+for a single module contains line information for the compiland, as well as
+all CodeView information for the symbols defined in the compiland.  Finally,
+there is a “global refs” substream which is not well understood.</p>
+</div>
+<div class="section" id="stream-layout">
+<span id="modi-stream-layout"></span><h2><a class="toc-backref" href="#id2">Stream Layout</a><a class="headerlink" href="#stream-layout" title="Permalink to this headline">¶</a></h2>
+<p>A modi stream is laid out as follows:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="k">struct</span> <span class="n">ModiStream</span> <span class="p">{</span>
+  <span class="n">uint32_t</span> <span class="n">Signature</span><span class="p">;</span>
+  <span class="n">uint8_t</span> <span class="n">Symbols</span><span class="p">[</span><span class="n">SymbolSize</span><span class="o">-</span><span class="mi">4</span><span class="p">];</span>
+  <span class="n">uint8_t</span> <span class="n">C11LineInfo</span><span class="p">[</span><span class="n">C11Size</span><span class="p">];</span>
+  <span class="n">uint8_t</span> <span class="n">C13LineInfo</span><span class="p">[</span><span class="n">C13Size</span><span class="p">];</span>
+
+  <span class="n">uint32_t</span> <span class="n">GlobalRefsSize</span><span class="p">;</span>
+  <span class="n">uint8_t</span> <span class="n">GlobalRefs</span><span class="p">[</span><span class="n">GlobalRefsSize</span><span class="p">];</span>
+<span class="p">};</span>
+</pre></div>
+</div>
+<ul class="simple">
+<li><strong>Signature</strong> - Unknown.  In practice only the value of <tt class="docutils literal"><span class="pre">4</span></tt> has been
+observed.  It is hypothesized that this value corresponds to the set of
+<tt class="docutils literal"><span class="pre">CV_SIGNATURE_xx</span></tt> defines in <tt class="docutils literal"><span class="pre">cvinfo.h</span></tt>, with the value of <tt class="docutils literal"><span class="pre">4</span></tt>
+meaning that this module has C13 line information (as opposed to C11 line
+information).  A corollary of this is that we expect to only ever see
+C13 line info, and that we do not understand the format of C11 line info.</li>
+<li><strong>Symbols</strong> - The <a class="reference internal" href="#modi-symbol-substream"><em>CodeView Symbol Substream</em></a>.
+<tt class="docutils literal"><span class="pre">SymbolSize</span></tt> is equal to the value of <tt class="docutils literal"><span class="pre">SymByteSize</span></tt> for the
+corresponding module’s entry in the <a class="reference internal" href="DbiStream.html#dbi-mod-info-substream"><em>Module Info Substream</em></a>
+of the <a class="reference internal" href="DbiStream.html"><em>DBI Stream</em></a>.</li>
+<li><strong>C11LineInfo</strong> - A block containing CodeView line information in C11
+format.  <tt class="docutils literal"><span class="pre">C11Size</span></tt> is equal to the value of <tt class="docutils literal"><span class="pre">C11ByteSize</span></tt> from the
+<a class="reference internal" href="DbiStream.html#dbi-mod-info-substream"><em>Module Info Substream</em></a> of the
+<a class="reference internal" href="DbiStream.html"><em>DBI Stream</em></a>.  If this value is <tt class="docutils literal"><span class="pre">0</span></tt>, then C11 line
+information is not present.  As mentioned previously, the format of
+C11 line info is not understood and we assume all line in modern PDBs
+to be in C13 format.</li>
+<li><strong>C13LineInfo</strong> - A block containing CodeView line information in C13
+format.  <tt class="docutils literal"><span class="pre">C13Size</span></tt> is equal to the value of <tt class="docutils literal"><span class="pre">C13ByteSize</span></tt> from the
+<a class="reference internal" href="DbiStream.html#dbi-mod-info-substream"><em>Module Info Substream</em></a> of the
+<a class="reference internal" href="DbiStream.html"><em>DBI Stream</em></a>.  If this value is <tt class="docutils literal"><span class="pre">0</span></tt>, then C13 line
+information is not present.</li>
+<li><strong>GlobalRefs</strong> - The meaning of this substream is not understood.</li>
+</ul>
+</div>
+<div class="section" id="the-codeview-symbol-substream">
+<span id="modi-symbol-substream"></span><h2><a class="toc-backref" href="#id3">The CodeView Symbol Substream</a><a class="headerlink" href="#the-codeview-symbol-substream" title="Permalink to this headline">¶</a></h2>
+<p>The CodeView Symbol Substream.  This is an array of variable length
+records describing the functions, variables, inlining information,
+and other symbols defined in the compiland.  The entire array consumes
+<tt class="docutils literal"><span class="pre">SymbolSize-4</span></tt> bytes.  The format of a CodeView Symbol Record (and
+thusly, an array of CodeView Symbol Records) is described in
+<a class="reference internal" href="CodeViewSymbols.html"><em>CodeView Symbol Records</em></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="PublicStream.html" title="The PDB Public Symbol Stream"
+             >next</a> |</li>
+        <li class="right" >
+          <a href="DbiStream.html" title="The PDB DBI (Debug Info) Stream"
+             >previous</a> |</li>
+  <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+  <li><a href="../index.html">Documentation</a>»</li>
+
+          <li><a href="index.html" >The PDB File Format</a> »</li> 
+      </ul>
+    </div>
+    <div class="footer">
+        © Copyright 2003-2018, LLVM Project.
+      Last updated on 2018-05-10.
+      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/5.0.2/docs/PDB/MsfFile.html
URL: http://llvm.org/viewvc/llvm-project/www-releases/trunk/5.0.2/docs/PDB/MsfFile.html?rev=331981&view=auto
==============================================================================
--- www-releases/trunk/5.0.2/docs/PDB/MsfFile.html (added)
+++ www-releases/trunk/5.0.2/docs/PDB/MsfFile.html Thu May 10 06:54:16 2018
@@ -0,0 +1,211 @@
+
+
+<!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>The MSF File Format — LLVM 5 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:     '5',
+        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 5 documentation" href="../index.html" />
+    <link rel="up" title="The PDB File Format" href="index.html" />
+    <link rel="next" title="The PDB Info Stream (aka the PDB Stream)" href="PdbStream.html" />
+    <link rel="prev" title="The PDB File Format" href="index.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="PdbStream.html" title="The PDB Info Stream (aka the PDB Stream)"
+             accesskey="N">next</a> |</li>
+        <li class="right" >
+          <a href="index.html" title="The PDB File Format"
+             accesskey="P">previous</a> |</li>
+  <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+  <li><a href="../index.html">Documentation</a>»</li>
+
+          <li><a href="index.html" accesskey="U">The PDB File Format</a> »</li> 
+      </ul>
+    </div>
+
+
+    <div class="document">
+      <div class="documentwrapper">
+          <div class="body">
+            
+  <div class="section" id="the-msf-file-format">
+<h1>The MSF File Format<a class="headerlink" href="#the-msf-file-format" title="Permalink to this headline">¶</a></h1>
+<div class="contents local topic" id="contents">
+<ul class="simple">
+<li><a class="reference internal" href="#the-superblock" id="id1">The Superblock</a></li>
+<li><a class="reference internal" href="#the-stream-directory" id="id2">The Stream Directory</a></li>
+<li><a class="reference internal" href="#alignment-and-block-boundaries" id="id3">Alignment and Block Boundaries</a></li>
+</ul>
+</div>
+<div class="section" id="the-superblock">
+<span id="msf-superblock"></span><h2><a class="toc-backref" href="#id1">The Superblock</a><a class="headerlink" href="#the-superblock" title="Permalink to this headline">¶</a></h2>
+<p>At file offset 0 in an MSF file is the MSF <em>SuperBlock</em>, which is laid out as
+follows:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="k">struct</span> <span class="n">SuperBlock</span> <span class="p">{</span>
+  <span class="kt">char</span> <span class="n">FileMagic</span><span class="p">[</span><span class="k">sizeof</span><span class="p">(</span><span class="n">Magic</span><span class="p">)];</span>
+  <span class="n">ulittle32_t</span> <span class="n">BlockSize</span><span class="p">;</span>
+  <span class="n">ulittle32_t</span> <span class="n">FreeBlockMapBlock</span><span class="p">;</span>
+  <span class="n">ulittle32_t</span> <span class="n">NumBlocks</span><span class="p">;</span>
+  <span class="n">ulittle32_t</span> <span class="n">NumDirectoryBytes</span><span class="p">;</span>
+  <span class="n">ulittle32_t</span> <span class="n">Unknown</span><span class="p">;</span>
+  <span class="n">ulittle32_t</span> <span class="n">BlockMapAddr</span><span class="p">;</span>
+<span class="p">};</span>
+</pre></div>
+</div>
+<ul class="simple">
+<li><strong>FileMagic</strong> - Must be equal to <tt class="docutils literal"><span class="pre">"Microsoft</span> <span class="pre">C</span> <span class="pre">/</span> <span class="pre">C++</span> <span class="pre">MSF</span> <span class="pre">7.00\\r\\n"</span></tt>
+followed by the bytes <tt class="docutils literal"><span class="pre">1A</span> <span class="pre">44</span> <span class="pre">53</span> <span class="pre">00</span> <span class="pre">00</span> <span class="pre">00</span></tt>.</li>
+<li><strong>BlockSize</strong> - The block size of the internal file system.  Valid values are
+512, 1024, 2048, and 4096 bytes.  Certain aspects of the MSF file layout vary
+depending on the block sizes.  For the purposes of LLVM, we handle only block
+sizes of 4KiB, and all further discussion assumes a block size of 4KiB.</li>
+<li><strong>FreeBlockMapBlock</strong> - The index of a block within the file, at which begins
+a bitfield representing the set of all blocks within the file which are “free”
+(i.e. the data within that block is not used).  This bitfield is spread across
+the MSF file at <tt class="docutils literal"><span class="pre">BlockSize</span></tt> intervals.
+<strong>Important</strong>: <tt class="docutils literal"><span class="pre">FreeBlockMapBlock</span></tt> can only be <tt class="docutils literal"><span class="pre">1</span></tt> or <tt class="docutils literal"><span class="pre">2</span></tt>!  This field
+is designed to support incremental and atomic updates of the underlying MSF
+file.  While writing to an MSF file, if the value of this field is <cite>1</cite>, you
+can write your new modified bitfield to page 2, and vice versa.  Only when
+you commit the file to disk do you need to swap the value in the SuperBlock
+to point to the new <tt class="docutils literal"><span class="pre">FreeBlockMapBlock</span></tt>.</li>
+<li><strong>NumBlocks</strong> - The total number of blocks in the file.  <tt class="docutils literal"><span class="pre">NumBlocks</span> <span class="pre">*</span> <span class="pre">BlockSize</span></tt>
+should equal the size of the file on disk.</li>
+<li><strong>NumDirectoryBytes</strong> - The size of the stream directory, in bytes.  The stream
+directory contains information about each stream’s size and the set of blocks
+that it occupies.  It will be described in more detail later.</li>
+<li><strong>BlockMapAddr</strong> - The index of a block within the MSF file.  At this block is
+an array of <tt class="docutils literal"><span class="pre">ulittle32_t</span></tt>‘s listing the blocks that the stream directory
+resides on.  For large MSF files, the stream directory (which describes the
+block layout of each stream) may not fit entirely on a single block.  As a
+result, this extra layer of indirection is introduced, whereby this block
+contains the list of blocks that the stream directory occupies, and the stream
+directory itself can be stitched together accordingly.  The number of
+<tt class="docutils literal"><span class="pre">ulittle32_t</span></tt>‘s in this array is given by <tt class="docutils literal"><span class="pre">ceil(NumDirectoryBytes</span> <span class="pre">/</span> <span class="pre">BlockSize)</span></tt>.</li>
+</ul>
+</div>
+<div class="section" id="the-stream-directory">
+<h2><a class="toc-backref" href="#id2">The Stream Directory</a><a class="headerlink" href="#the-stream-directory" title="Permalink to this headline">¶</a></h2>
+<p>The Stream Directory is the root of all access to the other streams in an MSF
+file.  Beginning at byte 0 of the stream directory is the following structure:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="k">struct</span> <span class="n">StreamDirectory</span> <span class="p">{</span>
+  <span class="n">ulittle32_t</span> <span class="n">NumStreams</span><span class="p">;</span>
+  <span class="n">ulittle32_t</span> <span class="n">StreamSizes</span><span class="p">[</span><span class="n">NumStreams</span><span class="p">];</span>
+  <span class="n">ulittle32_t</span> <span class="n">StreamBlocks</span><span class="p">[</span><span class="n">NumStreams</span><span class="p">][];</span>
+<span class="p">};</span>
+</pre></div>
+</div>
+<p>And this structure occupies exactly <tt class="docutils literal"><span class="pre">SuperBlock->NumDirectoryBytes</span></tt> bytes.
+Note that each of the last two arrays is of variable length, and in particular
+that the second array is jagged.</p>
+<p><strong>Example:</strong> Suppose a hypothetical PDB file with a 4KiB block size, and 4
+streams of lengths {1000 bytes, 8000 bytes, 16000 bytes, 9000 bytes}.</p>
+<p>Stream 0: ceil(1000 / 4096) = 1 block</p>
+<p>Stream 1: ceil(8000 / 4096) = 2 blocks</p>
+<p>Stream 2: ceil(16000 / 4096) = 4 blocks</p>
+<p>Stream 3: ceil(9000 / 4096) = 3 blocks</p>
+<p>In total, 10 blocks are used.  Let’s see what the stream directory might look
+like:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="k">struct</span> <span class="n">StreamDirectory</span> <span class="p">{</span>
+  <span class="n">ulittle32_t</span> <span class="n">NumStreams</span> <span class="o">=</span> <span class="mi">4</span><span class="p">;</span>
+  <span class="n">ulittle32_t</span> <span class="n">StreamSizes</span><span class="p">[]</span> <span class="o">=</span> <span class="p">{</span><span class="mi">1000</span><span class="p">,</span> <span class="mi">8000</span><span class="p">,</span> <span class="mi">16000</span><span class="p">,</span> <span class="mi">9000</span><span class="p">};</span>
+  <span class="n">ulittle32_t</span> <span class="n">StreamBlocks</span><span class="p">[][]</span> <span class="o">=</span> <span class="p">{</span>
+    <span class="p">{</span><span class="mi">4</span><span class="p">},</span>
+    <span class="p">{</span><span class="mi">5</span><span class="p">,</span> <span class="mi">6</span><span class="p">},</span>
+    <span class="p">{</span><span class="mi">11</span><span class="p">,</span> <span class="mi">9</span><span class="p">,</span> <span class="mi">7</span><span class="p">,</span> <span class="mi">8</span><span class="p">},</span>
+    <span class="p">{</span><span class="mi">10</span><span class="p">,</span> <span class="mi">15</span><span class="p">,</span> <span class="mi">12</span><span class="p">}</span>
+  <span class="p">};</span>
+<span class="p">};</span>
+</pre></div>
+</div>
+<p>In total, this occupies <tt class="docutils literal"><span class="pre">15</span> <span class="pre">*</span> <span class="pre">4</span> <span class="pre">=</span> <span class="pre">60</span></tt> bytes, so <tt class="docutils literal"><span class="pre">SuperBlock->NumDirectoryBytes</span></tt>
+would equal <tt class="docutils literal"><span class="pre">60</span></tt>, and <tt class="docutils literal"><span class="pre">SuperBlock->BlockMapAddr</span></tt> would be an array of one
+<tt class="docutils literal"><span class="pre">ulittle32_t</span></tt>, since <tt class="docutils literal"><span class="pre">60</span> <span class="pre"><=</span> <span class="pre">SuperBlock->BlockSize</span></tt>.</p>
+<p>Note also that the streams are discontiguous, and that part of stream 3 is in the
+middle of part of stream 2.  You cannot assume anything about the layout of the
+blocks!</p>
+</div>
+<div class="section" id="alignment-and-block-boundaries">
+<h2><a class="toc-backref" href="#id3">Alignment and Block Boundaries</a><a class="headerlink" href="#alignment-and-block-boundaries" title="Permalink to this headline">¶</a></h2>
+<p>As may be clear by now, it is possible for a single field (whether it be a high
+level record, a long string field, or even a single <tt class="docutils literal"><span class="pre">uint16</span></tt>) to begin and
+end in separate blocks.  For example, if the block size is 4096 bytes, and a
+<tt class="docutils literal"><span class="pre">uint16</span></tt> field begins at the last byte of the current block, then it would
+need to end on the first byte of the next block.  Since blocks are not
+necessarily contiguously laid out in the file, this means that both the consumer
+and the producer of an MSF file must be prepared to split data apart
+accordingly.  In the aforementioned example, the high byte of the <tt class="docutils literal"><span class="pre">uint16</span></tt>
+would be written to the last byte of block N, and the low byte would be written
+to the first byte of block N+1, which could be tens of thousands of bytes later
+(or even earlier!) in the file, depending on what the stream directory says.</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="PdbStream.html" title="The PDB Info Stream (aka the PDB Stream)"
+             >next</a> |</li>
+        <li class="right" >
+          <a href="index.html" title="The PDB File Format"
+             >previous</a> |</li>
+  <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+  <li><a href="../index.html">Documentation</a>»</li>
+
+          <li><a href="index.html" >The PDB File Format</a> »</li> 
+      </ul>
+    </div>
+    <div class="footer">
+        © Copyright 2003-2018, LLVM Project.
+      Last updated on 2018-05-10.
+      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/5.0.2/docs/PDB/PdbStream.html
URL: http://llvm.org/viewvc/llvm-project/www-releases/trunk/5.0.2/docs/PDB/PdbStream.html?rev=331981&view=auto
==============================================================================
--- www-releases/trunk/5.0.2/docs/PDB/PdbStream.html (added)
+++ www-releases/trunk/5.0.2/docs/PDB/PdbStream.html Thu May 10 06:54:16 2018
@@ -0,0 +1,174 @@
+
+
+<!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>The PDB Info Stream (aka the PDB Stream) — LLVM 5 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:     '5',
+        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 5 documentation" href="../index.html" />
+    <link rel="up" title="The PDB File Format" href="index.html" />
+    <link rel="next" title="The PDB TPI Stream" href="TpiStream.html" />
+    <link rel="prev" title="The MSF File Format" href="MsfFile.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="TpiStream.html" title="The PDB TPI Stream"
+             accesskey="N">next</a> |</li>
+        <li class="right" >
+          <a href="MsfFile.html" title="The MSF File Format"
+             accesskey="P">previous</a> |</li>
+  <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+  <li><a href="../index.html">Documentation</a>»</li>
+
+          <li><a href="index.html" accesskey="U">The PDB File Format</a> »</li> 
+      </ul>
+    </div>
+
+
+    <div class="document">
+      <div class="documentwrapper">
+          <div class="body">
+            
+  <div class="section" id="the-pdb-info-stream-aka-the-pdb-stream">
+<h1>The PDB Info Stream (aka the PDB Stream)<a class="headerlink" href="#the-pdb-info-stream-aka-the-pdb-stream" title="Permalink to this headline">¶</a></h1>
+<div class="contents local topic" id="contents">
+<ul class="simple">
+<li><a class="reference internal" href="#stream-header" id="id1">Stream Header</a></li>
+<li><a class="reference internal" href="#matching-a-pdb-to-its-executable" id="id2">Matching a PDB to its executable</a></li>
+</ul>
+</div>
+<div class="section" id="stream-header">
+<span id="pdb-stream-header"></span><h2><a class="toc-backref" href="#id1">Stream Header</a><a class="headerlink" href="#stream-header" title="Permalink to this headline">¶</a></h2>
+<p>At offset 0 of the PDB Stream is a header with the following layout:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="k">struct</span> <span class="n">PdbStreamHeader</span> <span class="p">{</span>
+  <span class="n">ulittle32_t</span> <span class="n">Version</span><span class="p">;</span>
+  <span class="n">ulittle32_t</span> <span class="n">Signature</span><span class="p">;</span>
+  <span class="n">ulittle32_t</span> <span class="n">Age</span><span class="p">;</span>
+  <span class="n">Guid</span> <span class="n">UniqueId</span><span class="p">;</span>
+<span class="p">};</span>
+</pre></div>
+</div>
+<ul class="simple">
+<li><strong>Version</strong> - A Value from the following enum:</li>
+</ul>
+<div class="highlight-c++"><div class="highlight"><pre><span class="k">enum</span> <span class="k">class</span> <span class="nc">PdbStreamVersion</span> <span class="o">:</span> <span class="n">uint32_t</span> <span class="p">{</span>
+  <span class="n">VC2</span> <span class="o">=</span> <span class="mi">19941610</span><span class="p">,</span>
+  <span class="n">VC4</span> <span class="o">=</span> <span class="mi">19950623</span><span class="p">,</span>
+  <span class="n">VC41</span> <span class="o">=</span> <span class="mi">19950814</span><span class="p">,</span>
+  <span class="n">VC50</span> <span class="o">=</span> <span class="mi">19960307</span><span class="p">,</span>
+  <span class="n">VC98</span> <span class="o">=</span> <span class="mi">19970604</span><span class="p">,</span>
+  <span class="n">VC70Dep</span> <span class="o">=</span> <span class="mi">19990604</span><span class="p">,</span>
+  <span class="n">VC70</span> <span class="o">=</span> <span class="mi">20000404</span><span class="p">,</span>
+  <span class="n">VC80</span> <span class="o">=</span> <span class="mi">20030901</span><span class="p">,</span>
+  <span class="n">VC110</span> <span class="o">=</span> <span class="mi">20091201</span><span class="p">,</span>
+  <span class="n">VC140</span> <span class="o">=</span> <span class="mi">20140508</span><span class="p">,</span>
+<span class="p">};</span>
+</pre></div>
+</div>
+<p>While the meaning of this field appears to be obvious, in practice we have
+never observed a value other than <tt class="docutils literal"><span class="pre">VC70</span></tt>, even with modern versions of
+the toolchain, and it is unclear why the other values exist.  It is assumed
+that certain aspects of the PDB stream’s layout, and perhaps even that of
+the other streams, will change if the value is something other than <tt class="docutils literal"><span class="pre">VC70</span></tt>.</p>
+<ul class="simple">
+<li><strong>Signature</strong> - A 32-bit time-stamp generated with a call to <tt class="docutils literal"><span class="pre">time()</span></tt> at
+the time the PDB file is written.  Note that due to the inherent uniqueness
+problems of using a timestamp with 1-second granularity, this field does not
+really serve its intended purpose, and as such is typically ignored in favor
+of the <tt class="docutils literal"><span class="pre">Guid</span></tt> field, described below.</li>
+<li><strong>Age</strong> - The number of times the PDB file has been written.  This can be used
+along with <tt class="docutils literal"><span class="pre">Guid</span></tt> to match the PDB to its corresponding executable.</li>
+<li><strong>Guid</strong> - A 128-bit identifier guaranteed to be unique across space and time.
+In general, this can be thought of as the result of calling the Win32 API
+<a class="reference external" href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa379205(v=vs.85).aspx">UuidCreate</a>,
+although LLVM cannot rely on that, as it must work on non-Windows platforms.</li>
+</ul>
+</div>
+<div class="section" id="matching-a-pdb-to-its-executable">
+<h2><a class="toc-backref" href="#id2">Matching a PDB to its executable</a><a class="headerlink" href="#matching-a-pdb-to-its-executable" title="Permalink to this headline">¶</a></h2>
+<p>The linker is responsible for writing both the PDB and the final executable, and
+as a result is the only entity capable of writing the information necessary to
+match the PDB to the executable.</p>
+<p>In order to accomplish this, the linker generates a guid for the PDB (or
+re-uses the existing guid if it is linking incrementally) and increments the Age
+field.</p>
+<p>The executable is a PE/COFF file, and part of a PE/COFF file is the presence of
+number of “directories”.  For our purposes here, we are interested in the “debug
+directory”.  The exact format of a debug directory is described by the
+<a class="reference external" href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms680307(v=vs.85).aspx">IMAGE_DEBUG_DIRECTORY structure</a>.
+For this particular case, the linker emits a debug directory of type
+<tt class="docutils literal"><span class="pre">IMAGE_DEBUG_TYPE_CODEVIEW</span></tt>.  The format of this record is defined in
+<tt class="docutils literal"><span class="pre">llvm/DebugInfo/CodeView/CVDebugRecord.h</span></tt>, but it suffices to say here only
+that it includes the same <tt class="docutils literal"><span class="pre">Guid</span></tt> and <tt class="docutils literal"><span class="pre">Age</span></tt> fields.  At runtime, a
+debugger or tool can scan the COFF executable image for the presence of
+a debug directory of the correct type and verify that the Guid and Age match.</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="TpiStream.html" title="The PDB TPI Stream"
+             >next</a> |</li>
+        <li class="right" >
+          <a href="MsfFile.html" title="The MSF File Format"
+             >previous</a> |</li>
+  <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+  <li><a href="../index.html">Documentation</a>»</li>
+
+          <li><a href="index.html" >The PDB File Format</a> »</li> 
+      </ul>
+    </div>
+    <div class="footer">
+        © Copyright 2003-2018, LLVM Project.
+      Last updated on 2018-05-10.
+      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/5.0.2/docs/PDB/PublicStream.html
URL: http://llvm.org/viewvc/llvm-project/www-releases/trunk/5.0.2/docs/PDB/PublicStream.html?rev=331981&view=auto
==============================================================================
--- www-releases/trunk/5.0.2/docs/PDB/PublicStream.html (added)
+++ www-releases/trunk/5.0.2/docs/PDB/PublicStream.html Thu May 10 06:54:16 2018
@@ -0,0 +1,102 @@
+
+
+<!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>The PDB Public Symbol Stream — LLVM 5 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:     '5',
+        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 5 documentation" href="../index.html" />
+    <link rel="up" title="The PDB File Format" href="index.html" />
+    <link rel="next" title="The PDB Global Symbol Stream" href="GlobalStream.html" />
+    <link rel="prev" title="The Module Information Stream" href="ModiStream.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="GlobalStream.html" title="The PDB Global Symbol Stream"
+             accesskey="N">next</a> |</li>
+        <li class="right" >
+          <a href="ModiStream.html" title="The Module Information Stream"
+             accesskey="P">previous</a> |</li>
+  <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+  <li><a href="../index.html">Documentation</a>»</li>
+
+          <li><a href="index.html" accesskey="U">The PDB File Format</a> »</li> 
+      </ul>
+    </div>
+
+
+    <div class="document">
+      <div class="documentwrapper">
+          <div class="body">
+            
+  <div class="section" id="the-pdb-public-symbol-stream">
+<h1>The PDB Public Symbol Stream<a class="headerlink" href="#the-pdb-public-symbol-stream" title="Permalink to this headline">¶</a></h1>
+</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="GlobalStream.html" title="The PDB Global Symbol Stream"
+             >next</a> |</li>
+        <li class="right" >
+          <a href="ModiStream.html" title="The Module Information Stream"
+             >previous</a> |</li>
+  <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+  <li><a href="../index.html">Documentation</a>»</li>
+
+          <li><a href="index.html" >The PDB File Format</a> »</li> 
+      </ul>
+    </div>
+    <div class="footer">
+        © Copyright 2003-2018, LLVM Project.
+      Last updated on 2018-05-10.
+      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/5.0.2/docs/PDB/TpiStream.html
URL: http://llvm.org/viewvc/llvm-project/www-releases/trunk/5.0.2/docs/PDB/TpiStream.html?rev=331981&view=auto
==============================================================================
--- www-releases/trunk/5.0.2/docs/PDB/TpiStream.html (added)
+++ www-releases/trunk/5.0.2/docs/PDB/TpiStream.html Thu May 10 06:54:16 2018
@@ -0,0 +1,102 @@
+
+
+<!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>The PDB TPI Stream — LLVM 5 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:     '5',
+        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 5 documentation" href="../index.html" />
+    <link rel="up" title="The PDB File Format" href="index.html" />
+    <link rel="next" title="The PDB DBI (Debug Info) Stream" href="DbiStream.html" />
+    <link rel="prev" title="The PDB Info Stream (aka the PDB Stream)" href="PdbStream.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="DbiStream.html" title="The PDB DBI (Debug Info) Stream"
+             accesskey="N">next</a> |</li>
+        <li class="right" >
+          <a href="PdbStream.html" title="The PDB Info Stream (aka the PDB Stream)"
+             accesskey="P">previous</a> |</li>
+  <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+  <li><a href="../index.html">Documentation</a>»</li>
+
+          <li><a href="index.html" accesskey="U">The PDB File Format</a> »</li> 
+      </ul>
+    </div>
+
+
+    <div class="document">
+      <div class="documentwrapper">
+          <div class="body">
+            
+  <div class="section" id="the-pdb-tpi-stream">
+<h1>The PDB TPI Stream<a class="headerlink" href="#the-pdb-tpi-stream" title="Permalink to this headline">¶</a></h1>
+</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="DbiStream.html" title="The PDB DBI (Debug Info) Stream"
+             >next</a> |</li>
+        <li class="right" >
+          <a href="PdbStream.html" title="The PDB Info Stream (aka the PDB Stream)"
+             >previous</a> |</li>
+  <li><a href="http://llvm.org/">LLVM Home</a> | </li>
+  <li><a href="../index.html">Documentation</a>»</li>
+
+          <li><a href="index.html" >The PDB File Format</a> »</li> 
+      </ul>
+    </div>
+    <div class="footer">
+        © Copyright 2003-2018, LLVM Project.
+      Last updated on 2018-05-10.
+      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/5.0.2/docs/PDB/index.html
URL: http://llvm.org/viewvc/llvm-project/www-releases/trunk/5.0.2/docs/PDB/index.html?rev=331981&view=auto
==============================================================================
--- www-releases/trunk/5.0.2/docs/PDB/index.html (added)
+++ www-releases/trunk/5.0.2/docs/PDB/index.html Thu May 10 06:54:16 2018
@@ -0,0 +1,358 @@
+
+
+<!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>The PDB File Format — LLVM 5 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:     '5',
+        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 5 documentation" href="../index.html" />
+    <link rel="next" title="The MSF File Format" href="MsfFile.html" />
+    <link rel="prev" title="Debugging with XRay" href="../XRayExample.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="MsfFile.html" title="The MSF File Format"
+             accesskey="N">next</a> |</li>
+        <li class="right" >
+          <a href="../XRayExample.html" title="Debugging with XRay"
+             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="the-pdb-file-format">
+<h1>The PDB File Format<a class="headerlink" href="#the-pdb-file-format" 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="#file-layout" id="id3">File Layout</a><ul>
+<li><a class="reference internal" href="#the-msf-container" id="id4">The MSF Container</a></li>
+<li><a class="reference internal" href="#streams" id="id5">Streams</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#codeview" id="id6">CodeView</a></li>
+</ul>
+</div>
+<div class="section" id="introduction">
+<span id="pdb-intro"></span><h2><a class="toc-backref" href="#id2">Introduction</a><a class="headerlink" href="#introduction" title="Permalink to this headline">¶</a></h2>
+<p>PDB (Program Database) is a file format invented by Microsoft and which contains
+debug information that can be consumed by debuggers and other tools.  Since
+officially supported APIs exist on Windows for querying debug information from
+PDBs even without the user understanding the internals of the file format, a
+large ecosystem of tools has been built for Windows to consume this format.  In
+order for Clang to be able to generate programs that can interoperate with these
+tools, it is necessary for us to generate PDB files ourselves.</p>
+<p>At the same time, LLVM has a long history of being able to cross-compile from
+any platform to any platform, and we wish for the same to be true here.  So it
+is necessary for us to understand the PDB file format at the byte-level so that
+we can generate PDB files entirely on our own.</p>
+<p>This manual describes what we know about the PDB file format today.  The layout
+of the file, the various streams contained within, the format of individual
+records within, and more.</p>
+<p>We would like to extend our heartfelt gratitude to Microsoft, without whom we
+would not be where we are today.  Much of the knowledge contained within this
+manual was learned through reading code published by Microsoft on their <a class="reference external" href="https://github.com/Microsoft/microsoft-pdb">GitHub
+repo</a>.</p>
+</div>
+<div class="section" id="file-layout">
+<span id="pdb-layout"></span><h2><a class="toc-backref" href="#id3">File Layout</a><a class="headerlink" href="#file-layout" title="Permalink to this headline">¶</a></h2>
+<div class="admonition important">
+<p class="first admonition-title">Important</p>
+<p class="last">Unless otherwise specified, all numeric values are encoded in little endian.
+If you see a type such as <tt class="docutils literal"><span class="pre">uint16_t</span></tt> or <tt class="docutils literal"><span class="pre">uint64_t</span></tt> going forward, always
+assume it is little endian!</p>
+</div>
+<div class="toctree-wrapper compound">
+</div>
+<div class="section" id="the-msf-container">
+<span id="msf"></span><h3><a class="toc-backref" href="#id4">The MSF Container</a><a class="headerlink" href="#the-msf-container" title="Permalink to this headline">¶</a></h3>
+<p>A PDB file is really just a special case of an MSF (Multi-Stream Format) file.
+An MSF file is actually a miniature “file system within a file”.  It contains
+multiple streams (aka files) which can represent arbitrary data, and these
+streams are divided into blocks which may not necessarily be contiguously
+laid out within the file (aka fragmented).  Additionally, the MSF contains a
+stream directory (aka MFT) which describes how the streams (files) are laid
+out within the MSF.</p>
+<p>For more information about the MSF container format, stream directory, and
+block layout, see <a class="reference internal" href="MsfFile.html"><em>The MSF File Format</em></a>.</p>
+</div>
+<div class="section" id="streams">
+<span id="id1"></span><h3><a class="toc-backref" href="#id5">Streams</a><a class="headerlink" href="#streams" title="Permalink to this headline">¶</a></h3>
+<p>The PDB format contains a number of streams which describe various information
+such as the types, symbols, source files, and compilands (e.g. object files)
+of a program, as well as some additional streams containing hash tables that are
+used by debuggers and other tools to provide fast lookup of records and types
+by name, and various other information about how the program was compiled such
+as the specific toolchain used, and more.  A summary of streams contained in a
+PDB file is as follows:</p>
+<table border="1" class="docutils">
+<colgroup>
+<col width="22%" />
+<col width="32%" />
+<col width="46%" />
+</colgroup>
+<thead valign="bottom">
+<tr class="row-odd"><th class="head">Name</th>
+<th class="head">Stream Index</th>
+<th class="head">Contents</th>
+</tr>
+</thead>
+<tbody valign="top">
+<tr class="row-even"><td>Old Directory</td>
+<td><ul class="first last simple">
+<li>Fixed Stream Index 0</li>
+</ul>
+</td>
+<td><ul class="first last simple">
+<li>Previous MSF Stream Directory</li>
+</ul>
+</td>
+</tr>
+<tr class="row-odd"><td>PDB Stream</td>
+<td><ul class="first last simple">
+<li>Fixed Stream Index 1</li>
+</ul>
+</td>
+<td><ul class="first last simple">
+<li>Basic File Information</li>
+<li>Fields to match EXE to this PDB</li>
+<li>Map of named streams to stream indices</li>
+</ul>
+</td>
+</tr>
+<tr class="row-even"><td>TPI Stream</td>
+<td><ul class="first last simple">
+<li>Fixed Stream Index 2</li>
+</ul>
+</td>
+<td><ul class="first last simple">
+<li>CodeView Type Records</li>
+<li>Index of TPI Hash Stream</li>
+</ul>
+</td>
+</tr>
+<tr class="row-odd"><td>DBI Stream</td>
+<td><ul class="first last simple">
+<li>Fixed Stream Index 3</li>
+</ul>
+</td>
+<td><ul class="first last simple">
+<li>Module/Compiland Information</li>
+<li>Indices of individual module streams</li>
+<li>Indices of public / global streams</li>
+<li>Section Contribution Information</li>
+<li>Source File Information</li>
+<li>FPO / PGO Data</li>
+</ul>
+</td>
+</tr>
+<tr class="row-even"><td>IPI Stream</td>
+<td><ul class="first last simple">
+<li>Fixed Stream Index 4</li>
+</ul>
+</td>
+<td><ul class="first last simple">
+<li>CodeView Type Records</li>
+<li>Index of IPI Hash Stream</li>
+</ul>
+</td>
+</tr>
+<tr class="row-odd"><td>/LinkInfo</td>
+<td><ul class="first last simple">
+<li>Contained in PDB Stream
+Named Stream map</li>
+</ul>
+</td>
+<td><ul class="first last simple">
+<li>Unknown</li>
+</ul>
+</td>
+</tr>
+<tr class="row-even"><td>/src/headerblock</td>
+<td><ul class="first last simple">
+<li>Contained in PDB Stream
+Named Stream map</li>
+</ul>
+</td>
+<td><ul class="first last simple">
+<li>Unknown</li>
+</ul>
+</td>
+</tr>
+<tr class="row-odd"><td>/names</td>
+<td><ul class="first last simple">
+<li>Contained in PDB Stream
+Named Stream map</li>
+</ul>
+</td>
+<td><ul class="first last simple">
+<li>PDB-wide global string table used for
+string de-duplication</li>
+</ul>
+</td>
+</tr>
+<tr class="row-even"><td>Module Info Stream</td>
+<td><ul class="first last simple">
+<li>Contained in DBI Stream</li>
+<li>One for each compiland</li>
+</ul>
+</td>
+<td><ul class="first last simple">
+<li>CodeView Symbol Records for this module</li>
+<li>Line Number Information</li>
+</ul>
+</td>
+</tr>
+<tr class="row-odd"><td>Public Stream</td>
+<td><ul class="first last simple">
+<li>Contained in DBI Stream</li>
+</ul>
+</td>
+<td><ul class="first last simple">
+<li>Public (Exported) Symbol Records</li>
+<li>Index of Public Hash Stream</li>
+</ul>
+</td>
+</tr>
+<tr class="row-even"><td>Global Stream</td>
+<td><ul class="first last simple">
+<li>Contained in DBI Stream</li>
+</ul>
+</td>
+<td><ul class="first last simple">
+<li>Global Symbol Records</li>
+<li>Index of Global Hash Stream</li>
+</ul>
+</td>
+</tr>
+<tr class="row-odd"><td>TPI Hash Stream</td>
+<td><ul class="first last simple">
+<li>Contained in TPI Stream</li>
+</ul>
+</td>
+<td><ul class="first last simple">
+<li>Hash table for looking up TPI records
+by name</li>
+</ul>
+</td>
+</tr>
+<tr class="row-even"><td>IPI Hash Stream</td>
+<td><ul class="first last simple">
+<li>Contained in IPI Stream</li>
+</ul>
+</td>
+<td><ul class="first last simple">
+<li>Hash table for looking up IPI records
+by name</li>
+</ul>
+</td>
+</tr>
+</tbody>
+</table>
+<p>More information about the structure of each of these can be found on the
+following pages:</p>
+<dl class="docutils">
+<dt><a class="reference internal" href="PdbStream.html"><em>The PDB Info Stream (aka the PDB Stream)</em></a></dt>
+<dd>Information about the PDB Info Stream and how it is used to match PDBs to EXEs.</dd>
+<dt><a class="reference internal" href="TpiStream.html"><em>The PDB TPI Stream</em></a></dt>
+<dd>Information about the TPI stream and the CodeView records contained within.</dd>
+<dt><a class="reference internal" href="DbiStream.html"><em>The PDB DBI (Debug Info) Stream</em></a></dt>
+<dd>Information about the DBI stream and relevant substreams including the Module Substreams,
+source file information, and CodeView symbol records contained within.</dd>
+<dt><a class="reference internal" href="ModiStream.html"><em>The Module Information Stream</em></a></dt>
+<dd>Information about the Module Information Stream, of which there is one for each compilation
+unit and the format of symbols contained within.</dd>
+<dt><a class="reference internal" href="PublicStream.html"><em>The PDB Public Symbol Stream</em></a></dt>
+<dd>Information about the Public Symbol Stream.</dd>
+<dt><a class="reference internal" href="GlobalStream.html"><em>The PDB Global Symbol Stream</em></a></dt>
+<dd>Information about the Global Symbol Stream.</dd>
+<dt><a class="reference internal" href="HashStream.html"><em>The TPI & IPI Hash Streams</em></a></dt>
+<dd>Information about the Hash Table stream, and how it can be used to quickly look up records
+by name.</dd>
+</dl>
+</div>
+</div>
+<div class="section" id="codeview">
+<h2><a class="toc-backref" href="#id6">CodeView</a><a class="headerlink" href="#codeview" title="Permalink to this headline">¶</a></h2>
+<p>CodeView is another format which comes into the picture.  While MSF defines
+the structure of the overall file, and PDB defines the set of streams that
+appear within the MSF file and the format of those streams, CodeView defines
+the format of <strong>symbol and type records</strong> that appear within specific streams.
+Refer to the pages on <a class="reference internal" href="CodeViewSymbols.html"><em>CodeView Symbol Records</em></a> and <a class="reference internal" href="CodeViewTypes.html"><em>CodeView Type Records</em></a> for
+more information about the CodeView format.</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="MsfFile.html" title="The MSF File Format"
+             >next</a> |</li>
+        <li class="right" >
+          <a href="../XRayExample.html" title="Debugging with XRay"
+             >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-2018, LLVM Project.
+      Last updated on 2018-05-10.
+      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/5.0.2/docs/Packaging.html
URL: http://llvm.org/viewvc/llvm-project/www-releases/trunk/5.0.2/docs/Packaging.html?rev=331981&view=auto
==============================================================================
--- www-releases/trunk/5.0.2/docs/Packaging.html (added)
+++ www-releases/trunk/5.0.2/docs/Packaging.html Thu May 10 06:54:16 2018
@@ -0,0 +1,170 @@
+
+
+<!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 5 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:     '5',
+        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 5 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-2018, LLVM Project.
+      Last updated on 2018-05-10.
+      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/5.0.2/docs/Passes.html
URL: http://llvm.org/viewvc/llvm-project/www-releases/trunk/5.0.2/docs/Passes.html?rev=331981&view=auto
==============================================================================
--- www-releases/trunk/5.0.2/docs/Passes.html (added)
+++ www-releases/trunk/5.0.2/docs/Passes.html Thu May 10 06:54:16 2018
@@ -0,0 +1,1172 @@
+
+
+<!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 5 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:     '5',
+        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 5 documentation" href="index.html" />
+    <link rel="next" title="YAML I/O" href="YamlIO.html" />
+    <link rel="prev" title="LLVM 5.0.0 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 5.0.0 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="#postdomfrontier-post-dominance-frontier-construction" id="id28"><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="id29"><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="id30"><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="id31"><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="id32"><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="id33"><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="id34"><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="id35"><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="id36"><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="id37"><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="id38"><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="id39"><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="id40"><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="id41"><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="id42"><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="id43">Transform Passes</a><ul>
+<li><a class="reference internal" href="#adce-aggressive-dead-code-elimination" id="id44"><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="id45"><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="id46"><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="id47"><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="id48"><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="id49"><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="id50"><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="id51"><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="id52"><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="id53"><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="id54"><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="id55"><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="id56"><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="id57"><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="id58"><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="id59"><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="id60"><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="id61"><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="id62"><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="id63"><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="id64"><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="id65"><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="id66"><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="id67"><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="id68"><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="id69"><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="id70"><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="id71"><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="id72"><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="id73"><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="id74"><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="id75"><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="id76"><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="id77"><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="id78"><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="id79"><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="id80"><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="id81"><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="id82"><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="id83"><tt class="docutils literal"><span class="pre">-memcpyopt</span></tt>: MemCpy Optimization</a></li>
+<li><a class="reference internal" href="#mergefunc-merge-functions" id="id84"><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="id85"><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="id86"><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="id87"><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="id88"><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="id89"><tt class="docutils literal"><span class="pre">-reg2mem</span></tt>: Demote all values to stack slots</a></li>
+<li><a class="reference internal" href="#sroa-scalar-replacement-of-aggregates" id="id90"><tt class="docutils literal"><span class="pre">-sroa</span></tt>: Scalar Replacement of Aggregates</a></li>
+<li><a class="reference internal" href="#sccp-sparse-conditional-constant-propagation" id="id91"><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="id92"><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="id93"><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="id94"><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="id95"><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="id96"><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="id97"><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="id98"><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="id99"><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="id100">Utility Passes</a><ul>
+<li><a class="reference internal" href="#deadarghax0r-dead-argument-hacking-bugpoint-use-only-do-not-use" id="id101"><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="id102"><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="id103"><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="id104"><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="id105"><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="id106"><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="id107"><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="id108"><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="id109"><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="id110"><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="postdomfrontier-post-dominance-frontier-construction">
+<h3><a class="toc-backref" href="#id28"><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="#id29"><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="#id30"><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="#id31"><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="#id32"><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="#id33"><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="#id34"><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="#id35"><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="#id36"><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="#id37"><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="#id38"><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="#id39"><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="#id40"><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="#id41"><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="#id42"><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="#id43">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="#id44"><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="#id45"><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="#id46"><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="#id47"><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="#id48"><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="#id49"><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="#id50"><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="#id51"><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="#id52"><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="#id53"><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="#id54"><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="#id55"><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="#id56"><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="#id57"><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="#id58"><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="#id59"><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="#id60"><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="#id61"><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="#id62"><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="#id63"><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="#id64"><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="#id65"><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="#id66"><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="#id67"><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="#id68"><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="#id69"><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="#id70"><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="#id71"><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="#id72"><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="#id73"><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="#id74"><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="#id75"><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="#id76"><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="#id77"><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="#id78"><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="#id79"><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="#id80"><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="#id81"><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="#id82"><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="#id83"><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="#id84"><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="#id85"><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="#id86"><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="#id87"><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="#id88"><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="#id89"><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="sroa-scalar-replacement-of-aggregates">
+<h3><a class="toc-backref" href="#id90"><tt class="docutils literal"><span class="pre">-sroa</span></tt>: Scalar Replacement of Aggregates</a><a class="headerlink" href="#sroa-scalar-replacement-of-aggregates" 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>
+</div>
+<div class="section" id="sccp-sparse-conditional-constant-propagation">
+<span id="passes-sccp"></span><h3><a class="toc-backref" href="#id91"><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="#id92"><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="#id93"><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="#id94"><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="#id95"><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="#id96"><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="#id97"><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="#id98"><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="#id99"><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="#id100">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="#id101"><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="#id102"><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="#id103"><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="#id104"><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="#id105"><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="#id106"><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="#id107"><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="#id108"><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="#id109"><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="#id110"><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 5.0.0 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-2018, LLVM Project.
+      Last updated on 2018-05-10.
+      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/5.0.2/docs/Phabricator.html
URL: http://llvm.org/viewvc/llvm-project/www-releases/trunk/5.0.2/docs/Phabricator.html?rev=331981&view=auto
==============================================================================
--- www-releases/trunk/5.0.2/docs/Phabricator.html (added)
+++ www-releases/trunk/5.0.2/docs/Phabricator.html Thu May 10 06:54:16 2018
@@ -0,0 +1,300 @@
+
+
+<!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 5 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:     '5',
+        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 5 documentation" href="index.html" />
+    <link rel="next" title="LLVM Community Code of Conduct" href="CodeOfConduct.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="CodeOfConduct.html" title="LLVM Community Code of Conduct"
+             accesskey="N">next</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><ul>
+<li><a class="reference internal" href="#subversion-and-arcanist" id="id6">Subversion and Arcanist</a></li>
+<li><a class="reference internal" href="#git-svn-and-arcanist" id="id7">git-svn and Arcanist</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#abandoning-a-change" id="id8">Abandoning a change</a></li>
+<li><a class="reference internal" href="#status" id="id9">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 you 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="https://secure.phabricator.com/book/phabricator/article/arcanist_quick_start/">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="https://secure.phabricator.com/book/phabricator/article/arcanist/">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">show</span> <span class="pre">HEAD</span> <span class="pre">-U999999</span> <span class="pre">></span> <span class="pre">mypatch.patch</span></tt></li>
+<li><tt class="docutils literal"><span class="pre">git</span> <span class="pre">format-patch</span> <span class="pre">-U999999</span> <span class="pre">@{u}</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 (see below for advice) and subscribe 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>
+<p>Choosing reviewers: You typically pick one or two people as initial reviewers.
+This choice is not crucial, because you are merely suggesting and not requiring
+them to participate. Many people will see the email notification on cfe-commits
+or llvm-commits, and if the subject line suggests the patch is something they
+should look at, they will.</p>
+<p>Here are a couple of ways to pick the initial reviewer(s):</p>
+<ul class="simple">
+<li>Use <tt class="docutils literal"><span class="pre">svn</span> <span class="pre">blame</span></tt> and the commit log to find names of people who have
+recently modified the same area of code that you are modifying.</li>
+<li>Look in CODE_OWNERS.TXT to see who might be responsible for that area.</li>
+<li>If you’ve discussed the change on a dev list, the people who participated
+might be appropriate reviewers.</li>
+</ul>
+<p>Even if you think the code owner is the busiest person in the world, it’s still
+okay to put them as a reviewer. Being the code owner means they have accepted
+responsibility for making sure the review happens.</p>
+</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>Once a patch has been reviewed and approved on Phabricator it can then be
+committed to trunk. If you do not have commit access, someone has to
+commit the change for you (with attribution). It is sufficient to add
+a comment to the approved review indicating you cannot commit the patch
+yourself. If you have commit access, there are multiple workflows to commit the
+change. Whichever method you follow it is recommended that your commit message
+ends with the line:</p>
+<div class="highlight-python"><pre>Differential Revision: <URL></pre>
+</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>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>
+<p>Note that if you use the Arcanist tool the <tt class="docutils literal"><span class="pre">Differential</span> <span class="pre">Revision</span></tt> line will
+be added automatically. If you don’t want to use Arcanist, you can add the
+<tt class="docutils literal"><span class="pre">Differential</span> <span class="pre">Revision</span></tt> line (as the last line) to the commit message
+yourself.</p>
+<p>Using the Arcanist tool can simplify the process of committing reviewed code
+as it will retrieve reviewers, the <tt class="docutils literal"><span class="pre">Differential</span> <span class="pre">Revision</span></tt>, etc from the review
+and place it in the commit message. Several methods of using Arcanist to commit
+code are given below. If you do not wish to use Arcanist then simply commit
+the reviewed patch as you would normally.</p>
+<p>Note that if you commit the change without using Arcanist and forget to add the
+<tt class="docutils literal"><span class="pre">Differential</span> <span class="pre">Revision</span></tt> line to your commit message then it is recommended
+that you close the review manually. In the web UI, under “Leap Into Action” put
+the SVN revision number in the Comment, set the Action to “Close Revision” and
+click Submit.  Note the review must have been Accepted first.</p>
+<div class="section" id="subversion-and-arcanist">
+<h3><a class="toc-backref" href="#id6">Subversion and Arcanist</a><a class="headerlink" href="#subversion-and-arcanist" title="Permalink to this headline">¶</a></h3>
+<p>On a clean Subversion working copy run the following (where <tt class="docutils literal"><span class="pre"><Revision></span></tt> is
+the Phabricator review number):</p>
+<div class="highlight-python"><pre>arc patch D<Revision>
+arc commit --revision D<Revision></pre>
+</div>
+<p>The first command will take the latest version of the reviewed patch and apply it to the working
+copy. The second command will commit this revision to trunk.</p>
+</div>
+<div class="section" id="git-svn-and-arcanist">
+<h3><a class="toc-backref" href="#id7">git-svn and Arcanist</a><a class="headerlink" href="#git-svn-and-arcanist" title="Permalink to this headline">¶</a></h3>
+<p>This presumes that the git repository has been configured as described in <a class="reference internal" href="GettingStarted.html#developers-work-with-git-svn"><em>For developers to work with git-svn</em></a>.</p>
+<p>On a clean Git repository on an up to date <tt class="docutils literal"><span class="pre">master</span></tt> branch run the
+following (where <tt class="docutils literal"><span class="pre"><Revision></span></tt> is the Phabricator review number):</p>
+<div class="highlight-python"><pre>arc patch D<Revision></pre>
+</div>
+<p>This will create a new branch called <tt class="docutils literal"><span class="pre">arcpatch-D<Revision></span></tt> based on the
+current <tt class="docutils literal"><span class="pre">master</span></tt> and will create a commit corresponding to <tt class="docutils literal"><span class="pre">D<Revision></span></tt> with a
+commit message derived from information in the Phabricator review.</p>
+<p>Check you are happy with the commit message and amend it if necessary. Now switch to
+the <tt class="docutils literal"><span class="pre">master</span></tt> branch and add the new commit to it and commit it to trunk. This
+can be done by running the following:</p>
+<div class="highlight-python"><pre>git checkout master
+git merge --ff-only arcpatch-D<Revision>
+git svn dcommit</pre>
+</div>
+</div>
+</div>
+<div class="section" id="abandoning-a-change">
+<h2><a class="toc-backref" href="#id8">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="#id9">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="CodeOfConduct.html" title="LLVM Community Code of Conduct"
+             >next</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-2018, LLVM Project.
+      Last updated on 2018-05-10.
+      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/5.0.2/docs/ProgrammersManual.html
URL: http://llvm.org/viewvc/llvm-project/www-releases/trunk/5.0.2/docs/ProgrammersManual.html?rev=331981&view=auto
==============================================================================
--- www-releases/trunk/5.0.2/docs/ProgrammersManual.html (added)
+++ www-releases/trunk/5.0.2/docs/ProgrammersManual.html Thu May 10 06:54:16 2018
@@ -0,0 +1,3608 @@
+
+
+<!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 5 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:     '5',
+        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 5 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="id8">Introduction</a></li>
+<li><a class="reference internal" href="#general-information" id="id9">General Information</a><ul>
+<li><a class="reference internal" href="#the-c-standard-template-library" id="id10">The C++ Standard Template Library</a></li>
+<li><a class="reference internal" href="#other-useful-references" id="id11">Other useful references</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#important-and-useful-llvm-apis" id="id12">Important and useful LLVM APIs</a><ul>
+<li><a class="reference internal" href="#the-isa-cast-and-dyn-cast-templates" id="id13">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="id14">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="id15">The <tt class="docutils literal"><span class="pre">StringRef</span></tt> class</a></li>
+<li><a class="reference internal" href="#the-twine-class" id="id16">The <tt class="docutils literal"><span class="pre">Twine</span></tt> class</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#formatting-strings-the-formatv-function" id="id17">Formatting strings (the <tt class="docutils literal"><span class="pre">formatv</span></tt> function)</a><ul>
+<li><a class="reference internal" href="#simple-formatting" id="id18">Simple formatting</a></li>
+<li><a class="reference internal" href="#custom-formatting" id="id19">Custom formatting</a></li>
+<li><a class="reference internal" href="#formatv-examples" id="id20"><tt class="docutils literal"><span class="pre">formatv</span></tt> Examples</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#error-handling" id="id21">Error handling</a><ul>
+<li><a class="reference internal" href="#programmatic-errors" id="id22">Programmatic Errors</a></li>
+<li><a class="reference internal" href="#recoverable-errors" id="id23">Recoverable Errors</a><ul>
+<li><a class="reference internal" href="#stringerror" id="id24">StringError</a></li>
+<li><a class="reference internal" href="#interoperability-with-std-error-code-and-erroror" id="id25">Interoperability with std::error_code and ErrorOr</a></li>
+<li><a class="reference internal" href="#returning-errors-from-error-handlers" id="id26">Returning Errors from error handlers</a></li>
+<li><a class="reference internal" href="#using-exitonerror-to-simplify-tool-code" id="id27">Using ExitOnError to simplify tool code</a></li>
+<li><a class="reference internal" href="#using-cantfail-to-simplify-safe-callsites" id="id28">Using cantFail to simplify safe callsites</a></li>
+<li><a class="reference internal" href="#fallible-constructors" id="id29">Fallible constructors</a></li>
+<li><a class="reference internal" href="#propagating-and-consuming-errors-based-on-types" id="id30">Propagating and consuming errors based on types</a></li>
+<li><a class="reference internal" href="#concatenating-errors-with-joinerrors" id="id31">Concatenating Errors with joinErrors</a></li>
+<li><a class="reference internal" href="#building-fallible-iterators-and-iterator-ranges" id="id32">Building fallible iterators and iterator ranges</a></li>
+</ul>
+</li>
+</ul>
+</li>
+<li><a class="reference internal" href="#passing-functions-and-other-callable-objects" id="id33">Passing functions and other callable objects</a><ul>
+<li><a class="reference internal" href="#function-template" id="id34">Function template</a></li>
+<li><a class="reference internal" href="#the-function-ref-class-template" id="id35">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="id36">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="id37">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="id38">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="#adding-debug-counters-to-aid-in-debugging-your-code" id="id39">Adding debug counters to aid in debugging your code</a></li>
+<li><a class="reference internal" href="#viewing-graphs-while-debugging-code" id="id40">Viewing graphs while debugging code</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#picking-the-right-data-structure-for-a-task" id="id41">Picking the Right Data Structure for a Task</a><ul>
+<li><a class="reference internal" href="#sequential-containers-std-vector-std-list-etc" id="id42">Sequential Containers (std::vector, std::list, etc)</a><ul>
+<li><a class="reference internal" href="#llvm-adt-arrayref-h" id="id43">llvm/ADT/ArrayRef.h</a></li>
+<li><a class="reference internal" href="#fixed-size-arrays" id="id44">Fixed Size Arrays</a></li>
+<li><a class="reference internal" href="#heap-allocated-arrays" id="id45">Heap Allocated Arrays</a></li>
+<li><a class="reference internal" href="#llvm-adt-tinyptrvector-h" id="id46">llvm/ADT/TinyPtrVector.h</a></li>
+<li><a class="reference internal" href="#llvm-adt-smallvector-h" id="id47">llvm/ADT/SmallVector.h</a></li>
+<li><a class="reference internal" href="#vector" id="id48"><vector></a></li>
+<li><a class="reference internal" href="#deque" id="id49"><deque></a></li>
+<li><a class="reference internal" href="#list" id="id50"><list></a></li>
+<li><a class="reference internal" href="#llvm-adt-ilist-h" id="id51">llvm/ADT/ilist.h</a></li>
+<li><a class="reference internal" href="#llvm-adt-packedvector-h" id="id52">llvm/ADT/PackedVector.h</a></li>
+<li><a class="reference internal" href="#ilist-traits" id="id53">ilist_traits</a></li>
+<li><a class="reference internal" href="#iplist" id="id54">iplist</a></li>
+<li><a class="reference internal" href="#llvm-adt-ilist-node-h" id="id55">llvm/ADT/ilist_node.h</a></li>
+<li><a class="reference internal" href="#sentinels" id="id56">Sentinels</a></li>
+<li><a class="reference internal" href="#other-sequential-container-options" id="id57">Other Sequential Container options</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#string-like-containers" id="id58">String-like containers</a><ul>
+<li><a class="reference internal" href="#llvm-adt-stringref-h" id="id59">llvm/ADT/StringRef.h</a></li>
+<li><a class="reference internal" href="#llvm-adt-twine-h" id="id60">llvm/ADT/Twine.h</a></li>
+<li><a class="reference internal" href="#llvm-adt-smallstring-h" id="id61">llvm/ADT/SmallString.h</a></li>
+<li><a class="reference internal" href="#std-string" id="id62">std::string</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#set-like-containers-std-set-smallset-setvector-etc" id="id63">Set-Like Containers (std::set, SmallSet, SetVector, etc)</a><ul>
+<li><a class="reference internal" href="#a-sorted-vector" id="id64">A sorted ‘vector’</a></li>
+<li><a class="reference internal" href="#llvm-adt-smallset-h" id="id65">llvm/ADT/SmallSet.h</a></li>
+<li><a class="reference internal" href="#llvm-adt-smallptrset-h" id="id66">llvm/ADT/SmallPtrSet.h</a></li>
+<li><a class="reference internal" href="#llvm-adt-stringset-h" id="id67">llvm/ADT/StringSet.h</a></li>
+<li><a class="reference internal" href="#llvm-adt-denseset-h" id="id68">llvm/ADT/DenseSet.h</a></li>
+<li><a class="reference internal" href="#llvm-adt-sparseset-h" id="id69">llvm/ADT/SparseSet.h</a></li>
+<li><a class="reference internal" href="#llvm-adt-sparsemultiset-h" id="id70">llvm/ADT/SparseMultiSet.h</a></li>
+<li><a class="reference internal" href="#llvm-adt-foldingset-h" id="id71">llvm/ADT/FoldingSet.h</a></li>
+<li><a class="reference internal" href="#set" id="id72"><set></a></li>
+<li><a class="reference internal" href="#llvm-adt-setvector-h" id="id73">llvm/ADT/SetVector.h</a></li>
+<li><a class="reference internal" href="#llvm-adt-uniquevector-h" id="id74">llvm/ADT/UniqueVector.h</a></li>
+<li><a class="reference internal" href="#llvm-adt-immutableset-h" id="id75">llvm/ADT/ImmutableSet.h</a></li>
+<li><a class="reference internal" href="#other-set-like-container-options" id="id76">Other Set-Like Container Options</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#map-like-containers-std-map-densemap-etc" id="id77">Map-Like Containers (std::map, DenseMap, etc)</a><ul>
+<li><a class="reference internal" href="#dss-sortedvectormap" id="id78">A sorted ‘vector’</a></li>
+<li><a class="reference internal" href="#llvm-adt-stringmap-h" id="id79">llvm/ADT/StringMap.h</a></li>
+<li><a class="reference internal" href="#llvm-adt-indexedmap-h" id="id80">llvm/ADT/IndexedMap.h</a></li>
+<li><a class="reference internal" href="#llvm-adt-densemap-h" id="id81">llvm/ADT/DenseMap.h</a></li>
+<li><a class="reference internal" href="#llvm-ir-valuemap-h" id="id82">llvm/IR/ValueMap.h</a></li>
+<li><a class="reference internal" href="#llvm-adt-intervalmap-h" id="id83">llvm/ADT/IntervalMap.h</a></li>
+<li><a class="reference internal" href="#map" id="id84"><map></a></li>
+<li><a class="reference internal" href="#llvm-adt-mapvector-h" id="id85">llvm/ADT/MapVector.h</a></li>
+<li><a class="reference internal" href="#llvm-adt-inteqclasses-h" id="id86">llvm/ADT/IntEqClasses.h</a></li>
+<li><a class="reference internal" href="#llvm-adt-immutablemap-h" id="id87">llvm/ADT/ImmutableMap.h</a></li>
+<li><a class="reference internal" href="#other-map-like-container-options" id="id88">Other Map-Like Container Options</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#bit-storage-containers-bitvector-sparsebitvector" id="id89">Bit storage containers (BitVector, SparseBitVector)</a><ul>
+<li><a class="reference internal" href="#bitvector" id="id90">BitVector</a></li>
+<li><a class="reference internal" href="#smallbitvector" id="id91">SmallBitVector</a></li>
+<li><a class="reference internal" href="#sparsebitvector" id="id92">SparseBitVector</a></li>
+</ul>
+</li>
+</ul>
+</li>
+<li><a class="reference internal" href="#debugging" id="id93">Debugging</a></li>
+<li><a class="reference internal" href="#helpful-hints-for-common-operations" id="id94">Helpful Hints for Common Operations</a><ul>
+<li><a class="reference internal" href="#basic-inspection-and-traversal-routines" id="id95">Basic Inspection and Traversal Routines</a><ul>
+<li><a class="reference internal" href="#iterating-over-the-basicblock-in-a-function" id="id96">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="id97">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="id98">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="id99">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="id100">Finding call sites: a slightly more complex example</a></li>
+<li><a class="reference internal" href="#treating-calls-and-invokes-the-same-way" id="id101">Treating calls and invokes the same way</a></li>
+<li><a class="reference internal" href="#iterating-over-def-use-use-def-chains" id="id102">Iterating over def-use & use-def chains</a></li>
+<li><a class="reference internal" href="#iterating-over-predecessors-successors-of-blocks" id="id103">Iterating over predecessors & successors of blocks</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#making-simple-changes" id="id104">Making simple changes</a><ul>
+<li><a class="reference internal" href="#creating-and-inserting-new-instructions" id="id105">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="id106">Deleting Instructions</a></li>
+<li><a class="reference internal" href="#replacing-an-instruction-with-another-value" id="id107">Replacing an Instruction with another Value</a><ul>
+<li><a class="reference internal" href="#replacing-individual-instructions" id="id108">Replacing individual instructions</a></li>
+<li><a class="reference internal" href="#schanges-deleting-sub" id="id109">Deleting Instructions</a></li>
+<li><a class="reference internal" href="#replacing-multiple-uses-of-users-and-values" id="id110">Replacing multiple uses of Users and Values</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#deleting-globalvariables" id="id111">Deleting GlobalVariables</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#how-to-create-types" id="id112">How to Create Types</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#threads-and-llvm" id="id113">Threads and LLVM</a><ul>
+<li><a class="reference internal" href="#ending-execution-with-llvm-shutdown" id="id114">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="id115">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="id116">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="id117">Threads and the JIT</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#advanced-topics" id="id118">Advanced Topics</a><ul>
+<li><a class="reference internal" href="#the-valuesymboltable-class" id="id119">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="id120">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="id121">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="id122">The waymarking algorithm</a></li>
+<li><a class="reference internal" href="#reference-implementation" id="id123">Reference implementation</a></li>
+<li><a class="reference internal" href="#tagging-considerations" id="id124">Tagging considerations</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#designing-type-hiercharies-and-polymorphic-interfaces" id="id125">Designing Type Hiercharies and Polymorphic Interfaces</a></li>
+<li><a class="reference internal" href="#abi-breaking-checks" id="id126">ABI Breaking Checks</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#the-core-llvm-class-hierarchy-reference" id="id127">The Core LLVM Class Hierarchy Reference</a><ul>
+<li><a class="reference internal" href="#the-type-class-and-derived-types" id="id128">The Type class and Derived Types</a><ul>
+<li><a class="reference internal" href="#important-public-methods" id="id129">Important Public Methods</a></li>
+<li><a class="reference internal" href="#important-derived-types" id="id130">Important Derived Types</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#the-module-class" id="id131">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="id132">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="id133">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="id134">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="id135">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="id136">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="id137">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="id138">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="id139">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="id140">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="id141">Important Subclasses of Constant</a></li>
+</ul>
+</li>
+<li><a class="reference internal" href="#the-globalvalue-class" id="id142">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="id143">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="id144">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="id145">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="id146">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="id147">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="id148">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="id149">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="id150">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="#id8">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="#id9">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="#id10">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="#id11">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="#id12">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="#id13">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="n">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="kc">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="k">auto</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="#id14">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="#id15">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="n">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/StringRef_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="#id16">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="formatting-strings-the-formatv-function">
+<span id="formatting-strings"></span><h3><a class="toc-backref" href="#id17">Formatting strings (the <tt class="docutils literal"><span class="pre">formatv</span></tt> function)</a><a class="headerlink" href="#formatting-strings-the-formatv-function" title="Permalink to this headline">¶</a></h3>
+<p>While LLVM doesn’t necessarily do a lot of string manipulation and parsing, it
+does do a lot of string formatting.  From diagnostic messages, to llvm tool
+outputs such as <tt class="docutils literal"><span class="pre">llvm-readobj</span></tt> to printing verbose disassembly listings and
+LLDB runtime logging, the need for string formatting is pervasive.</p>
+<p>The <tt class="docutils literal"><span class="pre">formatv</span></tt> is similar in spirit to <tt class="docutils literal"><span class="pre">printf</span></tt>, but uses a different syntax
+which borrows heavily from Python and C#.  Unlike <tt class="docutils literal"><span class="pre">printf</span></tt> it deduces the type
+to be formatted at compile time, so it does not need a format specifier such as
+<tt class="docutils literal"><span class="pre">%d</span></tt>.  This reduces the mental overhead of trying to construct portable format
+strings, especially for platform-specific types like <tt class="docutils literal"><span class="pre">size_t</span></tt> or pointer types.
+Unlike both <tt class="docutils literal"><span class="pre">printf</span></tt> and Python, it additionally fails to compile if LLVM does
+not know how to format the type.  These two properties ensure that the function
+is both safer and simpler to use than traditional formatting methods such as
+the <tt class="docutils literal"><span class="pre">printf</span></tt> family of functions.</p>
+<div class="section" id="simple-formatting">
+<h4><a class="toc-backref" href="#id18">Simple formatting</a><a class="headerlink" href="#simple-formatting" title="Permalink to this headline">¶</a></h4>
+<p>A call to <tt class="docutils literal"><span class="pre">formatv</span></tt> involves a single <strong>format string</strong> consisting of 0 or more
+<strong>replacement sequences</strong>, followed by a variable length list of <strong>replacement values</strong>.
+A replacement sequence is a string of the form <tt class="docutils literal"><span class="pre">{N[[,align]:style]}</span></tt>.</p>
+<p><tt class="docutils literal"><span class="pre">N</span></tt> refers to the 0-based index of the argument from the list of replacement
+values.  Note that this means it is possible to reference the same parameter
+multiple times, possibly with different style and/or alignment options, in any order.</p>
+<p><tt class="docutils literal"><span class="pre">align</span></tt> is an optional string specifying the width of the field to format
+the value into, and the alignment of the value within the field.  It is specified as
+an optional <strong>alignment style</strong> followed by a positive integral <strong>field width</strong>.  The
+alignment style can be one of the characters <tt class="docutils literal"><span class="pre">-</span></tt> (left align), <tt class="docutils literal"><span class="pre">=</span></tt> (center align),
+or <tt class="docutils literal"><span class="pre">+</span></tt> (right align).  The default is right aligned.</p>
+<p><tt class="docutils literal"><span class="pre">style</span></tt> is an optional string consisting of a type specific that controls the
+formatting of the value.  For example, to format a floating point value as a percentage,
+you can use the style option <tt class="docutils literal"><span class="pre">P</span></tt>.</p>
+</div>
+<div class="section" id="custom-formatting">
+<h4><a class="toc-backref" href="#id19">Custom formatting</a><a class="headerlink" href="#custom-formatting" title="Permalink to this headline">¶</a></h4>
+<p>There are two ways to customize the formatting behavior for a type.</p>
+<ol class="arabic simple">
+<li>Provide a template specialization of <tt class="docutils literal"><span class="pre">llvm::format_provider<T></span></tt> for your
+type <tt class="docutils literal"><span class="pre">T</span></tt> with the appropriate static format method.</li>
+</ol>
+<blockquote>
+<div><div class="highlight-c++"><div class="highlight"><pre><span class="k">namespace</span> <span class="n">llvm</span> <span class="p">{</span>
+  <span class="k">template</span><span class="o"><></span>
+  <span class="k">struct</span> <span class="n">format_provider</span><span class="o"><</span><span class="n">MyFooBar</span><span class="o">></span> <span class="p">{</span>
+    <span class="k">static</span> <span class="kt">void</span> <span class="n">format</span><span class="p">(</span><span class="k">const</span> <span class="n">MyFooBar</span> <span class="o">&</span><span class="n">V</span><span class="p">,</span> <span class="n">raw_ostream</span> <span class="o">&</span><span class="n">Stream</span><span class="p">,</span> <span class="n">StringRef</span> <span class="n">Style</span><span class="p">)</span> <span class="p">{</span>
+      <span class="c1">// Do whatever is necessary to format `V` into `Stream`</span>
+    <span class="p">}</span>
+  <span class="p">};</span>
+  <span class="kt">void</span> <span class="n">foo</span><span class="p">()</span> <span class="p">{</span>
+    <span class="n">MyFooBar</span> <span class="n">X</span><span class="p">;</span>
+    <span class="n">std</span><span class="o">::</span><span class="n">string</span> <span class="n">S</span> <span class="o">=</span> <span class="n">formatv</span><span class="p">(</span><span class="s">"{0}"</span><span class="p">,</span> <span class="n">X</span><span class="p">);</span>
+  <span class="p">}</span>
+<span class="p">}</span>
+</pre></div>
+</div>
+<p>This is a useful extensibility mechanism for adding support for formatting your own
+custom types with your own custom Style options.  But it does not help when you want
+to extend the mechanism for formatting a type that the library already knows how to
+format.  For that, we need something else.</p>
+</div></blockquote>
+<ol class="arabic simple" start="2">
+<li>Provide a <strong>format adapter</strong> inheriting from <tt class="docutils literal"><span class="pre">llvm::FormatAdapter<T></span></tt>.</li>
+</ol>
+<blockquote>
+<div><div class="highlight-c++"><div class="highlight"><pre><span class="k">namespace</span> <span class="n">anything</span> <span class="p">{</span>
+  <span class="k">struct</span> <span class="n">format_int_custom</span> <span class="o">:</span> <span class="k">public</span> <span class="n">llvm</span><span class="o">::</span><span class="n">FormatAdapter</span><span class="o"><</span><span class="kt">int</span><span class="o">></span> <span class="p">{</span>
+    <span class="k">explicit</span> <span class="n">format_int_custom</span><span class="p">(</span><span class="kt">int</span> <span class="n">N</span><span class="p">)</span> <span class="o">:</span> <span class="n">llvm</span><span class="o">::</span><span class="n">FormatAdapter</span><span class="o"><</span><span class="kt">int</span><span class="o">></span><span class="p">(</span><span class="n">N</span><span class="p">)</span> <span class="p">{}</span>
+    <span class="kt">void</span> <span class="n">format</span><span class="p">(</span><span class="n">llvm</span><span class="o">::</span><span class="n">raw_ostream</span> <span class="o">&</span><span class="n">Stream</span><span class="p">,</span> <span class="n">StringRef</span> <span class="n">Style</span><span class="p">)</span> <span class="n">override</span> <span class="p">{</span>
+      <span class="c1">// Do whatever is necessary to format ``this->Item`` into ``Stream``</span>
+    <span class="p">}</span>
+  <span class="p">};</span>
+<span class="p">}</span>
+<span class="k">namespace</span> <span class="n">llvm</span> <span class="p">{</span>
+  <span class="kt">void</span> <span class="n">foo</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">S</span> <span class="o">=</span> <span class="n">formatv</span><span class="p">(</span><span class="s">"{0}"</span><span class="p">,</span> <span class="n">anything</span><span class="o">::</span><span class="n">format_int_custom</span><span class="p">(</span><span class="mi">42</span><span class="p">));</span>
+  <span class="p">}</span>
+<span class="p">}</span>
+</pre></div>
+</div>
+<p>If the type is detected to be derived from <tt class="docutils literal"><span class="pre">FormatAdapter<T></span></tt>, <tt class="docutils literal"><span class="pre">formatv</span></tt>
+will call the
+<tt class="docutils literal"><span class="pre">format</span></tt> method on the argument passing in the specified style.  This allows
+one to provide custom formatting of any type, including one which already has
+a builtin format provider.</p>
+</div></blockquote>
+</div>
+<div class="section" id="formatv-examples">
+<h4><a class="toc-backref" href="#id20"><tt class="docutils literal"><span class="pre">formatv</span></tt> Examples</a><a class="headerlink" href="#formatv-examples" title="Permalink to this headline">¶</a></h4>
+<p>Below is intended to provide an incomplete set of examples demonstrating
+the usage of <tt class="docutils literal"><span class="pre">formatv</span></tt>.  More information can be found by reading the
+doxygen documentation or by looking at the unit test suite.</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">std</span><span class="o">::</span><span class="n">string</span> <span class="n">S</span><span class="p">;</span>
+<span class="c1">// Simple formatting of basic types and implicit string conversion.</span>
+<span class="n">S</span> <span class="o">=</span> <span class="n">formatv</span><span class="p">(</span><span class="s">"{0} ({1:P})"</span><span class="p">,</span> <span class="mi">7</span><span class="p">,</span> <span class="mf">0.35</span><span class="p">);</span>  <span class="c1">// S == "7 (35.00%)"</span>
+
+<span class="c1">// Out-of-order referencing and multi-referencing</span>
+<span class="n">outs</span><span class="p">()</span> <span class="o"><<</span> <span class="n">formatv</span><span class="p">(</span><span class="s">"{0} {2} {1} {0}"</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="s">"test"</span><span class="p">,</span> <span class="mi">3</span><span class="p">);</span> <span class="c1">// prints "1 3 test 1"</span>
+
+<span class="c1">// Left, right, and center alignment</span>
+<span class="n">S</span> <span class="o">=</span> <span class="n">formatv</span><span class="p">(</span><span class="s">"{0,7}"</span><span class="p">,</span>  <span class="sc">'a'</span><span class="p">);</span>  <span class="c1">// S == "      a";</span>
+<span class="n">S</span> <span class="o">=</span> <span class="n">formatv</span><span class="p">(</span><span class="s">"{0,-7}"</span><span class="p">,</span> <span class="sc">'a'</span><span class="p">);</span>  <span class="c1">// S == "a      ";</span>
+<span class="n">S</span> <span class="o">=</span> <span class="n">formatv</span><span class="p">(</span><span class="s">"{0,=7}"</span><span class="p">,</span> <span class="sc">'a'</span><span class="p">);</span>  <span class="c1">// S == "   a   ";</span>
+<span class="n">S</span> <span class="o">=</span> <span class="n">formatv</span><span class="p">(</span><span class="s">"{0,+7}"</span><span class="p">,</span> <span class="sc">'a'</span><span class="p">);</span>  <span class="c1">// S == "      a";</span>
+
+<span class="c1">// Custom styles</span>
+<span class="n">S</span> <span class="o">=</span> <span class="n">formatv</span><span class="p">(</span><span class="s">"{0:N} - {0:x} - {1:E}"</span><span class="p">,</span> <span class="mi">12345</span><span class="p">,</span> <span class="mi">123908342</span><span class="p">);</span> <span class="c1">// S == "12,345 - 0x3039 - 1.24E8"</span>
+
+<span class="c1">// Adapters</span>
+<span class="n">S</span> <span class="o">=</span> <span class="n">formatv</span><span class="p">(</span><span class="s">"{0}"</span><span class="p">,</span> <span class="n">fmt_align</span><span class="p">(</span><span class="mi">42</span><span class="p">,</span> <span class="n">AlignStyle</span><span class="o">::</span><span class="n">Center</span><span class="p">,</span> <span class="mi">7</span><span class="p">));</span>  <span class="c1">// S == "  42   "</span>
+<span class="n">S</span> <span class="o">=</span> <span class="n">formatv</span><span class="p">(</span><span class="s">"{0}"</span><span class="p">,</span> <span class="n">fmt_repeat</span><span class="p">(</span><span class="s">"hi"</span><span class="p">,</span> <span class="mi">3</span><span class="p">));</span> <span class="c1">// S == "hihihi"</span>
+<span class="n">S</span> <span class="o">=</span> <span class="n">formatv</span><span class="p">(</span><span class="s">"{0}"</span><span class="p">,</span> <span class="n">fmt_pad</span><span class="p">(</span><span class="s">"hi"</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">6</span><span class="p">));</span> <span class="c1">// S == "  hi      "</span>
+
+<span class="c1">// Ranges</span>
+<span class="n">std</span><span class="o">::</span><span class="n">vector</span><span class="o"><</span><span class="kt">int</span><span class="o">></span> <span class="n">V</span> <span class="o">=</span> <span class="p">{</span><span class="mi">8</span><span class="p">,</span> <span class="mi">9</span><span class="p">,</span> <span class="mi">10</span><span class="p">};</span>
+<span class="n">S</span> <span class="o">=</span> <span class="n">formatv</span><span class="p">(</span><span class="s">"{0}"</span><span class="p">,</span> <span class="n">make_range</span><span class="p">(</span><span class="n">V</span><span class="p">.</span><span class="n">begin</span><span class="p">(),</span> <span class="n">V</span><span class="p">.</span><span class="n">end</span><span class="p">()));</span> <span class="c1">// S == "8, 9, 10"</span>
+<span class="n">S</span> <span class="o">=</span> <span class="n">formatv</span><span class="p">(</span><span class="s">"{0:$[+]}"</span><span class="p">,</span> <span class="n">make_range</span><span class="p">(</span><span class="n">V</span><span class="p">.</span><span class="n">begin</span><span class="p">(),</span> <span class="n">V</span><span class="p">.</span><span class="n">end</span><span class="p">()));</span> <span class="c1">// S == "8+9+10"</span>
+<span class="n">S</span> <span class="o">=</span> <span class="n">formatv</span><span class="p">(</span><span class="s">"{0:$[ + ]@[x]}"</span><span class="p">,</span> <span class="n">make_range</span><span class="p">(</span><span class="n">V</span><span class="p">.</span><span class="n">begin</span><span class="p">(),</span> <span class="n">V</span><span class="p">.</span><span class="n">end</span><span class="p">()));</span> <span class="c1">// S == "0x8 + 0x9 + 0xA"</span>
+</pre></div>
+</div>
+</div>
+</div>
+<div class="section" id="error-handling">
+<span id="error-apis"></span><h3><a class="toc-backref" href="#id21">Error handling</a><a class="headerlink" href="#error-handling" title="Permalink to this headline">¶</a></h3>
+<p>Proper error handling helps us identify bugs in our code, and helps end-users
+understand errors in their tool usage. Errors fall into two broad categories:
+<em>programmatic</em> and <em>recoverable</em>, with different strategies for handling and
+reporting.</p>
+<div class="section" id="programmatic-errors">
+<h4><a class="toc-backref" href="#id22">Programmatic Errors</a><a class="headerlink" href="#programmatic-errors" title="Permalink to this headline">¶</a></h4>
+<p>Programmatic errors are violations of program invariants or API contracts, and
+represent bugs within the program itself. Our aim is to document invariants, and
+to abort quickly at the point of failure (providing some basic diagnostic) when
+invariants are broken at runtime.</p>
+<p>The fundamental tools for handling programmatic errors are assertions and the
+llvm_unreachable function. Assertions are used to express invariant conditions,
+and should include a message describing the invariant:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">assert</span><span class="p">(</span><span class="n">isPhysReg</span><span class="p">(</span><span class="n">R</span><span class="p">)</span> <span class="o">&&</span> <span class="s">"All virt regs should have been allocated already."</span><span class="p">);</span>
+</pre></div>
+</div>
+<p>The llvm_unreachable function can be used to document areas of control flow
+that should never be entered if the program invariants hold:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="k">enum</span> <span class="p">{</span> <span class="n">Foo</span><span class="p">,</span> <span class="n">Bar</span><span class="p">,</span> <span class="n">Baz</span> <span class="p">}</span> <span class="n">X</span> <span class="o">=</span> <span class="n">foo</span><span class="p">();</span>
+
+<span class="k">switch</span> <span class="p">(</span><span class="n">X</span><span class="p">)</span> <span class="p">{</span>
+  <span class="k">case</span> <span class="nl">Foo:</span> <span class="cm">/* Handle Foo */</span><span class="p">;</span> <span class="k">break</span><span class="p">;</span>
+  <span class="k">case</span> <span class="nl">Bar:</span> <span class="cm">/* Handle Bar */</span><span class="p">;</span> <span class="k">break</span><span class="p">;</span>
+  <span class="k">default</span><span class="o">:</span>
+    <span class="n">llvm_unreachable</span><span class="p">(</span><span class="s">"X should be Foo or Bar here"</span><span class="p">);</span>
+<span class="p">}</span>
+</pre></div>
+</div>
+</div>
+<div class="section" id="recoverable-errors">
+<h4><a class="toc-backref" href="#id23">Recoverable Errors</a><a class="headerlink" href="#recoverable-errors" title="Permalink to this headline">¶</a></h4>
+<p>Recoverable errors represent an error in the program’s environment, for example
+a resource failure (a missing file, a dropped network connection, etc.), or
+malformed input. These errors should be detected and communicated to a level of
+the program where they can be handled appropriately. Handling the error may be
+as simple as reporting the issue to the user, or it may involve attempts at
+recovery.</p>
+<p>Recoverable errors are modeled using LLVM’s <tt class="docutils literal"><span class="pre">Error</span></tt> scheme. This scheme
+represents errors using function return values, similar to classic C integer
+error codes, or C++’s <tt class="docutils literal"><span class="pre">std::error_code</span></tt>. However, the <tt class="docutils literal"><span class="pre">Error</span></tt> class is
+actually a lightweight wrapper for user-defined error types, allowing arbitrary
+information to be attached to describe the error. This is similar to the way C++
+exceptions allow throwing of user-defined types.</p>
+<p>Success values are created by calling <tt class="docutils literal"><span class="pre">Error::success()</span></tt>, E.g.:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">Error</span> <span class="n">foo</span><span class="p">()</span> <span class="p">{</span>
+  <span class="c1">// Do something.</span>
+  <span class="c1">// Return success.</span>
+  <span class="k">return</span> <span class="n">Error</span><span class="o">::</span><span class="n">success</span><span class="p">();</span>
+<span class="p">}</span>
+</pre></div>
+</div>
+<p>Success values are very cheap to construct and return - they have minimal
+impact on program performance.</p>
+<p>Failure values are constructed using <tt class="docutils literal"><span class="pre">make_error<T></span></tt>, where <tt class="docutils literal"><span class="pre">T</span></tt> is any class
+that inherits from the ErrorInfo utility, E.g.:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="k">class</span> <span class="nc">BadFileFormat</span> <span class="o">:</span> <span class="k">public</span> <span class="n">ErrorInfo</span><span class="o"><</span><span class="n">BadFileFormat</span><span class="o">></span> <span class="p">{</span>
+<span class="k">public</span><span class="o">:</span>
+  <span class="k">static</span> <span class="kt">char</span> <span class="n">ID</span><span class="p">;</span>
+  <span class="n">std</span><span class="o">::</span><span class="n">string</span> <span class="n">Path</span><span class="p">;</span>
+
+  <span class="n">BadFileFormat</span><span class="p">(</span><span class="n">StringRef</span> <span class="n">Path</span><span class="p">)</span> <span class="o">:</span> <span class="n">Path</span><span class="p">(</span><span class="n">Path</span><span class="p">.</span><span class="n">str</span><span class="p">())</span> <span class="p">{}</span>
+
+  <span class="kt">void</span> <span class="n">log</span><span class="p">(</span><span class="n">raw_ostream</span> <span class="o">&</span><span class="n">OS</span><span class="p">)</span> <span class="k">const</span> <span class="n">override</span> <span class="p">{</span>
+    <span class="n">OS</span> <span class="o"><<</span> <span class="n">Path</span> <span class="o"><<</span> <span class="s">" is malformed"</span><span class="p">;</span>
+  <span class="p">}</span>
+
+  <span class="n">std</span><span class="o">::</span><span class="n">error_code</span> <span class="n">convertToErrorCode</span><span class="p">()</span> <span class="k">const</span> <span class="n">override</span> <span class="p">{</span>
+    <span class="k">return</span> <span class="n">make_error_code</span><span class="p">(</span><span class="n">object_error</span><span class="o">::</span><span class="n">parse_failed</span><span class="p">);</span>
+  <span class="p">}</span>
+<span class="p">};</span>
+
+<span class="kt">char</span> <span class="n">BadFileFormat</span><span class="o">::</span><span class="n">ID</span><span class="p">;</span> <span class="c1">// This should be declared in the C++ file.</span>
+
+<span class="n">Error</span> <span class="n">printFormattedFile</span><span class="p">(</span><span class="n">StringRef</span> <span class="n">Path</span><span class="p">)</span> <span class="p">{</span>
+  <span class="k">if</span> <span class="p">(</span><span class="o"><</span><span class="n">check</span> <span class="k">for</span> <span class="n">valid</span> <span class="n">format</span><span class="o">></span><span class="p">)</span>
+    <span class="k">return</span> <span class="n">make_error</span><span class="o"><</span><span class="n">InvalidObjectFile</span><span class="o">></span><span class="p">(</span><span class="n">Path</span><span class="p">);</span>
+  <span class="c1">// print file contents.</span>
+  <span class="k">return</span> <span class="n">Error</span><span class="o">::</span><span class="n">success</span><span class="p">();</span>
+<span class="p">}</span>
+</pre></div>
+</div>
+<p>Error values can be implicitly converted to bool: true for error, false for
+success, enabling the following idiom:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">Error</span> <span class="n">mayFail</span><span class="p">();</span>
+
+<span class="n">Error</span> <span class="n">foo</span><span class="p">()</span> <span class="p">{</span>
+  <span class="k">if</span> <span class="p">(</span><span class="k">auto</span> <span class="n">Err</span> <span class="o">=</span> <span class="n">mayFail</span><span class="p">())</span>
+    <span class="k">return</span> <span class="n">Err</span><span class="p">;</span>
+  <span class="c1">// Success! We can proceed.</span>
+  <span class="p">...</span>
+</pre></div>
+</div>
+<p>For functions that can fail but need to return a value the <tt class="docutils literal"><span class="pre">Expected<T></span></tt>
+utility can be used. Values of this type can be constructed with either a
+<tt class="docutils literal"><span class="pre">T</span></tt>, or an <tt class="docutils literal"><span class="pre">Error</span></tt>. Expected<T> values are also implicitly convertible to
+boolean, but with the opposite convention to <tt class="docutils literal"><span class="pre">Error</span></tt>: true for success, false
+for error. If success, the <tt class="docutils literal"><span class="pre">T</span></tt> value can be accessed via the dereference
+operator. If failure, the <tt class="docutils literal"><span class="pre">Error</span></tt> value can be extracted using the
+<tt class="docutils literal"><span class="pre">takeError()</span></tt> method. Idiomatic usage looks like:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">Expected</span><span class="o"><</span><span class="n">FormattedFile</span><span class="o">></span> <span class="n">openFormattedFile</span><span class="p">(</span><span class="n">StringRef</span> <span class="n">Path</span><span class="p">)</span> <span class="p">{</span>
+  <span class="c1">// If badly formatted, return an error.</span>
+  <span class="k">if</span> <span class="p">(</span><span class="k">auto</span> <span class="n">Err</span> <span class="o">=</span> <span class="n">checkFormat</span><span class="p">(</span><span class="n">Path</span><span class="p">))</span>
+    <span class="k">return</span> <span class="n">std</span><span class="o">::</span><span class="n">move</span><span class="p">(</span><span class="n">Err</span><span class="p">);</span>
+  <span class="c1">// Otherwise return a FormattedFile instance.</span>
+  <span class="k">return</span> <span class="n">FormattedFile</span><span class="p">(</span><span class="n">Path</span><span class="p">);</span>
+<span class="p">}</span>
+
+<span class="n">Error</span> <span class="n">processFormattedFile</span><span class="p">(</span><span class="n">StringRef</span> <span class="n">Path</span><span class="p">)</span> <span class="p">{</span>
+  <span class="c1">// Try to open a formatted file</span>
+  <span class="k">if</span> <span class="p">(</span><span class="k">auto</span> <span class="n">FileOrErr</span> <span class="o">=</span> <span class="n">openFormattedFile</span><span class="p">(</span><span class="n">Path</span><span class="p">))</span> <span class="p">{</span>
+    <span class="c1">// On success, grab a reference to the file and continue.</span>
+    <span class="k">auto</span> <span class="o">&</span><span class="n">File</span> <span class="o">=</span> <span class="o">*</span><span class="n">FileOrErr</span><span class="p">;</span>
+    <span class="p">...</span>
+  <span class="p">}</span> <span class="k">else</span>
+    <span class="c1">// On error, extract the Error value and return it.</span>
+    <span class="k">return</span> <span class="n">FileOrErr</span><span class="p">.</span><span class="n">takeError</span><span class="p">();</span>
+<span class="p">}</span>
+</pre></div>
+</div>
+<p>If an <tt class="docutils literal"><span class="pre">Expected<T></span></tt> value is in success mode then the <tt class="docutils literal"><span class="pre">takeError()</span></tt> method
+will return a success value. Using this fact, the above function can be
+rewritten as:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">Error</span> <span class="n">processFormattedFile</span><span class="p">(</span><span class="n">StringRef</span> <span class="n">Path</span><span class="p">)</span> <span class="p">{</span>
+  <span class="c1">// Try to open a formatted file</span>
+  <span class="k">auto</span> <span class="n">FileOrErr</span> <span class="o">=</span> <span class="n">openFormattedFile</span><span class="p">(</span><span class="n">Path</span><span class="p">);</span>
+  <span class="k">if</span> <span class="p">(</span><span class="k">auto</span> <span class="n">Err</span> <span class="o">=</span> <span class="n">FileOrErr</span><span class="p">.</span><span class="n">takeError</span><span class="p">())</span>
+    <span class="c1">// On error, extract the Error value and return it.</span>
+    <span class="k">return</span> <span class="n">Err</span><span class="p">;</span>
+  <span class="c1">// On success, grab a reference to the file and continue.</span>
+  <span class="k">auto</span> <span class="o">&</span><span class="n">File</span> <span class="o">=</span> <span class="o">*</span><span class="n">FileOrErr</span><span class="p">;</span>
+  <span class="p">...</span>
+<span class="p">}</span>
+</pre></div>
+</div>
+<p>This second form is often more readable for functions that involve multiple
+<tt class="docutils literal"><span class="pre">Expected<T></span></tt> values as it limits the indentation required.</p>
+<p>All <tt class="docutils literal"><span class="pre">Error</span></tt> instances, whether success or failure, must be either checked or
+moved from (via <tt class="docutils literal"><span class="pre">std::move</span></tt> or a return) before they are destructed.
+Accidentally discarding an unchecked error will cause a program abort at the
+point where the unchecked value’s destructor is run, making it easy to identify
+and fix violations of this rule.</p>
+<p>Success values are considered checked once they have been tested (by invoking
+the boolean conversion operator):</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="k">if</span> <span class="p">(</span><span class="k">auto</span> <span class="n">Err</span> <span class="o">=</span> <span class="n">mayFail</span><span class="p">(...))</span>
+  <span class="k">return</span> <span class="n">Err</span><span class="p">;</span> <span class="c1">// Failure value - move error to caller.</span>
+
+<span class="c1">// Safe to continue: Err was checked.</span>
+</pre></div>
+</div>
+<p>In contrast, the following code will always cause an abort, even if <tt class="docutils literal"><span class="pre">mayFail</span></tt>
+returns a success value:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">mayFail</span><span class="p">();</span>
+<span class="c1">// Program will always abort here, even if mayFail() returns Success, since</span>
+<span class="c1">// the value is not checked.</span>
+</pre></div>
+</div>
+<p>Failure values are considered checked once a handler for the error type has
+been activated:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">handleErrors</span><span class="p">(</span>
+  <span class="n">processFormattedFile</span><span class="p">(...),</span>
+  <span class="p">[](</span><span class="k">const</span> <span class="n">BadFileFormat</span> <span class="o">&</span><span class="n">BFF</span><span class="p">)</span> <span class="p">{</span>
+    <span class="n">report</span><span class="p">(</span><span class="s">"Unable to process "</span> <span class="o">+</span> <span class="n">BFF</span><span class="p">.</span><span class="n">Path</span> <span class="o">+</span> <span class="s">": bad format"</span><span class="p">);</span>
+  <span class="p">},</span>
+  <span class="p">[](</span><span class="k">const</span> <span class="n">FileNotFound</span> <span class="o">&</span><span class="n">FNF</span><span class="p">)</span> <span class="p">{</span>
+    <span class="n">report</span><span class="p">(</span><span class="s">"File not found "</span> <span class="o">+</span> <span class="n">FNF</span><span class="p">.</span><span class="n">Path</span><span class="p">);</span>
+  <span class="p">});</span>
+</pre></div>
+</div>
+<p>The <tt class="docutils literal"><span class="pre">handleErrors</span></tt> function takes an error as its first argument, followed by
+a variadic list of “handlers”, each of which must be a callable type (a
+function, lambda, or class with a call operator) with one argument. The
+<tt class="docutils literal"><span class="pre">handleErrors</span></tt> function will visit each handler in the sequence and check its
+argument type against the dynamic type of the error, running the first handler
+that matches. This is the same decision process that is used decide which catch
+clause to run for a C++ exception.</p>
+<p>Since the list of handlers passed to <tt class="docutils literal"><span class="pre">handleErrors</span></tt> may not cover every error
+type that can occur, the <tt class="docutils literal"><span class="pre">handleErrors</span></tt> function also returns an Error value
+that must be checked or propagated. If the error value that is passed to
+<tt class="docutils literal"><span class="pre">handleErrors</span></tt> does not match any of the handlers it will be returned from
+handleErrors. Idiomatic use of <tt class="docutils literal"><span class="pre">handleErrors</span></tt> thus looks like:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="k">if</span> <span class="p">(</span><span class="k">auto</span> <span class="n">Err</span> <span class="o">=</span>
+      <span class="n">handleErrors</span><span class="p">(</span>
+        <span class="n">processFormattedFile</span><span class="p">(...),</span>
+        <span class="p">[](</span><span class="k">const</span> <span class="n">BadFileFormat</span> <span class="o">&</span><span class="n">BFF</span><span class="p">)</span> <span class="p">{</span>
+          <span class="n">report</span><span class="p">(</span><span class="s">"Unable to process "</span> <span class="o">+</span> <span class="n">BFF</span><span class="p">.</span><span class="n">Path</span> <span class="o">+</span> <span class="s">": bad format"</span><span class="p">);</span>
+        <span class="p">},</span>
+        <span class="p">[](</span><span class="k">const</span> <span class="n">FileNotFound</span> <span class="o">&</span><span class="n">FNF</span><span class="p">)</span> <span class="p">{</span>
+          <span class="n">report</span><span class="p">(</span><span class="s">"File not found "</span> <span class="o">+</span> <span class="n">FNF</span><span class="p">.</span><span class="n">Path</span><span class="p">);</span>
+        <span class="p">}))</span>
+  <span class="k">return</span> <span class="n">Err</span><span class="p">;</span>
+</pre></div>
+</div>
+<p>In cases where you truly know that the handler list is exhaustive the
+<tt class="docutils literal"><span class="pre">handleAllErrors</span></tt> function can be used instead. This is identical to
+<tt class="docutils literal"><span class="pre">handleErrors</span></tt> except that it will terminate the program if an unhandled
+error is passed in, and can therefore return void. The <tt class="docutils literal"><span class="pre">handleAllErrors</span></tt>
+function should generally be avoided: the introduction of a new error type
+elsewhere in the program can easily turn a formerly exhaustive list of errors
+into a non-exhaustive list, risking unexpected program termination. Where
+possible, use handleErrors and propagate unknown errors up the stack instead.</p>
+<p>For tool code, where errors can be handled by printing an error message then
+exiting with an error code, the <a class="reference internal" href="#err-exitonerr"><em>ExitOnError</em></a> utility
+may be a better choice than handleErrors, as it simplifies control flow when
+calling fallible functions.</p>
+<p>In situations where it is known that a particular call to a fallible function
+will always succeed (for example, a call to a function that can only fail on a
+subset of inputs with an input that is known to be safe) the
+<a class="reference internal" href="#err-cantfail"><em>cantFail</em></a> functions can be used to remove the error type,
+simplifying control flow.</p>
+<div class="section" id="stringerror">
+<h5><a class="toc-backref" href="#id24">StringError</a><a class="headerlink" href="#stringerror" title="Permalink to this headline">¶</a></h5>
+<p>Many kinds of errors have no recovery strategy, the only action that can be
+taken is to report them to the user so that the user can attempt to fix the
+environment. In this case representing the error as a string makes perfect
+sense. LLVM provides the <tt class="docutils literal"><span class="pre">StringError</span></tt> class for this purpose. It takes two
+arguments: A string error message, and an equivalent <tt class="docutils literal"><span class="pre">std::error_code</span></tt> for
+interoperability:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">make_error</span><span class="o"><</span><span class="n">StringError</span><span class="o">></span><span class="p">(</span><span class="s">"Bad executable"</span><span class="p">,</span>
+                        <span class="n">make_error_code</span><span class="p">(</span><span class="n">errc</span><span class="o">::</span><span class="n">executable_format_error</span><span class="s">"));</span>
+</pre></div>
+</div>
+<p>If you’re certain that the error you’re building will never need to be converted
+to a <tt class="docutils literal"><span class="pre">std::error_code</span></tt> you can use the <tt class="docutils literal"><span class="pre">inconvertibleErrorCode()</span></tt> function:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">make_error</span><span class="o"><</span><span class="n">StringError</span><span class="o">></span><span class="p">(</span><span class="s">"Bad executable"</span><span class="p">,</span> <span class="n">inconvertibleErrorCode</span><span class="p">());</span>
+</pre></div>
+</div>
+<p>This should be done only after careful consideration. If any attempt is made to
+convert this error to a <tt class="docutils literal"><span class="pre">std::error_code</span></tt> it will trigger immediate program
+termination. Unless you are certain that your errors will not need
+interoperability you should look for an existing <tt class="docutils literal"><span class="pre">std::error_code</span></tt> that you
+can convert to, and even (as painful as it is) consider introducing a new one as
+a stopgap measure.</p>
+</div>
+<div class="section" id="interoperability-with-std-error-code-and-erroror">
+<h5><a class="toc-backref" href="#id25">Interoperability with std::error_code and ErrorOr</a><a class="headerlink" href="#interoperability-with-std-error-code-and-erroror" title="Permalink to this headline">¶</a></h5>
+<p>Many existing LLVM APIs use <tt class="docutils literal"><span class="pre">std::error_code</span></tt> and its partner <tt class="docutils literal"><span class="pre">ErrorOr<T></span></tt>
+(which plays the same role as <tt class="docutils literal"><span class="pre">Expected<T></span></tt>, but wraps a <tt class="docutils literal"><span class="pre">std::error_code</span></tt>
+rather than an <tt class="docutils literal"><span class="pre">Error</span></tt>). The infectious nature of error types means that an
+attempt to change one of these functions to return <tt class="docutils literal"><span class="pre">Error</span></tt> or <tt class="docutils literal"><span class="pre">Expected<T></span></tt>
+instead often results in an avalanche of changes to callers, callers of callers,
+and so on. (The first such attempt, returning an <tt class="docutils literal"><span class="pre">Error</span></tt> from
+MachOObjectFile’s constructor, was abandoned after the diff reached 3000 lines,
+impacted half a dozen libraries, and was still growing).</p>
+<p>To solve this problem, the <tt class="docutils literal"><span class="pre">Error</span></tt>/<tt class="docutils literal"><span class="pre">std::error_code</span></tt> interoperability requirement was
+introduced. Two pairs of functions allow any <tt class="docutils literal"><span class="pre">Error</span></tt> value to be converted to a
+<tt class="docutils literal"><span class="pre">std::error_code</span></tt>, any <tt class="docutils literal"><span class="pre">Expected<T></span></tt> to be converted to an <tt class="docutils literal"><span class="pre">ErrorOr<T></span></tt>, and vice
+versa:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">std</span><span class="o">::</span><span class="n">error_code</span> <span class="n">errorToErrorCode</span><span class="p">(</span><span class="n">Error</span> <span class="n">Err</span><span class="p">);</span>
+<span class="n">Error</span> <span class="n">errorCodeToError</span><span class="p">(</span><span class="n">std</span><span class="o">::</span><span class="n">error_code</span> <span class="n">EC</span><span class="p">);</span>
+
+<span class="k">template</span> <span class="o"><</span><span class="k">typename</span> <span class="n">T</span><span class="o">></span> <span class="n">ErrorOr</span><span class="o"><</span><span class="n">T</span><span class="o">></span> <span class="n">expectedToErrorOr</span><span class="p">(</span><span class="n">Expected</span><span class="o"><</span><span class="n">T</span><span class="o">></span> <span class="n">TOrErr</span><span class="p">);</span>
+<span class="k">template</span> <span class="o"><</span><span class="k">typename</span> <span class="n">T</span><span class="o">></span> <span class="n">Expected</span><span class="o"><</span><span class="n">T</span><span class="o">></span> <span class="n">errorOrToExpected</span><span class="p">(</span><span class="n">ErrorOr</span><span class="o"><</span><span class="n">T</span><span class="o">></span> <span class="n">TOrEC</span><span class="p">);</span>
+</pre></div>
+</div>
+<p>Using these APIs it is easy to make surgical patches that update individual
+functions from <tt class="docutils literal"><span class="pre">std::error_code</span></tt> to <tt class="docutils literal"><span class="pre">Error</span></tt>, and from <tt class="docutils literal"><span class="pre">ErrorOr<T></span></tt> to
+<tt class="docutils literal"><span class="pre">Expected<T></span></tt>.</p>
+</div>
+<div class="section" id="returning-errors-from-error-handlers">
+<h5><a class="toc-backref" href="#id26">Returning Errors from error handlers</a><a class="headerlink" href="#returning-errors-from-error-handlers" title="Permalink to this headline">¶</a></h5>
+<p>Error recovery attempts may themselves fail. For that reason, <tt class="docutils literal"><span class="pre">handleErrors</span></tt>
+actually recognises three different forms of handler signature:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="c1">// Error must be handled, no new errors produced:</span>
+<span class="kt">void</span><span class="p">(</span><span class="n">UserDefinedError</span> <span class="o">&</span><span class="n">E</span><span class="p">);</span>
+
+<span class="c1">// Error must be handled, new errors can be produced:</span>
+<span class="n">Error</span><span class="p">(</span><span class="n">UserDefinedError</span> <span class="o">&</span><span class="n">E</span><span class="p">);</span>
+
+<span class="c1">// Original error can be inspected, then re-wrapped and returned (or a new</span>
+<span class="c1">// error can be produced):</span>
+<span class="n">Error</span><span class="p">(</span><span class="n">std</span><span class="o">::</span><span class="n">unique_ptr</span><span class="o"><</span><span class="n">UserDefinedError</span><span class="o">></span> <span class="n">E</span><span class="p">);</span>
+</pre></div>
+</div>
+<p>Any error returned from a handler will be returned from the <tt class="docutils literal"><span class="pre">handleErrors</span></tt>
+function so that it can be handled itself, or propagated up the stack.</p>
+</div>
+<div class="section" id="using-exitonerror-to-simplify-tool-code">
+<span id="err-exitonerr"></span><h5><a class="toc-backref" href="#id27">Using ExitOnError to simplify tool code</a><a class="headerlink" href="#using-exitonerror-to-simplify-tool-code" title="Permalink to this headline">¶</a></h5>
+<p>Library code should never call <tt class="docutils literal"><span class="pre">exit</span></tt> for a recoverable error, however in tool
+code (especially command line tools) this can be a reasonable approach. Calling
+<tt class="docutils literal"><span class="pre">exit</span></tt> upon encountering an error dramatically simplifies control flow as the
+error no longer needs to be propagated up the stack. This allows code to be
+written in straight-line style, as long as each fallible call is wrapped in a
+check and call to exit. The <tt class="docutils literal"><span class="pre">ExitOnError</span></tt> class supports this pattern by
+providing call operators that inspect <tt class="docutils literal"><span class="pre">Error</span></tt> values, stripping the error away
+in the success case and logging to <tt class="docutils literal"><span class="pre">stderr</span></tt> then exiting in the failure case.</p>
+<p>To use this class, declare a global <tt class="docutils literal"><span class="pre">ExitOnError</span></tt> variable in your program:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">ExitOnError</span> <span class="n">ExitOnErr</span><span class="p">;</span>
+</pre></div>
+</div>
+<p>Calls to fallible functions can then be wrapped with a call to <tt class="docutils literal"><span class="pre">ExitOnErr</span></tt>,
+turning them into non-failing calls:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">Error</span> <span class="n">mayFail</span><span class="p">();</span>
+<span class="n">Expected</span><span class="o"><</span><span class="kt">int</span><span class="o">></span> <span class="n">mayFail2</span><span class="p">();</span>
+
+<span class="kt">void</span> <span class="n">foo</span><span class="p">()</span> <span class="p">{</span>
+  <span class="n">ExitOnErr</span><span class="p">(</span><span class="n">mayFail</span><span class="p">());</span>
+  <span class="kt">int</span> <span class="n">X</span> <span class="o">=</span> <span class="n">ExitOnErr</span><span class="p">(</span><span class="n">mayFail2</span><span class="p">());</span>
+<span class="p">}</span>
+</pre></div>
+</div>
+<p>On failure, the error’s log message will be written to <tt class="docutils literal"><span class="pre">stderr</span></tt>, optionally
+preceded by a string “banner” that can be set by calling the setBanner method. A
+mapping can also be supplied from <tt class="docutils literal"><span class="pre">Error</span></tt> values to exit codes using the
+<tt class="docutils literal"><span class="pre">setExitCodeMapper</span></tt> method:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="kt">int</span> <span class="n">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">ExitOnErr</span><span class="p">.</span><span class="n">setBanner</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="n">argv</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="o">+</span> <span class="s">" error:"</span><span class="p">);</span>
+  <span class="n">ExitOnErr</span><span class="p">.</span><span class="n">setExitCodeMapper</span><span class="p">(</span>
+    <span class="p">[](</span><span class="k">const</span> <span class="n">Error</span> <span class="o">&</span><span class="n">Err</span><span class="p">)</span> <span class="p">{</span>
+      <span class="k">if</span> <span class="p">(</span><span class="n">Err</span><span class="p">.</span><span class="n">isA</span><span class="o"><</span><span class="n">BadFileFormat</span><span class="o">></span><span class="p">())</span>
+        <span class="k">return</span> <span class="mi">2</span><span class="p">;</span>
+      <span class="k">return</span> <span class="mi">1</span><span class="p">;</span>
+    <span class="p">});</span>
+</pre></div>
+</div>
+<p>Use <tt class="docutils literal"><span class="pre">ExitOnError</span></tt> in your tool code where possible as it can greatly improve
+readability.</p>
+</div>
+<div class="section" id="using-cantfail-to-simplify-safe-callsites">
+<span id="err-cantfail"></span><h5><a class="toc-backref" href="#id28">Using cantFail to simplify safe callsites</a><a class="headerlink" href="#using-cantfail-to-simplify-safe-callsites" title="Permalink to this headline">¶</a></h5>
+<p>Some functions may only fail for a subset of their inputs, so calls using known
+safe inputs can be assumed to succeed.</p>
+<p>The cantFail functions encapsulate this by wrapping an assertion that their
+argument is a success value and, in the case of Expected<T>, unwrapping the
+T value:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">Error</span> <span class="n">onlyFailsForSomeXValues</span><span class="p">(</span><span class="kt">int</span> <span class="n">X</span><span class="p">);</span>
+<span class="n">Expected</span><span class="o"><</span><span class="kt">int</span><span class="o">></span> <span class="n">onlyFailsForSomeXValues2</span><span class="p">(</span><span class="kt">int</span> <span class="n">X</span><span class="p">);</span>
+
+<span class="kt">void</span> <span class="n">foo</span><span class="p">()</span> <span class="p">{</span>
+  <span class="n">cantFail</span><span class="p">(</span><span class="n">onlyFailsForSomeXValues</span><span class="p">(</span><span class="n">KnownSafeValue</span><span class="p">));</span>
+  <span class="kt">int</span> <span class="n">Y</span> <span class="o">=</span> <span class="n">cantFail</span><span class="p">(</span><span class="n">onlyFailsForSomeXValues2</span><span class="p">(</span><span class="n">KnownSafeValue</span><span class="p">));</span>
+  <span class="p">...</span>
+<span class="p">}</span>
+</pre></div>
+</div>
+<p>Like the ExitOnError utility, cantFail simplifies control flow. Their treatment
+of error cases is very different however: Where ExitOnError is guaranteed to
+terminate the program on an error input, cantFile simply asserts that the result
+is success. In debug builds this will result in an assertion failure if an error
+is encountered. In release builds the behavior of cantFail for failure values is
+undefined. As such, care must be taken in the use of cantFail: clients must be
+certain that a cantFail wrapped call really can not fail with the given
+arguments.</p>
+<p>Use of the cantFail functions should be rare in library code, but they are
+likely to be of more use in tool and unit-test code where inputs and/or
+mocked-up classes or functions may be known to be safe.</p>
+</div>
+<div class="section" id="fallible-constructors">
+<h5><a class="toc-backref" href="#id29">Fallible constructors</a><a class="headerlink" href="#fallible-constructors" title="Permalink to this headline">¶</a></h5>
+<p>Some classes require resource acquisition or other complex initialization that
+can fail during construction. Unfortunately constructors can’t return errors,
+and having clients test objects after they’re constructed to ensure that they’re
+valid is error prone as it’s all too easy to forget the test. To work around
+this, use the named constructor idiom and return an <tt class="docutils literal"><span class="pre">Expected<T></span></tt>:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="k">class</span> <span class="nc">Foo</span> <span class="p">{</span>
+<span class="k">public</span><span class="o">:</span>
+
+  <span class="k">static</span> <span class="n">Expected</span><span class="o"><</span><span class="n">Foo</span><span class="o">></span> <span class="n">Create</span><span class="p">(</span><span class="n">Resource</span> <span class="n">R1</span><span class="p">,</span> <span class="n">Resource</span> <span class="n">R2</span><span class="p">)</span> <span class="p">{</span>
+    <span class="n">Error</span> <span class="n">Err</span><span class="p">;</span>
+    <span class="n">Foo</span> <span class="n">F</span><span class="p">(</span><span class="n">R1</span><span class="p">,</span> <span class="n">R2</span><span class="p">,</span> <span class="n">Err</span><span class="p">);</span>
+    <span class="k">if</span> <span class="p">(</span><span class="n">Err</span><span class="p">)</span>
+      <span class="k">return</span> <span class="n">std</span><span class="o">::</span><span class="n">move</span><span class="p">(</span><span class="n">Err</span><span class="p">);</span>
+    <span class="k">return</span> <span class="n">std</span><span class="o">::</span><span class="n">move</span><span class="p">(</span><span class="n">F</span><span class="p">);</span>
+  <span class="p">}</span>
+
+<span class="k">private</span><span class="o">:</span>
+
+  <span class="n">Foo</span><span class="p">(</span><span class="n">Resource</span> <span class="n">R1</span><span class="p">,</span> <span class="n">Resource</span> <span class="n">R2</span><span class="p">,</span> <span class="n">Error</span> <span class="o">&</span><span class="n">Err</span><span class="p">)</span> <span class="p">{</span>
+    <span class="n">ErrorAsOutParameter</span> <span class="n">EAO</span><span class="p">(</span><span class="o">&</span><span class="n">Err</span><span class="p">);</span>
+    <span class="k">if</span> <span class="p">(</span><span class="k">auto</span> <span class="n">Err2</span> <span class="o">=</span> <span class="n">R1</span><span class="p">.</span><span class="n">acquire</span><span class="p">())</span> <span class="p">{</span>
+      <span class="n">Err</span> <span class="o">=</span> <span class="n">std</span><span class="o">::</span><span class="n">move</span><span class="p">(</span><span class="n">Err2</span><span class="p">);</span>
+      <span class="k">return</span><span class="p">;</span>
+    <span class="p">}</span>
+    <span class="n">Err</span> <span class="o">=</span> <span class="n">R2</span><span class="p">.</span><span class="n">acquire</span><span class="p">();</span>
+  <span class="p">}</span>
+<span class="p">};</span>
+</pre></div>
+</div>
+<p>Here, the named constructor passes an <tt class="docutils literal"><span class="pre">Error</span></tt> by reference into the actual
+constructor, which the constructor can then use to return errors. The
+<tt class="docutils literal"><span class="pre">ErrorAsOutParameter</span></tt> utility sets the <tt class="docutils literal"><span class="pre">Error</span></tt> value’s checked flag on entry
+to the constructor so that the error can be assigned to, then resets it on exit
+to force the client (the named constructor) to check the error.</p>
+<p>By using this idiom, clients attempting to construct a Foo receive either a
+well-formed Foo or an Error, never an object in an invalid state.</p>
+</div>
+<div class="section" id="propagating-and-consuming-errors-based-on-types">
+<h5><a class="toc-backref" href="#id30">Propagating and consuming errors based on types</a><a class="headerlink" href="#propagating-and-consuming-errors-based-on-types" title="Permalink to this headline">¶</a></h5>
+<p>In some contexts, certain types of error are known to be benign. For example,
+when walking an archive, some clients may be happy to skip over badly formatted
+object files rather than terminating the walk immediately. Skipping badly
+formatted objects could be achieved using an elaborate handler method, but the
+Error.h header provides two utilities that make this idiom much cleaner: the
+type inspection method, <tt class="docutils literal"><span class="pre">isA</span></tt>, and the <tt class="docutils literal"><span class="pre">consumeError</span></tt> function:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">Error</span> <span class="n">walkArchive</span><span class="p">(</span><span class="n">Archive</span> <span class="n">A</span><span class="p">)</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="n">A</span><span class="p">.</span><span class="n">numMembers</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">auto</span> <span class="n">ChildOrErr</span> <span class="o">=</span> <span class="n">A</span><span class="p">.</span><span class="n">getMember</span><span class="p">(</span><span class="n">I</span><span class="p">);</span>
+    <span class="k">if</span> <span class="p">(</span><span class="k">auto</span> <span class="n">Err</span> <span class="o">=</span> <span class="n">ChildOrErr</span><span class="p">.</span><span class="n">takeError</span><span class="p">())</span> <span class="p">{</span>
+      <span class="k">if</span> <span class="p">(</span><span class="n">Err</span><span class="p">.</span><span class="n">isA</span><span class="o"><</span><span class="n">BadFileFormat</span><span class="o">></span><span class="p">())</span>
+        <span class="n">consumeError</span><span class="p">(</span><span class="n">std</span><span class="o">::</span><span class="n">move</span><span class="p">(</span><span class="n">Err</span><span class="p">))</span>
+      <span class="k">else</span>
+        <span class="k">return</span> <span class="n">Err</span><span class="p">;</span>
+    <span class="p">}</span>
+    <span class="k">auto</span> <span class="o">&</span><span class="n">Child</span> <span class="o">=</span> <span class="o">*</span><span class="n">ChildOrErr</span><span class="p">;</span>
+    <span class="c1">// Use Child</span>
+    <span class="p">...</span>
+  <span class="p">}</span>
+  <span class="k">return</span> <span class="n">Error</span><span class="o">::</span><span class="n">success</span><span class="p">();</span>
+<span class="p">}</span>
+</pre></div>
+</div>
+</div>
+<div class="section" id="concatenating-errors-with-joinerrors">
+<h5><a class="toc-backref" href="#id31">Concatenating Errors with joinErrors</a><a class="headerlink" href="#concatenating-errors-with-joinerrors" title="Permalink to this headline">¶</a></h5>
+<p>In the archive walking example above <tt class="docutils literal"><span class="pre">BadFileFormat</span></tt> errors are simply
+consumed and ignored. If the client had wanted report these errors after
+completing the walk over the archive they could use the <tt class="docutils literal"><span class="pre">joinErrors</span></tt> utility:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">Error</span> <span class="n">walkArchive</span><span class="p">(</span><span class="n">Archive</span> <span class="n">A</span><span class="p">)</span> <span class="p">{</span>
+  <span class="n">Error</span> <span class="n">DeferredErrs</span> <span class="o">=</span> <span class="n">Error</span><span class="o">::</span><span class="n">success</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="n">A</span><span class="p">.</span><span class="n">numMembers</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">auto</span> <span class="n">ChildOrErr</span> <span class="o">=</span> <span class="n">A</span><span class="p">.</span><span class="n">getMember</span><span class="p">(</span><span class="n">I</span><span class="p">);</span>
+    <span class="k">if</span> <span class="p">(</span><span class="k">auto</span> <span class="n">Err</span> <span class="o">=</span> <span class="n">ChildOrErr</span><span class="p">.</span><span class="n">takeError</span><span class="p">())</span>
+      <span class="k">if</span> <span class="p">(</span><span class="n">Err</span><span class="p">.</span><span class="n">isA</span><span class="o"><</span><span class="n">BadFileFormat</span><span class="o">></span><span class="p">())</span>
+        <span class="n">DeferredErrs</span> <span class="o">=</span> <span class="n">joinErrors</span><span class="p">(</span><span class="n">std</span><span class="o">::</span><span class="n">move</span><span class="p">(</span><span class="n">DeferredErrs</span><span class="p">),</span> <span class="n">std</span><span class="o">::</span><span class="n">move</span><span class="p">(</span><span class="n">Err</span><span class="p">));</span>
+      <span class="k">else</span>
+        <span class="k">return</span> <span class="n">Err</span><span class="p">;</span>
+    <span class="k">auto</span> <span class="o">&</span><span class="n">Child</span> <span class="o">=</span> <span class="o">*</span><span class="n">ChildOrErr</span><span class="p">;</span>
+    <span class="c1">// Use Child</span>
+    <span class="p">...</span>
+  <span class="p">}</span>
+  <span class="k">return</span> <span class="n">DeferredErrs</span><span class="p">;</span>
+<span class="p">}</span>
+</pre></div>
+</div>
+<p>The <tt class="docutils literal"><span class="pre">joinErrors</span></tt> routine builds a special error type called <tt class="docutils literal"><span class="pre">ErrorList</span></tt>,
+which holds a list of user defined errors. The <tt class="docutils literal"><span class="pre">handleErrors</span></tt> routine
+recognizes this type and will attempt to handle each of the contained errors in
+order. If all contained errors can be handled, <tt class="docutils literal"><span class="pre">handleErrors</span></tt> will return
+<tt class="docutils literal"><span class="pre">Error::success()</span></tt>, otherwise <tt class="docutils literal"><span class="pre">handleErrors</span></tt> will concatenate the remaining
+errors and return the resulting <tt class="docutils literal"><span class="pre">ErrorList</span></tt>.</p>
+</div>
+<div class="section" id="building-fallible-iterators-and-iterator-ranges">
+<h5><a class="toc-backref" href="#id32">Building fallible iterators and iterator ranges</a><a class="headerlink" href="#building-fallible-iterators-and-iterator-ranges" title="Permalink to this headline">¶</a></h5>
+<p>The archive walking examples above retrieve archive members by index, however
+this requires considerable boiler-plate for iteration and error checking. We can
+clean this up by using <tt class="docutils literal"><span class="pre">Error</span></tt> with the “fallible iterator” pattern. The usual
+C++ iterator patterns do not allow for failure on increment, but we can
+incorporate support for it by having iterators hold an Error reference through
+which they can report failure. In this pattern, if an increment operation fails
+the failure is recorded via the Error reference and the iterator value is set to
+the end of the range in order to terminate the loop. This ensures that the
+dereference operation is safe anywhere that an ordinary iterator dereference
+would be safe (i.e. when the iterator is not equal to end). Where this pattern
+is followed (as in the <tt class="docutils literal"><span class="pre">llvm::object::Archive</span></tt> class) the result is much
+cleaner iteration idiom:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">Error</span> <span class="n">Err</span><span class="p">;</span>
+<span class="k">for</span> <span class="p">(</span><span class="k">auto</span> <span class="o">&</span><span class="n">Child</span> <span class="o">:</span> <span class="n">Ar</span><span class="o">-></span><span class="n">children</span><span class="p">(</span><span class="n">Err</span><span class="p">))</span> <span class="p">{</span>
+  <span class="c1">// Use Child - we only enter the loop when it's valid</span>
+  <span class="p">...</span>
+<span class="p">}</span>
+<span class="c1">// Check Err after the loop to ensure it didn't break due to an error.</span>
+<span class="k">if</span> <span class="p">(</span><span class="n">Err</span><span class="p">)</span>
+  <span class="k">return</span> <span class="n">Err</span><span class="p">;</span>
+</pre></div>
+</div>
+<p id="function-apis">More information on Error and its related utilities can be found in the
+Error.h header file.</p>
+</div>
+</div>
+</div>
+<div class="section" id="passing-functions-and-other-callable-objects">
+<h3><a class="toc-backref" href="#id33">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="n">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="#id34">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="#id35">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_3_01Ret_07Params_8_8_8_08_4.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="n">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="kc">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="#id36">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 non-asserts 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="#id37">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
+should 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">#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>
+</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
+'foo' debug type
+'bar' debug type
+$ opt < a.bc > /dev/null -mypass -debug-only=foo
+'foo' debug type
+$ opt < a.bc > /dev/null -mypass -debug-only=bar
+'bar' debug type
+$ opt < a.bc > /dev/null -mypass -debug-only=foo,bar
+'foo' debug type
+'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. Be careful that you only do
+this after including Debug.h and not around any #include of headers. 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. The name must not include a comma (,) as that is used to separate the
+arguments of the <tt class="docutils literal"><span class="pre">-debug-only</span></tt> option.</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">"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>
+</pre></div>
+</div>
+</div>
+</div>
+<div class="section" id="the-statistic-class-stats-option">
+<span id="statistic"></span><h3><a class="toc-backref" href="#id38">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>
+<p>Define your statistic like this:</p>
+<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>
+<p>Whenever you make a transformation, bump the counter:</p>
+<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>
+<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="adding-debug-counters-to-aid-in-debugging-your-code">
+<span id="debugcounters"></span><h3><a class="toc-backref" href="#id39">Adding debug counters to aid in debugging your code</a><a class="headerlink" href="#adding-debug-counters-to-aid-in-debugging-your-code" title="Permalink to this headline">¶</a></h3>
+<p>Sometimes, when writing new passes, or trying to track down bugs, it
+is useful to be able to control whether certain things in your pass
+happen or not.  For example, there are times the minimization tooling
+can only easily give you large testcases.  You would like to narrow
+your bug down to a specific transformation happening or not happening,
+automatically, using bisection.  This is where debug counters help.
+They provide a framework for making parts of your code only execute a
+certain number of times.</p>
+<p>The <tt class="docutils literal"><span class="pre">llvm/Support/DebugCounter.h</span></tt> (<a class="reference external" href="http://llvm.org/doxygen/DebugCounter_8h_source.html">doxygen</a>) file
+provides a class named <tt class="docutils literal"><span class="pre">DebugCounter</span></tt> that can be used to create
+command line counter options that control execution of parts of your code.</p>
+<p>Define your DebugCounter like this:</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="n">DEBUG_COUNTER</span><span class="p">(</span><span class="n">DeleteAnInstruction</span><span class="p">,</span> <span class="s">"passname-delete-instruction"</span><span class="p">,</span>
+              <span class="s">"Controls which instructions get delete"</span><span class="p">).</span>
+</pre></div>
+</div>
+<p>The <tt class="docutils literal"><span class="pre">DEBUG_COUNTER</span></tt> macro defines a static variable, whose name
+is specified by the first argument.  The name of the counter
+(which is used on the command line) is specified by the second
+argument, and the description used in the help is specified by the
+third argument.</p>
+<p>Whatever code you want that control, use <tt class="docutils literal"><span class="pre">DebugCounter::shouldExecute</span></tt> to control it.</p>
+<div class="highlight-c++"><div class="highlight"><pre><span class="k">if</span> <span class="p">(</span><span class="n">DebugCounter</span><span class="o">::</span><span class="n">shouldExecute</span><span class="p">(</span><span class="n">DeleteAnInstruction</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>That’s all you have to do.  Now, using opt, you can control when this code triggers using
+the ‘<tt class="docutils literal"><span class="pre">--debug-counter</span></tt>‘ option.  There are two counters provided, <tt class="docutils literal"><span class="pre">skip</span></tt> and <tt class="docutils literal"><span class="pre">count</span></tt>.
+<tt class="docutils literal"><span class="pre">skip</span></tt> is the number of times to skip execution of the codepath.  <tt class="docutils literal"><span class="pre">count</span></tt> is the number
+of times, once we are done skipping, to execute the codepath.</p>
+<div class="highlight-none"><div class="highlight"><pre>$ opt --debug-counter=passname-delete-instruction-skip=1,passname-delete-instruction-count=2 -passname
+</pre></div>
+</div>
+<p>This will skip the above code the first time we hit it, then execute it twice, then skip the rest of the executions.</p>
+<p>So if executed on the following code:</p>
+<div class="highlight-llvm"><div class="highlight"><pre><span class="nv-Anonymous">%1</span> <span class="p">=</span> <span class="k">add</span> <span class="k">i32</span> <span class="nv">%a</span><span class="p">,</span> <span class="nv">%b</span>
+<span class="nv-Anonymous">%2</span> <span class="p">=</span> <span class="k">add</span> <span class="k">i32</span> <span class="nv">%a</span><span class="p">,</span> <span class="nv">%b</span>
+<span class="nv-Anonymous">%3</span> <span class="p">=</span> <span class="k">add</span> <span class="k">i32</span> <span class="nv">%a</span><span class="p">,</span> <span class="nv">%b</span>
+<span class="nv-Anonymous">%4</span> <span class="p">=</span> <span class="k">add</span> <span class="k">i32</span> <span class="nv">%a</span><span class="p">,</span> <span class="nv">%b</span>
+</pre></div>
+</div>
+<p>It would delete number <tt class="docutils literal"><span class="pre">%2</span></tt> and <tt class="docutils literal"><span class="pre">%3</span></tt>.</p>
+<p>A utility is provided in <cite>utils/bisect-skip-count</cite> to binary search
+skip and count arguments. It can be used to automatically minimize the
+skip and count for a debug-counter variable.</p>
+</div>
+<div class="section" id="viewing-graphs-while-debugging-code">
+<span id="viewgraph"></span><h3><a class="toc-backref" href="#id40">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="#id41">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="#id42">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="#id43">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="#id44">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="#id45">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="#id46">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="#id47">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="n">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="#id48"><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="#id49"><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="#id50"><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="#id51">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="#id52">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="n">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="#id53">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="#id54">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="#id55">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="#id56">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="#id57">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="#id58">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="#id59">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="#id60">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="n">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="n">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="#id61">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="#id62">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="#id63">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="#id64">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="#id65">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="#id66">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="#id67">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 supports
+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="#id68">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="#id69">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="#id70">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="#id71">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="#id72"><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="#id73">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="#id74">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="#id75">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="#id76">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="#id77">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="#id78">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="#id79">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="#id80">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="#id81">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="#id82">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="#id83">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="#id84"><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="#id85">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="#id86">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="#id87">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="#id88">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="#id89">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="#id90">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="#id91">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="#id92">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="debugging">
+<span id="id3"></span><h2><a class="toc-backref" href="#id93">Debugging</a><a class="headerlink" href="#debugging" title="Permalink to this headline">¶</a></h2>
+<p>A handful of <a class="reference external" href="https://sourceware.org/gdb/onlinedocs/gdb/Pretty-Printing.html">GDB pretty printers</a> are
+provided for some of the core LLVM libraries. To use them, execute the
+following (or add it to your <tt class="docutils literal"><span class="pre">~/.gdbinit</span></tt>):</p>
+<div class="highlight-python"><div class="highlight"><pre><span class="n">source</span> <span class="o">/</span><span class="n">path</span><span class="o">/</span><span class="n">to</span><span class="o">/</span><span class="n">llvm</span><span class="o">/</span><span class="n">src</span><span class="o">/</span><span class="n">utils</span><span class="o">/</span><span class="n">gdb</span><span class="o">-</span><span class="n">scripts</span><span class="o">/</span><span class="n">prettyprinters</span><span class="o">.</span><span class="n">py</span>
+</pre></div>
+</div>
+<p>It also might be handy to enable the <a class="reference external" href="http://ftp.gnu.org/old-gnu/Manuals/gdb/html_node/gdb_57.html">print pretty</a> option to
+avoid data structures being printed as a big block of text.</p>
+</div>
+<div class="section" id="helpful-hints-for-common-operations">
+<span id="common"></span><h2><a class="toc-backref" href="#id94">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="#id95">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="#id96">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="n">Function</span> <span class="o">&</span><span class="n">Func</span> <span class="o">=</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="n">Func</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">BB</span><span class="p">.</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">BB</span><span class="p">.</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>
+</div>
+<div class="section" id="iterating-over-the-instruction-in-a-basicblock">
+<span id="iterate-basicblock"></span><h4><a class="toc-backref" href="#id97">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="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">Instruction</span> <span class="o">&</span><span class="n">I</span> <span class="o">:</span> <span class="n">BB</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="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">BB</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="#id98">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="#id99">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 dereferencing 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="n">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="#id100">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="k">public</span><span class="o">:</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">BasicBlock</span> <span class="o">&</span><span class="n">B</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">Instruction</span> <span class="o">&</span><span class="nl">I:</span> <span class="n">B</span><span class="p">)</span> <span class="p">{</span>
+          <span class="k">if</span> <span class="p">(</span><span class="k">auto</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="k">private</span><span class="o">:</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="#id101">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="#id102">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="#id103">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/IR/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">BasicBlock</span> <span class="o">*</span><span class="n">Pred</span> <span class="o">:</span> <span class="n">predecessors</span><span class="p">(</span><span class="n">BB</span><span class="p">))</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">successors</span></tt>.</p>
+</div>
+</div>
+<div class="section" id="making-simple-changes">
+<span id="simplechanges"></span><h3><a class="toc-backref" href="#id104">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="#id105">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="k">auto</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="k">auto</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="k">auto</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="k">auto</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="k">auto</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="k">auto</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="k">auto</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/LangImpl03.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="#id106">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="#id107">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="#id108">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="id4"></span><h5><a class="toc-backref" href="#id109">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="#id110">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="#id111">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="#id112">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="kc">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="kc">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="#id113">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="#id114">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="#id115">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="#id116">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>
+</div>
+<div class="section" id="threads-and-the-jit">
+<span id="jitthreading"></span><h3><a class="toc-backref" href="#id117">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="https://bugs.llvm.org/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="#id118">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="#id119">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="#id120">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="#id121">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="#id122">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="#id123">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="sc">'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="sc">'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"><pre>*Main> quickCheck identityProp
+OK, passed 100 tests.</pre>
+</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"><pre>*Main> deepCheck identityProp
+OK, passed 500 tests.</pre>
+</div>
+</div>
+<div class="section" id="tagging-considerations">
+<span id="tagging"></span><h4><a class="toc-backref" href="#id124">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="#id125">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="id5"></span><h3><a class="toc-backref" href="#id126">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="#id127">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="#id128">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="#id129">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="#id130">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 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>
+<li><tt class="docutils literal"><span class="pre">uint64_t</span> <span class="pre">getNumElements()</span> <span class="pre">const</span></tt>: Returns the number of elements
+in the sequential type.</li>
+</ul>
+</dd>
+<dt><tt class="docutils literal"><span class="pre">ArrayType</span></tt></dt>
+<dd>This is a subclass of SequentialType and defines the interface for array
+types.</dd>
+<dt><tt class="docutils literal"><span class="pre">PointerType</span></tt></dt>
+<dd>Subclass of Type 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="#id131">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="#id132">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="#id133">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="#id134">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="#id135">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="#id136">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="#id137">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="#id138">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="#id139">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="#id140">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="#id141">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="#id142">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="#id143">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="#id144">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="#id145">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="#id146">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="#id147">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="#id148">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="#id149">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="#id150">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-2018, LLVM Project.
+      Last updated on 2018-05-10.
+      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
+    </div>
+  </body>
+</html>
\ No newline at end of file




More information about the llvm-commits mailing list