blob: eb7638fed3606f8ae304a8b5b121e4d4ed424c04 [file] [log] [blame]
Sean Silvab084af42012-12-07 10:36:55 +00001==============================
2LLVM Language Reference Manual
3==============================
4
5.. contents::
6 :local:
Rafael Espindola08013342013-12-07 19:34:20 +00007 :depth: 4
Sean Silvab084af42012-12-07 10:36:55 +00008
Sean Silvab084af42012-12-07 10:36:55 +00009Abstract
10========
11
12This document is a reference manual for the LLVM assembly language. LLVM
13is a Static Single Assignment (SSA) based representation that provides
14type safety, low-level operations, flexibility, and the capability of
15representing 'all' high-level languages cleanly. It is the common code
16representation used throughout all phases of the LLVM compilation
17strategy.
18
19Introduction
20============
21
22The LLVM code representation is designed to be used in three different
23forms: as an in-memory compiler IR, as an on-disk bitcode representation
24(suitable for fast loading by a Just-In-Time compiler), and as a human
25readable assembly language representation. This allows LLVM to provide a
26powerful intermediate representation for efficient compiler
27transformations and analysis, while providing a natural means to debug
28and visualize the transformations. The three different forms of LLVM are
29all equivalent. This document describes the human readable
30representation and notation.
31
32The LLVM representation aims to be light-weight and low-level while
33being expressive, typed, and extensible at the same time. It aims to be
34a "universal IR" of sorts, by being at a low enough level that
35high-level ideas may be cleanly mapped to it (similar to how
36microprocessors are "universal IR's", allowing many source languages to
37be mapped to them). By providing type information, LLVM can be used as
38the target of optimizations: for example, through pointer analysis, it
39can be proven that a C automatic variable is never accessed outside of
40the current function, allowing it to be promoted to a simple SSA value
41instead of a memory location.
42
43.. _wellformed:
44
45Well-Formedness
46---------------
47
48It is important to note that this document describes 'well formed' LLVM
49assembly language. There is a difference between what the parser accepts
50and what is considered 'well formed'. For example, the following
51instruction is syntactically okay, but not well formed:
52
53.. code-block:: llvm
54
55 %x = add i32 1, %x
56
57because the definition of ``%x`` does not dominate all of its uses. The
58LLVM infrastructure provides a verification pass that may be used to
59verify that an LLVM module is well formed. This pass is automatically
60run by the parser after parsing input assembly and by the optimizer
61before it outputs bitcode. The violations pointed out by the verifier
62pass indicate bugs in transformation passes or input to the parser.
63
64.. _identifiers:
65
66Identifiers
67===========
68
69LLVM identifiers come in two basic types: global and local. Global
70identifiers (functions, global variables) begin with the ``'@'``
71character. Local identifiers (register names, types) begin with the
72``'%'`` character. Additionally, there are three different formats for
73identifiers, for different purposes:
74
75#. Named values are represented as a string of characters with their
76 prefix. For example, ``%foo``, ``@DivisionByZero``,
77 ``%a.really.long.identifier``. The actual regular expression used is
Sean Silva9d01a5b2015-01-07 21:35:14 +000078 '``[%@][-a-zA-Z$._][-a-zA-Z$._0-9]*``'. Identifiers that require other
Sean Silvab084af42012-12-07 10:36:55 +000079 characters in their names can be surrounded with quotes. Special
80 characters may be escaped using ``"\xx"`` where ``xx`` is the ASCII
81 code for the character in hexadecimal. In this way, any character can
Hans Wennborg85e06532014-07-30 20:02:08 +000082 be used in a name value, even quotes themselves. The ``"\01"`` prefix
83 can be used on global variables to suppress mangling.
Sean Silvab084af42012-12-07 10:36:55 +000084#. Unnamed values are represented as an unsigned numeric value with
85 their prefix. For example, ``%12``, ``@2``, ``%44``.
Sean Silvaa1190322015-08-06 22:56:48 +000086#. Constants, which are described in the section Constants_ below.
Sean Silvab084af42012-12-07 10:36:55 +000087
88LLVM requires that values start with a prefix for two reasons: Compilers
89don't need to worry about name clashes with reserved words, and the set
90of reserved words may be expanded in the future without penalty.
91Additionally, unnamed identifiers allow a compiler to quickly come up
92with a temporary variable without having to avoid symbol table
93conflicts.
94
95Reserved words in LLVM are very similar to reserved words in other
96languages. There are keywords for different opcodes ('``add``',
97'``bitcast``', '``ret``', etc...), for primitive type names ('``void``',
98'``i32``', etc...), and others. These reserved words cannot conflict
99with variable names, because none of them start with a prefix character
100(``'%'`` or ``'@'``).
101
102Here is an example of LLVM code to multiply the integer variable
103'``%X``' by 8:
104
105The easy way:
106
107.. code-block:: llvm
108
109 %result = mul i32 %X, 8
110
111After strength reduction:
112
113.. code-block:: llvm
114
Dmitri Gribenko675911d2013-01-26 13:30:13 +0000115 %result = shl i32 %X, 3
Sean Silvab084af42012-12-07 10:36:55 +0000116
117And the hard way:
118
119.. code-block:: llvm
120
Tim Northover675a0962014-06-13 14:24:23 +0000121 %0 = add i32 %X, %X ; yields i32:%0
122 %1 = add i32 %0, %0 ; yields i32:%1
Sean Silvab084af42012-12-07 10:36:55 +0000123 %result = add i32 %1, %1
124
125This last way of multiplying ``%X`` by 8 illustrates several important
126lexical features of LLVM:
127
128#. Comments are delimited with a '``;``' and go until the end of line.
129#. Unnamed temporaries are created when the result of a computation is
130 not assigned to a named value.
Sean Silva8ca11782013-05-20 23:31:12 +0000131#. Unnamed temporaries are numbered sequentially (using a per-function
Dan Liew2661dfc2014-08-20 15:06:30 +0000132 incrementing counter, starting with 0). Note that basic blocks and unnamed
133 function parameters are included in this numbering. For example, if the
134 entry basic block is not given a label name and all function parameters are
135 named, then it will get number 0.
Sean Silvab084af42012-12-07 10:36:55 +0000136
137It also shows a convention that we follow in this document. When
138demonstrating instructions, we will follow an instruction with a comment
139that defines the type and name of value produced.
140
141High Level Structure
142====================
143
144Module Structure
145----------------
146
147LLVM programs are composed of ``Module``'s, each of which is a
148translation unit of the input programs. Each module consists of
149functions, global variables, and symbol table entries. Modules may be
150combined together with the LLVM linker, which merges function (and
151global variable) definitions, resolves forward declarations, and merges
152symbol table entries. Here is an example of the "hello world" module:
153
154.. code-block:: llvm
155
Michael Liaoa7699082013-03-06 18:24:34 +0000156 ; Declare the string constant as a global constant.
157 @.str = private unnamed_addr constant [13 x i8] c"hello world\0A\00"
Sean Silvab084af42012-12-07 10:36:55 +0000158
Michael Liaoa7699082013-03-06 18:24:34 +0000159 ; External declaration of the puts function
160 declare i32 @puts(i8* nocapture) nounwind
Sean Silvab084af42012-12-07 10:36:55 +0000161
162 ; Definition of main function
Michael Liaoa7699082013-03-06 18:24:34 +0000163 define i32 @main() { ; i32()*
George Burgess IVfbc34982017-05-20 04:52:29 +0000164 ; Convert [13 x i8]* to i8*...
David Blaikie16a97eb2015-03-04 22:02:58 +0000165 %cast210 = getelementptr [13 x i8], [13 x i8]* @.str, i64 0, i64 0
Sean Silvab084af42012-12-07 10:36:55 +0000166
Michael Liaoa7699082013-03-06 18:24:34 +0000167 ; Call puts function to write out the string to stdout.
Sean Silvab084af42012-12-07 10:36:55 +0000168 call i32 @puts(i8* %cast210)
Michael Liaoa7699082013-03-06 18:24:34 +0000169 ret i32 0
Sean Silvab084af42012-12-07 10:36:55 +0000170 }
171
172 ; Named metadata
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +0000173 !0 = !{i32 42, null, !"string"}
Nick Lewyckya0de40a2014-08-13 04:54:05 +0000174 !foo = !{!0}
Sean Silvab084af42012-12-07 10:36:55 +0000175
176This example is made up of a :ref:`global variable <globalvars>` named
177"``.str``", an external declaration of the "``puts``" function, a
178:ref:`function definition <functionstructure>` for "``main``" and
179:ref:`named metadata <namedmetadatastructure>` "``foo``".
180
181In general, a module is made up of a list of global values (where both
182functions and global variables are global values). Global values are
183represented by a pointer to a memory location (in this case, a pointer
184to an array of char, and a pointer to a function), and have one of the
185following :ref:`linkage types <linkage>`.
186
187.. _linkage:
188
189Linkage Types
190-------------
191
192All Global Variables and Functions have one of the following types of
193linkage:
194
195``private``
196 Global values with "``private``" linkage are only directly
197 accessible by objects in the current module. In particular, linking
Sylvestre Ledru0604c5c2017-03-04 14:01:38 +0000198 code into a module with a private global value may cause the
Sean Silvab084af42012-12-07 10:36:55 +0000199 private to be renamed as necessary to avoid collisions. Because the
200 symbol is private to the module, all references can be updated. This
201 doesn't show up in any symbol table in the object file.
Sean Silvab084af42012-12-07 10:36:55 +0000202``internal``
203 Similar to private, but the value shows as a local symbol
204 (``STB_LOCAL`` in the case of ELF) in the object file. This
205 corresponds to the notion of the '``static``' keyword in C.
206``available_externally``
Peter Collingbourne45cd0c32015-12-14 19:22:37 +0000207 Globals with "``available_externally``" linkage are never emitted into
208 the object file corresponding to the LLVM module. From the linker's
209 perspective, an ``available_externally`` global is equivalent to
210 an external declaration. They exist to allow inlining and other
211 optimizations to take place given knowledge of the definition of the
212 global, which is known to be somewhere outside the module. Globals
213 with ``available_externally`` linkage are allowed to be discarded at
214 will, and allow inlining and other optimizations. This linkage type is
215 only allowed on definitions, not declarations.
Sean Silvab084af42012-12-07 10:36:55 +0000216``linkonce``
217 Globals with "``linkonce``" linkage are merged with other globals of
218 the same name when linkage occurs. This can be used to implement
219 some forms of inline functions, templates, or other code which must
220 be generated in each translation unit that uses it, but where the
221 body may be overridden with a more definitive definition later.
222 Unreferenced ``linkonce`` globals are allowed to be discarded. Note
223 that ``linkonce`` linkage does not actually allow the optimizer to
224 inline the body of this function into callers because it doesn't
225 know if this definition of the function is the definitive definition
226 within the program or whether it will be overridden by a stronger
227 definition. To enable inlining and other optimizations, use
228 "``linkonce_odr``" linkage.
229``weak``
230 "``weak``" linkage has the same merging semantics as ``linkonce``
231 linkage, except that unreferenced globals with ``weak`` linkage may
232 not be discarded. This is used for globals that are declared "weak"
233 in C source code.
234``common``
235 "``common``" linkage is most similar to "``weak``" linkage, but they
236 are used for tentative definitions in C, such as "``int X;``" at
237 global scope. Symbols with "``common``" linkage are merged in the
238 same way as ``weak symbols``, and they may not be deleted if
239 unreferenced. ``common`` symbols may not have an explicit section,
240 must have a zero initializer, and may not be marked
241 ':ref:`constant <globalvars>`'. Functions and aliases may not have
242 common linkage.
243
244.. _linkage_appending:
245
246``appending``
247 "``appending``" linkage may only be applied to global variables of
248 pointer to array type. When two global variables with appending
249 linkage are linked together, the two global arrays are appended
250 together. This is the LLVM, typesafe, equivalent of having the
251 system linker append together "sections" with identical names when
252 .o files are linked.
Rafael Espindolae64619c2016-05-16 21:14:24 +0000253
254 Unfortunately this doesn't correspond to any feature in .o files, so it
255 can only be used for variables like ``llvm.global_ctors`` which llvm
256 interprets specially.
257
Sean Silvab084af42012-12-07 10:36:55 +0000258``extern_weak``
259 The semantics of this linkage follow the ELF object file model: the
260 symbol is weak until linked, if not linked, the symbol becomes null
261 instead of being an undefined reference.
262``linkonce_odr``, ``weak_odr``
263 Some languages allow differing globals to be merged, such as two
264 functions with different semantics. Other languages, such as
265 ``C++``, ensure that only equivalent globals are ever merged (the
Sean Silvaa1190322015-08-06 22:56:48 +0000266 "one definition rule" --- "ODR"). Such languages can use the
Sean Silvab084af42012-12-07 10:36:55 +0000267 ``linkonce_odr`` and ``weak_odr`` linkage types to indicate that the
268 global will only be merged with equivalent globals. These linkage
269 types are otherwise the same as their non-``odr`` versions.
Sean Silvab084af42012-12-07 10:36:55 +0000270``external``
271 If none of the above identifiers are used, the global is externally
272 visible, meaning that it participates in linkage and can be used to
273 resolve external symbol references.
274
Sean Silvab084af42012-12-07 10:36:55 +0000275It is illegal for a function *declaration* to have any linkage type
Nico Rieck7157bb72014-01-14 15:22:47 +0000276other than ``external`` or ``extern_weak``.
Sean Silvab084af42012-12-07 10:36:55 +0000277
Sean Silvab084af42012-12-07 10:36:55 +0000278.. _callingconv:
279
280Calling Conventions
281-------------------
282
283LLVM :ref:`functions <functionstructure>`, :ref:`calls <i_call>` and
284:ref:`invokes <i_invoke>` can all have an optional calling convention
285specified for the call. The calling convention of any pair of dynamic
286caller/callee must match, or the behavior of the program is undefined.
287The following calling conventions are supported by LLVM, and more may be
288added in the future:
289
290"``ccc``" - The C calling convention
291 This calling convention (the default if no other calling convention
292 is specified) matches the target C calling conventions. This calling
293 convention supports varargs function calls and tolerates some
294 mismatch in the declared prototype and implemented declaration of
295 the function (as does normal C).
296"``fastcc``" - The fast calling convention
297 This calling convention attempts to make calls as fast as possible
298 (e.g. by passing things in registers). This calling convention
299 allows the target to use whatever tricks it wants to produce fast
300 code for the target, without having to conform to an externally
301 specified ABI (Application Binary Interface). `Tail calls can only
302 be optimized when this, the GHC or the HiPE convention is
303 used. <CodeGenerator.html#id80>`_ This calling convention does not
304 support varargs and requires the prototype of all callees to exactly
305 match the prototype of the function definition.
306"``coldcc``" - The cold calling convention
307 This calling convention attempts to make code in the caller as
308 efficient as possible under the assumption that the call is not
309 commonly executed. As such, these calls often preserve all registers
310 so that the call does not break any live ranges in the caller side.
311 This calling convention does not support varargs and requires the
312 prototype of all callees to exactly match the prototype of the
Juergen Ributzka5d05ed12014-01-17 22:24:35 +0000313 function definition. Furthermore the inliner doesn't consider such function
314 calls for inlining.
Sean Silvab084af42012-12-07 10:36:55 +0000315"``cc 10``" - GHC convention
316 This calling convention has been implemented specifically for use by
317 the `Glasgow Haskell Compiler (GHC) <http://www.haskell.org/ghc>`_.
318 It passes everything in registers, going to extremes to achieve this
319 by disabling callee save registers. This calling convention should
320 not be used lightly but only for specific situations such as an
321 alternative to the *register pinning* performance technique often
322 used when implementing functional programming languages. At the
323 moment only X86 supports this convention and it has the following
324 limitations:
325
326 - On *X86-32* only supports up to 4 bit type parameters. No
327 floating point types are supported.
328 - On *X86-64* only supports up to 10 bit type parameters and 6
329 floating point parameters.
330
331 This calling convention supports `tail call
332 optimization <CodeGenerator.html#id80>`_ but requires both the
333 caller and callee are using it.
334"``cc 11``" - The HiPE calling convention
335 This calling convention has been implemented specifically for use by
336 the `High-Performance Erlang
337 (HiPE) <http://www.it.uu.se/research/group/hipe/>`_ compiler, *the*
338 native code compiler of the `Ericsson's Open Source Erlang/OTP
339 system <http://www.erlang.org/download.shtml>`_. It uses more
340 registers for argument passing than the ordinary C calling
341 convention and defines no callee-saved registers. The calling
342 convention properly supports `tail call
343 optimization <CodeGenerator.html#id80>`_ but requires that both the
344 caller and the callee use it. It uses a *register pinning*
345 mechanism, similar to GHC's convention, for keeping frequently
346 accessed runtime components pinned to specific hardware registers.
347 At the moment only X86 supports this convention (both 32 and 64
348 bit).
Andrew Trick5e029ce2013-12-24 02:57:25 +0000349"``webkit_jscc``" - WebKit's JavaScript calling convention
350 This calling convention has been implemented for `WebKit FTL JIT
351 <https://trac.webkit.org/wiki/FTLJIT>`_. It passes arguments on the
352 stack right to left (as cdecl does), and returns a value in the
353 platform's customary return register.
354"``anyregcc``" - Dynamic calling convention for code patching
355 This is a special convention that supports patching an arbitrary code
356 sequence in place of a call site. This convention forces the call
Eli Bendersky45324ce2015-04-02 15:20:04 +0000357 arguments into registers but allows them to be dynamically
Andrew Trick5e029ce2013-12-24 02:57:25 +0000358 allocated. This can currently only be used with calls to
359 llvm.experimental.patchpoint because only this intrinsic records
360 the location of its arguments in a side table. See :doc:`StackMaps`.
Juergen Ributzkae6250132014-01-17 19:47:03 +0000361"``preserve_mostcc``" - The `PreserveMost` calling convention
Eli Bendersky45324ce2015-04-02 15:20:04 +0000362 This calling convention attempts to make the code in the caller as
363 unintrusive as possible. This convention behaves identically to the `C`
Juergen Ributzkae6250132014-01-17 19:47:03 +0000364 calling convention on how arguments and return values are passed, but it
365 uses a different set of caller/callee-saved registers. This alleviates the
366 burden of saving and recovering a large register set before and after the
Juergen Ributzka980f2dc2014-01-30 02:39:00 +0000367 call in the caller. If the arguments are passed in callee-saved registers,
368 then they will be preserved by the callee across the call. This doesn't
369 apply for values returned in callee-saved registers.
Juergen Ributzkae6250132014-01-17 19:47:03 +0000370
371 - On X86-64 the callee preserves all general purpose registers, except for
372 R11. R11 can be used as a scratch register. Floating-point registers
373 (XMMs/YMMs) are not preserved and need to be saved by the caller.
374
375 The idea behind this convention is to support calls to runtime functions
376 that have a hot path and a cold path. The hot path is usually a small piece
Eric Christopher1e61ffd2015-02-19 18:46:25 +0000377 of code that doesn't use many registers. The cold path might need to call out to
Juergen Ributzkae6250132014-01-17 19:47:03 +0000378 another function and therefore only needs to preserve the caller-saved
Juergen Ributzka5d05ed12014-01-17 22:24:35 +0000379 registers, which haven't already been saved by the caller. The
380 `PreserveMost` calling convention is very similar to the `cold` calling
381 convention in terms of caller/callee-saved registers, but they are used for
382 different types of function calls. `coldcc` is for function calls that are
383 rarely executed, whereas `preserve_mostcc` function calls are intended to be
384 on the hot path and definitely executed a lot. Furthermore `preserve_mostcc`
385 doesn't prevent the inliner from inlining the function call.
Juergen Ributzkae6250132014-01-17 19:47:03 +0000386
387 This calling convention will be used by a future version of the ObjectiveC
388 runtime and should therefore still be considered experimental at this time.
389 Although this convention was created to optimize certain runtime calls to
390 the ObjectiveC runtime, it is not limited to this runtime and might be used
391 by other runtimes in the future too. The current implementation only
392 supports X86-64, but the intention is to support more architectures in the
393 future.
394"``preserve_allcc``" - The `PreserveAll` calling convention
395 This calling convention attempts to make the code in the caller even less
396 intrusive than the `PreserveMost` calling convention. This calling
397 convention also behaves identical to the `C` calling convention on how
398 arguments and return values are passed, but it uses a different set of
399 caller/callee-saved registers. This removes the burden of saving and
Juergen Ributzka980f2dc2014-01-30 02:39:00 +0000400 recovering a large register set before and after the call in the caller. If
401 the arguments are passed in callee-saved registers, then they will be
402 preserved by the callee across the call. This doesn't apply for values
403 returned in callee-saved registers.
Juergen Ributzkae6250132014-01-17 19:47:03 +0000404
405 - On X86-64 the callee preserves all general purpose registers, except for
406 R11. R11 can be used as a scratch register. Furthermore it also preserves
407 all floating-point registers (XMMs/YMMs).
408
409 The idea behind this convention is to support calls to runtime functions
410 that don't need to call out to any other functions.
411
412 This calling convention, like the `PreserveMost` calling convention, will be
413 used by a future version of the ObjectiveC runtime and should be considered
414 experimental at this time.
Manman Ren19c7bbe2015-12-04 17:40:13 +0000415"``cxx_fast_tlscc``" - The `CXX_FAST_TLS` calling convention for access functions
Manman Ren17567d22015-12-07 21:40:09 +0000416 Clang generates an access function to access C++-style TLS. The access
417 function generally has an entry block, an exit block and an initialization
418 block that is run at the first time. The entry and exit blocks can access
419 a few TLS IR variables, each access will be lowered to a platform-specific
420 sequence.
421
Manman Ren19c7bbe2015-12-04 17:40:13 +0000422 This calling convention aims to minimize overhead in the caller by
Manman Ren17567d22015-12-07 21:40:09 +0000423 preserving as many registers as possible (all the registers that are
424 perserved on the fast path, composed of the entry and exit blocks).
425
426 This calling convention behaves identical to the `C` calling convention on
427 how arguments and return values are passed, but it uses a different set of
428 caller/callee-saved registers.
429
430 Given that each platform has its own lowering sequence, hence its own set
431 of preserved registers, we can't use the existing `PreserveMost`.
Manman Ren19c7bbe2015-12-04 17:40:13 +0000432
433 - On X86-64 the callee preserves all general purpose registers, except for
434 RDI and RAX.
Manman Renf8bdd882016-04-05 22:41:47 +0000435"``swiftcc``" - This calling convention is used for Swift language.
436 - On X86-64 RCX and R8 are available for additional integer returns, and
437 XMM2 and XMM3 are available for additional FP/vector returns.
Manman Ren802cd6f2016-04-05 22:44:44 +0000438 - On iOS platforms, we use AAPCS-VFP calling convention.
Sean Silvab084af42012-12-07 10:36:55 +0000439"``cc <n>``" - Numbered convention
440 Any calling convention may be specified by number, allowing
441 target-specific calling conventions to be used. Target specific
442 calling conventions start at 64.
443
444More calling conventions can be added/defined on an as-needed basis, to
445support Pascal conventions or any other well-known target-independent
446convention.
447
Eli Benderskyfdc529a2013-06-07 19:40:08 +0000448.. _visibilitystyles:
449
Sean Silvab084af42012-12-07 10:36:55 +0000450Visibility Styles
451-----------------
452
453All Global Variables and Functions have one of the following visibility
454styles:
455
456"``default``" - Default style
457 On targets that use the ELF object file format, default visibility
458 means that the declaration is visible to other modules and, in
459 shared libraries, means that the declared entity may be overridden.
460 On Darwin, default visibility means that the declaration is visible
461 to other modules. Default visibility corresponds to "external
462 linkage" in the language.
463"``hidden``" - Hidden style
464 Two declarations of an object with hidden visibility refer to the
465 same object if they are in the same shared object. Usually, hidden
466 visibility indicates that the symbol will not be placed into the
467 dynamic symbol table, so no other module (executable or shared
468 library) can reference it directly.
469"``protected``" - Protected style
470 On ELF, protected visibility indicates that the symbol will be
471 placed in the dynamic symbol table, but that references within the
472 defining module will bind to the local symbol. That is, the symbol
473 cannot be overridden by another module.
474
Duncan P. N. Exon Smithb80de102014-05-07 22:57:20 +0000475A symbol with ``internal`` or ``private`` linkage must have ``default``
476visibility.
477
Rafael Espindola3bc64d52014-05-26 21:30:40 +0000478.. _dllstorageclass:
Eli Benderskyfdc529a2013-06-07 19:40:08 +0000479
Nico Rieck7157bb72014-01-14 15:22:47 +0000480DLL Storage Classes
481-------------------
482
483All Global Variables, Functions and Aliases can have one of the following
484DLL storage class:
485
486``dllimport``
487 "``dllimport``" causes the compiler to reference a function or variable via
488 a global pointer to a pointer that is set up by the DLL exporting the
489 symbol. On Microsoft Windows targets, the pointer name is formed by
490 combining ``__imp_`` and the function or variable name.
491``dllexport``
492 "``dllexport``" causes the compiler to provide a global pointer to a pointer
493 in a DLL, so that it can be referenced with the ``dllimport`` attribute. On
494 Microsoft Windows targets, the pointer name is formed by combining
495 ``__imp_`` and the function or variable name. Since this storage class
496 exists for defining a dll interface, the compiler, assembler and linker know
497 it is externally referenced and must refrain from deleting the symbol.
498
Rafael Espindola59f7eba2014-05-28 18:15:43 +0000499.. _tls_model:
500
501Thread Local Storage Models
502---------------------------
503
504A variable may be defined as ``thread_local``, which means that it will
505not be shared by threads (each thread will have a separated copy of the
506variable). Not all targets support thread-local variables. Optionally, a
507TLS model may be specified:
508
509``localdynamic``
510 For variables that are only used within the current shared library.
511``initialexec``
512 For variables in modules that will not be loaded dynamically.
513``localexec``
514 For variables defined in the executable and only used within it.
515
516If no explicit model is given, the "general dynamic" model is used.
517
518The models correspond to the ELF TLS models; see `ELF Handling For
519Thread-Local Storage <http://people.redhat.com/drepper/tls.pdf>`_ for
520more information on under which circumstances the different models may
521be used. The target may choose a different TLS model if the specified
522model is not supported, or if a better choice of model can be made.
523
Sean Silva706fba52015-08-06 22:56:24 +0000524A model can also be specified in an alias, but then it only governs how
Rafael Espindola59f7eba2014-05-28 18:15:43 +0000525the alias is accessed. It will not have any effect in the aliasee.
526
Chih-Hung Hsieh1e859582015-07-28 16:24:05 +0000527For platforms without linker support of ELF TLS model, the -femulated-tls
528flag can be used to generate GCC compatible emulated TLS code.
529
Rafael Espindola3bc64d52014-05-26 21:30:40 +0000530.. _namedtypes:
531
Reid Kleckner7c84d1d2014-03-05 02:21:50 +0000532Structure Types
533---------------
Sean Silvab084af42012-12-07 10:36:55 +0000534
Reid Kleckner7c84d1d2014-03-05 02:21:50 +0000535LLVM IR allows you to specify both "identified" and "literal" :ref:`structure
Sean Silvaa1190322015-08-06 22:56:48 +0000536types <t_struct>`. Literal types are uniqued structurally, but identified types
537are never uniqued. An :ref:`opaque structural type <t_opaque>` can also be used
Richard Smith32dbdf62014-07-31 04:25:36 +0000538to forward declare a type that is not yet available.
Reid Kleckner7c84d1d2014-03-05 02:21:50 +0000539
Sean Silva706fba52015-08-06 22:56:24 +0000540An example of an identified structure specification is:
Sean Silvab084af42012-12-07 10:36:55 +0000541
542.. code-block:: llvm
543
544 %mytype = type { %mytype*, i32 }
545
Sean Silvaa1190322015-08-06 22:56:48 +0000546Prior to the LLVM 3.0 release, identified types were structurally uniqued. Only
Reid Kleckner7c84d1d2014-03-05 02:21:50 +0000547literal types are uniqued in recent versions of LLVM.
Sean Silvab084af42012-12-07 10:36:55 +0000548
Sanjoy Dasc6af5ea2016-07-28 23:43:38 +0000549.. _nointptrtype:
550
551Non-Integral Pointer Type
552-------------------------
553
554Note: non-integral pointer types are a work in progress, and they should be
555considered experimental at this time.
556
557LLVM IR optionally allows the frontend to denote pointers in certain address
Sanjoy Das63752e62016-08-10 21:48:24 +0000558spaces as "non-integral" via the :ref:`datalayout string<langref_datalayout>`.
559Non-integral pointer types represent pointers that have an *unspecified* bitwise
560representation; that is, the integral representation may be target dependent or
561unstable (not backed by a fixed integer).
Sanjoy Dasc6af5ea2016-07-28 23:43:38 +0000562
563``inttoptr`` instructions converting integers to non-integral pointer types are
564ill-typed, and so are ``ptrtoint`` instructions converting values of
565non-integral pointer types to integers. Vector versions of said instructions
566are ill-typed as well.
567
Sean Silvab084af42012-12-07 10:36:55 +0000568.. _globalvars:
569
570Global Variables
571----------------
572
573Global variables define regions of memory allocated at compilation time
Rafael Espindola5d1b7452013-10-29 13:44:11 +0000574instead of run-time.
575
Eric Christopher1e61ffd2015-02-19 18:46:25 +0000576Global variable definitions must be initialized.
Rafael Espindola5d1b7452013-10-29 13:44:11 +0000577
578Global variables in other translation units can also be declared, in which
579case they don't have an initializer.
Sean Silvab084af42012-12-07 10:36:55 +0000580
Bob Wilson85b24f22014-06-12 20:40:33 +0000581Either global variable definitions or declarations may have an explicit section
Erich Keane0343ef82017-08-22 15:30:43 +0000582to be placed in and may have an optional explicit alignment specified. If there
583is a mismatch between the explicit or inferred section information for the
584variable declaration and its definition the resulting behavior is undefined.
Bob Wilson85b24f22014-06-12 20:40:33 +0000585
Michael Gottesman006039c2013-01-31 05:48:48 +0000586A variable may be defined as a global ``constant``, which indicates that
Sean Silvab084af42012-12-07 10:36:55 +0000587the contents of the variable will **never** be modified (enabling better
588optimization, allowing the global data to be placed in the read-only
589section of an executable, etc). Note that variables that need runtime
Michael Gottesman1cffcf742013-01-31 05:44:04 +0000590initialization cannot be marked ``constant`` as there is a store to the
Sean Silvab084af42012-12-07 10:36:55 +0000591variable.
592
593LLVM explicitly allows *declarations* of global variables to be marked
594constant, even if the final definition of the global is not. This
595capability can be used to enable slightly better optimization of the
596program, but requires the language definition to guarantee that
597optimizations based on the 'constantness' are valid for the translation
598units that do not include the definition.
599
600As SSA values, global variables define pointer values that are in scope
601(i.e. they dominate) all basic blocks in the program. Global variables
602always define a pointer to their "content" type because they describe a
603region of memory, and all memory objects in LLVM are accessed through
604pointers.
605
606Global variables can be marked with ``unnamed_addr`` which indicates
607that the address is not significant, only the content. Constants marked
608like this can be merged with other constants if they have the same
609initializer. Note that a constant with significant address *can* be
610merged with a ``unnamed_addr`` constant, the result being a constant
611whose address is significant.
612
Peter Collingbourne96efdd62016-06-14 21:01:22 +0000613If the ``local_unnamed_addr`` attribute is given, the address is known to
614not be significant within the module.
615
Sean Silvab084af42012-12-07 10:36:55 +0000616A global variable may be declared to reside in a target-specific
617numbered address space. For targets that support them, address spaces
618may affect how optimizations are performed and/or what target
619instructions are used to access the variable. The default address space
620is zero. The address space qualifier must precede any other attributes.
621
622LLVM allows an explicit section to be specified for globals. If the
623target supports it, it will emit globals to the section specified.
David Majnemerdad0a642014-06-27 18:19:56 +0000624Additionally, the global can placed in a comdat if the target has the necessary
625support.
Sean Silvab084af42012-12-07 10:36:55 +0000626
Erich Keane0343ef82017-08-22 15:30:43 +0000627External declarations may have an explicit section specified. Section
628information is retained in LLVM IR for targets that make use of this
629information. Attaching section information to an external declaration is an
630assertion that its definition is located in the specified section. If the
631definition is located in a different section, the behavior is undefined.
632
Michael Gottesmane743a302013-02-04 03:22:00 +0000633By default, global initializers are optimized by assuming that global
Michael Gottesmanef2bc772013-02-03 09:57:15 +0000634variables defined within the module are not modified from their
Sean Silvaa1190322015-08-06 22:56:48 +0000635initial values before the start of the global initializer. This is
Michael Gottesmanef2bc772013-02-03 09:57:15 +0000636true even for variables potentially accessible from outside the
637module, including those with external linkage or appearing in
Yunzhong Gaof5b769e2013-12-05 18:37:54 +0000638``@llvm.used`` or dllexported variables. This assumption may be suppressed
639by marking the variable with ``externally_initialized``.
Michael Gottesmanef2bc772013-02-03 09:57:15 +0000640
Sean Silvab084af42012-12-07 10:36:55 +0000641An explicit alignment may be specified for a global, which must be a
642power of 2. If not present, or if the alignment is set to zero, the
643alignment of the global is set by the target to whatever it feels
644convenient. If an explicit alignment is specified, the global is forced
645to have exactly that alignment. Targets and optimizers are not allowed
646to over-align the global if the global has an assigned section. In this
647case, the extra alignment could be observable: for example, code could
648assume that the globals are densely packed in their section and try to
649iterate over them as an array, alignment padding would break this
Reid Kleckner15fe7a52014-07-15 01:16:09 +0000650iteration. The maximum alignment is ``1 << 29``.
Sean Silvab084af42012-12-07 10:36:55 +0000651
Javed Absarf3d79042017-05-11 12:28:08 +0000652Globals can also have a :ref:`DLL storage class <dllstorageclass>`,
653an optional :ref:`global attributes <glattrs>` and
654an optional list of attached :ref:`metadata <metadata>`.
Nico Rieck7157bb72014-01-14 15:22:47 +0000655
Peter Collingbourne69ba0162015-02-04 00:42:45 +0000656Variables and aliases can have a
Rafael Espindola59f7eba2014-05-28 18:15:43 +0000657:ref:`Thread Local Storage Model <tls_model>`.
658
Nico Rieck7157bb72014-01-14 15:22:47 +0000659Syntax::
660
Rafael Espindola32483a72016-05-10 18:22:45 +0000661 @<GlobalVarName> = [Linkage] [Visibility] [DLLStorageClass] [ThreadLocal]
Peter Collingbourne96efdd62016-06-14 21:01:22 +0000662 [(unnamed_addr|local_unnamed_addr)] [AddrSpace]
663 [ExternallyInitialized]
Bob Wilson85b24f22014-06-12 20:40:33 +0000664 <global | constant> <Type> [<InitializerConstant>]
Rafael Espindola83a362c2015-01-06 22:55:16 +0000665 [, section "name"] [, comdat [($name)]]
Peter Collingbournecceae7f2016-05-31 23:01:54 +0000666 [, align <Alignment>] (, !name !N)*
Nico Rieck7157bb72014-01-14 15:22:47 +0000667
Sean Silvab084af42012-12-07 10:36:55 +0000668For example, the following defines a global in a numbered address space
669with an initializer, section, and alignment:
670
671.. code-block:: llvm
672
673 @G = addrspace(5) constant float 1.0, section "foo", align 4
674
Rafael Espindola5d1b7452013-10-29 13:44:11 +0000675The following example just declares a global variable
676
677.. code-block:: llvm
678
679 @G = external global i32
680
Sean Silvab084af42012-12-07 10:36:55 +0000681The following example defines a thread-local global with the
682``initialexec`` TLS model:
683
684.. code-block:: llvm
685
686 @G = thread_local(initialexec) global i32 0, align 4
687
688.. _functionstructure:
689
690Functions
691---------
692
693LLVM function definitions consist of the "``define``" keyword, an
694optional :ref:`linkage type <linkage>`, an optional :ref:`visibility
Nico Rieck7157bb72014-01-14 15:22:47 +0000695style <visibility>`, an optional :ref:`DLL storage class <dllstorageclass>`,
696an optional :ref:`calling convention <callingconv>`,
Sean Silvab084af42012-12-07 10:36:55 +0000697an optional ``unnamed_addr`` attribute, a return type, an optional
698:ref:`parameter attribute <paramattrs>` for the return type, a function
699name, a (possibly empty) argument list (each with optional :ref:`parameter
700attributes <paramattrs>`), optional :ref:`function attributes <fnattrs>`,
David Majnemerdad0a642014-06-27 18:19:56 +0000701an optional section, an optional alignment,
702an optional :ref:`comdat <langref_comdats>`,
Peter Collingbourne51d2de72014-12-03 02:08:38 +0000703an optional :ref:`garbage collector name <gc>`, an optional :ref:`prefix <prefixdata>`,
David Majnemer7fddecc2015-06-17 20:52:32 +0000704an optional :ref:`prologue <prologuedata>`,
705an optional :ref:`personality <personalityfn>`,
Peter Collingbourne50108682015-11-06 02:41:02 +0000706an optional list of attached :ref:`metadata <metadata>`,
David Majnemer7fddecc2015-06-17 20:52:32 +0000707an opening curly brace, a list of basic blocks, and a closing curly brace.
Sean Silvab084af42012-12-07 10:36:55 +0000708
709LLVM function declarations consist of the "``declare``" keyword, an
Peter Collingbourne96efdd62016-06-14 21:01:22 +0000710optional :ref:`linkage type <linkage>`, an optional :ref:`visibility style
711<visibility>`, an optional :ref:`DLL storage class <dllstorageclass>`, an
712optional :ref:`calling convention <callingconv>`, an optional ``unnamed_addr``
713or ``local_unnamed_addr`` attribute, a return type, an optional :ref:`parameter
714attribute <paramattrs>` for the return type, a function name, a possibly
715empty list of arguments, an optional alignment, an optional :ref:`garbage
716collector name <gc>`, an optional :ref:`prefix <prefixdata>`, and an optional
717:ref:`prologue <prologuedata>`.
Sean Silvab084af42012-12-07 10:36:55 +0000718
Bill Wendling6822ecb2013-10-27 05:09:12 +0000719A function definition contains a list of basic blocks, forming the CFG (Control
720Flow Graph) for the function. Each basic block may optionally start with a label
721(giving the basic block a symbol table entry), contains a list of instructions,
722and ends with a :ref:`terminator <terminators>` instruction (such as a branch or
723function return). If an explicit label is not provided, a block is assigned an
724implicit numbered label, using the next value from the same counter as used for
725unnamed temporaries (:ref:`see above<identifiers>`). For example, if a function
726entry block does not have an explicit label, it will be assigned label "%0",
727then the first unnamed temporary in that block will be "%1", etc.
Sean Silvab084af42012-12-07 10:36:55 +0000728
729The first basic block in a function is special in two ways: it is
730immediately executed on entrance to the function, and it is not allowed
731to have predecessor basic blocks (i.e. there can not be any branches to
732the entry block of a function). Because the block can have no
733predecessors, it also cannot have any :ref:`PHI nodes <i_phi>`.
734
735LLVM allows an explicit section to be specified for functions. If the
736target supports it, it will emit functions to the section specified.
Eric Christopher1e61ffd2015-02-19 18:46:25 +0000737Additionally, the function can be placed in a COMDAT.
Sean Silvab084af42012-12-07 10:36:55 +0000738
739An explicit alignment may be specified for a function. If not present,
740or if the alignment is set to zero, the alignment of the function is set
741by the target to whatever it feels convenient. If an explicit alignment
742is specified, the function is forced to have at least that much
743alignment. All alignments must be a power of 2.
744
Eric Christopher1e61ffd2015-02-19 18:46:25 +0000745If the ``unnamed_addr`` attribute is given, the address is known to not
Sean Silvab084af42012-12-07 10:36:55 +0000746be significant and two identical functions can be merged.
747
Peter Collingbourne96efdd62016-06-14 21:01:22 +0000748If the ``local_unnamed_addr`` attribute is given, the address is known to
749not be significant within the module.
750
Sean Silvab084af42012-12-07 10:36:55 +0000751Syntax::
752
Nico Rieck7157bb72014-01-14 15:22:47 +0000753 define [linkage] [visibility] [DLLStorageClass]
Sean Silvab084af42012-12-07 10:36:55 +0000754 [cconv] [ret attrs]
755 <ResultType> @<FunctionName> ([argument list])
Peter Collingbourne96efdd62016-06-14 21:01:22 +0000756 [(unnamed_addr|local_unnamed_addr)] [fn Attrs] [section "name"]
757 [comdat [($name)]] [align N] [gc] [prefix Constant]
758 [prologue Constant] [personality Constant] (!name !N)* { ... }
Sean Silvab084af42012-12-07 10:36:55 +0000759
Sean Silva706fba52015-08-06 22:56:24 +0000760The argument list is a comma separated sequence of arguments where each
761argument is of the following form:
Dan Liew2661dfc2014-08-20 15:06:30 +0000762
763Syntax::
764
765 <type> [parameter Attrs] [name]
766
767
Eli Benderskyfdc529a2013-06-07 19:40:08 +0000768.. _langref_aliases:
769
Sean Silvab084af42012-12-07 10:36:55 +0000770Aliases
771-------
772
Rafael Espindola64c1e182014-06-03 02:41:57 +0000773Aliases, unlike function or variables, don't create any new data. They
774are just a new symbol and metadata for an existing position.
775
776Aliases have a name and an aliasee that is either a global value or a
777constant expression.
778
Nico Rieck7157bb72014-01-14 15:22:47 +0000779Aliases may have an optional :ref:`linkage type <linkage>`, an optional
Rafael Espindola64c1e182014-06-03 02:41:57 +0000780:ref:`visibility style <visibility>`, an optional :ref:`DLL storage class
781<dllstorageclass>` and an optional :ref:`tls model <tls_model>`.
Sean Silvab084af42012-12-07 10:36:55 +0000782
783Syntax::
784
Peter Collingbourne96efdd62016-06-14 21:01:22 +0000785 @<Name> = [Linkage] [Visibility] [DLLStorageClass] [ThreadLocal] [(unnamed_addr|local_unnamed_addr)] alias <AliaseeTy>, <AliaseeTy>* @<Aliasee>
Sean Silvab084af42012-12-07 10:36:55 +0000786
Rafael Espindola2fb5bc32014-03-13 23:18:37 +0000787The linkage must be one of ``private``, ``internal``, ``linkonce``, ``weak``,
Rafael Espindola716e7402013-11-01 17:09:14 +0000788``linkonce_odr``, ``weak_odr``, ``external``. Note that some system linkers
Rafael Espindola64c1e182014-06-03 02:41:57 +0000789might not correctly handle dropping a weak symbol that is aliased.
Rafael Espindola78527052013-10-06 15:10:43 +0000790
Eric Christopher1e61ffd2015-02-19 18:46:25 +0000791Aliases that are not ``unnamed_addr`` are guaranteed to have the same address as
Rafael Espindola42a4c9f2014-06-06 01:20:28 +0000792the aliasee expression. ``unnamed_addr`` ones are only guaranteed to point
793to the same content.
Rafael Espindolaf3336bc2014-03-12 20:15:49 +0000794
Peter Collingbourne96efdd62016-06-14 21:01:22 +0000795If the ``local_unnamed_addr`` attribute is given, the address is known to
796not be significant within the module.
797
Rafael Espindola64c1e182014-06-03 02:41:57 +0000798Since aliases are only a second name, some restrictions apply, of which
799some can only be checked when producing an object file:
Rafael Espindolaf3336bc2014-03-12 20:15:49 +0000800
Rafael Espindola64c1e182014-06-03 02:41:57 +0000801* The expression defining the aliasee must be computable at assembly
802 time. Since it is just a name, no relocations can be used.
803
804* No alias in the expression can be weak as the possibility of the
805 intermediate alias being overridden cannot be represented in an
806 object file.
807
808* No global value in the expression can be a declaration, since that
809 would require a relocation, which is not possible.
Rafael Espindola24a669d2014-03-27 15:26:56 +0000810
Dmitry Polukhina1feff72016-04-07 12:32:19 +0000811.. _langref_ifunc:
812
813IFuncs
814-------
815
816IFuncs, like as aliases, don't create any new data or func. They are just a new
817symbol that dynamic linker resolves at runtime by calling a resolver function.
818
819IFuncs have a name and a resolver that is a function called by dynamic linker
820that returns address of another function associated with the name.
821
822IFunc may have an optional :ref:`linkage type <linkage>` and an optional
823:ref:`visibility style <visibility>`.
824
825Syntax::
826
827 @<Name> = [Linkage] [Visibility] ifunc <IFuncTy>, <ResolverTy>* @<Resolver>
828
829
David Majnemerdad0a642014-06-27 18:19:56 +0000830.. _langref_comdats:
831
832Comdats
833-------
834
835Comdat IR provides access to COFF and ELF object file COMDAT functionality.
836
Sean Silvaa1190322015-08-06 22:56:48 +0000837Comdats have a name which represents the COMDAT key. All global objects that
David Majnemerdad0a642014-06-27 18:19:56 +0000838specify this key will only end up in the final object file if the linker chooses
Sean Silvaa1190322015-08-06 22:56:48 +0000839that key over some other key. Aliases are placed in the same COMDAT that their
David Majnemerdad0a642014-06-27 18:19:56 +0000840aliasee computes to, if any.
841
842Comdats have a selection kind to provide input on how the linker should
843choose between keys in two different object files.
844
845Syntax::
846
847 $<Name> = comdat SelectionKind
848
849The selection kind must be one of the following:
850
851``any``
852 The linker may choose any COMDAT key, the choice is arbitrary.
853``exactmatch``
854 The linker may choose any COMDAT key but the sections must contain the
855 same data.
856``largest``
857 The linker will choose the section containing the largest COMDAT key.
858``noduplicates``
859 The linker requires that only section with this COMDAT key exist.
860``samesize``
861 The linker may choose any COMDAT key but the sections must contain the
862 same amount of data.
863
864Note that the Mach-O platform doesn't support COMDATs and ELF only supports
865``any`` as a selection kind.
866
867Here is an example of a COMDAT group where a function will only be selected if
868the COMDAT key's section is the largest:
869
Renato Golin124f2592016-07-20 12:16:38 +0000870.. code-block:: text
David Majnemerdad0a642014-06-27 18:19:56 +0000871
872 $foo = comdat largest
Rafael Espindola83a362c2015-01-06 22:55:16 +0000873 @foo = global i32 2, comdat($foo)
David Majnemerdad0a642014-06-27 18:19:56 +0000874
Rafael Espindola83a362c2015-01-06 22:55:16 +0000875 define void @bar() comdat($foo) {
David Majnemerdad0a642014-06-27 18:19:56 +0000876 ret void
877 }
878
Rafael Espindola83a362c2015-01-06 22:55:16 +0000879As a syntactic sugar the ``$name`` can be omitted if the name is the same as
880the global name:
881
Renato Golin124f2592016-07-20 12:16:38 +0000882.. code-block:: text
Rafael Espindola83a362c2015-01-06 22:55:16 +0000883
884 $foo = comdat any
885 @foo = global i32 2, comdat
886
887
David Majnemerdad0a642014-06-27 18:19:56 +0000888In a COFF object file, this will create a COMDAT section with selection kind
889``IMAGE_COMDAT_SELECT_LARGEST`` containing the contents of the ``@foo`` symbol
890and another COMDAT section with selection kind
891``IMAGE_COMDAT_SELECT_ASSOCIATIVE`` which is associated with the first COMDAT
Hans Wennborg0def0662014-09-10 17:05:08 +0000892section and contains the contents of the ``@bar`` symbol.
David Majnemerdad0a642014-06-27 18:19:56 +0000893
894There are some restrictions on the properties of the global object.
895It, or an alias to it, must have the same name as the COMDAT group when
896targeting COFF.
897The contents and size of this object may be used during link-time to determine
898which COMDAT groups get selected depending on the selection kind.
899Because the name of the object must match the name of the COMDAT group, the
900linkage of the global object must not be local; local symbols can get renamed
901if a collision occurs in the symbol table.
902
903The combined use of COMDATS and section attributes may yield surprising results.
904For example:
905
Renato Golin124f2592016-07-20 12:16:38 +0000906.. code-block:: text
David Majnemerdad0a642014-06-27 18:19:56 +0000907
908 $foo = comdat any
909 $bar = comdat any
Rafael Espindola83a362c2015-01-06 22:55:16 +0000910 @g1 = global i32 42, section "sec", comdat($foo)
911 @g2 = global i32 42, section "sec", comdat($bar)
David Majnemerdad0a642014-06-27 18:19:56 +0000912
913From the object file perspective, this requires the creation of two sections
Sean Silvaa1190322015-08-06 22:56:48 +0000914with the same name. This is necessary because both globals belong to different
David Majnemerdad0a642014-06-27 18:19:56 +0000915COMDAT groups and COMDATs, at the object file level, are represented by
916sections.
917
Peter Collingbourne1feef2e2015-06-30 19:10:31 +0000918Note that certain IR constructs like global variables and functions may
919create COMDATs in the object file in addition to any which are specified using
Sean Silvaa1190322015-08-06 22:56:48 +0000920COMDAT IR. This arises when the code generator is configured to emit globals
Peter Collingbourne1feef2e2015-06-30 19:10:31 +0000921in individual sections (e.g. when `-data-sections` or `-function-sections`
922is supplied to `llc`).
David Majnemerdad0a642014-06-27 18:19:56 +0000923
Sean Silvab084af42012-12-07 10:36:55 +0000924.. _namedmetadatastructure:
925
926Named Metadata
927--------------
928
929Named metadata is a collection of metadata. :ref:`Metadata
930nodes <metadata>` (but not metadata strings) are the only valid
931operands for a named metadata.
932
Filipe Cabecinhas62431b12015-06-02 21:25:08 +0000933#. Named metadata are represented as a string of characters with the
934 metadata prefix. The rules for metadata names are the same as for
935 identifiers, but quoted names are not allowed. ``"\xx"`` type escapes
936 are still valid, which allows any character to be part of a name.
937
Sean Silvab084af42012-12-07 10:36:55 +0000938Syntax::
939
940 ; Some unnamed metadata nodes, which are referenced by the named metadata.
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +0000941 !0 = !{!"zero"}
942 !1 = !{!"one"}
943 !2 = !{!"two"}
Sean Silvab084af42012-12-07 10:36:55 +0000944 ; A named metadata.
945 !name = !{!0, !1, !2}
946
947.. _paramattrs:
948
949Parameter Attributes
950--------------------
951
952The return type and each parameter of a function type may have a set of
953*parameter attributes* associated with them. Parameter attributes are
954used to communicate additional information about the result or
955parameters of a function. Parameter attributes are considered to be part
956of the function, not of the function type, so functions with different
957parameter attributes can have the same function type.
958
959Parameter attributes are simple keywords that follow the type specified.
960If multiple parameter attributes are needed, they are space separated.
961For example:
962
963.. code-block:: llvm
964
965 declare i32 @printf(i8* noalias nocapture, ...)
966 declare i32 @atoi(i8 zeroext)
967 declare signext i8 @returns_signed_char()
968
969Note that any attributes for the function result (``nounwind``,
970``readonly``) come immediately after the argument list.
971
972Currently, only the following parameter attributes are defined:
973
974``zeroext``
975 This indicates to the code generator that the parameter or return
976 value should be zero-extended to the extent required by the target's
Hans Wennborg850ec6c2016-02-08 19:34:30 +0000977 ABI by the caller (for a parameter) or the callee (for a return value).
Sean Silvab084af42012-12-07 10:36:55 +0000978``signext``
979 This indicates to the code generator that the parameter or return
980 value should be sign-extended to the extent required by the target's
981 ABI (which is usually 32-bits) by the caller (for a parameter) or
982 the callee (for a return value).
983``inreg``
984 This indicates that this parameter or return value should be treated
Sean Silva706fba52015-08-06 22:56:24 +0000985 in a special target-dependent fashion while emitting code for
Sean Silvab084af42012-12-07 10:36:55 +0000986 a function call or return (usually, by putting it in a register as
987 opposed to memory, though some targets use it to distinguish between
988 two different kinds of registers). Use of this attribute is
989 target-specific.
990``byval``
991 This indicates that the pointer parameter should really be passed by
992 value to the function. The attribute implies that a hidden copy of
993 the pointee is made between the caller and the callee, so the callee
994 is unable to modify the value in the caller. This attribute is only
995 valid on LLVM pointer arguments. It is generally used to pass
996 structs and arrays by value, but is also valid on pointers to
997 scalars. The copy is considered to belong to the caller not the
998 callee (for example, ``readonly`` functions should not write to
999 ``byval`` parameters). This is not a valid attribute for return
1000 values.
1001
1002 The byval attribute also supports specifying an alignment with the
1003 align attribute. It indicates the alignment of the stack slot to
1004 form and the known alignment of the pointer specified to the call
1005 site. If the alignment is not specified, then the code generator
1006 makes a target-specific assumption.
1007
Reid Klecknera534a382013-12-19 02:14:12 +00001008.. _attr_inalloca:
1009
1010``inalloca``
1011
Reid Kleckner60d3a832014-01-16 22:59:24 +00001012 The ``inalloca`` argument attribute allows the caller to take the
Sean Silvaa1190322015-08-06 22:56:48 +00001013 address of outgoing stack arguments. An ``inalloca`` argument must
Reid Kleckner436c42e2014-01-17 23:58:17 +00001014 be a pointer to stack memory produced by an ``alloca`` instruction.
1015 The alloca, or argument allocation, must also be tagged with the
Sean Silvaa1190322015-08-06 22:56:48 +00001016 inalloca keyword. Only the last argument may have the ``inalloca``
Reid Kleckner436c42e2014-01-17 23:58:17 +00001017 attribute, and that argument is guaranteed to be passed in memory.
Reid Klecknera534a382013-12-19 02:14:12 +00001018
Reid Kleckner436c42e2014-01-17 23:58:17 +00001019 An argument allocation may be used by a call at most once because
Sean Silvaa1190322015-08-06 22:56:48 +00001020 the call may deallocate it. The ``inalloca`` attribute cannot be
Reid Kleckner436c42e2014-01-17 23:58:17 +00001021 used in conjunction with other attributes that affect argument
Sean Silvaa1190322015-08-06 22:56:48 +00001022 storage, like ``inreg``, ``nest``, ``sret``, or ``byval``. The
Reid Klecknerf5b76512014-01-31 23:50:57 +00001023 ``inalloca`` attribute also disables LLVM's implicit lowering of
1024 large aggregate return values, which means that frontend authors
1025 must lower them with ``sret`` pointers.
Reid Klecknera534a382013-12-19 02:14:12 +00001026
Reid Kleckner60d3a832014-01-16 22:59:24 +00001027 When the call site is reached, the argument allocation must have
1028 been the most recent stack allocation that is still live, or the
Sean Silvaa1190322015-08-06 22:56:48 +00001029 results are undefined. It is possible to allocate additional stack
Reid Kleckner60d3a832014-01-16 22:59:24 +00001030 space after an argument allocation and before its call site, but it
1031 must be cleared off with :ref:`llvm.stackrestore
1032 <int_stackrestore>`.
Reid Klecknera534a382013-12-19 02:14:12 +00001033
1034 See :doc:`InAlloca` for more information on how to use this
1035 attribute.
1036
Sean Silvab084af42012-12-07 10:36:55 +00001037``sret``
1038 This indicates that the pointer parameter specifies the address of a
1039 structure that is the return value of the function in the source
1040 program. This pointer must be guaranteed by the caller to be valid:
Reid Kleckner1361c0c2016-09-08 15:45:27 +00001041 loads and stores to the structure may be assumed by the callee not
1042 to trap and to be properly aligned. This is not a valid attribute
1043 for return values.
Sean Silva1703e702014-04-08 21:06:22 +00001044
Hal Finkelccc70902014-07-22 16:58:55 +00001045``align <n>``
1046 This indicates that the pointer value may be assumed by the optimizer to
1047 have the specified alignment.
1048
1049 Note that this attribute has additional semantics when combined with the
1050 ``byval`` attribute.
1051
Sean Silva1703e702014-04-08 21:06:22 +00001052.. _noalias:
1053
Sean Silvab084af42012-12-07 10:36:55 +00001054``noalias``
Hal Finkel12d36302014-11-21 02:22:46 +00001055 This indicates that objects accessed via pointer values
1056 :ref:`based <pointeraliasing>` on the argument or return value are not also
1057 accessed, during the execution of the function, via pointer values not
1058 *based* on the argument or return value. The attribute on a return value
1059 also has additional semantics described below. The caller shares the
1060 responsibility with the callee for ensuring that these requirements are met.
1061 For further details, please see the discussion of the NoAlias response in
1062 :ref:`alias analysis <Must, May, or No>`.
Sean Silvab084af42012-12-07 10:36:55 +00001063
1064 Note that this definition of ``noalias`` is intentionally similar
Hal Finkel12d36302014-11-21 02:22:46 +00001065 to the definition of ``restrict`` in C99 for function arguments.
Sean Silvab084af42012-12-07 10:36:55 +00001066
1067 For function return values, C99's ``restrict`` is not meaningful,
Hal Finkel12d36302014-11-21 02:22:46 +00001068 while LLVM's ``noalias`` is. Furthermore, the semantics of the ``noalias``
1069 attribute on return values are stronger than the semantics of the attribute
1070 when used on function arguments. On function return values, the ``noalias``
1071 attribute indicates that the function acts like a system memory allocation
1072 function, returning a pointer to allocated storage disjoint from the
1073 storage for any other object accessible to the caller.
1074
Sean Silvab084af42012-12-07 10:36:55 +00001075``nocapture``
1076 This indicates that the callee does not make any copies of the
1077 pointer that outlive the callee itself. This is not a valid
David Majnemer7f324202016-05-26 17:36:22 +00001078 attribute for return values. Addresses used in volatile operations
1079 are considered to be captured.
Sean Silvab084af42012-12-07 10:36:55 +00001080
1081.. _nest:
1082
1083``nest``
1084 This indicates that the pointer parameter can be excised using the
1085 :ref:`trampoline intrinsics <int_trampoline>`. This is not a valid
Stephen Linb8bd2322013-04-20 05:14:40 +00001086 attribute for return values and can only be applied to one parameter.
1087
1088``returned``
Stephen Linfec5b0b2013-06-20 21:55:10 +00001089 This indicates that the function always returns the argument as its return
Hal Finkel3b66caa2016-07-10 21:52:39 +00001090 value. This is a hint to the optimizer and code generator used when
1091 generating the caller, allowing value propagation, tail call optimization,
1092 and omission of register saves and restores in some cases; it is not
1093 checked or enforced when generating the callee. The parameter and the
1094 function return type must be valid operands for the
1095 :ref:`bitcast instruction <i_bitcast>`. This is not a valid attribute for
1096 return values and can only be applied to one parameter.
Sean Silvab084af42012-12-07 10:36:55 +00001097
Nick Lewyckyd52b1522014-05-20 01:23:40 +00001098``nonnull``
1099 This indicates that the parameter or return pointer is not null. This
1100 attribute may only be applied to pointer typed parameters. This is not
1101 checked or enforced by LLVM, the caller must ensure that the pointer
Mehdi Amini4a121fa2015-03-14 22:04:06 +00001102 passed in is non-null, or the callee must ensure that the returned pointer
Nick Lewyckyd52b1522014-05-20 01:23:40 +00001103 is non-null.
1104
Hal Finkelb0407ba2014-07-18 15:51:28 +00001105``dereferenceable(<n>)``
1106 This indicates that the parameter or return pointer is dereferenceable. This
1107 attribute may only be applied to pointer typed parameters. A pointer that
1108 is dereferenceable can be loaded from speculatively without a risk of
1109 trapping. The number of bytes known to be dereferenceable must be provided
1110 in parentheses. It is legal for the number of bytes to be less than the
1111 size of the pointee type. The ``nonnull`` attribute does not imply
1112 dereferenceability (consider a pointer to one element past the end of an
1113 array), however ``dereferenceable(<n>)`` does imply ``nonnull`` in
1114 ``addrspace(0)`` (which is the default address space).
1115
Sanjoy Das31ea6d12015-04-16 20:29:50 +00001116``dereferenceable_or_null(<n>)``
1117 This indicates that the parameter or return value isn't both
1118 non-null and non-dereferenceable (up to ``<n>`` bytes) at the same
Sean Silvaa1190322015-08-06 22:56:48 +00001119 time. All non-null pointers tagged with
Sanjoy Das31ea6d12015-04-16 20:29:50 +00001120 ``dereferenceable_or_null(<n>)`` are ``dereferenceable(<n>)``.
1121 For address space 0 ``dereferenceable_or_null(<n>)`` implies that
1122 a pointer is exactly one of ``dereferenceable(<n>)`` or ``null``,
1123 and in other address spaces ``dereferenceable_or_null(<n>)``
1124 implies that a pointer is at least one of ``dereferenceable(<n>)``
1125 or ``null`` (i.e. it may be both ``null`` and
Sean Silvaa1190322015-08-06 22:56:48 +00001126 ``dereferenceable(<n>)``). This attribute may only be applied to
Sanjoy Das31ea6d12015-04-16 20:29:50 +00001127 pointer typed parameters.
1128
Manman Renf46262e2016-03-29 17:37:21 +00001129``swiftself``
1130 This indicates that the parameter is the self/context parameter. This is not
1131 a valid attribute for return values and can only be applied to one
1132 parameter.
1133
Manman Ren9bfd0d02016-04-01 21:41:15 +00001134``swifterror``
1135 This attribute is motivated to model and optimize Swift error handling. It
1136 can be applied to a parameter with pointer to pointer type or a
1137 pointer-sized alloca. At the call site, the actual argument that corresponds
Arnold Schwaighofer6c57f4f2016-09-10 19:42:53 +00001138 to a ``swifterror`` parameter has to come from a ``swifterror`` alloca or
1139 the ``swifterror`` parameter of the caller. A ``swifterror`` value (either
1140 the parameter or the alloca) can only be loaded and stored from, or used as
1141 a ``swifterror`` argument. This is not a valid attribute for return values
1142 and can only be applied to one parameter.
Manman Ren9bfd0d02016-04-01 21:41:15 +00001143
1144 These constraints allow the calling convention to optimize access to
1145 ``swifterror`` variables by associating them with a specific register at
1146 call boundaries rather than placing them in memory. Since this does change
1147 the calling convention, a function which uses the ``swifterror`` attribute
1148 on a parameter is not ABI-compatible with one which does not.
1149
1150 These constraints also allow LLVM to assume that a ``swifterror`` argument
1151 does not alias any other memory visible within a function and that a
1152 ``swifterror`` alloca passed as an argument does not escape.
1153
Sean Silvab084af42012-12-07 10:36:55 +00001154.. _gc:
1155
Philip Reamesf80bbff2015-02-25 23:45:20 +00001156Garbage Collector Strategy Names
1157--------------------------------
Sean Silvab084af42012-12-07 10:36:55 +00001158
Philip Reamesf80bbff2015-02-25 23:45:20 +00001159Each function may specify a garbage collector strategy name, which is simply a
Sean Silvab084af42012-12-07 10:36:55 +00001160string:
1161
1162.. code-block:: llvm
1163
1164 define void @f() gc "name" { ... }
1165
Mehdi Amini4a121fa2015-03-14 22:04:06 +00001166The supported values of *name* includes those :ref:`built in to LLVM
Sean Silvaa1190322015-08-06 22:56:48 +00001167<builtin-gc-strategies>` and any provided by loaded plugins. Specifying a GC
Mehdi Amini4a121fa2015-03-14 22:04:06 +00001168strategy will cause the compiler to alter its output in order to support the
Sean Silvaa1190322015-08-06 22:56:48 +00001169named garbage collection algorithm. Note that LLVM itself does not contain a
Philip Reamesf80bbff2015-02-25 23:45:20 +00001170garbage collector, this functionality is restricted to generating machine code
Mehdi Amini4a121fa2015-03-14 22:04:06 +00001171which can interoperate with a collector provided externally.
Sean Silvab084af42012-12-07 10:36:55 +00001172
Peter Collingbourne3fa50f92013-09-16 01:08:15 +00001173.. _prefixdata:
1174
1175Prefix Data
1176-----------
1177
Peter Collingbourne51d2de72014-12-03 02:08:38 +00001178Prefix data is data associated with a function which the code
1179generator will emit immediately before the function's entrypoint.
1180The purpose of this feature is to allow frontends to associate
1181language-specific runtime metadata with specific functions and make it
1182available through the function pointer while still allowing the
1183function pointer to be called.
Peter Collingbourne3fa50f92013-09-16 01:08:15 +00001184
Peter Collingbourne51d2de72014-12-03 02:08:38 +00001185To access the data for a given function, a program may bitcast the
1186function pointer to a pointer to the constant's type and dereference
Sean Silvaa1190322015-08-06 22:56:48 +00001187index -1. This implies that the IR symbol points just past the end of
Peter Collingbourne51d2de72014-12-03 02:08:38 +00001188the prefix data. For instance, take the example of a function annotated
1189with a single ``i32``,
1190
1191.. code-block:: llvm
1192
1193 define void @f() prefix i32 123 { ... }
1194
1195The prefix data can be referenced as,
1196
1197.. code-block:: llvm
1198
David Blaikie16a97eb2015-03-04 22:02:58 +00001199 %0 = bitcast void* () @f to i32*
1200 %a = getelementptr inbounds i32, i32* %0, i32 -1
David Blaikiec7aabbb2015-03-04 22:06:14 +00001201 %b = load i32, i32* %a
Peter Collingbourne51d2de72014-12-03 02:08:38 +00001202
1203Prefix data is laid out as if it were an initializer for a global variable
Sean Silvaa1190322015-08-06 22:56:48 +00001204of the prefix data's type. The function will be placed such that the
Peter Collingbourne51d2de72014-12-03 02:08:38 +00001205beginning of the prefix data is aligned. This means that if the size
1206of the prefix data is not a multiple of the alignment size, the
1207function's entrypoint will not be aligned. If alignment of the
1208function's entrypoint is desired, padding must be added to the prefix
1209data.
1210
Sean Silvaa1190322015-08-06 22:56:48 +00001211A function may have prefix data but no body. This has similar semantics
Peter Collingbourne51d2de72014-12-03 02:08:38 +00001212to the ``available_externally`` linkage in that the data may be used by the
1213optimizers but will not be emitted in the object file.
1214
1215.. _prologuedata:
1216
1217Prologue Data
1218-------------
1219
1220The ``prologue`` attribute allows arbitrary code (encoded as bytes) to
1221be inserted prior to the function body. This can be used for enabling
1222function hot-patching and instrumentation.
1223
1224To maintain the semantics of ordinary function calls, the prologue data must
Sean Silvaa1190322015-08-06 22:56:48 +00001225have a particular format. Specifically, it must begin with a sequence of
Peter Collingbourne3fa50f92013-09-16 01:08:15 +00001226bytes which decode to a sequence of machine instructions, valid for the
1227module's target, which transfer control to the point immediately succeeding
Sean Silvaa1190322015-08-06 22:56:48 +00001228the prologue data, without performing any other visible action. This allows
Peter Collingbourne3fa50f92013-09-16 01:08:15 +00001229the inliner and other passes to reason about the semantics of the function
Sean Silvaa1190322015-08-06 22:56:48 +00001230definition without needing to reason about the prologue data. Obviously this
Peter Collingbourne51d2de72014-12-03 02:08:38 +00001231makes the format of the prologue data highly target dependent.
Peter Collingbourne3fa50f92013-09-16 01:08:15 +00001232
Peter Collingbourne51d2de72014-12-03 02:08:38 +00001233A trivial example of valid prologue data for the x86 architecture is ``i8 144``,
Peter Collingbourne3fa50f92013-09-16 01:08:15 +00001234which encodes the ``nop`` instruction:
1235
Renato Golin124f2592016-07-20 12:16:38 +00001236.. code-block:: text
Peter Collingbourne3fa50f92013-09-16 01:08:15 +00001237
Peter Collingbourne51d2de72014-12-03 02:08:38 +00001238 define void @f() prologue i8 144 { ... }
Peter Collingbourne3fa50f92013-09-16 01:08:15 +00001239
Peter Collingbourne51d2de72014-12-03 02:08:38 +00001240Generally prologue data can be formed by encoding a relative branch instruction
1241which skips the metadata, as in this example of valid prologue data for the
Peter Collingbourne3fa50f92013-09-16 01:08:15 +00001242x86_64 architecture, where the first two bytes encode ``jmp .+10``:
1243
Renato Golin124f2592016-07-20 12:16:38 +00001244.. code-block:: text
Peter Collingbourne3fa50f92013-09-16 01:08:15 +00001245
1246 %0 = type <{ i8, i8, i8* }>
1247
Peter Collingbourne51d2de72014-12-03 02:08:38 +00001248 define void @f() prologue %0 <{ i8 235, i8 8, i8* @md}> { ... }
Peter Collingbourne3fa50f92013-09-16 01:08:15 +00001249
Sean Silvaa1190322015-08-06 22:56:48 +00001250A function may have prologue data but no body. This has similar semantics
Peter Collingbourne3fa50f92013-09-16 01:08:15 +00001251to the ``available_externally`` linkage in that the data may be used by the
1252optimizers but will not be emitted in the object file.
1253
David Majnemer7fddecc2015-06-17 20:52:32 +00001254.. _personalityfn:
1255
1256Personality Function
David Majnemerc5ad8a92015-06-17 21:21:16 +00001257--------------------
David Majnemer7fddecc2015-06-17 20:52:32 +00001258
1259The ``personality`` attribute permits functions to specify what function
1260to use for exception handling.
1261
Bill Wendling63b88192013-02-06 06:52:58 +00001262.. _attrgrp:
1263
1264Attribute Groups
1265----------------
1266
1267Attribute groups are groups of attributes that are referenced by objects within
1268the IR. They are important for keeping ``.ll`` files readable, because a lot of
1269functions will use the same set of attributes. In the degenerative case of a
1270``.ll`` file that corresponds to a single ``.c`` file, the single attribute
1271group will capture the important command line flags used to build that file.
1272
1273An attribute group is a module-level object. To use an attribute group, an
1274object references the attribute group's ID (e.g. ``#37``). An object may refer
1275to more than one attribute group. In that situation, the attributes from the
1276different groups are merged.
1277
1278Here is an example of attribute groups for a function that should always be
1279inlined, has a stack alignment of 4, and which shouldn't use SSE instructions:
1280
1281.. code-block:: llvm
1282
1283 ; Target-independent attributes:
Eli Bendersky97ad9242013-04-18 16:11:44 +00001284 attributes #0 = { alwaysinline alignstack=4 }
Bill Wendling63b88192013-02-06 06:52:58 +00001285
1286 ; Target-dependent attributes:
Eli Bendersky97ad9242013-04-18 16:11:44 +00001287 attributes #1 = { "no-sse" }
Bill Wendling63b88192013-02-06 06:52:58 +00001288
1289 ; Function @f has attributes: alwaysinline, alignstack=4, and "no-sse".
1290 define void @f() #0 #1 { ... }
1291
Sean Silvab084af42012-12-07 10:36:55 +00001292.. _fnattrs:
1293
1294Function Attributes
1295-------------------
1296
1297Function attributes are set to communicate additional information about
1298a function. Function attributes are considered to be part of the
1299function, not of the function type, so functions with different function
1300attributes can have the same function type.
1301
1302Function attributes are simple keywords that follow the type specified.
1303If multiple attributes are needed, they are space separated. For
1304example:
1305
1306.. code-block:: llvm
1307
1308 define void @f() noinline { ... }
1309 define void @f() alwaysinline { ... }
1310 define void @f() alwaysinline optsize { ... }
1311 define void @f() optsize { ... }
1312
Sean Silvab084af42012-12-07 10:36:55 +00001313``alignstack(<n>)``
1314 This attribute indicates that, when emitting the prologue and
1315 epilogue, the backend should forcibly align the stack pointer.
1316 Specify the desired alignment, which must be a power of two, in
1317 parentheses.
George Burgess IV278199f2016-04-12 01:05:35 +00001318``allocsize(<EltSizeParam>[, <NumEltsParam>])``
1319 This attribute indicates that the annotated function will always return at
1320 least a given number of bytes (or null). Its arguments are zero-indexed
1321 parameter numbers; if one argument is provided, then it's assumed that at
1322 least ``CallSite.Args[EltSizeParam]`` bytes will be available at the
1323 returned pointer. If two are provided, then it's assumed that
1324 ``CallSite.Args[EltSizeParam] * CallSite.Args[NumEltsParam]`` bytes are
1325 available. The referenced parameters must be integer types. No assumptions
1326 are made about the contents of the returned block of memory.
Sean Silvab084af42012-12-07 10:36:55 +00001327``alwaysinline``
1328 This attribute indicates that the inliner should attempt to inline
1329 this function into callers whenever possible, ignoring any active
1330 inlining size threshold for this caller.
Michael Gottesman41748d72013-06-27 00:25:01 +00001331``builtin``
1332 This indicates that the callee function at a call site should be
1333 recognized as a built-in function, even though the function's declaration
Michael Gottesman3a6a9672013-07-02 21:32:56 +00001334 uses the ``nobuiltin`` attribute. This is only valid at call sites for
Richard Smith32dbdf62014-07-31 04:25:36 +00001335 direct calls to functions that are declared with the ``nobuiltin``
Michael Gottesman41748d72013-06-27 00:25:01 +00001336 attribute.
Michael Gottesman296adb82013-06-27 22:48:08 +00001337``cold``
1338 This attribute indicates that this function is rarely called. When
1339 computing edge weights, basic blocks post-dominated by a cold
1340 function call are also considered to be cold; and, thus, given low
1341 weight.
Owen Anderson85fa7d52015-05-26 23:48:40 +00001342``convergent``
Justin Lebard5fb6952016-02-09 23:03:17 +00001343 In some parallel execution models, there exist operations that cannot be
1344 made control-dependent on any additional values. We call such operations
Justin Lebar58535b12016-02-17 17:46:41 +00001345 ``convergent``, and mark them with this attribute.
Justin Lebard5fb6952016-02-09 23:03:17 +00001346
Justin Lebar58535b12016-02-17 17:46:41 +00001347 The ``convergent`` attribute may appear on functions or call/invoke
1348 instructions. When it appears on a function, it indicates that calls to
1349 this function should not be made control-dependent on additional values.
Justin Bognera4635372016-07-06 20:02:45 +00001350 For example, the intrinsic ``llvm.nvvm.barrier0`` is ``convergent``, so
Justin Lebard5fb6952016-02-09 23:03:17 +00001351 calls to this intrinsic cannot be made control-dependent on additional
Justin Lebar58535b12016-02-17 17:46:41 +00001352 values.
Justin Lebard5fb6952016-02-09 23:03:17 +00001353
Justin Lebar58535b12016-02-17 17:46:41 +00001354 When it appears on a call/invoke, the ``convergent`` attribute indicates
1355 that we should treat the call as though we're calling a convergent
1356 function. This is particularly useful on indirect calls; without this we
1357 may treat such calls as though the target is non-convergent.
1358
1359 The optimizer may remove the ``convergent`` attribute on functions when it
1360 can prove that the function does not execute any convergent operations.
1361 Similarly, the optimizer may remove ``convergent`` on calls/invokes when it
1362 can prove that the call/invoke cannot call a convergent function.
Vaivaswatha Nagarajfb3f4902015-12-16 16:16:19 +00001363``inaccessiblememonly``
1364 This attribute indicates that the function may only access memory that
1365 is not accessible by the module being compiled. This is a weaker form
1366 of ``readnone``.
1367``inaccessiblemem_or_argmemonly``
1368 This attribute indicates that the function may only access memory that is
1369 either not accessible by the module being compiled, or is pointed to
1370 by its pointer arguments. This is a weaker form of ``argmemonly``
Sean Silvab084af42012-12-07 10:36:55 +00001371``inlinehint``
1372 This attribute indicates that the source code contained a hint that
1373 inlining this function is desirable (such as the "inline" keyword in
1374 C/C++). It is just a hint; it imposes no requirements on the
1375 inliner.
Tom Roeder44cb65f2014-06-05 19:29:43 +00001376``jumptable``
1377 This attribute indicates that the function should be added to a
1378 jump-instruction table at code-generation time, and that all address-taken
1379 references to this function should be replaced with a reference to the
1380 appropriate jump-instruction-table function pointer. Note that this creates
1381 a new pointer for the original function, which means that code that depends
1382 on function-pointer identity can break. So, any function annotated with
1383 ``jumptable`` must also be ``unnamed_addr``.
Andrea Di Biagio9b5d23b2013-08-09 18:42:18 +00001384``minsize``
1385 This attribute suggests that optimization passes and code generator
1386 passes make choices that keep the code size of this function as small
Andrew Trickd4d1d9c2013-10-31 17:18:07 +00001387 as possible and perform optimizations that may sacrifice runtime
Andrea Di Biagio9b5d23b2013-08-09 18:42:18 +00001388 performance in order to minimize the size of the generated code.
Sean Silvab084af42012-12-07 10:36:55 +00001389``naked``
1390 This attribute disables prologue / epilogue emission for the
1391 function. This can have very system-specific consequences.
Sumanth Gundapaneni6af104e2017-07-28 22:26:22 +00001392``no-jump-tables``
1393 When this attribute is set to true, the jump tables and lookup tables that
1394 can be generated from a switch case lowering are disabled.
Eli Bendersky97ad9242013-04-18 16:11:44 +00001395``nobuiltin``
Michael Gottesman41748d72013-06-27 00:25:01 +00001396 This indicates that the callee function at a call site is not recognized as
1397 a built-in function. LLVM will retain the original call and not replace it
1398 with equivalent code based on the semantics of the built-in function, unless
1399 the call site uses the ``builtin`` attribute. This is valid at call sites
1400 and on function declarations and definitions.
Bill Wendlingbf902f12013-02-06 06:22:58 +00001401``noduplicate``
1402 This attribute indicates that calls to the function cannot be
1403 duplicated. A call to a ``noduplicate`` function may be moved
1404 within its parent function, but may not be duplicated within
1405 its parent function.
1406
1407 A function containing a ``noduplicate`` call may still
1408 be an inlining candidate, provided that the call is not
1409 duplicated by inlining. That implies that the function has
1410 internal linkage and only has one call site, so the original
1411 call is dead after inlining.
Sean Silvab084af42012-12-07 10:36:55 +00001412``noimplicitfloat``
1413 This attributes disables implicit floating point instructions.
1414``noinline``
1415 This attribute indicates that the inliner should never inline this
1416 function in any situation. This attribute may not be used together
1417 with the ``alwaysinline`` attribute.
Sean Silva1cbbcf12013-08-06 19:34:37 +00001418``nonlazybind``
1419 This attribute suppresses lazy symbol binding for the function. This
1420 may make calls to the function faster, at the cost of extra program
1421 startup time if the function is not called during program startup.
Sean Silvab084af42012-12-07 10:36:55 +00001422``noredzone``
1423 This attribute indicates that the code generator should not use a
1424 red zone, even if the target-specific ABI normally permits it.
1425``noreturn``
1426 This function attribute indicates that the function never returns
1427 normally. This produces undefined behavior at runtime if the
1428 function ever does dynamically return.
James Molloye6f87ca2015-11-06 10:32:53 +00001429``norecurse``
1430 This function attribute indicates that the function does not call itself
1431 either directly or indirectly down any possible call path. This produces
1432 undefined behavior at runtime if the function ever does recurse.
Sean Silvab084af42012-12-07 10:36:55 +00001433``nounwind``
Reid Kleckner96d01132015-02-11 01:23:16 +00001434 This function attribute indicates that the function never raises an
1435 exception. If the function does raise an exception, its runtime
1436 behavior is undefined. However, functions marked nounwind may still
1437 trap or generate asynchronous exceptions. Exception handling schemes
1438 that are recognized by LLVM to handle asynchronous exceptions, such
1439 as SEH, will still provide their implementation defined semantics.
Andrea Di Biagio377496b2013-08-23 11:53:55 +00001440``optnone``
Paul Robinsona2550a62015-11-30 21:56:16 +00001441 This function attribute indicates that most optimization passes will skip
1442 this function, with the exception of interprocedural optimization passes.
1443 Code generation defaults to the "fast" instruction selector.
Andrea Di Biagio377496b2013-08-23 11:53:55 +00001444 This attribute cannot be used together with the ``alwaysinline``
1445 attribute; this attribute is also incompatible
1446 with the ``minsize`` attribute and the ``optsize`` attribute.
Andrew Trickd4d1d9c2013-10-31 17:18:07 +00001447
Paul Robinsondcbe35b2013-11-18 21:44:03 +00001448 This attribute requires the ``noinline`` attribute to be specified on
1449 the function as well, so the function is never inlined into any caller.
Andrea Di Biagio377496b2013-08-23 11:53:55 +00001450 Only functions with the ``alwaysinline`` attribute are valid
Paul Robinsondcbe35b2013-11-18 21:44:03 +00001451 candidates for inlining into the body of this function.
Sean Silvab084af42012-12-07 10:36:55 +00001452``optsize``
1453 This attribute suggests that optimization passes and code generator
1454 passes make choices that keep the code size of this function low,
Andrea Di Biagio9b5d23b2013-08-09 18:42:18 +00001455 and otherwise do optimizations specifically to reduce code size as
1456 long as they do not significantly impact runtime performance.
Sanjoy Dasc0441c22016-04-19 05:24:47 +00001457``"patchable-function"``
1458 This attribute tells the code generator that the code
1459 generated for this function needs to follow certain conventions that
1460 make it possible for a runtime function to patch over it later.
1461 The exact effect of this attribute depends on its string value,
Charles Davise9c32c72016-08-08 21:20:15 +00001462 for which there currently is one legal possibility:
Sanjoy Dasc0441c22016-04-19 05:24:47 +00001463
1464 * ``"prologue-short-redirect"`` - This style of patchable
1465 function is intended to support patching a function prologue to
1466 redirect control away from the function in a thread safe
1467 manner. It guarantees that the first instruction of the
1468 function will be large enough to accommodate a short jump
1469 instruction, and will be sufficiently aligned to allow being
1470 fully changed via an atomic compare-and-swap instruction.
1471 While the first requirement can be satisfied by inserting large
1472 enough NOP, LLVM can and will try to re-purpose an existing
1473 instruction (i.e. one that would have to be emitted anyway) as
1474 the patchable instruction larger than a short jump.
1475
1476 ``"prologue-short-redirect"`` is currently only supported on
1477 x86-64.
1478
1479 This attribute by itself does not imply restrictions on
1480 inter-procedural optimizations. All of the semantic effects the
1481 patching may have to be separately conveyed via the linkage type.
whitequarked54b4a2017-06-21 18:46:50 +00001482``"probe-stack"``
1483 This attribute indicates that the function will trigger a guard region
1484 in the end of the stack. It ensures that accesses to the stack must be
1485 no further apart than the size of the guard region to a previous
1486 access of the stack. It takes one required string value, the name of
1487 the stack probing function that will be called.
1488
1489 If a function that has a ``"probe-stack"`` attribute is inlined into
1490 a function with another ``"probe-stack"`` attribute, the resulting
1491 function has the ``"probe-stack"`` attribute of the caller. If a
1492 function that has a ``"probe-stack"`` attribute is inlined into a
1493 function that has no ``"probe-stack"`` attribute at all, the resulting
1494 function has the ``"probe-stack"`` attribute of the callee.
Sean Silvab084af42012-12-07 10:36:55 +00001495``readnone``
Nick Lewyckyc2ec0722013-07-06 00:29:58 +00001496 On a function, this attribute indicates that the function computes its
1497 result (or decides to unwind an exception) based strictly on its arguments,
Sean Silvab084af42012-12-07 10:36:55 +00001498 without dereferencing any pointer arguments or otherwise accessing
1499 any mutable state (e.g. memory, control registers, etc) visible to
1500 caller functions. It does not write through any pointer arguments
1501 (including ``byval`` arguments) and never changes any state visible
Sanjoy Das5be2e842017-02-13 23:19:07 +00001502 to callers. This means while it cannot unwind exceptions by calling
1503 the ``C++`` exception throwing methods (since they write to memory), there may
1504 be non-``C++`` mechanisms that throw exceptions without writing to LLVM
1505 visible memory.
Andrew Trickd4d1d9c2013-10-31 17:18:07 +00001506
Nick Lewyckyc2ec0722013-07-06 00:29:58 +00001507 On an argument, this attribute indicates that the function does not
1508 dereference that pointer argument, even though it may read or write the
Nick Lewyckyefe31f22013-07-06 01:04:47 +00001509 memory that the pointer points to if accessed through other pointers.
Sean Silvab084af42012-12-07 10:36:55 +00001510``readonly``
Nick Lewyckyc2ec0722013-07-06 00:29:58 +00001511 On a function, this attribute indicates that the function does not write
1512 through any pointer arguments (including ``byval`` arguments) or otherwise
Sean Silvab084af42012-12-07 10:36:55 +00001513 modify any state (e.g. memory, control registers, etc) visible to
1514 caller functions. It may dereference pointer arguments and read
1515 state that may be set in the caller. A readonly function always
1516 returns the same value (or unwinds an exception identically) when
Sanjoy Das5be2e842017-02-13 23:19:07 +00001517 called with the same set of arguments and global state. This means while it
1518 cannot unwind exceptions by calling the ``C++`` exception throwing methods
1519 (since they write to memory), there may be non-``C++`` mechanisms that throw
1520 exceptions without writing to LLVM visible memory.
Andrew Trickd4d1d9c2013-10-31 17:18:07 +00001521
Nick Lewyckyc2ec0722013-07-06 00:29:58 +00001522 On an argument, this attribute indicates that the function does not write
1523 through this pointer argument, even though it may write to the memory that
1524 the pointer points to.
whitequark08b20352017-06-22 23:22:36 +00001525``"stack-probe-size"``
1526 This attribute controls the behavior of stack probes: either
1527 the ``"probe-stack"`` attribute, or ABI-required stack probes, if any.
1528 It defines the size of the guard region. It ensures that if the function
1529 may use more stack space than the size of the guard region, stack probing
1530 sequence will be emitted. It takes one required integer value, which
1531 is 4096 by default.
1532
1533 If a function that has a ``"stack-probe-size"`` attribute is inlined into
1534 a function with another ``"stack-probe-size"`` attribute, the resulting
1535 function has the ``"stack-probe-size"`` attribute that has the lower
1536 numeric value. If a function that has a ``"stack-probe-size"`` attribute is
1537 inlined into a function that has no ``"stack-probe-size"`` attribute
1538 at all, the resulting function has the ``"stack-probe-size"`` attribute
1539 of the callee.
Nicolai Haehnle84c9f992016-07-04 08:01:29 +00001540``writeonly``
1541 On a function, this attribute indicates that the function may write to but
1542 does not read from memory.
1543
1544 On an argument, this attribute indicates that the function may write to but
1545 does not read through this pointer argument (even though it may read from
1546 the memory that the pointer points to).
Igor Laevsky39d662f2015-07-11 10:30:36 +00001547``argmemonly``
1548 This attribute indicates that the only memory accesses inside function are
1549 loads and stores from objects pointed to by its pointer-typed arguments,
1550 with arbitrary offsets. Or in other words, all memory operations in the
1551 function can refer to memory only using pointers based on its function
1552 arguments.
1553 Note that ``argmemonly`` can be used together with ``readonly`` attribute
1554 in order to specify that function reads only from its arguments.
Sean Silvab084af42012-12-07 10:36:55 +00001555``returns_twice``
1556 This attribute indicates that this function can return twice. The C
1557 ``setjmp`` is an example of such a function. The compiler disables
1558 some optimizations (like tail calls) in the caller of these
1559 functions.
Peter Collingbourne82437bf2015-06-15 21:07:11 +00001560``safestack``
1561 This attribute indicates that
1562 `SafeStack <http://clang.llvm.org/docs/SafeStack.html>`_
1563 protection is enabled for this function.
1564
1565 If a function that has a ``safestack`` attribute is inlined into a
1566 function that doesn't have a ``safestack`` attribute or which has an
1567 ``ssp``, ``sspstrong`` or ``sspreq`` attribute, then the resulting
1568 function will have a ``safestack`` attribute.
Kostya Serebryanycf880b92013-02-26 06:58:09 +00001569``sanitize_address``
1570 This attribute indicates that AddressSanitizer checks
1571 (dynamic address safety analysis) are enabled for this function.
1572``sanitize_memory``
1573 This attribute indicates that MemorySanitizer checks (dynamic detection
1574 of accesses to uninitialized memory) are enabled for this function.
1575``sanitize_thread``
1576 This attribute indicates that ThreadSanitizer checks
1577 (dynamic thread safety analysis) are enabled for this function.
Matt Arsenaultb19b57e2017-04-28 20:25:27 +00001578``speculatable``
1579 This function attribute indicates that the function does not have any
1580 effects besides calculating its result and does not have undefined behavior.
1581 Note that ``speculatable`` is not enough to conclude that along any
Xin Tongc7180202017-05-02 23:24:12 +00001582 particular execution path the number of calls to this function will not be
Matt Arsenaultb19b57e2017-04-28 20:25:27 +00001583 externally observable. This attribute is only valid on functions
1584 and declarations, not on individual call sites. If a function is
1585 incorrectly marked as speculatable and really does exhibit
1586 undefined behavior, the undefined behavior may be observed even
1587 if the call site is dead code.
1588
Sean Silvab084af42012-12-07 10:36:55 +00001589``ssp``
1590 This attribute indicates that the function should emit a stack
Dmitri Gribenkoe8131122013-01-19 20:34:20 +00001591 smashing protector. It is in the form of a "canary" --- a random value
Sean Silvab084af42012-12-07 10:36:55 +00001592 placed on the stack before the local variables that's checked upon
1593 return from the function to see if it has been overwritten. A
1594 heuristic is used to determine if a function needs stack protectors
Bill Wendling7c8f96a2013-01-23 06:43:53 +00001595 or not. The heuristic used will enable protectors for functions with:
Dmitri Gribenko69b56472013-01-29 23:14:41 +00001596
Bill Wendling7c8f96a2013-01-23 06:43:53 +00001597 - Character arrays larger than ``ssp-buffer-size`` (default 8).
1598 - Aggregates containing character arrays larger than ``ssp-buffer-size``.
1599 - Calls to alloca() with variable sizes or constant sizes greater than
1600 ``ssp-buffer-size``.
Sean Silvab084af42012-12-07 10:36:55 +00001601
Josh Magee24c7f062014-02-01 01:36:16 +00001602 Variables that are identified as requiring a protector will be arranged
1603 on the stack such that they are adjacent to the stack protector guard.
1604
Sean Silvab084af42012-12-07 10:36:55 +00001605 If a function that has an ``ssp`` attribute is inlined into a
1606 function that doesn't have an ``ssp`` attribute, then the resulting
1607 function will have an ``ssp`` attribute.
1608``sspreq``
1609 This attribute indicates that the function should *always* emit a
1610 stack smashing protector. This overrides the ``ssp`` function
1611 attribute.
1612
Josh Magee24c7f062014-02-01 01:36:16 +00001613 Variables that are identified as requiring a protector will be arranged
1614 on the stack such that they are adjacent to the stack protector guard.
1615 The specific layout rules are:
1616
1617 #. Large arrays and structures containing large arrays
1618 (``>= ssp-buffer-size``) are closest to the stack protector.
1619 #. Small arrays and structures containing small arrays
1620 (``< ssp-buffer-size``) are 2nd closest to the protector.
1621 #. Variables that have had their address taken are 3rd closest to the
1622 protector.
1623
Sean Silvab084af42012-12-07 10:36:55 +00001624 If a function that has an ``sspreq`` attribute is inlined into a
1625 function that doesn't have an ``sspreq`` attribute or which has an
Bill Wendlingd154e2832013-01-23 06:41:41 +00001626 ``ssp`` or ``sspstrong`` attribute, then the resulting function will have
1627 an ``sspreq`` attribute.
1628``sspstrong``
1629 This attribute indicates that the function should emit a stack smashing
Bill Wendling7c8f96a2013-01-23 06:43:53 +00001630 protector. This attribute causes a strong heuristic to be used when
Sean Silvaa1190322015-08-06 22:56:48 +00001631 determining if a function needs stack protectors. The strong heuristic
Bill Wendling7c8f96a2013-01-23 06:43:53 +00001632 will enable protectors for functions with:
Dmitri Gribenko69b56472013-01-29 23:14:41 +00001633
Bill Wendling7c8f96a2013-01-23 06:43:53 +00001634 - Arrays of any size and type
1635 - Aggregates containing an array of any size and type.
1636 - Calls to alloca().
1637 - Local variables that have had their address taken.
1638
Josh Magee24c7f062014-02-01 01:36:16 +00001639 Variables that are identified as requiring a protector will be arranged
1640 on the stack such that they are adjacent to the stack protector guard.
1641 The specific layout rules are:
1642
1643 #. Large arrays and structures containing large arrays
1644 (``>= ssp-buffer-size``) are closest to the stack protector.
1645 #. Small arrays and structures containing small arrays
1646 (``< ssp-buffer-size``) are 2nd closest to the protector.
1647 #. Variables that have had their address taken are 3rd closest to the
1648 protector.
1649
Bill Wendling7c8f96a2013-01-23 06:43:53 +00001650 This overrides the ``ssp`` function attribute.
Bill Wendlingd154e2832013-01-23 06:41:41 +00001651
1652 If a function that has an ``sspstrong`` attribute is inlined into a
1653 function that doesn't have an ``sspstrong`` attribute, then the
1654 resulting function will have an ``sspstrong`` attribute.
Andrew Kaylor53a5fbb2017-08-14 21:15:13 +00001655``strictfp``
1656 This attribute indicates that the function was called from a scope that
1657 requires strict floating point semantics. LLVM will not attempt any
1658 optimizations that require assumptions about the floating point rounding
1659 mode or that might alter the state of floating point status flags that
1660 might otherwise be set or cleared by calling this function.
Reid Kleckner5a2ab2b2015-03-04 00:08:56 +00001661``"thunk"``
1662 This attribute indicates that the function will delegate to some other
1663 function with a tail call. The prototype of a thunk should not be used for
1664 optimization purposes. The caller is expected to cast the thunk prototype to
1665 match the thunk target prototype.
Sean Silvab084af42012-12-07 10:36:55 +00001666``uwtable``
1667 This attribute indicates that the ABI being targeted requires that
Sean Silva706fba52015-08-06 22:56:24 +00001668 an unwind table entry be produced for this function even if we can
Sean Silvab084af42012-12-07 10:36:55 +00001669 show that no exceptions passes by it. This is normally the case for
1670 the ELF x86-64 abi, but it can be disabled for some compilation
1671 units.
Sean Silvab084af42012-12-07 10:36:55 +00001672
Javed Absarf3d79042017-05-11 12:28:08 +00001673.. _glattrs:
1674
1675Global Attributes
1676-----------------
1677
1678Attributes may be set to communicate additional information about a global variable.
1679Unlike :ref:`function attributes <fnattrs>`, attributes on a global variable
1680are grouped into a single :ref:`attribute group <attrgrp>`.
Sanjoy Dasb513a9f2015-09-24 23:34:52 +00001681
1682.. _opbundles:
1683
1684Operand Bundles
1685---------------
1686
Sanjoy Dasb513a9f2015-09-24 23:34:52 +00001687Operand bundles are tagged sets of SSA values that can be associated
Sanjoy Dasb0e9d4a52015-09-25 00:05:40 +00001688with certain LLVM instructions (currently only ``call`` s and
1689``invoke`` s). In a way they are like metadata, but dropping them is
Sanjoy Dasb513a9f2015-09-24 23:34:52 +00001690incorrect and will change program semantics.
1691
1692Syntax::
David Majnemer34cacb42015-10-22 01:46:38 +00001693
Sanjoy Das9f3c1252015-11-21 09:12:07 +00001694 operand bundle set ::= '[' operand bundle (, operand bundle )* ']'
Sanjoy Dasb513a9f2015-09-24 23:34:52 +00001695 operand bundle ::= tag '(' [ bundle operand ] (, bundle operand )* ')'
1696 bundle operand ::= SSA value
1697 tag ::= string constant
1698
1699Operand bundles are **not** part of a function's signature, and a
1700given function may be called from multiple places with different kinds
1701of operand bundles. This reflects the fact that the operand bundles
1702are conceptually a part of the ``call`` (or ``invoke``), not the
1703callee being dispatched to.
1704
1705Operand bundles are a generic mechanism intended to support
1706runtime-introspection-like functionality for managed languages. While
1707the exact semantics of an operand bundle depend on the bundle tag,
1708there are certain limitations to how much the presence of an operand
1709bundle can influence the semantics of a program. These restrictions
1710are described as the semantics of an "unknown" operand bundle. As
1711long as the behavior of an operand bundle is describable within these
1712restrictions, LLVM does not need to have special knowledge of the
1713operand bundle to not miscompile programs containing it.
1714
David Majnemer34cacb42015-10-22 01:46:38 +00001715- The bundle operands for an unknown operand bundle escape in unknown
1716 ways before control is transferred to the callee or invokee.
1717- Calls and invokes with operand bundles have unknown read / write
1718 effect on the heap on entry and exit (even if the call target is
Sylvestre Ledru84666a12016-02-14 20:16:22 +00001719 ``readnone`` or ``readonly``), unless they're overridden with
Sanjoy Das98a341b2015-10-22 03:12:22 +00001720 callsite specific attributes.
1721- An operand bundle at a call site cannot change the implementation
1722 of the called function. Inter-procedural optimizations work as
1723 usual as long as they take into account the first two properties.
Sanjoy Dasb513a9f2015-09-24 23:34:52 +00001724
Sanjoy Dascdafd842015-11-11 21:38:02 +00001725More specific types of operand bundles are described below.
1726
Sanjoy Dasb51325d2016-03-11 19:08:34 +00001727.. _deopt_opbundles:
1728
Sanjoy Dascdafd842015-11-11 21:38:02 +00001729Deoptimization Operand Bundles
1730^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1731
Sanjoy Das9f3c1252015-11-21 09:12:07 +00001732Deoptimization operand bundles are characterized by the ``"deopt"``
Sanjoy Dascdafd842015-11-11 21:38:02 +00001733operand bundle tag. These operand bundles represent an alternate
1734"safe" continuation for the call site they're attached to, and can be
1735used by a suitable runtime to deoptimize the compiled frame at the
Sanjoy Das9f3c1252015-11-21 09:12:07 +00001736specified call site. There can be at most one ``"deopt"`` operand
1737bundle attached to a call site. Exact details of deoptimization is
1738out of scope for the language reference, but it usually involves
1739rewriting a compiled frame into a set of interpreted frames.
Sanjoy Dascdafd842015-11-11 21:38:02 +00001740
1741From the compiler's perspective, deoptimization operand bundles make
1742the call sites they're attached to at least ``readonly``. They read
1743through all of their pointer typed operands (even if they're not
1744otherwise escaped) and the entire visible heap. Deoptimization
1745operand bundles do not capture their operands except during
1746deoptimization, in which case control will not be returned to the
1747compiled frame.
1748
Sanjoy Das2d161452015-11-18 06:23:38 +00001749The inliner knows how to inline through calls that have deoptimization
1750operand bundles. Just like inlining through a normal call site
1751involves composing the normal and exceptional continuations, inlining
1752through a call site with a deoptimization operand bundle needs to
1753appropriately compose the "safe" deoptimization continuation. The
1754inliner does this by prepending the parent's deoptimization
1755continuation to every deoptimization continuation in the inlined body.
1756E.g. inlining ``@f`` into ``@g`` in the following example
1757
1758.. code-block:: llvm
1759
1760 define void @f() {
1761 call void @x() ;; no deopt state
1762 call void @y() [ "deopt"(i32 10) ]
1763 call void @y() [ "deopt"(i32 10), "unknown"(i8* null) ]
1764 ret void
1765 }
1766
1767 define void @g() {
1768 call void @f() [ "deopt"(i32 20) ]
1769 ret void
1770 }
1771
1772will result in
1773
1774.. code-block:: llvm
1775
1776 define void @g() {
1777 call void @x() ;; still no deopt state
1778 call void @y() [ "deopt"(i32 20, i32 10) ]
1779 call void @y() [ "deopt"(i32 20, i32 10), "unknown"(i8* null) ]
1780 ret void
1781 }
1782
1783It is the frontend's responsibility to structure or encode the
1784deoptimization state in a way that syntactically prepending the
1785caller's deoptimization state to the callee's deoptimization state is
1786semantically equivalent to composing the caller's deoptimization
1787continuation after the callee's deoptimization continuation.
1788
Joseph Tremoulete28885e2016-01-10 04:28:38 +00001789.. _ob_funclet:
1790
David Majnemer3bb88c02015-12-15 21:27:27 +00001791Funclet Operand Bundles
1792^^^^^^^^^^^^^^^^^^^^^^^
1793
1794Funclet operand bundles are characterized by the ``"funclet"``
1795operand bundle tag. These operand bundles indicate that a call site
1796is within a particular funclet. There can be at most one
1797``"funclet"`` operand bundle attached to a call site and it must have
1798exactly one bundle operand.
1799
Joseph Tremoulete28885e2016-01-10 04:28:38 +00001800If any funclet EH pads have been "entered" but not "exited" (per the
1801`description in the EH doc\ <ExceptionHandling.html#wineh-constraints>`_),
1802it is undefined behavior to execute a ``call`` or ``invoke`` which:
1803
1804* does not have a ``"funclet"`` bundle and is not a ``call`` to a nounwind
1805 intrinsic, or
1806* has a ``"funclet"`` bundle whose operand is not the most-recently-entered
1807 not-yet-exited funclet EH pad.
1808
1809Similarly, if no funclet EH pads have been entered-but-not-yet-exited,
1810executing a ``call`` or ``invoke`` with a ``"funclet"`` bundle is undefined behavior.
1811
Sanjoy Dasa34ce952016-01-20 19:50:25 +00001812GC Transition Operand Bundles
1813^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1814
1815GC transition operand bundles are characterized by the
1816``"gc-transition"`` operand bundle tag. These operand bundles mark a
1817call as a transition between a function with one GC strategy to a
1818function with a different GC strategy. If coordinating the transition
1819between GC strategies requires additional code generation at the call
1820site, these bundles may contain any values that are needed by the
1821generated code. For more details, see :ref:`GC Transitions
1822<gc_transition_args>`.
1823
Sean Silvab084af42012-12-07 10:36:55 +00001824.. _moduleasm:
1825
1826Module-Level Inline Assembly
1827----------------------------
1828
1829Modules may contain "module-level inline asm" blocks, which corresponds
1830to the GCC "file scope inline asm" blocks. These blocks are internally
1831concatenated by LLVM and treated as a single unit, but may be separated
1832in the ``.ll`` file if desired. The syntax is very simple:
1833
1834.. code-block:: llvm
1835
1836 module asm "inline asm code goes here"
1837 module asm "more can go here"
1838
1839The strings can contain any character by escaping non-printable
1840characters. The escape sequence used is simply "\\xx" where "xx" is the
1841two digit hex code for the number.
1842
James Y Knightbc832ed2015-07-08 18:08:36 +00001843Note that the assembly string *must* be parseable by LLVM's integrated assembler
1844(unless it is disabled), even when emitting a ``.s`` file.
Sean Silvab084af42012-12-07 10:36:55 +00001845
Eli Benderskyfdc529a2013-06-07 19:40:08 +00001846.. _langref_datalayout:
1847
Sean Silvab084af42012-12-07 10:36:55 +00001848Data Layout
1849-----------
1850
1851A module may specify a target specific data layout string that specifies
1852how data is to be laid out in memory. The syntax for the data layout is
1853simply:
1854
1855.. code-block:: llvm
1856
1857 target datalayout = "layout specification"
1858
1859The *layout specification* consists of a list of specifications
1860separated by the minus sign character ('-'). Each specification starts
1861with a letter and may include other information after the letter to
1862define some aspect of the data layout. The specifications accepted are
1863as follows:
1864
1865``E``
1866 Specifies that the target lays out data in big-endian form. That is,
1867 the bits with the most significance have the lowest address
1868 location.
1869``e``
1870 Specifies that the target lays out data in little-endian form. That
1871 is, the bits with the least significance have the lowest address
1872 location.
1873``S<size>``
1874 Specifies the natural alignment of the stack in bits. Alignment
1875 promotion of stack variables is limited to the natural stack
1876 alignment to avoid dynamic stack realignment. The stack alignment
1877 must be a multiple of 8-bits. If omitted, the natural stack
1878 alignment defaults to "unspecified", which does not prevent any
1879 alignment promotions.
Matt Arsenault3c1fc762017-04-10 22:27:50 +00001880``A<address space>``
1881 Specifies the address space of objects created by '``alloca``'.
1882 Defaults to the default address space of 0.
Sean Silvab084af42012-12-07 10:36:55 +00001883``p[n]:<size>:<abi>:<pref>``
1884 This specifies the *size* of a pointer and its ``<abi>`` and
1885 ``<pref>``\erred alignments for address space ``n``. All sizes are in
Sean Silva706fba52015-08-06 22:56:24 +00001886 bits. The address space, ``n``, is optional, and if not specified,
Sean Silvaa1190322015-08-06 22:56:48 +00001887 denotes the default address space 0. The value of ``n`` must be
Rafael Espindolaabdd7262014-01-06 21:40:24 +00001888 in the range [1,2^23).
Sean Silvab084af42012-12-07 10:36:55 +00001889``i<size>:<abi>:<pref>``
1890 This specifies the alignment for an integer type of a given bit
1891 ``<size>``. The value of ``<size>`` must be in the range [1,2^23).
1892``v<size>:<abi>:<pref>``
1893 This specifies the alignment for a vector type of a given bit
1894 ``<size>``.
1895``f<size>:<abi>:<pref>``
1896 This specifies the alignment for a floating point type of a given bit
1897 ``<size>``. Only values of ``<size>`` that are supported by the target
1898 will work. 32 (float) and 64 (double) are supported on all targets; 80
1899 or 128 (different flavors of long double) are also supported on some
1900 targets.
Rafael Espindolaabdd7262014-01-06 21:40:24 +00001901``a:<abi>:<pref>``
1902 This specifies the alignment for an object of aggregate type.
Rafael Espindola58873562014-01-03 19:21:54 +00001903``m:<mangling>``
Hans Wennborgd4245ac2014-01-15 02:49:17 +00001904 If present, specifies that llvm names are mangled in the output. The
1905 options are
1906
1907 * ``e``: ELF mangling: Private symbols get a ``.L`` prefix.
1908 * ``m``: Mips mangling: Private symbols get a ``$`` prefix.
1909 * ``o``: Mach-O mangling: Private symbols get ``L`` prefix. Other
1910 symbols get a ``_`` prefix.
1911 * ``w``: Windows COFF prefix: Similar to Mach-O, but stdcall and fastcall
1912 functions also get a suffix based on the frame size.
Saleem Abdulrasool70d2d642015-10-25 20:39:35 +00001913 * ``x``: Windows x86 COFF prefix: Similar to Windows COFF, but use a ``_``
1914 prefix for ``__cdecl`` functions.
Sean Silvab084af42012-12-07 10:36:55 +00001915``n<size1>:<size2>:<size3>...``
1916 This specifies a set of native integer widths for the target CPU in
1917 bits. For example, it might contain ``n32`` for 32-bit PowerPC,
1918 ``n32:64`` for PowerPC 64, or ``n8:16:32:64`` for X86-64. Elements of
1919 this set are considered to support most general arithmetic operations
1920 efficiently.
Sanjoy Dasc6af5ea2016-07-28 23:43:38 +00001921``ni:<address space0>:<address space1>:<address space2>...``
1922 This specifies pointer types with the specified address spaces
1923 as :ref:`Non-Integral Pointer Type <nointptrtype>` s. The ``0``
1924 address space cannot be specified as non-integral.
Sean Silvab084af42012-12-07 10:36:55 +00001925
Rafael Espindolaabdd7262014-01-06 21:40:24 +00001926On every specification that takes a ``<abi>:<pref>``, specifying the
1927``<pref>`` alignment is optional. If omitted, the preceding ``:``
1928should be omitted too and ``<pref>`` will be equal to ``<abi>``.
1929
Sean Silvab084af42012-12-07 10:36:55 +00001930When constructing the data layout for a given target, LLVM starts with a
1931default set of specifications which are then (possibly) overridden by
1932the specifications in the ``datalayout`` keyword. The default
1933specifications are given in this list:
1934
1935- ``E`` - big endian
Matt Arsenault24b49c42013-07-31 17:49:08 +00001936- ``p:64:64:64`` - 64-bit pointers with 64-bit alignment.
1937- ``p[n]:64:64:64`` - Other address spaces are assumed to be the
1938 same as the default address space.
Patrik Hagglunda832ab12013-01-30 09:02:06 +00001939- ``S0`` - natural stack alignment is unspecified
Sean Silvab084af42012-12-07 10:36:55 +00001940- ``i1:8:8`` - i1 is 8-bit (byte) aligned
1941- ``i8:8:8`` - i8 is 8-bit (byte) aligned
1942- ``i16:16:16`` - i16 is 16-bit aligned
1943- ``i32:32:32`` - i32 is 32-bit aligned
1944- ``i64:32:64`` - i64 has ABI alignment of 32-bits but preferred
1945 alignment of 64-bits
Patrik Hagglunda832ab12013-01-30 09:02:06 +00001946- ``f16:16:16`` - half is 16-bit aligned
Sean Silvab084af42012-12-07 10:36:55 +00001947- ``f32:32:32`` - float is 32-bit aligned
1948- ``f64:64:64`` - double is 64-bit aligned
Patrik Hagglunda832ab12013-01-30 09:02:06 +00001949- ``f128:128:128`` - quad is 128-bit aligned
Sean Silvab084af42012-12-07 10:36:55 +00001950- ``v64:64:64`` - 64-bit vector is 64-bit aligned
1951- ``v128:128:128`` - 128-bit vector is 128-bit aligned
Rafael Espindolae8f4d582013-12-12 17:21:51 +00001952- ``a:0:64`` - aggregates are 64-bit aligned
Sean Silvab084af42012-12-07 10:36:55 +00001953
1954When LLVM is determining the alignment for a given type, it uses the
1955following rules:
1956
1957#. If the type sought is an exact match for one of the specifications,
1958 that specification is used.
1959#. If no match is found, and the type sought is an integer type, then
1960 the smallest integer type that is larger than the bitwidth of the
1961 sought type is used. If none of the specifications are larger than
1962 the bitwidth then the largest integer type is used. For example,
1963 given the default specifications above, the i7 type will use the
1964 alignment of i8 (next largest) while both i65 and i256 will use the
1965 alignment of i64 (largest specified).
1966#. If no match is found, and the type sought is a vector type, then the
1967 largest vector type that is smaller than the sought vector type will
1968 be used as a fall back. This happens because <128 x double> can be
1969 implemented in terms of 64 <2 x double>, for example.
1970
1971The function of the data layout string may not be what you expect.
1972Notably, this is not a specification from the frontend of what alignment
1973the code generator should use.
1974
1975Instead, if specified, the target data layout is required to match what
1976the ultimate *code generator* expects. This string is used by the
1977mid-level optimizers to improve code, and this only works if it matches
Mehdi Amini4a121fa2015-03-14 22:04:06 +00001978what the ultimate code generator uses. There is no way to generate IR
1979that does not embed this target-specific detail into the IR. If you
1980don't specify the string, the default specifications will be used to
1981generate a Data Layout and the optimization phases will operate
1982accordingly and introduce target specificity into the IR with respect to
1983these default specifications.
Sean Silvab084af42012-12-07 10:36:55 +00001984
Bill Wendling5cc90842013-10-18 23:41:25 +00001985.. _langref_triple:
1986
1987Target Triple
1988-------------
1989
1990A module may specify a target triple string that describes the target
1991host. The syntax for the target triple is simply:
1992
1993.. code-block:: llvm
1994
1995 target triple = "x86_64-apple-macosx10.7.0"
1996
1997The *target triple* string consists of a series of identifiers delimited
1998by the minus sign character ('-'). The canonical forms are:
1999
2000::
2001
2002 ARCHITECTURE-VENDOR-OPERATING_SYSTEM
2003 ARCHITECTURE-VENDOR-OPERATING_SYSTEM-ENVIRONMENT
2004
2005This information is passed along to the backend so that it generates
2006code for the proper architecture. It's possible to override this on the
2007command line with the ``-mtriple`` command line option.
2008
Sean Silvab084af42012-12-07 10:36:55 +00002009.. _pointeraliasing:
2010
2011Pointer Aliasing Rules
2012----------------------
2013
2014Any memory access must be done through a pointer value associated with
2015an address range of the memory access, otherwise the behavior is
2016undefined. Pointer values are associated with address ranges according
2017to the following rules:
2018
2019- A pointer value is associated with the addresses associated with any
2020 value it is *based* on.
2021- An address of a global variable is associated with the address range
2022 of the variable's storage.
2023- The result value of an allocation instruction is associated with the
2024 address range of the allocated storage.
2025- A null pointer in the default address-space is associated with no
2026 address.
2027- An integer constant other than zero or a pointer value returned from
2028 a function not defined within LLVM may be associated with address
2029 ranges allocated through mechanisms other than those provided by
2030 LLVM. Such ranges shall not overlap with any ranges of addresses
2031 allocated by mechanisms provided by LLVM.
2032
2033A pointer value is *based* on another pointer value according to the
2034following rules:
2035
2036- A pointer value formed from a ``getelementptr`` operation is *based*
David Blaikief91b0302017-06-19 05:34:21 +00002037 on the second value operand of the ``getelementptr``.
Sean Silvab084af42012-12-07 10:36:55 +00002038- The result value of a ``bitcast`` is *based* on the operand of the
2039 ``bitcast``.
2040- A pointer value formed by an ``inttoptr`` is *based* on all pointer
2041 values that contribute (directly or indirectly) to the computation of
2042 the pointer's value.
2043- The "*based* on" relationship is transitive.
2044
2045Note that this definition of *"based"* is intentionally similar to the
2046definition of *"based"* in C99, though it is slightly weaker.
2047
2048LLVM IR does not associate types with memory. The result type of a
2049``load`` merely indicates the size and alignment of the memory from
2050which to load, as well as the interpretation of the value. The first
2051operand type of a ``store`` similarly only indicates the size and
2052alignment of the store.
2053
2054Consequently, type-based alias analysis, aka TBAA, aka
2055``-fstrict-aliasing``, is not applicable to general unadorned LLVM IR.
2056:ref:`Metadata <metadata>` may be used to encode additional information
2057which specialized optimization passes may use to implement type-based
2058alias analysis.
2059
2060.. _volatile:
2061
2062Volatile Memory Accesses
2063------------------------
2064
2065Certain memory accesses, such as :ref:`load <i_load>`'s,
2066:ref:`store <i_store>`'s, and :ref:`llvm.memcpy <int_memcpy>`'s may be
2067marked ``volatile``. The optimizers must not change the number of
2068volatile operations or change their order of execution relative to other
2069volatile operations. The optimizers *may* change the order of volatile
2070operations relative to non-volatile operations. This is not Java's
2071"volatile" and has no cross-thread synchronization behavior.
2072
Andrew Trick89fc5a62013-01-30 21:19:35 +00002073IR-level volatile loads and stores cannot safely be optimized into
2074llvm.memcpy or llvm.memmove intrinsics even when those intrinsics are
2075flagged volatile. Likewise, the backend should never split or merge
2076target-legal volatile load/store instructions.
2077
Andrew Trick7e6f9282013-01-31 00:49:39 +00002078.. admonition:: Rationale
2079
2080 Platforms may rely on volatile loads and stores of natively supported
2081 data width to be executed as single instruction. For example, in C
2082 this holds for an l-value of volatile primitive type with native
2083 hardware support, but not necessarily for aggregate types. The
2084 frontend upholds these expectations, which are intentionally
Sean Silva706fba52015-08-06 22:56:24 +00002085 unspecified in the IR. The rules above ensure that IR transformations
Andrew Trick7e6f9282013-01-31 00:49:39 +00002086 do not violate the frontend's contract with the language.
2087
Sean Silvab084af42012-12-07 10:36:55 +00002088.. _memmodel:
2089
2090Memory Model for Concurrent Operations
2091--------------------------------------
2092
2093The LLVM IR does not define any way to start parallel threads of
2094execution or to register signal handlers. Nonetheless, there are
2095platform-specific ways to create them, and we define LLVM IR's behavior
2096in their presence. This model is inspired by the C++0x memory model.
2097
2098For a more informal introduction to this model, see the :doc:`Atomics`.
2099
2100We define a *happens-before* partial order as the least partial order
2101that
2102
2103- Is a superset of single-thread program order, and
2104- When a *synchronizes-with* ``b``, includes an edge from ``a`` to
2105 ``b``. *Synchronizes-with* pairs are introduced by platform-specific
2106 techniques, like pthread locks, thread creation, thread joining,
2107 etc., and by atomic instructions. (See also :ref:`Atomic Memory Ordering
2108 Constraints <ordering>`).
2109
2110Note that program order does not introduce *happens-before* edges
2111between a thread and signals executing inside that thread.
2112
2113Every (defined) read operation (load instructions, memcpy, atomic
2114loads/read-modify-writes, etc.) R reads a series of bytes written by
2115(defined) write operations (store instructions, atomic
2116stores/read-modify-writes, memcpy, etc.). For the purposes of this
2117section, initialized globals are considered to have a write of the
2118initializer which is atomic and happens before any other read or write
2119of the memory in question. For each byte of a read R, R\ :sub:`byte`
2120may see any write to the same byte, except:
2121
2122- If write\ :sub:`1` happens before write\ :sub:`2`, and
2123 write\ :sub:`2` happens before R\ :sub:`byte`, then
2124 R\ :sub:`byte` does not see write\ :sub:`1`.
2125- If R\ :sub:`byte` happens before write\ :sub:`3`, then
2126 R\ :sub:`byte` does not see write\ :sub:`3`.
2127
2128Given that definition, R\ :sub:`byte` is defined as follows:
2129
2130- If R is volatile, the result is target-dependent. (Volatile is
2131 supposed to give guarantees which can support ``sig_atomic_t`` in
Richard Smith32dbdf62014-07-31 04:25:36 +00002132 C/C++, and may be used for accesses to addresses that do not behave
Sean Silvab084af42012-12-07 10:36:55 +00002133 like normal memory. It does not generally provide cross-thread
2134 synchronization.)
2135- Otherwise, if there is no write to the same byte that happens before
2136 R\ :sub:`byte`, R\ :sub:`byte` returns ``undef`` for that byte.
2137- Otherwise, if R\ :sub:`byte` may see exactly one write,
2138 R\ :sub:`byte` returns the value written by that write.
2139- Otherwise, if R is atomic, and all the writes R\ :sub:`byte` may
2140 see are atomic, it chooses one of the values written. See the :ref:`Atomic
2141 Memory Ordering Constraints <ordering>` section for additional
2142 constraints on how the choice is made.
2143- Otherwise R\ :sub:`byte` returns ``undef``.
2144
2145R returns the value composed of the series of bytes it read. This
2146implies that some bytes within the value may be ``undef`` **without**
2147the entire value being ``undef``. Note that this only defines the
2148semantics of the operation; it doesn't mean that targets will emit more
2149than one instruction to read the series of bytes.
2150
2151Note that in cases where none of the atomic intrinsics are used, this
2152model places only one restriction on IR transformations on top of what
2153is required for single-threaded execution: introducing a store to a byte
2154which might not otherwise be stored is not allowed in general.
2155(Specifically, in the case where another thread might write to and read
2156from an address, introducing a store can change a load that may see
2157exactly one write into a load that may see multiple writes.)
2158
2159.. _ordering:
2160
2161Atomic Memory Ordering Constraints
2162----------------------------------
2163
2164Atomic instructions (:ref:`cmpxchg <i_cmpxchg>`,
2165:ref:`atomicrmw <i_atomicrmw>`, :ref:`fence <i_fence>`,
2166:ref:`atomic load <i_load>`, and :ref:`atomic store <i_store>`) take
Tim Northovere94a5182014-03-11 10:48:52 +00002167ordering parameters that determine which other atomic instructions on
Sean Silvab084af42012-12-07 10:36:55 +00002168the same address they *synchronize with*. These semantics are borrowed
2169from Java and C++0x, but are somewhat more colloquial. If these
2170descriptions aren't precise enough, check those specs (see spec
2171references in the :doc:`atomics guide <Atomics>`).
2172:ref:`fence <i_fence>` instructions treat these orderings somewhat
2173differently since they don't take an address. See that instruction's
2174documentation for details.
2175
2176For a simpler introduction to the ordering constraints, see the
2177:doc:`Atomics`.
2178
2179``unordered``
2180 The set of values that can be read is governed by the happens-before
2181 partial order. A value cannot be read unless some operation wrote
2182 it. This is intended to provide a guarantee strong enough to model
2183 Java's non-volatile shared variables. This ordering cannot be
2184 specified for read-modify-write operations; it is not strong enough
2185 to make them atomic in any interesting way.
2186``monotonic``
2187 In addition to the guarantees of ``unordered``, there is a single
2188 total order for modifications by ``monotonic`` operations on each
2189 address. All modification orders must be compatible with the
2190 happens-before order. There is no guarantee that the modification
2191 orders can be combined to a global total order for the whole program
2192 (and this often will not be possible). The read in an atomic
2193 read-modify-write operation (:ref:`cmpxchg <i_cmpxchg>` and
2194 :ref:`atomicrmw <i_atomicrmw>`) reads the value in the modification
2195 order immediately before the value it writes. If one atomic read
2196 happens before another atomic read of the same address, the later
2197 read must see the same value or a later value in the address's
2198 modification order. This disallows reordering of ``monotonic`` (or
2199 stronger) operations on the same address. If an address is written
2200 ``monotonic``-ally by one thread, and other threads ``monotonic``-ally
2201 read that address repeatedly, the other threads must eventually see
2202 the write. This corresponds to the C++0x/C1x
2203 ``memory_order_relaxed``.
2204``acquire``
2205 In addition to the guarantees of ``monotonic``, a
2206 *synchronizes-with* edge may be formed with a ``release`` operation.
2207 This is intended to model C++'s ``memory_order_acquire``.
2208``release``
2209 In addition to the guarantees of ``monotonic``, if this operation
2210 writes a value which is subsequently read by an ``acquire``
2211 operation, it *synchronizes-with* that operation. (This isn't a
2212 complete description; see the C++0x definition of a release
2213 sequence.) This corresponds to the C++0x/C1x
2214 ``memory_order_release``.
2215``acq_rel`` (acquire+release)
2216 Acts as both an ``acquire`` and ``release`` operation on its
2217 address. This corresponds to the C++0x/C1x ``memory_order_acq_rel``.
2218``seq_cst`` (sequentially consistent)
2219 In addition to the guarantees of ``acq_rel`` (``acquire`` for an
Richard Smith32dbdf62014-07-31 04:25:36 +00002220 operation that only reads, ``release`` for an operation that only
Sean Silvab084af42012-12-07 10:36:55 +00002221 writes), there is a global total order on all
2222 sequentially-consistent operations on all addresses, which is
2223 consistent with the *happens-before* partial order and with the
2224 modification orders of all the affected addresses. Each
2225 sequentially-consistent read sees the last preceding write to the
2226 same address in this global order. This corresponds to the C++0x/C1x
2227 ``memory_order_seq_cst`` and Java volatile.
2228
Konstantin Zhuravlyovbb80d3e2017-07-11 22:23:00 +00002229.. _syncscope:
Sean Silvab084af42012-12-07 10:36:55 +00002230
Konstantin Zhuravlyovbb80d3e2017-07-11 22:23:00 +00002231If an atomic operation is marked ``syncscope("singlethread")``, it only
2232*synchronizes with* and only participates in the seq\_cst total orderings of
2233other operations running in the same thread (for example, in signal handlers).
2234
2235If an atomic operation is marked ``syncscope("<target-scope>")``, where
2236``<target-scope>`` is a target specific synchronization scope, then it is target
2237dependent if it *synchronizes with* and participates in the seq\_cst total
2238orderings of other operations.
2239
2240Otherwise, an atomic operation that is not marked ``syncscope("singlethread")``
2241or ``syncscope("<target-scope>")`` *synchronizes with* and participates in the
2242seq\_cst total orderings of other operations that are not marked
2243``syncscope("singlethread")`` or ``syncscope("<target-scope>")``.
Sean Silvab084af42012-12-07 10:36:55 +00002244
2245.. _fastmath:
2246
2247Fast-Math Flags
2248---------------
2249
2250LLVM IR floating-point binary ops (:ref:`fadd <i_fadd>`,
2251:ref:`fsub <i_fsub>`, :ref:`fmul <i_fmul>`, :ref:`fdiv <i_fdiv>`,
Matt Arsenault74b73e52017-01-10 18:06:38 +00002252:ref:`frem <i_frem>`, :ref:`fcmp <i_fcmp>`) and :ref:`call <i_call>`
2253instructions have the following flags that can be set to enable
2254otherwise unsafe floating point transformations.
Sean Silvab084af42012-12-07 10:36:55 +00002255
2256``nnan``
2257 No NaNs - Allow optimizations to assume the arguments and result are not
2258 NaN. Such optimizations are required to retain defined behavior over
2259 NaNs, but the value of the result is undefined.
2260
2261``ninf``
2262 No Infs - Allow optimizations to assume the arguments and result are not
2263 +/-Inf. Such optimizations are required to retain defined behavior over
2264 +/-Inf, but the value of the result is undefined.
2265
2266``nsz``
2267 No Signed Zeros - Allow optimizations to treat the sign of a zero
2268 argument or result as insignificant.
2269
2270``arcp``
2271 Allow Reciprocal - Allow optimizations to use the reciprocal of an
2272 argument rather than perform division.
2273
Adam Nemetcd847a82017-03-28 20:11:52 +00002274``contract``
2275 Allow floating-point contraction (e.g. fusing a multiply followed by an
2276 addition into a fused multiply-and-add).
2277
Sean Silvab084af42012-12-07 10:36:55 +00002278``fast``
2279 Fast - Allow algebraically equivalent transformations that may
2280 dramatically change results in floating point (e.g. reassociate). This
2281 flag implies all the others.
2282
Duncan P. N. Exon Smith0a448fb2014-08-19 21:30:15 +00002283.. _uselistorder:
2284
2285Use-list Order Directives
2286-------------------------
2287
2288Use-list directives encode the in-memory order of each use-list, allowing the
Sean Silvaa1190322015-08-06 22:56:48 +00002289order to be recreated. ``<order-indexes>`` is a comma-separated list of
2290indexes that are assigned to the referenced value's uses. The referenced
Duncan P. N. Exon Smith0a448fb2014-08-19 21:30:15 +00002291value's use-list is immediately sorted by these indexes.
2292
Sean Silvaa1190322015-08-06 22:56:48 +00002293Use-list directives may appear at function scope or global scope. They are not
2294instructions, and have no effect on the semantics of the IR. When they're at
Duncan P. N. Exon Smith0a448fb2014-08-19 21:30:15 +00002295function scope, they must appear after the terminator of the final basic block.
2296
2297If basic blocks have their address taken via ``blockaddress()`` expressions,
2298``uselistorder_bb`` can be used to reorder their use-lists from outside their
2299function's scope.
2300
2301:Syntax:
2302
2303::
2304
2305 uselistorder <ty> <value>, { <order-indexes> }
2306 uselistorder_bb @function, %block { <order-indexes> }
2307
2308:Examples:
2309
2310::
2311
Duncan P. N. Exon Smith23046652014-08-19 21:48:04 +00002312 define void @foo(i32 %arg1, i32 %arg2) {
2313 entry:
2314 ; ... instructions ...
2315 bb:
2316 ; ... instructions ...
2317
2318 ; At function scope.
2319 uselistorder i32 %arg1, { 1, 0, 2 }
2320 uselistorder label %bb, { 1, 0 }
2321 }
Duncan P. N. Exon Smith0a448fb2014-08-19 21:30:15 +00002322
2323 ; At global scope.
2324 uselistorder i32* @global, { 1, 2, 0 }
2325 uselistorder i32 7, { 1, 0 }
2326 uselistorder i32 (i32) @bar, { 1, 0 }
2327 uselistorder_bb @foo, %bb, { 5, 1, 3, 2, 0, 4 }
2328
Teresa Johnsonde9b8b42016-04-22 13:09:17 +00002329.. _source_filename:
2330
2331Source Filename
2332---------------
2333
2334The *source filename* string is set to the original module identifier,
2335which will be the name of the compiled source file when compiling from
2336source through the clang front end, for example. It is then preserved through
2337the IR and bitcode.
2338
2339This is currently necessary to generate a consistent unique global
2340identifier for local functions used in profile data, which prepends the
2341source file name to the local function name.
2342
2343The syntax for the source file name is simply:
2344
Renato Golin124f2592016-07-20 12:16:38 +00002345.. code-block:: text
Teresa Johnsonde9b8b42016-04-22 13:09:17 +00002346
2347 source_filename = "/path/to/source.c"
2348
Sean Silvab084af42012-12-07 10:36:55 +00002349.. _typesystem:
2350
2351Type System
2352===========
2353
2354The LLVM type system is one of the most important features of the
2355intermediate representation. Being typed enables a number of
2356optimizations to be performed on the intermediate representation
2357directly, without having to do extra analyses on the side before the
2358transformation. A strong type system makes it easier to read the
2359generated code and enables novel analyses and transformations that are
2360not feasible to perform on normal three address code representations.
2361
Rafael Espindola08013342013-12-07 19:34:20 +00002362.. _t_void:
Eli Bendersky0220e6b2013-06-07 20:24:43 +00002363
Rafael Espindola08013342013-12-07 19:34:20 +00002364Void Type
2365---------
Sean Silvab084af42012-12-07 10:36:55 +00002366
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002367:Overview:
2368
Rafael Espindola08013342013-12-07 19:34:20 +00002369
2370The void type does not represent any value and has no size.
2371
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002372:Syntax:
2373
Rafael Espindola08013342013-12-07 19:34:20 +00002374
2375::
2376
2377 void
Sean Silvab084af42012-12-07 10:36:55 +00002378
2379
Rafael Espindola08013342013-12-07 19:34:20 +00002380.. _t_function:
Sean Silvab084af42012-12-07 10:36:55 +00002381
Rafael Espindola08013342013-12-07 19:34:20 +00002382Function Type
2383-------------
Sean Silvab084af42012-12-07 10:36:55 +00002384
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002385:Overview:
2386
Sean Silvab084af42012-12-07 10:36:55 +00002387
Rafael Espindola08013342013-12-07 19:34:20 +00002388The function type can be thought of as a function signature. It consists of a
2389return type and a list of formal parameter types. The return type of a function
2390type is a void type or first class type --- except for :ref:`label <t_label>`
2391and :ref:`metadata <t_metadata>` types.
Sean Silvab084af42012-12-07 10:36:55 +00002392
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002393:Syntax:
Sean Silvab084af42012-12-07 10:36:55 +00002394
Rafael Espindola08013342013-12-07 19:34:20 +00002395::
Sean Silvab084af42012-12-07 10:36:55 +00002396
Rafael Espindola08013342013-12-07 19:34:20 +00002397 <returntype> (<parameter list>)
Sean Silvab084af42012-12-07 10:36:55 +00002398
Rafael Espindola08013342013-12-07 19:34:20 +00002399...where '``<parameter list>``' is a comma-separated list of type
2400specifiers. Optionally, the parameter list may include a type ``...``, which
Sean Silvaa1190322015-08-06 22:56:48 +00002401indicates that the function takes a variable number of arguments. Variable
Rafael Espindola08013342013-12-07 19:34:20 +00002402argument functions can access their arguments with the :ref:`variable argument
Sean Silvaa1190322015-08-06 22:56:48 +00002403handling intrinsic <int_varargs>` functions. '``<returntype>``' is any type
Rafael Espindola08013342013-12-07 19:34:20 +00002404except :ref:`label <t_label>` and :ref:`metadata <t_metadata>`.
Sean Silvab084af42012-12-07 10:36:55 +00002405
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002406:Examples:
Sean Silvab084af42012-12-07 10:36:55 +00002407
Rafael Espindola08013342013-12-07 19:34:20 +00002408+---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
2409| ``i32 (i32)`` | function taking an ``i32``, returning an ``i32`` |
2410+---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
2411| ``float (i16, i32 *) *`` | :ref:`Pointer <t_pointer>` to a function that takes an ``i16`` and a :ref:`pointer <t_pointer>` to ``i32``, returning ``float``. |
2412+---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
2413| ``i32 (i8*, ...)`` | A vararg function that takes at least one :ref:`pointer <t_pointer>` to ``i8`` (char in C), which returns an integer. This is the signature for ``printf`` in LLVM. |
2414+---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
2415| ``{i32, i32} (i32)`` | A function taking an ``i32``, returning a :ref:`structure <t_struct>` containing two ``i32`` values |
2416+---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
2417
2418.. _t_firstclass:
2419
2420First Class Types
2421-----------------
Sean Silvab084af42012-12-07 10:36:55 +00002422
2423The :ref:`first class <t_firstclass>` types are perhaps the most important.
2424Values of these types are the only ones which can be produced by
2425instructions.
2426
Rafael Espindola08013342013-12-07 19:34:20 +00002427.. _t_single_value:
Sean Silvab084af42012-12-07 10:36:55 +00002428
Rafael Espindola08013342013-12-07 19:34:20 +00002429Single Value Types
2430^^^^^^^^^^^^^^^^^^
Sean Silvab084af42012-12-07 10:36:55 +00002431
Rafael Espindola08013342013-12-07 19:34:20 +00002432These are the types that are valid in registers from CodeGen's perspective.
Sean Silvab084af42012-12-07 10:36:55 +00002433
2434.. _t_integer:
2435
2436Integer Type
Rafael Espindola08013342013-12-07 19:34:20 +00002437""""""""""""
Sean Silvab084af42012-12-07 10:36:55 +00002438
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002439:Overview:
Sean Silvab084af42012-12-07 10:36:55 +00002440
2441The integer type is a very simple type that simply specifies an
2442arbitrary bit width for the integer type desired. Any bit width from 1
2443bit to 2\ :sup:`23`\ -1 (about 8 million) can be specified.
2444
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002445:Syntax:
Sean Silvab084af42012-12-07 10:36:55 +00002446
2447::
2448
2449 iN
2450
2451The number of bits the integer will occupy is specified by the ``N``
2452value.
2453
2454Examples:
Rafael Espindola08013342013-12-07 19:34:20 +00002455*********
Sean Silvab084af42012-12-07 10:36:55 +00002456
2457+----------------+------------------------------------------------+
2458| ``i1`` | a single-bit integer. |
2459+----------------+------------------------------------------------+
2460| ``i32`` | a 32-bit integer. |
2461+----------------+------------------------------------------------+
2462| ``i1942652`` | a really big integer of over 1 million bits. |
2463+----------------+------------------------------------------------+
2464
2465.. _t_floating:
2466
2467Floating Point Types
Rafael Espindola08013342013-12-07 19:34:20 +00002468""""""""""""""""""""
Sean Silvab084af42012-12-07 10:36:55 +00002469
2470.. list-table::
2471 :header-rows: 1
2472
2473 * - Type
2474 - Description
2475
2476 * - ``half``
2477 - 16-bit floating point value
2478
2479 * - ``float``
2480 - 32-bit floating point value
2481
2482 * - ``double``
2483 - 64-bit floating point value
2484
2485 * - ``fp128``
2486 - 128-bit floating point value (112-bit mantissa)
2487
2488 * - ``x86_fp80``
2489 - 80-bit floating point value (X87)
2490
2491 * - ``ppc_fp128``
2492 - 128-bit floating point value (two 64-bits)
2493
Reid Kleckner9a16d082014-03-05 02:41:37 +00002494X86_mmx Type
2495""""""""""""
Sean Silvab084af42012-12-07 10:36:55 +00002496
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002497:Overview:
Sean Silvab084af42012-12-07 10:36:55 +00002498
Reid Kleckner9a16d082014-03-05 02:41:37 +00002499The x86_mmx type represents a value held in an MMX register on an x86
Sean Silvab084af42012-12-07 10:36:55 +00002500machine. The operations allowed on it are quite limited: parameters and
2501return values, load and store, and bitcast. User-specified MMX
2502instructions are represented as intrinsic or asm calls with arguments
2503and/or results of this type. There are no arrays, vectors or constants
2504of this type.
2505
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002506:Syntax:
Sean Silvab084af42012-12-07 10:36:55 +00002507
2508::
2509
Reid Kleckner9a16d082014-03-05 02:41:37 +00002510 x86_mmx
Sean Silvab084af42012-12-07 10:36:55 +00002511
Sean Silvab084af42012-12-07 10:36:55 +00002512
Rafael Espindola08013342013-12-07 19:34:20 +00002513.. _t_pointer:
2514
2515Pointer Type
2516""""""""""""
Sean Silvab084af42012-12-07 10:36:55 +00002517
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002518:Overview:
Sean Silvab084af42012-12-07 10:36:55 +00002519
Rafael Espindola08013342013-12-07 19:34:20 +00002520The pointer type is used to specify memory locations. Pointers are
2521commonly used to reference objects in memory.
2522
2523Pointer types may have an optional address space attribute defining the
2524numbered address space where the pointed-to object resides. The default
2525address space is number zero. The semantics of non-zero address spaces
2526are target-specific.
2527
2528Note that LLVM does not permit pointers to void (``void*``) nor does it
2529permit pointers to labels (``label*``). Use ``i8*`` instead.
Sean Silvab084af42012-12-07 10:36:55 +00002530
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002531:Syntax:
Sean Silvab084af42012-12-07 10:36:55 +00002532
2533::
2534
Rafael Espindola08013342013-12-07 19:34:20 +00002535 <type> *
2536
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002537:Examples:
Rafael Espindola08013342013-12-07 19:34:20 +00002538
2539+-------------------------+--------------------------------------------------------------------------------------------------------------+
2540| ``[4 x i32]*`` | A :ref:`pointer <t_pointer>` to :ref:`array <t_array>` of four ``i32`` values. |
2541+-------------------------+--------------------------------------------------------------------------------------------------------------+
2542| ``i32 (i32*) *`` | A :ref:`pointer <t_pointer>` to a :ref:`function <t_function>` that takes an ``i32*``, returning an ``i32``. |
2543+-------------------------+--------------------------------------------------------------------------------------------------------------+
2544| ``i32 addrspace(5)*`` | A :ref:`pointer <t_pointer>` to an ``i32`` value that resides in address space #5. |
2545+-------------------------+--------------------------------------------------------------------------------------------------------------+
2546
2547.. _t_vector:
2548
2549Vector Type
2550"""""""""""
2551
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002552:Overview:
Rafael Espindola08013342013-12-07 19:34:20 +00002553
2554A vector type is a simple derived type that represents a vector of
2555elements. Vector types are used when multiple primitive data are
2556operated in parallel using a single instruction (SIMD). A vector type
2557requires a size (number of elements) and an underlying primitive data
2558type. Vector types are considered :ref:`first class <t_firstclass>`.
2559
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002560:Syntax:
Rafael Espindola08013342013-12-07 19:34:20 +00002561
2562::
2563
2564 < <# elements> x <elementtype> >
2565
2566The number of elements is a constant integer value larger than 0;
Manuel Jacob961f7872014-07-30 12:30:06 +00002567elementtype may be any integer, floating point or pointer type. Vectors
2568of size zero are not allowed.
Rafael Espindola08013342013-12-07 19:34:20 +00002569
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002570:Examples:
Rafael Espindola08013342013-12-07 19:34:20 +00002571
2572+-------------------+--------------------------------------------------+
2573| ``<4 x i32>`` | Vector of 4 32-bit integer values. |
2574+-------------------+--------------------------------------------------+
2575| ``<8 x float>`` | Vector of 8 32-bit floating-point values. |
2576+-------------------+--------------------------------------------------+
2577| ``<2 x i64>`` | Vector of 2 64-bit integer values. |
2578+-------------------+--------------------------------------------------+
2579| ``<4 x i64*>`` | Vector of 4 pointers to 64-bit integer values. |
2580+-------------------+--------------------------------------------------+
Sean Silvab084af42012-12-07 10:36:55 +00002581
2582.. _t_label:
2583
2584Label Type
2585^^^^^^^^^^
2586
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002587:Overview:
Sean Silvab084af42012-12-07 10:36:55 +00002588
2589The label type represents code labels.
2590
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002591:Syntax:
Sean Silvab084af42012-12-07 10:36:55 +00002592
2593::
2594
2595 label
2596
David Majnemerb611e3f2015-08-14 05:09:07 +00002597.. _t_token:
2598
2599Token Type
2600^^^^^^^^^^
2601
2602:Overview:
2603
2604The token type is used when a value is associated with an instruction
2605but all uses of the value must not attempt to introspect or obscure it.
2606As such, it is not appropriate to have a :ref:`phi <i_phi>` or
2607:ref:`select <i_select>` of type token.
2608
2609:Syntax:
2610
2611::
2612
2613 token
2614
2615
2616
Sean Silvab084af42012-12-07 10:36:55 +00002617.. _t_metadata:
2618
2619Metadata Type
2620^^^^^^^^^^^^^
2621
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002622:Overview:
Sean Silvab084af42012-12-07 10:36:55 +00002623
2624The metadata type represents embedded metadata. No derived types may be
2625created from metadata except for :ref:`function <t_function>` arguments.
2626
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002627:Syntax:
Sean Silvab084af42012-12-07 10:36:55 +00002628
2629::
2630
2631 metadata
2632
Sean Silvab084af42012-12-07 10:36:55 +00002633.. _t_aggregate:
2634
2635Aggregate Types
2636^^^^^^^^^^^^^^^
2637
2638Aggregate Types are a subset of derived types that can contain multiple
2639member types. :ref:`Arrays <t_array>` and :ref:`structs <t_struct>` are
2640aggregate types. :ref:`Vectors <t_vector>` are not considered to be
2641aggregate types.
2642
2643.. _t_array:
2644
2645Array Type
Rafael Espindola08013342013-12-07 19:34:20 +00002646""""""""""
Sean Silvab084af42012-12-07 10:36:55 +00002647
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002648:Overview:
Sean Silvab084af42012-12-07 10:36:55 +00002649
2650The array type is a very simple derived type that arranges elements
2651sequentially in memory. The array type requires a size (number of
2652elements) and an underlying data type.
2653
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002654:Syntax:
Sean Silvab084af42012-12-07 10:36:55 +00002655
2656::
2657
2658 [<# elements> x <elementtype>]
2659
2660The number of elements is a constant integer value; ``elementtype`` may
2661be any type with a size.
2662
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002663:Examples:
Sean Silvab084af42012-12-07 10:36:55 +00002664
2665+------------------+--------------------------------------+
2666| ``[40 x i32]`` | Array of 40 32-bit integer values. |
2667+------------------+--------------------------------------+
2668| ``[41 x i32]`` | Array of 41 32-bit integer values. |
2669+------------------+--------------------------------------+
2670| ``[4 x i8]`` | Array of 4 8-bit integer values. |
2671+------------------+--------------------------------------+
2672
2673Here are some examples of multidimensional arrays:
2674
2675+-----------------------------+----------------------------------------------------------+
2676| ``[3 x [4 x i32]]`` | 3x4 array of 32-bit integer values. |
2677+-----------------------------+----------------------------------------------------------+
2678| ``[12 x [10 x float]]`` | 12x10 array of single precision floating point values. |
2679+-----------------------------+----------------------------------------------------------+
2680| ``[2 x [3 x [4 x i16]]]`` | 2x3x4 array of 16-bit integer values. |
2681+-----------------------------+----------------------------------------------------------+
2682
2683There is no restriction on indexing beyond the end of the array implied
2684by a static type (though there are restrictions on indexing beyond the
2685bounds of an allocated object in some cases). This means that
2686single-dimension 'variable sized array' addressing can be implemented in
2687LLVM with a zero length array type. An implementation of 'pascal style
2688arrays' in LLVM could use the type "``{ i32, [0 x float]}``", for
2689example.
2690
Sean Silvab084af42012-12-07 10:36:55 +00002691.. _t_struct:
2692
2693Structure Type
Rafael Espindola08013342013-12-07 19:34:20 +00002694""""""""""""""
Sean Silvab084af42012-12-07 10:36:55 +00002695
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002696:Overview:
Sean Silvab084af42012-12-07 10:36:55 +00002697
2698The structure type is used to represent a collection of data members
2699together in memory. The elements of a structure may be any type that has
2700a size.
2701
2702Structures in memory are accessed using '``load``' and '``store``' by
2703getting a pointer to a field with the '``getelementptr``' instruction.
2704Structures in registers are accessed using the '``extractvalue``' and
2705'``insertvalue``' instructions.
2706
2707Structures may optionally be "packed" structures, which indicate that
2708the alignment of the struct is one byte, and that there is no padding
2709between the elements. In non-packed structs, padding between field types
2710is inserted as defined by the DataLayout string in the module, which is
2711required to match what the underlying code generator expects.
2712
2713Structures can either be "literal" or "identified". A literal structure
2714is defined inline with other types (e.g. ``{i32, i32}*``) whereas
2715identified types are always defined at the top level with a name.
2716Literal types are uniqued by their contents and can never be recursive
2717or opaque since there is no way to write one. Identified types can be
2718recursive, can be opaqued, and are never uniqued.
2719
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002720:Syntax:
Sean Silvab084af42012-12-07 10:36:55 +00002721
2722::
2723
2724 %T1 = type { <type list> } ; Identified normal struct type
2725 %T2 = type <{ <type list> }> ; Identified packed struct type
2726
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002727:Examples:
Sean Silvab084af42012-12-07 10:36:55 +00002728
2729+------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
2730| ``{ i32, i32, i32 }`` | A triple of three ``i32`` values |
2731+------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
Daniel Dunbar1dc66ca2013-01-17 18:57:32 +00002732| ``{ float, i32 (i32) * }`` | A pair, where the first element is a ``float`` and the second element is a :ref:`pointer <t_pointer>` to a :ref:`function <t_function>` that takes an ``i32``, returning an ``i32``. |
Sean Silvab084af42012-12-07 10:36:55 +00002733+------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
2734| ``<{ i8, i32 }>`` | A packed struct known to be 5 bytes in size. |
2735+------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
2736
2737.. _t_opaque:
2738
2739Opaque Structure Types
Rafael Espindola08013342013-12-07 19:34:20 +00002740""""""""""""""""""""""
Sean Silvab084af42012-12-07 10:36:55 +00002741
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002742:Overview:
Sean Silvab084af42012-12-07 10:36:55 +00002743
2744Opaque structure types are used to represent named structure types that
2745do not have a body specified. This corresponds (for example) to the C
2746notion of a forward declared structure.
2747
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002748:Syntax:
Sean Silvab084af42012-12-07 10:36:55 +00002749
2750::
2751
2752 %X = type opaque
2753 %52 = type opaque
2754
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002755:Examples:
Sean Silvab084af42012-12-07 10:36:55 +00002756
2757+--------------+-------------------+
2758| ``opaque`` | An opaque type. |
2759+--------------+-------------------+
2760
Sean Silva1703e702014-04-08 21:06:22 +00002761.. _constants:
2762
Sean Silvab084af42012-12-07 10:36:55 +00002763Constants
2764=========
2765
2766LLVM has several different basic types of constants. This section
2767describes them all and their syntax.
2768
2769Simple Constants
2770----------------
2771
2772**Boolean constants**
2773 The two strings '``true``' and '``false``' are both valid constants
2774 of the ``i1`` type.
2775**Integer constants**
2776 Standard integers (such as '4') are constants of the
2777 :ref:`integer <t_integer>` type. Negative numbers may be used with
2778 integer types.
2779**Floating point constants**
2780 Floating point constants use standard decimal notation (e.g.
2781 123.421), exponential notation (e.g. 1.23421e+2), or a more precise
2782 hexadecimal notation (see below). The assembler requires the exact
2783 decimal value of a floating-point constant. For example, the
2784 assembler accepts 1.25 but rejects 1.3 because 1.3 is a repeating
2785 decimal in binary. Floating point constants must have a :ref:`floating
2786 point <t_floating>` type.
2787**Null pointer constants**
2788 The identifier '``null``' is recognized as a null pointer constant
2789 and must be of :ref:`pointer type <t_pointer>`.
David Majnemerf0f224d2015-11-11 21:57:16 +00002790**Token constants**
2791 The identifier '``none``' is recognized as an empty token constant
2792 and must be of :ref:`token type <t_token>`.
Sean Silvab084af42012-12-07 10:36:55 +00002793
2794The one non-intuitive notation for constants is the hexadecimal form of
2795floating point constants. For example, the form
2796'``double 0x432ff973cafa8000``' is equivalent to (but harder to read
2797than) '``double 4.5e+15``'. The only time hexadecimal floating point
2798constants are required (and the only time that they are generated by the
2799disassembler) is when a floating point constant must be emitted but it
2800cannot be represented as a decimal floating point number in a reasonable
2801number of digits. For example, NaN's, infinities, and other special
2802values are represented in their IEEE hexadecimal format so that assembly
2803and disassembly do not cause any bits to change in the constants.
2804
2805When using the hexadecimal form, constants of types half, float, and
2806double are represented using the 16-digit form shown above (which
2807matches the IEEE754 representation for double); half and float values
Dmitri Gribenko4dc2ba12013-01-16 23:40:37 +00002808must, however, be exactly representable as IEEE 754 half and single
Sean Silvab084af42012-12-07 10:36:55 +00002809precision, respectively. Hexadecimal format is always used for long
2810double, and there are three forms of long double. The 80-bit format used
2811by x86 is represented as ``0xK`` followed by 20 hexadecimal digits. The
2812128-bit format used by PowerPC (two adjacent doubles) is represented by
2813``0xM`` followed by 32 hexadecimal digits. The IEEE 128-bit format is
Richard Sandifordae426b42013-05-03 14:32:27 +00002814represented by ``0xL`` followed by 32 hexadecimal digits. Long doubles
2815will only work if they match the long double format on your target.
2816The IEEE 16-bit format (half precision) is represented by ``0xH``
2817followed by 4 hexadecimal digits. All hexadecimal formats are big-endian
2818(sign bit at the left).
Sean Silvab084af42012-12-07 10:36:55 +00002819
Reid Kleckner9a16d082014-03-05 02:41:37 +00002820There are no constants of type x86_mmx.
Sean Silvab084af42012-12-07 10:36:55 +00002821
Eli Bendersky0220e6b2013-06-07 20:24:43 +00002822.. _complexconstants:
2823
Sean Silvab084af42012-12-07 10:36:55 +00002824Complex Constants
2825-----------------
2826
2827Complex constants are a (potentially recursive) combination of simple
2828constants and smaller complex constants.
2829
2830**Structure constants**
2831 Structure constants are represented with notation similar to
2832 structure type definitions (a comma separated list of elements,
2833 surrounded by braces (``{}``)). For example:
2834 "``{ i32 4, float 17.0, i32* @G }``", where "``@G``" is declared as
2835 "``@G = external global i32``". Structure constants must have
2836 :ref:`structure type <t_struct>`, and the number and types of elements
2837 must match those specified by the type.
2838**Array constants**
2839 Array constants are represented with notation similar to array type
2840 definitions (a comma separated list of elements, surrounded by
2841 square brackets (``[]``)). For example:
2842 "``[ i32 42, i32 11, i32 74 ]``". Array constants must have
2843 :ref:`array type <t_array>`, and the number and types of elements must
Daniel Sandersf6051842014-09-11 12:02:59 +00002844 match those specified by the type. As a special case, character array
2845 constants may also be represented as a double-quoted string using the ``c``
2846 prefix. For example: "``c"Hello World\0A\00"``".
Sean Silvab084af42012-12-07 10:36:55 +00002847**Vector constants**
2848 Vector constants are represented with notation similar to vector
2849 type definitions (a comma separated list of elements, surrounded by
2850 less-than/greater-than's (``<>``)). For example:
2851 "``< i32 42, i32 11, i32 74, i32 100 >``". Vector constants
2852 must have :ref:`vector type <t_vector>`, and the number and types of
2853 elements must match those specified by the type.
2854**Zero initialization**
2855 The string '``zeroinitializer``' can be used to zero initialize a
2856 value to zero of *any* type, including scalar and
2857 :ref:`aggregate <t_aggregate>` types. This is often used to avoid
2858 having to print large zero initializers (e.g. for large arrays) and
2859 is always exactly equivalent to using explicit zero initializers.
2860**Metadata node**
Sean Silvaa1190322015-08-06 22:56:48 +00002861 A metadata node is a constant tuple without types. For example:
2862 "``!{!0, !{!2, !0}, !"test"}``". Metadata can reference constant values,
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00002863 for example: "``!{!0, i32 0, i8* @global, i64 (i64)* @function, !"str"}``".
2864 Unlike other typed constants that are meant to be interpreted as part of
2865 the instruction stream, metadata is a place to attach additional
Sean Silvab084af42012-12-07 10:36:55 +00002866 information such as debug info.
2867
2868Global Variable and Function Addresses
2869--------------------------------------
2870
2871The addresses of :ref:`global variables <globalvars>` and
2872:ref:`functions <functionstructure>` are always implicitly valid
2873(link-time) constants. These constants are explicitly referenced when
2874the :ref:`identifier for the global <identifiers>` is used and always have
2875:ref:`pointer <t_pointer>` type. For example, the following is a legal LLVM
2876file:
2877
2878.. code-block:: llvm
2879
2880 @X = global i32 17
2881 @Y = global i32 42
2882 @Z = global [2 x i32*] [ i32* @X, i32* @Y ]
2883
2884.. _undefvalues:
2885
2886Undefined Values
2887----------------
2888
2889The string '``undef``' can be used anywhere a constant is expected, and
2890indicates that the user of the value may receive an unspecified
2891bit-pattern. Undefined values may be of any type (other than '``label``'
2892or '``void``') and be used anywhere a constant is permitted.
2893
2894Undefined values are useful because they indicate to the compiler that
2895the program is well defined no matter what value is used. This gives the
2896compiler more freedom to optimize. Here are some examples of
2897(potentially surprising) transformations that are valid (in pseudo IR):
2898
2899.. code-block:: llvm
2900
2901 %A = add %X, undef
2902 %B = sub %X, undef
2903 %C = xor %X, undef
2904 Safe:
2905 %A = undef
2906 %B = undef
2907 %C = undef
2908
2909This is safe because all of the output bits are affected by the undef
2910bits. Any output bit can have a zero or one depending on the input bits.
2911
2912.. code-block:: llvm
2913
2914 %A = or %X, undef
2915 %B = and %X, undef
2916 Safe:
2917 %A = -1
2918 %B = 0
Sanjoy Das151493a2016-09-15 01:56:58 +00002919 Safe:
2920 %A = %X ;; By choosing undef as 0
2921 %B = %X ;; By choosing undef as -1
Sean Silvab084af42012-12-07 10:36:55 +00002922 Unsafe:
2923 %A = undef
2924 %B = undef
2925
2926These logical operations have bits that are not always affected by the
2927input. For example, if ``%X`` has a zero bit, then the output of the
2928'``and``' operation will always be a zero for that bit, no matter what
2929the corresponding bit from the '``undef``' is. As such, it is unsafe to
2930optimize or assume that the result of the '``and``' is '``undef``'.
2931However, it is safe to assume that all bits of the '``undef``' could be
29320, and optimize the '``and``' to 0. Likewise, it is safe to assume that
2933all the bits of the '``undef``' operand to the '``or``' could be set,
2934allowing the '``or``' to be folded to -1.
2935
2936.. code-block:: llvm
2937
2938 %A = select undef, %X, %Y
2939 %B = select undef, 42, %Y
2940 %C = select %X, %Y, undef
2941 Safe:
2942 %A = %X (or %Y)
2943 %B = 42 (or %Y)
2944 %C = %Y
2945 Unsafe:
2946 %A = undef
2947 %B = undef
2948 %C = undef
2949
2950This set of examples shows that undefined '``select``' (and conditional
2951branch) conditions can go *either way*, but they have to come from one
2952of the two operands. In the ``%A`` example, if ``%X`` and ``%Y`` were
2953both known to have a clear low bit, then ``%A`` would have to have a
2954cleared low bit. However, in the ``%C`` example, the optimizer is
2955allowed to assume that the '``undef``' operand could be the same as
2956``%Y``, allowing the whole '``select``' to be eliminated.
2957
Renato Golin124f2592016-07-20 12:16:38 +00002958.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00002959
2960 %A = xor undef, undef
2961
2962 %B = undef
2963 %C = xor %B, %B
2964
2965 %D = undef
Jonathan Roelofsec81c0b2014-10-16 19:28:10 +00002966 %E = icmp slt %D, 4
Sean Silvab084af42012-12-07 10:36:55 +00002967 %F = icmp gte %D, 4
2968
2969 Safe:
2970 %A = undef
2971 %B = undef
2972 %C = undef
2973 %D = undef
2974 %E = undef
2975 %F = undef
2976
2977This example points out that two '``undef``' operands are not
2978necessarily the same. This can be surprising to people (and also matches
2979C semantics) where they assume that "``X^X``" is always zero, even if
2980``X`` is undefined. This isn't true for a number of reasons, but the
2981short answer is that an '``undef``' "variable" can arbitrarily change
2982its value over its "live range". This is true because the variable
2983doesn't actually *have a live range*. Instead, the value is logically
2984read from arbitrary registers that happen to be around when needed, so
2985the value is not necessarily consistent over time. In fact, ``%A`` and
2986``%C`` need to have the same semantics or the core LLVM "replace all
2987uses with" concept would not hold.
2988
2989.. code-block:: llvm
2990
2991 %A = fdiv undef, %X
2992 %B = fdiv %X, undef
2993 Safe:
2994 %A = undef
2995 b: unreachable
2996
2997These examples show the crucial difference between an *undefined value*
2998and *undefined behavior*. An undefined value (like '``undef``') is
2999allowed to have an arbitrary bit-pattern. This means that the ``%A``
3000operation can be constant folded to '``undef``', because the '``undef``'
3001could be an SNaN, and ``fdiv`` is not (currently) defined on SNaN's.
3002However, in the second example, we can make a more aggressive
3003assumption: because the ``undef`` is allowed to be an arbitrary value,
3004we are allowed to assume that it could be zero. Since a divide by zero
3005has *undefined behavior*, we are allowed to assume that the operation
3006does not execute at all. This allows us to delete the divide and all
3007code after it. Because the undefined operation "can't happen", the
3008optimizer can assume that it occurs in dead code.
3009
Renato Golin124f2592016-07-20 12:16:38 +00003010.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00003011
3012 a: store undef -> %X
3013 b: store %X -> undef
3014 Safe:
3015 a: <deleted>
3016 b: unreachable
3017
3018These examples reiterate the ``fdiv`` example: a store *of* an undefined
3019value can be assumed to not have any effect; we can assume that the
3020value is overwritten with bits that happen to match what was already
3021there. However, a store *to* an undefined location could clobber
3022arbitrary memory, therefore, it has undefined behavior.
3023
3024.. _poisonvalues:
3025
3026Poison Values
3027-------------
3028
3029Poison values are similar to :ref:`undef values <undefvalues>`, however
3030they also represent the fact that an instruction or constant expression
Richard Smith32dbdf62014-07-31 04:25:36 +00003031that cannot evoke side effects has nevertheless detected a condition
3032that results in undefined behavior.
Sean Silvab084af42012-12-07 10:36:55 +00003033
3034There is currently no way of representing a poison value in the IR; they
3035only exist when produced by operations such as :ref:`add <i_add>` with
3036the ``nsw`` flag.
3037
3038Poison value behavior is defined in terms of value *dependence*:
3039
3040- Values other than :ref:`phi <i_phi>` nodes depend on their operands.
3041- :ref:`Phi <i_phi>` nodes depend on the operand corresponding to
3042 their dynamic predecessor basic block.
3043- Function arguments depend on the corresponding actual argument values
3044 in the dynamic callers of their functions.
3045- :ref:`Call <i_call>` instructions depend on the :ref:`ret <i_ret>`
3046 instructions that dynamically transfer control back to them.
3047- :ref:`Invoke <i_invoke>` instructions depend on the
3048 :ref:`ret <i_ret>`, :ref:`resume <i_resume>`, or exception-throwing
3049 call instructions that dynamically transfer control back to them.
3050- Non-volatile loads and stores depend on the most recent stores to all
3051 of the referenced memory addresses, following the order in the IR
3052 (including loads and stores implied by intrinsics such as
3053 :ref:`@llvm.memcpy <int_memcpy>`.)
3054- An instruction with externally visible side effects depends on the
3055 most recent preceding instruction with externally visible side
3056 effects, following the order in the IR. (This includes :ref:`volatile
3057 operations <volatile>`.)
3058- An instruction *control-depends* on a :ref:`terminator
3059 instruction <terminators>` if the terminator instruction has
3060 multiple successors and the instruction is always executed when
3061 control transfers to one of the successors, and may not be executed
3062 when control is transferred to another.
3063- Additionally, an instruction also *control-depends* on a terminator
3064 instruction if the set of instructions it otherwise depends on would
3065 be different if the terminator had transferred control to a different
3066 successor.
3067- Dependence is transitive.
3068
Richard Smith32dbdf62014-07-31 04:25:36 +00003069Poison values have the same behavior as :ref:`undef values <undefvalues>`,
3070with the additional effect that any instruction that has a *dependence*
Sean Silvab084af42012-12-07 10:36:55 +00003071on a poison value has undefined behavior.
3072
3073Here are some examples:
3074
3075.. code-block:: llvm
3076
3077 entry:
3078 %poison = sub nuw i32 0, 1 ; Results in a poison value.
3079 %still_poison = and i32 %poison, 0 ; 0, but also poison.
David Blaikie16a97eb2015-03-04 22:02:58 +00003080 %poison_yet_again = getelementptr i32, i32* @h, i32 %still_poison
Sean Silvab084af42012-12-07 10:36:55 +00003081 store i32 0, i32* %poison_yet_again ; memory at @h[0] is poisoned
3082
3083 store i32 %poison, i32* @g ; Poison value stored to memory.
David Blaikiec7aabbb2015-03-04 22:06:14 +00003084 %poison2 = load i32, i32* @g ; Poison value loaded back from memory.
Sean Silvab084af42012-12-07 10:36:55 +00003085
3086 store volatile i32 %poison, i32* @g ; External observation; undefined behavior.
3087
3088 %narrowaddr = bitcast i32* @g to i16*
3089 %wideaddr = bitcast i32* @g to i64*
David Blaikiec7aabbb2015-03-04 22:06:14 +00003090 %poison3 = load i16, i16* %narrowaddr ; Returns a poison value.
3091 %poison4 = load i64, i64* %wideaddr ; Returns a poison value.
Sean Silvab084af42012-12-07 10:36:55 +00003092
3093 %cmp = icmp slt i32 %poison, 0 ; Returns a poison value.
3094 br i1 %cmp, label %true, label %end ; Branch to either destination.
3095
3096 true:
3097 store volatile i32 0, i32* @g ; This is control-dependent on %cmp, so
3098 ; it has undefined behavior.
3099 br label %end
3100
3101 end:
3102 %p = phi i32 [ 0, %entry ], [ 1, %true ]
3103 ; Both edges into this PHI are
3104 ; control-dependent on %cmp, so this
3105 ; always results in a poison value.
3106
3107 store volatile i32 0, i32* @g ; This would depend on the store in %true
3108 ; if %cmp is true, or the store in %entry
3109 ; otherwise, so this is undefined behavior.
3110
3111 br i1 %cmp, label %second_true, label %second_end
3112 ; The same branch again, but this time the
3113 ; true block doesn't have side effects.
3114
3115 second_true:
3116 ; No side effects!
3117 ret void
3118
3119 second_end:
3120 store volatile i32 0, i32* @g ; This time, the instruction always depends
3121 ; on the store in %end. Also, it is
3122 ; control-equivalent to %end, so this is
3123 ; well-defined (ignoring earlier undefined
3124 ; behavior in this example).
3125
3126.. _blockaddress:
3127
3128Addresses of Basic Blocks
3129-------------------------
3130
3131``blockaddress(@function, %block)``
3132
3133The '``blockaddress``' constant computes the address of the specified
3134basic block in the specified function, and always has an ``i8*`` type.
3135Taking the address of the entry block is illegal.
3136
3137This value only has defined behavior when used as an operand to the
3138':ref:`indirectbr <i_indirectbr>`' instruction, or for comparisons
3139against null. Pointer equality tests between labels addresses results in
Dmitri Gribenkoe8131122013-01-19 20:34:20 +00003140undefined behavior --- though, again, comparison against null is ok, and
Sean Silvab084af42012-12-07 10:36:55 +00003141no label is equal to the null pointer. This may be passed around as an
3142opaque pointer sized value as long as the bits are not inspected. This
3143allows ``ptrtoint`` and arithmetic to be performed on these values so
3144long as the original value is reconstituted before the ``indirectbr``
3145instruction.
3146
3147Finally, some targets may provide defined semantics when using the value
3148as the operand to an inline assembly, but that is target specific.
3149
Eli Bendersky0220e6b2013-06-07 20:24:43 +00003150.. _constantexprs:
3151
Sean Silvab084af42012-12-07 10:36:55 +00003152Constant Expressions
3153--------------------
3154
3155Constant expressions are used to allow expressions involving other
3156constants to be used as constants. Constant expressions may be of any
3157:ref:`first class <t_firstclass>` type and may involve any LLVM operation
3158that does not have side effects (e.g. load and call are not supported).
3159The following is the syntax for constant expressions:
3160
3161``trunc (CST to TYPE)``
3162 Truncate a constant to another type. The bit size of CST must be
3163 larger than the bit size of TYPE. Both types must be integers.
3164``zext (CST to TYPE)``
3165 Zero extend a constant to another type. The bit size of CST must be
3166 smaller than the bit size of TYPE. Both types must be integers.
3167``sext (CST to TYPE)``
3168 Sign extend a constant to another type. The bit size of CST must be
3169 smaller than the bit size of TYPE. Both types must be integers.
3170``fptrunc (CST to TYPE)``
3171 Truncate a floating point constant to another floating point type.
3172 The size of CST must be larger than the size of TYPE. Both types
3173 must be floating point.
3174``fpext (CST to TYPE)``
3175 Floating point extend a constant to another type. The size of CST
3176 must be smaller or equal to the size of TYPE. Both types must be
3177 floating point.
3178``fptoui (CST to TYPE)``
3179 Convert a floating point constant to the corresponding unsigned
3180 integer constant. TYPE must be a scalar or vector integer type. CST
3181 must be of scalar or vector floating point type. Both CST and TYPE
3182 must be scalars, or vectors of the same number of elements. If the
3183 value won't fit in the integer type, the results are undefined.
3184``fptosi (CST to TYPE)``
3185 Convert a floating point constant to the corresponding signed
3186 integer constant. TYPE must be a scalar or vector integer type. CST
3187 must be of scalar or vector floating point type. Both CST and TYPE
3188 must be scalars, or vectors of the same number of elements. If the
3189 value won't fit in the integer type, the results are undefined.
3190``uitofp (CST to TYPE)``
3191 Convert an unsigned integer constant to the corresponding floating
3192 point constant. TYPE must be a scalar or vector floating point type.
3193 CST must be of scalar or vector integer type. Both CST and TYPE must
3194 be scalars, or vectors of the same number of elements. If the value
3195 won't fit in the floating point type, the results are undefined.
3196``sitofp (CST to TYPE)``
3197 Convert a signed integer constant to the corresponding floating
3198 point constant. TYPE must be a scalar or vector floating point type.
3199 CST must be of scalar or vector integer type. Both CST and TYPE must
3200 be scalars, or vectors of the same number of elements. If the value
3201 won't fit in the floating point type, the results are undefined.
3202``ptrtoint (CST to TYPE)``
3203 Convert a pointer typed constant to the corresponding integer
Eli Bendersky9c0d4932013-03-11 16:51:15 +00003204 constant. ``TYPE`` must be an integer type. ``CST`` must be of
Sean Silvab084af42012-12-07 10:36:55 +00003205 pointer type. The ``CST`` value is zero extended, truncated, or
3206 unchanged to make it fit in ``TYPE``.
3207``inttoptr (CST to TYPE)``
3208 Convert an integer constant to a pointer constant. TYPE must be a
3209 pointer type. CST must be of integer type. The CST value is zero
3210 extended, truncated, or unchanged to make it fit in a pointer size.
3211 This one is *really* dangerous!
3212``bitcast (CST to TYPE)``
3213 Convert a constant, CST, to another TYPE. The constraints of the
3214 operands are the same as those for the :ref:`bitcast
3215 instruction <i_bitcast>`.
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00003216``addrspacecast (CST to TYPE)``
3217 Convert a constant pointer or constant vector of pointer, CST, to another
3218 TYPE in a different address space. The constraints of the operands are the
3219 same as those for the :ref:`addrspacecast instruction <i_addrspacecast>`.
David Blaikief72d05b2015-03-13 18:20:45 +00003220``getelementptr (TY, CSTPTR, IDX0, IDX1, ...)``, ``getelementptr inbounds (TY, CSTPTR, IDX0, IDX1, ...)``
Sean Silvab084af42012-12-07 10:36:55 +00003221 Perform the :ref:`getelementptr operation <i_getelementptr>` on
3222 constants. As with the :ref:`getelementptr <i_getelementptr>`
David Blaikief91b0302017-06-19 05:34:21 +00003223 instruction, the index list may have one or more indexes, which are
David Blaikief72d05b2015-03-13 18:20:45 +00003224 required to make sense for the type of "pointer to TY".
Sean Silvab084af42012-12-07 10:36:55 +00003225``select (COND, VAL1, VAL2)``
3226 Perform the :ref:`select operation <i_select>` on constants.
3227``icmp COND (VAL1, VAL2)``
3228 Performs the :ref:`icmp operation <i_icmp>` on constants.
3229``fcmp COND (VAL1, VAL2)``
3230 Performs the :ref:`fcmp operation <i_fcmp>` on constants.
3231``extractelement (VAL, IDX)``
3232 Perform the :ref:`extractelement operation <i_extractelement>` on
3233 constants.
3234``insertelement (VAL, ELT, IDX)``
3235 Perform the :ref:`insertelement operation <i_insertelement>` on
3236 constants.
3237``shufflevector (VEC1, VEC2, IDXMASK)``
3238 Perform the :ref:`shufflevector operation <i_shufflevector>` on
3239 constants.
3240``extractvalue (VAL, IDX0, IDX1, ...)``
3241 Perform the :ref:`extractvalue operation <i_extractvalue>` on
3242 constants. The index list is interpreted in a similar manner as
3243 indices in a ':ref:`getelementptr <i_getelementptr>`' operation. At
3244 least one index value must be specified.
3245``insertvalue (VAL, ELT, IDX0, IDX1, ...)``
3246 Perform the :ref:`insertvalue operation <i_insertvalue>` on constants.
3247 The index list is interpreted in a similar manner as indices in a
3248 ':ref:`getelementptr <i_getelementptr>`' operation. At least one index
3249 value must be specified.
3250``OPCODE (LHS, RHS)``
3251 Perform the specified operation of the LHS and RHS constants. OPCODE
3252 may be any of the :ref:`binary <binaryops>` or :ref:`bitwise
3253 binary <bitwiseops>` operations. The constraints on operands are
3254 the same as those for the corresponding instruction (e.g. no bitwise
3255 operations on floating point values are allowed).
3256
3257Other Values
3258============
3259
Eli Bendersky0220e6b2013-06-07 20:24:43 +00003260.. _inlineasmexprs:
3261
Sean Silvab084af42012-12-07 10:36:55 +00003262Inline Assembler Expressions
3263----------------------------
3264
3265LLVM supports inline assembler expressions (as opposed to :ref:`Module-Level
James Y Knightbc832ed2015-07-08 18:08:36 +00003266Inline Assembly <moduleasm>`) through the use of a special value. This value
3267represents the inline assembler as a template string (containing the
3268instructions to emit), a list of operand constraints (stored as a string), a
3269flag that indicates whether or not the inline asm expression has side effects,
3270and a flag indicating whether the function containing the asm needs to align its
3271stack conservatively.
3272
3273The template string supports argument substitution of the operands using "``$``"
3274followed by a number, to indicate substitution of the given register/memory
3275location, as specified by the constraint string. "``${NUM:MODIFIER}``" may also
3276be used, where ``MODIFIER`` is a target-specific annotation for how to print the
3277operand (See :ref:`inline-asm-modifiers`).
3278
3279A literal "``$``" may be included by using "``$$``" in the template. To include
3280other special characters into the output, the usual "``\XX``" escapes may be
3281used, just as in other strings. Note that after template substitution, the
3282resulting assembly string is parsed by LLVM's integrated assembler unless it is
3283disabled -- even when emitting a ``.s`` file -- and thus must contain assembly
3284syntax known to LLVM.
3285
Reid Kleckner71cb1642017-02-06 18:08:45 +00003286LLVM also supports a few more substitions useful for writing inline assembly:
3287
3288- ``${:uid}``: Expands to a decimal integer unique to this inline assembly blob.
3289 This substitution is useful when declaring a local label. Many standard
3290 compiler optimizations, such as inlining, may duplicate an inline asm blob.
3291 Adding a blob-unique identifier ensures that the two labels will not conflict
3292 during assembly. This is used to implement `GCC's %= special format
3293 string <https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html>`_.
3294- ``${:comment}``: Expands to the comment character of the current target's
3295 assembly dialect. This is usually ``#``, but many targets use other strings,
3296 such as ``;``, ``//``, or ``!``.
3297- ``${:private}``: Expands to the assembler private label prefix. Labels with
3298 this prefix will not appear in the symbol table of the assembled object.
3299 Typically the prefix is ``L``, but targets may use other strings. ``.L`` is
3300 relatively popular.
3301
James Y Knightbc832ed2015-07-08 18:08:36 +00003302LLVM's support for inline asm is modeled closely on the requirements of Clang's
3303GCC-compatible inline-asm support. Thus, the feature-set and the constraint and
3304modifier codes listed here are similar or identical to those in GCC's inline asm
3305support. However, to be clear, the syntax of the template and constraint strings
3306described here is *not* the same as the syntax accepted by GCC and Clang, and,
3307while most constraint letters are passed through as-is by Clang, some get
3308translated to other codes when converting from the C source to the LLVM
3309assembly.
3310
3311An example inline assembler expression is:
Sean Silvab084af42012-12-07 10:36:55 +00003312
3313.. code-block:: llvm
3314
3315 i32 (i32) asm "bswap $0", "=r,r"
3316
3317Inline assembler expressions may **only** be used as the callee operand
3318of a :ref:`call <i_call>` or an :ref:`invoke <i_invoke>` instruction.
3319Thus, typically we have:
3320
3321.. code-block:: llvm
3322
3323 %X = call i32 asm "bswap $0", "=r,r"(i32 %Y)
3324
3325Inline asms with side effects not visible in the constraint list must be
3326marked as having side effects. This is done through the use of the
3327'``sideeffect``' keyword, like so:
3328
3329.. code-block:: llvm
3330
3331 call void asm sideeffect "eieio", ""()
3332
3333In some cases inline asms will contain code that will not work unless
3334the stack is aligned in some way, such as calls or SSE instructions on
3335x86, yet will not contain code that does that alignment within the asm.
3336The compiler should make conservative assumptions about what the asm
3337might contain and should generate its usual stack alignment code in the
3338prologue if the '``alignstack``' keyword is present:
3339
3340.. code-block:: llvm
3341
3342 call void asm alignstack "eieio", ""()
3343
3344Inline asms also support using non-standard assembly dialects. The
3345assumed dialect is ATT. When the '``inteldialect``' keyword is present,
3346the inline asm is using the Intel dialect. Currently, ATT and Intel are
3347the only supported dialects. An example is:
3348
3349.. code-block:: llvm
3350
3351 call void asm inteldialect "eieio", ""()
3352
3353If multiple keywords appear the '``sideeffect``' keyword must come
3354first, the '``alignstack``' keyword second and the '``inteldialect``'
3355keyword last.
3356
James Y Knightbc832ed2015-07-08 18:08:36 +00003357Inline Asm Constraint String
3358^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3359
3360The constraint list is a comma-separated string, each element containing one or
3361more constraint codes.
3362
3363For each element in the constraint list an appropriate register or memory
3364operand will be chosen, and it will be made available to assembly template
3365string expansion as ``$0`` for the first constraint in the list, ``$1`` for the
3366second, etc.
3367
3368There are three different types of constraints, which are distinguished by a
3369prefix symbol in front of the constraint code: Output, Input, and Clobber. The
3370constraints must always be given in that order: outputs first, then inputs, then
3371clobbers. They cannot be intermingled.
3372
3373There are also three different categories of constraint codes:
3374
3375- Register constraint. This is either a register class, or a fixed physical
3376 register. This kind of constraint will allocate a register, and if necessary,
3377 bitcast the argument or result to the appropriate type.
3378- Memory constraint. This kind of constraint is for use with an instruction
3379 taking a memory operand. Different constraints allow for different addressing
3380 modes used by the target.
3381- Immediate value constraint. This kind of constraint is for an integer or other
3382 immediate value which can be rendered directly into an instruction. The
3383 various target-specific constraints allow the selection of a value in the
3384 proper range for the instruction you wish to use it with.
3385
3386Output constraints
3387""""""""""""""""""
3388
3389Output constraints are specified by an "``=``" prefix (e.g. "``=r``"). This
3390indicates that the assembly will write to this operand, and the operand will
3391then be made available as a return value of the ``asm`` expression. Output
3392constraints do not consume an argument from the call instruction. (Except, see
3393below about indirect outputs).
3394
3395Normally, it is expected that no output locations are written to by the assembly
3396expression until *all* of the inputs have been read. As such, LLVM may assign
3397the same register to an output and an input. If this is not safe (e.g. if the
3398assembly contains two instructions, where the first writes to one output, and
3399the second reads an input and writes to a second output), then the "``&``"
3400modifier must be used (e.g. "``=&r``") to specify that the output is an
Sylvestre Ledru84666a12016-02-14 20:16:22 +00003401"early-clobber" output. Marking an output as "early-clobber" ensures that LLVM
James Y Knightbc832ed2015-07-08 18:08:36 +00003402will not use the same register for any inputs (other than an input tied to this
3403output).
3404
3405Input constraints
3406"""""""""""""""""
3407
3408Input constraints do not have a prefix -- just the constraint codes. Each input
3409constraint will consume one argument from the call instruction. It is not
3410permitted for the asm to write to any input register or memory location (unless
3411that input is tied to an output). Note also that multiple inputs may all be
3412assigned to the same register, if LLVM can determine that they necessarily all
3413contain the same value.
3414
3415Instead of providing a Constraint Code, input constraints may also "tie"
3416themselves to an output constraint, by providing an integer as the constraint
3417string. Tied inputs still consume an argument from the call instruction, and
3418take up a position in the asm template numbering as is usual -- they will simply
3419be constrained to always use the same register as the output they've been tied
3420to. For example, a constraint string of "``=r,0``" says to assign a register for
3421output, and use that register as an input as well (it being the 0'th
3422constraint).
3423
3424It is permitted to tie an input to an "early-clobber" output. In that case, no
3425*other* input may share the same register as the input tied to the early-clobber
3426(even when the other input has the same value).
3427
3428You may only tie an input to an output which has a register constraint, not a
3429memory constraint. Only a single input may be tied to an output.
3430
3431There is also an "interesting" feature which deserves a bit of explanation: if a
3432register class constraint allocates a register which is too small for the value
3433type operand provided as input, the input value will be split into multiple
3434registers, and all of them passed to the inline asm.
3435
3436However, this feature is often not as useful as you might think.
3437
3438Firstly, the registers are *not* guaranteed to be consecutive. So, on those
3439architectures that have instructions which operate on multiple consecutive
3440instructions, this is not an appropriate way to support them. (e.g. the 32-bit
3441SparcV8 has a 64-bit load, which instruction takes a single 32-bit register. The
3442hardware then loads into both the named register, and the next register. This
3443feature of inline asm would not be useful to support that.)
3444
3445A few of the targets provide a template string modifier allowing explicit access
3446to the second register of a two-register operand (e.g. MIPS ``L``, ``M``, and
3447``D``). On such an architecture, you can actually access the second allocated
3448register (yet, still, not any subsequent ones). But, in that case, you're still
3449probably better off simply splitting the value into two separate operands, for
3450clarity. (e.g. see the description of the ``A`` constraint on X86, which,
3451despite existing only for use with this feature, is not really a good idea to
3452use)
3453
3454Indirect inputs and outputs
3455"""""""""""""""""""""""""""
3456
3457Indirect output or input constraints can be specified by the "``*``" modifier
3458(which goes after the "``=``" in case of an output). This indicates that the asm
3459will write to or read from the contents of an *address* provided as an input
3460argument. (Note that in this way, indirect outputs act more like an *input* than
3461an output: just like an input, they consume an argument of the call expression,
3462rather than producing a return value. An indirect output constraint is an
3463"output" only in that the asm is expected to write to the contents of the input
3464memory location, instead of just read from it).
3465
3466This is most typically used for memory constraint, e.g. "``=*m``", to pass the
3467address of a variable as a value.
3468
3469It is also possible to use an indirect *register* constraint, but only on output
3470(e.g. "``=*r``"). This will cause LLVM to allocate a register for an output
3471value normally, and then, separately emit a store to the address provided as
3472input, after the provided inline asm. (It's not clear what value this
3473functionality provides, compared to writing the store explicitly after the asm
3474statement, and it can only produce worse code, since it bypasses many
3475optimization passes. I would recommend not using it.)
3476
3477
3478Clobber constraints
3479"""""""""""""""""""
3480
3481A clobber constraint is indicated by a "``~``" prefix. A clobber does not
3482consume an input operand, nor generate an output. Clobbers cannot use any of the
3483general constraint code letters -- they may use only explicit register
3484constraints, e.g. "``~{eax}``". The one exception is that a clobber string of
3485"``~{memory}``" indicates that the assembly writes to arbitrary undeclared
3486memory locations -- not only the memory pointed to by a declared indirect
3487output.
3488
Peter Zotov00257232016-08-30 10:48:31 +00003489Note that clobbering named registers that are also present in output
3490constraints is not legal.
3491
James Y Knightbc832ed2015-07-08 18:08:36 +00003492
3493Constraint Codes
3494""""""""""""""""
3495After a potential prefix comes constraint code, or codes.
3496
3497A Constraint Code is either a single letter (e.g. "``r``"), a "``^``" character
3498followed by two letters (e.g. "``^wc``"), or "``{``" register-name "``}``"
3499(e.g. "``{eax}``").
3500
3501The one and two letter constraint codes are typically chosen to be the same as
3502GCC's constraint codes.
3503
3504A single constraint may include one or more than constraint code in it, leaving
3505it up to LLVM to choose which one to use. This is included mainly for
3506compatibility with the translation of GCC inline asm coming from clang.
3507
3508There are two ways to specify alternatives, and either or both may be used in an
3509inline asm constraint list:
3510
35111) Append the codes to each other, making a constraint code set. E.g. "``im``"
3512 or "``{eax}m``". This means "choose any of the options in the set". The
3513 choice of constraint is made independently for each constraint in the
3514 constraint list.
3515
35162) Use "``|``" between constraint code sets, creating alternatives. Every
3517 constraint in the constraint list must have the same number of alternative
3518 sets. With this syntax, the same alternative in *all* of the items in the
3519 constraint list will be chosen together.
3520
3521Putting those together, you might have a two operand constraint string like
3522``"rm|r,ri|rm"``. This indicates that if operand 0 is ``r`` or ``m``, then
3523operand 1 may be one of ``r`` or ``i``. If operand 0 is ``r``, then operand 1
3524may be one of ``r`` or ``m``. But, operand 0 and 1 cannot both be of type m.
3525
3526However, the use of either of the alternatives features is *NOT* recommended, as
3527LLVM is not able to make an intelligent choice about which one to use. (At the
3528point it currently needs to choose, not enough information is available to do so
3529in a smart way.) Thus, it simply tries to make a choice that's most likely to
3530compile, not one that will be optimal performance. (e.g., given "``rm``", it'll
3531always choose to use memory, not registers). And, if given multiple registers,
3532or multiple register classes, it will simply choose the first one. (In fact, it
3533doesn't currently even ensure explicitly specified physical registers are
3534unique, so specifying multiple physical registers as alternatives, like
3535``{r11}{r12},{r11}{r12}``, will assign r11 to both operands, not at all what was
3536intended.)
3537
3538Supported Constraint Code List
3539""""""""""""""""""""""""""""""
3540
3541The constraint codes are, in general, expected to behave the same way they do in
3542GCC. LLVM's support is often implemented on an 'as-needed' basis, to support C
3543inline asm code which was supported by GCC. A mismatch in behavior between LLVM
3544and GCC likely indicates a bug in LLVM.
3545
3546Some constraint codes are typically supported by all targets:
3547
3548- ``r``: A register in the target's general purpose register class.
3549- ``m``: A memory address operand. It is target-specific what addressing modes
3550 are supported, typical examples are register, or register + register offset,
3551 or register + immediate offset (of some target-specific size).
3552- ``i``: An integer constant (of target-specific width). Allows either a simple
3553 immediate, or a relocatable value.
3554- ``n``: An integer constant -- *not* including relocatable values.
3555- ``s``: An integer constant, but allowing *only* relocatable values.
3556- ``X``: Allows an operand of any kind, no constraint whatsoever. Typically
3557 useful to pass a label for an asm branch or call.
3558
3559 .. FIXME: but that surely isn't actually okay to jump out of an asm
3560 block without telling llvm about the control transfer???)
3561
3562- ``{register-name}``: Requires exactly the named physical register.
3563
3564Other constraints are target-specific:
3565
3566AArch64:
3567
3568- ``z``: An immediate integer 0. Outputs ``WZR`` or ``XZR``, as appropriate.
3569- ``I``: An immediate integer valid for an ``ADD`` or ``SUB`` instruction,
3570 i.e. 0 to 4095 with optional shift by 12.
3571- ``J``: An immediate integer that, when negated, is valid for an ``ADD`` or
3572 ``SUB`` instruction, i.e. -1 to -4095 with optional left shift by 12.
3573- ``K``: An immediate integer that is valid for the 'bitmask immediate 32' of a
3574 logical instruction like ``AND``, ``EOR``, or ``ORR`` with a 32-bit register.
3575- ``L``: An immediate integer that is valid for the 'bitmask immediate 64' of a
3576 logical instruction like ``AND``, ``EOR``, or ``ORR`` with a 64-bit register.
3577- ``M``: An immediate integer for use with the ``MOV`` assembly alias on a
3578 32-bit register. This is a superset of ``K``: in addition to the bitmask
3579 immediate, also allows immediate integers which can be loaded with a single
3580 ``MOVZ`` or ``MOVL`` instruction.
3581- ``N``: An immediate integer for use with the ``MOV`` assembly alias on a
3582 64-bit register. This is a superset of ``L``.
3583- ``Q``: Memory address operand must be in a single register (no
3584 offsets). (However, LLVM currently does this for the ``m`` constraint as
3585 well.)
3586- ``r``: A 32 or 64-bit integer register (W* or X*).
3587- ``w``: A 32, 64, or 128-bit floating-point/SIMD register.
3588- ``x``: A lower 128-bit floating-point/SIMD register (``V0`` to ``V15``).
3589
3590AMDGPU:
3591
3592- ``r``: A 32 or 64-bit integer register.
3593- ``[0-9]v``: The 32-bit VGPR register, number 0-9.
3594- ``[0-9]s``: The 32-bit SGPR register, number 0-9.
3595
3596
3597All ARM modes:
3598
3599- ``Q``, ``Um``, ``Un``, ``Uq``, ``Us``, ``Ut``, ``Uv``, ``Uy``: Memory address
3600 operand. Treated the same as operand ``m``, at the moment.
3601
3602ARM and ARM's Thumb2 mode:
3603
3604- ``j``: An immediate integer between 0 and 65535 (valid for ``MOVW``)
3605- ``I``: An immediate integer valid for a data-processing instruction.
3606- ``J``: An immediate integer between -4095 and 4095.
3607- ``K``: An immediate integer whose bitwise inverse is valid for a
3608 data-processing instruction. (Can be used with template modifier "``B``" to
3609 print the inverted value).
3610- ``L``: An immediate integer whose negation is valid for a data-processing
3611 instruction. (Can be used with template modifier "``n``" to print the negated
3612 value).
3613- ``M``: A power of two or a integer between 0 and 32.
3614- ``N``: Invalid immediate constraint.
3615- ``O``: Invalid immediate constraint.
3616- ``r``: A general-purpose 32-bit integer register (``r0-r15``).
3617- ``l``: In Thumb2 mode, low 32-bit GPR registers (``r0-r7``). In ARM mode, same
3618 as ``r``.
3619- ``h``: In Thumb2 mode, a high 32-bit GPR register (``r8-r15``). In ARM mode,
3620 invalid.
3621- ``w``: A 32, 64, or 128-bit floating-point/SIMD register: ``s0-s31``,
3622 ``d0-d31``, or ``q0-q15``.
3623- ``x``: A 32, 64, or 128-bit floating-point/SIMD register: ``s0-s15``,
3624 ``d0-d7``, or ``q0-q3``.
3625- ``t``: A floating-point/SIMD register, only supports 32-bit values:
3626 ``s0-s31``.
3627
3628ARM's Thumb1 mode:
3629
3630- ``I``: An immediate integer between 0 and 255.
3631- ``J``: An immediate integer between -255 and -1.
3632- ``K``: An immediate integer between 0 and 255, with optional left-shift by
3633 some amount.
3634- ``L``: An immediate integer between -7 and 7.
3635- ``M``: An immediate integer which is a multiple of 4 between 0 and 1020.
3636- ``N``: An immediate integer between 0 and 31.
3637- ``O``: An immediate integer which is a multiple of 4 between -508 and 508.
3638- ``r``: A low 32-bit GPR register (``r0-r7``).
3639- ``l``: A low 32-bit GPR register (``r0-r7``).
3640- ``h``: A high GPR register (``r0-r7``).
3641- ``w``: A 32, 64, or 128-bit floating-point/SIMD register: ``s0-s31``,
3642 ``d0-d31``, or ``q0-q15``.
3643- ``x``: A 32, 64, or 128-bit floating-point/SIMD register: ``s0-s15``,
3644 ``d0-d7``, or ``q0-q3``.
3645- ``t``: A floating-point/SIMD register, only supports 32-bit values:
3646 ``s0-s31``.
3647
3648
3649Hexagon:
3650
3651- ``o``, ``v``: A memory address operand, treated the same as constraint ``m``,
3652 at the moment.
3653- ``r``: A 32 or 64-bit register.
3654
3655MSP430:
3656
3657- ``r``: An 8 or 16-bit register.
3658
3659MIPS:
3660
3661- ``I``: An immediate signed 16-bit integer.
3662- ``J``: An immediate integer zero.
3663- ``K``: An immediate unsigned 16-bit integer.
3664- ``L``: An immediate 32-bit integer, where the lower 16 bits are 0.
3665- ``N``: An immediate integer between -65535 and -1.
3666- ``O``: An immediate signed 15-bit integer.
3667- ``P``: An immediate integer between 1 and 65535.
3668- ``m``: A memory address operand. In MIPS-SE mode, allows a base address
3669 register plus 16-bit immediate offset. In MIPS mode, just a base register.
3670- ``R``: A memory address operand. In MIPS-SE mode, allows a base address
3671 register plus a 9-bit signed offset. In MIPS mode, the same as constraint
3672 ``m``.
3673- ``ZC``: A memory address operand, suitable for use in a ``pref``, ``ll``, or
3674 ``sc`` instruction on the given subtarget (details vary).
3675- ``r``, ``d``, ``y``: A 32 or 64-bit GPR register.
3676- ``f``: A 32 or 64-bit FPU register (``F0-F31``), or a 128-bit MSA register
Daniel Sanders3745e022015-07-13 09:24:21 +00003677 (``W0-W31``). In the case of MSA registers, it is recommended to use the ``w``
3678 argument modifier for compatibility with GCC.
James Y Knightbc832ed2015-07-08 18:08:36 +00003679- ``c``: A 32-bit or 64-bit GPR register suitable for indirect jump (always
3680 ``25``).
3681- ``l``: The ``lo`` register, 32 or 64-bit.
3682- ``x``: Invalid.
3683
3684NVPTX:
3685
3686- ``b``: A 1-bit integer register.
3687- ``c`` or ``h``: A 16-bit integer register.
3688- ``r``: A 32-bit integer register.
3689- ``l`` or ``N``: A 64-bit integer register.
3690- ``f``: A 32-bit float register.
3691- ``d``: A 64-bit float register.
3692
3693
3694PowerPC:
3695
3696- ``I``: An immediate signed 16-bit integer.
3697- ``J``: An immediate unsigned 16-bit integer, shifted left 16 bits.
3698- ``K``: An immediate unsigned 16-bit integer.
3699- ``L``: An immediate signed 16-bit integer, shifted left 16 bits.
3700- ``M``: An immediate integer greater than 31.
3701- ``N``: An immediate integer that is an exact power of 2.
3702- ``O``: The immediate integer constant 0.
3703- ``P``: An immediate integer constant whose negation is a signed 16-bit
3704 constant.
3705- ``es``, ``o``, ``Q``, ``Z``, ``Zy``: A memory address operand, currently
3706 treated the same as ``m``.
3707- ``r``: A 32 or 64-bit integer register.
3708- ``b``: A 32 or 64-bit integer register, excluding ``R0`` (that is:
3709 ``R1-R31``).
3710- ``f``: A 32 or 64-bit float register (``F0-F31``), or when QPX is enabled, a
3711 128 or 256-bit QPX register (``Q0-Q31``; aliases the ``F`` registers).
3712- ``v``: For ``4 x f32`` or ``4 x f64`` types, when QPX is enabled, a
3713 128 or 256-bit QPX register (``Q0-Q31``), otherwise a 128-bit
3714 altivec vector register (``V0-V31``).
3715
3716 .. FIXME: is this a bug that v accepts QPX registers? I think this
3717 is supposed to only use the altivec vector registers?
3718
3719- ``y``: Condition register (``CR0-CR7``).
3720- ``wc``: An individual CR bit in a CR register.
3721- ``wa``, ``wd``, ``wf``: Any 128-bit VSX vector register, from the full VSX
3722 register set (overlapping both the floating-point and vector register files).
3723- ``ws``: A 32 or 64-bit floating point register, from the full VSX register
3724 set.
3725
3726Sparc:
3727
3728- ``I``: An immediate 13-bit signed integer.
3729- ``r``: A 32-bit integer register.
James Y Knightd4e1b002017-05-12 15:59:10 +00003730- ``f``: Any floating-point register on SparcV8, or a floating point
3731 register in the "low" half of the registers on SparcV9.
3732- ``e``: Any floating point register. (Same as ``f`` on SparcV8.)
James Y Knightbc832ed2015-07-08 18:08:36 +00003733
3734SystemZ:
3735
3736- ``I``: An immediate unsigned 8-bit integer.
3737- ``J``: An immediate unsigned 12-bit integer.
3738- ``K``: An immediate signed 16-bit integer.
3739- ``L``: An immediate signed 20-bit integer.
3740- ``M``: An immediate integer 0x7fffffff.
Ulrich Weiganddaae87aa2016-06-13 14:24:05 +00003741- ``Q``: A memory address operand with a base address and a 12-bit immediate
3742 unsigned displacement.
3743- ``R``: A memory address operand with a base address, a 12-bit immediate
3744 unsigned displacement, and an index register.
3745- ``S``: A memory address operand with a base address and a 20-bit immediate
3746 signed displacement.
3747- ``T``: A memory address operand with a base address, a 20-bit immediate
3748 signed displacement, and an index register.
James Y Knightbc832ed2015-07-08 18:08:36 +00003749- ``r`` or ``d``: A 32, 64, or 128-bit integer register.
3750- ``a``: A 32, 64, or 128-bit integer address register (excludes R0, which in an
3751 address context evaluates as zero).
3752- ``h``: A 32-bit value in the high part of a 64bit data register
3753 (LLVM-specific)
3754- ``f``: A 32, 64, or 128-bit floating point register.
3755
3756X86:
3757
3758- ``I``: An immediate integer between 0 and 31.
3759- ``J``: An immediate integer between 0 and 64.
3760- ``K``: An immediate signed 8-bit integer.
3761- ``L``: An immediate integer, 0xff or 0xffff or (in 64-bit mode only)
3762 0xffffffff.
3763- ``M``: An immediate integer between 0 and 3.
3764- ``N``: An immediate unsigned 8-bit integer.
3765- ``O``: An immediate integer between 0 and 127.
3766- ``e``: An immediate 32-bit signed integer.
3767- ``Z``: An immediate 32-bit unsigned integer.
3768- ``o``, ``v``: Treated the same as ``m``, at the moment.
3769- ``q``: An 8, 16, 32, or 64-bit register which can be accessed as an 8-bit
3770 ``l`` integer register. On X86-32, this is the ``a``, ``b``, ``c``, and ``d``
3771 registers, and on X86-64, it is all of the integer registers.
3772- ``Q``: An 8, 16, 32, or 64-bit register which can be accessed as an 8-bit
3773 ``h`` integer register. This is the ``a``, ``b``, ``c``, and ``d`` registers.
3774- ``r`` or ``l``: An 8, 16, 32, or 64-bit integer register.
3775- ``R``: An 8, 16, 32, or 64-bit "legacy" integer register -- one which has
3776 existed since i386, and can be accessed without the REX prefix.
3777- ``f``: A 32, 64, or 80-bit '387 FPU stack pseudo-register.
3778- ``y``: A 64-bit MMX register, if MMX is enabled.
3779- ``x``: If SSE is enabled: a 32 or 64-bit scalar operand, or 128-bit vector
3780 operand in a SSE register. If AVX is also enabled, can also be a 256-bit
3781 vector operand in an AVX register. If AVX-512 is also enabled, can also be a
3782 512-bit vector operand in an AVX512 register, Otherwise, an error.
3783- ``Y``: The same as ``x``, if *SSE2* is enabled, otherwise an error.
3784- ``A``: Special case: allocates EAX first, then EDX, for a single operand (in
3785 32-bit mode, a 64-bit integer operand will get split into two registers). It
3786 is not recommended to use this constraint, as in 64-bit mode, the 64-bit
3787 operand will get allocated only to RAX -- if two 32-bit operands are needed,
3788 you're better off splitting it yourself, before passing it to the asm
3789 statement.
3790
3791XCore:
3792
3793- ``r``: A 32-bit integer register.
3794
3795
3796.. _inline-asm-modifiers:
3797
3798Asm template argument modifiers
3799^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3800
3801In the asm template string, modifiers can be used on the operand reference, like
3802"``${0:n}``".
3803
3804The modifiers are, in general, expected to behave the same way they do in
3805GCC. LLVM's support is often implemented on an 'as-needed' basis, to support C
3806inline asm code which was supported by GCC. A mismatch in behavior between LLVM
3807and GCC likely indicates a bug in LLVM.
3808
3809Target-independent:
3810
Sean Silvaa1190322015-08-06 22:56:48 +00003811- ``c``: Print an immediate integer constant unadorned, without
James Y Knightbc832ed2015-07-08 18:08:36 +00003812 the target-specific immediate punctuation (e.g. no ``$`` prefix).
3813- ``n``: Negate and print immediate integer constant unadorned, without the
3814 target-specific immediate punctuation (e.g. no ``$`` prefix).
3815- ``l``: Print as an unadorned label, without the target-specific label
3816 punctuation (e.g. no ``$`` prefix).
3817
3818AArch64:
3819
3820- ``w``: Print a GPR register with a ``w*`` name instead of ``x*`` name. E.g.,
3821 instead of ``x30``, print ``w30``.
3822- ``x``: Print a GPR register with a ``x*`` name. (this is the default, anyhow).
3823- ``b``, ``h``, ``s``, ``d``, ``q``: Print a floating-point/SIMD register with a
3824 ``b*``, ``h*``, ``s*``, ``d*``, or ``q*`` name, rather than the default of
3825 ``v*``.
3826
3827AMDGPU:
3828
3829- ``r``: No effect.
3830
3831ARM:
3832
3833- ``a``: Print an operand as an address (with ``[`` and ``]`` surrounding a
3834 register).
3835- ``P``: No effect.
3836- ``q``: No effect.
3837- ``y``: Print a VFP single-precision register as an indexed double (e.g. print
3838 as ``d4[1]`` instead of ``s9``)
3839- ``B``: Bitwise invert and print an immediate integer constant without ``#``
3840 prefix.
3841- ``L``: Print the low 16-bits of an immediate integer constant.
3842- ``M``: Print as a register set suitable for ldm/stm. Also prints *all*
3843 register operands subsequent to the specified one (!), so use carefully.
3844- ``Q``: Print the low-order register of a register-pair, or the low-order
3845 register of a two-register operand.
3846- ``R``: Print the high-order register of a register-pair, or the high-order
3847 register of a two-register operand.
3848- ``H``: Print the second register of a register-pair. (On a big-endian system,
3849 ``H`` is equivalent to ``Q``, and on little-endian system, ``H`` is equivalent
3850 to ``R``.)
3851
3852 .. FIXME: H doesn't currently support printing the second register
3853 of a two-register operand.
3854
3855- ``e``: Print the low doubleword register of a NEON quad register.
3856- ``f``: Print the high doubleword register of a NEON quad register.
3857- ``m``: Print the base register of a memory operand without the ``[`` and ``]``
3858 adornment.
3859
3860Hexagon:
3861
3862- ``L``: Print the second register of a two-register operand. Requires that it
3863 has been allocated consecutively to the first.
3864
3865 .. FIXME: why is it restricted to consecutive ones? And there's
3866 nothing that ensures that happens, is there?
3867
3868- ``I``: Print the letter 'i' if the operand is an integer constant, otherwise
3869 nothing. Used to print 'addi' vs 'add' instructions.
3870
3871MSP430:
3872
3873No additional modifiers.
3874
3875MIPS:
3876
3877- ``X``: Print an immediate integer as hexadecimal
3878- ``x``: Print the low 16 bits of an immediate integer as hexadecimal.
3879- ``d``: Print an immediate integer as decimal.
3880- ``m``: Subtract one and print an immediate integer as decimal.
3881- ``z``: Print $0 if an immediate zero, otherwise print normally.
3882- ``L``: Print the low-order register of a two-register operand, or prints the
3883 address of the low-order word of a double-word memory operand.
3884
3885 .. FIXME: L seems to be missing memory operand support.
3886
3887- ``M``: Print the high-order register of a two-register operand, or prints the
3888 address of the high-order word of a double-word memory operand.
3889
3890 .. FIXME: M seems to be missing memory operand support.
3891
3892- ``D``: Print the second register of a two-register operand, or prints the
3893 second word of a double-word memory operand. (On a big-endian system, ``D`` is
3894 equivalent to ``L``, and on little-endian system, ``D`` is equivalent to
3895 ``M``.)
Daniel Sanders3745e022015-07-13 09:24:21 +00003896- ``w``: No effect. Provided for compatibility with GCC which requires this
3897 modifier in order to print MSA registers (``W0-W31``) with the ``f``
3898 constraint.
James Y Knightbc832ed2015-07-08 18:08:36 +00003899
3900NVPTX:
3901
3902- ``r``: No effect.
3903
3904PowerPC:
3905
3906- ``L``: Print the second register of a two-register operand. Requires that it
3907 has been allocated consecutively to the first.
3908
3909 .. FIXME: why is it restricted to consecutive ones? And there's
3910 nothing that ensures that happens, is there?
3911
3912- ``I``: Print the letter 'i' if the operand is an integer constant, otherwise
3913 nothing. Used to print 'addi' vs 'add' instructions.
3914- ``y``: For a memory operand, prints formatter for a two-register X-form
3915 instruction. (Currently always prints ``r0,OPERAND``).
3916- ``U``: Prints 'u' if the memory operand is an update form, and nothing
3917 otherwise. (NOTE: LLVM does not support update form, so this will currently
3918 always print nothing)
3919- ``X``: Prints 'x' if the memory operand is an indexed form. (NOTE: LLVM does
3920 not support indexed form, so this will currently always print nothing)
3921
3922Sparc:
3923
3924- ``r``: No effect.
3925
3926SystemZ:
3927
3928SystemZ implements only ``n``, and does *not* support any of the other
3929target-independent modifiers.
3930
3931X86:
3932
3933- ``c``: Print an unadorned integer or symbol name. (The latter is
3934 target-specific behavior for this typically target-independent modifier).
3935- ``A``: Print a register name with a '``*``' before it.
3936- ``b``: Print an 8-bit register name (e.g. ``al``); do nothing on a memory
3937 operand.
3938- ``h``: Print the upper 8-bit register name (e.g. ``ah``); do nothing on a
3939 memory operand.
3940- ``w``: Print the 16-bit register name (e.g. ``ax``); do nothing on a memory
3941 operand.
3942- ``k``: Print the 32-bit register name (e.g. ``eax``); do nothing on a memory
3943 operand.
3944- ``q``: Print the 64-bit register name (e.g. ``rax``), if 64-bit registers are
3945 available, otherwise the 32-bit register name; do nothing on a memory operand.
3946- ``n``: Negate and print an unadorned integer, or, for operands other than an
3947 immediate integer (e.g. a relocatable symbol expression), print a '-' before
3948 the operand. (The behavior for relocatable symbol expressions is a
3949 target-specific behavior for this typically target-independent modifier)
3950- ``H``: Print a memory reference with additional offset +8.
3951- ``P``: Print a memory reference or operand for use as the argument of a call
3952 instruction. (E.g. omit ``(rip)``, even though it's PC-relative.)
3953
3954XCore:
3955
3956No additional modifiers.
3957
3958
Sean Silvab084af42012-12-07 10:36:55 +00003959Inline Asm Metadata
3960^^^^^^^^^^^^^^^^^^^
3961
3962The call instructions that wrap inline asm nodes may have a
3963"``!srcloc``" MDNode attached to it that contains a list of constant
3964integers. If present, the code generator will use the integer as the
3965location cookie value when report errors through the ``LLVMContext``
3966error reporting mechanisms. This allows a front-end to correlate backend
3967errors that occur with inline asm back to the source code that produced
3968it. For example:
3969
3970.. code-block:: llvm
3971
3972 call void asm sideeffect "something bad", ""(), !srcloc !42
3973 ...
3974 !42 = !{ i32 1234567 }
3975
3976It is up to the front-end to make sense of the magic numbers it places
3977in the IR. If the MDNode contains multiple constants, the code generator
3978will use the one that corresponds to the line of the asm that the error
3979occurs on.
3980
3981.. _metadata:
3982
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00003983Metadata
3984========
Sean Silvab084af42012-12-07 10:36:55 +00003985
3986LLVM IR allows metadata to be attached to instructions in the program
3987that can convey extra information about the code to the optimizers and
3988code generator. One example application of metadata is source-level
3989debug information. There are two metadata primitives: strings and nodes.
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00003990
Sean Silvaa1190322015-08-06 22:56:48 +00003991Metadata does not have a type, and is not a value. If referenced from a
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00003992``call`` instruction, it uses the ``metadata`` type.
3993
3994All metadata are identified in syntax by a exclamation point ('``!``').
3995
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00003996.. _metadata-string:
3997
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00003998Metadata Nodes and Metadata Strings
3999-----------------------------------
Sean Silvab084af42012-12-07 10:36:55 +00004000
4001A metadata string is a string surrounded by double quotes. It can
4002contain any character by escaping non-printable characters with
4003"``\xx``" where "``xx``" is the two digit hex code. For example:
4004"``!"test\00"``".
4005
4006Metadata nodes are represented with notation similar to structure
4007constants (a comma separated list of elements, surrounded by braces and
4008preceded by an exclamation point). Metadata nodes can have any values as
4009their operand. For example:
4010
4011.. code-block:: llvm
4012
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00004013 !{ !"test\00", i32 10}
Sean Silvab084af42012-12-07 10:36:55 +00004014
Duncan P. N. Exon Smith090a19b2015-01-08 22:38:29 +00004015Metadata nodes that aren't uniqued use the ``distinct`` keyword. For example:
4016
Renato Golin124f2592016-07-20 12:16:38 +00004017.. code-block:: text
Duncan P. N. Exon Smith090a19b2015-01-08 22:38:29 +00004018
4019 !0 = distinct !{!"test\00", i32 10}
4020
Duncan P. N. Exon Smith99010342015-01-08 23:50:26 +00004021``distinct`` nodes are useful when nodes shouldn't be merged based on their
Sean Silvaa1190322015-08-06 22:56:48 +00004022content. They can also occur when transformations cause uniquing collisions
Duncan P. N. Exon Smith99010342015-01-08 23:50:26 +00004023when metadata operands change.
4024
Sean Silvab084af42012-12-07 10:36:55 +00004025A :ref:`named metadata <namedmetadatastructure>` is a collection of
4026metadata nodes, which can be looked up in the module symbol table. For
4027example:
4028
4029.. code-block:: llvm
4030
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00004031 !foo = !{!4, !3}
Sean Silvab084af42012-12-07 10:36:55 +00004032
Adrian Prantl1b842da2017-07-28 20:44:29 +00004033Metadata can be used as function arguments. Here the ``llvm.dbg.value``
4034intrinsic is using three metadata arguments:
Sean Silvab084af42012-12-07 10:36:55 +00004035
4036.. code-block:: llvm
4037
Adrian Prantlabe04752017-07-28 20:21:02 +00004038 call void @llvm.dbg.value(metadata !24, metadata !25, metadata !26)
Sean Silvab084af42012-12-07 10:36:55 +00004039
Peter Collingbourne50108682015-11-06 02:41:02 +00004040Metadata can be attached to an instruction. Here metadata ``!21`` is attached
4041to the ``add`` instruction using the ``!dbg`` identifier:
Sean Silvab084af42012-12-07 10:36:55 +00004042
4043.. code-block:: llvm
4044
4045 %indvar.next = add i64 %indvar, 1, !dbg !21
4046
Peter Collingbourne7b5b7c72017-01-25 21:50:14 +00004047Metadata can also be attached to a function or a global variable. Here metadata
4048``!22`` is attached to the ``f1`` and ``f2 functions, and the globals ``g1``
4049and ``g2`` using the ``!dbg`` identifier:
Peter Collingbourne50108682015-11-06 02:41:02 +00004050
4051.. code-block:: llvm
4052
Peter Collingbourne7b5b7c72017-01-25 21:50:14 +00004053 declare !dbg !22 void @f1()
4054 define void @f2() !dbg !22 {
Peter Collingbourne50108682015-11-06 02:41:02 +00004055 ret void
4056 }
4057
Peter Collingbourne7b5b7c72017-01-25 21:50:14 +00004058 @g1 = global i32 0, !dbg !22
4059 @g2 = external global i32, !dbg !22
4060
4061A transformation is required to drop any metadata attachment that it does not
4062know or know it can't preserve. Currently there is an exception for metadata
4063attachment to globals for ``!type`` and ``!absolute_symbol`` which can't be
4064unconditionally dropped unless the global is itself deleted.
4065
4066Metadata attached to a module using named metadata may not be dropped, with
4067the exception of debug metadata (named metadata with the name ``!llvm.dbg.*``).
4068
Sean Silvab084af42012-12-07 10:36:55 +00004069More information about specific metadata nodes recognized by the
4070optimizers and code generator is found below.
4071
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004072.. _specialized-metadata:
4073
Duncan P. N. Exon Smith6a484832015-01-13 21:10:44 +00004074Specialized Metadata Nodes
4075^^^^^^^^^^^^^^^^^^^^^^^^^^
4076
4077Specialized metadata nodes are custom data structures in metadata (as opposed
Sean Silvaa1190322015-08-06 22:56:48 +00004078to generic tuples). Their fields are labelled, and can be specified in any
Duncan P. N. Exon Smith6a484832015-01-13 21:10:44 +00004079order.
4080
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004081These aren't inherently debug info centric, but currently all the specialized
4082metadata nodes are related to debug info.
4083
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004084.. _DICompileUnit:
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004085
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004086DICompileUnit
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004087"""""""""""""
4088
Sean Silvaa1190322015-08-06 22:56:48 +00004089``DICompileUnit`` nodes represent a compile unit. The ``enums:``,
Adrian Prantl6c2497f2017-06-12 23:59:43 +00004090``retainedTypes:``, ``globals:``, ``imports:`` and ``macros:`` fields are tuples
4091containing the debug info to be emitted along with the compile unit, regardless
4092of code optimizations (some nodes are only emitted if there are references to
4093them from instructions). The ``debugInfoForProfiling:`` field is a boolean
4094indicating whether or not line-table discriminators are updated to provide
4095more-accurate debug info for profiling results.
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004096
Renato Golin124f2592016-07-20 12:16:38 +00004097.. code-block:: text
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004098
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004099 !0 = !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang",
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004100 isOptimized: true, flags: "-O2", runtimeVersion: 2,
Adrian Prantlb8089512016-04-01 00:16:49 +00004101 splitDebugFilename: "abc.debug", emissionKind: FullDebug,
Adrian Prantl6c2497f2017-06-12 23:59:43 +00004102 enums: !2, retainedTypes: !3, globals: !4, imports: !5,
4103 macros: !6, dwoId: 0x0abcd)
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004104
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004105Compile unit descriptors provide the root scope for objects declared in a
Adrian Prantl6c2497f2017-06-12 23:59:43 +00004106specific compilation unit. File descriptors are defined using this scope. These
4107descriptors are collected by a named metadata node ``!llvm.dbg.cu``. They keep
4108track of global variables, type information, and imported entities (declarations
4109and namespaces).
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004110
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004111.. _DIFile:
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004112
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004113DIFile
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004114""""""
4115
Sean Silvaa1190322015-08-06 22:56:48 +00004116``DIFile`` nodes represent files. The ``filename:`` can include slashes.
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004117
Aaron Ballmanb3c51512017-01-17 21:48:31 +00004118.. code-block:: none
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004119
Amjad Aboud7faeecc2016-12-25 10:12:09 +00004120 !0 = !DIFile(filename: "path/to/file", directory: "/path/to/dir",
4121 checksumkind: CSK_MD5,
4122 checksum: "000102030405060708090a0b0c0d0e0f")
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004123
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004124Files are sometimes used in ``scope:`` fields, and are the only valid target
4125for ``file:`` fields.
Amjad Aboud7faeecc2016-12-25 10:12:09 +00004126Valid values for ``checksumkind:`` field are: {CSK_None, CSK_MD5, CSK_SHA1}
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004127
Michael Kuperstein605308a2015-05-14 10:58:59 +00004128.. _DIBasicType:
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004129
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004130DIBasicType
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004131"""""""""""
4132
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004133``DIBasicType`` nodes represent primitive types, such as ``int``, ``bool`` and
Sean Silvaa1190322015-08-06 22:56:48 +00004134``float``. ``tag:`` defaults to ``DW_TAG_base_type``.
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004135
Renato Golin124f2592016-07-20 12:16:38 +00004136.. code-block:: text
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004137
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004138 !0 = !DIBasicType(name: "unsigned char", size: 8, align: 8,
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004139 encoding: DW_ATE_unsigned_char)
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004140 !1 = !DIBasicType(tag: DW_TAG_unspecified_type, name: "decltype(nullptr)")
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004141
Sean Silvaa1190322015-08-06 22:56:48 +00004142The ``encoding:`` describes the details of the type. Usually it's one of the
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004143following:
4144
Renato Golin124f2592016-07-20 12:16:38 +00004145.. code-block:: text
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004146
4147 DW_ATE_address = 1
4148 DW_ATE_boolean = 2
4149 DW_ATE_float = 4
4150 DW_ATE_signed = 5
4151 DW_ATE_signed_char = 6
4152 DW_ATE_unsigned = 7
4153 DW_ATE_unsigned_char = 8
4154
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004155.. _DISubroutineType:
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004156
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004157DISubroutineType
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004158""""""""""""""""
4159
Sean Silvaa1190322015-08-06 22:56:48 +00004160``DISubroutineType`` nodes represent subroutine types. Their ``types:`` field
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004161refers to a tuple; the first operand is the return type, while the rest are the
Sean Silvaa1190322015-08-06 22:56:48 +00004162types of the formal arguments in order. If the first operand is ``null``, that
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004163represents a function with no return value (such as ``void foo() {}`` in C++).
4164
Renato Golin124f2592016-07-20 12:16:38 +00004165.. code-block:: text
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004166
4167 !0 = !BasicType(name: "int", size: 32, align: 32, DW_ATE_signed)
4168 !1 = !BasicType(name: "char", size: 8, align: 8, DW_ATE_signed_char)
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004169 !2 = !DISubroutineType(types: !{null, !0, !1}) ; void (int, char)
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004170
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004171.. _DIDerivedType:
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004172
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004173DIDerivedType
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004174"""""""""""""
4175
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004176``DIDerivedType`` nodes represent types derived from other types, such as
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004177qualified types.
4178
Renato Golin124f2592016-07-20 12:16:38 +00004179.. code-block:: text
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004180
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004181 !0 = !DIBasicType(name: "unsigned char", size: 8, align: 8,
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004182 encoding: DW_ATE_unsigned_char)
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004183 !1 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !0, size: 32,
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004184 align: 32)
4185
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004186The following ``tag:`` values are valid:
4187
Renato Golin124f2592016-07-20 12:16:38 +00004188.. code-block:: text
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004189
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004190 DW_TAG_member = 13
4191 DW_TAG_pointer_type = 15
4192 DW_TAG_reference_type = 16
4193 DW_TAG_typedef = 22
Duncan P. N. Exon Smitha3f3de12016-04-16 22:46:47 +00004194 DW_TAG_inheritance = 28
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004195 DW_TAG_ptr_to_member_type = 31
4196 DW_TAG_const_type = 38
Duncan P. N. Exon Smitha3f3de12016-04-16 22:46:47 +00004197 DW_TAG_friend = 42
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004198 DW_TAG_volatile_type = 53
4199 DW_TAG_restrict_type = 55
Victor Leschuke1156c22016-10-31 19:09:38 +00004200 DW_TAG_atomic_type = 71
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004201
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +00004202.. _DIDerivedTypeMember:
4203
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004204``DW_TAG_member`` is used to define a member of a :ref:`composite type
Duncan P. N. Exon Smith90990cd2016-04-17 00:45:00 +00004205<DICompositeType>`. The type of the member is the ``baseType:``. The
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +00004206``offset:`` is the member's bit offset. If the composite type has an ODR
4207``identifier:`` and does not set ``flags: DIFwdDecl``, then the member is
4208uniqued based only on its ``name:`` and ``scope:``.
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004209
Duncan P. N. Exon Smitha3f3de12016-04-16 22:46:47 +00004210``DW_TAG_inheritance`` and ``DW_TAG_friend`` are used in the ``elements:``
4211field of :ref:`composite types <DICompositeType>` to describe parents and
4212friends.
4213
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004214``DW_TAG_typedef`` is used to provide a name for the ``baseType:``.
4215
4216``DW_TAG_pointer_type``, ``DW_TAG_reference_type``, ``DW_TAG_const_type``,
Victor Leschuke1156c22016-10-31 19:09:38 +00004217``DW_TAG_volatile_type``, ``DW_TAG_restrict_type`` and ``DW_TAG_atomic_type``
4218are used to qualify the ``baseType:``.
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004219
4220Note that the ``void *`` type is expressed as a type derived from NULL.
4221
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004222.. _DICompositeType:
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004223
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004224DICompositeType
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004225"""""""""""""""
4226
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004227``DICompositeType`` nodes represent types composed of other types, like
Sean Silvaa1190322015-08-06 22:56:48 +00004228structures and unions. ``elements:`` points to a tuple of the composed types.
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004229
4230If the source language supports ODR, the ``identifier:`` field gives the unique
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +00004231identifier used for type merging between modules. When specified,
4232:ref:`subprogram declarations <DISubprogramDeclaration>` and :ref:`member
4233derived types <DIDerivedTypeMember>` that reference the ODR-type in their
4234``scope:`` change uniquing rules.
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004235
Duncan P. N. Exon Smith5ab2be02016-04-17 03:58:21 +00004236For a given ``identifier:``, there should only be a single composite type that
4237does not have ``flags: DIFlagFwdDecl`` set. LLVM tools that link modules
4238together will unique such definitions at parse time via the ``identifier:``
4239field, even if the nodes are ``distinct``.
4240
Renato Golin124f2592016-07-20 12:16:38 +00004241.. code-block:: text
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004242
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004243 !0 = !DIEnumerator(name: "SixKind", value: 7)
4244 !1 = !DIEnumerator(name: "SevenKind", value: 7)
4245 !2 = !DIEnumerator(name: "NegEightKind", value: -8)
4246 !3 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "Enum", file: !12,
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004247 line: 2, size: 32, align: 32, identifier: "_M4Enum",
4248 elements: !{!0, !1, !2})
4249
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004250The following ``tag:`` values are valid:
4251
Renato Golin124f2592016-07-20 12:16:38 +00004252.. code-block:: text
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004253
4254 DW_TAG_array_type = 1
4255 DW_TAG_class_type = 2
4256 DW_TAG_enumeration_type = 4
4257 DW_TAG_structure_type = 19
4258 DW_TAG_union_type = 23
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004259
4260For ``DW_TAG_array_type``, the ``elements:`` should be :ref:`subrange
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004261descriptors <DISubrange>`, each representing the range of subscripts at that
Sean Silvaa1190322015-08-06 22:56:48 +00004262level of indexing. The ``DIFlagVector`` flag to ``flags:`` indicates that an
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004263array type is a native packed vector.
4264
4265For ``DW_TAG_enumeration_type``, the ``elements:`` should be :ref:`enumerator
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004266descriptors <DIEnumerator>`, each representing the definition of an enumeration
Sean Silvaa1190322015-08-06 22:56:48 +00004267value for the set. All enumeration type descriptors are collected in the
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004268``enums:`` field of the :ref:`compile unit <DICompileUnit>`.
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004269
4270For ``DW_TAG_structure_type``, ``DW_TAG_class_type``, and
4271``DW_TAG_union_type``, the ``elements:`` should be :ref:`derived types
Duncan P. N. Exon Smitha3f3de12016-04-16 22:46:47 +00004272<DIDerivedType>` with ``tag: DW_TAG_member``, ``tag: DW_TAG_inheritance``, or
4273``tag: DW_TAG_friend``; or :ref:`subprograms <DISubprogram>` with
4274``isDefinition: false``.
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004275
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004276.. _DISubrange:
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004277
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004278DISubrange
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004279""""""""""
4280
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004281``DISubrange`` nodes are the elements for ``DW_TAG_array_type`` variants of
Sean Silvaa1190322015-08-06 22:56:48 +00004282:ref:`DICompositeType`. ``count: -1`` indicates an empty array.
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004283
4284.. code-block:: llvm
4285
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004286 !0 = !DISubrange(count: 5, lowerBound: 0) ; array counting from 0
4287 !1 = !DISubrange(count: 5, lowerBound: 1) ; array counting from 1
4288 !2 = !DISubrange(count: -1) ; empty array.
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004289
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004290.. _DIEnumerator:
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004291
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004292DIEnumerator
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004293""""""""""""
4294
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004295``DIEnumerator`` nodes are the elements for ``DW_TAG_enumeration_type``
4296variants of :ref:`DICompositeType`.
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004297
4298.. code-block:: llvm
4299
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004300 !0 = !DIEnumerator(name: "SixKind", value: 7)
4301 !1 = !DIEnumerator(name: "SevenKind", value: 7)
4302 !2 = !DIEnumerator(name: "NegEightKind", value: -8)
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004303
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004304DITemplateTypeParameter
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004305"""""""""""""""""""""""
4306
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004307``DITemplateTypeParameter`` nodes represent type parameters to generic source
Sean Silvaa1190322015-08-06 22:56:48 +00004308language constructs. They are used (optionally) in :ref:`DICompositeType` and
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004309:ref:`DISubprogram` ``templateParams:`` fields.
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004310
4311.. code-block:: llvm
4312
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004313 !0 = !DITemplateTypeParameter(name: "Ty", type: !1)
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004314
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004315DITemplateValueParameter
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004316""""""""""""""""""""""""
4317
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004318``DITemplateValueParameter`` nodes represent value parameters to generic source
Sean Silvaa1190322015-08-06 22:56:48 +00004319language constructs. ``tag:`` defaults to ``DW_TAG_template_value_parameter``,
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004320but if specified can also be set to ``DW_TAG_GNU_template_template_param`` or
Sean Silvaa1190322015-08-06 22:56:48 +00004321``DW_TAG_GNU_template_param_pack``. They are used (optionally) in
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004322:ref:`DICompositeType` and :ref:`DISubprogram` ``templateParams:`` fields.
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004323
4324.. code-block:: llvm
4325
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004326 !0 = !DITemplateValueParameter(name: "Ty", type: !1, value: i32 7)
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004327
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004328DINamespace
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004329"""""""""""
4330
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004331``DINamespace`` nodes represent namespaces in the source language.
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004332
4333.. code-block:: llvm
4334
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004335 !0 = !DINamespace(name: "myawesomeproject", scope: !1, file: !2, line: 7)
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004336
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004337DIGlobalVariable
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004338""""""""""""""""
4339
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004340``DIGlobalVariable`` nodes represent global variables in the source language.
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004341
4342.. code-block:: llvm
4343
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004344 !0 = !DIGlobalVariable(name: "foo", linkageName: "foo", scope: !1,
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004345 file: !2, line: 7, type: !3, isLocal: true,
4346 isDefinition: false, variable: i32* @foo,
4347 declaration: !4)
4348
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004349All global variables should be referenced by the `globals:` field of a
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004350:ref:`compile unit <DICompileUnit>`.
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004351
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004352.. _DISubprogram:
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004353
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004354DISubprogram
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004355""""""""""""
4356
Peter Collingbourne50108682015-11-06 02:41:02 +00004357``DISubprogram`` nodes represent functions from the source language. A
4358``DISubprogram`` may be attached to a function definition using ``!dbg``
4359metadata. The ``variables:`` field points at :ref:`variables <DILocalVariable>`
4360that must be retained, even if their IR counterparts are optimized out of
4361the IR. The ``type:`` field must point at an :ref:`DISubroutineType`.
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004362
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +00004363.. _DISubprogramDeclaration:
4364
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +00004365When ``isDefinition: false``, subprograms describe a declaration in the type
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +00004366tree as opposed to a definition of a function. If the scope is a composite
4367type with an ODR ``identifier:`` and that does not set ``flags: DIFwdDecl``,
4368then the subprogram declaration is uniqued based only on its ``linkageName:``
4369and ``scope:``.
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +00004370
Renato Golin124f2592016-07-20 12:16:38 +00004371.. code-block:: text
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004372
Peter Collingbourne50108682015-11-06 02:41:02 +00004373 define void @_Z3foov() !dbg !0 {
4374 ...
4375 }
4376
4377 !0 = distinct !DISubprogram(name: "foo", linkageName: "_Zfoov", scope: !1,
4378 file: !2, line: 7, type: !3, isLocal: true,
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +00004379 isDefinition: true, scopeLine: 8,
Peter Collingbourne50108682015-11-06 02:41:02 +00004380 containingType: !4,
4381 virtuality: DW_VIRTUALITY_pure_virtual,
4382 virtualIndex: 10, flags: DIFlagPrototyped,
Adrian Prantl6c2497f2017-06-12 23:59:43 +00004383 isOptimized: true, unit: !5, templateParams: !6,
4384 declaration: !7, variables: !8, thrownTypes: !9)
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004385
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004386.. _DILexicalBlock:
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004387
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004388DILexicalBlock
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004389""""""""""""""
4390
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004391``DILexicalBlock`` nodes describe nested blocks within a :ref:`subprogram
Bruce Mitchenere9ffb452015-09-12 01:17:08 +00004392<DISubprogram>`. The line number and column numbers are used to distinguish
Sean Silvaa1190322015-08-06 22:56:48 +00004393two lexical blocks at same depth. They are valid targets for ``scope:``
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004394fields.
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004395
Renato Golin124f2592016-07-20 12:16:38 +00004396.. code-block:: text
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004397
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004398 !0 = distinct !DILexicalBlock(scope: !1, file: !2, line: 7, column: 35)
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004399
4400Usually lexical blocks are ``distinct`` to prevent node merging based on
4401operands.
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004402
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004403.. _DILexicalBlockFile:
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004404
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004405DILexicalBlockFile
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004406""""""""""""""""""
4407
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004408``DILexicalBlockFile`` nodes are used to discriminate between sections of a
Sean Silvaa1190322015-08-06 22:56:48 +00004409:ref:`lexical block <DILexicalBlock>`. The ``file:`` field can be changed to
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004410indicate textual inclusion, or the ``discriminator:`` field can be used to
4411discriminate between control flow within a single block in the source language.
4412
4413.. code-block:: llvm
4414
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004415 !0 = !DILexicalBlock(scope: !3, file: !4, line: 7, column: 35)
4416 !1 = !DILexicalBlockFile(scope: !0, file: !4, discriminator: 0)
4417 !2 = !DILexicalBlockFile(scope: !0, file: !4, discriminator: 1)
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004418
Michael Kuperstein605308a2015-05-14 10:58:59 +00004419.. _DILocation:
4420
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004421DILocation
Duncan P. N. Exon Smith6a484832015-01-13 21:10:44 +00004422""""""""""
4423
Sean Silvaa1190322015-08-06 22:56:48 +00004424``DILocation`` nodes represent source debug locations. The ``scope:`` field is
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004425mandatory, and points at an :ref:`DILexicalBlockFile`, an
4426:ref:`DILexicalBlock`, or an :ref:`DISubprogram`.
Duncan P. N. Exon Smith6a484832015-01-13 21:10:44 +00004427
4428.. code-block:: llvm
4429
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004430 !0 = !DILocation(line: 2900, column: 42, scope: !1, inlinedAt: !2)
Duncan P. N. Exon Smith6a484832015-01-13 21:10:44 +00004431
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004432.. _DILocalVariable:
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004433
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004434DILocalVariable
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004435"""""""""""""""
4436
Sean Silvaa1190322015-08-06 22:56:48 +00004437``DILocalVariable`` nodes represent local variables in the source language. If
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +00004438the ``arg:`` field is set to non-zero, then this variable is a subprogram
4439parameter, and it will be included in the ``variables:`` field of its
4440:ref:`DISubprogram`.
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004441
Renato Golin124f2592016-07-20 12:16:38 +00004442.. code-block:: text
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004443
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +00004444 !0 = !DILocalVariable(name: "this", arg: 1, scope: !3, file: !2, line: 7,
4445 type: !3, flags: DIFlagArtificial)
4446 !1 = !DILocalVariable(name: "x", arg: 2, scope: !4, file: !2, line: 7,
4447 type: !3)
4448 !2 = !DILocalVariable(name: "y", scope: !5, file: !2, line: 7, type: !3)
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004449
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004450DIExpression
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004451""""""""""""
4452
Adrian Prantlb44c7762017-03-22 18:01:01 +00004453``DIExpression`` nodes represent expressions that are inspired by the DWARF
4454expression language. They are used in :ref:`debug intrinsics<dbg_intrinsics>`
4455(such as ``llvm.dbg.declare`` and ``llvm.dbg.value``) to describe how the
4456referenced LLVM variable relates to the source language variable.
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004457
4458The current supported vocabulary is limited:
4459
Adrian Prantl6825fb62017-04-18 01:21:53 +00004460- ``DW_OP_deref`` dereferences the top of the expression stack.
Florian Hahnffc498d2017-06-14 13:14:38 +00004461- ``DW_OP_plus`` pops the last two entries from the expression stack, adds
4462 them together and appends the result to the expression stack.
4463- ``DW_OP_minus`` pops the last two entries from the expression stack, subtracts
4464 the last entry from the second last entry and appends the result to the
4465 expression stack.
Florian Hahnc9c403c2017-06-13 16:54:44 +00004466- ``DW_OP_plus_uconst, 93`` adds ``93`` to the working expression.
Adrian Prantlb44c7762017-03-22 18:01:01 +00004467- ``DW_OP_LLVM_fragment, 16, 8`` specifies the offset and size (``16`` and ``8``
4468 here, respectively) of the variable fragment from the working expression. Note
4469 that contrary to DW_OP_bit_piece, the offset is describing the the location
4470 within the described source variable.
Konstantin Zhuravlyovf9b41cd2017-03-08 00:28:57 +00004471- ``DW_OP_swap`` swaps top two stack entries.
4472- ``DW_OP_xderef`` provides extended dereference mechanism. The entry at the top
4473 of the stack is treated as an address. The second stack entry is treated as an
4474 address space identifier.
Adrian Prantlb44c7762017-03-22 18:01:01 +00004475- ``DW_OP_stack_value`` marks a constant value.
4476
Adrian Prantl6825fb62017-04-18 01:21:53 +00004477DWARF specifies three kinds of simple location descriptions: Register, memory,
4478and implicit location descriptions. Register and memory location descriptions
4479describe the *location* of a source variable (in the sense that a debugger might
4480modify its value), whereas implicit locations describe merely the *value* of a
4481source variable. DIExpressions also follow this model: A DIExpression that
4482doesn't have a trailing ``DW_OP_stack_value`` will describe an *address* when
4483combined with a concrete location.
4484
4485.. code-block:: llvm
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004486
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004487 !0 = !DIExpression(DW_OP_deref)
Florian Hahnc9c403c2017-06-13 16:54:44 +00004488 !1 = !DIExpression(DW_OP_plus_uconst, 3)
Florian Hahnffc498d2017-06-14 13:14:38 +00004489 !1 = !DIExpression(DW_OP_constu, 3, DW_OP_plus)
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004490 !2 = !DIExpression(DW_OP_bit_piece, 3, 7)
Florian Hahnffc498d2017-06-14 13:14:38 +00004491 !3 = !DIExpression(DW_OP_deref, DW_OP_constu, 3, DW_OP_plus, DW_OP_LLVM_fragment, 3, 7)
Konstantin Zhuravlyovf9b41cd2017-03-08 00:28:57 +00004492 !4 = !DIExpression(DW_OP_constu, 2, DW_OP_swap, DW_OP_xderef)
Adrian Prantlb44c7762017-03-22 18:01:01 +00004493 !5 = !DIExpression(DW_OP_constu, 42, DW_OP_stack_value)
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004494
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004495DIObjCProperty
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004496""""""""""""""
4497
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004498``DIObjCProperty`` nodes represent Objective-C property nodes.
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004499
4500.. code-block:: llvm
4501
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004502 !3 = !DIObjCProperty(name: "foo", file: !1, line: 7, setter: "setFoo",
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004503 getter: "getFoo", attributes: 7, type: !2)
4504
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004505DIImportedEntity
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004506""""""""""""""""
4507
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004508``DIImportedEntity`` nodes represent entities (such as modules) imported into a
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004509compile unit.
4510
Renato Golin124f2592016-07-20 12:16:38 +00004511.. code-block:: text
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004512
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004513 !2 = !DIImportedEntity(tag: DW_TAG_imported_module, name: "foo", scope: !0,
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004514 entity: !1, line: 7)
4515
Amjad Abouda9bcf162015-12-10 12:56:35 +00004516DIMacro
4517"""""""
4518
4519``DIMacro`` nodes represent definition or undefinition of a macro identifiers.
4520The ``name:`` field is the macro identifier, followed by macro parameters when
Sylvestre Ledru7d540502016-07-02 19:28:40 +00004521defining a function-like macro, and the ``value`` field is the token-string
Amjad Abouda9bcf162015-12-10 12:56:35 +00004522used to expand the macro identifier.
4523
Renato Golin124f2592016-07-20 12:16:38 +00004524.. code-block:: text
Amjad Abouda9bcf162015-12-10 12:56:35 +00004525
4526 !2 = !DIMacro(macinfo: DW_MACINFO_define, line: 7, name: "foo(x)",
4527 value: "((x) + 1)")
4528 !3 = !DIMacro(macinfo: DW_MACINFO_undef, line: 30, name: "foo")
4529
4530DIMacroFile
4531"""""""""""
4532
4533``DIMacroFile`` nodes represent inclusion of source files.
4534The ``nodes:`` field is a list of ``DIMacro`` and ``DIMacroFile`` nodes that
4535appear in the included source file.
4536
Renato Golin124f2592016-07-20 12:16:38 +00004537.. code-block:: text
Amjad Abouda9bcf162015-12-10 12:56:35 +00004538
4539 !2 = !DIMacroFile(macinfo: DW_MACINFO_start_file, line: 7, file: !2,
4540 nodes: !3)
4541
Sean Silvab084af42012-12-07 10:36:55 +00004542'``tbaa``' Metadata
4543^^^^^^^^^^^^^^^^^^^
4544
4545In LLVM IR, memory does not have types, so LLVM's own type system is not
Sanjoy Dasa3ff9942017-02-13 23:14:03 +00004546suitable for doing type based alias analysis (TBAA). Instead, metadata is
4547added to the IR to describe a type system of a higher level language. This
4548can be used to implement C/C++ strict type aliasing rules, but it can also
4549be used to implement custom alias analysis behavior for other languages.
Sean Silvab084af42012-12-07 10:36:55 +00004550
Sanjoy Dasa3ff9942017-02-13 23:14:03 +00004551This description of LLVM's TBAA system is broken into two parts:
4552:ref:`Semantics<tbaa_node_semantics>` talks about high level issues, and
4553:ref:`Representation<tbaa_node_representation>` talks about the metadata
4554encoding of various entities.
Sean Silvab084af42012-12-07 10:36:55 +00004555
Sanjoy Dasa3ff9942017-02-13 23:14:03 +00004556It is always possible to trace any TBAA node to a "root" TBAA node (details
4557in the :ref:`Representation<tbaa_node_representation>` section). TBAA
4558nodes with different roots have an unknown aliasing relationship, and LLVM
4559conservatively infers ``MayAlias`` between them. The rules mentioned in
4560this section only pertain to TBAA nodes living under the same root.
Sean Silvab084af42012-12-07 10:36:55 +00004561
Sanjoy Dasa3ff9942017-02-13 23:14:03 +00004562.. _tbaa_node_semantics:
Sean Silvab084af42012-12-07 10:36:55 +00004563
Sanjoy Dasa3ff9942017-02-13 23:14:03 +00004564Semantics
4565"""""""""
Sean Silvab084af42012-12-07 10:36:55 +00004566
Sanjoy Dasa3ff9942017-02-13 23:14:03 +00004567The TBAA metadata system, referred to as "struct path TBAA" (not to be
4568confused with ``tbaa.struct``), consists of the following high level
4569concepts: *Type Descriptors*, further subdivided into scalar type
4570descriptors and struct type descriptors; and *Access Tags*.
Sean Silvab084af42012-12-07 10:36:55 +00004571
Sanjoy Dasa3ff9942017-02-13 23:14:03 +00004572**Type descriptors** describe the type system of the higher level language
4573being compiled. **Scalar type descriptors** describe types that do not
4574contain other types. Each scalar type has a parent type, which must also
4575be a scalar type or the TBAA root. Via this parent relation, scalar types
4576within a TBAA root form a tree. **Struct type descriptors** denote types
4577that contain a sequence of other type descriptors, at known offsets. These
4578contained type descriptors can either be struct type descriptors themselves
4579or scalar type descriptors.
4580
4581**Access tags** are metadata nodes attached to load and store instructions.
4582Access tags use type descriptors to describe the *location* being accessed
4583in terms of the type system of the higher level language. Access tags are
4584tuples consisting of a base type, an access type and an offset. The base
4585type is a scalar type descriptor or a struct type descriptor, the access
4586type is a scalar type descriptor, and the offset is a constant integer.
4587
4588The access tag ``(BaseTy, AccessTy, Offset)`` can describe one of two
4589things:
4590
4591 * If ``BaseTy`` is a struct type, the tag describes a memory access (load
4592 or store) of a value of type ``AccessTy`` contained in the struct type
4593 ``BaseTy`` at offset ``Offset``.
4594
4595 * If ``BaseTy`` is a scalar type, ``Offset`` must be 0 and ``BaseTy`` and
4596 ``AccessTy`` must be the same; and the access tag describes a scalar
4597 access with scalar type ``AccessTy``.
4598
4599We first define an ``ImmediateParent`` relation on ``(BaseTy, Offset)``
4600tuples this way:
4601
4602 * If ``BaseTy`` is a scalar type then ``ImmediateParent(BaseTy, 0)`` is
4603 ``(ParentTy, 0)`` where ``ParentTy`` is the parent of the scalar type as
4604 described in the TBAA metadata. ``ImmediateParent(BaseTy, Offset)`` is
4605 undefined if ``Offset`` is non-zero.
4606
4607 * If ``BaseTy`` is a struct type then ``ImmediateParent(BaseTy, Offset)``
4608 is ``(NewTy, NewOffset)`` where ``NewTy`` is the type contained in
4609 ``BaseTy`` at offset ``Offset`` and ``NewOffset`` is ``Offset`` adjusted
4610 to be relative within that inner type.
4611
4612A memory access with an access tag ``(BaseTy1, AccessTy1, Offset1)``
4613aliases a memory access with an access tag ``(BaseTy2, AccessTy2,
4614Offset2)`` if either ``(BaseTy1, Offset1)`` is reachable from ``(Base2,
4615Offset2)`` via the ``Parent`` relation or vice versa.
4616
4617As a concrete example, the type descriptor graph for the following program
4618
4619.. code-block:: c
4620
4621 struct Inner {
4622 int i; // offset 0
4623 float f; // offset 4
4624 };
4625
4626 struct Outer {
4627 float f; // offset 0
4628 double d; // offset 4
4629 struct Inner inner_a; // offset 12
4630 };
4631
4632 void f(struct Outer* outer, struct Inner* inner, float* f, int* i, char* c) {
4633 outer->f = 0; // tag0: (OuterStructTy, FloatScalarTy, 0)
4634 outer->inner_a.i = 0; // tag1: (OuterStructTy, IntScalarTy, 12)
4635 outer->inner_a.f = 0.0; // tag2: (OuterStructTy, IntScalarTy, 16)
4636 *f = 0.0; // tag3: (FloatScalarTy, FloatScalarTy, 0)
4637 }
4638
4639is (note that in C and C++, ``char`` can be used to access any arbitrary
4640type):
4641
4642.. code-block:: text
4643
4644 Root = "TBAA Root"
4645 CharScalarTy = ("char", Root, 0)
4646 FloatScalarTy = ("float", CharScalarTy, 0)
4647 DoubleScalarTy = ("double", CharScalarTy, 0)
4648 IntScalarTy = ("int", CharScalarTy, 0)
4649 InnerStructTy = {"Inner" (IntScalarTy, 0), (FloatScalarTy, 4)}
4650 OuterStructTy = {"Outer", (FloatScalarTy, 0), (DoubleScalarTy, 4),
4651 (InnerStructTy, 12)}
4652
4653
4654with (e.g.) ``ImmediateParent(OuterStructTy, 12)`` = ``(InnerStructTy,
46550)``, ``ImmediateParent(InnerStructTy, 0)`` = ``(IntScalarTy, 0)``, and
4656``ImmediateParent(IntScalarTy, 0)`` = ``(CharScalarTy, 0)``.
4657
4658.. _tbaa_node_representation:
4659
4660Representation
4661""""""""""""""
4662
4663The root node of a TBAA type hierarchy is an ``MDNode`` with 0 operands or
4664with exactly one ``MDString`` operand.
4665
4666Scalar type descriptors are represented as an ``MDNode`` s with two
4667operands. The first operand is an ``MDString`` denoting the name of the
4668struct type. LLVM does not assign meaning to the value of this operand, it
4669only cares about it being an ``MDString``. The second operand is an
4670``MDNode`` which points to the parent for said scalar type descriptor,
4671which is either another scalar type descriptor or the TBAA root. Scalar
4672type descriptors can have an optional third argument, but that must be the
4673constant integer zero.
4674
4675Struct type descriptors are represented as ``MDNode`` s with an odd number
4676of operands greater than 1. The first operand is an ``MDString`` denoting
4677the name of the struct type. Like in scalar type descriptors the actual
4678value of this name operand is irrelevant to LLVM. After the name operand,
4679the struct type descriptors have a sequence of alternating ``MDNode`` and
4680``ConstantInt`` operands. With N starting from 1, the 2N - 1 th operand,
4681an ``MDNode``, denotes a contained field, and the 2N th operand, a
4682``ConstantInt``, is the offset of the said contained field. The offsets
4683must be in non-decreasing order.
4684
4685Access tags are represented as ``MDNode`` s with either 3 or 4 operands.
4686The first operand is an ``MDNode`` pointing to the node representing the
4687base type. The second operand is an ``MDNode`` pointing to the node
4688representing the access type. The third operand is a ``ConstantInt`` that
4689states the offset of the access. If a fourth field is present, it must be
4690a ``ConstantInt`` valued at 0 or 1. If it is 1 then the access tag states
4691that the location being accessed is "constant" (meaning
Sean Silvab084af42012-12-07 10:36:55 +00004692``pointsToConstantMemory`` should return true; see `other useful
Sanjoy Dasa3ff9942017-02-13 23:14:03 +00004693AliasAnalysis methods <AliasAnalysis.html#OtherItfs>`_). The TBAA root of
4694the access type and the base type of an access tag must be the same, and
4695that is the TBAA root of the access tag.
Sean Silvab084af42012-12-07 10:36:55 +00004696
4697'``tbaa.struct``' Metadata
4698^^^^^^^^^^^^^^^^^^^^^^^^^^
4699
4700The :ref:`llvm.memcpy <int_memcpy>` is often used to implement
4701aggregate assignment operations in C and similar languages, however it
4702is defined to copy a contiguous region of memory, which is more than
4703strictly necessary for aggregate types which contain holes due to
4704padding. Also, it doesn't contain any TBAA information about the fields
4705of the aggregate.
4706
4707``!tbaa.struct`` metadata can describe which memory subregions in a
4708memcpy are padding and what the TBAA tags of the struct are.
4709
4710The current metadata format is very simple. ``!tbaa.struct`` metadata
4711nodes are a list of operands which are in conceptual groups of three.
4712For each group of three, the first operand gives the byte offset of a
4713field in bytes, the second gives its size in bytes, and the third gives
4714its tbaa tag. e.g.:
4715
4716.. code-block:: llvm
4717
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00004718 !4 = !{ i64 0, i64 4, !1, i64 8, i64 4, !2 }
Sean Silvab084af42012-12-07 10:36:55 +00004719
4720This describes a struct with two fields. The first is at offset 0 bytes
4721with size 4 bytes, and has tbaa tag !1. The second is at offset 8 bytes
4722and has size 4 bytes and has tbaa tag !2.
4723
4724Note that the fields need not be contiguous. In this example, there is a
47254 byte gap between the two fields. This gap represents padding which
4726does not carry useful data and need not be preserved.
4727
Hal Finkel94146652014-07-24 14:25:39 +00004728'``noalias``' and '``alias.scope``' Metadata
Dan Liewbafdcba2014-07-28 13:33:51 +00004729^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Hal Finkel94146652014-07-24 14:25:39 +00004730
4731``noalias`` and ``alias.scope`` metadata provide the ability to specify generic
4732noalias memory-access sets. This means that some collection of memory access
4733instructions (loads, stores, memory-accessing calls, etc.) that carry
4734``noalias`` metadata can specifically be specified not to alias with some other
4735collection of memory access instructions that carry ``alias.scope`` metadata.
Hal Finkel029cde62014-07-25 15:50:02 +00004736Each type of metadata specifies a list of scopes where each scope has an id and
Adam Nemet569a5b32016-04-27 00:52:48 +00004737a domain.
4738
4739When evaluating an aliasing query, if for some domain, the set
Hal Finkel029cde62014-07-25 15:50:02 +00004740of scopes with that domain in one instruction's ``alias.scope`` list is a
Arch D. Robison96cf7ab2015-02-24 20:11:49 +00004741subset of (or equal to) the set of scopes for that domain in another
Hal Finkel029cde62014-07-25 15:50:02 +00004742instruction's ``noalias`` list, then the two memory accesses are assumed not to
4743alias.
Hal Finkel94146652014-07-24 14:25:39 +00004744
Adam Nemet569a5b32016-04-27 00:52:48 +00004745Because scopes in one domain don't affect scopes in other domains, separate
4746domains can be used to compose multiple independent noalias sets. This is
4747used for example during inlining. As the noalias function parameters are
4748turned into noalias scope metadata, a new domain is used every time the
4749function is inlined.
4750
Hal Finkel029cde62014-07-25 15:50:02 +00004751The metadata identifying each domain is itself a list containing one or two
4752entries. The first entry is the name of the domain. Note that if the name is a
Bruce Mitchenere9ffb452015-09-12 01:17:08 +00004753string then it can be combined across functions and translation units. A
Hal Finkel029cde62014-07-25 15:50:02 +00004754self-reference can be used to create globally unique domain names. A
4755descriptive string may optionally be provided as a second list entry.
4756
4757The metadata identifying each scope is also itself a list containing two or
4758three entries. The first entry is the name of the scope. Note that if the name
Bruce Mitchenere9ffb452015-09-12 01:17:08 +00004759is a string then it can be combined across functions and translation units. A
Hal Finkel029cde62014-07-25 15:50:02 +00004760self-reference can be used to create globally unique scope names. A metadata
4761reference to the scope's domain is the second entry. A descriptive string may
4762optionally be provided as a third list entry.
Hal Finkel94146652014-07-24 14:25:39 +00004763
4764For example,
4765
4766.. code-block:: llvm
4767
Hal Finkel029cde62014-07-25 15:50:02 +00004768 ; Two scope domains:
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00004769 !0 = !{!0}
4770 !1 = !{!1}
Hal Finkel94146652014-07-24 14:25:39 +00004771
Hal Finkel029cde62014-07-25 15:50:02 +00004772 ; Some scopes in these domains:
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00004773 !2 = !{!2, !0}
4774 !3 = !{!3, !0}
4775 !4 = !{!4, !1}
Hal Finkel94146652014-07-24 14:25:39 +00004776
Hal Finkel029cde62014-07-25 15:50:02 +00004777 ; Some scope lists:
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00004778 !5 = !{!4} ; A list containing only scope !4
4779 !6 = !{!4, !3, !2}
4780 !7 = !{!3}
Hal Finkel94146652014-07-24 14:25:39 +00004781
4782 ; These two instructions don't alias:
David Blaikiec7aabbb2015-03-04 22:06:14 +00004783 %0 = load float, float* %c, align 4, !alias.scope !5
Hal Finkel029cde62014-07-25 15:50:02 +00004784 store float %0, float* %arrayidx.i, align 4, !noalias !5
Hal Finkel94146652014-07-24 14:25:39 +00004785
Hal Finkel029cde62014-07-25 15:50:02 +00004786 ; These two instructions also don't alias (for domain !1, the set of scopes
4787 ; in the !alias.scope equals that in the !noalias list):
David Blaikiec7aabbb2015-03-04 22:06:14 +00004788 %2 = load float, float* %c, align 4, !alias.scope !5
Hal Finkel029cde62014-07-25 15:50:02 +00004789 store float %2, float* %arrayidx.i2, align 4, !noalias !6
Hal Finkel94146652014-07-24 14:25:39 +00004790
Adam Nemet0a8416f2015-05-11 08:30:28 +00004791 ; These two instructions may alias (for domain !0, the set of scopes in
Hal Finkel029cde62014-07-25 15:50:02 +00004792 ; the !noalias list is not a superset of, or equal to, the scopes in the
4793 ; !alias.scope list):
David Blaikiec7aabbb2015-03-04 22:06:14 +00004794 %2 = load float, float* %c, align 4, !alias.scope !6
Hal Finkel029cde62014-07-25 15:50:02 +00004795 store float %0, float* %arrayidx.i, align 4, !noalias !7
Hal Finkel94146652014-07-24 14:25:39 +00004796
Sean Silvab084af42012-12-07 10:36:55 +00004797'``fpmath``' Metadata
4798^^^^^^^^^^^^^^^^^^^^^
4799
4800``fpmath`` metadata may be attached to any instruction of floating point
4801type. It can be used to express the maximum acceptable error in the
4802result of that instruction, in ULPs, thus potentially allowing the
4803compiler to use a more efficient but less accurate method of computing
4804it. ULP is defined as follows:
4805
4806 If ``x`` is a real number that lies between two finite consecutive
4807 floating-point numbers ``a`` and ``b``, without being equal to one
4808 of them, then ``ulp(x) = |b - a|``, otherwise ``ulp(x)`` is the
4809 distance between the two non-equal finite floating-point numbers
4810 nearest ``x``. Moreover, ``ulp(NaN)`` is ``NaN``.
4811
Matt Arsenault82f41512016-06-27 19:43:15 +00004812The metadata node shall consist of a single positive float type number
4813representing the maximum relative error, for example:
Sean Silvab084af42012-12-07 10:36:55 +00004814
4815.. code-block:: llvm
4816
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00004817 !0 = !{ float 2.5 } ; maximum acceptable inaccuracy is 2.5 ULPs
Sean Silvab084af42012-12-07 10:36:55 +00004818
Philip Reamesf8bf9dd2015-02-27 23:14:50 +00004819.. _range-metadata:
4820
Sean Silvab084af42012-12-07 10:36:55 +00004821'``range``' Metadata
4822^^^^^^^^^^^^^^^^^^^^
4823
Jingyue Wu37fcb592014-06-19 16:50:16 +00004824``range`` metadata may be attached only to ``load``, ``call`` and ``invoke`` of
4825integer types. It expresses the possible ranges the loaded value or the value
4826returned by the called function at this call site is in. The ranges are
4827represented with a flattened list of integers. The loaded value or the value
4828returned is known to be in the union of the ranges defined by each consecutive
4829pair. Each pair has the following properties:
Sean Silvab084af42012-12-07 10:36:55 +00004830
4831- The type must match the type loaded by the instruction.
4832- The pair ``a,b`` represents the range ``[a,b)``.
4833- Both ``a`` and ``b`` are constants.
4834- The range is allowed to wrap.
4835- The range should not represent the full or empty set. That is,
4836 ``a!=b``.
4837
4838In addition, the pairs must be in signed order of the lower bound and
4839they must be non-contiguous.
4840
4841Examples:
4842
4843.. code-block:: llvm
4844
David Blaikiec7aabbb2015-03-04 22:06:14 +00004845 %a = load i8, i8* %x, align 1, !range !0 ; Can only be 0 or 1
4846 %b = load i8, i8* %y, align 1, !range !1 ; Can only be 255 (-1), 0 or 1
Jingyue Wu37fcb592014-06-19 16:50:16 +00004847 %c = call i8 @foo(), !range !2 ; Can only be 0, 1, 3, 4 or 5
4848 %d = invoke i8 @bar() to label %cont
4849 unwind label %lpad, !range !3 ; Can only be -2, -1, 3, 4 or 5
Sean Silvab084af42012-12-07 10:36:55 +00004850 ...
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00004851 !0 = !{ i8 0, i8 2 }
4852 !1 = !{ i8 255, i8 2 }
4853 !2 = !{ i8 0, i8 2, i8 3, i8 6 }
4854 !3 = !{ i8 -2, i8 0, i8 3, i8 6 }
Sean Silvab084af42012-12-07 10:36:55 +00004855
Peter Collingbourne235c2752016-12-08 19:01:00 +00004856'``absolute_symbol``' Metadata
4857^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4858
4859``absolute_symbol`` metadata may be attached to a global variable
4860declaration. It marks the declaration as a reference to an absolute symbol,
4861which causes the backend to use absolute relocations for the symbol even
4862in position independent code, and expresses the possible ranges that the
4863global variable's *address* (not its value) is in, in the same format as
Peter Collingbourned88f9282017-01-20 21:56:37 +00004864``range`` metadata, with the extension that the pair ``all-ones,all-ones``
4865may be used to represent the full set.
Peter Collingbourne235c2752016-12-08 19:01:00 +00004866
Peter Collingbourned88f9282017-01-20 21:56:37 +00004867Example (assuming 64-bit pointers):
Peter Collingbourne235c2752016-12-08 19:01:00 +00004868
4869.. code-block:: llvm
4870
4871 @a = external global i8, !absolute_symbol !0 ; Absolute symbol in range [0,256)
Peter Collingbourned88f9282017-01-20 21:56:37 +00004872 @b = external global i8, !absolute_symbol !1 ; Absolute symbol in range [0,2^64)
Peter Collingbourne235c2752016-12-08 19:01:00 +00004873
4874 ...
4875 !0 = !{ i64 0, i64 256 }
Peter Collingbourned88f9282017-01-20 21:56:37 +00004876 !1 = !{ i64 -1, i64 -1 }
Peter Collingbourne235c2752016-12-08 19:01:00 +00004877
Sanjay Patela99ab1f2015-09-02 19:06:43 +00004878'``unpredictable``' Metadata
Sanjay Patel1f12b342015-09-02 19:35:31 +00004879^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Sanjay Patela99ab1f2015-09-02 19:06:43 +00004880
4881``unpredictable`` metadata may be attached to any branch or switch
4882instruction. It can be used to express the unpredictability of control
4883flow. Similar to the llvm.expect intrinsic, it may be used to alter
4884optimizations related to compare and branch instructions. The metadata
4885is treated as a boolean value; if it exists, it signals that the branch
4886or switch that it is attached to is completely unpredictable.
4887
Pekka Jaaskelainen0d237252013-02-13 18:08:57 +00004888'``llvm.loop``'
4889^^^^^^^^^^^^^^^
4890
4891It is sometimes useful to attach information to loop constructs. Currently,
4892loop metadata is implemented as metadata attached to the branch instruction
4893in the loop latch block. This type of metadata refer to a metadata node that is
Matt Arsenault24b49c42013-07-31 17:49:08 +00004894guaranteed to be separate for each loop. The loop identifier metadata is
Paul Redmond5fdf8362013-05-28 20:00:34 +00004895specified with the name ``llvm.loop``.
Pekka Jaaskelainen0d237252013-02-13 18:08:57 +00004896
4897The loop identifier metadata is implemented using a metadata that refers to
Michael Liaoa7699082013-03-06 18:24:34 +00004898itself to avoid merging it with any other identifier metadata, e.g.,
4899during module linkage or function inlining. That is, each loop should refer
4900to their own identification metadata even if they reside in separate functions.
4901The following example contains loop identifier metadata for two separate loop
Pekka Jaaskelainen119a2b62013-02-22 12:03:07 +00004902constructs:
Pekka Jaaskelainen0d237252013-02-13 18:08:57 +00004903
4904.. code-block:: llvm
Paul Redmondeaaed3b2013-02-21 17:20:45 +00004905
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00004906 !0 = !{!0}
4907 !1 = !{!1}
Pekka Jaaskelainen119a2b62013-02-22 12:03:07 +00004908
Mark Heffernan893752a2014-07-18 19:24:51 +00004909The loop identifier metadata can be used to specify additional
4910per-loop metadata. Any operands after the first operand can be treated
4911as user-defined metadata. For example the ``llvm.loop.unroll.count``
4912suggests an unroll factor to the loop unroller:
Pekka Jaaskelainen0d237252013-02-13 18:08:57 +00004913
Paul Redmond5fdf8362013-05-28 20:00:34 +00004914.. code-block:: llvm
Pekka Jaaskelainen0d237252013-02-13 18:08:57 +00004915
Paul Redmond5fdf8362013-05-28 20:00:34 +00004916 br i1 %exitcond, label %._crit_edge, label %.lr.ph, !llvm.loop !0
4917 ...
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00004918 !0 = !{!0, !1}
4919 !1 = !{!"llvm.loop.unroll.count", i32 4}
Mark Heffernan893752a2014-07-18 19:24:51 +00004920
Mark Heffernan9d20e422014-07-21 23:11:03 +00004921'``llvm.loop.vectorize``' and '``llvm.loop.interleave``'
4922^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Mark Heffernan893752a2014-07-18 19:24:51 +00004923
Mark Heffernan9d20e422014-07-21 23:11:03 +00004924Metadata prefixed with ``llvm.loop.vectorize`` or ``llvm.loop.interleave`` are
4925used to control per-loop vectorization and interleaving parameters such as
Sean Silvaa1190322015-08-06 22:56:48 +00004926vectorization width and interleave count. These metadata should be used in
4927conjunction with ``llvm.loop`` loop identification metadata. The
Mark Heffernan9d20e422014-07-21 23:11:03 +00004928``llvm.loop.vectorize`` and ``llvm.loop.interleave`` metadata are only
4929optimization hints and the optimizer will only interleave and vectorize loops if
Sean Silvaa1190322015-08-06 22:56:48 +00004930it believes it is safe to do so. The ``llvm.mem.parallel_loop_access`` metadata
Mark Heffernan9d20e422014-07-21 23:11:03 +00004931which contains information about loop-carried memory dependencies can be helpful
4932in determining the safety of these transformations.
Mark Heffernan893752a2014-07-18 19:24:51 +00004933
Mark Heffernan9d20e422014-07-21 23:11:03 +00004934'``llvm.loop.interleave.count``' Metadata
Mark Heffernan893752a2014-07-18 19:24:51 +00004935^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4936
Mark Heffernan9d20e422014-07-21 23:11:03 +00004937This metadata suggests an interleave count to the loop interleaver.
4938The first operand is the string ``llvm.loop.interleave.count`` and the
Mark Heffernan893752a2014-07-18 19:24:51 +00004939second operand is an integer specifying the interleave count. For
4940example:
4941
4942.. code-block:: llvm
4943
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00004944 !0 = !{!"llvm.loop.interleave.count", i32 4}
Mark Heffernan893752a2014-07-18 19:24:51 +00004945
Mark Heffernan9d20e422014-07-21 23:11:03 +00004946Note that setting ``llvm.loop.interleave.count`` to 1 disables interleaving
Sean Silvaa1190322015-08-06 22:56:48 +00004947multiple iterations of the loop. If ``llvm.loop.interleave.count`` is set to 0
Mark Heffernan9d20e422014-07-21 23:11:03 +00004948then the interleave count will be determined automatically.
4949
4950'``llvm.loop.vectorize.enable``' Metadata
Dan Liew9a1829d2014-07-22 14:59:38 +00004951^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Mark Heffernan9d20e422014-07-21 23:11:03 +00004952
4953This metadata selectively enables or disables vectorization for the loop. The
4954first operand is the string ``llvm.loop.vectorize.enable`` and the second operand
Sean Silvaa1190322015-08-06 22:56:48 +00004955is a bit. If the bit operand value is 1 vectorization is enabled. A value of
Mark Heffernan9d20e422014-07-21 23:11:03 +000049560 disables vectorization:
4957
4958.. code-block:: llvm
4959
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00004960 !0 = !{!"llvm.loop.vectorize.enable", i1 0}
4961 !1 = !{!"llvm.loop.vectorize.enable", i1 1}
Mark Heffernan893752a2014-07-18 19:24:51 +00004962
4963'``llvm.loop.vectorize.width``' Metadata
4964^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4965
4966This metadata sets the target width of the vectorizer. The first
4967operand is the string ``llvm.loop.vectorize.width`` and the second
4968operand is an integer specifying the width. For example:
4969
4970.. code-block:: llvm
4971
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00004972 !0 = !{!"llvm.loop.vectorize.width", i32 4}
Mark Heffernan893752a2014-07-18 19:24:51 +00004973
4974Note that setting ``llvm.loop.vectorize.width`` to 1 disables
Sean Silvaa1190322015-08-06 22:56:48 +00004975vectorization of the loop. If ``llvm.loop.vectorize.width`` is set to
Mark Heffernan893752a2014-07-18 19:24:51 +000049760 or if the loop does not have this metadata the width will be
4977determined automatically.
4978
4979'``llvm.loop.unroll``'
4980^^^^^^^^^^^^^^^^^^^^^^
4981
4982Metadata prefixed with ``llvm.loop.unroll`` are loop unrolling
4983optimization hints such as the unroll factor. ``llvm.loop.unroll``
4984metadata should be used in conjunction with ``llvm.loop`` loop
4985identification metadata. The ``llvm.loop.unroll`` metadata are only
4986optimization hints and the unrolling will only be performed if the
4987optimizer believes it is safe to do so.
4988
Mark Heffernan893752a2014-07-18 19:24:51 +00004989'``llvm.loop.unroll.count``' Metadata
4990^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4991
4992This metadata suggests an unroll factor to the loop unroller. The
4993first operand is the string ``llvm.loop.unroll.count`` and the second
4994operand is a positive integer specifying the unroll factor. For
4995example:
4996
4997.. code-block:: llvm
4998
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00004999 !0 = !{!"llvm.loop.unroll.count", i32 4}
Mark Heffernan893752a2014-07-18 19:24:51 +00005000
5001If the trip count of the loop is less than the unroll count the loop
5002will be partially unrolled.
5003
Mark Heffernane6b4ba12014-07-23 17:31:37 +00005004'``llvm.loop.unroll.disable``' Metadata
5005^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5006
Mark Heffernan3e32a4e2015-06-30 22:48:51 +00005007This metadata disables loop unrolling. The metadata has a single operand
Sean Silvaa1190322015-08-06 22:56:48 +00005008which is the string ``llvm.loop.unroll.disable``. For example:
Mark Heffernane6b4ba12014-07-23 17:31:37 +00005009
5010.. code-block:: llvm
5011
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00005012 !0 = !{!"llvm.loop.unroll.disable"}
Mark Heffernane6b4ba12014-07-23 17:31:37 +00005013
Kevin Qin715b01e2015-03-09 06:14:18 +00005014'``llvm.loop.unroll.runtime.disable``' Metadata
Dan Liew868b0742015-03-11 13:34:49 +00005015^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Kevin Qin715b01e2015-03-09 06:14:18 +00005016
Mark Heffernan3e32a4e2015-06-30 22:48:51 +00005017This metadata disables runtime loop unrolling. The metadata has a single
Sean Silvaa1190322015-08-06 22:56:48 +00005018operand which is the string ``llvm.loop.unroll.runtime.disable``. For example:
Kevin Qin715b01e2015-03-09 06:14:18 +00005019
5020.. code-block:: llvm
5021
5022 !0 = !{!"llvm.loop.unroll.runtime.disable"}
5023
Mark Heffernan89391542015-08-10 17:28:08 +00005024'``llvm.loop.unroll.enable``' Metadata
5025^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5026
5027This metadata suggests that the loop should be fully unrolled if the trip count
5028is known at compile time and partially unrolled if the trip count is not known
5029at compile time. The metadata has a single operand which is the string
5030``llvm.loop.unroll.enable``. For example:
5031
5032.. code-block:: llvm
5033
5034 !0 = !{!"llvm.loop.unroll.enable"}
5035
Mark Heffernane6b4ba12014-07-23 17:31:37 +00005036'``llvm.loop.unroll.full``' Metadata
5037^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5038
Mark Heffernan3e32a4e2015-06-30 22:48:51 +00005039This metadata suggests that the loop should be unrolled fully. The
5040metadata has a single operand which is the string ``llvm.loop.unroll.full``.
Mark Heffernane6b4ba12014-07-23 17:31:37 +00005041For example:
5042
5043.. code-block:: llvm
5044
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00005045 !0 = !{!"llvm.loop.unroll.full"}
Pekka Jaaskelainen0d237252013-02-13 18:08:57 +00005046
Ashutosh Nemadf6763a2016-02-06 07:47:48 +00005047'``llvm.loop.licm_versioning.disable``' Metadata
Ashutosh Nema5f0e4722016-02-06 09:24:37 +00005048^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Ashutosh Nemadf6763a2016-02-06 07:47:48 +00005049
5050This metadata indicates that the loop should not be versioned for the purpose
5051of enabling loop-invariant code motion (LICM). The metadata has a single operand
5052which is the string ``llvm.loop.licm_versioning.disable``. For example:
5053
5054.. code-block:: llvm
5055
5056 !0 = !{!"llvm.loop.licm_versioning.disable"}
5057
Adam Nemetd2fa4142016-04-27 05:28:18 +00005058'``llvm.loop.distribute.enable``' Metadata
Adam Nemet55dc0af2016-04-27 05:59:51 +00005059^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Adam Nemetd2fa4142016-04-27 05:28:18 +00005060
5061Loop distribution allows splitting a loop into multiple loops. Currently,
5062this is only performed if the entire loop cannot be vectorized due to unsafe
Hiroshi Inoueb93daec2017-07-02 12:44:27 +00005063memory dependencies. The transformation will attempt to isolate the unsafe
Adam Nemetd2fa4142016-04-27 05:28:18 +00005064dependencies into their own loop.
5065
5066This metadata can be used to selectively enable or disable distribution of the
5067loop. The first operand is the string ``llvm.loop.distribute.enable`` and the
5068second operand is a bit. If the bit operand value is 1 distribution is
5069enabled. A value of 0 disables distribution:
5070
5071.. code-block:: llvm
5072
5073 !0 = !{!"llvm.loop.distribute.enable", i1 0}
5074 !1 = !{!"llvm.loop.distribute.enable", i1 1}
5075
5076This metadata should be used in conjunction with ``llvm.loop`` loop
5077identification metadata.
5078
Pekka Jaaskelainen0d237252013-02-13 18:08:57 +00005079'``llvm.mem``'
5080^^^^^^^^^^^^^^^
5081
5082Metadata types used to annotate memory accesses with information helpful
5083for optimizations are prefixed with ``llvm.mem``.
5084
5085'``llvm.mem.parallel_loop_access``' Metadata
5086^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5087
Mehdi Amini4a121fa2015-03-14 22:04:06 +00005088The ``llvm.mem.parallel_loop_access`` metadata refers to a loop identifier,
5089or metadata containing a list of loop identifiers for nested loops.
5090The metadata is attached to memory accessing instructions and denotes that
5091no loop carried memory dependence exist between it and other instructions denoted
Hal Finkel411d31a2016-04-26 02:00:36 +00005092with the same loop identifier. The metadata on memory reads also implies that
5093if conversion (i.e. speculative execution within a loop iteration) is safe.
Pekka Jaaskelainen23b222cc2014-05-23 11:35:46 +00005094
Mehdi Amini4a121fa2015-03-14 22:04:06 +00005095Precisely, given two instructions ``m1`` and ``m2`` that both have the
5096``llvm.mem.parallel_loop_access`` metadata, with ``L1`` and ``L2`` being the
5097set of loops associated with that metadata, respectively, then there is no loop
5098carried dependence between ``m1`` and ``m2`` for loops in both ``L1`` and
Pekka Jaaskelainen23b222cc2014-05-23 11:35:46 +00005099``L2``.
5100
Mehdi Amini4a121fa2015-03-14 22:04:06 +00005101As a special case, if all memory accessing instructions in a loop have
5102``llvm.mem.parallel_loop_access`` metadata that refers to that loop, then the
5103loop has no loop carried memory dependences and is considered to be a parallel
5104loop.
Pekka Jaaskelainen23b222cc2014-05-23 11:35:46 +00005105
Mehdi Amini4a121fa2015-03-14 22:04:06 +00005106Note that if not all memory access instructions have such metadata referring to
5107the loop, then the loop is considered not being trivially parallel. Additional
Sean Silvaa1190322015-08-06 22:56:48 +00005108memory dependence analysis is required to make that determination. As a fail
Mehdi Amini4a121fa2015-03-14 22:04:06 +00005109safe mechanism, this causes loops that were originally parallel to be considered
5110sequential (if optimization passes that are unaware of the parallel semantics
Pekka Jaaskelainen23b222cc2014-05-23 11:35:46 +00005111insert new memory instructions into the loop body).
Pekka Jaaskelainen0d237252013-02-13 18:08:57 +00005112
5113Example of a loop that is considered parallel due to its correct use of
Paul Redmond5fdf8362013-05-28 20:00:34 +00005114both ``llvm.loop`` and ``llvm.mem.parallel_loop_access``
Pekka Jaaskelainen0d237252013-02-13 18:08:57 +00005115metadata types that refer to the same loop identifier metadata.
5116
5117.. code-block:: llvm
5118
5119 for.body:
Paul Redmond5fdf8362013-05-28 20:00:34 +00005120 ...
David Blaikiec7aabbb2015-03-04 22:06:14 +00005121 %val0 = load i32, i32* %arrayidx, !llvm.mem.parallel_loop_access !0
Paul Redmond5fdf8362013-05-28 20:00:34 +00005122 ...
Tobias Grosserfbe95dc2014-03-05 13:36:04 +00005123 store i32 %val0, i32* %arrayidx1, !llvm.mem.parallel_loop_access !0
Paul Redmond5fdf8362013-05-28 20:00:34 +00005124 ...
5125 br i1 %exitcond, label %for.end, label %for.body, !llvm.loop !0
Pekka Jaaskelainen0d237252013-02-13 18:08:57 +00005126
5127 for.end:
5128 ...
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00005129 !0 = !{!0}
Pekka Jaaskelainen0d237252013-02-13 18:08:57 +00005130
5131It is also possible to have nested parallel loops. In that case the
5132memory accesses refer to a list of loop identifier metadata nodes instead of
5133the loop identifier metadata node directly:
5134
5135.. code-block:: llvm
5136
5137 outer.for.body:
Tobias Grosserfbe95dc2014-03-05 13:36:04 +00005138 ...
David Blaikiec7aabbb2015-03-04 22:06:14 +00005139 %val1 = load i32, i32* %arrayidx3, !llvm.mem.parallel_loop_access !2
Tobias Grosserfbe95dc2014-03-05 13:36:04 +00005140 ...
5141 br label %inner.for.body
Pekka Jaaskelainen0d237252013-02-13 18:08:57 +00005142
5143 inner.for.body:
Paul Redmond5fdf8362013-05-28 20:00:34 +00005144 ...
David Blaikiec7aabbb2015-03-04 22:06:14 +00005145 %val0 = load i32, i32* %arrayidx1, !llvm.mem.parallel_loop_access !0
Paul Redmond5fdf8362013-05-28 20:00:34 +00005146 ...
Tobias Grosserfbe95dc2014-03-05 13:36:04 +00005147 store i32 %val0, i32* %arrayidx2, !llvm.mem.parallel_loop_access !0
Paul Redmond5fdf8362013-05-28 20:00:34 +00005148 ...
5149 br i1 %exitcond, label %inner.for.end, label %inner.for.body, !llvm.loop !1
Pekka Jaaskelainen0d237252013-02-13 18:08:57 +00005150
5151 inner.for.end:
Paul Redmond5fdf8362013-05-28 20:00:34 +00005152 ...
Tobias Grosserfbe95dc2014-03-05 13:36:04 +00005153 store i32 %val1, i32* %arrayidx4, !llvm.mem.parallel_loop_access !2
Paul Redmond5fdf8362013-05-28 20:00:34 +00005154 ...
5155 br i1 %exitcond, label %outer.for.end, label %outer.for.body, !llvm.loop !2
Pekka Jaaskelainen0d237252013-02-13 18:08:57 +00005156
5157 outer.for.end: ; preds = %for.body
5158 ...
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00005159 !0 = !{!1, !2} ; a list of loop identifiers
5160 !1 = !{!1} ; an identifier for the inner loop
5161 !2 = !{!2} ; an identifier for the outer loop
Pekka Jaaskelainen0d237252013-02-13 18:08:57 +00005162
Piotr Padlewski6c15ec42015-09-15 18:32:14 +00005163'``invariant.group``' Metadata
5164^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5165
5166The ``invariant.group`` metadata may be attached to ``load``/``store`` instructions.
5167The existence of the ``invariant.group`` metadata on the instruction tells
5168the optimizer that every ``load`` and ``store`` to the same pointer operand
5169within the same invariant group can be assumed to load or store the same
5170value (but see the ``llvm.invariant.group.barrier`` intrinsic which affects
Piotr Padlewskida362152016-12-30 18:45:07 +00005171when two pointers are considered the same). Pointers returned by bitcast or
5172getelementptr with only zero indices are considered the same.
Piotr Padlewski6c15ec42015-09-15 18:32:14 +00005173
5174Examples:
5175
5176.. code-block:: llvm
5177
5178 @unknownPtr = external global i8
5179 ...
5180 %ptr = alloca i8
5181 store i8 42, i8* %ptr, !invariant.group !0
5182 call void @foo(i8* %ptr)
5183
5184 %a = load i8, i8* %ptr, !invariant.group !0 ; Can assume that value under %ptr didn't change
5185 call void @foo(i8* %ptr)
5186 %b = load i8, i8* %ptr, !invariant.group !1 ; Can't assume anything, because group changed
5187
5188 %newPtr = call i8* @getPointer(i8* %ptr)
5189 %c = load i8, i8* %newPtr, !invariant.group !0 ; Can't assume anything, because we only have information about %ptr
5190
5191 %unknownValue = load i8, i8* @unknownPtr
5192 store i8 %unknownValue, i8* %ptr, !invariant.group !0 ; Can assume that %unknownValue == 42
5193
5194 call void @foo(i8* %ptr)
5195 %newPtr2 = call i8* @llvm.invariant.group.barrier(i8* %ptr)
5196 %d = load i8, i8* %newPtr2, !invariant.group !0 ; Can't step through invariant.group.barrier to get value of %ptr
5197
5198 ...
5199 declare void @foo(i8*)
5200 declare i8* @getPointer(i8*)
5201 declare i8* @llvm.invariant.group.barrier(i8*)
5202
5203 !0 = !{!"magic ptr"}
5204 !1 = !{!"other ptr"}
5205
Piotr Padlewskif8486e32017-04-12 07:59:35 +00005206The invariant.group metadata must be dropped when replacing one pointer by
5207another based on aliasing information. This is because invariant.group is tied
5208to the SSA value of the pointer operand.
5209
5210.. code-block:: llvm
Piotr Padlewskiaa1b2412017-04-12 11:18:19 +00005211
Piotr Padlewskif8486e32017-04-12 07:59:35 +00005212 %v = load i8, i8* %x, !invariant.group !0
5213 ; if %x mustalias %y then we can replace the above instruction with
5214 %v = load i8, i8* %y
5215
5216
Peter Collingbournea333db82016-07-26 22:31:30 +00005217'``type``' Metadata
5218^^^^^^^^^^^^^^^^^^^
5219
5220See :doc:`TypeMetadata`.
Piotr Padlewski6c15ec42015-09-15 18:32:14 +00005221
Evgeniy Stepanov51c962f722017-03-17 22:17:24 +00005222'``associated``' Metadata
Evgeniy Stepanov4d490de2017-03-17 22:31:13 +00005223^^^^^^^^^^^^^^^^^^^^^^^^^
Evgeniy Stepanov51c962f722017-03-17 22:17:24 +00005224
5225The ``associated`` metadata may be attached to a global object
5226declaration with a single argument that references another global object.
5227
5228This metadata prevents discarding of the global object in linker GC
5229unless the referenced object is also discarded. The linker support for
5230this feature is spotty. For best compatibility, globals carrying this
5231metadata may also:
5232
5233- Be in a comdat with the referenced global.
5234- Be in @llvm.compiler.used.
5235- Have an explicit section with a name which is a valid C identifier.
5236
5237It does not have any effect on non-ELF targets.
5238
5239Example:
5240
5241.. code-block:: llvm
Evgeniy Stepanov4d490de2017-03-17 22:31:13 +00005242
Evgeniy Stepanov51c962f722017-03-17 22:17:24 +00005243 $a = comdat any
5244 @a = global i32 1, comdat $a
5245 @b = internal global i32 2, comdat $a, section "abc", !associated !0
5246 !0 = !{i32* @a}
5247
Piotr Padlewski6c15ec42015-09-15 18:32:14 +00005248
Teresa Johnsond72f51c2017-06-15 15:57:12 +00005249'``prof``' Metadata
5250^^^^^^^^^^^^^^^^^^^
5251
5252The ``prof`` metadata is used to record profile data in the IR.
5253The first operand of the metadata node indicates the profile metadata
5254type. There are currently 3 types:
5255:ref:`branch_weights<prof_node_branch_weights>`,
5256:ref:`function_entry_count<prof_node_function_entry_count>`, and
5257:ref:`VP<prof_node_VP>`.
5258
5259.. _prof_node_branch_weights:
5260
5261branch_weights
5262""""""""""""""
5263
5264Branch weight metadata attached to a branch, select, switch or call instruction
5265represents the likeliness of the associated branch being taken.
5266For more information, see :doc:`BranchWeightMetadata`.
5267
5268.. _prof_node_function_entry_count:
5269
5270function_entry_count
5271""""""""""""""""""""
5272
5273Function entry count metadata can be attached to function definitions
5274to record the number of times the function is called. Used with BFI
5275information, it is also used to derive the basic block profile count.
5276For more information, see :doc:`BranchWeightMetadata`.
5277
5278.. _prof_node_VP:
5279
5280VP
5281""
5282
5283VP (value profile) metadata can be attached to instructions that have
5284value profile information. Currently this is indirect calls (where it
5285records the hottest callees) and calls to memory intrinsics such as memcpy,
5286memmove, and memset (where it records the hottest byte lengths).
5287
5288Each VP metadata node contains "VP" string, then a uint32_t value for the value
5289profiling kind, a uint64_t value for the total number of times the instruction
5290is executed, followed by uint64_t value and execution count pairs.
5291The value profiling kind is 0 for indirect call targets and 1 for memory
5292operations. For indirect call targets, each profile value is a hash
5293of the callee function name, and for memory operations each value is the
5294byte length.
5295
5296Note that the value counts do not need to add up to the total count
5297listed in the third operand (in practice only the top hottest values
5298are tracked and reported).
5299
5300Indirect call example:
5301
5302.. code-block:: llvm
5303
5304 call void %f(), !prof !1
5305 !1 = !{!"VP", i32 0, i64 1600, i64 7651369219802541373, i64 1030, i64 -4377547752858689819, i64 410}
5306
5307Note that the VP type is 0 (the second operand), which indicates this is
5308an indirect call value profile data. The third operand indicates that the
5309indirect call executed 1600 times. The 4th and 6th operands give the
5310hashes of the 2 hottest target functions' names (this is the same hash used
5311to represent function names in the profile database), and the 5th and 7th
5312operands give the execution count that each of the respective prior target
5313functions was called.
5314
Sean Silvab084af42012-12-07 10:36:55 +00005315Module Flags Metadata
5316=====================
5317
5318Information about the module as a whole is difficult to convey to LLVM's
5319subsystems. The LLVM IR isn't sufficient to transmit this information.
5320The ``llvm.module.flags`` named metadata exists in order to facilitate
Dmitri Gribenkoe8131122013-01-19 20:34:20 +00005321this. These flags are in the form of key / value pairs --- much like a
5322dictionary --- making it easy for any subsystem who cares about a flag to
Sean Silvab084af42012-12-07 10:36:55 +00005323look it up.
5324
5325The ``llvm.module.flags`` metadata contains a list of metadata triplets.
5326Each triplet has the following form:
5327
5328- The first element is a *behavior* flag, which specifies the behavior
5329 when two (or more) modules are merged together, and it encounters two
5330 (or more) metadata with the same ID. The supported behaviors are
5331 described below.
5332- The second element is a metadata string that is a unique ID for the
Daniel Dunbar25c4b572013-01-15 01:22:53 +00005333 metadata. Each module may only have one flag entry for each unique ID (not
5334 including entries with the **Require** behavior).
Sean Silvab084af42012-12-07 10:36:55 +00005335- The third element is the value of the flag.
5336
5337When two (or more) modules are merged together, the resulting
Daniel Dunbar25c4b572013-01-15 01:22:53 +00005338``llvm.module.flags`` metadata is the union of the modules' flags. That is, for
5339each unique metadata ID string, there will be exactly one entry in the merged
5340modules ``llvm.module.flags`` metadata table, and the value for that entry will
5341be determined by the merge behavior flag, as described below. The only exception
5342is that entries with the *Require* behavior are always preserved.
Sean Silvab084af42012-12-07 10:36:55 +00005343
5344The following behaviors are supported:
5345
5346.. list-table::
5347 :header-rows: 1
5348 :widths: 10 90
5349
5350 * - Value
5351 - Behavior
5352
5353 * - 1
5354 - **Error**
Daniel Dunbar25c4b572013-01-15 01:22:53 +00005355 Emits an error if two values disagree, otherwise the resulting value
5356 is that of the operands.
Sean Silvab084af42012-12-07 10:36:55 +00005357
5358 * - 2
5359 - **Warning**
Daniel Dunbar25c4b572013-01-15 01:22:53 +00005360 Emits a warning if two values disagree. The result value will be the
5361 operand for the flag from the first module being linked.
Sean Silvab084af42012-12-07 10:36:55 +00005362
5363 * - 3
5364 - **Require**
Daniel Dunbar25c4b572013-01-15 01:22:53 +00005365 Adds a requirement that another module flag be present and have a
5366 specified value after linking is performed. The value must be a
5367 metadata pair, where the first element of the pair is the ID of the
5368 module flag to be restricted, and the second element of the pair is
5369 the value the module flag should be restricted to. This behavior can
5370 be used to restrict the allowable results (via triggering of an
5371 error) of linking IDs with the **Override** behavior.
Sean Silvab084af42012-12-07 10:36:55 +00005372
5373 * - 4
5374 - **Override**
Daniel Dunbar25c4b572013-01-15 01:22:53 +00005375 Uses the specified value, regardless of the behavior or value of the
5376 other module. If both modules specify **Override**, but the values
5377 differ, an error will be emitted.
5378
Daniel Dunbard77d9fb2013-01-16 21:38:56 +00005379 * - 5
5380 - **Append**
5381 Appends the two values, which are required to be metadata nodes.
5382
5383 * - 6
5384 - **AppendUnique**
5385 Appends the two values, which are required to be metadata
5386 nodes. However, duplicate entries in the second list are dropped
5387 during the append operation.
5388
Steven Wu86a511e2017-08-15 16:16:33 +00005389 * - 7
5390 - **Max**
5391 Takes the max of the two values, which are required to be integers.
5392
Daniel Dunbar25c4b572013-01-15 01:22:53 +00005393It is an error for a particular unique flag ID to have multiple behaviors,
5394except in the case of **Require** (which adds restrictions on another metadata
5395value) or **Override**.
Sean Silvab084af42012-12-07 10:36:55 +00005396
5397An example of module flags:
5398
5399.. code-block:: llvm
5400
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00005401 !0 = !{ i32 1, !"foo", i32 1 }
5402 !1 = !{ i32 4, !"bar", i32 37 }
5403 !2 = !{ i32 2, !"qux", i32 42 }
5404 !3 = !{ i32 3, !"qux",
5405 !{
5406 !"foo", i32 1
Sean Silvab084af42012-12-07 10:36:55 +00005407 }
5408 }
5409 !llvm.module.flags = !{ !0, !1, !2, !3 }
5410
5411- Metadata ``!0`` has the ID ``!"foo"`` and the value '1'. The behavior
5412 if two or more ``!"foo"`` flags are seen is to emit an error if their
5413 values are not equal.
5414
5415- Metadata ``!1`` has the ID ``!"bar"`` and the value '37'. The
5416 behavior if two or more ``!"bar"`` flags are seen is to use the value
Daniel Dunbar25c4b572013-01-15 01:22:53 +00005417 '37'.
Sean Silvab084af42012-12-07 10:36:55 +00005418
5419- Metadata ``!2`` has the ID ``!"qux"`` and the value '42'. The
5420 behavior if two or more ``!"qux"`` flags are seen is to emit a
5421 warning if their values are not equal.
5422
5423- Metadata ``!3`` has the ID ``!"qux"`` and the value:
5424
5425 ::
5426
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00005427 !{ !"foo", i32 1 }
Sean Silvab084af42012-12-07 10:36:55 +00005428
Daniel Dunbar25c4b572013-01-15 01:22:53 +00005429 The behavior is to emit an error if the ``llvm.module.flags`` does not
5430 contain a flag with the ID ``!"foo"`` that has the value '1' after linking is
5431 performed.
Sean Silvab084af42012-12-07 10:36:55 +00005432
5433Objective-C Garbage Collection Module Flags Metadata
5434----------------------------------------------------
5435
5436On the Mach-O platform, Objective-C stores metadata about garbage
5437collection in a special section called "image info". The metadata
5438consists of a version number and a bitmask specifying what types of
5439garbage collection are supported (if any) by the file. If two or more
5440modules are linked together their garbage collection metadata needs to
5441be merged rather than appended together.
5442
5443The Objective-C garbage collection module flags metadata consists of the
5444following key-value pairs:
5445
5446.. list-table::
5447 :header-rows: 1
5448 :widths: 30 70
5449
5450 * - Key
5451 - Value
5452
Daniel Dunbar1dc66ca2013-01-17 18:57:32 +00005453 * - ``Objective-C Version``
Dmitri Gribenkoe8131122013-01-19 20:34:20 +00005454 - **[Required]** --- The Objective-C ABI version. Valid values are 1 and 2.
Sean Silvab084af42012-12-07 10:36:55 +00005455
Daniel Dunbar1dc66ca2013-01-17 18:57:32 +00005456 * - ``Objective-C Image Info Version``
Dmitri Gribenkoe8131122013-01-19 20:34:20 +00005457 - **[Required]** --- The version of the image info section. Currently
Sean Silvab084af42012-12-07 10:36:55 +00005458 always 0.
5459
Daniel Dunbar1dc66ca2013-01-17 18:57:32 +00005460 * - ``Objective-C Image Info Section``
Dmitri Gribenkoe8131122013-01-19 20:34:20 +00005461 - **[Required]** --- The section to place the metadata. Valid values are
Sean Silvab084af42012-12-07 10:36:55 +00005462 ``"__OBJC, __image_info, regular"`` for Objective-C ABI version 1, and
5463 ``"__DATA,__objc_imageinfo, regular, no_dead_strip"`` for
5464 Objective-C ABI version 2.
5465
Daniel Dunbar1dc66ca2013-01-17 18:57:32 +00005466 * - ``Objective-C Garbage Collection``
Dmitri Gribenkoe8131122013-01-19 20:34:20 +00005467 - **[Required]** --- Specifies whether garbage collection is supported or
Sean Silvab084af42012-12-07 10:36:55 +00005468 not. Valid values are 0, for no garbage collection, and 2, for garbage
5469 collection supported.
5470
Daniel Dunbar1dc66ca2013-01-17 18:57:32 +00005471 * - ``Objective-C GC Only``
Dmitri Gribenkoe8131122013-01-19 20:34:20 +00005472 - **[Optional]** --- Specifies that only garbage collection is supported.
Sean Silvab084af42012-12-07 10:36:55 +00005473 If present, its value must be 6. This flag requires that the
5474 ``Objective-C Garbage Collection`` flag have the value 2.
5475
5476Some important flag interactions:
5477
5478- If a module with ``Objective-C Garbage Collection`` set to 0 is
5479 merged with a module with ``Objective-C Garbage Collection`` set to
5480 2, then the resulting module has the
5481 ``Objective-C Garbage Collection`` flag set to 0.
5482- A module with ``Objective-C Garbage Collection`` set to 0 cannot be
5483 merged with a module with ``Objective-C GC Only`` set to 6.
5484
Oliver Stannard5dc29342014-06-20 10:08:11 +00005485C type width Module Flags Metadata
5486----------------------------------
5487
5488The ARM backend emits a section into each generated object file describing the
5489options that it was compiled with (in a compiler-independent way) to prevent
5490linking incompatible objects, and to allow automatic library selection. Some
5491of these options are not visible at the IR level, namely wchar_t width and enum
5492width.
5493
5494To pass this information to the backend, these options are encoded in module
5495flags metadata, using the following key-value pairs:
5496
5497.. list-table::
5498 :header-rows: 1
5499 :widths: 30 70
5500
5501 * - Key
5502 - Value
5503
5504 * - short_wchar
5505 - * 0 --- sizeof(wchar_t) == 4
5506 * 1 --- sizeof(wchar_t) == 2
5507
5508 * - short_enum
5509 - * 0 --- Enums are at least as large as an ``int``.
5510 * 1 --- Enums are stored in the smallest integer type which can
5511 represent all of its values.
5512
5513For example, the following metadata section specifies that the module was
5514compiled with a ``wchar_t`` width of 4 bytes, and the underlying type of an
5515enum is the smallest type which can represent all of its values::
5516
5517 !llvm.module.flags = !{!0, !1}
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00005518 !0 = !{i32 1, !"short_wchar", i32 1}
5519 !1 = !{i32 1, !"short_enum", i32 0}
Oliver Stannard5dc29342014-06-20 10:08:11 +00005520
Peter Collingbourne89061b22017-06-12 20:10:48 +00005521Automatic Linker Flags Named Metadata
5522=====================================
5523
5524Some targets support embedding flags to the linker inside individual object
5525files. Typically this is used in conjunction with language extensions which
5526allow source files to explicitly declare the libraries they depend on, and have
5527these automatically be transmitted to the linker via object files.
5528
5529These flags are encoded in the IR using named metadata with the name
5530``!llvm.linker.options``. Each operand is expected to be a metadata node
5531which should be a list of other metadata nodes, each of which should be a
5532list of metadata strings defining linker options.
5533
5534For example, the following metadata section specifies two separate sets of
5535linker options, presumably to link against ``libz`` and the ``Cocoa``
5536framework::
5537
5538 !0 = !{ !"-lz" },
5539 !1 = !{ !"-framework", !"Cocoa" } } }
5540 !llvm.linker.options = !{ !0, !1 }
5541
5542The metadata encoding as lists of lists of options, as opposed to a collapsed
5543list of options, is chosen so that the IR encoding can use multiple option
5544strings to specify e.g., a single library, while still having that specifier be
5545preserved as an atomic element that can be recognized by a target specific
5546assembly writer or object file emitter.
5547
5548Each individual option is required to be either a valid option for the target's
5549linker, or an option that is reserved by the target specific assembly writer or
5550object file emitter. No other aspect of these options is defined by the IR.
5551
Eli Bendersky0220e6b2013-06-07 20:24:43 +00005552.. _intrinsicglobalvariables:
5553
Sean Silvab084af42012-12-07 10:36:55 +00005554Intrinsic Global Variables
5555==========================
5556
5557LLVM has a number of "magic" global variables that contain data that
5558affect code generation or other IR semantics. These are documented here.
5559All globals of this sort should have a section specified as
5560"``llvm.metadata``". This section and all globals that start with
5561"``llvm.``" are reserved for use by LLVM.
5562
Eli Bendersky0220e6b2013-06-07 20:24:43 +00005563.. _gv_llvmused:
5564
Sean Silvab084af42012-12-07 10:36:55 +00005565The '``llvm.used``' Global Variable
5566-----------------------------------
5567
Rafael Espindola74f2e462013-04-22 14:58:02 +00005568The ``@llvm.used`` global is an array which has
Paul Redmond219ef812013-05-30 17:24:32 +00005569:ref:`appending linkage <linkage_appending>`. This array contains a list of
Rafael Espindola70a729d2013-06-11 13:18:13 +00005570pointers to named global variables, functions and aliases which may optionally
5571have a pointer cast formed of bitcast or getelementptr. For example, a legal
Sean Silvab084af42012-12-07 10:36:55 +00005572use of it is:
5573
5574.. code-block:: llvm
5575
5576 @X = global i8 4
5577 @Y = global i32 123
5578
5579 @llvm.used = appending global [2 x i8*] [
5580 i8* @X,
5581 i8* bitcast (i32* @Y to i8*)
5582 ], section "llvm.metadata"
5583
Rafael Espindola74f2e462013-04-22 14:58:02 +00005584If a symbol appears in the ``@llvm.used`` list, then the compiler, assembler,
5585and linker are required to treat the symbol as if there is a reference to the
Rafael Espindola70a729d2013-06-11 13:18:13 +00005586symbol that it cannot see (which is why they have to be named). For example, if
5587a variable has internal linkage and no references other than that from the
5588``@llvm.used`` list, it cannot be deleted. This is commonly used to represent
5589references from inline asms and other things the compiler cannot "see", and
5590corresponds to "``attribute((used))``" in GNU C.
Sean Silvab084af42012-12-07 10:36:55 +00005591
5592On some targets, the code generator must emit a directive to the
5593assembler or object file to prevent the assembler and linker from
5594molesting the symbol.
5595
Eli Bendersky0220e6b2013-06-07 20:24:43 +00005596.. _gv_llvmcompilerused:
5597
Sean Silvab084af42012-12-07 10:36:55 +00005598The '``llvm.compiler.used``' Global Variable
5599--------------------------------------------
5600
5601The ``@llvm.compiler.used`` directive is the same as the ``@llvm.used``
5602directive, except that it only prevents the compiler from touching the
5603symbol. On targets that support it, this allows an intelligent linker to
5604optimize references to the symbol without being impeded as it would be
5605by ``@llvm.used``.
5606
5607This is a rare construct that should only be used in rare circumstances,
5608and should not be exposed to source languages.
5609
Eli Bendersky0220e6b2013-06-07 20:24:43 +00005610.. _gv_llvmglobalctors:
5611
Sean Silvab084af42012-12-07 10:36:55 +00005612The '``llvm.global_ctors``' Global Variable
5613-------------------------------------------
5614
5615.. code-block:: llvm
5616
Reid Klecknerfceb76f2014-05-16 20:39:27 +00005617 %0 = type { i32, void ()*, i8* }
5618 @llvm.global_ctors = appending global [1 x %0] [%0 { i32 65535, void ()* @ctor, i8* @data }]
Sean Silvab084af42012-12-07 10:36:55 +00005619
5620The ``@llvm.global_ctors`` array contains a list of constructor
Reid Klecknerfceb76f2014-05-16 20:39:27 +00005621functions, priorities, and an optional associated global or function.
5622The functions referenced by this array will be called in ascending order
5623of priority (i.e. lowest first) when the module is loaded. The order of
5624functions with the same priority is not defined.
5625
5626If the third field is present, non-null, and points to a global variable
5627or function, the initializer function will only run if the associated
5628data from the current module is not discarded.
Sean Silvab084af42012-12-07 10:36:55 +00005629
Eli Bendersky0220e6b2013-06-07 20:24:43 +00005630.. _llvmglobaldtors:
5631
Sean Silvab084af42012-12-07 10:36:55 +00005632The '``llvm.global_dtors``' Global Variable
5633-------------------------------------------
5634
5635.. code-block:: llvm
5636
Reid Klecknerfceb76f2014-05-16 20:39:27 +00005637 %0 = type { i32, void ()*, i8* }
5638 @llvm.global_dtors = appending global [1 x %0] [%0 { i32 65535, void ()* @dtor, i8* @data }]
Sean Silvab084af42012-12-07 10:36:55 +00005639
Reid Klecknerfceb76f2014-05-16 20:39:27 +00005640The ``@llvm.global_dtors`` array contains a list of destructor
5641functions, priorities, and an optional associated global or function.
5642The functions referenced by this array will be called in descending
Reid Klecknerbffbcc52014-05-27 21:35:17 +00005643order of priority (i.e. highest first) when the module is unloaded. The
Reid Klecknerfceb76f2014-05-16 20:39:27 +00005644order of functions with the same priority is not defined.
5645
5646If the third field is present, non-null, and points to a global variable
5647or function, the destructor function will only run if the associated
5648data from the current module is not discarded.
Sean Silvab084af42012-12-07 10:36:55 +00005649
5650Instruction Reference
5651=====================
5652
5653The LLVM instruction set consists of several different classifications
5654of instructions: :ref:`terminator instructions <terminators>`, :ref:`binary
5655instructions <binaryops>`, :ref:`bitwise binary
5656instructions <bitwiseops>`, :ref:`memory instructions <memoryops>`, and
5657:ref:`other instructions <otherops>`.
5658
5659.. _terminators:
5660
5661Terminator Instructions
5662-----------------------
5663
5664As mentioned :ref:`previously <functionstructure>`, every basic block in a
5665program ends with a "Terminator" instruction, which indicates which
5666block should be executed after the current block is finished. These
5667terminator instructions typically yield a '``void``' value: they produce
5668control flow, not values (the one exception being the
5669':ref:`invoke <i_invoke>`' instruction).
5670
5671The terminator instructions are: ':ref:`ret <i_ret>`',
5672':ref:`br <i_br>`', ':ref:`switch <i_switch>`',
5673':ref:`indirectbr <i_indirectbr>`', ':ref:`invoke <i_invoke>`',
David Majnemer8a1c45d2015-12-12 05:38:55 +00005674':ref:`resume <i_resume>`', ':ref:`catchswitch <i_catchswitch>`',
David Majnemer654e1302015-07-31 17:58:14 +00005675':ref:`catchret <i_catchret>`',
5676':ref:`cleanupret <i_cleanupret>`',
David Majnemer654e1302015-07-31 17:58:14 +00005677and ':ref:`unreachable <i_unreachable>`'.
Sean Silvab084af42012-12-07 10:36:55 +00005678
5679.. _i_ret:
5680
5681'``ret``' Instruction
5682^^^^^^^^^^^^^^^^^^^^^
5683
5684Syntax:
5685"""""""
5686
5687::
5688
5689 ret <type> <value> ; Return a value from a non-void function
5690 ret void ; Return from void function
5691
5692Overview:
5693"""""""""
5694
5695The '``ret``' instruction is used to return control flow (and optionally
5696a value) from a function back to the caller.
5697
5698There are two forms of the '``ret``' instruction: one that returns a
5699value and then causes control flow, and one that just causes control
5700flow to occur.
5701
5702Arguments:
5703""""""""""
5704
5705The '``ret``' instruction optionally accepts a single argument, the
5706return value. The type of the return value must be a ':ref:`first
5707class <t_firstclass>`' type.
5708
5709A function is not :ref:`well formed <wellformed>` if it it has a non-void
5710return type and contains a '``ret``' instruction with no return value or
5711a return value with a type that does not match its type, or if it has a
5712void return type and contains a '``ret``' instruction with a return
5713value.
5714
5715Semantics:
5716""""""""""
5717
5718When the '``ret``' instruction is executed, control flow returns back to
5719the calling function's context. If the caller is a
5720":ref:`call <i_call>`" instruction, execution continues at the
5721instruction after the call. If the caller was an
5722":ref:`invoke <i_invoke>`" instruction, execution continues at the
5723beginning of the "normal" destination block. If the instruction returns
5724a value, that value shall set the call or invoke instruction's return
5725value.
5726
5727Example:
5728""""""""
5729
5730.. code-block:: llvm
5731
5732 ret i32 5 ; Return an integer value of 5
5733 ret void ; Return from a void function
5734 ret { i32, i8 } { i32 4, i8 2 } ; Return a struct of values 4 and 2
5735
5736.. _i_br:
5737
5738'``br``' Instruction
5739^^^^^^^^^^^^^^^^^^^^
5740
5741Syntax:
5742"""""""
5743
5744::
5745
5746 br i1 <cond>, label <iftrue>, label <iffalse>
5747 br label <dest> ; Unconditional branch
5748
5749Overview:
5750"""""""""
5751
5752The '``br``' instruction is used to cause control flow to transfer to a
5753different basic block in the current function. There are two forms of
5754this instruction, corresponding to a conditional branch and an
5755unconditional branch.
5756
5757Arguments:
5758""""""""""
5759
5760The conditional branch form of the '``br``' instruction takes a single
5761'``i1``' value and two '``label``' values. The unconditional form of the
5762'``br``' instruction takes a single '``label``' value as a target.
5763
5764Semantics:
5765""""""""""
5766
5767Upon execution of a conditional '``br``' instruction, the '``i1``'
5768argument is evaluated. If the value is ``true``, control flows to the
5769'``iftrue``' ``label`` argument. If "cond" is ``false``, control flows
5770to the '``iffalse``' ``label`` argument.
5771
5772Example:
5773""""""""
5774
5775.. code-block:: llvm
5776
5777 Test:
5778 %cond = icmp eq i32 %a, %b
5779 br i1 %cond, label %IfEqual, label %IfUnequal
5780 IfEqual:
5781 ret i32 1
5782 IfUnequal:
5783 ret i32 0
5784
5785.. _i_switch:
5786
5787'``switch``' Instruction
5788^^^^^^^^^^^^^^^^^^^^^^^^
5789
5790Syntax:
5791"""""""
5792
5793::
5794
5795 switch <intty> <value>, label <defaultdest> [ <intty> <val>, label <dest> ... ]
5796
5797Overview:
5798"""""""""
5799
5800The '``switch``' instruction is used to transfer control flow to one of
5801several different places. It is a generalization of the '``br``'
5802instruction, allowing a branch to occur to one of many possible
5803destinations.
5804
5805Arguments:
5806""""""""""
5807
5808The '``switch``' instruction uses three parameters: an integer
5809comparison value '``value``', a default '``label``' destination, and an
5810array of pairs of comparison value constants and '``label``'s. The table
5811is not allowed to contain duplicate constant entries.
5812
5813Semantics:
5814""""""""""
5815
5816The ``switch`` instruction specifies a table of values and destinations.
5817When the '``switch``' instruction is executed, this table is searched
5818for the given value. If the value is found, control flow is transferred
5819to the corresponding destination; otherwise, control flow is transferred
5820to the default destination.
5821
5822Implementation:
5823"""""""""""""""
5824
5825Depending on properties of the target machine and the particular
5826``switch`` instruction, this instruction may be code generated in
5827different ways. For example, it could be generated as a series of
5828chained conditional branches or with a lookup table.
5829
5830Example:
5831""""""""
5832
5833.. code-block:: llvm
5834
5835 ; Emulate a conditional br instruction
5836 %Val = zext i1 %value to i32
5837 switch i32 %Val, label %truedest [ i32 0, label %falsedest ]
5838
5839 ; Emulate an unconditional br instruction
5840 switch i32 0, label %dest [ ]
5841
5842 ; Implement a jump table:
5843 switch i32 %val, label %otherwise [ i32 0, label %onzero
5844 i32 1, label %onone
5845 i32 2, label %ontwo ]
5846
5847.. _i_indirectbr:
5848
5849'``indirectbr``' Instruction
5850^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5851
5852Syntax:
5853"""""""
5854
5855::
5856
5857 indirectbr <somety>* <address>, [ label <dest1>, label <dest2>, ... ]
5858
5859Overview:
5860"""""""""
5861
5862The '``indirectbr``' instruction implements an indirect branch to a
5863label within the current function, whose address is specified by
5864"``address``". Address must be derived from a
5865:ref:`blockaddress <blockaddress>` constant.
5866
5867Arguments:
5868""""""""""
5869
5870The '``address``' argument is the address of the label to jump to. The
5871rest of the arguments indicate the full set of possible destinations
5872that the address may point to. Blocks are allowed to occur multiple
5873times in the destination list, though this isn't particularly useful.
5874
5875This destination list is required so that dataflow analysis has an
5876accurate understanding of the CFG.
5877
5878Semantics:
5879""""""""""
5880
5881Control transfers to the block specified in the address argument. All
5882possible destination blocks must be listed in the label list, otherwise
5883this instruction has undefined behavior. This implies that jumps to
5884labels defined in other functions have undefined behavior as well.
5885
5886Implementation:
5887"""""""""""""""
5888
5889This is typically implemented with a jump through a register.
5890
5891Example:
5892""""""""
5893
5894.. code-block:: llvm
5895
5896 indirectbr i8* %Addr, [ label %bb1, label %bb2, label %bb3 ]
5897
5898.. _i_invoke:
5899
5900'``invoke``' Instruction
5901^^^^^^^^^^^^^^^^^^^^^^^^
5902
5903Syntax:
5904"""""""
5905
5906::
5907
David Blaikieb83cf102016-07-13 17:21:34 +00005908 <result> = invoke [cconv] [ret attrs] <ty>|<fnty> <fnptrval>(<function args>) [fn attrs]
Sanjoy Dasb513a9f2015-09-24 23:34:52 +00005909 [operand bundles] to label <normal label> unwind label <exception label>
Sean Silvab084af42012-12-07 10:36:55 +00005910
5911Overview:
5912"""""""""
5913
5914The '``invoke``' instruction causes control to transfer to a specified
5915function, with the possibility of control flow transfer to either the
5916'``normal``' label or the '``exception``' label. If the callee function
5917returns with the "``ret``" instruction, control flow will return to the
5918"normal" label. If the callee (or any indirect callees) returns via the
5919":ref:`resume <i_resume>`" instruction or other exception handling
5920mechanism, control is interrupted and continued at the dynamically
5921nearest "exception" label.
5922
5923The '``exception``' label is a `landing
5924pad <ExceptionHandling.html#overview>`_ for the exception. As such,
5925'``exception``' label is required to have the
5926":ref:`landingpad <i_landingpad>`" instruction, which contains the
5927information about the behavior of the program after unwinding happens,
5928as its first non-PHI instruction. The restrictions on the
5929"``landingpad``" instruction's tightly couples it to the "``invoke``"
5930instruction, so that the important information contained within the
5931"``landingpad``" instruction can't be lost through normal code motion.
5932
5933Arguments:
5934""""""""""
5935
5936This instruction requires several arguments:
5937
5938#. The optional "cconv" marker indicates which :ref:`calling
5939 convention <callingconv>` the call should use. If none is
5940 specified, the call defaults to using C calling conventions.
5941#. The optional :ref:`Parameter Attributes <paramattrs>` list for return
5942 values. Only '``zeroext``', '``signext``', and '``inreg``' attributes
5943 are valid here.
David Blaikieb83cf102016-07-13 17:21:34 +00005944#. '``ty``': the type of the call instruction itself which is also the
5945 type of the return value. Functions that return no value are marked
5946 ``void``.
5947#. '``fnty``': shall be the signature of the function being invoked. The
5948 argument types must match the types implied by this signature. This
5949 type can be omitted if the function is not varargs.
5950#. '``fnptrval``': An LLVM value containing a pointer to a function to
5951 be invoked. In most cases, this is a direct function invocation, but
5952 indirect ``invoke``'s are just as possible, calling an arbitrary pointer
5953 to function value.
Sean Silvab084af42012-12-07 10:36:55 +00005954#. '``function args``': argument list whose types match the function
5955 signature argument types and parameter attributes. All arguments must
5956 be of :ref:`first class <t_firstclass>` type. If the function signature
5957 indicates the function accepts a variable number of arguments, the
5958 extra arguments can be specified.
5959#. '``normal label``': the label reached when the called function
5960 executes a '``ret``' instruction.
5961#. '``exception label``': the label reached when a callee returns via
5962 the :ref:`resume <i_resume>` instruction or other exception handling
5963 mechanism.
George Burgess IV8a464a72017-04-13 05:00:31 +00005964#. The optional :ref:`function attributes <fnattrs>` list.
Sanjoy Dasb513a9f2015-09-24 23:34:52 +00005965#. The optional :ref:`operand bundles <opbundles>` list.
Sean Silvab084af42012-12-07 10:36:55 +00005966
5967Semantics:
5968""""""""""
5969
5970This instruction is designed to operate as a standard '``call``'
5971instruction in most regards. The primary difference is that it
5972establishes an association with a label, which is used by the runtime
5973library to unwind the stack.
5974
5975This instruction is used in languages with destructors to ensure that
5976proper cleanup is performed in the case of either a ``longjmp`` or a
5977thrown exception. Additionally, this is important for implementation of
5978'``catch``' clauses in high-level languages that support them.
5979
5980For the purposes of the SSA form, the definition of the value returned
5981by the '``invoke``' instruction is deemed to occur on the edge from the
5982current block to the "normal" label. If the callee unwinds then no
5983return value is available.
5984
5985Example:
5986""""""""
5987
5988.. code-block:: llvm
5989
5990 %retval = invoke i32 @Test(i32 15) to label %Continue
Tim Northover675a0962014-06-13 14:24:23 +00005991 unwind label %TestCleanup ; i32:retval set
Sean Silvab084af42012-12-07 10:36:55 +00005992 %retval = invoke coldcc i32 %Testfnptr(i32 15) to label %Continue
Tim Northover675a0962014-06-13 14:24:23 +00005993 unwind label %TestCleanup ; i32:retval set
Sean Silvab084af42012-12-07 10:36:55 +00005994
5995.. _i_resume:
5996
5997'``resume``' Instruction
5998^^^^^^^^^^^^^^^^^^^^^^^^
5999
6000Syntax:
6001"""""""
6002
6003::
6004
6005 resume <type> <value>
6006
6007Overview:
6008"""""""""
6009
6010The '``resume``' instruction is a terminator instruction that has no
6011successors.
6012
6013Arguments:
6014""""""""""
6015
6016The '``resume``' instruction requires one argument, which must have the
6017same type as the result of any '``landingpad``' instruction in the same
6018function.
6019
6020Semantics:
6021""""""""""
6022
6023The '``resume``' instruction resumes propagation of an existing
6024(in-flight) exception whose unwinding was interrupted with a
6025:ref:`landingpad <i_landingpad>` instruction.
6026
6027Example:
6028""""""""
6029
6030.. code-block:: llvm
6031
6032 resume { i8*, i32 } %exn
6033
David Majnemer8a1c45d2015-12-12 05:38:55 +00006034.. _i_catchswitch:
6035
6036'``catchswitch``' Instruction
Akira Hatanakacedf8e92015-12-14 05:15:40 +00006037^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
David Majnemer8a1c45d2015-12-12 05:38:55 +00006038
6039Syntax:
6040"""""""
6041
6042::
6043
6044 <resultval> = catchswitch within <parent> [ label <handler1>, label <handler2>, ... ] unwind to caller
6045 <resultval> = catchswitch within <parent> [ label <handler1>, label <handler2>, ... ] unwind label <default>
6046
6047Overview:
6048"""""""""
6049
6050The '``catchswitch``' instruction is used by `LLVM's exception handling system
6051<ExceptionHandling.html#overview>`_ to describe the set of possible catch handlers
6052that may be executed by the :ref:`EH personality routine <personalityfn>`.
6053
6054Arguments:
6055""""""""""
6056
6057The ``parent`` argument is the token of the funclet that contains the
6058``catchswitch`` instruction. If the ``catchswitch`` is not inside a funclet,
6059this operand may be the token ``none``.
6060
Joseph Tremoulete28885e2016-01-10 04:28:38 +00006061The ``default`` argument is the label of another basic block beginning with
6062either a ``cleanuppad`` or ``catchswitch`` instruction. This unwind destination
6063must be a legal target with respect to the ``parent`` links, as described in
6064the `exception handling documentation\ <ExceptionHandling.html#wineh-constraints>`_.
David Majnemer8a1c45d2015-12-12 05:38:55 +00006065
Joseph Tremoulete28885e2016-01-10 04:28:38 +00006066The ``handlers`` are a nonempty list of successor blocks that each begin with a
David Majnemer8a1c45d2015-12-12 05:38:55 +00006067:ref:`catchpad <i_catchpad>` instruction.
6068
6069Semantics:
6070""""""""""
6071
6072Executing this instruction transfers control to one of the successors in
6073``handlers``, if appropriate, or continues to unwind via the unwind label if
6074present.
6075
6076The ``catchswitch`` is both a terminator and a "pad" instruction, meaning that
6077it must be both the first non-phi instruction and last instruction in the basic
6078block. Therefore, it must be the only non-phi instruction in the block.
6079
6080Example:
6081""""""""
6082
Renato Golin124f2592016-07-20 12:16:38 +00006083.. code-block:: text
David Majnemer8a1c45d2015-12-12 05:38:55 +00006084
6085 dispatch1:
6086 %cs1 = catchswitch within none [label %handler0, label %handler1] unwind to caller
6087 dispatch2:
6088 %cs2 = catchswitch within %parenthandler [label %handler0] unwind label %cleanup
6089
David Majnemer654e1302015-07-31 17:58:14 +00006090.. _i_catchret:
6091
6092'``catchret``' Instruction
6093^^^^^^^^^^^^^^^^^^^^^^^^^^
6094
6095Syntax:
6096"""""""
6097
6098::
6099
David Majnemer8a1c45d2015-12-12 05:38:55 +00006100 catchret from <token> to label <normal>
David Majnemer654e1302015-07-31 17:58:14 +00006101
6102Overview:
6103"""""""""
6104
6105The '``catchret``' instruction is a terminator instruction that has a
6106single successor.
6107
6108
6109Arguments:
6110""""""""""
6111
Joseph Tremoulet8220bcc2015-08-23 00:26:33 +00006112The first argument to a '``catchret``' indicates which ``catchpad`` it
6113exits. It must be a :ref:`catchpad <i_catchpad>`.
6114The second argument to a '``catchret``' specifies where control will
6115transfer to next.
David Majnemer654e1302015-07-31 17:58:14 +00006116
6117Semantics:
6118""""""""""
6119
David Majnemer8a1c45d2015-12-12 05:38:55 +00006120The '``catchret``' instruction ends an existing (in-flight) exception whose
6121unwinding was interrupted with a :ref:`catchpad <i_catchpad>` instruction. The
6122:ref:`personality function <personalityfn>` gets a chance to execute arbitrary
6123code to, for example, destroy the active exception. Control then transfers to
6124``normal``.
Joseph Tremoulet9ce71f72015-09-03 09:09:43 +00006125
Joseph Tremoulete28885e2016-01-10 04:28:38 +00006126The ``token`` argument must be a token produced by a ``catchpad`` instruction.
6127If the specified ``catchpad`` is not the most-recently-entered not-yet-exited
6128funclet pad (as described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_),
6129the ``catchret``'s behavior is undefined.
David Majnemer654e1302015-07-31 17:58:14 +00006130
6131Example:
6132""""""""
6133
Renato Golin124f2592016-07-20 12:16:38 +00006134.. code-block:: text
David Majnemer654e1302015-07-31 17:58:14 +00006135
David Majnemer8a1c45d2015-12-12 05:38:55 +00006136 catchret from %catch label %continue
Joseph Tremoulet9ce71f72015-09-03 09:09:43 +00006137
David Majnemer654e1302015-07-31 17:58:14 +00006138.. _i_cleanupret:
6139
6140'``cleanupret``' Instruction
6141^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6142
6143Syntax:
6144"""""""
6145
6146::
6147
David Majnemer8a1c45d2015-12-12 05:38:55 +00006148 cleanupret from <value> unwind label <continue>
6149 cleanupret from <value> unwind to caller
David Majnemer654e1302015-07-31 17:58:14 +00006150
6151Overview:
6152"""""""""
6153
6154The '``cleanupret``' instruction is a terminator instruction that has
6155an optional successor.
6156
6157
6158Arguments:
6159""""""""""
6160
Joseph Tremoulet8220bcc2015-08-23 00:26:33 +00006161The '``cleanupret``' instruction requires one argument, which indicates
6162which ``cleanuppad`` it exits, and must be a :ref:`cleanuppad <i_cleanuppad>`.
Joseph Tremoulete28885e2016-01-10 04:28:38 +00006163If the specified ``cleanuppad`` is not the most-recently-entered not-yet-exited
6164funclet pad (as described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_),
6165the ``cleanupret``'s behavior is undefined.
6166
6167The '``cleanupret``' instruction also has an optional successor, ``continue``,
6168which must be the label of another basic block beginning with either a
6169``cleanuppad`` or ``catchswitch`` instruction. This unwind destination must
6170be a legal target with respect to the ``parent`` links, as described in the
6171`exception handling documentation\ <ExceptionHandling.html#wineh-constraints>`_.
David Majnemer654e1302015-07-31 17:58:14 +00006172
6173Semantics:
6174""""""""""
6175
6176The '``cleanupret``' instruction indicates to the
6177:ref:`personality function <personalityfn>` that one
6178:ref:`cleanuppad <i_cleanuppad>` it transferred control to has ended.
6179It transfers control to ``continue`` or unwinds out of the function.
Joseph Tremoulet9ce71f72015-09-03 09:09:43 +00006180
David Majnemer654e1302015-07-31 17:58:14 +00006181Example:
6182""""""""
6183
Renato Golin124f2592016-07-20 12:16:38 +00006184.. code-block:: text
David Majnemer654e1302015-07-31 17:58:14 +00006185
David Majnemer8a1c45d2015-12-12 05:38:55 +00006186 cleanupret from %cleanup unwind to caller
6187 cleanupret from %cleanup unwind label %continue
David Majnemer654e1302015-07-31 17:58:14 +00006188
Sean Silvab084af42012-12-07 10:36:55 +00006189.. _i_unreachable:
6190
6191'``unreachable``' Instruction
6192^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6193
6194Syntax:
6195"""""""
6196
6197::
6198
6199 unreachable
6200
6201Overview:
6202"""""""""
6203
6204The '``unreachable``' instruction has no defined semantics. This
6205instruction is used to inform the optimizer that a particular portion of
6206the code is not reachable. This can be used to indicate that the code
6207after a no-return function cannot be reached, and other facts.
6208
6209Semantics:
6210""""""""""
6211
6212The '``unreachable``' instruction has no defined semantics.
6213
6214.. _binaryops:
6215
6216Binary Operations
6217-----------------
6218
6219Binary operators are used to do most of the computation in a program.
6220They require two operands of the same type, execute an operation on
6221them, and produce a single value. The operands might represent multiple
6222data, as is the case with the :ref:`vector <t_vector>` data type. The
6223result value has the same type as its operands.
6224
6225There are several different binary operators:
6226
6227.. _i_add:
6228
6229'``add``' Instruction
6230^^^^^^^^^^^^^^^^^^^^^
6231
6232Syntax:
6233"""""""
6234
6235::
6236
Tim Northover675a0962014-06-13 14:24:23 +00006237 <result> = add <ty> <op1>, <op2> ; yields ty:result
6238 <result> = add nuw <ty> <op1>, <op2> ; yields ty:result
6239 <result> = add nsw <ty> <op1>, <op2> ; yields ty:result
6240 <result> = add nuw nsw <ty> <op1>, <op2> ; yields ty:result
Sean Silvab084af42012-12-07 10:36:55 +00006241
6242Overview:
6243"""""""""
6244
6245The '``add``' instruction returns the sum of its two operands.
6246
6247Arguments:
6248""""""""""
6249
6250The two arguments to the '``add``' instruction must be
6251:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
6252arguments must have identical types.
6253
6254Semantics:
6255""""""""""
6256
6257The value produced is the integer sum of the two operands.
6258
6259If the sum has unsigned overflow, the result returned is the
6260mathematical result modulo 2\ :sup:`n`\ , where n is the bit width of
6261the result.
6262
6263Because LLVM integers use a two's complement representation, this
6264instruction is appropriate for both signed and unsigned integers.
6265
6266``nuw`` and ``nsw`` stand for "No Unsigned Wrap" and "No Signed Wrap",
6267respectively. If the ``nuw`` and/or ``nsw`` keywords are present, the
6268result value of the ``add`` is a :ref:`poison value <poisonvalues>` if
6269unsigned and/or signed overflow, respectively, occurs.
6270
6271Example:
6272""""""""
6273
Renato Golin124f2592016-07-20 12:16:38 +00006274.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00006275
Tim Northover675a0962014-06-13 14:24:23 +00006276 <result> = add i32 4, %var ; yields i32:result = 4 + %var
Sean Silvab084af42012-12-07 10:36:55 +00006277
6278.. _i_fadd:
6279
6280'``fadd``' Instruction
6281^^^^^^^^^^^^^^^^^^^^^^
6282
6283Syntax:
6284"""""""
6285
6286::
6287
Tim Northover675a0962014-06-13 14:24:23 +00006288 <result> = fadd [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result
Sean Silvab084af42012-12-07 10:36:55 +00006289
6290Overview:
6291"""""""""
6292
6293The '``fadd``' instruction returns the sum of its two operands.
6294
6295Arguments:
6296""""""""""
6297
6298The two arguments to the '``fadd``' instruction must be :ref:`floating
6299point <t_floating>` or :ref:`vector <t_vector>` of floating point values.
6300Both arguments must have identical types.
6301
6302Semantics:
6303""""""""""
6304
6305The value produced is the floating point sum of the two operands. This
6306instruction can also take any number of :ref:`fast-math flags <fastmath>`,
6307which are optimization hints to enable otherwise unsafe floating point
6308optimizations:
6309
6310Example:
6311""""""""
6312
Renato Golin124f2592016-07-20 12:16:38 +00006313.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00006314
Tim Northover675a0962014-06-13 14:24:23 +00006315 <result> = fadd float 4.0, %var ; yields float:result = 4.0 + %var
Sean Silvab084af42012-12-07 10:36:55 +00006316
6317'``sub``' Instruction
6318^^^^^^^^^^^^^^^^^^^^^
6319
6320Syntax:
6321"""""""
6322
6323::
6324
Tim Northover675a0962014-06-13 14:24:23 +00006325 <result> = sub <ty> <op1>, <op2> ; yields ty:result
6326 <result> = sub nuw <ty> <op1>, <op2> ; yields ty:result
6327 <result> = sub nsw <ty> <op1>, <op2> ; yields ty:result
6328 <result> = sub nuw nsw <ty> <op1>, <op2> ; yields ty:result
Sean Silvab084af42012-12-07 10:36:55 +00006329
6330Overview:
6331"""""""""
6332
6333The '``sub``' instruction returns the difference of its two operands.
6334
6335Note that the '``sub``' instruction is used to represent the '``neg``'
6336instruction present in most other intermediate representations.
6337
6338Arguments:
6339""""""""""
6340
6341The two arguments to the '``sub``' instruction must be
6342:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
6343arguments must have identical types.
6344
6345Semantics:
6346""""""""""
6347
6348The value produced is the integer difference of the two operands.
6349
6350If the difference has unsigned overflow, the result returned is the
6351mathematical result modulo 2\ :sup:`n`\ , where n is the bit width of
6352the result.
6353
6354Because LLVM integers use a two's complement representation, this
6355instruction is appropriate for both signed and unsigned integers.
6356
6357``nuw`` and ``nsw`` stand for "No Unsigned Wrap" and "No Signed Wrap",
6358respectively. If the ``nuw`` and/or ``nsw`` keywords are present, the
6359result value of the ``sub`` is a :ref:`poison value <poisonvalues>` if
6360unsigned and/or signed overflow, respectively, occurs.
6361
6362Example:
6363""""""""
6364
Renato Golin124f2592016-07-20 12:16:38 +00006365.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00006366
Tim Northover675a0962014-06-13 14:24:23 +00006367 <result> = sub i32 4, %var ; yields i32:result = 4 - %var
6368 <result> = sub i32 0, %val ; yields i32:result = -%var
Sean Silvab084af42012-12-07 10:36:55 +00006369
6370.. _i_fsub:
6371
6372'``fsub``' Instruction
6373^^^^^^^^^^^^^^^^^^^^^^
6374
6375Syntax:
6376"""""""
6377
6378::
6379
Tim Northover675a0962014-06-13 14:24:23 +00006380 <result> = fsub [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result
Sean Silvab084af42012-12-07 10:36:55 +00006381
6382Overview:
6383"""""""""
6384
6385The '``fsub``' instruction returns the difference of its two operands.
6386
6387Note that the '``fsub``' instruction is used to represent the '``fneg``'
6388instruction present in most other intermediate representations.
6389
6390Arguments:
6391""""""""""
6392
6393The two arguments to the '``fsub``' instruction must be :ref:`floating
6394point <t_floating>` or :ref:`vector <t_vector>` of floating point values.
6395Both arguments must have identical types.
6396
6397Semantics:
6398""""""""""
6399
6400The value produced is the floating point difference of the two operands.
6401This instruction can also take any number of :ref:`fast-math
6402flags <fastmath>`, which are optimization hints to enable otherwise
6403unsafe floating point optimizations:
6404
6405Example:
6406""""""""
6407
Renato Golin124f2592016-07-20 12:16:38 +00006408.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00006409
Tim Northover675a0962014-06-13 14:24:23 +00006410 <result> = fsub float 4.0, %var ; yields float:result = 4.0 - %var
6411 <result> = fsub float -0.0, %val ; yields float:result = -%var
Sean Silvab084af42012-12-07 10:36:55 +00006412
6413'``mul``' Instruction
6414^^^^^^^^^^^^^^^^^^^^^
6415
6416Syntax:
6417"""""""
6418
6419::
6420
Tim Northover675a0962014-06-13 14:24:23 +00006421 <result> = mul <ty> <op1>, <op2> ; yields ty:result
6422 <result> = mul nuw <ty> <op1>, <op2> ; yields ty:result
6423 <result> = mul nsw <ty> <op1>, <op2> ; yields ty:result
6424 <result> = mul nuw nsw <ty> <op1>, <op2> ; yields ty:result
Sean Silvab084af42012-12-07 10:36:55 +00006425
6426Overview:
6427"""""""""
6428
6429The '``mul``' instruction returns the product of its two operands.
6430
6431Arguments:
6432""""""""""
6433
6434The two arguments to the '``mul``' instruction must be
6435:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
6436arguments must have identical types.
6437
6438Semantics:
6439""""""""""
6440
6441The value produced is the integer product of the two operands.
6442
6443If the result of the multiplication has unsigned overflow, the result
6444returned is the mathematical result modulo 2\ :sup:`n`\ , where n is the
6445bit width of the result.
6446
6447Because LLVM integers use a two's complement representation, and the
6448result is the same width as the operands, this instruction returns the
6449correct result for both signed and unsigned integers. If a full product
6450(e.g. ``i32`` * ``i32`` -> ``i64``) is needed, the operands should be
6451sign-extended or zero-extended as appropriate to the width of the full
6452product.
6453
6454``nuw`` and ``nsw`` stand for "No Unsigned Wrap" and "No Signed Wrap",
6455respectively. If the ``nuw`` and/or ``nsw`` keywords are present, the
6456result value of the ``mul`` is a :ref:`poison value <poisonvalues>` if
6457unsigned and/or signed overflow, respectively, occurs.
6458
6459Example:
6460""""""""
6461
Renato Golin124f2592016-07-20 12:16:38 +00006462.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00006463
Tim Northover675a0962014-06-13 14:24:23 +00006464 <result> = mul i32 4, %var ; yields i32:result = 4 * %var
Sean Silvab084af42012-12-07 10:36:55 +00006465
6466.. _i_fmul:
6467
6468'``fmul``' Instruction
6469^^^^^^^^^^^^^^^^^^^^^^
6470
6471Syntax:
6472"""""""
6473
6474::
6475
Tim Northover675a0962014-06-13 14:24:23 +00006476 <result> = fmul [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result
Sean Silvab084af42012-12-07 10:36:55 +00006477
6478Overview:
6479"""""""""
6480
6481The '``fmul``' instruction returns the product of its two operands.
6482
6483Arguments:
6484""""""""""
6485
6486The two arguments to the '``fmul``' instruction must be :ref:`floating
6487point <t_floating>` or :ref:`vector <t_vector>` of floating point values.
6488Both arguments must have identical types.
6489
6490Semantics:
6491""""""""""
6492
6493The value produced is the floating point product of the two operands.
6494This instruction can also take any number of :ref:`fast-math
6495flags <fastmath>`, which are optimization hints to enable otherwise
6496unsafe floating point optimizations:
6497
6498Example:
6499""""""""
6500
Renato Golin124f2592016-07-20 12:16:38 +00006501.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00006502
Tim Northover675a0962014-06-13 14:24:23 +00006503 <result> = fmul float 4.0, %var ; yields float:result = 4.0 * %var
Sean Silvab084af42012-12-07 10:36:55 +00006504
6505'``udiv``' Instruction
6506^^^^^^^^^^^^^^^^^^^^^^
6507
6508Syntax:
6509"""""""
6510
6511::
6512
Tim Northover675a0962014-06-13 14:24:23 +00006513 <result> = udiv <ty> <op1>, <op2> ; yields ty:result
6514 <result> = udiv exact <ty> <op1>, <op2> ; yields ty:result
Sean Silvab084af42012-12-07 10:36:55 +00006515
6516Overview:
6517"""""""""
6518
6519The '``udiv``' instruction returns the quotient of its two operands.
6520
6521Arguments:
6522""""""""""
6523
6524The two arguments to the '``udiv``' instruction must be
6525:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
6526arguments must have identical types.
6527
6528Semantics:
6529""""""""""
6530
6531The value produced is the unsigned integer quotient of the two operands.
6532
6533Note that unsigned integer division and signed integer division are
6534distinct operations; for signed integer division, use '``sdiv``'.
6535
Sanjay Patel2b1f6f42017-03-09 16:20:52 +00006536Division by zero is undefined behavior. For vectors, if any element
6537of the divisor is zero, the operation has undefined behavior.
6538
Sean Silvab084af42012-12-07 10:36:55 +00006539
6540If the ``exact`` keyword is present, the result value of the ``udiv`` is
6541a :ref:`poison value <poisonvalues>` if %op1 is not a multiple of %op2 (as
6542such, "((a udiv exact b) mul b) == a").
6543
6544Example:
6545""""""""
6546
Renato Golin124f2592016-07-20 12:16:38 +00006547.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00006548
Tim Northover675a0962014-06-13 14:24:23 +00006549 <result> = udiv i32 4, %var ; yields i32:result = 4 / %var
Sean Silvab084af42012-12-07 10:36:55 +00006550
6551'``sdiv``' Instruction
6552^^^^^^^^^^^^^^^^^^^^^^
6553
6554Syntax:
6555"""""""
6556
6557::
6558
Tim Northover675a0962014-06-13 14:24:23 +00006559 <result> = sdiv <ty> <op1>, <op2> ; yields ty:result
6560 <result> = sdiv exact <ty> <op1>, <op2> ; yields ty:result
Sean Silvab084af42012-12-07 10:36:55 +00006561
6562Overview:
6563"""""""""
6564
6565The '``sdiv``' instruction returns the quotient of its two operands.
6566
6567Arguments:
6568""""""""""
6569
6570The two arguments to the '``sdiv``' instruction must be
6571:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
6572arguments must have identical types.
6573
6574Semantics:
6575""""""""""
6576
6577The value produced is the signed integer quotient of the two operands
6578rounded towards zero.
6579
6580Note that signed integer division and unsigned integer division are
6581distinct operations; for unsigned integer division, use '``udiv``'.
6582
Sanjay Patel2b1f6f42017-03-09 16:20:52 +00006583Division by zero is undefined behavior. For vectors, if any element
6584of the divisor is zero, the operation has undefined behavior.
6585Overflow also leads to undefined behavior; this is a rare case, but can
6586occur, for example, by doing a 32-bit division of -2147483648 by -1.
Sean Silvab084af42012-12-07 10:36:55 +00006587
6588If the ``exact`` keyword is present, the result value of the ``sdiv`` is
6589a :ref:`poison value <poisonvalues>` if the result would be rounded.
6590
6591Example:
6592""""""""
6593
Renato Golin124f2592016-07-20 12:16:38 +00006594.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00006595
Tim Northover675a0962014-06-13 14:24:23 +00006596 <result> = sdiv i32 4, %var ; yields i32:result = 4 / %var
Sean Silvab084af42012-12-07 10:36:55 +00006597
6598.. _i_fdiv:
6599
6600'``fdiv``' Instruction
6601^^^^^^^^^^^^^^^^^^^^^^
6602
6603Syntax:
6604"""""""
6605
6606::
6607
Tim Northover675a0962014-06-13 14:24:23 +00006608 <result> = fdiv [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result
Sean Silvab084af42012-12-07 10:36:55 +00006609
6610Overview:
6611"""""""""
6612
6613The '``fdiv``' instruction returns the quotient of its two operands.
6614
6615Arguments:
6616""""""""""
6617
6618The two arguments to the '``fdiv``' instruction must be :ref:`floating
6619point <t_floating>` or :ref:`vector <t_vector>` of floating point values.
6620Both arguments must have identical types.
6621
6622Semantics:
6623""""""""""
6624
6625The value produced is the floating point quotient of the two operands.
6626This instruction can also take any number of :ref:`fast-math
6627flags <fastmath>`, which are optimization hints to enable otherwise
6628unsafe floating point optimizations:
6629
6630Example:
6631""""""""
6632
Renato Golin124f2592016-07-20 12:16:38 +00006633.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00006634
Tim Northover675a0962014-06-13 14:24:23 +00006635 <result> = fdiv float 4.0, %var ; yields float:result = 4.0 / %var
Sean Silvab084af42012-12-07 10:36:55 +00006636
6637'``urem``' Instruction
6638^^^^^^^^^^^^^^^^^^^^^^
6639
6640Syntax:
6641"""""""
6642
6643::
6644
Tim Northover675a0962014-06-13 14:24:23 +00006645 <result> = urem <ty> <op1>, <op2> ; yields ty:result
Sean Silvab084af42012-12-07 10:36:55 +00006646
6647Overview:
6648"""""""""
6649
6650The '``urem``' instruction returns the remainder from the unsigned
6651division of its two arguments.
6652
6653Arguments:
6654""""""""""
6655
6656The two arguments to the '``urem``' instruction must be
6657:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
6658arguments must have identical types.
6659
6660Semantics:
6661""""""""""
6662
6663This instruction returns the unsigned integer *remainder* of a division.
6664This instruction always performs an unsigned division to get the
6665remainder.
6666
6667Note that unsigned integer remainder and signed integer remainder are
6668distinct operations; for signed integer remainder, use '``srem``'.
Sanjay Patel2b1f6f42017-03-09 16:20:52 +00006669
6670Taking the remainder of a division by zero is undefined behavior.
6671For vectors, if any element of the divisor is zero, the operation has
6672undefined behavior.
Sean Silvab084af42012-12-07 10:36:55 +00006673
6674Example:
6675""""""""
6676
Renato Golin124f2592016-07-20 12:16:38 +00006677.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00006678
Tim Northover675a0962014-06-13 14:24:23 +00006679 <result> = urem i32 4, %var ; yields i32:result = 4 % %var
Sean Silvab084af42012-12-07 10:36:55 +00006680
6681'``srem``' Instruction
6682^^^^^^^^^^^^^^^^^^^^^^
6683
6684Syntax:
6685"""""""
6686
6687::
6688
Tim Northover675a0962014-06-13 14:24:23 +00006689 <result> = srem <ty> <op1>, <op2> ; yields ty:result
Sean Silvab084af42012-12-07 10:36:55 +00006690
6691Overview:
6692"""""""""
6693
6694The '``srem``' instruction returns the remainder from the signed
6695division of its two operands. This instruction can also take
6696:ref:`vector <t_vector>` versions of the values in which case the elements
6697must be integers.
6698
6699Arguments:
6700""""""""""
6701
6702The two arguments to the '``srem``' instruction must be
6703:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
6704arguments must have identical types.
6705
6706Semantics:
6707""""""""""
6708
6709This instruction returns the *remainder* of a division (where the result
6710is either zero or has the same sign as the dividend, ``op1``), not the
6711*modulo* operator (where the result is either zero or has the same sign
6712as the divisor, ``op2``) of a value. For more information about the
6713difference, see `The Math
6714Forum <http://mathforum.org/dr.math/problems/anne.4.28.99.html>`_. For a
6715table of how this is implemented in various languages, please see
6716`Wikipedia: modulo
6717operation <http://en.wikipedia.org/wiki/Modulo_operation>`_.
6718
6719Note that signed integer remainder and unsigned integer remainder are
6720distinct operations; for unsigned integer remainder, use '``urem``'.
6721
Sanjay Patel2b1f6f42017-03-09 16:20:52 +00006722Taking the remainder of a division by zero is undefined behavior.
6723For vectors, if any element of the divisor is zero, the operation has
6724undefined behavior.
Sean Silvab084af42012-12-07 10:36:55 +00006725Overflow also leads to undefined behavior; this is a rare case, but can
6726occur, for example, by taking the remainder of a 32-bit division of
6727-2147483648 by -1. (The remainder doesn't actually overflow, but this
6728rule lets srem be implemented using instructions that return both the
6729result of the division and the remainder.)
6730
6731Example:
6732""""""""
6733
Renato Golin124f2592016-07-20 12:16:38 +00006734.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00006735
Tim Northover675a0962014-06-13 14:24:23 +00006736 <result> = srem i32 4, %var ; yields i32:result = 4 % %var
Sean Silvab084af42012-12-07 10:36:55 +00006737
6738.. _i_frem:
6739
6740'``frem``' Instruction
6741^^^^^^^^^^^^^^^^^^^^^^
6742
6743Syntax:
6744"""""""
6745
6746::
6747
Tim Northover675a0962014-06-13 14:24:23 +00006748 <result> = frem [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result
Sean Silvab084af42012-12-07 10:36:55 +00006749
6750Overview:
6751"""""""""
6752
6753The '``frem``' instruction returns the remainder from the division of
6754its two operands.
6755
6756Arguments:
6757""""""""""
6758
6759The two arguments to the '``frem``' instruction must be :ref:`floating
6760point <t_floating>` or :ref:`vector <t_vector>` of floating point values.
6761Both arguments must have identical types.
6762
6763Semantics:
6764""""""""""
6765
6766This instruction returns the *remainder* of a division. The remainder
6767has the same sign as the dividend. This instruction can also take any
6768number of :ref:`fast-math flags <fastmath>`, which are optimization hints
6769to enable otherwise unsafe floating point optimizations:
6770
6771Example:
6772""""""""
6773
Renato Golin124f2592016-07-20 12:16:38 +00006774.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00006775
Tim Northover675a0962014-06-13 14:24:23 +00006776 <result> = frem float 4.0, %var ; yields float:result = 4.0 % %var
Sean Silvab084af42012-12-07 10:36:55 +00006777
6778.. _bitwiseops:
6779
6780Bitwise Binary Operations
6781-------------------------
6782
6783Bitwise binary operators are used to do various forms of bit-twiddling
6784in a program. They are generally very efficient instructions and can
6785commonly be strength reduced from other instructions. They require two
6786operands of the same type, execute an operation on them, and produce a
6787single value. The resulting value is the same type as its operands.
6788
6789'``shl``' Instruction
6790^^^^^^^^^^^^^^^^^^^^^
6791
6792Syntax:
6793"""""""
6794
6795::
6796
Tim Northover675a0962014-06-13 14:24:23 +00006797 <result> = shl <ty> <op1>, <op2> ; yields ty:result
6798 <result> = shl nuw <ty> <op1>, <op2> ; yields ty:result
6799 <result> = shl nsw <ty> <op1>, <op2> ; yields ty:result
6800 <result> = shl nuw nsw <ty> <op1>, <op2> ; yields ty:result
Sean Silvab084af42012-12-07 10:36:55 +00006801
6802Overview:
6803"""""""""
6804
6805The '``shl``' instruction returns the first operand shifted to the left
6806a specified number of bits.
6807
6808Arguments:
6809""""""""""
6810
6811Both arguments to the '``shl``' instruction must be the same
6812:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer type.
6813'``op2``' is treated as an unsigned value.
6814
6815Semantics:
6816""""""""""
6817
6818The value produced is ``op1`` \* 2\ :sup:`op2` mod 2\ :sup:`n`,
6819where ``n`` is the width of the result. If ``op2`` is (statically or
Sean Silvab8a108c2015-04-17 21:58:55 +00006820dynamically) equal to or larger than the number of bits in
Nuno Lopesb2781fb2017-06-06 08:28:17 +00006821``op1``, this instruction returns a :ref:`poison value <poisonvalues>`.
6822If the arguments are vectors, each vector element of ``op1`` is shifted
6823by the corresponding shift amount in ``op2``.
Sean Silvab084af42012-12-07 10:36:55 +00006824
Nuno Lopesb2781fb2017-06-06 08:28:17 +00006825If the ``nuw`` keyword is present, then the shift produces a poison
6826value if it shifts out any non-zero bits.
6827If the ``nsw`` keyword is present, then the shift produces a poison
6828value it shifts out any bits that disagree with the resultant sign bit.
Sean Silvab084af42012-12-07 10:36:55 +00006829
6830Example:
6831""""""""
6832
Renato Golin124f2592016-07-20 12:16:38 +00006833.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00006834
Tim Northover675a0962014-06-13 14:24:23 +00006835 <result> = shl i32 4, %var ; yields i32: 4 << %var
6836 <result> = shl i32 4, 2 ; yields i32: 16
6837 <result> = shl i32 1, 10 ; yields i32: 1024
Sean Silvab084af42012-12-07 10:36:55 +00006838 <result> = shl i32 1, 32 ; undefined
6839 <result> = shl <2 x i32> < i32 1, i32 1>, < i32 1, i32 2> ; yields: result=<2 x i32> < i32 2, i32 4>
6840
6841'``lshr``' Instruction
6842^^^^^^^^^^^^^^^^^^^^^^
6843
6844Syntax:
6845"""""""
6846
6847::
6848
Tim Northover675a0962014-06-13 14:24:23 +00006849 <result> = lshr <ty> <op1>, <op2> ; yields ty:result
6850 <result> = lshr exact <ty> <op1>, <op2> ; yields ty:result
Sean Silvab084af42012-12-07 10:36:55 +00006851
6852Overview:
6853"""""""""
6854
6855The '``lshr``' instruction (logical shift right) returns the first
6856operand shifted to the right a specified number of bits with zero fill.
6857
6858Arguments:
6859""""""""""
6860
6861Both arguments to the '``lshr``' instruction must be the same
6862:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer type.
6863'``op2``' is treated as an unsigned value.
6864
6865Semantics:
6866""""""""""
6867
6868This instruction always performs a logical shift right operation. The
6869most significant bits of the result will be filled with zero bits after
6870the shift. If ``op2`` is (statically or dynamically) equal to or larger
Nuno Lopesb2781fb2017-06-06 08:28:17 +00006871than the number of bits in ``op1``, this instruction returns a :ref:`poison
6872value <poisonvalues>`. If the arguments are vectors, each vector element
6873of ``op1`` is shifted by the corresponding shift amount in ``op2``.
Sean Silvab084af42012-12-07 10:36:55 +00006874
6875If the ``exact`` keyword is present, the result value of the ``lshr`` is
Nuno Lopesb2781fb2017-06-06 08:28:17 +00006876a poison value if any of the bits shifted out are non-zero.
Sean Silvab084af42012-12-07 10:36:55 +00006877
6878Example:
6879""""""""
6880
Renato Golin124f2592016-07-20 12:16:38 +00006881.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00006882
Tim Northover675a0962014-06-13 14:24:23 +00006883 <result> = lshr i32 4, 1 ; yields i32:result = 2
6884 <result> = lshr i32 4, 2 ; yields i32:result = 1
6885 <result> = lshr i8 4, 3 ; yields i8:result = 0
6886 <result> = lshr i8 -2, 1 ; yields i8:result = 0x7F
Sean Silvab084af42012-12-07 10:36:55 +00006887 <result> = lshr i32 1, 32 ; undefined
6888 <result> = lshr <2 x i32> < i32 -2, i32 4>, < i32 1, i32 2> ; yields: result=<2 x i32> < i32 0x7FFFFFFF, i32 1>
6889
6890'``ashr``' Instruction
6891^^^^^^^^^^^^^^^^^^^^^^
6892
6893Syntax:
6894"""""""
6895
6896::
6897
Tim Northover675a0962014-06-13 14:24:23 +00006898 <result> = ashr <ty> <op1>, <op2> ; yields ty:result
6899 <result> = ashr exact <ty> <op1>, <op2> ; yields ty:result
Sean Silvab084af42012-12-07 10:36:55 +00006900
6901Overview:
6902"""""""""
6903
6904The '``ashr``' instruction (arithmetic shift right) returns the first
6905operand shifted to the right a specified number of bits with sign
6906extension.
6907
6908Arguments:
6909""""""""""
6910
6911Both arguments to the '``ashr``' instruction must be the same
6912:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer type.
6913'``op2``' is treated as an unsigned value.
6914
6915Semantics:
6916""""""""""
6917
6918This instruction always performs an arithmetic shift right operation,
6919The most significant bits of the result will be filled with the sign bit
6920of ``op1``. If ``op2`` is (statically or dynamically) equal to or larger
Nuno Lopesb2781fb2017-06-06 08:28:17 +00006921than the number of bits in ``op1``, this instruction returns a :ref:`poison
6922value <poisonvalues>`. If the arguments are vectors, each vector element
6923of ``op1`` is shifted by the corresponding shift amount in ``op2``.
Sean Silvab084af42012-12-07 10:36:55 +00006924
6925If the ``exact`` keyword is present, the result value of the ``ashr`` is
Nuno Lopesb2781fb2017-06-06 08:28:17 +00006926a poison value if any of the bits shifted out are non-zero.
Sean Silvab084af42012-12-07 10:36:55 +00006927
6928Example:
6929""""""""
6930
Renato Golin124f2592016-07-20 12:16:38 +00006931.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00006932
Tim Northover675a0962014-06-13 14:24:23 +00006933 <result> = ashr i32 4, 1 ; yields i32:result = 2
6934 <result> = ashr i32 4, 2 ; yields i32:result = 1
6935 <result> = ashr i8 4, 3 ; yields i8:result = 0
6936 <result> = ashr i8 -2, 1 ; yields i8:result = -1
Sean Silvab084af42012-12-07 10:36:55 +00006937 <result> = ashr i32 1, 32 ; undefined
6938 <result> = ashr <2 x i32> < i32 -2, i32 4>, < i32 1, i32 3> ; yields: result=<2 x i32> < i32 -1, i32 0>
6939
6940'``and``' Instruction
6941^^^^^^^^^^^^^^^^^^^^^
6942
6943Syntax:
6944"""""""
6945
6946::
6947
Tim Northover675a0962014-06-13 14:24:23 +00006948 <result> = and <ty> <op1>, <op2> ; yields ty:result
Sean Silvab084af42012-12-07 10:36:55 +00006949
6950Overview:
6951"""""""""
6952
6953The '``and``' instruction returns the bitwise logical and of its two
6954operands.
6955
6956Arguments:
6957""""""""""
6958
6959The two arguments to the '``and``' instruction must be
6960:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
6961arguments must have identical types.
6962
6963Semantics:
6964""""""""""
6965
6966The truth table used for the '``and``' instruction is:
6967
6968+-----+-----+-----+
6969| In0 | In1 | Out |
6970+-----+-----+-----+
6971| 0 | 0 | 0 |
6972+-----+-----+-----+
6973| 0 | 1 | 0 |
6974+-----+-----+-----+
6975| 1 | 0 | 0 |
6976+-----+-----+-----+
6977| 1 | 1 | 1 |
6978+-----+-----+-----+
6979
6980Example:
6981""""""""
6982
Renato Golin124f2592016-07-20 12:16:38 +00006983.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00006984
Tim Northover675a0962014-06-13 14:24:23 +00006985 <result> = and i32 4, %var ; yields i32:result = 4 & %var
6986 <result> = and i32 15, 40 ; yields i32:result = 8
6987 <result> = and i32 4, 8 ; yields i32:result = 0
Sean Silvab084af42012-12-07 10:36:55 +00006988
6989'``or``' Instruction
6990^^^^^^^^^^^^^^^^^^^^
6991
6992Syntax:
6993"""""""
6994
6995::
6996
Tim Northover675a0962014-06-13 14:24:23 +00006997 <result> = or <ty> <op1>, <op2> ; yields ty:result
Sean Silvab084af42012-12-07 10:36:55 +00006998
6999Overview:
7000"""""""""
7001
7002The '``or``' instruction returns the bitwise logical inclusive or of its
7003two operands.
7004
7005Arguments:
7006""""""""""
7007
7008The two arguments to the '``or``' instruction must be
7009:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
7010arguments must have identical types.
7011
7012Semantics:
7013""""""""""
7014
7015The truth table used for the '``or``' instruction is:
7016
7017+-----+-----+-----+
7018| In0 | In1 | Out |
7019+-----+-----+-----+
7020| 0 | 0 | 0 |
7021+-----+-----+-----+
7022| 0 | 1 | 1 |
7023+-----+-----+-----+
7024| 1 | 0 | 1 |
7025+-----+-----+-----+
7026| 1 | 1 | 1 |
7027+-----+-----+-----+
7028
7029Example:
7030""""""""
7031
7032::
7033
Tim Northover675a0962014-06-13 14:24:23 +00007034 <result> = or i32 4, %var ; yields i32:result = 4 | %var
7035 <result> = or i32 15, 40 ; yields i32:result = 47
7036 <result> = or i32 4, 8 ; yields i32:result = 12
Sean Silvab084af42012-12-07 10:36:55 +00007037
7038'``xor``' Instruction
7039^^^^^^^^^^^^^^^^^^^^^
7040
7041Syntax:
7042"""""""
7043
7044::
7045
Tim Northover675a0962014-06-13 14:24:23 +00007046 <result> = xor <ty> <op1>, <op2> ; yields ty:result
Sean Silvab084af42012-12-07 10:36:55 +00007047
7048Overview:
7049"""""""""
7050
7051The '``xor``' instruction returns the bitwise logical exclusive or of
7052its two operands. The ``xor`` is used to implement the "one's
7053complement" operation, which is the "~" operator in C.
7054
7055Arguments:
7056""""""""""
7057
7058The two arguments to the '``xor``' instruction must be
7059:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
7060arguments must have identical types.
7061
7062Semantics:
7063""""""""""
7064
7065The truth table used for the '``xor``' instruction is:
7066
7067+-----+-----+-----+
7068| In0 | In1 | Out |
7069+-----+-----+-----+
7070| 0 | 0 | 0 |
7071+-----+-----+-----+
7072| 0 | 1 | 1 |
7073+-----+-----+-----+
7074| 1 | 0 | 1 |
7075+-----+-----+-----+
7076| 1 | 1 | 0 |
7077+-----+-----+-----+
7078
7079Example:
7080""""""""
7081
Renato Golin124f2592016-07-20 12:16:38 +00007082.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00007083
Tim Northover675a0962014-06-13 14:24:23 +00007084 <result> = xor i32 4, %var ; yields i32:result = 4 ^ %var
7085 <result> = xor i32 15, 40 ; yields i32:result = 39
7086 <result> = xor i32 4, 8 ; yields i32:result = 12
7087 <result> = xor i32 %V, -1 ; yields i32:result = ~%V
Sean Silvab084af42012-12-07 10:36:55 +00007088
7089Vector Operations
7090-----------------
7091
7092LLVM supports several instructions to represent vector operations in a
7093target-independent manner. These instructions cover the element-access
7094and vector-specific operations needed to process vectors effectively.
7095While LLVM does directly support these vector operations, many
7096sophisticated algorithms will want to use target-specific intrinsics to
7097take full advantage of a specific target.
7098
7099.. _i_extractelement:
7100
7101'``extractelement``' Instruction
7102^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7103
7104Syntax:
7105"""""""
7106
7107::
7108
Michael J. Spencer1f10c5ea2014-05-01 22:12:39 +00007109 <result> = extractelement <n x <ty>> <val>, <ty2> <idx> ; yields <ty>
Sean Silvab084af42012-12-07 10:36:55 +00007110
7111Overview:
7112"""""""""
7113
7114The '``extractelement``' instruction extracts a single scalar element
7115from a vector at a specified index.
7116
7117Arguments:
7118""""""""""
7119
7120The first operand of an '``extractelement``' instruction is a value of
7121:ref:`vector <t_vector>` type. The second operand is an index indicating
7122the position from which to extract the element. The index may be a
Michael J. Spencer1f10c5ea2014-05-01 22:12:39 +00007123variable of any integer type.
Sean Silvab084af42012-12-07 10:36:55 +00007124
7125Semantics:
7126""""""""""
7127
7128The result is a scalar of the same type as the element type of ``val``.
7129Its value is the value at position ``idx`` of ``val``. If ``idx``
7130exceeds the length of ``val``, the results are undefined.
7131
7132Example:
7133""""""""
7134
Renato Golin124f2592016-07-20 12:16:38 +00007135.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00007136
7137 <result> = extractelement <4 x i32> %vec, i32 0 ; yields i32
7138
7139.. _i_insertelement:
7140
7141'``insertelement``' Instruction
7142^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7143
7144Syntax:
7145"""""""
7146
7147::
7148
Michael J. Spencer1f10c5ea2014-05-01 22:12:39 +00007149 <result> = insertelement <n x <ty>> <val>, <ty> <elt>, <ty2> <idx> ; yields <n x <ty>>
Sean Silvab084af42012-12-07 10:36:55 +00007150
7151Overview:
7152"""""""""
7153
7154The '``insertelement``' instruction inserts a scalar element into a
7155vector at a specified index.
7156
7157Arguments:
7158""""""""""
7159
7160The first operand of an '``insertelement``' instruction is a value of
7161:ref:`vector <t_vector>` type. The second operand is a scalar value whose
7162type must equal the element type of the first operand. The third operand
7163is an index indicating the position at which to insert the value. The
Michael J. Spencer1f10c5ea2014-05-01 22:12:39 +00007164index may be a variable of any integer type.
Sean Silvab084af42012-12-07 10:36:55 +00007165
7166Semantics:
7167""""""""""
7168
7169The result is a vector of the same type as ``val``. Its element values
7170are those of ``val`` except at position ``idx``, where it gets the value
7171``elt``. If ``idx`` exceeds the length of ``val``, the results are
7172undefined.
7173
7174Example:
7175""""""""
7176
Renato Golin124f2592016-07-20 12:16:38 +00007177.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00007178
7179 <result> = insertelement <4 x i32> %vec, i32 1, i32 0 ; yields <4 x i32>
7180
7181.. _i_shufflevector:
7182
7183'``shufflevector``' Instruction
7184^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7185
7186Syntax:
7187"""""""
7188
7189::
7190
7191 <result> = shufflevector <n x <ty>> <v1>, <n x <ty>> <v2>, <m x i32> <mask> ; yields <m x <ty>>
7192
7193Overview:
7194"""""""""
7195
7196The '``shufflevector``' instruction constructs a permutation of elements
7197from two input vectors, returning a vector with the same element type as
7198the input and length that is the same as the shuffle mask.
7199
7200Arguments:
7201""""""""""
7202
7203The first two operands of a '``shufflevector``' instruction are vectors
7204with the same type. The third argument is a shuffle mask whose element
7205type is always 'i32'. The result of the instruction is a vector whose
7206length is the same as the shuffle mask and whose element type is the
7207same as the element type of the first two operands.
7208
7209The shuffle mask operand is required to be a constant vector with either
7210constant integer or undef values.
7211
7212Semantics:
7213""""""""""
7214
7215The elements of the two input vectors are numbered from left to right
7216across both of the vectors. The shuffle mask operand specifies, for each
7217element of the result vector, which element of the two input vectors the
Sanjay Patel6e410182017-04-12 18:39:53 +00007218result element gets. If the shuffle mask is undef, the result vector is
7219undef. If any element of the mask operand is undef, that element of the
7220result is undef. If the shuffle mask selects an undef element from one
7221of the input vectors, the resulting element is undef.
Sean Silvab084af42012-12-07 10:36:55 +00007222
7223Example:
7224""""""""
7225
Renato Golin124f2592016-07-20 12:16:38 +00007226.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00007227
7228 <result> = shufflevector <4 x i32> %v1, <4 x i32> %v2,
7229 <4 x i32> <i32 0, i32 4, i32 1, i32 5> ; yields <4 x i32>
7230 <result> = shufflevector <4 x i32> %v1, <4 x i32> undef,
7231 <4 x i32> <i32 0, i32 1, i32 2, i32 3> ; yields <4 x i32> - Identity shuffle.
7232 <result> = shufflevector <8 x i32> %v1, <8 x i32> undef,
7233 <4 x i32> <i32 0, i32 1, i32 2, i32 3> ; yields <4 x i32>
7234 <result> = shufflevector <4 x i32> %v1, <4 x i32> %v2,
7235 <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7 > ; yields <8 x i32>
7236
7237Aggregate Operations
7238--------------------
7239
7240LLVM supports several instructions for working with
7241:ref:`aggregate <t_aggregate>` values.
7242
7243.. _i_extractvalue:
7244
7245'``extractvalue``' Instruction
7246^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7247
7248Syntax:
7249"""""""
7250
7251::
7252
7253 <result> = extractvalue <aggregate type> <val>, <idx>{, <idx>}*
7254
7255Overview:
7256"""""""""
7257
7258The '``extractvalue``' instruction extracts the value of a member field
7259from an :ref:`aggregate <t_aggregate>` value.
7260
7261Arguments:
7262""""""""""
7263
7264The first operand of an '``extractvalue``' instruction is a value of
Arch D. Robisona7f8f252015-10-14 19:10:45 +00007265:ref:`struct <t_struct>` or :ref:`array <t_array>` type. The other operands are
Sean Silvab084af42012-12-07 10:36:55 +00007266constant indices to specify which value to extract in a similar manner
7267as indices in a '``getelementptr``' instruction.
7268
7269The major differences to ``getelementptr`` indexing are:
7270
7271- Since the value being indexed is not a pointer, the first index is
7272 omitted and assumed to be zero.
7273- At least one index must be specified.
7274- Not only struct indices but also array indices must be in bounds.
7275
7276Semantics:
7277""""""""""
7278
7279The result is the value at the position in the aggregate specified by
7280the index operands.
7281
7282Example:
7283""""""""
7284
Renato Golin124f2592016-07-20 12:16:38 +00007285.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00007286
7287 <result> = extractvalue {i32, float} %agg, 0 ; yields i32
7288
7289.. _i_insertvalue:
7290
7291'``insertvalue``' Instruction
7292^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7293
7294Syntax:
7295"""""""
7296
7297::
7298
7299 <result> = insertvalue <aggregate type> <val>, <ty> <elt>, <idx>{, <idx>}* ; yields <aggregate type>
7300
7301Overview:
7302"""""""""
7303
7304The '``insertvalue``' instruction inserts a value into a member field in
7305an :ref:`aggregate <t_aggregate>` value.
7306
7307Arguments:
7308""""""""""
7309
7310The first operand of an '``insertvalue``' instruction is a value of
7311:ref:`struct <t_struct>` or :ref:`array <t_array>` type. The second operand is
7312a first-class value to insert. The following operands are constant
7313indices indicating the position at which to insert the value in a
7314similar manner as indices in a '``extractvalue``' instruction. The value
7315to insert must have the same type as the value identified by the
7316indices.
7317
7318Semantics:
7319""""""""""
7320
7321The result is an aggregate of the same type as ``val``. Its value is
7322that of ``val`` except that the value at the position specified by the
7323indices is that of ``elt``.
7324
7325Example:
7326""""""""
7327
7328.. code-block:: llvm
7329
7330 %agg1 = insertvalue {i32, float} undef, i32 1, 0 ; yields {i32 1, float undef}
7331 %agg2 = insertvalue {i32, float} %agg1, float %val, 1 ; yields {i32 1, float %val}
Dan Liewffcfe7f2014-09-08 21:19:46 +00007332 %agg3 = insertvalue {i32, {float}} undef, float %val, 1, 0 ; yields {i32 undef, {float %val}}
Sean Silvab084af42012-12-07 10:36:55 +00007333
7334.. _memoryops:
7335
7336Memory Access and Addressing Operations
7337---------------------------------------
7338
7339A key design point of an SSA-based representation is how it represents
7340memory. In LLVM, no memory locations are in SSA form, which makes things
7341very simple. This section describes how to read, write, and allocate
7342memory in LLVM.
7343
7344.. _i_alloca:
7345
7346'``alloca``' Instruction
7347^^^^^^^^^^^^^^^^^^^^^^^^
7348
7349Syntax:
7350"""""""
7351
7352::
7353
Matt Arsenault3c1fc762017-04-10 22:27:50 +00007354 <result> = alloca [inalloca] <type> [, <ty> <NumElements>] [, align <alignment>] [, addrspace(<num>)] ; yields type addrspace(num)*:result
Sean Silvab084af42012-12-07 10:36:55 +00007355
7356Overview:
7357"""""""""
7358
7359The '``alloca``' instruction allocates memory on the stack frame of the
7360currently executing function, to be automatically released when this
7361function returns to its caller. The object is always allocated in the
Matt Arsenault3c1fc762017-04-10 22:27:50 +00007362address space for allocas indicated in the datalayout.
Sean Silvab084af42012-12-07 10:36:55 +00007363
7364Arguments:
7365""""""""""
7366
7367The '``alloca``' instruction allocates ``sizeof(<type>)*NumElements``
7368bytes of memory on the runtime stack, returning a pointer of the
7369appropriate type to the program. If "NumElements" is specified, it is
7370the number of elements allocated, otherwise "NumElements" is defaulted
7371to be one. If a constant alignment is specified, the value result of the
Reid Kleckner15fe7a52014-07-15 01:16:09 +00007372allocation is guaranteed to be aligned to at least that boundary. The
7373alignment may not be greater than ``1 << 29``. If not specified, or if
7374zero, the target can choose to align the allocation on any convenient
7375boundary compatible with the type.
Sean Silvab084af42012-12-07 10:36:55 +00007376
7377'``type``' may be any sized type.
7378
7379Semantics:
7380""""""""""
7381
7382Memory is allocated; a pointer is returned. The operation is undefined
7383if there is insufficient stack space for the allocation. '``alloca``'d
7384memory is automatically released when the function returns. The
7385'``alloca``' instruction is commonly used to represent automatic
7386variables that must have an address available. When the function returns
7387(either with the ``ret`` or ``resume`` instructions), the memory is
7388reclaimed. Allocating zero bytes is legal, but the result is undefined.
7389The order in which memory is allocated (ie., which way the stack grows)
7390is not specified.
7391
7392Example:
7393""""""""
7394
7395.. code-block:: llvm
7396
Tim Northover675a0962014-06-13 14:24:23 +00007397 %ptr = alloca i32 ; yields i32*:ptr
7398 %ptr = alloca i32, i32 4 ; yields i32*:ptr
7399 %ptr = alloca i32, i32 4, align 1024 ; yields i32*:ptr
7400 %ptr = alloca i32, align 1024 ; yields i32*:ptr
Sean Silvab084af42012-12-07 10:36:55 +00007401
7402.. _i_load:
7403
7404'``load``' Instruction
7405^^^^^^^^^^^^^^^^^^^^^^
7406
7407Syntax:
7408"""""""
7409
7410::
7411
Artur Pilipenkob4d00902015-09-28 17:41:08 +00007412 <result> = load [volatile] <ty>, <ty>* <pointer>[, align <alignment>][, !nontemporal !<index>][, !invariant.load !<index>][, !invariant.group !<index>][, !nonnull !<index>][, !dereferenceable !<deref_bytes_node>][, !dereferenceable_or_null !<deref_bytes_node>][, !align !<align_node>]
Konstantin Zhuravlyovbb80d3e2017-07-11 22:23:00 +00007413 <result> = load atomic [volatile] <ty>, <ty>* <pointer> [syncscope("<target-scope>")] <ordering>, align <alignment> [, !invariant.group !<index>]
Sean Silvab084af42012-12-07 10:36:55 +00007414 !<index> = !{ i32 1 }
Artur Pilipenko253d71e2015-09-18 12:07:10 +00007415 !<deref_bytes_node> = !{i64 <dereferenceable_bytes>}
Artur Pilipenkob4d00902015-09-28 17:41:08 +00007416 !<align_node> = !{ i64 <value_alignment> }
Sean Silvab084af42012-12-07 10:36:55 +00007417
7418Overview:
7419"""""""""
7420
7421The '``load``' instruction is used to read from memory.
7422
7423Arguments:
7424""""""""""
7425
Sanjoy Dasc2cf6ef2016-06-01 16:13:10 +00007426The argument to the ``load`` instruction specifies the memory address from which
7427to load. The type specified must be a :ref:`first class <t_firstclass>` type of
7428known size (i.e. not containing an :ref:`opaque structural type <t_opaque>`). If
7429the ``load`` is marked as ``volatile``, then the optimizer is not allowed to
7430modify the number or order of execution of this ``load`` with other
7431:ref:`volatile operations <volatile>`.
Sean Silvab084af42012-12-07 10:36:55 +00007432
JF Bastiend1fb5852015-12-17 22:09:19 +00007433If the ``load`` is marked as ``atomic``, it takes an extra :ref:`ordering
Konstantin Zhuravlyovbb80d3e2017-07-11 22:23:00 +00007434<ordering>` and optional ``syncscope("<target-scope>")`` argument. The
7435``release`` and ``acq_rel`` orderings are not valid on ``load`` instructions.
7436Atomic loads produce :ref:`defined <memmodel>` results when they may see
7437multiple atomic stores. The type of the pointee must be an integer, pointer, or
7438floating-point type whose bit width is a power of two greater than or equal to
7439eight and less than or equal to a target-specific size limit. ``align`` must be
7440explicitly specified on atomic loads, and the load has undefined behavior if the
7441alignment is not set to a value which is at least the size in bytes of the
JF Bastiend1fb5852015-12-17 22:09:19 +00007442pointee. ``!nontemporal`` does not have any defined semantics for atomic loads.
Sean Silvab084af42012-12-07 10:36:55 +00007443
7444The optional constant ``align`` argument specifies the alignment of the
7445operation (that is, the alignment of the memory address). A value of 0
Eli Bendersky239a78b2013-04-17 20:17:08 +00007446or an omitted ``align`` argument means that the operation has the ABI
Sean Silvab084af42012-12-07 10:36:55 +00007447alignment for the target. It is the responsibility of the code emitter
7448to ensure that the alignment information is correct. Overestimating the
7449alignment results in undefined behavior. Underestimating the alignment
Reid Kleckner15fe7a52014-07-15 01:16:09 +00007450may produce less efficient code. An alignment of 1 is always safe. The
Matt Arsenault7020f252016-06-16 16:33:41 +00007451maximum possible alignment is ``1 << 29``. An alignment value higher
7452than the size of the loaded type implies memory up to the alignment
7453value bytes can be safely loaded without trapping in the default
7454address space. Access of the high bytes can interfere with debugging
7455tools, so should not be accessed if the function has the
7456``sanitize_thread`` or ``sanitize_address`` attributes.
Sean Silvab084af42012-12-07 10:36:55 +00007457
7458The optional ``!nontemporal`` metadata must reference a single
Stefanus Du Toit736e2e22013-06-20 14:02:44 +00007459metadata name ``<index>`` corresponding to a metadata node with one
Sean Silvab084af42012-12-07 10:36:55 +00007460``i32`` entry of value 1. The existence of the ``!nontemporal``
Stefanus Du Toit736e2e22013-06-20 14:02:44 +00007461metadata on the instruction tells the optimizer and code generator
Sean Silvab084af42012-12-07 10:36:55 +00007462that this load is not expected to be reused in the cache. The code
7463generator may select special instructions to save cache bandwidth, such
7464as the ``MOVNT`` instruction on x86.
7465
7466The optional ``!invariant.load`` metadata must reference a single
Stefanus Du Toit736e2e22013-06-20 14:02:44 +00007467metadata name ``<index>`` corresponding to a metadata node with no
Geoff Berry4bda5762016-08-31 17:39:21 +00007468entries. If a load instruction tagged with the ``!invariant.load``
7469metadata is executed, the optimizer may assume the memory location
7470referenced by the load contains the same value at all points in the
7471program where the memory location is known to be dereferenceable.
Sean Silvab084af42012-12-07 10:36:55 +00007472
Piotr Padlewski6c15ec42015-09-15 18:32:14 +00007473The optional ``!invariant.group`` metadata must reference a single metadata name
7474 ``<index>`` corresponding to a metadata node. See ``invariant.group`` metadata.
7475
Philip Reamescdb72f32014-10-20 22:40:55 +00007476The optional ``!nonnull`` metadata must reference a single
7477metadata name ``<index>`` corresponding to a metadata node with no
7478entries. The existence of the ``!nonnull`` metadata on the
7479instruction tells the optimizer that the value loaded is known to
Piotr Padlewskid97846e2015-09-02 20:33:16 +00007480never be null. This is analogous to the ``nonnull`` attribute
Sean Silvaa1190322015-08-06 22:56:48 +00007481on parameters and return values. This metadata can only be applied
Mehdi Amini4a121fa2015-03-14 22:04:06 +00007482to loads of a pointer type.
Philip Reamescdb72f32014-10-20 22:40:55 +00007483
Artur Pilipenko253d71e2015-09-18 12:07:10 +00007484The optional ``!dereferenceable`` metadata must reference a single metadata
7485name ``<deref_bytes_node>`` corresponding to a metadata node with one ``i64``
Sean Silva706fba52015-08-06 22:56:24 +00007486entry. The existence of the ``!dereferenceable`` metadata on the instruction
Sanjoy Dasf9995472015-05-19 20:10:19 +00007487tells the optimizer that the value loaded is known to be dereferenceable.
Sean Silva706fba52015-08-06 22:56:24 +00007488The number of bytes known to be dereferenceable is specified by the integer
7489value in the metadata node. This is analogous to the ''dereferenceable''
7490attribute on parameters and return values. This metadata can only be applied
Sanjoy Dasf9995472015-05-19 20:10:19 +00007491to loads of a pointer type.
7492
7493The optional ``!dereferenceable_or_null`` metadata must reference a single
Artur Pilipenko253d71e2015-09-18 12:07:10 +00007494metadata name ``<deref_bytes_node>`` corresponding to a metadata node with one
7495``i64`` entry. The existence of the ``!dereferenceable_or_null`` metadata on the
Sanjoy Dasf9995472015-05-19 20:10:19 +00007496instruction tells the optimizer that the value loaded is known to be either
7497dereferenceable or null.
Sean Silva706fba52015-08-06 22:56:24 +00007498The number of bytes known to be dereferenceable is specified by the integer
7499value in the metadata node. This is analogous to the ''dereferenceable_or_null''
7500attribute on parameters and return values. This metadata can only be applied
Sanjoy Dasf9995472015-05-19 20:10:19 +00007501to loads of a pointer type.
7502
Artur Pilipenkob4d00902015-09-28 17:41:08 +00007503The optional ``!align`` metadata must reference a single metadata name
7504``<align_node>`` corresponding to a metadata node with one ``i64`` entry.
7505The existence of the ``!align`` metadata on the instruction tells the
7506optimizer that the value loaded is known to be aligned to a boundary specified
7507by the integer value in the metadata node. The alignment must be a power of 2.
7508This is analogous to the ''align'' attribute on parameters and return values.
7509This metadata can only be applied to loads of a pointer type.
7510
Sean Silvab084af42012-12-07 10:36:55 +00007511Semantics:
7512""""""""""
7513
7514The location of memory pointed to is loaded. If the value being loaded
7515is of scalar type then the number of bytes read does not exceed the
7516minimum number of bytes needed to hold all bits of the type. For
7517example, loading an ``i24`` reads at most three bytes. When loading a
7518value of a type like ``i20`` with a size that is not an integral number
7519of bytes, the result is undefined if the value was not originally
7520written using a store of the same type.
7521
7522Examples:
7523"""""""""
7524
7525.. code-block:: llvm
7526
Tim Northover675a0962014-06-13 14:24:23 +00007527 %ptr = alloca i32 ; yields i32*:ptr
7528 store i32 3, i32* %ptr ; yields void
David Blaikiec7aabbb2015-03-04 22:06:14 +00007529 %val = load i32, i32* %ptr ; yields i32:val = i32 3
Sean Silvab084af42012-12-07 10:36:55 +00007530
7531.. _i_store:
7532
7533'``store``' Instruction
7534^^^^^^^^^^^^^^^^^^^^^^^
7535
7536Syntax:
7537"""""""
7538
7539::
7540
Piotr Padlewski6c15ec42015-09-15 18:32:14 +00007541 store [volatile] <ty> <value>, <ty>* <pointer>[, align <alignment>][, !nontemporal !<index>][, !invariant.group !<index>] ; yields void
Konstantin Zhuravlyovbb80d3e2017-07-11 22:23:00 +00007542 store atomic [volatile] <ty> <value>, <ty>* <pointer> [syncscope("<target-scope>")] <ordering>, align <alignment> [, !invariant.group !<index>] ; yields void
Sean Silvab084af42012-12-07 10:36:55 +00007543
7544Overview:
7545"""""""""
7546
7547The '``store``' instruction is used to write to memory.
7548
7549Arguments:
7550""""""""""
7551
Sanjoy Dasc2cf6ef2016-06-01 16:13:10 +00007552There are two arguments to the ``store`` instruction: a value to store and an
7553address at which to store it. The type of the ``<pointer>`` operand must be a
7554pointer to the :ref:`first class <t_firstclass>` type of the ``<value>``
7555operand. If the ``store`` is marked as ``volatile``, then the optimizer is not
7556allowed to modify the number or order of execution of this ``store`` with other
7557:ref:`volatile operations <volatile>`. Only values of :ref:`first class
7558<t_firstclass>` types of known size (i.e. not containing an :ref:`opaque
7559structural type <t_opaque>`) can be stored.
Sean Silvab084af42012-12-07 10:36:55 +00007560
JF Bastiend1fb5852015-12-17 22:09:19 +00007561If the ``store`` is marked as ``atomic``, it takes an extra :ref:`ordering
Konstantin Zhuravlyovbb80d3e2017-07-11 22:23:00 +00007562<ordering>` and optional ``syncscope("<target-scope>")`` argument. The
7563``acquire`` and ``acq_rel`` orderings aren't valid on ``store`` instructions.
7564Atomic loads produce :ref:`defined <memmodel>` results when they may see
7565multiple atomic stores. The type of the pointee must be an integer, pointer, or
7566floating-point type whose bit width is a power of two greater than or equal to
7567eight and less than or equal to a target-specific size limit. ``align`` must be
7568explicitly specified on atomic stores, and the store has undefined behavior if
7569the alignment is not set to a value which is at least the size in bytes of the
JF Bastiend1fb5852015-12-17 22:09:19 +00007570pointee. ``!nontemporal`` does not have any defined semantics for atomic stores.
Sean Silvab084af42012-12-07 10:36:55 +00007571
Eli Benderskyca380842013-04-17 17:17:20 +00007572The optional constant ``align`` argument specifies the alignment of the
Sean Silvab084af42012-12-07 10:36:55 +00007573operation (that is, the alignment of the memory address). A value of 0
Eli Benderskyca380842013-04-17 17:17:20 +00007574or an omitted ``align`` argument means that the operation has the ABI
Sean Silvab084af42012-12-07 10:36:55 +00007575alignment for the target. It is the responsibility of the code emitter
7576to ensure that the alignment information is correct. Overestimating the
Eli Benderskyca380842013-04-17 17:17:20 +00007577alignment results in undefined behavior. Underestimating the
Sean Silvab084af42012-12-07 10:36:55 +00007578alignment may produce less efficient code. An alignment of 1 is always
Matt Arsenault7020f252016-06-16 16:33:41 +00007579safe. The maximum possible alignment is ``1 << 29``. An alignment
7580value higher than the size of the stored type implies memory up to the
7581alignment value bytes can be stored to without trapping in the default
7582address space. Storing to the higher bytes however may result in data
7583races if another thread can access the same address. Introducing a
7584data race is not allowed. Storing to the extra bytes is not allowed
7585even in situations where a data race is known to not exist if the
7586function has the ``sanitize_address`` attribute.
Sean Silvab084af42012-12-07 10:36:55 +00007587
Stefanus Du Toit736e2e22013-06-20 14:02:44 +00007588The optional ``!nontemporal`` metadata must reference a single metadata
Eli Benderskyca380842013-04-17 17:17:20 +00007589name ``<index>`` corresponding to a metadata node with one ``i32`` entry of
Stefanus Du Toit736e2e22013-06-20 14:02:44 +00007590value 1. The existence of the ``!nontemporal`` metadata on the instruction
Sean Silvab084af42012-12-07 10:36:55 +00007591tells the optimizer and code generator that this load is not expected to
7592be reused in the cache. The code generator may select special
JF Bastiend2d8ffd2016-01-13 04:52:26 +00007593instructions to save cache bandwidth, such as the ``MOVNT`` instruction on
Sean Silvab084af42012-12-07 10:36:55 +00007594x86.
7595
Piotr Padlewski6c15ec42015-09-15 18:32:14 +00007596The optional ``!invariant.group`` metadata must reference a
7597single metadata name ``<index>``. See ``invariant.group`` metadata.
7598
Sean Silvab084af42012-12-07 10:36:55 +00007599Semantics:
7600""""""""""
7601
Eli Benderskyca380842013-04-17 17:17:20 +00007602The contents of memory are updated to contain ``<value>`` at the
7603location specified by the ``<pointer>`` operand. If ``<value>`` is
Sean Silvab084af42012-12-07 10:36:55 +00007604of scalar type then the number of bytes written does not exceed the
7605minimum number of bytes needed to hold all bits of the type. For
7606example, storing an ``i24`` writes at most three bytes. When writing a
7607value of a type like ``i20`` with a size that is not an integral number
7608of bytes, it is unspecified what happens to the extra bits that do not
7609belong to the type, but they will typically be overwritten.
7610
7611Example:
7612""""""""
7613
7614.. code-block:: llvm
7615
Tim Northover675a0962014-06-13 14:24:23 +00007616 %ptr = alloca i32 ; yields i32*:ptr
7617 store i32 3, i32* %ptr ; yields void
Nick Lewycky149d04c2015-08-11 01:05:16 +00007618 %val = load i32, i32* %ptr ; yields i32:val = i32 3
Sean Silvab084af42012-12-07 10:36:55 +00007619
7620.. _i_fence:
7621
7622'``fence``' Instruction
7623^^^^^^^^^^^^^^^^^^^^^^^
7624
7625Syntax:
7626"""""""
7627
7628::
7629
Konstantin Zhuravlyovbb80d3e2017-07-11 22:23:00 +00007630 fence [syncscope("<target-scope>")] <ordering> ; yields void
Sean Silvab084af42012-12-07 10:36:55 +00007631
7632Overview:
7633"""""""""
7634
7635The '``fence``' instruction is used to introduce happens-before edges
7636between operations.
7637
7638Arguments:
7639""""""""""
7640
7641'``fence``' instructions take an :ref:`ordering <ordering>` argument which
7642defines what *synchronizes-with* edges they add. They can only be given
7643``acquire``, ``release``, ``acq_rel``, and ``seq_cst`` orderings.
7644
7645Semantics:
7646""""""""""
7647
7648A fence A which has (at least) ``release`` ordering semantics
7649*synchronizes with* a fence B with (at least) ``acquire`` ordering
7650semantics if and only if there exist atomic operations X and Y, both
7651operating on some atomic object M, such that A is sequenced before X, X
7652modifies M (either directly or through some side effect of a sequence
7653headed by X), Y is sequenced before B, and Y observes M. This provides a
7654*happens-before* dependency between A and B. Rather than an explicit
7655``fence``, one (but not both) of the atomic operations X or Y might
7656provide a ``release`` or ``acquire`` (resp.) ordering constraint and
7657still *synchronize-with* the explicit ``fence`` and establish the
7658*happens-before* edge.
7659
7660A ``fence`` which has ``seq_cst`` ordering, in addition to having both
7661``acquire`` and ``release`` semantics specified above, participates in
7662the global program order of other ``seq_cst`` operations and/or fences.
7663
Konstantin Zhuravlyovbb80d3e2017-07-11 22:23:00 +00007664A ``fence`` instruction can also take an optional
7665":ref:`syncscope <syncscope>`" argument.
Sean Silvab084af42012-12-07 10:36:55 +00007666
7667Example:
7668""""""""
7669
7670.. code-block:: llvm
7671
Konstantin Zhuravlyovbb80d3e2017-07-11 22:23:00 +00007672 fence acquire ; yields void
7673 fence syncscope("singlethread") seq_cst ; yields void
7674 fence syncscope("agent") seq_cst ; yields void
Sean Silvab084af42012-12-07 10:36:55 +00007675
7676.. _i_cmpxchg:
7677
7678'``cmpxchg``' Instruction
7679^^^^^^^^^^^^^^^^^^^^^^^^^
7680
7681Syntax:
7682"""""""
7683
7684::
7685
Konstantin Zhuravlyovbb80d3e2017-07-11 22:23:00 +00007686 cmpxchg [weak] [volatile] <ty>* <pointer>, <ty> <cmp>, <ty> <new> [syncscope("<target-scope>")] <success ordering> <failure ordering> ; yields { ty, i1 }
Sean Silvab084af42012-12-07 10:36:55 +00007687
7688Overview:
7689"""""""""
7690
7691The '``cmpxchg``' instruction is used to atomically modify memory. It
7692loads a value in memory and compares it to a given value. If they are
Tim Northover420a2162014-06-13 14:24:07 +00007693equal, it tries to store a new value into the memory.
Sean Silvab084af42012-12-07 10:36:55 +00007694
7695Arguments:
7696""""""""""
7697
7698There are three arguments to the '``cmpxchg``' instruction: an address
7699to operate on, a value to compare to the value currently be at that
7700address, and a new value to place at that address if the compared values
Philip Reames1960cfd2016-02-19 00:06:41 +00007701are equal. The type of '<cmp>' must be an integer or pointer type whose
7702bit width is a power of two greater than or equal to eight and less
7703than or equal to a target-specific size limit. '<cmp>' and '<new>' must
7704have the same type, and the type of '<pointer>' must be a pointer to
7705that type. If the ``cmpxchg`` is marked as ``volatile``, then the
7706optimizer is not allowed to modify the number or order of execution of
7707this ``cmpxchg`` with other :ref:`volatile operations <volatile>`.
Sean Silvab084af42012-12-07 10:36:55 +00007708
Tim Northovere94a5182014-03-11 10:48:52 +00007709The success and failure :ref:`ordering <ordering>` arguments specify how this
Tim Northover1dcc9f92014-06-13 14:24:16 +00007710``cmpxchg`` synchronizes with other atomic operations. Both ordering parameters
7711must be at least ``monotonic``, the ordering constraint on failure must be no
7712stronger than that on success, and the failure ordering cannot be either
7713``release`` or ``acq_rel``.
Sean Silvab084af42012-12-07 10:36:55 +00007714
Konstantin Zhuravlyovbb80d3e2017-07-11 22:23:00 +00007715A ``cmpxchg`` instruction can also take an optional
7716":ref:`syncscope <syncscope>`" argument.
Sean Silvab084af42012-12-07 10:36:55 +00007717
7718The pointer passed into cmpxchg must have alignment greater than or
7719equal to the size in memory of the operand.
7720
7721Semantics:
7722""""""""""
7723
Tim Northover420a2162014-06-13 14:24:07 +00007724The contents of memory at the location specified by the '``<pointer>``' operand
Matthias Braun93f2b4b2017-08-09 22:22:04 +00007725is read and compared to '``<cmp>``'; if the values are equal, '``<new>``' is
7726written to the location. The original value at the location is returned,
7727together with a flag indicating success (true) or failure (false).
Tim Northover420a2162014-06-13 14:24:07 +00007728
7729If the cmpxchg operation is marked as ``weak`` then a spurious failure is
7730permitted: the operation may not write ``<new>`` even if the comparison
7731matched.
7732
7733If the cmpxchg operation is strong (the default), the i1 value is 1 if and only
7734if the value loaded equals ``cmp``.
Sean Silvab084af42012-12-07 10:36:55 +00007735
Tim Northovere94a5182014-03-11 10:48:52 +00007736A successful ``cmpxchg`` is a read-modify-write instruction for the purpose of
7737identifying release sequences. A failed ``cmpxchg`` is equivalent to an atomic
7738load with an ordering parameter determined the second ordering parameter.
Sean Silvab084af42012-12-07 10:36:55 +00007739
7740Example:
7741""""""""
7742
7743.. code-block:: llvm
7744
7745 entry:
Duncan P. N. Exon Smithc917c7a2016-02-07 05:06:35 +00007746 %orig = load atomic i32, i32* %ptr unordered, align 4 ; yields i32
Sean Silvab084af42012-12-07 10:36:55 +00007747 br label %loop
7748
7749 loop:
Duncan P. N. Exon Smithc917c7a2016-02-07 05:06:35 +00007750 %cmp = phi i32 [ %orig, %entry ], [%value_loaded, %loop]
Sean Silvab084af42012-12-07 10:36:55 +00007751 %squared = mul i32 %cmp, %cmp
Tim Northover675a0962014-06-13 14:24:23 +00007752 %val_success = cmpxchg i32* %ptr, i32 %cmp, i32 %squared acq_rel monotonic ; yields { i32, i1 }
Tim Northover420a2162014-06-13 14:24:07 +00007753 %value_loaded = extractvalue { i32, i1 } %val_success, 0
7754 %success = extractvalue { i32, i1 } %val_success, 1
Sean Silvab084af42012-12-07 10:36:55 +00007755 br i1 %success, label %done, label %loop
7756
7757 done:
7758 ...
7759
7760.. _i_atomicrmw:
7761
7762'``atomicrmw``' Instruction
7763^^^^^^^^^^^^^^^^^^^^^^^^^^^
7764
7765Syntax:
7766"""""""
7767
7768::
7769
Konstantin Zhuravlyovbb80d3e2017-07-11 22:23:00 +00007770 atomicrmw [volatile] <operation> <ty>* <pointer>, <ty> <value> [syncscope("<target-scope>")] <ordering> ; yields ty
Sean Silvab084af42012-12-07 10:36:55 +00007771
7772Overview:
7773"""""""""
7774
7775The '``atomicrmw``' instruction is used to atomically modify memory.
7776
7777Arguments:
7778""""""""""
7779
7780There are three arguments to the '``atomicrmw``' instruction: an
7781operation to apply, an address whose value to modify, an argument to the
7782operation. The operation must be one of the following keywords:
7783
7784- xchg
7785- add
7786- sub
7787- and
7788- nand
7789- or
7790- xor
7791- max
7792- min
7793- umax
7794- umin
7795
7796The type of '<value>' must be an integer type whose bit width is a power
7797of two greater than or equal to eight and less than or equal to a
7798target-specific size limit. The type of the '``<pointer>``' operand must
7799be a pointer to that type. If the ``atomicrmw`` is marked as
7800``volatile``, then the optimizer is not allowed to modify the number or
7801order of execution of this ``atomicrmw`` with other :ref:`volatile
7802operations <volatile>`.
7803
Konstantin Zhuravlyovbb80d3e2017-07-11 22:23:00 +00007804A ``atomicrmw`` instruction can also take an optional
7805":ref:`syncscope <syncscope>`" argument.
7806
Sean Silvab084af42012-12-07 10:36:55 +00007807Semantics:
7808""""""""""
7809
7810The contents of memory at the location specified by the '``<pointer>``'
7811operand are atomically read, modified, and written back. The original
7812value at the location is returned. The modification is specified by the
7813operation argument:
7814
7815- xchg: ``*ptr = val``
7816- add: ``*ptr = *ptr + val``
7817- sub: ``*ptr = *ptr - val``
7818- and: ``*ptr = *ptr & val``
7819- nand: ``*ptr = ~(*ptr & val)``
7820- or: ``*ptr = *ptr | val``
7821- xor: ``*ptr = *ptr ^ val``
7822- max: ``*ptr = *ptr > val ? *ptr : val`` (using a signed comparison)
7823- min: ``*ptr = *ptr < val ? *ptr : val`` (using a signed comparison)
7824- umax: ``*ptr = *ptr > val ? *ptr : val`` (using an unsigned
7825 comparison)
7826- umin: ``*ptr = *ptr < val ? *ptr : val`` (using an unsigned
7827 comparison)
7828
7829Example:
7830""""""""
7831
7832.. code-block:: llvm
7833
Tim Northover675a0962014-06-13 14:24:23 +00007834 %old = atomicrmw add i32* %ptr, i32 1 acquire ; yields i32
Sean Silvab084af42012-12-07 10:36:55 +00007835
7836.. _i_getelementptr:
7837
7838'``getelementptr``' Instruction
7839^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7840
7841Syntax:
7842"""""""
7843
7844::
7845
Peter Collingbourned93620b2016-11-10 22:34:55 +00007846 <result> = getelementptr <ty>, <ty>* <ptrval>{, [inrange] <ty> <idx>}*
7847 <result> = getelementptr inbounds <ty>, <ty>* <ptrval>{, [inrange] <ty> <idx>}*
7848 <result> = getelementptr <ty>, <ptr vector> <ptrval>, [inrange] <vector index type> <idx>
Sean Silvab084af42012-12-07 10:36:55 +00007849
7850Overview:
7851"""""""""
7852
7853The '``getelementptr``' instruction is used to get the address of a
7854subelement of an :ref:`aggregate <t_aggregate>` data structure. It performs
Elena Demikhovsky37a4da82015-07-09 07:42:48 +00007855address calculation only and does not access memory. The instruction can also
7856be used to calculate a vector of such addresses.
Sean Silvab084af42012-12-07 10:36:55 +00007857
7858Arguments:
7859""""""""""
7860
David Blaikie16a97eb2015-03-04 22:02:58 +00007861The first argument is always a type used as the basis for the calculations.
7862The second argument is always a pointer or a vector of pointers, and is the
7863base address to start from. The remaining arguments are indices
Sean Silvab084af42012-12-07 10:36:55 +00007864that indicate which of the elements of the aggregate object are indexed.
7865The interpretation of each index is dependent on the type being indexed
7866into. The first index always indexes the pointer value given as the
David Blaikief91b0302017-06-19 05:34:21 +00007867second argument, the second index indexes a value of the type pointed to
Sean Silvab084af42012-12-07 10:36:55 +00007868(not necessarily the value directly pointed to, since the first index
7869can be non-zero), etc. The first type indexed into must be a pointer
7870value, subsequent types can be arrays, vectors, and structs. Note that
7871subsequent types being indexed into can never be pointers, since that
7872would require loading the pointer before continuing calculation.
7873
7874The type of each index argument depends on the type it is indexing into.
7875When indexing into a (optionally packed) structure, only ``i32`` integer
7876**constants** are allowed (when using a vector of indices they must all
7877be the **same** ``i32`` integer constant). When indexing into an array,
7878pointer or vector, integers of any width are allowed, and they are not
7879required to be constant. These integers are treated as signed values
7880where relevant.
7881
7882For example, let's consider a C code fragment and how it gets compiled
7883to LLVM:
7884
7885.. code-block:: c
7886
7887 struct RT {
7888 char A;
7889 int B[10][20];
7890 char C;
7891 };
7892 struct ST {
7893 int X;
7894 double Y;
7895 struct RT Z;
7896 };
7897
7898 int *foo(struct ST *s) {
7899 return &s[1].Z.B[5][13];
7900 }
7901
7902The LLVM code generated by Clang is:
7903
7904.. code-block:: llvm
7905
7906 %struct.RT = type { i8, [10 x [20 x i32]], i8 }
7907 %struct.ST = type { i32, double, %struct.RT }
7908
7909 define i32* @foo(%struct.ST* %s) nounwind uwtable readnone optsize ssp {
7910 entry:
David Blaikie16a97eb2015-03-04 22:02:58 +00007911 %arrayidx = getelementptr inbounds %struct.ST, %struct.ST* %s, i64 1, i32 2, i32 1, i64 5, i64 13
Sean Silvab084af42012-12-07 10:36:55 +00007912 ret i32* %arrayidx
7913 }
7914
7915Semantics:
7916""""""""""
7917
7918In the example above, the first index is indexing into the
7919'``%struct.ST*``' type, which is a pointer, yielding a '``%struct.ST``'
7920= '``{ i32, double, %struct.RT }``' type, a structure. The second index
7921indexes into the third element of the structure, yielding a
7922'``%struct.RT``' = '``{ i8 , [10 x [20 x i32]], i8 }``' type, another
7923structure. The third index indexes into the second element of the
7924structure, yielding a '``[10 x [20 x i32]]``' type, an array. The two
7925dimensions of the array are subscripted into, yielding an '``i32``'
7926type. The '``getelementptr``' instruction returns a pointer to this
7927element, thus computing a value of '``i32*``' type.
7928
7929Note that it is perfectly legal to index partially through a structure,
7930returning a pointer to an inner element. Because of this, the LLVM code
7931for the given testcase is equivalent to:
7932
7933.. code-block:: llvm
7934
7935 define i32* @foo(%struct.ST* %s) {
David Blaikie16a97eb2015-03-04 22:02:58 +00007936 %t1 = getelementptr %struct.ST, %struct.ST* %s, i32 1 ; yields %struct.ST*:%t1
7937 %t2 = getelementptr %struct.ST, %struct.ST* %t1, i32 0, i32 2 ; yields %struct.RT*:%t2
7938 %t3 = getelementptr %struct.RT, %struct.RT* %t2, i32 0, i32 1 ; yields [10 x [20 x i32]]*:%t3
7939 %t4 = getelementptr [10 x [20 x i32]], [10 x [20 x i32]]* %t3, i32 0, i32 5 ; yields [20 x i32]*:%t4
7940 %t5 = getelementptr [20 x i32], [20 x i32]* %t4, i32 0, i32 13 ; yields i32*:%t5
Sean Silvab084af42012-12-07 10:36:55 +00007941 ret i32* %t5
7942 }
7943
7944If the ``inbounds`` keyword is present, the result value of the
7945``getelementptr`` is a :ref:`poison value <poisonvalues>` if the base
7946pointer is not an *in bounds* address of an allocated object, or if any
7947of the addresses that would be formed by successive addition of the
7948offsets implied by the indices to the base address with infinitely
7949precise signed arithmetic are not an *in bounds* address of that
7950allocated object. The *in bounds* addresses for an allocated object are
7951all the addresses that point into the object, plus the address one byte
Eli Friedman13f2e352017-02-23 00:48:18 +00007952past the end. The only *in bounds* address for a null pointer in the
7953default address-space is the null pointer itself. In cases where the
7954base is a vector of pointers the ``inbounds`` keyword applies to each
7955of the computations element-wise.
Sean Silvab084af42012-12-07 10:36:55 +00007956
7957If the ``inbounds`` keyword is not present, the offsets are added to the
7958base address with silently-wrapping two's complement arithmetic. If the
7959offsets have a different width from the pointer, they are sign-extended
7960or truncated to the width of the pointer. The result value of the
7961``getelementptr`` may be outside the object pointed to by the base
7962pointer. The result value may not necessarily be used to access memory
7963though, even if it happens to point into allocated storage. See the
7964:ref:`Pointer Aliasing Rules <pointeraliasing>` section for more
7965information.
7966
Peter Collingbourned93620b2016-11-10 22:34:55 +00007967If the ``inrange`` keyword is present before any index, loading from or
7968storing to any pointer derived from the ``getelementptr`` has undefined
7969behavior if the load or store would access memory outside of the bounds of
7970the element selected by the index marked as ``inrange``. The result of a
7971pointer comparison or ``ptrtoint`` (including ``ptrtoint``-like operations
7972involving memory) involving a pointer derived from a ``getelementptr`` with
7973the ``inrange`` keyword is undefined, with the exception of comparisons
7974in the case where both operands are in the range of the element selected
7975by the ``inrange`` keyword, inclusive of the address one past the end of
7976that element. Note that the ``inrange`` keyword is currently only allowed
7977in constant ``getelementptr`` expressions.
7978
Sean Silvab084af42012-12-07 10:36:55 +00007979The getelementptr instruction is often confusing. For some more insight
7980into how it works, see :doc:`the getelementptr FAQ <GetElementPtr>`.
7981
7982Example:
7983""""""""
7984
7985.. code-block:: llvm
7986
7987 ; yields [12 x i8]*:aptr
David Blaikie16a97eb2015-03-04 22:02:58 +00007988 %aptr = getelementptr {i32, [12 x i8]}, {i32, [12 x i8]}* %saptr, i64 0, i32 1
Sean Silvab084af42012-12-07 10:36:55 +00007989 ; yields i8*:vptr
David Blaikie16a97eb2015-03-04 22:02:58 +00007990 %vptr = getelementptr {i32, <2 x i8>}, {i32, <2 x i8>}* %svptr, i64 0, i32 1, i32 1
Sean Silvab084af42012-12-07 10:36:55 +00007991 ; yields i8*:eptr
David Blaikie16a97eb2015-03-04 22:02:58 +00007992 %eptr = getelementptr [12 x i8], [12 x i8]* %aptr, i64 0, i32 1
Sean Silvab084af42012-12-07 10:36:55 +00007993 ; yields i32*:iptr
David Blaikie16a97eb2015-03-04 22:02:58 +00007994 %iptr = getelementptr [10 x i32], [10 x i32]* @arr, i16 0, i16 0
Sean Silvab084af42012-12-07 10:36:55 +00007995
Elena Demikhovsky37a4da82015-07-09 07:42:48 +00007996Vector of pointers:
7997"""""""""""""""""""
7998
7999The ``getelementptr`` returns a vector of pointers, instead of a single address,
8000when one or more of its arguments is a vector. In such cases, all vector
8001arguments should have the same number of elements, and every scalar argument
8002will be effectively broadcast into a vector during address calculation.
Sean Silvab084af42012-12-07 10:36:55 +00008003
8004.. code-block:: llvm
8005
Elena Demikhovsky37a4da82015-07-09 07:42:48 +00008006 ; All arguments are vectors:
8007 ; A[i] = ptrs[i] + offsets[i]*sizeof(i8)
8008 %A = getelementptr i8, <4 x i8*> %ptrs, <4 x i64> %offsets
Sean Silva706fba52015-08-06 22:56:24 +00008009
Elena Demikhovsky37a4da82015-07-09 07:42:48 +00008010 ; Add the same scalar offset to each pointer of a vector:
8011 ; A[i] = ptrs[i] + offset*sizeof(i8)
8012 %A = getelementptr i8, <4 x i8*> %ptrs, i64 %offset
Sean Silva706fba52015-08-06 22:56:24 +00008013
Elena Demikhovsky37a4da82015-07-09 07:42:48 +00008014 ; Add distinct offsets to the same pointer:
8015 ; A[i] = ptr + offsets[i]*sizeof(i8)
8016 %A = getelementptr i8, i8* %ptr, <4 x i64> %offsets
Sean Silva706fba52015-08-06 22:56:24 +00008017
Elena Demikhovsky37a4da82015-07-09 07:42:48 +00008018 ; In all cases described above the type of the result is <4 x i8*>
8019
8020The two following instructions are equivalent:
8021
8022.. code-block:: llvm
8023
8024 getelementptr %struct.ST, <4 x %struct.ST*> %s, <4 x i64> %ind1,
8025 <4 x i32> <i32 2, i32 2, i32 2, i32 2>,
8026 <4 x i32> <i32 1, i32 1, i32 1, i32 1>,
8027 <4 x i32> %ind4,
8028 <4 x i64> <i64 13, i64 13, i64 13, i64 13>
Sean Silva706fba52015-08-06 22:56:24 +00008029
Elena Demikhovsky37a4da82015-07-09 07:42:48 +00008030 getelementptr %struct.ST, <4 x %struct.ST*> %s, <4 x i64> %ind1,
8031 i32 2, i32 1, <4 x i32> %ind4, i64 13
8032
8033Let's look at the C code, where the vector version of ``getelementptr``
8034makes sense:
8035
8036.. code-block:: c
8037
8038 // Let's assume that we vectorize the following loop:
Alexey Baderadec2832017-01-30 07:38:58 +00008039 double *A, *B; int *C;
Elena Demikhovsky37a4da82015-07-09 07:42:48 +00008040 for (int i = 0; i < size; ++i) {
8041 A[i] = B[C[i]];
8042 }
8043
8044.. code-block:: llvm
8045
8046 ; get pointers for 8 elements from array B
8047 %ptrs = getelementptr double, double* %B, <8 x i32> %C
8048 ; load 8 elements from array B into A
Elad Cohenef5798a2017-05-03 12:28:54 +00008049 %A = call <8 x double> @llvm.masked.gather.v8f64.v8p0f64(<8 x double*> %ptrs,
Elena Demikhovsky37a4da82015-07-09 07:42:48 +00008050 i32 8, <8 x i1> %mask, <8 x double> %passthru)
Sean Silvab084af42012-12-07 10:36:55 +00008051
8052Conversion Operations
8053---------------------
8054
8055The instructions in this category are the conversion instructions
8056(casting) which all take a single operand and a type. They perform
8057various bit conversions on the operand.
8058
8059'``trunc .. to``' Instruction
8060^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8061
8062Syntax:
8063"""""""
8064
8065::
8066
8067 <result> = trunc <ty> <value> to <ty2> ; yields ty2
8068
8069Overview:
8070"""""""""
8071
8072The '``trunc``' instruction truncates its operand to the type ``ty2``.
8073
8074Arguments:
8075""""""""""
8076
8077The '``trunc``' instruction takes a value to trunc, and a type to trunc
8078it to. Both types must be of :ref:`integer <t_integer>` types, or vectors
8079of the same number of integers. The bit size of the ``value`` must be
8080larger than the bit size of the destination type, ``ty2``. Equal sized
8081types are not allowed.
8082
8083Semantics:
8084""""""""""
8085
8086The '``trunc``' instruction truncates the high order bits in ``value``
8087and converts the remaining bits to ``ty2``. Since the source size must
8088be larger than the destination size, ``trunc`` cannot be a *no-op cast*.
8089It will always truncate bits.
8090
8091Example:
8092""""""""
8093
8094.. code-block:: llvm
8095
8096 %X = trunc i32 257 to i8 ; yields i8:1
8097 %Y = trunc i32 123 to i1 ; yields i1:true
8098 %Z = trunc i32 122 to i1 ; yields i1:false
8099 %W = trunc <2 x i16> <i16 8, i16 7> to <2 x i8> ; yields <i8 8, i8 7>
8100
8101'``zext .. to``' Instruction
8102^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8103
8104Syntax:
8105"""""""
8106
8107::
8108
8109 <result> = zext <ty> <value> to <ty2> ; yields ty2
8110
8111Overview:
8112"""""""""
8113
8114The '``zext``' instruction zero extends its operand to type ``ty2``.
8115
8116Arguments:
8117""""""""""
8118
8119The '``zext``' instruction takes a value to cast, and a type to cast it
8120to. Both types must be of :ref:`integer <t_integer>` types, or vectors of
8121the same number of integers. The bit size of the ``value`` must be
8122smaller than the bit size of the destination type, ``ty2``.
8123
8124Semantics:
8125""""""""""
8126
8127The ``zext`` fills the high order bits of the ``value`` with zero bits
8128until it reaches the size of the destination type, ``ty2``.
8129
8130When zero extending from i1, the result will always be either 0 or 1.
8131
8132Example:
8133""""""""
8134
8135.. code-block:: llvm
8136
8137 %X = zext i32 257 to i64 ; yields i64:257
8138 %Y = zext i1 true to i32 ; yields i32:1
8139 %Z = zext <2 x i16> <i16 8, i16 7> to <2 x i32> ; yields <i32 8, i32 7>
8140
8141'``sext .. to``' Instruction
8142^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8143
8144Syntax:
8145"""""""
8146
8147::
8148
8149 <result> = sext <ty> <value> to <ty2> ; yields ty2
8150
8151Overview:
8152"""""""""
8153
8154The '``sext``' sign extends ``value`` to the type ``ty2``.
8155
8156Arguments:
8157""""""""""
8158
8159The '``sext``' instruction takes a value to cast, and a type to cast it
8160to. Both types must be of :ref:`integer <t_integer>` types, or vectors of
8161the same number of integers. The bit size of the ``value`` must be
8162smaller than the bit size of the destination type, ``ty2``.
8163
8164Semantics:
8165""""""""""
8166
8167The '``sext``' instruction performs a sign extension by copying the sign
8168bit (highest order bit) of the ``value`` until it reaches the bit size
8169of the type ``ty2``.
8170
8171When sign extending from i1, the extension always results in -1 or 0.
8172
8173Example:
8174""""""""
8175
8176.. code-block:: llvm
8177
8178 %X = sext i8 -1 to i16 ; yields i16 :65535
8179 %Y = sext i1 true to i32 ; yields i32:-1
8180 %Z = sext <2 x i16> <i16 8, i16 7> to <2 x i32> ; yields <i32 8, i32 7>
8181
8182'``fptrunc .. to``' Instruction
8183^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8184
8185Syntax:
8186"""""""
8187
8188::
8189
8190 <result> = fptrunc <ty> <value> to <ty2> ; yields ty2
8191
8192Overview:
8193"""""""""
8194
8195The '``fptrunc``' instruction truncates ``value`` to type ``ty2``.
8196
8197Arguments:
8198""""""""""
8199
8200The '``fptrunc``' instruction takes a :ref:`floating point <t_floating>`
8201value to cast and a :ref:`floating point <t_floating>` type to cast it to.
8202The size of ``value`` must be larger than the size of ``ty2``. This
8203implies that ``fptrunc`` cannot be used to make a *no-op cast*.
8204
8205Semantics:
8206""""""""""
8207
Dan Liew50456fb2015-09-03 18:43:56 +00008208The '``fptrunc``' instruction casts a ``value`` from a larger
Sean Silvab084af42012-12-07 10:36:55 +00008209:ref:`floating point <t_floating>` type to a smaller :ref:`floating
Dan Liew50456fb2015-09-03 18:43:56 +00008210point <t_floating>` type. If the value cannot fit (i.e. overflows) within the
8211destination type, ``ty2``, then the results are undefined. If the cast produces
8212an inexact result, how rounding is performed (e.g. truncation, also known as
8213round to zero) is undefined.
Sean Silvab084af42012-12-07 10:36:55 +00008214
8215Example:
8216""""""""
8217
8218.. code-block:: llvm
8219
8220 %X = fptrunc double 123.0 to float ; yields float:123.0
8221 %Y = fptrunc double 1.0E+300 to float ; yields undefined
8222
8223'``fpext .. to``' Instruction
8224^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8225
8226Syntax:
8227"""""""
8228
8229::
8230
8231 <result> = fpext <ty> <value> to <ty2> ; yields ty2
8232
8233Overview:
8234"""""""""
8235
8236The '``fpext``' extends a floating point ``value`` to a larger floating
8237point value.
8238
8239Arguments:
8240""""""""""
8241
8242The '``fpext``' instruction takes a :ref:`floating point <t_floating>`
8243``value`` to cast, and a :ref:`floating point <t_floating>` type to cast it
8244to. The source type must be smaller than the destination type.
8245
8246Semantics:
8247""""""""""
8248
8249The '``fpext``' instruction extends the ``value`` from a smaller
8250:ref:`floating point <t_floating>` type to a larger :ref:`floating
8251point <t_floating>` type. The ``fpext`` cannot be used to make a
8252*no-op cast* because it always changes bits. Use ``bitcast`` to make a
8253*no-op cast* for a floating point cast.
8254
8255Example:
8256""""""""
8257
8258.. code-block:: llvm
8259
8260 %X = fpext float 3.125 to double ; yields double:3.125000e+00
8261 %Y = fpext double %X to fp128 ; yields fp128:0xL00000000000000004000900000000000
8262
8263'``fptoui .. to``' Instruction
8264^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8265
8266Syntax:
8267"""""""
8268
8269::
8270
8271 <result> = fptoui <ty> <value> to <ty2> ; yields ty2
8272
8273Overview:
8274"""""""""
8275
8276The '``fptoui``' converts a floating point ``value`` to its unsigned
8277integer equivalent of type ``ty2``.
8278
8279Arguments:
8280""""""""""
8281
8282The '``fptoui``' instruction takes a value to cast, which must be a
8283scalar or vector :ref:`floating point <t_floating>` value, and a type to
8284cast it to ``ty2``, which must be an :ref:`integer <t_integer>` type. If
8285``ty`` is a vector floating point type, ``ty2`` must be a vector integer
8286type with the same number of elements as ``ty``
8287
8288Semantics:
8289""""""""""
8290
8291The '``fptoui``' instruction converts its :ref:`floating
8292point <t_floating>` operand into the nearest (rounding towards zero)
8293unsigned integer value. If the value cannot fit in ``ty2``, the results
8294are undefined.
8295
8296Example:
8297""""""""
8298
8299.. code-block:: llvm
8300
8301 %X = fptoui double 123.0 to i32 ; yields i32:123
8302 %Y = fptoui float 1.0E+300 to i1 ; yields undefined:1
8303 %Z = fptoui float 1.04E+17 to i8 ; yields undefined:1
8304
8305'``fptosi .. to``' Instruction
8306^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8307
8308Syntax:
8309"""""""
8310
8311::
8312
8313 <result> = fptosi <ty> <value> to <ty2> ; yields ty2
8314
8315Overview:
8316"""""""""
8317
8318The '``fptosi``' instruction converts :ref:`floating point <t_floating>`
8319``value`` to type ``ty2``.
8320
8321Arguments:
8322""""""""""
8323
8324The '``fptosi``' instruction takes a value to cast, which must be a
8325scalar or vector :ref:`floating point <t_floating>` value, and a type to
8326cast it to ``ty2``, which must be an :ref:`integer <t_integer>` type. If
8327``ty`` is a vector floating point type, ``ty2`` must be a vector integer
8328type with the same number of elements as ``ty``
8329
8330Semantics:
8331""""""""""
8332
8333The '``fptosi``' instruction converts its :ref:`floating
8334point <t_floating>` operand into the nearest (rounding towards zero)
8335signed integer value. If the value cannot fit in ``ty2``, the results
8336are undefined.
8337
8338Example:
8339""""""""
8340
8341.. code-block:: llvm
8342
8343 %X = fptosi double -123.0 to i32 ; yields i32:-123
8344 %Y = fptosi float 1.0E-247 to i1 ; yields undefined:1
8345 %Z = fptosi float 1.04E+17 to i8 ; yields undefined:1
8346
8347'``uitofp .. to``' Instruction
8348^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8349
8350Syntax:
8351"""""""
8352
8353::
8354
8355 <result> = uitofp <ty> <value> to <ty2> ; yields ty2
8356
8357Overview:
8358"""""""""
8359
8360The '``uitofp``' instruction regards ``value`` as an unsigned integer
8361and converts that value to the ``ty2`` type.
8362
8363Arguments:
8364""""""""""
8365
8366The '``uitofp``' instruction takes a value to cast, which must be a
8367scalar or vector :ref:`integer <t_integer>` value, and a type to cast it to
8368``ty2``, which must be an :ref:`floating point <t_floating>` type. If
8369``ty`` is a vector integer type, ``ty2`` must be a vector floating point
8370type with the same number of elements as ``ty``
8371
8372Semantics:
8373""""""""""
8374
8375The '``uitofp``' instruction interprets its operand as an unsigned
8376integer quantity and converts it to the corresponding floating point
8377value. If the value cannot fit in the floating point value, the results
8378are undefined.
8379
8380Example:
8381""""""""
8382
8383.. code-block:: llvm
8384
8385 %X = uitofp i32 257 to float ; yields float:257.0
8386 %Y = uitofp i8 -1 to double ; yields double:255.0
8387
8388'``sitofp .. to``' Instruction
8389^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8390
8391Syntax:
8392"""""""
8393
8394::
8395
8396 <result> = sitofp <ty> <value> to <ty2> ; yields ty2
8397
8398Overview:
8399"""""""""
8400
8401The '``sitofp``' instruction regards ``value`` as a signed integer and
8402converts that value to the ``ty2`` type.
8403
8404Arguments:
8405""""""""""
8406
8407The '``sitofp``' instruction takes a value to cast, which must be a
8408scalar or vector :ref:`integer <t_integer>` value, and a type to cast it to
8409``ty2``, which must be an :ref:`floating point <t_floating>` type. If
8410``ty`` is a vector integer type, ``ty2`` must be a vector floating point
8411type with the same number of elements as ``ty``
8412
8413Semantics:
8414""""""""""
8415
8416The '``sitofp``' instruction interprets its operand as a signed integer
8417quantity and converts it to the corresponding floating point value. If
8418the value cannot fit in the floating point value, the results are
8419undefined.
8420
8421Example:
8422""""""""
8423
8424.. code-block:: llvm
8425
8426 %X = sitofp i32 257 to float ; yields float:257.0
8427 %Y = sitofp i8 -1 to double ; yields double:-1.0
8428
8429.. _i_ptrtoint:
8430
8431'``ptrtoint .. to``' Instruction
8432^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8433
8434Syntax:
8435"""""""
8436
8437::
8438
8439 <result> = ptrtoint <ty> <value> to <ty2> ; yields ty2
8440
8441Overview:
8442"""""""""
8443
8444The '``ptrtoint``' instruction converts the pointer or a vector of
8445pointers ``value`` to the integer (or vector of integers) type ``ty2``.
8446
8447Arguments:
8448""""""""""
8449
8450The '``ptrtoint``' instruction takes a ``value`` to cast, which must be
Ed Maste8ed40ce2015-04-14 20:52:58 +00008451a value of type :ref:`pointer <t_pointer>` or a vector of pointers, and a
Sean Silvab084af42012-12-07 10:36:55 +00008452type to cast it to ``ty2``, which must be an :ref:`integer <t_integer>` or
8453a vector of integers type.
8454
8455Semantics:
8456""""""""""
8457
8458The '``ptrtoint``' instruction converts ``value`` to integer type
8459``ty2`` by interpreting the pointer value as an integer and either
8460truncating or zero extending that value to the size of the integer type.
8461If ``value`` is smaller than ``ty2`` then a zero extension is done. If
8462``value`` is larger than ``ty2`` then a truncation is done. If they are
8463the same size, then nothing is done (*no-op cast*) other than a type
8464change.
8465
8466Example:
8467""""""""
8468
8469.. code-block:: llvm
8470
8471 %X = ptrtoint i32* %P to i8 ; yields truncation on 32-bit architecture
8472 %Y = ptrtoint i32* %P to i64 ; yields zero extension on 32-bit architecture
8473 %Z = ptrtoint <4 x i32*> %P to <4 x i64>; yields vector zero extension for a vector of addresses on 32-bit architecture
8474
8475.. _i_inttoptr:
8476
8477'``inttoptr .. to``' Instruction
8478^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8479
8480Syntax:
8481"""""""
8482
8483::
8484
8485 <result> = inttoptr <ty> <value> to <ty2> ; yields ty2
8486
8487Overview:
8488"""""""""
8489
8490The '``inttoptr``' instruction converts an integer ``value`` to a
8491pointer type, ``ty2``.
8492
8493Arguments:
8494""""""""""
8495
8496The '``inttoptr``' instruction takes an :ref:`integer <t_integer>` value to
8497cast, and a type to cast it to, which must be a :ref:`pointer <t_pointer>`
8498type.
8499
8500Semantics:
8501""""""""""
8502
8503The '``inttoptr``' instruction converts ``value`` to type ``ty2`` by
8504applying either a zero extension or a truncation depending on the size
8505of the integer ``value``. If ``value`` is larger than the size of a
8506pointer then a truncation is done. If ``value`` is smaller than the size
8507of a pointer then a zero extension is done. If they are the same size,
8508nothing is done (*no-op cast*).
8509
8510Example:
8511""""""""
8512
8513.. code-block:: llvm
8514
8515 %X = inttoptr i32 255 to i32* ; yields zero extension on 64-bit architecture
8516 %Y = inttoptr i32 255 to i32* ; yields no-op on 32-bit architecture
8517 %Z = inttoptr i64 0 to i32* ; yields truncation on 32-bit architecture
8518 %Z = inttoptr <4 x i32> %G to <4 x i8*>; yields truncation of vector G to four pointers
8519
8520.. _i_bitcast:
8521
8522'``bitcast .. to``' Instruction
8523^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8524
8525Syntax:
8526"""""""
8527
8528::
8529
8530 <result> = bitcast <ty> <value> to <ty2> ; yields ty2
8531
8532Overview:
8533"""""""""
8534
8535The '``bitcast``' instruction converts ``value`` to type ``ty2`` without
8536changing any bits.
8537
8538Arguments:
8539""""""""""
8540
8541The '``bitcast``' instruction takes a value to cast, which must be a
8542non-aggregate first class value, and a type to cast it to, which must
Matt Arsenault24b49c42013-07-31 17:49:08 +00008543also be a non-aggregate :ref:`first class <t_firstclass>` type. The
8544bit sizes of ``value`` and the destination type, ``ty2``, must be
Sean Silvaa1190322015-08-06 22:56:48 +00008545identical. If the source type is a pointer, the destination type must
Matt Arsenault24b49c42013-07-31 17:49:08 +00008546also be a pointer of the same size. This instruction supports bitwise
8547conversion of vectors to integers and to vectors of other types (as
8548long as they have the same size).
Sean Silvab084af42012-12-07 10:36:55 +00008549
8550Semantics:
8551""""""""""
8552
Matt Arsenault24b49c42013-07-31 17:49:08 +00008553The '``bitcast``' instruction converts ``value`` to type ``ty2``. It
8554is always a *no-op cast* because no bits change with this
8555conversion. The conversion is done as if the ``value`` had been stored
8556to memory and read back as type ``ty2``. Pointer (or vector of
8557pointers) types may only be converted to other pointer (or vector of
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00008558pointers) types with the same address space through this instruction.
8559To convert pointers to other types, use the :ref:`inttoptr <i_inttoptr>`
8560or :ref:`ptrtoint <i_ptrtoint>` instructions first.
Sean Silvab084af42012-12-07 10:36:55 +00008561
8562Example:
8563""""""""
8564
Renato Golin124f2592016-07-20 12:16:38 +00008565.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00008566
8567 %X = bitcast i8 255 to i8 ; yields i8 :-1
8568 %Y = bitcast i32* %x to sint* ; yields sint*:%x
8569 %Z = bitcast <2 x int> %V to i64; ; yields i64: %V
8570 %Z = bitcast <2 x i32*> %V to <2 x i64*> ; yields <2 x i64*>
8571
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00008572.. _i_addrspacecast:
8573
8574'``addrspacecast .. to``' Instruction
8575^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8576
8577Syntax:
8578"""""""
8579
8580::
8581
8582 <result> = addrspacecast <pty> <ptrval> to <pty2> ; yields pty2
8583
8584Overview:
8585"""""""""
8586
8587The '``addrspacecast``' instruction converts ``ptrval`` from ``pty`` in
8588address space ``n`` to type ``pty2`` in address space ``m``.
8589
8590Arguments:
8591""""""""""
8592
8593The '``addrspacecast``' instruction takes a pointer or vector of pointer value
8594to cast and a pointer type to cast it to, which must have a different
8595address space.
8596
8597Semantics:
8598""""""""""
8599
8600The '``addrspacecast``' instruction converts the pointer value
8601``ptrval`` to type ``pty2``. It can be a *no-op cast* or a complex
Matt Arsenault54a2a172013-11-15 05:44:56 +00008602value modification, depending on the target and the address space
8603pair. Pointer conversions within the same address space must be
8604performed with the ``bitcast`` instruction. Note that if the address space
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00008605conversion is legal then both result and operand refer to the same memory
8606location.
8607
8608Example:
8609""""""""
8610
8611.. code-block:: llvm
8612
Matt Arsenault9c13dd02013-11-15 22:43:50 +00008613 %X = addrspacecast i32* %x to i32 addrspace(1)* ; yields i32 addrspace(1)*:%x
8614 %Y = addrspacecast i32 addrspace(1)* %y to i64 addrspace(2)* ; yields i64 addrspace(2)*:%y
8615 %Z = addrspacecast <4 x i32*> %z to <4 x float addrspace(3)*> ; yields <4 x float addrspace(3)*>:%z
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00008616
Sean Silvab084af42012-12-07 10:36:55 +00008617.. _otherops:
8618
8619Other Operations
8620----------------
8621
8622The instructions in this category are the "miscellaneous" instructions,
8623which defy better classification.
8624
8625.. _i_icmp:
8626
8627'``icmp``' Instruction
8628^^^^^^^^^^^^^^^^^^^^^^
8629
8630Syntax:
8631"""""""
8632
8633::
8634
Tim Northover675a0962014-06-13 14:24:23 +00008635 <result> = icmp <cond> <ty> <op1>, <op2> ; yields i1 or <N x i1>:result
Sean Silvab084af42012-12-07 10:36:55 +00008636
8637Overview:
8638"""""""""
8639
8640The '``icmp``' instruction returns a boolean value or a vector of
8641boolean values based on comparison of its two integer, integer vector,
8642pointer, or pointer vector operands.
8643
8644Arguments:
8645""""""""""
8646
8647The '``icmp``' instruction takes three operands. The first operand is
8648the condition code indicating the kind of comparison to perform. It is
Sanjay Patel43d41442016-03-30 21:38:20 +00008649not a value, just a keyword. The possible condition codes are:
Sean Silvab084af42012-12-07 10:36:55 +00008650
8651#. ``eq``: equal
8652#. ``ne``: not equal
8653#. ``ugt``: unsigned greater than
8654#. ``uge``: unsigned greater or equal
8655#. ``ult``: unsigned less than
8656#. ``ule``: unsigned less or equal
8657#. ``sgt``: signed greater than
8658#. ``sge``: signed greater or equal
8659#. ``slt``: signed less than
8660#. ``sle``: signed less or equal
8661
8662The remaining two arguments must be :ref:`integer <t_integer>` or
8663:ref:`pointer <t_pointer>` or integer :ref:`vector <t_vector>` typed. They
8664must also be identical types.
8665
8666Semantics:
8667""""""""""
8668
8669The '``icmp``' compares ``op1`` and ``op2`` according to the condition
8670code given as ``cond``. The comparison performed always yields either an
8671:ref:`i1 <t_integer>` or vector of ``i1`` result, as follows:
8672
8673#. ``eq``: yields ``true`` if the operands are equal, ``false``
8674 otherwise. No sign interpretation is necessary or performed.
8675#. ``ne``: yields ``true`` if the operands are unequal, ``false``
8676 otherwise. No sign interpretation is necessary or performed.
8677#. ``ugt``: interprets the operands as unsigned values and yields
8678 ``true`` if ``op1`` is greater than ``op2``.
8679#. ``uge``: interprets the operands as unsigned values and yields
8680 ``true`` if ``op1`` is greater than or equal to ``op2``.
8681#. ``ult``: interprets the operands as unsigned values and yields
8682 ``true`` if ``op1`` is less than ``op2``.
8683#. ``ule``: interprets the operands as unsigned values and yields
8684 ``true`` if ``op1`` is less than or equal to ``op2``.
8685#. ``sgt``: interprets the operands as signed values and yields ``true``
8686 if ``op1`` is greater than ``op2``.
8687#. ``sge``: interprets the operands as signed values and yields ``true``
8688 if ``op1`` is greater than or equal to ``op2``.
8689#. ``slt``: interprets the operands as signed values and yields ``true``
8690 if ``op1`` is less than ``op2``.
8691#. ``sle``: interprets the operands as signed values and yields ``true``
8692 if ``op1`` is less than or equal to ``op2``.
8693
8694If the operands are :ref:`pointer <t_pointer>` typed, the pointer values
8695are compared as if they were integers.
8696
8697If the operands are integer vectors, then they are compared element by
8698element. The result is an ``i1`` vector with the same number of elements
8699as the values being compared. Otherwise, the result is an ``i1``.
8700
8701Example:
8702""""""""
8703
Renato Golin124f2592016-07-20 12:16:38 +00008704.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00008705
8706 <result> = icmp eq i32 4, 5 ; yields: result=false
8707 <result> = icmp ne float* %X, %X ; yields: result=false
8708 <result> = icmp ult i16 4, 5 ; yields: result=true
8709 <result> = icmp sgt i16 4, 5 ; yields: result=false
8710 <result> = icmp ule i16 -4, 5 ; yields: result=false
8711 <result> = icmp sge i16 4, 5 ; yields: result=false
8712
Sean Silvab084af42012-12-07 10:36:55 +00008713.. _i_fcmp:
8714
8715'``fcmp``' Instruction
8716^^^^^^^^^^^^^^^^^^^^^^
8717
8718Syntax:
8719"""""""
8720
8721::
8722
James Molloy88eb5352015-07-10 12:52:00 +00008723 <result> = fcmp [fast-math flags]* <cond> <ty> <op1>, <op2> ; yields i1 or <N x i1>:result
Sean Silvab084af42012-12-07 10:36:55 +00008724
8725Overview:
8726"""""""""
8727
8728The '``fcmp``' instruction returns a boolean value or vector of boolean
8729values based on comparison of its operands.
8730
8731If the operands are floating point scalars, then the result type is a
8732boolean (:ref:`i1 <t_integer>`).
8733
8734If the operands are floating point vectors, then the result type is a
8735vector of boolean with the same number of elements as the operands being
8736compared.
8737
8738Arguments:
8739""""""""""
8740
8741The '``fcmp``' instruction takes three operands. The first operand is
8742the condition code indicating the kind of comparison to perform. It is
Sanjay Patel43d41442016-03-30 21:38:20 +00008743not a value, just a keyword. The possible condition codes are:
Sean Silvab084af42012-12-07 10:36:55 +00008744
8745#. ``false``: no comparison, always returns false
8746#. ``oeq``: ordered and equal
8747#. ``ogt``: ordered and greater than
8748#. ``oge``: ordered and greater than or equal
8749#. ``olt``: ordered and less than
8750#. ``ole``: ordered and less than or equal
8751#. ``one``: ordered and not equal
8752#. ``ord``: ordered (no nans)
8753#. ``ueq``: unordered or equal
8754#. ``ugt``: unordered or greater than
8755#. ``uge``: unordered or greater than or equal
8756#. ``ult``: unordered or less than
8757#. ``ule``: unordered or less than or equal
8758#. ``une``: unordered or not equal
8759#. ``uno``: unordered (either nans)
8760#. ``true``: no comparison, always returns true
8761
8762*Ordered* means that neither operand is a QNAN while *unordered* means
8763that either operand may be a QNAN.
8764
8765Each of ``val1`` and ``val2`` arguments must be either a :ref:`floating
8766point <t_floating>` type or a :ref:`vector <t_vector>` of floating point
8767type. They must have identical types.
8768
8769Semantics:
8770""""""""""
8771
8772The '``fcmp``' instruction compares ``op1`` and ``op2`` according to the
8773condition code given as ``cond``. If the operands are vectors, then the
8774vectors are compared element by element. Each comparison performed
8775always yields an :ref:`i1 <t_integer>` result, as follows:
8776
8777#. ``false``: always yields ``false``, regardless of operands.
8778#. ``oeq``: yields ``true`` if both operands are not a QNAN and ``op1``
8779 is equal to ``op2``.
8780#. ``ogt``: yields ``true`` if both operands are not a QNAN and ``op1``
8781 is greater than ``op2``.
8782#. ``oge``: yields ``true`` if both operands are not a QNAN and ``op1``
8783 is greater than or equal to ``op2``.
8784#. ``olt``: yields ``true`` if both operands are not a QNAN and ``op1``
8785 is less than ``op2``.
8786#. ``ole``: yields ``true`` if both operands are not a QNAN and ``op1``
8787 is less than or equal to ``op2``.
8788#. ``one``: yields ``true`` if both operands are not a QNAN and ``op1``
8789 is not equal to ``op2``.
8790#. ``ord``: yields ``true`` if both operands are not a QNAN.
8791#. ``ueq``: yields ``true`` if either operand is a QNAN or ``op1`` is
8792 equal to ``op2``.
8793#. ``ugt``: yields ``true`` if either operand is a QNAN or ``op1`` is
8794 greater than ``op2``.
8795#. ``uge``: yields ``true`` if either operand is a QNAN or ``op1`` is
8796 greater than or equal to ``op2``.
8797#. ``ult``: yields ``true`` if either operand is a QNAN or ``op1`` is
8798 less than ``op2``.
8799#. ``ule``: yields ``true`` if either operand is a QNAN or ``op1`` is
8800 less than or equal to ``op2``.
8801#. ``une``: yields ``true`` if either operand is a QNAN or ``op1`` is
8802 not equal to ``op2``.
8803#. ``uno``: yields ``true`` if either operand is a QNAN.
8804#. ``true``: always yields ``true``, regardless of operands.
8805
James Molloy88eb5352015-07-10 12:52:00 +00008806The ``fcmp`` instruction can also optionally take any number of
8807:ref:`fast-math flags <fastmath>`, which are optimization hints to enable
8808otherwise unsafe floating point optimizations.
8809
8810Any set of fast-math flags are legal on an ``fcmp`` instruction, but the
8811only flags that have any effect on its semantics are those that allow
8812assumptions to be made about the values of input arguments; namely
8813``nnan``, ``ninf``, and ``nsz``. See :ref:`fastmath` for more information.
8814
Sean Silvab084af42012-12-07 10:36:55 +00008815Example:
8816""""""""
8817
Renato Golin124f2592016-07-20 12:16:38 +00008818.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00008819
8820 <result> = fcmp oeq float 4.0, 5.0 ; yields: result=false
8821 <result> = fcmp one float 4.0, 5.0 ; yields: result=true
8822 <result> = fcmp olt float 4.0, 5.0 ; yields: result=true
8823 <result> = fcmp ueq double 1.0, 2.0 ; yields: result=false
8824
Sean Silvab084af42012-12-07 10:36:55 +00008825.. _i_phi:
8826
8827'``phi``' Instruction
8828^^^^^^^^^^^^^^^^^^^^^
8829
8830Syntax:
8831"""""""
8832
8833::
8834
8835 <result> = phi <ty> [ <val0>, <label0>], ...
8836
8837Overview:
8838"""""""""
8839
8840The '``phi``' instruction is used to implement the φ node in the SSA
8841graph representing the function.
8842
8843Arguments:
8844""""""""""
8845
8846The type of the incoming values is specified with the first type field.
8847After this, the '``phi``' instruction takes a list of pairs as
8848arguments, with one pair for each predecessor basic block of the current
8849block. Only values of :ref:`first class <t_firstclass>` type may be used as
8850the value arguments to the PHI node. Only labels may be used as the
8851label arguments.
8852
8853There must be no non-phi instructions between the start of a basic block
8854and the PHI instructions: i.e. PHI instructions must be first in a basic
8855block.
8856
8857For the purposes of the SSA form, the use of each incoming value is
8858deemed to occur on the edge from the corresponding predecessor block to
8859the current block (but after any definition of an '``invoke``'
8860instruction's return value on the same edge).
8861
8862Semantics:
8863""""""""""
8864
8865At runtime, the '``phi``' instruction logically takes on the value
8866specified by the pair corresponding to the predecessor basic block that
8867executed just prior to the current block.
8868
8869Example:
8870""""""""
8871
8872.. code-block:: llvm
8873
8874 Loop: ; Infinite loop that counts from 0 on up...
8875 %indvar = phi i32 [ 0, %LoopHeader ], [ %nextindvar, %Loop ]
8876 %nextindvar = add i32 %indvar, 1
8877 br label %Loop
8878
8879.. _i_select:
8880
8881'``select``' Instruction
8882^^^^^^^^^^^^^^^^^^^^^^^^
8883
8884Syntax:
8885"""""""
8886
8887::
8888
8889 <result> = select selty <cond>, <ty> <val1>, <ty> <val2> ; yields ty
8890
8891 selty is either i1 or {<N x i1>}
8892
8893Overview:
8894"""""""""
8895
8896The '``select``' instruction is used to choose one value based on a
Joerg Sonnenberger94321ec2014-03-26 15:30:21 +00008897condition, without IR-level branching.
Sean Silvab084af42012-12-07 10:36:55 +00008898
8899Arguments:
8900""""""""""
8901
8902The '``select``' instruction requires an 'i1' value or a vector of 'i1'
8903values indicating the condition, and two values of the same :ref:`first
David Majnemer40a0b592015-03-03 22:45:47 +00008904class <t_firstclass>` type.
Sean Silvab084af42012-12-07 10:36:55 +00008905
8906Semantics:
8907""""""""""
8908
8909If the condition is an i1 and it evaluates to 1, the instruction returns
8910the first value argument; otherwise, it returns the second value
8911argument.
8912
8913If the condition is a vector of i1, then the value arguments must be
8914vectors of the same size, and the selection is done element by element.
8915
David Majnemer40a0b592015-03-03 22:45:47 +00008916If the condition is an i1 and the value arguments are vectors of the
8917same size, then an entire vector is selected.
8918
Sean Silvab084af42012-12-07 10:36:55 +00008919Example:
8920""""""""
8921
8922.. code-block:: llvm
8923
8924 %X = select i1 true, i8 17, i8 42 ; yields i8:17
8925
8926.. _i_call:
8927
8928'``call``' Instruction
8929^^^^^^^^^^^^^^^^^^^^^^
8930
8931Syntax:
8932"""""""
8933
8934::
8935
David Blaikieb83cf102016-07-13 17:21:34 +00008936 <result> = [tail | musttail | notail ] call [fast-math flags] [cconv] [ret attrs] <ty>|<fnty> <fnptrval>(<function args>) [fn attrs]
Sanjoy Dasb513a9f2015-09-24 23:34:52 +00008937 [ operand bundles ]
Sean Silvab084af42012-12-07 10:36:55 +00008938
8939Overview:
8940"""""""""
8941
8942The '``call``' instruction represents a simple function call.
8943
8944Arguments:
8945""""""""""
8946
8947This instruction requires several arguments:
8948
Reid Kleckner5772b772014-04-24 20:14:34 +00008949#. The optional ``tail`` and ``musttail`` markers indicate that the optimizers
Sean Silvaa1190322015-08-06 22:56:48 +00008950 should perform tail call optimization. The ``tail`` marker is a hint that
8951 `can be ignored <CodeGenerator.html#sibcallopt>`_. The ``musttail`` marker
Reid Kleckner5772b772014-04-24 20:14:34 +00008952 means that the call must be tail call optimized in order for the program to
Sean Silvaa1190322015-08-06 22:56:48 +00008953 be correct. The ``musttail`` marker provides these guarantees:
Reid Kleckner5772b772014-04-24 20:14:34 +00008954
8955 #. The call will not cause unbounded stack growth if it is part of a
8956 recursive cycle in the call graph.
8957 #. Arguments with the :ref:`inalloca <attr_inalloca>` attribute are
8958 forwarded in place.
8959
8960 Both markers imply that the callee does not access allocas or varargs from
Sean Silvaa1190322015-08-06 22:56:48 +00008961 the caller. Calls marked ``musttail`` must obey the following additional
Reid Kleckner5772b772014-04-24 20:14:34 +00008962 rules:
8963
8964 - The call must immediately precede a :ref:`ret <i_ret>` instruction,
8965 or a pointer bitcast followed by a ret instruction.
8966 - The ret instruction must return the (possibly bitcasted) value
8967 produced by the call or void.
Sean Silvaa1190322015-08-06 22:56:48 +00008968 - The caller and callee prototypes must match. Pointer types of
Reid Kleckner5772b772014-04-24 20:14:34 +00008969 parameters or return types may differ in pointee type, but not
8970 in address space.
8971 - The calling conventions of the caller and callee must match.
8972 - All ABI-impacting function attributes, such as sret, byval, inreg,
8973 returned, and inalloca, must match.
Reid Kleckner83498642014-08-26 00:33:28 +00008974 - The callee must be varargs iff the caller is varargs. Bitcasting a
8975 non-varargs function to the appropriate varargs type is legal so
8976 long as the non-varargs prefixes obey the other rules.
Reid Kleckner5772b772014-04-24 20:14:34 +00008977
8978 Tail call optimization for calls marked ``tail`` is guaranteed to occur if
8979 the following conditions are met:
Sean Silvab084af42012-12-07 10:36:55 +00008980
8981 - Caller and callee both have the calling convention ``fastcc``.
8982 - The call is in tail position (ret immediately follows call and ret
8983 uses value of call or is void).
8984 - Option ``-tailcallopt`` is enabled, or
8985 ``llvm::GuaranteedTailCallOpt`` is ``true``.
Alp Tokercf218752014-06-30 18:57:16 +00008986 - `Platform-specific constraints are
Sean Silvab084af42012-12-07 10:36:55 +00008987 met. <CodeGenerator.html#tailcallopt>`_
8988
Akira Hatanaka5cfcce122015-11-06 23:55:38 +00008989#. The optional ``notail`` marker indicates that the optimizers should not add
8990 ``tail`` or ``musttail`` markers to the call. It is used to prevent tail
8991 call optimization from being performed on the call.
8992
Sanjay Patelfa54ace2015-12-14 21:59:03 +00008993#. The optional ``fast-math flags`` marker indicates that the call has one or more
8994 :ref:`fast-math flags <fastmath>`, which are optimization hints to enable
8995 otherwise unsafe floating-point optimizations. Fast-math flags are only valid
8996 for calls that return a floating-point scalar or vector type.
8997
Sean Silvab084af42012-12-07 10:36:55 +00008998#. The optional "cconv" marker indicates which :ref:`calling
8999 convention <callingconv>` the call should use. If none is
9000 specified, the call defaults to using C calling conventions. The
9001 calling convention of the call must match the calling convention of
9002 the target function, or else the behavior is undefined.
9003#. The optional :ref:`Parameter Attributes <paramattrs>` list for return
9004 values. Only '``zeroext``', '``signext``', and '``inreg``' attributes
9005 are valid here.
9006#. '``ty``': the type of the call instruction itself which is also the
9007 type of the return value. Functions that return no value are marked
9008 ``void``.
David Blaikieb83cf102016-07-13 17:21:34 +00009009#. '``fnty``': shall be the signature of the function being called. The
9010 argument types must match the types implied by this signature. This
9011 type can be omitted if the function is not varargs.
Sean Silvab084af42012-12-07 10:36:55 +00009012#. '``fnptrval``': An LLVM value containing a pointer to a function to
David Blaikieb83cf102016-07-13 17:21:34 +00009013 be called. In most cases, this is a direct function call, but
Sean Silvab084af42012-12-07 10:36:55 +00009014 indirect ``call``'s are just as possible, calling an arbitrary pointer
9015 to function value.
9016#. '``function args``': argument list whose types match the function
9017 signature argument types and parameter attributes. All arguments must
9018 be of :ref:`first class <t_firstclass>` type. If the function signature
9019 indicates the function accepts a variable number of arguments, the
9020 extra arguments can be specified.
George Burgess IV39c91052017-04-13 04:01:55 +00009021#. The optional :ref:`function attributes <fnattrs>` list.
Sanjoy Dasb513a9f2015-09-24 23:34:52 +00009022#. The optional :ref:`operand bundles <opbundles>` list.
Sean Silvab084af42012-12-07 10:36:55 +00009023
9024Semantics:
9025""""""""""
9026
9027The '``call``' instruction is used to cause control flow to transfer to
9028a specified function, with its incoming arguments bound to the specified
9029values. Upon a '``ret``' instruction in the called function, control
9030flow continues with the instruction after the function call, and the
9031return value of the function is bound to the result argument.
9032
9033Example:
9034""""""""
9035
9036.. code-block:: llvm
9037
9038 %retval = call i32 @test(i32 %argc)
9039 call i32 (i8*, ...)* @printf(i8* %msg, i32 12, i8 42) ; yields i32
9040 %X = tail call i32 @foo() ; yields i32
9041 %Y = tail call fastcc i32 @foo() ; yields i32
9042 call void %foo(i8 97 signext)
9043
9044 %struct.A = type { i32, i8 }
Tim Northover675a0962014-06-13 14:24:23 +00009045 %r = call %struct.A @foo() ; yields { i32, i8 }
Sean Silvab084af42012-12-07 10:36:55 +00009046 %gr = extractvalue %struct.A %r, 0 ; yields i32
9047 %gr1 = extractvalue %struct.A %r, 1 ; yields i8
9048 %Z = call void @foo() noreturn ; indicates that %foo never returns normally
9049 %ZZ = call zeroext i32 @bar() ; Return value is %zero extended
9050
9051llvm treats calls to some functions with names and arguments that match
9052the standard C99 library as being the C99 library functions, and may
9053perform optimizations or generate code for them under that assumption.
9054This is something we'd like to change in the future to provide better
9055support for freestanding environments and non-C-based languages.
9056
9057.. _i_va_arg:
9058
9059'``va_arg``' Instruction
9060^^^^^^^^^^^^^^^^^^^^^^^^
9061
9062Syntax:
9063"""""""
9064
9065::
9066
9067 <resultval> = va_arg <va_list*> <arglist>, <argty>
9068
9069Overview:
9070"""""""""
9071
9072The '``va_arg``' instruction is used to access arguments passed through
9073the "variable argument" area of a function call. It is used to implement
9074the ``va_arg`` macro in C.
9075
9076Arguments:
9077""""""""""
9078
9079This instruction takes a ``va_list*`` value and the type of the
9080argument. It returns a value of the specified argument type and
9081increments the ``va_list`` to point to the next argument. The actual
9082type of ``va_list`` is target specific.
9083
9084Semantics:
9085""""""""""
9086
9087The '``va_arg``' instruction loads an argument of the specified type
9088from the specified ``va_list`` and causes the ``va_list`` to point to
9089the next argument. For more information, see the variable argument
9090handling :ref:`Intrinsic Functions <int_varargs>`.
9091
9092It is legal for this instruction to be called in a function which does
9093not take a variable number of arguments, for example, the ``vfprintf``
9094function.
9095
9096``va_arg`` is an LLVM instruction instead of an :ref:`intrinsic
9097function <intrinsics>` because it takes a type as an argument.
9098
9099Example:
9100""""""""
9101
9102See the :ref:`variable argument processing <int_varargs>` section.
9103
9104Note that the code generator does not yet fully support va\_arg on many
9105targets. Also, it does not currently support va\_arg with aggregate
9106types on any target.
9107
9108.. _i_landingpad:
9109
9110'``landingpad``' Instruction
9111^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9112
9113Syntax:
9114"""""""
9115
9116::
9117
David Majnemer7fddecc2015-06-17 20:52:32 +00009118 <resultval> = landingpad <resultty> <clause>+
9119 <resultval> = landingpad <resultty> cleanup <clause>*
Sean Silvab084af42012-12-07 10:36:55 +00009120
9121 <clause> := catch <type> <value>
9122 <clause> := filter <array constant type> <array constant>
9123
9124Overview:
9125"""""""""
9126
9127The '``landingpad``' instruction is used by `LLVM's exception handling
9128system <ExceptionHandling.html#overview>`_ to specify that a basic block
Dmitri Gribenkoe8131122013-01-19 20:34:20 +00009129is a landing pad --- one where the exception lands, and corresponds to the
Sean Silvab084af42012-12-07 10:36:55 +00009130code found in the ``catch`` portion of a ``try``/``catch`` sequence. It
David Majnemer7fddecc2015-06-17 20:52:32 +00009131defines values supplied by the :ref:`personality function <personalityfn>` upon
Sean Silvab084af42012-12-07 10:36:55 +00009132re-entry to the function. The ``resultval`` has the type ``resultty``.
9133
9134Arguments:
9135""""""""""
9136
David Majnemer7fddecc2015-06-17 20:52:32 +00009137The optional
Sean Silvab084af42012-12-07 10:36:55 +00009138``cleanup`` flag indicates that the landing pad block is a cleanup.
9139
Dmitri Gribenkoe8131122013-01-19 20:34:20 +00009140A ``clause`` begins with the clause type --- ``catch`` or ``filter`` --- and
Sean Silvab084af42012-12-07 10:36:55 +00009141contains the global variable representing the "type" that may be caught
9142or filtered respectively. Unlike the ``catch`` clause, the ``filter``
9143clause takes an array constant as its argument. Use
9144"``[0 x i8**] undef``" for a filter which cannot throw. The
9145'``landingpad``' instruction must contain *at least* one ``clause`` or
9146the ``cleanup`` flag.
9147
9148Semantics:
9149""""""""""
9150
9151The '``landingpad``' instruction defines the values which are set by the
David Majnemer7fddecc2015-06-17 20:52:32 +00009152:ref:`personality function <personalityfn>` upon re-entry to the function, and
Sean Silvab084af42012-12-07 10:36:55 +00009153therefore the "result type" of the ``landingpad`` instruction. As with
9154calling conventions, how the personality function results are
9155represented in LLVM IR is target specific.
9156
9157The clauses are applied in order from top to bottom. If two
9158``landingpad`` instructions are merged together through inlining, the
9159clauses from the calling function are appended to the list of clauses.
9160When the call stack is being unwound due to an exception being thrown,
9161the exception is compared against each ``clause`` in turn. If it doesn't
9162match any of the clauses, and the ``cleanup`` flag is not set, then
9163unwinding continues further up the call stack.
9164
9165The ``landingpad`` instruction has several restrictions:
9166
9167- A landing pad block is a basic block which is the unwind destination
9168 of an '``invoke``' instruction.
9169- A landing pad block must have a '``landingpad``' instruction as its
9170 first non-PHI instruction.
9171- There can be only one '``landingpad``' instruction within the landing
9172 pad block.
9173- A basic block that is not a landing pad block may not include a
9174 '``landingpad``' instruction.
Sean Silvab084af42012-12-07 10:36:55 +00009175
9176Example:
9177""""""""
9178
9179.. code-block:: llvm
9180
9181 ;; A landing pad which can catch an integer.
David Majnemer7fddecc2015-06-17 20:52:32 +00009182 %res = landingpad { i8*, i32 }
Sean Silvab084af42012-12-07 10:36:55 +00009183 catch i8** @_ZTIi
9184 ;; A landing pad that is a cleanup.
David Majnemer7fddecc2015-06-17 20:52:32 +00009185 %res = landingpad { i8*, i32 }
Sean Silvab084af42012-12-07 10:36:55 +00009186 cleanup
9187 ;; A landing pad which can catch an integer and can only throw a double.
David Majnemer7fddecc2015-06-17 20:52:32 +00009188 %res = landingpad { i8*, i32 }
Sean Silvab084af42012-12-07 10:36:55 +00009189 catch i8** @_ZTIi
9190 filter [1 x i8**] [@_ZTId]
9191
Joseph Tremoulet2adaa982016-01-10 04:46:10 +00009192.. _i_catchpad:
9193
9194'``catchpad``' Instruction
9195^^^^^^^^^^^^^^^^^^^^^^^^^^
9196
9197Syntax:
9198"""""""
9199
9200::
9201
9202 <resultval> = catchpad within <catchswitch> [<args>*]
9203
9204Overview:
9205"""""""""
9206
9207The '``catchpad``' instruction is used by `LLVM's exception handling
9208system <ExceptionHandling.html#overview>`_ to specify that a basic block
9209begins a catch handler --- one where a personality routine attempts to transfer
9210control to catch an exception.
9211
9212Arguments:
9213""""""""""
9214
9215The ``catchswitch`` operand must always be a token produced by a
9216:ref:`catchswitch <i_catchswitch>` instruction in a predecessor block. This
9217ensures that each ``catchpad`` has exactly one predecessor block, and it always
9218terminates in a ``catchswitch``.
9219
9220The ``args`` correspond to whatever information the personality routine
9221requires to know if this is an appropriate handler for the exception. Control
9222will transfer to the ``catchpad`` if this is the first appropriate handler for
9223the exception.
9224
9225The ``resultval`` has the type :ref:`token <t_token>` and is used to match the
9226``catchpad`` to corresponding :ref:`catchrets <i_catchret>` and other nested EH
9227pads.
9228
9229Semantics:
9230""""""""""
9231
9232When the call stack is being unwound due to an exception being thrown, the
9233exception is compared against the ``args``. If it doesn't match, control will
9234not reach the ``catchpad`` instruction. The representation of ``args`` is
9235entirely target and personality function-specific.
9236
9237Like the :ref:`landingpad <i_landingpad>` instruction, the ``catchpad``
9238instruction must be the first non-phi of its parent basic block.
9239
9240The meaning of the tokens produced and consumed by ``catchpad`` and other "pad"
9241instructions is described in the
9242`Windows exception handling documentation\ <ExceptionHandling.html#wineh>`_.
9243
9244When a ``catchpad`` has been "entered" but not yet "exited" (as
9245described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_),
9246it is undefined behavior to execute a :ref:`call <i_call>` or :ref:`invoke <i_invoke>`
9247that does not carry an appropriate :ref:`"funclet" bundle <ob_funclet>`.
9248
9249Example:
9250""""""""
9251
Renato Golin124f2592016-07-20 12:16:38 +00009252.. code-block:: text
Joseph Tremoulet2adaa982016-01-10 04:46:10 +00009253
9254 dispatch:
9255 %cs = catchswitch within none [label %handler0] unwind to caller
9256 ;; A catch block which can catch an integer.
9257 handler0:
9258 %tok = catchpad within %cs [i8** @_ZTIi]
9259
David Majnemer654e1302015-07-31 17:58:14 +00009260.. _i_cleanuppad:
9261
9262'``cleanuppad``' Instruction
9263^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9264
9265Syntax:
9266"""""""
9267
9268::
9269
David Majnemer8a1c45d2015-12-12 05:38:55 +00009270 <resultval> = cleanuppad within <parent> [<args>*]
David Majnemer654e1302015-07-31 17:58:14 +00009271
9272Overview:
9273"""""""""
9274
9275The '``cleanuppad``' instruction is used by `LLVM's exception handling
9276system <ExceptionHandling.html#overview>`_ to specify that a basic block
9277is a cleanup block --- one where a personality routine attempts to
9278transfer control to run cleanup actions.
9279The ``args`` correspond to whatever additional
9280information the :ref:`personality function <personalityfn>` requires to
9281execute the cleanup.
Joseph Tremoulet8220bcc2015-08-23 00:26:33 +00009282The ``resultval`` has the type :ref:`token <t_token>` and is used to
David Majnemer8a1c45d2015-12-12 05:38:55 +00009283match the ``cleanuppad`` to corresponding :ref:`cleanuprets <i_cleanupret>`.
9284The ``parent`` argument is the token of the funclet that contains the
9285``cleanuppad`` instruction. If the ``cleanuppad`` is not inside a funclet,
9286this operand may be the token ``none``.
David Majnemer654e1302015-07-31 17:58:14 +00009287
9288Arguments:
9289""""""""""
9290
9291The instruction takes a list of arbitrary values which are interpreted
9292by the :ref:`personality function <personalityfn>`.
9293
9294Semantics:
9295""""""""""
9296
David Majnemer654e1302015-07-31 17:58:14 +00009297When the call stack is being unwound due to an exception being thrown,
9298the :ref:`personality function <personalityfn>` transfers control to the
9299``cleanuppad`` with the aid of the personality-specific arguments.
Joseph Tremoulet9ce71f72015-09-03 09:09:43 +00009300As with calling conventions, how the personality function results are
9301represented in LLVM IR is target specific.
David Majnemer654e1302015-07-31 17:58:14 +00009302
9303The ``cleanuppad`` instruction has several restrictions:
9304
9305- A cleanup block is a basic block which is the unwind destination of
9306 an exceptional instruction.
9307- A cleanup block must have a '``cleanuppad``' instruction as its
9308 first non-PHI instruction.
9309- There can be only one '``cleanuppad``' instruction within the
9310 cleanup block.
9311- A basic block that is not a cleanup block may not include a
9312 '``cleanuppad``' instruction.
David Majnemer8a1c45d2015-12-12 05:38:55 +00009313
Joseph Tremoulete28885e2016-01-10 04:28:38 +00009314When a ``cleanuppad`` has been "entered" but not yet "exited" (as
9315described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_),
9316it is undefined behavior to execute a :ref:`call <i_call>` or :ref:`invoke <i_invoke>`
9317that does not carry an appropriate :ref:`"funclet" bundle <ob_funclet>`.
David Majnemer8a1c45d2015-12-12 05:38:55 +00009318
David Majnemer654e1302015-07-31 17:58:14 +00009319Example:
9320""""""""
9321
Renato Golin124f2592016-07-20 12:16:38 +00009322.. code-block:: text
David Majnemer654e1302015-07-31 17:58:14 +00009323
David Majnemer8a1c45d2015-12-12 05:38:55 +00009324 %tok = cleanuppad within %cs []
David Majnemer654e1302015-07-31 17:58:14 +00009325
Sean Silvab084af42012-12-07 10:36:55 +00009326.. _intrinsics:
9327
9328Intrinsic Functions
9329===================
9330
9331LLVM supports the notion of an "intrinsic function". These functions
9332have well known names and semantics and are required to follow certain
9333restrictions. Overall, these intrinsics represent an extension mechanism
9334for the LLVM language that does not require changing all of the
9335transformations in LLVM when adding to the language (or the bitcode
9336reader/writer, the parser, etc...).
9337
9338Intrinsic function names must all start with an "``llvm.``" prefix. This
9339prefix is reserved in LLVM for intrinsic names; thus, function names may
9340not begin with this prefix. Intrinsic functions must always be external
9341functions: you cannot define the body of intrinsic functions. Intrinsic
9342functions may only be used in call or invoke instructions: it is illegal
9343to take the address of an intrinsic function. Additionally, because
9344intrinsic functions are part of the LLVM language, it is required if any
9345are added that they be documented here.
9346
9347Some intrinsic functions can be overloaded, i.e., the intrinsic
9348represents a family of functions that perform the same operation but on
9349different data types. Because LLVM can represent over 8 million
9350different integer types, overloading is used commonly to allow an
9351intrinsic function to operate on any integer type. One or more of the
9352argument types or the result type can be overloaded to accept any
9353integer type. Argument types may also be defined as exactly matching a
9354previous argument's type or the result type. This allows an intrinsic
9355function which accepts multiple arguments, but needs all of them to be
9356of the same type, to only be overloaded with respect to a single
9357argument or the result.
9358
9359Overloaded intrinsics will have the names of its overloaded argument
9360types encoded into its function name, each preceded by a period. Only
9361those types which are overloaded result in a name suffix. Arguments
9362whose type is matched against another type do not. For example, the
9363``llvm.ctpop`` function can take an integer of any width and returns an
9364integer of exactly the same integer width. This leads to a family of
9365functions such as ``i8 @llvm.ctpop.i8(i8 %val)`` and
9366``i29 @llvm.ctpop.i29(i29 %val)``. Only one type, the return type, is
9367overloaded, and only one type suffix is required. Because the argument's
9368type is matched against the return type, it does not require its own
9369name suffix.
9370
9371To learn how to add an intrinsic function, please see the `Extending
9372LLVM Guide <ExtendingLLVM.html>`_.
9373
9374.. _int_varargs:
9375
9376Variable Argument Handling Intrinsics
9377-------------------------------------
9378
9379Variable argument support is defined in LLVM with the
9380:ref:`va_arg <i_va_arg>` instruction and these three intrinsic
9381functions. These functions are related to the similarly named macros
9382defined in the ``<stdarg.h>`` header file.
9383
9384All of these functions operate on arguments that use a target-specific
9385value type "``va_list``". The LLVM assembly language reference manual
9386does not define what this type is, so all transformations should be
9387prepared to handle these functions regardless of the type used.
9388
9389This example shows how the :ref:`va_arg <i_va_arg>` instruction and the
9390variable argument handling intrinsic functions are used.
9391
9392.. code-block:: llvm
9393
Tim Northoverab60bb92014-11-02 01:21:51 +00009394 ; This struct is different for every platform. For most platforms,
9395 ; it is merely an i8*.
9396 %struct.va_list = type { i8* }
9397
9398 ; For Unix x86_64 platforms, va_list is the following struct:
9399 ; %struct.va_list = type { i32, i32, i8*, i8* }
9400
Sean Silvab084af42012-12-07 10:36:55 +00009401 define i32 @test(i32 %X, ...) {
9402 ; Initialize variable argument processing
Tim Northoverab60bb92014-11-02 01:21:51 +00009403 %ap = alloca %struct.va_list
9404 %ap2 = bitcast %struct.va_list* %ap to i8*
Sean Silvab084af42012-12-07 10:36:55 +00009405 call void @llvm.va_start(i8* %ap2)
9406
9407 ; Read a single integer argument
Tim Northoverab60bb92014-11-02 01:21:51 +00009408 %tmp = va_arg i8* %ap2, i32
Sean Silvab084af42012-12-07 10:36:55 +00009409
9410 ; Demonstrate usage of llvm.va_copy and llvm.va_end
9411 %aq = alloca i8*
9412 %aq2 = bitcast i8** %aq to i8*
9413 call void @llvm.va_copy(i8* %aq2, i8* %ap2)
9414 call void @llvm.va_end(i8* %aq2)
9415
9416 ; Stop processing of arguments.
9417 call void @llvm.va_end(i8* %ap2)
9418 ret i32 %tmp
9419 }
9420
9421 declare void @llvm.va_start(i8*)
9422 declare void @llvm.va_copy(i8*, i8*)
9423 declare void @llvm.va_end(i8*)
9424
9425.. _int_va_start:
9426
9427'``llvm.va_start``' Intrinsic
9428^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9429
9430Syntax:
9431"""""""
9432
9433::
9434
Nick Lewycky04f6de02013-09-11 22:04:52 +00009435 declare void @llvm.va_start(i8* <arglist>)
Sean Silvab084af42012-12-07 10:36:55 +00009436
9437Overview:
9438"""""""""
9439
9440The '``llvm.va_start``' intrinsic initializes ``*<arglist>`` for
9441subsequent use by ``va_arg``.
9442
9443Arguments:
9444""""""""""
9445
9446The argument is a pointer to a ``va_list`` element to initialize.
9447
9448Semantics:
9449""""""""""
9450
9451The '``llvm.va_start``' intrinsic works just like the ``va_start`` macro
9452available in C. In a target-dependent way, it initializes the
9453``va_list`` element to which the argument points, so that the next call
9454to ``va_arg`` will produce the first variable argument passed to the
9455function. Unlike the C ``va_start`` macro, this intrinsic does not need
9456to know the last argument of the function as the compiler can figure
9457that out.
9458
9459'``llvm.va_end``' Intrinsic
9460^^^^^^^^^^^^^^^^^^^^^^^^^^^
9461
9462Syntax:
9463"""""""
9464
9465::
9466
9467 declare void @llvm.va_end(i8* <arglist>)
9468
9469Overview:
9470"""""""""
9471
9472The '``llvm.va_end``' intrinsic destroys ``*<arglist>``, which has been
9473initialized previously with ``llvm.va_start`` or ``llvm.va_copy``.
9474
9475Arguments:
9476""""""""""
9477
9478The argument is a pointer to a ``va_list`` to destroy.
9479
9480Semantics:
9481""""""""""
9482
9483The '``llvm.va_end``' intrinsic works just like the ``va_end`` macro
9484available in C. In a target-dependent way, it destroys the ``va_list``
9485element to which the argument points. Calls to
9486:ref:`llvm.va_start <int_va_start>` and
9487:ref:`llvm.va_copy <int_va_copy>` must be matched exactly with calls to
9488``llvm.va_end``.
9489
9490.. _int_va_copy:
9491
9492'``llvm.va_copy``' Intrinsic
9493^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9494
9495Syntax:
9496"""""""
9497
9498::
9499
9500 declare void @llvm.va_copy(i8* <destarglist>, i8* <srcarglist>)
9501
9502Overview:
9503"""""""""
9504
9505The '``llvm.va_copy``' intrinsic copies the current argument position
9506from the source argument list to the destination argument list.
9507
9508Arguments:
9509""""""""""
9510
9511The first argument is a pointer to a ``va_list`` element to initialize.
9512The second argument is a pointer to a ``va_list`` element to copy from.
9513
9514Semantics:
9515""""""""""
9516
9517The '``llvm.va_copy``' intrinsic works just like the ``va_copy`` macro
9518available in C. In a target-dependent way, it copies the source
9519``va_list`` element into the destination ``va_list`` element. This
9520intrinsic is necessary because the `` llvm.va_start`` intrinsic may be
9521arbitrarily complex and require, for example, memory allocation.
9522
9523Accurate Garbage Collection Intrinsics
9524--------------------------------------
9525
Philip Reamesc5b0f562015-02-25 23:52:06 +00009526LLVM's support for `Accurate Garbage Collection <GarbageCollection.html>`_
Mehdi Amini4a121fa2015-03-14 22:04:06 +00009527(GC) requires the frontend to generate code containing appropriate intrinsic
9528calls and select an appropriate GC strategy which knows how to lower these
Philip Reamesc5b0f562015-02-25 23:52:06 +00009529intrinsics in a manner which is appropriate for the target collector.
9530
Sean Silvab084af42012-12-07 10:36:55 +00009531These intrinsics allow identification of :ref:`GC roots on the
9532stack <int_gcroot>`, as well as garbage collector implementations that
9533require :ref:`read <int_gcread>` and :ref:`write <int_gcwrite>` barriers.
Philip Reamesc5b0f562015-02-25 23:52:06 +00009534Frontends for type-safe garbage collected languages should generate
Sean Silvab084af42012-12-07 10:36:55 +00009535these intrinsics to make use of the LLVM garbage collectors. For more
Philip Reamesf80bbff2015-02-25 23:45:20 +00009536details, see `Garbage Collection with LLVM <GarbageCollection.html>`_.
Sean Silvab084af42012-12-07 10:36:55 +00009537
Philip Reamesf80bbff2015-02-25 23:45:20 +00009538Experimental Statepoint Intrinsics
9539^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9540
9541LLVM provides an second experimental set of intrinsics for describing garbage
Sean Silvaa1190322015-08-06 22:56:48 +00009542collection safepoints in compiled code. These intrinsics are an alternative
Mehdi Amini4a121fa2015-03-14 22:04:06 +00009543to the ``llvm.gcroot`` intrinsics, but are compatible with the ones for
Sean Silvaa1190322015-08-06 22:56:48 +00009544:ref:`read <int_gcread>` and :ref:`write <int_gcwrite>` barriers. The
Mehdi Amini4a121fa2015-03-14 22:04:06 +00009545differences in approach are covered in the `Garbage Collection with LLVM
Sean Silvaa1190322015-08-06 22:56:48 +00009546<GarbageCollection.html>`_ documentation. The intrinsics themselves are
Philip Reamesf80bbff2015-02-25 23:45:20 +00009547described in :doc:`Statepoints`.
Sean Silvab084af42012-12-07 10:36:55 +00009548
9549.. _int_gcroot:
9550
9551'``llvm.gcroot``' Intrinsic
9552^^^^^^^^^^^^^^^^^^^^^^^^^^^
9553
9554Syntax:
9555"""""""
9556
9557::
9558
9559 declare void @llvm.gcroot(i8** %ptrloc, i8* %metadata)
9560
9561Overview:
9562"""""""""
9563
9564The '``llvm.gcroot``' intrinsic declares the existence of a GC root to
9565the code generator, and allows some metadata to be associated with it.
9566
9567Arguments:
9568""""""""""
9569
9570The first argument specifies the address of a stack object that contains
9571the root pointer. The second pointer (which must be either a constant or
9572a global value address) contains the meta-data to be associated with the
9573root.
9574
9575Semantics:
9576""""""""""
9577
9578At runtime, a call to this intrinsic stores a null pointer into the
9579"ptrloc" location. At compile-time, the code generator generates
9580information to allow the runtime to find the pointer at GC safe points.
9581The '``llvm.gcroot``' intrinsic may only be used in a function which
9582:ref:`specifies a GC algorithm <gc>`.
9583
9584.. _int_gcread:
9585
9586'``llvm.gcread``' Intrinsic
9587^^^^^^^^^^^^^^^^^^^^^^^^^^^
9588
9589Syntax:
9590"""""""
9591
9592::
9593
9594 declare i8* @llvm.gcread(i8* %ObjPtr, i8** %Ptr)
9595
9596Overview:
9597"""""""""
9598
9599The '``llvm.gcread``' intrinsic identifies reads of references from heap
9600locations, allowing garbage collector implementations that require read
9601barriers.
9602
9603Arguments:
9604""""""""""
9605
9606The second argument is the address to read from, which should be an
9607address allocated from the garbage collector. The first object is a
9608pointer to the start of the referenced object, if needed by the language
9609runtime (otherwise null).
9610
9611Semantics:
9612""""""""""
9613
9614The '``llvm.gcread``' intrinsic has the same semantics as a load
9615instruction, but may be replaced with substantially more complex code by
9616the garbage collector runtime, as needed. The '``llvm.gcread``'
9617intrinsic may only be used in a function which :ref:`specifies a GC
9618algorithm <gc>`.
9619
9620.. _int_gcwrite:
9621
9622'``llvm.gcwrite``' Intrinsic
9623^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9624
9625Syntax:
9626"""""""
9627
9628::
9629
9630 declare void @llvm.gcwrite(i8* %P1, i8* %Obj, i8** %P2)
9631
9632Overview:
9633"""""""""
9634
9635The '``llvm.gcwrite``' intrinsic identifies writes of references to heap
9636locations, allowing garbage collector implementations that require write
9637barriers (such as generational or reference counting collectors).
9638
9639Arguments:
9640""""""""""
9641
9642The first argument is the reference to store, the second is the start of
9643the object to store it to, and the third is the address of the field of
9644Obj to store to. If the runtime does not require a pointer to the
9645object, Obj may be null.
9646
9647Semantics:
9648""""""""""
9649
9650The '``llvm.gcwrite``' intrinsic has the same semantics as a store
9651instruction, but may be replaced with substantially more complex code by
9652the garbage collector runtime, as needed. The '``llvm.gcwrite``'
9653intrinsic may only be used in a function which :ref:`specifies a GC
9654algorithm <gc>`.
9655
9656Code Generator Intrinsics
9657-------------------------
9658
9659These intrinsics are provided by LLVM to expose special features that
9660may only be implemented with code generator support.
9661
9662'``llvm.returnaddress``' Intrinsic
9663^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9664
9665Syntax:
9666"""""""
9667
9668::
9669
George Burgess IVfbc34982017-05-20 04:52:29 +00009670 declare i8* @llvm.returnaddress(i32 <level>)
Sean Silvab084af42012-12-07 10:36:55 +00009671
9672Overview:
9673"""""""""
9674
9675The '``llvm.returnaddress``' intrinsic attempts to compute a
9676target-specific value indicating the return address of the current
9677function or one of its callers.
9678
9679Arguments:
9680""""""""""
9681
9682The argument to this intrinsic indicates which function to return the
9683address for. Zero indicates the calling function, one indicates its
9684caller, etc. The argument is **required** to be a constant integer
9685value.
9686
9687Semantics:
9688""""""""""
9689
9690The '``llvm.returnaddress``' intrinsic either returns a pointer
9691indicating the return address of the specified call frame, or zero if it
9692cannot be identified. The value returned by this intrinsic is likely to
9693be incorrect or 0 for arguments other than zero, so it should only be
9694used for debugging purposes.
9695
9696Note that calling this intrinsic does not prevent function inlining or
9697other aggressive transformations, so the value returned may not be that
9698of the obvious source-language caller.
9699
Albert Gutowski795d7d62016-10-12 22:13:19 +00009700'``llvm.addressofreturnaddress``' Intrinsic
Albert Gutowski57ad5fe2016-10-12 23:10:02 +00009701^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Albert Gutowski795d7d62016-10-12 22:13:19 +00009702
9703Syntax:
9704"""""""
9705
9706::
9707
George Burgess IVfbc34982017-05-20 04:52:29 +00009708 declare i8* @llvm.addressofreturnaddress()
Albert Gutowski795d7d62016-10-12 22:13:19 +00009709
9710Overview:
9711"""""""""
9712
9713The '``llvm.addressofreturnaddress``' intrinsic returns a target-specific
9714pointer to the place in the stack frame where the return address of the
9715current function is stored.
9716
9717Semantics:
9718""""""""""
9719
9720Note that calling this intrinsic does not prevent function inlining or
9721other aggressive transformations, so the value returned may not be that
9722of the obvious source-language caller.
9723
9724This intrinsic is only implemented for x86.
9725
Sean Silvab084af42012-12-07 10:36:55 +00009726'``llvm.frameaddress``' Intrinsic
9727^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9728
9729Syntax:
9730"""""""
9731
9732::
9733
9734 declare i8* @llvm.frameaddress(i32 <level>)
9735
9736Overview:
9737"""""""""
9738
9739The '``llvm.frameaddress``' intrinsic attempts to return the
9740target-specific frame pointer value for the specified stack frame.
9741
9742Arguments:
9743""""""""""
9744
9745The argument to this intrinsic indicates which function to return the
9746frame pointer for. Zero indicates the calling function, one indicates
9747its caller, etc. The argument is **required** to be a constant integer
9748value.
9749
9750Semantics:
9751""""""""""
9752
9753The '``llvm.frameaddress``' intrinsic either returns a pointer
9754indicating the frame address of the specified call frame, or zero if it
9755cannot be identified. The value returned by this intrinsic is likely to
9756be incorrect or 0 for arguments other than zero, so it should only be
9757used for debugging purposes.
9758
9759Note that calling this intrinsic does not prevent function inlining or
9760other aggressive transformations, so the value returned may not be that
9761of the obvious source-language caller.
9762
Reid Kleckner60381792015-07-07 22:25:32 +00009763'``llvm.localescape``' and '``llvm.localrecover``' Intrinsics
Reid Klecknere9b89312015-01-13 00:48:10 +00009764^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9765
9766Syntax:
9767"""""""
9768
9769::
9770
Reid Kleckner60381792015-07-07 22:25:32 +00009771 declare void @llvm.localescape(...)
9772 declare i8* @llvm.localrecover(i8* %func, i8* %fp, i32 %idx)
Reid Klecknere9b89312015-01-13 00:48:10 +00009773
9774Overview:
9775"""""""""
9776
Reid Kleckner60381792015-07-07 22:25:32 +00009777The '``llvm.localescape``' intrinsic escapes offsets of a collection of static
9778allocas, and the '``llvm.localrecover``' intrinsic applies those offsets to a
Reid Klecknercfb9ce52015-03-05 18:26:34 +00009779live frame pointer to recover the address of the allocation. The offset is
Reid Kleckner60381792015-07-07 22:25:32 +00009780computed during frame layout of the caller of ``llvm.localescape``.
Reid Klecknere9b89312015-01-13 00:48:10 +00009781
9782Arguments:
9783""""""""""
9784
Reid Kleckner60381792015-07-07 22:25:32 +00009785All arguments to '``llvm.localescape``' must be pointers to static allocas or
9786casts of static allocas. Each function can only call '``llvm.localescape``'
Reid Klecknercfb9ce52015-03-05 18:26:34 +00009787once, and it can only do so from the entry block.
Reid Klecknere9b89312015-01-13 00:48:10 +00009788
Reid Kleckner60381792015-07-07 22:25:32 +00009789The ``func`` argument to '``llvm.localrecover``' must be a constant
Reid Klecknere9b89312015-01-13 00:48:10 +00009790bitcasted pointer to a function defined in the current module. The code
9791generator cannot determine the frame allocation offset of functions defined in
9792other modules.
9793
Reid Klecknerd5afc62f2015-07-07 23:23:03 +00009794The ``fp`` argument to '``llvm.localrecover``' must be a frame pointer of a
9795call frame that is currently live. The return value of '``llvm.localaddress``'
9796is one way to produce such a value, but various runtimes also expose a suitable
9797pointer in platform-specific ways.
Reid Klecknere9b89312015-01-13 00:48:10 +00009798
Reid Kleckner60381792015-07-07 22:25:32 +00009799The ``idx`` argument to '``llvm.localrecover``' indicates which alloca passed to
9800'``llvm.localescape``' to recover. It is zero-indexed.
Reid Klecknercfb9ce52015-03-05 18:26:34 +00009801
Reid Klecknere9b89312015-01-13 00:48:10 +00009802Semantics:
9803""""""""""
9804
Reid Kleckner60381792015-07-07 22:25:32 +00009805These intrinsics allow a group of functions to share access to a set of local
9806stack allocations of a one parent function. The parent function may call the
9807'``llvm.localescape``' intrinsic once from the function entry block, and the
9808child functions can use '``llvm.localrecover``' to access the escaped allocas.
9809The '``llvm.localescape``' intrinsic blocks inlining, as inlining changes where
9810the escaped allocas are allocated, which would break attempts to use
9811'``llvm.localrecover``'.
Reid Klecknere9b89312015-01-13 00:48:10 +00009812
Renato Golinc7aea402014-05-06 16:51:25 +00009813.. _int_read_register:
9814.. _int_write_register:
9815
9816'``llvm.read_register``' and '``llvm.write_register``' Intrinsics
9817^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9818
9819Syntax:
9820"""""""
9821
9822::
9823
9824 declare i32 @llvm.read_register.i32(metadata)
9825 declare i64 @llvm.read_register.i64(metadata)
9826 declare void @llvm.write_register.i32(metadata, i32 @value)
9827 declare void @llvm.write_register.i64(metadata, i64 @value)
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00009828 !0 = !{!"sp\00"}
Renato Golinc7aea402014-05-06 16:51:25 +00009829
9830Overview:
9831"""""""""
9832
9833The '``llvm.read_register``' and '``llvm.write_register``' intrinsics
9834provides access to the named register. The register must be valid on
9835the architecture being compiled to. The type needs to be compatible
9836with the register being read.
9837
9838Semantics:
9839""""""""""
9840
9841The '``llvm.read_register``' intrinsic returns the current value of the
9842register, where possible. The '``llvm.write_register``' intrinsic sets
9843the current value of the register, where possible.
9844
9845This is useful to implement named register global variables that need
9846to always be mapped to a specific register, as is common practice on
9847bare-metal programs including OS kernels.
9848
9849The compiler doesn't check for register availability or use of the used
9850register in surrounding code, including inline assembly. Because of that,
9851allocatable registers are not supported.
9852
9853Warning: So far it only works with the stack pointer on selected
Tim Northover3b0846e2014-05-24 12:50:23 +00009854architectures (ARM, AArch64, PowerPC and x86_64). Significant amount of
Renato Golinc7aea402014-05-06 16:51:25 +00009855work is needed to support other registers and even more so, allocatable
9856registers.
9857
Sean Silvab084af42012-12-07 10:36:55 +00009858.. _int_stacksave:
9859
9860'``llvm.stacksave``' Intrinsic
9861^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9862
9863Syntax:
9864"""""""
9865
9866::
9867
9868 declare i8* @llvm.stacksave()
9869
9870Overview:
9871"""""""""
9872
9873The '``llvm.stacksave``' intrinsic is used to remember the current state
9874of the function stack, for use with
9875:ref:`llvm.stackrestore <int_stackrestore>`. This is useful for
9876implementing language features like scoped automatic variable sized
9877arrays in C99.
9878
9879Semantics:
9880""""""""""
9881
9882This intrinsic returns a opaque pointer value that can be passed to
9883:ref:`llvm.stackrestore <int_stackrestore>`. When an
9884``llvm.stackrestore`` intrinsic is executed with a value saved from
9885``llvm.stacksave``, it effectively restores the state of the stack to
9886the state it was in when the ``llvm.stacksave`` intrinsic executed. In
9887practice, this pops any :ref:`alloca <i_alloca>` blocks from the stack that
9888were allocated after the ``llvm.stacksave`` was executed.
9889
9890.. _int_stackrestore:
9891
9892'``llvm.stackrestore``' Intrinsic
9893^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9894
9895Syntax:
9896"""""""
9897
9898::
9899
9900 declare void @llvm.stackrestore(i8* %ptr)
9901
9902Overview:
9903"""""""""
9904
9905The '``llvm.stackrestore``' intrinsic is used to restore the state of
9906the function stack to the state it was in when the corresponding
9907:ref:`llvm.stacksave <int_stacksave>` intrinsic executed. This is
9908useful for implementing language features like scoped automatic variable
9909sized arrays in C99.
9910
9911Semantics:
9912""""""""""
9913
9914See the description for :ref:`llvm.stacksave <int_stacksave>`.
9915
Yury Gribovd7dbb662015-12-01 11:40:55 +00009916.. _int_get_dynamic_area_offset:
9917
9918'``llvm.get.dynamic.area.offset``' Intrinsic
Yury Gribov81f3f152015-12-01 13:24:48 +00009919^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Yury Gribovd7dbb662015-12-01 11:40:55 +00009920
9921Syntax:
9922"""""""
9923
9924::
9925
9926 declare i32 @llvm.get.dynamic.area.offset.i32()
9927 declare i64 @llvm.get.dynamic.area.offset.i64()
9928
Lang Hames10239932016-10-08 00:20:42 +00009929Overview:
9930"""""""""
Yury Gribovd7dbb662015-12-01 11:40:55 +00009931
9932 The '``llvm.get.dynamic.area.offset.*``' intrinsic family is used to
9933 get the offset from native stack pointer to the address of the most
9934 recent dynamic alloca on the caller's stack. These intrinsics are
9935 intendend for use in combination with
9936 :ref:`llvm.stacksave <int_stacksave>` to get a
9937 pointer to the most recent dynamic alloca. This is useful, for example,
9938 for AddressSanitizer's stack unpoisoning routines.
9939
9940Semantics:
9941""""""""""
9942
9943 These intrinsics return a non-negative integer value that can be used to
9944 get the address of the most recent dynamic alloca, allocated by :ref:`alloca <i_alloca>`
9945 on the caller's stack. In particular, for targets where stack grows downwards,
9946 adding this offset to the native stack pointer would get the address of the most
9947 recent dynamic alloca. For targets where stack grows upwards, the situation is a bit more
Sylvestre Ledru0455cbe2016-07-28 09:28:58 +00009948 complicated, because subtracting this value from stack pointer would get the address
Yury Gribovd7dbb662015-12-01 11:40:55 +00009949 one past the end of the most recent dynamic alloca.
9950
9951 Although for most targets `llvm.get.dynamic.area.offset <int_get_dynamic_area_offset>`
9952 returns just a zero, for others, such as PowerPC and PowerPC64, it returns a
9953 compile-time-known constant value.
9954
9955 The return value type of :ref:`llvm.get.dynamic.area.offset <int_get_dynamic_area_offset>`
Matt Arsenaultc749bdc2017-03-30 23:36:47 +00009956 must match the target's default address space's (address space 0) pointer type.
Yury Gribovd7dbb662015-12-01 11:40:55 +00009957
Sean Silvab084af42012-12-07 10:36:55 +00009958'``llvm.prefetch``' Intrinsic
9959^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9960
9961Syntax:
9962"""""""
9963
9964::
9965
9966 declare void @llvm.prefetch(i8* <address>, i32 <rw>, i32 <locality>, i32 <cache type>)
9967
9968Overview:
9969"""""""""
9970
9971The '``llvm.prefetch``' intrinsic is a hint to the code generator to
9972insert a prefetch instruction if supported; otherwise, it is a noop.
9973Prefetches have no effect on the behavior of the program but can change
9974its performance characteristics.
9975
9976Arguments:
9977""""""""""
9978
9979``address`` is the address to be prefetched, ``rw`` is the specifier
9980determining if the fetch should be for a read (0) or write (1), and
9981``locality`` is a temporal locality specifier ranging from (0) - no
9982locality, to (3) - extremely local keep in cache. The ``cache type``
9983specifies whether the prefetch is performed on the data (1) or
9984instruction (0) cache. The ``rw``, ``locality`` and ``cache type``
9985arguments must be constant integers.
9986
9987Semantics:
9988""""""""""
9989
9990This intrinsic does not modify the behavior of the program. In
9991particular, prefetches cannot trap and do not produce a value. On
9992targets that support this intrinsic, the prefetch can provide hints to
9993the processor cache for better performance.
9994
9995'``llvm.pcmarker``' Intrinsic
9996^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9997
9998Syntax:
9999"""""""
10000
10001::
10002
10003 declare void @llvm.pcmarker(i32 <id>)
10004
10005Overview:
10006"""""""""
10007
10008The '``llvm.pcmarker``' intrinsic is a method to export a Program
10009Counter (PC) in a region of code to simulators and other tools. The
10010method is target specific, but it is expected that the marker will use
10011exported symbols to transmit the PC of the marker. The marker makes no
10012guarantees that it will remain with any specific instruction after
10013optimizations. It is possible that the presence of a marker will inhibit
10014optimizations. The intended use is to be inserted after optimizations to
10015allow correlations of simulation runs.
10016
10017Arguments:
10018""""""""""
10019
10020``id`` is a numerical id identifying the marker.
10021
10022Semantics:
10023""""""""""
10024
10025This intrinsic does not modify the behavior of the program. Backends
10026that do not support this intrinsic may ignore it.
10027
10028'``llvm.readcyclecounter``' Intrinsic
10029^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10030
10031Syntax:
10032"""""""
10033
10034::
10035
10036 declare i64 @llvm.readcyclecounter()
10037
10038Overview:
10039"""""""""
10040
10041The '``llvm.readcyclecounter``' intrinsic provides access to the cycle
10042counter register (or similar low latency, high accuracy clocks) on those
10043targets that support it. On X86, it should map to RDTSC. On Alpha, it
10044should map to RPCC. As the backing counters overflow quickly (on the
10045order of 9 seconds on alpha), this should only be used for small
10046timings.
10047
10048Semantics:
10049""""""""""
10050
10051When directly supported, reading the cycle counter should not modify any
10052memory. Implementations are allowed to either return a application
10053specific value or a system wide value. On backends without support, this
10054is lowered to a constant 0.
10055
Tim Northoverbc933082013-05-23 19:11:20 +000010056Note that runtime support may be conditional on the privilege-level code is
10057running at and the host platform.
10058
Renato Golinc0a3c1d2014-03-26 12:52:28 +000010059'``llvm.clear_cache``' Intrinsic
10060^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10061
10062Syntax:
10063"""""""
10064
10065::
10066
10067 declare void @llvm.clear_cache(i8*, i8*)
10068
10069Overview:
10070"""""""""
10071
Joerg Sonnenberger03014d62014-03-26 14:35:21 +000010072The '``llvm.clear_cache``' intrinsic ensures visibility of modifications
10073in the specified range to the execution unit of the processor. On
10074targets with non-unified instruction and data cache, the implementation
10075flushes the instruction cache.
Renato Golinc0a3c1d2014-03-26 12:52:28 +000010076
10077Semantics:
10078""""""""""
10079
Joerg Sonnenberger03014d62014-03-26 14:35:21 +000010080On platforms with coherent instruction and data caches (e.g. x86), this
10081intrinsic is a nop. On platforms with non-coherent instruction and data
Alp Toker16f98b22014-04-09 14:47:27 +000010082cache (e.g. ARM, MIPS), the intrinsic is lowered either to appropriate
Joerg Sonnenberger03014d62014-03-26 14:35:21 +000010083instructions or a system call, if cache flushing requires special
10084privileges.
Renato Golinc0a3c1d2014-03-26 12:52:28 +000010085
Sean Silvad02bf3e2014-04-07 22:29:53 +000010086The default behavior is to emit a call to ``__clear_cache`` from the run
Joerg Sonnenberger03014d62014-03-26 14:35:21 +000010087time library.
Renato Golin93010e62014-03-26 14:01:32 +000010088
Joerg Sonnenberger03014d62014-03-26 14:35:21 +000010089This instrinsic does *not* empty the instruction pipeline. Modifications
10090of the current function are outside the scope of the intrinsic.
Renato Golinc0a3c1d2014-03-26 12:52:28 +000010091
Justin Bogner61ba2e32014-12-08 18:02:35 +000010092'``llvm.instrprof_increment``' Intrinsic
10093^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10094
10095Syntax:
10096"""""""
10097
10098::
10099
10100 declare void @llvm.instrprof_increment(i8* <name>, i64 <hash>,
10101 i32 <num-counters>, i32 <index>)
10102
10103Overview:
10104"""""""""
10105
10106The '``llvm.instrprof_increment``' intrinsic can be emitted by a
10107frontend for use with instrumentation based profiling. These will be
10108lowered by the ``-instrprof`` pass to generate execution counts of a
10109program at runtime.
10110
10111Arguments:
10112""""""""""
10113
10114The first argument is a pointer to a global variable containing the
10115name of the entity being instrumented. This should generally be the
10116(mangled) function name for a set of counters.
10117
10118The second argument is a hash value that can be used by the consumer
10119of the profile data to detect changes to the instrumented source, and
10120the third is the number of counters associated with ``name``. It is an
10121error if ``hash`` or ``num-counters`` differ between two instances of
10122``instrprof_increment`` that refer to the same name.
10123
10124The last argument refers to which of the counters for ``name`` should
10125be incremented. It should be a value between 0 and ``num-counters``.
10126
10127Semantics:
10128""""""""""
10129
10130This intrinsic represents an increment of a profiling counter. It will
10131cause the ``-instrprof`` pass to generate the appropriate data
10132structures and the code to increment the appropriate value, in a
10133format that can be written out by a compiler runtime and consumed via
10134the ``llvm-profdata`` tool.
10135
Xinliang David Li4ca17332016-09-18 18:34:07 +000010136'``llvm.instrprof_increment_step``' Intrinsic
Xinliang David Lie1117102016-09-18 22:10:19 +000010137^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Xinliang David Li4ca17332016-09-18 18:34:07 +000010138
10139Syntax:
10140"""""""
10141
10142::
10143
10144 declare void @llvm.instrprof_increment_step(i8* <name>, i64 <hash>,
10145 i32 <num-counters>,
10146 i32 <index>, i64 <step>)
10147
10148Overview:
10149"""""""""
10150
10151The '``llvm.instrprof_increment_step``' intrinsic is an extension to
10152the '``llvm.instrprof_increment``' intrinsic with an additional fifth
10153argument to specify the step of the increment.
10154
10155Arguments:
10156""""""""""
10157The first four arguments are the same as '``llvm.instrprof_increment``'
Pete Couperused9569d2017-08-23 20:58:22 +000010158intrinsic.
Xinliang David Li4ca17332016-09-18 18:34:07 +000010159
10160The last argument specifies the value of the increment of the counter variable.
10161
10162Semantics:
10163""""""""""
10164See description of '``llvm.instrprof_increment``' instrinsic.
10165
10166
Betul Buyukkurt6fac1742015-11-18 18:14:55 +000010167'``llvm.instrprof_value_profile``' Intrinsic
10168^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10169
10170Syntax:
10171"""""""
10172
10173::
10174
10175 declare void @llvm.instrprof_value_profile(i8* <name>, i64 <hash>,
10176 i64 <value>, i32 <value_kind>,
10177 i32 <index>)
10178
10179Overview:
10180"""""""""
10181
10182The '``llvm.instrprof_value_profile``' intrinsic can be emitted by a
10183frontend for use with instrumentation based profiling. This will be
10184lowered by the ``-instrprof`` pass to find out the target values,
10185instrumented expressions take in a program at runtime.
10186
10187Arguments:
10188""""""""""
10189
10190The first argument is a pointer to a global variable containing the
10191name of the entity being instrumented. ``name`` should generally be the
10192(mangled) function name for a set of counters.
10193
10194The second argument is a hash value that can be used by the consumer
10195of the profile data to detect changes to the instrumented source. It
10196is an error if ``hash`` differs between two instances of
10197``llvm.instrprof_*`` that refer to the same name.
10198
10199The third argument is the value of the expression being profiled. The profiled
10200expression's value should be representable as an unsigned 64-bit value. The
10201fourth argument represents the kind of value profiling that is being done. The
10202supported value profiling kinds are enumerated through the
10203``InstrProfValueKind`` type declared in the
10204``<include/llvm/ProfileData/InstrProf.h>`` header file. The last argument is the
10205index of the instrumented expression within ``name``. It should be >= 0.
10206
10207Semantics:
10208""""""""""
10209
10210This intrinsic represents the point where a call to a runtime routine
10211should be inserted for value profiling of target expressions. ``-instrprof``
10212pass will generate the appropriate data structures and replace the
10213``llvm.instrprof_value_profile`` intrinsic with the call to the profile
10214runtime library with proper arguments.
10215
Marcin Koscielnicki3fdc2572016-04-19 20:51:05 +000010216'``llvm.thread.pointer``' Intrinsic
10217^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10218
10219Syntax:
10220"""""""
10221
10222::
10223
10224 declare i8* @llvm.thread.pointer()
10225
10226Overview:
10227"""""""""
10228
10229The '``llvm.thread.pointer``' intrinsic returns the value of the thread
10230pointer.
10231
10232Semantics:
10233""""""""""
10234
10235The '``llvm.thread.pointer``' intrinsic returns a pointer to the TLS area
10236for the current thread. The exact semantics of this value are target
10237specific: it may point to the start of TLS area, to the end, or somewhere
10238in the middle. Depending on the target, this intrinsic may read a register,
10239call a helper function, read from an alternate memory space, or perform
10240other operations necessary to locate the TLS area. Not all targets support
10241this intrinsic.
10242
Sean Silvab084af42012-12-07 10:36:55 +000010243Standard C Library Intrinsics
10244-----------------------------
10245
10246LLVM provides intrinsics for a few important standard C library
10247functions. These intrinsics allow source-language front-ends to pass
10248information about the alignment of the pointer arguments to the code
10249generator, providing opportunity for more efficient code generation.
10250
10251.. _int_memcpy:
10252
10253'``llvm.memcpy``' Intrinsic
10254^^^^^^^^^^^^^^^^^^^^^^^^^^^
10255
10256Syntax:
10257"""""""
10258
10259This is an overloaded intrinsic. You can use ``llvm.memcpy`` on any
10260integer bit width and for different address spaces. Not all targets
10261support all bit widths however.
10262
10263::
10264
10265 declare void @llvm.memcpy.p0i8.p0i8.i32(i8* <dest>, i8* <src>,
10266 i32 <len>, i32 <align>, i1 <isvolatile>)
10267 declare void @llvm.memcpy.p0i8.p0i8.i64(i8* <dest>, i8* <src>,
10268 i64 <len>, i32 <align>, i1 <isvolatile>)
10269
10270Overview:
10271"""""""""
10272
10273The '``llvm.memcpy.*``' intrinsics copy a block of memory from the
10274source location to the destination location.
10275
10276Note that, unlike the standard libc function, the ``llvm.memcpy.*``
10277intrinsics do not return a value, takes extra alignment/isvolatile
10278arguments and the pointers can be in specified address spaces.
10279
10280Arguments:
10281""""""""""
10282
10283The first argument is a pointer to the destination, the second is a
10284pointer to the source. The third argument is an integer argument
10285specifying the number of bytes to copy, the fourth argument is the
10286alignment of the source and destination locations, and the fifth is a
10287boolean indicating a volatile access.
10288
10289If the call to this intrinsic has an alignment value that is not 0 or 1,
10290then the caller guarantees that both the source and destination pointers
10291are aligned to that boundary.
10292
10293If the ``isvolatile`` parameter is ``true``, the ``llvm.memcpy`` call is
10294a :ref:`volatile operation <volatile>`. The detailed access behavior is not
10295very cleanly specified and it is unwise to depend on it.
10296
10297Semantics:
10298""""""""""
10299
10300The '``llvm.memcpy.*``' intrinsics copy a block of memory from the
10301source location to the destination location, which are not allowed to
10302overlap. It copies "len" bytes of memory over. If the argument is known
10303to be aligned to some boundary, this can be specified as the fourth
Bill Wendling61163152013-10-18 23:26:55 +000010304argument, otherwise it should be set to 0 or 1 (both meaning no alignment).
Sean Silvab084af42012-12-07 10:36:55 +000010305
Daniel Neilson57226ef2017-07-12 15:25:26 +000010306.. _int_memmove:
10307
Sean Silvab084af42012-12-07 10:36:55 +000010308'``llvm.memmove``' Intrinsic
10309^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10310
10311Syntax:
10312"""""""
10313
10314This is an overloaded intrinsic. You can use llvm.memmove on any integer
10315bit width and for different address space. Not all targets support all
10316bit widths however.
10317
10318::
10319
10320 declare void @llvm.memmove.p0i8.p0i8.i32(i8* <dest>, i8* <src>,
10321 i32 <len>, i32 <align>, i1 <isvolatile>)
10322 declare void @llvm.memmove.p0i8.p0i8.i64(i8* <dest>, i8* <src>,
10323 i64 <len>, i32 <align>, i1 <isvolatile>)
10324
10325Overview:
10326"""""""""
10327
10328The '``llvm.memmove.*``' intrinsics move a block of memory from the
10329source location to the destination location. It is similar to the
10330'``llvm.memcpy``' intrinsic but allows the two memory locations to
10331overlap.
10332
10333Note that, unlike the standard libc function, the ``llvm.memmove.*``
10334intrinsics do not return a value, takes extra alignment/isvolatile
10335arguments and the pointers can be in specified address spaces.
10336
10337Arguments:
10338""""""""""
10339
10340The first argument is a pointer to the destination, the second is a
10341pointer to the source. The third argument is an integer argument
10342specifying the number of bytes to copy, the fourth argument is the
10343alignment of the source and destination locations, and the fifth is a
10344boolean indicating a volatile access.
10345
10346If the call to this intrinsic has an alignment value that is not 0 or 1,
10347then the caller guarantees that the source and destination pointers are
10348aligned to that boundary.
10349
10350If the ``isvolatile`` parameter is ``true``, the ``llvm.memmove`` call
10351is a :ref:`volatile operation <volatile>`. The detailed access behavior is
10352not very cleanly specified and it is unwise to depend on it.
10353
10354Semantics:
10355""""""""""
10356
10357The '``llvm.memmove.*``' intrinsics copy a block of memory from the
10358source location to the destination location, which may overlap. It
10359copies "len" bytes of memory over. If the argument is known to be
10360aligned to some boundary, this can be specified as the fourth argument,
Bill Wendling61163152013-10-18 23:26:55 +000010361otherwise it should be set to 0 or 1 (both meaning no alignment).
Sean Silvab084af42012-12-07 10:36:55 +000010362
Daniel Neilson965613e2017-07-12 21:57:23 +000010363.. _int_memset:
10364
Sean Silvab084af42012-12-07 10:36:55 +000010365'``llvm.memset.*``' Intrinsics
10366^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10367
10368Syntax:
10369"""""""
10370
10371This is an overloaded intrinsic. You can use llvm.memset on any integer
10372bit width and for different address spaces. However, not all targets
10373support all bit widths.
10374
10375::
10376
10377 declare void @llvm.memset.p0i8.i32(i8* <dest>, i8 <val>,
10378 i32 <len>, i32 <align>, i1 <isvolatile>)
10379 declare void @llvm.memset.p0i8.i64(i8* <dest>, i8 <val>,
10380 i64 <len>, i32 <align>, i1 <isvolatile>)
10381
10382Overview:
10383"""""""""
10384
10385The '``llvm.memset.*``' intrinsics fill a block of memory with a
10386particular byte value.
10387
10388Note that, unlike the standard libc function, the ``llvm.memset``
10389intrinsic does not return a value and takes extra alignment/volatile
10390arguments. Also, the destination can be in an arbitrary address space.
10391
10392Arguments:
10393""""""""""
10394
10395The first argument is a pointer to the destination to fill, the second
10396is the byte value with which to fill it, the third argument is an
10397integer argument specifying the number of bytes to fill, and the fourth
10398argument is the known alignment of the destination location.
10399
10400If the call to this intrinsic has an alignment value that is not 0 or 1,
10401then the caller guarantees that the destination pointer is aligned to
10402that boundary.
10403
10404If the ``isvolatile`` parameter is ``true``, the ``llvm.memset`` call is
10405a :ref:`volatile operation <volatile>`. The detailed access behavior is not
10406very cleanly specified and it is unwise to depend on it.
10407
10408Semantics:
10409""""""""""
10410
10411The '``llvm.memset.*``' intrinsics fill "len" bytes of memory starting
10412at the destination location. If the argument is known to be aligned to
10413some boundary, this can be specified as the fourth argument, otherwise
Bill Wendling61163152013-10-18 23:26:55 +000010414it should be set to 0 or 1 (both meaning no alignment).
Sean Silvab084af42012-12-07 10:36:55 +000010415
10416'``llvm.sqrt.*``' Intrinsic
10417^^^^^^^^^^^^^^^^^^^^^^^^^^^
10418
10419Syntax:
10420"""""""
10421
10422This is an overloaded intrinsic. You can use ``llvm.sqrt`` on any
10423floating point or vector of floating point type. Not all targets support
10424all types however.
10425
10426::
10427
10428 declare float @llvm.sqrt.f32(float %Val)
10429 declare double @llvm.sqrt.f64(double %Val)
10430 declare x86_fp80 @llvm.sqrt.f80(x86_fp80 %Val)
10431 declare fp128 @llvm.sqrt.f128(fp128 %Val)
10432 declare ppc_fp128 @llvm.sqrt.ppcf128(ppc_fp128 %Val)
10433
10434Overview:
10435"""""""""
10436
Andrew Kaylorcaf24d22017-04-11 21:52:40 +000010437The '``llvm.sqrt``' intrinsics return the square root of the specified value,
Justin Lebarcb9b41d2017-01-27 00:58:03 +000010438returning the same value as the libm '``sqrt``' functions would, but without
10439trapping or setting ``errno``.
Sean Silvab084af42012-12-07 10:36:55 +000010440
10441Arguments:
10442""""""""""
10443
Andrew Kaylorcaf24d22017-04-11 21:52:40 +000010444The argument and return value are floating point numbers of the same type.
Sean Silvab084af42012-12-07 10:36:55 +000010445
10446Semantics:
10447""""""""""
10448
Andrew Kaylorcaf24d22017-04-11 21:52:40 +000010449This function returns the square root of the operand if it is a nonnegative
10450floating point number.
Sean Silvab084af42012-12-07 10:36:55 +000010451
10452'``llvm.powi.*``' Intrinsic
10453^^^^^^^^^^^^^^^^^^^^^^^^^^^
10454
10455Syntax:
10456"""""""
10457
10458This is an overloaded intrinsic. You can use ``llvm.powi`` on any
10459floating point or vector of floating point type. Not all targets support
10460all types however.
10461
10462::
10463
10464 declare float @llvm.powi.f32(float %Val, i32 %power)
10465 declare double @llvm.powi.f64(double %Val, i32 %power)
10466 declare x86_fp80 @llvm.powi.f80(x86_fp80 %Val, i32 %power)
10467 declare fp128 @llvm.powi.f128(fp128 %Val, i32 %power)
10468 declare ppc_fp128 @llvm.powi.ppcf128(ppc_fp128 %Val, i32 %power)
10469
10470Overview:
10471"""""""""
10472
10473The '``llvm.powi.*``' intrinsics return the first operand raised to the
10474specified (positive or negative) power. The order of evaluation of
10475multiplications is not defined. When a vector of floating point type is
10476used, the second argument remains a scalar integer value.
10477
10478Arguments:
10479""""""""""
10480
10481The second argument is an integer power, and the first is a value to
10482raise to that power.
10483
10484Semantics:
10485""""""""""
10486
10487This function returns the first value raised to the second power with an
10488unspecified sequence of rounding operations.
10489
10490'``llvm.sin.*``' Intrinsic
10491^^^^^^^^^^^^^^^^^^^^^^^^^^
10492
10493Syntax:
10494"""""""
10495
10496This is an overloaded intrinsic. You can use ``llvm.sin`` on any
10497floating point or vector of floating point type. Not all targets support
10498all types however.
10499
10500::
10501
10502 declare float @llvm.sin.f32(float %Val)
10503 declare double @llvm.sin.f64(double %Val)
10504 declare x86_fp80 @llvm.sin.f80(x86_fp80 %Val)
10505 declare fp128 @llvm.sin.f128(fp128 %Val)
10506 declare ppc_fp128 @llvm.sin.ppcf128(ppc_fp128 %Val)
10507
10508Overview:
10509"""""""""
10510
10511The '``llvm.sin.*``' intrinsics return the sine of the operand.
10512
10513Arguments:
10514""""""""""
10515
Andrew Kaylorcaf24d22017-04-11 21:52:40 +000010516The argument and return value are floating point numbers of the same type.
Sean Silvab084af42012-12-07 10:36:55 +000010517
10518Semantics:
10519""""""""""
10520
10521This function returns the sine of the specified operand, returning the
10522same values as the libm ``sin`` functions would, and handles error
10523conditions in the same way.
10524
10525'``llvm.cos.*``' Intrinsic
10526^^^^^^^^^^^^^^^^^^^^^^^^^^
10527
10528Syntax:
10529"""""""
10530
10531This is an overloaded intrinsic. You can use ``llvm.cos`` on any
10532floating point or vector of floating point type. Not all targets support
10533all types however.
10534
10535::
10536
10537 declare float @llvm.cos.f32(float %Val)
10538 declare double @llvm.cos.f64(double %Val)
10539 declare x86_fp80 @llvm.cos.f80(x86_fp80 %Val)
10540 declare fp128 @llvm.cos.f128(fp128 %Val)
10541 declare ppc_fp128 @llvm.cos.ppcf128(ppc_fp128 %Val)
10542
10543Overview:
10544"""""""""
10545
10546The '``llvm.cos.*``' intrinsics return the cosine of the operand.
10547
10548Arguments:
10549""""""""""
10550
Andrew Kaylorcaf24d22017-04-11 21:52:40 +000010551The argument and return value are floating point numbers of the same type.
Sean Silvab084af42012-12-07 10:36:55 +000010552
10553Semantics:
10554""""""""""
10555
10556This function returns the cosine of the specified operand, returning the
10557same values as the libm ``cos`` functions would, and handles error
10558conditions in the same way.
10559
10560'``llvm.pow.*``' Intrinsic
10561^^^^^^^^^^^^^^^^^^^^^^^^^^
10562
10563Syntax:
10564"""""""
10565
10566This is an overloaded intrinsic. You can use ``llvm.pow`` on any
10567floating point or vector of floating point type. Not all targets support
10568all types however.
10569
10570::
10571
10572 declare float @llvm.pow.f32(float %Val, float %Power)
10573 declare double @llvm.pow.f64(double %Val, double %Power)
10574 declare x86_fp80 @llvm.pow.f80(x86_fp80 %Val, x86_fp80 %Power)
10575 declare fp128 @llvm.pow.f128(fp128 %Val, fp128 %Power)
10576 declare ppc_fp128 @llvm.pow.ppcf128(ppc_fp128 %Val, ppc_fp128 Power)
10577
10578Overview:
10579"""""""""
10580
10581The '``llvm.pow.*``' intrinsics return the first operand raised to the
10582specified (positive or negative) power.
10583
10584Arguments:
10585""""""""""
10586
10587The second argument is a floating point power, and the first is a value
10588to raise to that power.
10589
10590Semantics:
10591""""""""""
10592
10593This function returns the first value raised to the second power,
10594returning the same values as the libm ``pow`` functions would, and
10595handles error conditions in the same way.
10596
10597'``llvm.exp.*``' Intrinsic
10598^^^^^^^^^^^^^^^^^^^^^^^^^^
10599
10600Syntax:
10601"""""""
10602
10603This is an overloaded intrinsic. You can use ``llvm.exp`` on any
10604floating point or vector of floating point type. Not all targets support
10605all types however.
10606
10607::
10608
10609 declare float @llvm.exp.f32(float %Val)
10610 declare double @llvm.exp.f64(double %Val)
10611 declare x86_fp80 @llvm.exp.f80(x86_fp80 %Val)
10612 declare fp128 @llvm.exp.f128(fp128 %Val)
10613 declare ppc_fp128 @llvm.exp.ppcf128(ppc_fp128 %Val)
10614
10615Overview:
10616"""""""""
10617
Andrew Kaylorcaf24d22017-04-11 21:52:40 +000010618The '``llvm.exp.*``' intrinsics compute the base-e exponential of the specified
10619value.
Sean Silvab084af42012-12-07 10:36:55 +000010620
10621Arguments:
10622""""""""""
10623
Andrew Kaylorcaf24d22017-04-11 21:52:40 +000010624The argument and return value are floating point numbers of the same type.
Sean Silvab084af42012-12-07 10:36:55 +000010625
10626Semantics:
10627""""""""""
10628
10629This function returns the same values as the libm ``exp`` functions
10630would, and handles error conditions in the same way.
10631
10632'``llvm.exp2.*``' Intrinsic
10633^^^^^^^^^^^^^^^^^^^^^^^^^^^
10634
10635Syntax:
10636"""""""
10637
10638This is an overloaded intrinsic. You can use ``llvm.exp2`` on any
10639floating point or vector of floating point type. Not all targets support
10640all types however.
10641
10642::
10643
10644 declare float @llvm.exp2.f32(float %Val)
10645 declare double @llvm.exp2.f64(double %Val)
10646 declare x86_fp80 @llvm.exp2.f80(x86_fp80 %Val)
10647 declare fp128 @llvm.exp2.f128(fp128 %Val)
10648 declare ppc_fp128 @llvm.exp2.ppcf128(ppc_fp128 %Val)
10649
10650Overview:
10651"""""""""
10652
Andrew Kaylorcaf24d22017-04-11 21:52:40 +000010653The '``llvm.exp2.*``' intrinsics compute the base-2 exponential of the
10654specified value.
Sean Silvab084af42012-12-07 10:36:55 +000010655
10656Arguments:
10657""""""""""
10658
Andrew Kaylorcaf24d22017-04-11 21:52:40 +000010659The argument and return value are floating point numbers of the same type.
Sean Silvab084af42012-12-07 10:36:55 +000010660
10661Semantics:
10662""""""""""
10663
10664This function returns the same values as the libm ``exp2`` functions
10665would, and handles error conditions in the same way.
10666
10667'``llvm.log.*``' Intrinsic
10668^^^^^^^^^^^^^^^^^^^^^^^^^^
10669
10670Syntax:
10671"""""""
10672
10673This is an overloaded intrinsic. You can use ``llvm.log`` on any
10674floating point or vector of floating point type. Not all targets support
10675all types however.
10676
10677::
10678
10679 declare float @llvm.log.f32(float %Val)
10680 declare double @llvm.log.f64(double %Val)
10681 declare x86_fp80 @llvm.log.f80(x86_fp80 %Val)
10682 declare fp128 @llvm.log.f128(fp128 %Val)
10683 declare ppc_fp128 @llvm.log.ppcf128(ppc_fp128 %Val)
10684
10685Overview:
10686"""""""""
10687
Andrew Kaylorcaf24d22017-04-11 21:52:40 +000010688The '``llvm.log.*``' intrinsics compute the base-e logarithm of the specified
10689value.
Sean Silvab084af42012-12-07 10:36:55 +000010690
10691Arguments:
10692""""""""""
10693
Andrew Kaylorcaf24d22017-04-11 21:52:40 +000010694The argument and return value are floating point numbers of the same type.
Sean Silvab084af42012-12-07 10:36:55 +000010695
10696Semantics:
10697""""""""""
10698
10699This function returns the same values as the libm ``log`` functions
10700would, and handles error conditions in the same way.
10701
10702'``llvm.log10.*``' Intrinsic
10703^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10704
10705Syntax:
10706"""""""
10707
10708This is an overloaded intrinsic. You can use ``llvm.log10`` on any
10709floating point or vector of floating point type. Not all targets support
10710all types however.
10711
10712::
10713
10714 declare float @llvm.log10.f32(float %Val)
10715 declare double @llvm.log10.f64(double %Val)
10716 declare x86_fp80 @llvm.log10.f80(x86_fp80 %Val)
10717 declare fp128 @llvm.log10.f128(fp128 %Val)
10718 declare ppc_fp128 @llvm.log10.ppcf128(ppc_fp128 %Val)
10719
10720Overview:
10721"""""""""
10722
Andrew Kaylorcaf24d22017-04-11 21:52:40 +000010723The '``llvm.log10.*``' intrinsics compute the base-10 logarithm of the
10724specified value.
Sean Silvab084af42012-12-07 10:36:55 +000010725
10726Arguments:
10727""""""""""
10728
Andrew Kaylorcaf24d22017-04-11 21:52:40 +000010729The argument and return value are floating point numbers of the same type.
Sean Silvab084af42012-12-07 10:36:55 +000010730
10731Semantics:
10732""""""""""
10733
10734This function returns the same values as the libm ``log10`` functions
10735would, and handles error conditions in the same way.
10736
10737'``llvm.log2.*``' Intrinsic
10738^^^^^^^^^^^^^^^^^^^^^^^^^^^
10739
10740Syntax:
10741"""""""
10742
10743This is an overloaded intrinsic. You can use ``llvm.log2`` on any
10744floating point or vector of floating point type. Not all targets support
10745all types however.
10746
10747::
10748
10749 declare float @llvm.log2.f32(float %Val)
10750 declare double @llvm.log2.f64(double %Val)
10751 declare x86_fp80 @llvm.log2.f80(x86_fp80 %Val)
10752 declare fp128 @llvm.log2.f128(fp128 %Val)
10753 declare ppc_fp128 @llvm.log2.ppcf128(ppc_fp128 %Val)
10754
10755Overview:
10756"""""""""
10757
Andrew Kaylorcaf24d22017-04-11 21:52:40 +000010758The '``llvm.log2.*``' intrinsics compute the base-2 logarithm of the specified
10759value.
Sean Silvab084af42012-12-07 10:36:55 +000010760
10761Arguments:
10762""""""""""
10763
Andrew Kaylorcaf24d22017-04-11 21:52:40 +000010764The argument and return value are floating point numbers of the same type.
Sean Silvab084af42012-12-07 10:36:55 +000010765
10766Semantics:
10767""""""""""
10768
10769This function returns the same values as the libm ``log2`` functions
10770would, and handles error conditions in the same way.
10771
10772'``llvm.fma.*``' Intrinsic
10773^^^^^^^^^^^^^^^^^^^^^^^^^^
10774
10775Syntax:
10776"""""""
10777
10778This is an overloaded intrinsic. You can use ``llvm.fma`` on any
10779floating point or vector of floating point type. Not all targets support
10780all types however.
10781
10782::
10783
10784 declare float @llvm.fma.f32(float %a, float %b, float %c)
10785 declare double @llvm.fma.f64(double %a, double %b, double %c)
10786 declare x86_fp80 @llvm.fma.f80(x86_fp80 %a, x86_fp80 %b, x86_fp80 %c)
10787 declare fp128 @llvm.fma.f128(fp128 %a, fp128 %b, fp128 %c)
10788 declare ppc_fp128 @llvm.fma.ppcf128(ppc_fp128 %a, ppc_fp128 %b, ppc_fp128 %c)
10789
10790Overview:
10791"""""""""
10792
10793The '``llvm.fma.*``' intrinsics perform the fused multiply-add
10794operation.
10795
10796Arguments:
10797""""""""""
10798
10799The argument and return value are floating point numbers of the same
10800type.
10801
10802Semantics:
10803""""""""""
10804
10805This function returns the same values as the libm ``fma`` functions
Matt Arsenaultee364ee2014-01-31 00:09:00 +000010806would, and does not set errno.
Sean Silvab084af42012-12-07 10:36:55 +000010807
10808'``llvm.fabs.*``' Intrinsic
10809^^^^^^^^^^^^^^^^^^^^^^^^^^^
10810
10811Syntax:
10812"""""""
10813
10814This is an overloaded intrinsic. You can use ``llvm.fabs`` on any
10815floating point or vector of floating point type. Not all targets support
10816all types however.
10817
10818::
10819
10820 declare float @llvm.fabs.f32(float %Val)
10821 declare double @llvm.fabs.f64(double %Val)
Matt Arsenaultd6511b42014-10-21 23:00:20 +000010822 declare x86_fp80 @llvm.fabs.f80(x86_fp80 %Val)
Sean Silvab084af42012-12-07 10:36:55 +000010823 declare fp128 @llvm.fabs.f128(fp128 %Val)
Matt Arsenaultd6511b42014-10-21 23:00:20 +000010824 declare ppc_fp128 @llvm.fabs.ppcf128(ppc_fp128 %Val)
Sean Silvab084af42012-12-07 10:36:55 +000010825
10826Overview:
10827"""""""""
10828
10829The '``llvm.fabs.*``' intrinsics return the absolute value of the
10830operand.
10831
10832Arguments:
10833""""""""""
10834
10835The argument and return value are floating point numbers of the same
10836type.
10837
10838Semantics:
10839""""""""""
10840
10841This function returns the same values as the libm ``fabs`` functions
10842would, and handles error conditions in the same way.
10843
Matt Arsenaultd6511b42014-10-21 23:00:20 +000010844'``llvm.minnum.*``' Intrinsic
Matt Arsenault9886b0d2014-10-22 00:15:53 +000010845^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Matt Arsenaultd6511b42014-10-21 23:00:20 +000010846
10847Syntax:
10848"""""""
10849
10850This is an overloaded intrinsic. You can use ``llvm.minnum`` on any
10851floating point or vector of floating point type. Not all targets support
10852all types however.
10853
10854::
10855
Matt Arsenault64313c92014-10-22 18:25:02 +000010856 declare float @llvm.minnum.f32(float %Val0, float %Val1)
10857 declare double @llvm.minnum.f64(double %Val0, double %Val1)
10858 declare x86_fp80 @llvm.minnum.f80(x86_fp80 %Val0, x86_fp80 %Val1)
10859 declare fp128 @llvm.minnum.f128(fp128 %Val0, fp128 %Val1)
10860 declare ppc_fp128 @llvm.minnum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1)
Matt Arsenaultd6511b42014-10-21 23:00:20 +000010861
10862Overview:
10863"""""""""
10864
10865The '``llvm.minnum.*``' intrinsics return the minimum of the two
10866arguments.
10867
10868
10869Arguments:
10870""""""""""
10871
10872The arguments and return value are floating point numbers of the same
10873type.
10874
10875Semantics:
10876""""""""""
10877
10878Follows the IEEE-754 semantics for minNum, which also match for libm's
10879fmin.
10880
10881If either operand is a NaN, returns the other non-NaN operand. Returns
10882NaN only if both operands are NaN. If the operands compare equal,
10883returns a value that compares equal to both operands. This means that
10884fmin(+/-0.0, +/-0.0) could return either -0.0 or 0.0.
10885
10886'``llvm.maxnum.*``' Intrinsic
Matt Arsenault9886b0d2014-10-22 00:15:53 +000010887^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Matt Arsenaultd6511b42014-10-21 23:00:20 +000010888
10889Syntax:
10890"""""""
10891
10892This is an overloaded intrinsic. You can use ``llvm.maxnum`` on any
10893floating point or vector of floating point type. Not all targets support
10894all types however.
10895
10896::
10897
Matt Arsenault64313c92014-10-22 18:25:02 +000010898 declare float @llvm.maxnum.f32(float %Val0, float %Val1l)
10899 declare double @llvm.maxnum.f64(double %Val0, double %Val1)
10900 declare x86_fp80 @llvm.maxnum.f80(x86_fp80 %Val0, x86_fp80 %Val1)
10901 declare fp128 @llvm.maxnum.f128(fp128 %Val0, fp128 %Val1)
10902 declare ppc_fp128 @llvm.maxnum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1)
Matt Arsenaultd6511b42014-10-21 23:00:20 +000010903
10904Overview:
10905"""""""""
10906
10907The '``llvm.maxnum.*``' intrinsics return the maximum of the two
10908arguments.
10909
10910
10911Arguments:
10912""""""""""
10913
10914The arguments and return value are floating point numbers of the same
10915type.
10916
10917Semantics:
10918""""""""""
10919Follows the IEEE-754 semantics for maxNum, which also match for libm's
10920fmax.
10921
10922If either operand is a NaN, returns the other non-NaN operand. Returns
10923NaN only if both operands are NaN. If the operands compare equal,
10924returns a value that compares equal to both operands. This means that
10925fmax(+/-0.0, +/-0.0) could return either -0.0 or 0.0.
10926
Hal Finkel0c5c01aa2013-08-19 23:35:46 +000010927'``llvm.copysign.*``' Intrinsic
10928^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10929
10930Syntax:
10931"""""""
10932
10933This is an overloaded intrinsic. You can use ``llvm.copysign`` on any
10934floating point or vector of floating point type. Not all targets support
10935all types however.
10936
10937::
10938
10939 declare float @llvm.copysign.f32(float %Mag, float %Sgn)
10940 declare double @llvm.copysign.f64(double %Mag, double %Sgn)
10941 declare x86_fp80 @llvm.copysign.f80(x86_fp80 %Mag, x86_fp80 %Sgn)
10942 declare fp128 @llvm.copysign.f128(fp128 %Mag, fp128 %Sgn)
10943 declare ppc_fp128 @llvm.copysign.ppcf128(ppc_fp128 %Mag, ppc_fp128 %Sgn)
10944
10945Overview:
10946"""""""""
10947
10948The '``llvm.copysign.*``' intrinsics return a value with the magnitude of the
10949first operand and the sign of the second operand.
10950
10951Arguments:
10952""""""""""
10953
10954The arguments and return value are floating point numbers of the same
10955type.
10956
10957Semantics:
10958""""""""""
10959
10960This function returns the same values as the libm ``copysign``
10961functions would, and handles error conditions in the same way.
10962
Sean Silvab084af42012-12-07 10:36:55 +000010963'``llvm.floor.*``' Intrinsic
10964^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10965
10966Syntax:
10967"""""""
10968
10969This is an overloaded intrinsic. You can use ``llvm.floor`` on any
10970floating point or vector of floating point type. Not all targets support
10971all types however.
10972
10973::
10974
10975 declare float @llvm.floor.f32(float %Val)
10976 declare double @llvm.floor.f64(double %Val)
10977 declare x86_fp80 @llvm.floor.f80(x86_fp80 %Val)
10978 declare fp128 @llvm.floor.f128(fp128 %Val)
10979 declare ppc_fp128 @llvm.floor.ppcf128(ppc_fp128 %Val)
10980
10981Overview:
10982"""""""""
10983
10984The '``llvm.floor.*``' intrinsics return the floor of the operand.
10985
10986Arguments:
10987""""""""""
10988
10989The argument and return value are floating point numbers of the same
10990type.
10991
10992Semantics:
10993""""""""""
10994
10995This function returns the same values as the libm ``floor`` functions
10996would, and handles error conditions in the same way.
10997
10998'``llvm.ceil.*``' Intrinsic
10999^^^^^^^^^^^^^^^^^^^^^^^^^^^
11000
11001Syntax:
11002"""""""
11003
11004This is an overloaded intrinsic. You can use ``llvm.ceil`` on any
11005floating point or vector of floating point type. Not all targets support
11006all types however.
11007
11008::
11009
11010 declare float @llvm.ceil.f32(float %Val)
11011 declare double @llvm.ceil.f64(double %Val)
11012 declare x86_fp80 @llvm.ceil.f80(x86_fp80 %Val)
11013 declare fp128 @llvm.ceil.f128(fp128 %Val)
11014 declare ppc_fp128 @llvm.ceil.ppcf128(ppc_fp128 %Val)
11015
11016Overview:
11017"""""""""
11018
11019The '``llvm.ceil.*``' intrinsics return the ceiling of the operand.
11020
11021Arguments:
11022""""""""""
11023
11024The argument and return value are floating point numbers of the same
11025type.
11026
11027Semantics:
11028""""""""""
11029
11030This function returns the same values as the libm ``ceil`` functions
11031would, and handles error conditions in the same way.
11032
11033'``llvm.trunc.*``' Intrinsic
11034^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11035
11036Syntax:
11037"""""""
11038
11039This is an overloaded intrinsic. You can use ``llvm.trunc`` on any
11040floating point or vector of floating point type. Not all targets support
11041all types however.
11042
11043::
11044
11045 declare float @llvm.trunc.f32(float %Val)
11046 declare double @llvm.trunc.f64(double %Val)
11047 declare x86_fp80 @llvm.trunc.f80(x86_fp80 %Val)
11048 declare fp128 @llvm.trunc.f128(fp128 %Val)
11049 declare ppc_fp128 @llvm.trunc.ppcf128(ppc_fp128 %Val)
11050
11051Overview:
11052"""""""""
11053
11054The '``llvm.trunc.*``' intrinsics returns the operand rounded to the
11055nearest integer not larger in magnitude than the operand.
11056
11057Arguments:
11058""""""""""
11059
11060The argument and return value are floating point numbers of the same
11061type.
11062
11063Semantics:
11064""""""""""
11065
11066This function returns the same values as the libm ``trunc`` functions
11067would, and handles error conditions in the same way.
11068
11069'``llvm.rint.*``' Intrinsic
11070^^^^^^^^^^^^^^^^^^^^^^^^^^^
11071
11072Syntax:
11073"""""""
11074
11075This is an overloaded intrinsic. You can use ``llvm.rint`` on any
11076floating point or vector of floating point type. Not all targets support
11077all types however.
11078
11079::
11080
11081 declare float @llvm.rint.f32(float %Val)
11082 declare double @llvm.rint.f64(double %Val)
11083 declare x86_fp80 @llvm.rint.f80(x86_fp80 %Val)
11084 declare fp128 @llvm.rint.f128(fp128 %Val)
11085 declare ppc_fp128 @llvm.rint.ppcf128(ppc_fp128 %Val)
11086
11087Overview:
11088"""""""""
11089
11090The '``llvm.rint.*``' intrinsics returns the operand rounded to the
11091nearest integer. It may raise an inexact floating-point exception if the
11092operand isn't an integer.
11093
11094Arguments:
11095""""""""""
11096
11097The argument and return value are floating point numbers of the same
11098type.
11099
11100Semantics:
11101""""""""""
11102
11103This function returns the same values as the libm ``rint`` functions
11104would, and handles error conditions in the same way.
11105
11106'``llvm.nearbyint.*``' Intrinsic
11107^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11108
11109Syntax:
11110"""""""
11111
11112This is an overloaded intrinsic. You can use ``llvm.nearbyint`` on any
11113floating point or vector of floating point type. Not all targets support
11114all types however.
11115
11116::
11117
11118 declare float @llvm.nearbyint.f32(float %Val)
11119 declare double @llvm.nearbyint.f64(double %Val)
11120 declare x86_fp80 @llvm.nearbyint.f80(x86_fp80 %Val)
11121 declare fp128 @llvm.nearbyint.f128(fp128 %Val)
11122 declare ppc_fp128 @llvm.nearbyint.ppcf128(ppc_fp128 %Val)
11123
11124Overview:
11125"""""""""
11126
11127The '``llvm.nearbyint.*``' intrinsics returns the operand rounded to the
11128nearest integer.
11129
11130Arguments:
11131""""""""""
11132
11133The argument and return value are floating point numbers of the same
11134type.
11135
11136Semantics:
11137""""""""""
11138
11139This function returns the same values as the libm ``nearbyint``
11140functions would, and handles error conditions in the same way.
11141
Hal Finkel171817e2013-08-07 22:49:12 +000011142'``llvm.round.*``' Intrinsic
11143^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11144
11145Syntax:
11146"""""""
11147
11148This is an overloaded intrinsic. You can use ``llvm.round`` on any
11149floating point or vector of floating point type. Not all targets support
11150all types however.
11151
11152::
11153
11154 declare float @llvm.round.f32(float %Val)
11155 declare double @llvm.round.f64(double %Val)
11156 declare x86_fp80 @llvm.round.f80(x86_fp80 %Val)
11157 declare fp128 @llvm.round.f128(fp128 %Val)
11158 declare ppc_fp128 @llvm.round.ppcf128(ppc_fp128 %Val)
11159
11160Overview:
11161"""""""""
11162
11163The '``llvm.round.*``' intrinsics returns the operand rounded to the
11164nearest integer.
11165
11166Arguments:
11167""""""""""
11168
11169The argument and return value are floating point numbers of the same
11170type.
11171
11172Semantics:
11173""""""""""
11174
11175This function returns the same values as the libm ``round``
11176functions would, and handles error conditions in the same way.
11177
Sean Silvab084af42012-12-07 10:36:55 +000011178Bit Manipulation Intrinsics
11179---------------------------
11180
11181LLVM provides intrinsics for a few important bit manipulation
11182operations. These allow efficient code generation for some algorithms.
11183
James Molloy90111f72015-11-12 12:29:09 +000011184'``llvm.bitreverse.*``' Intrinsics
Akira Hatanaka7f5562b2015-11-13 21:09:57 +000011185^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
James Molloy90111f72015-11-12 12:29:09 +000011186
11187Syntax:
11188"""""""
11189
11190This is an overloaded intrinsic function. You can use bitreverse on any
11191integer type.
11192
11193::
11194
11195 declare i16 @llvm.bitreverse.i16(i16 <id>)
11196 declare i32 @llvm.bitreverse.i32(i32 <id>)
11197 declare i64 @llvm.bitreverse.i64(i64 <id>)
11198
11199Overview:
11200"""""""""
11201
11202The '``llvm.bitreverse``' family of intrinsics is used to reverse the
Matt Arsenaultde2d6a32016-03-07 21:54:52 +000011203bitpattern of an integer value; for example ``0b10110110`` becomes
11204``0b01101101``.
James Molloy90111f72015-11-12 12:29:09 +000011205
11206Semantics:
11207""""""""""
11208
Yichao Yu5abf14b2016-11-23 16:25:31 +000011209The ``llvm.bitreverse.iN`` intrinsic returns an iN value that has bit
James Molloy90111f72015-11-12 12:29:09 +000011210``M`` in the input moved to bit ``N-M`` in the output.
11211
Sean Silvab084af42012-12-07 10:36:55 +000011212'``llvm.bswap.*``' Intrinsics
11213^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11214
11215Syntax:
11216"""""""
11217
11218This is an overloaded intrinsic function. You can use bswap on any
11219integer type that is an even number of bytes (i.e. BitWidth % 16 == 0).
11220
11221::
11222
11223 declare i16 @llvm.bswap.i16(i16 <id>)
11224 declare i32 @llvm.bswap.i32(i32 <id>)
11225 declare i64 @llvm.bswap.i64(i64 <id>)
11226
11227Overview:
11228"""""""""
11229
11230The '``llvm.bswap``' family of intrinsics is used to byte swap integer
11231values with an even number of bytes (positive multiple of 16 bits).
11232These are useful for performing operations on data that is not in the
11233target's native byte order.
11234
11235Semantics:
11236""""""""""
11237
11238The ``llvm.bswap.i16`` intrinsic returns an i16 value that has the high
11239and low byte of the input i16 swapped. Similarly, the ``llvm.bswap.i32``
11240intrinsic returns an i32 value that has the four bytes of the input i32
11241swapped, so that if the input bytes are numbered 0, 1, 2, 3 then the
11242returned i32 will have its bytes in 3, 2, 1, 0 order. The
11243``llvm.bswap.i48``, ``llvm.bswap.i64`` and other intrinsics extend this
11244concept to additional even-byte lengths (6 bytes, 8 bytes and more,
11245respectively).
11246
11247'``llvm.ctpop.*``' Intrinsic
11248^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11249
11250Syntax:
11251"""""""
11252
11253This is an overloaded intrinsic. You can use llvm.ctpop on any integer
11254bit width, or on any vector with integer elements. Not all targets
11255support all bit widths or vector types, however.
11256
11257::
11258
11259 declare i8 @llvm.ctpop.i8(i8 <src>)
11260 declare i16 @llvm.ctpop.i16(i16 <src>)
11261 declare i32 @llvm.ctpop.i32(i32 <src>)
11262 declare i64 @llvm.ctpop.i64(i64 <src>)
11263 declare i256 @llvm.ctpop.i256(i256 <src>)
11264 declare <2 x i32> @llvm.ctpop.v2i32(<2 x i32> <src>)
11265
11266Overview:
11267"""""""""
11268
11269The '``llvm.ctpop``' family of intrinsics counts the number of bits set
11270in a value.
11271
11272Arguments:
11273""""""""""
11274
11275The only argument is the value to be counted. The argument may be of any
11276integer type, or a vector with integer elements. The return type must
11277match the argument type.
11278
11279Semantics:
11280""""""""""
11281
11282The '``llvm.ctpop``' intrinsic counts the 1's in a variable, or within
11283each element of a vector.
11284
11285'``llvm.ctlz.*``' Intrinsic
11286^^^^^^^^^^^^^^^^^^^^^^^^^^^
11287
11288Syntax:
11289"""""""
11290
11291This is an overloaded intrinsic. You can use ``llvm.ctlz`` on any
11292integer bit width, or any vector whose elements are integers. Not all
11293targets support all bit widths or vector types, however.
11294
11295::
11296
11297 declare i8 @llvm.ctlz.i8 (i8 <src>, i1 <is_zero_undef>)
11298 declare i16 @llvm.ctlz.i16 (i16 <src>, i1 <is_zero_undef>)
11299 declare i32 @llvm.ctlz.i32 (i32 <src>, i1 <is_zero_undef>)
11300 declare i64 @llvm.ctlz.i64 (i64 <src>, i1 <is_zero_undef>)
11301 declare i256 @llvm.ctlz.i256(i256 <src>, i1 <is_zero_undef>)
Alexey Samsonovc4b18302016-03-17 23:08:01 +000011302 declare <2 x i32> @llvm.ctlz.v2i32(<2 x i32> <src>, i1 <is_zero_undef>)
Sean Silvab084af42012-12-07 10:36:55 +000011303
11304Overview:
11305"""""""""
11306
11307The '``llvm.ctlz``' family of intrinsic functions counts the number of
11308leading zeros in a variable.
11309
11310Arguments:
11311""""""""""
11312
11313The first argument is the value to be counted. This argument may be of
Hal Finkel5dd82782015-01-05 04:05:21 +000011314any integer type, or a vector with integer element type. The return
Sean Silvab084af42012-12-07 10:36:55 +000011315type must match the first argument type.
11316
11317The second argument must be a constant and is a flag to indicate whether
11318the intrinsic should ensure that a zero as the first argument produces a
11319defined result. Historically some architectures did not provide a
11320defined result for zero values as efficiently, and many algorithms are
11321now predicated on avoiding zero-value inputs.
11322
11323Semantics:
11324""""""""""
11325
11326The '``llvm.ctlz``' intrinsic counts the leading (most significant)
11327zeros in a variable, or within each element of the vector. If
11328``src == 0`` then the result is the size in bits of the type of ``src``
11329if ``is_zero_undef == 0`` and ``undef`` otherwise. For example,
11330``llvm.ctlz(i32 2) = 30``.
11331
11332'``llvm.cttz.*``' Intrinsic
11333^^^^^^^^^^^^^^^^^^^^^^^^^^^
11334
11335Syntax:
11336"""""""
11337
11338This is an overloaded intrinsic. You can use ``llvm.cttz`` on any
11339integer bit width, or any vector of integer elements. Not all targets
11340support all bit widths or vector types, however.
11341
11342::
11343
11344 declare i8 @llvm.cttz.i8 (i8 <src>, i1 <is_zero_undef>)
11345 declare i16 @llvm.cttz.i16 (i16 <src>, i1 <is_zero_undef>)
11346 declare i32 @llvm.cttz.i32 (i32 <src>, i1 <is_zero_undef>)
11347 declare i64 @llvm.cttz.i64 (i64 <src>, i1 <is_zero_undef>)
11348 declare i256 @llvm.cttz.i256(i256 <src>, i1 <is_zero_undef>)
Alexey Samsonovc4b18302016-03-17 23:08:01 +000011349 declare <2 x i32> @llvm.cttz.v2i32(<2 x i32> <src>, i1 <is_zero_undef>)
Sean Silvab084af42012-12-07 10:36:55 +000011350
11351Overview:
11352"""""""""
11353
11354The '``llvm.cttz``' family of intrinsic functions counts the number of
11355trailing zeros.
11356
11357Arguments:
11358""""""""""
11359
11360The first argument is the value to be counted. This argument may be of
Hal Finkel5dd82782015-01-05 04:05:21 +000011361any integer type, or a vector with integer element type. The return
Sean Silvab084af42012-12-07 10:36:55 +000011362type must match the first argument type.
11363
11364The second argument must be a constant and is a flag to indicate whether
11365the intrinsic should ensure that a zero as the first argument produces a
11366defined result. Historically some architectures did not provide a
11367defined result for zero values as efficiently, and many algorithms are
11368now predicated on avoiding zero-value inputs.
11369
11370Semantics:
11371""""""""""
11372
11373The '``llvm.cttz``' intrinsic counts the trailing (least significant)
11374zeros in a variable, or within each element of a vector. If ``src == 0``
11375then the result is the size in bits of the type of ``src`` if
11376``is_zero_undef == 0`` and ``undef`` otherwise. For example,
11377``llvm.cttz(2) = 1``.
11378
Philip Reames34843ae2015-03-05 05:55:55 +000011379.. _int_overflow:
11380
Sean Silvab084af42012-12-07 10:36:55 +000011381Arithmetic with Overflow Intrinsics
11382-----------------------------------
11383
John Regehr6a493f22016-05-12 20:55:09 +000011384LLVM provides intrinsics for fast arithmetic overflow checking.
11385
11386Each of these intrinsics returns a two-element struct. The first
11387element of this struct contains the result of the corresponding
11388arithmetic operation modulo 2\ :sup:`n`\ , where n is the bit width of
11389the result. Therefore, for example, the first element of the struct
11390returned by ``llvm.sadd.with.overflow.i32`` is always the same as the
11391result of a 32-bit ``add`` instruction with the same operands, where
11392the ``add`` is *not* modified by an ``nsw`` or ``nuw`` flag.
11393
11394The second element of the result is an ``i1`` that is 1 if the
11395arithmetic operation overflowed and 0 otherwise. An operation
11396overflows if, for any values of its operands ``A`` and ``B`` and for
11397any ``N`` larger than the operands' width, ``ext(A op B) to iN`` is
11398not equal to ``(ext(A) to iN) op (ext(B) to iN)`` where ``ext`` is
11399``sext`` for signed overflow and ``zext`` for unsigned overflow, and
11400``op`` is the underlying arithmetic operation.
11401
11402The behavior of these intrinsics is well-defined for all argument
11403values.
Sean Silvab084af42012-12-07 10:36:55 +000011404
11405'``llvm.sadd.with.overflow.*``' Intrinsics
11406^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11407
11408Syntax:
11409"""""""
11410
11411This is an overloaded intrinsic. You can use ``llvm.sadd.with.overflow``
11412on any integer bit width.
11413
11414::
11415
11416 declare {i16, i1} @llvm.sadd.with.overflow.i16(i16 %a, i16 %b)
11417 declare {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b)
11418 declare {i64, i1} @llvm.sadd.with.overflow.i64(i64 %a, i64 %b)
11419
11420Overview:
11421"""""""""
11422
11423The '``llvm.sadd.with.overflow``' family of intrinsic functions perform
11424a signed addition of the two arguments, and indicate whether an overflow
11425occurred during the signed summation.
11426
11427Arguments:
11428""""""""""
11429
11430The arguments (%a and %b) and the first element of the result structure
11431may be of integer types of any bit width, but they must have the same
11432bit width. The second element of the result structure must be of type
11433``i1``. ``%a`` and ``%b`` are the two values that will undergo signed
11434addition.
11435
11436Semantics:
11437""""""""""
11438
11439The '``llvm.sadd.with.overflow``' family of intrinsic functions perform
Dmitri Gribenkoe8131122013-01-19 20:34:20 +000011440a signed addition of the two variables. They return a structure --- the
Sean Silvab084af42012-12-07 10:36:55 +000011441first element of which is the signed summation, and the second element
11442of which is a bit specifying if the signed summation resulted in an
11443overflow.
11444
11445Examples:
11446"""""""""
11447
11448.. code-block:: llvm
11449
11450 %res = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b)
11451 %sum = extractvalue {i32, i1} %res, 0
11452 %obit = extractvalue {i32, i1} %res, 1
11453 br i1 %obit, label %overflow, label %normal
11454
11455'``llvm.uadd.with.overflow.*``' Intrinsics
11456^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11457
11458Syntax:
11459"""""""
11460
11461This is an overloaded intrinsic. You can use ``llvm.uadd.with.overflow``
11462on any integer bit width.
11463
11464::
11465
11466 declare {i16, i1} @llvm.uadd.with.overflow.i16(i16 %a, i16 %b)
11467 declare {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b)
11468 declare {i64, i1} @llvm.uadd.with.overflow.i64(i64 %a, i64 %b)
11469
11470Overview:
11471"""""""""
11472
11473The '``llvm.uadd.with.overflow``' family of intrinsic functions perform
11474an unsigned addition of the two arguments, and indicate whether a carry
11475occurred during the unsigned summation.
11476
11477Arguments:
11478""""""""""
11479
11480The arguments (%a and %b) and the first element of the result structure
11481may be of integer types of any bit width, but they must have the same
11482bit width. The second element of the result structure must be of type
11483``i1``. ``%a`` and ``%b`` are the two values that will undergo unsigned
11484addition.
11485
11486Semantics:
11487""""""""""
11488
11489The '``llvm.uadd.with.overflow``' family of intrinsic functions perform
Dmitri Gribenkoe8131122013-01-19 20:34:20 +000011490an unsigned addition of the two arguments. They return a structure --- the
Sean Silvab084af42012-12-07 10:36:55 +000011491first element of which is the sum, and the second element of which is a
11492bit specifying if the unsigned summation resulted in a carry.
11493
11494Examples:
11495"""""""""
11496
11497.. code-block:: llvm
11498
11499 %res = call {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b)
11500 %sum = extractvalue {i32, i1} %res, 0
11501 %obit = extractvalue {i32, i1} %res, 1
11502 br i1 %obit, label %carry, label %normal
11503
11504'``llvm.ssub.with.overflow.*``' Intrinsics
11505^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11506
11507Syntax:
11508"""""""
11509
11510This is an overloaded intrinsic. You can use ``llvm.ssub.with.overflow``
11511on any integer bit width.
11512
11513::
11514
11515 declare {i16, i1} @llvm.ssub.with.overflow.i16(i16 %a, i16 %b)
11516 declare {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a, i32 %b)
11517 declare {i64, i1} @llvm.ssub.with.overflow.i64(i64 %a, i64 %b)
11518
11519Overview:
11520"""""""""
11521
11522The '``llvm.ssub.with.overflow``' family of intrinsic functions perform
11523a signed subtraction of the two arguments, and indicate whether an
11524overflow occurred during the signed subtraction.
11525
11526Arguments:
11527""""""""""
11528
11529The arguments (%a and %b) and the first element of the result structure
11530may be of integer types of any bit width, but they must have the same
11531bit width. The second element of the result structure must be of type
11532``i1``. ``%a`` and ``%b`` are the two values that will undergo signed
11533subtraction.
11534
11535Semantics:
11536""""""""""
11537
11538The '``llvm.ssub.with.overflow``' family of intrinsic functions perform
Dmitri Gribenkoe8131122013-01-19 20:34:20 +000011539a signed subtraction of the two arguments. They return a structure --- the
Sean Silvab084af42012-12-07 10:36:55 +000011540first element of which is the subtraction, and the second element of
11541which is a bit specifying if the signed subtraction resulted in an
11542overflow.
11543
11544Examples:
11545"""""""""
11546
11547.. code-block:: llvm
11548
11549 %res = call {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a, i32 %b)
11550 %sum = extractvalue {i32, i1} %res, 0
11551 %obit = extractvalue {i32, i1} %res, 1
11552 br i1 %obit, label %overflow, label %normal
11553
11554'``llvm.usub.with.overflow.*``' Intrinsics
11555^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11556
11557Syntax:
11558"""""""
11559
11560This is an overloaded intrinsic. You can use ``llvm.usub.with.overflow``
11561on any integer bit width.
11562
11563::
11564
11565 declare {i16, i1} @llvm.usub.with.overflow.i16(i16 %a, i16 %b)
11566 declare {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b)
11567 declare {i64, i1} @llvm.usub.with.overflow.i64(i64 %a, i64 %b)
11568
11569Overview:
11570"""""""""
11571
11572The '``llvm.usub.with.overflow``' family of intrinsic functions perform
11573an unsigned subtraction of the two arguments, and indicate whether an
11574overflow occurred during the unsigned subtraction.
11575
11576Arguments:
11577""""""""""
11578
11579The arguments (%a and %b) and the first element of the result structure
11580may be of integer types of any bit width, but they must have the same
11581bit width. The second element of the result structure must be of type
11582``i1``. ``%a`` and ``%b`` are the two values that will undergo unsigned
11583subtraction.
11584
11585Semantics:
11586""""""""""
11587
11588The '``llvm.usub.with.overflow``' family of intrinsic functions perform
Dmitri Gribenkoe8131122013-01-19 20:34:20 +000011589an unsigned subtraction of the two arguments. They return a structure ---
Sean Silvab084af42012-12-07 10:36:55 +000011590the first element of which is the subtraction, and the second element of
11591which is a bit specifying if the unsigned subtraction resulted in an
11592overflow.
11593
11594Examples:
11595"""""""""
11596
11597.. code-block:: llvm
11598
11599 %res = call {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b)
11600 %sum = extractvalue {i32, i1} %res, 0
11601 %obit = extractvalue {i32, i1} %res, 1
11602 br i1 %obit, label %overflow, label %normal
11603
11604'``llvm.smul.with.overflow.*``' Intrinsics
11605^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11606
11607Syntax:
11608"""""""
11609
11610This is an overloaded intrinsic. You can use ``llvm.smul.with.overflow``
11611on any integer bit width.
11612
11613::
11614
11615 declare {i16, i1} @llvm.smul.with.overflow.i16(i16 %a, i16 %b)
11616 declare {i32, i1} @llvm.smul.with.overflow.i32(i32 %a, i32 %b)
11617 declare {i64, i1} @llvm.smul.with.overflow.i64(i64 %a, i64 %b)
11618
11619Overview:
11620"""""""""
11621
11622The '``llvm.smul.with.overflow``' family of intrinsic functions perform
11623a signed multiplication of the two arguments, and indicate whether an
11624overflow occurred during the signed multiplication.
11625
11626Arguments:
11627""""""""""
11628
11629The arguments (%a and %b) and the first element of the result structure
11630may be of integer types of any bit width, but they must have the same
11631bit width. The second element of the result structure must be of type
11632``i1``. ``%a`` and ``%b`` are the two values that will undergo signed
11633multiplication.
11634
11635Semantics:
11636""""""""""
11637
11638The '``llvm.smul.with.overflow``' family of intrinsic functions perform
Dmitri Gribenkoe8131122013-01-19 20:34:20 +000011639a signed multiplication of the two arguments. They return a structure ---
Sean Silvab084af42012-12-07 10:36:55 +000011640the first element of which is the multiplication, and the second element
11641of which is a bit specifying if the signed multiplication resulted in an
11642overflow.
11643
11644Examples:
11645"""""""""
11646
11647.. code-block:: llvm
11648
11649 %res = call {i32, i1} @llvm.smul.with.overflow.i32(i32 %a, i32 %b)
11650 %sum = extractvalue {i32, i1} %res, 0
11651 %obit = extractvalue {i32, i1} %res, 1
11652 br i1 %obit, label %overflow, label %normal
11653
11654'``llvm.umul.with.overflow.*``' Intrinsics
11655^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11656
11657Syntax:
11658"""""""
11659
11660This is an overloaded intrinsic. You can use ``llvm.umul.with.overflow``
11661on any integer bit width.
11662
11663::
11664
11665 declare {i16, i1} @llvm.umul.with.overflow.i16(i16 %a, i16 %b)
11666 declare {i32, i1} @llvm.umul.with.overflow.i32(i32 %a, i32 %b)
11667 declare {i64, i1} @llvm.umul.with.overflow.i64(i64 %a, i64 %b)
11668
11669Overview:
11670"""""""""
11671
11672The '``llvm.umul.with.overflow``' family of intrinsic functions perform
11673a unsigned multiplication of the two arguments, and indicate whether an
11674overflow occurred during the unsigned multiplication.
11675
11676Arguments:
11677""""""""""
11678
11679The arguments (%a and %b) and the first element of the result structure
11680may be of integer types of any bit width, but they must have the same
11681bit width. The second element of the result structure must be of type
11682``i1``. ``%a`` and ``%b`` are the two values that will undergo unsigned
11683multiplication.
11684
11685Semantics:
11686""""""""""
11687
11688The '``llvm.umul.with.overflow``' family of intrinsic functions perform
Dmitri Gribenkoe8131122013-01-19 20:34:20 +000011689an unsigned multiplication of the two arguments. They return a structure ---
11690the first element of which is the multiplication, and the second
Sean Silvab084af42012-12-07 10:36:55 +000011691element of which is a bit specifying if the unsigned multiplication
11692resulted in an overflow.
11693
11694Examples:
11695"""""""""
11696
11697.. code-block:: llvm
11698
11699 %res = call {i32, i1} @llvm.umul.with.overflow.i32(i32 %a, i32 %b)
11700 %sum = extractvalue {i32, i1} %res, 0
11701 %obit = extractvalue {i32, i1} %res, 1
11702 br i1 %obit, label %overflow, label %normal
11703
11704Specialised Arithmetic Intrinsics
11705---------------------------------
11706
Owen Anderson1056a922015-07-11 07:01:27 +000011707'``llvm.canonicalize.*``' Intrinsic
11708^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11709
11710Syntax:
11711"""""""
11712
11713::
11714
11715 declare float @llvm.canonicalize.f32(float %a)
11716 declare double @llvm.canonicalize.f64(double %b)
11717
11718Overview:
11719"""""""""
11720
11721The '``llvm.canonicalize.*``' intrinsic returns the platform specific canonical
Sean Silvaa1190322015-08-06 22:56:48 +000011722encoding of a floating point number. This canonicalization is useful for
Owen Anderson1056a922015-07-11 07:01:27 +000011723implementing certain numeric primitives such as frexp. The canonical encoding is
11724defined by IEEE-754-2008 to be:
11725
11726::
11727
11728 2.1.8 canonical encoding: The preferred encoding of a floating-point
Sean Silvaa1190322015-08-06 22:56:48 +000011729 representation in a format. Applied to declets, significands of finite
Owen Anderson1056a922015-07-11 07:01:27 +000011730 numbers, infinities, and NaNs, especially in decimal formats.
11731
11732This operation can also be considered equivalent to the IEEE-754-2008
Sean Silvaa1190322015-08-06 22:56:48 +000011733conversion of a floating-point value to the same format. NaNs are handled
Owen Anderson1056a922015-07-11 07:01:27 +000011734according to section 6.2.
11735
11736Examples of non-canonical encodings:
11737
Sean Silvaa1190322015-08-06 22:56:48 +000011738- x87 pseudo denormals, pseudo NaNs, pseudo Infinity, Unnormals. These are
Owen Anderson1056a922015-07-11 07:01:27 +000011739 converted to a canonical representation per hardware-specific protocol.
11740- Many normal decimal floating point numbers have non-canonical alternative
11741 encodings.
11742- Some machines, like GPUs or ARMv7 NEON, do not support subnormal values.
Sanjay Patelcc330962016-02-24 23:44:19 +000011743 These are treated as non-canonical encodings of zero and will be flushed to
Owen Anderson1056a922015-07-11 07:01:27 +000011744 a zero of the same sign by this operation.
11745
11746Note that per IEEE-754-2008 6.2, systems that support signaling NaNs with
11747default exception handling must signal an invalid exception, and produce a
11748quiet NaN result.
11749
11750This function should always be implementable as multiplication by 1.0, provided
Sean Silvaa1190322015-08-06 22:56:48 +000011751that the compiler does not constant fold the operation. Likewise, division by
117521.0 and ``llvm.minnum(x, x)`` are possible implementations. Addition with
Owen Anderson1056a922015-07-11 07:01:27 +000011753-0.0 is also sufficient provided that the rounding mode is not -Infinity.
11754
Sean Silvaa1190322015-08-06 22:56:48 +000011755``@llvm.canonicalize`` must preserve the equality relation. That is:
Owen Anderson1056a922015-07-11 07:01:27 +000011756
11757- ``(@llvm.canonicalize(x) == x)`` is equivalent to ``(x == x)``
11758- ``(@llvm.canonicalize(x) == @llvm.canonicalize(y))`` is equivalent to
11759 to ``(x == y)``
11760
11761Additionally, the sign of zero must be conserved:
11762``@llvm.canonicalize(-0.0) = -0.0`` and ``@llvm.canonicalize(+0.0) = +0.0``
11763
11764The payload bits of a NaN must be conserved, with two exceptions.
11765First, environments which use only a single canonical representation of NaN
Sean Silvaa1190322015-08-06 22:56:48 +000011766must perform said canonicalization. Second, SNaNs must be quieted per the
Owen Anderson1056a922015-07-11 07:01:27 +000011767usual methods.
11768
11769The canonicalization operation may be optimized away if:
11770
Sean Silvaa1190322015-08-06 22:56:48 +000011771- The input is known to be canonical. For example, it was produced by a
Owen Anderson1056a922015-07-11 07:01:27 +000011772 floating-point operation that is required by the standard to be canonical.
11773- The result is consumed only by (or fused with) other floating-point
Sean Silvaa1190322015-08-06 22:56:48 +000011774 operations. That is, the bits of the floating point value are not examined.
Owen Anderson1056a922015-07-11 07:01:27 +000011775
Sean Silvab084af42012-12-07 10:36:55 +000011776'``llvm.fmuladd.*``' Intrinsic
11777^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11778
11779Syntax:
11780"""""""
11781
11782::
11783
11784 declare float @llvm.fmuladd.f32(float %a, float %b, float %c)
11785 declare double @llvm.fmuladd.f64(double %a, double %b, double %c)
11786
11787Overview:
11788"""""""""
11789
11790The '``llvm.fmuladd.*``' intrinsic functions represent multiply-add
Lang Hames045f4392013-01-17 00:00:49 +000011791expressions that can be fused if the code generator determines that (a) the
11792target instruction set has support for a fused operation, and (b) that the
11793fused operation is more efficient than the equivalent, separate pair of mul
11794and add instructions.
Sean Silvab084af42012-12-07 10:36:55 +000011795
11796Arguments:
11797""""""""""
11798
11799The '``llvm.fmuladd.*``' intrinsics each take three arguments: two
11800multiplicands, a and b, and an addend c.
11801
11802Semantics:
11803""""""""""
11804
11805The expression:
11806
11807::
11808
11809 %0 = call float @llvm.fmuladd.f32(%a, %b, %c)
11810
11811is equivalent to the expression a \* b + c, except that rounding will
11812not be performed between the multiplication and addition steps if the
11813code generator fuses the operations. Fusion is not guaranteed, even if
11814the target platform supports it. If a fused multiply-add is required the
Matt Arsenaultee364ee2014-01-31 00:09:00 +000011815corresponding llvm.fma.\* intrinsic function should be used
11816instead. This never sets errno, just as '``llvm.fma.*``'.
Sean Silvab084af42012-12-07 10:36:55 +000011817
11818Examples:
11819"""""""""
11820
11821.. code-block:: llvm
11822
Tim Northover675a0962014-06-13 14:24:23 +000011823 %r2 = call float @llvm.fmuladd.f32(float %a, float %b, float %c) ; yields float:r2 = (a * b) + c
Sean Silvab084af42012-12-07 10:36:55 +000011824
Amara Emersoncf9daa32017-05-09 10:43:25 +000011825
11826Experimental Vector Reduction Intrinsics
11827----------------------------------------
11828
11829Horizontal reductions of vectors can be expressed using the following
11830intrinsics. Each one takes a vector operand as an input and applies its
11831respective operation across all elements of the vector, returning a single
11832scalar result of the same element type.
11833
11834
11835'``llvm.experimental.vector.reduce.add.*``' Intrinsic
11836^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11837
11838Syntax:
11839"""""""
11840
11841::
11842
11843 declare i32 @llvm.experimental.vector.reduce.add.i32.v4i32(<4 x i32> %a)
11844 declare i64 @llvm.experimental.vector.reduce.add.i64.v2i64(<2 x i64> %a)
11845
11846Overview:
11847"""""""""
11848
11849The '``llvm.experimental.vector.reduce.add.*``' intrinsics do an integer ``ADD``
11850reduction of a vector, returning the result as a scalar. The return type matches
11851the element-type of the vector input.
11852
11853Arguments:
11854""""""""""
11855The argument to this intrinsic must be a vector of integer values.
11856
11857'``llvm.experimental.vector.reduce.fadd.*``' Intrinsic
11858^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11859
11860Syntax:
11861"""""""
11862
11863::
11864
11865 declare float @llvm.experimental.vector.reduce.fadd.f32.v4f32(float %acc, <4 x float> %a)
11866 declare double @llvm.experimental.vector.reduce.fadd.f64.v2f64(double %acc, <2 x double> %a)
11867
11868Overview:
11869"""""""""
11870
11871The '``llvm.experimental.vector.reduce.fadd.*``' intrinsics do a floating point
11872``ADD`` reduction of a vector, returning the result as a scalar. The return type
11873matches the element-type of the vector input.
11874
11875If the intrinsic call has fast-math flags, then the reduction will not preserve
11876the associativity of an equivalent scalarized counterpart. If it does not have
11877fast-math flags, then the reduction will be *ordered*, implying that the
11878operation respects the associativity of a scalarized reduction.
11879
11880
11881Arguments:
11882""""""""""
11883The first argument to this intrinsic is a scalar accumulator value, which is
11884only used when there are no fast-math flags attached. This argument may be undef
11885when fast-math flags are used.
11886
11887The second argument must be a vector of floating point values.
11888
11889Examples:
11890"""""""""
11891
11892.. code-block:: llvm
11893
11894 %fast = call fast float @llvm.experimental.vector.reduce.fadd.f32.v4f32(float undef, <4 x float> %input) ; fast reduction
11895 %ord = call float @llvm.experimental.vector.reduce.fadd.f32.v4f32(float %acc, <4 x float> %input) ; ordered reduction
11896
11897
11898'``llvm.experimental.vector.reduce.mul.*``' Intrinsic
11899^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11900
11901Syntax:
11902"""""""
11903
11904::
11905
11906 declare i32 @llvm.experimental.vector.reduce.mul.i32.v4i32(<4 x i32> %a)
11907 declare i64 @llvm.experimental.vector.reduce.mul.i64.v2i64(<2 x i64> %a)
11908
11909Overview:
11910"""""""""
11911
11912The '``llvm.experimental.vector.reduce.mul.*``' intrinsics do an integer ``MUL``
11913reduction of a vector, returning the result as a scalar. The return type matches
11914the element-type of the vector input.
11915
11916Arguments:
11917""""""""""
11918The argument to this intrinsic must be a vector of integer values.
11919
11920'``llvm.experimental.vector.reduce.fmul.*``' Intrinsic
11921^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11922
11923Syntax:
11924"""""""
11925
11926::
11927
11928 declare float @llvm.experimental.vector.reduce.fmul.f32.v4f32(float %acc, <4 x float> %a)
11929 declare double @llvm.experimental.vector.reduce.fmul.f64.v2f64(double %acc, <2 x double> %a)
11930
11931Overview:
11932"""""""""
11933
11934The '``llvm.experimental.vector.reduce.fmul.*``' intrinsics do a floating point
11935``MUL`` reduction of a vector, returning the result as a scalar. The return type
11936matches the element-type of the vector input.
11937
11938If the intrinsic call has fast-math flags, then the reduction will not preserve
11939the associativity of an equivalent scalarized counterpart. If it does not have
11940fast-math flags, then the reduction will be *ordered*, implying that the
11941operation respects the associativity of a scalarized reduction.
11942
11943
11944Arguments:
11945""""""""""
11946The first argument to this intrinsic is a scalar accumulator value, which is
11947only used when there are no fast-math flags attached. This argument may be undef
11948when fast-math flags are used.
11949
11950The second argument must be a vector of floating point values.
11951
11952Examples:
11953"""""""""
11954
11955.. code-block:: llvm
11956
11957 %fast = call fast float @llvm.experimental.vector.reduce.fmul.f32.v4f32(float undef, <4 x float> %input) ; fast reduction
11958 %ord = call float @llvm.experimental.vector.reduce.fmul.f32.v4f32(float %acc, <4 x float> %input) ; ordered reduction
11959
11960'``llvm.experimental.vector.reduce.and.*``' Intrinsic
11961^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11962
11963Syntax:
11964"""""""
11965
11966::
11967
11968 declare i32 @llvm.experimental.vector.reduce.and.i32.v4i32(<4 x i32> %a)
11969
11970Overview:
11971"""""""""
11972
11973The '``llvm.experimental.vector.reduce.and.*``' intrinsics do a bitwise ``AND``
11974reduction of a vector, returning the result as a scalar. The return type matches
11975the element-type of the vector input.
11976
11977Arguments:
11978""""""""""
11979The argument to this intrinsic must be a vector of integer values.
11980
11981'``llvm.experimental.vector.reduce.or.*``' Intrinsic
11982^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11983
11984Syntax:
11985"""""""
11986
11987::
11988
11989 declare i32 @llvm.experimental.vector.reduce.or.i32.v4i32(<4 x i32> %a)
11990
11991Overview:
11992"""""""""
11993
11994The '``llvm.experimental.vector.reduce.or.*``' intrinsics do a bitwise ``OR`` reduction
11995of a vector, returning the result as a scalar. The return type matches the
11996element-type of the vector input.
11997
11998Arguments:
11999""""""""""
12000The argument to this intrinsic must be a vector of integer values.
12001
12002'``llvm.experimental.vector.reduce.xor.*``' Intrinsic
12003^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12004
12005Syntax:
12006"""""""
12007
12008::
12009
12010 declare i32 @llvm.experimental.vector.reduce.xor.i32.v4i32(<4 x i32> %a)
12011
12012Overview:
12013"""""""""
12014
12015The '``llvm.experimental.vector.reduce.xor.*``' intrinsics do a bitwise ``XOR``
12016reduction of a vector, returning the result as a scalar. The return type matches
12017the element-type of the vector input.
12018
12019Arguments:
12020""""""""""
12021The argument to this intrinsic must be a vector of integer values.
12022
12023'``llvm.experimental.vector.reduce.smax.*``' Intrinsic
12024^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12025
12026Syntax:
12027"""""""
12028
12029::
12030
12031 declare i32 @llvm.experimental.vector.reduce.smax.i32.v4i32(<4 x i32> %a)
12032
12033Overview:
12034"""""""""
12035
12036The '``llvm.experimental.vector.reduce.smax.*``' intrinsics do a signed integer
12037``MAX`` reduction of a vector, returning the result as a scalar. The return type
12038matches the element-type of the vector input.
12039
12040Arguments:
12041""""""""""
12042The argument to this intrinsic must be a vector of integer values.
12043
12044'``llvm.experimental.vector.reduce.smin.*``' Intrinsic
12045^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12046
12047Syntax:
12048"""""""
12049
12050::
12051
12052 declare i32 @llvm.experimental.vector.reduce.smin.i32.v4i32(<4 x i32> %a)
12053
12054Overview:
12055"""""""""
12056
12057The '``llvm.experimental.vector.reduce.smin.*``' intrinsics do a signed integer
12058``MIN`` reduction of a vector, returning the result as a scalar. The return type
12059matches the element-type of the vector input.
12060
12061Arguments:
12062""""""""""
12063The argument to this intrinsic must be a vector of integer values.
12064
12065'``llvm.experimental.vector.reduce.umax.*``' Intrinsic
12066^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12067
12068Syntax:
12069"""""""
12070
12071::
12072
12073 declare i32 @llvm.experimental.vector.reduce.umax.i32.v4i32(<4 x i32> %a)
12074
12075Overview:
12076"""""""""
12077
12078The '``llvm.experimental.vector.reduce.umax.*``' intrinsics do an unsigned
12079integer ``MAX`` reduction of a vector, returning the result as a scalar. The
12080return type matches the element-type of the vector input.
12081
12082Arguments:
12083""""""""""
12084The argument to this intrinsic must be a vector of integer values.
12085
12086'``llvm.experimental.vector.reduce.umin.*``' Intrinsic
12087^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12088
12089Syntax:
12090"""""""
12091
12092::
12093
12094 declare i32 @llvm.experimental.vector.reduce.umin.i32.v4i32(<4 x i32> %a)
12095
12096Overview:
12097"""""""""
12098
12099The '``llvm.experimental.vector.reduce.umin.*``' intrinsics do an unsigned
12100integer ``MIN`` reduction of a vector, returning the result as a scalar. The
12101return type matches the element-type of the vector input.
12102
12103Arguments:
12104""""""""""
12105The argument to this intrinsic must be a vector of integer values.
12106
12107'``llvm.experimental.vector.reduce.fmax.*``' Intrinsic
12108^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12109
12110Syntax:
12111"""""""
12112
12113::
12114
12115 declare float @llvm.experimental.vector.reduce.fmax.f32.v4f32(<4 x float> %a)
12116 declare double @llvm.experimental.vector.reduce.fmax.f64.v2f64(<2 x double> %a)
12117
12118Overview:
12119"""""""""
12120
12121The '``llvm.experimental.vector.reduce.fmax.*``' intrinsics do a floating point
12122``MAX`` reduction of a vector, returning the result as a scalar. The return type
12123matches the element-type of the vector input.
12124
12125If the intrinsic call has the ``nnan`` fast-math flag then the operation can
12126assume that NaNs are not present in the input vector.
12127
12128Arguments:
12129""""""""""
12130The argument to this intrinsic must be a vector of floating point values.
12131
12132'``llvm.experimental.vector.reduce.fmin.*``' Intrinsic
12133^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12134
12135Syntax:
12136"""""""
12137
12138::
12139
12140 declare float @llvm.experimental.vector.reduce.fmin.f32.v4f32(<4 x float> %a)
12141 declare double @llvm.experimental.vector.reduce.fmin.f64.v2f64(<2 x double> %a)
12142
12143Overview:
12144"""""""""
12145
12146The '``llvm.experimental.vector.reduce.fmin.*``' intrinsics do a floating point
12147``MIN`` reduction of a vector, returning the result as a scalar. The return type
12148matches the element-type of the vector input.
12149
12150If the intrinsic call has the ``nnan`` fast-math flag then the operation can
12151assume that NaNs are not present in the input vector.
12152
12153Arguments:
12154""""""""""
12155The argument to this intrinsic must be a vector of floating point values.
12156
Sean Silvab084af42012-12-07 10:36:55 +000012157Half Precision Floating Point Intrinsics
12158----------------------------------------
12159
12160For most target platforms, half precision floating point is a
12161storage-only format. This means that it is a dense encoding (in memory)
12162but does not support computation in the format.
12163
12164This means that code must first load the half-precision floating point
12165value as an i16, then convert it to float with
12166:ref:`llvm.convert.from.fp16 <int_convert_from_fp16>`. Computation can
12167then be performed on the float value (including extending to double
12168etc). To store the value back to memory, it is first converted to float
12169if needed, then converted to i16 with
12170:ref:`llvm.convert.to.fp16 <int_convert_to_fp16>`, then storing as an
12171i16 value.
12172
12173.. _int_convert_to_fp16:
12174
12175'``llvm.convert.to.fp16``' Intrinsic
12176^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12177
12178Syntax:
12179"""""""
12180
12181::
12182
Tim Northoverfd7e4242014-07-17 10:51:23 +000012183 declare i16 @llvm.convert.to.fp16.f32(float %a)
12184 declare i16 @llvm.convert.to.fp16.f64(double %a)
Sean Silvab084af42012-12-07 10:36:55 +000012185
12186Overview:
12187"""""""""
12188
Tim Northoverfd7e4242014-07-17 10:51:23 +000012189The '``llvm.convert.to.fp16``' intrinsic function performs a conversion from a
12190conventional floating point type to half precision floating point format.
Sean Silvab084af42012-12-07 10:36:55 +000012191
12192Arguments:
12193""""""""""
12194
12195The intrinsic function contains single argument - the value to be
12196converted.
12197
12198Semantics:
12199""""""""""
12200
Tim Northoverfd7e4242014-07-17 10:51:23 +000012201The '``llvm.convert.to.fp16``' intrinsic function performs a conversion from a
12202conventional floating point format to half precision floating point format. The
12203return value is an ``i16`` which contains the converted number.
Sean Silvab084af42012-12-07 10:36:55 +000012204
12205Examples:
12206"""""""""
12207
12208.. code-block:: llvm
12209
Tim Northoverfd7e4242014-07-17 10:51:23 +000012210 %res = call i16 @llvm.convert.to.fp16.f32(float %a)
Sean Silvab084af42012-12-07 10:36:55 +000012211 store i16 %res, i16* @x, align 2
12212
12213.. _int_convert_from_fp16:
12214
12215'``llvm.convert.from.fp16``' Intrinsic
12216^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12217
12218Syntax:
12219"""""""
12220
12221::
12222
Tim Northoverfd7e4242014-07-17 10:51:23 +000012223 declare float @llvm.convert.from.fp16.f32(i16 %a)
12224 declare double @llvm.convert.from.fp16.f64(i16 %a)
Sean Silvab084af42012-12-07 10:36:55 +000012225
12226Overview:
12227"""""""""
12228
12229The '``llvm.convert.from.fp16``' intrinsic function performs a
12230conversion from half precision floating point format to single precision
12231floating point format.
12232
12233Arguments:
12234""""""""""
12235
12236The intrinsic function contains single argument - the value to be
12237converted.
12238
12239Semantics:
12240""""""""""
12241
12242The '``llvm.convert.from.fp16``' intrinsic function performs a
12243conversion from half single precision floating point format to single
12244precision floating point format. The input half-float value is
12245represented by an ``i16`` value.
12246
12247Examples:
12248"""""""""
12249
12250.. code-block:: llvm
12251
David Blaikiec7aabbb2015-03-04 22:06:14 +000012252 %a = load i16, i16* @x, align 2
Matt Arsenault3e3ddda2014-07-10 03:22:16 +000012253 %res = call float @llvm.convert.from.fp16(i16 %a)
Sean Silvab084af42012-12-07 10:36:55 +000012254
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +000012255.. _dbg_intrinsics:
12256
Sean Silvab084af42012-12-07 10:36:55 +000012257Debugger Intrinsics
12258-------------------
12259
12260The LLVM debugger intrinsics (which all start with ``llvm.dbg.``
12261prefix), are described in the `LLVM Source Level
12262Debugging <SourceLevelDebugging.html#format_common_intrinsics>`_
12263document.
12264
12265Exception Handling Intrinsics
12266-----------------------------
12267
12268The LLVM exception handling intrinsics (which all start with
12269``llvm.eh.`` prefix), are described in the `LLVM Exception
12270Handling <ExceptionHandling.html#format_common_intrinsics>`_ document.
12271
12272.. _int_trampoline:
12273
12274Trampoline Intrinsics
12275---------------------
12276
12277These intrinsics make it possible to excise one parameter, marked with
12278the :ref:`nest <nest>` attribute, from a function. The result is a
12279callable function pointer lacking the nest parameter - the caller does
12280not need to provide a value for it. Instead, the value to use is stored
12281in advance in a "trampoline", a block of memory usually allocated on the
12282stack, which also contains code to splice the nest value into the
12283argument list. This is used to implement the GCC nested function address
12284extension.
12285
12286For example, if the function is ``i32 f(i8* nest %c, i32 %x, i32 %y)``
12287then the resulting function pointer has signature ``i32 (i32, i32)*``.
12288It can be created as follows:
12289
12290.. code-block:: llvm
12291
12292 %tramp = alloca [10 x i8], align 4 ; size and alignment only correct for X86
David Blaikie16a97eb2015-03-04 22:02:58 +000012293 %tramp1 = getelementptr [10 x i8], [10 x i8]* %tramp, i32 0, i32 0
Sean Silvab084af42012-12-07 10:36:55 +000012294 call i8* @llvm.init.trampoline(i8* %tramp1, i8* bitcast (i32 (i8*, i32, i32)* @f to i8*), i8* %nval)
12295 %p = call i8* @llvm.adjust.trampoline(i8* %tramp1)
12296 %fp = bitcast i8* %p to i32 (i32, i32)*
12297
12298The call ``%val = call i32 %fp(i32 %x, i32 %y)`` is then equivalent to
12299``%val = call i32 %f(i8* %nval, i32 %x, i32 %y)``.
12300
12301.. _int_it:
12302
12303'``llvm.init.trampoline``' Intrinsic
12304^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12305
12306Syntax:
12307"""""""
12308
12309::
12310
12311 declare void @llvm.init.trampoline(i8* <tramp>, i8* <func>, i8* <nval>)
12312
12313Overview:
12314"""""""""
12315
12316This fills the memory pointed to by ``tramp`` with executable code,
12317turning it into a trampoline.
12318
12319Arguments:
12320""""""""""
12321
12322The ``llvm.init.trampoline`` intrinsic takes three arguments, all
12323pointers. The ``tramp`` argument must point to a sufficiently large and
12324sufficiently aligned block of memory; this memory is written to by the
12325intrinsic. Note that the size and the alignment are target-specific -
12326LLVM currently provides no portable way of determining them, so a
12327front-end that generates this intrinsic needs to have some
12328target-specific knowledge. The ``func`` argument must hold a function
12329bitcast to an ``i8*``.
12330
12331Semantics:
12332""""""""""
12333
12334The block of memory pointed to by ``tramp`` is filled with target
12335dependent code, turning it into a function. Then ``tramp`` needs to be
12336passed to :ref:`llvm.adjust.trampoline <int_at>` to get a pointer which can
12337be :ref:`bitcast (to a new function) and called <int_trampoline>`. The new
12338function's signature is the same as that of ``func`` with any arguments
12339marked with the ``nest`` attribute removed. At most one such ``nest``
12340argument is allowed, and it must be of pointer type. Calling the new
12341function is equivalent to calling ``func`` with the same argument list,
12342but with ``nval`` used for the missing ``nest`` argument. If, after
12343calling ``llvm.init.trampoline``, the memory pointed to by ``tramp`` is
12344modified, then the effect of any later call to the returned function
12345pointer is undefined.
12346
12347.. _int_at:
12348
12349'``llvm.adjust.trampoline``' Intrinsic
12350^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12351
12352Syntax:
12353"""""""
12354
12355::
12356
12357 declare i8* @llvm.adjust.trampoline(i8* <tramp>)
12358
12359Overview:
12360"""""""""
12361
12362This performs any required machine-specific adjustment to the address of
12363a trampoline (passed as ``tramp``).
12364
12365Arguments:
12366""""""""""
12367
12368``tramp`` must point to a block of memory which already has trampoline
12369code filled in by a previous call to
12370:ref:`llvm.init.trampoline <int_it>`.
12371
12372Semantics:
12373""""""""""
12374
12375On some architectures the address of the code to be executed needs to be
Sanjay Patel69bf48e2014-07-04 19:40:43 +000012376different than the address where the trampoline is actually stored. This
Sean Silvab084af42012-12-07 10:36:55 +000012377intrinsic returns the executable address corresponding to ``tramp``
12378after performing the required machine specific adjustments. The pointer
12379returned can then be :ref:`bitcast and executed <int_trampoline>`.
12380
Elena Demikhovsky82cdd652015-05-07 12:25:11 +000012381.. _int_mload_mstore:
12382
Elena Demikhovsky3d13f1c2014-12-25 09:29:13 +000012383Masked Vector Load and Store Intrinsics
12384---------------------------------------
12385
12386LLVM provides intrinsics for predicated vector load and store operations. The predicate is specified by a mask operand, which holds one bit per vector element, switching the associated vector lane on or off. The memory addresses corresponding to the "off" lanes are not accessed. When all bits of the mask are on, the intrinsic is identical to a regular vector load or store. When all bits are off, no memory is accessed.
12387
12388.. _int_mload:
12389
12390'``llvm.masked.load.*``' Intrinsics
12391^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12392
12393Syntax:
12394"""""""
Elena Demikhovsky1ca72e12015-11-19 07:17:16 +000012395This is an overloaded intrinsic. The loaded data is a vector of any integer, floating point or pointer data type.
Elena Demikhovsky3d13f1c2014-12-25 09:29:13 +000012396
12397::
12398
Artur Pilipenko7ad95ec2016-06-28 18:27:25 +000012399 declare <16 x float> @llvm.masked.load.v16f32.p0v16f32 (<16 x float>* <ptr>, i32 <alignment>, <16 x i1> <mask>, <16 x float> <passthru>)
12400 declare <2 x double> @llvm.masked.load.v2f64.p0v2f64 (<2 x double>* <ptr>, i32 <alignment>, <2 x i1> <mask>, <2 x double> <passthru>)
Elena Demikhovsky1ca72e12015-11-19 07:17:16 +000012401 ;; The data is a vector of pointers to double
Artur Pilipenko7ad95ec2016-06-28 18:27:25 +000012402 declare <8 x double*> @llvm.masked.load.v8p0f64.p0v8p0f64 (<8 x double*>* <ptr>, i32 <alignment>, <8 x i1> <mask>, <8 x double*> <passthru>)
Elena Demikhovsky1ca72e12015-11-19 07:17:16 +000012403 ;; The data is a vector of function pointers
Artur Pilipenko7ad95ec2016-06-28 18:27:25 +000012404 declare <8 x i32 ()*> @llvm.masked.load.v8p0f_i32f.p0v8p0f_i32f (<8 x i32 ()*>* <ptr>, i32 <alignment>, <8 x i1> <mask>, <8 x i32 ()*> <passthru>)
Elena Demikhovsky3d13f1c2014-12-25 09:29:13 +000012405
12406Overview:
12407"""""""""
12408
Elena Demikhovsky82cdd652015-05-07 12:25:11 +000012409Reads a vector from memory according to the provided mask. The mask holds a bit for each vector lane, and is used to prevent memory accesses to the masked-off lanes. The masked-off lanes in the result vector are taken from the corresponding lanes of the '``passthru``' operand.
Elena Demikhovsky3d13f1c2014-12-25 09:29:13 +000012410
12411
12412Arguments:
12413""""""""""
12414
Elena Demikhovsky82cdd652015-05-07 12:25:11 +000012415The first operand is the base pointer for the load. The second operand is the alignment of the source location. It must be a constant integer value. The third operand, mask, is a vector of boolean values with the same number of elements as the return type. The fourth is a pass-through value that is used to fill the masked-off lanes of the result. The return type, underlying type of the base pointer and the type of the '``passthru``' operand are the same vector types.
Elena Demikhovsky3d13f1c2014-12-25 09:29:13 +000012416
12417
12418Semantics:
12419""""""""""
12420
12421The '``llvm.masked.load``' intrinsic is designed for conditional reading of selected vector elements in a single IR operation. It is useful for targets that support vector masked loads and allows vectorizing predicated basic blocks on these targets. Other targets may support this intrinsic differently, for example by lowering it into a sequence of branches that guard scalar load operations.
12422The result of this operation is equivalent to a regular vector load instruction followed by a 'select' between the loaded and the passthru values, predicated on the same mask. However, using this intrinsic prevents exceptions on memory access to masked-off lanes.
12423
12424
12425::
12426
Artur Pilipenko7ad95ec2016-06-28 18:27:25 +000012427 %res = call <16 x float> @llvm.masked.load.v16f32.p0v16f32 (<16 x float>* %ptr, i32 4, <16 x i1>%mask, <16 x float> %passthru)
Mehdi Amini4a121fa2015-03-14 22:04:06 +000012428
Elena Demikhovsky3d13f1c2014-12-25 09:29:13 +000012429 ;; The result of the two following instructions is identical aside from potential memory access exception
David Blaikiec7aabbb2015-03-04 22:06:14 +000012430 %loadlal = load <16 x float>, <16 x float>* %ptr, align 4
Elena Demikhovskye86c8c82014-12-29 09:47:51 +000012431 %res = select <16 x i1> %mask, <16 x float> %loadlal, <16 x float> %passthru
Elena Demikhovsky3d13f1c2014-12-25 09:29:13 +000012432
12433.. _int_mstore:
12434
12435'``llvm.masked.store.*``' Intrinsics
12436^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12437
12438Syntax:
12439"""""""
Elena Demikhovsky1ca72e12015-11-19 07:17:16 +000012440This is an overloaded intrinsic. The data stored in memory is a vector of any integer, floating point or pointer data type.
Elena Demikhovsky3d13f1c2014-12-25 09:29:13 +000012441
12442::
12443
Artur Pilipenko7ad95ec2016-06-28 18:27:25 +000012444 declare void @llvm.masked.store.v8i32.p0v8i32 (<8 x i32> <value>, <8 x i32>* <ptr>, i32 <alignment>, <8 x i1> <mask>)
12445 declare void @llvm.masked.store.v16f32.p0v16f32 (<16 x float> <value>, <16 x float>* <ptr>, i32 <alignment>, <16 x i1> <mask>)
Elena Demikhovsky1ca72e12015-11-19 07:17:16 +000012446 ;; The data is a vector of pointers to double
Artur Pilipenko7ad95ec2016-06-28 18:27:25 +000012447 declare void @llvm.masked.store.v8p0f64.p0v8p0f64 (<8 x double*> <value>, <8 x double*>* <ptr>, i32 <alignment>, <8 x i1> <mask>)
Elena Demikhovsky1ca72e12015-11-19 07:17:16 +000012448 ;; The data is a vector of function pointers
Artur Pilipenko7ad95ec2016-06-28 18:27:25 +000012449 declare void @llvm.masked.store.v4p0f_i32f.p0v4p0f_i32f (<4 x i32 ()*> <value>, <4 x i32 ()*>* <ptr>, i32 <alignment>, <4 x i1> <mask>)
Elena Demikhovsky3d13f1c2014-12-25 09:29:13 +000012450
12451Overview:
12452"""""""""
12453
12454Writes a vector to memory according to the provided mask. The mask holds a bit for each vector lane, and is used to prevent memory accesses to the masked-off lanes.
12455
12456Arguments:
12457""""""""""
12458
12459The first operand is the vector value to be written to memory. The second operand is the base pointer for the store, it has the same underlying type as the value operand. The third operand is the alignment of the destination location. The fourth operand, mask, is a vector of boolean values. The types of the mask and the value operand must have the same number of vector elements.
12460
12461
12462Semantics:
12463""""""""""
12464
12465The '``llvm.masked.store``' intrinsics is designed for conditional writing of selected vector elements in a single IR operation. It is useful for targets that support vector masked store and allows vectorizing predicated basic blocks on these targets. Other targets may support this intrinsic differently, for example by lowering it into a sequence of branches that guard scalar store operations.
12466The result of this operation is equivalent to a load-modify-store sequence. However, using this intrinsic prevents exceptions and data races on memory access to masked-off lanes.
12467
12468::
12469
Artur Pilipenko7ad95ec2016-06-28 18:27:25 +000012470 call void @llvm.masked.store.v16f32.p0v16f32(<16 x float> %value, <16 x float>* %ptr, i32 4, <16 x i1> %mask)
Mehdi Amini4a121fa2015-03-14 22:04:06 +000012471
Elena Demikhovskye86c8c82014-12-29 09:47:51 +000012472 ;; The result of the following instructions is identical aside from potential data races and memory access exceptions
David Blaikiec7aabbb2015-03-04 22:06:14 +000012473 %oldval = load <16 x float>, <16 x float>* %ptr, align 4
Elena Demikhovsky3d13f1c2014-12-25 09:29:13 +000012474 %res = select <16 x i1> %mask, <16 x float> %value, <16 x float> %oldval
12475 store <16 x float> %res, <16 x float>* %ptr, align 4
12476
12477
Elena Demikhovsky82cdd652015-05-07 12:25:11 +000012478Masked Vector Gather and Scatter Intrinsics
12479-------------------------------------------
12480
12481LLVM provides intrinsics for vector gather and scatter operations. They are similar to :ref:`Masked Vector Load and Store <int_mload_mstore>`, except they are designed for arbitrary memory accesses, rather than sequential memory accesses. Gather and scatter also employ a mask operand, which holds one bit per vector element, switching the associated vector lane on or off. The memory addresses corresponding to the "off" lanes are not accessed. When all bits are off, no memory is accessed.
12482
12483.. _int_mgather:
12484
12485'``llvm.masked.gather.*``' Intrinsics
12486^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12487
12488Syntax:
12489"""""""
Elena Demikhovsky1ca72e12015-11-19 07:17:16 +000012490This is an overloaded intrinsic. The loaded data are multiple scalar values of any integer, floating point or pointer data type gathered together into one vector.
Elena Demikhovsky82cdd652015-05-07 12:25:11 +000012491
12492::
12493
Elad Cohenef5798a2017-05-03 12:28:54 +000012494 declare <16 x float> @llvm.masked.gather.v16f32.v16p0f32 (<16 x float*> <ptrs>, i32 <alignment>, <16 x i1> <mask>, <16 x float> <passthru>)
12495 declare <2 x double> @llvm.masked.gather.v2f64.v2p1f64 (<2 x double addrspace(1)*> <ptrs>, i32 <alignment>, <2 x i1> <mask>, <2 x double> <passthru>)
12496 declare <8 x float*> @llvm.masked.gather.v8p0f32.v8p0p0f32 (<8 x float**> <ptrs>, i32 <alignment>, <8 x i1> <mask>, <8 x float*> <passthru>)
Elena Demikhovsky82cdd652015-05-07 12:25:11 +000012497
12498Overview:
12499"""""""""
12500
12501Reads scalar values from arbitrary memory locations and gathers them into one vector. The memory locations are provided in the vector of pointers '``ptrs``'. The memory is accessed according to the provided mask. The mask holds a bit for each vector lane, and is used to prevent memory accesses to the masked-off lanes. The masked-off lanes in the result vector are taken from the corresponding lanes of the '``passthru``' operand.
12502
12503
12504Arguments:
12505""""""""""
12506
12507The first operand is a vector of pointers which holds all memory addresses to read. The second operand is an alignment of the source addresses. It must be a constant integer value. The third operand, mask, is a vector of boolean values with the same number of elements as the return type. The fourth is a pass-through value that is used to fill the masked-off lanes of the result. The return type, underlying type of the vector of pointers and the type of the '``passthru``' operand are the same vector types.
12508
12509
12510Semantics:
12511""""""""""
12512
12513The '``llvm.masked.gather``' intrinsic is designed for conditional reading of multiple scalar values from arbitrary memory locations in a single IR operation. It is useful for targets that support vector masked gathers and allows vectorizing basic blocks with data and control divergence. Other targets may support this intrinsic differently, for example by lowering it into a sequence of scalar load operations.
12514The semantics of this operation are equivalent to a sequence of conditional scalar loads with subsequent gathering all loaded values into a single vector. The mask restricts memory access to certain lanes and facilitates vectorization of predicated basic blocks.
12515
12516
12517::
12518
Elad Cohenef5798a2017-05-03 12:28:54 +000012519 %res = call <4 x double> @llvm.masked.gather.v4f64.v4p0f64 (<4 x double*> %ptrs, i32 8, <4 x i1> <i1 true, i1 true, i1 true, i1 true>, <4 x double> undef)
Elena Demikhovsky82cdd652015-05-07 12:25:11 +000012520
12521 ;; The gather with all-true mask is equivalent to the following instruction sequence
12522 %ptr0 = extractelement <4 x double*> %ptrs, i32 0
12523 %ptr1 = extractelement <4 x double*> %ptrs, i32 1
12524 %ptr2 = extractelement <4 x double*> %ptrs, i32 2
12525 %ptr3 = extractelement <4 x double*> %ptrs, i32 3
12526
12527 %val0 = load double, double* %ptr0, align 8
12528 %val1 = load double, double* %ptr1, align 8
12529 %val2 = load double, double* %ptr2, align 8
12530 %val3 = load double, double* %ptr3, align 8
12531
12532 %vec0 = insertelement <4 x double>undef, %val0, 0
12533 %vec01 = insertelement <4 x double>%vec0, %val1, 1
12534 %vec012 = insertelement <4 x double>%vec01, %val2, 2
12535 %vec0123 = insertelement <4 x double>%vec012, %val3, 3
12536
12537.. _int_mscatter:
12538
12539'``llvm.masked.scatter.*``' Intrinsics
12540^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12541
12542Syntax:
12543"""""""
Elena Demikhovsky1ca72e12015-11-19 07:17:16 +000012544This is an overloaded intrinsic. The data stored in memory is a vector of any integer, floating point or pointer data type. Each vector element is stored in an arbitrary memory address. Scatter with overlapping addresses is guaranteed to be ordered from least-significant to most-significant element.
Elena Demikhovsky82cdd652015-05-07 12:25:11 +000012545
12546::
12547
Elad Cohenef5798a2017-05-03 12:28:54 +000012548 declare void @llvm.masked.scatter.v8i32.v8p0i32 (<8 x i32> <value>, <8 x i32*> <ptrs>, i32 <alignment>, <8 x i1> <mask>)
12549 declare void @llvm.masked.scatter.v16f32.v16p1f32 (<16 x float> <value>, <16 x float addrspace(1)*> <ptrs>, i32 <alignment>, <16 x i1> <mask>)
12550 declare void @llvm.masked.scatter.v4p0f64.v4p0p0f64 (<4 x double*> <value>, <4 x double**> <ptrs>, i32 <alignment>, <4 x i1> <mask>)
Elena Demikhovsky82cdd652015-05-07 12:25:11 +000012551
12552Overview:
12553"""""""""
12554
12555Writes each element from the value vector to the corresponding memory address. The memory addresses are represented as a vector of pointers. Writing is done according to the provided mask. The mask holds a bit for each vector lane, and is used to prevent memory accesses to the masked-off lanes.
12556
12557Arguments:
12558""""""""""
12559
12560The first operand is a vector value to be written to memory. The second operand is a vector of pointers, pointing to where the value elements should be stored. It has the same underlying type as the value operand. The third operand is an alignment of the destination addresses. The fourth operand, mask, is a vector of boolean values. The types of the mask and the value operand must have the same number of vector elements.
12561
12562
12563Semantics:
12564""""""""""
12565
Bruce Mitchenere9ffb452015-09-12 01:17:08 +000012566The '``llvm.masked.scatter``' intrinsics is designed for writing selected vector elements to arbitrary memory addresses in a single IR operation. The operation may be conditional, when not all bits in the mask are switched on. It is useful for targets that support vector masked scatter and allows vectorizing basic blocks with data and control divergence. Other targets may support this intrinsic differently, for example by lowering it into a sequence of branches that guard scalar store operations.
Elena Demikhovsky82cdd652015-05-07 12:25:11 +000012567
12568::
12569
Sylvestre Ledru84666a12016-02-14 20:16:22 +000012570 ;; This instruction unconditionally stores data vector in multiple addresses
Elad Cohenef5798a2017-05-03 12:28:54 +000012571 call @llvm.masked.scatter.v8i32.v8p0i32 (<8 x i32> %value, <8 x i32*> %ptrs, i32 4, <8 x i1> <true, true, .. true>)
Elena Demikhovsky82cdd652015-05-07 12:25:11 +000012572
12573 ;; It is equivalent to a list of scalar stores
12574 %val0 = extractelement <8 x i32> %value, i32 0
12575 %val1 = extractelement <8 x i32> %value, i32 1
12576 ..
12577 %val7 = extractelement <8 x i32> %value, i32 7
12578 %ptr0 = extractelement <8 x i32*> %ptrs, i32 0
12579 %ptr1 = extractelement <8 x i32*> %ptrs, i32 1
12580 ..
12581 %ptr7 = extractelement <8 x i32*> %ptrs, i32 7
12582 ;; Note: the order of the following stores is important when they overlap:
12583 store i32 %val0, i32* %ptr0, align 4
12584 store i32 %val1, i32* %ptr1, align 4
12585 ..
12586 store i32 %val7, i32* %ptr7, align 4
12587
12588
Sean Silvab084af42012-12-07 10:36:55 +000012589Memory Use Markers
12590------------------
12591
Sanjay Patel69bf48e2014-07-04 19:40:43 +000012592This class of intrinsics provides information about the lifetime of
Sean Silvab084af42012-12-07 10:36:55 +000012593memory objects and ranges where variables are immutable.
12594
Reid Klecknera534a382013-12-19 02:14:12 +000012595.. _int_lifestart:
12596
Sean Silvab084af42012-12-07 10:36:55 +000012597'``llvm.lifetime.start``' Intrinsic
12598^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12599
12600Syntax:
12601"""""""
12602
12603::
12604
12605 declare void @llvm.lifetime.start(i64 <size>, i8* nocapture <ptr>)
12606
12607Overview:
12608"""""""""
12609
12610The '``llvm.lifetime.start``' intrinsic specifies the start of a memory
12611object's lifetime.
12612
12613Arguments:
12614""""""""""
12615
12616The first argument is a constant integer representing the size of the
12617object, or -1 if it is variable sized. The second argument is a pointer
12618to the object.
12619
12620Semantics:
12621""""""""""
12622
12623This intrinsic indicates that before this point in the code, the value
12624of the memory pointed to by ``ptr`` is dead. This means that it is known
12625to never be used and has an undefined value. A load from the pointer
12626that precedes this intrinsic can be replaced with ``'undef'``.
12627
Reid Klecknera534a382013-12-19 02:14:12 +000012628.. _int_lifeend:
12629
Sean Silvab084af42012-12-07 10:36:55 +000012630'``llvm.lifetime.end``' Intrinsic
12631^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12632
12633Syntax:
12634"""""""
12635
12636::
12637
12638 declare void @llvm.lifetime.end(i64 <size>, i8* nocapture <ptr>)
12639
12640Overview:
12641"""""""""
12642
12643The '``llvm.lifetime.end``' intrinsic specifies the end of a memory
12644object's lifetime.
12645
12646Arguments:
12647""""""""""
12648
12649The first argument is a constant integer representing the size of the
12650object, or -1 if it is variable sized. The second argument is a pointer
12651to the object.
12652
12653Semantics:
12654""""""""""
12655
12656This intrinsic indicates that after this point in the code, the value of
12657the memory pointed to by ``ptr`` is dead. This means that it is known to
12658never be used and has an undefined value. Any stores into the memory
12659object following this intrinsic may be removed as dead.
12660
12661'``llvm.invariant.start``' Intrinsic
12662^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12663
12664Syntax:
12665"""""""
Mehdi Amini8c629ec2016-08-13 23:31:24 +000012666This is an overloaded intrinsic. The memory object can belong to any address space.
Sean Silvab084af42012-12-07 10:36:55 +000012667
12668::
12669
Mehdi Amini8c629ec2016-08-13 23:31:24 +000012670 declare {}* @llvm.invariant.start.p0i8(i64 <size>, i8* nocapture <ptr>)
Sean Silvab084af42012-12-07 10:36:55 +000012671
12672Overview:
12673"""""""""
12674
12675The '``llvm.invariant.start``' intrinsic specifies that the contents of
12676a memory object will not change.
12677
12678Arguments:
12679""""""""""
12680
12681The first argument is a constant integer representing the size of the
12682object, or -1 if it is variable sized. The second argument is a pointer
12683to the object.
12684
12685Semantics:
12686""""""""""
12687
12688This intrinsic indicates that until an ``llvm.invariant.end`` that uses
12689the return value, the referenced memory location is constant and
12690unchanging.
12691
12692'``llvm.invariant.end``' Intrinsic
12693^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12694
12695Syntax:
12696"""""""
Mehdi Amini8c629ec2016-08-13 23:31:24 +000012697This is an overloaded intrinsic. The memory object can belong to any address space.
Sean Silvab084af42012-12-07 10:36:55 +000012698
12699::
12700
Mehdi Amini8c629ec2016-08-13 23:31:24 +000012701 declare void @llvm.invariant.end.p0i8({}* <start>, i64 <size>, i8* nocapture <ptr>)
Sean Silvab084af42012-12-07 10:36:55 +000012702
12703Overview:
12704"""""""""
12705
12706The '``llvm.invariant.end``' intrinsic specifies that the contents of a
12707memory object are mutable.
12708
12709Arguments:
12710""""""""""
12711
12712The first argument is the matching ``llvm.invariant.start`` intrinsic.
12713The second argument is a constant integer representing the size of the
12714object, or -1 if it is variable sized and the third argument is a
12715pointer to the object.
12716
12717Semantics:
12718""""""""""
12719
12720This intrinsic indicates that the memory is mutable again.
12721
Piotr Padlewski6c15ec42015-09-15 18:32:14 +000012722'``llvm.invariant.group.barrier``' Intrinsic
12723^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12724
12725Syntax:
12726"""""""
12727
12728::
12729
12730 declare i8* @llvm.invariant.group.barrier(i8* <ptr>)
12731
12732Overview:
12733"""""""""
12734
12735The '``llvm.invariant.group.barrier``' intrinsic can be used when an invariant
12736established by invariant.group metadata no longer holds, to obtain a new pointer
12737value that does not carry the invariant information.
12738
12739
12740Arguments:
12741""""""""""
12742
12743The ``llvm.invariant.group.barrier`` takes only one argument, which is
12744the pointer to the memory for which the ``invariant.group`` no longer holds.
12745
12746Semantics:
12747""""""""""
12748
12749Returns another pointer that aliases its argument but which is considered different
12750for the purposes of ``load``/``store`` ``invariant.group`` metadata.
12751
Andrew Kaylora0a11642017-01-26 23:27:59 +000012752Constrained Floating Point Intrinsics
12753-------------------------------------
12754
12755These intrinsics are used to provide special handling of floating point
12756operations when specific rounding mode or floating point exception behavior is
12757required. By default, LLVM optimization passes assume that the rounding mode is
12758round-to-nearest and that floating point exceptions will not be monitored.
12759Constrained FP intrinsics are used to support non-default rounding modes and
12760accurately preserve exception behavior without compromising LLVM's ability to
12761optimize FP code when the default behavior is used.
12762
12763Each of these intrinsics corresponds to a normal floating point operation. The
12764first two arguments and the return value are the same as the corresponding FP
12765operation.
12766
12767The third argument is a metadata argument specifying the rounding mode to be
12768assumed. This argument must be one of the following strings:
12769
12770::
Andrew Kaylor73b4a9a2017-04-20 18:18:36 +000012771
Andrew Kaylora0a11642017-01-26 23:27:59 +000012772 "round.dynamic"
12773 "round.tonearest"
12774 "round.downward"
12775 "round.upward"
12776 "round.towardzero"
12777
12778If this argument is "round.dynamic" optimization passes must assume that the
12779rounding mode is unknown and may change at runtime. No transformations that
12780depend on rounding mode may be performed in this case.
12781
12782The other possible values for the rounding mode argument correspond to the
12783similarly named IEEE rounding modes. If the argument is any of these values
12784optimization passes may perform transformations as long as they are consistent
12785with the specified rounding mode.
12786
12787For example, 'x-0'->'x' is not a valid transformation if the rounding mode is
12788"round.downward" or "round.dynamic" because if the value of 'x' is +0 then
12789'x-0' should evaluate to '-0' when rounding downward. However, this
12790transformation is legal for all other rounding modes.
12791
12792For values other than "round.dynamic" optimization passes may assume that the
12793actual runtime rounding mode (as defined in a target-specific manner) matches
12794the specified rounding mode, but this is not guaranteed. Using a specific
12795non-dynamic rounding mode which does not match the actual rounding mode at
12796runtime results in undefined behavior.
12797
12798The fourth argument to the constrained floating point intrinsics specifies the
12799required exception behavior. This argument must be one of the following
12800strings:
12801
12802::
Andrew Kaylor73b4a9a2017-04-20 18:18:36 +000012803
Andrew Kaylora0a11642017-01-26 23:27:59 +000012804 "fpexcept.ignore"
12805 "fpexcept.maytrap"
12806 "fpexcept.strict"
12807
12808If this argument is "fpexcept.ignore" optimization passes may assume that the
12809exception status flags will not be read and that floating point exceptions will
12810be masked. This allows transformations to be performed that may change the
12811exception semantics of the original code. For example, FP operations may be
12812speculatively executed in this case whereas they must not be for either of the
12813other possible values of this argument.
12814
12815If the exception behavior argument is "fpexcept.maytrap" optimization passes
12816must avoid transformations that may raise exceptions that would not have been
12817raised by the original code (such as speculatively executing FP operations), but
12818passes are not required to preserve all exceptions that are implied by the
12819original code. For example, exceptions may be potentially hidden by constant
12820folding.
12821
12822If the exception behavior argument is "fpexcept.strict" all transformations must
12823strictly preserve the floating point exception semantics of the original code.
12824Any FP exception that would have been raised by the original code must be raised
12825by the transformed code, and the transformed code must not raise any FP
12826exceptions that would not have been raised by the original code. This is the
12827exception behavior argument that will be used if the code being compiled reads
12828the FP exception status flags, but this mode can also be used with code that
12829unmasks FP exceptions.
12830
12831The number and order of floating point exceptions is NOT guaranteed. For
12832example, a series of FP operations that each may raise exceptions may be
12833vectorized into a single instruction that raises each unique exception a single
12834time.
12835
12836
12837'``llvm.experimental.constrained.fadd``' Intrinsic
12838^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12839
12840Syntax:
12841"""""""
12842
12843::
12844
12845 declare <type>
12846 @llvm.experimental.constrained.fadd(<type> <op1>, <type> <op2>,
12847 metadata <rounding mode>,
Andrew Kaylorf4660012017-05-25 21:31:00 +000012848 metadata <exception behavior>)
Andrew Kaylora0a11642017-01-26 23:27:59 +000012849
12850Overview:
12851"""""""""
12852
12853The '``llvm.experimental.constrained.fadd``' intrinsic returns the sum of its
12854two operands.
12855
12856
12857Arguments:
12858""""""""""
12859
12860The first two arguments to the '``llvm.experimental.constrained.fadd``'
12861intrinsic must be :ref:`floating point <t_floating>` or :ref:`vector <t_vector>`
12862of floating point values. Both arguments must have identical types.
12863
12864The third and fourth arguments specify the rounding mode and exception
12865behavior as described above.
12866
12867Semantics:
12868""""""""""
12869
12870The value produced is the floating point sum of the two value operands and has
12871the same type as the operands.
12872
12873
12874'``llvm.experimental.constrained.fsub``' Intrinsic
12875^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12876
12877Syntax:
12878"""""""
12879
12880::
12881
12882 declare <type>
12883 @llvm.experimental.constrained.fsub(<type> <op1>, <type> <op2>,
12884 metadata <rounding mode>,
Andrew Kaylorf4660012017-05-25 21:31:00 +000012885 metadata <exception behavior>)
Andrew Kaylora0a11642017-01-26 23:27:59 +000012886
12887Overview:
12888"""""""""
12889
12890The '``llvm.experimental.constrained.fsub``' intrinsic returns the difference
12891of its two operands.
12892
12893
12894Arguments:
12895""""""""""
12896
12897The first two arguments to the '``llvm.experimental.constrained.fsub``'
12898intrinsic must be :ref:`floating point <t_floating>` or :ref:`vector <t_vector>`
12899of floating point values. Both arguments must have identical types.
12900
12901The third and fourth arguments specify the rounding mode and exception
12902behavior as described above.
12903
12904Semantics:
12905""""""""""
12906
12907The value produced is the floating point difference of the two value operands
12908and has the same type as the operands.
12909
12910
12911'``llvm.experimental.constrained.fmul``' Intrinsic
12912^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12913
12914Syntax:
12915"""""""
12916
12917::
12918
12919 declare <type>
12920 @llvm.experimental.constrained.fmul(<type> <op1>, <type> <op2>,
12921 metadata <rounding mode>,
Andrew Kaylorf4660012017-05-25 21:31:00 +000012922 metadata <exception behavior>)
Andrew Kaylora0a11642017-01-26 23:27:59 +000012923
12924Overview:
12925"""""""""
12926
12927The '``llvm.experimental.constrained.fmul``' intrinsic returns the product of
12928its two operands.
12929
12930
12931Arguments:
12932""""""""""
12933
12934The first two arguments to the '``llvm.experimental.constrained.fmul``'
12935intrinsic must be :ref:`floating point <t_floating>` or :ref:`vector <t_vector>`
12936of floating point values. Both arguments must have identical types.
12937
12938The third and fourth arguments specify the rounding mode and exception
12939behavior as described above.
12940
12941Semantics:
12942""""""""""
12943
12944The value produced is the floating point product of the two value operands and
12945has the same type as the operands.
12946
12947
12948'``llvm.experimental.constrained.fdiv``' Intrinsic
12949^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12950
12951Syntax:
12952"""""""
12953
12954::
12955
12956 declare <type>
12957 @llvm.experimental.constrained.fdiv(<type> <op1>, <type> <op2>,
12958 metadata <rounding mode>,
Andrew Kaylorf4660012017-05-25 21:31:00 +000012959 metadata <exception behavior>)
Andrew Kaylora0a11642017-01-26 23:27:59 +000012960
12961Overview:
12962"""""""""
12963
12964The '``llvm.experimental.constrained.fdiv``' intrinsic returns the quotient of
12965its two operands.
12966
12967
12968Arguments:
12969""""""""""
12970
12971The first two arguments to the '``llvm.experimental.constrained.fdiv``'
12972intrinsic must be :ref:`floating point <t_floating>` or :ref:`vector <t_vector>`
12973of floating point values. Both arguments must have identical types.
12974
12975The third and fourth arguments specify the rounding mode and exception
12976behavior as described above.
12977
12978Semantics:
12979""""""""""
12980
12981The value produced is the floating point quotient of the two value operands and
12982has the same type as the operands.
12983
12984
12985'``llvm.experimental.constrained.frem``' Intrinsic
12986^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12987
12988Syntax:
12989"""""""
12990
12991::
12992
12993 declare <type>
12994 @llvm.experimental.constrained.frem(<type> <op1>, <type> <op2>,
12995 metadata <rounding mode>,
Andrew Kaylorf4660012017-05-25 21:31:00 +000012996 metadata <exception behavior>)
Andrew Kaylora0a11642017-01-26 23:27:59 +000012997
12998Overview:
12999"""""""""
13000
13001The '``llvm.experimental.constrained.frem``' intrinsic returns the remainder
13002from the division of its two operands.
13003
13004
13005Arguments:
13006""""""""""
13007
13008The first two arguments to the '``llvm.experimental.constrained.frem``'
13009intrinsic must be :ref:`floating point <t_floating>` or :ref:`vector <t_vector>`
13010of floating point values. Both arguments must have identical types.
13011
13012The third and fourth arguments specify the rounding mode and exception
13013behavior as described above. The rounding mode argument has no effect, since
13014the result of frem is never rounded, but the argument is included for
13015consistency with the other constrained floating point intrinsics.
13016
13017Semantics:
13018""""""""""
13019
13020The value produced is the floating point remainder from the division of the two
13021value operands and has the same type as the operands. The remainder has the
13022same sign as the dividend.
13023
Wei Dinga131d3f2017-08-24 04:18:24 +000013024'``llvm.experimental.constrained.fma``' Intrinsic
13025^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13026
13027Syntax:
13028"""""""
13029
13030::
13031
13032 declare <type>
13033 @llvm.experimental.constrained.fma(<type> <op1>, <type> <op2>, <type> <op3>,
13034 metadata <rounding mode>,
13035 metadata <exception behavior>)
13036
13037Overview:
13038"""""""""
13039
13040The '``llvm.experimental.constrained.fma``' intrinsic returns the result of a
13041fused-multiply-add operation on its operands.
13042
13043Arguments:
13044""""""""""
13045
13046The first three arguments to the '``llvm.experimental.constrained.fma``'
13047intrinsic must be :ref:`floating point <t_floating>` or :ref:`vector
13048<t_vector>` of floating point values. All arguments must have identical types.
13049
13050The fourth and fifth arguments specify the rounding mode and exception behavior
13051as described above.
13052
13053Semantics:
13054""""""""""
13055
13056The result produced is the product of the first two operands added to the third
13057operand computed with infinite precision, and then rounded to the target
13058precision.
Andrew Kaylora0a11642017-01-26 23:27:59 +000013059
Andrew Kaylorf4660012017-05-25 21:31:00 +000013060Constrained libm-equivalent Intrinsics
13061--------------------------------------
13062
13063In addition to the basic floating point operations for which constrained
13064intrinsics are described above, there are constrained versions of various
13065operations which provide equivalent behavior to a corresponding libm function.
13066These intrinsics allow the precise behavior of these operations with respect to
13067rounding mode and exception behavior to be controlled.
13068
13069As with the basic constrained floating point intrinsics, the rounding mode
13070and exception behavior arguments only control the behavior of the optimizer.
13071They do not change the runtime floating point environment.
13072
13073
13074'``llvm.experimental.constrained.sqrt``' Intrinsic
13075^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13076
13077Syntax:
13078"""""""
13079
13080::
13081
13082 declare <type>
13083 @llvm.experimental.constrained.sqrt(<type> <op1>,
13084 metadata <rounding mode>,
13085 metadata <exception behavior>)
13086
13087Overview:
13088"""""""""
13089
13090The '``llvm.experimental.constrained.sqrt``' intrinsic returns the square root
13091of the specified value, returning the same value as the libm '``sqrt``'
13092functions would, but without setting ``errno``.
13093
13094Arguments:
13095""""""""""
13096
13097The first argument and the return type are floating point numbers of the same
13098type.
13099
13100The second and third arguments specify the rounding mode and exception
13101behavior as described above.
13102
13103Semantics:
13104""""""""""
13105
13106This function returns the nonnegative square root of the specified value.
13107If the value is less than negative zero, a floating point exception occurs
13108and the the return value is architecture specific.
13109
13110
13111'``llvm.experimental.constrained.pow``' Intrinsic
13112^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13113
13114Syntax:
13115"""""""
13116
13117::
13118
13119 declare <type>
13120 @llvm.experimental.constrained.pow(<type> <op1>, <type> <op2>,
13121 metadata <rounding mode>,
13122 metadata <exception behavior>)
13123
13124Overview:
13125"""""""""
13126
13127The '``llvm.experimental.constrained.pow``' intrinsic returns the first operand
13128raised to the (positive or negative) power specified by the second operand.
13129
13130Arguments:
13131""""""""""
13132
13133The first two arguments and the return value are floating point numbers of the
13134same type. The second argument specifies the power to which the first argument
13135should be raised.
13136
13137The third and fourth arguments specify the rounding mode and exception
13138behavior as described above.
13139
13140Semantics:
13141""""""""""
13142
13143This function returns the first value raised to the second power,
13144returning the same values as the libm ``pow`` functions would, and
13145handles error conditions in the same way.
13146
13147
13148'``llvm.experimental.constrained.powi``' Intrinsic
13149^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13150
13151Syntax:
13152"""""""
13153
13154::
13155
13156 declare <type>
13157 @llvm.experimental.constrained.powi(<type> <op1>, i32 <op2>,
13158 metadata <rounding mode>,
13159 metadata <exception behavior>)
13160
13161Overview:
13162"""""""""
13163
13164The '``llvm.experimental.constrained.powi``' intrinsic returns the first operand
13165raised to the (positive or negative) power specified by the second operand. The
13166order of evaluation of multiplications is not defined. When a vector of floating
13167point type is used, the second argument remains a scalar integer value.
13168
13169
13170Arguments:
13171""""""""""
13172
13173The first argument and the return value are floating point numbers of the same
13174type. The second argument is a 32-bit signed integer specifying the power to
13175which the first argument should be raised.
13176
13177The third and fourth arguments specify the rounding mode and exception
13178behavior as described above.
13179
13180Semantics:
13181""""""""""
13182
13183This function returns the first value raised to the second power with an
13184unspecified sequence of rounding operations.
13185
13186
13187'``llvm.experimental.constrained.sin``' Intrinsic
13188^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13189
13190Syntax:
13191"""""""
13192
13193::
13194
13195 declare <type>
13196 @llvm.experimental.constrained.sin(<type> <op1>,
13197 metadata <rounding mode>,
13198 metadata <exception behavior>)
13199
13200Overview:
13201"""""""""
13202
13203The '``llvm.experimental.constrained.sin``' intrinsic returns the sine of the
13204first operand.
13205
13206Arguments:
13207""""""""""
13208
13209The first argument and the return type are floating point numbers of the same
13210type.
13211
13212The second and third arguments specify the rounding mode and exception
13213behavior as described above.
13214
13215Semantics:
13216""""""""""
13217
13218This function returns the sine of the specified operand, returning the
13219same values as the libm ``sin`` functions would, and handles error
13220conditions in the same way.
13221
13222
13223'``llvm.experimental.constrained.cos``' Intrinsic
13224^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13225
13226Syntax:
13227"""""""
13228
13229::
13230
13231 declare <type>
13232 @llvm.experimental.constrained.cos(<type> <op1>,
13233 metadata <rounding mode>,
13234 metadata <exception behavior>)
13235
13236Overview:
13237"""""""""
13238
13239The '``llvm.experimental.constrained.cos``' intrinsic returns the cosine of the
13240first operand.
13241
13242Arguments:
13243""""""""""
13244
13245The first argument and the return type are floating point numbers of the same
13246type.
13247
13248The second and third arguments specify the rounding mode and exception
13249behavior as described above.
13250
13251Semantics:
13252""""""""""
13253
13254This function returns the cosine of the specified operand, returning the
13255same values as the libm ``cos`` functions would, and handles error
13256conditions in the same way.
13257
13258
13259'``llvm.experimental.constrained.exp``' Intrinsic
13260^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13261
13262Syntax:
13263"""""""
13264
13265::
13266
13267 declare <type>
13268 @llvm.experimental.constrained.exp(<type> <op1>,
13269 metadata <rounding mode>,
13270 metadata <exception behavior>)
13271
13272Overview:
13273"""""""""
13274
13275The '``llvm.experimental.constrained.exp``' intrinsic computes the base-e
13276exponential of the specified value.
13277
13278Arguments:
13279""""""""""
13280
13281The first argument and the return value are floating point numbers of the same
13282type.
13283
13284The second and third arguments specify the rounding mode and exception
13285behavior as described above.
13286
13287Semantics:
13288""""""""""
13289
13290This function returns the same values as the libm ``exp`` functions
13291would, and handles error conditions in the same way.
13292
13293
13294'``llvm.experimental.constrained.exp2``' Intrinsic
13295^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13296
13297Syntax:
13298"""""""
13299
13300::
13301
13302 declare <type>
13303 @llvm.experimental.constrained.exp2(<type> <op1>,
13304 metadata <rounding mode>,
13305 metadata <exception behavior>)
13306
13307Overview:
13308"""""""""
13309
13310The '``llvm.experimental.constrained.exp2``' intrinsic computes the base-2
13311exponential of the specified value.
13312
13313
13314Arguments:
13315""""""""""
13316
13317The first argument and the return value are floating point numbers of the same
13318type.
13319
13320The second and third arguments specify the rounding mode and exception
13321behavior as described above.
13322
13323Semantics:
13324""""""""""
13325
13326This function returns the same values as the libm ``exp2`` functions
13327would, and handles error conditions in the same way.
13328
13329
13330'``llvm.experimental.constrained.log``' Intrinsic
13331^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13332
13333Syntax:
13334"""""""
13335
13336::
13337
13338 declare <type>
13339 @llvm.experimental.constrained.log(<type> <op1>,
13340 metadata <rounding mode>,
13341 metadata <exception behavior>)
13342
13343Overview:
13344"""""""""
13345
13346The '``llvm.experimental.constrained.log``' intrinsic computes the base-e
13347logarithm of the specified value.
13348
13349Arguments:
13350""""""""""
13351
13352The first argument and the return value are floating point numbers of the same
13353type.
13354
13355The second and third arguments specify the rounding mode and exception
13356behavior as described above.
13357
13358
13359Semantics:
13360""""""""""
13361
13362This function returns the same values as the libm ``log`` functions
13363would, and handles error conditions in the same way.
13364
13365
13366'``llvm.experimental.constrained.log10``' Intrinsic
13367^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13368
13369Syntax:
13370"""""""
13371
13372::
13373
13374 declare <type>
13375 @llvm.experimental.constrained.log10(<type> <op1>,
13376 metadata <rounding mode>,
13377 metadata <exception behavior>)
13378
13379Overview:
13380"""""""""
13381
13382The '``llvm.experimental.constrained.log10``' intrinsic computes the base-10
13383logarithm of the specified value.
13384
13385Arguments:
13386""""""""""
13387
13388The first argument and the return value are floating point numbers of the same
13389type.
13390
13391The second and third arguments specify the rounding mode and exception
13392behavior as described above.
13393
13394Semantics:
13395""""""""""
13396
13397This function returns the same values as the libm ``log10`` functions
13398would, and handles error conditions in the same way.
13399
13400
13401'``llvm.experimental.constrained.log2``' Intrinsic
13402^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13403
13404Syntax:
13405"""""""
13406
13407::
13408
13409 declare <type>
13410 @llvm.experimental.constrained.log2(<type> <op1>,
13411 metadata <rounding mode>,
13412 metadata <exception behavior>)
13413
13414Overview:
13415"""""""""
13416
13417The '``llvm.experimental.constrained.log2``' intrinsic computes the base-2
13418logarithm of the specified value.
13419
13420Arguments:
13421""""""""""
13422
13423The first argument and the return value are floating point numbers of the same
13424type.
13425
13426The second and third arguments specify the rounding mode and exception
13427behavior as described above.
13428
13429Semantics:
13430""""""""""
13431
13432This function returns the same values as the libm ``log2`` functions
13433would, and handles error conditions in the same way.
13434
13435
13436'``llvm.experimental.constrained.rint``' Intrinsic
13437^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13438
13439Syntax:
13440"""""""
13441
13442::
13443
13444 declare <type>
13445 @llvm.experimental.constrained.rint(<type> <op1>,
13446 metadata <rounding mode>,
13447 metadata <exception behavior>)
13448
13449Overview:
13450"""""""""
13451
13452The '``llvm.experimental.constrained.rint``' intrinsic returns the first
13453operand rounded to the nearest integer. It may raise an inexact floating point
13454exception if the operand is not an integer.
13455
13456Arguments:
13457""""""""""
13458
13459The first argument and the return value are floating point numbers of the same
13460type.
13461
13462The second and third arguments specify the rounding mode and exception
13463behavior as described above.
13464
13465Semantics:
13466""""""""""
13467
13468This function returns the same values as the libm ``rint`` functions
13469would, and handles error conditions in the same way. The rounding mode is
13470described, not determined, by the rounding mode argument. The actual rounding
13471mode is determined by the runtime floating point environment. The rounding
13472mode argument is only intended as information to the compiler.
13473
13474
13475'``llvm.experimental.constrained.nearbyint``' Intrinsic
13476^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13477
13478Syntax:
13479"""""""
13480
13481::
13482
13483 declare <type>
13484 @llvm.experimental.constrained.nearbyint(<type> <op1>,
13485 metadata <rounding mode>,
13486 metadata <exception behavior>)
13487
13488Overview:
13489"""""""""
13490
13491The '``llvm.experimental.constrained.nearbyint``' intrinsic returns the first
13492operand rounded to the nearest integer. It will not raise an inexact floating
13493point exception if the operand is not an integer.
13494
13495
13496Arguments:
13497""""""""""
13498
13499The first argument and the return value are floating point numbers of the same
13500type.
13501
13502The second and third arguments specify the rounding mode and exception
13503behavior as described above.
13504
13505Semantics:
13506""""""""""
13507
13508This function returns the same values as the libm ``nearbyint`` functions
13509would, and handles error conditions in the same way. The rounding mode is
13510described, not determined, by the rounding mode argument. The actual rounding
13511mode is determined by the runtime floating point environment. The rounding
13512mode argument is only intended as information to the compiler.
13513
13514
Sean Silvab084af42012-12-07 10:36:55 +000013515General Intrinsics
13516------------------
13517
13518This class of intrinsics is designed to be generic and has no specific
13519purpose.
13520
13521'``llvm.var.annotation``' Intrinsic
13522^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13523
13524Syntax:
13525"""""""
13526
13527::
13528
13529 declare void @llvm.var.annotation(i8* <val>, i8* <str>, i8* <str>, i32 <int>)
13530
13531Overview:
13532"""""""""
13533
13534The '``llvm.var.annotation``' intrinsic.
13535
13536Arguments:
13537""""""""""
13538
13539The first argument is a pointer to a value, the second is a pointer to a
13540global string, the third is a pointer to a global string which is the
13541source file name, and the last argument is the line number.
13542
13543Semantics:
13544""""""""""
13545
13546This intrinsic allows annotation of local variables with arbitrary
13547strings. This can be useful for special purpose optimizations that want
13548to look for these annotations. These have no other defined use; they are
13549ignored by code generation and optimization.
13550
Michael Gottesman88d18832013-03-26 00:34:27 +000013551'``llvm.ptr.annotation.*``' Intrinsic
13552^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13553
13554Syntax:
13555"""""""
13556
13557This is an overloaded intrinsic. You can use '``llvm.ptr.annotation``' on a
13558pointer to an integer of any width. *NOTE* you must specify an address space for
13559the pointer. The identifier for the default address space is the integer
13560'``0``'.
13561
13562::
13563
13564 declare i8* @llvm.ptr.annotation.p<address space>i8(i8* <val>, i8* <str>, i8* <str>, i32 <int>)
13565 declare i16* @llvm.ptr.annotation.p<address space>i16(i16* <val>, i8* <str>, i8* <str>, i32 <int>)
13566 declare i32* @llvm.ptr.annotation.p<address space>i32(i32* <val>, i8* <str>, i8* <str>, i32 <int>)
13567 declare i64* @llvm.ptr.annotation.p<address space>i64(i64* <val>, i8* <str>, i8* <str>, i32 <int>)
13568 declare i256* @llvm.ptr.annotation.p<address space>i256(i256* <val>, i8* <str>, i8* <str>, i32 <int>)
13569
13570Overview:
13571"""""""""
13572
13573The '``llvm.ptr.annotation``' intrinsic.
13574
13575Arguments:
13576""""""""""
13577
13578The first argument is a pointer to an integer value of arbitrary bitwidth
13579(result of some expression), the second is a pointer to a global string, the
13580third is a pointer to a global string which is the source file name, and the
13581last argument is the line number. It returns the value of the first argument.
13582
13583Semantics:
13584""""""""""
13585
13586This intrinsic allows annotation of a pointer to an integer with arbitrary
13587strings. This can be useful for special purpose optimizations that want to look
13588for these annotations. These have no other defined use; they are ignored by code
13589generation and optimization.
13590
Sean Silvab084af42012-12-07 10:36:55 +000013591'``llvm.annotation.*``' Intrinsic
13592^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13593
13594Syntax:
13595"""""""
13596
13597This is an overloaded intrinsic. You can use '``llvm.annotation``' on
13598any integer bit width.
13599
13600::
13601
13602 declare i8 @llvm.annotation.i8(i8 <val>, i8* <str>, i8* <str>, i32 <int>)
13603 declare i16 @llvm.annotation.i16(i16 <val>, i8* <str>, i8* <str>, i32 <int>)
13604 declare i32 @llvm.annotation.i32(i32 <val>, i8* <str>, i8* <str>, i32 <int>)
13605 declare i64 @llvm.annotation.i64(i64 <val>, i8* <str>, i8* <str>, i32 <int>)
13606 declare i256 @llvm.annotation.i256(i256 <val>, i8* <str>, i8* <str>, i32 <int>)
13607
13608Overview:
13609"""""""""
13610
13611The '``llvm.annotation``' intrinsic.
13612
13613Arguments:
13614""""""""""
13615
13616The first argument is an integer value (result of some expression), the
13617second is a pointer to a global string, the third is a pointer to a
13618global string which is the source file name, and the last argument is
13619the line number. It returns the value of the first argument.
13620
13621Semantics:
13622""""""""""
13623
13624This intrinsic allows annotations to be put on arbitrary expressions
13625with arbitrary strings. This can be useful for special purpose
13626optimizations that want to look for these annotations. These have no
13627other defined use; they are ignored by code generation and optimization.
13628
Reid Klecknere33c94f2017-09-05 20:14:58 +000013629'``llvm.codeview.annotation``' Intrinsic
13630^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13631
13632Syntax:
13633"""""""
13634
13635This annotation emits a label at its program point and an associated
13636``S_ANNOTATION`` codeview record with some additional string metadata. This is
13637used to implement MSVC's ``__annotation`` intrinsic. It is marked
13638``noduplicate``, so calls to this intrinsic prevent inlining and should be
13639considered expensive.
13640
13641::
13642
13643 declare void @llvm.codeview.annotation(metadata)
13644
13645Arguments:
13646""""""""""
13647
13648The argument should be an MDTuple containing any number of MDStrings.
13649
Sean Silvab084af42012-12-07 10:36:55 +000013650'``llvm.trap``' Intrinsic
13651^^^^^^^^^^^^^^^^^^^^^^^^^
13652
13653Syntax:
13654"""""""
13655
13656::
13657
13658 declare void @llvm.trap() noreturn nounwind
13659
13660Overview:
13661"""""""""
13662
13663The '``llvm.trap``' intrinsic.
13664
13665Arguments:
13666""""""""""
13667
13668None.
13669
13670Semantics:
13671""""""""""
13672
13673This intrinsic is lowered to the target dependent trap instruction. If
13674the target does not have a trap instruction, this intrinsic will be
13675lowered to a call of the ``abort()`` function.
13676
13677'``llvm.debugtrap``' Intrinsic
13678^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13679
13680Syntax:
13681"""""""
13682
13683::
13684
13685 declare void @llvm.debugtrap() nounwind
13686
13687Overview:
13688"""""""""
13689
13690The '``llvm.debugtrap``' intrinsic.
13691
13692Arguments:
13693""""""""""
13694
13695None.
13696
13697Semantics:
13698""""""""""
13699
13700This intrinsic is lowered to code which is intended to cause an
13701execution trap with the intention of requesting the attention of a
13702debugger.
13703
13704'``llvm.stackprotector``' Intrinsic
13705^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13706
13707Syntax:
13708"""""""
13709
13710::
13711
13712 declare void @llvm.stackprotector(i8* <guard>, i8** <slot>)
13713
13714Overview:
13715"""""""""
13716
13717The ``llvm.stackprotector`` intrinsic takes the ``guard`` and stores it
13718onto the stack at ``slot``. The stack slot is adjusted to ensure that it
13719is placed on the stack before local variables.
13720
13721Arguments:
13722""""""""""
13723
13724The ``llvm.stackprotector`` intrinsic requires two pointer arguments.
13725The first argument is the value loaded from the stack guard
13726``@__stack_chk_guard``. The second variable is an ``alloca`` that has
13727enough space to hold the value of the guard.
13728
13729Semantics:
13730""""""""""
13731
Michael Gottesmandafc7d92013-08-12 18:35:32 +000013732This intrinsic causes the prologue/epilogue inserter to force the position of
13733the ``AllocaInst`` stack slot to be before local variables on the stack. This is
13734to ensure that if a local variable on the stack is overwritten, it will destroy
13735the value of the guard. When the function exits, the guard on the stack is
13736checked against the original guard by ``llvm.stackprotectorcheck``. If they are
13737different, then ``llvm.stackprotectorcheck`` causes the program to abort by
13738calling the ``__stack_chk_fail()`` function.
13739
Tim Shene885d5e2016-04-19 19:40:37 +000013740'``llvm.stackguard``' Intrinsic
13741^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13742
13743Syntax:
13744"""""""
13745
13746::
13747
13748 declare i8* @llvm.stackguard()
13749
13750Overview:
13751"""""""""
13752
13753The ``llvm.stackguard`` intrinsic returns the system stack guard value.
13754
13755It should not be generated by frontends, since it is only for internal usage.
13756The reason why we create this intrinsic is that we still support IR form Stack
13757Protector in FastISel.
13758
13759Arguments:
13760""""""""""
13761
13762None.
13763
13764Semantics:
13765""""""""""
13766
13767On some platforms, the value returned by this intrinsic remains unchanged
13768between loads in the same thread. On other platforms, it returns the same
13769global variable value, if any, e.g. ``@__stack_chk_guard``.
13770
13771Currently some platforms have IR-level customized stack guard loading (e.g.
13772X86 Linux) that is not handled by ``llvm.stackguard()``, while they should be
13773in the future.
13774
Sean Silvab084af42012-12-07 10:36:55 +000013775'``llvm.objectsize``' Intrinsic
13776^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13777
13778Syntax:
13779"""""""
13780
13781::
13782
George Burgess IV56c7e882017-03-21 20:08:59 +000013783 declare i32 @llvm.objectsize.i32(i8* <object>, i1 <min>, i1 <nullunknown>)
13784 declare i64 @llvm.objectsize.i64(i8* <object>, i1 <min>, i1 <nullunknown>)
Sean Silvab084af42012-12-07 10:36:55 +000013785
13786Overview:
13787"""""""""
13788
13789The ``llvm.objectsize`` intrinsic is designed to provide information to
13790the optimizers to determine at compile time whether a) an operation
13791(like memcpy) will overflow a buffer that corresponds to an object, or
13792b) that a runtime check for overflow isn't necessary. An object in this
13793context means an allocation of a specific class, structure, array, or
13794other object.
13795
13796Arguments:
13797""""""""""
13798
George Burgess IV56c7e882017-03-21 20:08:59 +000013799The ``llvm.objectsize`` intrinsic takes three arguments. The first argument is
13800a pointer to or into the ``object``. The second argument determines whether
13801``llvm.objectsize`` returns 0 (if true) or -1 (if false) when the object size
13802is unknown. The third argument controls how ``llvm.objectsize`` acts when
13803``null`` is used as its pointer argument. If it's true and the pointer is in
13804address space 0, ``null`` is treated as an opaque value with an unknown number
13805of bytes. Otherwise, ``llvm.objectsize`` reports 0 bytes available when given
13806``null``.
13807
13808The second and third arguments only accept constants.
Sean Silvab084af42012-12-07 10:36:55 +000013809
13810Semantics:
13811""""""""""
13812
13813The ``llvm.objectsize`` intrinsic is lowered to a constant representing
13814the size of the object concerned. If the size cannot be determined at
13815compile time, ``llvm.objectsize`` returns ``i32/i64 -1 or 0`` (depending
13816on the ``min`` argument).
13817
13818'``llvm.expect``' Intrinsic
13819^^^^^^^^^^^^^^^^^^^^^^^^^^^
13820
13821Syntax:
13822"""""""
13823
Duncan P. N. Exon Smith1ff08e32014-02-02 22:43:55 +000013824This is an overloaded intrinsic. You can use ``llvm.expect`` on any
13825integer bit width.
13826
Sean Silvab084af42012-12-07 10:36:55 +000013827::
13828
Duncan P. N. Exon Smith1ff08e32014-02-02 22:43:55 +000013829 declare i1 @llvm.expect.i1(i1 <val>, i1 <expected_val>)
Sean Silvab084af42012-12-07 10:36:55 +000013830 declare i32 @llvm.expect.i32(i32 <val>, i32 <expected_val>)
13831 declare i64 @llvm.expect.i64(i64 <val>, i64 <expected_val>)
13832
13833Overview:
13834"""""""""
13835
13836The ``llvm.expect`` intrinsic provides information about expected (the
13837most probable) value of ``val``, which can be used by optimizers.
13838
13839Arguments:
13840""""""""""
13841
13842The ``llvm.expect`` intrinsic takes two arguments. The first argument is
13843a value. The second argument is an expected value, this needs to be a
13844constant value, variables are not allowed.
13845
13846Semantics:
13847""""""""""
13848
13849This intrinsic is lowered to the ``val``.
13850
Philip Reamese0e90832015-04-26 22:23:12 +000013851.. _int_assume:
13852
Hal Finkel93046912014-07-25 21:13:35 +000013853'``llvm.assume``' Intrinsic
13854^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13855
13856Syntax:
13857"""""""
13858
13859::
13860
13861 declare void @llvm.assume(i1 %cond)
13862
13863Overview:
13864"""""""""
13865
13866The ``llvm.assume`` allows the optimizer to assume that the provided
13867condition is true. This information can then be used in simplifying other parts
13868of the code.
13869
13870Arguments:
13871""""""""""
13872
13873The condition which the optimizer may assume is always true.
13874
13875Semantics:
13876""""""""""
13877
13878The intrinsic allows the optimizer to assume that the provided condition is
13879always true whenever the control flow reaches the intrinsic call. No code is
13880generated for this intrinsic, and instructions that contribute only to the
13881provided condition are not used for code generation. If the condition is
13882violated during execution, the behavior is undefined.
13883
Sanjay Patel1ed2bb52015-01-14 16:03:58 +000013884Note that the optimizer might limit the transformations performed on values
Hal Finkel93046912014-07-25 21:13:35 +000013885used by the ``llvm.assume`` intrinsic in order to preserve the instructions
13886only used to form the intrinsic's input argument. This might prove undesirable
Sanjay Patel1ed2bb52015-01-14 16:03:58 +000013887if the extra information provided by the ``llvm.assume`` intrinsic does not cause
Hal Finkel93046912014-07-25 21:13:35 +000013888sufficient overall improvement in code quality. For this reason,
13889``llvm.assume`` should not be used to document basic mathematical invariants
13890that the optimizer can otherwise deduce or facts that are of little use to the
13891optimizer.
13892
Daniel Berlin2c438a32017-02-07 19:29:25 +000013893.. _int_ssa_copy:
13894
13895'``llvm.ssa_copy``' Intrinsic
13896^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13897
13898Syntax:
13899"""""""
13900
13901::
13902
13903 declare type @llvm.ssa_copy(type %operand) returned(1) readnone
13904
13905Arguments:
13906""""""""""
13907
13908The first argument is an operand which is used as the returned value.
13909
13910Overview:
13911""""""""""
13912
13913The ``llvm.ssa_copy`` intrinsic can be used to attach information to
13914operations by copying them and giving them new names. For example,
13915the PredicateInfo utility uses it to build Extended SSA form, and
13916attach various forms of information to operands that dominate specific
13917uses. It is not meant for general use, only for building temporary
13918renaming forms that require value splits at certain points.
13919
Peter Collingbourne7efd7502016-06-24 21:21:32 +000013920.. _type.test:
Peter Collingbournee6909c82015-02-20 20:30:47 +000013921
Peter Collingbourne7efd7502016-06-24 21:21:32 +000013922'``llvm.type.test``' Intrinsic
Peter Collingbournee6909c82015-02-20 20:30:47 +000013923^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13924
13925Syntax:
13926"""""""
13927
13928::
13929
Peter Collingbourne7efd7502016-06-24 21:21:32 +000013930 declare i1 @llvm.type.test(i8* %ptr, metadata %type) nounwind readnone
Peter Collingbournee6909c82015-02-20 20:30:47 +000013931
13932
13933Arguments:
13934""""""""""
13935
13936The first argument is a pointer to be tested. The second argument is a
Peter Collingbourne7efd7502016-06-24 21:21:32 +000013937metadata object representing a :doc:`type identifier <TypeMetadata>`.
Peter Collingbournee6909c82015-02-20 20:30:47 +000013938
13939Overview:
13940"""""""""
13941
Peter Collingbourne7efd7502016-06-24 21:21:32 +000013942The ``llvm.type.test`` intrinsic tests whether the given pointer is associated
13943with the given type identifier.
Peter Collingbournee6909c82015-02-20 20:30:47 +000013944
Peter Collingbourne0312f612016-06-25 00:23:04 +000013945'``llvm.type.checked.load``' Intrinsic
13946^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13947
13948Syntax:
13949"""""""
13950
13951::
13952
13953 declare {i8*, i1} @llvm.type.checked.load(i8* %ptr, i32 %offset, metadata %type) argmemonly nounwind readonly
13954
13955
13956Arguments:
13957""""""""""
13958
13959The first argument is a pointer from which to load a function pointer. The
13960second argument is the byte offset from which to load the function pointer. The
13961third argument is a metadata object representing a :doc:`type identifier
13962<TypeMetadata>`.
13963
13964Overview:
13965"""""""""
13966
13967The ``llvm.type.checked.load`` intrinsic safely loads a function pointer from a
13968virtual table pointer using type metadata. This intrinsic is used to implement
13969control flow integrity in conjunction with virtual call optimization. The
13970virtual call optimization pass will optimize away ``llvm.type.checked.load``
13971intrinsics associated with devirtualized calls, thereby removing the type
13972check in cases where it is not needed to enforce the control flow integrity
13973constraint.
13974
13975If the given pointer is associated with a type metadata identifier, this
13976function returns true as the second element of its return value. (Note that
13977the function may also return true if the given pointer is not associated
13978with a type metadata identifier.) If the function's return value's second
13979element is true, the following rules apply to the first element:
13980
13981- If the given pointer is associated with the given type metadata identifier,
13982 it is the function pointer loaded from the given byte offset from the given
13983 pointer.
13984
13985- If the given pointer is not associated with the given type metadata
13986 identifier, it is one of the following (the choice of which is unspecified):
13987
13988 1. The function pointer that would have been loaded from an arbitrarily chosen
13989 (through an unspecified mechanism) pointer associated with the type
13990 metadata.
13991
13992 2. If the function has a non-void return type, a pointer to a function that
13993 returns an unspecified value without causing side effects.
13994
13995If the function's return value's second element is false, the value of the
13996first element is undefined.
13997
13998
Sean Silvab084af42012-12-07 10:36:55 +000013999'``llvm.donothing``' Intrinsic
14000^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14001
14002Syntax:
14003"""""""
14004
14005::
14006
14007 declare void @llvm.donothing() nounwind readnone
14008
14009Overview:
14010"""""""""
14011
Juergen Ributzkac9161192014-10-23 22:36:13 +000014012The ``llvm.donothing`` intrinsic doesn't perform any operation. It's one of only
Sanjoy Das7a4c94d2016-02-26 03:33:59 +000014013three intrinsics (besides ``llvm.experimental.patchpoint`` and
14014``llvm.experimental.gc.statepoint``) that can be called with an invoke
14015instruction.
Sean Silvab084af42012-12-07 10:36:55 +000014016
14017Arguments:
14018""""""""""
14019
14020None.
14021
14022Semantics:
14023""""""""""
14024
14025This intrinsic does nothing, and it's removed by optimizers and ignored
14026by codegen.
Andrew Trick5e029ce2013-12-24 02:57:25 +000014027
Sanjoy Dasb51325d2016-03-11 19:08:34 +000014028'``llvm.experimental.deoptimize``' Intrinsic
14029^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14030
14031Syntax:
14032"""""""
14033
14034::
14035
14036 declare type @llvm.experimental.deoptimize(...) [ "deopt"(...) ]
14037
14038Overview:
14039"""""""""
14040
14041This intrinsic, together with :ref:`deoptimization operand bundles
14042<deopt_opbundles>`, allow frontends to express transfer of control and
14043frame-local state from the currently executing (typically more specialized,
14044hence faster) version of a function into another (typically more generic, hence
14045slower) version.
14046
14047In languages with a fully integrated managed runtime like Java and JavaScript
14048this intrinsic can be used to implement "uncommon trap" or "side exit" like
14049functionality. In unmanaged languages like C and C++, this intrinsic can be
14050used to represent the slow paths of specialized functions.
14051
14052
14053Arguments:
14054""""""""""
14055
14056The intrinsic takes an arbitrary number of arguments, whose meaning is
14057decided by the :ref:`lowering strategy<deoptimize_lowering>`.
14058
14059Semantics:
14060""""""""""
14061
14062The ``@llvm.experimental.deoptimize`` intrinsic executes an attached
14063deoptimization continuation (denoted using a :ref:`deoptimization
14064operand bundle <deopt_opbundles>`) and returns the value returned by
14065the deoptimization continuation. Defining the semantic properties of
14066the continuation itself is out of scope of the language reference --
14067as far as LLVM is concerned, the deoptimization continuation can
14068invoke arbitrary side effects, including reading from and writing to
14069the entire heap.
14070
14071Deoptimization continuations expressed using ``"deopt"`` operand bundles always
14072continue execution to the end of the physical frame containing them, so all
14073calls to ``@llvm.experimental.deoptimize`` must be in "tail position":
14074
14075 - ``@llvm.experimental.deoptimize`` cannot be invoked.
14076 - The call must immediately precede a :ref:`ret <i_ret>` instruction.
14077 - The ``ret`` instruction must return the value produced by the
14078 ``@llvm.experimental.deoptimize`` call if there is one, or void.
14079
14080Note that the above restrictions imply that the return type for a call to
14081``@llvm.experimental.deoptimize`` will match the return type of its immediate
14082caller.
14083
14084The inliner composes the ``"deopt"`` continuations of the caller into the
14085``"deopt"`` continuations present in the inlinee, and also updates calls to this
14086intrinsic to return directly from the frame of the function it inlined into.
14087
Sanjoy Dase0aa4142016-05-12 01:17:38 +000014088All declarations of ``@llvm.experimental.deoptimize`` must share the
14089same calling convention.
14090
Sanjoy Dasb51325d2016-03-11 19:08:34 +000014091.. _deoptimize_lowering:
14092
14093Lowering:
14094"""""""""
14095
Sanjoy Dasdf9ae702016-03-24 20:23:29 +000014096Calls to ``@llvm.experimental.deoptimize`` are lowered to calls to the
14097symbol ``__llvm_deoptimize`` (it is the frontend's responsibility to
14098ensure that this symbol is defined). The call arguments to
14099``@llvm.experimental.deoptimize`` are lowered as if they were formal
14100arguments of the specified types, and not as varargs.
14101
Sanjoy Dasb51325d2016-03-11 19:08:34 +000014102
Sanjoy Das021de052016-03-31 00:18:46 +000014103'``llvm.experimental.guard``' Intrinsic
14104^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14105
14106Syntax:
14107"""""""
14108
14109::
14110
14111 declare void @llvm.experimental.guard(i1, ...) [ "deopt"(...) ]
14112
14113Overview:
14114"""""""""
14115
14116This intrinsic, together with :ref:`deoptimization operand bundles
14117<deopt_opbundles>`, allows frontends to express guards or checks on
14118optimistic assumptions made during compilation. The semantics of
14119``@llvm.experimental.guard`` is defined in terms of
14120``@llvm.experimental.deoptimize`` -- its body is defined to be
14121equivalent to:
14122
Renato Golin124f2592016-07-20 12:16:38 +000014123.. code-block:: text
Sanjoy Das021de052016-03-31 00:18:46 +000014124
Renato Golin124f2592016-07-20 12:16:38 +000014125 define void @llvm.experimental.guard(i1 %pred, <args...>) {
14126 %realPred = and i1 %pred, undef
14127 br i1 %realPred, label %continue, label %leave [, !make.implicit !{}]
Sanjoy Das021de052016-03-31 00:18:46 +000014128
Renato Golin124f2592016-07-20 12:16:38 +000014129 leave:
14130 call void @llvm.experimental.deoptimize(<args...>) [ "deopt"() ]
14131 ret void
Sanjoy Das021de052016-03-31 00:18:46 +000014132
Renato Golin124f2592016-07-20 12:16:38 +000014133 continue:
14134 ret void
14135 }
Sanjoy Das021de052016-03-31 00:18:46 +000014136
Sanjoy Das47cf2af2016-04-30 00:55:59 +000014137
14138with the optional ``[, !make.implicit !{}]`` present if and only if it
14139is present on the call site. For more details on ``!make.implicit``,
14140see :doc:`FaultMaps`.
14141
Sanjoy Das021de052016-03-31 00:18:46 +000014142In words, ``@llvm.experimental.guard`` executes the attached
14143``"deopt"`` continuation if (but **not** only if) its first argument
14144is ``false``. Since the optimizer is allowed to replace the ``undef``
14145with an arbitrary value, it can optimize guard to fail "spuriously",
14146i.e. without the original condition being false (hence the "not only
14147if"); and this allows for "check widening" type optimizations.
14148
14149``@llvm.experimental.guard`` cannot be invoked.
14150
14151
Peter Collingbourne7dd8dbf2016-04-22 21:18:02 +000014152'``llvm.load.relative``' Intrinsic
14153^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14154
14155Syntax:
14156"""""""
14157
14158::
14159
14160 declare i8* @llvm.load.relative.iN(i8* %ptr, iN %offset) argmemonly nounwind readonly
14161
14162Overview:
14163"""""""""
14164
14165This intrinsic loads a 32-bit value from the address ``%ptr + %offset``,
14166adds ``%ptr`` to that value and returns it. The constant folder specifically
14167recognizes the form of this intrinsic and the constant initializers it may
14168load from; if a loaded constant initializer is known to have the form
14169``i32 trunc(x - %ptr)``, the intrinsic call is folded to ``x``.
14170
14171LLVM provides that the calculation of such a constant initializer will
14172not overflow at link time under the medium code model if ``x`` is an
14173``unnamed_addr`` function. However, it does not provide this guarantee for
14174a constant initializer folded into a function body. This intrinsic can be
14175used to avoid the possibility of overflows when loading from such a constant.
14176
Andrew Trick5e029ce2013-12-24 02:57:25 +000014177Stack Map Intrinsics
14178--------------------
14179
14180LLVM provides experimental intrinsics to support runtime patching
14181mechanisms commonly desired in dynamic language JITs. These intrinsics
14182are described in :doc:`StackMaps`.
Igor Laevsky4f31e522016-12-29 14:31:07 +000014183
14184Element Wise Atomic Memory Intrinsics
Igor Laevskyfedab152016-12-29 15:08:57 +000014185-------------------------------------
Igor Laevsky4f31e522016-12-29 14:31:07 +000014186
14187These intrinsics are similar to the standard library memory intrinsics except
14188that they perform memory transfer as a sequence of atomic memory accesses.
14189
Daniel Neilson3faabbb2017-06-16 14:43:59 +000014190.. _int_memcpy_element_unordered_atomic:
Igor Laevsky4f31e522016-12-29 14:31:07 +000014191
Daniel Neilson3faabbb2017-06-16 14:43:59 +000014192'``llvm.memcpy.element.unordered.atomic``' Intrinsic
14193^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Igor Laevsky4f31e522016-12-29 14:31:07 +000014194
14195Syntax:
14196"""""""
14197
Daniel Neilson3faabbb2017-06-16 14:43:59 +000014198This is an overloaded intrinsic. You can use ``llvm.memcpy.element.unordered.atomic`` on
Igor Laevsky4f31e522016-12-29 14:31:07 +000014199any integer bit width and for different address spaces. Not all targets
14200support all bit widths however.
14201
14202::
14203
Daniel Neilson3faabbb2017-06-16 14:43:59 +000014204 declare void @llvm.memcpy.element.unordered.atomic.p0i8.p0i8.i32(i8* <dest>,
14205 i8* <src>,
14206 i32 <len>,
14207 i32 <element_size>)
14208 declare void @llvm.memcpy.element.unordered.atomic.p0i8.p0i8.i64(i8* <dest>,
14209 i8* <src>,
14210 i64 <len>,
14211 i32 <element_size>)
Igor Laevsky4f31e522016-12-29 14:31:07 +000014212
14213Overview:
14214"""""""""
14215
Daniel Neilson3faabbb2017-06-16 14:43:59 +000014216The '``llvm.memcpy.element.unordered.atomic.*``' intrinsic is a specialization of the
14217'``llvm.memcpy.*``' intrinsic. It differs in that the ``dest`` and ``src`` are treated
14218as arrays with elements that are exactly ``element_size`` bytes, and the copy between
14219buffers uses a sequence of :ref:`unordered atomic <ordering>` load/store operations
14220that are a positive integer multiple of the ``element_size`` in size.
Igor Laevsky4f31e522016-12-29 14:31:07 +000014221
14222Arguments:
14223""""""""""
14224
Daniel Neilson3faabbb2017-06-16 14:43:59 +000014225The first three arguments are the same as they are in the :ref:`@llvm.memcpy <int_memcpy>`
14226intrinsic, with the added constraint that ``len`` is required to be a positive integer
14227multiple of the ``element_size``. If ``len`` is not a positive integer multiple of
14228``element_size``, then the behaviour of the intrinsic is undefined.
Igor Laevsky4f31e522016-12-29 14:31:07 +000014229
Daniel Neilson3faabbb2017-06-16 14:43:59 +000014230``element_size`` must be a compile-time constant positive power of two no greater than
14231target-specific atomic access size limit.
Igor Laevsky4f31e522016-12-29 14:31:07 +000014232
Daniel Neilson3faabbb2017-06-16 14:43:59 +000014233For each of the input pointers ``align`` parameter attribute must be specified. It
14234must be a power of two no less than the ``element_size``. Caller guarantees that
14235both the source and destination pointers are aligned to that boundary.
Igor Laevsky4f31e522016-12-29 14:31:07 +000014236
14237Semantics:
14238""""""""""
14239
Daniel Neilson3faabbb2017-06-16 14:43:59 +000014240The '``llvm.memcpy.element.unordered.atomic.*``' intrinsic copies ``len`` bytes of
14241memory from the source location to the destination location. These locations are not
14242allowed to overlap. The memory copy is performed as a sequence of load/store operations
14243where each access is guaranteed to be a multiple of ``element_size`` bytes wide and
14244aligned at an ``element_size`` boundary.
Igor Laevsky4f31e522016-12-29 14:31:07 +000014245
14246The order of the copy is unspecified. The same value may be read from the source
14247buffer many times, but only one write is issued to the destination buffer per
Daniel Neilson3faabbb2017-06-16 14:43:59 +000014248element. It is well defined to have concurrent reads and writes to both source and
14249destination provided those reads and writes are unordered atomic when specified.
Igor Laevsky4f31e522016-12-29 14:31:07 +000014250
14251This intrinsic does not provide any additional ordering guarantees over those
14252provided by a set of unordered loads from the source location and stores to the
14253destination.
14254
14255Lowering:
Igor Laevskyfedab152016-12-29 15:08:57 +000014256"""""""""
Igor Laevsky4f31e522016-12-29 14:31:07 +000014257
Daniel Neilson3faabbb2017-06-16 14:43:59 +000014258In the most general case call to the '``llvm.memcpy.element.unordered.atomic.*``' is
14259lowered to a call to the symbol ``__llvm_memcpy_element_unordered_atomic_*``. Where '*'
14260is replaced with an actual element size.
Igor Laevsky4f31e522016-12-29 14:31:07 +000014261
Daniel Neilson57226ef2017-07-12 15:25:26 +000014262Optimizer is allowed to inline memory copy when it's profitable to do so.
14263
14264'``llvm.memmove.element.unordered.atomic``' Intrinsic
14265^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14266
14267Syntax:
14268"""""""
14269
14270This is an overloaded intrinsic. You can use
14271``llvm.memmove.element.unordered.atomic`` on any integer bit width and for
14272different address spaces. Not all targets support all bit widths however.
14273
14274::
14275
14276 declare void @llvm.memmove.element.unordered.atomic.p0i8.p0i8.i32(i8* <dest>,
14277 i8* <src>,
14278 i32 <len>,
14279 i32 <element_size>)
14280 declare void @llvm.memmove.element.unordered.atomic.p0i8.p0i8.i64(i8* <dest>,
14281 i8* <src>,
14282 i64 <len>,
14283 i32 <element_size>)
14284
14285Overview:
14286"""""""""
14287
14288The '``llvm.memmove.element.unordered.atomic.*``' intrinsic is a specialization
14289of the '``llvm.memmove.*``' intrinsic. It differs in that the ``dest`` and
14290``src`` are treated as arrays with elements that are exactly ``element_size``
14291bytes, and the copy between buffers uses a sequence of
14292:ref:`unordered atomic <ordering>` load/store operations that are a positive
14293integer multiple of the ``element_size`` in size.
14294
14295Arguments:
14296""""""""""
14297
14298The first three arguments are the same as they are in the
14299:ref:`@llvm.memmove <int_memmove>` intrinsic, with the added constraint that
14300``len`` is required to be a positive integer multiple of the ``element_size``.
14301If ``len`` is not a positive integer multiple of ``element_size``, then the
14302behaviour of the intrinsic is undefined.
14303
14304``element_size`` must be a compile-time constant positive power of two no
14305greater than a target-specific atomic access size limit.
14306
14307For each of the input pointers the ``align`` parameter attribute must be
14308specified. It must be a power of two no less than the ``element_size``. Caller
14309guarantees that both the source and destination pointers are aligned to that
14310boundary.
14311
14312Semantics:
14313""""""""""
14314
14315The '``llvm.memmove.element.unordered.atomic.*``' intrinsic copies ``len`` bytes
14316of memory from the source location to the destination location. These locations
14317are allowed to overlap. The memory copy is performed as a sequence of load/store
14318operations where each access is guaranteed to be a multiple of ``element_size``
14319bytes wide and aligned at an ``element_size`` boundary.
14320
14321The order of the copy is unspecified. The same value may be read from the source
14322buffer many times, but only one write is issued to the destination buffer per
14323element. It is well defined to have concurrent reads and writes to both source
14324and destination provided those reads and writes are unordered atomic when
14325specified.
14326
14327This intrinsic does not provide any additional ordering guarantees over those
14328provided by a set of unordered loads from the source location and stores to the
14329destination.
14330
14331Lowering:
14332"""""""""
14333
14334In the most general case call to the
14335'``llvm.memmove.element.unordered.atomic.*``' is lowered to a call to the symbol
14336``__llvm_memmove_element_unordered_atomic_*``. Where '*' is replaced with an
14337actual element size.
14338
Daniel Neilson3faabbb2017-06-16 14:43:59 +000014339The optimizer is allowed to inline the memory copy when it's profitable to do so.
Daniel Neilson965613e2017-07-12 21:57:23 +000014340
14341.. _int_memset_element_unordered_atomic:
14342
14343'``llvm.memset.element.unordered.atomic``' Intrinsic
14344^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14345
14346Syntax:
14347"""""""
14348
14349This is an overloaded intrinsic. You can use ``llvm.memset.element.unordered.atomic`` on
14350any integer bit width and for different address spaces. Not all targets
14351support all bit widths however.
14352
14353::
14354
14355 declare void @llvm.memset.element.unordered.atomic.p0i8.i32(i8* <dest>,
14356 i8 <value>,
14357 i32 <len>,
14358 i32 <element_size>)
14359 declare void @llvm.memset.element.unordered.atomic.p0i8.i64(i8* <dest>,
14360 i8 <value>,
14361 i64 <len>,
14362 i32 <element_size>)
14363
14364Overview:
14365"""""""""
14366
14367The '``llvm.memset.element.unordered.atomic.*``' intrinsic is a specialization of the
14368'``llvm.memset.*``' intrinsic. It differs in that the ``dest`` is treated as an array
14369with elements that are exactly ``element_size`` bytes, and the assignment to that array
14370uses uses a sequence of :ref:`unordered atomic <ordering>` store operations
14371that are a positive integer multiple of the ``element_size`` in size.
14372
14373Arguments:
14374""""""""""
14375
14376The first three arguments are the same as they are in the :ref:`@llvm.memset <int_memset>`
14377intrinsic, with the added constraint that ``len`` is required to be a positive integer
14378multiple of the ``element_size``. If ``len`` is not a positive integer multiple of
14379``element_size``, then the behaviour of the intrinsic is undefined.
14380
14381``element_size`` must be a compile-time constant positive power of two no greater than
14382target-specific atomic access size limit.
14383
14384The ``dest`` input pointer must have the ``align`` parameter attribute specified. It
14385must be a power of two no less than the ``element_size``. Caller guarantees that
14386the destination pointer is aligned to that boundary.
14387
14388Semantics:
14389""""""""""
14390
14391The '``llvm.memset.element.unordered.atomic.*``' intrinsic sets the ``len`` bytes of
14392memory starting at the destination location to the given ``value``. The memory is
14393set with a sequence of store operations where each access is guaranteed to be a
14394multiple of ``element_size`` bytes wide and aligned at an ``element_size`` boundary.
14395
14396The order of the assignment is unspecified. Only one write is issued to the
14397destination buffer per element. It is well defined to have concurrent reads and
14398writes to the destination provided those reads and writes are unordered atomic
14399when specified.
14400
14401This intrinsic does not provide any additional ordering guarantees over those
14402provided by a set of unordered stores to the destination.
14403
14404Lowering:
14405"""""""""
14406
14407In the most general case call to the '``llvm.memset.element.unordered.atomic.*``' is
14408lowered to a call to the symbol ``__llvm_memset_element_unordered_atomic_*``. Where '*'
14409is replaced with an actual element size.
14410
14411The optimizer is allowed to inline the memory assignment when it's profitable to do so.
14412