blob: d2250443d0b1d52798ffe090a6b99d6f855aa298 [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>`,
Alexander Richardson6bcf2ba2018-08-23 09:25:17 +0000722an optional address space, an optional section, an optional alignment,
David Majnemerdad0a642014-06-27 18:19:56 +0000723an 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``
Alexander Richardson6bcf2ba2018-08-23 09:25:17 +0000734or ``local_unnamed_addr`` attribute, an optional address space, a return type,
735an optional :ref:`parameter attribute <paramattrs>` for the return type, a function name, a possibly
Peter Collingbourne96efdd62016-06-14 21:01:22 +0000736empty 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
James Y Knightc0e6b8a2019-03-22 18:27:13 +0000744function return). If an explicit label name is not provided, a block is assigned
745an implicit numbered label, using the next value from the same counter as used
746for unnamed temporaries (:ref:`see above<identifiers>`). For example, if a
747function entry block does not have an explicit label, it will be assigned label
748"%0", then the first unnamed temporary in that block will be "%1", etc. If a
749numeric label is explicitly specified, it must match the numeric label that
750would be used implicitly.
Sean Silvab084af42012-12-07 10:36:55 +0000751
752The first basic block in a function is special in two ways: it is
753immediately executed on entrance to the function, and it is not allowed
754to have predecessor basic blocks (i.e. there can not be any branches to
755the entry block of a function). Because the block can have no
756predecessors, it also cannot have any :ref:`PHI nodes <i_phi>`.
757
758LLVM allows an explicit section to be specified for functions. If the
759target supports it, it will emit functions to the section specified.
Eric Christopher1e61ffd2015-02-19 18:46:25 +0000760Additionally, the function can be placed in a COMDAT.
Sean Silvab084af42012-12-07 10:36:55 +0000761
762An explicit alignment may be specified for a function. If not present,
763or if the alignment is set to zero, the alignment of the function is set
764by the target to whatever it feels convenient. If an explicit alignment
765is specified, the function is forced to have at least that much
766alignment. All alignments must be a power of 2.
767
Eric Christopher1e61ffd2015-02-19 18:46:25 +0000768If the ``unnamed_addr`` attribute is given, the address is known to not
Sean Silvab084af42012-12-07 10:36:55 +0000769be significant and two identical functions can be merged.
770
Peter Collingbourne96efdd62016-06-14 21:01:22 +0000771If the ``local_unnamed_addr`` attribute is given, the address is known to
772not be significant within the module.
773
Alexander Richardson6bcf2ba2018-08-23 09:25:17 +0000774If an explicit address space is not given, it will default to the program
775address space from the :ref:`datalayout string<langref_datalayout>`.
776
Sean Silvab084af42012-12-07 10:36:55 +0000777Syntax::
778
Sean Fertilec70d28b2017-10-26 15:00:26 +0000779 define [linkage] [PreemptionSpecifier] [visibility] [DLLStorageClass]
Sean Silvab084af42012-12-07 10:36:55 +0000780 [cconv] [ret attrs]
781 <ResultType> @<FunctionName> ([argument list])
Alexander Richardson6bcf2ba2018-08-23 09:25:17 +0000782 [(unnamed_addr|local_unnamed_addr)] [AddrSpace] [fn Attrs]
783 [section "name"] [comdat [($name)]] [align N] [gc] [prefix Constant]
Peter Collingbourne96efdd62016-06-14 21:01:22 +0000784 [prologue Constant] [personality Constant] (!name !N)* { ... }
Sean Silvab084af42012-12-07 10:36:55 +0000785
Sean Silva706fba52015-08-06 22:56:24 +0000786The argument list is a comma separated sequence of arguments where each
787argument is of the following form:
Dan Liew2661dfc2014-08-20 15:06:30 +0000788
789Syntax::
790
791 <type> [parameter Attrs] [name]
792
793
Eli Benderskyfdc529a2013-06-07 19:40:08 +0000794.. _langref_aliases:
795
Sean Silvab084af42012-12-07 10:36:55 +0000796Aliases
797-------
798
Rafael Espindola64c1e182014-06-03 02:41:57 +0000799Aliases, unlike function or variables, don't create any new data. They
800are just a new symbol and metadata for an existing position.
801
802Aliases have a name and an aliasee that is either a global value or a
803constant expression.
804
Nico Rieck7157bb72014-01-14 15:22:47 +0000805Aliases may have an optional :ref:`linkage type <linkage>`, an optional
Sean Fertilec70d28b2017-10-26 15:00:26 +0000806:ref:`runtime preemption specifier <runtime_preemption_model>`, an optional
Rafael Espindola64c1e182014-06-03 02:41:57 +0000807:ref:`visibility style <visibility>`, an optional :ref:`DLL storage class
808<dllstorageclass>` and an optional :ref:`tls model <tls_model>`.
Sean Silvab084af42012-12-07 10:36:55 +0000809
810Syntax::
811
Sean Fertilec70d28b2017-10-26 15:00:26 +0000812 @<Name> = [Linkage] [PreemptionSpecifier] [Visibility] [DLLStorageClass] [ThreadLocal] [(unnamed_addr|local_unnamed_addr)] alias <AliaseeTy>, <AliaseeTy>* @<Aliasee>
Sean Silvab084af42012-12-07 10:36:55 +0000813
Rafael Espindola2fb5bc32014-03-13 23:18:37 +0000814The linkage must be one of ``private``, ``internal``, ``linkonce``, ``weak``,
Rafael Espindola716e7402013-11-01 17:09:14 +0000815``linkonce_odr``, ``weak_odr``, ``external``. Note that some system linkers
Rafael Espindola64c1e182014-06-03 02:41:57 +0000816might not correctly handle dropping a weak symbol that is aliased.
Rafael Espindola78527052013-10-06 15:10:43 +0000817
Eric Christopher1e61ffd2015-02-19 18:46:25 +0000818Aliases that are not ``unnamed_addr`` are guaranteed to have the same address as
Rafael Espindola42a4c9f2014-06-06 01:20:28 +0000819the aliasee expression. ``unnamed_addr`` ones are only guaranteed to point
820to the same content.
Rafael Espindolaf3336bc2014-03-12 20:15:49 +0000821
Peter Collingbourne96efdd62016-06-14 21:01:22 +0000822If the ``local_unnamed_addr`` attribute is given, the address is known to
823not be significant within the module.
824
Rafael Espindola64c1e182014-06-03 02:41:57 +0000825Since aliases are only a second name, some restrictions apply, of which
826some can only be checked when producing an object file:
Rafael Espindolaf3336bc2014-03-12 20:15:49 +0000827
Rafael Espindola64c1e182014-06-03 02:41:57 +0000828* The expression defining the aliasee must be computable at assembly
829 time. Since it is just a name, no relocations can be used.
830
831* No alias in the expression can be weak as the possibility of the
832 intermediate alias being overridden cannot be represented in an
833 object file.
834
835* No global value in the expression can be a declaration, since that
836 would require a relocation, which is not possible.
Rafael Espindola24a669d2014-03-27 15:26:56 +0000837
Dmitry Polukhina1feff72016-04-07 12:32:19 +0000838.. _langref_ifunc:
839
840IFuncs
841-------
842
843IFuncs, like as aliases, don't create any new data or func. They are just a new
844symbol that dynamic linker resolves at runtime by calling a resolver function.
845
846IFuncs have a name and a resolver that is a function called by dynamic linker
847that returns address of another function associated with the name.
848
849IFunc may have an optional :ref:`linkage type <linkage>` and an optional
850:ref:`visibility style <visibility>`.
851
852Syntax::
853
854 @<Name> = [Linkage] [Visibility] ifunc <IFuncTy>, <ResolverTy>* @<Resolver>
855
856
David Majnemerdad0a642014-06-27 18:19:56 +0000857.. _langref_comdats:
858
859Comdats
860-------
861
862Comdat IR provides access to COFF and ELF object file COMDAT functionality.
863
Sean Silvaa1190322015-08-06 22:56:48 +0000864Comdats have a name which represents the COMDAT key. All global objects that
David Majnemerdad0a642014-06-27 18:19:56 +0000865specify this key will only end up in the final object file if the linker chooses
Sean Silvaa1190322015-08-06 22:56:48 +0000866that key over some other key. Aliases are placed in the same COMDAT that their
David Majnemerdad0a642014-06-27 18:19:56 +0000867aliasee computes to, if any.
868
869Comdats have a selection kind to provide input on how the linker should
870choose between keys in two different object files.
871
872Syntax::
873
874 $<Name> = comdat SelectionKind
875
876The selection kind must be one of the following:
877
878``any``
879 The linker may choose any COMDAT key, the choice is arbitrary.
880``exactmatch``
881 The linker may choose any COMDAT key but the sections must contain the
882 same data.
883``largest``
884 The linker will choose the section containing the largest COMDAT key.
885``noduplicates``
886 The linker requires that only section with this COMDAT key exist.
887``samesize``
888 The linker may choose any COMDAT key but the sections must contain the
889 same amount of data.
890
Sam Cleggea7cace2018-01-09 23:43:14 +0000891Note that the Mach-O platform doesn't support COMDATs, and ELF and WebAssembly
892only support ``any`` as a selection kind.
David Majnemerdad0a642014-06-27 18:19:56 +0000893
894Here is an example of a COMDAT group where a function will only be selected if
895the COMDAT key's section is the largest:
896
Renato Golin124f2592016-07-20 12:16:38 +0000897.. code-block:: text
David Majnemerdad0a642014-06-27 18:19:56 +0000898
899 $foo = comdat largest
Rafael Espindola83a362c2015-01-06 22:55:16 +0000900 @foo = global i32 2, comdat($foo)
David Majnemerdad0a642014-06-27 18:19:56 +0000901
Rafael Espindola83a362c2015-01-06 22:55:16 +0000902 define void @bar() comdat($foo) {
David Majnemerdad0a642014-06-27 18:19:56 +0000903 ret void
904 }
905
Rafael Espindola83a362c2015-01-06 22:55:16 +0000906As a syntactic sugar the ``$name`` can be omitted if the name is the same as
907the global name:
908
Renato Golin124f2592016-07-20 12:16:38 +0000909.. code-block:: text
Rafael Espindola83a362c2015-01-06 22:55:16 +0000910
911 $foo = comdat any
912 @foo = global i32 2, comdat
913
914
David Majnemerdad0a642014-06-27 18:19:56 +0000915In a COFF object file, this will create a COMDAT section with selection kind
916``IMAGE_COMDAT_SELECT_LARGEST`` containing the contents of the ``@foo`` symbol
917and another COMDAT section with selection kind
918``IMAGE_COMDAT_SELECT_ASSOCIATIVE`` which is associated with the first COMDAT
Hans Wennborg0def0662014-09-10 17:05:08 +0000919section and contains the contents of the ``@bar`` symbol.
David Majnemerdad0a642014-06-27 18:19:56 +0000920
921There are some restrictions on the properties of the global object.
922It, or an alias to it, must have the same name as the COMDAT group when
923targeting COFF.
924The contents and size of this object may be used during link-time to determine
925which COMDAT groups get selected depending on the selection kind.
926Because the name of the object must match the name of the COMDAT group, the
927linkage of the global object must not be local; local symbols can get renamed
928if a collision occurs in the symbol table.
929
930The combined use of COMDATS and section attributes may yield surprising results.
931For example:
932
Renato Golin124f2592016-07-20 12:16:38 +0000933.. code-block:: text
David Majnemerdad0a642014-06-27 18:19:56 +0000934
935 $foo = comdat any
936 $bar = comdat any
Rafael Espindola83a362c2015-01-06 22:55:16 +0000937 @g1 = global i32 42, section "sec", comdat($foo)
938 @g2 = global i32 42, section "sec", comdat($bar)
David Majnemerdad0a642014-06-27 18:19:56 +0000939
940From the object file perspective, this requires the creation of two sections
Sean Silvaa1190322015-08-06 22:56:48 +0000941with the same name. This is necessary because both globals belong to different
David Majnemerdad0a642014-06-27 18:19:56 +0000942COMDAT groups and COMDATs, at the object file level, are represented by
943sections.
944
Peter Collingbourne1feef2e2015-06-30 19:10:31 +0000945Note that certain IR constructs like global variables and functions may
946create COMDATs in the object file in addition to any which are specified using
Sean Silvaa1190322015-08-06 22:56:48 +0000947COMDAT IR. This arises when the code generator is configured to emit globals
Peter Collingbourne1feef2e2015-06-30 19:10:31 +0000948in individual sections (e.g. when `-data-sections` or `-function-sections`
949is supplied to `llc`).
David Majnemerdad0a642014-06-27 18:19:56 +0000950
Sean Silvab084af42012-12-07 10:36:55 +0000951.. _namedmetadatastructure:
952
953Named Metadata
954--------------
955
956Named metadata is a collection of metadata. :ref:`Metadata
957nodes <metadata>` (but not metadata strings) are the only valid
958operands for a named metadata.
959
Filipe Cabecinhas62431b12015-06-02 21:25:08 +0000960#. Named metadata are represented as a string of characters with the
961 metadata prefix. The rules for metadata names are the same as for
962 identifiers, but quoted names are not allowed. ``"\xx"`` type escapes
963 are still valid, which allows any character to be part of a name.
964
Sean Silvab084af42012-12-07 10:36:55 +0000965Syntax::
966
967 ; Some unnamed metadata nodes, which are referenced by the named metadata.
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +0000968 !0 = !{!"zero"}
969 !1 = !{!"one"}
970 !2 = !{!"two"}
Sean Silvab084af42012-12-07 10:36:55 +0000971 ; A named metadata.
972 !name = !{!0, !1, !2}
973
974.. _paramattrs:
975
976Parameter Attributes
977--------------------
978
979The return type and each parameter of a function type may have a set of
980*parameter attributes* associated with them. Parameter attributes are
981used to communicate additional information about the result or
982parameters of a function. Parameter attributes are considered to be part
983of the function, not of the function type, so functions with different
984parameter attributes can have the same function type.
985
986Parameter attributes are simple keywords that follow the type specified.
987If multiple parameter attributes are needed, they are space separated.
988For example:
989
990.. code-block:: llvm
991
992 declare i32 @printf(i8* noalias nocapture, ...)
993 declare i32 @atoi(i8 zeroext)
994 declare signext i8 @returns_signed_char()
995
996Note that any attributes for the function result (``nounwind``,
997``readonly``) come immediately after the argument list.
998
999Currently, only the following parameter attributes are defined:
1000
1001``zeroext``
1002 This indicates to the code generator that the parameter or return
1003 value should be zero-extended to the extent required by the target's
Hans Wennborg850ec6c2016-02-08 19:34:30 +00001004 ABI by the caller (for a parameter) or the callee (for a return value).
Sean Silvab084af42012-12-07 10:36:55 +00001005``signext``
1006 This indicates to the code generator that the parameter or return
1007 value should be sign-extended to the extent required by the target's
1008 ABI (which is usually 32-bits) by the caller (for a parameter) or
1009 the callee (for a return value).
1010``inreg``
1011 This indicates that this parameter or return value should be treated
Sean Silva706fba52015-08-06 22:56:24 +00001012 in a special target-dependent fashion while emitting code for
Sean Silvab084af42012-12-07 10:36:55 +00001013 a function call or return (usually, by putting it in a register as
1014 opposed to memory, though some targets use it to distinguish between
1015 two different kinds of registers). Use of this attribute is
1016 target-specific.
Tim Northoverb7141202019-05-30 18:48:23 +00001017``byval`` or ``byval(<ty>)``
Sean Silvab084af42012-12-07 10:36:55 +00001018 This indicates that the pointer parameter should really be passed by
1019 value to the function. The attribute implies that a hidden copy of
1020 the pointee is made between the caller and the callee, so the callee
1021 is unable to modify the value in the caller. This attribute is only
1022 valid on LLVM pointer arguments. It is generally used to pass
1023 structs and arrays by value, but is also valid on pointers to
1024 scalars. The copy is considered to belong to the caller not the
1025 callee (for example, ``readonly`` functions should not write to
1026 ``byval`` parameters). This is not a valid attribute for return
1027 values.
1028
Tim Northoverb7141202019-05-30 18:48:23 +00001029 The byval attribute also supports an optional type argument, which must be
1030 the same as the pointee type of the argument.
1031
Sean Silvab084af42012-12-07 10:36:55 +00001032 The byval attribute also supports specifying an alignment with the
1033 align attribute. It indicates the alignment of the stack slot to
1034 form and the known alignment of the pointer specified to the call
1035 site. If the alignment is not specified, then the code generator
1036 makes a target-specific assumption.
1037
Reid Klecknera534a382013-12-19 02:14:12 +00001038.. _attr_inalloca:
1039
1040``inalloca``
1041
Reid Kleckner60d3a832014-01-16 22:59:24 +00001042 The ``inalloca`` argument attribute allows the caller to take the
Sean Silvaa1190322015-08-06 22:56:48 +00001043 address of outgoing stack arguments. An ``inalloca`` argument must
Reid Kleckner436c42e2014-01-17 23:58:17 +00001044 be a pointer to stack memory produced by an ``alloca`` instruction.
1045 The alloca, or argument allocation, must also be tagged with the
Sean Silvaa1190322015-08-06 22:56:48 +00001046 inalloca keyword. Only the last argument may have the ``inalloca``
Reid Kleckner436c42e2014-01-17 23:58:17 +00001047 attribute, and that argument is guaranteed to be passed in memory.
Reid Klecknera534a382013-12-19 02:14:12 +00001048
Reid Kleckner436c42e2014-01-17 23:58:17 +00001049 An argument allocation may be used by a call at most once because
Sean Silvaa1190322015-08-06 22:56:48 +00001050 the call may deallocate it. The ``inalloca`` attribute cannot be
Reid Kleckner436c42e2014-01-17 23:58:17 +00001051 used in conjunction with other attributes that affect argument
Sean Silvaa1190322015-08-06 22:56:48 +00001052 storage, like ``inreg``, ``nest``, ``sret``, or ``byval``. The
Reid Klecknerf5b76512014-01-31 23:50:57 +00001053 ``inalloca`` attribute also disables LLVM's implicit lowering of
1054 large aggregate return values, which means that frontend authors
1055 must lower them with ``sret`` pointers.
Reid Klecknera534a382013-12-19 02:14:12 +00001056
Reid Kleckner60d3a832014-01-16 22:59:24 +00001057 When the call site is reached, the argument allocation must have
1058 been the most recent stack allocation that is still live, or the
Eli Friedman0f522bd2018-07-25 18:26:38 +00001059 behavior is undefined. It is possible to allocate additional stack
Reid Kleckner60d3a832014-01-16 22:59:24 +00001060 space after an argument allocation and before its call site, but it
1061 must be cleared off with :ref:`llvm.stackrestore
1062 <int_stackrestore>`.
Reid Klecknera534a382013-12-19 02:14:12 +00001063
1064 See :doc:`InAlloca` for more information on how to use this
1065 attribute.
1066
Sean Silvab084af42012-12-07 10:36:55 +00001067``sret``
1068 This indicates that the pointer parameter specifies the address of a
1069 structure that is the return value of the function in the source
1070 program. This pointer must be guaranteed by the caller to be valid:
Reid Kleckner1361c0c2016-09-08 15:45:27 +00001071 loads and stores to the structure may be assumed by the callee not
1072 to trap and to be properly aligned. This is not a valid attribute
1073 for return values.
Sean Silva1703e702014-04-08 21:06:22 +00001074
Daniel Neilson1e687242018-01-19 17:13:12 +00001075.. _attr_align:
Elena Demikhovsky945b7e52018-02-14 06:58:08 +00001076
Hal Finkelccc70902014-07-22 16:58:55 +00001077``align <n>``
1078 This indicates that the pointer value may be assumed by the optimizer to
Kristina Brooks76eb4b02019-02-26 18:53:13 +00001079 have the specified alignment. If the pointer value does not have the
1080 specified alignment, behavior is undefined.
Hal Finkelccc70902014-07-22 16:58:55 +00001081
1082 Note that this attribute has additional semantics when combined with the
Kristina Brooks76eb4b02019-02-26 18:53:13 +00001083 ``byval`` attribute, which are documented there.
Hal Finkelccc70902014-07-22 16:58:55 +00001084
Sean Silva1703e702014-04-08 21:06:22 +00001085.. _noalias:
1086
Sean Silvab084af42012-12-07 10:36:55 +00001087``noalias``
Hal Finkel12d36302014-11-21 02:22:46 +00001088 This indicates that objects accessed via pointer values
1089 :ref:`based <pointeraliasing>` on the argument or return value are not also
1090 accessed, during the execution of the function, via pointer values not
1091 *based* on the argument or return value. The attribute on a return value
1092 also has additional semantics described below. The caller shares the
1093 responsibility with the callee for ensuring that these requirements are met.
1094 For further details, please see the discussion of the NoAlias response in
1095 :ref:`alias analysis <Must, May, or No>`.
Sean Silvab084af42012-12-07 10:36:55 +00001096
1097 Note that this definition of ``noalias`` is intentionally similar
Hal Finkel12d36302014-11-21 02:22:46 +00001098 to the definition of ``restrict`` in C99 for function arguments.
Sean Silvab084af42012-12-07 10:36:55 +00001099
1100 For function return values, C99's ``restrict`` is not meaningful,
Hal Finkel12d36302014-11-21 02:22:46 +00001101 while LLVM's ``noalias`` is. Furthermore, the semantics of the ``noalias``
1102 attribute on return values are stronger than the semantics of the attribute
1103 when used on function arguments. On function return values, the ``noalias``
1104 attribute indicates that the function acts like a system memory allocation
1105 function, returning a pointer to allocated storage disjoint from the
1106 storage for any other object accessible to the caller.
1107
Sean Silvab084af42012-12-07 10:36:55 +00001108``nocapture``
1109 This indicates that the callee does not make any copies of the
1110 pointer that outlive the callee itself. This is not a valid
David Majnemer7f324202016-05-26 17:36:22 +00001111 attribute for return values. Addresses used in volatile operations
1112 are considered to be captured.
Sean Silvab084af42012-12-07 10:36:55 +00001113
1114.. _nest:
1115
1116``nest``
1117 This indicates that the pointer parameter can be excised using the
1118 :ref:`trampoline intrinsics <int_trampoline>`. This is not a valid
Stephen Linb8bd2322013-04-20 05:14:40 +00001119 attribute for return values and can only be applied to one parameter.
1120
1121``returned``
Stephen Linfec5b0b2013-06-20 21:55:10 +00001122 This indicates that the function always returns the argument as its return
Hal Finkel3b66caa2016-07-10 21:52:39 +00001123 value. This is a hint to the optimizer and code generator used when
1124 generating the caller, allowing value propagation, tail call optimization,
1125 and omission of register saves and restores in some cases; it is not
1126 checked or enforced when generating the callee. The parameter and the
1127 function return type must be valid operands for the
1128 :ref:`bitcast instruction <i_bitcast>`. This is not a valid attribute for
1129 return values and can only be applied to one parameter.
Sean Silvab084af42012-12-07 10:36:55 +00001130
Nick Lewyckyd52b1522014-05-20 01:23:40 +00001131``nonnull``
1132 This indicates that the parameter or return pointer is not null. This
1133 attribute may only be applied to pointer typed parameters. This is not
Eli Friedman0f522bd2018-07-25 18:26:38 +00001134 checked or enforced by LLVM; if the parameter or return pointer is null,
1135 the behavior is undefined.
Nick Lewyckyd52b1522014-05-20 01:23:40 +00001136
Hal Finkelb0407ba2014-07-18 15:51:28 +00001137``dereferenceable(<n>)``
1138 This indicates that the parameter or return pointer is dereferenceable. This
1139 attribute may only be applied to pointer typed parameters. A pointer that
1140 is dereferenceable can be loaded from speculatively without a risk of
1141 trapping. The number of bytes known to be dereferenceable must be provided
1142 in parentheses. It is legal for the number of bytes to be less than the
1143 size of the pointee type. The ``nonnull`` attribute does not imply
1144 dereferenceability (consider a pointer to one element past the end of an
1145 array), however ``dereferenceable(<n>)`` does imply ``nonnull`` in
1146 ``addrspace(0)`` (which is the default address space).
1147
Sanjoy Das31ea6d12015-04-16 20:29:50 +00001148``dereferenceable_or_null(<n>)``
1149 This indicates that the parameter or return value isn't both
1150 non-null and non-dereferenceable (up to ``<n>`` bytes) at the same
Sean Silvaa1190322015-08-06 22:56:48 +00001151 time. All non-null pointers tagged with
Sanjoy Das31ea6d12015-04-16 20:29:50 +00001152 ``dereferenceable_or_null(<n>)`` are ``dereferenceable(<n>)``.
1153 For address space 0 ``dereferenceable_or_null(<n>)`` implies that
1154 a pointer is exactly one of ``dereferenceable(<n>)`` or ``null``,
1155 and in other address spaces ``dereferenceable_or_null(<n>)``
1156 implies that a pointer is at least one of ``dereferenceable(<n>)``
1157 or ``null`` (i.e. it may be both ``null`` and
Sean Silvaa1190322015-08-06 22:56:48 +00001158 ``dereferenceable(<n>)``). This attribute may only be applied to
Sanjoy Das31ea6d12015-04-16 20:29:50 +00001159 pointer typed parameters.
1160
Manman Renf46262e2016-03-29 17:37:21 +00001161``swiftself``
1162 This indicates that the parameter is the self/context parameter. This is not
1163 a valid attribute for return values and can only be applied to one
1164 parameter.
1165
Manman Ren9bfd0d02016-04-01 21:41:15 +00001166``swifterror``
1167 This attribute is motivated to model and optimize Swift error handling. It
1168 can be applied to a parameter with pointer to pointer type or a
1169 pointer-sized alloca. At the call site, the actual argument that corresponds
Arnold Schwaighofer6c57f4f2016-09-10 19:42:53 +00001170 to a ``swifterror`` parameter has to come from a ``swifterror`` alloca or
1171 the ``swifterror`` parameter of the caller. A ``swifterror`` value (either
1172 the parameter or the alloca) can only be loaded and stored from, or used as
1173 a ``swifterror`` argument. This is not a valid attribute for return values
1174 and can only be applied to one parameter.
Manman Ren9bfd0d02016-04-01 21:41:15 +00001175
1176 These constraints allow the calling convention to optimize access to
1177 ``swifterror`` variables by associating them with a specific register at
1178 call boundaries rather than placing them in memory. Since this does change
1179 the calling convention, a function which uses the ``swifterror`` attribute
1180 on a parameter is not ABI-compatible with one which does not.
1181
1182 These constraints also allow LLVM to assume that a ``swifterror`` argument
1183 does not alias any other memory visible within a function and that a
1184 ``swifterror`` alloca passed as an argument does not escape.
1185
Matt Arsenaultcaf13162019-03-12 21:02:54 +00001186``immarg``
1187 This indicates the parameter is required to be an immediate
1188 value. This must be a trivial immediate integer or floating-point
1189 constant. Undef or constant expressions are not valid. This is
1190 only valid on intrinsic declarations and cannot be applied to a
1191 call site or arbitrary function.
1192
Sean Silvab084af42012-12-07 10:36:55 +00001193.. _gc:
1194
Philip Reamesf80bbff2015-02-25 23:45:20 +00001195Garbage Collector Strategy Names
1196--------------------------------
Sean Silvab084af42012-12-07 10:36:55 +00001197
Philip Reamesf80bbff2015-02-25 23:45:20 +00001198Each function may specify a garbage collector strategy name, which is simply a
Sean Silvab084af42012-12-07 10:36:55 +00001199string:
1200
1201.. code-block:: llvm
1202
1203 define void @f() gc "name" { ... }
1204
Mehdi Amini4a121fa2015-03-14 22:04:06 +00001205The supported values of *name* includes those :ref:`built in to LLVM
Sean Silvaa1190322015-08-06 22:56:48 +00001206<builtin-gc-strategies>` and any provided by loaded plugins. Specifying a GC
Mehdi Amini4a121fa2015-03-14 22:04:06 +00001207strategy will cause the compiler to alter its output in order to support the
Sean Silvaa1190322015-08-06 22:56:48 +00001208named garbage collection algorithm. Note that LLVM itself does not contain a
Philip Reamesf80bbff2015-02-25 23:45:20 +00001209garbage collector, this functionality is restricted to generating machine code
Mehdi Amini4a121fa2015-03-14 22:04:06 +00001210which can interoperate with a collector provided externally.
Sean Silvab084af42012-12-07 10:36:55 +00001211
Peter Collingbourne3fa50f92013-09-16 01:08:15 +00001212.. _prefixdata:
1213
1214Prefix Data
1215-----------
1216
Peter Collingbourne51d2de72014-12-03 02:08:38 +00001217Prefix data is data associated with a function which the code
1218generator will emit immediately before the function's entrypoint.
1219The purpose of this feature is to allow frontends to associate
1220language-specific runtime metadata with specific functions and make it
1221available through the function pointer while still allowing the
1222function pointer to be called.
Peter Collingbourne3fa50f92013-09-16 01:08:15 +00001223
Peter Collingbourne51d2de72014-12-03 02:08:38 +00001224To access the data for a given function, a program may bitcast the
1225function pointer to a pointer to the constant's type and dereference
Sean Silvaa1190322015-08-06 22:56:48 +00001226index -1. This implies that the IR symbol points just past the end of
Peter Collingbourne51d2de72014-12-03 02:08:38 +00001227the prefix data. For instance, take the example of a function annotated
1228with a single ``i32``,
1229
1230.. code-block:: llvm
1231
1232 define void @f() prefix i32 123 { ... }
1233
1234The prefix data can be referenced as,
1235
1236.. code-block:: llvm
1237
David Blaikie16a97eb2015-03-04 22:02:58 +00001238 %0 = bitcast void* () @f to i32*
1239 %a = getelementptr inbounds i32, i32* %0, i32 -1
David Blaikiec7aabbb2015-03-04 22:06:14 +00001240 %b = load i32, i32* %a
Peter Collingbourne51d2de72014-12-03 02:08:38 +00001241
1242Prefix data is laid out as if it were an initializer for a global variable
Sean Silvaa1190322015-08-06 22:56:48 +00001243of the prefix data's type. The function will be placed such that the
Peter Collingbourne51d2de72014-12-03 02:08:38 +00001244beginning of the prefix data is aligned. This means that if the size
1245of the prefix data is not a multiple of the alignment size, the
1246function's entrypoint will not be aligned. If alignment of the
1247function's entrypoint is desired, padding must be added to the prefix
1248data.
1249
Sean Silvaa1190322015-08-06 22:56:48 +00001250A function may have prefix data but no body. This has similar semantics
Peter Collingbourne51d2de72014-12-03 02:08:38 +00001251to the ``available_externally`` linkage in that the data may be used by the
1252optimizers but will not be emitted in the object file.
1253
1254.. _prologuedata:
1255
1256Prologue Data
1257-------------
1258
1259The ``prologue`` attribute allows arbitrary code (encoded as bytes) to
1260be inserted prior to the function body. This can be used for enabling
1261function hot-patching and instrumentation.
1262
1263To maintain the semantics of ordinary function calls, the prologue data must
Sean Silvaa1190322015-08-06 22:56:48 +00001264have a particular format. Specifically, it must begin with a sequence of
Peter Collingbourne3fa50f92013-09-16 01:08:15 +00001265bytes which decode to a sequence of machine instructions, valid for the
1266module's target, which transfer control to the point immediately succeeding
Sean Silvaa1190322015-08-06 22:56:48 +00001267the prologue data, without performing any other visible action. This allows
Peter Collingbourne3fa50f92013-09-16 01:08:15 +00001268the inliner and other passes to reason about the semantics of the function
Sean Silvaa1190322015-08-06 22:56:48 +00001269definition without needing to reason about the prologue data. Obviously this
Peter Collingbourne51d2de72014-12-03 02:08:38 +00001270makes the format of the prologue data highly target dependent.
Peter Collingbourne3fa50f92013-09-16 01:08:15 +00001271
Peter Collingbourne51d2de72014-12-03 02:08:38 +00001272A trivial example of valid prologue data for the x86 architecture is ``i8 144``,
Peter Collingbourne3fa50f92013-09-16 01:08:15 +00001273which encodes the ``nop`` instruction:
1274
Renato Golin124f2592016-07-20 12:16:38 +00001275.. code-block:: text
Peter Collingbourne3fa50f92013-09-16 01:08:15 +00001276
Peter Collingbourne51d2de72014-12-03 02:08:38 +00001277 define void @f() prologue i8 144 { ... }
Peter Collingbourne3fa50f92013-09-16 01:08:15 +00001278
Peter Collingbourne51d2de72014-12-03 02:08:38 +00001279Generally prologue data can be formed by encoding a relative branch instruction
1280which skips the metadata, as in this example of valid prologue data for the
Peter Collingbourne3fa50f92013-09-16 01:08:15 +00001281x86_64 architecture, where the first two bytes encode ``jmp .+10``:
1282
Renato Golin124f2592016-07-20 12:16:38 +00001283.. code-block:: text
Peter Collingbourne3fa50f92013-09-16 01:08:15 +00001284
1285 %0 = type <{ i8, i8, i8* }>
1286
Peter Collingbourne51d2de72014-12-03 02:08:38 +00001287 define void @f() prologue %0 <{ i8 235, i8 8, i8* @md}> { ... }
Peter Collingbourne3fa50f92013-09-16 01:08:15 +00001288
Sean Silvaa1190322015-08-06 22:56:48 +00001289A function may have prologue data but no body. This has similar semantics
Peter Collingbourne3fa50f92013-09-16 01:08:15 +00001290to the ``available_externally`` linkage in that the data may be used by the
1291optimizers but will not be emitted in the object file.
1292
David Majnemer7fddecc2015-06-17 20:52:32 +00001293.. _personalityfn:
1294
1295Personality Function
David Majnemerc5ad8a92015-06-17 21:21:16 +00001296--------------------
David Majnemer7fddecc2015-06-17 20:52:32 +00001297
1298The ``personality`` attribute permits functions to specify what function
1299to use for exception handling.
1300
Bill Wendling63b88192013-02-06 06:52:58 +00001301.. _attrgrp:
1302
1303Attribute Groups
1304----------------
1305
1306Attribute groups are groups of attributes that are referenced by objects within
1307the IR. They are important for keeping ``.ll`` files readable, because a lot of
1308functions will use the same set of attributes. In the degenerative case of a
1309``.ll`` file that corresponds to a single ``.c`` file, the single attribute
1310group will capture the important command line flags used to build that file.
1311
1312An attribute group is a module-level object. To use an attribute group, an
1313object references the attribute group's ID (e.g. ``#37``). An object may refer
1314to more than one attribute group. In that situation, the attributes from the
1315different groups are merged.
1316
1317Here is an example of attribute groups for a function that should always be
1318inlined, has a stack alignment of 4, and which shouldn't use SSE instructions:
1319
1320.. code-block:: llvm
1321
1322 ; Target-independent attributes:
Eli Bendersky97ad9242013-04-18 16:11:44 +00001323 attributes #0 = { alwaysinline alignstack=4 }
Bill Wendling63b88192013-02-06 06:52:58 +00001324
1325 ; Target-dependent attributes:
Eli Bendersky97ad9242013-04-18 16:11:44 +00001326 attributes #1 = { "no-sse" }
Bill Wendling63b88192013-02-06 06:52:58 +00001327
1328 ; Function @f has attributes: alwaysinline, alignstack=4, and "no-sse".
1329 define void @f() #0 #1 { ... }
1330
Sean Silvab084af42012-12-07 10:36:55 +00001331.. _fnattrs:
1332
1333Function Attributes
1334-------------------
1335
1336Function attributes are set to communicate additional information about
1337a function. Function attributes are considered to be part of the
1338function, not of the function type, so functions with different function
1339attributes can have the same function type.
1340
1341Function attributes are simple keywords that follow the type specified.
1342If multiple attributes are needed, they are space separated. For
1343example:
1344
1345.. code-block:: llvm
1346
1347 define void @f() noinline { ... }
1348 define void @f() alwaysinline { ... }
1349 define void @f() alwaysinline optsize { ... }
1350 define void @f() optsize { ... }
1351
Sean Silvab084af42012-12-07 10:36:55 +00001352``alignstack(<n>)``
1353 This attribute indicates that, when emitting the prologue and
1354 epilogue, the backend should forcibly align the stack pointer.
1355 Specify the desired alignment, which must be a power of two, in
1356 parentheses.
George Burgess IV278199f2016-04-12 01:05:35 +00001357``allocsize(<EltSizeParam>[, <NumEltsParam>])``
1358 This attribute indicates that the annotated function will always return at
1359 least a given number of bytes (or null). Its arguments are zero-indexed
1360 parameter numbers; if one argument is provided, then it's assumed that at
1361 least ``CallSite.Args[EltSizeParam]`` bytes will be available at the
1362 returned pointer. If two are provided, then it's assumed that
1363 ``CallSite.Args[EltSizeParam] * CallSite.Args[NumEltsParam]`` bytes are
1364 available. The referenced parameters must be integer types. No assumptions
1365 are made about the contents of the returned block of memory.
Sean Silvab084af42012-12-07 10:36:55 +00001366``alwaysinline``
1367 This attribute indicates that the inliner should attempt to inline
1368 this function into callers whenever possible, ignoring any active
1369 inlining size threshold for this caller.
Michael Gottesman41748d72013-06-27 00:25:01 +00001370``builtin``
1371 This indicates that the callee function at a call site should be
1372 recognized as a built-in function, even though the function's declaration
Michael Gottesman3a6a9672013-07-02 21:32:56 +00001373 uses the ``nobuiltin`` attribute. This is only valid at call sites for
Richard Smith32dbdf62014-07-31 04:25:36 +00001374 direct calls to functions that are declared with the ``nobuiltin``
Michael Gottesman41748d72013-06-27 00:25:01 +00001375 attribute.
Michael Gottesman296adb82013-06-27 22:48:08 +00001376``cold``
1377 This attribute indicates that this function is rarely called. When
1378 computing edge weights, basic blocks post-dominated by a cold
1379 function call are also considered to be cold; and, thus, given low
1380 weight.
Owen Anderson85fa7d52015-05-26 23:48:40 +00001381``convergent``
Justin Lebard5fb6952016-02-09 23:03:17 +00001382 In some parallel execution models, there exist operations that cannot be
1383 made control-dependent on any additional values. We call such operations
Justin Lebar58535b12016-02-17 17:46:41 +00001384 ``convergent``, and mark them with this attribute.
Justin Lebard5fb6952016-02-09 23:03:17 +00001385
Justin Lebar58535b12016-02-17 17:46:41 +00001386 The ``convergent`` attribute may appear on functions or call/invoke
1387 instructions. When it appears on a function, it indicates that calls to
1388 this function should not be made control-dependent on additional values.
Justin Bognera4635372016-07-06 20:02:45 +00001389 For example, the intrinsic ``llvm.nvvm.barrier0`` is ``convergent``, so
Justin Lebard5fb6952016-02-09 23:03:17 +00001390 calls to this intrinsic cannot be made control-dependent on additional
Justin Lebar58535b12016-02-17 17:46:41 +00001391 values.
Justin Lebard5fb6952016-02-09 23:03:17 +00001392
Justin Lebar58535b12016-02-17 17:46:41 +00001393 When it appears on a call/invoke, the ``convergent`` attribute indicates
1394 that we should treat the call as though we're calling a convergent
1395 function. This is particularly useful on indirect calls; without this we
1396 may treat such calls as though the target is non-convergent.
1397
1398 The optimizer may remove the ``convergent`` attribute on functions when it
1399 can prove that the function does not execute any convergent operations.
1400 Similarly, the optimizer may remove ``convergent`` on calls/invokes when it
1401 can prove that the call/invoke cannot call a convergent function.
Vaivaswatha Nagarajfb3f4902015-12-16 16:16:19 +00001402``inaccessiblememonly``
1403 This attribute indicates that the function may only access memory that
1404 is not accessible by the module being compiled. This is a weaker form
Eli Friedman0f522bd2018-07-25 18:26:38 +00001405 of ``readnone``. If the function reads or writes other memory, the
1406 behavior is undefined.
Vaivaswatha Nagarajfb3f4902015-12-16 16:16:19 +00001407``inaccessiblemem_or_argmemonly``
1408 This attribute indicates that the function may only access memory that is
1409 either not accessible by the module being compiled, or is pointed to
Eli Friedman0f522bd2018-07-25 18:26:38 +00001410 by its pointer arguments. This is a weaker form of ``argmemonly``. If the
1411 function reads or writes other memory, the behavior is undefined.
Sean Silvab084af42012-12-07 10:36:55 +00001412``inlinehint``
1413 This attribute indicates that the source code contained a hint that
1414 inlining this function is desirable (such as the "inline" keyword in
1415 C/C++). It is just a hint; it imposes no requirements on the
1416 inliner.
Tom Roeder44cb65f2014-06-05 19:29:43 +00001417``jumptable``
1418 This attribute indicates that the function should be added to a
1419 jump-instruction table at code-generation time, and that all address-taken
1420 references to this function should be replaced with a reference to the
1421 appropriate jump-instruction-table function pointer. Note that this creates
1422 a new pointer for the original function, which means that code that depends
1423 on function-pointer identity can break. So, any function annotated with
1424 ``jumptable`` must also be ``unnamed_addr``.
Andrea Di Biagio9b5d23b2013-08-09 18:42:18 +00001425``minsize``
1426 This attribute suggests that optimization passes and code generator
1427 passes make choices that keep the code size of this function as small
Andrew Trickd4d1d9c2013-10-31 17:18:07 +00001428 as possible and perform optimizations that may sacrifice runtime
Andrea Di Biagio9b5d23b2013-08-09 18:42:18 +00001429 performance in order to minimize the size of the generated code.
Sean Silvab084af42012-12-07 10:36:55 +00001430``naked``
1431 This attribute disables prologue / epilogue emission for the
1432 function. This can have very system-specific consequences.
Sumanth Gundapaneni6af104e2017-07-28 22:26:22 +00001433``no-jump-tables``
1434 When this attribute is set to true, the jump tables and lookup tables that
1435 can be generated from a switch case lowering are disabled.
Eli Bendersky97ad9242013-04-18 16:11:44 +00001436``nobuiltin``
Michael Gottesman41748d72013-06-27 00:25:01 +00001437 This indicates that the callee function at a call site is not recognized as
1438 a built-in function. LLVM will retain the original call and not replace it
1439 with equivalent code based on the semantics of the built-in function, unless
1440 the call site uses the ``builtin`` attribute. This is valid at call sites
1441 and on function declarations and definitions.
Bill Wendlingbf902f12013-02-06 06:22:58 +00001442``noduplicate``
1443 This attribute indicates that calls to the function cannot be
1444 duplicated. A call to a ``noduplicate`` function may be moved
1445 within its parent function, but may not be duplicated within
1446 its parent function.
1447
1448 A function containing a ``noduplicate`` call may still
1449 be an inlining candidate, provided that the call is not
1450 duplicated by inlining. That implies that the function has
1451 internal linkage and only has one call site, so the original
1452 call is dead after inlining.
Sean Silvab084af42012-12-07 10:36:55 +00001453``noimplicitfloat``
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00001454 This attributes disables implicit floating-point instructions.
Sean Silvab084af42012-12-07 10:36:55 +00001455``noinline``
1456 This attribute indicates that the inliner should never inline this
1457 function in any situation. This attribute may not be used together
1458 with the ``alwaysinline`` attribute.
Sean Silva1cbbcf12013-08-06 19:34:37 +00001459``nonlazybind``
1460 This attribute suppresses lazy symbol binding for the function. This
1461 may make calls to the function faster, at the cost of extra program
1462 startup time if the function is not called during program startup.
Sean Silvab084af42012-12-07 10:36:55 +00001463``noredzone``
1464 This attribute indicates that the code generator should not use a
1465 red zone, even if the target-specific ABI normally permits it.
Kristina Brooks312fcc12018-10-18 03:14:37 +00001466``indirect-tls-seg-refs``
1467 This attribute indicates that the code generator should not use
1468 direct TLS access through segment registers, even if the
1469 target-specific ABI normally permits it.
Sean Silvab084af42012-12-07 10:36:55 +00001470``noreturn``
1471 This function attribute indicates that the function never returns
1472 normally. This produces undefined behavior at runtime if the
1473 function ever does dynamically return.
James Molloye6f87ca2015-11-06 10:32:53 +00001474``norecurse``
1475 This function attribute indicates that the function does not call itself
1476 either directly or indirectly down any possible call path. This produces
1477 undefined behavior at runtime if the function ever does recurse.
Sean Silvab084af42012-12-07 10:36:55 +00001478``nounwind``
Reid Kleckner96d01132015-02-11 01:23:16 +00001479 This function attribute indicates that the function never raises an
1480 exception. If the function does raise an exception, its runtime
1481 behavior is undefined. However, functions marked nounwind may still
1482 trap or generate asynchronous exceptions. Exception handling schemes
1483 that are recognized by LLVM to handle asynchronous exceptions, such
1484 as SEH, will still provide their implementation defined semantics.
Manoj Gupta77eeac32018-07-09 22:27:23 +00001485``"null-pointer-is-valid"``
1486 If ``"null-pointer-is-valid"`` is set to ``"true"``, then ``null`` address
1487 in address-space 0 is considered to be a valid address for memory loads and
1488 stores. Any analysis or optimization should not treat dereferencing a
1489 pointer to ``null`` as undefined behavior in this function.
1490 Note: Comparing address of a global variable to ``null`` may still
1491 evaluate to false because of a limitation in querying this attribute inside
1492 constant expressions.
Matt Morehouse31819412018-03-22 19:50:10 +00001493``optforfuzzing``
1494 This attribute indicates that this function should be optimized
1495 for maximum fuzzing signal.
Andrea Di Biagio377496b2013-08-23 11:53:55 +00001496``optnone``
Paul Robinsona2550a62015-11-30 21:56:16 +00001497 This function attribute indicates that most optimization passes will skip
1498 this function, with the exception of interprocedural optimization passes.
1499 Code generation defaults to the "fast" instruction selector.
Andrea Di Biagio377496b2013-08-23 11:53:55 +00001500 This attribute cannot be used together with the ``alwaysinline``
1501 attribute; this attribute is also incompatible
1502 with the ``minsize`` attribute and the ``optsize`` attribute.
Andrew Trickd4d1d9c2013-10-31 17:18:07 +00001503
Paul Robinsondcbe35b2013-11-18 21:44:03 +00001504 This attribute requires the ``noinline`` attribute to be specified on
1505 the function as well, so the function is never inlined into any caller.
Andrea Di Biagio377496b2013-08-23 11:53:55 +00001506 Only functions with the ``alwaysinline`` attribute are valid
Paul Robinsondcbe35b2013-11-18 21:44:03 +00001507 candidates for inlining into the body of this function.
Sean Silvab084af42012-12-07 10:36:55 +00001508``optsize``
1509 This attribute suggests that optimization passes and code generator
1510 passes make choices that keep the code size of this function low,
Andrea Di Biagio9b5d23b2013-08-09 18:42:18 +00001511 and otherwise do optimizations specifically to reduce code size as
1512 long as they do not significantly impact runtime performance.
Sanjoy Dasc0441c22016-04-19 05:24:47 +00001513``"patchable-function"``
1514 This attribute tells the code generator that the code
1515 generated for this function needs to follow certain conventions that
1516 make it possible for a runtime function to patch over it later.
1517 The exact effect of this attribute depends on its string value,
Charles Davise9c32c72016-08-08 21:20:15 +00001518 for which there currently is one legal possibility:
Sanjoy Dasc0441c22016-04-19 05:24:47 +00001519
1520 * ``"prologue-short-redirect"`` - This style of patchable
1521 function is intended to support patching a function prologue to
1522 redirect control away from the function in a thread safe
1523 manner. It guarantees that the first instruction of the
1524 function will be large enough to accommodate a short jump
1525 instruction, and will be sufficiently aligned to allow being
1526 fully changed via an atomic compare-and-swap instruction.
1527 While the first requirement can be satisfied by inserting large
1528 enough NOP, LLVM can and will try to re-purpose an existing
1529 instruction (i.e. one that would have to be emitted anyway) as
1530 the patchable instruction larger than a short jump.
1531
1532 ``"prologue-short-redirect"`` is currently only supported on
1533 x86-64.
1534
1535 This attribute by itself does not imply restrictions on
1536 inter-procedural optimizations. All of the semantic effects the
1537 patching may have to be separately conveyed via the linkage type.
whitequarked54b4a2017-06-21 18:46:50 +00001538``"probe-stack"``
1539 This attribute indicates that the function will trigger a guard region
1540 in the end of the stack. It ensures that accesses to the stack must be
1541 no further apart than the size of the guard region to a previous
1542 access of the stack. It takes one required string value, the name of
1543 the stack probing function that will be called.
1544
1545 If a function that has a ``"probe-stack"`` attribute is inlined into
1546 a function with another ``"probe-stack"`` attribute, the resulting
1547 function has the ``"probe-stack"`` attribute of the caller. If a
1548 function that has a ``"probe-stack"`` attribute is inlined into a
1549 function that has no ``"probe-stack"`` attribute at all, the resulting
1550 function has the ``"probe-stack"`` attribute of the callee.
Sean Silvab084af42012-12-07 10:36:55 +00001551``readnone``
Nick Lewyckyc2ec0722013-07-06 00:29:58 +00001552 On a function, this attribute indicates that the function computes its
1553 result (or decides to unwind an exception) based strictly on its arguments,
Sean Silvab084af42012-12-07 10:36:55 +00001554 without dereferencing any pointer arguments or otherwise accessing
1555 any mutable state (e.g. memory, control registers, etc) visible to
1556 caller functions. It does not write through any pointer arguments
1557 (including ``byval`` arguments) and never changes any state visible
Sanjoy Das5be2e842017-02-13 23:19:07 +00001558 to callers. This means while it cannot unwind exceptions by calling
1559 the ``C++`` exception throwing methods (since they write to memory), there may
1560 be non-``C++`` mechanisms that throw exceptions without writing to LLVM
1561 visible memory.
Andrew Trickd4d1d9c2013-10-31 17:18:07 +00001562
Nick Lewyckyc2ec0722013-07-06 00:29:58 +00001563 On an argument, this attribute indicates that the function does not
1564 dereference that pointer argument, even though it may read or write the
Nick Lewyckyefe31f22013-07-06 01:04:47 +00001565 memory that the pointer points to if accessed through other pointers.
Eli Friedman0f522bd2018-07-25 18:26:38 +00001566
1567 If a readnone function reads or writes memory visible to the program, or
1568 has other side-effects, the behavior is undefined. If a function reads from
1569 or writes to a readnone pointer argument, the behavior is undefined.
Sean Silvab084af42012-12-07 10:36:55 +00001570``readonly``
Nick Lewyckyc2ec0722013-07-06 00:29:58 +00001571 On a function, this attribute indicates that the function does not write
1572 through any pointer arguments (including ``byval`` arguments) or otherwise
Sean Silvab084af42012-12-07 10:36:55 +00001573 modify any state (e.g. memory, control registers, etc) visible to
1574 caller functions. It may dereference pointer arguments and read
1575 state that may be set in the caller. A readonly function always
1576 returns the same value (or unwinds an exception identically) when
Sanjoy Das5be2e842017-02-13 23:19:07 +00001577 called with the same set of arguments and global state. This means while it
1578 cannot unwind exceptions by calling the ``C++`` exception throwing methods
1579 (since they write to memory), there may be non-``C++`` mechanisms that throw
1580 exceptions without writing to LLVM visible memory.
Andrew Trickd4d1d9c2013-10-31 17:18:07 +00001581
Nick Lewyckyc2ec0722013-07-06 00:29:58 +00001582 On an argument, this attribute indicates that the function does not write
1583 through this pointer argument, even though it may write to the memory that
1584 the pointer points to.
Eli Friedman0f522bd2018-07-25 18:26:38 +00001585
1586 If a readonly function writes memory visible to the program, or
1587 has other side-effects, the behavior is undefined. If a function writes to
1588 a readonly pointer argument, the behavior is undefined.
whitequark08b20352017-06-22 23:22:36 +00001589``"stack-probe-size"``
1590 This attribute controls the behavior of stack probes: either
1591 the ``"probe-stack"`` attribute, or ABI-required stack probes, if any.
1592 It defines the size of the guard region. It ensures that if the function
1593 may use more stack space than the size of the guard region, stack probing
1594 sequence will be emitted. It takes one required integer value, which
1595 is 4096 by default.
1596
1597 If a function that has a ``"stack-probe-size"`` attribute is inlined into
1598 a function with another ``"stack-probe-size"`` attribute, the resulting
1599 function has the ``"stack-probe-size"`` attribute that has the lower
1600 numeric value. If a function that has a ``"stack-probe-size"`` attribute is
1601 inlined into a function that has no ``"stack-probe-size"`` attribute
1602 at all, the resulting function has the ``"stack-probe-size"`` attribute
1603 of the callee.
Hans Wennborg89c35fc2018-02-23 13:46:25 +00001604``"no-stack-arg-probe"``
1605 This attribute disables ABI-required stack probes, if any.
Nicolai Haehnle84c9f992016-07-04 08:01:29 +00001606``writeonly``
1607 On a function, this attribute indicates that the function may write to but
1608 does not read from memory.
1609
1610 On an argument, this attribute indicates that the function may write to but
1611 does not read through this pointer argument (even though it may read from
1612 the memory that the pointer points to).
Eli Friedman0f522bd2018-07-25 18:26:38 +00001613
1614 If a writeonly function reads memory visible to the program, or
1615 has other side-effects, the behavior is undefined. If a function reads
1616 from a writeonly pointer argument, the behavior is undefined.
Igor Laevsky39d662f2015-07-11 10:30:36 +00001617``argmemonly``
1618 This attribute indicates that the only memory accesses inside function are
1619 loads and stores from objects pointed to by its pointer-typed arguments,
1620 with arbitrary offsets. Or in other words, all memory operations in the
1621 function can refer to memory only using pointers based on its function
1622 arguments.
Eli Friedman0f522bd2018-07-25 18:26:38 +00001623
Igor Laevsky39d662f2015-07-11 10:30:36 +00001624 Note that ``argmemonly`` can be used together with ``readonly`` attribute
1625 in order to specify that function reads only from its arguments.
Eli Friedman0f522bd2018-07-25 18:26:38 +00001626
1627 If an argmemonly function reads or writes memory other than the pointer
1628 arguments, or has other side-effects, the behavior is undefined.
Sean Silvab084af42012-12-07 10:36:55 +00001629``returns_twice``
1630 This attribute indicates that this function can return twice. The C
1631 ``setjmp`` is an example of such a function. The compiler disables
1632 some optimizations (like tail calls) in the caller of these
1633 functions.
Peter Collingbourne82437bf2015-06-15 21:07:11 +00001634``safestack``
1635 This attribute indicates that
1636 `SafeStack <http://clang.llvm.org/docs/SafeStack.html>`_
1637 protection is enabled for this function.
1638
1639 If a function that has a ``safestack`` attribute is inlined into a
1640 function that doesn't have a ``safestack`` attribute or which has an
1641 ``ssp``, ``sspstrong`` or ``sspreq`` attribute, then the resulting
1642 function will have a ``safestack`` attribute.
Kostya Serebryanycf880b92013-02-26 06:58:09 +00001643``sanitize_address``
1644 This attribute indicates that AddressSanitizer checks
1645 (dynamic address safety analysis) are enabled for this function.
1646``sanitize_memory``
1647 This attribute indicates that MemorySanitizer checks (dynamic detection
1648 of accesses to uninitialized memory) are enabled for this function.
1649``sanitize_thread``
1650 This attribute indicates that ThreadSanitizer checks
1651 (dynamic thread safety analysis) are enabled for this function.
Evgeniy Stepanovc667c1f2017-12-09 00:21:41 +00001652``sanitize_hwaddress``
1653 This attribute indicates that HWAddressSanitizer checks
1654 (dynamic address safety analysis based on tagged pointers) are enabled for
1655 this function.
Chandler Carruth664aa862018-09-04 12:38:00 +00001656``speculative_load_hardening``
1657 This attribute indicates that
1658 `Speculative Load Hardening <https://llvm.org/docs/SpeculativeLoadHardening.html>`_
Zola Bridgescbac3ad2018-11-27 19:56:46 +00001659 should be enabled for the function body.
1660
1661 Speculative Load Hardening is a best-effort mitigation against
1662 information leak attacks that make use of control flow
1663 miss-speculation - specifically miss-speculation of whether a branch
1664 is taken or not. Typically vulnerabilities enabling such attacks are
1665 classified as "Spectre variant #1". Notably, this does not attempt to
1666 mitigate against miss-speculation of branch target, classified as
1667 "Spectre variant #2" vulnerabilities.
Chandler Carruth664aa862018-09-04 12:38:00 +00001668
1669 When inlining, the attribute is sticky. Inlining a function that carries
1670 this attribute will cause the caller to gain the attribute. This is intended
1671 to provide a maximally conservative model where the code in a function
1672 annotated with this attribute will always (even after inlining) end up
1673 hardened.
Matt Arsenaultb19b57e2017-04-28 20:25:27 +00001674``speculatable``
1675 This function attribute indicates that the function does not have any
1676 effects besides calculating its result and does not have undefined behavior.
1677 Note that ``speculatable`` is not enough to conclude that along any
Xin Tongc7180202017-05-02 23:24:12 +00001678 particular execution path the number of calls to this function will not be
Matt Arsenaultb19b57e2017-04-28 20:25:27 +00001679 externally observable. This attribute is only valid on functions
1680 and declarations, not on individual call sites. If a function is
1681 incorrectly marked as speculatable and really does exhibit
1682 undefined behavior, the undefined behavior may be observed even
1683 if the call site is dead code.
1684
Sean Silvab084af42012-12-07 10:36:55 +00001685``ssp``
1686 This attribute indicates that the function should emit a stack
Dmitri Gribenkoe8131122013-01-19 20:34:20 +00001687 smashing protector. It is in the form of a "canary" --- a random value
Sean Silvab084af42012-12-07 10:36:55 +00001688 placed on the stack before the local variables that's checked upon
1689 return from the function to see if it has been overwritten. A
1690 heuristic is used to determine if a function needs stack protectors
Bill Wendling7c8f96a2013-01-23 06:43:53 +00001691 or not. The heuristic used will enable protectors for functions with:
Dmitri Gribenko69b56472013-01-29 23:14:41 +00001692
Bill Wendling7c8f96a2013-01-23 06:43:53 +00001693 - Character arrays larger than ``ssp-buffer-size`` (default 8).
1694 - Aggregates containing character arrays larger than ``ssp-buffer-size``.
1695 - Calls to alloca() with variable sizes or constant sizes greater than
1696 ``ssp-buffer-size``.
Sean Silvab084af42012-12-07 10:36:55 +00001697
Josh Magee24c7f062014-02-01 01:36:16 +00001698 Variables that are identified as requiring a protector will be arranged
1699 on the stack such that they are adjacent to the stack protector guard.
1700
Sean Silvab084af42012-12-07 10:36:55 +00001701 If a function that has an ``ssp`` attribute is inlined into a
1702 function that doesn't have an ``ssp`` attribute, then the resulting
1703 function will have an ``ssp`` attribute.
1704``sspreq``
1705 This attribute indicates that the function should *always* emit a
1706 stack smashing protector. This overrides the ``ssp`` function
1707 attribute.
1708
Josh Magee24c7f062014-02-01 01:36:16 +00001709 Variables that are identified as requiring a protector will be arranged
1710 on the stack such that they are adjacent to the stack protector guard.
1711 The specific layout rules are:
1712
1713 #. Large arrays and structures containing large arrays
1714 (``>= ssp-buffer-size``) are closest to the stack protector.
1715 #. Small arrays and structures containing small arrays
1716 (``< ssp-buffer-size``) are 2nd closest to the protector.
1717 #. Variables that have had their address taken are 3rd closest to the
1718 protector.
1719
Sean Silvab084af42012-12-07 10:36:55 +00001720 If a function that has an ``sspreq`` attribute is inlined into a
1721 function that doesn't have an ``sspreq`` attribute or which has an
Bill Wendlingd154e2832013-01-23 06:41:41 +00001722 ``ssp`` or ``sspstrong`` attribute, then the resulting function will have
1723 an ``sspreq`` attribute.
1724``sspstrong``
1725 This attribute indicates that the function should emit a stack smashing
Bill Wendling7c8f96a2013-01-23 06:43:53 +00001726 protector. This attribute causes a strong heuristic to be used when
Sean Silvaa1190322015-08-06 22:56:48 +00001727 determining if a function needs stack protectors. The strong heuristic
Bill Wendling7c8f96a2013-01-23 06:43:53 +00001728 will enable protectors for functions with:
Dmitri Gribenko69b56472013-01-29 23:14:41 +00001729
Bill Wendling7c8f96a2013-01-23 06:43:53 +00001730 - Arrays of any size and type
1731 - Aggregates containing an array of any size and type.
1732 - Calls to alloca().
1733 - Local variables that have had their address taken.
1734
Josh Magee24c7f062014-02-01 01:36:16 +00001735 Variables that are identified as requiring a protector will be arranged
1736 on the stack such that they are adjacent to the stack protector guard.
1737 The specific layout rules are:
1738
1739 #. Large arrays and structures containing large arrays
1740 (``>= ssp-buffer-size``) are closest to the stack protector.
1741 #. Small arrays and structures containing small arrays
1742 (``< ssp-buffer-size``) are 2nd closest to the protector.
1743 #. Variables that have had their address taken are 3rd closest to the
1744 protector.
1745
Bill Wendling7c8f96a2013-01-23 06:43:53 +00001746 This overrides the ``ssp`` function attribute.
Bill Wendlingd154e2832013-01-23 06:41:41 +00001747
1748 If a function that has an ``sspstrong`` attribute is inlined into a
1749 function that doesn't have an ``sspstrong`` attribute, then the
1750 resulting function will have an ``sspstrong`` attribute.
Andrew Kaylor53a5fbb2017-08-14 21:15:13 +00001751``strictfp``
1752 This attribute indicates that the function was called from a scope that
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00001753 requires strict floating-point semantics. LLVM will not attempt any
1754 optimizations that require assumptions about the floating-point rounding
1755 mode or that might alter the state of floating-point status flags that
Andrew Kaylor53a5fbb2017-08-14 21:15:13 +00001756 might otherwise be set or cleared by calling this function.
Reid Kleckner5a2ab2b2015-03-04 00:08:56 +00001757``"thunk"``
1758 This attribute indicates that the function will delegate to some other
1759 function with a tail call. The prototype of a thunk should not be used for
1760 optimization purposes. The caller is expected to cast the thunk prototype to
1761 match the thunk target prototype.
Sean Silvab084af42012-12-07 10:36:55 +00001762``uwtable``
1763 This attribute indicates that the ABI being targeted requires that
Sean Silva706fba52015-08-06 22:56:24 +00001764 an unwind table entry be produced for this function even if we can
Sean Silvab084af42012-12-07 10:36:55 +00001765 show that no exceptions passes by it. This is normally the case for
1766 the ELF x86-64 abi, but it can be disabled for some compilation
1767 units.
Oren Ben Simhonfdd72fd2018-03-17 13:29:46 +00001768``nocf_check``
Hiroshi Inouec36a1f12018-06-15 05:10:09 +00001769 This attribute indicates that no control-flow check will be performed on
Oren Ben Simhonfdd72fd2018-03-17 13:29:46 +00001770 the attributed entity. It disables -fcf-protection=<> for a specific
1771 entity to fine grain the HW control flow protection mechanism. The flag
Hiroshi Inouec36a1f12018-06-15 05:10:09 +00001772 is target independent and currently appertains to a function or function
Oren Ben Simhonfdd72fd2018-03-17 13:29:46 +00001773 pointer.
Vlad Tsyrklevichd17f61e2018-04-03 20:10:40 +00001774``shadowcallstack``
1775 This attribute indicates that the ShadowCallStack checks are enabled for
1776 the function. The instrumentation checks that the return address for the
1777 function has not changed between the function prolog and eiplog. It is
1778 currently x86_64-specific.
Sean Silvab084af42012-12-07 10:36:55 +00001779
Javed Absarf3d79042017-05-11 12:28:08 +00001780.. _glattrs:
1781
1782Global Attributes
1783-----------------
1784
1785Attributes may be set to communicate additional information about a global variable.
1786Unlike :ref:`function attributes <fnattrs>`, attributes on a global variable
1787are grouped into a single :ref:`attribute group <attrgrp>`.
Sanjoy Dasb513a9f2015-09-24 23:34:52 +00001788
1789.. _opbundles:
1790
1791Operand Bundles
1792---------------
1793
Sanjoy Dasb513a9f2015-09-24 23:34:52 +00001794Operand bundles are tagged sets of SSA values that can be associated
Sanjoy Dasb0e9d4a52015-09-25 00:05:40 +00001795with certain LLVM instructions (currently only ``call`` s and
1796``invoke`` s). In a way they are like metadata, but dropping them is
Sanjoy Dasb513a9f2015-09-24 23:34:52 +00001797incorrect and will change program semantics.
1798
1799Syntax::
David Majnemer34cacb42015-10-22 01:46:38 +00001800
Sanjoy Das9f3c1252015-11-21 09:12:07 +00001801 operand bundle set ::= '[' operand bundle (, operand bundle )* ']'
Sanjoy Dasb513a9f2015-09-24 23:34:52 +00001802 operand bundle ::= tag '(' [ bundle operand ] (, bundle operand )* ')'
1803 bundle operand ::= SSA value
1804 tag ::= string constant
1805
1806Operand bundles are **not** part of a function's signature, and a
1807given function may be called from multiple places with different kinds
1808of operand bundles. This reflects the fact that the operand bundles
1809are conceptually a part of the ``call`` (or ``invoke``), not the
1810callee being dispatched to.
1811
1812Operand bundles are a generic mechanism intended to support
1813runtime-introspection-like functionality for managed languages. While
1814the exact semantics of an operand bundle depend on the bundle tag,
1815there are certain limitations to how much the presence of an operand
1816bundle can influence the semantics of a program. These restrictions
1817are described as the semantics of an "unknown" operand bundle. As
1818long as the behavior of an operand bundle is describable within these
1819restrictions, LLVM does not need to have special knowledge of the
1820operand bundle to not miscompile programs containing it.
1821
David Majnemer34cacb42015-10-22 01:46:38 +00001822- The bundle operands for an unknown operand bundle escape in unknown
1823 ways before control is transferred to the callee or invokee.
1824- Calls and invokes with operand bundles have unknown read / write
1825 effect on the heap on entry and exit (even if the call target is
Sylvestre Ledru84666a12016-02-14 20:16:22 +00001826 ``readnone`` or ``readonly``), unless they're overridden with
Sanjoy Das98a341b2015-10-22 03:12:22 +00001827 callsite specific attributes.
1828- An operand bundle at a call site cannot change the implementation
1829 of the called function. Inter-procedural optimizations work as
1830 usual as long as they take into account the first two properties.
Sanjoy Dasb513a9f2015-09-24 23:34:52 +00001831
Sanjoy Dascdafd842015-11-11 21:38:02 +00001832More specific types of operand bundles are described below.
1833
Sanjoy Dasb51325d2016-03-11 19:08:34 +00001834.. _deopt_opbundles:
1835
Sanjoy Dascdafd842015-11-11 21:38:02 +00001836Deoptimization Operand Bundles
1837^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1838
Sanjoy Das9f3c1252015-11-21 09:12:07 +00001839Deoptimization operand bundles are characterized by the ``"deopt"``
Sanjoy Dascdafd842015-11-11 21:38:02 +00001840operand bundle tag. These operand bundles represent an alternate
1841"safe" continuation for the call site they're attached to, and can be
1842used by a suitable runtime to deoptimize the compiled frame at the
Sanjoy Das9f3c1252015-11-21 09:12:07 +00001843specified call site. There can be at most one ``"deopt"`` operand
1844bundle attached to a call site. Exact details of deoptimization is
1845out of scope for the language reference, but it usually involves
1846rewriting a compiled frame into a set of interpreted frames.
Sanjoy Dascdafd842015-11-11 21:38:02 +00001847
1848From the compiler's perspective, deoptimization operand bundles make
1849the call sites they're attached to at least ``readonly``. They read
1850through all of their pointer typed operands (even if they're not
1851otherwise escaped) and the entire visible heap. Deoptimization
1852operand bundles do not capture their operands except during
1853deoptimization, in which case control will not be returned to the
1854compiled frame.
1855
Sanjoy Das2d161452015-11-18 06:23:38 +00001856The inliner knows how to inline through calls that have deoptimization
1857operand bundles. Just like inlining through a normal call site
1858involves composing the normal and exceptional continuations, inlining
1859through a call site with a deoptimization operand bundle needs to
1860appropriately compose the "safe" deoptimization continuation. The
1861inliner does this by prepending the parent's deoptimization
1862continuation to every deoptimization continuation in the inlined body.
1863E.g. inlining ``@f`` into ``@g`` in the following example
1864
1865.. code-block:: llvm
1866
1867 define void @f() {
1868 call void @x() ;; no deopt state
1869 call void @y() [ "deopt"(i32 10) ]
1870 call void @y() [ "deopt"(i32 10), "unknown"(i8* null) ]
1871 ret void
1872 }
1873
1874 define void @g() {
1875 call void @f() [ "deopt"(i32 20) ]
1876 ret void
1877 }
1878
1879will result in
1880
1881.. code-block:: llvm
1882
1883 define void @g() {
1884 call void @x() ;; still no deopt state
1885 call void @y() [ "deopt"(i32 20, i32 10) ]
1886 call void @y() [ "deopt"(i32 20, i32 10), "unknown"(i8* null) ]
1887 ret void
1888 }
1889
1890It is the frontend's responsibility to structure or encode the
1891deoptimization state in a way that syntactically prepending the
1892caller's deoptimization state to the callee's deoptimization state is
1893semantically equivalent to composing the caller's deoptimization
1894continuation after the callee's deoptimization continuation.
1895
Joseph Tremoulete28885e2016-01-10 04:28:38 +00001896.. _ob_funclet:
1897
David Majnemer3bb88c02015-12-15 21:27:27 +00001898Funclet Operand Bundles
1899^^^^^^^^^^^^^^^^^^^^^^^
1900
1901Funclet operand bundles are characterized by the ``"funclet"``
1902operand bundle tag. These operand bundles indicate that a call site
1903is within a particular funclet. There can be at most one
1904``"funclet"`` operand bundle attached to a call site and it must have
1905exactly one bundle operand.
1906
Joseph Tremoulete28885e2016-01-10 04:28:38 +00001907If any funclet EH pads have been "entered" but not "exited" (per the
1908`description in the EH doc\ <ExceptionHandling.html#wineh-constraints>`_),
1909it is undefined behavior to execute a ``call`` or ``invoke`` which:
1910
1911* does not have a ``"funclet"`` bundle and is not a ``call`` to a nounwind
1912 intrinsic, or
1913* has a ``"funclet"`` bundle whose operand is not the most-recently-entered
1914 not-yet-exited funclet EH pad.
1915
1916Similarly, if no funclet EH pads have been entered-but-not-yet-exited,
1917executing a ``call`` or ``invoke`` with a ``"funclet"`` bundle is undefined behavior.
1918
Sanjoy Dasa34ce952016-01-20 19:50:25 +00001919GC Transition Operand Bundles
1920^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1921
1922GC transition operand bundles are characterized by the
1923``"gc-transition"`` operand bundle tag. These operand bundles mark a
1924call as a transition between a function with one GC strategy to a
1925function with a different GC strategy. If coordinating the transition
1926between GC strategies requires additional code generation at the call
1927site, these bundles may contain any values that are needed by the
1928generated code. For more details, see :ref:`GC Transitions
1929<gc_transition_args>`.
1930
Sean Silvab084af42012-12-07 10:36:55 +00001931.. _moduleasm:
1932
1933Module-Level Inline Assembly
1934----------------------------
1935
1936Modules may contain "module-level inline asm" blocks, which corresponds
1937to the GCC "file scope inline asm" blocks. These blocks are internally
1938concatenated by LLVM and treated as a single unit, but may be separated
1939in the ``.ll`` file if desired. The syntax is very simple:
1940
1941.. code-block:: llvm
1942
1943 module asm "inline asm code goes here"
1944 module asm "more can go here"
1945
1946The strings can contain any character by escaping non-printable
1947characters. The escape sequence used is simply "\\xx" where "xx" is the
1948two digit hex code for the number.
1949
James Y Knightbc832ed2015-07-08 18:08:36 +00001950Note that the assembly string *must* be parseable by LLVM's integrated assembler
1951(unless it is disabled), even when emitting a ``.s`` file.
Sean Silvab084af42012-12-07 10:36:55 +00001952
Eli Benderskyfdc529a2013-06-07 19:40:08 +00001953.. _langref_datalayout:
1954
Sean Silvab084af42012-12-07 10:36:55 +00001955Data Layout
1956-----------
1957
1958A module may specify a target specific data layout string that specifies
1959how data is to be laid out in memory. The syntax for the data layout is
1960simply:
1961
1962.. code-block:: llvm
1963
1964 target datalayout = "layout specification"
1965
1966The *layout specification* consists of a list of specifications
1967separated by the minus sign character ('-'). Each specification starts
1968with a letter and may include other information after the letter to
1969define some aspect of the data layout. The specifications accepted are
1970as follows:
1971
1972``E``
1973 Specifies that the target lays out data in big-endian form. That is,
1974 the bits with the most significance have the lowest address
1975 location.
1976``e``
1977 Specifies that the target lays out data in little-endian form. That
1978 is, the bits with the least significance have the lowest address
1979 location.
1980``S<size>``
1981 Specifies the natural alignment of the stack in bits. Alignment
1982 promotion of stack variables is limited to the natural stack
1983 alignment to avoid dynamic stack realignment. The stack alignment
1984 must be a multiple of 8-bits. If omitted, the natural stack
1985 alignment defaults to "unspecified", which does not prevent any
1986 alignment promotions.
Dylan McKayced2fe62018-02-19 09:56:22 +00001987``P<address space>``
1988 Specifies the address space that corresponds to program memory.
1989 Harvard architectures can use this to specify what space LLVM
1990 should place things such as functions into. If omitted, the
1991 program memory space defaults to the default address space of 0,
1992 which corresponds to a Von Neumann architecture that has code
1993 and data in the same space.
Matt Arsenault3c1fc762017-04-10 22:27:50 +00001994``A<address space>``
Dylan McKayced2fe62018-02-19 09:56:22 +00001995 Specifies the address space of objects created by '``alloca``'.
Matt Arsenault3c1fc762017-04-10 22:27:50 +00001996 Defaults to the default address space of 0.
Elena Demikhovsky945b7e52018-02-14 06:58:08 +00001997``p[n]:<size>:<abi>:<pref>:<idx>``
Sean Silvab084af42012-12-07 10:36:55 +00001998 This specifies the *size* of a pointer and its ``<abi>`` and
Elena Demikhovsky945b7e52018-02-14 06:58:08 +00001999 ``<pref>``\erred alignments for address space ``n``. The fourth parameter
2000 ``<idx>`` is a size of index that used for address calculation. If not
2001 specified, the default index size is equal to the pointer size. All sizes
2002 are in bits. The address space, ``n``, is optional, and if not specified,
Sean Silvaa1190322015-08-06 22:56:48 +00002003 denotes the default address space 0. The value of ``n`` must be
Rafael Espindolaabdd7262014-01-06 21:40:24 +00002004 in the range [1,2^23).
Sean Silvab084af42012-12-07 10:36:55 +00002005``i<size>:<abi>:<pref>``
2006 This specifies the alignment for an integer type of a given bit
2007 ``<size>``. The value of ``<size>`` must be in the range [1,2^23).
2008``v<size>:<abi>:<pref>``
2009 This specifies the alignment for a vector type of a given bit
2010 ``<size>``.
2011``f<size>:<abi>:<pref>``
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00002012 This specifies the alignment for a floating-point type of a given bit
Sean Silvab084af42012-12-07 10:36:55 +00002013 ``<size>``. Only values of ``<size>`` that are supported by the target
2014 will work. 32 (float) and 64 (double) are supported on all targets; 80
2015 or 128 (different flavors of long double) are also supported on some
2016 targets.
Rafael Espindolaabdd7262014-01-06 21:40:24 +00002017``a:<abi>:<pref>``
2018 This specifies the alignment for an object of aggregate type.
Michael Platings308e82e2019-03-08 10:44:06 +00002019``F<type><abi>``
2020 This specifies the alignment for function pointers.
2021 The options for ``<type>`` are:
2022
2023 * ``i``: The alignment of function pointers is independent of the alignment
2024 of functions, and is a multiple of ``<abi>``.
2025 * ``n``: The alignment of function pointers is a multiple of the explicit
2026 alignment specified on the function, and is a multiple of ``<abi>``.
Rafael Espindola58873562014-01-03 19:21:54 +00002027``m:<mangling>``
Reid Klecknerf8b51c52018-03-16 20:13:32 +00002028 If present, specifies that llvm names are mangled in the output. Symbols
2029 prefixed with the mangling escape character ``\01`` are passed through
2030 directly to the assembler without the escape character. The mangling style
Hans Wennborgd4245ac2014-01-15 02:49:17 +00002031 options are
2032
2033 * ``e``: ELF mangling: Private symbols get a ``.L`` prefix.
2034 * ``m``: Mips mangling: Private symbols get a ``$`` prefix.
2035 * ``o``: Mach-O mangling: Private symbols get ``L`` prefix. Other
2036 symbols get a ``_`` prefix.
Reid Klecknerf8b51c52018-03-16 20:13:32 +00002037 * ``x``: Windows x86 COFF mangling: Private symbols get the usual prefix.
2038 Regular C symbols get a ``_`` prefix. Functions with ``__stdcall``,
2039 ``__fastcall``, and ``__vectorcall`` have custom mangling that appends
2040 ``@N`` where N is the number of bytes used to pass parameters. C++ symbols
2041 starting with ``?`` are not mangled in any way.
2042 * ``w``: Windows COFF mangling: Similar to ``x``, except that normal C
2043 symbols do not receive a ``_`` prefix.
Sean Silvab084af42012-12-07 10:36:55 +00002044``n<size1>:<size2>:<size3>...``
2045 This specifies a set of native integer widths for the target CPU in
2046 bits. For example, it might contain ``n32`` for 32-bit PowerPC,
2047 ``n32:64`` for PowerPC 64, or ``n8:16:32:64`` for X86-64. Elements of
2048 this set are considered to support most general arithmetic operations
2049 efficiently.
Sanjoy Dasc6af5ea2016-07-28 23:43:38 +00002050``ni:<address space0>:<address space1>:<address space2>...``
2051 This specifies pointer types with the specified address spaces
2052 as :ref:`Non-Integral Pointer Type <nointptrtype>` s. The ``0``
2053 address space cannot be specified as non-integral.
Sean Silvab084af42012-12-07 10:36:55 +00002054
Rafael Espindolaabdd7262014-01-06 21:40:24 +00002055On every specification that takes a ``<abi>:<pref>``, specifying the
2056``<pref>`` alignment is optional. If omitted, the preceding ``:``
2057should be omitted too and ``<pref>`` will be equal to ``<abi>``.
2058
Sean Silvab084af42012-12-07 10:36:55 +00002059When constructing the data layout for a given target, LLVM starts with a
2060default set of specifications which are then (possibly) overridden by
2061the specifications in the ``datalayout`` keyword. The default
2062specifications are given in this list:
2063
2064- ``E`` - big endian
Matt Arsenault24b49c42013-07-31 17:49:08 +00002065- ``p:64:64:64`` - 64-bit pointers with 64-bit alignment.
2066- ``p[n]:64:64:64`` - Other address spaces are assumed to be the
2067 same as the default address space.
Patrik Hagglunda832ab12013-01-30 09:02:06 +00002068- ``S0`` - natural stack alignment is unspecified
Sean Silvab084af42012-12-07 10:36:55 +00002069- ``i1:8:8`` - i1 is 8-bit (byte) aligned
2070- ``i8:8:8`` - i8 is 8-bit (byte) aligned
2071- ``i16:16:16`` - i16 is 16-bit aligned
2072- ``i32:32:32`` - i32 is 32-bit aligned
2073- ``i64:32:64`` - i64 has ABI alignment of 32-bits but preferred
2074 alignment of 64-bits
Patrik Hagglunda832ab12013-01-30 09:02:06 +00002075- ``f16:16:16`` - half is 16-bit aligned
Sean Silvab084af42012-12-07 10:36:55 +00002076- ``f32:32:32`` - float is 32-bit aligned
2077- ``f64:64:64`` - double is 64-bit aligned
Patrik Hagglunda832ab12013-01-30 09:02:06 +00002078- ``f128:128:128`` - quad is 128-bit aligned
Sean Silvab084af42012-12-07 10:36:55 +00002079- ``v64:64:64`` - 64-bit vector is 64-bit aligned
2080- ``v128:128:128`` - 128-bit vector is 128-bit aligned
Rafael Espindolae8f4d582013-12-12 17:21:51 +00002081- ``a:0:64`` - aggregates are 64-bit aligned
Sean Silvab084af42012-12-07 10:36:55 +00002082
2083When LLVM is determining the alignment for a given type, it uses the
2084following rules:
2085
2086#. If the type sought is an exact match for one of the specifications,
2087 that specification is used.
2088#. If no match is found, and the type sought is an integer type, then
2089 the smallest integer type that is larger than the bitwidth of the
2090 sought type is used. If none of the specifications are larger than
2091 the bitwidth then the largest integer type is used. For example,
2092 given the default specifications above, the i7 type will use the
2093 alignment of i8 (next largest) while both i65 and i256 will use the
2094 alignment of i64 (largest specified).
2095#. If no match is found, and the type sought is a vector type, then the
2096 largest vector type that is smaller than the sought vector type will
2097 be used as a fall back. This happens because <128 x double> can be
2098 implemented in terms of 64 <2 x double>, for example.
2099
2100The function of the data layout string may not be what you expect.
2101Notably, this is not a specification from the frontend of what alignment
2102the code generator should use.
2103
2104Instead, if specified, the target data layout is required to match what
2105the ultimate *code generator* expects. This string is used by the
2106mid-level optimizers to improve code, and this only works if it matches
Mehdi Amini4a121fa2015-03-14 22:04:06 +00002107what the ultimate code generator uses. There is no way to generate IR
2108that does not embed this target-specific detail into the IR. If you
2109don't specify the string, the default specifications will be used to
2110generate a Data Layout and the optimization phases will operate
2111accordingly and introduce target specificity into the IR with respect to
2112these default specifications.
Sean Silvab084af42012-12-07 10:36:55 +00002113
Bill Wendling5cc90842013-10-18 23:41:25 +00002114.. _langref_triple:
2115
2116Target Triple
2117-------------
2118
2119A module may specify a target triple string that describes the target
2120host. The syntax for the target triple is simply:
2121
2122.. code-block:: llvm
2123
2124 target triple = "x86_64-apple-macosx10.7.0"
2125
2126The *target triple* string consists of a series of identifiers delimited
2127by the minus sign character ('-'). The canonical forms are:
2128
2129::
2130
2131 ARCHITECTURE-VENDOR-OPERATING_SYSTEM
2132 ARCHITECTURE-VENDOR-OPERATING_SYSTEM-ENVIRONMENT
2133
2134This information is passed along to the backend so that it generates
2135code for the proper architecture. It's possible to override this on the
2136command line with the ``-mtriple`` command line option.
2137
Sean Silvab084af42012-12-07 10:36:55 +00002138.. _pointeraliasing:
2139
2140Pointer Aliasing Rules
2141----------------------
2142
2143Any memory access must be done through a pointer value associated with
2144an address range of the memory access, otherwise the behavior is
2145undefined. Pointer values are associated with address ranges according
2146to the following rules:
2147
2148- A pointer value is associated with the addresses associated with any
2149 value it is *based* on.
2150- An address of a global variable is associated with the address range
2151 of the variable's storage.
2152- The result value of an allocation instruction is associated with the
2153 address range of the allocated storage.
2154- A null pointer in the default address-space is associated with no
2155 address.
2156- An integer constant other than zero or a pointer value returned from
2157 a function not defined within LLVM may be associated with address
2158 ranges allocated through mechanisms other than those provided by
2159 LLVM. Such ranges shall not overlap with any ranges of addresses
2160 allocated by mechanisms provided by LLVM.
2161
2162A pointer value is *based* on another pointer value according to the
2163following rules:
2164
Sanjoy Das6d489492017-09-13 18:49:22 +00002165- A pointer value formed from a scalar ``getelementptr`` operation is *based* on
2166 the pointer-typed operand of the ``getelementptr``.
2167- The pointer in lane *l* of the result of a vector ``getelementptr`` operation
2168 is *based* on the pointer in lane *l* of the vector-of-pointers-typed operand
2169 of the ``getelementptr``.
Sean Silvab084af42012-12-07 10:36:55 +00002170- The result value of a ``bitcast`` is *based* on the operand of the
2171 ``bitcast``.
2172- A pointer value formed by an ``inttoptr`` is *based* on all pointer
2173 values that contribute (directly or indirectly) to the computation of
2174 the pointer's value.
2175- The "*based* on" relationship is transitive.
2176
2177Note that this definition of *"based"* is intentionally similar to the
2178definition of *"based"* in C99, though it is slightly weaker.
2179
2180LLVM IR does not associate types with memory. The result type of a
2181``load`` merely indicates the size and alignment of the memory from
2182which to load, as well as the interpretation of the value. The first
2183operand type of a ``store`` similarly only indicates the size and
2184alignment of the store.
2185
2186Consequently, type-based alias analysis, aka TBAA, aka
2187``-fstrict-aliasing``, is not applicable to general unadorned LLVM IR.
2188:ref:`Metadata <metadata>` may be used to encode additional information
2189which specialized optimization passes may use to implement type-based
2190alias analysis.
2191
2192.. _volatile:
2193
2194Volatile Memory Accesses
2195------------------------
2196
2197Certain memory accesses, such as :ref:`load <i_load>`'s,
2198:ref:`store <i_store>`'s, and :ref:`llvm.memcpy <int_memcpy>`'s may be
2199marked ``volatile``. The optimizers must not change the number of
2200volatile operations or change their order of execution relative to other
2201volatile operations. The optimizers *may* change the order of volatile
2202operations relative to non-volatile operations. This is not Java's
2203"volatile" and has no cross-thread synchronization behavior.
2204
Eli Friedman9ba16822019-01-22 00:42:20 +00002205A volatile load or store may have additional target-specific semantics.
2206Any volatile operation can have side effects, and any volatile operation
2207can read and/or modify state which is not accessible via a regular load
Eli Friedmanf0e67682019-01-28 23:03:41 +00002208or store in this module. Volatile operations may use addresses which do
Eli Friedman9ba16822019-01-22 00:42:20 +00002209not point to memory (like MMIO registers). This means the compiler may
2210not use a volatile operation to prove a non-volatile access to that
2211address has defined behavior.
2212
2213The allowed side-effects for volatile accesses are limited. If a
2214non-volatile store to a given address would be legal, a volatile
2215operation may modify the memory at that address. A volatile operation
2216may not modify any other memory accessible by the module being compiled.
2217A volatile operation may not call any code in the current module.
2218
2219The compiler may assume execution will continue after a volatile operation,
2220so operations which modify memory or may have undefined behavior can be
2221hoisted past a volatile operation.
2222
Andrew Trick89fc5a62013-01-30 21:19:35 +00002223IR-level volatile loads and stores cannot safely be optimized into
2224llvm.memcpy or llvm.memmove intrinsics even when those intrinsics are
2225flagged volatile. Likewise, the backend should never split or merge
2226target-legal volatile load/store instructions.
2227
Andrew Trick7e6f9282013-01-31 00:49:39 +00002228.. admonition:: Rationale
2229
2230 Platforms may rely on volatile loads and stores of natively supported
2231 data width to be executed as single instruction. For example, in C
2232 this holds for an l-value of volatile primitive type with native
2233 hardware support, but not necessarily for aggregate types. The
2234 frontend upholds these expectations, which are intentionally
Sean Silva706fba52015-08-06 22:56:24 +00002235 unspecified in the IR. The rules above ensure that IR transformations
Andrew Trick7e6f9282013-01-31 00:49:39 +00002236 do not violate the frontend's contract with the language.
2237
Sean Silvab084af42012-12-07 10:36:55 +00002238.. _memmodel:
2239
2240Memory Model for Concurrent Operations
2241--------------------------------------
2242
2243The LLVM IR does not define any way to start parallel threads of
2244execution or to register signal handlers. Nonetheless, there are
2245platform-specific ways to create them, and we define LLVM IR's behavior
2246in their presence. This model is inspired by the C++0x memory model.
2247
2248For a more informal introduction to this model, see the :doc:`Atomics`.
2249
2250We define a *happens-before* partial order as the least partial order
2251that
2252
2253- Is a superset of single-thread program order, and
2254- When a *synchronizes-with* ``b``, includes an edge from ``a`` to
2255 ``b``. *Synchronizes-with* pairs are introduced by platform-specific
2256 techniques, like pthread locks, thread creation, thread joining,
2257 etc., and by atomic instructions. (See also :ref:`Atomic Memory Ordering
2258 Constraints <ordering>`).
2259
2260Note that program order does not introduce *happens-before* edges
2261between a thread and signals executing inside that thread.
2262
2263Every (defined) read operation (load instructions, memcpy, atomic
2264loads/read-modify-writes, etc.) R reads a series of bytes written by
2265(defined) write operations (store instructions, atomic
2266stores/read-modify-writes, memcpy, etc.). For the purposes of this
2267section, initialized globals are considered to have a write of the
2268initializer which is atomic and happens before any other read or write
2269of the memory in question. For each byte of a read R, R\ :sub:`byte`
2270may see any write to the same byte, except:
2271
2272- If write\ :sub:`1` happens before write\ :sub:`2`, and
2273 write\ :sub:`2` happens before R\ :sub:`byte`, then
2274 R\ :sub:`byte` does not see write\ :sub:`1`.
2275- If R\ :sub:`byte` happens before write\ :sub:`3`, then
2276 R\ :sub:`byte` does not see write\ :sub:`3`.
2277
2278Given that definition, R\ :sub:`byte` is defined as follows:
2279
2280- If R is volatile, the result is target-dependent. (Volatile is
2281 supposed to give guarantees which can support ``sig_atomic_t`` in
Richard Smith32dbdf62014-07-31 04:25:36 +00002282 C/C++, and may be used for accesses to addresses that do not behave
Sean Silvab084af42012-12-07 10:36:55 +00002283 like normal memory. It does not generally provide cross-thread
2284 synchronization.)
2285- Otherwise, if there is no write to the same byte that happens before
2286 R\ :sub:`byte`, R\ :sub:`byte` returns ``undef`` for that byte.
2287- Otherwise, if R\ :sub:`byte` may see exactly one write,
2288 R\ :sub:`byte` returns the value written by that write.
2289- Otherwise, if R is atomic, and all the writes R\ :sub:`byte` may
2290 see are atomic, it chooses one of the values written. See the :ref:`Atomic
2291 Memory Ordering Constraints <ordering>` section for additional
2292 constraints on how the choice is made.
2293- Otherwise R\ :sub:`byte` returns ``undef``.
2294
2295R returns the value composed of the series of bytes it read. This
2296implies that some bytes within the value may be ``undef`` **without**
2297the entire value being ``undef``. Note that this only defines the
2298semantics of the operation; it doesn't mean that targets will emit more
2299than one instruction to read the series of bytes.
2300
2301Note that in cases where none of the atomic intrinsics are used, this
2302model places only one restriction on IR transformations on top of what
2303is required for single-threaded execution: introducing a store to a byte
2304which might not otherwise be stored is not allowed in general.
2305(Specifically, in the case where another thread might write to and read
2306from an address, introducing a store can change a load that may see
2307exactly one write into a load that may see multiple writes.)
2308
2309.. _ordering:
2310
2311Atomic Memory Ordering Constraints
2312----------------------------------
2313
2314Atomic instructions (:ref:`cmpxchg <i_cmpxchg>`,
2315:ref:`atomicrmw <i_atomicrmw>`, :ref:`fence <i_fence>`,
2316:ref:`atomic load <i_load>`, and :ref:`atomic store <i_store>`) take
Tim Northovere94a5182014-03-11 10:48:52 +00002317ordering parameters that determine which other atomic instructions on
Sean Silvab084af42012-12-07 10:36:55 +00002318the same address they *synchronize with*. These semantics are borrowed
2319from Java and C++0x, but are somewhat more colloquial. If these
2320descriptions aren't precise enough, check those specs (see spec
2321references in the :doc:`atomics guide <Atomics>`).
2322:ref:`fence <i_fence>` instructions treat these orderings somewhat
2323differently since they don't take an address. See that instruction's
2324documentation for details.
2325
2326For a simpler introduction to the ordering constraints, see the
2327:doc:`Atomics`.
2328
2329``unordered``
2330 The set of values that can be read is governed by the happens-before
2331 partial order. A value cannot be read unless some operation wrote
2332 it. This is intended to provide a guarantee strong enough to model
2333 Java's non-volatile shared variables. This ordering cannot be
2334 specified for read-modify-write operations; it is not strong enough
2335 to make them atomic in any interesting way.
2336``monotonic``
2337 In addition to the guarantees of ``unordered``, there is a single
2338 total order for modifications by ``monotonic`` operations on each
2339 address. All modification orders must be compatible with the
2340 happens-before order. There is no guarantee that the modification
2341 orders can be combined to a global total order for the whole program
2342 (and this often will not be possible). The read in an atomic
2343 read-modify-write operation (:ref:`cmpxchg <i_cmpxchg>` and
2344 :ref:`atomicrmw <i_atomicrmw>`) reads the value in the modification
2345 order immediately before the value it writes. If one atomic read
2346 happens before another atomic read of the same address, the later
2347 read must see the same value or a later value in the address's
2348 modification order. This disallows reordering of ``monotonic`` (or
2349 stronger) operations on the same address. If an address is written
2350 ``monotonic``-ally by one thread, and other threads ``monotonic``-ally
2351 read that address repeatedly, the other threads must eventually see
2352 the write. This corresponds to the C++0x/C1x
2353 ``memory_order_relaxed``.
2354``acquire``
2355 In addition to the guarantees of ``monotonic``, a
2356 *synchronizes-with* edge may be formed with a ``release`` operation.
2357 This is intended to model C++'s ``memory_order_acquire``.
2358``release``
2359 In addition to the guarantees of ``monotonic``, if this operation
2360 writes a value which is subsequently read by an ``acquire``
2361 operation, it *synchronizes-with* that operation. (This isn't a
2362 complete description; see the C++0x definition of a release
2363 sequence.) This corresponds to the C++0x/C1x
2364 ``memory_order_release``.
2365``acq_rel`` (acquire+release)
2366 Acts as both an ``acquire`` and ``release`` operation on its
2367 address. This corresponds to the C++0x/C1x ``memory_order_acq_rel``.
2368``seq_cst`` (sequentially consistent)
2369 In addition to the guarantees of ``acq_rel`` (``acquire`` for an
Richard Smith32dbdf62014-07-31 04:25:36 +00002370 operation that only reads, ``release`` for an operation that only
Sean Silvab084af42012-12-07 10:36:55 +00002371 writes), there is a global total order on all
2372 sequentially-consistent operations on all addresses, which is
2373 consistent with the *happens-before* partial order and with the
2374 modification orders of all the affected addresses. Each
2375 sequentially-consistent read sees the last preceding write to the
2376 same address in this global order. This corresponds to the C++0x/C1x
2377 ``memory_order_seq_cst`` and Java volatile.
2378
Konstantin Zhuravlyovbb80d3e2017-07-11 22:23:00 +00002379.. _syncscope:
Sean Silvab084af42012-12-07 10:36:55 +00002380
Konstantin Zhuravlyovbb80d3e2017-07-11 22:23:00 +00002381If an atomic operation is marked ``syncscope("singlethread")``, it only
2382*synchronizes with* and only participates in the seq\_cst total orderings of
2383other operations running in the same thread (for example, in signal handlers).
2384
2385If an atomic operation is marked ``syncscope("<target-scope>")``, where
2386``<target-scope>`` is a target specific synchronization scope, then it is target
2387dependent if it *synchronizes with* and participates in the seq\_cst total
2388orderings of other operations.
2389
2390Otherwise, an atomic operation that is not marked ``syncscope("singlethread")``
2391or ``syncscope("<target-scope>")`` *synchronizes with* and participates in the
2392seq\_cst total orderings of other operations that are not marked
2393``syncscope("singlethread")`` or ``syncscope("<target-scope>")``.
Sean Silvab084af42012-12-07 10:36:55 +00002394
Sanjay Patel54b161e2018-03-20 16:38:22 +00002395.. _floatenv:
2396
2397Floating-Point Environment
2398--------------------------
2399
2400The default LLVM floating-point environment assumes that floating-point
2401instructions do not have side effects. Results assume the round-to-nearest
2402rounding mode. No floating-point exception state is maintained in this
2403environment. Therefore, there is no attempt to create or preserve invalid
Chandler Carruth297620d2018-08-06 02:02:09 +00002404operation (SNaN) or division-by-zero exceptions.
Sanjay Patel54b161e2018-03-20 16:38:22 +00002405
2406The benefit of this exception-free assumption is that floating-point
2407operations may be speculated freely without any other fast-math relaxations
2408to the floating-point model.
2409
2410Code that requires different behavior than this should use the
Sanjay Patelec95e0e2018-03-20 17:05:19 +00002411:ref:`Constrained Floating-Point Intrinsics <constrainedfp>`.
Sanjay Patel54b161e2018-03-20 16:38:22 +00002412
Sean Silvab084af42012-12-07 10:36:55 +00002413.. _fastmath:
2414
2415Fast-Math Flags
2416---------------
2417
Sanjay Patel629c4112017-11-06 16:27:15 +00002418LLVM IR floating-point operations (:ref:`fadd <i_fadd>`,
Sean Silvab084af42012-12-07 10:36:55 +00002419:ref:`fsub <i_fsub>`, :ref:`fmul <i_fmul>`, :ref:`fdiv <i_fdiv>`,
Matt Arsenault74b73e52017-01-10 18:06:38 +00002420:ref:`frem <i_frem>`, :ref:`fcmp <i_fcmp>`) and :ref:`call <i_call>`
Elena Demikhovsky945b7e52018-02-14 06:58:08 +00002421may use the following flags to enable otherwise unsafe
Sanjay Patel629c4112017-11-06 16:27:15 +00002422floating-point transformations.
Sean Silvab084af42012-12-07 10:36:55 +00002423
2424``nnan``
2425 No NaNs - Allow optimizations to assume the arguments and result are not
Eli Friedmand3a30872018-07-17 20:31:42 +00002426 NaN. If an argument is a nan, or the result would be a nan, it produces
2427 a :ref:`poison value <poisonvalues>` instead.
Sean Silvab084af42012-12-07 10:36:55 +00002428
2429``ninf``
2430 No Infs - Allow optimizations to assume the arguments and result are not
Eli Friedmand3a30872018-07-17 20:31:42 +00002431 +/-Inf. If an argument is +/-Inf, or the result would be +/-Inf, it
2432 produces a :ref:`poison value <poisonvalues>` instead.
Sean Silvab084af42012-12-07 10:36:55 +00002433
2434``nsz``
2435 No Signed Zeros - Allow optimizations to treat the sign of a zero
2436 argument or result as insignificant.
2437
2438``arcp``
2439 Allow Reciprocal - Allow optimizations to use the reciprocal of an
2440 argument rather than perform division.
2441
Adam Nemetcd847a82017-03-28 20:11:52 +00002442``contract``
2443 Allow floating-point contraction (e.g. fusing a multiply followed by an
2444 addition into a fused multiply-and-add).
2445
Sanjay Patel629c4112017-11-06 16:27:15 +00002446``afn``
2447 Approximate functions - Allow substitution of approximate calculations for
Elena Demikhovsky945b7e52018-02-14 06:58:08 +00002448 functions (sin, log, sqrt, etc). See floating-point intrinsic definitions
2449 for places where this can apply to LLVM's intrinsic math functions.
Sanjay Patel629c4112017-11-06 16:27:15 +00002450
2451``reassoc``
Elena Demikhovsky945b7e52018-02-14 06:58:08 +00002452 Allow reassociation transformations for floating-point instructions.
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00002453 This may dramatically change results in floating-point.
Sanjay Patel629c4112017-11-06 16:27:15 +00002454
Sean Silvab084af42012-12-07 10:36:55 +00002455``fast``
Sanjay Patel629c4112017-11-06 16:27:15 +00002456 This flag implies all of the others.
Sean Silvab084af42012-12-07 10:36:55 +00002457
Duncan P. N. Exon Smith0a448fb2014-08-19 21:30:15 +00002458.. _uselistorder:
2459
2460Use-list Order Directives
2461-------------------------
2462
2463Use-list directives encode the in-memory order of each use-list, allowing the
Sean Silvaa1190322015-08-06 22:56:48 +00002464order to be recreated. ``<order-indexes>`` is a comma-separated list of
2465indexes that are assigned to the referenced value's uses. The referenced
Duncan P. N. Exon Smith0a448fb2014-08-19 21:30:15 +00002466value's use-list is immediately sorted by these indexes.
2467
Sean Silvaa1190322015-08-06 22:56:48 +00002468Use-list directives may appear at function scope or global scope. They are not
2469instructions, and have no effect on the semantics of the IR. When they're at
Duncan P. N. Exon Smith0a448fb2014-08-19 21:30:15 +00002470function scope, they must appear after the terminator of the final basic block.
2471
2472If basic blocks have their address taken via ``blockaddress()`` expressions,
2473``uselistorder_bb`` can be used to reorder their use-lists from outside their
2474function's scope.
2475
2476:Syntax:
2477
2478::
2479
2480 uselistorder <ty> <value>, { <order-indexes> }
2481 uselistorder_bb @function, %block { <order-indexes> }
2482
2483:Examples:
2484
2485::
2486
Duncan P. N. Exon Smith23046652014-08-19 21:48:04 +00002487 define void @foo(i32 %arg1, i32 %arg2) {
2488 entry:
2489 ; ... instructions ...
2490 bb:
2491 ; ... instructions ...
2492
2493 ; At function scope.
2494 uselistorder i32 %arg1, { 1, 0, 2 }
2495 uselistorder label %bb, { 1, 0 }
2496 }
Duncan P. N. Exon Smith0a448fb2014-08-19 21:30:15 +00002497
2498 ; At global scope.
2499 uselistorder i32* @global, { 1, 2, 0 }
2500 uselistorder i32 7, { 1, 0 }
2501 uselistorder i32 (i32) @bar, { 1, 0 }
2502 uselistorder_bb @foo, %bb, { 5, 1, 3, 2, 0, 4 }
2503
Teresa Johnsonde9b8b42016-04-22 13:09:17 +00002504.. _source_filename:
2505
2506Source Filename
2507---------------
2508
2509The *source filename* string is set to the original module identifier,
2510which will be the name of the compiled source file when compiling from
2511source through the clang front end, for example. It is then preserved through
2512the IR and bitcode.
2513
2514This is currently necessary to generate a consistent unique global
2515identifier for local functions used in profile data, which prepends the
2516source file name to the local function name.
2517
2518The syntax for the source file name is simply:
2519
Renato Golin124f2592016-07-20 12:16:38 +00002520.. code-block:: text
Teresa Johnsonde9b8b42016-04-22 13:09:17 +00002521
2522 source_filename = "/path/to/source.c"
2523
Sean Silvab084af42012-12-07 10:36:55 +00002524.. _typesystem:
2525
2526Type System
2527===========
2528
2529The LLVM type system is one of the most important features of the
2530intermediate representation. Being typed enables a number of
2531optimizations to be performed on the intermediate representation
2532directly, without having to do extra analyses on the side before the
2533transformation. A strong type system makes it easier to read the
2534generated code and enables novel analyses and transformations that are
2535not feasible to perform on normal three address code representations.
2536
Rafael Espindola08013342013-12-07 19:34:20 +00002537.. _t_void:
Eli Bendersky0220e6b2013-06-07 20:24:43 +00002538
Rafael Espindola08013342013-12-07 19:34:20 +00002539Void Type
2540---------
Sean Silvab084af42012-12-07 10:36:55 +00002541
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002542:Overview:
2543
Rafael Espindola08013342013-12-07 19:34:20 +00002544
2545The void type does not represent any value and has no size.
2546
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002547:Syntax:
2548
Rafael Espindola08013342013-12-07 19:34:20 +00002549
2550::
2551
2552 void
Sean Silvab084af42012-12-07 10:36:55 +00002553
2554
Rafael Espindola08013342013-12-07 19:34:20 +00002555.. _t_function:
Sean Silvab084af42012-12-07 10:36:55 +00002556
Rafael Espindola08013342013-12-07 19:34:20 +00002557Function Type
2558-------------
Sean Silvab084af42012-12-07 10:36:55 +00002559
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002560:Overview:
2561
Sean Silvab084af42012-12-07 10:36:55 +00002562
Rafael Espindola08013342013-12-07 19:34:20 +00002563The function type can be thought of as a function signature. It consists of a
2564return type and a list of formal parameter types. The return type of a function
2565type is a void type or first class type --- except for :ref:`label <t_label>`
2566and :ref:`metadata <t_metadata>` types.
Sean Silvab084af42012-12-07 10:36:55 +00002567
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002568:Syntax:
Sean Silvab084af42012-12-07 10:36:55 +00002569
Rafael Espindola08013342013-12-07 19:34:20 +00002570::
Sean Silvab084af42012-12-07 10:36:55 +00002571
Rafael Espindola08013342013-12-07 19:34:20 +00002572 <returntype> (<parameter list>)
Sean Silvab084af42012-12-07 10:36:55 +00002573
Rafael Espindola08013342013-12-07 19:34:20 +00002574...where '``<parameter list>``' is a comma-separated list of type
2575specifiers. Optionally, the parameter list may include a type ``...``, which
Sean Silvaa1190322015-08-06 22:56:48 +00002576indicates that the function takes a variable number of arguments. Variable
Rafael Espindola08013342013-12-07 19:34:20 +00002577argument functions can access their arguments with the :ref:`variable argument
Sean Silvaa1190322015-08-06 22:56:48 +00002578handling intrinsic <int_varargs>` functions. '``<returntype>``' is any type
Rafael Espindola08013342013-12-07 19:34:20 +00002579except :ref:`label <t_label>` and :ref:`metadata <t_metadata>`.
Sean Silvab084af42012-12-07 10:36:55 +00002580
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002581:Examples:
Sean Silvab084af42012-12-07 10:36:55 +00002582
Rafael Espindola08013342013-12-07 19:34:20 +00002583+---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
2584| ``i32 (i32)`` | function taking an ``i32``, returning an ``i32`` |
2585+---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
2586| ``float (i16, i32 *) *`` | :ref:`Pointer <t_pointer>` to a function that takes an ``i16`` and a :ref:`pointer <t_pointer>` to ``i32``, returning ``float``. |
2587+---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
2588| ``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. |
2589+---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
2590| ``{i32, i32} (i32)`` | A function taking an ``i32``, returning a :ref:`structure <t_struct>` containing two ``i32`` values |
2591+---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
2592
2593.. _t_firstclass:
2594
2595First Class Types
2596-----------------
Sean Silvab084af42012-12-07 10:36:55 +00002597
2598The :ref:`first class <t_firstclass>` types are perhaps the most important.
2599Values of these types are the only ones which can be produced by
2600instructions.
2601
Rafael Espindola08013342013-12-07 19:34:20 +00002602.. _t_single_value:
Sean Silvab084af42012-12-07 10:36:55 +00002603
Rafael Espindola08013342013-12-07 19:34:20 +00002604Single Value Types
2605^^^^^^^^^^^^^^^^^^
Sean Silvab084af42012-12-07 10:36:55 +00002606
Rafael Espindola08013342013-12-07 19:34:20 +00002607These are the types that are valid in registers from CodeGen's perspective.
Sean Silvab084af42012-12-07 10:36:55 +00002608
2609.. _t_integer:
2610
2611Integer Type
Rafael Espindola08013342013-12-07 19:34:20 +00002612""""""""""""
Sean Silvab084af42012-12-07 10:36:55 +00002613
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002614:Overview:
Sean Silvab084af42012-12-07 10:36:55 +00002615
2616The integer type is a very simple type that simply specifies an
2617arbitrary bit width for the integer type desired. Any bit width from 1
2618bit to 2\ :sup:`23`\ -1 (about 8 million) can be specified.
2619
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002620:Syntax:
Sean Silvab084af42012-12-07 10:36:55 +00002621
2622::
2623
2624 iN
2625
2626The number of bits the integer will occupy is specified by the ``N``
2627value.
2628
2629Examples:
Rafael Espindola08013342013-12-07 19:34:20 +00002630*********
Sean Silvab084af42012-12-07 10:36:55 +00002631
2632+----------------+------------------------------------------------+
2633| ``i1`` | a single-bit integer. |
2634+----------------+------------------------------------------------+
2635| ``i32`` | a 32-bit integer. |
2636+----------------+------------------------------------------------+
2637| ``i1942652`` | a really big integer of over 1 million bits. |
2638+----------------+------------------------------------------------+
2639
2640.. _t_floating:
2641
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00002642Floating-Point Types
Rafael Espindola08013342013-12-07 19:34:20 +00002643""""""""""""""""""""
Sean Silvab084af42012-12-07 10:36:55 +00002644
2645.. list-table::
2646 :header-rows: 1
2647
2648 * - Type
2649 - Description
2650
2651 * - ``half``
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00002652 - 16-bit floating-point value
Sean Silvab084af42012-12-07 10:36:55 +00002653
2654 * - ``float``
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00002655 - 32-bit floating-point value
Sean Silvab084af42012-12-07 10:36:55 +00002656
2657 * - ``double``
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00002658 - 64-bit floating-point value
Sean Silvab084af42012-12-07 10:36:55 +00002659
2660 * - ``fp128``
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00002661 - 128-bit floating-point value (112-bit mantissa)
Sean Silvab084af42012-12-07 10:36:55 +00002662
2663 * - ``x86_fp80``
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00002664 - 80-bit floating-point value (X87)
Sean Silvab084af42012-12-07 10:36:55 +00002665
2666 * - ``ppc_fp128``
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00002667 - 128-bit floating-point value (two 64-bits)
Sean Silvab084af42012-12-07 10:36:55 +00002668
Sanjay Patelbab6ce02018-03-21 15:22:09 +00002669The binary format of half, float, double, and fp128 correspond to the
2670IEEE-754-2008 specifications for binary16, binary32, binary64, and binary128
2671respectively.
2672
Reid Kleckner9a16d082014-03-05 02:41:37 +00002673X86_mmx Type
2674""""""""""""
Sean Silvab084af42012-12-07 10:36:55 +00002675
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002676:Overview:
Sean Silvab084af42012-12-07 10:36:55 +00002677
Reid Kleckner9a16d082014-03-05 02:41:37 +00002678The x86_mmx type represents a value held in an MMX register on an x86
Sean Silvab084af42012-12-07 10:36:55 +00002679machine. The operations allowed on it are quite limited: parameters and
2680return values, load and store, and bitcast. User-specified MMX
2681instructions are represented as intrinsic or asm calls with arguments
2682and/or results of this type. There are no arrays, vectors or constants
2683of this type.
2684
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002685:Syntax:
Sean Silvab084af42012-12-07 10:36:55 +00002686
2687::
2688
Reid Kleckner9a16d082014-03-05 02:41:37 +00002689 x86_mmx
Sean Silvab084af42012-12-07 10:36:55 +00002690
Sean Silvab084af42012-12-07 10:36:55 +00002691
Rafael Espindola08013342013-12-07 19:34:20 +00002692.. _t_pointer:
2693
2694Pointer Type
2695""""""""""""
Sean Silvab084af42012-12-07 10:36:55 +00002696
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002697:Overview:
Sean Silvab084af42012-12-07 10:36:55 +00002698
Rafael Espindola08013342013-12-07 19:34:20 +00002699The pointer type is used to specify memory locations. Pointers are
2700commonly used to reference objects in memory.
2701
2702Pointer types may have an optional address space attribute defining the
2703numbered address space where the pointed-to object resides. The default
2704address space is number zero. The semantics of non-zero address spaces
2705are target-specific.
2706
2707Note that LLVM does not permit pointers to void (``void*``) nor does it
2708permit pointers to labels (``label*``). Use ``i8*`` instead.
Sean Silvab084af42012-12-07 10:36:55 +00002709
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002710:Syntax:
Sean Silvab084af42012-12-07 10:36:55 +00002711
2712::
2713
Rafael Espindola08013342013-12-07 19:34:20 +00002714 <type> *
2715
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002716:Examples:
Rafael Espindola08013342013-12-07 19:34:20 +00002717
2718+-------------------------+--------------------------------------------------------------------------------------------------------------+
2719| ``[4 x i32]*`` | A :ref:`pointer <t_pointer>` to :ref:`array <t_array>` of four ``i32`` values. |
2720+-------------------------+--------------------------------------------------------------------------------------------------------------+
2721| ``i32 (i32*) *`` | A :ref:`pointer <t_pointer>` to a :ref:`function <t_function>` that takes an ``i32*``, returning an ``i32``. |
2722+-------------------------+--------------------------------------------------------------------------------------------------------------+
2723| ``i32 addrspace(5)*`` | A :ref:`pointer <t_pointer>` to an ``i32`` value that resides in address space #5. |
2724+-------------------------+--------------------------------------------------------------------------------------------------------------+
2725
2726.. _t_vector:
2727
2728Vector Type
2729"""""""""""
2730
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002731:Overview:
Rafael Espindola08013342013-12-07 19:34:20 +00002732
2733A vector type is a simple derived type that represents a vector of
2734elements. Vector types are used when multiple primitive data are
2735operated in parallel using a single instruction (SIMD). A vector type
Nico Weber80fee252019-06-09 19:27:50 +00002736requires a size (number of elements) and an underlying primitive data
2737type. Vector types are considered :ref:`first class <t_firstclass>`.
Rafael Espindola08013342013-12-07 19:34:20 +00002738
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002739:Syntax:
Rafael Espindola08013342013-12-07 19:34:20 +00002740
2741::
2742
Nico Weber80fee252019-06-09 19:27:50 +00002743 < <# elements> x <elementtype> >
Rafael Espindola08013342013-12-07 19:34:20 +00002744
2745The number of elements is a constant integer value larger than 0;
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00002746elementtype may be any integer, floating-point or pointer type. Vectors
Nico Weber80fee252019-06-09 19:27:50 +00002747of size zero are not allowed.
Rafael Espindola08013342013-12-07 19:34:20 +00002748
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002749:Examples:
Rafael Espindola08013342013-12-07 19:34:20 +00002750
Nico Weber80fee252019-06-09 19:27:50 +00002751+-------------------+--------------------------------------------------+
2752| ``<4 x i32>`` | Vector of 4 32-bit integer values. |
2753+-------------------+--------------------------------------------------+
2754| ``<8 x float>`` | Vector of 8 32-bit floating-point values. |
2755+-------------------+--------------------------------------------------+
2756| ``<2 x i64>`` | Vector of 2 64-bit integer values. |
2757+-------------------+--------------------------------------------------+
2758| ``<4 x i64*>`` | Vector of 4 pointers to 64-bit integer values. |
2759+-------------------+--------------------------------------------------+
Sean Silvab084af42012-12-07 10:36:55 +00002760
2761.. _t_label:
2762
2763Label Type
2764^^^^^^^^^^
2765
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002766:Overview:
Sean Silvab084af42012-12-07 10:36:55 +00002767
2768The label type represents code labels.
2769
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002770:Syntax:
Sean Silvab084af42012-12-07 10:36:55 +00002771
2772::
2773
2774 label
2775
David Majnemerb611e3f2015-08-14 05:09:07 +00002776.. _t_token:
2777
2778Token Type
2779^^^^^^^^^^
2780
2781:Overview:
2782
2783The token type is used when a value is associated with an instruction
2784but all uses of the value must not attempt to introspect or obscure it.
2785As such, it is not appropriate to have a :ref:`phi <i_phi>` or
2786:ref:`select <i_select>` of type token.
2787
2788:Syntax:
2789
2790::
2791
2792 token
2793
2794
2795
Sean Silvab084af42012-12-07 10:36:55 +00002796.. _t_metadata:
2797
2798Metadata Type
2799^^^^^^^^^^^^^
2800
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002801:Overview:
Sean Silvab084af42012-12-07 10:36:55 +00002802
2803The metadata type represents embedded metadata. No derived types may be
2804created from metadata except for :ref:`function <t_function>` arguments.
2805
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002806:Syntax:
Sean Silvab084af42012-12-07 10:36:55 +00002807
2808::
2809
2810 metadata
2811
Sean Silvab084af42012-12-07 10:36:55 +00002812.. _t_aggregate:
2813
2814Aggregate Types
2815^^^^^^^^^^^^^^^
2816
2817Aggregate Types are a subset of derived types that can contain multiple
2818member types. :ref:`Arrays <t_array>` and :ref:`structs <t_struct>` are
2819aggregate types. :ref:`Vectors <t_vector>` are not considered to be
2820aggregate types.
2821
2822.. _t_array:
2823
2824Array Type
Rafael Espindola08013342013-12-07 19:34:20 +00002825""""""""""
Sean Silvab084af42012-12-07 10:36:55 +00002826
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002827:Overview:
Sean Silvab084af42012-12-07 10:36:55 +00002828
2829The array type is a very simple derived type that arranges elements
2830sequentially in memory. The array type requires a size (number of
2831elements) and an underlying data type.
2832
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002833:Syntax:
Sean Silvab084af42012-12-07 10:36:55 +00002834
2835::
2836
2837 [<# elements> x <elementtype>]
2838
2839The number of elements is a constant integer value; ``elementtype`` may
2840be any type with a size.
2841
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002842:Examples:
Sean Silvab084af42012-12-07 10:36:55 +00002843
2844+------------------+--------------------------------------+
2845| ``[40 x i32]`` | Array of 40 32-bit integer values. |
2846+------------------+--------------------------------------+
2847| ``[41 x i32]`` | Array of 41 32-bit integer values. |
2848+------------------+--------------------------------------+
2849| ``[4 x i8]`` | Array of 4 8-bit integer values. |
2850+------------------+--------------------------------------+
2851
2852Here are some examples of multidimensional arrays:
2853
2854+-----------------------------+----------------------------------------------------------+
2855| ``[3 x [4 x i32]]`` | 3x4 array of 32-bit integer values. |
2856+-----------------------------+----------------------------------------------------------+
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00002857| ``[12 x [10 x float]]`` | 12x10 array of single precision floating-point values. |
Sean Silvab084af42012-12-07 10:36:55 +00002858+-----------------------------+----------------------------------------------------------+
2859| ``[2 x [3 x [4 x i16]]]`` | 2x3x4 array of 16-bit integer values. |
2860+-----------------------------+----------------------------------------------------------+
2861
2862There is no restriction on indexing beyond the end of the array implied
2863by a static type (though there are restrictions on indexing beyond the
2864bounds of an allocated object in some cases). This means that
2865single-dimension 'variable sized array' addressing can be implemented in
2866LLVM with a zero length array type. An implementation of 'pascal style
2867arrays' in LLVM could use the type "``{ i32, [0 x float]}``", for
2868example.
2869
Sean Silvab084af42012-12-07 10:36:55 +00002870.. _t_struct:
2871
2872Structure Type
Rafael Espindola08013342013-12-07 19:34:20 +00002873""""""""""""""
Sean Silvab084af42012-12-07 10:36:55 +00002874
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002875:Overview:
Sean Silvab084af42012-12-07 10:36:55 +00002876
2877The structure type is used to represent a collection of data members
2878together in memory. The elements of a structure may be any type that has
2879a size.
2880
2881Structures in memory are accessed using '``load``' and '``store``' by
2882getting a pointer to a field with the '``getelementptr``' instruction.
2883Structures in registers are accessed using the '``extractvalue``' and
2884'``insertvalue``' instructions.
2885
2886Structures may optionally be "packed" structures, which indicate that
2887the alignment of the struct is one byte, and that there is no padding
2888between the elements. In non-packed structs, padding between field types
2889is inserted as defined by the DataLayout string in the module, which is
2890required to match what the underlying code generator expects.
2891
2892Structures can either be "literal" or "identified". A literal structure
2893is defined inline with other types (e.g. ``{i32, i32}*``) whereas
2894identified types are always defined at the top level with a name.
2895Literal types are uniqued by their contents and can never be recursive
2896or opaque since there is no way to write one. Identified types can be
2897recursive, can be opaqued, and are never uniqued.
2898
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002899:Syntax:
Sean Silvab084af42012-12-07 10:36:55 +00002900
2901::
2902
2903 %T1 = type { <type list> } ; Identified normal struct type
2904 %T2 = type <{ <type list> }> ; Identified packed struct type
2905
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002906:Examples:
Sean Silvab084af42012-12-07 10:36:55 +00002907
2908+------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
2909| ``{ i32, i32, i32 }`` | A triple of three ``i32`` values |
2910+------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
Daniel Dunbar1dc66ca2013-01-17 18:57:32 +00002911| ``{ 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 +00002912+------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
2913| ``<{ i8, i32 }>`` | A packed struct known to be 5 bytes in size. |
2914+------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
2915
2916.. _t_opaque:
2917
2918Opaque Structure Types
Rafael Espindola08013342013-12-07 19:34:20 +00002919""""""""""""""""""""""
Sean Silvab084af42012-12-07 10:36:55 +00002920
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002921:Overview:
Sean Silvab084af42012-12-07 10:36:55 +00002922
2923Opaque structure types are used to represent named structure types that
2924do not have a body specified. This corresponds (for example) to the C
2925notion of a forward declared structure.
2926
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002927:Syntax:
Sean Silvab084af42012-12-07 10:36:55 +00002928
2929::
2930
2931 %X = type opaque
2932 %52 = type opaque
2933
Rafael Espindola2f6d7b92013-12-10 14:53:22 +00002934:Examples:
Sean Silvab084af42012-12-07 10:36:55 +00002935
2936+--------------+-------------------+
2937| ``opaque`` | An opaque type. |
2938+--------------+-------------------+
2939
Sean Silva1703e702014-04-08 21:06:22 +00002940.. _constants:
2941
Sean Silvab084af42012-12-07 10:36:55 +00002942Constants
2943=========
2944
2945LLVM has several different basic types of constants. This section
2946describes them all and their syntax.
2947
2948Simple Constants
2949----------------
2950
2951**Boolean constants**
2952 The two strings '``true``' and '``false``' are both valid constants
2953 of the ``i1`` type.
2954**Integer constants**
2955 Standard integers (such as '4') are constants of the
2956 :ref:`integer <t_integer>` type. Negative numbers may be used with
2957 integer types.
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00002958**Floating-point constants**
2959 Floating-point constants use standard decimal notation (e.g.
Sean Silvab084af42012-12-07 10:36:55 +00002960 123.421), exponential notation (e.g. 1.23421e+2), or a more precise
2961 hexadecimal notation (see below). The assembler requires the exact
2962 decimal value of a floating-point constant. For example, the
2963 assembler accepts 1.25 but rejects 1.3 because 1.3 is a repeating
Mandeep Singh Grang547a0d72018-11-01 23:22:25 +00002964 decimal in binary. Floating-point constants must have a
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00002965 :ref:`floating-point <t_floating>` type.
Sean Silvab084af42012-12-07 10:36:55 +00002966**Null pointer constants**
2967 The identifier '``null``' is recognized as a null pointer constant
2968 and must be of :ref:`pointer type <t_pointer>`.
David Majnemerf0f224d2015-11-11 21:57:16 +00002969**Token constants**
2970 The identifier '``none``' is recognized as an empty token constant
2971 and must be of :ref:`token type <t_token>`.
Sean Silvab084af42012-12-07 10:36:55 +00002972
2973The one non-intuitive notation for constants is the hexadecimal form of
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00002974floating-point constants. For example, the form
Sean Silvab084af42012-12-07 10:36:55 +00002975'``double 0x432ff973cafa8000``' is equivalent to (but harder to read
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00002976than) '``double 4.5e+15``'. The only time hexadecimal floating-point
Sean Silvab084af42012-12-07 10:36:55 +00002977constants are required (and the only time that they are generated by the
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00002978disassembler) is when a floating-point constant must be emitted but it
2979cannot be represented as a decimal floating-point number in a reasonable
Sean Silvab084af42012-12-07 10:36:55 +00002980number of digits. For example, NaN's, infinities, and other special
2981values are represented in their IEEE hexadecimal format so that assembly
2982and disassembly do not cause any bits to change in the constants.
2983
2984When using the hexadecimal form, constants of types half, float, and
2985double are represented using the 16-digit form shown above (which
2986matches the IEEE754 representation for double); half and float values
Dmitri Gribenko4dc2ba12013-01-16 23:40:37 +00002987must, however, be exactly representable as IEEE 754 half and single
Sean Silvab084af42012-12-07 10:36:55 +00002988precision, respectively. Hexadecimal format is always used for long
2989double, and there are three forms of long double. The 80-bit format used
2990by x86 is represented as ``0xK`` followed by 20 hexadecimal digits. The
2991128-bit format used by PowerPC (two adjacent doubles) is represented by
2992``0xM`` followed by 32 hexadecimal digits. The IEEE 128-bit format is
Richard Sandifordae426b42013-05-03 14:32:27 +00002993represented by ``0xL`` followed by 32 hexadecimal digits. Long doubles
2994will only work if they match the long double format on your target.
2995The IEEE 16-bit format (half precision) is represented by ``0xH``
2996followed by 4 hexadecimal digits. All hexadecimal formats are big-endian
2997(sign bit at the left).
Sean Silvab084af42012-12-07 10:36:55 +00002998
Reid Kleckner9a16d082014-03-05 02:41:37 +00002999There are no constants of type x86_mmx.
Sean Silvab084af42012-12-07 10:36:55 +00003000
Eli Bendersky0220e6b2013-06-07 20:24:43 +00003001.. _complexconstants:
3002
Sean Silvab084af42012-12-07 10:36:55 +00003003Complex Constants
3004-----------------
3005
3006Complex constants are a (potentially recursive) combination of simple
3007constants and smaller complex constants.
3008
3009**Structure constants**
3010 Structure constants are represented with notation similar to
3011 structure type definitions (a comma separated list of elements,
3012 surrounded by braces (``{}``)). For example:
3013 "``{ i32 4, float 17.0, i32* @G }``", where "``@G``" is declared as
3014 "``@G = external global i32``". Structure constants must have
3015 :ref:`structure type <t_struct>`, and the number and types of elements
3016 must match those specified by the type.
3017**Array constants**
3018 Array constants are represented with notation similar to array type
3019 definitions (a comma separated list of elements, surrounded by
3020 square brackets (``[]``)). For example:
3021 "``[ i32 42, i32 11, i32 74 ]``". Array constants must have
3022 :ref:`array type <t_array>`, and the number and types of elements must
Daniel Sandersf6051842014-09-11 12:02:59 +00003023 match those specified by the type. As a special case, character array
3024 constants may also be represented as a double-quoted string using the ``c``
3025 prefix. For example: "``c"Hello World\0A\00"``".
Sean Silvab084af42012-12-07 10:36:55 +00003026**Vector constants**
3027 Vector constants are represented with notation similar to vector
3028 type definitions (a comma separated list of elements, surrounded by
3029 less-than/greater-than's (``<>``)). For example:
3030 "``< i32 42, i32 11, i32 74, i32 100 >``". Vector constants
3031 must have :ref:`vector type <t_vector>`, and the number and types of
3032 elements must match those specified by the type.
3033**Zero initialization**
3034 The string '``zeroinitializer``' can be used to zero initialize a
3035 value to zero of *any* type, including scalar and
3036 :ref:`aggregate <t_aggregate>` types. This is often used to avoid
3037 having to print large zero initializers (e.g. for large arrays) and
3038 is always exactly equivalent to using explicit zero initializers.
3039**Metadata node**
Sean Silvaa1190322015-08-06 22:56:48 +00003040 A metadata node is a constant tuple without types. For example:
3041 "``!{!0, !{!2, !0}, !"test"}``". Metadata can reference constant values,
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00003042 for example: "``!{!0, i32 0, i8* @global, i64 (i64)* @function, !"str"}``".
3043 Unlike other typed constants that are meant to be interpreted as part of
3044 the instruction stream, metadata is a place to attach additional
Sean Silvab084af42012-12-07 10:36:55 +00003045 information such as debug info.
3046
3047Global Variable and Function Addresses
3048--------------------------------------
3049
3050The addresses of :ref:`global variables <globalvars>` and
3051:ref:`functions <functionstructure>` are always implicitly valid
3052(link-time) constants. These constants are explicitly referenced when
3053the :ref:`identifier for the global <identifiers>` is used and always have
3054:ref:`pointer <t_pointer>` type. For example, the following is a legal LLVM
3055file:
3056
3057.. code-block:: llvm
3058
3059 @X = global i32 17
3060 @Y = global i32 42
3061 @Z = global [2 x i32*] [ i32* @X, i32* @Y ]
3062
3063.. _undefvalues:
3064
3065Undefined Values
3066----------------
3067
3068The string '``undef``' can be used anywhere a constant is expected, and
3069indicates that the user of the value may receive an unspecified
3070bit-pattern. Undefined values may be of any type (other than '``label``'
3071or '``void``') and be used anywhere a constant is permitted.
3072
3073Undefined values are useful because they indicate to the compiler that
3074the program is well defined no matter what value is used. This gives the
3075compiler more freedom to optimize. Here are some examples of
3076(potentially surprising) transformations that are valid (in pseudo IR):
3077
3078.. code-block:: llvm
3079
3080 %A = add %X, undef
3081 %B = sub %X, undef
3082 %C = xor %X, undef
3083 Safe:
3084 %A = undef
3085 %B = undef
3086 %C = undef
3087
3088This is safe because all of the output bits are affected by the undef
3089bits. Any output bit can have a zero or one depending on the input bits.
3090
3091.. code-block:: llvm
3092
3093 %A = or %X, undef
3094 %B = and %X, undef
3095 Safe:
3096 %A = -1
3097 %B = 0
Sanjoy Das151493a2016-09-15 01:56:58 +00003098 Safe:
3099 %A = %X ;; By choosing undef as 0
3100 %B = %X ;; By choosing undef as -1
Sean Silvab084af42012-12-07 10:36:55 +00003101 Unsafe:
3102 %A = undef
3103 %B = undef
3104
3105These logical operations have bits that are not always affected by the
3106input. For example, if ``%X`` has a zero bit, then the output of the
3107'``and``' operation will always be a zero for that bit, no matter what
3108the corresponding bit from the '``undef``' is. As such, it is unsafe to
3109optimize or assume that the result of the '``and``' is '``undef``'.
3110However, it is safe to assume that all bits of the '``undef``' could be
31110, and optimize the '``and``' to 0. Likewise, it is safe to assume that
3112all the bits of the '``undef``' operand to the '``or``' could be set,
3113allowing the '``or``' to be folded to -1.
3114
3115.. code-block:: llvm
3116
3117 %A = select undef, %X, %Y
3118 %B = select undef, 42, %Y
3119 %C = select %X, %Y, undef
3120 Safe:
3121 %A = %X (or %Y)
3122 %B = 42 (or %Y)
3123 %C = %Y
3124 Unsafe:
3125 %A = undef
3126 %B = undef
3127 %C = undef
3128
3129This set of examples shows that undefined '``select``' (and conditional
3130branch) conditions can go *either way*, but they have to come from one
3131of the two operands. In the ``%A`` example, if ``%X`` and ``%Y`` were
3132both known to have a clear low bit, then ``%A`` would have to have a
3133cleared low bit. However, in the ``%C`` example, the optimizer is
3134allowed to assume that the '``undef``' operand could be the same as
3135``%Y``, allowing the whole '``select``' to be eliminated.
3136
Renato Golin124f2592016-07-20 12:16:38 +00003137.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00003138
3139 %A = xor undef, undef
3140
3141 %B = undef
3142 %C = xor %B, %B
3143
3144 %D = undef
Jonathan Roelofsec81c0b2014-10-16 19:28:10 +00003145 %E = icmp slt %D, 4
Sean Silvab084af42012-12-07 10:36:55 +00003146 %F = icmp gte %D, 4
3147
3148 Safe:
3149 %A = undef
3150 %B = undef
3151 %C = undef
3152 %D = undef
3153 %E = undef
3154 %F = undef
3155
3156This example points out that two '``undef``' operands are not
3157necessarily the same. This can be surprising to people (and also matches
3158C semantics) where they assume that "``X^X``" is always zero, even if
3159``X`` is undefined. This isn't true for a number of reasons, but the
3160short answer is that an '``undef``' "variable" can arbitrarily change
3161its value over its "live range". This is true because the variable
3162doesn't actually *have a live range*. Instead, the value is logically
3163read from arbitrary registers that happen to be around when needed, so
3164the value is not necessarily consistent over time. In fact, ``%A`` and
3165``%C`` need to have the same semantics or the core LLVM "replace all
3166uses with" concept would not hold.
3167
3168.. code-block:: llvm
3169
Sanjay Patel3aaf6a02018-03-09 15:27:48 +00003170 %A = sdiv undef, %X
3171 %B = sdiv %X, undef
Sean Silvab084af42012-12-07 10:36:55 +00003172 Safe:
Sanjay Patel3aaf6a02018-03-09 15:27:48 +00003173 %A = 0
Sean Silvab084af42012-12-07 10:36:55 +00003174 b: unreachable
3175
3176These examples show the crucial difference between an *undefined value*
3177and *undefined behavior*. An undefined value (like '``undef``') is
3178allowed to have an arbitrary bit-pattern. This means that the ``%A``
Sanjay Patel3aaf6a02018-03-09 15:27:48 +00003179operation can be constant folded to '``0``', because the '``undef``'
3180could be zero, and zero divided by any value is zero.
Sean Silvab084af42012-12-07 10:36:55 +00003181However, in the second example, we can make a more aggressive
3182assumption: because the ``undef`` is allowed to be an arbitrary value,
3183we are allowed to assume that it could be zero. Since a divide by zero
3184has *undefined behavior*, we are allowed to assume that the operation
3185does not execute at all. This allows us to delete the divide and all
3186code after it. Because the undefined operation "can't happen", the
3187optimizer can assume that it occurs in dead code.
3188
Renato Golin124f2592016-07-20 12:16:38 +00003189.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00003190
3191 a: store undef -> %X
3192 b: store %X -> undef
3193 Safe:
3194 a: <deleted>
3195 b: unreachable
3196
Sanjay Patel7b722402018-03-07 17:18:22 +00003197A store *of* an undefined value can be assumed to not have any effect;
3198we can assume that the value is overwritten with bits that happen to
3199match what was already there. However, a store *to* an undefined
3200location could clobber arbitrary memory, therefore, it has undefined
3201behavior.
Sean Silvab084af42012-12-07 10:36:55 +00003202
3203.. _poisonvalues:
3204
3205Poison Values
3206-------------
3207
3208Poison values are similar to :ref:`undef values <undefvalues>`, however
3209they also represent the fact that an instruction or constant expression
Richard Smith32dbdf62014-07-31 04:25:36 +00003210that cannot evoke side effects has nevertheless detected a condition
3211that results in undefined behavior.
Sean Silvab084af42012-12-07 10:36:55 +00003212
3213There is currently no way of representing a poison value in the IR; they
3214only exist when produced by operations such as :ref:`add <i_add>` with
3215the ``nsw`` flag.
3216
3217Poison value behavior is defined in terms of value *dependence*:
3218
3219- Values other than :ref:`phi <i_phi>` nodes depend on their operands.
3220- :ref:`Phi <i_phi>` nodes depend on the operand corresponding to
3221 their dynamic predecessor basic block.
3222- Function arguments depend on the corresponding actual argument values
3223 in the dynamic callers of their functions.
3224- :ref:`Call <i_call>` instructions depend on the :ref:`ret <i_ret>`
3225 instructions that dynamically transfer control back to them.
3226- :ref:`Invoke <i_invoke>` instructions depend on the
3227 :ref:`ret <i_ret>`, :ref:`resume <i_resume>`, or exception-throwing
3228 call instructions that dynamically transfer control back to them.
3229- Non-volatile loads and stores depend on the most recent stores to all
3230 of the referenced memory addresses, following the order in the IR
3231 (including loads and stores implied by intrinsics such as
3232 :ref:`@llvm.memcpy <int_memcpy>`.)
3233- An instruction with externally visible side effects depends on the
3234 most recent preceding instruction with externally visible side
3235 effects, following the order in the IR. (This includes :ref:`volatile
3236 operations <volatile>`.)
3237- An instruction *control-depends* on a :ref:`terminator
3238 instruction <terminators>` if the terminator instruction has
3239 multiple successors and the instruction is always executed when
3240 control transfers to one of the successors, and may not be executed
3241 when control is transferred to another.
3242- Additionally, an instruction also *control-depends* on a terminator
3243 instruction if the set of instructions it otherwise depends on would
3244 be different if the terminator had transferred control to a different
3245 successor.
3246- Dependence is transitive.
3247
Richard Smith32dbdf62014-07-31 04:25:36 +00003248Poison values have the same behavior as :ref:`undef values <undefvalues>`,
3249with the additional effect that any instruction that has a *dependence*
Sean Silvab084af42012-12-07 10:36:55 +00003250on a poison value has undefined behavior.
3251
3252Here are some examples:
3253
3254.. code-block:: llvm
3255
3256 entry:
3257 %poison = sub nuw i32 0, 1 ; Results in a poison value.
3258 %still_poison = and i32 %poison, 0 ; 0, but also poison.
David Blaikie16a97eb2015-03-04 22:02:58 +00003259 %poison_yet_again = getelementptr i32, i32* @h, i32 %still_poison
Sean Silvab084af42012-12-07 10:36:55 +00003260 store i32 0, i32* %poison_yet_again ; memory at @h[0] is poisoned
3261
3262 store i32 %poison, i32* @g ; Poison value stored to memory.
David Blaikiec7aabbb2015-03-04 22:06:14 +00003263 %poison2 = load i32, i32* @g ; Poison value loaded back from memory.
Sean Silvab084af42012-12-07 10:36:55 +00003264
3265 store volatile i32 %poison, i32* @g ; External observation; undefined behavior.
3266
3267 %narrowaddr = bitcast i32* @g to i16*
3268 %wideaddr = bitcast i32* @g to i64*
David Blaikiec7aabbb2015-03-04 22:06:14 +00003269 %poison3 = load i16, i16* %narrowaddr ; Returns a poison value.
3270 %poison4 = load i64, i64* %wideaddr ; Returns a poison value.
Sean Silvab084af42012-12-07 10:36:55 +00003271
3272 %cmp = icmp slt i32 %poison, 0 ; Returns a poison value.
3273 br i1 %cmp, label %true, label %end ; Branch to either destination.
3274
3275 true:
3276 store volatile i32 0, i32* @g ; This is control-dependent on %cmp, so
3277 ; it has undefined behavior.
3278 br label %end
3279
3280 end:
3281 %p = phi i32 [ 0, %entry ], [ 1, %true ]
3282 ; Both edges into this PHI are
3283 ; control-dependent on %cmp, so this
3284 ; always results in a poison value.
3285
3286 store volatile i32 0, i32* @g ; This would depend on the store in %true
3287 ; if %cmp is true, or the store in %entry
3288 ; otherwise, so this is undefined behavior.
3289
3290 br i1 %cmp, label %second_true, label %second_end
3291 ; The same branch again, but this time the
3292 ; true block doesn't have side effects.
3293
3294 second_true:
3295 ; No side effects!
3296 ret void
3297
3298 second_end:
3299 store volatile i32 0, i32* @g ; This time, the instruction always depends
3300 ; on the store in %end. Also, it is
3301 ; control-equivalent to %end, so this is
3302 ; well-defined (ignoring earlier undefined
3303 ; behavior in this example).
3304
3305.. _blockaddress:
3306
3307Addresses of Basic Blocks
3308-------------------------
3309
3310``blockaddress(@function, %block)``
3311
3312The '``blockaddress``' constant computes the address of the specified
3313basic block in the specified function, and always has an ``i8*`` type.
3314Taking the address of the entry block is illegal.
3315
3316This value only has defined behavior when used as an operand to the
Craig Topper7a091ae2019-03-05 05:23:37 +00003317':ref:`indirectbr <i_indirectbr>`' or ':ref:`callbr <i_callbr>`'instruction, or
3318for comparisons against null. Pointer equality tests between labels addresses
3319results in undefined behavior --- though, again, comparison against null is ok,
3320and no label is equal to the null pointer. This may be passed around as an
Sean Silvab084af42012-12-07 10:36:55 +00003321opaque pointer sized value as long as the bits are not inspected. This
3322allows ``ptrtoint`` and arithmetic to be performed on these values so
Craig Topper7a091ae2019-03-05 05:23:37 +00003323long as the original value is reconstituted before the ``indirectbr`` or
3324``callbr`` instruction.
Sean Silvab084af42012-12-07 10:36:55 +00003325
3326Finally, some targets may provide defined semantics when using the value
3327as the operand to an inline assembly, but that is target specific.
3328
Eli Bendersky0220e6b2013-06-07 20:24:43 +00003329.. _constantexprs:
3330
Sean Silvab084af42012-12-07 10:36:55 +00003331Constant Expressions
3332--------------------
3333
3334Constant expressions are used to allow expressions involving other
3335constants to be used as constants. Constant expressions may be of any
3336:ref:`first class <t_firstclass>` type and may involve any LLVM operation
3337that does not have side effects (e.g. load and call are not supported).
3338The following is the syntax for constant expressions:
3339
3340``trunc (CST to TYPE)``
Bjorn Petterssone1285e32017-10-24 11:59:20 +00003341 Perform the :ref:`trunc operation <i_trunc>` on constants.
Sean Silvab084af42012-12-07 10:36:55 +00003342``zext (CST to TYPE)``
Bjorn Petterssone1285e32017-10-24 11:59:20 +00003343 Perform the :ref:`zext operation <i_zext>` on constants.
Sean Silvab084af42012-12-07 10:36:55 +00003344``sext (CST to TYPE)``
Bjorn Petterssone1285e32017-10-24 11:59:20 +00003345 Perform the :ref:`sext operation <i_sext>` on constants.
Sean Silvab084af42012-12-07 10:36:55 +00003346``fptrunc (CST to TYPE)``
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00003347 Truncate a floating-point constant to another floating-point type.
Sean Silvab084af42012-12-07 10:36:55 +00003348 The size of CST must be larger than the size of TYPE. Both types
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00003349 must be floating-point.
Sean Silvab084af42012-12-07 10:36:55 +00003350``fpext (CST to TYPE)``
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00003351 Floating-point extend a constant to another type. The size of CST
Sean Silvab084af42012-12-07 10:36:55 +00003352 must be smaller or equal to the size of TYPE. Both types must be
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00003353 floating-point.
Sean Silvab084af42012-12-07 10:36:55 +00003354``fptoui (CST to TYPE)``
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00003355 Convert a floating-point constant to the corresponding unsigned
Sean Silvab084af42012-12-07 10:36:55 +00003356 integer constant. TYPE must be a scalar or vector integer type. CST
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00003357 must be of scalar or vector floating-point type. Both CST and TYPE
Sean Silvab084af42012-12-07 10:36:55 +00003358 must be scalars, or vectors of the same number of elements. If the
Eli Friedmanc065bb22018-06-08 21:33:33 +00003359 value won't fit in the integer type, the result is a
3360 :ref:`poison value <poisonvalues>`.
Sean Silvab084af42012-12-07 10:36:55 +00003361``fptosi (CST to TYPE)``
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00003362 Convert a floating-point constant to the corresponding signed
Sean Silvab084af42012-12-07 10:36:55 +00003363 integer constant. TYPE must be a scalar or vector integer type. CST
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00003364 must be of scalar or vector floating-point type. Both CST and TYPE
Sean Silvab084af42012-12-07 10:36:55 +00003365 must be scalars, or vectors of the same number of elements. If the
Eli Friedmanc065bb22018-06-08 21:33:33 +00003366 value won't fit in the integer type, the result is a
3367 :ref:`poison value <poisonvalues>`.
Sean Silvab084af42012-12-07 10:36:55 +00003368``uitofp (CST to TYPE)``
Mandeep Singh Grang547a0d72018-11-01 23:22:25 +00003369 Convert an unsigned integer constant to the corresponding
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00003370 floating-point constant. TYPE must be a scalar or vector floating-point
3371 type. CST must be of scalar or vector integer type. Both CST and TYPE must
Eli Friedman3f1ce092018-06-14 22:58:48 +00003372 be scalars, or vectors of the same number of elements.
Sean Silvab084af42012-12-07 10:36:55 +00003373``sitofp (CST to TYPE)``
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00003374 Convert a signed integer constant to the corresponding floating-point
3375 constant. TYPE must be a scalar or vector floating-point type.
Sean Silvab084af42012-12-07 10:36:55 +00003376 CST must be of scalar or vector integer type. Both CST and TYPE must
Eli Friedman3f1ce092018-06-14 22:58:48 +00003377 be scalars, or vectors of the same number of elements.
Sean Silvab084af42012-12-07 10:36:55 +00003378``ptrtoint (CST to TYPE)``
Bjorn Petterssone1285e32017-10-24 11:59:20 +00003379 Perform the :ref:`ptrtoint operation <i_ptrtoint>` on constants.
Sean Silvab084af42012-12-07 10:36:55 +00003380``inttoptr (CST to TYPE)``
Bjorn Petterssone1285e32017-10-24 11:59:20 +00003381 Perform the :ref:`inttoptr operation <i_inttoptr>` on constants.
Sean Silvab084af42012-12-07 10:36:55 +00003382 This one is *really* dangerous!
3383``bitcast (CST to TYPE)``
Bjorn Petterssone1285e32017-10-24 11:59:20 +00003384 Convert a constant, CST, to another TYPE.
3385 The constraints of the operands are the same as those for the
3386 :ref:`bitcast instruction <i_bitcast>`.
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00003387``addrspacecast (CST to TYPE)``
3388 Convert a constant pointer or constant vector of pointer, CST, to another
3389 TYPE in a different address space. The constraints of the operands are the
3390 same as those for the :ref:`addrspacecast instruction <i_addrspacecast>`.
David Blaikief72d05b2015-03-13 18:20:45 +00003391``getelementptr (TY, CSTPTR, IDX0, IDX1, ...)``, ``getelementptr inbounds (TY, CSTPTR, IDX0, IDX1, ...)``
Sean Silvab084af42012-12-07 10:36:55 +00003392 Perform the :ref:`getelementptr operation <i_getelementptr>` on
3393 constants. As with the :ref:`getelementptr <i_getelementptr>`
David Blaikief91b0302017-06-19 05:34:21 +00003394 instruction, the index list may have one or more indexes, which are
David Blaikief72d05b2015-03-13 18:20:45 +00003395 required to make sense for the type of "pointer to TY".
Sean Silvab084af42012-12-07 10:36:55 +00003396``select (COND, VAL1, VAL2)``
3397 Perform the :ref:`select operation <i_select>` on constants.
3398``icmp COND (VAL1, VAL2)``
Bjorn Petterssone1285e32017-10-24 11:59:20 +00003399 Perform the :ref:`icmp operation <i_icmp>` on constants.
Sean Silvab084af42012-12-07 10:36:55 +00003400``fcmp COND (VAL1, VAL2)``
Bjorn Petterssone1285e32017-10-24 11:59:20 +00003401 Perform the :ref:`fcmp operation <i_fcmp>` on constants.
Sean Silvab084af42012-12-07 10:36:55 +00003402``extractelement (VAL, IDX)``
3403 Perform the :ref:`extractelement operation <i_extractelement>` on
3404 constants.
3405``insertelement (VAL, ELT, IDX)``
3406 Perform the :ref:`insertelement operation <i_insertelement>` on
3407 constants.
3408``shufflevector (VEC1, VEC2, IDXMASK)``
3409 Perform the :ref:`shufflevector operation <i_shufflevector>` on
3410 constants.
3411``extractvalue (VAL, IDX0, IDX1, ...)``
3412 Perform the :ref:`extractvalue operation <i_extractvalue>` on
3413 constants. The index list is interpreted in a similar manner as
3414 indices in a ':ref:`getelementptr <i_getelementptr>`' operation. At
3415 least one index value must be specified.
3416``insertvalue (VAL, ELT, IDX0, IDX1, ...)``
3417 Perform the :ref:`insertvalue operation <i_insertvalue>` on constants.
3418 The index list is interpreted in a similar manner as indices in a
3419 ':ref:`getelementptr <i_getelementptr>`' operation. At least one index
3420 value must be specified.
3421``OPCODE (LHS, RHS)``
3422 Perform the specified operation of the LHS and RHS constants. OPCODE
3423 may be any of the :ref:`binary <binaryops>` or :ref:`bitwise
3424 binary <bitwiseops>` operations. The constraints on operands are
3425 the same as those for the corresponding instruction (e.g. no bitwise
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00003426 operations on floating-point values are allowed).
Sean Silvab084af42012-12-07 10:36:55 +00003427
3428Other Values
3429============
3430
Eli Bendersky0220e6b2013-06-07 20:24:43 +00003431.. _inlineasmexprs:
3432
Sean Silvab084af42012-12-07 10:36:55 +00003433Inline Assembler Expressions
3434----------------------------
3435
3436LLVM supports inline assembler expressions (as opposed to :ref:`Module-Level
James Y Knightbc832ed2015-07-08 18:08:36 +00003437Inline Assembly <moduleasm>`) through the use of a special value. This value
3438represents the inline assembler as a template string (containing the
3439instructions to emit), a list of operand constraints (stored as a string), a
3440flag that indicates whether or not the inline asm expression has side effects,
3441and a flag indicating whether the function containing the asm needs to align its
3442stack conservatively.
3443
3444The template string supports argument substitution of the operands using "``$``"
3445followed by a number, to indicate substitution of the given register/memory
3446location, as specified by the constraint string. "``${NUM:MODIFIER}``" may also
3447be used, where ``MODIFIER`` is a target-specific annotation for how to print the
3448operand (See :ref:`inline-asm-modifiers`).
3449
3450A literal "``$``" may be included by using "``$$``" in the template. To include
3451other special characters into the output, the usual "``\XX``" escapes may be
3452used, just as in other strings. Note that after template substitution, the
3453resulting assembly string is parsed by LLVM's integrated assembler unless it is
3454disabled -- even when emitting a ``.s`` file -- and thus must contain assembly
3455syntax known to LLVM.
3456
Reid Kleckner71cb1642017-02-06 18:08:45 +00003457LLVM also supports a few more substitions useful for writing inline assembly:
3458
3459- ``${:uid}``: Expands to a decimal integer unique to this inline assembly blob.
3460 This substitution is useful when declaring a local label. Many standard
3461 compiler optimizations, such as inlining, may duplicate an inline asm blob.
3462 Adding a blob-unique identifier ensures that the two labels will not conflict
3463 during assembly. This is used to implement `GCC's %= special format
3464 string <https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html>`_.
3465- ``${:comment}``: Expands to the comment character of the current target's
3466 assembly dialect. This is usually ``#``, but many targets use other strings,
3467 such as ``;``, ``//``, or ``!``.
3468- ``${:private}``: Expands to the assembler private label prefix. Labels with
3469 this prefix will not appear in the symbol table of the assembled object.
3470 Typically the prefix is ``L``, but targets may use other strings. ``.L`` is
3471 relatively popular.
3472
James Y Knightbc832ed2015-07-08 18:08:36 +00003473LLVM's support for inline asm is modeled closely on the requirements of Clang's
3474GCC-compatible inline-asm support. Thus, the feature-set and the constraint and
3475modifier codes listed here are similar or identical to those in GCC's inline asm
3476support. However, to be clear, the syntax of the template and constraint strings
3477described here is *not* the same as the syntax accepted by GCC and Clang, and,
3478while most constraint letters are passed through as-is by Clang, some get
3479translated to other codes when converting from the C source to the LLVM
3480assembly.
3481
3482An example inline assembler expression is:
Sean Silvab084af42012-12-07 10:36:55 +00003483
3484.. code-block:: llvm
3485
3486 i32 (i32) asm "bswap $0", "=r,r"
3487
3488Inline assembler expressions may **only** be used as the callee operand
3489of a :ref:`call <i_call>` or an :ref:`invoke <i_invoke>` instruction.
3490Thus, typically we have:
3491
3492.. code-block:: llvm
3493
3494 %X = call i32 asm "bswap $0", "=r,r"(i32 %Y)
3495
3496Inline asms with side effects not visible in the constraint list must be
3497marked as having side effects. This is done through the use of the
3498'``sideeffect``' keyword, like so:
3499
3500.. code-block:: llvm
3501
3502 call void asm sideeffect "eieio", ""()
3503
3504In some cases inline asms will contain code that will not work unless
3505the stack is aligned in some way, such as calls or SSE instructions on
3506x86, yet will not contain code that does that alignment within the asm.
3507The compiler should make conservative assumptions about what the asm
3508might contain and should generate its usual stack alignment code in the
3509prologue if the '``alignstack``' keyword is present:
3510
3511.. code-block:: llvm
3512
3513 call void asm alignstack "eieio", ""()
3514
3515Inline asms also support using non-standard assembly dialects. The
3516assumed dialect is ATT. When the '``inteldialect``' keyword is present,
3517the inline asm is using the Intel dialect. Currently, ATT and Intel are
3518the only supported dialects. An example is:
3519
3520.. code-block:: llvm
3521
3522 call void asm inteldialect "eieio", ""()
3523
3524If multiple keywords appear the '``sideeffect``' keyword must come
3525first, the '``alignstack``' keyword second and the '``inteldialect``'
3526keyword last.
3527
James Y Knightbc832ed2015-07-08 18:08:36 +00003528Inline Asm Constraint String
3529^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3530
3531The constraint list is a comma-separated string, each element containing one or
3532more constraint codes.
3533
3534For each element in the constraint list an appropriate register or memory
3535operand will be chosen, and it will be made available to assembly template
3536string expansion as ``$0`` for the first constraint in the list, ``$1`` for the
3537second, etc.
3538
3539There are three different types of constraints, which are distinguished by a
3540prefix symbol in front of the constraint code: Output, Input, and Clobber. The
3541constraints must always be given in that order: outputs first, then inputs, then
3542clobbers. They cannot be intermingled.
3543
3544There are also three different categories of constraint codes:
3545
3546- Register constraint. This is either a register class, or a fixed physical
3547 register. This kind of constraint will allocate a register, and if necessary,
3548 bitcast the argument or result to the appropriate type.
3549- Memory constraint. This kind of constraint is for use with an instruction
3550 taking a memory operand. Different constraints allow for different addressing
3551 modes used by the target.
3552- Immediate value constraint. This kind of constraint is for an integer or other
3553 immediate value which can be rendered directly into an instruction. The
3554 various target-specific constraints allow the selection of a value in the
3555 proper range for the instruction you wish to use it with.
3556
3557Output constraints
3558""""""""""""""""""
3559
3560Output constraints are specified by an "``=``" prefix (e.g. "``=r``"). This
3561indicates that the assembly will write to this operand, and the operand will
3562then be made available as a return value of the ``asm`` expression. Output
3563constraints do not consume an argument from the call instruction. (Except, see
3564below about indirect outputs).
3565
3566Normally, it is expected that no output locations are written to by the assembly
3567expression until *all* of the inputs have been read. As such, LLVM may assign
3568the same register to an output and an input. If this is not safe (e.g. if the
3569assembly contains two instructions, where the first writes to one output, and
3570the second reads an input and writes to a second output), then the "``&``"
3571modifier must be used (e.g. "``=&r``") to specify that the output is an
Sylvestre Ledru84666a12016-02-14 20:16:22 +00003572"early-clobber" output. Marking an output as "early-clobber" ensures that LLVM
James Y Knightbc832ed2015-07-08 18:08:36 +00003573will not use the same register for any inputs (other than an input tied to this
3574output).
3575
3576Input constraints
3577"""""""""""""""""
3578
3579Input constraints do not have a prefix -- just the constraint codes. Each input
3580constraint will consume one argument from the call instruction. It is not
3581permitted for the asm to write to any input register or memory location (unless
3582that input is tied to an output). Note also that multiple inputs may all be
3583assigned to the same register, if LLVM can determine that they necessarily all
3584contain the same value.
3585
3586Instead of providing a Constraint Code, input constraints may also "tie"
3587themselves to an output constraint, by providing an integer as the constraint
3588string. Tied inputs still consume an argument from the call instruction, and
3589take up a position in the asm template numbering as is usual -- they will simply
3590be constrained to always use the same register as the output they've been tied
3591to. For example, a constraint string of "``=r,0``" says to assign a register for
3592output, and use that register as an input as well (it being the 0'th
3593constraint).
3594
3595It is permitted to tie an input to an "early-clobber" output. In that case, no
3596*other* input may share the same register as the input tied to the early-clobber
3597(even when the other input has the same value).
3598
3599You may only tie an input to an output which has a register constraint, not a
3600memory constraint. Only a single input may be tied to an output.
3601
3602There is also an "interesting" feature which deserves a bit of explanation: if a
3603register class constraint allocates a register which is too small for the value
3604type operand provided as input, the input value will be split into multiple
3605registers, and all of them passed to the inline asm.
3606
3607However, this feature is often not as useful as you might think.
3608
3609Firstly, the registers are *not* guaranteed to be consecutive. So, on those
3610architectures that have instructions which operate on multiple consecutive
3611instructions, this is not an appropriate way to support them. (e.g. the 32-bit
3612SparcV8 has a 64-bit load, which instruction takes a single 32-bit register. The
3613hardware then loads into both the named register, and the next register. This
3614feature of inline asm would not be useful to support that.)
3615
3616A few of the targets provide a template string modifier allowing explicit access
3617to the second register of a two-register operand (e.g. MIPS ``L``, ``M``, and
3618``D``). On such an architecture, you can actually access the second allocated
3619register (yet, still, not any subsequent ones). But, in that case, you're still
3620probably better off simply splitting the value into two separate operands, for
3621clarity. (e.g. see the description of the ``A`` constraint on X86, which,
3622despite existing only for use with this feature, is not really a good idea to
3623use)
3624
3625Indirect inputs and outputs
3626"""""""""""""""""""""""""""
3627
3628Indirect output or input constraints can be specified by the "``*``" modifier
3629(which goes after the "``=``" in case of an output). This indicates that the asm
3630will write to or read from the contents of an *address* provided as an input
3631argument. (Note that in this way, indirect outputs act more like an *input* than
3632an output: just like an input, they consume an argument of the call expression,
3633rather than producing a return value. An indirect output constraint is an
3634"output" only in that the asm is expected to write to the contents of the input
3635memory location, instead of just read from it).
3636
3637This is most typically used for memory constraint, e.g. "``=*m``", to pass the
3638address of a variable as a value.
3639
3640It is also possible to use an indirect *register* constraint, but only on output
3641(e.g. "``=*r``"). This will cause LLVM to allocate a register for an output
3642value normally, and then, separately emit a store to the address provided as
3643input, after the provided inline asm. (It's not clear what value this
3644functionality provides, compared to writing the store explicitly after the asm
3645statement, and it can only produce worse code, since it bypasses many
3646optimization passes. I would recommend not using it.)
3647
3648
3649Clobber constraints
3650"""""""""""""""""""
3651
3652A clobber constraint is indicated by a "``~``" prefix. A clobber does not
3653consume an input operand, nor generate an output. Clobbers cannot use any of the
3654general constraint code letters -- they may use only explicit register
3655constraints, e.g. "``~{eax}``". The one exception is that a clobber string of
3656"``~{memory}``" indicates that the assembly writes to arbitrary undeclared
3657memory locations -- not only the memory pointed to by a declared indirect
3658output.
3659
Peter Zotov00257232016-08-30 10:48:31 +00003660Note that clobbering named registers that are also present in output
3661constraints is not legal.
3662
James Y Knightbc832ed2015-07-08 18:08:36 +00003663
3664Constraint Codes
3665""""""""""""""""
3666After a potential prefix comes constraint code, or codes.
3667
3668A Constraint Code is either a single letter (e.g. "``r``"), a "``^``" character
3669followed by two letters (e.g. "``^wc``"), or "``{``" register-name "``}``"
3670(e.g. "``{eax}``").
3671
3672The one and two letter constraint codes are typically chosen to be the same as
3673GCC's constraint codes.
3674
3675A single constraint may include one or more than constraint code in it, leaving
3676it up to LLVM to choose which one to use. This is included mainly for
3677compatibility with the translation of GCC inline asm coming from clang.
3678
3679There are two ways to specify alternatives, and either or both may be used in an
3680inline asm constraint list:
3681
36821) Append the codes to each other, making a constraint code set. E.g. "``im``"
3683 or "``{eax}m``". This means "choose any of the options in the set". The
3684 choice of constraint is made independently for each constraint in the
3685 constraint list.
3686
36872) Use "``|``" between constraint code sets, creating alternatives. Every
3688 constraint in the constraint list must have the same number of alternative
3689 sets. With this syntax, the same alternative in *all* of the items in the
3690 constraint list will be chosen together.
3691
3692Putting those together, you might have a two operand constraint string like
3693``"rm|r,ri|rm"``. This indicates that if operand 0 is ``r`` or ``m``, then
3694operand 1 may be one of ``r`` or ``i``. If operand 0 is ``r``, then operand 1
3695may be one of ``r`` or ``m``. But, operand 0 and 1 cannot both be of type m.
3696
3697However, the use of either of the alternatives features is *NOT* recommended, as
3698LLVM is not able to make an intelligent choice about which one to use. (At the
3699point it currently needs to choose, not enough information is available to do so
3700in a smart way.) Thus, it simply tries to make a choice that's most likely to
3701compile, not one that will be optimal performance. (e.g., given "``rm``", it'll
3702always choose to use memory, not registers). And, if given multiple registers,
3703or multiple register classes, it will simply choose the first one. (In fact, it
3704doesn't currently even ensure explicitly specified physical registers are
3705unique, so specifying multiple physical registers as alternatives, like
3706``{r11}{r12},{r11}{r12}``, will assign r11 to both operands, not at all what was
3707intended.)
3708
3709Supported Constraint Code List
3710""""""""""""""""""""""""""""""
3711
3712The constraint codes are, in general, expected to behave the same way they do in
3713GCC. LLVM's support is often implemented on an 'as-needed' basis, to support C
3714inline asm code which was supported by GCC. A mismatch in behavior between LLVM
3715and GCC likely indicates a bug in LLVM.
3716
3717Some constraint codes are typically supported by all targets:
3718
3719- ``r``: A register in the target's general purpose register class.
3720- ``m``: A memory address operand. It is target-specific what addressing modes
3721 are supported, typical examples are register, or register + register offset,
3722 or register + immediate offset (of some target-specific size).
3723- ``i``: An integer constant (of target-specific width). Allows either a simple
3724 immediate, or a relocatable value.
3725- ``n``: An integer constant -- *not* including relocatable values.
3726- ``s``: An integer constant, but allowing *only* relocatable values.
3727- ``X``: Allows an operand of any kind, no constraint whatsoever. Typically
3728 useful to pass a label for an asm branch or call.
3729
3730 .. FIXME: but that surely isn't actually okay to jump out of an asm
3731 block without telling llvm about the control transfer???)
3732
3733- ``{register-name}``: Requires exactly the named physical register.
3734
3735Other constraints are target-specific:
3736
3737AArch64:
3738
3739- ``z``: An immediate integer 0. Outputs ``WZR`` or ``XZR``, as appropriate.
3740- ``I``: An immediate integer valid for an ``ADD`` or ``SUB`` instruction,
3741 i.e. 0 to 4095 with optional shift by 12.
3742- ``J``: An immediate integer that, when negated, is valid for an ``ADD`` or
3743 ``SUB`` instruction, i.e. -1 to -4095 with optional left shift by 12.
3744- ``K``: An immediate integer that is valid for the 'bitmask immediate 32' of a
3745 logical instruction like ``AND``, ``EOR``, or ``ORR`` with a 32-bit register.
3746- ``L``: An immediate integer that is valid for the 'bitmask immediate 64' of a
3747 logical instruction like ``AND``, ``EOR``, or ``ORR`` with a 64-bit register.
3748- ``M``: An immediate integer for use with the ``MOV`` assembly alias on a
3749 32-bit register. This is a superset of ``K``: in addition to the bitmask
3750 immediate, also allows immediate integers which can be loaded with a single
3751 ``MOVZ`` or ``MOVL`` instruction.
3752- ``N``: An immediate integer for use with the ``MOV`` assembly alias on a
3753 64-bit register. This is a superset of ``L``.
3754- ``Q``: Memory address operand must be in a single register (no
3755 offsets). (However, LLVM currently does this for the ``m`` constraint as
3756 well.)
3757- ``r``: A 32 or 64-bit integer register (W* or X*).
3758- ``w``: A 32, 64, or 128-bit floating-point/SIMD register.
3759- ``x``: A lower 128-bit floating-point/SIMD register (``V0`` to ``V15``).
3760
3761AMDGPU:
3762
3763- ``r``: A 32 or 64-bit integer register.
3764- ``[0-9]v``: The 32-bit VGPR register, number 0-9.
3765- ``[0-9]s``: The 32-bit SGPR register, number 0-9.
3766
3767
3768All ARM modes:
3769
3770- ``Q``, ``Um``, ``Un``, ``Uq``, ``Us``, ``Ut``, ``Uv``, ``Uy``: Memory address
3771 operand. Treated the same as operand ``m``, at the moment.
3772
3773ARM and ARM's Thumb2 mode:
3774
3775- ``j``: An immediate integer between 0 and 65535 (valid for ``MOVW``)
3776- ``I``: An immediate integer valid for a data-processing instruction.
3777- ``J``: An immediate integer between -4095 and 4095.
3778- ``K``: An immediate integer whose bitwise inverse is valid for a
3779 data-processing instruction. (Can be used with template modifier "``B``" to
3780 print the inverted value).
3781- ``L``: An immediate integer whose negation is valid for a data-processing
3782 instruction. (Can be used with template modifier "``n``" to print the negated
3783 value).
3784- ``M``: A power of two or a integer between 0 and 32.
3785- ``N``: Invalid immediate constraint.
3786- ``O``: Invalid immediate constraint.
3787- ``r``: A general-purpose 32-bit integer register (``r0-r15``).
3788- ``l``: In Thumb2 mode, low 32-bit GPR registers (``r0-r7``). In ARM mode, same
3789 as ``r``.
3790- ``h``: In Thumb2 mode, a high 32-bit GPR register (``r8-r15``). In ARM mode,
3791 invalid.
3792- ``w``: A 32, 64, or 128-bit floating-point/SIMD register: ``s0-s31``,
3793 ``d0-d31``, or ``q0-q15``.
3794- ``x``: A 32, 64, or 128-bit floating-point/SIMD register: ``s0-s15``,
3795 ``d0-d7``, or ``q0-q3``.
Pablo Barrioe28cb832018-02-15 14:44:22 +00003796- ``t``: A low floating-point/SIMD register: ``s0-s31``, ``d0-d16``, or
3797 ``q0-q8``.
James Y Knightbc832ed2015-07-08 18:08:36 +00003798
3799ARM's Thumb1 mode:
3800
3801- ``I``: An immediate integer between 0 and 255.
3802- ``J``: An immediate integer between -255 and -1.
3803- ``K``: An immediate integer between 0 and 255, with optional left-shift by
3804 some amount.
3805- ``L``: An immediate integer between -7 and 7.
3806- ``M``: An immediate integer which is a multiple of 4 between 0 and 1020.
3807- ``N``: An immediate integer between 0 and 31.
3808- ``O``: An immediate integer which is a multiple of 4 between -508 and 508.
3809- ``r``: A low 32-bit GPR register (``r0-r7``).
3810- ``l``: A low 32-bit GPR register (``r0-r7``).
3811- ``h``: A high GPR register (``r0-r7``).
3812- ``w``: A 32, 64, or 128-bit floating-point/SIMD register: ``s0-s31``,
3813 ``d0-d31``, or ``q0-q15``.
3814- ``x``: A 32, 64, or 128-bit floating-point/SIMD register: ``s0-s15``,
3815 ``d0-d7``, or ``q0-q3``.
Pablo Barrioe28cb832018-02-15 14:44:22 +00003816- ``t``: A low floating-point/SIMD register: ``s0-s31``, ``d0-d16``, or
3817 ``q0-q8``.
James Y Knightbc832ed2015-07-08 18:08:36 +00003818
3819
3820Hexagon:
3821
3822- ``o``, ``v``: A memory address operand, treated the same as constraint ``m``,
3823 at the moment.
3824- ``r``: A 32 or 64-bit register.
3825
3826MSP430:
3827
3828- ``r``: An 8 or 16-bit register.
3829
3830MIPS:
3831
3832- ``I``: An immediate signed 16-bit integer.
3833- ``J``: An immediate integer zero.
3834- ``K``: An immediate unsigned 16-bit integer.
3835- ``L``: An immediate 32-bit integer, where the lower 16 bits are 0.
3836- ``N``: An immediate integer between -65535 and -1.
3837- ``O``: An immediate signed 15-bit integer.
3838- ``P``: An immediate integer between 1 and 65535.
3839- ``m``: A memory address operand. In MIPS-SE mode, allows a base address
3840 register plus 16-bit immediate offset. In MIPS mode, just a base register.
3841- ``R``: A memory address operand. In MIPS-SE mode, allows a base address
3842 register plus a 9-bit signed offset. In MIPS mode, the same as constraint
3843 ``m``.
3844- ``ZC``: A memory address operand, suitable for use in a ``pref``, ``ll``, or
3845 ``sc`` instruction on the given subtarget (details vary).
3846- ``r``, ``d``, ``y``: A 32 or 64-bit GPR register.
3847- ``f``: A 32 or 64-bit FPU register (``F0-F31``), or a 128-bit MSA register
Daniel Sanders3745e022015-07-13 09:24:21 +00003848 (``W0-W31``). In the case of MSA registers, it is recommended to use the ``w``
3849 argument modifier for compatibility with GCC.
James Y Knightbc832ed2015-07-08 18:08:36 +00003850- ``c``: A 32-bit or 64-bit GPR register suitable for indirect jump (always
3851 ``25``).
3852- ``l``: The ``lo`` register, 32 or 64-bit.
3853- ``x``: Invalid.
3854
3855NVPTX:
3856
3857- ``b``: A 1-bit integer register.
3858- ``c`` or ``h``: A 16-bit integer register.
3859- ``r``: A 32-bit integer register.
3860- ``l`` or ``N``: A 64-bit integer register.
3861- ``f``: A 32-bit float register.
3862- ``d``: A 64-bit float register.
3863
3864
3865PowerPC:
3866
3867- ``I``: An immediate signed 16-bit integer.
3868- ``J``: An immediate unsigned 16-bit integer, shifted left 16 bits.
3869- ``K``: An immediate unsigned 16-bit integer.
3870- ``L``: An immediate signed 16-bit integer, shifted left 16 bits.
3871- ``M``: An immediate integer greater than 31.
3872- ``N``: An immediate integer that is an exact power of 2.
3873- ``O``: The immediate integer constant 0.
3874- ``P``: An immediate integer constant whose negation is a signed 16-bit
3875 constant.
3876- ``es``, ``o``, ``Q``, ``Z``, ``Zy``: A memory address operand, currently
3877 treated the same as ``m``.
3878- ``r``: A 32 or 64-bit integer register.
3879- ``b``: A 32 or 64-bit integer register, excluding ``R0`` (that is:
3880 ``R1-R31``).
3881- ``f``: A 32 or 64-bit float register (``F0-F31``), or when QPX is enabled, a
3882 128 or 256-bit QPX register (``Q0-Q31``; aliases the ``F`` registers).
3883- ``v``: For ``4 x f32`` or ``4 x f64`` types, when QPX is enabled, a
3884 128 or 256-bit QPX register (``Q0-Q31``), otherwise a 128-bit
3885 altivec vector register (``V0-V31``).
3886
3887 .. FIXME: is this a bug that v accepts QPX registers? I think this
3888 is supposed to only use the altivec vector registers?
3889
3890- ``y``: Condition register (``CR0-CR7``).
3891- ``wc``: An individual CR bit in a CR register.
3892- ``wa``, ``wd``, ``wf``: Any 128-bit VSX vector register, from the full VSX
3893 register set (overlapping both the floating-point and vector register files).
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00003894- ``ws``: A 32 or 64-bit floating-point register, from the full VSX register
James Y Knightbc832ed2015-07-08 18:08:36 +00003895 set.
3896
3897Sparc:
3898
3899- ``I``: An immediate 13-bit signed integer.
3900- ``r``: A 32-bit integer register.
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00003901- ``f``: Any floating-point register on SparcV8, or a floating-point
James Y Knightd4e1b002017-05-12 15:59:10 +00003902 register in the "low" half of the registers on SparcV9.
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00003903- ``e``: Any floating-point register. (Same as ``f`` on SparcV8.)
James Y Knightbc832ed2015-07-08 18:08:36 +00003904
3905SystemZ:
3906
3907- ``I``: An immediate unsigned 8-bit integer.
3908- ``J``: An immediate unsigned 12-bit integer.
3909- ``K``: An immediate signed 16-bit integer.
3910- ``L``: An immediate signed 20-bit integer.
3911- ``M``: An immediate integer 0x7fffffff.
Ulrich Weiganddaae87aa2016-06-13 14:24:05 +00003912- ``Q``: A memory address operand with a base address and a 12-bit immediate
3913 unsigned displacement.
3914- ``R``: A memory address operand with a base address, a 12-bit immediate
3915 unsigned displacement, and an index register.
3916- ``S``: A memory address operand with a base address and a 20-bit immediate
3917 signed displacement.
3918- ``T``: A memory address operand with a base address, a 20-bit immediate
3919 signed displacement, and an index register.
James Y Knightbc832ed2015-07-08 18:08:36 +00003920- ``r`` or ``d``: A 32, 64, or 128-bit integer register.
3921- ``a``: A 32, 64, or 128-bit integer address register (excludes R0, which in an
3922 address context evaluates as zero).
3923- ``h``: A 32-bit value in the high part of a 64bit data register
3924 (LLVM-specific)
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00003925- ``f``: A 32, 64, or 128-bit floating-point register.
James Y Knightbc832ed2015-07-08 18:08:36 +00003926
3927X86:
3928
3929- ``I``: An immediate integer between 0 and 31.
3930- ``J``: An immediate integer between 0 and 64.
3931- ``K``: An immediate signed 8-bit integer.
3932- ``L``: An immediate integer, 0xff or 0xffff or (in 64-bit mode only)
3933 0xffffffff.
3934- ``M``: An immediate integer between 0 and 3.
3935- ``N``: An immediate unsigned 8-bit integer.
3936- ``O``: An immediate integer between 0 and 127.
3937- ``e``: An immediate 32-bit signed integer.
3938- ``Z``: An immediate 32-bit unsigned integer.
3939- ``o``, ``v``: Treated the same as ``m``, at the moment.
3940- ``q``: An 8, 16, 32, or 64-bit register which can be accessed as an 8-bit
3941 ``l`` integer register. On X86-32, this is the ``a``, ``b``, ``c``, and ``d``
3942 registers, and on X86-64, it is all of the integer registers.
3943- ``Q``: An 8, 16, 32, or 64-bit register which can be accessed as an 8-bit
3944 ``h`` integer register. This is the ``a``, ``b``, ``c``, and ``d`` registers.
3945- ``r`` or ``l``: An 8, 16, 32, or 64-bit integer register.
3946- ``R``: An 8, 16, 32, or 64-bit "legacy" integer register -- one which has
3947 existed since i386, and can be accessed without the REX prefix.
3948- ``f``: A 32, 64, or 80-bit '387 FPU stack pseudo-register.
3949- ``y``: A 64-bit MMX register, if MMX is enabled.
3950- ``x``: If SSE is enabled: a 32 or 64-bit scalar operand, or 128-bit vector
3951 operand in a SSE register. If AVX is also enabled, can also be a 256-bit
3952 vector operand in an AVX register. If AVX-512 is also enabled, can also be a
3953 512-bit vector operand in an AVX512 register, Otherwise, an error.
3954- ``Y``: The same as ``x``, if *SSE2* is enabled, otherwise an error.
3955- ``A``: Special case: allocates EAX first, then EDX, for a single operand (in
3956 32-bit mode, a 64-bit integer operand will get split into two registers). It
3957 is not recommended to use this constraint, as in 64-bit mode, the 64-bit
3958 operand will get allocated only to RAX -- if two 32-bit operands are needed,
3959 you're better off splitting it yourself, before passing it to the asm
3960 statement.
3961
3962XCore:
3963
3964- ``r``: A 32-bit integer register.
3965
3966
3967.. _inline-asm-modifiers:
3968
3969Asm template argument modifiers
3970^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3971
3972In the asm template string, modifiers can be used on the operand reference, like
3973"``${0:n}``".
3974
3975The modifiers are, in general, expected to behave the same way they do in
3976GCC. LLVM's support is often implemented on an 'as-needed' basis, to support C
3977inline asm code which was supported by GCC. A mismatch in behavior between LLVM
3978and GCC likely indicates a bug in LLVM.
3979
3980Target-independent:
3981
Sean Silvaa1190322015-08-06 22:56:48 +00003982- ``c``: Print an immediate integer constant unadorned, without
James Y Knightbc832ed2015-07-08 18:08:36 +00003983 the target-specific immediate punctuation (e.g. no ``$`` prefix).
3984- ``n``: Negate and print immediate integer constant unadorned, without the
3985 target-specific immediate punctuation (e.g. no ``$`` prefix).
3986- ``l``: Print as an unadorned label, without the target-specific label
3987 punctuation (e.g. no ``$`` prefix).
3988
3989AArch64:
3990
3991- ``w``: Print a GPR register with a ``w*`` name instead of ``x*`` name. E.g.,
3992 instead of ``x30``, print ``w30``.
3993- ``x``: Print a GPR register with a ``x*`` name. (this is the default, anyhow).
3994- ``b``, ``h``, ``s``, ``d``, ``q``: Print a floating-point/SIMD register with a
3995 ``b*``, ``h*``, ``s*``, ``d*``, or ``q*`` name, rather than the default of
3996 ``v*``.
3997
3998AMDGPU:
3999
4000- ``r``: No effect.
4001
4002ARM:
4003
4004- ``a``: Print an operand as an address (with ``[`` and ``]`` surrounding a
4005 register).
4006- ``P``: No effect.
4007- ``q``: No effect.
4008- ``y``: Print a VFP single-precision register as an indexed double (e.g. print
4009 as ``d4[1]`` instead of ``s9``)
4010- ``B``: Bitwise invert and print an immediate integer constant without ``#``
4011 prefix.
4012- ``L``: Print the low 16-bits of an immediate integer constant.
4013- ``M``: Print as a register set suitable for ldm/stm. Also prints *all*
4014 register operands subsequent to the specified one (!), so use carefully.
4015- ``Q``: Print the low-order register of a register-pair, or the low-order
4016 register of a two-register operand.
4017- ``R``: Print the high-order register of a register-pair, or the high-order
4018 register of a two-register operand.
4019- ``H``: Print the second register of a register-pair. (On a big-endian system,
4020 ``H`` is equivalent to ``Q``, and on little-endian system, ``H`` is equivalent
4021 to ``R``.)
4022
4023 .. FIXME: H doesn't currently support printing the second register
4024 of a two-register operand.
4025
4026- ``e``: Print the low doubleword register of a NEON quad register.
4027- ``f``: Print the high doubleword register of a NEON quad register.
4028- ``m``: Print the base register of a memory operand without the ``[`` and ``]``
4029 adornment.
4030
4031Hexagon:
4032
4033- ``L``: Print the second register of a two-register operand. Requires that it
4034 has been allocated consecutively to the first.
4035
4036 .. FIXME: why is it restricted to consecutive ones? And there's
4037 nothing that ensures that happens, is there?
4038
4039- ``I``: Print the letter 'i' if the operand is an integer constant, otherwise
4040 nothing. Used to print 'addi' vs 'add' instructions.
4041
4042MSP430:
4043
4044No additional modifiers.
4045
4046MIPS:
4047
4048- ``X``: Print an immediate integer as hexadecimal
4049- ``x``: Print the low 16 bits of an immediate integer as hexadecimal.
4050- ``d``: Print an immediate integer as decimal.
4051- ``m``: Subtract one and print an immediate integer as decimal.
4052- ``z``: Print $0 if an immediate zero, otherwise print normally.
4053- ``L``: Print the low-order register of a two-register operand, or prints the
4054 address of the low-order word of a double-word memory operand.
4055
4056 .. FIXME: L seems to be missing memory operand support.
4057
4058- ``M``: Print the high-order register of a two-register operand, or prints the
4059 address of the high-order word of a double-word memory operand.
4060
4061 .. FIXME: M seems to be missing memory operand support.
4062
4063- ``D``: Print the second register of a two-register operand, or prints the
4064 second word of a double-word memory operand. (On a big-endian system, ``D`` is
4065 equivalent to ``L``, and on little-endian system, ``D`` is equivalent to
4066 ``M``.)
Daniel Sanders3745e022015-07-13 09:24:21 +00004067- ``w``: No effect. Provided for compatibility with GCC which requires this
4068 modifier in order to print MSA registers (``W0-W31``) with the ``f``
4069 constraint.
James Y Knightbc832ed2015-07-08 18:08:36 +00004070
4071NVPTX:
4072
4073- ``r``: No effect.
4074
4075PowerPC:
4076
4077- ``L``: Print the second register of a two-register operand. Requires that it
4078 has been allocated consecutively to the first.
4079
4080 .. FIXME: why is it restricted to consecutive ones? And there's
4081 nothing that ensures that happens, is there?
4082
4083- ``I``: Print the letter 'i' if the operand is an integer constant, otherwise
4084 nothing. Used to print 'addi' vs 'add' instructions.
4085- ``y``: For a memory operand, prints formatter for a two-register X-form
4086 instruction. (Currently always prints ``r0,OPERAND``).
4087- ``U``: Prints 'u' if the memory operand is an update form, and nothing
4088 otherwise. (NOTE: LLVM does not support update form, so this will currently
4089 always print nothing)
4090- ``X``: Prints 'x' if the memory operand is an indexed form. (NOTE: LLVM does
4091 not support indexed form, so this will currently always print nothing)
4092
4093Sparc:
4094
4095- ``r``: No effect.
4096
4097SystemZ:
4098
4099SystemZ implements only ``n``, and does *not* support any of the other
4100target-independent modifiers.
4101
4102X86:
4103
4104- ``c``: Print an unadorned integer or symbol name. (The latter is
4105 target-specific behavior for this typically target-independent modifier).
4106- ``A``: Print a register name with a '``*``' before it.
4107- ``b``: Print an 8-bit register name (e.g. ``al``); do nothing on a memory
4108 operand.
4109- ``h``: Print the upper 8-bit register name (e.g. ``ah``); do nothing on a
4110 memory operand.
4111- ``w``: Print the 16-bit register name (e.g. ``ax``); do nothing on a memory
4112 operand.
4113- ``k``: Print the 32-bit register name (e.g. ``eax``); do nothing on a memory
4114 operand.
4115- ``q``: Print the 64-bit register name (e.g. ``rax``), if 64-bit registers are
4116 available, otherwise the 32-bit register name; do nothing on a memory operand.
4117- ``n``: Negate and print an unadorned integer, or, for operands other than an
4118 immediate integer (e.g. a relocatable symbol expression), print a '-' before
4119 the operand. (The behavior for relocatable symbol expressions is a
4120 target-specific behavior for this typically target-independent modifier)
4121- ``H``: Print a memory reference with additional offset +8.
4122- ``P``: Print a memory reference or operand for use as the argument of a call
4123 instruction. (E.g. omit ``(rip)``, even though it's PC-relative.)
4124
4125XCore:
4126
4127No additional modifiers.
4128
4129
Sean Silvab084af42012-12-07 10:36:55 +00004130Inline Asm Metadata
4131^^^^^^^^^^^^^^^^^^^
4132
4133The call instructions that wrap inline asm nodes may have a
4134"``!srcloc``" MDNode attached to it that contains a list of constant
4135integers. If present, the code generator will use the integer as the
4136location cookie value when report errors through the ``LLVMContext``
4137error reporting mechanisms. This allows a front-end to correlate backend
4138errors that occur with inline asm back to the source code that produced
4139it. For example:
4140
4141.. code-block:: llvm
4142
4143 call void asm sideeffect "something bad", ""(), !srcloc !42
4144 ...
4145 !42 = !{ i32 1234567 }
4146
4147It is up to the front-end to make sense of the magic numbers it places
4148in the IR. If the MDNode contains multiple constants, the code generator
4149will use the one that corresponds to the line of the asm that the error
4150occurs on.
4151
4152.. _metadata:
4153
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00004154Metadata
4155========
Sean Silvab084af42012-12-07 10:36:55 +00004156
4157LLVM IR allows metadata to be attached to instructions in the program
4158that can convey extra information about the code to the optimizers and
4159code generator. One example application of metadata is source-level
4160debug information. There are two metadata primitives: strings and nodes.
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00004161
Sean Silvaa1190322015-08-06 22:56:48 +00004162Metadata does not have a type, and is not a value. If referenced from a
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00004163``call`` instruction, it uses the ``metadata`` type.
4164
4165All metadata are identified in syntax by a exclamation point ('``!``').
4166
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004167.. _metadata-string:
4168
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00004169Metadata Nodes and Metadata Strings
4170-----------------------------------
Sean Silvab084af42012-12-07 10:36:55 +00004171
4172A metadata string is a string surrounded by double quotes. It can
4173contain any character by escaping non-printable characters with
4174"``\xx``" where "``xx``" is the two digit hex code. For example:
4175"``!"test\00"``".
4176
4177Metadata nodes are represented with notation similar to structure
4178constants (a comma separated list of elements, surrounded by braces and
4179preceded by an exclamation point). Metadata nodes can have any values as
4180their operand. For example:
4181
4182.. code-block:: llvm
4183
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00004184 !{ !"test\00", i32 10}
Sean Silvab084af42012-12-07 10:36:55 +00004185
Duncan P. N. Exon Smith090a19b2015-01-08 22:38:29 +00004186Metadata nodes that aren't uniqued use the ``distinct`` keyword. For example:
4187
Renato Golin124f2592016-07-20 12:16:38 +00004188.. code-block:: text
Duncan P. N. Exon Smith090a19b2015-01-08 22:38:29 +00004189
4190 !0 = distinct !{!"test\00", i32 10}
4191
Duncan P. N. Exon Smith99010342015-01-08 23:50:26 +00004192``distinct`` nodes are useful when nodes shouldn't be merged based on their
Sean Silvaa1190322015-08-06 22:56:48 +00004193content. They can also occur when transformations cause uniquing collisions
Duncan P. N. Exon Smith99010342015-01-08 23:50:26 +00004194when metadata operands change.
4195
Sean Silvab084af42012-12-07 10:36:55 +00004196A :ref:`named metadata <namedmetadatastructure>` is a collection of
4197metadata nodes, which can be looked up in the module symbol table. For
4198example:
4199
4200.. code-block:: llvm
4201
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00004202 !foo = !{!4, !3}
Sean Silvab084af42012-12-07 10:36:55 +00004203
Adrian Prantl1b842da2017-07-28 20:44:29 +00004204Metadata can be used as function arguments. Here the ``llvm.dbg.value``
4205intrinsic is using three metadata arguments:
Sean Silvab084af42012-12-07 10:36:55 +00004206
4207.. code-block:: llvm
4208
Adrian Prantlabe04752017-07-28 20:21:02 +00004209 call void @llvm.dbg.value(metadata !24, metadata !25, metadata !26)
Sean Silvab084af42012-12-07 10:36:55 +00004210
Peter Collingbourne50108682015-11-06 02:41:02 +00004211Metadata can be attached to an instruction. Here metadata ``!21`` is attached
4212to the ``add`` instruction using the ``!dbg`` identifier:
Sean Silvab084af42012-12-07 10:36:55 +00004213
4214.. code-block:: llvm
4215
4216 %indvar.next = add i64 %indvar, 1, !dbg !21
4217
Peter Collingbourne7b5b7c72017-01-25 21:50:14 +00004218Metadata can also be attached to a function or a global variable. Here metadata
4219``!22`` is attached to the ``f1`` and ``f2 functions, and the globals ``g1``
4220and ``g2`` using the ``!dbg`` identifier:
Peter Collingbourne50108682015-11-06 02:41:02 +00004221
4222.. code-block:: llvm
4223
Peter Collingbourne7b5b7c72017-01-25 21:50:14 +00004224 declare !dbg !22 void @f1()
4225 define void @f2() !dbg !22 {
Peter Collingbourne50108682015-11-06 02:41:02 +00004226 ret void
4227 }
4228
Peter Collingbourne7b5b7c72017-01-25 21:50:14 +00004229 @g1 = global i32 0, !dbg !22
4230 @g2 = external global i32, !dbg !22
4231
4232A transformation is required to drop any metadata attachment that it does not
4233know or know it can't preserve. Currently there is an exception for metadata
4234attachment to globals for ``!type`` and ``!absolute_symbol`` which can't be
4235unconditionally dropped unless the global is itself deleted.
4236
4237Metadata attached to a module using named metadata may not be dropped, with
4238the exception of debug metadata (named metadata with the name ``!llvm.dbg.*``).
4239
Sean Silvab084af42012-12-07 10:36:55 +00004240More information about specific metadata nodes recognized by the
4241optimizers and code generator is found below.
4242
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004243.. _specialized-metadata:
4244
Duncan P. N. Exon Smith6a484832015-01-13 21:10:44 +00004245Specialized Metadata Nodes
4246^^^^^^^^^^^^^^^^^^^^^^^^^^
4247
4248Specialized metadata nodes are custom data structures in metadata (as opposed
Sean Silvaa1190322015-08-06 22:56:48 +00004249to generic tuples). Their fields are labelled, and can be specified in any
Duncan P. N. Exon Smith6a484832015-01-13 21:10:44 +00004250order.
4251
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004252These aren't inherently debug info centric, but currently all the specialized
4253metadata nodes are related to debug info.
4254
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004255.. _DICompileUnit:
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004256
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004257DICompileUnit
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004258"""""""""""""
4259
Sean Silvaa1190322015-08-06 22:56:48 +00004260``DICompileUnit`` nodes represent a compile unit. The ``enums:``,
Adrian Prantl6c2497f2017-06-12 23:59:43 +00004261``retainedTypes:``, ``globals:``, ``imports:`` and ``macros:`` fields are tuples
4262containing the debug info to be emitted along with the compile unit, regardless
4263of code optimizations (some nodes are only emitted if there are references to
4264them from instructions). The ``debugInfoForProfiling:`` field is a boolean
4265indicating whether or not line-table discriminators are updated to provide
4266more-accurate debug info for profiling results.
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004267
Renato Golin124f2592016-07-20 12:16:38 +00004268.. code-block:: text
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004269
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004270 !0 = !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang",
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004271 isOptimized: true, flags: "-O2", runtimeVersion: 2,
Adrian Prantlb8089512016-04-01 00:16:49 +00004272 splitDebugFilename: "abc.debug", emissionKind: FullDebug,
Adrian Prantl6c2497f2017-06-12 23:59:43 +00004273 enums: !2, retainedTypes: !3, globals: !4, imports: !5,
4274 macros: !6, dwoId: 0x0abcd)
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004275
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004276Compile unit descriptors provide the root scope for objects declared in a
Adrian Prantl6c2497f2017-06-12 23:59:43 +00004277specific compilation unit. File descriptors are defined using this scope. These
4278descriptors are collected by a named metadata node ``!llvm.dbg.cu``. They keep
4279track of global variables, type information, and imported entities (declarations
4280and namespaces).
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004281
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004282.. _DIFile:
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004283
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004284DIFile
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004285""""""
4286
Sean Silvaa1190322015-08-06 22:56:48 +00004287``DIFile`` nodes represent files. The ``filename:`` can include slashes.
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004288
Aaron Ballmanb3c51512017-01-17 21:48:31 +00004289.. code-block:: none
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004290
Amjad Aboud7faeecc2016-12-25 10:12:09 +00004291 !0 = !DIFile(filename: "path/to/file", directory: "/path/to/dir",
4292 checksumkind: CSK_MD5,
4293 checksum: "000102030405060708090a0b0c0d0e0f")
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004294
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004295Files are sometimes used in ``scope:`` fields, and are the only valid target
4296for ``file:`` fields.
Amjad Aboud7faeecc2016-12-25 10:12:09 +00004297Valid values for ``checksumkind:`` field are: {CSK_None, CSK_MD5, CSK_SHA1}
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004298
Michael Kuperstein605308a2015-05-14 10:58:59 +00004299.. _DIBasicType:
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004300
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004301DIBasicType
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004302"""""""""""
4303
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004304``DIBasicType`` nodes represent primitive types, such as ``int``, ``bool`` and
Sean Silvaa1190322015-08-06 22:56:48 +00004305``float``. ``tag:`` defaults to ``DW_TAG_base_type``.
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004306
Renato Golin124f2592016-07-20 12:16:38 +00004307.. code-block:: text
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004308
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004309 !0 = !DIBasicType(name: "unsigned char", size: 8, align: 8,
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004310 encoding: DW_ATE_unsigned_char)
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004311 !1 = !DIBasicType(tag: DW_TAG_unspecified_type, name: "decltype(nullptr)")
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004312
Sean Silvaa1190322015-08-06 22:56:48 +00004313The ``encoding:`` describes the details of the type. Usually it's one of the
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004314following:
4315
Renato Golin124f2592016-07-20 12:16:38 +00004316.. code-block:: text
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004317
4318 DW_ATE_address = 1
4319 DW_ATE_boolean = 2
4320 DW_ATE_float = 4
4321 DW_ATE_signed = 5
4322 DW_ATE_signed_char = 6
4323 DW_ATE_unsigned = 7
4324 DW_ATE_unsigned_char = 8
4325
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004326.. _DISubroutineType:
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004327
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004328DISubroutineType
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004329""""""""""""""""
4330
Sean Silvaa1190322015-08-06 22:56:48 +00004331``DISubroutineType`` nodes represent subroutine types. Their ``types:`` field
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004332refers to a tuple; the first operand is the return type, while the rest are the
Sean Silvaa1190322015-08-06 22:56:48 +00004333types of the formal arguments in order. If the first operand is ``null``, that
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004334represents a function with no return value (such as ``void foo() {}`` in C++).
4335
Renato Golin124f2592016-07-20 12:16:38 +00004336.. code-block:: text
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004337
4338 !0 = !BasicType(name: "int", size: 32, align: 32, DW_ATE_signed)
4339 !1 = !BasicType(name: "char", size: 8, align: 8, DW_ATE_signed_char)
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004340 !2 = !DISubroutineType(types: !{null, !0, !1}) ; void (int, char)
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004341
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004342.. _DIDerivedType:
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004343
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004344DIDerivedType
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004345"""""""""""""
4346
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004347``DIDerivedType`` nodes represent types derived from other types, such as
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004348qualified types.
4349
Renato Golin124f2592016-07-20 12:16:38 +00004350.. code-block:: text
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004351
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004352 !0 = !DIBasicType(name: "unsigned char", size: 8, align: 8,
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004353 encoding: DW_ATE_unsigned_char)
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004354 !1 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !0, size: 32,
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004355 align: 32)
4356
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004357The following ``tag:`` values are valid:
4358
Renato Golin124f2592016-07-20 12:16:38 +00004359.. code-block:: text
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004360
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004361 DW_TAG_member = 13
4362 DW_TAG_pointer_type = 15
4363 DW_TAG_reference_type = 16
4364 DW_TAG_typedef = 22
Duncan P. N. Exon Smitha3f3de12016-04-16 22:46:47 +00004365 DW_TAG_inheritance = 28
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004366 DW_TAG_ptr_to_member_type = 31
4367 DW_TAG_const_type = 38
Duncan P. N. Exon Smitha3f3de12016-04-16 22:46:47 +00004368 DW_TAG_friend = 42
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004369 DW_TAG_volatile_type = 53
4370 DW_TAG_restrict_type = 55
Victor Leschuke1156c22016-10-31 19:09:38 +00004371 DW_TAG_atomic_type = 71
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004372
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +00004373.. _DIDerivedTypeMember:
4374
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004375``DW_TAG_member`` is used to define a member of a :ref:`composite type
Duncan P. N. Exon Smith90990cd2016-04-17 00:45:00 +00004376<DICompositeType>`. The type of the member is the ``baseType:``. The
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +00004377``offset:`` is the member's bit offset. If the composite type has an ODR
4378``identifier:`` and does not set ``flags: DIFwdDecl``, then the member is
4379uniqued based only on its ``name:`` and ``scope:``.
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004380
Duncan P. N. Exon Smitha3f3de12016-04-16 22:46:47 +00004381``DW_TAG_inheritance`` and ``DW_TAG_friend`` are used in the ``elements:``
4382field of :ref:`composite types <DICompositeType>` to describe parents and
4383friends.
4384
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004385``DW_TAG_typedef`` is used to provide a name for the ``baseType:``.
4386
4387``DW_TAG_pointer_type``, ``DW_TAG_reference_type``, ``DW_TAG_const_type``,
Victor Leschuke1156c22016-10-31 19:09:38 +00004388``DW_TAG_volatile_type``, ``DW_TAG_restrict_type`` and ``DW_TAG_atomic_type``
4389are used to qualify the ``baseType:``.
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004390
4391Note that the ``void *`` type is expressed as a type derived from NULL.
4392
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004393.. _DICompositeType:
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004394
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004395DICompositeType
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004396"""""""""""""""
4397
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004398``DICompositeType`` nodes represent types composed of other types, like
Sean Silvaa1190322015-08-06 22:56:48 +00004399structures and unions. ``elements:`` points to a tuple of the composed types.
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004400
4401If the source language supports ODR, the ``identifier:`` field gives the unique
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +00004402identifier used for type merging between modules. When specified,
4403:ref:`subprogram declarations <DISubprogramDeclaration>` and :ref:`member
4404derived types <DIDerivedTypeMember>` that reference the ODR-type in their
4405``scope:`` change uniquing rules.
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004406
Duncan P. N. Exon Smith5ab2be02016-04-17 03:58:21 +00004407For a given ``identifier:``, there should only be a single composite type that
4408does not have ``flags: DIFlagFwdDecl`` set. LLVM tools that link modules
4409together will unique such definitions at parse time via the ``identifier:``
4410field, even if the nodes are ``distinct``.
4411
Renato Golin124f2592016-07-20 12:16:38 +00004412.. code-block:: text
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004413
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004414 !0 = !DIEnumerator(name: "SixKind", value: 7)
4415 !1 = !DIEnumerator(name: "SevenKind", value: 7)
4416 !2 = !DIEnumerator(name: "NegEightKind", value: -8)
4417 !3 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "Enum", file: !12,
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004418 line: 2, size: 32, align: 32, identifier: "_M4Enum",
4419 elements: !{!0, !1, !2})
4420
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004421The following ``tag:`` values are valid:
4422
Renato Golin124f2592016-07-20 12:16:38 +00004423.. code-block:: text
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004424
4425 DW_TAG_array_type = 1
4426 DW_TAG_class_type = 2
4427 DW_TAG_enumeration_type = 4
4428 DW_TAG_structure_type = 19
4429 DW_TAG_union_type = 23
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004430
4431For ``DW_TAG_array_type``, the ``elements:`` should be :ref:`subrange
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004432descriptors <DISubrange>`, each representing the range of subscripts at that
Sean Silvaa1190322015-08-06 22:56:48 +00004433level of indexing. The ``DIFlagVector`` flag to ``flags:`` indicates that an
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004434array type is a native packed vector.
4435
4436For ``DW_TAG_enumeration_type``, the ``elements:`` should be :ref:`enumerator
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004437descriptors <DIEnumerator>`, each representing the definition of an enumeration
Sean Silvaa1190322015-08-06 22:56:48 +00004438value for the set. All enumeration type descriptors are collected in the
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004439``enums:`` field of the :ref:`compile unit <DICompileUnit>`.
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004440
4441For ``DW_TAG_structure_type``, ``DW_TAG_class_type``, and
4442``DW_TAG_union_type``, the ``elements:`` should be :ref:`derived types
Duncan P. N. Exon Smitha3f3de12016-04-16 22:46:47 +00004443<DIDerivedType>` with ``tag: DW_TAG_member``, ``tag: DW_TAG_inheritance``, or
4444``tag: DW_TAG_friend``; or :ref:`subprograms <DISubprogram>` with
4445``isDefinition: false``.
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004446
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004447.. _DISubrange:
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004448
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004449DISubrange
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004450""""""""""
4451
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004452``DISubrange`` nodes are the elements for ``DW_TAG_array_type`` variants of
Sander de Smalen1cb94312018-01-24 10:30:23 +00004453:ref:`DICompositeType`.
4454
4455- ``count: -1`` indicates an empty array.
4456- ``count: !9`` describes the count with a :ref:`DILocalVariable`.
4457- ``count: !11`` describes the count with a :ref:`DIGlobalVariable`.
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004458
Chandler Carruth4a73aa12018-08-06 03:35:36 +00004459.. code-block:: text
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004460
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004461 !0 = !DISubrange(count: 5, lowerBound: 0) ; array counting from 0
4462 !1 = !DISubrange(count: 5, lowerBound: 1) ; array counting from 1
4463 !2 = !DISubrange(count: -1) ; empty array.
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004464
Sander de Smalenfdf40912018-01-24 09:56:07 +00004465 ; Scopes used in rest of example
4466 !6 = !DIFile(filename: "vla.c", directory: "/path/to/file")
Chandler Carruth24dd2112018-08-06 02:30:01 +00004467 !7 = distinct !DICompileUnit(language: DW_LANG_C99, file: !6)
4468 !8 = distinct !DISubprogram(name: "foo", scope: !7, file: !6, line: 5)
Sander de Smalenfdf40912018-01-24 09:56:07 +00004469
4470 ; Use of local variable as count value
4471 !9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
4472 !10 = !DILocalVariable(name: "count", scope: !8, file: !6, line: 42, type: !9)
Chandler Carruth24dd2112018-08-06 02:30:01 +00004473 !11 = !DISubrange(count: !10, lowerBound: 0)
Sander de Smalenfdf40912018-01-24 09:56:07 +00004474
4475 ; Use of global variable as count value
4476 !12 = !DIGlobalVariable(name: "count", scope: !8, file: !6, line: 22, type: !9)
Chandler Carruth24dd2112018-08-06 02:30:01 +00004477 !13 = !DISubrange(count: !12, lowerBound: 0)
Sander de Smalenfdf40912018-01-24 09:56:07 +00004478
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004479.. _DIEnumerator:
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004480
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004481DIEnumerator
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004482""""""""""""
4483
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004484``DIEnumerator`` nodes are the elements for ``DW_TAG_enumeration_type``
4485variants of :ref:`DICompositeType`.
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004486
Chandler Carruth4a73aa12018-08-06 03:35:36 +00004487.. code-block:: text
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004488
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004489 !0 = !DIEnumerator(name: "SixKind", value: 7)
4490 !1 = !DIEnumerator(name: "SevenKind", value: 7)
4491 !2 = !DIEnumerator(name: "NegEightKind", value: -8)
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004492
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004493DITemplateTypeParameter
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004494"""""""""""""""""""""""
4495
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004496``DITemplateTypeParameter`` nodes represent type parameters to generic source
Sean Silvaa1190322015-08-06 22:56:48 +00004497language constructs. They are used (optionally) in :ref:`DICompositeType` and
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004498:ref:`DISubprogram` ``templateParams:`` fields.
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004499
Chandler Carruth4a73aa12018-08-06 03:35:36 +00004500.. code-block:: text
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004501
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004502 !0 = !DITemplateTypeParameter(name: "Ty", type: !1)
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004503
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004504DITemplateValueParameter
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004505""""""""""""""""""""""""
4506
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004507``DITemplateValueParameter`` nodes represent value parameters to generic source
Sean Silvaa1190322015-08-06 22:56:48 +00004508language constructs. ``tag:`` defaults to ``DW_TAG_template_value_parameter``,
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004509but if specified can also be set to ``DW_TAG_GNU_template_template_param`` or
Sean Silvaa1190322015-08-06 22:56:48 +00004510``DW_TAG_GNU_template_param_pack``. They are used (optionally) in
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004511:ref:`DICompositeType` and :ref:`DISubprogram` ``templateParams:`` fields.
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004512
Chandler Carruth4a73aa12018-08-06 03:35:36 +00004513.. code-block:: text
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004514
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004515 !0 = !DITemplateValueParameter(name: "Ty", type: !1, value: i32 7)
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004516
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004517DINamespace
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004518"""""""""""
4519
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004520``DINamespace`` nodes represent namespaces in the source language.
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004521
Chandler Carruth4a73aa12018-08-06 03:35:36 +00004522.. code-block:: text
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004523
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004524 !0 = !DINamespace(name: "myawesomeproject", scope: !1, file: !2, line: 7)
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004525
Sander de Smalen1cb94312018-01-24 10:30:23 +00004526.. _DIGlobalVariable:
4527
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004528DIGlobalVariable
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004529""""""""""""""""
4530
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004531``DIGlobalVariable`` nodes represent global variables in the source language.
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004532
Chandler Carruth4a73aa12018-08-06 03:35:36 +00004533.. code-block:: text
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004534
Adrian Prantl6f0ec692019-01-22 16:40:18 +00004535 @foo = global i32, !dbg !0
4536 !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
4537 !1 = !DIGlobalVariable(name: "foo", linkageName: "foo", scope: !2,
4538 file: !3, line: 7, type: !4, isLocal: true,
4539 isDefinition: false, declaration: !5)
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004540
Adrian Prantl6f0ec692019-01-22 16:40:18 +00004541
4542DIGlobalVariableExpression
4543""""""""""""""""""""""""""
4544
4545``DIGlobalVariableExpression`` nodes tie a :ref:`DIGlobalVariable` together
4546with a :ref:`DIExpression`.
4547
4548.. code-block:: text
4549
4550 @lower = global i32, !dbg !0
4551 @upper = global i32, !dbg !1
4552 !0 = !DIGlobalVariableExpression(
4553 var: !2,
4554 expr: !DIExpression(DW_OP_LLVM_fragment, 0, 32)
4555 )
4556 !1 = !DIGlobalVariableExpression(
4557 var: !2,
4558 expr: !DIExpression(DW_OP_LLVM_fragment, 32, 32)
4559 )
4560 !2 = !DIGlobalVariable(name: "split64", linkageName: "split64", scope: !3,
4561 file: !4, line: 8, type: !5, declaration: !6)
4562
4563All global variable expressions should be referenced by the `globals:` field of
4564a :ref:`compile unit <DICompileUnit>`.
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004565
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004566.. _DISubprogram:
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004567
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004568DISubprogram
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004569""""""""""""
4570
Peter Collingbourne50108682015-11-06 02:41:02 +00004571``DISubprogram`` nodes represent functions from the source language. A
4572``DISubprogram`` may be attached to a function definition using ``!dbg``
4573metadata. The ``variables:`` field points at :ref:`variables <DILocalVariable>`
4574that must be retained, even if their IR counterparts are optimized out of
4575the IR. The ``type:`` field must point at an :ref:`DISubroutineType`.
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004576
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +00004577.. _DISubprogramDeclaration:
4578
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +00004579When ``isDefinition: false``, subprograms describe a declaration in the type
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +00004580tree as opposed to a definition of a function. If the scope is a composite
4581type with an ODR ``identifier:`` and that does not set ``flags: DIFwdDecl``,
4582then the subprogram declaration is uniqued based only on its ``linkageName:``
4583and ``scope:``.
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +00004584
Renato Golin124f2592016-07-20 12:16:38 +00004585.. code-block:: text
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004586
Peter Collingbourne50108682015-11-06 02:41:02 +00004587 define void @_Z3foov() !dbg !0 {
4588 ...
4589 }
4590
4591 !0 = distinct !DISubprogram(name: "foo", linkageName: "_Zfoov", scope: !1,
4592 file: !2, line: 7, type: !3, isLocal: true,
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +00004593 isDefinition: true, scopeLine: 8,
Peter Collingbourne50108682015-11-06 02:41:02 +00004594 containingType: !4,
4595 virtuality: DW_VIRTUALITY_pure_virtual,
4596 virtualIndex: 10, flags: DIFlagPrototyped,
Adrian Prantl6c2497f2017-06-12 23:59:43 +00004597 isOptimized: true, unit: !5, templateParams: !6,
4598 declaration: !7, variables: !8, thrownTypes: !9)
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004599
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004600.. _DILexicalBlock:
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004601
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004602DILexicalBlock
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004603""""""""""""""
4604
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004605``DILexicalBlock`` nodes describe nested blocks within a :ref:`subprogram
Bruce Mitchenere9ffb452015-09-12 01:17:08 +00004606<DISubprogram>`. The line number and column numbers are used to distinguish
Sean Silvaa1190322015-08-06 22:56:48 +00004607two lexical blocks at same depth. They are valid targets for ``scope:``
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004608fields.
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004609
Renato Golin124f2592016-07-20 12:16:38 +00004610.. code-block:: text
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004611
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004612 !0 = distinct !DILexicalBlock(scope: !1, file: !2, line: 7, column: 35)
Duncan P. N. Exon Smithd937cd92015-03-17 23:41:05 +00004613
4614Usually lexical blocks are ``distinct`` to prevent node merging based on
4615operands.
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004616
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004617.. _DILexicalBlockFile:
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004618
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004619DILexicalBlockFile
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004620""""""""""""""""""
4621
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004622``DILexicalBlockFile`` nodes are used to discriminate between sections of a
Sean Silvaa1190322015-08-06 22:56:48 +00004623:ref:`lexical block <DILexicalBlock>`. The ``file:`` field can be changed to
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004624indicate textual inclusion, or the ``discriminator:`` field can be used to
4625discriminate between control flow within a single block in the source language.
4626
Chandler Carruth4a73aa12018-08-06 03:35:36 +00004627.. code-block:: text
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004628
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004629 !0 = !DILexicalBlock(scope: !3, file: !4, line: 7, column: 35)
4630 !1 = !DILexicalBlockFile(scope: !0, file: !4, discriminator: 0)
4631 !2 = !DILexicalBlockFile(scope: !0, file: !4, discriminator: 1)
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004632
Michael Kuperstein605308a2015-05-14 10:58:59 +00004633.. _DILocation:
4634
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004635DILocation
Duncan P. N. Exon Smith6a484832015-01-13 21:10:44 +00004636""""""""""
4637
Sean Silvaa1190322015-08-06 22:56:48 +00004638``DILocation`` nodes represent source debug locations. The ``scope:`` field is
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004639mandatory, and points at an :ref:`DILexicalBlockFile`, an
4640:ref:`DILexicalBlock`, or an :ref:`DISubprogram`.
Duncan P. N. Exon Smith6a484832015-01-13 21:10:44 +00004641
Chandler Carruth4a73aa12018-08-06 03:35:36 +00004642.. code-block:: text
Duncan P. N. Exon Smith6a484832015-01-13 21:10:44 +00004643
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004644 !0 = !DILocation(line: 2900, column: 42, scope: !1, inlinedAt: !2)
Duncan P. N. Exon Smith6a484832015-01-13 21:10:44 +00004645
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004646.. _DILocalVariable:
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004647
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004648DILocalVariable
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004649"""""""""""""""
4650
Sean Silvaa1190322015-08-06 22:56:48 +00004651``DILocalVariable`` nodes represent local variables in the source language. If
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +00004652the ``arg:`` field is set to non-zero, then this variable is a subprogram
4653parameter, and it will be included in the ``variables:`` field of its
4654:ref:`DISubprogram`.
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004655
Renato Golin124f2592016-07-20 12:16:38 +00004656.. code-block:: text
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004657
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +00004658 !0 = !DILocalVariable(name: "this", arg: 1, scope: !3, file: !2, line: 7,
4659 type: !3, flags: DIFlagArtificial)
4660 !1 = !DILocalVariable(name: "x", arg: 2, scope: !4, file: !2, line: 7,
4661 type: !3)
4662 !2 = !DILocalVariable(name: "y", scope: !5, file: !2, line: 7, type: !3)
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004663
James Y Knight94b97092019-02-01 17:06:41 +00004664.. _DIExpression:
4665
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004666DIExpression
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004667""""""""""""
4668
Adrian Prantlb44c7762017-03-22 18:01:01 +00004669``DIExpression`` nodes represent expressions that are inspired by the DWARF
4670expression language. They are used in :ref:`debug intrinsics<dbg_intrinsics>`
4671(such as ``llvm.dbg.declare`` and ``llvm.dbg.value``) to describe how the
Vedant Kumar8a05b012018-07-28 00:33:47 +00004672referenced LLVM variable relates to the source language variable. Debug
4673intrinsics are interpreted left-to-right: start by pushing the value/address
4674operand of the intrinsic onto a stack, then repeatedly push and evaluate
4675opcodes from the DIExpression until the final variable description is produced.
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004676
Vedant Kumar8a05b012018-07-28 00:33:47 +00004677The current supported opcode vocabulary is limited:
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004678
Adrian Prantl6825fb62017-04-18 01:21:53 +00004679- ``DW_OP_deref`` dereferences the top of the expression stack.
Florian Hahnffc498d2017-06-14 13:14:38 +00004680- ``DW_OP_plus`` pops the last two entries from the expression stack, adds
4681 them together and appends the result to the expression stack.
4682- ``DW_OP_minus`` pops the last two entries from the expression stack, subtracts
4683 the last entry from the second last entry and appends the result to the
4684 expression stack.
Florian Hahnc9c403c2017-06-13 16:54:44 +00004685- ``DW_OP_plus_uconst, 93`` adds ``93`` to the working expression.
Adrian Prantlb44c7762017-03-22 18:01:01 +00004686- ``DW_OP_LLVM_fragment, 16, 8`` specifies the offset and size (``16`` and ``8``
4687 here, respectively) of the variable fragment from the working expression. Note
Hiroshi Inoue760c0c92018-01-16 13:19:48 +00004688 that contrary to DW_OP_bit_piece, the offset is describing the location
Adrian Prantlb44c7762017-03-22 18:01:01 +00004689 within the described source variable.
Markus Lavinb86ce212019-03-19 13:16:28 +00004690- ``DW_OP_LLVM_convert, 16, DW_ATE_signed`` specifies a bit size and encoding
4691 (``16`` and ``DW_ATE_signed`` here, respectively) to which the top of the
4692 expression stack is to be converted. Maps into a ``DW_OP_convert`` operation
4693 that references a base type constructed from the supplied values.
Konstantin Zhuravlyovf9b41cd2017-03-08 00:28:57 +00004694- ``DW_OP_swap`` swaps top two stack entries.
4695- ``DW_OP_xderef`` provides extended dereference mechanism. The entry at the top
4696 of the stack is treated as an address. The second stack entry is treated as an
4697 address space identifier.
Adrian Prantlb44c7762017-03-22 18:01:01 +00004698- ``DW_OP_stack_value`` marks a constant value.
4699
Adrian Prantl6825fb62017-04-18 01:21:53 +00004700DWARF specifies three kinds of simple location descriptions: Register, memory,
Vedant Kumar8a05b012018-07-28 00:33:47 +00004701and implicit location descriptions. Note that a location description is
4702defined over certain ranges of a program, i.e the location of a variable may
4703change over the course of the program. Register and memory location
4704descriptions describe the *concrete location* of a source variable (in the
4705sense that a debugger might modify its value), whereas *implicit locations*
4706describe merely the actual *value* of a source variable which might not exist
4707in registers or in memory (see ``DW_OP_stack_value``).
4708
4709A ``llvm.dbg.addr`` or ``llvm.dbg.declare`` intrinsic describes an indirect
4710value (the address) of a source variable. The first operand of the intrinsic
4711must be an address of some kind. A DIExpression attached to the intrinsic
4712refines this address to produce a concrete location for the source variable.
4713
4714A ``llvm.dbg.value`` intrinsic describes the direct value of a source variable.
4715The first operand of the intrinsic may be a direct or indirect value. A
4716DIExpresion attached to the intrinsic refines the first operand to produce a
4717direct value. For example, if the first operand is an indirect value, it may be
4718necessary to insert ``DW_OP_deref`` into the DIExpresion in order to produce a
4719valid debug intrinsic.
4720
4721.. note::
4722
4723 A DIExpression is interpreted in the same way regardless of which kind of
4724 debug intrinsic it's attached to.
Adrian Prantl6825fb62017-04-18 01:21:53 +00004725
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +00004726.. code-block:: text
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004727
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004728 !0 = !DIExpression(DW_OP_deref)
Florian Hahnc9c403c2017-06-13 16:54:44 +00004729 !1 = !DIExpression(DW_OP_plus_uconst, 3)
Florian Hahnffc498d2017-06-14 13:14:38 +00004730 !1 = !DIExpression(DW_OP_constu, 3, DW_OP_plus)
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004731 !2 = !DIExpression(DW_OP_bit_piece, 3, 7)
Florian Hahnffc498d2017-06-14 13:14:38 +00004732 !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 +00004733 !4 = !DIExpression(DW_OP_constu, 2, DW_OP_swap, DW_OP_xderef)
Adrian Prantlb44c7762017-03-22 18:01:01 +00004734 !5 = !DIExpression(DW_OP_constu, 42, DW_OP_stack_value)
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004735
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004736DIObjCProperty
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004737""""""""""""""
4738
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004739``DIObjCProperty`` nodes represent Objective-C property nodes.
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004740
Chandler Carruth4a73aa12018-08-06 03:35:36 +00004741.. code-block:: text
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004742
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004743 !3 = !DIObjCProperty(name: "foo", file: !1, line: 7, setter: "setFoo",
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004744 getter: "getFoo", attributes: 7, type: !2)
4745
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004746DIImportedEntity
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004747""""""""""""""""
4748
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004749``DIImportedEntity`` nodes represent entities (such as modules) imported into a
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004750compile unit.
4751
Renato Golin124f2592016-07-20 12:16:38 +00004752.. code-block:: text
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004753
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00004754 !2 = !DIImportedEntity(tag: DW_TAG_imported_module, name: "foo", scope: !0,
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +00004755 entity: !1, line: 7)
4756
Amjad Abouda9bcf162015-12-10 12:56:35 +00004757DIMacro
4758"""""""
4759
4760``DIMacro`` nodes represent definition or undefinition of a macro identifiers.
4761The ``name:`` field is the macro identifier, followed by macro parameters when
Sylvestre Ledru7d540502016-07-02 19:28:40 +00004762defining a function-like macro, and the ``value`` field is the token-string
Amjad Abouda9bcf162015-12-10 12:56:35 +00004763used to expand the macro identifier.
4764
Renato Golin124f2592016-07-20 12:16:38 +00004765.. code-block:: text
Amjad Abouda9bcf162015-12-10 12:56:35 +00004766
4767 !2 = !DIMacro(macinfo: DW_MACINFO_define, line: 7, name: "foo(x)",
4768 value: "((x) + 1)")
4769 !3 = !DIMacro(macinfo: DW_MACINFO_undef, line: 30, name: "foo")
4770
4771DIMacroFile
4772"""""""""""
4773
4774``DIMacroFile`` nodes represent inclusion of source files.
4775The ``nodes:`` field is a list of ``DIMacro`` and ``DIMacroFile`` nodes that
4776appear in the included source file.
4777
Renato Golin124f2592016-07-20 12:16:38 +00004778.. code-block:: text
Amjad Abouda9bcf162015-12-10 12:56:35 +00004779
4780 !2 = !DIMacroFile(macinfo: DW_MACINFO_start_file, line: 7, file: !2,
4781 nodes: !3)
4782
Sean Silvab084af42012-12-07 10:36:55 +00004783'``tbaa``' Metadata
4784^^^^^^^^^^^^^^^^^^^
4785
4786In LLVM IR, memory does not have types, so LLVM's own type system is not
Sanjoy Dasa3ff9942017-02-13 23:14:03 +00004787suitable for doing type based alias analysis (TBAA). Instead, metadata is
4788added to the IR to describe a type system of a higher level language. This
4789can be used to implement C/C++ strict type aliasing rules, but it can also
4790be used to implement custom alias analysis behavior for other languages.
Sean Silvab084af42012-12-07 10:36:55 +00004791
Sanjoy Dasa3ff9942017-02-13 23:14:03 +00004792This description of LLVM's TBAA system is broken into two parts:
4793:ref:`Semantics<tbaa_node_semantics>` talks about high level issues, and
4794:ref:`Representation<tbaa_node_representation>` talks about the metadata
4795encoding of various entities.
Sean Silvab084af42012-12-07 10:36:55 +00004796
Sanjoy Dasa3ff9942017-02-13 23:14:03 +00004797It is always possible to trace any TBAA node to a "root" TBAA node (details
4798in the :ref:`Representation<tbaa_node_representation>` section). TBAA
4799nodes with different roots have an unknown aliasing relationship, and LLVM
4800conservatively infers ``MayAlias`` between them. The rules mentioned in
4801this section only pertain to TBAA nodes living under the same root.
Sean Silvab084af42012-12-07 10:36:55 +00004802
Sanjoy Dasa3ff9942017-02-13 23:14:03 +00004803.. _tbaa_node_semantics:
Sean Silvab084af42012-12-07 10:36:55 +00004804
Sanjoy Dasa3ff9942017-02-13 23:14:03 +00004805Semantics
4806"""""""""
Sean Silvab084af42012-12-07 10:36:55 +00004807
Sanjoy Dasa3ff9942017-02-13 23:14:03 +00004808The TBAA metadata system, referred to as "struct path TBAA" (not to be
4809confused with ``tbaa.struct``), consists of the following high level
4810concepts: *Type Descriptors*, further subdivided into scalar type
4811descriptors and struct type descriptors; and *Access Tags*.
Sean Silvab084af42012-12-07 10:36:55 +00004812
Sanjoy Dasa3ff9942017-02-13 23:14:03 +00004813**Type descriptors** describe the type system of the higher level language
4814being compiled. **Scalar type descriptors** describe types that do not
4815contain other types. Each scalar type has a parent type, which must also
4816be a scalar type or the TBAA root. Via this parent relation, scalar types
4817within a TBAA root form a tree. **Struct type descriptors** denote types
4818that contain a sequence of other type descriptors, at known offsets. These
4819contained type descriptors can either be struct type descriptors themselves
4820or scalar type descriptors.
4821
4822**Access tags** are metadata nodes attached to load and store instructions.
4823Access tags use type descriptors to describe the *location* being accessed
4824in terms of the type system of the higher level language. Access tags are
4825tuples consisting of a base type, an access type and an offset. The base
4826type is a scalar type descriptor or a struct type descriptor, the access
4827type is a scalar type descriptor, and the offset is a constant integer.
4828
4829The access tag ``(BaseTy, AccessTy, Offset)`` can describe one of two
4830things:
4831
4832 * If ``BaseTy`` is a struct type, the tag describes a memory access (load
4833 or store) of a value of type ``AccessTy`` contained in the struct type
4834 ``BaseTy`` at offset ``Offset``.
4835
4836 * If ``BaseTy`` is a scalar type, ``Offset`` must be 0 and ``BaseTy`` and
4837 ``AccessTy`` must be the same; and the access tag describes a scalar
4838 access with scalar type ``AccessTy``.
4839
4840We first define an ``ImmediateParent`` relation on ``(BaseTy, Offset)``
4841tuples this way:
4842
4843 * If ``BaseTy`` is a scalar type then ``ImmediateParent(BaseTy, 0)`` is
4844 ``(ParentTy, 0)`` where ``ParentTy`` is the parent of the scalar type as
4845 described in the TBAA metadata. ``ImmediateParent(BaseTy, Offset)`` is
4846 undefined if ``Offset`` is non-zero.
4847
4848 * If ``BaseTy`` is a struct type then ``ImmediateParent(BaseTy, Offset)``
4849 is ``(NewTy, NewOffset)`` where ``NewTy`` is the type contained in
4850 ``BaseTy`` at offset ``Offset`` and ``NewOffset`` is ``Offset`` adjusted
4851 to be relative within that inner type.
4852
4853A memory access with an access tag ``(BaseTy1, AccessTy1, Offset1)``
4854aliases a memory access with an access tag ``(BaseTy2, AccessTy2,
4855Offset2)`` if either ``(BaseTy1, Offset1)`` is reachable from ``(Base2,
4856Offset2)`` via the ``Parent`` relation or vice versa.
4857
4858As a concrete example, the type descriptor graph for the following program
4859
4860.. code-block:: c
4861
4862 struct Inner {
4863 int i; // offset 0
4864 float f; // offset 4
4865 };
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +00004866
Sanjoy Dasa3ff9942017-02-13 23:14:03 +00004867 struct Outer {
4868 float f; // offset 0
4869 double d; // offset 4
4870 struct Inner inner_a; // offset 12
4871 };
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +00004872
Sanjoy Dasa3ff9942017-02-13 23:14:03 +00004873 void f(struct Outer* outer, struct Inner* inner, float* f, int* i, char* c) {
4874 outer->f = 0; // tag0: (OuterStructTy, FloatScalarTy, 0)
4875 outer->inner_a.i = 0; // tag1: (OuterStructTy, IntScalarTy, 12)
Fangrui Song74d6a742018-05-29 05:38:05 +00004876 outer->inner_a.f = 0.0; // tag2: (OuterStructTy, FloatScalarTy, 16)
Sanjoy Dasa3ff9942017-02-13 23:14:03 +00004877 *f = 0.0; // tag3: (FloatScalarTy, FloatScalarTy, 0)
4878 }
4879
4880is (note that in C and C++, ``char`` can be used to access any arbitrary
4881type):
4882
4883.. code-block:: text
4884
4885 Root = "TBAA Root"
4886 CharScalarTy = ("char", Root, 0)
4887 FloatScalarTy = ("float", CharScalarTy, 0)
4888 DoubleScalarTy = ("double", CharScalarTy, 0)
4889 IntScalarTy = ("int", CharScalarTy, 0)
4890 InnerStructTy = {"Inner" (IntScalarTy, 0), (FloatScalarTy, 4)}
4891 OuterStructTy = {"Outer", (FloatScalarTy, 0), (DoubleScalarTy, 4),
4892 (InnerStructTy, 12)}
4893
4894
4895with (e.g.) ``ImmediateParent(OuterStructTy, 12)`` = ``(InnerStructTy,
48960)``, ``ImmediateParent(InnerStructTy, 0)`` = ``(IntScalarTy, 0)``, and
4897``ImmediateParent(IntScalarTy, 0)`` = ``(CharScalarTy, 0)``.
4898
4899.. _tbaa_node_representation:
4900
4901Representation
4902""""""""""""""
4903
4904The root node of a TBAA type hierarchy is an ``MDNode`` with 0 operands or
4905with exactly one ``MDString`` operand.
4906
4907Scalar type descriptors are represented as an ``MDNode`` s with two
4908operands. The first operand is an ``MDString`` denoting the name of the
4909struct type. LLVM does not assign meaning to the value of this operand, it
4910only cares about it being an ``MDString``. The second operand is an
4911``MDNode`` which points to the parent for said scalar type descriptor,
4912which is either another scalar type descriptor or the TBAA root. Scalar
4913type descriptors can have an optional third argument, but that must be the
4914constant integer zero.
4915
4916Struct type descriptors are represented as ``MDNode`` s with an odd number
4917of operands greater than 1. The first operand is an ``MDString`` denoting
4918the name of the struct type. Like in scalar type descriptors the actual
4919value of this name operand is irrelevant to LLVM. After the name operand,
4920the struct type descriptors have a sequence of alternating ``MDNode`` and
4921``ConstantInt`` operands. With N starting from 1, the 2N - 1 th operand,
4922an ``MDNode``, denotes a contained field, and the 2N th operand, a
4923``ConstantInt``, is the offset of the said contained field. The offsets
4924must be in non-decreasing order.
4925
4926Access tags are represented as ``MDNode`` s with either 3 or 4 operands.
4927The first operand is an ``MDNode`` pointing to the node representing the
4928base type. The second operand is an ``MDNode`` pointing to the node
4929representing the access type. The third operand is a ``ConstantInt`` that
4930states the offset of the access. If a fourth field is present, it must be
4931a ``ConstantInt`` valued at 0 or 1. If it is 1 then the access tag states
4932that the location being accessed is "constant" (meaning
Sean Silvab084af42012-12-07 10:36:55 +00004933``pointsToConstantMemory`` should return true; see `other useful
Sanjoy Dasa3ff9942017-02-13 23:14:03 +00004934AliasAnalysis methods <AliasAnalysis.html#OtherItfs>`_). The TBAA root of
4935the access type and the base type of an access tag must be the same, and
4936that is the TBAA root of the access tag.
Sean Silvab084af42012-12-07 10:36:55 +00004937
4938'``tbaa.struct``' Metadata
4939^^^^^^^^^^^^^^^^^^^^^^^^^^
4940
4941The :ref:`llvm.memcpy <int_memcpy>` is often used to implement
4942aggregate assignment operations in C and similar languages, however it
4943is defined to copy a contiguous region of memory, which is more than
4944strictly necessary for aggregate types which contain holes due to
4945padding. Also, it doesn't contain any TBAA information about the fields
4946of the aggregate.
4947
4948``!tbaa.struct`` metadata can describe which memory subregions in a
4949memcpy are padding and what the TBAA tags of the struct are.
4950
4951The current metadata format is very simple. ``!tbaa.struct`` metadata
4952nodes are a list of operands which are in conceptual groups of three.
4953For each group of three, the first operand gives the byte offset of a
4954field in bytes, the second gives its size in bytes, and the third gives
4955its tbaa tag. e.g.:
4956
4957.. code-block:: llvm
4958
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00004959 !4 = !{ i64 0, i64 4, !1, i64 8, i64 4, !2 }
Sean Silvab084af42012-12-07 10:36:55 +00004960
4961This describes a struct with two fields. The first is at offset 0 bytes
4962with size 4 bytes, and has tbaa tag !1. The second is at offset 8 bytes
4963and has size 4 bytes and has tbaa tag !2.
4964
4965Note that the fields need not be contiguous. In this example, there is a
49664 byte gap between the two fields. This gap represents padding which
4967does not carry useful data and need not be preserved.
4968
Hal Finkel94146652014-07-24 14:25:39 +00004969'``noalias``' and '``alias.scope``' Metadata
Dan Liewbafdcba2014-07-28 13:33:51 +00004970^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Hal Finkel94146652014-07-24 14:25:39 +00004971
4972``noalias`` and ``alias.scope`` metadata provide the ability to specify generic
4973noalias memory-access sets. This means that some collection of memory access
4974instructions (loads, stores, memory-accessing calls, etc.) that carry
4975``noalias`` metadata can specifically be specified not to alias with some other
4976collection of memory access instructions that carry ``alias.scope`` metadata.
Hal Finkel029cde62014-07-25 15:50:02 +00004977Each type of metadata specifies a list of scopes where each scope has an id and
Adam Nemet569a5b32016-04-27 00:52:48 +00004978a domain.
4979
4980When evaluating an aliasing query, if for some domain, the set
Hal Finkel029cde62014-07-25 15:50:02 +00004981of scopes with that domain in one instruction's ``alias.scope`` list is a
Arch D. Robison96cf7ab2015-02-24 20:11:49 +00004982subset of (or equal to) the set of scopes for that domain in another
Hal Finkel029cde62014-07-25 15:50:02 +00004983instruction's ``noalias`` list, then the two memory accesses are assumed not to
4984alias.
Hal Finkel94146652014-07-24 14:25:39 +00004985
Adam Nemet569a5b32016-04-27 00:52:48 +00004986Because scopes in one domain don't affect scopes in other domains, separate
4987domains can be used to compose multiple independent noalias sets. This is
4988used for example during inlining. As the noalias function parameters are
4989turned into noalias scope metadata, a new domain is used every time the
4990function is inlined.
4991
Hal Finkel029cde62014-07-25 15:50:02 +00004992The metadata identifying each domain is itself a list containing one or two
4993entries. The first entry is the name of the domain. Note that if the name is a
Bruce Mitchenere9ffb452015-09-12 01:17:08 +00004994string then it can be combined across functions and translation units. A
Hal Finkel029cde62014-07-25 15:50:02 +00004995self-reference can be used to create globally unique domain names. A
4996descriptive string may optionally be provided as a second list entry.
4997
4998The metadata identifying each scope is also itself a list containing two or
4999three entries. The first entry is the name of the scope. Note that if the name
Bruce Mitchenere9ffb452015-09-12 01:17:08 +00005000is a string then it can be combined across functions and translation units. A
Hal Finkel029cde62014-07-25 15:50:02 +00005001self-reference can be used to create globally unique scope names. A metadata
5002reference to the scope's domain is the second entry. A descriptive string may
5003optionally be provided as a third list entry.
Hal Finkel94146652014-07-24 14:25:39 +00005004
5005For example,
5006
5007.. code-block:: llvm
5008
Hal Finkel029cde62014-07-25 15:50:02 +00005009 ; Two scope domains:
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00005010 !0 = !{!0}
5011 !1 = !{!1}
Hal Finkel94146652014-07-24 14:25:39 +00005012
Hal Finkel029cde62014-07-25 15:50:02 +00005013 ; Some scopes in these domains:
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00005014 !2 = !{!2, !0}
5015 !3 = !{!3, !0}
5016 !4 = !{!4, !1}
Hal Finkel94146652014-07-24 14:25:39 +00005017
Hal Finkel029cde62014-07-25 15:50:02 +00005018 ; Some scope lists:
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00005019 !5 = !{!4} ; A list containing only scope !4
5020 !6 = !{!4, !3, !2}
5021 !7 = !{!3}
Hal Finkel94146652014-07-24 14:25:39 +00005022
5023 ; These two instructions don't alias:
David Blaikiec7aabbb2015-03-04 22:06:14 +00005024 %0 = load float, float* %c, align 4, !alias.scope !5
Hal Finkel029cde62014-07-25 15:50:02 +00005025 store float %0, float* %arrayidx.i, align 4, !noalias !5
Hal Finkel94146652014-07-24 14:25:39 +00005026
Hal Finkel029cde62014-07-25 15:50:02 +00005027 ; These two instructions also don't alias (for domain !1, the set of scopes
5028 ; in the !alias.scope equals that in the !noalias list):
David Blaikiec7aabbb2015-03-04 22:06:14 +00005029 %2 = load float, float* %c, align 4, !alias.scope !5
Hal Finkel029cde62014-07-25 15:50:02 +00005030 store float %2, float* %arrayidx.i2, align 4, !noalias !6
Hal Finkel94146652014-07-24 14:25:39 +00005031
Adam Nemet0a8416f2015-05-11 08:30:28 +00005032 ; These two instructions may alias (for domain !0, the set of scopes in
Hal Finkel029cde62014-07-25 15:50:02 +00005033 ; the !noalias list is not a superset of, or equal to, the scopes in the
5034 ; !alias.scope list):
David Blaikiec7aabbb2015-03-04 22:06:14 +00005035 %2 = load float, float* %c, align 4, !alias.scope !6
Hal Finkel029cde62014-07-25 15:50:02 +00005036 store float %0, float* %arrayidx.i, align 4, !noalias !7
Hal Finkel94146652014-07-24 14:25:39 +00005037
Sean Silvab084af42012-12-07 10:36:55 +00005038'``fpmath``' Metadata
5039^^^^^^^^^^^^^^^^^^^^^
5040
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00005041``fpmath`` metadata may be attached to any instruction of floating-point
Sean Silvab084af42012-12-07 10:36:55 +00005042type. It can be used to express the maximum acceptable error in the
5043result of that instruction, in ULPs, thus potentially allowing the
5044compiler to use a more efficient but less accurate method of computing
5045it. ULP is defined as follows:
5046
5047 If ``x`` is a real number that lies between two finite consecutive
5048 floating-point numbers ``a`` and ``b``, without being equal to one
5049 of them, then ``ulp(x) = |b - a|``, otherwise ``ulp(x)`` is the
5050 distance between the two non-equal finite floating-point numbers
5051 nearest ``x``. Moreover, ``ulp(NaN)`` is ``NaN``.
5052
Matt Arsenault82f41512016-06-27 19:43:15 +00005053The metadata node shall consist of a single positive float type number
5054representing the maximum relative error, for example:
Sean Silvab084af42012-12-07 10:36:55 +00005055
5056.. code-block:: llvm
5057
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00005058 !0 = !{ float 2.5 } ; maximum acceptable inaccuracy is 2.5 ULPs
Sean Silvab084af42012-12-07 10:36:55 +00005059
Philip Reamesf8bf9dd2015-02-27 23:14:50 +00005060.. _range-metadata:
5061
Sean Silvab084af42012-12-07 10:36:55 +00005062'``range``' Metadata
5063^^^^^^^^^^^^^^^^^^^^
5064
Jingyue Wu37fcb592014-06-19 16:50:16 +00005065``range`` metadata may be attached only to ``load``, ``call`` and ``invoke`` of
5066integer types. It expresses the possible ranges the loaded value or the value
Eli Friedmane15a1112018-07-17 20:38:11 +00005067returned by the called function at this call site is in. If the loaded or
5068returned value is not in the specified range, the behavior is undefined. The
5069ranges are represented with a flattened list of integers. The loaded value or
5070the value returned is known to be in the union of the ranges defined by each
5071consecutive pair. Each pair has the following properties:
Sean Silvab084af42012-12-07 10:36:55 +00005072
5073- The type must match the type loaded by the instruction.
5074- The pair ``a,b`` represents the range ``[a,b)``.
5075- Both ``a`` and ``b`` are constants.
5076- The range is allowed to wrap.
5077- The range should not represent the full or empty set. That is,
5078 ``a!=b``.
5079
5080In addition, the pairs must be in signed order of the lower bound and
5081they must be non-contiguous.
5082
5083Examples:
5084
5085.. code-block:: llvm
5086
David Blaikiec7aabbb2015-03-04 22:06:14 +00005087 %a = load i8, i8* %x, align 1, !range !0 ; Can only be 0 or 1
5088 %b = load i8, i8* %y, align 1, !range !1 ; Can only be 255 (-1), 0 or 1
Jingyue Wu37fcb592014-06-19 16:50:16 +00005089 %c = call i8 @foo(), !range !2 ; Can only be 0, 1, 3, 4 or 5
5090 %d = invoke i8 @bar() to label %cont
5091 unwind label %lpad, !range !3 ; Can only be -2, -1, 3, 4 or 5
Sean Silvab084af42012-12-07 10:36:55 +00005092 ...
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00005093 !0 = !{ i8 0, i8 2 }
5094 !1 = !{ i8 255, i8 2 }
5095 !2 = !{ i8 0, i8 2, i8 3, i8 6 }
5096 !3 = !{ i8 -2, i8 0, i8 3, i8 6 }
Sean Silvab084af42012-12-07 10:36:55 +00005097
Peter Collingbourne235c2752016-12-08 19:01:00 +00005098'``absolute_symbol``' Metadata
5099^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5100
5101``absolute_symbol`` metadata may be attached to a global variable
5102declaration. It marks the declaration as a reference to an absolute symbol,
5103which causes the backend to use absolute relocations for the symbol even
5104in position independent code, and expresses the possible ranges that the
5105global variable's *address* (not its value) is in, in the same format as
Peter Collingbourned88f9282017-01-20 21:56:37 +00005106``range`` metadata, with the extension that the pair ``all-ones,all-ones``
5107may be used to represent the full set.
Peter Collingbourne235c2752016-12-08 19:01:00 +00005108
Peter Collingbourned88f9282017-01-20 21:56:37 +00005109Example (assuming 64-bit pointers):
Peter Collingbourne235c2752016-12-08 19:01:00 +00005110
5111.. code-block:: llvm
5112
5113 @a = external global i8, !absolute_symbol !0 ; Absolute symbol in range [0,256)
Peter Collingbourned88f9282017-01-20 21:56:37 +00005114 @b = external global i8, !absolute_symbol !1 ; Absolute symbol in range [0,2^64)
Peter Collingbourne235c2752016-12-08 19:01:00 +00005115
5116 ...
5117 !0 = !{ i64 0, i64 256 }
Peter Collingbourned88f9282017-01-20 21:56:37 +00005118 !1 = !{ i64 -1, i64 -1 }
Peter Collingbourne235c2752016-12-08 19:01:00 +00005119
Matthew Simpson36bbc8c2017-10-16 22:22:11 +00005120'``callees``' Metadata
5121^^^^^^^^^^^^^^^^^^^^^^
5122
5123``callees`` metadata may be attached to indirect call sites. If ``callees``
5124metadata is attached to a call site, and any callee is not among the set of
5125functions provided by the metadata, the behavior is undefined. The intent of
5126this metadata is to facilitate optimizations such as indirect-call promotion.
5127For example, in the code below, the call instruction may only target the
5128``add`` or ``sub`` functions:
5129
5130.. code-block:: llvm
5131
5132 %result = call i64 %binop(i64 %x, i64 %y), !callees !0
5133
5134 ...
5135 !0 = !{i64 (i64, i64)* @add, i64 (i64, i64)* @sub}
5136
Johannes Doerfert18251842019-01-19 05:19:06 +00005137'``callback``' Metadata
Johannes Doerfert0b029072019-01-19 09:40:14 +00005138^^^^^^^^^^^^^^^^^^^^^^^
Johannes Doerfert18251842019-01-19 05:19:06 +00005139
5140``callback`` metadata may be attached to a function declaration, or definition.
5141(Call sites are excluded only due to the lack of a use case.) For ease of
5142exposition, we'll refer to the function annotated w/ metadata as a broker
5143function. The metadata describes how the arguments of a call to the broker are
5144in turn passed to the callback function specified by the metadata. Thus, the
5145``callback`` metadata provides a partial description of a call site inside the
5146broker function with regards to the arguments of a call to the broker. The only
5147semantic restriction on the broker function itself is that it is not allowed to
5148inspect or modify arguments referenced in the ``callback`` metadata as
5149pass-through to the callback function.
5150
5151The broker is not required to actually invoke the callback function at runtime.
5152However, the assumptions about not inspecting or modifying arguments that would
5153be passed to the specified callback function still hold, even if the callback
5154function is not dynamically invoked. The broker is allowed to invoke the
5155callback function more than once per invocation of the broker. The broker is
5156also allowed to invoke (directly or indirectly) the function passed as a
5157callback through another use. Finally, the broker is also allowed to relay the
5158callback callee invocation to a different thread.
5159
5160The metadata is structured as follows: At the outer level, ``callback``
5161metadata is a list of ``callback`` encodings. Each encoding starts with a
5162constant ``i64`` which describes the argument position of the callback function
5163in the call to the broker. The following elements, except the last, describe
5164what arguments are passed to the callback function. Each element is again an
5165``i64`` constant identifying the argument of the broker that is passed through,
5166or ``i64 -1`` to indicate an unknown or inspected argument. The order in which
5167they are listed has to be the same in which they are passed to the callback
5168callee. The last element of the encoding is a boolean which specifies how
5169variadic arguments of the broker are handled. If it is true, all variadic
5170arguments of the broker are passed through to the callback function *after* the
5171arguments encoded explicitly before.
5172
5173In the code below, the ``pthread_create`` function is marked as a broker
5174through the ``!callback !1`` metadata. In the example, there is only one
5175callback encoding, namely ``!2``, associated with the broker. This encoding
5176identifies the callback function as the second argument of the broker (``i64
51772``) and the sole argument of the callback function as the third one of the
5178broker function (``i64 3``).
5179
James Y Knight6e75c7e2019-02-01 19:40:07 +00005180.. FIXME why does the llvm-sphinx-docs builder give a highlighting
5181 error if the below is set to highlight as 'llvm', despite that we
5182 have misc.highlighting_failure set?
5183
5184.. code-block:: text
Johannes Doerfert18251842019-01-19 05:19:06 +00005185
5186 declare !callback !1 dso_local i32 @pthread_create(i64*, %union.pthread_attr_t*, i8* (i8*)*, i8*)
5187
5188 ...
5189 !2 = !{i64 2, i64 3, i1 false}
5190 !1 = !{!2}
5191
5192Another example is shown below. The callback callee is the second argument of
5193the ``__kmpc_fork_call`` function (``i64 2``). The callee is given two unknown
5194values (each identified by a ``i64 -1``) and afterwards all
5195variadic arguments that are passed to the ``__kmpc_fork_call`` call (due to the
5196final ``i1 true``).
5197
James Y Knight6e75c7e2019-02-01 19:40:07 +00005198.. FIXME why does the llvm-sphinx-docs builder give a highlighting
5199 error if the below is set to highlight as 'llvm', despite that we
5200 have misc.highlighting_failure set?
5201
5202.. code-block:: text
Johannes Doerfert18251842019-01-19 05:19:06 +00005203
5204 declare !callback !0 dso_local void @__kmpc_fork_call(%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...)
5205
5206 ...
5207 !1 = !{i64 2, i64 -1, i64 -1, i1 true}
5208 !0 = !{!1}
5209
5210
Sanjay Patela99ab1f2015-09-02 19:06:43 +00005211'``unpredictable``' Metadata
Sanjay Patel1f12b342015-09-02 19:35:31 +00005212^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Sanjay Patela99ab1f2015-09-02 19:06:43 +00005213
5214``unpredictable`` metadata may be attached to any branch or switch
5215instruction. It can be used to express the unpredictability of control
5216flow. Similar to the llvm.expect intrinsic, it may be used to alter
5217optimizations related to compare and branch instructions. The metadata
5218is treated as a boolean value; if it exists, it signals that the branch
5219or switch that it is attached to is completely unpredictable.
5220
Michael Kruse72448522018-12-12 17:32:52 +00005221.. _llvm.loop:
5222
Pekka Jaaskelainen0d237252013-02-13 18:08:57 +00005223'``llvm.loop``'
5224^^^^^^^^^^^^^^^
5225
5226It is sometimes useful to attach information to loop constructs. Currently,
5227loop metadata is implemented as metadata attached to the branch instruction
5228in the loop latch block. This type of metadata refer to a metadata node that is
Matt Arsenault24b49c42013-07-31 17:49:08 +00005229guaranteed to be separate for each loop. The loop identifier metadata is
Paul Redmond5fdf8362013-05-28 20:00:34 +00005230specified with the name ``llvm.loop``.
Pekka Jaaskelainen0d237252013-02-13 18:08:57 +00005231
5232The loop identifier metadata is implemented using a metadata that refers to
Michael Liaoa7699082013-03-06 18:24:34 +00005233itself to avoid merging it with any other identifier metadata, e.g.,
5234during module linkage or function inlining. That is, each loop should refer
5235to their own identification metadata even if they reside in separate functions.
5236The following example contains loop identifier metadata for two separate loop
Pekka Jaaskelainen119a2b62013-02-22 12:03:07 +00005237constructs:
Pekka Jaaskelainen0d237252013-02-13 18:08:57 +00005238
5239.. code-block:: llvm
Paul Redmondeaaed3b2013-02-21 17:20:45 +00005240
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00005241 !0 = !{!0}
5242 !1 = !{!1}
Pekka Jaaskelainen119a2b62013-02-22 12:03:07 +00005243
Mark Heffernan893752a2014-07-18 19:24:51 +00005244The loop identifier metadata can be used to specify additional
5245per-loop metadata. Any operands after the first operand can be treated
5246as user-defined metadata. For example the ``llvm.loop.unroll.count``
5247suggests an unroll factor to the loop unroller:
Pekka Jaaskelainen0d237252013-02-13 18:08:57 +00005248
Paul Redmond5fdf8362013-05-28 20:00:34 +00005249.. code-block:: llvm
Pekka Jaaskelainen0d237252013-02-13 18:08:57 +00005250
Paul Redmond5fdf8362013-05-28 20:00:34 +00005251 br i1 %exitcond, label %._crit_edge, label %.lr.ph, !llvm.loop !0
5252 ...
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00005253 !0 = !{!0, !1}
5254 !1 = !{!"llvm.loop.unroll.count", i32 4}
Mark Heffernan893752a2014-07-18 19:24:51 +00005255
Michael Kruse72448522018-12-12 17:32:52 +00005256'``llvm.loop.disable_nonforced``'
5257^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5258
5259This metadata disables all optional loop transformations unless
5260explicitly instructed using other transformation metdata such as
Michael Kruse82dd71e2018-12-12 17:59:01 +00005261``llvm.loop.unroll.enable``. That is, no heuristic will try to determine
Michael Kruse72448522018-12-12 17:32:52 +00005262whether a transformation is profitable. The purpose is to avoid that the
5263loop is transformed to a different loop before an explicitly requested
5264(forced) transformation is applied. For instance, loop fusion can make
5265other transformations impossible. Mandatory loop canonicalizations such
5266as loop rotation are still applied.
5267
5268It is recommended to use this metadata in addition to any llvm.loop.*
5269transformation directive. Also, any loop should have at most one
5270directive applied to it (and a sequence of transformations built using
5271followup-attributes). Otherwise, which transformation will be applied
5272depends on implementation details such as the pass pipeline order.
5273
5274See :ref:`transformation-metadata` for details.
5275
Mark Heffernan9d20e422014-07-21 23:11:03 +00005276'``llvm.loop.vectorize``' and '``llvm.loop.interleave``'
5277^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Mark Heffernan893752a2014-07-18 19:24:51 +00005278
Mark Heffernan9d20e422014-07-21 23:11:03 +00005279Metadata prefixed with ``llvm.loop.vectorize`` or ``llvm.loop.interleave`` are
5280used to control per-loop vectorization and interleaving parameters such as
Sean Silvaa1190322015-08-06 22:56:48 +00005281vectorization width and interleave count. These metadata should be used in
5282conjunction with ``llvm.loop`` loop identification metadata. The
Mark Heffernan9d20e422014-07-21 23:11:03 +00005283``llvm.loop.vectorize`` and ``llvm.loop.interleave`` metadata are only
5284optimization hints and the optimizer will only interleave and vectorize loops if
Michael Kruse978ba612018-12-20 04:58:07 +00005285it believes it is safe to do so. The ``llvm.loop.parallel_accesses`` metadata
Mark Heffernan9d20e422014-07-21 23:11:03 +00005286which contains information about loop-carried memory dependencies can be helpful
5287in determining the safety of these transformations.
Mark Heffernan893752a2014-07-18 19:24:51 +00005288
Mark Heffernan9d20e422014-07-21 23:11:03 +00005289'``llvm.loop.interleave.count``' Metadata
Mark Heffernan893752a2014-07-18 19:24:51 +00005290^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5291
Mark Heffernan9d20e422014-07-21 23:11:03 +00005292This metadata suggests an interleave count to the loop interleaver.
5293The first operand is the string ``llvm.loop.interleave.count`` and the
Mark Heffernan893752a2014-07-18 19:24:51 +00005294second operand is an integer specifying the interleave count. For
5295example:
5296
5297.. code-block:: llvm
5298
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00005299 !0 = !{!"llvm.loop.interleave.count", i32 4}
Mark Heffernan893752a2014-07-18 19:24:51 +00005300
Mark Heffernan9d20e422014-07-21 23:11:03 +00005301Note that setting ``llvm.loop.interleave.count`` to 1 disables interleaving
Sean Silvaa1190322015-08-06 22:56:48 +00005302multiple iterations of the loop. If ``llvm.loop.interleave.count`` is set to 0
Mark Heffernan9d20e422014-07-21 23:11:03 +00005303then the interleave count will be determined automatically.
5304
5305'``llvm.loop.vectorize.enable``' Metadata
Dan Liew9a1829d2014-07-22 14:59:38 +00005306^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Mark Heffernan9d20e422014-07-21 23:11:03 +00005307
5308This metadata selectively enables or disables vectorization for the loop. The
5309first operand is the string ``llvm.loop.vectorize.enable`` and the second operand
Sean Silvaa1190322015-08-06 22:56:48 +00005310is a bit. If the bit operand value is 1 vectorization is enabled. A value of
Mark Heffernan9d20e422014-07-21 23:11:03 +000053110 disables vectorization:
5312
5313.. code-block:: llvm
5314
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00005315 !0 = !{!"llvm.loop.vectorize.enable", i1 0}
5316 !1 = !{!"llvm.loop.vectorize.enable", i1 1}
Mark Heffernan893752a2014-07-18 19:24:51 +00005317
5318'``llvm.loop.vectorize.width``' Metadata
5319^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5320
5321This metadata sets the target width of the vectorizer. The first
5322operand is the string ``llvm.loop.vectorize.width`` and the second
5323operand is an integer specifying the width. For example:
5324
5325.. code-block:: llvm
5326
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00005327 !0 = !{!"llvm.loop.vectorize.width", i32 4}
Mark Heffernan893752a2014-07-18 19:24:51 +00005328
5329Note that setting ``llvm.loop.vectorize.width`` to 1 disables
Sean Silvaa1190322015-08-06 22:56:48 +00005330vectorization of the loop. If ``llvm.loop.vectorize.width`` is set to
Mark Heffernan893752a2014-07-18 19:24:51 +000053310 or if the loop does not have this metadata the width will be
5332determined automatically.
5333
Michael Kruse72448522018-12-12 17:32:52 +00005334'``llvm.loop.vectorize.followup_vectorized``' Metadata
5335^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5336
5337This metadata defines which loop attributes the vectorized loop will
5338have. See :ref:`transformation-metadata` for details.
5339
5340'``llvm.loop.vectorize.followup_epilogue``' Metadata
5341^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5342
5343This metadata defines which loop attributes the epilogue will have. The
5344epilogue is not vectorized and is executed when either the vectorized
5345loop is not known to preserve semantics (because e.g., it processes two
5346arrays that are found to alias by a runtime check) or for the last
5347iterations that do not fill a complete set of vector lanes. See
5348:ref:`Transformation Metadata <transformation-metadata>` for details.
5349
5350'``llvm.loop.vectorize.followup_all``' Metadata
5351^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5352
5353Attributes in the metadata will be added to both the vectorized and
5354epilogue loop.
5355See :ref:`Transformation Metadata <transformation-metadata>` for details.
5356
Mark Heffernan893752a2014-07-18 19:24:51 +00005357'``llvm.loop.unroll``'
5358^^^^^^^^^^^^^^^^^^^^^^
5359
5360Metadata prefixed with ``llvm.loop.unroll`` are loop unrolling
5361optimization hints such as the unroll factor. ``llvm.loop.unroll``
5362metadata should be used in conjunction with ``llvm.loop`` loop
5363identification metadata. The ``llvm.loop.unroll`` metadata are only
5364optimization hints and the unrolling will only be performed if the
5365optimizer believes it is safe to do so.
5366
Mark Heffernan893752a2014-07-18 19:24:51 +00005367'``llvm.loop.unroll.count``' Metadata
5368^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5369
5370This metadata suggests an unroll factor to the loop unroller. The
5371first operand is the string ``llvm.loop.unroll.count`` and the second
5372operand is a positive integer specifying the unroll factor. For
5373example:
5374
5375.. code-block:: llvm
5376
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00005377 !0 = !{!"llvm.loop.unroll.count", i32 4}
Mark Heffernan893752a2014-07-18 19:24:51 +00005378
5379If the trip count of the loop is less than the unroll count the loop
5380will be partially unrolled.
5381
Mark Heffernane6b4ba12014-07-23 17:31:37 +00005382'``llvm.loop.unroll.disable``' Metadata
5383^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5384
Mark Heffernan3e32a4e2015-06-30 22:48:51 +00005385This metadata disables loop unrolling. The metadata has a single operand
Sean Silvaa1190322015-08-06 22:56:48 +00005386which is the string ``llvm.loop.unroll.disable``. For example:
Mark Heffernane6b4ba12014-07-23 17:31:37 +00005387
5388.. code-block:: llvm
5389
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00005390 !0 = !{!"llvm.loop.unroll.disable"}
Mark Heffernane6b4ba12014-07-23 17:31:37 +00005391
Kevin Qin715b01e2015-03-09 06:14:18 +00005392'``llvm.loop.unroll.runtime.disable``' Metadata
Dan Liew868b0742015-03-11 13:34:49 +00005393^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Kevin Qin715b01e2015-03-09 06:14:18 +00005394
Mark Heffernan3e32a4e2015-06-30 22:48:51 +00005395This metadata disables runtime loop unrolling. The metadata has a single
Sean Silvaa1190322015-08-06 22:56:48 +00005396operand which is the string ``llvm.loop.unroll.runtime.disable``. For example:
Kevin Qin715b01e2015-03-09 06:14:18 +00005397
5398.. code-block:: llvm
5399
5400 !0 = !{!"llvm.loop.unroll.runtime.disable"}
5401
Mark Heffernan89391542015-08-10 17:28:08 +00005402'``llvm.loop.unroll.enable``' Metadata
5403^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5404
5405This metadata suggests that the loop should be fully unrolled if the trip count
5406is known at compile time and partially unrolled if the trip count is not known
5407at compile time. The metadata has a single operand which is the string
5408``llvm.loop.unroll.enable``. For example:
5409
5410.. code-block:: llvm
5411
5412 !0 = !{!"llvm.loop.unroll.enable"}
5413
Mark Heffernane6b4ba12014-07-23 17:31:37 +00005414'``llvm.loop.unroll.full``' Metadata
5415^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5416
Mark Heffernan3e32a4e2015-06-30 22:48:51 +00005417This metadata suggests that the loop should be unrolled fully. The
5418metadata has a single operand which is the string ``llvm.loop.unroll.full``.
Mark Heffernane6b4ba12014-07-23 17:31:37 +00005419For example:
5420
5421.. code-block:: llvm
5422
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00005423 !0 = !{!"llvm.loop.unroll.full"}
Pekka Jaaskelainen0d237252013-02-13 18:08:57 +00005424
Michael Kruse72448522018-12-12 17:32:52 +00005425'``llvm.loop.unroll.followup``' Metadata
5426^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5427
5428This metadata defines which loop attributes the unrolled loop will have.
5429See :ref:`Transformation Metadata <transformation-metadata>` for details.
5430
5431'``llvm.loop.unroll.followup_remainder``' Metadata
5432^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5433
5434This metadata defines which loop attributes the remainder loop after
5435partial/runtime unrolling will have. See
5436:ref:`Transformation Metadata <transformation-metadata>` for details.
5437
David Green7fbf06c2018-07-19 12:37:00 +00005438'``llvm.loop.unroll_and_jam``'
5439^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5440
5441This metadata is treated very similarly to the ``llvm.loop.unroll`` metadata
5442above, but affect the unroll and jam pass. In addition any loop with
5443``llvm.loop.unroll`` metadata but no ``llvm.loop.unroll_and_jam`` metadata will
5444disable unroll and jam (so ``llvm.loop.unroll`` metadata will be left to the
5445unroller, plus ``llvm.loop.unroll.disable`` metadata will disable unroll and jam
5446too.)
5447
5448The metadata for unroll and jam otherwise is the same as for ``unroll``.
5449``llvm.loop.unroll_and_jam.enable``, ``llvm.loop.unroll_and_jam.disable`` and
5450``llvm.loop.unroll_and_jam.count`` do the same as for unroll.
5451``llvm.loop.unroll_and_jam.full`` is not supported. Again these are only hints
5452and the normal safety checks will still be performed.
5453
5454'``llvm.loop.unroll_and_jam.count``' Metadata
5455^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5456
5457This metadata suggests an unroll and jam factor to use, similarly to
5458``llvm.loop.unroll.count``. The first operand is the string
5459``llvm.loop.unroll_and_jam.count`` and the second operand is a positive integer
5460specifying the unroll factor. For example:
5461
5462.. code-block:: llvm
5463
5464 !0 = !{!"llvm.loop.unroll_and_jam.count", i32 4}
5465
5466If the trip count of the loop is less than the unroll count the loop
5467will be partially unroll and jammed.
5468
5469'``llvm.loop.unroll_and_jam.disable``' Metadata
5470^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5471
5472This metadata disables loop unroll and jamming. The metadata has a single
5473operand which is the string ``llvm.loop.unroll_and_jam.disable``. For example:
5474
5475.. code-block:: llvm
5476
5477 !0 = !{!"llvm.loop.unroll_and_jam.disable"}
5478
5479'``llvm.loop.unroll_and_jam.enable``' Metadata
5480^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5481
5482This metadata suggests that the loop should be fully unroll and jammed if the
5483trip count is known at compile time and partially unrolled if the trip count is
5484not known at compile time. The metadata has a single operand which is the
5485string ``llvm.loop.unroll_and_jam.enable``. For example:
5486
5487.. code-block:: llvm
5488
5489 !0 = !{!"llvm.loop.unroll_and_jam.enable"}
5490
Michael Kruse72448522018-12-12 17:32:52 +00005491'``llvm.loop.unroll_and_jam.followup_outer``' Metadata
5492^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5493
5494This metadata defines which loop attributes the outer unrolled loop will
5495have. See :ref:`Transformation Metadata <transformation-metadata>` for
5496details.
5497
5498'``llvm.loop.unroll_and_jam.followup_inner``' Metadata
5499^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5500
5501This metadata defines which loop attributes the inner jammed loop will
5502have. See :ref:`Transformation Metadata <transformation-metadata>` for
5503details.
5504
5505'``llvm.loop.unroll_and_jam.followup_remainder_outer``' Metadata
5506^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5507
5508This metadata defines which attributes the epilogue of the outer loop
5509will have. This loop is usually unrolled, meaning there is no such
5510loop. This attribute will be ignored in this case. See
5511:ref:`Transformation Metadata <transformation-metadata>` for details.
5512
5513'``llvm.loop.unroll_and_jam.followup_remainder_inner``' Metadata
5514^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5515
5516This metadata defines which attributes the inner loop of the epilogue
5517will have. The outer epilogue will usually be unrolled, meaning there
5518can be multiple inner remainder loops. See
5519:ref:`Transformation Metadata <transformation-metadata>` for details.
5520
5521'``llvm.loop.unroll_and_jam.followup_all``' Metadata
5522^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5523
5524Attributes specified in the metadata is added to all
5525``llvm.loop.unroll_and_jam.*`` loops. See
5526:ref:`Transformation Metadata <transformation-metadata>` for details.
5527
Ashutosh Nemadf6763a2016-02-06 07:47:48 +00005528'``llvm.loop.licm_versioning.disable``' Metadata
Ashutosh Nema5f0e4722016-02-06 09:24:37 +00005529^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Ashutosh Nemadf6763a2016-02-06 07:47:48 +00005530
5531This metadata indicates that the loop should not be versioned for the purpose
5532of enabling loop-invariant code motion (LICM). The metadata has a single operand
5533which is the string ``llvm.loop.licm_versioning.disable``. For example:
5534
5535.. code-block:: llvm
5536
5537 !0 = !{!"llvm.loop.licm_versioning.disable"}
5538
Adam Nemetd2fa4142016-04-27 05:28:18 +00005539'``llvm.loop.distribute.enable``' Metadata
Adam Nemet55dc0af2016-04-27 05:59:51 +00005540^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Adam Nemetd2fa4142016-04-27 05:28:18 +00005541
5542Loop distribution allows splitting a loop into multiple loops. Currently,
5543this is only performed if the entire loop cannot be vectorized due to unsafe
Hiroshi Inoueb93daec2017-07-02 12:44:27 +00005544memory dependencies. The transformation will attempt to isolate the unsafe
Adam Nemetd2fa4142016-04-27 05:28:18 +00005545dependencies into their own loop.
5546
5547This metadata can be used to selectively enable or disable distribution of the
5548loop. The first operand is the string ``llvm.loop.distribute.enable`` and the
5549second operand is a bit. If the bit operand value is 1 distribution is
5550enabled. A value of 0 disables distribution:
5551
5552.. code-block:: llvm
5553
5554 !0 = !{!"llvm.loop.distribute.enable", i1 0}
5555 !1 = !{!"llvm.loop.distribute.enable", i1 1}
5556
5557This metadata should be used in conjunction with ``llvm.loop`` loop
5558identification metadata.
5559
Michael Kruse72448522018-12-12 17:32:52 +00005560'``llvm.loop.distribute.followup_coincident``' Metadata
5561^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5562
5563This metadata defines which attributes extracted loops with no cyclic
5564dependencies will have (i.e. can be vectorized). See
5565:ref:`Transformation Metadata <transformation-metadata>` for details.
5566
5567'``llvm.loop.distribute.followup_sequential``' Metadata
5568^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5569
5570This metadata defines which attributes the isolated loops with unsafe
5571memory dependencies will have. See
5572:ref:`Transformation Metadata <transformation-metadata>` for details.
5573
5574'``llvm.loop.distribute.followup_fallback``' Metadata
5575^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5576
5577If loop versioning is necessary, this metadata defined the attributes
5578the non-distributed fallback version will have. See
5579:ref:`Transformation Metadata <transformation-metadata>` for details.
5580
5581'``llvm.loop.distribute.followup_all``' Metadata
5582^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5583
5584Thes attributes in this metdata is added to all followup loops of the
5585loop distribution pass. See
5586:ref:`Transformation Metadata <transformation-metadata>` for details.
5587
Michael Kruse978ba612018-12-20 04:58:07 +00005588'``llvm.access.group``' Metadata
5589^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Pekka Jaaskelainen0d237252013-02-13 18:08:57 +00005590
Michael Kruse978ba612018-12-20 04:58:07 +00005591``llvm.access.group`` metadata can be attached to any instruction that
5592potentially accesses memory. It can point to a single distinct metadata
5593node, which we call access group. This node represents all memory access
5594instructions referring to it via ``llvm.access.group``. When an
5595instruction belongs to multiple access groups, it can also point to a
5596list of accesses groups, illustrated by the following example.
Pekka Jaaskelainen0d237252013-02-13 18:08:57 +00005597
Michael Kruse978ba612018-12-20 04:58:07 +00005598.. code-block:: llvm
Pekka Jaaskelainen0d237252013-02-13 18:08:57 +00005599
Michael Kruse978ba612018-12-20 04:58:07 +00005600 %val = load i32, i32* %arrayidx, !llvm.access.group !0
5601 ...
5602 !0 = !{!1, !2}
5603 !1 = distinct !{}
5604 !2 = distinct !{}
Pekka Jaaskelainen23b222cc2014-05-23 11:35:46 +00005605
Michael Kruse978ba612018-12-20 04:58:07 +00005606It is illegal for the list node to be empty since it might be confused
5607with an access group.
Pekka Jaaskelainen23b222cc2014-05-23 11:35:46 +00005608
Michael Kruse978ba612018-12-20 04:58:07 +00005609The access group metadata node must be 'distinct' to avoid collapsing
5610multiple access groups by content. A access group metadata node must
5611always be empty which can be used to distinguish an access group
5612metadata node from a list of access groups. Being empty avoids the
5613situation that the content must be updated which, because metadata is
5614immutable by design, would required finding and updating all references
5615to the access group node.
Pekka Jaaskelainen23b222cc2014-05-23 11:35:46 +00005616
Michael Kruse978ba612018-12-20 04:58:07 +00005617The access group can be used to refer to a memory access instruction
5618without pointing to it directly (which is not possible in global
5619metadata). Currently, the only metadata making use of it is
5620``llvm.loop.parallel_accesses``.
5621
5622'``llvm.loop.parallel_accesses``' Metadata
5623^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5624
5625The ``llvm.loop.parallel_accesses`` metadata refers to one or more
5626access group metadata nodes (see ``llvm.access.group``). It denotes that
5627no loop-carried memory dependence exist between it and other instructions
5628in the loop with this metadata.
5629
5630Let ``m1`` and ``m2`` be two instructions that both have the
5631``llvm.access.group`` metadata to the access group ``g1``, respectively
5632``g2`` (which might be identical). If a loop contains both access groups
5633in its ``llvm.loop.parallel_accesses`` metadata, then the compiler can
5634assume that there is no dependency between ``m1`` and ``m2`` carried by
5635this loop. Instructions that belong to multiple access groups are
5636considered having this property if at least one of the access groups
5637matches the ``llvm.loop.parallel_accesses`` list.
5638
5639If all memory-accessing instructions in a loop have
5640``llvm.loop.parallel_accesses`` metadata that refers to that loop, then the
5641loop has no loop carried memory dependences and is considered to be a
5642parallel loop.
5643
5644Note that if not all memory access instructions belong to an access
5645group referred to by ``llvm.loop.parallel_accesses``, then the loop must
5646not be considered trivially parallel. Additional
Sean Silvaa1190322015-08-06 22:56:48 +00005647memory dependence analysis is required to make that determination. As a fail
Mehdi Amini4a121fa2015-03-14 22:04:06 +00005648safe mechanism, this causes loops that were originally parallel to be considered
5649sequential (if optimization passes that are unaware of the parallel semantics
Pekka Jaaskelainen23b222cc2014-05-23 11:35:46 +00005650insert new memory instructions into the loop body).
Pekka Jaaskelainen0d237252013-02-13 18:08:57 +00005651
5652Example of a loop that is considered parallel due to its correct use of
Michael Kruse978ba612018-12-20 04:58:07 +00005653both ``llvm.access.group`` and ``llvm.loop.parallel_accesses``
5654metadata types.
Pekka Jaaskelainen0d237252013-02-13 18:08:57 +00005655
5656.. code-block:: llvm
5657
5658 for.body:
Paul Redmond5fdf8362013-05-28 20:00:34 +00005659 ...
Michael Kruse978ba612018-12-20 04:58:07 +00005660 %val0 = load i32, i32* %arrayidx, !llvm.access.group !1
Paul Redmond5fdf8362013-05-28 20:00:34 +00005661 ...
Michael Kruse978ba612018-12-20 04:58:07 +00005662 store i32 %val0, i32* %arrayidx1, !llvm.access.group !1
Paul Redmond5fdf8362013-05-28 20:00:34 +00005663 ...
5664 br i1 %exitcond, label %for.end, label %for.body, !llvm.loop !0
Pekka Jaaskelainen0d237252013-02-13 18:08:57 +00005665
5666 for.end:
5667 ...
Michael Kruse978ba612018-12-20 04:58:07 +00005668 !0 = distinct !{!0, !{!"llvm.loop.parallel_accesses", !1}}
5669 !1 = distinct !{}
Pekka Jaaskelainen0d237252013-02-13 18:08:57 +00005670
Michael Kruse978ba612018-12-20 04:58:07 +00005671It is also possible to have nested parallel loops:
Pekka Jaaskelainen0d237252013-02-13 18:08:57 +00005672
5673.. code-block:: llvm
5674
5675 outer.for.body:
Tobias Grosserfbe95dc2014-03-05 13:36:04 +00005676 ...
Michael Kruse978ba612018-12-20 04:58:07 +00005677 %val1 = load i32, i32* %arrayidx3, !llvm.access.group !4
Tobias Grosserfbe95dc2014-03-05 13:36:04 +00005678 ...
5679 br label %inner.for.body
Pekka Jaaskelainen0d237252013-02-13 18:08:57 +00005680
5681 inner.for.body:
Paul Redmond5fdf8362013-05-28 20:00:34 +00005682 ...
Michael Kruse978ba612018-12-20 04:58:07 +00005683 %val0 = load i32, i32* %arrayidx1, !llvm.access.group !3
Paul Redmond5fdf8362013-05-28 20:00:34 +00005684 ...
Michael Kruse978ba612018-12-20 04:58:07 +00005685 store i32 %val0, i32* %arrayidx2, !llvm.access.group !3
Paul Redmond5fdf8362013-05-28 20:00:34 +00005686 ...
5687 br i1 %exitcond, label %inner.for.end, label %inner.for.body, !llvm.loop !1
Pekka Jaaskelainen0d237252013-02-13 18:08:57 +00005688
5689 inner.for.end:
Paul Redmond5fdf8362013-05-28 20:00:34 +00005690 ...
Michael Kruse978ba612018-12-20 04:58:07 +00005691 store i32 %val1, i32* %arrayidx4, !llvm.access.group !4
Paul Redmond5fdf8362013-05-28 20:00:34 +00005692 ...
5693 br i1 %exitcond, label %outer.for.end, label %outer.for.body, !llvm.loop !2
Pekka Jaaskelainen0d237252013-02-13 18:08:57 +00005694
5695 outer.for.end: ; preds = %for.body
5696 ...
Michael Kruse978ba612018-12-20 04:58:07 +00005697 !1 = distinct !{!1, !{!"llvm.loop.parallel_accesses", !3}} ; metadata for the inner loop
5698 !2 = distinct !{!2, !{!"llvm.loop.parallel_accesses", !3, !4}} ; metadata for the outer loop
5699 !3 = distinct !{} ; access group for instructions in the inner loop (which are implicitly contained in outer loop as well)
5700 !4 = distinct !{} ; access group for instructions in the outer, but not the inner loop
Pekka Jaaskelainen0d237252013-02-13 18:08:57 +00005701
Hiroshi Yamauchidce9def2017-11-02 22:26:51 +00005702'``irr_loop``' Metadata
5703^^^^^^^^^^^^^^^^^^^^^^^
5704
5705``irr_loop`` metadata may be attached to the terminator instruction of a basic
5706block that's an irreducible loop header (note that an irreducible loop has more
5707than once header basic blocks.) If ``irr_loop`` metadata is attached to the
5708terminator instruction of a basic block that is not really an irreducible loop
5709header, the behavior is undefined. The intent of this metadata is to improve the
5710accuracy of the block frequency propagation. For example, in the code below, the
5711block ``header0`` may have a loop header weight (relative to the other headers of
5712the irreducible loop) of 100:
5713
5714.. code-block:: llvm
5715
5716 header0:
5717 ...
5718 br i1 %cmp, label %t1, label %t2, !irr_loop !0
5719
5720 ...
5721 !0 = !{"loop_header_weight", i64 100}
5722
5723Irreducible loop header weights are typically based on profile data.
5724
Piotr Padlewski6c15ec42015-09-15 18:32:14 +00005725'``invariant.group``' Metadata
5726^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5727
Mandeep Singh Grang547a0d72018-11-01 23:22:25 +00005728The experimental ``invariant.group`` metadata may be attached to
Piotr Padlewskice358262018-05-18 23:53:46 +00005729``load``/``store`` instructions referencing a single metadata with no entries.
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +00005730The existence of the ``invariant.group`` metadata on the instruction tells
5731the optimizer that every ``load`` and ``store`` to the same pointer operand
Piotr Padlewskice358262018-05-18 23:53:46 +00005732can be assumed to load or store the same
Piotr Padlewski5dde8092018-05-03 11:03:01 +00005733value (but see the ``llvm.launder.invariant.group`` intrinsic which affects
Piotr Padlewskida362152016-12-30 18:45:07 +00005734when two pointers are considered the same). Pointers returned by bitcast or
5735getelementptr with only zero indices are considered the same.
Piotr Padlewski6c15ec42015-09-15 18:32:14 +00005736
5737Examples:
5738
5739.. code-block:: llvm
5740
5741 @unknownPtr = external global i8
5742 ...
5743 %ptr = alloca i8
5744 store i8 42, i8* %ptr, !invariant.group !0
5745 call void @foo(i8* %ptr)
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +00005746
Piotr Padlewski6c15ec42015-09-15 18:32:14 +00005747 %a = load i8, i8* %ptr, !invariant.group !0 ; Can assume that value under %ptr didn't change
5748 call void @foo(i8* %ptr)
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +00005749
5750 %newPtr = call i8* @getPointer(i8* %ptr)
Piotr Padlewski6c15ec42015-09-15 18:32:14 +00005751 %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 +00005752
Piotr Padlewski6c15ec42015-09-15 18:32:14 +00005753 %unknownValue = load i8, i8* @unknownPtr
5754 store i8 %unknownValue, i8* %ptr, !invariant.group !0 ; Can assume that %unknownValue == 42
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +00005755
Piotr Padlewski6c15ec42015-09-15 18:32:14 +00005756 call void @foo(i8* %ptr)
Piotr Padlewski5dde8092018-05-03 11:03:01 +00005757 %newPtr2 = call i8* @llvm.launder.invariant.group(i8* %ptr)
5758 %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 +00005759
Piotr Padlewski6c15ec42015-09-15 18:32:14 +00005760 ...
5761 declare void @foo(i8*)
5762 declare i8* @getPointer(i8*)
Piotr Padlewski5dde8092018-05-03 11:03:01 +00005763 declare i8* @llvm.launder.invariant.group(i8*)
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +00005764
Piotr Padlewskice358262018-05-18 23:53:46 +00005765 !0 = !{}
Piotr Padlewski6c15ec42015-09-15 18:32:14 +00005766
Piotr Padlewskif8486e32017-04-12 07:59:35 +00005767The invariant.group metadata must be dropped when replacing one pointer by
5768another based on aliasing information. This is because invariant.group is tied
5769to the SSA value of the pointer operand.
5770
5771.. code-block:: llvm
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +00005772
Piotr Padlewskif8486e32017-04-12 07:59:35 +00005773 %v = load i8, i8* %x, !invariant.group !0
5774 ; if %x mustalias %y then we can replace the above instruction with
5775 %v = load i8, i8* %y
5776
Piotr Padlewski74b155f2018-04-08 13:53:04 +00005777Note that this is an experimental feature, which means that its semantics might
5778change in the future.
Piotr Padlewskif8486e32017-04-12 07:59:35 +00005779
Peter Collingbournea333db82016-07-26 22:31:30 +00005780'``type``' Metadata
5781^^^^^^^^^^^^^^^^^^^
5782
5783See :doc:`TypeMetadata`.
Piotr Padlewski6c15ec42015-09-15 18:32:14 +00005784
Evgeniy Stepanov51c962f722017-03-17 22:17:24 +00005785'``associated``' Metadata
Evgeniy Stepanov4d490de2017-03-17 22:31:13 +00005786^^^^^^^^^^^^^^^^^^^^^^^^^
Evgeniy Stepanov51c962f722017-03-17 22:17:24 +00005787
5788The ``associated`` metadata may be attached to a global object
5789declaration with a single argument that references another global object.
5790
5791This metadata prevents discarding of the global object in linker GC
5792unless the referenced object is also discarded. The linker support for
5793this feature is spotty. For best compatibility, globals carrying this
5794metadata may also:
5795
5796- Be in a comdat with the referenced global.
5797- Be in @llvm.compiler.used.
5798- Have an explicit section with a name which is a valid C identifier.
5799
5800It does not have any effect on non-ELF targets.
5801
5802Example:
5803
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +00005804.. code-block:: text
Evgeniy Stepanov4d490de2017-03-17 22:31:13 +00005805
Evgeniy Stepanov51c962f722017-03-17 22:17:24 +00005806 $a = comdat any
5807 @a = global i32 1, comdat $a
5808 @b = internal global i32 2, comdat $a, section "abc", !associated !0
5809 !0 = !{i32* @a}
5810
Piotr Padlewski6c15ec42015-09-15 18:32:14 +00005811
Teresa Johnsond72f51c2017-06-15 15:57:12 +00005812'``prof``' Metadata
5813^^^^^^^^^^^^^^^^^^^
5814
5815The ``prof`` metadata is used to record profile data in the IR.
5816The first operand of the metadata node indicates the profile metadata
5817type. There are currently 3 types:
5818:ref:`branch_weights<prof_node_branch_weights>`,
5819:ref:`function_entry_count<prof_node_function_entry_count>`, and
5820:ref:`VP<prof_node_VP>`.
5821
5822.. _prof_node_branch_weights:
5823
5824branch_weights
5825""""""""""""""
5826
5827Branch weight metadata attached to a branch, select, switch or call instruction
5828represents the likeliness of the associated branch being taken.
5829For more information, see :doc:`BranchWeightMetadata`.
5830
5831.. _prof_node_function_entry_count:
5832
5833function_entry_count
5834""""""""""""""""""""
5835
5836Function entry count metadata can be attached to function definitions
5837to record the number of times the function is called. Used with BFI
5838information, it is also used to derive the basic block profile count.
5839For more information, see :doc:`BranchWeightMetadata`.
5840
5841.. _prof_node_VP:
5842
5843VP
5844""
5845
5846VP (value profile) metadata can be attached to instructions that have
5847value profile information. Currently this is indirect calls (where it
5848records the hottest callees) and calls to memory intrinsics such as memcpy,
5849memmove, and memset (where it records the hottest byte lengths).
5850
5851Each VP metadata node contains "VP" string, then a uint32_t value for the value
5852profiling kind, a uint64_t value for the total number of times the instruction
5853is executed, followed by uint64_t value and execution count pairs.
5854The value profiling kind is 0 for indirect call targets and 1 for memory
5855operations. For indirect call targets, each profile value is a hash
5856of the callee function name, and for memory operations each value is the
5857byte length.
5858
5859Note that the value counts do not need to add up to the total count
5860listed in the third operand (in practice only the top hottest values
5861are tracked and reported).
5862
5863Indirect call example:
5864
5865.. code-block:: llvm
5866
5867 call void %f(), !prof !1
5868 !1 = !{!"VP", i32 0, i64 1600, i64 7651369219802541373, i64 1030, i64 -4377547752858689819, i64 410}
5869
5870Note that the VP type is 0 (the second operand), which indicates this is
5871an indirect call value profile data. The third operand indicates that the
5872indirect call executed 1600 times. The 4th and 6th operands give the
5873hashes of the 2 hottest target functions' names (this is the same hash used
5874to represent function names in the profile database), and the 5th and 7th
5875operands give the execution count that each of the respective prior target
5876functions was called.
5877
Sean Silvab084af42012-12-07 10:36:55 +00005878Module Flags Metadata
5879=====================
5880
5881Information about the module as a whole is difficult to convey to LLVM's
5882subsystems. The LLVM IR isn't sufficient to transmit this information.
5883The ``llvm.module.flags`` named metadata exists in order to facilitate
Dmitri Gribenkoe8131122013-01-19 20:34:20 +00005884this. These flags are in the form of key / value pairs --- much like a
5885dictionary --- making it easy for any subsystem who cares about a flag to
Sean Silvab084af42012-12-07 10:36:55 +00005886look it up.
5887
5888The ``llvm.module.flags`` metadata contains a list of metadata triplets.
5889Each triplet has the following form:
5890
5891- The first element is a *behavior* flag, which specifies the behavior
5892 when two (or more) modules are merged together, and it encounters two
5893 (or more) metadata with the same ID. The supported behaviors are
5894 described below.
5895- The second element is a metadata string that is a unique ID for the
Daniel Dunbar25c4b572013-01-15 01:22:53 +00005896 metadata. Each module may only have one flag entry for each unique ID (not
5897 including entries with the **Require** behavior).
Sean Silvab084af42012-12-07 10:36:55 +00005898- The third element is the value of the flag.
5899
5900When two (or more) modules are merged together, the resulting
Daniel Dunbar25c4b572013-01-15 01:22:53 +00005901``llvm.module.flags`` metadata is the union of the modules' flags. That is, for
5902each unique metadata ID string, there will be exactly one entry in the merged
5903modules ``llvm.module.flags`` metadata table, and the value for that entry will
5904be determined by the merge behavior flag, as described below. The only exception
5905is that entries with the *Require* behavior are always preserved.
Sean Silvab084af42012-12-07 10:36:55 +00005906
5907The following behaviors are supported:
5908
5909.. list-table::
5910 :header-rows: 1
5911 :widths: 10 90
5912
5913 * - Value
5914 - Behavior
5915
5916 * - 1
5917 - **Error**
Daniel Dunbar25c4b572013-01-15 01:22:53 +00005918 Emits an error if two values disagree, otherwise the resulting value
5919 is that of the operands.
Sean Silvab084af42012-12-07 10:36:55 +00005920
5921 * - 2
5922 - **Warning**
Daniel Dunbar25c4b572013-01-15 01:22:53 +00005923 Emits a warning if two values disagree. The result value will be the
5924 operand for the flag from the first module being linked.
Sean Silvab084af42012-12-07 10:36:55 +00005925
5926 * - 3
5927 - **Require**
Daniel Dunbar25c4b572013-01-15 01:22:53 +00005928 Adds a requirement that another module flag be present and have a
5929 specified value after linking is performed. The value must be a
5930 metadata pair, where the first element of the pair is the ID of the
5931 module flag to be restricted, and the second element of the pair is
5932 the value the module flag should be restricted to. This behavior can
5933 be used to restrict the allowable results (via triggering of an
5934 error) of linking IDs with the **Override** behavior.
Sean Silvab084af42012-12-07 10:36:55 +00005935
5936 * - 4
5937 - **Override**
Daniel Dunbar25c4b572013-01-15 01:22:53 +00005938 Uses the specified value, regardless of the behavior or value of the
5939 other module. If both modules specify **Override**, but the values
5940 differ, an error will be emitted.
5941
Daniel Dunbard77d9fb2013-01-16 21:38:56 +00005942 * - 5
5943 - **Append**
5944 Appends the two values, which are required to be metadata nodes.
5945
5946 * - 6
5947 - **AppendUnique**
5948 Appends the two values, which are required to be metadata
5949 nodes. However, duplicate entries in the second list are dropped
5950 during the append operation.
5951
Steven Wu86a511e2017-08-15 16:16:33 +00005952 * - 7
5953 - **Max**
5954 Takes the max of the two values, which are required to be integers.
5955
Daniel Dunbar25c4b572013-01-15 01:22:53 +00005956It is an error for a particular unique flag ID to have multiple behaviors,
5957except in the case of **Require** (which adds restrictions on another metadata
5958value) or **Override**.
Sean Silvab084af42012-12-07 10:36:55 +00005959
5960An example of module flags:
5961
5962.. code-block:: llvm
5963
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00005964 !0 = !{ i32 1, !"foo", i32 1 }
5965 !1 = !{ i32 4, !"bar", i32 37 }
5966 !2 = !{ i32 2, !"qux", i32 42 }
5967 !3 = !{ i32 3, !"qux",
5968 !{
5969 !"foo", i32 1
Sean Silvab084af42012-12-07 10:36:55 +00005970 }
5971 }
5972 !llvm.module.flags = !{ !0, !1, !2, !3 }
5973
5974- Metadata ``!0`` has the ID ``!"foo"`` and the value '1'. The behavior
5975 if two or more ``!"foo"`` flags are seen is to emit an error if their
5976 values are not equal.
5977
5978- Metadata ``!1`` has the ID ``!"bar"`` and the value '37'. The
5979 behavior if two or more ``!"bar"`` flags are seen is to use the value
Daniel Dunbar25c4b572013-01-15 01:22:53 +00005980 '37'.
Sean Silvab084af42012-12-07 10:36:55 +00005981
5982- Metadata ``!2`` has the ID ``!"qux"`` and the value '42'. The
5983 behavior if two or more ``!"qux"`` flags are seen is to emit a
5984 warning if their values are not equal.
5985
5986- Metadata ``!3`` has the ID ``!"qux"`` and the value:
5987
5988 ::
5989
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00005990 !{ !"foo", i32 1 }
Sean Silvab084af42012-12-07 10:36:55 +00005991
Daniel Dunbar25c4b572013-01-15 01:22:53 +00005992 The behavior is to emit an error if the ``llvm.module.flags`` does not
5993 contain a flag with the ID ``!"foo"`` that has the value '1' after linking is
5994 performed.
Sean Silvab084af42012-12-07 10:36:55 +00005995
5996Objective-C Garbage Collection Module Flags Metadata
5997----------------------------------------------------
5998
5999On the Mach-O platform, Objective-C stores metadata about garbage
6000collection in a special section called "image info". The metadata
6001consists of a version number and a bitmask specifying what types of
6002garbage collection are supported (if any) by the file. If two or more
6003modules are linked together their garbage collection metadata needs to
6004be merged rather than appended together.
6005
6006The Objective-C garbage collection module flags metadata consists of the
6007following key-value pairs:
6008
6009.. list-table::
6010 :header-rows: 1
6011 :widths: 30 70
6012
6013 * - Key
6014 - Value
6015
Daniel Dunbar1dc66ca2013-01-17 18:57:32 +00006016 * - ``Objective-C Version``
Dmitri Gribenkoe8131122013-01-19 20:34:20 +00006017 - **[Required]** --- The Objective-C ABI version. Valid values are 1 and 2.
Sean Silvab084af42012-12-07 10:36:55 +00006018
Daniel Dunbar1dc66ca2013-01-17 18:57:32 +00006019 * - ``Objective-C Image Info Version``
Dmitri Gribenkoe8131122013-01-19 20:34:20 +00006020 - **[Required]** --- The version of the image info section. Currently
Sean Silvab084af42012-12-07 10:36:55 +00006021 always 0.
6022
Daniel Dunbar1dc66ca2013-01-17 18:57:32 +00006023 * - ``Objective-C Image Info Section``
Dmitri Gribenkoe8131122013-01-19 20:34:20 +00006024 - **[Required]** --- The section to place the metadata. Valid values are
Sean Silvab084af42012-12-07 10:36:55 +00006025 ``"__OBJC, __image_info, regular"`` for Objective-C ABI version 1, and
6026 ``"__DATA,__objc_imageinfo, regular, no_dead_strip"`` for
6027 Objective-C ABI version 2.
6028
Daniel Dunbar1dc66ca2013-01-17 18:57:32 +00006029 * - ``Objective-C Garbage Collection``
Dmitri Gribenkoe8131122013-01-19 20:34:20 +00006030 - **[Required]** --- Specifies whether garbage collection is supported or
Sean Silvab084af42012-12-07 10:36:55 +00006031 not. Valid values are 0, for no garbage collection, and 2, for garbage
6032 collection supported.
6033
Daniel Dunbar1dc66ca2013-01-17 18:57:32 +00006034 * - ``Objective-C GC Only``
Dmitri Gribenkoe8131122013-01-19 20:34:20 +00006035 - **[Optional]** --- Specifies that only garbage collection is supported.
Sean Silvab084af42012-12-07 10:36:55 +00006036 If present, its value must be 6. This flag requires that the
6037 ``Objective-C Garbage Collection`` flag have the value 2.
6038
6039Some important flag interactions:
6040
6041- If a module with ``Objective-C Garbage Collection`` set to 0 is
6042 merged with a module with ``Objective-C Garbage Collection`` set to
6043 2, then the resulting module has the
6044 ``Objective-C Garbage Collection`` flag set to 0.
6045- A module with ``Objective-C Garbage Collection`` set to 0 cannot be
6046 merged with a module with ``Objective-C GC Only`` set to 6.
6047
Oliver Stannard5dc29342014-06-20 10:08:11 +00006048C type width Module Flags Metadata
6049----------------------------------
6050
6051The ARM backend emits a section into each generated object file describing the
6052options that it was compiled with (in a compiler-independent way) to prevent
6053linking incompatible objects, and to allow automatic library selection. Some
6054of these options are not visible at the IR level, namely wchar_t width and enum
6055width.
6056
6057To pass this information to the backend, these options are encoded in module
6058flags metadata, using the following key-value pairs:
6059
6060.. list-table::
6061 :header-rows: 1
6062 :widths: 30 70
6063
6064 * - Key
6065 - Value
6066
6067 * - short_wchar
6068 - * 0 --- sizeof(wchar_t) == 4
6069 * 1 --- sizeof(wchar_t) == 2
6070
6071 * - short_enum
6072 - * 0 --- Enums are at least as large as an ``int``.
6073 * 1 --- Enums are stored in the smallest integer type which can
6074 represent all of its values.
6075
6076For example, the following metadata section specifies that the module was
6077compiled with a ``wchar_t`` width of 4 bytes, and the underlying type of an
6078enum is the smallest type which can represent all of its values::
6079
6080 !llvm.module.flags = !{!0, !1}
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +00006081 !0 = !{i32 1, !"short_wchar", i32 1}
6082 !1 = !{i32 1, !"short_enum", i32 0}
Oliver Stannard5dc29342014-06-20 10:08:11 +00006083
Peter Collingbourne89061b22017-06-12 20:10:48 +00006084Automatic Linker Flags Named Metadata
6085=====================================
6086
Ben Dunbobbin1d165152019-05-17 03:44:15 +00006087Some targets support embedding of flags to the linker inside individual object
Peter Collingbourne89061b22017-06-12 20:10:48 +00006088files. Typically this is used in conjunction with language extensions which
Ben Dunbobbin1d165152019-05-17 03:44:15 +00006089allow source files to contain linker command line options, and have these
6090automatically be transmitted to the linker via object files.
Peter Collingbourne89061b22017-06-12 20:10:48 +00006091
6092These flags are encoded in the IR using named metadata with the name
6093``!llvm.linker.options``. Each operand is expected to be a metadata node
6094which should be a list of other metadata nodes, each of which should be a
6095list of metadata strings defining linker options.
6096
6097For example, the following metadata section specifies two separate sets of
6098linker options, presumably to link against ``libz`` and the ``Cocoa``
6099framework::
6100
Ben Dunbobbin1d165152019-05-17 03:44:15 +00006101 !0 = !{ !"-lz" }
6102 !1 = !{ !"-framework", !"Cocoa" }
Peter Collingbourne89061b22017-06-12 20:10:48 +00006103 !llvm.linker.options = !{ !0, !1 }
6104
6105The metadata encoding as lists of lists of options, as opposed to a collapsed
6106list of options, is chosen so that the IR encoding can use multiple option
6107strings to specify e.g., a single library, while still having that specifier be
6108preserved as an atomic element that can be recognized by a target specific
6109assembly writer or object file emitter.
6110
6111Each individual option is required to be either a valid option for the target's
6112linker, or an option that is reserved by the target specific assembly writer or
6113object file emitter. No other aspect of these options is defined by the IR.
6114
Ben Dunbobbin1d165152019-05-17 03:44:15 +00006115Dependent Libs Named Metadata
6116=============================
6117
6118Some targets support embedding of strings into object files to indicate
6119a set of libraries to add to the link. Typically this is used in conjunction
6120with language extensions which allow source files to explicitly declare the
6121libraries they depend on, and have these automatically be transmitted to the
6122linker via object files.
6123
6124The list is encoded in the IR using named metadata with the name
6125``!llvm.dependent-libraries``. Each operand is expected to be a metadata node
6126which should contain a single string operand.
6127
6128For example, the following metadata section contains two library specfiers::
6129
6130 !0 = !{!"a library specifier"}
6131 !1 = !{!"another library specifier"}
6132 !llvm.dependent-libraries = !{ !0, !1 }
6133
6134Each library specifier will be handled independently by the consuming linker.
6135The effect of the library specifiers are defined by the consuming linker.
6136
Teresa Johnson08d5b4e2018-05-26 02:34:13 +00006137.. _summary:
6138
6139ThinLTO Summary
6140===============
6141
6142Compiling with `ThinLTO <https://clang.llvm.org/docs/ThinLTO.html>`_
6143causes the building of a compact summary of the module that is emitted into
6144the bitcode. The summary is emitted into the LLVM assembly and identified
6145in syntax by a caret ('``^``').
6146
Teresa Johnsonab2a7f02018-09-18 13:44:13 +00006147The summary is parsed into a bitcode output, along with the Module
Teresa Johnson08d5b4e2018-05-26 02:34:13 +00006148IR, via the "``llvm-as``" tool. Tools that parse the Module IR for the purposes
6149of optimization (e.g. "``clang -x ir``" and "``opt``"), will ignore the
6150summary entries (just as they currently ignore summary entries in a bitcode
6151input file).
6152
Teresa Johnsonab2a7f02018-09-18 13:44:13 +00006153Eventually, the summary will be parsed into a ModuleSummaryIndex object under
6154the same conditions where summary index is currently built from bitcode.
6155Specifically, tools that test the Thin Link portion of a ThinLTO compile
6156(i.e. llvm-lto and llvm-lto2), or when parsing a combined index
6157for a distributed ThinLTO backend via clang's "``-fthinlto-index=<>``" flag
6158(this part is not yet implemented, use llvm-as to create a bitcode object
6159before feeding into thin link tools for now).
6160
Teresa Johnson08d5b4e2018-05-26 02:34:13 +00006161There are currently 3 types of summary entries in the LLVM assembly:
6162:ref:`module paths<module_path_summary>`,
6163:ref:`global values<gv_summary>`, and
6164:ref:`type identifiers<typeid_summary>`.
6165
6166.. _module_path_summary:
6167
6168Module Path Summary Entry
6169-------------------------
6170
6171Each module path summary entry lists a module containing global values included
6172in the summary. For a single IR module there will be one such entry, but
6173in a combined summary index produced during the thin link, there will be
6174one module path entry per linked module with summary.
6175
6176Example:
6177
Chandler Carruth3a56e3f2018-08-06 09:46:59 +00006178.. code-block:: text
Teresa Johnson08d5b4e2018-05-26 02:34:13 +00006179
6180 ^0 = module: (path: "/path/to/file.o", hash: (2468601609, 1329373163, 1565878005, 638838075, 3148790418))
6181
6182The ``path`` field is a string path to the bitcode file, and the ``hash``
6183field is the 160-bit SHA-1 hash of the IR bitcode contents, used for
6184incremental builds and caching.
6185
6186.. _gv_summary:
6187
6188Global Value Summary Entry
6189--------------------------
6190
6191Each global value summary entry corresponds to a global value defined or
6192referenced by a summarized module.
6193
6194Example:
6195
Chandler Carruth3a56e3f2018-08-06 09:46:59 +00006196.. code-block:: text
Teresa Johnson08d5b4e2018-05-26 02:34:13 +00006197
6198 ^4 = gv: (name: "f"[, summaries: (Summary)[, (Summary)]*]?) ; guid = 14740650423002898831
6199
6200For declarations, there will not be a summary list. For definitions, a
6201global value will contain a list of summaries, one per module containing
6202a definition. There can be multiple entries in a combined summary index
6203for symbols with weak linkage.
6204
6205Each ``Summary`` format will depend on whether the global value is a
6206:ref:`function<function_summary>`, :ref:`variable<variable_summary>`, or
6207:ref:`alias<alias_summary>`.
6208
6209.. _function_summary:
6210
6211Function Summary
6212^^^^^^^^^^^^^^^^
6213
6214If the global value is a function, the ``Summary`` entry will look like:
6215
Chandler Carruth3a56e3f2018-08-06 09:46:59 +00006216.. code-block:: text
Teresa Johnson08d5b4e2018-05-26 02:34:13 +00006217
6218 function: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0), insts: 2[, FuncFlags]?[, Calls]?[, TypeIdInfo]?[, Refs]?
6219
6220The ``module`` field includes the summary entry id for the module containing
6221this definition, and the ``flags`` field contains information such as
6222the linkage type, a flag indicating whether it is legal to import the
6223definition, whether it is globally live and whether the linker resolved it
6224to a local definition (the latter two are populated during the thin link).
6225The ``insts`` field contains the number of IR instructions in the function.
6226Finally, there are several optional fields: :ref:`FuncFlags<funcflags_summary>`,
6227:ref:`Calls<calls_summary>`, :ref:`TypeIdInfo<typeidinfo_summary>`,
6228:ref:`Refs<refs_summary>`.
6229
6230.. _variable_summary:
6231
6232Global Variable Summary
6233^^^^^^^^^^^^^^^^^^^^^^^
6234
6235If the global value is a variable, the ``Summary`` entry will look like:
6236
Chandler Carruth3a56e3f2018-08-06 09:46:59 +00006237.. code-block:: text
Teresa Johnson08d5b4e2018-05-26 02:34:13 +00006238
6239 variable: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0)[, Refs]?
6240
6241The variable entry contains a subset of the fields in a
6242:ref:`function summary <function_summary>`, see the descriptions there.
6243
6244.. _alias_summary:
6245
6246Alias Summary
6247^^^^^^^^^^^^^
6248
6249If the global value is an alias, the ``Summary`` entry will look like:
6250
Chandler Carruth3a56e3f2018-08-06 09:46:59 +00006251.. code-block:: text
Teresa Johnson08d5b4e2018-05-26 02:34:13 +00006252
6253 alias: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0), aliasee: ^2)
6254
6255The ``module`` and ``flags`` fields are as described for a
6256:ref:`function summary <function_summary>`. The ``aliasee`` field
6257contains a reference to the global value summary entry of the aliasee.
6258
6259.. _funcflags_summary:
6260
6261Function Flags
6262^^^^^^^^^^^^^^
6263
6264The optional ``FuncFlags`` field looks like:
6265
Chandler Carruth3a56e3f2018-08-06 09:46:59 +00006266.. code-block:: text
Teresa Johnson08d5b4e2018-05-26 02:34:13 +00006267
6268 funcFlags: (readNone: 0, readOnly: 0, noRecurse: 0, returnDoesNotAlias: 0)
6269
6270If unspecified, flags are assumed to hold the conservative ``false`` value of
6271``0``.
6272
6273.. _calls_summary:
6274
6275Calls
6276^^^^^
6277
6278The optional ``Calls`` field looks like:
6279
Chandler Carruth3a56e3f2018-08-06 09:46:59 +00006280.. code-block:: text
Teresa Johnson08d5b4e2018-05-26 02:34:13 +00006281
6282 calls: ((Callee)[, (Callee)]*)
6283
6284where each ``Callee`` looks like:
6285
Chandler Carruth3a56e3f2018-08-06 09:46:59 +00006286.. code-block:: text
Teresa Johnson08d5b4e2018-05-26 02:34:13 +00006287
6288 callee: ^1[, hotness: None]?[, relbf: 0]?
6289
6290The ``callee`` refers to the summary entry id of the callee. At most one
6291of ``hotness`` (which can take the values ``Unknown``, ``Cold``, ``None``,
6292``Hot``, and ``Critical``), and ``relbf`` (which holds the integer
6293branch frequency relative to the entry frequency, scaled down by 2^8)
6294may be specified. The defaults are ``Unknown`` and ``0``, respectively.
6295
6296.. _refs_summary:
6297
6298Refs
6299^^^^
6300
6301The optional ``Refs`` field looks like:
6302
Chandler Carruth3a56e3f2018-08-06 09:46:59 +00006303.. code-block:: text
Teresa Johnson08d5b4e2018-05-26 02:34:13 +00006304
6305 refs: ((Ref)[, (Ref)]*)
6306
6307where each ``Ref`` contains a reference to the summary id of the referenced
6308value (e.g. ``^1``).
6309
6310.. _typeidinfo_summary:
6311
6312TypeIdInfo
6313^^^^^^^^^^
6314
6315The optional ``TypeIdInfo`` field, used for
6316`Control Flow Integrity <http://clang.llvm.org/docs/ControlFlowIntegrity.html>`_,
6317looks like:
6318
Chandler Carruth3a56e3f2018-08-06 09:46:59 +00006319.. code-block:: text
Teresa Johnson08d5b4e2018-05-26 02:34:13 +00006320
6321 typeIdInfo: [(TypeTests)]?[, (TypeTestAssumeVCalls)]?[, (TypeCheckedLoadVCalls)]?[, (TypeTestAssumeConstVCalls)]?[, (TypeCheckedLoadConstVCalls)]?
6322
6323These optional fields have the following forms:
6324
6325TypeTests
6326"""""""""
6327
Chandler Carruth3a56e3f2018-08-06 09:46:59 +00006328.. code-block:: text
Teresa Johnson08d5b4e2018-05-26 02:34:13 +00006329
6330 typeTests: (TypeIdRef[, TypeIdRef]*)
6331
6332Where each ``TypeIdRef`` refers to a :ref:`type id<typeid_summary>`
6333by summary id or ``GUID``.
6334
6335TypeTestAssumeVCalls
6336""""""""""""""""""""
6337
Chandler Carruth3a56e3f2018-08-06 09:46:59 +00006338.. code-block:: text
Teresa Johnson08d5b4e2018-05-26 02:34:13 +00006339
6340 typeTestAssumeVCalls: (VFuncId[, VFuncId]*)
6341
6342Where each VFuncId has the format:
6343
Chandler Carruth3a56e3f2018-08-06 09:46:59 +00006344.. code-block:: text
Teresa Johnson08d5b4e2018-05-26 02:34:13 +00006345
6346 vFuncId: (TypeIdRef, offset: 16)
6347
6348Where each ``TypeIdRef`` refers to a :ref:`type id<typeid_summary>`
6349by summary id or ``GUID`` preceeded by a ``guid:`` tag.
6350
6351TypeCheckedLoadVCalls
6352"""""""""""""""""""""
6353
Chandler Carruth3a56e3f2018-08-06 09:46:59 +00006354.. code-block:: text
Teresa Johnson08d5b4e2018-05-26 02:34:13 +00006355
6356 typeCheckedLoadVCalls: (VFuncId[, VFuncId]*)
6357
6358Where each VFuncId has the format described for ``TypeTestAssumeVCalls``.
6359
6360TypeTestAssumeConstVCalls
6361"""""""""""""""""""""""""
6362
Chandler Carruth3a56e3f2018-08-06 09:46:59 +00006363.. code-block:: text
Teresa Johnson08d5b4e2018-05-26 02:34:13 +00006364
6365 typeTestAssumeConstVCalls: (ConstVCall[, ConstVCall]*)
6366
6367Where each ConstVCall has the format:
6368
Chandler Carruth3a56e3f2018-08-06 09:46:59 +00006369.. code-block:: text
Teresa Johnson08d5b4e2018-05-26 02:34:13 +00006370
Teresa Johnsonab2a7f02018-09-18 13:44:13 +00006371 (VFuncId, args: (Arg[, Arg]*))
Teresa Johnson08d5b4e2018-05-26 02:34:13 +00006372
6373and where each VFuncId has the format described for ``TypeTestAssumeVCalls``,
6374and each Arg is an integer argument number.
6375
6376TypeCheckedLoadConstVCalls
6377""""""""""""""""""""""""""
6378
Chandler Carruth3a56e3f2018-08-06 09:46:59 +00006379.. code-block:: text
Teresa Johnson08d5b4e2018-05-26 02:34:13 +00006380
6381 typeCheckedLoadConstVCalls: (ConstVCall[, ConstVCall]*)
6382
6383Where each ConstVCall has the format described for
6384``TypeTestAssumeConstVCalls``.
6385
6386.. _typeid_summary:
6387
6388Type ID Summary Entry
6389---------------------
6390
6391Each type id summary entry corresponds to a type identifier resolution
6392which is generated during the LTO link portion of the compile when building
6393with `Control Flow Integrity <http://clang.llvm.org/docs/ControlFlowIntegrity.html>`_,
6394so these are only present in a combined summary index.
6395
6396Example:
6397
Chandler Carruth3a56e3f2018-08-06 09:46:59 +00006398.. code-block:: text
Teresa Johnson08d5b4e2018-05-26 02:34:13 +00006399
6400 ^4 = typeid: (name: "_ZTS1A", summary: (typeTestRes: (kind: allOnes, sizeM1BitWidth: 7[, alignLog2: 0]?[, sizeM1: 0]?[, bitMask: 0]?[, inlineBits: 0]?)[, WpdResolutions]?)) ; guid = 7004155349499253778
6401
6402The ``typeTestRes`` gives the type test resolution ``kind`` (which may
6403be ``unsat``, ``byteArray``, ``inline``, ``single``, or ``allOnes``), and
6404the ``size-1`` bit width. It is followed by optional flags, which default to 0,
6405and an optional WpdResolutions (whole program devirtualization resolution)
6406field that looks like:
6407
Chandler Carruth3a56e3f2018-08-06 09:46:59 +00006408.. code-block:: text
Teresa Johnson08d5b4e2018-05-26 02:34:13 +00006409
6410 wpdResolutions: ((offset: 0, WpdRes)[, (offset: 1, WpdRes)]*
6411
6412where each entry is a mapping from the given byte offset to the whole-program
6413devirtualization resolution WpdRes, that has one of the following formats:
6414
Chandler Carruth3a56e3f2018-08-06 09:46:59 +00006415.. code-block:: text
Teresa Johnson08d5b4e2018-05-26 02:34:13 +00006416
6417 wpdRes: (kind: branchFunnel)
6418 wpdRes: (kind: singleImpl, singleImplName: "_ZN1A1nEi")
6419 wpdRes: (kind: indir)
6420
6421Additionally, each wpdRes has an optional ``resByArg`` field, which
6422describes the resolutions for calls with all constant integer arguments:
6423
Chandler Carruth3a56e3f2018-08-06 09:46:59 +00006424.. code-block:: text
Teresa Johnson08d5b4e2018-05-26 02:34:13 +00006425
6426 resByArg: (ResByArg[, ResByArg]*)
6427
6428where ResByArg is:
6429
Chandler Carruth3a56e3f2018-08-06 09:46:59 +00006430.. code-block:: text
Teresa Johnson08d5b4e2018-05-26 02:34:13 +00006431
6432 args: (Arg[, Arg]*), byArg: (kind: UniformRetVal[, info: 0][, byte: 0][, bit: 0])
6433
6434Where the ``kind`` can be ``Indir``, ``UniformRetVal``, ``UniqueRetVal``
6435or ``VirtualConstProp``. The ``info`` field is only used if the kind
6436is ``UniformRetVal`` (indicates the uniform return value), or
6437``UniqueRetVal`` (holds the return value associated with the unique vtable
6438(0 or 1)). The ``byte`` and ``bit`` fields are only used if the target does
6439not support the use of absolute symbols to store constants.
6440
Eli Bendersky0220e6b2013-06-07 20:24:43 +00006441.. _intrinsicglobalvariables:
6442
Sean Silvab084af42012-12-07 10:36:55 +00006443Intrinsic Global Variables
6444==========================
6445
6446LLVM has a number of "magic" global variables that contain data that
6447affect code generation or other IR semantics. These are documented here.
6448All globals of this sort should have a section specified as
6449"``llvm.metadata``". This section and all globals that start with
6450"``llvm.``" are reserved for use by LLVM.
6451
Eli Bendersky0220e6b2013-06-07 20:24:43 +00006452.. _gv_llvmused:
6453
Sean Silvab084af42012-12-07 10:36:55 +00006454The '``llvm.used``' Global Variable
6455-----------------------------------
6456
Rafael Espindola74f2e462013-04-22 14:58:02 +00006457The ``@llvm.used`` global is an array which has
Paul Redmond219ef812013-05-30 17:24:32 +00006458:ref:`appending linkage <linkage_appending>`. This array contains a list of
Rafael Espindola70a729d2013-06-11 13:18:13 +00006459pointers to named global variables, functions and aliases which may optionally
6460have a pointer cast formed of bitcast or getelementptr. For example, a legal
Sean Silvab084af42012-12-07 10:36:55 +00006461use of it is:
6462
6463.. code-block:: llvm
6464
6465 @X = global i8 4
6466 @Y = global i32 123
6467
6468 @llvm.used = appending global [2 x i8*] [
6469 i8* @X,
6470 i8* bitcast (i32* @Y to i8*)
6471 ], section "llvm.metadata"
6472
Rafael Espindola74f2e462013-04-22 14:58:02 +00006473If a symbol appears in the ``@llvm.used`` list, then the compiler, assembler,
6474and linker are required to treat the symbol as if there is a reference to the
Rafael Espindola70a729d2013-06-11 13:18:13 +00006475symbol that it cannot see (which is why they have to be named). For example, if
6476a variable has internal linkage and no references other than that from the
6477``@llvm.used`` list, it cannot be deleted. This is commonly used to represent
6478references from inline asms and other things the compiler cannot "see", and
6479corresponds to "``attribute((used))``" in GNU C.
Sean Silvab084af42012-12-07 10:36:55 +00006480
6481On some targets, the code generator must emit a directive to the
6482assembler or object file to prevent the assembler and linker from
6483molesting the symbol.
6484
Eli Bendersky0220e6b2013-06-07 20:24:43 +00006485.. _gv_llvmcompilerused:
6486
Sean Silvab084af42012-12-07 10:36:55 +00006487The '``llvm.compiler.used``' Global Variable
6488--------------------------------------------
6489
6490The ``@llvm.compiler.used`` directive is the same as the ``@llvm.used``
6491directive, except that it only prevents the compiler from touching the
6492symbol. On targets that support it, this allows an intelligent linker to
6493optimize references to the symbol without being impeded as it would be
6494by ``@llvm.used``.
6495
6496This is a rare construct that should only be used in rare circumstances,
6497and should not be exposed to source languages.
6498
Eli Bendersky0220e6b2013-06-07 20:24:43 +00006499.. _gv_llvmglobalctors:
6500
Sean Silvab084af42012-12-07 10:36:55 +00006501The '``llvm.global_ctors``' Global Variable
6502-------------------------------------------
6503
6504.. code-block:: llvm
6505
Reid Klecknerfceb76f2014-05-16 20:39:27 +00006506 %0 = type { i32, void ()*, i8* }
6507 @llvm.global_ctors = appending global [1 x %0] [%0 { i32 65535, void ()* @ctor, i8* @data }]
Sean Silvab084af42012-12-07 10:36:55 +00006508
6509The ``@llvm.global_ctors`` array contains a list of constructor
Fangrui Songf4dfd632019-05-15 02:35:32 +00006510functions, priorities, and an associated global or function.
Reid Klecknerfceb76f2014-05-16 20:39:27 +00006511The functions referenced by this array will be called in ascending order
6512of priority (i.e. lowest first) when the module is loaded. The order of
6513functions with the same priority is not defined.
6514
Fangrui Songf4dfd632019-05-15 02:35:32 +00006515If the third field is non-null, and points to a global variable
Reid Klecknerfceb76f2014-05-16 20:39:27 +00006516or function, the initializer function will only run if the associated
6517data from the current module is not discarded.
Sean Silvab084af42012-12-07 10:36:55 +00006518
Eli Bendersky0220e6b2013-06-07 20:24:43 +00006519.. _llvmglobaldtors:
6520
Sean Silvab084af42012-12-07 10:36:55 +00006521The '``llvm.global_dtors``' Global Variable
6522-------------------------------------------
6523
6524.. code-block:: llvm
6525
Reid Klecknerfceb76f2014-05-16 20:39:27 +00006526 %0 = type { i32, void ()*, i8* }
6527 @llvm.global_dtors = appending global [1 x %0] [%0 { i32 65535, void ()* @dtor, i8* @data }]
Sean Silvab084af42012-12-07 10:36:55 +00006528
Reid Klecknerfceb76f2014-05-16 20:39:27 +00006529The ``@llvm.global_dtors`` array contains a list of destructor
Fangrui Songf4dfd632019-05-15 02:35:32 +00006530functions, priorities, and an associated global or function.
Reid Klecknerfceb76f2014-05-16 20:39:27 +00006531The functions referenced by this array will be called in descending
Reid Klecknerbffbcc52014-05-27 21:35:17 +00006532order of priority (i.e. highest first) when the module is unloaded. The
Reid Klecknerfceb76f2014-05-16 20:39:27 +00006533order of functions with the same priority is not defined.
6534
Fangrui Songf4dfd632019-05-15 02:35:32 +00006535If the third field is non-null, and points to a global variable
Reid Klecknerfceb76f2014-05-16 20:39:27 +00006536or function, the destructor function will only run if the associated
6537data from the current module is not discarded.
Sean Silvab084af42012-12-07 10:36:55 +00006538
6539Instruction Reference
6540=====================
6541
6542The LLVM instruction set consists of several different classifications
6543of instructions: :ref:`terminator instructions <terminators>`, :ref:`binary
6544instructions <binaryops>`, :ref:`bitwise binary
6545instructions <bitwiseops>`, :ref:`memory instructions <memoryops>`, and
6546:ref:`other instructions <otherops>`.
6547
6548.. _terminators:
6549
6550Terminator Instructions
6551-----------------------
6552
6553As mentioned :ref:`previously <functionstructure>`, every basic block in a
6554program ends with a "Terminator" instruction, which indicates which
6555block should be executed after the current block is finished. These
6556terminator instructions typically yield a '``void``' value: they produce
6557control flow, not values (the one exception being the
6558':ref:`invoke <i_invoke>`' instruction).
6559
6560The terminator instructions are: ':ref:`ret <i_ret>`',
6561':ref:`br <i_br>`', ':ref:`switch <i_switch>`',
6562':ref:`indirectbr <i_indirectbr>`', ':ref:`invoke <i_invoke>`',
Craig Topper784929d2019-02-08 20:48:56 +00006563':ref:`callbr <i_callbr>`'
David Majnemer8a1c45d2015-12-12 05:38:55 +00006564':ref:`resume <i_resume>`', ':ref:`catchswitch <i_catchswitch>`',
David Majnemer654e1302015-07-31 17:58:14 +00006565':ref:`catchret <i_catchret>`',
6566':ref:`cleanupret <i_cleanupret>`',
David Majnemer654e1302015-07-31 17:58:14 +00006567and ':ref:`unreachable <i_unreachable>`'.
Sean Silvab084af42012-12-07 10:36:55 +00006568
6569.. _i_ret:
6570
6571'``ret``' Instruction
6572^^^^^^^^^^^^^^^^^^^^^
6573
6574Syntax:
6575"""""""
6576
6577::
6578
6579 ret <type> <value> ; Return a value from a non-void function
6580 ret void ; Return from void function
6581
6582Overview:
6583"""""""""
6584
6585The '``ret``' instruction is used to return control flow (and optionally
6586a value) from a function back to the caller.
6587
6588There are two forms of the '``ret``' instruction: one that returns a
6589value and then causes control flow, and one that just causes control
6590flow to occur.
6591
6592Arguments:
6593""""""""""
6594
6595The '``ret``' instruction optionally accepts a single argument, the
6596return value. The type of the return value must be a ':ref:`first
6597class <t_firstclass>`' type.
6598
Xing GUO454e51b2019-01-18 03:56:37 +00006599A function is not :ref:`well formed <wellformed>` if it has a non-void
Sean Silvab084af42012-12-07 10:36:55 +00006600return type and contains a '``ret``' instruction with no return value or
6601a return value with a type that does not match its type, or if it has a
6602void return type and contains a '``ret``' instruction with a return
6603value.
6604
6605Semantics:
6606""""""""""
6607
6608When the '``ret``' instruction is executed, control flow returns back to
6609the calling function's context. If the caller is a
6610":ref:`call <i_call>`" instruction, execution continues at the
6611instruction after the call. If the caller was an
6612":ref:`invoke <i_invoke>`" instruction, execution continues at the
6613beginning of the "normal" destination block. If the instruction returns
6614a value, that value shall set the call or invoke instruction's return
6615value.
6616
6617Example:
6618""""""""
6619
6620.. code-block:: llvm
6621
6622 ret i32 5 ; Return an integer value of 5
6623 ret void ; Return from a void function
6624 ret { i32, i8 } { i32 4, i8 2 } ; Return a struct of values 4 and 2
6625
6626.. _i_br:
6627
6628'``br``' Instruction
6629^^^^^^^^^^^^^^^^^^^^
6630
6631Syntax:
6632"""""""
6633
6634::
6635
6636 br i1 <cond>, label <iftrue>, label <iffalse>
6637 br label <dest> ; Unconditional branch
6638
6639Overview:
6640"""""""""
6641
6642The '``br``' instruction is used to cause control flow to transfer to a
6643different basic block in the current function. There are two forms of
6644this instruction, corresponding to a conditional branch and an
6645unconditional branch.
6646
6647Arguments:
6648""""""""""
6649
6650The conditional branch form of the '``br``' instruction takes a single
6651'``i1``' value and two '``label``' values. The unconditional form of the
6652'``br``' instruction takes a single '``label``' value as a target.
6653
6654Semantics:
6655""""""""""
6656
6657Upon execution of a conditional '``br``' instruction, the '``i1``'
6658argument is evaluated. If the value is ``true``, control flows to the
6659'``iftrue``' ``label`` argument. If "cond" is ``false``, control flows
6660to the '``iffalse``' ``label`` argument.
6661
6662Example:
6663""""""""
6664
6665.. code-block:: llvm
6666
6667 Test:
6668 %cond = icmp eq i32 %a, %b
6669 br i1 %cond, label %IfEqual, label %IfUnequal
6670 IfEqual:
6671 ret i32 1
6672 IfUnequal:
6673 ret i32 0
6674
6675.. _i_switch:
6676
6677'``switch``' Instruction
6678^^^^^^^^^^^^^^^^^^^^^^^^
6679
6680Syntax:
6681"""""""
6682
6683::
6684
6685 switch <intty> <value>, label <defaultdest> [ <intty> <val>, label <dest> ... ]
6686
6687Overview:
6688"""""""""
6689
6690The '``switch``' instruction is used to transfer control flow to one of
6691several different places. It is a generalization of the '``br``'
6692instruction, allowing a branch to occur to one of many possible
6693destinations.
6694
6695Arguments:
6696""""""""""
6697
6698The '``switch``' instruction uses three parameters: an integer
6699comparison value '``value``', a default '``label``' destination, and an
6700array of pairs of comparison value constants and '``label``'s. The table
6701is not allowed to contain duplicate constant entries.
6702
6703Semantics:
6704""""""""""
6705
6706The ``switch`` instruction specifies a table of values and destinations.
6707When the '``switch``' instruction is executed, this table is searched
6708for the given value. If the value is found, control flow is transferred
6709to the corresponding destination; otherwise, control flow is transferred
6710to the default destination.
6711
6712Implementation:
6713"""""""""""""""
6714
6715Depending on properties of the target machine and the particular
6716``switch`` instruction, this instruction may be code generated in
6717different ways. For example, it could be generated as a series of
6718chained conditional branches or with a lookup table.
6719
6720Example:
6721""""""""
6722
6723.. code-block:: llvm
6724
6725 ; Emulate a conditional br instruction
6726 %Val = zext i1 %value to i32
6727 switch i32 %Val, label %truedest [ i32 0, label %falsedest ]
6728
6729 ; Emulate an unconditional br instruction
6730 switch i32 0, label %dest [ ]
6731
6732 ; Implement a jump table:
6733 switch i32 %val, label %otherwise [ i32 0, label %onzero
6734 i32 1, label %onone
6735 i32 2, label %ontwo ]
6736
6737.. _i_indirectbr:
6738
6739'``indirectbr``' Instruction
6740^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6741
6742Syntax:
6743"""""""
6744
6745::
6746
6747 indirectbr <somety>* <address>, [ label <dest1>, label <dest2>, ... ]
6748
6749Overview:
6750"""""""""
6751
6752The '``indirectbr``' instruction implements an indirect branch to a
6753label within the current function, whose address is specified by
6754"``address``". Address must be derived from a
6755:ref:`blockaddress <blockaddress>` constant.
6756
6757Arguments:
6758""""""""""
6759
6760The '``address``' argument is the address of the label to jump to. The
6761rest of the arguments indicate the full set of possible destinations
6762that the address may point to. Blocks are allowed to occur multiple
6763times in the destination list, though this isn't particularly useful.
6764
6765This destination list is required so that dataflow analysis has an
6766accurate understanding of the CFG.
6767
6768Semantics:
6769""""""""""
6770
6771Control transfers to the block specified in the address argument. All
6772possible destination blocks must be listed in the label list, otherwise
6773this instruction has undefined behavior. This implies that jumps to
6774labels defined in other functions have undefined behavior as well.
6775
6776Implementation:
6777"""""""""""""""
6778
6779This is typically implemented with a jump through a register.
6780
6781Example:
6782""""""""
6783
6784.. code-block:: llvm
6785
6786 indirectbr i8* %Addr, [ label %bb1, label %bb2, label %bb3 ]
6787
6788.. _i_invoke:
6789
6790'``invoke``' Instruction
6791^^^^^^^^^^^^^^^^^^^^^^^^
6792
6793Syntax:
6794"""""""
6795
6796::
6797
Alexander Richardson6bcf2ba2018-08-23 09:25:17 +00006798 <result> = invoke [cconv] [ret attrs] [addrspace(<num>)] [<ty>|<fnty> <fnptrval>(<function args>) [fn attrs]
Sanjoy Dasb513a9f2015-09-24 23:34:52 +00006799 [operand bundles] to label <normal label> unwind label <exception label>
Sean Silvab084af42012-12-07 10:36:55 +00006800
6801Overview:
6802"""""""""
6803
6804The '``invoke``' instruction causes control to transfer to a specified
6805function, with the possibility of control flow transfer to either the
6806'``normal``' label or the '``exception``' label. If the callee function
6807returns with the "``ret``" instruction, control flow will return to the
6808"normal" label. If the callee (or any indirect callees) returns via the
6809":ref:`resume <i_resume>`" instruction or other exception handling
6810mechanism, control is interrupted and continued at the dynamically
6811nearest "exception" label.
6812
6813The '``exception``' label is a `landing
6814pad <ExceptionHandling.html#overview>`_ for the exception. As such,
6815'``exception``' label is required to have the
6816":ref:`landingpad <i_landingpad>`" instruction, which contains the
6817information about the behavior of the program after unwinding happens,
6818as its first non-PHI instruction. The restrictions on the
6819"``landingpad``" instruction's tightly couples it to the "``invoke``"
6820instruction, so that the important information contained within the
6821"``landingpad``" instruction can't be lost through normal code motion.
6822
6823Arguments:
6824""""""""""
6825
6826This instruction requires several arguments:
6827
6828#. The optional "cconv" marker indicates which :ref:`calling
6829 convention <callingconv>` the call should use. If none is
6830 specified, the call defaults to using C calling conventions.
6831#. The optional :ref:`Parameter Attributes <paramattrs>` list for return
6832 values. Only '``zeroext``', '``signext``', and '``inreg``' attributes
6833 are valid here.
Craig Topper78e7fff2019-01-16 00:21:59 +00006834#. The optional addrspace attribute can be used to indicate the address space
Alexander Richardson6bcf2ba2018-08-23 09:25:17 +00006835 of the called function. If it is not specified, the program address space
6836 from the :ref:`datalayout string<langref_datalayout>` will be used.
David Blaikieb83cf102016-07-13 17:21:34 +00006837#. '``ty``': the type of the call instruction itself which is also the
6838 type of the return value. Functions that return no value are marked
6839 ``void``.
6840#. '``fnty``': shall be the signature of the function being invoked. The
6841 argument types must match the types implied by this signature. This
6842 type can be omitted if the function is not varargs.
6843#. '``fnptrval``': An LLVM value containing a pointer to a function to
6844 be invoked. In most cases, this is a direct function invocation, but
6845 indirect ``invoke``'s are just as possible, calling an arbitrary pointer
6846 to function value.
Sean Silvab084af42012-12-07 10:36:55 +00006847#. '``function args``': argument list whose types match the function
6848 signature argument types and parameter attributes. All arguments must
6849 be of :ref:`first class <t_firstclass>` type. If the function signature
6850 indicates the function accepts a variable number of arguments, the
6851 extra arguments can be specified.
6852#. '``normal label``': the label reached when the called function
6853 executes a '``ret``' instruction.
6854#. '``exception label``': the label reached when a callee returns via
6855 the :ref:`resume <i_resume>` instruction or other exception handling
6856 mechanism.
George Burgess IV8a464a72017-04-13 05:00:31 +00006857#. The optional :ref:`function attributes <fnattrs>` list.
Sanjoy Dasb513a9f2015-09-24 23:34:52 +00006858#. The optional :ref:`operand bundles <opbundles>` list.
Sean Silvab084af42012-12-07 10:36:55 +00006859
6860Semantics:
6861""""""""""
6862
6863This instruction is designed to operate as a standard '``call``'
6864instruction in most regards. The primary difference is that it
6865establishes an association with a label, which is used by the runtime
6866library to unwind the stack.
6867
6868This instruction is used in languages with destructors to ensure that
6869proper cleanup is performed in the case of either a ``longjmp`` or a
6870thrown exception. Additionally, this is important for implementation of
6871'``catch``' clauses in high-level languages that support them.
6872
6873For the purposes of the SSA form, the definition of the value returned
6874by the '``invoke``' instruction is deemed to occur on the edge from the
6875current block to the "normal" label. If the callee unwinds then no
6876return value is available.
6877
6878Example:
6879""""""""
6880
6881.. code-block:: llvm
6882
6883 %retval = invoke i32 @Test(i32 15) to label %Continue
Tim Northover675a0962014-06-13 14:24:23 +00006884 unwind label %TestCleanup ; i32:retval set
Sean Silvab084af42012-12-07 10:36:55 +00006885 %retval = invoke coldcc i32 %Testfnptr(i32 15) to label %Continue
Tim Northover675a0962014-06-13 14:24:23 +00006886 unwind label %TestCleanup ; i32:retval set
Sean Silvab084af42012-12-07 10:36:55 +00006887
Craig Topper784929d2019-02-08 20:48:56 +00006888.. _i_callbr:
6889
6890'``callbr``' Instruction
6891^^^^^^^^^^^^^^^^^^^^^^^^
6892
6893Syntax:
6894"""""""
6895
6896::
6897
6898 <result> = callbr [cconv] [ret attrs] [addrspace(<num>)] [<ty>|<fnty> <fnptrval>(<function args>) [fn attrs]
6899 [operand bundles] to label <normal label> or jump [other labels]
6900
6901Overview:
6902"""""""""
6903
6904The '``callbr``' instruction causes control to transfer to a specified
6905function, with the possibility of control flow transfer to either the
6906'``normal``' label or one of the '``other``' labels.
6907
6908This instruction should only be used to implement the "goto" feature of gcc
6909style inline assembly. Any other usage is an error in the IR verifier.
6910
6911Arguments:
6912""""""""""
6913
6914This instruction requires several arguments:
6915
6916#. The optional "cconv" marker indicates which :ref:`calling
6917 convention <callingconv>` the call should use. If none is
6918 specified, the call defaults to using C calling conventions.
6919#. The optional :ref:`Parameter Attributes <paramattrs>` list for return
6920 values. Only '``zeroext``', '``signext``', and '``inreg``' attributes
6921 are valid here.
6922#. The optional addrspace attribute can be used to indicate the address space
6923 of the called function. If it is not specified, the program address space
6924 from the :ref:`datalayout string<langref_datalayout>` will be used.
6925#. '``ty``': the type of the call instruction itself which is also the
6926 type of the return value. Functions that return no value are marked
6927 ``void``.
6928#. '``fnty``': shall be the signature of the function being called. The
6929 argument types must match the types implied by this signature. This
6930 type can be omitted if the function is not varargs.
6931#. '``fnptrval``': An LLVM value containing a pointer to a function to
6932 be called. In most cases, this is a direct function call, but
6933 indirect ``callbr``'s are just as possible, calling an arbitrary pointer
6934 to function value.
6935#. '``function args``': argument list whose types match the function
6936 signature argument types and parameter attributes. All arguments must
6937 be of :ref:`first class <t_firstclass>` type. If the function signature
6938 indicates the function accepts a variable number of arguments, the
6939 extra arguments can be specified.
6940#. '``normal label``': the label reached when the called function
6941 executes a '``ret``' instruction.
6942#. '``other labels``': the labels reached when a callee transfers control
6943 to a location other than the normal '``normal label``'
6944#. The optional :ref:`function attributes <fnattrs>` list.
6945#. The optional :ref:`operand bundles <opbundles>` list.
6946
6947Semantics:
6948""""""""""
6949
6950This instruction is designed to operate as a standard '``call``'
6951instruction in most regards. The primary difference is that it
6952establishes an association with additional labels to define where control
6953flow goes after the call.
6954
6955The only use of this today is to implement the "goto" feature of gcc inline
6956assembly where additional labels can be provided as locations for the inline
6957assembly to jump to.
6958
6959Example:
6960""""""""
6961
Craig Toppere08e2b62019-02-08 21:09:33 +00006962.. code-block:: text
Craig Topper784929d2019-02-08 20:48:56 +00006963
6964 callbr void asm "", "r,x"(i32 %x, i8 *blockaddress(@foo, %fail))
6965 to label %normal or jump [label %fail]
6966
Sean Silvab084af42012-12-07 10:36:55 +00006967.. _i_resume:
6968
6969'``resume``' Instruction
6970^^^^^^^^^^^^^^^^^^^^^^^^
6971
6972Syntax:
6973"""""""
6974
6975::
6976
6977 resume <type> <value>
6978
6979Overview:
6980"""""""""
6981
6982The '``resume``' instruction is a terminator instruction that has no
6983successors.
6984
6985Arguments:
6986""""""""""
6987
6988The '``resume``' instruction requires one argument, which must have the
6989same type as the result of any '``landingpad``' instruction in the same
6990function.
6991
6992Semantics:
6993""""""""""
6994
6995The '``resume``' instruction resumes propagation of an existing
6996(in-flight) exception whose unwinding was interrupted with a
6997:ref:`landingpad <i_landingpad>` instruction.
6998
6999Example:
7000""""""""
7001
7002.. code-block:: llvm
7003
7004 resume { i8*, i32 } %exn
7005
David Majnemer8a1c45d2015-12-12 05:38:55 +00007006.. _i_catchswitch:
7007
7008'``catchswitch``' Instruction
Akira Hatanakacedf8e92015-12-14 05:15:40 +00007009^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
David Majnemer8a1c45d2015-12-12 05:38:55 +00007010
7011Syntax:
7012"""""""
7013
7014::
7015
7016 <resultval> = catchswitch within <parent> [ label <handler1>, label <handler2>, ... ] unwind to caller
7017 <resultval> = catchswitch within <parent> [ label <handler1>, label <handler2>, ... ] unwind label <default>
7018
7019Overview:
7020"""""""""
7021
7022The '``catchswitch``' instruction is used by `LLVM's exception handling system
7023<ExceptionHandling.html#overview>`_ to describe the set of possible catch handlers
7024that may be executed by the :ref:`EH personality routine <personalityfn>`.
7025
7026Arguments:
7027""""""""""
7028
7029The ``parent`` argument is the token of the funclet that contains the
7030``catchswitch`` instruction. If the ``catchswitch`` is not inside a funclet,
7031this operand may be the token ``none``.
7032
Joseph Tremoulete28885e2016-01-10 04:28:38 +00007033The ``default`` argument is the label of another basic block beginning with
7034either a ``cleanuppad`` or ``catchswitch`` instruction. This unwind destination
7035must be a legal target with respect to the ``parent`` links, as described in
7036the `exception handling documentation\ <ExceptionHandling.html#wineh-constraints>`_.
David Majnemer8a1c45d2015-12-12 05:38:55 +00007037
Joseph Tremoulete28885e2016-01-10 04:28:38 +00007038The ``handlers`` are a nonempty list of successor blocks that each begin with a
David Majnemer8a1c45d2015-12-12 05:38:55 +00007039:ref:`catchpad <i_catchpad>` instruction.
7040
7041Semantics:
7042""""""""""
7043
7044Executing this instruction transfers control to one of the successors in
7045``handlers``, if appropriate, or continues to unwind via the unwind label if
7046present.
7047
7048The ``catchswitch`` is both a terminator and a "pad" instruction, meaning that
7049it must be both the first non-phi instruction and last instruction in the basic
7050block. Therefore, it must be the only non-phi instruction in the block.
7051
7052Example:
7053""""""""
7054
Renato Golin124f2592016-07-20 12:16:38 +00007055.. code-block:: text
David Majnemer8a1c45d2015-12-12 05:38:55 +00007056
7057 dispatch1:
7058 %cs1 = catchswitch within none [label %handler0, label %handler1] unwind to caller
7059 dispatch2:
7060 %cs2 = catchswitch within %parenthandler [label %handler0] unwind label %cleanup
7061
David Majnemer654e1302015-07-31 17:58:14 +00007062.. _i_catchret:
7063
7064'``catchret``' Instruction
7065^^^^^^^^^^^^^^^^^^^^^^^^^^
7066
7067Syntax:
7068"""""""
7069
7070::
7071
David Majnemer8a1c45d2015-12-12 05:38:55 +00007072 catchret from <token> to label <normal>
David Majnemer654e1302015-07-31 17:58:14 +00007073
7074Overview:
7075"""""""""
7076
7077The '``catchret``' instruction is a terminator instruction that has a
7078single successor.
7079
7080
7081Arguments:
7082""""""""""
7083
Joseph Tremoulet8220bcc2015-08-23 00:26:33 +00007084The first argument to a '``catchret``' indicates which ``catchpad`` it
7085exits. It must be a :ref:`catchpad <i_catchpad>`.
7086The second argument to a '``catchret``' specifies where control will
7087transfer to next.
David Majnemer654e1302015-07-31 17:58:14 +00007088
7089Semantics:
7090""""""""""
7091
David Majnemer8a1c45d2015-12-12 05:38:55 +00007092The '``catchret``' instruction ends an existing (in-flight) exception whose
7093unwinding was interrupted with a :ref:`catchpad <i_catchpad>` instruction. The
7094:ref:`personality function <personalityfn>` gets a chance to execute arbitrary
7095code to, for example, destroy the active exception. Control then transfers to
7096``normal``.
Joseph Tremoulet9ce71f72015-09-03 09:09:43 +00007097
Joseph Tremoulete28885e2016-01-10 04:28:38 +00007098The ``token`` argument must be a token produced by a ``catchpad`` instruction.
7099If the specified ``catchpad`` is not the most-recently-entered not-yet-exited
7100funclet pad (as described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_),
7101the ``catchret``'s behavior is undefined.
David Majnemer654e1302015-07-31 17:58:14 +00007102
7103Example:
7104""""""""
7105
Renato Golin124f2592016-07-20 12:16:38 +00007106.. code-block:: text
David Majnemer654e1302015-07-31 17:58:14 +00007107
David Majnemer8a1c45d2015-12-12 05:38:55 +00007108 catchret from %catch label %continue
Joseph Tremoulet9ce71f72015-09-03 09:09:43 +00007109
David Majnemer654e1302015-07-31 17:58:14 +00007110.. _i_cleanupret:
7111
7112'``cleanupret``' Instruction
7113^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7114
7115Syntax:
7116"""""""
7117
7118::
7119
David Majnemer8a1c45d2015-12-12 05:38:55 +00007120 cleanupret from <value> unwind label <continue>
7121 cleanupret from <value> unwind to caller
David Majnemer654e1302015-07-31 17:58:14 +00007122
7123Overview:
7124"""""""""
7125
7126The '``cleanupret``' instruction is a terminator instruction that has
7127an optional successor.
7128
7129
7130Arguments:
7131""""""""""
7132
Joseph Tremoulet8220bcc2015-08-23 00:26:33 +00007133The '``cleanupret``' instruction requires one argument, which indicates
7134which ``cleanuppad`` it exits, and must be a :ref:`cleanuppad <i_cleanuppad>`.
Joseph Tremoulete28885e2016-01-10 04:28:38 +00007135If the specified ``cleanuppad`` is not the most-recently-entered not-yet-exited
7136funclet pad (as described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_),
7137the ``cleanupret``'s behavior is undefined.
7138
7139The '``cleanupret``' instruction also has an optional successor, ``continue``,
7140which must be the label of another basic block beginning with either a
7141``cleanuppad`` or ``catchswitch`` instruction. This unwind destination must
7142be a legal target with respect to the ``parent`` links, as described in the
7143`exception handling documentation\ <ExceptionHandling.html#wineh-constraints>`_.
David Majnemer654e1302015-07-31 17:58:14 +00007144
7145Semantics:
7146""""""""""
7147
7148The '``cleanupret``' instruction indicates to the
7149:ref:`personality function <personalityfn>` that one
7150:ref:`cleanuppad <i_cleanuppad>` it transferred control to has ended.
7151It transfers control to ``continue`` or unwinds out of the function.
Joseph Tremoulet9ce71f72015-09-03 09:09:43 +00007152
David Majnemer654e1302015-07-31 17:58:14 +00007153Example:
7154""""""""
7155
Renato Golin124f2592016-07-20 12:16:38 +00007156.. code-block:: text
David Majnemer654e1302015-07-31 17:58:14 +00007157
David Majnemer8a1c45d2015-12-12 05:38:55 +00007158 cleanupret from %cleanup unwind to caller
7159 cleanupret from %cleanup unwind label %continue
David Majnemer654e1302015-07-31 17:58:14 +00007160
Sean Silvab084af42012-12-07 10:36:55 +00007161.. _i_unreachable:
7162
7163'``unreachable``' Instruction
7164^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7165
7166Syntax:
7167"""""""
7168
7169::
7170
7171 unreachable
7172
7173Overview:
7174"""""""""
7175
7176The '``unreachable``' instruction has no defined semantics. This
7177instruction is used to inform the optimizer that a particular portion of
7178the code is not reachable. This can be used to indicate that the code
7179after a no-return function cannot be reached, and other facts.
7180
7181Semantics:
7182""""""""""
7183
7184The '``unreachable``' instruction has no defined semantics.
7185
Cameron McInallye4ee9842018-11-16 19:52:59 +00007186.. _unaryops:
7187
7188Unary Operations
7189-----------------
7190
7191Unary operators require a single operand, execute an operation on
7192it, and produce a single value. The operand might represent multiple
7193data, as is the case with the :ref:`vector <t_vector>` data type. The
7194result value has the same type as its operand.
7195
7196.. _i_fneg:
7197
7198'``fneg``' Instruction
7199^^^^^^^^^^^^^^^^^^^^^^
7200
7201Syntax:
7202"""""""
7203
7204::
7205
7206 <result> = fneg [fast-math flags]* <ty> <op1> ; yields ty:result
7207
7208Overview:
7209"""""""""
7210
7211The '``fneg``' instruction returns the negation of its operand.
7212
7213Arguments:
7214""""""""""
7215
7216The argument to the '``fneg``' instruction must be a
7217:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of
Michael Kruse978ba612018-12-20 04:58:07 +00007218floating-point values.
Cameron McInallye4ee9842018-11-16 19:52:59 +00007219
7220Semantics:
7221""""""""""
7222
7223The value produced is a copy of the operand with its sign bit flipped.
7224This instruction can also take any number of :ref:`fast-math
7225flags <fastmath>`, which are optimization hints to enable otherwise
7226unsafe floating-point optimizations:
7227
7228Example:
7229""""""""
7230
7231.. code-block:: text
7232
7233 <result> = fneg float %val ; yields float:result = -%var
7234
Sean Silvab084af42012-12-07 10:36:55 +00007235.. _binaryops:
7236
7237Binary Operations
7238-----------------
7239
7240Binary operators are used to do most of the computation in a program.
7241They require two operands of the same type, execute an operation on
7242them, and produce a single value. The operands might represent multiple
7243data, as is the case with the :ref:`vector <t_vector>` data type. The
7244result value has the same type as its operands.
7245
7246There are several different binary operators:
7247
7248.. _i_add:
7249
7250'``add``' Instruction
7251^^^^^^^^^^^^^^^^^^^^^
7252
7253Syntax:
7254"""""""
7255
7256::
7257
Tim Northover675a0962014-06-13 14:24:23 +00007258 <result> = add <ty> <op1>, <op2> ; yields ty:result
7259 <result> = add nuw <ty> <op1>, <op2> ; yields ty:result
7260 <result> = add nsw <ty> <op1>, <op2> ; yields ty:result
7261 <result> = add nuw nsw <ty> <op1>, <op2> ; yields ty:result
Sean Silvab084af42012-12-07 10:36:55 +00007262
7263Overview:
7264"""""""""
7265
7266The '``add``' instruction returns the sum of its two operands.
7267
7268Arguments:
7269""""""""""
7270
7271The two arguments to the '``add``' instruction must be
7272:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
7273arguments must have identical types.
7274
7275Semantics:
7276""""""""""
7277
7278The value produced is the integer sum of the two operands.
7279
7280If the sum has unsigned overflow, the result returned is the
7281mathematical result modulo 2\ :sup:`n`\ , where n is the bit width of
7282the result.
7283
7284Because LLVM integers use a two's complement representation, this
7285instruction is appropriate for both signed and unsigned integers.
7286
7287``nuw`` and ``nsw`` stand for "No Unsigned Wrap" and "No Signed Wrap",
7288respectively. If the ``nuw`` and/or ``nsw`` keywords are present, the
7289result value of the ``add`` is a :ref:`poison value <poisonvalues>` if
7290unsigned and/or signed overflow, respectively, occurs.
7291
7292Example:
7293""""""""
7294
Renato Golin124f2592016-07-20 12:16:38 +00007295.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00007296
Tim Northover675a0962014-06-13 14:24:23 +00007297 <result> = add i32 4, %var ; yields i32:result = 4 + %var
Sean Silvab084af42012-12-07 10:36:55 +00007298
7299.. _i_fadd:
7300
7301'``fadd``' Instruction
7302^^^^^^^^^^^^^^^^^^^^^^
7303
7304Syntax:
7305"""""""
7306
7307::
7308
Tim Northover675a0962014-06-13 14:24:23 +00007309 <result> = fadd [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result
Sean Silvab084af42012-12-07 10:36:55 +00007310
7311Overview:
7312"""""""""
7313
7314The '``fadd``' instruction returns the sum of its two operands.
7315
7316Arguments:
7317""""""""""
7318
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00007319The two arguments to the '``fadd``' instruction must be
Mandeep Singh Grang547a0d72018-11-01 23:22:25 +00007320:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00007321floating-point values. Both arguments must have identical types.
Sean Silvab084af42012-12-07 10:36:55 +00007322
7323Semantics:
7324""""""""""
7325
Sanjay Patel7b722402018-03-07 17:18:22 +00007326The value produced is the floating-point sum of the two operands.
Sanjay Patelec95e0e2018-03-20 17:05:19 +00007327This instruction is assumed to execute in the default :ref:`floating-point
Mandeep Singh Grang547a0d72018-11-01 23:22:25 +00007328environment <floatenv>`.
Sanjay Patel7b722402018-03-07 17:18:22 +00007329This instruction can also take any number of :ref:`fast-math
7330flags <fastmath>`, which are optimization hints to enable otherwise
7331unsafe floating-point optimizations:
Sean Silvab084af42012-12-07 10:36:55 +00007332
7333Example:
7334""""""""
7335
Renato Golin124f2592016-07-20 12:16:38 +00007336.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00007337
Tim Northover675a0962014-06-13 14:24:23 +00007338 <result> = fadd float 4.0, %var ; yields float:result = 4.0 + %var
Sean Silvab084af42012-12-07 10:36:55 +00007339
7340'``sub``' Instruction
7341^^^^^^^^^^^^^^^^^^^^^
7342
7343Syntax:
7344"""""""
7345
7346::
7347
Tim Northover675a0962014-06-13 14:24:23 +00007348 <result> = sub <ty> <op1>, <op2> ; yields ty:result
7349 <result> = sub nuw <ty> <op1>, <op2> ; yields ty:result
7350 <result> = sub nsw <ty> <op1>, <op2> ; yields ty:result
7351 <result> = sub nuw nsw <ty> <op1>, <op2> ; yields ty:result
Sean Silvab084af42012-12-07 10:36:55 +00007352
7353Overview:
7354"""""""""
7355
7356The '``sub``' instruction returns the difference of its two operands.
7357
7358Note that the '``sub``' instruction is used to represent the '``neg``'
7359instruction present in most other intermediate representations.
7360
7361Arguments:
7362""""""""""
7363
7364The two arguments to the '``sub``' instruction must be
7365:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
7366arguments must have identical types.
7367
7368Semantics:
7369""""""""""
7370
7371The value produced is the integer difference of the two operands.
7372
7373If the difference has unsigned overflow, the result returned is the
7374mathematical result modulo 2\ :sup:`n`\ , where n is the bit width of
7375the result.
7376
7377Because LLVM integers use a two's complement representation, this
7378instruction is appropriate for both signed and unsigned integers.
7379
7380``nuw`` and ``nsw`` stand for "No Unsigned Wrap" and "No Signed Wrap",
7381respectively. If the ``nuw`` and/or ``nsw`` keywords are present, the
7382result value of the ``sub`` is a :ref:`poison value <poisonvalues>` if
7383unsigned and/or signed overflow, respectively, occurs.
7384
7385Example:
7386""""""""
7387
Renato Golin124f2592016-07-20 12:16:38 +00007388.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00007389
Tim Northover675a0962014-06-13 14:24:23 +00007390 <result> = sub i32 4, %var ; yields i32:result = 4 - %var
7391 <result> = sub i32 0, %val ; yields i32:result = -%var
Sean Silvab084af42012-12-07 10:36:55 +00007392
7393.. _i_fsub:
7394
7395'``fsub``' Instruction
7396^^^^^^^^^^^^^^^^^^^^^^
7397
7398Syntax:
7399"""""""
7400
7401::
7402
Tim Northover675a0962014-06-13 14:24:23 +00007403 <result> = fsub [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result
Sean Silvab084af42012-12-07 10:36:55 +00007404
7405Overview:
7406"""""""""
7407
7408The '``fsub``' instruction returns the difference of its two operands.
7409
Sean Silvab084af42012-12-07 10:36:55 +00007410Arguments:
7411""""""""""
7412
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00007413The two arguments to the '``fsub``' instruction must be
Mandeep Singh Grang547a0d72018-11-01 23:22:25 +00007414:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00007415floating-point values. Both arguments must have identical types.
Sean Silvab084af42012-12-07 10:36:55 +00007416
7417Semantics:
7418""""""""""
7419
Sanjay Patel7b722402018-03-07 17:18:22 +00007420The value produced is the floating-point difference of the two operands.
Sanjay Patelec95e0e2018-03-20 17:05:19 +00007421This instruction is assumed to execute in the default :ref:`floating-point
Mandeep Singh Grang547a0d72018-11-01 23:22:25 +00007422environment <floatenv>`.
Sean Silvab084af42012-12-07 10:36:55 +00007423This instruction can also take any number of :ref:`fast-math
7424flags <fastmath>`, which are optimization hints to enable otherwise
Sanjay Patel7b722402018-03-07 17:18:22 +00007425unsafe floating-point optimizations:
Sean Silvab084af42012-12-07 10:36:55 +00007426
7427Example:
7428""""""""
7429
Renato Golin124f2592016-07-20 12:16:38 +00007430.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00007431
Tim Northover675a0962014-06-13 14:24:23 +00007432 <result> = fsub float 4.0, %var ; yields float:result = 4.0 - %var
7433 <result> = fsub float -0.0, %val ; yields float:result = -%var
Sean Silvab084af42012-12-07 10:36:55 +00007434
7435'``mul``' Instruction
7436^^^^^^^^^^^^^^^^^^^^^
7437
7438Syntax:
7439"""""""
7440
7441::
7442
Tim Northover675a0962014-06-13 14:24:23 +00007443 <result> = mul <ty> <op1>, <op2> ; yields ty:result
7444 <result> = mul nuw <ty> <op1>, <op2> ; yields ty:result
7445 <result> = mul nsw <ty> <op1>, <op2> ; yields ty:result
7446 <result> = mul nuw nsw <ty> <op1>, <op2> ; yields ty:result
Sean Silvab084af42012-12-07 10:36:55 +00007447
7448Overview:
7449"""""""""
7450
7451The '``mul``' instruction returns the product of its two operands.
7452
7453Arguments:
7454""""""""""
7455
7456The two arguments to the '``mul``' instruction must be
7457:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
7458arguments must have identical types.
7459
7460Semantics:
7461""""""""""
7462
7463The value produced is the integer product of the two operands.
7464
7465If the result of the multiplication has unsigned overflow, the result
7466returned is the mathematical result modulo 2\ :sup:`n`\ , where n is the
7467bit width of the result.
7468
7469Because LLVM integers use a two's complement representation, and the
7470result is the same width as the operands, this instruction returns the
7471correct result for both signed and unsigned integers. If a full product
7472(e.g. ``i32`` * ``i32`` -> ``i64``) is needed, the operands should be
7473sign-extended or zero-extended as appropriate to the width of the full
7474product.
7475
7476``nuw`` and ``nsw`` stand for "No Unsigned Wrap" and "No Signed Wrap",
7477respectively. If the ``nuw`` and/or ``nsw`` keywords are present, the
7478result value of the ``mul`` is a :ref:`poison value <poisonvalues>` if
7479unsigned and/or signed overflow, respectively, occurs.
7480
7481Example:
7482""""""""
7483
Renato Golin124f2592016-07-20 12:16:38 +00007484.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00007485
Tim Northover675a0962014-06-13 14:24:23 +00007486 <result> = mul i32 4, %var ; yields i32:result = 4 * %var
Sean Silvab084af42012-12-07 10:36:55 +00007487
7488.. _i_fmul:
7489
7490'``fmul``' Instruction
7491^^^^^^^^^^^^^^^^^^^^^^
7492
7493Syntax:
7494"""""""
7495
7496::
7497
Tim Northover675a0962014-06-13 14:24:23 +00007498 <result> = fmul [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result
Sean Silvab084af42012-12-07 10:36:55 +00007499
7500Overview:
7501"""""""""
7502
7503The '``fmul``' instruction returns the product of its two operands.
7504
7505Arguments:
7506""""""""""
7507
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00007508The two arguments to the '``fmul``' instruction must be
Mandeep Singh Grang547a0d72018-11-01 23:22:25 +00007509:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00007510floating-point values. Both arguments must have identical types.
Sean Silvab084af42012-12-07 10:36:55 +00007511
7512Semantics:
7513""""""""""
7514
Sanjay Patel7b722402018-03-07 17:18:22 +00007515The value produced is the floating-point product of the two operands.
Sanjay Patelec95e0e2018-03-20 17:05:19 +00007516This instruction is assumed to execute in the default :ref:`floating-point
Mandeep Singh Grang547a0d72018-11-01 23:22:25 +00007517environment <floatenv>`.
Sean Silvab084af42012-12-07 10:36:55 +00007518This instruction can also take any number of :ref:`fast-math
7519flags <fastmath>`, which are optimization hints to enable otherwise
Sanjay Patel7b722402018-03-07 17:18:22 +00007520unsafe floating-point optimizations:
Sean Silvab084af42012-12-07 10:36:55 +00007521
7522Example:
7523""""""""
7524
Renato Golin124f2592016-07-20 12:16:38 +00007525.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00007526
Tim Northover675a0962014-06-13 14:24:23 +00007527 <result> = fmul float 4.0, %var ; yields float:result = 4.0 * %var
Sean Silvab084af42012-12-07 10:36:55 +00007528
7529'``udiv``' Instruction
7530^^^^^^^^^^^^^^^^^^^^^^
7531
7532Syntax:
7533"""""""
7534
7535::
7536
Tim Northover675a0962014-06-13 14:24:23 +00007537 <result> = udiv <ty> <op1>, <op2> ; yields ty:result
7538 <result> = udiv exact <ty> <op1>, <op2> ; yields ty:result
Sean Silvab084af42012-12-07 10:36:55 +00007539
7540Overview:
7541"""""""""
7542
7543The '``udiv``' instruction returns the quotient of its two operands.
7544
7545Arguments:
7546""""""""""
7547
7548The two arguments to the '``udiv``' instruction must be
7549:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
7550arguments must have identical types.
7551
7552Semantics:
7553""""""""""
7554
7555The value produced is the unsigned integer quotient of the two operands.
7556
7557Note that unsigned integer division and signed integer division are
7558distinct operations; for signed integer division, use '``sdiv``'.
7559
Sanjay Patel2b1f6f42017-03-09 16:20:52 +00007560Division by zero is undefined behavior. For vectors, if any element
7561of the divisor is zero, the operation has undefined behavior.
7562
Sean Silvab084af42012-12-07 10:36:55 +00007563
7564If the ``exact`` keyword is present, the result value of the ``udiv`` is
7565a :ref:`poison value <poisonvalues>` if %op1 is not a multiple of %op2 (as
7566such, "((a udiv exact b) mul b) == a").
7567
7568Example:
7569""""""""
7570
Renato Golin124f2592016-07-20 12:16:38 +00007571.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00007572
Tim Northover675a0962014-06-13 14:24:23 +00007573 <result> = udiv i32 4, %var ; yields i32:result = 4 / %var
Sean Silvab084af42012-12-07 10:36:55 +00007574
7575'``sdiv``' Instruction
7576^^^^^^^^^^^^^^^^^^^^^^
7577
7578Syntax:
7579"""""""
7580
7581::
7582
Tim Northover675a0962014-06-13 14:24:23 +00007583 <result> = sdiv <ty> <op1>, <op2> ; yields ty:result
7584 <result> = sdiv exact <ty> <op1>, <op2> ; yields ty:result
Sean Silvab084af42012-12-07 10:36:55 +00007585
7586Overview:
7587"""""""""
7588
7589The '``sdiv``' instruction returns the quotient of its two operands.
7590
7591Arguments:
7592""""""""""
7593
7594The two arguments to the '``sdiv``' instruction must be
7595:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
7596arguments must have identical types.
7597
7598Semantics:
7599""""""""""
7600
7601The value produced is the signed integer quotient of the two operands
7602rounded towards zero.
7603
7604Note that signed integer division and unsigned integer division are
7605distinct operations; for unsigned integer division, use '``udiv``'.
7606
Sanjay Patel2b1f6f42017-03-09 16:20:52 +00007607Division by zero is undefined behavior. For vectors, if any element
7608of the divisor is zero, the operation has undefined behavior.
7609Overflow also leads to undefined behavior; this is a rare case, but can
7610occur, for example, by doing a 32-bit division of -2147483648 by -1.
Sean Silvab084af42012-12-07 10:36:55 +00007611
7612If the ``exact`` keyword is present, the result value of the ``sdiv`` is
7613a :ref:`poison value <poisonvalues>` if the result would be rounded.
7614
7615Example:
7616""""""""
7617
Renato Golin124f2592016-07-20 12:16:38 +00007618.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00007619
Tim Northover675a0962014-06-13 14:24:23 +00007620 <result> = sdiv i32 4, %var ; yields i32:result = 4 / %var
Sean Silvab084af42012-12-07 10:36:55 +00007621
7622.. _i_fdiv:
7623
7624'``fdiv``' Instruction
7625^^^^^^^^^^^^^^^^^^^^^^
7626
7627Syntax:
7628"""""""
7629
7630::
7631
Tim Northover675a0962014-06-13 14:24:23 +00007632 <result> = fdiv [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result
Sean Silvab084af42012-12-07 10:36:55 +00007633
7634Overview:
7635"""""""""
7636
7637The '``fdiv``' instruction returns the quotient of its two operands.
7638
7639Arguments:
7640""""""""""
7641
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00007642The two arguments to the '``fdiv``' instruction must be
Mandeep Singh Grang547a0d72018-11-01 23:22:25 +00007643:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00007644floating-point values. Both arguments must have identical types.
Sean Silvab084af42012-12-07 10:36:55 +00007645
7646Semantics:
7647""""""""""
7648
Sanjay Patel7b722402018-03-07 17:18:22 +00007649The value produced is the floating-point quotient of the two operands.
Sanjay Patelec95e0e2018-03-20 17:05:19 +00007650This instruction is assumed to execute in the default :ref:`floating-point
Mandeep Singh Grang547a0d72018-11-01 23:22:25 +00007651environment <floatenv>`.
Sean Silvab084af42012-12-07 10:36:55 +00007652This instruction can also take any number of :ref:`fast-math
7653flags <fastmath>`, which are optimization hints to enable otherwise
Sanjay Patel7b722402018-03-07 17:18:22 +00007654unsafe floating-point optimizations:
Sean Silvab084af42012-12-07 10:36:55 +00007655
7656Example:
7657""""""""
7658
Renato Golin124f2592016-07-20 12:16:38 +00007659.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00007660
Tim Northover675a0962014-06-13 14:24:23 +00007661 <result> = fdiv float 4.0, %var ; yields float:result = 4.0 / %var
Sean Silvab084af42012-12-07 10:36:55 +00007662
7663'``urem``' Instruction
7664^^^^^^^^^^^^^^^^^^^^^^
7665
7666Syntax:
7667"""""""
7668
7669::
7670
Tim Northover675a0962014-06-13 14:24:23 +00007671 <result> = urem <ty> <op1>, <op2> ; yields ty:result
Sean Silvab084af42012-12-07 10:36:55 +00007672
7673Overview:
7674"""""""""
7675
7676The '``urem``' instruction returns the remainder from the unsigned
7677division of its two arguments.
7678
7679Arguments:
7680""""""""""
7681
7682The two arguments to the '``urem``' instruction must be
7683:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
7684arguments must have identical types.
7685
7686Semantics:
7687""""""""""
7688
7689This instruction returns the unsigned integer *remainder* of a division.
7690This instruction always performs an unsigned division to get the
7691remainder.
7692
7693Note that unsigned integer remainder and signed integer remainder are
7694distinct operations; for signed integer remainder, use '``srem``'.
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +00007695
Sanjay Patel2b1f6f42017-03-09 16:20:52 +00007696Taking the remainder of a division by zero is undefined behavior.
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +00007697For vectors, if any element of the divisor is zero, the operation has
Sanjay Patel2b1f6f42017-03-09 16:20:52 +00007698undefined behavior.
Sean Silvab084af42012-12-07 10:36:55 +00007699
7700Example:
7701""""""""
7702
Renato Golin124f2592016-07-20 12:16:38 +00007703.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00007704
Tim Northover675a0962014-06-13 14:24:23 +00007705 <result> = urem i32 4, %var ; yields i32:result = 4 % %var
Sean Silvab084af42012-12-07 10:36:55 +00007706
7707'``srem``' Instruction
7708^^^^^^^^^^^^^^^^^^^^^^
7709
7710Syntax:
7711"""""""
7712
7713::
7714
Tim Northover675a0962014-06-13 14:24:23 +00007715 <result> = srem <ty> <op1>, <op2> ; yields ty:result
Sean Silvab084af42012-12-07 10:36:55 +00007716
7717Overview:
7718"""""""""
7719
7720The '``srem``' instruction returns the remainder from the signed
7721division of its two operands. This instruction can also take
7722:ref:`vector <t_vector>` versions of the values in which case the elements
7723must be integers.
7724
7725Arguments:
7726""""""""""
7727
7728The two arguments to the '``srem``' instruction must be
7729:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
7730arguments must have identical types.
7731
7732Semantics:
7733""""""""""
7734
7735This instruction returns the *remainder* of a division (where the result
7736is either zero or has the same sign as the dividend, ``op1``), not the
7737*modulo* operator (where the result is either zero or has the same sign
7738as the divisor, ``op2``) of a value. For more information about the
7739difference, see `The Math
7740Forum <http://mathforum.org/dr.math/problems/anne.4.28.99.html>`_. For a
7741table of how this is implemented in various languages, please see
7742`Wikipedia: modulo
7743operation <http://en.wikipedia.org/wiki/Modulo_operation>`_.
7744
7745Note that signed integer remainder and unsigned integer remainder are
7746distinct operations; for unsigned integer remainder, use '``urem``'.
7747
Sanjay Patel2b1f6f42017-03-09 16:20:52 +00007748Taking the remainder of a division by zero is undefined behavior.
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +00007749For vectors, if any element of the divisor is zero, the operation has
Sanjay Patel2b1f6f42017-03-09 16:20:52 +00007750undefined behavior.
Sean Silvab084af42012-12-07 10:36:55 +00007751Overflow also leads to undefined behavior; this is a rare case, but can
7752occur, for example, by taking the remainder of a 32-bit division of
7753-2147483648 by -1. (The remainder doesn't actually overflow, but this
7754rule lets srem be implemented using instructions that return both the
7755result of the division and the remainder.)
7756
7757Example:
7758""""""""
7759
Renato Golin124f2592016-07-20 12:16:38 +00007760.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00007761
Tim Northover675a0962014-06-13 14:24:23 +00007762 <result> = srem i32 4, %var ; yields i32:result = 4 % %var
Sean Silvab084af42012-12-07 10:36:55 +00007763
7764.. _i_frem:
7765
7766'``frem``' Instruction
7767^^^^^^^^^^^^^^^^^^^^^^
7768
7769Syntax:
7770"""""""
7771
7772::
7773
Tim Northover675a0962014-06-13 14:24:23 +00007774 <result> = frem [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result
Sean Silvab084af42012-12-07 10:36:55 +00007775
7776Overview:
7777"""""""""
7778
7779The '``frem``' instruction returns the remainder from the division of
7780its two operands.
7781
7782Arguments:
7783""""""""""
7784
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00007785The two arguments to the '``frem``' instruction must be
Mandeep Singh Grang547a0d72018-11-01 23:22:25 +00007786:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00007787floating-point values. Both arguments must have identical types.
Sean Silvab084af42012-12-07 10:36:55 +00007788
7789Semantics:
7790""""""""""
7791
Sanjay Patel7b722402018-03-07 17:18:22 +00007792The value produced is the floating-point remainder of the two operands.
7793This is the same output as a libm '``fmod``' function, but without any
Mandeep Singh Grang547a0d72018-11-01 23:22:25 +00007794possibility of setting ``errno``. The remainder has the same sign as the
Sanjay Patel7b722402018-03-07 17:18:22 +00007795dividend.
Sanjay Patelec95e0e2018-03-20 17:05:19 +00007796This instruction is assumed to execute in the default :ref:`floating-point
Mandeep Singh Grang547a0d72018-11-01 23:22:25 +00007797environment <floatenv>`.
Sanjay Patel7b722402018-03-07 17:18:22 +00007798This instruction can also take any number of :ref:`fast-math
7799flags <fastmath>`, which are optimization hints to enable otherwise
7800unsafe floating-point optimizations:
Sean Silvab084af42012-12-07 10:36:55 +00007801
7802Example:
7803""""""""
7804
Renato Golin124f2592016-07-20 12:16:38 +00007805.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00007806
Tim Northover675a0962014-06-13 14:24:23 +00007807 <result> = frem float 4.0, %var ; yields float:result = 4.0 % %var
Sean Silvab084af42012-12-07 10:36:55 +00007808
7809.. _bitwiseops:
7810
7811Bitwise Binary Operations
7812-------------------------
7813
7814Bitwise binary operators are used to do various forms of bit-twiddling
7815in a program. They are generally very efficient instructions and can
7816commonly be strength reduced from other instructions. They require two
7817operands of the same type, execute an operation on them, and produce a
7818single value. The resulting value is the same type as its operands.
7819
7820'``shl``' Instruction
7821^^^^^^^^^^^^^^^^^^^^^
7822
7823Syntax:
7824"""""""
7825
7826::
7827
Tim Northover675a0962014-06-13 14:24:23 +00007828 <result> = shl <ty> <op1>, <op2> ; yields ty:result
7829 <result> = shl nuw <ty> <op1>, <op2> ; yields ty:result
7830 <result> = shl nsw <ty> <op1>, <op2> ; yields ty:result
7831 <result> = shl nuw nsw <ty> <op1>, <op2> ; yields ty:result
Sean Silvab084af42012-12-07 10:36:55 +00007832
7833Overview:
7834"""""""""
7835
7836The '``shl``' instruction returns the first operand shifted to the left
7837a specified number of bits.
7838
7839Arguments:
7840""""""""""
7841
7842Both arguments to the '``shl``' instruction must be the same
7843:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer type.
7844'``op2``' is treated as an unsigned value.
7845
7846Semantics:
7847""""""""""
7848
7849The value produced is ``op1`` \* 2\ :sup:`op2` mod 2\ :sup:`n`,
7850where ``n`` is the width of the result. If ``op2`` is (statically or
Sean Silvab8a108c2015-04-17 21:58:55 +00007851dynamically) equal to or larger than the number of bits in
Nuno Lopesb2781fb2017-06-06 08:28:17 +00007852``op1``, this instruction returns a :ref:`poison value <poisonvalues>`.
7853If the arguments are vectors, each vector element of ``op1`` is shifted
7854by the corresponding shift amount in ``op2``.
Sean Silvab084af42012-12-07 10:36:55 +00007855
Nuno Lopesb2781fb2017-06-06 08:28:17 +00007856If the ``nuw`` keyword is present, then the shift produces a poison
7857value if it shifts out any non-zero bits.
7858If the ``nsw`` keyword is present, then the shift produces a poison
Sanjay Patel2896c772018-06-01 15:21:14 +00007859value if it shifts out any bits that disagree with the resultant sign bit.
Sean Silvab084af42012-12-07 10:36:55 +00007860
7861Example:
7862""""""""
7863
Renato Golin124f2592016-07-20 12:16:38 +00007864.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00007865
Tim Northover675a0962014-06-13 14:24:23 +00007866 <result> = shl i32 4, %var ; yields i32: 4 << %var
7867 <result> = shl i32 4, 2 ; yields i32: 16
7868 <result> = shl i32 1, 10 ; yields i32: 1024
Sean Silvab084af42012-12-07 10:36:55 +00007869 <result> = shl i32 1, 32 ; undefined
7870 <result> = shl <2 x i32> < i32 1, i32 1>, < i32 1, i32 2> ; yields: result=<2 x i32> < i32 2, i32 4>
7871
7872'``lshr``' Instruction
7873^^^^^^^^^^^^^^^^^^^^^^
7874
7875Syntax:
7876"""""""
7877
7878::
7879
Tim Northover675a0962014-06-13 14:24:23 +00007880 <result> = lshr <ty> <op1>, <op2> ; yields ty:result
7881 <result> = lshr exact <ty> <op1>, <op2> ; yields ty:result
Sean Silvab084af42012-12-07 10:36:55 +00007882
7883Overview:
7884"""""""""
7885
7886The '``lshr``' instruction (logical shift right) returns the first
7887operand shifted to the right a specified number of bits with zero fill.
7888
7889Arguments:
7890""""""""""
7891
7892Both arguments to the '``lshr``' instruction must be the same
7893:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer type.
7894'``op2``' is treated as an unsigned value.
7895
7896Semantics:
7897""""""""""
7898
7899This instruction always performs a logical shift right operation. The
7900most significant bits of the result will be filled with zero bits after
7901the shift. If ``op2`` is (statically or dynamically) equal to or larger
Nuno Lopesb2781fb2017-06-06 08:28:17 +00007902than the number of bits in ``op1``, this instruction returns a :ref:`poison
7903value <poisonvalues>`. If the arguments are vectors, each vector element
7904of ``op1`` is shifted by the corresponding shift amount in ``op2``.
Sean Silvab084af42012-12-07 10:36:55 +00007905
7906If the ``exact`` keyword is present, the result value of the ``lshr`` is
Nuno Lopesb2781fb2017-06-06 08:28:17 +00007907a poison value if any of the bits shifted out are non-zero.
Sean Silvab084af42012-12-07 10:36:55 +00007908
7909Example:
7910""""""""
7911
Renato Golin124f2592016-07-20 12:16:38 +00007912.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00007913
Tim Northover675a0962014-06-13 14:24:23 +00007914 <result> = lshr i32 4, 1 ; yields i32:result = 2
7915 <result> = lshr i32 4, 2 ; yields i32:result = 1
7916 <result> = lshr i8 4, 3 ; yields i8:result = 0
7917 <result> = lshr i8 -2, 1 ; yields i8:result = 0x7F
Sean Silvab084af42012-12-07 10:36:55 +00007918 <result> = lshr i32 1, 32 ; undefined
7919 <result> = lshr <2 x i32> < i32 -2, i32 4>, < i32 1, i32 2> ; yields: result=<2 x i32> < i32 0x7FFFFFFF, i32 1>
7920
7921'``ashr``' Instruction
7922^^^^^^^^^^^^^^^^^^^^^^
7923
7924Syntax:
7925"""""""
7926
7927::
7928
Tim Northover675a0962014-06-13 14:24:23 +00007929 <result> = ashr <ty> <op1>, <op2> ; yields ty:result
7930 <result> = ashr exact <ty> <op1>, <op2> ; yields ty:result
Sean Silvab084af42012-12-07 10:36:55 +00007931
7932Overview:
7933"""""""""
7934
7935The '``ashr``' instruction (arithmetic shift right) returns the first
7936operand shifted to the right a specified number of bits with sign
7937extension.
7938
7939Arguments:
7940""""""""""
7941
7942Both arguments to the '``ashr``' instruction must be the same
7943:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer type.
7944'``op2``' is treated as an unsigned value.
7945
7946Semantics:
7947""""""""""
7948
7949This instruction always performs an arithmetic shift right operation,
7950The most significant bits of the result will be filled with the sign bit
7951of ``op1``. If ``op2`` is (statically or dynamically) equal to or larger
Nuno Lopesb2781fb2017-06-06 08:28:17 +00007952than the number of bits in ``op1``, this instruction returns a :ref:`poison
7953value <poisonvalues>`. If the arguments are vectors, each vector element
7954of ``op1`` is shifted by the corresponding shift amount in ``op2``.
Sean Silvab084af42012-12-07 10:36:55 +00007955
7956If the ``exact`` keyword is present, the result value of the ``ashr`` is
Nuno Lopesb2781fb2017-06-06 08:28:17 +00007957a poison value if any of the bits shifted out are non-zero.
Sean Silvab084af42012-12-07 10:36:55 +00007958
7959Example:
7960""""""""
7961
Renato Golin124f2592016-07-20 12:16:38 +00007962.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00007963
Tim Northover675a0962014-06-13 14:24:23 +00007964 <result> = ashr i32 4, 1 ; yields i32:result = 2
7965 <result> = ashr i32 4, 2 ; yields i32:result = 1
7966 <result> = ashr i8 4, 3 ; yields i8:result = 0
7967 <result> = ashr i8 -2, 1 ; yields i8:result = -1
Sean Silvab084af42012-12-07 10:36:55 +00007968 <result> = ashr i32 1, 32 ; undefined
7969 <result> = ashr <2 x i32> < i32 -2, i32 4>, < i32 1, i32 3> ; yields: result=<2 x i32> < i32 -1, i32 0>
7970
7971'``and``' Instruction
7972^^^^^^^^^^^^^^^^^^^^^
7973
7974Syntax:
7975"""""""
7976
7977::
7978
Tim Northover675a0962014-06-13 14:24:23 +00007979 <result> = and <ty> <op1>, <op2> ; yields ty:result
Sean Silvab084af42012-12-07 10:36:55 +00007980
7981Overview:
7982"""""""""
7983
7984The '``and``' instruction returns the bitwise logical and of its two
7985operands.
7986
7987Arguments:
7988""""""""""
7989
7990The two arguments to the '``and``' instruction must be
7991:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
7992arguments must have identical types.
7993
7994Semantics:
7995""""""""""
7996
7997The truth table used for the '``and``' instruction is:
7998
7999+-----+-----+-----+
8000| In0 | In1 | Out |
8001+-----+-----+-----+
8002| 0 | 0 | 0 |
8003+-----+-----+-----+
8004| 0 | 1 | 0 |
8005+-----+-----+-----+
8006| 1 | 0 | 0 |
8007+-----+-----+-----+
8008| 1 | 1 | 1 |
8009+-----+-----+-----+
8010
8011Example:
8012""""""""
8013
Renato Golin124f2592016-07-20 12:16:38 +00008014.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00008015
Tim Northover675a0962014-06-13 14:24:23 +00008016 <result> = and i32 4, %var ; yields i32:result = 4 & %var
8017 <result> = and i32 15, 40 ; yields i32:result = 8
8018 <result> = and i32 4, 8 ; yields i32:result = 0
Sean Silvab084af42012-12-07 10:36:55 +00008019
8020'``or``' Instruction
8021^^^^^^^^^^^^^^^^^^^^
8022
8023Syntax:
8024"""""""
8025
8026::
8027
Tim Northover675a0962014-06-13 14:24:23 +00008028 <result> = or <ty> <op1>, <op2> ; yields ty:result
Sean Silvab084af42012-12-07 10:36:55 +00008029
8030Overview:
8031"""""""""
8032
8033The '``or``' instruction returns the bitwise logical inclusive or of its
8034two operands.
8035
8036Arguments:
8037""""""""""
8038
8039The two arguments to the '``or``' instruction must be
8040:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
8041arguments must have identical types.
8042
8043Semantics:
8044""""""""""
8045
8046The truth table used for the '``or``' instruction is:
8047
8048+-----+-----+-----+
8049| In0 | In1 | Out |
8050+-----+-----+-----+
8051| 0 | 0 | 0 |
8052+-----+-----+-----+
8053| 0 | 1 | 1 |
8054+-----+-----+-----+
8055| 1 | 0 | 1 |
8056+-----+-----+-----+
8057| 1 | 1 | 1 |
8058+-----+-----+-----+
8059
8060Example:
8061""""""""
8062
8063::
8064
Tim Northover675a0962014-06-13 14:24:23 +00008065 <result> = or i32 4, %var ; yields i32:result = 4 | %var
8066 <result> = or i32 15, 40 ; yields i32:result = 47
8067 <result> = or i32 4, 8 ; yields i32:result = 12
Sean Silvab084af42012-12-07 10:36:55 +00008068
8069'``xor``' Instruction
8070^^^^^^^^^^^^^^^^^^^^^
8071
8072Syntax:
8073"""""""
8074
8075::
8076
Tim Northover675a0962014-06-13 14:24:23 +00008077 <result> = xor <ty> <op1>, <op2> ; yields ty:result
Sean Silvab084af42012-12-07 10:36:55 +00008078
8079Overview:
8080"""""""""
8081
8082The '``xor``' instruction returns the bitwise logical exclusive or of
8083its two operands. The ``xor`` is used to implement the "one's
8084complement" operation, which is the "~" operator in C.
8085
8086Arguments:
8087""""""""""
8088
8089The two arguments to the '``xor``' instruction must be
8090:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
8091arguments must have identical types.
8092
8093Semantics:
8094""""""""""
8095
8096The truth table used for the '``xor``' instruction is:
8097
8098+-----+-----+-----+
8099| In0 | In1 | Out |
8100+-----+-----+-----+
8101| 0 | 0 | 0 |
8102+-----+-----+-----+
8103| 0 | 1 | 1 |
8104+-----+-----+-----+
8105| 1 | 0 | 1 |
8106+-----+-----+-----+
8107| 1 | 1 | 0 |
8108+-----+-----+-----+
8109
8110Example:
8111""""""""
8112
Renato Golin124f2592016-07-20 12:16:38 +00008113.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00008114
Tim Northover675a0962014-06-13 14:24:23 +00008115 <result> = xor i32 4, %var ; yields i32:result = 4 ^ %var
8116 <result> = xor i32 15, 40 ; yields i32:result = 39
8117 <result> = xor i32 4, 8 ; yields i32:result = 12
8118 <result> = xor i32 %V, -1 ; yields i32:result = ~%V
Sean Silvab084af42012-12-07 10:36:55 +00008119
8120Vector Operations
8121-----------------
8122
8123LLVM supports several instructions to represent vector operations in a
8124target-independent manner. These instructions cover the element-access
8125and vector-specific operations needed to process vectors effectively.
8126While LLVM does directly support these vector operations, many
8127sophisticated algorithms will want to use target-specific intrinsics to
8128take full advantage of a specific target.
8129
8130.. _i_extractelement:
8131
8132'``extractelement``' Instruction
8133^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8134
8135Syntax:
8136"""""""
8137
8138::
8139
Michael J. Spencer1f10c5ea2014-05-01 22:12:39 +00008140 <result> = extractelement <n x <ty>> <val>, <ty2> <idx> ; yields <ty>
Sean Silvab084af42012-12-07 10:36:55 +00008141
8142Overview:
8143"""""""""
8144
8145The '``extractelement``' instruction extracts a single scalar element
8146from a vector at a specified index.
8147
8148Arguments:
8149""""""""""
8150
8151The first operand of an '``extractelement``' instruction is a value of
8152:ref:`vector <t_vector>` type. The second operand is an index indicating
8153the position from which to extract the element. The index may be a
Michael J. Spencer1f10c5ea2014-05-01 22:12:39 +00008154variable of any integer type.
Sean Silvab084af42012-12-07 10:36:55 +00008155
8156Semantics:
8157""""""""""
8158
8159The result is a scalar of the same type as the element type of ``val``.
8160Its value is the value at position ``idx`` of ``val``. If ``idx``
Nico Weber80fee252019-06-09 19:27:50 +00008161exceeds the length of ``val``, the result is a
Eli Friedman2c7a81b2018-06-08 21:23:09 +00008162:ref:`poison value <poisonvalues>`.
Sean Silvab084af42012-12-07 10:36:55 +00008163
8164Example:
8165""""""""
8166
Renato Golin124f2592016-07-20 12:16:38 +00008167.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00008168
8169 <result> = extractelement <4 x i32> %vec, i32 0 ; yields i32
8170
8171.. _i_insertelement:
8172
8173'``insertelement``' Instruction
8174^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8175
8176Syntax:
8177"""""""
8178
8179::
8180
Michael J. Spencer1f10c5ea2014-05-01 22:12:39 +00008181 <result> = insertelement <n x <ty>> <val>, <ty> <elt>, <ty2> <idx> ; yields <n x <ty>>
Sean Silvab084af42012-12-07 10:36:55 +00008182
8183Overview:
8184"""""""""
8185
8186The '``insertelement``' instruction inserts a scalar element into a
8187vector at a specified index.
8188
8189Arguments:
8190""""""""""
8191
8192The first operand of an '``insertelement``' instruction is a value of
8193:ref:`vector <t_vector>` type. The second operand is a scalar value whose
8194type must equal the element type of the first operand. The third operand
8195is an index indicating the position at which to insert the value. The
Michael J. Spencer1f10c5ea2014-05-01 22:12:39 +00008196index may be a variable of any integer type.
Sean Silvab084af42012-12-07 10:36:55 +00008197
8198Semantics:
8199""""""""""
8200
8201The result is a vector of the same type as ``val``. Its element values
8202are those of ``val`` except at position ``idx``, where it gets the value
Nico Weber80fee252019-06-09 19:27:50 +00008203``elt``. If ``idx`` exceeds the length of ``val``, the result
Eli Friedman2c7a81b2018-06-08 21:23:09 +00008204is a :ref:`poison value <poisonvalues>`.
Sean Silvab084af42012-12-07 10:36:55 +00008205
8206Example:
8207""""""""
8208
Renato Golin124f2592016-07-20 12:16:38 +00008209.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00008210
8211 <result> = insertelement <4 x i32> %vec, i32 1, i32 0 ; yields <4 x i32>
8212
8213.. _i_shufflevector:
8214
8215'``shufflevector``' Instruction
8216^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8217
8218Syntax:
8219"""""""
8220
8221::
8222
8223 <result> = shufflevector <n x <ty>> <v1>, <n x <ty>> <v2>, <m x i32> <mask> ; yields <m x <ty>>
8224
8225Overview:
8226"""""""""
8227
8228The '``shufflevector``' instruction constructs a permutation of elements
8229from two input vectors, returning a vector with the same element type as
8230the input and length that is the same as the shuffle mask.
8231
8232Arguments:
8233""""""""""
8234
8235The first two operands of a '``shufflevector``' instruction are vectors
8236with the same type. The third argument is a shuffle mask whose element
8237type is always 'i32'. The result of the instruction is a vector whose
8238length is the same as the shuffle mask and whose element type is the
8239same as the element type of the first two operands.
8240
8241The shuffle mask operand is required to be a constant vector with either
8242constant integer or undef values.
8243
8244Semantics:
8245""""""""""
8246
8247The elements of the two input vectors are numbered from left to right
8248across both of the vectors. The shuffle mask operand specifies, for each
8249element of the result vector, which element of the two input vectors the
Sanjay Patel6e410182017-04-12 18:39:53 +00008250result element gets. If the shuffle mask is undef, the result vector is
8251undef. If any element of the mask operand is undef, that element of the
8252result is undef. If the shuffle mask selects an undef element from one
8253of the input vectors, the resulting element is undef.
Sean Silvab084af42012-12-07 10:36:55 +00008254
8255Example:
8256""""""""
8257
Renato Golin124f2592016-07-20 12:16:38 +00008258.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00008259
8260 <result> = shufflevector <4 x i32> %v1, <4 x i32> %v2,
8261 <4 x i32> <i32 0, i32 4, i32 1, i32 5> ; yields <4 x i32>
8262 <result> = shufflevector <4 x i32> %v1, <4 x i32> undef,
8263 <4 x i32> <i32 0, i32 1, i32 2, i32 3> ; yields <4 x i32> - Identity shuffle.
8264 <result> = shufflevector <8 x i32> %v1, <8 x i32> undef,
8265 <4 x i32> <i32 0, i32 1, i32 2, i32 3> ; yields <4 x i32>
8266 <result> = shufflevector <4 x i32> %v1, <4 x i32> %v2,
8267 <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7 > ; yields <8 x i32>
8268
8269Aggregate Operations
8270--------------------
8271
8272LLVM supports several instructions for working with
8273:ref:`aggregate <t_aggregate>` values.
8274
8275.. _i_extractvalue:
8276
8277'``extractvalue``' Instruction
8278^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8279
8280Syntax:
8281"""""""
8282
8283::
8284
8285 <result> = extractvalue <aggregate type> <val>, <idx>{, <idx>}*
8286
8287Overview:
8288"""""""""
8289
8290The '``extractvalue``' instruction extracts the value of a member field
8291from an :ref:`aggregate <t_aggregate>` value.
8292
8293Arguments:
8294""""""""""
8295
8296The first operand of an '``extractvalue``' instruction is a value of
Arch D. Robisona7f8f252015-10-14 19:10:45 +00008297:ref:`struct <t_struct>` or :ref:`array <t_array>` type. The other operands are
Sean Silvab084af42012-12-07 10:36:55 +00008298constant indices to specify which value to extract in a similar manner
8299as indices in a '``getelementptr``' instruction.
8300
8301The major differences to ``getelementptr`` indexing are:
8302
8303- Since the value being indexed is not a pointer, the first index is
8304 omitted and assumed to be zero.
8305- At least one index must be specified.
8306- Not only struct indices but also array indices must be in bounds.
8307
8308Semantics:
8309""""""""""
8310
8311The result is the value at the position in the aggregate specified by
8312the index operands.
8313
8314Example:
8315""""""""
8316
Renato Golin124f2592016-07-20 12:16:38 +00008317.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00008318
8319 <result> = extractvalue {i32, float} %agg, 0 ; yields i32
8320
8321.. _i_insertvalue:
8322
8323'``insertvalue``' Instruction
8324^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8325
8326Syntax:
8327"""""""
8328
8329::
8330
8331 <result> = insertvalue <aggregate type> <val>, <ty> <elt>, <idx>{, <idx>}* ; yields <aggregate type>
8332
8333Overview:
8334"""""""""
8335
8336The '``insertvalue``' instruction inserts a value into a member field in
8337an :ref:`aggregate <t_aggregate>` value.
8338
8339Arguments:
8340""""""""""
8341
8342The first operand of an '``insertvalue``' instruction is a value of
8343:ref:`struct <t_struct>` or :ref:`array <t_array>` type. The second operand is
8344a first-class value to insert. The following operands are constant
8345indices indicating the position at which to insert the value in a
8346similar manner as indices in a '``extractvalue``' instruction. The value
8347to insert must have the same type as the value identified by the
8348indices.
8349
8350Semantics:
8351""""""""""
8352
8353The result is an aggregate of the same type as ``val``. Its value is
8354that of ``val`` except that the value at the position specified by the
8355indices is that of ``elt``.
8356
8357Example:
8358""""""""
8359
8360.. code-block:: llvm
8361
8362 %agg1 = insertvalue {i32, float} undef, i32 1, 0 ; yields {i32 1, float undef}
8363 %agg2 = insertvalue {i32, float} %agg1, float %val, 1 ; yields {i32 1, float %val}
Dan Liewffcfe7f2014-09-08 21:19:46 +00008364 %agg3 = insertvalue {i32, {float}} undef, float %val, 1, 0 ; yields {i32 undef, {float %val}}
Sean Silvab084af42012-12-07 10:36:55 +00008365
8366.. _memoryops:
8367
8368Memory Access and Addressing Operations
8369---------------------------------------
8370
8371A key design point of an SSA-based representation is how it represents
8372memory. In LLVM, no memory locations are in SSA form, which makes things
8373very simple. This section describes how to read, write, and allocate
8374memory in LLVM.
8375
8376.. _i_alloca:
8377
8378'``alloca``' Instruction
8379^^^^^^^^^^^^^^^^^^^^^^^^
8380
8381Syntax:
8382"""""""
8383
8384::
8385
Matt Arsenault3c1fc762017-04-10 22:27:50 +00008386 <result> = alloca [inalloca] <type> [, <ty> <NumElements>] [, align <alignment>] [, addrspace(<num>)] ; yields type addrspace(num)*:result
Sean Silvab084af42012-12-07 10:36:55 +00008387
8388Overview:
8389"""""""""
8390
8391The '``alloca``' instruction allocates memory on the stack frame of the
8392currently executing function, to be automatically released when this
8393function returns to its caller. The object is always allocated in the
Matt Arsenault3c1fc762017-04-10 22:27:50 +00008394address space for allocas indicated in the datalayout.
Sean Silvab084af42012-12-07 10:36:55 +00008395
8396Arguments:
8397""""""""""
8398
8399The '``alloca``' instruction allocates ``sizeof(<type>)*NumElements``
8400bytes of memory on the runtime stack, returning a pointer of the
8401appropriate type to the program. If "NumElements" is specified, it is
8402the number of elements allocated, otherwise "NumElements" is defaulted
8403to be one. If a constant alignment is specified, the value result of the
Reid Kleckner15fe7a52014-07-15 01:16:09 +00008404allocation is guaranteed to be aligned to at least that boundary. The
8405alignment may not be greater than ``1 << 29``. If not specified, or if
8406zero, the target can choose to align the allocation on any convenient
8407boundary compatible with the type.
Sean Silvab084af42012-12-07 10:36:55 +00008408
8409'``type``' may be any sized type.
8410
8411Semantics:
8412""""""""""
8413
Sanjay Patelb6bc11d2019-02-19 22:35:12 +00008414Memory is allocated; a pointer is returned. The allocated memory is
8415uninitialized, and loading from uninitialized memory produces an undefined
8416value. The operation itself is undefined if there is insufficient stack
8417space for the allocation.'``alloca``'d memory is automatically released
8418when the function returns. The '``alloca``' instruction is commonly used
8419to represent automatic variables that must have an address available. When
8420the function returns (either with the ``ret`` or ``resume`` instructions),
8421the memory is reclaimed. Allocating zero bytes is legal, but the returned
8422pointer may not be unique. The order in which memory is allocated (ie.,
8423which way the stack grows) is not specified.
Sean Silvab084af42012-12-07 10:36:55 +00008424
8425Example:
8426""""""""
8427
8428.. code-block:: llvm
8429
Tim Northover675a0962014-06-13 14:24:23 +00008430 %ptr = alloca i32 ; yields i32*:ptr
8431 %ptr = alloca i32, i32 4 ; yields i32*:ptr
8432 %ptr = alloca i32, i32 4, align 1024 ; yields i32*:ptr
8433 %ptr = alloca i32, align 1024 ; yields i32*:ptr
Sean Silvab084af42012-12-07 10:36:55 +00008434
8435.. _i_load:
8436
8437'``load``' Instruction
8438^^^^^^^^^^^^^^^^^^^^^^
8439
8440Syntax:
8441"""""""
8442
8443::
8444
Artur Pilipenkob4d00902015-09-28 17:41:08 +00008445 <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 +00008446 <result> = load atomic [volatile] <ty>, <ty>* <pointer> [syncscope("<target-scope>")] <ordering>, align <alignment> [, !invariant.group !<index>]
Sean Silvab084af42012-12-07 10:36:55 +00008447 !<index> = !{ i32 1 }
Artur Pilipenko253d71e2015-09-18 12:07:10 +00008448 !<deref_bytes_node> = !{i64 <dereferenceable_bytes>}
Artur Pilipenkob4d00902015-09-28 17:41:08 +00008449 !<align_node> = !{ i64 <value_alignment> }
Sean Silvab084af42012-12-07 10:36:55 +00008450
8451Overview:
8452"""""""""
8453
8454The '``load``' instruction is used to read from memory.
8455
8456Arguments:
8457""""""""""
8458
Sanjoy Dasc2cf6ef2016-06-01 16:13:10 +00008459The argument to the ``load`` instruction specifies the memory address from which
8460to load. The type specified must be a :ref:`first class <t_firstclass>` type of
8461known size (i.e. not containing an :ref:`opaque structural type <t_opaque>`). If
8462the ``load`` is marked as ``volatile``, then the optimizer is not allowed to
8463modify the number or order of execution of this ``load`` with other
8464:ref:`volatile operations <volatile>`.
Sean Silvab084af42012-12-07 10:36:55 +00008465
JF Bastiend1fb5852015-12-17 22:09:19 +00008466If the ``load`` is marked as ``atomic``, it takes an extra :ref:`ordering
Konstantin Zhuravlyovbb80d3e2017-07-11 22:23:00 +00008467<ordering>` and optional ``syncscope("<target-scope>")`` argument. The
8468``release`` and ``acq_rel`` orderings are not valid on ``load`` instructions.
8469Atomic loads produce :ref:`defined <memmodel>` results when they may see
8470multiple atomic stores. The type of the pointee must be an integer, pointer, or
8471floating-point type whose bit width is a power of two greater than or equal to
8472eight and less than or equal to a target-specific size limit. ``align`` must be
8473explicitly specified on atomic loads, and the load has undefined behavior if the
8474alignment is not set to a value which is at least the size in bytes of the
JF Bastiend1fb5852015-12-17 22:09:19 +00008475pointee. ``!nontemporal`` does not have any defined semantics for atomic loads.
Sean Silvab084af42012-12-07 10:36:55 +00008476
8477The optional constant ``align`` argument specifies the alignment of the
8478operation (that is, the alignment of the memory address). A value of 0
Eli Bendersky239a78b2013-04-17 20:17:08 +00008479or an omitted ``align`` argument means that the operation has the ABI
Sean Silvab084af42012-12-07 10:36:55 +00008480alignment for the target. It is the responsibility of the code emitter
8481to ensure that the alignment information is correct. Overestimating the
8482alignment results in undefined behavior. Underestimating the alignment
Reid Kleckner15fe7a52014-07-15 01:16:09 +00008483may produce less efficient code. An alignment of 1 is always safe. The
Matt Arsenault7020f252016-06-16 16:33:41 +00008484maximum possible alignment is ``1 << 29``. An alignment value higher
8485than the size of the loaded type implies memory up to the alignment
8486value bytes can be safely loaded without trapping in the default
8487address space. Access of the high bytes can interfere with debugging
8488tools, so should not be accessed if the function has the
8489``sanitize_thread`` or ``sanitize_address`` attributes.
Sean Silvab084af42012-12-07 10:36:55 +00008490
8491The optional ``!nontemporal`` metadata must reference a single
Stefanus Du Toit736e2e22013-06-20 14:02:44 +00008492metadata name ``<index>`` corresponding to a metadata node with one
Sean Silvab084af42012-12-07 10:36:55 +00008493``i32`` entry of value 1. The existence of the ``!nontemporal``
Stefanus Du Toit736e2e22013-06-20 14:02:44 +00008494metadata on the instruction tells the optimizer and code generator
Sean Silvab084af42012-12-07 10:36:55 +00008495that this load is not expected to be reused in the cache. The code
8496generator may select special instructions to save cache bandwidth, such
8497as the ``MOVNT`` instruction on x86.
8498
8499The optional ``!invariant.load`` metadata must reference a single
Stefanus Du Toit736e2e22013-06-20 14:02:44 +00008500metadata name ``<index>`` corresponding to a metadata node with no
Geoff Berry4bda5762016-08-31 17:39:21 +00008501entries. If a load instruction tagged with the ``!invariant.load``
8502metadata is executed, the optimizer may assume the memory location
8503referenced by the load contains the same value at all points in the
Eli Friedmane15a1112018-07-17 20:38:11 +00008504program where the memory location is known to be dereferenceable;
8505otherwise, the behavior is undefined.
Sean Silvab084af42012-12-07 10:36:55 +00008506
Piotr Padlewski6c15ec42015-09-15 18:32:14 +00008507The optional ``!invariant.group`` metadata must reference a single metadata name
Piotr Padlewskice358262018-05-18 23:53:46 +00008508 ``<index>`` corresponding to a metadata node with no entries.
8509 See ``invariant.group`` metadata.
Piotr Padlewski6c15ec42015-09-15 18:32:14 +00008510
Philip Reamescdb72f32014-10-20 22:40:55 +00008511The optional ``!nonnull`` metadata must reference a single
8512metadata name ``<index>`` corresponding to a metadata node with no
8513entries. The existence of the ``!nonnull`` metadata on the
8514instruction tells the optimizer that the value loaded is known to
Eli Friedmane15a1112018-07-17 20:38:11 +00008515never be null. If the value is null at runtime, the behavior is undefined.
8516This is analogous to the ``nonnull`` attribute on parameters and return
8517values. This metadata can only be applied to loads of a pointer type.
Philip Reamescdb72f32014-10-20 22:40:55 +00008518
Artur Pilipenko253d71e2015-09-18 12:07:10 +00008519The optional ``!dereferenceable`` metadata must reference a single metadata
8520name ``<deref_bytes_node>`` corresponding to a metadata node with one ``i64``
Sean Silva706fba52015-08-06 22:56:24 +00008521entry. The existence of the ``!dereferenceable`` metadata on the instruction
Sanjoy Dasf9995472015-05-19 20:10:19 +00008522tells the optimizer that the value loaded is known to be dereferenceable.
Sean Silva706fba52015-08-06 22:56:24 +00008523The number of bytes known to be dereferenceable is specified by the integer
8524value in the metadata node. This is analogous to the ''dereferenceable''
8525attribute on parameters and return values. This metadata can only be applied
Sanjoy Dasf9995472015-05-19 20:10:19 +00008526to loads of a pointer type.
8527
8528The optional ``!dereferenceable_or_null`` metadata must reference a single
Artur Pilipenko253d71e2015-09-18 12:07:10 +00008529metadata name ``<deref_bytes_node>`` corresponding to a metadata node with one
8530``i64`` entry. The existence of the ``!dereferenceable_or_null`` metadata on the
Sanjoy Dasf9995472015-05-19 20:10:19 +00008531instruction tells the optimizer that the value loaded is known to be either
8532dereferenceable or null.
Sean Silva706fba52015-08-06 22:56:24 +00008533The number of bytes known to be dereferenceable is specified by the integer
8534value in the metadata node. This is analogous to the ''dereferenceable_or_null''
8535attribute on parameters and return values. This metadata can only be applied
Sanjoy Dasf9995472015-05-19 20:10:19 +00008536to loads of a pointer type.
8537
Artur Pilipenkob4d00902015-09-28 17:41:08 +00008538The optional ``!align`` metadata must reference a single metadata name
8539``<align_node>`` corresponding to a metadata node with one ``i64`` entry.
8540The existence of the ``!align`` metadata on the instruction tells the
8541optimizer that the value loaded is known to be aligned to a boundary specified
8542by the integer value in the metadata node. The alignment must be a power of 2.
8543This is analogous to the ''align'' attribute on parameters and return values.
Eli Friedmane15a1112018-07-17 20:38:11 +00008544This metadata can only be applied to loads of a pointer type. If the returned
8545value is not appropriately aligned at runtime, the behavior is undefined.
Artur Pilipenkob4d00902015-09-28 17:41:08 +00008546
Sean Silvab084af42012-12-07 10:36:55 +00008547Semantics:
8548""""""""""
8549
8550The location of memory pointed to is loaded. If the value being loaded
8551is of scalar type then the number of bytes read does not exceed the
8552minimum number of bytes needed to hold all bits of the type. For
8553example, loading an ``i24`` reads at most three bytes. When loading a
8554value of a type like ``i20`` with a size that is not an integral number
8555of bytes, the result is undefined if the value was not originally
8556written using a store of the same type.
8557
8558Examples:
8559"""""""""
8560
8561.. code-block:: llvm
8562
Tim Northover675a0962014-06-13 14:24:23 +00008563 %ptr = alloca i32 ; yields i32*:ptr
8564 store i32 3, i32* %ptr ; yields void
David Blaikiec7aabbb2015-03-04 22:06:14 +00008565 %val = load i32, i32* %ptr ; yields i32:val = i32 3
Sean Silvab084af42012-12-07 10:36:55 +00008566
8567.. _i_store:
8568
8569'``store``' Instruction
8570^^^^^^^^^^^^^^^^^^^^^^^
8571
8572Syntax:
8573"""""""
8574
8575::
8576
Piotr Padlewski6c15ec42015-09-15 18:32:14 +00008577 store [volatile] <ty> <value>, <ty>* <pointer>[, align <alignment>][, !nontemporal !<index>][, !invariant.group !<index>] ; yields void
Konstantin Zhuravlyovbb80d3e2017-07-11 22:23:00 +00008578 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 +00008579
8580Overview:
8581"""""""""
8582
8583The '``store``' instruction is used to write to memory.
8584
8585Arguments:
8586""""""""""
8587
Sanjoy Dasc2cf6ef2016-06-01 16:13:10 +00008588There are two arguments to the ``store`` instruction: a value to store and an
8589address at which to store it. The type of the ``<pointer>`` operand must be a
8590pointer to the :ref:`first class <t_firstclass>` type of the ``<value>``
8591operand. If the ``store`` is marked as ``volatile``, then the optimizer is not
8592allowed to modify the number or order of execution of this ``store`` with other
8593:ref:`volatile operations <volatile>`. Only values of :ref:`first class
8594<t_firstclass>` types of known size (i.e. not containing an :ref:`opaque
8595structural type <t_opaque>`) can be stored.
Sean Silvab084af42012-12-07 10:36:55 +00008596
JF Bastiend1fb5852015-12-17 22:09:19 +00008597If the ``store`` is marked as ``atomic``, it takes an extra :ref:`ordering
Konstantin Zhuravlyovbb80d3e2017-07-11 22:23:00 +00008598<ordering>` and optional ``syncscope("<target-scope>")`` argument. The
8599``acquire`` and ``acq_rel`` orderings aren't valid on ``store`` instructions.
8600Atomic loads produce :ref:`defined <memmodel>` results when they may see
8601multiple atomic stores. The type of the pointee must be an integer, pointer, or
8602floating-point type whose bit width is a power of two greater than or equal to
8603eight and less than or equal to a target-specific size limit. ``align`` must be
8604explicitly specified on atomic stores, and the store has undefined behavior if
8605the alignment is not set to a value which is at least the size in bytes of the
JF Bastiend1fb5852015-12-17 22:09:19 +00008606pointee. ``!nontemporal`` does not have any defined semantics for atomic stores.
Sean Silvab084af42012-12-07 10:36:55 +00008607
Eli Benderskyca380842013-04-17 17:17:20 +00008608The optional constant ``align`` argument specifies the alignment of the
Sean Silvab084af42012-12-07 10:36:55 +00008609operation (that is, the alignment of the memory address). A value of 0
Eli Benderskyca380842013-04-17 17:17:20 +00008610or an omitted ``align`` argument means that the operation has the ABI
Sean Silvab084af42012-12-07 10:36:55 +00008611alignment for the target. It is the responsibility of the code emitter
8612to ensure that the alignment information is correct. Overestimating the
Eli Benderskyca380842013-04-17 17:17:20 +00008613alignment results in undefined behavior. Underestimating the
Sean Silvab084af42012-12-07 10:36:55 +00008614alignment may produce less efficient code. An alignment of 1 is always
Matt Arsenault7020f252016-06-16 16:33:41 +00008615safe. The maximum possible alignment is ``1 << 29``. An alignment
8616value higher than the size of the stored type implies memory up to the
8617alignment value bytes can be stored to without trapping in the default
8618address space. Storing to the higher bytes however may result in data
8619races if another thread can access the same address. Introducing a
8620data race is not allowed. Storing to the extra bytes is not allowed
8621even in situations where a data race is known to not exist if the
8622function has the ``sanitize_address`` attribute.
Sean Silvab084af42012-12-07 10:36:55 +00008623
Stefanus Du Toit736e2e22013-06-20 14:02:44 +00008624The optional ``!nontemporal`` metadata must reference a single metadata
Eli Benderskyca380842013-04-17 17:17:20 +00008625name ``<index>`` corresponding to a metadata node with one ``i32`` entry of
Stefanus Du Toit736e2e22013-06-20 14:02:44 +00008626value 1. The existence of the ``!nontemporal`` metadata on the instruction
Sean Silvab084af42012-12-07 10:36:55 +00008627tells the optimizer and code generator that this load is not expected to
8628be reused in the cache. The code generator may select special
JF Bastiend2d8ffd2016-01-13 04:52:26 +00008629instructions to save cache bandwidth, such as the ``MOVNT`` instruction on
Sean Silvab084af42012-12-07 10:36:55 +00008630x86.
8631
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +00008632The optional ``!invariant.group`` metadata must reference a
Piotr Padlewski6c15ec42015-09-15 18:32:14 +00008633single metadata name ``<index>``. See ``invariant.group`` metadata.
8634
Sean Silvab084af42012-12-07 10:36:55 +00008635Semantics:
8636""""""""""
8637
Eli Benderskyca380842013-04-17 17:17:20 +00008638The contents of memory are updated to contain ``<value>`` at the
8639location specified by the ``<pointer>`` operand. If ``<value>`` is
Sean Silvab084af42012-12-07 10:36:55 +00008640of scalar type then the number of bytes written does not exceed the
8641minimum number of bytes needed to hold all bits of the type. For
8642example, storing an ``i24`` writes at most three bytes. When writing a
8643value of a type like ``i20`` with a size that is not an integral number
8644of bytes, it is unspecified what happens to the extra bits that do not
8645belong to the type, but they will typically be overwritten.
8646
8647Example:
8648""""""""
8649
8650.. code-block:: llvm
8651
Tim Northover675a0962014-06-13 14:24:23 +00008652 %ptr = alloca i32 ; yields i32*:ptr
8653 store i32 3, i32* %ptr ; yields void
Nick Lewycky149d04c2015-08-11 01:05:16 +00008654 %val = load i32, i32* %ptr ; yields i32:val = i32 3
Sean Silvab084af42012-12-07 10:36:55 +00008655
8656.. _i_fence:
8657
8658'``fence``' Instruction
8659^^^^^^^^^^^^^^^^^^^^^^^
8660
8661Syntax:
8662"""""""
8663
8664::
8665
Konstantin Zhuravlyovbb80d3e2017-07-11 22:23:00 +00008666 fence [syncscope("<target-scope>")] <ordering> ; yields void
Sean Silvab084af42012-12-07 10:36:55 +00008667
8668Overview:
8669"""""""""
8670
8671The '``fence``' instruction is used to introduce happens-before edges
8672between operations.
8673
8674Arguments:
8675""""""""""
8676
8677'``fence``' instructions take an :ref:`ordering <ordering>` argument which
8678defines what *synchronizes-with* edges they add. They can only be given
8679``acquire``, ``release``, ``acq_rel``, and ``seq_cst`` orderings.
8680
8681Semantics:
8682""""""""""
8683
8684A fence A which has (at least) ``release`` ordering semantics
8685*synchronizes with* a fence B with (at least) ``acquire`` ordering
8686semantics if and only if there exist atomic operations X and Y, both
8687operating on some atomic object M, such that A is sequenced before X, X
8688modifies M (either directly or through some side effect of a sequence
8689headed by X), Y is sequenced before B, and Y observes M. This provides a
8690*happens-before* dependency between A and B. Rather than an explicit
8691``fence``, one (but not both) of the atomic operations X or Y might
8692provide a ``release`` or ``acquire`` (resp.) ordering constraint and
8693still *synchronize-with* the explicit ``fence`` and establish the
8694*happens-before* edge.
8695
8696A ``fence`` which has ``seq_cst`` ordering, in addition to having both
8697``acquire`` and ``release`` semantics specified above, participates in
8698the global program order of other ``seq_cst`` operations and/or fences.
8699
Konstantin Zhuravlyovbb80d3e2017-07-11 22:23:00 +00008700A ``fence`` instruction can also take an optional
8701":ref:`syncscope <syncscope>`" argument.
Sean Silvab084af42012-12-07 10:36:55 +00008702
8703Example:
8704""""""""
8705
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +00008706.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00008707
Konstantin Zhuravlyovbb80d3e2017-07-11 22:23:00 +00008708 fence acquire ; yields void
8709 fence syncscope("singlethread") seq_cst ; yields void
8710 fence syncscope("agent") seq_cst ; yields void
Sean Silvab084af42012-12-07 10:36:55 +00008711
8712.. _i_cmpxchg:
8713
8714'``cmpxchg``' Instruction
8715^^^^^^^^^^^^^^^^^^^^^^^^^
8716
8717Syntax:
8718"""""""
8719
8720::
8721
Konstantin Zhuravlyovbb80d3e2017-07-11 22:23:00 +00008722 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 +00008723
8724Overview:
8725"""""""""
8726
8727The '``cmpxchg``' instruction is used to atomically modify memory. It
8728loads a value in memory and compares it to a given value. If they are
Tim Northover420a2162014-06-13 14:24:07 +00008729equal, it tries to store a new value into the memory.
Sean Silvab084af42012-12-07 10:36:55 +00008730
8731Arguments:
8732""""""""""
8733
8734There are three arguments to the '``cmpxchg``' instruction: an address
8735to operate on, a value to compare to the value currently be at that
8736address, and a new value to place at that address if the compared values
Philip Reames1960cfd2016-02-19 00:06:41 +00008737are equal. The type of '<cmp>' must be an integer or pointer type whose
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +00008738bit width is a power of two greater than or equal to eight and less
Philip Reames1960cfd2016-02-19 00:06:41 +00008739than or equal to a target-specific size limit. '<cmp>' and '<new>' must
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +00008740have the same type, and the type of '<pointer>' must be a pointer to
8741that type. If the ``cmpxchg`` is marked as ``volatile``, then the
Philip Reames1960cfd2016-02-19 00:06:41 +00008742optimizer is not allowed to modify the number or order of execution of
8743this ``cmpxchg`` with other :ref:`volatile operations <volatile>`.
Sean Silvab084af42012-12-07 10:36:55 +00008744
Tim Northovere94a5182014-03-11 10:48:52 +00008745The success and failure :ref:`ordering <ordering>` arguments specify how this
Tim Northover1dcc9f92014-06-13 14:24:16 +00008746``cmpxchg`` synchronizes with other atomic operations. Both ordering parameters
8747must be at least ``monotonic``, the ordering constraint on failure must be no
8748stronger than that on success, and the failure ordering cannot be either
8749``release`` or ``acq_rel``.
Sean Silvab084af42012-12-07 10:36:55 +00008750
Konstantin Zhuravlyovbb80d3e2017-07-11 22:23:00 +00008751A ``cmpxchg`` instruction can also take an optional
8752":ref:`syncscope <syncscope>`" argument.
Sean Silvab084af42012-12-07 10:36:55 +00008753
8754The pointer passed into cmpxchg must have alignment greater than or
8755equal to the size in memory of the operand.
8756
8757Semantics:
8758""""""""""
8759
Tim Northover420a2162014-06-13 14:24:07 +00008760The contents of memory at the location specified by the '``<pointer>``' operand
Matthias Braun93f2b4b2017-08-09 22:22:04 +00008761is read and compared to '``<cmp>``'; if the values are equal, '``<new>``' is
8762written to the location. The original value at the location is returned,
8763together with a flag indicating success (true) or failure (false).
Tim Northover420a2162014-06-13 14:24:07 +00008764
8765If the cmpxchg operation is marked as ``weak`` then a spurious failure is
8766permitted: the operation may not write ``<new>`` even if the comparison
8767matched.
8768
8769If the cmpxchg operation is strong (the default), the i1 value is 1 if and only
8770if the value loaded equals ``cmp``.
Sean Silvab084af42012-12-07 10:36:55 +00008771
Tim Northovere94a5182014-03-11 10:48:52 +00008772A successful ``cmpxchg`` is a read-modify-write instruction for the purpose of
8773identifying release sequences. A failed ``cmpxchg`` is equivalent to an atomic
8774load with an ordering parameter determined the second ordering parameter.
Sean Silvab084af42012-12-07 10:36:55 +00008775
8776Example:
8777""""""""
8778
8779.. code-block:: llvm
8780
8781 entry:
Duncan P. N. Exon Smithc917c7a2016-02-07 05:06:35 +00008782 %orig = load atomic i32, i32* %ptr unordered, align 4 ; yields i32
Sean Silvab084af42012-12-07 10:36:55 +00008783 br label %loop
8784
8785 loop:
Duncan P. N. Exon Smithc917c7a2016-02-07 05:06:35 +00008786 %cmp = phi i32 [ %orig, %entry ], [%value_loaded, %loop]
Sean Silvab084af42012-12-07 10:36:55 +00008787 %squared = mul i32 %cmp, %cmp
Tim Northover675a0962014-06-13 14:24:23 +00008788 %val_success = cmpxchg i32* %ptr, i32 %cmp, i32 %squared acq_rel monotonic ; yields { i32, i1 }
Tim Northover420a2162014-06-13 14:24:07 +00008789 %value_loaded = extractvalue { i32, i1 } %val_success, 0
8790 %success = extractvalue { i32, i1 } %val_success, 1
Sean Silvab084af42012-12-07 10:36:55 +00008791 br i1 %success, label %done, label %loop
8792
8793 done:
8794 ...
8795
8796.. _i_atomicrmw:
8797
8798'``atomicrmw``' Instruction
8799^^^^^^^^^^^^^^^^^^^^^^^^^^^
8800
8801Syntax:
8802"""""""
8803
8804::
8805
Konstantin Zhuravlyovbb80d3e2017-07-11 22:23:00 +00008806 atomicrmw [volatile] <operation> <ty>* <pointer>, <ty> <value> [syncscope("<target-scope>")] <ordering> ; yields ty
Sean Silvab084af42012-12-07 10:36:55 +00008807
8808Overview:
8809"""""""""
8810
8811The '``atomicrmw``' instruction is used to atomically modify memory.
8812
8813Arguments:
8814""""""""""
8815
8816There are three arguments to the '``atomicrmw``' instruction: an
8817operation to apply, an address whose value to modify, an argument to the
8818operation. The operation must be one of the following keywords:
8819
8820- xchg
8821- add
8822- sub
8823- and
8824- nand
8825- or
8826- xor
8827- max
8828- min
8829- umax
8830- umin
Matt Arsenault39508332019-01-22 18:18:02 +00008831- fadd
8832- fsub
Sean Silvab084af42012-12-07 10:36:55 +00008833
Matt Arsenault0cb08e42019-01-17 10:49:01 +00008834For most of these operations, the type of '<value>' must be an integer
8835type whose bit width is a power of two greater than or equal to eight
8836and less than or equal to a target-specific size limit. For xchg, this
8837may also be a floating point type with the same size constraints as
Matt Arsenault39508332019-01-22 18:18:02 +00008838integers. For fadd/fsub, this must be a floating point type. The
8839type of the '``<pointer>``' operand must be a pointer to that type. If
8840the ``atomicrmw`` is marked as ``volatile``, then the optimizer is not
8841allowed to modify the number or order of execution of this
8842``atomicrmw`` with other :ref:`volatile operations <volatile>`.
Sean Silvab084af42012-12-07 10:36:55 +00008843
Konstantin Zhuravlyovbb80d3e2017-07-11 22:23:00 +00008844A ``atomicrmw`` instruction can also take an optional
8845":ref:`syncscope <syncscope>`" argument.
8846
Sean Silvab084af42012-12-07 10:36:55 +00008847Semantics:
8848""""""""""
8849
8850The contents of memory at the location specified by the '``<pointer>``'
8851operand are atomically read, modified, and written back. The original
8852value at the location is returned. The modification is specified by the
8853operation argument:
8854
8855- xchg: ``*ptr = val``
8856- add: ``*ptr = *ptr + val``
8857- sub: ``*ptr = *ptr - val``
8858- and: ``*ptr = *ptr & val``
8859- nand: ``*ptr = ~(*ptr & val)``
8860- or: ``*ptr = *ptr | val``
8861- xor: ``*ptr = *ptr ^ val``
8862- max: ``*ptr = *ptr > val ? *ptr : val`` (using a signed comparison)
8863- min: ``*ptr = *ptr < val ? *ptr : val`` (using a signed comparison)
8864- umax: ``*ptr = *ptr > val ? *ptr : val`` (using an unsigned
8865 comparison)
8866- umin: ``*ptr = *ptr < val ? *ptr : val`` (using an unsigned
8867 comparison)
Matt Arsenault39508332019-01-22 18:18:02 +00008868- fadd: ``*ptr = *ptr + val`` (using floating point arithmetic)
8869- fsub: ``*ptr = *ptr - val`` (using floating point arithmetic)
Sean Silvab084af42012-12-07 10:36:55 +00008870
8871Example:
8872""""""""
8873
8874.. code-block:: llvm
8875
Tim Northover675a0962014-06-13 14:24:23 +00008876 %old = atomicrmw add i32* %ptr, i32 1 acquire ; yields i32
Sean Silvab084af42012-12-07 10:36:55 +00008877
8878.. _i_getelementptr:
8879
8880'``getelementptr``' Instruction
8881^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8882
8883Syntax:
8884"""""""
8885
8886::
8887
Peter Collingbourned93620b2016-11-10 22:34:55 +00008888 <result> = getelementptr <ty>, <ty>* <ptrval>{, [inrange] <ty> <idx>}*
8889 <result> = getelementptr inbounds <ty>, <ty>* <ptrval>{, [inrange] <ty> <idx>}*
8890 <result> = getelementptr <ty>, <ptr vector> <ptrval>, [inrange] <vector index type> <idx>
Sean Silvab084af42012-12-07 10:36:55 +00008891
8892Overview:
8893"""""""""
8894
8895The '``getelementptr``' instruction is used to get the address of a
8896subelement of an :ref:`aggregate <t_aggregate>` data structure. It performs
Elena Demikhovsky37a4da82015-07-09 07:42:48 +00008897address calculation only and does not access memory. The instruction can also
8898be used to calculate a vector of such addresses.
Sean Silvab084af42012-12-07 10:36:55 +00008899
8900Arguments:
8901""""""""""
8902
David Blaikie16a97eb2015-03-04 22:02:58 +00008903The first argument is always a type used as the basis for the calculations.
8904The second argument is always a pointer or a vector of pointers, and is the
8905base address to start from. The remaining arguments are indices
Sean Silvab084af42012-12-07 10:36:55 +00008906that indicate which of the elements of the aggregate object are indexed.
8907The interpretation of each index is dependent on the type being indexed
8908into. The first index always indexes the pointer value given as the
David Blaikief91b0302017-06-19 05:34:21 +00008909second argument, the second index indexes a value of the type pointed to
Sean Silvab084af42012-12-07 10:36:55 +00008910(not necessarily the value directly pointed to, since the first index
8911can be non-zero), etc. The first type indexed into must be a pointer
8912value, subsequent types can be arrays, vectors, and structs. Note that
8913subsequent types being indexed into can never be pointers, since that
8914would require loading the pointer before continuing calculation.
8915
8916The type of each index argument depends on the type it is indexing into.
8917When indexing into a (optionally packed) structure, only ``i32`` integer
8918**constants** are allowed (when using a vector of indices they must all
8919be the **same** ``i32`` integer constant). When indexing into an array,
8920pointer or vector, integers of any width are allowed, and they are not
8921required to be constant. These integers are treated as signed values
8922where relevant.
8923
8924For example, let's consider a C code fragment and how it gets compiled
8925to LLVM:
8926
8927.. code-block:: c
8928
8929 struct RT {
8930 char A;
8931 int B[10][20];
8932 char C;
8933 };
8934 struct ST {
8935 int X;
8936 double Y;
8937 struct RT Z;
8938 };
8939
8940 int *foo(struct ST *s) {
8941 return &s[1].Z.B[5][13];
8942 }
8943
8944The LLVM code generated by Clang is:
8945
8946.. code-block:: llvm
8947
8948 %struct.RT = type { i8, [10 x [20 x i32]], i8 }
8949 %struct.ST = type { i32, double, %struct.RT }
8950
8951 define i32* @foo(%struct.ST* %s) nounwind uwtable readnone optsize ssp {
8952 entry:
David Blaikie16a97eb2015-03-04 22:02:58 +00008953 %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 +00008954 ret i32* %arrayidx
8955 }
8956
8957Semantics:
8958""""""""""
8959
8960In the example above, the first index is indexing into the
8961'``%struct.ST*``' type, which is a pointer, yielding a '``%struct.ST``'
8962= '``{ i32, double, %struct.RT }``' type, a structure. The second index
8963indexes into the third element of the structure, yielding a
8964'``%struct.RT``' = '``{ i8 , [10 x [20 x i32]], i8 }``' type, another
8965structure. The third index indexes into the second element of the
8966structure, yielding a '``[10 x [20 x i32]]``' type, an array. The two
8967dimensions of the array are subscripted into, yielding an '``i32``'
8968type. The '``getelementptr``' instruction returns a pointer to this
8969element, thus computing a value of '``i32*``' type.
8970
8971Note that it is perfectly legal to index partially through a structure,
8972returning a pointer to an inner element. Because of this, the LLVM code
8973for the given testcase is equivalent to:
8974
8975.. code-block:: llvm
8976
8977 define i32* @foo(%struct.ST* %s) {
David Blaikie16a97eb2015-03-04 22:02:58 +00008978 %t1 = getelementptr %struct.ST, %struct.ST* %s, i32 1 ; yields %struct.ST*:%t1
8979 %t2 = getelementptr %struct.ST, %struct.ST* %t1, i32 0, i32 2 ; yields %struct.RT*:%t2
8980 %t3 = getelementptr %struct.RT, %struct.RT* %t2, i32 0, i32 1 ; yields [10 x [20 x i32]]*:%t3
8981 %t4 = getelementptr [10 x [20 x i32]], [10 x [20 x i32]]* %t3, i32 0, i32 5 ; yields [20 x i32]*:%t4
8982 %t5 = getelementptr [20 x i32], [20 x i32]* %t4, i32 0, i32 13 ; yields i32*:%t5
Sean Silvab084af42012-12-07 10:36:55 +00008983 ret i32* %t5
8984 }
8985
8986If the ``inbounds`` keyword is present, the result value of the
8987``getelementptr`` is a :ref:`poison value <poisonvalues>` if the base
8988pointer is not an *in bounds* address of an allocated object, or if any
8989of the addresses that would be formed by successive addition of the
8990offsets implied by the indices to the base address with infinitely
8991precise signed arithmetic are not an *in bounds* address of that
8992allocated object. The *in bounds* addresses for an allocated object are
8993all the addresses that point into the object, plus the address one byte
Eli Friedman13f2e352017-02-23 00:48:18 +00008994past the end. The only *in bounds* address for a null pointer in the
8995default address-space is the null pointer itself. In cases where the
8996base is a vector of pointers the ``inbounds`` keyword applies to each
8997of the computations element-wise.
Sean Silvab084af42012-12-07 10:36:55 +00008998
8999If the ``inbounds`` keyword is not present, the offsets are added to the
9000base address with silently-wrapping two's complement arithmetic. If the
9001offsets have a different width from the pointer, they are sign-extended
9002or truncated to the width of the pointer. The result value of the
9003``getelementptr`` may be outside the object pointed to by the base
9004pointer. The result value may not necessarily be used to access memory
9005though, even if it happens to point into allocated storage. See the
9006:ref:`Pointer Aliasing Rules <pointeraliasing>` section for more
9007information.
9008
Peter Collingbourned93620b2016-11-10 22:34:55 +00009009If the ``inrange`` keyword is present before any index, loading from or
9010storing to any pointer derived from the ``getelementptr`` has undefined
9011behavior if the load or store would access memory outside of the bounds of
9012the element selected by the index marked as ``inrange``. The result of a
9013pointer comparison or ``ptrtoint`` (including ``ptrtoint``-like operations
9014involving memory) involving a pointer derived from a ``getelementptr`` with
9015the ``inrange`` keyword is undefined, with the exception of comparisons
9016in the case where both operands are in the range of the element selected
9017by the ``inrange`` keyword, inclusive of the address one past the end of
9018that element. Note that the ``inrange`` keyword is currently only allowed
9019in constant ``getelementptr`` expressions.
9020
Sean Silvab084af42012-12-07 10:36:55 +00009021The getelementptr instruction is often confusing. For some more insight
9022into how it works, see :doc:`the getelementptr FAQ <GetElementPtr>`.
9023
9024Example:
9025""""""""
9026
9027.. code-block:: llvm
9028
9029 ; yields [12 x i8]*:aptr
David Blaikie16a97eb2015-03-04 22:02:58 +00009030 %aptr = getelementptr {i32, [12 x i8]}, {i32, [12 x i8]}* %saptr, i64 0, i32 1
Sean Silvab084af42012-12-07 10:36:55 +00009031 ; yields i8*:vptr
David Blaikie16a97eb2015-03-04 22:02:58 +00009032 %vptr = getelementptr {i32, <2 x i8>}, {i32, <2 x i8>}* %svptr, i64 0, i32 1, i32 1
Sean Silvab084af42012-12-07 10:36:55 +00009033 ; yields i8*:eptr
David Blaikie16a97eb2015-03-04 22:02:58 +00009034 %eptr = getelementptr [12 x i8], [12 x i8]* %aptr, i64 0, i32 1
Sean Silvab084af42012-12-07 10:36:55 +00009035 ; yields i32*:iptr
David Blaikie16a97eb2015-03-04 22:02:58 +00009036 %iptr = getelementptr [10 x i32], [10 x i32]* @arr, i16 0, i16 0
Sean Silvab084af42012-12-07 10:36:55 +00009037
Elena Demikhovsky37a4da82015-07-09 07:42:48 +00009038Vector of pointers:
9039"""""""""""""""""""
9040
9041The ``getelementptr`` returns a vector of pointers, instead of a single address,
9042when one or more of its arguments is a vector. In such cases, all vector
9043arguments should have the same number of elements, and every scalar argument
9044will be effectively broadcast into a vector during address calculation.
Sean Silvab084af42012-12-07 10:36:55 +00009045
9046.. code-block:: llvm
9047
Elena Demikhovsky37a4da82015-07-09 07:42:48 +00009048 ; All arguments are vectors:
9049 ; A[i] = ptrs[i] + offsets[i]*sizeof(i8)
9050 %A = getelementptr i8, <4 x i8*> %ptrs, <4 x i64> %offsets
Sean Silva706fba52015-08-06 22:56:24 +00009051
Elena Demikhovsky37a4da82015-07-09 07:42:48 +00009052 ; Add the same scalar offset to each pointer of a vector:
9053 ; A[i] = ptrs[i] + offset*sizeof(i8)
9054 %A = getelementptr i8, <4 x i8*> %ptrs, i64 %offset
Sean Silva706fba52015-08-06 22:56:24 +00009055
Elena Demikhovsky37a4da82015-07-09 07:42:48 +00009056 ; Add distinct offsets to the same pointer:
9057 ; A[i] = ptr + offsets[i]*sizeof(i8)
9058 %A = getelementptr i8, i8* %ptr, <4 x i64> %offsets
Sean Silva706fba52015-08-06 22:56:24 +00009059
Elena Demikhovsky37a4da82015-07-09 07:42:48 +00009060 ; In all cases described above the type of the result is <4 x i8*>
9061
9062The two following instructions are equivalent:
9063
9064.. code-block:: llvm
9065
9066 getelementptr %struct.ST, <4 x %struct.ST*> %s, <4 x i64> %ind1,
9067 <4 x i32> <i32 2, i32 2, i32 2, i32 2>,
9068 <4 x i32> <i32 1, i32 1, i32 1, i32 1>,
9069 <4 x i32> %ind4,
9070 <4 x i64> <i64 13, i64 13, i64 13, i64 13>
Sean Silva706fba52015-08-06 22:56:24 +00009071
Elena Demikhovsky37a4da82015-07-09 07:42:48 +00009072 getelementptr %struct.ST, <4 x %struct.ST*> %s, <4 x i64> %ind1,
9073 i32 2, i32 1, <4 x i32> %ind4, i64 13
9074
9075Let's look at the C code, where the vector version of ``getelementptr``
9076makes sense:
9077
9078.. code-block:: c
9079
9080 // Let's assume that we vectorize the following loop:
Alexey Baderadec2832017-01-30 07:38:58 +00009081 double *A, *B; int *C;
Elena Demikhovsky37a4da82015-07-09 07:42:48 +00009082 for (int i = 0; i < size; ++i) {
9083 A[i] = B[C[i]];
9084 }
9085
9086.. code-block:: llvm
9087
9088 ; get pointers for 8 elements from array B
9089 %ptrs = getelementptr double, double* %B, <8 x i32> %C
9090 ; load 8 elements from array B into A
Elad Cohenef5798a2017-05-03 12:28:54 +00009091 %A = call <8 x double> @llvm.masked.gather.v8f64.v8p0f64(<8 x double*> %ptrs,
Elena Demikhovsky37a4da82015-07-09 07:42:48 +00009092 i32 8, <8 x i1> %mask, <8 x double> %passthru)
Sean Silvab084af42012-12-07 10:36:55 +00009093
9094Conversion Operations
9095---------------------
9096
9097The instructions in this category are the conversion instructions
9098(casting) which all take a single operand and a type. They perform
9099various bit conversions on the operand.
9100
Bjorn Petterssone1285e32017-10-24 11:59:20 +00009101.. _i_trunc:
9102
Sean Silvab084af42012-12-07 10:36:55 +00009103'``trunc .. to``' Instruction
9104^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9105
9106Syntax:
9107"""""""
9108
9109::
9110
9111 <result> = trunc <ty> <value> to <ty2> ; yields ty2
9112
9113Overview:
9114"""""""""
9115
9116The '``trunc``' instruction truncates its operand to the type ``ty2``.
9117
9118Arguments:
9119""""""""""
9120
9121The '``trunc``' instruction takes a value to trunc, and a type to trunc
9122it to. Both types must be of :ref:`integer <t_integer>` types, or vectors
9123of the same number of integers. The bit size of the ``value`` must be
9124larger than the bit size of the destination type, ``ty2``. Equal sized
9125types are not allowed.
9126
9127Semantics:
9128""""""""""
9129
9130The '``trunc``' instruction truncates the high order bits in ``value``
9131and converts the remaining bits to ``ty2``. Since the source size must
9132be larger than the destination size, ``trunc`` cannot be a *no-op cast*.
9133It will always truncate bits.
9134
9135Example:
9136""""""""
9137
9138.. code-block:: llvm
9139
9140 %X = trunc i32 257 to i8 ; yields i8:1
9141 %Y = trunc i32 123 to i1 ; yields i1:true
9142 %Z = trunc i32 122 to i1 ; yields i1:false
9143 %W = trunc <2 x i16> <i16 8, i16 7> to <2 x i8> ; yields <i8 8, i8 7>
9144
Bjorn Petterssone1285e32017-10-24 11:59:20 +00009145.. _i_zext:
9146
Sean Silvab084af42012-12-07 10:36:55 +00009147'``zext .. to``' Instruction
9148^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9149
9150Syntax:
9151"""""""
9152
9153::
9154
9155 <result> = zext <ty> <value> to <ty2> ; yields ty2
9156
9157Overview:
9158"""""""""
9159
9160The '``zext``' instruction zero extends its operand to type ``ty2``.
9161
9162Arguments:
9163""""""""""
9164
9165The '``zext``' instruction takes a value to cast, and a type to cast it
9166to. Both types must be of :ref:`integer <t_integer>` types, or vectors of
9167the same number of integers. The bit size of the ``value`` must be
9168smaller than the bit size of the destination type, ``ty2``.
9169
9170Semantics:
9171""""""""""
9172
9173The ``zext`` fills the high order bits of the ``value`` with zero bits
9174until it reaches the size of the destination type, ``ty2``.
9175
9176When zero extending from i1, the result will always be either 0 or 1.
9177
9178Example:
9179""""""""
9180
9181.. code-block:: llvm
9182
9183 %X = zext i32 257 to i64 ; yields i64:257
9184 %Y = zext i1 true to i32 ; yields i32:1
9185 %Z = zext <2 x i16> <i16 8, i16 7> to <2 x i32> ; yields <i32 8, i32 7>
9186
Bjorn Petterssone1285e32017-10-24 11:59:20 +00009187.. _i_sext:
9188
Sean Silvab084af42012-12-07 10:36:55 +00009189'``sext .. to``' Instruction
9190^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9191
9192Syntax:
9193"""""""
9194
9195::
9196
9197 <result> = sext <ty> <value> to <ty2> ; yields ty2
9198
9199Overview:
9200"""""""""
9201
9202The '``sext``' sign extends ``value`` to the type ``ty2``.
9203
9204Arguments:
9205""""""""""
9206
9207The '``sext``' instruction takes a value to cast, and a type to cast it
9208to. Both types must be of :ref:`integer <t_integer>` types, or vectors of
9209the same number of integers. The bit size of the ``value`` must be
9210smaller than the bit size of the destination type, ``ty2``.
9211
9212Semantics:
9213""""""""""
9214
9215The '``sext``' instruction performs a sign extension by copying the sign
9216bit (highest order bit) of the ``value`` until it reaches the bit size
9217of the type ``ty2``.
9218
9219When sign extending from i1, the extension always results in -1 or 0.
9220
9221Example:
9222""""""""
9223
9224.. code-block:: llvm
9225
9226 %X = sext i8 -1 to i16 ; yields i16 :65535
9227 %Y = sext i1 true to i32 ; yields i32:-1
9228 %Z = sext <2 x i16> <i16 8, i16 7> to <2 x i32> ; yields <i32 8, i32 7>
9229
9230'``fptrunc .. to``' Instruction
9231^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9232
9233Syntax:
9234"""""""
9235
9236::
9237
9238 <result> = fptrunc <ty> <value> to <ty2> ; yields ty2
9239
9240Overview:
9241"""""""""
9242
9243The '``fptrunc``' instruction truncates ``value`` to type ``ty2``.
9244
9245Arguments:
9246""""""""""
9247
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00009248The '``fptrunc``' instruction takes a :ref:`floating-point <t_floating>`
9249value to cast and a :ref:`floating-point <t_floating>` type to cast it to.
Sean Silvab084af42012-12-07 10:36:55 +00009250The size of ``value`` must be larger than the size of ``ty2``. This
9251implies that ``fptrunc`` cannot be used to make a *no-op cast*.
9252
9253Semantics:
9254""""""""""
9255
Dan Liew50456fb2015-09-03 18:43:56 +00009256The '``fptrunc``' instruction casts a ``value`` from a larger
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00009257:ref:`floating-point <t_floating>` type to a smaller :ref:`floating-point
Mandeep Singh Grang547a0d72018-11-01 23:22:25 +00009258<t_floating>` type.
Sanjay Pateld96a3632018-04-03 13:05:20 +00009259This instruction is assumed to execute in the default :ref:`floating-point
9260environment <floatenv>`.
Sean Silvab084af42012-12-07 10:36:55 +00009261
9262Example:
9263""""""""
9264
9265.. code-block:: llvm
9266
Sanjay Pateld96a3632018-04-03 13:05:20 +00009267 %X = fptrunc double 16777217.0 to float ; yields float:16777216.0
9268 %Y = fptrunc double 1.0E+300 to half ; yields half:+infinity
Sean Silvab084af42012-12-07 10:36:55 +00009269
9270'``fpext .. to``' Instruction
9271^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9272
9273Syntax:
9274"""""""
9275
9276::
9277
9278 <result> = fpext <ty> <value> to <ty2> ; yields ty2
9279
9280Overview:
9281"""""""""
9282
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00009283The '``fpext``' extends a floating-point ``value`` to a larger floating-point
9284value.
Sean Silvab084af42012-12-07 10:36:55 +00009285
9286Arguments:
9287""""""""""
9288
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00009289The '``fpext``' instruction takes a :ref:`floating-point <t_floating>`
9290``value`` to cast, and a :ref:`floating-point <t_floating>` type to cast it
Sean Silvab084af42012-12-07 10:36:55 +00009291to. The source type must be smaller than the destination type.
9292
9293Semantics:
9294""""""""""
9295
9296The '``fpext``' instruction extends the ``value`` from a smaller
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00009297:ref:`floating-point <t_floating>` type to a larger :ref:`floating-point
9298<t_floating>` type. The ``fpext`` cannot be used to make a
Sean Silvab084af42012-12-07 10:36:55 +00009299*no-op cast* because it always changes bits. Use ``bitcast`` to make a
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00009300*no-op cast* for a floating-point cast.
Sean Silvab084af42012-12-07 10:36:55 +00009301
9302Example:
9303""""""""
9304
9305.. code-block:: llvm
9306
9307 %X = fpext float 3.125 to double ; yields double:3.125000e+00
9308 %Y = fpext double %X to fp128 ; yields fp128:0xL00000000000000004000900000000000
9309
9310'``fptoui .. to``' Instruction
9311^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9312
9313Syntax:
9314"""""""
9315
9316::
9317
9318 <result> = fptoui <ty> <value> to <ty2> ; yields ty2
9319
9320Overview:
9321"""""""""
9322
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00009323The '``fptoui``' converts a floating-point ``value`` to its unsigned
Sean Silvab084af42012-12-07 10:36:55 +00009324integer equivalent of type ``ty2``.
9325
9326Arguments:
9327""""""""""
9328
9329The '``fptoui``' instruction takes a value to cast, which must be a
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00009330scalar or vector :ref:`floating-point <t_floating>` value, and a type to
Sean Silvab084af42012-12-07 10:36:55 +00009331cast it to ``ty2``, which must be an :ref:`integer <t_integer>` type. If
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00009332``ty`` is a vector floating-point type, ``ty2`` must be a vector integer
Sean Silvab084af42012-12-07 10:36:55 +00009333type with the same number of elements as ``ty``
9334
9335Semantics:
9336""""""""""
9337
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00009338The '``fptoui``' instruction converts its :ref:`floating-point
9339<t_floating>` operand into the nearest (rounding towards zero)
Eli Friedmanc065bb22018-06-08 21:33:33 +00009340unsigned integer value. If the value cannot fit in ``ty2``, the result
9341is a :ref:`poison value <poisonvalues>`.
Sean Silvab084af42012-12-07 10:36:55 +00009342
9343Example:
9344""""""""
9345
9346.. code-block:: llvm
9347
9348 %X = fptoui double 123.0 to i32 ; yields i32:123
9349 %Y = fptoui float 1.0E+300 to i1 ; yields undefined:1
9350 %Z = fptoui float 1.04E+17 to i8 ; yields undefined:1
9351
9352'``fptosi .. to``' Instruction
9353^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9354
9355Syntax:
9356"""""""
9357
9358::
9359
9360 <result> = fptosi <ty> <value> to <ty2> ; yields ty2
9361
9362Overview:
9363"""""""""
9364
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00009365The '``fptosi``' instruction converts :ref:`floating-point <t_floating>`
Sean Silvab084af42012-12-07 10:36:55 +00009366``value`` to type ``ty2``.
9367
9368Arguments:
9369""""""""""
9370
9371The '``fptosi``' instruction takes a value to cast, which must be a
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00009372scalar or vector :ref:`floating-point <t_floating>` value, and a type to
Sean Silvab084af42012-12-07 10:36:55 +00009373cast it to ``ty2``, which must be an :ref:`integer <t_integer>` type. If
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00009374``ty`` is a vector floating-point type, ``ty2`` must be a vector integer
Sean Silvab084af42012-12-07 10:36:55 +00009375type with the same number of elements as ``ty``
9376
9377Semantics:
9378""""""""""
9379
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00009380The '``fptosi``' instruction converts its :ref:`floating-point
9381<t_floating>` operand into the nearest (rounding towards zero)
Eli Friedmanc065bb22018-06-08 21:33:33 +00009382signed integer value. If the value cannot fit in ``ty2``, the result
9383is a :ref:`poison value <poisonvalues>`.
Sean Silvab084af42012-12-07 10:36:55 +00009384
9385Example:
9386""""""""
9387
9388.. code-block:: llvm
9389
9390 %X = fptosi double -123.0 to i32 ; yields i32:-123
9391 %Y = fptosi float 1.0E-247 to i1 ; yields undefined:1
9392 %Z = fptosi float 1.04E+17 to i8 ; yields undefined:1
9393
9394'``uitofp .. to``' Instruction
9395^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9396
9397Syntax:
9398"""""""
9399
9400::
9401
9402 <result> = uitofp <ty> <value> to <ty2> ; yields ty2
9403
9404Overview:
9405"""""""""
9406
9407The '``uitofp``' instruction regards ``value`` as an unsigned integer
9408and converts that value to the ``ty2`` type.
9409
9410Arguments:
9411""""""""""
9412
9413The '``uitofp``' instruction takes a value to cast, which must be a
9414scalar or vector :ref:`integer <t_integer>` value, and a type to cast it to
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00009415``ty2``, which must be an :ref:`floating-point <t_floating>` type. If
9416``ty`` is a vector integer type, ``ty2`` must be a vector floating-point
Sean Silvab084af42012-12-07 10:36:55 +00009417type with the same number of elements as ``ty``
9418
9419Semantics:
9420""""""""""
9421
9422The '``uitofp``' instruction interprets its operand as an unsigned
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00009423integer quantity and converts it to the corresponding floating-point
Eli Friedman3f1ce092018-06-14 22:58:48 +00009424value. If the value cannot be exactly represented, it is rounded using
9425the default rounding mode.
9426
Sean Silvab084af42012-12-07 10:36:55 +00009427
9428Example:
9429""""""""
9430
9431.. code-block:: llvm
9432
9433 %X = uitofp i32 257 to float ; yields float:257.0
9434 %Y = uitofp i8 -1 to double ; yields double:255.0
9435
9436'``sitofp .. to``' Instruction
9437^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9438
9439Syntax:
9440"""""""
9441
9442::
9443
9444 <result> = sitofp <ty> <value> to <ty2> ; yields ty2
9445
9446Overview:
9447"""""""""
9448
9449The '``sitofp``' instruction regards ``value`` as a signed integer and
9450converts that value to the ``ty2`` type.
9451
9452Arguments:
9453""""""""""
9454
9455The '``sitofp``' instruction takes a value to cast, which must be a
9456scalar or vector :ref:`integer <t_integer>` value, and a type to cast it to
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00009457``ty2``, which must be an :ref:`floating-point <t_floating>` type. If
9458``ty`` is a vector integer type, ``ty2`` must be a vector floating-point
Sean Silvab084af42012-12-07 10:36:55 +00009459type with the same number of elements as ``ty``
9460
9461Semantics:
9462""""""""""
9463
9464The '``sitofp``' instruction interprets its operand as a signed integer
Eli Friedman3f1ce092018-06-14 22:58:48 +00009465quantity and converts it to the corresponding floating-point value. If the
9466value cannot be exactly represented, it is rounded using the default rounding
9467mode.
Sean Silvab084af42012-12-07 10:36:55 +00009468
9469Example:
9470""""""""
9471
9472.. code-block:: llvm
9473
9474 %X = sitofp i32 257 to float ; yields float:257.0
9475 %Y = sitofp i8 -1 to double ; yields double:-1.0
9476
9477.. _i_ptrtoint:
9478
9479'``ptrtoint .. to``' Instruction
9480^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9481
9482Syntax:
9483"""""""
9484
9485::
9486
9487 <result> = ptrtoint <ty> <value> to <ty2> ; yields ty2
9488
9489Overview:
9490"""""""""
9491
9492The '``ptrtoint``' instruction converts the pointer or a vector of
9493pointers ``value`` to the integer (or vector of integers) type ``ty2``.
9494
9495Arguments:
9496""""""""""
9497
9498The '``ptrtoint``' instruction takes a ``value`` to cast, which must be
Ed Maste8ed40ce2015-04-14 20:52:58 +00009499a value of type :ref:`pointer <t_pointer>` or a vector of pointers, and a
Sean Silvab084af42012-12-07 10:36:55 +00009500type to cast it to ``ty2``, which must be an :ref:`integer <t_integer>` or
9501a vector of integers type.
9502
9503Semantics:
9504""""""""""
9505
9506The '``ptrtoint``' instruction converts ``value`` to integer type
9507``ty2`` by interpreting the pointer value as an integer and either
9508truncating or zero extending that value to the size of the integer type.
9509If ``value`` is smaller than ``ty2`` then a zero extension is done. If
9510``value`` is larger than ``ty2`` then a truncation is done. If they are
9511the same size, then nothing is done (*no-op cast*) other than a type
9512change.
9513
9514Example:
9515""""""""
9516
9517.. code-block:: llvm
9518
9519 %X = ptrtoint i32* %P to i8 ; yields truncation on 32-bit architecture
9520 %Y = ptrtoint i32* %P to i64 ; yields zero extension on 32-bit architecture
9521 %Z = ptrtoint <4 x i32*> %P to <4 x i64>; yields vector zero extension for a vector of addresses on 32-bit architecture
9522
9523.. _i_inttoptr:
9524
9525'``inttoptr .. to``' Instruction
9526^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9527
9528Syntax:
9529"""""""
9530
9531::
9532
9533 <result> = inttoptr <ty> <value> to <ty2> ; yields ty2
9534
9535Overview:
9536"""""""""
9537
9538The '``inttoptr``' instruction converts an integer ``value`` to a
9539pointer type, ``ty2``.
9540
9541Arguments:
9542""""""""""
9543
9544The '``inttoptr``' instruction takes an :ref:`integer <t_integer>` value to
9545cast, and a type to cast it to, which must be a :ref:`pointer <t_pointer>`
9546type.
9547
9548Semantics:
9549""""""""""
9550
9551The '``inttoptr``' instruction converts ``value`` to type ``ty2`` by
9552applying either a zero extension or a truncation depending on the size
9553of the integer ``value``. If ``value`` is larger than the size of a
9554pointer then a truncation is done. If ``value`` is smaller than the size
9555of a pointer then a zero extension is done. If they are the same size,
9556nothing is done (*no-op cast*).
9557
9558Example:
9559""""""""
9560
9561.. code-block:: llvm
9562
9563 %X = inttoptr i32 255 to i32* ; yields zero extension on 64-bit architecture
9564 %Y = inttoptr i32 255 to i32* ; yields no-op on 32-bit architecture
9565 %Z = inttoptr i64 0 to i32* ; yields truncation on 32-bit architecture
9566 %Z = inttoptr <4 x i32> %G to <4 x i8*>; yields truncation of vector G to four pointers
9567
9568.. _i_bitcast:
9569
9570'``bitcast .. to``' Instruction
9571^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9572
9573Syntax:
9574"""""""
9575
9576::
9577
9578 <result> = bitcast <ty> <value> to <ty2> ; yields ty2
9579
9580Overview:
9581"""""""""
9582
9583The '``bitcast``' instruction converts ``value`` to type ``ty2`` without
9584changing any bits.
9585
9586Arguments:
9587""""""""""
9588
9589The '``bitcast``' instruction takes a value to cast, which must be a
9590non-aggregate first class value, and a type to cast it to, which must
Matt Arsenault24b49c42013-07-31 17:49:08 +00009591also be a non-aggregate :ref:`first class <t_firstclass>` type. The
9592bit sizes of ``value`` and the destination type, ``ty2``, must be
Sean Silvaa1190322015-08-06 22:56:48 +00009593identical. If the source type is a pointer, the destination type must
Matt Arsenault24b49c42013-07-31 17:49:08 +00009594also be a pointer of the same size. This instruction supports bitwise
9595conversion of vectors to integers and to vectors of other types (as
9596long as they have the same size).
Sean Silvab084af42012-12-07 10:36:55 +00009597
9598Semantics:
9599""""""""""
9600
Matt Arsenault24b49c42013-07-31 17:49:08 +00009601The '``bitcast``' instruction converts ``value`` to type ``ty2``. It
9602is always a *no-op cast* because no bits change with this
9603conversion. The conversion is done as if the ``value`` had been stored
9604to memory and read back as type ``ty2``. Pointer (or vector of
9605pointers) types may only be converted to other pointer (or vector of
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00009606pointers) types with the same address space through this instruction.
9607To convert pointers to other types, use the :ref:`inttoptr <i_inttoptr>`
9608or :ref:`ptrtoint <i_ptrtoint>` instructions first.
Sean Silvab084af42012-12-07 10:36:55 +00009609
9610Example:
9611""""""""
9612
Renato Golin124f2592016-07-20 12:16:38 +00009613.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00009614
9615 %X = bitcast i8 255 to i8 ; yields i8 :-1
9616 %Y = bitcast i32* %x to sint* ; yields sint*:%x
9617 %Z = bitcast <2 x int> %V to i64; ; yields i64: %V
9618 %Z = bitcast <2 x i32*> %V to <2 x i64*> ; yields <2 x i64*>
9619
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00009620.. _i_addrspacecast:
9621
9622'``addrspacecast .. to``' Instruction
9623^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9624
9625Syntax:
9626"""""""
9627
9628::
9629
9630 <result> = addrspacecast <pty> <ptrval> to <pty2> ; yields pty2
9631
9632Overview:
9633"""""""""
9634
9635The '``addrspacecast``' instruction converts ``ptrval`` from ``pty`` in
9636address space ``n`` to type ``pty2`` in address space ``m``.
9637
9638Arguments:
9639""""""""""
9640
9641The '``addrspacecast``' instruction takes a pointer or vector of pointer value
9642to cast and a pointer type to cast it to, which must have a different
9643address space.
9644
9645Semantics:
9646""""""""""
9647
9648The '``addrspacecast``' instruction converts the pointer value
9649``ptrval`` to type ``pty2``. It can be a *no-op cast* or a complex
Matt Arsenault54a2a172013-11-15 05:44:56 +00009650value modification, depending on the target and the address space
9651pair. Pointer conversions within the same address space must be
9652performed with the ``bitcast`` instruction. Note that if the address space
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00009653conversion is legal then both result and operand refer to the same memory
9654location.
9655
9656Example:
9657""""""""
9658
9659.. code-block:: llvm
9660
Matt Arsenault9c13dd02013-11-15 22:43:50 +00009661 %X = addrspacecast i32* %x to i32 addrspace(1)* ; yields i32 addrspace(1)*:%x
9662 %Y = addrspacecast i32 addrspace(1)* %y to i64 addrspace(2)* ; yields i64 addrspace(2)*:%y
9663 %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 +00009664
Sean Silvab084af42012-12-07 10:36:55 +00009665.. _otherops:
9666
9667Other Operations
9668----------------
9669
9670The instructions in this category are the "miscellaneous" instructions,
9671which defy better classification.
9672
9673.. _i_icmp:
9674
9675'``icmp``' Instruction
9676^^^^^^^^^^^^^^^^^^^^^^
9677
9678Syntax:
9679"""""""
9680
9681::
9682
Tim Northover675a0962014-06-13 14:24:23 +00009683 <result> = icmp <cond> <ty> <op1>, <op2> ; yields i1 or <N x i1>:result
Sean Silvab084af42012-12-07 10:36:55 +00009684
9685Overview:
9686"""""""""
9687
9688The '``icmp``' instruction returns a boolean value or a vector of
9689boolean values based on comparison of its two integer, integer vector,
9690pointer, or pointer vector operands.
9691
9692Arguments:
9693""""""""""
9694
9695The '``icmp``' instruction takes three operands. The first operand is
9696the condition code indicating the kind of comparison to perform. It is
Sanjay Patel43d41442016-03-30 21:38:20 +00009697not a value, just a keyword. The possible condition codes are:
Sean Silvab084af42012-12-07 10:36:55 +00009698
9699#. ``eq``: equal
9700#. ``ne``: not equal
9701#. ``ugt``: unsigned greater than
9702#. ``uge``: unsigned greater or equal
9703#. ``ult``: unsigned less than
9704#. ``ule``: unsigned less or equal
9705#. ``sgt``: signed greater than
9706#. ``sge``: signed greater or equal
9707#. ``slt``: signed less than
9708#. ``sle``: signed less or equal
9709
9710The remaining two arguments must be :ref:`integer <t_integer>` or
9711:ref:`pointer <t_pointer>` or integer :ref:`vector <t_vector>` typed. They
9712must also be identical types.
9713
9714Semantics:
9715""""""""""
9716
9717The '``icmp``' compares ``op1`` and ``op2`` according to the condition
9718code given as ``cond``. The comparison performed always yields either an
9719:ref:`i1 <t_integer>` or vector of ``i1`` result, as follows:
9720
9721#. ``eq``: yields ``true`` if the operands are equal, ``false``
9722 otherwise. No sign interpretation is necessary or performed.
9723#. ``ne``: yields ``true`` if the operands are unequal, ``false``
9724 otherwise. No sign interpretation is necessary or performed.
9725#. ``ugt``: interprets the operands as unsigned values and yields
9726 ``true`` if ``op1`` is greater than ``op2``.
9727#. ``uge``: interprets the operands as unsigned values and yields
9728 ``true`` if ``op1`` is greater than or equal to ``op2``.
9729#. ``ult``: interprets the operands as unsigned values and yields
9730 ``true`` if ``op1`` is less than ``op2``.
9731#. ``ule``: interprets the operands as unsigned values and yields
9732 ``true`` if ``op1`` is less than or equal to ``op2``.
9733#. ``sgt``: interprets the operands as signed values and yields ``true``
9734 if ``op1`` is greater than ``op2``.
9735#. ``sge``: interprets the operands as signed values and yields ``true``
9736 if ``op1`` is greater than or equal to ``op2``.
9737#. ``slt``: interprets the operands as signed values and yields ``true``
9738 if ``op1`` is less than ``op2``.
9739#. ``sle``: interprets the operands as signed values and yields ``true``
9740 if ``op1`` is less than or equal to ``op2``.
9741
9742If the operands are :ref:`pointer <t_pointer>` typed, the pointer values
9743are compared as if they were integers.
9744
9745If the operands are integer vectors, then they are compared element by
9746element. The result is an ``i1`` vector with the same number of elements
9747as the values being compared. Otherwise, the result is an ``i1``.
9748
9749Example:
9750""""""""
9751
Renato Golin124f2592016-07-20 12:16:38 +00009752.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00009753
9754 <result> = icmp eq i32 4, 5 ; yields: result=false
9755 <result> = icmp ne float* %X, %X ; yields: result=false
9756 <result> = icmp ult i16 4, 5 ; yields: result=true
9757 <result> = icmp sgt i16 4, 5 ; yields: result=false
9758 <result> = icmp ule i16 -4, 5 ; yields: result=false
9759 <result> = icmp sge i16 4, 5 ; yields: result=false
9760
Sean Silvab084af42012-12-07 10:36:55 +00009761.. _i_fcmp:
9762
9763'``fcmp``' Instruction
9764^^^^^^^^^^^^^^^^^^^^^^
9765
9766Syntax:
9767"""""""
9768
9769::
9770
James Molloy88eb5352015-07-10 12:52:00 +00009771 <result> = fcmp [fast-math flags]* <cond> <ty> <op1>, <op2> ; yields i1 or <N x i1>:result
Sean Silvab084af42012-12-07 10:36:55 +00009772
9773Overview:
9774"""""""""
9775
9776The '``fcmp``' instruction returns a boolean value or vector of boolean
9777values based on comparison of its operands.
9778
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00009779If the operands are floating-point scalars, then the result type is a
Sean Silvab084af42012-12-07 10:36:55 +00009780boolean (:ref:`i1 <t_integer>`).
9781
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00009782If the operands are floating-point vectors, then the result type is a
Sean Silvab084af42012-12-07 10:36:55 +00009783vector of boolean with the same number of elements as the operands being
9784compared.
9785
9786Arguments:
9787""""""""""
9788
9789The '``fcmp``' instruction takes three operands. The first operand is
9790the condition code indicating the kind of comparison to perform. It is
Sanjay Patel43d41442016-03-30 21:38:20 +00009791not a value, just a keyword. The possible condition codes are:
Sean Silvab084af42012-12-07 10:36:55 +00009792
9793#. ``false``: no comparison, always returns false
9794#. ``oeq``: ordered and equal
9795#. ``ogt``: ordered and greater than
9796#. ``oge``: ordered and greater than or equal
9797#. ``olt``: ordered and less than
9798#. ``ole``: ordered and less than or equal
9799#. ``one``: ordered and not equal
9800#. ``ord``: ordered (no nans)
9801#. ``ueq``: unordered or equal
9802#. ``ugt``: unordered or greater than
9803#. ``uge``: unordered or greater than or equal
9804#. ``ult``: unordered or less than
9805#. ``ule``: unordered or less than or equal
9806#. ``une``: unordered or not equal
9807#. ``uno``: unordered (either nans)
9808#. ``true``: no comparison, always returns true
9809
9810*Ordered* means that neither operand is a QNAN while *unordered* means
9811that either operand may be a QNAN.
9812
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00009813Each of ``val1`` and ``val2`` arguments must be either a :ref:`floating-point
9814<t_floating>` type or a :ref:`vector <t_vector>` of floating-point type.
9815They must have identical types.
Sean Silvab084af42012-12-07 10:36:55 +00009816
9817Semantics:
9818""""""""""
9819
9820The '``fcmp``' instruction compares ``op1`` and ``op2`` according to the
9821condition code given as ``cond``. If the operands are vectors, then the
9822vectors are compared element by element. Each comparison performed
9823always yields an :ref:`i1 <t_integer>` result, as follows:
9824
9825#. ``false``: always yields ``false``, regardless of operands.
9826#. ``oeq``: yields ``true`` if both operands are not a QNAN and ``op1``
9827 is equal to ``op2``.
9828#. ``ogt``: yields ``true`` if both operands are not a QNAN and ``op1``
9829 is greater than ``op2``.
9830#. ``oge``: yields ``true`` if both operands are not a QNAN and ``op1``
9831 is greater than or equal to ``op2``.
9832#. ``olt``: yields ``true`` if both operands are not a QNAN and ``op1``
9833 is less than ``op2``.
9834#. ``ole``: yields ``true`` if both operands are not a QNAN and ``op1``
9835 is less than or equal to ``op2``.
9836#. ``one``: yields ``true`` if both operands are not a QNAN and ``op1``
9837 is not equal to ``op2``.
9838#. ``ord``: yields ``true`` if both operands are not a QNAN.
9839#. ``ueq``: yields ``true`` if either operand is a QNAN or ``op1`` is
9840 equal to ``op2``.
9841#. ``ugt``: yields ``true`` if either operand is a QNAN or ``op1`` is
9842 greater than ``op2``.
9843#. ``uge``: yields ``true`` if either operand is a QNAN or ``op1`` is
9844 greater than or equal to ``op2``.
9845#. ``ult``: yields ``true`` if either operand is a QNAN or ``op1`` is
9846 less than ``op2``.
9847#. ``ule``: yields ``true`` if either operand is a QNAN or ``op1`` is
9848 less than or equal to ``op2``.
9849#. ``une``: yields ``true`` if either operand is a QNAN or ``op1`` is
9850 not equal to ``op2``.
9851#. ``uno``: yields ``true`` if either operand is a QNAN.
9852#. ``true``: always yields ``true``, regardless of operands.
9853
James Molloy88eb5352015-07-10 12:52:00 +00009854The ``fcmp`` instruction can also optionally take any number of
9855:ref:`fast-math flags <fastmath>`, which are optimization hints to enable
Sanjay Patel85fa9ef2018-03-21 14:15:33 +00009856otherwise unsafe floating-point optimizations.
James Molloy88eb5352015-07-10 12:52:00 +00009857
9858Any set of fast-math flags are legal on an ``fcmp`` instruction, but the
9859only flags that have any effect on its semantics are those that allow
9860assumptions to be made about the values of input arguments; namely
Eli Friedman8bb43262018-07-17 20:28:31 +00009861``nnan``, ``ninf``, and ``reassoc``. See :ref:`fastmath` for more information.
James Molloy88eb5352015-07-10 12:52:00 +00009862
Sean Silvab084af42012-12-07 10:36:55 +00009863Example:
9864""""""""
9865
Renato Golin124f2592016-07-20 12:16:38 +00009866.. code-block:: text
Sean Silvab084af42012-12-07 10:36:55 +00009867
9868 <result> = fcmp oeq float 4.0, 5.0 ; yields: result=false
9869 <result> = fcmp one float 4.0, 5.0 ; yields: result=true
9870 <result> = fcmp olt float 4.0, 5.0 ; yields: result=true
9871 <result> = fcmp ueq double 1.0, 2.0 ; yields: result=false
9872
Sean Silvab084af42012-12-07 10:36:55 +00009873.. _i_phi:
9874
9875'``phi``' Instruction
9876^^^^^^^^^^^^^^^^^^^^^
9877
9878Syntax:
9879"""""""
9880
9881::
9882
9883 <result> = phi <ty> [ <val0>, <label0>], ...
9884
9885Overview:
9886"""""""""
9887
9888The '``phi``' instruction is used to implement the φ node in the SSA
9889graph representing the function.
9890
9891Arguments:
9892""""""""""
9893
9894The type of the incoming values is specified with the first type field.
9895After this, the '``phi``' instruction takes a list of pairs as
9896arguments, with one pair for each predecessor basic block of the current
9897block. Only values of :ref:`first class <t_firstclass>` type may be used as
9898the value arguments to the PHI node. Only labels may be used as the
9899label arguments.
9900
9901There must be no non-phi instructions between the start of a basic block
9902and the PHI instructions: i.e. PHI instructions must be first in a basic
9903block.
9904
9905For the purposes of the SSA form, the use of each incoming value is
9906deemed to occur on the edge from the corresponding predecessor block to
9907the current block (but after any definition of an '``invoke``'
9908instruction's return value on the same edge).
9909
9910Semantics:
9911""""""""""
9912
9913At runtime, the '``phi``' instruction logically takes on the value
9914specified by the pair corresponding to the predecessor basic block that
9915executed just prior to the current block.
9916
9917Example:
9918""""""""
9919
9920.. code-block:: llvm
9921
9922 Loop: ; Infinite loop that counts from 0 on up...
9923 %indvar = phi i32 [ 0, %LoopHeader ], [ %nextindvar, %Loop ]
9924 %nextindvar = add i32 %indvar, 1
9925 br label %Loop
9926
9927.. _i_select:
9928
9929'``select``' Instruction
9930^^^^^^^^^^^^^^^^^^^^^^^^
9931
9932Syntax:
9933"""""""
9934
9935::
9936
Sanjay Patel5a4f7cf2019-05-22 15:50:46 +00009937 <result> = select [fast-math flags] selty <cond>, <ty> <val1>, <ty> <val2> ; yields ty
Sean Silvab084af42012-12-07 10:36:55 +00009938
9939 selty is either i1 or {<N x i1>}
9940
9941Overview:
9942"""""""""
9943
9944The '``select``' instruction is used to choose one value based on a
Joerg Sonnenberger94321ec2014-03-26 15:30:21 +00009945condition, without IR-level branching.
Sean Silvab084af42012-12-07 10:36:55 +00009946
9947Arguments:
9948""""""""""
9949
9950The '``select``' instruction requires an 'i1' value or a vector of 'i1'
9951values indicating the condition, and two values of the same :ref:`first
David Majnemer40a0b592015-03-03 22:45:47 +00009952class <t_firstclass>` type.
Sean Silvab084af42012-12-07 10:36:55 +00009953
Sanjay Patel5a4f7cf2019-05-22 15:50:46 +00009954#. The optional ``fast-math flags`` marker indicates that the select has one or more
9955 :ref:`fast-math flags <fastmath>`. These are optimization hints to enable
9956 otherwise unsafe floating-point optimizations. Fast-math flags are only valid
9957 for selects that return a floating-point scalar or vector type.
9958
Sean Silvab084af42012-12-07 10:36:55 +00009959Semantics:
9960""""""""""
9961
9962If the condition is an i1 and it evaluates to 1, the instruction returns
9963the first value argument; otherwise, it returns the second value
9964argument.
9965
9966If the condition is a vector of i1, then the value arguments must be
9967vectors of the same size, and the selection is done element by element.
9968
David Majnemer40a0b592015-03-03 22:45:47 +00009969If the condition is an i1 and the value arguments are vectors of the
9970same size, then an entire vector is selected.
9971
Sean Silvab084af42012-12-07 10:36:55 +00009972Example:
9973""""""""
9974
9975.. code-block:: llvm
9976
9977 %X = select i1 true, i8 17, i8 42 ; yields i8:17
9978
9979.. _i_call:
9980
9981'``call``' Instruction
9982^^^^^^^^^^^^^^^^^^^^^^
9983
9984Syntax:
9985"""""""
9986
9987::
9988
Alexander Richardson6bcf2ba2018-08-23 09:25:17 +00009989 <result> = [tail | musttail | notail ] call [fast-math flags] [cconv] [ret attrs] [addrspace(<num>)]
9990 [<ty>|<fnty> <fnptrval>(<function args>) [fn attrs] [ operand bundles ]
Sean Silvab084af42012-12-07 10:36:55 +00009991
9992Overview:
9993"""""""""
9994
9995The '``call``' instruction represents a simple function call.
9996
9997Arguments:
9998""""""""""
9999
10000This instruction requires several arguments:
10001
Reid Kleckner5772b772014-04-24 20:14:34 +000010002#. The optional ``tail`` and ``musttail`` markers indicate that the optimizers
Sean Silvaa1190322015-08-06 22:56:48 +000010003 should perform tail call optimization. The ``tail`` marker is a hint that
10004 `can be ignored <CodeGenerator.html#sibcallopt>`_. The ``musttail`` marker
Reid Kleckner5772b772014-04-24 20:14:34 +000010005 means that the call must be tail call optimized in order for the program to
Sean Silvaa1190322015-08-06 22:56:48 +000010006 be correct. The ``musttail`` marker provides these guarantees:
Reid Kleckner5772b772014-04-24 20:14:34 +000010007
10008 #. The call will not cause unbounded stack growth if it is part of a
10009 recursive cycle in the call graph.
10010 #. Arguments with the :ref:`inalloca <attr_inalloca>` attribute are
10011 forwarded in place.
Reid Kleckner414da9d2019-05-24 01:45:47 +000010012 #. If the musttail call appears in a function with the ``"thunk"`` attribute
10013 and the caller and callee both have varargs, than any unprototyped
10014 arguments in register or memory are forwarded to the callee. Similarly,
10015 the return value of the callee is returned the the caller's caller, even
10016 if a void return type is in use.
Reid Kleckner5772b772014-04-24 20:14:34 +000010017
Florian Hahnedae5a62018-01-17 23:29:25 +000010018 Both markers imply that the callee does not access allocas from the caller.
10019 The ``tail`` marker additionally implies that the callee does not access
Reid Kleckner414da9d2019-05-24 01:45:47 +000010020 varargs from the caller. Calls marked ``musttail`` must obey the following
10021 additional rules:
Reid Kleckner5772b772014-04-24 20:14:34 +000010022
10023 - The call must immediately precede a :ref:`ret <i_ret>` instruction,
10024 or a pointer bitcast followed by a ret instruction.
10025 - The ret instruction must return the (possibly bitcasted) value
10026 produced by the call or void.
Sean Silvaa1190322015-08-06 22:56:48 +000010027 - The caller and callee prototypes must match. Pointer types of
Reid Kleckner5772b772014-04-24 20:14:34 +000010028 parameters or return types may differ in pointee type, but not
10029 in address space.
10030 - The calling conventions of the caller and callee must match.
10031 - All ABI-impacting function attributes, such as sret, byval, inreg,
10032 returned, and inalloca, must match.
Reid Kleckner83498642014-08-26 00:33:28 +000010033 - The callee must be varargs iff the caller is varargs. Bitcasting a
10034 non-varargs function to the appropriate varargs type is legal so
10035 long as the non-varargs prefixes obey the other rules.
Reid Kleckner5772b772014-04-24 20:14:34 +000010036
10037 Tail call optimization for calls marked ``tail`` is guaranteed to occur if
10038 the following conditions are met:
Sean Silvab084af42012-12-07 10:36:55 +000010039
10040 - Caller and callee both have the calling convention ``fastcc``.
10041 - The call is in tail position (ret immediately follows call and ret
10042 uses value of call or is void).
10043 - Option ``-tailcallopt`` is enabled, or
10044 ``llvm::GuaranteedTailCallOpt`` is ``true``.
Alp Tokercf218752014-06-30 18:57:16 +000010045 - `Platform-specific constraints are
Sean Silvab084af42012-12-07 10:36:55 +000010046 met. <CodeGenerator.html#tailcallopt>`_
10047
Akira Hatanaka5cfcce122015-11-06 23:55:38 +000010048#. The optional ``notail`` marker indicates that the optimizers should not add
10049 ``tail`` or ``musttail`` markers to the call. It is used to prevent tail
10050 call optimization from being performed on the call.
10051
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +000010052#. The optional ``fast-math flags`` marker indicates that the call has one or more
Sanjay Patelfa54ace2015-12-14 21:59:03 +000010053 :ref:`fast-math flags <fastmath>`, which are optimization hints to enable
10054 otherwise unsafe floating-point optimizations. Fast-math flags are only valid
10055 for calls that return a floating-point scalar or vector type.
10056
Sean Silvab084af42012-12-07 10:36:55 +000010057#. The optional "cconv" marker indicates which :ref:`calling
10058 convention <callingconv>` the call should use. If none is
10059 specified, the call defaults to using C calling conventions. The
10060 calling convention of the call must match the calling convention of
10061 the target function, or else the behavior is undefined.
10062#. The optional :ref:`Parameter Attributes <paramattrs>` list for return
10063 values. Only '``zeroext``', '``signext``', and '``inreg``' attributes
10064 are valid here.
Craig Topper78e7fff2019-01-16 00:21:59 +000010065#. The optional addrspace attribute can be used to indicate the address space
Alexander Richardson6bcf2ba2018-08-23 09:25:17 +000010066 of the called function. If it is not specified, the program address space
10067 from the :ref:`datalayout string<langref_datalayout>` will be used.
Sean Silvab084af42012-12-07 10:36:55 +000010068#. '``ty``': the type of the call instruction itself which is also the
10069 type of the return value. Functions that return no value are marked
10070 ``void``.
David Blaikieb83cf102016-07-13 17:21:34 +000010071#. '``fnty``': shall be the signature of the function being called. The
10072 argument types must match the types implied by this signature. This
10073 type can be omitted if the function is not varargs.
Sean Silvab084af42012-12-07 10:36:55 +000010074#. '``fnptrval``': An LLVM value containing a pointer to a function to
David Blaikieb83cf102016-07-13 17:21:34 +000010075 be called. In most cases, this is a direct function call, but
Sean Silvab084af42012-12-07 10:36:55 +000010076 indirect ``call``'s are just as possible, calling an arbitrary pointer
10077 to function value.
10078#. '``function args``': argument list whose types match the function
10079 signature argument types and parameter attributes. All arguments must
10080 be of :ref:`first class <t_firstclass>` type. If the function signature
10081 indicates the function accepts a variable number of arguments, the
10082 extra arguments can be specified.
George Burgess IV39c91052017-04-13 04:01:55 +000010083#. The optional :ref:`function attributes <fnattrs>` list.
Sanjoy Dasb513a9f2015-09-24 23:34:52 +000010084#. The optional :ref:`operand bundles <opbundles>` list.
Sean Silvab084af42012-12-07 10:36:55 +000010085
10086Semantics:
10087""""""""""
10088
10089The '``call``' instruction is used to cause control flow to transfer to
10090a specified function, with its incoming arguments bound to the specified
10091values. Upon a '``ret``' instruction in the called function, control
10092flow continues with the instruction after the function call, and the
10093return value of the function is bound to the result argument.
10094
10095Example:
10096""""""""
10097
10098.. code-block:: llvm
10099
10100 %retval = call i32 @test(i32 %argc)
10101 call i32 (i8*, ...)* @printf(i8* %msg, i32 12, i8 42) ; yields i32
10102 %X = tail call i32 @foo() ; yields i32
10103 %Y = tail call fastcc i32 @foo() ; yields i32
10104 call void %foo(i8 97 signext)
10105
10106 %struct.A = type { i32, i8 }
Tim Northover675a0962014-06-13 14:24:23 +000010107 %r = call %struct.A @foo() ; yields { i32, i8 }
Sean Silvab084af42012-12-07 10:36:55 +000010108 %gr = extractvalue %struct.A %r, 0 ; yields i32
10109 %gr1 = extractvalue %struct.A %r, 1 ; yields i8
10110 %Z = call void @foo() noreturn ; indicates that %foo never returns normally
10111 %ZZ = call zeroext i32 @bar() ; Return value is %zero extended
10112
10113llvm treats calls to some functions with names and arguments that match
10114the standard C99 library as being the C99 library functions, and may
10115perform optimizations or generate code for them under that assumption.
10116This is something we'd like to change in the future to provide better
10117support for freestanding environments and non-C-based languages.
10118
10119.. _i_va_arg:
10120
10121'``va_arg``' Instruction
10122^^^^^^^^^^^^^^^^^^^^^^^^
10123
10124Syntax:
10125"""""""
10126
10127::
10128
10129 <resultval> = va_arg <va_list*> <arglist>, <argty>
10130
10131Overview:
10132"""""""""
10133
10134The '``va_arg``' instruction is used to access arguments passed through
10135the "variable argument" area of a function call. It is used to implement
10136the ``va_arg`` macro in C.
10137
10138Arguments:
10139""""""""""
10140
10141This instruction takes a ``va_list*`` value and the type of the
10142argument. It returns a value of the specified argument type and
10143increments the ``va_list`` to point to the next argument. The actual
10144type of ``va_list`` is target specific.
10145
10146Semantics:
10147""""""""""
10148
10149The '``va_arg``' instruction loads an argument of the specified type
10150from the specified ``va_list`` and causes the ``va_list`` to point to
10151the next argument. For more information, see the variable argument
10152handling :ref:`Intrinsic Functions <int_varargs>`.
10153
10154It is legal for this instruction to be called in a function which does
10155not take a variable number of arguments, for example, the ``vfprintf``
10156function.
10157
10158``va_arg`` is an LLVM instruction instead of an :ref:`intrinsic
10159function <intrinsics>` because it takes a type as an argument.
10160
10161Example:
10162""""""""
10163
10164See the :ref:`variable argument processing <int_varargs>` section.
10165
10166Note that the code generator does not yet fully support va\_arg on many
10167targets. Also, it does not currently support va\_arg with aggregate
10168types on any target.
10169
10170.. _i_landingpad:
10171
10172'``landingpad``' Instruction
10173^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10174
10175Syntax:
10176"""""""
10177
10178::
10179
David Majnemer7fddecc2015-06-17 20:52:32 +000010180 <resultval> = landingpad <resultty> <clause>+
10181 <resultval> = landingpad <resultty> cleanup <clause>*
Sean Silvab084af42012-12-07 10:36:55 +000010182
10183 <clause> := catch <type> <value>
10184 <clause> := filter <array constant type> <array constant>
10185
10186Overview:
10187"""""""""
10188
10189The '``landingpad``' instruction is used by `LLVM's exception handling
10190system <ExceptionHandling.html#overview>`_ to specify that a basic block
Dmitri Gribenkoe8131122013-01-19 20:34:20 +000010191is a landing pad --- one where the exception lands, and corresponds to the
Sean Silvab084af42012-12-07 10:36:55 +000010192code found in the ``catch`` portion of a ``try``/``catch`` sequence. It
David Majnemer7fddecc2015-06-17 20:52:32 +000010193defines values supplied by the :ref:`personality function <personalityfn>` upon
Sean Silvab084af42012-12-07 10:36:55 +000010194re-entry to the function. The ``resultval`` has the type ``resultty``.
10195
10196Arguments:
10197""""""""""
10198
David Majnemer7fddecc2015-06-17 20:52:32 +000010199The optional
Sean Silvab084af42012-12-07 10:36:55 +000010200``cleanup`` flag indicates that the landing pad block is a cleanup.
10201
Dmitri Gribenkoe8131122013-01-19 20:34:20 +000010202A ``clause`` begins with the clause type --- ``catch`` or ``filter`` --- and
Sean Silvab084af42012-12-07 10:36:55 +000010203contains the global variable representing the "type" that may be caught
10204or filtered respectively. Unlike the ``catch`` clause, the ``filter``
10205clause takes an array constant as its argument. Use
10206"``[0 x i8**] undef``" for a filter which cannot throw. The
10207'``landingpad``' instruction must contain *at least* one ``clause`` or
10208the ``cleanup`` flag.
10209
10210Semantics:
10211""""""""""
10212
10213The '``landingpad``' instruction defines the values which are set by the
David Majnemer7fddecc2015-06-17 20:52:32 +000010214:ref:`personality function <personalityfn>` upon re-entry to the function, and
Sean Silvab084af42012-12-07 10:36:55 +000010215therefore the "result type" of the ``landingpad`` instruction. As with
10216calling conventions, how the personality function results are
10217represented in LLVM IR is target specific.
10218
10219The clauses are applied in order from top to bottom. If two
10220``landingpad`` instructions are merged together through inlining, the
10221clauses from the calling function are appended to the list of clauses.
10222When the call stack is being unwound due to an exception being thrown,
10223the exception is compared against each ``clause`` in turn. If it doesn't
10224match any of the clauses, and the ``cleanup`` flag is not set, then
10225unwinding continues further up the call stack.
10226
10227The ``landingpad`` instruction has several restrictions:
10228
10229- A landing pad block is a basic block which is the unwind destination
10230 of an '``invoke``' instruction.
10231- A landing pad block must have a '``landingpad``' instruction as its
10232 first non-PHI instruction.
10233- There can be only one '``landingpad``' instruction within the landing
10234 pad block.
10235- A basic block that is not a landing pad block may not include a
10236 '``landingpad``' instruction.
Sean Silvab084af42012-12-07 10:36:55 +000010237
10238Example:
10239""""""""
10240
10241.. code-block:: llvm
10242
10243 ;; A landing pad which can catch an integer.
David Majnemer7fddecc2015-06-17 20:52:32 +000010244 %res = landingpad { i8*, i32 }
Sean Silvab084af42012-12-07 10:36:55 +000010245 catch i8** @_ZTIi
10246 ;; A landing pad that is a cleanup.
David Majnemer7fddecc2015-06-17 20:52:32 +000010247 %res = landingpad { i8*, i32 }
Sean Silvab084af42012-12-07 10:36:55 +000010248 cleanup
10249 ;; A landing pad which can catch an integer and can only throw a double.
David Majnemer7fddecc2015-06-17 20:52:32 +000010250 %res = landingpad { i8*, i32 }
Sean Silvab084af42012-12-07 10:36:55 +000010251 catch i8** @_ZTIi
10252 filter [1 x i8**] [@_ZTId]
10253
Joseph Tremoulet2adaa982016-01-10 04:46:10 +000010254.. _i_catchpad:
10255
10256'``catchpad``' Instruction
10257^^^^^^^^^^^^^^^^^^^^^^^^^^
10258
10259Syntax:
10260"""""""
10261
10262::
10263
10264 <resultval> = catchpad within <catchswitch> [<args>*]
10265
10266Overview:
10267"""""""""
10268
10269The '``catchpad``' instruction is used by `LLVM's exception handling
10270system <ExceptionHandling.html#overview>`_ to specify that a basic block
10271begins a catch handler --- one where a personality routine attempts to transfer
10272control to catch an exception.
10273
10274Arguments:
10275""""""""""
10276
10277The ``catchswitch`` operand must always be a token produced by a
10278:ref:`catchswitch <i_catchswitch>` instruction in a predecessor block. This
10279ensures that each ``catchpad`` has exactly one predecessor block, and it always
10280terminates in a ``catchswitch``.
10281
10282The ``args`` correspond to whatever information the personality routine
10283requires to know if this is an appropriate handler for the exception. Control
10284will transfer to the ``catchpad`` if this is the first appropriate handler for
10285the exception.
10286
10287The ``resultval`` has the type :ref:`token <t_token>` and is used to match the
10288``catchpad`` to corresponding :ref:`catchrets <i_catchret>` and other nested EH
10289pads.
10290
10291Semantics:
10292""""""""""
10293
10294When the call stack is being unwound due to an exception being thrown, the
10295exception is compared against the ``args``. If it doesn't match, control will
10296not reach the ``catchpad`` instruction. The representation of ``args`` is
10297entirely target and personality function-specific.
10298
10299Like the :ref:`landingpad <i_landingpad>` instruction, the ``catchpad``
10300instruction must be the first non-phi of its parent basic block.
10301
10302The meaning of the tokens produced and consumed by ``catchpad`` and other "pad"
10303instructions is described in the
10304`Windows exception handling documentation\ <ExceptionHandling.html#wineh>`_.
10305
10306When a ``catchpad`` has been "entered" but not yet "exited" (as
10307described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_),
10308it is undefined behavior to execute a :ref:`call <i_call>` or :ref:`invoke <i_invoke>`
10309that does not carry an appropriate :ref:`"funclet" bundle <ob_funclet>`.
10310
10311Example:
10312""""""""
10313
Renato Golin124f2592016-07-20 12:16:38 +000010314.. code-block:: text
Joseph Tremoulet2adaa982016-01-10 04:46:10 +000010315
10316 dispatch:
10317 %cs = catchswitch within none [label %handler0] unwind to caller
10318 ;; A catch block which can catch an integer.
10319 handler0:
10320 %tok = catchpad within %cs [i8** @_ZTIi]
10321
David Majnemer654e1302015-07-31 17:58:14 +000010322.. _i_cleanuppad:
10323
10324'``cleanuppad``' Instruction
10325^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10326
10327Syntax:
10328"""""""
10329
10330::
10331
David Majnemer8a1c45d2015-12-12 05:38:55 +000010332 <resultval> = cleanuppad within <parent> [<args>*]
David Majnemer654e1302015-07-31 17:58:14 +000010333
10334Overview:
10335"""""""""
10336
10337The '``cleanuppad``' instruction is used by `LLVM's exception handling
10338system <ExceptionHandling.html#overview>`_ to specify that a basic block
10339is a cleanup block --- one where a personality routine attempts to
10340transfer control to run cleanup actions.
10341The ``args`` correspond to whatever additional
10342information the :ref:`personality function <personalityfn>` requires to
10343execute the cleanup.
Joseph Tremoulet8220bcc2015-08-23 00:26:33 +000010344The ``resultval`` has the type :ref:`token <t_token>` and is used to
David Majnemer8a1c45d2015-12-12 05:38:55 +000010345match the ``cleanuppad`` to corresponding :ref:`cleanuprets <i_cleanupret>`.
10346The ``parent`` argument is the token of the funclet that contains the
10347``cleanuppad`` instruction. If the ``cleanuppad`` is not inside a funclet,
10348this operand may be the token ``none``.
David Majnemer654e1302015-07-31 17:58:14 +000010349
10350Arguments:
10351""""""""""
10352
10353The instruction takes a list of arbitrary values which are interpreted
10354by the :ref:`personality function <personalityfn>`.
10355
10356Semantics:
10357""""""""""
10358
David Majnemer654e1302015-07-31 17:58:14 +000010359When the call stack is being unwound due to an exception being thrown,
10360the :ref:`personality function <personalityfn>` transfers control to the
10361``cleanuppad`` with the aid of the personality-specific arguments.
Joseph Tremoulet9ce71f72015-09-03 09:09:43 +000010362As with calling conventions, how the personality function results are
10363represented in LLVM IR is target specific.
David Majnemer654e1302015-07-31 17:58:14 +000010364
10365The ``cleanuppad`` instruction has several restrictions:
10366
10367- A cleanup block is a basic block which is the unwind destination of
10368 an exceptional instruction.
10369- A cleanup block must have a '``cleanuppad``' instruction as its
10370 first non-PHI instruction.
10371- There can be only one '``cleanuppad``' instruction within the
10372 cleanup block.
10373- A basic block that is not a cleanup block may not include a
10374 '``cleanuppad``' instruction.
David Majnemer8a1c45d2015-12-12 05:38:55 +000010375
Joseph Tremoulete28885e2016-01-10 04:28:38 +000010376When a ``cleanuppad`` has been "entered" but not yet "exited" (as
10377described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_),
10378it is undefined behavior to execute a :ref:`call <i_call>` or :ref:`invoke <i_invoke>`
10379that does not carry an appropriate :ref:`"funclet" bundle <ob_funclet>`.
David Majnemer8a1c45d2015-12-12 05:38:55 +000010380
David Majnemer654e1302015-07-31 17:58:14 +000010381Example:
10382""""""""
10383
Renato Golin124f2592016-07-20 12:16:38 +000010384.. code-block:: text
David Majnemer654e1302015-07-31 17:58:14 +000010385
David Majnemer8a1c45d2015-12-12 05:38:55 +000010386 %tok = cleanuppad within %cs []
David Majnemer654e1302015-07-31 17:58:14 +000010387
Sean Silvab084af42012-12-07 10:36:55 +000010388.. _intrinsics:
10389
10390Intrinsic Functions
10391===================
10392
10393LLVM supports the notion of an "intrinsic function". These functions
10394have well known names and semantics and are required to follow certain
10395restrictions. Overall, these intrinsics represent an extension mechanism
10396for the LLVM language that does not require changing all of the
10397transformations in LLVM when adding to the language (or the bitcode
10398reader/writer, the parser, etc...).
10399
10400Intrinsic function names must all start with an "``llvm.``" prefix. This
10401prefix is reserved in LLVM for intrinsic names; thus, function names may
10402not begin with this prefix. Intrinsic functions must always be external
10403functions: you cannot define the body of intrinsic functions. Intrinsic
10404functions may only be used in call or invoke instructions: it is illegal
10405to take the address of an intrinsic function. Additionally, because
10406intrinsic functions are part of the LLVM language, it is required if any
10407are added that they be documented here.
10408
10409Some intrinsic functions can be overloaded, i.e., the intrinsic
10410represents a family of functions that perform the same operation but on
10411different data types. Because LLVM can represent over 8 million
10412different integer types, overloading is used commonly to allow an
10413intrinsic function to operate on any integer type. One or more of the
10414argument types or the result type can be overloaded to accept any
10415integer type. Argument types may also be defined as exactly matching a
10416previous argument's type or the result type. This allows an intrinsic
10417function which accepts multiple arguments, but needs all of them to be
10418of the same type, to only be overloaded with respect to a single
10419argument or the result.
10420
10421Overloaded intrinsics will have the names of its overloaded argument
10422types encoded into its function name, each preceded by a period. Only
10423those types which are overloaded result in a name suffix. Arguments
10424whose type is matched against another type do not. For example, the
10425``llvm.ctpop`` function can take an integer of any width and returns an
10426integer of exactly the same integer width. This leads to a family of
10427functions such as ``i8 @llvm.ctpop.i8(i8 %val)`` and
10428``i29 @llvm.ctpop.i29(i29 %val)``. Only one type, the return type, is
10429overloaded, and only one type suffix is required. Because the argument's
10430type is matched against the return type, it does not require its own
10431name suffix.
10432
10433To learn how to add an intrinsic function, please see the `Extending
10434LLVM Guide <ExtendingLLVM.html>`_.
10435
10436.. _int_varargs:
10437
10438Variable Argument Handling Intrinsics
10439-------------------------------------
10440
10441Variable argument support is defined in LLVM with the
10442:ref:`va_arg <i_va_arg>` instruction and these three intrinsic
10443functions. These functions are related to the similarly named macros
10444defined in the ``<stdarg.h>`` header file.
10445
10446All of these functions operate on arguments that use a target-specific
10447value type "``va_list``". The LLVM assembly language reference manual
10448does not define what this type is, so all transformations should be
10449prepared to handle these functions regardless of the type used.
10450
10451This example shows how the :ref:`va_arg <i_va_arg>` instruction and the
10452variable argument handling intrinsic functions are used.
10453
10454.. code-block:: llvm
10455
Tim Northoverab60bb92014-11-02 01:21:51 +000010456 ; This struct is different for every platform. For most platforms,
10457 ; it is merely an i8*.
10458 %struct.va_list = type { i8* }
10459
10460 ; For Unix x86_64 platforms, va_list is the following struct:
10461 ; %struct.va_list = type { i32, i32, i8*, i8* }
10462
Sean Silvab084af42012-12-07 10:36:55 +000010463 define i32 @test(i32 %X, ...) {
10464 ; Initialize variable argument processing
Tim Northoverab60bb92014-11-02 01:21:51 +000010465 %ap = alloca %struct.va_list
10466 %ap2 = bitcast %struct.va_list* %ap to i8*
Sean Silvab084af42012-12-07 10:36:55 +000010467 call void @llvm.va_start(i8* %ap2)
10468
10469 ; Read a single integer argument
Tim Northoverab60bb92014-11-02 01:21:51 +000010470 %tmp = va_arg i8* %ap2, i32
Sean Silvab084af42012-12-07 10:36:55 +000010471
10472 ; Demonstrate usage of llvm.va_copy and llvm.va_end
10473 %aq = alloca i8*
10474 %aq2 = bitcast i8** %aq to i8*
10475 call void @llvm.va_copy(i8* %aq2, i8* %ap2)
10476 call void @llvm.va_end(i8* %aq2)
10477
10478 ; Stop processing of arguments.
10479 call void @llvm.va_end(i8* %ap2)
10480 ret i32 %tmp
10481 }
10482
10483 declare void @llvm.va_start(i8*)
10484 declare void @llvm.va_copy(i8*, i8*)
10485 declare void @llvm.va_end(i8*)
10486
10487.. _int_va_start:
10488
10489'``llvm.va_start``' Intrinsic
10490^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10491
10492Syntax:
10493"""""""
10494
10495::
10496
Nick Lewycky04f6de02013-09-11 22:04:52 +000010497 declare void @llvm.va_start(i8* <arglist>)
Sean Silvab084af42012-12-07 10:36:55 +000010498
10499Overview:
10500"""""""""
10501
10502The '``llvm.va_start``' intrinsic initializes ``*<arglist>`` for
10503subsequent use by ``va_arg``.
10504
10505Arguments:
10506""""""""""
10507
10508The argument is a pointer to a ``va_list`` element to initialize.
10509
10510Semantics:
10511""""""""""
10512
10513The '``llvm.va_start``' intrinsic works just like the ``va_start`` macro
10514available in C. In a target-dependent way, it initializes the
10515``va_list`` element to which the argument points, so that the next call
10516to ``va_arg`` will produce the first variable argument passed to the
10517function. Unlike the C ``va_start`` macro, this intrinsic does not need
10518to know the last argument of the function as the compiler can figure
10519that out.
10520
10521'``llvm.va_end``' Intrinsic
10522^^^^^^^^^^^^^^^^^^^^^^^^^^^
10523
10524Syntax:
10525"""""""
10526
10527::
10528
10529 declare void @llvm.va_end(i8* <arglist>)
10530
10531Overview:
10532"""""""""
10533
10534The '``llvm.va_end``' intrinsic destroys ``*<arglist>``, which has been
10535initialized previously with ``llvm.va_start`` or ``llvm.va_copy``.
10536
10537Arguments:
10538""""""""""
10539
10540The argument is a pointer to a ``va_list`` to destroy.
10541
10542Semantics:
10543""""""""""
10544
10545The '``llvm.va_end``' intrinsic works just like the ``va_end`` macro
10546available in C. In a target-dependent way, it destroys the ``va_list``
10547element to which the argument points. Calls to
10548:ref:`llvm.va_start <int_va_start>` and
10549:ref:`llvm.va_copy <int_va_copy>` must be matched exactly with calls to
10550``llvm.va_end``.
10551
10552.. _int_va_copy:
10553
10554'``llvm.va_copy``' Intrinsic
10555^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10556
10557Syntax:
10558"""""""
10559
10560::
10561
10562 declare void @llvm.va_copy(i8* <destarglist>, i8* <srcarglist>)
10563
10564Overview:
10565"""""""""
10566
10567The '``llvm.va_copy``' intrinsic copies the current argument position
10568from the source argument list to the destination argument list.
10569
10570Arguments:
10571""""""""""
10572
10573The first argument is a pointer to a ``va_list`` element to initialize.
10574The second argument is a pointer to a ``va_list`` element to copy from.
10575
10576Semantics:
10577""""""""""
10578
10579The '``llvm.va_copy``' intrinsic works just like the ``va_copy`` macro
10580available in C. In a target-dependent way, it copies the source
10581``va_list`` element into the destination ``va_list`` element. This
10582intrinsic is necessary because the `` llvm.va_start`` intrinsic may be
10583arbitrarily complex and require, for example, memory allocation.
10584
10585Accurate Garbage Collection Intrinsics
10586--------------------------------------
10587
Philip Reamesc5b0f562015-02-25 23:52:06 +000010588LLVM's support for `Accurate Garbage Collection <GarbageCollection.html>`_
Mehdi Amini4a121fa2015-03-14 22:04:06 +000010589(GC) requires the frontend to generate code containing appropriate intrinsic
10590calls and select an appropriate GC strategy which knows how to lower these
Philip Reamesc5b0f562015-02-25 23:52:06 +000010591intrinsics in a manner which is appropriate for the target collector.
10592
Sean Silvab084af42012-12-07 10:36:55 +000010593These intrinsics allow identification of :ref:`GC roots on the
10594stack <int_gcroot>`, as well as garbage collector implementations that
10595require :ref:`read <int_gcread>` and :ref:`write <int_gcwrite>` barriers.
Philip Reamesc5b0f562015-02-25 23:52:06 +000010596Frontends for type-safe garbage collected languages should generate
Sean Silvab084af42012-12-07 10:36:55 +000010597these intrinsics to make use of the LLVM garbage collectors. For more
Philip Reamesf80bbff2015-02-25 23:45:20 +000010598details, see `Garbage Collection with LLVM <GarbageCollection.html>`_.
Sean Silvab084af42012-12-07 10:36:55 +000010599
Philip Reamesf80bbff2015-02-25 23:45:20 +000010600Experimental Statepoint Intrinsics
10601^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10602
10603LLVM provides an second experimental set of intrinsics for describing garbage
Sean Silvaa1190322015-08-06 22:56:48 +000010604collection safepoints in compiled code. These intrinsics are an alternative
Mehdi Amini4a121fa2015-03-14 22:04:06 +000010605to the ``llvm.gcroot`` intrinsics, but are compatible with the ones for
Sean Silvaa1190322015-08-06 22:56:48 +000010606:ref:`read <int_gcread>` and :ref:`write <int_gcwrite>` barriers. The
Mehdi Amini4a121fa2015-03-14 22:04:06 +000010607differences in approach are covered in the `Garbage Collection with LLVM
Sean Silvaa1190322015-08-06 22:56:48 +000010608<GarbageCollection.html>`_ documentation. The intrinsics themselves are
Philip Reamesf80bbff2015-02-25 23:45:20 +000010609described in :doc:`Statepoints`.
Sean Silvab084af42012-12-07 10:36:55 +000010610
10611.. _int_gcroot:
10612
10613'``llvm.gcroot``' Intrinsic
10614^^^^^^^^^^^^^^^^^^^^^^^^^^^
10615
10616Syntax:
10617"""""""
10618
10619::
10620
10621 declare void @llvm.gcroot(i8** %ptrloc, i8* %metadata)
10622
10623Overview:
10624"""""""""
10625
10626The '``llvm.gcroot``' intrinsic declares the existence of a GC root to
10627the code generator, and allows some metadata to be associated with it.
10628
10629Arguments:
10630""""""""""
10631
10632The first argument specifies the address of a stack object that contains
10633the root pointer. The second pointer (which must be either a constant or
10634a global value address) contains the meta-data to be associated with the
10635root.
10636
10637Semantics:
10638""""""""""
10639
10640At runtime, a call to this intrinsic stores a null pointer into the
10641"ptrloc" location. At compile-time, the code generator generates
10642information to allow the runtime to find the pointer at GC safe points.
10643The '``llvm.gcroot``' intrinsic may only be used in a function which
10644:ref:`specifies a GC algorithm <gc>`.
10645
10646.. _int_gcread:
10647
10648'``llvm.gcread``' Intrinsic
10649^^^^^^^^^^^^^^^^^^^^^^^^^^^
10650
10651Syntax:
10652"""""""
10653
10654::
10655
10656 declare i8* @llvm.gcread(i8* %ObjPtr, i8** %Ptr)
10657
10658Overview:
10659"""""""""
10660
10661The '``llvm.gcread``' intrinsic identifies reads of references from heap
10662locations, allowing garbage collector implementations that require read
10663barriers.
10664
10665Arguments:
10666""""""""""
10667
10668The second argument is the address to read from, which should be an
10669address allocated from the garbage collector. The first object is a
10670pointer to the start of the referenced object, if needed by the language
10671runtime (otherwise null).
10672
10673Semantics:
10674""""""""""
10675
10676The '``llvm.gcread``' intrinsic has the same semantics as a load
10677instruction, but may be replaced with substantially more complex code by
10678the garbage collector runtime, as needed. The '``llvm.gcread``'
10679intrinsic may only be used in a function which :ref:`specifies a GC
10680algorithm <gc>`.
10681
10682.. _int_gcwrite:
10683
10684'``llvm.gcwrite``' Intrinsic
10685^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10686
10687Syntax:
10688"""""""
10689
10690::
10691
10692 declare void @llvm.gcwrite(i8* %P1, i8* %Obj, i8** %P2)
10693
10694Overview:
10695"""""""""
10696
10697The '``llvm.gcwrite``' intrinsic identifies writes of references to heap
10698locations, allowing garbage collector implementations that require write
10699barriers (such as generational or reference counting collectors).
10700
10701Arguments:
10702""""""""""
10703
10704The first argument is the reference to store, the second is the start of
10705the object to store it to, and the third is the address of the field of
10706Obj to store to. If the runtime does not require a pointer to the
10707object, Obj may be null.
10708
10709Semantics:
10710""""""""""
10711
10712The '``llvm.gcwrite``' intrinsic has the same semantics as a store
10713instruction, but may be replaced with substantially more complex code by
10714the garbage collector runtime, as needed. The '``llvm.gcwrite``'
10715intrinsic may only be used in a function which :ref:`specifies a GC
10716algorithm <gc>`.
10717
10718Code Generator Intrinsics
10719-------------------------
10720
10721These intrinsics are provided by LLVM to expose special features that
10722may only be implemented with code generator support.
10723
10724'``llvm.returnaddress``' Intrinsic
10725^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10726
10727Syntax:
10728"""""""
10729
10730::
10731
George Burgess IVfbc34982017-05-20 04:52:29 +000010732 declare i8* @llvm.returnaddress(i32 <level>)
Sean Silvab084af42012-12-07 10:36:55 +000010733
10734Overview:
10735"""""""""
10736
10737The '``llvm.returnaddress``' intrinsic attempts to compute a
10738target-specific value indicating the return address of the current
10739function or one of its callers.
10740
10741Arguments:
10742""""""""""
10743
10744The argument to this intrinsic indicates which function to return the
10745address for. Zero indicates the calling function, one indicates its
10746caller, etc. The argument is **required** to be a constant integer
10747value.
10748
10749Semantics:
10750""""""""""
10751
10752The '``llvm.returnaddress``' intrinsic either returns a pointer
10753indicating the return address of the specified call frame, or zero if it
10754cannot be identified. The value returned by this intrinsic is likely to
10755be incorrect or 0 for arguments other than zero, so it should only be
10756used for debugging purposes.
10757
10758Note that calling this intrinsic does not prevent function inlining or
10759other aggressive transformations, so the value returned may not be that
10760of the obvious source-language caller.
10761
Albert Gutowski795d7d62016-10-12 22:13:19 +000010762'``llvm.addressofreturnaddress``' Intrinsic
Albert Gutowski57ad5fe2016-10-12 23:10:02 +000010763^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Albert Gutowski795d7d62016-10-12 22:13:19 +000010764
10765Syntax:
10766"""""""
10767
10768::
10769
George Burgess IVfbc34982017-05-20 04:52:29 +000010770 declare i8* @llvm.addressofreturnaddress()
Albert Gutowski795d7d62016-10-12 22:13:19 +000010771
10772Overview:
10773"""""""""
10774
10775The '``llvm.addressofreturnaddress``' intrinsic returns a target-specific
10776pointer to the place in the stack frame where the return address of the
10777current function is stored.
10778
10779Semantics:
10780""""""""""
10781
10782Note that calling this intrinsic does not prevent function inlining or
10783other aggressive transformations, so the value returned may not be that
10784of the obvious source-language caller.
10785
Mandeep Singh Grangdf19e572018-11-01 21:23:47 +000010786This intrinsic is only implemented for x86 and aarch64.
Albert Gutowski795d7d62016-10-12 22:13:19 +000010787
Mandeep Singh Grang547a0d72018-11-01 23:22:25 +000010788'``llvm.sponentry``' Intrinsic
10789^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10790
10791Syntax:
10792"""""""
10793
10794::
10795
10796 declare i8* @llvm.sponentry()
10797
10798Overview:
10799"""""""""
10800
10801The '``llvm.sponentry``' intrinsic returns the stack pointer value at
10802the entry of the current function calling this intrinsic.
10803
10804Semantics:
10805""""""""""
10806
10807Note this intrinsic is only verified on AArch64.
10808
Sean Silvab084af42012-12-07 10:36:55 +000010809'``llvm.frameaddress``' Intrinsic
10810^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10811
10812Syntax:
10813"""""""
10814
10815::
10816
10817 declare i8* @llvm.frameaddress(i32 <level>)
10818
10819Overview:
10820"""""""""
10821
10822The '``llvm.frameaddress``' intrinsic attempts to return the
10823target-specific frame pointer value for the specified stack frame.
10824
10825Arguments:
10826""""""""""
10827
10828The argument to this intrinsic indicates which function to return the
10829frame pointer for. Zero indicates the calling function, one indicates
10830its caller, etc. The argument is **required** to be a constant integer
10831value.
10832
10833Semantics:
10834""""""""""
10835
10836The '``llvm.frameaddress``' intrinsic either returns a pointer
10837indicating the frame address of the specified call frame, or zero if it
10838cannot be identified. The value returned by this intrinsic is likely to
10839be incorrect or 0 for arguments other than zero, so it should only be
10840used for debugging purposes.
10841
10842Note that calling this intrinsic does not prevent function inlining or
10843other aggressive transformations, so the value returned may not be that
10844of the obvious source-language caller.
10845
Reid Kleckner60381792015-07-07 22:25:32 +000010846'``llvm.localescape``' and '``llvm.localrecover``' Intrinsics
Reid Klecknere9b89312015-01-13 00:48:10 +000010847^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10848
10849Syntax:
10850"""""""
10851
10852::
10853
Reid Kleckner60381792015-07-07 22:25:32 +000010854 declare void @llvm.localescape(...)
10855 declare i8* @llvm.localrecover(i8* %func, i8* %fp, i32 %idx)
Reid Klecknere9b89312015-01-13 00:48:10 +000010856
10857Overview:
10858"""""""""
10859
Reid Kleckner60381792015-07-07 22:25:32 +000010860The '``llvm.localescape``' intrinsic escapes offsets of a collection of static
10861allocas, and the '``llvm.localrecover``' intrinsic applies those offsets to a
Reid Klecknercfb9ce52015-03-05 18:26:34 +000010862live frame pointer to recover the address of the allocation. The offset is
Reid Kleckner60381792015-07-07 22:25:32 +000010863computed during frame layout of the caller of ``llvm.localescape``.
Reid Klecknere9b89312015-01-13 00:48:10 +000010864
10865Arguments:
10866""""""""""
10867
Reid Kleckner60381792015-07-07 22:25:32 +000010868All arguments to '``llvm.localescape``' must be pointers to static allocas or
10869casts of static allocas. Each function can only call '``llvm.localescape``'
Reid Klecknercfb9ce52015-03-05 18:26:34 +000010870once, and it can only do so from the entry block.
Reid Klecknere9b89312015-01-13 00:48:10 +000010871
Reid Kleckner60381792015-07-07 22:25:32 +000010872The ``func`` argument to '``llvm.localrecover``' must be a constant
Reid Klecknere9b89312015-01-13 00:48:10 +000010873bitcasted pointer to a function defined in the current module. The code
10874generator cannot determine the frame allocation offset of functions defined in
10875other modules.
10876
Reid Klecknerd5afc62f2015-07-07 23:23:03 +000010877The ``fp`` argument to '``llvm.localrecover``' must be a frame pointer of a
10878call frame that is currently live. The return value of '``llvm.localaddress``'
10879is one way to produce such a value, but various runtimes also expose a suitable
10880pointer in platform-specific ways.
Reid Klecknere9b89312015-01-13 00:48:10 +000010881
Reid Kleckner60381792015-07-07 22:25:32 +000010882The ``idx`` argument to '``llvm.localrecover``' indicates which alloca passed to
10883'``llvm.localescape``' to recover. It is zero-indexed.
Reid Klecknercfb9ce52015-03-05 18:26:34 +000010884
Reid Klecknere9b89312015-01-13 00:48:10 +000010885Semantics:
10886""""""""""
10887
Reid Kleckner60381792015-07-07 22:25:32 +000010888These intrinsics allow a group of functions to share access to a set of local
10889stack allocations of a one parent function. The parent function may call the
10890'``llvm.localescape``' intrinsic once from the function entry block, and the
10891child functions can use '``llvm.localrecover``' to access the escaped allocas.
10892The '``llvm.localescape``' intrinsic blocks inlining, as inlining changes where
10893the escaped allocas are allocated, which would break attempts to use
10894'``llvm.localrecover``'.
Reid Klecknere9b89312015-01-13 00:48:10 +000010895
Renato Golinc7aea402014-05-06 16:51:25 +000010896.. _int_read_register:
10897.. _int_write_register:
10898
10899'``llvm.read_register``' and '``llvm.write_register``' Intrinsics
10900^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10901
10902Syntax:
10903"""""""
10904
10905::
10906
10907 declare i32 @llvm.read_register.i32(metadata)
10908 declare i64 @llvm.read_register.i64(metadata)
10909 declare void @llvm.write_register.i32(metadata, i32 @value)
10910 declare void @llvm.write_register.i64(metadata, i64 @value)
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +000010911 !0 = !{!"sp\00"}
Renato Golinc7aea402014-05-06 16:51:25 +000010912
10913Overview:
10914"""""""""
10915
10916The '``llvm.read_register``' and '``llvm.write_register``' intrinsics
10917provides access to the named register. The register must be valid on
10918the architecture being compiled to. The type needs to be compatible
10919with the register being read.
10920
10921Semantics:
10922""""""""""
10923
10924The '``llvm.read_register``' intrinsic returns the current value of the
10925register, where possible. The '``llvm.write_register``' intrinsic sets
10926the current value of the register, where possible.
10927
10928This is useful to implement named register global variables that need
10929to always be mapped to a specific register, as is common practice on
10930bare-metal programs including OS kernels.
10931
10932The compiler doesn't check for register availability or use of the used
10933register in surrounding code, including inline assembly. Because of that,
10934allocatable registers are not supported.
10935
10936Warning: So far it only works with the stack pointer on selected
Tim Northover3b0846e2014-05-24 12:50:23 +000010937architectures (ARM, AArch64, PowerPC and x86_64). Significant amount of
Renato Golinc7aea402014-05-06 16:51:25 +000010938work is needed to support other registers and even more so, allocatable
10939registers.
10940
Sean Silvab084af42012-12-07 10:36:55 +000010941.. _int_stacksave:
10942
10943'``llvm.stacksave``' Intrinsic
10944^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10945
10946Syntax:
10947"""""""
10948
10949::
10950
10951 declare i8* @llvm.stacksave()
10952
10953Overview:
10954"""""""""
10955
10956The '``llvm.stacksave``' intrinsic is used to remember the current state
10957of the function stack, for use with
10958:ref:`llvm.stackrestore <int_stackrestore>`. This is useful for
10959implementing language features like scoped automatic variable sized
10960arrays in C99.
10961
10962Semantics:
10963""""""""""
10964
10965This intrinsic returns a opaque pointer value that can be passed to
10966:ref:`llvm.stackrestore <int_stackrestore>`. When an
10967``llvm.stackrestore`` intrinsic is executed with a value saved from
10968``llvm.stacksave``, it effectively restores the state of the stack to
10969the state it was in when the ``llvm.stacksave`` intrinsic executed. In
10970practice, this pops any :ref:`alloca <i_alloca>` blocks from the stack that
10971were allocated after the ``llvm.stacksave`` was executed.
10972
10973.. _int_stackrestore:
10974
10975'``llvm.stackrestore``' Intrinsic
10976^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10977
10978Syntax:
10979"""""""
10980
10981::
10982
10983 declare void @llvm.stackrestore(i8* %ptr)
10984
10985Overview:
10986"""""""""
10987
10988The '``llvm.stackrestore``' intrinsic is used to restore the state of
10989the function stack to the state it was in when the corresponding
10990:ref:`llvm.stacksave <int_stacksave>` intrinsic executed. This is
10991useful for implementing language features like scoped automatic variable
10992sized arrays in C99.
10993
10994Semantics:
10995""""""""""
10996
10997See the description for :ref:`llvm.stacksave <int_stacksave>`.
10998
Yury Gribovd7dbb662015-12-01 11:40:55 +000010999.. _int_get_dynamic_area_offset:
11000
11001'``llvm.get.dynamic.area.offset``' Intrinsic
Yury Gribov81f3f152015-12-01 13:24:48 +000011002^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Yury Gribovd7dbb662015-12-01 11:40:55 +000011003
11004Syntax:
11005"""""""
11006
11007::
11008
11009 declare i32 @llvm.get.dynamic.area.offset.i32()
11010 declare i64 @llvm.get.dynamic.area.offset.i64()
11011
Lang Hames10239932016-10-08 00:20:42 +000011012Overview:
11013"""""""""
Yury Gribovd7dbb662015-12-01 11:40:55 +000011014
11015 The '``llvm.get.dynamic.area.offset.*``' intrinsic family is used to
11016 get the offset from native stack pointer to the address of the most
11017 recent dynamic alloca on the caller's stack. These intrinsics are
11018 intendend for use in combination with
11019 :ref:`llvm.stacksave <int_stacksave>` to get a
11020 pointer to the most recent dynamic alloca. This is useful, for example,
11021 for AddressSanitizer's stack unpoisoning routines.
11022
11023Semantics:
11024""""""""""
11025
11026 These intrinsics return a non-negative integer value that can be used to
11027 get the address of the most recent dynamic alloca, allocated by :ref:`alloca <i_alloca>`
11028 on the caller's stack. In particular, for targets where stack grows downwards,
11029 adding this offset to the native stack pointer would get the address of the most
11030 recent dynamic alloca. For targets where stack grows upwards, the situation is a bit more
Sylvestre Ledru0455cbe2016-07-28 09:28:58 +000011031 complicated, because subtracting this value from stack pointer would get the address
Yury Gribovd7dbb662015-12-01 11:40:55 +000011032 one past the end of the most recent dynamic alloca.
11033
11034 Although for most targets `llvm.get.dynamic.area.offset <int_get_dynamic_area_offset>`
11035 returns just a zero, for others, such as PowerPC and PowerPC64, it returns a
11036 compile-time-known constant value.
11037
11038 The return value type of :ref:`llvm.get.dynamic.area.offset <int_get_dynamic_area_offset>`
Matt Arsenaultc749bdc2017-03-30 23:36:47 +000011039 must match the target's default address space's (address space 0) pointer type.
Yury Gribovd7dbb662015-12-01 11:40:55 +000011040
Sean Silvab084af42012-12-07 10:36:55 +000011041'``llvm.prefetch``' Intrinsic
11042^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11043
11044Syntax:
11045"""""""
11046
11047::
11048
11049 declare void @llvm.prefetch(i8* <address>, i32 <rw>, i32 <locality>, i32 <cache type>)
11050
11051Overview:
11052"""""""""
11053
11054The '``llvm.prefetch``' intrinsic is a hint to the code generator to
11055insert a prefetch instruction if supported; otherwise, it is a noop.
11056Prefetches have no effect on the behavior of the program but can change
11057its performance characteristics.
11058
11059Arguments:
11060""""""""""
11061
11062``address`` is the address to be prefetched, ``rw`` is the specifier
11063determining if the fetch should be for a read (0) or write (1), and
11064``locality`` is a temporal locality specifier ranging from (0) - no
11065locality, to (3) - extremely local keep in cache. The ``cache type``
11066specifies whether the prefetch is performed on the data (1) or
11067instruction (0) cache. The ``rw``, ``locality`` and ``cache type``
11068arguments must be constant integers.
11069
11070Semantics:
11071""""""""""
11072
11073This intrinsic does not modify the behavior of the program. In
11074particular, prefetches cannot trap and do not produce a value. On
11075targets that support this intrinsic, the prefetch can provide hints to
11076the processor cache for better performance.
11077
11078'``llvm.pcmarker``' Intrinsic
11079^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11080
11081Syntax:
11082"""""""
11083
11084::
11085
11086 declare void @llvm.pcmarker(i32 <id>)
11087
11088Overview:
11089"""""""""
11090
11091The '``llvm.pcmarker``' intrinsic is a method to export a Program
11092Counter (PC) in a region of code to simulators and other tools. The
11093method is target specific, but it is expected that the marker will use
11094exported symbols to transmit the PC of the marker. The marker makes no
11095guarantees that it will remain with any specific instruction after
11096optimizations. It is possible that the presence of a marker will inhibit
11097optimizations. The intended use is to be inserted after optimizations to
11098allow correlations of simulation runs.
11099
11100Arguments:
11101""""""""""
11102
11103``id`` is a numerical id identifying the marker.
11104
11105Semantics:
11106""""""""""
11107
11108This intrinsic does not modify the behavior of the program. Backends
11109that do not support this intrinsic may ignore it.
11110
11111'``llvm.readcyclecounter``' Intrinsic
11112^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11113
11114Syntax:
11115"""""""
11116
11117::
11118
11119 declare i64 @llvm.readcyclecounter()
11120
11121Overview:
11122"""""""""
11123
11124The '``llvm.readcyclecounter``' intrinsic provides access to the cycle
11125counter register (or similar low latency, high accuracy clocks) on those
11126targets that support it. On X86, it should map to RDTSC. On Alpha, it
11127should map to RPCC. As the backing counters overflow quickly (on the
11128order of 9 seconds on alpha), this should only be used for small
11129timings.
11130
11131Semantics:
11132""""""""""
11133
11134When directly supported, reading the cycle counter should not modify any
11135memory. Implementations are allowed to either return a application
11136specific value or a system wide value. On backends without support, this
11137is lowered to a constant 0.
11138
Tim Northoverbc933082013-05-23 19:11:20 +000011139Note that runtime support may be conditional on the privilege-level code is
11140running at and the host platform.
11141
Renato Golinc0a3c1d2014-03-26 12:52:28 +000011142'``llvm.clear_cache``' Intrinsic
11143^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11144
11145Syntax:
11146"""""""
11147
11148::
11149
11150 declare void @llvm.clear_cache(i8*, i8*)
11151
11152Overview:
11153"""""""""
11154
Joerg Sonnenberger03014d62014-03-26 14:35:21 +000011155The '``llvm.clear_cache``' intrinsic ensures visibility of modifications
11156in the specified range to the execution unit of the processor. On
11157targets with non-unified instruction and data cache, the implementation
11158flushes the instruction cache.
Renato Golinc0a3c1d2014-03-26 12:52:28 +000011159
11160Semantics:
11161""""""""""
11162
Joerg Sonnenberger03014d62014-03-26 14:35:21 +000011163On platforms with coherent instruction and data caches (e.g. x86), this
11164intrinsic is a nop. On platforms with non-coherent instruction and data
Alp Toker16f98b22014-04-09 14:47:27 +000011165cache (e.g. ARM, MIPS), the intrinsic is lowered either to appropriate
Joerg Sonnenberger03014d62014-03-26 14:35:21 +000011166instructions or a system call, if cache flushing requires special
11167privileges.
Renato Golinc0a3c1d2014-03-26 12:52:28 +000011168
Sean Silvad02bf3e2014-04-07 22:29:53 +000011169The default behavior is to emit a call to ``__clear_cache`` from the run
Joerg Sonnenberger03014d62014-03-26 14:35:21 +000011170time library.
Renato Golin93010e62014-03-26 14:01:32 +000011171
Joerg Sonnenberger03014d62014-03-26 14:35:21 +000011172This instrinsic does *not* empty the instruction pipeline. Modifications
11173of the current function are outside the scope of the intrinsic.
Renato Golinc0a3c1d2014-03-26 12:52:28 +000011174
Vedant Kumar51ce6682018-01-26 23:54:25 +000011175'``llvm.instrprof.increment``' Intrinsic
Justin Bogner61ba2e32014-12-08 18:02:35 +000011176^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11177
11178Syntax:
11179"""""""
11180
11181::
11182
Vedant Kumar51ce6682018-01-26 23:54:25 +000011183 declare void @llvm.instrprof.increment(i8* <name>, i64 <hash>,
Justin Bogner61ba2e32014-12-08 18:02:35 +000011184 i32 <num-counters>, i32 <index>)
11185
11186Overview:
11187"""""""""
11188
Vedant Kumar51ce6682018-01-26 23:54:25 +000011189The '``llvm.instrprof.increment``' intrinsic can be emitted by a
Justin Bogner61ba2e32014-12-08 18:02:35 +000011190frontend for use with instrumentation based profiling. These will be
11191lowered by the ``-instrprof`` pass to generate execution counts of a
11192program at runtime.
11193
11194Arguments:
11195""""""""""
11196
11197The first argument is a pointer to a global variable containing the
11198name of the entity being instrumented. This should generally be the
11199(mangled) function name for a set of counters.
11200
11201The second argument is a hash value that can be used by the consumer
11202of the profile data to detect changes to the instrumented source, and
11203the third is the number of counters associated with ``name``. It is an
11204error if ``hash`` or ``num-counters`` differ between two instances of
Vedant Kumar51ce6682018-01-26 23:54:25 +000011205``instrprof.increment`` that refer to the same name.
Justin Bogner61ba2e32014-12-08 18:02:35 +000011206
11207The last argument refers to which of the counters for ``name`` should
11208be incremented. It should be a value between 0 and ``num-counters``.
11209
11210Semantics:
11211""""""""""
11212
11213This intrinsic represents an increment of a profiling counter. It will
11214cause the ``-instrprof`` pass to generate the appropriate data
11215structures and the code to increment the appropriate value, in a
11216format that can be written out by a compiler runtime and consumed via
11217the ``llvm-profdata`` tool.
11218
Vedant Kumar51ce6682018-01-26 23:54:25 +000011219'``llvm.instrprof.increment.step``' Intrinsic
Xinliang David Lie1117102016-09-18 22:10:19 +000011220^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Xinliang David Li4ca17332016-09-18 18:34:07 +000011221
11222Syntax:
11223"""""""
11224
11225::
11226
Vedant Kumar51ce6682018-01-26 23:54:25 +000011227 declare void @llvm.instrprof.increment.step(i8* <name>, i64 <hash>,
Xinliang David Li4ca17332016-09-18 18:34:07 +000011228 i32 <num-counters>,
11229 i32 <index>, i64 <step>)
11230
11231Overview:
11232"""""""""
11233
Vedant Kumar51ce6682018-01-26 23:54:25 +000011234The '``llvm.instrprof.increment.step``' intrinsic is an extension to
11235the '``llvm.instrprof.increment``' intrinsic with an additional fifth
Xinliang David Li4ca17332016-09-18 18:34:07 +000011236argument to specify the step of the increment.
11237
11238Arguments:
11239""""""""""
Vedant Kumar51ce6682018-01-26 23:54:25 +000011240The first four arguments are the same as '``llvm.instrprof.increment``'
Pete Couperused9569d2017-08-23 20:58:22 +000011241intrinsic.
Xinliang David Li4ca17332016-09-18 18:34:07 +000011242
11243The last argument specifies the value of the increment of the counter variable.
11244
11245Semantics:
11246""""""""""
Vedant Kumar51ce6682018-01-26 23:54:25 +000011247See description of '``llvm.instrprof.increment``' instrinsic.
Xinliang David Li4ca17332016-09-18 18:34:07 +000011248
11249
Vedant Kumar51ce6682018-01-26 23:54:25 +000011250'``llvm.instrprof.value.profile``' Intrinsic
Betul Buyukkurt6fac1742015-11-18 18:14:55 +000011251^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11252
11253Syntax:
11254"""""""
11255
11256::
11257
Vedant Kumar51ce6682018-01-26 23:54:25 +000011258 declare void @llvm.instrprof.value.profile(i8* <name>, i64 <hash>,
Betul Buyukkurt6fac1742015-11-18 18:14:55 +000011259 i64 <value>, i32 <value_kind>,
11260 i32 <index>)
11261
11262Overview:
11263"""""""""
11264
Vedant Kumar51ce6682018-01-26 23:54:25 +000011265The '``llvm.instrprof.value.profile``' intrinsic can be emitted by a
Betul Buyukkurt6fac1742015-11-18 18:14:55 +000011266frontend for use with instrumentation based profiling. This will be
11267lowered by the ``-instrprof`` pass to find out the target values,
11268instrumented expressions take in a program at runtime.
11269
11270Arguments:
11271""""""""""
11272
11273The first argument is a pointer to a global variable containing the
11274name of the entity being instrumented. ``name`` should generally be the
11275(mangled) function name for a set of counters.
11276
11277The second argument is a hash value that can be used by the consumer
11278of the profile data to detect changes to the instrumented source. It
11279is an error if ``hash`` differs between two instances of
Vedant Kumar51ce6682018-01-26 23:54:25 +000011280``llvm.instrprof.*`` that refer to the same name.
Betul Buyukkurt6fac1742015-11-18 18:14:55 +000011281
11282The third argument is the value of the expression being profiled. The profiled
11283expression's value should be representable as an unsigned 64-bit value. The
11284fourth argument represents the kind of value profiling that is being done. The
11285supported value profiling kinds are enumerated through the
11286``InstrProfValueKind`` type declared in the
11287``<include/llvm/ProfileData/InstrProf.h>`` header file. The last argument is the
11288index of the instrumented expression within ``name``. It should be >= 0.
11289
11290Semantics:
11291""""""""""
11292
11293This intrinsic represents the point where a call to a runtime routine
11294should be inserted for value profiling of target expressions. ``-instrprof``
11295pass will generate the appropriate data structures and replace the
Vedant Kumar51ce6682018-01-26 23:54:25 +000011296``llvm.instrprof.value.profile`` intrinsic with the call to the profile
Betul Buyukkurt6fac1742015-11-18 18:14:55 +000011297runtime library with proper arguments.
11298
Marcin Koscielnicki3fdc2572016-04-19 20:51:05 +000011299'``llvm.thread.pointer``' Intrinsic
11300^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11301
11302Syntax:
11303"""""""
11304
11305::
11306
11307 declare i8* @llvm.thread.pointer()
11308
11309Overview:
11310"""""""""
11311
11312The '``llvm.thread.pointer``' intrinsic returns the value of the thread
11313pointer.
11314
11315Semantics:
11316""""""""""
11317
11318The '``llvm.thread.pointer``' intrinsic returns a pointer to the TLS area
11319for the current thread. The exact semantics of this value are target
11320specific: it may point to the start of TLS area, to the end, or somewhere
11321in the middle. Depending on the target, this intrinsic may read a register,
11322call a helper function, read from an alternate memory space, or perform
11323other operations necessary to locate the TLS area. Not all targets support
11324this intrinsic.
11325
Sean Silvab084af42012-12-07 10:36:55 +000011326Standard C Library Intrinsics
11327-----------------------------
11328
11329LLVM provides intrinsics for a few important standard C library
11330functions. These intrinsics allow source-language front-ends to pass
11331information about the alignment of the pointer arguments to the code
11332generator, providing opportunity for more efficient code generation.
11333
11334.. _int_memcpy:
11335
11336'``llvm.memcpy``' Intrinsic
11337^^^^^^^^^^^^^^^^^^^^^^^^^^^
11338
11339Syntax:
11340"""""""
11341
11342This is an overloaded intrinsic. You can use ``llvm.memcpy`` on any
11343integer bit width and for different address spaces. Not all targets
11344support all bit widths however.
11345
11346::
11347
11348 declare void @llvm.memcpy.p0i8.p0i8.i32(i8* <dest>, i8* <src>,
Daniel Neilson1e687242018-01-19 17:13:12 +000011349 i32 <len>, i1 <isvolatile>)
Sean Silvab084af42012-12-07 10:36:55 +000011350 declare void @llvm.memcpy.p0i8.p0i8.i64(i8* <dest>, i8* <src>,
Daniel Neilson1e687242018-01-19 17:13:12 +000011351 i64 <len>, i1 <isvolatile>)
Sean Silvab084af42012-12-07 10:36:55 +000011352
11353Overview:
11354"""""""""
11355
11356The '``llvm.memcpy.*``' intrinsics copy a block of memory from the
11357source location to the destination location.
11358
11359Note that, unlike the standard libc function, the ``llvm.memcpy.*``
Daniel Neilson1e687242018-01-19 17:13:12 +000011360intrinsics do not return a value, takes extra isvolatile
Sean Silvab084af42012-12-07 10:36:55 +000011361arguments and the pointers can be in specified address spaces.
11362
11363Arguments:
11364""""""""""
11365
11366The first argument is a pointer to the destination, the second is a
11367pointer to the source. The third argument is an integer argument
Daniel Neilson1e687242018-01-19 17:13:12 +000011368specifying the number of bytes to copy, and the fourth is a
Sean Silvab084af42012-12-07 10:36:55 +000011369boolean indicating a volatile access.
11370
Daniel Neilson39eb6a52018-01-19 17:24:21 +000011371The :ref:`align <attr_align>` parameter attribute can be provided
Daniel Neilson1e687242018-01-19 17:13:12 +000011372for the first and second arguments.
Sean Silvab084af42012-12-07 10:36:55 +000011373
11374If the ``isvolatile`` parameter is ``true``, the ``llvm.memcpy`` call is
11375a :ref:`volatile operation <volatile>`. The detailed access behavior is not
11376very cleanly specified and it is unwise to depend on it.
11377
11378Semantics:
11379""""""""""
11380
11381The '``llvm.memcpy.*``' intrinsics copy a block of memory from the
11382source location to the destination location, which are not allowed to
11383overlap. It copies "len" bytes of memory over. If the argument is known
Kristina Brooks76eb4b02019-02-26 18:53:13 +000011384to be aligned to some boundary, this can be specified as an attribute on
11385the argument.
11386
11387If "len" is 0, the pointers may be NULL or dangling. However, they must still
11388be appropriately aligned.
Sean Silvab084af42012-12-07 10:36:55 +000011389
Daniel Neilson57226ef2017-07-12 15:25:26 +000011390.. _int_memmove:
11391
Sean Silvab084af42012-12-07 10:36:55 +000011392'``llvm.memmove``' Intrinsic
11393^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11394
11395Syntax:
11396"""""""
11397
11398This is an overloaded intrinsic. You can use llvm.memmove on any integer
11399bit width and for different address space. Not all targets support all
11400bit widths however.
11401
11402::
11403
11404 declare void @llvm.memmove.p0i8.p0i8.i32(i8* <dest>, i8* <src>,
Daniel Neilson1e687242018-01-19 17:13:12 +000011405 i32 <len>, i1 <isvolatile>)
Sean Silvab084af42012-12-07 10:36:55 +000011406 declare void @llvm.memmove.p0i8.p0i8.i64(i8* <dest>, i8* <src>,
Daniel Neilson1e687242018-01-19 17:13:12 +000011407 i64 <len>, i1 <isvolatile>)
Sean Silvab084af42012-12-07 10:36:55 +000011408
11409Overview:
11410"""""""""
11411
11412The '``llvm.memmove.*``' intrinsics move a block of memory from the
11413source location to the destination location. It is similar to the
11414'``llvm.memcpy``' intrinsic but allows the two memory locations to
11415overlap.
11416
11417Note that, unlike the standard libc function, the ``llvm.memmove.*``
Daniel Neilson1e687242018-01-19 17:13:12 +000011418intrinsics do not return a value, takes an extra isvolatile
11419argument and the pointers can be in specified address spaces.
Sean Silvab084af42012-12-07 10:36:55 +000011420
11421Arguments:
11422""""""""""
11423
11424The first argument is a pointer to the destination, the second is a
11425pointer to the source. The third argument is an integer argument
Daniel Neilson1e687242018-01-19 17:13:12 +000011426specifying the number of bytes to copy, and the fourth is a
Sean Silvab084af42012-12-07 10:36:55 +000011427boolean indicating a volatile access.
11428
Daniel Neilsonaac0f8f2018-01-19 17:32:33 +000011429The :ref:`align <attr_align>` parameter attribute can be provided
Daniel Neilson1e687242018-01-19 17:13:12 +000011430for the first and second arguments.
Sean Silvab084af42012-12-07 10:36:55 +000011431
11432If the ``isvolatile`` parameter is ``true``, the ``llvm.memmove`` call
11433is a :ref:`volatile operation <volatile>`. The detailed access behavior is
11434not very cleanly specified and it is unwise to depend on it.
11435
11436Semantics:
11437""""""""""
11438
11439The '``llvm.memmove.*``' intrinsics copy a block of memory from the
11440source location to the destination location, which may overlap. It
11441copies "len" bytes of memory over. If the argument is known to be
Kristina Brooks76eb4b02019-02-26 18:53:13 +000011442aligned to some boundary, this can be specified as an attribute on
11443the argument.
11444
11445If "len" is 0, the pointers may be NULL or dangling. However, they must still
11446be appropriately aligned.
Sean Silvab084af42012-12-07 10:36:55 +000011447
Daniel Neilson965613e2017-07-12 21:57:23 +000011448.. _int_memset:
11449
Sean Silvab084af42012-12-07 10:36:55 +000011450'``llvm.memset.*``' Intrinsics
11451^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11452
11453Syntax:
11454"""""""
11455
11456This is an overloaded intrinsic. You can use llvm.memset on any integer
11457bit width and for different address spaces. However, not all targets
11458support all bit widths.
11459
11460::
11461
11462 declare void @llvm.memset.p0i8.i32(i8* <dest>, i8 <val>,
Daniel Neilson1e687242018-01-19 17:13:12 +000011463 i32 <len>, i1 <isvolatile>)
Sean Silvab084af42012-12-07 10:36:55 +000011464 declare void @llvm.memset.p0i8.i64(i8* <dest>, i8 <val>,
Daniel Neilson1e687242018-01-19 17:13:12 +000011465 i64 <len>, i1 <isvolatile>)
Sean Silvab084af42012-12-07 10:36:55 +000011466
11467Overview:
11468"""""""""
11469
11470The '``llvm.memset.*``' intrinsics fill a block of memory with a
11471particular byte value.
11472
11473Note that, unlike the standard libc function, the ``llvm.memset``
Daniel Neilson1e687242018-01-19 17:13:12 +000011474intrinsic does not return a value and takes an extra volatile
11475argument. Also, the destination can be in an arbitrary address space.
Sean Silvab084af42012-12-07 10:36:55 +000011476
11477Arguments:
11478""""""""""
11479
11480The first argument is a pointer to the destination to fill, the second
11481is the byte value with which to fill it, the third argument is an
11482integer argument specifying the number of bytes to fill, and the fourth
Daniel Neilson1e687242018-01-19 17:13:12 +000011483is a boolean indicating a volatile access.
Sean Silvab084af42012-12-07 10:36:55 +000011484
Daniel Neilsonaac0f8f2018-01-19 17:32:33 +000011485The :ref:`align <attr_align>` parameter attribute can be provided
Daniel Neilson1e687242018-01-19 17:13:12 +000011486for the first arguments.
Sean Silvab084af42012-12-07 10:36:55 +000011487
11488If the ``isvolatile`` parameter is ``true``, the ``llvm.memset`` call is
11489a :ref:`volatile operation <volatile>`. The detailed access behavior is not
11490very cleanly specified and it is unwise to depend on it.
11491
11492Semantics:
11493""""""""""
11494
11495The '``llvm.memset.*``' intrinsics fill "len" bytes of memory starting
Kristina Brooks76eb4b02019-02-26 18:53:13 +000011496at the destination location. If the argument is known to be
11497aligned to some boundary, this can be specified as an attribute on
11498the argument.
11499
11500If "len" is 0, the pointers may be NULL or dangling. However, they must still
11501be appropriately aligned.
Sean Silvab084af42012-12-07 10:36:55 +000011502
11503'``llvm.sqrt.*``' Intrinsic
11504^^^^^^^^^^^^^^^^^^^^^^^^^^^
11505
11506Syntax:
11507"""""""
11508
11509This is an overloaded intrinsic. You can use ``llvm.sqrt`` on any
Sanjay Patel629c4112017-11-06 16:27:15 +000011510floating-point or vector of floating-point type. Not all targets support
Sean Silvab084af42012-12-07 10:36:55 +000011511all types however.
11512
11513::
11514
11515 declare float @llvm.sqrt.f32(float %Val)
11516 declare double @llvm.sqrt.f64(double %Val)
11517 declare x86_fp80 @llvm.sqrt.f80(x86_fp80 %Val)
11518 declare fp128 @llvm.sqrt.f128(fp128 %Val)
11519 declare ppc_fp128 @llvm.sqrt.ppcf128(ppc_fp128 %Val)
11520
11521Overview:
11522"""""""""
11523
Sanjay Patel629c4112017-11-06 16:27:15 +000011524The '``llvm.sqrt``' intrinsics return the square root of the specified value.
Sean Silvab084af42012-12-07 10:36:55 +000011525
11526Arguments:
11527""""""""""
11528
Sanjay Patel629c4112017-11-06 16:27:15 +000011529The argument and return value are floating-point numbers of the same type.
Sean Silvab084af42012-12-07 10:36:55 +000011530
11531Semantics:
11532""""""""""
11533
Sanjay Patel629c4112017-11-06 16:27:15 +000011534Return the same value as a corresponding libm '``sqrt``' function but without
Elena Demikhovsky945b7e52018-02-14 06:58:08 +000011535trapping or setting ``errno``. For types specified by IEEE-754, the result
Sanjay Patel629c4112017-11-06 16:27:15 +000011536matches a conforming libm implementation.
11537
Elena Demikhovsky945b7e52018-02-14 06:58:08 +000011538When specified with the fast-math-flag 'afn', the result may be approximated
Sanjay Patel629c4112017-11-06 16:27:15 +000011539using a less accurate calculation.
Sean Silvab084af42012-12-07 10:36:55 +000011540
11541'``llvm.powi.*``' Intrinsic
11542^^^^^^^^^^^^^^^^^^^^^^^^^^^
11543
11544Syntax:
11545"""""""
11546
11547This is an overloaded intrinsic. You can use ``llvm.powi`` on any
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000011548floating-point or vector of floating-point type. Not all targets support
Sean Silvab084af42012-12-07 10:36:55 +000011549all types however.
11550
11551::
11552
11553 declare float @llvm.powi.f32(float %Val, i32 %power)
11554 declare double @llvm.powi.f64(double %Val, i32 %power)
11555 declare x86_fp80 @llvm.powi.f80(x86_fp80 %Val, i32 %power)
11556 declare fp128 @llvm.powi.f128(fp128 %Val, i32 %power)
11557 declare ppc_fp128 @llvm.powi.ppcf128(ppc_fp128 %Val, i32 %power)
11558
11559Overview:
11560"""""""""
11561
11562The '``llvm.powi.*``' intrinsics return the first operand raised to the
11563specified (positive or negative) power. The order of evaluation of
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000011564multiplications is not defined. When a vector of floating-point type is
Sean Silvab084af42012-12-07 10:36:55 +000011565used, the second argument remains a scalar integer value.
11566
11567Arguments:
11568""""""""""
11569
11570The second argument is an integer power, and the first is a value to
11571raise to that power.
11572
11573Semantics:
11574""""""""""
11575
11576This function returns the first value raised to the second power with an
11577unspecified sequence of rounding operations.
11578
11579'``llvm.sin.*``' Intrinsic
11580^^^^^^^^^^^^^^^^^^^^^^^^^^
11581
11582Syntax:
11583"""""""
11584
11585This is an overloaded intrinsic. You can use ``llvm.sin`` on any
Sanjay Patel629c4112017-11-06 16:27:15 +000011586floating-point or vector of floating-point type. Not all targets support
Sean Silvab084af42012-12-07 10:36:55 +000011587all types however.
11588
11589::
11590
11591 declare float @llvm.sin.f32(float %Val)
11592 declare double @llvm.sin.f64(double %Val)
11593 declare x86_fp80 @llvm.sin.f80(x86_fp80 %Val)
11594 declare fp128 @llvm.sin.f128(fp128 %Val)
11595 declare ppc_fp128 @llvm.sin.ppcf128(ppc_fp128 %Val)
11596
11597Overview:
11598"""""""""
11599
11600The '``llvm.sin.*``' intrinsics return the sine of the operand.
11601
11602Arguments:
11603""""""""""
11604
Sanjay Patel629c4112017-11-06 16:27:15 +000011605The argument and return value are floating-point numbers of the same type.
Sean Silvab084af42012-12-07 10:36:55 +000011606
11607Semantics:
11608""""""""""
11609
Sanjay Patel629c4112017-11-06 16:27:15 +000011610Return the same value as a corresponding libm '``sin``' function but without
11611trapping or setting ``errno``.
11612
Elena Demikhovsky945b7e52018-02-14 06:58:08 +000011613When specified with the fast-math-flag 'afn', the result may be approximated
Sanjay Patel629c4112017-11-06 16:27:15 +000011614using a less accurate calculation.
Sean Silvab084af42012-12-07 10:36:55 +000011615
11616'``llvm.cos.*``' Intrinsic
11617^^^^^^^^^^^^^^^^^^^^^^^^^^
11618
11619Syntax:
11620"""""""
11621
11622This is an overloaded intrinsic. You can use ``llvm.cos`` on any
Sanjay Patel629c4112017-11-06 16:27:15 +000011623floating-point or vector of floating-point type. Not all targets support
Sean Silvab084af42012-12-07 10:36:55 +000011624all types however.
11625
11626::
11627
11628 declare float @llvm.cos.f32(float %Val)
11629 declare double @llvm.cos.f64(double %Val)
11630 declare x86_fp80 @llvm.cos.f80(x86_fp80 %Val)
11631 declare fp128 @llvm.cos.f128(fp128 %Val)
11632 declare ppc_fp128 @llvm.cos.ppcf128(ppc_fp128 %Val)
11633
11634Overview:
11635"""""""""
11636
11637The '``llvm.cos.*``' intrinsics return the cosine of the operand.
11638
11639Arguments:
11640""""""""""
11641
Sanjay Patel629c4112017-11-06 16:27:15 +000011642The argument and return value are floating-point numbers of the same type.
Sean Silvab084af42012-12-07 10:36:55 +000011643
11644Semantics:
11645""""""""""
11646
Sanjay Patel629c4112017-11-06 16:27:15 +000011647Return the same value as a corresponding libm '``cos``' function but without
11648trapping or setting ``errno``.
11649
Elena Demikhovsky945b7e52018-02-14 06:58:08 +000011650When specified with the fast-math-flag 'afn', the result may be approximated
Sanjay Patel629c4112017-11-06 16:27:15 +000011651using a less accurate calculation.
Sean Silvab084af42012-12-07 10:36:55 +000011652
11653'``llvm.pow.*``' Intrinsic
11654^^^^^^^^^^^^^^^^^^^^^^^^^^
11655
11656Syntax:
11657"""""""
11658
11659This is an overloaded intrinsic. You can use ``llvm.pow`` on any
Sanjay Patel629c4112017-11-06 16:27:15 +000011660floating-point or vector of floating-point type. Not all targets support
Sean Silvab084af42012-12-07 10:36:55 +000011661all types however.
11662
11663::
11664
11665 declare float @llvm.pow.f32(float %Val, float %Power)
11666 declare double @llvm.pow.f64(double %Val, double %Power)
11667 declare x86_fp80 @llvm.pow.f80(x86_fp80 %Val, x86_fp80 %Power)
11668 declare fp128 @llvm.pow.f128(fp128 %Val, fp128 %Power)
11669 declare ppc_fp128 @llvm.pow.ppcf128(ppc_fp128 %Val, ppc_fp128 Power)
11670
11671Overview:
11672"""""""""
11673
11674The '``llvm.pow.*``' intrinsics return the first operand raised to the
11675specified (positive or negative) power.
11676
11677Arguments:
11678""""""""""
11679
Sanjay Patel629c4112017-11-06 16:27:15 +000011680The arguments and return value are floating-point numbers of the same type.
Sean Silvab084af42012-12-07 10:36:55 +000011681
11682Semantics:
11683""""""""""
11684
Sanjay Patel629c4112017-11-06 16:27:15 +000011685Return the same value as a corresponding libm '``pow``' function but without
11686trapping or setting ``errno``.
11687
Elena Demikhovsky945b7e52018-02-14 06:58:08 +000011688When specified with the fast-math-flag 'afn', the result may be approximated
Sanjay Patel629c4112017-11-06 16:27:15 +000011689using a less accurate calculation.
Sean Silvab084af42012-12-07 10:36:55 +000011690
11691'``llvm.exp.*``' Intrinsic
11692^^^^^^^^^^^^^^^^^^^^^^^^^^
11693
11694Syntax:
11695"""""""
11696
11697This is an overloaded intrinsic. You can use ``llvm.exp`` on any
Sanjay Patel629c4112017-11-06 16:27:15 +000011698floating-point or vector of floating-point type. Not all targets support
Sean Silvab084af42012-12-07 10:36:55 +000011699all types however.
11700
11701::
11702
11703 declare float @llvm.exp.f32(float %Val)
11704 declare double @llvm.exp.f64(double %Val)
11705 declare x86_fp80 @llvm.exp.f80(x86_fp80 %Val)
11706 declare fp128 @llvm.exp.f128(fp128 %Val)
11707 declare ppc_fp128 @llvm.exp.ppcf128(ppc_fp128 %Val)
11708
11709Overview:
11710"""""""""
11711
Andrew Kaylorcaf24d22017-04-11 21:52:40 +000011712The '``llvm.exp.*``' intrinsics compute the base-e exponential of the specified
11713value.
Sean Silvab084af42012-12-07 10:36:55 +000011714
11715Arguments:
11716""""""""""
11717
Sanjay Patel629c4112017-11-06 16:27:15 +000011718The argument and return value are floating-point numbers of the same type.
Sean Silvab084af42012-12-07 10:36:55 +000011719
11720Semantics:
11721""""""""""
11722
Sanjay Patel629c4112017-11-06 16:27:15 +000011723Return the same value as a corresponding libm '``exp``' function but without
11724trapping or setting ``errno``.
11725
Elena Demikhovsky945b7e52018-02-14 06:58:08 +000011726When specified with the fast-math-flag 'afn', the result may be approximated
Sanjay Patel629c4112017-11-06 16:27:15 +000011727using a less accurate calculation.
Sean Silvab084af42012-12-07 10:36:55 +000011728
11729'``llvm.exp2.*``' Intrinsic
11730^^^^^^^^^^^^^^^^^^^^^^^^^^^
11731
11732Syntax:
11733"""""""
11734
11735This is an overloaded intrinsic. You can use ``llvm.exp2`` on any
Sanjay Patel629c4112017-11-06 16:27:15 +000011736floating-point or vector of floating-point type. Not all targets support
Sean Silvab084af42012-12-07 10:36:55 +000011737all types however.
11738
11739::
11740
11741 declare float @llvm.exp2.f32(float %Val)
11742 declare double @llvm.exp2.f64(double %Val)
11743 declare x86_fp80 @llvm.exp2.f80(x86_fp80 %Val)
11744 declare fp128 @llvm.exp2.f128(fp128 %Val)
11745 declare ppc_fp128 @llvm.exp2.ppcf128(ppc_fp128 %Val)
11746
11747Overview:
11748"""""""""
11749
Andrew Kaylorcaf24d22017-04-11 21:52:40 +000011750The '``llvm.exp2.*``' intrinsics compute the base-2 exponential of the
11751specified value.
Sean Silvab084af42012-12-07 10:36:55 +000011752
11753Arguments:
11754""""""""""
11755
Sanjay Patel629c4112017-11-06 16:27:15 +000011756The argument and return value are floating-point numbers of the same type.
Sean Silvab084af42012-12-07 10:36:55 +000011757
11758Semantics:
11759""""""""""
11760
Sanjay Patel629c4112017-11-06 16:27:15 +000011761Return the same value as a corresponding libm '``exp2``' function but without
11762trapping or setting ``errno``.
11763
Elena Demikhovsky945b7e52018-02-14 06:58:08 +000011764When specified with the fast-math-flag 'afn', the result may be approximated
Sanjay Patel629c4112017-11-06 16:27:15 +000011765using a less accurate calculation.
Sean Silvab084af42012-12-07 10:36:55 +000011766
11767'``llvm.log.*``' Intrinsic
11768^^^^^^^^^^^^^^^^^^^^^^^^^^
11769
11770Syntax:
11771"""""""
11772
11773This is an overloaded intrinsic. You can use ``llvm.log`` on any
Sanjay Patel629c4112017-11-06 16:27:15 +000011774floating-point or vector of floating-point type. Not all targets support
Sean Silvab084af42012-12-07 10:36:55 +000011775all types however.
11776
11777::
11778
11779 declare float @llvm.log.f32(float %Val)
11780 declare double @llvm.log.f64(double %Val)
11781 declare x86_fp80 @llvm.log.f80(x86_fp80 %Val)
11782 declare fp128 @llvm.log.f128(fp128 %Val)
11783 declare ppc_fp128 @llvm.log.ppcf128(ppc_fp128 %Val)
11784
11785Overview:
11786"""""""""
11787
Andrew Kaylorcaf24d22017-04-11 21:52:40 +000011788The '``llvm.log.*``' intrinsics compute the base-e logarithm of the specified
11789value.
Sean Silvab084af42012-12-07 10:36:55 +000011790
11791Arguments:
11792""""""""""
11793
Sanjay Patel629c4112017-11-06 16:27:15 +000011794The argument and return value are floating-point numbers of the same type.
Sean Silvab084af42012-12-07 10:36:55 +000011795
11796Semantics:
11797""""""""""
11798
Sanjay Patel629c4112017-11-06 16:27:15 +000011799Return the same value as a corresponding libm '``log``' function but without
11800trapping or setting ``errno``.
11801
Elena Demikhovsky945b7e52018-02-14 06:58:08 +000011802When specified with the fast-math-flag 'afn', the result may be approximated
Sanjay Patel629c4112017-11-06 16:27:15 +000011803using a less accurate calculation.
Sean Silvab084af42012-12-07 10:36:55 +000011804
11805'``llvm.log10.*``' Intrinsic
11806^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11807
11808Syntax:
11809"""""""
11810
11811This is an overloaded intrinsic. You can use ``llvm.log10`` on any
Sanjay Patel629c4112017-11-06 16:27:15 +000011812floating-point or vector of floating-point type. Not all targets support
Sean Silvab084af42012-12-07 10:36:55 +000011813all types however.
11814
11815::
11816
11817 declare float @llvm.log10.f32(float %Val)
11818 declare double @llvm.log10.f64(double %Val)
11819 declare x86_fp80 @llvm.log10.f80(x86_fp80 %Val)
11820 declare fp128 @llvm.log10.f128(fp128 %Val)
11821 declare ppc_fp128 @llvm.log10.ppcf128(ppc_fp128 %Val)
11822
11823Overview:
11824"""""""""
11825
Andrew Kaylorcaf24d22017-04-11 21:52:40 +000011826The '``llvm.log10.*``' intrinsics compute the base-10 logarithm of the
11827specified value.
Sean Silvab084af42012-12-07 10:36:55 +000011828
11829Arguments:
11830""""""""""
11831
Sanjay Patel629c4112017-11-06 16:27:15 +000011832The argument and return value are floating-point numbers of the same type.
Sean Silvab084af42012-12-07 10:36:55 +000011833
11834Semantics:
11835""""""""""
11836
Sanjay Patel629c4112017-11-06 16:27:15 +000011837Return the same value as a corresponding libm '``log10``' function but without
11838trapping or setting ``errno``.
11839
Elena Demikhovsky945b7e52018-02-14 06:58:08 +000011840When specified with the fast-math-flag 'afn', the result may be approximated
Sanjay Patel629c4112017-11-06 16:27:15 +000011841using a less accurate calculation.
Sean Silvab084af42012-12-07 10:36:55 +000011842
11843'``llvm.log2.*``' Intrinsic
11844^^^^^^^^^^^^^^^^^^^^^^^^^^^
11845
11846Syntax:
11847"""""""
11848
11849This is an overloaded intrinsic. You can use ``llvm.log2`` on any
Sanjay Patel629c4112017-11-06 16:27:15 +000011850floating-point or vector of floating-point type. Not all targets support
Sean Silvab084af42012-12-07 10:36:55 +000011851all types however.
11852
11853::
11854
11855 declare float @llvm.log2.f32(float %Val)
11856 declare double @llvm.log2.f64(double %Val)
11857 declare x86_fp80 @llvm.log2.f80(x86_fp80 %Val)
11858 declare fp128 @llvm.log2.f128(fp128 %Val)
11859 declare ppc_fp128 @llvm.log2.ppcf128(ppc_fp128 %Val)
11860
11861Overview:
11862"""""""""
11863
Andrew Kaylorcaf24d22017-04-11 21:52:40 +000011864The '``llvm.log2.*``' intrinsics compute the base-2 logarithm of the specified
11865value.
Sean Silvab084af42012-12-07 10:36:55 +000011866
11867Arguments:
11868""""""""""
11869
Sanjay Patel629c4112017-11-06 16:27:15 +000011870The argument and return value are floating-point numbers of the same type.
Sean Silvab084af42012-12-07 10:36:55 +000011871
11872Semantics:
11873""""""""""
11874
Sanjay Patel629c4112017-11-06 16:27:15 +000011875Return the same value as a corresponding libm '``log2``' function but without
11876trapping or setting ``errno``.
11877
Elena Demikhovsky945b7e52018-02-14 06:58:08 +000011878When specified with the fast-math-flag 'afn', the result may be approximated
Sanjay Patel629c4112017-11-06 16:27:15 +000011879using a less accurate calculation.
Sean Silvab084af42012-12-07 10:36:55 +000011880
11881'``llvm.fma.*``' Intrinsic
11882^^^^^^^^^^^^^^^^^^^^^^^^^^
11883
11884Syntax:
11885"""""""
11886
11887This is an overloaded intrinsic. You can use ``llvm.fma`` on any
Sanjay Patel629c4112017-11-06 16:27:15 +000011888floating-point or vector of floating-point type. Not all targets support
Sean Silvab084af42012-12-07 10:36:55 +000011889all types however.
11890
11891::
11892
11893 declare float @llvm.fma.f32(float %a, float %b, float %c)
11894 declare double @llvm.fma.f64(double %a, double %b, double %c)
11895 declare x86_fp80 @llvm.fma.f80(x86_fp80 %a, x86_fp80 %b, x86_fp80 %c)
11896 declare fp128 @llvm.fma.f128(fp128 %a, fp128 %b, fp128 %c)
11897 declare ppc_fp128 @llvm.fma.ppcf128(ppc_fp128 %a, ppc_fp128 %b, ppc_fp128 %c)
11898
11899Overview:
11900"""""""""
11901
Sanjay Patel629c4112017-11-06 16:27:15 +000011902The '``llvm.fma.*``' intrinsics perform the fused multiply-add operation.
Sean Silvab084af42012-12-07 10:36:55 +000011903
11904Arguments:
11905""""""""""
11906
Sanjay Patel629c4112017-11-06 16:27:15 +000011907The arguments and return value are floating-point numbers of the same type.
Sean Silvab084af42012-12-07 10:36:55 +000011908
11909Semantics:
11910""""""""""
11911
Sanjay Patel629c4112017-11-06 16:27:15 +000011912Return the same value as a corresponding libm '``fma``' function but without
11913trapping or setting ``errno``.
11914
Elena Demikhovsky945b7e52018-02-14 06:58:08 +000011915When specified with the fast-math-flag 'afn', the result may be approximated
Sanjay Patel629c4112017-11-06 16:27:15 +000011916using a less accurate calculation.
Sean Silvab084af42012-12-07 10:36:55 +000011917
11918'``llvm.fabs.*``' Intrinsic
11919^^^^^^^^^^^^^^^^^^^^^^^^^^^
11920
11921Syntax:
11922"""""""
11923
11924This is an overloaded intrinsic. You can use ``llvm.fabs`` on any
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000011925floating-point or vector of floating-point type. Not all targets support
Sean Silvab084af42012-12-07 10:36:55 +000011926all types however.
11927
11928::
11929
11930 declare float @llvm.fabs.f32(float %Val)
11931 declare double @llvm.fabs.f64(double %Val)
Matt Arsenaultd6511b42014-10-21 23:00:20 +000011932 declare x86_fp80 @llvm.fabs.f80(x86_fp80 %Val)
Sean Silvab084af42012-12-07 10:36:55 +000011933 declare fp128 @llvm.fabs.f128(fp128 %Val)
Matt Arsenaultd6511b42014-10-21 23:00:20 +000011934 declare ppc_fp128 @llvm.fabs.ppcf128(ppc_fp128 %Val)
Sean Silvab084af42012-12-07 10:36:55 +000011935
11936Overview:
11937"""""""""
11938
11939The '``llvm.fabs.*``' intrinsics return the absolute value of the
11940operand.
11941
11942Arguments:
11943""""""""""
11944
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000011945The argument and return value are floating-point numbers of the same
Sean Silvab084af42012-12-07 10:36:55 +000011946type.
11947
11948Semantics:
11949""""""""""
11950
11951This function returns the same values as the libm ``fabs`` functions
11952would, and handles error conditions in the same way.
11953
Matt Arsenaultd6511b42014-10-21 23:00:20 +000011954'``llvm.minnum.*``' Intrinsic
Matt Arsenault9886b0d2014-10-22 00:15:53 +000011955^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Matt Arsenaultd6511b42014-10-21 23:00:20 +000011956
11957Syntax:
11958"""""""
11959
11960This is an overloaded intrinsic. You can use ``llvm.minnum`` on any
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000011961floating-point or vector of floating-point type. Not all targets support
Matt Arsenaultd6511b42014-10-21 23:00:20 +000011962all types however.
11963
11964::
11965
Matt Arsenault64313c92014-10-22 18:25:02 +000011966 declare float @llvm.minnum.f32(float %Val0, float %Val1)
11967 declare double @llvm.minnum.f64(double %Val0, double %Val1)
11968 declare x86_fp80 @llvm.minnum.f80(x86_fp80 %Val0, x86_fp80 %Val1)
11969 declare fp128 @llvm.minnum.f128(fp128 %Val0, fp128 %Val1)
11970 declare ppc_fp128 @llvm.minnum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1)
Matt Arsenaultd6511b42014-10-21 23:00:20 +000011971
11972Overview:
11973"""""""""
11974
11975The '``llvm.minnum.*``' intrinsics return the minimum of the two
11976arguments.
11977
11978
11979Arguments:
11980""""""""""
11981
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000011982The arguments and return value are floating-point numbers of the same
Matt Arsenaultd6511b42014-10-21 23:00:20 +000011983type.
11984
11985Semantics:
11986""""""""""
11987
Matt Arsenault937003c2018-08-27 17:40:07 +000011988Follows the IEEE-754 semantics for minNum, except for handling of
11989signaling NaNs. This match's the behavior of libm's fmin.
Matt Arsenaultd6511b42014-10-21 23:00:20 +000011990
11991If either operand is a NaN, returns the other non-NaN operand. Returns
Matt Arsenault937003c2018-08-27 17:40:07 +000011992NaN only if both operands are NaN. The returned NaN is always
11993quiet. If the operands compare equal, returns a value that compares
11994equal to both operands. This means that fmin(+/-0.0, +/-0.0) could
11995return either -0.0 or 0.0.
11996
11997Unlike the IEEE-754 2008 behavior, this does not distinguish between
11998signaling and quiet NaN inputs. If a target's implementation follows
11999the standard and returns a quiet NaN if either input is a signaling
12000NaN, the intrinsic lowering is responsible for quieting the inputs to
12001correctly return the non-NaN input (e.g. by using the equivalent of
12002``llvm.canonicalize``).
12003
Matt Arsenaultd6511b42014-10-21 23:00:20 +000012004
12005'``llvm.maxnum.*``' Intrinsic
Matt Arsenault9886b0d2014-10-22 00:15:53 +000012006^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Matt Arsenaultd6511b42014-10-21 23:00:20 +000012007
12008Syntax:
12009"""""""
12010
12011This is an overloaded intrinsic. You can use ``llvm.maxnum`` on any
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000012012floating-point or vector of floating-point type. Not all targets support
Matt Arsenaultd6511b42014-10-21 23:00:20 +000012013all types however.
12014
12015::
12016
Matt Arsenault64313c92014-10-22 18:25:02 +000012017 declare float @llvm.maxnum.f32(float %Val0, float %Val1l)
12018 declare double @llvm.maxnum.f64(double %Val0, double %Val1)
12019 declare x86_fp80 @llvm.maxnum.f80(x86_fp80 %Val0, x86_fp80 %Val1)
12020 declare fp128 @llvm.maxnum.f128(fp128 %Val0, fp128 %Val1)
12021 declare ppc_fp128 @llvm.maxnum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1)
Matt Arsenaultd6511b42014-10-21 23:00:20 +000012022
12023Overview:
12024"""""""""
12025
12026The '``llvm.maxnum.*``' intrinsics return the maximum of the two
12027arguments.
12028
12029
12030Arguments:
12031""""""""""
12032
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000012033The arguments and return value are floating-point numbers of the same
Matt Arsenaultd6511b42014-10-21 23:00:20 +000012034type.
12035
12036Semantics:
12037""""""""""
Matt Arsenault937003c2018-08-27 17:40:07 +000012038Follows the IEEE-754 semantics for maxNum except for the handling of
12039signaling NaNs. This matches the behavior of libm's fmax.
Matt Arsenaultd6511b42014-10-21 23:00:20 +000012040
12041If either operand is a NaN, returns the other non-NaN operand. Returns
Matt Arsenault937003c2018-08-27 17:40:07 +000012042NaN only if both operands are NaN. The returned NaN is always
12043quiet. If the operands compare equal, returns a value that compares
12044equal to both operands. This means that fmax(+/-0.0, +/-0.0) could
12045return either -0.0 or 0.0.
12046
12047Unlike the IEEE-754 2008 behavior, this does not distinguish between
12048signaling and quiet NaN inputs. If a target's implementation follows
12049the standard and returns a quiet NaN if either input is a signaling
12050NaN, the intrinsic lowering is responsible for quieting the inputs to
12051correctly return the non-NaN input (e.g. by using the equivalent of
12052``llvm.canonicalize``).
Matt Arsenaultd6511b42014-10-21 23:00:20 +000012053
Thomas Lively16c349d2018-10-13 07:21:44 +000012054'``llvm.minimum.*``' Intrinsic
12055^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12056
12057Syntax:
12058"""""""
12059
12060This is an overloaded intrinsic. You can use ``llvm.minimum`` on any
12061floating-point or vector of floating-point type. Not all targets support
12062all types however.
12063
12064::
12065
12066 declare float @llvm.minimum.f32(float %Val0, float %Val1)
12067 declare double @llvm.minimum.f64(double %Val0, double %Val1)
12068 declare x86_fp80 @llvm.minimum.f80(x86_fp80 %Val0, x86_fp80 %Val1)
12069 declare fp128 @llvm.minimum.f128(fp128 %Val0, fp128 %Val1)
12070 declare ppc_fp128 @llvm.minimum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1)
12071
12072Overview:
12073"""""""""
12074
12075The '``llvm.minimum.*``' intrinsics return the minimum of the two
12076arguments, propagating NaNs and treating -0.0 as less than +0.0.
12077
12078
12079Arguments:
12080""""""""""
12081
12082The arguments and return value are floating-point numbers of the same
12083type.
12084
12085Semantics:
12086""""""""""
12087If either operand is a NaN, returns NaN. Otherwise returns the lesser
12088of the two arguments. -0.0 is considered to be less than +0.0 for this
12089intrinsic. Note that these are the semantics specified in the draft of
12090IEEE 754-2018.
12091
12092'``llvm.maximum.*``' Intrinsic
12093^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12094
12095Syntax:
12096"""""""
12097
12098This is an overloaded intrinsic. You can use ``llvm.maximum`` on any
12099floating-point or vector of floating-point type. Not all targets support
12100all types however.
12101
12102::
12103
12104 declare float @llvm.maximum.f32(float %Val0, float %Val1)
12105 declare double @llvm.maximum.f64(double %Val0, double %Val1)
12106 declare x86_fp80 @llvm.maximum.f80(x86_fp80 %Val0, x86_fp80 %Val1)
12107 declare fp128 @llvm.maximum.f128(fp128 %Val0, fp128 %Val1)
12108 declare ppc_fp128 @llvm.maximum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1)
12109
12110Overview:
12111"""""""""
12112
12113The '``llvm.maximum.*``' intrinsics return the maximum of the two
12114arguments, propagating NaNs and treating -0.0 as less than +0.0.
12115
12116
12117Arguments:
12118""""""""""
12119
12120The arguments and return value are floating-point numbers of the same
12121type.
12122
12123Semantics:
12124""""""""""
12125If either operand is a NaN, returns NaN. Otherwise returns the greater
12126of the two arguments. -0.0 is considered to be less than +0.0 for this
12127intrinsic. Note that these are the semantics specified in the draft of
12128IEEE 754-2018.
12129
Hal Finkel0c5c01aa2013-08-19 23:35:46 +000012130'``llvm.copysign.*``' Intrinsic
12131^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12132
12133Syntax:
12134"""""""
12135
12136This is an overloaded intrinsic. You can use ``llvm.copysign`` on any
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000012137floating-point or vector of floating-point type. Not all targets support
Hal Finkel0c5c01aa2013-08-19 23:35:46 +000012138all types however.
12139
12140::
12141
12142 declare float @llvm.copysign.f32(float %Mag, float %Sgn)
12143 declare double @llvm.copysign.f64(double %Mag, double %Sgn)
12144 declare x86_fp80 @llvm.copysign.f80(x86_fp80 %Mag, x86_fp80 %Sgn)
12145 declare fp128 @llvm.copysign.f128(fp128 %Mag, fp128 %Sgn)
12146 declare ppc_fp128 @llvm.copysign.ppcf128(ppc_fp128 %Mag, ppc_fp128 %Sgn)
12147
12148Overview:
12149"""""""""
12150
12151The '``llvm.copysign.*``' intrinsics return a value with the magnitude of the
12152first operand and the sign of the second operand.
12153
12154Arguments:
12155""""""""""
12156
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000012157The arguments and return value are floating-point numbers of the same
Hal Finkel0c5c01aa2013-08-19 23:35:46 +000012158type.
12159
12160Semantics:
12161""""""""""
12162
12163This function returns the same values as the libm ``copysign``
12164functions would, and handles error conditions in the same way.
12165
Sean Silvab084af42012-12-07 10:36:55 +000012166'``llvm.floor.*``' Intrinsic
12167^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12168
12169Syntax:
12170"""""""
12171
12172This is an overloaded intrinsic. You can use ``llvm.floor`` on any
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000012173floating-point or vector of floating-point type. Not all targets support
Sean Silvab084af42012-12-07 10:36:55 +000012174all types however.
12175
12176::
12177
12178 declare float @llvm.floor.f32(float %Val)
12179 declare double @llvm.floor.f64(double %Val)
12180 declare x86_fp80 @llvm.floor.f80(x86_fp80 %Val)
12181 declare fp128 @llvm.floor.f128(fp128 %Val)
12182 declare ppc_fp128 @llvm.floor.ppcf128(ppc_fp128 %Val)
12183
12184Overview:
12185"""""""""
12186
12187The '``llvm.floor.*``' intrinsics return the floor of the operand.
12188
12189Arguments:
12190""""""""""
12191
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000012192The argument and return value are floating-point numbers of the same
Sean Silvab084af42012-12-07 10:36:55 +000012193type.
12194
12195Semantics:
12196""""""""""
12197
12198This function returns the same values as the libm ``floor`` functions
12199would, and handles error conditions in the same way.
12200
12201'``llvm.ceil.*``' Intrinsic
12202^^^^^^^^^^^^^^^^^^^^^^^^^^^
12203
12204Syntax:
12205"""""""
12206
12207This is an overloaded intrinsic. You can use ``llvm.ceil`` on any
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000012208floating-point or vector of floating-point type. Not all targets support
Sean Silvab084af42012-12-07 10:36:55 +000012209all types however.
12210
12211::
12212
12213 declare float @llvm.ceil.f32(float %Val)
12214 declare double @llvm.ceil.f64(double %Val)
12215 declare x86_fp80 @llvm.ceil.f80(x86_fp80 %Val)
12216 declare fp128 @llvm.ceil.f128(fp128 %Val)
12217 declare ppc_fp128 @llvm.ceil.ppcf128(ppc_fp128 %Val)
12218
12219Overview:
12220"""""""""
12221
12222The '``llvm.ceil.*``' intrinsics return the ceiling of the operand.
12223
12224Arguments:
12225""""""""""
12226
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000012227The argument and return value are floating-point numbers of the same
Sean Silvab084af42012-12-07 10:36:55 +000012228type.
12229
12230Semantics:
12231""""""""""
12232
12233This function returns the same values as the libm ``ceil`` functions
12234would, and handles error conditions in the same way.
12235
12236'``llvm.trunc.*``' Intrinsic
12237^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12238
12239Syntax:
12240"""""""
12241
12242This is an overloaded intrinsic. You can use ``llvm.trunc`` on any
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000012243floating-point or vector of floating-point type. Not all targets support
Sean Silvab084af42012-12-07 10:36:55 +000012244all types however.
12245
12246::
12247
12248 declare float @llvm.trunc.f32(float %Val)
12249 declare double @llvm.trunc.f64(double %Val)
12250 declare x86_fp80 @llvm.trunc.f80(x86_fp80 %Val)
12251 declare fp128 @llvm.trunc.f128(fp128 %Val)
12252 declare ppc_fp128 @llvm.trunc.ppcf128(ppc_fp128 %Val)
12253
12254Overview:
12255"""""""""
12256
12257The '``llvm.trunc.*``' intrinsics returns the operand rounded to the
12258nearest integer not larger in magnitude than the operand.
12259
12260Arguments:
12261""""""""""
12262
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000012263The argument and return value are floating-point numbers of the same
Sean Silvab084af42012-12-07 10:36:55 +000012264type.
12265
12266Semantics:
12267""""""""""
12268
12269This function returns the same values as the libm ``trunc`` functions
12270would, and handles error conditions in the same way.
12271
12272'``llvm.rint.*``' Intrinsic
12273^^^^^^^^^^^^^^^^^^^^^^^^^^^
12274
12275Syntax:
12276"""""""
12277
12278This is an overloaded intrinsic. You can use ``llvm.rint`` on any
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000012279floating-point or vector of floating-point type. Not all targets support
Sean Silvab084af42012-12-07 10:36:55 +000012280all types however.
12281
12282::
12283
12284 declare float @llvm.rint.f32(float %Val)
12285 declare double @llvm.rint.f64(double %Val)
12286 declare x86_fp80 @llvm.rint.f80(x86_fp80 %Val)
12287 declare fp128 @llvm.rint.f128(fp128 %Val)
12288 declare ppc_fp128 @llvm.rint.ppcf128(ppc_fp128 %Val)
12289
12290Overview:
12291"""""""""
12292
12293The '``llvm.rint.*``' intrinsics returns the operand rounded to the
12294nearest integer. It may raise an inexact floating-point exception if the
12295operand isn't an integer.
12296
12297Arguments:
12298""""""""""
12299
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000012300The argument and return value are floating-point numbers of the same
Sean Silvab084af42012-12-07 10:36:55 +000012301type.
12302
12303Semantics:
12304""""""""""
12305
12306This function returns the same values as the libm ``rint`` functions
12307would, and handles error conditions in the same way.
12308
12309'``llvm.nearbyint.*``' Intrinsic
12310^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12311
12312Syntax:
12313"""""""
12314
12315This is an overloaded intrinsic. You can use ``llvm.nearbyint`` on any
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000012316floating-point or vector of floating-point type. Not all targets support
Sean Silvab084af42012-12-07 10:36:55 +000012317all types however.
12318
12319::
12320
12321 declare float @llvm.nearbyint.f32(float %Val)
12322 declare double @llvm.nearbyint.f64(double %Val)
12323 declare x86_fp80 @llvm.nearbyint.f80(x86_fp80 %Val)
12324 declare fp128 @llvm.nearbyint.f128(fp128 %Val)
12325 declare ppc_fp128 @llvm.nearbyint.ppcf128(ppc_fp128 %Val)
12326
12327Overview:
12328"""""""""
12329
12330The '``llvm.nearbyint.*``' intrinsics returns the operand rounded to the
12331nearest integer.
12332
12333Arguments:
12334""""""""""
12335
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000012336The argument and return value are floating-point numbers of the same
Sean Silvab084af42012-12-07 10:36:55 +000012337type.
12338
12339Semantics:
12340""""""""""
12341
12342This function returns the same values as the libm ``nearbyint``
12343functions would, and handles error conditions in the same way.
12344
Hal Finkel171817e2013-08-07 22:49:12 +000012345'``llvm.round.*``' Intrinsic
12346^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12347
12348Syntax:
12349"""""""
12350
12351This is an overloaded intrinsic. You can use ``llvm.round`` on any
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000012352floating-point or vector of floating-point type. Not all targets support
Hal Finkel171817e2013-08-07 22:49:12 +000012353all types however.
12354
12355::
12356
12357 declare float @llvm.round.f32(float %Val)
12358 declare double @llvm.round.f64(double %Val)
12359 declare x86_fp80 @llvm.round.f80(x86_fp80 %Val)
12360 declare fp128 @llvm.round.f128(fp128 %Val)
12361 declare ppc_fp128 @llvm.round.ppcf128(ppc_fp128 %Val)
12362
12363Overview:
12364"""""""""
12365
12366The '``llvm.round.*``' intrinsics returns the operand rounded to the
12367nearest integer.
12368
12369Arguments:
12370""""""""""
12371
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000012372The argument and return value are floating-point numbers of the same
Hal Finkel171817e2013-08-07 22:49:12 +000012373type.
12374
12375Semantics:
12376""""""""""
12377
12378This function returns the same values as the libm ``round``
12379functions would, and handles error conditions in the same way.
12380
Adhemerval Zanella73643b52019-05-16 13:15:27 +000012381'``llvm.lround.*``' Intrinsic
12382^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12383
12384Syntax:
12385"""""""
12386
12387This is an overloaded intrinsic. You can use ``llvm.lround`` on any
12388floating-point type. Not all targets support all types however.
12389
12390::
12391
12392 declare i32 @llvm.lround.i32.f32(float %Val)
12393 declare i32 @llvm.lround.i32.f64(double %Val)
12394 declare i32 @llvm.lround.i32.f80(float %Val)
12395 declare i32 @llvm.lround.i32.f128(double %Val)
12396 declare i32 @llvm.lround.i32.ppcf128(double %Val)
12397
12398 declare i64 @llvm.lround.i64.f32(float %Val)
12399 declare i64 @llvm.lround.i64.f64(double %Val)
12400 declare i64 @llvm.lround.i64.f80(float %Val)
12401 declare i64 @llvm.lround.i64.f128(double %Val)
12402 declare i64 @llvm.lround.i64.ppcf128(double %Val)
12403
12404Overview:
12405"""""""""
12406
12407The '``llvm.lround.*``' intrinsics returns the operand rounded to the
12408nearest integer.
12409
12410Arguments:
12411""""""""""
12412
Craig Topperaf7a1882019-05-20 16:27:09 +000012413The argument is a floating-point number and return is an integer type.
Adhemerval Zanella73643b52019-05-16 13:15:27 +000012414
12415Semantics:
12416""""""""""
12417
12418This function returns the same values as the libm ``lround``
12419functions would, but without setting errno.
12420
12421'``llvm.llround.*``' Intrinsic
12422^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12423
12424Syntax:
12425"""""""
12426
12427This is an overloaded intrinsic. You can use ``llvm.llround`` on any
12428floating-point type. Not all targets support all types however.
12429
12430::
12431
Craig Topperaf7a1882019-05-20 16:27:09 +000012432 declare i64 @llvm.lround.i64.f32(float %Val)
12433 declare i64 @llvm.lround.i64.f64(double %Val)
12434 declare i64 @llvm.lround.i64.f80(float %Val)
12435 declare i64 @llvm.lround.i64.f128(double %Val)
12436 declare i64 @llvm.lround.i64.ppcf128(double %Val)
Adhemerval Zanella73643b52019-05-16 13:15:27 +000012437
12438Overview:
12439"""""""""
12440
12441The '``llvm.llround.*``' intrinsics returns the operand rounded to the
12442nearest integer.
12443
12444Arguments:
12445""""""""""
12446
Craig Topperaf7a1882019-05-20 16:27:09 +000012447The argument is a floating-point number and return is an integer type.
Adhemerval Zanella73643b52019-05-16 13:15:27 +000012448
12449Semantics:
12450""""""""""
12451
12452This function returns the same values as the libm ``llround``
12453functions would, but without setting errno.
12454
Adhemerval Zanella6d7bf5e2019-05-28 20:47:44 +000012455'``llvm.lrint.*``' Intrinsic
12456^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12457
12458Syntax:
12459"""""""
12460
12461This is an overloaded intrinsic. You can use ``llvm.lrint`` on any
12462floating-point type. Not all targets support all types however.
12463
12464::
12465
12466 declare i32 @llvm.lrint.i32.f32(float %Val)
12467 declare i32 @llvm.lrint.i32.f64(double %Val)
12468 declare i32 @llvm.lrint.i32.f80(float %Val)
12469 declare i32 @llvm.lrint.i32.f128(double %Val)
12470 declare i32 @llvm.lrint.i32.ppcf128(double %Val)
12471
12472 declare i64 @llvm.lrint.i64.f32(float %Val)
12473 declare i64 @llvm.lrint.i64.f64(double %Val)
12474 declare i64 @llvm.lrint.i64.f80(float %Val)
12475 declare i64 @llvm.lrint.i64.f128(double %Val)
12476 declare i64 @llvm.lrint.i64.ppcf128(double %Val)
12477
12478Overview:
12479"""""""""
12480
12481The '``llvm.lrint.*``' intrinsics returns the operand rounded to the
12482nearest integer.
12483
12484Arguments:
12485""""""""""
12486
12487The argument is a floating-point number and return is an integer type.
12488
12489Semantics:
12490""""""""""
12491
12492This function returns the same values as the libm ``lrint``
12493functions would, but without setting errno.
12494
12495'``llvm.llrint.*``' Intrinsic
12496^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12497
12498Syntax:
12499"""""""
12500
12501This is an overloaded intrinsic. You can use ``llvm.llrint`` on any
12502floating-point type. Not all targets support all types however.
12503
12504::
12505
12506 declare i64 @llvm.llrint.i64.f32(float %Val)
12507 declare i64 @llvm.llrint.i64.f64(double %Val)
12508 declare i64 @llvm.llrint.i64.f80(float %Val)
12509 declare i64 @llvm.llrint.i64.f128(double %Val)
12510 declare i64 @llvm.llrint.i64.ppcf128(double %Val)
12511
12512Overview:
12513"""""""""
12514
12515The '``llvm.llrint.*``' intrinsics returns the operand rounded to the
12516nearest integer.
12517
12518Arguments:
12519""""""""""
12520
12521The argument is a floating-point number and return is an integer type.
12522
12523Semantics:
12524""""""""""
12525
12526This function returns the same values as the libm ``llrint``
12527functions would, but without setting errno.
12528
Sean Silvab084af42012-12-07 10:36:55 +000012529Bit Manipulation Intrinsics
12530---------------------------
12531
12532LLVM provides intrinsics for a few important bit manipulation
12533operations. These allow efficient code generation for some algorithms.
12534
James Molloy90111f72015-11-12 12:29:09 +000012535'``llvm.bitreverse.*``' Intrinsics
Akira Hatanaka7f5562b2015-11-13 21:09:57 +000012536^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
James Molloy90111f72015-11-12 12:29:09 +000012537
12538Syntax:
12539"""""""
12540
12541This is an overloaded intrinsic function. You can use bitreverse on any
12542integer type.
12543
12544::
12545
12546 declare i16 @llvm.bitreverse.i16(i16 <id>)
12547 declare i32 @llvm.bitreverse.i32(i32 <id>)
12548 declare i64 @llvm.bitreverse.i64(i64 <id>)
Simon Pilgrimf4268172019-01-28 16:56:38 +000012549 declare <4 x i32> @llvm.bitreverse.v4i32(<4 x i32> <id>)
James Molloy90111f72015-11-12 12:29:09 +000012550
12551Overview:
12552"""""""""
12553
12554The '``llvm.bitreverse``' family of intrinsics is used to reverse the
Simon Pilgrimf4268172019-01-28 16:56:38 +000012555bitpattern of an integer value or vector of integer values; for example
12556``0b10110110`` becomes ``0b01101101``.
James Molloy90111f72015-11-12 12:29:09 +000012557
12558Semantics:
12559""""""""""
12560
Yichao Yu5abf14b2016-11-23 16:25:31 +000012561The ``llvm.bitreverse.iN`` intrinsic returns an iN value that has bit
Simon Pilgrimf4268172019-01-28 16:56:38 +000012562``M`` in the input moved to bit ``N-M`` in the output. The vector
12563intrinsics, such as ``llvm.bitreverse.v4i32``, operate on a per-element
12564basis and the element order is not affected.
James Molloy90111f72015-11-12 12:29:09 +000012565
Sean Silvab084af42012-12-07 10:36:55 +000012566'``llvm.bswap.*``' Intrinsics
12567^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12568
12569Syntax:
12570"""""""
12571
12572This is an overloaded intrinsic function. You can use bswap on any
12573integer type that is an even number of bytes (i.e. BitWidth % 16 == 0).
12574
12575::
12576
12577 declare i16 @llvm.bswap.i16(i16 <id>)
12578 declare i32 @llvm.bswap.i32(i32 <id>)
12579 declare i64 @llvm.bswap.i64(i64 <id>)
Simon Pilgrimf4268172019-01-28 16:56:38 +000012580 declare <4 x i32> @llvm.bswap.v4i32(<4 x i32> <id>)
Sean Silvab084af42012-12-07 10:36:55 +000012581
12582Overview:
12583"""""""""
12584
Simon Pilgrimf4268172019-01-28 16:56:38 +000012585The '``llvm.bswap``' family of intrinsics is used to byte swap an integer
12586value or vector of integer values with an even number of bytes (positive
12587multiple of 16 bits).
Sean Silvab084af42012-12-07 10:36:55 +000012588
12589Semantics:
12590""""""""""
12591
12592The ``llvm.bswap.i16`` intrinsic returns an i16 value that has the high
12593and low byte of the input i16 swapped. Similarly, the ``llvm.bswap.i32``
12594intrinsic returns an i32 value that has the four bytes of the input i32
12595swapped, so that if the input bytes are numbered 0, 1, 2, 3 then the
12596returned i32 will have its bytes in 3, 2, 1, 0 order. The
12597``llvm.bswap.i48``, ``llvm.bswap.i64`` and other intrinsics extend this
12598concept to additional even-byte lengths (6 bytes, 8 bytes and more,
Simon Pilgrimf4268172019-01-28 16:56:38 +000012599respectively). The vector intrinsics, such as ``llvm.bswap.v4i32``,
12600operate on a per-element basis and the element order is not affected.
Sean Silvab084af42012-12-07 10:36:55 +000012601
12602'``llvm.ctpop.*``' Intrinsic
12603^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12604
12605Syntax:
12606"""""""
12607
12608This is an overloaded intrinsic. You can use llvm.ctpop on any integer
12609bit width, or on any vector with integer elements. Not all targets
12610support all bit widths or vector types, however.
12611
12612::
12613
12614 declare i8 @llvm.ctpop.i8(i8 <src>)
12615 declare i16 @llvm.ctpop.i16(i16 <src>)
12616 declare i32 @llvm.ctpop.i32(i32 <src>)
12617 declare i64 @llvm.ctpop.i64(i64 <src>)
12618 declare i256 @llvm.ctpop.i256(i256 <src>)
12619 declare <2 x i32> @llvm.ctpop.v2i32(<2 x i32> <src>)
12620
12621Overview:
12622"""""""""
12623
12624The '``llvm.ctpop``' family of intrinsics counts the number of bits set
12625in a value.
12626
12627Arguments:
12628""""""""""
12629
12630The only argument is the value to be counted. The argument may be of any
12631integer type, or a vector with integer elements. The return type must
12632match the argument type.
12633
12634Semantics:
12635""""""""""
12636
12637The '``llvm.ctpop``' intrinsic counts the 1's in a variable, or within
12638each element of a vector.
12639
12640'``llvm.ctlz.*``' Intrinsic
12641^^^^^^^^^^^^^^^^^^^^^^^^^^^
12642
12643Syntax:
12644"""""""
12645
12646This is an overloaded intrinsic. You can use ``llvm.ctlz`` on any
12647integer bit width, or any vector whose elements are integers. Not all
12648targets support all bit widths or vector types, however.
12649
12650::
12651
12652 declare i8 @llvm.ctlz.i8 (i8 <src>, i1 <is_zero_undef>)
12653 declare i16 @llvm.ctlz.i16 (i16 <src>, i1 <is_zero_undef>)
12654 declare i32 @llvm.ctlz.i32 (i32 <src>, i1 <is_zero_undef>)
12655 declare i64 @llvm.ctlz.i64 (i64 <src>, i1 <is_zero_undef>)
12656 declare i256 @llvm.ctlz.i256(i256 <src>, i1 <is_zero_undef>)
Alexey Samsonovc4b18302016-03-17 23:08:01 +000012657 declare <2 x i32> @llvm.ctlz.v2i32(<2 x i32> <src>, i1 <is_zero_undef>)
Sean Silvab084af42012-12-07 10:36:55 +000012658
12659Overview:
12660"""""""""
12661
12662The '``llvm.ctlz``' family of intrinsic functions counts the number of
12663leading zeros in a variable.
12664
12665Arguments:
12666""""""""""
12667
12668The first argument is the value to be counted. This argument may be of
Hal Finkel5dd82782015-01-05 04:05:21 +000012669any integer type, or a vector with integer element type. The return
Sean Silvab084af42012-12-07 10:36:55 +000012670type must match the first argument type.
12671
12672The second argument must be a constant and is a flag to indicate whether
12673the intrinsic should ensure that a zero as the first argument produces a
12674defined result. Historically some architectures did not provide a
12675defined result for zero values as efficiently, and many algorithms are
12676now predicated on avoiding zero-value inputs.
12677
12678Semantics:
12679""""""""""
12680
12681The '``llvm.ctlz``' intrinsic counts the leading (most significant)
12682zeros in a variable, or within each element of the vector. If
12683``src == 0`` then the result is the size in bits of the type of ``src``
12684if ``is_zero_undef == 0`` and ``undef`` otherwise. For example,
12685``llvm.ctlz(i32 2) = 30``.
12686
12687'``llvm.cttz.*``' Intrinsic
12688^^^^^^^^^^^^^^^^^^^^^^^^^^^
12689
12690Syntax:
12691"""""""
12692
12693This is an overloaded intrinsic. You can use ``llvm.cttz`` on any
12694integer bit width, or any vector of integer elements. Not all targets
12695support all bit widths or vector types, however.
12696
12697::
12698
12699 declare i8 @llvm.cttz.i8 (i8 <src>, i1 <is_zero_undef>)
12700 declare i16 @llvm.cttz.i16 (i16 <src>, i1 <is_zero_undef>)
12701 declare i32 @llvm.cttz.i32 (i32 <src>, i1 <is_zero_undef>)
12702 declare i64 @llvm.cttz.i64 (i64 <src>, i1 <is_zero_undef>)
12703 declare i256 @llvm.cttz.i256(i256 <src>, i1 <is_zero_undef>)
Alexey Samsonovc4b18302016-03-17 23:08:01 +000012704 declare <2 x i32> @llvm.cttz.v2i32(<2 x i32> <src>, i1 <is_zero_undef>)
Sean Silvab084af42012-12-07 10:36:55 +000012705
12706Overview:
12707"""""""""
12708
12709The '``llvm.cttz``' family of intrinsic functions counts the number of
12710trailing zeros.
12711
12712Arguments:
12713""""""""""
12714
12715The first argument is the value to be counted. This argument may be of
Hal Finkel5dd82782015-01-05 04:05:21 +000012716any integer type, or a vector with integer element type. The return
Sean Silvab084af42012-12-07 10:36:55 +000012717type must match the first argument type.
12718
12719The second argument must be a constant and is a flag to indicate whether
12720the intrinsic should ensure that a zero as the first argument produces a
12721defined result. Historically some architectures did not provide a
12722defined result for zero values as efficiently, and many algorithms are
12723now predicated on avoiding zero-value inputs.
12724
12725Semantics:
12726""""""""""
12727
12728The '``llvm.cttz``' intrinsic counts the trailing (least significant)
12729zeros in a variable, or within each element of a vector. If ``src == 0``
12730then the result is the size in bits of the type of ``src`` if
12731``is_zero_undef == 0`` and ``undef`` otherwise. For example,
12732``llvm.cttz(2) = 1``.
12733
Philip Reames34843ae2015-03-05 05:55:55 +000012734.. _int_overflow:
12735
Sanjay Patelc71adc82018-07-16 22:59:31 +000012736'``llvm.fshl.*``' Intrinsic
12737^^^^^^^^^^^^^^^^^^^^^^^^^^^
12738
12739Syntax:
12740"""""""
12741
12742This is an overloaded intrinsic. You can use ``llvm.fshl`` on any
12743integer bit width or any vector of integer elements. Not all targets
12744support all bit widths or vector types, however.
12745
12746::
12747
12748 declare i8 @llvm.fshl.i8 (i8 %a, i8 %b, i8 %c)
12749 declare i67 @llvm.fshl.i67(i67 %a, i67 %b, i67 %c)
12750 declare <2 x i32> @llvm.fshl.v2i32(<2 x i32> %a, <2 x i32> %b, <2 x i32> %c)
12751
12752Overview:
12753"""""""""
12754
12755The '``llvm.fshl``' family of intrinsic functions performs a funnel shift left:
12756the first two values are concatenated as { %a : %b } (%a is the most significant
Mandeep Singh Grang547a0d72018-11-01 23:22:25 +000012757bits of the wide value), the combined value is shifted left, and the most
12758significant bits are extracted to produce a result that is the same size as the
12759original arguments. If the first 2 arguments are identical, this is equivalent
12760to a rotate left operation. For vector types, the operation occurs for each
12761element of the vector. The shift argument is treated as an unsigned amount
Sanjay Patelc71adc82018-07-16 22:59:31 +000012762modulo the element size of the arguments.
12763
12764Arguments:
12765""""""""""
12766
12767The first two arguments are the values to be concatenated. The third
12768argument is the shift amount. The arguments may be any integer type or a
12769vector with integer element type. All arguments and the return value must
12770have the same type.
12771
12772Example:
12773""""""""
12774
12775.. code-block:: text
12776
12777 %r = call i8 @llvm.fshl.i8(i8 %x, i8 %y, i8 %z) ; %r = i8: msb_extract((concat(x, y) << (z % 8)), 8)
12778 %r = call i8 @llvm.fshl.i8(i8 255, i8 0, i8 15) ; %r = i8: 128 (0b10000000)
12779 %r = call i8 @llvm.fshl.i8(i8 15, i8 15, i8 11) ; %r = i8: 120 (0b01111000)
12780 %r = call i8 @llvm.fshl.i8(i8 0, i8 255, i8 8) ; %r = i8: 0 (0b00000000)
12781
12782'``llvm.fshr.*``' Intrinsic
12783^^^^^^^^^^^^^^^^^^^^^^^^^^^
12784
12785Syntax:
12786"""""""
12787
12788This is an overloaded intrinsic. You can use ``llvm.fshr`` on any
12789integer bit width or any vector of integer elements. Not all targets
12790support all bit widths or vector types, however.
12791
12792::
12793
12794 declare i8 @llvm.fshr.i8 (i8 %a, i8 %b, i8 %c)
12795 declare i67 @llvm.fshr.i67(i67 %a, i67 %b, i67 %c)
12796 declare <2 x i32> @llvm.fshr.v2i32(<2 x i32> %a, <2 x i32> %b, <2 x i32> %c)
12797
12798Overview:
12799"""""""""
12800
12801The '``llvm.fshr``' family of intrinsic functions performs a funnel shift right:
12802the first two values are concatenated as { %a : %b } (%a is the most significant
Mandeep Singh Grang547a0d72018-11-01 23:22:25 +000012803bits of the wide value), the combined value is shifted right, and the least
12804significant bits are extracted to produce a result that is the same size as the
12805original arguments. If the first 2 arguments are identical, this is equivalent
12806to a rotate right operation. For vector types, the operation occurs for each
12807element of the vector. The shift argument is treated as an unsigned amount
Sanjay Patelc71adc82018-07-16 22:59:31 +000012808modulo the element size of the arguments.
12809
12810Arguments:
12811""""""""""
12812
12813The first two arguments are the values to be concatenated. The third
12814argument is the shift amount. The arguments may be any integer type or a
12815vector with integer element type. All arguments and the return value must
12816have the same type.
12817
12818Example:
12819""""""""
12820
12821.. code-block:: text
12822
12823 %r = call i8 @llvm.fshr.i8(i8 %x, i8 %y, i8 %z) ; %r = i8: lsb_extract((concat(x, y) >> (z % 8)), 8)
12824 %r = call i8 @llvm.fshr.i8(i8 255, i8 0, i8 15) ; %r = i8: 254 (0b11111110)
12825 %r = call i8 @llvm.fshr.i8(i8 15, i8 15, i8 11) ; %r = i8: 225 (0b11100001)
12826 %r = call i8 @llvm.fshr.i8(i8 0, i8 255, i8 8) ; %r = i8: 255 (0b11111111)
12827
Sean Silvab084af42012-12-07 10:36:55 +000012828Arithmetic with Overflow Intrinsics
12829-----------------------------------
12830
John Regehr6a493f22016-05-12 20:55:09 +000012831LLVM provides intrinsics for fast arithmetic overflow checking.
12832
12833Each of these intrinsics returns a two-element struct. The first
12834element of this struct contains the result of the corresponding
12835arithmetic operation modulo 2\ :sup:`n`\ , where n is the bit width of
12836the result. Therefore, for example, the first element of the struct
12837returned by ``llvm.sadd.with.overflow.i32`` is always the same as the
12838result of a 32-bit ``add`` instruction with the same operands, where
12839the ``add`` is *not* modified by an ``nsw`` or ``nuw`` flag.
12840
12841The second element of the result is an ``i1`` that is 1 if the
12842arithmetic operation overflowed and 0 otherwise. An operation
12843overflows if, for any values of its operands ``A`` and ``B`` and for
12844any ``N`` larger than the operands' width, ``ext(A op B) to iN`` is
12845not equal to ``(ext(A) to iN) op (ext(B) to iN)`` where ``ext`` is
12846``sext`` for signed overflow and ``zext`` for unsigned overflow, and
12847``op`` is the underlying arithmetic operation.
12848
12849The behavior of these intrinsics is well-defined for all argument
12850values.
Sean Silvab084af42012-12-07 10:36:55 +000012851
12852'``llvm.sadd.with.overflow.*``' Intrinsics
12853^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12854
12855Syntax:
12856"""""""
12857
12858This is an overloaded intrinsic. You can use ``llvm.sadd.with.overflow``
Simon Pilgrim7166ab42019-02-25 21:05:09 +000012859on any integer bit width or vectors of integers.
Sean Silvab084af42012-12-07 10:36:55 +000012860
12861::
12862
12863 declare {i16, i1} @llvm.sadd.with.overflow.i16(i16 %a, i16 %b)
12864 declare {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b)
12865 declare {i64, i1} @llvm.sadd.with.overflow.i64(i64 %a, i64 %b)
Simon Pilgrim7166ab42019-02-25 21:05:09 +000012866 declare {<4 x i32>, <4 x i1>} @llvm.sadd.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b)
Sean Silvab084af42012-12-07 10:36:55 +000012867
12868Overview:
12869"""""""""
12870
12871The '``llvm.sadd.with.overflow``' family of intrinsic functions perform
12872a signed addition of the two arguments, and indicate whether an overflow
12873occurred during the signed summation.
12874
12875Arguments:
12876""""""""""
12877
12878The arguments (%a and %b) and the first element of the result structure
12879may be of integer types of any bit width, but they must have the same
12880bit width. The second element of the result structure must be of type
12881``i1``. ``%a`` and ``%b`` are the two values that will undergo signed
12882addition.
12883
12884Semantics:
12885""""""""""
12886
12887The '``llvm.sadd.with.overflow``' family of intrinsic functions perform
Dmitri Gribenkoe8131122013-01-19 20:34:20 +000012888a signed addition of the two variables. They return a structure --- the
Sean Silvab084af42012-12-07 10:36:55 +000012889first element of which is the signed summation, and the second element
12890of which is a bit specifying if the signed summation resulted in an
12891overflow.
12892
12893Examples:
12894"""""""""
12895
12896.. code-block:: llvm
12897
12898 %res = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b)
12899 %sum = extractvalue {i32, i1} %res, 0
12900 %obit = extractvalue {i32, i1} %res, 1
12901 br i1 %obit, label %overflow, label %normal
12902
12903'``llvm.uadd.with.overflow.*``' Intrinsics
12904^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12905
12906Syntax:
12907"""""""
12908
12909This is an overloaded intrinsic. You can use ``llvm.uadd.with.overflow``
Simon Pilgrim7166ab42019-02-25 21:05:09 +000012910on any integer bit width or vectors of integers.
Sean Silvab084af42012-12-07 10:36:55 +000012911
12912::
12913
12914 declare {i16, i1} @llvm.uadd.with.overflow.i16(i16 %a, i16 %b)
12915 declare {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b)
12916 declare {i64, i1} @llvm.uadd.with.overflow.i64(i64 %a, i64 %b)
Simon Pilgrim7166ab42019-02-25 21:05:09 +000012917 declare {<4 x i32>, <4 x i1>} @llvm.uadd.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b)
Sean Silvab084af42012-12-07 10:36:55 +000012918
12919Overview:
12920"""""""""
12921
12922The '``llvm.uadd.with.overflow``' family of intrinsic functions perform
12923an unsigned addition of the two arguments, and indicate whether a carry
12924occurred during the unsigned summation.
12925
12926Arguments:
12927""""""""""
12928
12929The arguments (%a and %b) and the first element of the result structure
12930may be of integer types of any bit width, but they must have the same
12931bit width. The second element of the result structure must be of type
12932``i1``. ``%a`` and ``%b`` are the two values that will undergo unsigned
12933addition.
12934
12935Semantics:
12936""""""""""
12937
12938The '``llvm.uadd.with.overflow``' family of intrinsic functions perform
Dmitri Gribenkoe8131122013-01-19 20:34:20 +000012939an unsigned addition of the two arguments. They return a structure --- the
Sean Silvab084af42012-12-07 10:36:55 +000012940first element of which is the sum, and the second element of which is a
12941bit specifying if the unsigned summation resulted in a carry.
12942
12943Examples:
12944"""""""""
12945
12946.. code-block:: llvm
12947
12948 %res = call {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b)
12949 %sum = extractvalue {i32, i1} %res, 0
12950 %obit = extractvalue {i32, i1} %res, 1
12951 br i1 %obit, label %carry, label %normal
12952
12953'``llvm.ssub.with.overflow.*``' Intrinsics
12954^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12955
12956Syntax:
12957"""""""
12958
12959This is an overloaded intrinsic. You can use ``llvm.ssub.with.overflow``
Simon Pilgrim7166ab42019-02-25 21:05:09 +000012960on any integer bit width or vectors of integers.
Sean Silvab084af42012-12-07 10:36:55 +000012961
12962::
12963
12964 declare {i16, i1} @llvm.ssub.with.overflow.i16(i16 %a, i16 %b)
12965 declare {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a, i32 %b)
12966 declare {i64, i1} @llvm.ssub.with.overflow.i64(i64 %a, i64 %b)
Simon Pilgrim7166ab42019-02-25 21:05:09 +000012967 declare {<4 x i32>, <4 x i1>} @llvm.ssub.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b)
Sean Silvab084af42012-12-07 10:36:55 +000012968
12969Overview:
12970"""""""""
12971
12972The '``llvm.ssub.with.overflow``' family of intrinsic functions perform
12973a signed subtraction of the two arguments, and indicate whether an
12974overflow occurred during the signed subtraction.
12975
12976Arguments:
12977""""""""""
12978
12979The arguments (%a and %b) and the first element of the result structure
12980may be of integer types of any bit width, but they must have the same
12981bit width. The second element of the result structure must be of type
12982``i1``. ``%a`` and ``%b`` are the two values that will undergo signed
12983subtraction.
12984
12985Semantics:
12986""""""""""
12987
12988The '``llvm.ssub.with.overflow``' family of intrinsic functions perform
Dmitri Gribenkoe8131122013-01-19 20:34:20 +000012989a signed subtraction of the two arguments. They return a structure --- the
Sean Silvab084af42012-12-07 10:36:55 +000012990first element of which is the subtraction, and the second element of
12991which is a bit specifying if the signed subtraction resulted in an
12992overflow.
12993
12994Examples:
12995"""""""""
12996
12997.. code-block:: llvm
12998
12999 %res = call {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a, i32 %b)
13000 %sum = extractvalue {i32, i1} %res, 0
13001 %obit = extractvalue {i32, i1} %res, 1
13002 br i1 %obit, label %overflow, label %normal
13003
13004'``llvm.usub.with.overflow.*``' Intrinsics
13005^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13006
13007Syntax:
13008"""""""
13009
13010This is an overloaded intrinsic. You can use ``llvm.usub.with.overflow``
Simon Pilgrim7166ab42019-02-25 21:05:09 +000013011on any integer bit width or vectors of integers.
Sean Silvab084af42012-12-07 10:36:55 +000013012
13013::
13014
13015 declare {i16, i1} @llvm.usub.with.overflow.i16(i16 %a, i16 %b)
13016 declare {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b)
13017 declare {i64, i1} @llvm.usub.with.overflow.i64(i64 %a, i64 %b)
Simon Pilgrim7166ab42019-02-25 21:05:09 +000013018 declare {<4 x i32>, <4 x i1>} @llvm.usub.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b)
Sean Silvab084af42012-12-07 10:36:55 +000013019
13020Overview:
13021"""""""""
13022
13023The '``llvm.usub.with.overflow``' family of intrinsic functions perform
13024an unsigned subtraction of the two arguments, and indicate whether an
13025overflow occurred during the unsigned subtraction.
13026
13027Arguments:
13028""""""""""
13029
13030The arguments (%a and %b) and the first element of the result structure
13031may be of integer types of any bit width, but they must have the same
13032bit width. The second element of the result structure must be of type
13033``i1``. ``%a`` and ``%b`` are the two values that will undergo unsigned
13034subtraction.
13035
13036Semantics:
13037""""""""""
13038
13039The '``llvm.usub.with.overflow``' family of intrinsic functions perform
Dmitri Gribenkoe8131122013-01-19 20:34:20 +000013040an unsigned subtraction of the two arguments. They return a structure ---
Sean Silvab084af42012-12-07 10:36:55 +000013041the first element of which is the subtraction, and the second element of
13042which is a bit specifying if the unsigned subtraction resulted in an
13043overflow.
13044
13045Examples:
13046"""""""""
13047
13048.. code-block:: llvm
13049
13050 %res = call {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b)
13051 %sum = extractvalue {i32, i1} %res, 0
13052 %obit = extractvalue {i32, i1} %res, 1
13053 br i1 %obit, label %overflow, label %normal
13054
13055'``llvm.smul.with.overflow.*``' Intrinsics
13056^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13057
13058Syntax:
13059"""""""
13060
13061This is an overloaded intrinsic. You can use ``llvm.smul.with.overflow``
Simon Pilgrim7166ab42019-02-25 21:05:09 +000013062on any integer bit width or vectors of integers.
Sean Silvab084af42012-12-07 10:36:55 +000013063
13064::
13065
13066 declare {i16, i1} @llvm.smul.with.overflow.i16(i16 %a, i16 %b)
13067 declare {i32, i1} @llvm.smul.with.overflow.i32(i32 %a, i32 %b)
13068 declare {i64, i1} @llvm.smul.with.overflow.i64(i64 %a, i64 %b)
Simon Pilgrim7166ab42019-02-25 21:05:09 +000013069 declare {<4 x i32>, <4 x i1>} @llvm.smul.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b)
Sean Silvab084af42012-12-07 10:36:55 +000013070
13071Overview:
13072"""""""""
13073
13074The '``llvm.smul.with.overflow``' family of intrinsic functions perform
13075a signed multiplication of the two arguments, and indicate whether an
13076overflow occurred during the signed multiplication.
13077
13078Arguments:
13079""""""""""
13080
13081The arguments (%a and %b) and the first element of the result structure
13082may be of integer types of any bit width, but they must have the same
13083bit width. The second element of the result structure must be of type
13084``i1``. ``%a`` and ``%b`` are the two values that will undergo signed
13085multiplication.
13086
13087Semantics:
13088""""""""""
13089
13090The '``llvm.smul.with.overflow``' family of intrinsic functions perform
Dmitri Gribenkoe8131122013-01-19 20:34:20 +000013091a signed multiplication of the two arguments. They return a structure ---
Sean Silvab084af42012-12-07 10:36:55 +000013092the first element of which is the multiplication, and the second element
13093of which is a bit specifying if the signed multiplication resulted in an
13094overflow.
13095
13096Examples:
13097"""""""""
13098
13099.. code-block:: llvm
13100
13101 %res = call {i32, i1} @llvm.smul.with.overflow.i32(i32 %a, i32 %b)
13102 %sum = extractvalue {i32, i1} %res, 0
13103 %obit = extractvalue {i32, i1} %res, 1
13104 br i1 %obit, label %overflow, label %normal
13105
13106'``llvm.umul.with.overflow.*``' Intrinsics
13107^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13108
13109Syntax:
13110"""""""
13111
13112This is an overloaded intrinsic. You can use ``llvm.umul.with.overflow``
Simon Pilgrim7166ab42019-02-25 21:05:09 +000013113on any integer bit width or vectors of integers.
Sean Silvab084af42012-12-07 10:36:55 +000013114
13115::
13116
13117 declare {i16, i1} @llvm.umul.with.overflow.i16(i16 %a, i16 %b)
13118 declare {i32, i1} @llvm.umul.with.overflow.i32(i32 %a, i32 %b)
13119 declare {i64, i1} @llvm.umul.with.overflow.i64(i64 %a, i64 %b)
Simon Pilgrim7166ab42019-02-25 21:05:09 +000013120 declare {<4 x i32>, <4 x i1>} @llvm.umul.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b)
Sean Silvab084af42012-12-07 10:36:55 +000013121
13122Overview:
13123"""""""""
13124
13125The '``llvm.umul.with.overflow``' family of intrinsic functions perform
13126a unsigned multiplication of the two arguments, and indicate whether an
13127overflow occurred during the unsigned multiplication.
13128
13129Arguments:
13130""""""""""
13131
13132The arguments (%a and %b) and the first element of the result structure
13133may be of integer types of any bit width, but they must have the same
13134bit width. The second element of the result structure must be of type
13135``i1``. ``%a`` and ``%b`` are the two values that will undergo unsigned
13136multiplication.
13137
13138Semantics:
13139""""""""""
13140
13141The '``llvm.umul.with.overflow``' family of intrinsic functions perform
Dmitri Gribenkoe8131122013-01-19 20:34:20 +000013142an unsigned multiplication of the two arguments. They return a structure ---
13143the first element of which is the multiplication, and the second
Sean Silvab084af42012-12-07 10:36:55 +000013144element of which is a bit specifying if the unsigned multiplication
13145resulted in an overflow.
13146
13147Examples:
13148"""""""""
13149
13150.. code-block:: llvm
13151
13152 %res = call {i32, i1} @llvm.umul.with.overflow.i32(i32 %a, i32 %b)
13153 %sum = extractvalue {i32, i1} %res, 0
13154 %obit = extractvalue {i32, i1} %res, 1
13155 br i1 %obit, label %overflow, label %normal
13156
Leonard Chan9ede9532018-11-20 18:01:24 +000013157Saturation Arithmetic Intrinsics
13158---------------------------------
13159
13160Saturation arithmetic is a version of arithmetic in which operations are
13161limited to a fixed range between a minimum and maximum value. If the result of
13162an operation is greater than the maximum value, the result is set (or
13163"clamped") to this maximum. If it is below the minimum, it is clamped to this
13164minimum.
13165
13166
13167'``llvm.sadd.sat.*``' Intrinsics
13168^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13169
13170Syntax
13171"""""""
13172
13173This is an overloaded intrinsic. You can use ``llvm.sadd.sat``
13174on any integer bit width or vectors of integers.
13175
13176::
13177
13178 declare i16 @llvm.sadd.sat.i16(i16 %a, i16 %b)
13179 declare i32 @llvm.sadd.sat.i32(i32 %a, i32 %b)
13180 declare i64 @llvm.sadd.sat.i64(i64 %a, i64 %b)
13181 declare <4 x i32> @llvm.sadd.sat.v4i32(<4 x i32> %a, <4 x i32> %b)
13182
13183Overview
13184"""""""""
13185
13186The '``llvm.sadd.sat``' family of intrinsic functions perform signed
13187saturation addition on the 2 arguments.
13188
13189Arguments
13190""""""""""
13191
13192The arguments (%a and %b) and the result may be of integer types of any bit
13193width, but they must have the same bit width. ``%a`` and ``%b`` are the two
13194values that will undergo signed addition.
13195
13196Semantics:
13197""""""""""
13198
13199The maximum value this operation can clamp to is the largest signed value
13200representable by the bit width of the arguments. The minimum value is the
13201smallest signed value representable by this bit width.
13202
13203
13204Examples
13205"""""""""
13206
13207.. code-block:: llvm
13208
13209 %res = call i4 @llvm.sadd.sat.i4(i4 1, i4 2) ; %res = 3
13210 %res = call i4 @llvm.sadd.sat.i4(i4 5, i4 6) ; %res = 7
13211 %res = call i4 @llvm.sadd.sat.i4(i4 -4, i4 2) ; %res = -2
13212 %res = call i4 @llvm.sadd.sat.i4(i4 -4, i4 -5) ; %res = -8
13213
13214
13215'``llvm.uadd.sat.*``' Intrinsics
13216^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13217
13218Syntax
13219"""""""
13220
13221This is an overloaded intrinsic. You can use ``llvm.uadd.sat``
13222on any integer bit width or vectors of integers.
13223
13224::
13225
13226 declare i16 @llvm.uadd.sat.i16(i16 %a, i16 %b)
13227 declare i32 @llvm.uadd.sat.i32(i32 %a, i32 %b)
13228 declare i64 @llvm.uadd.sat.i64(i64 %a, i64 %b)
13229 declare <4 x i32> @llvm.uadd.sat.v4i32(<4 x i32> %a, <4 x i32> %b)
13230
13231Overview
13232"""""""""
13233
13234The '``llvm.uadd.sat``' family of intrinsic functions perform unsigned
13235saturation addition on the 2 arguments.
13236
13237Arguments
13238""""""""""
13239
13240The arguments (%a and %b) and the result may be of integer types of any bit
13241width, but they must have the same bit width. ``%a`` and ``%b`` are the two
13242values that will undergo unsigned addition.
13243
13244Semantics:
13245""""""""""
13246
13247The maximum value this operation can clamp to is the largest unsigned value
13248representable by the bit width of the arguments. Because this is an unsigned
13249operation, the result will never saturate towards zero.
13250
13251
13252Examples
13253"""""""""
13254
13255.. code-block:: llvm
13256
13257 %res = call i4 @llvm.uadd.sat.i4(i4 1, i4 2) ; %res = 3
13258 %res = call i4 @llvm.uadd.sat.i4(i4 5, i4 6) ; %res = 11
13259 %res = call i4 @llvm.uadd.sat.i4(i4 8, i4 8) ; %res = 15
13260
13261
13262'``llvm.ssub.sat.*``' Intrinsics
13263^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13264
13265Syntax
13266"""""""
13267
13268This is an overloaded intrinsic. You can use ``llvm.ssub.sat``
13269on any integer bit width or vectors of integers.
13270
13271::
13272
13273 declare i16 @llvm.ssub.sat.i16(i16 %a, i16 %b)
13274 declare i32 @llvm.ssub.sat.i32(i32 %a, i32 %b)
13275 declare i64 @llvm.ssub.sat.i64(i64 %a, i64 %b)
13276 declare <4 x i32> @llvm.ssub.sat.v4i32(<4 x i32> %a, <4 x i32> %b)
13277
13278Overview
13279"""""""""
13280
13281The '``llvm.ssub.sat``' family of intrinsic functions perform signed
13282saturation subtraction on the 2 arguments.
13283
13284Arguments
13285""""""""""
13286
13287The arguments (%a and %b) and the result may be of integer types of any bit
13288width, but they must have the same bit width. ``%a`` and ``%b`` are the two
13289values that will undergo signed subtraction.
13290
13291Semantics:
13292""""""""""
13293
13294The maximum value this operation can clamp to is the largest signed value
13295representable by the bit width of the arguments. The minimum value is the
13296smallest signed value representable by this bit width.
13297
13298
13299Examples
13300"""""""""
13301
13302.. code-block:: llvm
13303
13304 %res = call i4 @llvm.ssub.sat.i4(i4 2, i4 1) ; %res = 1
13305 %res = call i4 @llvm.ssub.sat.i4(i4 2, i4 6) ; %res = -4
13306 %res = call i4 @llvm.ssub.sat.i4(i4 -4, i4 5) ; %res = -8
13307 %res = call i4 @llvm.ssub.sat.i4(i4 4, i4 -5) ; %res = 7
13308
13309
13310'``llvm.usub.sat.*``' Intrinsics
13311^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13312
13313Syntax
13314"""""""
13315
13316This is an overloaded intrinsic. You can use ``llvm.usub.sat``
13317on any integer bit width or vectors of integers.
13318
13319::
13320
13321 declare i16 @llvm.usub.sat.i16(i16 %a, i16 %b)
13322 declare i32 @llvm.usub.sat.i32(i32 %a, i32 %b)
13323 declare i64 @llvm.usub.sat.i64(i64 %a, i64 %b)
13324 declare <4 x i32> @llvm.usub.sat.v4i32(<4 x i32> %a, <4 x i32> %b)
13325
13326Overview
13327"""""""""
13328
13329The '``llvm.usub.sat``' family of intrinsic functions perform unsigned
13330saturation subtraction on the 2 arguments.
13331
13332Arguments
13333""""""""""
13334
13335The arguments (%a and %b) and the result may be of integer types of any bit
13336width, but they must have the same bit width. ``%a`` and ``%b`` are the two
13337values that will undergo unsigned subtraction.
13338
13339Semantics:
13340""""""""""
13341
13342The minimum value this operation can clamp to is 0, which is the smallest
13343unsigned value representable by the bit width of the unsigned arguments.
13344Because this is an unsigned operation, the result will never saturate towards
13345the largest possible value representable by this bit width.
13346
13347
13348Examples
13349"""""""""
13350
13351.. code-block:: llvm
13352
13353 %res = call i4 @llvm.usub.sat.i4(i4 2, i4 1) ; %res = 1
13354 %res = call i4 @llvm.usub.sat.i4(i4 2, i4 6) ; %res = 0
13355
13356
Leonard Chan118e53f2018-12-12 06:29:14 +000013357Fixed Point Arithmetic Intrinsics
13358---------------------------------
13359
13360A fixed point number represents a real data type for a number that has a fixed
13361number of digits after a radix point (equivalent to the decimal point '.').
13362The number of digits after the radix point is referred as the ``scale``. These
13363are useful for representing fractional values to a specific precision. The
13364following intrinsics perform fixed point arithmetic operations on 2 operands
13365of the same scale, specified as the third argument.
13366
Leonard Chan0bada7c2019-05-21 19:17:19 +000013367The `llvm.*mul.fix` family of intrinsic functions represents a multiplication
13368of fixed point numbers through scaled integers. Therefore, fixed point
13369multplication can be represented as
13370
13371::
13372 %result = call i4 @llvm.smul.fix.i4(i4 %a, i4 %b, i32 %scale)
Leonard Chan9bb96982019-05-21 19:30:25 +000013373
13374 ; Expands to
Leonard Chan0bada7c2019-05-21 19:17:19 +000013375 %a2 = sext i4 %a to i8
13376 %b2 = sext i4 %b to i8
13377 %mul = mul nsw nuw i8 %a, %b
13378 %scale2 = trunc i32 %scale to i8
13379 %r = ashr i8 %mul, i8 %scale2 ; this is for a target rounding down towards negative infinity
13380 %result = trunc i8 %r to i4
13381
13382For each of these functions, if the result cannot be represented exactly with
13383the provided scale, the result is rounded. Rounding is unspecified since
13384preferred rounding may vary for different targets. Rounding is specified
13385through a target hook. Different pipelines should legalize or optimize this
13386using the rounding specified by this hook if it is provided. Operations like
13387constant folding, instruction combining, KnownBits, and ValueTracking should
13388also use this hook, if provided, and not assume the direction of rounding. A
13389rounded result must always be within one unit of precision from the true
13390result. That is, the error between the returned result and the true result must
13391be less than 1/2^(scale).
13392
Leonard Chan118e53f2018-12-12 06:29:14 +000013393
13394'``llvm.smul.fix.*``' Intrinsics
13395^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13396
13397Syntax
13398"""""""
13399
13400This is an overloaded intrinsic. You can use ``llvm.smul.fix``
13401on any integer bit width or vectors of integers.
13402
13403::
13404
13405 declare i16 @llvm.smul.fix.i16(i16 %a, i16 %b, i32 %scale)
13406 declare i32 @llvm.smul.fix.i32(i32 %a, i32 %b, i32 %scale)
13407 declare i64 @llvm.smul.fix.i64(i64 %a, i64 %b, i32 %scale)
13408 declare <4 x i32> @llvm.smul.fix.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale)
13409
13410Overview
13411"""""""""
13412
13413The '``llvm.smul.fix``' family of intrinsic functions perform signed
13414fixed point multiplication on 2 arguments of the same scale.
13415
13416Arguments
13417""""""""""
13418
13419The arguments (%a and %b) and the result may be of integer types of any bit
Leonard Chan68d428e2019-02-04 17:18:11 +000013420width, but they must have the same bit width. The arguments may also work with
13421int vectors of the same length and int size. ``%a`` and ``%b`` are the two
Leonard Chan118e53f2018-12-12 06:29:14 +000013422values that will undergo signed fixed point multiplication. The argument
13423``%scale`` represents the scale of both operands, and must be a constant
13424integer.
13425
13426Semantics:
13427""""""""""
13428
13429This operation performs fixed point multiplication on the 2 arguments of a
13430specified scale. The result will also be returned in the same scale specified
13431in the third argument.
13432
13433If the result value cannot be precisely represented in the given scale, the
13434value is rounded up or down to the closest representable value. The rounding
13435direction is unspecified.
13436
Leonard Chan68d428e2019-02-04 17:18:11 +000013437It is undefined behavior if the result value does not fit within the range of
Leonard Chan118e53f2018-12-12 06:29:14 +000013438the fixed point type.
13439
13440
13441Examples
13442"""""""""
13443
13444.. code-block:: llvm
13445
13446 %res = call i4 @llvm.smul.fix.i4(i4 3, i4 2, i32 0) ; %res = 6 (2 x 3 = 6)
13447 %res = call i4 @llvm.smul.fix.i4(i4 3, i4 2, i32 1) ; %res = 3 (1.5 x 1 = 1.5)
13448 %res = call i4 @llvm.smul.fix.i4(i4 3, i4 -2, i32 1) ; %res = -3 (1.5 x -1 = -1.5)
13449
13450 ; The result in the following could be rounded up to -2 or down to -2.5
13451 %res = call i4 @llvm.smul.fix.i4(i4 3, i4 -3, i32 1) ; %res = -5 (or -4) (1.5 x -1.5 = -2.25)
13452
13453
Leonard Chan68d428e2019-02-04 17:18:11 +000013454'``llvm.umul.fix.*``' Intrinsics
13455^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13456
13457Syntax
13458"""""""
13459
13460This is an overloaded intrinsic. You can use ``llvm.umul.fix``
13461on any integer bit width or vectors of integers.
13462
13463::
13464
13465 declare i16 @llvm.umul.fix.i16(i16 %a, i16 %b, i32 %scale)
13466 declare i32 @llvm.umul.fix.i32(i32 %a, i32 %b, i32 %scale)
13467 declare i64 @llvm.umul.fix.i64(i64 %a, i64 %b, i32 %scale)
13468 declare <4 x i32> @llvm.umul.fix.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale)
13469
13470Overview
13471"""""""""
13472
13473The '``llvm.umul.fix``' family of intrinsic functions perform unsigned
13474fixed point multiplication on 2 arguments of the same scale.
13475
13476Arguments
13477""""""""""
13478
13479The arguments (%a and %b) and the result may be of integer types of any bit
13480width, but they must have the same bit width. The arguments may also work with
13481int vectors of the same length and int size. ``%a`` and ``%b`` are the two
13482values that will undergo unsigned fixed point multiplication. The argument
13483``%scale`` represents the scale of both operands, and must be a constant
13484integer.
13485
13486Semantics:
13487""""""""""
13488
13489This operation performs unsigned fixed point multiplication on the 2 arguments of a
13490specified scale. The result will also be returned in the same scale specified
13491in the third argument.
13492
13493If the result value cannot be precisely represented in the given scale, the
13494value is rounded up or down to the closest representable value. The rounding
13495direction is unspecified.
13496
13497It is undefined behavior if the result value does not fit within the range of
13498the fixed point type.
13499
13500
13501Examples
13502"""""""""
13503
13504.. code-block:: llvm
13505
13506 %res = call i4 @llvm.umul.fix.i4(i4 3, i4 2, i32 0) ; %res = 6 (2 x 3 = 6)
13507 %res = call i4 @llvm.umul.fix.i4(i4 3, i4 2, i32 1) ; %res = 3 (1.5 x 1 = 1.5)
13508
13509 ; The result in the following could be rounded down to 3.5 or up to 4
13510 %res = call i4 @llvm.umul.fix.i4(i4 15, i4 1, i32 1) ; %res = 7 (or 8) (7.5 x 0.5 = 3.75)
13511
13512
Leonard Chan0bada7c2019-05-21 19:17:19 +000013513'``llvm.smul.fix.sat.*``' Intrinsics
13514^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13515
13516Syntax
13517"""""""
13518
13519This is an overloaded intrinsic. You can use ``llvm.smul.fix.sat``
13520on any integer bit width or vectors of integers.
13521
13522::
13523
13524 declare i16 @llvm.smul.fix.sat.i16(i16 %a, i16 %b, i32 %scale)
13525 declare i32 @llvm.smul.fix.sat.i32(i32 %a, i32 %b, i32 %scale)
13526 declare i64 @llvm.smul.fix.sat.i64(i64 %a, i64 %b, i32 %scale)
13527 declare <4 x i32> @llvm.smul.fix.sat.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale)
13528
13529Overview
13530"""""""""
13531
13532The '``llvm.smul.fix.sat``' family of intrinsic functions perform signed
13533fixed point saturation multiplication on 2 arguments of the same scale.
13534
13535Arguments
13536""""""""""
13537
13538The arguments (%a and %b) and the result may be of integer types of any bit
13539width, but they must have the same bit width. ``%a`` and ``%b`` are the two
13540values that will undergo signed fixed point multiplication. The argument
13541``%scale`` represents the scale of both operands, and must be a constant
13542integer.
13543
13544Semantics:
13545""""""""""
13546
13547This operation performs fixed point multiplication on the 2 arguments of a
13548specified scale. The result will also be returned in the same scale specified
13549in the third argument.
13550
13551If the result value cannot be precisely represented in the given scale, the
13552value is rounded up or down to the closest representable value. The rounding
13553direction is unspecified.
13554
13555The maximum value this operation can clamp to is the largest signed value
13556representable by the bit width of the first 2 arguments. The minimum value is the
13557smallest signed value representable by this bit width.
13558
13559
13560Examples
13561"""""""""
13562
13563.. code-block:: llvm
13564
13565 %res = call i4 @llvm.smul.fix.sat.i4(i4 3, i4 2, i32 0) ; %res = 6 (2 x 3 = 6)
13566 %res = call i4 @llvm.smul.fix.sat.i4(i4 3, i4 2, i32 1) ; %res = 3 (1.5 x 1 = 1.5)
13567 %res = call i4 @llvm.smul.fix.sat.i4(i4 3, i4 -2, i32 1) ; %res = -3 (1.5 x -1 = -1.5)
13568
13569 ; The result in the following could be rounded up to -2 or down to -2.5
13570 %res = call i4 @llvm.smul.fix.sat.i4(i4 3, i4 -3, i32 1) ; %res = -5 (or -4) (1.5 x -1.5 = -2.25)
13571
13572 ; Saturation
13573 %res = call i4 @llvm.smul.fix.sat.i4(i4 7, i4 2, i32 0) ; %res = 7
13574 %res = call i4 @llvm.smul.fix.sat.i4(i4 7, i4 2, i32 2) ; %res = 7
13575 %res = call i4 @llvm.smul.fix.sat.i4(i4 -8, i4 2, i32 2) ; %res = -8
13576 %res = call i4 @llvm.smul.fix.sat.i4(i4 -8, i4 -2, i32 2) ; %res = 7
13577
13578 ; Scale can affect the saturation result
13579 %res = call i4 @llvm.smul.fix.sat.i4(i4 2, i4 4, i32 0) ; %res = 7 (2 x 4 -> clamped to 7)
13580 %res = call i4 @llvm.smul.fix.sat.i4(i4 2, i4 4, i32 1) ; %res = 4 (1 x 2 = 2)
13581
13582
Sean Silvab084af42012-12-07 10:36:55 +000013583Specialised Arithmetic Intrinsics
13584---------------------------------
13585
Owen Anderson1056a922015-07-11 07:01:27 +000013586'``llvm.canonicalize.*``' Intrinsic
13587^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13588
13589Syntax:
13590"""""""
13591
13592::
13593
13594 declare float @llvm.canonicalize.f32(float %a)
13595 declare double @llvm.canonicalize.f64(double %b)
13596
13597Overview:
13598"""""""""
13599
13600The '``llvm.canonicalize.*``' intrinsic returns the platform specific canonical
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000013601encoding of a floating-point number. This canonicalization is useful for
Owen Anderson1056a922015-07-11 07:01:27 +000013602implementing certain numeric primitives such as frexp. The canonical encoding is
13603defined by IEEE-754-2008 to be:
13604
13605::
13606
13607 2.1.8 canonical encoding: The preferred encoding of a floating-point
Sean Silvaa1190322015-08-06 22:56:48 +000013608 representation in a format. Applied to declets, significands of finite
Owen Anderson1056a922015-07-11 07:01:27 +000013609 numbers, infinities, and NaNs, especially in decimal formats.
13610
13611This operation can also be considered equivalent to the IEEE-754-2008
Sean Silvaa1190322015-08-06 22:56:48 +000013612conversion of a floating-point value to the same format. NaNs are handled
Owen Anderson1056a922015-07-11 07:01:27 +000013613according to section 6.2.
13614
13615Examples of non-canonical encodings:
13616
Sean Silvaa1190322015-08-06 22:56:48 +000013617- x87 pseudo denormals, pseudo NaNs, pseudo Infinity, Unnormals. These are
Owen Anderson1056a922015-07-11 07:01:27 +000013618 converted to a canonical representation per hardware-specific protocol.
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000013619- Many normal decimal floating-point numbers have non-canonical alternative
Owen Anderson1056a922015-07-11 07:01:27 +000013620 encodings.
13621- Some machines, like GPUs or ARMv7 NEON, do not support subnormal values.
Sanjay Patelcc330962016-02-24 23:44:19 +000013622 These are treated as non-canonical encodings of zero and will be flushed to
Owen Anderson1056a922015-07-11 07:01:27 +000013623 a zero of the same sign by this operation.
13624
13625Note that per IEEE-754-2008 6.2, systems that support signaling NaNs with
13626default exception handling must signal an invalid exception, and produce a
13627quiet NaN result.
13628
13629This function should always be implementable as multiplication by 1.0, provided
Sean Silvaa1190322015-08-06 22:56:48 +000013630that the compiler does not constant fold the operation. Likewise, division by
136311.0 and ``llvm.minnum(x, x)`` are possible implementations. Addition with
Owen Anderson1056a922015-07-11 07:01:27 +000013632-0.0 is also sufficient provided that the rounding mode is not -Infinity.
13633
Sean Silvaa1190322015-08-06 22:56:48 +000013634``@llvm.canonicalize`` must preserve the equality relation. That is:
Owen Anderson1056a922015-07-11 07:01:27 +000013635
13636- ``(@llvm.canonicalize(x) == x)`` is equivalent to ``(x == x)``
13637- ``(@llvm.canonicalize(x) == @llvm.canonicalize(y))`` is equivalent to
13638 to ``(x == y)``
13639
13640Additionally, the sign of zero must be conserved:
13641``@llvm.canonicalize(-0.0) = -0.0`` and ``@llvm.canonicalize(+0.0) = +0.0``
13642
13643The payload bits of a NaN must be conserved, with two exceptions.
13644First, environments which use only a single canonical representation of NaN
Sean Silvaa1190322015-08-06 22:56:48 +000013645must perform said canonicalization. Second, SNaNs must be quieted per the
Owen Anderson1056a922015-07-11 07:01:27 +000013646usual methods.
13647
13648The canonicalization operation may be optimized away if:
13649
Sean Silvaa1190322015-08-06 22:56:48 +000013650- The input is known to be canonical. For example, it was produced by a
Owen Anderson1056a922015-07-11 07:01:27 +000013651 floating-point operation that is required by the standard to be canonical.
13652- The result is consumed only by (or fused with) other floating-point
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000013653 operations. That is, the bits of the floating-point value are not examined.
Owen Anderson1056a922015-07-11 07:01:27 +000013654
Sean Silvab084af42012-12-07 10:36:55 +000013655'``llvm.fmuladd.*``' Intrinsic
13656^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13657
13658Syntax:
13659"""""""
13660
13661::
13662
13663 declare float @llvm.fmuladd.f32(float %a, float %b, float %c)
13664 declare double @llvm.fmuladd.f64(double %a, double %b, double %c)
13665
13666Overview:
13667"""""""""
13668
13669The '``llvm.fmuladd.*``' intrinsic functions represent multiply-add
Lang Hames045f4392013-01-17 00:00:49 +000013670expressions that can be fused if the code generator determines that (a) the
13671target instruction set has support for a fused operation, and (b) that the
13672fused operation is more efficient than the equivalent, separate pair of mul
13673and add instructions.
Sean Silvab084af42012-12-07 10:36:55 +000013674
13675Arguments:
13676""""""""""
13677
13678The '``llvm.fmuladd.*``' intrinsics each take three arguments: two
13679multiplicands, a and b, and an addend c.
13680
13681Semantics:
13682""""""""""
13683
13684The expression:
13685
13686::
13687
13688 %0 = call float @llvm.fmuladd.f32(%a, %b, %c)
13689
13690is equivalent to the expression a \* b + c, except that rounding will
13691not be performed between the multiplication and addition steps if the
13692code generator fuses the operations. Fusion is not guaranteed, even if
13693the target platform supports it. If a fused multiply-add is required the
Matt Arsenaultee364ee2014-01-31 00:09:00 +000013694corresponding llvm.fma.\* intrinsic function should be used
13695instead. This never sets errno, just as '``llvm.fma.*``'.
Sean Silvab084af42012-12-07 10:36:55 +000013696
13697Examples:
13698"""""""""
13699
13700.. code-block:: llvm
13701
Tim Northover675a0962014-06-13 14:24:23 +000013702 %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 +000013703
Amara Emersoncf9daa32017-05-09 10:43:25 +000013704
13705Experimental Vector Reduction Intrinsics
13706----------------------------------------
13707
13708Horizontal reductions of vectors can be expressed using the following
13709intrinsics. Each one takes a vector operand as an input and applies its
13710respective operation across all elements of the vector, returning a single
13711scalar result of the same element type.
13712
13713
13714'``llvm.experimental.vector.reduce.add.*``' Intrinsic
13715^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13716
13717Syntax:
13718"""""""
13719
13720::
13721
13722 declare i32 @llvm.experimental.vector.reduce.add.i32.v4i32(<4 x i32> %a)
13723 declare i64 @llvm.experimental.vector.reduce.add.i64.v2i64(<2 x i64> %a)
13724
13725Overview:
13726"""""""""
13727
13728The '``llvm.experimental.vector.reduce.add.*``' intrinsics do an integer ``ADD``
13729reduction of a vector, returning the result as a scalar. The return type matches
13730the element-type of the vector input.
13731
13732Arguments:
13733""""""""""
13734The argument to this intrinsic must be a vector of integer values.
13735
Sander de Smalencbeb5632019-06-11 08:22:10 +000013736'``llvm.experimental.vector.reduce.v2.fadd.*``' Intrinsic
13737^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Amara Emersoncf9daa32017-05-09 10:43:25 +000013738
13739Syntax:
13740"""""""
13741
13742::
13743
Sander de Smalencbeb5632019-06-11 08:22:10 +000013744 declare float @llvm.experimental.vector.reduce.v2.fadd.f32.v4f32(float %start_value, <4 x float> %a)
13745 declare double @llvm.experimental.vector.reduce.v2.fadd.f64.v2f64(double %start_value, <2 x double> %a)
Amara Emersoncf9daa32017-05-09 10:43:25 +000013746
13747Overview:
13748"""""""""
13749
Sander de Smalencbeb5632019-06-11 08:22:10 +000013750The '``llvm.experimental.vector.reduce.v2.fadd.*``' intrinsics do a floating-point
Amara Emersoncf9daa32017-05-09 10:43:25 +000013751``ADD`` reduction of a vector, returning the result as a scalar. The return type
13752matches the element-type of the vector input.
13753
Sander de Smalencbeb5632019-06-11 08:22:10 +000013754If the intrinsic call has the 'reassoc' or 'fast' flags set, then the
13755reduction will not preserve the associativity of an equivalent scalarized
13756counterpart. Otherwise the reduction will be *ordered*, thus implying that
13757the operation respects the associativity of a scalarized reduction.
Amara Emersoncf9daa32017-05-09 10:43:25 +000013758
13759
13760Arguments:
13761""""""""""
Sander de Smalencbeb5632019-06-11 08:22:10 +000013762The first argument to this intrinsic is a scalar start value for the reduction.
13763The type of the start value matches the element-type of the vector input.
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000013764The second argument must be a vector of floating-point values.
Amara Emersoncf9daa32017-05-09 10:43:25 +000013765
13766Examples:
13767"""""""""
13768
13769.. code-block:: llvm
13770
Sander de Smalencbeb5632019-06-11 08:22:10 +000013771 %unord = call reassoc float @llvm.experimental.vector.reduce.v2.fadd.f32.v4f32(float 0.0, <4 x float> %input) ; unordered reduction
13772 %ord = call float @llvm.experimental.vector.reduce.v2.fadd.f32.v4f32(float %start_value, <4 x float> %input) ; ordered reduction
Amara Emersoncf9daa32017-05-09 10:43:25 +000013773
13774
13775'``llvm.experimental.vector.reduce.mul.*``' Intrinsic
13776^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13777
13778Syntax:
13779"""""""
13780
13781::
13782
13783 declare i32 @llvm.experimental.vector.reduce.mul.i32.v4i32(<4 x i32> %a)
13784 declare i64 @llvm.experimental.vector.reduce.mul.i64.v2i64(<2 x i64> %a)
13785
13786Overview:
13787"""""""""
13788
13789The '``llvm.experimental.vector.reduce.mul.*``' intrinsics do an integer ``MUL``
13790reduction of a vector, returning the result as a scalar. The return type matches
13791the element-type of the vector input.
13792
13793Arguments:
13794""""""""""
13795The argument to this intrinsic must be a vector of integer values.
13796
Sander de Smalencbeb5632019-06-11 08:22:10 +000013797'``llvm.experimental.vector.reduce.v2.fmul.*``' Intrinsic
13798^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Amara Emersoncf9daa32017-05-09 10:43:25 +000013799
13800Syntax:
13801"""""""
13802
13803::
13804
Sander de Smalencbeb5632019-06-11 08:22:10 +000013805 declare float @llvm.experimental.vector.reduce.v2.fmul.f32.v4f32(float %start_value, <4 x float> %a)
13806 declare double @llvm.experimental.vector.reduce.v2.fmul.f64.v2f64(double %start_value, <2 x double> %a)
Amara Emersoncf9daa32017-05-09 10:43:25 +000013807
13808Overview:
13809"""""""""
13810
Sander de Smalencbeb5632019-06-11 08:22:10 +000013811The '``llvm.experimental.vector.reduce.v2.fmul.*``' intrinsics do a floating-point
Amara Emersoncf9daa32017-05-09 10:43:25 +000013812``MUL`` reduction of a vector, returning the result as a scalar. The return type
13813matches the element-type of the vector input.
13814
Sander de Smalencbeb5632019-06-11 08:22:10 +000013815If the intrinsic call has the 'reassoc' or 'fast' flags set, then the
13816reduction will not preserve the associativity of an equivalent scalarized
13817counterpart. Otherwise the reduction will be *ordered*, thus implying that
13818the operation respects the associativity of a scalarized reduction.
Amara Emersoncf9daa32017-05-09 10:43:25 +000013819
13820
13821Arguments:
13822""""""""""
Sander de Smalencbeb5632019-06-11 08:22:10 +000013823The first argument to this intrinsic is a scalar start value for the reduction.
13824The type of the start value matches the element-type of the vector input.
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000013825The second argument must be a vector of floating-point values.
Amara Emersoncf9daa32017-05-09 10:43:25 +000013826
13827Examples:
13828"""""""""
13829
13830.. code-block:: llvm
13831
Sander de Smalencbeb5632019-06-11 08:22:10 +000013832 %unord = call reassoc float @llvm.experimental.vector.reduce.v2.fmul.f32.v4f32(float 1.0, <4 x float> %input) ; unordered reduction
13833 %ord = call float @llvm.experimental.vector.reduce.v2.fmul.f32.v4f32(float %start_value, <4 x float> %input) ; ordered reduction
Amara Emersoncf9daa32017-05-09 10:43:25 +000013834
13835'``llvm.experimental.vector.reduce.and.*``' Intrinsic
13836^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13837
13838Syntax:
13839"""""""
13840
13841::
13842
13843 declare i32 @llvm.experimental.vector.reduce.and.i32.v4i32(<4 x i32> %a)
13844
13845Overview:
13846"""""""""
13847
13848The '``llvm.experimental.vector.reduce.and.*``' intrinsics do a bitwise ``AND``
13849reduction of a vector, returning the result as a scalar. The return type matches
13850the element-type of the vector input.
13851
13852Arguments:
13853""""""""""
13854The argument to this intrinsic must be a vector of integer values.
13855
13856'``llvm.experimental.vector.reduce.or.*``' Intrinsic
13857^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13858
13859Syntax:
13860"""""""
13861
13862::
13863
13864 declare i32 @llvm.experimental.vector.reduce.or.i32.v4i32(<4 x i32> %a)
13865
13866Overview:
13867"""""""""
13868
13869The '``llvm.experimental.vector.reduce.or.*``' intrinsics do a bitwise ``OR`` reduction
13870of a vector, returning the result as a scalar. The return type matches the
13871element-type of the vector input.
13872
13873Arguments:
13874""""""""""
13875The argument to this intrinsic must be a vector of integer values.
13876
13877'``llvm.experimental.vector.reduce.xor.*``' Intrinsic
13878^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13879
13880Syntax:
13881"""""""
13882
13883::
13884
13885 declare i32 @llvm.experimental.vector.reduce.xor.i32.v4i32(<4 x i32> %a)
13886
13887Overview:
13888"""""""""
13889
13890The '``llvm.experimental.vector.reduce.xor.*``' intrinsics do a bitwise ``XOR``
13891reduction of a vector, returning the result as a scalar. The return type matches
13892the element-type of the vector input.
13893
13894Arguments:
13895""""""""""
13896The argument to this intrinsic must be a vector of integer values.
13897
13898'``llvm.experimental.vector.reduce.smax.*``' Intrinsic
13899^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13900
13901Syntax:
13902"""""""
13903
13904::
13905
13906 declare i32 @llvm.experimental.vector.reduce.smax.i32.v4i32(<4 x i32> %a)
13907
13908Overview:
13909"""""""""
13910
13911The '``llvm.experimental.vector.reduce.smax.*``' intrinsics do a signed integer
13912``MAX`` reduction of a vector, returning the result as a scalar. The return type
13913matches the element-type of the vector input.
13914
13915Arguments:
13916""""""""""
13917The argument to this intrinsic must be a vector of integer values.
13918
13919'``llvm.experimental.vector.reduce.smin.*``' Intrinsic
13920^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13921
13922Syntax:
13923"""""""
13924
13925::
13926
13927 declare i32 @llvm.experimental.vector.reduce.smin.i32.v4i32(<4 x i32> %a)
13928
13929Overview:
13930"""""""""
13931
13932The '``llvm.experimental.vector.reduce.smin.*``' intrinsics do a signed integer
13933``MIN`` reduction of a vector, returning the result as a scalar. The return type
13934matches the element-type of the vector input.
13935
13936Arguments:
13937""""""""""
13938The argument to this intrinsic must be a vector of integer values.
13939
13940'``llvm.experimental.vector.reduce.umax.*``' Intrinsic
13941^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13942
13943Syntax:
13944"""""""
13945
13946::
13947
13948 declare i32 @llvm.experimental.vector.reduce.umax.i32.v4i32(<4 x i32> %a)
13949
13950Overview:
13951"""""""""
13952
13953The '``llvm.experimental.vector.reduce.umax.*``' intrinsics do an unsigned
13954integer ``MAX`` reduction of a vector, returning the result as a scalar. The
13955return type matches the element-type of the vector input.
13956
13957Arguments:
13958""""""""""
13959The argument to this intrinsic must be a vector of integer values.
13960
13961'``llvm.experimental.vector.reduce.umin.*``' Intrinsic
13962^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13963
13964Syntax:
13965"""""""
13966
13967::
13968
13969 declare i32 @llvm.experimental.vector.reduce.umin.i32.v4i32(<4 x i32> %a)
13970
13971Overview:
13972"""""""""
13973
13974The '``llvm.experimental.vector.reduce.umin.*``' intrinsics do an unsigned
13975integer ``MIN`` reduction of a vector, returning the result as a scalar. The
13976return type matches the element-type of the vector input.
13977
13978Arguments:
13979""""""""""
13980The argument to this intrinsic must be a vector of integer values.
13981
13982'``llvm.experimental.vector.reduce.fmax.*``' Intrinsic
13983^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13984
13985Syntax:
13986"""""""
13987
13988::
13989
13990 declare float @llvm.experimental.vector.reduce.fmax.f32.v4f32(<4 x float> %a)
13991 declare double @llvm.experimental.vector.reduce.fmax.f64.v2f64(<2 x double> %a)
13992
13993Overview:
13994"""""""""
13995
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000013996The '``llvm.experimental.vector.reduce.fmax.*``' intrinsics do a floating-point
Amara Emersoncf9daa32017-05-09 10:43:25 +000013997``MAX`` reduction of a vector, returning the result as a scalar. The return type
13998matches the element-type of the vector input.
13999
14000If the intrinsic call has the ``nnan`` fast-math flag then the operation can
14001assume that NaNs are not present in the input vector.
14002
14003Arguments:
14004""""""""""
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000014005The argument to this intrinsic must be a vector of floating-point values.
Amara Emersoncf9daa32017-05-09 10:43:25 +000014006
14007'``llvm.experimental.vector.reduce.fmin.*``' Intrinsic
14008^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14009
14010Syntax:
14011"""""""
14012
14013::
14014
14015 declare float @llvm.experimental.vector.reduce.fmin.f32.v4f32(<4 x float> %a)
14016 declare double @llvm.experimental.vector.reduce.fmin.f64.v2f64(<2 x double> %a)
14017
14018Overview:
14019"""""""""
14020
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000014021The '``llvm.experimental.vector.reduce.fmin.*``' intrinsics do a floating-point
Amara Emersoncf9daa32017-05-09 10:43:25 +000014022``MIN`` reduction of a vector, returning the result as a scalar. The return type
14023matches the element-type of the vector input.
14024
14025If the intrinsic call has the ``nnan`` fast-math flag then the operation can
14026assume that NaNs are not present in the input vector.
14027
14028Arguments:
14029""""""""""
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000014030The argument to this intrinsic must be a vector of floating-point values.
Amara Emersoncf9daa32017-05-09 10:43:25 +000014031
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000014032Half Precision Floating-Point Intrinsics
Sean Silvab084af42012-12-07 10:36:55 +000014033----------------------------------------
14034
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000014035For most target platforms, half precision floating-point is a
Sean Silvab084af42012-12-07 10:36:55 +000014036storage-only format. This means that it is a dense encoding (in memory)
14037but does not support computation in the format.
14038
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000014039This means that code must first load the half-precision floating-point
Sean Silvab084af42012-12-07 10:36:55 +000014040value as an i16, then convert it to float with
14041:ref:`llvm.convert.from.fp16 <int_convert_from_fp16>`. Computation can
14042then be performed on the float value (including extending to double
14043etc). To store the value back to memory, it is first converted to float
14044if needed, then converted to i16 with
14045:ref:`llvm.convert.to.fp16 <int_convert_to_fp16>`, then storing as an
14046i16 value.
14047
14048.. _int_convert_to_fp16:
14049
14050'``llvm.convert.to.fp16``' Intrinsic
14051^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14052
14053Syntax:
14054"""""""
14055
14056::
14057
Tim Northoverfd7e4242014-07-17 10:51:23 +000014058 declare i16 @llvm.convert.to.fp16.f32(float %a)
14059 declare i16 @llvm.convert.to.fp16.f64(double %a)
Sean Silvab084af42012-12-07 10:36:55 +000014060
14061Overview:
14062"""""""""
14063
Tim Northoverfd7e4242014-07-17 10:51:23 +000014064The '``llvm.convert.to.fp16``' intrinsic function performs a conversion from a
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000014065conventional floating-point type to half precision floating-point format.
Sean Silvab084af42012-12-07 10:36:55 +000014066
14067Arguments:
14068""""""""""
14069
14070The intrinsic function contains single argument - the value to be
14071converted.
14072
14073Semantics:
14074""""""""""
14075
Tim Northoverfd7e4242014-07-17 10:51:23 +000014076The '``llvm.convert.to.fp16``' intrinsic function performs a conversion from a
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000014077conventional floating-point format to half precision floating-point format. The
Tim Northoverfd7e4242014-07-17 10:51:23 +000014078return value is an ``i16`` which contains the converted number.
Sean Silvab084af42012-12-07 10:36:55 +000014079
14080Examples:
14081"""""""""
14082
14083.. code-block:: llvm
14084
Tim Northoverfd7e4242014-07-17 10:51:23 +000014085 %res = call i16 @llvm.convert.to.fp16.f32(float %a)
Sean Silvab084af42012-12-07 10:36:55 +000014086 store i16 %res, i16* @x, align 2
14087
14088.. _int_convert_from_fp16:
14089
14090'``llvm.convert.from.fp16``' Intrinsic
14091^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14092
14093Syntax:
14094"""""""
14095
14096::
14097
Tim Northoverfd7e4242014-07-17 10:51:23 +000014098 declare float @llvm.convert.from.fp16.f32(i16 %a)
14099 declare double @llvm.convert.from.fp16.f64(i16 %a)
Sean Silvab084af42012-12-07 10:36:55 +000014100
14101Overview:
14102"""""""""
14103
14104The '``llvm.convert.from.fp16``' intrinsic function performs a
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000014105conversion from half precision floating-point format to single precision
14106floating-point format.
Sean Silvab084af42012-12-07 10:36:55 +000014107
14108Arguments:
14109""""""""""
14110
14111The intrinsic function contains single argument - the value to be
14112converted.
14113
14114Semantics:
14115""""""""""
14116
14117The '``llvm.convert.from.fp16``' intrinsic function performs a
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000014118conversion from half single precision floating-point format to single
14119precision floating-point format. The input half-float value is
Sean Silvab084af42012-12-07 10:36:55 +000014120represented by an ``i16`` value.
14121
14122Examples:
14123"""""""""
14124
14125.. code-block:: llvm
14126
David Blaikiec7aabbb2015-03-04 22:06:14 +000014127 %a = load i16, i16* @x, align 2
Matt Arsenault3e3ddda2014-07-10 03:22:16 +000014128 %res = call float @llvm.convert.from.fp16(i16 %a)
Sean Silvab084af42012-12-07 10:36:55 +000014129
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +000014130.. _dbg_intrinsics:
14131
Sean Silvab084af42012-12-07 10:36:55 +000014132Debugger Intrinsics
14133-------------------
14134
14135The LLVM debugger intrinsics (which all start with ``llvm.dbg.``
14136prefix), are described in the `LLVM Source Level
Hans Wennborg65195622017-09-28 15:16:37 +000014137Debugging <SourceLevelDebugging.html#format-common-intrinsics>`_
Sean Silvab084af42012-12-07 10:36:55 +000014138document.
14139
14140Exception Handling Intrinsics
14141-----------------------------
14142
14143The LLVM exception handling intrinsics (which all start with
14144``llvm.eh.`` prefix), are described in the `LLVM Exception
Hans Wennborg65195622017-09-28 15:16:37 +000014145Handling <ExceptionHandling.html#format-common-intrinsics>`_ document.
Sean Silvab084af42012-12-07 10:36:55 +000014146
14147.. _int_trampoline:
14148
14149Trampoline Intrinsics
14150---------------------
14151
14152These intrinsics make it possible to excise one parameter, marked with
14153the :ref:`nest <nest>` attribute, from a function. The result is a
14154callable function pointer lacking the nest parameter - the caller does
14155not need to provide a value for it. Instead, the value to use is stored
14156in advance in a "trampoline", a block of memory usually allocated on the
14157stack, which also contains code to splice the nest value into the
14158argument list. This is used to implement the GCC nested function address
14159extension.
14160
14161For example, if the function is ``i32 f(i8* nest %c, i32 %x, i32 %y)``
14162then the resulting function pointer has signature ``i32 (i32, i32)*``.
14163It can be created as follows:
14164
14165.. code-block:: llvm
14166
14167 %tramp = alloca [10 x i8], align 4 ; size and alignment only correct for X86
David Blaikie16a97eb2015-03-04 22:02:58 +000014168 %tramp1 = getelementptr [10 x i8], [10 x i8]* %tramp, i32 0, i32 0
Sean Silvab084af42012-12-07 10:36:55 +000014169 call i8* @llvm.init.trampoline(i8* %tramp1, i8* bitcast (i32 (i8*, i32, i32)* @f to i8*), i8* %nval)
14170 %p = call i8* @llvm.adjust.trampoline(i8* %tramp1)
14171 %fp = bitcast i8* %p to i32 (i32, i32)*
14172
14173The call ``%val = call i32 %fp(i32 %x, i32 %y)`` is then equivalent to
14174``%val = call i32 %f(i8* %nval, i32 %x, i32 %y)``.
14175
14176.. _int_it:
14177
14178'``llvm.init.trampoline``' Intrinsic
14179^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14180
14181Syntax:
14182"""""""
14183
14184::
14185
14186 declare void @llvm.init.trampoline(i8* <tramp>, i8* <func>, i8* <nval>)
14187
14188Overview:
14189"""""""""
14190
14191This fills the memory pointed to by ``tramp`` with executable code,
14192turning it into a trampoline.
14193
14194Arguments:
14195""""""""""
14196
14197The ``llvm.init.trampoline`` intrinsic takes three arguments, all
14198pointers. The ``tramp`` argument must point to a sufficiently large and
14199sufficiently aligned block of memory; this memory is written to by the
14200intrinsic. Note that the size and the alignment are target-specific -
14201LLVM currently provides no portable way of determining them, so a
14202front-end that generates this intrinsic needs to have some
14203target-specific knowledge. The ``func`` argument must hold a function
14204bitcast to an ``i8*``.
14205
14206Semantics:
14207""""""""""
14208
14209The block of memory pointed to by ``tramp`` is filled with target
14210dependent code, turning it into a function. Then ``tramp`` needs to be
14211passed to :ref:`llvm.adjust.trampoline <int_at>` to get a pointer which can
14212be :ref:`bitcast (to a new function) and called <int_trampoline>`. The new
14213function's signature is the same as that of ``func`` with any arguments
14214marked with the ``nest`` attribute removed. At most one such ``nest``
14215argument is allowed, and it must be of pointer type. Calling the new
14216function is equivalent to calling ``func`` with the same argument list,
14217but with ``nval`` used for the missing ``nest`` argument. If, after
14218calling ``llvm.init.trampoline``, the memory pointed to by ``tramp`` is
14219modified, then the effect of any later call to the returned function
14220pointer is undefined.
14221
14222.. _int_at:
14223
14224'``llvm.adjust.trampoline``' Intrinsic
14225^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14226
14227Syntax:
14228"""""""
14229
14230::
14231
14232 declare i8* @llvm.adjust.trampoline(i8* <tramp>)
14233
14234Overview:
14235"""""""""
14236
14237This performs any required machine-specific adjustment to the address of
14238a trampoline (passed as ``tramp``).
14239
14240Arguments:
14241""""""""""
14242
14243``tramp`` must point to a block of memory which already has trampoline
14244code filled in by a previous call to
14245:ref:`llvm.init.trampoline <int_it>`.
14246
14247Semantics:
14248""""""""""
14249
14250On some architectures the address of the code to be executed needs to be
Sanjay Patel69bf48e2014-07-04 19:40:43 +000014251different than the address where the trampoline is actually stored. This
Sean Silvab084af42012-12-07 10:36:55 +000014252intrinsic returns the executable address corresponding to ``tramp``
14253after performing the required machine specific adjustments. The pointer
14254returned can then be :ref:`bitcast and executed <int_trampoline>`.
14255
Elena Demikhovsky82cdd652015-05-07 12:25:11 +000014256.. _int_mload_mstore:
14257
Elena Demikhovsky3d13f1c2014-12-25 09:29:13 +000014258Masked Vector Load and Store Intrinsics
14259---------------------------------------
14260
14261LLVM 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.
14262
14263.. _int_mload:
14264
14265'``llvm.masked.load.*``' Intrinsics
14266^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14267
14268Syntax:
14269"""""""
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000014270This 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 +000014271
14272::
14273
Artur Pilipenko7ad95ec2016-06-28 18:27:25 +000014274 declare <16 x float> @llvm.masked.load.v16f32.p0v16f32 (<16 x float>* <ptr>, i32 <alignment>, <16 x i1> <mask>, <16 x float> <passthru>)
14275 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 +000014276 ;; The data is a vector of pointers to double
Artur Pilipenko7ad95ec2016-06-28 18:27:25 +000014277 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 +000014278 ;; The data is a vector of function pointers
Artur Pilipenko7ad95ec2016-06-28 18:27:25 +000014279 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 +000014280
14281Overview:
14282"""""""""
14283
Elena Demikhovsky82cdd652015-05-07 12:25:11 +000014284Reads 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 +000014285
14286
14287Arguments:
14288""""""""""
14289
Elena Demikhovsky82cdd652015-05-07 12:25:11 +000014290The 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 +000014291
14292
14293Semantics:
14294""""""""""
14295
14296The '``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.
14297The 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.
14298
14299
14300::
14301
Artur Pilipenko7ad95ec2016-06-28 18:27:25 +000014302 %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 +000014303
Elena Demikhovsky3d13f1c2014-12-25 09:29:13 +000014304 ;; The result of the two following instructions is identical aside from potential memory access exception
David Blaikiec7aabbb2015-03-04 22:06:14 +000014305 %loadlal = load <16 x float>, <16 x float>* %ptr, align 4
Elena Demikhovskye86c8c82014-12-29 09:47:51 +000014306 %res = select <16 x i1> %mask, <16 x float> %loadlal, <16 x float> %passthru
Elena Demikhovsky3d13f1c2014-12-25 09:29:13 +000014307
14308.. _int_mstore:
14309
14310'``llvm.masked.store.*``' Intrinsics
14311^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14312
14313Syntax:
14314"""""""
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000014315This 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 +000014316
14317::
14318
Artur Pilipenko7ad95ec2016-06-28 18:27:25 +000014319 declare void @llvm.masked.store.v8i32.p0v8i32 (<8 x i32> <value>, <8 x i32>* <ptr>, i32 <alignment>, <8 x i1> <mask>)
14320 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 +000014321 ;; The data is a vector of pointers to double
Artur Pilipenko7ad95ec2016-06-28 18:27:25 +000014322 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 +000014323 ;; The data is a vector of function pointers
Artur Pilipenko7ad95ec2016-06-28 18:27:25 +000014324 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 +000014325
14326Overview:
14327"""""""""
14328
14329Writes 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.
14330
14331Arguments:
14332""""""""""
14333
14334The 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.
14335
14336
14337Semantics:
14338""""""""""
14339
14340The '``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.
14341The 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.
14342
14343::
14344
Artur Pilipenko7ad95ec2016-06-28 18:27:25 +000014345 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 +000014346
Elena Demikhovskye86c8c82014-12-29 09:47:51 +000014347 ;; The result of the following instructions is identical aside from potential data races and memory access exceptions
David Blaikiec7aabbb2015-03-04 22:06:14 +000014348 %oldval = load <16 x float>, <16 x float>* %ptr, align 4
Elena Demikhovsky3d13f1c2014-12-25 09:29:13 +000014349 %res = select <16 x i1> %mask, <16 x float> %value, <16 x float> %oldval
14350 store <16 x float> %res, <16 x float>* %ptr, align 4
14351
14352
Elena Demikhovsky82cdd652015-05-07 12:25:11 +000014353Masked Vector Gather and Scatter Intrinsics
14354-------------------------------------------
14355
14356LLVM 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.
14357
14358.. _int_mgather:
14359
14360'``llvm.masked.gather.*``' Intrinsics
14361^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14362
14363Syntax:
14364"""""""
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000014365This 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 +000014366
14367::
14368
Elad Cohenef5798a2017-05-03 12:28:54 +000014369 declare <16 x float> @llvm.masked.gather.v16f32.v16p0f32 (<16 x float*> <ptrs>, i32 <alignment>, <16 x i1> <mask>, <16 x float> <passthru>)
14370 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>)
14371 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 +000014372
14373Overview:
14374"""""""""
14375
14376Reads 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.
14377
14378
14379Arguments:
14380""""""""""
14381
14382The 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.
14383
14384
14385Semantics:
14386""""""""""
14387
14388The '``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.
14389The 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.
14390
14391
14392::
14393
Elad Cohenef5798a2017-05-03 12:28:54 +000014394 %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 +000014395
14396 ;; The gather with all-true mask is equivalent to the following instruction sequence
14397 %ptr0 = extractelement <4 x double*> %ptrs, i32 0
14398 %ptr1 = extractelement <4 x double*> %ptrs, i32 1
14399 %ptr2 = extractelement <4 x double*> %ptrs, i32 2
14400 %ptr3 = extractelement <4 x double*> %ptrs, i32 3
14401
14402 %val0 = load double, double* %ptr0, align 8
14403 %val1 = load double, double* %ptr1, align 8
14404 %val2 = load double, double* %ptr2, align 8
14405 %val3 = load double, double* %ptr3, align 8
14406
14407 %vec0 = insertelement <4 x double>undef, %val0, 0
14408 %vec01 = insertelement <4 x double>%vec0, %val1, 1
14409 %vec012 = insertelement <4 x double>%vec01, %val2, 2
14410 %vec0123 = insertelement <4 x double>%vec012, %val3, 3
14411
14412.. _int_mscatter:
14413
14414'``llvm.masked.scatter.*``' Intrinsics
14415^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14416
14417Syntax:
14418"""""""
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000014419This 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 +000014420
14421::
14422
Elad Cohenef5798a2017-05-03 12:28:54 +000014423 declare void @llvm.masked.scatter.v8i32.v8p0i32 (<8 x i32> <value>, <8 x i32*> <ptrs>, i32 <alignment>, <8 x i1> <mask>)
14424 declare void @llvm.masked.scatter.v16f32.v16p1f32 (<16 x float> <value>, <16 x float addrspace(1)*> <ptrs>, i32 <alignment>, <16 x i1> <mask>)
14425 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 +000014426
14427Overview:
14428"""""""""
14429
14430Writes 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.
14431
14432Arguments:
14433""""""""""
14434
14435The 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.
14436
14437
14438Semantics:
14439""""""""""
14440
Bruce Mitchenere9ffb452015-09-12 01:17:08 +000014441The '``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 +000014442
14443::
14444
Sylvestre Ledru84666a12016-02-14 20:16:22 +000014445 ;; This instruction unconditionally stores data vector in multiple addresses
Elad Cohenef5798a2017-05-03 12:28:54 +000014446 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 +000014447
14448 ;; It is equivalent to a list of scalar stores
14449 %val0 = extractelement <8 x i32> %value, i32 0
14450 %val1 = extractelement <8 x i32> %value, i32 1
14451 ..
14452 %val7 = extractelement <8 x i32> %value, i32 7
14453 %ptr0 = extractelement <8 x i32*> %ptrs, i32 0
14454 %ptr1 = extractelement <8 x i32*> %ptrs, i32 1
14455 ..
14456 %ptr7 = extractelement <8 x i32*> %ptrs, i32 7
14457 ;; Note: the order of the following stores is important when they overlap:
14458 store i32 %val0, i32* %ptr0, align 4
14459 store i32 %val1, i32* %ptr1, align 4
14460 ..
14461 store i32 %val7, i32* %ptr7, align 4
14462
14463
Elena Demikhovsky0ef2ce32018-06-06 09:11:46 +000014464Masked Vector Expanding Load and Compressing Store Intrinsics
14465-------------------------------------------------------------
14466
14467LLVM 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>`.
14468
14469.. _int_expandload:
14470
14471'``llvm.masked.expandload.*``' Intrinsics
14472^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14473
14474Syntax:
14475"""""""
14476This 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.
14477
14478::
14479
14480 declare <16 x float> @llvm.masked.expandload.v16f32 (float* <ptr>, <16 x i1> <mask>, <16 x float> <passthru>)
14481 declare <2 x i64> @llvm.masked.expandload.v2i64 (i64* <ptr>, <2 x i1> <mask>, <2 x i64> <passthru>)
14482
14483Overview:
14484"""""""""
14485
14486Reads 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.
14487
14488
14489Arguments:
14490""""""""""
14491
14492The 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.
14493
14494Semantics:
14495""""""""""
14496
14497The '``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:
14498
14499.. code-block:: c
14500
14501 // In this loop we load from B and spread the elements into array A.
14502 double *A, B; int *C;
14503 for (int i = 0; i < size; ++i) {
14504 if (C[i] != 0)
14505 A[i] = B[j++];
14506 }
14507
14508
14509.. code-block:: llvm
14510
14511 ; Load several elements from array B and expand them in a vector.
14512 ; The number of loaded elements is equal to the number of '1' elements in the Mask.
14513 %Tmp = call <8 x double> @llvm.masked.expandload.v8f64(double* %Bptr, <8 x i1> %Mask, <8 x double> undef)
14514 ; Store the result in A
14515 call void @llvm.masked.store.v8f64.p0v8f64(<8 x double> %Tmp, <8 x double>* %Aptr, i32 8, <8 x i1> %Mask)
Mandeep Singh Grang547a0d72018-11-01 23:22:25 +000014516
Elena Demikhovsky0ef2ce32018-06-06 09:11:46 +000014517 ; %Bptr should be increased on each iteration according to the number of '1' elements in the Mask.
14518 %MaskI = bitcast <8 x i1> %Mask to i8
14519 %MaskIPopcnt = call i8 @llvm.ctpop.i8(i8 %MaskI)
14520 %MaskI64 = zext i8 %MaskIPopcnt to i64
14521 %BNextInd = add i64 %BInd, %MaskI64
14522
14523
14524Other targets may support this intrinsic differently, for example, by lowering it into a sequence of conditional scalar load operations and shuffles.
14525If all mask elements are '1', the intrinsic behavior is equivalent to the regular unmasked vector load.
14526
14527.. _int_compressstore:
14528
14529'``llvm.masked.compressstore.*``' Intrinsics
14530^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14531
14532Syntax:
14533"""""""
14534This 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.
14535
14536::
14537
14538 declare void @llvm.masked.compressstore.v8i32 (<8 x i32> <value>, i32* <ptr>, <8 x i1> <mask>)
14539 declare void @llvm.masked.compressstore.v16f32 (<16 x float> <value>, float* <ptr>, <16 x i1> <mask>)
14540
14541Overview:
14542"""""""""
14543
14544Selects 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.
14545
14546Arguments:
14547""""""""""
14548
14549The 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.
14550
14551
14552Semantics:
14553""""""""""
14554
14555The '``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:
14556
14557.. code-block:: c
14558
14559 // In this loop we load elements from A and store them consecutively in B
14560 double *A, B; int *C;
14561 for (int i = 0; i < size; ++i) {
14562 if (C[i] != 0)
14563 B[j++] = A[i]
14564 }
14565
14566
14567.. code-block:: llvm
14568
14569 ; Load elements from A.
14570 %Tmp = call <8 x double> @llvm.masked.load.v8f64.p0v8f64(<8 x double>* %Aptr, i32 8, <8 x i1> %Mask, <8 x double> undef)
14571 ; Store all selected elements consecutively in array B
14572 call <void> @llvm.masked.compressstore.v8f64(<8 x double> %Tmp, double* %Bptr, <8 x i1> %Mask)
Mandeep Singh Grang547a0d72018-11-01 23:22:25 +000014573
Elena Demikhovsky0ef2ce32018-06-06 09:11:46 +000014574 ; %Bptr should be increased on each iteration according to the number of '1' elements in the Mask.
14575 %MaskI = bitcast <8 x i1> %Mask to i8
14576 %MaskIPopcnt = call i8 @llvm.ctpop.i8(i8 %MaskI)
14577 %MaskI64 = zext i8 %MaskIPopcnt to i64
14578 %BNextInd = add i64 %BInd, %MaskI64
14579
14580
14581Other targets may support this intrinsic differently, for example, by lowering it into a sequence of branches that guard scalar store operations.
14582
14583
Sean Silvab084af42012-12-07 10:36:55 +000014584Memory Use Markers
14585------------------
14586
Sanjay Patel69bf48e2014-07-04 19:40:43 +000014587This class of intrinsics provides information about the lifetime of
Sean Silvab084af42012-12-07 10:36:55 +000014588memory objects and ranges where variables are immutable.
14589
Reid Klecknera534a382013-12-19 02:14:12 +000014590.. _int_lifestart:
14591
Sean Silvab084af42012-12-07 10:36:55 +000014592'``llvm.lifetime.start``' Intrinsic
14593^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14594
14595Syntax:
14596"""""""
14597
14598::
14599
14600 declare void @llvm.lifetime.start(i64 <size>, i8* nocapture <ptr>)
14601
14602Overview:
14603"""""""""
14604
14605The '``llvm.lifetime.start``' intrinsic specifies the start of a memory
14606object's lifetime.
14607
14608Arguments:
14609""""""""""
14610
14611The first argument is a constant integer representing the size of the
14612object, or -1 if it is variable sized. The second argument is a pointer
14613to the object.
14614
14615Semantics:
14616""""""""""
14617
14618This intrinsic indicates that before this point in the code, the value
14619of the memory pointed to by ``ptr`` is dead. This means that it is known
14620to never be used and has an undefined value. A load from the pointer
14621that precedes this intrinsic can be replaced with ``'undef'``.
14622
Reid Klecknera534a382013-12-19 02:14:12 +000014623.. _int_lifeend:
14624
Sean Silvab084af42012-12-07 10:36:55 +000014625'``llvm.lifetime.end``' Intrinsic
14626^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14627
14628Syntax:
14629"""""""
14630
14631::
14632
14633 declare void @llvm.lifetime.end(i64 <size>, i8* nocapture <ptr>)
14634
14635Overview:
14636"""""""""
14637
14638The '``llvm.lifetime.end``' intrinsic specifies the end of a memory
14639object's lifetime.
14640
14641Arguments:
14642""""""""""
14643
14644The first argument is a constant integer representing the size of the
14645object, or -1 if it is variable sized. The second argument is a pointer
14646to the object.
14647
14648Semantics:
14649""""""""""
14650
14651This intrinsic indicates that after this point in the code, the value of
14652the memory pointed to by ``ptr`` is dead. This means that it is known to
14653never be used and has an undefined value. Any stores into the memory
14654object following this intrinsic may be removed as dead.
14655
14656'``llvm.invariant.start``' Intrinsic
14657^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14658
14659Syntax:
14660"""""""
Mehdi Amini8c629ec2016-08-13 23:31:24 +000014661This is an overloaded intrinsic. The memory object can belong to any address space.
Sean Silvab084af42012-12-07 10:36:55 +000014662
14663::
14664
Mehdi Amini8c629ec2016-08-13 23:31:24 +000014665 declare {}* @llvm.invariant.start.p0i8(i64 <size>, i8* nocapture <ptr>)
Sean Silvab084af42012-12-07 10:36:55 +000014666
14667Overview:
14668"""""""""
14669
14670The '``llvm.invariant.start``' intrinsic specifies that the contents of
14671a memory object will not change.
14672
14673Arguments:
14674""""""""""
14675
14676The first argument is a constant integer representing the size of the
14677object, or -1 if it is variable sized. The second argument is a pointer
14678to the object.
14679
14680Semantics:
14681""""""""""
14682
14683This intrinsic indicates that until an ``llvm.invariant.end`` that uses
14684the return value, the referenced memory location is constant and
14685unchanging.
14686
14687'``llvm.invariant.end``' Intrinsic
14688^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14689
14690Syntax:
14691"""""""
Mehdi Amini8c629ec2016-08-13 23:31:24 +000014692This is an overloaded intrinsic. The memory object can belong to any address space.
Sean Silvab084af42012-12-07 10:36:55 +000014693
14694::
14695
Mehdi Amini8c629ec2016-08-13 23:31:24 +000014696 declare void @llvm.invariant.end.p0i8({}* <start>, i64 <size>, i8* nocapture <ptr>)
Sean Silvab084af42012-12-07 10:36:55 +000014697
14698Overview:
14699"""""""""
14700
14701The '``llvm.invariant.end``' intrinsic specifies that the contents of a
14702memory object are mutable.
14703
14704Arguments:
14705""""""""""
14706
14707The first argument is the matching ``llvm.invariant.start`` intrinsic.
14708The second argument is a constant integer representing the size of the
14709object, or -1 if it is variable sized and the third argument is a
14710pointer to the object.
14711
14712Semantics:
14713""""""""""
14714
14715This intrinsic indicates that the memory is mutable again.
14716
Piotr Padlewski5dde8092018-05-03 11:03:01 +000014717'``llvm.launder.invariant.group``' Intrinsic
Piotr Padlewski6c15ec42015-09-15 18:32:14 +000014718^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14719
14720Syntax:
14721"""""""
Yaxun Liu407ca362017-11-16 16:32:16 +000014722This is an overloaded intrinsic. The memory object can belong to any address
14723space. The returned pointer must belong to the same address space as the
14724argument.
Piotr Padlewski6c15ec42015-09-15 18:32:14 +000014725
14726::
14727
Piotr Padlewski5dde8092018-05-03 11:03:01 +000014728 declare i8* @llvm.launder.invariant.group.p0i8(i8* <ptr>)
Piotr Padlewski6c15ec42015-09-15 18:32:14 +000014729
14730Overview:
14731"""""""""
14732
Piotr Padlewski5dde8092018-05-03 11:03:01 +000014733The '``llvm.launder.invariant.group``' intrinsic can be used when an invariant
Piotr Padlewski5b3db452018-07-02 04:49:30 +000014734established by ``invariant.group`` metadata no longer holds, to obtain a new
14735pointer value that carries fresh invariant group information. It is an
14736experimental intrinsic, which means that its semantics might change in the
14737future.
Piotr Padlewski6c15ec42015-09-15 18:32:14 +000014738
14739
14740Arguments:
14741""""""""""
14742
Piotr Padlewski5b3db452018-07-02 04:49:30 +000014743The ``llvm.launder.invariant.group`` takes only one argument, which is a pointer
14744to the memory.
Piotr Padlewski6c15ec42015-09-15 18:32:14 +000014745
14746Semantics:
14747""""""""""
14748
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +000014749Returns another pointer that aliases its argument but which is considered different
Piotr Padlewski6c15ec42015-09-15 18:32:14 +000014750for the purposes of ``load``/``store`` ``invariant.group`` metadata.
Piotr Padlewski5dde8092018-05-03 11:03:01 +000014751It does not read any accessible memory and the execution can be speculated.
Piotr Padlewski6c15ec42015-09-15 18:32:14 +000014752
Piotr Padlewski5b3db452018-07-02 04:49:30 +000014753'``llvm.strip.invariant.group``' Intrinsic
14754^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14755
14756Syntax:
14757"""""""
14758This is an overloaded intrinsic. The memory object can belong to any address
14759space. The returned pointer must belong to the same address space as the
14760argument.
14761
14762::
14763
14764 declare i8* @llvm.strip.invariant.group.p0i8(i8* <ptr>)
14765
14766Overview:
14767"""""""""
14768
14769The '``llvm.strip.invariant.group``' intrinsic can be used when an invariant
14770established by ``invariant.group`` metadata no longer holds, to obtain a new pointer
14771value that does not carry the invariant information. It is an experimental
14772intrinsic, which means that its semantics might change in the future.
14773
14774
14775Arguments:
14776""""""""""
14777
14778The ``llvm.strip.invariant.group`` takes only one argument, which is a pointer
14779to the memory.
14780
14781Semantics:
14782""""""""""
14783
14784Returns another pointer that aliases its argument but which has no associated
14785``invariant.group`` metadata.
14786It does not read any memory and can be speculated.
14787
14788
14789
Sanjay Patel54b161e2018-03-20 16:38:22 +000014790.. _constrainedfp:
14791
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000014792Constrained Floating-Point Intrinsics
Andrew Kaylora0a11642017-01-26 23:27:59 +000014793-------------------------------------
14794
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000014795These intrinsics are used to provide special handling of floating-point
14796operations when specific rounding mode or floating-point exception behavior is
Andrew Kaylora0a11642017-01-26 23:27:59 +000014797required. By default, LLVM optimization passes assume that the rounding mode is
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000014798round-to-nearest and that floating-point exceptions will not be monitored.
Andrew Kaylora0a11642017-01-26 23:27:59 +000014799Constrained FP intrinsics are used to support non-default rounding modes and
14800accurately preserve exception behavior without compromising LLVM's ability to
14801optimize FP code when the default behavior is used.
14802
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000014803Each of these intrinsics corresponds to a normal floating-point operation. The
Andrew Kaylora0a11642017-01-26 23:27:59 +000014804first two arguments and the return value are the same as the corresponding FP
14805operation.
14806
14807The third argument is a metadata argument specifying the rounding mode to be
14808assumed. This argument must be one of the following strings:
14809
14810::
Andrew Kaylor73b4a9a2017-04-20 18:18:36 +000014811
Andrew Kaylora0a11642017-01-26 23:27:59 +000014812 "round.dynamic"
14813 "round.tonearest"
14814 "round.downward"
14815 "round.upward"
14816 "round.towardzero"
14817
14818If this argument is "round.dynamic" optimization passes must assume that the
14819rounding mode is unknown and may change at runtime. No transformations that
14820depend on rounding mode may be performed in this case.
14821
14822The other possible values for the rounding mode argument correspond to the
14823similarly named IEEE rounding modes. If the argument is any of these values
14824optimization passes may perform transformations as long as they are consistent
14825with the specified rounding mode.
14826
14827For example, 'x-0'->'x' is not a valid transformation if the rounding mode is
14828"round.downward" or "round.dynamic" because if the value of 'x' is +0 then
14829'x-0' should evaluate to '-0' when rounding downward. However, this
14830transformation is legal for all other rounding modes.
14831
14832For values other than "round.dynamic" optimization passes may assume that the
14833actual runtime rounding mode (as defined in a target-specific manner) matches
14834the specified rounding mode, but this is not guaranteed. Using a specific
14835non-dynamic rounding mode which does not match the actual rounding mode at
14836runtime results in undefined behavior.
14837
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000014838The fourth argument to the constrained floating-point intrinsics specifies the
Andrew Kaylora0a11642017-01-26 23:27:59 +000014839required exception behavior. This argument must be one of the following
14840strings:
14841
14842::
Andrew Kaylor73b4a9a2017-04-20 18:18:36 +000014843
Andrew Kaylora0a11642017-01-26 23:27:59 +000014844 "fpexcept.ignore"
14845 "fpexcept.maytrap"
14846 "fpexcept.strict"
14847
14848If this argument is "fpexcept.ignore" optimization passes may assume that the
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000014849exception status flags will not be read and that floating-point exceptions will
Andrew Kaylora0a11642017-01-26 23:27:59 +000014850be masked. This allows transformations to be performed that may change the
14851exception semantics of the original code. For example, FP operations may be
14852speculatively executed in this case whereas they must not be for either of the
14853other possible values of this argument.
14854
14855If the exception behavior argument is "fpexcept.maytrap" optimization passes
14856must avoid transformations that may raise exceptions that would not have been
14857raised by the original code (such as speculatively executing FP operations), but
14858passes are not required to preserve all exceptions that are implied by the
14859original code. For example, exceptions may be potentially hidden by constant
14860folding.
14861
14862If the exception behavior argument is "fpexcept.strict" all transformations must
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000014863strictly preserve the floating-point exception semantics of the original code.
Andrew Kaylora0a11642017-01-26 23:27:59 +000014864Any FP exception that would have been raised by the original code must be raised
14865by the transformed code, and the transformed code must not raise any FP
14866exceptions that would not have been raised by the original code. This is the
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +000014867exception behavior argument that will be used if the code being compiled reads
Andrew Kaylora0a11642017-01-26 23:27:59 +000014868the FP exception status flags, but this mode can also be used with code that
14869unmasks FP exceptions.
14870
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000014871The number and order of floating-point exceptions is NOT guaranteed. For
Andrew Kaylora0a11642017-01-26 23:27:59 +000014872example, a series of FP operations that each may raise exceptions may be
14873vectorized into a single instruction that raises each unique exception a single
14874time.
14875
14876
14877'``llvm.experimental.constrained.fadd``' Intrinsic
14878^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14879
14880Syntax:
14881"""""""
14882
14883::
14884
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +000014885 declare <type>
Andrew Kaylora0a11642017-01-26 23:27:59 +000014886 @llvm.experimental.constrained.fadd(<type> <op1>, <type> <op2>,
14887 metadata <rounding mode>,
Andrew Kaylorf4660012017-05-25 21:31:00 +000014888 metadata <exception behavior>)
Andrew Kaylora0a11642017-01-26 23:27:59 +000014889
14890Overview:
14891"""""""""
14892
14893The '``llvm.experimental.constrained.fadd``' intrinsic returns the sum of its
14894two operands.
14895
14896
14897Arguments:
14898""""""""""
14899
14900The first two arguments to the '``llvm.experimental.constrained.fadd``'
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000014901intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>`
14902of floating-point values. Both arguments must have identical types.
Andrew Kaylora0a11642017-01-26 23:27:59 +000014903
14904The third and fourth arguments specify the rounding mode and exception
14905behavior as described above.
14906
14907Semantics:
14908""""""""""
14909
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000014910The value produced is the floating-point sum of the two value operands and has
Andrew Kaylora0a11642017-01-26 23:27:59 +000014911the same type as the operands.
14912
14913
14914'``llvm.experimental.constrained.fsub``' Intrinsic
14915^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14916
14917Syntax:
14918"""""""
14919
14920::
14921
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +000014922 declare <type>
Andrew Kaylora0a11642017-01-26 23:27:59 +000014923 @llvm.experimental.constrained.fsub(<type> <op1>, <type> <op2>,
14924 metadata <rounding mode>,
Andrew Kaylorf4660012017-05-25 21:31:00 +000014925 metadata <exception behavior>)
Andrew Kaylora0a11642017-01-26 23:27:59 +000014926
14927Overview:
14928"""""""""
14929
14930The '``llvm.experimental.constrained.fsub``' intrinsic returns the difference
14931of its two operands.
14932
14933
14934Arguments:
14935""""""""""
14936
14937The first two arguments to the '``llvm.experimental.constrained.fsub``'
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000014938intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>`
14939of floating-point values. Both arguments must have identical types.
Andrew Kaylora0a11642017-01-26 23:27:59 +000014940
14941The third and fourth arguments specify the rounding mode and exception
14942behavior as described above.
14943
14944Semantics:
14945""""""""""
14946
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000014947The value produced is the floating-point difference of the two value operands
Andrew Kaylora0a11642017-01-26 23:27:59 +000014948and has the same type as the operands.
14949
14950
14951'``llvm.experimental.constrained.fmul``' Intrinsic
14952^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14953
14954Syntax:
14955"""""""
14956
14957::
14958
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +000014959 declare <type>
Andrew Kaylora0a11642017-01-26 23:27:59 +000014960 @llvm.experimental.constrained.fmul(<type> <op1>, <type> <op2>,
14961 metadata <rounding mode>,
Andrew Kaylorf4660012017-05-25 21:31:00 +000014962 metadata <exception behavior>)
Andrew Kaylora0a11642017-01-26 23:27:59 +000014963
14964Overview:
14965"""""""""
14966
14967The '``llvm.experimental.constrained.fmul``' intrinsic returns the product of
14968its two operands.
14969
14970
14971Arguments:
14972""""""""""
14973
14974The first two arguments to the '``llvm.experimental.constrained.fmul``'
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000014975intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>`
14976of floating-point values. Both arguments must have identical types.
Andrew Kaylora0a11642017-01-26 23:27:59 +000014977
14978The third and fourth arguments specify the rounding mode and exception
14979behavior as described above.
14980
14981Semantics:
14982""""""""""
14983
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000014984The value produced is the floating-point product of the two value operands and
Andrew Kaylora0a11642017-01-26 23:27:59 +000014985has the same type as the operands.
14986
14987
14988'``llvm.experimental.constrained.fdiv``' Intrinsic
14989^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14990
14991Syntax:
14992"""""""
14993
14994::
14995
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +000014996 declare <type>
Andrew Kaylora0a11642017-01-26 23:27:59 +000014997 @llvm.experimental.constrained.fdiv(<type> <op1>, <type> <op2>,
14998 metadata <rounding mode>,
Andrew Kaylorf4660012017-05-25 21:31:00 +000014999 metadata <exception behavior>)
Andrew Kaylora0a11642017-01-26 23:27:59 +000015000
15001Overview:
15002"""""""""
15003
15004The '``llvm.experimental.constrained.fdiv``' intrinsic returns the quotient of
15005its two operands.
15006
15007
15008Arguments:
15009""""""""""
15010
15011The first two arguments to the '``llvm.experimental.constrained.fdiv``'
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000015012intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>`
15013of floating-point values. Both arguments must have identical types.
Andrew Kaylora0a11642017-01-26 23:27:59 +000015014
15015The third and fourth arguments specify the rounding mode and exception
15016behavior as described above.
15017
15018Semantics:
15019""""""""""
15020
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000015021The value produced is the floating-point quotient of the two value operands and
Andrew Kaylora0a11642017-01-26 23:27:59 +000015022has the same type as the operands.
15023
15024
15025'``llvm.experimental.constrained.frem``' Intrinsic
15026^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15027
15028Syntax:
15029"""""""
15030
15031::
15032
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +000015033 declare <type>
Andrew Kaylora0a11642017-01-26 23:27:59 +000015034 @llvm.experimental.constrained.frem(<type> <op1>, <type> <op2>,
15035 metadata <rounding mode>,
Andrew Kaylorf4660012017-05-25 21:31:00 +000015036 metadata <exception behavior>)
Andrew Kaylora0a11642017-01-26 23:27:59 +000015037
15038Overview:
15039"""""""""
15040
15041The '``llvm.experimental.constrained.frem``' intrinsic returns the remainder
15042from the division of its two operands.
15043
15044
15045Arguments:
15046""""""""""
15047
15048The first two arguments to the '``llvm.experimental.constrained.frem``'
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000015049intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>`
15050of floating-point values. Both arguments must have identical types.
Andrew Kaylora0a11642017-01-26 23:27:59 +000015051
15052The third and fourth arguments specify the rounding mode and exception
15053behavior as described above. The rounding mode argument has no effect, since
15054the result of frem is never rounded, but the argument is included for
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000015055consistency with the other constrained floating-point intrinsics.
Andrew Kaylora0a11642017-01-26 23:27:59 +000015056
15057Semantics:
15058""""""""""
15059
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000015060The value produced is the floating-point remainder from the division of the two
Andrew Kaylora0a11642017-01-26 23:27:59 +000015061value operands and has the same type as the operands. The remainder has the
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +000015062same sign as the dividend.
Andrew Kaylora0a11642017-01-26 23:27:59 +000015063
Wei Dinga131d3f2017-08-24 04:18:24 +000015064'``llvm.experimental.constrained.fma``' Intrinsic
Cameron McInally10056792018-11-02 15:51:43 +000015065^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Wei Dinga131d3f2017-08-24 04:18:24 +000015066
15067Syntax:
15068"""""""
15069
15070::
15071
15072 declare <type>
15073 @llvm.experimental.constrained.fma(<type> <op1>, <type> <op2>, <type> <op3>,
15074 metadata <rounding mode>,
15075 metadata <exception behavior>)
15076
15077Overview:
15078"""""""""
15079
15080The '``llvm.experimental.constrained.fma``' intrinsic returns the result of a
15081fused-multiply-add operation on its operands.
15082
15083Arguments:
15084""""""""""
15085
15086The first three arguments to the '``llvm.experimental.constrained.fma``'
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000015087intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector
15088<t_vector>` of floating-point values. All arguments must have identical types.
Wei Dinga131d3f2017-08-24 04:18:24 +000015089
15090The fourth and fifth arguments specify the rounding mode and exception behavior
15091as described above.
15092
15093Semantics:
15094""""""""""
15095
15096The result produced is the product of the first two operands added to the third
15097operand computed with infinite precision, and then rounded to the target
15098precision.
Andrew Kaylora0a11642017-01-26 23:27:59 +000015099
Kevin P. Neal59877492019-05-13 13:23:30 +000015100'``llvm.experimental.constrained.fptrunc``' Intrinsic
15101^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15102
15103Syntax:
15104"""""""
15105
15106::
15107
15108 declare <ty2>
15109 @llvm.experimental.constrained.fptrunc(<type> <value>,
15110 metadata <rounding mode>,
15111 metadata <exception behavior>)
15112
15113Overview:
15114"""""""""
15115
15116The '``llvm.experimental.constrained.fptrunc``' intrinsic truncates ``value``
15117to type ``ty2``.
15118
15119Arguments:
15120""""""""""
15121
15122The first argument to the '``llvm.experimental.constrained.fptrunc``'
15123intrinsic must be :ref:`floating point <t_floating>` or :ref:`vector
15124<t_vector>` of floating point values. This argument must be larger in size
15125than the result.
15126
15127The second and third arguments specify the rounding mode and exception
15128behavior as described above.
15129
15130Semantics:
15131""""""""""
15132
15133The result produced is a floating point value truncated to be smaller in size
15134than the operand.
15135
15136'``llvm.experimental.constrained.fpext``' Intrinsic
15137^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15138
15139Syntax:
15140"""""""
15141
15142::
15143
15144 declare <ty2>
15145 @llvm.experimental.constrained.fpext(<type> <value>,
15146 metadata <exception behavior>)
15147
15148Overview:
15149"""""""""
15150
15151The '``llvm.experimental.constrained.fpext``' intrinsic extends a
15152floating-point ``value`` to a larger floating-point value.
15153
15154Arguments:
15155""""""""""
15156
15157The first argument to the '``llvm.experimental.constrained.fpext``'
15158intrinsic must be :ref:`floating point <t_floating>` or :ref:`vector
15159<t_vector>` of floating point values. This argument must be smaller in size
15160than the result.
15161
15162The second argument specifies the exception behavior as described above.
15163
15164Semantics:
15165""""""""""
15166
15167The result produced is a floating point value extended to be larger in size
15168than the operand. All restrictions that apply to the fpext instruction also
15169apply to this intrinsic.
15170
Andrew Kaylorf4660012017-05-25 21:31:00 +000015171Constrained libm-equivalent Intrinsics
15172--------------------------------------
15173
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000015174In addition to the basic floating-point operations for which constrained
Andrew Kaylorf4660012017-05-25 21:31:00 +000015175intrinsics are described above, there are constrained versions of various
15176operations which provide equivalent behavior to a corresponding libm function.
15177These intrinsics allow the precise behavior of these operations with respect to
15178rounding mode and exception behavior to be controlled.
15179
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000015180As with the basic constrained floating-point intrinsics, the rounding mode
Andrew Kaylorf4660012017-05-25 21:31:00 +000015181and exception behavior arguments only control the behavior of the optimizer.
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000015182They do not change the runtime floating-point environment.
Andrew Kaylorf4660012017-05-25 21:31:00 +000015183
15184
15185'``llvm.experimental.constrained.sqrt``' Intrinsic
15186^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15187
15188Syntax:
15189"""""""
15190
15191::
15192
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +000015193 declare <type>
Andrew Kaylorf4660012017-05-25 21:31:00 +000015194 @llvm.experimental.constrained.sqrt(<type> <op1>,
15195 metadata <rounding mode>,
15196 metadata <exception behavior>)
15197
15198Overview:
15199"""""""""
15200
15201The '``llvm.experimental.constrained.sqrt``' intrinsic returns the square root
15202of the specified value, returning the same value as the libm '``sqrt``'
15203functions would, but without setting ``errno``.
15204
15205Arguments:
15206""""""""""
15207
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000015208The first argument and the return type are floating-point numbers of the same
Andrew Kaylorf4660012017-05-25 21:31:00 +000015209type.
15210
15211The second and third arguments specify the rounding mode and exception
15212behavior as described above.
15213
15214Semantics:
15215""""""""""
15216
15217This function returns the nonnegative square root of the specified value.
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000015218If the value is less than negative zero, a floating-point exception occurs
Hiroshi Inoue760c0c92018-01-16 13:19:48 +000015219and the return value is architecture specific.
Andrew Kaylorf4660012017-05-25 21:31:00 +000015220
15221
15222'``llvm.experimental.constrained.pow``' Intrinsic
15223^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15224
15225Syntax:
15226"""""""
15227
15228::
15229
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +000015230 declare <type>
Andrew Kaylorf4660012017-05-25 21:31:00 +000015231 @llvm.experimental.constrained.pow(<type> <op1>, <type> <op2>,
15232 metadata <rounding mode>,
15233 metadata <exception behavior>)
15234
15235Overview:
15236"""""""""
15237
15238The '``llvm.experimental.constrained.pow``' intrinsic returns the first operand
15239raised to the (positive or negative) power specified by the second operand.
15240
15241Arguments:
15242""""""""""
15243
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000015244The first two arguments and the return value are floating-point numbers of the
Andrew Kaylorf4660012017-05-25 21:31:00 +000015245same type. The second argument specifies the power to which the first argument
15246should be raised.
15247
15248The third and fourth arguments specify the rounding mode and exception
15249behavior as described above.
15250
15251Semantics:
15252""""""""""
15253
15254This function returns the first value raised to the second power,
15255returning the same values as the libm ``pow`` functions would, and
15256handles error conditions in the same way.
15257
15258
15259'``llvm.experimental.constrained.powi``' Intrinsic
15260^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15261
15262Syntax:
15263"""""""
15264
15265::
15266
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +000015267 declare <type>
Andrew Kaylorf4660012017-05-25 21:31:00 +000015268 @llvm.experimental.constrained.powi(<type> <op1>, i32 <op2>,
15269 metadata <rounding mode>,
15270 metadata <exception behavior>)
15271
15272Overview:
15273"""""""""
15274
15275The '``llvm.experimental.constrained.powi``' intrinsic returns the first operand
15276raised to the (positive or negative) power specified by the second operand. The
Mandeep Singh Grang547a0d72018-11-01 23:22:25 +000015277order of evaluation of multiplications is not defined. When a vector of
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000015278floating-point type is used, the second argument remains a scalar integer value.
Andrew Kaylorf4660012017-05-25 21:31:00 +000015279
15280
15281Arguments:
15282""""""""""
15283
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000015284The first argument and the return value are floating-point numbers of the same
Andrew Kaylorf4660012017-05-25 21:31:00 +000015285type. The second argument is a 32-bit signed integer specifying the power to
15286which the first argument should be raised.
15287
15288The third and fourth arguments specify the rounding mode and exception
15289behavior as described above.
15290
15291Semantics:
15292""""""""""
15293
15294This function returns the first value raised to the second power with an
15295unspecified sequence of rounding operations.
15296
15297
15298'``llvm.experimental.constrained.sin``' Intrinsic
15299^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15300
15301Syntax:
15302"""""""
15303
15304::
15305
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +000015306 declare <type>
Andrew Kaylorf4660012017-05-25 21:31:00 +000015307 @llvm.experimental.constrained.sin(<type> <op1>,
15308 metadata <rounding mode>,
15309 metadata <exception behavior>)
15310
15311Overview:
15312"""""""""
15313
15314The '``llvm.experimental.constrained.sin``' intrinsic returns the sine of the
15315first operand.
15316
15317Arguments:
15318""""""""""
15319
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000015320The first argument and the return type are floating-point numbers of the same
Andrew Kaylorf4660012017-05-25 21:31:00 +000015321type.
15322
15323The second and third arguments specify the rounding mode and exception
15324behavior as described above.
15325
15326Semantics:
15327""""""""""
15328
15329This function returns the sine of the specified operand, returning the
15330same values as the libm ``sin`` functions would, and handles error
15331conditions in the same way.
15332
15333
15334'``llvm.experimental.constrained.cos``' Intrinsic
15335^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15336
15337Syntax:
15338"""""""
15339
15340::
15341
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +000015342 declare <type>
Andrew Kaylorf4660012017-05-25 21:31:00 +000015343 @llvm.experimental.constrained.cos(<type> <op1>,
15344 metadata <rounding mode>,
15345 metadata <exception behavior>)
15346
15347Overview:
15348"""""""""
15349
15350The '``llvm.experimental.constrained.cos``' intrinsic returns the cosine of the
15351first operand.
15352
15353Arguments:
15354""""""""""
15355
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000015356The first argument and the return type are floating-point numbers of the same
Andrew Kaylorf4660012017-05-25 21:31:00 +000015357type.
15358
15359The second and third arguments specify the rounding mode and exception
15360behavior as described above.
15361
15362Semantics:
15363""""""""""
15364
15365This function returns the cosine of the specified operand, returning the
15366same values as the libm ``cos`` functions would, and handles error
15367conditions in the same way.
15368
15369
15370'``llvm.experimental.constrained.exp``' Intrinsic
15371^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15372
15373Syntax:
15374"""""""
15375
15376::
15377
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +000015378 declare <type>
Andrew Kaylorf4660012017-05-25 21:31:00 +000015379 @llvm.experimental.constrained.exp(<type> <op1>,
15380 metadata <rounding mode>,
15381 metadata <exception behavior>)
15382
15383Overview:
15384"""""""""
15385
15386The '``llvm.experimental.constrained.exp``' intrinsic computes the base-e
15387exponential of the specified value.
15388
15389Arguments:
15390""""""""""
15391
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000015392The first argument and the return value are floating-point numbers of the same
Andrew Kaylorf4660012017-05-25 21:31:00 +000015393type.
15394
15395The second and third arguments specify the rounding mode and exception
15396behavior as described above.
15397
15398Semantics:
15399""""""""""
15400
15401This function returns the same values as the libm ``exp`` functions
15402would, and handles error conditions in the same way.
15403
15404
15405'``llvm.experimental.constrained.exp2``' Intrinsic
15406^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15407
15408Syntax:
15409"""""""
15410
15411::
15412
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +000015413 declare <type>
Andrew Kaylorf4660012017-05-25 21:31:00 +000015414 @llvm.experimental.constrained.exp2(<type> <op1>,
15415 metadata <rounding mode>,
15416 metadata <exception behavior>)
15417
15418Overview:
15419"""""""""
15420
15421The '``llvm.experimental.constrained.exp2``' intrinsic computes the base-2
15422exponential of the specified value.
15423
15424
15425Arguments:
15426""""""""""
15427
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000015428The first argument and the return value are floating-point numbers of the same
Andrew Kaylorf4660012017-05-25 21:31:00 +000015429type.
15430
15431The second and third arguments specify the rounding mode and exception
15432behavior as described above.
15433
15434Semantics:
15435""""""""""
15436
15437This function returns the same values as the libm ``exp2`` functions
15438would, and handles error conditions in the same way.
15439
15440
15441'``llvm.experimental.constrained.log``' Intrinsic
15442^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15443
15444Syntax:
15445"""""""
15446
15447::
15448
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +000015449 declare <type>
Andrew Kaylorf4660012017-05-25 21:31:00 +000015450 @llvm.experimental.constrained.log(<type> <op1>,
15451 metadata <rounding mode>,
15452 metadata <exception behavior>)
15453
15454Overview:
15455"""""""""
15456
15457The '``llvm.experimental.constrained.log``' intrinsic computes the base-e
15458logarithm of the specified value.
15459
15460Arguments:
15461""""""""""
15462
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000015463The first argument and the return value are floating-point numbers of the same
Andrew Kaylorf4660012017-05-25 21:31:00 +000015464type.
15465
15466The second and third arguments specify the rounding mode and exception
15467behavior as described above.
15468
15469
15470Semantics:
15471""""""""""
15472
15473This function returns the same values as the libm ``log`` functions
15474would, and handles error conditions in the same way.
15475
15476
15477'``llvm.experimental.constrained.log10``' Intrinsic
15478^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15479
15480Syntax:
15481"""""""
15482
15483::
15484
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +000015485 declare <type>
Andrew Kaylorf4660012017-05-25 21:31:00 +000015486 @llvm.experimental.constrained.log10(<type> <op1>,
15487 metadata <rounding mode>,
15488 metadata <exception behavior>)
15489
15490Overview:
15491"""""""""
15492
15493The '``llvm.experimental.constrained.log10``' intrinsic computes the base-10
15494logarithm of the specified value.
15495
15496Arguments:
15497""""""""""
15498
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000015499The first argument and the return value are floating-point numbers of the same
Andrew Kaylorf4660012017-05-25 21:31:00 +000015500type.
15501
15502The second and third arguments specify the rounding mode and exception
15503behavior as described above.
15504
15505Semantics:
15506""""""""""
15507
15508This function returns the same values as the libm ``log10`` functions
15509would, and handles error conditions in the same way.
15510
15511
15512'``llvm.experimental.constrained.log2``' Intrinsic
15513^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15514
15515Syntax:
15516"""""""
15517
15518::
15519
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +000015520 declare <type>
Andrew Kaylorf4660012017-05-25 21:31:00 +000015521 @llvm.experimental.constrained.log2(<type> <op1>,
15522 metadata <rounding mode>,
15523 metadata <exception behavior>)
15524
15525Overview:
15526"""""""""
15527
15528The '``llvm.experimental.constrained.log2``' intrinsic computes the base-2
15529logarithm of the specified value.
15530
15531Arguments:
15532""""""""""
15533
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000015534The first argument and the return value are floating-point numbers of the same
Andrew Kaylorf4660012017-05-25 21:31:00 +000015535type.
15536
15537The second and third arguments specify the rounding mode and exception
15538behavior as described above.
15539
15540Semantics:
15541""""""""""
15542
15543This function returns the same values as the libm ``log2`` functions
15544would, and handles error conditions in the same way.
15545
15546
15547'``llvm.experimental.constrained.rint``' Intrinsic
15548^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15549
15550Syntax:
15551"""""""
15552
15553::
15554
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +000015555 declare <type>
Andrew Kaylorf4660012017-05-25 21:31:00 +000015556 @llvm.experimental.constrained.rint(<type> <op1>,
15557 metadata <rounding mode>,
15558 metadata <exception behavior>)
15559
15560Overview:
15561"""""""""
15562
15563The '``llvm.experimental.constrained.rint``' intrinsic returns the first
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000015564operand rounded to the nearest integer. It may raise an inexact floating-point
Andrew Kaylorf4660012017-05-25 21:31:00 +000015565exception if the operand is not an integer.
15566
15567Arguments:
15568""""""""""
15569
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000015570The first argument and the return value are floating-point numbers of the same
Andrew Kaylorf4660012017-05-25 21:31:00 +000015571type.
15572
15573The second and third arguments specify the rounding mode and exception
15574behavior as described above.
15575
15576Semantics:
15577""""""""""
15578
15579This function returns the same values as the libm ``rint`` functions
15580would, and handles error conditions in the same way. The rounding mode is
15581described, not determined, by the rounding mode argument. The actual rounding
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000015582mode is determined by the runtime floating-point environment. The rounding
Andrew Kaylorf4660012017-05-25 21:31:00 +000015583mode argument is only intended as information to the compiler.
15584
15585
15586'``llvm.experimental.constrained.nearbyint``' Intrinsic
15587^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15588
15589Syntax:
15590"""""""
15591
15592::
15593
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +000015594 declare <type>
Andrew Kaylorf4660012017-05-25 21:31:00 +000015595 @llvm.experimental.constrained.nearbyint(<type> <op1>,
15596 metadata <rounding mode>,
15597 metadata <exception behavior>)
15598
15599Overview:
15600"""""""""
15601
15602The '``llvm.experimental.constrained.nearbyint``' intrinsic returns the first
Mandeep Singh Grang547a0d72018-11-01 23:22:25 +000015603operand rounded to the nearest integer. It will not raise an inexact
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000015604floating-point exception if the operand is not an integer.
Andrew Kaylorf4660012017-05-25 21:31:00 +000015605
15606
15607Arguments:
15608""""""""""
15609
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000015610The first argument and the return value are floating-point numbers of the same
Andrew Kaylorf4660012017-05-25 21:31:00 +000015611type.
15612
15613The second and third arguments specify the rounding mode and exception
15614behavior as described above.
15615
15616Semantics:
15617""""""""""
15618
15619This function returns the same values as the libm ``nearbyint`` functions
15620would, and handles error conditions in the same way. The rounding mode is
15621described, not determined, by the rounding mode argument. The actual rounding
Sanjay Patel85fa9ef2018-03-21 14:15:33 +000015622mode is determined by the runtime floating-point environment. The rounding
Andrew Kaylorf4660012017-05-25 21:31:00 +000015623mode argument is only intended as information to the compiler.
15624
15625
Cameron McInally2ad870e2018-10-30 21:01:29 +000015626'``llvm.experimental.constrained.maxnum``' Intrinsic
Cameron McInally10056792018-11-02 15:51:43 +000015627^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Cameron McInally2ad870e2018-10-30 21:01:29 +000015628
15629Syntax:
15630"""""""
15631
15632::
15633
15634 declare <type>
15635 @llvm.experimental.constrained.maxnum(<type> <op1>, <type> <op2>
15636 metadata <rounding mode>,
15637 metadata <exception behavior>)
15638
15639Overview:
15640"""""""""
15641
Michael Kruse978ba612018-12-20 04:58:07 +000015642The '``llvm.experimental.constrained.maxnum``' intrinsic returns the maximum
Cameron McInally2ad870e2018-10-30 21:01:29 +000015643of the two arguments.
15644
15645Arguments:
15646""""""""""
15647
Michael Kruse978ba612018-12-20 04:58:07 +000015648The first two arguments and the return value are floating-point numbers
Cameron McInally2ad870e2018-10-30 21:01:29 +000015649of the same type.
15650
15651The third and forth arguments specify the rounding mode and exception
15652behavior as described above.
15653
15654Semantics:
15655""""""""""
15656
15657This function follows the IEEE-754 semantics for maxNum. The rounding mode is
15658described, not determined, by the rounding mode argument. The actual rounding
15659mode is determined by the runtime floating-point environment. The rounding
15660mode argument is only intended as information to the compiler.
15661
15662
15663'``llvm.experimental.constrained.minnum``' Intrinsic
Cameron McInally10056792018-11-02 15:51:43 +000015664^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Cameron McInally2ad870e2018-10-30 21:01:29 +000015665
15666Syntax:
15667"""""""
15668
15669::
15670
15671 declare <type>
15672 @llvm.experimental.constrained.minnum(<type> <op1>, <type> <op2>
15673 metadata <rounding mode>,
15674 metadata <exception behavior>)
15675
15676Overview:
15677"""""""""
15678
15679The '``llvm.experimental.constrained.minnum``' intrinsic returns the minimum
15680of the two arguments.
15681
15682Arguments:
15683""""""""""
15684
15685The first two arguments and the return value are floating-point numbers
15686of the same type.
15687
15688The third and forth arguments specify the rounding mode and exception
15689behavior as described above.
15690
15691Semantics:
15692""""""""""
15693
15694This function follows the IEEE-754 semantics for minNum. The rounding mode is
15695described, not determined, by the rounding mode argument. The actual rounding
15696mode is determined by the runtime floating-point environment. The rounding
15697mode argument is only intended as information to the compiler.
15698
15699
Cameron McInally9757d5d2018-11-05 15:59:49 +000015700'``llvm.experimental.constrained.ceil``' Intrinsic
15701^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15702
15703Syntax:
15704"""""""
15705
15706::
15707
15708 declare <type>
15709 @llvm.experimental.constrained.ceil(<type> <op1>,
15710 metadata <rounding mode>,
15711 metadata <exception behavior>)
15712
15713Overview:
15714"""""""""
15715
Michael Kruse978ba612018-12-20 04:58:07 +000015716The '``llvm.experimental.constrained.ceil``' intrinsic returns the ceiling of the
Cameron McInally9757d5d2018-11-05 15:59:49 +000015717first operand.
15718
15719Arguments:
15720""""""""""
15721
15722The first argument and the return value are floating-point numbers of the same
15723type.
15724
15725The second and third arguments specify the rounding mode and exception
15726behavior as described above. The rounding mode is currently unused for this
15727intrinsic.
15728
15729Semantics:
15730""""""""""
15731
15732This function returns the same values as the libm ``ceil`` functions
15733would and handles error conditions in the same way.
15734
15735
15736'``llvm.experimental.constrained.floor``' Intrinsic
15737^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15738
15739Syntax:
15740"""""""
15741
15742::
15743
15744 declare <type>
15745 @llvm.experimental.constrained.floor(<type> <op1>,
15746 metadata <rounding mode>,
15747 metadata <exception behavior>)
15748
15749Overview:
15750"""""""""
15751
Michael Kruse978ba612018-12-20 04:58:07 +000015752The '``llvm.experimental.constrained.floor``' intrinsic returns the floor of the
Cameron McInally9757d5d2018-11-05 15:59:49 +000015753first operand.
15754
15755Arguments:
15756""""""""""
15757
15758The first argument and the return value are floating-point numbers of the same
15759type.
15760
15761The second and third arguments specify the rounding mode and exception
15762behavior as described above. The rounding mode is currently unused for this
15763intrinsic.
15764
15765Semantics:
15766""""""""""
15767
15768This function returns the same values as the libm ``floor`` functions
Michael Kruse978ba612018-12-20 04:58:07 +000015769would and handles error conditions in the same way.
Cameron McInally9757d5d2018-11-05 15:59:49 +000015770
15771
15772'``llvm.experimental.constrained.round``' Intrinsic
15773^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15774
15775Syntax:
15776"""""""
15777
15778::
15779
15780 declare <type>
15781 @llvm.experimental.constrained.round(<type> <op1>,
15782 metadata <rounding mode>,
15783 metadata <exception behavior>)
15784
15785Overview:
15786"""""""""
15787
Michael Kruse978ba612018-12-20 04:58:07 +000015788The '``llvm.experimental.constrained.round``' intrinsic returns the first
Cameron McInally9757d5d2018-11-05 15:59:49 +000015789operand rounded to the nearest integer.
15790
15791Arguments:
15792""""""""""
15793
15794The first argument and the return value are floating-point numbers of the same
15795type.
15796
15797The second and third arguments specify the rounding mode and exception
15798behavior as described above. The rounding mode is currently unused for this
15799intrinsic.
15800
15801Semantics:
15802""""""""""
15803
15804This function returns the same values as the libm ``round`` functions
15805would and handles error conditions in the same way.
15806
15807
15808'``llvm.experimental.constrained.trunc``' Intrinsic
15809^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15810
15811Syntax:
15812"""""""
15813
15814::
15815
15816 declare <type>
15817 @llvm.experimental.constrained.trunc(<type> <op1>,
15818 metadata <truncing mode>,
15819 metadata <exception behavior>)
15820
15821Overview:
15822"""""""""
15823
Michael Kruse978ba612018-12-20 04:58:07 +000015824The '``llvm.experimental.constrained.trunc``' intrinsic returns the first
15825operand rounded to the nearest integer not larger in magnitude than the
Cameron McInally9757d5d2018-11-05 15:59:49 +000015826operand.
15827
15828Arguments:
15829""""""""""
15830
15831The first argument and the return value are floating-point numbers of the same
15832type.
15833
15834The second and third arguments specify the truncing mode and exception
15835behavior as described above. The truncing mode is currently unused for this
15836intrinsic.
15837
15838Semantics:
15839""""""""""
15840
15841This function returns the same values as the libm ``trunc`` functions
15842would and handles error conditions in the same way.
15843
15844
Sean Silvab084af42012-12-07 10:36:55 +000015845General Intrinsics
15846------------------
15847
15848This class of intrinsics is designed to be generic and has no specific
15849purpose.
15850
15851'``llvm.var.annotation``' Intrinsic
15852^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15853
15854Syntax:
15855"""""""
15856
15857::
15858
15859 declare void @llvm.var.annotation(i8* <val>, i8* <str>, i8* <str>, i32 <int>)
15860
15861Overview:
15862"""""""""
15863
15864The '``llvm.var.annotation``' intrinsic.
15865
15866Arguments:
15867""""""""""
15868
15869The first argument is a pointer to a value, the second is a pointer to a
15870global string, the third is a pointer to a global string which is the
15871source file name, and the last argument is the line number.
15872
15873Semantics:
15874""""""""""
15875
15876This intrinsic allows annotation of local variables with arbitrary
15877strings. This can be useful for special purpose optimizations that want
15878to look for these annotations. These have no other defined use; they are
15879ignored by code generation and optimization.
15880
Michael Gottesman88d18832013-03-26 00:34:27 +000015881'``llvm.ptr.annotation.*``' Intrinsic
15882^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15883
15884Syntax:
15885"""""""
15886
15887This is an overloaded intrinsic. You can use '``llvm.ptr.annotation``' on a
15888pointer to an integer of any width. *NOTE* you must specify an address space for
15889the pointer. The identifier for the default address space is the integer
15890'``0``'.
15891
15892::
15893
15894 declare i8* @llvm.ptr.annotation.p<address space>i8(i8* <val>, i8* <str>, i8* <str>, i32 <int>)
15895 declare i16* @llvm.ptr.annotation.p<address space>i16(i16* <val>, i8* <str>, i8* <str>, i32 <int>)
15896 declare i32* @llvm.ptr.annotation.p<address space>i32(i32* <val>, i8* <str>, i8* <str>, i32 <int>)
15897 declare i64* @llvm.ptr.annotation.p<address space>i64(i64* <val>, i8* <str>, i8* <str>, i32 <int>)
15898 declare i256* @llvm.ptr.annotation.p<address space>i256(i256* <val>, i8* <str>, i8* <str>, i32 <int>)
15899
15900Overview:
15901"""""""""
15902
15903The '``llvm.ptr.annotation``' intrinsic.
15904
15905Arguments:
15906""""""""""
15907
15908The first argument is a pointer to an integer value of arbitrary bitwidth
15909(result of some expression), the second is a pointer to a global string, the
15910third is a pointer to a global string which is the source file name, and the
15911last argument is the line number. It returns the value of the first argument.
15912
15913Semantics:
15914""""""""""
15915
15916This intrinsic allows annotation of a pointer to an integer with arbitrary
15917strings. This can be useful for special purpose optimizations that want to look
15918for these annotations. These have no other defined use; they are ignored by code
15919generation and optimization.
15920
Sean Silvab084af42012-12-07 10:36:55 +000015921'``llvm.annotation.*``' Intrinsic
15922^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15923
15924Syntax:
15925"""""""
15926
15927This is an overloaded intrinsic. You can use '``llvm.annotation``' on
15928any integer bit width.
15929
15930::
15931
15932 declare i8 @llvm.annotation.i8(i8 <val>, i8* <str>, i8* <str>, i32 <int>)
15933 declare i16 @llvm.annotation.i16(i16 <val>, i8* <str>, i8* <str>, i32 <int>)
15934 declare i32 @llvm.annotation.i32(i32 <val>, i8* <str>, i8* <str>, i32 <int>)
15935 declare i64 @llvm.annotation.i64(i64 <val>, i8* <str>, i8* <str>, i32 <int>)
15936 declare i256 @llvm.annotation.i256(i256 <val>, i8* <str>, i8* <str>, i32 <int>)
15937
15938Overview:
15939"""""""""
15940
15941The '``llvm.annotation``' intrinsic.
15942
15943Arguments:
15944""""""""""
15945
15946The first argument is an integer value (result of some expression), the
15947second is a pointer to a global string, the third is a pointer to a
15948global string which is the source file name, and the last argument is
15949the line number. It returns the value of the first argument.
15950
15951Semantics:
15952""""""""""
15953
15954This intrinsic allows annotations to be put on arbitrary expressions
15955with arbitrary strings. This can be useful for special purpose
15956optimizations that want to look for these annotations. These have no
15957other defined use; they are ignored by code generation and optimization.
15958
Reid Klecknere33c94f2017-09-05 20:14:58 +000015959'``llvm.codeview.annotation``' Intrinsic
Reid Klecknerd4523682017-09-05 20:26:25 +000015960^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Reid Klecknere33c94f2017-09-05 20:14:58 +000015961
15962Syntax:
15963"""""""
15964
15965This annotation emits a label at its program point and an associated
15966``S_ANNOTATION`` codeview record with some additional string metadata. This is
15967used to implement MSVC's ``__annotation`` intrinsic. It is marked
15968``noduplicate``, so calls to this intrinsic prevent inlining and should be
15969considered expensive.
15970
15971::
15972
15973 declare void @llvm.codeview.annotation(metadata)
15974
15975Arguments:
15976""""""""""
15977
15978The argument should be an MDTuple containing any number of MDStrings.
15979
Sean Silvab084af42012-12-07 10:36:55 +000015980'``llvm.trap``' Intrinsic
15981^^^^^^^^^^^^^^^^^^^^^^^^^
15982
15983Syntax:
15984"""""""
15985
15986::
15987
Vedant Kumar808e1572018-11-14 19:53:41 +000015988 declare void @llvm.trap() cold noreturn nounwind
Sean Silvab084af42012-12-07 10:36:55 +000015989
15990Overview:
15991"""""""""
15992
15993The '``llvm.trap``' intrinsic.
15994
15995Arguments:
15996""""""""""
15997
15998None.
15999
16000Semantics:
16001""""""""""
16002
16003This intrinsic is lowered to the target dependent trap instruction. If
16004the target does not have a trap instruction, this intrinsic will be
16005lowered to a call of the ``abort()`` function.
16006
16007'``llvm.debugtrap``' Intrinsic
16008^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16009
16010Syntax:
16011"""""""
16012
16013::
16014
16015 declare void @llvm.debugtrap() nounwind
16016
16017Overview:
16018"""""""""
16019
16020The '``llvm.debugtrap``' intrinsic.
16021
16022Arguments:
16023""""""""""
16024
16025None.
16026
16027Semantics:
16028""""""""""
16029
16030This intrinsic is lowered to code which is intended to cause an
16031execution trap with the intention of requesting the attention of a
16032debugger.
16033
16034'``llvm.stackprotector``' Intrinsic
16035^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16036
16037Syntax:
16038"""""""
16039
16040::
16041
16042 declare void @llvm.stackprotector(i8* <guard>, i8** <slot>)
16043
16044Overview:
16045"""""""""
16046
16047The ``llvm.stackprotector`` intrinsic takes the ``guard`` and stores it
16048onto the stack at ``slot``. The stack slot is adjusted to ensure that it
16049is placed on the stack before local variables.
16050
16051Arguments:
16052""""""""""
16053
16054The ``llvm.stackprotector`` intrinsic requires two pointer arguments.
16055The first argument is the value loaded from the stack guard
16056``@__stack_chk_guard``. The second variable is an ``alloca`` that has
16057enough space to hold the value of the guard.
16058
16059Semantics:
16060""""""""""
16061
Michael Gottesmandafc7d92013-08-12 18:35:32 +000016062This intrinsic causes the prologue/epilogue inserter to force the position of
16063the ``AllocaInst`` stack slot to be before local variables on the stack. This is
16064to ensure that if a local variable on the stack is overwritten, it will destroy
16065the value of the guard. When the function exits, the guard on the stack is
16066checked against the original guard by ``llvm.stackprotectorcheck``. If they are
16067different, then ``llvm.stackprotectorcheck`` causes the program to abort by
16068calling the ``__stack_chk_fail()`` function.
16069
Tim Shene885d5e2016-04-19 19:40:37 +000016070'``llvm.stackguard``' Intrinsic
16071^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16072
16073Syntax:
16074"""""""
16075
16076::
16077
16078 declare i8* @llvm.stackguard()
16079
16080Overview:
16081"""""""""
16082
16083The ``llvm.stackguard`` intrinsic returns the system stack guard value.
16084
16085It should not be generated by frontends, since it is only for internal usage.
16086The reason why we create this intrinsic is that we still support IR form Stack
16087Protector in FastISel.
16088
16089Arguments:
16090""""""""""
16091
16092None.
16093
16094Semantics:
16095""""""""""
16096
16097On some platforms, the value returned by this intrinsic remains unchanged
16098between loads in the same thread. On other platforms, it returns the same
16099global variable value, if any, e.g. ``@__stack_chk_guard``.
16100
16101Currently some platforms have IR-level customized stack guard loading (e.g.
16102X86 Linux) that is not handled by ``llvm.stackguard()``, while they should be
16103in the future.
16104
Sean Silvab084af42012-12-07 10:36:55 +000016105'``llvm.objectsize``' Intrinsic
16106^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16107
16108Syntax:
16109"""""""
16110
16111::
16112
Erik Pilkington600e9de2019-01-30 20:34:35 +000016113 declare i32 @llvm.objectsize.i32(i8* <object>, i1 <min>, i1 <nullunknown>, i1 <dynamic>)
16114 declare i64 @llvm.objectsize.i64(i8* <object>, i1 <min>, i1 <nullunknown>, i1 <dynamic>)
Sean Silvab084af42012-12-07 10:36:55 +000016115
16116Overview:
16117"""""""""
16118
Erik Pilkington600e9de2019-01-30 20:34:35 +000016119The ``llvm.objectsize`` intrinsic is designed to provide information to the
16120optimizer to determine whether a) an operation (like memcpy) will overflow a
16121buffer that corresponds to an object, or b) that a runtime check for overflow
16122isn't necessary. An object in this context means an allocation of a specific
16123class, structure, array, or other object.
Sean Silvab084af42012-12-07 10:36:55 +000016124
16125Arguments:
16126""""""""""
16127
Erik Pilkington600e9de2019-01-30 20:34:35 +000016128The ``llvm.objectsize`` intrinsic takes four arguments. The first argument is a
16129pointer to or into the ``object``. The second argument determines whether
16130``llvm.objectsize`` returns 0 (if true) or -1 (if false) when the object size is
16131unknown. The third argument controls how ``llvm.objectsize`` acts when ``null``
16132in address space 0 is used as its pointer argument. If it's ``false``,
George Burgess IV3fbfa9c42018-07-09 22:21:16 +000016133``llvm.objectsize`` reports 0 bytes available when given ``null``. Otherwise, if
16134the ``null`` is in a non-zero address space or if ``true`` is given for the
Erik Pilkington600e9de2019-01-30 20:34:35 +000016135third argument of ``llvm.objectsize``, we assume its size is unknown. The fourth
16136argument to ``llvm.objectsize`` determines if the value should be evaluated at
16137runtime.
George Burgess IV56c7e882017-03-21 20:08:59 +000016138
Erik Pilkington600e9de2019-01-30 20:34:35 +000016139The second, third, and fourth arguments only accept constants.
Sean Silvab084af42012-12-07 10:36:55 +000016140
16141Semantics:
16142""""""""""
16143
Erik Pilkington600e9de2019-01-30 20:34:35 +000016144The ``llvm.objectsize`` intrinsic is lowered to a value representing the size of
16145the object concerned. If the size cannot be determined, ``llvm.objectsize``
16146returns ``i32/i64 -1 or 0`` (depending on the ``min`` argument).
Sean Silvab084af42012-12-07 10:36:55 +000016147
16148'``llvm.expect``' Intrinsic
16149^^^^^^^^^^^^^^^^^^^^^^^^^^^
16150
16151Syntax:
16152"""""""
16153
Duncan P. N. Exon Smith1ff08e32014-02-02 22:43:55 +000016154This is an overloaded intrinsic. You can use ``llvm.expect`` on any
16155integer bit width.
16156
Sean Silvab084af42012-12-07 10:36:55 +000016157::
16158
Duncan P. N. Exon Smith1ff08e32014-02-02 22:43:55 +000016159 declare i1 @llvm.expect.i1(i1 <val>, i1 <expected_val>)
Sean Silvab084af42012-12-07 10:36:55 +000016160 declare i32 @llvm.expect.i32(i32 <val>, i32 <expected_val>)
16161 declare i64 @llvm.expect.i64(i64 <val>, i64 <expected_val>)
16162
16163Overview:
16164"""""""""
16165
16166The ``llvm.expect`` intrinsic provides information about expected (the
16167most probable) value of ``val``, which can be used by optimizers.
16168
16169Arguments:
16170""""""""""
16171
16172The ``llvm.expect`` intrinsic takes two arguments. The first argument is
Matt Arsenault48730562019-03-17 23:16:18 +000016173a value. The second argument is an expected value.
Sean Silvab084af42012-12-07 10:36:55 +000016174
16175Semantics:
16176""""""""""
16177
16178This intrinsic is lowered to the ``val``.
16179
Philip Reamese0e90832015-04-26 22:23:12 +000016180.. _int_assume:
16181
Hal Finkel93046912014-07-25 21:13:35 +000016182'``llvm.assume``' Intrinsic
16183^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16184
16185Syntax:
16186"""""""
16187
16188::
16189
16190 declare void @llvm.assume(i1 %cond)
16191
16192Overview:
16193"""""""""
16194
16195The ``llvm.assume`` allows the optimizer to assume that the provided
16196condition is true. This information can then be used in simplifying other parts
16197of the code.
16198
16199Arguments:
16200""""""""""
16201
16202The condition which the optimizer may assume is always true.
16203
16204Semantics:
16205""""""""""
16206
16207The intrinsic allows the optimizer to assume that the provided condition is
16208always true whenever the control flow reaches the intrinsic call. No code is
16209generated for this intrinsic, and instructions that contribute only to the
16210provided condition are not used for code generation. If the condition is
16211violated during execution, the behavior is undefined.
16212
Sanjay Patel1ed2bb52015-01-14 16:03:58 +000016213Note that the optimizer might limit the transformations performed on values
Hal Finkel93046912014-07-25 21:13:35 +000016214used by the ``llvm.assume`` intrinsic in order to preserve the instructions
16215only used to form the intrinsic's input argument. This might prove undesirable
Sanjay Patel1ed2bb52015-01-14 16:03:58 +000016216if the extra information provided by the ``llvm.assume`` intrinsic does not cause
Hal Finkel93046912014-07-25 21:13:35 +000016217sufficient overall improvement in code quality. For this reason,
16218``llvm.assume`` should not be used to document basic mathematical invariants
16219that the optimizer can otherwise deduce or facts that are of little use to the
16220optimizer.
16221
Daniel Berlin2c438a32017-02-07 19:29:25 +000016222.. _int_ssa_copy:
16223
16224'``llvm.ssa_copy``' Intrinsic
16225^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16226
16227Syntax:
16228"""""""
16229
16230::
16231
16232 declare type @llvm.ssa_copy(type %operand) returned(1) readnone
16233
16234Arguments:
16235""""""""""
16236
16237The first argument is an operand which is used as the returned value.
16238
16239Overview:
16240""""""""""
16241
16242The ``llvm.ssa_copy`` intrinsic can be used to attach information to
16243operations by copying them and giving them new names. For example,
16244the PredicateInfo utility uses it to build Extended SSA form, and
16245attach various forms of information to operands that dominate specific
16246uses. It is not meant for general use, only for building temporary
16247renaming forms that require value splits at certain points.
16248
Peter Collingbourne7efd7502016-06-24 21:21:32 +000016249.. _type.test:
Peter Collingbournee6909c82015-02-20 20:30:47 +000016250
Peter Collingbourne7efd7502016-06-24 21:21:32 +000016251'``llvm.type.test``' Intrinsic
Peter Collingbournee6909c82015-02-20 20:30:47 +000016252^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16253
16254Syntax:
16255"""""""
16256
16257::
16258
Peter Collingbourne7efd7502016-06-24 21:21:32 +000016259 declare i1 @llvm.type.test(i8* %ptr, metadata %type) nounwind readnone
Peter Collingbournee6909c82015-02-20 20:30:47 +000016260
16261
16262Arguments:
16263""""""""""
16264
16265The first argument is a pointer to be tested. The second argument is a
Peter Collingbourne7efd7502016-06-24 21:21:32 +000016266metadata object representing a :doc:`type identifier <TypeMetadata>`.
Peter Collingbournee6909c82015-02-20 20:30:47 +000016267
16268Overview:
16269"""""""""
16270
Peter Collingbourne7efd7502016-06-24 21:21:32 +000016271The ``llvm.type.test`` intrinsic tests whether the given pointer is associated
16272with the given type identifier.
Peter Collingbournee6909c82015-02-20 20:30:47 +000016273
Peter Collingbourne0312f612016-06-25 00:23:04 +000016274'``llvm.type.checked.load``' Intrinsic
16275^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16276
16277Syntax:
16278"""""""
16279
16280::
16281
16282 declare {i8*, i1} @llvm.type.checked.load(i8* %ptr, i32 %offset, metadata %type) argmemonly nounwind readonly
16283
16284
16285Arguments:
16286""""""""""
16287
16288The first argument is a pointer from which to load a function pointer. The
16289second argument is the byte offset from which to load the function pointer. The
16290third argument is a metadata object representing a :doc:`type identifier
16291<TypeMetadata>`.
16292
16293Overview:
16294"""""""""
16295
16296The ``llvm.type.checked.load`` intrinsic safely loads a function pointer from a
16297virtual table pointer using type metadata. This intrinsic is used to implement
16298control flow integrity in conjunction with virtual call optimization. The
16299virtual call optimization pass will optimize away ``llvm.type.checked.load``
16300intrinsics associated with devirtualized calls, thereby removing the type
16301check in cases where it is not needed to enforce the control flow integrity
16302constraint.
16303
16304If the given pointer is associated with a type metadata identifier, this
16305function returns true as the second element of its return value. (Note that
16306the function may also return true if the given pointer is not associated
16307with a type metadata identifier.) If the function's return value's second
16308element is true, the following rules apply to the first element:
16309
16310- If the given pointer is associated with the given type metadata identifier,
16311 it is the function pointer loaded from the given byte offset from the given
16312 pointer.
16313
16314- If the given pointer is not associated with the given type metadata
16315 identifier, it is one of the following (the choice of which is unspecified):
16316
16317 1. The function pointer that would have been loaded from an arbitrarily chosen
16318 (through an unspecified mechanism) pointer associated with the type
16319 metadata.
16320
16321 2. If the function has a non-void return type, a pointer to a function that
16322 returns an unspecified value without causing side effects.
16323
16324If the function's return value's second element is false, the value of the
16325first element is undefined.
16326
16327
Sean Silvab084af42012-12-07 10:36:55 +000016328'``llvm.donothing``' Intrinsic
16329^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16330
16331Syntax:
16332"""""""
16333
16334::
16335
16336 declare void @llvm.donothing() nounwind readnone
16337
16338Overview:
16339"""""""""
16340
Juergen Ributzkac9161192014-10-23 22:36:13 +000016341The ``llvm.donothing`` intrinsic doesn't perform any operation. It's one of only
Sanjoy Das7a4c94d2016-02-26 03:33:59 +000016342three intrinsics (besides ``llvm.experimental.patchpoint`` and
16343``llvm.experimental.gc.statepoint``) that can be called with an invoke
16344instruction.
Sean Silvab084af42012-12-07 10:36:55 +000016345
16346Arguments:
16347""""""""""
16348
16349None.
16350
16351Semantics:
16352""""""""""
16353
16354This intrinsic does nothing, and it's removed by optimizers and ignored
16355by codegen.
Andrew Trick5e029ce2013-12-24 02:57:25 +000016356
Sanjoy Dasb51325d2016-03-11 19:08:34 +000016357'``llvm.experimental.deoptimize``' Intrinsic
16358^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16359
16360Syntax:
16361"""""""
16362
16363::
16364
16365 declare type @llvm.experimental.deoptimize(...) [ "deopt"(...) ]
16366
16367Overview:
16368"""""""""
16369
16370This intrinsic, together with :ref:`deoptimization operand bundles
16371<deopt_opbundles>`, allow frontends to express transfer of control and
16372frame-local state from the currently executing (typically more specialized,
16373hence faster) version of a function into another (typically more generic, hence
16374slower) version.
16375
16376In languages with a fully integrated managed runtime like Java and JavaScript
16377this intrinsic can be used to implement "uncommon trap" or "side exit" like
16378functionality. In unmanaged languages like C and C++, this intrinsic can be
16379used to represent the slow paths of specialized functions.
16380
16381
16382Arguments:
16383""""""""""
16384
16385The intrinsic takes an arbitrary number of arguments, whose meaning is
16386decided by the :ref:`lowering strategy<deoptimize_lowering>`.
16387
16388Semantics:
16389""""""""""
16390
16391The ``@llvm.experimental.deoptimize`` intrinsic executes an attached
16392deoptimization continuation (denoted using a :ref:`deoptimization
16393operand bundle <deopt_opbundles>`) and returns the value returned by
16394the deoptimization continuation. Defining the semantic properties of
16395the continuation itself is out of scope of the language reference --
16396as far as LLVM is concerned, the deoptimization continuation can
16397invoke arbitrary side effects, including reading from and writing to
16398the entire heap.
16399
16400Deoptimization continuations expressed using ``"deopt"`` operand bundles always
16401continue execution to the end of the physical frame containing them, so all
16402calls to ``@llvm.experimental.deoptimize`` must be in "tail position":
16403
16404 - ``@llvm.experimental.deoptimize`` cannot be invoked.
16405 - The call must immediately precede a :ref:`ret <i_ret>` instruction.
16406 - The ``ret`` instruction must return the value produced by the
16407 ``@llvm.experimental.deoptimize`` call if there is one, or void.
16408
16409Note that the above restrictions imply that the return type for a call to
16410``@llvm.experimental.deoptimize`` will match the return type of its immediate
16411caller.
16412
16413The inliner composes the ``"deopt"`` continuations of the caller into the
16414``"deopt"`` continuations present in the inlinee, and also updates calls to this
16415intrinsic to return directly from the frame of the function it inlined into.
16416
Sanjoy Dase0aa4142016-05-12 01:17:38 +000016417All declarations of ``@llvm.experimental.deoptimize`` must share the
16418same calling convention.
16419
Sanjoy Dasb51325d2016-03-11 19:08:34 +000016420.. _deoptimize_lowering:
16421
16422Lowering:
16423"""""""""
16424
Sanjoy Dasdf9ae702016-03-24 20:23:29 +000016425Calls to ``@llvm.experimental.deoptimize`` are lowered to calls to the
16426symbol ``__llvm_deoptimize`` (it is the frontend's responsibility to
16427ensure that this symbol is defined). The call arguments to
16428``@llvm.experimental.deoptimize`` are lowered as if they were formal
16429arguments of the specified types, and not as varargs.
16430
Sanjoy Dasb51325d2016-03-11 19:08:34 +000016431
Sanjoy Das021de052016-03-31 00:18:46 +000016432'``llvm.experimental.guard``' Intrinsic
16433^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16434
16435Syntax:
16436"""""""
16437
16438::
16439
16440 declare void @llvm.experimental.guard(i1, ...) [ "deopt"(...) ]
16441
16442Overview:
16443"""""""""
16444
16445This intrinsic, together with :ref:`deoptimization operand bundles
16446<deopt_opbundles>`, allows frontends to express guards or checks on
16447optimistic assumptions made during compilation. The semantics of
16448``@llvm.experimental.guard`` is defined in terms of
16449``@llvm.experimental.deoptimize`` -- its body is defined to be
16450equivalent to:
16451
Renato Golin124f2592016-07-20 12:16:38 +000016452.. code-block:: text
Sanjoy Das021de052016-03-31 00:18:46 +000016453
Renato Golin124f2592016-07-20 12:16:38 +000016454 define void @llvm.experimental.guard(i1 %pred, <args...>) {
16455 %realPred = and i1 %pred, undef
16456 br i1 %realPred, label %continue, label %leave [, !make.implicit !{}]
Sanjoy Das021de052016-03-31 00:18:46 +000016457
Renato Golin124f2592016-07-20 12:16:38 +000016458 leave:
16459 call void @llvm.experimental.deoptimize(<args...>) [ "deopt"() ]
16460 ret void
Sanjoy Das021de052016-03-31 00:18:46 +000016461
Renato Golin124f2592016-07-20 12:16:38 +000016462 continue:
16463 ret void
16464 }
Sanjoy Das021de052016-03-31 00:18:46 +000016465
Sanjoy Das47cf2af2016-04-30 00:55:59 +000016466
16467with the optional ``[, !make.implicit !{}]`` present if and only if it
16468is present on the call site. For more details on ``!make.implicit``,
16469see :doc:`FaultMaps`.
16470
Sanjoy Das021de052016-03-31 00:18:46 +000016471In words, ``@llvm.experimental.guard`` executes the attached
16472``"deopt"`` continuation if (but **not** only if) its first argument
16473is ``false``. Since the optimizer is allowed to replace the ``undef``
16474with an arbitrary value, it can optimize guard to fail "spuriously",
16475i.e. without the original condition being false (hence the "not only
16476if"); and this allows for "check widening" type optimizations.
16477
16478``@llvm.experimental.guard`` cannot be invoked.
16479
16480
Max Kazantsevb9e65cb2018-12-07 14:39:46 +000016481'``llvm.experimental.widenable.condition``' Intrinsic
16482^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16483
16484Syntax:
16485"""""""
16486
16487::
16488
16489 declare i1 @llvm.experimental.widenable.condition()
16490
16491Overview:
16492"""""""""
16493
16494This intrinsic represents a "widenable condition" which is
16495boolean expressions with the following property: whether this
16496expression is `true` or `false`, the program is correct and
16497well-defined.
16498
16499Together with :ref:`deoptimization operand bundles <deopt_opbundles>`,
16500``@llvm.experimental.widenable.condition`` allows frontends to
16501express guards or checks on optimistic assumptions made during
16502compilation and represent them as branch instructions on special
16503conditions.
16504
16505While this may appear similar in semantics to `undef`, it is very
16506different in that an invocation produces a particular, singular
16507value. It is also intended to be lowered late, and remain available
16508for specific optimizations and transforms that can benefit from its
16509special properties.
16510
16511Arguments:
16512""""""""""
16513
16514None.
16515
16516Semantics:
16517""""""""""
16518
16519The intrinsic ``@llvm.experimental.widenable.condition()``
16520returns either `true` or `false`. For each evaluation of a call
16521to this intrinsic, the program must be valid and correct both if
16522it returns `true` and if it returns `false`. This allows
16523transformation passes to replace evaluations of this intrinsic
16524with either value whenever one is beneficial.
16525
16526When used in a branch condition, it allows us to choose between
16527two alternative correct solutions for the same problem, like
16528in example below:
16529
16530.. code-block:: text
16531
16532 %cond = call i1 @llvm.experimental.widenable.condition()
16533 br i1 %cond, label %solution_1, label %solution_2
16534
16535 label %fast_path:
16536 ; Apply memory-consuming but fast solution for a task.
16537
16538 label %slow_path:
16539 ; Cheap in memory but slow solution.
16540
16541Whether the result of intrinsic's call is `true` or `false`,
16542it should be correct to pick either solution. We can switch
16543between them by replacing the result of
16544``@llvm.experimental.widenable.condition`` with different
16545`i1` expressions.
16546
16547This is how it can be used to represent guards as widenable branches:
16548
16549.. code-block:: text
16550
16551 block:
16552 ; Unguarded instructions
16553 call void @llvm.experimental.guard(i1 %cond, <args...>) ["deopt"(<deopt_args...>)]
16554 ; Guarded instructions
16555
16556Can be expressed in an alternative equivalent form of explicit branch using
16557``@llvm.experimental.widenable.condition``:
16558
16559.. code-block:: text
16560
16561 block:
16562 ; Unguarded instructions
16563 %widenable_condition = call i1 @llvm.experimental.widenable.condition()
16564 %guard_condition = and i1 %cond, %widenable_condition
16565 br i1 %guard_condition, label %guarded, label %deopt
16566
16567 guarded:
16568 ; Guarded instructions
16569
16570 deopt:
16571 call type @llvm.experimental.deoptimize(<args...>) [ "deopt"(<deopt_args...>) ]
16572
16573So the block `guarded` is only reachable when `%cond` is `true`,
16574and it should be valid to go to the block `deopt` whenever `%cond`
16575is `true` or `false`.
16576
16577``@llvm.experimental.widenable.condition`` will never throw, thus
16578it cannot be invoked.
16579
16580Guard widening:
16581"""""""""""""""
16582
16583When ``@llvm.experimental.widenable.condition()`` is used in
16584condition of a guard represented as explicit branch, it is
16585legal to widen the guard's condition with any additional
16586conditions.
16587
16588Guard widening looks like replacement of
16589
16590.. code-block:: text
16591
16592 %widenable_cond = call i1 @llvm.experimental.widenable.condition()
16593 %guard_cond = and i1 %cond, %widenable_cond
16594 br i1 %guard_cond, label %guarded, label %deopt
16595
16596with
16597
16598.. code-block:: text
16599
16600 %widenable_cond = call i1 @llvm.experimental.widenable.condition()
16601 %new_cond = and i1 %any_other_cond, %widenable_cond
16602 %new_guard_cond = and i1 %cond, %new_cond
16603 br i1 %new_guard_cond, label %guarded, label %deopt
16604
16605for this branch. Here `%any_other_cond` is an arbitrarily chosen
16606well-defined `i1` value. By making guard widening, we may
16607impose stricter conditions on `guarded` block and bail to the
16608deopt when the new condition is not met.
16609
16610Lowering:
16611"""""""""
16612
16613Default lowering strategy is replacing the result of
16614call of ``@llvm.experimental.widenable.condition`` with
16615constant `true`. However it is always correct to replace
16616it with any other `i1` value. Any pass can
16617freely do it if it can benefit from non-default lowering.
16618
16619
Peter Collingbourne7dd8dbf2016-04-22 21:18:02 +000016620'``llvm.load.relative``' Intrinsic
16621^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16622
16623Syntax:
16624"""""""
16625
16626::
16627
16628 declare i8* @llvm.load.relative.iN(i8* %ptr, iN %offset) argmemonly nounwind readonly
16629
16630Overview:
16631"""""""""
16632
16633This intrinsic loads a 32-bit value from the address ``%ptr + %offset``,
16634adds ``%ptr`` to that value and returns it. The constant folder specifically
16635recognizes the form of this intrinsic and the constant initializers it may
16636load from; if a loaded constant initializer is known to have the form
16637``i32 trunc(x - %ptr)``, the intrinsic call is folded to ``x``.
16638
16639LLVM provides that the calculation of such a constant initializer will
16640not overflow at link time under the medium code model if ``x`` is an
16641``unnamed_addr`` function. However, it does not provide this guarantee for
16642a constant initializer folded into a function body. This intrinsic can be
16643used to avoid the possibility of overflows when loading from such a constant.
16644
Dan Gohman2c74fe92017-11-08 21:59:51 +000016645'``llvm.sideeffect``' Intrinsic
16646^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16647
16648Syntax:
16649"""""""
16650
16651::
16652
16653 declare void @llvm.sideeffect() inaccessiblememonly nounwind
16654
16655Overview:
16656"""""""""
16657
16658The ``llvm.sideeffect`` intrinsic doesn't perform any operation. Optimizers
16659treat it as having side effects, so it can be inserted into a loop to
16660indicate that the loop shouldn't be assumed to terminate (which could
16661potentially lead to the loop being optimized away entirely), even if it's
16662an infinite loop with no other side effects.
16663
16664Arguments:
16665""""""""""
16666
16667None.
16668
16669Semantics:
16670""""""""""
16671
16672This intrinsic actually does nothing, but optimizers must assume that it
16673has externally observable side effects.
16674
James Y Knight72f76bf2018-11-07 15:24:12 +000016675'``llvm.is.constant.*``' Intrinsic
16676^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16677
16678Syntax:
16679"""""""
16680
16681This is an overloaded intrinsic. You can use llvm.is.constant with any argument type.
16682
16683::
16684
16685 declare i1 @llvm.is.constant.i32(i32 %operand) nounwind readnone
16686 declare i1 @llvm.is.constant.f32(float %operand) nounwind readnone
16687 declare i1 @llvm.is.constant.TYPENAME(TYPE %operand) nounwind readnone
16688
16689Overview:
16690"""""""""
16691
16692The '``llvm.is.constant``' intrinsic will return true if the argument
16693is known to be a manifest compile-time constant. It is guaranteed to
16694fold to either true or false before generating machine code.
16695
16696Semantics:
16697""""""""""
16698
16699This intrinsic generates no code. If its argument is known to be a
16700manifest compile-time constant value, then the intrinsic will be
16701converted to a constant true value. Otherwise, it will be converted to
16702a constant false value.
16703
16704In particular, note that if the argument is a constant expression
16705which refers to a global (the address of which _is_ a constant, but
16706not manifest during the compile), then the intrinsic evaluates to
16707false.
16708
16709The result also intentionally depends on the result of optimization
16710passes -- e.g., the result can change depending on whether a
16711function gets inlined or not. A function's parameters are
16712obviously not constant. However, a call like
16713``llvm.is.constant.i32(i32 %param)`` *can* return true after the
16714function is inlined, if the value passed to the function parameter was
16715a constant.
16716
16717On the other hand, if constant folding is not run, it will never
16718evaluate to true, even in simple cases.
16719
Andrew Trick5e029ce2013-12-24 02:57:25 +000016720Stack Map Intrinsics
16721--------------------
16722
16723LLVM provides experimental intrinsics to support runtime patching
16724mechanisms commonly desired in dynamic language JITs. These intrinsics
16725are described in :doc:`StackMaps`.
Igor Laevsky4f31e522016-12-29 14:31:07 +000016726
16727Element Wise Atomic Memory Intrinsics
Igor Laevskyfedab152016-12-29 15:08:57 +000016728-------------------------------------
Igor Laevsky4f31e522016-12-29 14:31:07 +000016729
16730These intrinsics are similar to the standard library memory intrinsics except
16731that they perform memory transfer as a sequence of atomic memory accesses.
16732
Daniel Neilson3faabbb2017-06-16 14:43:59 +000016733.. _int_memcpy_element_unordered_atomic:
Igor Laevsky4f31e522016-12-29 14:31:07 +000016734
Daniel Neilson3faabbb2017-06-16 14:43:59 +000016735'``llvm.memcpy.element.unordered.atomic``' Intrinsic
16736^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Igor Laevsky4f31e522016-12-29 14:31:07 +000016737
16738Syntax:
16739"""""""
16740
Daniel Neilson3faabbb2017-06-16 14:43:59 +000016741This is an overloaded intrinsic. You can use ``llvm.memcpy.element.unordered.atomic`` on
Igor Laevsky4f31e522016-12-29 14:31:07 +000016742any integer bit width and for different address spaces. Not all targets
16743support all bit widths however.
16744
16745::
16746
Daniel Neilson3faabbb2017-06-16 14:43:59 +000016747 declare void @llvm.memcpy.element.unordered.atomic.p0i8.p0i8.i32(i8* <dest>,
16748 i8* <src>,
16749 i32 <len>,
16750 i32 <element_size>)
16751 declare void @llvm.memcpy.element.unordered.atomic.p0i8.p0i8.i64(i8* <dest>,
16752 i8* <src>,
16753 i64 <len>,
16754 i32 <element_size>)
Igor Laevsky4f31e522016-12-29 14:31:07 +000016755
16756Overview:
16757"""""""""
16758
Daniel Neilson3faabbb2017-06-16 14:43:59 +000016759The '``llvm.memcpy.element.unordered.atomic.*``' intrinsic is a specialization of the
16760'``llvm.memcpy.*``' intrinsic. It differs in that the ``dest`` and ``src`` are treated
16761as arrays with elements that are exactly ``element_size`` bytes, and the copy between
16762buffers uses a sequence of :ref:`unordered atomic <ordering>` load/store operations
16763that are a positive integer multiple of the ``element_size`` in size.
Igor Laevsky4f31e522016-12-29 14:31:07 +000016764
16765Arguments:
16766""""""""""
16767
Daniel Neilson3faabbb2017-06-16 14:43:59 +000016768The first three arguments are the same as they are in the :ref:`@llvm.memcpy <int_memcpy>`
16769intrinsic, with the added constraint that ``len`` is required to be a positive integer
16770multiple of the ``element_size``. If ``len`` is not a positive integer multiple of
16771``element_size``, then the behaviour of the intrinsic is undefined.
Igor Laevsky4f31e522016-12-29 14:31:07 +000016772
Daniel Neilson3faabbb2017-06-16 14:43:59 +000016773``element_size`` must be a compile-time constant positive power of two no greater than
16774target-specific atomic access size limit.
Igor Laevsky4f31e522016-12-29 14:31:07 +000016775
Daniel Neilson3faabbb2017-06-16 14:43:59 +000016776For each of the input pointers ``align`` parameter attribute must be specified. It
16777must be a power of two no less than the ``element_size``. Caller guarantees that
16778both the source and destination pointers are aligned to that boundary.
Igor Laevsky4f31e522016-12-29 14:31:07 +000016779
16780Semantics:
16781""""""""""
16782
Daniel Neilson3faabbb2017-06-16 14:43:59 +000016783The '``llvm.memcpy.element.unordered.atomic.*``' intrinsic copies ``len`` bytes of
16784memory from the source location to the destination location. These locations are not
16785allowed to overlap. The memory copy is performed as a sequence of load/store operations
16786where each access is guaranteed to be a multiple of ``element_size`` bytes wide and
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +000016787aligned at an ``element_size`` boundary.
Igor Laevsky4f31e522016-12-29 14:31:07 +000016788
16789The order of the copy is unspecified. The same value may be read from the source
16790buffer many times, but only one write is issued to the destination buffer per
Daniel Neilson3faabbb2017-06-16 14:43:59 +000016791element. It is well defined to have concurrent reads and writes to both source and
16792destination provided those reads and writes are unordered atomic when specified.
Igor Laevsky4f31e522016-12-29 14:31:07 +000016793
16794This intrinsic does not provide any additional ordering guarantees over those
16795provided by a set of unordered loads from the source location and stores to the
16796destination.
16797
16798Lowering:
Igor Laevskyfedab152016-12-29 15:08:57 +000016799"""""""""
Igor Laevsky4f31e522016-12-29 14:31:07 +000016800
Daniel Neilson3faabbb2017-06-16 14:43:59 +000016801In the most general case call to the '``llvm.memcpy.element.unordered.atomic.*``' is
16802lowered to a call to the symbol ``__llvm_memcpy_element_unordered_atomic_*``. Where '*'
16803is replaced with an actual element size.
Igor Laevsky4f31e522016-12-29 14:31:07 +000016804
Daniel Neilson57226ef2017-07-12 15:25:26 +000016805Optimizer is allowed to inline memory copy when it's profitable to do so.
16806
16807'``llvm.memmove.element.unordered.atomic``' Intrinsic
16808^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16809
16810Syntax:
16811"""""""
16812
16813This is an overloaded intrinsic. You can use
16814``llvm.memmove.element.unordered.atomic`` on any integer bit width and for
16815different address spaces. Not all targets support all bit widths however.
16816
16817::
16818
16819 declare void @llvm.memmove.element.unordered.atomic.p0i8.p0i8.i32(i8* <dest>,
16820 i8* <src>,
16821 i32 <len>,
16822 i32 <element_size>)
16823 declare void @llvm.memmove.element.unordered.atomic.p0i8.p0i8.i64(i8* <dest>,
16824 i8* <src>,
16825 i64 <len>,
16826 i32 <element_size>)
16827
16828Overview:
16829"""""""""
16830
16831The '``llvm.memmove.element.unordered.atomic.*``' intrinsic is a specialization
16832of the '``llvm.memmove.*``' intrinsic. It differs in that the ``dest`` and
16833``src`` are treated as arrays with elements that are exactly ``element_size``
16834bytes, and the copy between buffers uses a sequence of
16835:ref:`unordered atomic <ordering>` load/store operations that are a positive
16836integer multiple of the ``element_size`` in size.
16837
16838Arguments:
16839""""""""""
16840
16841The first three arguments are the same as they are in the
16842:ref:`@llvm.memmove <int_memmove>` intrinsic, with the added constraint that
16843``len`` is required to be a positive integer multiple of the ``element_size``.
16844If ``len`` is not a positive integer multiple of ``element_size``, then the
16845behaviour of the intrinsic is undefined.
16846
16847``element_size`` must be a compile-time constant positive power of two no
16848greater than a target-specific atomic access size limit.
16849
16850For each of the input pointers the ``align`` parameter attribute must be
16851specified. It must be a power of two no less than the ``element_size``. Caller
16852guarantees that both the source and destination pointers are aligned to that
16853boundary.
16854
16855Semantics:
16856""""""""""
16857
16858The '``llvm.memmove.element.unordered.atomic.*``' intrinsic copies ``len`` bytes
16859of memory from the source location to the destination location. These locations
16860are allowed to overlap. The memory copy is performed as a sequence of load/store
16861operations where each access is guaranteed to be a multiple of ``element_size``
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +000016862bytes wide and aligned at an ``element_size`` boundary.
Daniel Neilson57226ef2017-07-12 15:25:26 +000016863
16864The order of the copy is unspecified. The same value may be read from the source
16865buffer many times, but only one write is issued to the destination buffer per
16866element. It is well defined to have concurrent reads and writes to both source
16867and destination provided those reads and writes are unordered atomic when
16868specified.
16869
16870This intrinsic does not provide any additional ordering guarantees over those
16871provided by a set of unordered loads from the source location and stores to the
16872destination.
16873
16874Lowering:
16875"""""""""
16876
16877In the most general case call to the
16878'``llvm.memmove.element.unordered.atomic.*``' is lowered to a call to the symbol
16879``__llvm_memmove_element_unordered_atomic_*``. Where '*' is replaced with an
16880actual element size.
16881
Daniel Neilson3faabbb2017-06-16 14:43:59 +000016882The optimizer is allowed to inline the memory copy when it's profitable to do so.
Daniel Neilson965613e2017-07-12 21:57:23 +000016883
16884.. _int_memset_element_unordered_atomic:
16885
16886'``llvm.memset.element.unordered.atomic``' Intrinsic
16887^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16888
16889Syntax:
16890"""""""
16891
16892This is an overloaded intrinsic. You can use ``llvm.memset.element.unordered.atomic`` on
16893any integer bit width and for different address spaces. Not all targets
16894support all bit widths however.
16895
16896::
16897
16898 declare void @llvm.memset.element.unordered.atomic.p0i8.i32(i8* <dest>,
16899 i8 <value>,
16900 i32 <len>,
16901 i32 <element_size>)
16902 declare void @llvm.memset.element.unordered.atomic.p0i8.i64(i8* <dest>,
16903 i8 <value>,
16904 i64 <len>,
16905 i32 <element_size>)
16906
16907Overview:
16908"""""""""
16909
16910The '``llvm.memset.element.unordered.atomic.*``' intrinsic is a specialization of the
16911'``llvm.memset.*``' intrinsic. It differs in that the ``dest`` is treated as an array
16912with elements that are exactly ``element_size`` bytes, and the assignment to that array
16913uses uses a sequence of :ref:`unordered atomic <ordering>` store operations
16914that are a positive integer multiple of the ``element_size`` in size.
16915
16916Arguments:
16917""""""""""
16918
16919The first three arguments are the same as they are in the :ref:`@llvm.memset <int_memset>`
16920intrinsic, with the added constraint that ``len`` is required to be a positive integer
16921multiple of the ``element_size``. If ``len`` is not a positive integer multiple of
16922``element_size``, then the behaviour of the intrinsic is undefined.
16923
16924``element_size`` must be a compile-time constant positive power of two no greater than
16925target-specific atomic access size limit.
16926
16927The ``dest`` input pointer must have the ``align`` parameter attribute specified. It
16928must be a power of two no less than the ``element_size``. Caller guarantees that
16929the destination pointer is aligned to that boundary.
16930
16931Semantics:
16932""""""""""
16933
16934The '``llvm.memset.element.unordered.atomic.*``' intrinsic sets the ``len`` bytes of
16935memory starting at the destination location to the given ``value``. The memory is
16936set with a sequence of store operations where each access is guaranteed to be a
Jonas Devlieghereaaecdc42017-11-06 11:47:24 +000016937multiple of ``element_size`` bytes wide and aligned at an ``element_size`` boundary.
Daniel Neilson965613e2017-07-12 21:57:23 +000016938
16939The order of the assignment is unspecified. Only one write is issued to the
16940destination buffer per element. It is well defined to have concurrent reads and
16941writes to the destination provided those reads and writes are unordered atomic
16942when specified.
16943
16944This intrinsic does not provide any additional ordering guarantees over those
16945provided by a set of unordered stores to the destination.
16946
16947Lowering:
16948"""""""""
16949
16950In the most general case call to the '``llvm.memset.element.unordered.atomic.*``' is
16951lowered to a call to the symbol ``__llvm_memset_element_unordered_atomic_*``. Where '*'
16952is replaced with an actual element size.
16953
16954The optimizer is allowed to inline the memory assignment when it's profitable to do so.
Erik Pilkingtonbdad92a2018-12-10 18:19:43 +000016955
16956Objective-C ARC Runtime Intrinsics
16957----------------------------------
16958
16959LLVM provides intrinsics that lower to Objective-C ARC runtime entry points.
16960LLVM is aware of the semantics of these functions, and optimizes based on that
16961knowledge. You can read more about the details of Objective-C ARC `here
16962<https://clang.llvm.org/docs/AutomaticReferenceCounting.html>`_.
16963
16964'``llvm.objc.autorelease``' Intrinsic
16965^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16966
16967Syntax:
16968"""""""
16969::
16970
16971 declare i8* @llvm.objc.autorelease(i8*)
16972
16973Lowering:
16974"""""""""
16975
16976Lowers to a call to `objc_autorelease <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-autorelease>`_.
16977
16978'``llvm.objc.autoreleasePoolPop``' Intrinsic
16979^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16980
16981Syntax:
16982"""""""
16983::
16984
16985 declare void @llvm.objc.autoreleasePoolPop(i8*)
16986
16987Lowering:
16988"""""""""
16989
16990Lowers to a call to `objc_autoreleasePoolPop <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-autoreleasepoolpop-void-pool>`_.
16991
16992'``llvm.objc.autoreleasePoolPush``' Intrinsic
16993^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16994
16995Syntax:
16996"""""""
16997::
16998
16999 declare i8* @llvm.objc.autoreleasePoolPush()
17000
17001Lowering:
17002"""""""""
17003
17004Lowers to a call to `objc_autoreleasePoolPush <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-autoreleasepoolpush-void>`_.
17005
17006'``llvm.objc.autoreleaseReturnValue``' Intrinsic
17007^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17008
17009Syntax:
17010"""""""
17011::
17012
17013 declare i8* @llvm.objc.autoreleaseReturnValue(i8*)
17014
17015Lowering:
17016"""""""""
17017
17018Lowers to a call to `objc_autoreleaseReturnValue <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-autoreleasereturnvalue>`_.
17019
17020'``llvm.objc.copyWeak``' Intrinsic
17021^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17022
17023Syntax:
17024"""""""
17025::
17026
17027 declare void @llvm.objc.copyWeak(i8**, i8**)
17028
17029Lowering:
17030"""""""""
17031
17032Lowers to a call to `objc_copyWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-copyweak-id-dest-id-src>`_.
17033
17034'``llvm.objc.destroyWeak``' Intrinsic
17035^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17036
17037Syntax:
17038"""""""
17039::
17040
17041 declare void @llvm.objc.destroyWeak(i8**)
17042
17043Lowering:
17044"""""""""
17045
17046Lowers to a call to `objc_destroyWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-destroyweak-id-object>`_.
17047
17048'``llvm.objc.initWeak``' Intrinsic
17049^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17050
17051Syntax:
17052"""""""
17053::
17054
17055 declare i8* @llvm.objc.initWeak(i8**, i8*)
17056
17057Lowering:
17058"""""""""
17059
17060Lowers to a call to `objc_initWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-initweak>`_.
17061
17062'``llvm.objc.loadWeak``' Intrinsic
17063^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17064
17065Syntax:
17066"""""""
17067::
17068
17069 declare i8* @llvm.objc.loadWeak(i8**)
17070
17071Lowering:
17072"""""""""
17073
17074Lowers to a call to `objc_loadWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-loadweak>`_.
17075
17076'``llvm.objc.loadWeakRetained``' Intrinsic
17077^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17078
17079Syntax:
17080"""""""
17081::
17082
17083 declare i8* @llvm.objc.loadWeakRetained(i8**)
17084
17085Lowering:
17086"""""""""
17087
17088Lowers to a call to `objc_loadWeakRetained <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-loadweakretained>`_.
17089
17090'``llvm.objc.moveWeak``' Intrinsic
17091^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17092
17093Syntax:
17094"""""""
17095::
17096
17097 declare void @llvm.objc.moveWeak(i8**, i8**)
17098
17099Lowering:
17100"""""""""
17101
17102Lowers to a call to `objc_moveWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-moveweak-id-dest-id-src>`_.
17103
17104'``llvm.objc.release``' Intrinsic
17105^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17106
17107Syntax:
17108"""""""
17109::
17110
17111 declare void @llvm.objc.release(i8*)
17112
17113Lowering:
17114"""""""""
17115
17116Lowers to a call to `objc_release <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-release-id-value>`_.
17117
17118'``llvm.objc.retain``' Intrinsic
17119^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17120
17121Syntax:
17122"""""""
17123::
17124
17125 declare i8* @llvm.objc.retain(i8*)
17126
17127Lowering:
17128"""""""""
17129
17130Lowers to a call to `objc_retain <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retain>`_.
17131
17132'``llvm.objc.retainAutorelease``' Intrinsic
17133^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17134
17135Syntax:
17136"""""""
17137::
17138
17139 declare i8* @llvm.objc.retainAutorelease(i8*)
17140
17141Lowering:
17142"""""""""
17143
17144Lowers to a call to `objc_retainAutorelease <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retainautorelease>`_.
17145
17146'``llvm.objc.retainAutoreleaseReturnValue``' Intrinsic
17147^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17148
17149Syntax:
17150"""""""
17151::
17152
17153 declare i8* @llvm.objc.retainAutoreleaseReturnValue(i8*)
17154
17155Lowering:
17156"""""""""
17157
17158Lowers to a call to `objc_retainAutoreleaseReturnValue <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retainautoreleasereturnvalue>`_.
17159
17160'``llvm.objc.retainAutoreleasedReturnValue``' Intrinsic
17161^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17162
17163Syntax:
17164"""""""
17165::
17166
17167 declare i8* @llvm.objc.retainAutoreleasedReturnValue(i8*)
17168
17169Lowering:
17170"""""""""
17171
17172Lowers to a call to `objc_retainAutoreleasedReturnValue <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retainautoreleasedreturnvalue>`_.
17173
17174'``llvm.objc.retainBlock``' Intrinsic
17175^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17176
17177Syntax:
17178"""""""
17179::
17180
17181 declare i8* @llvm.objc.retainBlock(i8*)
17182
17183Lowering:
17184"""""""""
17185
17186Lowers to a call to `objc_retainBlock <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retainblock>`_.
17187
17188'``llvm.objc.storeStrong``' Intrinsic
17189^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17190
17191Syntax:
17192"""""""
17193::
17194
17195 declare void @llvm.objc.storeStrong(i8**, i8*)
17196
17197Lowering:
17198"""""""""
17199
17200Lowers to a call to `objc_storeStrong <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-storestrong-id-object-id-value>`_.
17201
17202'``llvm.objc.storeWeak``' Intrinsic
17203^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17204
17205Syntax:
17206"""""""
17207::
17208
17209 declare i8* @llvm.objc.storeWeak(i8**, i8*)
17210
17211Lowering:
17212"""""""""
17213
17214Lowers to a call to `objc_storeWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-storeweak>`_.