Home | History | Annotate | Download | only in reference
      1 {{+bindTo:partials.standard_nacl_article}}
      2 
      3 <section id="pnacl-bitcode-reference-manual">
      4 <h1 id="pnacl-bitcode-reference-manual">PNaCl Bitcode Reference Manual</h1>
      5 <div class="contents local" id="contents" style="display: none">
      6 <ul class="small-gap">
      7 <li><a class="reference internal" href="#introduction" id="id1">Introduction</a></li>
      8 <li><p class="first"><a class="reference internal" href="#high-level-structure" id="id2">High Level Structure</a></p>
      9 <ul class="small-gap">
     10 <li><a class="reference internal" href="#data-model" id="id3">Data Model</a></li>
     11 <li><a class="reference internal" href="#linkage-types" id="id4">Linkage Types</a></li>
     12 <li><a class="reference internal" href="#calling-conventions" id="id5">Calling Conventions</a></li>
     13 <li><a class="reference internal" href="#visibility-styles" id="id6">Visibility Styles</a></li>
     14 <li><a class="reference internal" href="#global-variables" id="id7">Global Variables</a></li>
     15 <li><a class="reference internal" href="#functions" id="id8">Functions</a></li>
     16 <li><a class="reference internal" href="#aliases" id="id9">Aliases</a></li>
     17 <li><a class="reference internal" href="#named-metadata" id="id10">Named Metadata</a></li>
     18 <li><a class="reference internal" href="#module-level-inline-assembly" id="id11">Module-Level Inline Assembly</a></li>
     19 <li><a class="reference internal" href="#volatile-memory-accesses" id="id12">Volatile Memory Accesses</a></li>
     20 <li><a class="reference internal" href="#memory-model-for-concurrent-operations" id="id13">Memory Model for Concurrent Operations</a></li>
     21 <li><a class="reference internal" href="#fast-math-flags" id="id14">Fast-Math Flags</a></li>
     22 </ul>
     23 </li>
     24 <li><p class="first"><a class="reference internal" href="#type-system" id="id15">Type System</a></p>
     25 <ul class="small-gap">
     26 <li><a class="reference internal" href="#scalar-types" id="id16">Scalar types</a></li>
     27 <li><a class="reference internal" href="#vector-types" id="id17">Vector types</a></li>
     28 <li><a class="reference internal" href="#array-and-struct-types" id="id18">Array and struct types</a></li>
     29 <li><a class="reference internal" href="#pointer-types" id="id19">Pointer types</a></li>
     30 <li><a class="reference internal" href="#undefined-values" id="id20">Undefined Values</a></li>
     31 <li><a class="reference internal" href="#constant-expressions" id="id21">Constant Expressions</a></li>
     32 </ul>
     33 </li>
     34 <li><p class="first"><a class="reference internal" href="#other-values" id="id22">Other Values</a></p>
     35 <ul class="small-gap">
     36 <li><a class="reference internal" href="#metadata-nodes-and-metadata-strings" id="id23">Metadata Nodes and Metadata Strings</a></li>
     37 </ul>
     38 </li>
     39 <li><a class="reference internal" href="#intrinsic-global-variables" id="id24">Intrinsic Global Variables</a></li>
     40 <li><a class="reference internal" href="#errno-and-errors-in-arithmetic-instructions" id="id25">Errno and errors in arithmetic instructions</a></li>
     41 <li><p class="first"><a class="reference internal" href="#instruction-reference" id="id26">Instruction Reference</a></p>
     42 <ul class="small-gap">
     43 <li><a class="reference internal" href="#list-of-allowed-instructions" id="id27">List of allowed instructions</a></li>
     44 <li><a class="reference internal" href="#alloca" id="id28"><code>alloca</code></a></li>
     45 </ul>
     46 </li>
     47 <li><p class="first"><a class="reference internal" href="#intrinsic-functions" id="id29">Intrinsic Functions</a></p>
     48 <ul class="small-gap">
     49 <li><a class="reference internal" href="#list-of-allowed-intrinsics" id="id30">List of allowed intrinsics</a></li>
     50 <li><a class="reference internal" href="#thread-pointer-related-intrinsics" id="id31">Thread pointer related intrinsics</a></li>
     51 <li><a class="reference internal" href="#setjmp-and-longjmp" id="id32">Setjmp and Longjmp</a></li>
     52 <li><a class="reference internal" href="#atomic-intrinsics" id="id33">Atomic intrinsics</a></li>
     53 </ul>
     54 </li>
     55 </ul>
     56 
     57 </div><section id="introduction">
     58 <h2 id="introduction">Introduction</h2>
     59 <p>This document is a reference manual for the PNaCl bitcode format. It describes
     60 the bitcode on a <em>semantic</em> level; the physical encoding level will be described
     61 elsewhere. For the purpose of this document, the textual form of LLVM IR is
     62 used to describe instructions and other bitcode constructs.</p>
     63 <p>Since the PNaCl bitcode is based to a large extent on LLVM IR as of
     64 version 3.3, many sections in this document point to a relevant section
     65 of the LLVM language reference manual. Only the changes, restrictions
     66 and variations specific to PNaCl are described&#8212;full semantic
     67 descriptions are not duplicated from the LLVM reference manual.</p>
     68 </section><section id="high-level-structure">
     69 <h2 id="high-level-structure">High Level Structure</h2>
     70 <p>A PNaCl portable executable (<strong>pexe</strong> in short) is a single LLVM IR module.</p>
     71 <section id="data-model">
     72 <h3 id="data-model">Data Model</h3>
     73 <p>The data model for PNaCl bitcode is fixed at little-endian ILP32: pointers are
     74 32 bits in size. 64-bit integer types are also supported natively via the i64
     75 type (for example, a front-end can generate these from the C/C++ type
     76 <code>long long</code>).</p>
     77 <p>Floating point support is fixed at IEEE 754 32-bit and 64-bit values (f32 and
     78 f64, respectively).</p>
     79 </section><section id="linkage-types">
     80 <span id="bitcode-linkagetypes"></span><h3 id="linkage-types"><span id="bitcode-linkagetypes"></span>Linkage Types</h3>
     81 <p><a class="reference external" href="http://llvm.org/releases/3.3/docs/LangRef.html#linkage">LLVM LangRef: Linkage Types</a></p>
     82 <p>The linkage types supported by PNaCl bitcode are <code>internal</code> and <code>external</code>.
     83 A single function in the pexe, named <code>_start</code>, has the linkage type
     84 <code>external</code>. All the other functions and globals have the linkage type
     85 <code>internal</code>.</p>
     86 </section><section id="calling-conventions">
     87 <h3 id="calling-conventions">Calling Conventions</h3>
     88 <p><a class="reference external" href="http://llvm.org/releases/3.3/docs/LangRef.html#callingconv">LLVM LangRef: Calling Conventions</a></p>
     89 <p>The only calling convention supported by PNaCl bitcode is <code>ccc</code> - the C
     90 calling convention.</p>
     91 </section><section id="visibility-styles">
     92 <h3 id="visibility-styles">Visibility Styles</h3>
     93 <p><a class="reference external" href="http://llvm.org/releases/3.3/docs/LangRef.html#visibility-styles">LLVM LangRef: Visibility Styles</a></p>
     94 <p>PNaCl bitcode does not support visibility styles.</p>
     95 </section><section id="global-variables">
     96 <span id="bitcode-globalvariables"></span><h3 id="global-variables"><span id="bitcode-globalvariables"></span>Global Variables</h3>
     97 <p><a class="reference external" href="http://llvm.org/releases/3.3/docs/LangRef.html#globalvars">LLVM LangRef: Global Variables</a></p>
     98 <p>Restrictions on global variables:</p>
     99 <ul class="small-gap">
    100 <li>PNaCl bitcode does not support LLVM IR TLS models. See
    101 <a class="reference internal" href="/native-client/reference/pnacl-c-cpp-language-support.html#language-support-threading"><em>Threading</em></a> for more details.</li>
    102 <li>Restrictions on <a class="reference internal" href="#bitcode-linkagetypes"><em>linkage types</em></a>.</li>
    103 <li>The <code>addrspace</code>, <code>section</code>, <code>unnamed_addr</code> and
    104 <code>externally_initialized</code> attributes are not supported.</li>
    105 </ul>
    106 <p>Every global variable must have an initializer. Each initializer must be
    107 either a <em>SimpleElement</em> or a <em>CompoundElement</em>, defined as follows.</p>
    108 <p>A <em>SimpleElement</em> is one of the following:</p>
    109 <ol class="arabic simple">
    110 <li>An i8 array literal or <code>zeroinitializer</code>:</li>
    111 </ol>
    112 <pre>
    113    [SIZE x i8] c&quot;DATA&quot;
    114    [SIZE x i8] zeroinitializer
    115 </pre>
    116 <ol class="arabic simple" start="2">
    117 <li>A reference to a <em>GlobalValue</em> (a function or global variable) with an
    118 optional 32-bit byte offset added to it (the addend, which may be
    119 negative):</li>
    120 </ol>
    121 <pre>
    122    ptrtoint (TYPE* &#64;GLOBAL to i32)
    123    add (i32 ptrtoint (TYPE* &#64;GLOBAL to i32), i32 ADDEND)
    124 </pre>
    125 <p>A <em>CompoundElement</em> is a unnamed, packed struct containing more than one
    126 <em>SimpleElement</em>.</p>
    127 </section><section id="functions">
    128 <h3 id="functions">Functions</h3>
    129 <p><a class="reference external" href="http://llvm.org/releases/3.3/docs/LangRef.html#functionstructure">LLVM LangRef: Functions</a></p>
    130 <p>The restrictions on <a class="reference internal" href="#bitcode-linkagetypes"><em>linkage types</em></a>, calling
    131 conventions and visibility styles apply to functions. In addition, the following
    132 are not supported for functions:</p>
    133 <ul class="small-gap">
    134 <li>Function attributes (either for the the function itself, its parameters or its
    135 return type).</li>
    136 <li>Garbage collector name (<code>gc</code>).</li>
    137 <li>Functions with a variable number of arguments (<em>vararg</em>).</li>
    138 <li>Alignment (<code>align</code>).</li>
    139 </ul>
    140 </section><section id="aliases">
    141 <h3 id="aliases">Aliases</h3>
    142 <p><a class="reference external" href="http://llvm.org/releases/3.3/docs/LangRef.html#aliases">LLVM LangRef: Aliases</a></p>
    143 <p>PNaCl bitcode does not support aliases.</p>
    144 </section><section id="named-metadata">
    145 <h3 id="named-metadata">Named Metadata</h3>
    146 <p><a class="reference external" href="http://llvm.org/releases/3.3/docs/LangRef.html#namedmetadatastructure">LLVM LangRef: Named Metadata</a></p>
    147 <p>While PNaCl bitcode has provisions for debugging metadata, it is not considered
    148 part of the stable ABI. It exists for tool support and should not appear in
    149 distributed pexes.</p>
    150 <p>Other kinds of LLVM metadata are not supported.</p>
    151 </section><section id="module-level-inline-assembly">
    152 <h3 id="module-level-inline-assembly">Module-Level Inline Assembly</h3>
    153 <p><a class="reference external" href="http://llvm.org/releases/3.3/docs/LangRef.html#moduleasm">LLVM LangRef: Module-Level Inline Assembly</a></p>
    154 <p>PNaCl bitcode does not support inline assembly.</p>
    155 </section><section id="volatile-memory-accesses">
    156 <h3 id="volatile-memory-accesses">Volatile Memory Accesses</h3>
    157 <p><a class="reference external" href="http://llvm.org/releases/3.3/docs/LangRef.html#volatile">LLVM LangRef: Volatile Memory Accesses</a></p>
    158 <p>PNaCl bitcode does not support volatile memory accesses. The
    159 <code>volatile</code> attribute on loads and stores is not supported. See the
    160 <a class="reference internal" href="/native-client/reference/pnacl-c-cpp-language-support.html"><em>PNaCl C/C++ Language Support</em></a> for more details.</p>
    161 </section><section id="memory-model-for-concurrent-operations">
    162 <h3 id="memory-model-for-concurrent-operations">Memory Model for Concurrent Operations</h3>
    163 <p><a class="reference external" href="http://llvm.org/releases/3.3/docs/LangRef.html#memmodel">LLVM LangRef: Memory Model for Concurrent Operations</a></p>
    164 <p>See the <a class="reference external" href="PNaClDeveloperGuide.html">PNaCl Developer&#8217;s Guide</a> for more
    165 details.</p>
    166 </section><section id="fast-math-flags">
    167 <h3 id="fast-math-flags">Fast-Math Flags</h3>
    168 <p><a class="reference external" href="http://llvm.org/releases/3.3/docs/LangRef.html#fastmath">LLVM LangRef: Fast-Math Flags</a></p>
    169 <p>Fast-math mode is not currently supported by the PNaCl bitcode.</p>
    170 </section></section><section id="type-system">
    171 <h2 id="type-system">Type System</h2>
    172 <p><a class="reference external" href="http://llvm.org/releases/3.3/docs/LangRef.html#typesystem">LLVM LangRef: Type System</a></p>
    173 <p>The LLVM types allowed in PNaCl bitcode are restricted, as follows:</p>
    174 <section id="scalar-types">
    175 <h3 id="scalar-types">Scalar types</h3>
    176 <ul class="small-gap">
    177 <li><p class="first">The only scalar types allowed are integer, float (32-bit floating point),
    178 double (64-bit floating point) and void.</p>
    179 <ul class="small-gap">
    180 <li>The only integer sizes allowed are i1, i8, i16, i32 and i64.</li>
    181 <li>The only integer sizes allowed for function arguments and function return
    182 values are i32 and i64.</li>
    183 </ul>
    184 </li>
    185 </ul>
    186 </section><section id="vector-types">
    187 <h3 id="vector-types">Vector types</h3>
    188 <p>The only vector types allowed are:</p>
    189 <ul class="small-gap">
    190 <li>128-bit vectors integers of elements size i8, i16, i32.</li>
    191 <li>128-bit vectors of float elements.</li>
    192 <li>Vectors of i1 type with element counts corresponding to the allowed
    193 element counts listed previously (their width is therefore not
    194 128-bits).</li>
    195 </ul>
    196 </section><section id="array-and-struct-types">
    197 <h3 id="array-and-struct-types">Array and struct types</h3>
    198 <p>Array and struct types are only allowed in
    199 <a class="reference internal" href="#bitcode-globalvariables"><em>global variable initializers</em></a>.</p>
    200 </section><section id="pointer-types">
    201 <span id="bitcode-pointertypes"></span><h3 id="pointer-types"><span id="bitcode-pointertypes"></span>Pointer types</h3>
    202 <p>Only the following pointer types are allowed:</p>
    203 <ul class="small-gap">
    204 <li>Pointers to valid PNaCl bitcode scalar types, as specified above.</li>
    205 <li>Pointers to functions.</li>
    206 </ul>
    207 <p>In addition, the address space for all pointers must be 0.</p>
    208 <p>A pointer is <em>inherent</em> when it represents the return value of an <code>alloca</code>
    209 instruction, or is an address of a global value.</p>
    210 <p>A pointer is <em>normalized</em> if it&#8217;s either:</p>
    211 <ul class="small-gap">
    212 <li><em>inherent</em></li>
    213 <li>Is the return value of a <code>bitcast</code> instruction.</li>
    214 <li>Is the return value of a <code>inttoptr</code> instruction.</li>
    215 </ul>
    216 </section><section id="undefined-values">
    217 <h3 id="undefined-values">Undefined Values</h3>
    218 <p><a class="reference external" href="http://llvm.org/releases/3.3/docs/LangRef.html#undefvalues">LLVM LangRef: Undefined Values</a></p>
    219 <p><code>undef</code> is only allowed within functions, not in global variable initializers.</p>
    220 </section><section id="constant-expressions">
    221 <h3 id="constant-expressions">Constant Expressions</h3>
    222 <p><a class="reference external" href="http://llvm.org/releases/3.3/docs/LangRef.html#constant-expressions">LLVM LangRef: Constant Expressions</a></p>
    223 <p>Constant expressions are only allowed in
    224 <a class="reference internal" href="#bitcode-globalvariables"><em>global variable initializers</em></a>.</p>
    225 </section></section><section id="other-values">
    226 <h2 id="other-values">Other Values</h2>
    227 <section id="metadata-nodes-and-metadata-strings">
    228 <h3 id="metadata-nodes-and-metadata-strings">Metadata Nodes and Metadata Strings</h3>
    229 <p><a class="reference external" href="http://llvm.org/releases/3.3/docs/LangRef.html#metadata">LLVM LangRef: Metadata Nodes and Metadata Strings</a></p>
    230 <p>While PNaCl bitcode has provisions for debugging metadata, it is not considered
    231 part of the stable ABI. It exists for tool support and should not appear in
    232 distributed pexes.</p>
    233 <p>Other kinds of LLVM metadata are not supported.</p>
    234 </section></section><section id="intrinsic-global-variables">
    235 <h2 id="intrinsic-global-variables">Intrinsic Global Variables</h2>
    236 <p><a class="reference external" href="http://llvm.org/releases/3.3/docs/LangRef.html#intrinsic-global-variables">LLVM LangRef: Intrinsic Global Variables</a></p>
    237 <p>PNaCl bitcode does not support intrinsic global variables.</p>
    238 </section><section id="errno-and-errors-in-arithmetic-instructions">
    239 <span id="ir-and-errno"></span><h2 id="errno-and-errors-in-arithmetic-instructions"><span id="ir-and-errno"></span>Errno and errors in arithmetic instructions</h2>
    240 <p>Some arithmetic instructions and intrinsics have the similar semantics to
    241 libc math functions, but differ in the treatment of <code>errno</code>. While the
    242 libc functions may set <code>errno</code> for domain errors, the instructions and
    243 intrinsics do not. This is because the variable <code>errno</code> is not special
    244 and is not required to be part of the program.</p>
    245 </section><section id="instruction-reference">
    246 <h2 id="instruction-reference">Instruction Reference</h2>
    247 <section id="list-of-allowed-instructions">
    248 <h3 id="list-of-allowed-instructions">List of allowed instructions</h3>
    249 <p>This is a list of LLVM instructions supported by PNaCl bitcode. Where
    250 applicable, PNaCl-specific restrictions are provided.</p>
    251 <p>The following attributes are disallowed for all instructions:</p>
    252 <ul class="small-gap">
    253 <li><code>nsw</code> and <code>nuw</code></li>
    254 <li><code>exact</code></li>
    255 </ul>
    256 <p>Only the LLVM instructions listed here are supported by PNaCl bitcode.</p>
    257 <ul class="small-gap">
    258 <li><code>ret</code></li>
    259 <li><code>br</code></li>
    260 <li><p class="first"><code>switch</code></p>
    261 <p>i1 values are disallowed for <code>switch</code>.</p>
    262 </li>
    263 <li><p class="first"><code>add</code>, <code>sub</code>, <code>mul</code>, <code>shl</code>,  <code>udiv</code>, <code>sdiv</code>, <code>urem</code>, <code>srem</code>,
    264 <code>lshr</code>, <code>ashr</code></p>
    265 <p>These arithmetic operations are disallowed on values of type <code>i1</code>.</p>
    266 <p>Integer division (<code>udiv</code>, <code>sdiv</code>, <code>urem</code>, <code>srem</code>) by zero is
    267 guaranteed to trap in PNaCl bitcode.</p>
    268 </li>
    269 <li><code>and</code></li>
    270 <li><code>or</code></li>
    271 <li><code>xor</code></li>
    272 <li><code>fadd</code></li>
    273 <li><code>fsub</code></li>
    274 <li><code>fmul</code></li>
    275 <li><code>fdiv</code></li>
    276 <li><p class="first"><code>frem</code></p>
    277 <p>The frem instruction has the semantics of the libc fmod function for
    278 computing the floating point remainder. If the numerator is infinity, or
    279 denominator is zero, or either are NaN, then the result is NaN.
    280 Unlike the libc fmod function, this does not set <code>errno</code> when the
    281 result is NaN (see the <a class="reference internal" href="#ir-and-errno"><em>instructions and errno</em></a>
    282 section).</p>
    283 </li>
    284 <li><p class="first"><code>alloca</code></p>
    285 <p>See <a class="reference internal" href="#bitcode-allocainst"><em>alloca instructions</em></a>.</p>
    286 </li>
    287 <li><p class="first"><code>load</code>, <code>store</code></p>
    288 <p>The pointer argument of these instructions must be a <em>normalized</em> pointer (see
    289 <a class="reference internal" href="#bitcode-pointertypes"><em>pointer types</em></a>). The <code>volatile</code> and <code>atomic</code>
    290 attributes are not supported. Loads and stores of the type <code>i1</code> are not
    291 supported.</p>
    292 <p>These instructions must use <code>align 1</code> on integer memory accesses, <code>align 4</code>
    293 for <code>float</code> accesses and <code>align 8</code> for <code>double</code> accesses.</p>
    294 </li>
    295 <li><code>trunc</code></li>
    296 <li><code>zext</code></li>
    297 <li><code>sext</code></li>
    298 <li><code>fptrunc</code></li>
    299 <li><code>fpext</code></li>
    300 <li><code>fptoui</code></li>
    301 <li><code>fptosi</code></li>
    302 <li><code>uitofp</code></li>
    303 <li><code>sitofp</code></li>
    304 <li><p class="first"><code>ptrtoint</code></p>
    305 <p>The pointer argument of a <code>ptrtoint</code> instruction must be a <em>normalized</em>
    306 pointer (see <a class="reference internal" href="#bitcode-pointertypes"><em>pointer types</em></a>) and the integer
    307 argument must be an i32.</p>
    308 </li>
    309 <li><p class="first"><code>inttoptr</code></p>
    310 <p>The integer argument of a <code>inttoptr</code> instruction must be an i32.</p>
    311 </li>
    312 <li><p class="first"><code>bitcast</code></p>
    313 <p>The pointer argument of a <code>bitcast</code> instruction must be a <em>inherent</em> pointer
    314 (see <a class="reference internal" href="#bitcode-pointertypes"><em>pointer types</em></a>).</p>
    315 </li>
    316 <li><code>icmp</code></li>
    317 <li><code>fcmp</code></li>
    318 <li><code>phi</code></li>
    319 <li><code>select</code></li>
    320 <li><code>call</code></li>
    321 <li><code>unreachable</code></li>
    322 <li><code>insertelement</code></li>
    323 <li><code>extractelement</code></li>
    324 </ul>
    325 </section><section id="alloca">
    326 <span id="bitcode-allocainst"></span><h3 id="alloca"><span id="bitcode-allocainst"></span><code>alloca</code></h3>
    327 <p>The only allowed type for <code>alloca</code> instructions in PNaCl bitcode is i8. The
    328 size argument must be an i32. For example:</p>
    329 <pre>
    330   %buf = alloca i8, i32 8, align 4
    331 </pre>
    332 </section></section><section id="intrinsic-functions">
    333 <h2 id="intrinsic-functions">Intrinsic Functions</h2>
    334 <p><a class="reference external" href="http://llvm.org/releases/3.3/docs/LangRef.html#intrinsics">LLVM LangRef: Intrinsic Functions</a></p>
    335 <section id="list-of-allowed-intrinsics">
    336 <h3 id="list-of-allowed-intrinsics">List of allowed intrinsics</h3>
    337 <p>The only intrinsics supported by PNaCl bitcode are the following.</p>
    338 <ul class="small-gap">
    339 <li><code>llvm.memcpy</code></li>
    340 <li><code>llvm.memmove</code></li>
    341 <li><p class="first"><code>llvm.memset</code></p>
    342 <p>These intrinsics are only supported with an i32 <code>len</code> argument.</p>
    343 </li>
    344 <li><p class="first"><code>llvm.bswap</code></p>
    345 <p>The overloaded <code>llvm.bswap</code> intrinsic is only supported with the following
    346 argument types: i16, i32, i64 (the types supported by C-style GCC builtins).</p>
    347 </li>
    348 <li><code>llvm.ctlz</code></li>
    349 <li><code>llvm.cttz</code></li>
    350 <li><p class="first"><code>llvm.ctpop</code></p>
    351 <p>The overloaded llvm.ctlz, llvm.cttz, and llvm.ctpop intrinsics are only
    352 supported with the i32 and i64 argument types (the types supported by
    353 C-style GCC builtins).</p>
    354 </li>
    355 <li><p class="first"><code>llvm.sqrt</code></p>
    356 <p>The overloaded <code>llvm.sqrt</code> intrinsic is only supported for float
    357 and double arguments types. This has the same semantics as the libc
    358 sqrt function, returning NaN for values less than -0.0. However, this
    359 does not set <code>errno</code> when the result is NaN (see the
    360 <a class="reference internal" href="#ir-and-errno"><em>instructions and errno</em></a> section).</p>
    361 </li>
    362 <li><code>llvm.stacksave</code></li>
    363 <li><p class="first"><code>llvm.stackrestore</code></p>
    364 <p>These intrinsics are used to implement language features like scoped automatic
    365 variable sized arrays in C99. <code>llvm.stacksave</code> returns a value that
    366 represents the current state of the stack. This value may only be used as the
    367 argument to <code>llvm.stackrestore</code>, which restores the stack to the given
    368 state.</p>
    369 </li>
    370 <li><p class="first"><code>llvm.trap</code></p>
    371 <p>This intrinsic is lowered to a target dependent trap instruction, which aborts
    372 execution.</p>
    373 </li>
    374 <li><p class="first"><code>llvm.nacl.read.tp</code></p>
    375 <p>See <a class="reference internal" href="#bitcode-threadpointerintrinsics"><em>thread pointer related intrinsics</em></a>.</p>
    376 </li>
    377 <li><code>llvm.nacl.longjmp</code></li>
    378 <li><p class="first"><code>llvm.nacl.setjmp</code></p>
    379 <p>See <a class="reference internal" href="#bitcode-setjmplongjmp"><em>Setjmp and Longjmp</em></a>.</p>
    380 </li>
    381 <li><code>llvm.nacl.atomic.store</code></li>
    382 <li><code>llvm.nacl.atomic.load</code></li>
    383 <li><code>llvm.nacl.atomic.rmw</code></li>
    384 <li><code>llvm.nacl.atomic.cmpxchg</code></li>
    385 <li><code>llvm.nacl.atomic.fence</code></li>
    386 <li><code>llvm.nacl.atomic.fence.all</code></li>
    387 <li><p class="first"><code>llvm.nacl.atomic.is.lock.free</code></p>
    388 <p>See <a class="reference internal" href="#bitcode-atomicintrinsics"><em>atomic intrinsics</em></a>.</p>
    389 </li>
    390 </ul>
    391 </section><section id="thread-pointer-related-intrinsics">
    392 <span id="bitcode-threadpointerintrinsics"></span><h3 id="thread-pointer-related-intrinsics"><span id="bitcode-threadpointerintrinsics"></span>Thread pointer related intrinsics</h3>
    393 <pre>
    394   declare i8* &#64;llvm.nacl.read.tp()
    395 </pre>
    396 <p>Returns a read-only thread pointer. The value is controlled by the embedding
    397 sandbox&#8217;s runtime.</p>
    398 </section><section id="setjmp-and-longjmp">
    399 <span id="bitcode-setjmplongjmp"></span><h3 id="setjmp-and-longjmp"><span id="bitcode-setjmplongjmp"></span>Setjmp and Longjmp</h3>
    400 <pre>
    401   declare void &#64;llvm.nacl.longjmp(i8* %jmpbuf, i32)
    402   declare i32 &#64;llvm.nacl.setjmp(i8* %jmpbuf)
    403 </pre>
    404 <p>These intrinsics implement the semantics of C11 <code>setjmp</code> and <code>longjmp</code>. The
    405 <code>jmpbuf</code> pointer must be 64-bit aligned and point to at least 1024 bytes of
    406 allocated memory.</p>
    407 </section><section id="atomic-intrinsics">
    408 <span id="bitcode-atomicintrinsics"></span><h3 id="atomic-intrinsics"><span id="bitcode-atomicintrinsics"></span>Atomic intrinsics</h3>
    409 <pre>
    410   declare iN &#64;llvm.nacl.atomic.load.&lt;size&gt;(
    411           iN* &lt;source&gt;, i32 &lt;memory_order&gt;)
    412   declare void &#64;llvm.nacl.atomic.store.&lt;size&gt;(
    413           iN &lt;operand&gt;, iN* &lt;destination&gt;, i32 &lt;memory_order&gt;)
    414   declare iN &#64;llvm.nacl.atomic.rmw.&lt;size&gt;(
    415           i32 &lt;computation&gt;, iN* &lt;object&gt;, iN &lt;operand&gt;, i32 &lt;memory_order&gt;)
    416   declare iN &#64;llvm.nacl.atomic.cmpxchg.&lt;size&gt;(
    417           iN* &lt;object&gt;, iN &lt;expected&gt;, iN &lt;desired&gt;,
    418           i32 &lt;memory_order_success&gt;, i32 &lt;memory_order_failure&gt;)
    419   declare void &#64;llvm.nacl.atomic.fence(i32 &lt;memory_order&gt;)
    420   declare void &#64;llvm.nacl.atomic.fence.all()
    421 </pre>
    422 <p>Each of these intrinsics is overloaded on the <code>iN</code> argument, which is
    423 reflected through <code>&lt;size&gt;</code> in the overload&#8217;s name. Integral types of
    424 8, 16, 32 and 64-bit width are supported for these arguments.</p>
    425 <p>The <code>&#64;llvm.nacl.atomic.rmw</code> intrinsic implements the following
    426 read-modify-write operations, from the general and arithmetic sections
    427 of the C11/C++11 standards:</p>
    428 <blockquote>
    429 <div><ul class="small-gap">
    430 <li><code>add</code></li>
    431 <li><code>sub</code></li>
    432 <li><code>or</code></li>
    433 <li><code>and</code></li>
    434 <li><code>xor</code></li>
    435 <li><code>exchange</code></li>
    436 </ul>
    437 </div></blockquote>
    438 <p>For all of these read-modify-write operations, the returned value is
    439 that at <code>object</code> before the computation. The <code>computation</code> argument
    440 must be a compile-time constant.</p>
    441 <p>All atomic intrinsics also support C11/C++11 memory orderings, which
    442 must be compile-time constants.</p>
    443 <p>Integer values for these computations and memory orderings are defined
    444 in <code>&quot;llvm/IR/NaClAtomicIntrinsics.h&quot;</code>.</p>
    445 <p>The <code>&#64;llvm.nacl.atomic.fence.all</code> intrinsic is equivalent to the
    446 <code>&#64;llvm.nacl.atomic.fence</code> intrinsic with sequentially consistent
    447 ordering and compiler barriers preventing most non-atomic memory
    448 accesses from reordering around it.</p>
    449 <aside class="note">
    450 <blockquote>
    451 <div>These intrinsics allow PNaCl to support C11/C++11 style atomic
    452 operations as well as some legacy GCC-style <code>__sync_*</code> builtins
    453 while remaining stable as the LLVM codebase changes. The user isn&#8217;t
    454 expected to use these intrinsics directly.</div></blockquote>
    455 
    456 </aside>
    457 <pre>
    458   declare i1 &#64;llvm.nacl.atomic.is.lock.free(i32 &lt;byte_size&gt;, i8* &lt;address&gt;)
    459 </pre>
    460 <p>The <code>llvm.nacl.atomic.is.lock.free</code> intrinsic is designed to
    461 determine at translation time whether atomic operations of a certain
    462 <code>byte_size</code> (a compile-time constant), at a particular <code>address</code>,
    463 are lock-free or not. This reflects the C11 <code>atomic_is_lock_free</code>
    464 function from header <code>&lt;stdatomic.h&gt;</code> and the C++11 <code>is_lock_free</code>
    465 member function in header <code>&lt;atomic&gt;</code>. It can be used through the
    466 <code>__nacl_atomic_is_lock_free</code> builtin.</p>
    467 </section></section></section>
    468 
    469 {{/partials.standard_nacl_article}}
    470