[SyncFS] Build indexes from FileTracker entries on disk.
[chromium-blink-merge.git] / native_client_sdk / doc_generated / reference / pnacl-bitcode-abi.html
blobf6c2590631ed223721d7d8f23c3b51f43f1b36ed
1 {{+bindTo:partials.standard_nacl_article}}
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>
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, except for
205 <code>i1</code>.</li>
206 <li>Pointers to valid PNaCl bitcode vector types, as specified above, except for
207 <code>&lt;? x i1&gt;</code>.</li>
208 <li>Pointers to functions.</li>
209 </ul>
210 <p>In addition, the address space for all pointers must be 0.</p>
211 <p>A pointer is <em>inherent</em> when it represents the return value of an <code>alloca</code>
212 instruction, or is an address of a global value.</p>
213 <p>A pointer is <em>normalized</em> if it&#8217;s either:</p>
214 <ul class="small-gap">
215 <li><em>inherent</em></li>
216 <li>Is the return value of a <code>bitcast</code> instruction.</li>
217 <li>Is the return value of a <code>inttoptr</code> instruction.</li>
218 </ul>
219 </section><section id="undefined-values">
220 <h3 id="undefined-values">Undefined Values</h3>
221 <p><a class="reference external" href="http://llvm.org/releases/3.3/docs/LangRef.html#undefvalues">LLVM LangRef: Undefined Values</a></p>
222 <p><code>undef</code> is only allowed within functions, not in global variable initializers.</p>
223 </section><section id="constant-expressions">
224 <h3 id="constant-expressions">Constant Expressions</h3>
225 <p><a class="reference external" href="http://llvm.org/releases/3.3/docs/LangRef.html#constant-expressions">LLVM LangRef: Constant Expressions</a></p>
226 <p>Constant expressions are only allowed in
227 <a class="reference internal" href="#bitcode-globalvariables"><em>global variable initializers</em></a>.</p>
228 </section></section><section id="other-values">
229 <h2 id="other-values">Other Values</h2>
230 <section id="metadata-nodes-and-metadata-strings">
231 <h3 id="metadata-nodes-and-metadata-strings">Metadata Nodes and Metadata Strings</h3>
232 <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>
233 <p>While PNaCl bitcode has provisions for debugging metadata, it is not considered
234 part of the stable ABI. It exists for tool support and should not appear in
235 distributed pexes.</p>
236 <p>Other kinds of LLVM metadata are not supported.</p>
237 </section></section><section id="intrinsic-global-variables">
238 <h2 id="intrinsic-global-variables">Intrinsic Global Variables</h2>
239 <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>
240 <p>PNaCl bitcode does not support intrinsic global variables.</p>
241 </section><section id="errno-and-errors-in-arithmetic-instructions">
242 <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>
243 <p>Some arithmetic instructions and intrinsics have the similar semantics to
244 libc math functions, but differ in the treatment of <code>errno</code>. While the
245 libc functions may set <code>errno</code> for domain errors, the instructions and
246 intrinsics do not. This is because the variable <code>errno</code> is not special
247 and is not required to be part of the program.</p>
248 </section><section id="instruction-reference">
249 <h2 id="instruction-reference">Instruction Reference</h2>
250 <section id="list-of-allowed-instructions">
251 <h3 id="list-of-allowed-instructions">List of allowed instructions</h3>
252 <p>This is a list of LLVM instructions supported by PNaCl bitcode. Where
253 applicable, PNaCl-specific restrictions are provided.</p>
254 <p>The following attributes are disallowed for all instructions:</p>
255 <ul class="small-gap">
256 <li><code>nsw</code> and <code>nuw</code></li>
257 <li><code>exact</code></li>
258 </ul>
259 <p>Only the LLVM instructions listed here are supported by PNaCl bitcode.</p>
260 <ul class="small-gap">
261 <li><code>ret</code></li>
262 <li><code>br</code></li>
263 <li><p class="first"><code>switch</code></p>
264 <p>i1 values are disallowed for <code>switch</code>.</p>
265 </li>
266 <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>,
267 <code>lshr</code>, <code>ashr</code></p>
268 <p>These arithmetic operations are disallowed on values of type <code>i1</code>.</p>
269 <p>Integer division (<code>udiv</code>, <code>sdiv</code>, <code>urem</code>, <code>srem</code>) by zero is
270 guaranteed to trap in PNaCl bitcode.</p>
271 </li>
272 <li><code>and</code></li>
273 <li><code>or</code></li>
274 <li><code>xor</code></li>
275 <li><code>fadd</code></li>
276 <li><code>fsub</code></li>
277 <li><code>fmul</code></li>
278 <li><code>fdiv</code></li>
279 <li><p class="first"><code>frem</code></p>
280 <p>The frem instruction has the semantics of the libc fmod function for
281 computing the floating point remainder. If the numerator is infinity, or
282 denominator is zero, or either are NaN, then the result is NaN.
283 Unlike the libc fmod function, this does not set <code>errno</code> when the
284 result is NaN (see the <a class="reference internal" href="#ir-and-errno"><em>instructions and errno</em></a>
285 section).</p>
286 </li>
287 <li><p class="first"><code>alloca</code></p>
288 <p>See <a class="reference internal" href="#bitcode-allocainst"><em>alloca instructions</em></a>.</p>
289 </li>
290 <li><p class="first"><code>load</code>, <code>store</code></p>
291 <p>The pointer argument of these instructions must be a <em>normalized</em> pointer (see
292 <a class="reference internal" href="#bitcode-pointertypes"><em>pointer types</em></a>). The <code>volatile</code> and <code>atomic</code>
293 attributes are not supported. Loads and stores of the type <code>i1</code> and <code>&lt;? x
294 i1&gt;</code> are not supported.</p>
295 <p>These instructions must follow the following alignment restrictions:</p>
296 <ul class="small-gap">
297 <li>On integer memory accesses: <code>align 1</code>.</li>
298 <li>On <code>float</code> memory accesses: <code>align 1</code> or <code>align 4</code>.</li>
299 <li>On <code>double</code> memory accesses: <code>align 1</code> or <code>align 8</code>.</li>
300 <li>On vector memory accesses: alignment at the vector&#8217;s element width, for
301 example <code>&lt;4 x i32&gt;</code> must be <code>align 4</code>.</li>
302 </ul>
303 </li>
304 <li><code>trunc</code></li>
305 <li><code>zext</code></li>
306 <li><code>sext</code></li>
307 <li><code>fptrunc</code></li>
308 <li><code>fpext</code></li>
309 <li><code>fptoui</code></li>
310 <li><code>fptosi</code></li>
311 <li><code>uitofp</code></li>
312 <li><code>sitofp</code></li>
313 <li><p class="first"><code>ptrtoint</code></p>
314 <p>The pointer argument of a <code>ptrtoint</code> instruction must be a <em>normalized</em>
315 pointer (see <a class="reference internal" href="#bitcode-pointertypes"><em>pointer types</em></a>) and the integer
316 argument must be an i32.</p>
317 </li>
318 <li><p class="first"><code>inttoptr</code></p>
319 <p>The integer argument of a <code>inttoptr</code> instruction must be an i32.</p>
320 </li>
321 <li><p class="first"><code>bitcast</code></p>
322 <p>The pointer argument of a <code>bitcast</code> instruction must be a <em>inherent</em> pointer
323 (see <a class="reference internal" href="#bitcode-pointertypes"><em>pointer types</em></a>).</p>
324 </li>
325 <li><code>icmp</code></li>
326 <li><code>fcmp</code></li>
327 <li><code>phi</code></li>
328 <li><code>select</code></li>
329 <li><code>call</code></li>
330 <li><code>unreachable</code></li>
331 <li><code>insertelement</code></li>
332 <li><code>extractelement</code></li>
333 </ul>
334 </section><section id="alloca">
335 <span id="bitcode-allocainst"></span><h3 id="alloca"><span id="bitcode-allocainst"></span><code>alloca</code></h3>
336 <p>The only allowed type for <code>alloca</code> instructions in PNaCl bitcode is i8. The
337 size argument must be an i32. For example:</p>
338 <pre>
339 %buf = alloca i8, i32 8, align 4
340 </pre>
341 </section></section><section id="intrinsic-functions">
342 <h2 id="intrinsic-functions">Intrinsic Functions</h2>
343 <p><a class="reference external" href="http://llvm.org/releases/3.3/docs/LangRef.html#intrinsics">LLVM LangRef: Intrinsic Functions</a></p>
344 <section id="list-of-allowed-intrinsics">
345 <h3 id="list-of-allowed-intrinsics">List of allowed intrinsics</h3>
346 <p>The only intrinsics supported by PNaCl bitcode are the following.</p>
347 <ul class="small-gap">
348 <li><code>llvm.memcpy</code></li>
349 <li><code>llvm.memmove</code></li>
350 <li><p class="first"><code>llvm.memset</code></p>
351 <p>These intrinsics are only supported with an i32 <code>len</code> argument.</p>
352 </li>
353 <li><p class="first"><code>llvm.bswap</code></p>
354 <p>The overloaded <code>llvm.bswap</code> intrinsic is only supported with the following
355 argument types: i16, i32, i64 (the types supported by C-style GCC builtins).</p>
356 </li>
357 <li><code>llvm.ctlz</code></li>
358 <li><code>llvm.cttz</code></li>
359 <li><p class="first"><code>llvm.ctpop</code></p>
360 <p>The overloaded llvm.ctlz, llvm.cttz, and llvm.ctpop intrinsics are only
361 supported with the i32 and i64 argument types (the types supported by
362 C-style GCC builtins).</p>
363 </li>
364 <li><p class="first"><code>llvm.sqrt</code></p>
365 <p>The overloaded <code>llvm.sqrt</code> intrinsic is only supported for float
366 and double arguments types. This has the same semantics as the libc
367 sqrt function, returning NaN for values less than -0.0. However, this
368 does not set <code>errno</code> when the result is NaN (see the
369 <a class="reference internal" href="#ir-and-errno"><em>instructions and errno</em></a> section).</p>
370 </li>
371 <li><code>llvm.stacksave</code></li>
372 <li><p class="first"><code>llvm.stackrestore</code></p>
373 <p>These intrinsics are used to implement language features like scoped automatic
374 variable sized arrays in C99. <code>llvm.stacksave</code> returns a value that
375 represents the current state of the stack. This value may only be used as the
376 argument to <code>llvm.stackrestore</code>, which restores the stack to the given
377 state.</p>
378 </li>
379 <li><p class="first"><code>llvm.trap</code></p>
380 <p>This intrinsic is lowered to a target dependent trap instruction, which aborts
381 execution.</p>
382 </li>
383 <li><p class="first"><code>llvm.nacl.read.tp</code></p>
384 <p>See <a class="reference internal" href="#bitcode-threadpointerintrinsics"><em>thread pointer related intrinsics</em></a>.</p>
385 </li>
386 <li><code>llvm.nacl.longjmp</code></li>
387 <li><p class="first"><code>llvm.nacl.setjmp</code></p>
388 <p>See <a class="reference internal" href="#bitcode-setjmplongjmp"><em>Setjmp and Longjmp</em></a>.</p>
389 </li>
390 <li><code>llvm.nacl.atomic.store</code></li>
391 <li><code>llvm.nacl.atomic.load</code></li>
392 <li><code>llvm.nacl.atomic.rmw</code></li>
393 <li><code>llvm.nacl.atomic.cmpxchg</code></li>
394 <li><code>llvm.nacl.atomic.fence</code></li>
395 <li><code>llvm.nacl.atomic.fence.all</code></li>
396 <li><p class="first"><code>llvm.nacl.atomic.is.lock.free</code></p>
397 <p>See <a class="reference internal" href="#bitcode-atomicintrinsics"><em>atomic intrinsics</em></a>.</p>
398 </li>
399 </ul>
400 </section><section id="thread-pointer-related-intrinsics">
401 <span id="bitcode-threadpointerintrinsics"></span><h3 id="thread-pointer-related-intrinsics"><span id="bitcode-threadpointerintrinsics"></span>Thread pointer related intrinsics</h3>
402 <pre>
403 declare i8* &#64;llvm.nacl.read.tp()
404 </pre>
405 <p>Returns a read-only thread pointer. The value is controlled by the embedding
406 sandbox&#8217;s runtime.</p>
407 </section><section id="setjmp-and-longjmp">
408 <span id="bitcode-setjmplongjmp"></span><h3 id="setjmp-and-longjmp"><span id="bitcode-setjmplongjmp"></span>Setjmp and Longjmp</h3>
409 <pre>
410 declare void &#64;llvm.nacl.longjmp(i8* %jmpbuf, i32)
411 declare i32 &#64;llvm.nacl.setjmp(i8* %jmpbuf)
412 </pre>
413 <p>These intrinsics implement the semantics of C11 <code>setjmp</code> and <code>longjmp</code>. The
414 <code>jmpbuf</code> pointer must be 64-bit aligned and point to at least 1024 bytes of
415 allocated memory.</p>
416 </section><section id="atomic-intrinsics">
417 <span id="bitcode-atomicintrinsics"></span><h3 id="atomic-intrinsics"><span id="bitcode-atomicintrinsics"></span>Atomic intrinsics</h3>
418 <pre>
419 declare iN &#64;llvm.nacl.atomic.load.&lt;size&gt;(
420 iN* &lt;source&gt;, i32 &lt;memory_order&gt;)
421 declare void &#64;llvm.nacl.atomic.store.&lt;size&gt;(
422 iN &lt;operand&gt;, iN* &lt;destination&gt;, i32 &lt;memory_order&gt;)
423 declare iN &#64;llvm.nacl.atomic.rmw.&lt;size&gt;(
424 i32 &lt;computation&gt;, iN* &lt;object&gt;, iN &lt;operand&gt;, i32 &lt;memory_order&gt;)
425 declare iN &#64;llvm.nacl.atomic.cmpxchg.&lt;size&gt;(
426 iN* &lt;object&gt;, iN &lt;expected&gt;, iN &lt;desired&gt;,
427 i32 &lt;memory_order_success&gt;, i32 &lt;memory_order_failure&gt;)
428 declare void &#64;llvm.nacl.atomic.fence(i32 &lt;memory_order&gt;)
429 declare void &#64;llvm.nacl.atomic.fence.all()
430 </pre>
431 <p>Each of these intrinsics is overloaded on the <code>iN</code> argument, which is
432 reflected through <code>&lt;size&gt;</code> in the overload&#8217;s name. Integral types of
433 8, 16, 32 and 64-bit width are supported for these arguments.</p>
434 <p>The <code>&#64;llvm.nacl.atomic.rmw</code> intrinsic implements the following
435 read-modify-write operations, from the general and arithmetic sections
436 of the C11/C++11 standards:</p>
437 <blockquote>
438 <div><ul class="small-gap">
439 <li><code>add</code></li>
440 <li><code>sub</code></li>
441 <li><code>or</code></li>
442 <li><code>and</code></li>
443 <li><code>xor</code></li>
444 <li><code>exchange</code></li>
445 </ul>
446 </div></blockquote>
447 <p>For all of these read-modify-write operations, the returned value is
448 that at <code>object</code> before the computation. The <code>computation</code> argument
449 must be a compile-time constant.</p>
450 <p>All atomic intrinsics also support C11/C++11 memory orderings, which
451 must be compile-time constants.</p>
452 <p>Integer values for these computations and memory orderings are defined
453 in <code>&quot;llvm/IR/NaClAtomicIntrinsics.h&quot;</code>.</p>
454 <p>The <code>&#64;llvm.nacl.atomic.fence.all</code> intrinsic is equivalent to the
455 <code>&#64;llvm.nacl.atomic.fence</code> intrinsic with sequentially consistent
456 ordering and compiler barriers preventing most non-atomic memory
457 accesses from reordering around it.</p>
458 <aside class="note">
459 <blockquote>
460 <div>These intrinsics allow PNaCl to support C11/C++11 style atomic
461 operations as well as some legacy GCC-style <code>__sync_*</code> builtins
462 while remaining stable as the LLVM codebase changes. The user isn&#8217;t
463 expected to use these intrinsics directly.</div></blockquote>
465 </aside>
466 <pre>
467 declare i1 &#64;llvm.nacl.atomic.is.lock.free(i32 &lt;byte_size&gt;, i8* &lt;address&gt;)
468 </pre>
469 <p>The <code>llvm.nacl.atomic.is.lock.free</code> intrinsic is designed to
470 determine at translation time whether atomic operations of a certain
471 <code>byte_size</code> (a compile-time constant), at a particular <code>address</code>,
472 are lock-free or not. This reflects the C11 <code>atomic_is_lock_free</code>
473 function from header <code>&lt;stdatomic.h&gt;</code> and the C++11 <code>is_lock_free</code>
474 member function in header <code>&lt;atomic&gt;</code>. It can be used through the
475 <code>__nacl_atomic_is_lock_free</code> builtin.</p>
476 </section></section></section>
478 {{/partials.standard_nacl_article}}