blob: df91c91cd31591b095a38f6ae694e563476337d2 [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
Hans Wennborg2cfcc012018-05-22 10:14:07 +000083 can be used on global values 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
Sanjay Patel85fa9ef2018-03-21 14:15:33 +0000327 floating-point types are supported.
Sean Silvab084af42012-12-07 10:36:55 +0000328 - On *X86-64* only supports up to 10 bit type parameters and 6
Sanjay Patel85fa9ef2018-03-21 14:15:33 +0000329 floating-point parameters.
Sean Silvab084af42012-12-07 10:36:55 +0000330
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
Sean Fertilec70d28b2017-10-26 15:00:26 +0000530.. _runtime_preemption_model:
531
532Runtime Preemption Specifiers
533-----------------------------
534
535Global variables, functions and aliases may have an optional runtime preemption
536specifier. If a preemption specifier isn't given explicitly, then a
537symbol is assumed to be ``dso_preemptable``.
538
539``dso_preemptable``
540 Indicates that the function or variable may be replaced by a symbol from
541 outside the linkage unit at runtime.
542
543``dso_local``
544 The compiler may assume that a function or variable marked as ``dso_local``
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +0000545 will resolve to a symbol within the same linkage unit. Direct access will
Sean Fertilec70d28b2017-10-26 15:00:26 +0000546 be generated even if the definition is not within this compilation unit.
547
Rafael Espindola3bc64d52014-05-26 21:30:40 +0000548.. _namedtypes:
549
Reid Kleckner7c84d1d2014-03-05 02:21:50 +0000550Structure Types
551---------------
Sean Silvab084af42012-12-07 10:36:55 +0000552
Reid Kleckner7c84d1d2014-03-05 02:21:50 +0000553LLVM IR allows you to specify both "identified" and "literal" :ref:`structure
Sean Silvaa1190322015-08-06 22:56:48 +0000554types <t_struct>`. Literal types are uniqued structurally, but identified types
555are never uniqued. An :ref:`opaque structural type <t_opaque>` can also be used
Richard Smith32dbdf62014-07-31 04:25:36 +0000556to forward declare a type that is not yet available.
Reid Kleckner7c84d1d2014-03-05 02:21:50 +0000557
Sean Silva706fba52015-08-06 22:56:24 +0000558An example of an identified structure specification is:
Sean Silvab084af42012-12-07 10:36:55 +0000559
560.. code-block:: llvm
561
562 %mytype = type { %mytype*, i32 }
563
Sean Silvaa1190322015-08-06 22:56:48 +0000564Prior to the LLVM 3.0 release, identified types were structurally uniqued. Only
Reid Kleckner7c84d1d2014-03-05 02:21:50 +0000565literal types are uniqued in recent versions of LLVM.
Sean Silvab084af42012-12-07 10:36:55 +0000566
Sanjoy Dasc6af5ea2016-07-28 23:43:38 +0000567.. _nointptrtype:
568
569Non-Integral Pointer Type
570-------------------------
571
572Note: non-integral pointer types are a work in progress, and they should be
573considered experimental at this time.
574
575LLVM IR optionally allows the frontend to denote pointers in certain address
Sanjoy Das63752e62016-08-10 21:48:24 +0000576spaces as "non-integral" via the :ref:`datalayout string<langref_datalayout>`.
577Non-integral pointer types represent pointers that have an *unspecified* bitwise
578representation; that is, the integral representation may be target dependent or
579unstable (not backed by a fixed integer).
Sanjoy Dasc6af5ea2016-07-28 23:43:38 +0000580
581``inttoptr`` instructions converting integers to non-integral pointer types are
582ill-typed, and so are ``ptrtoint`` instructions converting values of
583non-integral pointer types to integers. Vector versions of said instructions
584are ill-typed as well.
585
Sean Silvab084af42012-12-07 10:36:55 +0000586.. _globalvars:
587
588Global Variables
589----------------
590
591Global variables define regions of memory allocated at compilation time
Rafael Espindola5d1b7452013-10-29 13:44:11 +0000592instead of run-time.
593
Eric Christopher1e61ffd2015-02-19 18:46:25 +0000594Global variable definitions must be initialized.
Rafael Espindola5d1b7452013-10-29 13:44:11 +0000595
596Global variables in other translation units can also be declared, in which
597case they don't have an initializer.
Sean Silvab084af42012-12-07 10:36:55 +0000598
Bob Wilson85b24f22014-06-12 20:40:33 +0000599Either global variable definitions or declarations may have an explicit section
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +0000600to be placed in and may have an optional explicit alignment specified. If there
601is a mismatch between the explicit or inferred section information for the
602variable declaration and its definition the resulting behavior is undefined.
Bob Wilson85b24f22014-06-12 20:40:33 +0000603
Michael Gottesman006039c2013-01-31 05:48:48 +0000604A variable may be defined as a global ``constant``, which indicates that
Sean Silvab084af42012-12-07 10:36:55 +0000605the contents of the variable will **never** be modified (enabling better
606optimization, allowing the global data to be placed in the read-only
607section of an executable, etc). Note that variables that need runtime
Michael Gottesman1cffcf742013-01-31 05:44:04 +0000608initialization cannot be marked ``constant`` as there is a store to the
Sean Silvab084af42012-12-07 10:36:55 +0000609variable.
610
611LLVM explicitly allows *declarations* of global variables to be marked
612constant, even if the final definition of the global is not. This
613capability can be used to enable slightly better optimization of the
614program, but requires the language definition to guarantee that
615optimizations based on the 'constantness' are valid for the translation
616units that do not include the definition.
617
618As SSA values, global variables define pointer values that are in scope
619(i.e. they dominate) all basic blocks in the program. Global variables
620always define a pointer to their "content" type because they describe a
621region of memory, and all memory objects in LLVM are accessed through
622pointers.
623
624Global variables can be marked with ``unnamed_addr`` which indicates
625that the address is not significant, only the content. Constants marked
626like this can be merged with other constants if they have the same
627initializer. Note that a constant with significant address *can* be
628merged with a ``unnamed_addr`` constant, the result being a constant
629whose address is significant.
630
Peter Collingbourne96efdd62016-06-14 21:01:22 +0000631If the ``local_unnamed_addr`` attribute is given, the address is known to
632not be significant within the module.
633
Sean Silvab084af42012-12-07 10:36:55 +0000634A global variable may be declared to reside in a target-specific
635numbered address space. For targets that support them, address spaces
636may affect how optimizations are performed and/or what target
637instructions are used to access the variable. The default address space
638is zero. The address space qualifier must precede any other attributes.
639
640LLVM allows an explicit section to be specified for globals. If the
641target supports it, it will emit globals to the section specified.
David Majnemerdad0a642014-06-27 18:19:56 +0000642Additionally, the global can placed in a comdat if the target has the necessary
643support.
Sean Silvab084af42012-12-07 10:36:55 +0000644
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +0000645External declarations may have an explicit section specified. Section
646information is retained in LLVM IR for targets that make use of this
647information. Attaching section information to an external declaration is an
648assertion that its definition is located in the specified section. If the
649definition is located in a different section, the behavior is undefined.
Erich Keane0343ef82017-08-22 15:30:43 +0000650
Michael Gottesmane743a302013-02-04 03:22:00 +0000651By default, global initializers are optimized by assuming that global
Michael Gottesmanef2bc772013-02-03 09:57:15 +0000652variables defined within the module are not modified from their
Sean Silvaa1190322015-08-06 22:56:48 +0000653initial values before the start of the global initializer. This is
Michael Gottesmanef2bc772013-02-03 09:57:15 +0000654true even for variables potentially accessible from outside the
655module, including those with external linkage or appearing in
Yunzhong Gaof5b769e2013-12-05 18:37:54 +0000656``@llvm.used`` or dllexported variables. This assumption may be suppressed
657by marking the variable with ``externally_initialized``.
Michael Gottesmanef2bc772013-02-03 09:57:15 +0000658
Sean Silvab084af42012-12-07 10:36:55 +0000659An explicit alignment may be specified for a global, which must be a
660power of 2. If not present, or if the alignment is set to zero, the
661alignment of the global is set by the target to whatever it feels
662convenient. If an explicit alignment is specified, the global is forced
663to have exactly that alignment. Targets and optimizers are not allowed
664to over-align the global if the global has an assigned section. In this
665case, the extra alignment could be observable: for example, code could
666assume that the globals are densely packed in their section and try to
667iterate over them as an array, alignment padding would break this
Reid Kleckner15fe7a52014-07-15 01:16:09 +0000668iteration. The maximum alignment is ``1 << 29``.
Sean Silvab084af42012-12-07 10:36:55 +0000669
Javed Absarf3d79042017-05-11 12:28:08 +0000670Globals can also have a :ref:`DLL storage class <dllstorageclass>`,
Sean Fertilec70d28b2017-10-26 15:00:26 +0000671an optional :ref:`runtime preemption specifier <runtime_preemption_model>`,
Javed Absarf3d79042017-05-11 12:28:08 +0000672an optional :ref:`global attributes <glattrs>` and
673an optional list of attached :ref:`metadata <metadata>`.
Nico Rieck7157bb72014-01-14 15:22:47 +0000674
Peter Collingbourne69ba0162015-02-04 00:42:45 +0000675Variables and aliases can have a
Rafael Espindola59f7eba2014-05-28 18:15:43 +0000676:ref:`Thread Local Storage Model <tls_model>`.
677
Nico Rieck7157bb72014-01-14 15:22:47 +0000678Syntax::
679
Sean Fertilec70d28b2017-10-26 15:00:26 +0000680 @<GlobalVarName> = [Linkage] [PreemptionSpecifier] [Visibility]
681 [DLLStorageClass] [ThreadLocal]
Peter Collingbourne96efdd62016-06-14 21:01:22 +0000682 [(unnamed_addr|local_unnamed_addr)] [AddrSpace]
683 [ExternallyInitialized]
Bob Wilson85b24f22014-06-12 20:40:33 +0000684 <global | constant> <Type> [<InitializerConstant>]
Rafael Espindola83a362c2015-01-06 22:55:16 +0000685 [, section "name"] [, comdat [($name)]]
Peter Collingbournecceae7f2016-05-31 23:01:54 +0000686 [, align <Alignment>] (, !name !N)*
Nico Rieck7157bb72014-01-14 15:22:47 +0000687
Sean Silvab084af42012-12-07 10:36:55 +0000688For example, the following defines a global in a numbered address space
689with an initializer, section, and alignment:
690
691.. code-block:: llvm
692
693 @G = addrspace(5) constant float 1.0, section "foo", align 4
694
Rafael Espindola5d1b7452013-10-29 13:44:11 +0000695The following example just declares a global variable
696
697.. code-block:: llvm
698
699 @G = external global i32
700
Sean Silvab084af42012-12-07 10:36:55 +0000701The following example defines a thread-local global with the
702``initialexec`` TLS model:
703
704.. code-block:: llvm
705
706 @G = thread_local(initialexec) global i32 0, align 4
707
708.. _functionstructure:
709
710Functions
711---------
712
713LLVM function definitions consist of the "``define``" keyword, an
Sean Fertilec70d28b2017-10-26 15:00:26 +0000714optional :ref:`linkage type <linkage>`, an optional :ref:`runtime preemption
715specifier <runtime_preemption_model>`, an optional :ref:`visibility
Nico Rieck7157bb72014-01-14 15:22:47 +0000716style <visibility>`, an optional :ref:`DLL storage class <dllstorageclass>`,
717an optional :ref:`calling convention <callingconv>`,
Sean Silvab084af42012-12-07 10:36:55 +0000718an optional ``unnamed_addr`` attribute, a return type, an optional
719:ref:`parameter attribute <paramattrs>` for the return type, a function
720name, a (possibly empty) argument list (each with optional :ref:`parameter
721attributes <paramattrs>`), optional :ref:`function attributes <fnattrs>`,
David Majnemerdad0a642014-06-27 18:19:56 +0000722an optional section, an optional alignment,
723an optional :ref:`comdat <langref_comdats>`,
Peter Collingbourne51d2de72014-12-03 02:08:38 +0000724an optional :ref:`garbage collector name <gc>`, an optional :ref:`prefix <prefixdata>`,
David Majnemer7fddecc2015-06-17 20:52:32 +0000725an optional :ref:`prologue <prologuedata>`,
726an optional :ref:`personality <personalityfn>`,
Peter Collingbourne50108682015-11-06 02:41:02 +0000727an optional list of attached :ref:`metadata <metadata>`,
David Majnemer7fddecc2015-06-17 20:52:32 +0000728an opening curly brace, a list of basic blocks, and a closing curly brace.
Sean Silvab084af42012-12-07 10:36:55 +0000729
730LLVM function declarations consist of the "``declare``" keyword, an
Peter Collingbourne96efdd62016-06-14 21:01:22 +0000731optional :ref:`linkage type <linkage>`, an optional :ref:`visibility style
732<visibility>`, an optional :ref:`DLL storage class <dllstorageclass>`, an
733optional :ref:`calling convention <callingconv>`, an optional ``unnamed_addr``
734or ``local_unnamed_addr`` attribute, a return type, an optional :ref:`parameter
735attribute <paramattrs>` for the return type, a function name, a possibly
736empty list of arguments, an optional alignment, an optional :ref:`garbage
737collector name <gc>`, an optional :ref:`prefix <prefixdata>`, and an optional
738:ref:`prologue <prologuedata>`.
Sean Silvab084af42012-12-07 10:36:55 +0000739
Bill Wendling6822ecb2013-10-27 05:09:12 +0000740A function definition contains a list of basic blocks, forming the CFG (Control
741Flow Graph) for the function. Each basic block may optionally start with a label
742(giving the basic block a symbol table entry), contains a list of instructions,
743and ends with a :ref:`terminator <terminators>` instruction (such as a branch or
744function return). If an explicit label is not provided, a block is assigned an
745implicit numbered label, using the next value from the same counter as used for
746unnamed temporaries (:ref:`see above<identifiers>`). For example, if a function
747entry block does not have an explicit label, it will be assigned label "%0",
748then the first unnamed temporary in that block will be "%1", etc.
Sean Silvab084af42012-12-07 10:36:55 +0000749
750The first basic block in a function is special in two ways: it is
751immediately executed on entrance to the function, and it is not allowed
752to have predecessor basic blocks (i.e. there can not be any branches to
753the entry block of a function). Because the block can have no
754predecessors, it also cannot have any :ref:`PHI nodes <i_phi>`.
755
756LLVM allows an explicit section to be specified for functions. If the
757target supports it, it will emit functions to the section specified.
Eric Christopher1e61ffd2015-02-19 18:46:25 +0000758Additionally, the function can be placed in a COMDAT.
Sean Silvab084af42012-12-07 10:36:55 +0000759
760An explicit alignment may be specified for a function. If not present,
761or if the alignment is set to zero, the alignment of the function is set
762by the target to whatever it feels convenient. If an explicit alignment
763is specified, the function is forced to have at least that much
764alignment. All alignments must be a power of 2.
765
Eric Christopher1e61ffd2015-02-19 18:46:25 +0000766If the ``unnamed_addr`` attribute is given, the address is known to not
Sean Silvab084af42012-12-07 10:36:55 +0000767be significant and two identical functions can be merged.
768
Peter Collingbourne96efdd62016-06-14 21:01:22 +0000769If the ``local_unnamed_addr`` attribute is given, the address is known to
770not be significant within the module.
771
Sean Silvab084af42012-12-07 10:36:55 +0000772Syntax::
773
Sean Fertilec70d28b2017-10-26 15:00:26 +0000774 define [linkage] [PreemptionSpecifier] [visibility] [DLLStorageClass]
Sean Silvab084af42012-12-07 10:36:55 +0000775 [cconv] [ret attrs]
776 <ResultType> @<FunctionName> ([argument list])
Peter Collingbourne96efdd62016-06-14 21:01:22 +0000777 [(unnamed_addr|local_unnamed_addr)] [fn Attrs] [section "name"]
778 [comdat [($name)]] [align N] [gc] [prefix Constant]
779 [prologue Constant] [personality Constant] (!name !N)* { ... }
Sean Silvab084af42012-12-07 10:36:55 +0000780
Sean Silva706fba52015-08-06 22:56:24 +0000781The argument list is a comma separated sequence of arguments where each
782argument is of the following form:
Dan Liew2661dfc2014-08-20 15:06:30 +0000783
784Syntax::
785
786 <type> [parameter Attrs] [name]
787
788
Eli Benderskyfdc529a2013-06-07 19:40:08 +0000789.. _langref_aliases:
790
Sean Silvab084af42012-12-07 10:36:55 +0000791Aliases
792-------
793
Rafael Espindola64c1e182014-06-03 02:41:57 +0000794Aliases, unlike function or variables, don't create any new data. They
795are just a new symbol and metadata for an existing position.
796
797Aliases have a name and an aliasee that is either a global value or a
798constant expression.
799
Nico Rieck7157bb72014-01-14 15:22:47 +0000800Aliases may have an optional :ref:`linkage type <linkage>`, an optional
Sean Fertilec70d28b2017-10-26 15:00:26 +0000801:ref:`runtime preemption specifier <runtime_preemption_model>`, an optional
Rafael Espindola64c1e182014-06-03 02:41:57 +0000802:ref:`visibility style <visibility>`, an optional :ref:`DLL storage class
803<dllstorageclass>` and an optional :ref:`tls model <tls_model>`.
Sean Silvab084af42012-12-07 10:36:55 +0000804
805Syntax::
806
Sean Fertilec70d28b2017-10-26 15:00:26 +0000807 @<Name> = [Linkage] [PreemptionSpecifier] [Visibility] [DLLStorageClass] [ThreadLocal] [(unnamed_addr|local_unnamed_addr)] alias <AliaseeTy>, <AliaseeTy>* @<Aliasee>
Sean Silvab084af42012-12-07 10:36:55 +0000808
Rafael Espindola2fb5bc32014-03-13 23:18:37 +0000809The linkage must be one of ``private``, ``internal``, ``linkonce``, ``weak``,
Rafael Espindola716e7402013-11-01 17:09:14 +0000810``linkonce_odr``, ``weak_odr``, ``external``. Note that some system linkers
Rafael Espindola64c1e182014-06-03 02:41:57 +0000811might not correctly handle dropping a weak symbol that is aliased.
Rafael Espindola78527052013-10-06 15:10:43 +0000812
Eric Christopher1e61ffd2015-02-19 18:46:25 +0000813Aliases that are not ``unnamed_addr`` are guaranteed to have the same address as
Rafael Espindola42a4c9f2014-06-06 01:20:28 +0000814the aliasee expression. ``unnamed_addr`` ones are only guaranteed to point
815to the same content.
Rafael Espindolaf3336bc2014-03-12 20:15:49 +0000816
Peter Collingbourne96efdd62016-06-14 21:01:22 +0000817If the ``local_unnamed_addr`` attribute is given, the address is known to
818not be significant within the module.
819
Rafael Espindola64c1e182014-06-03 02:41:57 +0000820Since aliases are only a second name, some restrictions apply, of which
821some can only be checked when producing an object file:
Rafael Espindolaf3336bc2014-03-12 20:15:49 +0000822
Rafael Espindola64c1e182014-06-03 02:41:57 +0000823* The expression defining the aliasee must be computable at assembly
824 time. Since it is just a name, no relocations can be used.
825
826* No alias in the expression can be weak as the possibility of the
827 intermediate alias being overridden cannot be represented in an
828 object file.
829
830* No global value in the expression can be a declaration, since that
831 would require a relocation, which is not possible.
Rafael Espindola24a669d2014-03-27 15:26:56 +0000832
Dmitry Polukhina1feff72016-04-07 12:32:19 +0000833.. _langref_ifunc:
834
835IFuncs
836-------
837
838IFuncs, like as aliases, don't create any new data or func. They are just a new
839symbol that dynamic linker resolves at runtime by calling a resolver function.
840
841IFuncs have a name and a resolver that is a function called by dynamic linker
842that returns address of another function associated with the name.
843
844IFunc may have an optional :ref:`linkage type <linkage>` and an optional
845:ref:`visibility style <visibility>`.
846
847Syntax::
848
849 @<Name> = [Linkage] [Visibility] ifunc <IFuncTy>, <ResolverTy>* @<Resolver>
850
851
David Majnemerdad0a642014-06-27 18:19:56 +0000852.. _langref_comdats:
853
854Comdats
855-------
856
857Comdat IR provides access to COFF and ELF object file COMDAT functionality.
858
Sean Silvaa1190322015-08-06 22:56:48 +0000859Comdats have a name which represents the COMDAT key. All global objects that
David Majnemerdad0a642014-06-27 18:19:56 +0000860specify this key will only end up in the final object file if the linker chooses
Sean Silvaa1190322015-08-06 22:56:48 +0000861that key over some other key. Aliases are placed in the same COMDAT that their
David Majnemerdad0a642014-06-27 18:19:56 +0000862aliasee computes to, if any.
863
864Comdats have a selection kind to provide input on how the linker should
865choose between keys in two different object files.
866
867Syntax::
868
869 $<Name> = comdat SelectionKind
870
871The selection kind must be one of the following:
872
873``any``
874 The linker may choose any COMDAT key, the choice is arbitrary.
875``exactmatch``
876 The linker may choose any COMDAT key but the sections must contain the
877 same data.
878``largest``
879 The linker will choose the section containing the largest COMDAT key.
880``noduplicates``
881 The linker requires that only section with this COMDAT key exist.
882``samesize``
883 The linker may choose any COMDAT key but the sections must contain the
884 same amount of data.
885
Sam Cleggea7cace2018-01-09 23:43:14 +0000886Note that the Mach-O platform doesn't support COMDATs, and ELF and WebAssembly
887only support ``any`` as a selection kind.
David Majnemerdad0a642014-06-27 18:19:56 +0000888
889Here is an example of a COMDAT group where a function will only be selected if
890the COMDAT key's section is the largest:
891
Renato Golin124f2592016-07-20 12:16:38 +0000892.. code-block:: text
David Majnemerdad0a642014-06-27 18:19:56 +0000893
894 $foo = comdat largest
Rafael Espindola83a362c2015-01-06 22:55:16 +0000895 @foo = global i32 2, comdat($foo)
David Majnemerdad0a642014-06-27 18:19:56 +0000896
Rafael Espindola83a362c2015-01-06 22:55:16 +0000897 define void @bar() comdat($foo) {
David Majnemerdad0a642014-06-27 18:19:56 +0000898 ret void
899 }
900
Rafael Espindola83a362c2015-01-06 22:55:16 +0000901As a syntactic sugar the ``$name`` can be omitted if the name is the same as
902the global name:
903
Renato Golin124f2592016-07-20 12:16:38 +0000904.. code-block:: text
Rafael Espindola83a362c2015-01-06 22:55:16 +0000905
906 $foo = comdat any
907 @foo = global i32 2, comdat
908
909
David Majnemerdad0a642014-06-27 18:19:56 +0000910In a COFF object file, this will create a COMDAT section with selection kind
911``IMAGE_COMDAT_SELECT_LARGEST`` containing the contents of the ``@foo`` symbol
912and another COMDAT section with selection kind
913``IMAGE_COMDAT_SELECT_ASSOCIATIVE`` which is associated with the first COMDAT
Hans Wennborg0def0662014-09-10 17:05:08 +0000914section and contains the contents of the ``@bar`` symbol.
David Majnemerdad0a642014-06-27 18:19:56 +0000915
916There are some restrictions on the properties of the global object.
917It, or an alias to it, must have the same name as the COMDAT group when
918targeting COFF.
919The contents and size of this object may be used during link-time to determine
920which COMDAT groups get selected depending on the selection kind.
921Because the name of the object must match the name of the COMDAT group, the
922linkage of the global object must not be local; local symbols can get renamed
923if a collision occurs in the symbol table.
924
925The combined use of COMDATS and section attributes may yield surprising results.
926For example:
927
Renato Golin124f2592016-07-20 12:16:38 +0000928.. code-block:: text
David Majnemerdad0a642014-06-27 18:19:56 +0000929
930 $foo = comdat any
931 $bar = comdat any
Rafael Espindola83a362c2015-01-06 22:55:16 +0000932 @g1 = global i32 42, section "sec", comdat($foo)
933 @g2 = global i32 42, section "sec", comdat($bar)
David Majnemerdad0a642014-06-27 18:19:56 +0000934
935From the object file perspective, this requires the creation of two sections
Sean Silvaa1190322015-08-06 22:56:48 +0000936with the same name. This is necessary because both globals belong to different
David Majnemerdad0a642014-06-27 18:19:56 +0000937COMDAT groups and COMDATs, at the object file level, are represented by
938sections.
939
Peter Collingbourne1feef2e2015-06-30 19:10:31 +0000940Note that certain IR constructs like global variables and functions may
941create COMDATs in the object file in addition to any which are specified using
Sean Silvaa1190322015-08-06 22:56:48 +0000942COMDAT IR. This arises when the code generator is configured to emit globals
Peter Collingbourne1feef2e2015-06-30 19:10:31 +0000943in individual sections (e.g. when `-data-sections` or `-function-sections`
944is supplied to `llc`).
David Majnemerdad0a642014-06-27 18:19:56 +0000945
Sean Silvab084af42012-12-07 10:36:55 +0000946.. _namedmetadatastructure:
947
948Named Metadata
949--------------
950
951Named metadata is a collection of metadata. :ref:`Metadata
952nodes <metadata>` (but not metadata strings) are the only valid
953operands for a named metadata.
954
Filipe Cabecinhas62431b12015-06-02 21:25:08 +0000955#. Named metadata are represented as a string of characters with the
956 metadata prefix. The rules for metadata names are the same as for
957 identifiers, but quoted names are not allowed. ``"\xx"`` type escapes
958 are still valid, which allows any character to be part of a name.
959
Sean Silvab084af42012-12-07 10:36:55 +0000960Syntax::
961
962 ; Some unnamed metadata nodes, which are referenced by the named metadata.
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +0000963 !0 = !{!"zero"}
964 !1 = !{!"one"}
965 !2 = !{!"two"}
Sean Silvab084af42012-12-07 10:36:55 +0000966 ; A named metadata.
967 !name = !{!0, !1, !2}
968
969.. _paramattrs:
970
971Parameter Attributes
972--------------------
973
974The return type and each parameter of a function type may have a set of
975*parameter attributes* associated with them. Parameter attributes are
976used to communicate additional information about the result or
977parameters of a function. Parameter attributes are considered to be part
978of the function, not of the function type, so functions with different
979parameter attributes can have the same function type.
980
981Parameter attributes are simple keywords that follow the type specified.
982If multiple parameter attributes are needed, they are space separated.
983For example:
984
985.. code-block:: llvm
986
987 declare i32 @printf(i8* noalias nocapture, ...)
988 declare i32 @atoi(i8 zeroext)
989 declare signext i8 @returns_signed_char()
990
991Note that any attributes for the function result (``nounwind``,
992``readonly``) come immediately after the argument list.
993
994Currently, only the following parameter attributes are defined:
995
996``zeroext``
997 This indicates to the code generator that the parameter or return
998 value should be zero-extended to the extent required by the target's
Hans Wennborg850ec6c2016-02-08 19:34:30 +0000999 ABI by the caller (for a parameter) or the callee (for a return value).
Sean Silvab084af42012-12-07 10:36:55 +00001000``signext``
1001 This indicates to the code generator that the parameter or return
1002 value should be sign-extended to the extent required by the target's
1003 ABI (which is usually 32-bits) by the caller (for a parameter) or
1004 the callee (for a return value).
1005``inreg``
1006 This indicates that this parameter or return value should be treated
Sean Silva706fba52015-08-06 22:56:24 +00001007 in a special target-dependent fashion while emitting code for
Sean Silvab084af42012-12-07 10:36:55 +00001008 a function call or return (usually, by putting it in a register as
1009 opposed to memory, though some targets use it to distinguish between
1010 two different kinds of registers). Use of this attribute is
1011 target-specific.
1012``byval``
1013 This indicates that the pointer parameter should really be passed by
1014 value to the function. The attribute implies that a hidden copy of
1015 the pointee is made between the caller and the callee, so the callee
1016 is unable to modify the value in the caller. This attribute is only
1017 valid on LLVM pointer arguments. It is generally used to pass
1018 structs and arrays by value, but is also valid on pointers to
1019 scalars. The copy is considered to belong to the caller not the
1020 callee (for example, ``readonly`` functions should not write to
1021 ``byval`` parameters). This is not a valid attribute for return
1022 values.
1023
1024 The byval attribute also supports specifying an alignment with the
1025 align attribute. It indicates the alignment of the stack slot to
1026 form and the known alignment of the pointer specified to the call
1027 site. If the alignment is not specified, then the code generator
1028 makes a target-specific assumption.
1029
Reid Klecknera534a382013-12-19 02:14:12 +00001030.. _attr_inalloca:
1031
1032``inalloca``
1033
Reid Kleckner60d3a832014-01-16 22:59:24 +00001034 The ``inalloca`` argument attribute allows the caller to take the
Sean Silvaa1190322015-08-06 22:56:48 +00001035 address of outgoing stack arguments. An ``inalloca`` argument must
Reid Kleckner436c42e2014-01-17 23:58:17 +00001036 be a pointer to stack memory produced by an ``alloca`` instruction.
1037 The alloca, or argument allocation, must also be tagged with the
Sean Silvaa1190322015-08-06 22:56:48 +00001038 inalloca keyword. Only the last argument may have the ``inalloca``
Reid Kleckner436c42e2014-01-17 23:58:17 +00001039 attribute, and that argument is guaranteed to be passed in memory.
Reid Klecknera534a382013-12-19 02:14:12 +00001040
Reid Kleckner436c42e2014-01-17 23:58:17 +00001041 An argument allocation may be used by a call at most once because
Sean Silvaa1190322015-08-06 22:56:48 +00001042 the call may deallocate it. The ``inalloca`` attribute cannot be
Reid Kleckner436c42e2014-01-17 23:58:17 +00001043 used in conjunction with other attributes that affect argument
Sean Silvaa1190322015-08-06 22:56:48 +00001044 storage, like ``inreg``, ``nest``, ``sret``, or ``byval``. The
Reid Klecknerf5b76512014-01-31 23:50:57 +00001045 ``inalloca`` attribute also disables LLVM's implicit lowering of
1046 large aggregate return values, which means that frontend authors
1047 must lower them with ``sret`` pointers.
Reid Klecknera534a382013-12-19 02:14:12 +00001048
Reid Kleckner60d3a832014-01-16 22:59:24 +00001049 When the call site is reached, the argument allocation must have
1050 been the most recent stack allocation that is still live, or the
Sean Silvaa1190322015-08-06 22:56:48 +00001051 results are undefined. It is possible to allocate additional stack
Reid Kleckner60d3a832014-01-16 22:59:24 +00001052 space after an argument allocation and before its call site, but it
1053 must be cleared off with :ref:`llvm.stackrestore
1054 <int_stackrestore>`.
Reid Klecknera534a382013-12-19 02:14:12 +00001055
1056 See :doc:`InAlloca` for more information on how to use this
1057 attribute.
1058
Sean Silvab084af42012-12-07 10:36:55 +00001059``sret``
1060 This indicates that the pointer parameter specifies the address of a
1061 structure that is the return value of the function in the source
1062 program. This pointer must be guaranteed by the caller to be valid:
Reid Kleckner1361c0c2016-09-08 15:45:27 +00001063 loads and stores to the structure may be assumed by the callee not
1064 to trap and to be properly aligned. This is not a valid attribute
1065 for return values.
Sean Silva1703e702014-04-08 21:06:22 +00001066
Daniel Neilson1e687242018-01-19 17:13:12 +00001067.. _attr_align:
Elena Demikhovsky945b7e52018-02-14 06:58:08 +00001068
Hal Finkelccc70902014-07-22 16:58:55 +00001069``align <n>``
1070 This indicates that the pointer value may be assumed by the optimizer to
1071 have the specified alignment.
1072
1073 Note that this attribute has additional semantics when combined with the
1074 ``byval`` attribute.
1075
Sean Silva1703e702014-04-08 21:06:22 +00001076.. _noalias:
1077
Sean Silvab084af42012-12-07 10:36:55 +00001078``noalias``
Hal Finkel12d36302014-11-21 02:22:46 +00001079 This indicates that objects accessed via pointer values
1080 :ref:`based <pointeraliasing>` on the argument or return value are not also
1081 accessed, during the execution of the function, via pointer values not
1082 *based* on the argument or return value. The attribute on a return value
1083 also has additional semantics described below. The caller shares the
1084 responsibility with the callee for ensuring that these requirements are met.
1085 For further details, please see the discussion of the NoAlias response in
1086 :ref:`alias analysis <Must, May, or No>`.
Sean Silvab084af42012-12-07 10:36:55 +00001087
1088 Note that this definition of ``noalias`` is intentionally similar
Hal Finkel12d36302014-11-21 02:22:46 +00001089 to the definition of ``restrict`` in C99 for function arguments.
Sean Silvab084af42012-12-07 10:36:55 +00001090
1091 For function return values, C99's ``restrict`` is not meaningful,
Hal Finkel12d36302014-11-21 02:22:46 +00001092 while LLVM's ``noalias`` is. Furthermore, the semantics of the ``noalias``
1093 attribute on return values are stronger than the semantics of the attribute
1094 when used on function arguments. On function return values, the ``noalias``
1095 attribute indicates that the function acts like a system memory allocation
1096 function, returning a pointer to allocated storage disjoint from the
1097 storage for any other object accessible to the caller.
1098
Sean Silvab084af42012-12-07 10:36:55 +00001099``nocapture``
1100 This indicates that the callee does not make any copies of the
1101 pointer that outlive the callee itself. This is not a valid
David Majnemer7f324202016-05-26 17:36:22 +00001102 attribute for return values. Addresses used in volatile operations
1103 are considered to be captured.
Sean Silvab084af42012-12-07 10:36:55 +00001104
1105.. _nest:
1106
1107``nest``
1108 This indicates that the pointer parameter can be excised using the
1109 :ref:`trampoline intrinsics <int_trampoline>`. This is not a valid
Stephen Linb8bd2322013-04-20 05:14:40 +00001110 attribute for return values and can only be applied to one parameter.
1111
1112``returned``
Stephen Linfec5b0b2013-06-20 21:55:10 +00001113 This indicates that the function always returns the argument as its return
Hal Finkel3b66caa2016-07-10 21:52:39 +00001114 value. This is a hint to the optimizer and code generator used when
1115 generating the caller, allowing value propagation, tail call optimization,
1116 and omission of register saves and restores in some cases; it is not
1117 checked or enforced when generating the callee. The parameter and the
1118 function return type must be valid operands for the
1119 :ref:`bitcast instruction <i_bitcast>`. This is not a valid attribute for
1120 return values and can only be applied to one parameter.
Sean Silvab084af42012-12-07 10:36:55 +00001121
Nick Lewyckyd52b1522014-05-20 01:23:40 +00001122``nonnull``
1123 This indicates that the parameter or return pointer is not null. This
1124 attribute may only be applied to pointer typed parameters. This is not
1125 checked or enforced by LLVM, the caller must ensure that the pointer
Mehdi Amini4a121fa2015-03-14 22:04:06 +00001126 passed in is non-null, or the callee must ensure that the returned pointer
Nick Lewyckyd52b1522014-05-20 01:23:40 +00001127 is non-null.
1128
Hal Finkelb0407ba2014-07-18 15:51:28 +00001129``dereferenceable(<n>)``
1130 This indicates that the parameter or return pointer is dereferenceable. This
1131 attribute may only be applied to pointer typed parameters. A pointer that
1132 is dereferenceable can be loaded from speculatively without a risk of
1133 trapping. The number of bytes known to be dereferenceable must be provided
1134 in parentheses. It is legal for the number of bytes to be less than the
1135 size of the pointee type. The ``nonnull`` attribute does not imply
1136 dereferenceability (consider a pointer to one element past the end of an
1137 array), however ``dereferenceable(<n>)`` does imply ``nonnull`` in
1138 ``addrspace(0)`` (which is the default address space).
1139
Sanjoy Das31ea6d12015-04-16 20:29:50 +00001140``dereferenceable_or_null(<n>)``
1141 This indicates that the parameter or return value isn't both
1142 non-null and non-dereferenceable (up to ``<n>`` bytes) at the same
Sean Silvaa1190322015-08-06 22:56:48 +00001143 time. All non-null pointers tagged with
Sanjoy Das31ea6d12015-04-16 20:29:50 +00001144 ``dereferenceable_or_null(<n>)`` are ``dereferenceable(<n>)``.
1145 For address space 0 ``dereferenceable_or_null(<n>)`` implies that
1146 a pointer is exactly one of ``dereferenceable(<n>)`` or ``null``,
1147 and in other address spaces ``dereferenceable_or_null(<n>)``
1148 implies that a pointer is at least one of ``dereferenceable(<n>)``
1149 or ``null`` (i.e. it may be both ``null`` and
Sean Silvaa1190322015-08-06 22:56:48 +00001150 ``dereferenceable(<n>)``). This attribute may only be applied to
Sanjoy Das31ea6d12015-04-16 20:29:50 +00001151 pointer typed parameters.
1152
Manman Renf46262e2016-03-29 17:37:21 +00001153``swiftself``
1154 This indicates that the parameter is the self/context parameter. This is not
1155 a valid attribute for return values and can only be applied to one
1156 parameter.
1157
Manman Ren9bfd0d02016-04-01 21:41:15 +00001158``swifterror``
1159 This attribute is motivated to model and optimize Swift error handling. It
1160 can be applied to a parameter with pointer to pointer type or a
1161 pointer-sized alloca. At the call site, the actual argument that corresponds
Arnold Schwaighofer6c57f4f2016-09-10 19:42:53 +00001162 to a ``swifterror`` parameter has to come from a ``swifterror`` alloca or
1163 the ``swifterror`` parameter of the caller. A ``swifterror`` value (either
1164 the parameter or the alloca) can only be loaded and stored from, or used as
1165 a ``swifterror`` argument. This is not a valid attribute for return values
1166 and can only be applied to one parameter.
Manman Ren9bfd0d02016-04-01 21:41:15 +00001167
1168 These constraints allow the calling convention to optimize access to
1169 ``swifterror`` variables by associating them with a specific register at
1170 call boundaries rather than placing them in memory. Since this does change
1171 the calling convention, a function which uses the ``swifterror`` attribute
1172 on a parameter is not ABI-compatible with one which does not.
1173
1174 These constraints also allow LLVM to assume that a ``swifterror`` argument
1175 does not alias any other memory visible within a function and that a
1176 ``swifterror`` alloca passed as an argument does not escape.
1177
Sean Silvab084af42012-12-07 10:36:55 +00001178.. _gc:
1179
Philip Reamesf80bbff2015-02-25 23:45:20 +00001180Garbage Collector Strategy Names
1181--------------------------------
Sean Silvab084af42012-12-07 10:36:55 +00001182
Philip Reamesf80bbff2015-02-25 23:45:20 +00001183Each function may specify a garbage collector strategy name, which is simply a
Sean Silvab084af42012-12-07 10:36:55 +00001184string:
1185
1186.. code-block:: llvm
1187
1188 define void @f() gc "name" { ... }
1189
Mehdi Amini4a121fa2015-03-14 22:04:06 +00001190The supported values of *name* includes those :ref:`built in to LLVM
Sean Silvaa1190322015-08-06 22:56:48 +00001191<builtin-gc-strategies>` and any provided by loaded plugins. Specifying a GC
Mehdi Amini4a121fa2015-03-14 22:04:06 +00001192strategy will cause the compiler to alter its output in order to support the
Sean Silvaa1190322015-08-06 22:56:48 +00001193named garbage collection algorithm. Note that LLVM itself does not contain a
Philip Reamesf80bbff2015-02-25 23:45:20 +00001194garbage collector, this functionality is restricted to generating machine code
Mehdi Amini4a121fa2015-03-14 22:04:06 +00001195which can interoperate with a collector provided externally.
Sean Silvab084af42012-12-07 10:36:55 +00001196
Peter Collingbourne3fa50f92013-09-16 01:08:15 +00001197.. _prefixdata:
1198
1199Prefix Data
1200-----------
1201
Peter Collingbourne51d2de72014-12-03 02:08:38 +00001202Prefix data is data associated with a function which the code
1203generator will emit immediately before the function's entrypoint.
1204The purpose of this feature is to allow frontends to associate
1205language-specific runtime metadata with specific functions and make it
1206available through the function pointer while still allowing the
1207function pointer to be called.
Peter Collingbourne3fa50f92013-09-16 01:08:15 +00001208
Peter Collingbourne51d2de72014-12-03 02:08:38 +00001209To access the data for a given function, a program may bitcast the
1210function pointer to a pointer to the constant's type and dereference
Sean Silvaa1190322015-08-06 22:56:48 +00001211index -1. This implies that the IR symbol points just past the end of
Peter Collingbourne51d2de72014-12-03 02:08:38 +00001212the prefix data. For instance, take the example of a function annotated
1213with a single ``i32``,
1214
1215.. code-block:: llvm
1216
1217 define void @f() prefix i32 123 { ... }
1218
1219The prefix data can be referenced as,
1220
1221.. code-block:: llvm
1222
David Blaikie16a97eb2015-03-04 22:02:58 +00001223 %0 = bitcast void* () @f to i32*
1224 %a = getelementptr inbounds i32, i32* %0, i32 -1
David Blaikiec7aabbb2015-03-04 22:06:14 +00001225 %b = load i32, i32* %a
Peter Collingbourne51d2de72014-12-03 02:08:38 +00001226
1227Prefix data is laid out as if it were an initializer for a global variable
Sean Silvaa1190322015-08-06 22:56:48 +00001228of the prefix data's type. The function will be placed such that the
Peter Collingbourne51d2de72014-12-03 02:08:38 +00001229beginning of the prefix data is aligned. This means that if the size
1230of the prefix data is not a multiple of the alignment size, the
1231function's entrypoint will not be aligned. If alignment of the
1232function's entrypoint is desired, padding must be added to the prefix
1233data.
1234
Sean Silvaa1190322015-08-06 22:56:48 +00001235A function may have prefix data but no body. This has similar semantics
Peter Collingbourne51d2de72014-12-03 02:08:38 +00001236to the ``available_externally`` linkage in that the data may be used by the
1237optimizers but will not be emitted in the object file.
1238
1239.. _prologuedata:
1240
1241Prologue Data
1242-------------
1243
1244The ``prologue`` attribute allows arbitrary code (encoded as bytes) to
1245be inserted prior to the function body. This can be used for enabling
1246function hot-patching and instrumentation.
1247
1248To maintain the semantics of ordinary function calls, the prologue data must
Sean Silvaa1190322015-08-06 22:56:48 +00001249have a particular format. Specifically, it must begin with a sequence of
Peter Collingbourne3fa50f92013-09-16 01:08:15 +00001250bytes which decode to a sequence of machine instructions, valid for the
1251module's target, which transfer control to the point immediately succeeding
Sean Silvaa1190322015-08-06 22:56:48 +00001252the prologue data, without performing any other visible action. This allows
Peter Collingbourne3fa50f92013-09-16 01:08:15 +00001253the inliner and other passes to reason about the semantics of the function
Sean Silvaa1190322015-08-06 22:56:48 +00001254definition without needing to reason about the prologue data. Obviously this
Peter Collingbourne51d2de72014-12-03 02:08:38 +00001255makes the format of the prologue data highly target dependent.
Peter Collingbourne3fa50f92013-09-16 01:08:15 +00001256
Peter Collingbourne51d2de72014-12-03 02:08:38 +00001257A trivial example of valid prologue data for the x86 architecture is ``i8 144``,
Peter Collingbourne3fa50f92013-09-16 01:08:15 +00001258which encodes the ``nop`` instruction:
1259
Renato Golin124f2592016-07-20 12:16:38 +00001260.. code-block:: text
Peter Collingbourne3fa50f92013-09-16 01:08:15 +00001261
Peter Collingbourne51d2de72014-12-03 02:08:38 +00001262 define void @f() prologue i8 144 { ... }
Peter Collingbourne3fa50f92013-09-16 01:08:15 +00001263
Peter Collingbourne51d2de72014-12-03 02:08:38 +00001264Generally prologue data can be formed by encoding a relative branch instruction
1265which skips the metadata, as in this example of valid prologue data for the
Peter Collingbourne3fa50f92013-09-16 01:08:15 +00001266x86_64 architecture, where the first two bytes encode ``jmp .+10``:
1267
Renato Golin124f2592016-07-20 12:16:38 +00001268.. code-block:: text
Peter Collingbourne3fa50f92013-09-16 01:08:15 +00001269
1270 %0 = type <{ i8, i8, i8* }>
1271
Peter Collingbourne51d2de72014-12-03 02:08:38 +00001272 define void @f() prologue %0 <{ i8 235, i8 8, i8* @md}> { ... }
Peter Collingbourne3fa50f92013-09-16 01:08:15 +00001273
Sean Silvaa1190322015-08-06 22:56:48 +00001274A function may have prologue data but no body. This has similar semantics
Peter Collingbourne3fa50f92013-09-16 01:08:15 +00001275to the ``available_externally`` linkage in that the data may be used by the
1276optimizers but will not be emitted in the object file.
1277
David Majnemer7fddecc2015-06-17 20:52:32 +00001278.. _personalityfn:
1279
1280Personality Function
David Majnemerc5ad8a92015-06-17 21:21:16 +00001281--------------------
David Majnemer7fddecc2015-06-17 20:52:32 +00001282
1283The ``personality`` attribute permits functions to specify what function
1284to use for exception handling.
1285
Bill Wendling63b88192013-02-06 06:52:58 +00001286.. _attrgrp:
1287
1288Attribute Groups
1289----------------
1290
1291Attribute groups are groups of attributes that are referenced by objects within
1292the IR. They are important for keeping ``.ll`` files readable, because a lot of
1293functions will use the same set of attributes. In the degenerative case of a
1294``.ll`` file that corresponds to a single ``.c`` file, the single attribute
1295group will capture the important command line flags used to build that file.
1296
1297An attribute group is a module-level object. To use an attribute group, an
1298object references the attribute group's ID (e.g. ``#37``). An object may refer
1299to more than one attribute group. In that situation, the attributes from the
1300different groups are merged.
1301
1302Here is an example of attribute groups for a function that should always be
1303inlined, has a stack alignment of 4, and which shouldn't use SSE instructions:
1304
1305.. code-block:: llvm
1306
1307 ; Target-independent attributes:
Eli Bendersky97ad9242013-04-18 16:11:44 +00001308 attributes #0 = { alwaysinline alignstack=4 }
Bill Wendling63b88192013-02-06 06:52:58 +00001309
1310 ; Target-dependent attributes:
Eli Bendersky97ad9242013-04-18 16:11:44 +00001311 attributes #1 = { "no-sse" }
Bill Wendling63b88192013-02-06 06:52:58 +00001312
1313 ; Function @f has attributes: alwaysinline, alignstack=4, and "no-sse".
1314 define void @f() #0 #1 { ... }
1315
Sean Silvab084af42012-12-07 10:36:55 +00001316.. _fnattrs:
1317
1318Function Attributes
1319-------------------
1320
1321Function attributes are set to communicate additional information about
1322a function. Function attributes are considered to be part of the
1323function, not of the function type, so functions with different function
1324attributes can have the same function type.
1325
1326Function attributes are simple keywords that follow the type specified.
1327If multiple attributes are needed, they are space separated. For
1328example:
1329
1330.. code-block:: llvm
1331
1332 define void @f() noinline { ... }
1333 define void @f() alwaysinline { ... }
1334 define void @f() alwaysinline optsize { ... }
1335 define void @f() optsize { ... }
1336
Sean Silvab084af42012-12-07 10:36:55 +00001337``alignstack(<n>)``
1338 This attribute indicates that, when emitting the prologue and
1339 epilogue, the backend should forcibly align the stack pointer.
1340 Specify the desired alignment, which must be a power of two, in
1341 parentheses.
George Burgess IV278199f2016-04-12 01:05:35 +00001342``allocsize(<EltSizeParam>[, <NumEltsParam>])``
1343 This attribute indicates that the annotated function will always return at
1344 least a given number of bytes (or null). Its arguments are zero-indexed
1345 parameter numbers; if one argument is provided, then it's assumed that at
1346 least ``CallSite.Args[EltSizeParam]`` bytes will be available at the
1347 returned pointer. If two are provided, then it's assumed that
1348 ``CallSite.Args[EltSizeParam] * CallSite.Args[NumEltsParam]`` bytes are
1349 available. The referenced parameters must be integer types. No assumptions
1350 are made about the contents of the returned block of memory.
Sean Silvab084af42012-12-07 10:36:55 +00001351``alwaysinline``
1352 This attribute indicates that the inliner should attempt to inline
1353 this function into callers whenever possible, ignoring any active
1354 inlining size threshold for this caller.
Michael Gottesman41748d72013-06-27 00:25:01 +00001355``builtin``
1356 This indicates that the callee function at a call site should be
1357 recognized as a built-in function, even though the function's declaration
Michael Gottesman3a6a9672013-07-02 21:32:56 +00001358 uses the ``nobuiltin`` attribute. This is only valid at call sites for
Richard Smith32dbdf62014-07-31 04:25:36 +00001359 direct calls to functions that are declared with the ``nobuiltin``
Michael Gottesman41748d72013-06-27 00:25:01 +00001360 attribute.
Michael Gottesman296adb82013-06-27 22:48:08 +00001361``cold``
1362 This attribute indicates that this function is rarely called. When
1363 computing edge weights, basic blocks post-dominated by a cold
1364 function call are also considered to be cold; and, thus, given low
1365 weight.
Owen Anderson85fa7d52015-05-26 23:48:40 +00001366``convergent``
Justin Lebard5fb6952016-02-09 23:03:17 +00001367 In some parallel execution models, there exist operations that cannot be
1368 made control-dependent on any additional values. We call such operations
Justin Lebar58535b12016-02-17 17:46:41 +00001369 ``convergent``, and mark them with this attribute.
Justin Lebard5fb6952016-02-09 23:03:17 +00001370
Justin Lebar58535b12016-02-17 17:46:41 +00001371 The ``convergent`` attribute may appear on functions or call/invoke
1372 instructions. When it appears on a function, it indicates that calls to
1373 this function should not be made control-dependent on additional values.
Justin Bognera4635372016-07-06 20:02:45 +00001374 For example, the intrinsic ``llvm.nvvm.barrier0`` is ``convergent``, so
Justin Lebard5fb6952016-02-09 23:03:17 +00001375 calls to this intrinsic cannot be made control-dependent on additional
Justin Lebar58535b12016-02-17 17:46:41 +00001376 values.
Justin Lebard5fb6952016-02-09 23:03:17 +00001377
Justin Lebar58535b12016-02-17 17:46:41 +00001378 When it appears on a call/invoke, the ``convergent`` attribute indicates
1379 that we should treat the call as though we're calling a convergent
1380 function. This is particularly useful on indirect calls; without this we
1381 may treat such calls as though the target is non-convergent.
1382
1383 The optimizer may remove the ``convergent`` attribute on functions when it
1384 can prove that the function does not execute any convergent operations.
1385 Similarly, the optimizer may remove ``convergent`` on calls/invokes when it
1386 can prove that the call/invoke cannot call a convergent function.
Vaivaswatha Nagarajfb3f4902015-12-16 16:16:19 +00001387``inaccessiblememonly``
1388 This attribute indicates that the function may only access memory that
1389 is not accessible by the module being compiled. This is a weaker form
1390 of ``readnone``.
1391``inaccessiblemem_or_argmemonly``
1392 This attribute indicates that the function may only access memory that is
1393 either not accessible by the module being compiled, or is pointed to
1394 by its pointer arguments. This is a weaker form of ``argmemonly``
Sean Silvab084af42012-12-07 10:36:55 +00001395``inlinehint``
1396 This attribute indicates that the source code contained a hint that
1397 inlining this function is desirable (such as the "inline" keyword in
1398 C/C++). It is just a hint; it imposes no requirements on the
1399 inliner.
Tom Roeder44cb65f2014-06-05 19:29:43 +00001400``jumptable``
1401 This attribute indicates that the function should be added to a
1402 jump-instruction table at code-generation time, and that all address-taken
1403 references to this function should be replaced with a reference to the
1404 appropriate jump-instruction-table function pointer. Note that this creates
1405 a new pointer for the original function, which means that code that depends
1406 on function-pointer identity can break. So, any function annotated with
1407 ``jumptable`` must also be ``unnamed_addr``.
Andrea Di Biagio9b5d23b2013-08-09 18:42:18 +00001408``minsize``
1409 This attribute suggests that optimization passes and code generator
1410 passes make choices that keep the code size of this function as small
Andrew Trickd4d1d9c2013-10-31 17:18:07 +00001411 as possible and perform optimizations that may sacrifice runtime
Andrea Di Biagio9b5d23b2013-08-09 18:42:18 +00001412 performance in order to minimize the size of the generated code.
Sean Silvab084af42012-12-07 10:36:55 +00001413``naked``
1414 This attribute disables prologue / epilogue emission for the
1415 function. This can have very system-specific consequences.
Sumanth Gundapaneni6af104e2017-07-28 22:26:22 +00001416``no-jump-tables``
1417 When this attribute is set to true, the jump tables and lookup tables that
1418 can be generated from a switch case lowering are disabled.
Eli Bendersky97ad9242013-04-18 16:11:44 +00001419``nobuiltin``
Michael Gottesman41748d72013-06-27 00:25:01 +00001420 This indicates that the callee function at a call site is not recognized as
1421 a built-in function. LLVM will retain the original call and not replace it
1422 with equivalent code based on the semantics of the built-in function, unless
1423 the call site uses the ``builtin`` attribute. This is valid at call sites
1424 and on function declarations and definitions.
Bill Wendlingbf902f12013-02-06 06:22:58 +00001425``noduplicate``
1426 This attribute indicates that calls to the function cannot be
1427 duplicated. A call to a ``noduplicate`` function may be moved
1428 within its parent function, but may not be duplicated within
1429 its parent function.
1430
1431 A function containing a ``noduplicate`` call may still
1432 be an inlining candidate, provided that the call is not
1433 duplicated by inlining. That implies that the function has
1434 internal linkage and only has one call site, so the original
1435 call is dead after inlining.
Sean Silvab084af42012-12-07 10:36:55 +00001436``noimplicitfloat``
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00001437 This attributes disables implicit floating-point instructions.
Sean Silvab084af42012-12-07 10:36:55 +00001438``noinline``
1439 This attribute indicates that the inliner should never inline this
1440 function in any situation. This attribute may not be used together
1441 with the ``alwaysinline`` attribute.
Sean Silva1cbbcf12013-08-06 19:34:37 +00001442``nonlazybind``
1443 This attribute suppresses lazy symbol binding for the function. This
1444 may make calls to the function faster, at the cost of extra program
1445 startup time if the function is not called during program startup.
Sean Silvab084af42012-12-07 10:36:55 +00001446``noredzone``
1447 This attribute indicates that the code generator should not use a
1448 red zone, even if the target-specific ABI normally permits it.
1449``noreturn``
1450 This function attribute indicates that the function never returns
1451 normally. This produces undefined behavior at runtime if the
1452 function ever does dynamically return.
James Molloye6f87ca2015-11-06 10:32:53 +00001453``norecurse``
1454 This function attribute indicates that the function does not call itself
1455 either directly or indirectly down any possible call path. This produces
1456 undefined behavior at runtime if the function ever does recurse.
Sean Silvab084af42012-12-07 10:36:55 +00001457``nounwind``
Reid Kleckner96d01132015-02-11 01:23:16 +00001458 This function attribute indicates that the function never raises an
1459 exception. If the function does raise an exception, its runtime
1460 behavior is undefined. However, functions marked nounwind may still
1461 trap or generate asynchronous exceptions. Exception handling schemes
1462 that are recognized by LLVM to handle asynchronous exceptions, such
1463 as SEH, will still provide their implementation defined semantics.
Manoj Gupta77eeac32018-07-09 22:27:23 +00001464``"null-pointer-is-valid"``
1465 If ``"null-pointer-is-valid"`` is set to ``"true"``, then ``null`` address
1466 in address-space 0 is considered to be a valid address for memory loads and
1467 stores. Any analysis or optimization should not treat dereferencing a
1468 pointer to ``null`` as undefined behavior in this function.
1469 Note: Comparing address of a global variable to ``null`` may still
1470 evaluate to false because of a limitation in querying this attribute inside
1471 constant expressions.
Matt Morehouse31819412018-03-22 19:50:10 +00001472``optforfuzzing``
1473 This attribute indicates that this function should be optimized
1474 for maximum fuzzing signal.
Andrea Di Biagio377496b2013-08-23 11:53:55 +00001475``optnone``
Paul Robinsona2550a62015-11-30 21:56:16 +00001476 This function attribute indicates that most optimization passes will skip
1477 this function, with the exception of interprocedural optimization passes.
1478 Code generation defaults to the "fast" instruction selector.
Andrea Di Biagio377496b2013-08-23 11:53:55 +00001479 This attribute cannot be used together with the ``alwaysinline``
1480 attribute; this attribute is also incompatible
1481 with the ``minsize`` attribute and the ``optsize`` attribute.
Andrew Trickd4d1d9c2013-10-31 17:18:07 +00001482
Paul Robinsondcbe35b2013-11-18 21:44:03 +00001483 This attribute requires the ``noinline`` attribute to be specified on
1484 the function as well, so the function is never inlined into any caller.
Andrea Di Biagio377496b2013-08-23 11:53:55 +00001485 Only functions with the ``alwaysinline`` attribute are valid
Paul Robinsondcbe35b2013-11-18 21:44:03 +00001486 candidates for inlining into the body of this function.
Sean Silvab084af42012-12-07 10:36:55 +00001487``optsize``
1488 This attribute suggests that optimization passes and code generator
1489 passes make choices that keep the code size of this function low,
Andrea Di Biagio9b5d23b2013-08-09 18:42:18 +00001490 and otherwise do optimizations specifically to reduce code size as
1491 long as they do not significantly impact runtime performance.
Sanjoy Dasc0441c22016-04-19 05:24:47 +00001492``"patchable-function"``
1493 This attribute tells the code generator that the code
1494 generated for this function needs to follow certain conventions that
1495 make it possible for a runtime function to patch over it later.
1496 The exact effect of this attribute depends on its string value,
Charles Davise9c32c72016-08-08 21:20:15 +00001497 for which there currently is one legal possibility:
Sanjoy Dasc0441c22016-04-19 05:24:47 +00001498
1499 * ``"prologue-short-redirect"`` - This style of patchable
1500 function is intended to support patching a function prologue to
1501 redirect control away from the function in a thread safe
1502 manner. It guarantees that the first instruction of the
1503 function will be large enough to accommodate a short jump
1504 instruction, and will be sufficiently aligned to allow being
1505 fully changed via an atomic compare-and-swap instruction.
1506 While the first requirement can be satisfied by inserting large
1507 enough NOP, LLVM can and will try to re-purpose an existing
1508 instruction (i.e. one that would have to be emitted anyway) as
1509 the patchable instruction larger than a short jump.
1510
1511 ``"prologue-short-redirect"`` is currently only supported on
1512 x86-64.
1513
1514 This attribute by itself does not imply restrictions on
1515 inter-procedural optimizations. All of the semantic effects the
1516 patching may have to be separately conveyed via the linkage type.
whitequarked54b4a2017-06-21 18:46:50 +00001517``"probe-stack"``
1518 This attribute indicates that the function will trigger a guard region
1519 in the end of the stack. It ensures that accesses to the stack must be
1520 no further apart than the size of the guard region to a previous
1521 access of the stack. It takes one required string value, the name of
1522 the stack probing function that will be called.
1523
1524 If a function that has a ``"probe-stack"`` attribute is inlined into
1525 a function with another ``"probe-stack"`` attribute, the resulting
1526 function has the ``"probe-stack"`` attribute of the caller. If a
1527 function that has a ``"probe-stack"`` attribute is inlined into a
1528 function that has no ``"probe-stack"`` attribute at all, the resulting
1529 function has the ``"probe-stack"`` attribute of the callee.
Sean Silvab084af42012-12-07 10:36:55 +00001530``readnone``
Nick Lewyckyc2ec0722013-07-06 00:29:58 +00001531 On a function, this attribute indicates that the function computes its
1532 result (or decides to unwind an exception) based strictly on its arguments,
Sean Silvab084af42012-12-07 10:36:55 +00001533 without dereferencing any pointer arguments or otherwise accessing
1534 any mutable state (e.g. memory, control registers, etc) visible to
1535 caller functions. It does not write through any pointer arguments
1536 (including ``byval`` arguments) and never changes any state visible
Sanjoy Das5be2e842017-02-13 23:19:07 +00001537 to callers. This means while it cannot unwind exceptions by calling
1538 the ``C++`` exception throwing methods (since they write to memory), there may
1539 be non-``C++`` mechanisms that throw exceptions without writing to LLVM
1540 visible memory.
Andrew Trickd4d1d9c2013-10-31 17:18:07 +00001541
Nick Lewyckyc2ec0722013-07-06 00:29:58 +00001542 On an argument, this attribute indicates that the function does not
1543 dereference that pointer argument, even though it may read or write the
Nick Lewyckyefe31f22013-07-06 01:04:47 +00001544 memory that the pointer points to if accessed through other pointers.
Sean Silvab084af42012-12-07 10:36:55 +00001545``readonly``
Nick Lewyckyc2ec0722013-07-06 00:29:58 +00001546 On a function, this attribute indicates that the function does not write
1547 through any pointer arguments (including ``byval`` arguments) or otherwise
Sean Silvab084af42012-12-07 10:36:55 +00001548 modify any state (e.g. memory, control registers, etc) visible to
1549 caller functions. It may dereference pointer arguments and read
1550 state that may be set in the caller. A readonly function always
1551 returns the same value (or unwinds an exception identically) when
Sanjoy Das5be2e842017-02-13 23:19:07 +00001552 called with the same set of arguments and global state. This means while it
1553 cannot unwind exceptions by calling the ``C++`` exception throwing methods
1554 (since they write to memory), there may be non-``C++`` mechanisms that throw
1555 exceptions without writing to LLVM visible memory.
Andrew Trickd4d1d9c2013-10-31 17:18:07 +00001556
Nick Lewyckyc2ec0722013-07-06 00:29:58 +00001557 On an argument, this attribute indicates that the function does not write
1558 through this pointer argument, even though it may write to the memory that
1559 the pointer points to.
whitequark08b20352017-06-22 23:22:36 +00001560``"stack-probe-size"``
1561 This attribute controls the behavior of stack probes: either
1562 the ``"probe-stack"`` attribute, or ABI-required stack probes, if any.
1563 It defines the size of the guard region. It ensures that if the function
1564 may use more stack space than the size of the guard region, stack probing
1565 sequence will be emitted. It takes one required integer value, which
1566 is 4096 by default.
1567
1568 If a function that has a ``"stack-probe-size"`` attribute is inlined into
1569 a function with another ``"stack-probe-size"`` attribute, the resulting
1570 function has the ``"stack-probe-size"`` attribute that has the lower
1571 numeric value. If a function that has a ``"stack-probe-size"`` attribute is
1572 inlined into a function that has no ``"stack-probe-size"`` attribute
1573 at all, the resulting function has the ``"stack-probe-size"`` attribute
1574 of the callee.
Hans Wennborg89c35fc2018-02-23 13:46:25 +00001575``"no-stack-arg-probe"``
1576 This attribute disables ABI-required stack probes, if any.
Nicolai Haehnle84c9f992016-07-04 08:01:29 +00001577``writeonly``
1578 On a function, this attribute indicates that the function may write to but
1579 does not read from memory.
1580
1581 On an argument, this attribute indicates that the function may write to but
1582 does not read through this pointer argument (even though it may read from
1583 the memory that the pointer points to).
Igor Laevsky39d662f2015-07-11 10:30:36 +00001584``argmemonly``
1585 This attribute indicates that the only memory accesses inside function are
1586 loads and stores from objects pointed to by its pointer-typed arguments,
1587 with arbitrary offsets. Or in other words, all memory operations in the
1588 function can refer to memory only using pointers based on its function
1589 arguments.
1590 Note that ``argmemonly`` can be used together with ``readonly`` attribute
1591 in order to specify that function reads only from its arguments.
Sean Silvab084af42012-12-07 10:36:55 +00001592``returns_twice``
1593 This attribute indicates that this function can return twice. The C
1594 ``setjmp`` is an example of such a function. The compiler disables
1595 some optimizations (like tail calls) in the caller of these
1596 functions.
Peter Collingbourne82437bf2015-06-15 21:07:11 +00001597``safestack``
1598 This attribute indicates that
1599 `SafeStack <http://clang.llvm.org/docs/SafeStack.html>`_
1600 protection is enabled for this function.
1601
1602 If a function that has a ``safestack`` attribute is inlined into a
1603 function that doesn't have a ``safestack`` attribute or which has an
1604 ``ssp``, ``sspstrong`` or ``sspreq`` attribute, then the resulting
1605 function will have a ``safestack`` attribute.
Kostya Serebryanycf880b92013-02-26 06:58:09 +00001606``sanitize_address``
1607 This attribute indicates that AddressSanitizer checks
1608 (dynamic address safety analysis) are enabled for this function.
1609``sanitize_memory``
1610 This attribute indicates that MemorySanitizer checks (dynamic detection
1611 of accesses to uninitialized memory) are enabled for this function.
1612``sanitize_thread``
1613 This attribute indicates that ThreadSanitizer checks
1614 (dynamic thread safety analysis) are enabled for this function.
Evgeniy Stepanovc667c1f2017-12-09 00:21:41 +00001615``sanitize_hwaddress``
1616 This attribute indicates that HWAddressSanitizer checks
1617 (dynamic address safety analysis based on tagged pointers) are enabled for
1618 this function.
Matt Arsenaultb19b57e2017-04-28 20:25:27 +00001619``speculatable``
1620 This function attribute indicates that the function does not have any
1621 effects besides calculating its result and does not have undefined behavior.
1622 Note that ``speculatable`` is not enough to conclude that along any
Xin Tongc7180202017-05-02 23:24:12 +00001623 particular execution path the number of calls to this function will not be
Matt Arsenaultb19b57e2017-04-28 20:25:27 +00001624 externally observable. This attribute is only valid on functions
1625 and declarations, not on individual call sites. If a function is
1626 incorrectly marked as speculatable and really does exhibit
1627 undefined behavior, the undefined behavior may be observed even
1628 if the call site is dead code.
1629
Sean Silvab084af42012-12-07 10:36:55 +00001630``ssp``
1631 This attribute indicates that the function should emit a stack
Dmitri Gribenkoe8131122013-01-19 20:34:20 +00001632 smashing protector. It is in the form of a "canary" --- a random value
Sean Silvab084af42012-12-07 10:36:55 +00001633 placed on the stack before the local variables that's checked upon
1634 return from the function to see if it has been overwritten. A
1635 heuristic is used to determine if a function needs stack protectors
Bill Wendling7c8f96a2013-01-23 06:43:53 +00001636 or not. The heuristic used will enable protectors for functions with:
Dmitri Gribenko69b56472013-01-29 23:14:41 +00001637
Bill Wendling7c8f96a2013-01-23 06:43:53 +00001638 - Character arrays larger than ``ssp-buffer-size`` (default 8).
1639 - Aggregates containing character arrays larger than ``ssp-buffer-size``.
1640 - Calls to alloca() with variable sizes or constant sizes greater than
1641 ``ssp-buffer-size``.
Sean Silvab084af42012-12-07 10:36:55 +00001642
Josh Magee24c7f062014-02-01 01:36:16 +00001643 Variables that are identified as requiring a protector will be arranged
1644 on the stack such that they are adjacent to the stack protector guard.
1645
Sean Silvab084af42012-12-07 10:36:55 +00001646 If a function that has an ``ssp`` attribute is inlined into a
1647 function that doesn't have an ``ssp`` attribute, then the resulting
1648 function will have an ``ssp`` attribute.
1649``sspreq``
1650 This attribute indicates that the function should *always* emit a
1651 stack smashing protector. This overrides the ``ssp`` function
1652 attribute.
1653
Josh Magee24c7f062014-02-01 01:36:16 +00001654 Variables that are identified as requiring a protector will be arranged
1655 on the stack such that they are adjacent to the stack protector guard.
1656 The specific layout rules are:
1657
1658 #. Large arrays and structures containing large arrays
1659 (``>= ssp-buffer-size``) are closest to the stack protector.
1660 #. Small arrays and structures containing small arrays
1661 (``< ssp-buffer-size``) are 2nd closest to the protector.
1662 #. Variables that have had their address taken are 3rd closest to the
1663 protector.
1664
Sean Silvab084af42012-12-07 10:36:55 +00001665 If a function that has an ``sspreq`` attribute is inlined into a
1666 function that doesn't have an ``sspreq`` attribute or which has an
Bill Wendlingd154e2832013-01-23 06:41:41 +00001667 ``ssp`` or ``sspstrong`` attribute, then the resulting function will have
1668 an ``sspreq`` attribute.
1669``sspstrong``
1670 This attribute indicates that the function should emit a stack smashing
Bill Wendling7c8f96a2013-01-23 06:43:53 +00001671 protector. This attribute causes a strong heuristic to be used when
Sean Silvaa1190322015-08-06 22:56:48 +00001672 determining if a function needs stack protectors. The strong heuristic
Bill Wendling7c8f96a2013-01-23 06:43:53 +00001673 will enable protectors for functions with:
Dmitri Gribenko69b56472013-01-29 23:14:41 +00001674
Bill Wendling7c8f96a2013-01-23 06:43:53 +00001675 - Arrays of any size and type
1676 - Aggregates containing an array of any size and type.
1677 - Calls to alloca().
1678 - Local variables that have had their address taken.
1679
Josh Magee24c7f062014-02-01 01:36:16 +00001680 Variables that are identified as requiring a protector will be arranged
1681 on the stack such that they are adjacent to the stack protector guard.
1682 The specific layout rules are:
1683
1684 #. Large arrays and structures containing large arrays
1685 (``>= ssp-buffer-size``) are closest to the stack protector.
1686 #. Small arrays and structures containing small arrays
1687 (``< ssp-buffer-size``) are 2nd closest to the protector.
1688 #. Variables that have had their address taken are 3rd closest to the
1689 protector.
1690
Bill Wendling7c8f96a2013-01-23 06:43:53 +00001691 This overrides the ``ssp`` function attribute.
Bill Wendlingd154e2832013-01-23 06:41:41 +00001692
1693 If a function that has an ``sspstrong`` attribute is inlined into a
1694 function that doesn't have an ``sspstrong`` attribute, then the
1695 resulting function will have an ``sspstrong`` attribute.
Andrew Kaylor53a5fbb2017-08-14 21:15:13 +00001696``strictfp``
1697 This attribute indicates that the function was called from a scope that
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00001698 requires strict floating-point semantics. LLVM will not attempt any
1699 optimizations that require assumptions about the floating-point rounding
1700 mode or that might alter the state of floating-point status flags that
Andrew Kaylor53a5fbb2017-08-14 21:15:13 +00001701 might otherwise be set or cleared by calling this function.
Reid Kleckner5a2ab2b2015-03-04 00:08:56 +00001702``"thunk"``
1703 This attribute indicates that the function will delegate to some other
1704 function with a tail call. The prototype of a thunk should not be used for
1705 optimization purposes. The caller is expected to cast the thunk prototype to
1706 match the thunk target prototype.
Sean Silvab084af42012-12-07 10:36:55 +00001707``uwtable``
1708 This attribute indicates that the ABI being targeted requires that
Sean Silva706fba52015-08-06 22:56:24 +00001709 an unwind table entry be produced for this function even if we can
Sean Silvab084af42012-12-07 10:36:55 +00001710 show that no exceptions passes by it. This is normally the case for
1711 the ELF x86-64 abi, but it can be disabled for some compilation
1712 units.
Oren Ben Simhonfdd72fd2018-03-17 13:29:46 +00001713``nocf_check``
Hiroshi Inouec36a1f12018-06-15 05:10:09 +00001714 This attribute indicates that no control-flow check will be performed on
Oren Ben Simhonfdd72fd2018-03-17 13:29:46 +00001715 the attributed entity. It disables -fcf-protection=<> for a specific
1716 entity to fine grain the HW control flow protection mechanism. The flag
Hiroshi Inouec36a1f12018-06-15 05:10:09 +00001717 is target independent and currently appertains to a function or function
Oren Ben Simhonfdd72fd2018-03-17 13:29:46 +00001718 pointer.
Vlad Tsyrklevichd17f61e2018-04-03 20:10:40 +00001719``shadowcallstack``
1720 This attribute indicates that the ShadowCallStack checks are enabled for
1721 the function. The instrumentation checks that the return address for the
1722 function has not changed between the function prolog and eiplog. It is
1723 currently x86_64-specific.
Sean Silvab084af42012-12-07 10:36:55 +00001724
Javed Absarf3d79042017-05-11 12:28:08 +00001725.. _glattrs:
1726
1727Global Attributes
1728-----------------
1729
1730Attributes may be set to communicate additional information about a global variable.
1731Unlike :ref:`function attributes <fnattrs>`, attributes on a global variable
1732are grouped into a single :ref:`attribute group <attrgrp>`.
Sanjoy Dasb513a9f2015-09-24 23:34:52 +00001733
1734.. _opbundles:
1735
1736Operand Bundles
1737---------------
1738
Sanjoy Dasb513a9f2015-09-24 23:34:52 +00001739Operand bundles are tagged sets of SSA values that can be associated
Sanjoy Dasb0e9d4a52015-09-25 00:05:40 +00001740with certain LLVM instructions (currently only ``call`` s and
1741``invoke`` s). In a way they are like metadata, but dropping them is
Sanjoy Dasb513a9f2015-09-24 23:34:52 +00001742incorrect and will change program semantics.
1743
1744Syntax::
David Majnemer34cacb42015-10-22 01:46:38 +00001745
Sanjoy Das9f3c1252015-11-21 09:12:07 +00001746 operand bundle set ::= '[' operand bundle (, operand bundle )* ']'
Sanjoy Dasb513a9f2015-09-24 23:34:52 +00001747 operand bundle ::= tag '(' [ bundle operand ] (, bundle operand )* ')'
1748 bundle operand ::= SSA value
1749 tag ::= string constant
1750
1751Operand bundles are **not** part of a function's signature, and a
1752given function may be called from multiple places with different kinds
1753of operand bundles. This reflects the fact that the operand bundles
1754are conceptually a part of the ``call`` (or ``invoke``), not the
1755callee being dispatched to.
1756
1757Operand bundles are a generic mechanism intended to support
1758runtime-introspection-like functionality for managed languages. While
1759the exact semantics of an operand bundle depend on the bundle tag,
1760there are certain limitations to how much the presence of an operand
1761bundle can influence the semantics of a program. These restrictions
1762are described as the semantics of an "unknown" operand bundle. As
1763long as the behavior of an operand bundle is describable within these
1764restrictions, LLVM does not need to have special knowledge of the
1765operand bundle to not miscompile programs containing it.
1766
David Majnemer34cacb42015-10-22 01:46:38 +00001767- The bundle operands for an unknown operand bundle escape in unknown
1768 ways before control is transferred to the callee or invokee.
1769- Calls and invokes with operand bundles have unknown read / write
1770 effect on the heap on entry and exit (even if the call target is
Sylvestre Ledru84666a12016-02-14 20:16:22 +00001771 ``readnone`` or ``readonly``), unless they're overridden with
Sanjoy Das98a341b2015-10-22 03:12:22 +00001772 callsite specific attributes.
1773- An operand bundle at a call site cannot change the implementation
1774 of the called function. Inter-procedural optimizations work as
1775 usual as long as they take into account the first two properties.
Sanjoy Dasb513a9f2015-09-24 23:34:52 +00001776
Sanjoy Dascdafd842015-11-11 21:38:02 +00001777More specific types of operand bundles are described below.
1778
Sanjoy Dasb51325d2016-03-11 19:08:34 +00001779.. _deopt_opbundles:
1780
Sanjoy Dascdafd842015-11-11 21:38:02 +00001781Deoptimization Operand Bundles
1782^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1783
Sanjoy Das9f3c1252015-11-21 09:12:07 +00001784Deoptimization operand bundles are characterized by the ``"deopt"``
Sanjoy Dascdafd842015-11-11 21:38:02 +00001785operand bundle tag. These operand bundles represent an alternate
1786"safe" continuation for the call site they're attached to, and can be
1787used by a suitable runtime to deoptimize the compiled frame at the
Sanjoy Das9f3c1252015-11-21 09:12:07 +00001788specified call site. There can be at most one ``"deopt"`` operand
1789bundle attached to a call site. Exact details of deoptimization is
1790out of scope for the language reference, but it usually involves
1791rewriting a compiled frame into a set of interpreted frames.
Sanjoy Dascdafd842015-11-11 21:38:02 +00001792
1793From the compiler's perspective, deoptimization operand bundles make
1794the call sites they're attached to at least ``readonly``. They read
1795through all of their pointer typed operands (even if they're not
1796otherwise escaped) and the entire visible heap. Deoptimization
1797operand bundles do not capture their operands except during
1798deoptimization, in which case control will not be returned to the
1799compiled frame.
1800
Sanjoy Das2d161452015-11-18 06:23:38 +00001801The inliner knows how to inline through calls that have deoptimization
1802operand bundles. Just like inlining through a normal call site
1803involves composing the normal and exceptional continuations, inlining
1804through a call site with a deoptimization operand bundle needs to
1805appropriately compose the "safe" deoptimization continuation. The
1806inliner does this by prepending the parent's deoptimization
1807continuation to every deoptimization continuation in the inlined body.
1808E.g. inlining ``@f`` into ``@g`` in the following example
1809
1810.. code-block:: llvm
1811
1812 define void @f() {
1813 call void @x() ;; no deopt state
1814 call void @y() [ "deopt"(i32 10) ]
1815 call void @y() [ "deopt"(i32 10), "unknown"(i8* null) ]
1816 ret void
1817 }
1818
1819 define void @g() {
1820 call void @f() [ "deopt"(i32 20) ]
1821 ret void
1822 }
1823
1824will result in
1825
1826.. code-block:: llvm
1827
1828 define void @g() {
1829 call void @x() ;; still no deopt state
1830 call void @y() [ "deopt"(i32 20, i32 10) ]
1831 call void @y() [ "deopt"(i32 20, i32 10), "unknown"(i8* null) ]
1832 ret void
1833 }
1834
1835It is the frontend's responsibility to structure or encode the
1836deoptimization state in a way that syntactically prepending the
1837caller's deoptimization state to the callee's deoptimization state is
1838semantically equivalent to composing the caller's deoptimization
1839continuation after the callee's deoptimization continuation.
1840
Joseph Tremoulete28885e2016-01-10 04:28:38 +00001841.. _ob_funclet:
1842
David Majnemer3bb88c02015-12-15 21:27:27 +00001843Funclet Operand Bundles
1844^^^^^^^^^^^^^^^^^^^^^^^
1845
1846Funclet operand bundles are characterized by the ``"funclet"``
1847operand bundle tag. These operand bundles indicate that a call site
1848is within a particular funclet. There can be at most one
1849``"funclet"`` operand bundle attached to a call site and it must have
1850exactly one bundle operand.
1851
Joseph Tremoulete28885e2016-01-10 04:28:38 +00001852If any funclet EH pads have been "entered" but not "exited" (per the
1853`description in the EH doc\ <ExceptionHandling.html#wineh-constraints>`_),
1854it is undefined behavior to execute a ``call`` or ``invoke`` which:
1855
1856* does not have a ``"funclet"`` bundle and is not a ``call`` to a nounwind
1857 intrinsic, or
1858* has a ``"funclet"`` bundle whose operand is not the most-recently-entered
1859 not-yet-exited funclet EH pad.
1860
1861Similarly, if no funclet EH pads have been entered-but-not-yet-exited,
1862executing a ``call`` or ``invoke`` with a ``"funclet"`` bundle is undefined behavior.
1863
Sanjoy Dasa34ce952016-01-20 19:50:25 +00001864GC Transition Operand Bundles
1865^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1866
1867GC transition operand bundles are characterized by the
1868``"gc-transition"`` operand bundle tag. These operand bundles mark a
1869call as a transition between a function with one GC strategy to a
1870function with a different GC strategy. If coordinating the transition
1871between GC strategies requires additional code generation at the call
1872site, these bundles may contain any values that are needed by the
1873generated code. For more details, see :ref:`GC Transitions
1874<gc_transition_args>`.
1875
Sean Silvab084af42012-12-07 10:36:55 +00001876.. _moduleasm:
1877
1878Module-Level Inline Assembly
1879----------------------------
1880
1881Modules may contain "module-level inline asm" blocks, which corresponds
1882to the GCC "file scope inline asm" blocks. These blocks are internally
1883concatenated by LLVM and treated as a single unit, but may be separated
1884in the ``.ll`` file if desired. The syntax is very simple:
1885
1886.. code-block:: llvm
1887
1888 module asm "inline asm code goes here"
1889 module asm "more can go here"
1890
1891The strings can contain any character by escaping non-printable
1892characters. The escape sequence used is simply "\\xx" where "xx" is the
1893two digit hex code for the number.
1894
James Y Knightbc832ed2015-07-08 18:08:36 +00001895Note that the assembly string *must* be parseable by LLVM's integrated assembler
1896(unless it is disabled), even when emitting a ``.s`` file.
Sean Silvab084af42012-12-07 10:36:55 +00001897
Eli Benderskyfdc529a2013-06-07 19:40:08 +00001898.. _langref_datalayout:
1899
Sean Silvab084af42012-12-07 10:36:55 +00001900Data Layout
1901-----------
1902
1903A module may specify a target specific data layout string that specifies
1904how data is to be laid out in memory. The syntax for the data layout is
1905simply:
1906
1907.. code-block:: llvm
1908
1909 target datalayout = "layout specification"
1910
1911The *layout specification* consists of a list of specifications
1912separated by the minus sign character ('-'). Each specification starts
1913with a letter and may include other information after the letter to
1914define some aspect of the data layout. The specifications accepted are
1915as follows:
1916
1917``E``
1918 Specifies that the target lays out data in big-endian form. That is,
1919 the bits with the most significance have the lowest address
1920 location.
1921``e``
1922 Specifies that the target lays out data in little-endian form. That
1923 is, the bits with the least significance have the lowest address
1924 location.
1925``S<size>``
1926 Specifies the natural alignment of the stack in bits. Alignment
1927 promotion of stack variables is limited to the natural stack
1928 alignment to avoid dynamic stack realignment. The stack alignment
1929 must be a multiple of 8-bits. If omitted, the natural stack
1930 alignment defaults to "unspecified", which does not prevent any
1931 alignment promotions.
Dylan McKayced2fe62018-02-19 09:56:22 +00001932``P<address space>``
1933 Specifies the address space that corresponds to program memory.
1934 Harvard architectures can use this to specify what space LLVM
1935 should place things such as functions into. If omitted, the
1936 program memory space defaults to the default address space of 0,
1937 which corresponds to a Von Neumann architecture that has code
1938 and data in the same space.
Matt Arsenault3c1fc762017-04-10 22:27:50 +00001939``A<address space>``
Dylan McKayced2fe62018-02-19 09:56:22 +00001940 Specifies the address space of objects created by '``alloca``'.
Matt Arsenault3c1fc762017-04-10 22:27:50 +00001941 Defaults to the default address space of 0.
Elena Demikhovsky945b7e52018-02-14 06:58:08 +00001942``p[n]:<size>:<abi>:<pref>:<idx>``
Sean Silvab084af42012-12-07 10:36:55 +00001943 This specifies the *size* of a pointer and its ``<abi>`` and
Elena Demikhovsky945b7e52018-02-14 06:58:08 +00001944 ``<pref>``\erred alignments for address space ``n``. The fourth parameter
1945 ``<idx>`` is a size of index that used for address calculation. If not
1946 specified, the default index size is equal to the pointer size. All sizes
1947 are in bits. The address space, ``n``, is optional, and if not specified,
Sean Silvaa1190322015-08-06 22:56:48 +00001948 denotes the default address space 0. The value of ``n`` must be
Rafael Espindolaabdd7262014-01-06 21:40:24 +00001949 in the range [1,2^23).
Sean Silvab084af42012-12-07 10:36:55 +00001950``i<size>:<abi>:<pref>``
1951 This specifies the alignment for an integer type of a given bit
1952 ``<size>``. The value of ``<size>`` must be in the range [1,2^23).
1953``v<size>:<abi>:<pref>``
1954 This specifies the alignment for a vector type of a given bit
1955 ``<size>``.
1956``f<size>:<abi>:<pref>``
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00001957 This specifies the alignment for a floating-point type of a given bit
Sean Silvab084af42012-12-07 10:36:55 +00001958 ``<size>``. Only values of ``<size>`` that are supported by the target
1959 will work. 32 (float) and 64 (double) are supported on all targets; 80
1960 or 128 (different flavors of long double) are also supported on some
1961 targets.
Rafael Espindolaabdd7262014-01-06 21:40:24 +00001962``a:<abi>:<pref>``
1963 This specifies the alignment for an object of aggregate type.
Rafael Espindola58873562014-01-03 19:21:54 +00001964``m:<mangling>``
Reid Klecknerf8b51c52018-03-16 20:13:32 +00001965 If present, specifies that llvm names are mangled in the output. Symbols
1966 prefixed with the mangling escape character ``\01`` are passed through
1967 directly to the assembler without the escape character. The mangling style
Hans Wennborgd4245ac2014-01-15 02:49:17 +00001968 options are
1969
1970 * ``e``: ELF mangling: Private symbols get a ``.L`` prefix.
1971 * ``m``: Mips mangling: Private symbols get a ``$`` prefix.
1972 * ``o``: Mach-O mangling: Private symbols get ``L`` prefix. Other
1973 symbols get a ``_`` prefix.
Reid Klecknerf8b51c52018-03-16 20:13:32 +00001974 * ``x``: Windows x86 COFF mangling: Private symbols get the usual prefix.
1975 Regular C symbols get a ``_`` prefix. Functions with ``__stdcall``,
1976 ``__fastcall``, and ``__vectorcall`` have custom mangling that appends
1977 ``@N`` where N is the number of bytes used to pass parameters. C++ symbols
1978 starting with ``?`` are not mangled in any way.
1979 * ``w``: Windows COFF mangling: Similar to ``x``, except that normal C
1980 symbols do not receive a ``_`` prefix.
Sean Silvab084af42012-12-07 10:36:55 +00001981``n<size1>:<size2>:<size3>...``
1982 This specifies a set of native integer widths for the target CPU in
1983 bits. For example, it might contain ``n32`` for 32-bit PowerPC,
1984 ``n32:64`` for PowerPC 64, or ``n8:16:32:64`` for X86-64. Elements of
1985 this set are considered to support most general arithmetic operations
1986 efficiently.
Sanjoy Dasc6af5ea2016-07-28 23:43:38 +00001987``ni:<address space0>:<address space1>:<address space2>...``
1988 This specifies pointer types with the specified address spaces
1989 as :ref:`Non-Integral Pointer Type <nointptrtype>` s. The ``0``
1990 address space cannot be specified as non-integral.
Sean Silvab084af42012-12-07 10:36:55 +00001991
Rafael Espindolaabdd7262014-01-06 21:40:24 +00001992On every specification that takes a ``<abi>:<pref>``, specifying the
1993``<pref>`` alignment is optional. If omitted, the preceding ``:``
1994should be omitted too and ``<pref>`` will be equal to ``<abi>``.
1995
Sean Silvab084af42012-12-07 10:36:55 +00001996When constructing the data layout for a given target, LLVM starts with a
1997default set of specifications which are then (possibly) overridden by
1998the specifications in the ``datalayout`` keyword. The default
1999specifications are given in this list:
2000
2001- ``E`` - big endian
Matt Arsenault24b49c42013-07-31 17:49:08 +00002002- ``p:64:64:64`` - 64-bit pointers with 64-bit alignment.
2003- ``p[n]:64:64:64`` - Other address spaces are assumed to be the
2004 same as the default address space.
Patrik Hagglunda832ab12013-01-30 09:02:06 +00002005- ``S0`` - natural stack alignment is unspecified
Sean Silvab084af42012-12-07 10:36:55 +00002006- ``i1:8:8`` - i1 is 8-bit (byte) aligned
2007- ``i8:8:8`` - i8 is 8-bit (byte) aligned
2008- ``i16:16:16`` - i16 is 16-bit aligned
2009- ``i32:32:32`` - i32 is 32-bit aligned
2010- ``i64:32:64`` - i64 has ABI alignment of 32-bits but preferred
2011 alignment of 64-bits
Patrik Hagglunda832ab12013-01-30 09:02:06 +00002012- ``f16:16:16`` - half is 16-bit aligned
Sean Silvab084af42012-12-07 10:36:55 +00002013- ``f32:32:32`` - float is 32-bit aligned
2014- ``f64:64:64`` - double is 64-bit aligned
Patrik Hagglunda832ab12013-01-30 09:02:06 +00002015- ``f128:128:128`` - quad is 128-bit aligned
Sean Silvab084af42012-12-07 10:36:55 +00002016- ``v64:64:64`` - 64-bit vector is 64-bit aligned
2017- ``v128:128:128`` - 128-bit vector is 128-bit aligned
Rafael Espindolae8f4d582013-12-12 17:21:51 +00002018- ``a:0:64`` - aggregates are 64-bit aligned
Sean Silvab084af42012-12-07 10:36:55 +00002019
2020When LLVM is determining the alignment for a given type, it uses the
2021following rules:
2022
2023#. If the type sought is an exact match for one of the specifications,
2024 that specification is used.
2025#. If no match is found, and the type sought is an integer type, then
2026 the smallest integer type that is larger than the bitwidth of the
2027 sought type is used. If none of the specifications are larger than
2028 the bitwidth then the largest integer type is used. For example,
2029 given the default specifications above, the i7 type will use the
2030 alignment of i8 (next largest) while both i65 and i256 will use the
2031 alignment of i64 (largest specified).
2032#. If no match is found, and the type sought is a vector type, then the
2033 largest vector type that is smaller than the sought vector type will
2034 be used as a fall back. This happens because <128 x double> can be
2035 implemented in terms of 64 <2 x double>, for example.
2036
2037The function of the data layout string may not be what you expect.
2038Notably, this is not a specification from the frontend of what alignment
2039the code generator should use.
2040
2041Instead, if specified, the target data layout is required to match what
2042the ultimate *code generator* expects. This string is used by the
2043mid-level optimizers to improve code, and this only works if it matches
Mehdi Amini4a121fa2015-03-14 22:04:06 +00002044what the ultimate code generator uses. There is no way to generate IR
2045that does not embed this target-specific detail into the IR. If you
2046don't specify the string, the default specifications will be used to
2047generate a Data Layout and the optimization phases will operate
2048accordingly and introduce target specificity into the IR with respect to
2049these default specifications.
Sean Silvab084af42012-12-07 10:36:55 +00002050
Bill Wendling5cc90842013-10-18 23:41:25 +00002051.. _langref_triple:
2052
2053Target Triple
2054-------------
2055
2056A module may specify a target triple string that describes the target
2057host. The syntax for the target triple is simply:
2058
2059.. code-block:: llvm
2060
2061 target triple = "x86_64-apple-macosx10.7.0"
2062
2063The *target triple* string consists of a series of identifiers delimited
2064by the minus sign character ('-'). The canonical forms are:
2065
2066::
2067
2068 ARCHITECTURE-VENDOR-OPERATING_SYSTEM
2069 ARCHITECTURE-VENDOR-OPERATING_SYSTEM-ENVIRONMENT
2070
2071This information is passed along to the backend so that it generates
2072code for the proper architecture. It's possible to override this on the
2073command line with the ``-mtriple`` command line option.
2074
Sean Silvab084af42012-12-07 10:36:55 +00002075.. _pointeraliasing:
2076
2077Pointer Aliasing Rules
2078----------------------
2079
2080Any memory access must be done through a pointer value associated with
2081an address range of the memory access, otherwise the behavior is
2082undefined. Pointer values are associated with address ranges according
2083to the following rules:
2084
2085- A pointer value is associated with the addresses associated with any
2086 value it is *based* on.
2087- An address of a global variable is associated with the address range
2088 of the variable's storage.
2089- The result value of an allocation instruction is associated with the
2090 address range of the allocated storage.
2091- A null pointer in the default address-space is associated with no
2092 address.
2093- An integer constant other than zero or a pointer value returned from
2094 a function not defined within LLVM may be associated with address
2095 ranges allocated through mechanisms other than those provided by
2096 LLVM. Such ranges shall not overlap with any ranges of addresses
2097 allocated by mechanisms provided by LLVM.
2098
2099A pointer value is *based* on another pointer value according to the
2100following rules:
2101
Sanjoy Das6d489492017-09-13 18:49:22 +00002102- A pointer value formed from a scalar ``getelementptr`` operation is *based* on
2103 the pointer-typed operand of the ``getelementptr``.
2104- The pointer in lane *l* of the result of a vector ``getelementptr`` operation
2105 is *based* on the pointer in lane *l* of the vector-of-pointers-typed operand
2106 of the ``getelementptr``.
Sean Silvab084af42012-12-07 10:36:55 +00002107- The result value of a ``bitcast`` is *based* on the operand of the
2108 ``bitcast``.
2109- A pointer value formed by an ``inttoptr`` is *based* on all pointer
2110 values that contribute (directly or indirectly) to the computation of
2111 the pointer's value.
2112- The "*based* on" relationship is transitive.
2113
2114Note that this definition of *"based"* is intentionally similar to the
2115definition of *"based"* in C99, though it is slightly weaker.
2116
2117LLVM IR does not associate types with memory. The result type of a
2118``load`` merely indicates the size and alignment of the memory from
2119which to load, as well as the interpretation of the value. The first
2120operand type of a ``store`` similarly only indicates the size and
2121alignment of the store.
2122
2123Consequently, type-based alias analysis, aka TBAA, aka
2124``-fstrict-aliasing``, is not applicable to general unadorned LLVM IR.
2125:ref:`Metadata <metadata>` may be used to encode additional information
2126which specialized optimization passes may use to implement type-based
2127alias analysis.
2128
2129.. _volatile:
2130
2131Volatile Memory Accesses
2132------------------------
2133
2134Certain memory accesses, such as :ref:`load <i_load>`'s,
2135:ref:`store <i_store>`'s, and :ref:`llvm.memcpy <int_memcpy>`'s may be
2136marked ``volatile``. The optimizers must not change the number of
2137volatile operations or change their order of execution relative to other
2138volatile operations. The optimizers *may* change the order of volatile
2139operations relative to non-volatile operations. This is not Java's
2140"volatile" and has no cross-thread synchronization behavior.
2141
Andrew Trick89fc5a62013-01-30 21:19:35 +00002142IR-level volatile loads and stores cannot safely be optimized into
2143llvm.memcpy or llvm.memmove intrinsics even when those intrinsics are
2144flagged volatile. Likewise, the backend should never split or merge
2145target-legal volatile load/store instructions.
2146
Andrew Trick7e6f9282013-01-31 00:49:39 +00002147.. admonition:: Rationale
2148
2149 Platforms may rely on volatile loads and stores of natively supported
2150 data width to be executed as single instruction. For example, in C
2151 this holds for an l-value of volatile primitive type with native
2152 hardware support, but not necessarily for aggregate types. The
2153 frontend upholds these expectations, which are intentionally
Sean Silva706fba52015-08-06 22:56:24 +00002154 unspecified in the IR. The rules above ensure that IR transformations
Andrew Trick7e6f9282013-01-31 00:49:39 +00002155 do not violate the frontend's contract with the language.
2156
Sean Silvab084af42012-12-07 10:36:55 +00002157.. _memmodel:
2158
2159Memory Model for Concurrent Operations
2160--------------------------------------
2161
2162The LLVM IR does not define any way to start parallel threads of
2163execution or to register signal handlers. Nonetheless, there are
2164platform-specific ways to create them, and we define LLVM IR's behavior
2165in their presence. This model is inspired by the C++0x memory model.
2166
2167For a more informal introduction to this model, see the :doc:`Atomics`.
2168
2169We define a *happens-before* partial order as the least partial order
2170that
2171
2172- Is a superset of single-thread program order, and
2173- When a *synchronizes-with* ``b``, includes an edge from ``a`` to
2174 ``b``. *Synchronizes-with* pairs are introduced by platform-specific
2175 techniques, like pthread locks, thread creation, thread joining,
2176 etc., and by atomic instructions. (See also :ref:`Atomic Memory Ordering
2177 Constraints <ordering>`).
2178
2179Note that program order does not introduce *happens-before* edges
2180between a thread and signals executing inside that thread.
2181
2182Every (defined) read operation (load instructions, memcpy, atomic
2183loads/read-modify-writes, etc.) R reads a series of bytes written by
2184(defined) write operations (store instructions, atomic
2185stores/read-modify-writes, memcpy, etc.). For the purposes of this
2186section, initialized globals are considered to have a write of the
2187initializer which is atomic and happens before any other read or write
2188of the memory in question. For each byte of a read R, R\ :sub:`byte`
2189may see any write to the same byte, except:
2190
2191- If write\ :sub:`1` happens before write\ :sub:`2`, and
2192 write\ :sub:`2` happens before R\ :sub:`byte`, then
2193 R\ :sub:`byte` does not see write\ :sub:`1`.
2194- If R\ :sub:`byte` happens before write\ :sub:`3`, then
2195 R\ :sub:`byte` does not see write\ :sub:`3`.
2196
2197Given that definition, R\ :sub:`byte` is defined as follows:
2198
2199- If R is volatile, the result is target-dependent. (Volatile is
2200 supposed to give guarantees which can support ``sig_atomic_t`` in
Richard Smith32dbdf62014-07-31 04:25:36 +00002201 C/C++, and may be used for accesses to addresses that do not behave
Sean Silvab084af42012-12-07 10:36:55 +00002202 like normal memory. It does not generally provide cross-thread
2203 synchronization.)
2204- Otherwise, if there is no write to the same byte that happens before
2205 R\ :sub:`byte`, R\ :sub:`byte` returns ``undef`` for that byte.
2206- Otherwise, if R\ :sub:`byte` may see exactly one write,
2207 R\ :sub:`byte` returns the value written by that write.
2208- Otherwise, if R is atomic, and all the writes R\ :sub:`byte` may
2209 see are atomic, it chooses one of the values written. See the :ref:`Atomic
2210 Memory Ordering Constraints <ordering>` section for additional
2211 constraints on how the choice is made.
2212- Otherwise R\ :sub:`byte` returns ``undef``.
2213
2214R returns the value composed of the series of bytes it read. This
2215implies that some bytes within the value may be ``undef`` **without**
2216the entire value being ``undef``. Note that this only defines the
2217semantics of the operation; it doesn't mean that targets will emit more
2218than one instruction to read the series of bytes.
2219
2220Note that in cases where none of the atomic intrinsics are used, this
2221model places only one restriction on IR transformations on top of what
2222is required for single-threaded execution: introducing a store to a byte
2223which might not otherwise be stored is not allowed in general.
2224(Specifically, in the case where another thread might write to and read
2225from an address, introducing a store can change a load that may see
2226exactly one write into a load that may see multiple writes.)
2227
2228.. _ordering:
2229
2230Atomic Memory Ordering Constraints
2231----------------------------------
2232
2233Atomic instructions (:ref:`cmpxchg <i_cmpxchg>`,
2234:ref:`atomicrmw <i_atomicrmw>`, :ref:`fence <i_fence>`,
2235:ref:`atomic load <i_load>`, and :ref:`atomic store <i_store>`) take
Tim Northovere94a5182014-03-11 10:48:52 +00002236ordering parameters that determine which other atomic instructions on
Sean Silvab084af42012-12-07 10:36:55 +00002237the same address they *synchronize with*. These semantics are borrowed
2238from Java and C++0x, but are somewhat more colloquial. If these
2239descriptions aren't precise enough, check those specs (see spec
2240references in the :doc:`atomics guide <Atomics>`).
2241:ref:`fence <i_fence>` instructions treat these orderings somewhat
2242differently since they don't take an address. See that instruction's
2243documentation for details.
2244
2245For a simpler introduction to the ordering constraints, see the
2246:doc:`Atomics`.
2247
2248``unordered``
2249 The set of values that can be read is governed by the happens-before
2250 partial order. A value cannot be read unless some operation wrote
2251 it. This is intended to provide a guarantee strong enough to model
2252 Java's non-volatile shared variables. This ordering cannot be
2253 specified for read-modify-write operations; it is not strong enough
2254 to make them atomic in any interesting way.
2255``monotonic``
2256 In addition to the guarantees of ``unordered``, there is a single
2257 total order for modifications by ``monotonic`` operations on each
2258 address. All modification orders must be compatible with the
2259 happens-before order. There is no guarantee that the modification
2260 orders can be combined to a global total order for the whole program
2261 (and this often will not be possible). The read in an atomic
2262 read-modify-write operation (:ref:`cmpxchg <i_cmpxchg>` and
2263 :ref:`atomicrmw <i_atomicrmw>`) reads the value in the modification
2264 order immediately before the value it writes. If one atomic read
2265 happens before another atomic read of the same address, the later
2266 read must see the same value or a later value in the address's
2267 modification order. This disallows reordering of ``monotonic`` (or
2268 stronger) operations on the same address. If an address is written
2269 ``monotonic``-ally by one thread, and other threads ``monotonic``-ally
2270 read that address repeatedly, the other threads must eventually see
2271 the write. This corresponds to the C++0x/C1x
2272 ``memory_order_relaxed``.
2273``acquire``
2274 In addition to the guarantees of ``monotonic``, a
2275 *synchronizes-with* edge may be formed with a ``release`` operation.
2276 This is intended to model C++'s ``memory_order_acquire``.
2277``release``
2278 In addition to the guarantees of ``monotonic``, if this operation
2279 writes a value which is subsequently read by an ``acquire``
2280 operation, it *synchronizes-with* that operation. (This isn't a
2281 complete description; see the C++0x definition of a release
2282 sequence.) This corresponds to the C++0x/C1x
2283 ``memory_order_release``.
2284``acq_rel`` (acquire+release)
2285 Acts as both an ``acquire`` and ``release`` operation on its
2286 address. This corresponds to the C++0x/C1x ``memory_order_acq_rel``.
2287``seq_cst`` (sequentially consistent)
2288 In addition to the guarantees of ``acq_rel`` (``acquire`` for an
Richard Smith32dbdf62014-07-31 04:25:36 +00002289 operation that only reads, ``release`` for an operation that only
Sean Silvab084af42012-12-07 10:36:55 +00002290 writes), there is a global total order on all
2291 sequentially-consistent operations on all addresses, which is
2292 consistent with the *happens-before* partial order and with the
2293 modification orders of all the affected addresses. Each
2294 sequentially-consistent read sees the last preceding write to the
2295 same address in this global order. This corresponds to the C++0x/C1x
2296 ``memory_order_seq_cst`` and Java volatile.
2297
Konstantin Zhuravlyovbb80d3e2017-07-11 22:23:00 +00002298.. _syncscope:
Sean Silvab084af42012-12-07 10:36:55 +00002299
Konstantin Zhuravlyovbb80d3e2017-07-11 22:23:00 +00002300If an atomic operation is marked ``syncscope("singlethread")``, it only
2301*synchronizes with* and only participates in the seq\_cst total orderings of
2302other operations running in the same thread (for example, in signal handlers).
2303
2304If an atomic operation is marked ``syncscope("<target-scope>")``, where
2305``<target-scope>`` is a target specific synchronization scope, then it is target
2306dependent if it *synchronizes with* and participates in the seq\_cst total
2307orderings of other operations.
2308
2309Otherwise, an atomic operation that is not marked ``syncscope("singlethread")``
2310or ``syncscope("<target-scope>")`` *synchronizes with* and participates in the
2311seq\_cst total orderings of other operations that are not marked
2312``syncscope("singlethread")`` or ``syncscope("<target-scope>")``.
Sean Silvab084af42012-12-07 10:36:55 +00002313
Sanjay Patel54b161e2018-03-20 16:38:22 +00002314.. _floatenv:
2315
2316Floating-Point Environment
2317--------------------------
2318
2319The default LLVM floating-point environment assumes that floating-point
2320instructions do not have side effects. Results assume the round-to-nearest
2321rounding mode. No floating-point exception state is maintained in this
2322environment. Therefore, there is no attempt to create or preserve invalid
2323operation (SNaN) or division-by-zero exceptions in these examples:
2324
2325.. code-block:: llvm
2326
2327 %A = fdiv 0x7ff0000000000001, %X ; 64-bit SNaN hex value
2328 %B = fdiv %X, 0.0
2329 Safe:
2330 %A = NaN
2331 %B = NaN
2332
2333The benefit of this exception-free assumption is that floating-point
2334operations may be speculated freely without any other fast-math relaxations
2335to the floating-point model.
2336
2337Code that requires different behavior than this should use the
Sanjay Patelec95e0e2018-03-20 17:05:19 +00002338:ref:`Constrained Floating-Point Intrinsics <constrainedfp>`.
Sanjay Patel54b161e2018-03-20 16:38:22 +00002339
Sean Silvab084af42012-12-07 10:36:55 +00002340.. _fastmath:
2341
2342Fast-Math Flags
2343---------------
2344
Sanjay Patel629c4112017-11-06 16:27:15 +00002345LLVM IR floating-point operations (:ref:`fadd <i_fadd>`,
Sean Silvab084af42012-12-07 10:36:55 +00002346:ref:`fsub <i_fsub>`, :ref:`fmul <i_fmul>`, :ref:`fdiv <i_fdiv>`,
Matt Arsenault74b73e52017-01-10 18:06:38 +00002347:ref:`frem <i_frem>`, :ref:`fcmp <i_fcmp>`) and :ref:`call <i_call>`
Elena Demikhovsky945b7e52018-02-14 06:58:08 +00002348may use the following flags to enable otherwise unsafe
Sanjay Patel629c4112017-11-06 16:27:15 +00002349floating-point transformations.
Sean Silvab084af42012-12-07 10:36:55 +00002350
2351``nnan``
2352 No NaNs - Allow optimizations to assume the arguments and result are not
Eli Friedmand3a30872018-07-17 20:31:42 +00002353 NaN. If an argument is a nan, or the result would be a nan, it produces
2354 a :ref:`poison value <poisonvalues>` instead.
Sean Silvab084af42012-12-07 10:36:55 +00002355
2356``ninf``
2357 No Infs - Allow optimizations to assume the arguments and result are not
Eli Friedmand3a30872018-07-17 20:31:42 +00002358 +/-Inf. If an argument is +/-Inf, or the result would be +/-Inf, it
2359 produces a :ref:`poison value <poisonvalues>` instead.
Sean Silvab084af42012-12-07 10:36:55 +00002360
2361``nsz``
2362 No Signed Zeros - Allow optimizations to treat the sign of a zero
2363 argument or result as insignificant.
2364
2365``arcp``
2366 Allow Reciprocal - Allow optimizations to use the reciprocal of an
2367 argument rather than perform division.
2368
Adam Nemetcd847a82017-03-28 20:11:52 +00002369``contract``
2370 Allow floating-point contraction (e.g. fusing a multiply followed by an
2371 addition into a fused multiply-and-add).
2372
Sanjay Patel629c4112017-11-06 16:27:15 +00002373``afn``
2374 Approximate functions - Allow substitution of approximate calculations for
Elena Demikhovsky945b7e52018-02-14 06:58:08 +00002375 functions (sin, log, sqrt, etc). See floating-point intrinsic definitions
2376 for places where this can apply to LLVM's intrinsic math functions.
Sanjay Patel629c4112017-11-06 16:27:15 +00002377
2378``reassoc``
Elena Demikhovsky945b7e52018-02-14 06:58:08 +00002379 Allow reassociation transformations for floating-point instructions.
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00002380 This may dramatically change results in floating-point.
Sanjay Patel629c4112017-11-06 16:27:15 +00002381
Sean Silvab084af42012-12-07 10:36:55 +00002382``fast``
Sanjay Patel629c4112017-11-06 16:27:15 +00002383 This flag implies all of the others.
Sean Silvab084af42012-12-07 10:36:55 +00002384
Duncan P. N. Exon Smith0a448fb2014-08-19 21:30:15 +00002385.. _uselistorder:
2386
2387Use-list Order Directives
2388-------------------------
2389
2390Use-list directives encode the in-memory order of each use-list, allowing the
Sean Silvaa1190322015-08-06 22:56:48 +00002391order to be recreated. ``<order-indexes>`` is a comma-separated list of
2392indexes that are assigned to the referenced value's uses. The referenced
Duncan P. N. Exon Smith0a448fb2014-08-19 21:30:15 +00002393value's use-list is immediately sorted by these indexes.
2394
Sean Silvaa1190322015-08-06 22:56:48 +00002395Use-list directives may appear at function scope or global scope. They are not
2396instructions, and have no effect on the semantics of the IR. When they're at
Duncan P. N. Exon Smith0a448fb2014-08-19 21:30:15 +00002397function scope, they must appear after the terminator of the final basic block.
2398
2399If basic blocks have their address taken via ``blockaddress()`` expressions,
2400``uselistorder_bb`` can be used to reorder their use-lists from outside their
2401function's scope.
2402
2403:Syntax:
2404
2405::
2406
2407 uselistorder <ty> <value>, { <order-indexes> }
2408 uselistorder_bb @function, %block { <order-indexes> }
2409
2410:Examples:
2411
2412::
2413
Duncan P. N. Exon Smith23046652014-08-19 21:48:04 +00002414 define void @foo(i32 %arg1, i32 %arg2) {
2415 entry:
2416 ; ... instructions ...
2417 bb:
2418 ; ... instructions ...
2419
2420 ; At function scope.
2421 uselistorder i32 %arg1, { 1, 0, 2 }
2422 uselistorder label %bb, { 1, 0 }
2423 }
Duncan P. N. Exon Smith0a448fb2014-08-19 21:30:15 +00002424
2425 ; At global scope.
2426 uselistorder i32* @global, { 1, 2, 0 }
2427 uselistorder i32 7, { 1, 0 }
2428 uselistorder i32 (i32) @bar, { 1, 0 }
2429 uselistorder_bb @foo, %bb, { 5, 1, 3, 2, 0, 4 }
2430
Teresa Johnsonde9b8b42016-04-22 13:09:17 +00002431.. _source_filename:
2432
2433Source Filename
2434---------------
2435
2436The *source filename* string is set to the original module identifier,
2437which will be the name of the compiled source file when compiling from
2438source through the clang front end, for example. It is then preserved through
2439the IR and bitcode.
2440
2441This is currently necessary to generate a consistent unique global
2442identifier for local functions used in profile data, which prepends the
2443source file name to the local function name.
2444
2445The syntax for the source file name is simply:
2446
Renato Golin124f2592016-07-20 12:16:38 +00002447.. code-block:: text
Teresa Johnsonde9b8b42016-04-22 13:09:17 +00002448
2449 source_filename = "/path/to/source.c"
2450
Sean Silvab084af42012-12-07 10:36:55 +00002451.. _typesystem:
2452
2453Type System
2454===========
2455
2456The LLVM type system is one of the most important features of the
2457intermediate representation. Being typed enables a number of
2458optimizations to be performed on the intermediate representation
2459directly, without having to do extra analyses on the side before the
2460transformation. A strong type system makes it easier to read the
2461generated code and enables novel analyses and transformations that are
2462not feasible to perform on normal three address code representations.
2463
Rafael Espindola08013342013-12-07 19:34:20 +00002464.. _t_void:
Eli Bendersky0220e6b2013-06-07 20:24:43 +00002465
Rafael Espindola08013342013-12-07 19:34:20 +00002466Void Type
2467---------
Sean Silvab084af42012-12-07 10:36:55 +00002468
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002469:Overview:
2470
Rafael Espindola08013342013-12-07 19:34:20 +00002471
2472The void type does not represent any value and has no size.
2473
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002474:Syntax:
2475
Rafael Espindola08013342013-12-07 19:34:20 +00002476
2477::
2478
2479 void
Sean Silvab084af42012-12-07 10:36:55 +00002480
2481
Rafael Espindola08013342013-12-07 19:34:20 +00002482.. _t_function:
Sean Silvab084af42012-12-07 10:36:55 +00002483
Rafael Espindola08013342013-12-07 19:34:20 +00002484Function Type
2485-------------
Sean Silvab084af42012-12-07 10:36:55 +00002486
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002487:Overview:
2488
Sean Silvab084af42012-12-07 10:36:55 +00002489
Rafael Espindola08013342013-12-07 19:34:20 +00002490The function type can be thought of as a function signature. It consists of a
2491return type and a list of formal parameter types. The return type of a function
2492type is a void type or first class type --- except for :ref:`label <t_label>`
2493and :ref:`metadata <t_metadata>` types.
Sean Silvab084af42012-12-07 10:36:55 +00002494
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002495:Syntax:
Sean Silvab084af42012-12-07 10:36:55 +00002496
Rafael Espindola08013342013-12-07 19:34:20 +00002497::
Sean Silvab084af42012-12-07 10:36:55 +00002498
Rafael Espindola08013342013-12-07 19:34:20 +00002499 <returntype> (<parameter list>)
Sean Silvab084af42012-12-07 10:36:55 +00002500
Rafael Espindola08013342013-12-07 19:34:20 +00002501...where '``<parameter list>``' is a comma-separated list of type
2502specifiers. Optionally, the parameter list may include a type ``...``, which
Sean Silvaa1190322015-08-06 22:56:48 +00002503indicates that the function takes a variable number of arguments. Variable
Rafael Espindola08013342013-12-07 19:34:20 +00002504argument functions can access their arguments with the :ref:`variable argument
Sean Silvaa1190322015-08-06 22:56:48 +00002505handling intrinsic <int_varargs>` functions. '``<returntype>``' is any type
Rafael Espindola08013342013-12-07 19:34:20 +00002506except :ref:`label <t_label>` and :ref:`metadata <t_metadata>`.
Sean Silvab084af42012-12-07 10:36:55 +00002507
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002508:Examples:
Sean Silvab084af42012-12-07 10:36:55 +00002509
Rafael Espindola08013342013-12-07 19:34:20 +00002510+---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
2511| ``i32 (i32)`` | function taking an ``i32``, returning an ``i32`` |
2512+---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
2513| ``float (i16, i32 *) *`` | :ref:`Pointer <t_pointer>` to a function that takes an ``i16`` and a :ref:`pointer <t_pointer>` to ``i32``, returning ``float``. |
2514+---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
2515| ``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. |
2516+---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
2517| ``{i32, i32} (i32)`` | A function taking an ``i32``, returning a :ref:`structure <t_struct>` containing two ``i32`` values |
2518+---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
2519
2520.. _t_firstclass:
2521
2522First Class Types
2523-----------------
Sean Silvab084af42012-12-07 10:36:55 +00002524
2525The :ref:`first class <t_firstclass>` types are perhaps the most important.
2526Values of these types are the only ones which can be produced by
2527instructions.
2528
Rafael Espindola08013342013-12-07 19:34:20 +00002529.. _t_single_value:
Sean Silvab084af42012-12-07 10:36:55 +00002530
Rafael Espindola08013342013-12-07 19:34:20 +00002531Single Value Types
2532^^^^^^^^^^^^^^^^^^
Sean Silvab084af42012-12-07 10:36:55 +00002533
Rafael Espindola08013342013-12-07 19:34:20 +00002534These are the types that are valid in registers from CodeGen's perspective.
Sean Silvab084af42012-12-07 10:36:55 +00002535
2536.. _t_integer:
2537
2538Integer Type
Rafael Espindola08013342013-12-07 19:34:20 +00002539""""""""""""
Sean Silvab084af42012-12-07 10:36:55 +00002540
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002541:Overview:
Sean Silvab084af42012-12-07 10:36:55 +00002542
2543The integer type is a very simple type that simply specifies an
2544arbitrary bit width for the integer type desired. Any bit width from 1
2545bit to 2\ :sup:`23`\ -1 (about 8 million) can be specified.
2546
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002547:Syntax:
Sean Silvab084af42012-12-07 10:36:55 +00002548
2549::
2550
2551 iN
2552
2553The number of bits the integer will occupy is specified by the ``N``
2554value.
2555
2556Examples:
Rafael Espindola08013342013-12-07 19:34:20 +00002557*********
Sean Silvab084af42012-12-07 10:36:55 +00002558
2559+----------------+------------------------------------------------+
2560| ``i1`` | a single-bit integer. |
2561+----------------+------------------------------------------------+
2562| ``i32`` | a 32-bit integer. |
2563+----------------+------------------------------------------------+
2564| ``i1942652`` | a really big integer of over 1 million bits. |
2565+----------------+------------------------------------------------+
2566
2567.. _t_floating:
2568
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00002569Floating-Point Types
Rafael Espindola08013342013-12-07 19:34:20 +00002570""""""""""""""""""""
Sean Silvab084af42012-12-07 10:36:55 +00002571
2572.. list-table::
2573 :header-rows: 1
2574
2575 * - Type
2576 - Description
2577
2578 * - ``half``
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00002579 - 16-bit floating-point value
Sean Silvab084af42012-12-07 10:36:55 +00002580
2581 * - ``float``
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00002582 - 32-bit floating-point value
Sean Silvab084af42012-12-07 10:36:55 +00002583
2584 * - ``double``
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00002585 - 64-bit floating-point value
Sean Silvab084af42012-12-07 10:36:55 +00002586
2587 * - ``fp128``
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00002588 - 128-bit floating-point value (112-bit mantissa)
Sean Silvab084af42012-12-07 10:36:55 +00002589
2590 * - ``x86_fp80``
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00002591 - 80-bit floating-point value (X87)
Sean Silvab084af42012-12-07 10:36:55 +00002592
2593 * - ``ppc_fp128``
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00002594 - 128-bit floating-point value (two 64-bits)
Sean Silvab084af42012-12-07 10:36:55 +00002595
Sanjay Patelbab6ce02018-03-21 15:22:09 +00002596The binary format of half, float, double, and fp128 correspond to the
2597IEEE-754-2008 specifications for binary16, binary32, binary64, and binary128
2598respectively.
2599
Reid Kleckner9a16d082014-03-05 02:41:37 +00002600X86_mmx Type
2601""""""""""""
Sean Silvab084af42012-12-07 10:36:55 +00002602
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002603:Overview:
Sean Silvab084af42012-12-07 10:36:55 +00002604
Reid Kleckner9a16d082014-03-05 02:41:37 +00002605The x86_mmx type represents a value held in an MMX register on an x86
Sean Silvab084af42012-12-07 10:36:55 +00002606machine. The operations allowed on it are quite limited: parameters and
2607return values, load and store, and bitcast. User-specified MMX
2608instructions are represented as intrinsic or asm calls with arguments
2609and/or results of this type. There are no arrays, vectors or constants
2610of this type.
2611
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002612:Syntax:
Sean Silvab084af42012-12-07 10:36:55 +00002613
2614::
2615
Reid Kleckner9a16d082014-03-05 02:41:37 +00002616 x86_mmx
Sean Silvab084af42012-12-07 10:36:55 +00002617
Sean Silvab084af42012-12-07 10:36:55 +00002618
Rafael Espindola08013342013-12-07 19:34:20 +00002619.. _t_pointer:
2620
2621Pointer Type
2622""""""""""""
Sean Silvab084af42012-12-07 10:36:55 +00002623
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002624:Overview:
Sean Silvab084af42012-12-07 10:36:55 +00002625
Rafael Espindola08013342013-12-07 19:34:20 +00002626The pointer type is used to specify memory locations. Pointers are
2627commonly used to reference objects in memory.
2628
2629Pointer types may have an optional address space attribute defining the
2630numbered address space where the pointed-to object resides. The default
2631address space is number zero. The semantics of non-zero address spaces
2632are target-specific.
2633
2634Note that LLVM does not permit pointers to void (``void*``) nor does it
2635permit pointers to labels (``label*``). Use ``i8*`` instead.
Sean Silvab084af42012-12-07 10:36:55 +00002636
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002637:Syntax:
Sean Silvab084af42012-12-07 10:36:55 +00002638
2639::
2640
Rafael Espindola08013342013-12-07 19:34:20 +00002641 <type> *
2642
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002643:Examples:
Rafael Espindola08013342013-12-07 19:34:20 +00002644
2645+-------------------------+--------------------------------------------------------------------------------------------------------------+
2646| ``[4 x i32]*`` | A :ref:`pointer <t_pointer>` to :ref:`array <t_array>` of four ``i32`` values. |
2647+-------------------------+--------------------------------------------------------------------------------------------------------------+
2648| ``i32 (i32*) *`` | A :ref:`pointer <t_pointer>` to a :ref:`function <t_function>` that takes an ``i32*``, returning an ``i32``. |
2649+-------------------------+--------------------------------------------------------------------------------------------------------------+
2650| ``i32 addrspace(5)*`` | A :ref:`pointer <t_pointer>` to an ``i32`` value that resides in address space #5. |
2651+-------------------------+--------------------------------------------------------------------------------------------------------------+
2652
2653.. _t_vector:
2654
2655Vector Type
2656"""""""""""
2657
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002658:Overview:
Rafael Espindola08013342013-12-07 19:34:20 +00002659
2660A vector type is a simple derived type that represents a vector of
2661elements. Vector types are used when multiple primitive data are
2662operated in parallel using a single instruction (SIMD). A vector type
2663requires a size (number of elements) and an underlying primitive data
2664type. Vector types are considered :ref:`first class <t_firstclass>`.
2665
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002666:Syntax:
Rafael Espindola08013342013-12-07 19:34:20 +00002667
2668::
2669
2670 < <# elements> x <elementtype> >
2671
2672The number of elements is a constant integer value larger than 0;
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00002673elementtype may be any integer, floating-point or pointer type. Vectors
Manuel Jacob961f7872014-07-30 12:30:06 +00002674of size zero are not allowed.
Rafael Espindola08013342013-12-07 19:34:20 +00002675
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002676:Examples:
Rafael Espindola08013342013-12-07 19:34:20 +00002677
2678+-------------------+--------------------------------------------------+
2679| ``<4 x i32>`` | Vector of 4 32-bit integer values. |
2680+-------------------+--------------------------------------------------+
2681| ``<8 x float>`` | Vector of 8 32-bit floating-point values. |
2682+-------------------+--------------------------------------------------+
2683| ``<2 x i64>`` | Vector of 2 64-bit integer values. |
2684+-------------------+--------------------------------------------------+
2685| ``<4 x i64*>`` | Vector of 4 pointers to 64-bit integer values. |
2686+-------------------+--------------------------------------------------+
Sean Silvab084af42012-12-07 10:36:55 +00002687
2688.. _t_label:
2689
2690Label Type
2691^^^^^^^^^^
2692
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002693:Overview:
Sean Silvab084af42012-12-07 10:36:55 +00002694
2695The label type represents code labels.
2696
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002697:Syntax:
Sean Silvab084af42012-12-07 10:36:55 +00002698
2699::
2700
2701 label
2702
David Majnemerb611e3f2015-08-14 05:09:07 +00002703.. _t_token:
2704
2705Token Type
2706^^^^^^^^^^
2707
2708:Overview:
2709
2710The token type is used when a value is associated with an instruction
2711but all uses of the value must not attempt to introspect or obscure it.
2712As such, it is not appropriate to have a :ref:`phi <i_phi>` or
2713:ref:`select <i_select>` of type token.
2714
2715:Syntax:
2716
2717::
2718
2719 token
2720
2721
2722
Sean Silvab084af42012-12-07 10:36:55 +00002723.. _t_metadata:
2724
2725Metadata Type
2726^^^^^^^^^^^^^
2727
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002728:Overview:
Sean Silvab084af42012-12-07 10:36:55 +00002729
2730The metadata type represents embedded metadata. No derived types may be
2731created from metadata except for :ref:`function <t_function>` arguments.
2732
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002733:Syntax:
Sean Silvab084af42012-12-07 10:36:55 +00002734
2735::
2736
2737 metadata
2738
Sean Silvab084af42012-12-07 10:36:55 +00002739.. _t_aggregate:
2740
2741Aggregate Types
2742^^^^^^^^^^^^^^^
2743
2744Aggregate Types are a subset of derived types that can contain multiple
2745member types. :ref:`Arrays <t_array>` and :ref:`structs <t_struct>` are
2746aggregate types. :ref:`Vectors <t_vector>` are not considered to be
2747aggregate types.
2748
2749.. _t_array:
2750
2751Array Type
Rafael Espindola08013342013-12-07 19:34:20 +00002752""""""""""
Sean Silvab084af42012-12-07 10:36:55 +00002753
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002754:Overview:
Sean Silvab084af42012-12-07 10:36:55 +00002755
2756The array type is a very simple derived type that arranges elements
2757sequentially in memory. The array type requires a size (number of
2758elements) and an underlying data type.
2759
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002760:Syntax:
Sean Silvab084af42012-12-07 10:36:55 +00002761
2762::
2763
2764 [<# elements> x <elementtype>]
2765
2766The number of elements is a constant integer value; ``elementtype`` may
2767be any type with a size.
2768
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002769:Examples:
Sean Silvab084af42012-12-07 10:36:55 +00002770
2771+------------------+--------------------------------------+
2772| ``[40 x i32]`` | Array of 40 32-bit integer values. |
2773+------------------+--------------------------------------+
2774| ``[41 x i32]`` | Array of 41 32-bit integer values. |
2775+------------------+--------------------------------------+
2776| ``[4 x i8]`` | Array of 4 8-bit integer values. |
2777+------------------+--------------------------------------+
2778
2779Here are some examples of multidimensional arrays:
2780
2781+-----------------------------+----------------------------------------------------------+
2782| ``[3 x [4 x i32]]`` | 3x4 array of 32-bit integer values. |
2783+-----------------------------+----------------------------------------------------------+
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00002784| ``[12 x [10 x float]]`` | 12x10 array of single precision floating-point values. |
Sean Silvab084af42012-12-07 10:36:55 +00002785+-----------------------------+----------------------------------------------------------+
2786| ``[2 x [3 x [4 x i16]]]`` | 2x3x4 array of 16-bit integer values. |
2787+-----------------------------+----------------------------------------------------------+
2788
2789There is no restriction on indexing beyond the end of the array implied
2790by a static type (though there are restrictions on indexing beyond the
2791bounds of an allocated object in some cases). This means that
2792single-dimension 'variable sized array' addressing can be implemented in
2793LLVM with a zero length array type. An implementation of 'pascal style
2794arrays' in LLVM could use the type "``{ i32, [0 x float]}``", for
2795example.
2796
Sean Silvab084af42012-12-07 10:36:55 +00002797.. _t_struct:
2798
2799Structure Type
Rafael Espindola08013342013-12-07 19:34:20 +00002800""""""""""""""
Sean Silvab084af42012-12-07 10:36:55 +00002801
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002802:Overview:
Sean Silvab084af42012-12-07 10:36:55 +00002803
2804The structure type is used to represent a collection of data members
2805together in memory. The elements of a structure may be any type that has
2806a size.
2807
2808Structures in memory are accessed using '``load``' and '``store``' by
2809getting a pointer to a field with the '``getelementptr``' instruction.
2810Structures in registers are accessed using the '``extractvalue``' and
2811'``insertvalue``' instructions.
2812
2813Structures may optionally be "packed" structures, which indicate that
2814the alignment of the struct is one byte, and that there is no padding
2815between the elements. In non-packed structs, padding between field types
2816is inserted as defined by the DataLayout string in the module, which is
2817required to match what the underlying code generator expects.
2818
2819Structures can either be "literal" or "identified". A literal structure
2820is defined inline with other types (e.g. ``{i32, i32}*``) whereas
2821identified types are always defined at the top level with a name.
2822Literal types are uniqued by their contents and can never be recursive
2823or opaque since there is no way to write one. Identified types can be
2824recursive, can be opaqued, and are never uniqued.
2825
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002826:Syntax:
Sean Silvab084af42012-12-07 10:36:55 +00002827
2828::
2829
2830 %T1 = type { <type list> } ; Identified normal struct type
2831 %T2 = type <{ <type list> }> ; Identified packed struct type
2832
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002833:Examples:
Sean Silvab084af42012-12-07 10:36:55 +00002834
2835+------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
2836| ``{ i32, i32, i32 }`` | A triple of three ``i32`` values |
2837+------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
Daniel Dunbar1dc66ca2013-01-17 18:57:32 +00002838| ``{ 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 +00002839+------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
2840| ``<{ i8, i32 }>`` | A packed struct known to be 5 bytes in size. |
2841+------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
2842
2843.. _t_opaque:
2844
2845Opaque Structure Types
Rafael Espindola08013342013-12-07 19:34:20 +00002846""""""""""""""""""""""
Sean Silvab084af42012-12-07 10:36:55 +00002847
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002848:Overview:
Sean Silvab084af42012-12-07 10:36:55 +00002849
2850Opaque structure types are used to represent named structure types that
2851do not have a body specified. This corresponds (for example) to the C
2852notion of a forward declared structure.
2853
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002854:Syntax:
Sean Silvab084af42012-12-07 10:36:55 +00002855
2856::
2857
2858 %X = type opaque
2859 %52 = type opaque
2860
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002861:Examples:
Sean Silvab084af42012-12-07 10:36:55 +00002862
2863+--------------+-------------------+
2864| ``opaque`` | An opaque type. |
2865+--------------+-------------------+
2866
Sean Silva1703e702014-04-08 21:06:22 +00002867.. _constants:
2868
Sean Silvab084af42012-12-07 10:36:55 +00002869Constants
2870=========
2871
2872LLVM has several different basic types of constants. This section
2873describes them all and their syntax.
2874
2875Simple Constants
2876----------------
2877
2878**Boolean constants**
2879 The two strings '``true``' and '``false``' are both valid constants
2880 of the ``i1`` type.
2881**Integer constants**
2882 Standard integers (such as '4') are constants of the
2883 :ref:`integer <t_integer>` type. Negative numbers may be used with
2884 integer types.
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00002885**Floating-point constants**
2886 Floating-point constants use standard decimal notation (e.g.
Sean Silvab084af42012-12-07 10:36:55 +00002887 123.421), exponential notation (e.g. 1.23421e+2), or a more precise
2888 hexadecimal notation (see below). The assembler requires the exact
2889 decimal value of a floating-point constant. For example, the
2890 assembler accepts 1.25 but rejects 1.3 because 1.3 is a repeating
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00002891 decimal in binary. Floating-point constants must have a
2892 :ref:`floating-point <t_floating>` type.
Sean Silvab084af42012-12-07 10:36:55 +00002893**Null pointer constants**
2894 The identifier '``null``' is recognized as a null pointer constant
2895 and must be of :ref:`pointer type <t_pointer>`.
David Majnemerf0f224d2015-11-11 21:57:16 +00002896**Token constants**
2897 The identifier '``none``' is recognized as an empty token constant
2898 and must be of :ref:`token type <t_token>`.
Sean Silvab084af42012-12-07 10:36:55 +00002899
2900The one non-intuitive notation for constants is the hexadecimal form of
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00002901floating-point constants. For example, the form
Sean Silvab084af42012-12-07 10:36:55 +00002902'``double 0x432ff973cafa8000``' is equivalent to (but harder to read
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00002903than) '``double 4.5e+15``'. The only time hexadecimal floating-point
Sean Silvab084af42012-12-07 10:36:55 +00002904constants are required (and the only time that they are generated by the
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00002905disassembler) is when a floating-point constant must be emitted but it
2906cannot be represented as a decimal floating-point number in a reasonable
Sean Silvab084af42012-12-07 10:36:55 +00002907number of digits. For example, NaN's, infinities, and other special
2908values are represented in their IEEE hexadecimal format so that assembly
2909and disassembly do not cause any bits to change in the constants.
2910
2911When using the hexadecimal form, constants of types half, float, and
2912double are represented using the 16-digit form shown above (which
2913matches the IEEE754 representation for double); half and float values
Dmitri Gribenko4dc2ba12013-01-16 23:40:37 +00002914must, however, be exactly representable as IEEE 754 half and single
Sean Silvab084af42012-12-07 10:36:55 +00002915precision, respectively. Hexadecimal format is always used for long
2916double, and there are three forms of long double. The 80-bit format used
2917by x86 is represented as ``0xK`` followed by 20 hexadecimal digits. The
2918128-bit format used by PowerPC (two adjacent doubles) is represented by
2919``0xM`` followed by 32 hexadecimal digits. The IEEE 128-bit format is
Richard Sandifordae426b42013-05-03 14:32:27 +00002920represented by ``0xL`` followed by 32 hexadecimal digits. Long doubles
2921will only work if they match the long double format on your target.
2922The IEEE 16-bit format (half precision) is represented by ``0xH``
2923followed by 4 hexadecimal digits. All hexadecimal formats are big-endian
2924(sign bit at the left).
Sean Silvab084af42012-12-07 10:36:55 +00002925
Reid Kleckner9a16d082014-03-05 02:41:37 +00002926There are no constants of type x86_mmx.
Sean Silvab084af42012-12-07 10:36:55 +00002927
Eli Bendersky0220e6b2013-06-07 20:24:43 +00002928.. _complexconstants:
2929
Sean Silvab084af42012-12-07 10:36:55 +00002930Complex Constants
2931-----------------
2932
2933Complex constants are a (potentially recursive) combination of simple
2934constants and smaller complex constants.
2935
2936**Structure constants**
2937 Structure constants are represented with notation similar to
2938 structure type definitions (a comma separated list of elements,
2939 surrounded by braces (``{}``)). For example:
2940 "``{ i32 4, float 17.0, i32* @G }``", where "``@G``" is declared as
2941 "``@G = external global i32``". Structure constants must have
2942 :ref:`structure type <t_struct>`, and the number and types of elements
2943 must match those specified by the type.
2944**Array constants**
2945 Array constants are represented with notation similar to array type
2946 definitions (a comma separated list of elements, surrounded by
2947 square brackets (``[]``)). For example:
2948 "``[ i32 42, i32 11, i32 74 ]``". Array constants must have
2949 :ref:`array type <t_array>`, and the number and types of elements must
Daniel Sandersf6051842014-09-11 12:02:59 +00002950 match those specified by the type. As a special case, character array
2951 constants may also be represented as a double-quoted string using the ``c``
2952 prefix. For example: "``c"Hello World\0A\00"``".
Sean Silvab084af42012-12-07 10:36:55 +00002953**Vector constants**
2954 Vector constants are represented with notation similar to vector
2955 type definitions (a comma separated list of elements, surrounded by
2956 less-than/greater-than's (``<>``)). For example:
2957 "``< i32 42, i32 11, i32 74, i32 100 >``". Vector constants
2958 must have :ref:`vector type <t_vector>`, and the number and types of
2959 elements must match those specified by the type.
2960**Zero initialization**
2961 The string '``zeroinitializer``' can be used to zero initialize a
2962 value to zero of *any* type, including scalar and
2963 :ref:`aggregate <t_aggregate>` types. This is often used to avoid
2964 having to print large zero initializers (e.g. for large arrays) and
2965 is always exactly equivalent to using explicit zero initializers.
2966**Metadata node**
Sean Silvaa1190322015-08-06 22:56:48 +00002967 A metadata node is a constant tuple without types. For example:
2968 "``!{!0, !{!2, !0}, !"test"}``". Metadata can reference constant values,
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00002969 for example: "``!{!0, i32 0, i8* @global, i64 (i64)* @function, !"str"}``".
2970 Unlike other typed constants that are meant to be interpreted as part of
2971 the instruction stream, metadata is a place to attach additional
Sean Silvab084af42012-12-07 10:36:55 +00002972 information such as debug info.
2973
2974Global Variable and Function Addresses
2975--------------------------------------
2976
2977The addresses of :ref:`global variables <globalvars>` and
2978:ref:`functions <functionstructure>` are always implicitly valid
2979(link-time) constants. These constants are explicitly referenced when
2980the :ref:`identifier for the global <identifiers>` is used and always have
2981:ref:`pointer <t_pointer>` type. For example, the following is a legal LLVM
2982file:
2983
2984.. code-block:: llvm
2985
2986 @X = global i32 17
2987 @Y = global i32 42
2988 @Z = global [2 x i32*] [ i32* @X, i32* @Y ]
2989
2990.. _undefvalues:
2991
2992Undefined Values
2993----------------
2994
2995The string '``undef``' can be used anywhere a constant is expected, and
2996indicates that the user of the value may receive an unspecified
2997bit-pattern. Undefined values may be of any type (other than '``label``'
2998or '``void``') and be used anywhere a constant is permitted.
2999
3000Undefined values are useful because they indicate to the compiler that
3001the program is well defined no matter what value is used. This gives the
3002compiler more freedom to optimize. Here are some examples of
3003(potentially surprising) transformations that are valid (in pseudo IR):
3004
3005.. code-block:: llvm
3006
3007 %A = add %X, undef
3008 %B = sub %X, undef
3009 %C = xor %X, undef
3010 Safe:
3011 %A = undef
3012 %B = undef
3013 %C = undef
3014
3015This is safe because all of the output bits are affected by the undef
3016bits. Any output bit can have a zero or one depending on the input bits.
3017
3018.. code-block:: llvm
3019
3020 %A = or %X, undef
3021 %B = and %X, undef
3022 Safe:
3023 %A = -1
3024 %B = 0
Sanjoy Das151493a2016-09-15 01:56:58 +00003025 Safe:
3026 %A = %X ;; By choosing undef as 0
3027 %B = %X ;; By choosing undef as -1
Sean Silvab084af42012-12-07 10:36:55 +00003028 Unsafe:
3029 %A = undef
3030 %B = undef
3031
3032These logical operations have bits that are not always affected by the
3033input. For example, if ``%X`` has a zero bit, then the output of the
3034'``and``' operation will always be a zero for that bit, no matter what
3035the corresponding bit from the '``undef``' is. As such, it is unsafe to
3036optimize or assume that the result of the '``and``' is '``undef``'.
3037However, it is safe to assume that all bits of the '``undef``' could be
30380, and optimize the '``and``' to 0. Likewise, it is safe to assume that
3039all the bits of the '``undef``' operand to the '``or``' could be set,
3040allowing the '``or``' to be folded to -1.
3041
3042.. code-block:: llvm
3043
3044 %A = select undef, %X, %Y
3045 %B = select undef, 42, %Y
3046 %C = select %X, %Y, undef
3047 Safe:
3048 %A = %X (or %Y)
3049 %B = 42 (or %Y)
3050 %C = %Y
3051 Unsafe:
3052 %A = undef
3053 %B = undef
3054 %C = undef
3055
3056This set of examples shows that undefined '``select``' (and conditional
3057branch) conditions can go *either way*, but they have to come from one
3058of the two operands. In the ``%A`` example, if ``%X`` and ``%Y`` were
3059both known to have a clear low bit, then ``%A`` would have to have a
3060cleared low bit. However, in the ``%C`` example, the optimizer is
3061allowed to assume that the '``undef``' operand could be the same as
3062``%Y``, allowing the whole '``select``' to be eliminated.
3063
Renato Golin124f2592016-07-20 12:16:38 +00003064.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00003065
3066 %A = xor undef, undef
3067
3068 %B = undef
3069 %C = xor %B, %B
3070
3071 %D = undef
Jonathan Roelofsec81c0b2014-10-16 19:28:10 +00003072 %E = icmp slt %D, 4
Sean Silvab084af42012-12-07 10:36:55 +00003073 %F = icmp gte %D, 4
3074
3075 Safe:
3076 %A = undef
3077 %B = undef
3078 %C = undef
3079 %D = undef
3080 %E = undef
3081 %F = undef
3082
3083This example points out that two '``undef``' operands are not
3084necessarily the same. This can be surprising to people (and also matches
3085C semantics) where they assume that "``X^X``" is always zero, even if
3086``X`` is undefined. This isn't true for a number of reasons, but the
3087short answer is that an '``undef``' "variable" can arbitrarily change
3088its value over its "live range". This is true because the variable
3089doesn't actually *have a live range*. Instead, the value is logically
3090read from arbitrary registers that happen to be around when needed, so
3091the value is not necessarily consistent over time. In fact, ``%A`` and
3092``%C`` need to have the same semantics or the core LLVM "replace all
3093uses with" concept would not hold.
3094
3095.. code-block:: llvm
3096
Sanjay Patel3aaf6a02018-03-09 15:27:48 +00003097 %A = sdiv undef, %X
3098 %B = sdiv %X, undef
Sean Silvab084af42012-12-07 10:36:55 +00003099 Safe:
Sanjay Patel3aaf6a02018-03-09 15:27:48 +00003100 %A = 0
Sean Silvab084af42012-12-07 10:36:55 +00003101 b: unreachable
3102
3103These examples show the crucial difference between an *undefined value*
3104and *undefined behavior*. An undefined value (like '``undef``') is
3105allowed to have an arbitrary bit-pattern. This means that the ``%A``
Sanjay Patel3aaf6a02018-03-09 15:27:48 +00003106operation can be constant folded to '``0``', because the '``undef``'
3107could be zero, and zero divided by any value is zero.
Sean Silvab084af42012-12-07 10:36:55 +00003108However, in the second example, we can make a more aggressive
3109assumption: because the ``undef`` is allowed to be an arbitrary value,
3110we are allowed to assume that it could be zero. Since a divide by zero
3111has *undefined behavior*, we are allowed to assume that the operation
3112does not execute at all. This allows us to delete the divide and all
3113code after it. Because the undefined operation "can't happen", the
3114optimizer can assume that it occurs in dead code.
3115
Renato Golin124f2592016-07-20 12:16:38 +00003116.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00003117
3118 a: store undef -> %X
3119 b: store %X -> undef
3120 Safe:
3121 a: <deleted>
3122 b: unreachable
3123
Sanjay Patel7b722402018-03-07 17:18:22 +00003124A store *of* an undefined value can be assumed to not have any effect;
3125we can assume that the value is overwritten with bits that happen to
3126match what was already there. However, a store *to* an undefined
3127location could clobber arbitrary memory, therefore, it has undefined
3128behavior.
Sean Silvab084af42012-12-07 10:36:55 +00003129
3130.. _poisonvalues:
3131
3132Poison Values
3133-------------
3134
3135Poison values are similar to :ref:`undef values <undefvalues>`, however
3136they also represent the fact that an instruction or constant expression
Richard Smith32dbdf62014-07-31 04:25:36 +00003137that cannot evoke side effects has nevertheless detected a condition
3138that results in undefined behavior.
Sean Silvab084af42012-12-07 10:36:55 +00003139
3140There is currently no way of representing a poison value in the IR; they
3141only exist when produced by operations such as :ref:`add <i_add>` with
3142the ``nsw`` flag.
3143
3144Poison value behavior is defined in terms of value *dependence*:
3145
3146- Values other than :ref:`phi <i_phi>` nodes depend on their operands.
3147- :ref:`Phi <i_phi>` nodes depend on the operand corresponding to
3148 their dynamic predecessor basic block.
3149- Function arguments depend on the corresponding actual argument values
3150 in the dynamic callers of their functions.
3151- :ref:`Call <i_call>` instructions depend on the :ref:`ret <i_ret>`
3152 instructions that dynamically transfer control back to them.
3153- :ref:`Invoke <i_invoke>` instructions depend on the
3154 :ref:`ret <i_ret>`, :ref:`resume <i_resume>`, or exception-throwing
3155 call instructions that dynamically transfer control back to them.
3156- Non-volatile loads and stores depend on the most recent stores to all
3157 of the referenced memory addresses, following the order in the IR
3158 (including loads and stores implied by intrinsics such as
3159 :ref:`@llvm.memcpy <int_memcpy>`.)
3160- An instruction with externally visible side effects depends on the
3161 most recent preceding instruction with externally visible side
3162 effects, following the order in the IR. (This includes :ref:`volatile
3163 operations <volatile>`.)
3164- An instruction *control-depends* on a :ref:`terminator
3165 instruction <terminators>` if the terminator instruction has
3166 multiple successors and the instruction is always executed when
3167 control transfers to one of the successors, and may not be executed
3168 when control is transferred to another.
3169- Additionally, an instruction also *control-depends* on a terminator
3170 instruction if the set of instructions it otherwise depends on would
3171 be different if the terminator had transferred control to a different
3172 successor.
3173- Dependence is transitive.
3174
Richard Smith32dbdf62014-07-31 04:25:36 +00003175Poison values have the same behavior as :ref:`undef values <undefvalues>`,
3176with the additional effect that any instruction that has a *dependence*
Sean Silvab084af42012-12-07 10:36:55 +00003177on a poison value has undefined behavior.
3178
3179Here are some examples:
3180
3181.. code-block:: llvm
3182
3183 entry:
3184 %poison = sub nuw i32 0, 1 ; Results in a poison value.
3185 %still_poison = and i32 %poison, 0 ; 0, but also poison.
David Blaikie16a97eb2015-03-04 22:02:58 +00003186 %poison_yet_again = getelementptr i32, i32* @h, i32 %still_poison
Sean Silvab084af42012-12-07 10:36:55 +00003187 store i32 0, i32* %poison_yet_again ; memory at @h[0] is poisoned
3188
3189 store i32 %poison, i32* @g ; Poison value stored to memory.
David Blaikiec7aabbb2015-03-04 22:06:14 +00003190 %poison2 = load i32, i32* @g ; Poison value loaded back from memory.
Sean Silvab084af42012-12-07 10:36:55 +00003191
3192 store volatile i32 %poison, i32* @g ; External observation; undefined behavior.
3193
3194 %narrowaddr = bitcast i32* @g to i16*
3195 %wideaddr = bitcast i32* @g to i64*
David Blaikiec7aabbb2015-03-04 22:06:14 +00003196 %poison3 = load i16, i16* %narrowaddr ; Returns a poison value.
3197 %poison4 = load i64, i64* %wideaddr ; Returns a poison value.
Sean Silvab084af42012-12-07 10:36:55 +00003198
3199 %cmp = icmp slt i32 %poison, 0 ; Returns a poison value.
3200 br i1 %cmp, label %true, label %end ; Branch to either destination.
3201
3202 true:
3203 store volatile i32 0, i32* @g ; This is control-dependent on %cmp, so
3204 ; it has undefined behavior.
3205 br label %end
3206
3207 end:
3208 %p = phi i32 [ 0, %entry ], [ 1, %true ]
3209 ; Both edges into this PHI are
3210 ; control-dependent on %cmp, so this
3211 ; always results in a poison value.
3212
3213 store volatile i32 0, i32* @g ; This would depend on the store in %true
3214 ; if %cmp is true, or the store in %entry
3215 ; otherwise, so this is undefined behavior.
3216
3217 br i1 %cmp, label %second_true, label %second_end
3218 ; The same branch again, but this time the
3219 ; true block doesn't have side effects.
3220
3221 second_true:
3222 ; No side effects!
3223 ret void
3224
3225 second_end:
3226 store volatile i32 0, i32* @g ; This time, the instruction always depends
3227 ; on the store in %end. Also, it is
3228 ; control-equivalent to %end, so this is
3229 ; well-defined (ignoring earlier undefined
3230 ; behavior in this example).
3231
3232.. _blockaddress:
3233
3234Addresses of Basic Blocks
3235-------------------------
3236
3237``blockaddress(@function, %block)``
3238
3239The '``blockaddress``' constant computes the address of the specified
3240basic block in the specified function, and always has an ``i8*`` type.
3241Taking the address of the entry block is illegal.
3242
3243This value only has defined behavior when used as an operand to the
3244':ref:`indirectbr <i_indirectbr>`' instruction, or for comparisons
3245against null. Pointer equality tests between labels addresses results in
Dmitri Gribenkoe8131122013-01-19 20:34:20 +00003246undefined behavior --- though, again, comparison against null is ok, and
Sean Silvab084af42012-12-07 10:36:55 +00003247no label is equal to the null pointer. This may be passed around as an
3248opaque pointer sized value as long as the bits are not inspected. This
3249allows ``ptrtoint`` and arithmetic to be performed on these values so
3250long as the original value is reconstituted before the ``indirectbr``
3251instruction.
3252
3253Finally, some targets may provide defined semantics when using the value
3254as the operand to an inline assembly, but that is target specific.
3255
Eli Bendersky0220e6b2013-06-07 20:24:43 +00003256.. _constantexprs:
3257
Sean Silvab084af42012-12-07 10:36:55 +00003258Constant Expressions
3259--------------------
3260
3261Constant expressions are used to allow expressions involving other
3262constants to be used as constants. Constant expressions may be of any
3263:ref:`first class <t_firstclass>` type and may involve any LLVM operation
3264that does not have side effects (e.g. load and call are not supported).
3265The following is the syntax for constant expressions:
3266
3267``trunc (CST to TYPE)``
Bjorn Petterssone1285e32017-10-24 11:59:20 +00003268 Perform the :ref:`trunc operation <i_trunc>` on constants.
Sean Silvab084af42012-12-07 10:36:55 +00003269``zext (CST to TYPE)``
Bjorn Petterssone1285e32017-10-24 11:59:20 +00003270 Perform the :ref:`zext operation <i_zext>` on constants.
Sean Silvab084af42012-12-07 10:36:55 +00003271``sext (CST to TYPE)``
Bjorn Petterssone1285e32017-10-24 11:59:20 +00003272 Perform the :ref:`sext operation <i_sext>` on constants.
Sean Silvab084af42012-12-07 10:36:55 +00003273``fptrunc (CST to TYPE)``
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00003274 Truncate a floating-point constant to another floating-point type.
Sean Silvab084af42012-12-07 10:36:55 +00003275 The size of CST must be larger than the size of TYPE. Both types
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00003276 must be floating-point.
Sean Silvab084af42012-12-07 10:36:55 +00003277``fpext (CST to TYPE)``
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00003278 Floating-point extend a constant to another type. The size of CST
Sean Silvab084af42012-12-07 10:36:55 +00003279 must be smaller or equal to the size of TYPE. Both types must be
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00003280 floating-point.
Sean Silvab084af42012-12-07 10:36:55 +00003281``fptoui (CST to TYPE)``
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00003282 Convert a floating-point constant to the corresponding unsigned
Sean Silvab084af42012-12-07 10:36:55 +00003283 integer constant. TYPE must be a scalar or vector integer type. CST
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00003284 must be of scalar or vector floating-point type. Both CST and TYPE
Sean Silvab084af42012-12-07 10:36:55 +00003285 must be scalars, or vectors of the same number of elements. If the
Eli Friedmanc065bb22018-06-08 21:33:33 +00003286 value won't fit in the integer type, the result is a
3287 :ref:`poison value <poisonvalues>`.
Sean Silvab084af42012-12-07 10:36:55 +00003288``fptosi (CST to TYPE)``
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00003289 Convert a floating-point constant to the corresponding signed
Sean Silvab084af42012-12-07 10:36:55 +00003290 integer constant. TYPE must be a scalar or vector integer type. CST
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00003291 must be of scalar or vector floating-point type. Both CST and TYPE
Sean Silvab084af42012-12-07 10:36:55 +00003292 must be scalars, or vectors of the same number of elements. If the
Eli Friedmanc065bb22018-06-08 21:33:33 +00003293 value won't fit in the integer type, the result is a
3294 :ref:`poison value <poisonvalues>`.
Sean Silvab084af42012-12-07 10:36:55 +00003295``uitofp (CST to TYPE)``
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00003296 Convert an unsigned integer constant to the corresponding
3297 floating-point constant. TYPE must be a scalar or vector floating-point
3298 type. CST must be of scalar or vector integer type. Both CST and TYPE must
Eli Friedman3f1ce092018-06-14 22:58:48 +00003299 be scalars, or vectors of the same number of elements.
Sean Silvab084af42012-12-07 10:36:55 +00003300``sitofp (CST to TYPE)``
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00003301 Convert a signed integer constant to the corresponding floating-point
3302 constant. TYPE must be a scalar or vector floating-point type.
Sean Silvab084af42012-12-07 10:36:55 +00003303 CST must be of scalar or vector integer type. Both CST and TYPE must
Eli Friedman3f1ce092018-06-14 22:58:48 +00003304 be scalars, or vectors of the same number of elements.
Sean Silvab084af42012-12-07 10:36:55 +00003305``ptrtoint (CST to TYPE)``
Bjorn Petterssone1285e32017-10-24 11:59:20 +00003306 Perform the :ref:`ptrtoint operation <i_ptrtoint>` on constants.
Sean Silvab084af42012-12-07 10:36:55 +00003307``inttoptr (CST to TYPE)``
Bjorn Petterssone1285e32017-10-24 11:59:20 +00003308 Perform the :ref:`inttoptr operation <i_inttoptr>` on constants.
Sean Silvab084af42012-12-07 10:36:55 +00003309 This one is *really* dangerous!
3310``bitcast (CST to TYPE)``
Bjorn Petterssone1285e32017-10-24 11:59:20 +00003311 Convert a constant, CST, to another TYPE.
3312 The constraints of the operands are the same as those for the
3313 :ref:`bitcast instruction <i_bitcast>`.
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00003314``addrspacecast (CST to TYPE)``
3315 Convert a constant pointer or constant vector of pointer, CST, to another
3316 TYPE in a different address space. The constraints of the operands are the
3317 same as those for the :ref:`addrspacecast instruction <i_addrspacecast>`.
David Blaikief72d05b2015-03-13 18:20:45 +00003318``getelementptr (TY, CSTPTR, IDX0, IDX1, ...)``, ``getelementptr inbounds (TY, CSTPTR, IDX0, IDX1, ...)``
Sean Silvab084af42012-12-07 10:36:55 +00003319 Perform the :ref:`getelementptr operation <i_getelementptr>` on
3320 constants. As with the :ref:`getelementptr <i_getelementptr>`
David Blaikief91b0302017-06-19 05:34:21 +00003321 instruction, the index list may have one or more indexes, which are
David Blaikief72d05b2015-03-13 18:20:45 +00003322 required to make sense for the type of "pointer to TY".
Sean Silvab084af42012-12-07 10:36:55 +00003323``select (COND, VAL1, VAL2)``
3324 Perform the :ref:`select operation <i_select>` on constants.
3325``icmp COND (VAL1, VAL2)``
Bjorn Petterssone1285e32017-10-24 11:59:20 +00003326 Perform the :ref:`icmp operation <i_icmp>` on constants.
Sean Silvab084af42012-12-07 10:36:55 +00003327``fcmp COND (VAL1, VAL2)``
Bjorn Petterssone1285e32017-10-24 11:59:20 +00003328 Perform the :ref:`fcmp operation <i_fcmp>` on constants.
Sean Silvab084af42012-12-07 10:36:55 +00003329``extractelement (VAL, IDX)``
3330 Perform the :ref:`extractelement operation <i_extractelement>` on
3331 constants.
3332``insertelement (VAL, ELT, IDX)``
3333 Perform the :ref:`insertelement operation <i_insertelement>` on
3334 constants.
3335``shufflevector (VEC1, VEC2, IDXMASK)``
3336 Perform the :ref:`shufflevector operation <i_shufflevector>` on
3337 constants.
3338``extractvalue (VAL, IDX0, IDX1, ...)``
3339 Perform the :ref:`extractvalue operation <i_extractvalue>` on
3340 constants. The index list is interpreted in a similar manner as
3341 indices in a ':ref:`getelementptr <i_getelementptr>`' operation. At
3342 least one index value must be specified.
3343``insertvalue (VAL, ELT, IDX0, IDX1, ...)``
3344 Perform the :ref:`insertvalue operation <i_insertvalue>` on constants.
3345 The index list is interpreted in a similar manner as indices in a
3346 ':ref:`getelementptr <i_getelementptr>`' operation. At least one index
3347 value must be specified.
3348``OPCODE (LHS, RHS)``
3349 Perform the specified operation of the LHS and RHS constants. OPCODE
3350 may be any of the :ref:`binary <binaryops>` or :ref:`bitwise
3351 binary <bitwiseops>` operations. The constraints on operands are
3352 the same as those for the corresponding instruction (e.g. no bitwise
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00003353 operations on floating-point values are allowed).
Sean Silvab084af42012-12-07 10:36:55 +00003354
3355Other Values
3356============
3357
Eli Bendersky0220e6b2013-06-07 20:24:43 +00003358.. _inlineasmexprs:
3359
Sean Silvab084af42012-12-07 10:36:55 +00003360Inline Assembler Expressions
3361----------------------------
3362
3363LLVM supports inline assembler expressions (as opposed to :ref:`Module-Level
James Y Knightbc832ed2015-07-08 18:08:36 +00003364Inline Assembly <moduleasm>`) through the use of a special value. This value
3365represents the inline assembler as a template string (containing the
3366instructions to emit), a list of operand constraints (stored as a string), a
3367flag that indicates whether or not the inline asm expression has side effects,
3368and a flag indicating whether the function containing the asm needs to align its
3369stack conservatively.
3370
3371The template string supports argument substitution of the operands using "``$``"
3372followed by a number, to indicate substitution of the given register/memory
3373location, as specified by the constraint string. "``${NUM:MODIFIER}``" may also
3374be used, where ``MODIFIER`` is a target-specific annotation for how to print the
3375operand (See :ref:`inline-asm-modifiers`).
3376
3377A literal "``$``" may be included by using "``$$``" in the template. To include
3378other special characters into the output, the usual "``\XX``" escapes may be
3379used, just as in other strings. Note that after template substitution, the
3380resulting assembly string is parsed by LLVM's integrated assembler unless it is
3381disabled -- even when emitting a ``.s`` file -- and thus must contain assembly
3382syntax known to LLVM.
3383
Reid Kleckner71cb1642017-02-06 18:08:45 +00003384LLVM also supports a few more substitions useful for writing inline assembly:
3385
3386- ``${:uid}``: Expands to a decimal integer unique to this inline assembly blob.
3387 This substitution is useful when declaring a local label. Many standard
3388 compiler optimizations, such as inlining, may duplicate an inline asm blob.
3389 Adding a blob-unique identifier ensures that the two labels will not conflict
3390 during assembly. This is used to implement `GCC's %= special format
3391 string <https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html>`_.
3392- ``${:comment}``: Expands to the comment character of the current target's
3393 assembly dialect. This is usually ``#``, but many targets use other strings,
3394 such as ``;``, ``//``, or ``!``.
3395- ``${:private}``: Expands to the assembler private label prefix. Labels with
3396 this prefix will not appear in the symbol table of the assembled object.
3397 Typically the prefix is ``L``, but targets may use other strings. ``.L`` is
3398 relatively popular.
3399
James Y Knightbc832ed2015-07-08 18:08:36 +00003400LLVM's support for inline asm is modeled closely on the requirements of Clang's
3401GCC-compatible inline-asm support. Thus, the feature-set and the constraint and
3402modifier codes listed here are similar or identical to those in GCC's inline asm
3403support. However, to be clear, the syntax of the template and constraint strings
3404described here is *not* the same as the syntax accepted by GCC and Clang, and,
3405while most constraint letters are passed through as-is by Clang, some get
3406translated to other codes when converting from the C source to the LLVM
3407assembly.
3408
3409An example inline assembler expression is:
Sean Silvab084af42012-12-07 10:36:55 +00003410
3411.. code-block:: llvm
3412
3413 i32 (i32) asm "bswap $0", "=r,r"
3414
3415Inline assembler expressions may **only** be used as the callee operand
3416of a :ref:`call <i_call>` or an :ref:`invoke <i_invoke>` instruction.
3417Thus, typically we have:
3418
3419.. code-block:: llvm
3420
3421 %X = call i32 asm "bswap $0", "=r,r"(i32 %Y)
3422
3423Inline asms with side effects not visible in the constraint list must be
3424marked as having side effects. This is done through the use of the
3425'``sideeffect``' keyword, like so:
3426
3427.. code-block:: llvm
3428
3429 call void asm sideeffect "eieio", ""()
3430
3431In some cases inline asms will contain code that will not work unless
3432the stack is aligned in some way, such as calls or SSE instructions on
3433x86, yet will not contain code that does that alignment within the asm.
3434The compiler should make conservative assumptions about what the asm
3435might contain and should generate its usual stack alignment code in the
3436prologue if the '``alignstack``' keyword is present:
3437
3438.. code-block:: llvm
3439
3440 call void asm alignstack "eieio", ""()
3441
3442Inline asms also support using non-standard assembly dialects. The
3443assumed dialect is ATT. When the '``inteldialect``' keyword is present,
3444the inline asm is using the Intel dialect. Currently, ATT and Intel are
3445the only supported dialects. An example is:
3446
3447.. code-block:: llvm
3448
3449 call void asm inteldialect "eieio", ""()
3450
3451If multiple keywords appear the '``sideeffect``' keyword must come
3452first, the '``alignstack``' keyword second and the '``inteldialect``'
3453keyword last.
3454
James Y Knightbc832ed2015-07-08 18:08:36 +00003455Inline Asm Constraint String
3456^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3457
3458The constraint list is a comma-separated string, each element containing one or
3459more constraint codes.
3460
3461For each element in the constraint list an appropriate register or memory
3462operand will be chosen, and it will be made available to assembly template
3463string expansion as ``$0`` for the first constraint in the list, ``$1`` for the
3464second, etc.
3465
3466There are three different types of constraints, which are distinguished by a
3467prefix symbol in front of the constraint code: Output, Input, and Clobber. The
3468constraints must always be given in that order: outputs first, then inputs, then
3469clobbers. They cannot be intermingled.
3470
3471There are also three different categories of constraint codes:
3472
3473- Register constraint. This is either a register class, or a fixed physical
3474 register. This kind of constraint will allocate a register, and if necessary,
3475 bitcast the argument or result to the appropriate type.
3476- Memory constraint. This kind of constraint is for use with an instruction
3477 taking a memory operand. Different constraints allow for different addressing
3478 modes used by the target.
3479- Immediate value constraint. This kind of constraint is for an integer or other
3480 immediate value which can be rendered directly into an instruction. The
3481 various target-specific constraints allow the selection of a value in the
3482 proper range for the instruction you wish to use it with.
3483
3484Output constraints
3485""""""""""""""""""
3486
3487Output constraints are specified by an "``=``" prefix (e.g. "``=r``"). This
3488indicates that the assembly will write to this operand, and the operand will
3489then be made available as a return value of the ``asm`` expression. Output
3490constraints do not consume an argument from the call instruction. (Except, see
3491below about indirect outputs).
3492
3493Normally, it is expected that no output locations are written to by the assembly
3494expression until *all* of the inputs have been read. As such, LLVM may assign
3495the same register to an output and an input. If this is not safe (e.g. if the
3496assembly contains two instructions, where the first writes to one output, and
3497the second reads an input and writes to a second output), then the "``&``"
3498modifier must be used (e.g. "``=&r``") to specify that the output is an
Sylvestre Ledru84666a12016-02-14 20:16:22 +00003499"early-clobber" output. Marking an output as "early-clobber" ensures that LLVM
James Y Knightbc832ed2015-07-08 18:08:36 +00003500will not use the same register for any inputs (other than an input tied to this
3501output).
3502
3503Input constraints
3504"""""""""""""""""
3505
3506Input constraints do not have a prefix -- just the constraint codes. Each input
3507constraint will consume one argument from the call instruction. It is not
3508permitted for the asm to write to any input register or memory location (unless
3509that input is tied to an output). Note also that multiple inputs may all be
3510assigned to the same register, if LLVM can determine that they necessarily all
3511contain the same value.
3512
3513Instead of providing a Constraint Code, input constraints may also "tie"
3514themselves to an output constraint, by providing an integer as the constraint
3515string. Tied inputs still consume an argument from the call instruction, and
3516take up a position in the asm template numbering as is usual -- they will simply
3517be constrained to always use the same register as the output they've been tied
3518to. For example, a constraint string of "``=r,0``" says to assign a register for
3519output, and use that register as an input as well (it being the 0'th
3520constraint).
3521
3522It is permitted to tie an input to an "early-clobber" output. In that case, no
3523*other* input may share the same register as the input tied to the early-clobber
3524(even when the other input has the same value).
3525
3526You may only tie an input to an output which has a register constraint, not a
3527memory constraint. Only a single input may be tied to an output.
3528
3529There is also an "interesting" feature which deserves a bit of explanation: if a
3530register class constraint allocates a register which is too small for the value
3531type operand provided as input, the input value will be split into multiple
3532registers, and all of them passed to the inline asm.
3533
3534However, this feature is often not as useful as you might think.
3535
3536Firstly, the registers are *not* guaranteed to be consecutive. So, on those
3537architectures that have instructions which operate on multiple consecutive
3538instructions, this is not an appropriate way to support them. (e.g. the 32-bit
3539SparcV8 has a 64-bit load, which instruction takes a single 32-bit register. The
3540hardware then loads into both the named register, and the next register. This
3541feature of inline asm would not be useful to support that.)
3542
3543A few of the targets provide a template string modifier allowing explicit access
3544to the second register of a two-register operand (e.g. MIPS ``L``, ``M``, and
3545``D``). On such an architecture, you can actually access the second allocated
3546register (yet, still, not any subsequent ones). But, in that case, you're still
3547probably better off simply splitting the value into two separate operands, for
3548clarity. (e.g. see the description of the ``A`` constraint on X86, which,
3549despite existing only for use with this feature, is not really a good idea to
3550use)
3551
3552Indirect inputs and outputs
3553"""""""""""""""""""""""""""
3554
3555Indirect output or input constraints can be specified by the "``*``" modifier
3556(which goes after the "``=``" in case of an output). This indicates that the asm
3557will write to or read from the contents of an *address* provided as an input
3558argument. (Note that in this way, indirect outputs act more like an *input* than
3559an output: just like an input, they consume an argument of the call expression,
3560rather than producing a return value. An indirect output constraint is an
3561"output" only in that the asm is expected to write to the contents of the input
3562memory location, instead of just read from it).
3563
3564This is most typically used for memory constraint, e.g. "``=*m``", to pass the
3565address of a variable as a value.
3566
3567It is also possible to use an indirect *register* constraint, but only on output
3568(e.g. "``=*r``"). This will cause LLVM to allocate a register for an output
3569value normally, and then, separately emit a store to the address provided as
3570input, after the provided inline asm. (It's not clear what value this
3571functionality provides, compared to writing the store explicitly after the asm
3572statement, and it can only produce worse code, since it bypasses many
3573optimization passes. I would recommend not using it.)
3574
3575
3576Clobber constraints
3577"""""""""""""""""""
3578
3579A clobber constraint is indicated by a "``~``" prefix. A clobber does not
3580consume an input operand, nor generate an output. Clobbers cannot use any of the
3581general constraint code letters -- they may use only explicit register
3582constraints, e.g. "``~{eax}``". The one exception is that a clobber string of
3583"``~{memory}``" indicates that the assembly writes to arbitrary undeclared
3584memory locations -- not only the memory pointed to by a declared indirect
3585output.
3586
Peter Zotov00257232016-08-30 10:48:31 +00003587Note that clobbering named registers that are also present in output
3588constraints is not legal.
3589
James Y Knightbc832ed2015-07-08 18:08:36 +00003590
3591Constraint Codes
3592""""""""""""""""
3593After a potential prefix comes constraint code, or codes.
3594
3595A Constraint Code is either a single letter (e.g. "``r``"), a "``^``" character
3596followed by two letters (e.g. "``^wc``"), or "``{``" register-name "``}``"
3597(e.g. "``{eax}``").
3598
3599The one and two letter constraint codes are typically chosen to be the same as
3600GCC's constraint codes.
3601
3602A single constraint may include one or more than constraint code in it, leaving
3603it up to LLVM to choose which one to use. This is included mainly for
3604compatibility with the translation of GCC inline asm coming from clang.
3605
3606There are two ways to specify alternatives, and either or both may be used in an
3607inline asm constraint list:
3608
36091) Append the codes to each other, making a constraint code set. E.g. "``im``"
3610 or "``{eax}m``". This means "choose any of the options in the set". The
3611 choice of constraint is made independently for each constraint in the
3612 constraint list.
3613
36142) Use "``|``" between constraint code sets, creating alternatives. Every
3615 constraint in the constraint list must have the same number of alternative
3616 sets. With this syntax, the same alternative in *all* of the items in the
3617 constraint list will be chosen together.
3618
3619Putting those together, you might have a two operand constraint string like
3620``"rm|r,ri|rm"``. This indicates that if operand 0 is ``r`` or ``m``, then
3621operand 1 may be one of ``r`` or ``i``. If operand 0 is ``r``, then operand 1
3622may be one of ``r`` or ``m``. But, operand 0 and 1 cannot both be of type m.
3623
3624However, the use of either of the alternatives features is *NOT* recommended, as
3625LLVM is not able to make an intelligent choice about which one to use. (At the
3626point it currently needs to choose, not enough information is available to do so
3627in a smart way.) Thus, it simply tries to make a choice that's most likely to
3628compile, not one that will be optimal performance. (e.g., given "``rm``", it'll
3629always choose to use memory, not registers). And, if given multiple registers,
3630or multiple register classes, it will simply choose the first one. (In fact, it
3631doesn't currently even ensure explicitly specified physical registers are
3632unique, so specifying multiple physical registers as alternatives, like
3633``{r11}{r12},{r11}{r12}``, will assign r11 to both operands, not at all what was
3634intended.)
3635
3636Supported Constraint Code List
3637""""""""""""""""""""""""""""""
3638
3639The constraint codes are, in general, expected to behave the same way they do in
3640GCC. LLVM's support is often implemented on an 'as-needed' basis, to support C
3641inline asm code which was supported by GCC. A mismatch in behavior between LLVM
3642and GCC likely indicates a bug in LLVM.
3643
3644Some constraint codes are typically supported by all targets:
3645
3646- ``r``: A register in the target's general purpose register class.
3647- ``m``: A memory address operand. It is target-specific what addressing modes
3648 are supported, typical examples are register, or register + register offset,
3649 or register + immediate offset (of some target-specific size).
3650- ``i``: An integer constant (of target-specific width). Allows either a simple
3651 immediate, or a relocatable value.
3652- ``n``: An integer constant -- *not* including relocatable values.
3653- ``s``: An integer constant, but allowing *only* relocatable values.
3654- ``X``: Allows an operand of any kind, no constraint whatsoever. Typically
3655 useful to pass a label for an asm branch or call.
3656
3657 .. FIXME: but that surely isn't actually okay to jump out of an asm
3658 block without telling llvm about the control transfer???)
3659
3660- ``{register-name}``: Requires exactly the named physical register.
3661
3662Other constraints are target-specific:
3663
3664AArch64:
3665
3666- ``z``: An immediate integer 0. Outputs ``WZR`` or ``XZR``, as appropriate.
3667- ``I``: An immediate integer valid for an ``ADD`` or ``SUB`` instruction,
3668 i.e. 0 to 4095 with optional shift by 12.
3669- ``J``: An immediate integer that, when negated, is valid for an ``ADD`` or
3670 ``SUB`` instruction, i.e. -1 to -4095 with optional left shift by 12.
3671- ``K``: An immediate integer that is valid for the 'bitmask immediate 32' of a
3672 logical instruction like ``AND``, ``EOR``, or ``ORR`` with a 32-bit register.
3673- ``L``: An immediate integer that is valid for the 'bitmask immediate 64' of a
3674 logical instruction like ``AND``, ``EOR``, or ``ORR`` with a 64-bit register.
3675- ``M``: An immediate integer for use with the ``MOV`` assembly alias on a
3676 32-bit register. This is a superset of ``K``: in addition to the bitmask
3677 immediate, also allows immediate integers which can be loaded with a single
3678 ``MOVZ`` or ``MOVL`` instruction.
3679- ``N``: An immediate integer for use with the ``MOV`` assembly alias on a
3680 64-bit register. This is a superset of ``L``.
3681- ``Q``: Memory address operand must be in a single register (no
3682 offsets). (However, LLVM currently does this for the ``m`` constraint as
3683 well.)
3684- ``r``: A 32 or 64-bit integer register (W* or X*).
3685- ``w``: A 32, 64, or 128-bit floating-point/SIMD register.
3686- ``x``: A lower 128-bit floating-point/SIMD register (``V0`` to ``V15``).
3687
3688AMDGPU:
3689
3690- ``r``: A 32 or 64-bit integer register.
3691- ``[0-9]v``: The 32-bit VGPR register, number 0-9.
3692- ``[0-9]s``: The 32-bit SGPR register, number 0-9.
3693
3694
3695All ARM modes:
3696
3697- ``Q``, ``Um``, ``Un``, ``Uq``, ``Us``, ``Ut``, ``Uv``, ``Uy``: Memory address
3698 operand. Treated the same as operand ``m``, at the moment.
3699
3700ARM and ARM's Thumb2 mode:
3701
3702- ``j``: An immediate integer between 0 and 65535 (valid for ``MOVW``)
3703- ``I``: An immediate integer valid for a data-processing instruction.
3704- ``J``: An immediate integer between -4095 and 4095.
3705- ``K``: An immediate integer whose bitwise inverse is valid for a
3706 data-processing instruction. (Can be used with template modifier "``B``" to
3707 print the inverted value).
3708- ``L``: An immediate integer whose negation is valid for a data-processing
3709 instruction. (Can be used with template modifier "``n``" to print the negated
3710 value).
3711- ``M``: A power of two or a integer between 0 and 32.
3712- ``N``: Invalid immediate constraint.
3713- ``O``: Invalid immediate constraint.
3714- ``r``: A general-purpose 32-bit integer register (``r0-r15``).
3715- ``l``: In Thumb2 mode, low 32-bit GPR registers (``r0-r7``). In ARM mode, same
3716 as ``r``.
3717- ``h``: In Thumb2 mode, a high 32-bit GPR register (``r8-r15``). In ARM mode,
3718 invalid.
3719- ``w``: A 32, 64, or 128-bit floating-point/SIMD register: ``s0-s31``,
3720 ``d0-d31``, or ``q0-q15``.
3721- ``x``: A 32, 64, or 128-bit floating-point/SIMD register: ``s0-s15``,
3722 ``d0-d7``, or ``q0-q3``.
Pablo Barrioe28cb832018-02-15 14:44:22 +00003723- ``t``: A low floating-point/SIMD register: ``s0-s31``, ``d0-d16``, or
3724 ``q0-q8``.
James Y Knightbc832ed2015-07-08 18:08:36 +00003725
3726ARM's Thumb1 mode:
3727
3728- ``I``: An immediate integer between 0 and 255.
3729- ``J``: An immediate integer between -255 and -1.
3730- ``K``: An immediate integer between 0 and 255, with optional left-shift by
3731 some amount.
3732- ``L``: An immediate integer between -7 and 7.
3733- ``M``: An immediate integer which is a multiple of 4 between 0 and 1020.
3734- ``N``: An immediate integer between 0 and 31.
3735- ``O``: An immediate integer which is a multiple of 4 between -508 and 508.
3736- ``r``: A low 32-bit GPR register (``r0-r7``).
3737- ``l``: A low 32-bit GPR register (``r0-r7``).
3738- ``h``: A high GPR register (``r0-r7``).
3739- ``w``: A 32, 64, or 128-bit floating-point/SIMD register: ``s0-s31``,
3740 ``d0-d31``, or ``q0-q15``.
3741- ``x``: A 32, 64, or 128-bit floating-point/SIMD register: ``s0-s15``,
3742 ``d0-d7``, or ``q0-q3``.
Pablo Barrioe28cb832018-02-15 14:44:22 +00003743- ``t``: A low floating-point/SIMD register: ``s0-s31``, ``d0-d16``, or
3744 ``q0-q8``.
James Y Knightbc832ed2015-07-08 18:08:36 +00003745
3746
3747Hexagon:
3748
3749- ``o``, ``v``: A memory address operand, treated the same as constraint ``m``,
3750 at the moment.
3751- ``r``: A 32 or 64-bit register.
3752
3753MSP430:
3754
3755- ``r``: An 8 or 16-bit register.
3756
3757MIPS:
3758
3759- ``I``: An immediate signed 16-bit integer.
3760- ``J``: An immediate integer zero.
3761- ``K``: An immediate unsigned 16-bit integer.
3762- ``L``: An immediate 32-bit integer, where the lower 16 bits are 0.
3763- ``N``: An immediate integer between -65535 and -1.
3764- ``O``: An immediate signed 15-bit integer.
3765- ``P``: An immediate integer between 1 and 65535.
3766- ``m``: A memory address operand. In MIPS-SE mode, allows a base address
3767 register plus 16-bit immediate offset. In MIPS mode, just a base register.
3768- ``R``: A memory address operand. In MIPS-SE mode, allows a base address
3769 register plus a 9-bit signed offset. In MIPS mode, the same as constraint
3770 ``m``.
3771- ``ZC``: A memory address operand, suitable for use in a ``pref``, ``ll``, or
3772 ``sc`` instruction on the given subtarget (details vary).
3773- ``r``, ``d``, ``y``: A 32 or 64-bit GPR register.
3774- ``f``: A 32 or 64-bit FPU register (``F0-F31``), or a 128-bit MSA register
Daniel Sanders3745e022015-07-13 09:24:21 +00003775 (``W0-W31``). In the case of MSA registers, it is recommended to use the ``w``
3776 argument modifier for compatibility with GCC.
James Y Knightbc832ed2015-07-08 18:08:36 +00003777- ``c``: A 32-bit or 64-bit GPR register suitable for indirect jump (always
3778 ``25``).
3779- ``l``: The ``lo`` register, 32 or 64-bit.
3780- ``x``: Invalid.
3781
3782NVPTX:
3783
3784- ``b``: A 1-bit integer register.
3785- ``c`` or ``h``: A 16-bit integer register.
3786- ``r``: A 32-bit integer register.
3787- ``l`` or ``N``: A 64-bit integer register.
3788- ``f``: A 32-bit float register.
3789- ``d``: A 64-bit float register.
3790
3791
3792PowerPC:
3793
3794- ``I``: An immediate signed 16-bit integer.
3795- ``J``: An immediate unsigned 16-bit integer, shifted left 16 bits.
3796- ``K``: An immediate unsigned 16-bit integer.
3797- ``L``: An immediate signed 16-bit integer, shifted left 16 bits.
3798- ``M``: An immediate integer greater than 31.
3799- ``N``: An immediate integer that is an exact power of 2.
3800- ``O``: The immediate integer constant 0.
3801- ``P``: An immediate integer constant whose negation is a signed 16-bit
3802 constant.
3803- ``es``, ``o``, ``Q``, ``Z``, ``Zy``: A memory address operand, currently
3804 treated the same as ``m``.
3805- ``r``: A 32 or 64-bit integer register.
3806- ``b``: A 32 or 64-bit integer register, excluding ``R0`` (that is:
3807 ``R1-R31``).
3808- ``f``: A 32 or 64-bit float register (``F0-F31``), or when QPX is enabled, a
3809 128 or 256-bit QPX register (``Q0-Q31``; aliases the ``F`` registers).
3810- ``v``: For ``4 x f32`` or ``4 x f64`` types, when QPX is enabled, a
3811 128 or 256-bit QPX register (``Q0-Q31``), otherwise a 128-bit
3812 altivec vector register (``V0-V31``).
3813
3814 .. FIXME: is this a bug that v accepts QPX registers? I think this
3815 is supposed to only use the altivec vector registers?
3816
3817- ``y``: Condition register (``CR0-CR7``).
3818- ``wc``: An individual CR bit in a CR register.
3819- ``wa``, ``wd``, ``wf``: Any 128-bit VSX vector register, from the full VSX
3820 register set (overlapping both the floating-point and vector register files).
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00003821- ``ws``: A 32 or 64-bit floating-point register, from the full VSX register
James Y Knightbc832ed2015-07-08 18:08:36 +00003822 set.
3823
3824Sparc:
3825
3826- ``I``: An immediate 13-bit signed integer.
3827- ``r``: A 32-bit integer register.
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00003828- ``f``: Any floating-point register on SparcV8, or a floating-point
James Y Knightd4e1b002017-05-12 15:59:10 +00003829 register in the "low" half of the registers on SparcV9.
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00003830- ``e``: Any floating-point register. (Same as ``f`` on SparcV8.)
James Y Knightbc832ed2015-07-08 18:08:36 +00003831
3832SystemZ:
3833
3834- ``I``: An immediate unsigned 8-bit integer.
3835- ``J``: An immediate unsigned 12-bit integer.
3836- ``K``: An immediate signed 16-bit integer.
3837- ``L``: An immediate signed 20-bit integer.
3838- ``M``: An immediate integer 0x7fffffff.
Ulrich Weiganddaae87aa2016-06-13 14:24:05 +00003839- ``Q``: A memory address operand with a base address and a 12-bit immediate
3840 unsigned displacement.
3841- ``R``: A memory address operand with a base address, a 12-bit immediate
3842 unsigned displacement, and an index register.
3843- ``S``: A memory address operand with a base address and a 20-bit immediate
3844 signed displacement.
3845- ``T``: A memory address operand with a base address, a 20-bit immediate
3846 signed displacement, and an index register.
James Y Knightbc832ed2015-07-08 18:08:36 +00003847- ``r`` or ``d``: A 32, 64, or 128-bit integer register.
3848- ``a``: A 32, 64, or 128-bit integer address register (excludes R0, which in an
3849 address context evaluates as zero).
3850- ``h``: A 32-bit value in the high part of a 64bit data register
3851 (LLVM-specific)
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00003852- ``f``: A 32, 64, or 128-bit floating-point register.
James Y Knightbc832ed2015-07-08 18:08:36 +00003853
3854X86:
3855
3856- ``I``: An immediate integer between 0 and 31.
3857- ``J``: An immediate integer between 0 and 64.
3858- ``K``: An immediate signed 8-bit integer.
3859- ``L``: An immediate integer, 0xff or 0xffff or (in 64-bit mode only)
3860 0xffffffff.
3861- ``M``: An immediate integer between 0 and 3.
3862- ``N``: An immediate unsigned 8-bit integer.
3863- ``O``: An immediate integer between 0 and 127.
3864- ``e``: An immediate 32-bit signed integer.
3865- ``Z``: An immediate 32-bit unsigned integer.
3866- ``o``, ``v``: Treated the same as ``m``, at the moment.
3867- ``q``: An 8, 16, 32, or 64-bit register which can be accessed as an 8-bit
3868 ``l`` integer register. On X86-32, this is the ``a``, ``b``, ``c``, and ``d``
3869 registers, and on X86-64, it is all of the integer registers.
3870- ``Q``: An 8, 16, 32, or 64-bit register which can be accessed as an 8-bit
3871 ``h`` integer register. This is the ``a``, ``b``, ``c``, and ``d`` registers.
3872- ``r`` or ``l``: An 8, 16, 32, or 64-bit integer register.
3873- ``R``: An 8, 16, 32, or 64-bit "legacy" integer register -- one which has
3874 existed since i386, and can be accessed without the REX prefix.
3875- ``f``: A 32, 64, or 80-bit '387 FPU stack pseudo-register.
3876- ``y``: A 64-bit MMX register, if MMX is enabled.
3877- ``x``: If SSE is enabled: a 32 or 64-bit scalar operand, or 128-bit vector
3878 operand in a SSE register. If AVX is also enabled, can also be a 256-bit
3879 vector operand in an AVX register. If AVX-512 is also enabled, can also be a
3880 512-bit vector operand in an AVX512 register, Otherwise, an error.
3881- ``Y``: The same as ``x``, if *SSE2* is enabled, otherwise an error.
3882- ``A``: Special case: allocates EAX first, then EDX, for a single operand (in
3883 32-bit mode, a 64-bit integer operand will get split into two registers). It
3884 is not recommended to use this constraint, as in 64-bit mode, the 64-bit
3885 operand will get allocated only to RAX -- if two 32-bit operands are needed,
3886 you're better off splitting it yourself, before passing it to the asm
3887 statement.
3888
3889XCore:
3890
3891- ``r``: A 32-bit integer register.
3892
3893
3894.. _inline-asm-modifiers:
3895
3896Asm template argument modifiers
3897^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3898
3899In the asm template string, modifiers can be used on the operand reference, like
3900"``${0:n}``".
3901
3902The modifiers are, in general, expected to behave the same way they do in
3903GCC. LLVM's support is often implemented on an 'as-needed' basis, to support C
3904inline asm code which was supported by GCC. A mismatch in behavior between LLVM
3905and GCC likely indicates a bug in LLVM.
3906
3907Target-independent:
3908
Sean Silvaa1190322015-08-06 22:56:48 +00003909- ``c``: Print an immediate integer constant unadorned, without
James Y Knightbc832ed2015-07-08 18:08:36 +00003910 the target-specific immediate punctuation (e.g. no ``$`` prefix).
3911- ``n``: Negate and print immediate integer constant unadorned, without the
3912 target-specific immediate punctuation (e.g. no ``$`` prefix).
3913- ``l``: Print as an unadorned label, without the target-specific label
3914 punctuation (e.g. no ``$`` prefix).
3915
3916AArch64:
3917
3918- ``w``: Print a GPR register with a ``w*`` name instead of ``x*`` name. E.g.,
3919 instead of ``x30``, print ``w30``.
3920- ``x``: Print a GPR register with a ``x*`` name. (this is the default, anyhow).
3921- ``b``, ``h``, ``s``, ``d``, ``q``: Print a floating-point/SIMD register with a
3922 ``b*``, ``h*``, ``s*``, ``d*``, or ``q*`` name, rather than the default of
3923 ``v*``.
3924
3925AMDGPU:
3926
3927- ``r``: No effect.
3928
3929ARM:
3930
3931- ``a``: Print an operand as an address (with ``[`` and ``]`` surrounding a
3932 register).
3933- ``P``: No effect.
3934- ``q``: No effect.
3935- ``y``: Print a VFP single-precision register as an indexed double (e.g. print
3936 as ``d4[1]`` instead of ``s9``)
3937- ``B``: Bitwise invert and print an immediate integer constant without ``#``
3938 prefix.
3939- ``L``: Print the low 16-bits of an immediate integer constant.
3940- ``M``: Print as a register set suitable for ldm/stm. Also prints *all*
3941 register operands subsequent to the specified one (!), so use carefully.
3942- ``Q``: Print the low-order register of a register-pair, or the low-order
3943 register of a two-register operand.
3944- ``R``: Print the high-order register of a register-pair, or the high-order
3945 register of a two-register operand.
3946- ``H``: Print the second register of a register-pair. (On a big-endian system,
3947 ``H`` is equivalent to ``Q``, and on little-endian system, ``H`` is equivalent
3948 to ``R``.)
3949
3950 .. FIXME: H doesn't currently support printing the second register
3951 of a two-register operand.
3952
3953- ``e``: Print the low doubleword register of a NEON quad register.
3954- ``f``: Print the high doubleword register of a NEON quad register.
3955- ``m``: Print the base register of a memory operand without the ``[`` and ``]``
3956 adornment.
3957
3958Hexagon:
3959
3960- ``L``: Print the second register of a two-register operand. Requires that it
3961 has been allocated consecutively to the first.
3962
3963 .. FIXME: why is it restricted to consecutive ones? And there's
3964 nothing that ensures that happens, is there?
3965
3966- ``I``: Print the letter 'i' if the operand is an integer constant, otherwise
3967 nothing. Used to print 'addi' vs 'add' instructions.
3968
3969MSP430:
3970
3971No additional modifiers.
3972
3973MIPS:
3974
3975- ``X``: Print an immediate integer as hexadecimal
3976- ``x``: Print the low 16 bits of an immediate integer as hexadecimal.
3977- ``d``: Print an immediate integer as decimal.
3978- ``m``: Subtract one and print an immediate integer as decimal.
3979- ``z``: Print $0 if an immediate zero, otherwise print normally.
3980- ``L``: Print the low-order register of a two-register operand, or prints the
3981 address of the low-order word of a double-word memory operand.
3982
3983 .. FIXME: L seems to be missing memory operand support.
3984
3985- ``M``: Print the high-order register of a two-register operand, or prints the
3986 address of the high-order word of a double-word memory operand.
3987
3988 .. FIXME: M seems to be missing memory operand support.
3989
3990- ``D``: Print the second register of a two-register operand, or prints the
3991 second word of a double-word memory operand. (On a big-endian system, ``D`` is
3992 equivalent to ``L``, and on little-endian system, ``D`` is equivalent to
3993 ``M``.)
Daniel Sanders3745e022015-07-13 09:24:21 +00003994- ``w``: No effect. Provided for compatibility with GCC which requires this
3995 modifier in order to print MSA registers (``W0-W31``) with the ``f``
3996 constraint.
James Y Knightbc832ed2015-07-08 18:08:36 +00003997
3998NVPTX:
3999
4000- ``r``: No effect.
4001
4002PowerPC:
4003
4004- ``L``: Print the second register of a two-register operand. Requires that it
4005 has been allocated consecutively to the first.
4006
4007 .. FIXME: why is it restricted to consecutive ones? And there's
4008 nothing that ensures that happens, is there?
4009
4010- ``I``: Print the letter 'i' if the operand is an integer constant, otherwise
4011 nothing. Used to print 'addi' vs 'add' instructions.
4012- ``y``: For a memory operand, prints formatter for a two-register X-form
4013 instruction. (Currently always prints ``r0,OPERAND``).
4014- ``U``: Prints 'u' if the memory operand is an update form, and nothing
4015 otherwise. (NOTE: LLVM does not support update form, so this will currently
4016 always print nothing)
4017- ``X``: Prints 'x' if the memory operand is an indexed form. (NOTE: LLVM does
4018 not support indexed form, so this will currently always print nothing)
4019
4020Sparc:
4021
4022- ``r``: No effect.
4023
4024SystemZ:
4025
4026SystemZ implements only ``n``, and does *not* support any of the other
4027target-independent modifiers.
4028
4029X86:
4030
4031- ``c``: Print an unadorned integer or symbol name. (The latter is
4032 target-specific behavior for this typically target-independent modifier).
4033- ``A``: Print a register name with a '``*``' before it.
4034- ``b``: Print an 8-bit register name (e.g. ``al``); do nothing on a memory
4035 operand.
4036- ``h``: Print the upper 8-bit register name (e.g. ``ah``); do nothing on a
4037 memory operand.
4038- ``w``: Print the 16-bit register name (e.g. ``ax``); do nothing on a memory
4039 operand.
4040- ``k``: Print the 32-bit register name (e.g. ``eax``); do nothing on a memory
4041 operand.
4042- ``q``: Print the 64-bit register name (e.g. ``rax``), if 64-bit registers are
4043 available, otherwise the 32-bit register name; do nothing on a memory operand.
4044- ``n``: Negate and print an unadorned integer, or, for operands other than an
4045 immediate integer (e.g. a relocatable symbol expression), print a '-' before
4046 the operand. (The behavior for relocatable symbol expressions is a
4047 target-specific behavior for this typically target-independent modifier)
4048- ``H``: Print a memory reference with additional offset +8.
4049- ``P``: Print a memory reference or operand for use as the argument of a call
4050 instruction. (E.g. omit ``(rip)``, even though it's PC-relative.)
4051
4052XCore:
4053
4054No additional modifiers.
4055
4056
Sean Silvab084af42012-12-07 10:36:55 +00004057Inline Asm Metadata
4058^^^^^^^^^^^^^^^^^^^
4059
4060The call instructions that wrap inline asm nodes may have a
4061"``!srcloc``" MDNode attached to it that contains a list of constant
4062integers. If present, the code generator will use the integer as the
4063location cookie value when report errors through the ``LLVMContext``
4064error reporting mechanisms. This allows a front-end to correlate backend
4065errors that occur with inline asm back to the source code that produced
4066it. For example:
4067
4068.. code-block:: llvm
4069
4070 call void asm sideeffect "something bad", ""(), !srcloc !42
4071 ...
4072 !42 = !{ i32 1234567 }
4073
4074It is up to the front-end to make sense of the magic numbers it places
4075in the IR. If the MDNode contains multiple constants, the code generator
4076will use the one that corresponds to the line of the asm that the error
4077occurs on.
4078
4079.. _metadata:
4080
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00004081Metadata
4082========
Sean Silvab084af42012-12-07 10:36:55 +00004083
4084LLVM IR allows metadata to be attached to instructions in the program
4085that can convey extra information about the code to the optimizers and
4086code generator. One example application of metadata is source-level
4087debug information. There are two metadata primitives: strings and nodes.
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00004088
Sean Silvaa1190322015-08-06 22:56:48 +00004089Metadata does not have a type, and is not a value. If referenced from a
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00004090``call`` instruction, it uses the ``metadata`` type.
4091
4092All metadata are identified in syntax by a exclamation point ('``!``').
4093
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004094.. _metadata-string:
4095
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00004096Metadata Nodes and Metadata Strings
4097-----------------------------------
Sean Silvab084af42012-12-07 10:36:55 +00004098
4099A metadata string is a string surrounded by double quotes. It can
4100contain any character by escaping non-printable characters with
4101"``\xx``" where "``xx``" is the two digit hex code. For example:
4102"``!"test\00"``".
4103
4104Metadata nodes are represented with notation similar to structure
4105constants (a comma separated list of elements, surrounded by braces and
4106preceded by an exclamation point). Metadata nodes can have any values as
4107their operand. For example:
4108
4109.. code-block:: llvm
4110
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00004111 !{ !"test\00", i32 10}
Sean Silvab084af42012-12-07 10:36:55 +00004112
Duncan P. N. Exon Smith090a19b2015-01-08 22:38:29 +00004113Metadata nodes that aren't uniqued use the ``distinct`` keyword. For example:
4114
Renato Golin124f2592016-07-20 12:16:38 +00004115.. code-block:: text
Duncan P. N. Exon Smith090a19b2015-01-08 22:38:29 +00004116
4117 !0 = distinct !{!"test\00", i32 10}
4118
Duncan P. N. Exon Smith99010342015-01-08 23:50:26 +00004119``distinct`` nodes are useful when nodes shouldn't be merged based on their
Sean Silvaa1190322015-08-06 22:56:48 +00004120content. They can also occur when transformations cause uniquing collisions
Duncan P. N. Exon Smith99010342015-01-08 23:50:26 +00004121when metadata operands change.
4122
Sean Silvab084af42012-12-07 10:36:55 +00004123A :ref:`named metadata <namedmetadatastructure>` is a collection of
4124metadata nodes, which can be looked up in the module symbol table. For
4125example:
4126
4127.. code-block:: llvm
4128
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00004129 !foo = !{!4, !3}
Sean Silvab084af42012-12-07 10:36:55 +00004130
Adrian Prantl1b842da2017-07-28 20:44:29 +00004131Metadata can be used as function arguments. Here the ``llvm.dbg.value``
4132intrinsic is using three metadata arguments:
Sean Silvab084af42012-12-07 10:36:55 +00004133
4134.. code-block:: llvm
4135
Adrian Prantlabe04752017-07-28 20:21:02 +00004136 call void @llvm.dbg.value(metadata !24, metadata !25, metadata !26)
Sean Silvab084af42012-12-07 10:36:55 +00004137
Peter Collingbourne50108682015-11-06 02:41:02 +00004138Metadata can be attached to an instruction. Here metadata ``!21`` is attached
4139to the ``add`` instruction using the ``!dbg`` identifier:
Sean Silvab084af42012-12-07 10:36:55 +00004140
4141.. code-block:: llvm
4142
4143 %indvar.next = add i64 %indvar, 1, !dbg !21
4144
Peter Collingbourne7b5b7c72017-01-25 21:50:14 +00004145Metadata can also be attached to a function or a global variable. Here metadata
4146``!22`` is attached to the ``f1`` and ``f2 functions, and the globals ``g1``
4147and ``g2`` using the ``!dbg`` identifier:
Peter Collingbourne50108682015-11-06 02:41:02 +00004148
4149.. code-block:: llvm
4150
Peter Collingbourne7b5b7c72017-01-25 21:50:14 +00004151 declare !dbg !22 void @f1()
4152 define void @f2() !dbg !22 {
Peter Collingbourne50108682015-11-06 02:41:02 +00004153 ret void
4154 }
4155
Peter Collingbourne7b5b7c72017-01-25 21:50:14 +00004156 @g1 = global i32 0, !dbg !22
4157 @g2 = external global i32, !dbg !22
4158
4159A transformation is required to drop any metadata attachment that it does not
4160know or know it can't preserve. Currently there is an exception for metadata
4161attachment to globals for ``!type`` and ``!absolute_symbol`` which can't be
4162unconditionally dropped unless the global is itself deleted.
4163
4164Metadata attached to a module using named metadata may not be dropped, with
4165the exception of debug metadata (named metadata with the name ``!llvm.dbg.*``).
4166
Sean Silvab084af42012-12-07 10:36:55 +00004167More information about specific metadata nodes recognized by the
4168optimizers and code generator is found below.
4169
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004170.. _specialized-metadata:
4171
Duncan P. N. Exon Smith6a484832015-01-13 21:10:44 +00004172Specialized Metadata Nodes
4173^^^^^^^^^^^^^^^^^^^^^^^^^^
4174
4175Specialized metadata nodes are custom data structures in metadata (as opposed
Sean Silvaa1190322015-08-06 22:56:48 +00004176to generic tuples). Their fields are labelled, and can be specified in any
Duncan P. N. Exon Smith6a484832015-01-13 21:10:44 +00004177order.
4178
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004179These aren't inherently debug info centric, but currently all the specialized
4180metadata nodes are related to debug info.
4181
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004182.. _DICompileUnit:
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004183
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004184DICompileUnit
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004185"""""""""""""
4186
Sean Silvaa1190322015-08-06 22:56:48 +00004187``DICompileUnit`` nodes represent a compile unit. The ``enums:``,
Adrian Prantl6c2497f2017-06-12 23:59:43 +00004188``retainedTypes:``, ``globals:``, ``imports:`` and ``macros:`` fields are tuples
4189containing the debug info to be emitted along with the compile unit, regardless
4190of code optimizations (some nodes are only emitted if there are references to
4191them from instructions). The ``debugInfoForProfiling:`` field is a boolean
4192indicating whether or not line-table discriminators are updated to provide
4193more-accurate debug info for profiling results.
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004194
Renato Golin124f2592016-07-20 12:16:38 +00004195.. code-block:: text
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004196
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004197 !0 = !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang",
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004198 isOptimized: true, flags: "-O2", runtimeVersion: 2,
Adrian Prantlb8089512016-04-01 00:16:49 +00004199 splitDebugFilename: "abc.debug", emissionKind: FullDebug,
Adrian Prantl6c2497f2017-06-12 23:59:43 +00004200 enums: !2, retainedTypes: !3, globals: !4, imports: !5,
4201 macros: !6, dwoId: 0x0abcd)
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004202
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004203Compile unit descriptors provide the root scope for objects declared in a
Adrian Prantl6c2497f2017-06-12 23:59:43 +00004204specific compilation unit. File descriptors are defined using this scope. These
4205descriptors are collected by a named metadata node ``!llvm.dbg.cu``. They keep
4206track of global variables, type information, and imported entities (declarations
4207and namespaces).
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004208
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004209.. _DIFile:
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004210
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004211DIFile
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004212""""""
4213
Sean Silvaa1190322015-08-06 22:56:48 +00004214``DIFile`` nodes represent files. The ``filename:`` can include slashes.
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004215
Aaron Ballmanb3c51512017-01-17 21:48:31 +00004216.. code-block:: none
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004217
Amjad Aboud7faeecc2016-12-25 10:12:09 +00004218 !0 = !DIFile(filename: "path/to/file", directory: "/path/to/dir",
4219 checksumkind: CSK_MD5,
4220 checksum: "000102030405060708090a0b0c0d0e0f")
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004221
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004222Files are sometimes used in ``scope:`` fields, and are the only valid target
4223for ``file:`` fields.
Amjad Aboud7faeecc2016-12-25 10:12:09 +00004224Valid values for ``checksumkind:`` field are: {CSK_None, CSK_MD5, CSK_SHA1}
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004225
Michael Kuperstein605308a2015-05-14 10:58:59 +00004226.. _DIBasicType:
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004227
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004228DIBasicType
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004229"""""""""""
4230
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004231``DIBasicType`` nodes represent primitive types, such as ``int``, ``bool`` and
Sean Silvaa1190322015-08-06 22:56:48 +00004232``float``. ``tag:`` defaults to ``DW_TAG_base_type``.
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004233
Renato Golin124f2592016-07-20 12:16:38 +00004234.. code-block:: text
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004235
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004236 !0 = !DIBasicType(name: "unsigned char", size: 8, align: 8,
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004237 encoding: DW_ATE_unsigned_char)
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004238 !1 = !DIBasicType(tag: DW_TAG_unspecified_type, name: "decltype(nullptr)")
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004239
Sean Silvaa1190322015-08-06 22:56:48 +00004240The ``encoding:`` describes the details of the type. Usually it's one of the
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004241following:
4242
Renato Golin124f2592016-07-20 12:16:38 +00004243.. code-block:: text
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004244
4245 DW_ATE_address = 1
4246 DW_ATE_boolean = 2
4247 DW_ATE_float = 4
4248 DW_ATE_signed = 5
4249 DW_ATE_signed_char = 6
4250 DW_ATE_unsigned = 7
4251 DW_ATE_unsigned_char = 8
4252
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004253.. _DISubroutineType:
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004254
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004255DISubroutineType
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004256""""""""""""""""
4257
Sean Silvaa1190322015-08-06 22:56:48 +00004258``DISubroutineType`` nodes represent subroutine types. Their ``types:`` field
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004259refers to a tuple; the first operand is the return type, while the rest are the
Sean Silvaa1190322015-08-06 22:56:48 +00004260types of the formal arguments in order. If the first operand is ``null``, that
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004261represents a function with no return value (such as ``void foo() {}`` in C++).
4262
Renato Golin124f2592016-07-20 12:16:38 +00004263.. code-block:: text
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004264
4265 !0 = !BasicType(name: "int", size: 32, align: 32, DW_ATE_signed)
4266 !1 = !BasicType(name: "char", size: 8, align: 8, DW_ATE_signed_char)
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004267 !2 = !DISubroutineType(types: !{null, !0, !1}) ; void (int, char)
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004268
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004269.. _DIDerivedType:
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004270
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004271DIDerivedType
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004272"""""""""""""
4273
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004274``DIDerivedType`` nodes represent types derived from other types, such as
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004275qualified types.
4276
Renato Golin124f2592016-07-20 12:16:38 +00004277.. code-block:: text
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004278
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004279 !0 = !DIBasicType(name: "unsigned char", size: 8, align: 8,
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004280 encoding: DW_ATE_unsigned_char)
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004281 !1 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !0, size: 32,
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004282 align: 32)
4283
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004284The following ``tag:`` values are valid:
4285
Renato Golin124f2592016-07-20 12:16:38 +00004286.. code-block:: text
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004287
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004288 DW_TAG_member = 13
4289 DW_TAG_pointer_type = 15
4290 DW_TAG_reference_type = 16
4291 DW_TAG_typedef = 22
Duncan P. N. Exon Smitha3f3de12016-04-16 22:46:47 +00004292 DW_TAG_inheritance = 28
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004293 DW_TAG_ptr_to_member_type = 31
4294 DW_TAG_const_type = 38
Duncan P. N. Exon Smitha3f3de12016-04-16 22:46:47 +00004295 DW_TAG_friend = 42
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004296 DW_TAG_volatile_type = 53
4297 DW_TAG_restrict_type = 55
Victor Leschuke1156c22016-10-31 19:09:38 +00004298 DW_TAG_atomic_type = 71
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004299
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +00004300.. _DIDerivedTypeMember:
4301
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004302``DW_TAG_member`` is used to define a member of a :ref:`composite type
Duncan P. N. Exon Smith90990cd2016-04-17 00:45:00 +00004303<DICompositeType>`. The type of the member is the ``baseType:``. The
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +00004304``offset:`` is the member's bit offset. If the composite type has an ODR
4305``identifier:`` and does not set ``flags: DIFwdDecl``, then the member is
4306uniqued based only on its ``name:`` and ``scope:``.
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004307
Duncan P. N. Exon Smitha3f3de12016-04-16 22:46:47 +00004308``DW_TAG_inheritance`` and ``DW_TAG_friend`` are used in the ``elements:``
4309field of :ref:`composite types <DICompositeType>` to describe parents and
4310friends.
4311
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004312``DW_TAG_typedef`` is used to provide a name for the ``baseType:``.
4313
4314``DW_TAG_pointer_type``, ``DW_TAG_reference_type``, ``DW_TAG_const_type``,
Victor Leschuke1156c22016-10-31 19:09:38 +00004315``DW_TAG_volatile_type``, ``DW_TAG_restrict_type`` and ``DW_TAG_atomic_type``
4316are used to qualify the ``baseType:``.
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004317
4318Note that the ``void *`` type is expressed as a type derived from NULL.
4319
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004320.. _DICompositeType:
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004321
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004322DICompositeType
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004323"""""""""""""""
4324
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004325``DICompositeType`` nodes represent types composed of other types, like
Sean Silvaa1190322015-08-06 22:56:48 +00004326structures and unions. ``elements:`` points to a tuple of the composed types.
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004327
4328If the source language supports ODR, the ``identifier:`` field gives the unique
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +00004329identifier used for type merging between modules. When specified,
4330:ref:`subprogram declarations <DISubprogramDeclaration>` and :ref:`member
4331derived types <DIDerivedTypeMember>` that reference the ODR-type in their
4332``scope:`` change uniquing rules.
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004333
Duncan P. N. Exon Smith5ab2be02016-04-17 03:58:21 +00004334For a given ``identifier:``, there should only be a single composite type that
4335does not have ``flags: DIFlagFwdDecl`` set. LLVM tools that link modules
4336together will unique such definitions at parse time via the ``identifier:``
4337field, even if the nodes are ``distinct``.
4338
Renato Golin124f2592016-07-20 12:16:38 +00004339.. code-block:: text
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004340
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004341 !0 = !DIEnumerator(name: "SixKind", value: 7)
4342 !1 = !DIEnumerator(name: "SevenKind", value: 7)
4343 !2 = !DIEnumerator(name: "NegEightKind", value: -8)
4344 !3 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "Enum", file: !12,
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004345 line: 2, size: 32, align: 32, identifier: "_M4Enum",
4346 elements: !{!0, !1, !2})
4347
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004348The following ``tag:`` values are valid:
4349
Renato Golin124f2592016-07-20 12:16:38 +00004350.. code-block:: text
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004351
4352 DW_TAG_array_type = 1
4353 DW_TAG_class_type = 2
4354 DW_TAG_enumeration_type = 4
4355 DW_TAG_structure_type = 19
4356 DW_TAG_union_type = 23
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004357
4358For ``DW_TAG_array_type``, the ``elements:`` should be :ref:`subrange
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004359descriptors <DISubrange>`, each representing the range of subscripts at that
Sean Silvaa1190322015-08-06 22:56:48 +00004360level of indexing. The ``DIFlagVector`` flag to ``flags:`` indicates that an
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004361array type is a native packed vector.
4362
4363For ``DW_TAG_enumeration_type``, the ``elements:`` should be :ref:`enumerator
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004364descriptors <DIEnumerator>`, each representing the definition of an enumeration
Sean Silvaa1190322015-08-06 22:56:48 +00004365value for the set. All enumeration type descriptors are collected in the
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004366``enums:`` field of the :ref:`compile unit <DICompileUnit>`.
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004367
4368For ``DW_TAG_structure_type``, ``DW_TAG_class_type``, and
4369``DW_TAG_union_type``, the ``elements:`` should be :ref:`derived types
Duncan P. N. Exon Smitha3f3de12016-04-16 22:46:47 +00004370<DIDerivedType>` with ``tag: DW_TAG_member``, ``tag: DW_TAG_inheritance``, or
4371``tag: DW_TAG_friend``; or :ref:`subprograms <DISubprogram>` with
4372``isDefinition: false``.
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004373
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004374.. _DISubrange:
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004375
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004376DISubrange
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004377""""""""""
4378
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004379``DISubrange`` nodes are the elements for ``DW_TAG_array_type`` variants of
Sander de Smalen1cb94312018-01-24 10:30:23 +00004380:ref:`DICompositeType`.
4381
4382- ``count: -1`` indicates an empty array.
4383- ``count: !9`` describes the count with a :ref:`DILocalVariable`.
4384- ``count: !11`` describes the count with a :ref:`DIGlobalVariable`.
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004385
4386.. code-block:: llvm
4387
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004388 !0 = !DISubrange(count: 5, lowerBound: 0) ; array counting from 0
4389 !1 = !DISubrange(count: 5, lowerBound: 1) ; array counting from 1
4390 !2 = !DISubrange(count: -1) ; empty array.
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004391
Sander de Smalenfdf40912018-01-24 09:56:07 +00004392 ; Scopes used in rest of example
4393 !6 = !DIFile(filename: "vla.c", directory: "/path/to/file")
4394 !7 = distinct !DICompileUnit(language: DW_LANG_C99, ...
4395 !8 = distinct !DISubprogram(name: "foo", scope: !7, file: !6, line: 5, ...
4396
4397 ; Use of local variable as count value
4398 !9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
4399 !10 = !DILocalVariable(name: "count", scope: !8, file: !6, line: 42, type: !9)
4400 !11 = !DISubrange(count !10, lowerBound: 0)
4401
4402 ; Use of global variable as count value
4403 !12 = !DIGlobalVariable(name: "count", scope: !8, file: !6, line: 22, type: !9)
4404 !13 = !DISubrange(count !12, lowerBound: 0)
4405
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004406.. _DIEnumerator:
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004407
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004408DIEnumerator
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004409""""""""""""
4410
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004411``DIEnumerator`` nodes are the elements for ``DW_TAG_enumeration_type``
4412variants of :ref:`DICompositeType`.
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004413
4414.. code-block:: llvm
4415
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004416 !0 = !DIEnumerator(name: "SixKind", value: 7)
4417 !1 = !DIEnumerator(name: "SevenKind", value: 7)
4418 !2 = !DIEnumerator(name: "NegEightKind", value: -8)
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004419
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004420DITemplateTypeParameter
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004421"""""""""""""""""""""""
4422
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004423``DITemplateTypeParameter`` nodes represent type parameters to generic source
Sean Silvaa1190322015-08-06 22:56:48 +00004424language constructs. They are used (optionally) in :ref:`DICompositeType` and
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004425:ref:`DISubprogram` ``templateParams:`` fields.
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004426
4427.. code-block:: llvm
4428
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004429 !0 = !DITemplateTypeParameter(name: "Ty", type: !1)
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004430
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004431DITemplateValueParameter
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004432""""""""""""""""""""""""
4433
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004434``DITemplateValueParameter`` nodes represent value parameters to generic source
Sean Silvaa1190322015-08-06 22:56:48 +00004435language constructs. ``tag:`` defaults to ``DW_TAG_template_value_parameter``,
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004436but if specified can also be set to ``DW_TAG_GNU_template_template_param`` or
Sean Silvaa1190322015-08-06 22:56:48 +00004437``DW_TAG_GNU_template_param_pack``. They are used (optionally) in
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004438:ref:`DICompositeType` and :ref:`DISubprogram` ``templateParams:`` fields.
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004439
4440.. code-block:: llvm
4441
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004442 !0 = !DITemplateValueParameter(name: "Ty", type: !1, value: i32 7)
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004443
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004444DINamespace
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004445"""""""""""
4446
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004447``DINamespace`` nodes represent namespaces in the source language.
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004448
4449.. code-block:: llvm
4450
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004451 !0 = !DINamespace(name: "myawesomeproject", scope: !1, file: !2, line: 7)
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004452
Sander de Smalen1cb94312018-01-24 10:30:23 +00004453.. _DIGlobalVariable:
4454
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004455DIGlobalVariable
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004456""""""""""""""""
4457
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004458``DIGlobalVariable`` nodes represent global variables in the source language.
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004459
4460.. code-block:: llvm
4461
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004462 !0 = !DIGlobalVariable(name: "foo", linkageName: "foo", scope: !1,
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004463 file: !2, line: 7, type: !3, isLocal: true,
4464 isDefinition: false, variable: i32* @foo,
4465 declaration: !4)
4466
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004467All global variables should be referenced by the `globals:` field of a
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004468:ref:`compile unit <DICompileUnit>`.
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004469
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004470.. _DISubprogram:
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004471
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004472DISubprogram
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004473""""""""""""
4474
Peter Collingbourne50108682015-11-06 02:41:02 +00004475``DISubprogram`` nodes represent functions from the source language. A
4476``DISubprogram`` may be attached to a function definition using ``!dbg``
4477metadata. The ``variables:`` field points at :ref:`variables <DILocalVariable>`
4478that must be retained, even if their IR counterparts are optimized out of
4479the IR. The ``type:`` field must point at an :ref:`DISubroutineType`.
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004480
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +00004481.. _DISubprogramDeclaration:
4482
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +00004483When ``isDefinition: false``, subprograms describe a declaration in the type
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +00004484tree as opposed to a definition of a function. If the scope is a composite
4485type with an ODR ``identifier:`` and that does not set ``flags: DIFwdDecl``,
4486then the subprogram declaration is uniqued based only on its ``linkageName:``
4487and ``scope:``.
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +00004488
Renato Golin124f2592016-07-20 12:16:38 +00004489.. code-block:: text
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004490
Peter Collingbourne50108682015-11-06 02:41:02 +00004491 define void @_Z3foov() !dbg !0 {
4492 ...
4493 }
4494
4495 !0 = distinct !DISubprogram(name: "foo", linkageName: "_Zfoov", scope: !1,
4496 file: !2, line: 7, type: !3, isLocal: true,
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +00004497 isDefinition: true, scopeLine: 8,
Peter Collingbourne50108682015-11-06 02:41:02 +00004498 containingType: !4,
4499 virtuality: DW_VIRTUALITY_pure_virtual,
4500 virtualIndex: 10, flags: DIFlagPrototyped,
Adrian Prantl6c2497f2017-06-12 23:59:43 +00004501 isOptimized: true, unit: !5, templateParams: !6,
4502 declaration: !7, variables: !8, thrownTypes: !9)
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004503
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004504.. _DILexicalBlock:
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004505
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004506DILexicalBlock
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004507""""""""""""""
4508
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004509``DILexicalBlock`` nodes describe nested blocks within a :ref:`subprogram
Bruce Mitchenere9ffb452015-09-12 01:17:08 +00004510<DISubprogram>`. The line number and column numbers are used to distinguish
Sean Silvaa1190322015-08-06 22:56:48 +00004511two lexical blocks at same depth. They are valid targets for ``scope:``
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004512fields.
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004513
Renato Golin124f2592016-07-20 12:16:38 +00004514.. code-block:: text
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004515
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004516 !0 = distinct !DILexicalBlock(scope: !1, file: !2, line: 7, column: 35)
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004517
4518Usually lexical blocks are ``distinct`` to prevent node merging based on
4519operands.
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004520
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004521.. _DILexicalBlockFile:
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004522
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004523DILexicalBlockFile
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004524""""""""""""""""""
4525
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004526``DILexicalBlockFile`` nodes are used to discriminate between sections of a
Sean Silvaa1190322015-08-06 22:56:48 +00004527:ref:`lexical block <DILexicalBlock>`. The ``file:`` field can be changed to
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004528indicate textual inclusion, or the ``discriminator:`` field can be used to
4529discriminate between control flow within a single block in the source language.
4530
4531.. code-block:: llvm
4532
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004533 !0 = !DILexicalBlock(scope: !3, file: !4, line: 7, column: 35)
4534 !1 = !DILexicalBlockFile(scope: !0, file: !4, discriminator: 0)
4535 !2 = !DILexicalBlockFile(scope: !0, file: !4, discriminator: 1)
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004536
Michael Kuperstein605308a2015-05-14 10:58:59 +00004537.. _DILocation:
4538
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004539DILocation
Duncan P. N. Exon Smith6a484832015-01-13 21:10:44 +00004540""""""""""
4541
Sean Silvaa1190322015-08-06 22:56:48 +00004542``DILocation`` nodes represent source debug locations. The ``scope:`` field is
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004543mandatory, and points at an :ref:`DILexicalBlockFile`, an
4544:ref:`DILexicalBlock`, or an :ref:`DISubprogram`.
Duncan P. N. Exon Smith6a484832015-01-13 21:10:44 +00004545
4546.. code-block:: llvm
4547
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004548 !0 = !DILocation(line: 2900, column: 42, scope: !1, inlinedAt: !2)
Duncan P. N. Exon Smith6a484832015-01-13 21:10:44 +00004549
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004550.. _DILocalVariable:
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004551
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004552DILocalVariable
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004553"""""""""""""""
4554
Sean Silvaa1190322015-08-06 22:56:48 +00004555``DILocalVariable`` nodes represent local variables in the source language. If
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +00004556the ``arg:`` field is set to non-zero, then this variable is a subprogram
4557parameter, and it will be included in the ``variables:`` field of its
4558:ref:`DISubprogram`.
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004559
Renato Golin124f2592016-07-20 12:16:38 +00004560.. code-block:: text
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004561
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +00004562 !0 = !DILocalVariable(name: "this", arg: 1, scope: !3, file: !2, line: 7,
4563 type: !3, flags: DIFlagArtificial)
4564 !1 = !DILocalVariable(name: "x", arg: 2, scope: !4, file: !2, line: 7,
4565 type: !3)
4566 !2 = !DILocalVariable(name: "y", scope: !5, file: !2, line: 7, type: !3)
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004567
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004568DIExpression
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004569""""""""""""
4570
Adrian Prantlb44c7762017-03-22 18:01:01 +00004571``DIExpression`` nodes represent expressions that are inspired by the DWARF
4572expression language. They are used in :ref:`debug intrinsics<dbg_intrinsics>`
4573(such as ``llvm.dbg.declare`` and ``llvm.dbg.value``) to describe how the
4574referenced LLVM variable relates to the source language variable.
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004575
4576The current supported vocabulary is limited:
4577
Adrian Prantl6825fb62017-04-18 01:21:53 +00004578- ``DW_OP_deref`` dereferences the top of the expression stack.
Florian Hahnffc498d2017-06-14 13:14:38 +00004579- ``DW_OP_plus`` pops the last two entries from the expression stack, adds
4580 them together and appends the result to the expression stack.
4581- ``DW_OP_minus`` pops the last two entries from the expression stack, subtracts
4582 the last entry from the second last entry and appends the result to the
4583 expression stack.
Florian Hahnc9c403c2017-06-13 16:54:44 +00004584- ``DW_OP_plus_uconst, 93`` adds ``93`` to the working expression.
Adrian Prantlb44c7762017-03-22 18:01:01 +00004585- ``DW_OP_LLVM_fragment, 16, 8`` specifies the offset and size (``16`` and ``8``
4586 here, respectively) of the variable fragment from the working expression. Note
Hiroshi Inoue760c0c92018-01-16 13:19:48 +00004587 that contrary to DW_OP_bit_piece, the offset is describing the location
Adrian Prantlb44c7762017-03-22 18:01:01 +00004588 within the described source variable.
Konstantin Zhuravlyovf9b41cd2017-03-08 00:28:57 +00004589- ``DW_OP_swap`` swaps top two stack entries.
4590- ``DW_OP_xderef`` provides extended dereference mechanism. The entry at the top
4591 of the stack is treated as an address. The second stack entry is treated as an
4592 address space identifier.
Adrian Prantlb44c7762017-03-22 18:01:01 +00004593- ``DW_OP_stack_value`` marks a constant value.
4594
Adrian Prantl6825fb62017-04-18 01:21:53 +00004595DWARF specifies three kinds of simple location descriptions: Register, memory,
4596and implicit location descriptions. Register and memory location descriptions
4597describe the *location* of a source variable (in the sense that a debugger might
4598modify its value), whereas implicit locations describe merely the *value* of a
4599source variable. DIExpressions also follow this model: A DIExpression that
4600doesn't have a trailing ``DW_OP_stack_value`` will describe an *address* when
4601combined with a concrete location.
4602
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +00004603.. code-block:: text
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004604
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004605 !0 = !DIExpression(DW_OP_deref)
Florian Hahnc9c403c2017-06-13 16:54:44 +00004606 !1 = !DIExpression(DW_OP_plus_uconst, 3)
Florian Hahnffc498d2017-06-14 13:14:38 +00004607 !1 = !DIExpression(DW_OP_constu, 3, DW_OP_plus)
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004608 !2 = !DIExpression(DW_OP_bit_piece, 3, 7)
Florian Hahnffc498d2017-06-14 13:14:38 +00004609 !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 +00004610 !4 = !DIExpression(DW_OP_constu, 2, DW_OP_swap, DW_OP_xderef)
Adrian Prantlb44c7762017-03-22 18:01:01 +00004611 !5 = !DIExpression(DW_OP_constu, 42, DW_OP_stack_value)
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004612
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004613DIObjCProperty
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004614""""""""""""""
4615
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004616``DIObjCProperty`` nodes represent Objective-C property nodes.
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004617
4618.. code-block:: llvm
4619
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004620 !3 = !DIObjCProperty(name: "foo", file: !1, line: 7, setter: "setFoo",
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004621 getter: "getFoo", attributes: 7, type: !2)
4622
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004623DIImportedEntity
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004624""""""""""""""""
4625
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004626``DIImportedEntity`` nodes represent entities (such as modules) imported into a
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004627compile unit.
4628
Renato Golin124f2592016-07-20 12:16:38 +00004629.. code-block:: text
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004630
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004631 !2 = !DIImportedEntity(tag: DW_TAG_imported_module, name: "foo", scope: !0,
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004632 entity: !1, line: 7)
4633
Amjad Abouda9bcf162015-12-10 12:56:35 +00004634DIMacro
4635"""""""
4636
4637``DIMacro`` nodes represent definition or undefinition of a macro identifiers.
4638The ``name:`` field is the macro identifier, followed by macro parameters when
Sylvestre Ledru7d540502016-07-02 19:28:40 +00004639defining a function-like macro, and the ``value`` field is the token-string
Amjad Abouda9bcf162015-12-10 12:56:35 +00004640used to expand the macro identifier.
4641
Renato Golin124f2592016-07-20 12:16:38 +00004642.. code-block:: text
Amjad Abouda9bcf162015-12-10 12:56:35 +00004643
4644 !2 = !DIMacro(macinfo: DW_MACINFO_define, line: 7, name: "foo(x)",
4645 value: "((x) + 1)")
4646 !3 = !DIMacro(macinfo: DW_MACINFO_undef, line: 30, name: "foo")
4647
4648DIMacroFile
4649"""""""""""
4650
4651``DIMacroFile`` nodes represent inclusion of source files.
4652The ``nodes:`` field is a list of ``DIMacro`` and ``DIMacroFile`` nodes that
4653appear in the included source file.
4654
Renato Golin124f2592016-07-20 12:16:38 +00004655.. code-block:: text
Amjad Abouda9bcf162015-12-10 12:56:35 +00004656
4657 !2 = !DIMacroFile(macinfo: DW_MACINFO_start_file, line: 7, file: !2,
4658 nodes: !3)
4659
Sean Silvab084af42012-12-07 10:36:55 +00004660'``tbaa``' Metadata
4661^^^^^^^^^^^^^^^^^^^
4662
4663In LLVM IR, memory does not have types, so LLVM's own type system is not
Sanjoy Dasa3ff9942017-02-13 23:14:03 +00004664suitable for doing type based alias analysis (TBAA). Instead, metadata is
4665added to the IR to describe a type system of a higher level language. This
4666can be used to implement C/C++ strict type aliasing rules, but it can also
4667be used to implement custom alias analysis behavior for other languages.
Sean Silvab084af42012-12-07 10:36:55 +00004668
Sanjoy Dasa3ff9942017-02-13 23:14:03 +00004669This description of LLVM's TBAA system is broken into two parts:
4670:ref:`Semantics<tbaa_node_semantics>` talks about high level issues, and
4671:ref:`Representation<tbaa_node_representation>` talks about the metadata
4672encoding of various entities.
Sean Silvab084af42012-12-07 10:36:55 +00004673
Sanjoy Dasa3ff9942017-02-13 23:14:03 +00004674It is always possible to trace any TBAA node to a "root" TBAA node (details
4675in the :ref:`Representation<tbaa_node_representation>` section). TBAA
4676nodes with different roots have an unknown aliasing relationship, and LLVM
4677conservatively infers ``MayAlias`` between them. The rules mentioned in
4678this section only pertain to TBAA nodes living under the same root.
Sean Silvab084af42012-12-07 10:36:55 +00004679
Sanjoy Dasa3ff9942017-02-13 23:14:03 +00004680.. _tbaa_node_semantics:
Sean Silvab084af42012-12-07 10:36:55 +00004681
Sanjoy Dasa3ff9942017-02-13 23:14:03 +00004682Semantics
4683"""""""""
Sean Silvab084af42012-12-07 10:36:55 +00004684
Sanjoy Dasa3ff9942017-02-13 23:14:03 +00004685The TBAA metadata system, referred to as "struct path TBAA" (not to be
4686confused with ``tbaa.struct``), consists of the following high level
4687concepts: *Type Descriptors*, further subdivided into scalar type
4688descriptors and struct type descriptors; and *Access Tags*.
Sean Silvab084af42012-12-07 10:36:55 +00004689
Sanjoy Dasa3ff9942017-02-13 23:14:03 +00004690**Type descriptors** describe the type system of the higher level language
4691being compiled. **Scalar type descriptors** describe types that do not
4692contain other types. Each scalar type has a parent type, which must also
4693be a scalar type or the TBAA root. Via this parent relation, scalar types
4694within a TBAA root form a tree. **Struct type descriptors** denote types
4695that contain a sequence of other type descriptors, at known offsets. These
4696contained type descriptors can either be struct type descriptors themselves
4697or scalar type descriptors.
4698
4699**Access tags** are metadata nodes attached to load and store instructions.
4700Access tags use type descriptors to describe the *location* being accessed
4701in terms of the type system of the higher level language. Access tags are
4702tuples consisting of a base type, an access type and an offset. The base
4703type is a scalar type descriptor or a struct type descriptor, the access
4704type is a scalar type descriptor, and the offset is a constant integer.
4705
4706The access tag ``(BaseTy, AccessTy, Offset)`` can describe one of two
4707things:
4708
4709 * If ``BaseTy`` is a struct type, the tag describes a memory access (load
4710 or store) of a value of type ``AccessTy`` contained in the struct type
4711 ``BaseTy`` at offset ``Offset``.
4712
4713 * If ``BaseTy`` is a scalar type, ``Offset`` must be 0 and ``BaseTy`` and
4714 ``AccessTy`` must be the same; and the access tag describes a scalar
4715 access with scalar type ``AccessTy``.
4716
4717We first define an ``ImmediateParent`` relation on ``(BaseTy, Offset)``
4718tuples this way:
4719
4720 * If ``BaseTy`` is a scalar type then ``ImmediateParent(BaseTy, 0)`` is
4721 ``(ParentTy, 0)`` where ``ParentTy`` is the parent of the scalar type as
4722 described in the TBAA metadata. ``ImmediateParent(BaseTy, Offset)`` is
4723 undefined if ``Offset`` is non-zero.
4724
4725 * If ``BaseTy`` is a struct type then ``ImmediateParent(BaseTy, Offset)``
4726 is ``(NewTy, NewOffset)`` where ``NewTy`` is the type contained in
4727 ``BaseTy`` at offset ``Offset`` and ``NewOffset`` is ``Offset`` adjusted
4728 to be relative within that inner type.
4729
4730A memory access with an access tag ``(BaseTy1, AccessTy1, Offset1)``
4731aliases a memory access with an access tag ``(BaseTy2, AccessTy2,
4732Offset2)`` if either ``(BaseTy1, Offset1)`` is reachable from ``(Base2,
4733Offset2)`` via the ``Parent`` relation or vice versa.
4734
4735As a concrete example, the type descriptor graph for the following program
4736
4737.. code-block:: c
4738
4739 struct Inner {
4740 int i; // offset 0
4741 float f; // offset 4
4742 };
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +00004743
Sanjoy Dasa3ff9942017-02-13 23:14:03 +00004744 struct Outer {
4745 float f; // offset 0
4746 double d; // offset 4
4747 struct Inner inner_a; // offset 12
4748 };
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +00004749
Sanjoy Dasa3ff9942017-02-13 23:14:03 +00004750 void f(struct Outer* outer, struct Inner* inner, float* f, int* i, char* c) {
4751 outer->f = 0; // tag0: (OuterStructTy, FloatScalarTy, 0)
4752 outer->inner_a.i = 0; // tag1: (OuterStructTy, IntScalarTy, 12)
Fangrui Song74d6a742018-05-29 05:38:05 +00004753 outer->inner_a.f = 0.0; // tag2: (OuterStructTy, FloatScalarTy, 16)
Sanjoy Dasa3ff9942017-02-13 23:14:03 +00004754 *f = 0.0; // tag3: (FloatScalarTy, FloatScalarTy, 0)
4755 }
4756
4757is (note that in C and C++, ``char`` can be used to access any arbitrary
4758type):
4759
4760.. code-block:: text
4761
4762 Root = "TBAA Root"
4763 CharScalarTy = ("char", Root, 0)
4764 FloatScalarTy = ("float", CharScalarTy, 0)
4765 DoubleScalarTy = ("double", CharScalarTy, 0)
4766 IntScalarTy = ("int", CharScalarTy, 0)
4767 InnerStructTy = {"Inner" (IntScalarTy, 0), (FloatScalarTy, 4)}
4768 OuterStructTy = {"Outer", (FloatScalarTy, 0), (DoubleScalarTy, 4),
4769 (InnerStructTy, 12)}
4770
4771
4772with (e.g.) ``ImmediateParent(OuterStructTy, 12)`` = ``(InnerStructTy,
47730)``, ``ImmediateParent(InnerStructTy, 0)`` = ``(IntScalarTy, 0)``, and
4774``ImmediateParent(IntScalarTy, 0)`` = ``(CharScalarTy, 0)``.
4775
4776.. _tbaa_node_representation:
4777
4778Representation
4779""""""""""""""
4780
4781The root node of a TBAA type hierarchy is an ``MDNode`` with 0 operands or
4782with exactly one ``MDString`` operand.
4783
4784Scalar type descriptors are represented as an ``MDNode`` s with two
4785operands. The first operand is an ``MDString`` denoting the name of the
4786struct type. LLVM does not assign meaning to the value of this operand, it
4787only cares about it being an ``MDString``. The second operand is an
4788``MDNode`` which points to the parent for said scalar type descriptor,
4789which is either another scalar type descriptor or the TBAA root. Scalar
4790type descriptors can have an optional third argument, but that must be the
4791constant integer zero.
4792
4793Struct type descriptors are represented as ``MDNode`` s with an odd number
4794of operands greater than 1. The first operand is an ``MDString`` denoting
4795the name of the struct type. Like in scalar type descriptors the actual
4796value of this name operand is irrelevant to LLVM. After the name operand,
4797the struct type descriptors have a sequence of alternating ``MDNode`` and
4798``ConstantInt`` operands. With N starting from 1, the 2N - 1 th operand,
4799an ``MDNode``, denotes a contained field, and the 2N th operand, a
4800``ConstantInt``, is the offset of the said contained field. The offsets
4801must be in non-decreasing order.
4802
4803Access tags are represented as ``MDNode`` s with either 3 or 4 operands.
4804The first operand is an ``MDNode`` pointing to the node representing the
4805base type. The second operand is an ``MDNode`` pointing to the node
4806representing the access type. The third operand is a ``ConstantInt`` that
4807states the offset of the access. If a fourth field is present, it must be
4808a ``ConstantInt`` valued at 0 or 1. If it is 1 then the access tag states
4809that the location being accessed is "constant" (meaning
Sean Silvab084af42012-12-07 10:36:55 +00004810``pointsToConstantMemory`` should return true; see `other useful
Sanjoy Dasa3ff9942017-02-13 23:14:03 +00004811AliasAnalysis methods <AliasAnalysis.html#OtherItfs>`_). The TBAA root of
4812the access type and the base type of an access tag must be the same, and
4813that is the TBAA root of the access tag.
Sean Silvab084af42012-12-07 10:36:55 +00004814
4815'``tbaa.struct``' Metadata
4816^^^^^^^^^^^^^^^^^^^^^^^^^^
4817
4818The :ref:`llvm.memcpy <int_memcpy>` is often used to implement
4819aggregate assignment operations in C and similar languages, however it
4820is defined to copy a contiguous region of memory, which is more than
4821strictly necessary for aggregate types which contain holes due to
4822padding. Also, it doesn't contain any TBAA information about the fields
4823of the aggregate.
4824
4825``!tbaa.struct`` metadata can describe which memory subregions in a
4826memcpy are padding and what the TBAA tags of the struct are.
4827
4828The current metadata format is very simple. ``!tbaa.struct`` metadata
4829nodes are a list of operands which are in conceptual groups of three.
4830For each group of three, the first operand gives the byte offset of a
4831field in bytes, the second gives its size in bytes, and the third gives
4832its tbaa tag. e.g.:
4833
4834.. code-block:: llvm
4835
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00004836 !4 = !{ i64 0, i64 4, !1, i64 8, i64 4, !2 }
Sean Silvab084af42012-12-07 10:36:55 +00004837
4838This describes a struct with two fields. The first is at offset 0 bytes
4839with size 4 bytes, and has tbaa tag !1. The second is at offset 8 bytes
4840and has size 4 bytes and has tbaa tag !2.
4841
4842Note that the fields need not be contiguous. In this example, there is a
48434 byte gap between the two fields. This gap represents padding which
4844does not carry useful data and need not be preserved.
4845
Hal Finkel94146652014-07-24 14:25:39 +00004846'``noalias``' and '``alias.scope``' Metadata
Dan Liewbafdcba2014-07-28 13:33:51 +00004847^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Hal Finkel94146652014-07-24 14:25:39 +00004848
4849``noalias`` and ``alias.scope`` metadata provide the ability to specify generic
4850noalias memory-access sets. This means that some collection of memory access
4851instructions (loads, stores, memory-accessing calls, etc.) that carry
4852``noalias`` metadata can specifically be specified not to alias with some other
4853collection of memory access instructions that carry ``alias.scope`` metadata.
Hal Finkel029cde62014-07-25 15:50:02 +00004854Each type of metadata specifies a list of scopes where each scope has an id and
Adam Nemet569a5b32016-04-27 00:52:48 +00004855a domain.
4856
4857When evaluating an aliasing query, if for some domain, the set
Hal Finkel029cde62014-07-25 15:50:02 +00004858of scopes with that domain in one instruction's ``alias.scope`` list is a
Arch D. Robison96cf7ab2015-02-24 20:11:49 +00004859subset of (or equal to) the set of scopes for that domain in another
Hal Finkel029cde62014-07-25 15:50:02 +00004860instruction's ``noalias`` list, then the two memory accesses are assumed not to
4861alias.
Hal Finkel94146652014-07-24 14:25:39 +00004862
Adam Nemet569a5b32016-04-27 00:52:48 +00004863Because scopes in one domain don't affect scopes in other domains, separate
4864domains can be used to compose multiple independent noalias sets. This is
4865used for example during inlining. As the noalias function parameters are
4866turned into noalias scope metadata, a new domain is used every time the
4867function is inlined.
4868
Hal Finkel029cde62014-07-25 15:50:02 +00004869The metadata identifying each domain is itself a list containing one or two
4870entries. The first entry is the name of the domain. Note that if the name is a
Bruce Mitchenere9ffb452015-09-12 01:17:08 +00004871string then it can be combined across functions and translation units. A
Hal Finkel029cde62014-07-25 15:50:02 +00004872self-reference can be used to create globally unique domain names. A
4873descriptive string may optionally be provided as a second list entry.
4874
4875The metadata identifying each scope is also itself a list containing two or
4876three entries. The first entry is the name of the scope. Note that if the name
Bruce Mitchenere9ffb452015-09-12 01:17:08 +00004877is a string then it can be combined across functions and translation units. A
Hal Finkel029cde62014-07-25 15:50:02 +00004878self-reference can be used to create globally unique scope names. A metadata
4879reference to the scope's domain is the second entry. A descriptive string may
4880optionally be provided as a third list entry.
Hal Finkel94146652014-07-24 14:25:39 +00004881
4882For example,
4883
4884.. code-block:: llvm
4885
Hal Finkel029cde62014-07-25 15:50:02 +00004886 ; Two scope domains:
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00004887 !0 = !{!0}
4888 !1 = !{!1}
Hal Finkel94146652014-07-24 14:25:39 +00004889
Hal Finkel029cde62014-07-25 15:50:02 +00004890 ; Some scopes in these domains:
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00004891 !2 = !{!2, !0}
4892 !3 = !{!3, !0}
4893 !4 = !{!4, !1}
Hal Finkel94146652014-07-24 14:25:39 +00004894
Hal Finkel029cde62014-07-25 15:50:02 +00004895 ; Some scope lists:
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00004896 !5 = !{!4} ; A list containing only scope !4
4897 !6 = !{!4, !3, !2}
4898 !7 = !{!3}
Hal Finkel94146652014-07-24 14:25:39 +00004899
4900 ; These two instructions don't alias:
David Blaikiec7aabbb2015-03-04 22:06:14 +00004901 %0 = load float, float* %c, align 4, !alias.scope !5
Hal Finkel029cde62014-07-25 15:50:02 +00004902 store float %0, float* %arrayidx.i, align 4, !noalias !5
Hal Finkel94146652014-07-24 14:25:39 +00004903
Hal Finkel029cde62014-07-25 15:50:02 +00004904 ; These two instructions also don't alias (for domain !1, the set of scopes
4905 ; in the !alias.scope equals that in the !noalias list):
David Blaikiec7aabbb2015-03-04 22:06:14 +00004906 %2 = load float, float* %c, align 4, !alias.scope !5
Hal Finkel029cde62014-07-25 15:50:02 +00004907 store float %2, float* %arrayidx.i2, align 4, !noalias !6
Hal Finkel94146652014-07-24 14:25:39 +00004908
Adam Nemet0a8416f2015-05-11 08:30:28 +00004909 ; These two instructions may alias (for domain !0, the set of scopes in
Hal Finkel029cde62014-07-25 15:50:02 +00004910 ; the !noalias list is not a superset of, or equal to, the scopes in the
4911 ; !alias.scope list):
David Blaikiec7aabbb2015-03-04 22:06:14 +00004912 %2 = load float, float* %c, align 4, !alias.scope !6
Hal Finkel029cde62014-07-25 15:50:02 +00004913 store float %0, float* %arrayidx.i, align 4, !noalias !7
Hal Finkel94146652014-07-24 14:25:39 +00004914
Sean Silvab084af42012-12-07 10:36:55 +00004915'``fpmath``' Metadata
4916^^^^^^^^^^^^^^^^^^^^^
4917
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00004918``fpmath`` metadata may be attached to any instruction of floating-point
Sean Silvab084af42012-12-07 10:36:55 +00004919type. It can be used to express the maximum acceptable error in the
4920result of that instruction, in ULPs, thus potentially allowing the
4921compiler to use a more efficient but less accurate method of computing
4922it. ULP is defined as follows:
4923
4924 If ``x`` is a real number that lies between two finite consecutive
4925 floating-point numbers ``a`` and ``b``, without being equal to one
4926 of them, then ``ulp(x) = |b - a|``, otherwise ``ulp(x)`` is the
4927 distance between the two non-equal finite floating-point numbers
4928 nearest ``x``. Moreover, ``ulp(NaN)`` is ``NaN``.
4929
Matt Arsenault82f41512016-06-27 19:43:15 +00004930The metadata node shall consist of a single positive float type number
4931representing the maximum relative error, for example:
Sean Silvab084af42012-12-07 10:36:55 +00004932
4933.. code-block:: llvm
4934
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00004935 !0 = !{ float 2.5 } ; maximum acceptable inaccuracy is 2.5 ULPs
Sean Silvab084af42012-12-07 10:36:55 +00004936
Philip Reamesf8bf9dd2015-02-27 23:14:50 +00004937.. _range-metadata:
4938
Sean Silvab084af42012-12-07 10:36:55 +00004939'``range``' Metadata
4940^^^^^^^^^^^^^^^^^^^^
4941
Jingyue Wu37fcb592014-06-19 16:50:16 +00004942``range`` metadata may be attached only to ``load``, ``call`` and ``invoke`` of
4943integer types. It expresses the possible ranges the loaded value or the value
Eli Friedmane15a1112018-07-17 20:38:11 +00004944returned by the called function at this call site is in. If the loaded or
4945returned value is not in the specified range, the behavior is undefined. The
4946ranges are represented with a flattened list of integers. The loaded value or
4947the value returned is known to be in the union of the ranges defined by each
4948consecutive pair. Each pair has the following properties:
Sean Silvab084af42012-12-07 10:36:55 +00004949
4950- The type must match the type loaded by the instruction.
4951- The pair ``a,b`` represents the range ``[a,b)``.
4952- Both ``a`` and ``b`` are constants.
4953- The range is allowed to wrap.
4954- The range should not represent the full or empty set. That is,
4955 ``a!=b``.
4956
4957In addition, the pairs must be in signed order of the lower bound and
4958they must be non-contiguous.
4959
4960Examples:
4961
4962.. code-block:: llvm
4963
David Blaikiec7aabbb2015-03-04 22:06:14 +00004964 %a = load i8, i8* %x, align 1, !range !0 ; Can only be 0 or 1
4965 %b = load i8, i8* %y, align 1, !range !1 ; Can only be 255 (-1), 0 or 1
Jingyue Wu37fcb592014-06-19 16:50:16 +00004966 %c = call i8 @foo(), !range !2 ; Can only be 0, 1, 3, 4 or 5
4967 %d = invoke i8 @bar() to label %cont
4968 unwind label %lpad, !range !3 ; Can only be -2, -1, 3, 4 or 5
Sean Silvab084af42012-12-07 10:36:55 +00004969 ...
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00004970 !0 = !{ i8 0, i8 2 }
4971 !1 = !{ i8 255, i8 2 }
4972 !2 = !{ i8 0, i8 2, i8 3, i8 6 }
4973 !3 = !{ i8 -2, i8 0, i8 3, i8 6 }
Sean Silvab084af42012-12-07 10:36:55 +00004974
Peter Collingbourne235c2752016-12-08 19:01:00 +00004975'``absolute_symbol``' Metadata
4976^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4977
4978``absolute_symbol`` metadata may be attached to a global variable
4979declaration. It marks the declaration as a reference to an absolute symbol,
4980which causes the backend to use absolute relocations for the symbol even
4981in position independent code, and expresses the possible ranges that the
4982global variable's *address* (not its value) is in, in the same format as
Peter Collingbourned88f9282017-01-20 21:56:37 +00004983``range`` metadata, with the extension that the pair ``all-ones,all-ones``
4984may be used to represent the full set.
Peter Collingbourne235c2752016-12-08 19:01:00 +00004985
Peter Collingbourned88f9282017-01-20 21:56:37 +00004986Example (assuming 64-bit pointers):
Peter Collingbourne235c2752016-12-08 19:01:00 +00004987
4988.. code-block:: llvm
4989
4990 @a = external global i8, !absolute_symbol !0 ; Absolute symbol in range [0,256)
Peter Collingbourned88f9282017-01-20 21:56:37 +00004991 @b = external global i8, !absolute_symbol !1 ; Absolute symbol in range [0,2^64)
Peter Collingbourne235c2752016-12-08 19:01:00 +00004992
4993 ...
4994 !0 = !{ i64 0, i64 256 }
Peter Collingbourned88f9282017-01-20 21:56:37 +00004995 !1 = !{ i64 -1, i64 -1 }
Peter Collingbourne235c2752016-12-08 19:01:00 +00004996
Matthew Simpson36bbc8c2017-10-16 22:22:11 +00004997'``callees``' Metadata
4998^^^^^^^^^^^^^^^^^^^^^^
4999
5000``callees`` metadata may be attached to indirect call sites. If ``callees``
5001metadata is attached to a call site, and any callee is not among the set of
5002functions provided by the metadata, the behavior is undefined. The intent of
5003this metadata is to facilitate optimizations such as indirect-call promotion.
5004For example, in the code below, the call instruction may only target the
5005``add`` or ``sub`` functions:
5006
5007.. code-block:: llvm
5008
5009 %result = call i64 %binop(i64 %x, i64 %y), !callees !0
5010
5011 ...
5012 !0 = !{i64 (i64, i64)* @add, i64 (i64, i64)* @sub}
5013
Sanjay Patela99ab1f2015-09-02 19:06:43 +00005014'``unpredictable``' Metadata
Sanjay Patel1f12b342015-09-02 19:35:31 +00005015^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Sanjay Patela99ab1f2015-09-02 19:06:43 +00005016
5017``unpredictable`` metadata may be attached to any branch or switch
5018instruction. It can be used to express the unpredictability of control
5019flow. Similar to the llvm.expect intrinsic, it may be used to alter
5020optimizations related to compare and branch instructions. The metadata
5021is treated as a boolean value; if it exists, it signals that the branch
5022or switch that it is attached to is completely unpredictable.
5023
Pekka Jaaskelainen0d237252013-02-13 18:08:57 +00005024'``llvm.loop``'
5025^^^^^^^^^^^^^^^
5026
5027It is sometimes useful to attach information to loop constructs. Currently,
5028loop metadata is implemented as metadata attached to the branch instruction
5029in the loop latch block. This type of metadata refer to a metadata node that is
Matt Arsenault24b49c42013-07-31 17:49:08 +00005030guaranteed to be separate for each loop. The loop identifier metadata is
Paul Redmond5fdf8362013-05-28 20:00:34 +00005031specified with the name ``llvm.loop``.
Pekka Jaaskelainen0d237252013-02-13 18:08:57 +00005032
5033The loop identifier metadata is implemented using a metadata that refers to
Michael Liaoa7699082013-03-06 18:24:34 +00005034itself to avoid merging it with any other identifier metadata, e.g.,
5035during module linkage or function inlining. That is, each loop should refer
5036to their own identification metadata even if they reside in separate functions.
5037The following example contains loop identifier metadata for two separate loop
Pekka Jaaskelainen119a2b62013-02-22 12:03:07 +00005038constructs:
Pekka Jaaskelainen0d237252013-02-13 18:08:57 +00005039
5040.. code-block:: llvm
Paul Redmondeaaed3b2013-02-21 17:20:45 +00005041
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00005042 !0 = !{!0}
5043 !1 = !{!1}
Pekka Jaaskelainen119a2b62013-02-22 12:03:07 +00005044
Mark Heffernan893752a2014-07-18 19:24:51 +00005045The loop identifier metadata can be used to specify additional
5046per-loop metadata. Any operands after the first operand can be treated
5047as user-defined metadata. For example the ``llvm.loop.unroll.count``
5048suggests an unroll factor to the loop unroller:
Pekka Jaaskelainen0d237252013-02-13 18:08:57 +00005049
Paul Redmond5fdf8362013-05-28 20:00:34 +00005050.. code-block:: llvm
Pekka Jaaskelainen0d237252013-02-13 18:08:57 +00005051
Paul Redmond5fdf8362013-05-28 20:00:34 +00005052 br i1 %exitcond, label %._crit_edge, label %.lr.ph, !llvm.loop !0
5053 ...
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00005054 !0 = !{!0, !1}
5055 !1 = !{!"llvm.loop.unroll.count", i32 4}
Mark Heffernan893752a2014-07-18 19:24:51 +00005056
Mark Heffernan9d20e422014-07-21 23:11:03 +00005057'``llvm.loop.vectorize``' and '``llvm.loop.interleave``'
5058^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Mark Heffernan893752a2014-07-18 19:24:51 +00005059
Mark Heffernan9d20e422014-07-21 23:11:03 +00005060Metadata prefixed with ``llvm.loop.vectorize`` or ``llvm.loop.interleave`` are
5061used to control per-loop vectorization and interleaving parameters such as
Sean Silvaa1190322015-08-06 22:56:48 +00005062vectorization width and interleave count. These metadata should be used in
5063conjunction with ``llvm.loop`` loop identification metadata. The
Mark Heffernan9d20e422014-07-21 23:11:03 +00005064``llvm.loop.vectorize`` and ``llvm.loop.interleave`` metadata are only
5065optimization hints and the optimizer will only interleave and vectorize loops if
Sean Silvaa1190322015-08-06 22:56:48 +00005066it believes it is safe to do so. The ``llvm.mem.parallel_loop_access`` metadata
Mark Heffernan9d20e422014-07-21 23:11:03 +00005067which contains information about loop-carried memory dependencies can be helpful
5068in determining the safety of these transformations.
Mark Heffernan893752a2014-07-18 19:24:51 +00005069
Mark Heffernan9d20e422014-07-21 23:11:03 +00005070'``llvm.loop.interleave.count``' Metadata
Mark Heffernan893752a2014-07-18 19:24:51 +00005071^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5072
Mark Heffernan9d20e422014-07-21 23:11:03 +00005073This metadata suggests an interleave count to the loop interleaver.
5074The first operand is the string ``llvm.loop.interleave.count`` and the
Mark Heffernan893752a2014-07-18 19:24:51 +00005075second operand is an integer specifying the interleave count. For
5076example:
5077
5078.. code-block:: llvm
5079
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00005080 !0 = !{!"llvm.loop.interleave.count", i32 4}
Mark Heffernan893752a2014-07-18 19:24:51 +00005081
Mark Heffernan9d20e422014-07-21 23:11:03 +00005082Note that setting ``llvm.loop.interleave.count`` to 1 disables interleaving
Sean Silvaa1190322015-08-06 22:56:48 +00005083multiple iterations of the loop. If ``llvm.loop.interleave.count`` is set to 0
Mark Heffernan9d20e422014-07-21 23:11:03 +00005084then the interleave count will be determined automatically.
5085
5086'``llvm.loop.vectorize.enable``' Metadata
Dan Liew9a1829d2014-07-22 14:59:38 +00005087^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Mark Heffernan9d20e422014-07-21 23:11:03 +00005088
5089This metadata selectively enables or disables vectorization for the loop. The
5090first operand is the string ``llvm.loop.vectorize.enable`` and the second operand
Sean Silvaa1190322015-08-06 22:56:48 +00005091is a bit. If the bit operand value is 1 vectorization is enabled. A value of
Mark Heffernan9d20e422014-07-21 23:11:03 +000050920 disables vectorization:
5093
5094.. code-block:: llvm
5095
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00005096 !0 = !{!"llvm.loop.vectorize.enable", i1 0}
5097 !1 = !{!"llvm.loop.vectorize.enable", i1 1}
Mark Heffernan893752a2014-07-18 19:24:51 +00005098
5099'``llvm.loop.vectorize.width``' Metadata
5100^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5101
5102This metadata sets the target width of the vectorizer. The first
5103operand is the string ``llvm.loop.vectorize.width`` and the second
5104operand is an integer specifying the width. For example:
5105
5106.. code-block:: llvm
5107
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00005108 !0 = !{!"llvm.loop.vectorize.width", i32 4}
Mark Heffernan893752a2014-07-18 19:24:51 +00005109
5110Note that setting ``llvm.loop.vectorize.width`` to 1 disables
Sean Silvaa1190322015-08-06 22:56:48 +00005111vectorization of the loop. If ``llvm.loop.vectorize.width`` is set to
Mark Heffernan893752a2014-07-18 19:24:51 +000051120 or if the loop does not have this metadata the width will be
5113determined automatically.
5114
5115'``llvm.loop.unroll``'
5116^^^^^^^^^^^^^^^^^^^^^^
5117
5118Metadata prefixed with ``llvm.loop.unroll`` are loop unrolling
5119optimization hints such as the unroll factor. ``llvm.loop.unroll``
5120metadata should be used in conjunction with ``llvm.loop`` loop
5121identification metadata. The ``llvm.loop.unroll`` metadata are only
5122optimization hints and the unrolling will only be performed if the
5123optimizer believes it is safe to do so.
5124
Mark Heffernan893752a2014-07-18 19:24:51 +00005125'``llvm.loop.unroll.count``' Metadata
5126^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5127
5128This metadata suggests an unroll factor to the loop unroller. The
5129first operand is the string ``llvm.loop.unroll.count`` and the second
5130operand is a positive integer specifying the unroll factor. For
5131example:
5132
5133.. code-block:: llvm
5134
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00005135 !0 = !{!"llvm.loop.unroll.count", i32 4}
Mark Heffernan893752a2014-07-18 19:24:51 +00005136
5137If the trip count of the loop is less than the unroll count the loop
5138will be partially unrolled.
5139
Mark Heffernane6b4ba12014-07-23 17:31:37 +00005140'``llvm.loop.unroll.disable``' Metadata
5141^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5142
Mark Heffernan3e32a4e2015-06-30 22:48:51 +00005143This metadata disables loop unrolling. The metadata has a single operand
Sean Silvaa1190322015-08-06 22:56:48 +00005144which is the string ``llvm.loop.unroll.disable``. For example:
Mark Heffernane6b4ba12014-07-23 17:31:37 +00005145
5146.. code-block:: llvm
5147
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00005148 !0 = !{!"llvm.loop.unroll.disable"}
Mark Heffernane6b4ba12014-07-23 17:31:37 +00005149
Kevin Qin715b01e2015-03-09 06:14:18 +00005150'``llvm.loop.unroll.runtime.disable``' Metadata
Dan Liew868b0742015-03-11 13:34:49 +00005151^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Kevin Qin715b01e2015-03-09 06:14:18 +00005152
Mark Heffernan3e32a4e2015-06-30 22:48:51 +00005153This metadata disables runtime loop unrolling. The metadata has a single
Sean Silvaa1190322015-08-06 22:56:48 +00005154operand which is the string ``llvm.loop.unroll.runtime.disable``. For example:
Kevin Qin715b01e2015-03-09 06:14:18 +00005155
5156.. code-block:: llvm
5157
5158 !0 = !{!"llvm.loop.unroll.runtime.disable"}
5159
Mark Heffernan89391542015-08-10 17:28:08 +00005160'``llvm.loop.unroll.enable``' Metadata
5161^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5162
5163This metadata suggests that the loop should be fully unrolled if the trip count
5164is known at compile time and partially unrolled if the trip count is not known
5165at compile time. The metadata has a single operand which is the string
5166``llvm.loop.unroll.enable``. For example:
5167
5168.. code-block:: llvm
5169
5170 !0 = !{!"llvm.loop.unroll.enable"}
5171
Mark Heffernane6b4ba12014-07-23 17:31:37 +00005172'``llvm.loop.unroll.full``' Metadata
5173^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5174
Mark Heffernan3e32a4e2015-06-30 22:48:51 +00005175This metadata suggests that the loop should be unrolled fully. The
5176metadata has a single operand which is the string ``llvm.loop.unroll.full``.
Mark Heffernane6b4ba12014-07-23 17:31:37 +00005177For example:
5178
5179.. code-block:: llvm
5180
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00005181 !0 = !{!"llvm.loop.unroll.full"}
Pekka Jaaskelainen0d237252013-02-13 18:08:57 +00005182
David Green7fbf06c2018-07-19 12:37:00 +00005183'``llvm.loop.unroll_and_jam``'
5184^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5185
5186This metadata is treated very similarly to the ``llvm.loop.unroll`` metadata
5187above, but affect the unroll and jam pass. In addition any loop with
5188``llvm.loop.unroll`` metadata but no ``llvm.loop.unroll_and_jam`` metadata will
5189disable unroll and jam (so ``llvm.loop.unroll`` metadata will be left to the
5190unroller, plus ``llvm.loop.unroll.disable`` metadata will disable unroll and jam
5191too.)
5192
5193The metadata for unroll and jam otherwise is the same as for ``unroll``.
5194``llvm.loop.unroll_and_jam.enable``, ``llvm.loop.unroll_and_jam.disable`` and
5195``llvm.loop.unroll_and_jam.count`` do the same as for unroll.
5196``llvm.loop.unroll_and_jam.full`` is not supported. Again these are only hints
5197and the normal safety checks will still be performed.
5198
5199'``llvm.loop.unroll_and_jam.count``' Metadata
5200^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5201
5202This metadata suggests an unroll and jam factor to use, similarly to
5203``llvm.loop.unroll.count``. The first operand is the string
5204``llvm.loop.unroll_and_jam.count`` and the second operand is a positive integer
5205specifying the unroll factor. For example:
5206
5207.. code-block:: llvm
5208
5209 !0 = !{!"llvm.loop.unroll_and_jam.count", i32 4}
5210
5211If the trip count of the loop is less than the unroll count the loop
5212will be partially unroll and jammed.
5213
5214'``llvm.loop.unroll_and_jam.disable``' Metadata
5215^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5216
5217This metadata disables loop unroll and jamming. The metadata has a single
5218operand which is the string ``llvm.loop.unroll_and_jam.disable``. For example:
5219
5220.. code-block:: llvm
5221
5222 !0 = !{!"llvm.loop.unroll_and_jam.disable"}
5223
5224'``llvm.loop.unroll_and_jam.enable``' Metadata
5225^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5226
5227This metadata suggests that the loop should be fully unroll and jammed if the
5228trip count is known at compile time and partially unrolled if the trip count is
5229not known at compile time. The metadata has a single operand which is the
5230string ``llvm.loop.unroll_and_jam.enable``. For example:
5231
5232.. code-block:: llvm
5233
5234 !0 = !{!"llvm.loop.unroll_and_jam.enable"}
5235
Ashutosh Nemadf6763a2016-02-06 07:47:48 +00005236'``llvm.loop.licm_versioning.disable``' Metadata
Ashutosh Nema5f0e4722016-02-06 09:24:37 +00005237^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Ashutosh Nemadf6763a2016-02-06 07:47:48 +00005238
5239This metadata indicates that the loop should not be versioned for the purpose
5240of enabling loop-invariant code motion (LICM). The metadata has a single operand
5241which is the string ``llvm.loop.licm_versioning.disable``. For example:
5242
5243.. code-block:: llvm
5244
5245 !0 = !{!"llvm.loop.licm_versioning.disable"}
5246
Adam Nemetd2fa4142016-04-27 05:28:18 +00005247'``llvm.loop.distribute.enable``' Metadata
Adam Nemet55dc0af2016-04-27 05:59:51 +00005248^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Adam Nemetd2fa4142016-04-27 05:28:18 +00005249
5250Loop distribution allows splitting a loop into multiple loops. Currently,
5251this is only performed if the entire loop cannot be vectorized due to unsafe
Hiroshi Inoueb93daec2017-07-02 12:44:27 +00005252memory dependencies. The transformation will attempt to isolate the unsafe
Adam Nemetd2fa4142016-04-27 05:28:18 +00005253dependencies into their own loop.
5254
5255This metadata can be used to selectively enable or disable distribution of the
5256loop. The first operand is the string ``llvm.loop.distribute.enable`` and the
5257second operand is a bit. If the bit operand value is 1 distribution is
5258enabled. A value of 0 disables distribution:
5259
5260.. code-block:: llvm
5261
5262 !0 = !{!"llvm.loop.distribute.enable", i1 0}
5263 !1 = !{!"llvm.loop.distribute.enable", i1 1}
5264
5265This metadata should be used in conjunction with ``llvm.loop`` loop
5266identification metadata.
5267
Pekka Jaaskelainen0d237252013-02-13 18:08:57 +00005268'``llvm.mem``'
5269^^^^^^^^^^^^^^^
5270
5271Metadata types used to annotate memory accesses with information helpful
5272for optimizations are prefixed with ``llvm.mem``.
5273
5274'``llvm.mem.parallel_loop_access``' Metadata
5275^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5276
Mehdi Amini4a121fa2015-03-14 22:04:06 +00005277The ``llvm.mem.parallel_loop_access`` metadata refers to a loop identifier,
5278or metadata containing a list of loop identifiers for nested loops.
5279The metadata is attached to memory accessing instructions and denotes that
5280no loop carried memory dependence exist between it and other instructions denoted
Hal Finkel411d31a2016-04-26 02:00:36 +00005281with the same loop identifier. The metadata on memory reads also implies that
5282if conversion (i.e. speculative execution within a loop iteration) is safe.
Pekka Jaaskelainen23b222cc2014-05-23 11:35:46 +00005283
Mehdi Amini4a121fa2015-03-14 22:04:06 +00005284Precisely, given two instructions ``m1`` and ``m2`` that both have the
5285``llvm.mem.parallel_loop_access`` metadata, with ``L1`` and ``L2`` being the
5286set of loops associated with that metadata, respectively, then there is no loop
5287carried dependence between ``m1`` and ``m2`` for loops in both ``L1`` and
Pekka Jaaskelainen23b222cc2014-05-23 11:35:46 +00005288``L2``.
5289
Mehdi Amini4a121fa2015-03-14 22:04:06 +00005290As a special case, if all memory accessing instructions in a loop have
5291``llvm.mem.parallel_loop_access`` metadata that refers to that loop, then the
5292loop has no loop carried memory dependences and is considered to be a parallel
5293loop.
Pekka Jaaskelainen23b222cc2014-05-23 11:35:46 +00005294
Mehdi Amini4a121fa2015-03-14 22:04:06 +00005295Note that if not all memory access instructions have such metadata referring to
5296the loop, then the loop is considered not being trivially parallel. Additional
Sean Silvaa1190322015-08-06 22:56:48 +00005297memory dependence analysis is required to make that determination. As a fail
Mehdi Amini4a121fa2015-03-14 22:04:06 +00005298safe mechanism, this causes loops that were originally parallel to be considered
5299sequential (if optimization passes that are unaware of the parallel semantics
Pekka Jaaskelainen23b222cc2014-05-23 11:35:46 +00005300insert new memory instructions into the loop body).
Pekka Jaaskelainen0d237252013-02-13 18:08:57 +00005301
5302Example of a loop that is considered parallel due to its correct use of
Paul Redmond5fdf8362013-05-28 20:00:34 +00005303both ``llvm.loop`` and ``llvm.mem.parallel_loop_access``
Pekka Jaaskelainen0d237252013-02-13 18:08:57 +00005304metadata types that refer to the same loop identifier metadata.
5305
5306.. code-block:: llvm
5307
5308 for.body:
Paul Redmond5fdf8362013-05-28 20:00:34 +00005309 ...
David Blaikiec7aabbb2015-03-04 22:06:14 +00005310 %val0 = load i32, i32* %arrayidx, !llvm.mem.parallel_loop_access !0
Paul Redmond5fdf8362013-05-28 20:00:34 +00005311 ...
Tobias Grosserfbe95dc2014-03-05 13:36:04 +00005312 store i32 %val0, i32* %arrayidx1, !llvm.mem.parallel_loop_access !0
Paul Redmond5fdf8362013-05-28 20:00:34 +00005313 ...
5314 br i1 %exitcond, label %for.end, label %for.body, !llvm.loop !0
Pekka Jaaskelainen0d237252013-02-13 18:08:57 +00005315
5316 for.end:
5317 ...
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00005318 !0 = !{!0}
Pekka Jaaskelainen0d237252013-02-13 18:08:57 +00005319
5320It is also possible to have nested parallel loops. In that case the
5321memory accesses refer to a list of loop identifier metadata nodes instead of
5322the loop identifier metadata node directly:
5323
5324.. code-block:: llvm
5325
5326 outer.for.body:
Tobias Grosserfbe95dc2014-03-05 13:36:04 +00005327 ...
David Blaikiec7aabbb2015-03-04 22:06:14 +00005328 %val1 = load i32, i32* %arrayidx3, !llvm.mem.parallel_loop_access !2
Tobias Grosserfbe95dc2014-03-05 13:36:04 +00005329 ...
5330 br label %inner.for.body
Pekka Jaaskelainen0d237252013-02-13 18:08:57 +00005331
5332 inner.for.body:
Paul Redmond5fdf8362013-05-28 20:00:34 +00005333 ...
David Blaikiec7aabbb2015-03-04 22:06:14 +00005334 %val0 = load i32, i32* %arrayidx1, !llvm.mem.parallel_loop_access !0
Paul Redmond5fdf8362013-05-28 20:00:34 +00005335 ...
Tobias Grosserfbe95dc2014-03-05 13:36:04 +00005336 store i32 %val0, i32* %arrayidx2, !llvm.mem.parallel_loop_access !0
Paul Redmond5fdf8362013-05-28 20:00:34 +00005337 ...
5338 br i1 %exitcond, label %inner.for.end, label %inner.for.body, !llvm.loop !1
Pekka Jaaskelainen0d237252013-02-13 18:08:57 +00005339
5340 inner.for.end:
Paul Redmond5fdf8362013-05-28 20:00:34 +00005341 ...
Tobias Grosserfbe95dc2014-03-05 13:36:04 +00005342 store i32 %val1, i32* %arrayidx4, !llvm.mem.parallel_loop_access !2
Paul Redmond5fdf8362013-05-28 20:00:34 +00005343 ...
5344 br i1 %exitcond, label %outer.for.end, label %outer.for.body, !llvm.loop !2
Pekka Jaaskelainen0d237252013-02-13 18:08:57 +00005345
5346 outer.for.end: ; preds = %for.body
5347 ...
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00005348 !0 = !{!1, !2} ; a list of loop identifiers
5349 !1 = !{!1} ; an identifier for the inner loop
5350 !2 = !{!2} ; an identifier for the outer loop
Pekka Jaaskelainen0d237252013-02-13 18:08:57 +00005351
Hiroshi Yamauchidce9def2017-11-02 22:26:51 +00005352'``irr_loop``' Metadata
5353^^^^^^^^^^^^^^^^^^^^^^^
5354
5355``irr_loop`` metadata may be attached to the terminator instruction of a basic
5356block that's an irreducible loop header (note that an irreducible loop has more
5357than once header basic blocks.) If ``irr_loop`` metadata is attached to the
5358terminator instruction of a basic block that is not really an irreducible loop
5359header, the behavior is undefined. The intent of this metadata is to improve the
5360accuracy of the block frequency propagation. For example, in the code below, the
5361block ``header0`` may have a loop header weight (relative to the other headers of
5362the irreducible loop) of 100:
5363
5364.. code-block:: llvm
5365
5366 header0:
5367 ...
5368 br i1 %cmp, label %t1, label %t2, !irr_loop !0
5369
5370 ...
5371 !0 = !{"loop_header_weight", i64 100}
5372
5373Irreducible loop header weights are typically based on profile data.
5374
Piotr Padlewski6c15ec42015-09-15 18:32:14 +00005375'``invariant.group``' Metadata
5376^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5377
Piotr Padlewski74b155f2018-04-08 13:53:04 +00005378The experimental ``invariant.group`` metadata may be attached to
Piotr Padlewskice358262018-05-18 23:53:46 +00005379``load``/``store`` instructions referencing a single metadata with no entries.
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +00005380The existence of the ``invariant.group`` metadata on the instruction tells
5381the optimizer that every ``load`` and ``store`` to the same pointer operand
Piotr Padlewskice358262018-05-18 23:53:46 +00005382can be assumed to load or store the same
Piotr Padlewski5dde8092018-05-03 11:03:01 +00005383value (but see the ``llvm.launder.invariant.group`` intrinsic which affects
Piotr Padlewskida362152016-12-30 18:45:07 +00005384when two pointers are considered the same). Pointers returned by bitcast or
5385getelementptr with only zero indices are considered the same.
Piotr Padlewski6c15ec42015-09-15 18:32:14 +00005386
5387Examples:
5388
5389.. code-block:: llvm
5390
5391 @unknownPtr = external global i8
5392 ...
5393 %ptr = alloca i8
5394 store i8 42, i8* %ptr, !invariant.group !0
5395 call void @foo(i8* %ptr)
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +00005396
Piotr Padlewski6c15ec42015-09-15 18:32:14 +00005397 %a = load i8, i8* %ptr, !invariant.group !0 ; Can assume that value under %ptr didn't change
5398 call void @foo(i8* %ptr)
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +00005399
5400 %newPtr = call i8* @getPointer(i8* %ptr)
Piotr Padlewski6c15ec42015-09-15 18:32:14 +00005401 %c = load i8, i8* %newPtr, !invariant.group !0 ; Can't assume anything, because we only have information about %ptr
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +00005402
Piotr Padlewski6c15ec42015-09-15 18:32:14 +00005403 %unknownValue = load i8, i8* @unknownPtr
5404 store i8 %unknownValue, i8* %ptr, !invariant.group !0 ; Can assume that %unknownValue == 42
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +00005405
Piotr Padlewski6c15ec42015-09-15 18:32:14 +00005406 call void @foo(i8* %ptr)
Piotr Padlewski5dde8092018-05-03 11:03:01 +00005407 %newPtr2 = call i8* @llvm.launder.invariant.group(i8* %ptr)
5408 %d = load i8, i8* %newPtr2, !invariant.group !0 ; Can't step through launder.invariant.group to get value of %ptr
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +00005409
Piotr Padlewski6c15ec42015-09-15 18:32:14 +00005410 ...
5411 declare void @foo(i8*)
5412 declare i8* @getPointer(i8*)
Piotr Padlewski5dde8092018-05-03 11:03:01 +00005413 declare i8* @llvm.launder.invariant.group(i8*)
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +00005414
Piotr Padlewskice358262018-05-18 23:53:46 +00005415 !0 = !{}
Piotr Padlewski6c15ec42015-09-15 18:32:14 +00005416
Piotr Padlewskif8486e32017-04-12 07:59:35 +00005417The invariant.group metadata must be dropped when replacing one pointer by
5418another based on aliasing information. This is because invariant.group is tied
5419to the SSA value of the pointer operand.
5420
5421.. code-block:: llvm
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +00005422
Piotr Padlewskif8486e32017-04-12 07:59:35 +00005423 %v = load i8, i8* %x, !invariant.group !0
5424 ; if %x mustalias %y then we can replace the above instruction with
5425 %v = load i8, i8* %y
5426
Piotr Padlewski74b155f2018-04-08 13:53:04 +00005427Note that this is an experimental feature, which means that its semantics might
5428change in the future.
Piotr Padlewskif8486e32017-04-12 07:59:35 +00005429
Peter Collingbournea333db82016-07-26 22:31:30 +00005430'``type``' Metadata
5431^^^^^^^^^^^^^^^^^^^
5432
5433See :doc:`TypeMetadata`.
Piotr Padlewski6c15ec42015-09-15 18:32:14 +00005434
Evgeniy Stepanov51c962f722017-03-17 22:17:24 +00005435'``associated``' Metadata
Evgeniy Stepanov4d490de2017-03-17 22:31:13 +00005436^^^^^^^^^^^^^^^^^^^^^^^^^
Evgeniy Stepanov51c962f722017-03-17 22:17:24 +00005437
5438The ``associated`` metadata may be attached to a global object
5439declaration with a single argument that references another global object.
5440
5441This metadata prevents discarding of the global object in linker GC
5442unless the referenced object is also discarded. The linker support for
5443this feature is spotty. For best compatibility, globals carrying this
5444metadata may also:
5445
5446- Be in a comdat with the referenced global.
5447- Be in @llvm.compiler.used.
5448- Have an explicit section with a name which is a valid C identifier.
5449
5450It does not have any effect on non-ELF targets.
5451
5452Example:
5453
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +00005454.. code-block:: text
Evgeniy Stepanov4d490de2017-03-17 22:31:13 +00005455
Evgeniy Stepanov51c962f722017-03-17 22:17:24 +00005456 $a = comdat any
5457 @a = global i32 1, comdat $a
5458 @b = internal global i32 2, comdat $a, section "abc", !associated !0
5459 !0 = !{i32* @a}
5460
Piotr Padlewski6c15ec42015-09-15 18:32:14 +00005461
Teresa Johnsond72f51c2017-06-15 15:57:12 +00005462'``prof``' Metadata
5463^^^^^^^^^^^^^^^^^^^
5464
5465The ``prof`` metadata is used to record profile data in the IR.
5466The first operand of the metadata node indicates the profile metadata
5467type. There are currently 3 types:
5468:ref:`branch_weights<prof_node_branch_weights>`,
5469:ref:`function_entry_count<prof_node_function_entry_count>`, and
5470:ref:`VP<prof_node_VP>`.
5471
5472.. _prof_node_branch_weights:
5473
5474branch_weights
5475""""""""""""""
5476
5477Branch weight metadata attached to a branch, select, switch or call instruction
5478represents the likeliness of the associated branch being taken.
5479For more information, see :doc:`BranchWeightMetadata`.
5480
5481.. _prof_node_function_entry_count:
5482
5483function_entry_count
5484""""""""""""""""""""
5485
5486Function entry count metadata can be attached to function definitions
5487to record the number of times the function is called. Used with BFI
5488information, it is also used to derive the basic block profile count.
5489For more information, see :doc:`BranchWeightMetadata`.
5490
5491.. _prof_node_VP:
5492
5493VP
5494""
5495
5496VP (value profile) metadata can be attached to instructions that have
5497value profile information. Currently this is indirect calls (where it
5498records the hottest callees) and calls to memory intrinsics such as memcpy,
5499memmove, and memset (where it records the hottest byte lengths).
5500
5501Each VP metadata node contains "VP" string, then a uint32_t value for the value
5502profiling kind, a uint64_t value for the total number of times the instruction
5503is executed, followed by uint64_t value and execution count pairs.
5504The value profiling kind is 0 for indirect call targets and 1 for memory
5505operations. For indirect call targets, each profile value is a hash
5506of the callee function name, and for memory operations each value is the
5507byte length.
5508
5509Note that the value counts do not need to add up to the total count
5510listed in the third operand (in practice only the top hottest values
5511are tracked and reported).
5512
5513Indirect call example:
5514
5515.. code-block:: llvm
5516
5517 call void %f(), !prof !1
5518 !1 = !{!"VP", i32 0, i64 1600, i64 7651369219802541373, i64 1030, i64 -4377547752858689819, i64 410}
5519
5520Note that the VP type is 0 (the second operand), which indicates this is
5521an indirect call value profile data. The third operand indicates that the
5522indirect call executed 1600 times. The 4th and 6th operands give the
5523hashes of the 2 hottest target functions' names (this is the same hash used
5524to represent function names in the profile database), and the 5th and 7th
5525operands give the execution count that each of the respective prior target
5526functions was called.
5527
Sean Silvab084af42012-12-07 10:36:55 +00005528Module Flags Metadata
5529=====================
5530
5531Information about the module as a whole is difficult to convey to LLVM's
5532subsystems. The LLVM IR isn't sufficient to transmit this information.
5533The ``llvm.module.flags`` named metadata exists in order to facilitate
Dmitri Gribenkoe8131122013-01-19 20:34:20 +00005534this. These flags are in the form of key / value pairs --- much like a
5535dictionary --- making it easy for any subsystem who cares about a flag to
Sean Silvab084af42012-12-07 10:36:55 +00005536look it up.
5537
5538The ``llvm.module.flags`` metadata contains a list of metadata triplets.
5539Each triplet has the following form:
5540
5541- The first element is a *behavior* flag, which specifies the behavior
5542 when two (or more) modules are merged together, and it encounters two
5543 (or more) metadata with the same ID. The supported behaviors are
5544 described below.
5545- The second element is a metadata string that is a unique ID for the
Daniel Dunbar25c4b572013-01-15 01:22:53 +00005546 metadata. Each module may only have one flag entry for each unique ID (not
5547 including entries with the **Require** behavior).
Sean Silvab084af42012-12-07 10:36:55 +00005548- The third element is the value of the flag.
5549
5550When two (or more) modules are merged together, the resulting
Daniel Dunbar25c4b572013-01-15 01:22:53 +00005551``llvm.module.flags`` metadata is the union of the modules' flags. That is, for
5552each unique metadata ID string, there will be exactly one entry in the merged
5553modules ``llvm.module.flags`` metadata table, and the value for that entry will
5554be determined by the merge behavior flag, as described below. The only exception
5555is that entries with the *Require* behavior are always preserved.
Sean Silvab084af42012-12-07 10:36:55 +00005556
5557The following behaviors are supported:
5558
5559.. list-table::
5560 :header-rows: 1
5561 :widths: 10 90
5562
5563 * - Value
5564 - Behavior
5565
5566 * - 1
5567 - **Error**
Daniel Dunbar25c4b572013-01-15 01:22:53 +00005568 Emits an error if two values disagree, otherwise the resulting value
5569 is that of the operands.
Sean Silvab084af42012-12-07 10:36:55 +00005570
5571 * - 2
5572 - **Warning**
Daniel Dunbar25c4b572013-01-15 01:22:53 +00005573 Emits a warning if two values disagree. The result value will be the
5574 operand for the flag from the first module being linked.
Sean Silvab084af42012-12-07 10:36:55 +00005575
5576 * - 3
5577 - **Require**
Daniel Dunbar25c4b572013-01-15 01:22:53 +00005578 Adds a requirement that another module flag be present and have a
5579 specified value after linking is performed. The value must be a
5580 metadata pair, where the first element of the pair is the ID of the
5581 module flag to be restricted, and the second element of the pair is
5582 the value the module flag should be restricted to. This behavior can
5583 be used to restrict the allowable results (via triggering of an
5584 error) of linking IDs with the **Override** behavior.
Sean Silvab084af42012-12-07 10:36:55 +00005585
5586 * - 4
5587 - **Override**
Daniel Dunbar25c4b572013-01-15 01:22:53 +00005588 Uses the specified value, regardless of the behavior or value of the
5589 other module. If both modules specify **Override**, but the values
5590 differ, an error will be emitted.
5591
Daniel Dunbard77d9fb2013-01-16 21:38:56 +00005592 * - 5
5593 - **Append**
5594 Appends the two values, which are required to be metadata nodes.
5595
5596 * - 6
5597 - **AppendUnique**
5598 Appends the two values, which are required to be metadata
5599 nodes. However, duplicate entries in the second list are dropped
5600 during the append operation.
5601
Steven Wu86a511e2017-08-15 16:16:33 +00005602 * - 7
5603 - **Max**
5604 Takes the max of the two values, which are required to be integers.
5605
Daniel Dunbar25c4b572013-01-15 01:22:53 +00005606It is an error for a particular unique flag ID to have multiple behaviors,
5607except in the case of **Require** (which adds restrictions on another metadata
5608value) or **Override**.
Sean Silvab084af42012-12-07 10:36:55 +00005609
5610An example of module flags:
5611
5612.. code-block:: llvm
5613
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00005614 !0 = !{ i32 1, !"foo", i32 1 }
5615 !1 = !{ i32 4, !"bar", i32 37 }
5616 !2 = !{ i32 2, !"qux", i32 42 }
5617 !3 = !{ i32 3, !"qux",
5618 !{
5619 !"foo", i32 1
Sean Silvab084af42012-12-07 10:36:55 +00005620 }
5621 }
5622 !llvm.module.flags = !{ !0, !1, !2, !3 }
5623
5624- Metadata ``!0`` has the ID ``!"foo"`` and the value '1'. The behavior
5625 if two or more ``!"foo"`` flags are seen is to emit an error if their
5626 values are not equal.
5627
5628- Metadata ``!1`` has the ID ``!"bar"`` and the value '37'. The
5629 behavior if two or more ``!"bar"`` flags are seen is to use the value
Daniel Dunbar25c4b572013-01-15 01:22:53 +00005630 '37'.
Sean Silvab084af42012-12-07 10:36:55 +00005631
5632- Metadata ``!2`` has the ID ``!"qux"`` and the value '42'. The
5633 behavior if two or more ``!"qux"`` flags are seen is to emit a
5634 warning if their values are not equal.
5635
5636- Metadata ``!3`` has the ID ``!"qux"`` and the value:
5637
5638 ::
5639
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00005640 !{ !"foo", i32 1 }
Sean Silvab084af42012-12-07 10:36:55 +00005641
Daniel Dunbar25c4b572013-01-15 01:22:53 +00005642 The behavior is to emit an error if the ``llvm.module.flags`` does not
5643 contain a flag with the ID ``!"foo"`` that has the value '1' after linking is
5644 performed.
Sean Silvab084af42012-12-07 10:36:55 +00005645
5646Objective-C Garbage Collection Module Flags Metadata
5647----------------------------------------------------
5648
5649On the Mach-O platform, Objective-C stores metadata about garbage
5650collection in a special section called "image info". The metadata
5651consists of a version number and a bitmask specifying what types of
5652garbage collection are supported (if any) by the file. If two or more
5653modules are linked together their garbage collection metadata needs to
5654be merged rather than appended together.
5655
5656The Objective-C garbage collection module flags metadata consists of the
5657following key-value pairs:
5658
5659.. list-table::
5660 :header-rows: 1
5661 :widths: 30 70
5662
5663 * - Key
5664 - Value
5665
Daniel Dunbar1dc66ca2013-01-17 18:57:32 +00005666 * - ``Objective-C Version``
Dmitri Gribenkoe8131122013-01-19 20:34:20 +00005667 - **[Required]** --- The Objective-C ABI version. Valid values are 1 and 2.
Sean Silvab084af42012-12-07 10:36:55 +00005668
Daniel Dunbar1dc66ca2013-01-17 18:57:32 +00005669 * - ``Objective-C Image Info Version``
Dmitri Gribenkoe8131122013-01-19 20:34:20 +00005670 - **[Required]** --- The version of the image info section. Currently
Sean Silvab084af42012-12-07 10:36:55 +00005671 always 0.
5672
Daniel Dunbar1dc66ca2013-01-17 18:57:32 +00005673 * - ``Objective-C Image Info Section``
Dmitri Gribenkoe8131122013-01-19 20:34:20 +00005674 - **[Required]** --- The section to place the metadata. Valid values are
Sean Silvab084af42012-12-07 10:36:55 +00005675 ``"__OBJC, __image_info, regular"`` for Objective-C ABI version 1, and
5676 ``"__DATA,__objc_imageinfo, regular, no_dead_strip"`` for
5677 Objective-C ABI version 2.
5678
Daniel Dunbar1dc66ca2013-01-17 18:57:32 +00005679 * - ``Objective-C Garbage Collection``
Dmitri Gribenkoe8131122013-01-19 20:34:20 +00005680 - **[Required]** --- Specifies whether garbage collection is supported or
Sean Silvab084af42012-12-07 10:36:55 +00005681 not. Valid values are 0, for no garbage collection, and 2, for garbage
5682 collection supported.
5683
Daniel Dunbar1dc66ca2013-01-17 18:57:32 +00005684 * - ``Objective-C GC Only``
Dmitri Gribenkoe8131122013-01-19 20:34:20 +00005685 - **[Optional]** --- Specifies that only garbage collection is supported.
Sean Silvab084af42012-12-07 10:36:55 +00005686 If present, its value must be 6. This flag requires that the
5687 ``Objective-C Garbage Collection`` flag have the value 2.
5688
5689Some important flag interactions:
5690
5691- If a module with ``Objective-C Garbage Collection`` set to 0 is
5692 merged with a module with ``Objective-C Garbage Collection`` set to
5693 2, then the resulting module has the
5694 ``Objective-C Garbage Collection`` flag set to 0.
5695- A module with ``Objective-C Garbage Collection`` set to 0 cannot be
5696 merged with a module with ``Objective-C GC Only`` set to 6.
5697
Oliver Stannard5dc29342014-06-20 10:08:11 +00005698C type width Module Flags Metadata
5699----------------------------------
5700
5701The ARM backend emits a section into each generated object file describing the
5702options that it was compiled with (in a compiler-independent way) to prevent
5703linking incompatible objects, and to allow automatic library selection. Some
5704of these options are not visible at the IR level, namely wchar_t width and enum
5705width.
5706
5707To pass this information to the backend, these options are encoded in module
5708flags metadata, using the following key-value pairs:
5709
5710.. list-table::
5711 :header-rows: 1
5712 :widths: 30 70
5713
5714 * - Key
5715 - Value
5716
5717 * - short_wchar
5718 - * 0 --- sizeof(wchar_t) == 4
5719 * 1 --- sizeof(wchar_t) == 2
5720
5721 * - short_enum
5722 - * 0 --- Enums are at least as large as an ``int``.
5723 * 1 --- Enums are stored in the smallest integer type which can
5724 represent all of its values.
5725
5726For example, the following metadata section specifies that the module was
5727compiled with a ``wchar_t`` width of 4 bytes, and the underlying type of an
5728enum is the smallest type which can represent all of its values::
5729
5730 !llvm.module.flags = !{!0, !1}
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00005731 !0 = !{i32 1, !"short_wchar", i32 1}
5732 !1 = !{i32 1, !"short_enum", i32 0}
Oliver Stannard5dc29342014-06-20 10:08:11 +00005733
Peter Collingbourne89061b22017-06-12 20:10:48 +00005734Automatic Linker Flags Named Metadata
5735=====================================
5736
5737Some targets support embedding flags to the linker inside individual object
5738files. Typically this is used in conjunction with language extensions which
5739allow source files to explicitly declare the libraries they depend on, and have
5740these automatically be transmitted to the linker via object files.
5741
5742These flags are encoded in the IR using named metadata with the name
5743``!llvm.linker.options``. Each operand is expected to be a metadata node
5744which should be a list of other metadata nodes, each of which should be a
5745list of metadata strings defining linker options.
5746
5747For example, the following metadata section specifies two separate sets of
5748linker options, presumably to link against ``libz`` and the ``Cocoa``
5749framework::
5750
5751 !0 = !{ !"-lz" },
5752 !1 = !{ !"-framework", !"Cocoa" } } }
5753 !llvm.linker.options = !{ !0, !1 }
5754
5755The metadata encoding as lists of lists of options, as opposed to a collapsed
5756list of options, is chosen so that the IR encoding can use multiple option
5757strings to specify e.g., a single library, while still having that specifier be
5758preserved as an atomic element that can be recognized by a target specific
5759assembly writer or object file emitter.
5760
5761Each individual option is required to be either a valid option for the target's
5762linker, or an option that is reserved by the target specific assembly writer or
5763object file emitter. No other aspect of these options is defined by the IR.
5764
Teresa Johnson08d5b4e2018-05-26 02:34:13 +00005765.. _summary:
5766
5767ThinLTO Summary
5768===============
5769
5770Compiling with `ThinLTO <https://clang.llvm.org/docs/ThinLTO.html>`_
5771causes the building of a compact summary of the module that is emitted into
5772the bitcode. The summary is emitted into the LLVM assembly and identified
5773in syntax by a caret ('``^``').
5774
5775*Note that temporarily the summary entries are skipped when parsing the
5776assembly, although the parsing support is actively being implemented. The
5777following describes when the summary entries will be parsed once implemented.*
5778The summary will be parsed into a ModuleSummaryIndex object under the
5779same conditions where summary index is currently built from bitcode.
5780Specifically, tools that test the Thin Link portion of a ThinLTO compile
5781(i.e. llvm-lto and llvm-lto2), or when parsing a combined index
5782for a distributed ThinLTO backend via clang's "``-fthinlto-index=<>``" flag.
5783Additionally, it will be parsed into a bitcode output, along with the Module
5784IR, via the "``llvm-as``" tool. Tools that parse the Module IR for the purposes
5785of optimization (e.g. "``clang -x ir``" and "``opt``"), will ignore the
5786summary entries (just as they currently ignore summary entries in a bitcode
5787input file).
5788
5789There are currently 3 types of summary entries in the LLVM assembly:
5790:ref:`module paths<module_path_summary>`,
5791:ref:`global values<gv_summary>`, and
5792:ref:`type identifiers<typeid_summary>`.
5793
5794.. _module_path_summary:
5795
5796Module Path Summary Entry
5797-------------------------
5798
5799Each module path summary entry lists a module containing global values included
5800in the summary. For a single IR module there will be one such entry, but
5801in a combined summary index produced during the thin link, there will be
5802one module path entry per linked module with summary.
5803
5804Example:
5805
5806.. code-block:: llvm
5807
5808 ^0 = module: (path: "/path/to/file.o", hash: (2468601609, 1329373163, 1565878005, 638838075, 3148790418))
5809
5810The ``path`` field is a string path to the bitcode file, and the ``hash``
5811field is the 160-bit SHA-1 hash of the IR bitcode contents, used for
5812incremental builds and caching.
5813
5814.. _gv_summary:
5815
5816Global Value Summary Entry
5817--------------------------
5818
5819Each global value summary entry corresponds to a global value defined or
5820referenced by a summarized module.
5821
5822Example:
5823
5824.. code-block:: llvm
5825
5826 ^4 = gv: (name: "f"[, summaries: (Summary)[, (Summary)]*]?) ; guid = 14740650423002898831
5827
5828For declarations, there will not be a summary list. For definitions, a
5829global value will contain a list of summaries, one per module containing
5830a definition. There can be multiple entries in a combined summary index
5831for symbols with weak linkage.
5832
5833Each ``Summary`` format will depend on whether the global value is a
5834:ref:`function<function_summary>`, :ref:`variable<variable_summary>`, or
5835:ref:`alias<alias_summary>`.
5836
5837.. _function_summary:
5838
5839Function Summary
5840^^^^^^^^^^^^^^^^
5841
5842If the global value is a function, the ``Summary`` entry will look like:
5843
5844.. code-block:: llvm
5845
5846 function: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0), insts: 2[, FuncFlags]?[, Calls]?[, TypeIdInfo]?[, Refs]?
5847
5848The ``module`` field includes the summary entry id for the module containing
5849this definition, and the ``flags`` field contains information such as
5850the linkage type, a flag indicating whether it is legal to import the
5851definition, whether it is globally live and whether the linker resolved it
5852to a local definition (the latter two are populated during the thin link).
5853The ``insts`` field contains the number of IR instructions in the function.
5854Finally, there are several optional fields: :ref:`FuncFlags<funcflags_summary>`,
5855:ref:`Calls<calls_summary>`, :ref:`TypeIdInfo<typeidinfo_summary>`,
5856:ref:`Refs<refs_summary>`.
5857
5858.. _variable_summary:
5859
5860Global Variable Summary
5861^^^^^^^^^^^^^^^^^^^^^^^
5862
5863If the global value is a variable, the ``Summary`` entry will look like:
5864
5865.. code-block:: llvm
5866
5867 variable: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0)[, Refs]?
5868
5869The variable entry contains a subset of the fields in a
5870:ref:`function summary <function_summary>`, see the descriptions there.
5871
5872.. _alias_summary:
5873
5874Alias Summary
5875^^^^^^^^^^^^^
5876
5877If the global value is an alias, the ``Summary`` entry will look like:
5878
5879.. code-block:: llvm
5880
5881 alias: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0), aliasee: ^2)
5882
5883The ``module`` and ``flags`` fields are as described for a
5884:ref:`function summary <function_summary>`. The ``aliasee`` field
5885contains a reference to the global value summary entry of the aliasee.
5886
5887.. _funcflags_summary:
5888
5889Function Flags
5890^^^^^^^^^^^^^^
5891
5892The optional ``FuncFlags`` field looks like:
5893
5894.. code-block:: llvm
5895
5896 funcFlags: (readNone: 0, readOnly: 0, noRecurse: 0, returnDoesNotAlias: 0)
5897
5898If unspecified, flags are assumed to hold the conservative ``false`` value of
5899``0``.
5900
5901.. _calls_summary:
5902
5903Calls
5904^^^^^
5905
5906The optional ``Calls`` field looks like:
5907
5908.. code-block:: llvm
5909
5910 calls: ((Callee)[, (Callee)]*)
5911
5912where each ``Callee`` looks like:
5913
5914.. code-block:: llvm
5915
5916 callee: ^1[, hotness: None]?[, relbf: 0]?
5917
5918The ``callee`` refers to the summary entry id of the callee. At most one
5919of ``hotness`` (which can take the values ``Unknown``, ``Cold``, ``None``,
5920``Hot``, and ``Critical``), and ``relbf`` (which holds the integer
5921branch frequency relative to the entry frequency, scaled down by 2^8)
5922may be specified. The defaults are ``Unknown`` and ``0``, respectively.
5923
5924.. _refs_summary:
5925
5926Refs
5927^^^^
5928
5929The optional ``Refs`` field looks like:
5930
5931.. code-block:: llvm
5932
5933 refs: ((Ref)[, (Ref)]*)
5934
5935where each ``Ref`` contains a reference to the summary id of the referenced
5936value (e.g. ``^1``).
5937
5938.. _typeidinfo_summary:
5939
5940TypeIdInfo
5941^^^^^^^^^^
5942
5943The optional ``TypeIdInfo`` field, used for
5944`Control Flow Integrity <http://clang.llvm.org/docs/ControlFlowIntegrity.html>`_,
5945looks like:
5946
5947.. code-block:: llvm
5948
5949 typeIdInfo: [(TypeTests)]?[, (TypeTestAssumeVCalls)]?[, (TypeCheckedLoadVCalls)]?[, (TypeTestAssumeConstVCalls)]?[, (TypeCheckedLoadConstVCalls)]?
5950
5951These optional fields have the following forms:
5952
5953TypeTests
5954"""""""""
5955
5956.. code-block:: llvm
5957
5958 typeTests: (TypeIdRef[, TypeIdRef]*)
5959
5960Where each ``TypeIdRef`` refers to a :ref:`type id<typeid_summary>`
5961by summary id or ``GUID``.
5962
5963TypeTestAssumeVCalls
5964""""""""""""""""""""
5965
5966.. code-block:: llvm
5967
5968 typeTestAssumeVCalls: (VFuncId[, VFuncId]*)
5969
5970Where each VFuncId has the format:
5971
5972.. code-block:: llvm
5973
5974 vFuncId: (TypeIdRef, offset: 16)
5975
5976Where each ``TypeIdRef`` refers to a :ref:`type id<typeid_summary>`
5977by summary id or ``GUID`` preceeded by a ``guid:`` tag.
5978
5979TypeCheckedLoadVCalls
5980"""""""""""""""""""""
5981
5982.. code-block:: llvm
5983
5984 typeCheckedLoadVCalls: (VFuncId[, VFuncId]*)
5985
5986Where each VFuncId has the format described for ``TypeTestAssumeVCalls``.
5987
5988TypeTestAssumeConstVCalls
5989"""""""""""""""""""""""""
5990
5991.. code-block:: llvm
5992
5993 typeTestAssumeConstVCalls: (ConstVCall[, ConstVCall]*)
5994
5995Where each ConstVCall has the format:
5996
5997.. code-block:: llvm
5998
5999 VFuncId, args: (Arg[, Arg]*)
6000
6001and where each VFuncId has the format described for ``TypeTestAssumeVCalls``,
6002and each Arg is an integer argument number.
6003
6004TypeCheckedLoadConstVCalls
6005""""""""""""""""""""""""""
6006
6007.. code-block:: llvm
6008
6009 typeCheckedLoadConstVCalls: (ConstVCall[, ConstVCall]*)
6010
6011Where each ConstVCall has the format described for
6012``TypeTestAssumeConstVCalls``.
6013
6014.. _typeid_summary:
6015
6016Type ID Summary Entry
6017---------------------
6018
6019Each type id summary entry corresponds to a type identifier resolution
6020which is generated during the LTO link portion of the compile when building
6021with `Control Flow Integrity <http://clang.llvm.org/docs/ControlFlowIntegrity.html>`_,
6022so these are only present in a combined summary index.
6023
6024Example:
6025
6026.. code-block:: llvm
6027
6028 ^4 = typeid: (name: "_ZTS1A", summary: (typeTestRes: (kind: allOnes, sizeM1BitWidth: 7[, alignLog2: 0]?[, sizeM1: 0]?[, bitMask: 0]?[, inlineBits: 0]?)[, WpdResolutions]?)) ; guid = 7004155349499253778
6029
6030The ``typeTestRes`` gives the type test resolution ``kind`` (which may
6031be ``unsat``, ``byteArray``, ``inline``, ``single``, or ``allOnes``), and
6032the ``size-1`` bit width. It is followed by optional flags, which default to 0,
6033and an optional WpdResolutions (whole program devirtualization resolution)
6034field that looks like:
6035
6036.. code-block:: llvm
6037
6038 wpdResolutions: ((offset: 0, WpdRes)[, (offset: 1, WpdRes)]*
6039
6040where each entry is a mapping from the given byte offset to the whole-program
6041devirtualization resolution WpdRes, that has one of the following formats:
6042
6043.. code-block:: llvm
6044
6045 wpdRes: (kind: branchFunnel)
6046 wpdRes: (kind: singleImpl, singleImplName: "_ZN1A1nEi")
6047 wpdRes: (kind: indir)
6048
6049Additionally, each wpdRes has an optional ``resByArg`` field, which
6050describes the resolutions for calls with all constant integer arguments:
6051
6052.. code-block:: llvm
6053
6054 resByArg: (ResByArg[, ResByArg]*)
6055
6056where ResByArg is:
6057
6058.. code-block:: llvm
6059
6060 args: (Arg[, Arg]*), byArg: (kind: UniformRetVal[, info: 0][, byte: 0][, bit: 0])
6061
6062Where the ``kind`` can be ``Indir``, ``UniformRetVal``, ``UniqueRetVal``
6063or ``VirtualConstProp``. The ``info`` field is only used if the kind
6064is ``UniformRetVal`` (indicates the uniform return value), or
6065``UniqueRetVal`` (holds the return value associated with the unique vtable
6066(0 or 1)). The ``byte`` and ``bit`` fields are only used if the target does
6067not support the use of absolute symbols to store constants.
6068
Eli Bendersky0220e6b2013-06-07 20:24:43 +00006069.. _intrinsicglobalvariables:
6070
Sean Silvab084af42012-12-07 10:36:55 +00006071Intrinsic Global Variables
6072==========================
6073
6074LLVM has a number of "magic" global variables that contain data that
6075affect code generation or other IR semantics. These are documented here.
6076All globals of this sort should have a section specified as
6077"``llvm.metadata``". This section and all globals that start with
6078"``llvm.``" are reserved for use by LLVM.
6079
Eli Bendersky0220e6b2013-06-07 20:24:43 +00006080.. _gv_llvmused:
6081
Sean Silvab084af42012-12-07 10:36:55 +00006082The '``llvm.used``' Global Variable
6083-----------------------------------
6084
Rafael Espindola74f2e462013-04-22 14:58:02 +00006085The ``@llvm.used`` global is an array which has
Paul Redmond219ef812013-05-30 17:24:32 +00006086:ref:`appending linkage <linkage_appending>`. This array contains a list of
Rafael Espindola70a729d2013-06-11 13:18:13 +00006087pointers to named global variables, functions and aliases which may optionally
6088have a pointer cast formed of bitcast or getelementptr. For example, a legal
Sean Silvab084af42012-12-07 10:36:55 +00006089use of it is:
6090
6091.. code-block:: llvm
6092
6093 @X = global i8 4
6094 @Y = global i32 123
6095
6096 @llvm.used = appending global [2 x i8*] [
6097 i8* @X,
6098 i8* bitcast (i32* @Y to i8*)
6099 ], section "llvm.metadata"
6100
Rafael Espindola74f2e462013-04-22 14:58:02 +00006101If a symbol appears in the ``@llvm.used`` list, then the compiler, assembler,
6102and linker are required to treat the symbol as if there is a reference to the
Rafael Espindola70a729d2013-06-11 13:18:13 +00006103symbol that it cannot see (which is why they have to be named). For example, if
6104a variable has internal linkage and no references other than that from the
6105``@llvm.used`` list, it cannot be deleted. This is commonly used to represent
6106references from inline asms and other things the compiler cannot "see", and
6107corresponds to "``attribute((used))``" in GNU C.
Sean Silvab084af42012-12-07 10:36:55 +00006108
6109On some targets, the code generator must emit a directive to the
6110assembler or object file to prevent the assembler and linker from
6111molesting the symbol.
6112
Eli Bendersky0220e6b2013-06-07 20:24:43 +00006113.. _gv_llvmcompilerused:
6114
Sean Silvab084af42012-12-07 10:36:55 +00006115The '``llvm.compiler.used``' Global Variable
6116--------------------------------------------
6117
6118The ``@llvm.compiler.used`` directive is the same as the ``@llvm.used``
6119directive, except that it only prevents the compiler from touching the
6120symbol. On targets that support it, this allows an intelligent linker to
6121optimize references to the symbol without being impeded as it would be
6122by ``@llvm.used``.
6123
6124This is a rare construct that should only be used in rare circumstances,
6125and should not be exposed to source languages.
6126
Eli Bendersky0220e6b2013-06-07 20:24:43 +00006127.. _gv_llvmglobalctors:
6128
Sean Silvab084af42012-12-07 10:36:55 +00006129The '``llvm.global_ctors``' Global Variable
6130-------------------------------------------
6131
6132.. code-block:: llvm
6133
Reid Klecknerfceb76f2014-05-16 20:39:27 +00006134 %0 = type { i32, void ()*, i8* }
6135 @llvm.global_ctors = appending global [1 x %0] [%0 { i32 65535, void ()* @ctor, i8* @data }]
Sean Silvab084af42012-12-07 10:36:55 +00006136
6137The ``@llvm.global_ctors`` array contains a list of constructor
Reid Klecknerfceb76f2014-05-16 20:39:27 +00006138functions, priorities, and an optional associated global or function.
6139The functions referenced by this array will be called in ascending order
6140of priority (i.e. lowest first) when the module is loaded. The order of
6141functions with the same priority is not defined.
6142
6143If the third field is present, non-null, and points to a global variable
6144or function, the initializer function will only run if the associated
6145data from the current module is not discarded.
Sean Silvab084af42012-12-07 10:36:55 +00006146
Eli Bendersky0220e6b2013-06-07 20:24:43 +00006147.. _llvmglobaldtors:
6148
Sean Silvab084af42012-12-07 10:36:55 +00006149The '``llvm.global_dtors``' Global Variable
6150-------------------------------------------
6151
6152.. code-block:: llvm
6153
Reid Klecknerfceb76f2014-05-16 20:39:27 +00006154 %0 = type { i32, void ()*, i8* }
6155 @llvm.global_dtors = appending global [1 x %0] [%0 { i32 65535, void ()* @dtor, i8* @data }]
Sean Silvab084af42012-12-07 10:36:55 +00006156
Reid Klecknerfceb76f2014-05-16 20:39:27 +00006157The ``@llvm.global_dtors`` array contains a list of destructor
6158functions, priorities, and an optional associated global or function.
6159The functions referenced by this array will be called in descending
Reid Klecknerbffbcc52014-05-27 21:35:17 +00006160order of priority (i.e. highest first) when the module is unloaded. The
Reid Klecknerfceb76f2014-05-16 20:39:27 +00006161order of functions with the same priority is not defined.
6162
6163If the third field is present, non-null, and points to a global variable
6164or function, the destructor function will only run if the associated
6165data from the current module is not discarded.
Sean Silvab084af42012-12-07 10:36:55 +00006166
6167Instruction Reference
6168=====================
6169
6170The LLVM instruction set consists of several different classifications
6171of instructions: :ref:`terminator instructions <terminators>`, :ref:`binary
6172instructions <binaryops>`, :ref:`bitwise binary
6173instructions <bitwiseops>`, :ref:`memory instructions <memoryops>`, and
6174:ref:`other instructions <otherops>`.
6175
6176.. _terminators:
6177
6178Terminator Instructions
6179-----------------------
6180
6181As mentioned :ref:`previously <functionstructure>`, every basic block in a
6182program ends with a "Terminator" instruction, which indicates which
6183block should be executed after the current block is finished. These
6184terminator instructions typically yield a '``void``' value: they produce
6185control flow, not values (the one exception being the
6186':ref:`invoke <i_invoke>`' instruction).
6187
6188The terminator instructions are: ':ref:`ret <i_ret>`',
6189':ref:`br <i_br>`', ':ref:`switch <i_switch>`',
6190':ref:`indirectbr <i_indirectbr>`', ':ref:`invoke <i_invoke>`',
David Majnemer8a1c45d2015-12-12 05:38:55 +00006191':ref:`resume <i_resume>`', ':ref:`catchswitch <i_catchswitch>`',
David Majnemer654e1302015-07-31 17:58:14 +00006192':ref:`catchret <i_catchret>`',
6193':ref:`cleanupret <i_cleanupret>`',
David Majnemer654e1302015-07-31 17:58:14 +00006194and ':ref:`unreachable <i_unreachable>`'.
Sean Silvab084af42012-12-07 10:36:55 +00006195
6196.. _i_ret:
6197
6198'``ret``' Instruction
6199^^^^^^^^^^^^^^^^^^^^^
6200
6201Syntax:
6202"""""""
6203
6204::
6205
6206 ret <type> <value> ; Return a value from a non-void function
6207 ret void ; Return from void function
6208
6209Overview:
6210"""""""""
6211
6212The '``ret``' instruction is used to return control flow (and optionally
6213a value) from a function back to the caller.
6214
6215There are two forms of the '``ret``' instruction: one that returns a
6216value and then causes control flow, and one that just causes control
6217flow to occur.
6218
6219Arguments:
6220""""""""""
6221
6222The '``ret``' instruction optionally accepts a single argument, the
6223return value. The type of the return value must be a ':ref:`first
6224class <t_firstclass>`' type.
6225
6226A function is not :ref:`well formed <wellformed>` if it it has a non-void
6227return type and contains a '``ret``' instruction with no return value or
6228a return value with a type that does not match its type, or if it has a
6229void return type and contains a '``ret``' instruction with a return
6230value.
6231
6232Semantics:
6233""""""""""
6234
6235When the '``ret``' instruction is executed, control flow returns back to
6236the calling function's context. If the caller is a
6237":ref:`call <i_call>`" instruction, execution continues at the
6238instruction after the call. If the caller was an
6239":ref:`invoke <i_invoke>`" instruction, execution continues at the
6240beginning of the "normal" destination block. If the instruction returns
6241a value, that value shall set the call or invoke instruction's return
6242value.
6243
6244Example:
6245""""""""
6246
6247.. code-block:: llvm
6248
6249 ret i32 5 ; Return an integer value of 5
6250 ret void ; Return from a void function
6251 ret { i32, i8 } { i32 4, i8 2 } ; Return a struct of values 4 and 2
6252
6253.. _i_br:
6254
6255'``br``' Instruction
6256^^^^^^^^^^^^^^^^^^^^
6257
6258Syntax:
6259"""""""
6260
6261::
6262
6263 br i1 <cond>, label <iftrue>, label <iffalse>
6264 br label <dest> ; Unconditional branch
6265
6266Overview:
6267"""""""""
6268
6269The '``br``' instruction is used to cause control flow to transfer to a
6270different basic block in the current function. There are two forms of
6271this instruction, corresponding to a conditional branch and an
6272unconditional branch.
6273
6274Arguments:
6275""""""""""
6276
6277The conditional branch form of the '``br``' instruction takes a single
6278'``i1``' value and two '``label``' values. The unconditional form of the
6279'``br``' instruction takes a single '``label``' value as a target.
6280
6281Semantics:
6282""""""""""
6283
6284Upon execution of a conditional '``br``' instruction, the '``i1``'
6285argument is evaluated. If the value is ``true``, control flows to the
6286'``iftrue``' ``label`` argument. If "cond" is ``false``, control flows
6287to the '``iffalse``' ``label`` argument.
6288
6289Example:
6290""""""""
6291
6292.. code-block:: llvm
6293
6294 Test:
6295 %cond = icmp eq i32 %a, %b
6296 br i1 %cond, label %IfEqual, label %IfUnequal
6297 IfEqual:
6298 ret i32 1
6299 IfUnequal:
6300 ret i32 0
6301
6302.. _i_switch:
6303
6304'``switch``' Instruction
6305^^^^^^^^^^^^^^^^^^^^^^^^
6306
6307Syntax:
6308"""""""
6309
6310::
6311
6312 switch <intty> <value>, label <defaultdest> [ <intty> <val>, label <dest> ... ]
6313
6314Overview:
6315"""""""""
6316
6317The '``switch``' instruction is used to transfer control flow to one of
6318several different places. It is a generalization of the '``br``'
6319instruction, allowing a branch to occur to one of many possible
6320destinations.
6321
6322Arguments:
6323""""""""""
6324
6325The '``switch``' instruction uses three parameters: an integer
6326comparison value '``value``', a default '``label``' destination, and an
6327array of pairs of comparison value constants and '``label``'s. The table
6328is not allowed to contain duplicate constant entries.
6329
6330Semantics:
6331""""""""""
6332
6333The ``switch`` instruction specifies a table of values and destinations.
6334When the '``switch``' instruction is executed, this table is searched
6335for the given value. If the value is found, control flow is transferred
6336to the corresponding destination; otherwise, control flow is transferred
6337to the default destination.
6338
6339Implementation:
6340"""""""""""""""
6341
6342Depending on properties of the target machine and the particular
6343``switch`` instruction, this instruction may be code generated in
6344different ways. For example, it could be generated as a series of
6345chained conditional branches or with a lookup table.
6346
6347Example:
6348""""""""
6349
6350.. code-block:: llvm
6351
6352 ; Emulate a conditional br instruction
6353 %Val = zext i1 %value to i32
6354 switch i32 %Val, label %truedest [ i32 0, label %falsedest ]
6355
6356 ; Emulate an unconditional br instruction
6357 switch i32 0, label %dest [ ]
6358
6359 ; Implement a jump table:
6360 switch i32 %val, label %otherwise [ i32 0, label %onzero
6361 i32 1, label %onone
6362 i32 2, label %ontwo ]
6363
6364.. _i_indirectbr:
6365
6366'``indirectbr``' Instruction
6367^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6368
6369Syntax:
6370"""""""
6371
6372::
6373
6374 indirectbr <somety>* <address>, [ label <dest1>, label <dest2>, ... ]
6375
6376Overview:
6377"""""""""
6378
6379The '``indirectbr``' instruction implements an indirect branch to a
6380label within the current function, whose address is specified by
6381"``address``". Address must be derived from a
6382:ref:`blockaddress <blockaddress>` constant.
6383
6384Arguments:
6385""""""""""
6386
6387The '``address``' argument is the address of the label to jump to. The
6388rest of the arguments indicate the full set of possible destinations
6389that the address may point to. Blocks are allowed to occur multiple
6390times in the destination list, though this isn't particularly useful.
6391
6392This destination list is required so that dataflow analysis has an
6393accurate understanding of the CFG.
6394
6395Semantics:
6396""""""""""
6397
6398Control transfers to the block specified in the address argument. All
6399possible destination blocks must be listed in the label list, otherwise
6400this instruction has undefined behavior. This implies that jumps to
6401labels defined in other functions have undefined behavior as well.
6402
6403Implementation:
6404"""""""""""""""
6405
6406This is typically implemented with a jump through a register.
6407
6408Example:
6409""""""""
6410
6411.. code-block:: llvm
6412
6413 indirectbr i8* %Addr, [ label %bb1, label %bb2, label %bb3 ]
6414
6415.. _i_invoke:
6416
6417'``invoke``' Instruction
6418^^^^^^^^^^^^^^^^^^^^^^^^
6419
6420Syntax:
6421"""""""
6422
6423::
6424
David Blaikieb83cf102016-07-13 17:21:34 +00006425 <result> = invoke [cconv] [ret attrs] <ty>|<fnty> <fnptrval>(<function args>) [fn attrs]
Sanjoy Dasb513a9f2015-09-24 23:34:52 +00006426 [operand bundles] to label <normal label> unwind label <exception label>
Sean Silvab084af42012-12-07 10:36:55 +00006427
6428Overview:
6429"""""""""
6430
6431The '``invoke``' instruction causes control to transfer to a specified
6432function, with the possibility of control flow transfer to either the
6433'``normal``' label or the '``exception``' label. If the callee function
6434returns with the "``ret``" instruction, control flow will return to the
6435"normal" label. If the callee (or any indirect callees) returns via the
6436":ref:`resume <i_resume>`" instruction or other exception handling
6437mechanism, control is interrupted and continued at the dynamically
6438nearest "exception" label.
6439
6440The '``exception``' label is a `landing
6441pad <ExceptionHandling.html#overview>`_ for the exception. As such,
6442'``exception``' label is required to have the
6443":ref:`landingpad <i_landingpad>`" instruction, which contains the
6444information about the behavior of the program after unwinding happens,
6445as its first non-PHI instruction. The restrictions on the
6446"``landingpad``" instruction's tightly couples it to the "``invoke``"
6447instruction, so that the important information contained within the
6448"``landingpad``" instruction can't be lost through normal code motion.
6449
6450Arguments:
6451""""""""""
6452
6453This instruction requires several arguments:
6454
6455#. The optional "cconv" marker indicates which :ref:`calling
6456 convention <callingconv>` the call should use. If none is
6457 specified, the call defaults to using C calling conventions.
6458#. The optional :ref:`Parameter Attributes <paramattrs>` list for return
6459 values. Only '``zeroext``', '``signext``', and '``inreg``' attributes
6460 are valid here.
David Blaikieb83cf102016-07-13 17:21:34 +00006461#. '``ty``': the type of the call instruction itself which is also the
6462 type of the return value. Functions that return no value are marked
6463 ``void``.
6464#. '``fnty``': shall be the signature of the function being invoked. The
6465 argument types must match the types implied by this signature. This
6466 type can be omitted if the function is not varargs.
6467#. '``fnptrval``': An LLVM value containing a pointer to a function to
6468 be invoked. In most cases, this is a direct function invocation, but
6469 indirect ``invoke``'s are just as possible, calling an arbitrary pointer
6470 to function value.
Sean Silvab084af42012-12-07 10:36:55 +00006471#. '``function args``': argument list whose types match the function
6472 signature argument types and parameter attributes. All arguments must
6473 be of :ref:`first class <t_firstclass>` type. If the function signature
6474 indicates the function accepts a variable number of arguments, the
6475 extra arguments can be specified.
6476#. '``normal label``': the label reached when the called function
6477 executes a '``ret``' instruction.
6478#. '``exception label``': the label reached when a callee returns via
6479 the :ref:`resume <i_resume>` instruction or other exception handling
6480 mechanism.
George Burgess IV8a464a72017-04-13 05:00:31 +00006481#. The optional :ref:`function attributes <fnattrs>` list.
Sanjoy Dasb513a9f2015-09-24 23:34:52 +00006482#. The optional :ref:`operand bundles <opbundles>` list.
Sean Silvab084af42012-12-07 10:36:55 +00006483
6484Semantics:
6485""""""""""
6486
6487This instruction is designed to operate as a standard '``call``'
6488instruction in most regards. The primary difference is that it
6489establishes an association with a label, which is used by the runtime
6490library to unwind the stack.
6491
6492This instruction is used in languages with destructors to ensure that
6493proper cleanup is performed in the case of either a ``longjmp`` or a
6494thrown exception. Additionally, this is important for implementation of
6495'``catch``' clauses in high-level languages that support them.
6496
6497For the purposes of the SSA form, the definition of the value returned
6498by the '``invoke``' instruction is deemed to occur on the edge from the
6499current block to the "normal" label. If the callee unwinds then no
6500return value is available.
6501
6502Example:
6503""""""""
6504
6505.. code-block:: llvm
6506
6507 %retval = invoke i32 @Test(i32 15) to label %Continue
Tim Northover675a0962014-06-13 14:24:23 +00006508 unwind label %TestCleanup ; i32:retval set
Sean Silvab084af42012-12-07 10:36:55 +00006509 %retval = invoke coldcc i32 %Testfnptr(i32 15) to label %Continue
Tim Northover675a0962014-06-13 14:24:23 +00006510 unwind label %TestCleanup ; i32:retval set
Sean Silvab084af42012-12-07 10:36:55 +00006511
6512.. _i_resume:
6513
6514'``resume``' Instruction
6515^^^^^^^^^^^^^^^^^^^^^^^^
6516
6517Syntax:
6518"""""""
6519
6520::
6521
6522 resume <type> <value>
6523
6524Overview:
6525"""""""""
6526
6527The '``resume``' instruction is a terminator instruction that has no
6528successors.
6529
6530Arguments:
6531""""""""""
6532
6533The '``resume``' instruction requires one argument, which must have the
6534same type as the result of any '``landingpad``' instruction in the same
6535function.
6536
6537Semantics:
6538""""""""""
6539
6540The '``resume``' instruction resumes propagation of an existing
6541(in-flight) exception whose unwinding was interrupted with a
6542:ref:`landingpad <i_landingpad>` instruction.
6543
6544Example:
6545""""""""
6546
6547.. code-block:: llvm
6548
6549 resume { i8*, i32 } %exn
6550
David Majnemer8a1c45d2015-12-12 05:38:55 +00006551.. _i_catchswitch:
6552
6553'``catchswitch``' Instruction
Akira Hatanakacedf8e92015-12-14 05:15:40 +00006554^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
David Majnemer8a1c45d2015-12-12 05:38:55 +00006555
6556Syntax:
6557"""""""
6558
6559::
6560
6561 <resultval> = catchswitch within <parent> [ label <handler1>, label <handler2>, ... ] unwind to caller
6562 <resultval> = catchswitch within <parent> [ label <handler1>, label <handler2>, ... ] unwind label <default>
6563
6564Overview:
6565"""""""""
6566
6567The '``catchswitch``' instruction is used by `LLVM's exception handling system
6568<ExceptionHandling.html#overview>`_ to describe the set of possible catch handlers
6569that may be executed by the :ref:`EH personality routine <personalityfn>`.
6570
6571Arguments:
6572""""""""""
6573
6574The ``parent`` argument is the token of the funclet that contains the
6575``catchswitch`` instruction. If the ``catchswitch`` is not inside a funclet,
6576this operand may be the token ``none``.
6577
Joseph Tremoulete28885e2016-01-10 04:28:38 +00006578The ``default`` argument is the label of another basic block beginning with
6579either a ``cleanuppad`` or ``catchswitch`` instruction. This unwind destination
6580must be a legal target with respect to the ``parent`` links, as described in
6581the `exception handling documentation\ <ExceptionHandling.html#wineh-constraints>`_.
David Majnemer8a1c45d2015-12-12 05:38:55 +00006582
Joseph Tremoulete28885e2016-01-10 04:28:38 +00006583The ``handlers`` are a nonempty list of successor blocks that each begin with a
David Majnemer8a1c45d2015-12-12 05:38:55 +00006584:ref:`catchpad <i_catchpad>` instruction.
6585
6586Semantics:
6587""""""""""
6588
6589Executing this instruction transfers control to one of the successors in
6590``handlers``, if appropriate, or continues to unwind via the unwind label if
6591present.
6592
6593The ``catchswitch`` is both a terminator and a "pad" instruction, meaning that
6594it must be both the first non-phi instruction and last instruction in the basic
6595block. Therefore, it must be the only non-phi instruction in the block.
6596
6597Example:
6598""""""""
6599
Renato Golin124f2592016-07-20 12:16:38 +00006600.. code-block:: text
David Majnemer8a1c45d2015-12-12 05:38:55 +00006601
6602 dispatch1:
6603 %cs1 = catchswitch within none [label %handler0, label %handler1] unwind to caller
6604 dispatch2:
6605 %cs2 = catchswitch within %parenthandler [label %handler0] unwind label %cleanup
6606
David Majnemer654e1302015-07-31 17:58:14 +00006607.. _i_catchret:
6608
6609'``catchret``' Instruction
6610^^^^^^^^^^^^^^^^^^^^^^^^^^
6611
6612Syntax:
6613"""""""
6614
6615::
6616
David Majnemer8a1c45d2015-12-12 05:38:55 +00006617 catchret from <token> to label <normal>
David Majnemer654e1302015-07-31 17:58:14 +00006618
6619Overview:
6620"""""""""
6621
6622The '``catchret``' instruction is a terminator instruction that has a
6623single successor.
6624
6625
6626Arguments:
6627""""""""""
6628
Joseph Tremoulet8220bcc2015-08-23 00:26:33 +00006629The first argument to a '``catchret``' indicates which ``catchpad`` it
6630exits. It must be a :ref:`catchpad <i_catchpad>`.
6631The second argument to a '``catchret``' specifies where control will
6632transfer to next.
David Majnemer654e1302015-07-31 17:58:14 +00006633
6634Semantics:
6635""""""""""
6636
David Majnemer8a1c45d2015-12-12 05:38:55 +00006637The '``catchret``' instruction ends an existing (in-flight) exception whose
6638unwinding was interrupted with a :ref:`catchpad <i_catchpad>` instruction. The
6639:ref:`personality function <personalityfn>` gets a chance to execute arbitrary
6640code to, for example, destroy the active exception. Control then transfers to
6641``normal``.
Joseph Tremoulet9ce71f72015-09-03 09:09:43 +00006642
Joseph Tremoulete28885e2016-01-10 04:28:38 +00006643The ``token`` argument must be a token produced by a ``catchpad`` instruction.
6644If the specified ``catchpad`` is not the most-recently-entered not-yet-exited
6645funclet pad (as described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_),
6646the ``catchret``'s behavior is undefined.
David Majnemer654e1302015-07-31 17:58:14 +00006647
6648Example:
6649""""""""
6650
Renato Golin124f2592016-07-20 12:16:38 +00006651.. code-block:: text
David Majnemer654e1302015-07-31 17:58:14 +00006652
David Majnemer8a1c45d2015-12-12 05:38:55 +00006653 catchret from %catch label %continue
Joseph Tremoulet9ce71f72015-09-03 09:09:43 +00006654
David Majnemer654e1302015-07-31 17:58:14 +00006655.. _i_cleanupret:
6656
6657'``cleanupret``' Instruction
6658^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6659
6660Syntax:
6661"""""""
6662
6663::
6664
David Majnemer8a1c45d2015-12-12 05:38:55 +00006665 cleanupret from <value> unwind label <continue>
6666 cleanupret from <value> unwind to caller
David Majnemer654e1302015-07-31 17:58:14 +00006667
6668Overview:
6669"""""""""
6670
6671The '``cleanupret``' instruction is a terminator instruction that has
6672an optional successor.
6673
6674
6675Arguments:
6676""""""""""
6677
Joseph Tremoulet8220bcc2015-08-23 00:26:33 +00006678The '``cleanupret``' instruction requires one argument, which indicates
6679which ``cleanuppad`` it exits, and must be a :ref:`cleanuppad <i_cleanuppad>`.
Joseph Tremoulete28885e2016-01-10 04:28:38 +00006680If the specified ``cleanuppad`` is not the most-recently-entered not-yet-exited
6681funclet pad (as described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_),
6682the ``cleanupret``'s behavior is undefined.
6683
6684The '``cleanupret``' instruction also has an optional successor, ``continue``,
6685which must be the label of another basic block beginning with either a
6686``cleanuppad`` or ``catchswitch`` instruction. This unwind destination must
6687be a legal target with respect to the ``parent`` links, as described in the
6688`exception handling documentation\ <ExceptionHandling.html#wineh-constraints>`_.
David Majnemer654e1302015-07-31 17:58:14 +00006689
6690Semantics:
6691""""""""""
6692
6693The '``cleanupret``' instruction indicates to the
6694:ref:`personality function <personalityfn>` that one
6695:ref:`cleanuppad <i_cleanuppad>` it transferred control to has ended.
6696It transfers control to ``continue`` or unwinds out of the function.
Joseph Tremoulet9ce71f72015-09-03 09:09:43 +00006697
David Majnemer654e1302015-07-31 17:58:14 +00006698Example:
6699""""""""
6700
Renato Golin124f2592016-07-20 12:16:38 +00006701.. code-block:: text
David Majnemer654e1302015-07-31 17:58:14 +00006702
David Majnemer8a1c45d2015-12-12 05:38:55 +00006703 cleanupret from %cleanup unwind to caller
6704 cleanupret from %cleanup unwind label %continue
David Majnemer654e1302015-07-31 17:58:14 +00006705
Sean Silvab084af42012-12-07 10:36:55 +00006706.. _i_unreachable:
6707
6708'``unreachable``' Instruction
6709^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6710
6711Syntax:
6712"""""""
6713
6714::
6715
6716 unreachable
6717
6718Overview:
6719"""""""""
6720
6721The '``unreachable``' instruction has no defined semantics. This
6722instruction is used to inform the optimizer that a particular portion of
6723the code is not reachable. This can be used to indicate that the code
6724after a no-return function cannot be reached, and other facts.
6725
6726Semantics:
6727""""""""""
6728
6729The '``unreachable``' instruction has no defined semantics.
6730
6731.. _binaryops:
6732
6733Binary Operations
6734-----------------
6735
6736Binary operators are used to do most of the computation in a program.
6737They require two operands of the same type, execute an operation on
6738them, and produce a single value. The operands might represent multiple
6739data, as is the case with the :ref:`vector <t_vector>` data type. The
6740result value has the same type as its operands.
6741
6742There are several different binary operators:
6743
6744.. _i_add:
6745
6746'``add``' Instruction
6747^^^^^^^^^^^^^^^^^^^^^
6748
6749Syntax:
6750"""""""
6751
6752::
6753
Tim Northover675a0962014-06-13 14:24:23 +00006754 <result> = add <ty> <op1>, <op2> ; yields ty:result
6755 <result> = add nuw <ty> <op1>, <op2> ; yields ty:result
6756 <result> = add nsw <ty> <op1>, <op2> ; yields ty:result
6757 <result> = add nuw nsw <ty> <op1>, <op2> ; yields ty:result
Sean Silvab084af42012-12-07 10:36:55 +00006758
6759Overview:
6760"""""""""
6761
6762The '``add``' instruction returns the sum of its two operands.
6763
6764Arguments:
6765""""""""""
6766
6767The two arguments to the '``add``' instruction must be
6768:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
6769arguments must have identical types.
6770
6771Semantics:
6772""""""""""
6773
6774The value produced is the integer sum of the two operands.
6775
6776If the sum has unsigned overflow, the result returned is the
6777mathematical result modulo 2\ :sup:`n`\ , where n is the bit width of
6778the result.
6779
6780Because LLVM integers use a two's complement representation, this
6781instruction is appropriate for both signed and unsigned integers.
6782
6783``nuw`` and ``nsw`` stand for "No Unsigned Wrap" and "No Signed Wrap",
6784respectively. If the ``nuw`` and/or ``nsw`` keywords are present, the
6785result value of the ``add`` is a :ref:`poison value <poisonvalues>` if
6786unsigned and/or signed overflow, respectively, occurs.
6787
6788Example:
6789""""""""
6790
Renato Golin124f2592016-07-20 12:16:38 +00006791.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00006792
Tim Northover675a0962014-06-13 14:24:23 +00006793 <result> = add i32 4, %var ; yields i32:result = 4 + %var
Sean Silvab084af42012-12-07 10:36:55 +00006794
6795.. _i_fadd:
6796
6797'``fadd``' Instruction
6798^^^^^^^^^^^^^^^^^^^^^^
6799
6800Syntax:
6801"""""""
6802
6803::
6804
Tim Northover675a0962014-06-13 14:24:23 +00006805 <result> = fadd [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result
Sean Silvab084af42012-12-07 10:36:55 +00006806
6807Overview:
6808"""""""""
6809
6810The '``fadd``' instruction returns the sum of its two operands.
6811
6812Arguments:
6813""""""""""
6814
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00006815The two arguments to the '``fadd``' instruction must be
6816:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of
6817floating-point values. Both arguments must have identical types.
Sean Silvab084af42012-12-07 10:36:55 +00006818
6819Semantics:
6820""""""""""
6821
Sanjay Patel7b722402018-03-07 17:18:22 +00006822The value produced is the floating-point sum of the two operands.
Sanjay Patelec95e0e2018-03-20 17:05:19 +00006823This instruction is assumed to execute in the default :ref:`floating-point
6824environment <floatenv>`.
Sanjay Patel7b722402018-03-07 17:18:22 +00006825This instruction can also take any number of :ref:`fast-math
6826flags <fastmath>`, which are optimization hints to enable otherwise
6827unsafe floating-point optimizations:
Sean Silvab084af42012-12-07 10:36:55 +00006828
6829Example:
6830""""""""
6831
Renato Golin124f2592016-07-20 12:16:38 +00006832.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00006833
Tim Northover675a0962014-06-13 14:24:23 +00006834 <result> = fadd float 4.0, %var ; yields float:result = 4.0 + %var
Sean Silvab084af42012-12-07 10:36:55 +00006835
6836'``sub``' Instruction
6837^^^^^^^^^^^^^^^^^^^^^
6838
6839Syntax:
6840"""""""
6841
6842::
6843
Tim Northover675a0962014-06-13 14:24:23 +00006844 <result> = sub <ty> <op1>, <op2> ; yields ty:result
6845 <result> = sub nuw <ty> <op1>, <op2> ; yields ty:result
6846 <result> = sub nsw <ty> <op1>, <op2> ; yields ty:result
6847 <result> = sub nuw nsw <ty> <op1>, <op2> ; yields ty:result
Sean Silvab084af42012-12-07 10:36:55 +00006848
6849Overview:
6850"""""""""
6851
6852The '``sub``' instruction returns the difference of its two operands.
6853
6854Note that the '``sub``' instruction is used to represent the '``neg``'
6855instruction present in most other intermediate representations.
6856
6857Arguments:
6858""""""""""
6859
6860The two arguments to the '``sub``' instruction must be
6861:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
6862arguments must have identical types.
6863
6864Semantics:
6865""""""""""
6866
6867The value produced is the integer difference of the two operands.
6868
6869If the difference has unsigned overflow, the result returned is the
6870mathematical result modulo 2\ :sup:`n`\ , where n is the bit width of
6871the result.
6872
6873Because LLVM integers use a two's complement representation, this
6874instruction is appropriate for both signed and unsigned integers.
6875
6876``nuw`` and ``nsw`` stand for "No Unsigned Wrap" and "No Signed Wrap",
6877respectively. If the ``nuw`` and/or ``nsw`` keywords are present, the
6878result value of the ``sub`` is a :ref:`poison value <poisonvalues>` if
6879unsigned and/or signed overflow, respectively, occurs.
6880
6881Example:
6882""""""""
6883
Renato Golin124f2592016-07-20 12:16:38 +00006884.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00006885
Tim Northover675a0962014-06-13 14:24:23 +00006886 <result> = sub i32 4, %var ; yields i32:result = 4 - %var
6887 <result> = sub i32 0, %val ; yields i32:result = -%var
Sean Silvab084af42012-12-07 10:36:55 +00006888
6889.. _i_fsub:
6890
6891'``fsub``' Instruction
6892^^^^^^^^^^^^^^^^^^^^^^
6893
6894Syntax:
6895"""""""
6896
6897::
6898
Tim Northover675a0962014-06-13 14:24:23 +00006899 <result> = fsub [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result
Sean Silvab084af42012-12-07 10:36:55 +00006900
6901Overview:
6902"""""""""
6903
6904The '``fsub``' instruction returns the difference of its two operands.
6905
6906Note that the '``fsub``' instruction is used to represent the '``fneg``'
6907instruction present in most other intermediate representations.
6908
6909Arguments:
6910""""""""""
6911
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00006912The two arguments to the '``fsub``' instruction must be
6913:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of
6914floating-point values. Both arguments must have identical types.
Sean Silvab084af42012-12-07 10:36:55 +00006915
6916Semantics:
6917""""""""""
6918
Sanjay Patel7b722402018-03-07 17:18:22 +00006919The value produced is the floating-point difference of the two operands.
Sanjay Patelec95e0e2018-03-20 17:05:19 +00006920This instruction is assumed to execute in the default :ref:`floating-point
6921environment <floatenv>`.
Sean Silvab084af42012-12-07 10:36:55 +00006922This instruction can also take any number of :ref:`fast-math
6923flags <fastmath>`, which are optimization hints to enable otherwise
Sanjay Patel7b722402018-03-07 17:18:22 +00006924unsafe floating-point optimizations:
Sean Silvab084af42012-12-07 10:36:55 +00006925
6926Example:
6927""""""""
6928
Renato Golin124f2592016-07-20 12:16:38 +00006929.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00006930
Tim Northover675a0962014-06-13 14:24:23 +00006931 <result> = fsub float 4.0, %var ; yields float:result = 4.0 - %var
6932 <result> = fsub float -0.0, %val ; yields float:result = -%var
Sean Silvab084af42012-12-07 10:36:55 +00006933
6934'``mul``' Instruction
6935^^^^^^^^^^^^^^^^^^^^^
6936
6937Syntax:
6938"""""""
6939
6940::
6941
Tim Northover675a0962014-06-13 14:24:23 +00006942 <result> = mul <ty> <op1>, <op2> ; yields ty:result
6943 <result> = mul nuw <ty> <op1>, <op2> ; yields ty:result
6944 <result> = mul nsw <ty> <op1>, <op2> ; yields ty:result
6945 <result> = mul nuw nsw <ty> <op1>, <op2> ; yields ty:result
Sean Silvab084af42012-12-07 10:36:55 +00006946
6947Overview:
6948"""""""""
6949
6950The '``mul``' instruction returns the product of its two operands.
6951
6952Arguments:
6953""""""""""
6954
6955The two arguments to the '``mul``' instruction must be
6956:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
6957arguments must have identical types.
6958
6959Semantics:
6960""""""""""
6961
6962The value produced is the integer product of the two operands.
6963
6964If the result of the multiplication has unsigned overflow, the result
6965returned is the mathematical result modulo 2\ :sup:`n`\ , where n is the
6966bit width of the result.
6967
6968Because LLVM integers use a two's complement representation, and the
6969result is the same width as the operands, this instruction returns the
6970correct result for both signed and unsigned integers. If a full product
6971(e.g. ``i32`` * ``i32`` -> ``i64``) is needed, the operands should be
6972sign-extended or zero-extended as appropriate to the width of the full
6973product.
6974
6975``nuw`` and ``nsw`` stand for "No Unsigned Wrap" and "No Signed Wrap",
6976respectively. If the ``nuw`` and/or ``nsw`` keywords are present, the
6977result value of the ``mul`` is a :ref:`poison value <poisonvalues>` if
6978unsigned and/or signed overflow, respectively, occurs.
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> = mul i32 4, %var ; yields i32:result = 4 * %var
Sean Silvab084af42012-12-07 10:36:55 +00006986
6987.. _i_fmul:
6988
6989'``fmul``' Instruction
6990^^^^^^^^^^^^^^^^^^^^^^
6991
6992Syntax:
6993"""""""
6994
6995::
6996
Tim Northover675a0962014-06-13 14:24:23 +00006997 <result> = fmul [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result
Sean Silvab084af42012-12-07 10:36:55 +00006998
6999Overview:
7000"""""""""
7001
7002The '``fmul``' instruction returns the product of its two operands.
7003
7004Arguments:
7005""""""""""
7006
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00007007The two arguments to the '``fmul``' instruction must be
7008:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of
7009floating-point values. Both arguments must have identical types.
Sean Silvab084af42012-12-07 10:36:55 +00007010
7011Semantics:
7012""""""""""
7013
Sanjay Patel7b722402018-03-07 17:18:22 +00007014The value produced is the floating-point product of the two operands.
Sanjay Patelec95e0e2018-03-20 17:05:19 +00007015This instruction is assumed to execute in the default :ref:`floating-point
7016environment <floatenv>`.
Sean Silvab084af42012-12-07 10:36:55 +00007017This instruction can also take any number of :ref:`fast-math
7018flags <fastmath>`, which are optimization hints to enable otherwise
Sanjay Patel7b722402018-03-07 17:18:22 +00007019unsafe floating-point optimizations:
Sean Silvab084af42012-12-07 10:36:55 +00007020
7021Example:
7022""""""""
7023
Renato Golin124f2592016-07-20 12:16:38 +00007024.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00007025
Tim Northover675a0962014-06-13 14:24:23 +00007026 <result> = fmul float 4.0, %var ; yields float:result = 4.0 * %var
Sean Silvab084af42012-12-07 10:36:55 +00007027
7028'``udiv``' Instruction
7029^^^^^^^^^^^^^^^^^^^^^^
7030
7031Syntax:
7032"""""""
7033
7034::
7035
Tim Northover675a0962014-06-13 14:24:23 +00007036 <result> = udiv <ty> <op1>, <op2> ; yields ty:result
7037 <result> = udiv exact <ty> <op1>, <op2> ; yields ty:result
Sean Silvab084af42012-12-07 10:36:55 +00007038
7039Overview:
7040"""""""""
7041
7042The '``udiv``' instruction returns the quotient of its two operands.
7043
7044Arguments:
7045""""""""""
7046
7047The two arguments to the '``udiv``' instruction must be
7048:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
7049arguments must have identical types.
7050
7051Semantics:
7052""""""""""
7053
7054The value produced is the unsigned integer quotient of the two operands.
7055
7056Note that unsigned integer division and signed integer division are
7057distinct operations; for signed integer division, use '``sdiv``'.
7058
Sanjay Patel2b1f6f42017-03-09 16:20:52 +00007059Division by zero is undefined behavior. For vectors, if any element
7060of the divisor is zero, the operation has undefined behavior.
7061
Sean Silvab084af42012-12-07 10:36:55 +00007062
7063If the ``exact`` keyword is present, the result value of the ``udiv`` is
7064a :ref:`poison value <poisonvalues>` if %op1 is not a multiple of %op2 (as
7065such, "((a udiv exact b) mul b) == a").
7066
7067Example:
7068""""""""
7069
Renato Golin124f2592016-07-20 12:16:38 +00007070.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00007071
Tim Northover675a0962014-06-13 14:24:23 +00007072 <result> = udiv i32 4, %var ; yields i32:result = 4 / %var
Sean Silvab084af42012-12-07 10:36:55 +00007073
7074'``sdiv``' Instruction
7075^^^^^^^^^^^^^^^^^^^^^^
7076
7077Syntax:
7078"""""""
7079
7080::
7081
Tim Northover675a0962014-06-13 14:24:23 +00007082 <result> = sdiv <ty> <op1>, <op2> ; yields ty:result
7083 <result> = sdiv exact <ty> <op1>, <op2> ; yields ty:result
Sean Silvab084af42012-12-07 10:36:55 +00007084
7085Overview:
7086"""""""""
7087
7088The '``sdiv``' instruction returns the quotient of its two operands.
7089
7090Arguments:
7091""""""""""
7092
7093The two arguments to the '``sdiv``' instruction must be
7094:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
7095arguments must have identical types.
7096
7097Semantics:
7098""""""""""
7099
7100The value produced is the signed integer quotient of the two operands
7101rounded towards zero.
7102
7103Note that signed integer division and unsigned integer division are
7104distinct operations; for unsigned integer division, use '``udiv``'.
7105
Sanjay Patel2b1f6f42017-03-09 16:20:52 +00007106Division by zero is undefined behavior. For vectors, if any element
7107of the divisor is zero, the operation has undefined behavior.
7108Overflow also leads to undefined behavior; this is a rare case, but can
7109occur, for example, by doing a 32-bit division of -2147483648 by -1.
Sean Silvab084af42012-12-07 10:36:55 +00007110
7111If the ``exact`` keyword is present, the result value of the ``sdiv`` is
7112a :ref:`poison value <poisonvalues>` if the result would be rounded.
7113
7114Example:
7115""""""""
7116
Renato Golin124f2592016-07-20 12:16:38 +00007117.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00007118
Tim Northover675a0962014-06-13 14:24:23 +00007119 <result> = sdiv i32 4, %var ; yields i32:result = 4 / %var
Sean Silvab084af42012-12-07 10:36:55 +00007120
7121.. _i_fdiv:
7122
7123'``fdiv``' Instruction
7124^^^^^^^^^^^^^^^^^^^^^^
7125
7126Syntax:
7127"""""""
7128
7129::
7130
Tim Northover675a0962014-06-13 14:24:23 +00007131 <result> = fdiv [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result
Sean Silvab084af42012-12-07 10:36:55 +00007132
7133Overview:
7134"""""""""
7135
7136The '``fdiv``' instruction returns the quotient of its two operands.
7137
7138Arguments:
7139""""""""""
7140
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00007141The two arguments to the '``fdiv``' instruction must be
7142:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of
7143floating-point values. Both arguments must have identical types.
Sean Silvab084af42012-12-07 10:36:55 +00007144
7145Semantics:
7146""""""""""
7147
Sanjay Patel7b722402018-03-07 17:18:22 +00007148The value produced is the floating-point quotient of the two operands.
Sanjay Patelec95e0e2018-03-20 17:05:19 +00007149This instruction is assumed to execute in the default :ref:`floating-point
7150environment <floatenv>`.
Sean Silvab084af42012-12-07 10:36:55 +00007151This instruction can also take any number of :ref:`fast-math
7152flags <fastmath>`, which are optimization hints to enable otherwise
Sanjay Patel7b722402018-03-07 17:18:22 +00007153unsafe floating-point optimizations:
Sean Silvab084af42012-12-07 10:36:55 +00007154
7155Example:
7156""""""""
7157
Renato Golin124f2592016-07-20 12:16:38 +00007158.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00007159
Tim Northover675a0962014-06-13 14:24:23 +00007160 <result> = fdiv float 4.0, %var ; yields float:result = 4.0 / %var
Sean Silvab084af42012-12-07 10:36:55 +00007161
7162'``urem``' Instruction
7163^^^^^^^^^^^^^^^^^^^^^^
7164
7165Syntax:
7166"""""""
7167
7168::
7169
Tim Northover675a0962014-06-13 14:24:23 +00007170 <result> = urem <ty> <op1>, <op2> ; yields ty:result
Sean Silvab084af42012-12-07 10:36:55 +00007171
7172Overview:
7173"""""""""
7174
7175The '``urem``' instruction returns the remainder from the unsigned
7176division of its two arguments.
7177
7178Arguments:
7179""""""""""
7180
7181The two arguments to the '``urem``' instruction must be
7182:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
7183arguments must have identical types.
7184
7185Semantics:
7186""""""""""
7187
7188This instruction returns the unsigned integer *remainder* of a division.
7189This instruction always performs an unsigned division to get the
7190remainder.
7191
7192Note that unsigned integer remainder and signed integer remainder are
7193distinct operations; for signed integer remainder, use '``srem``'.
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +00007194
Sanjay Patel2b1f6f42017-03-09 16:20:52 +00007195Taking the remainder of a division by zero is undefined behavior.
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +00007196For vectors, if any element of the divisor is zero, the operation has
Sanjay Patel2b1f6f42017-03-09 16:20:52 +00007197undefined behavior.
Sean Silvab084af42012-12-07 10:36:55 +00007198
7199Example:
7200""""""""
7201
Renato Golin124f2592016-07-20 12:16:38 +00007202.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00007203
Tim Northover675a0962014-06-13 14:24:23 +00007204 <result> = urem i32 4, %var ; yields i32:result = 4 % %var
Sean Silvab084af42012-12-07 10:36:55 +00007205
7206'``srem``' Instruction
7207^^^^^^^^^^^^^^^^^^^^^^
7208
7209Syntax:
7210"""""""
7211
7212::
7213
Tim Northover675a0962014-06-13 14:24:23 +00007214 <result> = srem <ty> <op1>, <op2> ; yields ty:result
Sean Silvab084af42012-12-07 10:36:55 +00007215
7216Overview:
7217"""""""""
7218
7219The '``srem``' instruction returns the remainder from the signed
7220division of its two operands. This instruction can also take
7221:ref:`vector <t_vector>` versions of the values in which case the elements
7222must be integers.
7223
7224Arguments:
7225""""""""""
7226
7227The two arguments to the '``srem``' instruction must be
7228:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
7229arguments must have identical types.
7230
7231Semantics:
7232""""""""""
7233
7234This instruction returns the *remainder* of a division (where the result
7235is either zero or has the same sign as the dividend, ``op1``), not the
7236*modulo* operator (where the result is either zero or has the same sign
7237as the divisor, ``op2``) of a value. For more information about the
7238difference, see `The Math
7239Forum <http://mathforum.org/dr.math/problems/anne.4.28.99.html>`_. For a
7240table of how this is implemented in various languages, please see
7241`Wikipedia: modulo
7242operation <http://en.wikipedia.org/wiki/Modulo_operation>`_.
7243
7244Note that signed integer remainder and unsigned integer remainder are
7245distinct operations; for unsigned integer remainder, use '``urem``'.
7246
Sanjay Patel2b1f6f42017-03-09 16:20:52 +00007247Taking the remainder of a division by zero is undefined behavior.
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +00007248For vectors, if any element of the divisor is zero, the operation has
Sanjay Patel2b1f6f42017-03-09 16:20:52 +00007249undefined behavior.
Sean Silvab084af42012-12-07 10:36:55 +00007250Overflow also leads to undefined behavior; this is a rare case, but can
7251occur, for example, by taking the remainder of a 32-bit division of
7252-2147483648 by -1. (The remainder doesn't actually overflow, but this
7253rule lets srem be implemented using instructions that return both the
7254result of the division and the remainder.)
7255
7256Example:
7257""""""""
7258
Renato Golin124f2592016-07-20 12:16:38 +00007259.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00007260
Tim Northover675a0962014-06-13 14:24:23 +00007261 <result> = srem i32 4, %var ; yields i32:result = 4 % %var
Sean Silvab084af42012-12-07 10:36:55 +00007262
7263.. _i_frem:
7264
7265'``frem``' Instruction
7266^^^^^^^^^^^^^^^^^^^^^^
7267
7268Syntax:
7269"""""""
7270
7271::
7272
Tim Northover675a0962014-06-13 14:24:23 +00007273 <result> = frem [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result
Sean Silvab084af42012-12-07 10:36:55 +00007274
7275Overview:
7276"""""""""
7277
7278The '``frem``' instruction returns the remainder from the division of
7279its two operands.
7280
7281Arguments:
7282""""""""""
7283
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00007284The two arguments to the '``frem``' instruction must be
7285:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of
7286floating-point values. Both arguments must have identical types.
Sean Silvab084af42012-12-07 10:36:55 +00007287
7288Semantics:
7289""""""""""
7290
Sanjay Patel7b722402018-03-07 17:18:22 +00007291The value produced is the floating-point remainder of the two operands.
7292This is the same output as a libm '``fmod``' function, but without any
7293possibility of setting ``errno``. The remainder has the same sign as the
7294dividend.
Sanjay Patelec95e0e2018-03-20 17:05:19 +00007295This instruction is assumed to execute in the default :ref:`floating-point
7296environment <floatenv>`.
Sanjay Patel7b722402018-03-07 17:18:22 +00007297This instruction can also take any number of :ref:`fast-math
7298flags <fastmath>`, which are optimization hints to enable otherwise
7299unsafe floating-point optimizations:
Sean Silvab084af42012-12-07 10:36:55 +00007300
7301Example:
7302""""""""
7303
Renato Golin124f2592016-07-20 12:16:38 +00007304.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00007305
Tim Northover675a0962014-06-13 14:24:23 +00007306 <result> = frem float 4.0, %var ; yields float:result = 4.0 % %var
Sean Silvab084af42012-12-07 10:36:55 +00007307
7308.. _bitwiseops:
7309
7310Bitwise Binary Operations
7311-------------------------
7312
7313Bitwise binary operators are used to do various forms of bit-twiddling
7314in a program. They are generally very efficient instructions and can
7315commonly be strength reduced from other instructions. They require two
7316operands of the same type, execute an operation on them, and produce a
7317single value. The resulting value is the same type as its operands.
7318
7319'``shl``' Instruction
7320^^^^^^^^^^^^^^^^^^^^^
7321
7322Syntax:
7323"""""""
7324
7325::
7326
Tim Northover675a0962014-06-13 14:24:23 +00007327 <result> = shl <ty> <op1>, <op2> ; yields ty:result
7328 <result> = shl nuw <ty> <op1>, <op2> ; yields ty:result
7329 <result> = shl nsw <ty> <op1>, <op2> ; yields ty:result
7330 <result> = shl nuw nsw <ty> <op1>, <op2> ; yields ty:result
Sean Silvab084af42012-12-07 10:36:55 +00007331
7332Overview:
7333"""""""""
7334
7335The '``shl``' instruction returns the first operand shifted to the left
7336a specified number of bits.
7337
7338Arguments:
7339""""""""""
7340
7341Both arguments to the '``shl``' instruction must be the same
7342:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer type.
7343'``op2``' is treated as an unsigned value.
7344
7345Semantics:
7346""""""""""
7347
7348The value produced is ``op1`` \* 2\ :sup:`op2` mod 2\ :sup:`n`,
7349where ``n`` is the width of the result. If ``op2`` is (statically or
Sean Silvab8a108c2015-04-17 21:58:55 +00007350dynamically) equal to or larger than the number of bits in
Nuno Lopesb2781fb2017-06-06 08:28:17 +00007351``op1``, this instruction returns a :ref:`poison value <poisonvalues>`.
7352If the arguments are vectors, each vector element of ``op1`` is shifted
7353by the corresponding shift amount in ``op2``.
Sean Silvab084af42012-12-07 10:36:55 +00007354
Nuno Lopesb2781fb2017-06-06 08:28:17 +00007355If the ``nuw`` keyword is present, then the shift produces a poison
7356value if it shifts out any non-zero bits.
7357If the ``nsw`` keyword is present, then the shift produces a poison
Sanjay Patel2896c772018-06-01 15:21:14 +00007358value if it shifts out any bits that disagree with the resultant sign bit.
Sean Silvab084af42012-12-07 10:36:55 +00007359
7360Example:
7361""""""""
7362
Renato Golin124f2592016-07-20 12:16:38 +00007363.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00007364
Tim Northover675a0962014-06-13 14:24:23 +00007365 <result> = shl i32 4, %var ; yields i32: 4 << %var
7366 <result> = shl i32 4, 2 ; yields i32: 16
7367 <result> = shl i32 1, 10 ; yields i32: 1024
Sean Silvab084af42012-12-07 10:36:55 +00007368 <result> = shl i32 1, 32 ; undefined
7369 <result> = shl <2 x i32> < i32 1, i32 1>, < i32 1, i32 2> ; yields: result=<2 x i32> < i32 2, i32 4>
7370
7371'``lshr``' Instruction
7372^^^^^^^^^^^^^^^^^^^^^^
7373
7374Syntax:
7375"""""""
7376
7377::
7378
Tim Northover675a0962014-06-13 14:24:23 +00007379 <result> = lshr <ty> <op1>, <op2> ; yields ty:result
7380 <result> = lshr exact <ty> <op1>, <op2> ; yields ty:result
Sean Silvab084af42012-12-07 10:36:55 +00007381
7382Overview:
7383"""""""""
7384
7385The '``lshr``' instruction (logical shift right) returns the first
7386operand shifted to the right a specified number of bits with zero fill.
7387
7388Arguments:
7389""""""""""
7390
7391Both arguments to the '``lshr``' instruction must be the same
7392:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer type.
7393'``op2``' is treated as an unsigned value.
7394
7395Semantics:
7396""""""""""
7397
7398This instruction always performs a logical shift right operation. The
7399most significant bits of the result will be filled with zero bits after
7400the shift. If ``op2`` is (statically or dynamically) equal to or larger
Nuno Lopesb2781fb2017-06-06 08:28:17 +00007401than the number of bits in ``op1``, this instruction returns a :ref:`poison
7402value <poisonvalues>`. If the arguments are vectors, each vector element
7403of ``op1`` is shifted by the corresponding shift amount in ``op2``.
Sean Silvab084af42012-12-07 10:36:55 +00007404
7405If the ``exact`` keyword is present, the result value of the ``lshr`` is
Nuno Lopesb2781fb2017-06-06 08:28:17 +00007406a poison value if any of the bits shifted out are non-zero.
Sean Silvab084af42012-12-07 10:36:55 +00007407
7408Example:
7409""""""""
7410
Renato Golin124f2592016-07-20 12:16:38 +00007411.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00007412
Tim Northover675a0962014-06-13 14:24:23 +00007413 <result> = lshr i32 4, 1 ; yields i32:result = 2
7414 <result> = lshr i32 4, 2 ; yields i32:result = 1
7415 <result> = lshr i8 4, 3 ; yields i8:result = 0
7416 <result> = lshr i8 -2, 1 ; yields i8:result = 0x7F
Sean Silvab084af42012-12-07 10:36:55 +00007417 <result> = lshr i32 1, 32 ; undefined
7418 <result> = lshr <2 x i32> < i32 -2, i32 4>, < i32 1, i32 2> ; yields: result=<2 x i32> < i32 0x7FFFFFFF, i32 1>
7419
7420'``ashr``' Instruction
7421^^^^^^^^^^^^^^^^^^^^^^
7422
7423Syntax:
7424"""""""
7425
7426::
7427
Tim Northover675a0962014-06-13 14:24:23 +00007428 <result> = ashr <ty> <op1>, <op2> ; yields ty:result
7429 <result> = ashr exact <ty> <op1>, <op2> ; yields ty:result
Sean Silvab084af42012-12-07 10:36:55 +00007430
7431Overview:
7432"""""""""
7433
7434The '``ashr``' instruction (arithmetic shift right) returns the first
7435operand shifted to the right a specified number of bits with sign
7436extension.
7437
7438Arguments:
7439""""""""""
7440
7441Both arguments to the '``ashr``' instruction must be the same
7442:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer type.
7443'``op2``' is treated as an unsigned value.
7444
7445Semantics:
7446""""""""""
7447
7448This instruction always performs an arithmetic shift right operation,
7449The most significant bits of the result will be filled with the sign bit
7450of ``op1``. If ``op2`` is (statically or dynamically) equal to or larger
Nuno Lopesb2781fb2017-06-06 08:28:17 +00007451than the number of bits in ``op1``, this instruction returns a :ref:`poison
7452value <poisonvalues>`. If the arguments are vectors, each vector element
7453of ``op1`` is shifted by the corresponding shift amount in ``op2``.
Sean Silvab084af42012-12-07 10:36:55 +00007454
7455If the ``exact`` keyword is present, the result value of the ``ashr`` is
Nuno Lopesb2781fb2017-06-06 08:28:17 +00007456a poison value if any of the bits shifted out are non-zero.
Sean Silvab084af42012-12-07 10:36:55 +00007457
7458Example:
7459""""""""
7460
Renato Golin124f2592016-07-20 12:16:38 +00007461.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00007462
Tim Northover675a0962014-06-13 14:24:23 +00007463 <result> = ashr i32 4, 1 ; yields i32:result = 2
7464 <result> = ashr i32 4, 2 ; yields i32:result = 1
7465 <result> = ashr i8 4, 3 ; yields i8:result = 0
7466 <result> = ashr i8 -2, 1 ; yields i8:result = -1
Sean Silvab084af42012-12-07 10:36:55 +00007467 <result> = ashr i32 1, 32 ; undefined
7468 <result> = ashr <2 x i32> < i32 -2, i32 4>, < i32 1, i32 3> ; yields: result=<2 x i32> < i32 -1, i32 0>
7469
7470'``and``' Instruction
7471^^^^^^^^^^^^^^^^^^^^^
7472
7473Syntax:
7474"""""""
7475
7476::
7477
Tim Northover675a0962014-06-13 14:24:23 +00007478 <result> = and <ty> <op1>, <op2> ; yields ty:result
Sean Silvab084af42012-12-07 10:36:55 +00007479
7480Overview:
7481"""""""""
7482
7483The '``and``' instruction returns the bitwise logical and of its two
7484operands.
7485
7486Arguments:
7487""""""""""
7488
7489The two arguments to the '``and``' instruction must be
7490:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
7491arguments must have identical types.
7492
7493Semantics:
7494""""""""""
7495
7496The truth table used for the '``and``' instruction is:
7497
7498+-----+-----+-----+
7499| In0 | In1 | Out |
7500+-----+-----+-----+
7501| 0 | 0 | 0 |
7502+-----+-----+-----+
7503| 0 | 1 | 0 |
7504+-----+-----+-----+
7505| 1 | 0 | 0 |
7506+-----+-----+-----+
7507| 1 | 1 | 1 |
7508+-----+-----+-----+
7509
7510Example:
7511""""""""
7512
Renato Golin124f2592016-07-20 12:16:38 +00007513.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00007514
Tim Northover675a0962014-06-13 14:24:23 +00007515 <result> = and i32 4, %var ; yields i32:result = 4 & %var
7516 <result> = and i32 15, 40 ; yields i32:result = 8
7517 <result> = and i32 4, 8 ; yields i32:result = 0
Sean Silvab084af42012-12-07 10:36:55 +00007518
7519'``or``' Instruction
7520^^^^^^^^^^^^^^^^^^^^
7521
7522Syntax:
7523"""""""
7524
7525::
7526
Tim Northover675a0962014-06-13 14:24:23 +00007527 <result> = or <ty> <op1>, <op2> ; yields ty:result
Sean Silvab084af42012-12-07 10:36:55 +00007528
7529Overview:
7530"""""""""
7531
7532The '``or``' instruction returns the bitwise logical inclusive or of its
7533two operands.
7534
7535Arguments:
7536""""""""""
7537
7538The two arguments to the '``or``' instruction must be
7539:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
7540arguments must have identical types.
7541
7542Semantics:
7543""""""""""
7544
7545The truth table used for the '``or``' instruction is:
7546
7547+-----+-----+-----+
7548| In0 | In1 | Out |
7549+-----+-----+-----+
7550| 0 | 0 | 0 |
7551+-----+-----+-----+
7552| 0 | 1 | 1 |
7553+-----+-----+-----+
7554| 1 | 0 | 1 |
7555+-----+-----+-----+
7556| 1 | 1 | 1 |
7557+-----+-----+-----+
7558
7559Example:
7560""""""""
7561
7562::
7563
Tim Northover675a0962014-06-13 14:24:23 +00007564 <result> = or i32 4, %var ; yields i32:result = 4 | %var
7565 <result> = or i32 15, 40 ; yields i32:result = 47
7566 <result> = or i32 4, 8 ; yields i32:result = 12
Sean Silvab084af42012-12-07 10:36:55 +00007567
7568'``xor``' Instruction
7569^^^^^^^^^^^^^^^^^^^^^
7570
7571Syntax:
7572"""""""
7573
7574::
7575
Tim Northover675a0962014-06-13 14:24:23 +00007576 <result> = xor <ty> <op1>, <op2> ; yields ty:result
Sean Silvab084af42012-12-07 10:36:55 +00007577
7578Overview:
7579"""""""""
7580
7581The '``xor``' instruction returns the bitwise logical exclusive or of
7582its two operands. The ``xor`` is used to implement the "one's
7583complement" operation, which is the "~" operator in C.
7584
7585Arguments:
7586""""""""""
7587
7588The two arguments to the '``xor``' instruction must be
7589:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
7590arguments must have identical types.
7591
7592Semantics:
7593""""""""""
7594
7595The truth table used for the '``xor``' instruction is:
7596
7597+-----+-----+-----+
7598| In0 | In1 | Out |
7599+-----+-----+-----+
7600| 0 | 0 | 0 |
7601+-----+-----+-----+
7602| 0 | 1 | 1 |
7603+-----+-----+-----+
7604| 1 | 0 | 1 |
7605+-----+-----+-----+
7606| 1 | 1 | 0 |
7607+-----+-----+-----+
7608
7609Example:
7610""""""""
7611
Renato Golin124f2592016-07-20 12:16:38 +00007612.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00007613
Tim Northover675a0962014-06-13 14:24:23 +00007614 <result> = xor i32 4, %var ; yields i32:result = 4 ^ %var
7615 <result> = xor i32 15, 40 ; yields i32:result = 39
7616 <result> = xor i32 4, 8 ; yields i32:result = 12
7617 <result> = xor i32 %V, -1 ; yields i32:result = ~%V
Sean Silvab084af42012-12-07 10:36:55 +00007618
7619Vector Operations
7620-----------------
7621
7622LLVM supports several instructions to represent vector operations in a
7623target-independent manner. These instructions cover the element-access
7624and vector-specific operations needed to process vectors effectively.
7625While LLVM does directly support these vector operations, many
7626sophisticated algorithms will want to use target-specific intrinsics to
7627take full advantage of a specific target.
7628
7629.. _i_extractelement:
7630
7631'``extractelement``' Instruction
7632^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7633
7634Syntax:
7635"""""""
7636
7637::
7638
Michael J. Spencer1f10c5ea2014-05-01 22:12:39 +00007639 <result> = extractelement <n x <ty>> <val>, <ty2> <idx> ; yields <ty>
Sean Silvab084af42012-12-07 10:36:55 +00007640
7641Overview:
7642"""""""""
7643
7644The '``extractelement``' instruction extracts a single scalar element
7645from a vector at a specified index.
7646
7647Arguments:
7648""""""""""
7649
7650The first operand of an '``extractelement``' instruction is a value of
7651:ref:`vector <t_vector>` type. The second operand is an index indicating
7652the position from which to extract the element. The index may be a
Michael J. Spencer1f10c5ea2014-05-01 22:12:39 +00007653variable of any integer type.
Sean Silvab084af42012-12-07 10:36:55 +00007654
7655Semantics:
7656""""""""""
7657
7658The result is a scalar of the same type as the element type of ``val``.
7659Its value is the value at position ``idx`` of ``val``. If ``idx``
Eli Friedman2c7a81b2018-06-08 21:23:09 +00007660exceeds the length of ``val``, the result is a
7661:ref:`poison value <poisonvalues>`.
Sean Silvab084af42012-12-07 10:36:55 +00007662
7663Example:
7664""""""""
7665
Renato Golin124f2592016-07-20 12:16:38 +00007666.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00007667
7668 <result> = extractelement <4 x i32> %vec, i32 0 ; yields i32
7669
7670.. _i_insertelement:
7671
7672'``insertelement``' Instruction
7673^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7674
7675Syntax:
7676"""""""
7677
7678::
7679
Michael J. Spencer1f10c5ea2014-05-01 22:12:39 +00007680 <result> = insertelement <n x <ty>> <val>, <ty> <elt>, <ty2> <idx> ; yields <n x <ty>>
Sean Silvab084af42012-12-07 10:36:55 +00007681
7682Overview:
7683"""""""""
7684
7685The '``insertelement``' instruction inserts a scalar element into a
7686vector at a specified index.
7687
7688Arguments:
7689""""""""""
7690
7691The first operand of an '``insertelement``' instruction is a value of
7692:ref:`vector <t_vector>` type. The second operand is a scalar value whose
7693type must equal the element type of the first operand. The third operand
7694is an index indicating the position at which to insert the value. The
Michael J. Spencer1f10c5ea2014-05-01 22:12:39 +00007695index may be a variable of any integer type.
Sean Silvab084af42012-12-07 10:36:55 +00007696
7697Semantics:
7698""""""""""
7699
7700The result is a vector of the same type as ``val``. Its element values
7701are those of ``val`` except at position ``idx``, where it gets the value
Eli Friedman2c7a81b2018-06-08 21:23:09 +00007702``elt``. If ``idx`` exceeds the length of ``val``, the result
7703is a :ref:`poison value <poisonvalues>`.
Sean Silvab084af42012-12-07 10:36:55 +00007704
7705Example:
7706""""""""
7707
Renato Golin124f2592016-07-20 12:16:38 +00007708.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00007709
7710 <result> = insertelement <4 x i32> %vec, i32 1, i32 0 ; yields <4 x i32>
7711
7712.. _i_shufflevector:
7713
7714'``shufflevector``' Instruction
7715^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7716
7717Syntax:
7718"""""""
7719
7720::
7721
7722 <result> = shufflevector <n x <ty>> <v1>, <n x <ty>> <v2>, <m x i32> <mask> ; yields <m x <ty>>
7723
7724Overview:
7725"""""""""
7726
7727The '``shufflevector``' instruction constructs a permutation of elements
7728from two input vectors, returning a vector with the same element type as
7729the input and length that is the same as the shuffle mask.
7730
7731Arguments:
7732""""""""""
7733
7734The first two operands of a '``shufflevector``' instruction are vectors
7735with the same type. The third argument is a shuffle mask whose element
7736type is always 'i32'. The result of the instruction is a vector whose
7737length is the same as the shuffle mask and whose element type is the
7738same as the element type of the first two operands.
7739
7740The shuffle mask operand is required to be a constant vector with either
7741constant integer or undef values.
7742
7743Semantics:
7744""""""""""
7745
7746The elements of the two input vectors are numbered from left to right
7747across both of the vectors. The shuffle mask operand specifies, for each
7748element of the result vector, which element of the two input vectors the
Sanjay Patel6e410182017-04-12 18:39:53 +00007749result element gets. If the shuffle mask is undef, the result vector is
7750undef. If any element of the mask operand is undef, that element of the
7751result is undef. If the shuffle mask selects an undef element from one
7752of the input vectors, the resulting element is undef.
Sean Silvab084af42012-12-07 10:36:55 +00007753
7754Example:
7755""""""""
7756
Renato Golin124f2592016-07-20 12:16:38 +00007757.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00007758
7759 <result> = shufflevector <4 x i32> %v1, <4 x i32> %v2,
7760 <4 x i32> <i32 0, i32 4, i32 1, i32 5> ; yields <4 x i32>
7761 <result> = shufflevector <4 x i32> %v1, <4 x i32> undef,
7762 <4 x i32> <i32 0, i32 1, i32 2, i32 3> ; yields <4 x i32> - Identity shuffle.
7763 <result> = shufflevector <8 x i32> %v1, <8 x i32> undef,
7764 <4 x i32> <i32 0, i32 1, i32 2, i32 3> ; yields <4 x i32>
7765 <result> = shufflevector <4 x i32> %v1, <4 x i32> %v2,
7766 <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7 > ; yields <8 x i32>
7767
7768Aggregate Operations
7769--------------------
7770
7771LLVM supports several instructions for working with
7772:ref:`aggregate <t_aggregate>` values.
7773
7774.. _i_extractvalue:
7775
7776'``extractvalue``' Instruction
7777^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7778
7779Syntax:
7780"""""""
7781
7782::
7783
7784 <result> = extractvalue <aggregate type> <val>, <idx>{, <idx>}*
7785
7786Overview:
7787"""""""""
7788
7789The '``extractvalue``' instruction extracts the value of a member field
7790from an :ref:`aggregate <t_aggregate>` value.
7791
7792Arguments:
7793""""""""""
7794
7795The first operand of an '``extractvalue``' instruction is a value of
Arch D. Robisona7f8f252015-10-14 19:10:45 +00007796:ref:`struct <t_struct>` or :ref:`array <t_array>` type. The other operands are
Sean Silvab084af42012-12-07 10:36:55 +00007797constant indices to specify which value to extract in a similar manner
7798as indices in a '``getelementptr``' instruction.
7799
7800The major differences to ``getelementptr`` indexing are:
7801
7802- Since the value being indexed is not a pointer, the first index is
7803 omitted and assumed to be zero.
7804- At least one index must be specified.
7805- Not only struct indices but also array indices must be in bounds.
7806
7807Semantics:
7808""""""""""
7809
7810The result is the value at the position in the aggregate specified by
7811the index operands.
7812
7813Example:
7814""""""""
7815
Renato Golin124f2592016-07-20 12:16:38 +00007816.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00007817
7818 <result> = extractvalue {i32, float} %agg, 0 ; yields i32
7819
7820.. _i_insertvalue:
7821
7822'``insertvalue``' Instruction
7823^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7824
7825Syntax:
7826"""""""
7827
7828::
7829
7830 <result> = insertvalue <aggregate type> <val>, <ty> <elt>, <idx>{, <idx>}* ; yields <aggregate type>
7831
7832Overview:
7833"""""""""
7834
7835The '``insertvalue``' instruction inserts a value into a member field in
7836an :ref:`aggregate <t_aggregate>` value.
7837
7838Arguments:
7839""""""""""
7840
7841The first operand of an '``insertvalue``' instruction is a value of
7842:ref:`struct <t_struct>` or :ref:`array <t_array>` type. The second operand is
7843a first-class value to insert. The following operands are constant
7844indices indicating the position at which to insert the value in a
7845similar manner as indices in a '``extractvalue``' instruction. The value
7846to insert must have the same type as the value identified by the
7847indices.
7848
7849Semantics:
7850""""""""""
7851
7852The result is an aggregate of the same type as ``val``. Its value is
7853that of ``val`` except that the value at the position specified by the
7854indices is that of ``elt``.
7855
7856Example:
7857""""""""
7858
7859.. code-block:: llvm
7860
7861 %agg1 = insertvalue {i32, float} undef, i32 1, 0 ; yields {i32 1, float undef}
7862 %agg2 = insertvalue {i32, float} %agg1, float %val, 1 ; yields {i32 1, float %val}
Dan Liewffcfe7f2014-09-08 21:19:46 +00007863 %agg3 = insertvalue {i32, {float}} undef, float %val, 1, 0 ; yields {i32 undef, {float %val}}
Sean Silvab084af42012-12-07 10:36:55 +00007864
7865.. _memoryops:
7866
7867Memory Access and Addressing Operations
7868---------------------------------------
7869
7870A key design point of an SSA-based representation is how it represents
7871memory. In LLVM, no memory locations are in SSA form, which makes things
7872very simple. This section describes how to read, write, and allocate
7873memory in LLVM.
7874
7875.. _i_alloca:
7876
7877'``alloca``' Instruction
7878^^^^^^^^^^^^^^^^^^^^^^^^
7879
7880Syntax:
7881"""""""
7882
7883::
7884
Matt Arsenault3c1fc762017-04-10 22:27:50 +00007885 <result> = alloca [inalloca] <type> [, <ty> <NumElements>] [, align <alignment>] [, addrspace(<num>)] ; yields type addrspace(num)*:result
Sean Silvab084af42012-12-07 10:36:55 +00007886
7887Overview:
7888"""""""""
7889
7890The '``alloca``' instruction allocates memory on the stack frame of the
7891currently executing function, to be automatically released when this
7892function returns to its caller. The object is always allocated in the
Matt Arsenault3c1fc762017-04-10 22:27:50 +00007893address space for allocas indicated in the datalayout.
Sean Silvab084af42012-12-07 10:36:55 +00007894
7895Arguments:
7896""""""""""
7897
7898The '``alloca``' instruction allocates ``sizeof(<type>)*NumElements``
7899bytes of memory on the runtime stack, returning a pointer of the
7900appropriate type to the program. If "NumElements" is specified, it is
7901the number of elements allocated, otherwise "NumElements" is defaulted
7902to be one. If a constant alignment is specified, the value result of the
Reid Kleckner15fe7a52014-07-15 01:16:09 +00007903allocation is guaranteed to be aligned to at least that boundary. The
7904alignment may not be greater than ``1 << 29``. If not specified, or if
7905zero, the target can choose to align the allocation on any convenient
7906boundary compatible with the type.
Sean Silvab084af42012-12-07 10:36:55 +00007907
7908'``type``' may be any sized type.
7909
7910Semantics:
7911""""""""""
7912
7913Memory is allocated; a pointer is returned. The operation is undefined
7914if there is insufficient stack space for the allocation. '``alloca``'d
7915memory is automatically released when the function returns. The
7916'``alloca``' instruction is commonly used to represent automatic
7917variables that must have an address available. When the function returns
7918(either with the ``ret`` or ``resume`` instructions), the memory is
Eli Friedman18f882c2018-07-11 00:02:01 +00007919reclaimed. Allocating zero bytes is legal, but the returned pointer may not
7920be unique. The order in which memory is allocated (ie., which way the stack
7921grows) is not specified.
Sean Silvab084af42012-12-07 10:36:55 +00007922
7923Example:
7924""""""""
7925
7926.. code-block:: llvm
7927
Tim Northover675a0962014-06-13 14:24:23 +00007928 %ptr = alloca i32 ; yields i32*:ptr
7929 %ptr = alloca i32, i32 4 ; yields i32*:ptr
7930 %ptr = alloca i32, i32 4, align 1024 ; yields i32*:ptr
7931 %ptr = alloca i32, align 1024 ; yields i32*:ptr
Sean Silvab084af42012-12-07 10:36:55 +00007932
7933.. _i_load:
7934
7935'``load``' Instruction
7936^^^^^^^^^^^^^^^^^^^^^^
7937
7938Syntax:
7939"""""""
7940
7941::
7942
Artur Pilipenkob4d00902015-09-28 17:41:08 +00007943 <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 +00007944 <result> = load atomic [volatile] <ty>, <ty>* <pointer> [syncscope("<target-scope>")] <ordering>, align <alignment> [, !invariant.group !<index>]
Sean Silvab084af42012-12-07 10:36:55 +00007945 !<index> = !{ i32 1 }
Artur Pilipenko253d71e2015-09-18 12:07:10 +00007946 !<deref_bytes_node> = !{i64 <dereferenceable_bytes>}
Artur Pilipenkob4d00902015-09-28 17:41:08 +00007947 !<align_node> = !{ i64 <value_alignment> }
Sean Silvab084af42012-12-07 10:36:55 +00007948
7949Overview:
7950"""""""""
7951
7952The '``load``' instruction is used to read from memory.
7953
7954Arguments:
7955""""""""""
7956
Sanjoy Dasc2cf6ef2016-06-01 16:13:10 +00007957The argument to the ``load`` instruction specifies the memory address from which
7958to load. The type specified must be a :ref:`first class <t_firstclass>` type of
7959known size (i.e. not containing an :ref:`opaque structural type <t_opaque>`). If
7960the ``load`` is marked as ``volatile``, then the optimizer is not allowed to
7961modify the number or order of execution of this ``load`` with other
7962:ref:`volatile operations <volatile>`.
Sean Silvab084af42012-12-07 10:36:55 +00007963
JF Bastiend1fb5852015-12-17 22:09:19 +00007964If the ``load`` is marked as ``atomic``, it takes an extra :ref:`ordering
Konstantin Zhuravlyovbb80d3e2017-07-11 22:23:00 +00007965<ordering>` and optional ``syncscope("<target-scope>")`` argument. The
7966``release`` and ``acq_rel`` orderings are not valid on ``load`` instructions.
7967Atomic loads produce :ref:`defined <memmodel>` results when they may see
7968multiple atomic stores. The type of the pointee must be an integer, pointer, or
7969floating-point type whose bit width is a power of two greater than or equal to
7970eight and less than or equal to a target-specific size limit. ``align`` must be
7971explicitly specified on atomic loads, and the load has undefined behavior if the
7972alignment is not set to a value which is at least the size in bytes of the
JF Bastiend1fb5852015-12-17 22:09:19 +00007973pointee. ``!nontemporal`` does not have any defined semantics for atomic loads.
Sean Silvab084af42012-12-07 10:36:55 +00007974
7975The optional constant ``align`` argument specifies the alignment of the
7976operation (that is, the alignment of the memory address). A value of 0
Eli Bendersky239a78b2013-04-17 20:17:08 +00007977or an omitted ``align`` argument means that the operation has the ABI
Sean Silvab084af42012-12-07 10:36:55 +00007978alignment for the target. It is the responsibility of the code emitter
7979to ensure that the alignment information is correct. Overestimating the
7980alignment results in undefined behavior. Underestimating the alignment
Reid Kleckner15fe7a52014-07-15 01:16:09 +00007981may produce less efficient code. An alignment of 1 is always safe. The
Matt Arsenault7020f252016-06-16 16:33:41 +00007982maximum possible alignment is ``1 << 29``. An alignment value higher
7983than the size of the loaded type implies memory up to the alignment
7984value bytes can be safely loaded without trapping in the default
7985address space. Access of the high bytes can interfere with debugging
7986tools, so should not be accessed if the function has the
7987``sanitize_thread`` or ``sanitize_address`` attributes.
Sean Silvab084af42012-12-07 10:36:55 +00007988
7989The optional ``!nontemporal`` metadata must reference a single
Stefanus Du Toit736e2e22013-06-20 14:02:44 +00007990metadata name ``<index>`` corresponding to a metadata node with one
Sean Silvab084af42012-12-07 10:36:55 +00007991``i32`` entry of value 1. The existence of the ``!nontemporal``
Stefanus Du Toit736e2e22013-06-20 14:02:44 +00007992metadata on the instruction tells the optimizer and code generator
Sean Silvab084af42012-12-07 10:36:55 +00007993that this load is not expected to be reused in the cache. The code
7994generator may select special instructions to save cache bandwidth, such
7995as the ``MOVNT`` instruction on x86.
7996
7997The optional ``!invariant.load`` metadata must reference a single
Stefanus Du Toit736e2e22013-06-20 14:02:44 +00007998metadata name ``<index>`` corresponding to a metadata node with no
Geoff Berry4bda5762016-08-31 17:39:21 +00007999entries. If a load instruction tagged with the ``!invariant.load``
8000metadata is executed, the optimizer may assume the memory location
8001referenced by the load contains the same value at all points in the
Eli Friedmane15a1112018-07-17 20:38:11 +00008002program where the memory location is known to be dereferenceable;
8003otherwise, the behavior is undefined.
Sean Silvab084af42012-12-07 10:36:55 +00008004
Piotr Padlewski6c15ec42015-09-15 18:32:14 +00008005The optional ``!invariant.group`` metadata must reference a single metadata name
Piotr Padlewskice358262018-05-18 23:53:46 +00008006 ``<index>`` corresponding to a metadata node with no entries.
8007 See ``invariant.group`` metadata.
Piotr Padlewski6c15ec42015-09-15 18:32:14 +00008008
Philip Reamescdb72f32014-10-20 22:40:55 +00008009The optional ``!nonnull`` metadata must reference a single
8010metadata name ``<index>`` corresponding to a metadata node with no
8011entries. The existence of the ``!nonnull`` metadata on the
8012instruction tells the optimizer that the value loaded is known to
Eli Friedmane15a1112018-07-17 20:38:11 +00008013never be null. If the value is null at runtime, the behavior is undefined.
8014This is analogous to the ``nonnull`` attribute on parameters and return
8015values. This metadata can only be applied to loads of a pointer type.
Philip Reamescdb72f32014-10-20 22:40:55 +00008016
Artur Pilipenko253d71e2015-09-18 12:07:10 +00008017The optional ``!dereferenceable`` metadata must reference a single metadata
8018name ``<deref_bytes_node>`` corresponding to a metadata node with one ``i64``
Sean Silva706fba52015-08-06 22:56:24 +00008019entry. The existence of the ``!dereferenceable`` metadata on the instruction
Sanjoy Dasf9995472015-05-19 20:10:19 +00008020tells the optimizer that the value loaded is known to be dereferenceable.
Sean Silva706fba52015-08-06 22:56:24 +00008021The number of bytes known to be dereferenceable is specified by the integer
8022value in the metadata node. This is analogous to the ''dereferenceable''
8023attribute on parameters and return values. This metadata can only be applied
Sanjoy Dasf9995472015-05-19 20:10:19 +00008024to loads of a pointer type.
8025
8026The optional ``!dereferenceable_or_null`` metadata must reference a single
Artur Pilipenko253d71e2015-09-18 12:07:10 +00008027metadata name ``<deref_bytes_node>`` corresponding to a metadata node with one
8028``i64`` entry. The existence of the ``!dereferenceable_or_null`` metadata on the
Sanjoy Dasf9995472015-05-19 20:10:19 +00008029instruction tells the optimizer that the value loaded is known to be either
8030dereferenceable or null.
Sean Silva706fba52015-08-06 22:56:24 +00008031The number of bytes known to be dereferenceable is specified by the integer
8032value in the metadata node. This is analogous to the ''dereferenceable_or_null''
8033attribute on parameters and return values. This metadata can only be applied
Sanjoy Dasf9995472015-05-19 20:10:19 +00008034to loads of a pointer type.
8035
Artur Pilipenkob4d00902015-09-28 17:41:08 +00008036The optional ``!align`` metadata must reference a single metadata name
8037``<align_node>`` corresponding to a metadata node with one ``i64`` entry.
8038The existence of the ``!align`` metadata on the instruction tells the
8039optimizer that the value loaded is known to be aligned to a boundary specified
8040by the integer value in the metadata node. The alignment must be a power of 2.
8041This is analogous to the ''align'' attribute on parameters and return values.
Eli Friedmane15a1112018-07-17 20:38:11 +00008042This metadata can only be applied to loads of a pointer type. If the returned
8043value is not appropriately aligned at runtime, the behavior is undefined.
Artur Pilipenkob4d00902015-09-28 17:41:08 +00008044
Sean Silvab084af42012-12-07 10:36:55 +00008045Semantics:
8046""""""""""
8047
8048The location of memory pointed to is loaded. If the value being loaded
8049is of scalar type then the number of bytes read does not exceed the
8050minimum number of bytes needed to hold all bits of the type. For
8051example, loading an ``i24`` reads at most three bytes. When loading a
8052value of a type like ``i20`` with a size that is not an integral number
8053of bytes, the result is undefined if the value was not originally
8054written using a store of the same type.
8055
8056Examples:
8057"""""""""
8058
8059.. code-block:: llvm
8060
Tim Northover675a0962014-06-13 14:24:23 +00008061 %ptr = alloca i32 ; yields i32*:ptr
8062 store i32 3, i32* %ptr ; yields void
David Blaikiec7aabbb2015-03-04 22:06:14 +00008063 %val = load i32, i32* %ptr ; yields i32:val = i32 3
Sean Silvab084af42012-12-07 10:36:55 +00008064
8065.. _i_store:
8066
8067'``store``' Instruction
8068^^^^^^^^^^^^^^^^^^^^^^^
8069
8070Syntax:
8071"""""""
8072
8073::
8074
Piotr Padlewski6c15ec42015-09-15 18:32:14 +00008075 store [volatile] <ty> <value>, <ty>* <pointer>[, align <alignment>][, !nontemporal !<index>][, !invariant.group !<index>] ; yields void
Konstantin Zhuravlyovbb80d3e2017-07-11 22:23:00 +00008076 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 +00008077
8078Overview:
8079"""""""""
8080
8081The '``store``' instruction is used to write to memory.
8082
8083Arguments:
8084""""""""""
8085
Sanjoy Dasc2cf6ef2016-06-01 16:13:10 +00008086There are two arguments to the ``store`` instruction: a value to store and an
8087address at which to store it. The type of the ``<pointer>`` operand must be a
8088pointer to the :ref:`first class <t_firstclass>` type of the ``<value>``
8089operand. If the ``store`` is marked as ``volatile``, then the optimizer is not
8090allowed to modify the number or order of execution of this ``store`` with other
8091:ref:`volatile operations <volatile>`. Only values of :ref:`first class
8092<t_firstclass>` types of known size (i.e. not containing an :ref:`opaque
8093structural type <t_opaque>`) can be stored.
Sean Silvab084af42012-12-07 10:36:55 +00008094
JF Bastiend1fb5852015-12-17 22:09:19 +00008095If the ``store`` is marked as ``atomic``, it takes an extra :ref:`ordering
Konstantin Zhuravlyovbb80d3e2017-07-11 22:23:00 +00008096<ordering>` and optional ``syncscope("<target-scope>")`` argument. The
8097``acquire`` and ``acq_rel`` orderings aren't valid on ``store`` instructions.
8098Atomic loads produce :ref:`defined <memmodel>` results when they may see
8099multiple atomic stores. The type of the pointee must be an integer, pointer, or
8100floating-point type whose bit width is a power of two greater than or equal to
8101eight and less than or equal to a target-specific size limit. ``align`` must be
8102explicitly specified on atomic stores, and the store has undefined behavior if
8103the alignment is not set to a value which is at least the size in bytes of the
JF Bastiend1fb5852015-12-17 22:09:19 +00008104pointee. ``!nontemporal`` does not have any defined semantics for atomic stores.
Sean Silvab084af42012-12-07 10:36:55 +00008105
Eli Benderskyca380842013-04-17 17:17:20 +00008106The optional constant ``align`` argument specifies the alignment of the
Sean Silvab084af42012-12-07 10:36:55 +00008107operation (that is, the alignment of the memory address). A value of 0
Eli Benderskyca380842013-04-17 17:17:20 +00008108or an omitted ``align`` argument means that the operation has the ABI
Sean Silvab084af42012-12-07 10:36:55 +00008109alignment for the target. It is the responsibility of the code emitter
8110to ensure that the alignment information is correct. Overestimating the
Eli Benderskyca380842013-04-17 17:17:20 +00008111alignment results in undefined behavior. Underestimating the
Sean Silvab084af42012-12-07 10:36:55 +00008112alignment may produce less efficient code. An alignment of 1 is always
Matt Arsenault7020f252016-06-16 16:33:41 +00008113safe. The maximum possible alignment is ``1 << 29``. An alignment
8114value higher than the size of the stored type implies memory up to the
8115alignment value bytes can be stored to without trapping in the default
8116address space. Storing to the higher bytes however may result in data
8117races if another thread can access the same address. Introducing a
8118data race is not allowed. Storing to the extra bytes is not allowed
8119even in situations where a data race is known to not exist if the
8120function has the ``sanitize_address`` attribute.
Sean Silvab084af42012-12-07 10:36:55 +00008121
Stefanus Du Toit736e2e22013-06-20 14:02:44 +00008122The optional ``!nontemporal`` metadata must reference a single metadata
Eli Benderskyca380842013-04-17 17:17:20 +00008123name ``<index>`` corresponding to a metadata node with one ``i32`` entry of
Stefanus Du Toit736e2e22013-06-20 14:02:44 +00008124value 1. The existence of the ``!nontemporal`` metadata on the instruction
Sean Silvab084af42012-12-07 10:36:55 +00008125tells the optimizer and code generator that this load is not expected to
8126be reused in the cache. The code generator may select special
JF Bastiend2d8ffd2016-01-13 04:52:26 +00008127instructions to save cache bandwidth, such as the ``MOVNT`` instruction on
Sean Silvab084af42012-12-07 10:36:55 +00008128x86.
8129
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +00008130The optional ``!invariant.group`` metadata must reference a
Piotr Padlewski6c15ec42015-09-15 18:32:14 +00008131single metadata name ``<index>``. See ``invariant.group`` metadata.
8132
Sean Silvab084af42012-12-07 10:36:55 +00008133Semantics:
8134""""""""""
8135
Eli Benderskyca380842013-04-17 17:17:20 +00008136The contents of memory are updated to contain ``<value>`` at the
8137location specified by the ``<pointer>`` operand. If ``<value>`` is
Sean Silvab084af42012-12-07 10:36:55 +00008138of scalar type then the number of bytes written does not exceed the
8139minimum number of bytes needed to hold all bits of the type. For
8140example, storing an ``i24`` writes at most three bytes. When writing a
8141value of a type like ``i20`` with a size that is not an integral number
8142of bytes, it is unspecified what happens to the extra bits that do not
8143belong to the type, but they will typically be overwritten.
8144
8145Example:
8146""""""""
8147
8148.. code-block:: llvm
8149
Tim Northover675a0962014-06-13 14:24:23 +00008150 %ptr = alloca i32 ; yields i32*:ptr
8151 store i32 3, i32* %ptr ; yields void
Nick Lewycky149d04c2015-08-11 01:05:16 +00008152 %val = load i32, i32* %ptr ; yields i32:val = i32 3
Sean Silvab084af42012-12-07 10:36:55 +00008153
8154.. _i_fence:
8155
8156'``fence``' Instruction
8157^^^^^^^^^^^^^^^^^^^^^^^
8158
8159Syntax:
8160"""""""
8161
8162::
8163
Konstantin Zhuravlyovbb80d3e2017-07-11 22:23:00 +00008164 fence [syncscope("<target-scope>")] <ordering> ; yields void
Sean Silvab084af42012-12-07 10:36:55 +00008165
8166Overview:
8167"""""""""
8168
8169The '``fence``' instruction is used to introduce happens-before edges
8170between operations.
8171
8172Arguments:
8173""""""""""
8174
8175'``fence``' instructions take an :ref:`ordering <ordering>` argument which
8176defines what *synchronizes-with* edges they add. They can only be given
8177``acquire``, ``release``, ``acq_rel``, and ``seq_cst`` orderings.
8178
8179Semantics:
8180""""""""""
8181
8182A fence A which has (at least) ``release`` ordering semantics
8183*synchronizes with* a fence B with (at least) ``acquire`` ordering
8184semantics if and only if there exist atomic operations X and Y, both
8185operating on some atomic object M, such that A is sequenced before X, X
8186modifies M (either directly or through some side effect of a sequence
8187headed by X), Y is sequenced before B, and Y observes M. This provides a
8188*happens-before* dependency between A and B. Rather than an explicit
8189``fence``, one (but not both) of the atomic operations X or Y might
8190provide a ``release`` or ``acquire`` (resp.) ordering constraint and
8191still *synchronize-with* the explicit ``fence`` and establish the
8192*happens-before* edge.
8193
8194A ``fence`` which has ``seq_cst`` ordering, in addition to having both
8195``acquire`` and ``release`` semantics specified above, participates in
8196the global program order of other ``seq_cst`` operations and/or fences.
8197
Konstantin Zhuravlyovbb80d3e2017-07-11 22:23:00 +00008198A ``fence`` instruction can also take an optional
8199":ref:`syncscope <syncscope>`" argument.
Sean Silvab084af42012-12-07 10:36:55 +00008200
8201Example:
8202""""""""
8203
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +00008204.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00008205
Konstantin Zhuravlyovbb80d3e2017-07-11 22:23:00 +00008206 fence acquire ; yields void
8207 fence syncscope("singlethread") seq_cst ; yields void
8208 fence syncscope("agent") seq_cst ; yields void
Sean Silvab084af42012-12-07 10:36:55 +00008209
8210.. _i_cmpxchg:
8211
8212'``cmpxchg``' Instruction
8213^^^^^^^^^^^^^^^^^^^^^^^^^
8214
8215Syntax:
8216"""""""
8217
8218::
8219
Konstantin Zhuravlyovbb80d3e2017-07-11 22:23:00 +00008220 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 +00008221
8222Overview:
8223"""""""""
8224
8225The '``cmpxchg``' instruction is used to atomically modify memory. It
8226loads a value in memory and compares it to a given value. If they are
Tim Northover420a2162014-06-13 14:24:07 +00008227equal, it tries to store a new value into the memory.
Sean Silvab084af42012-12-07 10:36:55 +00008228
8229Arguments:
8230""""""""""
8231
8232There are three arguments to the '``cmpxchg``' instruction: an address
8233to operate on, a value to compare to the value currently be at that
8234address, and a new value to place at that address if the compared values
Philip Reames1960cfd2016-02-19 00:06:41 +00008235are equal. The type of '<cmp>' must be an integer or pointer type whose
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +00008236bit width is a power of two greater than or equal to eight and less
Philip Reames1960cfd2016-02-19 00:06:41 +00008237than or equal to a target-specific size limit. '<cmp>' and '<new>' must
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +00008238have the same type, and the type of '<pointer>' must be a pointer to
8239that type. If the ``cmpxchg`` is marked as ``volatile``, then the
Philip Reames1960cfd2016-02-19 00:06:41 +00008240optimizer is not allowed to modify the number or order of execution of
8241this ``cmpxchg`` with other :ref:`volatile operations <volatile>`.
Sean Silvab084af42012-12-07 10:36:55 +00008242
Tim Northovere94a5182014-03-11 10:48:52 +00008243The success and failure :ref:`ordering <ordering>` arguments specify how this
Tim Northover1dcc9f92014-06-13 14:24:16 +00008244``cmpxchg`` synchronizes with other atomic operations. Both ordering parameters
8245must be at least ``monotonic``, the ordering constraint on failure must be no
8246stronger than that on success, and the failure ordering cannot be either
8247``release`` or ``acq_rel``.
Sean Silvab084af42012-12-07 10:36:55 +00008248
Konstantin Zhuravlyovbb80d3e2017-07-11 22:23:00 +00008249A ``cmpxchg`` instruction can also take an optional
8250":ref:`syncscope <syncscope>`" argument.
Sean Silvab084af42012-12-07 10:36:55 +00008251
8252The pointer passed into cmpxchg must have alignment greater than or
8253equal to the size in memory of the operand.
8254
8255Semantics:
8256""""""""""
8257
Tim Northover420a2162014-06-13 14:24:07 +00008258The contents of memory at the location specified by the '``<pointer>``' operand
Matthias Braun93f2b4b2017-08-09 22:22:04 +00008259is read and compared to '``<cmp>``'; if the values are equal, '``<new>``' is
8260written to the location. The original value at the location is returned,
8261together with a flag indicating success (true) or failure (false).
Tim Northover420a2162014-06-13 14:24:07 +00008262
8263If the cmpxchg operation is marked as ``weak`` then a spurious failure is
8264permitted: the operation may not write ``<new>`` even if the comparison
8265matched.
8266
8267If the cmpxchg operation is strong (the default), the i1 value is 1 if and only
8268if the value loaded equals ``cmp``.
Sean Silvab084af42012-12-07 10:36:55 +00008269
Tim Northovere94a5182014-03-11 10:48:52 +00008270A successful ``cmpxchg`` is a read-modify-write instruction for the purpose of
8271identifying release sequences. A failed ``cmpxchg`` is equivalent to an atomic
8272load with an ordering parameter determined the second ordering parameter.
Sean Silvab084af42012-12-07 10:36:55 +00008273
8274Example:
8275""""""""
8276
8277.. code-block:: llvm
8278
8279 entry:
Duncan P. N. Exon Smithc917c7a2016-02-07 05:06:35 +00008280 %orig = load atomic i32, i32* %ptr unordered, align 4 ; yields i32
Sean Silvab084af42012-12-07 10:36:55 +00008281 br label %loop
8282
8283 loop:
Duncan P. N. Exon Smithc917c7a2016-02-07 05:06:35 +00008284 %cmp = phi i32 [ %orig, %entry ], [%value_loaded, %loop]
Sean Silvab084af42012-12-07 10:36:55 +00008285 %squared = mul i32 %cmp, %cmp
Tim Northover675a0962014-06-13 14:24:23 +00008286 %val_success = cmpxchg i32* %ptr, i32 %cmp, i32 %squared acq_rel monotonic ; yields { i32, i1 }
Tim Northover420a2162014-06-13 14:24:07 +00008287 %value_loaded = extractvalue { i32, i1 } %val_success, 0
8288 %success = extractvalue { i32, i1 } %val_success, 1
Sean Silvab084af42012-12-07 10:36:55 +00008289 br i1 %success, label %done, label %loop
8290
8291 done:
8292 ...
8293
8294.. _i_atomicrmw:
8295
8296'``atomicrmw``' Instruction
8297^^^^^^^^^^^^^^^^^^^^^^^^^^^
8298
8299Syntax:
8300"""""""
8301
8302::
8303
Konstantin Zhuravlyovbb80d3e2017-07-11 22:23:00 +00008304 atomicrmw [volatile] <operation> <ty>* <pointer>, <ty> <value> [syncscope("<target-scope>")] <ordering> ; yields ty
Sean Silvab084af42012-12-07 10:36:55 +00008305
8306Overview:
8307"""""""""
8308
8309The '``atomicrmw``' instruction is used to atomically modify memory.
8310
8311Arguments:
8312""""""""""
8313
8314There are three arguments to the '``atomicrmw``' instruction: an
8315operation to apply, an address whose value to modify, an argument to the
8316operation. The operation must be one of the following keywords:
8317
8318- xchg
8319- add
8320- sub
8321- and
8322- nand
8323- or
8324- xor
8325- max
8326- min
8327- umax
8328- umin
8329
8330The type of '<value>' must be an integer type whose bit width is a power
8331of two greater than or equal to eight and less than or equal to a
8332target-specific size limit. The type of the '``<pointer>``' operand must
8333be a pointer to that type. If the ``atomicrmw`` is marked as
8334``volatile``, then the optimizer is not allowed to modify the number or
8335order of execution of this ``atomicrmw`` with other :ref:`volatile
8336operations <volatile>`.
8337
Konstantin Zhuravlyovbb80d3e2017-07-11 22:23:00 +00008338A ``atomicrmw`` instruction can also take an optional
8339":ref:`syncscope <syncscope>`" argument.
8340
Sean Silvab084af42012-12-07 10:36:55 +00008341Semantics:
8342""""""""""
8343
8344The contents of memory at the location specified by the '``<pointer>``'
8345operand are atomically read, modified, and written back. The original
8346value at the location is returned. The modification is specified by the
8347operation argument:
8348
8349- xchg: ``*ptr = val``
8350- add: ``*ptr = *ptr + val``
8351- sub: ``*ptr = *ptr - val``
8352- and: ``*ptr = *ptr & val``
8353- nand: ``*ptr = ~(*ptr & val)``
8354- or: ``*ptr = *ptr | val``
8355- xor: ``*ptr = *ptr ^ val``
8356- max: ``*ptr = *ptr > val ? *ptr : val`` (using a signed comparison)
8357- min: ``*ptr = *ptr < val ? *ptr : val`` (using a signed comparison)
8358- umax: ``*ptr = *ptr > val ? *ptr : val`` (using an unsigned
8359 comparison)
8360- umin: ``*ptr = *ptr < val ? *ptr : val`` (using an unsigned
8361 comparison)
8362
8363Example:
8364""""""""
8365
8366.. code-block:: llvm
8367
Tim Northover675a0962014-06-13 14:24:23 +00008368 %old = atomicrmw add i32* %ptr, i32 1 acquire ; yields i32
Sean Silvab084af42012-12-07 10:36:55 +00008369
8370.. _i_getelementptr:
8371
8372'``getelementptr``' Instruction
8373^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8374
8375Syntax:
8376"""""""
8377
8378::
8379
Peter Collingbourned93620b2016-11-10 22:34:55 +00008380 <result> = getelementptr <ty>, <ty>* <ptrval>{, [inrange] <ty> <idx>}*
8381 <result> = getelementptr inbounds <ty>, <ty>* <ptrval>{, [inrange] <ty> <idx>}*
8382 <result> = getelementptr <ty>, <ptr vector> <ptrval>, [inrange] <vector index type> <idx>
Sean Silvab084af42012-12-07 10:36:55 +00008383
8384Overview:
8385"""""""""
8386
8387The '``getelementptr``' instruction is used to get the address of a
8388subelement of an :ref:`aggregate <t_aggregate>` data structure. It performs
Elena Demikhovsky37a4da82015-07-09 07:42:48 +00008389address calculation only and does not access memory. The instruction can also
8390be used to calculate a vector of such addresses.
Sean Silvab084af42012-12-07 10:36:55 +00008391
8392Arguments:
8393""""""""""
8394
David Blaikie16a97eb2015-03-04 22:02:58 +00008395The first argument is always a type used as the basis for the calculations.
8396The second argument is always a pointer or a vector of pointers, and is the
8397base address to start from. The remaining arguments are indices
Sean Silvab084af42012-12-07 10:36:55 +00008398that indicate which of the elements of the aggregate object are indexed.
8399The interpretation of each index is dependent on the type being indexed
8400into. The first index always indexes the pointer value given as the
David Blaikief91b0302017-06-19 05:34:21 +00008401second argument, the second index indexes a value of the type pointed to
Sean Silvab084af42012-12-07 10:36:55 +00008402(not necessarily the value directly pointed to, since the first index
8403can be non-zero), etc. The first type indexed into must be a pointer
8404value, subsequent types can be arrays, vectors, and structs. Note that
8405subsequent types being indexed into can never be pointers, since that
8406would require loading the pointer before continuing calculation.
8407
8408The type of each index argument depends on the type it is indexing into.
8409When indexing into a (optionally packed) structure, only ``i32`` integer
8410**constants** are allowed (when using a vector of indices they must all
8411be the **same** ``i32`` integer constant). When indexing into an array,
8412pointer or vector, integers of any width are allowed, and they are not
8413required to be constant. These integers are treated as signed values
8414where relevant.
8415
8416For example, let's consider a C code fragment and how it gets compiled
8417to LLVM:
8418
8419.. code-block:: c
8420
8421 struct RT {
8422 char A;
8423 int B[10][20];
8424 char C;
8425 };
8426 struct ST {
8427 int X;
8428 double Y;
8429 struct RT Z;
8430 };
8431
8432 int *foo(struct ST *s) {
8433 return &s[1].Z.B[5][13];
8434 }
8435
8436The LLVM code generated by Clang is:
8437
8438.. code-block:: llvm
8439
8440 %struct.RT = type { i8, [10 x [20 x i32]], i8 }
8441 %struct.ST = type { i32, double, %struct.RT }
8442
8443 define i32* @foo(%struct.ST* %s) nounwind uwtable readnone optsize ssp {
8444 entry:
David Blaikie16a97eb2015-03-04 22:02:58 +00008445 %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 +00008446 ret i32* %arrayidx
8447 }
8448
8449Semantics:
8450""""""""""
8451
8452In the example above, the first index is indexing into the
8453'``%struct.ST*``' type, which is a pointer, yielding a '``%struct.ST``'
8454= '``{ i32, double, %struct.RT }``' type, a structure. The second index
8455indexes into the third element of the structure, yielding a
8456'``%struct.RT``' = '``{ i8 , [10 x [20 x i32]], i8 }``' type, another
8457structure. The third index indexes into the second element of the
8458structure, yielding a '``[10 x [20 x i32]]``' type, an array. The two
8459dimensions of the array are subscripted into, yielding an '``i32``'
8460type. The '``getelementptr``' instruction returns a pointer to this
8461element, thus computing a value of '``i32*``' type.
8462
8463Note that it is perfectly legal to index partially through a structure,
8464returning a pointer to an inner element. Because of this, the LLVM code
8465for the given testcase is equivalent to:
8466
8467.. code-block:: llvm
8468
8469 define i32* @foo(%struct.ST* %s) {
David Blaikie16a97eb2015-03-04 22:02:58 +00008470 %t1 = getelementptr %struct.ST, %struct.ST* %s, i32 1 ; yields %struct.ST*:%t1
8471 %t2 = getelementptr %struct.ST, %struct.ST* %t1, i32 0, i32 2 ; yields %struct.RT*:%t2
8472 %t3 = getelementptr %struct.RT, %struct.RT* %t2, i32 0, i32 1 ; yields [10 x [20 x i32]]*:%t3
8473 %t4 = getelementptr [10 x [20 x i32]], [10 x [20 x i32]]* %t3, i32 0, i32 5 ; yields [20 x i32]*:%t4
8474 %t5 = getelementptr [20 x i32], [20 x i32]* %t4, i32 0, i32 13 ; yields i32*:%t5
Sean Silvab084af42012-12-07 10:36:55 +00008475 ret i32* %t5
8476 }
8477
8478If the ``inbounds`` keyword is present, the result value of the
8479``getelementptr`` is a :ref:`poison value <poisonvalues>` if the base
8480pointer is not an *in bounds* address of an allocated object, or if any
8481of the addresses that would be formed by successive addition of the
8482offsets implied by the indices to the base address with infinitely
8483precise signed arithmetic are not an *in bounds* address of that
8484allocated object. The *in bounds* addresses for an allocated object are
8485all the addresses that point into the object, plus the address one byte
Eli Friedman13f2e352017-02-23 00:48:18 +00008486past the end. The only *in bounds* address for a null pointer in the
8487default address-space is the null pointer itself. In cases where the
8488base is a vector of pointers the ``inbounds`` keyword applies to each
8489of the computations element-wise.
Sean Silvab084af42012-12-07 10:36:55 +00008490
8491If the ``inbounds`` keyword is not present, the offsets are added to the
8492base address with silently-wrapping two's complement arithmetic. If the
8493offsets have a different width from the pointer, they are sign-extended
8494or truncated to the width of the pointer. The result value of the
8495``getelementptr`` may be outside the object pointed to by the base
8496pointer. The result value may not necessarily be used to access memory
8497though, even if it happens to point into allocated storage. See the
8498:ref:`Pointer Aliasing Rules <pointeraliasing>` section for more
8499information.
8500
Peter Collingbourned93620b2016-11-10 22:34:55 +00008501If the ``inrange`` keyword is present before any index, loading from or
8502storing to any pointer derived from the ``getelementptr`` has undefined
8503behavior if the load or store would access memory outside of the bounds of
8504the element selected by the index marked as ``inrange``. The result of a
8505pointer comparison or ``ptrtoint`` (including ``ptrtoint``-like operations
8506involving memory) involving a pointer derived from a ``getelementptr`` with
8507the ``inrange`` keyword is undefined, with the exception of comparisons
8508in the case where both operands are in the range of the element selected
8509by the ``inrange`` keyword, inclusive of the address one past the end of
8510that element. Note that the ``inrange`` keyword is currently only allowed
8511in constant ``getelementptr`` expressions.
8512
Sean Silvab084af42012-12-07 10:36:55 +00008513The getelementptr instruction is often confusing. For some more insight
8514into how it works, see :doc:`the getelementptr FAQ <GetElementPtr>`.
8515
8516Example:
8517""""""""
8518
8519.. code-block:: llvm
8520
8521 ; yields [12 x i8]*:aptr
David Blaikie16a97eb2015-03-04 22:02:58 +00008522 %aptr = getelementptr {i32, [12 x i8]}, {i32, [12 x i8]}* %saptr, i64 0, i32 1
Sean Silvab084af42012-12-07 10:36:55 +00008523 ; yields i8*:vptr
David Blaikie16a97eb2015-03-04 22:02:58 +00008524 %vptr = getelementptr {i32, <2 x i8>}, {i32, <2 x i8>}* %svptr, i64 0, i32 1, i32 1
Sean Silvab084af42012-12-07 10:36:55 +00008525 ; yields i8*:eptr
David Blaikie16a97eb2015-03-04 22:02:58 +00008526 %eptr = getelementptr [12 x i8], [12 x i8]* %aptr, i64 0, i32 1
Sean Silvab084af42012-12-07 10:36:55 +00008527 ; yields i32*:iptr
David Blaikie16a97eb2015-03-04 22:02:58 +00008528 %iptr = getelementptr [10 x i32], [10 x i32]* @arr, i16 0, i16 0
Sean Silvab084af42012-12-07 10:36:55 +00008529
Elena Demikhovsky37a4da82015-07-09 07:42:48 +00008530Vector of pointers:
8531"""""""""""""""""""
8532
8533The ``getelementptr`` returns a vector of pointers, instead of a single address,
8534when one or more of its arguments is a vector. In such cases, all vector
8535arguments should have the same number of elements, and every scalar argument
8536will be effectively broadcast into a vector during address calculation.
Sean Silvab084af42012-12-07 10:36:55 +00008537
8538.. code-block:: llvm
8539
Elena Demikhovsky37a4da82015-07-09 07:42:48 +00008540 ; All arguments are vectors:
8541 ; A[i] = ptrs[i] + offsets[i]*sizeof(i8)
8542 %A = getelementptr i8, <4 x i8*> %ptrs, <4 x i64> %offsets
Sean Silva706fba52015-08-06 22:56:24 +00008543
Elena Demikhovsky37a4da82015-07-09 07:42:48 +00008544 ; Add the same scalar offset to each pointer of a vector:
8545 ; A[i] = ptrs[i] + offset*sizeof(i8)
8546 %A = getelementptr i8, <4 x i8*> %ptrs, i64 %offset
Sean Silva706fba52015-08-06 22:56:24 +00008547
Elena Demikhovsky37a4da82015-07-09 07:42:48 +00008548 ; Add distinct offsets to the same pointer:
8549 ; A[i] = ptr + offsets[i]*sizeof(i8)
8550 %A = getelementptr i8, i8* %ptr, <4 x i64> %offsets
Sean Silva706fba52015-08-06 22:56:24 +00008551
Elena Demikhovsky37a4da82015-07-09 07:42:48 +00008552 ; In all cases described above the type of the result is <4 x i8*>
8553
8554The two following instructions are equivalent:
8555
8556.. code-block:: llvm
8557
8558 getelementptr %struct.ST, <4 x %struct.ST*> %s, <4 x i64> %ind1,
8559 <4 x i32> <i32 2, i32 2, i32 2, i32 2>,
8560 <4 x i32> <i32 1, i32 1, i32 1, i32 1>,
8561 <4 x i32> %ind4,
8562 <4 x i64> <i64 13, i64 13, i64 13, i64 13>
Sean Silva706fba52015-08-06 22:56:24 +00008563
Elena Demikhovsky37a4da82015-07-09 07:42:48 +00008564 getelementptr %struct.ST, <4 x %struct.ST*> %s, <4 x i64> %ind1,
8565 i32 2, i32 1, <4 x i32> %ind4, i64 13
8566
8567Let's look at the C code, where the vector version of ``getelementptr``
8568makes sense:
8569
8570.. code-block:: c
8571
8572 // Let's assume that we vectorize the following loop:
Alexey Baderadec2832017-01-30 07:38:58 +00008573 double *A, *B; int *C;
Elena Demikhovsky37a4da82015-07-09 07:42:48 +00008574 for (int i = 0; i < size; ++i) {
8575 A[i] = B[C[i]];
8576 }
8577
8578.. code-block:: llvm
8579
8580 ; get pointers for 8 elements from array B
8581 %ptrs = getelementptr double, double* %B, <8 x i32> %C
8582 ; load 8 elements from array B into A
Elad Cohenef5798a2017-05-03 12:28:54 +00008583 %A = call <8 x double> @llvm.masked.gather.v8f64.v8p0f64(<8 x double*> %ptrs,
Elena Demikhovsky37a4da82015-07-09 07:42:48 +00008584 i32 8, <8 x i1> %mask, <8 x double> %passthru)
Sean Silvab084af42012-12-07 10:36:55 +00008585
8586Conversion Operations
8587---------------------
8588
8589The instructions in this category are the conversion instructions
8590(casting) which all take a single operand and a type. They perform
8591various bit conversions on the operand.
8592
Bjorn Petterssone1285e32017-10-24 11:59:20 +00008593.. _i_trunc:
8594
Sean Silvab084af42012-12-07 10:36:55 +00008595'``trunc .. to``' Instruction
8596^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8597
8598Syntax:
8599"""""""
8600
8601::
8602
8603 <result> = trunc <ty> <value> to <ty2> ; yields ty2
8604
8605Overview:
8606"""""""""
8607
8608The '``trunc``' instruction truncates its operand to the type ``ty2``.
8609
8610Arguments:
8611""""""""""
8612
8613The '``trunc``' instruction takes a value to trunc, and a type to trunc
8614it to. Both types must be of :ref:`integer <t_integer>` types, or vectors
8615of the same number of integers. The bit size of the ``value`` must be
8616larger than the bit size of the destination type, ``ty2``. Equal sized
8617types are not allowed.
8618
8619Semantics:
8620""""""""""
8621
8622The '``trunc``' instruction truncates the high order bits in ``value``
8623and converts the remaining bits to ``ty2``. Since the source size must
8624be larger than the destination size, ``trunc`` cannot be a *no-op cast*.
8625It will always truncate bits.
8626
8627Example:
8628""""""""
8629
8630.. code-block:: llvm
8631
8632 %X = trunc i32 257 to i8 ; yields i8:1
8633 %Y = trunc i32 123 to i1 ; yields i1:true
8634 %Z = trunc i32 122 to i1 ; yields i1:false
8635 %W = trunc <2 x i16> <i16 8, i16 7> to <2 x i8> ; yields <i8 8, i8 7>
8636
Bjorn Petterssone1285e32017-10-24 11:59:20 +00008637.. _i_zext:
8638
Sean Silvab084af42012-12-07 10:36:55 +00008639'``zext .. to``' Instruction
8640^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8641
8642Syntax:
8643"""""""
8644
8645::
8646
8647 <result> = zext <ty> <value> to <ty2> ; yields ty2
8648
8649Overview:
8650"""""""""
8651
8652The '``zext``' instruction zero extends its operand to type ``ty2``.
8653
8654Arguments:
8655""""""""""
8656
8657The '``zext``' instruction takes a value to cast, and a type to cast it
8658to. Both types must be of :ref:`integer <t_integer>` types, or vectors of
8659the same number of integers. The bit size of the ``value`` must be
8660smaller than the bit size of the destination type, ``ty2``.
8661
8662Semantics:
8663""""""""""
8664
8665The ``zext`` fills the high order bits of the ``value`` with zero bits
8666until it reaches the size of the destination type, ``ty2``.
8667
8668When zero extending from i1, the result will always be either 0 or 1.
8669
8670Example:
8671""""""""
8672
8673.. code-block:: llvm
8674
8675 %X = zext i32 257 to i64 ; yields i64:257
8676 %Y = zext i1 true to i32 ; yields i32:1
8677 %Z = zext <2 x i16> <i16 8, i16 7> to <2 x i32> ; yields <i32 8, i32 7>
8678
Bjorn Petterssone1285e32017-10-24 11:59:20 +00008679.. _i_sext:
8680
Sean Silvab084af42012-12-07 10:36:55 +00008681'``sext .. to``' Instruction
8682^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8683
8684Syntax:
8685"""""""
8686
8687::
8688
8689 <result> = sext <ty> <value> to <ty2> ; yields ty2
8690
8691Overview:
8692"""""""""
8693
8694The '``sext``' sign extends ``value`` to the type ``ty2``.
8695
8696Arguments:
8697""""""""""
8698
8699The '``sext``' instruction takes a value to cast, and a type to cast it
8700to. Both types must be of :ref:`integer <t_integer>` types, or vectors of
8701the same number of integers. The bit size of the ``value`` must be
8702smaller than the bit size of the destination type, ``ty2``.
8703
8704Semantics:
8705""""""""""
8706
8707The '``sext``' instruction performs a sign extension by copying the sign
8708bit (highest order bit) of the ``value`` until it reaches the bit size
8709of the type ``ty2``.
8710
8711When sign extending from i1, the extension always results in -1 or 0.
8712
8713Example:
8714""""""""
8715
8716.. code-block:: llvm
8717
8718 %X = sext i8 -1 to i16 ; yields i16 :65535
8719 %Y = sext i1 true to i32 ; yields i32:-1
8720 %Z = sext <2 x i16> <i16 8, i16 7> to <2 x i32> ; yields <i32 8, i32 7>
8721
8722'``fptrunc .. to``' Instruction
8723^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8724
8725Syntax:
8726"""""""
8727
8728::
8729
8730 <result> = fptrunc <ty> <value> to <ty2> ; yields ty2
8731
8732Overview:
8733"""""""""
8734
8735The '``fptrunc``' instruction truncates ``value`` to type ``ty2``.
8736
8737Arguments:
8738""""""""""
8739
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00008740The '``fptrunc``' instruction takes a :ref:`floating-point <t_floating>`
8741value to cast and a :ref:`floating-point <t_floating>` type to cast it to.
Sean Silvab084af42012-12-07 10:36:55 +00008742The size of ``value`` must be larger than the size of ``ty2``. This
8743implies that ``fptrunc`` cannot be used to make a *no-op cast*.
8744
8745Semantics:
8746""""""""""
8747
Dan Liew50456fb2015-09-03 18:43:56 +00008748The '``fptrunc``' instruction casts a ``value`` from a larger
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00008749:ref:`floating-point <t_floating>` type to a smaller :ref:`floating-point
Sanjay Pateld96a3632018-04-03 13:05:20 +00008750<t_floating>` type.
8751This instruction is assumed to execute in the default :ref:`floating-point
8752environment <floatenv>`.
Sean Silvab084af42012-12-07 10:36:55 +00008753
8754Example:
8755""""""""
8756
8757.. code-block:: llvm
8758
Sanjay Pateld96a3632018-04-03 13:05:20 +00008759 %X = fptrunc double 16777217.0 to float ; yields float:16777216.0
8760 %Y = fptrunc double 1.0E+300 to half ; yields half:+infinity
Sean Silvab084af42012-12-07 10:36:55 +00008761
8762'``fpext .. to``' Instruction
8763^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8764
8765Syntax:
8766"""""""
8767
8768::
8769
8770 <result> = fpext <ty> <value> to <ty2> ; yields ty2
8771
8772Overview:
8773"""""""""
8774
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00008775The '``fpext``' extends a floating-point ``value`` to a larger floating-point
8776value.
Sean Silvab084af42012-12-07 10:36:55 +00008777
8778Arguments:
8779""""""""""
8780
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00008781The '``fpext``' instruction takes a :ref:`floating-point <t_floating>`
8782``value`` to cast, and a :ref:`floating-point <t_floating>` type to cast it
Sean Silvab084af42012-12-07 10:36:55 +00008783to. The source type must be smaller than the destination type.
8784
8785Semantics:
8786""""""""""
8787
8788The '``fpext``' instruction extends the ``value`` from a smaller
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00008789:ref:`floating-point <t_floating>` type to a larger :ref:`floating-point
8790<t_floating>` type. The ``fpext`` cannot be used to make a
Sean Silvab084af42012-12-07 10:36:55 +00008791*no-op cast* because it always changes bits. Use ``bitcast`` to make a
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00008792*no-op cast* for a floating-point cast.
Sean Silvab084af42012-12-07 10:36:55 +00008793
8794Example:
8795""""""""
8796
8797.. code-block:: llvm
8798
8799 %X = fpext float 3.125 to double ; yields double:3.125000e+00
8800 %Y = fpext double %X to fp128 ; yields fp128:0xL00000000000000004000900000000000
8801
8802'``fptoui .. to``' Instruction
8803^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8804
8805Syntax:
8806"""""""
8807
8808::
8809
8810 <result> = fptoui <ty> <value> to <ty2> ; yields ty2
8811
8812Overview:
8813"""""""""
8814
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00008815The '``fptoui``' converts a floating-point ``value`` to its unsigned
Sean Silvab084af42012-12-07 10:36:55 +00008816integer equivalent of type ``ty2``.
8817
8818Arguments:
8819""""""""""
8820
8821The '``fptoui``' instruction takes a value to cast, which must be a
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00008822scalar or vector :ref:`floating-point <t_floating>` value, and a type to
Sean Silvab084af42012-12-07 10:36:55 +00008823cast it to ``ty2``, which must be an :ref:`integer <t_integer>` type. If
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00008824``ty`` is a vector floating-point type, ``ty2`` must be a vector integer
Sean Silvab084af42012-12-07 10:36:55 +00008825type with the same number of elements as ``ty``
8826
8827Semantics:
8828""""""""""
8829
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00008830The '``fptoui``' instruction converts its :ref:`floating-point
8831<t_floating>` operand into the nearest (rounding towards zero)
Eli Friedmanc065bb22018-06-08 21:33:33 +00008832unsigned integer value. If the value cannot fit in ``ty2``, the result
8833is a :ref:`poison value <poisonvalues>`.
Sean Silvab084af42012-12-07 10:36:55 +00008834
8835Example:
8836""""""""
8837
8838.. code-block:: llvm
8839
8840 %X = fptoui double 123.0 to i32 ; yields i32:123
8841 %Y = fptoui float 1.0E+300 to i1 ; yields undefined:1
8842 %Z = fptoui float 1.04E+17 to i8 ; yields undefined:1
8843
8844'``fptosi .. to``' Instruction
8845^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8846
8847Syntax:
8848"""""""
8849
8850::
8851
8852 <result> = fptosi <ty> <value> to <ty2> ; yields ty2
8853
8854Overview:
8855"""""""""
8856
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00008857The '``fptosi``' instruction converts :ref:`floating-point <t_floating>`
Sean Silvab084af42012-12-07 10:36:55 +00008858``value`` to type ``ty2``.
8859
8860Arguments:
8861""""""""""
8862
8863The '``fptosi``' instruction takes a value to cast, which must be a
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00008864scalar or vector :ref:`floating-point <t_floating>` value, and a type to
Sean Silvab084af42012-12-07 10:36:55 +00008865cast it to ``ty2``, which must be an :ref:`integer <t_integer>` type. If
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00008866``ty`` is a vector floating-point type, ``ty2`` must be a vector integer
Sean Silvab084af42012-12-07 10:36:55 +00008867type with the same number of elements as ``ty``
8868
8869Semantics:
8870""""""""""
8871
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00008872The '``fptosi``' instruction converts its :ref:`floating-point
8873<t_floating>` operand into the nearest (rounding towards zero)
Eli Friedmanc065bb22018-06-08 21:33:33 +00008874signed integer value. If the value cannot fit in ``ty2``, the result
8875is a :ref:`poison value <poisonvalues>`.
Sean Silvab084af42012-12-07 10:36:55 +00008876
8877Example:
8878""""""""
8879
8880.. code-block:: llvm
8881
8882 %X = fptosi double -123.0 to i32 ; yields i32:-123
8883 %Y = fptosi float 1.0E-247 to i1 ; yields undefined:1
8884 %Z = fptosi float 1.04E+17 to i8 ; yields undefined:1
8885
8886'``uitofp .. to``' Instruction
8887^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8888
8889Syntax:
8890"""""""
8891
8892::
8893
8894 <result> = uitofp <ty> <value> to <ty2> ; yields ty2
8895
8896Overview:
8897"""""""""
8898
8899The '``uitofp``' instruction regards ``value`` as an unsigned integer
8900and converts that value to the ``ty2`` type.
8901
8902Arguments:
8903""""""""""
8904
8905The '``uitofp``' instruction takes a value to cast, which must be a
8906scalar or vector :ref:`integer <t_integer>` value, and a type to cast it to
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00008907``ty2``, which must be an :ref:`floating-point <t_floating>` type. If
8908``ty`` is a vector integer type, ``ty2`` must be a vector floating-point
Sean Silvab084af42012-12-07 10:36:55 +00008909type with the same number of elements as ``ty``
8910
8911Semantics:
8912""""""""""
8913
8914The '``uitofp``' instruction interprets its operand as an unsigned
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00008915integer quantity and converts it to the corresponding floating-point
Eli Friedman3f1ce092018-06-14 22:58:48 +00008916value. If the value cannot be exactly represented, it is rounded using
8917the default rounding mode.
8918
Sean Silvab084af42012-12-07 10:36:55 +00008919
8920Example:
8921""""""""
8922
8923.. code-block:: llvm
8924
8925 %X = uitofp i32 257 to float ; yields float:257.0
8926 %Y = uitofp i8 -1 to double ; yields double:255.0
8927
8928'``sitofp .. to``' Instruction
8929^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8930
8931Syntax:
8932"""""""
8933
8934::
8935
8936 <result> = sitofp <ty> <value> to <ty2> ; yields ty2
8937
8938Overview:
8939"""""""""
8940
8941The '``sitofp``' instruction regards ``value`` as a signed integer and
8942converts that value to the ``ty2`` type.
8943
8944Arguments:
8945""""""""""
8946
8947The '``sitofp``' instruction takes a value to cast, which must be a
8948scalar or vector :ref:`integer <t_integer>` value, and a type to cast it to
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00008949``ty2``, which must be an :ref:`floating-point <t_floating>` type. If
8950``ty`` is a vector integer type, ``ty2`` must be a vector floating-point
Sean Silvab084af42012-12-07 10:36:55 +00008951type with the same number of elements as ``ty``
8952
8953Semantics:
8954""""""""""
8955
8956The '``sitofp``' instruction interprets its operand as a signed integer
Eli Friedman3f1ce092018-06-14 22:58:48 +00008957quantity and converts it to the corresponding floating-point value. If the
8958value cannot be exactly represented, it is rounded using the default rounding
8959mode.
Sean Silvab084af42012-12-07 10:36:55 +00008960
8961Example:
8962""""""""
8963
8964.. code-block:: llvm
8965
8966 %X = sitofp i32 257 to float ; yields float:257.0
8967 %Y = sitofp i8 -1 to double ; yields double:-1.0
8968
8969.. _i_ptrtoint:
8970
8971'``ptrtoint .. to``' Instruction
8972^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8973
8974Syntax:
8975"""""""
8976
8977::
8978
8979 <result> = ptrtoint <ty> <value> to <ty2> ; yields ty2
8980
8981Overview:
8982"""""""""
8983
8984The '``ptrtoint``' instruction converts the pointer or a vector of
8985pointers ``value`` to the integer (or vector of integers) type ``ty2``.
8986
8987Arguments:
8988""""""""""
8989
8990The '``ptrtoint``' instruction takes a ``value`` to cast, which must be
Ed Maste8ed40ce2015-04-14 20:52:58 +00008991a value of type :ref:`pointer <t_pointer>` or a vector of pointers, and a
Sean Silvab084af42012-12-07 10:36:55 +00008992type to cast it to ``ty2``, which must be an :ref:`integer <t_integer>` or
8993a vector of integers type.
8994
8995Semantics:
8996""""""""""
8997
8998The '``ptrtoint``' instruction converts ``value`` to integer type
8999``ty2`` by interpreting the pointer value as an integer and either
9000truncating or zero extending that value to the size of the integer type.
9001If ``value`` is smaller than ``ty2`` then a zero extension is done. If
9002``value`` is larger than ``ty2`` then a truncation is done. If they are
9003the same size, then nothing is done (*no-op cast*) other than a type
9004change.
9005
9006Example:
9007""""""""
9008
9009.. code-block:: llvm
9010
9011 %X = ptrtoint i32* %P to i8 ; yields truncation on 32-bit architecture
9012 %Y = ptrtoint i32* %P to i64 ; yields zero extension on 32-bit architecture
9013 %Z = ptrtoint <4 x i32*> %P to <4 x i64>; yields vector zero extension for a vector of addresses on 32-bit architecture
9014
9015.. _i_inttoptr:
9016
9017'``inttoptr .. to``' Instruction
9018^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9019
9020Syntax:
9021"""""""
9022
9023::
9024
9025 <result> = inttoptr <ty> <value> to <ty2> ; yields ty2
9026
9027Overview:
9028"""""""""
9029
9030The '``inttoptr``' instruction converts an integer ``value`` to a
9031pointer type, ``ty2``.
9032
9033Arguments:
9034""""""""""
9035
9036The '``inttoptr``' instruction takes an :ref:`integer <t_integer>` value to
9037cast, and a type to cast it to, which must be a :ref:`pointer <t_pointer>`
9038type.
9039
9040Semantics:
9041""""""""""
9042
9043The '``inttoptr``' instruction converts ``value`` to type ``ty2`` by
9044applying either a zero extension or a truncation depending on the size
9045of the integer ``value``. If ``value`` is larger than the size of a
9046pointer then a truncation is done. If ``value`` is smaller than the size
9047of a pointer then a zero extension is done. If they are the same size,
9048nothing is done (*no-op cast*).
9049
9050Example:
9051""""""""
9052
9053.. code-block:: llvm
9054
9055 %X = inttoptr i32 255 to i32* ; yields zero extension on 64-bit architecture
9056 %Y = inttoptr i32 255 to i32* ; yields no-op on 32-bit architecture
9057 %Z = inttoptr i64 0 to i32* ; yields truncation on 32-bit architecture
9058 %Z = inttoptr <4 x i32> %G to <4 x i8*>; yields truncation of vector G to four pointers
9059
9060.. _i_bitcast:
9061
9062'``bitcast .. to``' Instruction
9063^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9064
9065Syntax:
9066"""""""
9067
9068::
9069
9070 <result> = bitcast <ty> <value> to <ty2> ; yields ty2
9071
9072Overview:
9073"""""""""
9074
9075The '``bitcast``' instruction converts ``value`` to type ``ty2`` without
9076changing any bits.
9077
9078Arguments:
9079""""""""""
9080
9081The '``bitcast``' instruction takes a value to cast, which must be a
9082non-aggregate first class value, and a type to cast it to, which must
Matt Arsenault24b49c42013-07-31 17:49:08 +00009083also be a non-aggregate :ref:`first class <t_firstclass>` type. The
9084bit sizes of ``value`` and the destination type, ``ty2``, must be
Sean Silvaa1190322015-08-06 22:56:48 +00009085identical. If the source type is a pointer, the destination type must
Matt Arsenault24b49c42013-07-31 17:49:08 +00009086also be a pointer of the same size. This instruction supports bitwise
9087conversion of vectors to integers and to vectors of other types (as
9088long as they have the same size).
Sean Silvab084af42012-12-07 10:36:55 +00009089
9090Semantics:
9091""""""""""
9092
Matt Arsenault24b49c42013-07-31 17:49:08 +00009093The '``bitcast``' instruction converts ``value`` to type ``ty2``. It
9094is always a *no-op cast* because no bits change with this
9095conversion. The conversion is done as if the ``value`` had been stored
9096to memory and read back as type ``ty2``. Pointer (or vector of
9097pointers) types may only be converted to other pointer (or vector of
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00009098pointers) types with the same address space through this instruction.
9099To convert pointers to other types, use the :ref:`inttoptr <i_inttoptr>`
9100or :ref:`ptrtoint <i_ptrtoint>` instructions first.
Sean Silvab084af42012-12-07 10:36:55 +00009101
9102Example:
9103""""""""
9104
Renato Golin124f2592016-07-20 12:16:38 +00009105.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00009106
9107 %X = bitcast i8 255 to i8 ; yields i8 :-1
9108 %Y = bitcast i32* %x to sint* ; yields sint*:%x
9109 %Z = bitcast <2 x int> %V to i64; ; yields i64: %V
9110 %Z = bitcast <2 x i32*> %V to <2 x i64*> ; yields <2 x i64*>
9111
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00009112.. _i_addrspacecast:
9113
9114'``addrspacecast .. to``' Instruction
9115^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9116
9117Syntax:
9118"""""""
9119
9120::
9121
9122 <result> = addrspacecast <pty> <ptrval> to <pty2> ; yields pty2
9123
9124Overview:
9125"""""""""
9126
9127The '``addrspacecast``' instruction converts ``ptrval`` from ``pty`` in
9128address space ``n`` to type ``pty2`` in address space ``m``.
9129
9130Arguments:
9131""""""""""
9132
9133The '``addrspacecast``' instruction takes a pointer or vector of pointer value
9134to cast and a pointer type to cast it to, which must have a different
9135address space.
9136
9137Semantics:
9138""""""""""
9139
9140The '``addrspacecast``' instruction converts the pointer value
9141``ptrval`` to type ``pty2``. It can be a *no-op cast* or a complex
Matt Arsenault54a2a172013-11-15 05:44:56 +00009142value modification, depending on the target and the address space
9143pair. Pointer conversions within the same address space must be
9144performed with the ``bitcast`` instruction. Note that if the address space
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00009145conversion is legal then both result and operand refer to the same memory
9146location.
9147
9148Example:
9149""""""""
9150
9151.. code-block:: llvm
9152
Matt Arsenault9c13dd02013-11-15 22:43:50 +00009153 %X = addrspacecast i32* %x to i32 addrspace(1)* ; yields i32 addrspace(1)*:%x
9154 %Y = addrspacecast i32 addrspace(1)* %y to i64 addrspace(2)* ; yields i64 addrspace(2)*:%y
9155 %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 +00009156
Sean Silvab084af42012-12-07 10:36:55 +00009157.. _otherops:
9158
9159Other Operations
9160----------------
9161
9162The instructions in this category are the "miscellaneous" instructions,
9163which defy better classification.
9164
9165.. _i_icmp:
9166
9167'``icmp``' Instruction
9168^^^^^^^^^^^^^^^^^^^^^^
9169
9170Syntax:
9171"""""""
9172
9173::
9174
Tim Northover675a0962014-06-13 14:24:23 +00009175 <result> = icmp <cond> <ty> <op1>, <op2> ; yields i1 or <N x i1>:result
Sean Silvab084af42012-12-07 10:36:55 +00009176
9177Overview:
9178"""""""""
9179
9180The '``icmp``' instruction returns a boolean value or a vector of
9181boolean values based on comparison of its two integer, integer vector,
9182pointer, or pointer vector operands.
9183
9184Arguments:
9185""""""""""
9186
9187The '``icmp``' instruction takes three operands. The first operand is
9188the condition code indicating the kind of comparison to perform. It is
Sanjay Patel43d41442016-03-30 21:38:20 +00009189not a value, just a keyword. The possible condition codes are:
Sean Silvab084af42012-12-07 10:36:55 +00009190
9191#. ``eq``: equal
9192#. ``ne``: not equal
9193#. ``ugt``: unsigned greater than
9194#. ``uge``: unsigned greater or equal
9195#. ``ult``: unsigned less than
9196#. ``ule``: unsigned less or equal
9197#. ``sgt``: signed greater than
9198#. ``sge``: signed greater or equal
9199#. ``slt``: signed less than
9200#. ``sle``: signed less or equal
9201
9202The remaining two arguments must be :ref:`integer <t_integer>` or
9203:ref:`pointer <t_pointer>` or integer :ref:`vector <t_vector>` typed. They
9204must also be identical types.
9205
9206Semantics:
9207""""""""""
9208
9209The '``icmp``' compares ``op1`` and ``op2`` according to the condition
9210code given as ``cond``. The comparison performed always yields either an
9211:ref:`i1 <t_integer>` or vector of ``i1`` result, as follows:
9212
9213#. ``eq``: yields ``true`` if the operands are equal, ``false``
9214 otherwise. No sign interpretation is necessary or performed.
9215#. ``ne``: yields ``true`` if the operands are unequal, ``false``
9216 otherwise. No sign interpretation is necessary or performed.
9217#. ``ugt``: interprets the operands as unsigned values and yields
9218 ``true`` if ``op1`` is greater than ``op2``.
9219#. ``uge``: interprets the operands as unsigned values and yields
9220 ``true`` if ``op1`` is greater than or equal to ``op2``.
9221#. ``ult``: interprets the operands as unsigned values and yields
9222 ``true`` if ``op1`` is less than ``op2``.
9223#. ``ule``: interprets the operands as unsigned values and yields
9224 ``true`` if ``op1`` is less than or equal to ``op2``.
9225#. ``sgt``: interprets the operands as signed values and yields ``true``
9226 if ``op1`` is greater than ``op2``.
9227#. ``sge``: interprets the operands as signed values and yields ``true``
9228 if ``op1`` is greater than or equal to ``op2``.
9229#. ``slt``: interprets the operands as signed values and yields ``true``
9230 if ``op1`` is less than ``op2``.
9231#. ``sle``: interprets the operands as signed values and yields ``true``
9232 if ``op1`` is less than or equal to ``op2``.
9233
9234If the operands are :ref:`pointer <t_pointer>` typed, the pointer values
9235are compared as if they were integers.
9236
9237If the operands are integer vectors, then they are compared element by
9238element. The result is an ``i1`` vector with the same number of elements
9239as the values being compared. Otherwise, the result is an ``i1``.
9240
9241Example:
9242""""""""
9243
Renato Golin124f2592016-07-20 12:16:38 +00009244.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00009245
9246 <result> = icmp eq i32 4, 5 ; yields: result=false
9247 <result> = icmp ne float* %X, %X ; yields: result=false
9248 <result> = icmp ult i16 4, 5 ; yields: result=true
9249 <result> = icmp sgt i16 4, 5 ; yields: result=false
9250 <result> = icmp ule i16 -4, 5 ; yields: result=false
9251 <result> = icmp sge i16 4, 5 ; yields: result=false
9252
Sean Silvab084af42012-12-07 10:36:55 +00009253.. _i_fcmp:
9254
9255'``fcmp``' Instruction
9256^^^^^^^^^^^^^^^^^^^^^^
9257
9258Syntax:
9259"""""""
9260
9261::
9262
James Molloy88eb5352015-07-10 12:52:00 +00009263 <result> = fcmp [fast-math flags]* <cond> <ty> <op1>, <op2> ; yields i1 or <N x i1>:result
Sean Silvab084af42012-12-07 10:36:55 +00009264
9265Overview:
9266"""""""""
9267
9268The '``fcmp``' instruction returns a boolean value or vector of boolean
9269values based on comparison of its operands.
9270
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00009271If the operands are floating-point scalars, then the result type is a
Sean Silvab084af42012-12-07 10:36:55 +00009272boolean (:ref:`i1 <t_integer>`).
9273
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00009274If the operands are floating-point vectors, then the result type is a
Sean Silvab084af42012-12-07 10:36:55 +00009275vector of boolean with the same number of elements as the operands being
9276compared.
9277
9278Arguments:
9279""""""""""
9280
9281The '``fcmp``' instruction takes three operands. The first operand is
9282the condition code indicating the kind of comparison to perform. It is
Sanjay Patel43d41442016-03-30 21:38:20 +00009283not a value, just a keyword. The possible condition codes are:
Sean Silvab084af42012-12-07 10:36:55 +00009284
9285#. ``false``: no comparison, always returns false
9286#. ``oeq``: ordered and equal
9287#. ``ogt``: ordered and greater than
9288#. ``oge``: ordered and greater than or equal
9289#. ``olt``: ordered and less than
9290#. ``ole``: ordered and less than or equal
9291#. ``one``: ordered and not equal
9292#. ``ord``: ordered (no nans)
9293#. ``ueq``: unordered or equal
9294#. ``ugt``: unordered or greater than
9295#. ``uge``: unordered or greater than or equal
9296#. ``ult``: unordered or less than
9297#. ``ule``: unordered or less than or equal
9298#. ``une``: unordered or not equal
9299#. ``uno``: unordered (either nans)
9300#. ``true``: no comparison, always returns true
9301
9302*Ordered* means that neither operand is a QNAN while *unordered* means
9303that either operand may be a QNAN.
9304
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00009305Each of ``val1`` and ``val2`` arguments must be either a :ref:`floating-point
9306<t_floating>` type or a :ref:`vector <t_vector>` of floating-point type.
9307They must have identical types.
Sean Silvab084af42012-12-07 10:36:55 +00009308
9309Semantics:
9310""""""""""
9311
9312The '``fcmp``' instruction compares ``op1`` and ``op2`` according to the
9313condition code given as ``cond``. If the operands are vectors, then the
9314vectors are compared element by element. Each comparison performed
9315always yields an :ref:`i1 <t_integer>` result, as follows:
9316
9317#. ``false``: always yields ``false``, regardless of operands.
9318#. ``oeq``: yields ``true`` if both operands are not a QNAN and ``op1``
9319 is equal to ``op2``.
9320#. ``ogt``: yields ``true`` if both operands are not a QNAN and ``op1``
9321 is greater than ``op2``.
9322#. ``oge``: yields ``true`` if both operands are not a QNAN and ``op1``
9323 is greater than or equal to ``op2``.
9324#. ``olt``: yields ``true`` if both operands are not a QNAN and ``op1``
9325 is less than ``op2``.
9326#. ``ole``: yields ``true`` if both operands are not a QNAN and ``op1``
9327 is less than or equal to ``op2``.
9328#. ``one``: yields ``true`` if both operands are not a QNAN and ``op1``
9329 is not equal to ``op2``.
9330#. ``ord``: yields ``true`` if both operands are not a QNAN.
9331#. ``ueq``: yields ``true`` if either operand is a QNAN or ``op1`` is
9332 equal to ``op2``.
9333#. ``ugt``: yields ``true`` if either operand is a QNAN or ``op1`` is
9334 greater than ``op2``.
9335#. ``uge``: yields ``true`` if either operand is a QNAN or ``op1`` is
9336 greater than or equal to ``op2``.
9337#. ``ult``: yields ``true`` if either operand is a QNAN or ``op1`` is
9338 less than ``op2``.
9339#. ``ule``: yields ``true`` if either operand is a QNAN or ``op1`` is
9340 less than or equal to ``op2``.
9341#. ``une``: yields ``true`` if either operand is a QNAN or ``op1`` is
9342 not equal to ``op2``.
9343#. ``uno``: yields ``true`` if either operand is a QNAN.
9344#. ``true``: always yields ``true``, regardless of operands.
9345
James Molloy88eb5352015-07-10 12:52:00 +00009346The ``fcmp`` instruction can also optionally take any number of
9347:ref:`fast-math flags <fastmath>`, which are optimization hints to enable
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00009348otherwise unsafe floating-point optimizations.
James Molloy88eb5352015-07-10 12:52:00 +00009349
9350Any set of fast-math flags are legal on an ``fcmp`` instruction, but the
9351only flags that have any effect on its semantics are those that allow
9352assumptions to be made about the values of input arguments; namely
Eli Friedman8bb43262018-07-17 20:28:31 +00009353``nnan``, ``ninf``, and ``reassoc``. See :ref:`fastmath` for more information.
James Molloy88eb5352015-07-10 12:52:00 +00009354
Sean Silvab084af42012-12-07 10:36:55 +00009355Example:
9356""""""""
9357
Renato Golin124f2592016-07-20 12:16:38 +00009358.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00009359
9360 <result> = fcmp oeq float 4.0, 5.0 ; yields: result=false
9361 <result> = fcmp one float 4.0, 5.0 ; yields: result=true
9362 <result> = fcmp olt float 4.0, 5.0 ; yields: result=true
9363 <result> = fcmp ueq double 1.0, 2.0 ; yields: result=false
9364
Sean Silvab084af42012-12-07 10:36:55 +00009365.. _i_phi:
9366
9367'``phi``' Instruction
9368^^^^^^^^^^^^^^^^^^^^^
9369
9370Syntax:
9371"""""""
9372
9373::
9374
9375 <result> = phi <ty> [ <val0>, <label0>], ...
9376
9377Overview:
9378"""""""""
9379
9380The '``phi``' instruction is used to implement the φ node in the SSA
9381graph representing the function.
9382
9383Arguments:
9384""""""""""
9385
9386The type of the incoming values is specified with the first type field.
9387After this, the '``phi``' instruction takes a list of pairs as
9388arguments, with one pair for each predecessor basic block of the current
9389block. Only values of :ref:`first class <t_firstclass>` type may be used as
9390the value arguments to the PHI node. Only labels may be used as the
9391label arguments.
9392
9393There must be no non-phi instructions between the start of a basic block
9394and the PHI instructions: i.e. PHI instructions must be first in a basic
9395block.
9396
9397For the purposes of the SSA form, the use of each incoming value is
9398deemed to occur on the edge from the corresponding predecessor block to
9399the current block (but after any definition of an '``invoke``'
9400instruction's return value on the same edge).
9401
9402Semantics:
9403""""""""""
9404
9405At runtime, the '``phi``' instruction logically takes on the value
9406specified by the pair corresponding to the predecessor basic block that
9407executed just prior to the current block.
9408
9409Example:
9410""""""""
9411
9412.. code-block:: llvm
9413
9414 Loop: ; Infinite loop that counts from 0 on up...
9415 %indvar = phi i32 [ 0, %LoopHeader ], [ %nextindvar, %Loop ]
9416 %nextindvar = add i32 %indvar, 1
9417 br label %Loop
9418
9419.. _i_select:
9420
9421'``select``' Instruction
9422^^^^^^^^^^^^^^^^^^^^^^^^
9423
9424Syntax:
9425"""""""
9426
9427::
9428
9429 <result> = select selty <cond>, <ty> <val1>, <ty> <val2> ; yields ty
9430
9431 selty is either i1 or {<N x i1>}
9432
9433Overview:
9434"""""""""
9435
9436The '``select``' instruction is used to choose one value based on a
Joerg Sonnenberger94321ec2014-03-26 15:30:21 +00009437condition, without IR-level branching.
Sean Silvab084af42012-12-07 10:36:55 +00009438
9439Arguments:
9440""""""""""
9441
9442The '``select``' instruction requires an 'i1' value or a vector of 'i1'
9443values indicating the condition, and two values of the same :ref:`first
David Majnemer40a0b592015-03-03 22:45:47 +00009444class <t_firstclass>` type.
Sean Silvab084af42012-12-07 10:36:55 +00009445
9446Semantics:
9447""""""""""
9448
9449If the condition is an i1 and it evaluates to 1, the instruction returns
9450the first value argument; otherwise, it returns the second value
9451argument.
9452
9453If the condition is a vector of i1, then the value arguments must be
9454vectors of the same size, and the selection is done element by element.
9455
David Majnemer40a0b592015-03-03 22:45:47 +00009456If the condition is an i1 and the value arguments are vectors of the
9457same size, then an entire vector is selected.
9458
Sean Silvab084af42012-12-07 10:36:55 +00009459Example:
9460""""""""
9461
9462.. code-block:: llvm
9463
9464 %X = select i1 true, i8 17, i8 42 ; yields i8:17
9465
9466.. _i_call:
9467
9468'``call``' Instruction
9469^^^^^^^^^^^^^^^^^^^^^^
9470
9471Syntax:
9472"""""""
9473
9474::
9475
David Blaikieb83cf102016-07-13 17:21:34 +00009476 <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 +00009477 [ operand bundles ]
Sean Silvab084af42012-12-07 10:36:55 +00009478
9479Overview:
9480"""""""""
9481
9482The '``call``' instruction represents a simple function call.
9483
9484Arguments:
9485""""""""""
9486
9487This instruction requires several arguments:
9488
Reid Kleckner5772b772014-04-24 20:14:34 +00009489#. The optional ``tail`` and ``musttail`` markers indicate that the optimizers
Sean Silvaa1190322015-08-06 22:56:48 +00009490 should perform tail call optimization. The ``tail`` marker is a hint that
9491 `can be ignored <CodeGenerator.html#sibcallopt>`_. The ``musttail`` marker
Reid Kleckner5772b772014-04-24 20:14:34 +00009492 means that the call must be tail call optimized in order for the program to
Sean Silvaa1190322015-08-06 22:56:48 +00009493 be correct. The ``musttail`` marker provides these guarantees:
Reid Kleckner5772b772014-04-24 20:14:34 +00009494
9495 #. The call will not cause unbounded stack growth if it is part of a
9496 recursive cycle in the call graph.
9497 #. Arguments with the :ref:`inalloca <attr_inalloca>` attribute are
9498 forwarded in place.
9499
Florian Hahnedae5a62018-01-17 23:29:25 +00009500 Both markers imply that the callee does not access allocas from the caller.
9501 The ``tail`` marker additionally implies that the callee does not access
9502 varargs from the caller, while ``musttail`` implies that varargs from the
9503 caller are passed to the callee. Calls marked ``musttail`` must obey the
9504 following additional rules:
Reid Kleckner5772b772014-04-24 20:14:34 +00009505
9506 - The call must immediately precede a :ref:`ret <i_ret>` instruction,
9507 or a pointer bitcast followed by a ret instruction.
9508 - The ret instruction must return the (possibly bitcasted) value
9509 produced by the call or void.
Sean Silvaa1190322015-08-06 22:56:48 +00009510 - The caller and callee prototypes must match. Pointer types of
Reid Kleckner5772b772014-04-24 20:14:34 +00009511 parameters or return types may differ in pointee type, but not
9512 in address space.
9513 - The calling conventions of the caller and callee must match.
9514 - All ABI-impacting function attributes, such as sret, byval, inreg,
9515 returned, and inalloca, must match.
Reid Kleckner83498642014-08-26 00:33:28 +00009516 - The callee must be varargs iff the caller is varargs. Bitcasting a
9517 non-varargs function to the appropriate varargs type is legal so
9518 long as the non-varargs prefixes obey the other rules.
Reid Kleckner5772b772014-04-24 20:14:34 +00009519
9520 Tail call optimization for calls marked ``tail`` is guaranteed to occur if
9521 the following conditions are met:
Sean Silvab084af42012-12-07 10:36:55 +00009522
9523 - Caller and callee both have the calling convention ``fastcc``.
9524 - The call is in tail position (ret immediately follows call and ret
9525 uses value of call or is void).
9526 - Option ``-tailcallopt`` is enabled, or
9527 ``llvm::GuaranteedTailCallOpt`` is ``true``.
Alp Tokercf218752014-06-30 18:57:16 +00009528 - `Platform-specific constraints are
Sean Silvab084af42012-12-07 10:36:55 +00009529 met. <CodeGenerator.html#tailcallopt>`_
9530
Akira Hatanaka5cfcce122015-11-06 23:55:38 +00009531#. The optional ``notail`` marker indicates that the optimizers should not add
9532 ``tail`` or ``musttail`` markers to the call. It is used to prevent tail
9533 call optimization from being performed on the call.
9534
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +00009535#. The optional ``fast-math flags`` marker indicates that the call has one or more
Sanjay Patelfa54ace2015-12-14 21:59:03 +00009536 :ref:`fast-math flags <fastmath>`, which are optimization hints to enable
9537 otherwise unsafe floating-point optimizations. Fast-math flags are only valid
9538 for calls that return a floating-point scalar or vector type.
9539
Sean Silvab084af42012-12-07 10:36:55 +00009540#. The optional "cconv" marker indicates which :ref:`calling
9541 convention <callingconv>` the call should use. If none is
9542 specified, the call defaults to using C calling conventions. The
9543 calling convention of the call must match the calling convention of
9544 the target function, or else the behavior is undefined.
9545#. The optional :ref:`Parameter Attributes <paramattrs>` list for return
9546 values. Only '``zeroext``', '``signext``', and '``inreg``' attributes
9547 are valid here.
9548#. '``ty``': the type of the call instruction itself which is also the
9549 type of the return value. Functions that return no value are marked
9550 ``void``.
David Blaikieb83cf102016-07-13 17:21:34 +00009551#. '``fnty``': shall be the signature of the function being called. The
9552 argument types must match the types implied by this signature. This
9553 type can be omitted if the function is not varargs.
Sean Silvab084af42012-12-07 10:36:55 +00009554#. '``fnptrval``': An LLVM value containing a pointer to a function to
David Blaikieb83cf102016-07-13 17:21:34 +00009555 be called. In most cases, this is a direct function call, but
Sean Silvab084af42012-12-07 10:36:55 +00009556 indirect ``call``'s are just as possible, calling an arbitrary pointer
9557 to function value.
9558#. '``function args``': argument list whose types match the function
9559 signature argument types and parameter attributes. All arguments must
9560 be of :ref:`first class <t_firstclass>` type. If the function signature
9561 indicates the function accepts a variable number of arguments, the
9562 extra arguments can be specified.
George Burgess IV39c91052017-04-13 04:01:55 +00009563#. The optional :ref:`function attributes <fnattrs>` list.
Sanjoy Dasb513a9f2015-09-24 23:34:52 +00009564#. The optional :ref:`operand bundles <opbundles>` list.
Sean Silvab084af42012-12-07 10:36:55 +00009565
9566Semantics:
9567""""""""""
9568
9569The '``call``' instruction is used to cause control flow to transfer to
9570a specified function, with its incoming arguments bound to the specified
9571values. Upon a '``ret``' instruction in the called function, control
9572flow continues with the instruction after the function call, and the
9573return value of the function is bound to the result argument.
9574
9575Example:
9576""""""""
9577
9578.. code-block:: llvm
9579
9580 %retval = call i32 @test(i32 %argc)
9581 call i32 (i8*, ...)* @printf(i8* %msg, i32 12, i8 42) ; yields i32
9582 %X = tail call i32 @foo() ; yields i32
9583 %Y = tail call fastcc i32 @foo() ; yields i32
9584 call void %foo(i8 97 signext)
9585
9586 %struct.A = type { i32, i8 }
Tim Northover675a0962014-06-13 14:24:23 +00009587 %r = call %struct.A @foo() ; yields { i32, i8 }
Sean Silvab084af42012-12-07 10:36:55 +00009588 %gr = extractvalue %struct.A %r, 0 ; yields i32
9589 %gr1 = extractvalue %struct.A %r, 1 ; yields i8
9590 %Z = call void @foo() noreturn ; indicates that %foo never returns normally
9591 %ZZ = call zeroext i32 @bar() ; Return value is %zero extended
9592
9593llvm treats calls to some functions with names and arguments that match
9594the standard C99 library as being the C99 library functions, and may
9595perform optimizations or generate code for them under that assumption.
9596This is something we'd like to change in the future to provide better
9597support for freestanding environments and non-C-based languages.
9598
9599.. _i_va_arg:
9600
9601'``va_arg``' Instruction
9602^^^^^^^^^^^^^^^^^^^^^^^^
9603
9604Syntax:
9605"""""""
9606
9607::
9608
9609 <resultval> = va_arg <va_list*> <arglist>, <argty>
9610
9611Overview:
9612"""""""""
9613
9614The '``va_arg``' instruction is used to access arguments passed through
9615the "variable argument" area of a function call. It is used to implement
9616the ``va_arg`` macro in C.
9617
9618Arguments:
9619""""""""""
9620
9621This instruction takes a ``va_list*`` value and the type of the
9622argument. It returns a value of the specified argument type and
9623increments the ``va_list`` to point to the next argument. The actual
9624type of ``va_list`` is target specific.
9625
9626Semantics:
9627""""""""""
9628
9629The '``va_arg``' instruction loads an argument of the specified type
9630from the specified ``va_list`` and causes the ``va_list`` to point to
9631the next argument. For more information, see the variable argument
9632handling :ref:`Intrinsic Functions <int_varargs>`.
9633
9634It is legal for this instruction to be called in a function which does
9635not take a variable number of arguments, for example, the ``vfprintf``
9636function.
9637
9638``va_arg`` is an LLVM instruction instead of an :ref:`intrinsic
9639function <intrinsics>` because it takes a type as an argument.
9640
9641Example:
9642""""""""
9643
9644See the :ref:`variable argument processing <int_varargs>` section.
9645
9646Note that the code generator does not yet fully support va\_arg on many
9647targets. Also, it does not currently support va\_arg with aggregate
9648types on any target.
9649
9650.. _i_landingpad:
9651
9652'``landingpad``' Instruction
9653^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9654
9655Syntax:
9656"""""""
9657
9658::
9659
David Majnemer7fddecc2015-06-17 20:52:32 +00009660 <resultval> = landingpad <resultty> <clause>+
9661 <resultval> = landingpad <resultty> cleanup <clause>*
Sean Silvab084af42012-12-07 10:36:55 +00009662
9663 <clause> := catch <type> <value>
9664 <clause> := filter <array constant type> <array constant>
9665
9666Overview:
9667"""""""""
9668
9669The '``landingpad``' instruction is used by `LLVM's exception handling
9670system <ExceptionHandling.html#overview>`_ to specify that a basic block
Dmitri Gribenkoe8131122013-01-19 20:34:20 +00009671is a landing pad --- one where the exception lands, and corresponds to the
Sean Silvab084af42012-12-07 10:36:55 +00009672code found in the ``catch`` portion of a ``try``/``catch`` sequence. It
David Majnemer7fddecc2015-06-17 20:52:32 +00009673defines values supplied by the :ref:`personality function <personalityfn>` upon
Sean Silvab084af42012-12-07 10:36:55 +00009674re-entry to the function. The ``resultval`` has the type ``resultty``.
9675
9676Arguments:
9677""""""""""
9678
David Majnemer7fddecc2015-06-17 20:52:32 +00009679The optional
Sean Silvab084af42012-12-07 10:36:55 +00009680``cleanup`` flag indicates that the landing pad block is a cleanup.
9681
Dmitri Gribenkoe8131122013-01-19 20:34:20 +00009682A ``clause`` begins with the clause type --- ``catch`` or ``filter`` --- and
Sean Silvab084af42012-12-07 10:36:55 +00009683contains the global variable representing the "type" that may be caught
9684or filtered respectively. Unlike the ``catch`` clause, the ``filter``
9685clause takes an array constant as its argument. Use
9686"``[0 x i8**] undef``" for a filter which cannot throw. The
9687'``landingpad``' instruction must contain *at least* one ``clause`` or
9688the ``cleanup`` flag.
9689
9690Semantics:
9691""""""""""
9692
9693The '``landingpad``' instruction defines the values which are set by the
David Majnemer7fddecc2015-06-17 20:52:32 +00009694:ref:`personality function <personalityfn>` upon re-entry to the function, and
Sean Silvab084af42012-12-07 10:36:55 +00009695therefore the "result type" of the ``landingpad`` instruction. As with
9696calling conventions, how the personality function results are
9697represented in LLVM IR is target specific.
9698
9699The clauses are applied in order from top to bottom. If two
9700``landingpad`` instructions are merged together through inlining, the
9701clauses from the calling function are appended to the list of clauses.
9702When the call stack is being unwound due to an exception being thrown,
9703the exception is compared against each ``clause`` in turn. If it doesn't
9704match any of the clauses, and the ``cleanup`` flag is not set, then
9705unwinding continues further up the call stack.
9706
9707The ``landingpad`` instruction has several restrictions:
9708
9709- A landing pad block is a basic block which is the unwind destination
9710 of an '``invoke``' instruction.
9711- A landing pad block must have a '``landingpad``' instruction as its
9712 first non-PHI instruction.
9713- There can be only one '``landingpad``' instruction within the landing
9714 pad block.
9715- A basic block that is not a landing pad block may not include a
9716 '``landingpad``' instruction.
Sean Silvab084af42012-12-07 10:36:55 +00009717
9718Example:
9719""""""""
9720
9721.. code-block:: llvm
9722
9723 ;; A landing pad which can catch an integer.
David Majnemer7fddecc2015-06-17 20:52:32 +00009724 %res = landingpad { i8*, i32 }
Sean Silvab084af42012-12-07 10:36:55 +00009725 catch i8** @_ZTIi
9726 ;; A landing pad that is a cleanup.
David Majnemer7fddecc2015-06-17 20:52:32 +00009727 %res = landingpad { i8*, i32 }
Sean Silvab084af42012-12-07 10:36:55 +00009728 cleanup
9729 ;; A landing pad which can catch an integer and can only throw a double.
David Majnemer7fddecc2015-06-17 20:52:32 +00009730 %res = landingpad { i8*, i32 }
Sean Silvab084af42012-12-07 10:36:55 +00009731 catch i8** @_ZTIi
9732 filter [1 x i8**] [@_ZTId]
9733
Joseph Tremoulet2adaa982016-01-10 04:46:10 +00009734.. _i_catchpad:
9735
9736'``catchpad``' Instruction
9737^^^^^^^^^^^^^^^^^^^^^^^^^^
9738
9739Syntax:
9740"""""""
9741
9742::
9743
9744 <resultval> = catchpad within <catchswitch> [<args>*]
9745
9746Overview:
9747"""""""""
9748
9749The '``catchpad``' instruction is used by `LLVM's exception handling
9750system <ExceptionHandling.html#overview>`_ to specify that a basic block
9751begins a catch handler --- one where a personality routine attempts to transfer
9752control to catch an exception.
9753
9754Arguments:
9755""""""""""
9756
9757The ``catchswitch`` operand must always be a token produced by a
9758:ref:`catchswitch <i_catchswitch>` instruction in a predecessor block. This
9759ensures that each ``catchpad`` has exactly one predecessor block, and it always
9760terminates in a ``catchswitch``.
9761
9762The ``args`` correspond to whatever information the personality routine
9763requires to know if this is an appropriate handler for the exception. Control
9764will transfer to the ``catchpad`` if this is the first appropriate handler for
9765the exception.
9766
9767The ``resultval`` has the type :ref:`token <t_token>` and is used to match the
9768``catchpad`` to corresponding :ref:`catchrets <i_catchret>` and other nested EH
9769pads.
9770
9771Semantics:
9772""""""""""
9773
9774When the call stack is being unwound due to an exception being thrown, the
9775exception is compared against the ``args``. If it doesn't match, control will
9776not reach the ``catchpad`` instruction. The representation of ``args`` is
9777entirely target and personality function-specific.
9778
9779Like the :ref:`landingpad <i_landingpad>` instruction, the ``catchpad``
9780instruction must be the first non-phi of its parent basic block.
9781
9782The meaning of the tokens produced and consumed by ``catchpad`` and other "pad"
9783instructions is described in the
9784`Windows exception handling documentation\ <ExceptionHandling.html#wineh>`_.
9785
9786When a ``catchpad`` has been "entered" but not yet "exited" (as
9787described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_),
9788it is undefined behavior to execute a :ref:`call <i_call>` or :ref:`invoke <i_invoke>`
9789that does not carry an appropriate :ref:`"funclet" bundle <ob_funclet>`.
9790
9791Example:
9792""""""""
9793
Renato Golin124f2592016-07-20 12:16:38 +00009794.. code-block:: text
Joseph Tremoulet2adaa982016-01-10 04:46:10 +00009795
9796 dispatch:
9797 %cs = catchswitch within none [label %handler0] unwind to caller
9798 ;; A catch block which can catch an integer.
9799 handler0:
9800 %tok = catchpad within %cs [i8** @_ZTIi]
9801
David Majnemer654e1302015-07-31 17:58:14 +00009802.. _i_cleanuppad:
9803
9804'``cleanuppad``' Instruction
9805^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9806
9807Syntax:
9808"""""""
9809
9810::
9811
David Majnemer8a1c45d2015-12-12 05:38:55 +00009812 <resultval> = cleanuppad within <parent> [<args>*]
David Majnemer654e1302015-07-31 17:58:14 +00009813
9814Overview:
9815"""""""""
9816
9817The '``cleanuppad``' instruction is used by `LLVM's exception handling
9818system <ExceptionHandling.html#overview>`_ to specify that a basic block
9819is a cleanup block --- one where a personality routine attempts to
9820transfer control to run cleanup actions.
9821The ``args`` correspond to whatever additional
9822information the :ref:`personality function <personalityfn>` requires to
9823execute the cleanup.
Joseph Tremoulet8220bcc2015-08-23 00:26:33 +00009824The ``resultval`` has the type :ref:`token <t_token>` and is used to
David Majnemer8a1c45d2015-12-12 05:38:55 +00009825match the ``cleanuppad`` to corresponding :ref:`cleanuprets <i_cleanupret>`.
9826The ``parent`` argument is the token of the funclet that contains the
9827``cleanuppad`` instruction. If the ``cleanuppad`` is not inside a funclet,
9828this operand may be the token ``none``.
David Majnemer654e1302015-07-31 17:58:14 +00009829
9830Arguments:
9831""""""""""
9832
9833The instruction takes a list of arbitrary values which are interpreted
9834by the :ref:`personality function <personalityfn>`.
9835
9836Semantics:
9837""""""""""
9838
David Majnemer654e1302015-07-31 17:58:14 +00009839When the call stack is being unwound due to an exception being thrown,
9840the :ref:`personality function <personalityfn>` transfers control to the
9841``cleanuppad`` with the aid of the personality-specific arguments.
Joseph Tremoulet9ce71f72015-09-03 09:09:43 +00009842As with calling conventions, how the personality function results are
9843represented in LLVM IR is target specific.
David Majnemer654e1302015-07-31 17:58:14 +00009844
9845The ``cleanuppad`` instruction has several restrictions:
9846
9847- A cleanup block is a basic block which is the unwind destination of
9848 an exceptional instruction.
9849- A cleanup block must have a '``cleanuppad``' instruction as its
9850 first non-PHI instruction.
9851- There can be only one '``cleanuppad``' instruction within the
9852 cleanup block.
9853- A basic block that is not a cleanup block may not include a
9854 '``cleanuppad``' instruction.
David Majnemer8a1c45d2015-12-12 05:38:55 +00009855
Joseph Tremoulete28885e2016-01-10 04:28:38 +00009856When a ``cleanuppad`` has been "entered" but not yet "exited" (as
9857described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_),
9858it is undefined behavior to execute a :ref:`call <i_call>` or :ref:`invoke <i_invoke>`
9859that does not carry an appropriate :ref:`"funclet" bundle <ob_funclet>`.
David Majnemer8a1c45d2015-12-12 05:38:55 +00009860
David Majnemer654e1302015-07-31 17:58:14 +00009861Example:
9862""""""""
9863
Renato Golin124f2592016-07-20 12:16:38 +00009864.. code-block:: text
David Majnemer654e1302015-07-31 17:58:14 +00009865
David Majnemer8a1c45d2015-12-12 05:38:55 +00009866 %tok = cleanuppad within %cs []
David Majnemer654e1302015-07-31 17:58:14 +00009867
Sean Silvab084af42012-12-07 10:36:55 +00009868.. _intrinsics:
9869
9870Intrinsic Functions
9871===================
9872
9873LLVM supports the notion of an "intrinsic function". These functions
9874have well known names and semantics and are required to follow certain
9875restrictions. Overall, these intrinsics represent an extension mechanism
9876for the LLVM language that does not require changing all of the
9877transformations in LLVM when adding to the language (or the bitcode
9878reader/writer, the parser, etc...).
9879
9880Intrinsic function names must all start with an "``llvm.``" prefix. This
9881prefix is reserved in LLVM for intrinsic names; thus, function names may
9882not begin with this prefix. Intrinsic functions must always be external
9883functions: you cannot define the body of intrinsic functions. Intrinsic
9884functions may only be used in call or invoke instructions: it is illegal
9885to take the address of an intrinsic function. Additionally, because
9886intrinsic functions are part of the LLVM language, it is required if any
9887are added that they be documented here.
9888
9889Some intrinsic functions can be overloaded, i.e., the intrinsic
9890represents a family of functions that perform the same operation but on
9891different data types. Because LLVM can represent over 8 million
9892different integer types, overloading is used commonly to allow an
9893intrinsic function to operate on any integer type. One or more of the
9894argument types or the result type can be overloaded to accept any
9895integer type. Argument types may also be defined as exactly matching a
9896previous argument's type or the result type. This allows an intrinsic
9897function which accepts multiple arguments, but needs all of them to be
9898of the same type, to only be overloaded with respect to a single
9899argument or the result.
9900
9901Overloaded intrinsics will have the names of its overloaded argument
9902types encoded into its function name, each preceded by a period. Only
9903those types which are overloaded result in a name suffix. Arguments
9904whose type is matched against another type do not. For example, the
9905``llvm.ctpop`` function can take an integer of any width and returns an
9906integer of exactly the same integer width. This leads to a family of
9907functions such as ``i8 @llvm.ctpop.i8(i8 %val)`` and
9908``i29 @llvm.ctpop.i29(i29 %val)``. Only one type, the return type, is
9909overloaded, and only one type suffix is required. Because the argument's
9910type is matched against the return type, it does not require its own
9911name suffix.
9912
9913To learn how to add an intrinsic function, please see the `Extending
9914LLVM Guide <ExtendingLLVM.html>`_.
9915
9916.. _int_varargs:
9917
9918Variable Argument Handling Intrinsics
9919-------------------------------------
9920
9921Variable argument support is defined in LLVM with the
9922:ref:`va_arg <i_va_arg>` instruction and these three intrinsic
9923functions. These functions are related to the similarly named macros
9924defined in the ``<stdarg.h>`` header file.
9925
9926All of these functions operate on arguments that use a target-specific
9927value type "``va_list``". The LLVM assembly language reference manual
9928does not define what this type is, so all transformations should be
9929prepared to handle these functions regardless of the type used.
9930
9931This example shows how the :ref:`va_arg <i_va_arg>` instruction and the
9932variable argument handling intrinsic functions are used.
9933
9934.. code-block:: llvm
9935
Tim Northoverab60bb92014-11-02 01:21:51 +00009936 ; This struct is different for every platform. For most platforms,
9937 ; it is merely an i8*.
9938 %struct.va_list = type { i8* }
9939
9940 ; For Unix x86_64 platforms, va_list is the following struct:
9941 ; %struct.va_list = type { i32, i32, i8*, i8* }
9942
Sean Silvab084af42012-12-07 10:36:55 +00009943 define i32 @test(i32 %X, ...) {
9944 ; Initialize variable argument processing
Tim Northoverab60bb92014-11-02 01:21:51 +00009945 %ap = alloca %struct.va_list
9946 %ap2 = bitcast %struct.va_list* %ap to i8*
Sean Silvab084af42012-12-07 10:36:55 +00009947 call void @llvm.va_start(i8* %ap2)
9948
9949 ; Read a single integer argument
Tim Northoverab60bb92014-11-02 01:21:51 +00009950 %tmp = va_arg i8* %ap2, i32
Sean Silvab084af42012-12-07 10:36:55 +00009951
9952 ; Demonstrate usage of llvm.va_copy and llvm.va_end
9953 %aq = alloca i8*
9954 %aq2 = bitcast i8** %aq to i8*
9955 call void @llvm.va_copy(i8* %aq2, i8* %ap2)
9956 call void @llvm.va_end(i8* %aq2)
9957
9958 ; Stop processing of arguments.
9959 call void @llvm.va_end(i8* %ap2)
9960 ret i32 %tmp
9961 }
9962
9963 declare void @llvm.va_start(i8*)
9964 declare void @llvm.va_copy(i8*, i8*)
9965 declare void @llvm.va_end(i8*)
9966
9967.. _int_va_start:
9968
9969'``llvm.va_start``' Intrinsic
9970^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9971
9972Syntax:
9973"""""""
9974
9975::
9976
Nick Lewycky04f6de02013-09-11 22:04:52 +00009977 declare void @llvm.va_start(i8* <arglist>)
Sean Silvab084af42012-12-07 10:36:55 +00009978
9979Overview:
9980"""""""""
9981
9982The '``llvm.va_start``' intrinsic initializes ``*<arglist>`` for
9983subsequent use by ``va_arg``.
9984
9985Arguments:
9986""""""""""
9987
9988The argument is a pointer to a ``va_list`` element to initialize.
9989
9990Semantics:
9991""""""""""
9992
9993The '``llvm.va_start``' intrinsic works just like the ``va_start`` macro
9994available in C. In a target-dependent way, it initializes the
9995``va_list`` element to which the argument points, so that the next call
9996to ``va_arg`` will produce the first variable argument passed to the
9997function. Unlike the C ``va_start`` macro, this intrinsic does not need
9998to know the last argument of the function as the compiler can figure
9999that out.
10000
10001'``llvm.va_end``' Intrinsic
10002^^^^^^^^^^^^^^^^^^^^^^^^^^^
10003
10004Syntax:
10005"""""""
10006
10007::
10008
10009 declare void @llvm.va_end(i8* <arglist>)
10010
10011Overview:
10012"""""""""
10013
10014The '``llvm.va_end``' intrinsic destroys ``*<arglist>``, which has been
10015initialized previously with ``llvm.va_start`` or ``llvm.va_copy``.
10016
10017Arguments:
10018""""""""""
10019
10020The argument is a pointer to a ``va_list`` to destroy.
10021
10022Semantics:
10023""""""""""
10024
10025The '``llvm.va_end``' intrinsic works just like the ``va_end`` macro
10026available in C. In a target-dependent way, it destroys the ``va_list``
10027element to which the argument points. Calls to
10028:ref:`llvm.va_start <int_va_start>` and
10029:ref:`llvm.va_copy <int_va_copy>` must be matched exactly with calls to
10030``llvm.va_end``.
10031
10032.. _int_va_copy:
10033
10034'``llvm.va_copy``' Intrinsic
10035^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10036
10037Syntax:
10038"""""""
10039
10040::
10041
10042 declare void @llvm.va_copy(i8* <destarglist>, i8* <srcarglist>)
10043
10044Overview:
10045"""""""""
10046
10047The '``llvm.va_copy``' intrinsic copies the current argument position
10048from the source argument list to the destination argument list.
10049
10050Arguments:
10051""""""""""
10052
10053The first argument is a pointer to a ``va_list`` element to initialize.
10054The second argument is a pointer to a ``va_list`` element to copy from.
10055
10056Semantics:
10057""""""""""
10058
10059The '``llvm.va_copy``' intrinsic works just like the ``va_copy`` macro
10060available in C. In a target-dependent way, it copies the source
10061``va_list`` element into the destination ``va_list`` element. This
10062intrinsic is necessary because the `` llvm.va_start`` intrinsic may be
10063arbitrarily complex and require, for example, memory allocation.
10064
10065Accurate Garbage Collection Intrinsics
10066--------------------------------------
10067
Philip Reamesc5b0f562015-02-25 23:52:06 +000010068LLVM's support for `Accurate Garbage Collection <GarbageCollection.html>`_
Mehdi Amini4a121fa2015-03-14 22:04:06 +000010069(GC) requires the frontend to generate code containing appropriate intrinsic
10070calls and select an appropriate GC strategy which knows how to lower these
Philip Reamesc5b0f562015-02-25 23:52:06 +000010071intrinsics in a manner which is appropriate for the target collector.
10072
Sean Silvab084af42012-12-07 10:36:55 +000010073These intrinsics allow identification of :ref:`GC roots on the
10074stack <int_gcroot>`, as well as garbage collector implementations that
10075require :ref:`read <int_gcread>` and :ref:`write <int_gcwrite>` barriers.
Philip Reamesc5b0f562015-02-25 23:52:06 +000010076Frontends for type-safe garbage collected languages should generate
Sean Silvab084af42012-12-07 10:36:55 +000010077these intrinsics to make use of the LLVM garbage collectors. For more
Philip Reamesf80bbff2015-02-25 23:45:20 +000010078details, see `Garbage Collection with LLVM <GarbageCollection.html>`_.
Sean Silvab084af42012-12-07 10:36:55 +000010079
Philip Reamesf80bbff2015-02-25 23:45:20 +000010080Experimental Statepoint Intrinsics
10081^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10082
10083LLVM provides an second experimental set of intrinsics for describing garbage
Sean Silvaa1190322015-08-06 22:56:48 +000010084collection safepoints in compiled code. These intrinsics are an alternative
Mehdi Amini4a121fa2015-03-14 22:04:06 +000010085to the ``llvm.gcroot`` intrinsics, but are compatible with the ones for
Sean Silvaa1190322015-08-06 22:56:48 +000010086:ref:`read <int_gcread>` and :ref:`write <int_gcwrite>` barriers. The
Mehdi Amini4a121fa2015-03-14 22:04:06 +000010087differences in approach are covered in the `Garbage Collection with LLVM
Sean Silvaa1190322015-08-06 22:56:48 +000010088<GarbageCollection.html>`_ documentation. The intrinsics themselves are
Philip Reamesf80bbff2015-02-25 23:45:20 +000010089described in :doc:`Statepoints`.
Sean Silvab084af42012-12-07 10:36:55 +000010090
10091.. _int_gcroot:
10092
10093'``llvm.gcroot``' Intrinsic
10094^^^^^^^^^^^^^^^^^^^^^^^^^^^
10095
10096Syntax:
10097"""""""
10098
10099::
10100
10101 declare void @llvm.gcroot(i8** %ptrloc, i8* %metadata)
10102
10103Overview:
10104"""""""""
10105
10106The '``llvm.gcroot``' intrinsic declares the existence of a GC root to
10107the code generator, and allows some metadata to be associated with it.
10108
10109Arguments:
10110""""""""""
10111
10112The first argument specifies the address of a stack object that contains
10113the root pointer. The second pointer (which must be either a constant or
10114a global value address) contains the meta-data to be associated with the
10115root.
10116
10117Semantics:
10118""""""""""
10119
10120At runtime, a call to this intrinsic stores a null pointer into the
10121"ptrloc" location. At compile-time, the code generator generates
10122information to allow the runtime to find the pointer at GC safe points.
10123The '``llvm.gcroot``' intrinsic may only be used in a function which
10124:ref:`specifies a GC algorithm <gc>`.
10125
10126.. _int_gcread:
10127
10128'``llvm.gcread``' Intrinsic
10129^^^^^^^^^^^^^^^^^^^^^^^^^^^
10130
10131Syntax:
10132"""""""
10133
10134::
10135
10136 declare i8* @llvm.gcread(i8* %ObjPtr, i8** %Ptr)
10137
10138Overview:
10139"""""""""
10140
10141The '``llvm.gcread``' intrinsic identifies reads of references from heap
10142locations, allowing garbage collector implementations that require read
10143barriers.
10144
10145Arguments:
10146""""""""""
10147
10148The second argument is the address to read from, which should be an
10149address allocated from the garbage collector. The first object is a
10150pointer to the start of the referenced object, if needed by the language
10151runtime (otherwise null).
10152
10153Semantics:
10154""""""""""
10155
10156The '``llvm.gcread``' intrinsic has the same semantics as a load
10157instruction, but may be replaced with substantially more complex code by
10158the garbage collector runtime, as needed. The '``llvm.gcread``'
10159intrinsic may only be used in a function which :ref:`specifies a GC
10160algorithm <gc>`.
10161
10162.. _int_gcwrite:
10163
10164'``llvm.gcwrite``' Intrinsic
10165^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10166
10167Syntax:
10168"""""""
10169
10170::
10171
10172 declare void @llvm.gcwrite(i8* %P1, i8* %Obj, i8** %P2)
10173
10174Overview:
10175"""""""""
10176
10177The '``llvm.gcwrite``' intrinsic identifies writes of references to heap
10178locations, allowing garbage collector implementations that require write
10179barriers (such as generational or reference counting collectors).
10180
10181Arguments:
10182""""""""""
10183
10184The first argument is the reference to store, the second is the start of
10185the object to store it to, and the third is the address of the field of
10186Obj to store to. If the runtime does not require a pointer to the
10187object, Obj may be null.
10188
10189Semantics:
10190""""""""""
10191
10192The '``llvm.gcwrite``' intrinsic has the same semantics as a store
10193instruction, but may be replaced with substantially more complex code by
10194the garbage collector runtime, as needed. The '``llvm.gcwrite``'
10195intrinsic may only be used in a function which :ref:`specifies a GC
10196algorithm <gc>`.
10197
10198Code Generator Intrinsics
10199-------------------------
10200
10201These intrinsics are provided by LLVM to expose special features that
10202may only be implemented with code generator support.
10203
10204'``llvm.returnaddress``' Intrinsic
10205^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10206
10207Syntax:
10208"""""""
10209
10210::
10211
George Burgess IVfbc34982017-05-20 04:52:29 +000010212 declare i8* @llvm.returnaddress(i32 <level>)
Sean Silvab084af42012-12-07 10:36:55 +000010213
10214Overview:
10215"""""""""
10216
10217The '``llvm.returnaddress``' intrinsic attempts to compute a
10218target-specific value indicating the return address of the current
10219function or one of its callers.
10220
10221Arguments:
10222""""""""""
10223
10224The argument to this intrinsic indicates which function to return the
10225address for. Zero indicates the calling function, one indicates its
10226caller, etc. The argument is **required** to be a constant integer
10227value.
10228
10229Semantics:
10230""""""""""
10231
10232The '``llvm.returnaddress``' intrinsic either returns a pointer
10233indicating the return address of the specified call frame, or zero if it
10234cannot be identified. The value returned by this intrinsic is likely to
10235be incorrect or 0 for arguments other than zero, so it should only be
10236used for debugging purposes.
10237
10238Note that calling this intrinsic does not prevent function inlining or
10239other aggressive transformations, so the value returned may not be that
10240of the obvious source-language caller.
10241
Albert Gutowski795d7d62016-10-12 22:13:19 +000010242'``llvm.addressofreturnaddress``' Intrinsic
Albert Gutowski57ad5fe2016-10-12 23:10:02 +000010243^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Albert Gutowski795d7d62016-10-12 22:13:19 +000010244
10245Syntax:
10246"""""""
10247
10248::
10249
George Burgess IVfbc34982017-05-20 04:52:29 +000010250 declare i8* @llvm.addressofreturnaddress()
Albert Gutowski795d7d62016-10-12 22:13:19 +000010251
10252Overview:
10253"""""""""
10254
10255The '``llvm.addressofreturnaddress``' intrinsic returns a target-specific
10256pointer to the place in the stack frame where the return address of the
10257current function is stored.
10258
10259Semantics:
10260""""""""""
10261
10262Note that calling this intrinsic does not prevent function inlining or
10263other aggressive transformations, so the value returned may not be that
10264of the obvious source-language caller.
10265
10266This intrinsic is only implemented for x86.
10267
Sean Silvab084af42012-12-07 10:36:55 +000010268'``llvm.frameaddress``' Intrinsic
10269^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10270
10271Syntax:
10272"""""""
10273
10274::
10275
10276 declare i8* @llvm.frameaddress(i32 <level>)
10277
10278Overview:
10279"""""""""
10280
10281The '``llvm.frameaddress``' intrinsic attempts to return the
10282target-specific frame pointer value for the specified stack frame.
10283
10284Arguments:
10285""""""""""
10286
10287The argument to this intrinsic indicates which function to return the
10288frame pointer for. Zero indicates the calling function, one indicates
10289its caller, etc. The argument is **required** to be a constant integer
10290value.
10291
10292Semantics:
10293""""""""""
10294
10295The '``llvm.frameaddress``' intrinsic either returns a pointer
10296indicating the frame address of the specified call frame, or zero if it
10297cannot be identified. The value returned by this intrinsic is likely to
10298be incorrect or 0 for arguments other than zero, so it should only be
10299used for debugging purposes.
10300
10301Note that calling this intrinsic does not prevent function inlining or
10302other aggressive transformations, so the value returned may not be that
10303of the obvious source-language caller.
10304
Reid Kleckner60381792015-07-07 22:25:32 +000010305'``llvm.localescape``' and '``llvm.localrecover``' Intrinsics
Reid Klecknere9b89312015-01-13 00:48:10 +000010306^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10307
10308Syntax:
10309"""""""
10310
10311::
10312
Reid Kleckner60381792015-07-07 22:25:32 +000010313 declare void @llvm.localescape(...)
10314 declare i8* @llvm.localrecover(i8* %func, i8* %fp, i32 %idx)
Reid Klecknere9b89312015-01-13 00:48:10 +000010315
10316Overview:
10317"""""""""
10318
Reid Kleckner60381792015-07-07 22:25:32 +000010319The '``llvm.localescape``' intrinsic escapes offsets of a collection of static
10320allocas, and the '``llvm.localrecover``' intrinsic applies those offsets to a
Reid Klecknercfb9ce52015-03-05 18:26:34 +000010321live frame pointer to recover the address of the allocation. The offset is
Reid Kleckner60381792015-07-07 22:25:32 +000010322computed during frame layout of the caller of ``llvm.localescape``.
Reid Klecknere9b89312015-01-13 00:48:10 +000010323
10324Arguments:
10325""""""""""
10326
Reid Kleckner60381792015-07-07 22:25:32 +000010327All arguments to '``llvm.localescape``' must be pointers to static allocas or
10328casts of static allocas. Each function can only call '``llvm.localescape``'
Reid Klecknercfb9ce52015-03-05 18:26:34 +000010329once, and it can only do so from the entry block.
Reid Klecknere9b89312015-01-13 00:48:10 +000010330
Reid Kleckner60381792015-07-07 22:25:32 +000010331The ``func`` argument to '``llvm.localrecover``' must be a constant
Reid Klecknere9b89312015-01-13 00:48:10 +000010332bitcasted pointer to a function defined in the current module. The code
10333generator cannot determine the frame allocation offset of functions defined in
10334other modules.
10335
Reid Klecknerd5afc62f2015-07-07 23:23:03 +000010336The ``fp`` argument to '``llvm.localrecover``' must be a frame pointer of a
10337call frame that is currently live. The return value of '``llvm.localaddress``'
10338is one way to produce such a value, but various runtimes also expose a suitable
10339pointer in platform-specific ways.
Reid Klecknere9b89312015-01-13 00:48:10 +000010340
Reid Kleckner60381792015-07-07 22:25:32 +000010341The ``idx`` argument to '``llvm.localrecover``' indicates which alloca passed to
10342'``llvm.localescape``' to recover. It is zero-indexed.
Reid Klecknercfb9ce52015-03-05 18:26:34 +000010343
Reid Klecknere9b89312015-01-13 00:48:10 +000010344Semantics:
10345""""""""""
10346
Reid Kleckner60381792015-07-07 22:25:32 +000010347These intrinsics allow a group of functions to share access to a set of local
10348stack allocations of a one parent function. The parent function may call the
10349'``llvm.localescape``' intrinsic once from the function entry block, and the
10350child functions can use '``llvm.localrecover``' to access the escaped allocas.
10351The '``llvm.localescape``' intrinsic blocks inlining, as inlining changes where
10352the escaped allocas are allocated, which would break attempts to use
10353'``llvm.localrecover``'.
Reid Klecknere9b89312015-01-13 00:48:10 +000010354
Renato Golinc7aea402014-05-06 16:51:25 +000010355.. _int_read_register:
10356.. _int_write_register:
10357
10358'``llvm.read_register``' and '``llvm.write_register``' Intrinsics
10359^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10360
10361Syntax:
10362"""""""
10363
10364::
10365
10366 declare i32 @llvm.read_register.i32(metadata)
10367 declare i64 @llvm.read_register.i64(metadata)
10368 declare void @llvm.write_register.i32(metadata, i32 @value)
10369 declare void @llvm.write_register.i64(metadata, i64 @value)
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +000010370 !0 = !{!"sp\00"}
Renato Golinc7aea402014-05-06 16:51:25 +000010371
10372Overview:
10373"""""""""
10374
10375The '``llvm.read_register``' and '``llvm.write_register``' intrinsics
10376provides access to the named register. The register must be valid on
10377the architecture being compiled to. The type needs to be compatible
10378with the register being read.
10379
10380Semantics:
10381""""""""""
10382
10383The '``llvm.read_register``' intrinsic returns the current value of the
10384register, where possible. The '``llvm.write_register``' intrinsic sets
10385the current value of the register, where possible.
10386
10387This is useful to implement named register global variables that need
10388to always be mapped to a specific register, as is common practice on
10389bare-metal programs including OS kernels.
10390
10391The compiler doesn't check for register availability or use of the used
10392register in surrounding code, including inline assembly. Because of that,
10393allocatable registers are not supported.
10394
10395Warning: So far it only works with the stack pointer on selected
Tim Northover3b0846e2014-05-24 12:50:23 +000010396architectures (ARM, AArch64, PowerPC and x86_64). Significant amount of
Renato Golinc7aea402014-05-06 16:51:25 +000010397work is needed to support other registers and even more so, allocatable
10398registers.
10399
Sean Silvab084af42012-12-07 10:36:55 +000010400.. _int_stacksave:
10401
10402'``llvm.stacksave``' Intrinsic
10403^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10404
10405Syntax:
10406"""""""
10407
10408::
10409
10410 declare i8* @llvm.stacksave()
10411
10412Overview:
10413"""""""""
10414
10415The '``llvm.stacksave``' intrinsic is used to remember the current state
10416of the function stack, for use with
10417:ref:`llvm.stackrestore <int_stackrestore>`. This is useful for
10418implementing language features like scoped automatic variable sized
10419arrays in C99.
10420
10421Semantics:
10422""""""""""
10423
10424This intrinsic returns a opaque pointer value that can be passed to
10425:ref:`llvm.stackrestore <int_stackrestore>`. When an
10426``llvm.stackrestore`` intrinsic is executed with a value saved from
10427``llvm.stacksave``, it effectively restores the state of the stack to
10428the state it was in when the ``llvm.stacksave`` intrinsic executed. In
10429practice, this pops any :ref:`alloca <i_alloca>` blocks from the stack that
10430were allocated after the ``llvm.stacksave`` was executed.
10431
10432.. _int_stackrestore:
10433
10434'``llvm.stackrestore``' Intrinsic
10435^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10436
10437Syntax:
10438"""""""
10439
10440::
10441
10442 declare void @llvm.stackrestore(i8* %ptr)
10443
10444Overview:
10445"""""""""
10446
10447The '``llvm.stackrestore``' intrinsic is used to restore the state of
10448the function stack to the state it was in when the corresponding
10449:ref:`llvm.stacksave <int_stacksave>` intrinsic executed. This is
10450useful for implementing language features like scoped automatic variable
10451sized arrays in C99.
10452
10453Semantics:
10454""""""""""
10455
10456See the description for :ref:`llvm.stacksave <int_stacksave>`.
10457
Yury Gribovd7dbb662015-12-01 11:40:55 +000010458.. _int_get_dynamic_area_offset:
10459
10460'``llvm.get.dynamic.area.offset``' Intrinsic
Yury Gribov81f3f152015-12-01 13:24:48 +000010461^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Yury Gribovd7dbb662015-12-01 11:40:55 +000010462
10463Syntax:
10464"""""""
10465
10466::
10467
10468 declare i32 @llvm.get.dynamic.area.offset.i32()
10469 declare i64 @llvm.get.dynamic.area.offset.i64()
10470
Lang Hames10239932016-10-08 00:20:42 +000010471Overview:
10472"""""""""
Yury Gribovd7dbb662015-12-01 11:40:55 +000010473
10474 The '``llvm.get.dynamic.area.offset.*``' intrinsic family is used to
10475 get the offset from native stack pointer to the address of the most
10476 recent dynamic alloca on the caller's stack. These intrinsics are
10477 intendend for use in combination with
10478 :ref:`llvm.stacksave <int_stacksave>` to get a
10479 pointer to the most recent dynamic alloca. This is useful, for example,
10480 for AddressSanitizer's stack unpoisoning routines.
10481
10482Semantics:
10483""""""""""
10484
10485 These intrinsics return a non-negative integer value that can be used to
10486 get the address of the most recent dynamic alloca, allocated by :ref:`alloca <i_alloca>`
10487 on the caller's stack. In particular, for targets where stack grows downwards,
10488 adding this offset to the native stack pointer would get the address of the most
10489 recent dynamic alloca. For targets where stack grows upwards, the situation is a bit more
Sylvestre Ledru0455cbe2016-07-28 09:28:58 +000010490 complicated, because subtracting this value from stack pointer would get the address
Yury Gribovd7dbb662015-12-01 11:40:55 +000010491 one past the end of the most recent dynamic alloca.
10492
10493 Although for most targets `llvm.get.dynamic.area.offset <int_get_dynamic_area_offset>`
10494 returns just a zero, for others, such as PowerPC and PowerPC64, it returns a
10495 compile-time-known constant value.
10496
10497 The return value type of :ref:`llvm.get.dynamic.area.offset <int_get_dynamic_area_offset>`
Matt Arsenaultc749bdc2017-03-30 23:36:47 +000010498 must match the target's default address space's (address space 0) pointer type.
Yury Gribovd7dbb662015-12-01 11:40:55 +000010499
Sean Silvab084af42012-12-07 10:36:55 +000010500'``llvm.prefetch``' Intrinsic
10501^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10502
10503Syntax:
10504"""""""
10505
10506::
10507
10508 declare void @llvm.prefetch(i8* <address>, i32 <rw>, i32 <locality>, i32 <cache type>)
10509
10510Overview:
10511"""""""""
10512
10513The '``llvm.prefetch``' intrinsic is a hint to the code generator to
10514insert a prefetch instruction if supported; otherwise, it is a noop.
10515Prefetches have no effect on the behavior of the program but can change
10516its performance characteristics.
10517
10518Arguments:
10519""""""""""
10520
10521``address`` is the address to be prefetched, ``rw`` is the specifier
10522determining if the fetch should be for a read (0) or write (1), and
10523``locality`` is a temporal locality specifier ranging from (0) - no
10524locality, to (3) - extremely local keep in cache. The ``cache type``
10525specifies whether the prefetch is performed on the data (1) or
10526instruction (0) cache. The ``rw``, ``locality`` and ``cache type``
10527arguments must be constant integers.
10528
10529Semantics:
10530""""""""""
10531
10532This intrinsic does not modify the behavior of the program. In
10533particular, prefetches cannot trap and do not produce a value. On
10534targets that support this intrinsic, the prefetch can provide hints to
10535the processor cache for better performance.
10536
10537'``llvm.pcmarker``' Intrinsic
10538^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10539
10540Syntax:
10541"""""""
10542
10543::
10544
10545 declare void @llvm.pcmarker(i32 <id>)
10546
10547Overview:
10548"""""""""
10549
10550The '``llvm.pcmarker``' intrinsic is a method to export a Program
10551Counter (PC) in a region of code to simulators and other tools. The
10552method is target specific, but it is expected that the marker will use
10553exported symbols to transmit the PC of the marker. The marker makes no
10554guarantees that it will remain with any specific instruction after
10555optimizations. It is possible that the presence of a marker will inhibit
10556optimizations. The intended use is to be inserted after optimizations to
10557allow correlations of simulation runs.
10558
10559Arguments:
10560""""""""""
10561
10562``id`` is a numerical id identifying the marker.
10563
10564Semantics:
10565""""""""""
10566
10567This intrinsic does not modify the behavior of the program. Backends
10568that do not support this intrinsic may ignore it.
10569
10570'``llvm.readcyclecounter``' Intrinsic
10571^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10572
10573Syntax:
10574"""""""
10575
10576::
10577
10578 declare i64 @llvm.readcyclecounter()
10579
10580Overview:
10581"""""""""
10582
10583The '``llvm.readcyclecounter``' intrinsic provides access to the cycle
10584counter register (or similar low latency, high accuracy clocks) on those
10585targets that support it. On X86, it should map to RDTSC. On Alpha, it
10586should map to RPCC. As the backing counters overflow quickly (on the
10587order of 9 seconds on alpha), this should only be used for small
10588timings.
10589
10590Semantics:
10591""""""""""
10592
10593When directly supported, reading the cycle counter should not modify any
10594memory. Implementations are allowed to either return a application
10595specific value or a system wide value. On backends without support, this
10596is lowered to a constant 0.
10597
Tim Northoverbc933082013-05-23 19:11:20 +000010598Note that runtime support may be conditional on the privilege-level code is
10599running at and the host platform.
10600
Renato Golinc0a3c1d2014-03-26 12:52:28 +000010601'``llvm.clear_cache``' Intrinsic
10602^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10603
10604Syntax:
10605"""""""
10606
10607::
10608
10609 declare void @llvm.clear_cache(i8*, i8*)
10610
10611Overview:
10612"""""""""
10613
Joerg Sonnenberger03014d62014-03-26 14:35:21 +000010614The '``llvm.clear_cache``' intrinsic ensures visibility of modifications
10615in the specified range to the execution unit of the processor. On
10616targets with non-unified instruction and data cache, the implementation
10617flushes the instruction cache.
Renato Golinc0a3c1d2014-03-26 12:52:28 +000010618
10619Semantics:
10620""""""""""
10621
Joerg Sonnenberger03014d62014-03-26 14:35:21 +000010622On platforms with coherent instruction and data caches (e.g. x86), this
10623intrinsic is a nop. On platforms with non-coherent instruction and data
Alp Toker16f98b22014-04-09 14:47:27 +000010624cache (e.g. ARM, MIPS), the intrinsic is lowered either to appropriate
Joerg Sonnenberger03014d62014-03-26 14:35:21 +000010625instructions or a system call, if cache flushing requires special
10626privileges.
Renato Golinc0a3c1d2014-03-26 12:52:28 +000010627
Sean Silvad02bf3e2014-04-07 22:29:53 +000010628The default behavior is to emit a call to ``__clear_cache`` from the run
Joerg Sonnenberger03014d62014-03-26 14:35:21 +000010629time library.
Renato Golin93010e62014-03-26 14:01:32 +000010630
Joerg Sonnenberger03014d62014-03-26 14:35:21 +000010631This instrinsic does *not* empty the instruction pipeline. Modifications
10632of the current function are outside the scope of the intrinsic.
Renato Golinc0a3c1d2014-03-26 12:52:28 +000010633
Vedant Kumar51ce6682018-01-26 23:54:25 +000010634'``llvm.instrprof.increment``' Intrinsic
Justin Bogner61ba2e32014-12-08 18:02:35 +000010635^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10636
10637Syntax:
10638"""""""
10639
10640::
10641
Vedant Kumar51ce6682018-01-26 23:54:25 +000010642 declare void @llvm.instrprof.increment(i8* <name>, i64 <hash>,
Justin Bogner61ba2e32014-12-08 18:02:35 +000010643 i32 <num-counters>, i32 <index>)
10644
10645Overview:
10646"""""""""
10647
Vedant Kumar51ce6682018-01-26 23:54:25 +000010648The '``llvm.instrprof.increment``' intrinsic can be emitted by a
Justin Bogner61ba2e32014-12-08 18:02:35 +000010649frontend for use with instrumentation based profiling. These will be
10650lowered by the ``-instrprof`` pass to generate execution counts of a
10651program at runtime.
10652
10653Arguments:
10654""""""""""
10655
10656The first argument is a pointer to a global variable containing the
10657name of the entity being instrumented. This should generally be the
10658(mangled) function name for a set of counters.
10659
10660The second argument is a hash value that can be used by the consumer
10661of the profile data to detect changes to the instrumented source, and
10662the third is the number of counters associated with ``name``. It is an
10663error if ``hash`` or ``num-counters`` differ between two instances of
Vedant Kumar51ce6682018-01-26 23:54:25 +000010664``instrprof.increment`` that refer to the same name.
Justin Bogner61ba2e32014-12-08 18:02:35 +000010665
10666The last argument refers to which of the counters for ``name`` should
10667be incremented. It should be a value between 0 and ``num-counters``.
10668
10669Semantics:
10670""""""""""
10671
10672This intrinsic represents an increment of a profiling counter. It will
10673cause the ``-instrprof`` pass to generate the appropriate data
10674structures and the code to increment the appropriate value, in a
10675format that can be written out by a compiler runtime and consumed via
10676the ``llvm-profdata`` tool.
10677
Vedant Kumar51ce6682018-01-26 23:54:25 +000010678'``llvm.instrprof.increment.step``' Intrinsic
Xinliang David Lie1117102016-09-18 22:10:19 +000010679^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Xinliang David Li4ca17332016-09-18 18:34:07 +000010680
10681Syntax:
10682"""""""
10683
10684::
10685
Vedant Kumar51ce6682018-01-26 23:54:25 +000010686 declare void @llvm.instrprof.increment.step(i8* <name>, i64 <hash>,
Xinliang David Li4ca17332016-09-18 18:34:07 +000010687 i32 <num-counters>,
10688 i32 <index>, i64 <step>)
10689
10690Overview:
10691"""""""""
10692
Vedant Kumar51ce6682018-01-26 23:54:25 +000010693The '``llvm.instrprof.increment.step``' intrinsic is an extension to
10694the '``llvm.instrprof.increment``' intrinsic with an additional fifth
Xinliang David Li4ca17332016-09-18 18:34:07 +000010695argument to specify the step of the increment.
10696
10697Arguments:
10698""""""""""
Vedant Kumar51ce6682018-01-26 23:54:25 +000010699The first four arguments are the same as '``llvm.instrprof.increment``'
Pete Couperused9569d2017-08-23 20:58:22 +000010700intrinsic.
Xinliang David Li4ca17332016-09-18 18:34:07 +000010701
10702The last argument specifies the value of the increment of the counter variable.
10703
10704Semantics:
10705""""""""""
Vedant Kumar51ce6682018-01-26 23:54:25 +000010706See description of '``llvm.instrprof.increment``' instrinsic.
Xinliang David Li4ca17332016-09-18 18:34:07 +000010707
10708
Vedant Kumar51ce6682018-01-26 23:54:25 +000010709'``llvm.instrprof.value.profile``' Intrinsic
Betul Buyukkurt6fac1742015-11-18 18:14:55 +000010710^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10711
10712Syntax:
10713"""""""
10714
10715::
10716
Vedant Kumar51ce6682018-01-26 23:54:25 +000010717 declare void @llvm.instrprof.value.profile(i8* <name>, i64 <hash>,
Betul Buyukkurt6fac1742015-11-18 18:14:55 +000010718 i64 <value>, i32 <value_kind>,
10719 i32 <index>)
10720
10721Overview:
10722"""""""""
10723
Vedant Kumar51ce6682018-01-26 23:54:25 +000010724The '``llvm.instrprof.value.profile``' intrinsic can be emitted by a
Betul Buyukkurt6fac1742015-11-18 18:14:55 +000010725frontend for use with instrumentation based profiling. This will be
10726lowered by the ``-instrprof`` pass to find out the target values,
10727instrumented expressions take in a program at runtime.
10728
10729Arguments:
10730""""""""""
10731
10732The first argument is a pointer to a global variable containing the
10733name of the entity being instrumented. ``name`` should generally be the
10734(mangled) function name for a set of counters.
10735
10736The second argument is a hash value that can be used by the consumer
10737of the profile data to detect changes to the instrumented source. It
10738is an error if ``hash`` differs between two instances of
Vedant Kumar51ce6682018-01-26 23:54:25 +000010739``llvm.instrprof.*`` that refer to the same name.
Betul Buyukkurt6fac1742015-11-18 18:14:55 +000010740
10741The third argument is the value of the expression being profiled. The profiled
10742expression's value should be representable as an unsigned 64-bit value. The
10743fourth argument represents the kind of value profiling that is being done. The
10744supported value profiling kinds are enumerated through the
10745``InstrProfValueKind`` type declared in the
10746``<include/llvm/ProfileData/InstrProf.h>`` header file. The last argument is the
10747index of the instrumented expression within ``name``. It should be >= 0.
10748
10749Semantics:
10750""""""""""
10751
10752This intrinsic represents the point where a call to a runtime routine
10753should be inserted for value profiling of target expressions. ``-instrprof``
10754pass will generate the appropriate data structures and replace the
Vedant Kumar51ce6682018-01-26 23:54:25 +000010755``llvm.instrprof.value.profile`` intrinsic with the call to the profile
Betul Buyukkurt6fac1742015-11-18 18:14:55 +000010756runtime library with proper arguments.
10757
Marcin Koscielnicki3fdc2572016-04-19 20:51:05 +000010758'``llvm.thread.pointer``' Intrinsic
10759^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10760
10761Syntax:
10762"""""""
10763
10764::
10765
10766 declare i8* @llvm.thread.pointer()
10767
10768Overview:
10769"""""""""
10770
10771The '``llvm.thread.pointer``' intrinsic returns the value of the thread
10772pointer.
10773
10774Semantics:
10775""""""""""
10776
10777The '``llvm.thread.pointer``' intrinsic returns a pointer to the TLS area
10778for the current thread. The exact semantics of this value are target
10779specific: it may point to the start of TLS area, to the end, or somewhere
10780in the middle. Depending on the target, this intrinsic may read a register,
10781call a helper function, read from an alternate memory space, or perform
10782other operations necessary to locate the TLS area. Not all targets support
10783this intrinsic.
10784
Sean Silvab084af42012-12-07 10:36:55 +000010785Standard C Library Intrinsics
10786-----------------------------
10787
10788LLVM provides intrinsics for a few important standard C library
10789functions. These intrinsics allow source-language front-ends to pass
10790information about the alignment of the pointer arguments to the code
10791generator, providing opportunity for more efficient code generation.
10792
10793.. _int_memcpy:
10794
10795'``llvm.memcpy``' Intrinsic
10796^^^^^^^^^^^^^^^^^^^^^^^^^^^
10797
10798Syntax:
10799"""""""
10800
10801This is an overloaded intrinsic. You can use ``llvm.memcpy`` on any
10802integer bit width and for different address spaces. Not all targets
10803support all bit widths however.
10804
10805::
10806
10807 declare void @llvm.memcpy.p0i8.p0i8.i32(i8* <dest>, i8* <src>,
Daniel Neilson1e687242018-01-19 17:13:12 +000010808 i32 <len>, i1 <isvolatile>)
Sean Silvab084af42012-12-07 10:36:55 +000010809 declare void @llvm.memcpy.p0i8.p0i8.i64(i8* <dest>, i8* <src>,
Daniel Neilson1e687242018-01-19 17:13:12 +000010810 i64 <len>, i1 <isvolatile>)
Sean Silvab084af42012-12-07 10:36:55 +000010811
10812Overview:
10813"""""""""
10814
10815The '``llvm.memcpy.*``' intrinsics copy a block of memory from the
10816source location to the destination location.
10817
10818Note that, unlike the standard libc function, the ``llvm.memcpy.*``
Daniel Neilson1e687242018-01-19 17:13:12 +000010819intrinsics do not return a value, takes extra isvolatile
Sean Silvab084af42012-12-07 10:36:55 +000010820arguments and the pointers can be in specified address spaces.
10821
10822Arguments:
10823""""""""""
10824
10825The first argument is a pointer to the destination, the second is a
10826pointer to the source. The third argument is an integer argument
Daniel Neilson1e687242018-01-19 17:13:12 +000010827specifying the number of bytes to copy, and the fourth is a
Sean Silvab084af42012-12-07 10:36:55 +000010828boolean indicating a volatile access.
10829
Daniel Neilson39eb6a52018-01-19 17:24:21 +000010830The :ref:`align <attr_align>` parameter attribute can be provided
Daniel Neilson1e687242018-01-19 17:13:12 +000010831for the first and second arguments.
Sean Silvab084af42012-12-07 10:36:55 +000010832
10833If the ``isvolatile`` parameter is ``true``, the ``llvm.memcpy`` call is
10834a :ref:`volatile operation <volatile>`. The detailed access behavior is not
10835very cleanly specified and it is unwise to depend on it.
10836
10837Semantics:
10838""""""""""
10839
10840The '``llvm.memcpy.*``' intrinsics copy a block of memory from the
10841source location to the destination location, which are not allowed to
10842overlap. It copies "len" bytes of memory over. If the argument is known
10843to be aligned to some boundary, this can be specified as the fourth
Bill Wendling61163152013-10-18 23:26:55 +000010844argument, otherwise it should be set to 0 or 1 (both meaning no alignment).
Sean Silvab084af42012-12-07 10:36:55 +000010845
Daniel Neilson57226ef2017-07-12 15:25:26 +000010846.. _int_memmove:
10847
Sean Silvab084af42012-12-07 10:36:55 +000010848'``llvm.memmove``' Intrinsic
10849^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10850
10851Syntax:
10852"""""""
10853
10854This is an overloaded intrinsic. You can use llvm.memmove on any integer
10855bit width and for different address space. Not all targets support all
10856bit widths however.
10857
10858::
10859
10860 declare void @llvm.memmove.p0i8.p0i8.i32(i8* <dest>, i8* <src>,
Daniel Neilson1e687242018-01-19 17:13:12 +000010861 i32 <len>, i1 <isvolatile>)
Sean Silvab084af42012-12-07 10:36:55 +000010862 declare void @llvm.memmove.p0i8.p0i8.i64(i8* <dest>, i8* <src>,
Daniel Neilson1e687242018-01-19 17:13:12 +000010863 i64 <len>, i1 <isvolatile>)
Sean Silvab084af42012-12-07 10:36:55 +000010864
10865Overview:
10866"""""""""
10867
10868The '``llvm.memmove.*``' intrinsics move a block of memory from the
10869source location to the destination location. It is similar to the
10870'``llvm.memcpy``' intrinsic but allows the two memory locations to
10871overlap.
10872
10873Note that, unlike the standard libc function, the ``llvm.memmove.*``
Daniel Neilson1e687242018-01-19 17:13:12 +000010874intrinsics do not return a value, takes an extra isvolatile
10875argument and the pointers can be in specified address spaces.
Sean Silvab084af42012-12-07 10:36:55 +000010876
10877Arguments:
10878""""""""""
10879
10880The first argument is a pointer to the destination, the second is a
10881pointer to the source. The third argument is an integer argument
Daniel Neilson1e687242018-01-19 17:13:12 +000010882specifying the number of bytes to copy, and the fourth is a
Sean Silvab084af42012-12-07 10:36:55 +000010883boolean indicating a volatile access.
10884
Daniel Neilsonaac0f8f2018-01-19 17:32:33 +000010885The :ref:`align <attr_align>` parameter attribute can be provided
Daniel Neilson1e687242018-01-19 17:13:12 +000010886for the first and second arguments.
Sean Silvab084af42012-12-07 10:36:55 +000010887
10888If the ``isvolatile`` parameter is ``true``, the ``llvm.memmove`` call
10889is a :ref:`volatile operation <volatile>`. The detailed access behavior is
10890not very cleanly specified and it is unwise to depend on it.
10891
10892Semantics:
10893""""""""""
10894
10895The '``llvm.memmove.*``' intrinsics copy a block of memory from the
10896source location to the destination location, which may overlap. It
10897copies "len" bytes of memory over. If the argument is known to be
10898aligned to some boundary, this can be specified as the fourth argument,
Bill Wendling61163152013-10-18 23:26:55 +000010899otherwise it should be set to 0 or 1 (both meaning no alignment).
Sean Silvab084af42012-12-07 10:36:55 +000010900
Daniel Neilson965613e2017-07-12 21:57:23 +000010901.. _int_memset:
10902
Sean Silvab084af42012-12-07 10:36:55 +000010903'``llvm.memset.*``' Intrinsics
10904^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10905
10906Syntax:
10907"""""""
10908
10909This is an overloaded intrinsic. You can use llvm.memset on any integer
10910bit width and for different address spaces. However, not all targets
10911support all bit widths.
10912
10913::
10914
10915 declare void @llvm.memset.p0i8.i32(i8* <dest>, i8 <val>,
Daniel Neilson1e687242018-01-19 17:13:12 +000010916 i32 <len>, i1 <isvolatile>)
Sean Silvab084af42012-12-07 10:36:55 +000010917 declare void @llvm.memset.p0i8.i64(i8* <dest>, i8 <val>,
Daniel Neilson1e687242018-01-19 17:13:12 +000010918 i64 <len>, i1 <isvolatile>)
Sean Silvab084af42012-12-07 10:36:55 +000010919
10920Overview:
10921"""""""""
10922
10923The '``llvm.memset.*``' intrinsics fill a block of memory with a
10924particular byte value.
10925
10926Note that, unlike the standard libc function, the ``llvm.memset``
Daniel Neilson1e687242018-01-19 17:13:12 +000010927intrinsic does not return a value and takes an extra volatile
10928argument. Also, the destination can be in an arbitrary address space.
Sean Silvab084af42012-12-07 10:36:55 +000010929
10930Arguments:
10931""""""""""
10932
10933The first argument is a pointer to the destination to fill, the second
10934is the byte value with which to fill it, the third argument is an
10935integer argument specifying the number of bytes to fill, and the fourth
Daniel Neilson1e687242018-01-19 17:13:12 +000010936is a boolean indicating a volatile access.
Sean Silvab084af42012-12-07 10:36:55 +000010937
Daniel Neilsonaac0f8f2018-01-19 17:32:33 +000010938The :ref:`align <attr_align>` parameter attribute can be provided
Daniel Neilson1e687242018-01-19 17:13:12 +000010939for the first arguments.
Sean Silvab084af42012-12-07 10:36:55 +000010940
10941If the ``isvolatile`` parameter is ``true``, the ``llvm.memset`` call is
10942a :ref:`volatile operation <volatile>`. The detailed access behavior is not
10943very cleanly specified and it is unwise to depend on it.
10944
10945Semantics:
10946""""""""""
10947
10948The '``llvm.memset.*``' intrinsics fill "len" bytes of memory starting
Elena Demikhovsky945b7e52018-02-14 06:58:08 +000010949at the destination location.
Sean Silvab084af42012-12-07 10:36:55 +000010950
10951'``llvm.sqrt.*``' Intrinsic
10952^^^^^^^^^^^^^^^^^^^^^^^^^^^
10953
10954Syntax:
10955"""""""
10956
10957This is an overloaded intrinsic. You can use ``llvm.sqrt`` on any
Sanjay Patel629c4112017-11-06 16:27:15 +000010958floating-point or vector of floating-point type. Not all targets support
Sean Silvab084af42012-12-07 10:36:55 +000010959all types however.
10960
10961::
10962
10963 declare float @llvm.sqrt.f32(float %Val)
10964 declare double @llvm.sqrt.f64(double %Val)
10965 declare x86_fp80 @llvm.sqrt.f80(x86_fp80 %Val)
10966 declare fp128 @llvm.sqrt.f128(fp128 %Val)
10967 declare ppc_fp128 @llvm.sqrt.ppcf128(ppc_fp128 %Val)
10968
10969Overview:
10970"""""""""
10971
Sanjay Patel629c4112017-11-06 16:27:15 +000010972The '``llvm.sqrt``' intrinsics return the square root of the specified value.
Sean Silvab084af42012-12-07 10:36:55 +000010973
10974Arguments:
10975""""""""""
10976
Sanjay Patel629c4112017-11-06 16:27:15 +000010977The argument and return value are floating-point numbers of the same type.
Sean Silvab084af42012-12-07 10:36:55 +000010978
10979Semantics:
10980""""""""""
10981
Sanjay Patel629c4112017-11-06 16:27:15 +000010982Return the same value as a corresponding libm '``sqrt``' function but without
Elena Demikhovsky945b7e52018-02-14 06:58:08 +000010983trapping or setting ``errno``. For types specified by IEEE-754, the result
Sanjay Patel629c4112017-11-06 16:27:15 +000010984matches a conforming libm implementation.
10985
Elena Demikhovsky945b7e52018-02-14 06:58:08 +000010986When specified with the fast-math-flag 'afn', the result may be approximated
Sanjay Patel629c4112017-11-06 16:27:15 +000010987using a less accurate calculation.
Sean Silvab084af42012-12-07 10:36:55 +000010988
10989'``llvm.powi.*``' Intrinsic
10990^^^^^^^^^^^^^^^^^^^^^^^^^^^
10991
10992Syntax:
10993"""""""
10994
10995This is an overloaded intrinsic. You can use ``llvm.powi`` on any
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000010996floating-point or vector of floating-point type. Not all targets support
Sean Silvab084af42012-12-07 10:36:55 +000010997all types however.
10998
10999::
11000
11001 declare float @llvm.powi.f32(float %Val, i32 %power)
11002 declare double @llvm.powi.f64(double %Val, i32 %power)
11003 declare x86_fp80 @llvm.powi.f80(x86_fp80 %Val, i32 %power)
11004 declare fp128 @llvm.powi.f128(fp128 %Val, i32 %power)
11005 declare ppc_fp128 @llvm.powi.ppcf128(ppc_fp128 %Val, i32 %power)
11006
11007Overview:
11008"""""""""
11009
11010The '``llvm.powi.*``' intrinsics return the first operand raised to the
11011specified (positive or negative) power. The order of evaluation of
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000011012multiplications is not defined. When a vector of floating-point type is
Sean Silvab084af42012-12-07 10:36:55 +000011013used, the second argument remains a scalar integer value.
11014
11015Arguments:
11016""""""""""
11017
11018The second argument is an integer power, and the first is a value to
11019raise to that power.
11020
11021Semantics:
11022""""""""""
11023
11024This function returns the first value raised to the second power with an
11025unspecified sequence of rounding operations.
11026
11027'``llvm.sin.*``' Intrinsic
11028^^^^^^^^^^^^^^^^^^^^^^^^^^
11029
11030Syntax:
11031"""""""
11032
11033This is an overloaded intrinsic. You can use ``llvm.sin`` on any
Sanjay Patel629c4112017-11-06 16:27:15 +000011034floating-point or vector of floating-point type. Not all targets support
Sean Silvab084af42012-12-07 10:36:55 +000011035all types however.
11036
11037::
11038
11039 declare float @llvm.sin.f32(float %Val)
11040 declare double @llvm.sin.f64(double %Val)
11041 declare x86_fp80 @llvm.sin.f80(x86_fp80 %Val)
11042 declare fp128 @llvm.sin.f128(fp128 %Val)
11043 declare ppc_fp128 @llvm.sin.ppcf128(ppc_fp128 %Val)
11044
11045Overview:
11046"""""""""
11047
11048The '``llvm.sin.*``' intrinsics return the sine of the operand.
11049
11050Arguments:
11051""""""""""
11052
Sanjay Patel629c4112017-11-06 16:27:15 +000011053The argument and return value are floating-point numbers of the same type.
Sean Silvab084af42012-12-07 10:36:55 +000011054
11055Semantics:
11056""""""""""
11057
Sanjay Patel629c4112017-11-06 16:27:15 +000011058Return the same value as a corresponding libm '``sin``' function but without
11059trapping or setting ``errno``.
11060
Elena Demikhovsky945b7e52018-02-14 06:58:08 +000011061When specified with the fast-math-flag 'afn', the result may be approximated
Sanjay Patel629c4112017-11-06 16:27:15 +000011062using a less accurate calculation.
Sean Silvab084af42012-12-07 10:36:55 +000011063
11064'``llvm.cos.*``' Intrinsic
11065^^^^^^^^^^^^^^^^^^^^^^^^^^
11066
11067Syntax:
11068"""""""
11069
11070This is an overloaded intrinsic. You can use ``llvm.cos`` on any
Sanjay Patel629c4112017-11-06 16:27:15 +000011071floating-point or vector of floating-point type. Not all targets support
Sean Silvab084af42012-12-07 10:36:55 +000011072all types however.
11073
11074::
11075
11076 declare float @llvm.cos.f32(float %Val)
11077 declare double @llvm.cos.f64(double %Val)
11078 declare x86_fp80 @llvm.cos.f80(x86_fp80 %Val)
11079 declare fp128 @llvm.cos.f128(fp128 %Val)
11080 declare ppc_fp128 @llvm.cos.ppcf128(ppc_fp128 %Val)
11081
11082Overview:
11083"""""""""
11084
11085The '``llvm.cos.*``' intrinsics return the cosine of the operand.
11086
11087Arguments:
11088""""""""""
11089
Sanjay Patel629c4112017-11-06 16:27:15 +000011090The argument and return value are floating-point numbers of the same type.
Sean Silvab084af42012-12-07 10:36:55 +000011091
11092Semantics:
11093""""""""""
11094
Sanjay Patel629c4112017-11-06 16:27:15 +000011095Return the same value as a corresponding libm '``cos``' function but without
11096trapping or setting ``errno``.
11097
Elena Demikhovsky945b7e52018-02-14 06:58:08 +000011098When specified with the fast-math-flag 'afn', the result may be approximated
Sanjay Patel629c4112017-11-06 16:27:15 +000011099using a less accurate calculation.
Sean Silvab084af42012-12-07 10:36:55 +000011100
11101'``llvm.pow.*``' Intrinsic
11102^^^^^^^^^^^^^^^^^^^^^^^^^^
11103
11104Syntax:
11105"""""""
11106
11107This is an overloaded intrinsic. You can use ``llvm.pow`` on any
Sanjay Patel629c4112017-11-06 16:27:15 +000011108floating-point or vector of floating-point type. Not all targets support
Sean Silvab084af42012-12-07 10:36:55 +000011109all types however.
11110
11111::
11112
11113 declare float @llvm.pow.f32(float %Val, float %Power)
11114 declare double @llvm.pow.f64(double %Val, double %Power)
11115 declare x86_fp80 @llvm.pow.f80(x86_fp80 %Val, x86_fp80 %Power)
11116 declare fp128 @llvm.pow.f128(fp128 %Val, fp128 %Power)
11117 declare ppc_fp128 @llvm.pow.ppcf128(ppc_fp128 %Val, ppc_fp128 Power)
11118
11119Overview:
11120"""""""""
11121
11122The '``llvm.pow.*``' intrinsics return the first operand raised to the
11123specified (positive or negative) power.
11124
11125Arguments:
11126""""""""""
11127
Sanjay Patel629c4112017-11-06 16:27:15 +000011128The arguments and return value are floating-point numbers of the same type.
Sean Silvab084af42012-12-07 10:36:55 +000011129
11130Semantics:
11131""""""""""
11132
Sanjay Patel629c4112017-11-06 16:27:15 +000011133Return the same value as a corresponding libm '``pow``' function but without
11134trapping or setting ``errno``.
11135
Elena Demikhovsky945b7e52018-02-14 06:58:08 +000011136When specified with the fast-math-flag 'afn', the result may be approximated
Sanjay Patel629c4112017-11-06 16:27:15 +000011137using a less accurate calculation.
Sean Silvab084af42012-12-07 10:36:55 +000011138
11139'``llvm.exp.*``' Intrinsic
11140^^^^^^^^^^^^^^^^^^^^^^^^^^
11141
11142Syntax:
11143"""""""
11144
11145This is an overloaded intrinsic. You can use ``llvm.exp`` on any
Sanjay Patel629c4112017-11-06 16:27:15 +000011146floating-point or vector of floating-point type. Not all targets support
Sean Silvab084af42012-12-07 10:36:55 +000011147all types however.
11148
11149::
11150
11151 declare float @llvm.exp.f32(float %Val)
11152 declare double @llvm.exp.f64(double %Val)
11153 declare x86_fp80 @llvm.exp.f80(x86_fp80 %Val)
11154 declare fp128 @llvm.exp.f128(fp128 %Val)
11155 declare ppc_fp128 @llvm.exp.ppcf128(ppc_fp128 %Val)
11156
11157Overview:
11158"""""""""
11159
Andrew Kaylorcaf24d22017-04-11 21:52:40 +000011160The '``llvm.exp.*``' intrinsics compute the base-e exponential of the specified
11161value.
Sean Silvab084af42012-12-07 10:36:55 +000011162
11163Arguments:
11164""""""""""
11165
Sanjay Patel629c4112017-11-06 16:27:15 +000011166The argument and return value are floating-point numbers of the same type.
Sean Silvab084af42012-12-07 10:36:55 +000011167
11168Semantics:
11169""""""""""
11170
Sanjay Patel629c4112017-11-06 16:27:15 +000011171Return the same value as a corresponding libm '``exp``' function but without
11172trapping or setting ``errno``.
11173
Elena Demikhovsky945b7e52018-02-14 06:58:08 +000011174When specified with the fast-math-flag 'afn', the result may be approximated
Sanjay Patel629c4112017-11-06 16:27:15 +000011175using a less accurate calculation.
Sean Silvab084af42012-12-07 10:36:55 +000011176
11177'``llvm.exp2.*``' Intrinsic
11178^^^^^^^^^^^^^^^^^^^^^^^^^^^
11179
11180Syntax:
11181"""""""
11182
11183This is an overloaded intrinsic. You can use ``llvm.exp2`` on any
Sanjay Patel629c4112017-11-06 16:27:15 +000011184floating-point or vector of floating-point type. Not all targets support
Sean Silvab084af42012-12-07 10:36:55 +000011185all types however.
11186
11187::
11188
11189 declare float @llvm.exp2.f32(float %Val)
11190 declare double @llvm.exp2.f64(double %Val)
11191 declare x86_fp80 @llvm.exp2.f80(x86_fp80 %Val)
11192 declare fp128 @llvm.exp2.f128(fp128 %Val)
11193 declare ppc_fp128 @llvm.exp2.ppcf128(ppc_fp128 %Val)
11194
11195Overview:
11196"""""""""
11197
Andrew Kaylorcaf24d22017-04-11 21:52:40 +000011198The '``llvm.exp2.*``' intrinsics compute the base-2 exponential of the
11199specified value.
Sean Silvab084af42012-12-07 10:36:55 +000011200
11201Arguments:
11202""""""""""
11203
Sanjay Patel629c4112017-11-06 16:27:15 +000011204The argument and return value are floating-point numbers of the same type.
Sean Silvab084af42012-12-07 10:36:55 +000011205
11206Semantics:
11207""""""""""
11208
Sanjay Patel629c4112017-11-06 16:27:15 +000011209Return the same value as a corresponding libm '``exp2``' function but without
11210trapping or setting ``errno``.
11211
Elena Demikhovsky945b7e52018-02-14 06:58:08 +000011212When specified with the fast-math-flag 'afn', the result may be approximated
Sanjay Patel629c4112017-11-06 16:27:15 +000011213using a less accurate calculation.
Sean Silvab084af42012-12-07 10:36:55 +000011214
11215'``llvm.log.*``' Intrinsic
11216^^^^^^^^^^^^^^^^^^^^^^^^^^
11217
11218Syntax:
11219"""""""
11220
11221This is an overloaded intrinsic. You can use ``llvm.log`` on any
Sanjay Patel629c4112017-11-06 16:27:15 +000011222floating-point or vector of floating-point type. Not all targets support
Sean Silvab084af42012-12-07 10:36:55 +000011223all types however.
11224
11225::
11226
11227 declare float @llvm.log.f32(float %Val)
11228 declare double @llvm.log.f64(double %Val)
11229 declare x86_fp80 @llvm.log.f80(x86_fp80 %Val)
11230 declare fp128 @llvm.log.f128(fp128 %Val)
11231 declare ppc_fp128 @llvm.log.ppcf128(ppc_fp128 %Val)
11232
11233Overview:
11234"""""""""
11235
Andrew Kaylorcaf24d22017-04-11 21:52:40 +000011236The '``llvm.log.*``' intrinsics compute the base-e logarithm of the specified
11237value.
Sean Silvab084af42012-12-07 10:36:55 +000011238
11239Arguments:
11240""""""""""
11241
Sanjay Patel629c4112017-11-06 16:27:15 +000011242The argument and return value are floating-point numbers of the same type.
Sean Silvab084af42012-12-07 10:36:55 +000011243
11244Semantics:
11245""""""""""
11246
Sanjay Patel629c4112017-11-06 16:27:15 +000011247Return the same value as a corresponding libm '``log``' function but without
11248trapping or setting ``errno``.
11249
Elena Demikhovsky945b7e52018-02-14 06:58:08 +000011250When specified with the fast-math-flag 'afn', the result may be approximated
Sanjay Patel629c4112017-11-06 16:27:15 +000011251using a less accurate calculation.
Sean Silvab084af42012-12-07 10:36:55 +000011252
11253'``llvm.log10.*``' Intrinsic
11254^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11255
11256Syntax:
11257"""""""
11258
11259This is an overloaded intrinsic. You can use ``llvm.log10`` on any
Sanjay Patel629c4112017-11-06 16:27:15 +000011260floating-point or vector of floating-point type. Not all targets support
Sean Silvab084af42012-12-07 10:36:55 +000011261all types however.
11262
11263::
11264
11265 declare float @llvm.log10.f32(float %Val)
11266 declare double @llvm.log10.f64(double %Val)
11267 declare x86_fp80 @llvm.log10.f80(x86_fp80 %Val)
11268 declare fp128 @llvm.log10.f128(fp128 %Val)
11269 declare ppc_fp128 @llvm.log10.ppcf128(ppc_fp128 %Val)
11270
11271Overview:
11272"""""""""
11273
Andrew Kaylorcaf24d22017-04-11 21:52:40 +000011274The '``llvm.log10.*``' intrinsics compute the base-10 logarithm of the
11275specified value.
Sean Silvab084af42012-12-07 10:36:55 +000011276
11277Arguments:
11278""""""""""
11279
Sanjay Patel629c4112017-11-06 16:27:15 +000011280The argument and return value are floating-point numbers of the same type.
Sean Silvab084af42012-12-07 10:36:55 +000011281
11282Semantics:
11283""""""""""
11284
Sanjay Patel629c4112017-11-06 16:27:15 +000011285Return the same value as a corresponding libm '``log10``' function but without
11286trapping or setting ``errno``.
11287
Elena Demikhovsky945b7e52018-02-14 06:58:08 +000011288When specified with the fast-math-flag 'afn', the result may be approximated
Sanjay Patel629c4112017-11-06 16:27:15 +000011289using a less accurate calculation.
Sean Silvab084af42012-12-07 10:36:55 +000011290
11291'``llvm.log2.*``' Intrinsic
11292^^^^^^^^^^^^^^^^^^^^^^^^^^^
11293
11294Syntax:
11295"""""""
11296
11297This is an overloaded intrinsic. You can use ``llvm.log2`` on any
Sanjay Patel629c4112017-11-06 16:27:15 +000011298floating-point or vector of floating-point type. Not all targets support
Sean Silvab084af42012-12-07 10:36:55 +000011299all types however.
11300
11301::
11302
11303 declare float @llvm.log2.f32(float %Val)
11304 declare double @llvm.log2.f64(double %Val)
11305 declare x86_fp80 @llvm.log2.f80(x86_fp80 %Val)
11306 declare fp128 @llvm.log2.f128(fp128 %Val)
11307 declare ppc_fp128 @llvm.log2.ppcf128(ppc_fp128 %Val)
11308
11309Overview:
11310"""""""""
11311
Andrew Kaylorcaf24d22017-04-11 21:52:40 +000011312The '``llvm.log2.*``' intrinsics compute the base-2 logarithm of the specified
11313value.
Sean Silvab084af42012-12-07 10:36:55 +000011314
11315Arguments:
11316""""""""""
11317
Sanjay Patel629c4112017-11-06 16:27:15 +000011318The argument and return value are floating-point numbers of the same type.
Sean Silvab084af42012-12-07 10:36:55 +000011319
11320Semantics:
11321""""""""""
11322
Sanjay Patel629c4112017-11-06 16:27:15 +000011323Return the same value as a corresponding libm '``log2``' function but without
11324trapping or setting ``errno``.
11325
Elena Demikhovsky945b7e52018-02-14 06:58:08 +000011326When specified with the fast-math-flag 'afn', the result may be approximated
Sanjay Patel629c4112017-11-06 16:27:15 +000011327using a less accurate calculation.
Sean Silvab084af42012-12-07 10:36:55 +000011328
11329'``llvm.fma.*``' Intrinsic
11330^^^^^^^^^^^^^^^^^^^^^^^^^^
11331
11332Syntax:
11333"""""""
11334
11335This is an overloaded intrinsic. You can use ``llvm.fma`` on any
Sanjay Patel629c4112017-11-06 16:27:15 +000011336floating-point or vector of floating-point type. Not all targets support
Sean Silvab084af42012-12-07 10:36:55 +000011337all types however.
11338
11339::
11340
11341 declare float @llvm.fma.f32(float %a, float %b, float %c)
11342 declare double @llvm.fma.f64(double %a, double %b, double %c)
11343 declare x86_fp80 @llvm.fma.f80(x86_fp80 %a, x86_fp80 %b, x86_fp80 %c)
11344 declare fp128 @llvm.fma.f128(fp128 %a, fp128 %b, fp128 %c)
11345 declare ppc_fp128 @llvm.fma.ppcf128(ppc_fp128 %a, ppc_fp128 %b, ppc_fp128 %c)
11346
11347Overview:
11348"""""""""
11349
Sanjay Patel629c4112017-11-06 16:27:15 +000011350The '``llvm.fma.*``' intrinsics perform the fused multiply-add operation.
Sean Silvab084af42012-12-07 10:36:55 +000011351
11352Arguments:
11353""""""""""
11354
Sanjay Patel629c4112017-11-06 16:27:15 +000011355The arguments and return value are floating-point numbers of the same type.
Sean Silvab084af42012-12-07 10:36:55 +000011356
11357Semantics:
11358""""""""""
11359
Sanjay Patel629c4112017-11-06 16:27:15 +000011360Return the same value as a corresponding libm '``fma``' function but without
11361trapping or setting ``errno``.
11362
Elena Demikhovsky945b7e52018-02-14 06:58:08 +000011363When specified with the fast-math-flag 'afn', the result may be approximated
Sanjay Patel629c4112017-11-06 16:27:15 +000011364using a less accurate calculation.
Sean Silvab084af42012-12-07 10:36:55 +000011365
11366'``llvm.fabs.*``' Intrinsic
11367^^^^^^^^^^^^^^^^^^^^^^^^^^^
11368
11369Syntax:
11370"""""""
11371
11372This is an overloaded intrinsic. You can use ``llvm.fabs`` on any
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000011373floating-point or vector of floating-point type. Not all targets support
Sean Silvab084af42012-12-07 10:36:55 +000011374all types however.
11375
11376::
11377
11378 declare float @llvm.fabs.f32(float %Val)
11379 declare double @llvm.fabs.f64(double %Val)
Matt Arsenaultd6511b42014-10-21 23:00:20 +000011380 declare x86_fp80 @llvm.fabs.f80(x86_fp80 %Val)
Sean Silvab084af42012-12-07 10:36:55 +000011381 declare fp128 @llvm.fabs.f128(fp128 %Val)
Matt Arsenaultd6511b42014-10-21 23:00:20 +000011382 declare ppc_fp128 @llvm.fabs.ppcf128(ppc_fp128 %Val)
Sean Silvab084af42012-12-07 10:36:55 +000011383
11384Overview:
11385"""""""""
11386
11387The '``llvm.fabs.*``' intrinsics return the absolute value of the
11388operand.
11389
11390Arguments:
11391""""""""""
11392
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000011393The argument and return value are floating-point numbers of the same
Sean Silvab084af42012-12-07 10:36:55 +000011394type.
11395
11396Semantics:
11397""""""""""
11398
11399This function returns the same values as the libm ``fabs`` functions
11400would, and handles error conditions in the same way.
11401
Matt Arsenaultd6511b42014-10-21 23:00:20 +000011402'``llvm.minnum.*``' Intrinsic
Matt Arsenault9886b0d2014-10-22 00:15:53 +000011403^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Matt Arsenaultd6511b42014-10-21 23:00:20 +000011404
11405Syntax:
11406"""""""
11407
11408This is an overloaded intrinsic. You can use ``llvm.minnum`` on any
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000011409floating-point or vector of floating-point type. Not all targets support
Matt Arsenaultd6511b42014-10-21 23:00:20 +000011410all types however.
11411
11412::
11413
Matt Arsenault64313c92014-10-22 18:25:02 +000011414 declare float @llvm.minnum.f32(float %Val0, float %Val1)
11415 declare double @llvm.minnum.f64(double %Val0, double %Val1)
11416 declare x86_fp80 @llvm.minnum.f80(x86_fp80 %Val0, x86_fp80 %Val1)
11417 declare fp128 @llvm.minnum.f128(fp128 %Val0, fp128 %Val1)
11418 declare ppc_fp128 @llvm.minnum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1)
Matt Arsenaultd6511b42014-10-21 23:00:20 +000011419
11420Overview:
11421"""""""""
11422
11423The '``llvm.minnum.*``' intrinsics return the minimum of the two
11424arguments.
11425
11426
11427Arguments:
11428""""""""""
11429
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000011430The arguments and return value are floating-point numbers of the same
Matt Arsenaultd6511b42014-10-21 23:00:20 +000011431type.
11432
11433Semantics:
11434""""""""""
11435
11436Follows the IEEE-754 semantics for minNum, which also match for libm's
11437fmin.
11438
11439If either operand is a NaN, returns the other non-NaN operand. Returns
11440NaN only if both operands are NaN. If the operands compare equal,
11441returns a value that compares equal to both operands. This means that
11442fmin(+/-0.0, +/-0.0) could return either -0.0 or 0.0.
11443
11444'``llvm.maxnum.*``' Intrinsic
Matt Arsenault9886b0d2014-10-22 00:15:53 +000011445^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Matt Arsenaultd6511b42014-10-21 23:00:20 +000011446
11447Syntax:
11448"""""""
11449
11450This is an overloaded intrinsic. You can use ``llvm.maxnum`` on any
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000011451floating-point or vector of floating-point type. Not all targets support
Matt Arsenaultd6511b42014-10-21 23:00:20 +000011452all types however.
11453
11454::
11455
Matt Arsenault64313c92014-10-22 18:25:02 +000011456 declare float @llvm.maxnum.f32(float %Val0, float %Val1l)
11457 declare double @llvm.maxnum.f64(double %Val0, double %Val1)
11458 declare x86_fp80 @llvm.maxnum.f80(x86_fp80 %Val0, x86_fp80 %Val1)
11459 declare fp128 @llvm.maxnum.f128(fp128 %Val0, fp128 %Val1)
11460 declare ppc_fp128 @llvm.maxnum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1)
Matt Arsenaultd6511b42014-10-21 23:00:20 +000011461
11462Overview:
11463"""""""""
11464
11465The '``llvm.maxnum.*``' intrinsics return the maximum of the two
11466arguments.
11467
11468
11469Arguments:
11470""""""""""
11471
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000011472The arguments and return value are floating-point numbers of the same
Matt Arsenaultd6511b42014-10-21 23:00:20 +000011473type.
11474
11475Semantics:
11476""""""""""
11477Follows the IEEE-754 semantics for maxNum, which also match for libm's
11478fmax.
11479
11480If either operand is a NaN, returns the other non-NaN operand. Returns
11481NaN only if both operands are NaN. If the operands compare equal,
11482returns a value that compares equal to both operands. This means that
11483fmax(+/-0.0, +/-0.0) could return either -0.0 or 0.0.
11484
Hal Finkel0c5c01aa2013-08-19 23:35:46 +000011485'``llvm.copysign.*``' Intrinsic
11486^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11487
11488Syntax:
11489"""""""
11490
11491This is an overloaded intrinsic. You can use ``llvm.copysign`` on any
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000011492floating-point or vector of floating-point type. Not all targets support
Hal Finkel0c5c01aa2013-08-19 23:35:46 +000011493all types however.
11494
11495::
11496
11497 declare float @llvm.copysign.f32(float %Mag, float %Sgn)
11498 declare double @llvm.copysign.f64(double %Mag, double %Sgn)
11499 declare x86_fp80 @llvm.copysign.f80(x86_fp80 %Mag, x86_fp80 %Sgn)
11500 declare fp128 @llvm.copysign.f128(fp128 %Mag, fp128 %Sgn)
11501 declare ppc_fp128 @llvm.copysign.ppcf128(ppc_fp128 %Mag, ppc_fp128 %Sgn)
11502
11503Overview:
11504"""""""""
11505
11506The '``llvm.copysign.*``' intrinsics return a value with the magnitude of the
11507first operand and the sign of the second operand.
11508
11509Arguments:
11510""""""""""
11511
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000011512The arguments and return value are floating-point numbers of the same
Hal Finkel0c5c01aa2013-08-19 23:35:46 +000011513type.
11514
11515Semantics:
11516""""""""""
11517
11518This function returns the same values as the libm ``copysign``
11519functions would, and handles error conditions in the same way.
11520
Sean Silvab084af42012-12-07 10:36:55 +000011521'``llvm.floor.*``' Intrinsic
11522^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11523
11524Syntax:
11525"""""""
11526
11527This is an overloaded intrinsic. You can use ``llvm.floor`` on any
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000011528floating-point or vector of floating-point type. Not all targets support
Sean Silvab084af42012-12-07 10:36:55 +000011529all types however.
11530
11531::
11532
11533 declare float @llvm.floor.f32(float %Val)
11534 declare double @llvm.floor.f64(double %Val)
11535 declare x86_fp80 @llvm.floor.f80(x86_fp80 %Val)
11536 declare fp128 @llvm.floor.f128(fp128 %Val)
11537 declare ppc_fp128 @llvm.floor.ppcf128(ppc_fp128 %Val)
11538
11539Overview:
11540"""""""""
11541
11542The '``llvm.floor.*``' intrinsics return the floor of the operand.
11543
11544Arguments:
11545""""""""""
11546
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000011547The argument and return value are floating-point numbers of the same
Sean Silvab084af42012-12-07 10:36:55 +000011548type.
11549
11550Semantics:
11551""""""""""
11552
11553This function returns the same values as the libm ``floor`` functions
11554would, and handles error conditions in the same way.
11555
11556'``llvm.ceil.*``' Intrinsic
11557^^^^^^^^^^^^^^^^^^^^^^^^^^^
11558
11559Syntax:
11560"""""""
11561
11562This is an overloaded intrinsic. You can use ``llvm.ceil`` on any
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000011563floating-point or vector of floating-point type. Not all targets support
Sean Silvab084af42012-12-07 10:36:55 +000011564all types however.
11565
11566::
11567
11568 declare float @llvm.ceil.f32(float %Val)
11569 declare double @llvm.ceil.f64(double %Val)
11570 declare x86_fp80 @llvm.ceil.f80(x86_fp80 %Val)
11571 declare fp128 @llvm.ceil.f128(fp128 %Val)
11572 declare ppc_fp128 @llvm.ceil.ppcf128(ppc_fp128 %Val)
11573
11574Overview:
11575"""""""""
11576
11577The '``llvm.ceil.*``' intrinsics return the ceiling of the operand.
11578
11579Arguments:
11580""""""""""
11581
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000011582The argument and return value are floating-point numbers of the same
Sean Silvab084af42012-12-07 10:36:55 +000011583type.
11584
11585Semantics:
11586""""""""""
11587
11588This function returns the same values as the libm ``ceil`` functions
11589would, and handles error conditions in the same way.
11590
11591'``llvm.trunc.*``' Intrinsic
11592^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11593
11594Syntax:
11595"""""""
11596
11597This is an overloaded intrinsic. You can use ``llvm.trunc`` on any
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000011598floating-point or vector of floating-point type. Not all targets support
Sean Silvab084af42012-12-07 10:36:55 +000011599all types however.
11600
11601::
11602
11603 declare float @llvm.trunc.f32(float %Val)
11604 declare double @llvm.trunc.f64(double %Val)
11605 declare x86_fp80 @llvm.trunc.f80(x86_fp80 %Val)
11606 declare fp128 @llvm.trunc.f128(fp128 %Val)
11607 declare ppc_fp128 @llvm.trunc.ppcf128(ppc_fp128 %Val)
11608
11609Overview:
11610"""""""""
11611
11612The '``llvm.trunc.*``' intrinsics returns the operand rounded to the
11613nearest integer not larger in magnitude than the operand.
11614
11615Arguments:
11616""""""""""
11617
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000011618The argument and return value are floating-point numbers of the same
Sean Silvab084af42012-12-07 10:36:55 +000011619type.
11620
11621Semantics:
11622""""""""""
11623
11624This function returns the same values as the libm ``trunc`` functions
11625would, and handles error conditions in the same way.
11626
11627'``llvm.rint.*``' Intrinsic
11628^^^^^^^^^^^^^^^^^^^^^^^^^^^
11629
11630Syntax:
11631"""""""
11632
11633This is an overloaded intrinsic. You can use ``llvm.rint`` on any
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000011634floating-point or vector of floating-point type. Not all targets support
Sean Silvab084af42012-12-07 10:36:55 +000011635all types however.
11636
11637::
11638
11639 declare float @llvm.rint.f32(float %Val)
11640 declare double @llvm.rint.f64(double %Val)
11641 declare x86_fp80 @llvm.rint.f80(x86_fp80 %Val)
11642 declare fp128 @llvm.rint.f128(fp128 %Val)
11643 declare ppc_fp128 @llvm.rint.ppcf128(ppc_fp128 %Val)
11644
11645Overview:
11646"""""""""
11647
11648The '``llvm.rint.*``' intrinsics returns the operand rounded to the
11649nearest integer. It may raise an inexact floating-point exception if the
11650operand isn't an integer.
11651
11652Arguments:
11653""""""""""
11654
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000011655The argument and return value are floating-point numbers of the same
Sean Silvab084af42012-12-07 10:36:55 +000011656type.
11657
11658Semantics:
11659""""""""""
11660
11661This function returns the same values as the libm ``rint`` functions
11662would, and handles error conditions in the same way.
11663
11664'``llvm.nearbyint.*``' Intrinsic
11665^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11666
11667Syntax:
11668"""""""
11669
11670This is an overloaded intrinsic. You can use ``llvm.nearbyint`` on any
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000011671floating-point or vector of floating-point type. Not all targets support
Sean Silvab084af42012-12-07 10:36:55 +000011672all types however.
11673
11674::
11675
11676 declare float @llvm.nearbyint.f32(float %Val)
11677 declare double @llvm.nearbyint.f64(double %Val)
11678 declare x86_fp80 @llvm.nearbyint.f80(x86_fp80 %Val)
11679 declare fp128 @llvm.nearbyint.f128(fp128 %Val)
11680 declare ppc_fp128 @llvm.nearbyint.ppcf128(ppc_fp128 %Val)
11681
11682Overview:
11683"""""""""
11684
11685The '``llvm.nearbyint.*``' intrinsics returns the operand rounded to the
11686nearest integer.
11687
11688Arguments:
11689""""""""""
11690
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000011691The argument and return value are floating-point numbers of the same
Sean Silvab084af42012-12-07 10:36:55 +000011692type.
11693
11694Semantics:
11695""""""""""
11696
11697This function returns the same values as the libm ``nearbyint``
11698functions would, and handles error conditions in the same way.
11699
Hal Finkel171817e2013-08-07 22:49:12 +000011700'``llvm.round.*``' Intrinsic
11701^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11702
11703Syntax:
11704"""""""
11705
11706This is an overloaded intrinsic. You can use ``llvm.round`` on any
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000011707floating-point or vector of floating-point type. Not all targets support
Hal Finkel171817e2013-08-07 22:49:12 +000011708all types however.
11709
11710::
11711
11712 declare float @llvm.round.f32(float %Val)
11713 declare double @llvm.round.f64(double %Val)
11714 declare x86_fp80 @llvm.round.f80(x86_fp80 %Val)
11715 declare fp128 @llvm.round.f128(fp128 %Val)
11716 declare ppc_fp128 @llvm.round.ppcf128(ppc_fp128 %Val)
11717
11718Overview:
11719"""""""""
11720
11721The '``llvm.round.*``' intrinsics returns the operand rounded to the
11722nearest integer.
11723
11724Arguments:
11725""""""""""
11726
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000011727The argument and return value are floating-point numbers of the same
Hal Finkel171817e2013-08-07 22:49:12 +000011728type.
11729
11730Semantics:
11731""""""""""
11732
11733This function returns the same values as the libm ``round``
11734functions would, and handles error conditions in the same way.
11735
Sean Silvab084af42012-12-07 10:36:55 +000011736Bit Manipulation Intrinsics
11737---------------------------
11738
11739LLVM provides intrinsics for a few important bit manipulation
11740operations. These allow efficient code generation for some algorithms.
11741
James Molloy90111f72015-11-12 12:29:09 +000011742'``llvm.bitreverse.*``' Intrinsics
Akira Hatanaka7f5562b2015-11-13 21:09:57 +000011743^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
James Molloy90111f72015-11-12 12:29:09 +000011744
11745Syntax:
11746"""""""
11747
11748This is an overloaded intrinsic function. You can use bitreverse on any
11749integer type.
11750
11751::
11752
11753 declare i16 @llvm.bitreverse.i16(i16 <id>)
11754 declare i32 @llvm.bitreverse.i32(i32 <id>)
11755 declare i64 @llvm.bitreverse.i64(i64 <id>)
11756
11757Overview:
11758"""""""""
11759
11760The '``llvm.bitreverse``' family of intrinsics is used to reverse the
Matt Arsenaultde2d6a32016-03-07 21:54:52 +000011761bitpattern of an integer value; for example ``0b10110110`` becomes
11762``0b01101101``.
James Molloy90111f72015-11-12 12:29:09 +000011763
11764Semantics:
11765""""""""""
11766
Yichao Yu5abf14b2016-11-23 16:25:31 +000011767The ``llvm.bitreverse.iN`` intrinsic returns an iN value that has bit
James Molloy90111f72015-11-12 12:29:09 +000011768``M`` in the input moved to bit ``N-M`` in the output.
11769
Sean Silvab084af42012-12-07 10:36:55 +000011770'``llvm.bswap.*``' Intrinsics
11771^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11772
11773Syntax:
11774"""""""
11775
11776This is an overloaded intrinsic function. You can use bswap on any
11777integer type that is an even number of bytes (i.e. BitWidth % 16 == 0).
11778
11779::
11780
11781 declare i16 @llvm.bswap.i16(i16 <id>)
11782 declare i32 @llvm.bswap.i32(i32 <id>)
11783 declare i64 @llvm.bswap.i64(i64 <id>)
11784
11785Overview:
11786"""""""""
11787
11788The '``llvm.bswap``' family of intrinsics is used to byte swap integer
11789values with an even number of bytes (positive multiple of 16 bits).
11790These are useful for performing operations on data that is not in the
11791target's native byte order.
11792
11793Semantics:
11794""""""""""
11795
11796The ``llvm.bswap.i16`` intrinsic returns an i16 value that has the high
11797and low byte of the input i16 swapped. Similarly, the ``llvm.bswap.i32``
11798intrinsic returns an i32 value that has the four bytes of the input i32
11799swapped, so that if the input bytes are numbered 0, 1, 2, 3 then the
11800returned i32 will have its bytes in 3, 2, 1, 0 order. The
11801``llvm.bswap.i48``, ``llvm.bswap.i64`` and other intrinsics extend this
11802concept to additional even-byte lengths (6 bytes, 8 bytes and more,
11803respectively).
11804
11805'``llvm.ctpop.*``' Intrinsic
11806^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11807
11808Syntax:
11809"""""""
11810
11811This is an overloaded intrinsic. You can use llvm.ctpop on any integer
11812bit width, or on any vector with integer elements. Not all targets
11813support all bit widths or vector types, however.
11814
11815::
11816
11817 declare i8 @llvm.ctpop.i8(i8 <src>)
11818 declare i16 @llvm.ctpop.i16(i16 <src>)
11819 declare i32 @llvm.ctpop.i32(i32 <src>)
11820 declare i64 @llvm.ctpop.i64(i64 <src>)
11821 declare i256 @llvm.ctpop.i256(i256 <src>)
11822 declare <2 x i32> @llvm.ctpop.v2i32(<2 x i32> <src>)
11823
11824Overview:
11825"""""""""
11826
11827The '``llvm.ctpop``' family of intrinsics counts the number of bits set
11828in a value.
11829
11830Arguments:
11831""""""""""
11832
11833The only argument is the value to be counted. The argument may be of any
11834integer type, or a vector with integer elements. The return type must
11835match the argument type.
11836
11837Semantics:
11838""""""""""
11839
11840The '``llvm.ctpop``' intrinsic counts the 1's in a variable, or within
11841each element of a vector.
11842
11843'``llvm.ctlz.*``' Intrinsic
11844^^^^^^^^^^^^^^^^^^^^^^^^^^^
11845
11846Syntax:
11847"""""""
11848
11849This is an overloaded intrinsic. You can use ``llvm.ctlz`` on any
11850integer bit width, or any vector whose elements are integers. Not all
11851targets support all bit widths or vector types, however.
11852
11853::
11854
11855 declare i8 @llvm.ctlz.i8 (i8 <src>, i1 <is_zero_undef>)
11856 declare i16 @llvm.ctlz.i16 (i16 <src>, i1 <is_zero_undef>)
11857 declare i32 @llvm.ctlz.i32 (i32 <src>, i1 <is_zero_undef>)
11858 declare i64 @llvm.ctlz.i64 (i64 <src>, i1 <is_zero_undef>)
11859 declare i256 @llvm.ctlz.i256(i256 <src>, i1 <is_zero_undef>)
Alexey Samsonovc4b18302016-03-17 23:08:01 +000011860 declare <2 x i32> @llvm.ctlz.v2i32(<2 x i32> <src>, i1 <is_zero_undef>)
Sean Silvab084af42012-12-07 10:36:55 +000011861
11862Overview:
11863"""""""""
11864
11865The '``llvm.ctlz``' family of intrinsic functions counts the number of
11866leading zeros in a variable.
11867
11868Arguments:
11869""""""""""
11870
11871The first argument is the value to be counted. This argument may be of
Hal Finkel5dd82782015-01-05 04:05:21 +000011872any integer type, or a vector with integer element type. The return
Sean Silvab084af42012-12-07 10:36:55 +000011873type must match the first argument type.
11874
11875The second argument must be a constant and is a flag to indicate whether
11876the intrinsic should ensure that a zero as the first argument produces a
11877defined result. Historically some architectures did not provide a
11878defined result for zero values as efficiently, and many algorithms are
11879now predicated on avoiding zero-value inputs.
11880
11881Semantics:
11882""""""""""
11883
11884The '``llvm.ctlz``' intrinsic counts the leading (most significant)
11885zeros in a variable, or within each element of the vector. If
11886``src == 0`` then the result is the size in bits of the type of ``src``
11887if ``is_zero_undef == 0`` and ``undef`` otherwise. For example,
11888``llvm.ctlz(i32 2) = 30``.
11889
11890'``llvm.cttz.*``' Intrinsic
11891^^^^^^^^^^^^^^^^^^^^^^^^^^^
11892
11893Syntax:
11894"""""""
11895
11896This is an overloaded intrinsic. You can use ``llvm.cttz`` on any
11897integer bit width, or any vector of integer elements. Not all targets
11898support all bit widths or vector types, however.
11899
11900::
11901
11902 declare i8 @llvm.cttz.i8 (i8 <src>, i1 <is_zero_undef>)
11903 declare i16 @llvm.cttz.i16 (i16 <src>, i1 <is_zero_undef>)
11904 declare i32 @llvm.cttz.i32 (i32 <src>, i1 <is_zero_undef>)
11905 declare i64 @llvm.cttz.i64 (i64 <src>, i1 <is_zero_undef>)
11906 declare i256 @llvm.cttz.i256(i256 <src>, i1 <is_zero_undef>)
Alexey Samsonovc4b18302016-03-17 23:08:01 +000011907 declare <2 x i32> @llvm.cttz.v2i32(<2 x i32> <src>, i1 <is_zero_undef>)
Sean Silvab084af42012-12-07 10:36:55 +000011908
11909Overview:
11910"""""""""
11911
11912The '``llvm.cttz``' family of intrinsic functions counts the number of
11913trailing zeros.
11914
11915Arguments:
11916""""""""""
11917
11918The first argument is the value to be counted. This argument may be of
Hal Finkel5dd82782015-01-05 04:05:21 +000011919any integer type, or a vector with integer element type. The return
Sean Silvab084af42012-12-07 10:36:55 +000011920type must match the first argument type.
11921
11922The second argument must be a constant and is a flag to indicate whether
11923the intrinsic should ensure that a zero as the first argument produces a
11924defined result. Historically some architectures did not provide a
11925defined result for zero values as efficiently, and many algorithms are
11926now predicated on avoiding zero-value inputs.
11927
11928Semantics:
11929""""""""""
11930
11931The '``llvm.cttz``' intrinsic counts the trailing (least significant)
11932zeros in a variable, or within each element of a vector. If ``src == 0``
11933then the result is the size in bits of the type of ``src`` if
11934``is_zero_undef == 0`` and ``undef`` otherwise. For example,
11935``llvm.cttz(2) = 1``.
11936
Philip Reames34843ae2015-03-05 05:55:55 +000011937.. _int_overflow:
11938
Sanjay Patelc71adc82018-07-16 22:59:31 +000011939'``llvm.fshl.*``' Intrinsic
11940^^^^^^^^^^^^^^^^^^^^^^^^^^^
11941
11942Syntax:
11943"""""""
11944
11945This is an overloaded intrinsic. You can use ``llvm.fshl`` on any
11946integer bit width or any vector of integer elements. Not all targets
11947support all bit widths or vector types, however.
11948
11949::
11950
11951 declare i8 @llvm.fshl.i8 (i8 %a, i8 %b, i8 %c)
11952 declare i67 @llvm.fshl.i67(i67 %a, i67 %b, i67 %c)
11953 declare <2 x i32> @llvm.fshl.v2i32(<2 x i32> %a, <2 x i32> %b, <2 x i32> %c)
11954
11955Overview:
11956"""""""""
11957
11958The '``llvm.fshl``' family of intrinsic functions performs a funnel shift left:
11959the first two values are concatenated as { %a : %b } (%a is the most significant
11960bits of the wide value), the combined value is shifted left, and the most
11961significant bits are extracted to produce a result that is the same size as the
11962original arguments. If the first 2 arguments are identical, this is equivalent
11963to a rotate left operation. For vector types, the operation occurs for each
11964element of the vector. The shift argument is treated as an unsigned amount
11965modulo the element size of the arguments.
11966
11967Arguments:
11968""""""""""
11969
11970The first two arguments are the values to be concatenated. The third
11971argument is the shift amount. The arguments may be any integer type or a
11972vector with integer element type. All arguments and the return value must
11973have the same type.
11974
11975Example:
11976""""""""
11977
11978.. code-block:: text
11979
11980 %r = call i8 @llvm.fshl.i8(i8 %x, i8 %y, i8 %z) ; %r = i8: msb_extract((concat(x, y) << (z % 8)), 8)
11981 %r = call i8 @llvm.fshl.i8(i8 255, i8 0, i8 15) ; %r = i8: 128 (0b10000000)
11982 %r = call i8 @llvm.fshl.i8(i8 15, i8 15, i8 11) ; %r = i8: 120 (0b01111000)
11983 %r = call i8 @llvm.fshl.i8(i8 0, i8 255, i8 8) ; %r = i8: 0 (0b00000000)
11984
11985'``llvm.fshr.*``' Intrinsic
11986^^^^^^^^^^^^^^^^^^^^^^^^^^^
11987
11988Syntax:
11989"""""""
11990
11991This is an overloaded intrinsic. You can use ``llvm.fshr`` on any
11992integer bit width or any vector of integer elements. Not all targets
11993support all bit widths or vector types, however.
11994
11995::
11996
11997 declare i8 @llvm.fshr.i8 (i8 %a, i8 %b, i8 %c)
11998 declare i67 @llvm.fshr.i67(i67 %a, i67 %b, i67 %c)
11999 declare <2 x i32> @llvm.fshr.v2i32(<2 x i32> %a, <2 x i32> %b, <2 x i32> %c)
12000
12001Overview:
12002"""""""""
12003
12004The '``llvm.fshr``' family of intrinsic functions performs a funnel shift right:
12005the first two values are concatenated as { %a : %b } (%a is the most significant
12006bits of the wide value), the combined value is shifted right, and the least
12007significant bits are extracted to produce a result that is the same size as the
12008original arguments. If the first 2 arguments are identical, this is equivalent
12009to a rotate right operation. For vector types, the operation occurs for each
12010element of the vector. The shift argument is treated as an unsigned amount
12011modulo the element size of the arguments.
12012
12013Arguments:
12014""""""""""
12015
12016The first two arguments are the values to be concatenated. The third
12017argument is the shift amount. The arguments may be any integer type or a
12018vector with integer element type. All arguments and the return value must
12019have the same type.
12020
12021Example:
12022""""""""
12023
12024.. code-block:: text
12025
12026 %r = call i8 @llvm.fshr.i8(i8 %x, i8 %y, i8 %z) ; %r = i8: lsb_extract((concat(x, y) >> (z % 8)), 8)
12027 %r = call i8 @llvm.fshr.i8(i8 255, i8 0, i8 15) ; %r = i8: 254 (0b11111110)
12028 %r = call i8 @llvm.fshr.i8(i8 15, i8 15, i8 11) ; %r = i8: 225 (0b11100001)
12029 %r = call i8 @llvm.fshr.i8(i8 0, i8 255, i8 8) ; %r = i8: 255 (0b11111111)
12030
Sean Silvab084af42012-12-07 10:36:55 +000012031Arithmetic with Overflow Intrinsics
12032-----------------------------------
12033
John Regehr6a493f22016-05-12 20:55:09 +000012034LLVM provides intrinsics for fast arithmetic overflow checking.
12035
12036Each of these intrinsics returns a two-element struct. The first
12037element of this struct contains the result of the corresponding
12038arithmetic operation modulo 2\ :sup:`n`\ , where n is the bit width of
12039the result. Therefore, for example, the first element of the struct
12040returned by ``llvm.sadd.with.overflow.i32`` is always the same as the
12041result of a 32-bit ``add`` instruction with the same operands, where
12042the ``add`` is *not* modified by an ``nsw`` or ``nuw`` flag.
12043
12044The second element of the result is an ``i1`` that is 1 if the
12045arithmetic operation overflowed and 0 otherwise. An operation
12046overflows if, for any values of its operands ``A`` and ``B`` and for
12047any ``N`` larger than the operands' width, ``ext(A op B) to iN`` is
12048not equal to ``(ext(A) to iN) op (ext(B) to iN)`` where ``ext`` is
12049``sext`` for signed overflow and ``zext`` for unsigned overflow, and
12050``op`` is the underlying arithmetic operation.
12051
12052The behavior of these intrinsics is well-defined for all argument
12053values.
Sean Silvab084af42012-12-07 10:36:55 +000012054
12055'``llvm.sadd.with.overflow.*``' Intrinsics
12056^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12057
12058Syntax:
12059"""""""
12060
12061This is an overloaded intrinsic. You can use ``llvm.sadd.with.overflow``
12062on any integer bit width.
12063
12064::
12065
12066 declare {i16, i1} @llvm.sadd.with.overflow.i16(i16 %a, i16 %b)
12067 declare {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b)
12068 declare {i64, i1} @llvm.sadd.with.overflow.i64(i64 %a, i64 %b)
12069
12070Overview:
12071"""""""""
12072
12073The '``llvm.sadd.with.overflow``' family of intrinsic functions perform
12074a signed addition of the two arguments, and indicate whether an overflow
12075occurred during the signed summation.
12076
12077Arguments:
12078""""""""""
12079
12080The arguments (%a and %b) and the first element of the result structure
12081may be of integer types of any bit width, but they must have the same
12082bit width. The second element of the result structure must be of type
12083``i1``. ``%a`` and ``%b`` are the two values that will undergo signed
12084addition.
12085
12086Semantics:
12087""""""""""
12088
12089The '``llvm.sadd.with.overflow``' family of intrinsic functions perform
Dmitri Gribenkoe8131122013-01-19 20:34:20 +000012090a signed addition of the two variables. They return a structure --- the
Sean Silvab084af42012-12-07 10:36:55 +000012091first element of which is the signed summation, and the second element
12092of which is a bit specifying if the signed summation resulted in an
12093overflow.
12094
12095Examples:
12096"""""""""
12097
12098.. code-block:: llvm
12099
12100 %res = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b)
12101 %sum = extractvalue {i32, i1} %res, 0
12102 %obit = extractvalue {i32, i1} %res, 1
12103 br i1 %obit, label %overflow, label %normal
12104
12105'``llvm.uadd.with.overflow.*``' Intrinsics
12106^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12107
12108Syntax:
12109"""""""
12110
12111This is an overloaded intrinsic. You can use ``llvm.uadd.with.overflow``
12112on any integer bit width.
12113
12114::
12115
12116 declare {i16, i1} @llvm.uadd.with.overflow.i16(i16 %a, i16 %b)
12117 declare {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b)
12118 declare {i64, i1} @llvm.uadd.with.overflow.i64(i64 %a, i64 %b)
12119
12120Overview:
12121"""""""""
12122
12123The '``llvm.uadd.with.overflow``' family of intrinsic functions perform
12124an unsigned addition of the two arguments, and indicate whether a carry
12125occurred during the unsigned summation.
12126
12127Arguments:
12128""""""""""
12129
12130The arguments (%a and %b) and the first element of the result structure
12131may be of integer types of any bit width, but they must have the same
12132bit width. The second element of the result structure must be of type
12133``i1``. ``%a`` and ``%b`` are the two values that will undergo unsigned
12134addition.
12135
12136Semantics:
12137""""""""""
12138
12139The '``llvm.uadd.with.overflow``' family of intrinsic functions perform
Dmitri Gribenkoe8131122013-01-19 20:34:20 +000012140an unsigned addition of the two arguments. They return a structure --- the
Sean Silvab084af42012-12-07 10:36:55 +000012141first element of which is the sum, and the second element of which is a
12142bit specifying if the unsigned summation resulted in a carry.
12143
12144Examples:
12145"""""""""
12146
12147.. code-block:: llvm
12148
12149 %res = call {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b)
12150 %sum = extractvalue {i32, i1} %res, 0
12151 %obit = extractvalue {i32, i1} %res, 1
12152 br i1 %obit, label %carry, label %normal
12153
12154'``llvm.ssub.with.overflow.*``' Intrinsics
12155^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12156
12157Syntax:
12158"""""""
12159
12160This is an overloaded intrinsic. You can use ``llvm.ssub.with.overflow``
12161on any integer bit width.
12162
12163::
12164
12165 declare {i16, i1} @llvm.ssub.with.overflow.i16(i16 %a, i16 %b)
12166 declare {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a, i32 %b)
12167 declare {i64, i1} @llvm.ssub.with.overflow.i64(i64 %a, i64 %b)
12168
12169Overview:
12170"""""""""
12171
12172The '``llvm.ssub.with.overflow``' family of intrinsic functions perform
12173a signed subtraction of the two arguments, and indicate whether an
12174overflow occurred during the signed subtraction.
12175
12176Arguments:
12177""""""""""
12178
12179The arguments (%a and %b) and the first element of the result structure
12180may be of integer types of any bit width, but they must have the same
12181bit width. The second element of the result structure must be of type
12182``i1``. ``%a`` and ``%b`` are the two values that will undergo signed
12183subtraction.
12184
12185Semantics:
12186""""""""""
12187
12188The '``llvm.ssub.with.overflow``' family of intrinsic functions perform
Dmitri Gribenkoe8131122013-01-19 20:34:20 +000012189a signed subtraction of the two arguments. They return a structure --- the
Sean Silvab084af42012-12-07 10:36:55 +000012190first element of which is the subtraction, and the second element of
12191which is a bit specifying if the signed subtraction resulted in an
12192overflow.
12193
12194Examples:
12195"""""""""
12196
12197.. code-block:: llvm
12198
12199 %res = call {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a, i32 %b)
12200 %sum = extractvalue {i32, i1} %res, 0
12201 %obit = extractvalue {i32, i1} %res, 1
12202 br i1 %obit, label %overflow, label %normal
12203
12204'``llvm.usub.with.overflow.*``' Intrinsics
12205^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12206
12207Syntax:
12208"""""""
12209
12210This is an overloaded intrinsic. You can use ``llvm.usub.with.overflow``
12211on any integer bit width.
12212
12213::
12214
12215 declare {i16, i1} @llvm.usub.with.overflow.i16(i16 %a, i16 %b)
12216 declare {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b)
12217 declare {i64, i1} @llvm.usub.with.overflow.i64(i64 %a, i64 %b)
12218
12219Overview:
12220"""""""""
12221
12222The '``llvm.usub.with.overflow``' family of intrinsic functions perform
12223an unsigned subtraction of the two arguments, and indicate whether an
12224overflow occurred during the unsigned subtraction.
12225
12226Arguments:
12227""""""""""
12228
12229The arguments (%a and %b) and the first element of the result structure
12230may be of integer types of any bit width, but they must have the same
12231bit width. The second element of the result structure must be of type
12232``i1``. ``%a`` and ``%b`` are the two values that will undergo unsigned
12233subtraction.
12234
12235Semantics:
12236""""""""""
12237
12238The '``llvm.usub.with.overflow``' family of intrinsic functions perform
Dmitri Gribenkoe8131122013-01-19 20:34:20 +000012239an unsigned subtraction of the two arguments. They return a structure ---
Sean Silvab084af42012-12-07 10:36:55 +000012240the first element of which is the subtraction, and the second element of
12241which is a bit specifying if the unsigned subtraction resulted in an
12242overflow.
12243
12244Examples:
12245"""""""""
12246
12247.. code-block:: llvm
12248
12249 %res = call {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b)
12250 %sum = extractvalue {i32, i1} %res, 0
12251 %obit = extractvalue {i32, i1} %res, 1
12252 br i1 %obit, label %overflow, label %normal
12253
12254'``llvm.smul.with.overflow.*``' Intrinsics
12255^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12256
12257Syntax:
12258"""""""
12259
12260This is an overloaded intrinsic. You can use ``llvm.smul.with.overflow``
12261on any integer bit width.
12262
12263::
12264
12265 declare {i16, i1} @llvm.smul.with.overflow.i16(i16 %a, i16 %b)
12266 declare {i32, i1} @llvm.smul.with.overflow.i32(i32 %a, i32 %b)
12267 declare {i64, i1} @llvm.smul.with.overflow.i64(i64 %a, i64 %b)
12268
12269Overview:
12270"""""""""
12271
12272The '``llvm.smul.with.overflow``' family of intrinsic functions perform
12273a signed multiplication of the two arguments, and indicate whether an
12274overflow occurred during the signed multiplication.
12275
12276Arguments:
12277""""""""""
12278
12279The arguments (%a and %b) and the first element of the result structure
12280may be of integer types of any bit width, but they must have the same
12281bit width. The second element of the result structure must be of type
12282``i1``. ``%a`` and ``%b`` are the two values that will undergo signed
12283multiplication.
12284
12285Semantics:
12286""""""""""
12287
12288The '``llvm.smul.with.overflow``' family of intrinsic functions perform
Dmitri Gribenkoe8131122013-01-19 20:34:20 +000012289a signed multiplication of the two arguments. They return a structure ---
Sean Silvab084af42012-12-07 10:36:55 +000012290the first element of which is the multiplication, and the second element
12291of which is a bit specifying if the signed multiplication resulted in an
12292overflow.
12293
12294Examples:
12295"""""""""
12296
12297.. code-block:: llvm
12298
12299 %res = call {i32, i1} @llvm.smul.with.overflow.i32(i32 %a, i32 %b)
12300 %sum = extractvalue {i32, i1} %res, 0
12301 %obit = extractvalue {i32, i1} %res, 1
12302 br i1 %obit, label %overflow, label %normal
12303
12304'``llvm.umul.with.overflow.*``' Intrinsics
12305^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12306
12307Syntax:
12308"""""""
12309
12310This is an overloaded intrinsic. You can use ``llvm.umul.with.overflow``
12311on any integer bit width.
12312
12313::
12314
12315 declare {i16, i1} @llvm.umul.with.overflow.i16(i16 %a, i16 %b)
12316 declare {i32, i1} @llvm.umul.with.overflow.i32(i32 %a, i32 %b)
12317 declare {i64, i1} @llvm.umul.with.overflow.i64(i64 %a, i64 %b)
12318
12319Overview:
12320"""""""""
12321
12322The '``llvm.umul.with.overflow``' family of intrinsic functions perform
12323a unsigned multiplication of the two arguments, and indicate whether an
12324overflow occurred during the unsigned multiplication.
12325
12326Arguments:
12327""""""""""
12328
12329The arguments (%a and %b) and the first element of the result structure
12330may be of integer types of any bit width, but they must have the same
12331bit width. The second element of the result structure must be of type
12332``i1``. ``%a`` and ``%b`` are the two values that will undergo unsigned
12333multiplication.
12334
12335Semantics:
12336""""""""""
12337
12338The '``llvm.umul.with.overflow``' family of intrinsic functions perform
Dmitri Gribenkoe8131122013-01-19 20:34:20 +000012339an unsigned multiplication of the two arguments. They return a structure ---
12340the first element of which is the multiplication, and the second
Sean Silvab084af42012-12-07 10:36:55 +000012341element of which is a bit specifying if the unsigned multiplication
12342resulted in an overflow.
12343
12344Examples:
12345"""""""""
12346
12347.. code-block:: llvm
12348
12349 %res = call {i32, i1} @llvm.umul.with.overflow.i32(i32 %a, i32 %b)
12350 %sum = extractvalue {i32, i1} %res, 0
12351 %obit = extractvalue {i32, i1} %res, 1
12352 br i1 %obit, label %overflow, label %normal
12353
12354Specialised Arithmetic Intrinsics
12355---------------------------------
12356
Owen Anderson1056a922015-07-11 07:01:27 +000012357'``llvm.canonicalize.*``' Intrinsic
12358^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12359
12360Syntax:
12361"""""""
12362
12363::
12364
12365 declare float @llvm.canonicalize.f32(float %a)
12366 declare double @llvm.canonicalize.f64(double %b)
12367
12368Overview:
12369"""""""""
12370
12371The '``llvm.canonicalize.*``' intrinsic returns the platform specific canonical
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000012372encoding of a floating-point number. This canonicalization is useful for
Owen Anderson1056a922015-07-11 07:01:27 +000012373implementing certain numeric primitives such as frexp. The canonical encoding is
12374defined by IEEE-754-2008 to be:
12375
12376::
12377
12378 2.1.8 canonical encoding: The preferred encoding of a floating-point
Sean Silvaa1190322015-08-06 22:56:48 +000012379 representation in a format. Applied to declets, significands of finite
Owen Anderson1056a922015-07-11 07:01:27 +000012380 numbers, infinities, and NaNs, especially in decimal formats.
12381
12382This operation can also be considered equivalent to the IEEE-754-2008
Sean Silvaa1190322015-08-06 22:56:48 +000012383conversion of a floating-point value to the same format. NaNs are handled
Owen Anderson1056a922015-07-11 07:01:27 +000012384according to section 6.2.
12385
12386Examples of non-canonical encodings:
12387
Sean Silvaa1190322015-08-06 22:56:48 +000012388- x87 pseudo denormals, pseudo NaNs, pseudo Infinity, Unnormals. These are
Owen Anderson1056a922015-07-11 07:01:27 +000012389 converted to a canonical representation per hardware-specific protocol.
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000012390- Many normal decimal floating-point numbers have non-canonical alternative
Owen Anderson1056a922015-07-11 07:01:27 +000012391 encodings.
12392- Some machines, like GPUs or ARMv7 NEON, do not support subnormal values.
Sanjay Patelcc330962016-02-24 23:44:19 +000012393 These are treated as non-canonical encodings of zero and will be flushed to
Owen Anderson1056a922015-07-11 07:01:27 +000012394 a zero of the same sign by this operation.
12395
12396Note that per IEEE-754-2008 6.2, systems that support signaling NaNs with
12397default exception handling must signal an invalid exception, and produce a
12398quiet NaN result.
12399
12400This function should always be implementable as multiplication by 1.0, provided
Sean Silvaa1190322015-08-06 22:56:48 +000012401that the compiler does not constant fold the operation. Likewise, division by
124021.0 and ``llvm.minnum(x, x)`` are possible implementations. Addition with
Owen Anderson1056a922015-07-11 07:01:27 +000012403-0.0 is also sufficient provided that the rounding mode is not -Infinity.
12404
Sean Silvaa1190322015-08-06 22:56:48 +000012405``@llvm.canonicalize`` must preserve the equality relation. That is:
Owen Anderson1056a922015-07-11 07:01:27 +000012406
12407- ``(@llvm.canonicalize(x) == x)`` is equivalent to ``(x == x)``
12408- ``(@llvm.canonicalize(x) == @llvm.canonicalize(y))`` is equivalent to
12409 to ``(x == y)``
12410
12411Additionally, the sign of zero must be conserved:
12412``@llvm.canonicalize(-0.0) = -0.0`` and ``@llvm.canonicalize(+0.0) = +0.0``
12413
12414The payload bits of a NaN must be conserved, with two exceptions.
12415First, environments which use only a single canonical representation of NaN
Sean Silvaa1190322015-08-06 22:56:48 +000012416must perform said canonicalization. Second, SNaNs must be quieted per the
Owen Anderson1056a922015-07-11 07:01:27 +000012417usual methods.
12418
12419The canonicalization operation may be optimized away if:
12420
Sean Silvaa1190322015-08-06 22:56:48 +000012421- The input is known to be canonical. For example, it was produced by a
Owen Anderson1056a922015-07-11 07:01:27 +000012422 floating-point operation that is required by the standard to be canonical.
12423- The result is consumed only by (or fused with) other floating-point
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000012424 operations. That is, the bits of the floating-point value are not examined.
Owen Anderson1056a922015-07-11 07:01:27 +000012425
Sean Silvab084af42012-12-07 10:36:55 +000012426'``llvm.fmuladd.*``' Intrinsic
12427^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12428
12429Syntax:
12430"""""""
12431
12432::
12433
12434 declare float @llvm.fmuladd.f32(float %a, float %b, float %c)
12435 declare double @llvm.fmuladd.f64(double %a, double %b, double %c)
12436
12437Overview:
12438"""""""""
12439
12440The '``llvm.fmuladd.*``' intrinsic functions represent multiply-add
Lang Hames045f4392013-01-17 00:00:49 +000012441expressions that can be fused if the code generator determines that (a) the
12442target instruction set has support for a fused operation, and (b) that the
12443fused operation is more efficient than the equivalent, separate pair of mul
12444and add instructions.
Sean Silvab084af42012-12-07 10:36:55 +000012445
12446Arguments:
12447""""""""""
12448
12449The '``llvm.fmuladd.*``' intrinsics each take three arguments: two
12450multiplicands, a and b, and an addend c.
12451
12452Semantics:
12453""""""""""
12454
12455The expression:
12456
12457::
12458
12459 %0 = call float @llvm.fmuladd.f32(%a, %b, %c)
12460
12461is equivalent to the expression a \* b + c, except that rounding will
12462not be performed between the multiplication and addition steps if the
12463code generator fuses the operations. Fusion is not guaranteed, even if
12464the target platform supports it. If a fused multiply-add is required the
Matt Arsenaultee364ee2014-01-31 00:09:00 +000012465corresponding llvm.fma.\* intrinsic function should be used
12466instead. This never sets errno, just as '``llvm.fma.*``'.
Sean Silvab084af42012-12-07 10:36:55 +000012467
12468Examples:
12469"""""""""
12470
12471.. code-block:: llvm
12472
Tim Northover675a0962014-06-13 14:24:23 +000012473 %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 +000012474
Amara Emersoncf9daa32017-05-09 10:43:25 +000012475
12476Experimental Vector Reduction Intrinsics
12477----------------------------------------
12478
12479Horizontal reductions of vectors can be expressed using the following
12480intrinsics. Each one takes a vector operand as an input and applies its
12481respective operation across all elements of the vector, returning a single
12482scalar result of the same element type.
12483
12484
12485'``llvm.experimental.vector.reduce.add.*``' Intrinsic
12486^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12487
12488Syntax:
12489"""""""
12490
12491::
12492
12493 declare i32 @llvm.experimental.vector.reduce.add.i32.v4i32(<4 x i32> %a)
12494 declare i64 @llvm.experimental.vector.reduce.add.i64.v2i64(<2 x i64> %a)
12495
12496Overview:
12497"""""""""
12498
12499The '``llvm.experimental.vector.reduce.add.*``' intrinsics do an integer ``ADD``
12500reduction of a vector, returning the result as a scalar. The return type matches
12501the element-type of the vector input.
12502
12503Arguments:
12504""""""""""
12505The argument to this intrinsic must be a vector of integer values.
12506
12507'``llvm.experimental.vector.reduce.fadd.*``' Intrinsic
12508^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12509
12510Syntax:
12511"""""""
12512
12513::
12514
12515 declare float @llvm.experimental.vector.reduce.fadd.f32.v4f32(float %acc, <4 x float> %a)
12516 declare double @llvm.experimental.vector.reduce.fadd.f64.v2f64(double %acc, <2 x double> %a)
12517
12518Overview:
12519"""""""""
12520
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000012521The '``llvm.experimental.vector.reduce.fadd.*``' intrinsics do a floating-point
Amara Emersoncf9daa32017-05-09 10:43:25 +000012522``ADD`` reduction of a vector, returning the result as a scalar. The return type
12523matches the element-type of the vector input.
12524
12525If the intrinsic call has fast-math flags, then the reduction will not preserve
12526the associativity of an equivalent scalarized counterpart. If it does not have
12527fast-math flags, then the reduction will be *ordered*, implying that the
12528operation respects the associativity of a scalarized reduction.
12529
12530
12531Arguments:
12532""""""""""
12533The first argument to this intrinsic is a scalar accumulator value, which is
12534only used when there are no fast-math flags attached. This argument may be undef
12535when fast-math flags are used.
12536
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000012537The second argument must be a vector of floating-point values.
Amara Emersoncf9daa32017-05-09 10:43:25 +000012538
12539Examples:
12540"""""""""
12541
12542.. code-block:: llvm
12543
12544 %fast = call fast float @llvm.experimental.vector.reduce.fadd.f32.v4f32(float undef, <4 x float> %input) ; fast reduction
12545 %ord = call float @llvm.experimental.vector.reduce.fadd.f32.v4f32(float %acc, <4 x float> %input) ; ordered reduction
12546
12547
12548'``llvm.experimental.vector.reduce.mul.*``' Intrinsic
12549^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12550
12551Syntax:
12552"""""""
12553
12554::
12555
12556 declare i32 @llvm.experimental.vector.reduce.mul.i32.v4i32(<4 x i32> %a)
12557 declare i64 @llvm.experimental.vector.reduce.mul.i64.v2i64(<2 x i64> %a)
12558
12559Overview:
12560"""""""""
12561
12562The '``llvm.experimental.vector.reduce.mul.*``' intrinsics do an integer ``MUL``
12563reduction of a vector, returning the result as a scalar. The return type matches
12564the element-type of the vector input.
12565
12566Arguments:
12567""""""""""
12568The argument to this intrinsic must be a vector of integer values.
12569
12570'``llvm.experimental.vector.reduce.fmul.*``' Intrinsic
12571^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12572
12573Syntax:
12574"""""""
12575
12576::
12577
12578 declare float @llvm.experimental.vector.reduce.fmul.f32.v4f32(float %acc, <4 x float> %a)
12579 declare double @llvm.experimental.vector.reduce.fmul.f64.v2f64(double %acc, <2 x double> %a)
12580
12581Overview:
12582"""""""""
12583
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000012584The '``llvm.experimental.vector.reduce.fmul.*``' intrinsics do a floating-point
Amara Emersoncf9daa32017-05-09 10:43:25 +000012585``MUL`` reduction of a vector, returning the result as a scalar. The return type
12586matches the element-type of the vector input.
12587
12588If the intrinsic call has fast-math flags, then the reduction will not preserve
12589the associativity of an equivalent scalarized counterpart. If it does not have
12590fast-math flags, then the reduction will be *ordered*, implying that the
12591operation respects the associativity of a scalarized reduction.
12592
12593
12594Arguments:
12595""""""""""
12596The first argument to this intrinsic is a scalar accumulator value, which is
12597only used when there are no fast-math flags attached. This argument may be undef
12598when fast-math flags are used.
12599
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000012600The second argument must be a vector of floating-point values.
Amara Emersoncf9daa32017-05-09 10:43:25 +000012601
12602Examples:
12603"""""""""
12604
12605.. code-block:: llvm
12606
12607 %fast = call fast float @llvm.experimental.vector.reduce.fmul.f32.v4f32(float undef, <4 x float> %input) ; fast reduction
12608 %ord = call float @llvm.experimental.vector.reduce.fmul.f32.v4f32(float %acc, <4 x float> %input) ; ordered reduction
12609
12610'``llvm.experimental.vector.reduce.and.*``' Intrinsic
12611^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12612
12613Syntax:
12614"""""""
12615
12616::
12617
12618 declare i32 @llvm.experimental.vector.reduce.and.i32.v4i32(<4 x i32> %a)
12619
12620Overview:
12621"""""""""
12622
12623The '``llvm.experimental.vector.reduce.and.*``' intrinsics do a bitwise ``AND``
12624reduction of a vector, returning the result as a scalar. The return type matches
12625the element-type of the vector input.
12626
12627Arguments:
12628""""""""""
12629The argument to this intrinsic must be a vector of integer values.
12630
12631'``llvm.experimental.vector.reduce.or.*``' Intrinsic
12632^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12633
12634Syntax:
12635"""""""
12636
12637::
12638
12639 declare i32 @llvm.experimental.vector.reduce.or.i32.v4i32(<4 x i32> %a)
12640
12641Overview:
12642"""""""""
12643
12644The '``llvm.experimental.vector.reduce.or.*``' intrinsics do a bitwise ``OR`` reduction
12645of a vector, returning the result as a scalar. The return type matches the
12646element-type of the vector input.
12647
12648Arguments:
12649""""""""""
12650The argument to this intrinsic must be a vector of integer values.
12651
12652'``llvm.experimental.vector.reduce.xor.*``' Intrinsic
12653^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12654
12655Syntax:
12656"""""""
12657
12658::
12659
12660 declare i32 @llvm.experimental.vector.reduce.xor.i32.v4i32(<4 x i32> %a)
12661
12662Overview:
12663"""""""""
12664
12665The '``llvm.experimental.vector.reduce.xor.*``' intrinsics do a bitwise ``XOR``
12666reduction of a vector, returning the result as a scalar. The return type matches
12667the element-type of the vector input.
12668
12669Arguments:
12670""""""""""
12671The argument to this intrinsic must be a vector of integer values.
12672
12673'``llvm.experimental.vector.reduce.smax.*``' Intrinsic
12674^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12675
12676Syntax:
12677"""""""
12678
12679::
12680
12681 declare i32 @llvm.experimental.vector.reduce.smax.i32.v4i32(<4 x i32> %a)
12682
12683Overview:
12684"""""""""
12685
12686The '``llvm.experimental.vector.reduce.smax.*``' intrinsics do a signed integer
12687``MAX`` reduction of a vector, returning the result as a scalar. The return type
12688matches the element-type of the vector input.
12689
12690Arguments:
12691""""""""""
12692The argument to this intrinsic must be a vector of integer values.
12693
12694'``llvm.experimental.vector.reduce.smin.*``' Intrinsic
12695^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12696
12697Syntax:
12698"""""""
12699
12700::
12701
12702 declare i32 @llvm.experimental.vector.reduce.smin.i32.v4i32(<4 x i32> %a)
12703
12704Overview:
12705"""""""""
12706
12707The '``llvm.experimental.vector.reduce.smin.*``' intrinsics do a signed integer
12708``MIN`` reduction of a vector, returning the result as a scalar. The return type
12709matches the element-type of the vector input.
12710
12711Arguments:
12712""""""""""
12713The argument to this intrinsic must be a vector of integer values.
12714
12715'``llvm.experimental.vector.reduce.umax.*``' Intrinsic
12716^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12717
12718Syntax:
12719"""""""
12720
12721::
12722
12723 declare i32 @llvm.experimental.vector.reduce.umax.i32.v4i32(<4 x i32> %a)
12724
12725Overview:
12726"""""""""
12727
12728The '``llvm.experimental.vector.reduce.umax.*``' intrinsics do an unsigned
12729integer ``MAX`` reduction of a vector, returning the result as a scalar. The
12730return type matches the element-type of the vector input.
12731
12732Arguments:
12733""""""""""
12734The argument to this intrinsic must be a vector of integer values.
12735
12736'``llvm.experimental.vector.reduce.umin.*``' Intrinsic
12737^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12738
12739Syntax:
12740"""""""
12741
12742::
12743
12744 declare i32 @llvm.experimental.vector.reduce.umin.i32.v4i32(<4 x i32> %a)
12745
12746Overview:
12747"""""""""
12748
12749The '``llvm.experimental.vector.reduce.umin.*``' intrinsics do an unsigned
12750integer ``MIN`` reduction of a vector, returning the result as a scalar. The
12751return type matches the element-type of the vector input.
12752
12753Arguments:
12754""""""""""
12755The argument to this intrinsic must be a vector of integer values.
12756
12757'``llvm.experimental.vector.reduce.fmax.*``' Intrinsic
12758^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12759
12760Syntax:
12761"""""""
12762
12763::
12764
12765 declare float @llvm.experimental.vector.reduce.fmax.f32.v4f32(<4 x float> %a)
12766 declare double @llvm.experimental.vector.reduce.fmax.f64.v2f64(<2 x double> %a)
12767
12768Overview:
12769"""""""""
12770
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000012771The '``llvm.experimental.vector.reduce.fmax.*``' intrinsics do a floating-point
Amara Emersoncf9daa32017-05-09 10:43:25 +000012772``MAX`` reduction of a vector, returning the result as a scalar. The return type
12773matches the element-type of the vector input.
12774
12775If the intrinsic call has the ``nnan`` fast-math flag then the operation can
12776assume that NaNs are not present in the input vector.
12777
12778Arguments:
12779""""""""""
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000012780The argument to this intrinsic must be a vector of floating-point values.
Amara Emersoncf9daa32017-05-09 10:43:25 +000012781
12782'``llvm.experimental.vector.reduce.fmin.*``' Intrinsic
12783^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12784
12785Syntax:
12786"""""""
12787
12788::
12789
12790 declare float @llvm.experimental.vector.reduce.fmin.f32.v4f32(<4 x float> %a)
12791 declare double @llvm.experimental.vector.reduce.fmin.f64.v2f64(<2 x double> %a)
12792
12793Overview:
12794"""""""""
12795
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000012796The '``llvm.experimental.vector.reduce.fmin.*``' intrinsics do a floating-point
Amara Emersoncf9daa32017-05-09 10:43:25 +000012797``MIN`` reduction of a vector, returning the result as a scalar. The return type
12798matches the element-type of the vector input.
12799
12800If the intrinsic call has the ``nnan`` fast-math flag then the operation can
12801assume that NaNs are not present in the input vector.
12802
12803Arguments:
12804""""""""""
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000012805The argument to this intrinsic must be a vector of floating-point values.
Amara Emersoncf9daa32017-05-09 10:43:25 +000012806
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000012807Half Precision Floating-Point Intrinsics
Sean Silvab084af42012-12-07 10:36:55 +000012808----------------------------------------
12809
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000012810For most target platforms, half precision floating-point is a
Sean Silvab084af42012-12-07 10:36:55 +000012811storage-only format. This means that it is a dense encoding (in memory)
12812but does not support computation in the format.
12813
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000012814This means that code must first load the half-precision floating-point
Sean Silvab084af42012-12-07 10:36:55 +000012815value as an i16, then convert it to float with
12816:ref:`llvm.convert.from.fp16 <int_convert_from_fp16>`. Computation can
12817then be performed on the float value (including extending to double
12818etc). To store the value back to memory, it is first converted to float
12819if needed, then converted to i16 with
12820:ref:`llvm.convert.to.fp16 <int_convert_to_fp16>`, then storing as an
12821i16 value.
12822
12823.. _int_convert_to_fp16:
12824
12825'``llvm.convert.to.fp16``' Intrinsic
12826^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12827
12828Syntax:
12829"""""""
12830
12831::
12832
Tim Northoverfd7e4242014-07-17 10:51:23 +000012833 declare i16 @llvm.convert.to.fp16.f32(float %a)
12834 declare i16 @llvm.convert.to.fp16.f64(double %a)
Sean Silvab084af42012-12-07 10:36:55 +000012835
12836Overview:
12837"""""""""
12838
Tim Northoverfd7e4242014-07-17 10:51:23 +000012839The '``llvm.convert.to.fp16``' intrinsic function performs a conversion from a
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000012840conventional floating-point type to half precision floating-point format.
Sean Silvab084af42012-12-07 10:36:55 +000012841
12842Arguments:
12843""""""""""
12844
12845The intrinsic function contains single argument - the value to be
12846converted.
12847
12848Semantics:
12849""""""""""
12850
Tim Northoverfd7e4242014-07-17 10:51:23 +000012851The '``llvm.convert.to.fp16``' intrinsic function performs a conversion from a
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000012852conventional floating-point format to half precision floating-point format. The
Tim Northoverfd7e4242014-07-17 10:51:23 +000012853return value is an ``i16`` which contains the converted number.
Sean Silvab084af42012-12-07 10:36:55 +000012854
12855Examples:
12856"""""""""
12857
12858.. code-block:: llvm
12859
Tim Northoverfd7e4242014-07-17 10:51:23 +000012860 %res = call i16 @llvm.convert.to.fp16.f32(float %a)
Sean Silvab084af42012-12-07 10:36:55 +000012861 store i16 %res, i16* @x, align 2
12862
12863.. _int_convert_from_fp16:
12864
12865'``llvm.convert.from.fp16``' Intrinsic
12866^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12867
12868Syntax:
12869"""""""
12870
12871::
12872
Tim Northoverfd7e4242014-07-17 10:51:23 +000012873 declare float @llvm.convert.from.fp16.f32(i16 %a)
12874 declare double @llvm.convert.from.fp16.f64(i16 %a)
Sean Silvab084af42012-12-07 10:36:55 +000012875
12876Overview:
12877"""""""""
12878
12879The '``llvm.convert.from.fp16``' intrinsic function performs a
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000012880conversion from half precision floating-point format to single precision
12881floating-point format.
Sean Silvab084af42012-12-07 10:36:55 +000012882
12883Arguments:
12884""""""""""
12885
12886The intrinsic function contains single argument - the value to be
12887converted.
12888
12889Semantics:
12890""""""""""
12891
12892The '``llvm.convert.from.fp16``' intrinsic function performs a
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000012893conversion from half single precision floating-point format to single
12894precision floating-point format. The input half-float value is
Sean Silvab084af42012-12-07 10:36:55 +000012895represented by an ``i16`` value.
12896
12897Examples:
12898"""""""""
12899
12900.. code-block:: llvm
12901
David Blaikiec7aabbb2015-03-04 22:06:14 +000012902 %a = load i16, i16* @x, align 2
Matt Arsenault3e3ddda2014-07-10 03:22:16 +000012903 %res = call float @llvm.convert.from.fp16(i16 %a)
Sean Silvab084af42012-12-07 10:36:55 +000012904
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +000012905.. _dbg_intrinsics:
12906
Sean Silvab084af42012-12-07 10:36:55 +000012907Debugger Intrinsics
12908-------------------
12909
12910The LLVM debugger intrinsics (which all start with ``llvm.dbg.``
12911prefix), are described in the `LLVM Source Level
Hans Wennborg65195622017-09-28 15:16:37 +000012912Debugging <SourceLevelDebugging.html#format-common-intrinsics>`_
Sean Silvab084af42012-12-07 10:36:55 +000012913document.
12914
12915Exception Handling Intrinsics
12916-----------------------------
12917
12918The LLVM exception handling intrinsics (which all start with
12919``llvm.eh.`` prefix), are described in the `LLVM Exception
Hans Wennborg65195622017-09-28 15:16:37 +000012920Handling <ExceptionHandling.html#format-common-intrinsics>`_ document.
Sean Silvab084af42012-12-07 10:36:55 +000012921
12922.. _int_trampoline:
12923
12924Trampoline Intrinsics
12925---------------------
12926
12927These intrinsics make it possible to excise one parameter, marked with
12928the :ref:`nest <nest>` attribute, from a function. The result is a
12929callable function pointer lacking the nest parameter - the caller does
12930not need to provide a value for it. Instead, the value to use is stored
12931in advance in a "trampoline", a block of memory usually allocated on the
12932stack, which also contains code to splice the nest value into the
12933argument list. This is used to implement the GCC nested function address
12934extension.
12935
12936For example, if the function is ``i32 f(i8* nest %c, i32 %x, i32 %y)``
12937then the resulting function pointer has signature ``i32 (i32, i32)*``.
12938It can be created as follows:
12939
12940.. code-block:: llvm
12941
12942 %tramp = alloca [10 x i8], align 4 ; size and alignment only correct for X86
David Blaikie16a97eb2015-03-04 22:02:58 +000012943 %tramp1 = getelementptr [10 x i8], [10 x i8]* %tramp, i32 0, i32 0
Sean Silvab084af42012-12-07 10:36:55 +000012944 call i8* @llvm.init.trampoline(i8* %tramp1, i8* bitcast (i32 (i8*, i32, i32)* @f to i8*), i8* %nval)
12945 %p = call i8* @llvm.adjust.trampoline(i8* %tramp1)
12946 %fp = bitcast i8* %p to i32 (i32, i32)*
12947
12948The call ``%val = call i32 %fp(i32 %x, i32 %y)`` is then equivalent to
12949``%val = call i32 %f(i8* %nval, i32 %x, i32 %y)``.
12950
12951.. _int_it:
12952
12953'``llvm.init.trampoline``' Intrinsic
12954^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12955
12956Syntax:
12957"""""""
12958
12959::
12960
12961 declare void @llvm.init.trampoline(i8* <tramp>, i8* <func>, i8* <nval>)
12962
12963Overview:
12964"""""""""
12965
12966This fills the memory pointed to by ``tramp`` with executable code,
12967turning it into a trampoline.
12968
12969Arguments:
12970""""""""""
12971
12972The ``llvm.init.trampoline`` intrinsic takes three arguments, all
12973pointers. The ``tramp`` argument must point to a sufficiently large and
12974sufficiently aligned block of memory; this memory is written to by the
12975intrinsic. Note that the size and the alignment are target-specific -
12976LLVM currently provides no portable way of determining them, so a
12977front-end that generates this intrinsic needs to have some
12978target-specific knowledge. The ``func`` argument must hold a function
12979bitcast to an ``i8*``.
12980
12981Semantics:
12982""""""""""
12983
12984The block of memory pointed to by ``tramp`` is filled with target
12985dependent code, turning it into a function. Then ``tramp`` needs to be
12986passed to :ref:`llvm.adjust.trampoline <int_at>` to get a pointer which can
12987be :ref:`bitcast (to a new function) and called <int_trampoline>`. The new
12988function's signature is the same as that of ``func`` with any arguments
12989marked with the ``nest`` attribute removed. At most one such ``nest``
12990argument is allowed, and it must be of pointer type. Calling the new
12991function is equivalent to calling ``func`` with the same argument list,
12992but with ``nval`` used for the missing ``nest`` argument. If, after
12993calling ``llvm.init.trampoline``, the memory pointed to by ``tramp`` is
12994modified, then the effect of any later call to the returned function
12995pointer is undefined.
12996
12997.. _int_at:
12998
12999'``llvm.adjust.trampoline``' Intrinsic
13000^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13001
13002Syntax:
13003"""""""
13004
13005::
13006
13007 declare i8* @llvm.adjust.trampoline(i8* <tramp>)
13008
13009Overview:
13010"""""""""
13011
13012This performs any required machine-specific adjustment to the address of
13013a trampoline (passed as ``tramp``).
13014
13015Arguments:
13016""""""""""
13017
13018``tramp`` must point to a block of memory which already has trampoline
13019code filled in by a previous call to
13020:ref:`llvm.init.trampoline <int_it>`.
13021
13022Semantics:
13023""""""""""
13024
13025On some architectures the address of the code to be executed needs to be
Sanjay Patel69bf48e2014-07-04 19:40:43 +000013026different than the address where the trampoline is actually stored. This
Sean Silvab084af42012-12-07 10:36:55 +000013027intrinsic returns the executable address corresponding to ``tramp``
13028after performing the required machine specific adjustments. The pointer
13029returned can then be :ref:`bitcast and executed <int_trampoline>`.
13030
Elena Demikhovsky82cdd652015-05-07 12:25:11 +000013031.. _int_mload_mstore:
13032
Elena Demikhovsky3d13f1c2014-12-25 09:29:13 +000013033Masked Vector Load and Store Intrinsics
13034---------------------------------------
13035
13036LLVM 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.
13037
13038.. _int_mload:
13039
13040'``llvm.masked.load.*``' Intrinsics
13041^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13042
13043Syntax:
13044"""""""
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000013045This 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 +000013046
13047::
13048
Artur Pilipenko7ad95ec2016-06-28 18:27:25 +000013049 declare <16 x float> @llvm.masked.load.v16f32.p0v16f32 (<16 x float>* <ptr>, i32 <alignment>, <16 x i1> <mask>, <16 x float> <passthru>)
13050 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 +000013051 ;; The data is a vector of pointers to double
Artur Pilipenko7ad95ec2016-06-28 18:27:25 +000013052 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 +000013053 ;; The data is a vector of function pointers
Artur Pilipenko7ad95ec2016-06-28 18:27:25 +000013054 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 +000013055
13056Overview:
13057"""""""""
13058
Elena Demikhovsky82cdd652015-05-07 12:25:11 +000013059Reads 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 +000013060
13061
13062Arguments:
13063""""""""""
13064
Elena Demikhovsky82cdd652015-05-07 12:25:11 +000013065The 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 +000013066
13067
13068Semantics:
13069""""""""""
13070
13071The '``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.
13072The 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.
13073
13074
13075::
13076
Artur Pilipenko7ad95ec2016-06-28 18:27:25 +000013077 %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 +000013078
Elena Demikhovsky3d13f1c2014-12-25 09:29:13 +000013079 ;; The result of the two following instructions is identical aside from potential memory access exception
David Blaikiec7aabbb2015-03-04 22:06:14 +000013080 %loadlal = load <16 x float>, <16 x float>* %ptr, align 4
Elena Demikhovskye86c8c82014-12-29 09:47:51 +000013081 %res = select <16 x i1> %mask, <16 x float> %loadlal, <16 x float> %passthru
Elena Demikhovsky3d13f1c2014-12-25 09:29:13 +000013082
13083.. _int_mstore:
13084
13085'``llvm.masked.store.*``' Intrinsics
13086^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13087
13088Syntax:
13089"""""""
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000013090This 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 +000013091
13092::
13093
Artur Pilipenko7ad95ec2016-06-28 18:27:25 +000013094 declare void @llvm.masked.store.v8i32.p0v8i32 (<8 x i32> <value>, <8 x i32>* <ptr>, i32 <alignment>, <8 x i1> <mask>)
13095 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 +000013096 ;; The data is a vector of pointers to double
Artur Pilipenko7ad95ec2016-06-28 18:27:25 +000013097 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 +000013098 ;; The data is a vector of function pointers
Artur Pilipenko7ad95ec2016-06-28 18:27:25 +000013099 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 +000013100
13101Overview:
13102"""""""""
13103
13104Writes 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.
13105
13106Arguments:
13107""""""""""
13108
13109The 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.
13110
13111
13112Semantics:
13113""""""""""
13114
13115The '``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.
13116The 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.
13117
13118::
13119
Artur Pilipenko7ad95ec2016-06-28 18:27:25 +000013120 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 +000013121
Elena Demikhovskye86c8c82014-12-29 09:47:51 +000013122 ;; The result of the following instructions is identical aside from potential data races and memory access exceptions
David Blaikiec7aabbb2015-03-04 22:06:14 +000013123 %oldval = load <16 x float>, <16 x float>* %ptr, align 4
Elena Demikhovsky3d13f1c2014-12-25 09:29:13 +000013124 %res = select <16 x i1> %mask, <16 x float> %value, <16 x float> %oldval
13125 store <16 x float> %res, <16 x float>* %ptr, align 4
13126
13127
Elena Demikhovsky82cdd652015-05-07 12:25:11 +000013128Masked Vector Gather and Scatter Intrinsics
13129-------------------------------------------
13130
13131LLVM 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.
13132
13133.. _int_mgather:
13134
13135'``llvm.masked.gather.*``' Intrinsics
13136^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13137
13138Syntax:
13139"""""""
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000013140This 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 +000013141
13142::
13143
Elad Cohenef5798a2017-05-03 12:28:54 +000013144 declare <16 x float> @llvm.masked.gather.v16f32.v16p0f32 (<16 x float*> <ptrs>, i32 <alignment>, <16 x i1> <mask>, <16 x float> <passthru>)
13145 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>)
13146 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 +000013147
13148Overview:
13149"""""""""
13150
13151Reads 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.
13152
13153
13154Arguments:
13155""""""""""
13156
13157The 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.
13158
13159
13160Semantics:
13161""""""""""
13162
13163The '``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.
13164The 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.
13165
13166
13167::
13168
Elad Cohenef5798a2017-05-03 12:28:54 +000013169 %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 +000013170
13171 ;; The gather with all-true mask is equivalent to the following instruction sequence
13172 %ptr0 = extractelement <4 x double*> %ptrs, i32 0
13173 %ptr1 = extractelement <4 x double*> %ptrs, i32 1
13174 %ptr2 = extractelement <4 x double*> %ptrs, i32 2
13175 %ptr3 = extractelement <4 x double*> %ptrs, i32 3
13176
13177 %val0 = load double, double* %ptr0, align 8
13178 %val1 = load double, double* %ptr1, align 8
13179 %val2 = load double, double* %ptr2, align 8
13180 %val3 = load double, double* %ptr3, align 8
13181
13182 %vec0 = insertelement <4 x double>undef, %val0, 0
13183 %vec01 = insertelement <4 x double>%vec0, %val1, 1
13184 %vec012 = insertelement <4 x double>%vec01, %val2, 2
13185 %vec0123 = insertelement <4 x double>%vec012, %val3, 3
13186
13187.. _int_mscatter:
13188
13189'``llvm.masked.scatter.*``' Intrinsics
13190^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13191
13192Syntax:
13193"""""""
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000013194This 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 +000013195
13196::
13197
Elad Cohenef5798a2017-05-03 12:28:54 +000013198 declare void @llvm.masked.scatter.v8i32.v8p0i32 (<8 x i32> <value>, <8 x i32*> <ptrs>, i32 <alignment>, <8 x i1> <mask>)
13199 declare void @llvm.masked.scatter.v16f32.v16p1f32 (<16 x float> <value>, <16 x float addrspace(1)*> <ptrs>, i32 <alignment>, <16 x i1> <mask>)
13200 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 +000013201
13202Overview:
13203"""""""""
13204
13205Writes 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.
13206
13207Arguments:
13208""""""""""
13209
13210The 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.
13211
13212
13213Semantics:
13214""""""""""
13215
Bruce Mitchenere9ffb452015-09-12 01:17:08 +000013216The '``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 +000013217
13218::
13219
Sylvestre Ledru84666a12016-02-14 20:16:22 +000013220 ;; This instruction unconditionally stores data vector in multiple addresses
Elad Cohenef5798a2017-05-03 12:28:54 +000013221 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 +000013222
13223 ;; It is equivalent to a list of scalar stores
13224 %val0 = extractelement <8 x i32> %value, i32 0
13225 %val1 = extractelement <8 x i32> %value, i32 1
13226 ..
13227 %val7 = extractelement <8 x i32> %value, i32 7
13228 %ptr0 = extractelement <8 x i32*> %ptrs, i32 0
13229 %ptr1 = extractelement <8 x i32*> %ptrs, i32 1
13230 ..
13231 %ptr7 = extractelement <8 x i32*> %ptrs, i32 7
13232 ;; Note: the order of the following stores is important when they overlap:
13233 store i32 %val0, i32* %ptr0, align 4
13234 store i32 %val1, i32* %ptr1, align 4
13235 ..
13236 store i32 %val7, i32* %ptr7, align 4
13237
13238
Elena Demikhovsky0ef2ce32018-06-06 09:11:46 +000013239Masked Vector Expanding Load and Compressing Store Intrinsics
13240-------------------------------------------------------------
13241
13242LLVM provides intrinsics for expanding load and compressing store operations. Data selected from a vector according to a mask is stored in consecutive memory addresses (compressed store), and vice-versa (expanding load). These operations effective map to "if (cond.i) a[j++] = v.i" and "if (cond.i) v.i = a[j++]" patterns, respectively. Note that when the mask starts with '1' bits followed by '0' bits, these operations are identical to :ref:`llvm.masked.store <int_mstore>` and :ref:`llvm.masked.load <int_mload>`.
13243
13244.. _int_expandload:
13245
13246'``llvm.masked.expandload.*``' Intrinsics
13247^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13248
13249Syntax:
13250"""""""
13251This is an overloaded intrinsic. Several values of integer, floating point or pointer data type are loaded from consecutive memory addresses and stored into the elements of a vector according to the mask.
13252
13253::
13254
13255 declare <16 x float> @llvm.masked.expandload.v16f32 (float* <ptr>, <16 x i1> <mask>, <16 x float> <passthru>)
13256 declare <2 x i64> @llvm.masked.expandload.v2i64 (i64* <ptr>, <2 x i1> <mask>, <2 x i64> <passthru>)
13257
13258Overview:
13259"""""""""
13260
13261Reads a number of scalar values sequentially from memory location provided in '``ptr``' and spreads them in a vector. The '``mask``' holds a bit for each vector lane. The number of elements read from memory is equal to the number of '1' bits in the mask. The loaded elements are positioned in the destination vector according to the sequence of '1' and '0' bits in the mask. E.g., if the mask vector is '10010001', "explandload" reads 3 values from memory addresses ptr, ptr+1, ptr+2 and places them in lanes 0, 3 and 7 accordingly. The masked-off lanes are filled by elements from the corresponding lanes of the '``passthru``' operand.
13262
13263
13264Arguments:
13265""""""""""
13266
13267The first operand is the base pointer for the load. It has the same underlying type as the element of the returned vector. The second operand, mask, is a vector of boolean values with the same number of elements as the return type. The third is a pass-through value that is used to fill the masked-off lanes of the result. The return type and the type of the '``passthru``' operand have the same vector type.
13268
13269Semantics:
13270""""""""""
13271
13272The '``llvm.masked.expandload``' intrinsic is designed for reading multiple scalar values from adjacent memory addresses into possibly non-adjacent vector lanes. It is useful for targets that support vector expanding loads and allows vectorizing loop with cross-iteration dependency like in the following example:
13273
13274.. code-block:: c
13275
13276 // In this loop we load from B and spread the elements into array A.
13277 double *A, B; int *C;
13278 for (int i = 0; i < size; ++i) {
13279 if (C[i] != 0)
13280 A[i] = B[j++];
13281 }
13282
13283
13284.. code-block:: llvm
13285
13286 ; Load several elements from array B and expand them in a vector.
13287 ; The number of loaded elements is equal to the number of '1' elements in the Mask.
13288 %Tmp = call <8 x double> @llvm.masked.expandload.v8f64(double* %Bptr, <8 x i1> %Mask, <8 x double> undef)
13289 ; Store the result in A
13290 call void @llvm.masked.store.v8f64.p0v8f64(<8 x double> %Tmp, <8 x double>* %Aptr, i32 8, <8 x i1> %Mask)
13291
13292 ; %Bptr should be increased on each iteration according to the number of '1' elements in the Mask.
13293 %MaskI = bitcast <8 x i1> %Mask to i8
13294 %MaskIPopcnt = call i8 @llvm.ctpop.i8(i8 %MaskI)
13295 %MaskI64 = zext i8 %MaskIPopcnt to i64
13296 %BNextInd = add i64 %BInd, %MaskI64
13297
13298
13299Other targets may support this intrinsic differently, for example, by lowering it into a sequence of conditional scalar load operations and shuffles.
13300If all mask elements are '1', the intrinsic behavior is equivalent to the regular unmasked vector load.
13301
13302.. _int_compressstore:
13303
13304'``llvm.masked.compressstore.*``' Intrinsics
13305^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13306
13307Syntax:
13308"""""""
13309This is an overloaded intrinsic. A number of scalar values of integer, floating point or pointer data type are collected from an input vector and stored into adjacent memory addresses. A mask defines which elements to collect from the vector.
13310
13311::
13312
13313 declare void @llvm.masked.compressstore.v8i32 (<8 x i32> <value>, i32* <ptr>, <8 x i1> <mask>)
13314 declare void @llvm.masked.compressstore.v16f32 (<16 x float> <value>, float* <ptr>, <16 x i1> <mask>)
13315
13316Overview:
13317"""""""""
13318
13319Selects elements from input vector '``value``' according to the '``mask``'. All selected elements are written into adjacent memory addresses starting at address '`ptr`', from lower to higher. The mask holds a bit for each vector lane, and is used to select elements to be stored. The number of elements to be stored is equal to the number of active bits in the mask.
13320
13321Arguments:
13322""""""""""
13323
13324The first operand is the input vector, from which elements are collected and written to memory. The second operand is the base pointer for the store, it has the same underlying type as the element of the input vector operand. The third operand is the mask, a vector of boolean values. The mask and the input vector must have the same number of vector elements.
13325
13326
13327Semantics:
13328""""""""""
13329
13330The '``llvm.masked.compressstore``' intrinsic is designed for compressing data in memory. It allows to collect elements from possibly non-adjacent lanes of a vector and store them contiguously in memory in one IR operation. It is useful for targets that support compressing store operations and allows vectorizing loops with cross-iteration dependences like in the following example:
13331
13332.. code-block:: c
13333
13334 // In this loop we load elements from A and store them consecutively in B
13335 double *A, B; int *C;
13336 for (int i = 0; i < size; ++i) {
13337 if (C[i] != 0)
13338 B[j++] = A[i]
13339 }
13340
13341
13342.. code-block:: llvm
13343
13344 ; Load elements from A.
13345 %Tmp = call <8 x double> @llvm.masked.load.v8f64.p0v8f64(<8 x double>* %Aptr, i32 8, <8 x i1> %Mask, <8 x double> undef)
13346 ; Store all selected elements consecutively in array B
13347 call <void> @llvm.masked.compressstore.v8f64(<8 x double> %Tmp, double* %Bptr, <8 x i1> %Mask)
13348
13349 ; %Bptr should be increased on each iteration according to the number of '1' elements in the Mask.
13350 %MaskI = bitcast <8 x i1> %Mask to i8
13351 %MaskIPopcnt = call i8 @llvm.ctpop.i8(i8 %MaskI)
13352 %MaskI64 = zext i8 %MaskIPopcnt to i64
13353 %BNextInd = add i64 %BInd, %MaskI64
13354
13355
13356Other targets may support this intrinsic differently, for example, by lowering it into a sequence of branches that guard scalar store operations.
13357
13358
Sean Silvab084af42012-12-07 10:36:55 +000013359Memory Use Markers
13360------------------
13361
Sanjay Patel69bf48e2014-07-04 19:40:43 +000013362This class of intrinsics provides information about the lifetime of
Sean Silvab084af42012-12-07 10:36:55 +000013363memory objects and ranges where variables are immutable.
13364
Reid Klecknera534a382013-12-19 02:14:12 +000013365.. _int_lifestart:
13366
Sean Silvab084af42012-12-07 10:36:55 +000013367'``llvm.lifetime.start``' Intrinsic
13368^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13369
13370Syntax:
13371"""""""
13372
13373::
13374
13375 declare void @llvm.lifetime.start(i64 <size>, i8* nocapture <ptr>)
13376
13377Overview:
13378"""""""""
13379
13380The '``llvm.lifetime.start``' intrinsic specifies the start of a memory
13381object's lifetime.
13382
13383Arguments:
13384""""""""""
13385
13386The first argument is a constant integer representing the size of the
13387object, or -1 if it is variable sized. The second argument is a pointer
13388to the object.
13389
13390Semantics:
13391""""""""""
13392
13393This intrinsic indicates that before this point in the code, the value
13394of the memory pointed to by ``ptr`` is dead. This means that it is known
13395to never be used and has an undefined value. A load from the pointer
13396that precedes this intrinsic can be replaced with ``'undef'``.
13397
Reid Klecknera534a382013-12-19 02:14:12 +000013398.. _int_lifeend:
13399
Sean Silvab084af42012-12-07 10:36:55 +000013400'``llvm.lifetime.end``' Intrinsic
13401^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13402
13403Syntax:
13404"""""""
13405
13406::
13407
13408 declare void @llvm.lifetime.end(i64 <size>, i8* nocapture <ptr>)
13409
13410Overview:
13411"""""""""
13412
13413The '``llvm.lifetime.end``' intrinsic specifies the end of a memory
13414object's lifetime.
13415
13416Arguments:
13417""""""""""
13418
13419The first argument is a constant integer representing the size of the
13420object, or -1 if it is variable sized. The second argument is a pointer
13421to the object.
13422
13423Semantics:
13424""""""""""
13425
13426This intrinsic indicates that after this point in the code, the value of
13427the memory pointed to by ``ptr`` is dead. This means that it is known to
13428never be used and has an undefined value. Any stores into the memory
13429object following this intrinsic may be removed as dead.
13430
13431'``llvm.invariant.start``' Intrinsic
13432^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13433
13434Syntax:
13435"""""""
Mehdi Amini8c629ec2016-08-13 23:31:24 +000013436This is an overloaded intrinsic. The memory object can belong to any address space.
Sean Silvab084af42012-12-07 10:36:55 +000013437
13438::
13439
Mehdi Amini8c629ec2016-08-13 23:31:24 +000013440 declare {}* @llvm.invariant.start.p0i8(i64 <size>, i8* nocapture <ptr>)
Sean Silvab084af42012-12-07 10:36:55 +000013441
13442Overview:
13443"""""""""
13444
13445The '``llvm.invariant.start``' intrinsic specifies that the contents of
13446a memory object will not change.
13447
13448Arguments:
13449""""""""""
13450
13451The first argument is a constant integer representing the size of the
13452object, or -1 if it is variable sized. The second argument is a pointer
13453to the object.
13454
13455Semantics:
13456""""""""""
13457
13458This intrinsic indicates that until an ``llvm.invariant.end`` that uses
13459the return value, the referenced memory location is constant and
13460unchanging.
13461
13462'``llvm.invariant.end``' Intrinsic
13463^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13464
13465Syntax:
13466"""""""
Mehdi Amini8c629ec2016-08-13 23:31:24 +000013467This is an overloaded intrinsic. The memory object can belong to any address space.
Sean Silvab084af42012-12-07 10:36:55 +000013468
13469::
13470
Mehdi Amini8c629ec2016-08-13 23:31:24 +000013471 declare void @llvm.invariant.end.p0i8({}* <start>, i64 <size>, i8* nocapture <ptr>)
Sean Silvab084af42012-12-07 10:36:55 +000013472
13473Overview:
13474"""""""""
13475
13476The '``llvm.invariant.end``' intrinsic specifies that the contents of a
13477memory object are mutable.
13478
13479Arguments:
13480""""""""""
13481
13482The first argument is the matching ``llvm.invariant.start`` intrinsic.
13483The second argument is a constant integer representing the size of the
13484object, or -1 if it is variable sized and the third argument is a
13485pointer to the object.
13486
13487Semantics:
13488""""""""""
13489
13490This intrinsic indicates that the memory is mutable again.
13491
Piotr Padlewski5dde8092018-05-03 11:03:01 +000013492'``llvm.launder.invariant.group``' Intrinsic
Piotr Padlewski6c15ec42015-09-15 18:32:14 +000013493^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13494
13495Syntax:
13496"""""""
Yaxun Liu407ca362017-11-16 16:32:16 +000013497This is an overloaded intrinsic. The memory object can belong to any address
13498space. The returned pointer must belong to the same address space as the
13499argument.
Piotr Padlewski6c15ec42015-09-15 18:32:14 +000013500
13501::
13502
Piotr Padlewski5dde8092018-05-03 11:03:01 +000013503 declare i8* @llvm.launder.invariant.group.p0i8(i8* <ptr>)
Piotr Padlewski6c15ec42015-09-15 18:32:14 +000013504
13505Overview:
13506"""""""""
13507
Piotr Padlewski5dde8092018-05-03 11:03:01 +000013508The '``llvm.launder.invariant.group``' intrinsic can be used when an invariant
Piotr Padlewski5b3db452018-07-02 04:49:30 +000013509established by ``invariant.group`` metadata no longer holds, to obtain a new
13510pointer value that carries fresh invariant group information. It is an
13511experimental intrinsic, which means that its semantics might change in the
13512future.
Piotr Padlewski6c15ec42015-09-15 18:32:14 +000013513
13514
13515Arguments:
13516""""""""""
13517
Piotr Padlewski5b3db452018-07-02 04:49:30 +000013518The ``llvm.launder.invariant.group`` takes only one argument, which is a pointer
13519to the memory.
Piotr Padlewski6c15ec42015-09-15 18:32:14 +000013520
13521Semantics:
13522""""""""""
13523
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +000013524Returns another pointer that aliases its argument but which is considered different
Piotr Padlewski6c15ec42015-09-15 18:32:14 +000013525for the purposes of ``load``/``store`` ``invariant.group`` metadata.
Piotr Padlewski5dde8092018-05-03 11:03:01 +000013526It does not read any accessible memory and the execution can be speculated.
Piotr Padlewski6c15ec42015-09-15 18:32:14 +000013527
Piotr Padlewski5b3db452018-07-02 04:49:30 +000013528'``llvm.strip.invariant.group``' Intrinsic
13529^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13530
13531Syntax:
13532"""""""
13533This is an overloaded intrinsic. The memory object can belong to any address
13534space. The returned pointer must belong to the same address space as the
13535argument.
13536
13537::
13538
13539 declare i8* @llvm.strip.invariant.group.p0i8(i8* <ptr>)
13540
13541Overview:
13542"""""""""
13543
13544The '``llvm.strip.invariant.group``' intrinsic can be used when an invariant
13545established by ``invariant.group`` metadata no longer holds, to obtain a new pointer
13546value that does not carry the invariant information. It is an experimental
13547intrinsic, which means that its semantics might change in the future.
13548
13549
13550Arguments:
13551""""""""""
13552
13553The ``llvm.strip.invariant.group`` takes only one argument, which is a pointer
13554to the memory.
13555
13556Semantics:
13557""""""""""
13558
13559Returns another pointer that aliases its argument but which has no associated
13560``invariant.group`` metadata.
13561It does not read any memory and can be speculated.
13562
13563
13564
Sanjay Patel54b161e2018-03-20 16:38:22 +000013565.. _constrainedfp:
13566
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000013567Constrained Floating-Point Intrinsics
Andrew Kaylora0a11642017-01-26 23:27:59 +000013568-------------------------------------
13569
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000013570These intrinsics are used to provide special handling of floating-point
13571operations when specific rounding mode or floating-point exception behavior is
Andrew Kaylora0a11642017-01-26 23:27:59 +000013572required. By default, LLVM optimization passes assume that the rounding mode is
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000013573round-to-nearest and that floating-point exceptions will not be monitored.
Andrew Kaylora0a11642017-01-26 23:27:59 +000013574Constrained FP intrinsics are used to support non-default rounding modes and
13575accurately preserve exception behavior without compromising LLVM's ability to
13576optimize FP code when the default behavior is used.
13577
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000013578Each of these intrinsics corresponds to a normal floating-point operation. The
Andrew Kaylora0a11642017-01-26 23:27:59 +000013579first two arguments and the return value are the same as the corresponding FP
13580operation.
13581
13582The third argument is a metadata argument specifying the rounding mode to be
13583assumed. This argument must be one of the following strings:
13584
13585::
Andrew Kaylor73b4a9a2017-04-20 18:18:36 +000013586
Andrew Kaylora0a11642017-01-26 23:27:59 +000013587 "round.dynamic"
13588 "round.tonearest"
13589 "round.downward"
13590 "round.upward"
13591 "round.towardzero"
13592
13593If this argument is "round.dynamic" optimization passes must assume that the
13594rounding mode is unknown and may change at runtime. No transformations that
13595depend on rounding mode may be performed in this case.
13596
13597The other possible values for the rounding mode argument correspond to the
13598similarly named IEEE rounding modes. If the argument is any of these values
13599optimization passes may perform transformations as long as they are consistent
13600with the specified rounding mode.
13601
13602For example, 'x-0'->'x' is not a valid transformation if the rounding mode is
13603"round.downward" or "round.dynamic" because if the value of 'x' is +0 then
13604'x-0' should evaluate to '-0' when rounding downward. However, this
13605transformation is legal for all other rounding modes.
13606
13607For values other than "round.dynamic" optimization passes may assume that the
13608actual runtime rounding mode (as defined in a target-specific manner) matches
13609the specified rounding mode, but this is not guaranteed. Using a specific
13610non-dynamic rounding mode which does not match the actual rounding mode at
13611runtime results in undefined behavior.
13612
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000013613The fourth argument to the constrained floating-point intrinsics specifies the
Andrew Kaylora0a11642017-01-26 23:27:59 +000013614required exception behavior. This argument must be one of the following
13615strings:
13616
13617::
Andrew Kaylor73b4a9a2017-04-20 18:18:36 +000013618
Andrew Kaylora0a11642017-01-26 23:27:59 +000013619 "fpexcept.ignore"
13620 "fpexcept.maytrap"
13621 "fpexcept.strict"
13622
13623If this argument is "fpexcept.ignore" optimization passes may assume that the
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000013624exception status flags will not be read and that floating-point exceptions will
Andrew Kaylora0a11642017-01-26 23:27:59 +000013625be masked. This allows transformations to be performed that may change the
13626exception semantics of the original code. For example, FP operations may be
13627speculatively executed in this case whereas they must not be for either of the
13628other possible values of this argument.
13629
13630If the exception behavior argument is "fpexcept.maytrap" optimization passes
13631must avoid transformations that may raise exceptions that would not have been
13632raised by the original code (such as speculatively executing FP operations), but
13633passes are not required to preserve all exceptions that are implied by the
13634original code. For example, exceptions may be potentially hidden by constant
13635folding.
13636
13637If the exception behavior argument is "fpexcept.strict" all transformations must
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000013638strictly preserve the floating-point exception semantics of the original code.
Andrew Kaylora0a11642017-01-26 23:27:59 +000013639Any FP exception that would have been raised by the original code must be raised
13640by the transformed code, and the transformed code must not raise any FP
13641exceptions that would not have been raised by the original code. This is the
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +000013642exception behavior argument that will be used if the code being compiled reads
Andrew Kaylora0a11642017-01-26 23:27:59 +000013643the FP exception status flags, but this mode can also be used with code that
13644unmasks FP exceptions.
13645
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000013646The number and order of floating-point exceptions is NOT guaranteed. For
Andrew Kaylora0a11642017-01-26 23:27:59 +000013647example, a series of FP operations that each may raise exceptions may be
13648vectorized into a single instruction that raises each unique exception a single
13649time.
13650
13651
13652'``llvm.experimental.constrained.fadd``' Intrinsic
13653^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13654
13655Syntax:
13656"""""""
13657
13658::
13659
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +000013660 declare <type>
Andrew Kaylora0a11642017-01-26 23:27:59 +000013661 @llvm.experimental.constrained.fadd(<type> <op1>, <type> <op2>,
13662 metadata <rounding mode>,
Andrew Kaylorf4660012017-05-25 21:31:00 +000013663 metadata <exception behavior>)
Andrew Kaylora0a11642017-01-26 23:27:59 +000013664
13665Overview:
13666"""""""""
13667
13668The '``llvm.experimental.constrained.fadd``' intrinsic returns the sum of its
13669two operands.
13670
13671
13672Arguments:
13673""""""""""
13674
13675The first two arguments to the '``llvm.experimental.constrained.fadd``'
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000013676intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>`
13677of floating-point values. Both arguments must have identical types.
Andrew Kaylora0a11642017-01-26 23:27:59 +000013678
13679The third and fourth arguments specify the rounding mode and exception
13680behavior as described above.
13681
13682Semantics:
13683""""""""""
13684
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000013685The value produced is the floating-point sum of the two value operands and has
Andrew Kaylora0a11642017-01-26 23:27:59 +000013686the same type as the operands.
13687
13688
13689'``llvm.experimental.constrained.fsub``' Intrinsic
13690^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13691
13692Syntax:
13693"""""""
13694
13695::
13696
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +000013697 declare <type>
Andrew Kaylora0a11642017-01-26 23:27:59 +000013698 @llvm.experimental.constrained.fsub(<type> <op1>, <type> <op2>,
13699 metadata <rounding mode>,
Andrew Kaylorf4660012017-05-25 21:31:00 +000013700 metadata <exception behavior>)
Andrew Kaylora0a11642017-01-26 23:27:59 +000013701
13702Overview:
13703"""""""""
13704
13705The '``llvm.experimental.constrained.fsub``' intrinsic returns the difference
13706of its two operands.
13707
13708
13709Arguments:
13710""""""""""
13711
13712The first two arguments to the '``llvm.experimental.constrained.fsub``'
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000013713intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>`
13714of floating-point values. Both arguments must have identical types.
Andrew Kaylora0a11642017-01-26 23:27:59 +000013715
13716The third and fourth arguments specify the rounding mode and exception
13717behavior as described above.
13718
13719Semantics:
13720""""""""""
13721
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000013722The value produced is the floating-point difference of the two value operands
Andrew Kaylora0a11642017-01-26 23:27:59 +000013723and has the same type as the operands.
13724
13725
13726'``llvm.experimental.constrained.fmul``' Intrinsic
13727^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13728
13729Syntax:
13730"""""""
13731
13732::
13733
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +000013734 declare <type>
Andrew Kaylora0a11642017-01-26 23:27:59 +000013735 @llvm.experimental.constrained.fmul(<type> <op1>, <type> <op2>,
13736 metadata <rounding mode>,
Andrew Kaylorf4660012017-05-25 21:31:00 +000013737 metadata <exception behavior>)
Andrew Kaylora0a11642017-01-26 23:27:59 +000013738
13739Overview:
13740"""""""""
13741
13742The '``llvm.experimental.constrained.fmul``' intrinsic returns the product of
13743its two operands.
13744
13745
13746Arguments:
13747""""""""""
13748
13749The first two arguments to the '``llvm.experimental.constrained.fmul``'
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000013750intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>`
13751of floating-point values. Both arguments must have identical types.
Andrew Kaylora0a11642017-01-26 23:27:59 +000013752
13753The third and fourth arguments specify the rounding mode and exception
13754behavior as described above.
13755
13756Semantics:
13757""""""""""
13758
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000013759The value produced is the floating-point product of the two value operands and
Andrew Kaylora0a11642017-01-26 23:27:59 +000013760has the same type as the operands.
13761
13762
13763'``llvm.experimental.constrained.fdiv``' Intrinsic
13764^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13765
13766Syntax:
13767"""""""
13768
13769::
13770
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +000013771 declare <type>
Andrew Kaylora0a11642017-01-26 23:27:59 +000013772 @llvm.experimental.constrained.fdiv(<type> <op1>, <type> <op2>,
13773 metadata <rounding mode>,
Andrew Kaylorf4660012017-05-25 21:31:00 +000013774 metadata <exception behavior>)
Andrew Kaylora0a11642017-01-26 23:27:59 +000013775
13776Overview:
13777"""""""""
13778
13779The '``llvm.experimental.constrained.fdiv``' intrinsic returns the quotient of
13780its two operands.
13781
13782
13783Arguments:
13784""""""""""
13785
13786The first two arguments to the '``llvm.experimental.constrained.fdiv``'
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000013787intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>`
13788of floating-point values. Both arguments must have identical types.
Andrew Kaylora0a11642017-01-26 23:27:59 +000013789
13790The third and fourth arguments specify the rounding mode and exception
13791behavior as described above.
13792
13793Semantics:
13794""""""""""
13795
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000013796The value produced is the floating-point quotient of the two value operands and
Andrew Kaylora0a11642017-01-26 23:27:59 +000013797has the same type as the operands.
13798
13799
13800'``llvm.experimental.constrained.frem``' Intrinsic
13801^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13802
13803Syntax:
13804"""""""
13805
13806::
13807
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +000013808 declare <type>
Andrew Kaylora0a11642017-01-26 23:27:59 +000013809 @llvm.experimental.constrained.frem(<type> <op1>, <type> <op2>,
13810 metadata <rounding mode>,
Andrew Kaylorf4660012017-05-25 21:31:00 +000013811 metadata <exception behavior>)
Andrew Kaylora0a11642017-01-26 23:27:59 +000013812
13813Overview:
13814"""""""""
13815
13816The '``llvm.experimental.constrained.frem``' intrinsic returns the remainder
13817from the division of its two operands.
13818
13819
13820Arguments:
13821""""""""""
13822
13823The first two arguments to the '``llvm.experimental.constrained.frem``'
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000013824intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>`
13825of floating-point values. Both arguments must have identical types.
Andrew Kaylora0a11642017-01-26 23:27:59 +000013826
13827The third and fourth arguments specify the rounding mode and exception
13828behavior as described above. The rounding mode argument has no effect, since
13829the result of frem is never rounded, but the argument is included for
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000013830consistency with the other constrained floating-point intrinsics.
Andrew Kaylora0a11642017-01-26 23:27:59 +000013831
13832Semantics:
13833""""""""""
13834
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000013835The value produced is the floating-point remainder from the division of the two
Andrew Kaylora0a11642017-01-26 23:27:59 +000013836value operands and has the same type as the operands. The remainder has the
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +000013837same sign as the dividend.
Andrew Kaylora0a11642017-01-26 23:27:59 +000013838
Wei Dinga131d3f2017-08-24 04:18:24 +000013839'``llvm.experimental.constrained.fma``' Intrinsic
13840^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13841
13842Syntax:
13843"""""""
13844
13845::
13846
13847 declare <type>
13848 @llvm.experimental.constrained.fma(<type> <op1>, <type> <op2>, <type> <op3>,
13849 metadata <rounding mode>,
13850 metadata <exception behavior>)
13851
13852Overview:
13853"""""""""
13854
13855The '``llvm.experimental.constrained.fma``' intrinsic returns the result of a
13856fused-multiply-add operation on its operands.
13857
13858Arguments:
13859""""""""""
13860
13861The first three arguments to the '``llvm.experimental.constrained.fma``'
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000013862intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector
13863<t_vector>` of floating-point values. All arguments must have identical types.
Wei Dinga131d3f2017-08-24 04:18:24 +000013864
13865The fourth and fifth arguments specify the rounding mode and exception behavior
13866as described above.
13867
13868Semantics:
13869""""""""""
13870
13871The result produced is the product of the first two operands added to the third
13872operand computed with infinite precision, and then rounded to the target
13873precision.
Andrew Kaylora0a11642017-01-26 23:27:59 +000013874
Andrew Kaylorf4660012017-05-25 21:31:00 +000013875Constrained libm-equivalent Intrinsics
13876--------------------------------------
13877
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000013878In addition to the basic floating-point operations for which constrained
Andrew Kaylorf4660012017-05-25 21:31:00 +000013879intrinsics are described above, there are constrained versions of various
13880operations which provide equivalent behavior to a corresponding libm function.
13881These intrinsics allow the precise behavior of these operations with respect to
13882rounding mode and exception behavior to be controlled.
13883
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000013884As with the basic constrained floating-point intrinsics, the rounding mode
Andrew Kaylorf4660012017-05-25 21:31:00 +000013885and exception behavior arguments only control the behavior of the optimizer.
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000013886They do not change the runtime floating-point environment.
Andrew Kaylorf4660012017-05-25 21:31:00 +000013887
13888
13889'``llvm.experimental.constrained.sqrt``' Intrinsic
13890^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13891
13892Syntax:
13893"""""""
13894
13895::
13896
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +000013897 declare <type>
Andrew Kaylorf4660012017-05-25 21:31:00 +000013898 @llvm.experimental.constrained.sqrt(<type> <op1>,
13899 metadata <rounding mode>,
13900 metadata <exception behavior>)
13901
13902Overview:
13903"""""""""
13904
13905The '``llvm.experimental.constrained.sqrt``' intrinsic returns the square root
13906of the specified value, returning the same value as the libm '``sqrt``'
13907functions would, but without setting ``errno``.
13908
13909Arguments:
13910""""""""""
13911
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000013912The first argument and the return type are floating-point numbers of the same
Andrew Kaylorf4660012017-05-25 21:31:00 +000013913type.
13914
13915The second and third arguments specify the rounding mode and exception
13916behavior as described above.
13917
13918Semantics:
13919""""""""""
13920
13921This function returns the nonnegative square root of the specified value.
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000013922If the value is less than negative zero, a floating-point exception occurs
Hiroshi Inoue760c0c92018-01-16 13:19:48 +000013923and the return value is architecture specific.
Andrew Kaylorf4660012017-05-25 21:31:00 +000013924
13925
13926'``llvm.experimental.constrained.pow``' Intrinsic
13927^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13928
13929Syntax:
13930"""""""
13931
13932::
13933
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +000013934 declare <type>
Andrew Kaylorf4660012017-05-25 21:31:00 +000013935 @llvm.experimental.constrained.pow(<type> <op1>, <type> <op2>,
13936 metadata <rounding mode>,
13937 metadata <exception behavior>)
13938
13939Overview:
13940"""""""""
13941
13942The '``llvm.experimental.constrained.pow``' intrinsic returns the first operand
13943raised to the (positive or negative) power specified by the second operand.
13944
13945Arguments:
13946""""""""""
13947
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000013948The first two arguments and the return value are floating-point numbers of the
Andrew Kaylorf4660012017-05-25 21:31:00 +000013949same type. The second argument specifies the power to which the first argument
13950should be raised.
13951
13952The third and fourth arguments specify the rounding mode and exception
13953behavior as described above.
13954
13955Semantics:
13956""""""""""
13957
13958This function returns the first value raised to the second power,
13959returning the same values as the libm ``pow`` functions would, and
13960handles error conditions in the same way.
13961
13962
13963'``llvm.experimental.constrained.powi``' Intrinsic
13964^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13965
13966Syntax:
13967"""""""
13968
13969::
13970
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +000013971 declare <type>
Andrew Kaylorf4660012017-05-25 21:31:00 +000013972 @llvm.experimental.constrained.powi(<type> <op1>, i32 <op2>,
13973 metadata <rounding mode>,
13974 metadata <exception behavior>)
13975
13976Overview:
13977"""""""""
13978
13979The '``llvm.experimental.constrained.powi``' intrinsic returns the first operand
13980raised to the (positive or negative) power specified by the second operand. The
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000013981order of evaluation of multiplications is not defined. When a vector of
13982floating-point type is used, the second argument remains a scalar integer value.
Andrew Kaylorf4660012017-05-25 21:31:00 +000013983
13984
13985Arguments:
13986""""""""""
13987
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000013988The first argument and the return value are floating-point numbers of the same
Andrew Kaylorf4660012017-05-25 21:31:00 +000013989type. The second argument is a 32-bit signed integer specifying the power to
13990which the first argument should be raised.
13991
13992The third and fourth arguments specify the rounding mode and exception
13993behavior as described above.
13994
13995Semantics:
13996""""""""""
13997
13998This function returns the first value raised to the second power with an
13999unspecified sequence of rounding operations.
14000
14001
14002'``llvm.experimental.constrained.sin``' Intrinsic
14003^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14004
14005Syntax:
14006"""""""
14007
14008::
14009
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +000014010 declare <type>
Andrew Kaylorf4660012017-05-25 21:31:00 +000014011 @llvm.experimental.constrained.sin(<type> <op1>,
14012 metadata <rounding mode>,
14013 metadata <exception behavior>)
14014
14015Overview:
14016"""""""""
14017
14018The '``llvm.experimental.constrained.sin``' intrinsic returns the sine of the
14019first operand.
14020
14021Arguments:
14022""""""""""
14023
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000014024The first argument and the return type are floating-point numbers of the same
Andrew Kaylorf4660012017-05-25 21:31:00 +000014025type.
14026
14027The second and third arguments specify the rounding mode and exception
14028behavior as described above.
14029
14030Semantics:
14031""""""""""
14032
14033This function returns the sine of the specified operand, returning the
14034same values as the libm ``sin`` functions would, and handles error
14035conditions in the same way.
14036
14037
14038'``llvm.experimental.constrained.cos``' Intrinsic
14039^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14040
14041Syntax:
14042"""""""
14043
14044::
14045
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +000014046 declare <type>
Andrew Kaylorf4660012017-05-25 21:31:00 +000014047 @llvm.experimental.constrained.cos(<type> <op1>,
14048 metadata <rounding mode>,
14049 metadata <exception behavior>)
14050
14051Overview:
14052"""""""""
14053
14054The '``llvm.experimental.constrained.cos``' intrinsic returns the cosine of the
14055first operand.
14056
14057Arguments:
14058""""""""""
14059
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000014060The first argument and the return type are floating-point numbers of the same
Andrew Kaylorf4660012017-05-25 21:31:00 +000014061type.
14062
14063The second and third arguments specify the rounding mode and exception
14064behavior as described above.
14065
14066Semantics:
14067""""""""""
14068
14069This function returns the cosine of the specified operand, returning the
14070same values as the libm ``cos`` functions would, and handles error
14071conditions in the same way.
14072
14073
14074'``llvm.experimental.constrained.exp``' Intrinsic
14075^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14076
14077Syntax:
14078"""""""
14079
14080::
14081
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +000014082 declare <type>
Andrew Kaylorf4660012017-05-25 21:31:00 +000014083 @llvm.experimental.constrained.exp(<type> <op1>,
14084 metadata <rounding mode>,
14085 metadata <exception behavior>)
14086
14087Overview:
14088"""""""""
14089
14090The '``llvm.experimental.constrained.exp``' intrinsic computes the base-e
14091exponential of the specified value.
14092
14093Arguments:
14094""""""""""
14095
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000014096The first argument and the return value are floating-point numbers of the same
Andrew Kaylorf4660012017-05-25 21:31:00 +000014097type.
14098
14099The second and third arguments specify the rounding mode and exception
14100behavior as described above.
14101
14102Semantics:
14103""""""""""
14104
14105This function returns the same values as the libm ``exp`` functions
14106would, and handles error conditions in the same way.
14107
14108
14109'``llvm.experimental.constrained.exp2``' Intrinsic
14110^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14111
14112Syntax:
14113"""""""
14114
14115::
14116
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +000014117 declare <type>
Andrew Kaylorf4660012017-05-25 21:31:00 +000014118 @llvm.experimental.constrained.exp2(<type> <op1>,
14119 metadata <rounding mode>,
14120 metadata <exception behavior>)
14121
14122Overview:
14123"""""""""
14124
14125The '``llvm.experimental.constrained.exp2``' intrinsic computes the base-2
14126exponential of the specified value.
14127
14128
14129Arguments:
14130""""""""""
14131
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000014132The first argument and the return value are floating-point numbers of the same
Andrew Kaylorf4660012017-05-25 21:31:00 +000014133type.
14134
14135The second and third arguments specify the rounding mode and exception
14136behavior as described above.
14137
14138Semantics:
14139""""""""""
14140
14141This function returns the same values as the libm ``exp2`` functions
14142would, and handles error conditions in the same way.
14143
14144
14145'``llvm.experimental.constrained.log``' Intrinsic
14146^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14147
14148Syntax:
14149"""""""
14150
14151::
14152
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +000014153 declare <type>
Andrew Kaylorf4660012017-05-25 21:31:00 +000014154 @llvm.experimental.constrained.log(<type> <op1>,
14155 metadata <rounding mode>,
14156 metadata <exception behavior>)
14157
14158Overview:
14159"""""""""
14160
14161The '``llvm.experimental.constrained.log``' intrinsic computes the base-e
14162logarithm of the specified value.
14163
14164Arguments:
14165""""""""""
14166
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000014167The first argument and the return value are floating-point numbers of the same
Andrew Kaylorf4660012017-05-25 21:31:00 +000014168type.
14169
14170The second and third arguments specify the rounding mode and exception
14171behavior as described above.
14172
14173
14174Semantics:
14175""""""""""
14176
14177This function returns the same values as the libm ``log`` functions
14178would, and handles error conditions in the same way.
14179
14180
14181'``llvm.experimental.constrained.log10``' Intrinsic
14182^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14183
14184Syntax:
14185"""""""
14186
14187::
14188
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +000014189 declare <type>
Andrew Kaylorf4660012017-05-25 21:31:00 +000014190 @llvm.experimental.constrained.log10(<type> <op1>,
14191 metadata <rounding mode>,
14192 metadata <exception behavior>)
14193
14194Overview:
14195"""""""""
14196
14197The '``llvm.experimental.constrained.log10``' intrinsic computes the base-10
14198logarithm of the specified value.
14199
14200Arguments:
14201""""""""""
14202
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000014203The first argument and the return value are floating-point numbers of the same
Andrew Kaylorf4660012017-05-25 21:31:00 +000014204type.
14205
14206The second and third arguments specify the rounding mode and exception
14207behavior as described above.
14208
14209Semantics:
14210""""""""""
14211
14212This function returns the same values as the libm ``log10`` functions
14213would, and handles error conditions in the same way.
14214
14215
14216'``llvm.experimental.constrained.log2``' Intrinsic
14217^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14218
14219Syntax:
14220"""""""
14221
14222::
14223
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +000014224 declare <type>
Andrew Kaylorf4660012017-05-25 21:31:00 +000014225 @llvm.experimental.constrained.log2(<type> <op1>,
14226 metadata <rounding mode>,
14227 metadata <exception behavior>)
14228
14229Overview:
14230"""""""""
14231
14232The '``llvm.experimental.constrained.log2``' intrinsic computes the base-2
14233logarithm of the specified value.
14234
14235Arguments:
14236""""""""""
14237
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000014238The first argument and the return value are floating-point numbers of the same
Andrew Kaylorf4660012017-05-25 21:31:00 +000014239type.
14240
14241The second and third arguments specify the rounding mode and exception
14242behavior as described above.
14243
14244Semantics:
14245""""""""""
14246
14247This function returns the same values as the libm ``log2`` functions
14248would, and handles error conditions in the same way.
14249
14250
14251'``llvm.experimental.constrained.rint``' Intrinsic
14252^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14253
14254Syntax:
14255"""""""
14256
14257::
14258
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +000014259 declare <type>
Andrew Kaylorf4660012017-05-25 21:31:00 +000014260 @llvm.experimental.constrained.rint(<type> <op1>,
14261 metadata <rounding mode>,
14262 metadata <exception behavior>)
14263
14264Overview:
14265"""""""""
14266
14267The '``llvm.experimental.constrained.rint``' intrinsic returns the first
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000014268operand rounded to the nearest integer. It may raise an inexact floating-point
Andrew Kaylorf4660012017-05-25 21:31:00 +000014269exception if the operand is not an integer.
14270
14271Arguments:
14272""""""""""
14273
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000014274The first argument and the return value are floating-point numbers of the same
Andrew Kaylorf4660012017-05-25 21:31:00 +000014275type.
14276
14277The second and third arguments specify the rounding mode and exception
14278behavior as described above.
14279
14280Semantics:
14281""""""""""
14282
14283This function returns the same values as the libm ``rint`` functions
14284would, and handles error conditions in the same way. The rounding mode is
14285described, not determined, by the rounding mode argument. The actual rounding
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000014286mode is determined by the runtime floating-point environment. The rounding
Andrew Kaylorf4660012017-05-25 21:31:00 +000014287mode argument is only intended as information to the compiler.
14288
14289
14290'``llvm.experimental.constrained.nearbyint``' Intrinsic
14291^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14292
14293Syntax:
14294"""""""
14295
14296::
14297
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +000014298 declare <type>
Andrew Kaylorf4660012017-05-25 21:31:00 +000014299 @llvm.experimental.constrained.nearbyint(<type> <op1>,
14300 metadata <rounding mode>,
14301 metadata <exception behavior>)
14302
14303Overview:
14304"""""""""
14305
14306The '``llvm.experimental.constrained.nearbyint``' intrinsic returns the first
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000014307operand rounded to the nearest integer. It will not raise an inexact
14308floating-point exception if the operand is not an integer.
Andrew Kaylorf4660012017-05-25 21:31:00 +000014309
14310
14311Arguments:
14312""""""""""
14313
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000014314The first argument and the return value are floating-point numbers of the same
Andrew Kaylorf4660012017-05-25 21:31:00 +000014315type.
14316
14317The second and third arguments specify the rounding mode and exception
14318behavior as described above.
14319
14320Semantics:
14321""""""""""
14322
14323This function returns the same values as the libm ``nearbyint`` functions
14324would, and handles error conditions in the same way. The rounding mode is
14325described, not determined, by the rounding mode argument. The actual rounding
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000014326mode is determined by the runtime floating-point environment. The rounding
Andrew Kaylorf4660012017-05-25 21:31:00 +000014327mode argument is only intended as information to the compiler.
14328
14329
Sean Silvab084af42012-12-07 10:36:55 +000014330General Intrinsics
14331------------------
14332
14333This class of intrinsics is designed to be generic and has no specific
14334purpose.
14335
14336'``llvm.var.annotation``' Intrinsic
14337^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14338
14339Syntax:
14340"""""""
14341
14342::
14343
14344 declare void @llvm.var.annotation(i8* <val>, i8* <str>, i8* <str>, i32 <int>)
14345
14346Overview:
14347"""""""""
14348
14349The '``llvm.var.annotation``' intrinsic.
14350
14351Arguments:
14352""""""""""
14353
14354The first argument is a pointer to a value, the second is a pointer to a
14355global string, the third is a pointer to a global string which is the
14356source file name, and the last argument is the line number.
14357
14358Semantics:
14359""""""""""
14360
14361This intrinsic allows annotation of local variables with arbitrary
14362strings. This can be useful for special purpose optimizations that want
14363to look for these annotations. These have no other defined use; they are
14364ignored by code generation and optimization.
14365
Michael Gottesman88d18832013-03-26 00:34:27 +000014366'``llvm.ptr.annotation.*``' Intrinsic
14367^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14368
14369Syntax:
14370"""""""
14371
14372This is an overloaded intrinsic. You can use '``llvm.ptr.annotation``' on a
14373pointer to an integer of any width. *NOTE* you must specify an address space for
14374the pointer. The identifier for the default address space is the integer
14375'``0``'.
14376
14377::
14378
14379 declare i8* @llvm.ptr.annotation.p<address space>i8(i8* <val>, i8* <str>, i8* <str>, i32 <int>)
14380 declare i16* @llvm.ptr.annotation.p<address space>i16(i16* <val>, i8* <str>, i8* <str>, i32 <int>)
14381 declare i32* @llvm.ptr.annotation.p<address space>i32(i32* <val>, i8* <str>, i8* <str>, i32 <int>)
14382 declare i64* @llvm.ptr.annotation.p<address space>i64(i64* <val>, i8* <str>, i8* <str>, i32 <int>)
14383 declare i256* @llvm.ptr.annotation.p<address space>i256(i256* <val>, i8* <str>, i8* <str>, i32 <int>)
14384
14385Overview:
14386"""""""""
14387
14388The '``llvm.ptr.annotation``' intrinsic.
14389
14390Arguments:
14391""""""""""
14392
14393The first argument is a pointer to an integer value of arbitrary bitwidth
14394(result of some expression), the second is a pointer to a global string, the
14395third is a pointer to a global string which is the source file name, and the
14396last argument is the line number. It returns the value of the first argument.
14397
14398Semantics:
14399""""""""""
14400
14401This intrinsic allows annotation of a pointer to an integer with arbitrary
14402strings. This can be useful for special purpose optimizations that want to look
14403for these annotations. These have no other defined use; they are ignored by code
14404generation and optimization.
14405
Sean Silvab084af42012-12-07 10:36:55 +000014406'``llvm.annotation.*``' Intrinsic
14407^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14408
14409Syntax:
14410"""""""
14411
14412This is an overloaded intrinsic. You can use '``llvm.annotation``' on
14413any integer bit width.
14414
14415::
14416
14417 declare i8 @llvm.annotation.i8(i8 <val>, i8* <str>, i8* <str>, i32 <int>)
14418 declare i16 @llvm.annotation.i16(i16 <val>, i8* <str>, i8* <str>, i32 <int>)
14419 declare i32 @llvm.annotation.i32(i32 <val>, i8* <str>, i8* <str>, i32 <int>)
14420 declare i64 @llvm.annotation.i64(i64 <val>, i8* <str>, i8* <str>, i32 <int>)
14421 declare i256 @llvm.annotation.i256(i256 <val>, i8* <str>, i8* <str>, i32 <int>)
14422
14423Overview:
14424"""""""""
14425
14426The '``llvm.annotation``' intrinsic.
14427
14428Arguments:
14429""""""""""
14430
14431The first argument is an integer value (result of some expression), the
14432second is a pointer to a global string, the third is a pointer to a
14433global string which is the source file name, and the last argument is
14434the line number. It returns the value of the first argument.
14435
14436Semantics:
14437""""""""""
14438
14439This intrinsic allows annotations to be put on arbitrary expressions
14440with arbitrary strings. This can be useful for special purpose
14441optimizations that want to look for these annotations. These have no
14442other defined use; they are ignored by code generation and optimization.
14443
Reid Klecknere33c94f2017-09-05 20:14:58 +000014444'``llvm.codeview.annotation``' Intrinsic
Reid Klecknerd4523682017-09-05 20:26:25 +000014445^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Reid Klecknere33c94f2017-09-05 20:14:58 +000014446
14447Syntax:
14448"""""""
14449
14450This annotation emits a label at its program point and an associated
14451``S_ANNOTATION`` codeview record with some additional string metadata. This is
14452used to implement MSVC's ``__annotation`` intrinsic. It is marked
14453``noduplicate``, so calls to this intrinsic prevent inlining and should be
14454considered expensive.
14455
14456::
14457
14458 declare void @llvm.codeview.annotation(metadata)
14459
14460Arguments:
14461""""""""""
14462
14463The argument should be an MDTuple containing any number of MDStrings.
14464
Sean Silvab084af42012-12-07 10:36:55 +000014465'``llvm.trap``' Intrinsic
14466^^^^^^^^^^^^^^^^^^^^^^^^^
14467
14468Syntax:
14469"""""""
14470
14471::
14472
14473 declare void @llvm.trap() noreturn nounwind
14474
14475Overview:
14476"""""""""
14477
14478The '``llvm.trap``' intrinsic.
14479
14480Arguments:
14481""""""""""
14482
14483None.
14484
14485Semantics:
14486""""""""""
14487
14488This intrinsic is lowered to the target dependent trap instruction. If
14489the target does not have a trap instruction, this intrinsic will be
14490lowered to a call of the ``abort()`` function.
14491
14492'``llvm.debugtrap``' Intrinsic
14493^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14494
14495Syntax:
14496"""""""
14497
14498::
14499
14500 declare void @llvm.debugtrap() nounwind
14501
14502Overview:
14503"""""""""
14504
14505The '``llvm.debugtrap``' intrinsic.
14506
14507Arguments:
14508""""""""""
14509
14510None.
14511
14512Semantics:
14513""""""""""
14514
14515This intrinsic is lowered to code which is intended to cause an
14516execution trap with the intention of requesting the attention of a
14517debugger.
14518
14519'``llvm.stackprotector``' Intrinsic
14520^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14521
14522Syntax:
14523"""""""
14524
14525::
14526
14527 declare void @llvm.stackprotector(i8* <guard>, i8** <slot>)
14528
14529Overview:
14530"""""""""
14531
14532The ``llvm.stackprotector`` intrinsic takes the ``guard`` and stores it
14533onto the stack at ``slot``. The stack slot is adjusted to ensure that it
14534is placed on the stack before local variables.
14535
14536Arguments:
14537""""""""""
14538
14539The ``llvm.stackprotector`` intrinsic requires two pointer arguments.
14540The first argument is the value loaded from the stack guard
14541``@__stack_chk_guard``. The second variable is an ``alloca`` that has
14542enough space to hold the value of the guard.
14543
14544Semantics:
14545""""""""""
14546
Michael Gottesmandafc7d92013-08-12 18:35:32 +000014547This intrinsic causes the prologue/epilogue inserter to force the position of
14548the ``AllocaInst`` stack slot to be before local variables on the stack. This is
14549to ensure that if a local variable on the stack is overwritten, it will destroy
14550the value of the guard. When the function exits, the guard on the stack is
14551checked against the original guard by ``llvm.stackprotectorcheck``. If they are
14552different, then ``llvm.stackprotectorcheck`` causes the program to abort by
14553calling the ``__stack_chk_fail()`` function.
14554
Tim Shene885d5e2016-04-19 19:40:37 +000014555'``llvm.stackguard``' Intrinsic
14556^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14557
14558Syntax:
14559"""""""
14560
14561::
14562
14563 declare i8* @llvm.stackguard()
14564
14565Overview:
14566"""""""""
14567
14568The ``llvm.stackguard`` intrinsic returns the system stack guard value.
14569
14570It should not be generated by frontends, since it is only for internal usage.
14571The reason why we create this intrinsic is that we still support IR form Stack
14572Protector in FastISel.
14573
14574Arguments:
14575""""""""""
14576
14577None.
14578
14579Semantics:
14580""""""""""
14581
14582On some platforms, the value returned by this intrinsic remains unchanged
14583between loads in the same thread. On other platforms, it returns the same
14584global variable value, if any, e.g. ``@__stack_chk_guard``.
14585
14586Currently some platforms have IR-level customized stack guard loading (e.g.
14587X86 Linux) that is not handled by ``llvm.stackguard()``, while they should be
14588in the future.
14589
Sean Silvab084af42012-12-07 10:36:55 +000014590'``llvm.objectsize``' Intrinsic
14591^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14592
14593Syntax:
14594"""""""
14595
14596::
14597
George Burgess IV56c7e882017-03-21 20:08:59 +000014598 declare i32 @llvm.objectsize.i32(i8* <object>, i1 <min>, i1 <nullunknown>)
14599 declare i64 @llvm.objectsize.i64(i8* <object>, i1 <min>, i1 <nullunknown>)
Sean Silvab084af42012-12-07 10:36:55 +000014600
14601Overview:
14602"""""""""
14603
14604The ``llvm.objectsize`` intrinsic is designed to provide information to
14605the optimizers to determine at compile time whether a) an operation
14606(like memcpy) will overflow a buffer that corresponds to an object, or
14607b) that a runtime check for overflow isn't necessary. An object in this
14608context means an allocation of a specific class, structure, array, or
14609other object.
14610
14611Arguments:
14612""""""""""
14613
George Burgess IV56c7e882017-03-21 20:08:59 +000014614The ``llvm.objectsize`` intrinsic takes three arguments. The first argument is
14615a pointer to or into the ``object``. The second argument determines whether
14616``llvm.objectsize`` returns 0 (if true) or -1 (if false) when the object size
14617is unknown. The third argument controls how ``llvm.objectsize`` acts when
George Burgess IV3fbfa9c42018-07-09 22:21:16 +000014618``null`` in address space 0 is used as its pointer argument. If it's ``false``,
14619``llvm.objectsize`` reports 0 bytes available when given ``null``. Otherwise, if
14620the ``null`` is in a non-zero address space or if ``true`` is given for the
14621third argument of ``llvm.objectsize``, we assume its size is unknown.
George Burgess IV56c7e882017-03-21 20:08:59 +000014622
14623The second and third arguments only accept constants.
Sean Silvab084af42012-12-07 10:36:55 +000014624
14625Semantics:
14626""""""""""
14627
14628The ``llvm.objectsize`` intrinsic is lowered to a constant representing
14629the size of the object concerned. If the size cannot be determined at
14630compile time, ``llvm.objectsize`` returns ``i32/i64 -1 or 0`` (depending
14631on the ``min`` argument).
14632
14633'``llvm.expect``' Intrinsic
14634^^^^^^^^^^^^^^^^^^^^^^^^^^^
14635
14636Syntax:
14637"""""""
14638
Duncan P. N. Exon Smith1ff08e32014-02-02 22:43:55 +000014639This is an overloaded intrinsic. You can use ``llvm.expect`` on any
14640integer bit width.
14641
Sean Silvab084af42012-12-07 10:36:55 +000014642::
14643
Duncan P. N. Exon Smith1ff08e32014-02-02 22:43:55 +000014644 declare i1 @llvm.expect.i1(i1 <val>, i1 <expected_val>)
Sean Silvab084af42012-12-07 10:36:55 +000014645 declare i32 @llvm.expect.i32(i32 <val>, i32 <expected_val>)
14646 declare i64 @llvm.expect.i64(i64 <val>, i64 <expected_val>)
14647
14648Overview:
14649"""""""""
14650
14651The ``llvm.expect`` intrinsic provides information about expected (the
14652most probable) value of ``val``, which can be used by optimizers.
14653
14654Arguments:
14655""""""""""
14656
14657The ``llvm.expect`` intrinsic takes two arguments. The first argument is
14658a value. The second argument is an expected value, this needs to be a
14659constant value, variables are not allowed.
14660
14661Semantics:
14662""""""""""
14663
14664This intrinsic is lowered to the ``val``.
14665
Philip Reamese0e90832015-04-26 22:23:12 +000014666.. _int_assume:
14667
Hal Finkel93046912014-07-25 21:13:35 +000014668'``llvm.assume``' Intrinsic
14669^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14670
14671Syntax:
14672"""""""
14673
14674::
14675
14676 declare void @llvm.assume(i1 %cond)
14677
14678Overview:
14679"""""""""
14680
14681The ``llvm.assume`` allows the optimizer to assume that the provided
14682condition is true. This information can then be used in simplifying other parts
14683of the code.
14684
14685Arguments:
14686""""""""""
14687
14688The condition which the optimizer may assume is always true.
14689
14690Semantics:
14691""""""""""
14692
14693The intrinsic allows the optimizer to assume that the provided condition is
14694always true whenever the control flow reaches the intrinsic call. No code is
14695generated for this intrinsic, and instructions that contribute only to the
14696provided condition are not used for code generation. If the condition is
14697violated during execution, the behavior is undefined.
14698
Sanjay Patel1ed2bb52015-01-14 16:03:58 +000014699Note that the optimizer might limit the transformations performed on values
Hal Finkel93046912014-07-25 21:13:35 +000014700used by the ``llvm.assume`` intrinsic in order to preserve the instructions
14701only used to form the intrinsic's input argument. This might prove undesirable
Sanjay Patel1ed2bb52015-01-14 16:03:58 +000014702if the extra information provided by the ``llvm.assume`` intrinsic does not cause
Hal Finkel93046912014-07-25 21:13:35 +000014703sufficient overall improvement in code quality. For this reason,
14704``llvm.assume`` should not be used to document basic mathematical invariants
14705that the optimizer can otherwise deduce or facts that are of little use to the
14706optimizer.
14707
Daniel Berlin2c438a32017-02-07 19:29:25 +000014708.. _int_ssa_copy:
14709
14710'``llvm.ssa_copy``' Intrinsic
14711^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14712
14713Syntax:
14714"""""""
14715
14716::
14717
14718 declare type @llvm.ssa_copy(type %operand) returned(1) readnone
14719
14720Arguments:
14721""""""""""
14722
14723The first argument is an operand which is used as the returned value.
14724
14725Overview:
14726""""""""""
14727
14728The ``llvm.ssa_copy`` intrinsic can be used to attach information to
14729operations by copying them and giving them new names. For example,
14730the PredicateInfo utility uses it to build Extended SSA form, and
14731attach various forms of information to operands that dominate specific
14732uses. It is not meant for general use, only for building temporary
14733renaming forms that require value splits at certain points.
14734
Peter Collingbourne7efd7502016-06-24 21:21:32 +000014735.. _type.test:
Peter Collingbournee6909c82015-02-20 20:30:47 +000014736
Peter Collingbourne7efd7502016-06-24 21:21:32 +000014737'``llvm.type.test``' Intrinsic
Peter Collingbournee6909c82015-02-20 20:30:47 +000014738^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14739
14740Syntax:
14741"""""""
14742
14743::
14744
Peter Collingbourne7efd7502016-06-24 21:21:32 +000014745 declare i1 @llvm.type.test(i8* %ptr, metadata %type) nounwind readnone
Peter Collingbournee6909c82015-02-20 20:30:47 +000014746
14747
14748Arguments:
14749""""""""""
14750
14751The first argument is a pointer to be tested. The second argument is a
Peter Collingbourne7efd7502016-06-24 21:21:32 +000014752metadata object representing a :doc:`type identifier <TypeMetadata>`.
Peter Collingbournee6909c82015-02-20 20:30:47 +000014753
14754Overview:
14755"""""""""
14756
Peter Collingbourne7efd7502016-06-24 21:21:32 +000014757The ``llvm.type.test`` intrinsic tests whether the given pointer is associated
14758with the given type identifier.
Peter Collingbournee6909c82015-02-20 20:30:47 +000014759
Peter Collingbourne0312f612016-06-25 00:23:04 +000014760'``llvm.type.checked.load``' Intrinsic
14761^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14762
14763Syntax:
14764"""""""
14765
14766::
14767
14768 declare {i8*, i1} @llvm.type.checked.load(i8* %ptr, i32 %offset, metadata %type) argmemonly nounwind readonly
14769
14770
14771Arguments:
14772""""""""""
14773
14774The first argument is a pointer from which to load a function pointer. The
14775second argument is the byte offset from which to load the function pointer. The
14776third argument is a metadata object representing a :doc:`type identifier
14777<TypeMetadata>`.
14778
14779Overview:
14780"""""""""
14781
14782The ``llvm.type.checked.load`` intrinsic safely loads a function pointer from a
14783virtual table pointer using type metadata. This intrinsic is used to implement
14784control flow integrity in conjunction with virtual call optimization. The
14785virtual call optimization pass will optimize away ``llvm.type.checked.load``
14786intrinsics associated with devirtualized calls, thereby removing the type
14787check in cases where it is not needed to enforce the control flow integrity
14788constraint.
14789
14790If the given pointer is associated with a type metadata identifier, this
14791function returns true as the second element of its return value. (Note that
14792the function may also return true if the given pointer is not associated
14793with a type metadata identifier.) If the function's return value's second
14794element is true, the following rules apply to the first element:
14795
14796- If the given pointer is associated with the given type metadata identifier,
14797 it is the function pointer loaded from the given byte offset from the given
14798 pointer.
14799
14800- If the given pointer is not associated with the given type metadata
14801 identifier, it is one of the following (the choice of which is unspecified):
14802
14803 1. The function pointer that would have been loaded from an arbitrarily chosen
14804 (through an unspecified mechanism) pointer associated with the type
14805 metadata.
14806
14807 2. If the function has a non-void return type, a pointer to a function that
14808 returns an unspecified value without causing side effects.
14809
14810If the function's return value's second element is false, the value of the
14811first element is undefined.
14812
14813
Sean Silvab084af42012-12-07 10:36:55 +000014814'``llvm.donothing``' Intrinsic
14815^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14816
14817Syntax:
14818"""""""
14819
14820::
14821
14822 declare void @llvm.donothing() nounwind readnone
14823
14824Overview:
14825"""""""""
14826
Juergen Ributzkac9161192014-10-23 22:36:13 +000014827The ``llvm.donothing`` intrinsic doesn't perform any operation. It's one of only
Sanjoy Das7a4c94d2016-02-26 03:33:59 +000014828three intrinsics (besides ``llvm.experimental.patchpoint`` and
14829``llvm.experimental.gc.statepoint``) that can be called with an invoke
14830instruction.
Sean Silvab084af42012-12-07 10:36:55 +000014831
14832Arguments:
14833""""""""""
14834
14835None.
14836
14837Semantics:
14838""""""""""
14839
14840This intrinsic does nothing, and it's removed by optimizers and ignored
14841by codegen.
Andrew Trick5e029ce2013-12-24 02:57:25 +000014842
Sanjoy Dasb51325d2016-03-11 19:08:34 +000014843'``llvm.experimental.deoptimize``' Intrinsic
14844^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14845
14846Syntax:
14847"""""""
14848
14849::
14850
14851 declare type @llvm.experimental.deoptimize(...) [ "deopt"(...) ]
14852
14853Overview:
14854"""""""""
14855
14856This intrinsic, together with :ref:`deoptimization operand bundles
14857<deopt_opbundles>`, allow frontends to express transfer of control and
14858frame-local state from the currently executing (typically more specialized,
14859hence faster) version of a function into another (typically more generic, hence
14860slower) version.
14861
14862In languages with a fully integrated managed runtime like Java and JavaScript
14863this intrinsic can be used to implement "uncommon trap" or "side exit" like
14864functionality. In unmanaged languages like C and C++, this intrinsic can be
14865used to represent the slow paths of specialized functions.
14866
14867
14868Arguments:
14869""""""""""
14870
14871The intrinsic takes an arbitrary number of arguments, whose meaning is
14872decided by the :ref:`lowering strategy<deoptimize_lowering>`.
14873
14874Semantics:
14875""""""""""
14876
14877The ``@llvm.experimental.deoptimize`` intrinsic executes an attached
14878deoptimization continuation (denoted using a :ref:`deoptimization
14879operand bundle <deopt_opbundles>`) and returns the value returned by
14880the deoptimization continuation. Defining the semantic properties of
14881the continuation itself is out of scope of the language reference --
14882as far as LLVM is concerned, the deoptimization continuation can
14883invoke arbitrary side effects, including reading from and writing to
14884the entire heap.
14885
14886Deoptimization continuations expressed using ``"deopt"`` operand bundles always
14887continue execution to the end of the physical frame containing them, so all
14888calls to ``@llvm.experimental.deoptimize`` must be in "tail position":
14889
14890 - ``@llvm.experimental.deoptimize`` cannot be invoked.
14891 - The call must immediately precede a :ref:`ret <i_ret>` instruction.
14892 - The ``ret`` instruction must return the value produced by the
14893 ``@llvm.experimental.deoptimize`` call if there is one, or void.
14894
14895Note that the above restrictions imply that the return type for a call to
14896``@llvm.experimental.deoptimize`` will match the return type of its immediate
14897caller.
14898
14899The inliner composes the ``"deopt"`` continuations of the caller into the
14900``"deopt"`` continuations present in the inlinee, and also updates calls to this
14901intrinsic to return directly from the frame of the function it inlined into.
14902
Sanjoy Dase0aa4142016-05-12 01:17:38 +000014903All declarations of ``@llvm.experimental.deoptimize`` must share the
14904same calling convention.
14905
Sanjoy Dasb51325d2016-03-11 19:08:34 +000014906.. _deoptimize_lowering:
14907
14908Lowering:
14909"""""""""
14910
Sanjoy Dasdf9ae702016-03-24 20:23:29 +000014911Calls to ``@llvm.experimental.deoptimize`` are lowered to calls to the
14912symbol ``__llvm_deoptimize`` (it is the frontend's responsibility to
14913ensure that this symbol is defined). The call arguments to
14914``@llvm.experimental.deoptimize`` are lowered as if they were formal
14915arguments of the specified types, and not as varargs.
14916
Sanjoy Dasb51325d2016-03-11 19:08:34 +000014917
Sanjoy Das021de052016-03-31 00:18:46 +000014918'``llvm.experimental.guard``' Intrinsic
14919^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14920
14921Syntax:
14922"""""""
14923
14924::
14925
14926 declare void @llvm.experimental.guard(i1, ...) [ "deopt"(...) ]
14927
14928Overview:
14929"""""""""
14930
14931This intrinsic, together with :ref:`deoptimization operand bundles
14932<deopt_opbundles>`, allows frontends to express guards or checks on
14933optimistic assumptions made during compilation. The semantics of
14934``@llvm.experimental.guard`` is defined in terms of
14935``@llvm.experimental.deoptimize`` -- its body is defined to be
14936equivalent to:
14937
Renato Golin124f2592016-07-20 12:16:38 +000014938.. code-block:: text
Sanjoy Das021de052016-03-31 00:18:46 +000014939
Renato Golin124f2592016-07-20 12:16:38 +000014940 define void @llvm.experimental.guard(i1 %pred, <args...>) {
14941 %realPred = and i1 %pred, undef
14942 br i1 %realPred, label %continue, label %leave [, !make.implicit !{}]
Sanjoy Das021de052016-03-31 00:18:46 +000014943
Renato Golin124f2592016-07-20 12:16:38 +000014944 leave:
14945 call void @llvm.experimental.deoptimize(<args...>) [ "deopt"() ]
14946 ret void
Sanjoy Das021de052016-03-31 00:18:46 +000014947
Renato Golin124f2592016-07-20 12:16:38 +000014948 continue:
14949 ret void
14950 }
Sanjoy Das021de052016-03-31 00:18:46 +000014951
Sanjoy Das47cf2af2016-04-30 00:55:59 +000014952
14953with the optional ``[, !make.implicit !{}]`` present if and only if it
14954is present on the call site. For more details on ``!make.implicit``,
14955see :doc:`FaultMaps`.
14956
Sanjoy Das021de052016-03-31 00:18:46 +000014957In words, ``@llvm.experimental.guard`` executes the attached
14958``"deopt"`` continuation if (but **not** only if) its first argument
14959is ``false``. Since the optimizer is allowed to replace the ``undef``
14960with an arbitrary value, it can optimize guard to fail "spuriously",
14961i.e. without the original condition being false (hence the "not only
14962if"); and this allows for "check widening" type optimizations.
14963
14964``@llvm.experimental.guard`` cannot be invoked.
14965
14966
Peter Collingbourne7dd8dbf2016-04-22 21:18:02 +000014967'``llvm.load.relative``' Intrinsic
14968^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14969
14970Syntax:
14971"""""""
14972
14973::
14974
14975 declare i8* @llvm.load.relative.iN(i8* %ptr, iN %offset) argmemonly nounwind readonly
14976
14977Overview:
14978"""""""""
14979
14980This intrinsic loads a 32-bit value from the address ``%ptr + %offset``,
14981adds ``%ptr`` to that value and returns it. The constant folder specifically
14982recognizes the form of this intrinsic and the constant initializers it may
14983load from; if a loaded constant initializer is known to have the form
14984``i32 trunc(x - %ptr)``, the intrinsic call is folded to ``x``.
14985
14986LLVM provides that the calculation of such a constant initializer will
14987not overflow at link time under the medium code model if ``x`` is an
14988``unnamed_addr`` function. However, it does not provide this guarantee for
14989a constant initializer folded into a function body. This intrinsic can be
14990used to avoid the possibility of overflows when loading from such a constant.
14991
Dan Gohman2c74fe92017-11-08 21:59:51 +000014992'``llvm.sideeffect``' Intrinsic
14993^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14994
14995Syntax:
14996"""""""
14997
14998::
14999
15000 declare void @llvm.sideeffect() inaccessiblememonly nounwind
15001
15002Overview:
15003"""""""""
15004
15005The ``llvm.sideeffect`` intrinsic doesn't perform any operation. Optimizers
15006treat it as having side effects, so it can be inserted into a loop to
15007indicate that the loop shouldn't be assumed to terminate (which could
15008potentially lead to the loop being optimized away entirely), even if it's
15009an infinite loop with no other side effects.
15010
15011Arguments:
15012""""""""""
15013
15014None.
15015
15016Semantics:
15017""""""""""
15018
15019This intrinsic actually does nothing, but optimizers must assume that it
15020has externally observable side effects.
15021
Andrew Trick5e029ce2013-12-24 02:57:25 +000015022Stack Map Intrinsics
15023--------------------
15024
15025LLVM provides experimental intrinsics to support runtime patching
15026mechanisms commonly desired in dynamic language JITs. These intrinsics
15027are described in :doc:`StackMaps`.
Igor Laevsky4f31e522016-12-29 14:31:07 +000015028
15029Element Wise Atomic Memory Intrinsics
Igor Laevskyfedab152016-12-29 15:08:57 +000015030-------------------------------------
Igor Laevsky4f31e522016-12-29 14:31:07 +000015031
15032These intrinsics are similar to the standard library memory intrinsics except
15033that they perform memory transfer as a sequence of atomic memory accesses.
15034
Daniel Neilson3faabbb2017-06-16 14:43:59 +000015035.. _int_memcpy_element_unordered_atomic:
Igor Laevsky4f31e522016-12-29 14:31:07 +000015036
Daniel Neilson3faabbb2017-06-16 14:43:59 +000015037'``llvm.memcpy.element.unordered.atomic``' Intrinsic
15038^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Igor Laevsky4f31e522016-12-29 14:31:07 +000015039
15040Syntax:
15041"""""""
15042
Daniel Neilson3faabbb2017-06-16 14:43:59 +000015043This is an overloaded intrinsic. You can use ``llvm.memcpy.element.unordered.atomic`` on
Igor Laevsky4f31e522016-12-29 14:31:07 +000015044any integer bit width and for different address spaces. Not all targets
15045support all bit widths however.
15046
15047::
15048
Daniel Neilson3faabbb2017-06-16 14:43:59 +000015049 declare void @llvm.memcpy.element.unordered.atomic.p0i8.p0i8.i32(i8* <dest>,
15050 i8* <src>,
15051 i32 <len>,
15052 i32 <element_size>)
15053 declare void @llvm.memcpy.element.unordered.atomic.p0i8.p0i8.i64(i8* <dest>,
15054 i8* <src>,
15055 i64 <len>,
15056 i32 <element_size>)
Igor Laevsky4f31e522016-12-29 14:31:07 +000015057
15058Overview:
15059"""""""""
15060
Daniel Neilson3faabbb2017-06-16 14:43:59 +000015061The '``llvm.memcpy.element.unordered.atomic.*``' intrinsic is a specialization of the
15062'``llvm.memcpy.*``' intrinsic. It differs in that the ``dest`` and ``src`` are treated
15063as arrays with elements that are exactly ``element_size`` bytes, and the copy between
15064buffers uses a sequence of :ref:`unordered atomic <ordering>` load/store operations
15065that are a positive integer multiple of the ``element_size`` in size.
Igor Laevsky4f31e522016-12-29 14:31:07 +000015066
15067Arguments:
15068""""""""""
15069
Daniel Neilson3faabbb2017-06-16 14:43:59 +000015070The first three arguments are the same as they are in the :ref:`@llvm.memcpy <int_memcpy>`
15071intrinsic, with the added constraint that ``len`` is required to be a positive integer
15072multiple of the ``element_size``. If ``len`` is not a positive integer multiple of
15073``element_size``, then the behaviour of the intrinsic is undefined.
Igor Laevsky4f31e522016-12-29 14:31:07 +000015074
Daniel Neilson3faabbb2017-06-16 14:43:59 +000015075``element_size`` must be a compile-time constant positive power of two no greater than
15076target-specific atomic access size limit.
Igor Laevsky4f31e522016-12-29 14:31:07 +000015077
Daniel Neilson3faabbb2017-06-16 14:43:59 +000015078For each of the input pointers ``align`` parameter attribute must be specified. It
15079must be a power of two no less than the ``element_size``. Caller guarantees that
15080both the source and destination pointers are aligned to that boundary.
Igor Laevsky4f31e522016-12-29 14:31:07 +000015081
15082Semantics:
15083""""""""""
15084
Daniel Neilson3faabbb2017-06-16 14:43:59 +000015085The '``llvm.memcpy.element.unordered.atomic.*``' intrinsic copies ``len`` bytes of
15086memory from the source location to the destination location. These locations are not
15087allowed to overlap. The memory copy is performed as a sequence of load/store operations
15088where each access is guaranteed to be a multiple of ``element_size`` bytes wide and
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +000015089aligned at an ``element_size`` boundary.
Igor Laevsky4f31e522016-12-29 14:31:07 +000015090
15091The order of the copy is unspecified. The same value may be read from the source
15092buffer many times, but only one write is issued to the destination buffer per
Daniel Neilson3faabbb2017-06-16 14:43:59 +000015093element. It is well defined to have concurrent reads and writes to both source and
15094destination provided those reads and writes are unordered atomic when specified.
Igor Laevsky4f31e522016-12-29 14:31:07 +000015095
15096This intrinsic does not provide any additional ordering guarantees over those
15097provided by a set of unordered loads from the source location and stores to the
15098destination.
15099
15100Lowering:
Igor Laevskyfedab152016-12-29 15:08:57 +000015101"""""""""
Igor Laevsky4f31e522016-12-29 14:31:07 +000015102
Daniel Neilson3faabbb2017-06-16 14:43:59 +000015103In the most general case call to the '``llvm.memcpy.element.unordered.atomic.*``' is
15104lowered to a call to the symbol ``__llvm_memcpy_element_unordered_atomic_*``. Where '*'
15105is replaced with an actual element size.
Igor Laevsky4f31e522016-12-29 14:31:07 +000015106
Daniel Neilson57226ef2017-07-12 15:25:26 +000015107Optimizer is allowed to inline memory copy when it's profitable to do so.
15108
15109'``llvm.memmove.element.unordered.atomic``' Intrinsic
15110^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15111
15112Syntax:
15113"""""""
15114
15115This is an overloaded intrinsic. You can use
15116``llvm.memmove.element.unordered.atomic`` on any integer bit width and for
15117different address spaces. Not all targets support all bit widths however.
15118
15119::
15120
15121 declare void @llvm.memmove.element.unordered.atomic.p0i8.p0i8.i32(i8* <dest>,
15122 i8* <src>,
15123 i32 <len>,
15124 i32 <element_size>)
15125 declare void @llvm.memmove.element.unordered.atomic.p0i8.p0i8.i64(i8* <dest>,
15126 i8* <src>,
15127 i64 <len>,
15128 i32 <element_size>)
15129
15130Overview:
15131"""""""""
15132
15133The '``llvm.memmove.element.unordered.atomic.*``' intrinsic is a specialization
15134of the '``llvm.memmove.*``' intrinsic. It differs in that the ``dest`` and
15135``src`` are treated as arrays with elements that are exactly ``element_size``
15136bytes, and the copy between buffers uses a sequence of
15137:ref:`unordered atomic <ordering>` load/store operations that are a positive
15138integer multiple of the ``element_size`` in size.
15139
15140Arguments:
15141""""""""""
15142
15143The first three arguments are the same as they are in the
15144:ref:`@llvm.memmove <int_memmove>` intrinsic, with the added constraint that
15145``len`` is required to be a positive integer multiple of the ``element_size``.
15146If ``len`` is not a positive integer multiple of ``element_size``, then the
15147behaviour of the intrinsic is undefined.
15148
15149``element_size`` must be a compile-time constant positive power of two no
15150greater than a target-specific atomic access size limit.
15151
15152For each of the input pointers the ``align`` parameter attribute must be
15153specified. It must be a power of two no less than the ``element_size``. Caller
15154guarantees that both the source and destination pointers are aligned to that
15155boundary.
15156
15157Semantics:
15158""""""""""
15159
15160The '``llvm.memmove.element.unordered.atomic.*``' intrinsic copies ``len`` bytes
15161of memory from the source location to the destination location. These locations
15162are allowed to overlap. The memory copy is performed as a sequence of load/store
15163operations where each access is guaranteed to be a multiple of ``element_size``
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +000015164bytes wide and aligned at an ``element_size`` boundary.
Daniel Neilson57226ef2017-07-12 15:25:26 +000015165
15166The order of the copy is unspecified. The same value may be read from the source
15167buffer many times, but only one write is issued to the destination buffer per
15168element. It is well defined to have concurrent reads and writes to both source
15169and destination provided those reads and writes are unordered atomic when
15170specified.
15171
15172This intrinsic does not provide any additional ordering guarantees over those
15173provided by a set of unordered loads from the source location and stores to the
15174destination.
15175
15176Lowering:
15177"""""""""
15178
15179In the most general case call to the
15180'``llvm.memmove.element.unordered.atomic.*``' is lowered to a call to the symbol
15181``__llvm_memmove_element_unordered_atomic_*``. Where '*' is replaced with an
15182actual element size.
15183
Daniel Neilson3faabbb2017-06-16 14:43:59 +000015184The optimizer is allowed to inline the memory copy when it's profitable to do so.
Daniel Neilson965613e2017-07-12 21:57:23 +000015185
15186.. _int_memset_element_unordered_atomic:
15187
15188'``llvm.memset.element.unordered.atomic``' Intrinsic
15189^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15190
15191Syntax:
15192"""""""
15193
15194This is an overloaded intrinsic. You can use ``llvm.memset.element.unordered.atomic`` on
15195any integer bit width and for different address spaces. Not all targets
15196support all bit widths however.
15197
15198::
15199
15200 declare void @llvm.memset.element.unordered.atomic.p0i8.i32(i8* <dest>,
15201 i8 <value>,
15202 i32 <len>,
15203 i32 <element_size>)
15204 declare void @llvm.memset.element.unordered.atomic.p0i8.i64(i8* <dest>,
15205 i8 <value>,
15206 i64 <len>,
15207 i32 <element_size>)
15208
15209Overview:
15210"""""""""
15211
15212The '``llvm.memset.element.unordered.atomic.*``' intrinsic is a specialization of the
15213'``llvm.memset.*``' intrinsic. It differs in that the ``dest`` is treated as an array
15214with elements that are exactly ``element_size`` bytes, and the assignment to that array
15215uses uses a sequence of :ref:`unordered atomic <ordering>` store operations
15216that are a positive integer multiple of the ``element_size`` in size.
15217
15218Arguments:
15219""""""""""
15220
15221The first three arguments are the same as they are in the :ref:`@llvm.memset <int_memset>`
15222intrinsic, with the added constraint that ``len`` is required to be a positive integer
15223multiple of the ``element_size``. If ``len`` is not a positive integer multiple of
15224``element_size``, then the behaviour of the intrinsic is undefined.
15225
15226``element_size`` must be a compile-time constant positive power of two no greater than
15227target-specific atomic access size limit.
15228
15229The ``dest`` input pointer must have the ``align`` parameter attribute specified. It
15230must be a power of two no less than the ``element_size``. Caller guarantees that
15231the destination pointer is aligned to that boundary.
15232
15233Semantics:
15234""""""""""
15235
15236The '``llvm.memset.element.unordered.atomic.*``' intrinsic sets the ``len`` bytes of
15237memory starting at the destination location to the given ``value``. The memory is
15238set with a sequence of store operations where each access is guaranteed to be a
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +000015239multiple of ``element_size`` bytes wide and aligned at an ``element_size`` boundary.
Daniel Neilson965613e2017-07-12 21:57:23 +000015240
15241The order of the assignment is unspecified. Only one write is issued to the
15242destination buffer per element. It is well defined to have concurrent reads and
15243writes to the destination provided those reads and writes are unordered atomic
15244when specified.
15245
15246This intrinsic does not provide any additional ordering guarantees over those
15247provided by a set of unordered stores to the destination.
15248
15249Lowering:
15250"""""""""
15251
15252In the most general case call to the '``llvm.memset.element.unordered.atomic.*``' is
15253lowered to a call to the symbol ``__llvm_memset_element_unordered_atomic_*``. Where '*'
15254is replaced with an actual element size.
15255
15256The optimizer is allowed to inline the memory assignment when it's profitable to do so.