[IR/AsmWriter] Output escape sequences if the first character isdigit()
[oota-llvm.git] / docs / LangRef.rst
1 ==============================
2 LLVM Language Reference Manual
3 ==============================
4
5 .. contents::
6    :local:
7    :depth: 4
8
9 Abstract
10 ========
11
12 This document is a reference manual for the LLVM assembly language. LLVM
13 is a Static Single Assignment (SSA) based representation that provides
14 type safety, low-level operations, flexibility, and the capability of
15 representing 'all' high-level languages cleanly. It is the common code
16 representation used throughout all phases of the LLVM compilation
17 strategy.
18
19 Introduction
20 ============
21
22 The LLVM code representation is designed to be used in three different
23 forms: 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
25 readable assembly language representation. This allows LLVM to provide a
26 powerful intermediate representation for efficient compiler
27 transformations and analysis, while providing a natural means to debug
28 and visualize the transformations. The three different forms of LLVM are
29 all equivalent. This document describes the human readable
30 representation and notation.
31
32 The LLVM representation aims to be light-weight and low-level while
33 being expressive, typed, and extensible at the same time. It aims to be
34 a "universal IR" of sorts, by being at a low enough level that
35 high-level ideas may be cleanly mapped to it (similar to how
36 microprocessors are "universal IR's", allowing many source languages to
37 be mapped to them). By providing type information, LLVM can be used as
38 the target of optimizations: for example, through pointer analysis, it
39 can be proven that a C automatic variable is never accessed outside of
40 the current function, allowing it to be promoted to a simple SSA value
41 instead of a memory location.
42
43 .. _wellformed:
44
45 Well-Formedness
46 ---------------
47
48 It is important to note that this document describes 'well formed' LLVM
49 assembly language. There is a difference between what the parser accepts
50 and what is considered 'well formed'. For example, the following
51 instruction is syntactically okay, but not well formed:
52
53 .. code-block:: llvm
54
55     %x = add i32 1, %x
56
57 because the definition of ``%x`` does not dominate all of its uses. The
58 LLVM infrastructure provides a verification pass that may be used to
59 verify that an LLVM module is well formed. This pass is automatically
60 run by the parser after parsing input assembly and by the optimizer
61 before it outputs bitcode. The violations pointed out by the verifier
62 pass indicate bugs in transformation passes or input to the parser.
63
64 .. _identifiers:
65
66 Identifiers
67 ===========
68
69 LLVM identifiers come in two basic types: global and local. Global
70 identifiers (functions, global variables) begin with the ``'@'``
71 character. Local identifiers (register names, types) begin with the
72 ``'%'`` character. Additionally, there are three different formats for
73 identifiers, 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
78    '``[%@][-a-zA-Z$._][-a-zA-Z$._0-9]*``'. Identifiers that require other
79    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
82    be used in a name value, even quotes themselves. The ``"\01"`` prefix
83    can be used on global variables to suppress mangling.
84 #. Unnamed values are represented as an unsigned numeric value with
85    their prefix. For example, ``%12``, ``@2``, ``%44``.
86 #. Constants, which are described in the section  Constants_ below.
87
88 LLVM requires that values start with a prefix for two reasons: Compilers
89 don't need to worry about name clashes with reserved words, and the set
90 of reserved words may be expanded in the future without penalty.
91 Additionally, unnamed identifiers allow a compiler to quickly come up
92 with a temporary variable without having to avoid symbol table
93 conflicts.
94
95 Reserved words in LLVM are very similar to reserved words in other
96 languages. 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
99 with variable names, because none of them start with a prefix character
100 (``'%'`` or ``'@'``).
101
102 Here is an example of LLVM code to multiply the integer variable
103 '``%X``' by 8:
104
105 The easy way:
106
107 .. code-block:: llvm
108
109     %result = mul i32 %X, 8
110
111 After strength reduction:
112
113 .. code-block:: llvm
114
115     %result = shl i32 %X, 3
116
117 And the hard way:
118
119 .. code-block:: llvm
120
121     %0 = add i32 %X, %X           ; yields i32:%0
122     %1 = add i32 %0, %0           ; yields i32:%1
123     %result = add i32 %1, %1
124
125 This last way of multiplying ``%X`` by 8 illustrates several important
126 lexical 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.
131 #. Unnamed temporaries are numbered sequentially (using a per-function
132    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.
136
137 It also shows a convention that we follow in this document. When
138 demonstrating instructions, we will follow an instruction with a comment
139 that defines the type and name of value produced.
140
141 High Level Structure
142 ====================
143
144 Module Structure
145 ----------------
146
147 LLVM programs are composed of ``Module``'s, each of which is a
148 translation unit of the input programs. Each module consists of
149 functions, global variables, and symbol table entries. Modules may be
150 combined together with the LLVM linker, which merges function (and
151 global variable) definitions, resolves forward declarations, and merges
152 symbol table entries. Here is an example of the "hello world" module:
153
154 .. code-block:: llvm
155
156     ; Declare the string constant as a global constant.
157     @.str = private unnamed_addr constant [13 x i8] c"hello world\0A\00"
158
159     ; External declaration of the puts function
160     declare i32 @puts(i8* nocapture) nounwind
161
162     ; Definition of main function
163     define i32 @main() {   ; i32()*
164       ; Convert [13 x i8]* to i8  *...
165       %cast210 = getelementptr [13 x i8], [13 x i8]* @.str, i64 0, i64 0
166
167       ; Call puts function to write out the string to stdout.
168       call i32 @puts(i8* %cast210)
169       ret i32 0
170     }
171
172     ; Named metadata
173     !0 = !{i32 42, null, !"string"}
174     !foo = !{!0}
175
176 This 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
181 In general, a module is made up of a list of global values (where both
182 functions and global variables are global values). Global values are
183 represented by a pointer to a memory location (in this case, a pointer
184 to an array of char, and a pointer to a function), and have one of the
185 following :ref:`linkage types <linkage>`.
186
187 .. _linkage:
188
189 Linkage Types
190 -------------
191
192 All Global Variables and Functions have one of the following types of
193 linkage:
194
195 ``private``
196     Global values with "``private``" linkage are only directly
197     accessible by objects in the current module. In particular, linking
198     code into a module with an private global value may cause the
199     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.
202 ``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``
207     Globals with "``available_externally``" linkage are never emitted
208     into the object file corresponding to the LLVM module. They exist to
209     allow inlining and other optimizations to take place given knowledge
210     of the definition of the global, which is known to be somewhere
211     outside the module. Globals with ``available_externally`` linkage
212     are allowed to be discarded at will, and are otherwise the same as
213     ``linkonce_odr``. This linkage type is only allowed on definitions,
214     not declarations.
215 ``linkonce``
216     Globals with "``linkonce``" linkage are merged with other globals of
217     the same name when linkage occurs. This can be used to implement
218     some forms of inline functions, templates, or other code which must
219     be generated in each translation unit that uses it, but where the
220     body may be overridden with a more definitive definition later.
221     Unreferenced ``linkonce`` globals are allowed to be discarded. Note
222     that ``linkonce`` linkage does not actually allow the optimizer to
223     inline the body of this function into callers because it doesn't
224     know if this definition of the function is the definitive definition
225     within the program or whether it will be overridden by a stronger
226     definition. To enable inlining and other optimizations, use
227     "``linkonce_odr``" linkage.
228 ``weak``
229     "``weak``" linkage has the same merging semantics as ``linkonce``
230     linkage, except that unreferenced globals with ``weak`` linkage may
231     not be discarded. This is used for globals that are declared "weak"
232     in C source code.
233 ``common``
234     "``common``" linkage is most similar to "``weak``" linkage, but they
235     are used for tentative definitions in C, such as "``int X;``" at
236     global scope. Symbols with "``common``" linkage are merged in the
237     same way as ``weak symbols``, and they may not be deleted if
238     unreferenced. ``common`` symbols may not have an explicit section,
239     must have a zero initializer, and may not be marked
240     ':ref:`constant <globalvars>`'. Functions and aliases may not have
241     common linkage.
242
243 .. _linkage_appending:
244
245 ``appending``
246     "``appending``" linkage may only be applied to global variables of
247     pointer to array type. When two global variables with appending
248     linkage are linked together, the two global arrays are appended
249     together. This is the LLVM, typesafe, equivalent of having the
250     system linker append together "sections" with identical names when
251     .o files are linked.
252 ``extern_weak``
253     The semantics of this linkage follow the ELF object file model: the
254     symbol is weak until linked, if not linked, the symbol becomes null
255     instead of being an undefined reference.
256 ``linkonce_odr``, ``weak_odr``
257     Some languages allow differing globals to be merged, such as two
258     functions with different semantics. Other languages, such as
259     ``C++``, ensure that only equivalent globals are ever merged (the
260     "one definition rule" --- "ODR").  Such languages can use the
261     ``linkonce_odr`` and ``weak_odr`` linkage types to indicate that the
262     global will only be merged with equivalent globals. These linkage
263     types are otherwise the same as their non-``odr`` versions.
264 ``external``
265     If none of the above identifiers are used, the global is externally
266     visible, meaning that it participates in linkage and can be used to
267     resolve external symbol references.
268
269 It is illegal for a function *declaration* to have any linkage type
270 other than ``external`` or ``extern_weak``.
271
272 .. _callingconv:
273
274 Calling Conventions
275 -------------------
276
277 LLVM :ref:`functions <functionstructure>`, :ref:`calls <i_call>` and
278 :ref:`invokes <i_invoke>` can all have an optional calling convention
279 specified for the call. The calling convention of any pair of dynamic
280 caller/callee must match, or the behavior of the program is undefined.
281 The following calling conventions are supported by LLVM, and more may be
282 added in the future:
283
284 "``ccc``" - The C calling convention
285     This calling convention (the default if no other calling convention
286     is specified) matches the target C calling conventions. This calling
287     convention supports varargs function calls and tolerates some
288     mismatch in the declared prototype and implemented declaration of
289     the function (as does normal C).
290 "``fastcc``" - The fast calling convention
291     This calling convention attempts to make calls as fast as possible
292     (e.g. by passing things in registers). This calling convention
293     allows the target to use whatever tricks it wants to produce fast
294     code for the target, without having to conform to an externally
295     specified ABI (Application Binary Interface). `Tail calls can only
296     be optimized when this, the GHC or the HiPE convention is
297     used. <CodeGenerator.html#id80>`_ This calling convention does not
298     support varargs and requires the prototype of all callees to exactly
299     match the prototype of the function definition.
300 "``coldcc``" - The cold calling convention
301     This calling convention attempts to make code in the caller as
302     efficient as possible under the assumption that the call is not
303     commonly executed. As such, these calls often preserve all registers
304     so that the call does not break any live ranges in the caller side.
305     This calling convention does not support varargs and requires the
306     prototype of all callees to exactly match the prototype of the
307     function definition. Furthermore the inliner doesn't consider such function
308     calls for inlining.
309 "``cc 10``" - GHC convention
310     This calling convention has been implemented specifically for use by
311     the `Glasgow Haskell Compiler (GHC) <http://www.haskell.org/ghc>`_.
312     It passes everything in registers, going to extremes to achieve this
313     by disabling callee save registers. This calling convention should
314     not be used lightly but only for specific situations such as an
315     alternative to the *register pinning* performance technique often
316     used when implementing functional programming languages. At the
317     moment only X86 supports this convention and it has the following
318     limitations:
319
320     -  On *X86-32* only supports up to 4 bit type parameters. No
321        floating point types are supported.
322     -  On *X86-64* only supports up to 10 bit type parameters and 6
323        floating point parameters.
324
325     This calling convention supports `tail call
326     optimization <CodeGenerator.html#id80>`_ but requires both the
327     caller and callee are using it.
328 "``cc 11``" - The HiPE calling convention
329     This calling convention has been implemented specifically for use by
330     the `High-Performance Erlang
331     (HiPE) <http://www.it.uu.se/research/group/hipe/>`_ compiler, *the*
332     native code compiler of the `Ericsson's Open Source Erlang/OTP
333     system <http://www.erlang.org/download.shtml>`_. It uses more
334     registers for argument passing than the ordinary C calling
335     convention and defines no callee-saved registers. The calling
336     convention properly supports `tail call
337     optimization <CodeGenerator.html#id80>`_ but requires that both the
338     caller and the callee use it. It uses a *register pinning*
339     mechanism, similar to GHC's convention, for keeping frequently
340     accessed runtime components pinned to specific hardware registers.
341     At the moment only X86 supports this convention (both 32 and 64
342     bit).
343 "``webkit_jscc``" - WebKit's JavaScript calling convention
344     This calling convention has been implemented for `WebKit FTL JIT
345     <https://trac.webkit.org/wiki/FTLJIT>`_. It passes arguments on the
346     stack right to left (as cdecl does), and returns a value in the
347     platform's customary return register.
348 "``anyregcc``" - Dynamic calling convention for code patching
349     This is a special convention that supports patching an arbitrary code
350     sequence in place of a call site. This convention forces the call
351     arguments into registers but allows them to be dynamically
352     allocated. This can currently only be used with calls to
353     llvm.experimental.patchpoint because only this intrinsic records
354     the location of its arguments in a side table. See :doc:`StackMaps`.
355 "``preserve_mostcc``" - The `PreserveMost` calling convention
356     This calling convention attempts to make the code in the caller as
357     unintrusive as possible. This convention behaves identically to the `C`
358     calling convention on how arguments and return values are passed, but it
359     uses a different set of caller/callee-saved registers. This alleviates the
360     burden of saving and recovering a large register set before and after the
361     call in the caller. If the arguments are passed in callee-saved registers,
362     then they will be preserved by the callee across the call. This doesn't
363     apply for values returned in callee-saved registers.
364
365     - On X86-64 the callee preserves all general purpose registers, except for
366       R11. R11 can be used as a scratch register. Floating-point registers
367       (XMMs/YMMs) are not preserved and need to be saved by the caller.
368
369     The idea behind this convention is to support calls to runtime functions
370     that have a hot path and a cold path. The hot path is usually a small piece
371     of code that doesn't use many registers. The cold path might need to call out to
372     another function and therefore only needs to preserve the caller-saved
373     registers, which haven't already been saved by the caller. The
374     `PreserveMost` calling convention is very similar to the `cold` calling
375     convention in terms of caller/callee-saved registers, but they are used for
376     different types of function calls. `coldcc` is for function calls that are
377     rarely executed, whereas `preserve_mostcc` function calls are intended to be
378     on the hot path and definitely executed a lot. Furthermore `preserve_mostcc`
379     doesn't prevent the inliner from inlining the function call.
380
381     This calling convention will be used by a future version of the ObjectiveC
382     runtime and should therefore still be considered experimental at this time.
383     Although this convention was created to optimize certain runtime calls to
384     the ObjectiveC runtime, it is not limited to this runtime and might be used
385     by other runtimes in the future too. The current implementation only
386     supports X86-64, but the intention is to support more architectures in the
387     future.
388 "``preserve_allcc``" - The `PreserveAll` calling convention
389     This calling convention attempts to make the code in the caller even less
390     intrusive than the `PreserveMost` calling convention. This calling
391     convention also behaves identical to the `C` calling convention on how
392     arguments and return values are passed, but it uses a different set of
393     caller/callee-saved registers. This removes the burden of saving and
394     recovering a large register set before and after the call in the caller. If
395     the arguments are passed in callee-saved registers, then they will be
396     preserved by the callee across the call. This doesn't apply for values
397     returned in callee-saved registers.
398
399     - On X86-64 the callee preserves all general purpose registers, except for
400       R11. R11 can be used as a scratch register. Furthermore it also preserves
401       all floating-point registers (XMMs/YMMs).
402
403     The idea behind this convention is to support calls to runtime functions
404     that don't need to call out to any other functions.
405
406     This calling convention, like the `PreserveMost` calling convention, will be
407     used by a future version of the ObjectiveC runtime and should be considered
408     experimental at this time.
409 "``cc <n>``" - Numbered convention
410     Any calling convention may be specified by number, allowing
411     target-specific calling conventions to be used. Target specific
412     calling conventions start at 64.
413
414 More calling conventions can be added/defined on an as-needed basis, to
415 support Pascal conventions or any other well-known target-independent
416 convention.
417
418 .. _visibilitystyles:
419
420 Visibility Styles
421 -----------------
422
423 All Global Variables and Functions have one of the following visibility
424 styles:
425
426 "``default``" - Default style
427     On targets that use the ELF object file format, default visibility
428     means that the declaration is visible to other modules and, in
429     shared libraries, means that the declared entity may be overridden.
430     On Darwin, default visibility means that the declaration is visible
431     to other modules. Default visibility corresponds to "external
432     linkage" in the language.
433 "``hidden``" - Hidden style
434     Two declarations of an object with hidden visibility refer to the
435     same object if they are in the same shared object. Usually, hidden
436     visibility indicates that the symbol will not be placed into the
437     dynamic symbol table, so no other module (executable or shared
438     library) can reference it directly.
439 "``protected``" - Protected style
440     On ELF, protected visibility indicates that the symbol will be
441     placed in the dynamic symbol table, but that references within the
442     defining module will bind to the local symbol. That is, the symbol
443     cannot be overridden by another module.
444
445 A symbol with ``internal`` or ``private`` linkage must have ``default``
446 visibility.
447
448 .. _dllstorageclass:
449
450 DLL Storage Classes
451 -------------------
452
453 All Global Variables, Functions and Aliases can have one of the following
454 DLL storage class:
455
456 ``dllimport``
457     "``dllimport``" causes the compiler to reference a function or variable via
458     a global pointer to a pointer that is set up by the DLL exporting the
459     symbol. On Microsoft Windows targets, the pointer name is formed by
460     combining ``__imp_`` and the function or variable name.
461 ``dllexport``
462     "``dllexport``" causes the compiler to provide a global pointer to a pointer
463     in a DLL, so that it can be referenced with the ``dllimport`` attribute. On
464     Microsoft Windows targets, the pointer name is formed by combining
465     ``__imp_`` and the function or variable name. Since this storage class
466     exists for defining a dll interface, the compiler, assembler and linker know
467     it is externally referenced and must refrain from deleting the symbol.
468
469 .. _tls_model:
470
471 Thread Local Storage Models
472 ---------------------------
473
474 A variable may be defined as ``thread_local``, which means that it will
475 not be shared by threads (each thread will have a separated copy of the
476 variable). Not all targets support thread-local variables. Optionally, a
477 TLS model may be specified:
478
479 ``localdynamic``
480     For variables that are only used within the current shared library.
481 ``initialexec``
482     For variables in modules that will not be loaded dynamically.
483 ``localexec``
484     For variables defined in the executable and only used within it.
485
486 If no explicit model is given, the "general dynamic" model is used.
487
488 The models correspond to the ELF TLS models; see `ELF Handling For
489 Thread-Local Storage <http://people.redhat.com/drepper/tls.pdf>`_ for
490 more information on under which circumstances the different models may
491 be used. The target may choose a different TLS model if the specified
492 model is not supported, or if a better choice of model can be made.
493
494 A model can also be specified in a alias, but then it only governs how
495 the alias is accessed. It will not have any effect in the aliasee.
496
497 .. _namedtypes:
498
499 Structure Types
500 ---------------
501
502 LLVM IR allows you to specify both "identified" and "literal" :ref:`structure
503 types <t_struct>`.  Literal types are uniqued structurally, but identified types
504 are never uniqued.  An :ref:`opaque structural type <t_opaque>` can also be used
505 to forward declare a type that is not yet available.
506
507 An example of a identified structure specification is:
508
509 .. code-block:: llvm
510
511     %mytype = type { %mytype*, i32 }
512
513 Prior to the LLVM 3.0 release, identified types were structurally uniqued.  Only
514 literal types are uniqued in recent versions of LLVM.
515
516 .. _globalvars:
517
518 Global Variables
519 ----------------
520
521 Global variables define regions of memory allocated at compilation time
522 instead of run-time.
523
524 Global variable definitions must be initialized.
525
526 Global variables in other translation units can also be declared, in which
527 case they don't have an initializer.
528
529 Either global variable definitions or declarations may have an explicit section
530 to be placed in and may have an optional explicit alignment specified.
531
532 A variable may be defined as a global ``constant``, which indicates that
533 the contents of the variable will **never** be modified (enabling better
534 optimization, allowing the global data to be placed in the read-only
535 section of an executable, etc). Note that variables that need runtime
536 initialization cannot be marked ``constant`` as there is a store to the
537 variable.
538
539 LLVM explicitly allows *declarations* of global variables to be marked
540 constant, even if the final definition of the global is not. This
541 capability can be used to enable slightly better optimization of the
542 program, but requires the language definition to guarantee that
543 optimizations based on the 'constantness' are valid for the translation
544 units that do not include the definition.
545
546 As SSA values, global variables define pointer values that are in scope
547 (i.e. they dominate) all basic blocks in the program. Global variables
548 always define a pointer to their "content" type because they describe a
549 region of memory, and all memory objects in LLVM are accessed through
550 pointers.
551
552 Global variables can be marked with ``unnamed_addr`` which indicates
553 that the address is not significant, only the content. Constants marked
554 like this can be merged with other constants if they have the same
555 initializer. Note that a constant with significant address *can* be
556 merged with a ``unnamed_addr`` constant, the result being a constant
557 whose address is significant.
558
559 A global variable may be declared to reside in a target-specific
560 numbered address space. For targets that support them, address spaces
561 may affect how optimizations are performed and/or what target
562 instructions are used to access the variable. The default address space
563 is zero. The address space qualifier must precede any other attributes.
564
565 LLVM allows an explicit section to be specified for globals. If the
566 target supports it, it will emit globals to the section specified.
567 Additionally, the global can placed in a comdat if the target has the necessary
568 support.
569
570 By default, global initializers are optimized by assuming that global
571 variables defined within the module are not modified from their
572 initial values before the start of the global initializer.  This is
573 true even for variables potentially accessible from outside the
574 module, including those with external linkage or appearing in
575 ``@llvm.used`` or dllexported variables. This assumption may be suppressed
576 by marking the variable with ``externally_initialized``.
577
578 An explicit alignment may be specified for a global, which must be a
579 power of 2. If not present, or if the alignment is set to zero, the
580 alignment of the global is set by the target to whatever it feels
581 convenient. If an explicit alignment is specified, the global is forced
582 to have exactly that alignment. Targets and optimizers are not allowed
583 to over-align the global if the global has an assigned section. In this
584 case, the extra alignment could be observable: for example, code could
585 assume that the globals are densely packed in their section and try to
586 iterate over them as an array, alignment padding would break this
587 iteration. The maximum alignment is ``1 << 29``.
588
589 Globals can also have a :ref:`DLL storage class <dllstorageclass>`.
590
591 Variables and aliases can have a
592 :ref:`Thread Local Storage Model <tls_model>`.
593
594 Syntax::
595
596     [@<GlobalVarName> =] [Linkage] [Visibility] [DLLStorageClass] [ThreadLocal]
597                          [unnamed_addr] [AddrSpace] [ExternallyInitialized]
598                          <global | constant> <Type> [<InitializerConstant>]
599                          [, section "name"] [, comdat [($name)]]
600                          [, align <Alignment>]
601
602 For example, the following defines a global in a numbered address space
603 with an initializer, section, and alignment:
604
605 .. code-block:: llvm
606
607     @G = addrspace(5) constant float 1.0, section "foo", align 4
608
609 The following example just declares a global variable
610
611 .. code-block:: llvm
612
613    @G = external global i32
614
615 The following example defines a thread-local global with the
616 ``initialexec`` TLS model:
617
618 .. code-block:: llvm
619
620     @G = thread_local(initialexec) global i32 0, align 4
621
622 .. _functionstructure:
623
624 Functions
625 ---------
626
627 LLVM function definitions consist of the "``define``" keyword, an
628 optional :ref:`linkage type <linkage>`, an optional :ref:`visibility
629 style <visibility>`, an optional :ref:`DLL storage class <dllstorageclass>`,
630 an optional :ref:`calling convention <callingconv>`,
631 an optional ``unnamed_addr`` attribute, a return type, an optional
632 :ref:`parameter attribute <paramattrs>` for the return type, a function
633 name, a (possibly empty) argument list (each with optional :ref:`parameter
634 attributes <paramattrs>`), optional :ref:`function attributes <fnattrs>`,
635 an optional section, an optional alignment,
636 an optional :ref:`comdat <langref_comdats>`,
637 an optional :ref:`garbage collector name <gc>`, an optional :ref:`prefix <prefixdata>`,
638 an optional :ref:`prologue <prologuedata>`, an opening
639 curly brace, a list of basic blocks, and a closing curly brace.
640
641 LLVM function declarations consist of the "``declare``" keyword, an
642 optional :ref:`linkage type <linkage>`, an optional :ref:`visibility
643 style <visibility>`, an optional :ref:`DLL storage class <dllstorageclass>`,
644 an optional :ref:`calling convention <callingconv>`,
645 an optional ``unnamed_addr`` attribute, a return type, an optional
646 :ref:`parameter attribute <paramattrs>` for the return type, a function
647 name, a possibly empty list of arguments, an optional alignment, an optional
648 :ref:`garbage collector name <gc>`, an optional :ref:`prefix <prefixdata>`,
649 and an optional :ref:`prologue <prologuedata>`.
650
651 A function definition contains a list of basic blocks, forming the CFG (Control
652 Flow Graph) for the function. Each basic block may optionally start with a label
653 (giving the basic block a symbol table entry), contains a list of instructions,
654 and ends with a :ref:`terminator <terminators>` instruction (such as a branch or
655 function return). If an explicit label is not provided, a block is assigned an
656 implicit numbered label, using the next value from the same counter as used for
657 unnamed temporaries (:ref:`see above<identifiers>`). For example, if a function
658 entry block does not have an explicit label, it will be assigned label "%0",
659 then the first unnamed temporary in that block will be "%1", etc.
660
661 The first basic block in a function is special in two ways: it is
662 immediately executed on entrance to the function, and it is not allowed
663 to have predecessor basic blocks (i.e. there can not be any branches to
664 the entry block of a function). Because the block can have no
665 predecessors, it also cannot have any :ref:`PHI nodes <i_phi>`.
666
667 LLVM allows an explicit section to be specified for functions. If the
668 target supports it, it will emit functions to the section specified.
669 Additionally, the function can be placed in a COMDAT.
670
671 An explicit alignment may be specified for a function. If not present,
672 or if the alignment is set to zero, the alignment of the function is set
673 by the target to whatever it feels convenient. If an explicit alignment
674 is specified, the function is forced to have at least that much
675 alignment. All alignments must be a power of 2.
676
677 If the ``unnamed_addr`` attribute is given, the address is known to not
678 be significant and two identical functions can be merged.
679
680 Syntax::
681
682     define [linkage] [visibility] [DLLStorageClass]
683            [cconv] [ret attrs]
684            <ResultType> @<FunctionName> ([argument list])
685            [unnamed_addr] [fn Attrs] [section "name"] [comdat [($name)]]
686            [align N] [gc] [prefix Constant] [prologue Constant] { ... }
687
688 The argument list is a comma seperated sequence of arguments where each
689 argument is of the following form
690
691 Syntax::
692
693    <type> [parameter Attrs] [name]
694
695
696 .. _langref_aliases:
697
698 Aliases
699 -------
700
701 Aliases, unlike function or variables, don't create any new data. They
702 are just a new symbol and metadata for an existing position.
703
704 Aliases have a name and an aliasee that is either a global value or a
705 constant expression.
706
707 Aliases may have an optional :ref:`linkage type <linkage>`, an optional
708 :ref:`visibility style <visibility>`, an optional :ref:`DLL storage class
709 <dllstorageclass>` and an optional :ref:`tls model <tls_model>`.
710
711 Syntax::
712
713     @<Name> = [Linkage] [Visibility] [DLLStorageClass] [ThreadLocal] [unnamed_addr] alias <AliaseeTy> @<Aliasee>
714
715 The linkage must be one of ``private``, ``internal``, ``linkonce``, ``weak``,
716 ``linkonce_odr``, ``weak_odr``, ``external``. Note that some system linkers
717 might not correctly handle dropping a weak symbol that is aliased.
718
719 Aliases that are not ``unnamed_addr`` are guaranteed to have the same address as
720 the aliasee expression. ``unnamed_addr`` ones are only guaranteed to point
721 to the same content.
722
723 Since aliases are only a second name, some restrictions apply, of which
724 some can only be checked when producing an object file:
725
726 * The expression defining the aliasee must be computable at assembly
727   time. Since it is just a name, no relocations can be used.
728
729 * No alias in the expression can be weak as the possibility of the
730   intermediate alias being overridden cannot be represented in an
731   object file.
732
733 * No global value in the expression can be a declaration, since that
734   would require a relocation, which is not possible.
735
736 .. _langref_comdats:
737
738 Comdats
739 -------
740
741 Comdat IR provides access to COFF and ELF object file COMDAT functionality.
742
743 Comdats have a name which represents the COMDAT key.  All global objects that
744 specify this key will only end up in the final object file if the linker chooses
745 that key over some other key.  Aliases are placed in the same COMDAT that their
746 aliasee computes to, if any.
747
748 Comdats have a selection kind to provide input on how the linker should
749 choose between keys in two different object files.
750
751 Syntax::
752
753     $<Name> = comdat SelectionKind
754
755 The selection kind must be one of the following:
756
757 ``any``
758     The linker may choose any COMDAT key, the choice is arbitrary.
759 ``exactmatch``
760     The linker may choose any COMDAT key but the sections must contain the
761     same data.
762 ``largest``
763     The linker will choose the section containing the largest COMDAT key.
764 ``noduplicates``
765     The linker requires that only section with this COMDAT key exist.
766 ``samesize``
767     The linker may choose any COMDAT key but the sections must contain the
768     same amount of data.
769
770 Note that the Mach-O platform doesn't support COMDATs and ELF only supports
771 ``any`` as a selection kind.
772
773 Here is an example of a COMDAT group where a function will only be selected if
774 the COMDAT key's section is the largest:
775
776 .. code-block:: llvm
777
778    $foo = comdat largest
779    @foo = global i32 2, comdat($foo)
780
781    define void @bar() comdat($foo) {
782      ret void
783    }
784
785 As a syntactic sugar the ``$name`` can be omitted if the name is the same as
786 the global name:
787
788 .. code-block:: llvm
789
790   $foo = comdat any
791   @foo = global i32 2, comdat
792
793
794 In a COFF object file, this will create a COMDAT section with selection kind
795 ``IMAGE_COMDAT_SELECT_LARGEST`` containing the contents of the ``@foo`` symbol
796 and another COMDAT section with selection kind
797 ``IMAGE_COMDAT_SELECT_ASSOCIATIVE`` which is associated with the first COMDAT
798 section and contains the contents of the ``@bar`` symbol.
799
800 There are some restrictions on the properties of the global object.
801 It, or an alias to it, must have the same name as the COMDAT group when
802 targeting COFF.
803 The contents and size of this object may be used during link-time to determine
804 which COMDAT groups get selected depending on the selection kind.
805 Because the name of the object must match the name of the COMDAT group, the
806 linkage of the global object must not be local; local symbols can get renamed
807 if a collision occurs in the symbol table.
808
809 The combined use of COMDATS and section attributes may yield surprising results.
810 For example:
811
812 .. code-block:: llvm
813
814    $foo = comdat any
815    $bar = comdat any
816    @g1 = global i32 42, section "sec", comdat($foo)
817    @g2 = global i32 42, section "sec", comdat($bar)
818
819 From the object file perspective, this requires the creation of two sections
820 with the same name.  This is necessary because both globals belong to different
821 COMDAT groups and COMDATs, at the object file level, are represented by
822 sections.
823
824 Note that certain IR constructs like global variables and functions may create
825 COMDATs in the object file in addition to any which are specified using COMDAT
826 IR.  This arises, for example, when a global variable has linkonce_odr linkage.
827
828 .. _namedmetadatastructure:
829
830 Named Metadata
831 --------------
832
833 Named metadata is a collection of metadata. :ref:`Metadata
834 nodes <metadata>` (but not metadata strings) are the only valid
835 operands for a named metadata.
836
837 #. Named metadata are represented as a string of characters with the
838    metadata prefix. The rules for metadata names are the same as for
839    identifiers, but quoted names are not allowed. ``"\xx"`` type escapes
840    are still valid, which allows any character to be part of a name.
841
842 Syntax::
843
844     ; Some unnamed metadata nodes, which are referenced by the named metadata.
845     !0 = !{!"zero"}
846     !1 = !{!"one"}
847     !2 = !{!"two"}
848     ; A named metadata.
849     !name = !{!0, !1, !2}
850
851 .. _paramattrs:
852
853 Parameter Attributes
854 --------------------
855
856 The return type and each parameter of a function type may have a set of
857 *parameter attributes* associated with them. Parameter attributes are
858 used to communicate additional information about the result or
859 parameters of a function. Parameter attributes are considered to be part
860 of the function, not of the function type, so functions with different
861 parameter attributes can have the same function type.
862
863 Parameter attributes are simple keywords that follow the type specified.
864 If multiple parameter attributes are needed, they are space separated.
865 For example:
866
867 .. code-block:: llvm
868
869     declare i32 @printf(i8* noalias nocapture, ...)
870     declare i32 @atoi(i8 zeroext)
871     declare signext i8 @returns_signed_char()
872
873 Note that any attributes for the function result (``nounwind``,
874 ``readonly``) come immediately after the argument list.
875
876 Currently, only the following parameter attributes are defined:
877
878 ``zeroext``
879     This indicates to the code generator that the parameter or return
880     value should be zero-extended to the extent required by the target's
881     ABI (which is usually 32-bits, but is 8-bits for a i1 on x86-64) by
882     the caller (for a parameter) or the callee (for a return value).
883 ``signext``
884     This indicates to the code generator that the parameter or return
885     value should be sign-extended to the extent required by the target's
886     ABI (which is usually 32-bits) by the caller (for a parameter) or
887     the callee (for a return value).
888 ``inreg``
889     This indicates that this parameter or return value should be treated
890     in a special target-dependent fashion during while emitting code for
891     a function call or return (usually, by putting it in a register as
892     opposed to memory, though some targets use it to distinguish between
893     two different kinds of registers). Use of this attribute is
894     target-specific.
895 ``byval``
896     This indicates that the pointer parameter should really be passed by
897     value to the function. The attribute implies that a hidden copy of
898     the pointee is made between the caller and the callee, so the callee
899     is unable to modify the value in the caller. This attribute is only
900     valid on LLVM pointer arguments. It is generally used to pass
901     structs and arrays by value, but is also valid on pointers to
902     scalars. The copy is considered to belong to the caller not the
903     callee (for example, ``readonly`` functions should not write to
904     ``byval`` parameters). This is not a valid attribute for return
905     values.
906
907     The byval attribute also supports specifying an alignment with the
908     align attribute. It indicates the alignment of the stack slot to
909     form and the known alignment of the pointer specified to the call
910     site. If the alignment is not specified, then the code generator
911     makes a target-specific assumption.
912
913 .. _attr_inalloca:
914
915 ``inalloca``
916
917     The ``inalloca`` argument attribute allows the caller to take the
918     address of outgoing stack arguments.  An ``inalloca`` argument must
919     be a pointer to stack memory produced by an ``alloca`` instruction.
920     The alloca, or argument allocation, must also be tagged with the
921     inalloca keyword.  Only the last argument may have the ``inalloca``
922     attribute, and that argument is guaranteed to be passed in memory.
923
924     An argument allocation may be used by a call at most once because
925     the call may deallocate it.  The ``inalloca`` attribute cannot be
926     used in conjunction with other attributes that affect argument
927     storage, like ``inreg``, ``nest``, ``sret``, or ``byval``.  The
928     ``inalloca`` attribute also disables LLVM's implicit lowering of
929     large aggregate return values, which means that frontend authors
930     must lower them with ``sret`` pointers.
931
932     When the call site is reached, the argument allocation must have
933     been the most recent stack allocation that is still live, or the
934     results are undefined.  It is possible to allocate additional stack
935     space after an argument allocation and before its call site, but it
936     must be cleared off with :ref:`llvm.stackrestore
937     <int_stackrestore>`.
938
939     See :doc:`InAlloca` for more information on how to use this
940     attribute.
941
942 ``sret``
943     This indicates that the pointer parameter specifies the address of a
944     structure that is the return value of the function in the source
945     program. This pointer must be guaranteed by the caller to be valid:
946     loads and stores to the structure may be assumed by the callee
947     not to trap and to be properly aligned. This may only be applied to
948     the first parameter. This is not a valid attribute for return
949     values.
950
951 ``align <n>``
952     This indicates that the pointer value may be assumed by the optimizer to
953     have the specified alignment.
954
955     Note that this attribute has additional semantics when combined with the
956     ``byval`` attribute.
957
958 .. _noalias:
959
960 ``noalias``
961     This indicates that objects accessed via pointer values
962     :ref:`based <pointeraliasing>` on the argument or return value are not also
963     accessed, during the execution of the function, via pointer values not
964     *based* on the argument or return value. The attribute on a return value
965     also has additional semantics described below. The caller shares the
966     responsibility with the callee for ensuring that these requirements are met.
967     For further details, please see the discussion of the NoAlias response in
968     :ref:`alias analysis <Must, May, or No>`.
969
970     Note that this definition of ``noalias`` is intentionally similar
971     to the definition of ``restrict`` in C99 for function arguments.
972
973     For function return values, C99's ``restrict`` is not meaningful,
974     while LLVM's ``noalias`` is. Furthermore, the semantics of the ``noalias``
975     attribute on return values are stronger than the semantics of the attribute
976     when used on function arguments. On function return values, the ``noalias``
977     attribute indicates that the function acts like a system memory allocation
978     function, returning a pointer to allocated storage disjoint from the
979     storage for any other object accessible to the caller.
980
981 ``nocapture``
982     This indicates that the callee does not make any copies of the
983     pointer that outlive the callee itself. This is not a valid
984     attribute for return values.
985
986 .. _nest:
987
988 ``nest``
989     This indicates that the pointer parameter can be excised using the
990     :ref:`trampoline intrinsics <int_trampoline>`. This is not a valid
991     attribute for return values and can only be applied to one parameter.
992
993 ``returned``
994     This indicates that the function always returns the argument as its return
995     value. This is an optimization hint to the code generator when generating
996     the caller, allowing tail call optimization and omission of register saves
997     and restores in some cases; it is not checked or enforced when generating
998     the callee. The parameter and the function return type must be valid
999     operands for the :ref:`bitcast instruction <i_bitcast>`. This is not a
1000     valid attribute for return values and can only be applied to one parameter.
1001
1002 ``nonnull``
1003     This indicates that the parameter or return pointer is not null. This
1004     attribute may only be applied to pointer typed parameters. This is not
1005     checked or enforced by LLVM, the caller must ensure that the pointer
1006     passed in is non-null, or the callee must ensure that the returned pointer
1007     is non-null.
1008
1009 ``dereferenceable(<n>)``
1010     This indicates that the parameter or return pointer is dereferenceable. This
1011     attribute may only be applied to pointer typed parameters. A pointer that
1012     is dereferenceable can be loaded from speculatively without a risk of
1013     trapping. The number of bytes known to be dereferenceable must be provided
1014     in parentheses. It is legal for the number of bytes to be less than the
1015     size of the pointee type. The ``nonnull`` attribute does not imply
1016     dereferenceability (consider a pointer to one element past the end of an
1017     array), however ``dereferenceable(<n>)`` does imply ``nonnull`` in
1018     ``addrspace(0)`` (which is the default address space).
1019
1020 ``dereferenceable_or_null(<n>)``
1021     This indicates that the parameter or return value isn't both
1022     non-null and non-dereferenceable (up to ``<n>`` bytes) at the same
1023     time.  All non-null pointers tagged with
1024     ``dereferenceable_or_null(<n>)`` are ``dereferenceable(<n>)``.
1025     For address space 0 ``dereferenceable_or_null(<n>)`` implies that
1026     a pointer is exactly one of ``dereferenceable(<n>)`` or ``null``,
1027     and in other address spaces ``dereferenceable_or_null(<n>)``
1028     implies that a pointer is at least one of ``dereferenceable(<n>)``
1029     or ``null`` (i.e. it may be both ``null`` and
1030     ``dereferenceable(<n>)``).  This attribute may only be applied to
1031     pointer typed parameters.
1032
1033 .. _gc:
1034
1035 Garbage Collector Strategy Names
1036 --------------------------------
1037
1038 Each function may specify a garbage collector strategy name, which is simply a
1039 string:
1040
1041 .. code-block:: llvm
1042
1043     define void @f() gc "name" { ... }
1044
1045 The supported values of *name* includes those :ref:`built in to LLVM
1046 <builtin-gc-strategies>` and any provided by loaded plugins.  Specifying a GC
1047 strategy will cause the compiler to alter its output in order to support the
1048 named garbage collection algorithm.  Note that LLVM itself does not contain a
1049 garbage collector, this functionality is restricted to generating machine code
1050 which can interoperate with a collector provided externally.
1051
1052 .. _prefixdata:
1053
1054 Prefix Data
1055 -----------
1056
1057 Prefix data is data associated with a function which the code
1058 generator will emit immediately before the function's entrypoint.
1059 The purpose of this feature is to allow frontends to associate
1060 language-specific runtime metadata with specific functions and make it
1061 available through the function pointer while still allowing the
1062 function pointer to be called.
1063
1064 To access the data for a given function, a program may bitcast the
1065 function pointer to a pointer to the constant's type and dereference
1066 index -1.  This implies that the IR symbol points just past the end of
1067 the prefix data. For instance, take the example of a function annotated
1068 with a single ``i32``,
1069
1070 .. code-block:: llvm
1071
1072     define void @f() prefix i32 123 { ... }
1073
1074 The prefix data can be referenced as,
1075
1076 .. code-block:: llvm
1077
1078     %0 = bitcast void* () @f to i32*
1079     %a = getelementptr inbounds i32, i32* %0, i32 -1
1080     %b = load i32, i32* %a
1081
1082 Prefix data is laid out as if it were an initializer for a global variable
1083 of the prefix data's type.  The function will be placed such that the
1084 beginning of the prefix data is aligned. This means that if the size
1085 of the prefix data is not a multiple of the alignment size, the
1086 function's entrypoint will not be aligned. If alignment of the
1087 function's entrypoint is desired, padding must be added to the prefix
1088 data.
1089
1090 A function may have prefix data but no body.  This has similar semantics
1091 to the ``available_externally`` linkage in that the data may be used by the
1092 optimizers but will not be emitted in the object file.
1093
1094 .. _prologuedata:
1095
1096 Prologue Data
1097 -------------
1098
1099 The ``prologue`` attribute allows arbitrary code (encoded as bytes) to
1100 be inserted prior to the function body. This can be used for enabling
1101 function hot-patching and instrumentation.
1102
1103 To maintain the semantics of ordinary function calls, the prologue data must
1104 have a particular format.  Specifically, it must begin with a sequence of
1105 bytes which decode to a sequence of machine instructions, valid for the
1106 module's target, which transfer control to the point immediately succeeding
1107 the prologue data, without performing any other visible action.  This allows
1108 the inliner and other passes to reason about the semantics of the function
1109 definition without needing to reason about the prologue data.  Obviously this
1110 makes the format of the prologue data highly target dependent.
1111
1112 A trivial example of valid prologue data for the x86 architecture is ``i8 144``,
1113 which encodes the ``nop`` instruction:
1114
1115 .. code-block:: llvm
1116
1117     define void @f() prologue i8 144 { ... }
1118
1119 Generally prologue data can be formed by encoding a relative branch instruction
1120 which skips the metadata, as in this example of valid prologue data for the
1121 x86_64 architecture, where the first two bytes encode ``jmp .+10``:
1122
1123 .. code-block:: llvm
1124
1125     %0 = type <{ i8, i8, i8* }>
1126
1127     define void @f() prologue %0 <{ i8 235, i8 8, i8* @md}> { ... }
1128
1129 A function may have prologue data but no body.  This has similar semantics
1130 to the ``available_externally`` linkage in that the data may be used by the
1131 optimizers but will not be emitted in the object file.
1132
1133 .. _attrgrp:
1134
1135 Attribute Groups
1136 ----------------
1137
1138 Attribute groups are groups of attributes that are referenced by objects within
1139 the IR. They are important for keeping ``.ll`` files readable, because a lot of
1140 functions will use the same set of attributes. In the degenerative case of a
1141 ``.ll`` file that corresponds to a single ``.c`` file, the single attribute
1142 group will capture the important command line flags used to build that file.
1143
1144 An attribute group is a module-level object. To use an attribute group, an
1145 object references the attribute group's ID (e.g. ``#37``). An object may refer
1146 to more than one attribute group. In that situation, the attributes from the
1147 different groups are merged.
1148
1149 Here is an example of attribute groups for a function that should always be
1150 inlined, has a stack alignment of 4, and which shouldn't use SSE instructions:
1151
1152 .. code-block:: llvm
1153
1154    ; Target-independent attributes:
1155    attributes #0 = { alwaysinline alignstack=4 }
1156
1157    ; Target-dependent attributes:
1158    attributes #1 = { "no-sse" }
1159
1160    ; Function @f has attributes: alwaysinline, alignstack=4, and "no-sse".
1161    define void @f() #0 #1 { ... }
1162
1163 .. _fnattrs:
1164
1165 Function Attributes
1166 -------------------
1167
1168 Function attributes are set to communicate additional information about
1169 a function. Function attributes are considered to be part of the
1170 function, not of the function type, so functions with different function
1171 attributes can have the same function type.
1172
1173 Function attributes are simple keywords that follow the type specified.
1174 If multiple attributes are needed, they are space separated. For
1175 example:
1176
1177 .. code-block:: llvm
1178
1179     define void @f() noinline { ... }
1180     define void @f() alwaysinline { ... }
1181     define void @f() alwaysinline optsize { ... }
1182     define void @f() optsize { ... }
1183
1184 ``alignstack(<n>)``
1185     This attribute indicates that, when emitting the prologue and
1186     epilogue, the backend should forcibly align the stack pointer.
1187     Specify the desired alignment, which must be a power of two, in
1188     parentheses.
1189 ``alwaysinline``
1190     This attribute indicates that the inliner should attempt to inline
1191     this function into callers whenever possible, ignoring any active
1192     inlining size threshold for this caller.
1193 ``builtin``
1194     This indicates that the callee function at a call site should be
1195     recognized as a built-in function, even though the function's declaration
1196     uses the ``nobuiltin`` attribute. This is only valid at call sites for
1197     direct calls to functions that are declared with the ``nobuiltin``
1198     attribute.
1199 ``cold``
1200     This attribute indicates that this function is rarely called. When
1201     computing edge weights, basic blocks post-dominated by a cold
1202     function call are also considered to be cold; and, thus, given low
1203     weight.
1204 ``convergent``
1205     This attribute indicates that the callee is dependent on a convergent
1206     thread execution pattern under certain parallel execution models.
1207     Transformations that are execution model agnostic may only move or
1208     tranform this call if the final location is control equivalent to its
1209     original position in the program, where control equivalence is defined as
1210     A dominates B and B post-dominates A, or vice versa.
1211 ``inlinehint``
1212     This attribute indicates that the source code contained a hint that
1213     inlining this function is desirable (such as the "inline" keyword in
1214     C/C++). It is just a hint; it imposes no requirements on the
1215     inliner.
1216 ``jumptable``
1217     This attribute indicates that the function should be added to a
1218     jump-instruction table at code-generation time, and that all address-taken
1219     references to this function should be replaced with a reference to the
1220     appropriate jump-instruction-table function pointer. Note that this creates
1221     a new pointer for the original function, which means that code that depends
1222     on function-pointer identity can break. So, any function annotated with
1223     ``jumptable`` must also be ``unnamed_addr``.
1224 ``minsize``
1225     This attribute suggests that optimization passes and code generator
1226     passes make choices that keep the code size of this function as small
1227     as possible and perform optimizations that may sacrifice runtime
1228     performance in order to minimize the size of the generated code.
1229 ``naked``
1230     This attribute disables prologue / epilogue emission for the
1231     function. This can have very system-specific consequences.
1232 ``nobuiltin``
1233     This indicates that the callee function at a call site is not recognized as
1234     a built-in function. LLVM will retain the original call and not replace it
1235     with equivalent code based on the semantics of the built-in function, unless
1236     the call site uses the ``builtin`` attribute. This is valid at call sites
1237     and on function declarations and definitions.
1238 ``noduplicate``
1239     This attribute indicates that calls to the function cannot be
1240     duplicated. A call to a ``noduplicate`` function may be moved
1241     within its parent function, but may not be duplicated within
1242     its parent function.
1243
1244     A function containing a ``noduplicate`` call may still
1245     be an inlining candidate, provided that the call is not
1246     duplicated by inlining. That implies that the function has
1247     internal linkage and only has one call site, so the original
1248     call is dead after inlining.
1249 ``noimplicitfloat``
1250     This attributes disables implicit floating point instructions.
1251 ``noinline``
1252     This attribute indicates that the inliner should never inline this
1253     function in any situation. This attribute may not be used together
1254     with the ``alwaysinline`` attribute.
1255 ``nonlazybind``
1256     This attribute suppresses lazy symbol binding for the function. This
1257     may make calls to the function faster, at the cost of extra program
1258     startup time if the function is not called during program startup.
1259 ``noredzone``
1260     This attribute indicates that the code generator should not use a
1261     red zone, even if the target-specific ABI normally permits it.
1262 ``noreturn``
1263     This function attribute indicates that the function never returns
1264     normally. This produces undefined behavior at runtime if the
1265     function ever does dynamically return.
1266 ``nounwind``
1267     This function attribute indicates that the function never raises an
1268     exception. If the function does raise an exception, its runtime
1269     behavior is undefined. However, functions marked nounwind may still
1270     trap or generate asynchronous exceptions. Exception handling schemes
1271     that are recognized by LLVM to handle asynchronous exceptions, such
1272     as SEH, will still provide their implementation defined semantics.
1273 ``optnone``
1274     This function attribute indicates that the function is not optimized
1275     by any optimization or code generator passes with the
1276     exception of interprocedural optimization passes.
1277     This attribute cannot be used together with the ``alwaysinline``
1278     attribute; this attribute is also incompatible
1279     with the ``minsize`` attribute and the ``optsize`` attribute.
1280
1281     This attribute requires the ``noinline`` attribute to be specified on
1282     the function as well, so the function is never inlined into any caller.
1283     Only functions with the ``alwaysinline`` attribute are valid
1284     candidates for inlining into the body of this function.
1285 ``optsize``
1286     This attribute suggests that optimization passes and code generator
1287     passes make choices that keep the code size of this function low,
1288     and otherwise do optimizations specifically to reduce code size as
1289     long as they do not significantly impact runtime performance.
1290 ``readnone``
1291     On a function, this attribute indicates that the function computes its
1292     result (or decides to unwind an exception) based strictly on its arguments,
1293     without dereferencing any pointer arguments or otherwise accessing
1294     any mutable state (e.g. memory, control registers, etc) visible to
1295     caller functions. It does not write through any pointer arguments
1296     (including ``byval`` arguments) and never changes any state visible
1297     to callers. This means that it cannot unwind exceptions by calling
1298     the ``C++`` exception throwing methods.
1299
1300     On an argument, this attribute indicates that the function does not
1301     dereference that pointer argument, even though it may read or write the
1302     memory that the pointer points to if accessed through other pointers.
1303 ``readonly``
1304     On a function, this attribute indicates that the function does not write
1305     through any pointer arguments (including ``byval`` arguments) or otherwise
1306     modify any state (e.g. memory, control registers, etc) visible to
1307     caller functions. It may dereference pointer arguments and read
1308     state that may be set in the caller. A readonly function always
1309     returns the same value (or unwinds an exception identically) when
1310     called with the same set of arguments and global state. It cannot
1311     unwind an exception by calling the ``C++`` exception throwing
1312     methods.
1313
1314     On an argument, this attribute indicates that the function does not write
1315     through this pointer argument, even though it may write to the memory that
1316     the pointer points to.
1317 ``returns_twice``
1318     This attribute indicates that this function can return twice. The C
1319     ``setjmp`` is an example of such a function. The compiler disables
1320     some optimizations (like tail calls) in the caller of these
1321     functions.
1322 ``sanitize_address``
1323     This attribute indicates that AddressSanitizer checks
1324     (dynamic address safety analysis) are enabled for this function.
1325 ``sanitize_memory``
1326     This attribute indicates that MemorySanitizer checks (dynamic detection
1327     of accesses to uninitialized memory) are enabled for this function.
1328 ``sanitize_thread``
1329     This attribute indicates that ThreadSanitizer checks
1330     (dynamic thread safety analysis) are enabled for this function.
1331 ``ssp``
1332     This attribute indicates that the function should emit a stack
1333     smashing protector. It is in the form of a "canary" --- a random value
1334     placed on the stack before the local variables that's checked upon
1335     return from the function to see if it has been overwritten. A
1336     heuristic is used to determine if a function needs stack protectors
1337     or not. The heuristic used will enable protectors for functions with:
1338
1339     - Character arrays larger than ``ssp-buffer-size`` (default 8).
1340     - Aggregates containing character arrays larger than ``ssp-buffer-size``.
1341     - Calls to alloca() with variable sizes or constant sizes greater than
1342       ``ssp-buffer-size``.
1343
1344     Variables that are identified as requiring a protector will be arranged
1345     on the stack such that they are adjacent to the stack protector guard.
1346
1347     If a function that has an ``ssp`` attribute is inlined into a
1348     function that doesn't have an ``ssp`` attribute, then the resulting
1349     function will have an ``ssp`` attribute.
1350 ``sspreq``
1351     This attribute indicates that the function should *always* emit a
1352     stack smashing protector. This overrides the ``ssp`` function
1353     attribute.
1354
1355     Variables that are identified as requiring a protector will be arranged
1356     on the stack such that they are adjacent to the stack protector guard.
1357     The specific layout rules are:
1358
1359     #. Large arrays and structures containing large arrays
1360        (``>= ssp-buffer-size``) are closest to the stack protector.
1361     #. Small arrays and structures containing small arrays
1362        (``< ssp-buffer-size``) are 2nd closest to the protector.
1363     #. Variables that have had their address taken are 3rd closest to the
1364        protector.
1365
1366     If a function that has an ``sspreq`` attribute is inlined into a
1367     function that doesn't have an ``sspreq`` attribute or which has an
1368     ``ssp`` or ``sspstrong`` attribute, then the resulting function will have
1369     an ``sspreq`` attribute.
1370 ``sspstrong``
1371     This attribute indicates that the function should emit a stack smashing
1372     protector. This attribute causes a strong heuristic to be used when
1373     determining if a function needs stack protectors.  The strong heuristic
1374     will enable protectors for functions with:
1375
1376     - Arrays of any size and type
1377     - Aggregates containing an array of any size and type.
1378     - Calls to alloca().
1379     - Local variables that have had their address taken.
1380
1381     Variables that are identified as requiring a protector will be arranged
1382     on the stack such that they are adjacent to the stack protector guard.
1383     The specific layout rules are:
1384
1385     #. Large arrays and structures containing large arrays
1386        (``>= ssp-buffer-size``) are closest to the stack protector.
1387     #. Small arrays and structures containing small arrays
1388        (``< ssp-buffer-size``) are 2nd closest to the protector.
1389     #. Variables that have had their address taken are 3rd closest to the
1390        protector.
1391
1392     This overrides the ``ssp`` function attribute.
1393
1394     If a function that has an ``sspstrong`` attribute is inlined into a
1395     function that doesn't have an ``sspstrong`` attribute, then the
1396     resulting function will have an ``sspstrong`` attribute.
1397 ``"thunk"``
1398     This attribute indicates that the function will delegate to some other
1399     function with a tail call. The prototype of a thunk should not be used for
1400     optimization purposes. The caller is expected to cast the thunk prototype to
1401     match the thunk target prototype.
1402 ``uwtable``
1403     This attribute indicates that the ABI being targeted requires that
1404     an unwind table entry be produce for this function even if we can
1405     show that no exceptions passes by it. This is normally the case for
1406     the ELF x86-64 abi, but it can be disabled for some compilation
1407     units.
1408
1409 .. _moduleasm:
1410
1411 Module-Level Inline Assembly
1412 ----------------------------
1413
1414 Modules may contain "module-level inline asm" blocks, which corresponds
1415 to the GCC "file scope inline asm" blocks. These blocks are internally
1416 concatenated by LLVM and treated as a single unit, but may be separated
1417 in the ``.ll`` file if desired. The syntax is very simple:
1418
1419 .. code-block:: llvm
1420
1421     module asm "inline asm code goes here"
1422     module asm "more can go here"
1423
1424 The strings can contain any character by escaping non-printable
1425 characters. The escape sequence used is simply "\\xx" where "xx" is the
1426 two digit hex code for the number.
1427
1428 The inline asm code is simply printed to the machine code .s file when
1429 assembly code is generated.
1430
1431 .. _langref_datalayout:
1432
1433 Data Layout
1434 -----------
1435
1436 A module may specify a target specific data layout string that specifies
1437 how data is to be laid out in memory. The syntax for the data layout is
1438 simply:
1439
1440 .. code-block:: llvm
1441
1442     target datalayout = "layout specification"
1443
1444 The *layout specification* consists of a list of specifications
1445 separated by the minus sign character ('-'). Each specification starts
1446 with a letter and may include other information after the letter to
1447 define some aspect of the data layout. The specifications accepted are
1448 as follows:
1449
1450 ``E``
1451     Specifies that the target lays out data in big-endian form. That is,
1452     the bits with the most significance have the lowest address
1453     location.
1454 ``e``
1455     Specifies that the target lays out data in little-endian form. That
1456     is, the bits with the least significance have the lowest address
1457     location.
1458 ``S<size>``
1459     Specifies the natural alignment of the stack in bits. Alignment
1460     promotion of stack variables is limited to the natural stack
1461     alignment to avoid dynamic stack realignment. The stack alignment
1462     must be a multiple of 8-bits. If omitted, the natural stack
1463     alignment defaults to "unspecified", which does not prevent any
1464     alignment promotions.
1465 ``p[n]:<size>:<abi>:<pref>``
1466     This specifies the *size* of a pointer and its ``<abi>`` and
1467     ``<pref>``\erred alignments for address space ``n``. All sizes are in
1468     bits. The address space, ``n`` is optional, and if not specified,
1469     denotes the default address space 0.  The value of ``n`` must be
1470     in the range [1,2^23).
1471 ``i<size>:<abi>:<pref>``
1472     This specifies the alignment for an integer type of a given bit
1473     ``<size>``. The value of ``<size>`` must be in the range [1,2^23).
1474 ``v<size>:<abi>:<pref>``
1475     This specifies the alignment for a vector type of a given bit
1476     ``<size>``.
1477 ``f<size>:<abi>:<pref>``
1478     This specifies the alignment for a floating point type of a given bit
1479     ``<size>``. Only values of ``<size>`` that are supported by the target
1480     will work. 32 (float) and 64 (double) are supported on all targets; 80
1481     or 128 (different flavors of long double) are also supported on some
1482     targets.
1483 ``a:<abi>:<pref>``
1484     This specifies the alignment for an object of aggregate type.
1485 ``m:<mangling>``
1486     If present, specifies that llvm names are mangled in the output. The
1487     options are
1488
1489     * ``e``: ELF mangling: Private symbols get a ``.L`` prefix.
1490     * ``m``: Mips mangling: Private symbols get a ``$`` prefix.
1491     * ``o``: Mach-O mangling: Private symbols get ``L`` prefix. Other
1492       symbols get a ``_`` prefix.
1493     * ``w``: Windows COFF prefix:  Similar to Mach-O, but stdcall and fastcall
1494       functions also get a suffix based on the frame size.
1495 ``n<size1>:<size2>:<size3>...``
1496     This specifies a set of native integer widths for the target CPU in
1497     bits. For example, it might contain ``n32`` for 32-bit PowerPC,
1498     ``n32:64`` for PowerPC 64, or ``n8:16:32:64`` for X86-64. Elements of
1499     this set are considered to support most general arithmetic operations
1500     efficiently.
1501
1502 On every specification that takes a ``<abi>:<pref>``, specifying the
1503 ``<pref>`` alignment is optional. If omitted, the preceding ``:``
1504 should be omitted too and ``<pref>`` will be equal to ``<abi>``.
1505
1506 When constructing the data layout for a given target, LLVM starts with a
1507 default set of specifications which are then (possibly) overridden by
1508 the specifications in the ``datalayout`` keyword. The default
1509 specifications are given in this list:
1510
1511 -  ``E`` - big endian
1512 -  ``p:64:64:64`` - 64-bit pointers with 64-bit alignment.
1513 -  ``p[n]:64:64:64`` - Other address spaces are assumed to be the
1514    same as the default address space.
1515 -  ``S0`` - natural stack alignment is unspecified
1516 -  ``i1:8:8`` - i1 is 8-bit (byte) aligned
1517 -  ``i8:8:8`` - i8 is 8-bit (byte) aligned
1518 -  ``i16:16:16`` - i16 is 16-bit aligned
1519 -  ``i32:32:32`` - i32 is 32-bit aligned
1520 -  ``i64:32:64`` - i64 has ABI alignment of 32-bits but preferred
1521    alignment of 64-bits
1522 -  ``f16:16:16`` - half is 16-bit aligned
1523 -  ``f32:32:32`` - float is 32-bit aligned
1524 -  ``f64:64:64`` - double is 64-bit aligned
1525 -  ``f128:128:128`` - quad is 128-bit aligned
1526 -  ``v64:64:64`` - 64-bit vector is 64-bit aligned
1527 -  ``v128:128:128`` - 128-bit vector is 128-bit aligned
1528 -  ``a:0:64`` - aggregates are 64-bit aligned
1529
1530 When LLVM is determining the alignment for a given type, it uses the
1531 following rules:
1532
1533 #. If the type sought is an exact match for one of the specifications,
1534    that specification is used.
1535 #. If no match is found, and the type sought is an integer type, then
1536    the smallest integer type that is larger than the bitwidth of the
1537    sought type is used. If none of the specifications are larger than
1538    the bitwidth then the largest integer type is used. For example,
1539    given the default specifications above, the i7 type will use the
1540    alignment of i8 (next largest) while both i65 and i256 will use the
1541    alignment of i64 (largest specified).
1542 #. If no match is found, and the type sought is a vector type, then the
1543    largest vector type that is smaller than the sought vector type will
1544    be used as a fall back. This happens because <128 x double> can be
1545    implemented in terms of 64 <2 x double>, for example.
1546
1547 The function of the data layout string may not be what you expect.
1548 Notably, this is not a specification from the frontend of what alignment
1549 the code generator should use.
1550
1551 Instead, if specified, the target data layout is required to match what
1552 the ultimate *code generator* expects. This string is used by the
1553 mid-level optimizers to improve code, and this only works if it matches
1554 what the ultimate code generator uses. There is no way to generate IR
1555 that does not embed this target-specific detail into the IR. If you
1556 don't specify the string, the default specifications will be used to
1557 generate a Data Layout and the optimization phases will operate
1558 accordingly and introduce target specificity into the IR with respect to
1559 these default specifications.
1560
1561 .. _langref_triple:
1562
1563 Target Triple
1564 -------------
1565
1566 A module may specify a target triple string that describes the target
1567 host. The syntax for the target triple is simply:
1568
1569 .. code-block:: llvm
1570
1571     target triple = "x86_64-apple-macosx10.7.0"
1572
1573 The *target triple* string consists of a series of identifiers delimited
1574 by the minus sign character ('-'). The canonical forms are:
1575
1576 ::
1577
1578     ARCHITECTURE-VENDOR-OPERATING_SYSTEM
1579     ARCHITECTURE-VENDOR-OPERATING_SYSTEM-ENVIRONMENT
1580
1581 This information is passed along to the backend so that it generates
1582 code for the proper architecture. It's possible to override this on the
1583 command line with the ``-mtriple`` command line option.
1584
1585 .. _pointeraliasing:
1586
1587 Pointer Aliasing Rules
1588 ----------------------
1589
1590 Any memory access must be done through a pointer value associated with
1591 an address range of the memory access, otherwise the behavior is
1592 undefined. Pointer values are associated with address ranges according
1593 to the following rules:
1594
1595 -  A pointer value is associated with the addresses associated with any
1596    value it is *based* on.
1597 -  An address of a global variable is associated with the address range
1598    of the variable's storage.
1599 -  The result value of an allocation instruction is associated with the
1600    address range of the allocated storage.
1601 -  A null pointer in the default address-space is associated with no
1602    address.
1603 -  An integer constant other than zero or a pointer value returned from
1604    a function not defined within LLVM may be associated with address
1605    ranges allocated through mechanisms other than those provided by
1606    LLVM. Such ranges shall not overlap with any ranges of addresses
1607    allocated by mechanisms provided by LLVM.
1608
1609 A pointer value is *based* on another pointer value according to the
1610 following rules:
1611
1612 -  A pointer value formed from a ``getelementptr`` operation is *based*
1613    on the first value operand of the ``getelementptr``.
1614 -  The result value of a ``bitcast`` is *based* on the operand of the
1615    ``bitcast``.
1616 -  A pointer value formed by an ``inttoptr`` is *based* on all pointer
1617    values that contribute (directly or indirectly) to the computation of
1618    the pointer's value.
1619 -  The "*based* on" relationship is transitive.
1620
1621 Note that this definition of *"based"* is intentionally similar to the
1622 definition of *"based"* in C99, though it is slightly weaker.
1623
1624 LLVM IR does not associate types with memory. The result type of a
1625 ``load`` merely indicates the size and alignment of the memory from
1626 which to load, as well as the interpretation of the value. The first
1627 operand type of a ``store`` similarly only indicates the size and
1628 alignment of the store.
1629
1630 Consequently, type-based alias analysis, aka TBAA, aka
1631 ``-fstrict-aliasing``, is not applicable to general unadorned LLVM IR.
1632 :ref:`Metadata <metadata>` may be used to encode additional information
1633 which specialized optimization passes may use to implement type-based
1634 alias analysis.
1635
1636 .. _volatile:
1637
1638 Volatile Memory Accesses
1639 ------------------------
1640
1641 Certain memory accesses, such as :ref:`load <i_load>`'s,
1642 :ref:`store <i_store>`'s, and :ref:`llvm.memcpy <int_memcpy>`'s may be
1643 marked ``volatile``. The optimizers must not change the number of
1644 volatile operations or change their order of execution relative to other
1645 volatile operations. The optimizers *may* change the order of volatile
1646 operations relative to non-volatile operations. This is not Java's
1647 "volatile" and has no cross-thread synchronization behavior.
1648
1649 IR-level volatile loads and stores cannot safely be optimized into
1650 llvm.memcpy or llvm.memmove intrinsics even when those intrinsics are
1651 flagged volatile. Likewise, the backend should never split or merge
1652 target-legal volatile load/store instructions.
1653
1654 .. admonition:: Rationale
1655
1656  Platforms may rely on volatile loads and stores of natively supported
1657  data width to be executed as single instruction. For example, in C
1658  this holds for an l-value of volatile primitive type with native
1659  hardware support, but not necessarily for aggregate types. The
1660  frontend upholds these expectations, which are intentionally
1661  unspecified in the IR. The rules above ensure that IR transformation
1662  do not violate the frontend's contract with the language.
1663
1664 .. _memmodel:
1665
1666 Memory Model for Concurrent Operations
1667 --------------------------------------
1668
1669 The LLVM IR does not define any way to start parallel threads of
1670 execution or to register signal handlers. Nonetheless, there are
1671 platform-specific ways to create them, and we define LLVM IR's behavior
1672 in their presence. This model is inspired by the C++0x memory model.
1673
1674 For a more informal introduction to this model, see the :doc:`Atomics`.
1675
1676 We define a *happens-before* partial order as the least partial order
1677 that
1678
1679 -  Is a superset of single-thread program order, and
1680 -  When a *synchronizes-with* ``b``, includes an edge from ``a`` to
1681    ``b``. *Synchronizes-with* pairs are introduced by platform-specific
1682    techniques, like pthread locks, thread creation, thread joining,
1683    etc., and by atomic instructions. (See also :ref:`Atomic Memory Ordering
1684    Constraints <ordering>`).
1685
1686 Note that program order does not introduce *happens-before* edges
1687 between a thread and signals executing inside that thread.
1688
1689 Every (defined) read operation (load instructions, memcpy, atomic
1690 loads/read-modify-writes, etc.) R reads a series of bytes written by
1691 (defined) write operations (store instructions, atomic
1692 stores/read-modify-writes, memcpy, etc.). For the purposes of this
1693 section, initialized globals are considered to have a write of the
1694 initializer which is atomic and happens before any other read or write
1695 of the memory in question. For each byte of a read R, R\ :sub:`byte`
1696 may see any write to the same byte, except:
1697
1698 -  If write\ :sub:`1`  happens before write\ :sub:`2`, and
1699    write\ :sub:`2` happens before R\ :sub:`byte`, then
1700    R\ :sub:`byte` does not see write\ :sub:`1`.
1701 -  If R\ :sub:`byte` happens before write\ :sub:`3`, then
1702    R\ :sub:`byte` does not see write\ :sub:`3`.
1703
1704 Given that definition, R\ :sub:`byte` is defined as follows:
1705
1706 -  If R is volatile, the result is target-dependent. (Volatile is
1707    supposed to give guarantees which can support ``sig_atomic_t`` in
1708    C/C++, and may be used for accesses to addresses that do not behave
1709    like normal memory. It does not generally provide cross-thread
1710    synchronization.)
1711 -  Otherwise, if there is no write to the same byte that happens before
1712    R\ :sub:`byte`, R\ :sub:`byte` returns ``undef`` for that byte.
1713 -  Otherwise, if R\ :sub:`byte` may see exactly one write,
1714    R\ :sub:`byte` returns the value written by that write.
1715 -  Otherwise, if R is atomic, and all the writes R\ :sub:`byte` may
1716    see are atomic, it chooses one of the values written. See the :ref:`Atomic
1717    Memory Ordering Constraints <ordering>` section for additional
1718    constraints on how the choice is made.
1719 -  Otherwise R\ :sub:`byte` returns ``undef``.
1720
1721 R returns the value composed of the series of bytes it read. This
1722 implies that some bytes within the value may be ``undef`` **without**
1723 the entire value being ``undef``. Note that this only defines the
1724 semantics of the operation; it doesn't mean that targets will emit more
1725 than one instruction to read the series of bytes.
1726
1727 Note that in cases where none of the atomic intrinsics are used, this
1728 model places only one restriction on IR transformations on top of what
1729 is required for single-threaded execution: introducing a store to a byte
1730 which might not otherwise be stored is not allowed in general.
1731 (Specifically, in the case where another thread might write to and read
1732 from an address, introducing a store can change a load that may see
1733 exactly one write into a load that may see multiple writes.)
1734
1735 .. _ordering:
1736
1737 Atomic Memory Ordering Constraints
1738 ----------------------------------
1739
1740 Atomic instructions (:ref:`cmpxchg <i_cmpxchg>`,
1741 :ref:`atomicrmw <i_atomicrmw>`, :ref:`fence <i_fence>`,
1742 :ref:`atomic load <i_load>`, and :ref:`atomic store <i_store>`) take
1743 ordering parameters that determine which other atomic instructions on
1744 the same address they *synchronize with*. These semantics are borrowed
1745 from Java and C++0x, but are somewhat more colloquial. If these
1746 descriptions aren't precise enough, check those specs (see spec
1747 references in the :doc:`atomics guide <Atomics>`).
1748 :ref:`fence <i_fence>` instructions treat these orderings somewhat
1749 differently since they don't take an address. See that instruction's
1750 documentation for details.
1751
1752 For a simpler introduction to the ordering constraints, see the
1753 :doc:`Atomics`.
1754
1755 ``unordered``
1756     The set of values that can be read is governed by the happens-before
1757     partial order. A value cannot be read unless some operation wrote
1758     it. This is intended to provide a guarantee strong enough to model
1759     Java's non-volatile shared variables. This ordering cannot be
1760     specified for read-modify-write operations; it is not strong enough
1761     to make them atomic in any interesting way.
1762 ``monotonic``
1763     In addition to the guarantees of ``unordered``, there is a single
1764     total order for modifications by ``monotonic`` operations on each
1765     address. All modification orders must be compatible with the
1766     happens-before order. There is no guarantee that the modification
1767     orders can be combined to a global total order for the whole program
1768     (and this often will not be possible). The read in an atomic
1769     read-modify-write operation (:ref:`cmpxchg <i_cmpxchg>` and
1770     :ref:`atomicrmw <i_atomicrmw>`) reads the value in the modification
1771     order immediately before the value it writes. If one atomic read
1772     happens before another atomic read of the same address, the later
1773     read must see the same value or a later value in the address's
1774     modification order. This disallows reordering of ``monotonic`` (or
1775     stronger) operations on the same address. If an address is written
1776     ``monotonic``-ally by one thread, and other threads ``monotonic``-ally
1777     read that address repeatedly, the other threads must eventually see
1778     the write. This corresponds to the C++0x/C1x
1779     ``memory_order_relaxed``.
1780 ``acquire``
1781     In addition to the guarantees of ``monotonic``, a
1782     *synchronizes-with* edge may be formed with a ``release`` operation.
1783     This is intended to model C++'s ``memory_order_acquire``.
1784 ``release``
1785     In addition to the guarantees of ``monotonic``, if this operation
1786     writes a value which is subsequently read by an ``acquire``
1787     operation, it *synchronizes-with* that operation. (This isn't a
1788     complete description; see the C++0x definition of a release
1789     sequence.) This corresponds to the C++0x/C1x
1790     ``memory_order_release``.
1791 ``acq_rel`` (acquire+release)
1792     Acts as both an ``acquire`` and ``release`` operation on its
1793     address. This corresponds to the C++0x/C1x ``memory_order_acq_rel``.
1794 ``seq_cst`` (sequentially consistent)
1795     In addition to the guarantees of ``acq_rel`` (``acquire`` for an
1796     operation that only reads, ``release`` for an operation that only
1797     writes), there is a global total order on all
1798     sequentially-consistent operations on all addresses, which is
1799     consistent with the *happens-before* partial order and with the
1800     modification orders of all the affected addresses. Each
1801     sequentially-consistent read sees the last preceding write to the
1802     same address in this global order. This corresponds to the C++0x/C1x
1803     ``memory_order_seq_cst`` and Java volatile.
1804
1805 .. _singlethread:
1806
1807 If an atomic operation is marked ``singlethread``, it only *synchronizes
1808 with* or participates in modification and seq\_cst total orderings with
1809 other operations running in the same thread (for example, in signal
1810 handlers).
1811
1812 .. _fastmath:
1813
1814 Fast-Math Flags
1815 ---------------
1816
1817 LLVM IR floating-point binary ops (:ref:`fadd <i_fadd>`,
1818 :ref:`fsub <i_fsub>`, :ref:`fmul <i_fmul>`, :ref:`fdiv <i_fdiv>`,
1819 :ref:`frem <i_frem>`) have the following flags that can be set to enable
1820 otherwise unsafe floating point operations
1821
1822 ``nnan``
1823    No NaNs - Allow optimizations to assume the arguments and result are not
1824    NaN. Such optimizations are required to retain defined behavior over
1825    NaNs, but the value of the result is undefined.
1826
1827 ``ninf``
1828    No Infs - Allow optimizations to assume the arguments and result are not
1829    +/-Inf. Such optimizations are required to retain defined behavior over
1830    +/-Inf, but the value of the result is undefined.
1831
1832 ``nsz``
1833    No Signed Zeros - Allow optimizations to treat the sign of a zero
1834    argument or result as insignificant.
1835
1836 ``arcp``
1837    Allow Reciprocal - Allow optimizations to use the reciprocal of an
1838    argument rather than perform division.
1839
1840 ``fast``
1841    Fast - Allow algebraically equivalent transformations that may
1842    dramatically change results in floating point (e.g. reassociate). This
1843    flag implies all the others.
1844
1845 .. _uselistorder:
1846
1847 Use-list Order Directives
1848 -------------------------
1849
1850 Use-list directives encode the in-memory order of each use-list, allowing the
1851 order to be recreated.  ``<order-indexes>`` is a comma-separated list of
1852 indexes that are assigned to the referenced value's uses.  The referenced
1853 value's use-list is immediately sorted by these indexes.
1854
1855 Use-list directives may appear at function scope or global scope.  They are not
1856 instructions, and have no effect on the semantics of the IR.  When they're at
1857 function scope, they must appear after the terminator of the final basic block.
1858
1859 If basic blocks have their address taken via ``blockaddress()`` expressions,
1860 ``uselistorder_bb`` can be used to reorder their use-lists from outside their
1861 function's scope.
1862
1863 :Syntax:
1864
1865 ::
1866
1867     uselistorder <ty> <value>, { <order-indexes> }
1868     uselistorder_bb @function, %block { <order-indexes> }
1869
1870 :Examples:
1871
1872 ::
1873
1874     define void @foo(i32 %arg1, i32 %arg2) {
1875     entry:
1876       ; ... instructions ...
1877     bb:
1878       ; ... instructions ...
1879
1880       ; At function scope.
1881       uselistorder i32 %arg1, { 1, 0, 2 }
1882       uselistorder label %bb, { 1, 0 }
1883     }
1884
1885     ; At global scope.
1886     uselistorder i32* @global, { 1, 2, 0 }
1887     uselistorder i32 7, { 1, 0 }
1888     uselistorder i32 (i32) @bar, { 1, 0 }
1889     uselistorder_bb @foo, %bb, { 5, 1, 3, 2, 0, 4 }
1890
1891 .. _typesystem:
1892
1893 Type System
1894 ===========
1895
1896 The LLVM type system is one of the most important features of the
1897 intermediate representation. Being typed enables a number of
1898 optimizations to be performed on the intermediate representation
1899 directly, without having to do extra analyses on the side before the
1900 transformation. A strong type system makes it easier to read the
1901 generated code and enables novel analyses and transformations that are
1902 not feasible to perform on normal three address code representations.
1903
1904 .. _t_void:
1905
1906 Void Type
1907 ---------
1908
1909 :Overview:
1910
1911
1912 The void type does not represent any value and has no size.
1913
1914 :Syntax:
1915
1916
1917 ::
1918
1919       void
1920
1921
1922 .. _t_function:
1923
1924 Function Type
1925 -------------
1926
1927 :Overview:
1928
1929
1930 The function type can be thought of as a function signature. It consists of a
1931 return type and a list of formal parameter types. The return type of a function
1932 type is a void type or first class type --- except for :ref:`label <t_label>`
1933 and :ref:`metadata <t_metadata>` types.
1934
1935 :Syntax:
1936
1937 ::
1938
1939       <returntype> (<parameter list>)
1940
1941 ...where '``<parameter list>``' is a comma-separated list of type
1942 specifiers. Optionally, the parameter list may include a type ``...``, which
1943 indicates that the function takes a variable number of arguments.  Variable
1944 argument functions can access their arguments with the :ref:`variable argument
1945 handling intrinsic <int_varargs>` functions.  '``<returntype>``' is any type
1946 except :ref:`label <t_label>` and :ref:`metadata <t_metadata>`.
1947
1948 :Examples:
1949
1950 +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1951 | ``i32 (i32)``                   | function taking an ``i32``, returning an ``i32``                                                                                                                    |
1952 +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1953 | ``float (i16, i32 *) *``        | :ref:`Pointer <t_pointer>` to a function that takes an ``i16`` and a :ref:`pointer <t_pointer>` to ``i32``, returning ``float``.                                    |
1954 +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1955 | ``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. |
1956 +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1957 | ``{i32, i32} (i32)``            | A function taking an ``i32``, returning a :ref:`structure <t_struct>` containing two ``i32`` values                                                                 |
1958 +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1959
1960 .. _t_firstclass:
1961
1962 First Class Types
1963 -----------------
1964
1965 The :ref:`first class <t_firstclass>` types are perhaps the most important.
1966 Values of these types are the only ones which can be produced by
1967 instructions.
1968
1969 .. _t_single_value:
1970
1971 Single Value Types
1972 ^^^^^^^^^^^^^^^^^^
1973
1974 These are the types that are valid in registers from CodeGen's perspective.
1975
1976 .. _t_integer:
1977
1978 Integer Type
1979 """"""""""""
1980
1981 :Overview:
1982
1983 The integer type is a very simple type that simply specifies an
1984 arbitrary bit width for the integer type desired. Any bit width from 1
1985 bit to 2\ :sup:`23`\ -1 (about 8 million) can be specified.
1986
1987 :Syntax:
1988
1989 ::
1990
1991       iN
1992
1993 The number of bits the integer will occupy is specified by the ``N``
1994 value.
1995
1996 Examples:
1997 *********
1998
1999 +----------------+------------------------------------------------+
2000 | ``i1``         | a single-bit integer.                          |
2001 +----------------+------------------------------------------------+
2002 | ``i32``        | a 32-bit integer.                              |
2003 +----------------+------------------------------------------------+
2004 | ``i1942652``   | a really big integer of over 1 million bits.   |
2005 +----------------+------------------------------------------------+
2006
2007 .. _t_floating:
2008
2009 Floating Point Types
2010 """"""""""""""""""""
2011
2012 .. list-table::
2013    :header-rows: 1
2014
2015    * - Type
2016      - Description
2017
2018    * - ``half``
2019      - 16-bit floating point value
2020
2021    * - ``float``
2022      - 32-bit floating point value
2023
2024    * - ``double``
2025      - 64-bit floating point value
2026
2027    * - ``fp128``
2028      - 128-bit floating point value (112-bit mantissa)
2029
2030    * - ``x86_fp80``
2031      -  80-bit floating point value (X87)
2032
2033    * - ``ppc_fp128``
2034      - 128-bit floating point value (two 64-bits)
2035
2036 X86_mmx Type
2037 """"""""""""
2038
2039 :Overview:
2040
2041 The x86_mmx type represents a value held in an MMX register on an x86
2042 machine. The operations allowed on it are quite limited: parameters and
2043 return values, load and store, and bitcast. User-specified MMX
2044 instructions are represented as intrinsic or asm calls with arguments
2045 and/or results of this type. There are no arrays, vectors or constants
2046 of this type.
2047
2048 :Syntax:
2049
2050 ::
2051
2052       x86_mmx
2053
2054
2055 .. _t_pointer:
2056
2057 Pointer Type
2058 """"""""""""
2059
2060 :Overview:
2061
2062 The pointer type is used to specify memory locations. Pointers are
2063 commonly used to reference objects in memory.
2064
2065 Pointer types may have an optional address space attribute defining the
2066 numbered address space where the pointed-to object resides. The default
2067 address space is number zero. The semantics of non-zero address spaces
2068 are target-specific.
2069
2070 Note that LLVM does not permit pointers to void (``void*``) nor does it
2071 permit pointers to labels (``label*``). Use ``i8*`` instead.
2072
2073 :Syntax:
2074
2075 ::
2076
2077       <type> *
2078
2079 :Examples:
2080
2081 +-------------------------+--------------------------------------------------------------------------------------------------------------+
2082 | ``[4 x i32]*``          | A :ref:`pointer <t_pointer>` to :ref:`array <t_array>` of four ``i32`` values.                               |
2083 +-------------------------+--------------------------------------------------------------------------------------------------------------+
2084 | ``i32 (i32*) *``        | A :ref:`pointer <t_pointer>` to a :ref:`function <t_function>` that takes an ``i32*``, returning an ``i32``. |
2085 +-------------------------+--------------------------------------------------------------------------------------------------------------+
2086 | ``i32 addrspace(5)*``   | A :ref:`pointer <t_pointer>` to an ``i32`` value that resides in address space #5.                           |
2087 +-------------------------+--------------------------------------------------------------------------------------------------------------+
2088
2089 .. _t_vector:
2090
2091 Vector Type
2092 """""""""""
2093
2094 :Overview:
2095
2096 A vector type is a simple derived type that represents a vector of
2097 elements. Vector types are used when multiple primitive data are
2098 operated in parallel using a single instruction (SIMD). A vector type
2099 requires a size (number of elements) and an underlying primitive data
2100 type. Vector types are considered :ref:`first class <t_firstclass>`.
2101
2102 :Syntax:
2103
2104 ::
2105
2106       < <# elements> x <elementtype> >
2107
2108 The number of elements is a constant integer value larger than 0;
2109 elementtype may be any integer, floating point or pointer type. Vectors
2110 of size zero are not allowed.
2111
2112 :Examples:
2113
2114 +-------------------+--------------------------------------------------+
2115 | ``<4 x i32>``     | Vector of 4 32-bit integer values.               |
2116 +-------------------+--------------------------------------------------+
2117 | ``<8 x float>``   | Vector of 8 32-bit floating-point values.        |
2118 +-------------------+--------------------------------------------------+
2119 | ``<2 x i64>``     | Vector of 2 64-bit integer values.               |
2120 +-------------------+--------------------------------------------------+
2121 | ``<4 x i64*>``    | Vector of 4 pointers to 64-bit integer values.   |
2122 +-------------------+--------------------------------------------------+
2123
2124 .. _t_label:
2125
2126 Label Type
2127 ^^^^^^^^^^
2128
2129 :Overview:
2130
2131 The label type represents code labels.
2132
2133 :Syntax:
2134
2135 ::
2136
2137       label
2138
2139 .. _t_metadata:
2140
2141 Metadata Type
2142 ^^^^^^^^^^^^^
2143
2144 :Overview:
2145
2146 The metadata type represents embedded metadata. No derived types may be
2147 created from metadata except for :ref:`function <t_function>` arguments.
2148
2149 :Syntax:
2150
2151 ::
2152
2153       metadata
2154
2155 .. _t_aggregate:
2156
2157 Aggregate Types
2158 ^^^^^^^^^^^^^^^
2159
2160 Aggregate Types are a subset of derived types that can contain multiple
2161 member types. :ref:`Arrays <t_array>` and :ref:`structs <t_struct>` are
2162 aggregate types. :ref:`Vectors <t_vector>` are not considered to be
2163 aggregate types.
2164
2165 .. _t_array:
2166
2167 Array Type
2168 """"""""""
2169
2170 :Overview:
2171
2172 The array type is a very simple derived type that arranges elements
2173 sequentially in memory. The array type requires a size (number of
2174 elements) and an underlying data type.
2175
2176 :Syntax:
2177
2178 ::
2179
2180       [<# elements> x <elementtype>]
2181
2182 The number of elements is a constant integer value; ``elementtype`` may
2183 be any type with a size.
2184
2185 :Examples:
2186
2187 +------------------+--------------------------------------+
2188 | ``[40 x i32]``   | Array of 40 32-bit integer values.   |
2189 +------------------+--------------------------------------+
2190 | ``[41 x i32]``   | Array of 41 32-bit integer values.   |
2191 +------------------+--------------------------------------+
2192 | ``[4 x i8]``     | Array of 4 8-bit integer values.     |
2193 +------------------+--------------------------------------+
2194
2195 Here are some examples of multidimensional arrays:
2196
2197 +-----------------------------+----------------------------------------------------------+
2198 | ``[3 x [4 x i32]]``         | 3x4 array of 32-bit integer values.                      |
2199 +-----------------------------+----------------------------------------------------------+
2200 | ``[12 x [10 x float]]``     | 12x10 array of single precision floating point values.   |
2201 +-----------------------------+----------------------------------------------------------+
2202 | ``[2 x [3 x [4 x i16]]]``   | 2x3x4 array of 16-bit integer values.                    |
2203 +-----------------------------+----------------------------------------------------------+
2204
2205 There is no restriction on indexing beyond the end of the array implied
2206 by a static type (though there are restrictions on indexing beyond the
2207 bounds of an allocated object in some cases). This means that
2208 single-dimension 'variable sized array' addressing can be implemented in
2209 LLVM with a zero length array type. An implementation of 'pascal style
2210 arrays' in LLVM could use the type "``{ i32, [0 x float]}``", for
2211 example.
2212
2213 .. _t_struct:
2214
2215 Structure Type
2216 """"""""""""""
2217
2218 :Overview:
2219
2220 The structure type is used to represent a collection of data members
2221 together in memory. The elements of a structure may be any type that has
2222 a size.
2223
2224 Structures in memory are accessed using '``load``' and '``store``' by
2225 getting a pointer to a field with the '``getelementptr``' instruction.
2226 Structures in registers are accessed using the '``extractvalue``' and
2227 '``insertvalue``' instructions.
2228
2229 Structures may optionally be "packed" structures, which indicate that
2230 the alignment of the struct is one byte, and that there is no padding
2231 between the elements. In non-packed structs, padding between field types
2232 is inserted as defined by the DataLayout string in the module, which is
2233 required to match what the underlying code generator expects.
2234
2235 Structures can either be "literal" or "identified". A literal structure
2236 is defined inline with other types (e.g. ``{i32, i32}*``) whereas
2237 identified types are always defined at the top level with a name.
2238 Literal types are uniqued by their contents and can never be recursive
2239 or opaque since there is no way to write one. Identified types can be
2240 recursive, can be opaqued, and are never uniqued.
2241
2242 :Syntax:
2243
2244 ::
2245
2246       %T1 = type { <type list> }     ; Identified normal struct type
2247       %T2 = type <{ <type list> }>   ; Identified packed struct type
2248
2249 :Examples:
2250
2251 +------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
2252 | ``{ i32, i32, i32 }``        | A triple of three ``i32`` values                                                                                                                                                      |
2253 +------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
2254 | ``{ 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``.  |
2255 +------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
2256 | ``<{ i8, i32 }>``            | A packed struct known to be 5 bytes in size.                                                                                                                                          |
2257 +------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
2258
2259 .. _t_opaque:
2260
2261 Opaque Structure Types
2262 """"""""""""""""""""""
2263
2264 :Overview:
2265
2266 Opaque structure types are used to represent named structure types that
2267 do not have a body specified. This corresponds (for example) to the C
2268 notion of a forward declared structure.
2269
2270 :Syntax:
2271
2272 ::
2273
2274       %X = type opaque
2275       %52 = type opaque
2276
2277 :Examples:
2278
2279 +--------------+-------------------+
2280 | ``opaque``   | An opaque type.   |
2281 +--------------+-------------------+
2282
2283 .. _constants:
2284
2285 Constants
2286 =========
2287
2288 LLVM has several different basic types of constants. This section
2289 describes them all and their syntax.
2290
2291 Simple Constants
2292 ----------------
2293
2294 **Boolean constants**
2295     The two strings '``true``' and '``false``' are both valid constants
2296     of the ``i1`` type.
2297 **Integer constants**
2298     Standard integers (such as '4') are constants of the
2299     :ref:`integer <t_integer>` type. Negative numbers may be used with
2300     integer types.
2301 **Floating point constants**
2302     Floating point constants use standard decimal notation (e.g.
2303     123.421), exponential notation (e.g. 1.23421e+2), or a more precise
2304     hexadecimal notation (see below). The assembler requires the exact
2305     decimal value of a floating-point constant. For example, the
2306     assembler accepts 1.25 but rejects 1.3 because 1.3 is a repeating
2307     decimal in binary. Floating point constants must have a :ref:`floating
2308     point <t_floating>` type.
2309 **Null pointer constants**
2310     The identifier '``null``' is recognized as a null pointer constant
2311     and must be of :ref:`pointer type <t_pointer>`.
2312
2313 The one non-intuitive notation for constants is the hexadecimal form of
2314 floating point constants. For example, the form
2315 '``double    0x432ff973cafa8000``' is equivalent to (but harder to read
2316 than) '``double 4.5e+15``'. The only time hexadecimal floating point
2317 constants are required (and the only time that they are generated by the
2318 disassembler) is when a floating point constant must be emitted but it
2319 cannot be represented as a decimal floating point number in a reasonable
2320 number of digits. For example, NaN's, infinities, and other special
2321 values are represented in their IEEE hexadecimal format so that assembly
2322 and disassembly do not cause any bits to change in the constants.
2323
2324 When using the hexadecimal form, constants of types half, float, and
2325 double are represented using the 16-digit form shown above (which
2326 matches the IEEE754 representation for double); half and float values
2327 must, however, be exactly representable as IEEE 754 half and single
2328 precision, respectively. Hexadecimal format is always used for long
2329 double, and there are three forms of long double. The 80-bit format used
2330 by x86 is represented as ``0xK`` followed by 20 hexadecimal digits. The
2331 128-bit format used by PowerPC (two adjacent doubles) is represented by
2332 ``0xM`` followed by 32 hexadecimal digits. The IEEE 128-bit format is
2333 represented by ``0xL`` followed by 32 hexadecimal digits. Long doubles
2334 will only work if they match the long double format on your target.
2335 The IEEE 16-bit format (half precision) is represented by ``0xH``
2336 followed by 4 hexadecimal digits. All hexadecimal formats are big-endian
2337 (sign bit at the left).
2338
2339 There are no constants of type x86_mmx.
2340
2341 .. _complexconstants:
2342
2343 Complex Constants
2344 -----------------
2345
2346 Complex constants are a (potentially recursive) combination of simple
2347 constants and smaller complex constants.
2348
2349 **Structure constants**
2350     Structure constants are represented with notation similar to
2351     structure type definitions (a comma separated list of elements,
2352     surrounded by braces (``{}``)). For example:
2353     "``{ i32 4, float 17.0, i32* @G }``", where "``@G``" is declared as
2354     "``@G = external global i32``". Structure constants must have
2355     :ref:`structure type <t_struct>`, and the number and types of elements
2356     must match those specified by the type.
2357 **Array constants**
2358     Array constants are represented with notation similar to array type
2359     definitions (a comma separated list of elements, surrounded by
2360     square brackets (``[]``)). For example:
2361     "``[ i32 42, i32 11, i32 74 ]``". Array constants must have
2362     :ref:`array type <t_array>`, and the number and types of elements must
2363     match those specified by the type. As a special case, character array
2364     constants may also be represented as a double-quoted string using the ``c``
2365     prefix. For example: "``c"Hello World\0A\00"``".
2366 **Vector constants**
2367     Vector constants are represented with notation similar to vector
2368     type definitions (a comma separated list of elements, surrounded by
2369     less-than/greater-than's (``<>``)). For example:
2370     "``< i32 42, i32 11, i32 74, i32 100 >``". Vector constants
2371     must have :ref:`vector type <t_vector>`, and the number and types of
2372     elements must match those specified by the type.
2373 **Zero initialization**
2374     The string '``zeroinitializer``' can be used to zero initialize a
2375     value to zero of *any* type, including scalar and
2376     :ref:`aggregate <t_aggregate>` types. This is often used to avoid
2377     having to print large zero initializers (e.g. for large arrays) and
2378     is always exactly equivalent to using explicit zero initializers.
2379 **Metadata node**
2380     A metadata node is a constant tuple without types.  For example:
2381     "``!{!0, !{!2, !0}, !"test"}``".  Metadata can reference constant values,
2382     for example: "``!{!0, i32 0, i8* @global, i64 (i64)* @function, !"str"}``".
2383     Unlike other typed constants that are meant to be interpreted as part of
2384     the instruction stream, metadata is a place to attach additional
2385     information such as debug info.
2386
2387 Global Variable and Function Addresses
2388 --------------------------------------
2389
2390 The addresses of :ref:`global variables <globalvars>` and
2391 :ref:`functions <functionstructure>` are always implicitly valid
2392 (link-time) constants. These constants are explicitly referenced when
2393 the :ref:`identifier for the global <identifiers>` is used and always have
2394 :ref:`pointer <t_pointer>` type. For example, the following is a legal LLVM
2395 file:
2396
2397 .. code-block:: llvm
2398
2399     @X = global i32 17
2400     @Y = global i32 42
2401     @Z = global [2 x i32*] [ i32* @X, i32* @Y ]
2402
2403 .. _undefvalues:
2404
2405 Undefined Values
2406 ----------------
2407
2408 The string '``undef``' can be used anywhere a constant is expected, and
2409 indicates that the user of the value may receive an unspecified
2410 bit-pattern. Undefined values may be of any type (other than '``label``'
2411 or '``void``') and be used anywhere a constant is permitted.
2412
2413 Undefined values are useful because they indicate to the compiler that
2414 the program is well defined no matter what value is used. This gives the
2415 compiler more freedom to optimize. Here are some examples of
2416 (potentially surprising) transformations that are valid (in pseudo IR):
2417
2418 .. code-block:: llvm
2419
2420       %A = add %X, undef
2421       %B = sub %X, undef
2422       %C = xor %X, undef
2423     Safe:
2424       %A = undef
2425       %B = undef
2426       %C = undef
2427
2428 This is safe because all of the output bits are affected by the undef
2429 bits. Any output bit can have a zero or one depending on the input bits.
2430
2431 .. code-block:: llvm
2432
2433       %A = or %X, undef
2434       %B = and %X, undef
2435     Safe:
2436       %A = -1
2437       %B = 0
2438     Unsafe:
2439       %A = undef
2440       %B = undef
2441
2442 These logical operations have bits that are not always affected by the
2443 input. For example, if ``%X`` has a zero bit, then the output of the
2444 '``and``' operation will always be a zero for that bit, no matter what
2445 the corresponding bit from the '``undef``' is. As such, it is unsafe to
2446 optimize or assume that the result of the '``and``' is '``undef``'.
2447 However, it is safe to assume that all bits of the '``undef``' could be
2448 0, and optimize the '``and``' to 0. Likewise, it is safe to assume that
2449 all the bits of the '``undef``' operand to the '``or``' could be set,
2450 allowing the '``or``' to be folded to -1.
2451
2452 .. code-block:: llvm
2453
2454       %A = select undef, %X, %Y
2455       %B = select undef, 42, %Y
2456       %C = select %X, %Y, undef
2457     Safe:
2458       %A = %X     (or %Y)
2459       %B = 42     (or %Y)
2460       %C = %Y
2461     Unsafe:
2462       %A = undef
2463       %B = undef
2464       %C = undef
2465
2466 This set of examples shows that undefined '``select``' (and conditional
2467 branch) conditions can go *either way*, but they have to come from one
2468 of the two operands. In the ``%A`` example, if ``%X`` and ``%Y`` were
2469 both known to have a clear low bit, then ``%A`` would have to have a
2470 cleared low bit. However, in the ``%C`` example, the optimizer is
2471 allowed to assume that the '``undef``' operand could be the same as
2472 ``%Y``, allowing the whole '``select``' to be eliminated.
2473
2474 .. code-block:: llvm
2475
2476       %A = xor undef, undef
2477
2478       %B = undef
2479       %C = xor %B, %B
2480
2481       %D = undef
2482       %E = icmp slt %D, 4
2483       %F = icmp gte %D, 4
2484
2485     Safe:
2486       %A = undef
2487       %B = undef
2488       %C = undef
2489       %D = undef
2490       %E = undef
2491       %F = undef
2492
2493 This example points out that two '``undef``' operands are not
2494 necessarily the same. This can be surprising to people (and also matches
2495 C semantics) where they assume that "``X^X``" is always zero, even if
2496 ``X`` is undefined. This isn't true for a number of reasons, but the
2497 short answer is that an '``undef``' "variable" can arbitrarily change
2498 its value over its "live range". This is true because the variable
2499 doesn't actually *have a live range*. Instead, the value is logically
2500 read from arbitrary registers that happen to be around when needed, so
2501 the value is not necessarily consistent over time. In fact, ``%A`` and
2502 ``%C`` need to have the same semantics or the core LLVM "replace all
2503 uses with" concept would not hold.
2504
2505 .. code-block:: llvm
2506
2507       %A = fdiv undef, %X
2508       %B = fdiv %X, undef
2509     Safe:
2510       %A = undef
2511     b: unreachable
2512
2513 These examples show the crucial difference between an *undefined value*
2514 and *undefined behavior*. An undefined value (like '``undef``') is
2515 allowed to have an arbitrary bit-pattern. This means that the ``%A``
2516 operation can be constant folded to '``undef``', because the '``undef``'
2517 could be an SNaN, and ``fdiv`` is not (currently) defined on SNaN's.
2518 However, in the second example, we can make a more aggressive
2519 assumption: because the ``undef`` is allowed to be an arbitrary value,
2520 we are allowed to assume that it could be zero. Since a divide by zero
2521 has *undefined behavior*, we are allowed to assume that the operation
2522 does not execute at all. This allows us to delete the divide and all
2523 code after it. Because the undefined operation "can't happen", the
2524 optimizer can assume that it occurs in dead code.
2525
2526 .. code-block:: llvm
2527
2528     a:  store undef -> %X
2529     b:  store %X -> undef
2530     Safe:
2531     a: <deleted>
2532     b: unreachable
2533
2534 These examples reiterate the ``fdiv`` example: a store *of* an undefined
2535 value can be assumed to not have any effect; we can assume that the
2536 value is overwritten with bits that happen to match what was already
2537 there. However, a store *to* an undefined location could clobber
2538 arbitrary memory, therefore, it has undefined behavior.
2539
2540 .. _poisonvalues:
2541
2542 Poison Values
2543 -------------
2544
2545 Poison values are similar to :ref:`undef values <undefvalues>`, however
2546 they also represent the fact that an instruction or constant expression
2547 that cannot evoke side effects has nevertheless detected a condition
2548 that results in undefined behavior.
2549
2550 There is currently no way of representing a poison value in the IR; they
2551 only exist when produced by operations such as :ref:`add <i_add>` with
2552 the ``nsw`` flag.
2553
2554 Poison value behavior is defined in terms of value *dependence*:
2555
2556 -  Values other than :ref:`phi <i_phi>` nodes depend on their operands.
2557 -  :ref:`Phi <i_phi>` nodes depend on the operand corresponding to
2558    their dynamic predecessor basic block.
2559 -  Function arguments depend on the corresponding actual argument values
2560    in the dynamic callers of their functions.
2561 -  :ref:`Call <i_call>` instructions depend on the :ref:`ret <i_ret>`
2562    instructions that dynamically transfer control back to them.
2563 -  :ref:`Invoke <i_invoke>` instructions depend on the
2564    :ref:`ret <i_ret>`, :ref:`resume <i_resume>`, or exception-throwing
2565    call instructions that dynamically transfer control back to them.
2566 -  Non-volatile loads and stores depend on the most recent stores to all
2567    of the referenced memory addresses, following the order in the IR
2568    (including loads and stores implied by intrinsics such as
2569    :ref:`@llvm.memcpy <int_memcpy>`.)
2570 -  An instruction with externally visible side effects depends on the
2571    most recent preceding instruction with externally visible side
2572    effects, following the order in the IR. (This includes :ref:`volatile
2573    operations <volatile>`.)
2574 -  An instruction *control-depends* on a :ref:`terminator
2575    instruction <terminators>` if the terminator instruction has
2576    multiple successors and the instruction is always executed when
2577    control transfers to one of the successors, and may not be executed
2578    when control is transferred to another.
2579 -  Additionally, an instruction also *control-depends* on a terminator
2580    instruction if the set of instructions it otherwise depends on would
2581    be different if the terminator had transferred control to a different
2582    successor.
2583 -  Dependence is transitive.
2584
2585 Poison values have the same behavior as :ref:`undef values <undefvalues>`,
2586 with the additional effect that any instruction that has a *dependence*
2587 on a poison value has undefined behavior.
2588
2589 Here are some examples:
2590
2591 .. code-block:: llvm
2592
2593     entry:
2594       %poison = sub nuw i32 0, 1           ; Results in a poison value.
2595       %still_poison = and i32 %poison, 0   ; 0, but also poison.
2596       %poison_yet_again = getelementptr i32, i32* @h, i32 %still_poison
2597       store i32 0, i32* %poison_yet_again  ; memory at @h[0] is poisoned
2598
2599       store i32 %poison, i32* @g           ; Poison value stored to memory.
2600       %poison2 = load i32, i32* @g         ; Poison value loaded back from memory.
2601
2602       store volatile i32 %poison, i32* @g  ; External observation; undefined behavior.
2603
2604       %narrowaddr = bitcast i32* @g to i16*
2605       %wideaddr = bitcast i32* @g to i64*
2606       %poison3 = load i16, i16* %narrowaddr ; Returns a poison value.
2607       %poison4 = load i64, i64* %wideaddr  ; Returns a poison value.
2608
2609       %cmp = icmp slt i32 %poison, 0       ; Returns a poison value.
2610       br i1 %cmp, label %true, label %end  ; Branch to either destination.
2611
2612     true:
2613       store volatile i32 0, i32* @g        ; This is control-dependent on %cmp, so
2614                                            ; it has undefined behavior.
2615       br label %end
2616
2617     end:
2618       %p = phi i32 [ 0, %entry ], [ 1, %true ]
2619                                            ; Both edges into this PHI are
2620                                            ; control-dependent on %cmp, so this
2621                                            ; always results in a poison value.
2622
2623       store volatile i32 0, i32* @g        ; This would depend on the store in %true
2624                                            ; if %cmp is true, or the store in %entry
2625                                            ; otherwise, so this is undefined behavior.
2626
2627       br i1 %cmp, label %second_true, label %second_end
2628                                            ; The same branch again, but this time the
2629                                            ; true block doesn't have side effects.
2630
2631     second_true:
2632       ; No side effects!
2633       ret void
2634
2635     second_end:
2636       store volatile i32 0, i32* @g        ; This time, the instruction always depends
2637                                            ; on the store in %end. Also, it is
2638                                            ; control-equivalent to %end, so this is
2639                                            ; well-defined (ignoring earlier undefined
2640                                            ; behavior in this example).
2641
2642 .. _blockaddress:
2643
2644 Addresses of Basic Blocks
2645 -------------------------
2646
2647 ``blockaddress(@function, %block)``
2648
2649 The '``blockaddress``' constant computes the address of the specified
2650 basic block in the specified function, and always has an ``i8*`` type.
2651 Taking the address of the entry block is illegal.
2652
2653 This value only has defined behavior when used as an operand to the
2654 ':ref:`indirectbr <i_indirectbr>`' instruction, or for comparisons
2655 against null. Pointer equality tests between labels addresses results in
2656 undefined behavior --- though, again, comparison against null is ok, and
2657 no label is equal to the null pointer. This may be passed around as an
2658 opaque pointer sized value as long as the bits are not inspected. This
2659 allows ``ptrtoint`` and arithmetic to be performed on these values so
2660 long as the original value is reconstituted before the ``indirectbr``
2661 instruction.
2662
2663 Finally, some targets may provide defined semantics when using the value
2664 as the operand to an inline assembly, but that is target specific.
2665
2666 .. _constantexprs:
2667
2668 Constant Expressions
2669 --------------------
2670
2671 Constant expressions are used to allow expressions involving other
2672 constants to be used as constants. Constant expressions may be of any
2673 :ref:`first class <t_firstclass>` type and may involve any LLVM operation
2674 that does not have side effects (e.g. load and call are not supported).
2675 The following is the syntax for constant expressions:
2676
2677 ``trunc (CST to TYPE)``
2678     Truncate a constant to another type. The bit size of CST must be
2679     larger than the bit size of TYPE. Both types must be integers.
2680 ``zext (CST to TYPE)``
2681     Zero extend a constant to another type. The bit size of CST must be
2682     smaller than the bit size of TYPE. Both types must be integers.
2683 ``sext (CST to TYPE)``
2684     Sign extend a constant to another type. The bit size of CST must be
2685     smaller than the bit size of TYPE. Both types must be integers.
2686 ``fptrunc (CST to TYPE)``
2687     Truncate a floating point constant to another floating point type.
2688     The size of CST must be larger than the size of TYPE. Both types
2689     must be floating point.
2690 ``fpext (CST to TYPE)``
2691     Floating point extend a constant to another type. The size of CST
2692     must be smaller or equal to the size of TYPE. Both types must be
2693     floating point.
2694 ``fptoui (CST to TYPE)``
2695     Convert a floating point constant to the corresponding unsigned
2696     integer constant. TYPE must be a scalar or vector integer type. CST
2697     must be of scalar or vector floating point type. Both CST and TYPE
2698     must be scalars, or vectors of the same number of elements. If the
2699     value won't fit in the integer type, the results are undefined.
2700 ``fptosi (CST to TYPE)``
2701     Convert a floating point constant to the corresponding signed
2702     integer constant. TYPE must be a scalar or vector integer type. CST
2703     must be of scalar or vector floating point type. Both CST and TYPE
2704     must be scalars, or vectors of the same number of elements. If the
2705     value won't fit in the integer type, the results are undefined.
2706 ``uitofp (CST to TYPE)``
2707     Convert an unsigned integer constant to the corresponding floating
2708     point constant. TYPE must be a scalar or vector floating point type.
2709     CST must be of scalar or vector integer type. Both CST and TYPE must
2710     be scalars, or vectors of the same number of elements. If the value
2711     won't fit in the floating point type, the results are undefined.
2712 ``sitofp (CST to TYPE)``
2713     Convert a signed integer constant to the corresponding floating
2714     point constant. TYPE must be a scalar or vector floating point type.
2715     CST must be of scalar or vector integer type. Both CST and TYPE must
2716     be scalars, or vectors of the same number of elements. If the value
2717     won't fit in the floating point type, the results are undefined.
2718 ``ptrtoint (CST to TYPE)``
2719     Convert a pointer typed constant to the corresponding integer
2720     constant. ``TYPE`` must be an integer type. ``CST`` must be of
2721     pointer type. The ``CST`` value is zero extended, truncated, or
2722     unchanged to make it fit in ``TYPE``.
2723 ``inttoptr (CST to TYPE)``
2724     Convert an integer constant to a pointer constant. TYPE must be a
2725     pointer type. CST must be of integer type. The CST value is zero
2726     extended, truncated, or unchanged to make it fit in a pointer size.
2727     This one is *really* dangerous!
2728 ``bitcast (CST to TYPE)``
2729     Convert a constant, CST, to another TYPE. The constraints of the
2730     operands are the same as those for the :ref:`bitcast
2731     instruction <i_bitcast>`.
2732 ``addrspacecast (CST to TYPE)``
2733     Convert a constant pointer or constant vector of pointer, CST, to another
2734     TYPE in a different address space. The constraints of the operands are the
2735     same as those for the :ref:`addrspacecast instruction <i_addrspacecast>`.
2736 ``getelementptr (TY, CSTPTR, IDX0, IDX1, ...)``, ``getelementptr inbounds (TY, CSTPTR, IDX0, IDX1, ...)``
2737     Perform the :ref:`getelementptr operation <i_getelementptr>` on
2738     constants. As with the :ref:`getelementptr <i_getelementptr>`
2739     instruction, the index list may have zero or more indexes, which are
2740     required to make sense for the type of "pointer to TY".
2741 ``select (COND, VAL1, VAL2)``
2742     Perform the :ref:`select operation <i_select>` on constants.
2743 ``icmp COND (VAL1, VAL2)``
2744     Performs the :ref:`icmp operation <i_icmp>` on constants.
2745 ``fcmp COND (VAL1, VAL2)``
2746     Performs the :ref:`fcmp operation <i_fcmp>` on constants.
2747 ``extractelement (VAL, IDX)``
2748     Perform the :ref:`extractelement operation <i_extractelement>` on
2749     constants.
2750 ``insertelement (VAL, ELT, IDX)``
2751     Perform the :ref:`insertelement operation <i_insertelement>` on
2752     constants.
2753 ``shufflevector (VEC1, VEC2, IDXMASK)``
2754     Perform the :ref:`shufflevector operation <i_shufflevector>` on
2755     constants.
2756 ``extractvalue (VAL, IDX0, IDX1, ...)``
2757     Perform the :ref:`extractvalue operation <i_extractvalue>` on
2758     constants. The index list is interpreted in a similar manner as
2759     indices in a ':ref:`getelementptr <i_getelementptr>`' operation. At
2760     least one index value must be specified.
2761 ``insertvalue (VAL, ELT, IDX0, IDX1, ...)``
2762     Perform the :ref:`insertvalue operation <i_insertvalue>` on constants.
2763     The index list is interpreted in a similar manner as indices in a
2764     ':ref:`getelementptr <i_getelementptr>`' operation. At least one index
2765     value must be specified.
2766 ``OPCODE (LHS, RHS)``
2767     Perform the specified operation of the LHS and RHS constants. OPCODE
2768     may be any of the :ref:`binary <binaryops>` or :ref:`bitwise
2769     binary <bitwiseops>` operations. The constraints on operands are
2770     the same as those for the corresponding instruction (e.g. no bitwise
2771     operations on floating point values are allowed).
2772
2773 Other Values
2774 ============
2775
2776 .. _inlineasmexprs:
2777
2778 Inline Assembler Expressions
2779 ----------------------------
2780
2781 LLVM supports inline assembler expressions (as opposed to :ref:`Module-Level
2782 Inline Assembly <moduleasm>`) through the use of a special value. This
2783 value represents the inline assembler as a string (containing the
2784 instructions to emit), a list of operand constraints (stored as a
2785 string), a flag that indicates whether or not the inline asm expression
2786 has side effects, and a flag indicating whether the function containing
2787 the asm needs to align its stack conservatively. An example inline
2788 assembler expression is:
2789
2790 .. code-block:: llvm
2791
2792     i32 (i32) asm "bswap $0", "=r,r"
2793
2794 Inline assembler expressions may **only** be used as the callee operand
2795 of a :ref:`call <i_call>` or an :ref:`invoke <i_invoke>` instruction.
2796 Thus, typically we have:
2797
2798 .. code-block:: llvm
2799
2800     %X = call i32 asm "bswap $0", "=r,r"(i32 %Y)
2801
2802 Inline asms with side effects not visible in the constraint list must be
2803 marked as having side effects. This is done through the use of the
2804 '``sideeffect``' keyword, like so:
2805
2806 .. code-block:: llvm
2807
2808     call void asm sideeffect "eieio", ""()
2809
2810 In some cases inline asms will contain code that will not work unless
2811 the stack is aligned in some way, such as calls or SSE instructions on
2812 x86, yet will not contain code that does that alignment within the asm.
2813 The compiler should make conservative assumptions about what the asm
2814 might contain and should generate its usual stack alignment code in the
2815 prologue if the '``alignstack``' keyword is present:
2816
2817 .. code-block:: llvm
2818
2819     call void asm alignstack "eieio", ""()
2820
2821 Inline asms also support using non-standard assembly dialects. The
2822 assumed dialect is ATT. When the '``inteldialect``' keyword is present,
2823 the inline asm is using the Intel dialect. Currently, ATT and Intel are
2824 the only supported dialects. An example is:
2825
2826 .. code-block:: llvm
2827
2828     call void asm inteldialect "eieio", ""()
2829
2830 If multiple keywords appear the '``sideeffect``' keyword must come
2831 first, the '``alignstack``' keyword second and the '``inteldialect``'
2832 keyword last.
2833
2834 Inline Asm Metadata
2835 ^^^^^^^^^^^^^^^^^^^
2836
2837 The call instructions that wrap inline asm nodes may have a
2838 "``!srcloc``" MDNode attached to it that contains a list of constant
2839 integers. If present, the code generator will use the integer as the
2840 location cookie value when report errors through the ``LLVMContext``
2841 error reporting mechanisms. This allows a front-end to correlate backend
2842 errors that occur with inline asm back to the source code that produced
2843 it. For example:
2844
2845 .. code-block:: llvm
2846
2847     call void asm sideeffect "something bad", ""(), !srcloc !42
2848     ...
2849     !42 = !{ i32 1234567 }
2850
2851 It is up to the front-end to make sense of the magic numbers it places
2852 in the IR. If the MDNode contains multiple constants, the code generator
2853 will use the one that corresponds to the line of the asm that the error
2854 occurs on.
2855
2856 .. _metadata:
2857
2858 Metadata
2859 ========
2860
2861 LLVM IR allows metadata to be attached to instructions in the program
2862 that can convey extra information about the code to the optimizers and
2863 code generator. One example application of metadata is source-level
2864 debug information. There are two metadata primitives: strings and nodes.
2865
2866 Metadata does not have a type, and is not a value.  If referenced from a
2867 ``call`` instruction, it uses the ``metadata`` type.
2868
2869 All metadata are identified in syntax by a exclamation point ('``!``').
2870
2871 .. _metadata-string:
2872
2873 Metadata Nodes and Metadata Strings
2874 -----------------------------------
2875
2876 A metadata string is a string surrounded by double quotes. It can
2877 contain any character by escaping non-printable characters with
2878 "``\xx``" where "``xx``" is the two digit hex code. For example:
2879 "``!"test\00"``".
2880
2881 Metadata nodes are represented with notation similar to structure
2882 constants (a comma separated list of elements, surrounded by braces and
2883 preceded by an exclamation point). Metadata nodes can have any values as
2884 their operand. For example:
2885
2886 .. code-block:: llvm
2887
2888     !{ !"test\00", i32 10}
2889
2890 Metadata nodes that aren't uniqued use the ``distinct`` keyword. For example:
2891
2892 .. code-block:: llvm
2893
2894     !0 = distinct !{!"test\00", i32 10}
2895
2896 ``distinct`` nodes are useful when nodes shouldn't be merged based on their
2897 content.  They can also occur when transformations cause uniquing collisions
2898 when metadata operands change.
2899
2900 A :ref:`named metadata <namedmetadatastructure>` is a collection of
2901 metadata nodes, which can be looked up in the module symbol table. For
2902 example:
2903
2904 .. code-block:: llvm
2905
2906     !foo = !{!4, !3}
2907
2908 Metadata can be used as function arguments. Here ``llvm.dbg.value``
2909 function is using two metadata arguments:
2910
2911 .. code-block:: llvm
2912
2913     call void @llvm.dbg.value(metadata !24, i64 0, metadata !25)
2914
2915 Metadata can be attached with an instruction. Here metadata ``!21`` is
2916 attached to the ``add`` instruction using the ``!dbg`` identifier:
2917
2918 .. code-block:: llvm
2919
2920     %indvar.next = add i64 %indvar, 1, !dbg !21
2921
2922 More information about specific metadata nodes recognized by the
2923 optimizers and code generator is found below.
2924
2925 .. _specialized-metadata:
2926
2927 Specialized Metadata Nodes
2928 ^^^^^^^^^^^^^^^^^^^^^^^^^^
2929
2930 Specialized metadata nodes are custom data structures in metadata (as opposed
2931 to generic tuples).  Their fields are labelled, and can be specified in any
2932 order.
2933
2934 These aren't inherently debug info centric, but currently all the specialized
2935 metadata nodes are related to debug info.
2936
2937 .. _DICompileUnit:
2938
2939 DICompileUnit
2940 """""""""""""
2941
2942 ``DICompileUnit`` nodes represent a compile unit.  The ``enums:``,
2943 ``retainedTypes:``, ``subprograms:``, ``globals:`` and ``imports:`` fields are
2944 tuples containing the debug info to be emitted along with the compile unit,
2945 regardless of code optimizations (some nodes are only emitted if there are
2946 references to them from instructions).
2947
2948 .. code-block:: llvm
2949
2950     !0 = !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang",
2951                         isOptimized: true, flags: "-O2", runtimeVersion: 2,
2952                         splitDebugFilename: "abc.debug", emissionKind: 1,
2953                         enums: !2, retainedTypes: !3, subprograms: !4,
2954                         globals: !5, imports: !6)
2955
2956 Compile unit descriptors provide the root scope for objects declared in a
2957 specific compilation unit.  File descriptors are defined using this scope.
2958 These descriptors are collected by a named metadata ``!llvm.dbg.cu``.  They
2959 keep track of subprograms, global variables, type information, and imported
2960 entities (declarations and namespaces).
2961
2962 .. _DIFile:
2963
2964 DIFile
2965 """"""
2966
2967 ``DIFile`` nodes represent files.  The ``filename:`` can include slashes.
2968
2969 .. code-block:: llvm
2970
2971     !0 = !DIFile(filename: "path/to/file", directory: "/path/to/dir")
2972
2973 Files are sometimes used in ``scope:`` fields, and are the only valid target
2974 for ``file:`` fields.
2975
2976 .. _DIBasicType:
2977
2978 DIBasicType
2979 """""""""""
2980
2981 ``DIBasicType`` nodes represent primitive types, such as ``int``, ``bool`` and
2982 ``float``.  ``tag:`` defaults to ``DW_TAG_base_type``.
2983
2984 .. code-block:: llvm
2985
2986     !0 = !DIBasicType(name: "unsigned char", size: 8, align: 8,
2987                       encoding: DW_ATE_unsigned_char)
2988     !1 = !DIBasicType(tag: DW_TAG_unspecified_type, name: "decltype(nullptr)")
2989
2990 The ``encoding:`` describes the details of the type.  Usually it's one of the
2991 following:
2992
2993 .. code-block:: llvm
2994
2995   DW_ATE_address       = 1
2996   DW_ATE_boolean       = 2
2997   DW_ATE_float         = 4
2998   DW_ATE_signed        = 5
2999   DW_ATE_signed_char   = 6
3000   DW_ATE_unsigned      = 7
3001   DW_ATE_unsigned_char = 8
3002
3003 .. _DISubroutineType:
3004
3005 DISubroutineType
3006 """"""""""""""""
3007
3008 ``DISubroutineType`` nodes represent subroutine types.  Their ``types:`` field
3009 refers to a tuple; the first operand is the return type, while the rest are the
3010 types of the formal arguments in order.  If the first operand is ``null``, that
3011 represents a function with no return value (such as ``void foo() {}`` in C++).
3012
3013 .. code-block:: llvm
3014
3015     !0 = !BasicType(name: "int", size: 32, align: 32, DW_ATE_signed)
3016     !1 = !BasicType(name: "char", size: 8, align: 8, DW_ATE_signed_char)
3017     !2 = !DISubroutineType(types: !{null, !0, !1}) ; void (int, char)
3018
3019 .. _DIDerivedType:
3020
3021 DIDerivedType
3022 """""""""""""
3023
3024 ``DIDerivedType`` nodes represent types derived from other types, such as
3025 qualified types.
3026
3027 .. code-block:: llvm
3028
3029     !0 = !DIBasicType(name: "unsigned char", size: 8, align: 8,
3030                       encoding: DW_ATE_unsigned_char)
3031     !1 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !0, size: 32,
3032                         align: 32)
3033
3034 The following ``tag:`` values are valid:
3035
3036 .. code-block:: llvm
3037
3038   DW_TAG_formal_parameter   = 5
3039   DW_TAG_member             = 13
3040   DW_TAG_pointer_type       = 15
3041   DW_TAG_reference_type     = 16
3042   DW_TAG_typedef            = 22
3043   DW_TAG_ptr_to_member_type = 31
3044   DW_TAG_const_type         = 38
3045   DW_TAG_volatile_type      = 53
3046   DW_TAG_restrict_type      = 55
3047
3048 ``DW_TAG_member`` is used to define a member of a :ref:`composite type
3049 <DICompositeType>` or :ref:`subprogram <DISubprogram>`.  The type of the member
3050 is the ``baseType:``.  The ``offset:`` is the member's bit offset.
3051 ``DW_TAG_formal_parameter`` is used to define a member which is a formal
3052 argument of a subprogram.
3053
3054 ``DW_TAG_typedef`` is used to provide a name for the ``baseType:``.
3055
3056 ``DW_TAG_pointer_type``, ``DW_TAG_reference_type``, ``DW_TAG_const_type``,
3057 ``DW_TAG_volatile_type`` and ``DW_TAG_restrict_type`` are used to qualify the
3058 ``baseType:``.
3059
3060 Note that the ``void *`` type is expressed as a type derived from NULL.
3061
3062 .. _DICompositeType:
3063
3064 DICompositeType
3065 """""""""""""""
3066
3067 ``DICompositeType`` nodes represent types composed of other types, like
3068 structures and unions.  ``elements:`` points to a tuple of the composed types.
3069
3070 If the source language supports ODR, the ``identifier:`` field gives the unique
3071 identifier used for type merging between modules.  When specified, other types
3072 can refer to composite types indirectly via a :ref:`metadata string
3073 <metadata-string>` that matches their identifier.
3074
3075 .. code-block:: llvm
3076
3077     !0 = !DIEnumerator(name: "SixKind", value: 7)
3078     !1 = !DIEnumerator(name: "SevenKind", value: 7)
3079     !2 = !DIEnumerator(name: "NegEightKind", value: -8)
3080     !3 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "Enum", file: !12,
3081                           line: 2, size: 32, align: 32, identifier: "_M4Enum",
3082                           elements: !{!0, !1, !2})
3083
3084 The following ``tag:`` values are valid:
3085
3086 .. code-block:: llvm
3087
3088   DW_TAG_array_type       = 1
3089   DW_TAG_class_type       = 2
3090   DW_TAG_enumeration_type = 4
3091   DW_TAG_structure_type   = 19
3092   DW_TAG_union_type       = 23
3093   DW_TAG_subroutine_type  = 21
3094   DW_TAG_inheritance      = 28
3095
3096
3097 For ``DW_TAG_array_type``, the ``elements:`` should be :ref:`subrange
3098 descriptors <DISubrange>`, each representing the range of subscripts at that
3099 level of indexing.  The ``DIFlagVector`` flag to ``flags:`` indicates that an
3100 array type is a native packed vector.
3101
3102 For ``DW_TAG_enumeration_type``, the ``elements:`` should be :ref:`enumerator
3103 descriptors <DIEnumerator>`, each representing the definition of an enumeration
3104 value for the set.  All enumeration type descriptors are collected in the
3105 ``enums:`` field of the :ref:`compile unit <DICompileUnit>`.
3106
3107 For ``DW_TAG_structure_type``, ``DW_TAG_class_type``, and
3108 ``DW_TAG_union_type``, the ``elements:`` should be :ref:`derived types
3109 <DIDerivedType>` with ``tag: DW_TAG_member`` or ``tag: DW_TAG_inheritance``.
3110
3111 .. _DISubrange:
3112
3113 DISubrange
3114 """"""""""
3115
3116 ``DISubrange`` nodes are the elements for ``DW_TAG_array_type`` variants of
3117 :ref:`DICompositeType`.  ``count: -1`` indicates an empty array.
3118
3119 .. code-block:: llvm
3120
3121     !0 = !DISubrange(count: 5, lowerBound: 0) ; array counting from 0
3122     !1 = !DISubrange(count: 5, lowerBound: 1) ; array counting from 1
3123     !2 = !DISubrange(count: -1) ; empty array.
3124
3125 .. _DIEnumerator:
3126
3127 DIEnumerator
3128 """"""""""""
3129
3130 ``DIEnumerator`` nodes are the elements for ``DW_TAG_enumeration_type``
3131 variants of :ref:`DICompositeType`.
3132
3133 .. code-block:: llvm
3134
3135     !0 = !DIEnumerator(name: "SixKind", value: 7)
3136     !1 = !DIEnumerator(name: "SevenKind", value: 7)
3137     !2 = !DIEnumerator(name: "NegEightKind", value: -8)
3138
3139 DITemplateTypeParameter
3140 """""""""""""""""""""""
3141
3142 ``DITemplateTypeParameter`` nodes represent type parameters to generic source
3143 language constructs.  They are used (optionally) in :ref:`DICompositeType` and
3144 :ref:`DISubprogram` ``templateParams:`` fields.
3145
3146 .. code-block:: llvm
3147
3148     !0 = !DITemplateTypeParameter(name: "Ty", type: !1)
3149
3150 DITemplateValueParameter
3151 """"""""""""""""""""""""
3152
3153 ``DITemplateValueParameter`` nodes represent value parameters to generic source
3154 language constructs.  ``tag:`` defaults to ``DW_TAG_template_value_parameter``,
3155 but if specified can also be set to ``DW_TAG_GNU_template_template_param`` or
3156 ``DW_TAG_GNU_template_param_pack``.  They are used (optionally) in
3157 :ref:`DICompositeType` and :ref:`DISubprogram` ``templateParams:`` fields.
3158
3159 .. code-block:: llvm
3160
3161     !0 = !DITemplateValueParameter(name: "Ty", type: !1, value: i32 7)
3162
3163 DINamespace
3164 """""""""""
3165
3166 ``DINamespace`` nodes represent namespaces in the source language.
3167
3168 .. code-block:: llvm
3169
3170     !0 = !DINamespace(name: "myawesomeproject", scope: !1, file: !2, line: 7)
3171
3172 DIGlobalVariable
3173 """"""""""""""""
3174
3175 ``DIGlobalVariable`` nodes represent global variables in the source language.
3176
3177 .. code-block:: llvm
3178
3179     !0 = !DIGlobalVariable(name: "foo", linkageName: "foo", scope: !1,
3180                            file: !2, line: 7, type: !3, isLocal: true,
3181                            isDefinition: false, variable: i32* @foo,
3182                            declaration: !4)
3183
3184 All global variables should be referenced by the `globals:` field of a
3185 :ref:`compile unit <DICompileUnit>`.
3186
3187 .. _DISubprogram:
3188
3189 DISubprogram
3190 """"""""""""
3191
3192 ``DISubprogram`` nodes represent functions from the source language.  The
3193 ``variables:`` field points at :ref:`variables <DILocalVariable>` that must be
3194 retained, even if their IR counterparts are optimized out of the IR.  The
3195 ``type:`` field must point at an :ref:`DISubroutineType`.
3196
3197 .. code-block:: llvm
3198
3199     !0 = !DISubprogram(name: "foo", linkageName: "_Zfoov", scope: !1,
3200                        file: !2, line: 7, type: !3, isLocal: true,
3201                        isDefinition: false, scopeLine: 8, containingType: !4,
3202                        virtuality: DW_VIRTUALITY_pure_virtual, virtualIndex: 10,
3203                        flags: DIFlagPrototyped, isOptimized: true,
3204                        function: void ()* @_Z3foov,
3205                        templateParams: !5, declaration: !6, variables: !7)
3206
3207 .. _DILexicalBlock:
3208
3209 DILexicalBlock
3210 """"""""""""""
3211
3212 ``DILexicalBlock`` nodes describe nested blocks within a :ref:`subprogram
3213 <DISubprogram>`.  The line number and column numbers are used to dinstinguish
3214 two lexical blocks at same depth.  They are valid targets for ``scope:``
3215 fields.
3216
3217 .. code-block:: llvm
3218
3219     !0 = distinct !DILexicalBlock(scope: !1, file: !2, line: 7, column: 35)
3220
3221 Usually lexical blocks are ``distinct`` to prevent node merging based on
3222 operands.
3223
3224 .. _DILexicalBlockFile:
3225
3226 DILexicalBlockFile
3227 """"""""""""""""""
3228
3229 ``DILexicalBlockFile`` nodes are used to discriminate between sections of a
3230 :ref:`lexical block <DILexicalBlock>`.  The ``file:`` field can be changed to
3231 indicate textual inclusion, or the ``discriminator:`` field can be used to
3232 discriminate between control flow within a single block in the source language.
3233
3234 .. code-block:: llvm
3235
3236     !0 = !DILexicalBlock(scope: !3, file: !4, line: 7, column: 35)
3237     !1 = !DILexicalBlockFile(scope: !0, file: !4, discriminator: 0)
3238     !2 = !DILexicalBlockFile(scope: !0, file: !4, discriminator: 1)
3239
3240 .. _DILocation:
3241
3242 DILocation
3243 """"""""""
3244
3245 ``DILocation`` nodes represent source debug locations.  The ``scope:`` field is
3246 mandatory, and points at an :ref:`DILexicalBlockFile`, an
3247 :ref:`DILexicalBlock`, or an :ref:`DISubprogram`.
3248
3249 .. code-block:: llvm
3250
3251     !0 = !DILocation(line: 2900, column: 42, scope: !1, inlinedAt: !2)
3252
3253 .. _DILocalVariable:
3254
3255 DILocalVariable
3256 """""""""""""""
3257
3258 ``DILocalVariable`` nodes represent local variables in the source language.
3259 Instead of ``DW_TAG_variable``, they use LLVM-specific fake tags to
3260 discriminate between local variables (``DW_TAG_auto_variable``) and subprogram
3261 arguments (``DW_TAG_arg_variable``).  In the latter case, the ``arg:`` field
3262 specifies the argument position, and this variable will be included in the
3263 ``variables:`` field of its :ref:`DISubprogram`.
3264
3265 .. code-block:: llvm
3266
3267     !0 = !DILocalVariable(tag: DW_TAG_arg_variable, name: "this", arg: 0,
3268                           scope: !3, file: !2, line: 7, type: !3,
3269                           flags: DIFlagArtificial)
3270     !1 = !DILocalVariable(tag: DW_TAG_arg_variable, name: "x", arg: 1,
3271                           scope: !4, file: !2, line: 7, type: !3)
3272     !1 = !DILocalVariable(tag: DW_TAG_auto_variable, name: "y",
3273                           scope: !5, file: !2, line: 7, type: !3)
3274
3275 DIExpression
3276 """"""""""""
3277
3278 ``DIExpression`` nodes represent DWARF expression sequences.  They are used in
3279 :ref:`debug intrinsics<dbg_intrinsics>` (such as ``llvm.dbg.declare``) to
3280 describe how the referenced LLVM variable relates to the source language
3281 variable.
3282
3283 The current supported vocabulary is limited:
3284
3285 - ``DW_OP_deref`` dereferences the working expression.
3286 - ``DW_OP_plus, 93`` adds ``93`` to the working expression.
3287 - ``DW_OP_bit_piece, 16, 8`` specifies the offset and size (``16`` and ``8``
3288   here, respectively) of the variable piece from the working expression.
3289
3290 .. code-block:: llvm
3291
3292     !0 = !DIExpression(DW_OP_deref)
3293     !1 = !DIExpression(DW_OP_plus, 3)
3294     !2 = !DIExpression(DW_OP_bit_piece, 3, 7)
3295     !3 = !DIExpression(DW_OP_deref, DW_OP_plus, 3, DW_OP_bit_piece, 3, 7)
3296
3297 DIObjCProperty
3298 """"""""""""""
3299
3300 ``DIObjCProperty`` nodes represent Objective-C property nodes.
3301
3302 .. code-block:: llvm
3303
3304     !3 = !DIObjCProperty(name: "foo", file: !1, line: 7, setter: "setFoo",
3305                          getter: "getFoo", attributes: 7, type: !2)
3306
3307 DIImportedEntity
3308 """"""""""""""""
3309
3310 ``DIImportedEntity`` nodes represent entities (such as modules) imported into a
3311 compile unit.
3312
3313 .. code-block:: llvm
3314
3315    !2 = !DIImportedEntity(tag: DW_TAG_imported_module, name: "foo", scope: !0,
3316                           entity: !1, line: 7)
3317
3318 '``tbaa``' Metadata
3319 ^^^^^^^^^^^^^^^^^^^
3320
3321 In LLVM IR, memory does not have types, so LLVM's own type system is not
3322 suitable for doing TBAA. Instead, metadata is added to the IR to
3323 describe a type system of a higher level language. This can be used to
3324 implement typical C/C++ TBAA, but it can also be used to implement
3325 custom alias analysis behavior for other languages.
3326
3327 The current metadata format is very simple. TBAA metadata nodes have up
3328 to three fields, e.g.:
3329
3330 .. code-block:: llvm
3331
3332     !0 = !{ !"an example type tree" }
3333     !1 = !{ !"int", !0 }
3334     !2 = !{ !"float", !0 }
3335     !3 = !{ !"const float", !2, i64 1 }
3336
3337 The first field is an identity field. It can be any value, usually a
3338 metadata string, which uniquely identifies the type. The most important
3339 name in the tree is the name of the root node. Two trees with different
3340 root node names are entirely disjoint, even if they have leaves with
3341 common names.
3342
3343 The second field identifies the type's parent node in the tree, or is
3344 null or omitted for a root node. A type is considered to alias all of
3345 its descendants and all of its ancestors in the tree. Also, a type is
3346 considered to alias all types in other trees, so that bitcode produced
3347 from multiple front-ends is handled conservatively.
3348
3349 If the third field is present, it's an integer which if equal to 1
3350 indicates that the type is "constant" (meaning
3351 ``pointsToConstantMemory`` should return true; see `other useful
3352 AliasAnalysis methods <AliasAnalysis.html#OtherItfs>`_).
3353
3354 '``tbaa.struct``' Metadata
3355 ^^^^^^^^^^^^^^^^^^^^^^^^^^
3356
3357 The :ref:`llvm.memcpy <int_memcpy>` is often used to implement
3358 aggregate assignment operations in C and similar languages, however it
3359 is defined to copy a contiguous region of memory, which is more than
3360 strictly necessary for aggregate types which contain holes due to
3361 padding. Also, it doesn't contain any TBAA information about the fields
3362 of the aggregate.
3363
3364 ``!tbaa.struct`` metadata can describe which memory subregions in a
3365 memcpy are padding and what the TBAA tags of the struct are.
3366
3367 The current metadata format is very simple. ``!tbaa.struct`` metadata
3368 nodes are a list of operands which are in conceptual groups of three.
3369 For each group of three, the first operand gives the byte offset of a
3370 field in bytes, the second gives its size in bytes, and the third gives
3371 its tbaa tag. e.g.:
3372
3373 .. code-block:: llvm
3374
3375     !4 = !{ i64 0, i64 4, !1, i64 8, i64 4, !2 }
3376
3377 This describes a struct with two fields. The first is at offset 0 bytes
3378 with size 4 bytes, and has tbaa tag !1. The second is at offset 8 bytes
3379 and has size 4 bytes and has tbaa tag !2.
3380
3381 Note that the fields need not be contiguous. In this example, there is a
3382 4 byte gap between the two fields. This gap represents padding which
3383 does not carry useful data and need not be preserved.
3384
3385 '``noalias``' and '``alias.scope``' Metadata
3386 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3387
3388 ``noalias`` and ``alias.scope`` metadata provide the ability to specify generic
3389 noalias memory-access sets. This means that some collection of memory access
3390 instructions (loads, stores, memory-accessing calls, etc.) that carry
3391 ``noalias`` metadata can specifically be specified not to alias with some other
3392 collection of memory access instructions that carry ``alias.scope`` metadata.
3393 Each type of metadata specifies a list of scopes where each scope has an id and
3394 a domain. When evaluating an aliasing query, if for some domain, the set
3395 of scopes with that domain in one instruction's ``alias.scope`` list is a
3396 subset of (or equal to) the set of scopes for that domain in another
3397 instruction's ``noalias`` list, then the two memory accesses are assumed not to
3398 alias.
3399
3400 The metadata identifying each domain is itself a list containing one or two
3401 entries. The first entry is the name of the domain. Note that if the name is a
3402 string then it can be combined accross functions and translation units. A
3403 self-reference can be used to create globally unique domain names. A
3404 descriptive string may optionally be provided as a second list entry.
3405
3406 The metadata identifying each scope is also itself a list containing two or
3407 three entries. The first entry is the name of the scope. Note that if the name
3408 is a string then it can be combined accross functions and translation units. A
3409 self-reference can be used to create globally unique scope names. A metadata
3410 reference to the scope's domain is the second entry. A descriptive string may
3411 optionally be provided as a third list entry.
3412
3413 For example,
3414
3415 .. code-block:: llvm
3416
3417     ; Two scope domains:
3418     !0 = !{!0}
3419     !1 = !{!1}
3420
3421     ; Some scopes in these domains:
3422     !2 = !{!2, !0}
3423     !3 = !{!3, !0}
3424     !4 = !{!4, !1}
3425
3426     ; Some scope lists:
3427     !5 = !{!4} ; A list containing only scope !4
3428     !6 = !{!4, !3, !2}
3429     !7 = !{!3}
3430
3431     ; These two instructions don't alias:
3432     %0 = load float, float* %c, align 4, !alias.scope !5
3433     store float %0, float* %arrayidx.i, align 4, !noalias !5
3434
3435     ; These two instructions also don't alias (for domain !1, the set of scopes
3436     ; in the !alias.scope equals that in the !noalias list):
3437     %2 = load float, float* %c, align 4, !alias.scope !5
3438     store float %2, float* %arrayidx.i2, align 4, !noalias !6
3439
3440     ; These two instructions may alias (for domain !0, the set of scopes in
3441     ; the !noalias list is not a superset of, or equal to, the scopes in the
3442     ; !alias.scope list):
3443     %2 = load float, float* %c, align 4, !alias.scope !6
3444     store float %0, float* %arrayidx.i, align 4, !noalias !7
3445
3446 '``fpmath``' Metadata
3447 ^^^^^^^^^^^^^^^^^^^^^
3448
3449 ``fpmath`` metadata may be attached to any instruction of floating point
3450 type. It can be used to express the maximum acceptable error in the
3451 result of that instruction, in ULPs, thus potentially allowing the
3452 compiler to use a more efficient but less accurate method of computing
3453 it. ULP is defined as follows:
3454
3455     If ``x`` is a real number that lies between two finite consecutive
3456     floating-point numbers ``a`` and ``b``, without being equal to one
3457     of them, then ``ulp(x) = |b - a|``, otherwise ``ulp(x)`` is the
3458     distance between the two non-equal finite floating-point numbers
3459     nearest ``x``. Moreover, ``ulp(NaN)`` is ``NaN``.
3460
3461 The metadata node shall consist of a single positive floating point
3462 number representing the maximum relative error, for example:
3463
3464 .. code-block:: llvm
3465
3466     !0 = !{ float 2.5 } ; maximum acceptable inaccuracy is 2.5 ULPs
3467
3468 .. _range-metadata:
3469
3470 '``range``' Metadata
3471 ^^^^^^^^^^^^^^^^^^^^
3472
3473 ``range`` metadata may be attached only to ``load``, ``call`` and ``invoke`` of
3474 integer types. It expresses the possible ranges the loaded value or the value
3475 returned by the called function at this call site is in. The ranges are
3476 represented with a flattened list of integers. The loaded value or the value
3477 returned is known to be in the union of the ranges defined by each consecutive
3478 pair. Each pair has the following properties:
3479
3480 -  The type must match the type loaded by the instruction.
3481 -  The pair ``a,b`` represents the range ``[a,b)``.
3482 -  Both ``a`` and ``b`` are constants.
3483 -  The range is allowed to wrap.
3484 -  The range should not represent the full or empty set. That is,
3485    ``a!=b``.
3486
3487 In addition, the pairs must be in signed order of the lower bound and
3488 they must be non-contiguous.
3489
3490 Examples:
3491
3492 .. code-block:: llvm
3493
3494       %a = load i8, i8* %x, align 1, !range !0 ; Can only be 0 or 1
3495       %b = load i8, i8* %y, align 1, !range !1 ; Can only be 255 (-1), 0 or 1
3496       %c = call i8 @foo(),       !range !2 ; Can only be 0, 1, 3, 4 or 5
3497       %d = invoke i8 @bar() to label %cont
3498              unwind label %lpad, !range !3 ; Can only be -2, -1, 3, 4 or 5
3499     ...
3500     !0 = !{ i8 0, i8 2 }
3501     !1 = !{ i8 255, i8 2 }
3502     !2 = !{ i8 0, i8 2, i8 3, i8 6 }
3503     !3 = !{ i8 -2, i8 0, i8 3, i8 6 }
3504
3505 '``llvm.loop``'
3506 ^^^^^^^^^^^^^^^
3507
3508 It is sometimes useful to attach information to loop constructs. Currently,
3509 loop metadata is implemented as metadata attached to the branch instruction
3510 in the loop latch block. This type of metadata refer to a metadata node that is
3511 guaranteed to be separate for each loop. The loop identifier metadata is
3512 specified with the name ``llvm.loop``.
3513
3514 The loop identifier metadata is implemented using a metadata that refers to
3515 itself to avoid merging it with any other identifier metadata, e.g.,
3516 during module linkage or function inlining. That is, each loop should refer
3517 to their own identification metadata even if they reside in separate functions.
3518 The following example contains loop identifier metadata for two separate loop
3519 constructs:
3520
3521 .. code-block:: llvm
3522
3523     !0 = !{!0}
3524     !1 = !{!1}
3525
3526 The loop identifier metadata can be used to specify additional
3527 per-loop metadata. Any operands after the first operand can be treated
3528 as user-defined metadata. For example the ``llvm.loop.unroll.count``
3529 suggests an unroll factor to the loop unroller:
3530
3531 .. code-block:: llvm
3532
3533       br i1 %exitcond, label %._crit_edge, label %.lr.ph, !llvm.loop !0
3534     ...
3535     !0 = !{!0, !1}
3536     !1 = !{!"llvm.loop.unroll.count", i32 4}
3537
3538 '``llvm.loop.vectorize``' and '``llvm.loop.interleave``'
3539 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3540
3541 Metadata prefixed with ``llvm.loop.vectorize`` or ``llvm.loop.interleave`` are
3542 used to control per-loop vectorization and interleaving parameters such as
3543 vectorization width and interleave count.  These metadata should be used in
3544 conjunction with ``llvm.loop`` loop identification metadata.  The
3545 ``llvm.loop.vectorize`` and ``llvm.loop.interleave`` metadata are only
3546 optimization hints and the optimizer will only interleave and vectorize loops if
3547 it believes it is safe to do so.  The ``llvm.mem.parallel_loop_access`` metadata
3548 which contains information about loop-carried memory dependencies can be helpful
3549 in determining the safety of these transformations.
3550
3551 '``llvm.loop.interleave.count``' Metadata
3552 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3553
3554 This metadata suggests an interleave count to the loop interleaver.
3555 The first operand is the string ``llvm.loop.interleave.count`` and the
3556 second operand is an integer specifying the interleave count. For
3557 example:
3558
3559 .. code-block:: llvm
3560
3561    !0 = !{!"llvm.loop.interleave.count", i32 4}
3562
3563 Note that setting ``llvm.loop.interleave.count`` to 1 disables interleaving
3564 multiple iterations of the loop.  If ``llvm.loop.interleave.count`` is set to 0
3565 then the interleave count will be determined automatically.
3566
3567 '``llvm.loop.vectorize.enable``' Metadata
3568 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3569
3570 This metadata selectively enables or disables vectorization for the loop. The
3571 first operand is the string ``llvm.loop.vectorize.enable`` and the second operand
3572 is a bit.  If the bit operand value is 1 vectorization is enabled. A value of
3573 0 disables vectorization:
3574
3575 .. code-block:: llvm
3576
3577    !0 = !{!"llvm.loop.vectorize.enable", i1 0}
3578    !1 = !{!"llvm.loop.vectorize.enable", i1 1}
3579
3580 '``llvm.loop.vectorize.width``' Metadata
3581 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3582
3583 This metadata sets the target width of the vectorizer. The first
3584 operand is the string ``llvm.loop.vectorize.width`` and the second
3585 operand is an integer specifying the width. For example:
3586
3587 .. code-block:: llvm
3588
3589    !0 = !{!"llvm.loop.vectorize.width", i32 4}
3590
3591 Note that setting ``llvm.loop.vectorize.width`` to 1 disables
3592 vectorization of the loop.  If ``llvm.loop.vectorize.width`` is set to
3593 0 or if the loop does not have this metadata the width will be
3594 determined automatically.
3595
3596 '``llvm.loop.unroll``'
3597 ^^^^^^^^^^^^^^^^^^^^^^
3598
3599 Metadata prefixed with ``llvm.loop.unroll`` are loop unrolling
3600 optimization hints such as the unroll factor. ``llvm.loop.unroll``
3601 metadata should be used in conjunction with ``llvm.loop`` loop
3602 identification metadata. The ``llvm.loop.unroll`` metadata are only
3603 optimization hints and the unrolling will only be performed if the
3604 optimizer believes it is safe to do so.
3605
3606 '``llvm.loop.unroll.count``' Metadata
3607 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3608
3609 This metadata suggests an unroll factor to the loop unroller. The
3610 first operand is the string ``llvm.loop.unroll.count`` and the second
3611 operand is a positive integer specifying the unroll factor. For
3612 example:
3613
3614 .. code-block:: llvm
3615
3616    !0 = !{!"llvm.loop.unroll.count", i32 4}
3617
3618 If the trip count of the loop is less than the unroll count the loop
3619 will be partially unrolled.
3620
3621 '``llvm.loop.unroll.disable``' Metadata
3622 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3623
3624 This metadata either disables loop unrolling. The metadata has a single operand
3625 which is the string ``llvm.loop.unroll.disable``.  For example:
3626
3627 .. code-block:: llvm
3628
3629    !0 = !{!"llvm.loop.unroll.disable"}
3630
3631 '``llvm.loop.unroll.runtime.disable``' Metadata
3632 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3633
3634 This metadata either disables runtime loop unrolling. The metadata has a single
3635 operand which is the string ``llvm.loop.unroll.runtime.disable``.  For example:
3636
3637 .. code-block:: llvm
3638
3639    !0 = !{!"llvm.loop.unroll.runtime.disable"}
3640
3641 '``llvm.loop.unroll.full``' Metadata
3642 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3643
3644 This metadata either suggests that the loop should be unrolled fully. The
3645 metadata has a single operand which is the string ``llvm.loop.unroll.disable``.
3646 For example:
3647
3648 .. code-block:: llvm
3649
3650    !0 = !{!"llvm.loop.unroll.full"}
3651
3652 '``llvm.mem``'
3653 ^^^^^^^^^^^^^^^
3654
3655 Metadata types used to annotate memory accesses with information helpful
3656 for optimizations are prefixed with ``llvm.mem``.
3657
3658 '``llvm.mem.parallel_loop_access``' Metadata
3659 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3660
3661 The ``llvm.mem.parallel_loop_access`` metadata refers to a loop identifier,
3662 or metadata containing a list of loop identifiers for nested loops.
3663 The metadata is attached to memory accessing instructions and denotes that
3664 no loop carried memory dependence exist between it and other instructions denoted
3665 with the same loop identifier.
3666
3667 Precisely, given two instructions ``m1`` and ``m2`` that both have the
3668 ``llvm.mem.parallel_loop_access`` metadata, with ``L1`` and ``L2`` being the
3669 set of loops associated with that metadata, respectively, then there is no loop
3670 carried dependence between ``m1`` and ``m2`` for loops in both ``L1`` and
3671 ``L2``.
3672
3673 As a special case, if all memory accessing instructions in a loop have
3674 ``llvm.mem.parallel_loop_access`` metadata that refers to that loop, then the
3675 loop has no loop carried memory dependences and is considered to be a parallel
3676 loop.
3677
3678 Note that if not all memory access instructions have such metadata referring to
3679 the loop, then the loop is considered not being trivially parallel. Additional
3680 memory dependence analysis is required to make that determination.  As a fail
3681 safe mechanism, this causes loops that were originally parallel to be considered
3682 sequential (if optimization passes that are unaware of the parallel semantics
3683 insert new memory instructions into the loop body).
3684
3685 Example of a loop that is considered parallel due to its correct use of
3686 both ``llvm.loop`` and ``llvm.mem.parallel_loop_access``
3687 metadata types that refer to the same loop identifier metadata.
3688
3689 .. code-block:: llvm
3690
3691    for.body:
3692      ...
3693      %val0 = load i32, i32* %arrayidx, !llvm.mem.parallel_loop_access !0
3694      ...
3695      store i32 %val0, i32* %arrayidx1, !llvm.mem.parallel_loop_access !0
3696      ...
3697      br i1 %exitcond, label %for.end, label %for.body, !llvm.loop !0
3698
3699    for.end:
3700    ...
3701    !0 = !{!0}
3702
3703 It is also possible to have nested parallel loops. In that case the
3704 memory accesses refer to a list of loop identifier metadata nodes instead of
3705 the loop identifier metadata node directly:
3706
3707 .. code-block:: llvm
3708
3709    outer.for.body:
3710      ...
3711      %val1 = load i32, i32* %arrayidx3, !llvm.mem.parallel_loop_access !2
3712      ...
3713      br label %inner.for.body
3714
3715    inner.for.body:
3716      ...
3717      %val0 = load i32, i32* %arrayidx1, !llvm.mem.parallel_loop_access !0
3718      ...
3719      store i32 %val0, i32* %arrayidx2, !llvm.mem.parallel_loop_access !0
3720      ...
3721      br i1 %exitcond, label %inner.for.end, label %inner.for.body, !llvm.loop !1
3722
3723    inner.for.end:
3724      ...
3725      store i32 %val1, i32* %arrayidx4, !llvm.mem.parallel_loop_access !2
3726      ...
3727      br i1 %exitcond, label %outer.for.end, label %outer.for.body, !llvm.loop !2
3728
3729    outer.for.end:                                          ; preds = %for.body
3730    ...
3731    !0 = !{!1, !2} ; a list of loop identifiers
3732    !1 = !{!1} ; an identifier for the inner loop
3733    !2 = !{!2} ; an identifier for the outer loop
3734
3735 '``llvm.bitsets``'
3736 ^^^^^^^^^^^^^^^^^^
3737
3738 The ``llvm.bitsets`` global metadata is used to implement
3739 :doc:`bitsets <BitSets>`.
3740
3741 Module Flags Metadata
3742 =====================
3743
3744 Information about the module as a whole is difficult to convey to LLVM's
3745 subsystems. The LLVM IR isn't sufficient to transmit this information.
3746 The ``llvm.module.flags`` named metadata exists in order to facilitate
3747 this. These flags are in the form of key / value pairs --- much like a
3748 dictionary --- making it easy for any subsystem who cares about a flag to
3749 look it up.
3750
3751 The ``llvm.module.flags`` metadata contains a list of metadata triplets.
3752 Each triplet has the following form:
3753
3754 -  The first element is a *behavior* flag, which specifies the behavior
3755    when two (or more) modules are merged together, and it encounters two
3756    (or more) metadata with the same ID. The supported behaviors are
3757    described below.
3758 -  The second element is a metadata string that is a unique ID for the
3759    metadata. Each module may only have one flag entry for each unique ID (not
3760    including entries with the **Require** behavior).
3761 -  The third element is the value of the flag.
3762
3763 When two (or more) modules are merged together, the resulting
3764 ``llvm.module.flags`` metadata is the union of the modules' flags. That is, for
3765 each unique metadata ID string, there will be exactly one entry in the merged
3766 modules ``llvm.module.flags`` metadata table, and the value for that entry will
3767 be determined by the merge behavior flag, as described below. The only exception
3768 is that entries with the *Require* behavior are always preserved.
3769
3770 The following behaviors are supported:
3771
3772 .. list-table::
3773    :header-rows: 1
3774    :widths: 10 90
3775
3776    * - Value
3777      - Behavior
3778
3779    * - 1
3780      - **Error**
3781            Emits an error if two values disagree, otherwise the resulting value
3782            is that of the operands.
3783
3784    * - 2
3785      - **Warning**
3786            Emits a warning if two values disagree. The result value will be the
3787            operand for the flag from the first module being linked.
3788
3789    * - 3
3790      - **Require**
3791            Adds a requirement that another module flag be present and have a
3792            specified value after linking is performed. The value must be a
3793            metadata pair, where the first element of the pair is the ID of the
3794            module flag to be restricted, and the second element of the pair is
3795            the value the module flag should be restricted to. This behavior can
3796            be used to restrict the allowable results (via triggering of an
3797            error) of linking IDs with the **Override** behavior.
3798
3799    * - 4
3800      - **Override**
3801            Uses the specified value, regardless of the behavior or value of the
3802            other module. If both modules specify **Override**, but the values
3803            differ, an error will be emitted.
3804
3805    * - 5
3806      - **Append**
3807            Appends the two values, which are required to be metadata nodes.
3808
3809    * - 6
3810      - **AppendUnique**
3811            Appends the two values, which are required to be metadata
3812            nodes. However, duplicate entries in the second list are dropped
3813            during the append operation.
3814
3815 It is an error for a particular unique flag ID to have multiple behaviors,
3816 except in the case of **Require** (which adds restrictions on another metadata
3817 value) or **Override**.
3818
3819 An example of module flags:
3820
3821 .. code-block:: llvm
3822
3823     !0 = !{ i32 1, !"foo", i32 1 }
3824     !1 = !{ i32 4, !"bar", i32 37 }
3825     !2 = !{ i32 2, !"qux", i32 42 }
3826     !3 = !{ i32 3, !"qux",
3827       !{
3828         !"foo", i32 1
3829       }
3830     }
3831     !llvm.module.flags = !{ !0, !1, !2, !3 }
3832
3833 -  Metadata ``!0`` has the ID ``!"foo"`` and the value '1'. The behavior
3834    if two or more ``!"foo"`` flags are seen is to emit an error if their
3835    values are not equal.
3836
3837 -  Metadata ``!1`` has the ID ``!"bar"`` and the value '37'. The
3838    behavior if two or more ``!"bar"`` flags are seen is to use the value
3839    '37'.
3840
3841 -  Metadata ``!2`` has the ID ``!"qux"`` and the value '42'. The
3842    behavior if two or more ``!"qux"`` flags are seen is to emit a
3843    warning if their values are not equal.
3844
3845 -  Metadata ``!3`` has the ID ``!"qux"`` and the value:
3846
3847    ::
3848
3849        !{ !"foo", i32 1 }
3850
3851    The behavior is to emit an error if the ``llvm.module.flags`` does not
3852    contain a flag with the ID ``!"foo"`` that has the value '1' after linking is
3853    performed.
3854
3855 Objective-C Garbage Collection Module Flags Metadata
3856 ----------------------------------------------------
3857
3858 On the Mach-O platform, Objective-C stores metadata about garbage
3859 collection in a special section called "image info". The metadata
3860 consists of a version number and a bitmask specifying what types of
3861 garbage collection are supported (if any) by the file. If two or more
3862 modules are linked together their garbage collection metadata needs to
3863 be merged rather than appended together.
3864
3865 The Objective-C garbage collection module flags metadata consists of the
3866 following key-value pairs:
3867
3868 .. list-table::
3869    :header-rows: 1
3870    :widths: 30 70
3871
3872    * - Key
3873      - Value
3874
3875    * - ``Objective-C Version``
3876      - **[Required]** --- The Objective-C ABI version. Valid values are 1 and 2.
3877
3878    * - ``Objective-C Image Info Version``
3879      - **[Required]** --- The version of the image info section. Currently
3880        always 0.
3881
3882    * - ``Objective-C Image Info Section``
3883      - **[Required]** --- The section to place the metadata. Valid values are
3884        ``"__OBJC, __image_info, regular"`` for Objective-C ABI version 1, and
3885        ``"__DATA,__objc_imageinfo, regular, no_dead_strip"`` for
3886        Objective-C ABI version 2.
3887
3888    * - ``Objective-C Garbage Collection``
3889      - **[Required]** --- Specifies whether garbage collection is supported or
3890        not. Valid values are 0, for no garbage collection, and 2, for garbage
3891        collection supported.
3892
3893    * - ``Objective-C GC Only``
3894      - **[Optional]** --- Specifies that only garbage collection is supported.
3895        If present, its value must be 6. This flag requires that the
3896        ``Objective-C Garbage Collection`` flag have the value 2.
3897
3898 Some important flag interactions:
3899
3900 -  If a module with ``Objective-C Garbage Collection`` set to 0 is
3901    merged with a module with ``Objective-C Garbage Collection`` set to
3902    2, then the resulting module has the
3903    ``Objective-C Garbage Collection`` flag set to 0.
3904 -  A module with ``Objective-C Garbage Collection`` set to 0 cannot be
3905    merged with a module with ``Objective-C GC Only`` set to 6.
3906
3907 Automatic Linker Flags Module Flags Metadata
3908 --------------------------------------------
3909
3910 Some targets support embedding flags to the linker inside individual object
3911 files. Typically this is used in conjunction with language extensions which
3912 allow source files to explicitly declare the libraries they depend on, and have
3913 these automatically be transmitted to the linker via object files.
3914
3915 These flags are encoded in the IR using metadata in the module flags section,
3916 using the ``Linker Options`` key. The merge behavior for this flag is required
3917 to be ``AppendUnique``, and the value for the key is expected to be a metadata
3918 node which should be a list of other metadata nodes, each of which should be a
3919 list of metadata strings defining linker options.
3920
3921 For example, the following metadata section specifies two separate sets of
3922 linker options, presumably to link against ``libz`` and the ``Cocoa``
3923 framework::
3924
3925     !0 = !{ i32 6, !"Linker Options",
3926        !{
3927           !{ !"-lz" },
3928           !{ !"-framework", !"Cocoa" } } }
3929     !llvm.module.flags = !{ !0 }
3930
3931 The metadata encoding as lists of lists of options, as opposed to a collapsed
3932 list of options, is chosen so that the IR encoding can use multiple option
3933 strings to specify e.g., a single library, while still having that specifier be
3934 preserved as an atomic element that can be recognized by a target specific
3935 assembly writer or object file emitter.
3936
3937 Each individual option is required to be either a valid option for the target's
3938 linker, or an option that is reserved by the target specific assembly writer or
3939 object file emitter. No other aspect of these options is defined by the IR.
3940
3941 C type width Module Flags Metadata
3942 ----------------------------------
3943
3944 The ARM backend emits a section into each generated object file describing the
3945 options that it was compiled with (in a compiler-independent way) to prevent
3946 linking incompatible objects, and to allow automatic library selection. Some
3947 of these options are not visible at the IR level, namely wchar_t width and enum
3948 width.
3949
3950 To pass this information to the backend, these options are encoded in module
3951 flags metadata, using the following key-value pairs:
3952
3953 .. list-table::
3954    :header-rows: 1
3955    :widths: 30 70
3956
3957    * - Key
3958      - Value
3959
3960    * - short_wchar
3961      - * 0 --- sizeof(wchar_t) == 4
3962        * 1 --- sizeof(wchar_t) == 2
3963
3964    * - short_enum
3965      - * 0 --- Enums are at least as large as an ``int``.
3966        * 1 --- Enums are stored in the smallest integer type which can
3967          represent all of its values.
3968
3969 For example, the following metadata section specifies that the module was
3970 compiled with a ``wchar_t`` width of 4 bytes, and the underlying type of an
3971 enum is the smallest type which can represent all of its values::
3972
3973     !llvm.module.flags = !{!0, !1}
3974     !0 = !{i32 1, !"short_wchar", i32 1}
3975     !1 = !{i32 1, !"short_enum", i32 0}
3976
3977 .. _intrinsicglobalvariables:
3978
3979 Intrinsic Global Variables
3980 ==========================
3981
3982 LLVM has a number of "magic" global variables that contain data that
3983 affect code generation or other IR semantics. These are documented here.
3984 All globals of this sort should have a section specified as
3985 "``llvm.metadata``". This section and all globals that start with
3986 "``llvm.``" are reserved for use by LLVM.
3987
3988 .. _gv_llvmused:
3989
3990 The '``llvm.used``' Global Variable
3991 -----------------------------------
3992
3993 The ``@llvm.used`` global is an array which has
3994 :ref:`appending linkage <linkage_appending>`. This array contains a list of
3995 pointers to named global variables, functions and aliases which may optionally
3996 have a pointer cast formed of bitcast or getelementptr. For example, a legal
3997 use of it is:
3998
3999 .. code-block:: llvm
4000
4001     @X = global i8 4
4002     @Y = global i32 123
4003
4004     @llvm.used = appending global [2 x i8*] [
4005        i8* @X,
4006        i8* bitcast (i32* @Y to i8*)
4007     ], section "llvm.metadata"
4008
4009 If a symbol appears in the ``@llvm.used`` list, then the compiler, assembler,
4010 and linker are required to treat the symbol as if there is a reference to the
4011 symbol that it cannot see (which is why they have to be named). For example, if
4012 a variable has internal linkage and no references other than that from the
4013 ``@llvm.used`` list, it cannot be deleted. This is commonly used to represent
4014 references from inline asms and other things the compiler cannot "see", and
4015 corresponds to "``attribute((used))``" in GNU C.
4016
4017 On some targets, the code generator must emit a directive to the
4018 assembler or object file to prevent the assembler and linker from
4019 molesting the symbol.
4020
4021 .. _gv_llvmcompilerused:
4022
4023 The '``llvm.compiler.used``' Global Variable
4024 --------------------------------------------
4025
4026 The ``@llvm.compiler.used`` directive is the same as the ``@llvm.used``
4027 directive, except that it only prevents the compiler from touching the
4028 symbol. On targets that support it, this allows an intelligent linker to
4029 optimize references to the symbol without being impeded as it would be
4030 by ``@llvm.used``.
4031
4032 This is a rare construct that should only be used in rare circumstances,
4033 and should not be exposed to source languages.
4034
4035 .. _gv_llvmglobalctors:
4036
4037 The '``llvm.global_ctors``' Global Variable
4038 -------------------------------------------
4039
4040 .. code-block:: llvm
4041
4042     %0 = type { i32, void ()*, i8* }
4043     @llvm.global_ctors = appending global [1 x %0] [%0 { i32 65535, void ()* @ctor, i8* @data }]
4044
4045 The ``@llvm.global_ctors`` array contains a list of constructor
4046 functions, priorities, and an optional associated global or function.
4047 The functions referenced by this array will be called in ascending order
4048 of priority (i.e. lowest first) when the module is loaded. The order of
4049 functions with the same priority is not defined.
4050
4051 If the third field is present, non-null, and points to a global variable
4052 or function, the initializer function will only run if the associated
4053 data from the current module is not discarded.
4054
4055 .. _llvmglobaldtors:
4056
4057 The '``llvm.global_dtors``' Global Variable
4058 -------------------------------------------
4059
4060 .. code-block:: llvm
4061
4062     %0 = type { i32, void ()*, i8* }
4063     @llvm.global_dtors = appending global [1 x %0] [%0 { i32 65535, void ()* @dtor, i8* @data }]
4064
4065 The ``@llvm.global_dtors`` array contains a list of destructor
4066 functions, priorities, and an optional associated global or function.
4067 The functions referenced by this array will be called in descending
4068 order of priority (i.e. highest first) when the module is unloaded. The
4069 order of functions with the same priority is not defined.
4070
4071 If the third field is present, non-null, and points to a global variable
4072 or function, the destructor function will only run if the associated
4073 data from the current module is not discarded.
4074
4075 Instruction Reference
4076 =====================
4077
4078 The LLVM instruction set consists of several different classifications
4079 of instructions: :ref:`terminator instructions <terminators>`, :ref:`binary
4080 instructions <binaryops>`, :ref:`bitwise binary
4081 instructions <bitwiseops>`, :ref:`memory instructions <memoryops>`, and
4082 :ref:`other instructions <otherops>`.
4083
4084 .. _terminators:
4085
4086 Terminator Instructions
4087 -----------------------
4088
4089 As mentioned :ref:`previously <functionstructure>`, every basic block in a
4090 program ends with a "Terminator" instruction, which indicates which
4091 block should be executed after the current block is finished. These
4092 terminator instructions typically yield a '``void``' value: they produce
4093 control flow, not values (the one exception being the
4094 ':ref:`invoke <i_invoke>`' instruction).
4095
4096 The terminator instructions are: ':ref:`ret <i_ret>`',
4097 ':ref:`br <i_br>`', ':ref:`switch <i_switch>`',
4098 ':ref:`indirectbr <i_indirectbr>`', ':ref:`invoke <i_invoke>`',
4099 ':ref:`resume <i_resume>`', and ':ref:`unreachable <i_unreachable>`'.
4100
4101 .. _i_ret:
4102
4103 '``ret``' Instruction
4104 ^^^^^^^^^^^^^^^^^^^^^
4105
4106 Syntax:
4107 """""""
4108
4109 ::
4110
4111       ret <type> <value>       ; Return a value from a non-void function
4112       ret void                 ; Return from void function
4113
4114 Overview:
4115 """""""""
4116
4117 The '``ret``' instruction is used to return control flow (and optionally
4118 a value) from a function back to the caller.
4119
4120 There are two forms of the '``ret``' instruction: one that returns a
4121 value and then causes control flow, and one that just causes control
4122 flow to occur.
4123
4124 Arguments:
4125 """"""""""
4126
4127 The '``ret``' instruction optionally accepts a single argument, the
4128 return value. The type of the return value must be a ':ref:`first
4129 class <t_firstclass>`' type.
4130
4131 A function is not :ref:`well formed <wellformed>` if it it has a non-void
4132 return type and contains a '``ret``' instruction with no return value or
4133 a return value with a type that does not match its type, or if it has a
4134 void return type and contains a '``ret``' instruction with a return
4135 value.
4136
4137 Semantics:
4138 """"""""""
4139
4140 When the '``ret``' instruction is executed, control flow returns back to
4141 the calling function's context. If the caller is a
4142 ":ref:`call <i_call>`" instruction, execution continues at the
4143 instruction after the call. If the caller was an
4144 ":ref:`invoke <i_invoke>`" instruction, execution continues at the
4145 beginning of the "normal" destination block. If the instruction returns
4146 a value, that value shall set the call or invoke instruction's return
4147 value.
4148
4149 Example:
4150 """"""""
4151
4152 .. code-block:: llvm
4153
4154       ret i32 5                       ; Return an integer value of 5
4155       ret void                        ; Return from a void function
4156       ret { i32, i8 } { i32 4, i8 2 } ; Return a struct of values 4 and 2
4157
4158 .. _i_br:
4159
4160 '``br``' Instruction
4161 ^^^^^^^^^^^^^^^^^^^^
4162
4163 Syntax:
4164 """""""
4165
4166 ::
4167
4168       br i1 <cond>, label <iftrue>, label <iffalse>
4169       br label <dest>          ; Unconditional branch
4170
4171 Overview:
4172 """""""""
4173
4174 The '``br``' instruction is used to cause control flow to transfer to a
4175 different basic block in the current function. There are two forms of
4176 this instruction, corresponding to a conditional branch and an
4177 unconditional branch.
4178
4179 Arguments:
4180 """"""""""
4181
4182 The conditional branch form of the '``br``' instruction takes a single
4183 '``i1``' value and two '``label``' values. The unconditional form of the
4184 '``br``' instruction takes a single '``label``' value as a target.
4185
4186 Semantics:
4187 """"""""""
4188
4189 Upon execution of a conditional '``br``' instruction, the '``i1``'
4190 argument is evaluated. If the value is ``true``, control flows to the
4191 '``iftrue``' ``label`` argument. If "cond" is ``false``, control flows
4192 to the '``iffalse``' ``label`` argument.
4193
4194 Example:
4195 """"""""
4196
4197 .. code-block:: llvm
4198
4199     Test:
4200       %cond = icmp eq i32 %a, %b
4201       br i1 %cond, label %IfEqual, label %IfUnequal
4202     IfEqual:
4203       ret i32 1
4204     IfUnequal:
4205       ret i32 0
4206
4207 .. _i_switch:
4208
4209 '``switch``' Instruction
4210 ^^^^^^^^^^^^^^^^^^^^^^^^
4211
4212 Syntax:
4213 """""""
4214
4215 ::
4216
4217       switch <intty> <value>, label <defaultdest> [ <intty> <val>, label <dest> ... ]
4218
4219 Overview:
4220 """""""""
4221
4222 The '``switch``' instruction is used to transfer control flow to one of
4223 several different places. It is a generalization of the '``br``'
4224 instruction, allowing a branch to occur to one of many possible
4225 destinations.
4226
4227 Arguments:
4228 """"""""""
4229
4230 The '``switch``' instruction uses three parameters: an integer
4231 comparison value '``value``', a default '``label``' destination, and an
4232 array of pairs of comparison value constants and '``label``'s. The table
4233 is not allowed to contain duplicate constant entries.
4234
4235 Semantics:
4236 """"""""""
4237
4238 The ``switch`` instruction specifies a table of values and destinations.
4239 When the '``switch``' instruction is executed, this table is searched
4240 for the given value. If the value is found, control flow is transferred
4241 to the corresponding destination; otherwise, control flow is transferred
4242 to the default destination.
4243
4244 Implementation:
4245 """""""""""""""
4246
4247 Depending on properties of the target machine and the particular
4248 ``switch`` instruction, this instruction may be code generated in
4249 different ways. For example, it could be generated as a series of
4250 chained conditional branches or with a lookup table.
4251
4252 Example:
4253 """"""""
4254
4255 .. code-block:: llvm
4256
4257      ; Emulate a conditional br instruction
4258      %Val = zext i1 %value to i32
4259      switch i32 %Val, label %truedest [ i32 0, label %falsedest ]
4260
4261      ; Emulate an unconditional br instruction
4262      switch i32 0, label %dest [ ]
4263
4264      ; Implement a jump table:
4265      switch i32 %val, label %otherwise [ i32 0, label %onzero
4266                                          i32 1, label %onone
4267                                          i32 2, label %ontwo ]
4268
4269 .. _i_indirectbr:
4270
4271 '``indirectbr``' Instruction
4272 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4273
4274 Syntax:
4275 """""""
4276
4277 ::
4278
4279       indirectbr <somety>* <address>, [ label <dest1>, label <dest2>, ... ]
4280
4281 Overview:
4282 """""""""
4283
4284 The '``indirectbr``' instruction implements an indirect branch to a
4285 label within the current function, whose address is specified by
4286 "``address``". Address must be derived from a
4287 :ref:`blockaddress <blockaddress>` constant.
4288
4289 Arguments:
4290 """"""""""
4291
4292 The '``address``' argument is the address of the label to jump to. The
4293 rest of the arguments indicate the full set of possible destinations
4294 that the address may point to. Blocks are allowed to occur multiple
4295 times in the destination list, though this isn't particularly useful.
4296
4297 This destination list is required so that dataflow analysis has an
4298 accurate understanding of the CFG.
4299
4300 Semantics:
4301 """"""""""
4302
4303 Control transfers to the block specified in the address argument. All
4304 possible destination blocks must be listed in the label list, otherwise
4305 this instruction has undefined behavior. This implies that jumps to
4306 labels defined in other functions have undefined behavior as well.
4307
4308 Implementation:
4309 """""""""""""""
4310
4311 This is typically implemented with a jump through a register.
4312
4313 Example:
4314 """"""""
4315
4316 .. code-block:: llvm
4317
4318      indirectbr i8* %Addr, [ label %bb1, label %bb2, label %bb3 ]
4319
4320 .. _i_invoke:
4321
4322 '``invoke``' Instruction
4323 ^^^^^^^^^^^^^^^^^^^^^^^^
4324
4325 Syntax:
4326 """""""
4327
4328 ::
4329
4330       <result> = invoke [cconv] [ret attrs] <ptr to function ty> <function ptr val>(<function args>) [fn attrs]
4331                     to label <normal label> unwind label <exception label>
4332
4333 Overview:
4334 """""""""
4335
4336 The '``invoke``' instruction causes control to transfer to a specified
4337 function, with the possibility of control flow transfer to either the
4338 '``normal``' label or the '``exception``' label. If the callee function
4339 returns with the "``ret``" instruction, control flow will return to the
4340 "normal" label. If the callee (or any indirect callees) returns via the
4341 ":ref:`resume <i_resume>`" instruction or other exception handling
4342 mechanism, control is interrupted and continued at the dynamically
4343 nearest "exception" label.
4344
4345 The '``exception``' label is a `landing
4346 pad <ExceptionHandling.html#overview>`_ for the exception. As such,
4347 '``exception``' label is required to have the
4348 ":ref:`landingpad <i_landingpad>`" instruction, which contains the
4349 information about the behavior of the program after unwinding happens,
4350 as its first non-PHI instruction. The restrictions on the
4351 "``landingpad``" instruction's tightly couples it to the "``invoke``"
4352 instruction, so that the important information contained within the
4353 "``landingpad``" instruction can't be lost through normal code motion.
4354
4355 Arguments:
4356 """"""""""
4357
4358 This instruction requires several arguments:
4359
4360 #. The optional "cconv" marker indicates which :ref:`calling
4361    convention <callingconv>` the call should use. If none is
4362    specified, the call defaults to using C calling conventions.
4363 #. The optional :ref:`Parameter Attributes <paramattrs>` list for return
4364    values. Only '``zeroext``', '``signext``', and '``inreg``' attributes
4365    are valid here.
4366 #. '``ptr to function ty``': shall be the signature of the pointer to
4367    function value being invoked. In most cases, this is a direct
4368    function invocation, but indirect ``invoke``'s are just as possible,
4369    branching off an arbitrary pointer to function value.
4370 #. '``function ptr val``': An LLVM value containing a pointer to a
4371    function to be invoked.
4372 #. '``function args``': argument list whose types match the function
4373    signature argument types and parameter attributes. All arguments must
4374    be of :ref:`first class <t_firstclass>` type. If the function signature
4375    indicates the function accepts a variable number of arguments, the
4376    extra arguments can be specified.
4377 #. '``normal label``': the label reached when the called function
4378    executes a '``ret``' instruction.
4379 #. '``exception label``': the label reached when a callee returns via
4380    the :ref:`resume <i_resume>` instruction or other exception handling
4381    mechanism.
4382 #. The optional :ref:`function attributes <fnattrs>` list. Only
4383    '``noreturn``', '``nounwind``', '``readonly``' and '``readnone``'
4384    attributes are valid here.
4385
4386 Semantics:
4387 """"""""""
4388
4389 This instruction is designed to operate as a standard '``call``'
4390 instruction in most regards. The primary difference is that it
4391 establishes an association with a label, which is used by the runtime
4392 library to unwind the stack.
4393
4394 This instruction is used in languages with destructors to ensure that
4395 proper cleanup is performed in the case of either a ``longjmp`` or a
4396 thrown exception. Additionally, this is important for implementation of
4397 '``catch``' clauses in high-level languages that support them.
4398
4399 For the purposes of the SSA form, the definition of the value returned
4400 by the '``invoke``' instruction is deemed to occur on the edge from the
4401 current block to the "normal" label. If the callee unwinds then no
4402 return value is available.
4403
4404 Example:
4405 """"""""
4406
4407 .. code-block:: llvm
4408
4409       %retval = invoke i32 @Test(i32 15) to label %Continue
4410                   unwind label %TestCleanup              ; i32:retval set
4411       %retval = invoke coldcc i32 %Testfnptr(i32 15) to label %Continue
4412                   unwind label %TestCleanup              ; i32:retval set
4413
4414 .. _i_resume:
4415
4416 '``resume``' Instruction
4417 ^^^^^^^^^^^^^^^^^^^^^^^^
4418
4419 Syntax:
4420 """""""
4421
4422 ::
4423
4424       resume <type> <value>
4425
4426 Overview:
4427 """""""""
4428
4429 The '``resume``' instruction is a terminator instruction that has no
4430 successors.
4431
4432 Arguments:
4433 """"""""""
4434
4435 The '``resume``' instruction requires one argument, which must have the
4436 same type as the result of any '``landingpad``' instruction in the same
4437 function.
4438
4439 Semantics:
4440 """"""""""
4441
4442 The '``resume``' instruction resumes propagation of an existing
4443 (in-flight) exception whose unwinding was interrupted with a
4444 :ref:`landingpad <i_landingpad>` instruction.
4445
4446 Example:
4447 """"""""
4448
4449 .. code-block:: llvm
4450
4451       resume { i8*, i32 } %exn
4452
4453 .. _i_unreachable:
4454
4455 '``unreachable``' Instruction
4456 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4457
4458 Syntax:
4459 """""""
4460
4461 ::
4462
4463       unreachable
4464
4465 Overview:
4466 """""""""
4467
4468 The '``unreachable``' instruction has no defined semantics. This
4469 instruction is used to inform the optimizer that a particular portion of
4470 the code is not reachable. This can be used to indicate that the code
4471 after a no-return function cannot be reached, and other facts.
4472
4473 Semantics:
4474 """"""""""
4475
4476 The '``unreachable``' instruction has no defined semantics.
4477
4478 .. _binaryops:
4479
4480 Binary Operations
4481 -----------------
4482
4483 Binary operators are used to do most of the computation in a program.
4484 They require two operands of the same type, execute an operation on
4485 them, and produce a single value. The operands might represent multiple
4486 data, as is the case with the :ref:`vector <t_vector>` data type. The
4487 result value has the same type as its operands.
4488
4489 There are several different binary operators:
4490
4491 .. _i_add:
4492
4493 '``add``' Instruction
4494 ^^^^^^^^^^^^^^^^^^^^^
4495
4496 Syntax:
4497 """""""
4498
4499 ::
4500
4501       <result> = add <ty> <op1>, <op2>          ; yields ty:result
4502       <result> = add nuw <ty> <op1>, <op2>      ; yields ty:result
4503       <result> = add nsw <ty> <op1>, <op2>      ; yields ty:result
4504       <result> = add nuw nsw <ty> <op1>, <op2>  ; yields ty:result
4505
4506 Overview:
4507 """""""""
4508
4509 The '``add``' instruction returns the sum of its two operands.
4510
4511 Arguments:
4512 """"""""""
4513
4514 The two arguments to the '``add``' instruction must be
4515 :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
4516 arguments must have identical types.
4517
4518 Semantics:
4519 """"""""""
4520
4521 The value produced is the integer sum of the two operands.
4522
4523 If the sum has unsigned overflow, the result returned is the
4524 mathematical result modulo 2\ :sup:`n`\ , where n is the bit width of
4525 the result.
4526
4527 Because LLVM integers use a two's complement representation, this
4528 instruction is appropriate for both signed and unsigned integers.
4529
4530 ``nuw`` and ``nsw`` stand for "No Unsigned Wrap" and "No Signed Wrap",
4531 respectively. If the ``nuw`` and/or ``nsw`` keywords are present, the
4532 result value of the ``add`` is a :ref:`poison value <poisonvalues>` if
4533 unsigned and/or signed overflow, respectively, occurs.
4534
4535 Example:
4536 """"""""
4537
4538 .. code-block:: llvm
4539
4540       <result> = add i32 4, %var          ; yields i32:result = 4 + %var
4541
4542 .. _i_fadd:
4543
4544 '``fadd``' Instruction
4545 ^^^^^^^^^^^^^^^^^^^^^^
4546
4547 Syntax:
4548 """""""
4549
4550 ::
4551
4552       <result> = fadd [fast-math flags]* <ty> <op1>, <op2>   ; yields ty:result
4553
4554 Overview:
4555 """""""""
4556
4557 The '``fadd``' instruction returns the sum of its two operands.
4558
4559 Arguments:
4560 """"""""""
4561
4562 The two arguments to the '``fadd``' instruction must be :ref:`floating
4563 point <t_floating>` or :ref:`vector <t_vector>` of floating point values.
4564 Both arguments must have identical types.
4565
4566 Semantics:
4567 """"""""""
4568
4569 The value produced is the floating point sum of the two operands. This
4570 instruction can also take any number of :ref:`fast-math flags <fastmath>`,
4571 which are optimization hints to enable otherwise unsafe floating point
4572 optimizations:
4573
4574 Example:
4575 """"""""
4576
4577 .. code-block:: llvm
4578
4579       <result> = fadd float 4.0, %var          ; yields float:result = 4.0 + %var
4580
4581 '``sub``' Instruction
4582 ^^^^^^^^^^^^^^^^^^^^^
4583
4584 Syntax:
4585 """""""
4586
4587 ::
4588
4589       <result> = sub <ty> <op1>, <op2>          ; yields ty:result
4590       <result> = sub nuw <ty> <op1>, <op2>      ; yields ty:result
4591       <result> = sub nsw <ty> <op1>, <op2>      ; yields ty:result
4592       <result> = sub nuw nsw <ty> <op1>, <op2>  ; yields ty:result
4593
4594 Overview:
4595 """""""""
4596
4597 The '``sub``' instruction returns the difference of its two operands.
4598
4599 Note that the '``sub``' instruction is used to represent the '``neg``'
4600 instruction present in most other intermediate representations.
4601
4602 Arguments:
4603 """"""""""
4604
4605 The two arguments to the '``sub``' instruction must be
4606 :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
4607 arguments must have identical types.
4608
4609 Semantics:
4610 """"""""""
4611
4612 The value produced is the integer difference of the two operands.
4613
4614 If the difference has unsigned overflow, the result returned is the
4615 mathematical result modulo 2\ :sup:`n`\ , where n is the bit width of
4616 the result.
4617
4618 Because LLVM integers use a two's complement representation, this
4619 instruction is appropriate for both signed and unsigned integers.
4620
4621 ``nuw`` and ``nsw`` stand for "No Unsigned Wrap" and "No Signed Wrap",
4622 respectively. If the ``nuw`` and/or ``nsw`` keywords are present, the
4623 result value of the ``sub`` is a :ref:`poison value <poisonvalues>` if
4624 unsigned and/or signed overflow, respectively, occurs.
4625
4626 Example:
4627 """"""""
4628
4629 .. code-block:: llvm
4630
4631       <result> = sub i32 4, %var          ; yields i32:result = 4 - %var
4632       <result> = sub i32 0, %val          ; yields i32:result = -%var
4633
4634 .. _i_fsub:
4635
4636 '``fsub``' Instruction
4637 ^^^^^^^^^^^^^^^^^^^^^^
4638
4639 Syntax:
4640 """""""
4641
4642 ::
4643
4644       <result> = fsub [fast-math flags]* <ty> <op1>, <op2>   ; yields ty:result
4645
4646 Overview:
4647 """""""""
4648
4649 The '``fsub``' instruction returns the difference of its two operands.
4650
4651 Note that the '``fsub``' instruction is used to represent the '``fneg``'
4652 instruction present in most other intermediate representations.
4653
4654 Arguments:
4655 """"""""""
4656
4657 The two arguments to the '``fsub``' instruction must be :ref:`floating
4658 point <t_floating>` or :ref:`vector <t_vector>` of floating point values.
4659 Both arguments must have identical types.
4660
4661 Semantics:
4662 """"""""""
4663
4664 The value produced is the floating point difference of the two operands.
4665 This instruction can also take any number of :ref:`fast-math
4666 flags <fastmath>`, which are optimization hints to enable otherwise
4667 unsafe floating point optimizations:
4668
4669 Example:
4670 """"""""
4671
4672 .. code-block:: llvm
4673
4674       <result> = fsub float 4.0, %var           ; yields float:result = 4.0 - %var
4675       <result> = fsub float -0.0, %val          ; yields float:result = -%var
4676
4677 '``mul``' Instruction
4678 ^^^^^^^^^^^^^^^^^^^^^
4679
4680 Syntax:
4681 """""""
4682
4683 ::
4684
4685       <result> = mul <ty> <op1>, <op2>          ; yields ty:result
4686       <result> = mul nuw <ty> <op1>, <op2>      ; yields ty:result
4687       <result> = mul nsw <ty> <op1>, <op2>      ; yields ty:result
4688       <result> = mul nuw nsw <ty> <op1>, <op2>  ; yields ty:result
4689
4690 Overview:
4691 """""""""
4692
4693 The '``mul``' instruction returns the product of its two operands.
4694
4695 Arguments:
4696 """"""""""
4697
4698 The two arguments to the '``mul``' instruction must be
4699 :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
4700 arguments must have identical types.
4701
4702 Semantics:
4703 """"""""""
4704
4705 The value produced is the integer product of the two operands.
4706
4707 If the result of the multiplication has unsigned overflow, the result
4708 returned is the mathematical result modulo 2\ :sup:`n`\ , where n is the
4709 bit width of the result.
4710
4711 Because LLVM integers use a two's complement representation, and the
4712 result is the same width as the operands, this instruction returns the
4713 correct result for both signed and unsigned integers. If a full product
4714 (e.g. ``i32`` * ``i32`` -> ``i64``) is needed, the operands should be
4715 sign-extended or zero-extended as appropriate to the width of the full
4716 product.
4717
4718 ``nuw`` and ``nsw`` stand for "No Unsigned Wrap" and "No Signed Wrap",
4719 respectively. If the ``nuw`` and/or ``nsw`` keywords are present, the
4720 result value of the ``mul`` is a :ref:`poison value <poisonvalues>` if
4721 unsigned and/or signed overflow, respectively, occurs.
4722
4723 Example:
4724 """"""""
4725
4726 .. code-block:: llvm
4727
4728       <result> = mul i32 4, %var          ; yields i32:result = 4 * %var
4729
4730 .. _i_fmul:
4731
4732 '``fmul``' Instruction
4733 ^^^^^^^^^^^^^^^^^^^^^^
4734
4735 Syntax:
4736 """""""
4737
4738 ::
4739
4740       <result> = fmul [fast-math flags]* <ty> <op1>, <op2>   ; yields ty:result
4741
4742 Overview:
4743 """""""""
4744
4745 The '``fmul``' instruction returns the product of its two operands.
4746
4747 Arguments:
4748 """"""""""
4749
4750 The two arguments to the '``fmul``' instruction must be :ref:`floating
4751 point <t_floating>` or :ref:`vector <t_vector>` of floating point values.
4752 Both arguments must have identical types.
4753
4754 Semantics:
4755 """"""""""
4756
4757 The value produced is the floating point product of the two operands.
4758 This instruction can also take any number of :ref:`fast-math
4759 flags <fastmath>`, which are optimization hints to enable otherwise
4760 unsafe floating point optimizations:
4761
4762 Example:
4763 """"""""
4764
4765 .. code-block:: llvm
4766
4767       <result> = fmul float 4.0, %var          ; yields float:result = 4.0 * %var
4768
4769 '``udiv``' Instruction
4770 ^^^^^^^^^^^^^^^^^^^^^^
4771
4772 Syntax:
4773 """""""
4774
4775 ::
4776
4777       <result> = udiv <ty> <op1>, <op2>         ; yields ty:result
4778       <result> = udiv exact <ty> <op1>, <op2>   ; yields ty:result
4779
4780 Overview:
4781 """""""""
4782
4783 The '``udiv``' instruction returns the quotient of its two operands.
4784
4785 Arguments:
4786 """"""""""
4787
4788 The two arguments to the '``udiv``' instruction must be
4789 :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
4790 arguments must have identical types.
4791
4792 Semantics:
4793 """"""""""
4794
4795 The value produced is the unsigned integer quotient of the two operands.
4796
4797 Note that unsigned integer division and signed integer division are
4798 distinct operations; for signed integer division, use '``sdiv``'.
4799
4800 Division by zero leads to undefined behavior.
4801
4802 If the ``exact`` keyword is present, the result value of the ``udiv`` is
4803 a :ref:`poison value <poisonvalues>` if %op1 is not a multiple of %op2 (as
4804 such, "((a udiv exact b) mul b) == a").
4805
4806 Example:
4807 """"""""
4808
4809 .. code-block:: llvm
4810
4811       <result> = udiv i32 4, %var          ; yields i32:result = 4 / %var
4812
4813 '``sdiv``' Instruction
4814 ^^^^^^^^^^^^^^^^^^^^^^
4815
4816 Syntax:
4817 """""""
4818
4819 ::
4820
4821       <result> = sdiv <ty> <op1>, <op2>         ; yields ty:result
4822       <result> = sdiv exact <ty> <op1>, <op2>   ; yields ty:result
4823
4824 Overview:
4825 """""""""
4826
4827 The '``sdiv``' instruction returns the quotient of its two operands.
4828
4829 Arguments:
4830 """"""""""
4831
4832 The two arguments to the '``sdiv``' instruction must be
4833 :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
4834 arguments must have identical types.
4835
4836 Semantics:
4837 """"""""""
4838
4839 The value produced is the signed integer quotient of the two operands
4840 rounded towards zero.
4841
4842 Note that signed integer division and unsigned integer division are
4843 distinct operations; for unsigned integer division, use '``udiv``'.
4844
4845 Division by zero leads to undefined behavior. Overflow also leads to
4846 undefined behavior; this is a rare case, but can occur, for example, by
4847 doing a 32-bit division of -2147483648 by -1.
4848
4849 If the ``exact`` keyword is present, the result value of the ``sdiv`` is
4850 a :ref:`poison value <poisonvalues>` if the result would be rounded.
4851
4852 Example:
4853 """"""""
4854
4855 .. code-block:: llvm
4856
4857       <result> = sdiv i32 4, %var          ; yields i32:result = 4 / %var
4858
4859 .. _i_fdiv:
4860
4861 '``fdiv``' Instruction
4862 ^^^^^^^^^^^^^^^^^^^^^^
4863
4864 Syntax:
4865 """""""
4866
4867 ::
4868
4869       <result> = fdiv [fast-math flags]* <ty> <op1>, <op2>   ; yields ty:result
4870
4871 Overview:
4872 """""""""
4873
4874 The '``fdiv``' instruction returns the quotient of its two operands.
4875
4876 Arguments:
4877 """"""""""
4878
4879 The two arguments to the '``fdiv``' instruction must be :ref:`floating
4880 point <t_floating>` or :ref:`vector <t_vector>` of floating point values.
4881 Both arguments must have identical types.
4882
4883 Semantics:
4884 """"""""""
4885
4886 The value produced is the floating point quotient of the two operands.
4887 This instruction can also take any number of :ref:`fast-math
4888 flags <fastmath>`, which are optimization hints to enable otherwise
4889 unsafe floating point optimizations:
4890
4891 Example:
4892 """"""""
4893
4894 .. code-block:: llvm
4895
4896       <result> = fdiv float 4.0, %var          ; yields float:result = 4.0 / %var
4897
4898 '``urem``' Instruction
4899 ^^^^^^^^^^^^^^^^^^^^^^
4900
4901 Syntax:
4902 """""""
4903
4904 ::
4905
4906       <result> = urem <ty> <op1>, <op2>   ; yields ty:result
4907
4908 Overview:
4909 """""""""
4910
4911 The '``urem``' instruction returns the remainder from the unsigned
4912 division of its two arguments.
4913
4914 Arguments:
4915 """"""""""
4916
4917 The two arguments to the '``urem``' instruction must be
4918 :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
4919 arguments must have identical types.
4920
4921 Semantics:
4922 """"""""""
4923
4924 This instruction returns the unsigned integer *remainder* of a division.
4925 This instruction always performs an unsigned division to get the
4926 remainder.
4927
4928 Note that unsigned integer remainder and signed integer remainder are
4929 distinct operations; for signed integer remainder, use '``srem``'.
4930
4931 Taking the remainder of a division by zero leads to undefined behavior.
4932
4933 Example:
4934 """"""""
4935
4936 .. code-block:: llvm
4937
4938       <result> = urem i32 4, %var          ; yields i32:result = 4 % %var
4939
4940 '``srem``' Instruction
4941 ^^^^^^^^^^^^^^^^^^^^^^
4942
4943 Syntax:
4944 """""""
4945
4946 ::
4947
4948       <result> = srem <ty> <op1>, <op2>   ; yields ty:result
4949
4950 Overview:
4951 """""""""
4952
4953 The '``srem``' instruction returns the remainder from the signed
4954 division of its two operands. This instruction can also take
4955 :ref:`vector <t_vector>` versions of the values in which case the elements
4956 must be integers.
4957
4958 Arguments:
4959 """"""""""
4960
4961 The two arguments to the '``srem``' instruction must be
4962 :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
4963 arguments must have identical types.
4964
4965 Semantics:
4966 """"""""""
4967
4968 This instruction returns the *remainder* of a division (where the result
4969 is either zero or has the same sign as the dividend, ``op1``), not the
4970 *modulo* operator (where the result is either zero or has the same sign
4971 as the divisor, ``op2``) of a value. For more information about the
4972 difference, see `The Math
4973 Forum <http://mathforum.org/dr.math/problems/anne.4.28.99.html>`_. For a
4974 table of how this is implemented in various languages, please see
4975 `Wikipedia: modulo
4976 operation <http://en.wikipedia.org/wiki/Modulo_operation>`_.
4977
4978 Note that signed integer remainder and unsigned integer remainder are
4979 distinct operations; for unsigned integer remainder, use '``urem``'.
4980
4981 Taking the remainder of a division by zero leads to undefined behavior.
4982 Overflow also leads to undefined behavior; this is a rare case, but can
4983 occur, for example, by taking the remainder of a 32-bit division of
4984 -2147483648 by -1. (The remainder doesn't actually overflow, but this
4985 rule lets srem be implemented using instructions that return both the
4986 result of the division and the remainder.)
4987
4988 Example:
4989 """"""""
4990
4991 .. code-block:: llvm
4992
4993       <result> = srem i32 4, %var          ; yields i32:result = 4 % %var
4994
4995 .. _i_frem:
4996
4997 '``frem``' Instruction
4998 ^^^^^^^^^^^^^^^^^^^^^^
4999
5000 Syntax:
5001 """""""
5002
5003 ::
5004
5005       <result> = frem [fast-math flags]* <ty> <op1>, <op2>   ; yields ty:result
5006
5007 Overview:
5008 """""""""
5009
5010 The '``frem``' instruction returns the remainder from the division of
5011 its two operands.
5012
5013 Arguments:
5014 """"""""""
5015
5016 The two arguments to the '``frem``' instruction must be :ref:`floating
5017 point <t_floating>` or :ref:`vector <t_vector>` of floating point values.
5018 Both arguments must have identical types.
5019
5020 Semantics:
5021 """"""""""
5022
5023 This instruction returns the *remainder* of a division. The remainder
5024 has the same sign as the dividend. This instruction can also take any
5025 number of :ref:`fast-math flags <fastmath>`, which are optimization hints
5026 to enable otherwise unsafe floating point optimizations:
5027
5028 Example:
5029 """"""""
5030
5031 .. code-block:: llvm
5032
5033       <result> = frem float 4.0, %var          ; yields float:result = 4.0 % %var
5034
5035 .. _bitwiseops:
5036
5037 Bitwise Binary Operations
5038 -------------------------
5039
5040 Bitwise binary operators are used to do various forms of bit-twiddling
5041 in a program. They are generally very efficient instructions and can
5042 commonly be strength reduced from other instructions. They require two
5043 operands of the same type, execute an operation on them, and produce a
5044 single value. The resulting value is the same type as its operands.
5045
5046 '``shl``' Instruction
5047 ^^^^^^^^^^^^^^^^^^^^^
5048
5049 Syntax:
5050 """""""
5051
5052 ::
5053
5054       <result> = shl <ty> <op1>, <op2>           ; yields ty:result
5055       <result> = shl nuw <ty> <op1>, <op2>       ; yields ty:result
5056       <result> = shl nsw <ty> <op1>, <op2>       ; yields ty:result
5057       <result> = shl nuw nsw <ty> <op1>, <op2>   ; yields ty:result
5058
5059 Overview:
5060 """""""""
5061
5062 The '``shl``' instruction returns the first operand shifted to the left
5063 a specified number of bits.
5064
5065 Arguments:
5066 """"""""""
5067
5068 Both arguments to the '``shl``' instruction must be the same
5069 :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer type.
5070 '``op2``' is treated as an unsigned value.
5071
5072 Semantics:
5073 """"""""""
5074
5075 The value produced is ``op1`` \* 2\ :sup:`op2` mod 2\ :sup:`n`,
5076 where ``n`` is the width of the result. If ``op2`` is (statically or
5077 dynamically) equal to or larger than the number of bits in
5078 ``op1``, the result is undefined. If the arguments are vectors, each
5079 vector element of ``op1`` is shifted by the corresponding shift amount
5080 in ``op2``.
5081
5082 If the ``nuw`` keyword is present, then the shift produces a :ref:`poison
5083 value <poisonvalues>` if it shifts out any non-zero bits. If the
5084 ``nsw`` keyword is present, then the shift produces a :ref:`poison
5085 value <poisonvalues>` if it shifts out any bits that disagree with the
5086 resultant sign bit. As such, NUW/NSW have the same semantics as they
5087 would if the shift were expressed as a mul instruction with the same
5088 nsw/nuw bits in (mul %op1, (shl 1, %op2)).
5089
5090 Example:
5091 """"""""
5092
5093 .. code-block:: llvm
5094
5095       <result> = shl i32 4, %var   ; yields i32: 4 << %var
5096       <result> = shl i32 4, 2      ; yields i32: 16
5097       <result> = shl i32 1, 10     ; yields i32: 1024
5098       <result> = shl i32 1, 32     ; undefined
5099       <result> = shl <2 x i32> < i32 1, i32 1>, < i32 1, i32 2>   ; yields: result=<2 x i32> < i32 2, i32 4>
5100
5101 '``lshr``' Instruction
5102 ^^^^^^^^^^^^^^^^^^^^^^
5103
5104 Syntax:
5105 """""""
5106
5107 ::
5108
5109       <result> = lshr <ty> <op1>, <op2>         ; yields ty:result
5110       <result> = lshr exact <ty> <op1>, <op2>   ; yields ty:result
5111
5112 Overview:
5113 """""""""
5114
5115 The '``lshr``' instruction (logical shift right) returns the first
5116 operand shifted to the right a specified number of bits with zero fill.
5117
5118 Arguments:
5119 """"""""""
5120
5121 Both arguments to the '``lshr``' instruction must be the same
5122 :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer type.
5123 '``op2``' is treated as an unsigned value.
5124
5125 Semantics:
5126 """"""""""
5127
5128 This instruction always performs a logical shift right operation. The
5129 most significant bits of the result will be filled with zero bits after
5130 the shift. If ``op2`` is (statically or dynamically) equal to or larger
5131 than the number of bits in ``op1``, the result is undefined. If the
5132 arguments are vectors, each vector element of ``op1`` is shifted by the
5133 corresponding shift amount in ``op2``.
5134
5135 If the ``exact`` keyword is present, the result value of the ``lshr`` is
5136 a :ref:`poison value <poisonvalues>` if any of the bits shifted out are
5137 non-zero.
5138
5139 Example:
5140 """"""""
5141
5142 .. code-block:: llvm
5143
5144       <result> = lshr i32 4, 1   ; yields i32:result = 2
5145       <result> = lshr i32 4, 2   ; yields i32:result = 1
5146       <result> = lshr i8  4, 3   ; yields i8:result = 0
5147       <result> = lshr i8 -2, 1   ; yields i8:result = 0x7F
5148       <result> = lshr i32 1, 32  ; undefined
5149       <result> = lshr <2 x i32> < i32 -2, i32 4>, < i32 1, i32 2>   ; yields: result=<2 x i32> < i32 0x7FFFFFFF, i32 1>
5150
5151 '``ashr``' Instruction
5152 ^^^^^^^^^^^^^^^^^^^^^^
5153
5154 Syntax:
5155 """""""
5156
5157 ::
5158
5159       <result> = ashr <ty> <op1>, <op2>         ; yields ty:result
5160       <result> = ashr exact <ty> <op1>, <op2>   ; yields ty:result
5161
5162 Overview:
5163 """""""""
5164
5165 The '``ashr``' instruction (arithmetic shift right) returns the first
5166 operand shifted to the right a specified number of bits with sign
5167 extension.
5168
5169 Arguments:
5170 """"""""""
5171
5172 Both arguments to the '``ashr``' instruction must be the same
5173 :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer type.
5174 '``op2``' is treated as an unsigned value.
5175
5176 Semantics:
5177 """"""""""
5178
5179 This instruction always performs an arithmetic shift right operation,
5180 The most significant bits of the result will be filled with the sign bit
5181 of ``op1``. If ``op2`` is (statically or dynamically) equal to or larger
5182 than the number of bits in ``op1``, the result is undefined. If the
5183 arguments are vectors, each vector element of ``op1`` is shifted by the
5184 corresponding shift amount in ``op2``.
5185
5186 If the ``exact`` keyword is present, the result value of the ``ashr`` is
5187 a :ref:`poison value <poisonvalues>` if any of the bits shifted out are
5188 non-zero.
5189
5190 Example:
5191 """"""""
5192
5193 .. code-block:: llvm
5194
5195       <result> = ashr i32 4, 1   ; yields i32:result = 2
5196       <result> = ashr i32 4, 2   ; yields i32:result = 1
5197       <result> = ashr i8  4, 3   ; yields i8:result = 0
5198       <result> = ashr i8 -2, 1   ; yields i8:result = -1
5199       <result> = ashr i32 1, 32  ; undefined
5200       <result> = ashr <2 x i32> < i32 -2, i32 4>, < i32 1, i32 3>   ; yields: result=<2 x i32> < i32 -1, i32 0>
5201
5202 '``and``' Instruction
5203 ^^^^^^^^^^^^^^^^^^^^^
5204
5205 Syntax:
5206 """""""
5207
5208 ::
5209
5210       <result> = and <ty> <op1>, <op2>   ; yields ty:result
5211
5212 Overview:
5213 """""""""
5214
5215 The '``and``' instruction returns the bitwise logical and of its two
5216 operands.
5217
5218 Arguments:
5219 """"""""""
5220
5221 The two arguments to the '``and``' instruction must be
5222 :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
5223 arguments must have identical types.
5224
5225 Semantics:
5226 """"""""""
5227
5228 The truth table used for the '``and``' instruction is:
5229
5230 +-----+-----+-----+
5231 | In0 | In1 | Out |
5232 +-----+-----+-----+
5233 |   0 |   0 |   0 |
5234 +-----+-----+-----+
5235 |   0 |   1 |   0 |
5236 +-----+-----+-----+
5237 |   1 |   0 |   0 |
5238 +-----+-----+-----+
5239 |   1 |   1 |   1 |
5240 +-----+-----+-----+
5241
5242 Example:
5243 """"""""
5244
5245 .. code-block:: llvm
5246
5247       <result> = and i32 4, %var         ; yields i32:result = 4 & %var
5248       <result> = and i32 15, 40          ; yields i32:result = 8
5249       <result> = and i32 4, 8            ; yields i32:result = 0
5250
5251 '``or``' Instruction
5252 ^^^^^^^^^^^^^^^^^^^^
5253
5254 Syntax:
5255 """""""
5256
5257 ::
5258
5259       <result> = or <ty> <op1>, <op2>   ; yields ty:result
5260
5261 Overview:
5262 """""""""
5263
5264 The '``or``' instruction returns the bitwise logical inclusive or of its
5265 two operands.
5266
5267 Arguments:
5268 """"""""""
5269
5270 The two arguments to the '``or``' instruction must be
5271 :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
5272 arguments must have identical types.
5273
5274 Semantics:
5275 """"""""""
5276
5277 The truth table used for the '``or``' instruction is:
5278
5279 +-----+-----+-----+
5280 | In0 | In1 | Out |
5281 +-----+-----+-----+
5282 |   0 |   0 |   0 |
5283 +-----+-----+-----+
5284 |   0 |   1 |   1 |
5285 +-----+-----+-----+
5286 |   1 |   0 |   1 |
5287 +-----+-----+-----+
5288 |   1 |   1 |   1 |
5289 +-----+-----+-----+
5290
5291 Example:
5292 """"""""
5293
5294 ::
5295
5296       <result> = or i32 4, %var         ; yields i32:result = 4 | %var
5297       <result> = or i32 15, 40          ; yields i32:result = 47
5298       <result> = or i32 4, 8            ; yields i32:result = 12
5299
5300 '``xor``' Instruction
5301 ^^^^^^^^^^^^^^^^^^^^^
5302
5303 Syntax:
5304 """""""
5305
5306 ::
5307
5308       <result> = xor <ty> <op1>, <op2>   ; yields ty:result
5309
5310 Overview:
5311 """""""""
5312
5313 The '``xor``' instruction returns the bitwise logical exclusive or of
5314 its two operands. The ``xor`` is used to implement the "one's
5315 complement" operation, which is the "~" operator in C.
5316
5317 Arguments:
5318 """"""""""
5319
5320 The two arguments to the '``xor``' instruction must be
5321 :ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both
5322 arguments must have identical types.
5323
5324 Semantics:
5325 """"""""""
5326
5327 The truth table used for the '``xor``' instruction is:
5328
5329 +-----+-----+-----+
5330 | In0 | In1 | Out |
5331 +-----+-----+-----+
5332 |   0 |   0 |   0 |
5333 +-----+-----+-----+
5334 |   0 |   1 |   1 |
5335 +-----+-----+-----+
5336 |   1 |   0 |   1 |
5337 +-----+-----+-----+
5338 |   1 |   1 |   0 |
5339 +-----+-----+-----+
5340
5341 Example:
5342 """"""""
5343
5344 .. code-block:: llvm
5345
5346       <result> = xor i32 4, %var         ; yields i32:result = 4 ^ %var
5347       <result> = xor i32 15, 40          ; yields i32:result = 39
5348       <result> = xor i32 4, 8            ; yields i32:result = 12
5349       <result> = xor i32 %V, -1          ; yields i32:result = ~%V
5350
5351 Vector Operations
5352 -----------------
5353
5354 LLVM supports several instructions to represent vector operations in a
5355 target-independent manner. These instructions cover the element-access
5356 and vector-specific operations needed to process vectors effectively.
5357 While LLVM does directly support these vector operations, many
5358 sophisticated algorithms will want to use target-specific intrinsics to
5359 take full advantage of a specific target.
5360
5361 .. _i_extractelement:
5362
5363 '``extractelement``' Instruction
5364 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5365
5366 Syntax:
5367 """""""
5368
5369 ::
5370
5371       <result> = extractelement <n x <ty>> <val>, <ty2> <idx>  ; yields <ty>
5372
5373 Overview:
5374 """""""""
5375
5376 The '``extractelement``' instruction extracts a single scalar element
5377 from a vector at a specified index.
5378
5379 Arguments:
5380 """"""""""
5381
5382 The first operand of an '``extractelement``' instruction is a value of
5383 :ref:`vector <t_vector>` type. The second operand is an index indicating
5384 the position from which to extract the element. The index may be a
5385 variable of any integer type.
5386
5387 Semantics:
5388 """"""""""
5389
5390 The result is a scalar of the same type as the element type of ``val``.
5391 Its value is the value at position ``idx`` of ``val``. If ``idx``
5392 exceeds the length of ``val``, the results are undefined.
5393
5394 Example:
5395 """"""""
5396
5397 .. code-block:: llvm
5398
5399       <result> = extractelement <4 x i32> %vec, i32 0    ; yields i32
5400
5401 .. _i_insertelement:
5402
5403 '``insertelement``' Instruction
5404 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5405
5406 Syntax:
5407 """""""
5408
5409 ::
5410
5411       <result> = insertelement <n x <ty>> <val>, <ty> <elt>, <ty2> <idx>    ; yields <n x <ty>>
5412
5413 Overview:
5414 """""""""
5415
5416 The '``insertelement``' instruction inserts a scalar element into a
5417 vector at a specified index.
5418
5419 Arguments:
5420 """"""""""
5421
5422 The first operand of an '``insertelement``' instruction is a value of
5423 :ref:`vector <t_vector>` type. The second operand is a scalar value whose
5424 type must equal the element type of the first operand. The third operand
5425 is an index indicating the position at which to insert the value. The
5426 index may be a variable of any integer type.
5427
5428 Semantics:
5429 """"""""""
5430
5431 The result is a vector of the same type as ``val``. Its element values
5432 are those of ``val`` except at position ``idx``, where it gets the value
5433 ``elt``. If ``idx`` exceeds the length of ``val``, the results are
5434 undefined.
5435
5436 Example:
5437 """"""""
5438
5439 .. code-block:: llvm
5440
5441       <result> = insertelement <4 x i32> %vec, i32 1, i32 0    ; yields <4 x i32>
5442
5443 .. _i_shufflevector:
5444
5445 '``shufflevector``' Instruction
5446 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5447
5448 Syntax:
5449 """""""
5450
5451 ::
5452
5453       <result> = shufflevector <n x <ty>> <v1>, <n x <ty>> <v2>, <m x i32> <mask>    ; yields <m x <ty>>
5454
5455 Overview:
5456 """""""""
5457
5458 The '``shufflevector``' instruction constructs a permutation of elements
5459 from two input vectors, returning a vector with the same element type as
5460 the input and length that is the same as the shuffle mask.
5461
5462 Arguments:
5463 """"""""""
5464
5465 The first two operands of a '``shufflevector``' instruction are vectors
5466 with the same type. The third argument is a shuffle mask whose element
5467 type is always 'i32'. The result of the instruction is a vector whose
5468 length is the same as the shuffle mask and whose element type is the
5469 same as the element type of the first two operands.
5470
5471 The shuffle mask operand is required to be a constant vector with either
5472 constant integer or undef values.
5473
5474 Semantics:
5475 """"""""""
5476
5477 The elements of the two input vectors are numbered from left to right
5478 across both of the vectors. The shuffle mask operand specifies, for each
5479 element of the result vector, which element of the two input vectors the
5480 result element gets. The element selector may be undef (meaning "don't
5481 care") and the second operand may be undef if performing a shuffle from
5482 only one vector.
5483
5484 Example:
5485 """"""""
5486
5487 .. code-block:: llvm
5488
5489       <result> = shufflevector <4 x i32> %v1, <4 x i32> %v2,
5490                               <4 x i32> <i32 0, i32 4, i32 1, i32 5>  ; yields <4 x i32>
5491       <result> = shufflevector <4 x i32> %v1, <4 x i32> undef,
5492                               <4 x i32> <i32 0, i32 1, i32 2, i32 3>  ; yields <4 x i32> - Identity shuffle.
5493       <result> = shufflevector <8 x i32> %v1, <8 x i32> undef,
5494                               <4 x i32> <i32 0, i32 1, i32 2, i32 3>  ; yields <4 x i32>
5495       <result> = shufflevector <4 x i32> %v1, <4 x i32> %v2,
5496                               <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7 >  ; yields <8 x i32>
5497
5498 Aggregate Operations
5499 --------------------
5500
5501 LLVM supports several instructions for working with
5502 :ref:`aggregate <t_aggregate>` values.
5503
5504 .. _i_extractvalue:
5505
5506 '``extractvalue``' Instruction
5507 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5508
5509 Syntax:
5510 """""""
5511
5512 ::
5513
5514       <result> = extractvalue <aggregate type> <val>, <idx>{, <idx>}*
5515
5516 Overview:
5517 """""""""
5518
5519 The '``extractvalue``' instruction extracts the value of a member field
5520 from an :ref:`aggregate <t_aggregate>` value.
5521
5522 Arguments:
5523 """"""""""
5524
5525 The first operand of an '``extractvalue``' instruction is a value of
5526 :ref:`struct <t_struct>` or :ref:`array <t_array>` type. The operands are
5527 constant indices to specify which value to extract in a similar manner
5528 as indices in a '``getelementptr``' instruction.
5529
5530 The major differences to ``getelementptr`` indexing are:
5531
5532 -  Since the value being indexed is not a pointer, the first index is
5533    omitted and assumed to be zero.
5534 -  At least one index must be specified.
5535 -  Not only struct indices but also array indices must be in bounds.
5536
5537 Semantics:
5538 """"""""""
5539
5540 The result is the value at the position in the aggregate specified by
5541 the index operands.
5542
5543 Example:
5544 """"""""
5545
5546 .. code-block:: llvm
5547
5548       <result> = extractvalue {i32, float} %agg, 0    ; yields i32
5549
5550 .. _i_insertvalue:
5551
5552 '``insertvalue``' Instruction
5553 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5554
5555 Syntax:
5556 """""""
5557
5558 ::
5559
5560       <result> = insertvalue <aggregate type> <val>, <ty> <elt>, <idx>{, <idx>}*    ; yields <aggregate type>
5561
5562 Overview:
5563 """""""""
5564
5565 The '``insertvalue``' instruction inserts a value into a member field in
5566 an :ref:`aggregate <t_aggregate>` value.
5567
5568 Arguments:
5569 """"""""""
5570
5571 The first operand of an '``insertvalue``' instruction is a value of
5572 :ref:`struct <t_struct>` or :ref:`array <t_array>` type. The second operand is
5573 a first-class value to insert. The following operands are constant
5574 indices indicating the position at which to insert the value in a
5575 similar manner as indices in a '``extractvalue``' instruction. The value
5576 to insert must have the same type as the value identified by the
5577 indices.
5578
5579 Semantics:
5580 """"""""""
5581
5582 The result is an aggregate of the same type as ``val``. Its value is
5583 that of ``val`` except that the value at the position specified by the
5584 indices is that of ``elt``.
5585
5586 Example:
5587 """"""""
5588
5589 .. code-block:: llvm
5590
5591       %agg1 = insertvalue {i32, float} undef, i32 1, 0              ; yields {i32 1, float undef}
5592       %agg2 = insertvalue {i32, float} %agg1, float %val, 1         ; yields {i32 1, float %val}
5593       %agg3 = insertvalue {i32, {float}} undef, float %val, 1, 0    ; yields {i32 undef, {float %val}}
5594
5595 .. _memoryops:
5596
5597 Memory Access and Addressing Operations
5598 ---------------------------------------
5599
5600 A key design point of an SSA-based representation is how it represents
5601 memory. In LLVM, no memory locations are in SSA form, which makes things
5602 very simple. This section describes how to read, write, and allocate
5603 memory in LLVM.
5604
5605 .. _i_alloca:
5606
5607 '``alloca``' Instruction
5608 ^^^^^^^^^^^^^^^^^^^^^^^^
5609
5610 Syntax:
5611 """""""
5612
5613 ::
5614
5615       <result> = alloca [inalloca] <type> [, <ty> <NumElements>] [, align <alignment>]     ; yields type*:result
5616
5617 Overview:
5618 """""""""
5619
5620 The '``alloca``' instruction allocates memory on the stack frame of the
5621 currently executing function, to be automatically released when this
5622 function returns to its caller. The object is always allocated in the
5623 generic address space (address space zero).
5624
5625 Arguments:
5626 """"""""""
5627
5628 The '``alloca``' instruction allocates ``sizeof(<type>)*NumElements``
5629 bytes of memory on the runtime stack, returning a pointer of the
5630 appropriate type to the program. If "NumElements" is specified, it is
5631 the number of elements allocated, otherwise "NumElements" is defaulted
5632 to be one. If a constant alignment is specified, the value result of the
5633 allocation is guaranteed to be aligned to at least that boundary. The
5634 alignment may not be greater than ``1 << 29``. If not specified, or if
5635 zero, the target can choose to align the allocation on any convenient
5636 boundary compatible with the type.
5637
5638 '``type``' may be any sized type.
5639
5640 Semantics:
5641 """"""""""
5642
5643 Memory is allocated; a pointer is returned. The operation is undefined
5644 if there is insufficient stack space for the allocation. '``alloca``'d
5645 memory is automatically released when the function returns. The
5646 '``alloca``' instruction is commonly used to represent automatic
5647 variables that must have an address available. When the function returns
5648 (either with the ``ret`` or ``resume`` instructions), the memory is
5649 reclaimed. Allocating zero bytes is legal, but the result is undefined.
5650 The order in which memory is allocated (ie., which way the stack grows)
5651 is not specified.
5652
5653 Example:
5654 """"""""
5655
5656 .. code-block:: llvm
5657
5658       %ptr = alloca i32                             ; yields i32*:ptr
5659       %ptr = alloca i32, i32 4                      ; yields i32*:ptr
5660       %ptr = alloca i32, i32 4, align 1024          ; yields i32*:ptr
5661       %ptr = alloca i32, align 1024                 ; yields i32*:ptr
5662
5663 .. _i_load:
5664
5665 '``load``' Instruction
5666 ^^^^^^^^^^^^^^^^^^^^^^
5667
5668 Syntax:
5669 """""""
5670
5671 ::
5672
5673       <result> = load [volatile] <ty>, <ty>* <pointer>[, align <alignment>][, !nontemporal !<index>][, !invariant.load !<index>][, !nonnull !<index>][, !dereferenceable !<index>][, !dereferenceable_or_null !<index>]
5674       <result> = load atomic [volatile] <ty>* <pointer> [singlethread] <ordering>, align <alignment>
5675       !<index> = !{ i32 1 }
5676
5677 Overview:
5678 """""""""
5679
5680 The '``load``' instruction is used to read from memory.
5681
5682 Arguments:
5683 """"""""""
5684
5685 The argument to the ``load`` instruction specifies the memory address
5686 from which to load. The type specified must be a :ref:`first
5687 class <t_firstclass>` type. If the ``load`` is marked as ``volatile``,
5688 then the optimizer is not allowed to modify the number or order of
5689 execution of this ``load`` with other :ref:`volatile
5690 operations <volatile>`.
5691
5692 If the ``load`` is marked as ``atomic``, it takes an extra
5693 :ref:`ordering <ordering>` and optional ``singlethread`` argument. The
5694 ``release`` and ``acq_rel`` orderings are not valid on ``load``
5695 instructions. Atomic loads produce :ref:`defined <memmodel>` results
5696 when they may see multiple atomic stores. The type of the pointee must
5697 be an integer type whose bit width is a power of two greater than or
5698 equal to eight and less than or equal to a target-specific size limit.
5699 ``align`` must be explicitly specified on atomic loads, and the load has
5700 undefined behavior if the alignment is not set to a value which is at
5701 least the size in bytes of the pointee. ``!nontemporal`` does not have
5702 any defined semantics for atomic loads.
5703
5704 The optional constant ``align`` argument specifies the alignment of the
5705 operation (that is, the alignment of the memory address). A value of 0
5706 or an omitted ``align`` argument means that the operation has the ABI
5707 alignment for the target. It is the responsibility of the code emitter
5708 to ensure that the alignment information is correct. Overestimating the
5709 alignment results in undefined behavior. Underestimating the alignment
5710 may produce less efficient code. An alignment of 1 is always safe. The
5711 maximum possible alignment is ``1 << 29``.
5712
5713 The optional ``!nontemporal`` metadata must reference a single
5714 metadata name ``<index>`` corresponding to a metadata node with one
5715 ``i32`` entry of value 1. The existence of the ``!nontemporal``
5716 metadata on the instruction tells the optimizer and code generator
5717 that this load is not expected to be reused in the cache. The code
5718 generator may select special instructions to save cache bandwidth, such
5719 as the ``MOVNT`` instruction on x86.
5720
5721 The optional ``!invariant.load`` metadata must reference a single
5722 metadata name ``<index>`` corresponding to a metadata node with no
5723 entries. The existence of the ``!invariant.load`` metadata on the
5724 instruction tells the optimizer and code generator that the address
5725 operand to this load points to memory which can be assumed unchanged.
5726 Being invariant does not imply that a location is dereferenceable,
5727 but it does imply that once the location is known dereferenceable
5728 its value is henceforth unchanging.
5729
5730 The optional ``!nonnull`` metadata must reference a single
5731 metadata name ``<index>`` corresponding to a metadata node with no
5732 entries. The existence of the ``!nonnull`` metadata on the
5733 instruction tells the optimizer that the value loaded is known to
5734 never be null.  This is analogous to the ''nonnull'' attribute
5735 on parameters and return values.  This metadata can only be applied
5736 to loads of a pointer type.
5737
5738 The optional ``!dereferenceable`` metadata must reference a single
5739 metadata name ``<index>`` corresponding to a metadata node with one ``i64``
5740 entry. The existence of the ``!dereferenceable`` metadata on the instruction 
5741 tells the optimizer that the value loaded is known to be dereferenceable.
5742 The number of bytes known to be dereferenceable is specified by the integer 
5743 value in the metadata node. This is analogous to the ''dereferenceable'' 
5744 attribute on parameters and return values.  This metadata can only be applied 
5745 to loads of a pointer type.
5746
5747 The optional ``!dereferenceable_or_null`` metadata must reference a single
5748 metadata name ``<index>`` corresponding to a metadata node with one ``i64``
5749 entry. The existence of the ``!dereferenceable_or_null`` metadata on the 
5750 instruction tells the optimizer that the value loaded is known to be either
5751 dereferenceable or null.
5752 The number of bytes known to be dereferenceable is specified by the integer 
5753 value in the metadata node. This is analogous to the ''dereferenceable_or_null'' 
5754 attribute on parameters and return values.  This metadata can only be applied 
5755 to loads of a pointer type.
5756
5757 Semantics:
5758 """"""""""
5759
5760 The location of memory pointed to is loaded. If the value being loaded
5761 is of scalar type then the number of bytes read does not exceed the
5762 minimum number of bytes needed to hold all bits of the type. For
5763 example, loading an ``i24`` reads at most three bytes. When loading a
5764 value of a type like ``i20`` with a size that is not an integral number
5765 of bytes, the result is undefined if the value was not originally
5766 written using a store of the same type.
5767
5768 Examples:
5769 """""""""
5770
5771 .. code-block:: llvm
5772
5773       %ptr = alloca i32                               ; yields i32*:ptr
5774       store i32 3, i32* %ptr                          ; yields void
5775       %val = load i32, i32* %ptr                      ; yields i32:val = i32 3
5776
5777 .. _i_store:
5778
5779 '``store``' Instruction
5780 ^^^^^^^^^^^^^^^^^^^^^^^
5781
5782 Syntax:
5783 """""""
5784
5785 ::
5786
5787       store [volatile] <ty> <value>, <ty>* <pointer>[, align <alignment>][, !nontemporal !<index>]        ; yields void
5788       store atomic [volatile] <ty> <value>, <ty>* <pointer> [singlethread] <ordering>, align <alignment>  ; yields void
5789
5790 Overview:
5791 """""""""
5792
5793 The '``store``' instruction is used to write to memory.
5794
5795 Arguments:
5796 """"""""""
5797
5798 There are two arguments to the ``store`` instruction: a value to store
5799 and an address at which to store it. The type of the ``<pointer>``
5800 operand must be a pointer to the :ref:`first class <t_firstclass>` type of
5801 the ``<value>`` operand. If the ``store`` is marked as ``volatile``,
5802 then the optimizer is not allowed to modify the number or order of
5803 execution of this ``store`` with other :ref:`volatile
5804 operations <volatile>`.
5805
5806 If the ``store`` is marked as ``atomic``, it takes an extra
5807 :ref:`ordering <ordering>` and optional ``singlethread`` argument. The
5808 ``acquire`` and ``acq_rel`` orderings aren't valid on ``store``
5809 instructions. Atomic loads produce :ref:`defined <memmodel>` results
5810 when they may see multiple atomic stores. The type of the pointee must
5811 be an integer type whose bit width is a power of two greater than or
5812 equal to eight and less than or equal to a target-specific size limit.
5813 ``align`` must be explicitly specified on atomic stores, and the store
5814 has undefined behavior if the alignment is not set to a value which is
5815 at least the size in bytes of the pointee. ``!nontemporal`` does not
5816 have any defined semantics for atomic stores.
5817
5818 The optional constant ``align`` argument specifies the alignment of the
5819 operation (that is, the alignment of the memory address). A value of 0
5820 or an omitted ``align`` argument means that the operation has the ABI
5821 alignment for the target. It is the responsibility of the code emitter
5822 to ensure that the alignment information is correct. Overestimating the
5823 alignment results in undefined behavior. Underestimating the
5824 alignment may produce less efficient code. An alignment of 1 is always
5825 safe. The maximum possible alignment is ``1 << 29``.
5826
5827 The optional ``!nontemporal`` metadata must reference a single metadata
5828 name ``<index>`` corresponding to a metadata node with one ``i32`` entry of
5829 value 1. The existence of the ``!nontemporal`` metadata on the instruction
5830 tells the optimizer and code generator that this load is not expected to
5831 be reused in the cache. The code generator may select special
5832 instructions to save cache bandwidth, such as the MOVNT instruction on
5833 x86.
5834
5835 Semantics:
5836 """"""""""
5837
5838 The contents of memory are updated to contain ``<value>`` at the
5839 location specified by the ``<pointer>`` operand. If ``<value>`` is
5840 of scalar type then the number of bytes written does not exceed the
5841 minimum number of bytes needed to hold all bits of the type. For
5842 example, storing an ``i24`` writes at most three bytes. When writing a
5843 value of a type like ``i20`` with a size that is not an integral number
5844 of bytes, it is unspecified what happens to the extra bits that do not
5845 belong to the type, but they will typically be overwritten.
5846
5847 Example:
5848 """"""""
5849
5850 .. code-block:: llvm
5851
5852       %ptr = alloca i32                               ; yields i32*:ptr
5853       store i32 3, i32* %ptr                          ; yields void
5854       %val = load i32* %ptr                           ; yields i32:val = i32 3
5855
5856 .. _i_fence:
5857
5858 '``fence``' Instruction
5859 ^^^^^^^^^^^^^^^^^^^^^^^
5860
5861 Syntax:
5862 """""""
5863
5864 ::
5865
5866       fence [singlethread] <ordering>                   ; yields void
5867
5868 Overview:
5869 """""""""
5870
5871 The '``fence``' instruction is used to introduce happens-before edges
5872 between operations.
5873
5874 Arguments:
5875 """"""""""
5876
5877 '``fence``' instructions take an :ref:`ordering <ordering>` argument which
5878 defines what *synchronizes-with* edges they add. They can only be given
5879 ``acquire``, ``release``, ``acq_rel``, and ``seq_cst`` orderings.
5880
5881 Semantics:
5882 """"""""""
5883
5884 A fence A which has (at least) ``release`` ordering semantics
5885 *synchronizes with* a fence B with (at least) ``acquire`` ordering
5886 semantics if and only if there exist atomic operations X and Y, both
5887 operating on some atomic object M, such that A is sequenced before X, X
5888 modifies M (either directly or through some side effect of a sequence
5889 headed by X), Y is sequenced before B, and Y observes M. This provides a
5890 *happens-before* dependency between A and B. Rather than an explicit
5891 ``fence``, one (but not both) of the atomic operations X or Y might
5892 provide a ``release`` or ``acquire`` (resp.) ordering constraint and
5893 still *synchronize-with* the explicit ``fence`` and establish the
5894 *happens-before* edge.
5895
5896 A ``fence`` which has ``seq_cst`` ordering, in addition to having both
5897 ``acquire`` and ``release`` semantics specified above, participates in
5898 the global program order of other ``seq_cst`` operations and/or fences.
5899
5900 The optional ":ref:`singlethread <singlethread>`" argument specifies
5901 that the fence only synchronizes with other fences in the same thread.
5902 (This is useful for interacting with signal handlers.)
5903
5904 Example:
5905 """"""""
5906
5907 .. code-block:: llvm
5908
5909       fence acquire                          ; yields void
5910       fence singlethread seq_cst             ; yields void
5911
5912 .. _i_cmpxchg:
5913
5914 '``cmpxchg``' Instruction
5915 ^^^^^^^^^^^^^^^^^^^^^^^^^
5916
5917 Syntax:
5918 """""""
5919
5920 ::
5921
5922       cmpxchg [weak] [volatile] <ty>* <pointer>, <ty> <cmp>, <ty> <new> [singlethread] <success ordering> <failure ordering> ; yields  { ty, i1 }
5923
5924 Overview:
5925 """""""""
5926
5927 The '``cmpxchg``' instruction is used to atomically modify memory. It
5928 loads a value in memory and compares it to a given value. If they are
5929 equal, it tries to store a new value into the memory.
5930
5931 Arguments:
5932 """"""""""
5933
5934 There are three arguments to the '``cmpxchg``' instruction: an address
5935 to operate on, a value to compare to the value currently be at that
5936 address, and a new value to place at that address if the compared values
5937 are equal. The type of '<cmp>' must be an integer type whose bit width
5938 is a power of two greater than or equal to eight and less than or equal
5939 to a target-specific size limit. '<cmp>' and '<new>' must have the same
5940 type, and the type of '<pointer>' must be a pointer to that type. If the
5941 ``cmpxchg`` is marked as ``volatile``, then the optimizer is not allowed
5942 to modify the number or order of execution of this ``cmpxchg`` with
5943 other :ref:`volatile operations <volatile>`.
5944
5945 The success and failure :ref:`ordering <ordering>` arguments specify how this
5946 ``cmpxchg`` synchronizes with other atomic operations. Both ordering parameters
5947 must be at least ``monotonic``, the ordering constraint on failure must be no
5948 stronger than that on success, and the failure ordering cannot be either
5949 ``release`` or ``acq_rel``.
5950
5951 The optional "``singlethread``" argument declares that the ``cmpxchg``
5952 is only atomic with respect to code (usually signal handlers) running in
5953 the same thread as the ``cmpxchg``. Otherwise the cmpxchg is atomic with
5954 respect to all other code in the system.
5955
5956 The pointer passed into cmpxchg must have alignment greater than or
5957 equal to the size in memory of the operand.
5958
5959 Semantics:
5960 """"""""""
5961
5962 The contents of memory at the location specified by the '``<pointer>``' operand
5963 is read and compared to '``<cmp>``'; if the read value is the equal, the
5964 '``<new>``' is written. The original value at the location is returned, together
5965 with a flag indicating success (true) or failure (false).
5966
5967 If the cmpxchg operation is marked as ``weak`` then a spurious failure is
5968 permitted: the operation may not write ``<new>`` even if the comparison
5969 matched.
5970
5971 If the cmpxchg operation is strong (the default), the i1 value is 1 if and only
5972 if the value loaded equals ``cmp``.
5973
5974 A successful ``cmpxchg`` is a read-modify-write instruction for the purpose of
5975 identifying release sequences. A failed ``cmpxchg`` is equivalent to an atomic
5976 load with an ordering parameter determined the second ordering parameter.
5977
5978 Example:
5979 """"""""
5980
5981 .. code-block:: llvm
5982
5983     entry:
5984       %orig = atomic load i32, i32* %ptr unordered                ; yields i32
5985       br label %loop
5986
5987     loop:
5988       %cmp = phi i32 [ %orig, %entry ], [%old, %loop]
5989       %squared = mul i32 %cmp, %cmp
5990       %val_success = cmpxchg i32* %ptr, i32 %cmp, i32 %squared acq_rel monotonic ; yields  { i32, i1 }
5991       %value_loaded = extractvalue { i32, i1 } %val_success, 0
5992       %success = extractvalue { i32, i1 } %val_success, 1
5993       br i1 %success, label %done, label %loop
5994
5995     done:
5996       ...
5997
5998 .. _i_atomicrmw:
5999
6000 '``atomicrmw``' Instruction
6001 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
6002
6003 Syntax:
6004 """""""
6005
6006 ::
6007
6008       atomicrmw [volatile] <operation> <ty>* <pointer>, <ty> <value> [singlethread] <ordering>                   ; yields ty
6009
6010 Overview:
6011 """""""""
6012
6013 The '``atomicrmw``' instruction is used to atomically modify memory.
6014
6015 Arguments:
6016 """"""""""
6017
6018 There are three arguments to the '``atomicrmw``' instruction: an
6019 operation to apply, an address whose value to modify, an argument to the
6020 operation. The operation must be one of the following keywords:
6021
6022 -  xchg
6023 -  add
6024 -  sub
6025 -  and
6026 -  nand
6027 -  or
6028 -  xor
6029 -  max
6030 -  min
6031 -  umax
6032 -  umin
6033
6034 The type of '<value>' must be an integer type whose bit width is a power
6035 of two greater than or equal to eight and less than or equal to a
6036 target-specific size limit. The type of the '``<pointer>``' operand must
6037 be a pointer to that type. If the ``atomicrmw`` is marked as
6038 ``volatile``, then the optimizer is not allowed to modify the number or
6039 order of execution of this ``atomicrmw`` with other :ref:`volatile
6040 operations <volatile>`.
6041
6042 Semantics:
6043 """"""""""
6044
6045 The contents of memory at the location specified by the '``<pointer>``'
6046 operand are atomically read, modified, and written back. The original
6047 value at the location is returned. The modification is specified by the
6048 operation argument:
6049
6050 -  xchg: ``*ptr = val``
6051 -  add: ``*ptr = *ptr + val``
6052 -  sub: ``*ptr = *ptr - val``
6053 -  and: ``*ptr = *ptr & val``
6054 -  nand: ``*ptr = ~(*ptr & val)``
6055 -  or: ``*ptr = *ptr | val``
6056 -  xor: ``*ptr = *ptr ^ val``
6057 -  max: ``*ptr = *ptr > val ? *ptr : val`` (using a signed comparison)
6058 -  min: ``*ptr = *ptr < val ? *ptr : val`` (using a signed comparison)
6059 -  umax: ``*ptr = *ptr > val ? *ptr : val`` (using an unsigned
6060    comparison)
6061 -  umin: ``*ptr = *ptr < val ? *ptr : val`` (using an unsigned
6062    comparison)
6063
6064 Example:
6065 """"""""
6066
6067 .. code-block:: llvm
6068
6069       %old = atomicrmw add i32* %ptr, i32 1 acquire                        ; yields i32
6070
6071 .. _i_getelementptr:
6072
6073 '``getelementptr``' Instruction
6074 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6075
6076 Syntax:
6077 """""""
6078
6079 ::
6080
6081       <result> = getelementptr <ty>, <ty>* <ptrval>{, <ty> <idx>}*
6082       <result> = getelementptr inbounds <ty>, <ty>* <ptrval>{, <ty> <idx>}*
6083       <result> = getelementptr <ty>, <ptr vector> <ptrval>, <vector index type> <idx>
6084
6085 Overview:
6086 """""""""
6087
6088 The '``getelementptr``' instruction is used to get the address of a
6089 subelement of an :ref:`aggregate <t_aggregate>` data structure. It performs
6090 address calculation only and does not access memory.
6091
6092 Arguments:
6093 """"""""""
6094
6095 The first argument is always a type used as the basis for the calculations.
6096 The second argument is always a pointer or a vector of pointers, and is the
6097 base address to start from. The remaining arguments are indices
6098 that indicate which of the elements of the aggregate object are indexed.
6099 The interpretation of each index is dependent on the type being indexed
6100 into. The first index always indexes the pointer value given as the
6101 first argument, the second index indexes a value of the type pointed to
6102 (not necessarily the value directly pointed to, since the first index
6103 can be non-zero), etc. The first type indexed into must be a pointer
6104 value, subsequent types can be arrays, vectors, and structs. Note that
6105 subsequent types being indexed into can never be pointers, since that
6106 would require loading the pointer before continuing calculation.
6107
6108 The type of each index argument depends on the type it is indexing into.
6109 When indexing into a (optionally packed) structure, only ``i32`` integer
6110 **constants** are allowed (when using a vector of indices they must all
6111 be the **same** ``i32`` integer constant). When indexing into an array,
6112 pointer or vector, integers of any width are allowed, and they are not
6113 required to be constant. These integers are treated as signed values
6114 where relevant.
6115
6116 For example, let's consider a C code fragment and how it gets compiled
6117 to LLVM:
6118
6119 .. code-block:: c
6120
6121     struct RT {
6122       char A;
6123       int B[10][20];
6124       char C;
6125     };
6126     struct ST {
6127       int X;
6128       double Y;
6129       struct RT Z;
6130     };
6131
6132     int *foo(struct ST *s) {
6133       return &s[1].Z.B[5][13];
6134     }
6135
6136 The LLVM code generated by Clang is:
6137
6138 .. code-block:: llvm
6139
6140     %struct.RT = type { i8, [10 x [20 x i32]], i8 }
6141     %struct.ST = type { i32, double, %struct.RT }
6142
6143     define i32* @foo(%struct.ST* %s) nounwind uwtable readnone optsize ssp {
6144     entry:
6145       %arrayidx = getelementptr inbounds %struct.ST, %struct.ST* %s, i64 1, i32 2, i32 1, i64 5, i64 13
6146       ret i32* %arrayidx
6147     }
6148
6149 Semantics:
6150 """"""""""
6151
6152 In the example above, the first index is indexing into the
6153 '``%struct.ST*``' type, which is a pointer, yielding a '``%struct.ST``'
6154 = '``{ i32, double, %struct.RT }``' type, a structure. The second index
6155 indexes into the third element of the structure, yielding a
6156 '``%struct.RT``' = '``{ i8 , [10 x [20 x i32]], i8 }``' type, another
6157 structure. The third index indexes into the second element of the
6158 structure, yielding a '``[10 x [20 x i32]]``' type, an array. The two
6159 dimensions of the array are subscripted into, yielding an '``i32``'
6160 type. The '``getelementptr``' instruction returns a pointer to this
6161 element, thus computing a value of '``i32*``' type.
6162
6163 Note that it is perfectly legal to index partially through a structure,
6164 returning a pointer to an inner element. Because of this, the LLVM code
6165 for the given testcase is equivalent to:
6166
6167 .. code-block:: llvm
6168
6169     define i32* @foo(%struct.ST* %s) {
6170       %t1 = getelementptr %struct.ST, %struct.ST* %s, i32 1                        ; yields %struct.ST*:%t1
6171       %t2 = getelementptr %struct.ST, %struct.ST* %t1, i32 0, i32 2                ; yields %struct.RT*:%t2
6172       %t3 = getelementptr %struct.RT, %struct.RT* %t2, i32 0, i32 1                ; yields [10 x [20 x i32]]*:%t3
6173       %t4 = getelementptr [10 x [20 x i32]], [10 x [20 x i32]]* %t3, i32 0, i32 5  ; yields [20 x i32]*:%t4
6174       %t5 = getelementptr [20 x i32], [20 x i32]* %t4, i32 0, i32 13               ; yields i32*:%t5
6175       ret i32* %t5
6176     }
6177
6178 If the ``inbounds`` keyword is present, the result value of the
6179 ``getelementptr`` is a :ref:`poison value <poisonvalues>` if the base
6180 pointer is not an *in bounds* address of an allocated object, or if any
6181 of the addresses that would be formed by successive addition of the
6182 offsets implied by the indices to the base address with infinitely
6183 precise signed arithmetic are not an *in bounds* address of that
6184 allocated object. The *in bounds* addresses for an allocated object are
6185 all the addresses that point into the object, plus the address one byte
6186 past the end. In cases where the base is a vector of pointers the
6187 ``inbounds`` keyword applies to each of the computations element-wise.
6188
6189 If the ``inbounds`` keyword is not present, the offsets are added to the
6190 base address with silently-wrapping two's complement arithmetic. If the
6191 offsets have a different width from the pointer, they are sign-extended
6192 or truncated to the width of the pointer. The result value of the
6193 ``getelementptr`` may be outside the object pointed to by the base
6194 pointer. The result value may not necessarily be used to access memory
6195 though, even if it happens to point into allocated storage. See the
6196 :ref:`Pointer Aliasing Rules <pointeraliasing>` section for more
6197 information.
6198
6199 The getelementptr instruction is often confusing. For some more insight
6200 into how it works, see :doc:`the getelementptr FAQ <GetElementPtr>`.
6201
6202 Example:
6203 """"""""
6204
6205 .. code-block:: llvm
6206
6207         ; yields [12 x i8]*:aptr
6208         %aptr = getelementptr {i32, [12 x i8]}, {i32, [12 x i8]}* %saptr, i64 0, i32 1
6209         ; yields i8*:vptr
6210         %vptr = getelementptr {i32, <2 x i8>}, {i32, <2 x i8>}* %svptr, i64 0, i32 1, i32 1
6211         ; yields i8*:eptr
6212         %eptr = getelementptr [12 x i8], [12 x i8]* %aptr, i64 0, i32 1
6213         ; yields i32*:iptr
6214         %iptr = getelementptr [10 x i32], [10 x i32]* @arr, i16 0, i16 0
6215
6216 In cases where the pointer argument is a vector of pointers, each index
6217 must be a vector with the same number of elements. For example:
6218
6219 .. code-block:: llvm
6220
6221      %A = getelementptr i8, <4 x i8*> %ptrs, <4 x i64> %offsets,
6222
6223 Conversion Operations
6224 ---------------------
6225
6226 The instructions in this category are the conversion instructions
6227 (casting) which all take a single operand and a type. They perform
6228 various bit conversions on the operand.
6229
6230 '``trunc .. to``' Instruction
6231 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6232
6233 Syntax:
6234 """""""
6235
6236 ::
6237
6238       <result> = trunc <ty> <value> to <ty2>             ; yields ty2
6239
6240 Overview:
6241 """""""""
6242
6243 The '``trunc``' instruction truncates its operand to the type ``ty2``.
6244
6245 Arguments:
6246 """"""""""
6247
6248 The '``trunc``' instruction takes a value to trunc, and a type to trunc
6249 it to. Both types must be of :ref:`integer <t_integer>` types, or vectors
6250 of the same number of integers. The bit size of the ``value`` must be
6251 larger than the bit size of the destination type, ``ty2``. Equal sized
6252 types are not allowed.
6253
6254 Semantics:
6255 """"""""""
6256
6257 The '``trunc``' instruction truncates the high order bits in ``value``
6258 and converts the remaining bits to ``ty2``. Since the source size must
6259 be larger than the destination size, ``trunc`` cannot be a *no-op cast*.
6260 It will always truncate bits.
6261
6262 Example:
6263 """"""""
6264
6265 .. code-block:: llvm
6266
6267       %X = trunc i32 257 to i8                        ; yields i8:1
6268       %Y = trunc i32 123 to i1                        ; yields i1:true
6269       %Z = trunc i32 122 to i1                        ; yields i1:false
6270       %W = trunc <2 x i16> <i16 8, i16 7> to <2 x i8> ; yields <i8 8, i8 7>
6271
6272 '``zext .. to``' Instruction
6273 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6274
6275 Syntax:
6276 """""""
6277
6278 ::
6279
6280       <result> = zext <ty> <value> to <ty2>             ; yields ty2
6281
6282 Overview:
6283 """""""""
6284
6285 The '``zext``' instruction zero extends its operand to type ``ty2``.
6286
6287 Arguments:
6288 """"""""""
6289
6290 The '``zext``' instruction takes a value to cast, and a type to cast it
6291 to. Both types must be of :ref:`integer <t_integer>` types, or vectors of
6292 the same number of integers. The bit size of the ``value`` must be
6293 smaller than the bit size of the destination type, ``ty2``.
6294
6295 Semantics:
6296 """"""""""
6297
6298 The ``zext`` fills the high order bits of the ``value`` with zero bits
6299 until it reaches the size of the destination type, ``ty2``.
6300
6301 When zero extending from i1, the result will always be either 0 or 1.
6302
6303 Example:
6304 """"""""
6305
6306 .. code-block:: llvm
6307
6308       %X = zext i32 257 to i64              ; yields i64:257
6309       %Y = zext i1 true to i32              ; yields i32:1
6310       %Z = zext <2 x i16> <i16 8, i16 7> to <2 x i32> ; yields <i32 8, i32 7>
6311
6312 '``sext .. to``' Instruction
6313 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6314
6315 Syntax:
6316 """""""
6317
6318 ::
6319
6320       <result> = sext <ty> <value> to <ty2>             ; yields ty2
6321
6322 Overview:
6323 """""""""
6324
6325 The '``sext``' sign extends ``value`` to the type ``ty2``.
6326
6327 Arguments:
6328 """"""""""
6329
6330 The '``sext``' instruction takes a value to cast, and a type to cast it
6331 to. Both types must be of :ref:`integer <t_integer>` types, or vectors of
6332 the same number of integers. The bit size of the ``value`` must be
6333 smaller than the bit size of the destination type, ``ty2``.
6334
6335 Semantics:
6336 """"""""""
6337
6338 The '``sext``' instruction performs a sign extension by copying the sign
6339 bit (highest order bit) of the ``value`` until it reaches the bit size
6340 of the type ``ty2``.
6341
6342 When sign extending from i1, the extension always results in -1 or 0.
6343
6344 Example:
6345 """"""""
6346
6347 .. code-block:: llvm
6348
6349       %X = sext i8  -1 to i16              ; yields i16   :65535
6350       %Y = sext i1 true to i32             ; yields i32:-1
6351       %Z = sext <2 x i16> <i16 8, i16 7> to <2 x i32> ; yields <i32 8, i32 7>
6352
6353 '``fptrunc .. to``' Instruction
6354 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6355
6356 Syntax:
6357 """""""
6358
6359 ::
6360
6361       <result> = fptrunc <ty> <value> to <ty2>             ; yields ty2
6362
6363 Overview:
6364 """""""""
6365
6366 The '``fptrunc``' instruction truncates ``value`` to type ``ty2``.
6367
6368 Arguments:
6369 """"""""""
6370
6371 The '``fptrunc``' instruction takes a :ref:`floating point <t_floating>`
6372 value to cast and a :ref:`floating point <t_floating>` type to cast it to.
6373 The size of ``value`` must be larger than the size of ``ty2``. This
6374 implies that ``fptrunc`` cannot be used to make a *no-op cast*.
6375
6376 Semantics:
6377 """"""""""
6378
6379 The '``fptrunc``' instruction truncates a ``value`` from a larger
6380 :ref:`floating point <t_floating>` type to a smaller :ref:`floating
6381 point <t_floating>` type. If the value cannot fit within the
6382 destination type, ``ty2``, then the results are undefined.
6383
6384 Example:
6385 """"""""
6386
6387 .. code-block:: llvm
6388
6389       %X = fptrunc double 123.0 to float         ; yields float:123.0
6390       %Y = fptrunc double 1.0E+300 to float      ; yields undefined
6391
6392 '``fpext .. to``' Instruction
6393 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6394
6395 Syntax:
6396 """""""
6397
6398 ::
6399
6400       <result> = fpext <ty> <value> to <ty2>             ; yields ty2
6401
6402 Overview:
6403 """""""""
6404
6405 The '``fpext``' extends a floating point ``value`` to a larger floating
6406 point value.
6407
6408 Arguments:
6409 """"""""""
6410
6411 The '``fpext``' instruction takes a :ref:`floating point <t_floating>`
6412 ``value`` to cast, and a :ref:`floating point <t_floating>` type to cast it
6413 to. The source type must be smaller than the destination type.
6414
6415 Semantics:
6416 """"""""""
6417
6418 The '``fpext``' instruction extends the ``value`` from a smaller
6419 :ref:`floating point <t_floating>` type to a larger :ref:`floating
6420 point <t_floating>` type. The ``fpext`` cannot be used to make a
6421 *no-op cast* because it always changes bits. Use ``bitcast`` to make a
6422 *no-op cast* for a floating point cast.
6423
6424 Example:
6425 """"""""
6426
6427 .. code-block:: llvm
6428
6429       %X = fpext float 3.125 to double         ; yields double:3.125000e+00
6430       %Y = fpext double %X to fp128            ; yields fp128:0xL00000000000000004000900000000000
6431
6432 '``fptoui .. to``' Instruction
6433 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6434
6435 Syntax:
6436 """""""
6437
6438 ::
6439
6440       <result> = fptoui <ty> <value> to <ty2>             ; yields ty2
6441
6442 Overview:
6443 """""""""
6444
6445 The '``fptoui``' converts a floating point ``value`` to its unsigned
6446 integer equivalent of type ``ty2``.
6447
6448 Arguments:
6449 """"""""""
6450
6451 The '``fptoui``' instruction takes a value to cast, which must be a
6452 scalar or vector :ref:`floating point <t_floating>` value, and a type to
6453 cast it to ``ty2``, which must be an :ref:`integer <t_integer>` type. If
6454 ``ty`` is a vector floating point type, ``ty2`` must be a vector integer
6455 type with the same number of elements as ``ty``
6456
6457 Semantics:
6458 """"""""""
6459
6460 The '``fptoui``' instruction converts its :ref:`floating
6461 point <t_floating>` operand into the nearest (rounding towards zero)
6462 unsigned integer value. If the value cannot fit in ``ty2``, the results
6463 are undefined.
6464
6465 Example:
6466 """"""""
6467
6468 .. code-block:: llvm
6469
6470       %X = fptoui double 123.0 to i32      ; yields i32:123
6471       %Y = fptoui float 1.0E+300 to i1     ; yields undefined:1
6472       %Z = fptoui float 1.04E+17 to i8     ; yields undefined:1
6473
6474 '``fptosi .. to``' Instruction
6475 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6476
6477 Syntax:
6478 """""""
6479
6480 ::
6481
6482       <result> = fptosi <ty> <value> to <ty2>             ; yields ty2
6483
6484 Overview:
6485 """""""""
6486
6487 The '``fptosi``' instruction converts :ref:`floating point <t_floating>`
6488 ``value`` to type ``ty2``.
6489
6490 Arguments:
6491 """"""""""
6492
6493 The '``fptosi``' instruction takes a value to cast, which must be a
6494 scalar or vector :ref:`floating point <t_floating>` value, and a type to
6495 cast it to ``ty2``, which must be an :ref:`integer <t_integer>` type. If
6496 ``ty`` is a vector floating point type, ``ty2`` must be a vector integer
6497 type with the same number of elements as ``ty``
6498
6499 Semantics:
6500 """"""""""
6501
6502 The '``fptosi``' instruction converts its :ref:`floating
6503 point <t_floating>` operand into the nearest (rounding towards zero)
6504 signed integer value. If the value cannot fit in ``ty2``, the results
6505 are undefined.
6506
6507 Example:
6508 """"""""
6509
6510 .. code-block:: llvm
6511
6512       %X = fptosi double -123.0 to i32      ; yields i32:-123
6513       %Y = fptosi float 1.0E-247 to i1      ; yields undefined:1
6514       %Z = fptosi float 1.04E+17 to i8      ; yields undefined:1
6515
6516 '``uitofp .. to``' Instruction
6517 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6518
6519 Syntax:
6520 """""""
6521
6522 ::
6523
6524       <result> = uitofp <ty> <value> to <ty2>             ; yields ty2
6525
6526 Overview:
6527 """""""""
6528
6529 The '``uitofp``' instruction regards ``value`` as an unsigned integer
6530 and converts that value to the ``ty2`` type.
6531
6532 Arguments:
6533 """"""""""
6534
6535 The '``uitofp``' instruction takes a value to cast, which must be a
6536 scalar or vector :ref:`integer <t_integer>` value, and a type to cast it to
6537 ``ty2``, which must be an :ref:`floating point <t_floating>` type. If
6538 ``ty`` is a vector integer type, ``ty2`` must be a vector floating point
6539 type with the same number of elements as ``ty``
6540
6541 Semantics:
6542 """"""""""
6543
6544 The '``uitofp``' instruction interprets its operand as an unsigned
6545 integer quantity and converts it to the corresponding floating point
6546 value. If the value cannot fit in the floating point value, the results
6547 are undefined.
6548
6549 Example:
6550 """"""""
6551
6552 .. code-block:: llvm
6553
6554       %X = uitofp i32 257 to float         ; yields float:257.0
6555       %Y = uitofp i8 -1 to double          ; yields double:255.0
6556
6557 '``sitofp .. to``' Instruction
6558 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6559
6560 Syntax:
6561 """""""
6562
6563 ::
6564
6565       <result> = sitofp <ty> <value> to <ty2>             ; yields ty2
6566
6567 Overview:
6568 """""""""
6569
6570 The '``sitofp``' instruction regards ``value`` as a signed integer and
6571 converts that value to the ``ty2`` type.
6572
6573 Arguments:
6574 """"""""""
6575
6576 The '``sitofp``' instruction takes a value to cast, which must be a
6577 scalar or vector :ref:`integer <t_integer>` value, and a type to cast it to
6578 ``ty2``, which must be an :ref:`floating point <t_floating>` type. If
6579 ``ty`` is a vector integer type, ``ty2`` must be a vector floating point
6580 type with the same number of elements as ``ty``
6581
6582 Semantics:
6583 """"""""""
6584
6585 The '``sitofp``' instruction interprets its operand as a signed integer
6586 quantity and converts it to the corresponding floating point value. If
6587 the value cannot fit in the floating point value, the results are
6588 undefined.
6589
6590 Example:
6591 """"""""
6592
6593 .. code-block:: llvm
6594
6595       %X = sitofp i32 257 to float         ; yields float:257.0
6596       %Y = sitofp i8 -1 to double          ; yields double:-1.0
6597
6598 .. _i_ptrtoint:
6599
6600 '``ptrtoint .. to``' Instruction
6601 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6602
6603 Syntax:
6604 """""""
6605
6606 ::
6607
6608       <result> = ptrtoint <ty> <value> to <ty2>             ; yields ty2
6609
6610 Overview:
6611 """""""""
6612
6613 The '``ptrtoint``' instruction converts the pointer or a vector of
6614 pointers ``value`` to the integer (or vector of integers) type ``ty2``.
6615
6616 Arguments:
6617 """"""""""
6618
6619 The '``ptrtoint``' instruction takes a ``value`` to cast, which must be
6620 a value of type :ref:`pointer <t_pointer>` or a vector of pointers, and a
6621 type to cast it to ``ty2``, which must be an :ref:`integer <t_integer>` or
6622 a vector of integers type.
6623
6624 Semantics:
6625 """"""""""
6626
6627 The '``ptrtoint``' instruction converts ``value`` to integer type
6628 ``ty2`` by interpreting the pointer value as an integer and either
6629 truncating or zero extending that value to the size of the integer type.
6630 If ``value`` is smaller than ``ty2`` then a zero extension is done. If
6631 ``value`` is larger than ``ty2`` then a truncation is done. If they are
6632 the same size, then nothing is done (*no-op cast*) other than a type
6633 change.
6634
6635 Example:
6636 """"""""
6637
6638 .. code-block:: llvm
6639
6640       %X = ptrtoint i32* %P to i8                         ; yields truncation on 32-bit architecture
6641       %Y = ptrtoint i32* %P to i64                        ; yields zero extension on 32-bit architecture
6642       %Z = ptrtoint <4 x i32*> %P to <4 x i64>; yields vector zero extension for a vector of addresses on 32-bit architecture
6643
6644 .. _i_inttoptr:
6645
6646 '``inttoptr .. to``' Instruction
6647 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6648
6649 Syntax:
6650 """""""
6651
6652 ::
6653
6654       <result> = inttoptr <ty> <value> to <ty2>             ; yields ty2
6655
6656 Overview:
6657 """""""""
6658
6659 The '``inttoptr``' instruction converts an integer ``value`` to a
6660 pointer type, ``ty2``.
6661
6662 Arguments:
6663 """"""""""
6664
6665 The '``inttoptr``' instruction takes an :ref:`integer <t_integer>` value to
6666 cast, and a type to cast it to, which must be a :ref:`pointer <t_pointer>`
6667 type.
6668
6669 Semantics:
6670 """"""""""
6671
6672 The '``inttoptr``' instruction converts ``value`` to type ``ty2`` by
6673 applying either a zero extension or a truncation depending on the size
6674 of the integer ``value``. If ``value`` is larger than the size of a
6675 pointer then a truncation is done. If ``value`` is smaller than the size
6676 of a pointer then a zero extension is done. If they are the same size,
6677 nothing is done (*no-op cast*).
6678
6679 Example:
6680 """"""""
6681
6682 .. code-block:: llvm
6683
6684       %X = inttoptr i32 255 to i32*          ; yields zero extension on 64-bit architecture
6685       %Y = inttoptr i32 255 to i32*          ; yields no-op on 32-bit architecture
6686       %Z = inttoptr i64 0 to i32*            ; yields truncation on 32-bit architecture
6687       %Z = inttoptr <4 x i32> %G to <4 x i8*>; yields truncation of vector G to four pointers
6688
6689 .. _i_bitcast:
6690
6691 '``bitcast .. to``' Instruction
6692 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6693
6694 Syntax:
6695 """""""
6696
6697 ::
6698
6699       <result> = bitcast <ty> <value> to <ty2>             ; yields ty2
6700
6701 Overview:
6702 """""""""
6703
6704 The '``bitcast``' instruction converts ``value`` to type ``ty2`` without
6705 changing any bits.
6706
6707 Arguments:
6708 """"""""""
6709
6710 The '``bitcast``' instruction takes a value to cast, which must be a
6711 non-aggregate first class value, and a type to cast it to, which must
6712 also be a non-aggregate :ref:`first class <t_firstclass>` type. The
6713 bit sizes of ``value`` and the destination type, ``ty2``, must be
6714 identical.  If the source type is a pointer, the destination type must
6715 also be a pointer of the same size. This instruction supports bitwise
6716 conversion of vectors to integers and to vectors of other types (as
6717 long as they have the same size).
6718
6719 Semantics:
6720 """"""""""
6721
6722 The '``bitcast``' instruction converts ``value`` to type ``ty2``. It
6723 is always a *no-op cast* because no bits change with this
6724 conversion. The conversion is done as if the ``value`` had been stored
6725 to memory and read back as type ``ty2``. Pointer (or vector of
6726 pointers) types may only be converted to other pointer (or vector of
6727 pointers) types with the same address space through this instruction.
6728 To convert pointers to other types, use the :ref:`inttoptr <i_inttoptr>`
6729 or :ref:`ptrtoint <i_ptrtoint>` instructions first.
6730
6731 Example:
6732 """"""""
6733
6734 .. code-block:: llvm
6735
6736       %X = bitcast i8 255 to i8              ; yields i8 :-1
6737       %Y = bitcast i32* %x to sint*          ; yields sint*:%x
6738       %Z = bitcast <2 x int> %V to i64;        ; yields i64: %V
6739       %Z = bitcast <2 x i32*> %V to <2 x i64*> ; yields <2 x i64*>
6740
6741 .. _i_addrspacecast:
6742
6743 '``addrspacecast .. to``' Instruction
6744 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6745
6746 Syntax:
6747 """""""
6748
6749 ::
6750
6751       <result> = addrspacecast <pty> <ptrval> to <pty2>       ; yields pty2
6752
6753 Overview:
6754 """""""""
6755
6756 The '``addrspacecast``' instruction converts ``ptrval`` from ``pty`` in
6757 address space ``n`` to type ``pty2`` in address space ``m``.
6758
6759 Arguments:
6760 """"""""""
6761
6762 The '``addrspacecast``' instruction takes a pointer or vector of pointer value
6763 to cast and a pointer type to cast it to, which must have a different
6764 address space.
6765
6766 Semantics:
6767 """"""""""
6768
6769 The '``addrspacecast``' instruction converts the pointer value
6770 ``ptrval`` to type ``pty2``. It can be a *no-op cast* or a complex
6771 value modification, depending on the target and the address space
6772 pair. Pointer conversions within the same address space must be
6773 performed with the ``bitcast`` instruction. Note that if the address space
6774 conversion is legal then both result and operand refer to the same memory
6775 location.
6776
6777 Example:
6778 """"""""
6779
6780 .. code-block:: llvm
6781
6782       %X = addrspacecast i32* %x to i32 addrspace(1)*    ; yields i32 addrspace(1)*:%x
6783       %Y = addrspacecast i32 addrspace(1)* %y to i64 addrspace(2)*    ; yields i64 addrspace(2)*:%y
6784       %Z = addrspacecast <4 x i32*> %z to <4 x float addrspace(3)*>   ; yields <4 x float addrspace(3)*>:%z
6785
6786 .. _otherops:
6787
6788 Other Operations
6789 ----------------
6790
6791 The instructions in this category are the "miscellaneous" instructions,
6792 which defy better classification.
6793
6794 .. _i_icmp:
6795
6796 '``icmp``' Instruction
6797 ^^^^^^^^^^^^^^^^^^^^^^
6798
6799 Syntax:
6800 """""""
6801
6802 ::
6803
6804       <result> = icmp <cond> <ty> <op1>, <op2>   ; yields i1 or <N x i1>:result
6805
6806 Overview:
6807 """""""""
6808
6809 The '``icmp``' instruction returns a boolean value or a vector of
6810 boolean values based on comparison of its two integer, integer vector,
6811 pointer, or pointer vector operands.
6812
6813 Arguments:
6814 """"""""""
6815
6816 The '``icmp``' instruction takes three operands. The first operand is
6817 the condition code indicating the kind of comparison to perform. It is
6818 not a value, just a keyword. The possible condition code are:
6819
6820 #. ``eq``: equal
6821 #. ``ne``: not equal
6822 #. ``ugt``: unsigned greater than
6823 #. ``uge``: unsigned greater or equal
6824 #. ``ult``: unsigned less than
6825 #. ``ule``: unsigned less or equal
6826 #. ``sgt``: signed greater than
6827 #. ``sge``: signed greater or equal
6828 #. ``slt``: signed less than
6829 #. ``sle``: signed less or equal
6830
6831 The remaining two arguments must be :ref:`integer <t_integer>` or
6832 :ref:`pointer <t_pointer>` or integer :ref:`vector <t_vector>` typed. They
6833 must also be identical types.
6834
6835 Semantics:
6836 """"""""""
6837
6838 The '``icmp``' compares ``op1`` and ``op2`` according to the condition
6839 code given as ``cond``. The comparison performed always yields either an
6840 :ref:`i1 <t_integer>` or vector of ``i1`` result, as follows:
6841
6842 #. ``eq``: yields ``true`` if the operands are equal, ``false``
6843    otherwise. No sign interpretation is necessary or performed.
6844 #. ``ne``: yields ``true`` if the operands are unequal, ``false``
6845    otherwise. No sign interpretation is necessary or performed.
6846 #. ``ugt``: interprets the operands as unsigned values and yields
6847    ``true`` if ``op1`` is greater than ``op2``.
6848 #. ``uge``: interprets the operands as unsigned values and yields
6849    ``true`` if ``op1`` is greater than or equal to ``op2``.
6850 #. ``ult``: interprets the operands as unsigned values and yields
6851    ``true`` if ``op1`` is less than ``op2``.
6852 #. ``ule``: interprets the operands as unsigned values and yields
6853    ``true`` if ``op1`` is less than or equal to ``op2``.
6854 #. ``sgt``: interprets the operands as signed values and yields ``true``
6855    if ``op1`` is greater than ``op2``.
6856 #. ``sge``: interprets the operands as signed values and yields ``true``
6857    if ``op1`` is greater than or equal to ``op2``.
6858 #. ``slt``: interprets the operands as signed values and yields ``true``
6859    if ``op1`` is less than ``op2``.
6860 #. ``sle``: interprets the operands as signed values and yields ``true``
6861    if ``op1`` is less than or equal to ``op2``.
6862
6863 If the operands are :ref:`pointer <t_pointer>` typed, the pointer values
6864 are compared as if they were integers.
6865
6866 If the operands are integer vectors, then they are compared element by
6867 element. The result is an ``i1`` vector with the same number of elements
6868 as the values being compared. Otherwise, the result is an ``i1``.
6869
6870 Example:
6871 """"""""
6872
6873 .. code-block:: llvm
6874
6875       <result> = icmp eq i32 4, 5          ; yields: result=false
6876       <result> = icmp ne float* %X, %X     ; yields: result=false
6877       <result> = icmp ult i16  4, 5        ; yields: result=true
6878       <result> = icmp sgt i16  4, 5        ; yields: result=false
6879       <result> = icmp ule i16 -4, 5        ; yields: result=false
6880       <result> = icmp sge i16  4, 5        ; yields: result=false
6881
6882 Note that the code generator does not yet support vector types with the
6883 ``icmp`` instruction.
6884
6885 .. _i_fcmp:
6886
6887 '``fcmp``' Instruction
6888 ^^^^^^^^^^^^^^^^^^^^^^
6889
6890 Syntax:
6891 """""""
6892
6893 ::
6894
6895       <result> = fcmp <cond> <ty> <op1>, <op2>     ; yields i1 or <N x i1>:result
6896
6897 Overview:
6898 """""""""
6899
6900 The '``fcmp``' instruction returns a boolean value or vector of boolean
6901 values based on comparison of its operands.
6902
6903 If the operands are floating point scalars, then the result type is a
6904 boolean (:ref:`i1 <t_integer>`).
6905
6906 If the operands are floating point vectors, then the result type is a
6907 vector of boolean with the same number of elements as the operands being
6908 compared.
6909
6910 Arguments:
6911 """"""""""
6912
6913 The '``fcmp``' instruction takes three operands. The first operand is
6914 the condition code indicating the kind of comparison to perform. It is
6915 not a value, just a keyword. The possible condition code are:
6916
6917 #. ``false``: no comparison, always returns false
6918 #. ``oeq``: ordered and equal
6919 #. ``ogt``: ordered and greater than
6920 #. ``oge``: ordered and greater than or equal
6921 #. ``olt``: ordered and less than
6922 #. ``ole``: ordered and less than or equal
6923 #. ``one``: ordered and not equal
6924 #. ``ord``: ordered (no nans)
6925 #. ``ueq``: unordered or equal
6926 #. ``ugt``: unordered or greater than
6927 #. ``uge``: unordered or greater than or equal
6928 #. ``ult``: unordered or less than
6929 #. ``ule``: unordered or less than or equal
6930 #. ``une``: unordered or not equal
6931 #. ``uno``: unordered (either nans)
6932 #. ``true``: no comparison, always returns true
6933
6934 *Ordered* means that neither operand is a QNAN while *unordered* means
6935 that either operand may be a QNAN.
6936
6937 Each of ``val1`` and ``val2`` arguments must be either a :ref:`floating
6938 point <t_floating>` type or a :ref:`vector <t_vector>` of floating point
6939 type. They must have identical types.
6940
6941 Semantics:
6942 """"""""""
6943
6944 The '``fcmp``' instruction compares ``op1`` and ``op2`` according to the
6945 condition code given as ``cond``. If the operands are vectors, then the
6946 vectors are compared element by element. Each comparison performed
6947 always yields an :ref:`i1 <t_integer>` result, as follows:
6948
6949 #. ``false``: always yields ``false``, regardless of operands.
6950 #. ``oeq``: yields ``true`` if both operands are not a QNAN and ``op1``
6951    is equal to ``op2``.
6952 #. ``ogt``: yields ``true`` if both operands are not a QNAN and ``op1``
6953    is greater than ``op2``.
6954 #. ``oge``: yields ``true`` if both operands are not a QNAN and ``op1``
6955    is greater than or equal to ``op2``.
6956 #. ``olt``: yields ``true`` if both operands are not a QNAN and ``op1``
6957    is less than ``op2``.
6958 #. ``ole``: yields ``true`` if both operands are not a QNAN and ``op1``
6959    is less than or equal to ``op2``.
6960 #. ``one``: yields ``true`` if both operands are not a QNAN and ``op1``
6961    is not equal to ``op2``.
6962 #. ``ord``: yields ``true`` if both operands are not a QNAN.
6963 #. ``ueq``: yields ``true`` if either operand is a QNAN or ``op1`` is
6964    equal to ``op2``.
6965 #. ``ugt``: yields ``true`` if either operand is a QNAN or ``op1`` is
6966    greater than ``op2``.
6967 #. ``uge``: yields ``true`` if either operand is a QNAN or ``op1`` is
6968    greater than or equal to ``op2``.
6969 #. ``ult``: yields ``true`` if either operand is a QNAN or ``op1`` is
6970    less than ``op2``.
6971 #. ``ule``: yields ``true`` if either operand is a QNAN or ``op1`` is
6972    less than or equal to ``op2``.
6973 #. ``une``: yields ``true`` if either operand is a QNAN or ``op1`` is
6974    not equal to ``op2``.
6975 #. ``uno``: yields ``true`` if either operand is a QNAN.
6976 #. ``true``: always yields ``true``, regardless of operands.
6977
6978 Example:
6979 """"""""
6980
6981 .. code-block:: llvm
6982
6983       <result> = fcmp oeq float 4.0, 5.0    ; yields: result=false
6984       <result> = fcmp one float 4.0, 5.0    ; yields: result=true
6985       <result> = fcmp olt float 4.0, 5.0    ; yields: result=true
6986       <result> = fcmp ueq double 1.0, 2.0   ; yields: result=false
6987
6988 Note that the code generator does not yet support vector types with the
6989 ``fcmp`` instruction.
6990
6991 .. _i_phi:
6992
6993 '``phi``' Instruction
6994 ^^^^^^^^^^^^^^^^^^^^^
6995
6996 Syntax:
6997 """""""
6998
6999 ::
7000
7001       <result> = phi <ty> [ <val0>, <label0>], ...
7002
7003 Overview:
7004 """""""""
7005
7006 The '``phi``' instruction is used to implement the Ï† node in the SSA
7007 graph representing the function.
7008
7009 Arguments:
7010 """"""""""
7011
7012 The type of the incoming values is specified with the first type field.
7013 After this, the '``phi``' instruction takes a list of pairs as
7014 arguments, with one pair for each predecessor basic block of the current
7015 block. Only values of :ref:`first class <t_firstclass>` type may be used as
7016 the value arguments to the PHI node. Only labels may be used as the
7017 label arguments.
7018
7019 There must be no non-phi instructions between the start of a basic block
7020 and the PHI instructions: i.e. PHI instructions must be first in a basic
7021 block.
7022
7023 For the purposes of the SSA form, the use of each incoming value is
7024 deemed to occur on the edge from the corresponding predecessor block to
7025 the current block (but after any definition of an '``invoke``'
7026 instruction's return value on the same edge).
7027
7028 Semantics:
7029 """"""""""
7030
7031 At runtime, the '``phi``' instruction logically takes on the value
7032 specified by the pair corresponding to the predecessor basic block that
7033 executed just prior to the current block.
7034
7035 Example:
7036 """"""""
7037
7038 .. code-block:: llvm
7039
7040     Loop:       ; Infinite loop that counts from 0 on up...
7041       %indvar = phi i32 [ 0, %LoopHeader ], [ %nextindvar, %Loop ]
7042       %nextindvar = add i32 %indvar, 1
7043       br label %Loop
7044
7045 .. _i_select:
7046
7047 '``select``' Instruction
7048 ^^^^^^^^^^^^^^^^^^^^^^^^
7049
7050 Syntax:
7051 """""""
7052
7053 ::
7054
7055       <result> = select selty <cond>, <ty> <val1>, <ty> <val2>             ; yields ty
7056
7057       selty is either i1 or {<N x i1>}
7058
7059 Overview:
7060 """""""""
7061
7062 The '``select``' instruction is used to choose one value based on a
7063 condition, without IR-level branching.
7064
7065 Arguments:
7066 """"""""""
7067
7068 The '``select``' instruction requires an 'i1' value or a vector of 'i1'
7069 values indicating the condition, and two values of the same :ref:`first
7070 class <t_firstclass>` type.
7071
7072 Semantics:
7073 """"""""""
7074
7075 If the condition is an i1 and it evaluates to 1, the instruction returns
7076 the first value argument; otherwise, it returns the second value
7077 argument.
7078
7079 If the condition is a vector of i1, then the value arguments must be
7080 vectors of the same size, and the selection is done element by element.
7081
7082 If the condition is an i1 and the value arguments are vectors of the
7083 same size, then an entire vector is selected.
7084
7085 Example:
7086 """"""""
7087
7088 .. code-block:: llvm
7089
7090       %X = select i1 true, i8 17, i8 42          ; yields i8:17
7091
7092 .. _i_call:
7093
7094 '``call``' Instruction
7095 ^^^^^^^^^^^^^^^^^^^^^^
7096
7097 Syntax:
7098 """""""
7099
7100 ::
7101
7102       <result> = [tail | musttail] call [cconv] [ret attrs] <ty> [<fnty>*] <fnptrval>(<function args>) [fn attrs]
7103
7104 Overview:
7105 """""""""
7106
7107 The '``call``' instruction represents a simple function call.
7108
7109 Arguments:
7110 """"""""""
7111
7112 This instruction requires several arguments:
7113
7114 #. The optional ``tail`` and ``musttail`` markers indicate that the optimizers
7115    should perform tail call optimization.  The ``tail`` marker is a hint that
7116    `can be ignored <CodeGenerator.html#sibcallopt>`_.  The ``musttail`` marker
7117    means that the call must be tail call optimized in order for the program to
7118    be correct.  The ``musttail`` marker provides these guarantees:
7119
7120    #. The call will not cause unbounded stack growth if it is part of a
7121       recursive cycle in the call graph.
7122    #. Arguments with the :ref:`inalloca <attr_inalloca>` attribute are
7123       forwarded in place.
7124
7125    Both markers imply that the callee does not access allocas or varargs from
7126    the caller.  Calls marked ``musttail`` must obey the following additional
7127    rules:
7128
7129    - The call must immediately precede a :ref:`ret <i_ret>` instruction,
7130      or a pointer bitcast followed by a ret instruction.
7131    - The ret instruction must return the (possibly bitcasted) value
7132      produced by the call or void.
7133    - The caller and callee prototypes must match.  Pointer types of
7134      parameters or return types may differ in pointee type, but not
7135      in address space.
7136    - The calling conventions of the caller and callee must match.
7137    - All ABI-impacting function attributes, such as sret, byval, inreg,
7138      returned, and inalloca, must match.
7139    - The callee must be varargs iff the caller is varargs. Bitcasting a
7140      non-varargs function to the appropriate varargs type is legal so
7141      long as the non-varargs prefixes obey the other rules.
7142
7143    Tail call optimization for calls marked ``tail`` is guaranteed to occur if
7144    the following conditions are met:
7145
7146    -  Caller and callee both have the calling convention ``fastcc``.
7147    -  The call is in tail position (ret immediately follows call and ret
7148       uses value of call or is void).
7149    -  Option ``-tailcallopt`` is enabled, or
7150       ``llvm::GuaranteedTailCallOpt`` is ``true``.
7151    -  `Platform-specific constraints are
7152       met. <CodeGenerator.html#tailcallopt>`_
7153
7154 #. The optional "cconv" marker indicates which :ref:`calling
7155    convention <callingconv>` the call should use. If none is
7156    specified, the call defaults to using C calling conventions. The
7157    calling convention of the call must match the calling convention of
7158    the target function, or else the behavior is undefined.
7159 #. The optional :ref:`Parameter Attributes <paramattrs>` list for return
7160    values. Only '``zeroext``', '``signext``', and '``inreg``' attributes
7161    are valid here.
7162 #. '``ty``': the type of the call instruction itself which is also the
7163    type of the return value. Functions that return no value are marked
7164    ``void``.
7165 #. '``fnty``': shall be the signature of the pointer to function value
7166    being invoked. The argument types must match the types implied by
7167    this signature. This type can be omitted if the function is not
7168    varargs and if the function type does not return a pointer to a
7169    function.
7170 #. '``fnptrval``': An LLVM value containing a pointer to a function to
7171    be invoked. In most cases, this is a direct function invocation, but
7172    indirect ``call``'s are just as possible, calling an arbitrary pointer
7173    to function value.
7174 #. '``function args``': argument list whose types match the function
7175    signature argument types and parameter attributes. All arguments must
7176    be of :ref:`first class <t_firstclass>` type. If the function signature
7177    indicates the function accepts a variable number of arguments, the
7178    extra arguments can be specified.
7179 #. The optional :ref:`function attributes <fnattrs>` list. Only
7180    '``noreturn``', '``nounwind``', '``readonly``' and '``readnone``'
7181    attributes are valid here.
7182
7183 Semantics:
7184 """"""""""
7185
7186 The '``call``' instruction is used to cause control flow to transfer to
7187 a specified function, with its incoming arguments bound to the specified
7188 values. Upon a '``ret``' instruction in the called function, control
7189 flow continues with the instruction after the function call, and the
7190 return value of the function is bound to the result argument.
7191
7192 Example:
7193 """"""""
7194
7195 .. code-block:: llvm
7196
7197       %retval = call i32 @test(i32 %argc)
7198       call i32 (i8*, ...)* @printf(i8* %msg, i32 12, i8 42)        ; yields i32
7199       %X = tail call i32 @foo()                                    ; yields i32
7200       %Y = tail call fastcc i32 @foo()  ; yields i32
7201       call void %foo(i8 97 signext)
7202
7203       %struct.A = type { i32, i8 }
7204       %r = call %struct.A @foo()                        ; yields { i32, i8 }
7205       %gr = extractvalue %struct.A %r, 0                ; yields i32
7206       %gr1 = extractvalue %struct.A %r, 1               ; yields i8
7207       %Z = call void @foo() noreturn                    ; indicates that %foo never returns normally
7208       %ZZ = call zeroext i32 @bar()                     ; Return value is %zero extended
7209
7210 llvm treats calls to some functions with names and arguments that match
7211 the standard C99 library as being the C99 library functions, and may
7212 perform optimizations or generate code for them under that assumption.
7213 This is something we'd like to change in the future to provide better
7214 support for freestanding environments and non-C-based languages.
7215
7216 .. _i_va_arg:
7217
7218 '``va_arg``' Instruction
7219 ^^^^^^^^^^^^^^^^^^^^^^^^
7220
7221 Syntax:
7222 """""""
7223
7224 ::
7225
7226       <resultval> = va_arg <va_list*> <arglist>, <argty>
7227
7228 Overview:
7229 """""""""
7230
7231 The '``va_arg``' instruction is used to access arguments passed through
7232 the "variable argument" area of a function call. It is used to implement
7233 the ``va_arg`` macro in C.
7234
7235 Arguments:
7236 """"""""""
7237
7238 This instruction takes a ``va_list*`` value and the type of the
7239 argument. It returns a value of the specified argument type and
7240 increments the ``va_list`` to point to the next argument. The actual
7241 type of ``va_list`` is target specific.
7242
7243 Semantics:
7244 """"""""""
7245
7246 The '``va_arg``' instruction loads an argument of the specified type
7247 from the specified ``va_list`` and causes the ``va_list`` to point to
7248 the next argument. For more information, see the variable argument
7249 handling :ref:`Intrinsic Functions <int_varargs>`.
7250
7251 It is legal for this instruction to be called in a function which does
7252 not take a variable number of arguments, for example, the ``vfprintf``
7253 function.
7254
7255 ``va_arg`` is an LLVM instruction instead of an :ref:`intrinsic
7256 function <intrinsics>` because it takes a type as an argument.
7257
7258 Example:
7259 """"""""
7260
7261 See the :ref:`variable argument processing <int_varargs>` section.
7262
7263 Note that the code generator does not yet fully support va\_arg on many
7264 targets. Also, it does not currently support va\_arg with aggregate
7265 types on any target.
7266
7267 .. _i_landingpad:
7268
7269 '``landingpad``' Instruction
7270 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7271
7272 Syntax:
7273 """""""
7274
7275 ::
7276
7277       <resultval> = landingpad <resultty> personality <type> <pers_fn> <clause>+
7278       <resultval> = landingpad <resultty> personality <type> <pers_fn> cleanup <clause>*
7279
7280       <clause> := catch <type> <value>
7281       <clause> := filter <array constant type> <array constant>
7282
7283 Overview:
7284 """""""""
7285
7286 The '``landingpad``' instruction is used by `LLVM's exception handling
7287 system <ExceptionHandling.html#overview>`_ to specify that a basic block
7288 is a landing pad --- one where the exception lands, and corresponds to the
7289 code found in the ``catch`` portion of a ``try``/``catch`` sequence. It
7290 defines values supplied by the personality function (``pers_fn``) upon
7291 re-entry to the function. The ``resultval`` has the type ``resultty``.
7292
7293 Arguments:
7294 """"""""""
7295
7296 This instruction takes a ``pers_fn`` value. This is the personality
7297 function associated with the unwinding mechanism. The optional
7298 ``cleanup`` flag indicates that the landing pad block is a cleanup.
7299
7300 A ``clause`` begins with the clause type --- ``catch`` or ``filter`` --- and
7301 contains the global variable representing the "type" that may be caught
7302 or filtered respectively. Unlike the ``catch`` clause, the ``filter``
7303 clause takes an array constant as its argument. Use
7304 "``[0 x i8**] undef``" for a filter which cannot throw. The
7305 '``landingpad``' instruction must contain *at least* one ``clause`` or
7306 the ``cleanup`` flag.
7307
7308 Semantics:
7309 """"""""""
7310
7311 The '``landingpad``' instruction defines the values which are set by the
7312 personality function (``pers_fn``) upon re-entry to the function, and
7313 therefore the "result type" of the ``landingpad`` instruction. As with
7314 calling conventions, how the personality function results are
7315 represented in LLVM IR is target specific.
7316
7317 The clauses are applied in order from top to bottom. If two
7318 ``landingpad`` instructions are merged together through inlining, the
7319 clauses from the calling function are appended to the list of clauses.
7320 When the call stack is being unwound due to an exception being thrown,
7321 the exception is compared against each ``clause`` in turn. If it doesn't
7322 match any of the clauses, and the ``cleanup`` flag is not set, then
7323 unwinding continues further up the call stack.
7324
7325 The ``landingpad`` instruction has several restrictions:
7326
7327 -  A landing pad block is a basic block which is the unwind destination
7328    of an '``invoke``' instruction.
7329 -  A landing pad block must have a '``landingpad``' instruction as its
7330    first non-PHI instruction.
7331 -  There can be only one '``landingpad``' instruction within the landing
7332    pad block.
7333 -  A basic block that is not a landing pad block may not include a
7334    '``landingpad``' instruction.
7335 -  All '``landingpad``' instructions in a function must have the same
7336    personality function.
7337
7338 Example:
7339 """"""""
7340
7341 .. code-block:: llvm
7342
7343       ;; A landing pad which can catch an integer.
7344       %res = landingpad { i8*, i32 } personality i32 (...)* @__gxx_personality_v0
7345                catch i8** @_ZTIi
7346       ;; A landing pad that is a cleanup.
7347       %res = landingpad { i8*, i32 } personality i32 (...)* @__gxx_personality_v0
7348                cleanup
7349       ;; A landing pad which can catch an integer and can only throw a double.
7350       %res = landingpad { i8*, i32 } personality i32 (...)* @__gxx_personality_v0
7351                catch i8** @_ZTIi
7352                filter [1 x i8**] [@_ZTId]
7353
7354 .. _intrinsics:
7355
7356 Intrinsic Functions
7357 ===================
7358
7359 LLVM supports the notion of an "intrinsic function". These functions
7360 have well known names and semantics and are required to follow certain
7361 restrictions. Overall, these intrinsics represent an extension mechanism
7362 for the LLVM language that does not require changing all of the
7363 transformations in LLVM when adding to the language (or the bitcode
7364 reader/writer, the parser, etc...).
7365
7366 Intrinsic function names must all start with an "``llvm.``" prefix. This
7367 prefix is reserved in LLVM for intrinsic names; thus, function names may
7368 not begin with this prefix. Intrinsic functions must always be external
7369 functions: you cannot define the body of intrinsic functions. Intrinsic
7370 functions may only be used in call or invoke instructions: it is illegal
7371 to take the address of an intrinsic function. Additionally, because
7372 intrinsic functions are part of the LLVM language, it is required if any
7373 are added that they be documented here.
7374
7375 Some intrinsic functions can be overloaded, i.e., the intrinsic
7376 represents a family of functions that perform the same operation but on
7377 different data types. Because LLVM can represent over 8 million
7378 different integer types, overloading is used commonly to allow an
7379 intrinsic function to operate on any integer type. One or more of the
7380 argument types or the result type can be overloaded to accept any
7381 integer type. Argument types may also be defined as exactly matching a
7382 previous argument's type or the result type. This allows an intrinsic
7383 function which accepts multiple arguments, but needs all of them to be
7384 of the same type, to only be overloaded with respect to a single
7385 argument or the result.
7386
7387 Overloaded intrinsics will have the names of its overloaded argument
7388 types encoded into its function name, each preceded by a period. Only
7389 those types which are overloaded result in a name suffix. Arguments
7390 whose type is matched against another type do not. For example, the
7391 ``llvm.ctpop`` function can take an integer of any width and returns an
7392 integer of exactly the same integer width. This leads to a family of
7393 functions such as ``i8 @llvm.ctpop.i8(i8 %val)`` and
7394 ``i29 @llvm.ctpop.i29(i29 %val)``. Only one type, the return type, is
7395 overloaded, and only one type suffix is required. Because the argument's
7396 type is matched against the return type, it does not require its own
7397 name suffix.
7398
7399 To learn how to add an intrinsic function, please see the `Extending
7400 LLVM Guide <ExtendingLLVM.html>`_.
7401
7402 .. _int_varargs:
7403
7404 Variable Argument Handling Intrinsics
7405 -------------------------------------
7406
7407 Variable argument support is defined in LLVM with the
7408 :ref:`va_arg <i_va_arg>` instruction and these three intrinsic
7409 functions. These functions are related to the similarly named macros
7410 defined in the ``<stdarg.h>`` header file.
7411
7412 All of these functions operate on arguments that use a target-specific
7413 value type "``va_list``". The LLVM assembly language reference manual
7414 does not define what this type is, so all transformations should be
7415 prepared to handle these functions regardless of the type used.
7416
7417 This example shows how the :ref:`va_arg <i_va_arg>` instruction and the
7418 variable argument handling intrinsic functions are used.
7419
7420 .. code-block:: llvm
7421
7422     ; This struct is different for every platform. For most platforms,
7423     ; it is merely an i8*.
7424     %struct.va_list = type { i8* }
7425
7426     ; For Unix x86_64 platforms, va_list is the following struct:
7427     ; %struct.va_list = type { i32, i32, i8*, i8* }
7428
7429     define i32 @test(i32 %X, ...) {
7430       ; Initialize variable argument processing
7431       %ap = alloca %struct.va_list
7432       %ap2 = bitcast %struct.va_list* %ap to i8*
7433       call void @llvm.va_start(i8* %ap2)
7434
7435       ; Read a single integer argument
7436       %tmp = va_arg i8* %ap2, i32
7437
7438       ; Demonstrate usage of llvm.va_copy and llvm.va_end
7439       %aq = alloca i8*
7440       %aq2 = bitcast i8** %aq to i8*
7441       call void @llvm.va_copy(i8* %aq2, i8* %ap2)
7442       call void @llvm.va_end(i8* %aq2)
7443
7444       ; Stop processing of arguments.
7445       call void @llvm.va_end(i8* %ap2)
7446       ret i32 %tmp
7447     }
7448
7449     declare void @llvm.va_start(i8*)
7450     declare void @llvm.va_copy(i8*, i8*)
7451     declare void @llvm.va_end(i8*)
7452
7453 .. _int_va_start:
7454
7455 '``llvm.va_start``' Intrinsic
7456 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7457
7458 Syntax:
7459 """""""
7460
7461 ::
7462
7463       declare void @llvm.va_start(i8* <arglist>)
7464
7465 Overview:
7466 """""""""
7467
7468 The '``llvm.va_start``' intrinsic initializes ``*<arglist>`` for
7469 subsequent use by ``va_arg``.
7470
7471 Arguments:
7472 """"""""""
7473
7474 The argument is a pointer to a ``va_list`` element to initialize.
7475
7476 Semantics:
7477 """"""""""
7478
7479 The '``llvm.va_start``' intrinsic works just like the ``va_start`` macro
7480 available in C. In a target-dependent way, it initializes the
7481 ``va_list`` element to which the argument points, so that the next call
7482 to ``va_arg`` will produce the first variable argument passed to the
7483 function. Unlike the C ``va_start`` macro, this intrinsic does not need
7484 to know the last argument of the function as the compiler can figure
7485 that out.
7486
7487 '``llvm.va_end``' Intrinsic
7488 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
7489
7490 Syntax:
7491 """""""
7492
7493 ::
7494
7495       declare void @llvm.va_end(i8* <arglist>)
7496
7497 Overview:
7498 """""""""
7499
7500 The '``llvm.va_end``' intrinsic destroys ``*<arglist>``, which has been
7501 initialized previously with ``llvm.va_start`` or ``llvm.va_copy``.
7502
7503 Arguments:
7504 """"""""""
7505
7506 The argument is a pointer to a ``va_list`` to destroy.
7507
7508 Semantics:
7509 """"""""""
7510
7511 The '``llvm.va_end``' intrinsic works just like the ``va_end`` macro
7512 available in C. In a target-dependent way, it destroys the ``va_list``
7513 element to which the argument points. Calls to
7514 :ref:`llvm.va_start <int_va_start>` and
7515 :ref:`llvm.va_copy <int_va_copy>` must be matched exactly with calls to
7516 ``llvm.va_end``.
7517
7518 .. _int_va_copy:
7519
7520 '``llvm.va_copy``' Intrinsic
7521 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7522
7523 Syntax:
7524 """""""
7525
7526 ::
7527
7528       declare void @llvm.va_copy(i8* <destarglist>, i8* <srcarglist>)
7529
7530 Overview:
7531 """""""""
7532
7533 The '``llvm.va_copy``' intrinsic copies the current argument position
7534 from the source argument list to the destination argument list.
7535
7536 Arguments:
7537 """"""""""
7538
7539 The first argument is a pointer to a ``va_list`` element to initialize.
7540 The second argument is a pointer to a ``va_list`` element to copy from.
7541
7542 Semantics:
7543 """"""""""
7544
7545 The '``llvm.va_copy``' intrinsic works just like the ``va_copy`` macro
7546 available in C. In a target-dependent way, it copies the source
7547 ``va_list`` element into the destination ``va_list`` element. This
7548 intrinsic is necessary because the `` llvm.va_start`` intrinsic may be
7549 arbitrarily complex and require, for example, memory allocation.
7550
7551 Accurate Garbage Collection Intrinsics
7552 --------------------------------------
7553
7554 LLVM's support for `Accurate Garbage Collection <GarbageCollection.html>`_
7555 (GC) requires the frontend to generate code containing appropriate intrinsic
7556 calls and select an appropriate GC strategy which knows how to lower these
7557 intrinsics in a manner which is appropriate for the target collector.
7558
7559 These intrinsics allow identification of :ref:`GC roots on the
7560 stack <int_gcroot>`, as well as garbage collector implementations that
7561 require :ref:`read <int_gcread>` and :ref:`write <int_gcwrite>` barriers.
7562 Frontends for type-safe garbage collected languages should generate
7563 these intrinsics to make use of the LLVM garbage collectors. For more
7564 details, see `Garbage Collection with LLVM <GarbageCollection.html>`_.
7565
7566 Experimental Statepoint Intrinsics
7567 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7568
7569 LLVM provides an second experimental set of intrinsics for describing garbage
7570 collection safepoints in compiled code.  These intrinsics are an alternative
7571 to the ``llvm.gcroot`` intrinsics, but are compatible with the ones for
7572 :ref:`read <int_gcread>` and :ref:`write <int_gcwrite>` barriers.  The
7573 differences in approach are covered in the `Garbage Collection with LLVM
7574 <GarbageCollection.html>`_ documentation.  The intrinsics themselves are
7575 described in :doc:`Statepoints`.
7576
7577 .. _int_gcroot:
7578
7579 '``llvm.gcroot``' Intrinsic
7580 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
7581
7582 Syntax:
7583 """""""
7584
7585 ::
7586
7587       declare void @llvm.gcroot(i8** %ptrloc, i8* %metadata)
7588
7589 Overview:
7590 """""""""
7591
7592 The '``llvm.gcroot``' intrinsic declares the existence of a GC root to
7593 the code generator, and allows some metadata to be associated with it.
7594
7595 Arguments:
7596 """"""""""
7597
7598 The first argument specifies the address of a stack object that contains
7599 the root pointer. The second pointer (which must be either a constant or
7600 a global value address) contains the meta-data to be associated with the
7601 root.
7602
7603 Semantics:
7604 """"""""""
7605
7606 At runtime, a call to this intrinsic stores a null pointer into the
7607 "ptrloc" location. At compile-time, the code generator generates
7608 information to allow the runtime to find the pointer at GC safe points.
7609 The '``llvm.gcroot``' intrinsic may only be used in a function which
7610 :ref:`specifies a GC algorithm <gc>`.
7611
7612 .. _int_gcread:
7613
7614 '``llvm.gcread``' Intrinsic
7615 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
7616
7617 Syntax:
7618 """""""
7619
7620 ::
7621
7622       declare i8* @llvm.gcread(i8* %ObjPtr, i8** %Ptr)
7623
7624 Overview:
7625 """""""""
7626
7627 The '``llvm.gcread``' intrinsic identifies reads of references from heap
7628 locations, allowing garbage collector implementations that require read
7629 barriers.
7630
7631 Arguments:
7632 """"""""""
7633
7634 The second argument is the address to read from, which should be an
7635 address allocated from the garbage collector. The first object is a
7636 pointer to the start of the referenced object, if needed by the language
7637 runtime (otherwise null).
7638
7639 Semantics:
7640 """"""""""
7641
7642 The '``llvm.gcread``' intrinsic has the same semantics as a load
7643 instruction, but may be replaced with substantially more complex code by
7644 the garbage collector runtime, as needed. The '``llvm.gcread``'
7645 intrinsic may only be used in a function which :ref:`specifies a GC
7646 algorithm <gc>`.
7647
7648 .. _int_gcwrite:
7649
7650 '``llvm.gcwrite``' Intrinsic
7651 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7652
7653 Syntax:
7654 """""""
7655
7656 ::
7657
7658       declare void @llvm.gcwrite(i8* %P1, i8* %Obj, i8** %P2)
7659
7660 Overview:
7661 """""""""
7662
7663 The '``llvm.gcwrite``' intrinsic identifies writes of references to heap
7664 locations, allowing garbage collector implementations that require write
7665 barriers (such as generational or reference counting collectors).
7666
7667 Arguments:
7668 """"""""""
7669
7670 The first argument is the reference to store, the second is the start of
7671 the object to store it to, and the third is the address of the field of
7672 Obj to store to. If the runtime does not require a pointer to the
7673 object, Obj may be null.
7674
7675 Semantics:
7676 """"""""""
7677
7678 The '``llvm.gcwrite``' intrinsic has the same semantics as a store
7679 instruction, but may be replaced with substantially more complex code by
7680 the garbage collector runtime, as needed. The '``llvm.gcwrite``'
7681 intrinsic may only be used in a function which :ref:`specifies a GC
7682 algorithm <gc>`.
7683
7684 Code Generator Intrinsics
7685 -------------------------
7686
7687 These intrinsics are provided by LLVM to expose special features that
7688 may only be implemented with code generator support.
7689
7690 '``llvm.returnaddress``' Intrinsic
7691 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7692
7693 Syntax:
7694 """""""
7695
7696 ::
7697
7698       declare i8  *@llvm.returnaddress(i32 <level>)
7699
7700 Overview:
7701 """""""""
7702
7703 The '``llvm.returnaddress``' intrinsic attempts to compute a
7704 target-specific value indicating the return address of the current
7705 function or one of its callers.
7706
7707 Arguments:
7708 """"""""""
7709
7710 The argument to this intrinsic indicates which function to return the
7711 address for. Zero indicates the calling function, one indicates its
7712 caller, etc. The argument is **required** to be a constant integer
7713 value.
7714
7715 Semantics:
7716 """"""""""
7717
7718 The '``llvm.returnaddress``' intrinsic either returns a pointer
7719 indicating the return address of the specified call frame, or zero if it
7720 cannot be identified. The value returned by this intrinsic is likely to
7721 be incorrect or 0 for arguments other than zero, so it should only be
7722 used for debugging purposes.
7723
7724 Note that calling this intrinsic does not prevent function inlining or
7725 other aggressive transformations, so the value returned may not be that
7726 of the obvious source-language caller.
7727
7728 '``llvm.frameaddress``' Intrinsic
7729 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7730
7731 Syntax:
7732 """""""
7733
7734 ::
7735
7736       declare i8* @llvm.frameaddress(i32 <level>)
7737
7738 Overview:
7739 """""""""
7740
7741 The '``llvm.frameaddress``' intrinsic attempts to return the
7742 target-specific frame pointer value for the specified stack frame.
7743
7744 Arguments:
7745 """"""""""
7746
7747 The argument to this intrinsic indicates which function to return the
7748 frame pointer for. Zero indicates the calling function, one indicates
7749 its caller, etc. The argument is **required** to be a constant integer
7750 value.
7751
7752 Semantics:
7753 """"""""""
7754
7755 The '``llvm.frameaddress``' intrinsic either returns a pointer
7756 indicating the frame address of the specified call frame, or zero if it
7757 cannot be identified. The value returned by this intrinsic is likely to
7758 be incorrect or 0 for arguments other than zero, so it should only be
7759 used for debugging purposes.
7760
7761 Note that calling this intrinsic does not prevent function inlining or
7762 other aggressive transformations, so the value returned may not be that
7763 of the obvious source-language caller.
7764
7765 '``llvm.frameescape``' and '``llvm.framerecover``' Intrinsics
7766 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7767
7768 Syntax:
7769 """""""
7770
7771 ::
7772
7773       declare void @llvm.frameescape(...)
7774       declare i8* @llvm.framerecover(i8* %func, i8* %fp, i32 %idx)
7775
7776 Overview:
7777 """""""""
7778
7779 The '``llvm.frameescape``' intrinsic escapes offsets of a collection of static
7780 allocas, and the '``llvm.framerecover``' intrinsic applies those offsets to a
7781 live frame pointer to recover the address of the allocation. The offset is
7782 computed during frame layout of the caller of ``llvm.frameescape``.
7783
7784 Arguments:
7785 """"""""""
7786
7787 All arguments to '``llvm.frameescape``' must be pointers to static allocas or
7788 casts of static allocas. Each function can only call '``llvm.frameescape``'
7789 once, and it can only do so from the entry block.
7790
7791 The ``func`` argument to '``llvm.framerecover``' must be a constant
7792 bitcasted pointer to a function defined in the current module. The code
7793 generator cannot determine the frame allocation offset of functions defined in
7794 other modules.
7795
7796 The ``fp`` argument to '``llvm.framerecover``' must be a frame
7797 pointer of a call frame that is currently live. The return value of
7798 '``llvm.frameaddress``' is one way to produce such a value, but most platforms
7799 also expose the frame pointer through stack unwinding mechanisms.
7800
7801 The ``idx`` argument to '``llvm.framerecover``' indicates which alloca passed to
7802 '``llvm.frameescape``' to recover. It is zero-indexed.
7803
7804 Semantics:
7805 """"""""""
7806
7807 These intrinsics allow a group of functions to access one stack memory
7808 allocation in an ancestor stack frame. The memory returned from
7809 '``llvm.frameallocate``' may be allocated prior to stack realignment, so the
7810 memory is only aligned to the ABI-required stack alignment.  Each function may
7811 only call '``llvm.frameallocate``' one or zero times from the function entry
7812 block.  The frame allocation intrinsic inhibits inlining, as any frame
7813 allocations in the inlined function frame are likely to be at a different
7814 offset from the one used by '``llvm.framerecover``' called with the
7815 uninlined function.
7816
7817 .. _int_read_register:
7818 .. _int_write_register:
7819
7820 '``llvm.read_register``' and '``llvm.write_register``' Intrinsics
7821 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7822
7823 Syntax:
7824 """""""
7825
7826 ::
7827
7828       declare i32 @llvm.read_register.i32(metadata)
7829       declare i64 @llvm.read_register.i64(metadata)
7830       declare void @llvm.write_register.i32(metadata, i32 @value)
7831       declare void @llvm.write_register.i64(metadata, i64 @value)
7832       !0 = !{!"sp\00"}
7833
7834 Overview:
7835 """""""""
7836
7837 The '``llvm.read_register``' and '``llvm.write_register``' intrinsics
7838 provides access to the named register. The register must be valid on
7839 the architecture being compiled to. The type needs to be compatible
7840 with the register being read.
7841
7842 Semantics:
7843 """"""""""
7844
7845 The '``llvm.read_register``' intrinsic returns the current value of the
7846 register, where possible. The '``llvm.write_register``' intrinsic sets
7847 the current value of the register, where possible.
7848
7849 This is useful to implement named register global variables that need
7850 to always be mapped to a specific register, as is common practice on
7851 bare-metal programs including OS kernels.
7852
7853 The compiler doesn't check for register availability or use of the used
7854 register in surrounding code, including inline assembly. Because of that,
7855 allocatable registers are not supported.
7856
7857 Warning: So far it only works with the stack pointer on selected
7858 architectures (ARM, AArch64, PowerPC and x86_64). Significant amount of
7859 work is needed to support other registers and even more so, allocatable
7860 registers.
7861
7862 .. _int_stacksave:
7863
7864 '``llvm.stacksave``' Intrinsic
7865 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7866
7867 Syntax:
7868 """""""
7869
7870 ::
7871
7872       declare i8* @llvm.stacksave()
7873
7874 Overview:
7875 """""""""
7876
7877 The '``llvm.stacksave``' intrinsic is used to remember the current state
7878 of the function stack, for use with
7879 :ref:`llvm.stackrestore <int_stackrestore>`. This is useful for
7880 implementing language features like scoped automatic variable sized
7881 arrays in C99.
7882
7883 Semantics:
7884 """"""""""
7885
7886 This intrinsic returns a opaque pointer value that can be passed to
7887 :ref:`llvm.stackrestore <int_stackrestore>`. When an
7888 ``llvm.stackrestore`` intrinsic is executed with a value saved from
7889 ``llvm.stacksave``, it effectively restores the state of the stack to
7890 the state it was in when the ``llvm.stacksave`` intrinsic executed. In
7891 practice, this pops any :ref:`alloca <i_alloca>` blocks from the stack that
7892 were allocated after the ``llvm.stacksave`` was executed.
7893
7894 .. _int_stackrestore:
7895
7896 '``llvm.stackrestore``' Intrinsic
7897 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7898
7899 Syntax:
7900 """""""
7901
7902 ::
7903
7904       declare void @llvm.stackrestore(i8* %ptr)
7905
7906 Overview:
7907 """""""""
7908
7909 The '``llvm.stackrestore``' intrinsic is used to restore the state of
7910 the function stack to the state it was in when the corresponding
7911 :ref:`llvm.stacksave <int_stacksave>` intrinsic executed. This is
7912 useful for implementing language features like scoped automatic variable
7913 sized arrays in C99.
7914
7915 Semantics:
7916 """"""""""
7917
7918 See the description for :ref:`llvm.stacksave <int_stacksave>`.
7919
7920 '``llvm.prefetch``' Intrinsic
7921 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7922
7923 Syntax:
7924 """""""
7925
7926 ::
7927
7928       declare void @llvm.prefetch(i8* <address>, i32 <rw>, i32 <locality>, i32 <cache type>)
7929
7930 Overview:
7931 """""""""
7932
7933 The '``llvm.prefetch``' intrinsic is a hint to the code generator to
7934 insert a prefetch instruction if supported; otherwise, it is a noop.
7935 Prefetches have no effect on the behavior of the program but can change
7936 its performance characteristics.
7937
7938 Arguments:
7939 """"""""""
7940
7941 ``address`` is the address to be prefetched, ``rw`` is the specifier
7942 determining if the fetch should be for a read (0) or write (1), and
7943 ``locality`` is a temporal locality specifier ranging from (0) - no
7944 locality, to (3) - extremely local keep in cache. The ``cache type``
7945 specifies whether the prefetch is performed on the data (1) or
7946 instruction (0) cache. The ``rw``, ``locality`` and ``cache type``
7947 arguments must be constant integers.
7948
7949 Semantics:
7950 """"""""""
7951
7952 This intrinsic does not modify the behavior of the program. In
7953 particular, prefetches cannot trap and do not produce a value. On
7954 targets that support this intrinsic, the prefetch can provide hints to
7955 the processor cache for better performance.
7956
7957 '``llvm.pcmarker``' Intrinsic
7958 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7959
7960 Syntax:
7961 """""""
7962
7963 ::
7964
7965       declare void @llvm.pcmarker(i32 <id>)
7966
7967 Overview:
7968 """""""""
7969
7970 The '``llvm.pcmarker``' intrinsic is a method to export a Program
7971 Counter (PC) in a region of code to simulators and other tools. The
7972 method is target specific, but it is expected that the marker will use
7973 exported symbols to transmit the PC of the marker. The marker makes no
7974 guarantees that it will remain with any specific instruction after
7975 optimizations. It is possible that the presence of a marker will inhibit
7976 optimizations. The intended use is to be inserted after optimizations to
7977 allow correlations of simulation runs.
7978
7979 Arguments:
7980 """"""""""
7981
7982 ``id`` is a numerical id identifying the marker.
7983
7984 Semantics:
7985 """"""""""
7986
7987 This intrinsic does not modify the behavior of the program. Backends
7988 that do not support this intrinsic may ignore it.
7989
7990 '``llvm.readcyclecounter``' Intrinsic
7991 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7992
7993 Syntax:
7994 """""""
7995
7996 ::
7997
7998       declare i64 @llvm.readcyclecounter()
7999
8000 Overview:
8001 """""""""
8002
8003 The '``llvm.readcyclecounter``' intrinsic provides access to the cycle
8004 counter register (or similar low latency, high accuracy clocks) on those
8005 targets that support it. On X86, it should map to RDTSC. On Alpha, it
8006 should map to RPCC. As the backing counters overflow quickly (on the
8007 order of 9 seconds on alpha), this should only be used for small
8008 timings.
8009
8010 Semantics:
8011 """"""""""
8012
8013 When directly supported, reading the cycle counter should not modify any
8014 memory. Implementations are allowed to either return a application
8015 specific value or a system wide value. On backends without support, this
8016 is lowered to a constant 0.
8017
8018 Note that runtime support may be conditional on the privilege-level code is
8019 running at and the host platform.
8020
8021 '``llvm.clear_cache``' Intrinsic
8022 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8023
8024 Syntax:
8025 """""""
8026
8027 ::
8028
8029       declare void @llvm.clear_cache(i8*, i8*)
8030
8031 Overview:
8032 """""""""
8033
8034 The '``llvm.clear_cache``' intrinsic ensures visibility of modifications
8035 in the specified range to the execution unit of the processor. On
8036 targets with non-unified instruction and data cache, the implementation
8037 flushes the instruction cache.
8038
8039 Semantics:
8040 """"""""""
8041
8042 On platforms with coherent instruction and data caches (e.g. x86), this
8043 intrinsic is a nop. On platforms with non-coherent instruction and data
8044 cache (e.g. ARM, MIPS), the intrinsic is lowered either to appropriate
8045 instructions or a system call, if cache flushing requires special
8046 privileges.
8047
8048 The default behavior is to emit a call to ``__clear_cache`` from the run
8049 time library.
8050
8051 This instrinsic does *not* empty the instruction pipeline. Modifications
8052 of the current function are outside the scope of the intrinsic.
8053
8054 '``llvm.instrprof_increment``' Intrinsic
8055 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8056
8057 Syntax:
8058 """""""
8059
8060 ::
8061
8062       declare void @llvm.instrprof_increment(i8* <name>, i64 <hash>,
8063                                              i32 <num-counters>, i32 <index>)
8064
8065 Overview:
8066 """""""""
8067
8068 The '``llvm.instrprof_increment``' intrinsic can be emitted by a
8069 frontend for use with instrumentation based profiling. These will be
8070 lowered by the ``-instrprof`` pass to generate execution counts of a
8071 program at runtime.
8072
8073 Arguments:
8074 """"""""""
8075
8076 The first argument is a pointer to a global variable containing the
8077 name of the entity being instrumented. This should generally be the
8078 (mangled) function name for a set of counters.
8079
8080 The second argument is a hash value that can be used by the consumer
8081 of the profile data to detect changes to the instrumented source, and
8082 the third is the number of counters associated with ``name``. It is an
8083 error if ``hash`` or ``num-counters`` differ between two instances of
8084 ``instrprof_increment`` that refer to the same name.
8085
8086 The last argument refers to which of the counters for ``name`` should
8087 be incremented. It should be a value between 0 and ``num-counters``.
8088
8089 Semantics:
8090 """"""""""
8091
8092 This intrinsic represents an increment of a profiling counter. It will
8093 cause the ``-instrprof`` pass to generate the appropriate data
8094 structures and the code to increment the appropriate value, in a
8095 format that can be written out by a compiler runtime and consumed via
8096 the ``llvm-profdata`` tool.
8097
8098 Standard C Library Intrinsics
8099 -----------------------------
8100
8101 LLVM provides intrinsics for a few important standard C library
8102 functions. These intrinsics allow source-language front-ends to pass
8103 information about the alignment of the pointer arguments to the code
8104 generator, providing opportunity for more efficient code generation.
8105
8106 .. _int_memcpy:
8107
8108 '``llvm.memcpy``' Intrinsic
8109 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
8110
8111 Syntax:
8112 """""""
8113
8114 This is an overloaded intrinsic. You can use ``llvm.memcpy`` on any
8115 integer bit width and for different address spaces. Not all targets
8116 support all bit widths however.
8117
8118 ::
8119
8120       declare void @llvm.memcpy.p0i8.p0i8.i32(i8* <dest>, i8* <src>,
8121                                               i32 <len>, i32 <align>, i1 <isvolatile>)
8122       declare void @llvm.memcpy.p0i8.p0i8.i64(i8* <dest>, i8* <src>,
8123                                               i64 <len>, i32 <align>, i1 <isvolatile>)
8124
8125 Overview:
8126 """""""""
8127
8128 The '``llvm.memcpy.*``' intrinsics copy a block of memory from the
8129 source location to the destination location.
8130
8131 Note that, unlike the standard libc function, the ``llvm.memcpy.*``
8132 intrinsics do not return a value, takes extra alignment/isvolatile
8133 arguments and the pointers can be in specified address spaces.
8134
8135 Arguments:
8136 """"""""""
8137
8138 The first argument is a pointer to the destination, the second is a
8139 pointer to the source. The third argument is an integer argument
8140 specifying the number of bytes to copy, the fourth argument is the
8141 alignment of the source and destination locations, and the fifth is a
8142 boolean indicating a volatile access.
8143
8144 If the call to this intrinsic has an alignment value that is not 0 or 1,
8145 then the caller guarantees that both the source and destination pointers
8146 are aligned to that boundary.
8147
8148 If the ``isvolatile`` parameter is ``true``, the ``llvm.memcpy`` call is
8149 a :ref:`volatile operation <volatile>`. The detailed access behavior is not
8150 very cleanly specified and it is unwise to depend on it.
8151
8152 Semantics:
8153 """"""""""
8154
8155 The '``llvm.memcpy.*``' intrinsics copy a block of memory from the
8156 source location to the destination location, which are not allowed to
8157 overlap. It copies "len" bytes of memory over. If the argument is known
8158 to be aligned to some boundary, this can be specified as the fourth
8159 argument, otherwise it should be set to 0 or 1 (both meaning no alignment).
8160
8161 '``llvm.memmove``' Intrinsic
8162 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8163
8164 Syntax:
8165 """""""
8166
8167 This is an overloaded intrinsic. You can use llvm.memmove on any integer
8168 bit width and for different address space. Not all targets support all
8169 bit widths however.
8170
8171 ::
8172
8173       declare void @llvm.memmove.p0i8.p0i8.i32(i8* <dest>, i8* <src>,
8174                                                i32 <len>, i32 <align>, i1 <isvolatile>)
8175       declare void @llvm.memmove.p0i8.p0i8.i64(i8* <dest>, i8* <src>,
8176                                                i64 <len>, i32 <align>, i1 <isvolatile>)
8177
8178 Overview:
8179 """""""""
8180
8181 The '``llvm.memmove.*``' intrinsics move a block of memory from the
8182 source location to the destination location. It is similar to the
8183 '``llvm.memcpy``' intrinsic but allows the two memory locations to
8184 overlap.
8185
8186 Note that, unlike the standard libc function, the ``llvm.memmove.*``
8187 intrinsics do not return a value, takes extra alignment/isvolatile
8188 arguments and the pointers can be in specified address spaces.
8189
8190 Arguments:
8191 """"""""""
8192
8193 The first argument is a pointer to the destination, the second is a
8194 pointer to the source. The third argument is an integer argument
8195 specifying the number of bytes to copy, the fourth argument is the
8196 alignment of the source and destination locations, and the fifth is a
8197 boolean indicating a volatile access.
8198
8199 If the call to this intrinsic has an alignment value that is not 0 or 1,
8200 then the caller guarantees that the source and destination pointers are
8201 aligned to that boundary.
8202
8203 If the ``isvolatile`` parameter is ``true``, the ``llvm.memmove`` call
8204 is a :ref:`volatile operation <volatile>`. The detailed access behavior is
8205 not very cleanly specified and it is unwise to depend on it.
8206
8207 Semantics:
8208 """"""""""
8209
8210 The '``llvm.memmove.*``' intrinsics copy a block of memory from the
8211 source location to the destination location, which may overlap. It
8212 copies "len" bytes of memory over. If the argument is known to be
8213 aligned to some boundary, this can be specified as the fourth argument,
8214 otherwise it should be set to 0 or 1 (both meaning no alignment).
8215
8216 '``llvm.memset.*``' Intrinsics
8217 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8218
8219 Syntax:
8220 """""""
8221
8222 This is an overloaded intrinsic. You can use llvm.memset on any integer
8223 bit width and for different address spaces. However, not all targets
8224 support all bit widths.
8225
8226 ::
8227
8228       declare void @llvm.memset.p0i8.i32(i8* <dest>, i8 <val>,
8229                                          i32 <len>, i32 <align>, i1 <isvolatile>)
8230       declare void @llvm.memset.p0i8.i64(i8* <dest>, i8 <val>,
8231                                          i64 <len>, i32 <align>, i1 <isvolatile>)
8232
8233 Overview:
8234 """""""""
8235
8236 The '``llvm.memset.*``' intrinsics fill a block of memory with a
8237 particular byte value.
8238
8239 Note that, unlike the standard libc function, the ``llvm.memset``
8240 intrinsic does not return a value and takes extra alignment/volatile
8241 arguments. Also, the destination can be in an arbitrary address space.
8242
8243 Arguments:
8244 """"""""""
8245
8246 The first argument is a pointer to the destination to fill, the second
8247 is the byte value with which to fill it, the third argument is an
8248 integer argument specifying the number of bytes to fill, and the fourth
8249 argument is the known alignment of the destination location.
8250
8251 If the call to this intrinsic has an alignment value that is not 0 or 1,
8252 then the caller guarantees that the destination pointer is aligned to
8253 that boundary.
8254
8255 If the ``isvolatile`` parameter is ``true``, the ``llvm.memset`` call is
8256 a :ref:`volatile operation <volatile>`. The detailed access behavior is not
8257 very cleanly specified and it is unwise to depend on it.
8258
8259 Semantics:
8260 """"""""""
8261
8262 The '``llvm.memset.*``' intrinsics fill "len" bytes of memory starting
8263 at the destination location. If the argument is known to be aligned to
8264 some boundary, this can be specified as the fourth argument, otherwise
8265 it should be set to 0 or 1 (both meaning no alignment).
8266
8267 '``llvm.sqrt.*``' Intrinsic
8268 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
8269
8270 Syntax:
8271 """""""
8272
8273 This is an overloaded intrinsic. You can use ``llvm.sqrt`` on any
8274 floating point or vector of floating point type. Not all targets support
8275 all types however.
8276
8277 ::
8278
8279       declare float     @llvm.sqrt.f32(float %Val)
8280       declare double    @llvm.sqrt.f64(double %Val)
8281       declare x86_fp80  @llvm.sqrt.f80(x86_fp80 %Val)
8282       declare fp128     @llvm.sqrt.f128(fp128 %Val)
8283       declare ppc_fp128 @llvm.sqrt.ppcf128(ppc_fp128 %Val)
8284
8285 Overview:
8286 """""""""
8287
8288 The '``llvm.sqrt``' intrinsics return the sqrt of the specified operand,
8289 returning the same value as the libm '``sqrt``' functions would. Unlike
8290 ``sqrt`` in libm, however, ``llvm.sqrt`` has undefined behavior for
8291 negative numbers other than -0.0 (which allows for better optimization,
8292 because there is no need to worry about errno being set).
8293 ``llvm.sqrt(-0.0)`` is defined to return -0.0 like IEEE sqrt.
8294
8295 Arguments:
8296 """"""""""
8297
8298 The argument and return value are floating point numbers of the same
8299 type.
8300
8301 Semantics:
8302 """"""""""
8303
8304 This function returns the sqrt of the specified operand if it is a
8305 nonnegative floating point number.
8306
8307 '``llvm.powi.*``' Intrinsic
8308 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
8309
8310 Syntax:
8311 """""""
8312
8313 This is an overloaded intrinsic. You can use ``llvm.powi`` on any
8314 floating point or vector of floating point type. Not all targets support
8315 all types however.
8316
8317 ::
8318
8319       declare float     @llvm.powi.f32(float  %Val, i32 %power)
8320       declare double    @llvm.powi.f64(double %Val, i32 %power)
8321       declare x86_fp80  @llvm.powi.f80(x86_fp80  %Val, i32 %power)
8322       declare fp128     @llvm.powi.f128(fp128 %Val, i32 %power)
8323       declare ppc_fp128 @llvm.powi.ppcf128(ppc_fp128  %Val, i32 %power)
8324
8325 Overview:
8326 """""""""
8327
8328 The '``llvm.powi.*``' intrinsics return the first operand raised to the
8329 specified (positive or negative) power. The order of evaluation of
8330 multiplications is not defined. When a vector of floating point type is
8331 used, the second argument remains a scalar integer value.
8332
8333 Arguments:
8334 """"""""""
8335
8336 The second argument is an integer power, and the first is a value to
8337 raise to that power.
8338
8339 Semantics:
8340 """"""""""
8341
8342 This function returns the first value raised to the second power with an
8343 unspecified sequence of rounding operations.
8344
8345 '``llvm.sin.*``' Intrinsic
8346 ^^^^^^^^^^^^^^^^^^^^^^^^^^
8347
8348 Syntax:
8349 """""""
8350
8351 This is an overloaded intrinsic. You can use ``llvm.sin`` on any
8352 floating point or vector of floating point type. Not all targets support
8353 all types however.
8354
8355 ::
8356
8357       declare float     @llvm.sin.f32(float  %Val)
8358       declare double    @llvm.sin.f64(double %Val)
8359       declare x86_fp80  @llvm.sin.f80(x86_fp80  %Val)
8360       declare fp128     @llvm.sin.f128(fp128 %Val)
8361       declare ppc_fp128 @llvm.sin.ppcf128(ppc_fp128  %Val)
8362
8363 Overview:
8364 """""""""
8365
8366 The '``llvm.sin.*``' intrinsics return the sine of the operand.
8367
8368 Arguments:
8369 """"""""""
8370
8371 The argument and return value are floating point numbers of the same
8372 type.
8373
8374 Semantics:
8375 """"""""""
8376
8377 This function returns the sine of the specified operand, returning the
8378 same values as the libm ``sin`` functions would, and handles error
8379 conditions in the same way.
8380
8381 '``llvm.cos.*``' Intrinsic
8382 ^^^^^^^^^^^^^^^^^^^^^^^^^^
8383
8384 Syntax:
8385 """""""
8386
8387 This is an overloaded intrinsic. You can use ``llvm.cos`` on any
8388 floating point or vector of floating point type. Not all targets support
8389 all types however.
8390
8391 ::
8392
8393       declare float     @llvm.cos.f32(float  %Val)
8394       declare double    @llvm.cos.f64(double %Val)
8395       declare x86_fp80  @llvm.cos.f80(x86_fp80  %Val)
8396       declare fp128     @llvm.cos.f128(fp128 %Val)
8397       declare ppc_fp128 @llvm.cos.ppcf128(ppc_fp128  %Val)
8398
8399 Overview:
8400 """""""""
8401
8402 The '``llvm.cos.*``' intrinsics return the cosine of the operand.
8403
8404 Arguments:
8405 """"""""""
8406
8407 The argument and return value are floating point numbers of the same
8408 type.
8409
8410 Semantics:
8411 """"""""""
8412
8413 This function returns the cosine of the specified operand, returning the
8414 same values as the libm ``cos`` functions would, and handles error
8415 conditions in the same way.
8416
8417 '``llvm.pow.*``' Intrinsic
8418 ^^^^^^^^^^^^^^^^^^^^^^^^^^
8419
8420 Syntax:
8421 """""""
8422
8423 This is an overloaded intrinsic. You can use ``llvm.pow`` on any
8424 floating point or vector of floating point type. Not all targets support
8425 all types however.
8426
8427 ::
8428
8429       declare float     @llvm.pow.f32(float  %Val, float %Power)
8430       declare double    @llvm.pow.f64(double %Val, double %Power)
8431       declare x86_fp80  @llvm.pow.f80(x86_fp80  %Val, x86_fp80 %Power)
8432       declare fp128     @llvm.pow.f128(fp128 %Val, fp128 %Power)
8433       declare ppc_fp128 @llvm.pow.ppcf128(ppc_fp128  %Val, ppc_fp128 Power)
8434
8435 Overview:
8436 """""""""
8437
8438 The '``llvm.pow.*``' intrinsics return the first operand raised to the
8439 specified (positive or negative) power.
8440
8441 Arguments:
8442 """"""""""
8443
8444 The second argument is a floating point power, and the first is a value
8445 to raise to that power.
8446
8447 Semantics:
8448 """"""""""
8449
8450 This function returns the first value raised to the second power,
8451 returning the same values as the libm ``pow`` functions would, and
8452 handles error conditions in the same way.
8453
8454 '``llvm.exp.*``' Intrinsic
8455 ^^^^^^^^^^^^^^^^^^^^^^^^^^
8456
8457 Syntax:
8458 """""""
8459
8460 This is an overloaded intrinsic. You can use ``llvm.exp`` on any
8461 floating point or vector of floating point type. Not all targets support
8462 all types however.
8463
8464 ::
8465
8466       declare float     @llvm.exp.f32(float  %Val)
8467       declare double    @llvm.exp.f64(double %Val)
8468       declare x86_fp80  @llvm.exp.f80(x86_fp80  %Val)
8469       declare fp128     @llvm.exp.f128(fp128 %Val)
8470       declare ppc_fp128 @llvm.exp.ppcf128(ppc_fp128  %Val)
8471
8472 Overview:
8473 """""""""
8474
8475 The '``llvm.exp.*``' intrinsics perform the exp function.
8476
8477 Arguments:
8478 """"""""""
8479
8480 The argument and return value are floating point numbers of the same
8481 type.
8482
8483 Semantics:
8484 """"""""""
8485
8486 This function returns the same values as the libm ``exp`` functions
8487 would, and handles error conditions in the same way.
8488
8489 '``llvm.exp2.*``' Intrinsic
8490 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
8491
8492 Syntax:
8493 """""""
8494
8495 This is an overloaded intrinsic. You can use ``llvm.exp2`` on any
8496 floating point or vector of floating point type. Not all targets support
8497 all types however.
8498
8499 ::
8500
8501       declare float     @llvm.exp2.f32(float  %Val)
8502       declare double    @llvm.exp2.f64(double %Val)
8503       declare x86_fp80  @llvm.exp2.f80(x86_fp80  %Val)
8504       declare fp128     @llvm.exp2.f128(fp128 %Val)
8505       declare ppc_fp128 @llvm.exp2.ppcf128(ppc_fp128  %Val)
8506
8507 Overview:
8508 """""""""
8509
8510 The '``llvm.exp2.*``' intrinsics perform the exp2 function.
8511
8512 Arguments:
8513 """"""""""
8514
8515 The argument and return value are floating point numbers of the same
8516 type.
8517
8518 Semantics:
8519 """"""""""
8520
8521 This function returns the same values as the libm ``exp2`` functions
8522 would, and handles error conditions in the same way.
8523
8524 '``llvm.log.*``' Intrinsic
8525 ^^^^^^^^^^^^^^^^^^^^^^^^^^
8526
8527 Syntax:
8528 """""""
8529
8530 This is an overloaded intrinsic. You can use ``llvm.log`` on any
8531 floating point or vector of floating point type. Not all targets support
8532 all types however.
8533
8534 ::
8535
8536       declare float     @llvm.log.f32(float  %Val)
8537       declare double    @llvm.log.f64(double %Val)
8538       declare x86_fp80  @llvm.log.f80(x86_fp80  %Val)
8539       declare fp128     @llvm.log.f128(fp128 %Val)
8540       declare ppc_fp128 @llvm.log.ppcf128(ppc_fp128  %Val)
8541
8542 Overview:
8543 """""""""
8544
8545 The '``llvm.log.*``' intrinsics perform the log function.
8546
8547 Arguments:
8548 """"""""""
8549
8550 The argument and return value are floating point numbers of the same
8551 type.
8552
8553 Semantics:
8554 """"""""""
8555
8556 This function returns the same values as the libm ``log`` functions
8557 would, and handles error conditions in the same way.
8558
8559 '``llvm.log10.*``' Intrinsic
8560 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8561
8562 Syntax:
8563 """""""
8564
8565 This is an overloaded intrinsic. You can use ``llvm.log10`` on any
8566 floating point or vector of floating point type. Not all targets support
8567 all types however.
8568
8569 ::
8570
8571       declare float     @llvm.log10.f32(float  %Val)
8572       declare double    @llvm.log10.f64(double %Val)
8573       declare x86_fp80  @llvm.log10.f80(x86_fp80  %Val)
8574       declare fp128     @llvm.log10.f128(fp128 %Val)
8575       declare ppc_fp128 @llvm.log10.ppcf128(ppc_fp128  %Val)
8576
8577 Overview:
8578 """""""""
8579
8580 The '``llvm.log10.*``' intrinsics perform the log10 function.
8581
8582 Arguments:
8583 """"""""""
8584
8585 The argument and return value are floating point numbers of the same
8586 type.
8587
8588 Semantics:
8589 """"""""""
8590
8591 This function returns the same values as the libm ``log10`` functions
8592 would, and handles error conditions in the same way.
8593
8594 '``llvm.log2.*``' Intrinsic
8595 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
8596
8597 Syntax:
8598 """""""
8599
8600 This is an overloaded intrinsic. You can use ``llvm.log2`` on any
8601 floating point or vector of floating point type. Not all targets support
8602 all types however.
8603
8604 ::
8605
8606       declare float     @llvm.log2.f32(float  %Val)
8607       declare double    @llvm.log2.f64(double %Val)
8608       declare x86_fp80  @llvm.log2.f80(x86_fp80  %Val)
8609       declare fp128     @llvm.log2.f128(fp128 %Val)
8610       declare ppc_fp128 @llvm.log2.ppcf128(ppc_fp128  %Val)
8611
8612 Overview:
8613 """""""""
8614
8615 The '``llvm.log2.*``' intrinsics perform the log2 function.
8616
8617 Arguments:
8618 """"""""""
8619
8620 The argument and return value are floating point numbers of the same
8621 type.
8622
8623 Semantics:
8624 """"""""""
8625
8626 This function returns the same values as the libm ``log2`` functions
8627 would, and handles error conditions in the same way.
8628
8629 '``llvm.fma.*``' Intrinsic
8630 ^^^^^^^^^^^^^^^^^^^^^^^^^^
8631
8632 Syntax:
8633 """""""
8634
8635 This is an overloaded intrinsic. You can use ``llvm.fma`` on any
8636 floating point or vector of floating point type. Not all targets support
8637 all types however.
8638
8639 ::
8640
8641       declare float     @llvm.fma.f32(float  %a, float  %b, float  %c)
8642       declare double    @llvm.fma.f64(double %a, double %b, double %c)
8643       declare x86_fp80  @llvm.fma.f80(x86_fp80 %a, x86_fp80 %b, x86_fp80 %c)
8644       declare fp128     @llvm.fma.f128(fp128 %a, fp128 %b, fp128 %c)
8645       declare ppc_fp128 @llvm.fma.ppcf128(ppc_fp128 %a, ppc_fp128 %b, ppc_fp128 %c)
8646
8647 Overview:
8648 """""""""
8649
8650 The '``llvm.fma.*``' intrinsics perform the fused multiply-add
8651 operation.
8652
8653 Arguments:
8654 """"""""""
8655
8656 The argument and return value are floating point numbers of the same
8657 type.
8658
8659 Semantics:
8660 """"""""""
8661
8662 This function returns the same values as the libm ``fma`` functions
8663 would, and does not set errno.
8664
8665 '``llvm.fabs.*``' Intrinsic
8666 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
8667
8668 Syntax:
8669 """""""
8670
8671 This is an overloaded intrinsic. You can use ``llvm.fabs`` on any
8672 floating point or vector of floating point type. Not all targets support
8673 all types however.
8674
8675 ::
8676
8677       declare float     @llvm.fabs.f32(float  %Val)
8678       declare double    @llvm.fabs.f64(double %Val)
8679       declare x86_fp80  @llvm.fabs.f80(x86_fp80 %Val)
8680       declare fp128     @llvm.fabs.f128(fp128 %Val)
8681       declare ppc_fp128 @llvm.fabs.ppcf128(ppc_fp128 %Val)
8682
8683 Overview:
8684 """""""""
8685
8686 The '``llvm.fabs.*``' intrinsics return the absolute value of the
8687 operand.
8688
8689 Arguments:
8690 """"""""""
8691
8692 The argument and return value are floating point numbers of the same
8693 type.
8694
8695 Semantics:
8696 """"""""""
8697
8698 This function returns the same values as the libm ``fabs`` functions
8699 would, and handles error conditions in the same way.
8700
8701 '``llvm.minnum.*``' Intrinsic
8702 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8703
8704 Syntax:
8705 """""""
8706
8707 This is an overloaded intrinsic. You can use ``llvm.minnum`` on any
8708 floating point or vector of floating point type. Not all targets support
8709 all types however.
8710
8711 ::
8712
8713       declare float     @llvm.minnum.f32(float %Val0, float %Val1)
8714       declare double    @llvm.minnum.f64(double %Val0, double %Val1)
8715       declare x86_fp80  @llvm.minnum.f80(x86_fp80 %Val0, x86_fp80 %Val1)
8716       declare fp128     @llvm.minnum.f128(fp128 %Val0, fp128 %Val1)
8717       declare ppc_fp128 @llvm.minnum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1)
8718
8719 Overview:
8720 """""""""
8721
8722 The '``llvm.minnum.*``' intrinsics return the minimum of the two
8723 arguments.
8724
8725
8726 Arguments:
8727 """"""""""
8728
8729 The arguments and return value are floating point numbers of the same
8730 type.
8731
8732 Semantics:
8733 """"""""""
8734
8735 Follows the IEEE-754 semantics for minNum, which also match for libm's
8736 fmin.
8737
8738 If either operand is a NaN, returns the other non-NaN operand. Returns
8739 NaN only if both operands are NaN. If the operands compare equal,
8740 returns a value that compares equal to both operands. This means that
8741 fmin(+/-0.0, +/-0.0) could return either -0.0 or 0.0.
8742
8743 '``llvm.maxnum.*``' Intrinsic
8744 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8745
8746 Syntax:
8747 """""""
8748
8749 This is an overloaded intrinsic. You can use ``llvm.maxnum`` on any
8750 floating point or vector of floating point type. Not all targets support
8751 all types however.
8752
8753 ::
8754
8755       declare float     @llvm.maxnum.f32(float  %Val0, float  %Val1l)
8756       declare double    @llvm.maxnum.f64(double %Val0, double %Val1)
8757       declare x86_fp80  @llvm.maxnum.f80(x86_fp80  %Val0, x86_fp80  %Val1)
8758       declare fp128     @llvm.maxnum.f128(fp128 %Val0, fp128 %Val1)
8759       declare ppc_fp128 @llvm.maxnum.ppcf128(ppc_fp128  %Val0, ppc_fp128  %Val1)
8760
8761 Overview:
8762 """""""""
8763
8764 The '``llvm.maxnum.*``' intrinsics return the maximum of the two
8765 arguments.
8766
8767
8768 Arguments:
8769 """"""""""
8770
8771 The arguments and return value are floating point numbers of the same
8772 type.
8773
8774 Semantics:
8775 """"""""""
8776 Follows the IEEE-754 semantics for maxNum, which also match for libm's
8777 fmax.
8778
8779 If either operand is a NaN, returns the other non-NaN operand. Returns
8780 NaN only if both operands are NaN. If the operands compare equal,
8781 returns a value that compares equal to both operands. This means that
8782 fmax(+/-0.0, +/-0.0) could return either -0.0 or 0.0.
8783
8784 '``llvm.copysign.*``' Intrinsic
8785 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8786
8787 Syntax:
8788 """""""
8789
8790 This is an overloaded intrinsic. You can use ``llvm.copysign`` on any
8791 floating point or vector of floating point type. Not all targets support
8792 all types however.
8793
8794 ::
8795
8796       declare float     @llvm.copysign.f32(float  %Mag, float  %Sgn)
8797       declare double    @llvm.copysign.f64(double %Mag, double %Sgn)
8798       declare x86_fp80  @llvm.copysign.f80(x86_fp80  %Mag, x86_fp80  %Sgn)
8799       declare fp128     @llvm.copysign.f128(fp128 %Mag, fp128 %Sgn)
8800       declare ppc_fp128 @llvm.copysign.ppcf128(ppc_fp128  %Mag, ppc_fp128  %Sgn)
8801
8802 Overview:
8803 """""""""
8804
8805 The '``llvm.copysign.*``' intrinsics return a value with the magnitude of the
8806 first operand and the sign of the second operand.
8807
8808 Arguments:
8809 """"""""""
8810
8811 The arguments and return value are floating point numbers of the same
8812 type.
8813
8814 Semantics:
8815 """"""""""
8816
8817 This function returns the same values as the libm ``copysign``
8818 functions would, and handles error conditions in the same way.
8819
8820 '``llvm.floor.*``' Intrinsic
8821 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8822
8823 Syntax:
8824 """""""
8825
8826 This is an overloaded intrinsic. You can use ``llvm.floor`` on any
8827 floating point or vector of floating point type. Not all targets support
8828 all types however.
8829
8830 ::
8831
8832       declare float     @llvm.floor.f32(float  %Val)
8833       declare double    @llvm.floor.f64(double %Val)
8834       declare x86_fp80  @llvm.floor.f80(x86_fp80  %Val)
8835       declare fp128     @llvm.floor.f128(fp128 %Val)
8836       declare ppc_fp128 @llvm.floor.ppcf128(ppc_fp128  %Val)
8837
8838 Overview:
8839 """""""""
8840
8841 The '``llvm.floor.*``' intrinsics return the floor of the operand.
8842
8843 Arguments:
8844 """"""""""
8845
8846 The argument and return value are floating point numbers of the same
8847 type.
8848
8849 Semantics:
8850 """"""""""
8851
8852 This function returns the same values as the libm ``floor`` functions
8853 would, and handles error conditions in the same way.
8854
8855 '``llvm.ceil.*``' Intrinsic
8856 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
8857
8858 Syntax:
8859 """""""
8860
8861 This is an overloaded intrinsic. You can use ``llvm.ceil`` on any
8862 floating point or vector of floating point type. Not all targets support
8863 all types however.
8864
8865 ::
8866
8867       declare float     @llvm.ceil.f32(float  %Val)
8868       declare double    @llvm.ceil.f64(double %Val)
8869       declare x86_fp80  @llvm.ceil.f80(x86_fp80  %Val)
8870       declare fp128     @llvm.ceil.f128(fp128 %Val)
8871       declare ppc_fp128 @llvm.ceil.ppcf128(ppc_fp128  %Val)
8872
8873 Overview:
8874 """""""""
8875
8876 The '``llvm.ceil.*``' intrinsics return the ceiling of the operand.
8877
8878 Arguments:
8879 """"""""""
8880
8881 The argument and return value are floating point numbers of the same
8882 type.
8883
8884 Semantics:
8885 """"""""""
8886
8887 This function returns the same values as the libm ``ceil`` functions
8888 would, and handles error conditions in the same way.
8889
8890 '``llvm.trunc.*``' Intrinsic
8891 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8892
8893 Syntax:
8894 """""""
8895
8896 This is an overloaded intrinsic. You can use ``llvm.trunc`` on any
8897 floating point or vector of floating point type. Not all targets support
8898 all types however.
8899
8900 ::
8901
8902       declare float     @llvm.trunc.f32(float  %Val)
8903       declare double    @llvm.trunc.f64(double %Val)
8904       declare x86_fp80  @llvm.trunc.f80(x86_fp80  %Val)
8905       declare fp128     @llvm.trunc.f128(fp128 %Val)
8906       declare ppc_fp128 @llvm.trunc.ppcf128(ppc_fp128  %Val)
8907
8908 Overview:
8909 """""""""
8910
8911 The '``llvm.trunc.*``' intrinsics returns the operand rounded to the
8912 nearest integer not larger in magnitude than the operand.
8913
8914 Arguments:
8915 """"""""""
8916
8917 The argument and return value are floating point numbers of the same
8918 type.
8919
8920 Semantics:
8921 """"""""""
8922
8923 This function returns the same values as the libm ``trunc`` functions
8924 would, and handles error conditions in the same way.
8925
8926 '``llvm.rint.*``' Intrinsic
8927 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
8928
8929 Syntax:
8930 """""""
8931
8932 This is an overloaded intrinsic. You can use ``llvm.rint`` on any
8933 floating point or vector of floating point type. Not all targets support
8934 all types however.
8935
8936 ::
8937
8938       declare float     @llvm.rint.f32(float  %Val)
8939       declare double    @llvm.rint.f64(double %Val)
8940       declare x86_fp80  @llvm.rint.f80(x86_fp80  %Val)
8941       declare fp128     @llvm.rint.f128(fp128 %Val)
8942       declare ppc_fp128 @llvm.rint.ppcf128(ppc_fp128  %Val)
8943
8944 Overview:
8945 """""""""
8946
8947 The '``llvm.rint.*``' intrinsics returns the operand rounded to the
8948 nearest integer. It may raise an inexact floating-point exception if the
8949 operand isn't an integer.
8950
8951 Arguments:
8952 """"""""""
8953
8954 The argument and return value are floating point numbers of the same
8955 type.
8956
8957 Semantics:
8958 """"""""""
8959
8960 This function returns the same values as the libm ``rint`` functions
8961 would, and handles error conditions in the same way.
8962
8963 '``llvm.nearbyint.*``' Intrinsic
8964 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8965
8966 Syntax:
8967 """""""
8968
8969 This is an overloaded intrinsic. You can use ``llvm.nearbyint`` on any
8970 floating point or vector of floating point type. Not all targets support
8971 all types however.
8972
8973 ::
8974
8975       declare float     @llvm.nearbyint.f32(float  %Val)
8976       declare double    @llvm.nearbyint.f64(double %Val)
8977       declare x86_fp80  @llvm.nearbyint.f80(x86_fp80  %Val)
8978       declare fp128     @llvm.nearbyint.f128(fp128 %Val)
8979       declare ppc_fp128 @llvm.nearbyint.ppcf128(ppc_fp128  %Val)
8980
8981 Overview:
8982 """""""""
8983
8984 The '``llvm.nearbyint.*``' intrinsics returns the operand rounded to the
8985 nearest integer.
8986
8987 Arguments:
8988 """"""""""
8989
8990 The argument and return value are floating point numbers of the same
8991 type.
8992
8993 Semantics:
8994 """"""""""
8995
8996 This function returns the same values as the libm ``nearbyint``
8997 functions would, and handles error conditions in the same way.
8998
8999 '``llvm.round.*``' Intrinsic
9000 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9001
9002 Syntax:
9003 """""""
9004
9005 This is an overloaded intrinsic. You can use ``llvm.round`` on any
9006 floating point or vector of floating point type. Not all targets support
9007 all types however.
9008
9009 ::
9010
9011       declare float     @llvm.round.f32(float  %Val)
9012       declare double    @llvm.round.f64(double %Val)
9013       declare x86_fp80  @llvm.round.f80(x86_fp80  %Val)
9014       declare fp128     @llvm.round.f128(fp128 %Val)
9015       declare ppc_fp128 @llvm.round.ppcf128(ppc_fp128  %Val)
9016
9017 Overview:
9018 """""""""
9019
9020 The '``llvm.round.*``' intrinsics returns the operand rounded to the
9021 nearest integer.
9022
9023 Arguments:
9024 """"""""""
9025
9026 The argument and return value are floating point numbers of the same
9027 type.
9028
9029 Semantics:
9030 """"""""""
9031
9032 This function returns the same values as the libm ``round``
9033 functions would, and handles error conditions in the same way.
9034
9035 Bit Manipulation Intrinsics
9036 ---------------------------
9037
9038 LLVM provides intrinsics for a few important bit manipulation
9039 operations. These allow efficient code generation for some algorithms.
9040
9041 '``llvm.bswap.*``' Intrinsics
9042 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9043
9044 Syntax:
9045 """""""
9046
9047 This is an overloaded intrinsic function. You can use bswap on any
9048 integer type that is an even number of bytes (i.e. BitWidth % 16 == 0).
9049
9050 ::
9051
9052       declare i16 @llvm.bswap.i16(i16 <id>)
9053       declare i32 @llvm.bswap.i32(i32 <id>)
9054       declare i64 @llvm.bswap.i64(i64 <id>)
9055
9056 Overview:
9057 """""""""
9058
9059 The '``llvm.bswap``' family of intrinsics is used to byte swap integer
9060 values with an even number of bytes (positive multiple of 16 bits).
9061 These are useful for performing operations on data that is not in the
9062 target's native byte order.
9063
9064 Semantics:
9065 """"""""""
9066
9067 The ``llvm.bswap.i16`` intrinsic returns an i16 value that has the high
9068 and low byte of the input i16 swapped. Similarly, the ``llvm.bswap.i32``
9069 intrinsic returns an i32 value that has the four bytes of the input i32
9070 swapped, so that if the input bytes are numbered 0, 1, 2, 3 then the
9071 returned i32 will have its bytes in 3, 2, 1, 0 order. The
9072 ``llvm.bswap.i48``, ``llvm.bswap.i64`` and other intrinsics extend this
9073 concept to additional even-byte lengths (6 bytes, 8 bytes and more,
9074 respectively).
9075
9076 '``llvm.ctpop.*``' Intrinsic
9077 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9078
9079 Syntax:
9080 """""""
9081
9082 This is an overloaded intrinsic. You can use llvm.ctpop on any integer
9083 bit width, or on any vector with integer elements. Not all targets
9084 support all bit widths or vector types, however.
9085
9086 ::
9087
9088       declare i8 @llvm.ctpop.i8(i8  <src>)
9089       declare i16 @llvm.ctpop.i16(i16 <src>)
9090       declare i32 @llvm.ctpop.i32(i32 <src>)
9091       declare i64 @llvm.ctpop.i64(i64 <src>)
9092       declare i256 @llvm.ctpop.i256(i256 <src>)
9093       declare <2 x i32> @llvm.ctpop.v2i32(<2 x i32> <src>)
9094
9095 Overview:
9096 """""""""
9097
9098 The '``llvm.ctpop``' family of intrinsics counts the number of bits set
9099 in a value.
9100
9101 Arguments:
9102 """"""""""
9103
9104 The only argument is the value to be counted. The argument may be of any
9105 integer type, or a vector with integer elements. The return type must
9106 match the argument type.
9107
9108 Semantics:
9109 """"""""""
9110
9111 The '``llvm.ctpop``' intrinsic counts the 1's in a variable, or within
9112 each element of a vector.
9113
9114 '``llvm.ctlz.*``' Intrinsic
9115 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
9116
9117 Syntax:
9118 """""""
9119
9120 This is an overloaded intrinsic. You can use ``llvm.ctlz`` on any
9121 integer bit width, or any vector whose elements are integers. Not all
9122 targets support all bit widths or vector types, however.
9123
9124 ::
9125
9126       declare i8   @llvm.ctlz.i8  (i8   <src>, i1 <is_zero_undef>)
9127       declare i16  @llvm.ctlz.i16 (i16  <src>, i1 <is_zero_undef>)
9128       declare i32  @llvm.ctlz.i32 (i32  <src>, i1 <is_zero_undef>)
9129       declare i64  @llvm.ctlz.i64 (i64  <src>, i1 <is_zero_undef>)
9130       declare i256 @llvm.ctlz.i256(i256 <src>, i1 <is_zero_undef>)
9131       declase <2 x i32> @llvm.ctlz.v2i32(<2 x i32> <src>, i1 <is_zero_undef>)
9132
9133 Overview:
9134 """""""""
9135
9136 The '``llvm.ctlz``' family of intrinsic functions counts the number of
9137 leading zeros in a variable.
9138
9139 Arguments:
9140 """"""""""
9141
9142 The first argument is the value to be counted. This argument may be of
9143 any integer type, or a vector with integer element type. The return
9144 type must match the first argument type.
9145
9146 The second argument must be a constant and is a flag to indicate whether
9147 the intrinsic should ensure that a zero as the first argument produces a
9148 defined result. Historically some architectures did not provide a
9149 defined result for zero values as efficiently, and many algorithms are
9150 now predicated on avoiding zero-value inputs.
9151
9152 Semantics:
9153 """"""""""
9154
9155 The '``llvm.ctlz``' intrinsic counts the leading (most significant)
9156 zeros in a variable, or within each element of the vector. If
9157 ``src == 0`` then the result is the size in bits of the type of ``src``
9158 if ``is_zero_undef == 0`` and ``undef`` otherwise. For example,
9159 ``llvm.ctlz(i32 2) = 30``.
9160
9161 '``llvm.cttz.*``' Intrinsic
9162 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
9163
9164 Syntax:
9165 """""""
9166
9167 This is an overloaded intrinsic. You can use ``llvm.cttz`` on any
9168 integer bit width, or any vector of integer elements. Not all targets
9169 support all bit widths or vector types, however.
9170
9171 ::
9172
9173       declare i8   @llvm.cttz.i8  (i8   <src>, i1 <is_zero_undef>)
9174       declare i16  @llvm.cttz.i16 (i16  <src>, i1 <is_zero_undef>)
9175       declare i32  @llvm.cttz.i32 (i32  <src>, i1 <is_zero_undef>)
9176       declare i64  @llvm.cttz.i64 (i64  <src>, i1 <is_zero_undef>)
9177       declare i256 @llvm.cttz.i256(i256 <src>, i1 <is_zero_undef>)
9178       declase <2 x i32> @llvm.cttz.v2i32(<2 x i32> <src>, i1 <is_zero_undef>)
9179
9180 Overview:
9181 """""""""
9182
9183 The '``llvm.cttz``' family of intrinsic functions counts the number of
9184 trailing zeros.
9185
9186 Arguments:
9187 """"""""""
9188
9189 The first argument is the value to be counted. This argument may be of
9190 any integer type, or a vector with integer element type. The return
9191 type must match the first argument type.
9192
9193 The second argument must be a constant and is a flag to indicate whether
9194 the intrinsic should ensure that a zero as the first argument produces a
9195 defined result. Historically some architectures did not provide a
9196 defined result for zero values as efficiently, and many algorithms are
9197 now predicated on avoiding zero-value inputs.
9198
9199 Semantics:
9200 """"""""""
9201
9202 The '``llvm.cttz``' intrinsic counts the trailing (least significant)
9203 zeros in a variable, or within each element of a vector. If ``src == 0``
9204 then the result is the size in bits of the type of ``src`` if
9205 ``is_zero_undef == 0`` and ``undef`` otherwise. For example,
9206 ``llvm.cttz(2) = 1``.
9207
9208 .. _int_overflow:
9209
9210 Arithmetic with Overflow Intrinsics
9211 -----------------------------------
9212
9213 LLVM provides intrinsics for some arithmetic with overflow operations.
9214
9215 '``llvm.sadd.with.overflow.*``' Intrinsics
9216 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9217
9218 Syntax:
9219 """""""
9220
9221 This is an overloaded intrinsic. You can use ``llvm.sadd.with.overflow``
9222 on any integer bit width.
9223
9224 ::
9225
9226       declare {i16, i1} @llvm.sadd.with.overflow.i16(i16 %a, i16 %b)
9227       declare {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b)
9228       declare {i64, i1} @llvm.sadd.with.overflow.i64(i64 %a, i64 %b)
9229
9230 Overview:
9231 """""""""
9232
9233 The '``llvm.sadd.with.overflow``' family of intrinsic functions perform
9234 a signed addition of the two arguments, and indicate whether an overflow
9235 occurred during the signed summation.
9236
9237 Arguments:
9238 """"""""""
9239
9240 The arguments (%a and %b) and the first element of the result structure
9241 may be of integer types of any bit width, but they must have the same
9242 bit width. The second element of the result structure must be of type
9243 ``i1``. ``%a`` and ``%b`` are the two values that will undergo signed
9244 addition.
9245
9246 Semantics:
9247 """"""""""
9248
9249 The '``llvm.sadd.with.overflow``' family of intrinsic functions perform
9250 a signed addition of the two variables. They return a structure --- the
9251 first element of which is the signed summation, and the second element
9252 of which is a bit specifying if the signed summation resulted in an
9253 overflow.
9254
9255 Examples:
9256 """""""""
9257
9258 .. code-block:: llvm
9259
9260       %res = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b)
9261       %sum = extractvalue {i32, i1} %res, 0
9262       %obit = extractvalue {i32, i1} %res, 1
9263       br i1 %obit, label %overflow, label %normal
9264
9265 '``llvm.uadd.with.overflow.*``' Intrinsics
9266 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9267
9268 Syntax:
9269 """""""
9270
9271 This is an overloaded intrinsic. You can use ``llvm.uadd.with.overflow``
9272 on any integer bit width.
9273
9274 ::
9275
9276       declare {i16, i1} @llvm.uadd.with.overflow.i16(i16 %a, i16 %b)
9277       declare {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b)
9278       declare {i64, i1} @llvm.uadd.with.overflow.i64(i64 %a, i64 %b)
9279
9280 Overview:
9281 """""""""
9282
9283 The '``llvm.uadd.with.overflow``' family of intrinsic functions perform
9284 an unsigned addition of the two arguments, and indicate whether a carry
9285 occurred during the unsigned summation.
9286
9287 Arguments:
9288 """"""""""
9289
9290 The arguments (%a and %b) and the first element of the result structure
9291 may be of integer types of any bit width, but they must have the same
9292 bit width. The second element of the result structure must be of type
9293 ``i1``. ``%a`` and ``%b`` are the two values that will undergo unsigned
9294 addition.
9295
9296 Semantics:
9297 """"""""""
9298
9299 The '``llvm.uadd.with.overflow``' family of intrinsic functions perform
9300 an unsigned addition of the two arguments. They return a structure --- the
9301 first element of which is the sum, and the second element of which is a
9302 bit specifying if the unsigned summation resulted in a carry.
9303
9304 Examples:
9305 """""""""
9306
9307 .. code-block:: llvm
9308
9309       %res = call {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b)
9310       %sum = extractvalue {i32, i1} %res, 0
9311       %obit = extractvalue {i32, i1} %res, 1
9312       br i1 %obit, label %carry, label %normal
9313
9314 '``llvm.ssub.with.overflow.*``' Intrinsics
9315 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9316
9317 Syntax:
9318 """""""
9319
9320 This is an overloaded intrinsic. You can use ``llvm.ssub.with.overflow``
9321 on any integer bit width.
9322
9323 ::
9324
9325       declare {i16, i1} @llvm.ssub.with.overflow.i16(i16 %a, i16 %b)
9326       declare {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a, i32 %b)
9327       declare {i64, i1} @llvm.ssub.with.overflow.i64(i64 %a, i64 %b)
9328
9329 Overview:
9330 """""""""
9331
9332 The '``llvm.ssub.with.overflow``' family of intrinsic functions perform
9333 a signed subtraction of the two arguments, and indicate whether an
9334 overflow occurred during the signed subtraction.
9335
9336 Arguments:
9337 """"""""""
9338
9339 The arguments (%a and %b) and the first element of the result structure
9340 may be of integer types of any bit width, but they must have the same
9341 bit width. The second element of the result structure must be of type
9342 ``i1``. ``%a`` and ``%b`` are the two values that will undergo signed
9343 subtraction.
9344
9345 Semantics:
9346 """"""""""
9347
9348 The '``llvm.ssub.with.overflow``' family of intrinsic functions perform
9349 a signed subtraction of the two arguments. They return a structure --- the
9350 first element of which is the subtraction, and the second element of
9351 which is a bit specifying if the signed subtraction resulted in an
9352 overflow.
9353
9354 Examples:
9355 """""""""
9356
9357 .. code-block:: llvm
9358
9359       %res = call {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a, i32 %b)
9360       %sum = extractvalue {i32, i1} %res, 0
9361       %obit = extractvalue {i32, i1} %res, 1
9362       br i1 %obit, label %overflow, label %normal
9363
9364 '``llvm.usub.with.overflow.*``' Intrinsics
9365 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9366
9367 Syntax:
9368 """""""
9369
9370 This is an overloaded intrinsic. You can use ``llvm.usub.with.overflow``
9371 on any integer bit width.
9372
9373 ::
9374
9375       declare {i16, i1} @llvm.usub.with.overflow.i16(i16 %a, i16 %b)
9376       declare {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b)
9377       declare {i64, i1} @llvm.usub.with.overflow.i64(i64 %a, i64 %b)
9378
9379 Overview:
9380 """""""""
9381
9382 The '``llvm.usub.with.overflow``' family of intrinsic functions perform
9383 an unsigned subtraction of the two arguments, and indicate whether an
9384 overflow occurred during the unsigned subtraction.
9385
9386 Arguments:
9387 """"""""""
9388
9389 The arguments (%a and %b) and the first element of the result structure
9390 may be of integer types of any bit width, but they must have the same
9391 bit width. The second element of the result structure must be of type
9392 ``i1``. ``%a`` and ``%b`` are the two values that will undergo unsigned
9393 subtraction.
9394
9395 Semantics:
9396 """"""""""
9397
9398 The '``llvm.usub.with.overflow``' family of intrinsic functions perform
9399 an unsigned subtraction of the two arguments. They return a structure ---
9400 the first element of which is the subtraction, and the second element of
9401 which is a bit specifying if the unsigned subtraction resulted in an
9402 overflow.
9403
9404 Examples:
9405 """""""""
9406
9407 .. code-block:: llvm
9408
9409       %res = call {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b)
9410       %sum = extractvalue {i32, i1} %res, 0
9411       %obit = extractvalue {i32, i1} %res, 1
9412       br i1 %obit, label %overflow, label %normal
9413
9414 '``llvm.smul.with.overflow.*``' Intrinsics
9415 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9416
9417 Syntax:
9418 """""""
9419
9420 This is an overloaded intrinsic. You can use ``llvm.smul.with.overflow``
9421 on any integer bit width.
9422
9423 ::
9424
9425       declare {i16, i1} @llvm.smul.with.overflow.i16(i16 %a, i16 %b)
9426       declare {i32, i1} @llvm.smul.with.overflow.i32(i32 %a, i32 %b)
9427       declare {i64, i1} @llvm.smul.with.overflow.i64(i64 %a, i64 %b)
9428
9429 Overview:
9430 """""""""
9431
9432 The '``llvm.smul.with.overflow``' family of intrinsic functions perform
9433 a signed multiplication of the two arguments, and indicate whether an
9434 overflow occurred during the signed multiplication.
9435
9436 Arguments:
9437 """"""""""
9438
9439 The arguments (%a and %b) and the first element of the result structure
9440 may be of integer types of any bit width, but they must have the same
9441 bit width. The second element of the result structure must be of type
9442 ``i1``. ``%a`` and ``%b`` are the two values that will undergo signed
9443 multiplication.
9444
9445 Semantics:
9446 """"""""""
9447
9448 The '``llvm.smul.with.overflow``' family of intrinsic functions perform
9449 a signed multiplication of the two arguments. They return a structure ---
9450 the first element of which is the multiplication, and the second element
9451 of which is a bit specifying if the signed multiplication resulted in an
9452 overflow.
9453
9454 Examples:
9455 """""""""
9456
9457 .. code-block:: llvm
9458
9459       %res = call {i32, i1} @llvm.smul.with.overflow.i32(i32 %a, i32 %b)
9460       %sum = extractvalue {i32, i1} %res, 0
9461       %obit = extractvalue {i32, i1} %res, 1
9462       br i1 %obit, label %overflow, label %normal
9463
9464 '``llvm.umul.with.overflow.*``' Intrinsics
9465 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9466
9467 Syntax:
9468 """""""
9469
9470 This is an overloaded intrinsic. You can use ``llvm.umul.with.overflow``
9471 on any integer bit width.
9472
9473 ::
9474
9475       declare {i16, i1} @llvm.umul.with.overflow.i16(i16 %a, i16 %b)
9476       declare {i32, i1} @llvm.umul.with.overflow.i32(i32 %a, i32 %b)
9477       declare {i64, i1} @llvm.umul.with.overflow.i64(i64 %a, i64 %b)
9478
9479 Overview:
9480 """""""""
9481
9482 The '``llvm.umul.with.overflow``' family of intrinsic functions perform
9483 a unsigned multiplication of the two arguments, and indicate whether an
9484 overflow occurred during the unsigned multiplication.
9485
9486 Arguments:
9487 """"""""""
9488
9489 The arguments (%a and %b) and the first element of the result structure
9490 may be of integer types of any bit width, but they must have the same
9491 bit width. The second element of the result structure must be of type
9492 ``i1``. ``%a`` and ``%b`` are the two values that will undergo unsigned
9493 multiplication.
9494
9495 Semantics:
9496 """"""""""
9497
9498 The '``llvm.umul.with.overflow``' family of intrinsic functions perform
9499 an unsigned multiplication of the two arguments. They return a structure ---
9500 the first element of which is the multiplication, and the second
9501 element of which is a bit specifying if the unsigned multiplication
9502 resulted in an overflow.
9503
9504 Examples:
9505 """""""""
9506
9507 .. code-block:: llvm
9508
9509       %res = call {i32, i1} @llvm.umul.with.overflow.i32(i32 %a, i32 %b)
9510       %sum = extractvalue {i32, i1} %res, 0
9511       %obit = extractvalue {i32, i1} %res, 1
9512       br i1 %obit, label %overflow, label %normal
9513
9514 Specialised Arithmetic Intrinsics
9515 ---------------------------------
9516
9517 '``llvm.fmuladd.*``' Intrinsic
9518 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9519
9520 Syntax:
9521 """""""
9522
9523 ::
9524
9525       declare float @llvm.fmuladd.f32(float %a, float %b, float %c)
9526       declare double @llvm.fmuladd.f64(double %a, double %b, double %c)
9527
9528 Overview:
9529 """""""""
9530
9531 The '``llvm.fmuladd.*``' intrinsic functions represent multiply-add
9532 expressions that can be fused if the code generator determines that (a) the
9533 target instruction set has support for a fused operation, and (b) that the
9534 fused operation is more efficient than the equivalent, separate pair of mul
9535 and add instructions.
9536
9537 Arguments:
9538 """"""""""
9539
9540 The '``llvm.fmuladd.*``' intrinsics each take three arguments: two
9541 multiplicands, a and b, and an addend c.
9542
9543 Semantics:
9544 """"""""""
9545
9546 The expression:
9547
9548 ::
9549
9550       %0 = call float @llvm.fmuladd.f32(%a, %b, %c)
9551
9552 is equivalent to the expression a \* b + c, except that rounding will
9553 not be performed between the multiplication and addition steps if the
9554 code generator fuses the operations. Fusion is not guaranteed, even if
9555 the target platform supports it. If a fused multiply-add is required the
9556 corresponding llvm.fma.\* intrinsic function should be used
9557 instead. This never sets errno, just as '``llvm.fma.*``'.
9558
9559 Examples:
9560 """""""""
9561
9562 .. code-block:: llvm
9563
9564       %r2 = call float @llvm.fmuladd.f32(float %a, float %b, float %c) ; yields float:r2 = (a * b) + c
9565
9566 Half Precision Floating Point Intrinsics
9567 ----------------------------------------
9568
9569 For most target platforms, half precision floating point is a
9570 storage-only format. This means that it is a dense encoding (in memory)
9571 but does not support computation in the format.
9572
9573 This means that code must first load the half-precision floating point
9574 value as an i16, then convert it to float with
9575 :ref:`llvm.convert.from.fp16 <int_convert_from_fp16>`. Computation can
9576 then be performed on the float value (including extending to double
9577 etc). To store the value back to memory, it is first converted to float
9578 if needed, then converted to i16 with
9579 :ref:`llvm.convert.to.fp16 <int_convert_to_fp16>`, then storing as an
9580 i16 value.
9581
9582 .. _int_convert_to_fp16:
9583
9584 '``llvm.convert.to.fp16``' Intrinsic
9585 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9586
9587 Syntax:
9588 """""""
9589
9590 ::
9591
9592       declare i16 @llvm.convert.to.fp16.f32(float %a)
9593       declare i16 @llvm.convert.to.fp16.f64(double %a)
9594
9595 Overview:
9596 """""""""
9597
9598 The '``llvm.convert.to.fp16``' intrinsic function performs a conversion from a
9599 conventional floating point type to half precision floating point format.
9600
9601 Arguments:
9602 """"""""""
9603
9604 The intrinsic function contains single argument - the value to be
9605 converted.
9606
9607 Semantics:
9608 """"""""""
9609
9610 The '``llvm.convert.to.fp16``' intrinsic function performs a conversion from a
9611 conventional floating point format to half precision floating point format. The
9612 return value is an ``i16`` which contains the converted number.
9613
9614 Examples:
9615 """""""""
9616
9617 .. code-block:: llvm
9618
9619       %res = call i16 @llvm.convert.to.fp16.f32(float %a)
9620       store i16 %res, i16* @x, align 2
9621
9622 .. _int_convert_from_fp16:
9623
9624 '``llvm.convert.from.fp16``' Intrinsic
9625 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9626
9627 Syntax:
9628 """""""
9629
9630 ::
9631
9632       declare float @llvm.convert.from.fp16.f32(i16 %a)
9633       declare double @llvm.convert.from.fp16.f64(i16 %a)
9634
9635 Overview:
9636 """""""""
9637
9638 The '``llvm.convert.from.fp16``' intrinsic function performs a
9639 conversion from half precision floating point format to single precision
9640 floating point format.
9641
9642 Arguments:
9643 """"""""""
9644
9645 The intrinsic function contains single argument - the value to be
9646 converted.
9647
9648 Semantics:
9649 """"""""""
9650
9651 The '``llvm.convert.from.fp16``' intrinsic function performs a
9652 conversion from half single precision floating point format to single
9653 precision floating point format. The input half-float value is
9654 represented by an ``i16`` value.
9655
9656 Examples:
9657 """""""""
9658
9659 .. code-block:: llvm
9660
9661       %a = load i16, i16* @x, align 2
9662       %res = call float @llvm.convert.from.fp16(i16 %a)
9663
9664 .. _dbg_intrinsics:
9665
9666 Debugger Intrinsics
9667 -------------------
9668
9669 The LLVM debugger intrinsics (which all start with ``llvm.dbg.``
9670 prefix), are described in the `LLVM Source Level
9671 Debugging <SourceLevelDebugging.html#format_common_intrinsics>`_
9672 document.
9673
9674 Exception Handling Intrinsics
9675 -----------------------------
9676
9677 The LLVM exception handling intrinsics (which all start with
9678 ``llvm.eh.`` prefix), are described in the `LLVM Exception
9679 Handling <ExceptionHandling.html#format_common_intrinsics>`_ document.
9680
9681 .. _int_trampoline:
9682
9683 Trampoline Intrinsics
9684 ---------------------
9685
9686 These intrinsics make it possible to excise one parameter, marked with
9687 the :ref:`nest <nest>` attribute, from a function. The result is a
9688 callable function pointer lacking the nest parameter - the caller does
9689 not need to provide a value for it. Instead, the value to use is stored
9690 in advance in a "trampoline", a block of memory usually allocated on the
9691 stack, which also contains code to splice the nest value into the
9692 argument list. This is used to implement the GCC nested function address
9693 extension.
9694
9695 For example, if the function is ``i32 f(i8* nest %c, i32 %x, i32 %y)``
9696 then the resulting function pointer has signature ``i32 (i32, i32)*``.
9697 It can be created as follows:
9698
9699 .. code-block:: llvm
9700
9701       %tramp = alloca [10 x i8], align 4 ; size and alignment only correct for X86
9702       %tramp1 = getelementptr [10 x i8], [10 x i8]* %tramp, i32 0, i32 0
9703       call i8* @llvm.init.trampoline(i8* %tramp1, i8* bitcast (i32 (i8*, i32, i32)* @f to i8*), i8* %nval)
9704       %p = call i8* @llvm.adjust.trampoline(i8* %tramp1)
9705       %fp = bitcast i8* %p to i32 (i32, i32)*
9706
9707 The call ``%val = call i32 %fp(i32 %x, i32 %y)`` is then equivalent to
9708 ``%val = call i32 %f(i8* %nval, i32 %x, i32 %y)``.
9709
9710 .. _int_it:
9711
9712 '``llvm.init.trampoline``' Intrinsic
9713 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9714
9715 Syntax:
9716 """""""
9717
9718 ::
9719
9720       declare void @llvm.init.trampoline(i8* <tramp>, i8* <func>, i8* <nval>)
9721
9722 Overview:
9723 """""""""
9724
9725 This fills the memory pointed to by ``tramp`` with executable code,
9726 turning it into a trampoline.
9727
9728 Arguments:
9729 """"""""""
9730
9731 The ``llvm.init.trampoline`` intrinsic takes three arguments, all
9732 pointers. The ``tramp`` argument must point to a sufficiently large and
9733 sufficiently aligned block of memory; this memory is written to by the
9734 intrinsic. Note that the size and the alignment are target-specific -
9735 LLVM currently provides no portable way of determining them, so a
9736 front-end that generates this intrinsic needs to have some
9737 target-specific knowledge. The ``func`` argument must hold a function
9738 bitcast to an ``i8*``.
9739
9740 Semantics:
9741 """"""""""
9742
9743 The block of memory pointed to by ``tramp`` is filled with target
9744 dependent code, turning it into a function. Then ``tramp`` needs to be
9745 passed to :ref:`llvm.adjust.trampoline <int_at>` to get a pointer which can
9746 be :ref:`bitcast (to a new function) and called <int_trampoline>`. The new
9747 function's signature is the same as that of ``func`` with any arguments
9748 marked with the ``nest`` attribute removed. At most one such ``nest``
9749 argument is allowed, and it must be of pointer type. Calling the new
9750 function is equivalent to calling ``func`` with the same argument list,
9751 but with ``nval`` used for the missing ``nest`` argument. If, after
9752 calling ``llvm.init.trampoline``, the memory pointed to by ``tramp`` is
9753 modified, then the effect of any later call to the returned function
9754 pointer is undefined.
9755
9756 .. _int_at:
9757
9758 '``llvm.adjust.trampoline``' Intrinsic
9759 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9760
9761 Syntax:
9762 """""""
9763
9764 ::
9765
9766       declare i8* @llvm.adjust.trampoline(i8* <tramp>)
9767
9768 Overview:
9769 """""""""
9770
9771 This performs any required machine-specific adjustment to the address of
9772 a trampoline (passed as ``tramp``).
9773
9774 Arguments:
9775 """"""""""
9776
9777 ``tramp`` must point to a block of memory which already has trampoline
9778 code filled in by a previous call to
9779 :ref:`llvm.init.trampoline <int_it>`.
9780
9781 Semantics:
9782 """"""""""
9783
9784 On some architectures the address of the code to be executed needs to be
9785 different than the address where the trampoline is actually stored. This
9786 intrinsic returns the executable address corresponding to ``tramp``
9787 after performing the required machine specific adjustments. The pointer
9788 returned can then be :ref:`bitcast and executed <int_trampoline>`.
9789
9790 .. _int_mload_mstore:
9791
9792 Masked Vector Load and Store Intrinsics
9793 ---------------------------------------
9794
9795 LLVM 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.
9796
9797 .. _int_mload:
9798
9799 '``llvm.masked.load.*``' Intrinsics
9800 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9801
9802 Syntax:
9803 """""""
9804 This is an overloaded intrinsic. The loaded data is a vector of any integer or floating point data type.
9805
9806 ::
9807
9808       declare <16 x float> @llvm.masked.load.v16f32 (<16 x float>* <ptr>, i32 <alignment>, <16 x i1> <mask>, <16 x float> <passthru>)
9809       declare <2 x double> @llvm.masked.load.v2f64  (<2 x double>* <ptr>, i32 <alignment>, <2 x i1>  <mask>, <2 x double> <passthru>)
9810
9811 Overview:
9812 """""""""
9813
9814 Reads 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.
9815
9816
9817 Arguments:
9818 """"""""""
9819
9820 The 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.
9821
9822
9823 Semantics:
9824 """"""""""
9825
9826 The '``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.
9827 The 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.
9828
9829
9830 ::
9831
9832        %res = call <16 x float> @llvm.masked.load.v16f32 (<16 x float>* %ptr, i32 4, <16 x i1>%mask, <16 x float> %passthru)
9833
9834        ;; The result of the two following instructions is identical aside from potential memory access exception
9835        %loadlal = load <16 x float>, <16 x float>* %ptr, align 4
9836        %res = select <16 x i1> %mask, <16 x float> %loadlal, <16 x float> %passthru
9837
9838 .. _int_mstore:
9839
9840 '``llvm.masked.store.*``' Intrinsics
9841 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9842
9843 Syntax:
9844 """""""
9845 This is an overloaded intrinsic. The data stored in memory is a vector of any integer or floating point data type.
9846
9847 ::
9848
9849        declare void @llvm.masked.store.v8i32 (<8 x i32>  <value>, <8 x i32> * <ptr>, i32 <alignment>,  <8 x i1>  <mask>)
9850        declare void @llvm.masked.store.v16f32(<16 x i32> <value>, <16 x i32>* <ptr>, i32 <alignment>,  <16 x i1> <mask>)
9851
9852 Overview:
9853 """""""""
9854
9855 Writes 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.
9856
9857 Arguments:
9858 """"""""""
9859
9860 The 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.
9861
9862
9863 Semantics:
9864 """"""""""
9865
9866 The '``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.
9867 The 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.
9868
9869 ::
9870
9871        call void @llvm.masked.store.v16f32(<16 x float> %value, <16 x float>* %ptr, i32 4,  <16 x i1> %mask)
9872
9873        ;; The result of the following instructions is identical aside from potential data races and memory access exceptions
9874        %oldval = load <16 x float>, <16 x float>* %ptr, align 4
9875        %res = select <16 x i1> %mask, <16 x float> %value, <16 x float> %oldval
9876        store <16 x float> %res, <16 x float>* %ptr, align 4
9877
9878
9879 Masked Vector Gather and Scatter Intrinsics
9880 -------------------------------------------
9881
9882 LLVM 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.
9883
9884 .. _int_mgather:
9885
9886 '``llvm.masked.gather.*``' Intrinsics
9887 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9888
9889 Syntax:
9890 """""""
9891 This is an overloaded intrinsic. The loaded data are multiple scalar values of any integer or floating point data type gathered together into one vector.
9892
9893 ::
9894
9895       declare <16 x float> @llvm.masked.gather.v16f32 (<16 x float*> <ptrs>, i32 <alignment>, <16 x i1> <mask>, <16 x float> <passthru>)
9896       declare <2 x double> @llvm.masked.gather.v2f64  (<2 x double*> <ptrs>, i32 <alignment>, <2 x i1>  <mask>, <2 x double> <passthru>)
9897
9898 Overview:
9899 """""""""
9900
9901 Reads 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.
9902
9903
9904 Arguments:
9905 """"""""""
9906
9907 The 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.
9908
9909
9910 Semantics:
9911 """"""""""
9912
9913 The '``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.
9914 The 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.
9915
9916
9917 ::
9918
9919        %res = call <4 x double> @llvm.masked.gather.v4f64 (<4 x double*> %ptrs, i32 8, <4 x i1>%mask, <4 x double> <true, true, true, true>)
9920
9921        ;; The gather with all-true mask is equivalent to the following instruction sequence
9922        %ptr0 = extractelement <4 x double*> %ptrs, i32 0
9923        %ptr1 = extractelement <4 x double*> %ptrs, i32 1
9924        %ptr2 = extractelement <4 x double*> %ptrs, i32 2
9925        %ptr3 = extractelement <4 x double*> %ptrs, i32 3
9926
9927        %val0 = load double, double* %ptr0, align 8
9928        %val1 = load double, double* %ptr1, align 8
9929        %val2 = load double, double* %ptr2, align 8
9930        %val3 = load double, double* %ptr3, align 8
9931
9932        %vec0    = insertelement <4 x double>undef, %val0, 0
9933        %vec01   = insertelement <4 x double>%vec0, %val1, 1
9934        %vec012  = insertelement <4 x double>%vec01, %val2, 2
9935        %vec0123 = insertelement <4 x double>%vec012, %val3, 3
9936
9937 .. _int_mscatter:
9938
9939 '``llvm.masked.scatter.*``' Intrinsics
9940 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9941
9942 Syntax:
9943 """""""
9944 This is an overloaded intrinsic. The data stored in memory is a vector of any integer or floating point data type. Each vector element is stored in an arbitrary memory addresses. Scatter with overlapping addresses is guaranteed to be ordered from least-significant to most-significant element.
9945
9946 ::
9947
9948        declare void @llvm.masked.scatter.v8i32 (<8 x i32>  <value>, <8 x i32*>  <ptrs>, i32 <alignment>,  <8 x i1>  <mask>)
9949        declare void @llvm.masked.scatter.v16f32(<16 x i32> <value>, <16 x i32*> <ptrs>, i32 <alignment>,  <16 x i1> <mask>)
9950
9951 Overview:
9952 """""""""
9953
9954 Writes 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.
9955
9956 Arguments:
9957 """"""""""
9958
9959 The 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.
9960
9961
9962 Semantics:
9963 """"""""""
9964
9965 The '``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 divergency. Other targets may support this intrinsic differently, for example by lowering it into a sequence of branches that guard scalar store operations.
9966
9967 ::
9968
9969        ;; This instruction unconditionaly stores data vector in multiple addresses
9970        call @llvm.masked.scatter.v8i32 (<8 x i32> %value, <8 x i32*> %ptrs, i32 4,  <8 x i1>  <true, true, .. true>)
9971
9972        ;; It is equivalent to a list of scalar stores
9973        %val0 = extractelement <8 x i32> %value, i32 0
9974        %val1 = extractelement <8 x i32> %value, i32 1
9975        ..
9976        %val7 = extractelement <8 x i32> %value, i32 7
9977        %ptr0 = extractelement <8 x i32*> %ptrs, i32 0
9978        %ptr1 = extractelement <8 x i32*> %ptrs, i32 1
9979        ..
9980        %ptr7 = extractelement <8 x i32*> %ptrs, i32 7
9981        ;; Note: the order of the following stores is important when they overlap:
9982        store i32 %val0, i32* %ptr0, align 4
9983        store i32 %val1, i32* %ptr1, align 4
9984        ..
9985        store i32 %val7, i32* %ptr7, align 4
9986
9987
9988 Memory Use Markers
9989 ------------------
9990
9991 This class of intrinsics provides information about the lifetime of
9992 memory objects and ranges where variables are immutable.
9993
9994 .. _int_lifestart:
9995
9996 '``llvm.lifetime.start``' Intrinsic
9997 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9998
9999 Syntax:
10000 """""""
10001
10002 ::
10003
10004       declare void @llvm.lifetime.start(i64 <size>, i8* nocapture <ptr>)
10005
10006 Overview:
10007 """""""""
10008
10009 The '``llvm.lifetime.start``' intrinsic specifies the start of a memory
10010 object's lifetime.
10011
10012 Arguments:
10013 """"""""""
10014
10015 The first argument is a constant integer representing the size of the
10016 object, or -1 if it is variable sized. The second argument is a pointer
10017 to the object.
10018
10019 Semantics:
10020 """"""""""
10021
10022 This intrinsic indicates that before this point in the code, the value
10023 of the memory pointed to by ``ptr`` is dead. This means that it is known
10024 to never be used and has an undefined value. A load from the pointer
10025 that precedes this intrinsic can be replaced with ``'undef'``.
10026
10027 .. _int_lifeend:
10028
10029 '``llvm.lifetime.end``' Intrinsic
10030 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10031
10032 Syntax:
10033 """""""
10034
10035 ::
10036
10037       declare void @llvm.lifetime.end(i64 <size>, i8* nocapture <ptr>)
10038
10039 Overview:
10040 """""""""
10041
10042 The '``llvm.lifetime.end``' intrinsic specifies the end of a memory
10043 object's lifetime.
10044
10045 Arguments:
10046 """"""""""
10047
10048 The first argument is a constant integer representing the size of the
10049 object, or -1 if it is variable sized. The second argument is a pointer
10050 to the object.
10051
10052 Semantics:
10053 """"""""""
10054
10055 This intrinsic indicates that after this point in the code, the value of
10056 the memory pointed to by ``ptr`` is dead. This means that it is known to
10057 never be used and has an undefined value. Any stores into the memory
10058 object following this intrinsic may be removed as dead.
10059
10060 '``llvm.invariant.start``' Intrinsic
10061 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10062
10063 Syntax:
10064 """""""
10065
10066 ::
10067
10068       declare {}* @llvm.invariant.start(i64 <size>, i8* nocapture <ptr>)
10069
10070 Overview:
10071 """""""""
10072
10073 The '``llvm.invariant.start``' intrinsic specifies that the contents of
10074 a memory object will not change.
10075
10076 Arguments:
10077 """"""""""
10078
10079 The first argument is a constant integer representing the size of the
10080 object, or -1 if it is variable sized. The second argument is a pointer
10081 to the object.
10082
10083 Semantics:
10084 """"""""""
10085
10086 This intrinsic indicates that until an ``llvm.invariant.end`` that uses
10087 the return value, the referenced memory location is constant and
10088 unchanging.
10089
10090 '``llvm.invariant.end``' Intrinsic
10091 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10092
10093 Syntax:
10094 """""""
10095
10096 ::
10097
10098       declare void @llvm.invariant.end({}* <start>, i64 <size>, i8* nocapture <ptr>)
10099
10100 Overview:
10101 """""""""
10102
10103 The '``llvm.invariant.end``' intrinsic specifies that the contents of a
10104 memory object are mutable.
10105
10106 Arguments:
10107 """"""""""
10108
10109 The first argument is the matching ``llvm.invariant.start`` intrinsic.
10110 The second argument is a constant integer representing the size of the
10111 object, or -1 if it is variable sized and the third argument is a
10112 pointer to the object.
10113
10114 Semantics:
10115 """"""""""
10116
10117 This intrinsic indicates that the memory is mutable again.
10118
10119 General Intrinsics
10120 ------------------
10121
10122 This class of intrinsics is designed to be generic and has no specific
10123 purpose.
10124
10125 '``llvm.var.annotation``' Intrinsic
10126 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10127
10128 Syntax:
10129 """""""
10130
10131 ::
10132
10133       declare void @llvm.var.annotation(i8* <val>, i8* <str>, i8* <str>, i32  <int>)
10134
10135 Overview:
10136 """""""""
10137
10138 The '``llvm.var.annotation``' intrinsic.
10139
10140 Arguments:
10141 """"""""""
10142
10143 The first argument is a pointer to a value, the second is a pointer to a
10144 global string, the third is a pointer to a global string which is the
10145 source file name, and the last argument is the line number.
10146
10147 Semantics:
10148 """"""""""
10149
10150 This intrinsic allows annotation of local variables with arbitrary
10151 strings. This can be useful for special purpose optimizations that want
10152 to look for these annotations. These have no other defined use; they are
10153 ignored by code generation and optimization.
10154
10155 '``llvm.ptr.annotation.*``' Intrinsic
10156 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10157
10158 Syntax:
10159 """""""
10160
10161 This is an overloaded intrinsic. You can use '``llvm.ptr.annotation``' on a
10162 pointer to an integer of any width. *NOTE* you must specify an address space for
10163 the pointer. The identifier for the default address space is the integer
10164 '``0``'.
10165
10166 ::
10167
10168       declare i8*   @llvm.ptr.annotation.p<address space>i8(i8* <val>, i8* <str>, i8* <str>, i32  <int>)
10169       declare i16*  @llvm.ptr.annotation.p<address space>i16(i16* <val>, i8* <str>, i8* <str>, i32  <int>)
10170       declare i32*  @llvm.ptr.annotation.p<address space>i32(i32* <val>, i8* <str>, i8* <str>, i32  <int>)
10171       declare i64*  @llvm.ptr.annotation.p<address space>i64(i64* <val>, i8* <str>, i8* <str>, i32  <int>)
10172       declare i256* @llvm.ptr.annotation.p<address space>i256(i256* <val>, i8* <str>, i8* <str>, i32  <int>)
10173
10174 Overview:
10175 """""""""
10176
10177 The '``llvm.ptr.annotation``' intrinsic.
10178
10179 Arguments:
10180 """"""""""
10181
10182 The first argument is a pointer to an integer value of arbitrary bitwidth
10183 (result of some expression), the second is a pointer to a global string, the
10184 third is a pointer to a global string which is the source file name, and the
10185 last argument is the line number. It returns the value of the first argument.
10186
10187 Semantics:
10188 """"""""""
10189
10190 This intrinsic allows annotation of a pointer to an integer with arbitrary
10191 strings. This can be useful for special purpose optimizations that want to look
10192 for these annotations. These have no other defined use; they are ignored by code
10193 generation and optimization.
10194
10195 '``llvm.annotation.*``' Intrinsic
10196 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10197
10198 Syntax:
10199 """""""
10200
10201 This is an overloaded intrinsic. You can use '``llvm.annotation``' on
10202 any integer bit width.
10203
10204 ::
10205
10206       declare i8 @llvm.annotation.i8(i8 <val>, i8* <str>, i8* <str>, i32  <int>)
10207       declare i16 @llvm.annotation.i16(i16 <val>, i8* <str>, i8* <str>, i32  <int>)
10208       declare i32 @llvm.annotation.i32(i32 <val>, i8* <str>, i8* <str>, i32  <int>)
10209       declare i64 @llvm.annotation.i64(i64 <val>, i8* <str>, i8* <str>, i32  <int>)
10210       declare i256 @llvm.annotation.i256(i256 <val>, i8* <str>, i8* <str>, i32  <int>)
10211
10212 Overview:
10213 """""""""
10214
10215 The '``llvm.annotation``' intrinsic.
10216
10217 Arguments:
10218 """"""""""
10219
10220 The first argument is an integer value (result of some expression), the
10221 second is a pointer to a global string, the third is a pointer to a
10222 global string which is the source file name, and the last argument is
10223 the line number. It returns the value of the first argument.
10224
10225 Semantics:
10226 """"""""""
10227
10228 This intrinsic allows annotations to be put on arbitrary expressions
10229 with arbitrary strings. This can be useful for special purpose
10230 optimizations that want to look for these annotations. These have no
10231 other defined use; they are ignored by code generation and optimization.
10232
10233 '``llvm.trap``' Intrinsic
10234 ^^^^^^^^^^^^^^^^^^^^^^^^^
10235
10236 Syntax:
10237 """""""
10238
10239 ::
10240
10241       declare void @llvm.trap() noreturn nounwind
10242
10243 Overview:
10244 """""""""
10245
10246 The '``llvm.trap``' intrinsic.
10247
10248 Arguments:
10249 """"""""""
10250
10251 None.
10252
10253 Semantics:
10254 """"""""""
10255
10256 This intrinsic is lowered to the target dependent trap instruction. If
10257 the target does not have a trap instruction, this intrinsic will be
10258 lowered to a call of the ``abort()`` function.
10259
10260 '``llvm.debugtrap``' Intrinsic
10261 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10262
10263 Syntax:
10264 """""""
10265
10266 ::
10267
10268       declare void @llvm.debugtrap() nounwind
10269
10270 Overview:
10271 """""""""
10272
10273 The '``llvm.debugtrap``' intrinsic.
10274
10275 Arguments:
10276 """"""""""
10277
10278 None.
10279
10280 Semantics:
10281 """"""""""
10282
10283 This intrinsic is lowered to code which is intended to cause an
10284 execution trap with the intention of requesting the attention of a
10285 debugger.
10286
10287 '``llvm.stackprotector``' Intrinsic
10288 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10289
10290 Syntax:
10291 """""""
10292
10293 ::
10294
10295       declare void @llvm.stackprotector(i8* <guard>, i8** <slot>)
10296
10297 Overview:
10298 """""""""
10299
10300 The ``llvm.stackprotector`` intrinsic takes the ``guard`` and stores it
10301 onto the stack at ``slot``. The stack slot is adjusted to ensure that it
10302 is placed on the stack before local variables.
10303
10304 Arguments:
10305 """"""""""
10306
10307 The ``llvm.stackprotector`` intrinsic requires two pointer arguments.
10308 The first argument is the value loaded from the stack guard
10309 ``@__stack_chk_guard``. The second variable is an ``alloca`` that has
10310 enough space to hold the value of the guard.
10311
10312 Semantics:
10313 """"""""""
10314
10315 This intrinsic causes the prologue/epilogue inserter to force the position of
10316 the ``AllocaInst`` stack slot to be before local variables on the stack. This is
10317 to ensure that if a local variable on the stack is overwritten, it will destroy
10318 the value of the guard. When the function exits, the guard on the stack is
10319 checked against the original guard by ``llvm.stackprotectorcheck``. If they are
10320 different, then ``llvm.stackprotectorcheck`` causes the program to abort by
10321 calling the ``__stack_chk_fail()`` function.
10322
10323 '``llvm.stackprotectorcheck``' Intrinsic
10324 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10325
10326 Syntax:
10327 """""""
10328
10329 ::
10330
10331       declare void @llvm.stackprotectorcheck(i8** <guard>)
10332
10333 Overview:
10334 """""""""
10335
10336 The ``llvm.stackprotectorcheck`` intrinsic compares ``guard`` against an already
10337 created stack protector and if they are not equal calls the
10338 ``__stack_chk_fail()`` function.
10339
10340 Arguments:
10341 """"""""""
10342
10343 The ``llvm.stackprotectorcheck`` intrinsic requires one pointer argument, the
10344 the variable ``@__stack_chk_guard``.
10345
10346 Semantics:
10347 """"""""""
10348
10349 This intrinsic is provided to perform the stack protector check by comparing
10350 ``guard`` with the stack slot created by ``llvm.stackprotector`` and if the
10351 values do not match call the ``__stack_chk_fail()`` function.
10352
10353 The reason to provide this as an IR level intrinsic instead of implementing it
10354 via other IR operations is that in order to perform this operation at the IR
10355 level without an intrinsic, one would need to create additional basic blocks to
10356 handle the success/failure cases. This makes it difficult to stop the stack
10357 protector check from disrupting sibling tail calls in Codegen. With this
10358 intrinsic, we are able to generate the stack protector basic blocks late in
10359 codegen after the tail call decision has occurred.
10360
10361 '``llvm.objectsize``' Intrinsic
10362 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10363
10364 Syntax:
10365 """""""
10366
10367 ::
10368
10369       declare i32 @llvm.objectsize.i32(i8* <object>, i1 <min>)
10370       declare i64 @llvm.objectsize.i64(i8* <object>, i1 <min>)
10371
10372 Overview:
10373 """""""""
10374
10375 The ``llvm.objectsize`` intrinsic is designed to provide information to
10376 the optimizers to determine at compile time whether a) an operation
10377 (like memcpy) will overflow a buffer that corresponds to an object, or
10378 b) that a runtime check for overflow isn't necessary. An object in this
10379 context means an allocation of a specific class, structure, array, or
10380 other object.
10381
10382 Arguments:
10383 """"""""""
10384
10385 The ``llvm.objectsize`` intrinsic takes two arguments. The first
10386 argument is a pointer to or into the ``object``. The second argument is
10387 a boolean and determines whether ``llvm.objectsize`` returns 0 (if true)
10388 or -1 (if false) when the object size is unknown. The second argument
10389 only accepts constants.
10390
10391 Semantics:
10392 """"""""""
10393
10394 The ``llvm.objectsize`` intrinsic is lowered to a constant representing
10395 the size of the object concerned. If the size cannot be determined at
10396 compile time, ``llvm.objectsize`` returns ``i32/i64 -1 or 0`` (depending
10397 on the ``min`` argument).
10398
10399 '``llvm.expect``' Intrinsic
10400 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
10401
10402 Syntax:
10403 """""""
10404
10405 This is an overloaded intrinsic. You can use ``llvm.expect`` on any
10406 integer bit width.
10407
10408 ::
10409
10410       declare i1 @llvm.expect.i1(i1 <val>, i1 <expected_val>)
10411       declare i32 @llvm.expect.i32(i32 <val>, i32 <expected_val>)
10412       declare i64 @llvm.expect.i64(i64 <val>, i64 <expected_val>)
10413
10414 Overview:
10415 """""""""
10416
10417 The ``llvm.expect`` intrinsic provides information about expected (the
10418 most probable) value of ``val``, which can be used by optimizers.
10419
10420 Arguments:
10421 """"""""""
10422
10423 The ``llvm.expect`` intrinsic takes two arguments. The first argument is
10424 a value. The second argument is an expected value, this needs to be a
10425 constant value, variables are not allowed.
10426
10427 Semantics:
10428 """"""""""
10429
10430 This intrinsic is lowered to the ``val``.
10431
10432 .. _int_assume:
10433
10434 '``llvm.assume``' Intrinsic
10435 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10436
10437 Syntax:
10438 """""""
10439
10440 ::
10441
10442       declare void @llvm.assume(i1 %cond)
10443
10444 Overview:
10445 """""""""
10446
10447 The ``llvm.assume`` allows the optimizer to assume that the provided
10448 condition is true. This information can then be used in simplifying other parts
10449 of the code.
10450
10451 Arguments:
10452 """"""""""
10453
10454 The condition which the optimizer may assume is always true.
10455
10456 Semantics:
10457 """"""""""
10458
10459 The intrinsic allows the optimizer to assume that the provided condition is
10460 always true whenever the control flow reaches the intrinsic call. No code is
10461 generated for this intrinsic, and instructions that contribute only to the
10462 provided condition are not used for code generation. If the condition is
10463 violated during execution, the behavior is undefined.
10464
10465 Note that the optimizer might limit the transformations performed on values
10466 used by the ``llvm.assume`` intrinsic in order to preserve the instructions
10467 only used to form the intrinsic's input argument. This might prove undesirable
10468 if the extra information provided by the ``llvm.assume`` intrinsic does not cause
10469 sufficient overall improvement in code quality. For this reason,
10470 ``llvm.assume`` should not be used to document basic mathematical invariants
10471 that the optimizer can otherwise deduce or facts that are of little use to the
10472 optimizer.
10473
10474 .. _bitset.test:
10475
10476 '``llvm.bitset.test``' Intrinsic
10477 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10478
10479 Syntax:
10480 """""""
10481
10482 ::
10483
10484       declare i1 @llvm.bitset.test(i8* %ptr, metadata %bitset) nounwind readnone
10485
10486
10487 Arguments:
10488 """"""""""
10489
10490 The first argument is a pointer to be tested. The second argument is a
10491 metadata string containing the name of a :doc:`bitset <BitSets>`.
10492
10493 Overview:
10494 """""""""
10495
10496 The ``llvm.bitset.test`` intrinsic tests whether the given pointer is a
10497 member of the given bitset.
10498
10499 '``llvm.donothing``' Intrinsic
10500 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10501
10502 Syntax:
10503 """""""
10504
10505 ::
10506
10507       declare void @llvm.donothing() nounwind readnone
10508
10509 Overview:
10510 """""""""
10511
10512 The ``llvm.donothing`` intrinsic doesn't perform any operation. It's one of only
10513 two intrinsics (besides ``llvm.experimental.patchpoint``) that can be called
10514 with an invoke instruction.
10515
10516 Arguments:
10517 """"""""""
10518
10519 None.
10520
10521 Semantics:
10522 """"""""""
10523
10524 This intrinsic does nothing, and it's removed by optimizers and ignored
10525 by codegen.
10526
10527 Stack Map Intrinsics
10528 --------------------
10529
10530 LLVM provides experimental intrinsics to support runtime patching
10531 mechanisms commonly desired in dynamic language JITs. These intrinsics
10532 are described in :doc:`StackMaps`.