1============================== 2LLVM Language Reference Manual 3============================== 4 5.. contents:: 6 :local: 7 :depth: 4 8 9Abstract 10======== 11 12This document is a reference manual for the LLVM assembly language. LLVM 13is a Static Single Assignment (SSA) based representation that provides 14type safety, low-level operations, flexibility, and the capability of 15representing 'all' high-level languages cleanly. It is the common code 16representation used throughout all phases of the LLVM compilation 17strategy. 18 19Introduction 20============ 21 22The LLVM code representation is designed to be used in three different 23forms: as an in-memory compiler IR, as an on-disk bitcode representation 24(suitable for fast loading by a Just-In-Time compiler), and as a human 25readable assembly language representation. This allows LLVM to provide a 26powerful intermediate representation for efficient compiler 27transformations and analysis, while providing a natural means to debug 28and visualize the transformations. The three different forms of LLVM are 29all equivalent. This document describes the human readable 30representation and notation. 31 32The LLVM representation aims to be light-weight and low-level while 33being expressive, typed, and extensible at the same time. It aims to be 34a "universal IR" of sorts, by being at a low enough level that 35high-level ideas may be cleanly mapped to it (similar to how 36microprocessors are "universal IR's", allowing many source languages to 37be mapped to them). By providing type information, LLVM can be used as 38the target of optimizations: for example, through pointer analysis, it 39can be proven that a C automatic variable is never accessed outside of 40the current function, allowing it to be promoted to a simple SSA value 41instead of a memory location. 42 43.. _wellformed: 44 45Well-Formedness 46--------------- 47 48It is important to note that this document describes 'well formed' LLVM 49assembly language. There is a difference between what the parser accepts 50and what is considered 'well formed'. For example, the following 51instruction is syntactically okay, but not well formed: 52 53.. code-block:: llvm 54 55 %x = add i32 1, %x 56 57because the definition of ``%x`` does not dominate all of its uses. The 58LLVM infrastructure provides a verification pass that may be used to 59verify that an LLVM module is well formed. This pass is automatically 60run by the parser after parsing input assembly and by the optimizer 61before it outputs bitcode. The violations pointed out by the verifier 62pass indicate bugs in transformation passes or input to the parser. 63 64.. _identifiers: 65 66Identifiers 67=========== 68 69LLVM identifiers come in two basic types: global and local. Global 70identifiers (functions, global variables) begin with the ``'@'`` 71character. Local identifiers (register names, types) begin with the 72``'%'`` character. Additionally, there are three different formats for 73identifiers, for different purposes: 74 75#. Named values are represented as a string of characters with their 76 prefix. For example, ``%foo``, ``@DivisionByZero``, 77 ``%a.really.long.identifier``. The actual regular expression used is 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 values 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 88LLVM requires that values start with a prefix for two reasons: Compilers 89don't need to worry about name clashes with reserved words, and the set 90of reserved words may be expanded in the future without penalty. 91Additionally, unnamed identifiers allow a compiler to quickly come up 92with a temporary variable without having to avoid symbol table 93conflicts. 94 95Reserved words in LLVM are very similar to reserved words in other 96languages. There are keywords for different opcodes ('``add``', 97'``bitcast``', '``ret``', etc...), for primitive type names ('``void``', 98'``i32``', etc...), and others. These reserved words cannot conflict 99with variable names, because none of them start with a prefix character 100(``'%'`` or ``'@'``). 101 102Here is an example of LLVM code to multiply the integer variable 103'``%X``' by 8: 104 105The easy way: 106 107.. code-block:: llvm 108 109 %result = mul i32 %X, 8 110 111After strength reduction: 112 113.. code-block:: llvm 114 115 %result = shl i32 %X, 3 116 117And 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 125This last way of multiplying ``%X`` by 8 illustrates several important 126lexical features of LLVM: 127 128#. Comments are delimited with a '``;``' and go until the end of line. 129#. Unnamed temporaries are created when the result of a computation is 130 not assigned to a named value. 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 137It also shows a convention that we follow in this document. When 138demonstrating instructions, we will follow an instruction with a comment 139that defines the type and name of value produced. 140 141High Level Structure 142==================== 143 144Module Structure 145---------------- 146 147LLVM programs are composed of ``Module``'s, each of which is a 148translation unit of the input programs. Each module consists of 149functions, global variables, and symbol table entries. Modules may be 150combined together with the LLVM linker, which merges function (and 151global variable) definitions, resolves forward declarations, and merges 152symbol table entries. Here is an example of the "hello world" module: 153 154.. code-block:: llvm 155 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 176This example is made up of a :ref:`global variable <globalvars>` named 177"``.str``", an external declaration of the "``puts``" function, a 178:ref:`function definition <functionstructure>` for "``main``" and 179:ref:`named metadata <namedmetadatastructure>` "``foo``". 180 181In general, a module is made up of a list of global values (where both 182functions and global variables are global values). Global values are 183represented by a pointer to a memory location (in this case, a pointer 184to an array of char, and a pointer to a function), and have one of the 185following :ref:`linkage types <linkage>`. 186 187.. _linkage: 188 189Linkage Types 190------------- 191 192All Global Variables and Functions have one of the following types of 193linkage: 194 195``private`` 196 Global values with "``private``" linkage are only directly 197 accessible by objects in the current module. In particular, linking 198 code into a module with a 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 into 208 the object file corresponding to the LLVM module. From the linker's 209 perspective, an ``available_externally`` global is equivalent to 210 an external declaration. They exist to allow inlining and other 211 optimizations to take place given knowledge of the definition of the 212 global, which is known to be somewhere outside the module. Globals 213 with ``available_externally`` linkage are allowed to be discarded at 214 will, and allow inlining and other optimizations. This linkage type is 215 only allowed on definitions, not declarations. 216``linkonce`` 217 Globals with "``linkonce``" linkage are merged with other globals of 218 the same name when linkage occurs. This can be used to implement 219 some forms of inline functions, templates, or other code which must 220 be generated in each translation unit that uses it, but where the 221 body may be overridden with a more definitive definition later. 222 Unreferenced ``linkonce`` globals are allowed to be discarded. Note 223 that ``linkonce`` linkage does not actually allow the optimizer to 224 inline the body of this function into callers because it doesn't 225 know if this definition of the function is the definitive definition 226 within the program or whether it will be overridden by a stronger 227 definition. To enable inlining and other optimizations, use 228 "``linkonce_odr``" linkage. 229``weak`` 230 "``weak``" linkage has the same merging semantics as ``linkonce`` 231 linkage, except that unreferenced globals with ``weak`` linkage may 232 not be discarded. This is used for globals that are declared "weak" 233 in C source code. 234``common`` 235 "``common``" linkage is most similar to "``weak``" linkage, but they 236 are used for tentative definitions in C, such as "``int X;``" at 237 global scope. Symbols with "``common``" linkage are merged in the 238 same way as ``weak symbols``, and they may not be deleted if 239 unreferenced. ``common`` symbols may not have an explicit section, 240 must have a zero initializer, and may not be marked 241 ':ref:`constant <globalvars>`'. Functions and aliases may not have 242 common linkage. 243 244.. _linkage_appending: 245 246``appending`` 247 "``appending``" linkage may only be applied to global variables of 248 pointer to array type. When two global variables with appending 249 linkage are linked together, the two global arrays are appended 250 together. This is the LLVM, typesafe, equivalent of having the 251 system linker append together "sections" with identical names when 252 .o files are linked. 253 254 Unfortunately this doesn't correspond to any feature in .o files, so it 255 can only be used for variables like ``llvm.global_ctors`` which llvm 256 interprets specially. 257 258``extern_weak`` 259 The semantics of this linkage follow the ELF object file model: the 260 symbol is weak until linked, if not linked, the symbol becomes null 261 instead of being an undefined reference. 262``linkonce_odr``, ``weak_odr`` 263 Some languages allow differing globals to be merged, such as two 264 functions with different semantics. Other languages, such as 265 ``C++``, ensure that only equivalent globals are ever merged (the 266 "one definition rule" --- "ODR"). Such languages can use the 267 ``linkonce_odr`` and ``weak_odr`` linkage types to indicate that the 268 global will only be merged with equivalent globals. These linkage 269 types are otherwise the same as their non-``odr`` versions. 270``external`` 271 If none of the above identifiers are used, the global is externally 272 visible, meaning that it participates in linkage and can be used to 273 resolve external symbol references. 274 275It is illegal for a function *declaration* to have any linkage type 276other than ``external`` or ``extern_weak``. 277 278.. _callingconv: 279 280Calling Conventions 281------------------- 282 283LLVM :ref:`functions <functionstructure>`, :ref:`calls <i_call>` and 284:ref:`invokes <i_invoke>` can all have an optional calling convention 285specified for the call. The calling convention of any pair of dynamic 286caller/callee must match, or the behavior of the program is undefined. 287The following calling conventions are supported by LLVM, and more may be 288added in the future: 289 290"``ccc``" - The C calling convention 291 This calling convention (the default if no other calling convention 292 is specified) matches the target C calling conventions. This calling 293 convention supports varargs function calls and tolerates some 294 mismatch in the declared prototype and implemented declaration of 295 the function (as does normal C). 296"``fastcc``" - The fast calling convention 297 This calling convention attempts to make calls as fast as possible 298 (e.g. by passing things in registers). This calling convention 299 allows the target to use whatever tricks it wants to produce fast 300 code for the target, without having to conform to an externally 301 specified ABI (Application Binary Interface). `Tail calls can only 302 be optimized when this, the tailcc, the GHC or the HiPE convention is 303 used. <CodeGenerator.html#id80>`_ This calling convention does not 304 support varargs and requires the prototype of all callees to exactly 305 match the prototype of the function definition. 306"``coldcc``" - The cold calling convention 307 This calling convention attempts to make code in the caller as 308 efficient as possible under the assumption that the call is not 309 commonly executed. As such, these calls often preserve all registers 310 so that the call does not break any live ranges in the caller side. 311 This calling convention does not support varargs and requires the 312 prototype of all callees to exactly match the prototype of the 313 function definition. Furthermore the inliner doesn't consider such function 314 calls for inlining. 315"``cc 10``" - GHC convention 316 This calling convention has been implemented specifically for use by 317 the `Glasgow Haskell Compiler (GHC) <http://www.haskell.org/ghc>`_. 318 It passes everything in registers, going to extremes to achieve this 319 by disabling callee save registers. This calling convention should 320 not be used lightly but only for specific situations such as an 321 alternative to the *register pinning* performance technique often 322 used when implementing functional programming languages. At the 323 moment only X86 supports this convention and it has the following 324 limitations: 325 326 - On *X86-32* only supports up to 4 bit type parameters. No 327 floating-point types are supported. 328 - On *X86-64* only supports up to 10 bit type parameters and 6 329 floating-point parameters. 330 331 This calling convention supports `tail call 332 optimization <CodeGenerator.html#id80>`_ but requires both the 333 caller and callee are using it. 334"``cc 11``" - The HiPE calling convention 335 This calling convention has been implemented specifically for use by 336 the `High-Performance Erlang 337 (HiPE) <http://www.it.uu.se/research/group/hipe/>`_ compiler, *the* 338 native code compiler of the `Ericsson's Open Source Erlang/OTP 339 system <http://www.erlang.org/download.shtml>`_. It uses more 340 registers for argument passing than the ordinary C calling 341 convention and defines no callee-saved registers. The calling 342 convention properly supports `tail call 343 optimization <CodeGenerator.html#id80>`_ but requires that both the 344 caller and the callee use it. It uses a *register pinning* 345 mechanism, similar to GHC's convention, for keeping frequently 346 accessed runtime components pinned to specific hardware registers. 347 At the moment only X86 supports this convention (both 32 and 64 348 bit). 349"``webkit_jscc``" - WebKit's JavaScript calling convention 350 This calling convention has been implemented for `WebKit FTL JIT 351 <https://trac.webkit.org/wiki/FTLJIT>`_. It passes arguments on the 352 stack right to left (as cdecl does), and returns a value in the 353 platform's customary return register. 354"``anyregcc``" - Dynamic calling convention for code patching 355 This is a special convention that supports patching an arbitrary code 356 sequence in place of a call site. This convention forces the call 357 arguments into registers but allows them to be dynamically 358 allocated. This can currently only be used with calls to 359 llvm.experimental.patchpoint because only this intrinsic records 360 the location of its arguments in a side table. See :doc:`StackMaps`. 361"``preserve_mostcc``" - The `PreserveMost` calling convention 362 This calling convention attempts to make the code in the caller as 363 unintrusive as possible. This convention behaves identically to the `C` 364 calling convention on how arguments and return values are passed, but it 365 uses a different set of caller/callee-saved registers. This alleviates the 366 burden of saving and recovering a large register set before and after the 367 call in the caller. If the arguments are passed in callee-saved registers, 368 then they will be preserved by the callee across the call. This doesn't 369 apply for values returned in callee-saved registers. 370 371 - On X86-64 the callee preserves all general purpose registers, except for 372 R11. R11 can be used as a scratch register. Floating-point registers 373 (XMMs/YMMs) are not preserved and need to be saved by the caller. 374 375 The idea behind this convention is to support calls to runtime functions 376 that have a hot path and a cold path. The hot path is usually a small piece 377 of code that doesn't use many registers. The cold path might need to call out to 378 another function and therefore only needs to preserve the caller-saved 379 registers, which haven't already been saved by the caller. The 380 `PreserveMost` calling convention is very similar to the `cold` calling 381 convention in terms of caller/callee-saved registers, but they are used for 382 different types of function calls. `coldcc` is for function calls that are 383 rarely executed, whereas `preserve_mostcc` function calls are intended to be 384 on the hot path and definitely executed a lot. Furthermore `preserve_mostcc` 385 doesn't prevent the inliner from inlining the function call. 386 387 This calling convention will be used by a future version of the ObjectiveC 388 runtime and should therefore still be considered experimental at this time. 389 Although this convention was created to optimize certain runtime calls to 390 the ObjectiveC runtime, it is not limited to this runtime and might be used 391 by other runtimes in the future too. The current implementation only 392 supports X86-64, but the intention is to support more architectures in the 393 future. 394"``preserve_allcc``" - The `PreserveAll` calling convention 395 This calling convention attempts to make the code in the caller even less 396 intrusive than the `PreserveMost` calling convention. This calling 397 convention also behaves identical to the `C` calling convention on how 398 arguments and return values are passed, but it uses a different set of 399 caller/callee-saved registers. This removes the burden of saving and 400 recovering a large register set before and after the call in the caller. If 401 the arguments are passed in callee-saved registers, then they will be 402 preserved by the callee across the call. This doesn't apply for values 403 returned in callee-saved registers. 404 405 - On X86-64 the callee preserves all general purpose registers, except for 406 R11. R11 can be used as a scratch register. Furthermore it also preserves 407 all floating-point registers (XMMs/YMMs). 408 409 The idea behind this convention is to support calls to runtime functions 410 that don't need to call out to any other functions. 411 412 This calling convention, like the `PreserveMost` calling convention, will be 413 used by a future version of the ObjectiveC runtime and should be considered 414 experimental at this time. 415"``cxx_fast_tlscc``" - The `CXX_FAST_TLS` calling convention for access functions 416 Clang generates an access function to access C++-style TLS. The access 417 function generally has an entry block, an exit block and an initialization 418 block that is run at the first time. The entry and exit blocks can access 419 a few TLS IR variables, each access will be lowered to a platform-specific 420 sequence. 421 422 This calling convention aims to minimize overhead in the caller by 423 preserving as many registers as possible (all the registers that are 424 preserved on the fast path, composed of the entry and exit blocks). 425 426 This calling convention behaves identical to the `C` calling convention on 427 how arguments and return values are passed, but it uses a different set of 428 caller/callee-saved registers. 429 430 Given that each platform has its own lowering sequence, hence its own set 431 of preserved registers, we can't use the existing `PreserveMost`. 432 433 - On X86-64 the callee preserves all general purpose registers, except for 434 RDI and RAX. 435"``swiftcc``" - This calling convention is used for Swift language. 436 - On X86-64 RCX and R8 are available for additional integer returns, and 437 XMM2 and XMM3 are available for additional FP/vector returns. 438 - On iOS platforms, we use AAPCS-VFP calling convention. 439"``tailcc``" - Tail callable calling convention 440 This calling convention ensures that calls in tail position will always be 441 tail call optimized. This calling convention is equivalent to fastcc, 442 except for an additional guarantee that tail calls will be produced 443 whenever possible. `Tail calls can only be optimized when this, the fastcc, 444 the GHC or the HiPE convention is used. <CodeGenerator.html#id80>`_ This 445 calling convention does not support varargs and requires the prototype of 446 all callees to exactly match the prototype of the function definition. 447"``cfguard_checkcc``" - Windows Control Flow Guard (Check mechanism) 448 This calling convention is used for the Control Flow Guard check function, 449 calls to which can be inserted before indirect calls to check that the call 450 target is a valid function address. The check function has no return value, 451 but it will trigger an OS-level error if the address is not a valid target. 452 The set of registers preserved by the check function, and the register 453 containing the target address are architecture-specific. 454 455 - On X86 the target address is passed in ECX. 456 - On ARM the target address is passed in R0. 457 - On AArch64 the target address is passed in X15. 458"``cc <n>``" - Numbered convention 459 Any calling convention may be specified by number, allowing 460 target-specific calling conventions to be used. Target specific 461 calling conventions start at 64. 462 463More calling conventions can be added/defined on an as-needed basis, to 464support Pascal conventions or any other well-known target-independent 465convention. 466 467.. _visibilitystyles: 468 469Visibility Styles 470----------------- 471 472All Global Variables and Functions have one of the following visibility 473styles: 474 475"``default``" - Default style 476 On targets that use the ELF object file format, default visibility 477 means that the declaration is visible to other modules and, in 478 shared libraries, means that the declared entity may be overridden. 479 On Darwin, default visibility means that the declaration is visible 480 to other modules. Default visibility corresponds to "external 481 linkage" in the language. 482"``hidden``" - Hidden style 483 Two declarations of an object with hidden visibility refer to the 484 same object if they are in the same shared object. Usually, hidden 485 visibility indicates that the symbol will not be placed into the 486 dynamic symbol table, so no other module (executable or shared 487 library) can reference it directly. 488"``protected``" - Protected style 489 On ELF, protected visibility indicates that the symbol will be 490 placed in the dynamic symbol table, but that references within the 491 defining module will bind to the local symbol. That is, the symbol 492 cannot be overridden by another module. 493 494A symbol with ``internal`` or ``private`` linkage must have ``default`` 495visibility. 496 497.. _dllstorageclass: 498 499DLL Storage Classes 500------------------- 501 502All Global Variables, Functions and Aliases can have one of the following 503DLL storage class: 504 505``dllimport`` 506 "``dllimport``" causes the compiler to reference a function or variable via 507 a global pointer to a pointer that is set up by the DLL exporting the 508 symbol. On Microsoft Windows targets, the pointer name is formed by 509 combining ``__imp_`` and the function or variable name. 510``dllexport`` 511 "``dllexport``" causes the compiler to provide a global pointer to a pointer 512 in a DLL, so that it can be referenced with the ``dllimport`` attribute. On 513 Microsoft Windows targets, the pointer name is formed by combining 514 ``__imp_`` and the function or variable name. Since this storage class 515 exists for defining a dll interface, the compiler, assembler and linker know 516 it is externally referenced and must refrain from deleting the symbol. 517 518.. _tls_model: 519 520Thread Local Storage Models 521--------------------------- 522 523A variable may be defined as ``thread_local``, which means that it will 524not be shared by threads (each thread will have a separated copy of the 525variable). Not all targets support thread-local variables. Optionally, a 526TLS model may be specified: 527 528``localdynamic`` 529 For variables that are only used within the current shared library. 530``initialexec`` 531 For variables in modules that will not be loaded dynamically. 532``localexec`` 533 For variables defined in the executable and only used within it. 534 535If no explicit model is given, the "general dynamic" model is used. 536 537The models correspond to the ELF TLS models; see `ELF Handling For 538Thread-Local Storage <http://people.redhat.com/drepper/tls.pdf>`_ for 539more information on under which circumstances the different models may 540be used. The target may choose a different TLS model if the specified 541model is not supported, or if a better choice of model can be made. 542 543A model can also be specified in an alias, but then it only governs how 544the alias is accessed. It will not have any effect in the aliasee. 545 546For platforms without linker support of ELF TLS model, the -femulated-tls 547flag can be used to generate GCC compatible emulated TLS code. 548 549.. _runtime_preemption_model: 550 551Runtime Preemption Specifiers 552----------------------------- 553 554Global variables, functions and aliases may have an optional runtime preemption 555specifier. If a preemption specifier isn't given explicitly, then a 556symbol is assumed to be ``dso_preemptable``. 557 558``dso_preemptable`` 559 Indicates that the function or variable may be replaced by a symbol from 560 outside the linkage unit at runtime. 561 562``dso_local`` 563 The compiler may assume that a function or variable marked as ``dso_local`` 564 will resolve to a symbol within the same linkage unit. Direct access will 565 be generated even if the definition is not within this compilation unit. 566 567.. _namedtypes: 568 569Structure Types 570--------------- 571 572LLVM IR allows you to specify both "identified" and "literal" :ref:`structure 573types <t_struct>`. Literal types are uniqued structurally, but identified types 574are never uniqued. An :ref:`opaque structural type <t_opaque>` can also be used 575to forward declare a type that is not yet available. 576 577An example of an identified structure specification is: 578 579.. code-block:: llvm 580 581 %mytype = type { %mytype*, i32 } 582 583Prior to the LLVM 3.0 release, identified types were structurally uniqued. Only 584literal types are uniqued in recent versions of LLVM. 585 586.. _nointptrtype: 587 588Non-Integral Pointer Type 589------------------------- 590 591Note: non-integral pointer types are a work in progress, and they should be 592considered experimental at this time. 593 594LLVM IR optionally allows the frontend to denote pointers in certain address 595spaces as "non-integral" via the :ref:`datalayout string<langref_datalayout>`. 596Non-integral pointer types represent pointers that have an *unspecified* bitwise 597representation; that is, the integral representation may be target dependent or 598unstable (not backed by a fixed integer). 599 600``inttoptr`` instructions converting integers to non-integral pointer types are 601ill-typed, and so are ``ptrtoint`` instructions converting values of 602non-integral pointer types to integers. Vector versions of said instructions 603are ill-typed as well. 604 605.. _globalvars: 606 607Global Variables 608---------------- 609 610Global variables define regions of memory allocated at compilation time 611instead of run-time. 612 613Global variable definitions must be initialized. 614 615Global variables in other translation units can also be declared, in which 616case they don't have an initializer. 617 618Either global variable definitions or declarations may have an explicit section 619to be placed in and may have an optional explicit alignment specified. If there 620is a mismatch between the explicit or inferred section information for the 621variable declaration and its definition the resulting behavior is undefined. 622 623A variable may be defined as a global ``constant``, which indicates that 624the contents of the variable will **never** be modified (enabling better 625optimization, allowing the global data to be placed in the read-only 626section of an executable, etc). Note that variables that need runtime 627initialization cannot be marked ``constant`` as there is a store to the 628variable. 629 630LLVM explicitly allows *declarations* of global variables to be marked 631constant, even if the final definition of the global is not. This 632capability can be used to enable slightly better optimization of the 633program, but requires the language definition to guarantee that 634optimizations based on the 'constantness' are valid for the translation 635units that do not include the definition. 636 637As SSA values, global variables define pointer values that are in scope 638(i.e. they dominate) all basic blocks in the program. Global variables 639always define a pointer to their "content" type because they describe a 640region of memory, and all memory objects in LLVM are accessed through 641pointers. 642 643Global variables can be marked with ``unnamed_addr`` which indicates 644that the address is not significant, only the content. Constants marked 645like this can be merged with other constants if they have the same 646initializer. Note that a constant with significant address *can* be 647merged with a ``unnamed_addr`` constant, the result being a constant 648whose address is significant. 649 650If the ``local_unnamed_addr`` attribute is given, the address is known to 651not be significant within the module. 652 653A global variable may be declared to reside in a target-specific 654numbered address space. For targets that support them, address spaces 655may affect how optimizations are performed and/or what target 656instructions are used to access the variable. The default address space 657is zero. The address space qualifier must precede any other attributes. 658 659LLVM allows an explicit section to be specified for globals. If the 660target supports it, it will emit globals to the section specified. 661Additionally, the global can placed in a comdat if the target has the necessary 662support. 663 664External declarations may have an explicit section specified. Section 665information is retained in LLVM IR for targets that make use of this 666information. Attaching section information to an external declaration is an 667assertion that its definition is located in the specified section. If the 668definition is located in a different section, the behavior is undefined. 669 670By default, global initializers are optimized by assuming that global 671variables defined within the module are not modified from their 672initial values before the start of the global initializer. This is 673true even for variables potentially accessible from outside the 674module, including those with external linkage or appearing in 675``@llvm.used`` or dllexported variables. This assumption may be suppressed 676by marking the variable with ``externally_initialized``. 677 678An explicit alignment may be specified for a global, which must be a 679power of 2. If not present, or if the alignment is set to zero, the 680alignment of the global is set by the target to whatever it feels 681convenient. If an explicit alignment is specified, the global is forced 682to have exactly that alignment. Targets and optimizers are not allowed 683to over-align the global if the global has an assigned section. In this 684case, the extra alignment could be observable: for example, code could 685assume that the globals are densely packed in their section and try to 686iterate over them as an array, alignment padding would break this 687iteration. The maximum alignment is ``1 << 29``. 688 689Globals can also have a :ref:`DLL storage class <dllstorageclass>`, 690an optional :ref:`runtime preemption specifier <runtime_preemption_model>`, 691an optional :ref:`global attributes <glattrs>` and 692an optional list of attached :ref:`metadata <metadata>`. 693 694Variables and aliases can have a 695:ref:`Thread Local Storage Model <tls_model>`. 696 697:ref:`Scalable vectors <t_vector>` cannot be global variables or members of 698structs or arrays because their size is unknown at compile time. 699 700Syntax:: 701 702 @<GlobalVarName> = [Linkage] [PreemptionSpecifier] [Visibility] 703 [DLLStorageClass] [ThreadLocal] 704 [(unnamed_addr|local_unnamed_addr)] [AddrSpace] 705 [ExternallyInitialized] 706 <global | constant> <Type> [<InitializerConstant>] 707 [, section "name"] [, comdat [($name)]] 708 [, align <Alignment>] (, !name !N)* 709 710For example, the following defines a global in a numbered address space 711with an initializer, section, and alignment: 712 713.. code-block:: llvm 714 715 @G = addrspace(5) constant float 1.0, section "foo", align 4 716 717The following example just declares a global variable 718 719.. code-block:: llvm 720 721 @G = external global i32 722 723The following example defines a thread-local global with the 724``initialexec`` TLS model: 725 726.. code-block:: llvm 727 728 @G = thread_local(initialexec) global i32 0, align 4 729 730.. _functionstructure: 731 732Functions 733--------- 734 735LLVM function definitions consist of the "``define``" keyword, an 736optional :ref:`linkage type <linkage>`, an optional :ref:`runtime preemption 737specifier <runtime_preemption_model>`, an optional :ref:`visibility 738style <visibility>`, an optional :ref:`DLL storage class <dllstorageclass>`, 739an optional :ref:`calling convention <callingconv>`, 740an optional ``unnamed_addr`` attribute, a return type, an optional 741:ref:`parameter attribute <paramattrs>` for the return type, a function 742name, a (possibly empty) argument list (each with optional :ref:`parameter 743attributes <paramattrs>`), optional :ref:`function attributes <fnattrs>`, 744an optional address space, an optional section, an optional alignment, 745an optional :ref:`comdat <langref_comdats>`, 746an optional :ref:`garbage collector name <gc>`, an optional :ref:`prefix <prefixdata>`, 747an optional :ref:`prologue <prologuedata>`, 748an optional :ref:`personality <personalityfn>`, 749an optional list of attached :ref:`metadata <metadata>`, 750an opening curly brace, a list of basic blocks, and a closing curly brace. 751 752LLVM function declarations consist of the "``declare``" keyword, an 753optional :ref:`linkage type <linkage>`, an optional :ref:`visibility style 754<visibility>`, an optional :ref:`DLL storage class <dllstorageclass>`, an 755optional :ref:`calling convention <callingconv>`, an optional ``unnamed_addr`` 756or ``local_unnamed_addr`` attribute, an optional address space, a return type, 757an optional :ref:`parameter attribute <paramattrs>` for the return type, a function name, a possibly 758empty list of arguments, an optional alignment, an optional :ref:`garbage 759collector name <gc>`, an optional :ref:`prefix <prefixdata>`, and an optional 760:ref:`prologue <prologuedata>`. 761 762A function definition contains a list of basic blocks, forming the CFG (Control 763Flow Graph) for the function. Each basic block may optionally start with a label 764(giving the basic block a symbol table entry), contains a list of instructions, 765and ends with a :ref:`terminator <terminators>` instruction (such as a branch or 766function return). If an explicit label name is not provided, a block is assigned 767an implicit numbered label, using the next value from the same counter as used 768for unnamed temporaries (:ref:`see above<identifiers>`). For example, if a 769function entry block does not have an explicit label, it will be assigned label 770"%0", then the first unnamed temporary in that block will be "%1", etc. If a 771numeric label is explicitly specified, it must match the numeric label that 772would be used implicitly. 773 774The first basic block in a function is special in two ways: it is 775immediately executed on entrance to the function, and it is not allowed 776to have predecessor basic blocks (i.e. there can not be any branches to 777the entry block of a function). Because the block can have no 778predecessors, it also cannot have any :ref:`PHI nodes <i_phi>`. 779 780LLVM allows an explicit section to be specified for functions. If the 781target supports it, it will emit functions to the section specified. 782Additionally, the function can be placed in a COMDAT. 783 784An explicit alignment may be specified for a function. If not present, 785or if the alignment is set to zero, the alignment of the function is set 786by the target to whatever it feels convenient. If an explicit alignment 787is specified, the function is forced to have at least that much 788alignment. All alignments must be a power of 2. 789 790If the ``unnamed_addr`` attribute is given, the address is known to not 791be significant and two identical functions can be merged. 792 793If the ``local_unnamed_addr`` attribute is given, the address is known to 794not be significant within the module. 795 796If an explicit address space is not given, it will default to the program 797address space from the :ref:`datalayout string<langref_datalayout>`. 798 799Syntax:: 800 801 define [linkage] [PreemptionSpecifier] [visibility] [DLLStorageClass] 802 [cconv] [ret attrs] 803 <ResultType> @<FunctionName> ([argument list]) 804 [(unnamed_addr|local_unnamed_addr)] [AddrSpace] [fn Attrs] 805 [section "name"] [comdat [($name)]] [align N] [gc] [prefix Constant] 806 [prologue Constant] [personality Constant] (!name !N)* { ... } 807 808The argument list is a comma separated sequence of arguments where each 809argument is of the following form: 810 811Syntax:: 812 813 <type> [parameter Attrs] [name] 814 815 816.. _langref_aliases: 817 818Aliases 819------- 820 821Aliases, unlike function or variables, don't create any new data. They 822are just a new symbol and metadata for an existing position. 823 824Aliases have a name and an aliasee that is either a global value or a 825constant expression. 826 827Aliases may have an optional :ref:`linkage type <linkage>`, an optional 828:ref:`runtime preemption specifier <runtime_preemption_model>`, an optional 829:ref:`visibility style <visibility>`, an optional :ref:`DLL storage class 830<dllstorageclass>` and an optional :ref:`tls model <tls_model>`. 831 832Syntax:: 833 834 @<Name> = [Linkage] [PreemptionSpecifier] [Visibility] [DLLStorageClass] [ThreadLocal] [(unnamed_addr|local_unnamed_addr)] alias <AliaseeTy>, <AliaseeTy>* @<Aliasee> 835 836The linkage must be one of ``private``, ``internal``, ``linkonce``, ``weak``, 837``linkonce_odr``, ``weak_odr``, ``external``. Note that some system linkers 838might not correctly handle dropping a weak symbol that is aliased. 839 840Aliases that are not ``unnamed_addr`` are guaranteed to have the same address as 841the aliasee expression. ``unnamed_addr`` ones are only guaranteed to point 842to the same content. 843 844If the ``local_unnamed_addr`` attribute is given, the address is known to 845not be significant within the module. 846 847Since aliases are only a second name, some restrictions apply, of which 848some can only be checked when producing an object file: 849 850* The expression defining the aliasee must be computable at assembly 851 time. Since it is just a name, no relocations can be used. 852 853* No alias in the expression can be weak as the possibility of the 854 intermediate alias being overridden cannot be represented in an 855 object file. 856 857* No global value in the expression can be a declaration, since that 858 would require a relocation, which is not possible. 859 860.. _langref_ifunc: 861 862IFuncs 863------- 864 865IFuncs, like as aliases, don't create any new data or func. They are just a new 866symbol that dynamic linker resolves at runtime by calling a resolver function. 867 868IFuncs have a name and a resolver that is a function called by dynamic linker 869that returns address of another function associated with the name. 870 871IFunc may have an optional :ref:`linkage type <linkage>` and an optional 872:ref:`visibility style <visibility>`. 873 874Syntax:: 875 876 @<Name> = [Linkage] [Visibility] ifunc <IFuncTy>, <ResolverTy>* @<Resolver> 877 878 879.. _langref_comdats: 880 881Comdats 882------- 883 884Comdat IR provides access to COFF and ELF object file COMDAT functionality. 885 886Comdats have a name which represents the COMDAT key. All global objects that 887specify this key will only end up in the final object file if the linker chooses 888that key over some other key. Aliases are placed in the same COMDAT that their 889aliasee computes to, if any. 890 891Comdats have a selection kind to provide input on how the linker should 892choose between keys in two different object files. 893 894Syntax:: 895 896 $<Name> = comdat SelectionKind 897 898The selection kind must be one of the following: 899 900``any`` 901 The linker may choose any COMDAT key, the choice is arbitrary. 902``exactmatch`` 903 The linker may choose any COMDAT key but the sections must contain the 904 same data. 905``largest`` 906 The linker will choose the section containing the largest COMDAT key. 907``noduplicates`` 908 The linker requires that only section with this COMDAT key exist. 909``samesize`` 910 The linker may choose any COMDAT key but the sections must contain the 911 same amount of data. 912 913Note that XCOFF and the Mach-O platform don't support COMDATs, and ELF and 914WebAssembly only support ``any`` as a selection kind. 915 916Here is an example of a COMDAT group where a function will only be selected if 917the COMDAT key's section is the largest: 918 919.. code-block:: text 920 921 $foo = comdat largest 922 @foo = global i32 2, comdat($foo) 923 924 define void @bar() comdat($foo) { 925 ret void 926 } 927 928As a syntactic sugar the ``$name`` can be omitted if the name is the same as 929the global name: 930 931.. code-block:: text 932 933 $foo = comdat any 934 @foo = global i32 2, comdat 935 936 937In a COFF object file, this will create a COMDAT section with selection kind 938``IMAGE_COMDAT_SELECT_LARGEST`` containing the contents of the ``@foo`` symbol 939and another COMDAT section with selection kind 940``IMAGE_COMDAT_SELECT_ASSOCIATIVE`` which is associated with the first COMDAT 941section and contains the contents of the ``@bar`` symbol. 942 943There are some restrictions on the properties of the global object. 944It, or an alias to it, must have the same name as the COMDAT group when 945targeting COFF. 946The contents and size of this object may be used during link-time to determine 947which COMDAT groups get selected depending on the selection kind. 948Because the name of the object must match the name of the COMDAT group, the 949linkage of the global object must not be local; local symbols can get renamed 950if a collision occurs in the symbol table. 951 952The combined use of COMDATS and section attributes may yield surprising results. 953For example: 954 955.. code-block:: text 956 957 $foo = comdat any 958 $bar = comdat any 959 @g1 = global i32 42, section "sec", comdat($foo) 960 @g2 = global i32 42, section "sec", comdat($bar) 961 962From the object file perspective, this requires the creation of two sections 963with the same name. This is necessary because both globals belong to different 964COMDAT groups and COMDATs, at the object file level, are represented by 965sections. 966 967Note that certain IR constructs like global variables and functions may 968create COMDATs in the object file in addition to any which are specified using 969COMDAT IR. This arises when the code generator is configured to emit globals 970in individual sections (e.g. when `-data-sections` or `-function-sections` 971is supplied to `llc`). 972 973.. _namedmetadatastructure: 974 975Named Metadata 976-------------- 977 978Named metadata is a collection of metadata. :ref:`Metadata 979nodes <metadata>` (but not metadata strings) are the only valid 980operands for a named metadata. 981 982#. Named metadata are represented as a string of characters with the 983 metadata prefix. The rules for metadata names are the same as for 984 identifiers, but quoted names are not allowed. ``"\xx"`` type escapes 985 are still valid, which allows any character to be part of a name. 986 987Syntax:: 988 989 ; Some unnamed metadata nodes, which are referenced by the named metadata. 990 !0 = !{!"zero"} 991 !1 = !{!"one"} 992 !2 = !{!"two"} 993 ; A named metadata. 994 !name = !{!0, !1, !2} 995 996.. _paramattrs: 997 998Parameter Attributes 999-------------------- 1000 1001The return type and each parameter of a function type may have a set of 1002*parameter attributes* associated with them. Parameter attributes are 1003used to communicate additional information about the result or 1004parameters of a function. Parameter attributes are considered to be part 1005of the function, not of the function type, so functions with different 1006parameter attributes can have the same function type. 1007 1008Parameter attributes are simple keywords that follow the type specified. 1009If multiple parameter attributes are needed, they are space separated. 1010For example: 1011 1012.. code-block:: llvm 1013 1014 declare i32 @printf(i8* noalias nocapture, ...) 1015 declare i32 @atoi(i8 zeroext) 1016 declare signext i8 @returns_signed_char() 1017 1018Note that any attributes for the function result (``nounwind``, 1019``readonly``) come immediately after the argument list. 1020 1021Currently, only the following parameter attributes are defined: 1022 1023``zeroext`` 1024 This indicates to the code generator that the parameter or return 1025 value should be zero-extended to the extent required by the target's 1026 ABI by the caller (for a parameter) or the callee (for a return value). 1027``signext`` 1028 This indicates to the code generator that the parameter or return 1029 value should be sign-extended to the extent required by the target's 1030 ABI (which is usually 32-bits) by the caller (for a parameter) or 1031 the callee (for a return value). 1032``inreg`` 1033 This indicates that this parameter or return value should be treated 1034 in a special target-dependent fashion while emitting code for 1035 a function call or return (usually, by putting it in a register as 1036 opposed to memory, though some targets use it to distinguish between 1037 two different kinds of registers). Use of this attribute is 1038 target-specific. 1039``byval`` or ``byval(<ty>)`` 1040 This indicates that the pointer parameter should really be passed by 1041 value to the function. The attribute implies that a hidden copy of 1042 the pointee is made between the caller and the callee, so the callee 1043 is unable to modify the value in the caller. This attribute is only 1044 valid on LLVM pointer arguments. It is generally used to pass 1045 structs and arrays by value, but is also valid on pointers to 1046 scalars. The copy is considered to belong to the caller not the 1047 callee (for example, ``readonly`` functions should not write to 1048 ``byval`` parameters). This is not a valid attribute for return 1049 values. 1050 1051 The byval attribute also supports an optional type argument, which must be 1052 the same as the pointee type of the argument. 1053 1054 The byval attribute also supports specifying an alignment with the 1055 align attribute. It indicates the alignment of the stack slot to 1056 form and the known alignment of the pointer specified to the call 1057 site. If the alignment is not specified, then the code generator 1058 makes a target-specific assumption. 1059``preallocated(<ty>)`` 1060 This indicates that the pointer parameter should really be passed by 1061 value to the function, and that the pointer parameter's pointee has 1062 already been initialized before the call instruction. This attribute 1063 is only valid on LLVM pointer arguments. The argument must be the value 1064 returned by the appropriate 1065 :ref:`llvm.call.preallocated.arg<int_call_preallocated_arg>`, although is 1066 ignored during codegen. 1067 1068 Any function call with a ``preallocated`` attribute in any parameter 1069 must have a ``"preallocated"`` operand bundle. 1070 1071 The preallocated attribute requires a type argument, which must be 1072 the same as the pointee type of the argument. 1073 1074 The preallocated attribute also supports specifying an alignment with the 1075 align attribute. It indicates the alignment of the stack slot to 1076 form and the known alignment of the pointer specified to the call 1077 site. If the alignment is not specified, then the code generator 1078 makes a target-specific assumption. 1079 1080.. _attr_inalloca: 1081 1082``inalloca`` 1083 1084 The ``inalloca`` argument attribute allows the caller to take the 1085 address of outgoing stack arguments. An ``inalloca`` argument must 1086 be a pointer to stack memory produced by an ``alloca`` instruction. 1087 The alloca, or argument allocation, must also be tagged with the 1088 inalloca keyword. Only the last argument may have the ``inalloca`` 1089 attribute, and that argument is guaranteed to be passed in memory. 1090 1091 An argument allocation may be used by a call at most once because 1092 the call may deallocate it. The ``inalloca`` attribute cannot be 1093 used in conjunction with other attributes that affect argument 1094 storage, like ``inreg``, ``nest``, ``sret``, or ``byval``. The 1095 ``inalloca`` attribute also disables LLVM's implicit lowering of 1096 large aggregate return values, which means that frontend authors 1097 must lower them with ``sret`` pointers. 1098 1099 When the call site is reached, the argument allocation must have 1100 been the most recent stack allocation that is still live, or the 1101 behavior is undefined. It is possible to allocate additional stack 1102 space after an argument allocation and before its call site, but it 1103 must be cleared off with :ref:`llvm.stackrestore 1104 <int_stackrestore>`. 1105 1106 See :doc:`InAlloca` for more information on how to use this 1107 attribute. 1108 1109``sret`` 1110 This indicates that the pointer parameter specifies the address of a 1111 structure that is the return value of the function in the source 1112 program. This pointer must be guaranteed by the caller to be valid: 1113 loads and stores to the structure may be assumed by the callee not 1114 to trap and to be properly aligned. This is not a valid attribute 1115 for return values. 1116 1117.. _attr_align: 1118 1119``align <n>`` 1120 This indicates that the pointer value may be assumed by the optimizer to 1121 have the specified alignment. If the pointer value does not have the 1122 specified alignment, behavior is undefined. 1123 1124 Note that this attribute has additional semantics when combined with the 1125 ``byval`` attribute, which are documented there. 1126 1127.. _noalias: 1128 1129``noalias`` 1130 This indicates that memory locations accessed via pointer values 1131 :ref:`based <pointeraliasing>` on the argument or return value are not also 1132 accessed, during the execution of the function, via pointer values not 1133 *based* on the argument or return value. This guarantee only holds for 1134 memory locations that are *modified*, by any means, during the execution of 1135 the function. The attribute on a return value also has additional semantics 1136 described below. The caller shares the responsibility with the callee for 1137 ensuring that these requirements are met. For further details, please see 1138 the discussion of the NoAlias response in :ref:`alias analysis <Must, May, 1139 or No>`. 1140 1141 Note that this definition of ``noalias`` is intentionally similar 1142 to the definition of ``restrict`` in C99 for function arguments. 1143 1144 For function return values, C99's ``restrict`` is not meaningful, 1145 while LLVM's ``noalias`` is. Furthermore, the semantics of the ``noalias`` 1146 attribute on return values are stronger than the semantics of the attribute 1147 when used on function arguments. On function return values, the ``noalias`` 1148 attribute indicates that the function acts like a system memory allocation 1149 function, returning a pointer to allocated storage disjoint from the 1150 storage for any other object accessible to the caller. 1151 1152``nocapture`` 1153 This indicates that the callee does not make any copies of the 1154 pointer that outlive the callee itself. This is not a valid 1155 attribute for return values. Addresses used in volatile operations 1156 are considered to be captured. 1157 1158``nofree`` 1159 This indicates that callee does not free the pointer argument. This is not 1160 a valid attribute for return values. 1161 1162.. _nest: 1163 1164``nest`` 1165 This indicates that the pointer parameter can be excised using the 1166 :ref:`trampoline intrinsics <int_trampoline>`. This is not a valid 1167 attribute for return values and can only be applied to one parameter. 1168 1169``returned`` 1170 This indicates that the function always returns the argument as its return 1171 value. This is a hint to the optimizer and code generator used when 1172 generating the caller, allowing value propagation, tail call optimization, 1173 and omission of register saves and restores in some cases; it is not 1174 checked or enforced when generating the callee. The parameter and the 1175 function return type must be valid operands for the 1176 :ref:`bitcast instruction <i_bitcast>`. This is not a valid attribute for 1177 return values and can only be applied to one parameter. 1178 1179``nonnull`` 1180 This indicates that the parameter or return pointer is not null. This 1181 attribute may only be applied to pointer typed parameters. This is not 1182 checked or enforced by LLVM; if the parameter or return pointer is null, 1183 the behavior is undefined. 1184 1185``dereferenceable(<n>)`` 1186 This indicates that the parameter or return pointer is dereferenceable. This 1187 attribute may only be applied to pointer typed parameters. A pointer that 1188 is dereferenceable can be loaded from speculatively without a risk of 1189 trapping. The number of bytes known to be dereferenceable must be provided 1190 in parentheses. It is legal for the number of bytes to be less than the 1191 size of the pointee type. The ``nonnull`` attribute does not imply 1192 dereferenceability (consider a pointer to one element past the end of an 1193 array), however ``dereferenceable(<n>)`` does imply ``nonnull`` in 1194 ``addrspace(0)`` (which is the default address space). 1195 1196``dereferenceable_or_null(<n>)`` 1197 This indicates that the parameter or return value isn't both 1198 non-null and non-dereferenceable (up to ``<n>`` bytes) at the same 1199 time. All non-null pointers tagged with 1200 ``dereferenceable_or_null(<n>)`` are ``dereferenceable(<n>)``. 1201 For address space 0 ``dereferenceable_or_null(<n>)`` implies that 1202 a pointer is exactly one of ``dereferenceable(<n>)`` or ``null``, 1203 and in other address spaces ``dereferenceable_or_null(<n>)`` 1204 implies that a pointer is at least one of ``dereferenceable(<n>)`` 1205 or ``null`` (i.e. it may be both ``null`` and 1206 ``dereferenceable(<n>)``). This attribute may only be applied to 1207 pointer typed parameters. 1208 1209``swiftself`` 1210 This indicates that the parameter is the self/context parameter. This is not 1211 a valid attribute for return values and can only be applied to one 1212 parameter. 1213 1214``swifterror`` 1215 This attribute is motivated to model and optimize Swift error handling. It 1216 can be applied to a parameter with pointer to pointer type or a 1217 pointer-sized alloca. At the call site, the actual argument that corresponds 1218 to a ``swifterror`` parameter has to come from a ``swifterror`` alloca or 1219 the ``swifterror`` parameter of the caller. A ``swifterror`` value (either 1220 the parameter or the alloca) can only be loaded and stored from, or used as 1221 a ``swifterror`` argument. This is not a valid attribute for return values 1222 and can only be applied to one parameter. 1223 1224 These constraints allow the calling convention to optimize access to 1225 ``swifterror`` variables by associating them with a specific register at 1226 call boundaries rather than placing them in memory. Since this does change 1227 the calling convention, a function which uses the ``swifterror`` attribute 1228 on a parameter is not ABI-compatible with one which does not. 1229 1230 These constraints also allow LLVM to assume that a ``swifterror`` argument 1231 does not alias any other memory visible within a function and that a 1232 ``swifterror`` alloca passed as an argument does not escape. 1233 1234``immarg`` 1235 This indicates the parameter is required to be an immediate 1236 value. This must be a trivial immediate integer or floating-point 1237 constant. Undef or constant expressions are not valid. This is 1238 only valid on intrinsic declarations and cannot be applied to a 1239 call site or arbitrary function. 1240 1241.. _gc: 1242 1243Garbage Collector Strategy Names 1244-------------------------------- 1245 1246Each function may specify a garbage collector strategy name, which is simply a 1247string: 1248 1249.. code-block:: llvm 1250 1251 define void @f() gc "name" { ... } 1252 1253The supported values of *name* includes those :ref:`built in to LLVM 1254<builtin-gc-strategies>` and any provided by loaded plugins. Specifying a GC 1255strategy will cause the compiler to alter its output in order to support the 1256named garbage collection algorithm. Note that LLVM itself does not contain a 1257garbage collector, this functionality is restricted to generating machine code 1258which can interoperate with a collector provided externally. 1259 1260.. _prefixdata: 1261 1262Prefix Data 1263----------- 1264 1265Prefix data is data associated with a function which the code 1266generator will emit immediately before the function's entrypoint. 1267The purpose of this feature is to allow frontends to associate 1268language-specific runtime metadata with specific functions and make it 1269available through the function pointer while still allowing the 1270function pointer to be called. 1271 1272To access the data for a given function, a program may bitcast the 1273function pointer to a pointer to the constant's type and dereference 1274index -1. This implies that the IR symbol points just past the end of 1275the prefix data. For instance, take the example of a function annotated 1276with a single ``i32``, 1277 1278.. code-block:: llvm 1279 1280 define void @f() prefix i32 123 { ... } 1281 1282The prefix data can be referenced as, 1283 1284.. code-block:: llvm 1285 1286 %0 = bitcast void* () @f to i32* 1287 %a = getelementptr inbounds i32, i32* %0, i32 -1 1288 %b = load i32, i32* %a 1289 1290Prefix data is laid out as if it were an initializer for a global variable 1291of the prefix data's type. The function will be placed such that the 1292beginning of the prefix data is aligned. This means that if the size 1293of the prefix data is not a multiple of the alignment size, the 1294function's entrypoint will not be aligned. If alignment of the 1295function's entrypoint is desired, padding must be added to the prefix 1296data. 1297 1298A function may have prefix data but no body. This has similar semantics 1299to the ``available_externally`` linkage in that the data may be used by the 1300optimizers but will not be emitted in the object file. 1301 1302.. _prologuedata: 1303 1304Prologue Data 1305------------- 1306 1307The ``prologue`` attribute allows arbitrary code (encoded as bytes) to 1308be inserted prior to the function body. This can be used for enabling 1309function hot-patching and instrumentation. 1310 1311To maintain the semantics of ordinary function calls, the prologue data must 1312have a particular format. Specifically, it must begin with a sequence of 1313bytes which decode to a sequence of machine instructions, valid for the 1314module's target, which transfer control to the point immediately succeeding 1315the prologue data, without performing any other visible action. This allows 1316the inliner and other passes to reason about the semantics of the function 1317definition without needing to reason about the prologue data. Obviously this 1318makes the format of the prologue data highly target dependent. 1319 1320A trivial example of valid prologue data for the x86 architecture is ``i8 144``, 1321which encodes the ``nop`` instruction: 1322 1323.. code-block:: text 1324 1325 define void @f() prologue i8 144 { ... } 1326 1327Generally prologue data can be formed by encoding a relative branch instruction 1328which skips the metadata, as in this example of valid prologue data for the 1329x86_64 architecture, where the first two bytes encode ``jmp .+10``: 1330 1331.. code-block:: text 1332 1333 %0 = type <{ i8, i8, i8* }> 1334 1335 define void @f() prologue %0 <{ i8 235, i8 8, i8* @md}> { ... } 1336 1337A function may have prologue data but no body. This has similar semantics 1338to the ``available_externally`` linkage in that the data may be used by the 1339optimizers but will not be emitted in the object file. 1340 1341.. _personalityfn: 1342 1343Personality Function 1344-------------------- 1345 1346The ``personality`` attribute permits functions to specify what function 1347to use for exception handling. 1348 1349.. _attrgrp: 1350 1351Attribute Groups 1352---------------- 1353 1354Attribute groups are groups of attributes that are referenced by objects within 1355the IR. They are important for keeping ``.ll`` files readable, because a lot of 1356functions will use the same set of attributes. In the degenerative case of a 1357``.ll`` file that corresponds to a single ``.c`` file, the single attribute 1358group will capture the important command line flags used to build that file. 1359 1360An attribute group is a module-level object. To use an attribute group, an 1361object references the attribute group's ID (e.g. ``#37``). An object may refer 1362to more than one attribute group. In that situation, the attributes from the 1363different groups are merged. 1364 1365Here is an example of attribute groups for a function that should always be 1366inlined, has a stack alignment of 4, and which shouldn't use SSE instructions: 1367 1368.. code-block:: llvm 1369 1370 ; Target-independent attributes: 1371 attributes #0 = { alwaysinline alignstack=4 } 1372 1373 ; Target-dependent attributes: 1374 attributes #1 = { "no-sse" } 1375 1376 ; Function @f has attributes: alwaysinline, alignstack=4, and "no-sse". 1377 define void @f() #0 #1 { ... } 1378 1379.. _fnattrs: 1380 1381Function Attributes 1382------------------- 1383 1384Function attributes are set to communicate additional information about 1385a function. Function attributes are considered to be part of the 1386function, not of the function type, so functions with different function 1387attributes can have the same function type. 1388 1389Function attributes are simple keywords that follow the type specified. 1390If multiple attributes are needed, they are space separated. For 1391example: 1392 1393.. code-block:: llvm 1394 1395 define void @f() noinline { ... } 1396 define void @f() alwaysinline { ... } 1397 define void @f() alwaysinline optsize { ... } 1398 define void @f() optsize { ... } 1399 1400``alignstack(<n>)`` 1401 This attribute indicates that, when emitting the prologue and 1402 epilogue, the backend should forcibly align the stack pointer. 1403 Specify the desired alignment, which must be a power of two, in 1404 parentheses. 1405``allocsize(<EltSizeParam>[, <NumEltsParam>])`` 1406 This attribute indicates that the annotated function will always return at 1407 least a given number of bytes (or null). Its arguments are zero-indexed 1408 parameter numbers; if one argument is provided, then it's assumed that at 1409 least ``CallSite.Args[EltSizeParam]`` bytes will be available at the 1410 returned pointer. If two are provided, then it's assumed that 1411 ``CallSite.Args[EltSizeParam] * CallSite.Args[NumEltsParam]`` bytes are 1412 available. The referenced parameters must be integer types. No assumptions 1413 are made about the contents of the returned block of memory. 1414``alwaysinline`` 1415 This attribute indicates that the inliner should attempt to inline 1416 this function into callers whenever possible, ignoring any active 1417 inlining size threshold for this caller. 1418``builtin`` 1419 This indicates that the callee function at a call site should be 1420 recognized as a built-in function, even though the function's declaration 1421 uses the ``nobuiltin`` attribute. This is only valid at call sites for 1422 direct calls to functions that are declared with the ``nobuiltin`` 1423 attribute. 1424``cold`` 1425 This attribute indicates that this function is rarely called. When 1426 computing edge weights, basic blocks post-dominated by a cold 1427 function call are also considered to be cold; and, thus, given low 1428 weight. 1429``convergent`` 1430 In some parallel execution models, there exist operations that cannot be 1431 made control-dependent on any additional values. We call such operations 1432 ``convergent``, and mark them with this attribute. 1433 1434 The ``convergent`` attribute may appear on functions or call/invoke 1435 instructions. When it appears on a function, it indicates that calls to 1436 this function should not be made control-dependent on additional values. 1437 For example, the intrinsic ``llvm.nvvm.barrier0`` is ``convergent``, so 1438 calls to this intrinsic cannot be made control-dependent on additional 1439 values. 1440 1441 When it appears on a call/invoke, the ``convergent`` attribute indicates 1442 that we should treat the call as though we're calling a convergent 1443 function. This is particularly useful on indirect calls; without this we 1444 may treat such calls as though the target is non-convergent. 1445 1446 The optimizer may remove the ``convergent`` attribute on functions when it 1447 can prove that the function does not execute any convergent operations. 1448 Similarly, the optimizer may remove ``convergent`` on calls/invokes when it 1449 can prove that the call/invoke cannot call a convergent function. 1450``inaccessiblememonly`` 1451 This attribute indicates that the function may only access memory that 1452 is not accessible by the module being compiled. This is a weaker form 1453 of ``readnone``. If the function reads or writes other memory, the 1454 behavior is undefined. 1455``inaccessiblemem_or_argmemonly`` 1456 This attribute indicates that the function may only access memory that is 1457 either not accessible by the module being compiled, or is pointed to 1458 by its pointer arguments. This is a weaker form of ``argmemonly``. If the 1459 function reads or writes other memory, the behavior is undefined. 1460``inlinehint`` 1461 This attribute indicates that the source code contained a hint that 1462 inlining this function is desirable (such as the "inline" keyword in 1463 C/C++). It is just a hint; it imposes no requirements on the 1464 inliner. 1465``jumptable`` 1466 This attribute indicates that the function should be added to a 1467 jump-instruction table at code-generation time, and that all address-taken 1468 references to this function should be replaced with a reference to the 1469 appropriate jump-instruction-table function pointer. Note that this creates 1470 a new pointer for the original function, which means that code that depends 1471 on function-pointer identity can break. So, any function annotated with 1472 ``jumptable`` must also be ``unnamed_addr``. 1473``minsize`` 1474 This attribute suggests that optimization passes and code generator 1475 passes make choices that keep the code size of this function as small 1476 as possible and perform optimizations that may sacrifice runtime 1477 performance in order to minimize the size of the generated code. 1478``naked`` 1479 This attribute disables prologue / epilogue emission for the 1480 function. This can have very system-specific consequences. 1481``"no-inline-line-tables"`` 1482 When this attribute is set to true, the inliner discards source locations 1483 when inlining code and instead uses the source location of the call site. 1484 Breakpoints set on code that was inlined into the current function will 1485 not fire during the execution of the inlined call sites. If the debugger 1486 stops inside an inlined call site, it will appear to be stopped at the 1487 outermost inlined call site. 1488``no-jump-tables`` 1489 When this attribute is set to true, the jump tables and lookup tables that 1490 can be generated from a switch case lowering are disabled. 1491``nobuiltin`` 1492 This indicates that the callee function at a call site is not recognized as 1493 a built-in function. LLVM will retain the original call and not replace it 1494 with equivalent code based on the semantics of the built-in function, unless 1495 the call site uses the ``builtin`` attribute. This is valid at call sites 1496 and on function declarations and definitions. 1497``noduplicate`` 1498 This attribute indicates that calls to the function cannot be 1499 duplicated. A call to a ``noduplicate`` function may be moved 1500 within its parent function, but may not be duplicated within 1501 its parent function. 1502 1503 A function containing a ``noduplicate`` call may still 1504 be an inlining candidate, provided that the call is not 1505 duplicated by inlining. That implies that the function has 1506 internal linkage and only has one call site, so the original 1507 call is dead after inlining. 1508``nofree`` 1509 This function attribute indicates that the function does not, directly or 1510 indirectly, call a memory-deallocation function (free, for example). As a 1511 result, uncaptured pointers that are known to be dereferenceable prior to a 1512 call to a function with the ``nofree`` attribute are still known to be 1513 dereferenceable after the call (the capturing condition is necessary in 1514 environments where the function might communicate the pointer to another thread 1515 which then deallocates the memory). 1516``noimplicitfloat`` 1517 This attributes disables implicit floating-point instructions. 1518``noinline`` 1519 This attribute indicates that the inliner should never inline this 1520 function in any situation. This attribute may not be used together 1521 with the ``alwaysinline`` attribute. 1522``nonlazybind`` 1523 This attribute suppresses lazy symbol binding for the function. This 1524 may make calls to the function faster, at the cost of extra program 1525 startup time if the function is not called during program startup. 1526``noredzone`` 1527 This attribute indicates that the code generator should not use a 1528 red zone, even if the target-specific ABI normally permits it. 1529``indirect-tls-seg-refs`` 1530 This attribute indicates that the code generator should not use 1531 direct TLS access through segment registers, even if the 1532 target-specific ABI normally permits it. 1533``noreturn`` 1534 This function attribute indicates that the function never returns 1535 normally, hence through a return instruction. This produces undefined 1536 behavior at runtime if the function ever does dynamically return. Annotated 1537 functions may still raise an exception, i.a., ``nounwind`` is not implied. 1538``norecurse`` 1539 This function attribute indicates that the function does not call itself 1540 either directly or indirectly down any possible call path. This produces 1541 undefined behavior at runtime if the function ever does recurse. 1542``willreturn`` 1543 This function attribute indicates that a call of this function will 1544 either exhibit undefined behavior or comes back and continues execution 1545 at a point in the existing call stack that includes the current invocation. 1546 Annotated functions may still raise an exception, i.a., ``nounwind`` is not implied. 1547 If an invocation of an annotated function does not return control back 1548 to a point in the call stack, the behavior is undefined. 1549``nosync`` 1550 This function attribute indicates that the function does not communicate 1551 (synchronize) with another thread through memory or other well-defined means. 1552 Synchronization is considered possible in the presence of `atomic` accesses 1553 that enforce an order, thus not "unordered" and "monotonic", `volatile` accesses, 1554 as well as `convergent` function calls. Note that through `convergent` function calls 1555 non-memory communication, e.g., cross-lane operations, are possible and are also 1556 considered synchronization. However `convergent` does not contradict `nosync`. 1557 If an annotated function does ever synchronize with another thread, 1558 the behavior is undefined. 1559``nounwind`` 1560 This function attribute indicates that the function never raises an 1561 exception. If the function does raise an exception, its runtime 1562 behavior is undefined. However, functions marked nounwind may still 1563 trap or generate asynchronous exceptions. Exception handling schemes 1564 that are recognized by LLVM to handle asynchronous exceptions, such 1565 as SEH, will still provide their implementation defined semantics. 1566``"null-pointer-is-valid"`` 1567 If ``"null-pointer-is-valid"`` is set to ``"true"``, then ``null`` address 1568 in address-space 0 is considered to be a valid address for memory loads and 1569 stores. Any analysis or optimization should not treat dereferencing a 1570 pointer to ``null`` as undefined behavior in this function. 1571 Note: Comparing address of a global variable to ``null`` may still 1572 evaluate to false because of a limitation in querying this attribute inside 1573 constant expressions. 1574``optforfuzzing`` 1575 This attribute indicates that this function should be optimized 1576 for maximum fuzzing signal. 1577``optnone`` 1578 This function attribute indicates that most optimization passes will skip 1579 this function, with the exception of interprocedural optimization passes. 1580 Code generation defaults to the "fast" instruction selector. 1581 This attribute cannot be used together with the ``alwaysinline`` 1582 attribute; this attribute is also incompatible 1583 with the ``minsize`` attribute and the ``optsize`` attribute. 1584 1585 This attribute requires the ``noinline`` attribute to be specified on 1586 the function as well, so the function is never inlined into any caller. 1587 Only functions with the ``alwaysinline`` attribute are valid 1588 candidates for inlining into the body of this function. 1589``optsize`` 1590 This attribute suggests that optimization passes and code generator 1591 passes make choices that keep the code size of this function low, 1592 and otherwise do optimizations specifically to reduce code size as 1593 long as they do not significantly impact runtime performance. 1594``"patchable-function"`` 1595 This attribute tells the code generator that the code 1596 generated for this function needs to follow certain conventions that 1597 make it possible for a runtime function to patch over it later. 1598 The exact effect of this attribute depends on its string value, 1599 for which there currently is one legal possibility: 1600 1601 * ``"prologue-short-redirect"`` - This style of patchable 1602 function is intended to support patching a function prologue to 1603 redirect control away from the function in a thread safe 1604 manner. It guarantees that the first instruction of the 1605 function will be large enough to accommodate a short jump 1606 instruction, and will be sufficiently aligned to allow being 1607 fully changed via an atomic compare-and-swap instruction. 1608 While the first requirement can be satisfied by inserting large 1609 enough NOP, LLVM can and will try to re-purpose an existing 1610 instruction (i.e. one that would have to be emitted anyway) as 1611 the patchable instruction larger than a short jump. 1612 1613 ``"prologue-short-redirect"`` is currently only supported on 1614 x86-64. 1615 1616 This attribute by itself does not imply restrictions on 1617 inter-procedural optimizations. All of the semantic effects the 1618 patching may have to be separately conveyed via the linkage type. 1619``"probe-stack"`` 1620 This attribute indicates that the function will trigger a guard region 1621 in the end of the stack. It ensures that accesses to the stack must be 1622 no further apart than the size of the guard region to a previous 1623 access of the stack. It takes one required string value, the name of 1624 the stack probing function that will be called. 1625 1626 If a function that has a ``"probe-stack"`` attribute is inlined into 1627 a function with another ``"probe-stack"`` attribute, the resulting 1628 function has the ``"probe-stack"`` attribute of the caller. If a 1629 function that has a ``"probe-stack"`` attribute is inlined into a 1630 function that has no ``"probe-stack"`` attribute at all, the resulting 1631 function has the ``"probe-stack"`` attribute of the callee. 1632``readnone`` 1633 On a function, this attribute indicates that the function computes its 1634 result (or decides to unwind an exception) based strictly on its arguments, 1635 without dereferencing any pointer arguments or otherwise accessing 1636 any mutable state (e.g. memory, control registers, etc) visible to 1637 caller functions. It does not write through any pointer arguments 1638 (including ``byval`` arguments) and never changes any state visible 1639 to callers. This means while it cannot unwind exceptions by calling 1640 the ``C++`` exception throwing methods (since they write to memory), there may 1641 be non-``C++`` mechanisms that throw exceptions without writing to LLVM 1642 visible memory. 1643 1644 On an argument, this attribute indicates that the function does not 1645 dereference that pointer argument, even though it may read or write the 1646 memory that the pointer points to if accessed through other pointers. 1647 1648 If a readnone function reads or writes memory visible to the program, or 1649 has other side-effects, the behavior is undefined. If a function reads from 1650 or writes to a readnone pointer argument, the behavior is undefined. 1651``readonly`` 1652 On a function, this attribute indicates that the function does not write 1653 through any pointer arguments (including ``byval`` arguments) or otherwise 1654 modify any state (e.g. memory, control registers, etc) visible to 1655 caller functions. It may dereference pointer arguments and read 1656 state that may be set in the caller. A readonly function always 1657 returns the same value (or unwinds an exception identically) when 1658 called with the same set of arguments and global state. This means while it 1659 cannot unwind exceptions by calling the ``C++`` exception throwing methods 1660 (since they write to memory), there may be non-``C++`` mechanisms that throw 1661 exceptions without writing to LLVM visible memory. 1662 1663 On an argument, this attribute indicates that the function does not write 1664 through this pointer argument, even though it may write to the memory that 1665 the pointer points to. 1666 1667 If a readonly function writes memory visible to the program, or 1668 has other side-effects, the behavior is undefined. If a function writes to 1669 a readonly pointer argument, the behavior is undefined. 1670``"stack-probe-size"`` 1671 This attribute controls the behavior of stack probes: either 1672 the ``"probe-stack"`` attribute, or ABI-required stack probes, if any. 1673 It defines the size of the guard region. It ensures that if the function 1674 may use more stack space than the size of the guard region, stack probing 1675 sequence will be emitted. It takes one required integer value, which 1676 is 4096 by default. 1677 1678 If a function that has a ``"stack-probe-size"`` attribute is inlined into 1679 a function with another ``"stack-probe-size"`` attribute, the resulting 1680 function has the ``"stack-probe-size"`` attribute that has the lower 1681 numeric value. If a function that has a ``"stack-probe-size"`` attribute is 1682 inlined into a function that has no ``"stack-probe-size"`` attribute 1683 at all, the resulting function has the ``"stack-probe-size"`` attribute 1684 of the callee. 1685``"no-stack-arg-probe"`` 1686 This attribute disables ABI-required stack probes, if any. 1687``writeonly`` 1688 On a function, this attribute indicates that the function may write to but 1689 does not read from memory. 1690 1691 On an argument, this attribute indicates that the function may write to but 1692 does not read through this pointer argument (even though it may read from 1693 the memory that the pointer points to). 1694 1695 If a writeonly function reads memory visible to the program, or 1696 has other side-effects, the behavior is undefined. If a function reads 1697 from a writeonly pointer argument, the behavior is undefined. 1698``argmemonly`` 1699 This attribute indicates that the only memory accesses inside function are 1700 loads and stores from objects pointed to by its pointer-typed arguments, 1701 with arbitrary offsets. Or in other words, all memory operations in the 1702 function can refer to memory only using pointers based on its function 1703 arguments. 1704 1705 Note that ``argmemonly`` can be used together with ``readonly`` attribute 1706 in order to specify that function reads only from its arguments. 1707 1708 If an argmemonly function reads or writes memory other than the pointer 1709 arguments, or has other side-effects, the behavior is undefined. 1710``returns_twice`` 1711 This attribute indicates that this function can return twice. The C 1712 ``setjmp`` is an example of such a function. The compiler disables 1713 some optimizations (like tail calls) in the caller of these 1714 functions. 1715``safestack`` 1716 This attribute indicates that 1717 `SafeStack <https://clang.llvm.org/docs/SafeStack.html>`_ 1718 protection is enabled for this function. 1719 1720 If a function that has a ``safestack`` attribute is inlined into a 1721 function that doesn't have a ``safestack`` attribute or which has an 1722 ``ssp``, ``sspstrong`` or ``sspreq`` attribute, then the resulting 1723 function will have a ``safestack`` attribute. 1724``sanitize_address`` 1725 This attribute indicates that AddressSanitizer checks 1726 (dynamic address safety analysis) are enabled for this function. 1727``sanitize_memory`` 1728 This attribute indicates that MemorySanitizer checks (dynamic detection 1729 of accesses to uninitialized memory) are enabled for this function. 1730``sanitize_thread`` 1731 This attribute indicates that ThreadSanitizer checks 1732 (dynamic thread safety analysis) are enabled for this function. 1733``sanitize_hwaddress`` 1734 This attribute indicates that HWAddressSanitizer checks 1735 (dynamic address safety analysis based on tagged pointers) are enabled for 1736 this function. 1737``sanitize_memtag`` 1738 This attribute indicates that MemTagSanitizer checks 1739 (dynamic address safety analysis based on Armv8 MTE) are enabled for 1740 this function. 1741``speculative_load_hardening`` 1742 This attribute indicates that 1743 `Speculative Load Hardening <https://llvm.org/docs/SpeculativeLoadHardening.html>`_ 1744 should be enabled for the function body. 1745 1746 Speculative Load Hardening is a best-effort mitigation against 1747 information leak attacks that make use of control flow 1748 miss-speculation - specifically miss-speculation of whether a branch 1749 is taken or not. Typically vulnerabilities enabling such attacks are 1750 classified as "Spectre variant #1". Notably, this does not attempt to 1751 mitigate against miss-speculation of branch target, classified as 1752 "Spectre variant #2" vulnerabilities. 1753 1754 When inlining, the attribute is sticky. Inlining a function that carries 1755 this attribute will cause the caller to gain the attribute. This is intended 1756 to provide a maximally conservative model where the code in a function 1757 annotated with this attribute will always (even after inlining) end up 1758 hardened. 1759``speculatable`` 1760 This function attribute indicates that the function does not have any 1761 effects besides calculating its result and does not have undefined behavior. 1762 Note that ``speculatable`` is not enough to conclude that along any 1763 particular execution path the number of calls to this function will not be 1764 externally observable. This attribute is only valid on functions 1765 and declarations, not on individual call sites. If a function is 1766 incorrectly marked as speculatable and really does exhibit 1767 undefined behavior, the undefined behavior may be observed even 1768 if the call site is dead code. 1769 1770``ssp`` 1771 This attribute indicates that the function should emit a stack 1772 smashing protector. It is in the form of a "canary" --- a random value 1773 placed on the stack before the local variables that's checked upon 1774 return from the function to see if it has been overwritten. A 1775 heuristic is used to determine if a function needs stack protectors 1776 or not. The heuristic used will enable protectors for functions with: 1777 1778 - Character arrays larger than ``ssp-buffer-size`` (default 8). 1779 - Aggregates containing character arrays larger than ``ssp-buffer-size``. 1780 - Calls to alloca() with variable sizes or constant sizes greater than 1781 ``ssp-buffer-size``. 1782 1783 Variables that are identified as requiring a protector will be arranged 1784 on the stack such that they are adjacent to the stack protector guard. 1785 1786 If a function that has an ``ssp`` attribute is inlined into a 1787 function that doesn't have an ``ssp`` attribute, then the resulting 1788 function will have an ``ssp`` attribute. 1789``sspreq`` 1790 This attribute indicates that the function should *always* emit a 1791 stack smashing protector. This overrides the ``ssp`` function 1792 attribute. 1793 1794 Variables that are identified as requiring a protector will be arranged 1795 on the stack such that they are adjacent to the stack protector guard. 1796 The specific layout rules are: 1797 1798 #. Large arrays and structures containing large arrays 1799 (``>= ssp-buffer-size``) are closest to the stack protector. 1800 #. Small arrays and structures containing small arrays 1801 (``< ssp-buffer-size``) are 2nd closest to the protector. 1802 #. Variables that have had their address taken are 3rd closest to the 1803 protector. 1804 1805 If a function that has an ``sspreq`` attribute is inlined into a 1806 function that doesn't have an ``sspreq`` attribute or which has an 1807 ``ssp`` or ``sspstrong`` attribute, then the resulting function will have 1808 an ``sspreq`` attribute. 1809``sspstrong`` 1810 This attribute indicates that the function should emit a stack smashing 1811 protector. This attribute causes a strong heuristic to be used when 1812 determining if a function needs stack protectors. The strong heuristic 1813 will enable protectors for functions with: 1814 1815 - Arrays of any size and type 1816 - Aggregates containing an array of any size and type. 1817 - Calls to alloca(). 1818 - Local variables that have had their address taken. 1819 1820 Variables that are identified as requiring a protector will be arranged 1821 on the stack such that they are adjacent to the stack protector guard. 1822 The specific layout rules are: 1823 1824 #. Large arrays and structures containing large arrays 1825 (``>= ssp-buffer-size``) are closest to the stack protector. 1826 #. Small arrays and structures containing small arrays 1827 (``< ssp-buffer-size``) are 2nd closest to the protector. 1828 #. Variables that have had their address taken are 3rd closest to the 1829 protector. 1830 1831 This overrides the ``ssp`` function attribute. 1832 1833 If a function that has an ``sspstrong`` attribute is inlined into a 1834 function that doesn't have an ``sspstrong`` attribute, then the 1835 resulting function will have an ``sspstrong`` attribute. 1836``strictfp`` 1837 This attribute indicates that the function was called from a scope that 1838 requires strict floating-point semantics. LLVM will not attempt any 1839 optimizations that require assumptions about the floating-point rounding 1840 mode or that might alter the state of floating-point status flags that 1841 might otherwise be set or cleared by calling this function. LLVM will 1842 not introduce any new floating-point instructions that may trap. 1843 1844``"denormal-fp-math"`` 1845 This indicates the denormal (subnormal) handling that may be 1846 assumed for the default floating-point environment. This is a 1847 comma separated pair. The elements may be one of ``"ieee"``, 1848 ``"preserve-sign"``, or ``"positive-zero"``. The first entry 1849 indicates the flushing mode for the result of floating point 1850 operations. The second indicates the handling of denormal inputs 1851 to floating point instructions. For compatibility with older 1852 bitcode, if the second value is omitted, both input and output 1853 modes will assume the same mode. 1854 1855 If this is attribute is not specified, the default is 1856 ``"ieee,ieee"``. 1857 1858 If the output mode is ``"preserve-sign"``, or ``"positive-zero"``, 1859 denormal outputs may be flushed to zero by standard floating-point 1860 operations. It is not mandated that flushing to zero occurs, but if 1861 a denormal output is flushed to zero, it must respect the sign 1862 mode. Not all targets support all modes. While this indicates the 1863 expected floating point mode the function will be executed with, 1864 this does not make any attempt to ensure the mode is 1865 consistent. User or platform code is expected to set the floating 1866 point mode appropriately before function entry. 1867 1868 If the input mode is ``"preserve-sign"``, or ``"positive-zero"``, a 1869 floating-point operation must treat any input denormal value as 1870 zero. In some situations, if an instruction does not respect this 1871 mode, the input may need to be converted to 0 as if by 1872 ``@llvm.canonicalize`` during lowering for correctness. 1873 1874``"denormal-fp-math-f32"`` 1875 Same as ``"denormal-fp-math"``, but only controls the behavior of 1876 the 32-bit float type (or vectors of 32-bit floats). If both are 1877 are present, this overrides ``"denormal-fp-math"``. Not all targets 1878 support separately setting the denormal mode per type, and no 1879 attempt is made to diagnose unsupported uses. Currently this 1880 attribute is respected by the AMDGPU and NVPTX backends. 1881 1882``"thunk"`` 1883 This attribute indicates that the function will delegate to some other 1884 function with a tail call. The prototype of a thunk should not be used for 1885 optimization purposes. The caller is expected to cast the thunk prototype to 1886 match the thunk target prototype. 1887``uwtable`` 1888 This attribute indicates that the ABI being targeted requires that 1889 an unwind table entry be produced for this function even if we can 1890 show that no exceptions passes by it. This is normally the case for 1891 the ELF x86-64 abi, but it can be disabled for some compilation 1892 units. 1893``nocf_check`` 1894 This attribute indicates that no control-flow check will be performed on 1895 the attributed entity. It disables -fcf-protection=<> for a specific 1896 entity to fine grain the HW control flow protection mechanism. The flag 1897 is target independent and currently appertains to a function or function 1898 pointer. 1899``shadowcallstack`` 1900 This attribute indicates that the ShadowCallStack checks are enabled for 1901 the function. The instrumentation checks that the return address for the 1902 function has not changed between the function prolog and epilog. It is 1903 currently x86_64-specific. 1904 1905Call Site Attributes 1906---------------------- 1907 1908In addition to function attributes the following call site only 1909attributes are supported: 1910 1911``vector-function-abi-variant`` 1912 This attribute can be attached to a :ref:`call <i_call>` to list 1913 the vector functions associated to the function. Notice that the 1914 attribute cannot be attached to a :ref:`invoke <i_invoke>` or a 1915 :ref:`callbr <i_callbr>` instruction. The attribute consists of a 1916 comma separated list of mangled names. The order of the list does 1917 not imply preference (it is logically a set). The compiler is free 1918 to pick any listed vector function of its choosing. 1919 1920 The syntax for the mangled names is as follows::: 1921 1922 _ZGV<isa><mask><vlen><parameters>_<scalar_name>[(<vector_redirection>)] 1923 1924 When present, the attribute informs the compiler that the function 1925 ``<scalar_name>`` has a corresponding vector variant that can be 1926 used to perform the concurrent invocation of ``<scalar_name>`` on 1927 vectors. The shape of the vector function is described by the 1928 tokens between the prefix ``_ZGV`` and the ``<scalar_name>`` 1929 token. The standard name of the vector function is 1930 ``_ZGV<isa><mask><vlen><parameters>_<scalar_name>``. When present, 1931 the optional token ``(<vector_redirection>)`` informs the compiler 1932 that a custom name is provided in addition to the standard one 1933 (custom names can be provided for example via the use of ``declare 1934 variant`` in OpenMP 5.0). The declaration of the variant must be 1935 present in the IR Module. The signature of the vector variant is 1936 determined by the rules of the Vector Function ABI (VFABI) 1937 specifications of the target. For Arm and X86, the VFABI can be 1938 found at https://github.com/ARM-software/abi-aa and 1939 https://software.intel.com/en-us/articles/vector-simd-function-abi, 1940 respectively. 1941 1942 For X86 and Arm targets, the values of the tokens in the standard 1943 name are those that are defined in the VFABI. LLVM has an internal 1944 ``<isa>`` token that can be used to create scalar-to-vector 1945 mappings for functions that are not directly associated to any of 1946 the target ISAs (for example, some of the mappings stored in the 1947 TargetLibraryInfo). Valid values for the ``<isa>`` token are::: 1948 1949 <isa>:= b | c | d | e -> X86 SSE, AVX, AVX2, AVX512 1950 | n | s -> Armv8 Advanced SIMD, SVE 1951 | __LLVM__ -> Internal LLVM Vector ISA 1952 1953 For all targets currently supported (x86, Arm and Internal LLVM), 1954 the remaining tokens can have the following values::: 1955 1956 <mask>:= M | N -> mask | no mask 1957 1958 <vlen>:= number -> number of lanes 1959 | x -> VLA (Vector Length Agnostic) 1960 1961 <parameters>:= v -> vector 1962 | l | l <number> -> linear 1963 | R | R <number> -> linear with ref modifier 1964 | L | L <number> -> linear with val modifier 1965 | U | U <number> -> linear with uval modifier 1966 | ls <pos> -> runtime linear 1967 | Rs <pos> -> runtime linear with ref modifier 1968 | Ls <pos> -> runtime linear with val modifier 1969 | Us <pos> -> runtime linear with uval modifier 1970 | u -> uniform 1971 1972 <scalar_name>:= name of the scalar function 1973 1974 <vector_redirection>:= optional, custom name of the vector function 1975 1976``preallocated(<ty>)`` 1977 This attribute is required on calls to ``llvm.call.preallocated.arg`` 1978 and cannot be used on any other call. See 1979 :ref:`llvm.call.preallocated.arg<int_call_preallocated_arg>` for more 1980 details. 1981 1982.. _glattrs: 1983 1984Global Attributes 1985----------------- 1986 1987Attributes may be set to communicate additional information about a global variable. 1988Unlike :ref:`function attributes <fnattrs>`, attributes on a global variable 1989are grouped into a single :ref:`attribute group <attrgrp>`. 1990 1991.. _opbundles: 1992 1993Operand Bundles 1994--------------- 1995 1996Operand bundles are tagged sets of SSA values that can be associated 1997with certain LLVM instructions (currently only ``call`` s and 1998``invoke`` s). In a way they are like metadata, but dropping them is 1999incorrect and will change program semantics. 2000 2001Syntax:: 2002 2003 operand bundle set ::= '[' operand bundle (, operand bundle )* ']' 2004 operand bundle ::= tag '(' [ bundle operand ] (, bundle operand )* ')' 2005 bundle operand ::= SSA value 2006 tag ::= string constant 2007 2008Operand bundles are **not** part of a function's signature, and a 2009given function may be called from multiple places with different kinds 2010of operand bundles. This reflects the fact that the operand bundles 2011are conceptually a part of the ``call`` (or ``invoke``), not the 2012callee being dispatched to. 2013 2014Operand bundles are a generic mechanism intended to support 2015runtime-introspection-like functionality for managed languages. While 2016the exact semantics of an operand bundle depend on the bundle tag, 2017there are certain limitations to how much the presence of an operand 2018bundle can influence the semantics of a program. These restrictions 2019are described as the semantics of an "unknown" operand bundle. As 2020long as the behavior of an operand bundle is describable within these 2021restrictions, LLVM does not need to have special knowledge of the 2022operand bundle to not miscompile programs containing it. 2023 2024- The bundle operands for an unknown operand bundle escape in unknown 2025 ways before control is transferred to the callee or invokee. 2026- Calls and invokes with operand bundles have unknown read / write 2027 effect on the heap on entry and exit (even if the call target is 2028 ``readnone`` or ``readonly``), unless they're overridden with 2029 callsite specific attributes. 2030- An operand bundle at a call site cannot change the implementation 2031 of the called function. Inter-procedural optimizations work as 2032 usual as long as they take into account the first two properties. 2033 2034More specific types of operand bundles are described below. 2035 2036.. _deopt_opbundles: 2037 2038Deoptimization Operand Bundles 2039^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2040 2041Deoptimization operand bundles are characterized by the ``"deopt"`` 2042operand bundle tag. These operand bundles represent an alternate 2043"safe" continuation for the call site they're attached to, and can be 2044used by a suitable runtime to deoptimize the compiled frame at the 2045specified call site. There can be at most one ``"deopt"`` operand 2046bundle attached to a call site. Exact details of deoptimization is 2047out of scope for the language reference, but it usually involves 2048rewriting a compiled frame into a set of interpreted frames. 2049 2050From the compiler's perspective, deoptimization operand bundles make 2051the call sites they're attached to at least ``readonly``. They read 2052through all of their pointer typed operands (even if they're not 2053otherwise escaped) and the entire visible heap. Deoptimization 2054operand bundles do not capture their operands except during 2055deoptimization, in which case control will not be returned to the 2056compiled frame. 2057 2058The inliner knows how to inline through calls that have deoptimization 2059operand bundles. Just like inlining through a normal call site 2060involves composing the normal and exceptional continuations, inlining 2061through a call site with a deoptimization operand bundle needs to 2062appropriately compose the "safe" deoptimization continuation. The 2063inliner does this by prepending the parent's deoptimization 2064continuation to every deoptimization continuation in the inlined body. 2065E.g. inlining ``@f`` into ``@g`` in the following example 2066 2067.. code-block:: llvm 2068 2069 define void @f() { 2070 call void @x() ;; no deopt state 2071 call void @y() [ "deopt"(i32 10) ] 2072 call void @y() [ "deopt"(i32 10), "unknown"(i8* null) ] 2073 ret void 2074 } 2075 2076 define void @g() { 2077 call void @f() [ "deopt"(i32 20) ] 2078 ret void 2079 } 2080 2081will result in 2082 2083.. code-block:: llvm 2084 2085 define void @g() { 2086 call void @x() ;; still no deopt state 2087 call void @y() [ "deopt"(i32 20, i32 10) ] 2088 call void @y() [ "deopt"(i32 20, i32 10), "unknown"(i8* null) ] 2089 ret void 2090 } 2091 2092It is the frontend's responsibility to structure or encode the 2093deoptimization state in a way that syntactically prepending the 2094caller's deoptimization state to the callee's deoptimization state is 2095semantically equivalent to composing the caller's deoptimization 2096continuation after the callee's deoptimization continuation. 2097 2098.. _ob_funclet: 2099 2100Funclet Operand Bundles 2101^^^^^^^^^^^^^^^^^^^^^^^ 2102 2103Funclet operand bundles are characterized by the ``"funclet"`` 2104operand bundle tag. These operand bundles indicate that a call site 2105is within a particular funclet. There can be at most one 2106``"funclet"`` operand bundle attached to a call site and it must have 2107exactly one bundle operand. 2108 2109If any funclet EH pads have been "entered" but not "exited" (per the 2110`description in the EH doc\ <ExceptionHandling.html#wineh-constraints>`_), 2111it is undefined behavior to execute a ``call`` or ``invoke`` which: 2112 2113* does not have a ``"funclet"`` bundle and is not a ``call`` to a nounwind 2114 intrinsic, or 2115* has a ``"funclet"`` bundle whose operand is not the most-recently-entered 2116 not-yet-exited funclet EH pad. 2117 2118Similarly, if no funclet EH pads have been entered-but-not-yet-exited, 2119executing a ``call`` or ``invoke`` with a ``"funclet"`` bundle is undefined behavior. 2120 2121GC Transition Operand Bundles 2122^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2123 2124GC transition operand bundles are characterized by the 2125``"gc-transition"`` operand bundle tag. These operand bundles mark a 2126call as a transition between a function with one GC strategy to a 2127function with a different GC strategy. If coordinating the transition 2128between GC strategies requires additional code generation at the call 2129site, these bundles may contain any values that are needed by the 2130generated code. For more details, see :ref:`GC Transitions 2131<gc_transition_args>`. 2132 2133.. _assume_opbundles: 2134 2135Assume Operand Bundles 2136^^^^^^^^^^^^^^^^^^^^^^ 2137 2138Operand bundles on an :ref:`llvm.assume <int_assume>` allows representing 2139assumptions that a :ref:`parameter attribute <paramattrs>` or a 2140:ref:`function attribute <fnattrs>` holds for a certain value at a certain 2141location. Operand bundles enable assumptions that are either hard or impossible 2142to represent as a boolean argument of an :ref:`llvm.assume <int_assume>`. 2143 2144An assume operand bundle has the form: 2145 2146:: 2147 2148 "<tag>"([ <holds for value> [, <attribute argument>] ]) 2149 2150* The tag of the operand bundle is usually the name of attribute that can be 2151 assumed to hold. It can also be `ignore`, this tag doesn't contain any 2152 information and should be ignored. 2153* The first argument if present is the value for which the attribute hold. 2154* The second argument if present is an argument of the attribute. 2155 2156If there are no arguments the attribute is a property of the call location. 2157 2158If the represented attribute expects a constant argument, the argument provided 2159to the operand bundle should be a constant as well. 2160 2161For example: 2162 2163.. code-block:: llvm 2164 2165 call void @llvm.assume(i1 true) ["align"(i32* %val, i32 8)] 2166 2167allows the optimizer to assume that at location of call to 2168:ref:`llvm.assume <int_assume>` ``%val`` has an alignment of at least 8. 2169 2170.. code-block:: llvm 2171 2172 call void @llvm.assume(i1 %cond) ["cold"(), "nonnull"(i64* %val)] 2173 2174allows the optimizer to assume that the :ref:`llvm.assume <int_assume>` 2175call location is cold and that ``%val`` may not be null. 2176 2177Just like for the argument of :ref:`llvm.assume <int_assume>`, if any of the 2178provided guarantees are are violated at runtime the behavior is undefined. 2179 2180Even if the assumed property can be encoded as a boolean value, like 2181``nonnull``, using operand bundles to express the property can still have 2182benefits: 2183 2184* Attributes that can be expressed via operand bundles are directly the 2185 property that the optimizer uses and cares about. Encoding attributes as 2186 operand bundles removes the need for an instruction sequence that represents 2187 the property (e.g., `icmp ne i32* %p, null` for `nonnull`) and for the 2188 optimizer to deduce the property from that instruction sequence. 2189* Expressing the property using operand bundles makes it easy to identify the 2190 use of the value as a use in an :ref:`llvm.assume <int_assume>`. This then 2191 simplifies and improves heuristics, e.g., for use "use-sensitive" 2192 optimizations. 2193 2194.. _ob_preallocated: 2195 2196Preallocated Operand Bundles 2197^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2198 2199Preallocated operand bundles are characterized by the ``"preallocated"`` 2200operand bundle tag. These operand bundles allow separation of the allocation 2201of the call argument memory from the call site. This is necessary to pass 2202non-trivially copyable objects by value in a way that is compatible with MSVC 2203on some targets. There can be at most one ``"preallocated"`` operand bundle 2204attached to a call site and it must have exactly one bundle operand, which is 2205a token generated by ``@llvm.call.preallocated.setup``. A call with this 2206operand bundle should not adjust the stack before entering the function, as 2207that will have been done by one of the ``@llvm.call.preallocated.*`` intrinsics. 2208 2209.. code-block:: llvm 2210 2211 %foo = type { i64, i32 } 2212 2213 ... 2214 2215 %t = call token @llvm.call.preallocated.setup(i32 1) 2216 %a = call i8* @llvm.call.preallocated.arg(token %t, i32 0) preallocated(%foo) 2217 %b = bitcast i8* %a to %foo* 2218 ; initialize %b 2219 call void @bar(i32 42, %foo* preallocated(%foo) %b) ["preallocated"(token %t)] 2220 2221.. _moduleasm: 2222 2223Module-Level Inline Assembly 2224---------------------------- 2225 2226Modules may contain "module-level inline asm" blocks, which corresponds 2227to the GCC "file scope inline asm" blocks. These blocks are internally 2228concatenated by LLVM and treated as a single unit, but may be separated 2229in the ``.ll`` file if desired. The syntax is very simple: 2230 2231.. code-block:: llvm 2232 2233 module asm "inline asm code goes here" 2234 module asm "more can go here" 2235 2236The strings can contain any character by escaping non-printable 2237characters. The escape sequence used is simply "\\xx" where "xx" is the 2238two digit hex code for the number. 2239 2240Note that the assembly string *must* be parseable by LLVM's integrated assembler 2241(unless it is disabled), even when emitting a ``.s`` file. 2242 2243.. _langref_datalayout: 2244 2245Data Layout 2246----------- 2247 2248A module may specify a target specific data layout string that specifies 2249how data is to be laid out in memory. The syntax for the data layout is 2250simply: 2251 2252.. code-block:: llvm 2253 2254 target datalayout = "layout specification" 2255 2256The *layout specification* consists of a list of specifications 2257separated by the minus sign character ('-'). Each specification starts 2258with a letter and may include other information after the letter to 2259define some aspect of the data layout. The specifications accepted are 2260as follows: 2261 2262``E`` 2263 Specifies that the target lays out data in big-endian form. That is, 2264 the bits with the most significance have the lowest address 2265 location. 2266``e`` 2267 Specifies that the target lays out data in little-endian form. That 2268 is, the bits with the least significance have the lowest address 2269 location. 2270``S<size>`` 2271 Specifies the natural alignment of the stack in bits. Alignment 2272 promotion of stack variables is limited to the natural stack 2273 alignment to avoid dynamic stack realignment. The stack alignment 2274 must be a multiple of 8-bits. If omitted, the natural stack 2275 alignment defaults to "unspecified", which does not prevent any 2276 alignment promotions. 2277``P<address space>`` 2278 Specifies the address space that corresponds to program memory. 2279 Harvard architectures can use this to specify what space LLVM 2280 should place things such as functions into. If omitted, the 2281 program memory space defaults to the default address space of 0, 2282 which corresponds to a Von Neumann architecture that has code 2283 and data in the same space. 2284``A<address space>`` 2285 Specifies the address space of objects created by '``alloca``'. 2286 Defaults to the default address space of 0. 2287``p[n]:<size>:<abi>:<pref>:<idx>`` 2288 This specifies the *size* of a pointer and its ``<abi>`` and 2289 ``<pref>``\erred alignments for address space ``n``. The fourth parameter 2290 ``<idx>`` is a size of index that used for address calculation. If not 2291 specified, the default index size is equal to the pointer size. All sizes 2292 are in bits. The address space, ``n``, is optional, and if not specified, 2293 denotes the default address space 0. The value of ``n`` must be 2294 in the range [1,2^23). 2295``i<size>:<abi>:<pref>`` 2296 This specifies the alignment for an integer type of a given bit 2297 ``<size>``. The value of ``<size>`` must be in the range [1,2^23). 2298``v<size>:<abi>:<pref>`` 2299 This specifies the alignment for a vector type of a given bit 2300 ``<size>``. 2301``f<size>:<abi>:<pref>`` 2302 This specifies the alignment for a floating-point type of a given bit 2303 ``<size>``. Only values of ``<size>`` that are supported by the target 2304 will work. 32 (float) and 64 (double) are supported on all targets; 80 2305 or 128 (different flavors of long double) are also supported on some 2306 targets. 2307``a:<abi>:<pref>`` 2308 This specifies the alignment for an object of aggregate type. 2309``F<type><abi>`` 2310 This specifies the alignment for function pointers. 2311 The options for ``<type>`` are: 2312 2313 * ``i``: The alignment of function pointers is independent of the alignment 2314 of functions, and is a multiple of ``<abi>``. 2315 * ``n``: The alignment of function pointers is a multiple of the explicit 2316 alignment specified on the function, and is a multiple of ``<abi>``. 2317``m:<mangling>`` 2318 If present, specifies that llvm names are mangled in the output. Symbols 2319 prefixed with the mangling escape character ``\01`` are passed through 2320 directly to the assembler without the escape character. The mangling style 2321 options are 2322 2323 * ``e``: ELF mangling: Private symbols get a ``.L`` prefix. 2324 * ``m``: Mips mangling: Private symbols get a ``$`` prefix. 2325 * ``o``: Mach-O mangling: Private symbols get ``L`` prefix. Other 2326 symbols get a ``_`` prefix. 2327 * ``x``: Windows x86 COFF mangling: Private symbols get the usual prefix. 2328 Regular C symbols get a ``_`` prefix. Functions with ``__stdcall``, 2329 ``__fastcall``, and ``__vectorcall`` have custom mangling that appends 2330 ``@N`` where N is the number of bytes used to pass parameters. C++ symbols 2331 starting with ``?`` are not mangled in any way. 2332 * ``w``: Windows COFF mangling: Similar to ``x``, except that normal C 2333 symbols do not receive a ``_`` prefix. 2334``n<size1>:<size2>:<size3>...`` 2335 This specifies a set of native integer widths for the target CPU in 2336 bits. For example, it might contain ``n32`` for 32-bit PowerPC, 2337 ``n32:64`` for PowerPC 64, or ``n8:16:32:64`` for X86-64. Elements of 2338 this set are considered to support most general arithmetic operations 2339 efficiently. 2340``ni:<address space0>:<address space1>:<address space2>...`` 2341 This specifies pointer types with the specified address spaces 2342 as :ref:`Non-Integral Pointer Type <nointptrtype>` s. The ``0`` 2343 address space cannot be specified as non-integral. 2344 2345On every specification that takes a ``<abi>:<pref>``, specifying the 2346``<pref>`` alignment is optional. If omitted, the preceding ``:`` 2347should be omitted too and ``<pref>`` will be equal to ``<abi>``. 2348 2349When constructing the data layout for a given target, LLVM starts with a 2350default set of specifications which are then (possibly) overridden by 2351the specifications in the ``datalayout`` keyword. The default 2352specifications are given in this list: 2353 2354- ``E`` - big endian 2355- ``p:64:64:64`` - 64-bit pointers with 64-bit alignment. 2356- ``p[n]:64:64:64`` - Other address spaces are assumed to be the 2357 same as the default address space. 2358- ``S0`` - natural stack alignment is unspecified 2359- ``i1:8:8`` - i1 is 8-bit (byte) aligned 2360- ``i8:8:8`` - i8 is 8-bit (byte) aligned 2361- ``i16:16:16`` - i16 is 16-bit aligned 2362- ``i32:32:32`` - i32 is 32-bit aligned 2363- ``i64:32:64`` - i64 has ABI alignment of 32-bits but preferred 2364 alignment of 64-bits 2365- ``f16:16:16`` - half is 16-bit aligned 2366- ``f32:32:32`` - float is 32-bit aligned 2367- ``f64:64:64`` - double is 64-bit aligned 2368- ``f128:128:128`` - quad is 128-bit aligned 2369- ``v64:64:64`` - 64-bit vector is 64-bit aligned 2370- ``v128:128:128`` - 128-bit vector is 128-bit aligned 2371- ``a:0:64`` - aggregates are 64-bit aligned 2372 2373When LLVM is determining the alignment for a given type, it uses the 2374following rules: 2375 2376#. If the type sought is an exact match for one of the specifications, 2377 that specification is used. 2378#. If no match is found, and the type sought is an integer type, then 2379 the smallest integer type that is larger than the bitwidth of the 2380 sought type is used. If none of the specifications are larger than 2381 the bitwidth then the largest integer type is used. For example, 2382 given the default specifications above, the i7 type will use the 2383 alignment of i8 (next largest) while both i65 and i256 will use the 2384 alignment of i64 (largest specified). 2385#. If no match is found, and the type sought is a vector type, then the 2386 largest vector type that is smaller than the sought vector type will 2387 be used as a fall back. This happens because <128 x double> can be 2388 implemented in terms of 64 <2 x double>, for example. 2389 2390The function of the data layout string may not be what you expect. 2391Notably, this is not a specification from the frontend of what alignment 2392the code generator should use. 2393 2394Instead, if specified, the target data layout is required to match what 2395the ultimate *code generator* expects. This string is used by the 2396mid-level optimizers to improve code, and this only works if it matches 2397what the ultimate code generator uses. There is no way to generate IR 2398that does not embed this target-specific detail into the IR. If you 2399don't specify the string, the default specifications will be used to 2400generate a Data Layout and the optimization phases will operate 2401accordingly and introduce target specificity into the IR with respect to 2402these default specifications. 2403 2404.. _langref_triple: 2405 2406Target Triple 2407------------- 2408 2409A module may specify a target triple string that describes the target 2410host. The syntax for the target triple is simply: 2411 2412.. code-block:: llvm 2413 2414 target triple = "x86_64-apple-macosx10.7.0" 2415 2416The *target triple* string consists of a series of identifiers delimited 2417by the minus sign character ('-'). The canonical forms are: 2418 2419:: 2420 2421 ARCHITECTURE-VENDOR-OPERATING_SYSTEM 2422 ARCHITECTURE-VENDOR-OPERATING_SYSTEM-ENVIRONMENT 2423 2424This information is passed along to the backend so that it generates 2425code for the proper architecture. It's possible to override this on the 2426command line with the ``-mtriple`` command line option. 2427 2428.. _pointeraliasing: 2429 2430Pointer Aliasing Rules 2431---------------------- 2432 2433Any memory access must be done through a pointer value associated with 2434an address range of the memory access, otherwise the behavior is 2435undefined. Pointer values are associated with address ranges according 2436to the following rules: 2437 2438- A pointer value is associated with the addresses associated with any 2439 value it is *based* on. 2440- An address of a global variable is associated with the address range 2441 of the variable's storage. 2442- The result value of an allocation instruction is associated with the 2443 address range of the allocated storage. 2444- A null pointer in the default address-space is associated with no 2445 address. 2446- An :ref:`undef value <undefvalues>` in *any* address-space is 2447 associated with no address. 2448- An integer constant other than zero or a pointer value returned from 2449 a function not defined within LLVM may be associated with address 2450 ranges allocated through mechanisms other than those provided by 2451 LLVM. Such ranges shall not overlap with any ranges of addresses 2452 allocated by mechanisms provided by LLVM. 2453 2454A pointer value is *based* on another pointer value according to the 2455following rules: 2456 2457- A pointer value formed from a scalar ``getelementptr`` operation is *based* on 2458 the pointer-typed operand of the ``getelementptr``. 2459- The pointer in lane *l* of the result of a vector ``getelementptr`` operation 2460 is *based* on the pointer in lane *l* of the vector-of-pointers-typed operand 2461 of the ``getelementptr``. 2462- The result value of a ``bitcast`` is *based* on the operand of the 2463 ``bitcast``. 2464- A pointer value formed by an ``inttoptr`` is *based* on all pointer 2465 values that contribute (directly or indirectly) to the computation of 2466 the pointer's value. 2467- The "*based* on" relationship is transitive. 2468 2469Note that this definition of *"based"* is intentionally similar to the 2470definition of *"based"* in C99, though it is slightly weaker. 2471 2472LLVM IR does not associate types with memory. The result type of a 2473``load`` merely indicates the size and alignment of the memory from 2474which to load, as well as the interpretation of the value. The first 2475operand type of a ``store`` similarly only indicates the size and 2476alignment of the store. 2477 2478Consequently, type-based alias analysis, aka TBAA, aka 2479``-fstrict-aliasing``, is not applicable to general unadorned LLVM IR. 2480:ref:`Metadata <metadata>` may be used to encode additional information 2481which specialized optimization passes may use to implement type-based 2482alias analysis. 2483 2484.. _volatile: 2485 2486Volatile Memory Accesses 2487------------------------ 2488 2489Certain memory accesses, such as :ref:`load <i_load>`'s, 2490:ref:`store <i_store>`'s, and :ref:`llvm.memcpy <int_memcpy>`'s may be 2491marked ``volatile``. The optimizers must not change the number of 2492volatile operations or change their order of execution relative to other 2493volatile operations. The optimizers *may* change the order of volatile 2494operations relative to non-volatile operations. This is not Java's 2495"volatile" and has no cross-thread synchronization behavior. 2496 2497A volatile load or store may have additional target-specific semantics. 2498Any volatile operation can have side effects, and any volatile operation 2499can read and/or modify state which is not accessible via a regular load 2500or store in this module. Volatile operations may use addresses which do 2501not point to memory (like MMIO registers). This means the compiler may 2502not use a volatile operation to prove a non-volatile access to that 2503address has defined behavior. 2504 2505The allowed side-effects for volatile accesses are limited. If a 2506non-volatile store to a given address would be legal, a volatile 2507operation may modify the memory at that address. A volatile operation 2508may not modify any other memory accessible by the module being compiled. 2509A volatile operation may not call any code in the current module. 2510 2511The compiler may assume execution will continue after a volatile operation, 2512so operations which modify memory or may have undefined behavior can be 2513hoisted past a volatile operation. 2514 2515IR-level volatile loads and stores cannot safely be optimized into llvm.memcpy 2516or llvm.memmove intrinsics even when those intrinsics are flagged volatile. 2517Likewise, the backend should never split or merge target-legal volatile 2518load/store instructions. Similarly, IR-level volatile loads and stores cannot 2519change from integer to floating-point or vice versa. 2520 2521.. admonition:: Rationale 2522 2523 Platforms may rely on volatile loads and stores of natively supported 2524 data width to be executed as single instruction. For example, in C 2525 this holds for an l-value of volatile primitive type with native 2526 hardware support, but not necessarily for aggregate types. The 2527 frontend upholds these expectations, which are intentionally 2528 unspecified in the IR. The rules above ensure that IR transformations 2529 do not violate the frontend's contract with the language. 2530 2531.. _memmodel: 2532 2533Memory Model for Concurrent Operations 2534-------------------------------------- 2535 2536The LLVM IR does not define any way to start parallel threads of 2537execution or to register signal handlers. Nonetheless, there are 2538platform-specific ways to create them, and we define LLVM IR's behavior 2539in their presence. This model is inspired by the C++0x memory model. 2540 2541For a more informal introduction to this model, see the :doc:`Atomics`. 2542 2543We define a *happens-before* partial order as the least partial order 2544that 2545 2546- Is a superset of single-thread program order, and 2547- When a *synchronizes-with* ``b``, includes an edge from ``a`` to 2548 ``b``. *Synchronizes-with* pairs are introduced by platform-specific 2549 techniques, like pthread locks, thread creation, thread joining, 2550 etc., and by atomic instructions. (See also :ref:`Atomic Memory Ordering 2551 Constraints <ordering>`). 2552 2553Note that program order does not introduce *happens-before* edges 2554between a thread and signals executing inside that thread. 2555 2556Every (defined) read operation (load instructions, memcpy, atomic 2557loads/read-modify-writes, etc.) R reads a series of bytes written by 2558(defined) write operations (store instructions, atomic 2559stores/read-modify-writes, memcpy, etc.). For the purposes of this 2560section, initialized globals are considered to have a write of the 2561initializer which is atomic and happens before any other read or write 2562of the memory in question. For each byte of a read R, R\ :sub:`byte` 2563may see any write to the same byte, except: 2564 2565- If write\ :sub:`1` happens before write\ :sub:`2`, and 2566 write\ :sub:`2` happens before R\ :sub:`byte`, then 2567 R\ :sub:`byte` does not see write\ :sub:`1`. 2568- If R\ :sub:`byte` happens before write\ :sub:`3`, then 2569 R\ :sub:`byte` does not see write\ :sub:`3`. 2570 2571Given that definition, R\ :sub:`byte` is defined as follows: 2572 2573- If R is volatile, the result is target-dependent. (Volatile is 2574 supposed to give guarantees which can support ``sig_atomic_t`` in 2575 C/C++, and may be used for accesses to addresses that do not behave 2576 like normal memory. It does not generally provide cross-thread 2577 synchronization.) 2578- Otherwise, if there is no write to the same byte that happens before 2579 R\ :sub:`byte`, R\ :sub:`byte` returns ``undef`` for that byte. 2580- Otherwise, if R\ :sub:`byte` may see exactly one write, 2581 R\ :sub:`byte` returns the value written by that write. 2582- Otherwise, if R is atomic, and all the writes R\ :sub:`byte` may 2583 see are atomic, it chooses one of the values written. See the :ref:`Atomic 2584 Memory Ordering Constraints <ordering>` section for additional 2585 constraints on how the choice is made. 2586- Otherwise R\ :sub:`byte` returns ``undef``. 2587 2588R returns the value composed of the series of bytes it read. This 2589implies that some bytes within the value may be ``undef`` **without** 2590the entire value being ``undef``. Note that this only defines the 2591semantics of the operation; it doesn't mean that targets will emit more 2592than one instruction to read the series of bytes. 2593 2594Note that in cases where none of the atomic intrinsics are used, this 2595model places only one restriction on IR transformations on top of what 2596is required for single-threaded execution: introducing a store to a byte 2597which might not otherwise be stored is not allowed in general. 2598(Specifically, in the case where another thread might write to and read 2599from an address, introducing a store can change a load that may see 2600exactly one write into a load that may see multiple writes.) 2601 2602.. _ordering: 2603 2604Atomic Memory Ordering Constraints 2605---------------------------------- 2606 2607Atomic instructions (:ref:`cmpxchg <i_cmpxchg>`, 2608:ref:`atomicrmw <i_atomicrmw>`, :ref:`fence <i_fence>`, 2609:ref:`atomic load <i_load>`, and :ref:`atomic store <i_store>`) take 2610ordering parameters that determine which other atomic instructions on 2611the same address they *synchronize with*. These semantics are borrowed 2612from Java and C++0x, but are somewhat more colloquial. If these 2613descriptions aren't precise enough, check those specs (see spec 2614references in the :doc:`atomics guide <Atomics>`). 2615:ref:`fence <i_fence>` instructions treat these orderings somewhat 2616differently since they don't take an address. See that instruction's 2617documentation for details. 2618 2619For a simpler introduction to the ordering constraints, see the 2620:doc:`Atomics`. 2621 2622``unordered`` 2623 The set of values that can be read is governed by the happens-before 2624 partial order. A value cannot be read unless some operation wrote 2625 it. This is intended to provide a guarantee strong enough to model 2626 Java's non-volatile shared variables. This ordering cannot be 2627 specified for read-modify-write operations; it is not strong enough 2628 to make them atomic in any interesting way. 2629``monotonic`` 2630 In addition to the guarantees of ``unordered``, there is a single 2631 total order for modifications by ``monotonic`` operations on each 2632 address. All modification orders must be compatible with the 2633 happens-before order. There is no guarantee that the modification 2634 orders can be combined to a global total order for the whole program 2635 (and this often will not be possible). The read in an atomic 2636 read-modify-write operation (:ref:`cmpxchg <i_cmpxchg>` and 2637 :ref:`atomicrmw <i_atomicrmw>`) reads the value in the modification 2638 order immediately before the value it writes. If one atomic read 2639 happens before another atomic read of the same address, the later 2640 read must see the same value or a later value in the address's 2641 modification order. This disallows reordering of ``monotonic`` (or 2642 stronger) operations on the same address. If an address is written 2643 ``monotonic``-ally by one thread, and other threads ``monotonic``-ally 2644 read that address repeatedly, the other threads must eventually see 2645 the write. This corresponds to the C++0x/C1x 2646 ``memory_order_relaxed``. 2647``acquire`` 2648 In addition to the guarantees of ``monotonic``, a 2649 *synchronizes-with* edge may be formed with a ``release`` operation. 2650 This is intended to model C++'s ``memory_order_acquire``. 2651``release`` 2652 In addition to the guarantees of ``monotonic``, if this operation 2653 writes a value which is subsequently read by an ``acquire`` 2654 operation, it *synchronizes-with* that operation. (This isn't a 2655 complete description; see the C++0x definition of a release 2656 sequence.) This corresponds to the C++0x/C1x 2657 ``memory_order_release``. 2658``acq_rel`` (acquire+release) 2659 Acts as both an ``acquire`` and ``release`` operation on its 2660 address. This corresponds to the C++0x/C1x ``memory_order_acq_rel``. 2661``seq_cst`` (sequentially consistent) 2662 In addition to the guarantees of ``acq_rel`` (``acquire`` for an 2663 operation that only reads, ``release`` for an operation that only 2664 writes), there is a global total order on all 2665 sequentially-consistent operations on all addresses, which is 2666 consistent with the *happens-before* partial order and with the 2667 modification orders of all the affected addresses. Each 2668 sequentially-consistent read sees the last preceding write to the 2669 same address in this global order. This corresponds to the C++0x/C1x 2670 ``memory_order_seq_cst`` and Java volatile. 2671 2672.. _syncscope: 2673 2674If an atomic operation is marked ``syncscope("singlethread")``, it only 2675*synchronizes with* and only participates in the seq\_cst total orderings of 2676other operations running in the same thread (for example, in signal handlers). 2677 2678If an atomic operation is marked ``syncscope("<target-scope>")``, where 2679``<target-scope>`` is a target specific synchronization scope, then it is target 2680dependent if it *synchronizes with* and participates in the seq\_cst total 2681orderings of other operations. 2682 2683Otherwise, an atomic operation that is not marked ``syncscope("singlethread")`` 2684or ``syncscope("<target-scope>")`` *synchronizes with* and participates in the 2685seq\_cst total orderings of other operations that are not marked 2686``syncscope("singlethread")`` or ``syncscope("<target-scope>")``. 2687 2688.. _floatenv: 2689 2690Floating-Point Environment 2691-------------------------- 2692 2693The default LLVM floating-point environment assumes that floating-point 2694instructions do not have side effects. Results assume the round-to-nearest 2695rounding mode. No floating-point exception state is maintained in this 2696environment. Therefore, there is no attempt to create or preserve invalid 2697operation (SNaN) or division-by-zero exceptions. 2698 2699The benefit of this exception-free assumption is that floating-point 2700operations may be speculated freely without any other fast-math relaxations 2701to the floating-point model. 2702 2703Code that requires different behavior than this should use the 2704:ref:`Constrained Floating-Point Intrinsics <constrainedfp>`. 2705 2706.. _fastmath: 2707 2708Fast-Math Flags 2709--------------- 2710 2711LLVM IR floating-point operations (:ref:`fneg <i_fneg>`, :ref:`fadd <i_fadd>`, 2712:ref:`fsub <i_fsub>`, :ref:`fmul <i_fmul>`, :ref:`fdiv <i_fdiv>`, 2713:ref:`frem <i_frem>`, :ref:`fcmp <i_fcmp>`), :ref:`phi <i_phi>`, 2714:ref:`select <i_select>` and :ref:`call <i_call>` 2715may use the following flags to enable otherwise unsafe 2716floating-point transformations. 2717 2718``nnan`` 2719 No NaNs - Allow optimizations to assume the arguments and result are not 2720 NaN. If an argument is a nan, or the result would be a nan, it produces 2721 a :ref:`poison value <poisonvalues>` instead. 2722 2723``ninf`` 2724 No Infs - Allow optimizations to assume the arguments and result are not 2725 +/-Inf. If an argument is +/-Inf, or the result would be +/-Inf, it 2726 produces a :ref:`poison value <poisonvalues>` instead. 2727 2728``nsz`` 2729 No Signed Zeros - Allow optimizations to treat the sign of a zero 2730 argument or result as insignificant. 2731 2732``arcp`` 2733 Allow Reciprocal - Allow optimizations to use the reciprocal of an 2734 argument rather than perform division. 2735 2736``contract`` 2737 Allow floating-point contraction (e.g. fusing a multiply followed by an 2738 addition into a fused multiply-and-add). 2739 2740``afn`` 2741 Approximate functions - Allow substitution of approximate calculations for 2742 functions (sin, log, sqrt, etc). See floating-point intrinsic definitions 2743 for places where this can apply to LLVM's intrinsic math functions. 2744 2745``reassoc`` 2746 Allow reassociation transformations for floating-point instructions. 2747 This may dramatically change results in floating-point. 2748 2749``fast`` 2750 This flag implies all of the others. 2751 2752.. _uselistorder: 2753 2754Use-list Order Directives 2755------------------------- 2756 2757Use-list directives encode the in-memory order of each use-list, allowing the 2758order to be recreated. ``<order-indexes>`` is a comma-separated list of 2759indexes that are assigned to the referenced value's uses. The referenced 2760value's use-list is immediately sorted by these indexes. 2761 2762Use-list directives may appear at function scope or global scope. They are not 2763instructions, and have no effect on the semantics of the IR. When they're at 2764function scope, they must appear after the terminator of the final basic block. 2765 2766If basic blocks have their address taken via ``blockaddress()`` expressions, 2767``uselistorder_bb`` can be used to reorder their use-lists from outside their 2768function's scope. 2769 2770:Syntax: 2771 2772:: 2773 2774 uselistorder <ty> <value>, { <order-indexes> } 2775 uselistorder_bb @function, %block { <order-indexes> } 2776 2777:Examples: 2778 2779:: 2780 2781 define void @foo(i32 %arg1, i32 %arg2) { 2782 entry: 2783 ; ... instructions ... 2784 bb: 2785 ; ... instructions ... 2786 2787 ; At function scope. 2788 uselistorder i32 %arg1, { 1, 0, 2 } 2789 uselistorder label %bb, { 1, 0 } 2790 } 2791 2792 ; At global scope. 2793 uselistorder i32* @global, { 1, 2, 0 } 2794 uselistorder i32 7, { 1, 0 } 2795 uselistorder i32 (i32) @bar, { 1, 0 } 2796 uselistorder_bb @foo, %bb, { 5, 1, 3, 2, 0, 4 } 2797 2798.. _source_filename: 2799 2800Source Filename 2801--------------- 2802 2803The *source filename* string is set to the original module identifier, 2804which will be the name of the compiled source file when compiling from 2805source through the clang front end, for example. It is then preserved through 2806the IR and bitcode. 2807 2808This is currently necessary to generate a consistent unique global 2809identifier for local functions used in profile data, which prepends the 2810source file name to the local function name. 2811 2812The syntax for the source file name is simply: 2813 2814.. code-block:: text 2815 2816 source_filename = "/path/to/source.c" 2817 2818.. _typesystem: 2819 2820Type System 2821=========== 2822 2823The LLVM type system is one of the most important features of the 2824intermediate representation. Being typed enables a number of 2825optimizations to be performed on the intermediate representation 2826directly, without having to do extra analyses on the side before the 2827transformation. A strong type system makes it easier to read the 2828generated code and enables novel analyses and transformations that are 2829not feasible to perform on normal three address code representations. 2830 2831.. _t_void: 2832 2833Void Type 2834--------- 2835 2836:Overview: 2837 2838 2839The void type does not represent any value and has no size. 2840 2841:Syntax: 2842 2843 2844:: 2845 2846 void 2847 2848 2849.. _t_function: 2850 2851Function Type 2852------------- 2853 2854:Overview: 2855 2856 2857The function type can be thought of as a function signature. It consists of a 2858return type and a list of formal parameter types. The return type of a function 2859type is a void type or first class type --- except for :ref:`label <t_label>` 2860and :ref:`metadata <t_metadata>` types. 2861 2862:Syntax: 2863 2864:: 2865 2866 <returntype> (<parameter list>) 2867 2868...where '``<parameter list>``' is a comma-separated list of type 2869specifiers. Optionally, the parameter list may include a type ``...``, which 2870indicates that the function takes a variable number of arguments. Variable 2871argument functions can access their arguments with the :ref:`variable argument 2872handling intrinsic <int_varargs>` functions. '``<returntype>``' is any type 2873except :ref:`label <t_label>` and :ref:`metadata <t_metadata>`. 2874 2875:Examples: 2876 2877+---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 2878| ``i32 (i32)`` | function taking an ``i32``, returning an ``i32`` | 2879+---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 2880| ``float (i16, i32 *) *`` | :ref:`Pointer <t_pointer>` to a function that takes an ``i16`` and a :ref:`pointer <t_pointer>` to ``i32``, returning ``float``. | 2881+---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 2882| ``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. | 2883+---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 2884| ``{i32, i32} (i32)`` | A function taking an ``i32``, returning a :ref:`structure <t_struct>` containing two ``i32`` values | 2885+---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 2886 2887.. _t_firstclass: 2888 2889First Class Types 2890----------------- 2891 2892The :ref:`first class <t_firstclass>` types are perhaps the most important. 2893Values of these types are the only ones which can be produced by 2894instructions. 2895 2896.. _t_single_value: 2897 2898Single Value Types 2899^^^^^^^^^^^^^^^^^^ 2900 2901These are the types that are valid in registers from CodeGen's perspective. 2902 2903.. _t_integer: 2904 2905Integer Type 2906"""""""""""" 2907 2908:Overview: 2909 2910The integer type is a very simple type that simply specifies an 2911arbitrary bit width for the integer type desired. Any bit width from 1 2912bit to 2\ :sup:`23`\ -1 (about 8 million) can be specified. 2913 2914:Syntax: 2915 2916:: 2917 2918 iN 2919 2920The number of bits the integer will occupy is specified by the ``N`` 2921value. 2922 2923Examples: 2924********* 2925 2926+----------------+------------------------------------------------+ 2927| ``i1`` | a single-bit integer. | 2928+----------------+------------------------------------------------+ 2929| ``i32`` | a 32-bit integer. | 2930+----------------+------------------------------------------------+ 2931| ``i1942652`` | a really big integer of over 1 million bits. | 2932+----------------+------------------------------------------------+ 2933 2934.. _t_floating: 2935 2936Floating-Point Types 2937"""""""""""""""""""" 2938 2939.. list-table:: 2940 :header-rows: 1 2941 2942 * - Type 2943 - Description 2944 2945 * - ``half`` 2946 - 16-bit floating-point value 2947 2948 * - ``float`` 2949 - 32-bit floating-point value 2950 2951 * - ``double`` 2952 - 64-bit floating-point value 2953 2954 * - ``fp128`` 2955 - 128-bit floating-point value (112-bit mantissa) 2956 2957 * - ``x86_fp80`` 2958 - 80-bit floating-point value (X87) 2959 2960 * - ``ppc_fp128`` 2961 - 128-bit floating-point value (two 64-bits) 2962 2963The binary format of half, float, double, and fp128 correspond to the 2964IEEE-754-2008 specifications for binary16, binary32, binary64, and binary128 2965respectively. 2966 2967X86_mmx Type 2968"""""""""""" 2969 2970:Overview: 2971 2972The x86_mmx type represents a value held in an MMX register on an x86 2973machine. The operations allowed on it are quite limited: parameters and 2974return values, load and store, and bitcast. User-specified MMX 2975instructions are represented as intrinsic or asm calls with arguments 2976and/or results of this type. There are no arrays, vectors or constants 2977of this type. 2978 2979:Syntax: 2980 2981:: 2982 2983 x86_mmx 2984 2985 2986.. _t_pointer: 2987 2988Pointer Type 2989"""""""""""" 2990 2991:Overview: 2992 2993The pointer type is used to specify memory locations. Pointers are 2994commonly used to reference objects in memory. 2995 2996Pointer types may have an optional address space attribute defining the 2997numbered address space where the pointed-to object resides. The default 2998address space is number zero. The semantics of non-zero address spaces 2999are target-specific. 3000 3001Note that LLVM does not permit pointers to void (``void*``) nor does it 3002permit pointers to labels (``label*``). Use ``i8*`` instead. 3003 3004:Syntax: 3005 3006:: 3007 3008 <type> * 3009 3010:Examples: 3011 3012+-------------------------+--------------------------------------------------------------------------------------------------------------+ 3013| ``[4 x i32]*`` | A :ref:`pointer <t_pointer>` to :ref:`array <t_array>` of four ``i32`` values. | 3014+-------------------------+--------------------------------------------------------------------------------------------------------------+ 3015| ``i32 (i32*) *`` | A :ref:`pointer <t_pointer>` to a :ref:`function <t_function>` that takes an ``i32*``, returning an ``i32``. | 3016+-------------------------+--------------------------------------------------------------------------------------------------------------+ 3017| ``i32 addrspace(5)*`` | A :ref:`pointer <t_pointer>` to an ``i32`` value that resides in address space #5. | 3018+-------------------------+--------------------------------------------------------------------------------------------------------------+ 3019 3020.. _t_vector: 3021 3022Vector Type 3023""""""""""" 3024 3025:Overview: 3026 3027A vector type is a simple derived type that represents a vector of 3028elements. Vector types are used when multiple primitive data are 3029operated in parallel using a single instruction (SIMD). A vector type 3030requires a size (number of elements), an underlying primitive data type, 3031and a scalable property to represent vectors where the exact hardware 3032vector length is unknown at compile time. Vector types are considered 3033:ref:`first class <t_firstclass>`. 3034 3035:Syntax: 3036 3037:: 3038 3039 < <# elements> x <elementtype> > ; Fixed-length vector 3040 < vscale x <# elements> x <elementtype> > ; Scalable vector 3041 3042The number of elements is a constant integer value larger than 0; 3043elementtype may be any integer, floating-point or pointer type. Vectors 3044of size zero are not allowed. For scalable vectors, the total number of 3045elements is a constant multiple (called vscale) of the specified number 3046of elements; vscale is a positive integer that is unknown at compile time 3047and the same hardware-dependent constant for all scalable vectors at run 3048time. The size of a specific scalable vector type is thus constant within 3049IR, even if the exact size in bytes cannot be determined until run time. 3050 3051:Examples: 3052 3053+------------------------+----------------------------------------------------+ 3054| ``<4 x i32>`` | Vector of 4 32-bit integer values. | 3055+------------------------+----------------------------------------------------+ 3056| ``<8 x float>`` | Vector of 8 32-bit floating-point values. | 3057+------------------------+----------------------------------------------------+ 3058| ``<2 x i64>`` | Vector of 2 64-bit integer values. | 3059+------------------------+----------------------------------------------------+ 3060| ``<4 x i64*>`` | Vector of 4 pointers to 64-bit integer values. | 3061+------------------------+----------------------------------------------------+ 3062| ``<vscale x 4 x i32>`` | Vector with a multiple of 4 32-bit integer values. | 3063+------------------------+----------------------------------------------------+ 3064 3065.. _t_label: 3066 3067Label Type 3068^^^^^^^^^^ 3069 3070:Overview: 3071 3072The label type represents code labels. 3073 3074:Syntax: 3075 3076:: 3077 3078 label 3079 3080.. _t_token: 3081 3082Token Type 3083^^^^^^^^^^ 3084 3085:Overview: 3086 3087The token type is used when a value is associated with an instruction 3088but all uses of the value must not attempt to introspect or obscure it. 3089As such, it is not appropriate to have a :ref:`phi <i_phi>` or 3090:ref:`select <i_select>` of type token. 3091 3092:Syntax: 3093 3094:: 3095 3096 token 3097 3098 3099 3100.. _t_metadata: 3101 3102Metadata Type 3103^^^^^^^^^^^^^ 3104 3105:Overview: 3106 3107The metadata type represents embedded metadata. No derived types may be 3108created from metadata except for :ref:`function <t_function>` arguments. 3109 3110:Syntax: 3111 3112:: 3113 3114 metadata 3115 3116.. _t_aggregate: 3117 3118Aggregate Types 3119^^^^^^^^^^^^^^^ 3120 3121Aggregate Types are a subset of derived types that can contain multiple 3122member types. :ref:`Arrays <t_array>` and :ref:`structs <t_struct>` are 3123aggregate types. :ref:`Vectors <t_vector>` are not considered to be 3124aggregate types. 3125 3126.. _t_array: 3127 3128Array Type 3129"""""""""" 3130 3131:Overview: 3132 3133The array type is a very simple derived type that arranges elements 3134sequentially in memory. The array type requires a size (number of 3135elements) and an underlying data type. 3136 3137:Syntax: 3138 3139:: 3140 3141 [<# elements> x <elementtype>] 3142 3143The number of elements is a constant integer value; ``elementtype`` may 3144be any type with a size. 3145 3146:Examples: 3147 3148+------------------+--------------------------------------+ 3149| ``[40 x i32]`` | Array of 40 32-bit integer values. | 3150+------------------+--------------------------------------+ 3151| ``[41 x i32]`` | Array of 41 32-bit integer values. | 3152+------------------+--------------------------------------+ 3153| ``[4 x i8]`` | Array of 4 8-bit integer values. | 3154+------------------+--------------------------------------+ 3155 3156Here are some examples of multidimensional arrays: 3157 3158+-----------------------------+----------------------------------------------------------+ 3159| ``[3 x [4 x i32]]`` | 3x4 array of 32-bit integer values. | 3160+-----------------------------+----------------------------------------------------------+ 3161| ``[12 x [10 x float]]`` | 12x10 array of single precision floating-point values. | 3162+-----------------------------+----------------------------------------------------------+ 3163| ``[2 x [3 x [4 x i16]]]`` | 2x3x4 array of 16-bit integer values. | 3164+-----------------------------+----------------------------------------------------------+ 3165 3166There is no restriction on indexing beyond the end of the array implied 3167by a static type (though there are restrictions on indexing beyond the 3168bounds of an allocated object in some cases). This means that 3169single-dimension 'variable sized array' addressing can be implemented in 3170LLVM with a zero length array type. An implementation of 'pascal style 3171arrays' in LLVM could use the type "``{ i32, [0 x float]}``", for 3172example. 3173 3174.. _t_struct: 3175 3176Structure Type 3177"""""""""""""" 3178 3179:Overview: 3180 3181The structure type is used to represent a collection of data members 3182together in memory. The elements of a structure may be any type that has 3183a size. 3184 3185Structures in memory are accessed using '``load``' and '``store``' by 3186getting a pointer to a field with the '``getelementptr``' instruction. 3187Structures in registers are accessed using the '``extractvalue``' and 3188'``insertvalue``' instructions. 3189 3190Structures may optionally be "packed" structures, which indicate that 3191the alignment of the struct is one byte, and that there is no padding 3192between the elements. In non-packed structs, padding between field types 3193is inserted as defined by the DataLayout string in the module, which is 3194required to match what the underlying code generator expects. 3195 3196Structures can either be "literal" or "identified". A literal structure 3197is defined inline with other types (e.g. ``{i32, i32}*``) whereas 3198identified types are always defined at the top level with a name. 3199Literal types are uniqued by their contents and can never be recursive 3200or opaque since there is no way to write one. Identified types can be 3201recursive, can be opaqued, and are never uniqued. 3202 3203:Syntax: 3204 3205:: 3206 3207 %T1 = type { <type list> } ; Identified normal struct type 3208 %T2 = type <{ <type list> }> ; Identified packed struct type 3209 3210:Examples: 3211 3212+------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 3213| ``{ i32, i32, i32 }`` | A triple of three ``i32`` values | 3214+------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 3215| ``{ 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``. | 3216+------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 3217| ``<{ i8, i32 }>`` | A packed struct known to be 5 bytes in size. | 3218+------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 3219 3220.. _t_opaque: 3221 3222Opaque Structure Types 3223"""""""""""""""""""""" 3224 3225:Overview: 3226 3227Opaque structure types are used to represent named structure types that 3228do not have a body specified. This corresponds (for example) to the C 3229notion of a forward declared structure. 3230 3231:Syntax: 3232 3233:: 3234 3235 %X = type opaque 3236 %52 = type opaque 3237 3238:Examples: 3239 3240+--------------+-------------------+ 3241| ``opaque`` | An opaque type. | 3242+--------------+-------------------+ 3243 3244.. _constants: 3245 3246Constants 3247========= 3248 3249LLVM has several different basic types of constants. This section 3250describes them all and their syntax. 3251 3252Simple Constants 3253---------------- 3254 3255**Boolean constants** 3256 The two strings '``true``' and '``false``' are both valid constants 3257 of the ``i1`` type. 3258**Integer constants** 3259 Standard integers (such as '4') are constants of the 3260 :ref:`integer <t_integer>` type. Negative numbers may be used with 3261 integer types. 3262**Floating-point constants** 3263 Floating-point constants use standard decimal notation (e.g. 3264 123.421), exponential notation (e.g. 1.23421e+2), or a more precise 3265 hexadecimal notation (see below). The assembler requires the exact 3266 decimal value of a floating-point constant. For example, the 3267 assembler accepts 1.25 but rejects 1.3 because 1.3 is a repeating 3268 decimal in binary. Floating-point constants must have a 3269 :ref:`floating-point <t_floating>` type. 3270**Null pointer constants** 3271 The identifier '``null``' is recognized as a null pointer constant 3272 and must be of :ref:`pointer type <t_pointer>`. 3273**Token constants** 3274 The identifier '``none``' is recognized as an empty token constant 3275 and must be of :ref:`token type <t_token>`. 3276 3277The one non-intuitive notation for constants is the hexadecimal form of 3278floating-point constants. For example, the form 3279'``double 0x432ff973cafa8000``' is equivalent to (but harder to read 3280than) '``double 4.5e+15``'. The only time hexadecimal floating-point 3281constants are required (and the only time that they are generated by the 3282disassembler) is when a floating-point constant must be emitted but it 3283cannot be represented as a decimal floating-point number in a reasonable 3284number of digits. For example, NaN's, infinities, and other special 3285values are represented in their IEEE hexadecimal format so that assembly 3286and disassembly do not cause any bits to change in the constants. 3287 3288When using the hexadecimal form, constants of types half, float, and 3289double are represented using the 16-digit form shown above (which 3290matches the IEEE754 representation for double); half and float values 3291must, however, be exactly representable as IEEE 754 half and single 3292precision, respectively. Hexadecimal format is always used for long 3293double, and there are three forms of long double. The 80-bit format used 3294by x86 is represented as ``0xK`` followed by 20 hexadecimal digits. The 3295128-bit format used by PowerPC (two adjacent doubles) is represented by 3296``0xM`` followed by 32 hexadecimal digits. The IEEE 128-bit format is 3297represented by ``0xL`` followed by 32 hexadecimal digits. Long doubles 3298will only work if they match the long double format on your target. 3299The IEEE 16-bit format (half precision) is represented by ``0xH`` 3300followed by 4 hexadecimal digits. All hexadecimal formats are big-endian 3301(sign bit at the left). 3302 3303There are no constants of type x86_mmx. 3304 3305.. _complexconstants: 3306 3307Complex Constants 3308----------------- 3309 3310Complex constants are a (potentially recursive) combination of simple 3311constants and smaller complex constants. 3312 3313**Structure constants** 3314 Structure constants are represented with notation similar to 3315 structure type definitions (a comma separated list of elements, 3316 surrounded by braces (``{}``)). For example: 3317 "``{ i32 4, float 17.0, i32* @G }``", where "``@G``" is declared as 3318 "``@G = external global i32``". Structure constants must have 3319 :ref:`structure type <t_struct>`, and the number and types of elements 3320 must match those specified by the type. 3321**Array constants** 3322 Array constants are represented with notation similar to array type 3323 definitions (a comma separated list of elements, surrounded by 3324 square brackets (``[]``)). For example: 3325 "``[ i32 42, i32 11, i32 74 ]``". Array constants must have 3326 :ref:`array type <t_array>`, and the number and types of elements must 3327 match those specified by the type. As a special case, character array 3328 constants may also be represented as a double-quoted string using the ``c`` 3329 prefix. For example: "``c"Hello World\0A\00"``". 3330**Vector constants** 3331 Vector constants are represented with notation similar to vector 3332 type definitions (a comma separated list of elements, surrounded by 3333 less-than/greater-than's (``<>``)). For example: 3334 "``< i32 42, i32 11, i32 74, i32 100 >``". Vector constants 3335 must have :ref:`vector type <t_vector>`, and the number and types of 3336 elements must match those specified by the type. 3337**Zero initialization** 3338 The string '``zeroinitializer``' can be used to zero initialize a 3339 value to zero of *any* type, including scalar and 3340 :ref:`aggregate <t_aggregate>` types. This is often used to avoid 3341 having to print large zero initializers (e.g. for large arrays) and 3342 is always exactly equivalent to using explicit zero initializers. 3343**Metadata node** 3344 A metadata node is a constant tuple without types. For example: 3345 "``!{!0, !{!2, !0}, !"test"}``". Metadata can reference constant values, 3346 for example: "``!{!0, i32 0, i8* @global, i64 (i64)* @function, !"str"}``". 3347 Unlike other typed constants that are meant to be interpreted as part of 3348 the instruction stream, metadata is a place to attach additional 3349 information such as debug info. 3350 3351Global Variable and Function Addresses 3352-------------------------------------- 3353 3354The addresses of :ref:`global variables <globalvars>` and 3355:ref:`functions <functionstructure>` are always implicitly valid 3356(link-time) constants. These constants are explicitly referenced when 3357the :ref:`identifier for the global <identifiers>` is used and always have 3358:ref:`pointer <t_pointer>` type. For example, the following is a legal LLVM 3359file: 3360 3361.. code-block:: llvm 3362 3363 @X = global i32 17 3364 @Y = global i32 42 3365 @Z = global [2 x i32*] [ i32* @X, i32* @Y ] 3366 3367.. _undefvalues: 3368 3369Undefined Values 3370---------------- 3371 3372The string '``undef``' can be used anywhere a constant is expected, and 3373indicates that the user of the value may receive an unspecified 3374bit-pattern. Undefined values may be of any type (other than '``label``' 3375or '``void``') and be used anywhere a constant is permitted. 3376 3377Undefined values are useful because they indicate to the compiler that 3378the program is well defined no matter what value is used. This gives the 3379compiler more freedom to optimize. Here are some examples of 3380(potentially surprising) transformations that are valid (in pseudo IR): 3381 3382.. code-block:: llvm 3383 3384 %A = add %X, undef 3385 %B = sub %X, undef 3386 %C = xor %X, undef 3387 Safe: 3388 %A = undef 3389 %B = undef 3390 %C = undef 3391 3392This is safe because all of the output bits are affected by the undef 3393bits. Any output bit can have a zero or one depending on the input bits. 3394 3395.. code-block:: llvm 3396 3397 %A = or %X, undef 3398 %B = and %X, undef 3399 Safe: 3400 %A = -1 3401 %B = 0 3402 Safe: 3403 %A = %X ;; By choosing undef as 0 3404 %B = %X ;; By choosing undef as -1 3405 Unsafe: 3406 %A = undef 3407 %B = undef 3408 3409These logical operations have bits that are not always affected by the 3410input. For example, if ``%X`` has a zero bit, then the output of the 3411'``and``' operation will always be a zero for that bit, no matter what 3412the corresponding bit from the '``undef``' is. As such, it is unsafe to 3413optimize or assume that the result of the '``and``' is '``undef``'. 3414However, it is safe to assume that all bits of the '``undef``' could be 34150, and optimize the '``and``' to 0. Likewise, it is safe to assume that 3416all the bits of the '``undef``' operand to the '``or``' could be set, 3417allowing the '``or``' to be folded to -1. 3418 3419.. code-block:: llvm 3420 3421 %A = select undef, %X, %Y 3422 %B = select undef, 42, %Y 3423 %C = select %X, %Y, undef 3424 Safe: 3425 %A = %X (or %Y) 3426 %B = 42 (or %Y) 3427 %C = %Y 3428 Unsafe: 3429 %A = undef 3430 %B = undef 3431 %C = undef 3432 3433This set of examples shows that undefined '``select``' (and conditional 3434branch) conditions can go *either way*, but they have to come from one 3435of the two operands. In the ``%A`` example, if ``%X`` and ``%Y`` were 3436both known to have a clear low bit, then ``%A`` would have to have a 3437cleared low bit. However, in the ``%C`` example, the optimizer is 3438allowed to assume that the '``undef``' operand could be the same as 3439``%Y``, allowing the whole '``select``' to be eliminated. 3440 3441.. code-block:: text 3442 3443 %A = xor undef, undef 3444 3445 %B = undef 3446 %C = xor %B, %B 3447 3448 %D = undef 3449 %E = icmp slt %D, 4 3450 %F = icmp gte %D, 4 3451 3452 Safe: 3453 %A = undef 3454 %B = undef 3455 %C = undef 3456 %D = undef 3457 %E = undef 3458 %F = undef 3459 3460This example points out that two '``undef``' operands are not 3461necessarily the same. This can be surprising to people (and also matches 3462C semantics) where they assume that "``X^X``" is always zero, even if 3463``X`` is undefined. This isn't true for a number of reasons, but the 3464short answer is that an '``undef``' "variable" can arbitrarily change 3465its value over its "live range". This is true because the variable 3466doesn't actually *have a live range*. Instead, the value is logically 3467read from arbitrary registers that happen to be around when needed, so 3468the value is not necessarily consistent over time. In fact, ``%A`` and 3469``%C`` need to have the same semantics or the core LLVM "replace all 3470uses with" concept would not hold. 3471 3472To ensure all uses of a given register observe the same value (even if 3473'``undef``'), the :ref:`freeze instruction <i_freeze>` can be used. 3474A value is frozen if its uses see the same value. 3475 3476.. code-block:: llvm 3477 3478 %A = sdiv undef, %X 3479 %B = sdiv %X, undef 3480 Safe: 3481 %A = 0 3482 b: unreachable 3483 3484These examples show the crucial difference between an *undefined value* 3485and *undefined behavior*. An undefined value (like '``undef``') is 3486allowed to have an arbitrary bit-pattern. This means that the ``%A`` 3487operation can be constant folded to '``0``', because the '``undef``' 3488could be zero, and zero divided by any value is zero. 3489However, in the second example, we can make a more aggressive 3490assumption: because the ``undef`` is allowed to be an arbitrary value, 3491we are allowed to assume that it could be zero. Since a divide by zero 3492has *undefined behavior*, we are allowed to assume that the operation 3493does not execute at all. This allows us to delete the divide and all 3494code after it. Because the undefined operation "can't happen", the 3495optimizer can assume that it occurs in dead code. 3496 3497.. code-block:: text 3498 3499 a: store undef -> %X 3500 b: store %X -> undef 3501 Safe: 3502 a: <deleted> 3503 b: unreachable 3504 3505A store *of* an undefined value can be assumed to not have any effect; 3506we can assume that the value is overwritten with bits that happen to 3507match what was already there. However, a store *to* an undefined 3508location could clobber arbitrary memory, therefore, it has undefined 3509behavior. 3510 3511Branching on an undefined value is undefined behavior. 3512This explains optimizations that depend on branch conditions to construct 3513predicates, such as Correlated Value Propagation and Global Value Numbering. 3514In case of switch instruction, the branch condition should be frozen, otherwise 3515it is undefined behavior. 3516 3517.. code-block:: text 3518 3519 Unsafe: 3520 br undef, BB1, BB2 ; UB 3521 3522 %X = and i32 undef, 255 3523 switch %X, label %ret [ .. ] ; UB 3524 3525 store undef, i8* %ptr 3526 %X = load i8* %ptr ; %X is undef 3527 switch i8 %X, label %ret [ .. ] ; UB 3528 3529 Safe: 3530 %X = or i8 undef, 255 ; always 255 3531 switch i8 %X, label %ret [ .. ] ; Well-defined 3532 3533 %X = freeze i1 undef 3534 br %X, BB1, BB2 ; Well-defined (non-deterministic jump) 3535 3536 3537This is also consistent with the behavior of MemorySanitizer. 3538MemorySanitizer, detector of uses of uninitialized memory, 3539defines a branch with condition that depends on an undef value (or 3540certain other values, like e.g. a result of a load from heap-allocated 3541memory that has never been stored to) to have an externally visible 3542side effect. For this reason functions with *sanitize_memory* 3543attribute are not allowed to produce such branches "out of thin 3544air". More strictly, an optimization that inserts a conditional branch 3545is only valid if in all executions where the branch condition has at 3546least one undefined bit, the same branch condition is evaluated in the 3547input IR as well. 3548 3549.. _poisonvalues: 3550 3551Poison Values 3552------------- 3553 3554In order to facilitate speculative execution, many instructions do not 3555invoke immediate undefined behavior when provided with illegal operands, 3556and return a poison value instead. 3557 3558There is currently no way of representing a poison value in the IR; they 3559only exist when produced by operations such as :ref:`add <i_add>` with 3560the ``nsw`` flag. 3561 3562Poison value behavior is defined in terms of value *dependence*: 3563 3564- Values other than :ref:`phi <i_phi>` nodes and :ref:`select <i_select>` 3565 instructions depend on their operands. 3566- :ref:`Phi <i_phi>` nodes depend on the operand corresponding to 3567 their dynamic predecessor basic block. 3568- Select instructions depend on their condition operand and their 3569 selected operand. 3570- Function arguments depend on the corresponding actual argument values 3571 in the dynamic callers of their functions. 3572- :ref:`Call <i_call>` instructions depend on the :ref:`ret <i_ret>` 3573 instructions that dynamically transfer control back to them. 3574- :ref:`Invoke <i_invoke>` instructions depend on the 3575 :ref:`ret <i_ret>`, :ref:`resume <i_resume>`, or exception-throwing 3576 call instructions that dynamically transfer control back to them. 3577- Non-volatile loads and stores depend on the most recent stores to all 3578 of the referenced memory addresses, following the order in the IR 3579 (including loads and stores implied by intrinsics such as 3580 :ref:`@llvm.memcpy <int_memcpy>`.) 3581- An instruction with externally visible side effects depends on the 3582 most recent preceding instruction with externally visible side 3583 effects, following the order in the IR. (This includes :ref:`volatile 3584 operations <volatile>`.) 3585- An instruction *control-depends* on a :ref:`terminator 3586 instruction <terminators>` if the terminator instruction has 3587 multiple successors and the instruction is always executed when 3588 control transfers to one of the successors, and may not be executed 3589 when control is transferred to another. 3590- Additionally, an instruction also *control-depends* on a terminator 3591 instruction if the set of instructions it otherwise depends on would 3592 be different if the terminator had transferred control to a different 3593 successor. 3594- Dependence is transitive. 3595- Vector elements may be independently poisoned. Therefore, transforms 3596 on instructions such as shufflevector must be careful to propagate 3597 poison across values or elements only as allowed by the original code. 3598 3599An instruction that *depends* on a poison value, produces a poison value 3600itself. A poison value may be relaxed into an 3601:ref:`undef value <undefvalues>`, which takes an arbitrary bit-pattern. 3602Propagation of poison can be stopped with the 3603:ref:`freeze instruction <i_freeze>`. 3604 3605This means that immediate undefined behavior occurs if a poison value is 3606used as an instruction operand that has any values that trigger undefined 3607behavior. Notably this includes (but is not limited to): 3608 3609- The pointer operand of a :ref:`load <i_load>`, :ref:`store <i_store>` or 3610 any other pointer dereferencing instruction (independent of address 3611 space). 3612- The divisor operand of a ``udiv``, ``sdiv``, ``urem`` or ``srem`` 3613 instruction. 3614- The condition operand of a :ref:`br <i_br>` instruction. 3615- The callee operand of a :ref:`call <i_call>` or :ref:`invoke <i_invoke>` 3616 instruction. 3617 3618Here are some examples: 3619 3620.. code-block:: llvm 3621 3622 entry: 3623 %poison = sub nuw i32 0, 1 ; Results in a poison value. 3624 %still_poison = and i32 %poison, 0 ; 0, but also poison. 3625 %poison_yet_again = getelementptr i32, i32* @h, i32 %still_poison 3626 store i32 0, i32* %poison_yet_again ; Undefined behavior due to 3627 ; store to poison. 3628 3629 store i32 %poison, i32* @g ; Poison value stored to memory. 3630 %poison2 = load i32, i32* @g ; Poison value loaded back from memory. 3631 3632 %narrowaddr = bitcast i32* @g to i16* 3633 %wideaddr = bitcast i32* @g to i64* 3634 %poison3 = load i16, i16* %narrowaddr ; Returns a poison value. 3635 %poison4 = load i64, i64* %wideaddr ; Returns a poison value. 3636 3637 %cmp = icmp slt i32 %poison, 0 ; Returns a poison value. 3638 br i1 %cmp, label %end, label %end ; undefined behavior 3639 3640 end: 3641 3642.. _blockaddress: 3643 3644Addresses of Basic Blocks 3645------------------------- 3646 3647``blockaddress(@function, %block)`` 3648 3649The '``blockaddress``' constant computes the address of the specified 3650basic block in the specified function, and always has an ``i8*`` type. 3651Taking the address of the entry block is illegal. 3652 3653This value only has defined behavior when used as an operand to the 3654':ref:`indirectbr <i_indirectbr>`' or ':ref:`callbr <i_callbr>`'instruction, or 3655for comparisons against null. Pointer equality tests between labels addresses 3656results in undefined behavior --- though, again, comparison against null is ok, 3657and no label is equal to the null pointer. This may be passed around as an 3658opaque pointer sized value as long as the bits are not inspected. This 3659allows ``ptrtoint`` and arithmetic to be performed on these values so 3660long as the original value is reconstituted before the ``indirectbr`` or 3661``callbr`` instruction. 3662 3663Finally, some targets may provide defined semantics when using the value 3664as the operand to an inline assembly, but that is target specific. 3665 3666.. _constantexprs: 3667 3668Constant Expressions 3669-------------------- 3670 3671Constant expressions are used to allow expressions involving other 3672constants to be used as constants. Constant expressions may be of any 3673:ref:`first class <t_firstclass>` type and may involve any LLVM operation 3674that does not have side effects (e.g. load and call are not supported). 3675The following is the syntax for constant expressions: 3676 3677``trunc (CST to TYPE)`` 3678 Perform the :ref:`trunc operation <i_trunc>` on constants. 3679``zext (CST to TYPE)`` 3680 Perform the :ref:`zext operation <i_zext>` on constants. 3681``sext (CST to TYPE)`` 3682 Perform the :ref:`sext operation <i_sext>` on constants. 3683``fptrunc (CST to TYPE)`` 3684 Truncate a floating-point constant to another floating-point type. 3685 The size of CST must be larger than the size of TYPE. Both types 3686 must be floating-point. 3687``fpext (CST to TYPE)`` 3688 Floating-point extend a constant to another type. The size of CST 3689 must be smaller or equal to the size of TYPE. Both types must be 3690 floating-point. 3691``fptoui (CST to TYPE)`` 3692 Convert a floating-point constant to the corresponding unsigned 3693 integer constant. TYPE must be a scalar or vector integer type. CST 3694 must be of scalar or vector floating-point type. Both CST and TYPE 3695 must be scalars, or vectors of the same number of elements. If the 3696 value won't fit in the integer type, the result is a 3697 :ref:`poison value <poisonvalues>`. 3698``fptosi (CST to TYPE)`` 3699 Convert a floating-point constant to the corresponding signed 3700 integer constant. TYPE must be a scalar or vector integer type. CST 3701 must be of scalar or vector floating-point type. Both CST and TYPE 3702 must be scalars, or vectors of the same number of elements. If the 3703 value won't fit in the integer type, the result is a 3704 :ref:`poison value <poisonvalues>`. 3705``uitofp (CST to TYPE)`` 3706 Convert an unsigned integer constant to the corresponding 3707 floating-point constant. TYPE must be a scalar or vector floating-point 3708 type. CST must be of scalar or vector integer type. Both CST and TYPE must 3709 be scalars, or vectors of the same number of elements. 3710``sitofp (CST to TYPE)`` 3711 Convert a signed integer constant to the corresponding floating-point 3712 constant. TYPE must be a scalar or vector floating-point type. 3713 CST must be of scalar or vector integer type. Both CST and TYPE must 3714 be scalars, or vectors of the same number of elements. 3715``ptrtoint (CST to TYPE)`` 3716 Perform the :ref:`ptrtoint operation <i_ptrtoint>` on constants. 3717``inttoptr (CST to TYPE)`` 3718 Perform the :ref:`inttoptr operation <i_inttoptr>` on constants. 3719 This one is *really* dangerous! 3720``bitcast (CST to TYPE)`` 3721 Convert a constant, CST, to another TYPE. 3722 The constraints of the operands are the same as those for the 3723 :ref:`bitcast instruction <i_bitcast>`. 3724``addrspacecast (CST to TYPE)`` 3725 Convert a constant pointer or constant vector of pointer, CST, to another 3726 TYPE in a different address space. The constraints of the operands are the 3727 same as those for the :ref:`addrspacecast instruction <i_addrspacecast>`. 3728``getelementptr (TY, CSTPTR, IDX0, IDX1, ...)``, ``getelementptr inbounds (TY, CSTPTR, IDX0, IDX1, ...)`` 3729 Perform the :ref:`getelementptr operation <i_getelementptr>` on 3730 constants. As with the :ref:`getelementptr <i_getelementptr>` 3731 instruction, the index list may have one or more indexes, which are 3732 required to make sense for the type of "pointer to TY". 3733``select (COND, VAL1, VAL2)`` 3734 Perform the :ref:`select operation <i_select>` on constants. 3735``icmp COND (VAL1, VAL2)`` 3736 Perform the :ref:`icmp operation <i_icmp>` on constants. 3737``fcmp COND (VAL1, VAL2)`` 3738 Perform the :ref:`fcmp operation <i_fcmp>` on constants. 3739``extractelement (VAL, IDX)`` 3740 Perform the :ref:`extractelement operation <i_extractelement>` on 3741 constants. 3742``insertelement (VAL, ELT, IDX)`` 3743 Perform the :ref:`insertelement operation <i_insertelement>` on 3744 constants. 3745``shufflevector (VEC1, VEC2, IDXMASK)`` 3746 Perform the :ref:`shufflevector operation <i_shufflevector>` on 3747 constants. 3748``extractvalue (VAL, IDX0, IDX1, ...)`` 3749 Perform the :ref:`extractvalue operation <i_extractvalue>` on 3750 constants. The index list is interpreted in a similar manner as 3751 indices in a ':ref:`getelementptr <i_getelementptr>`' operation. At 3752 least one index value must be specified. 3753``insertvalue (VAL, ELT, IDX0, IDX1, ...)`` 3754 Perform the :ref:`insertvalue operation <i_insertvalue>` on constants. 3755 The index list is interpreted in a similar manner as indices in a 3756 ':ref:`getelementptr <i_getelementptr>`' operation. At least one index 3757 value must be specified. 3758``OPCODE (LHS, RHS)`` 3759 Perform the specified operation of the LHS and RHS constants. OPCODE 3760 may be any of the :ref:`binary <binaryops>` or :ref:`bitwise 3761 binary <bitwiseops>` operations. The constraints on operands are 3762 the same as those for the corresponding instruction (e.g. no bitwise 3763 operations on floating-point values are allowed). 3764 3765Other Values 3766============ 3767 3768.. _inlineasmexprs: 3769 3770Inline Assembler Expressions 3771---------------------------- 3772 3773LLVM supports inline assembler expressions (as opposed to :ref:`Module-Level 3774Inline Assembly <moduleasm>`) through the use of a special value. This value 3775represents the inline assembler as a template string (containing the 3776instructions to emit), a list of operand constraints (stored as a string), a 3777flag that indicates whether or not the inline asm expression has side effects, 3778and a flag indicating whether the function containing the asm needs to align its 3779stack conservatively. 3780 3781The template string supports argument substitution of the operands using "``$``" 3782followed by a number, to indicate substitution of the given register/memory 3783location, as specified by the constraint string. "``${NUM:MODIFIER}``" may also 3784be used, where ``MODIFIER`` is a target-specific annotation for how to print the 3785operand (See :ref:`inline-asm-modifiers`). 3786 3787A literal "``$``" may be included by using "``$$``" in the template. To include 3788other special characters into the output, the usual "``\XX``" escapes may be 3789used, just as in other strings. Note that after template substitution, the 3790resulting assembly string is parsed by LLVM's integrated assembler unless it is 3791disabled -- even when emitting a ``.s`` file -- and thus must contain assembly 3792syntax known to LLVM. 3793 3794LLVM also supports a few more substitutions useful for writing inline assembly: 3795 3796- ``${:uid}``: Expands to a decimal integer unique to this inline assembly blob. 3797 This substitution is useful when declaring a local label. Many standard 3798 compiler optimizations, such as inlining, may duplicate an inline asm blob. 3799 Adding a blob-unique identifier ensures that the two labels will not conflict 3800 during assembly. This is used to implement `GCC's %= special format 3801 string <https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html>`_. 3802- ``${:comment}``: Expands to the comment character of the current target's 3803 assembly dialect. This is usually ``#``, but many targets use other strings, 3804 such as ``;``, ``//``, or ``!``. 3805- ``${:private}``: Expands to the assembler private label prefix. Labels with 3806 this prefix will not appear in the symbol table of the assembled object. 3807 Typically the prefix is ``L``, but targets may use other strings. ``.L`` is 3808 relatively popular. 3809 3810LLVM's support for inline asm is modeled closely on the requirements of Clang's 3811GCC-compatible inline-asm support. Thus, the feature-set and the constraint and 3812modifier codes listed here are similar or identical to those in GCC's inline asm 3813support. However, to be clear, the syntax of the template and constraint strings 3814described here is *not* the same as the syntax accepted by GCC and Clang, and, 3815while most constraint letters are passed through as-is by Clang, some get 3816translated to other codes when converting from the C source to the LLVM 3817assembly. 3818 3819An example inline assembler expression is: 3820 3821.. code-block:: llvm 3822 3823 i32 (i32) asm "bswap $0", "=r,r" 3824 3825Inline assembler expressions may **only** be used as the callee operand 3826of a :ref:`call <i_call>` or an :ref:`invoke <i_invoke>` instruction. 3827Thus, typically we have: 3828 3829.. code-block:: llvm 3830 3831 %X = call i32 asm "bswap $0", "=r,r"(i32 %Y) 3832 3833Inline asms with side effects not visible in the constraint list must be 3834marked as having side effects. This is done through the use of the 3835'``sideeffect``' keyword, like so: 3836 3837.. code-block:: llvm 3838 3839 call void asm sideeffect "eieio", ""() 3840 3841In some cases inline asms will contain code that will not work unless 3842the stack is aligned in some way, such as calls or SSE instructions on 3843x86, yet will not contain code that does that alignment within the asm. 3844The compiler should make conservative assumptions about what the asm 3845might contain and should generate its usual stack alignment code in the 3846prologue if the '``alignstack``' keyword is present: 3847 3848.. code-block:: llvm 3849 3850 call void asm alignstack "eieio", ""() 3851 3852Inline asms also support using non-standard assembly dialects. The 3853assumed dialect is ATT. When the '``inteldialect``' keyword is present, 3854the inline asm is using the Intel dialect. Currently, ATT and Intel are 3855the only supported dialects. An example is: 3856 3857.. code-block:: llvm 3858 3859 call void asm inteldialect "eieio", ""() 3860 3861If multiple keywords appear the '``sideeffect``' keyword must come 3862first, the '``alignstack``' keyword second and the '``inteldialect``' 3863keyword last. 3864 3865Inline Asm Constraint String 3866^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 3867 3868The constraint list is a comma-separated string, each element containing one or 3869more constraint codes. 3870 3871For each element in the constraint list an appropriate register or memory 3872operand will be chosen, and it will be made available to assembly template 3873string expansion as ``$0`` for the first constraint in the list, ``$1`` for the 3874second, etc. 3875 3876There are three different types of constraints, which are distinguished by a 3877prefix symbol in front of the constraint code: Output, Input, and Clobber. The 3878constraints must always be given in that order: outputs first, then inputs, then 3879clobbers. They cannot be intermingled. 3880 3881There are also three different categories of constraint codes: 3882 3883- Register constraint. This is either a register class, or a fixed physical 3884 register. This kind of constraint will allocate a register, and if necessary, 3885 bitcast the argument or result to the appropriate type. 3886- Memory constraint. This kind of constraint is for use with an instruction 3887 taking a memory operand. Different constraints allow for different addressing 3888 modes used by the target. 3889- Immediate value constraint. This kind of constraint is for an integer or other 3890 immediate value which can be rendered directly into an instruction. The 3891 various target-specific constraints allow the selection of a value in the 3892 proper range for the instruction you wish to use it with. 3893 3894Output constraints 3895"""""""""""""""""" 3896 3897Output constraints are specified by an "``=``" prefix (e.g. "``=r``"). This 3898indicates that the assembly will write to this operand, and the operand will 3899then be made available as a return value of the ``asm`` expression. Output 3900constraints do not consume an argument from the call instruction. (Except, see 3901below about indirect outputs). 3902 3903Normally, it is expected that no output locations are written to by the assembly 3904expression until *all* of the inputs have been read. As such, LLVM may assign 3905the same register to an output and an input. If this is not safe (e.g. if the 3906assembly contains two instructions, where the first writes to one output, and 3907the second reads an input and writes to a second output), then the "``&``" 3908modifier must be used (e.g. "``=&r``") to specify that the output is an 3909"early-clobber" output. Marking an output as "early-clobber" ensures that LLVM 3910will not use the same register for any inputs (other than an input tied to this 3911output). 3912 3913Input constraints 3914""""""""""""""""" 3915 3916Input constraints do not have a prefix -- just the constraint codes. Each input 3917constraint will consume one argument from the call instruction. It is not 3918permitted for the asm to write to any input register or memory location (unless 3919that input is tied to an output). Note also that multiple inputs may all be 3920assigned to the same register, if LLVM can determine that they necessarily all 3921contain the same value. 3922 3923Instead of providing a Constraint Code, input constraints may also "tie" 3924themselves to an output constraint, by providing an integer as the constraint 3925string. Tied inputs still consume an argument from the call instruction, and 3926take up a position in the asm template numbering as is usual -- they will simply 3927be constrained to always use the same register as the output they've been tied 3928to. For example, a constraint string of "``=r,0``" says to assign a register for 3929output, and use that register as an input as well (it being the 0'th 3930constraint). 3931 3932It is permitted to tie an input to an "early-clobber" output. In that case, no 3933*other* input may share the same register as the input tied to the early-clobber 3934(even when the other input has the same value). 3935 3936You may only tie an input to an output which has a register constraint, not a 3937memory constraint. Only a single input may be tied to an output. 3938 3939There is also an "interesting" feature which deserves a bit of explanation: if a 3940register class constraint allocates a register which is too small for the value 3941type operand provided as input, the input value will be split into multiple 3942registers, and all of them passed to the inline asm. 3943 3944However, this feature is often not as useful as you might think. 3945 3946Firstly, the registers are *not* guaranteed to be consecutive. So, on those 3947architectures that have instructions which operate on multiple consecutive 3948instructions, this is not an appropriate way to support them. (e.g. the 32-bit 3949SparcV8 has a 64-bit load, which instruction takes a single 32-bit register. The 3950hardware then loads into both the named register, and the next register. This 3951feature of inline asm would not be useful to support that.) 3952 3953A few of the targets provide a template string modifier allowing explicit access 3954to the second register of a two-register operand (e.g. MIPS ``L``, ``M``, and 3955``D``). On such an architecture, you can actually access the second allocated 3956register (yet, still, not any subsequent ones). But, in that case, you're still 3957probably better off simply splitting the value into two separate operands, for 3958clarity. (e.g. see the description of the ``A`` constraint on X86, which, 3959despite existing only for use with this feature, is not really a good idea to 3960use) 3961 3962Indirect inputs and outputs 3963""""""""""""""""""""""""""" 3964 3965Indirect output or input constraints can be specified by the "``*``" modifier 3966(which goes after the "``=``" in case of an output). This indicates that the asm 3967will write to or read from the contents of an *address* provided as an input 3968argument. (Note that in this way, indirect outputs act more like an *input* than 3969an output: just like an input, they consume an argument of the call expression, 3970rather than producing a return value. An indirect output constraint is an 3971"output" only in that the asm is expected to write to the contents of the input 3972memory location, instead of just read from it). 3973 3974This is most typically used for memory constraint, e.g. "``=*m``", to pass the 3975address of a variable as a value. 3976 3977It is also possible to use an indirect *register* constraint, but only on output 3978(e.g. "``=*r``"). This will cause LLVM to allocate a register for an output 3979value normally, and then, separately emit a store to the address provided as 3980input, after the provided inline asm. (It's not clear what value this 3981functionality provides, compared to writing the store explicitly after the asm 3982statement, and it can only produce worse code, since it bypasses many 3983optimization passes. I would recommend not using it.) 3984 3985 3986Clobber constraints 3987""""""""""""""""""" 3988 3989A clobber constraint is indicated by a "``~``" prefix. A clobber does not 3990consume an input operand, nor generate an output. Clobbers cannot use any of the 3991general constraint code letters -- they may use only explicit register 3992constraints, e.g. "``~{eax}``". The one exception is that a clobber string of 3993"``~{memory}``" indicates that the assembly writes to arbitrary undeclared 3994memory locations -- not only the memory pointed to by a declared indirect 3995output. 3996 3997Note that clobbering named registers that are also present in output 3998constraints is not legal. 3999 4000 4001Constraint Codes 4002"""""""""""""""" 4003After a potential prefix comes constraint code, or codes. 4004 4005A Constraint Code is either a single letter (e.g. "``r``"), a "``^``" character 4006followed by two letters (e.g. "``^wc``"), or "``{``" register-name "``}``" 4007(e.g. "``{eax}``"). 4008 4009The one and two letter constraint codes are typically chosen to be the same as 4010GCC's constraint codes. 4011 4012A single constraint may include one or more than constraint code in it, leaving 4013it up to LLVM to choose which one to use. This is included mainly for 4014compatibility with the translation of GCC inline asm coming from clang. 4015 4016There are two ways to specify alternatives, and either or both may be used in an 4017inline asm constraint list: 4018 40191) Append the codes to each other, making a constraint code set. E.g. "``im``" 4020 or "``{eax}m``". This means "choose any of the options in the set". The 4021 choice of constraint is made independently for each constraint in the 4022 constraint list. 4023 40242) Use "``|``" between constraint code sets, creating alternatives. Every 4025 constraint in the constraint list must have the same number of alternative 4026 sets. With this syntax, the same alternative in *all* of the items in the 4027 constraint list will be chosen together. 4028 4029Putting those together, you might have a two operand constraint string like 4030``"rm|r,ri|rm"``. This indicates that if operand 0 is ``r`` or ``m``, then 4031operand 1 may be one of ``r`` or ``i``. If operand 0 is ``r``, then operand 1 4032may be one of ``r`` or ``m``. But, operand 0 and 1 cannot both be of type m. 4033 4034However, the use of either of the alternatives features is *NOT* recommended, as 4035LLVM is not able to make an intelligent choice about which one to use. (At the 4036point it currently needs to choose, not enough information is available to do so 4037in a smart way.) Thus, it simply tries to make a choice that's most likely to 4038compile, not one that will be optimal performance. (e.g., given "``rm``", it'll 4039always choose to use memory, not registers). And, if given multiple registers, 4040or multiple register classes, it will simply choose the first one. (In fact, it 4041doesn't currently even ensure explicitly specified physical registers are 4042unique, so specifying multiple physical registers as alternatives, like 4043``{r11}{r12},{r11}{r12}``, will assign r11 to both operands, not at all what was 4044intended.) 4045 4046Supported Constraint Code List 4047"""""""""""""""""""""""""""""" 4048 4049The constraint codes are, in general, expected to behave the same way they do in 4050GCC. LLVM's support is often implemented on an 'as-needed' basis, to support C 4051inline asm code which was supported by GCC. A mismatch in behavior between LLVM 4052and GCC likely indicates a bug in LLVM. 4053 4054Some constraint codes are typically supported by all targets: 4055 4056- ``r``: A register in the target's general purpose register class. 4057- ``m``: A memory address operand. It is target-specific what addressing modes 4058 are supported, typical examples are register, or register + register offset, 4059 or register + immediate offset (of some target-specific size). 4060- ``i``: An integer constant (of target-specific width). Allows either a simple 4061 immediate, or a relocatable value. 4062- ``n``: An integer constant -- *not* including relocatable values. 4063- ``s``: An integer constant, but allowing *only* relocatable values. 4064- ``X``: Allows an operand of any kind, no constraint whatsoever. Typically 4065 useful to pass a label for an asm branch or call. 4066 4067 .. FIXME: but that surely isn't actually okay to jump out of an asm 4068 block without telling llvm about the control transfer???) 4069 4070- ``{register-name}``: Requires exactly the named physical register. 4071 4072Other constraints are target-specific: 4073 4074AArch64: 4075 4076- ``z``: An immediate integer 0. Outputs ``WZR`` or ``XZR``, as appropriate. 4077- ``I``: An immediate integer valid for an ``ADD`` or ``SUB`` instruction, 4078 i.e. 0 to 4095 with optional shift by 12. 4079- ``J``: An immediate integer that, when negated, is valid for an ``ADD`` or 4080 ``SUB`` instruction, i.e. -1 to -4095 with optional left shift by 12. 4081- ``K``: An immediate integer that is valid for the 'bitmask immediate 32' of a 4082 logical instruction like ``AND``, ``EOR``, or ``ORR`` with a 32-bit register. 4083- ``L``: An immediate integer that is valid for the 'bitmask immediate 64' of a 4084 logical instruction like ``AND``, ``EOR``, or ``ORR`` with a 64-bit register. 4085- ``M``: An immediate integer for use with the ``MOV`` assembly alias on a 4086 32-bit register. This is a superset of ``K``: in addition to the bitmask 4087 immediate, also allows immediate integers which can be loaded with a single 4088 ``MOVZ`` or ``MOVL`` instruction. 4089- ``N``: An immediate integer for use with the ``MOV`` assembly alias on a 4090 64-bit register. This is a superset of ``L``. 4091- ``Q``: Memory address operand must be in a single register (no 4092 offsets). (However, LLVM currently does this for the ``m`` constraint as 4093 well.) 4094- ``r``: A 32 or 64-bit integer register (W* or X*). 4095- ``w``: A 32, 64, or 128-bit floating-point, SIMD or SVE vector register. 4096- ``x``: Like w, but restricted to registers 0 to 15 inclusive. 4097- ``y``: Like w, but restricted to SVE vector registers Z0 to Z7 inclusive. 4098- ``Upl``: One of the low eight SVE predicate registers (P0 to P7) 4099- ``Upa``: Any of the SVE predicate registers (P0 to P15) 4100 4101AMDGPU: 4102 4103- ``r``: A 32 or 64-bit integer register. 4104- ``[0-9]v``: The 32-bit VGPR register, number 0-9. 4105- ``[0-9]s``: The 32-bit SGPR register, number 0-9. 4106 4107 4108All ARM modes: 4109 4110- ``Q``, ``Um``, ``Un``, ``Uq``, ``Us``, ``Ut``, ``Uv``, ``Uy``: Memory address 4111 operand. Treated the same as operand ``m``, at the moment. 4112- ``Te``: An even general-purpose 32-bit integer register: ``r0,r2,...,r12,r14`` 4113- ``To``: An odd general-purpose 32-bit integer register: ``r1,r3,...,r11`` 4114 4115ARM and ARM's Thumb2 mode: 4116 4117- ``j``: An immediate integer between 0 and 65535 (valid for ``MOVW``) 4118- ``I``: An immediate integer valid for a data-processing instruction. 4119- ``J``: An immediate integer between -4095 and 4095. 4120- ``K``: An immediate integer whose bitwise inverse is valid for a 4121 data-processing instruction. (Can be used with template modifier "``B``" to 4122 print the inverted value). 4123- ``L``: An immediate integer whose negation is valid for a data-processing 4124 instruction. (Can be used with template modifier "``n``" to print the negated 4125 value). 4126- ``M``: A power of two or a integer between 0 and 32. 4127- ``N``: Invalid immediate constraint. 4128- ``O``: Invalid immediate constraint. 4129- ``r``: A general-purpose 32-bit integer register (``r0-r15``). 4130- ``l``: In Thumb2 mode, low 32-bit GPR registers (``r0-r7``). In ARM mode, same 4131 as ``r``. 4132- ``h``: In Thumb2 mode, a high 32-bit GPR register (``r8-r15``). In ARM mode, 4133 invalid. 4134- ``w``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges 4135 ``s0-s31``, ``d0-d31``, or ``q0-q15``, respectively. 4136- ``t``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges 4137 ``s0-s31``, ``d0-d15``, or ``q0-q7``, respectively. 4138- ``x``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges 4139 ``s0-s15``, ``d0-d7``, or ``q0-q3``, respectively. 4140 4141ARM's Thumb1 mode: 4142 4143- ``I``: An immediate integer between 0 and 255. 4144- ``J``: An immediate integer between -255 and -1. 4145- ``K``: An immediate integer between 0 and 255, with optional left-shift by 4146 some amount. 4147- ``L``: An immediate integer between -7 and 7. 4148- ``M``: An immediate integer which is a multiple of 4 between 0 and 1020. 4149- ``N``: An immediate integer between 0 and 31. 4150- ``O``: An immediate integer which is a multiple of 4 between -508 and 508. 4151- ``r``: A low 32-bit GPR register (``r0-r7``). 4152- ``l``: A low 32-bit GPR register (``r0-r7``). 4153- ``h``: A high GPR register (``r0-r7``). 4154- ``w``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges 4155 ``s0-s31``, ``d0-d31``, or ``q0-q15``, respectively. 4156- ``t``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges 4157 ``s0-s31``, ``d0-d15``, or ``q0-q7``, respectively. 4158- ``x``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges 4159 ``s0-s15``, ``d0-d7``, or ``q0-q3``, respectively. 4160 4161 4162Hexagon: 4163 4164- ``o``, ``v``: A memory address operand, treated the same as constraint ``m``, 4165 at the moment. 4166- ``r``: A 32 or 64-bit register. 4167 4168MSP430: 4169 4170- ``r``: An 8 or 16-bit register. 4171 4172MIPS: 4173 4174- ``I``: An immediate signed 16-bit integer. 4175- ``J``: An immediate integer zero. 4176- ``K``: An immediate unsigned 16-bit integer. 4177- ``L``: An immediate 32-bit integer, where the lower 16 bits are 0. 4178- ``N``: An immediate integer between -65535 and -1. 4179- ``O``: An immediate signed 15-bit integer. 4180- ``P``: An immediate integer between 1 and 65535. 4181- ``m``: A memory address operand. In MIPS-SE mode, allows a base address 4182 register plus 16-bit immediate offset. In MIPS mode, just a base register. 4183- ``R``: A memory address operand. In MIPS-SE mode, allows a base address 4184 register plus a 9-bit signed offset. In MIPS mode, the same as constraint 4185 ``m``. 4186- ``ZC``: A memory address operand, suitable for use in a ``pref``, ``ll``, or 4187 ``sc`` instruction on the given subtarget (details vary). 4188- ``r``, ``d``, ``y``: A 32 or 64-bit GPR register. 4189- ``f``: A 32 or 64-bit FPU register (``F0-F31``), or a 128-bit MSA register 4190 (``W0-W31``). In the case of MSA registers, it is recommended to use the ``w`` 4191 argument modifier for compatibility with GCC. 4192- ``c``: A 32-bit or 64-bit GPR register suitable for indirect jump (always 4193 ``25``). 4194- ``l``: The ``lo`` register, 32 or 64-bit. 4195- ``x``: Invalid. 4196 4197NVPTX: 4198 4199- ``b``: A 1-bit integer register. 4200- ``c`` or ``h``: A 16-bit integer register. 4201- ``r``: A 32-bit integer register. 4202- ``l`` or ``N``: A 64-bit integer register. 4203- ``f``: A 32-bit float register. 4204- ``d``: A 64-bit float register. 4205 4206 4207PowerPC: 4208 4209- ``I``: An immediate signed 16-bit integer. 4210- ``J``: An immediate unsigned 16-bit integer, shifted left 16 bits. 4211- ``K``: An immediate unsigned 16-bit integer. 4212- ``L``: An immediate signed 16-bit integer, shifted left 16 bits. 4213- ``M``: An immediate integer greater than 31. 4214- ``N``: An immediate integer that is an exact power of 2. 4215- ``O``: The immediate integer constant 0. 4216- ``P``: An immediate integer constant whose negation is a signed 16-bit 4217 constant. 4218- ``es``, ``o``, ``Q``, ``Z``, ``Zy``: A memory address operand, currently 4219 treated the same as ``m``. 4220- ``r``: A 32 or 64-bit integer register. 4221- ``b``: A 32 or 64-bit integer register, excluding ``R0`` (that is: 4222 ``R1-R31``). 4223- ``f``: A 32 or 64-bit float register (``F0-F31``), or when QPX is enabled, a 4224 128 or 256-bit QPX register (``Q0-Q31``; aliases the ``F`` registers). 4225- ``v``: For ``4 x f32`` or ``4 x f64`` types, when QPX is enabled, a 4226 128 or 256-bit QPX register (``Q0-Q31``), otherwise a 128-bit 4227 altivec vector register (``V0-V31``). 4228 4229 .. FIXME: is this a bug that v accepts QPX registers? I think this 4230 is supposed to only use the altivec vector registers? 4231 4232- ``y``: Condition register (``CR0-CR7``). 4233- ``wc``: An individual CR bit in a CR register. 4234- ``wa``, ``wd``, ``wf``: Any 128-bit VSX vector register, from the full VSX 4235 register set (overlapping both the floating-point and vector register files). 4236- ``ws``: A 32 or 64-bit floating-point register, from the full VSX register 4237 set. 4238 4239RISC-V: 4240 4241- ``A``: An address operand (using a general-purpose register, without an 4242 offset). 4243- ``I``: A 12-bit signed integer immediate operand. 4244- ``J``: A zero integer immediate operand. 4245- ``K``: A 5-bit unsigned integer immediate operand. 4246- ``f``: A 32- or 64-bit floating-point register (requires F or D extension). 4247- ``r``: A 32- or 64-bit general-purpose register (depending on the platform 4248 ``XLEN``). 4249 4250Sparc: 4251 4252- ``I``: An immediate 13-bit signed integer. 4253- ``r``: A 32-bit integer register. 4254- ``f``: Any floating-point register on SparcV8, or a floating-point 4255 register in the "low" half of the registers on SparcV9. 4256- ``e``: Any floating-point register. (Same as ``f`` on SparcV8.) 4257 4258SystemZ: 4259 4260- ``I``: An immediate unsigned 8-bit integer. 4261- ``J``: An immediate unsigned 12-bit integer. 4262- ``K``: An immediate signed 16-bit integer. 4263- ``L``: An immediate signed 20-bit integer. 4264- ``M``: An immediate integer 0x7fffffff. 4265- ``Q``: A memory address operand with a base address and a 12-bit immediate 4266 unsigned displacement. 4267- ``R``: A memory address operand with a base address, a 12-bit immediate 4268 unsigned displacement, and an index register. 4269- ``S``: A memory address operand with a base address and a 20-bit immediate 4270 signed displacement. 4271- ``T``: A memory address operand with a base address, a 20-bit immediate 4272 signed displacement, and an index register. 4273- ``r`` or ``d``: A 32, 64, or 128-bit integer register. 4274- ``a``: A 32, 64, or 128-bit integer address register (excludes R0, which in an 4275 address context evaluates as zero). 4276- ``h``: A 32-bit value in the high part of a 64bit data register 4277 (LLVM-specific) 4278- ``f``: A 32, 64, or 128-bit floating-point register. 4279 4280X86: 4281 4282- ``I``: An immediate integer between 0 and 31. 4283- ``J``: An immediate integer between 0 and 64. 4284- ``K``: An immediate signed 8-bit integer. 4285- ``L``: An immediate integer, 0xff or 0xffff or (in 64-bit mode only) 4286 0xffffffff. 4287- ``M``: An immediate integer between 0 and 3. 4288- ``N``: An immediate unsigned 8-bit integer. 4289- ``O``: An immediate integer between 0 and 127. 4290- ``e``: An immediate 32-bit signed integer. 4291- ``Z``: An immediate 32-bit unsigned integer. 4292- ``o``, ``v``: Treated the same as ``m``, at the moment. 4293- ``q``: An 8, 16, 32, or 64-bit register which can be accessed as an 8-bit 4294 ``l`` integer register. On X86-32, this is the ``a``, ``b``, ``c``, and ``d`` 4295 registers, and on X86-64, it is all of the integer registers. 4296- ``Q``: An 8, 16, 32, or 64-bit register which can be accessed as an 8-bit 4297 ``h`` integer register. This is the ``a``, ``b``, ``c``, and ``d`` registers. 4298- ``r`` or ``l``: An 8, 16, 32, or 64-bit integer register. 4299- ``R``: An 8, 16, 32, or 64-bit "legacy" integer register -- one which has 4300 existed since i386, and can be accessed without the REX prefix. 4301- ``f``: A 32, 64, or 80-bit '387 FPU stack pseudo-register. 4302- ``y``: A 64-bit MMX register, if MMX is enabled. 4303- ``x``: If SSE is enabled: a 32 or 64-bit scalar operand, or 128-bit vector 4304 operand in a SSE register. If AVX is also enabled, can also be a 256-bit 4305 vector operand in an AVX register. If AVX-512 is also enabled, can also be a 4306 512-bit vector operand in an AVX512 register, Otherwise, an error. 4307- ``Y``: The same as ``x``, if *SSE2* is enabled, otherwise an error. 4308- ``A``: Special case: allocates EAX first, then EDX, for a single operand (in 4309 32-bit mode, a 64-bit integer operand will get split into two registers). It 4310 is not recommended to use this constraint, as in 64-bit mode, the 64-bit 4311 operand will get allocated only to RAX -- if two 32-bit operands are needed, 4312 you're better off splitting it yourself, before passing it to the asm 4313 statement. 4314 4315XCore: 4316 4317- ``r``: A 32-bit integer register. 4318 4319 4320.. _inline-asm-modifiers: 4321 4322Asm template argument modifiers 4323^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 4324 4325In the asm template string, modifiers can be used on the operand reference, like 4326"``${0:n}``". 4327 4328The modifiers are, in general, expected to behave the same way they do in 4329GCC. LLVM's support is often implemented on an 'as-needed' basis, to support C 4330inline asm code which was supported by GCC. A mismatch in behavior between LLVM 4331and GCC likely indicates a bug in LLVM. 4332 4333Target-independent: 4334 4335- ``c``: Print an immediate integer constant unadorned, without 4336 the target-specific immediate punctuation (e.g. no ``$`` prefix). 4337- ``n``: Negate and print immediate integer constant unadorned, without the 4338 target-specific immediate punctuation (e.g. no ``$`` prefix). 4339- ``l``: Print as an unadorned label, without the target-specific label 4340 punctuation (e.g. no ``$`` prefix). 4341 4342AArch64: 4343 4344- ``w``: Print a GPR register with a ``w*`` name instead of ``x*`` name. E.g., 4345 instead of ``x30``, print ``w30``. 4346- ``x``: Print a GPR register with a ``x*`` name. (this is the default, anyhow). 4347- ``b``, ``h``, ``s``, ``d``, ``q``: Print a floating-point/SIMD register with a 4348 ``b*``, ``h*``, ``s*``, ``d*``, or ``q*`` name, rather than the default of 4349 ``v*``. 4350 4351AMDGPU: 4352 4353- ``r``: No effect. 4354 4355ARM: 4356 4357- ``a``: Print an operand as an address (with ``[`` and ``]`` surrounding a 4358 register). 4359- ``P``: No effect. 4360- ``q``: No effect. 4361- ``y``: Print a VFP single-precision register as an indexed double (e.g. print 4362 as ``d4[1]`` instead of ``s9``) 4363- ``B``: Bitwise invert and print an immediate integer constant without ``#`` 4364 prefix. 4365- ``L``: Print the low 16-bits of an immediate integer constant. 4366- ``M``: Print as a register set suitable for ldm/stm. Also prints *all* 4367 register operands subsequent to the specified one (!), so use carefully. 4368- ``Q``: Print the low-order register of a register-pair, or the low-order 4369 register of a two-register operand. 4370- ``R``: Print the high-order register of a register-pair, or the high-order 4371 register of a two-register operand. 4372- ``H``: Print the second register of a register-pair. (On a big-endian system, 4373 ``H`` is equivalent to ``Q``, and on little-endian system, ``H`` is equivalent 4374 to ``R``.) 4375 4376 .. FIXME: H doesn't currently support printing the second register 4377 of a two-register operand. 4378 4379- ``e``: Print the low doubleword register of a NEON quad register. 4380- ``f``: Print the high doubleword register of a NEON quad register. 4381- ``m``: Print the base register of a memory operand without the ``[`` and ``]`` 4382 adornment. 4383 4384Hexagon: 4385 4386- ``L``: Print the second register of a two-register operand. Requires that it 4387 has been allocated consecutively to the first. 4388 4389 .. FIXME: why is it restricted to consecutive ones? And there's 4390 nothing that ensures that happens, is there? 4391 4392- ``I``: Print the letter 'i' if the operand is an integer constant, otherwise 4393 nothing. Used to print 'addi' vs 'add' instructions. 4394 4395MSP430: 4396 4397No additional modifiers. 4398 4399MIPS: 4400 4401- ``X``: Print an immediate integer as hexadecimal 4402- ``x``: Print the low 16 bits of an immediate integer as hexadecimal. 4403- ``d``: Print an immediate integer as decimal. 4404- ``m``: Subtract one and print an immediate integer as decimal. 4405- ``z``: Print $0 if an immediate zero, otherwise print normally. 4406- ``L``: Print the low-order register of a two-register operand, or prints the 4407 address of the low-order word of a double-word memory operand. 4408 4409 .. FIXME: L seems to be missing memory operand support. 4410 4411- ``M``: Print the high-order register of a two-register operand, or prints the 4412 address of the high-order word of a double-word memory operand. 4413 4414 .. FIXME: M seems to be missing memory operand support. 4415 4416- ``D``: Print the second register of a two-register operand, or prints the 4417 second word of a double-word memory operand. (On a big-endian system, ``D`` is 4418 equivalent to ``L``, and on little-endian system, ``D`` is equivalent to 4419 ``M``.) 4420- ``w``: No effect. Provided for compatibility with GCC which requires this 4421 modifier in order to print MSA registers (``W0-W31``) with the ``f`` 4422 constraint. 4423 4424NVPTX: 4425 4426- ``r``: No effect. 4427 4428PowerPC: 4429 4430- ``L``: Print the second register of a two-register operand. Requires that it 4431 has been allocated consecutively to the first. 4432 4433 .. FIXME: why is it restricted to consecutive ones? And there's 4434 nothing that ensures that happens, is there? 4435 4436- ``I``: Print the letter 'i' if the operand is an integer constant, otherwise 4437 nothing. Used to print 'addi' vs 'add' instructions. 4438- ``y``: For a memory operand, prints formatter for a two-register X-form 4439 instruction. (Currently always prints ``r0,OPERAND``). 4440- ``U``: Prints 'u' if the memory operand is an update form, and nothing 4441 otherwise. (NOTE: LLVM does not support update form, so this will currently 4442 always print nothing) 4443- ``X``: Prints 'x' if the memory operand is an indexed form. (NOTE: LLVM does 4444 not support indexed form, so this will currently always print nothing) 4445 4446RISC-V: 4447 4448- ``i``: Print the letter 'i' if the operand is not a register, otherwise print 4449 nothing. Used to print 'addi' vs 'add' instructions, etc. 4450- ``z``: Print the register ``zero`` if an immediate zero, otherwise print 4451 normally. 4452 4453Sparc: 4454 4455- ``r``: No effect. 4456 4457SystemZ: 4458 4459SystemZ implements only ``n``, and does *not* support any of the other 4460target-independent modifiers. 4461 4462X86: 4463 4464- ``c``: Print an unadorned integer or symbol name. (The latter is 4465 target-specific behavior for this typically target-independent modifier). 4466- ``A``: Print a register name with a '``*``' before it. 4467- ``b``: Print an 8-bit register name (e.g. ``al``); do nothing on a memory 4468 operand. 4469- ``h``: Print the upper 8-bit register name (e.g. ``ah``); do nothing on a 4470 memory operand. 4471- ``w``: Print the 16-bit register name (e.g. ``ax``); do nothing on a memory 4472 operand. 4473- ``k``: Print the 32-bit register name (e.g. ``eax``); do nothing on a memory 4474 operand. 4475- ``q``: Print the 64-bit register name (e.g. ``rax``), if 64-bit registers are 4476 available, otherwise the 32-bit register name; do nothing on a memory operand. 4477- ``n``: Negate and print an unadorned integer, or, for operands other than an 4478 immediate integer (e.g. a relocatable symbol expression), print a '-' before 4479 the operand. (The behavior for relocatable symbol expressions is a 4480 target-specific behavior for this typically target-independent modifier) 4481- ``H``: Print a memory reference with additional offset +8. 4482- ``P``: Print a memory reference or operand for use as the argument of a call 4483 instruction. (E.g. omit ``(rip)``, even though it's PC-relative.) 4484 4485XCore: 4486 4487No additional modifiers. 4488 4489 4490Inline Asm Metadata 4491^^^^^^^^^^^^^^^^^^^ 4492 4493The call instructions that wrap inline asm nodes may have a 4494"``!srcloc``" MDNode attached to it that contains a list of constant 4495integers. If present, the code generator will use the integer as the 4496location cookie value when report errors through the ``LLVMContext`` 4497error reporting mechanisms. This allows a front-end to correlate backend 4498errors that occur with inline asm back to the source code that produced 4499it. For example: 4500 4501.. code-block:: llvm 4502 4503 call void asm sideeffect "something bad", ""(), !srcloc !42 4504 ... 4505 !42 = !{ i32 1234567 } 4506 4507It is up to the front-end to make sense of the magic numbers it places 4508in the IR. If the MDNode contains multiple constants, the code generator 4509will use the one that corresponds to the line of the asm that the error 4510occurs on. 4511 4512.. _metadata: 4513 4514Metadata 4515======== 4516 4517LLVM IR allows metadata to be attached to instructions in the program 4518that can convey extra information about the code to the optimizers and 4519code generator. One example application of metadata is source-level 4520debug information. There are two metadata primitives: strings and nodes. 4521 4522Metadata does not have a type, and is not a value. If referenced from a 4523``call`` instruction, it uses the ``metadata`` type. 4524 4525All metadata are identified in syntax by a exclamation point ('``!``'). 4526 4527.. _metadata-string: 4528 4529Metadata Nodes and Metadata Strings 4530----------------------------------- 4531 4532A metadata string is a string surrounded by double quotes. It can 4533contain any character by escaping non-printable characters with 4534"``\xx``" where "``xx``" is the two digit hex code. For example: 4535"``!"test\00"``". 4536 4537Metadata nodes are represented with notation similar to structure 4538constants (a comma separated list of elements, surrounded by braces and 4539preceded by an exclamation point). Metadata nodes can have any values as 4540their operand. For example: 4541 4542.. code-block:: llvm 4543 4544 !{ !"test\00", i32 10} 4545 4546Metadata nodes that aren't uniqued use the ``distinct`` keyword. For example: 4547 4548.. code-block:: text 4549 4550 !0 = distinct !{!"test\00", i32 10} 4551 4552``distinct`` nodes are useful when nodes shouldn't be merged based on their 4553content. They can also occur when transformations cause uniquing collisions 4554when metadata operands change. 4555 4556A :ref:`named metadata <namedmetadatastructure>` is a collection of 4557metadata nodes, which can be looked up in the module symbol table. For 4558example: 4559 4560.. code-block:: llvm 4561 4562 !foo = !{!4, !3} 4563 4564Metadata can be used as function arguments. Here the ``llvm.dbg.value`` 4565intrinsic is using three metadata arguments: 4566 4567.. code-block:: llvm 4568 4569 call void @llvm.dbg.value(metadata !24, metadata !25, metadata !26) 4570 4571Metadata can be attached to an instruction. Here metadata ``!21`` is attached 4572to the ``add`` instruction using the ``!dbg`` identifier: 4573 4574.. code-block:: llvm 4575 4576 %indvar.next = add i64 %indvar, 1, !dbg !21 4577 4578Metadata can also be attached to a function or a global variable. Here metadata 4579``!22`` is attached to the ``f1`` and ``f2 functions, and the globals ``g1`` 4580and ``g2`` using the ``!dbg`` identifier: 4581 4582.. code-block:: llvm 4583 4584 declare !dbg !22 void @f1() 4585 define void @f2() !dbg !22 { 4586 ret void 4587 } 4588 4589 @g1 = global i32 0, !dbg !22 4590 @g2 = external global i32, !dbg !22 4591 4592A transformation is required to drop any metadata attachment that it does not 4593know or know it can't preserve. Currently there is an exception for metadata 4594attachment to globals for ``!type`` and ``!absolute_symbol`` which can't be 4595unconditionally dropped unless the global is itself deleted. 4596 4597Metadata attached to a module using named metadata may not be dropped, with 4598the exception of debug metadata (named metadata with the name ``!llvm.dbg.*``). 4599 4600More information about specific metadata nodes recognized by the 4601optimizers and code generator is found below. 4602 4603.. _specialized-metadata: 4604 4605Specialized Metadata Nodes 4606^^^^^^^^^^^^^^^^^^^^^^^^^^ 4607 4608Specialized metadata nodes are custom data structures in metadata (as opposed 4609to generic tuples). Their fields are labelled, and can be specified in any 4610order. 4611 4612These aren't inherently debug info centric, but currently all the specialized 4613metadata nodes are related to debug info. 4614 4615.. _DICompileUnit: 4616 4617DICompileUnit 4618""""""""""""" 4619 4620``DICompileUnit`` nodes represent a compile unit. The ``enums:``, 4621``retainedTypes:``, ``globals:``, ``imports:`` and ``macros:`` fields are tuples 4622containing the debug info to be emitted along with the compile unit, regardless 4623of code optimizations (some nodes are only emitted if there are references to 4624them from instructions). The ``debugInfoForProfiling:`` field is a boolean 4625indicating whether or not line-table discriminators are updated to provide 4626more-accurate debug info for profiling results. 4627 4628.. code-block:: text 4629 4630 !0 = !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang", 4631 isOptimized: true, flags: "-O2", runtimeVersion: 2, 4632 splitDebugFilename: "abc.debug", emissionKind: FullDebug, 4633 enums: !2, retainedTypes: !3, globals: !4, imports: !5, 4634 macros: !6, dwoId: 0x0abcd) 4635 4636Compile unit descriptors provide the root scope for objects declared in a 4637specific compilation unit. File descriptors are defined using this scope. These 4638descriptors are collected by a named metadata node ``!llvm.dbg.cu``. They keep 4639track of global variables, type information, and imported entities (declarations 4640and namespaces). 4641 4642.. _DIFile: 4643 4644DIFile 4645"""""" 4646 4647``DIFile`` nodes represent files. The ``filename:`` can include slashes. 4648 4649.. code-block:: none 4650 4651 !0 = !DIFile(filename: "path/to/file", directory: "/path/to/dir", 4652 checksumkind: CSK_MD5, 4653 checksum: "000102030405060708090a0b0c0d0e0f") 4654 4655Files are sometimes used in ``scope:`` fields, and are the only valid target 4656for ``file:`` fields. 4657Valid values for ``checksumkind:`` field are: {CSK_None, CSK_MD5, CSK_SHA1, CSK_SHA256} 4658 4659.. _DIBasicType: 4660 4661DIBasicType 4662""""""""""" 4663 4664``DIBasicType`` nodes represent primitive types, such as ``int``, ``bool`` and 4665``float``. ``tag:`` defaults to ``DW_TAG_base_type``. 4666 4667.. code-block:: text 4668 4669 !0 = !DIBasicType(name: "unsigned char", size: 8, align: 8, 4670 encoding: DW_ATE_unsigned_char) 4671 !1 = !DIBasicType(tag: DW_TAG_unspecified_type, name: "decltype(nullptr)") 4672 4673The ``encoding:`` describes the details of the type. Usually it's one of the 4674following: 4675 4676.. code-block:: text 4677 4678 DW_ATE_address = 1 4679 DW_ATE_boolean = 2 4680 DW_ATE_float = 4 4681 DW_ATE_signed = 5 4682 DW_ATE_signed_char = 6 4683 DW_ATE_unsigned = 7 4684 DW_ATE_unsigned_char = 8 4685 4686.. _DISubroutineType: 4687 4688DISubroutineType 4689"""""""""""""""" 4690 4691``DISubroutineType`` nodes represent subroutine types. Their ``types:`` field 4692refers to a tuple; the first operand is the return type, while the rest are the 4693types of the formal arguments in order. If the first operand is ``null``, that 4694represents a function with no return value (such as ``void foo() {}`` in C++). 4695 4696.. code-block:: text 4697 4698 !0 = !BasicType(name: "int", size: 32, align: 32, DW_ATE_signed) 4699 !1 = !BasicType(name: "char", size: 8, align: 8, DW_ATE_signed_char) 4700 !2 = !DISubroutineType(types: !{null, !0, !1}) ; void (int, char) 4701 4702.. _DIDerivedType: 4703 4704DIDerivedType 4705""""""""""""" 4706 4707``DIDerivedType`` nodes represent types derived from other types, such as 4708qualified types. 4709 4710.. code-block:: text 4711 4712 !0 = !DIBasicType(name: "unsigned char", size: 8, align: 8, 4713 encoding: DW_ATE_unsigned_char) 4714 !1 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !0, size: 32, 4715 align: 32) 4716 4717The following ``tag:`` values are valid: 4718 4719.. code-block:: text 4720 4721 DW_TAG_member = 13 4722 DW_TAG_pointer_type = 15 4723 DW_TAG_reference_type = 16 4724 DW_TAG_typedef = 22 4725 DW_TAG_inheritance = 28 4726 DW_TAG_ptr_to_member_type = 31 4727 DW_TAG_const_type = 38 4728 DW_TAG_friend = 42 4729 DW_TAG_volatile_type = 53 4730 DW_TAG_restrict_type = 55 4731 DW_TAG_atomic_type = 71 4732 4733.. _DIDerivedTypeMember: 4734 4735``DW_TAG_member`` is used to define a member of a :ref:`composite type 4736<DICompositeType>`. The type of the member is the ``baseType:``. The 4737``offset:`` is the member's bit offset. If the composite type has an ODR 4738``identifier:`` and does not set ``flags: DIFwdDecl``, then the member is 4739uniqued based only on its ``name:`` and ``scope:``. 4740 4741``DW_TAG_inheritance`` and ``DW_TAG_friend`` are used in the ``elements:`` 4742field of :ref:`composite types <DICompositeType>` to describe parents and 4743friends. 4744 4745``DW_TAG_typedef`` is used to provide a name for the ``baseType:``. 4746 4747``DW_TAG_pointer_type``, ``DW_TAG_reference_type``, ``DW_TAG_const_type``, 4748``DW_TAG_volatile_type``, ``DW_TAG_restrict_type`` and ``DW_TAG_atomic_type`` 4749are used to qualify the ``baseType:``. 4750 4751Note that the ``void *`` type is expressed as a type derived from NULL. 4752 4753.. _DICompositeType: 4754 4755DICompositeType 4756""""""""""""""" 4757 4758``DICompositeType`` nodes represent types composed of other types, like 4759structures and unions. ``elements:`` points to a tuple of the composed types. 4760 4761If the source language supports ODR, the ``identifier:`` field gives the unique 4762identifier used for type merging between modules. When specified, 4763:ref:`subprogram declarations <DISubprogramDeclaration>` and :ref:`member 4764derived types <DIDerivedTypeMember>` that reference the ODR-type in their 4765``scope:`` change uniquing rules. 4766 4767For a given ``identifier:``, there should only be a single composite type that 4768does not have ``flags: DIFlagFwdDecl`` set. LLVM tools that link modules 4769together will unique such definitions at parse time via the ``identifier:`` 4770field, even if the nodes are ``distinct``. 4771 4772.. code-block:: text 4773 4774 !0 = !DIEnumerator(name: "SixKind", value: 7) 4775 !1 = !DIEnumerator(name: "SevenKind", value: 7) 4776 !2 = !DIEnumerator(name: "NegEightKind", value: -8) 4777 !3 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "Enum", file: !12, 4778 line: 2, size: 32, align: 32, identifier: "_M4Enum", 4779 elements: !{!0, !1, !2}) 4780 4781The following ``tag:`` values are valid: 4782 4783.. code-block:: text 4784 4785 DW_TAG_array_type = 1 4786 DW_TAG_class_type = 2 4787 DW_TAG_enumeration_type = 4 4788 DW_TAG_structure_type = 19 4789 DW_TAG_union_type = 23 4790 4791For ``DW_TAG_array_type``, the ``elements:`` should be :ref:`subrange 4792descriptors <DISubrange>`, each representing the range of subscripts at that 4793level of indexing. The ``DIFlagVector`` flag to ``flags:`` indicates that an 4794array type is a native packed vector. 4795 4796For ``DW_TAG_enumeration_type``, the ``elements:`` should be :ref:`enumerator 4797descriptors <DIEnumerator>`, each representing the definition of an enumeration 4798value for the set. All enumeration type descriptors are collected in the 4799``enums:`` field of the :ref:`compile unit <DICompileUnit>`. 4800 4801For ``DW_TAG_structure_type``, ``DW_TAG_class_type``, and 4802``DW_TAG_union_type``, the ``elements:`` should be :ref:`derived types 4803<DIDerivedType>` with ``tag: DW_TAG_member``, ``tag: DW_TAG_inheritance``, or 4804``tag: DW_TAG_friend``; or :ref:`subprograms <DISubprogram>` with 4805``isDefinition: false``. 4806 4807.. _DISubrange: 4808 4809DISubrange 4810"""""""""" 4811 4812``DISubrange`` nodes are the elements for ``DW_TAG_array_type`` variants of 4813:ref:`DICompositeType`. 4814 4815- ``count: -1`` indicates an empty array. 4816- ``count: !9`` describes the count with a :ref:`DILocalVariable`. 4817- ``count: !11`` describes the count with a :ref:`DIGlobalVariable`. 4818 4819.. code-block:: text 4820 4821 !0 = !DISubrange(count: 5, lowerBound: 0) ; array counting from 0 4822 !1 = !DISubrange(count: 5, lowerBound: 1) ; array counting from 1 4823 !2 = !DISubrange(count: -1) ; empty array. 4824 4825 ; Scopes used in rest of example 4826 !6 = !DIFile(filename: "vla.c", directory: "/path/to/file") 4827 !7 = distinct !DICompileUnit(language: DW_LANG_C99, file: !6) 4828 !8 = distinct !DISubprogram(name: "foo", scope: !7, file: !6, line: 5) 4829 4830 ; Use of local variable as count value 4831 !9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 4832 !10 = !DILocalVariable(name: "count", scope: !8, file: !6, line: 42, type: !9) 4833 !11 = !DISubrange(count: !10, lowerBound: 0) 4834 4835 ; Use of global variable as count value 4836 !12 = !DIGlobalVariable(name: "count", scope: !8, file: !6, line: 22, type: !9) 4837 !13 = !DISubrange(count: !12, lowerBound: 0) 4838 4839.. _DIEnumerator: 4840 4841DIEnumerator 4842"""""""""""" 4843 4844``DIEnumerator`` nodes are the elements for ``DW_TAG_enumeration_type`` 4845variants of :ref:`DICompositeType`. 4846 4847.. code-block:: text 4848 4849 !0 = !DIEnumerator(name: "SixKind", value: 7) 4850 !1 = !DIEnumerator(name: "SevenKind", value: 7) 4851 !2 = !DIEnumerator(name: "NegEightKind", value: -8) 4852 4853DITemplateTypeParameter 4854""""""""""""""""""""""" 4855 4856``DITemplateTypeParameter`` nodes represent type parameters to generic source 4857language constructs. They are used (optionally) in :ref:`DICompositeType` and 4858:ref:`DISubprogram` ``templateParams:`` fields. 4859 4860.. code-block:: text 4861 4862 !0 = !DITemplateTypeParameter(name: "Ty", type: !1) 4863 4864DITemplateValueParameter 4865"""""""""""""""""""""""" 4866 4867``DITemplateValueParameter`` nodes represent value parameters to generic source 4868language constructs. ``tag:`` defaults to ``DW_TAG_template_value_parameter``, 4869but if specified can also be set to ``DW_TAG_GNU_template_template_param`` or 4870``DW_TAG_GNU_template_param_pack``. They are used (optionally) in 4871:ref:`DICompositeType` and :ref:`DISubprogram` ``templateParams:`` fields. 4872 4873.. code-block:: text 4874 4875 !0 = !DITemplateValueParameter(name: "Ty", type: !1, value: i32 7) 4876 4877DINamespace 4878""""""""""" 4879 4880``DINamespace`` nodes represent namespaces in the source language. 4881 4882.. code-block:: text 4883 4884 !0 = !DINamespace(name: "myawesomeproject", scope: !1, file: !2, line: 7) 4885 4886.. _DIGlobalVariable: 4887 4888DIGlobalVariable 4889"""""""""""""""" 4890 4891``DIGlobalVariable`` nodes represent global variables in the source language. 4892 4893.. code-block:: text 4894 4895 @foo = global i32, !dbg !0 4896 !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) 4897 !1 = !DIGlobalVariable(name: "foo", linkageName: "foo", scope: !2, 4898 file: !3, line: 7, type: !4, isLocal: true, 4899 isDefinition: false, declaration: !5) 4900 4901 4902DIGlobalVariableExpression 4903"""""""""""""""""""""""""" 4904 4905``DIGlobalVariableExpression`` nodes tie a :ref:`DIGlobalVariable` together 4906with a :ref:`DIExpression`. 4907 4908.. code-block:: text 4909 4910 @lower = global i32, !dbg !0 4911 @upper = global i32, !dbg !1 4912 !0 = !DIGlobalVariableExpression( 4913 var: !2, 4914 expr: !DIExpression(DW_OP_LLVM_fragment, 0, 32) 4915 ) 4916 !1 = !DIGlobalVariableExpression( 4917 var: !2, 4918 expr: !DIExpression(DW_OP_LLVM_fragment, 32, 32) 4919 ) 4920 !2 = !DIGlobalVariable(name: "split64", linkageName: "split64", scope: !3, 4921 file: !4, line: 8, type: !5, declaration: !6) 4922 4923All global variable expressions should be referenced by the `globals:` field of 4924a :ref:`compile unit <DICompileUnit>`. 4925 4926.. _DISubprogram: 4927 4928DISubprogram 4929"""""""""""" 4930 4931``DISubprogram`` nodes represent functions from the source language. A 4932distinct ``DISubprogram`` may be attached to a function definition using 4933``!dbg`` metadata. A unique ``DISubprogram`` may be attached to a function 4934declaration used for call site debug info. The ``variables:`` field points at 4935:ref:`variables <DILocalVariable>` that must be retained, even if their IR 4936counterparts are optimized out of the IR. The ``type:`` field must point at an 4937:ref:`DISubroutineType`. 4938 4939.. _DISubprogramDeclaration: 4940 4941When ``isDefinition: false``, subprograms describe a declaration in the type 4942tree as opposed to a definition of a function. If the scope is a composite 4943type with an ODR ``identifier:`` and that does not set ``flags: DIFwdDecl``, 4944then the subprogram declaration is uniqued based only on its ``linkageName:`` 4945and ``scope:``. 4946 4947.. code-block:: text 4948 4949 define void @_Z3foov() !dbg !0 { 4950 ... 4951 } 4952 4953 !0 = distinct !DISubprogram(name: "foo", linkageName: "_Zfoov", scope: !1, 4954 file: !2, line: 7, type: !3, isLocal: true, 4955 isDefinition: true, scopeLine: 8, 4956 containingType: !4, 4957 virtuality: DW_VIRTUALITY_pure_virtual, 4958 virtualIndex: 10, flags: DIFlagPrototyped, 4959 isOptimized: true, unit: !5, templateParams: !6, 4960 declaration: !7, variables: !8, thrownTypes: !9) 4961 4962.. _DILexicalBlock: 4963 4964DILexicalBlock 4965"""""""""""""" 4966 4967``DILexicalBlock`` nodes describe nested blocks within a :ref:`subprogram 4968<DISubprogram>`. The line number and column numbers are used to distinguish 4969two lexical blocks at same depth. They are valid targets for ``scope:`` 4970fields. 4971 4972.. code-block:: text 4973 4974 !0 = distinct !DILexicalBlock(scope: !1, file: !2, line: 7, column: 35) 4975 4976Usually lexical blocks are ``distinct`` to prevent node merging based on 4977operands. 4978 4979.. _DILexicalBlockFile: 4980 4981DILexicalBlockFile 4982"""""""""""""""""" 4983 4984``DILexicalBlockFile`` nodes are used to discriminate between sections of a 4985:ref:`lexical block <DILexicalBlock>`. The ``file:`` field can be changed to 4986indicate textual inclusion, or the ``discriminator:`` field can be used to 4987discriminate between control flow within a single block in the source language. 4988 4989.. code-block:: text 4990 4991 !0 = !DILexicalBlock(scope: !3, file: !4, line: 7, column: 35) 4992 !1 = !DILexicalBlockFile(scope: !0, file: !4, discriminator: 0) 4993 !2 = !DILexicalBlockFile(scope: !0, file: !4, discriminator: 1) 4994 4995.. _DILocation: 4996 4997DILocation 4998"""""""""" 4999 5000``DILocation`` nodes represent source debug locations. The ``scope:`` field is 5001mandatory, and points at an :ref:`DILexicalBlockFile`, an 5002:ref:`DILexicalBlock`, or an :ref:`DISubprogram`. 5003 5004.. code-block:: text 5005 5006 !0 = !DILocation(line: 2900, column: 42, scope: !1, inlinedAt: !2) 5007 5008.. _DILocalVariable: 5009 5010DILocalVariable 5011""""""""""""""" 5012 5013``DILocalVariable`` nodes represent local variables in the source language. If 5014the ``arg:`` field is set to non-zero, then this variable is a subprogram 5015parameter, and it will be included in the ``variables:`` field of its 5016:ref:`DISubprogram`. 5017 5018.. code-block:: text 5019 5020 !0 = !DILocalVariable(name: "this", arg: 1, scope: !3, file: !2, line: 7, 5021 type: !3, flags: DIFlagArtificial) 5022 !1 = !DILocalVariable(name: "x", arg: 2, scope: !4, file: !2, line: 7, 5023 type: !3) 5024 !2 = !DILocalVariable(name: "y", scope: !5, file: !2, line: 7, type: !3) 5025 5026.. _DIExpression: 5027 5028DIExpression 5029"""""""""""" 5030 5031``DIExpression`` nodes represent expressions that are inspired by the DWARF 5032expression language. They are used in :ref:`debug intrinsics<dbg_intrinsics>` 5033(such as ``llvm.dbg.declare`` and ``llvm.dbg.value``) to describe how the 5034referenced LLVM variable relates to the source language variable. Debug 5035intrinsics are interpreted left-to-right: start by pushing the value/address 5036operand of the intrinsic onto a stack, then repeatedly push and evaluate 5037opcodes from the DIExpression until the final variable description is produced. 5038 5039The current supported opcode vocabulary is limited: 5040 5041- ``DW_OP_deref`` dereferences the top of the expression stack. 5042- ``DW_OP_plus`` pops the last two entries from the expression stack, adds 5043 them together and appends the result to the expression stack. 5044- ``DW_OP_minus`` pops the last two entries from the expression stack, subtracts 5045 the last entry from the second last entry and appends the result to the 5046 expression stack. 5047- ``DW_OP_plus_uconst, 93`` adds ``93`` to the working expression. 5048- ``DW_OP_LLVM_fragment, 16, 8`` specifies the offset and size (``16`` and ``8`` 5049 here, respectively) of the variable fragment from the working expression. Note 5050 that contrary to DW_OP_bit_piece, the offset is describing the location 5051 within the described source variable. 5052- ``DW_OP_LLVM_convert, 16, DW_ATE_signed`` specifies a bit size and encoding 5053 (``16`` and ``DW_ATE_signed`` here, respectively) to which the top of the 5054 expression stack is to be converted. Maps into a ``DW_OP_convert`` operation 5055 that references a base type constructed from the supplied values. 5056- ``DW_OP_LLVM_tag_offset, tag_offset`` specifies that a memory tag should be 5057 optionally applied to the pointer. The memory tag is derived from the 5058 given tag offset in an implementation-defined manner. 5059- ``DW_OP_swap`` swaps top two stack entries. 5060- ``DW_OP_xderef`` provides extended dereference mechanism. The entry at the top 5061 of the stack is treated as an address. The second stack entry is treated as an 5062 address space identifier. 5063- ``DW_OP_stack_value`` marks a constant value. 5064- ``DW_OP_LLVM_entry_value, N`` can only appear at the beginning of a 5065 ``DIExpression``, and it specifies that all register and memory read 5066 operations for the debug value instruction's value/address operand and for 5067 the ``(N - 1)`` operations immediately following the 5068 ``DW_OP_LLVM_entry_value`` refer to their respective values at function 5069 entry. For example, ``!DIExpression(DW_OP_LLVM_entry_value, 1, 5070 DW_OP_plus_uconst, 123, DW_OP_stack_value)`` specifies an expression where 5071 the entry value of the debug value instruction's value/address operand is 5072 pushed to the stack, and is added with 123. Due to framework limitations 5073 ``N`` can currently only be 1. 5074 5075 ``DW_OP_LLVM_entry_value`` is only legal in MIR. The operation is introduced 5076 by the ``LiveDebugValues`` pass; currently only for function parameters that 5077 are unmodified throughout a function and that are described as simple 5078 register location descriptions. The operation is also introduced by the 5079 ``AsmPrinter`` pass when a call site parameter value 5080 (``DW_AT_call_site_parameter_value``) is represented as entry value of the 5081 parameter. 5082- ``DW_OP_breg`` (or ``DW_OP_bregx``) represents a content on the provided 5083 signed offset of the specified register. The opcode is only generated by the 5084 ``AsmPrinter`` pass to describe call site parameter value which requires an 5085 expression over two registers. 5086 5087DWARF specifies three kinds of simple location descriptions: Register, memory, 5088and implicit location descriptions. Note that a location description is 5089defined over certain ranges of a program, i.e the location of a variable may 5090change over the course of the program. Register and memory location 5091descriptions describe the *concrete location* of a source variable (in the 5092sense that a debugger might modify its value), whereas *implicit locations* 5093describe merely the actual *value* of a source variable which might not exist 5094in registers or in memory (see ``DW_OP_stack_value``). 5095 5096A ``llvm.dbg.addr`` or ``llvm.dbg.declare`` intrinsic describes an indirect 5097value (the address) of a source variable. The first operand of the intrinsic 5098must be an address of some kind. A DIExpression attached to the intrinsic 5099refines this address to produce a concrete location for the source variable. 5100 5101A ``llvm.dbg.value`` intrinsic describes the direct value of a source variable. 5102The first operand of the intrinsic may be a direct or indirect value. A 5103DIExpression attached to the intrinsic refines the first operand to produce a 5104direct value. For example, if the first operand is an indirect value, it may be 5105necessary to insert ``DW_OP_deref`` into the DIExpression in order to produce a 5106valid debug intrinsic. 5107 5108.. note:: 5109 5110 A DIExpression is interpreted in the same way regardless of which kind of 5111 debug intrinsic it's attached to. 5112 5113.. code-block:: text 5114 5115 !0 = !DIExpression(DW_OP_deref) 5116 !1 = !DIExpression(DW_OP_plus_uconst, 3) 5117 !1 = !DIExpression(DW_OP_constu, 3, DW_OP_plus) 5118 !2 = !DIExpression(DW_OP_bit_piece, 3, 7) 5119 !3 = !DIExpression(DW_OP_deref, DW_OP_constu, 3, DW_OP_plus, DW_OP_LLVM_fragment, 3, 7) 5120 !4 = !DIExpression(DW_OP_constu, 2, DW_OP_swap, DW_OP_xderef) 5121 !5 = !DIExpression(DW_OP_constu, 42, DW_OP_stack_value) 5122 5123DIFlags 5124""""""""""""""" 5125 5126These flags encode various properties of DINodes. 5127 5128The `ExportSymbols` flag marks a class, struct or union whose members 5129may be referenced as if they were defined in the containing class or 5130union. This flag is used to decide whether the DW_AT_export_symbols can 5131be used for the structure type. 5132 5133DIObjCProperty 5134"""""""""""""" 5135 5136``DIObjCProperty`` nodes represent Objective-C property nodes. 5137 5138.. code-block:: text 5139 5140 !3 = !DIObjCProperty(name: "foo", file: !1, line: 7, setter: "setFoo", 5141 getter: "getFoo", attributes: 7, type: !2) 5142 5143DIImportedEntity 5144"""""""""""""""" 5145 5146``DIImportedEntity`` nodes represent entities (such as modules) imported into a 5147compile unit. 5148 5149.. code-block:: text 5150 5151 !2 = !DIImportedEntity(tag: DW_TAG_imported_module, name: "foo", scope: !0, 5152 entity: !1, line: 7) 5153 5154DIMacro 5155""""""" 5156 5157``DIMacro`` nodes represent definition or undefinition of a macro identifiers. 5158The ``name:`` field is the macro identifier, followed by macro parameters when 5159defining a function-like macro, and the ``value`` field is the token-string 5160used to expand the macro identifier. 5161 5162.. code-block:: text 5163 5164 !2 = !DIMacro(macinfo: DW_MACINFO_define, line: 7, name: "foo(x)", 5165 value: "((x) + 1)") 5166 !3 = !DIMacro(macinfo: DW_MACINFO_undef, line: 30, name: "foo") 5167 5168DIMacroFile 5169""""""""""" 5170 5171``DIMacroFile`` nodes represent inclusion of source files. 5172The ``nodes:`` field is a list of ``DIMacro`` and ``DIMacroFile`` nodes that 5173appear in the included source file. 5174 5175.. code-block:: text 5176 5177 !2 = !DIMacroFile(macinfo: DW_MACINFO_start_file, line: 7, file: !2, 5178 nodes: !3) 5179 5180'``tbaa``' Metadata 5181^^^^^^^^^^^^^^^^^^^ 5182 5183In LLVM IR, memory does not have types, so LLVM's own type system is not 5184suitable for doing type based alias analysis (TBAA). Instead, metadata is 5185added to the IR to describe a type system of a higher level language. This 5186can be used to implement C/C++ strict type aliasing rules, but it can also 5187be used to implement custom alias analysis behavior for other languages. 5188 5189This description of LLVM's TBAA system is broken into two parts: 5190:ref:`Semantics<tbaa_node_semantics>` talks about high level issues, and 5191:ref:`Representation<tbaa_node_representation>` talks about the metadata 5192encoding of various entities. 5193 5194It is always possible to trace any TBAA node to a "root" TBAA node (details 5195in the :ref:`Representation<tbaa_node_representation>` section). TBAA 5196nodes with different roots have an unknown aliasing relationship, and LLVM 5197conservatively infers ``MayAlias`` between them. The rules mentioned in 5198this section only pertain to TBAA nodes living under the same root. 5199 5200.. _tbaa_node_semantics: 5201 5202Semantics 5203""""""""" 5204 5205The TBAA metadata system, referred to as "struct path TBAA" (not to be 5206confused with ``tbaa.struct``), consists of the following high level 5207concepts: *Type Descriptors*, further subdivided into scalar type 5208descriptors and struct type descriptors; and *Access Tags*. 5209 5210**Type descriptors** describe the type system of the higher level language 5211being compiled. **Scalar type descriptors** describe types that do not 5212contain other types. Each scalar type has a parent type, which must also 5213be a scalar type or the TBAA root. Via this parent relation, scalar types 5214within a TBAA root form a tree. **Struct type descriptors** denote types 5215that contain a sequence of other type descriptors, at known offsets. These 5216contained type descriptors can either be struct type descriptors themselves 5217or scalar type descriptors. 5218 5219**Access tags** are metadata nodes attached to load and store instructions. 5220Access tags use type descriptors to describe the *location* being accessed 5221in terms of the type system of the higher level language. Access tags are 5222tuples consisting of a base type, an access type and an offset. The base 5223type is a scalar type descriptor or a struct type descriptor, the access 5224type is a scalar type descriptor, and the offset is a constant integer. 5225 5226The access tag ``(BaseTy, AccessTy, Offset)`` can describe one of two 5227things: 5228 5229 * If ``BaseTy`` is a struct type, the tag describes a memory access (load 5230 or store) of a value of type ``AccessTy`` contained in the struct type 5231 ``BaseTy`` at offset ``Offset``. 5232 5233 * If ``BaseTy`` is a scalar type, ``Offset`` must be 0 and ``BaseTy`` and 5234 ``AccessTy`` must be the same; and the access tag describes a scalar 5235 access with scalar type ``AccessTy``. 5236 5237We first define an ``ImmediateParent`` relation on ``(BaseTy, Offset)`` 5238tuples this way: 5239 5240 * If ``BaseTy`` is a scalar type then ``ImmediateParent(BaseTy, 0)`` is 5241 ``(ParentTy, 0)`` where ``ParentTy`` is the parent of the scalar type as 5242 described in the TBAA metadata. ``ImmediateParent(BaseTy, Offset)`` is 5243 undefined if ``Offset`` is non-zero. 5244 5245 * If ``BaseTy`` is a struct type then ``ImmediateParent(BaseTy, Offset)`` 5246 is ``(NewTy, NewOffset)`` where ``NewTy`` is the type contained in 5247 ``BaseTy`` at offset ``Offset`` and ``NewOffset`` is ``Offset`` adjusted 5248 to be relative within that inner type. 5249 5250A memory access with an access tag ``(BaseTy1, AccessTy1, Offset1)`` 5251aliases a memory access with an access tag ``(BaseTy2, AccessTy2, 5252Offset2)`` if either ``(BaseTy1, Offset1)`` is reachable from ``(Base2, 5253Offset2)`` via the ``Parent`` relation or vice versa. 5254 5255As a concrete example, the type descriptor graph for the following program 5256 5257.. code-block:: c 5258 5259 struct Inner { 5260 int i; // offset 0 5261 float f; // offset 4 5262 }; 5263 5264 struct Outer { 5265 float f; // offset 0 5266 double d; // offset 4 5267 struct Inner inner_a; // offset 12 5268 }; 5269 5270 void f(struct Outer* outer, struct Inner* inner, float* f, int* i, char* c) { 5271 outer->f = 0; // tag0: (OuterStructTy, FloatScalarTy, 0) 5272 outer->inner_a.i = 0; // tag1: (OuterStructTy, IntScalarTy, 12) 5273 outer->inner_a.f = 0.0; // tag2: (OuterStructTy, FloatScalarTy, 16) 5274 *f = 0.0; // tag3: (FloatScalarTy, FloatScalarTy, 0) 5275 } 5276 5277is (note that in C and C++, ``char`` can be used to access any arbitrary 5278type): 5279 5280.. code-block:: text 5281 5282 Root = "TBAA Root" 5283 CharScalarTy = ("char", Root, 0) 5284 FloatScalarTy = ("float", CharScalarTy, 0) 5285 DoubleScalarTy = ("double", CharScalarTy, 0) 5286 IntScalarTy = ("int", CharScalarTy, 0) 5287 InnerStructTy = {"Inner" (IntScalarTy, 0), (FloatScalarTy, 4)} 5288 OuterStructTy = {"Outer", (FloatScalarTy, 0), (DoubleScalarTy, 4), 5289 (InnerStructTy, 12)} 5290 5291 5292with (e.g.) ``ImmediateParent(OuterStructTy, 12)`` = ``(InnerStructTy, 52930)``, ``ImmediateParent(InnerStructTy, 0)`` = ``(IntScalarTy, 0)``, and 5294``ImmediateParent(IntScalarTy, 0)`` = ``(CharScalarTy, 0)``. 5295 5296.. _tbaa_node_representation: 5297 5298Representation 5299"""""""""""""" 5300 5301The root node of a TBAA type hierarchy is an ``MDNode`` with 0 operands or 5302with exactly one ``MDString`` operand. 5303 5304Scalar type descriptors are represented as an ``MDNode`` s with two 5305operands. The first operand is an ``MDString`` denoting the name of the 5306struct type. LLVM does not assign meaning to the value of this operand, it 5307only cares about it being an ``MDString``. The second operand is an 5308``MDNode`` which points to the parent for said scalar type descriptor, 5309which is either another scalar type descriptor or the TBAA root. Scalar 5310type descriptors can have an optional third argument, but that must be the 5311constant integer zero. 5312 5313Struct type descriptors are represented as ``MDNode`` s with an odd number 5314of operands greater than 1. The first operand is an ``MDString`` denoting 5315the name of the struct type. Like in scalar type descriptors the actual 5316value of this name operand is irrelevant to LLVM. After the name operand, 5317the struct type descriptors have a sequence of alternating ``MDNode`` and 5318``ConstantInt`` operands. With N starting from 1, the 2N - 1 th operand, 5319an ``MDNode``, denotes a contained field, and the 2N th operand, a 5320``ConstantInt``, is the offset of the said contained field. The offsets 5321must be in non-decreasing order. 5322 5323Access tags are represented as ``MDNode`` s with either 3 or 4 operands. 5324The first operand is an ``MDNode`` pointing to the node representing the 5325base type. The second operand is an ``MDNode`` pointing to the node 5326representing the access type. The third operand is a ``ConstantInt`` that 5327states the offset of the access. If a fourth field is present, it must be 5328a ``ConstantInt`` valued at 0 or 1. If it is 1 then the access tag states 5329that the location being accessed is "constant" (meaning 5330``pointsToConstantMemory`` should return true; see `other useful 5331AliasAnalysis methods <AliasAnalysis.html#OtherItfs>`_). The TBAA root of 5332the access type and the base type of an access tag must be the same, and 5333that is the TBAA root of the access tag. 5334 5335'``tbaa.struct``' Metadata 5336^^^^^^^^^^^^^^^^^^^^^^^^^^ 5337 5338The :ref:`llvm.memcpy <int_memcpy>` is often used to implement 5339aggregate assignment operations in C and similar languages, however it 5340is defined to copy a contiguous region of memory, which is more than 5341strictly necessary for aggregate types which contain holes due to 5342padding. Also, it doesn't contain any TBAA information about the fields 5343of the aggregate. 5344 5345``!tbaa.struct`` metadata can describe which memory subregions in a 5346memcpy are padding and what the TBAA tags of the struct are. 5347 5348The current metadata format is very simple. ``!tbaa.struct`` metadata 5349nodes are a list of operands which are in conceptual groups of three. 5350For each group of three, the first operand gives the byte offset of a 5351field in bytes, the second gives its size in bytes, and the third gives 5352its tbaa tag. e.g.: 5353 5354.. code-block:: llvm 5355 5356 !4 = !{ i64 0, i64 4, !1, i64 8, i64 4, !2 } 5357 5358This describes a struct with two fields. The first is at offset 0 bytes 5359with size 4 bytes, and has tbaa tag !1. The second is at offset 8 bytes 5360and has size 4 bytes and has tbaa tag !2. 5361 5362Note that the fields need not be contiguous. In this example, there is a 53634 byte gap between the two fields. This gap represents padding which 5364does not carry useful data and need not be preserved. 5365 5366'``noalias``' and '``alias.scope``' Metadata 5367^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 5368 5369``noalias`` and ``alias.scope`` metadata provide the ability to specify generic 5370noalias memory-access sets. This means that some collection of memory access 5371instructions (loads, stores, memory-accessing calls, etc.) that carry 5372``noalias`` metadata can specifically be specified not to alias with some other 5373collection of memory access instructions that carry ``alias.scope`` metadata. 5374Each type of metadata specifies a list of scopes where each scope has an id and 5375a domain. 5376 5377When evaluating an aliasing query, if for some domain, the set 5378of scopes with that domain in one instruction's ``alias.scope`` list is a 5379subset of (or equal to) the set of scopes for that domain in another 5380instruction's ``noalias`` list, then the two memory accesses are assumed not to 5381alias. 5382 5383Because scopes in one domain don't affect scopes in other domains, separate 5384domains can be used to compose multiple independent noalias sets. This is 5385used for example during inlining. As the noalias function parameters are 5386turned into noalias scope metadata, a new domain is used every time the 5387function is inlined. 5388 5389The metadata identifying each domain is itself a list containing one or two 5390entries. The first entry is the name of the domain. Note that if the name is a 5391string then it can be combined across functions and translation units. A 5392self-reference can be used to create globally unique domain names. A 5393descriptive string may optionally be provided as a second list entry. 5394 5395The metadata identifying each scope is also itself a list containing two or 5396three entries. The first entry is the name of the scope. Note that if the name 5397is a string then it can be combined across functions and translation units. A 5398self-reference can be used to create globally unique scope names. A metadata 5399reference to the scope's domain is the second entry. A descriptive string may 5400optionally be provided as a third list entry. 5401 5402For example, 5403 5404.. code-block:: llvm 5405 5406 ; Two scope domains: 5407 !0 = !{!0} 5408 !1 = !{!1} 5409 5410 ; Some scopes in these domains: 5411 !2 = !{!2, !0} 5412 !3 = !{!3, !0} 5413 !4 = !{!4, !1} 5414 5415 ; Some scope lists: 5416 !5 = !{!4} ; A list containing only scope !4 5417 !6 = !{!4, !3, !2} 5418 !7 = !{!3} 5419 5420 ; These two instructions don't alias: 5421 %0 = load float, float* %c, align 4, !alias.scope !5 5422 store float %0, float* %arrayidx.i, align 4, !noalias !5 5423 5424 ; These two instructions also don't alias (for domain !1, the set of scopes 5425 ; in the !alias.scope equals that in the !noalias list): 5426 %2 = load float, float* %c, align 4, !alias.scope !5 5427 store float %2, float* %arrayidx.i2, align 4, !noalias !6 5428 5429 ; These two instructions may alias (for domain !0, the set of scopes in 5430 ; the !noalias list is not a superset of, or equal to, the scopes in the 5431 ; !alias.scope list): 5432 %2 = load float, float* %c, align 4, !alias.scope !6 5433 store float %0, float* %arrayidx.i, align 4, !noalias !7 5434 5435'``fpmath``' Metadata 5436^^^^^^^^^^^^^^^^^^^^^ 5437 5438``fpmath`` metadata may be attached to any instruction of floating-point 5439type. It can be used to express the maximum acceptable error in the 5440result of that instruction, in ULPs, thus potentially allowing the 5441compiler to use a more efficient but less accurate method of computing 5442it. ULP is defined as follows: 5443 5444 If ``x`` is a real number that lies between two finite consecutive 5445 floating-point numbers ``a`` and ``b``, without being equal to one 5446 of them, then ``ulp(x) = |b - a|``, otherwise ``ulp(x)`` is the 5447 distance between the two non-equal finite floating-point numbers 5448 nearest ``x``. Moreover, ``ulp(NaN)`` is ``NaN``. 5449 5450The metadata node shall consist of a single positive float type number 5451representing the maximum relative error, for example: 5452 5453.. code-block:: llvm 5454 5455 !0 = !{ float 2.5 } ; maximum acceptable inaccuracy is 2.5 ULPs 5456 5457.. _range-metadata: 5458 5459'``range``' Metadata 5460^^^^^^^^^^^^^^^^^^^^ 5461 5462``range`` metadata may be attached only to ``load``, ``call`` and ``invoke`` of 5463integer types. It expresses the possible ranges the loaded value or the value 5464returned by the called function at this call site is in. If the loaded or 5465returned value is not in the specified range, the behavior is undefined. The 5466ranges are represented with a flattened list of integers. The loaded value or 5467the value returned is known to be in the union of the ranges defined by each 5468consecutive pair. Each pair has the following properties: 5469 5470- The type must match the type loaded by the instruction. 5471- The pair ``a,b`` represents the range ``[a,b)``. 5472- Both ``a`` and ``b`` are constants. 5473- The range is allowed to wrap. 5474- The range should not represent the full or empty set. That is, 5475 ``a!=b``. 5476 5477In addition, the pairs must be in signed order of the lower bound and 5478they must be non-contiguous. 5479 5480Examples: 5481 5482.. code-block:: llvm 5483 5484 %a = load i8, i8* %x, align 1, !range !0 ; Can only be 0 or 1 5485 %b = load i8, i8* %y, align 1, !range !1 ; Can only be 255 (-1), 0 or 1 5486 %c = call i8 @foo(), !range !2 ; Can only be 0, 1, 3, 4 or 5 5487 %d = invoke i8 @bar() to label %cont 5488 unwind label %lpad, !range !3 ; Can only be -2, -1, 3, 4 or 5 5489 ... 5490 !0 = !{ i8 0, i8 2 } 5491 !1 = !{ i8 255, i8 2 } 5492 !2 = !{ i8 0, i8 2, i8 3, i8 6 } 5493 !3 = !{ i8 -2, i8 0, i8 3, i8 6 } 5494 5495'``absolute_symbol``' Metadata 5496^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 5497 5498``absolute_symbol`` metadata may be attached to a global variable 5499declaration. It marks the declaration as a reference to an absolute symbol, 5500which causes the backend to use absolute relocations for the symbol even 5501in position independent code, and expresses the possible ranges that the 5502global variable's *address* (not its value) is in, in the same format as 5503``range`` metadata, with the extension that the pair ``all-ones,all-ones`` 5504may be used to represent the full set. 5505 5506Example (assuming 64-bit pointers): 5507 5508.. code-block:: llvm 5509 5510 @a = external global i8, !absolute_symbol !0 ; Absolute symbol in range [0,256) 5511 @b = external global i8, !absolute_symbol !1 ; Absolute symbol in range [0,2^64) 5512 5513 ... 5514 !0 = !{ i64 0, i64 256 } 5515 !1 = !{ i64 -1, i64 -1 } 5516 5517'``callees``' Metadata 5518^^^^^^^^^^^^^^^^^^^^^^ 5519 5520``callees`` metadata may be attached to indirect call sites. If ``callees`` 5521metadata is attached to a call site, and any callee is not among the set of 5522functions provided by the metadata, the behavior is undefined. The intent of 5523this metadata is to facilitate optimizations such as indirect-call promotion. 5524For example, in the code below, the call instruction may only target the 5525``add`` or ``sub`` functions: 5526 5527.. code-block:: llvm 5528 5529 %result = call i64 %binop(i64 %x, i64 %y), !callees !0 5530 5531 ... 5532 !0 = !{i64 (i64, i64)* @add, i64 (i64, i64)* @sub} 5533 5534'``callback``' Metadata 5535^^^^^^^^^^^^^^^^^^^^^^^ 5536 5537``callback`` metadata may be attached to a function declaration, or definition. 5538(Call sites are excluded only due to the lack of a use case.) For ease of 5539exposition, we'll refer to the function annotated w/ metadata as a broker 5540function. The metadata describes how the arguments of a call to the broker are 5541in turn passed to the callback function specified by the metadata. Thus, the 5542``callback`` metadata provides a partial description of a call site inside the 5543broker function with regards to the arguments of a call to the broker. The only 5544semantic restriction on the broker function itself is that it is not allowed to 5545inspect or modify arguments referenced in the ``callback`` metadata as 5546pass-through to the callback function. 5547 5548The broker is not required to actually invoke the callback function at runtime. 5549However, the assumptions about not inspecting or modifying arguments that would 5550be passed to the specified callback function still hold, even if the callback 5551function is not dynamically invoked. The broker is allowed to invoke the 5552callback function more than once per invocation of the broker. The broker is 5553also allowed to invoke (directly or indirectly) the function passed as a 5554callback through another use. Finally, the broker is also allowed to relay the 5555callback callee invocation to a different thread. 5556 5557The metadata is structured as follows: At the outer level, ``callback`` 5558metadata is a list of ``callback`` encodings. Each encoding starts with a 5559constant ``i64`` which describes the argument position of the callback function 5560in the call to the broker. The following elements, except the last, describe 5561what arguments are passed to the callback function. Each element is again an 5562``i64`` constant identifying the argument of the broker that is passed through, 5563or ``i64 -1`` to indicate an unknown or inspected argument. The order in which 5564they are listed has to be the same in which they are passed to the callback 5565callee. The last element of the encoding is a boolean which specifies how 5566variadic arguments of the broker are handled. If it is true, all variadic 5567arguments of the broker are passed through to the callback function *after* the 5568arguments encoded explicitly before. 5569 5570In the code below, the ``pthread_create`` function is marked as a broker 5571through the ``!callback !1`` metadata. In the example, there is only one 5572callback encoding, namely ``!2``, associated with the broker. This encoding 5573identifies the callback function as the second argument of the broker (``i64 55742``) and the sole argument of the callback function as the third one of the 5575broker function (``i64 3``). 5576 5577.. FIXME why does the llvm-sphinx-docs builder give a highlighting 5578 error if the below is set to highlight as 'llvm', despite that we 5579 have misc.highlighting_failure set? 5580 5581.. code-block:: text 5582 5583 declare !callback !1 dso_local i32 @pthread_create(i64*, %union.pthread_attr_t*, i8* (i8*)*, i8*) 5584 5585 ... 5586 !2 = !{i64 2, i64 3, i1 false} 5587 !1 = !{!2} 5588 5589Another example is shown below. The callback callee is the second argument of 5590the ``__kmpc_fork_call`` function (``i64 2``). The callee is given two unknown 5591values (each identified by a ``i64 -1``) and afterwards all 5592variadic arguments that are passed to the ``__kmpc_fork_call`` call (due to the 5593final ``i1 true``). 5594 5595.. FIXME why does the llvm-sphinx-docs builder give a highlighting 5596 error if the below is set to highlight as 'llvm', despite that we 5597 have misc.highlighting_failure set? 5598 5599.. code-block:: text 5600 5601 declare !callback !0 dso_local void @__kmpc_fork_call(%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) 5602 5603 ... 5604 !1 = !{i64 2, i64 -1, i64 -1, i1 true} 5605 !0 = !{!1} 5606 5607 5608'``unpredictable``' Metadata 5609^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 5610 5611``unpredictable`` metadata may be attached to any branch or switch 5612instruction. It can be used to express the unpredictability of control 5613flow. Similar to the llvm.expect intrinsic, it may be used to alter 5614optimizations related to compare and branch instructions. The metadata 5615is treated as a boolean value; if it exists, it signals that the branch 5616or switch that it is attached to is completely unpredictable. 5617 5618.. _md_dereferenceable: 5619 5620'``dereferenceable``' Metadata 5621^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 5622 5623The existence of the ``!dereferenceable`` metadata on the instruction 5624tells the optimizer that the value loaded is known to be dereferenceable. 5625The number of bytes known to be dereferenceable is specified by the integer 5626value in the metadata node. This is analogous to the ''dereferenceable'' 5627attribute on parameters and return values. 5628 5629.. _md_dereferenceable_or_null: 5630 5631'``dereferenceable_or_null``' Metadata 5632^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 5633 5634The existence of the ``!dereferenceable_or_null`` metadata on the 5635instruction tells the optimizer that the value loaded is known to be either 5636dereferenceable or null. 5637The number of bytes known to be dereferenceable is specified by the integer 5638value in the metadata node. This is analogous to the ''dereferenceable_or_null'' 5639attribute on parameters and return values. 5640 5641.. _llvm.loop: 5642 5643'``llvm.loop``' 5644^^^^^^^^^^^^^^^ 5645 5646It is sometimes useful to attach information to loop constructs. Currently, 5647loop metadata is implemented as metadata attached to the branch instruction 5648in the loop latch block. This type of metadata refer to a metadata node that is 5649guaranteed to be separate for each loop. The loop identifier metadata is 5650specified with the name ``llvm.loop``. 5651 5652The loop identifier metadata is implemented using a metadata that refers to 5653itself to avoid merging it with any other identifier metadata, e.g., 5654during module linkage or function inlining. That is, each loop should refer 5655to their own identification metadata even if they reside in separate functions. 5656The following example contains loop identifier metadata for two separate loop 5657constructs: 5658 5659.. code-block:: llvm 5660 5661 !0 = !{!0} 5662 !1 = !{!1} 5663 5664The loop identifier metadata can be used to specify additional 5665per-loop metadata. Any operands after the first operand can be treated 5666as user-defined metadata. For example the ``llvm.loop.unroll.count`` 5667suggests an unroll factor to the loop unroller: 5668 5669.. code-block:: llvm 5670 5671 br i1 %exitcond, label %._crit_edge, label %.lr.ph, !llvm.loop !0 5672 ... 5673 !0 = !{!0, !1} 5674 !1 = !{!"llvm.loop.unroll.count", i32 4} 5675 5676'``llvm.loop.disable_nonforced``' 5677^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 5678 5679This metadata disables all optional loop transformations unless 5680explicitly instructed using other transformation metadata such as 5681``llvm.loop.unroll.enable``. That is, no heuristic will try to determine 5682whether a transformation is profitable. The purpose is to avoid that the 5683loop is transformed to a different loop before an explicitly requested 5684(forced) transformation is applied. For instance, loop fusion can make 5685other transformations impossible. Mandatory loop canonicalizations such 5686as loop rotation are still applied. 5687 5688It is recommended to use this metadata in addition to any llvm.loop.* 5689transformation directive. Also, any loop should have at most one 5690directive applied to it (and a sequence of transformations built using 5691followup-attributes). Otherwise, which transformation will be applied 5692depends on implementation details such as the pass pipeline order. 5693 5694See :ref:`transformation-metadata` for details. 5695 5696'``llvm.loop.vectorize``' and '``llvm.loop.interleave``' 5697^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 5698 5699Metadata prefixed with ``llvm.loop.vectorize`` or ``llvm.loop.interleave`` are 5700used to control per-loop vectorization and interleaving parameters such as 5701vectorization width and interleave count. These metadata should be used in 5702conjunction with ``llvm.loop`` loop identification metadata. The 5703``llvm.loop.vectorize`` and ``llvm.loop.interleave`` metadata are only 5704optimization hints and the optimizer will only interleave and vectorize loops if 5705it believes it is safe to do so. The ``llvm.loop.parallel_accesses`` metadata 5706which contains information about loop-carried memory dependencies can be helpful 5707in determining the safety of these transformations. 5708 5709'``llvm.loop.interleave.count``' Metadata 5710^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 5711 5712This metadata suggests an interleave count to the loop interleaver. 5713The first operand is the string ``llvm.loop.interleave.count`` and the 5714second operand is an integer specifying the interleave count. For 5715example: 5716 5717.. code-block:: llvm 5718 5719 !0 = !{!"llvm.loop.interleave.count", i32 4} 5720 5721Note that setting ``llvm.loop.interleave.count`` to 1 disables interleaving 5722multiple iterations of the loop. If ``llvm.loop.interleave.count`` is set to 0 5723then the interleave count will be determined automatically. 5724 5725'``llvm.loop.vectorize.enable``' Metadata 5726^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 5727 5728This metadata selectively enables or disables vectorization for the loop. The 5729first operand is the string ``llvm.loop.vectorize.enable`` and the second operand 5730is a bit. If the bit operand value is 1 vectorization is enabled. A value of 57310 disables vectorization: 5732 5733.. code-block:: llvm 5734 5735 !0 = !{!"llvm.loop.vectorize.enable", i1 0} 5736 !1 = !{!"llvm.loop.vectorize.enable", i1 1} 5737 5738'``llvm.loop.vectorize.predicate.enable``' Metadata 5739^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 5740 5741This metadata selectively enables or disables creating predicated instructions 5742for the loop, which can enable folding of the scalar epilogue loop into the 5743main loop. The first operand is the string 5744``llvm.loop.vectorize.predicate.enable`` and the second operand is a bit. If 5745the bit operand value is 1 vectorization is enabled. A value of 0 disables 5746vectorization: 5747 5748.. code-block:: llvm 5749 5750 !0 = !{!"llvm.loop.vectorize.predicate.enable", i1 0} 5751 !1 = !{!"llvm.loop.vectorize.predicate.enable", i1 1} 5752 5753'``llvm.loop.vectorize.width``' Metadata 5754^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 5755 5756This metadata sets the target width of the vectorizer. The first 5757operand is the string ``llvm.loop.vectorize.width`` and the second 5758operand is an integer specifying the width. For example: 5759 5760.. code-block:: llvm 5761 5762 !0 = !{!"llvm.loop.vectorize.width", i32 4} 5763 5764Note that setting ``llvm.loop.vectorize.width`` to 1 disables 5765vectorization of the loop. If ``llvm.loop.vectorize.width`` is set to 57660 or if the loop does not have this metadata the width will be 5767determined automatically. 5768 5769'``llvm.loop.vectorize.followup_vectorized``' Metadata 5770^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 5771 5772This metadata defines which loop attributes the vectorized loop will 5773have. See :ref:`transformation-metadata` for details. 5774 5775'``llvm.loop.vectorize.followup_epilogue``' Metadata 5776^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 5777 5778This metadata defines which loop attributes the epilogue will have. The 5779epilogue is not vectorized and is executed when either the vectorized 5780loop is not known to preserve semantics (because e.g., it processes two 5781arrays that are found to alias by a runtime check) or for the last 5782iterations that do not fill a complete set of vector lanes. See 5783:ref:`Transformation Metadata <transformation-metadata>` for details. 5784 5785'``llvm.loop.vectorize.followup_all``' Metadata 5786^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 5787 5788Attributes in the metadata will be added to both the vectorized and 5789epilogue loop. 5790See :ref:`Transformation Metadata <transformation-metadata>` for details. 5791 5792'``llvm.loop.unroll``' 5793^^^^^^^^^^^^^^^^^^^^^^ 5794 5795Metadata prefixed with ``llvm.loop.unroll`` are loop unrolling 5796optimization hints such as the unroll factor. ``llvm.loop.unroll`` 5797metadata should be used in conjunction with ``llvm.loop`` loop 5798identification metadata. The ``llvm.loop.unroll`` metadata are only 5799optimization hints and the unrolling will only be performed if the 5800optimizer believes it is safe to do so. 5801 5802'``llvm.loop.unroll.count``' Metadata 5803^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 5804 5805This metadata suggests an unroll factor to the loop unroller. The 5806first operand is the string ``llvm.loop.unroll.count`` and the second 5807operand is a positive integer specifying the unroll factor. For 5808example: 5809 5810.. code-block:: llvm 5811 5812 !0 = !{!"llvm.loop.unroll.count", i32 4} 5813 5814If the trip count of the loop is less than the unroll count the loop 5815will be partially unrolled. 5816 5817'``llvm.loop.unroll.disable``' Metadata 5818^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 5819 5820This metadata disables loop unrolling. The metadata has a single operand 5821which is the string ``llvm.loop.unroll.disable``. For example: 5822 5823.. code-block:: llvm 5824 5825 !0 = !{!"llvm.loop.unroll.disable"} 5826 5827'``llvm.loop.unroll.runtime.disable``' Metadata 5828^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 5829 5830This metadata disables runtime loop unrolling. The metadata has a single 5831operand which is the string ``llvm.loop.unroll.runtime.disable``. For example: 5832 5833.. code-block:: llvm 5834 5835 !0 = !{!"llvm.loop.unroll.runtime.disable"} 5836 5837'``llvm.loop.unroll.enable``' Metadata 5838^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 5839 5840This metadata suggests that the loop should be fully unrolled if the trip count 5841is known at compile time and partially unrolled if the trip count is not known 5842at compile time. The metadata has a single operand which is the string 5843``llvm.loop.unroll.enable``. For example: 5844 5845.. code-block:: llvm 5846 5847 !0 = !{!"llvm.loop.unroll.enable"} 5848 5849'``llvm.loop.unroll.full``' Metadata 5850^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 5851 5852This metadata suggests that the loop should be unrolled fully. The 5853metadata has a single operand which is the string ``llvm.loop.unroll.full``. 5854For example: 5855 5856.. code-block:: llvm 5857 5858 !0 = !{!"llvm.loop.unroll.full"} 5859 5860'``llvm.loop.unroll.followup``' Metadata 5861^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 5862 5863This metadata defines which loop attributes the unrolled loop will have. 5864See :ref:`Transformation Metadata <transformation-metadata>` for details. 5865 5866'``llvm.loop.unroll.followup_remainder``' Metadata 5867^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 5868 5869This metadata defines which loop attributes the remainder loop after 5870partial/runtime unrolling will have. See 5871:ref:`Transformation Metadata <transformation-metadata>` for details. 5872 5873'``llvm.loop.unroll_and_jam``' 5874^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 5875 5876This metadata is treated very similarly to the ``llvm.loop.unroll`` metadata 5877above, but affect the unroll and jam pass. In addition any loop with 5878``llvm.loop.unroll`` metadata but no ``llvm.loop.unroll_and_jam`` metadata will 5879disable unroll and jam (so ``llvm.loop.unroll`` metadata will be left to the 5880unroller, plus ``llvm.loop.unroll.disable`` metadata will disable unroll and jam 5881too.) 5882 5883The metadata for unroll and jam otherwise is the same as for ``unroll``. 5884``llvm.loop.unroll_and_jam.enable``, ``llvm.loop.unroll_and_jam.disable`` and 5885``llvm.loop.unroll_and_jam.count`` do the same as for unroll. 5886``llvm.loop.unroll_and_jam.full`` is not supported. Again these are only hints 5887and the normal safety checks will still be performed. 5888 5889'``llvm.loop.unroll_and_jam.count``' Metadata 5890^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 5891 5892This metadata suggests an unroll and jam factor to use, similarly to 5893``llvm.loop.unroll.count``. The first operand is the string 5894``llvm.loop.unroll_and_jam.count`` and the second operand is a positive integer 5895specifying the unroll factor. For example: 5896 5897.. code-block:: llvm 5898 5899 !0 = !{!"llvm.loop.unroll_and_jam.count", i32 4} 5900 5901If the trip count of the loop is less than the unroll count the loop 5902will be partially unroll and jammed. 5903 5904'``llvm.loop.unroll_and_jam.disable``' Metadata 5905^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 5906 5907This metadata disables loop unroll and jamming. The metadata has a single 5908operand which is the string ``llvm.loop.unroll_and_jam.disable``. For example: 5909 5910.. code-block:: llvm 5911 5912 !0 = !{!"llvm.loop.unroll_and_jam.disable"} 5913 5914'``llvm.loop.unroll_and_jam.enable``' Metadata 5915^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 5916 5917This metadata suggests that the loop should be fully unroll and jammed if the 5918trip count is known at compile time and partially unrolled if the trip count is 5919not known at compile time. The metadata has a single operand which is the 5920string ``llvm.loop.unroll_and_jam.enable``. For example: 5921 5922.. code-block:: llvm 5923 5924 !0 = !{!"llvm.loop.unroll_and_jam.enable"} 5925 5926'``llvm.loop.unroll_and_jam.followup_outer``' Metadata 5927^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 5928 5929This metadata defines which loop attributes the outer unrolled loop will 5930have. See :ref:`Transformation Metadata <transformation-metadata>` for 5931details. 5932 5933'``llvm.loop.unroll_and_jam.followup_inner``' Metadata 5934^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 5935 5936This metadata defines which loop attributes the inner jammed loop will 5937have. See :ref:`Transformation Metadata <transformation-metadata>` for 5938details. 5939 5940'``llvm.loop.unroll_and_jam.followup_remainder_outer``' Metadata 5941^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 5942 5943This metadata defines which attributes the epilogue of the outer loop 5944will have. This loop is usually unrolled, meaning there is no such 5945loop. This attribute will be ignored in this case. See 5946:ref:`Transformation Metadata <transformation-metadata>` for details. 5947 5948'``llvm.loop.unroll_and_jam.followup_remainder_inner``' Metadata 5949^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 5950 5951This metadata defines which attributes the inner loop of the epilogue 5952will have. The outer epilogue will usually be unrolled, meaning there 5953can be multiple inner remainder loops. See 5954:ref:`Transformation Metadata <transformation-metadata>` for details. 5955 5956'``llvm.loop.unroll_and_jam.followup_all``' Metadata 5957^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 5958 5959Attributes specified in the metadata is added to all 5960``llvm.loop.unroll_and_jam.*`` loops. See 5961:ref:`Transformation Metadata <transformation-metadata>` for details. 5962 5963'``llvm.loop.licm_versioning.disable``' Metadata 5964^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 5965 5966This metadata indicates that the loop should not be versioned for the purpose 5967of enabling loop-invariant code motion (LICM). The metadata has a single operand 5968which is the string ``llvm.loop.licm_versioning.disable``. For example: 5969 5970.. code-block:: llvm 5971 5972 !0 = !{!"llvm.loop.licm_versioning.disable"} 5973 5974'``llvm.loop.distribute.enable``' Metadata 5975^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 5976 5977Loop distribution allows splitting a loop into multiple loops. Currently, 5978this is only performed if the entire loop cannot be vectorized due to unsafe 5979memory dependencies. The transformation will attempt to isolate the unsafe 5980dependencies into their own loop. 5981 5982This metadata can be used to selectively enable or disable distribution of the 5983loop. The first operand is the string ``llvm.loop.distribute.enable`` and the 5984second operand is a bit. If the bit operand value is 1 distribution is 5985enabled. A value of 0 disables distribution: 5986 5987.. code-block:: llvm 5988 5989 !0 = !{!"llvm.loop.distribute.enable", i1 0} 5990 !1 = !{!"llvm.loop.distribute.enable", i1 1} 5991 5992This metadata should be used in conjunction with ``llvm.loop`` loop 5993identification metadata. 5994 5995'``llvm.loop.distribute.followup_coincident``' Metadata 5996^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 5997 5998This metadata defines which attributes extracted loops with no cyclic 5999dependencies will have (i.e. can be vectorized). See 6000:ref:`Transformation Metadata <transformation-metadata>` for details. 6001 6002'``llvm.loop.distribute.followup_sequential``' Metadata 6003^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6004 6005This metadata defines which attributes the isolated loops with unsafe 6006memory dependencies will have. See 6007:ref:`Transformation Metadata <transformation-metadata>` for details. 6008 6009'``llvm.loop.distribute.followup_fallback``' Metadata 6010^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6011 6012If loop versioning is necessary, this metadata defined the attributes 6013the non-distributed fallback version will have. See 6014:ref:`Transformation Metadata <transformation-metadata>` for details. 6015 6016'``llvm.loop.distribute.followup_all``' Metadata 6017^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6018 6019The attributes in this metadata is added to all followup loops of the 6020loop distribution pass. See 6021:ref:`Transformation Metadata <transformation-metadata>` for details. 6022 6023'``llvm.licm.disable``' Metadata 6024^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6025 6026This metadata indicates that loop-invariant code motion (LICM) should not be 6027performed on this loop. The metadata has a single operand which is the string 6028``llvm.licm.disable``. For example: 6029 6030.. code-block:: llvm 6031 6032 !0 = !{!"llvm.licm.disable"} 6033 6034Note that although it operates per loop it isn't given the llvm.loop prefix 6035as it is not affected by the ``llvm.loop.disable_nonforced`` metadata. 6036 6037'``llvm.access.group``' Metadata 6038^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6039 6040``llvm.access.group`` metadata can be attached to any instruction that 6041potentially accesses memory. It can point to a single distinct metadata 6042node, which we call access group. This node represents all memory access 6043instructions referring to it via ``llvm.access.group``. When an 6044instruction belongs to multiple access groups, it can also point to a 6045list of accesses groups, illustrated by the following example. 6046 6047.. code-block:: llvm 6048 6049 %val = load i32, i32* %arrayidx, !llvm.access.group !0 6050 ... 6051 !0 = !{!1, !2} 6052 !1 = distinct !{} 6053 !2 = distinct !{} 6054 6055It is illegal for the list node to be empty since it might be confused 6056with an access group. 6057 6058The access group metadata node must be 'distinct' to avoid collapsing 6059multiple access groups by content. A access group metadata node must 6060always be empty which can be used to distinguish an access group 6061metadata node from a list of access groups. Being empty avoids the 6062situation that the content must be updated which, because metadata is 6063immutable by design, would required finding and updating all references 6064to the access group node. 6065 6066The access group can be used to refer to a memory access instruction 6067without pointing to it directly (which is not possible in global 6068metadata). Currently, the only metadata making use of it is 6069``llvm.loop.parallel_accesses``. 6070 6071'``llvm.loop.parallel_accesses``' Metadata 6072^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6073 6074The ``llvm.loop.parallel_accesses`` metadata refers to one or more 6075access group metadata nodes (see ``llvm.access.group``). It denotes that 6076no loop-carried memory dependence exist between it and other instructions 6077in the loop with this metadata. 6078 6079Let ``m1`` and ``m2`` be two instructions that both have the 6080``llvm.access.group`` metadata to the access group ``g1``, respectively 6081``g2`` (which might be identical). If a loop contains both access groups 6082in its ``llvm.loop.parallel_accesses`` metadata, then the compiler can 6083assume that there is no dependency between ``m1`` and ``m2`` carried by 6084this loop. Instructions that belong to multiple access groups are 6085considered having this property if at least one of the access groups 6086matches the ``llvm.loop.parallel_accesses`` list. 6087 6088If all memory-accessing instructions in a loop have 6089``llvm.loop.parallel_accesses`` metadata that refers to that loop, then the 6090loop has no loop carried memory dependences and is considered to be a 6091parallel loop. 6092 6093Note that if not all memory access instructions belong to an access 6094group referred to by ``llvm.loop.parallel_accesses``, then the loop must 6095not be considered trivially parallel. Additional 6096memory dependence analysis is required to make that determination. As a fail 6097safe mechanism, this causes loops that were originally parallel to be considered 6098sequential (if optimization passes that are unaware of the parallel semantics 6099insert new memory instructions into the loop body). 6100 6101Example of a loop that is considered parallel due to its correct use of 6102both ``llvm.access.group`` and ``llvm.loop.parallel_accesses`` 6103metadata types. 6104 6105.. code-block:: llvm 6106 6107 for.body: 6108 ... 6109 %val0 = load i32, i32* %arrayidx, !llvm.access.group !1 6110 ... 6111 store i32 %val0, i32* %arrayidx1, !llvm.access.group !1 6112 ... 6113 br i1 %exitcond, label %for.end, label %for.body, !llvm.loop !0 6114 6115 for.end: 6116 ... 6117 !0 = distinct !{!0, !{!"llvm.loop.parallel_accesses", !1}} 6118 !1 = distinct !{} 6119 6120It is also possible to have nested parallel loops: 6121 6122.. code-block:: llvm 6123 6124 outer.for.body: 6125 ... 6126 %val1 = load i32, i32* %arrayidx3, !llvm.access.group !4 6127 ... 6128 br label %inner.for.body 6129 6130 inner.for.body: 6131 ... 6132 %val0 = load i32, i32* %arrayidx1, !llvm.access.group !3 6133 ... 6134 store i32 %val0, i32* %arrayidx2, !llvm.access.group !3 6135 ... 6136 br i1 %exitcond, label %inner.for.end, label %inner.for.body, !llvm.loop !1 6137 6138 inner.for.end: 6139 ... 6140 store i32 %val1, i32* %arrayidx4, !llvm.access.group !4 6141 ... 6142 br i1 %exitcond, label %outer.for.end, label %outer.for.body, !llvm.loop !2 6143 6144 outer.for.end: ; preds = %for.body 6145 ... 6146 !1 = distinct !{!1, !{!"llvm.loop.parallel_accesses", !3}} ; metadata for the inner loop 6147 !2 = distinct !{!2, !{!"llvm.loop.parallel_accesses", !3, !4}} ; metadata for the outer loop 6148 !3 = distinct !{} ; access group for instructions in the inner loop (which are implicitly contained in outer loop as well) 6149 !4 = distinct !{} ; access group for instructions in the outer, but not the inner loop 6150 6151'``irr_loop``' Metadata 6152^^^^^^^^^^^^^^^^^^^^^^^ 6153 6154``irr_loop`` metadata may be attached to the terminator instruction of a basic 6155block that's an irreducible loop header (note that an irreducible loop has more 6156than once header basic blocks.) If ``irr_loop`` metadata is attached to the 6157terminator instruction of a basic block that is not really an irreducible loop 6158header, the behavior is undefined. The intent of this metadata is to improve the 6159accuracy of the block frequency propagation. For example, in the code below, the 6160block ``header0`` may have a loop header weight (relative to the other headers of 6161the irreducible loop) of 100: 6162 6163.. code-block:: llvm 6164 6165 header0: 6166 ... 6167 br i1 %cmp, label %t1, label %t2, !irr_loop !0 6168 6169 ... 6170 !0 = !{"loop_header_weight", i64 100} 6171 6172Irreducible loop header weights are typically based on profile data. 6173 6174.. _md_invariant.group: 6175 6176'``invariant.group``' Metadata 6177^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6178 6179The experimental ``invariant.group`` metadata may be attached to 6180``load``/``store`` instructions referencing a single metadata with no entries. 6181The existence of the ``invariant.group`` metadata on the instruction tells 6182the optimizer that every ``load`` and ``store`` to the same pointer operand 6183can be assumed to load or store the same 6184value (but see the ``llvm.launder.invariant.group`` intrinsic which affects 6185when two pointers are considered the same). Pointers returned by bitcast or 6186getelementptr with only zero indices are considered the same. 6187 6188Examples: 6189 6190.. code-block:: llvm 6191 6192 @unknownPtr = external global i8 6193 ... 6194 %ptr = alloca i8 6195 store i8 42, i8* %ptr, !invariant.group !0 6196 call void @foo(i8* %ptr) 6197 6198 %a = load i8, i8* %ptr, !invariant.group !0 ; Can assume that value under %ptr didn't change 6199 call void @foo(i8* %ptr) 6200 6201 %newPtr = call i8* @getPointer(i8* %ptr) 6202 %c = load i8, i8* %newPtr, !invariant.group !0 ; Can't assume anything, because we only have information about %ptr 6203 6204 %unknownValue = load i8, i8* @unknownPtr 6205 store i8 %unknownValue, i8* %ptr, !invariant.group !0 ; Can assume that %unknownValue == 42 6206 6207 call void @foo(i8* %ptr) 6208 %newPtr2 = call i8* @llvm.launder.invariant.group(i8* %ptr) 6209 %d = load i8, i8* %newPtr2, !invariant.group !0 ; Can't step through launder.invariant.group to get value of %ptr 6210 6211 ... 6212 declare void @foo(i8*) 6213 declare i8* @getPointer(i8*) 6214 declare i8* @llvm.launder.invariant.group(i8*) 6215 6216 !0 = !{} 6217 6218The invariant.group metadata must be dropped when replacing one pointer by 6219another based on aliasing information. This is because invariant.group is tied 6220to the SSA value of the pointer operand. 6221 6222.. code-block:: llvm 6223 6224 %v = load i8, i8* %x, !invariant.group !0 6225 ; if %x mustalias %y then we can replace the above instruction with 6226 %v = load i8, i8* %y 6227 6228Note that this is an experimental feature, which means that its semantics might 6229change in the future. 6230 6231'``type``' Metadata 6232^^^^^^^^^^^^^^^^^^^ 6233 6234See :doc:`TypeMetadata`. 6235 6236'``associated``' Metadata 6237^^^^^^^^^^^^^^^^^^^^^^^^^ 6238 6239The ``associated`` metadata may be attached to a global object 6240declaration with a single argument that references another global object. 6241 6242This metadata prevents discarding of the global object in linker GC 6243unless the referenced object is also discarded. The linker support for 6244this feature is spotty. For best compatibility, globals carrying this 6245metadata may also: 6246 6247- Be in a comdat with the referenced global. 6248- Be in @llvm.compiler.used. 6249- Have an explicit section with a name which is a valid C identifier. 6250 6251It does not have any effect on non-ELF targets. 6252 6253Example: 6254 6255.. code-block:: text 6256 6257 $a = comdat any 6258 @a = global i32 1, comdat $a 6259 @b = internal global i32 2, comdat $a, section "abc", !associated !0 6260 !0 = !{i32* @a} 6261 6262 6263'``prof``' Metadata 6264^^^^^^^^^^^^^^^^^^^ 6265 6266The ``prof`` metadata is used to record profile data in the IR. 6267The first operand of the metadata node indicates the profile metadata 6268type. There are currently 3 types: 6269:ref:`branch_weights<prof_node_branch_weights>`, 6270:ref:`function_entry_count<prof_node_function_entry_count>`, and 6271:ref:`VP<prof_node_VP>`. 6272 6273.. _prof_node_branch_weights: 6274 6275branch_weights 6276"""""""""""""" 6277 6278Branch weight metadata attached to a branch, select, switch or call instruction 6279represents the likeliness of the associated branch being taken. 6280For more information, see :doc:`BranchWeightMetadata`. 6281 6282.. _prof_node_function_entry_count: 6283 6284function_entry_count 6285"""""""""""""""""""" 6286 6287Function entry count metadata can be attached to function definitions 6288to record the number of times the function is called. Used with BFI 6289information, it is also used to derive the basic block profile count. 6290For more information, see :doc:`BranchWeightMetadata`. 6291 6292.. _prof_node_VP: 6293 6294VP 6295"" 6296 6297VP (value profile) metadata can be attached to instructions that have 6298value profile information. Currently this is indirect calls (where it 6299records the hottest callees) and calls to memory intrinsics such as memcpy, 6300memmove, and memset (where it records the hottest byte lengths). 6301 6302Each VP metadata node contains "VP" string, then a uint32_t value for the value 6303profiling kind, a uint64_t value for the total number of times the instruction 6304is executed, followed by uint64_t value and execution count pairs. 6305The value profiling kind is 0 for indirect call targets and 1 for memory 6306operations. For indirect call targets, each profile value is a hash 6307of the callee function name, and for memory operations each value is the 6308byte length. 6309 6310Note that the value counts do not need to add up to the total count 6311listed in the third operand (in practice only the top hottest values 6312are tracked and reported). 6313 6314Indirect call example: 6315 6316.. code-block:: llvm 6317 6318 call void %f(), !prof !1 6319 !1 = !{!"VP", i32 0, i64 1600, i64 7651369219802541373, i64 1030, i64 -4377547752858689819, i64 410} 6320 6321Note that the VP type is 0 (the second operand), which indicates this is 6322an indirect call value profile data. The third operand indicates that the 6323indirect call executed 1600 times. The 4th and 6th operands give the 6324hashes of the 2 hottest target functions' names (this is the same hash used 6325to represent function names in the profile database), and the 5th and 7th 6326operands give the execution count that each of the respective prior target 6327functions was called. 6328 6329Module Flags Metadata 6330===================== 6331 6332Information about the module as a whole is difficult to convey to LLVM's 6333subsystems. The LLVM IR isn't sufficient to transmit this information. 6334The ``llvm.module.flags`` named metadata exists in order to facilitate 6335this. These flags are in the form of key / value pairs --- much like a 6336dictionary --- making it easy for any subsystem who cares about a flag to 6337look it up. 6338 6339The ``llvm.module.flags`` metadata contains a list of metadata triplets. 6340Each triplet has the following form: 6341 6342- The first element is a *behavior* flag, which specifies the behavior 6343 when two (or more) modules are merged together, and it encounters two 6344 (or more) metadata with the same ID. The supported behaviors are 6345 described below. 6346- The second element is a metadata string that is a unique ID for the 6347 metadata. Each module may only have one flag entry for each unique ID (not 6348 including entries with the **Require** behavior). 6349- The third element is the value of the flag. 6350 6351When two (or more) modules are merged together, the resulting 6352``llvm.module.flags`` metadata is the union of the modules' flags. That is, for 6353each unique metadata ID string, there will be exactly one entry in the merged 6354modules ``llvm.module.flags`` metadata table, and the value for that entry will 6355be determined by the merge behavior flag, as described below. The only exception 6356is that entries with the *Require* behavior are always preserved. 6357 6358The following behaviors are supported: 6359 6360.. list-table:: 6361 :header-rows: 1 6362 :widths: 10 90 6363 6364 * - Value 6365 - Behavior 6366 6367 * - 1 6368 - **Error** 6369 Emits an error if two values disagree, otherwise the resulting value 6370 is that of the operands. 6371 6372 * - 2 6373 - **Warning** 6374 Emits a warning if two values disagree. The result value will be the 6375 operand for the flag from the first module being linked, or the max 6376 if the other module uses **Max** (in which case the resulting flag 6377 will be **Max**). 6378 6379 * - 3 6380 - **Require** 6381 Adds a requirement that another module flag be present and have a 6382 specified value after linking is performed. The value must be a 6383 metadata pair, where the first element of the pair is the ID of the 6384 module flag to be restricted, and the second element of the pair is 6385 the value the module flag should be restricted to. This behavior can 6386 be used to restrict the allowable results (via triggering of an 6387 error) of linking IDs with the **Override** behavior. 6388 6389 * - 4 6390 - **Override** 6391 Uses the specified value, regardless of the behavior or value of the 6392 other module. If both modules specify **Override**, but the values 6393 differ, an error will be emitted. 6394 6395 * - 5 6396 - **Append** 6397 Appends the two values, which are required to be metadata nodes. 6398 6399 * - 6 6400 - **AppendUnique** 6401 Appends the two values, which are required to be metadata 6402 nodes. However, duplicate entries in the second list are dropped 6403 during the append operation. 6404 6405 * - 7 6406 - **Max** 6407 Takes the max of the two values, which are required to be integers. 6408 6409It is an error for a particular unique flag ID to have multiple behaviors, 6410except in the case of **Require** (which adds restrictions on another metadata 6411value) or **Override**. 6412 6413An example of module flags: 6414 6415.. code-block:: llvm 6416 6417 !0 = !{ i32 1, !"foo", i32 1 } 6418 !1 = !{ i32 4, !"bar", i32 37 } 6419 !2 = !{ i32 2, !"qux", i32 42 } 6420 !3 = !{ i32 3, !"qux", 6421 !{ 6422 !"foo", i32 1 6423 } 6424 } 6425 !llvm.module.flags = !{ !0, !1, !2, !3 } 6426 6427- Metadata ``!0`` has the ID ``!"foo"`` and the value '1'. The behavior 6428 if two or more ``!"foo"`` flags are seen is to emit an error if their 6429 values are not equal. 6430 6431- Metadata ``!1`` has the ID ``!"bar"`` and the value '37'. The 6432 behavior if two or more ``!"bar"`` flags are seen is to use the value 6433 '37'. 6434 6435- Metadata ``!2`` has the ID ``!"qux"`` and the value '42'. The 6436 behavior if two or more ``!"qux"`` flags are seen is to emit a 6437 warning if their values are not equal. 6438 6439- Metadata ``!3`` has the ID ``!"qux"`` and the value: 6440 6441 :: 6442 6443 !{ !"foo", i32 1 } 6444 6445 The behavior is to emit an error if the ``llvm.module.flags`` does not 6446 contain a flag with the ID ``!"foo"`` that has the value '1' after linking is 6447 performed. 6448 6449Objective-C Garbage Collection Module Flags Metadata 6450---------------------------------------------------- 6451 6452On the Mach-O platform, Objective-C stores metadata about garbage 6453collection in a special section called "image info". The metadata 6454consists of a version number and a bitmask specifying what types of 6455garbage collection are supported (if any) by the file. If two or more 6456modules are linked together their garbage collection metadata needs to 6457be merged rather than appended together. 6458 6459The Objective-C garbage collection module flags metadata consists of the 6460following key-value pairs: 6461 6462.. list-table:: 6463 :header-rows: 1 6464 :widths: 30 70 6465 6466 * - Key 6467 - Value 6468 6469 * - ``Objective-C Version`` 6470 - **[Required]** --- The Objective-C ABI version. Valid values are 1 and 2. 6471 6472 * - ``Objective-C Image Info Version`` 6473 - **[Required]** --- The version of the image info section. Currently 6474 always 0. 6475 6476 * - ``Objective-C Image Info Section`` 6477 - **[Required]** --- The section to place the metadata. Valid values are 6478 ``"__OBJC, __image_info, regular"`` for Objective-C ABI version 1, and 6479 ``"__DATA,__objc_imageinfo, regular, no_dead_strip"`` for 6480 Objective-C ABI version 2. 6481 6482 * - ``Objective-C Garbage Collection`` 6483 - **[Required]** --- Specifies whether garbage collection is supported or 6484 not. Valid values are 0, for no garbage collection, and 2, for garbage 6485 collection supported. 6486 6487 * - ``Objective-C GC Only`` 6488 - **[Optional]** --- Specifies that only garbage collection is supported. 6489 If present, its value must be 6. This flag requires that the 6490 ``Objective-C Garbage Collection`` flag have the value 2. 6491 6492Some important flag interactions: 6493 6494- If a module with ``Objective-C Garbage Collection`` set to 0 is 6495 merged with a module with ``Objective-C Garbage Collection`` set to 6496 2, then the resulting module has the 6497 ``Objective-C Garbage Collection`` flag set to 0. 6498- A module with ``Objective-C Garbage Collection`` set to 0 cannot be 6499 merged with a module with ``Objective-C GC Only`` set to 6. 6500 6501C type width Module Flags Metadata 6502---------------------------------- 6503 6504The ARM backend emits a section into each generated object file describing the 6505options that it was compiled with (in a compiler-independent way) to prevent 6506linking incompatible objects, and to allow automatic library selection. Some 6507of these options are not visible at the IR level, namely wchar_t width and enum 6508width. 6509 6510To pass this information to the backend, these options are encoded in module 6511flags metadata, using the following key-value pairs: 6512 6513.. list-table:: 6514 :header-rows: 1 6515 :widths: 30 70 6516 6517 * - Key 6518 - Value 6519 6520 * - short_wchar 6521 - * 0 --- sizeof(wchar_t) == 4 6522 * 1 --- sizeof(wchar_t) == 2 6523 6524 * - short_enum 6525 - * 0 --- Enums are at least as large as an ``int``. 6526 * 1 --- Enums are stored in the smallest integer type which can 6527 represent all of its values. 6528 6529For example, the following metadata section specifies that the module was 6530compiled with a ``wchar_t`` width of 4 bytes, and the underlying type of an 6531enum is the smallest type which can represent all of its values:: 6532 6533 !llvm.module.flags = !{!0, !1} 6534 !0 = !{i32 1, !"short_wchar", i32 1} 6535 !1 = !{i32 1, !"short_enum", i32 0} 6536 6537LTO Post-Link Module Flags Metadata 6538----------------------------------- 6539 6540Some optimisations are only when the entire LTO unit is present in the current 6541module. This is represented by the ``LTOPostLink`` module flags metadata, which 6542will be created with a value of ``1`` when LTO linking occurs. 6543 6544Automatic Linker Flags Named Metadata 6545===================================== 6546 6547Some targets support embedding of flags to the linker inside individual object 6548files. Typically this is used in conjunction with language extensions which 6549allow source files to contain linker command line options, and have these 6550automatically be transmitted to the linker via object files. 6551 6552These flags are encoded in the IR using named metadata with the name 6553``!llvm.linker.options``. Each operand is expected to be a metadata node 6554which should be a list of other metadata nodes, each of which should be a 6555list of metadata strings defining linker options. 6556 6557For example, the following metadata section specifies two separate sets of 6558linker options, presumably to link against ``libz`` and the ``Cocoa`` 6559framework:: 6560 6561 !0 = !{ !"-lz" } 6562 !1 = !{ !"-framework", !"Cocoa" } 6563 !llvm.linker.options = !{ !0, !1 } 6564 6565The metadata encoding as lists of lists of options, as opposed to a collapsed 6566list of options, is chosen so that the IR encoding can use multiple option 6567strings to specify e.g., a single library, while still having that specifier be 6568preserved as an atomic element that can be recognized by a target specific 6569assembly writer or object file emitter. 6570 6571Each individual option is required to be either a valid option for the target's 6572linker, or an option that is reserved by the target specific assembly writer or 6573object file emitter. No other aspect of these options is defined by the IR. 6574 6575Dependent Libs Named Metadata 6576============================= 6577 6578Some targets support embedding of strings into object files to indicate 6579a set of libraries to add to the link. Typically this is used in conjunction 6580with language extensions which allow source files to explicitly declare the 6581libraries they depend on, and have these automatically be transmitted to the 6582linker via object files. 6583 6584The list is encoded in the IR using named metadata with the name 6585``!llvm.dependent-libraries``. Each operand is expected to be a metadata node 6586which should contain a single string operand. 6587 6588For example, the following metadata section contains two library specifiers:: 6589 6590 !0 = !{!"a library specifier"} 6591 !1 = !{!"another library specifier"} 6592 !llvm.dependent-libraries = !{ !0, !1 } 6593 6594Each library specifier will be handled independently by the consuming linker. 6595The effect of the library specifiers are defined by the consuming linker. 6596 6597.. _summary: 6598 6599ThinLTO Summary 6600=============== 6601 6602Compiling with `ThinLTO <https://clang.llvm.org/docs/ThinLTO.html>`_ 6603causes the building of a compact summary of the module that is emitted into 6604the bitcode. The summary is emitted into the LLVM assembly and identified 6605in syntax by a caret ('``^``'). 6606 6607The summary is parsed into a bitcode output, along with the Module 6608IR, via the "``llvm-as``" tool. Tools that parse the Module IR for the purposes 6609of optimization (e.g. "``clang -x ir``" and "``opt``"), will ignore the 6610summary entries (just as they currently ignore summary entries in a bitcode 6611input file). 6612 6613Eventually, the summary will be parsed into a ModuleSummaryIndex object under 6614the same conditions where summary index is currently built from bitcode. 6615Specifically, tools that test the Thin Link portion of a ThinLTO compile 6616(i.e. llvm-lto and llvm-lto2), or when parsing a combined index 6617for a distributed ThinLTO backend via clang's "``-fthinlto-index=<>``" flag 6618(this part is not yet implemented, use llvm-as to create a bitcode object 6619before feeding into thin link tools for now). 6620 6621There are currently 3 types of summary entries in the LLVM assembly: 6622:ref:`module paths<module_path_summary>`, 6623:ref:`global values<gv_summary>`, and 6624:ref:`type identifiers<typeid_summary>`. 6625 6626.. _module_path_summary: 6627 6628Module Path Summary Entry 6629------------------------- 6630 6631Each module path summary entry lists a module containing global values included 6632in the summary. For a single IR module there will be one such entry, but 6633in a combined summary index produced during the thin link, there will be 6634one module path entry per linked module with summary. 6635 6636Example: 6637 6638.. code-block:: text 6639 6640 ^0 = module: (path: "/path/to/file.o", hash: (2468601609, 1329373163, 1565878005, 638838075, 3148790418)) 6641 6642The ``path`` field is a string path to the bitcode file, and the ``hash`` 6643field is the 160-bit SHA-1 hash of the IR bitcode contents, used for 6644incremental builds and caching. 6645 6646.. _gv_summary: 6647 6648Global Value Summary Entry 6649-------------------------- 6650 6651Each global value summary entry corresponds to a global value defined or 6652referenced by a summarized module. 6653 6654Example: 6655 6656.. code-block:: text 6657 6658 ^4 = gv: (name: "f"[, summaries: (Summary)[, (Summary)]*]?) ; guid = 14740650423002898831 6659 6660For declarations, there will not be a summary list. For definitions, a 6661global value will contain a list of summaries, one per module containing 6662a definition. There can be multiple entries in a combined summary index 6663for symbols with weak linkage. 6664 6665Each ``Summary`` format will depend on whether the global value is a 6666:ref:`function<function_summary>`, :ref:`variable<variable_summary>`, or 6667:ref:`alias<alias_summary>`. 6668 6669.. _function_summary: 6670 6671Function Summary 6672^^^^^^^^^^^^^^^^ 6673 6674If the global value is a function, the ``Summary`` entry will look like: 6675 6676.. code-block:: text 6677 6678 function: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0), insts: 2[, FuncFlags]?[, Calls]?[, TypeIdInfo]?[, Refs]? 6679 6680The ``module`` field includes the summary entry id for the module containing 6681this definition, and the ``flags`` field contains information such as 6682the linkage type, a flag indicating whether it is legal to import the 6683definition, whether it is globally live and whether the linker resolved it 6684to a local definition (the latter two are populated during the thin link). 6685The ``insts`` field contains the number of IR instructions in the function. 6686Finally, there are several optional fields: :ref:`FuncFlags<funcflags_summary>`, 6687:ref:`Calls<calls_summary>`, :ref:`TypeIdInfo<typeidinfo_summary>`, 6688:ref:`Refs<refs_summary>`. 6689 6690.. _variable_summary: 6691 6692Global Variable Summary 6693^^^^^^^^^^^^^^^^^^^^^^^ 6694 6695If the global value is a variable, the ``Summary`` entry will look like: 6696 6697.. code-block:: text 6698 6699 variable: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0)[, Refs]? 6700 6701The variable entry contains a subset of the fields in a 6702:ref:`function summary <function_summary>`, see the descriptions there. 6703 6704.. _alias_summary: 6705 6706Alias Summary 6707^^^^^^^^^^^^^ 6708 6709If the global value is an alias, the ``Summary`` entry will look like: 6710 6711.. code-block:: text 6712 6713 alias: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0), aliasee: ^2) 6714 6715The ``module`` and ``flags`` fields are as described for a 6716:ref:`function summary <function_summary>`. The ``aliasee`` field 6717contains a reference to the global value summary entry of the aliasee. 6718 6719.. _funcflags_summary: 6720 6721Function Flags 6722^^^^^^^^^^^^^^ 6723 6724The optional ``FuncFlags`` field looks like: 6725 6726.. code-block:: text 6727 6728 funcFlags: (readNone: 0, readOnly: 0, noRecurse: 0, returnDoesNotAlias: 0) 6729 6730If unspecified, flags are assumed to hold the conservative ``false`` value of 6731``0``. 6732 6733.. _calls_summary: 6734 6735Calls 6736^^^^^ 6737 6738The optional ``Calls`` field looks like: 6739 6740.. code-block:: text 6741 6742 calls: ((Callee)[, (Callee)]*) 6743 6744where each ``Callee`` looks like: 6745 6746.. code-block:: text 6747 6748 callee: ^1[, hotness: None]?[, relbf: 0]? 6749 6750The ``callee`` refers to the summary entry id of the callee. At most one 6751of ``hotness`` (which can take the values ``Unknown``, ``Cold``, ``None``, 6752``Hot``, and ``Critical``), and ``relbf`` (which holds the integer 6753branch frequency relative to the entry frequency, scaled down by 2^8) 6754may be specified. The defaults are ``Unknown`` and ``0``, respectively. 6755 6756.. _refs_summary: 6757 6758Refs 6759^^^^ 6760 6761The optional ``Refs`` field looks like: 6762 6763.. code-block:: text 6764 6765 refs: ((Ref)[, (Ref)]*) 6766 6767where each ``Ref`` contains a reference to the summary id of the referenced 6768value (e.g. ``^1``). 6769 6770.. _typeidinfo_summary: 6771 6772TypeIdInfo 6773^^^^^^^^^^ 6774 6775The optional ``TypeIdInfo`` field, used for 6776`Control Flow Integrity <https://clang.llvm.org/docs/ControlFlowIntegrity.html>`_, 6777looks like: 6778 6779.. code-block:: text 6780 6781 typeIdInfo: [(TypeTests)]?[, (TypeTestAssumeVCalls)]?[, (TypeCheckedLoadVCalls)]?[, (TypeTestAssumeConstVCalls)]?[, (TypeCheckedLoadConstVCalls)]? 6782 6783These optional fields have the following forms: 6784 6785TypeTests 6786""""""""" 6787 6788.. code-block:: text 6789 6790 typeTests: (TypeIdRef[, TypeIdRef]*) 6791 6792Where each ``TypeIdRef`` refers to a :ref:`type id<typeid_summary>` 6793by summary id or ``GUID``. 6794 6795TypeTestAssumeVCalls 6796"""""""""""""""""""" 6797 6798.. code-block:: text 6799 6800 typeTestAssumeVCalls: (VFuncId[, VFuncId]*) 6801 6802Where each VFuncId has the format: 6803 6804.. code-block:: text 6805 6806 vFuncId: (TypeIdRef, offset: 16) 6807 6808Where each ``TypeIdRef`` refers to a :ref:`type id<typeid_summary>` 6809by summary id or ``GUID`` preceded by a ``guid:`` tag. 6810 6811TypeCheckedLoadVCalls 6812""""""""""""""""""""" 6813 6814.. code-block:: text 6815 6816 typeCheckedLoadVCalls: (VFuncId[, VFuncId]*) 6817 6818Where each VFuncId has the format described for ``TypeTestAssumeVCalls``. 6819 6820TypeTestAssumeConstVCalls 6821""""""""""""""""""""""""" 6822 6823.. code-block:: text 6824 6825 typeTestAssumeConstVCalls: (ConstVCall[, ConstVCall]*) 6826 6827Where each ConstVCall has the format: 6828 6829.. code-block:: text 6830 6831 (VFuncId, args: (Arg[, Arg]*)) 6832 6833and where each VFuncId has the format described for ``TypeTestAssumeVCalls``, 6834and each Arg is an integer argument number. 6835 6836TypeCheckedLoadConstVCalls 6837"""""""""""""""""""""""""" 6838 6839.. code-block:: text 6840 6841 typeCheckedLoadConstVCalls: (ConstVCall[, ConstVCall]*) 6842 6843Where each ConstVCall has the format described for 6844``TypeTestAssumeConstVCalls``. 6845 6846.. _typeid_summary: 6847 6848Type ID Summary Entry 6849--------------------- 6850 6851Each type id summary entry corresponds to a type identifier resolution 6852which is generated during the LTO link portion of the compile when building 6853with `Control Flow Integrity <https://clang.llvm.org/docs/ControlFlowIntegrity.html>`_, 6854so these are only present in a combined summary index. 6855 6856Example: 6857 6858.. code-block:: text 6859 6860 ^4 = typeid: (name: "_ZTS1A", summary: (typeTestRes: (kind: allOnes, sizeM1BitWidth: 7[, alignLog2: 0]?[, sizeM1: 0]?[, bitMask: 0]?[, inlineBits: 0]?)[, WpdResolutions]?)) ; guid = 7004155349499253778 6861 6862The ``typeTestRes`` gives the type test resolution ``kind`` (which may 6863be ``unsat``, ``byteArray``, ``inline``, ``single``, or ``allOnes``), and 6864the ``size-1`` bit width. It is followed by optional flags, which default to 0, 6865and an optional WpdResolutions (whole program devirtualization resolution) 6866field that looks like: 6867 6868.. code-block:: text 6869 6870 wpdResolutions: ((offset: 0, WpdRes)[, (offset: 1, WpdRes)]* 6871 6872where each entry is a mapping from the given byte offset to the whole-program 6873devirtualization resolution WpdRes, that has one of the following formats: 6874 6875.. code-block:: text 6876 6877 wpdRes: (kind: branchFunnel) 6878 wpdRes: (kind: singleImpl, singleImplName: "_ZN1A1nEi") 6879 wpdRes: (kind: indir) 6880 6881Additionally, each wpdRes has an optional ``resByArg`` field, which 6882describes the resolutions for calls with all constant integer arguments: 6883 6884.. code-block:: text 6885 6886 resByArg: (ResByArg[, ResByArg]*) 6887 6888where ResByArg is: 6889 6890.. code-block:: text 6891 6892 args: (Arg[, Arg]*), byArg: (kind: UniformRetVal[, info: 0][, byte: 0][, bit: 0]) 6893 6894Where the ``kind`` can be ``Indir``, ``UniformRetVal``, ``UniqueRetVal`` 6895or ``VirtualConstProp``. The ``info`` field is only used if the kind 6896is ``UniformRetVal`` (indicates the uniform return value), or 6897``UniqueRetVal`` (holds the return value associated with the unique vtable 6898(0 or 1)). The ``byte`` and ``bit`` fields are only used if the target does 6899not support the use of absolute symbols to store constants. 6900 6901.. _intrinsicglobalvariables: 6902 6903Intrinsic Global Variables 6904========================== 6905 6906LLVM has a number of "magic" global variables that contain data that 6907affect code generation or other IR semantics. These are documented here. 6908All globals of this sort should have a section specified as 6909"``llvm.metadata``". This section and all globals that start with 6910"``llvm.``" are reserved for use by LLVM. 6911 6912.. _gv_llvmused: 6913 6914The '``llvm.used``' Global Variable 6915----------------------------------- 6916 6917The ``@llvm.used`` global is an array which has 6918:ref:`appending linkage <linkage_appending>`. This array contains a list of 6919pointers to named global variables, functions and aliases which may optionally 6920have a pointer cast formed of bitcast or getelementptr. For example, a legal 6921use of it is: 6922 6923.. code-block:: llvm 6924 6925 @X = global i8 4 6926 @Y = global i32 123 6927 6928 @llvm.used = appending global [2 x i8*] [ 6929 i8* @X, 6930 i8* bitcast (i32* @Y to i8*) 6931 ], section "llvm.metadata" 6932 6933If a symbol appears in the ``@llvm.used`` list, then the compiler, assembler, 6934and linker are required to treat the symbol as if there is a reference to the 6935symbol that it cannot see (which is why they have to be named). For example, if 6936a variable has internal linkage and no references other than that from the 6937``@llvm.used`` list, it cannot be deleted. This is commonly used to represent 6938references from inline asms and other things the compiler cannot "see", and 6939corresponds to "``attribute((used))``" in GNU C. 6940 6941On some targets, the code generator must emit a directive to the 6942assembler or object file to prevent the assembler and linker from 6943removing the symbol. 6944 6945.. _gv_llvmcompilerused: 6946 6947The '``llvm.compiler.used``' Global Variable 6948-------------------------------------------- 6949 6950The ``@llvm.compiler.used`` directive is the same as the ``@llvm.used`` 6951directive, except that it only prevents the compiler from touching the 6952symbol. On targets that support it, this allows an intelligent linker to 6953optimize references to the symbol without being impeded as it would be 6954by ``@llvm.used``. 6955 6956This is a rare construct that should only be used in rare circumstances, 6957and should not be exposed to source languages. 6958 6959.. _gv_llvmglobalctors: 6960 6961The '``llvm.global_ctors``' Global Variable 6962------------------------------------------- 6963 6964.. code-block:: llvm 6965 6966 %0 = type { i32, void ()*, i8* } 6967 @llvm.global_ctors = appending global [1 x %0] [%0 { i32 65535, void ()* @ctor, i8* @data }] 6968 6969The ``@llvm.global_ctors`` array contains a list of constructor 6970functions, priorities, and an associated global or function. 6971The functions referenced by this array will be called in ascending order 6972of priority (i.e. lowest first) when the module is loaded. The order of 6973functions with the same priority is not defined. 6974 6975If the third field is non-null, and points to a global variable 6976or function, the initializer function will only run if the associated 6977data from the current module is not discarded. 6978 6979.. _llvmglobaldtors: 6980 6981The '``llvm.global_dtors``' Global Variable 6982------------------------------------------- 6983 6984.. code-block:: llvm 6985 6986 %0 = type { i32, void ()*, i8* } 6987 @llvm.global_dtors = appending global [1 x %0] [%0 { i32 65535, void ()* @dtor, i8* @data }] 6988 6989The ``@llvm.global_dtors`` array contains a list of destructor 6990functions, priorities, and an associated global or function. 6991The functions referenced by this array will be called in descending 6992order of priority (i.e. highest first) when the module is unloaded. The 6993order of functions with the same priority is not defined. 6994 6995If the third field is non-null, and points to a global variable 6996or function, the destructor function will only run if the associated 6997data from the current module is not discarded. 6998 6999Instruction Reference 7000===================== 7001 7002The LLVM instruction set consists of several different classifications 7003of instructions: :ref:`terminator instructions <terminators>`, :ref:`binary 7004instructions <binaryops>`, :ref:`bitwise binary 7005instructions <bitwiseops>`, :ref:`memory instructions <memoryops>`, and 7006:ref:`other instructions <otherops>`. 7007 7008.. _terminators: 7009 7010Terminator Instructions 7011----------------------- 7012 7013As mentioned :ref:`previously <functionstructure>`, every basic block in a 7014program ends with a "Terminator" instruction, which indicates which 7015block should be executed after the current block is finished. These 7016terminator instructions typically yield a '``void``' value: they produce 7017control flow, not values (the one exception being the 7018':ref:`invoke <i_invoke>`' instruction). 7019 7020The terminator instructions are: ':ref:`ret <i_ret>`', 7021':ref:`br <i_br>`', ':ref:`switch <i_switch>`', 7022':ref:`indirectbr <i_indirectbr>`', ':ref:`invoke <i_invoke>`', 7023':ref:`callbr <i_callbr>`' 7024':ref:`resume <i_resume>`', ':ref:`catchswitch <i_catchswitch>`', 7025':ref:`catchret <i_catchret>`', 7026':ref:`cleanupret <i_cleanupret>`', 7027and ':ref:`unreachable <i_unreachable>`'. 7028 7029.. _i_ret: 7030 7031'``ret``' Instruction 7032^^^^^^^^^^^^^^^^^^^^^ 7033 7034Syntax: 7035""""""" 7036 7037:: 7038 7039 ret <type> <value> ; Return a value from a non-void function 7040 ret void ; Return from void function 7041 7042Overview: 7043""""""""" 7044 7045The '``ret``' instruction is used to return control flow (and optionally 7046a value) from a function back to the caller. 7047 7048There are two forms of the '``ret``' instruction: one that returns a 7049value and then causes control flow, and one that just causes control 7050flow to occur. 7051 7052Arguments: 7053"""""""""" 7054 7055The '``ret``' instruction optionally accepts a single argument, the 7056return value. The type of the return value must be a ':ref:`first 7057class <t_firstclass>`' type. 7058 7059A function is not :ref:`well formed <wellformed>` if it has a non-void 7060return type and contains a '``ret``' instruction with no return value or 7061a return value with a type that does not match its type, or if it has a 7062void return type and contains a '``ret``' instruction with a return 7063value. 7064 7065Semantics: 7066"""""""""" 7067 7068When the '``ret``' instruction is executed, control flow returns back to 7069the calling function's context. If the caller is a 7070":ref:`call <i_call>`" instruction, execution continues at the 7071instruction after the call. If the caller was an 7072":ref:`invoke <i_invoke>`" instruction, execution continues at the 7073beginning of the "normal" destination block. If the instruction returns 7074a value, that value shall set the call or invoke instruction's return 7075value. 7076 7077Example: 7078"""""""" 7079 7080.. code-block:: llvm 7081 7082 ret i32 5 ; Return an integer value of 5 7083 ret void ; Return from a void function 7084 ret { i32, i8 } { i32 4, i8 2 } ; Return a struct of values 4 and 2 7085 7086.. _i_br: 7087 7088'``br``' Instruction 7089^^^^^^^^^^^^^^^^^^^^ 7090 7091Syntax: 7092""""""" 7093 7094:: 7095 7096 br i1 <cond>, label <iftrue>, label <iffalse> 7097 br label <dest> ; Unconditional branch 7098 7099Overview: 7100""""""""" 7101 7102The '``br``' instruction is used to cause control flow to transfer to a 7103different basic block in the current function. There are two forms of 7104this instruction, corresponding to a conditional branch and an 7105unconditional branch. 7106 7107Arguments: 7108"""""""""" 7109 7110The conditional branch form of the '``br``' instruction takes a single 7111'``i1``' value and two '``label``' values. The unconditional form of the 7112'``br``' instruction takes a single '``label``' value as a target. 7113 7114Semantics: 7115"""""""""" 7116 7117Upon execution of a conditional '``br``' instruction, the '``i1``' 7118argument is evaluated. If the value is ``true``, control flows to the 7119'``iftrue``' ``label`` argument. If "cond" is ``false``, control flows 7120to the '``iffalse``' ``label`` argument. 7121If '``cond``' is ``poison`` or ``undef``, this instruction has undefined 7122behavior. 7123 7124Example: 7125"""""""" 7126 7127.. code-block:: llvm 7128 7129 Test: 7130 %cond = icmp eq i32 %a, %b 7131 br i1 %cond, label %IfEqual, label %IfUnequal 7132 IfEqual: 7133 ret i32 1 7134 IfUnequal: 7135 ret i32 0 7136 7137.. _i_switch: 7138 7139'``switch``' Instruction 7140^^^^^^^^^^^^^^^^^^^^^^^^ 7141 7142Syntax: 7143""""""" 7144 7145:: 7146 7147 switch <intty> <value>, label <defaultdest> [ <intty> <val>, label <dest> ... ] 7148 7149Overview: 7150""""""""" 7151 7152The '``switch``' instruction is used to transfer control flow to one of 7153several different places. It is a generalization of the '``br``' 7154instruction, allowing a branch to occur to one of many possible 7155destinations. 7156 7157Arguments: 7158"""""""""" 7159 7160The '``switch``' instruction uses three parameters: an integer 7161comparison value '``value``', a default '``label``' destination, and an 7162array of pairs of comparison value constants and '``label``'s. The table 7163is not allowed to contain duplicate constant entries. 7164 7165Semantics: 7166"""""""""" 7167 7168The ``switch`` instruction specifies a table of values and destinations. 7169When the '``switch``' instruction is executed, this table is searched 7170for the given value. If the value is found, control flow is transferred 7171to the corresponding destination; otherwise, control flow is transferred 7172to the default destination. 7173If '``value``' is ``poison`` or ``undef``, this instruction has undefined 7174behavior. 7175 7176Implementation: 7177""""""""""""""" 7178 7179Depending on properties of the target machine and the particular 7180``switch`` instruction, this instruction may be code generated in 7181different ways. For example, it could be generated as a series of 7182chained conditional branches or with a lookup table. 7183 7184Example: 7185"""""""" 7186 7187.. code-block:: llvm 7188 7189 ; Emulate a conditional br instruction 7190 %Val = zext i1 %value to i32 7191 switch i32 %Val, label %truedest [ i32 0, label %falsedest ] 7192 7193 ; Emulate an unconditional br instruction 7194 switch i32 0, label %dest [ ] 7195 7196 ; Implement a jump table: 7197 switch i32 %val, label %otherwise [ i32 0, label %onzero 7198 i32 1, label %onone 7199 i32 2, label %ontwo ] 7200 7201.. _i_indirectbr: 7202 7203'``indirectbr``' Instruction 7204^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 7205 7206Syntax: 7207""""""" 7208 7209:: 7210 7211 indirectbr <somety>* <address>, [ label <dest1>, label <dest2>, ... ] 7212 7213Overview: 7214""""""""" 7215 7216The '``indirectbr``' instruction implements an indirect branch to a 7217label within the current function, whose address is specified by 7218"``address``". Address must be derived from a 7219:ref:`blockaddress <blockaddress>` constant. 7220 7221Arguments: 7222"""""""""" 7223 7224The '``address``' argument is the address of the label to jump to. The 7225rest of the arguments indicate the full set of possible destinations 7226that the address may point to. Blocks are allowed to occur multiple 7227times in the destination list, though this isn't particularly useful. 7228 7229This destination list is required so that dataflow analysis has an 7230accurate understanding of the CFG. 7231 7232Semantics: 7233"""""""""" 7234 7235Control transfers to the block specified in the address argument. All 7236possible destination blocks must be listed in the label list, otherwise 7237this instruction has undefined behavior. This implies that jumps to 7238labels defined in other functions have undefined behavior as well. 7239If '``address``' is ``poison`` or ``undef``, this instruction has undefined 7240behavior. 7241 7242Implementation: 7243""""""""""""""" 7244 7245This is typically implemented with a jump through a register. 7246 7247Example: 7248"""""""" 7249 7250.. code-block:: llvm 7251 7252 indirectbr i8* %Addr, [ label %bb1, label %bb2, label %bb3 ] 7253 7254.. _i_invoke: 7255 7256'``invoke``' Instruction 7257^^^^^^^^^^^^^^^^^^^^^^^^ 7258 7259Syntax: 7260""""""" 7261 7262:: 7263 7264 <result> = invoke [cconv] [ret attrs] [addrspace(<num>)] <ty>|<fnty> <fnptrval>(<function args>) [fn attrs] 7265 [operand bundles] to label <normal label> unwind label <exception label> 7266 7267Overview: 7268""""""""" 7269 7270The '``invoke``' instruction causes control to transfer to a specified 7271function, with the possibility of control flow transfer to either the 7272'``normal``' label or the '``exception``' label. If the callee function 7273returns with the "``ret``" instruction, control flow will return to the 7274"normal" label. If the callee (or any indirect callees) returns via the 7275":ref:`resume <i_resume>`" instruction or other exception handling 7276mechanism, control is interrupted and continued at the dynamically 7277nearest "exception" label. 7278 7279The '``exception``' label is a `landing 7280pad <ExceptionHandling.html#overview>`_ for the exception. As such, 7281'``exception``' label is required to have the 7282":ref:`landingpad <i_landingpad>`" instruction, which contains the 7283information about the behavior of the program after unwinding happens, 7284as its first non-PHI instruction. The restrictions on the 7285"``landingpad``" instruction's tightly couples it to the "``invoke``" 7286instruction, so that the important information contained within the 7287"``landingpad``" instruction can't be lost through normal code motion. 7288 7289Arguments: 7290"""""""""" 7291 7292This instruction requires several arguments: 7293 7294#. The optional "cconv" marker indicates which :ref:`calling 7295 convention <callingconv>` the call should use. If none is 7296 specified, the call defaults to using C calling conventions. 7297#. The optional :ref:`Parameter Attributes <paramattrs>` list for return 7298 values. Only '``zeroext``', '``signext``', and '``inreg``' attributes 7299 are valid here. 7300#. The optional addrspace attribute can be used to indicate the address space 7301 of the called function. If it is not specified, the program address space 7302 from the :ref:`datalayout string<langref_datalayout>` will be used. 7303#. '``ty``': the type of the call instruction itself which is also the 7304 type of the return value. Functions that return no value are marked 7305 ``void``. 7306#. '``fnty``': shall be the signature of the function being invoked. The 7307 argument types must match the types implied by this signature. This 7308 type can be omitted if the function is not varargs. 7309#. '``fnptrval``': An LLVM value containing a pointer to a function to 7310 be invoked. In most cases, this is a direct function invocation, but 7311 indirect ``invoke``'s are just as possible, calling an arbitrary pointer 7312 to function value. 7313#. '``function args``': argument list whose types match the function 7314 signature argument types and parameter attributes. All arguments must 7315 be of :ref:`first class <t_firstclass>` type. If the function signature 7316 indicates the function accepts a variable number of arguments, the 7317 extra arguments can be specified. 7318#. '``normal label``': the label reached when the called function 7319 executes a '``ret``' instruction. 7320#. '``exception label``': the label reached when a callee returns via 7321 the :ref:`resume <i_resume>` instruction or other exception handling 7322 mechanism. 7323#. The optional :ref:`function attributes <fnattrs>` list. 7324#. The optional :ref:`operand bundles <opbundles>` list. 7325 7326Semantics: 7327"""""""""" 7328 7329This instruction is designed to operate as a standard '``call``' 7330instruction in most regards. The primary difference is that it 7331establishes an association with a label, which is used by the runtime 7332library to unwind the stack. 7333 7334This instruction is used in languages with destructors to ensure that 7335proper cleanup is performed in the case of either a ``longjmp`` or a 7336thrown exception. Additionally, this is important for implementation of 7337'``catch``' clauses in high-level languages that support them. 7338 7339For the purposes of the SSA form, the definition of the value returned 7340by the '``invoke``' instruction is deemed to occur on the edge from the 7341current block to the "normal" label. If the callee unwinds then no 7342return value is available. 7343 7344Example: 7345"""""""" 7346 7347.. code-block:: llvm 7348 7349 %retval = invoke i32 @Test(i32 15) to label %Continue 7350 unwind label %TestCleanup ; i32:retval set 7351 %retval = invoke coldcc i32 %Testfnptr(i32 15) to label %Continue 7352 unwind label %TestCleanup ; i32:retval set 7353 7354.. _i_callbr: 7355 7356'``callbr``' Instruction 7357^^^^^^^^^^^^^^^^^^^^^^^^ 7358 7359Syntax: 7360""""""" 7361 7362:: 7363 7364 <result> = callbr [cconv] [ret attrs] [addrspace(<num>)] <ty>|<fnty> <fnptrval>(<function args>) [fn attrs] 7365 [operand bundles] to label <fallthrough label> [indirect labels] 7366 7367Overview: 7368""""""""" 7369 7370The '``callbr``' instruction causes control to transfer to a specified 7371function, with the possibility of control flow transfer to either the 7372'``fallthrough``' label or one of the '``indirect``' labels. 7373 7374This instruction should only be used to implement the "goto" feature of gcc 7375style inline assembly. Any other usage is an error in the IR verifier. 7376 7377Arguments: 7378"""""""""" 7379 7380This instruction requires several arguments: 7381 7382#. The optional "cconv" marker indicates which :ref:`calling 7383 convention <callingconv>` the call should use. If none is 7384 specified, the call defaults to using C calling conventions. 7385#. The optional :ref:`Parameter Attributes <paramattrs>` list for return 7386 values. Only '``zeroext``', '``signext``', and '``inreg``' attributes 7387 are valid here. 7388#. The optional addrspace attribute can be used to indicate the address space 7389 of the called function. If it is not specified, the program address space 7390 from the :ref:`datalayout string<langref_datalayout>` will be used. 7391#. '``ty``': the type of the call instruction itself which is also the 7392 type of the return value. Functions that return no value are marked 7393 ``void``. 7394#. '``fnty``': shall be the signature of the function being called. The 7395 argument types must match the types implied by this signature. This 7396 type can be omitted if the function is not varargs. 7397#. '``fnptrval``': An LLVM value containing a pointer to a function to 7398 be called. In most cases, this is a direct function call, but 7399 other ``callbr``'s are just as possible, calling an arbitrary pointer 7400 to function value. 7401#. '``function args``': argument list whose types match the function 7402 signature argument types and parameter attributes. All arguments must 7403 be of :ref:`first class <t_firstclass>` type. If the function signature 7404 indicates the function accepts a variable number of arguments, the 7405 extra arguments can be specified. 7406#. '``fallthrough label``': the label reached when the inline assembly's 7407 execution exits the bottom. 7408#. '``indirect labels``': the labels reached when a callee transfers control 7409 to a location other than the '``fallthrough label``'. The blockaddress 7410 constant for these should also be in the list of '``function args``'. 7411#. The optional :ref:`function attributes <fnattrs>` list. 7412#. The optional :ref:`operand bundles <opbundles>` list. 7413 7414Semantics: 7415"""""""""" 7416 7417This instruction is designed to operate as a standard '``call``' 7418instruction in most regards. The primary difference is that it 7419establishes an association with additional labels to define where control 7420flow goes after the call. 7421 7422The output values of a '``callbr``' instruction are available only to 7423the '``fallthrough``' block, not to any '``indirect``' blocks(s). 7424 7425The only use of this today is to implement the "goto" feature of gcc inline 7426assembly where additional labels can be provided as locations for the inline 7427assembly to jump to. 7428 7429Example: 7430"""""""" 7431 7432.. code-block:: llvm 7433 7434 ; "asm goto" without output constraints. 7435 callbr void asm "", "r,X"(i32 %x, i8 *blockaddress(@foo, %indirect)) 7436 to label %fallthrough [label %indirect] 7437 7438 ; "asm goto" with output constraints. 7439 <result> = callbr i32 asm "", "=r,r,X"(i32 %x, i8 *blockaddress(@foo, %indirect)) 7440 to label %fallthrough [label %indirect] 7441 7442.. _i_resume: 7443 7444'``resume``' Instruction 7445^^^^^^^^^^^^^^^^^^^^^^^^ 7446 7447Syntax: 7448""""""" 7449 7450:: 7451 7452 resume <type> <value> 7453 7454Overview: 7455""""""""" 7456 7457The '``resume``' instruction is a terminator instruction that has no 7458successors. 7459 7460Arguments: 7461"""""""""" 7462 7463The '``resume``' instruction requires one argument, which must have the 7464same type as the result of any '``landingpad``' instruction in the same 7465function. 7466 7467Semantics: 7468"""""""""" 7469 7470The '``resume``' instruction resumes propagation of an existing 7471(in-flight) exception whose unwinding was interrupted with a 7472:ref:`landingpad <i_landingpad>` instruction. 7473 7474Example: 7475"""""""" 7476 7477.. code-block:: llvm 7478 7479 resume { i8*, i32 } %exn 7480 7481.. _i_catchswitch: 7482 7483'``catchswitch``' Instruction 7484^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 7485 7486Syntax: 7487""""""" 7488 7489:: 7490 7491 <resultval> = catchswitch within <parent> [ label <handler1>, label <handler2>, ... ] unwind to caller 7492 <resultval> = catchswitch within <parent> [ label <handler1>, label <handler2>, ... ] unwind label <default> 7493 7494Overview: 7495""""""""" 7496 7497The '``catchswitch``' instruction is used by `LLVM's exception handling system 7498<ExceptionHandling.html#overview>`_ to describe the set of possible catch handlers 7499that may be executed by the :ref:`EH personality routine <personalityfn>`. 7500 7501Arguments: 7502"""""""""" 7503 7504The ``parent`` argument is the token of the funclet that contains the 7505``catchswitch`` instruction. If the ``catchswitch`` is not inside a funclet, 7506this operand may be the token ``none``. 7507 7508The ``default`` argument is the label of another basic block beginning with 7509either a ``cleanuppad`` or ``catchswitch`` instruction. This unwind destination 7510must be a legal target with respect to the ``parent`` links, as described in 7511the `exception handling documentation\ <ExceptionHandling.html#wineh-constraints>`_. 7512 7513The ``handlers`` are a nonempty list of successor blocks that each begin with a 7514:ref:`catchpad <i_catchpad>` instruction. 7515 7516Semantics: 7517"""""""""" 7518 7519Executing this instruction transfers control to one of the successors in 7520``handlers``, if appropriate, or continues to unwind via the unwind label if 7521present. 7522 7523The ``catchswitch`` is both a terminator and a "pad" instruction, meaning that 7524it must be both the first non-phi instruction and last instruction in the basic 7525block. Therefore, it must be the only non-phi instruction in the block. 7526 7527Example: 7528"""""""" 7529 7530.. code-block:: text 7531 7532 dispatch1: 7533 %cs1 = catchswitch within none [label %handler0, label %handler1] unwind to caller 7534 dispatch2: 7535 %cs2 = catchswitch within %parenthandler [label %handler0] unwind label %cleanup 7536 7537.. _i_catchret: 7538 7539'``catchret``' Instruction 7540^^^^^^^^^^^^^^^^^^^^^^^^^^ 7541 7542Syntax: 7543""""""" 7544 7545:: 7546 7547 catchret from <token> to label <normal> 7548 7549Overview: 7550""""""""" 7551 7552The '``catchret``' instruction is a terminator instruction that has a 7553single successor. 7554 7555 7556Arguments: 7557"""""""""" 7558 7559The first argument to a '``catchret``' indicates which ``catchpad`` it 7560exits. It must be a :ref:`catchpad <i_catchpad>`. 7561The second argument to a '``catchret``' specifies where control will 7562transfer to next. 7563 7564Semantics: 7565"""""""""" 7566 7567The '``catchret``' instruction ends an existing (in-flight) exception whose 7568unwinding was interrupted with a :ref:`catchpad <i_catchpad>` instruction. The 7569:ref:`personality function <personalityfn>` gets a chance to execute arbitrary 7570code to, for example, destroy the active exception. Control then transfers to 7571``normal``. 7572 7573The ``token`` argument must be a token produced by a ``catchpad`` instruction. 7574If the specified ``catchpad`` is not the most-recently-entered not-yet-exited 7575funclet pad (as described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_), 7576the ``catchret``'s behavior is undefined. 7577 7578Example: 7579"""""""" 7580 7581.. code-block:: text 7582 7583 catchret from %catch label %continue 7584 7585.. _i_cleanupret: 7586 7587'``cleanupret``' Instruction 7588^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 7589 7590Syntax: 7591""""""" 7592 7593:: 7594 7595 cleanupret from <value> unwind label <continue> 7596 cleanupret from <value> unwind to caller 7597 7598Overview: 7599""""""""" 7600 7601The '``cleanupret``' instruction is a terminator instruction that has 7602an optional successor. 7603 7604 7605Arguments: 7606"""""""""" 7607 7608The '``cleanupret``' instruction requires one argument, which indicates 7609which ``cleanuppad`` it exits, and must be a :ref:`cleanuppad <i_cleanuppad>`. 7610If the specified ``cleanuppad`` is not the most-recently-entered not-yet-exited 7611funclet pad (as described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_), 7612the ``cleanupret``'s behavior is undefined. 7613 7614The '``cleanupret``' instruction also has an optional successor, ``continue``, 7615which must be the label of another basic block beginning with either a 7616``cleanuppad`` or ``catchswitch`` instruction. This unwind destination must 7617be a legal target with respect to the ``parent`` links, as described in the 7618`exception handling documentation\ <ExceptionHandling.html#wineh-constraints>`_. 7619 7620Semantics: 7621"""""""""" 7622 7623The '``cleanupret``' instruction indicates to the 7624:ref:`personality function <personalityfn>` that one 7625:ref:`cleanuppad <i_cleanuppad>` it transferred control to has ended. 7626It transfers control to ``continue`` or unwinds out of the function. 7627 7628Example: 7629"""""""" 7630 7631.. code-block:: text 7632 7633 cleanupret from %cleanup unwind to caller 7634 cleanupret from %cleanup unwind label %continue 7635 7636.. _i_unreachable: 7637 7638'``unreachable``' Instruction 7639^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 7640 7641Syntax: 7642""""""" 7643 7644:: 7645 7646 unreachable 7647 7648Overview: 7649""""""""" 7650 7651The '``unreachable``' instruction has no defined semantics. This 7652instruction is used to inform the optimizer that a particular portion of 7653the code is not reachable. This can be used to indicate that the code 7654after a no-return function cannot be reached, and other facts. 7655 7656Semantics: 7657"""""""""" 7658 7659The '``unreachable``' instruction has no defined semantics. 7660 7661.. _unaryops: 7662 7663Unary Operations 7664----------------- 7665 7666Unary operators require a single operand, execute an operation on 7667it, and produce a single value. The operand might represent multiple 7668data, as is the case with the :ref:`vector <t_vector>` data type. The 7669result value has the same type as its operand. 7670 7671.. _i_fneg: 7672 7673'``fneg``' Instruction 7674^^^^^^^^^^^^^^^^^^^^^^ 7675 7676Syntax: 7677""""""" 7678 7679:: 7680 7681 <result> = fneg [fast-math flags]* <ty> <op1> ; yields ty:result 7682 7683Overview: 7684""""""""" 7685 7686The '``fneg``' instruction returns the negation of its operand. 7687 7688Arguments: 7689"""""""""" 7690 7691The argument to the '``fneg``' instruction must be a 7692:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of 7693floating-point values. 7694 7695Semantics: 7696"""""""""" 7697 7698The value produced is a copy of the operand with its sign bit flipped. 7699This instruction can also take any number of :ref:`fast-math 7700flags <fastmath>`, which are optimization hints to enable otherwise 7701unsafe floating-point optimizations: 7702 7703Example: 7704"""""""" 7705 7706.. code-block:: text 7707 7708 <result> = fneg float %val ; yields float:result = -%var 7709 7710.. _binaryops: 7711 7712Binary Operations 7713----------------- 7714 7715Binary operators are used to do most of the computation in a program. 7716They require two operands of the same type, execute an operation on 7717them, and produce a single value. The operands might represent multiple 7718data, as is the case with the :ref:`vector <t_vector>` data type. The 7719result value has the same type as its operands. 7720 7721There are several different binary operators: 7722 7723.. _i_add: 7724 7725'``add``' Instruction 7726^^^^^^^^^^^^^^^^^^^^^ 7727 7728Syntax: 7729""""""" 7730 7731:: 7732 7733 <result> = add <ty> <op1>, <op2> ; yields ty:result 7734 <result> = add nuw <ty> <op1>, <op2> ; yields ty:result 7735 <result> = add nsw <ty> <op1>, <op2> ; yields ty:result 7736 <result> = add nuw nsw <ty> <op1>, <op2> ; yields ty:result 7737 7738Overview: 7739""""""""" 7740 7741The '``add``' instruction returns the sum of its two operands. 7742 7743Arguments: 7744"""""""""" 7745 7746The two arguments to the '``add``' instruction must be 7747:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 7748arguments must have identical types. 7749 7750Semantics: 7751"""""""""" 7752 7753The value produced is the integer sum of the two operands. 7754 7755If the sum has unsigned overflow, the result returned is the 7756mathematical result modulo 2\ :sup:`n`\ , where n is the bit width of 7757the result. 7758 7759Because LLVM integers use a two's complement representation, this 7760instruction is appropriate for both signed and unsigned integers. 7761 7762``nuw`` and ``nsw`` stand for "No Unsigned Wrap" and "No Signed Wrap", 7763respectively. If the ``nuw`` and/or ``nsw`` keywords are present, the 7764result value of the ``add`` is a :ref:`poison value <poisonvalues>` if 7765unsigned and/or signed overflow, respectively, occurs. 7766 7767Example: 7768"""""""" 7769 7770.. code-block:: text 7771 7772 <result> = add i32 4, %var ; yields i32:result = 4 + %var 7773 7774.. _i_fadd: 7775 7776'``fadd``' Instruction 7777^^^^^^^^^^^^^^^^^^^^^^ 7778 7779Syntax: 7780""""""" 7781 7782:: 7783 7784 <result> = fadd [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result 7785 7786Overview: 7787""""""""" 7788 7789The '``fadd``' instruction returns the sum of its two operands. 7790 7791Arguments: 7792"""""""""" 7793 7794The two arguments to the '``fadd``' instruction must be 7795:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of 7796floating-point values. Both arguments must have identical types. 7797 7798Semantics: 7799"""""""""" 7800 7801The value produced is the floating-point sum of the two operands. 7802This instruction is assumed to execute in the default :ref:`floating-point 7803environment <floatenv>`. 7804This instruction can also take any number of :ref:`fast-math 7805flags <fastmath>`, which are optimization hints to enable otherwise 7806unsafe floating-point optimizations: 7807 7808Example: 7809"""""""" 7810 7811.. code-block:: text 7812 7813 <result> = fadd float 4.0, %var ; yields float:result = 4.0 + %var 7814 7815.. _i_sub: 7816 7817'``sub``' Instruction 7818^^^^^^^^^^^^^^^^^^^^^ 7819 7820Syntax: 7821""""""" 7822 7823:: 7824 7825 <result> = sub <ty> <op1>, <op2> ; yields ty:result 7826 <result> = sub nuw <ty> <op1>, <op2> ; yields ty:result 7827 <result> = sub nsw <ty> <op1>, <op2> ; yields ty:result 7828 <result> = sub nuw nsw <ty> <op1>, <op2> ; yields ty:result 7829 7830Overview: 7831""""""""" 7832 7833The '``sub``' instruction returns the difference of its two operands. 7834 7835Note that the '``sub``' instruction is used to represent the '``neg``' 7836instruction present in most other intermediate representations. 7837 7838Arguments: 7839"""""""""" 7840 7841The two arguments to the '``sub``' instruction must be 7842:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 7843arguments must have identical types. 7844 7845Semantics: 7846"""""""""" 7847 7848The value produced is the integer difference of the two operands. 7849 7850If the difference has unsigned overflow, the result returned is the 7851mathematical result modulo 2\ :sup:`n`\ , where n is the bit width of 7852the result. 7853 7854Because LLVM integers use a two's complement representation, this 7855instruction is appropriate for both signed and unsigned integers. 7856 7857``nuw`` and ``nsw`` stand for "No Unsigned Wrap" and "No Signed Wrap", 7858respectively. If the ``nuw`` and/or ``nsw`` keywords are present, the 7859result value of the ``sub`` is a :ref:`poison value <poisonvalues>` if 7860unsigned and/or signed overflow, respectively, occurs. 7861 7862Example: 7863"""""""" 7864 7865.. code-block:: text 7866 7867 <result> = sub i32 4, %var ; yields i32:result = 4 - %var 7868 <result> = sub i32 0, %val ; yields i32:result = -%var 7869 7870.. _i_fsub: 7871 7872'``fsub``' Instruction 7873^^^^^^^^^^^^^^^^^^^^^^ 7874 7875Syntax: 7876""""""" 7877 7878:: 7879 7880 <result> = fsub [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result 7881 7882Overview: 7883""""""""" 7884 7885The '``fsub``' instruction returns the difference of its two operands. 7886 7887Arguments: 7888"""""""""" 7889 7890The two arguments to the '``fsub``' instruction must be 7891:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of 7892floating-point values. Both arguments must have identical types. 7893 7894Semantics: 7895"""""""""" 7896 7897The value produced is the floating-point difference of the two operands. 7898This instruction is assumed to execute in the default :ref:`floating-point 7899environment <floatenv>`. 7900This instruction can also take any number of :ref:`fast-math 7901flags <fastmath>`, which are optimization hints to enable otherwise 7902unsafe floating-point optimizations: 7903 7904Example: 7905"""""""" 7906 7907.. code-block:: text 7908 7909 <result> = fsub float 4.0, %var ; yields float:result = 4.0 - %var 7910 <result> = fsub float -0.0, %val ; yields float:result = -%var 7911 7912.. _i_mul: 7913 7914'``mul``' Instruction 7915^^^^^^^^^^^^^^^^^^^^^ 7916 7917Syntax: 7918""""""" 7919 7920:: 7921 7922 <result> = mul <ty> <op1>, <op2> ; yields ty:result 7923 <result> = mul nuw <ty> <op1>, <op2> ; yields ty:result 7924 <result> = mul nsw <ty> <op1>, <op2> ; yields ty:result 7925 <result> = mul nuw nsw <ty> <op1>, <op2> ; yields ty:result 7926 7927Overview: 7928""""""""" 7929 7930The '``mul``' instruction returns the product of its two operands. 7931 7932Arguments: 7933"""""""""" 7934 7935The two arguments to the '``mul``' instruction must be 7936:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 7937arguments must have identical types. 7938 7939Semantics: 7940"""""""""" 7941 7942The value produced is the integer product of the two operands. 7943 7944If the result of the multiplication has unsigned overflow, the result 7945returned is the mathematical result modulo 2\ :sup:`n`\ , where n is the 7946bit width of the result. 7947 7948Because LLVM integers use a two's complement representation, and the 7949result is the same width as the operands, this instruction returns the 7950correct result for both signed and unsigned integers. If a full product 7951(e.g. ``i32`` * ``i32`` -> ``i64``) is needed, the operands should be 7952sign-extended or zero-extended as appropriate to the width of the full 7953product. 7954 7955``nuw`` and ``nsw`` stand for "No Unsigned Wrap" and "No Signed Wrap", 7956respectively. If the ``nuw`` and/or ``nsw`` keywords are present, the 7957result value of the ``mul`` is a :ref:`poison value <poisonvalues>` if 7958unsigned and/or signed overflow, respectively, occurs. 7959 7960Example: 7961"""""""" 7962 7963.. code-block:: text 7964 7965 <result> = mul i32 4, %var ; yields i32:result = 4 * %var 7966 7967.. _i_fmul: 7968 7969'``fmul``' Instruction 7970^^^^^^^^^^^^^^^^^^^^^^ 7971 7972Syntax: 7973""""""" 7974 7975:: 7976 7977 <result> = fmul [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result 7978 7979Overview: 7980""""""""" 7981 7982The '``fmul``' instruction returns the product of its two operands. 7983 7984Arguments: 7985"""""""""" 7986 7987The two arguments to the '``fmul``' instruction must be 7988:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of 7989floating-point values. Both arguments must have identical types. 7990 7991Semantics: 7992"""""""""" 7993 7994The value produced is the floating-point product of the two operands. 7995This instruction is assumed to execute in the default :ref:`floating-point 7996environment <floatenv>`. 7997This instruction can also take any number of :ref:`fast-math 7998flags <fastmath>`, which are optimization hints to enable otherwise 7999unsafe floating-point optimizations: 8000 8001Example: 8002"""""""" 8003 8004.. code-block:: text 8005 8006 <result> = fmul float 4.0, %var ; yields float:result = 4.0 * %var 8007 8008.. _i_udiv: 8009 8010'``udiv``' Instruction 8011^^^^^^^^^^^^^^^^^^^^^^ 8012 8013Syntax: 8014""""""" 8015 8016:: 8017 8018 <result> = udiv <ty> <op1>, <op2> ; yields ty:result 8019 <result> = udiv exact <ty> <op1>, <op2> ; yields ty:result 8020 8021Overview: 8022""""""""" 8023 8024The '``udiv``' instruction returns the quotient of its two operands. 8025 8026Arguments: 8027"""""""""" 8028 8029The two arguments to the '``udiv``' instruction must be 8030:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 8031arguments must have identical types. 8032 8033Semantics: 8034"""""""""" 8035 8036The value produced is the unsigned integer quotient of the two operands. 8037 8038Note that unsigned integer division and signed integer division are 8039distinct operations; for signed integer division, use '``sdiv``'. 8040 8041Division by zero is undefined behavior. For vectors, if any element 8042of the divisor is zero, the operation has undefined behavior. 8043 8044 8045If the ``exact`` keyword is present, the result value of the ``udiv`` is 8046a :ref:`poison value <poisonvalues>` if %op1 is not a multiple of %op2 (as 8047such, "((a udiv exact b) mul b) == a"). 8048 8049Example: 8050"""""""" 8051 8052.. code-block:: text 8053 8054 <result> = udiv i32 4, %var ; yields i32:result = 4 / %var 8055 8056.. _i_sdiv: 8057 8058'``sdiv``' Instruction 8059^^^^^^^^^^^^^^^^^^^^^^ 8060 8061Syntax: 8062""""""" 8063 8064:: 8065 8066 <result> = sdiv <ty> <op1>, <op2> ; yields ty:result 8067 <result> = sdiv exact <ty> <op1>, <op2> ; yields ty:result 8068 8069Overview: 8070""""""""" 8071 8072The '``sdiv``' instruction returns the quotient of its two operands. 8073 8074Arguments: 8075"""""""""" 8076 8077The two arguments to the '``sdiv``' instruction must be 8078:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 8079arguments must have identical types. 8080 8081Semantics: 8082"""""""""" 8083 8084The value produced is the signed integer quotient of the two operands 8085rounded towards zero. 8086 8087Note that signed integer division and unsigned integer division are 8088distinct operations; for unsigned integer division, use '``udiv``'. 8089 8090Division by zero is undefined behavior. For vectors, if any element 8091of the divisor is zero, the operation has undefined behavior. 8092Overflow also leads to undefined behavior; this is a rare case, but can 8093occur, for example, by doing a 32-bit division of -2147483648 by -1. 8094 8095If the ``exact`` keyword is present, the result value of the ``sdiv`` is 8096a :ref:`poison value <poisonvalues>` if the result would be rounded. 8097 8098Example: 8099"""""""" 8100 8101.. code-block:: text 8102 8103 <result> = sdiv i32 4, %var ; yields i32:result = 4 / %var 8104 8105.. _i_fdiv: 8106 8107'``fdiv``' Instruction 8108^^^^^^^^^^^^^^^^^^^^^^ 8109 8110Syntax: 8111""""""" 8112 8113:: 8114 8115 <result> = fdiv [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result 8116 8117Overview: 8118""""""""" 8119 8120The '``fdiv``' instruction returns the quotient of its two operands. 8121 8122Arguments: 8123"""""""""" 8124 8125The two arguments to the '``fdiv``' instruction must be 8126:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of 8127floating-point values. Both arguments must have identical types. 8128 8129Semantics: 8130"""""""""" 8131 8132The value produced is the floating-point quotient of the two operands. 8133This instruction is assumed to execute in the default :ref:`floating-point 8134environment <floatenv>`. 8135This instruction can also take any number of :ref:`fast-math 8136flags <fastmath>`, which are optimization hints to enable otherwise 8137unsafe floating-point optimizations: 8138 8139Example: 8140"""""""" 8141 8142.. code-block:: text 8143 8144 <result> = fdiv float 4.0, %var ; yields float:result = 4.0 / %var 8145 8146.. _i_urem: 8147 8148'``urem``' Instruction 8149^^^^^^^^^^^^^^^^^^^^^^ 8150 8151Syntax: 8152""""""" 8153 8154:: 8155 8156 <result> = urem <ty> <op1>, <op2> ; yields ty:result 8157 8158Overview: 8159""""""""" 8160 8161The '``urem``' instruction returns the remainder from the unsigned 8162division of its two arguments. 8163 8164Arguments: 8165"""""""""" 8166 8167The two arguments to the '``urem``' instruction must be 8168:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 8169arguments must have identical types. 8170 8171Semantics: 8172"""""""""" 8173 8174This instruction returns the unsigned integer *remainder* of a division. 8175This instruction always performs an unsigned division to get the 8176remainder. 8177 8178Note that unsigned integer remainder and signed integer remainder are 8179distinct operations; for signed integer remainder, use '``srem``'. 8180 8181Taking the remainder of a division by zero is undefined behavior. 8182For vectors, if any element of the divisor is zero, the operation has 8183undefined behavior. 8184 8185Example: 8186"""""""" 8187 8188.. code-block:: text 8189 8190 <result> = urem i32 4, %var ; yields i32:result = 4 % %var 8191 8192.. _i_srem: 8193 8194'``srem``' Instruction 8195^^^^^^^^^^^^^^^^^^^^^^ 8196 8197Syntax: 8198""""""" 8199 8200:: 8201 8202 <result> = srem <ty> <op1>, <op2> ; yields ty:result 8203 8204Overview: 8205""""""""" 8206 8207The '``srem``' instruction returns the remainder from the signed 8208division of its two operands. This instruction can also take 8209:ref:`vector <t_vector>` versions of the values in which case the elements 8210must be integers. 8211 8212Arguments: 8213"""""""""" 8214 8215The two arguments to the '``srem``' instruction must be 8216:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 8217arguments must have identical types. 8218 8219Semantics: 8220"""""""""" 8221 8222This instruction returns the *remainder* of a division (where the result 8223is either zero or has the same sign as the dividend, ``op1``), not the 8224*modulo* operator (where the result is either zero or has the same sign 8225as the divisor, ``op2``) of a value. For more information about the 8226difference, see `The Math 8227Forum <http://mathforum.org/dr.math/problems/anne.4.28.99.html>`_. For a 8228table of how this is implemented in various languages, please see 8229`Wikipedia: modulo 8230operation <http://en.wikipedia.org/wiki/Modulo_operation>`_. 8231 8232Note that signed integer remainder and unsigned integer remainder are 8233distinct operations; for unsigned integer remainder, use '``urem``'. 8234 8235Taking the remainder of a division by zero is undefined behavior. 8236For vectors, if any element of the divisor is zero, the operation has 8237undefined behavior. 8238Overflow also leads to undefined behavior; this is a rare case, but can 8239occur, for example, by taking the remainder of a 32-bit division of 8240-2147483648 by -1. (The remainder doesn't actually overflow, but this 8241rule lets srem be implemented using instructions that return both the 8242result of the division and the remainder.) 8243 8244Example: 8245"""""""" 8246 8247.. code-block:: text 8248 8249 <result> = srem i32 4, %var ; yields i32:result = 4 % %var 8250 8251.. _i_frem: 8252 8253'``frem``' Instruction 8254^^^^^^^^^^^^^^^^^^^^^^ 8255 8256Syntax: 8257""""""" 8258 8259:: 8260 8261 <result> = frem [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result 8262 8263Overview: 8264""""""""" 8265 8266The '``frem``' instruction returns the remainder from the division of 8267its two operands. 8268 8269Arguments: 8270"""""""""" 8271 8272The two arguments to the '``frem``' instruction must be 8273:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of 8274floating-point values. Both arguments must have identical types. 8275 8276Semantics: 8277"""""""""" 8278 8279The value produced is the floating-point remainder of the two operands. 8280This is the same output as a libm '``fmod``' function, but without any 8281possibility of setting ``errno``. The remainder has the same sign as the 8282dividend. 8283This instruction is assumed to execute in the default :ref:`floating-point 8284environment <floatenv>`. 8285This instruction can also take any number of :ref:`fast-math 8286flags <fastmath>`, which are optimization hints to enable otherwise 8287unsafe floating-point optimizations: 8288 8289Example: 8290"""""""" 8291 8292.. code-block:: text 8293 8294 <result> = frem float 4.0, %var ; yields float:result = 4.0 % %var 8295 8296.. _bitwiseops: 8297 8298Bitwise Binary Operations 8299------------------------- 8300 8301Bitwise binary operators are used to do various forms of bit-twiddling 8302in a program. They are generally very efficient instructions and can 8303commonly be strength reduced from other instructions. They require two 8304operands of the same type, execute an operation on them, and produce a 8305single value. The resulting value is the same type as its operands. 8306 8307.. _i_shl: 8308 8309'``shl``' Instruction 8310^^^^^^^^^^^^^^^^^^^^^ 8311 8312Syntax: 8313""""""" 8314 8315:: 8316 8317 <result> = shl <ty> <op1>, <op2> ; yields ty:result 8318 <result> = shl nuw <ty> <op1>, <op2> ; yields ty:result 8319 <result> = shl nsw <ty> <op1>, <op2> ; yields ty:result 8320 <result> = shl nuw nsw <ty> <op1>, <op2> ; yields ty:result 8321 8322Overview: 8323""""""""" 8324 8325The '``shl``' instruction returns the first operand shifted to the left 8326a specified number of bits. 8327 8328Arguments: 8329"""""""""" 8330 8331Both arguments to the '``shl``' instruction must be the same 8332:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer type. 8333'``op2``' is treated as an unsigned value. 8334 8335Semantics: 8336"""""""""" 8337 8338The value produced is ``op1`` \* 2\ :sup:`op2` mod 2\ :sup:`n`, 8339where ``n`` is the width of the result. If ``op2`` is (statically or 8340dynamically) equal to or larger than the number of bits in 8341``op1``, this instruction returns a :ref:`poison value <poisonvalues>`. 8342If the arguments are vectors, each vector element of ``op1`` is shifted 8343by the corresponding shift amount in ``op2``. 8344 8345If the ``nuw`` keyword is present, then the shift produces a poison 8346value if it shifts out any non-zero bits. 8347If the ``nsw`` keyword is present, then the shift produces a poison 8348value if it shifts out any bits that disagree with the resultant sign bit. 8349 8350Example: 8351"""""""" 8352 8353.. code-block:: text 8354 8355 <result> = shl i32 4, %var ; yields i32: 4 << %var 8356 <result> = shl i32 4, 2 ; yields i32: 16 8357 <result> = shl i32 1, 10 ; yields i32: 1024 8358 <result> = shl i32 1, 32 ; undefined 8359 <result> = shl <2 x i32> < i32 1, i32 1>, < i32 1, i32 2> ; yields: result=<2 x i32> < i32 2, i32 4> 8360 8361.. _i_lshr: 8362 8363 8364'``lshr``' Instruction 8365^^^^^^^^^^^^^^^^^^^^^^ 8366 8367Syntax: 8368""""""" 8369 8370:: 8371 8372 <result> = lshr <ty> <op1>, <op2> ; yields ty:result 8373 <result> = lshr exact <ty> <op1>, <op2> ; yields ty:result 8374 8375Overview: 8376""""""""" 8377 8378The '``lshr``' instruction (logical shift right) returns the first 8379operand shifted to the right a specified number of bits with zero fill. 8380 8381Arguments: 8382"""""""""" 8383 8384Both arguments to the '``lshr``' instruction must be the same 8385:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer type. 8386'``op2``' is treated as an unsigned value. 8387 8388Semantics: 8389"""""""""" 8390 8391This instruction always performs a logical shift right operation. The 8392most significant bits of the result will be filled with zero bits after 8393the shift. If ``op2`` is (statically or dynamically) equal to or larger 8394than the number of bits in ``op1``, this instruction returns a :ref:`poison 8395value <poisonvalues>`. If the arguments are vectors, each vector element 8396of ``op1`` is shifted by the corresponding shift amount in ``op2``. 8397 8398If the ``exact`` keyword is present, the result value of the ``lshr`` is 8399a poison value if any of the bits shifted out are non-zero. 8400 8401Example: 8402"""""""" 8403 8404.. code-block:: text 8405 8406 <result> = lshr i32 4, 1 ; yields i32:result = 2 8407 <result> = lshr i32 4, 2 ; yields i32:result = 1 8408 <result> = lshr i8 4, 3 ; yields i8:result = 0 8409 <result> = lshr i8 -2, 1 ; yields i8:result = 0x7F 8410 <result> = lshr i32 1, 32 ; undefined 8411 <result> = lshr <2 x i32> < i32 -2, i32 4>, < i32 1, i32 2> ; yields: result=<2 x i32> < i32 0x7FFFFFFF, i32 1> 8412 8413.. _i_ashr: 8414 8415'``ashr``' Instruction 8416^^^^^^^^^^^^^^^^^^^^^^ 8417 8418Syntax: 8419""""""" 8420 8421:: 8422 8423 <result> = ashr <ty> <op1>, <op2> ; yields ty:result 8424 <result> = ashr exact <ty> <op1>, <op2> ; yields ty:result 8425 8426Overview: 8427""""""""" 8428 8429The '``ashr``' instruction (arithmetic shift right) returns the first 8430operand shifted to the right a specified number of bits with sign 8431extension. 8432 8433Arguments: 8434"""""""""" 8435 8436Both arguments to the '``ashr``' instruction must be the same 8437:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer type. 8438'``op2``' is treated as an unsigned value. 8439 8440Semantics: 8441"""""""""" 8442 8443This instruction always performs an arithmetic shift right operation, 8444The most significant bits of the result will be filled with the sign bit 8445of ``op1``. If ``op2`` is (statically or dynamically) equal to or larger 8446than the number of bits in ``op1``, this instruction returns a :ref:`poison 8447value <poisonvalues>`. If the arguments are vectors, each vector element 8448of ``op1`` is shifted by the corresponding shift amount in ``op2``. 8449 8450If the ``exact`` keyword is present, the result value of the ``ashr`` is 8451a poison value if any of the bits shifted out are non-zero. 8452 8453Example: 8454"""""""" 8455 8456.. code-block:: text 8457 8458 <result> = ashr i32 4, 1 ; yields i32:result = 2 8459 <result> = ashr i32 4, 2 ; yields i32:result = 1 8460 <result> = ashr i8 4, 3 ; yields i8:result = 0 8461 <result> = ashr i8 -2, 1 ; yields i8:result = -1 8462 <result> = ashr i32 1, 32 ; undefined 8463 <result> = ashr <2 x i32> < i32 -2, i32 4>, < i32 1, i32 3> ; yields: result=<2 x i32> < i32 -1, i32 0> 8464 8465.. _i_and: 8466 8467'``and``' Instruction 8468^^^^^^^^^^^^^^^^^^^^^ 8469 8470Syntax: 8471""""""" 8472 8473:: 8474 8475 <result> = and <ty> <op1>, <op2> ; yields ty:result 8476 8477Overview: 8478""""""""" 8479 8480The '``and``' instruction returns the bitwise logical and of its two 8481operands. 8482 8483Arguments: 8484"""""""""" 8485 8486The two arguments to the '``and``' instruction must be 8487:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 8488arguments must have identical types. 8489 8490Semantics: 8491"""""""""" 8492 8493The truth table used for the '``and``' instruction is: 8494 8495+-----+-----+-----+ 8496| In0 | In1 | Out | 8497+-----+-----+-----+ 8498| 0 | 0 | 0 | 8499+-----+-----+-----+ 8500| 0 | 1 | 0 | 8501+-----+-----+-----+ 8502| 1 | 0 | 0 | 8503+-----+-----+-----+ 8504| 1 | 1 | 1 | 8505+-----+-----+-----+ 8506 8507Example: 8508"""""""" 8509 8510.. code-block:: text 8511 8512 <result> = and i32 4, %var ; yields i32:result = 4 & %var 8513 <result> = and i32 15, 40 ; yields i32:result = 8 8514 <result> = and i32 4, 8 ; yields i32:result = 0 8515 8516.. _i_or: 8517 8518'``or``' Instruction 8519^^^^^^^^^^^^^^^^^^^^ 8520 8521Syntax: 8522""""""" 8523 8524:: 8525 8526 <result> = or <ty> <op1>, <op2> ; yields ty:result 8527 8528Overview: 8529""""""""" 8530 8531The '``or``' instruction returns the bitwise logical inclusive or of its 8532two operands. 8533 8534Arguments: 8535"""""""""" 8536 8537The two arguments to the '``or``' instruction must be 8538:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 8539arguments must have identical types. 8540 8541Semantics: 8542"""""""""" 8543 8544The truth table used for the '``or``' instruction is: 8545 8546+-----+-----+-----+ 8547| In0 | In1 | Out | 8548+-----+-----+-----+ 8549| 0 | 0 | 0 | 8550+-----+-----+-----+ 8551| 0 | 1 | 1 | 8552+-----+-----+-----+ 8553| 1 | 0 | 1 | 8554+-----+-----+-----+ 8555| 1 | 1 | 1 | 8556+-----+-----+-----+ 8557 8558Example: 8559"""""""" 8560 8561:: 8562 8563 <result> = or i32 4, %var ; yields i32:result = 4 | %var 8564 <result> = or i32 15, 40 ; yields i32:result = 47 8565 <result> = or i32 4, 8 ; yields i32:result = 12 8566 8567.. _i_xor: 8568 8569'``xor``' Instruction 8570^^^^^^^^^^^^^^^^^^^^^ 8571 8572Syntax: 8573""""""" 8574 8575:: 8576 8577 <result> = xor <ty> <op1>, <op2> ; yields ty:result 8578 8579Overview: 8580""""""""" 8581 8582The '``xor``' instruction returns the bitwise logical exclusive or of 8583its two operands. The ``xor`` is used to implement the "one's 8584complement" operation, which is the "~" operator in C. 8585 8586Arguments: 8587"""""""""" 8588 8589The two arguments to the '``xor``' instruction must be 8590:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 8591arguments must have identical types. 8592 8593Semantics: 8594"""""""""" 8595 8596The truth table used for the '``xor``' instruction is: 8597 8598+-----+-----+-----+ 8599| In0 | In1 | Out | 8600+-----+-----+-----+ 8601| 0 | 0 | 0 | 8602+-----+-----+-----+ 8603| 0 | 1 | 1 | 8604+-----+-----+-----+ 8605| 1 | 0 | 1 | 8606+-----+-----+-----+ 8607| 1 | 1 | 0 | 8608+-----+-----+-----+ 8609 8610Example: 8611"""""""" 8612 8613.. code-block:: text 8614 8615 <result> = xor i32 4, %var ; yields i32:result = 4 ^ %var 8616 <result> = xor i32 15, 40 ; yields i32:result = 39 8617 <result> = xor i32 4, 8 ; yields i32:result = 12 8618 <result> = xor i32 %V, -1 ; yields i32:result = ~%V 8619 8620Vector Operations 8621----------------- 8622 8623LLVM supports several instructions to represent vector operations in a 8624target-independent manner. These instructions cover the element-access 8625and vector-specific operations needed to process vectors effectively. 8626While LLVM does directly support these vector operations, many 8627sophisticated algorithms will want to use target-specific intrinsics to 8628take full advantage of a specific target. 8629 8630.. _i_extractelement: 8631 8632'``extractelement``' Instruction 8633^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 8634 8635Syntax: 8636""""""" 8637 8638:: 8639 8640 <result> = extractelement <n x <ty>> <val>, <ty2> <idx> ; yields <ty> 8641 <result> = extractelement <vscale x n x <ty>> <val>, <ty2> <idx> ; yields <ty> 8642 8643Overview: 8644""""""""" 8645 8646The '``extractelement``' instruction extracts a single scalar element 8647from a vector at a specified index. 8648 8649Arguments: 8650"""""""""" 8651 8652The first operand of an '``extractelement``' instruction is a value of 8653:ref:`vector <t_vector>` type. The second operand is an index indicating 8654the position from which to extract the element. The index may be a 8655variable of any integer type. 8656 8657Semantics: 8658"""""""""" 8659 8660The result is a scalar of the same type as the element type of ``val``. 8661Its value is the value at position ``idx`` of ``val``. If ``idx`` 8662exceeds the length of ``val`` for a fixed-length vector, the result is a 8663:ref:`poison value <poisonvalues>`. For a scalable vector, if the value 8664of ``idx`` exceeds the runtime length of the vector, the result is a 8665:ref:`poison value <poisonvalues>`. 8666 8667Example: 8668"""""""" 8669 8670.. code-block:: text 8671 8672 <result> = extractelement <4 x i32> %vec, i32 0 ; yields i32 8673 8674.. _i_insertelement: 8675 8676'``insertelement``' Instruction 8677^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 8678 8679Syntax: 8680""""""" 8681 8682:: 8683 8684 <result> = insertelement <n x <ty>> <val>, <ty> <elt>, <ty2> <idx> ; yields <n x <ty>> 8685 <result> = insertelement <vscale x n x <ty>> <val>, <ty> <elt>, <ty2> <idx> ; yields <vscale x n x <ty>> 8686 8687Overview: 8688""""""""" 8689 8690The '``insertelement``' instruction inserts a scalar element into a 8691vector at a specified index. 8692 8693Arguments: 8694"""""""""" 8695 8696The first operand of an '``insertelement``' instruction is a value of 8697:ref:`vector <t_vector>` type. The second operand is a scalar value whose 8698type must equal the element type of the first operand. The third operand 8699is an index indicating the position at which to insert the value. The 8700index may be a variable of any integer type. 8701 8702Semantics: 8703"""""""""" 8704 8705The result is a vector of the same type as ``val``. Its element values 8706are those of ``val`` except at position ``idx``, where it gets the value 8707``elt``. If ``idx`` exceeds the length of ``val`` for a fixed-length vector, 8708the result is a :ref:`poison value <poisonvalues>`. For a scalable vector, 8709if the value of ``idx`` exceeds the runtime length of the vector, the result 8710is a :ref:`poison value <poisonvalues>`. 8711 8712Example: 8713"""""""" 8714 8715.. code-block:: text 8716 8717 <result> = insertelement <4 x i32> %vec, i32 1, i32 0 ; yields <4 x i32> 8718 8719.. _i_shufflevector: 8720 8721'``shufflevector``' Instruction 8722^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 8723 8724Syntax: 8725""""""" 8726 8727:: 8728 8729 <result> = shufflevector <n x <ty>> <v1>, <n x <ty>> <v2>, <m x i32> <mask> ; yields <m x <ty>> 8730 <result> = shufflevector <vscale x n x <ty>> <v1>, <vscale x n x <ty>> v2, <vscale x m x i32> <mask> ; yields <vscale x m x <ty>> 8731 8732Overview: 8733""""""""" 8734 8735The '``shufflevector``' instruction constructs a permutation of elements 8736from two input vectors, returning a vector with the same element type as 8737the input and length that is the same as the shuffle mask. 8738 8739Arguments: 8740"""""""""" 8741 8742The first two operands of a '``shufflevector``' instruction are vectors 8743with the same type. The third argument is a shuffle mask vector constant 8744whose element type is ``i32``. The mask vector elements must be constant 8745integers or ``undef`` values. The result of the instruction is a vector 8746whose length is the same as the shuffle mask and whose element type is the 8747same as the element type of the first two operands. 8748 8749Semantics: 8750"""""""""" 8751 8752The elements of the two input vectors are numbered from left to right 8753across both of the vectors. For each element of the result vector, the 8754shuffle mask selects an element from one of the input vectors to copy 8755to the result. Non-negative elements in the mask represent an index 8756into the concatenated pair of input vectors. 8757 8758If the shuffle mask is undefined, the result vector is undefined. If 8759the shuffle mask selects an undefined element from one of the input 8760vectors, the resulting element is undefined. An undefined element 8761in the mask vector specifies that the resulting element is undefined. 8762An undefined element in the mask vector prevents a poisoned vector 8763element from propagating. 8764 8765For scalable vectors, the only valid mask values at present are 8766``zeroinitializer`` and ``undef``, since we cannot write all indices as 8767literals for a vector with a length unknown at compile time. 8768 8769Example: 8770"""""""" 8771 8772.. code-block:: text 8773 8774 <result> = shufflevector <4 x i32> %v1, <4 x i32> %v2, 8775 <4 x i32> <i32 0, i32 4, i32 1, i32 5> ; yields <4 x i32> 8776 <result> = shufflevector <4 x i32> %v1, <4 x i32> undef, 8777 <4 x i32> <i32 0, i32 1, i32 2, i32 3> ; yields <4 x i32> - Identity shuffle. 8778 <result> = shufflevector <8 x i32> %v1, <8 x i32> undef, 8779 <4 x i32> <i32 0, i32 1, i32 2, i32 3> ; yields <4 x i32> 8780 <result> = shufflevector <4 x i32> %v1, <4 x i32> %v2, 8781 <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7 > ; yields <8 x i32> 8782 8783Aggregate Operations 8784-------------------- 8785 8786LLVM supports several instructions for working with 8787:ref:`aggregate <t_aggregate>` values. 8788 8789.. _i_extractvalue: 8790 8791'``extractvalue``' Instruction 8792^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 8793 8794Syntax: 8795""""""" 8796 8797:: 8798 8799 <result> = extractvalue <aggregate type> <val>, <idx>{, <idx>}* 8800 8801Overview: 8802""""""""" 8803 8804The '``extractvalue``' instruction extracts the value of a member field 8805from an :ref:`aggregate <t_aggregate>` value. 8806 8807Arguments: 8808"""""""""" 8809 8810The first operand of an '``extractvalue``' instruction is a value of 8811:ref:`struct <t_struct>` or :ref:`array <t_array>` type. The other operands are 8812constant indices to specify which value to extract in a similar manner 8813as indices in a '``getelementptr``' instruction. 8814 8815The major differences to ``getelementptr`` indexing are: 8816 8817- Since the value being indexed is not a pointer, the first index is 8818 omitted and assumed to be zero. 8819- At least one index must be specified. 8820- Not only struct indices but also array indices must be in bounds. 8821 8822Semantics: 8823"""""""""" 8824 8825The result is the value at the position in the aggregate specified by 8826the index operands. 8827 8828Example: 8829"""""""" 8830 8831.. code-block:: text 8832 8833 <result> = extractvalue {i32, float} %agg, 0 ; yields i32 8834 8835.. _i_insertvalue: 8836 8837'``insertvalue``' Instruction 8838^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 8839 8840Syntax: 8841""""""" 8842 8843:: 8844 8845 <result> = insertvalue <aggregate type> <val>, <ty> <elt>, <idx>{, <idx>}* ; yields <aggregate type> 8846 8847Overview: 8848""""""""" 8849 8850The '``insertvalue``' instruction inserts a value into a member field in 8851an :ref:`aggregate <t_aggregate>` value. 8852 8853Arguments: 8854"""""""""" 8855 8856The first operand of an '``insertvalue``' instruction is a value of 8857:ref:`struct <t_struct>` or :ref:`array <t_array>` type. The second operand is 8858a first-class value to insert. The following operands are constant 8859indices indicating the position at which to insert the value in a 8860similar manner as indices in a '``extractvalue``' instruction. The value 8861to insert must have the same type as the value identified by the 8862indices. 8863 8864Semantics: 8865"""""""""" 8866 8867The result is an aggregate of the same type as ``val``. Its value is 8868that of ``val`` except that the value at the position specified by the 8869indices is that of ``elt``. 8870 8871Example: 8872"""""""" 8873 8874.. code-block:: llvm 8875 8876 %agg1 = insertvalue {i32, float} undef, i32 1, 0 ; yields {i32 1, float undef} 8877 %agg2 = insertvalue {i32, float} %agg1, float %val, 1 ; yields {i32 1, float %val} 8878 %agg3 = insertvalue {i32, {float}} undef, float %val, 1, 0 ; yields {i32 undef, {float %val}} 8879 8880.. _memoryops: 8881 8882Memory Access and Addressing Operations 8883--------------------------------------- 8884 8885A key design point of an SSA-based representation is how it represents 8886memory. In LLVM, no memory locations are in SSA form, which makes things 8887very simple. This section describes how to read, write, and allocate 8888memory in LLVM. 8889 8890.. _i_alloca: 8891 8892'``alloca``' Instruction 8893^^^^^^^^^^^^^^^^^^^^^^^^ 8894 8895Syntax: 8896""""""" 8897 8898:: 8899 8900 <result> = alloca [inalloca] <type> [, <ty> <NumElements>] [, align <alignment>] [, addrspace(<num>)] ; yields type addrspace(num)*:result 8901 8902Overview: 8903""""""""" 8904 8905The '``alloca``' instruction allocates memory on the stack frame of the 8906currently executing function, to be automatically released when this 8907function returns to its caller. The object is always allocated in the 8908address space for allocas indicated in the datalayout. 8909 8910Arguments: 8911"""""""""" 8912 8913The '``alloca``' instruction allocates ``sizeof(<type>)*NumElements`` 8914bytes of memory on the runtime stack, returning a pointer of the 8915appropriate type to the program. If "NumElements" is specified, it is 8916the number of elements allocated, otherwise "NumElements" is defaulted 8917to be one. If a constant alignment is specified, the value result of the 8918allocation is guaranteed to be aligned to at least that boundary. The 8919alignment may not be greater than ``1 << 29``. If not specified, or if 8920zero, the target can choose to align the allocation on any convenient 8921boundary compatible with the type. 8922 8923'``type``' may be any sized type. 8924 8925Semantics: 8926"""""""""" 8927 8928Memory is allocated; a pointer is returned. The allocated memory is 8929uninitialized, and loading from uninitialized memory produces an undefined 8930value. The operation itself is undefined if there is insufficient stack 8931space for the allocation.'``alloca``'d memory is automatically released 8932when the function returns. The '``alloca``' instruction is commonly used 8933to represent automatic variables that must have an address available. When 8934the function returns (either with the ``ret`` or ``resume`` instructions), 8935the memory is reclaimed. Allocating zero bytes is legal, but the returned 8936pointer may not be unique. The order in which memory is allocated (ie., 8937which way the stack grows) is not specified. 8938 8939Example: 8940"""""""" 8941 8942.. code-block:: llvm 8943 8944 %ptr = alloca i32 ; yields i32*:ptr 8945 %ptr = alloca i32, i32 4 ; yields i32*:ptr 8946 %ptr = alloca i32, i32 4, align 1024 ; yields i32*:ptr 8947 %ptr = alloca i32, align 1024 ; yields i32*:ptr 8948 8949.. _i_load: 8950 8951'``load``' Instruction 8952^^^^^^^^^^^^^^^^^^^^^^ 8953 8954Syntax: 8955""""""" 8956 8957:: 8958 8959 <result> = load [volatile] <ty>, <ty>* <pointer>[, align <alignment>][, !nontemporal !<index>][, !invariant.load !<index>][, !invariant.group !<index>][, !nonnull !<index>][, !dereferenceable !<deref_bytes_node>][, !dereferenceable_or_null !<deref_bytes_node>][, !align !<align_node>] 8960 <result> = load atomic [volatile] <ty>, <ty>* <pointer> [syncscope("<target-scope>")] <ordering>, align <alignment> [, !invariant.group !<index>] 8961 !<index> = !{ i32 1 } 8962 !<deref_bytes_node> = !{i64 <dereferenceable_bytes>} 8963 !<align_node> = !{ i64 <value_alignment> } 8964 8965Overview: 8966""""""""" 8967 8968The '``load``' instruction is used to read from memory. 8969 8970Arguments: 8971"""""""""" 8972 8973The argument to the ``load`` instruction specifies the memory address from which 8974to load. The type specified must be a :ref:`first class <t_firstclass>` type of 8975known size (i.e. not containing an :ref:`opaque structural type <t_opaque>`). If 8976the ``load`` is marked as ``volatile``, then the optimizer is not allowed to 8977modify the number or order of execution of this ``load`` with other 8978:ref:`volatile operations <volatile>`. 8979 8980If the ``load`` is marked as ``atomic``, it takes an extra :ref:`ordering 8981<ordering>` and optional ``syncscope("<target-scope>")`` argument. The 8982``release`` and ``acq_rel`` orderings are not valid on ``load`` instructions. 8983Atomic loads produce :ref:`defined <memmodel>` results when they may see 8984multiple atomic stores. The type of the pointee must be an integer, pointer, or 8985floating-point type whose bit width is a power of two greater than or equal to 8986eight and less than or equal to a target-specific size limit. ``align`` must be 8987explicitly specified on atomic loads, and the load has undefined behavior if the 8988alignment is not set to a value which is at least the size in bytes of the 8989pointee. ``!nontemporal`` does not have any defined semantics for atomic loads. 8990 8991The optional constant ``align`` argument specifies the alignment of the 8992operation (that is, the alignment of the memory address). A value of 0 8993or an omitted ``align`` argument means that the operation has the ABI 8994alignment for the target. It is the responsibility of the code emitter 8995to ensure that the alignment information is correct. Overestimating the 8996alignment results in undefined behavior. Underestimating the alignment 8997may produce less efficient code. An alignment of 1 is always safe. The 8998maximum possible alignment is ``1 << 29``. An alignment value higher 8999than the size of the loaded type implies memory up to the alignment 9000value bytes can be safely loaded without trapping in the default 9001address space. Access of the high bytes can interfere with debugging 9002tools, so should not be accessed if the function has the 9003``sanitize_thread`` or ``sanitize_address`` attributes. 9004 9005The optional ``!nontemporal`` metadata must reference a single 9006metadata name ``<index>`` corresponding to a metadata node with one 9007``i32`` entry of value 1. The existence of the ``!nontemporal`` 9008metadata on the instruction tells the optimizer and code generator 9009that this load is not expected to be reused in the cache. The code 9010generator may select special instructions to save cache bandwidth, such 9011as the ``MOVNT`` instruction on x86. 9012 9013The optional ``!invariant.load`` metadata must reference a single 9014metadata name ``<index>`` corresponding to a metadata node with no 9015entries. If a load instruction tagged with the ``!invariant.load`` 9016metadata is executed, the optimizer may assume the memory location 9017referenced by the load contains the same value at all points in the 9018program where the memory location is known to be dereferenceable; 9019otherwise, the behavior is undefined. 9020 9021The optional ``!invariant.group`` metadata must reference a single metadata name 9022 ``<index>`` corresponding to a metadata node with no entries. 9023 See ``invariant.group`` metadata :ref:`invariant.group <md_invariant.group>` 9024 9025The optional ``!nonnull`` metadata must reference a single 9026metadata name ``<index>`` corresponding to a metadata node with no 9027entries. The existence of the ``!nonnull`` metadata on the 9028instruction tells the optimizer that the value loaded is known to 9029never be null. If the value is null at runtime, the behavior is undefined. 9030This is analogous to the ``nonnull`` attribute on parameters and return 9031values. This metadata can only be applied to loads of a pointer type. 9032 9033The optional ``!dereferenceable`` metadata must reference a single metadata 9034name ``<deref_bytes_node>`` corresponding to a metadata node with one ``i64`` 9035entry. 9036See ``dereferenceable`` metadata :ref:`dereferenceable <md_dereferenceable>` 9037 9038The optional ``!dereferenceable_or_null`` metadata must reference a single 9039metadata name ``<deref_bytes_node>`` corresponding to a metadata node with one 9040``i64`` entry. 9041See ``dereferenceable_or_null`` metadata :ref:`dereferenceable_or_null 9042<md_dereferenceable_or_null>` 9043 9044The optional ``!align`` metadata must reference a single metadata name 9045``<align_node>`` corresponding to a metadata node with one ``i64`` entry. 9046The existence of the ``!align`` metadata on the instruction tells the 9047optimizer that the value loaded is known to be aligned to a boundary specified 9048by the integer value in the metadata node. The alignment must be a power of 2. 9049This is analogous to the ''align'' attribute on parameters and return values. 9050This metadata can only be applied to loads of a pointer type. If the returned 9051value is not appropriately aligned at runtime, the behavior is undefined. 9052 9053Semantics: 9054"""""""""" 9055 9056The location of memory pointed to is loaded. If the value being loaded 9057is of scalar type then the number of bytes read does not exceed the 9058minimum number of bytes needed to hold all bits of the type. For 9059example, loading an ``i24`` reads at most three bytes. When loading a 9060value of a type like ``i20`` with a size that is not an integral number 9061of bytes, the result is undefined if the value was not originally 9062written using a store of the same type. 9063 9064Examples: 9065""""""""" 9066 9067.. code-block:: llvm 9068 9069 %ptr = alloca i32 ; yields i32*:ptr 9070 store i32 3, i32* %ptr ; yields void 9071 %val = load i32, i32* %ptr ; yields i32:val = i32 3 9072 9073.. _i_store: 9074 9075'``store``' Instruction 9076^^^^^^^^^^^^^^^^^^^^^^^ 9077 9078Syntax: 9079""""""" 9080 9081:: 9082 9083 store [volatile] <ty> <value>, <ty>* <pointer>[, align <alignment>][, !nontemporal !<index>][, !invariant.group !<index>] ; yields void 9084 store atomic [volatile] <ty> <value>, <ty>* <pointer> [syncscope("<target-scope>")] <ordering>, align <alignment> [, !invariant.group !<index>] ; yields void 9085 9086Overview: 9087""""""""" 9088 9089The '``store``' instruction is used to write to memory. 9090 9091Arguments: 9092"""""""""" 9093 9094There are two arguments to the ``store`` instruction: a value to store and an 9095address at which to store it. The type of the ``<pointer>`` operand must be a 9096pointer to the :ref:`first class <t_firstclass>` type of the ``<value>`` 9097operand. If the ``store`` is marked as ``volatile``, then the optimizer is not 9098allowed to modify the number or order of execution of this ``store`` with other 9099:ref:`volatile operations <volatile>`. Only values of :ref:`first class 9100<t_firstclass>` types of known size (i.e. not containing an :ref:`opaque 9101structural type <t_opaque>`) can be stored. 9102 9103If the ``store`` is marked as ``atomic``, it takes an extra :ref:`ordering 9104<ordering>` and optional ``syncscope("<target-scope>")`` argument. The 9105``acquire`` and ``acq_rel`` orderings aren't valid on ``store`` instructions. 9106Atomic loads produce :ref:`defined <memmodel>` results when they may see 9107multiple atomic stores. The type of the pointee must be an integer, pointer, or 9108floating-point type whose bit width is a power of two greater than or equal to 9109eight and less than or equal to a target-specific size limit. ``align`` must be 9110explicitly specified on atomic stores, and the store has undefined behavior if 9111the alignment is not set to a value which is at least the size in bytes of the 9112pointee. ``!nontemporal`` does not have any defined semantics for atomic stores. 9113 9114The optional constant ``align`` argument specifies the alignment of the 9115operation (that is, the alignment of the memory address). A value of 0 9116or an omitted ``align`` argument means that the operation has the ABI 9117alignment for the target. It is the responsibility of the code emitter 9118to ensure that the alignment information is correct. Overestimating the 9119alignment results in undefined behavior. Underestimating the 9120alignment may produce less efficient code. An alignment of 1 is always 9121safe. The maximum possible alignment is ``1 << 29``. An alignment 9122value higher than the size of the stored type implies memory up to the 9123alignment value bytes can be stored to without trapping in the default 9124address space. Storing to the higher bytes however may result in data 9125races if another thread can access the same address. Introducing a 9126data race is not allowed. Storing to the extra bytes is not allowed 9127even in situations where a data race is known to not exist if the 9128function has the ``sanitize_address`` attribute. 9129 9130The optional ``!nontemporal`` metadata must reference a single metadata 9131name ``<index>`` corresponding to a metadata node with one ``i32`` entry of 9132value 1. The existence of the ``!nontemporal`` metadata on the instruction 9133tells the optimizer and code generator that this load is not expected to 9134be reused in the cache. The code generator may select special 9135instructions to save cache bandwidth, such as the ``MOVNT`` instruction on 9136x86. 9137 9138The optional ``!invariant.group`` metadata must reference a 9139single metadata name ``<index>``. See ``invariant.group`` metadata. 9140 9141Semantics: 9142"""""""""" 9143 9144The contents of memory are updated to contain ``<value>`` at the 9145location specified by the ``<pointer>`` operand. If ``<value>`` is 9146of scalar type then the number of bytes written does not exceed the 9147minimum number of bytes needed to hold all bits of the type. For 9148example, storing an ``i24`` writes at most three bytes. When writing a 9149value of a type like ``i20`` with a size that is not an integral number 9150of bytes, it is unspecified what happens to the extra bits that do not 9151belong to the type, but they will typically be overwritten. 9152 9153Example: 9154"""""""" 9155 9156.. code-block:: llvm 9157 9158 %ptr = alloca i32 ; yields i32*:ptr 9159 store i32 3, i32* %ptr ; yields void 9160 %val = load i32, i32* %ptr ; yields i32:val = i32 3 9161 9162.. _i_fence: 9163 9164'``fence``' Instruction 9165^^^^^^^^^^^^^^^^^^^^^^^ 9166 9167Syntax: 9168""""""" 9169 9170:: 9171 9172 fence [syncscope("<target-scope>")] <ordering> ; yields void 9173 9174Overview: 9175""""""""" 9176 9177The '``fence``' instruction is used to introduce happens-before edges 9178between operations. 9179 9180Arguments: 9181"""""""""" 9182 9183'``fence``' instructions take an :ref:`ordering <ordering>` argument which 9184defines what *synchronizes-with* edges they add. They can only be given 9185``acquire``, ``release``, ``acq_rel``, and ``seq_cst`` orderings. 9186 9187Semantics: 9188"""""""""" 9189 9190A fence A which has (at least) ``release`` ordering semantics 9191*synchronizes with* a fence B with (at least) ``acquire`` ordering 9192semantics if and only if there exist atomic operations X and Y, both 9193operating on some atomic object M, such that A is sequenced before X, X 9194modifies M (either directly or through some side effect of a sequence 9195headed by X), Y is sequenced before B, and Y observes M. This provides a 9196*happens-before* dependency between A and B. Rather than an explicit 9197``fence``, one (but not both) of the atomic operations X or Y might 9198provide a ``release`` or ``acquire`` (resp.) ordering constraint and 9199still *synchronize-with* the explicit ``fence`` and establish the 9200*happens-before* edge. 9201 9202A ``fence`` which has ``seq_cst`` ordering, in addition to having both 9203``acquire`` and ``release`` semantics specified above, participates in 9204the global program order of other ``seq_cst`` operations and/or fences. 9205 9206A ``fence`` instruction can also take an optional 9207":ref:`syncscope <syncscope>`" argument. 9208 9209Example: 9210"""""""" 9211 9212.. code-block:: text 9213 9214 fence acquire ; yields void 9215 fence syncscope("singlethread") seq_cst ; yields void 9216 fence syncscope("agent") seq_cst ; yields void 9217 9218.. _i_cmpxchg: 9219 9220'``cmpxchg``' Instruction 9221^^^^^^^^^^^^^^^^^^^^^^^^^ 9222 9223Syntax: 9224""""""" 9225 9226:: 9227 9228 cmpxchg [weak] [volatile] <ty>* <pointer>, <ty> <cmp>, <ty> <new> [syncscope("<target-scope>")] <success ordering> <failure ordering> ; yields { ty, i1 } 9229 9230Overview: 9231""""""""" 9232 9233The '``cmpxchg``' instruction is used to atomically modify memory. It 9234loads a value in memory and compares it to a given value. If they are 9235equal, it tries to store a new value into the memory. 9236 9237Arguments: 9238"""""""""" 9239 9240There are three arguments to the '``cmpxchg``' instruction: an address 9241to operate on, a value to compare to the value currently be at that 9242address, and a new value to place at that address if the compared values 9243are equal. The type of '<cmp>' must be an integer or pointer type whose 9244bit width is a power of two greater than or equal to eight and less 9245than or equal to a target-specific size limit. '<cmp>' and '<new>' must 9246have the same type, and the type of '<pointer>' must be a pointer to 9247that type. If the ``cmpxchg`` is marked as ``volatile``, then the 9248optimizer is not allowed to modify the number or order of execution of 9249this ``cmpxchg`` with other :ref:`volatile operations <volatile>`. 9250 9251The success and failure :ref:`ordering <ordering>` arguments specify how this 9252``cmpxchg`` synchronizes with other atomic operations. Both ordering parameters 9253must be at least ``monotonic``, the ordering constraint on failure must be no 9254stronger than that on success, and the failure ordering cannot be either 9255``release`` or ``acq_rel``. 9256 9257A ``cmpxchg`` instruction can also take an optional 9258":ref:`syncscope <syncscope>`" argument. 9259 9260The pointer passed into cmpxchg must have alignment greater than or 9261equal to the size in memory of the operand. 9262 9263Semantics: 9264"""""""""" 9265 9266The contents of memory at the location specified by the '``<pointer>``' operand 9267is read and compared to '``<cmp>``'; if the values are equal, '``<new>``' is 9268written to the location. The original value at the location is returned, 9269together with a flag indicating success (true) or failure (false). 9270 9271If the cmpxchg operation is marked as ``weak`` then a spurious failure is 9272permitted: the operation may not write ``<new>`` even if the comparison 9273matched. 9274 9275If the cmpxchg operation is strong (the default), the i1 value is 1 if and only 9276if the value loaded equals ``cmp``. 9277 9278A successful ``cmpxchg`` is a read-modify-write instruction for the purpose of 9279identifying release sequences. A failed ``cmpxchg`` is equivalent to an atomic 9280load with an ordering parameter determined the second ordering parameter. 9281 9282Example: 9283"""""""" 9284 9285.. code-block:: llvm 9286 9287 entry: 9288 %orig = load atomic i32, i32* %ptr unordered, align 4 ; yields i32 9289 br label %loop 9290 9291 loop: 9292 %cmp = phi i32 [ %orig, %entry ], [%value_loaded, %loop] 9293 %squared = mul i32 %cmp, %cmp 9294 %val_success = cmpxchg i32* %ptr, i32 %cmp, i32 %squared acq_rel monotonic ; yields { i32, i1 } 9295 %value_loaded = extractvalue { i32, i1 } %val_success, 0 9296 %success = extractvalue { i32, i1 } %val_success, 1 9297 br i1 %success, label %done, label %loop 9298 9299 done: 9300 ... 9301 9302.. _i_atomicrmw: 9303 9304'``atomicrmw``' Instruction 9305^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9306 9307Syntax: 9308""""""" 9309 9310:: 9311 9312 atomicrmw [volatile] <operation> <ty>* <pointer>, <ty> <value> [syncscope("<target-scope>")] <ordering> ; yields ty 9313 9314Overview: 9315""""""""" 9316 9317The '``atomicrmw``' instruction is used to atomically modify memory. 9318 9319Arguments: 9320"""""""""" 9321 9322There are three arguments to the '``atomicrmw``' instruction: an 9323operation to apply, an address whose value to modify, an argument to the 9324operation. The operation must be one of the following keywords: 9325 9326- xchg 9327- add 9328- sub 9329- and 9330- nand 9331- or 9332- xor 9333- max 9334- min 9335- umax 9336- umin 9337- fadd 9338- fsub 9339 9340For most of these operations, the type of '<value>' must be an integer 9341type whose bit width is a power of two greater than or equal to eight 9342and less than or equal to a target-specific size limit. For xchg, this 9343may also be a floating point type with the same size constraints as 9344integers. For fadd/fsub, this must be a floating point type. The 9345type of the '``<pointer>``' operand must be a pointer to that type. If 9346the ``atomicrmw`` is marked as ``volatile``, then the optimizer is not 9347allowed to modify the number or order of execution of this 9348``atomicrmw`` with other :ref:`volatile operations <volatile>`. 9349 9350A ``atomicrmw`` instruction can also take an optional 9351":ref:`syncscope <syncscope>`" argument. 9352 9353Semantics: 9354"""""""""" 9355 9356The contents of memory at the location specified by the '``<pointer>``' 9357operand are atomically read, modified, and written back. The original 9358value at the location is returned. The modification is specified by the 9359operation argument: 9360 9361- xchg: ``*ptr = val`` 9362- add: ``*ptr = *ptr + val`` 9363- sub: ``*ptr = *ptr - val`` 9364- and: ``*ptr = *ptr & val`` 9365- nand: ``*ptr = ~(*ptr & val)`` 9366- or: ``*ptr = *ptr | val`` 9367- xor: ``*ptr = *ptr ^ val`` 9368- max: ``*ptr = *ptr > val ? *ptr : val`` (using a signed comparison) 9369- min: ``*ptr = *ptr < val ? *ptr : val`` (using a signed comparison) 9370- umax: ``*ptr = *ptr > val ? *ptr : val`` (using an unsigned 9371 comparison) 9372- umin: ``*ptr = *ptr < val ? *ptr : val`` (using an unsigned 9373 comparison) 9374- fadd: ``*ptr = *ptr + val`` (using floating point arithmetic) 9375- fsub: ``*ptr = *ptr - val`` (using floating point arithmetic) 9376 9377Example: 9378"""""""" 9379 9380.. code-block:: llvm 9381 9382 %old = atomicrmw add i32* %ptr, i32 1 acquire ; yields i32 9383 9384.. _i_getelementptr: 9385 9386'``getelementptr``' Instruction 9387^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9388 9389Syntax: 9390""""""" 9391 9392:: 9393 9394 <result> = getelementptr <ty>, <ty>* <ptrval>{, [inrange] <ty> <idx>}* 9395 <result> = getelementptr inbounds <ty>, <ty>* <ptrval>{, [inrange] <ty> <idx>}* 9396 <result> = getelementptr <ty>, <ptr vector> <ptrval>, [inrange] <vector index type> <idx> 9397 9398Overview: 9399""""""""" 9400 9401The '``getelementptr``' instruction is used to get the address of a 9402subelement of an :ref:`aggregate <t_aggregate>` data structure. It performs 9403address calculation only and does not access memory. The instruction can also 9404be used to calculate a vector of such addresses. 9405 9406Arguments: 9407"""""""""" 9408 9409The first argument is always a type used as the basis for the calculations. 9410The second argument is always a pointer or a vector of pointers, and is the 9411base address to start from. The remaining arguments are indices 9412that indicate which of the elements of the aggregate object are indexed. 9413The interpretation of each index is dependent on the type being indexed 9414into. The first index always indexes the pointer value given as the 9415second argument, the second index indexes a value of the type pointed to 9416(not necessarily the value directly pointed to, since the first index 9417can be non-zero), etc. The first type indexed into must be a pointer 9418value, subsequent types can be arrays, vectors, and structs. Note that 9419subsequent types being indexed into can never be pointers, since that 9420would require loading the pointer before continuing calculation. 9421 9422The type of each index argument depends on the type it is indexing into. 9423When indexing into a (optionally packed) structure, only ``i32`` integer 9424**constants** are allowed (when using a vector of indices they must all 9425be the **same** ``i32`` integer constant). When indexing into an array, 9426pointer or vector, integers of any width are allowed, and they are not 9427required to be constant. These integers are treated as signed values 9428where relevant. 9429 9430For example, let's consider a C code fragment and how it gets compiled 9431to LLVM: 9432 9433.. code-block:: c 9434 9435 struct RT { 9436 char A; 9437 int B[10][20]; 9438 char C; 9439 }; 9440 struct ST { 9441 int X; 9442 double Y; 9443 struct RT Z; 9444 }; 9445 9446 int *foo(struct ST *s) { 9447 return &s[1].Z.B[5][13]; 9448 } 9449 9450The LLVM code generated by Clang is: 9451 9452.. code-block:: llvm 9453 9454 %struct.RT = type { i8, [10 x [20 x i32]], i8 } 9455 %struct.ST = type { i32, double, %struct.RT } 9456 9457 define i32* @foo(%struct.ST* %s) nounwind uwtable readnone optsize ssp { 9458 entry: 9459 %arrayidx = getelementptr inbounds %struct.ST, %struct.ST* %s, i64 1, i32 2, i32 1, i64 5, i64 13 9460 ret i32* %arrayidx 9461 } 9462 9463Semantics: 9464"""""""""" 9465 9466In the example above, the first index is indexing into the 9467'``%struct.ST*``' type, which is a pointer, yielding a '``%struct.ST``' 9468= '``{ i32, double, %struct.RT }``' type, a structure. The second index 9469indexes into the third element of the structure, yielding a 9470'``%struct.RT``' = '``{ i8 , [10 x [20 x i32]], i8 }``' type, another 9471structure. The third index indexes into the second element of the 9472structure, yielding a '``[10 x [20 x i32]]``' type, an array. The two 9473dimensions of the array are subscripted into, yielding an '``i32``' 9474type. The '``getelementptr``' instruction returns a pointer to this 9475element, thus computing a value of '``i32*``' type. 9476 9477Note that it is perfectly legal to index partially through a structure, 9478returning a pointer to an inner element. Because of this, the LLVM code 9479for the given testcase is equivalent to: 9480 9481.. code-block:: llvm 9482 9483 define i32* @foo(%struct.ST* %s) { 9484 %t1 = getelementptr %struct.ST, %struct.ST* %s, i32 1 ; yields %struct.ST*:%t1 9485 %t2 = getelementptr %struct.ST, %struct.ST* %t1, i32 0, i32 2 ; yields %struct.RT*:%t2 9486 %t3 = getelementptr %struct.RT, %struct.RT* %t2, i32 0, i32 1 ; yields [10 x [20 x i32]]*:%t3 9487 %t4 = getelementptr [10 x [20 x i32]], [10 x [20 x i32]]* %t3, i32 0, i32 5 ; yields [20 x i32]*:%t4 9488 %t5 = getelementptr [20 x i32], [20 x i32]* %t4, i32 0, i32 13 ; yields i32*:%t5 9489 ret i32* %t5 9490 } 9491 9492If the ``inbounds`` keyword is present, the result value of the 9493``getelementptr`` is a :ref:`poison value <poisonvalues>` if the base 9494pointer is not an *in bounds* address of an allocated object, or if any 9495of the addresses that would be formed by successive addition of the 9496offsets implied by the indices to the base address with infinitely 9497precise signed arithmetic are not an *in bounds* address of that 9498allocated object. The *in bounds* addresses for an allocated object are 9499all the addresses that point into the object, plus the address one byte 9500past the end. The only *in bounds* address for a null pointer in the 9501default address-space is the null pointer itself. In cases where the 9502base is a vector of pointers the ``inbounds`` keyword applies to each 9503of the computations element-wise. 9504 9505If the ``inbounds`` keyword is not present, the offsets are added to the 9506base address with silently-wrapping two's complement arithmetic. If the 9507offsets have a different width from the pointer, they are sign-extended 9508or truncated to the width of the pointer. The result value of the 9509``getelementptr`` may be outside the object pointed to by the base 9510pointer. The result value may not necessarily be used to access memory 9511though, even if it happens to point into allocated storage. See the 9512:ref:`Pointer Aliasing Rules <pointeraliasing>` section for more 9513information. 9514 9515If the ``inrange`` keyword is present before any index, loading from or 9516storing to any pointer derived from the ``getelementptr`` has undefined 9517behavior if the load or store would access memory outside of the bounds of 9518the element selected by the index marked as ``inrange``. The result of a 9519pointer comparison or ``ptrtoint`` (including ``ptrtoint``-like operations 9520involving memory) involving a pointer derived from a ``getelementptr`` with 9521the ``inrange`` keyword is undefined, with the exception of comparisons 9522in the case where both operands are in the range of the element selected 9523by the ``inrange`` keyword, inclusive of the address one past the end of 9524that element. Note that the ``inrange`` keyword is currently only allowed 9525in constant ``getelementptr`` expressions. 9526 9527The getelementptr instruction is often confusing. For some more insight 9528into how it works, see :doc:`the getelementptr FAQ <GetElementPtr>`. 9529 9530Example: 9531"""""""" 9532 9533.. code-block:: llvm 9534 9535 ; yields [12 x i8]*:aptr 9536 %aptr = getelementptr {i32, [12 x i8]}, {i32, [12 x i8]}* %saptr, i64 0, i32 1 9537 ; yields i8*:vptr 9538 %vptr = getelementptr {i32, <2 x i8>}, {i32, <2 x i8>}* %svptr, i64 0, i32 1, i32 1 9539 ; yields i8*:eptr 9540 %eptr = getelementptr [12 x i8], [12 x i8]* %aptr, i64 0, i32 1 9541 ; yields i32*:iptr 9542 %iptr = getelementptr [10 x i32], [10 x i32]* @arr, i16 0, i16 0 9543 9544Vector of pointers: 9545""""""""""""""""""" 9546 9547The ``getelementptr`` returns a vector of pointers, instead of a single address, 9548when one or more of its arguments is a vector. In such cases, all vector 9549arguments should have the same number of elements, and every scalar argument 9550will be effectively broadcast into a vector during address calculation. 9551 9552.. code-block:: llvm 9553 9554 ; All arguments are vectors: 9555 ; A[i] = ptrs[i] + offsets[i]*sizeof(i8) 9556 %A = getelementptr i8, <4 x i8*> %ptrs, <4 x i64> %offsets 9557 9558 ; Add the same scalar offset to each pointer of a vector: 9559 ; A[i] = ptrs[i] + offset*sizeof(i8) 9560 %A = getelementptr i8, <4 x i8*> %ptrs, i64 %offset 9561 9562 ; Add distinct offsets to the same pointer: 9563 ; A[i] = ptr + offsets[i]*sizeof(i8) 9564 %A = getelementptr i8, i8* %ptr, <4 x i64> %offsets 9565 9566 ; In all cases described above the type of the result is <4 x i8*> 9567 9568The two following instructions are equivalent: 9569 9570.. code-block:: llvm 9571 9572 getelementptr %struct.ST, <4 x %struct.ST*> %s, <4 x i64> %ind1, 9573 <4 x i32> <i32 2, i32 2, i32 2, i32 2>, 9574 <4 x i32> <i32 1, i32 1, i32 1, i32 1>, 9575 <4 x i32> %ind4, 9576 <4 x i64> <i64 13, i64 13, i64 13, i64 13> 9577 9578 getelementptr %struct.ST, <4 x %struct.ST*> %s, <4 x i64> %ind1, 9579 i32 2, i32 1, <4 x i32> %ind4, i64 13 9580 9581Let's look at the C code, where the vector version of ``getelementptr`` 9582makes sense: 9583 9584.. code-block:: c 9585 9586 // Let's assume that we vectorize the following loop: 9587 double *A, *B; int *C; 9588 for (int i = 0; i < size; ++i) { 9589 A[i] = B[C[i]]; 9590 } 9591 9592.. code-block:: llvm 9593 9594 ; get pointers for 8 elements from array B 9595 %ptrs = getelementptr double, double* %B, <8 x i32> %C 9596 ; load 8 elements from array B into A 9597 %A = call <8 x double> @llvm.masked.gather.v8f64.v8p0f64(<8 x double*> %ptrs, 9598 i32 8, <8 x i1> %mask, <8 x double> %passthru) 9599 9600Conversion Operations 9601--------------------- 9602 9603The instructions in this category are the conversion instructions 9604(casting) which all take a single operand and a type. They perform 9605various bit conversions on the operand. 9606 9607.. _i_trunc: 9608 9609'``trunc .. to``' Instruction 9610^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9611 9612Syntax: 9613""""""" 9614 9615:: 9616 9617 <result> = trunc <ty> <value> to <ty2> ; yields ty2 9618 9619Overview: 9620""""""""" 9621 9622The '``trunc``' instruction truncates its operand to the type ``ty2``. 9623 9624Arguments: 9625"""""""""" 9626 9627The '``trunc``' instruction takes a value to trunc, and a type to trunc 9628it to. Both types must be of :ref:`integer <t_integer>` types, or vectors 9629of the same number of integers. The bit size of the ``value`` must be 9630larger than the bit size of the destination type, ``ty2``. Equal sized 9631types are not allowed. 9632 9633Semantics: 9634"""""""""" 9635 9636The '``trunc``' instruction truncates the high order bits in ``value`` 9637and converts the remaining bits to ``ty2``. Since the source size must 9638be larger than the destination size, ``trunc`` cannot be a *no-op cast*. 9639It will always truncate bits. 9640 9641Example: 9642"""""""" 9643 9644.. code-block:: llvm 9645 9646 %X = trunc i32 257 to i8 ; yields i8:1 9647 %Y = trunc i32 123 to i1 ; yields i1:true 9648 %Z = trunc i32 122 to i1 ; yields i1:false 9649 %W = trunc <2 x i16> <i16 8, i16 7> to <2 x i8> ; yields <i8 8, i8 7> 9650 9651.. _i_zext: 9652 9653'``zext .. to``' Instruction 9654^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9655 9656Syntax: 9657""""""" 9658 9659:: 9660 9661 <result> = zext <ty> <value> to <ty2> ; yields ty2 9662 9663Overview: 9664""""""""" 9665 9666The '``zext``' instruction zero extends its operand to type ``ty2``. 9667 9668Arguments: 9669"""""""""" 9670 9671The '``zext``' instruction takes a value to cast, and a type to cast it 9672to. Both types must be of :ref:`integer <t_integer>` types, or vectors of 9673the same number of integers. The bit size of the ``value`` must be 9674smaller than the bit size of the destination type, ``ty2``. 9675 9676Semantics: 9677"""""""""" 9678 9679The ``zext`` fills the high order bits of the ``value`` with zero bits 9680until it reaches the size of the destination type, ``ty2``. 9681 9682When zero extending from i1, the result will always be either 0 or 1. 9683 9684Example: 9685"""""""" 9686 9687.. code-block:: llvm 9688 9689 %X = zext i32 257 to i64 ; yields i64:257 9690 %Y = zext i1 true to i32 ; yields i32:1 9691 %Z = zext <2 x i16> <i16 8, i16 7> to <2 x i32> ; yields <i32 8, i32 7> 9692 9693.. _i_sext: 9694 9695'``sext .. to``' Instruction 9696^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9697 9698Syntax: 9699""""""" 9700 9701:: 9702 9703 <result> = sext <ty> <value> to <ty2> ; yields ty2 9704 9705Overview: 9706""""""""" 9707 9708The '``sext``' sign extends ``value`` to the type ``ty2``. 9709 9710Arguments: 9711"""""""""" 9712 9713The '``sext``' instruction takes a value to cast, and a type to cast it 9714to. Both types must be of :ref:`integer <t_integer>` types, or vectors of 9715the same number of integers. The bit size of the ``value`` must be 9716smaller than the bit size of the destination type, ``ty2``. 9717 9718Semantics: 9719"""""""""" 9720 9721The '``sext``' instruction performs a sign extension by copying the sign 9722bit (highest order bit) of the ``value`` until it reaches the bit size 9723of the type ``ty2``. 9724 9725When sign extending from i1, the extension always results in -1 or 0. 9726 9727Example: 9728"""""""" 9729 9730.. code-block:: llvm 9731 9732 %X = sext i8 -1 to i16 ; yields i16 :65535 9733 %Y = sext i1 true to i32 ; yields i32:-1 9734 %Z = sext <2 x i16> <i16 8, i16 7> to <2 x i32> ; yields <i32 8, i32 7> 9735 9736'``fptrunc .. to``' Instruction 9737^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9738 9739Syntax: 9740""""""" 9741 9742:: 9743 9744 <result> = fptrunc <ty> <value> to <ty2> ; yields ty2 9745 9746Overview: 9747""""""""" 9748 9749The '``fptrunc``' instruction truncates ``value`` to type ``ty2``. 9750 9751Arguments: 9752"""""""""" 9753 9754The '``fptrunc``' instruction takes a :ref:`floating-point <t_floating>` 9755value to cast and a :ref:`floating-point <t_floating>` type to cast it to. 9756The size of ``value`` must be larger than the size of ``ty2``. This 9757implies that ``fptrunc`` cannot be used to make a *no-op cast*. 9758 9759Semantics: 9760"""""""""" 9761 9762The '``fptrunc``' instruction casts a ``value`` from a larger 9763:ref:`floating-point <t_floating>` type to a smaller :ref:`floating-point 9764<t_floating>` type. 9765This instruction is assumed to execute in the default :ref:`floating-point 9766environment <floatenv>`. 9767 9768Example: 9769"""""""" 9770 9771.. code-block:: llvm 9772 9773 %X = fptrunc double 16777217.0 to float ; yields float:16777216.0 9774 %Y = fptrunc double 1.0E+300 to half ; yields half:+infinity 9775 9776'``fpext .. to``' Instruction 9777^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9778 9779Syntax: 9780""""""" 9781 9782:: 9783 9784 <result> = fpext <ty> <value> to <ty2> ; yields ty2 9785 9786Overview: 9787""""""""" 9788 9789The '``fpext``' extends a floating-point ``value`` to a larger floating-point 9790value. 9791 9792Arguments: 9793"""""""""" 9794 9795The '``fpext``' instruction takes a :ref:`floating-point <t_floating>` 9796``value`` to cast, and a :ref:`floating-point <t_floating>` type to cast it 9797to. The source type must be smaller than the destination type. 9798 9799Semantics: 9800"""""""""" 9801 9802The '``fpext``' instruction extends the ``value`` from a smaller 9803:ref:`floating-point <t_floating>` type to a larger :ref:`floating-point 9804<t_floating>` type. The ``fpext`` cannot be used to make a 9805*no-op cast* because it always changes bits. Use ``bitcast`` to make a 9806*no-op cast* for a floating-point cast. 9807 9808Example: 9809"""""""" 9810 9811.. code-block:: llvm 9812 9813 %X = fpext float 3.125 to double ; yields double:3.125000e+00 9814 %Y = fpext double %X to fp128 ; yields fp128:0xL00000000000000004000900000000000 9815 9816'``fptoui .. to``' Instruction 9817^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9818 9819Syntax: 9820""""""" 9821 9822:: 9823 9824 <result> = fptoui <ty> <value> to <ty2> ; yields ty2 9825 9826Overview: 9827""""""""" 9828 9829The '``fptoui``' converts a floating-point ``value`` to its unsigned 9830integer equivalent of type ``ty2``. 9831 9832Arguments: 9833"""""""""" 9834 9835The '``fptoui``' instruction takes a value to cast, which must be a 9836scalar or vector :ref:`floating-point <t_floating>` value, and a type to 9837cast it to ``ty2``, which must be an :ref:`integer <t_integer>` type. If 9838``ty`` is a vector floating-point type, ``ty2`` must be a vector integer 9839type with the same number of elements as ``ty`` 9840 9841Semantics: 9842"""""""""" 9843 9844The '``fptoui``' instruction converts its :ref:`floating-point 9845<t_floating>` operand into the nearest (rounding towards zero) 9846unsigned integer value. If the value cannot fit in ``ty2``, the result 9847is a :ref:`poison value <poisonvalues>`. 9848 9849Example: 9850"""""""" 9851 9852.. code-block:: llvm 9853 9854 %X = fptoui double 123.0 to i32 ; yields i32:123 9855 %Y = fptoui float 1.0E+300 to i1 ; yields undefined:1 9856 %Z = fptoui float 1.04E+17 to i8 ; yields undefined:1 9857 9858'``fptosi .. to``' Instruction 9859^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9860 9861Syntax: 9862""""""" 9863 9864:: 9865 9866 <result> = fptosi <ty> <value> to <ty2> ; yields ty2 9867 9868Overview: 9869""""""""" 9870 9871The '``fptosi``' instruction converts :ref:`floating-point <t_floating>` 9872``value`` to type ``ty2``. 9873 9874Arguments: 9875"""""""""" 9876 9877The '``fptosi``' instruction takes a value to cast, which must be a 9878scalar or vector :ref:`floating-point <t_floating>` value, and a type to 9879cast it to ``ty2``, which must be an :ref:`integer <t_integer>` type. If 9880``ty`` is a vector floating-point type, ``ty2`` must be a vector integer 9881type with the same number of elements as ``ty`` 9882 9883Semantics: 9884"""""""""" 9885 9886The '``fptosi``' instruction converts its :ref:`floating-point 9887<t_floating>` operand into the nearest (rounding towards zero) 9888signed integer value. If the value cannot fit in ``ty2``, the result 9889is a :ref:`poison value <poisonvalues>`. 9890 9891Example: 9892"""""""" 9893 9894.. code-block:: llvm 9895 9896 %X = fptosi double -123.0 to i32 ; yields i32:-123 9897 %Y = fptosi float 1.0E-247 to i1 ; yields undefined:1 9898 %Z = fptosi float 1.04E+17 to i8 ; yields undefined:1 9899 9900'``uitofp .. to``' Instruction 9901^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9902 9903Syntax: 9904""""""" 9905 9906:: 9907 9908 <result> = uitofp <ty> <value> to <ty2> ; yields ty2 9909 9910Overview: 9911""""""""" 9912 9913The '``uitofp``' instruction regards ``value`` as an unsigned integer 9914and converts that value to the ``ty2`` type. 9915 9916Arguments: 9917"""""""""" 9918 9919The '``uitofp``' instruction takes a value to cast, which must be a 9920scalar or vector :ref:`integer <t_integer>` value, and a type to cast it to 9921``ty2``, which must be an :ref:`floating-point <t_floating>` type. If 9922``ty`` is a vector integer type, ``ty2`` must be a vector floating-point 9923type with the same number of elements as ``ty`` 9924 9925Semantics: 9926"""""""""" 9927 9928The '``uitofp``' instruction interprets its operand as an unsigned 9929integer quantity and converts it to the corresponding floating-point 9930value. If the value cannot be exactly represented, it is rounded using 9931the default rounding mode. 9932 9933 9934Example: 9935"""""""" 9936 9937.. code-block:: llvm 9938 9939 %X = uitofp i32 257 to float ; yields float:257.0 9940 %Y = uitofp i8 -1 to double ; yields double:255.0 9941 9942'``sitofp .. to``' Instruction 9943^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9944 9945Syntax: 9946""""""" 9947 9948:: 9949 9950 <result> = sitofp <ty> <value> to <ty2> ; yields ty2 9951 9952Overview: 9953""""""""" 9954 9955The '``sitofp``' instruction regards ``value`` as a signed integer and 9956converts that value to the ``ty2`` type. 9957 9958Arguments: 9959"""""""""" 9960 9961The '``sitofp``' instruction takes a value to cast, which must be a 9962scalar or vector :ref:`integer <t_integer>` value, and a type to cast it to 9963``ty2``, which must be an :ref:`floating-point <t_floating>` type. If 9964``ty`` is a vector integer type, ``ty2`` must be a vector floating-point 9965type with the same number of elements as ``ty`` 9966 9967Semantics: 9968"""""""""" 9969 9970The '``sitofp``' instruction interprets its operand as a signed integer 9971quantity and converts it to the corresponding floating-point value. If the 9972value cannot be exactly represented, it is rounded using the default rounding 9973mode. 9974 9975Example: 9976"""""""" 9977 9978.. code-block:: llvm 9979 9980 %X = sitofp i32 257 to float ; yields float:257.0 9981 %Y = sitofp i8 -1 to double ; yields double:-1.0 9982 9983.. _i_ptrtoint: 9984 9985'``ptrtoint .. to``' Instruction 9986^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9987 9988Syntax: 9989""""""" 9990 9991:: 9992 9993 <result> = ptrtoint <ty> <value> to <ty2> ; yields ty2 9994 9995Overview: 9996""""""""" 9997 9998The '``ptrtoint``' instruction converts the pointer or a vector of 9999pointers ``value`` to the integer (or vector of integers) type ``ty2``. 10000 10001Arguments: 10002"""""""""" 10003 10004The '``ptrtoint``' instruction takes a ``value`` to cast, which must be 10005a value of type :ref:`pointer <t_pointer>` or a vector of pointers, and a 10006type to cast it to ``ty2``, which must be an :ref:`integer <t_integer>` or 10007a vector of integers type. 10008 10009Semantics: 10010"""""""""" 10011 10012The '``ptrtoint``' instruction converts ``value`` to integer type 10013``ty2`` by interpreting the pointer value as an integer and either 10014truncating or zero extending that value to the size of the integer type. 10015If ``value`` is smaller than ``ty2`` then a zero extension is done. If 10016``value`` is larger than ``ty2`` then a truncation is done. If they are 10017the same size, then nothing is done (*no-op cast*) other than a type 10018change. 10019 10020Example: 10021"""""""" 10022 10023.. code-block:: llvm 10024 10025 %X = ptrtoint i32* %P to i8 ; yields truncation on 32-bit architecture 10026 %Y = ptrtoint i32* %P to i64 ; yields zero extension on 32-bit architecture 10027 %Z = ptrtoint <4 x i32*> %P to <4 x i64>; yields vector zero extension for a vector of addresses on 32-bit architecture 10028 10029.. _i_inttoptr: 10030 10031'``inttoptr .. to``' Instruction 10032^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10033 10034Syntax: 10035""""""" 10036 10037:: 10038 10039 <result> = inttoptr <ty> <value> to <ty2>[, !dereferenceable !<deref_bytes_node>][, !dereferenceable_or_null !<deref_bytes_node] ; yields ty2 10040 10041Overview: 10042""""""""" 10043 10044The '``inttoptr``' instruction converts an integer ``value`` to a 10045pointer type, ``ty2``. 10046 10047Arguments: 10048"""""""""" 10049 10050The '``inttoptr``' instruction takes an :ref:`integer <t_integer>` value to 10051cast, and a type to cast it to, which must be a :ref:`pointer <t_pointer>` 10052type. 10053 10054The optional ``!dereferenceable`` metadata must reference a single metadata 10055name ``<deref_bytes_node>`` corresponding to a metadata node with one ``i64`` 10056entry. 10057See ``dereferenceable`` metadata. 10058 10059The optional ``!dereferenceable_or_null`` metadata must reference a single 10060metadata name ``<deref_bytes_node>`` corresponding to a metadata node with one 10061``i64`` entry. 10062See ``dereferenceable_or_null`` metadata. 10063 10064Semantics: 10065"""""""""" 10066 10067The '``inttoptr``' instruction converts ``value`` to type ``ty2`` by 10068applying either a zero extension or a truncation depending on the size 10069of the integer ``value``. If ``value`` is larger than the size of a 10070pointer then a truncation is done. If ``value`` is smaller than the size 10071of a pointer then a zero extension is done. If they are the same size, 10072nothing is done (*no-op cast*). 10073 10074Example: 10075"""""""" 10076 10077.. code-block:: llvm 10078 10079 %X = inttoptr i32 255 to i32* ; yields zero extension on 64-bit architecture 10080 %Y = inttoptr i32 255 to i32* ; yields no-op on 32-bit architecture 10081 %Z = inttoptr i64 0 to i32* ; yields truncation on 32-bit architecture 10082 %Z = inttoptr <4 x i32> %G to <4 x i8*>; yields truncation of vector G to four pointers 10083 10084.. _i_bitcast: 10085 10086'``bitcast .. to``' Instruction 10087^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10088 10089Syntax: 10090""""""" 10091 10092:: 10093 10094 <result> = bitcast <ty> <value> to <ty2> ; yields ty2 10095 10096Overview: 10097""""""""" 10098 10099The '``bitcast``' instruction converts ``value`` to type ``ty2`` without 10100changing any bits. 10101 10102Arguments: 10103"""""""""" 10104 10105The '``bitcast``' instruction takes a value to cast, which must be a 10106non-aggregate first class value, and a type to cast it to, which must 10107also be a non-aggregate :ref:`first class <t_firstclass>` type. The 10108bit sizes of ``value`` and the destination type, ``ty2``, must be 10109identical. If the source type is a pointer, the destination type must 10110also be a pointer of the same size. This instruction supports bitwise 10111conversion of vectors to integers and to vectors of other types (as 10112long as they have the same size). 10113 10114Semantics: 10115"""""""""" 10116 10117The '``bitcast``' instruction converts ``value`` to type ``ty2``. It 10118is always a *no-op cast* because no bits change with this 10119conversion. The conversion is done as if the ``value`` had been stored 10120to memory and read back as type ``ty2``. Pointer (or vector of 10121pointers) types may only be converted to other pointer (or vector of 10122pointers) types with the same address space through this instruction. 10123To convert pointers to other types, use the :ref:`inttoptr <i_inttoptr>` 10124or :ref:`ptrtoint <i_ptrtoint>` instructions first. 10125 10126Example: 10127"""""""" 10128 10129.. code-block:: text 10130 10131 %X = bitcast i8 255 to i8 ; yields i8 :-1 10132 %Y = bitcast i32* %x to sint* ; yields sint*:%x 10133 %Z = bitcast <2 x int> %V to i64; ; yields i64: %V 10134 %Z = bitcast <2 x i32*> %V to <2 x i64*> ; yields <2 x i64*> 10135 10136.. _i_addrspacecast: 10137 10138'``addrspacecast .. to``' Instruction 10139^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10140 10141Syntax: 10142""""""" 10143 10144:: 10145 10146 <result> = addrspacecast <pty> <ptrval> to <pty2> ; yields pty2 10147 10148Overview: 10149""""""""" 10150 10151The '``addrspacecast``' instruction converts ``ptrval`` from ``pty`` in 10152address space ``n`` to type ``pty2`` in address space ``m``. 10153 10154Arguments: 10155"""""""""" 10156 10157The '``addrspacecast``' instruction takes a pointer or vector of pointer value 10158to cast and a pointer type to cast it to, which must have a different 10159address space. 10160 10161Semantics: 10162"""""""""" 10163 10164The '``addrspacecast``' instruction converts the pointer value 10165``ptrval`` to type ``pty2``. It can be a *no-op cast* or a complex 10166value modification, depending on the target and the address space 10167pair. Pointer conversions within the same address space must be 10168performed with the ``bitcast`` instruction. Note that if the address space 10169conversion is legal then both result and operand refer to the same memory 10170location. 10171 10172Example: 10173"""""""" 10174 10175.. code-block:: llvm 10176 10177 %X = addrspacecast i32* %x to i32 addrspace(1)* ; yields i32 addrspace(1)*:%x 10178 %Y = addrspacecast i32 addrspace(1)* %y to i64 addrspace(2)* ; yields i64 addrspace(2)*:%y 10179 %Z = addrspacecast <4 x i32*> %z to <4 x float addrspace(3)*> ; yields <4 x float addrspace(3)*>:%z 10180 10181.. _otherops: 10182 10183Other Operations 10184---------------- 10185 10186The instructions in this category are the "miscellaneous" instructions, 10187which defy better classification. 10188 10189.. _i_icmp: 10190 10191'``icmp``' Instruction 10192^^^^^^^^^^^^^^^^^^^^^^ 10193 10194Syntax: 10195""""""" 10196 10197:: 10198 10199 <result> = icmp <cond> <ty> <op1>, <op2> ; yields i1 or <N x i1>:result 10200 10201Overview: 10202""""""""" 10203 10204The '``icmp``' instruction returns a boolean value or a vector of 10205boolean values based on comparison of its two integer, integer vector, 10206pointer, or pointer vector operands. 10207 10208Arguments: 10209"""""""""" 10210 10211The '``icmp``' instruction takes three operands. The first operand is 10212the condition code indicating the kind of comparison to perform. It is 10213not a value, just a keyword. The possible condition codes are: 10214 10215#. ``eq``: equal 10216#. ``ne``: not equal 10217#. ``ugt``: unsigned greater than 10218#. ``uge``: unsigned greater or equal 10219#. ``ult``: unsigned less than 10220#. ``ule``: unsigned less or equal 10221#. ``sgt``: signed greater than 10222#. ``sge``: signed greater or equal 10223#. ``slt``: signed less than 10224#. ``sle``: signed less or equal 10225 10226The remaining two arguments must be :ref:`integer <t_integer>` or 10227:ref:`pointer <t_pointer>` or integer :ref:`vector <t_vector>` typed. They 10228must also be identical types. 10229 10230Semantics: 10231"""""""""" 10232 10233The '``icmp``' compares ``op1`` and ``op2`` according to the condition 10234code given as ``cond``. The comparison performed always yields either an 10235:ref:`i1 <t_integer>` or vector of ``i1`` result, as follows: 10236 10237#. ``eq``: yields ``true`` if the operands are equal, ``false`` 10238 otherwise. No sign interpretation is necessary or performed. 10239#. ``ne``: yields ``true`` if the operands are unequal, ``false`` 10240 otherwise. No sign interpretation is necessary or performed. 10241#. ``ugt``: interprets the operands as unsigned values and yields 10242 ``true`` if ``op1`` is greater than ``op2``. 10243#. ``uge``: interprets the operands as unsigned values and yields 10244 ``true`` if ``op1`` is greater than or equal to ``op2``. 10245#. ``ult``: interprets the operands as unsigned values and yields 10246 ``true`` if ``op1`` is less than ``op2``. 10247#. ``ule``: interprets the operands as unsigned values and yields 10248 ``true`` if ``op1`` is less than or equal to ``op2``. 10249#. ``sgt``: interprets the operands as signed values and yields ``true`` 10250 if ``op1`` is greater than ``op2``. 10251#. ``sge``: interprets the operands as signed values and yields ``true`` 10252 if ``op1`` is greater than or equal to ``op2``. 10253#. ``slt``: interprets the operands as signed values and yields ``true`` 10254 if ``op1`` is less than ``op2``. 10255#. ``sle``: interprets the operands as signed values and yields ``true`` 10256 if ``op1`` is less than or equal to ``op2``. 10257 10258If the operands are :ref:`pointer <t_pointer>` typed, the pointer values 10259are compared as if they were integers. 10260 10261If the operands are integer vectors, then they are compared element by 10262element. The result is an ``i1`` vector with the same number of elements 10263as the values being compared. Otherwise, the result is an ``i1``. 10264 10265Example: 10266"""""""" 10267 10268.. code-block:: text 10269 10270 <result> = icmp eq i32 4, 5 ; yields: result=false 10271 <result> = icmp ne float* %X, %X ; yields: result=false 10272 <result> = icmp ult i16 4, 5 ; yields: result=true 10273 <result> = icmp sgt i16 4, 5 ; yields: result=false 10274 <result> = icmp ule i16 -4, 5 ; yields: result=false 10275 <result> = icmp sge i16 4, 5 ; yields: result=false 10276 10277.. _i_fcmp: 10278 10279'``fcmp``' Instruction 10280^^^^^^^^^^^^^^^^^^^^^^ 10281 10282Syntax: 10283""""""" 10284 10285:: 10286 10287 <result> = fcmp [fast-math flags]* <cond> <ty> <op1>, <op2> ; yields i1 or <N x i1>:result 10288 10289Overview: 10290""""""""" 10291 10292The '``fcmp``' instruction returns a boolean value or vector of boolean 10293values based on comparison of its operands. 10294 10295If the operands are floating-point scalars, then the result type is a 10296boolean (:ref:`i1 <t_integer>`). 10297 10298If the operands are floating-point vectors, then the result type is a 10299vector of boolean with the same number of elements as the operands being 10300compared. 10301 10302Arguments: 10303"""""""""" 10304 10305The '``fcmp``' instruction takes three operands. The first operand is 10306the condition code indicating the kind of comparison to perform. It is 10307not a value, just a keyword. The possible condition codes are: 10308 10309#. ``false``: no comparison, always returns false 10310#. ``oeq``: ordered and equal 10311#. ``ogt``: ordered and greater than 10312#. ``oge``: ordered and greater than or equal 10313#. ``olt``: ordered and less than 10314#. ``ole``: ordered and less than or equal 10315#. ``one``: ordered and not equal 10316#. ``ord``: ordered (no nans) 10317#. ``ueq``: unordered or equal 10318#. ``ugt``: unordered or greater than 10319#. ``uge``: unordered or greater than or equal 10320#. ``ult``: unordered or less than 10321#. ``ule``: unordered or less than or equal 10322#. ``une``: unordered or not equal 10323#. ``uno``: unordered (either nans) 10324#. ``true``: no comparison, always returns true 10325 10326*Ordered* means that neither operand is a QNAN while *unordered* means 10327that either operand may be a QNAN. 10328 10329Each of ``val1`` and ``val2`` arguments must be either a :ref:`floating-point 10330<t_floating>` type or a :ref:`vector <t_vector>` of floating-point type. 10331They must have identical types. 10332 10333Semantics: 10334"""""""""" 10335 10336The '``fcmp``' instruction compares ``op1`` and ``op2`` according to the 10337condition code given as ``cond``. If the operands are vectors, then the 10338vectors are compared element by element. Each comparison performed 10339always yields an :ref:`i1 <t_integer>` result, as follows: 10340 10341#. ``false``: always yields ``false``, regardless of operands. 10342#. ``oeq``: yields ``true`` if both operands are not a QNAN and ``op1`` 10343 is equal to ``op2``. 10344#. ``ogt``: yields ``true`` if both operands are not a QNAN and ``op1`` 10345 is greater than ``op2``. 10346#. ``oge``: yields ``true`` if both operands are not a QNAN and ``op1`` 10347 is greater than or equal to ``op2``. 10348#. ``olt``: yields ``true`` if both operands are not a QNAN and ``op1`` 10349 is less than ``op2``. 10350#. ``ole``: yields ``true`` if both operands are not a QNAN and ``op1`` 10351 is less than or equal to ``op2``. 10352#. ``one``: yields ``true`` if both operands are not a QNAN and ``op1`` 10353 is not equal to ``op2``. 10354#. ``ord``: yields ``true`` if both operands are not a QNAN. 10355#. ``ueq``: yields ``true`` if either operand is a QNAN or ``op1`` is 10356 equal to ``op2``. 10357#. ``ugt``: yields ``true`` if either operand is a QNAN or ``op1`` is 10358 greater than ``op2``. 10359#. ``uge``: yields ``true`` if either operand is a QNAN or ``op1`` is 10360 greater than or equal to ``op2``. 10361#. ``ult``: yields ``true`` if either operand is a QNAN or ``op1`` is 10362 less than ``op2``. 10363#. ``ule``: yields ``true`` if either operand is a QNAN or ``op1`` is 10364 less than or equal to ``op2``. 10365#. ``une``: yields ``true`` if either operand is a QNAN or ``op1`` is 10366 not equal to ``op2``. 10367#. ``uno``: yields ``true`` if either operand is a QNAN. 10368#. ``true``: always yields ``true``, regardless of operands. 10369 10370The ``fcmp`` instruction can also optionally take any number of 10371:ref:`fast-math flags <fastmath>`, which are optimization hints to enable 10372otherwise unsafe floating-point optimizations. 10373 10374Any set of fast-math flags are legal on an ``fcmp`` instruction, but the 10375only flags that have any effect on its semantics are those that allow 10376assumptions to be made about the values of input arguments; namely 10377``nnan``, ``ninf``, and ``reassoc``. See :ref:`fastmath` for more information. 10378 10379Example: 10380"""""""" 10381 10382.. code-block:: text 10383 10384 <result> = fcmp oeq float 4.0, 5.0 ; yields: result=false 10385 <result> = fcmp one float 4.0, 5.0 ; yields: result=true 10386 <result> = fcmp olt float 4.0, 5.0 ; yields: result=true 10387 <result> = fcmp ueq double 1.0, 2.0 ; yields: result=false 10388 10389.. _i_phi: 10390 10391'``phi``' Instruction 10392^^^^^^^^^^^^^^^^^^^^^ 10393 10394Syntax: 10395""""""" 10396 10397:: 10398 10399 <result> = phi [fast-math-flags] <ty> [ <val0>, <label0>], ... 10400 10401Overview: 10402""""""""" 10403 10404The '``phi``' instruction is used to implement the φ node in the SSA 10405graph representing the function. 10406 10407Arguments: 10408"""""""""" 10409 10410The type of the incoming values is specified with the first type field. 10411After this, the '``phi``' instruction takes a list of pairs as 10412arguments, with one pair for each predecessor basic block of the current 10413block. Only values of :ref:`first class <t_firstclass>` type may be used as 10414the value arguments to the PHI node. Only labels may be used as the 10415label arguments. 10416 10417There must be no non-phi instructions between the start of a basic block 10418and the PHI instructions: i.e. PHI instructions must be first in a basic 10419block. 10420 10421For the purposes of the SSA form, the use of each incoming value is 10422deemed to occur on the edge from the corresponding predecessor block to 10423the current block (but after any definition of an '``invoke``' 10424instruction's return value on the same edge). 10425 10426The optional ``fast-math-flags`` marker indicates that the phi has one 10427or more :ref:`fast-math-flags <fastmath>`. These are optimization hints 10428to enable otherwise unsafe floating-point optimizations. Fast-math-flags 10429are only valid for phis that return a floating-point scalar or vector 10430type, or an array (nested to any depth) of floating-point scalar or vector 10431types. 10432 10433Semantics: 10434"""""""""" 10435 10436At runtime, the '``phi``' instruction logically takes on the value 10437specified by the pair corresponding to the predecessor basic block that 10438executed just prior to the current block. 10439 10440Example: 10441"""""""" 10442 10443.. code-block:: llvm 10444 10445 Loop: ; Infinite loop that counts from 0 on up... 10446 %indvar = phi i32 [ 0, %LoopHeader ], [ %nextindvar, %Loop ] 10447 %nextindvar = add i32 %indvar, 1 10448 br label %Loop 10449 10450.. _i_select: 10451 10452'``select``' Instruction 10453^^^^^^^^^^^^^^^^^^^^^^^^ 10454 10455Syntax: 10456""""""" 10457 10458:: 10459 10460 <result> = select [fast-math flags] selty <cond>, <ty> <val1>, <ty> <val2> ; yields ty 10461 10462 selty is either i1 or {<N x i1>} 10463 10464Overview: 10465""""""""" 10466 10467The '``select``' instruction is used to choose one value based on a 10468condition, without IR-level branching. 10469 10470Arguments: 10471"""""""""" 10472 10473The '``select``' instruction requires an 'i1' value or a vector of 'i1' 10474values indicating the condition, and two values of the same :ref:`first 10475class <t_firstclass>` type. 10476 10477#. The optional ``fast-math flags`` marker indicates that the select has one or more 10478 :ref:`fast-math flags <fastmath>`. These are optimization hints to enable 10479 otherwise unsafe floating-point optimizations. Fast-math flags are only valid 10480 for selects that return a floating-point scalar or vector type, or an array 10481 (nested to any depth) of floating-point scalar or vector types. 10482 10483Semantics: 10484"""""""""" 10485 10486If the condition is an i1 and it evaluates to 1, the instruction returns 10487the first value argument; otherwise, it returns the second value 10488argument. 10489 10490If the condition is a vector of i1, then the value arguments must be 10491vectors of the same size, and the selection is done element by element. 10492 10493If the condition is an i1 and the value arguments are vectors of the 10494same size, then an entire vector is selected. 10495 10496Example: 10497"""""""" 10498 10499.. code-block:: llvm 10500 10501 %X = select i1 true, i8 17, i8 42 ; yields i8:17 10502 10503 10504.. _i_freeze: 10505 10506'``freeze``' Instruction 10507^^^^^^^^^^^^^^^^^^^^^^^^ 10508 10509Syntax: 10510""""""" 10511 10512:: 10513 10514 <result> = freeze ty <val> ; yields ty:result 10515 10516Overview: 10517""""""""" 10518 10519The '``freeze``' instruction is used to stop propagation of 10520:ref:`undef <undefvalues>` and :ref:`poison <poisonvalues>` values. 10521 10522Arguments: 10523"""""""""" 10524 10525The '``freeze``' instruction takes a single argument. 10526 10527Semantics: 10528"""""""""" 10529 10530If the argument is ``undef`` or ``poison``, '``freeze``' returns an 10531arbitrary, but fixed, value of type '``ty``'. 10532Otherwise, this instruction is a no-op and returns the input argument. 10533All uses of a value returned by the same '``freeze``' instruction are 10534guaranteed to always observe the same value, while different '``freeze``' 10535instructions may yield different values. 10536 10537While ``undef`` and ``poison`` pointers can be frozen, the result is a 10538non-dereferenceable pointer. See the 10539:ref:`Pointer Aliasing Rules <pointeraliasing>` section for more information. 10540 10541 10542Example: 10543"""""""" 10544 10545.. code-block:: text 10546 10547 %w = i32 undef 10548 %x = freeze i32 %w 10549 %y = add i32 %w, %w ; undef 10550 %z = add i32 %x, %x ; even number because all uses of %x observe 10551 ; the same value 10552 %x2 = freeze i32 %w 10553 %cmp = icmp eq i32 %x, %x2 ; can be true or false 10554 10555 ; example with vectors 10556 %v = <2 x i32> <i32 undef, i32 poison> 10557 %a = extractelement <2 x i32> %v, i32 0 ; undef 10558 %b = extractelement <2 x i32> %v, i32 1 ; poison 10559 %add = add i32 %a, %a ; undef 10560 10561 %v.fr = freeze <2 x i32> %v ; element-wise freeze 10562 %d = extractelement <2 x i32> %v.fr, i32 0 ; not undef 10563 %add.f = add i32 %d, %d ; even number 10564 10565 ; branching on frozen value 10566 %poison = add nsw i1 %k, undef ; poison 10567 %c = freeze i1 %poison 10568 br i1 %c, label %foo, label %bar ; non-deterministic branch to %foo or %bar 10569 10570 10571.. _i_call: 10572 10573'``call``' Instruction 10574^^^^^^^^^^^^^^^^^^^^^^ 10575 10576Syntax: 10577""""""" 10578 10579:: 10580 10581 <result> = [tail | musttail | notail ] call [fast-math flags] [cconv] [ret attrs] [addrspace(<num>)] 10582 <ty>|<fnty> <fnptrval>(<function args>) [fn attrs] [ operand bundles ] 10583 10584Overview: 10585""""""""" 10586 10587The '``call``' instruction represents a simple function call. 10588 10589Arguments: 10590"""""""""" 10591 10592This instruction requires several arguments: 10593 10594#. The optional ``tail`` and ``musttail`` markers indicate that the optimizers 10595 should perform tail call optimization. The ``tail`` marker is a hint that 10596 `can be ignored <CodeGenerator.html#sibcallopt>`_. The ``musttail`` marker 10597 means that the call must be tail call optimized in order for the program to 10598 be correct. The ``musttail`` marker provides these guarantees: 10599 10600 #. The call will not cause unbounded stack growth if it is part of a 10601 recursive cycle in the call graph. 10602 #. Arguments with the :ref:`inalloca <attr_inalloca>` attribute are 10603 forwarded in place. 10604 #. If the musttail call appears in a function with the ``"thunk"`` attribute 10605 and the caller and callee both have varargs, than any unprototyped 10606 arguments in register or memory are forwarded to the callee. Similarly, 10607 the return value of the callee is returned to the caller's caller, even 10608 if a void return type is in use. 10609 10610 Both markers imply that the callee does not access allocas from the caller. 10611 The ``tail`` marker additionally implies that the callee does not access 10612 varargs from the caller. Calls marked ``musttail`` must obey the following 10613 additional rules: 10614 10615 - The call must immediately precede a :ref:`ret <i_ret>` instruction, 10616 or a pointer bitcast followed by a ret instruction. 10617 - The ret instruction must return the (possibly bitcasted) value 10618 produced by the call or void. 10619 - The caller and callee prototypes must match. Pointer types of 10620 parameters or return types may differ in pointee type, but not 10621 in address space. 10622 - The calling conventions of the caller and callee must match. 10623 - All ABI-impacting function attributes, such as sret, byval, inreg, 10624 returned, and inalloca, must match. 10625 - The callee must be varargs iff the caller is varargs. Bitcasting a 10626 non-varargs function to the appropriate varargs type is legal so 10627 long as the non-varargs prefixes obey the other rules. 10628 10629 Tail call optimization for calls marked ``tail`` is guaranteed to occur if 10630 the following conditions are met: 10631 10632 - Caller and callee both have the calling convention ``fastcc`` or ``tailcc``. 10633 - The call is in tail position (ret immediately follows call and ret 10634 uses value of call or is void). 10635 - Option ``-tailcallopt`` is enabled, 10636 ``llvm::GuaranteedTailCallOpt`` is ``true``, or the calling convention 10637 is ``tailcc`` 10638 - `Platform-specific constraints are 10639 met. <CodeGenerator.html#tailcallopt>`_ 10640 10641#. The optional ``notail`` marker indicates that the optimizers should not add 10642 ``tail`` or ``musttail`` markers to the call. It is used to prevent tail 10643 call optimization from being performed on the call. 10644 10645#. The optional ``fast-math flags`` marker indicates that the call has one or more 10646 :ref:`fast-math flags <fastmath>`, which are optimization hints to enable 10647 otherwise unsafe floating-point optimizations. Fast-math flags are only valid 10648 for calls that return a floating-point scalar or vector type, or an array 10649 (nested to any depth) of floating-point scalar or vector types. 10650 10651#. The optional "cconv" marker indicates which :ref:`calling 10652 convention <callingconv>` the call should use. If none is 10653 specified, the call defaults to using C calling conventions. The 10654 calling convention of the call must match the calling convention of 10655 the target function, or else the behavior is undefined. 10656#. The optional :ref:`Parameter Attributes <paramattrs>` list for return 10657 values. Only '``zeroext``', '``signext``', and '``inreg``' attributes 10658 are valid here. 10659#. The optional addrspace attribute can be used to indicate the address space 10660 of the called function. If it is not specified, the program address space 10661 from the :ref:`datalayout string<langref_datalayout>` will be used. 10662#. '``ty``': the type of the call instruction itself which is also the 10663 type of the return value. Functions that return no value are marked 10664 ``void``. 10665#. '``fnty``': shall be the signature of the function being called. The 10666 argument types must match the types implied by this signature. This 10667 type can be omitted if the function is not varargs. 10668#. '``fnptrval``': An LLVM value containing a pointer to a function to 10669 be called. In most cases, this is a direct function call, but 10670 indirect ``call``'s are just as possible, calling an arbitrary pointer 10671 to function value. 10672#. '``function args``': argument list whose types match the function 10673 signature argument types and parameter attributes. All arguments must 10674 be of :ref:`first class <t_firstclass>` type. If the function signature 10675 indicates the function accepts a variable number of arguments, the 10676 extra arguments can be specified. 10677#. The optional :ref:`function attributes <fnattrs>` list. 10678#. The optional :ref:`operand bundles <opbundles>` list. 10679 10680Semantics: 10681"""""""""" 10682 10683The '``call``' instruction is used to cause control flow to transfer to 10684a specified function, with its incoming arguments bound to the specified 10685values. Upon a '``ret``' instruction in the called function, control 10686flow continues with the instruction after the function call, and the 10687return value of the function is bound to the result argument. 10688 10689Example: 10690"""""""" 10691 10692.. code-block:: llvm 10693 10694 %retval = call i32 @test(i32 %argc) 10695 call i32 (i8*, ...)* @printf(i8* %msg, i32 12, i8 42) ; yields i32 10696 %X = tail call i32 @foo() ; yields i32 10697 %Y = tail call fastcc i32 @foo() ; yields i32 10698 call void %foo(i8 97 signext) 10699 10700 %struct.A = type { i32, i8 } 10701 %r = call %struct.A @foo() ; yields { i32, i8 } 10702 %gr = extractvalue %struct.A %r, 0 ; yields i32 10703 %gr1 = extractvalue %struct.A %r, 1 ; yields i8 10704 %Z = call void @foo() noreturn ; indicates that %foo never returns normally 10705 %ZZ = call zeroext i32 @bar() ; Return value is %zero extended 10706 10707llvm treats calls to some functions with names and arguments that match 10708the standard C99 library as being the C99 library functions, and may 10709perform optimizations or generate code for them under that assumption. 10710This is something we'd like to change in the future to provide better 10711support for freestanding environments and non-C-based languages. 10712 10713.. _i_va_arg: 10714 10715'``va_arg``' Instruction 10716^^^^^^^^^^^^^^^^^^^^^^^^ 10717 10718Syntax: 10719""""""" 10720 10721:: 10722 10723 <resultval> = va_arg <va_list*> <arglist>, <argty> 10724 10725Overview: 10726""""""""" 10727 10728The '``va_arg``' instruction is used to access arguments passed through 10729the "variable argument" area of a function call. It is used to implement 10730the ``va_arg`` macro in C. 10731 10732Arguments: 10733"""""""""" 10734 10735This instruction takes a ``va_list*`` value and the type of the 10736argument. It returns a value of the specified argument type and 10737increments the ``va_list`` to point to the next argument. The actual 10738type of ``va_list`` is target specific. 10739 10740Semantics: 10741"""""""""" 10742 10743The '``va_arg``' instruction loads an argument of the specified type 10744from the specified ``va_list`` and causes the ``va_list`` to point to 10745the next argument. For more information, see the variable argument 10746handling :ref:`Intrinsic Functions <int_varargs>`. 10747 10748It is legal for this instruction to be called in a function which does 10749not take a variable number of arguments, for example, the ``vfprintf`` 10750function. 10751 10752``va_arg`` is an LLVM instruction instead of an :ref:`intrinsic 10753function <intrinsics>` because it takes a type as an argument. 10754 10755Example: 10756"""""""" 10757 10758See the :ref:`variable argument processing <int_varargs>` section. 10759 10760Note that the code generator does not yet fully support va\_arg on many 10761targets. Also, it does not currently support va\_arg with aggregate 10762types on any target. 10763 10764.. _i_landingpad: 10765 10766'``landingpad``' Instruction 10767^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10768 10769Syntax: 10770""""""" 10771 10772:: 10773 10774 <resultval> = landingpad <resultty> <clause>+ 10775 <resultval> = landingpad <resultty> cleanup <clause>* 10776 10777 <clause> := catch <type> <value> 10778 <clause> := filter <array constant type> <array constant> 10779 10780Overview: 10781""""""""" 10782 10783The '``landingpad``' instruction is used by `LLVM's exception handling 10784system <ExceptionHandling.html#overview>`_ to specify that a basic block 10785is a landing pad --- one where the exception lands, and corresponds to the 10786code found in the ``catch`` portion of a ``try``/``catch`` sequence. It 10787defines values supplied by the :ref:`personality function <personalityfn>` upon 10788re-entry to the function. The ``resultval`` has the type ``resultty``. 10789 10790Arguments: 10791"""""""""" 10792 10793The optional 10794``cleanup`` flag indicates that the landing pad block is a cleanup. 10795 10796A ``clause`` begins with the clause type --- ``catch`` or ``filter`` --- and 10797contains the global variable representing the "type" that may be caught 10798or filtered respectively. Unlike the ``catch`` clause, the ``filter`` 10799clause takes an array constant as its argument. Use 10800"``[0 x i8**] undef``" for a filter which cannot throw. The 10801'``landingpad``' instruction must contain *at least* one ``clause`` or 10802the ``cleanup`` flag. 10803 10804Semantics: 10805"""""""""" 10806 10807The '``landingpad``' instruction defines the values which are set by the 10808:ref:`personality function <personalityfn>` upon re-entry to the function, and 10809therefore the "result type" of the ``landingpad`` instruction. As with 10810calling conventions, how the personality function results are 10811represented in LLVM IR is target specific. 10812 10813The clauses are applied in order from top to bottom. If two 10814``landingpad`` instructions are merged together through inlining, the 10815clauses from the calling function are appended to the list of clauses. 10816When the call stack is being unwound due to an exception being thrown, 10817the exception is compared against each ``clause`` in turn. If it doesn't 10818match any of the clauses, and the ``cleanup`` flag is not set, then 10819unwinding continues further up the call stack. 10820 10821The ``landingpad`` instruction has several restrictions: 10822 10823- A landing pad block is a basic block which is the unwind destination 10824 of an '``invoke``' instruction. 10825- A landing pad block must have a '``landingpad``' instruction as its 10826 first non-PHI instruction. 10827- There can be only one '``landingpad``' instruction within the landing 10828 pad block. 10829- A basic block that is not a landing pad block may not include a 10830 '``landingpad``' instruction. 10831 10832Example: 10833"""""""" 10834 10835.. code-block:: llvm 10836 10837 ;; A landing pad which can catch an integer. 10838 %res = landingpad { i8*, i32 } 10839 catch i8** @_ZTIi 10840 ;; A landing pad that is a cleanup. 10841 %res = landingpad { i8*, i32 } 10842 cleanup 10843 ;; A landing pad which can catch an integer and can only throw a double. 10844 %res = landingpad { i8*, i32 } 10845 catch i8** @_ZTIi 10846 filter [1 x i8**] [@_ZTId] 10847 10848.. _i_catchpad: 10849 10850'``catchpad``' Instruction 10851^^^^^^^^^^^^^^^^^^^^^^^^^^ 10852 10853Syntax: 10854""""""" 10855 10856:: 10857 10858 <resultval> = catchpad within <catchswitch> [<args>*] 10859 10860Overview: 10861""""""""" 10862 10863The '``catchpad``' instruction is used by `LLVM's exception handling 10864system <ExceptionHandling.html#overview>`_ to specify that a basic block 10865begins a catch handler --- one where a personality routine attempts to transfer 10866control to catch an exception. 10867 10868Arguments: 10869"""""""""" 10870 10871The ``catchswitch`` operand must always be a token produced by a 10872:ref:`catchswitch <i_catchswitch>` instruction in a predecessor block. This 10873ensures that each ``catchpad`` has exactly one predecessor block, and it always 10874terminates in a ``catchswitch``. 10875 10876The ``args`` correspond to whatever information the personality routine 10877requires to know if this is an appropriate handler for the exception. Control 10878will transfer to the ``catchpad`` if this is the first appropriate handler for 10879the exception. 10880 10881The ``resultval`` has the type :ref:`token <t_token>` and is used to match the 10882``catchpad`` to corresponding :ref:`catchrets <i_catchret>` and other nested EH 10883pads. 10884 10885Semantics: 10886"""""""""" 10887 10888When the call stack is being unwound due to an exception being thrown, the 10889exception is compared against the ``args``. If it doesn't match, control will 10890not reach the ``catchpad`` instruction. The representation of ``args`` is 10891entirely target and personality function-specific. 10892 10893Like the :ref:`landingpad <i_landingpad>` instruction, the ``catchpad`` 10894instruction must be the first non-phi of its parent basic block. 10895 10896The meaning of the tokens produced and consumed by ``catchpad`` and other "pad" 10897instructions is described in the 10898`Windows exception handling documentation\ <ExceptionHandling.html#wineh>`_. 10899 10900When a ``catchpad`` has been "entered" but not yet "exited" (as 10901described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_), 10902it is undefined behavior to execute a :ref:`call <i_call>` or :ref:`invoke <i_invoke>` 10903that does not carry an appropriate :ref:`"funclet" bundle <ob_funclet>`. 10904 10905Example: 10906"""""""" 10907 10908.. code-block:: text 10909 10910 dispatch: 10911 %cs = catchswitch within none [label %handler0] unwind to caller 10912 ;; A catch block which can catch an integer. 10913 handler0: 10914 %tok = catchpad within %cs [i8** @_ZTIi] 10915 10916.. _i_cleanuppad: 10917 10918'``cleanuppad``' Instruction 10919^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10920 10921Syntax: 10922""""""" 10923 10924:: 10925 10926 <resultval> = cleanuppad within <parent> [<args>*] 10927 10928Overview: 10929""""""""" 10930 10931The '``cleanuppad``' instruction is used by `LLVM's exception handling 10932system <ExceptionHandling.html#overview>`_ to specify that a basic block 10933is a cleanup block --- one where a personality routine attempts to 10934transfer control to run cleanup actions. 10935The ``args`` correspond to whatever additional 10936information the :ref:`personality function <personalityfn>` requires to 10937execute the cleanup. 10938The ``resultval`` has the type :ref:`token <t_token>` and is used to 10939match the ``cleanuppad`` to corresponding :ref:`cleanuprets <i_cleanupret>`. 10940The ``parent`` argument is the token of the funclet that contains the 10941``cleanuppad`` instruction. If the ``cleanuppad`` is not inside a funclet, 10942this operand may be the token ``none``. 10943 10944Arguments: 10945"""""""""" 10946 10947The instruction takes a list of arbitrary values which are interpreted 10948by the :ref:`personality function <personalityfn>`. 10949 10950Semantics: 10951"""""""""" 10952 10953When the call stack is being unwound due to an exception being thrown, 10954the :ref:`personality function <personalityfn>` transfers control to the 10955``cleanuppad`` with the aid of the personality-specific arguments. 10956As with calling conventions, how the personality function results are 10957represented in LLVM IR is target specific. 10958 10959The ``cleanuppad`` instruction has several restrictions: 10960 10961- A cleanup block is a basic block which is the unwind destination of 10962 an exceptional instruction. 10963- A cleanup block must have a '``cleanuppad``' instruction as its 10964 first non-PHI instruction. 10965- There can be only one '``cleanuppad``' instruction within the 10966 cleanup block. 10967- A basic block that is not a cleanup block may not include a 10968 '``cleanuppad``' instruction. 10969 10970When a ``cleanuppad`` has been "entered" but not yet "exited" (as 10971described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_), 10972it is undefined behavior to execute a :ref:`call <i_call>` or :ref:`invoke <i_invoke>` 10973that does not carry an appropriate :ref:`"funclet" bundle <ob_funclet>`. 10974 10975Example: 10976"""""""" 10977 10978.. code-block:: text 10979 10980 %tok = cleanuppad within %cs [] 10981 10982.. _intrinsics: 10983 10984Intrinsic Functions 10985=================== 10986 10987LLVM supports the notion of an "intrinsic function". These functions 10988have well known names and semantics and are required to follow certain 10989restrictions. Overall, these intrinsics represent an extension mechanism 10990for the LLVM language that does not require changing all of the 10991transformations in LLVM when adding to the language (or the bitcode 10992reader/writer, the parser, etc...). 10993 10994Intrinsic function names must all start with an "``llvm.``" prefix. This 10995prefix is reserved in LLVM for intrinsic names; thus, function names may 10996not begin with this prefix. Intrinsic functions must always be external 10997functions: you cannot define the body of intrinsic functions. Intrinsic 10998functions may only be used in call or invoke instructions: it is illegal 10999to take the address of an intrinsic function. Additionally, because 11000intrinsic functions are part of the LLVM language, it is required if any 11001are added that they be documented here. 11002 11003Some intrinsic functions can be overloaded, i.e., the intrinsic 11004represents a family of functions that perform the same operation but on 11005different data types. Because LLVM can represent over 8 million 11006different integer types, overloading is used commonly to allow an 11007intrinsic function to operate on any integer type. One or more of the 11008argument types or the result type can be overloaded to accept any 11009integer type. Argument types may also be defined as exactly matching a 11010previous argument's type or the result type. This allows an intrinsic 11011function which accepts multiple arguments, but needs all of them to be 11012of the same type, to only be overloaded with respect to a single 11013argument or the result. 11014 11015Overloaded intrinsics will have the names of its overloaded argument 11016types encoded into its function name, each preceded by a period. Only 11017those types which are overloaded result in a name suffix. Arguments 11018whose type is matched against another type do not. For example, the 11019``llvm.ctpop`` function can take an integer of any width and returns an 11020integer of exactly the same integer width. This leads to a family of 11021functions such as ``i8 @llvm.ctpop.i8(i8 %val)`` and 11022``i29 @llvm.ctpop.i29(i29 %val)``. Only one type, the return type, is 11023overloaded, and only one type suffix is required. Because the argument's 11024type is matched against the return type, it does not require its own 11025name suffix. 11026 11027For target developers who are defining intrinsics for back-end code 11028generation, any intrinsic overloads based solely the distinction between 11029integer or floating point types should not be relied upon for correct 11030code generation. In such cases, the recommended approach for target 11031maintainers when defining intrinsics is to create separate integer and 11032FP intrinsics rather than rely on overloading. For example, if different 11033codegen is required for ``llvm.target.foo(<4 x i32>)`` and 11034``llvm.target.foo(<4 x float>)`` then these should be split into 11035different intrinsics. 11036 11037To learn how to add an intrinsic function, please see the `Extending 11038LLVM Guide <ExtendingLLVM.html>`_. 11039 11040.. _int_varargs: 11041 11042Variable Argument Handling Intrinsics 11043------------------------------------- 11044 11045Variable argument support is defined in LLVM with the 11046:ref:`va_arg <i_va_arg>` instruction and these three intrinsic 11047functions. These functions are related to the similarly named macros 11048defined in the ``<stdarg.h>`` header file. 11049 11050All of these functions operate on arguments that use a target-specific 11051value type "``va_list``". The LLVM assembly language reference manual 11052does not define what this type is, so all transformations should be 11053prepared to handle these functions regardless of the type used. 11054 11055This example shows how the :ref:`va_arg <i_va_arg>` instruction and the 11056variable argument handling intrinsic functions are used. 11057 11058.. code-block:: llvm 11059 11060 ; This struct is different for every platform. For most platforms, 11061 ; it is merely an i8*. 11062 %struct.va_list = type { i8* } 11063 11064 ; For Unix x86_64 platforms, va_list is the following struct: 11065 ; %struct.va_list = type { i32, i32, i8*, i8* } 11066 11067 define i32 @test(i32 %X, ...) { 11068 ; Initialize variable argument processing 11069 %ap = alloca %struct.va_list 11070 %ap2 = bitcast %struct.va_list* %ap to i8* 11071 call void @llvm.va_start(i8* %ap2) 11072 11073 ; Read a single integer argument 11074 %tmp = va_arg i8* %ap2, i32 11075 11076 ; Demonstrate usage of llvm.va_copy and llvm.va_end 11077 %aq = alloca i8* 11078 %aq2 = bitcast i8** %aq to i8* 11079 call void @llvm.va_copy(i8* %aq2, i8* %ap2) 11080 call void @llvm.va_end(i8* %aq2) 11081 11082 ; Stop processing of arguments. 11083 call void @llvm.va_end(i8* %ap2) 11084 ret i32 %tmp 11085 } 11086 11087 declare void @llvm.va_start(i8*) 11088 declare void @llvm.va_copy(i8*, i8*) 11089 declare void @llvm.va_end(i8*) 11090 11091.. _int_va_start: 11092 11093'``llvm.va_start``' Intrinsic 11094^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11095 11096Syntax: 11097""""""" 11098 11099:: 11100 11101 declare void @llvm.va_start(i8* <arglist>) 11102 11103Overview: 11104""""""""" 11105 11106The '``llvm.va_start``' intrinsic initializes ``*<arglist>`` for 11107subsequent use by ``va_arg``. 11108 11109Arguments: 11110"""""""""" 11111 11112The argument is a pointer to a ``va_list`` element to initialize. 11113 11114Semantics: 11115"""""""""" 11116 11117The '``llvm.va_start``' intrinsic works just like the ``va_start`` macro 11118available in C. In a target-dependent way, it initializes the 11119``va_list`` element to which the argument points, so that the next call 11120to ``va_arg`` will produce the first variable argument passed to the 11121function. Unlike the C ``va_start`` macro, this intrinsic does not need 11122to know the last argument of the function as the compiler can figure 11123that out. 11124 11125'``llvm.va_end``' Intrinsic 11126^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11127 11128Syntax: 11129""""""" 11130 11131:: 11132 11133 declare void @llvm.va_end(i8* <arglist>) 11134 11135Overview: 11136""""""""" 11137 11138The '``llvm.va_end``' intrinsic destroys ``*<arglist>``, which has been 11139initialized previously with ``llvm.va_start`` or ``llvm.va_copy``. 11140 11141Arguments: 11142"""""""""" 11143 11144The argument is a pointer to a ``va_list`` to destroy. 11145 11146Semantics: 11147"""""""""" 11148 11149The '``llvm.va_end``' intrinsic works just like the ``va_end`` macro 11150available in C. In a target-dependent way, it destroys the ``va_list`` 11151element to which the argument points. Calls to 11152:ref:`llvm.va_start <int_va_start>` and 11153:ref:`llvm.va_copy <int_va_copy>` must be matched exactly with calls to 11154``llvm.va_end``. 11155 11156.. _int_va_copy: 11157 11158'``llvm.va_copy``' Intrinsic 11159^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11160 11161Syntax: 11162""""""" 11163 11164:: 11165 11166 declare void @llvm.va_copy(i8* <destarglist>, i8* <srcarglist>) 11167 11168Overview: 11169""""""""" 11170 11171The '``llvm.va_copy``' intrinsic copies the current argument position 11172from the source argument list to the destination argument list. 11173 11174Arguments: 11175"""""""""" 11176 11177The first argument is a pointer to a ``va_list`` element to initialize. 11178The second argument is a pointer to a ``va_list`` element to copy from. 11179 11180Semantics: 11181"""""""""" 11182 11183The '``llvm.va_copy``' intrinsic works just like the ``va_copy`` macro 11184available in C. In a target-dependent way, it copies the source 11185``va_list`` element into the destination ``va_list`` element. This 11186intrinsic is necessary because the `` llvm.va_start`` intrinsic may be 11187arbitrarily complex and require, for example, memory allocation. 11188 11189Accurate Garbage Collection Intrinsics 11190-------------------------------------- 11191 11192LLVM's support for `Accurate Garbage Collection <GarbageCollection.html>`_ 11193(GC) requires the frontend to generate code containing appropriate intrinsic 11194calls and select an appropriate GC strategy which knows how to lower these 11195intrinsics in a manner which is appropriate for the target collector. 11196 11197These intrinsics allow identification of :ref:`GC roots on the 11198stack <int_gcroot>`, as well as garbage collector implementations that 11199require :ref:`read <int_gcread>` and :ref:`write <int_gcwrite>` barriers. 11200Frontends for type-safe garbage collected languages should generate 11201these intrinsics to make use of the LLVM garbage collectors. For more 11202details, see `Garbage Collection with LLVM <GarbageCollection.html>`_. 11203 11204Experimental Statepoint Intrinsics 11205^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11206 11207LLVM provides an second experimental set of intrinsics for describing garbage 11208collection safepoints in compiled code. These intrinsics are an alternative 11209to the ``llvm.gcroot`` intrinsics, but are compatible with the ones for 11210:ref:`read <int_gcread>` and :ref:`write <int_gcwrite>` barriers. The 11211differences in approach are covered in the `Garbage Collection with LLVM 11212<GarbageCollection.html>`_ documentation. The intrinsics themselves are 11213described in :doc:`Statepoints`. 11214 11215.. _int_gcroot: 11216 11217'``llvm.gcroot``' Intrinsic 11218^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11219 11220Syntax: 11221""""""" 11222 11223:: 11224 11225 declare void @llvm.gcroot(i8** %ptrloc, i8* %metadata) 11226 11227Overview: 11228""""""""" 11229 11230The '``llvm.gcroot``' intrinsic declares the existence of a GC root to 11231the code generator, and allows some metadata to be associated with it. 11232 11233Arguments: 11234"""""""""" 11235 11236The first argument specifies the address of a stack object that contains 11237the root pointer. The second pointer (which must be either a constant or 11238a global value address) contains the meta-data to be associated with the 11239root. 11240 11241Semantics: 11242"""""""""" 11243 11244At runtime, a call to this intrinsic stores a null pointer into the 11245"ptrloc" location. At compile-time, the code generator generates 11246information to allow the runtime to find the pointer at GC safe points. 11247The '``llvm.gcroot``' intrinsic may only be used in a function which 11248:ref:`specifies a GC algorithm <gc>`. 11249 11250.. _int_gcread: 11251 11252'``llvm.gcread``' Intrinsic 11253^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11254 11255Syntax: 11256""""""" 11257 11258:: 11259 11260 declare i8* @llvm.gcread(i8* %ObjPtr, i8** %Ptr) 11261 11262Overview: 11263""""""""" 11264 11265The '``llvm.gcread``' intrinsic identifies reads of references from heap 11266locations, allowing garbage collector implementations that require read 11267barriers. 11268 11269Arguments: 11270"""""""""" 11271 11272The second argument is the address to read from, which should be an 11273address allocated from the garbage collector. The first object is a 11274pointer to the start of the referenced object, if needed by the language 11275runtime (otherwise null). 11276 11277Semantics: 11278"""""""""" 11279 11280The '``llvm.gcread``' intrinsic has the same semantics as a load 11281instruction, but may be replaced with substantially more complex code by 11282the garbage collector runtime, as needed. The '``llvm.gcread``' 11283intrinsic may only be used in a function which :ref:`specifies a GC 11284algorithm <gc>`. 11285 11286.. _int_gcwrite: 11287 11288'``llvm.gcwrite``' Intrinsic 11289^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11290 11291Syntax: 11292""""""" 11293 11294:: 11295 11296 declare void @llvm.gcwrite(i8* %P1, i8* %Obj, i8** %P2) 11297 11298Overview: 11299""""""""" 11300 11301The '``llvm.gcwrite``' intrinsic identifies writes of references to heap 11302locations, allowing garbage collector implementations that require write 11303barriers (such as generational or reference counting collectors). 11304 11305Arguments: 11306"""""""""" 11307 11308The first argument is the reference to store, the second is the start of 11309the object to store it to, and the third is the address of the field of 11310Obj to store to. If the runtime does not require a pointer to the 11311object, Obj may be null. 11312 11313Semantics: 11314"""""""""" 11315 11316The '``llvm.gcwrite``' intrinsic has the same semantics as a store 11317instruction, but may be replaced with substantially more complex code by 11318the garbage collector runtime, as needed. The '``llvm.gcwrite``' 11319intrinsic may only be used in a function which :ref:`specifies a GC 11320algorithm <gc>`. 11321 11322Code Generator Intrinsics 11323------------------------- 11324 11325These intrinsics are provided by LLVM to expose special features that 11326may only be implemented with code generator support. 11327 11328'``llvm.returnaddress``' Intrinsic 11329^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11330 11331Syntax: 11332""""""" 11333 11334:: 11335 11336 declare i8* @llvm.returnaddress(i32 <level>) 11337 11338Overview: 11339""""""""" 11340 11341The '``llvm.returnaddress``' intrinsic attempts to compute a 11342target-specific value indicating the return address of the current 11343function or one of its callers. 11344 11345Arguments: 11346"""""""""" 11347 11348The argument to this intrinsic indicates which function to return the 11349address for. Zero indicates the calling function, one indicates its 11350caller, etc. The argument is **required** to be a constant integer 11351value. 11352 11353Semantics: 11354"""""""""" 11355 11356The '``llvm.returnaddress``' intrinsic either returns a pointer 11357indicating the return address of the specified call frame, or zero if it 11358cannot be identified. The value returned by this intrinsic is likely to 11359be incorrect or 0 for arguments other than zero, so it should only be 11360used for debugging purposes. 11361 11362Note that calling this intrinsic does not prevent function inlining or 11363other aggressive transformations, so the value returned may not be that 11364of the obvious source-language caller. 11365 11366'``llvm.addressofreturnaddress``' Intrinsic 11367^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11368 11369Syntax: 11370""""""" 11371 11372:: 11373 11374 declare i8* @llvm.addressofreturnaddress() 11375 11376Overview: 11377""""""""" 11378 11379The '``llvm.addressofreturnaddress``' intrinsic returns a target-specific 11380pointer to the place in the stack frame where the return address of the 11381current function is stored. 11382 11383Semantics: 11384"""""""""" 11385 11386Note that calling this intrinsic does not prevent function inlining or 11387other aggressive transformations, so the value returned may not be that 11388of the obvious source-language caller. 11389 11390This intrinsic is only implemented for x86 and aarch64. 11391 11392'``llvm.sponentry``' Intrinsic 11393^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11394 11395Syntax: 11396""""""" 11397 11398:: 11399 11400 declare i8* @llvm.sponentry() 11401 11402Overview: 11403""""""""" 11404 11405The '``llvm.sponentry``' intrinsic returns the stack pointer value at 11406the entry of the current function calling this intrinsic. 11407 11408Semantics: 11409"""""""""" 11410 11411Note this intrinsic is only verified on AArch64. 11412 11413'``llvm.frameaddress``' Intrinsic 11414^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11415 11416Syntax: 11417""""""" 11418 11419:: 11420 11421 declare i8* @llvm.frameaddress(i32 <level>) 11422 11423Overview: 11424""""""""" 11425 11426The '``llvm.frameaddress``' intrinsic attempts to return the 11427target-specific frame pointer value for the specified stack frame. 11428 11429Arguments: 11430"""""""""" 11431 11432The argument to this intrinsic indicates which function to return the 11433frame pointer for. Zero indicates the calling function, one indicates 11434its caller, etc. The argument is **required** to be a constant integer 11435value. 11436 11437Semantics: 11438"""""""""" 11439 11440The '``llvm.frameaddress``' intrinsic either returns a pointer 11441indicating the frame address of the specified call frame, or zero if it 11442cannot be identified. The value returned by this intrinsic is likely to 11443be incorrect or 0 for arguments other than zero, so it should only be 11444used for debugging purposes. 11445 11446Note that calling this intrinsic does not prevent function inlining or 11447other aggressive transformations, so the value returned may not be that 11448of the obvious source-language caller. 11449 11450'``llvm.localescape``' and '``llvm.localrecover``' Intrinsics 11451^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11452 11453Syntax: 11454""""""" 11455 11456:: 11457 11458 declare void @llvm.localescape(...) 11459 declare i8* @llvm.localrecover(i8* %func, i8* %fp, i32 %idx) 11460 11461Overview: 11462""""""""" 11463 11464The '``llvm.localescape``' intrinsic escapes offsets of a collection of static 11465allocas, and the '``llvm.localrecover``' intrinsic applies those offsets to a 11466live frame pointer to recover the address of the allocation. The offset is 11467computed during frame layout of the caller of ``llvm.localescape``. 11468 11469Arguments: 11470"""""""""" 11471 11472All arguments to '``llvm.localescape``' must be pointers to static allocas or 11473casts of static allocas. Each function can only call '``llvm.localescape``' 11474once, and it can only do so from the entry block. 11475 11476The ``func`` argument to '``llvm.localrecover``' must be a constant 11477bitcasted pointer to a function defined in the current module. The code 11478generator cannot determine the frame allocation offset of functions defined in 11479other modules. 11480 11481The ``fp`` argument to '``llvm.localrecover``' must be a frame pointer of a 11482call frame that is currently live. The return value of '``llvm.localaddress``' 11483is one way to produce such a value, but various runtimes also expose a suitable 11484pointer in platform-specific ways. 11485 11486The ``idx`` argument to '``llvm.localrecover``' indicates which alloca passed to 11487'``llvm.localescape``' to recover. It is zero-indexed. 11488 11489Semantics: 11490"""""""""" 11491 11492These intrinsics allow a group of functions to share access to a set of local 11493stack allocations of a one parent function. The parent function may call the 11494'``llvm.localescape``' intrinsic once from the function entry block, and the 11495child functions can use '``llvm.localrecover``' to access the escaped allocas. 11496The '``llvm.localescape``' intrinsic blocks inlining, as inlining changes where 11497the escaped allocas are allocated, which would break attempts to use 11498'``llvm.localrecover``'. 11499 11500.. _int_read_register: 11501.. _int_write_register: 11502 11503'``llvm.read_register``' and '``llvm.write_register``' Intrinsics 11504^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11505 11506Syntax: 11507""""""" 11508 11509:: 11510 11511 declare i32 @llvm.read_register.i32(metadata) 11512 declare i64 @llvm.read_register.i64(metadata) 11513 declare void @llvm.write_register.i32(metadata, i32 @value) 11514 declare void @llvm.write_register.i64(metadata, i64 @value) 11515 !0 = !{!"sp\00"} 11516 11517Overview: 11518""""""""" 11519 11520The '``llvm.read_register``' and '``llvm.write_register``' intrinsics 11521provides access to the named register. The register must be valid on 11522the architecture being compiled to. The type needs to be compatible 11523with the register being read. 11524 11525Semantics: 11526"""""""""" 11527 11528The '``llvm.read_register``' intrinsic returns the current value of the 11529register, where possible. The '``llvm.write_register``' intrinsic sets 11530the current value of the register, where possible. 11531 11532This is useful to implement named register global variables that need 11533to always be mapped to a specific register, as is common practice on 11534bare-metal programs including OS kernels. 11535 11536The compiler doesn't check for register availability or use of the used 11537register in surrounding code, including inline assembly. Because of that, 11538allocatable registers are not supported. 11539 11540Warning: So far it only works with the stack pointer on selected 11541architectures (ARM, AArch64, PowerPC and x86_64). Significant amount of 11542work is needed to support other registers and even more so, allocatable 11543registers. 11544 11545.. _int_stacksave: 11546 11547'``llvm.stacksave``' Intrinsic 11548^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11549 11550Syntax: 11551""""""" 11552 11553:: 11554 11555 declare i8* @llvm.stacksave() 11556 11557Overview: 11558""""""""" 11559 11560The '``llvm.stacksave``' intrinsic is used to remember the current state 11561of the function stack, for use with 11562:ref:`llvm.stackrestore <int_stackrestore>`. This is useful for 11563implementing language features like scoped automatic variable sized 11564arrays in C99. 11565 11566Semantics: 11567"""""""""" 11568 11569This intrinsic returns a opaque pointer value that can be passed to 11570:ref:`llvm.stackrestore <int_stackrestore>`. When an 11571``llvm.stackrestore`` intrinsic is executed with a value saved from 11572``llvm.stacksave``, it effectively restores the state of the stack to 11573the state it was in when the ``llvm.stacksave`` intrinsic executed. In 11574practice, this pops any :ref:`alloca <i_alloca>` blocks from the stack that 11575were allocated after the ``llvm.stacksave`` was executed. 11576 11577.. _int_stackrestore: 11578 11579'``llvm.stackrestore``' Intrinsic 11580^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11581 11582Syntax: 11583""""""" 11584 11585:: 11586 11587 declare void @llvm.stackrestore(i8* %ptr) 11588 11589Overview: 11590""""""""" 11591 11592The '``llvm.stackrestore``' intrinsic is used to restore the state of 11593the function stack to the state it was in when the corresponding 11594:ref:`llvm.stacksave <int_stacksave>` intrinsic executed. This is 11595useful for implementing language features like scoped automatic variable 11596sized arrays in C99. 11597 11598Semantics: 11599"""""""""" 11600 11601See the description for :ref:`llvm.stacksave <int_stacksave>`. 11602 11603.. _int_get_dynamic_area_offset: 11604 11605'``llvm.get.dynamic.area.offset``' Intrinsic 11606^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11607 11608Syntax: 11609""""""" 11610 11611:: 11612 11613 declare i32 @llvm.get.dynamic.area.offset.i32() 11614 declare i64 @llvm.get.dynamic.area.offset.i64() 11615 11616Overview: 11617""""""""" 11618 11619 The '``llvm.get.dynamic.area.offset.*``' intrinsic family is used to 11620 get the offset from native stack pointer to the address of the most 11621 recent dynamic alloca on the caller's stack. These intrinsics are 11622 intendend for use in combination with 11623 :ref:`llvm.stacksave <int_stacksave>` to get a 11624 pointer to the most recent dynamic alloca. This is useful, for example, 11625 for AddressSanitizer's stack unpoisoning routines. 11626 11627Semantics: 11628"""""""""" 11629 11630 These intrinsics return a non-negative integer value that can be used to 11631 get the address of the most recent dynamic alloca, allocated by :ref:`alloca <i_alloca>` 11632 on the caller's stack. In particular, for targets where stack grows downwards, 11633 adding this offset to the native stack pointer would get the address of the most 11634 recent dynamic alloca. For targets where stack grows upwards, the situation is a bit more 11635 complicated, because subtracting this value from stack pointer would get the address 11636 one past the end of the most recent dynamic alloca. 11637 11638 Although for most targets `llvm.get.dynamic.area.offset <int_get_dynamic_area_offset>` 11639 returns just a zero, for others, such as PowerPC and PowerPC64, it returns a 11640 compile-time-known constant value. 11641 11642 The return value type of :ref:`llvm.get.dynamic.area.offset <int_get_dynamic_area_offset>` 11643 must match the target's default address space's (address space 0) pointer type. 11644 11645'``llvm.prefetch``' Intrinsic 11646^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11647 11648Syntax: 11649""""""" 11650 11651:: 11652 11653 declare void @llvm.prefetch(i8* <address>, i32 <rw>, i32 <locality>, i32 <cache type>) 11654 11655Overview: 11656""""""""" 11657 11658The '``llvm.prefetch``' intrinsic is a hint to the code generator to 11659insert a prefetch instruction if supported; otherwise, it is a noop. 11660Prefetches have no effect on the behavior of the program but can change 11661its performance characteristics. 11662 11663Arguments: 11664"""""""""" 11665 11666``address`` is the address to be prefetched, ``rw`` is the specifier 11667determining if the fetch should be for a read (0) or write (1), and 11668``locality`` is a temporal locality specifier ranging from (0) - no 11669locality, to (3) - extremely local keep in cache. The ``cache type`` 11670specifies whether the prefetch is performed on the data (1) or 11671instruction (0) cache. The ``rw``, ``locality`` and ``cache type`` 11672arguments must be constant integers. 11673 11674Semantics: 11675"""""""""" 11676 11677This intrinsic does not modify the behavior of the program. In 11678particular, prefetches cannot trap and do not produce a value. On 11679targets that support this intrinsic, the prefetch can provide hints to 11680the processor cache for better performance. 11681 11682'``llvm.pcmarker``' Intrinsic 11683^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11684 11685Syntax: 11686""""""" 11687 11688:: 11689 11690 declare void @llvm.pcmarker(i32 <id>) 11691 11692Overview: 11693""""""""" 11694 11695The '``llvm.pcmarker``' intrinsic is a method to export a Program 11696Counter (PC) in a region of code to simulators and other tools. The 11697method is target specific, but it is expected that the marker will use 11698exported symbols to transmit the PC of the marker. The marker makes no 11699guarantees that it will remain with any specific instruction after 11700optimizations. It is possible that the presence of a marker will inhibit 11701optimizations. The intended use is to be inserted after optimizations to 11702allow correlations of simulation runs. 11703 11704Arguments: 11705"""""""""" 11706 11707``id`` is a numerical id identifying the marker. 11708 11709Semantics: 11710"""""""""" 11711 11712This intrinsic does not modify the behavior of the program. Backends 11713that do not support this intrinsic may ignore it. 11714 11715'``llvm.readcyclecounter``' Intrinsic 11716^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11717 11718Syntax: 11719""""""" 11720 11721:: 11722 11723 declare i64 @llvm.readcyclecounter() 11724 11725Overview: 11726""""""""" 11727 11728The '``llvm.readcyclecounter``' intrinsic provides access to the cycle 11729counter register (or similar low latency, high accuracy clocks) on those 11730targets that support it. On X86, it should map to RDTSC. On Alpha, it 11731should map to RPCC. As the backing counters overflow quickly (on the 11732order of 9 seconds on alpha), this should only be used for small 11733timings. 11734 11735Semantics: 11736"""""""""" 11737 11738When directly supported, reading the cycle counter should not modify any 11739memory. Implementations are allowed to either return a application 11740specific value or a system wide value. On backends without support, this 11741is lowered to a constant 0. 11742 11743Note that runtime support may be conditional on the privilege-level code is 11744running at and the host platform. 11745 11746'``llvm.clear_cache``' Intrinsic 11747^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11748 11749Syntax: 11750""""""" 11751 11752:: 11753 11754 declare void @llvm.clear_cache(i8*, i8*) 11755 11756Overview: 11757""""""""" 11758 11759The '``llvm.clear_cache``' intrinsic ensures visibility of modifications 11760in the specified range to the execution unit of the processor. On 11761targets with non-unified instruction and data cache, the implementation 11762flushes the instruction cache. 11763 11764Semantics: 11765"""""""""" 11766 11767On platforms with coherent instruction and data caches (e.g. x86), this 11768intrinsic is a nop. On platforms with non-coherent instruction and data 11769cache (e.g. ARM, MIPS), the intrinsic is lowered either to appropriate 11770instructions or a system call, if cache flushing requires special 11771privileges. 11772 11773The default behavior is to emit a call to ``__clear_cache`` from the run 11774time library. 11775 11776This intrinsic does *not* empty the instruction pipeline. Modifications 11777of the current function are outside the scope of the intrinsic. 11778 11779'``llvm.instrprof.increment``' Intrinsic 11780^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11781 11782Syntax: 11783""""""" 11784 11785:: 11786 11787 declare void @llvm.instrprof.increment(i8* <name>, i64 <hash>, 11788 i32 <num-counters>, i32 <index>) 11789 11790Overview: 11791""""""""" 11792 11793The '``llvm.instrprof.increment``' intrinsic can be emitted by a 11794frontend for use with instrumentation based profiling. These will be 11795lowered by the ``-instrprof`` pass to generate execution counts of a 11796program at runtime. 11797 11798Arguments: 11799"""""""""" 11800 11801The first argument is a pointer to a global variable containing the 11802name of the entity being instrumented. This should generally be the 11803(mangled) function name for a set of counters. 11804 11805The second argument is a hash value that can be used by the consumer 11806of the profile data to detect changes to the instrumented source, and 11807the third is the number of counters associated with ``name``. It is an 11808error if ``hash`` or ``num-counters`` differ between two instances of 11809``instrprof.increment`` that refer to the same name. 11810 11811The last argument refers to which of the counters for ``name`` should 11812be incremented. It should be a value between 0 and ``num-counters``. 11813 11814Semantics: 11815"""""""""" 11816 11817This intrinsic represents an increment of a profiling counter. It will 11818cause the ``-instrprof`` pass to generate the appropriate data 11819structures and the code to increment the appropriate value, in a 11820format that can be written out by a compiler runtime and consumed via 11821the ``llvm-profdata`` tool. 11822 11823'``llvm.instrprof.increment.step``' Intrinsic 11824^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11825 11826Syntax: 11827""""""" 11828 11829:: 11830 11831 declare void @llvm.instrprof.increment.step(i8* <name>, i64 <hash>, 11832 i32 <num-counters>, 11833 i32 <index>, i64 <step>) 11834 11835Overview: 11836""""""""" 11837 11838The '``llvm.instrprof.increment.step``' intrinsic is an extension to 11839the '``llvm.instrprof.increment``' intrinsic with an additional fifth 11840argument to specify the step of the increment. 11841 11842Arguments: 11843"""""""""" 11844The first four arguments are the same as '``llvm.instrprof.increment``' 11845intrinsic. 11846 11847The last argument specifies the value of the increment of the counter variable. 11848 11849Semantics: 11850"""""""""" 11851See description of '``llvm.instrprof.increment``' intrinsic. 11852 11853 11854'``llvm.instrprof.value.profile``' Intrinsic 11855^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11856 11857Syntax: 11858""""""" 11859 11860:: 11861 11862 declare void @llvm.instrprof.value.profile(i8* <name>, i64 <hash>, 11863 i64 <value>, i32 <value_kind>, 11864 i32 <index>) 11865 11866Overview: 11867""""""""" 11868 11869The '``llvm.instrprof.value.profile``' intrinsic can be emitted by a 11870frontend for use with instrumentation based profiling. This will be 11871lowered by the ``-instrprof`` pass to find out the target values, 11872instrumented expressions take in a program at runtime. 11873 11874Arguments: 11875"""""""""" 11876 11877The first argument is a pointer to a global variable containing the 11878name of the entity being instrumented. ``name`` should generally be the 11879(mangled) function name for a set of counters. 11880 11881The second argument is a hash value that can be used by the consumer 11882of the profile data to detect changes to the instrumented source. It 11883is an error if ``hash`` differs between two instances of 11884``llvm.instrprof.*`` that refer to the same name. 11885 11886The third argument is the value of the expression being profiled. The profiled 11887expression's value should be representable as an unsigned 64-bit value. The 11888fourth argument represents the kind of value profiling that is being done. The 11889supported value profiling kinds are enumerated through the 11890``InstrProfValueKind`` type declared in the 11891``<include/llvm/ProfileData/InstrProf.h>`` header file. The last argument is the 11892index of the instrumented expression within ``name``. It should be >= 0. 11893 11894Semantics: 11895"""""""""" 11896 11897This intrinsic represents the point where a call to a runtime routine 11898should be inserted for value profiling of target expressions. ``-instrprof`` 11899pass will generate the appropriate data structures and replace the 11900``llvm.instrprof.value.profile`` intrinsic with the call to the profile 11901runtime library with proper arguments. 11902 11903'``llvm.thread.pointer``' Intrinsic 11904^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11905 11906Syntax: 11907""""""" 11908 11909:: 11910 11911 declare i8* @llvm.thread.pointer() 11912 11913Overview: 11914""""""""" 11915 11916The '``llvm.thread.pointer``' intrinsic returns the value of the thread 11917pointer. 11918 11919Semantics: 11920"""""""""" 11921 11922The '``llvm.thread.pointer``' intrinsic returns a pointer to the TLS area 11923for the current thread. The exact semantics of this value are target 11924specific: it may point to the start of TLS area, to the end, or somewhere 11925in the middle. Depending on the target, this intrinsic may read a register, 11926call a helper function, read from an alternate memory space, or perform 11927other operations necessary to locate the TLS area. Not all targets support 11928this intrinsic. 11929 11930'``llvm.call.preallocated.setup``' Intrinsic 11931^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11932 11933Syntax: 11934""""""" 11935 11936:: 11937 11938 declare token @llvm.call.preallocated.setup(i32 %num_args) 11939 11940Overview: 11941""""""""" 11942 11943The '``llvm.call.preallocated.setup``' intrinsic returns a token which can 11944be used with a call's ``"preallocated"`` operand bundle to indicate that 11945certain arguments are allocated and initialized before the call. 11946 11947Semantics: 11948"""""""""" 11949 11950The '``llvm.call.preallocated.setup``' intrinsic returns a token which is 11951associated with at most one call. The token can be passed to 11952'``@llvm.call.preallocated.arg``' to get a pointer to get that 11953corresponding argument. The token must be the parameter to a 11954``"preallocated"`` operand bundle for the corresponding call. 11955 11956Nested calls to '``llvm.call.preallocated.setup``' are allowed, but must 11957be properly nested. e.g. 11958 11959:: code-block:: llvm 11960 11961 %t1 = call token @llvm.call.preallocated.setup(i32 0) 11962 %t2 = call token @llvm.call.preallocated.setup(i32 0) 11963 call void foo() ["preallocated"(token %t2)] 11964 call void foo() ["preallocated"(token %t1)] 11965 11966is allowed, but not 11967 11968:: code-block:: llvm 11969 11970 %t1 = call token @llvm.call.preallocated.setup(i32 0) 11971 %t2 = call token @llvm.call.preallocated.setup(i32 0) 11972 call void foo() ["preallocated"(token %t1)] 11973 call void foo() ["preallocated"(token %t2)] 11974 11975.. _int_call_preallocated_arg: 11976 11977'``llvm.call.preallocated.arg``' Intrinsic 11978^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11979 11980Syntax: 11981""""""" 11982 11983:: 11984 11985 declare i8* @llvm.call.preallocated.arg(token %setup_token, i32 %arg_index) 11986 11987Overview: 11988""""""""" 11989 11990The '``llvm.call.preallocated.arg``' intrinsic returns a pointer to the 11991corresponding preallocated argument for the preallocated call. 11992 11993Semantics: 11994"""""""""" 11995 11996The '``llvm.call.preallocated.arg``' intrinsic returns a pointer to the 11997``%arg_index``th argument with the ``preallocated`` attribute for 11998the call associated with the ``%setup_token``, which must be from 11999'``llvm.call.preallocated.setup``'. 12000 12001A call to '``llvm.call.preallocated.arg``' must have a call site 12002``preallocated`` attribute. The type of the ``preallocated`` attribute must 12003match the type used by the ``preallocated`` attribute of the corresponding 12004argument at the preallocated call. The type is used in the case that an 12005``llvm.call.preallocated.setup`` does not have a corresponding call (e.g. due 12006to DCE), where otherwise we cannot know how large the arguments are. 12007 12008It is undefined behavior if this is called with a token from an 12009'``llvm.call.preallocated.setup``' if another 12010'``llvm.call.preallocated.setup``' has already been called or if the 12011preallocated call corresponding to the '``llvm.call.preallocated.setup``' 12012has already been called. 12013 12014Standard C Library Intrinsics 12015----------------------------- 12016 12017LLVM provides intrinsics for a few important standard C library 12018functions. These intrinsics allow source-language front-ends to pass 12019information about the alignment of the pointer arguments to the code 12020generator, providing opportunity for more efficient code generation. 12021 12022.. _int_memcpy: 12023 12024'``llvm.memcpy``' Intrinsic 12025^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12026 12027Syntax: 12028""""""" 12029 12030This is an overloaded intrinsic. You can use ``llvm.memcpy`` on any 12031integer bit width and for different address spaces. Not all targets 12032support all bit widths however. 12033 12034:: 12035 12036 declare void @llvm.memcpy.p0i8.p0i8.i32(i8* <dest>, i8* <src>, 12037 i32 <len>, i1 <isvolatile>) 12038 declare void @llvm.memcpy.p0i8.p0i8.i64(i8* <dest>, i8* <src>, 12039 i64 <len>, i1 <isvolatile>) 12040 12041Overview: 12042""""""""" 12043 12044The '``llvm.memcpy.*``' intrinsics copy a block of memory from the 12045source location to the destination location. 12046 12047Note that, unlike the standard libc function, the ``llvm.memcpy.*`` 12048intrinsics do not return a value, takes extra isvolatile 12049arguments and the pointers can be in specified address spaces. 12050 12051Arguments: 12052"""""""""" 12053 12054The first argument is a pointer to the destination, the second is a 12055pointer to the source. The third argument is an integer argument 12056specifying the number of bytes to copy, and the fourth is a 12057boolean indicating a volatile access. 12058 12059The :ref:`align <attr_align>` parameter attribute can be provided 12060for the first and second arguments. 12061 12062If the ``isvolatile`` parameter is ``true``, the ``llvm.memcpy`` call is 12063a :ref:`volatile operation <volatile>`. The detailed access behavior is not 12064very cleanly specified and it is unwise to depend on it. 12065 12066Semantics: 12067"""""""""" 12068 12069The '``llvm.memcpy.*``' intrinsics copy a block of memory from the 12070source location to the destination location, which are not allowed to 12071overlap. It copies "len" bytes of memory over. If the argument is known 12072to be aligned to some boundary, this can be specified as an attribute on 12073the argument. 12074 12075If "len" is 0, the pointers may be NULL or dangling. However, they must still 12076be appropriately aligned. 12077 12078.. _int_memcpy_inline: 12079 12080'``llvm.memcpy.inline``' Intrinsic 12081^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12082 12083Syntax: 12084""""""" 12085 12086This is an overloaded intrinsic. You can use ``llvm.memcpy.inline`` on any 12087integer bit width and for different address spaces. Not all targets 12088support all bit widths however. 12089 12090:: 12091 12092 declare void @llvm.memcpy.inline.p0i8.p0i8.i32(i8* <dest>, i8* <src>, 12093 i32 <len>, i1 <isvolatile>) 12094 declare void @llvm.memcpy.inline.p0i8.p0i8.i64(i8* <dest>, i8* <src>, 12095 i64 <len>, i1 <isvolatile>) 12096 12097Overview: 12098""""""""" 12099 12100The '``llvm.memcpy.inline.*``' intrinsics copy a block of memory from the 12101source location to the destination location and guarantees that no external 12102functions are called. 12103 12104Note that, unlike the standard libc function, the ``llvm.memcpy.inline.*`` 12105intrinsics do not return a value, takes extra isvolatile 12106arguments and the pointers can be in specified address spaces. 12107 12108Arguments: 12109"""""""""" 12110 12111The first argument is a pointer to the destination, the second is a 12112pointer to the source. The third argument is a constant integer argument 12113specifying the number of bytes to copy, and the fourth is a 12114boolean indicating a volatile access. 12115 12116The :ref:`align <attr_align>` parameter attribute can be provided 12117for the first and second arguments. 12118 12119If the ``isvolatile`` parameter is ``true``, the ``llvm.memcpy.inline`` call is 12120a :ref:`volatile operation <volatile>`. The detailed access behavior is not 12121very cleanly specified and it is unwise to depend on it. 12122 12123Semantics: 12124"""""""""" 12125 12126The '``llvm.memcpy.inline.*``' intrinsics copy a block of memory from the 12127source location to the destination location, which are not allowed to 12128overlap. It copies "len" bytes of memory over. If the argument is known 12129to be aligned to some boundary, this can be specified as an attribute on 12130the argument. 12131 12132If "len" is 0, the pointers may be NULL or dangling. However, they must still 12133be appropriately aligned. 12134 12135The generated code is guaranteed not to call any external functions. 12136 12137.. _int_memmove: 12138 12139'``llvm.memmove``' Intrinsic 12140^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12141 12142Syntax: 12143""""""" 12144 12145This is an overloaded intrinsic. You can use llvm.memmove on any integer 12146bit width and for different address space. Not all targets support all 12147bit widths however. 12148 12149:: 12150 12151 declare void @llvm.memmove.p0i8.p0i8.i32(i8* <dest>, i8* <src>, 12152 i32 <len>, i1 <isvolatile>) 12153 declare void @llvm.memmove.p0i8.p0i8.i64(i8* <dest>, i8* <src>, 12154 i64 <len>, i1 <isvolatile>) 12155 12156Overview: 12157""""""""" 12158 12159The '``llvm.memmove.*``' intrinsics move a block of memory from the 12160source location to the destination location. It is similar to the 12161'``llvm.memcpy``' intrinsic but allows the two memory locations to 12162overlap. 12163 12164Note that, unlike the standard libc function, the ``llvm.memmove.*`` 12165intrinsics do not return a value, takes an extra isvolatile 12166argument and the pointers can be in specified address spaces. 12167 12168Arguments: 12169"""""""""" 12170 12171The first argument is a pointer to the destination, the second is a 12172pointer to the source. The third argument is an integer argument 12173specifying the number of bytes to copy, and the fourth is a 12174boolean indicating a volatile access. 12175 12176The :ref:`align <attr_align>` parameter attribute can be provided 12177for the first and second arguments. 12178 12179If the ``isvolatile`` parameter is ``true``, the ``llvm.memmove`` call 12180is a :ref:`volatile operation <volatile>`. The detailed access behavior is 12181not very cleanly specified and it is unwise to depend on it. 12182 12183Semantics: 12184"""""""""" 12185 12186The '``llvm.memmove.*``' intrinsics copy a block of memory from the 12187source location to the destination location, which may overlap. It 12188copies "len" bytes of memory over. If the argument is known to be 12189aligned to some boundary, this can be specified as an attribute on 12190the argument. 12191 12192If "len" is 0, the pointers may be NULL or dangling. However, they must still 12193be appropriately aligned. 12194 12195.. _int_memset: 12196 12197'``llvm.memset.*``' Intrinsics 12198^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12199 12200Syntax: 12201""""""" 12202 12203This is an overloaded intrinsic. You can use llvm.memset on any integer 12204bit width and for different address spaces. However, not all targets 12205support all bit widths. 12206 12207:: 12208 12209 declare void @llvm.memset.p0i8.i32(i8* <dest>, i8 <val>, 12210 i32 <len>, i1 <isvolatile>) 12211 declare void @llvm.memset.p0i8.i64(i8* <dest>, i8 <val>, 12212 i64 <len>, i1 <isvolatile>) 12213 12214Overview: 12215""""""""" 12216 12217The '``llvm.memset.*``' intrinsics fill a block of memory with a 12218particular byte value. 12219 12220Note that, unlike the standard libc function, the ``llvm.memset`` 12221intrinsic does not return a value and takes an extra volatile 12222argument. Also, the destination can be in an arbitrary address space. 12223 12224Arguments: 12225"""""""""" 12226 12227The first argument is a pointer to the destination to fill, the second 12228is the byte value with which to fill it, the third argument is an 12229integer argument specifying the number of bytes to fill, and the fourth 12230is a boolean indicating a volatile access. 12231 12232The :ref:`align <attr_align>` parameter attribute can be provided 12233for the first arguments. 12234 12235If the ``isvolatile`` parameter is ``true``, the ``llvm.memset`` call is 12236a :ref:`volatile operation <volatile>`. The detailed access behavior is not 12237very cleanly specified and it is unwise to depend on it. 12238 12239Semantics: 12240"""""""""" 12241 12242The '``llvm.memset.*``' intrinsics fill "len" bytes of memory starting 12243at the destination location. If the argument is known to be 12244aligned to some boundary, this can be specified as an attribute on 12245the argument. 12246 12247If "len" is 0, the pointers may be NULL or dangling. However, they must still 12248be appropriately aligned. 12249 12250'``llvm.sqrt.*``' Intrinsic 12251^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12252 12253Syntax: 12254""""""" 12255 12256This is an overloaded intrinsic. You can use ``llvm.sqrt`` on any 12257floating-point or vector of floating-point type. Not all targets support 12258all types however. 12259 12260:: 12261 12262 declare float @llvm.sqrt.f32(float %Val) 12263 declare double @llvm.sqrt.f64(double %Val) 12264 declare x86_fp80 @llvm.sqrt.f80(x86_fp80 %Val) 12265 declare fp128 @llvm.sqrt.f128(fp128 %Val) 12266 declare ppc_fp128 @llvm.sqrt.ppcf128(ppc_fp128 %Val) 12267 12268Overview: 12269""""""""" 12270 12271The '``llvm.sqrt``' intrinsics return the square root of the specified value. 12272 12273Arguments: 12274"""""""""" 12275 12276The argument and return value are floating-point numbers of the same type. 12277 12278Semantics: 12279"""""""""" 12280 12281Return the same value as a corresponding libm '``sqrt``' function but without 12282trapping or setting ``errno``. For types specified by IEEE-754, the result 12283matches a conforming libm implementation. 12284 12285When specified with the fast-math-flag 'afn', the result may be approximated 12286using a less accurate calculation. 12287 12288'``llvm.powi.*``' Intrinsic 12289^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12290 12291Syntax: 12292""""""" 12293 12294This is an overloaded intrinsic. You can use ``llvm.powi`` on any 12295floating-point or vector of floating-point type. Not all targets support 12296all types however. 12297 12298:: 12299 12300 declare float @llvm.powi.f32(float %Val, i32 %power) 12301 declare double @llvm.powi.f64(double %Val, i32 %power) 12302 declare x86_fp80 @llvm.powi.f80(x86_fp80 %Val, i32 %power) 12303 declare fp128 @llvm.powi.f128(fp128 %Val, i32 %power) 12304 declare ppc_fp128 @llvm.powi.ppcf128(ppc_fp128 %Val, i32 %power) 12305 12306Overview: 12307""""""""" 12308 12309The '``llvm.powi.*``' intrinsics return the first operand raised to the 12310specified (positive or negative) power. The order of evaluation of 12311multiplications is not defined. When a vector of floating-point type is 12312used, the second argument remains a scalar integer value. 12313 12314Arguments: 12315"""""""""" 12316 12317The second argument is an integer power, and the first is a value to 12318raise to that power. 12319 12320Semantics: 12321"""""""""" 12322 12323This function returns the first value raised to the second power with an 12324unspecified sequence of rounding operations. 12325 12326'``llvm.sin.*``' Intrinsic 12327^^^^^^^^^^^^^^^^^^^^^^^^^^ 12328 12329Syntax: 12330""""""" 12331 12332This is an overloaded intrinsic. You can use ``llvm.sin`` on any 12333floating-point or vector of floating-point type. Not all targets support 12334all types however. 12335 12336:: 12337 12338 declare float @llvm.sin.f32(float %Val) 12339 declare double @llvm.sin.f64(double %Val) 12340 declare x86_fp80 @llvm.sin.f80(x86_fp80 %Val) 12341 declare fp128 @llvm.sin.f128(fp128 %Val) 12342 declare ppc_fp128 @llvm.sin.ppcf128(ppc_fp128 %Val) 12343 12344Overview: 12345""""""""" 12346 12347The '``llvm.sin.*``' intrinsics return the sine of the operand. 12348 12349Arguments: 12350"""""""""" 12351 12352The argument and return value are floating-point numbers of the same type. 12353 12354Semantics: 12355"""""""""" 12356 12357Return the same value as a corresponding libm '``sin``' function but without 12358trapping or setting ``errno``. 12359 12360When specified with the fast-math-flag 'afn', the result may be approximated 12361using a less accurate calculation. 12362 12363'``llvm.cos.*``' Intrinsic 12364^^^^^^^^^^^^^^^^^^^^^^^^^^ 12365 12366Syntax: 12367""""""" 12368 12369This is an overloaded intrinsic. You can use ``llvm.cos`` on any 12370floating-point or vector of floating-point type. Not all targets support 12371all types however. 12372 12373:: 12374 12375 declare float @llvm.cos.f32(float %Val) 12376 declare double @llvm.cos.f64(double %Val) 12377 declare x86_fp80 @llvm.cos.f80(x86_fp80 %Val) 12378 declare fp128 @llvm.cos.f128(fp128 %Val) 12379 declare ppc_fp128 @llvm.cos.ppcf128(ppc_fp128 %Val) 12380 12381Overview: 12382""""""""" 12383 12384The '``llvm.cos.*``' intrinsics return the cosine of the operand. 12385 12386Arguments: 12387"""""""""" 12388 12389The argument and return value are floating-point numbers of the same type. 12390 12391Semantics: 12392"""""""""" 12393 12394Return the same value as a corresponding libm '``cos``' function but without 12395trapping or setting ``errno``. 12396 12397When specified with the fast-math-flag 'afn', the result may be approximated 12398using a less accurate calculation. 12399 12400'``llvm.pow.*``' Intrinsic 12401^^^^^^^^^^^^^^^^^^^^^^^^^^ 12402 12403Syntax: 12404""""""" 12405 12406This is an overloaded intrinsic. You can use ``llvm.pow`` on any 12407floating-point or vector of floating-point type. Not all targets support 12408all types however. 12409 12410:: 12411 12412 declare float @llvm.pow.f32(float %Val, float %Power) 12413 declare double @llvm.pow.f64(double %Val, double %Power) 12414 declare x86_fp80 @llvm.pow.f80(x86_fp80 %Val, x86_fp80 %Power) 12415 declare fp128 @llvm.pow.f128(fp128 %Val, fp128 %Power) 12416 declare ppc_fp128 @llvm.pow.ppcf128(ppc_fp128 %Val, ppc_fp128 Power) 12417 12418Overview: 12419""""""""" 12420 12421The '``llvm.pow.*``' intrinsics return the first operand raised to the 12422specified (positive or negative) power. 12423 12424Arguments: 12425"""""""""" 12426 12427The arguments and return value are floating-point numbers of the same type. 12428 12429Semantics: 12430"""""""""" 12431 12432Return the same value as a corresponding libm '``pow``' function but without 12433trapping or setting ``errno``. 12434 12435When specified with the fast-math-flag 'afn', the result may be approximated 12436using a less accurate calculation. 12437 12438'``llvm.exp.*``' Intrinsic 12439^^^^^^^^^^^^^^^^^^^^^^^^^^ 12440 12441Syntax: 12442""""""" 12443 12444This is an overloaded intrinsic. You can use ``llvm.exp`` on any 12445floating-point or vector of floating-point type. Not all targets support 12446all types however. 12447 12448:: 12449 12450 declare float @llvm.exp.f32(float %Val) 12451 declare double @llvm.exp.f64(double %Val) 12452 declare x86_fp80 @llvm.exp.f80(x86_fp80 %Val) 12453 declare fp128 @llvm.exp.f128(fp128 %Val) 12454 declare ppc_fp128 @llvm.exp.ppcf128(ppc_fp128 %Val) 12455 12456Overview: 12457""""""""" 12458 12459The '``llvm.exp.*``' intrinsics compute the base-e exponential of the specified 12460value. 12461 12462Arguments: 12463"""""""""" 12464 12465The argument and return value are floating-point numbers of the same type. 12466 12467Semantics: 12468"""""""""" 12469 12470Return the same value as a corresponding libm '``exp``' function but without 12471trapping or setting ``errno``. 12472 12473When specified with the fast-math-flag 'afn', the result may be approximated 12474using a less accurate calculation. 12475 12476'``llvm.exp2.*``' Intrinsic 12477^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12478 12479Syntax: 12480""""""" 12481 12482This is an overloaded intrinsic. You can use ``llvm.exp2`` on any 12483floating-point or vector of floating-point type. Not all targets support 12484all types however. 12485 12486:: 12487 12488 declare float @llvm.exp2.f32(float %Val) 12489 declare double @llvm.exp2.f64(double %Val) 12490 declare x86_fp80 @llvm.exp2.f80(x86_fp80 %Val) 12491 declare fp128 @llvm.exp2.f128(fp128 %Val) 12492 declare ppc_fp128 @llvm.exp2.ppcf128(ppc_fp128 %Val) 12493 12494Overview: 12495""""""""" 12496 12497The '``llvm.exp2.*``' intrinsics compute the base-2 exponential of the 12498specified value. 12499 12500Arguments: 12501"""""""""" 12502 12503The argument and return value are floating-point numbers of the same type. 12504 12505Semantics: 12506"""""""""" 12507 12508Return the same value as a corresponding libm '``exp2``' function but without 12509trapping or setting ``errno``. 12510 12511When specified with the fast-math-flag 'afn', the result may be approximated 12512using a less accurate calculation. 12513 12514'``llvm.log.*``' Intrinsic 12515^^^^^^^^^^^^^^^^^^^^^^^^^^ 12516 12517Syntax: 12518""""""" 12519 12520This is an overloaded intrinsic. You can use ``llvm.log`` on any 12521floating-point or vector of floating-point type. Not all targets support 12522all types however. 12523 12524:: 12525 12526 declare float @llvm.log.f32(float %Val) 12527 declare double @llvm.log.f64(double %Val) 12528 declare x86_fp80 @llvm.log.f80(x86_fp80 %Val) 12529 declare fp128 @llvm.log.f128(fp128 %Val) 12530 declare ppc_fp128 @llvm.log.ppcf128(ppc_fp128 %Val) 12531 12532Overview: 12533""""""""" 12534 12535The '``llvm.log.*``' intrinsics compute the base-e logarithm of the specified 12536value. 12537 12538Arguments: 12539"""""""""" 12540 12541The argument and return value are floating-point numbers of the same type. 12542 12543Semantics: 12544"""""""""" 12545 12546Return the same value as a corresponding libm '``log``' function but without 12547trapping or setting ``errno``. 12548 12549When specified with the fast-math-flag 'afn', the result may be approximated 12550using a less accurate calculation. 12551 12552'``llvm.log10.*``' Intrinsic 12553^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12554 12555Syntax: 12556""""""" 12557 12558This is an overloaded intrinsic. You can use ``llvm.log10`` on any 12559floating-point or vector of floating-point type. Not all targets support 12560all types however. 12561 12562:: 12563 12564 declare float @llvm.log10.f32(float %Val) 12565 declare double @llvm.log10.f64(double %Val) 12566 declare x86_fp80 @llvm.log10.f80(x86_fp80 %Val) 12567 declare fp128 @llvm.log10.f128(fp128 %Val) 12568 declare ppc_fp128 @llvm.log10.ppcf128(ppc_fp128 %Val) 12569 12570Overview: 12571""""""""" 12572 12573The '``llvm.log10.*``' intrinsics compute the base-10 logarithm of the 12574specified value. 12575 12576Arguments: 12577"""""""""" 12578 12579The argument and return value are floating-point numbers of the same type. 12580 12581Semantics: 12582"""""""""" 12583 12584Return the same value as a corresponding libm '``log10``' function but without 12585trapping or setting ``errno``. 12586 12587When specified with the fast-math-flag 'afn', the result may be approximated 12588using a less accurate calculation. 12589 12590'``llvm.log2.*``' Intrinsic 12591^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12592 12593Syntax: 12594""""""" 12595 12596This is an overloaded intrinsic. You can use ``llvm.log2`` on any 12597floating-point or vector of floating-point type. Not all targets support 12598all types however. 12599 12600:: 12601 12602 declare float @llvm.log2.f32(float %Val) 12603 declare double @llvm.log2.f64(double %Val) 12604 declare x86_fp80 @llvm.log2.f80(x86_fp80 %Val) 12605 declare fp128 @llvm.log2.f128(fp128 %Val) 12606 declare ppc_fp128 @llvm.log2.ppcf128(ppc_fp128 %Val) 12607 12608Overview: 12609""""""""" 12610 12611The '``llvm.log2.*``' intrinsics compute the base-2 logarithm of the specified 12612value. 12613 12614Arguments: 12615"""""""""" 12616 12617The argument and return value are floating-point numbers of the same type. 12618 12619Semantics: 12620"""""""""" 12621 12622Return the same value as a corresponding libm '``log2``' function but without 12623trapping or setting ``errno``. 12624 12625When specified with the fast-math-flag 'afn', the result may be approximated 12626using a less accurate calculation. 12627 12628.. _int_fma: 12629 12630'``llvm.fma.*``' Intrinsic 12631^^^^^^^^^^^^^^^^^^^^^^^^^^ 12632 12633Syntax: 12634""""""" 12635 12636This is an overloaded intrinsic. You can use ``llvm.fma`` on any 12637floating-point or vector of floating-point type. Not all targets support 12638all types however. 12639 12640:: 12641 12642 declare float @llvm.fma.f32(float %a, float %b, float %c) 12643 declare double @llvm.fma.f64(double %a, double %b, double %c) 12644 declare x86_fp80 @llvm.fma.f80(x86_fp80 %a, x86_fp80 %b, x86_fp80 %c) 12645 declare fp128 @llvm.fma.f128(fp128 %a, fp128 %b, fp128 %c) 12646 declare ppc_fp128 @llvm.fma.ppcf128(ppc_fp128 %a, ppc_fp128 %b, ppc_fp128 %c) 12647 12648Overview: 12649""""""""" 12650 12651The '``llvm.fma.*``' intrinsics perform the fused multiply-add operation. 12652 12653Arguments: 12654"""""""""" 12655 12656The arguments and return value are floating-point numbers of the same type. 12657 12658Semantics: 12659"""""""""" 12660 12661Return the same value as a corresponding libm '``fma``' function but without 12662trapping or setting ``errno``. 12663 12664When specified with the fast-math-flag 'afn', the result may be approximated 12665using a less accurate calculation. 12666 12667'``llvm.fabs.*``' Intrinsic 12668^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12669 12670Syntax: 12671""""""" 12672 12673This is an overloaded intrinsic. You can use ``llvm.fabs`` on any 12674floating-point or vector of floating-point type. Not all targets support 12675all types however. 12676 12677:: 12678 12679 declare float @llvm.fabs.f32(float %Val) 12680 declare double @llvm.fabs.f64(double %Val) 12681 declare x86_fp80 @llvm.fabs.f80(x86_fp80 %Val) 12682 declare fp128 @llvm.fabs.f128(fp128 %Val) 12683 declare ppc_fp128 @llvm.fabs.ppcf128(ppc_fp128 %Val) 12684 12685Overview: 12686""""""""" 12687 12688The '``llvm.fabs.*``' intrinsics return the absolute value of the 12689operand. 12690 12691Arguments: 12692"""""""""" 12693 12694The argument and return value are floating-point numbers of the same 12695type. 12696 12697Semantics: 12698"""""""""" 12699 12700This function returns the same values as the libm ``fabs`` functions 12701would, and handles error conditions in the same way. 12702 12703'``llvm.minnum.*``' Intrinsic 12704^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12705 12706Syntax: 12707""""""" 12708 12709This is an overloaded intrinsic. You can use ``llvm.minnum`` on any 12710floating-point or vector of floating-point type. Not all targets support 12711all types however. 12712 12713:: 12714 12715 declare float @llvm.minnum.f32(float %Val0, float %Val1) 12716 declare double @llvm.minnum.f64(double %Val0, double %Val1) 12717 declare x86_fp80 @llvm.minnum.f80(x86_fp80 %Val0, x86_fp80 %Val1) 12718 declare fp128 @llvm.minnum.f128(fp128 %Val0, fp128 %Val1) 12719 declare ppc_fp128 @llvm.minnum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1) 12720 12721Overview: 12722""""""""" 12723 12724The '``llvm.minnum.*``' intrinsics return the minimum of the two 12725arguments. 12726 12727 12728Arguments: 12729"""""""""" 12730 12731The arguments and return value are floating-point numbers of the same 12732type. 12733 12734Semantics: 12735"""""""""" 12736 12737Follows the IEEE-754 semantics for minNum, except for handling of 12738signaling NaNs. This match's the behavior of libm's fmin. 12739 12740If either operand is a NaN, returns the other non-NaN operand. Returns 12741NaN only if both operands are NaN. The returned NaN is always 12742quiet. If the operands compare equal, returns a value that compares 12743equal to both operands. This means that fmin(+/-0.0, +/-0.0) could 12744return either -0.0 or 0.0. 12745 12746Unlike the IEEE-754 2008 behavior, this does not distinguish between 12747signaling and quiet NaN inputs. If a target's implementation follows 12748the standard and returns a quiet NaN if either input is a signaling 12749NaN, the intrinsic lowering is responsible for quieting the inputs to 12750correctly return the non-NaN input (e.g. by using the equivalent of 12751``llvm.canonicalize``). 12752 12753 12754'``llvm.maxnum.*``' Intrinsic 12755^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12756 12757Syntax: 12758""""""" 12759 12760This is an overloaded intrinsic. You can use ``llvm.maxnum`` on any 12761floating-point or vector of floating-point type. Not all targets support 12762all types however. 12763 12764:: 12765 12766 declare float @llvm.maxnum.f32(float %Val0, float %Val1l) 12767 declare double @llvm.maxnum.f64(double %Val0, double %Val1) 12768 declare x86_fp80 @llvm.maxnum.f80(x86_fp80 %Val0, x86_fp80 %Val1) 12769 declare fp128 @llvm.maxnum.f128(fp128 %Val0, fp128 %Val1) 12770 declare ppc_fp128 @llvm.maxnum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1) 12771 12772Overview: 12773""""""""" 12774 12775The '``llvm.maxnum.*``' intrinsics return the maximum of the two 12776arguments. 12777 12778 12779Arguments: 12780"""""""""" 12781 12782The arguments and return value are floating-point numbers of the same 12783type. 12784 12785Semantics: 12786"""""""""" 12787Follows the IEEE-754 semantics for maxNum except for the handling of 12788signaling NaNs. This matches the behavior of libm's fmax. 12789 12790If either operand is a NaN, returns the other non-NaN operand. Returns 12791NaN only if both operands are NaN. The returned NaN is always 12792quiet. If the operands compare equal, returns a value that compares 12793equal to both operands. This means that fmax(+/-0.0, +/-0.0) could 12794return either -0.0 or 0.0. 12795 12796Unlike the IEEE-754 2008 behavior, this does not distinguish between 12797signaling and quiet NaN inputs. If a target's implementation follows 12798the standard and returns a quiet NaN if either input is a signaling 12799NaN, the intrinsic lowering is responsible for quieting the inputs to 12800correctly return the non-NaN input (e.g. by using the equivalent of 12801``llvm.canonicalize``). 12802 12803'``llvm.minimum.*``' Intrinsic 12804^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12805 12806Syntax: 12807""""""" 12808 12809This is an overloaded intrinsic. You can use ``llvm.minimum`` on any 12810floating-point or vector of floating-point type. Not all targets support 12811all types however. 12812 12813:: 12814 12815 declare float @llvm.minimum.f32(float %Val0, float %Val1) 12816 declare double @llvm.minimum.f64(double %Val0, double %Val1) 12817 declare x86_fp80 @llvm.minimum.f80(x86_fp80 %Val0, x86_fp80 %Val1) 12818 declare fp128 @llvm.minimum.f128(fp128 %Val0, fp128 %Val1) 12819 declare ppc_fp128 @llvm.minimum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1) 12820 12821Overview: 12822""""""""" 12823 12824The '``llvm.minimum.*``' intrinsics return the minimum of the two 12825arguments, propagating NaNs and treating -0.0 as less than +0.0. 12826 12827 12828Arguments: 12829"""""""""" 12830 12831The arguments and return value are floating-point numbers of the same 12832type. 12833 12834Semantics: 12835"""""""""" 12836If either operand is a NaN, returns NaN. Otherwise returns the lesser 12837of the two arguments. -0.0 is considered to be less than +0.0 for this 12838intrinsic. Note that these are the semantics specified in the draft of 12839IEEE 754-2018. 12840 12841'``llvm.maximum.*``' Intrinsic 12842^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12843 12844Syntax: 12845""""""" 12846 12847This is an overloaded intrinsic. You can use ``llvm.maximum`` on any 12848floating-point or vector of floating-point type. Not all targets support 12849all types however. 12850 12851:: 12852 12853 declare float @llvm.maximum.f32(float %Val0, float %Val1) 12854 declare double @llvm.maximum.f64(double %Val0, double %Val1) 12855 declare x86_fp80 @llvm.maximum.f80(x86_fp80 %Val0, x86_fp80 %Val1) 12856 declare fp128 @llvm.maximum.f128(fp128 %Val0, fp128 %Val1) 12857 declare ppc_fp128 @llvm.maximum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1) 12858 12859Overview: 12860""""""""" 12861 12862The '``llvm.maximum.*``' intrinsics return the maximum of the two 12863arguments, propagating NaNs and treating -0.0 as less than +0.0. 12864 12865 12866Arguments: 12867"""""""""" 12868 12869The arguments and return value are floating-point numbers of the same 12870type. 12871 12872Semantics: 12873"""""""""" 12874If either operand is a NaN, returns NaN. Otherwise returns the greater 12875of the two arguments. -0.0 is considered to be less than +0.0 for this 12876intrinsic. Note that these are the semantics specified in the draft of 12877IEEE 754-2018. 12878 12879'``llvm.copysign.*``' Intrinsic 12880^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12881 12882Syntax: 12883""""""" 12884 12885This is an overloaded intrinsic. You can use ``llvm.copysign`` on any 12886floating-point or vector of floating-point type. Not all targets support 12887all types however. 12888 12889:: 12890 12891 declare float @llvm.copysign.f32(float %Mag, float %Sgn) 12892 declare double @llvm.copysign.f64(double %Mag, double %Sgn) 12893 declare x86_fp80 @llvm.copysign.f80(x86_fp80 %Mag, x86_fp80 %Sgn) 12894 declare fp128 @llvm.copysign.f128(fp128 %Mag, fp128 %Sgn) 12895 declare ppc_fp128 @llvm.copysign.ppcf128(ppc_fp128 %Mag, ppc_fp128 %Sgn) 12896 12897Overview: 12898""""""""" 12899 12900The '``llvm.copysign.*``' intrinsics return a value with the magnitude of the 12901first operand and the sign of the second operand. 12902 12903Arguments: 12904"""""""""" 12905 12906The arguments and return value are floating-point numbers of the same 12907type. 12908 12909Semantics: 12910"""""""""" 12911 12912This function returns the same values as the libm ``copysign`` 12913functions would, and handles error conditions in the same way. 12914 12915'``llvm.floor.*``' Intrinsic 12916^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12917 12918Syntax: 12919""""""" 12920 12921This is an overloaded intrinsic. You can use ``llvm.floor`` on any 12922floating-point or vector of floating-point type. Not all targets support 12923all types however. 12924 12925:: 12926 12927 declare float @llvm.floor.f32(float %Val) 12928 declare double @llvm.floor.f64(double %Val) 12929 declare x86_fp80 @llvm.floor.f80(x86_fp80 %Val) 12930 declare fp128 @llvm.floor.f128(fp128 %Val) 12931 declare ppc_fp128 @llvm.floor.ppcf128(ppc_fp128 %Val) 12932 12933Overview: 12934""""""""" 12935 12936The '``llvm.floor.*``' intrinsics return the floor of the operand. 12937 12938Arguments: 12939"""""""""" 12940 12941The argument and return value are floating-point numbers of the same 12942type. 12943 12944Semantics: 12945"""""""""" 12946 12947This function returns the same values as the libm ``floor`` functions 12948would, and handles error conditions in the same way. 12949 12950'``llvm.ceil.*``' Intrinsic 12951^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12952 12953Syntax: 12954""""""" 12955 12956This is an overloaded intrinsic. You can use ``llvm.ceil`` on any 12957floating-point or vector of floating-point type. Not all targets support 12958all types however. 12959 12960:: 12961 12962 declare float @llvm.ceil.f32(float %Val) 12963 declare double @llvm.ceil.f64(double %Val) 12964 declare x86_fp80 @llvm.ceil.f80(x86_fp80 %Val) 12965 declare fp128 @llvm.ceil.f128(fp128 %Val) 12966 declare ppc_fp128 @llvm.ceil.ppcf128(ppc_fp128 %Val) 12967 12968Overview: 12969""""""""" 12970 12971The '``llvm.ceil.*``' intrinsics return the ceiling of the operand. 12972 12973Arguments: 12974"""""""""" 12975 12976The argument and return value are floating-point numbers of the same 12977type. 12978 12979Semantics: 12980"""""""""" 12981 12982This function returns the same values as the libm ``ceil`` functions 12983would, and handles error conditions in the same way. 12984 12985'``llvm.trunc.*``' Intrinsic 12986^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12987 12988Syntax: 12989""""""" 12990 12991This is an overloaded intrinsic. You can use ``llvm.trunc`` on any 12992floating-point or vector of floating-point type. Not all targets support 12993all types however. 12994 12995:: 12996 12997 declare float @llvm.trunc.f32(float %Val) 12998 declare double @llvm.trunc.f64(double %Val) 12999 declare x86_fp80 @llvm.trunc.f80(x86_fp80 %Val) 13000 declare fp128 @llvm.trunc.f128(fp128 %Val) 13001 declare ppc_fp128 @llvm.trunc.ppcf128(ppc_fp128 %Val) 13002 13003Overview: 13004""""""""" 13005 13006The '``llvm.trunc.*``' intrinsics returns the operand rounded to the 13007nearest integer not larger in magnitude than the operand. 13008 13009Arguments: 13010"""""""""" 13011 13012The argument and return value are floating-point numbers of the same 13013type. 13014 13015Semantics: 13016"""""""""" 13017 13018This function returns the same values as the libm ``trunc`` functions 13019would, and handles error conditions in the same way. 13020 13021'``llvm.rint.*``' Intrinsic 13022^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13023 13024Syntax: 13025""""""" 13026 13027This is an overloaded intrinsic. You can use ``llvm.rint`` on any 13028floating-point or vector of floating-point type. Not all targets support 13029all types however. 13030 13031:: 13032 13033 declare float @llvm.rint.f32(float %Val) 13034 declare double @llvm.rint.f64(double %Val) 13035 declare x86_fp80 @llvm.rint.f80(x86_fp80 %Val) 13036 declare fp128 @llvm.rint.f128(fp128 %Val) 13037 declare ppc_fp128 @llvm.rint.ppcf128(ppc_fp128 %Val) 13038 13039Overview: 13040""""""""" 13041 13042The '``llvm.rint.*``' intrinsics returns the operand rounded to the 13043nearest integer. It may raise an inexact floating-point exception if the 13044operand isn't an integer. 13045 13046Arguments: 13047"""""""""" 13048 13049The argument and return value are floating-point numbers of the same 13050type. 13051 13052Semantics: 13053"""""""""" 13054 13055This function returns the same values as the libm ``rint`` functions 13056would, and handles error conditions in the same way. 13057 13058'``llvm.nearbyint.*``' Intrinsic 13059^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13060 13061Syntax: 13062""""""" 13063 13064This is an overloaded intrinsic. You can use ``llvm.nearbyint`` on any 13065floating-point or vector of floating-point type. Not all targets support 13066all types however. 13067 13068:: 13069 13070 declare float @llvm.nearbyint.f32(float %Val) 13071 declare double @llvm.nearbyint.f64(double %Val) 13072 declare x86_fp80 @llvm.nearbyint.f80(x86_fp80 %Val) 13073 declare fp128 @llvm.nearbyint.f128(fp128 %Val) 13074 declare ppc_fp128 @llvm.nearbyint.ppcf128(ppc_fp128 %Val) 13075 13076Overview: 13077""""""""" 13078 13079The '``llvm.nearbyint.*``' intrinsics returns the operand rounded to the 13080nearest integer. 13081 13082Arguments: 13083"""""""""" 13084 13085The argument and return value are floating-point numbers of the same 13086type. 13087 13088Semantics: 13089"""""""""" 13090 13091This function returns the same values as the libm ``nearbyint`` 13092functions would, and handles error conditions in the same way. 13093 13094'``llvm.round.*``' Intrinsic 13095^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13096 13097Syntax: 13098""""""" 13099 13100This is an overloaded intrinsic. You can use ``llvm.round`` on any 13101floating-point or vector of floating-point type. Not all targets support 13102all types however. 13103 13104:: 13105 13106 declare float @llvm.round.f32(float %Val) 13107 declare double @llvm.round.f64(double %Val) 13108 declare x86_fp80 @llvm.round.f80(x86_fp80 %Val) 13109 declare fp128 @llvm.round.f128(fp128 %Val) 13110 declare ppc_fp128 @llvm.round.ppcf128(ppc_fp128 %Val) 13111 13112Overview: 13113""""""""" 13114 13115The '``llvm.round.*``' intrinsics returns the operand rounded to the 13116nearest integer. 13117 13118Arguments: 13119"""""""""" 13120 13121The argument and return value are floating-point numbers of the same 13122type. 13123 13124Semantics: 13125"""""""""" 13126 13127This function returns the same values as the libm ``round`` 13128functions would, and handles error conditions in the same way. 13129 13130'``llvm.lround.*``' Intrinsic 13131^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13132 13133Syntax: 13134""""""" 13135 13136This is an overloaded intrinsic. You can use ``llvm.lround`` on any 13137floating-point type. Not all targets support all types however. 13138 13139:: 13140 13141 declare i32 @llvm.lround.i32.f32(float %Val) 13142 declare i32 @llvm.lround.i32.f64(double %Val) 13143 declare i32 @llvm.lround.i32.f80(float %Val) 13144 declare i32 @llvm.lround.i32.f128(double %Val) 13145 declare i32 @llvm.lround.i32.ppcf128(double %Val) 13146 13147 declare i64 @llvm.lround.i64.f32(float %Val) 13148 declare i64 @llvm.lround.i64.f64(double %Val) 13149 declare i64 @llvm.lround.i64.f80(float %Val) 13150 declare i64 @llvm.lround.i64.f128(double %Val) 13151 declare i64 @llvm.lround.i64.ppcf128(double %Val) 13152 13153Overview: 13154""""""""" 13155 13156The '``llvm.lround.*``' intrinsics return the operand rounded to the nearest 13157integer with ties away from zero. 13158 13159 13160Arguments: 13161"""""""""" 13162 13163The argument is a floating-point number and the return value is an integer 13164type. 13165 13166Semantics: 13167"""""""""" 13168 13169This function returns the same values as the libm ``lround`` 13170functions would, but without setting errno. 13171 13172'``llvm.llround.*``' Intrinsic 13173^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13174 13175Syntax: 13176""""""" 13177 13178This is an overloaded intrinsic. You can use ``llvm.llround`` on any 13179floating-point type. Not all targets support all types however. 13180 13181:: 13182 13183 declare i64 @llvm.lround.i64.f32(float %Val) 13184 declare i64 @llvm.lround.i64.f64(double %Val) 13185 declare i64 @llvm.lround.i64.f80(float %Val) 13186 declare i64 @llvm.lround.i64.f128(double %Val) 13187 declare i64 @llvm.lround.i64.ppcf128(double %Val) 13188 13189Overview: 13190""""""""" 13191 13192The '``llvm.llround.*``' intrinsics return the operand rounded to the nearest 13193integer with ties away from zero. 13194 13195Arguments: 13196"""""""""" 13197 13198The argument is a floating-point number and the return value is an integer 13199type. 13200 13201Semantics: 13202"""""""""" 13203 13204This function returns the same values as the libm ``llround`` 13205functions would, but without setting errno. 13206 13207'``llvm.lrint.*``' Intrinsic 13208^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13209 13210Syntax: 13211""""""" 13212 13213This is an overloaded intrinsic. You can use ``llvm.lrint`` on any 13214floating-point type. Not all targets support all types however. 13215 13216:: 13217 13218 declare i32 @llvm.lrint.i32.f32(float %Val) 13219 declare i32 @llvm.lrint.i32.f64(double %Val) 13220 declare i32 @llvm.lrint.i32.f80(float %Val) 13221 declare i32 @llvm.lrint.i32.f128(double %Val) 13222 declare i32 @llvm.lrint.i32.ppcf128(double %Val) 13223 13224 declare i64 @llvm.lrint.i64.f32(float %Val) 13225 declare i64 @llvm.lrint.i64.f64(double %Val) 13226 declare i64 @llvm.lrint.i64.f80(float %Val) 13227 declare i64 @llvm.lrint.i64.f128(double %Val) 13228 declare i64 @llvm.lrint.i64.ppcf128(double %Val) 13229 13230Overview: 13231""""""""" 13232 13233The '``llvm.lrint.*``' intrinsics return the operand rounded to the nearest 13234integer. 13235 13236 13237Arguments: 13238"""""""""" 13239 13240The argument is a floating-point number and the return value is an integer 13241type. 13242 13243Semantics: 13244"""""""""" 13245 13246This function returns the same values as the libm ``lrint`` 13247functions would, but without setting errno. 13248 13249'``llvm.llrint.*``' Intrinsic 13250^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13251 13252Syntax: 13253""""""" 13254 13255This is an overloaded intrinsic. You can use ``llvm.llrint`` on any 13256floating-point type. Not all targets support all types however. 13257 13258:: 13259 13260 declare i64 @llvm.llrint.i64.f32(float %Val) 13261 declare i64 @llvm.llrint.i64.f64(double %Val) 13262 declare i64 @llvm.llrint.i64.f80(float %Val) 13263 declare i64 @llvm.llrint.i64.f128(double %Val) 13264 declare i64 @llvm.llrint.i64.ppcf128(double %Val) 13265 13266Overview: 13267""""""""" 13268 13269The '``llvm.llrint.*``' intrinsics return the operand rounded to the nearest 13270integer. 13271 13272Arguments: 13273"""""""""" 13274 13275The argument is a floating-point number and the return value is an integer 13276type. 13277 13278Semantics: 13279"""""""""" 13280 13281This function returns the same values as the libm ``llrint`` 13282functions would, but without setting errno. 13283 13284Bit Manipulation Intrinsics 13285--------------------------- 13286 13287LLVM provides intrinsics for a few important bit manipulation 13288operations. These allow efficient code generation for some algorithms. 13289 13290'``llvm.bitreverse.*``' Intrinsics 13291^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13292 13293Syntax: 13294""""""" 13295 13296This is an overloaded intrinsic function. You can use bitreverse on any 13297integer type. 13298 13299:: 13300 13301 declare i16 @llvm.bitreverse.i16(i16 <id>) 13302 declare i32 @llvm.bitreverse.i32(i32 <id>) 13303 declare i64 @llvm.bitreverse.i64(i64 <id>) 13304 declare <4 x i32> @llvm.bitreverse.v4i32(<4 x i32> <id>) 13305 13306Overview: 13307""""""""" 13308 13309The '``llvm.bitreverse``' family of intrinsics is used to reverse the 13310bitpattern of an integer value or vector of integer values; for example 13311``0b10110110`` becomes ``0b01101101``. 13312 13313Semantics: 13314"""""""""" 13315 13316The ``llvm.bitreverse.iN`` intrinsic returns an iN value that has bit 13317``M`` in the input moved to bit ``N-M`` in the output. The vector 13318intrinsics, such as ``llvm.bitreverse.v4i32``, operate on a per-element 13319basis and the element order is not affected. 13320 13321'``llvm.bswap.*``' Intrinsics 13322^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13323 13324Syntax: 13325""""""" 13326 13327This is an overloaded intrinsic function. You can use bswap on any 13328integer type that is an even number of bytes (i.e. BitWidth % 16 == 0). 13329 13330:: 13331 13332 declare i16 @llvm.bswap.i16(i16 <id>) 13333 declare i32 @llvm.bswap.i32(i32 <id>) 13334 declare i64 @llvm.bswap.i64(i64 <id>) 13335 declare <4 x i32> @llvm.bswap.v4i32(<4 x i32> <id>) 13336 13337Overview: 13338""""""""" 13339 13340The '``llvm.bswap``' family of intrinsics is used to byte swap an integer 13341value or vector of integer values with an even number of bytes (positive 13342multiple of 16 bits). 13343 13344Semantics: 13345"""""""""" 13346 13347The ``llvm.bswap.i16`` intrinsic returns an i16 value that has the high 13348and low byte of the input i16 swapped. Similarly, the ``llvm.bswap.i32`` 13349intrinsic returns an i32 value that has the four bytes of the input i32 13350swapped, so that if the input bytes are numbered 0, 1, 2, 3 then the 13351returned i32 will have its bytes in 3, 2, 1, 0 order. The 13352``llvm.bswap.i48``, ``llvm.bswap.i64`` and other intrinsics extend this 13353concept to additional even-byte lengths (6 bytes, 8 bytes and more, 13354respectively). The vector intrinsics, such as ``llvm.bswap.v4i32``, 13355operate on a per-element basis and the element order is not affected. 13356 13357'``llvm.ctpop.*``' Intrinsic 13358^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13359 13360Syntax: 13361""""""" 13362 13363This is an overloaded intrinsic. You can use llvm.ctpop on any integer 13364bit width, or on any vector with integer elements. Not all targets 13365support all bit widths or vector types, however. 13366 13367:: 13368 13369 declare i8 @llvm.ctpop.i8(i8 <src>) 13370 declare i16 @llvm.ctpop.i16(i16 <src>) 13371 declare i32 @llvm.ctpop.i32(i32 <src>) 13372 declare i64 @llvm.ctpop.i64(i64 <src>) 13373 declare i256 @llvm.ctpop.i256(i256 <src>) 13374 declare <2 x i32> @llvm.ctpop.v2i32(<2 x i32> <src>) 13375 13376Overview: 13377""""""""" 13378 13379The '``llvm.ctpop``' family of intrinsics counts the number of bits set 13380in a value. 13381 13382Arguments: 13383"""""""""" 13384 13385The only argument is the value to be counted. The argument may be of any 13386integer type, or a vector with integer elements. The return type must 13387match the argument type. 13388 13389Semantics: 13390"""""""""" 13391 13392The '``llvm.ctpop``' intrinsic counts the 1's in a variable, or within 13393each element of a vector. 13394 13395'``llvm.ctlz.*``' Intrinsic 13396^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13397 13398Syntax: 13399""""""" 13400 13401This is an overloaded intrinsic. You can use ``llvm.ctlz`` on any 13402integer bit width, or any vector whose elements are integers. Not all 13403targets support all bit widths or vector types, however. 13404 13405:: 13406 13407 declare i8 @llvm.ctlz.i8 (i8 <src>, i1 <is_zero_undef>) 13408 declare i16 @llvm.ctlz.i16 (i16 <src>, i1 <is_zero_undef>) 13409 declare i32 @llvm.ctlz.i32 (i32 <src>, i1 <is_zero_undef>) 13410 declare i64 @llvm.ctlz.i64 (i64 <src>, i1 <is_zero_undef>) 13411 declare i256 @llvm.ctlz.i256(i256 <src>, i1 <is_zero_undef>) 13412 declare <2 x i32> @llvm.ctlz.v2i32(<2 x i32> <src>, i1 <is_zero_undef>) 13413 13414Overview: 13415""""""""" 13416 13417The '``llvm.ctlz``' family of intrinsic functions counts the number of 13418leading zeros in a variable. 13419 13420Arguments: 13421"""""""""" 13422 13423The first argument is the value to be counted. This argument may be of 13424any integer type, or a vector with integer element type. The return 13425type must match the first argument type. 13426 13427The second argument must be a constant and is a flag to indicate whether 13428the intrinsic should ensure that a zero as the first argument produces a 13429defined result. Historically some architectures did not provide a 13430defined result for zero values as efficiently, and many algorithms are 13431now predicated on avoiding zero-value inputs. 13432 13433Semantics: 13434"""""""""" 13435 13436The '``llvm.ctlz``' intrinsic counts the leading (most significant) 13437zeros in a variable, or within each element of the vector. If 13438``src == 0`` then the result is the size in bits of the type of ``src`` 13439if ``is_zero_undef == 0`` and ``undef`` otherwise. For example, 13440``llvm.ctlz(i32 2) = 30``. 13441 13442'``llvm.cttz.*``' Intrinsic 13443^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13444 13445Syntax: 13446""""""" 13447 13448This is an overloaded intrinsic. You can use ``llvm.cttz`` on any 13449integer bit width, or any vector of integer elements. Not all targets 13450support all bit widths or vector types, however. 13451 13452:: 13453 13454 declare i8 @llvm.cttz.i8 (i8 <src>, i1 <is_zero_undef>) 13455 declare i16 @llvm.cttz.i16 (i16 <src>, i1 <is_zero_undef>) 13456 declare i32 @llvm.cttz.i32 (i32 <src>, i1 <is_zero_undef>) 13457 declare i64 @llvm.cttz.i64 (i64 <src>, i1 <is_zero_undef>) 13458 declare i256 @llvm.cttz.i256(i256 <src>, i1 <is_zero_undef>) 13459 declare <2 x i32> @llvm.cttz.v2i32(<2 x i32> <src>, i1 <is_zero_undef>) 13460 13461Overview: 13462""""""""" 13463 13464The '``llvm.cttz``' family of intrinsic functions counts the number of 13465trailing zeros. 13466 13467Arguments: 13468"""""""""" 13469 13470The first argument is the value to be counted. This argument may be of 13471any integer type, or a vector with integer element type. The return 13472type must match the first argument type. 13473 13474The second argument must be a constant and is a flag to indicate whether 13475the intrinsic should ensure that a zero as the first argument produces a 13476defined result. Historically some architectures did not provide a 13477defined result for zero values as efficiently, and many algorithms are 13478now predicated on avoiding zero-value inputs. 13479 13480Semantics: 13481"""""""""" 13482 13483The '``llvm.cttz``' intrinsic counts the trailing (least significant) 13484zeros in a variable, or within each element of a vector. If ``src == 0`` 13485then the result is the size in bits of the type of ``src`` if 13486``is_zero_undef == 0`` and ``undef`` otherwise. For example, 13487``llvm.cttz(2) = 1``. 13488 13489.. _int_overflow: 13490 13491'``llvm.fshl.*``' Intrinsic 13492^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13493 13494Syntax: 13495""""""" 13496 13497This is an overloaded intrinsic. You can use ``llvm.fshl`` on any 13498integer bit width or any vector of integer elements. Not all targets 13499support all bit widths or vector types, however. 13500 13501:: 13502 13503 declare i8 @llvm.fshl.i8 (i8 %a, i8 %b, i8 %c) 13504 declare i67 @llvm.fshl.i67(i67 %a, i67 %b, i67 %c) 13505 declare <2 x i32> @llvm.fshl.v2i32(<2 x i32> %a, <2 x i32> %b, <2 x i32> %c) 13506 13507Overview: 13508""""""""" 13509 13510The '``llvm.fshl``' family of intrinsic functions performs a funnel shift left: 13511the first two values are concatenated as { %a : %b } (%a is the most significant 13512bits of the wide value), the combined value is shifted left, and the most 13513significant bits are extracted to produce a result that is the same size as the 13514original arguments. If the first 2 arguments are identical, this is equivalent 13515to a rotate left operation. For vector types, the operation occurs for each 13516element of the vector. The shift argument is treated as an unsigned amount 13517modulo the element size of the arguments. 13518 13519Arguments: 13520"""""""""" 13521 13522The first two arguments are the values to be concatenated. The third 13523argument is the shift amount. The arguments may be any integer type or a 13524vector with integer element type. All arguments and the return value must 13525have the same type. 13526 13527Example: 13528"""""""" 13529 13530.. code-block:: text 13531 13532 %r = call i8 @llvm.fshl.i8(i8 %x, i8 %y, i8 %z) ; %r = i8: msb_extract((concat(x, y) << (z % 8)), 8) 13533 %r = call i8 @llvm.fshl.i8(i8 255, i8 0, i8 15) ; %r = i8: 128 (0b10000000) 13534 %r = call i8 @llvm.fshl.i8(i8 15, i8 15, i8 11) ; %r = i8: 120 (0b01111000) 13535 %r = call i8 @llvm.fshl.i8(i8 0, i8 255, i8 8) ; %r = i8: 0 (0b00000000) 13536 13537'``llvm.fshr.*``' Intrinsic 13538^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13539 13540Syntax: 13541""""""" 13542 13543This is an overloaded intrinsic. You can use ``llvm.fshr`` on any 13544integer bit width or any vector of integer elements. Not all targets 13545support all bit widths or vector types, however. 13546 13547:: 13548 13549 declare i8 @llvm.fshr.i8 (i8 %a, i8 %b, i8 %c) 13550 declare i67 @llvm.fshr.i67(i67 %a, i67 %b, i67 %c) 13551 declare <2 x i32> @llvm.fshr.v2i32(<2 x i32> %a, <2 x i32> %b, <2 x i32> %c) 13552 13553Overview: 13554""""""""" 13555 13556The '``llvm.fshr``' family of intrinsic functions performs a funnel shift right: 13557the first two values are concatenated as { %a : %b } (%a is the most significant 13558bits of the wide value), the combined value is shifted right, and the least 13559significant bits are extracted to produce a result that is the same size as the 13560original arguments. If the first 2 arguments are identical, this is equivalent 13561to a rotate right operation. For vector types, the operation occurs for each 13562element of the vector. The shift argument is treated as an unsigned amount 13563modulo the element size of the arguments. 13564 13565Arguments: 13566"""""""""" 13567 13568The first two arguments are the values to be concatenated. The third 13569argument is the shift amount. The arguments may be any integer type or a 13570vector with integer element type. All arguments and the return value must 13571have the same type. 13572 13573Example: 13574"""""""" 13575 13576.. code-block:: text 13577 13578 %r = call i8 @llvm.fshr.i8(i8 %x, i8 %y, i8 %z) ; %r = i8: lsb_extract((concat(x, y) >> (z % 8)), 8) 13579 %r = call i8 @llvm.fshr.i8(i8 255, i8 0, i8 15) ; %r = i8: 254 (0b11111110) 13580 %r = call i8 @llvm.fshr.i8(i8 15, i8 15, i8 11) ; %r = i8: 225 (0b11100001) 13581 %r = call i8 @llvm.fshr.i8(i8 0, i8 255, i8 8) ; %r = i8: 255 (0b11111111) 13582 13583Arithmetic with Overflow Intrinsics 13584----------------------------------- 13585 13586LLVM provides intrinsics for fast arithmetic overflow checking. 13587 13588Each of these intrinsics returns a two-element struct. The first 13589element of this struct contains the result of the corresponding 13590arithmetic operation modulo 2\ :sup:`n`\ , where n is the bit width of 13591the result. Therefore, for example, the first element of the struct 13592returned by ``llvm.sadd.with.overflow.i32`` is always the same as the 13593result of a 32-bit ``add`` instruction with the same operands, where 13594the ``add`` is *not* modified by an ``nsw`` or ``nuw`` flag. 13595 13596The second element of the result is an ``i1`` that is 1 if the 13597arithmetic operation overflowed and 0 otherwise. An operation 13598overflows if, for any values of its operands ``A`` and ``B`` and for 13599any ``N`` larger than the operands' width, ``ext(A op B) to iN`` is 13600not equal to ``(ext(A) to iN) op (ext(B) to iN)`` where ``ext`` is 13601``sext`` for signed overflow and ``zext`` for unsigned overflow, and 13602``op`` is the underlying arithmetic operation. 13603 13604The behavior of these intrinsics is well-defined for all argument 13605values. 13606 13607'``llvm.sadd.with.overflow.*``' Intrinsics 13608^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13609 13610Syntax: 13611""""""" 13612 13613This is an overloaded intrinsic. You can use ``llvm.sadd.with.overflow`` 13614on any integer bit width or vectors of integers. 13615 13616:: 13617 13618 declare {i16, i1} @llvm.sadd.with.overflow.i16(i16 %a, i16 %b) 13619 declare {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b) 13620 declare {i64, i1} @llvm.sadd.with.overflow.i64(i64 %a, i64 %b) 13621 declare {<4 x i32>, <4 x i1>} @llvm.sadd.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b) 13622 13623Overview: 13624""""""""" 13625 13626The '``llvm.sadd.with.overflow``' family of intrinsic functions perform 13627a signed addition of the two arguments, and indicate whether an overflow 13628occurred during the signed summation. 13629 13630Arguments: 13631"""""""""" 13632 13633The arguments (%a and %b) and the first element of the result structure 13634may be of integer types of any bit width, but they must have the same 13635bit width. The second element of the result structure must be of type 13636``i1``. ``%a`` and ``%b`` are the two values that will undergo signed 13637addition. 13638 13639Semantics: 13640"""""""""" 13641 13642The '``llvm.sadd.with.overflow``' family of intrinsic functions perform 13643a signed addition of the two variables. They return a structure --- the 13644first element of which is the signed summation, and the second element 13645of which is a bit specifying if the signed summation resulted in an 13646overflow. 13647 13648Examples: 13649""""""""" 13650 13651.. code-block:: llvm 13652 13653 %res = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b) 13654 %sum = extractvalue {i32, i1} %res, 0 13655 %obit = extractvalue {i32, i1} %res, 1 13656 br i1 %obit, label %overflow, label %normal 13657 13658'``llvm.uadd.with.overflow.*``' Intrinsics 13659^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13660 13661Syntax: 13662""""""" 13663 13664This is an overloaded intrinsic. You can use ``llvm.uadd.with.overflow`` 13665on any integer bit width or vectors of integers. 13666 13667:: 13668 13669 declare {i16, i1} @llvm.uadd.with.overflow.i16(i16 %a, i16 %b) 13670 declare {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b) 13671 declare {i64, i1} @llvm.uadd.with.overflow.i64(i64 %a, i64 %b) 13672 declare {<4 x i32>, <4 x i1>} @llvm.uadd.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b) 13673 13674Overview: 13675""""""""" 13676 13677The '``llvm.uadd.with.overflow``' family of intrinsic functions perform 13678an unsigned addition of the two arguments, and indicate whether a carry 13679occurred during the unsigned summation. 13680 13681Arguments: 13682"""""""""" 13683 13684The arguments (%a and %b) and the first element of the result structure 13685may be of integer types of any bit width, but they must have the same 13686bit width. The second element of the result structure must be of type 13687``i1``. ``%a`` and ``%b`` are the two values that will undergo unsigned 13688addition. 13689 13690Semantics: 13691"""""""""" 13692 13693The '``llvm.uadd.with.overflow``' family of intrinsic functions perform 13694an unsigned addition of the two arguments. They return a structure --- the 13695first element of which is the sum, and the second element of which is a 13696bit specifying if the unsigned summation resulted in a carry. 13697 13698Examples: 13699""""""""" 13700 13701.. code-block:: llvm 13702 13703 %res = call {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b) 13704 %sum = extractvalue {i32, i1} %res, 0 13705 %obit = extractvalue {i32, i1} %res, 1 13706 br i1 %obit, label %carry, label %normal 13707 13708'``llvm.ssub.with.overflow.*``' Intrinsics 13709^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13710 13711Syntax: 13712""""""" 13713 13714This is an overloaded intrinsic. You can use ``llvm.ssub.with.overflow`` 13715on any integer bit width or vectors of integers. 13716 13717:: 13718 13719 declare {i16, i1} @llvm.ssub.with.overflow.i16(i16 %a, i16 %b) 13720 declare {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a, i32 %b) 13721 declare {i64, i1} @llvm.ssub.with.overflow.i64(i64 %a, i64 %b) 13722 declare {<4 x i32>, <4 x i1>} @llvm.ssub.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b) 13723 13724Overview: 13725""""""""" 13726 13727The '``llvm.ssub.with.overflow``' family of intrinsic functions perform 13728a signed subtraction of the two arguments, and indicate whether an 13729overflow occurred during the signed subtraction. 13730 13731Arguments: 13732"""""""""" 13733 13734The arguments (%a and %b) and the first element of the result structure 13735may be of integer types of any bit width, but they must have the same 13736bit width. The second element of the result structure must be of type 13737``i1``. ``%a`` and ``%b`` are the two values that will undergo signed 13738subtraction. 13739 13740Semantics: 13741"""""""""" 13742 13743The '``llvm.ssub.with.overflow``' family of intrinsic functions perform 13744a signed subtraction of the two arguments. They return a structure --- the 13745first element of which is the subtraction, and the second element of 13746which is a bit specifying if the signed subtraction resulted in an 13747overflow. 13748 13749Examples: 13750""""""""" 13751 13752.. code-block:: llvm 13753 13754 %res = call {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a, i32 %b) 13755 %sum = extractvalue {i32, i1} %res, 0 13756 %obit = extractvalue {i32, i1} %res, 1 13757 br i1 %obit, label %overflow, label %normal 13758 13759'``llvm.usub.with.overflow.*``' Intrinsics 13760^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13761 13762Syntax: 13763""""""" 13764 13765This is an overloaded intrinsic. You can use ``llvm.usub.with.overflow`` 13766on any integer bit width or vectors of integers. 13767 13768:: 13769 13770 declare {i16, i1} @llvm.usub.with.overflow.i16(i16 %a, i16 %b) 13771 declare {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b) 13772 declare {i64, i1} @llvm.usub.with.overflow.i64(i64 %a, i64 %b) 13773 declare {<4 x i32>, <4 x i1>} @llvm.usub.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b) 13774 13775Overview: 13776""""""""" 13777 13778The '``llvm.usub.with.overflow``' family of intrinsic functions perform 13779an unsigned subtraction of the two arguments, and indicate whether an 13780overflow occurred during the unsigned subtraction. 13781 13782Arguments: 13783"""""""""" 13784 13785The arguments (%a and %b) and the first element of the result structure 13786may be of integer types of any bit width, but they must have the same 13787bit width. The second element of the result structure must be of type 13788``i1``. ``%a`` and ``%b`` are the two values that will undergo unsigned 13789subtraction. 13790 13791Semantics: 13792"""""""""" 13793 13794The '``llvm.usub.with.overflow``' family of intrinsic functions perform 13795an unsigned subtraction of the two arguments. They return a structure --- 13796the first element of which is the subtraction, and the second element of 13797which is a bit specifying if the unsigned subtraction resulted in an 13798overflow. 13799 13800Examples: 13801""""""""" 13802 13803.. code-block:: llvm 13804 13805 %res = call {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b) 13806 %sum = extractvalue {i32, i1} %res, 0 13807 %obit = extractvalue {i32, i1} %res, 1 13808 br i1 %obit, label %overflow, label %normal 13809 13810'``llvm.smul.with.overflow.*``' Intrinsics 13811^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13812 13813Syntax: 13814""""""" 13815 13816This is an overloaded intrinsic. You can use ``llvm.smul.with.overflow`` 13817on any integer bit width or vectors of integers. 13818 13819:: 13820 13821 declare {i16, i1} @llvm.smul.with.overflow.i16(i16 %a, i16 %b) 13822 declare {i32, i1} @llvm.smul.with.overflow.i32(i32 %a, i32 %b) 13823 declare {i64, i1} @llvm.smul.with.overflow.i64(i64 %a, i64 %b) 13824 declare {<4 x i32>, <4 x i1>} @llvm.smul.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b) 13825 13826Overview: 13827""""""""" 13828 13829The '``llvm.smul.with.overflow``' family of intrinsic functions perform 13830a signed multiplication of the two arguments, and indicate whether an 13831overflow occurred during the signed multiplication. 13832 13833Arguments: 13834"""""""""" 13835 13836The arguments (%a and %b) and the first element of the result structure 13837may be of integer types of any bit width, but they must have the same 13838bit width. The second element of the result structure must be of type 13839``i1``. ``%a`` and ``%b`` are the two values that will undergo signed 13840multiplication. 13841 13842Semantics: 13843"""""""""" 13844 13845The '``llvm.smul.with.overflow``' family of intrinsic functions perform 13846a signed multiplication of the two arguments. They return a structure --- 13847the first element of which is the multiplication, and the second element 13848of which is a bit specifying if the signed multiplication resulted in an 13849overflow. 13850 13851Examples: 13852""""""""" 13853 13854.. code-block:: llvm 13855 13856 %res = call {i32, i1} @llvm.smul.with.overflow.i32(i32 %a, i32 %b) 13857 %sum = extractvalue {i32, i1} %res, 0 13858 %obit = extractvalue {i32, i1} %res, 1 13859 br i1 %obit, label %overflow, label %normal 13860 13861'``llvm.umul.with.overflow.*``' Intrinsics 13862^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13863 13864Syntax: 13865""""""" 13866 13867This is an overloaded intrinsic. You can use ``llvm.umul.with.overflow`` 13868on any integer bit width or vectors of integers. 13869 13870:: 13871 13872 declare {i16, i1} @llvm.umul.with.overflow.i16(i16 %a, i16 %b) 13873 declare {i32, i1} @llvm.umul.with.overflow.i32(i32 %a, i32 %b) 13874 declare {i64, i1} @llvm.umul.with.overflow.i64(i64 %a, i64 %b) 13875 declare {<4 x i32>, <4 x i1>} @llvm.umul.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b) 13876 13877Overview: 13878""""""""" 13879 13880The '``llvm.umul.with.overflow``' family of intrinsic functions perform 13881a unsigned multiplication of the two arguments, and indicate whether an 13882overflow occurred during the unsigned multiplication. 13883 13884Arguments: 13885"""""""""" 13886 13887The arguments (%a and %b) and the first element of the result structure 13888may be of integer types of any bit width, but they must have the same 13889bit width. The second element of the result structure must be of type 13890``i1``. ``%a`` and ``%b`` are the two values that will undergo unsigned 13891multiplication. 13892 13893Semantics: 13894"""""""""" 13895 13896The '``llvm.umul.with.overflow``' family of intrinsic functions perform 13897an unsigned multiplication of the two arguments. They return a structure --- 13898the first element of which is the multiplication, and the second 13899element of which is a bit specifying if the unsigned multiplication 13900resulted in an overflow. 13901 13902Examples: 13903""""""""" 13904 13905.. code-block:: llvm 13906 13907 %res = call {i32, i1} @llvm.umul.with.overflow.i32(i32 %a, i32 %b) 13908 %sum = extractvalue {i32, i1} %res, 0 13909 %obit = extractvalue {i32, i1} %res, 1 13910 br i1 %obit, label %overflow, label %normal 13911 13912Saturation Arithmetic Intrinsics 13913--------------------------------- 13914 13915Saturation arithmetic is a version of arithmetic in which operations are 13916limited to a fixed range between a minimum and maximum value. If the result of 13917an operation is greater than the maximum value, the result is set (or 13918"clamped") to this maximum. If it is below the minimum, it is clamped to this 13919minimum. 13920 13921 13922'``llvm.sadd.sat.*``' Intrinsics 13923^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13924 13925Syntax 13926""""""" 13927 13928This is an overloaded intrinsic. You can use ``llvm.sadd.sat`` 13929on any integer bit width or vectors of integers. 13930 13931:: 13932 13933 declare i16 @llvm.sadd.sat.i16(i16 %a, i16 %b) 13934 declare i32 @llvm.sadd.sat.i32(i32 %a, i32 %b) 13935 declare i64 @llvm.sadd.sat.i64(i64 %a, i64 %b) 13936 declare <4 x i32> @llvm.sadd.sat.v4i32(<4 x i32> %a, <4 x i32> %b) 13937 13938Overview 13939""""""""" 13940 13941The '``llvm.sadd.sat``' family of intrinsic functions perform signed 13942saturation addition on the 2 arguments. 13943 13944Arguments 13945"""""""""" 13946 13947The arguments (%a and %b) and the result may be of integer types of any bit 13948width, but they must have the same bit width. ``%a`` and ``%b`` are the two 13949values that will undergo signed addition. 13950 13951Semantics: 13952"""""""""" 13953 13954The maximum value this operation can clamp to is the largest signed value 13955representable by the bit width of the arguments. The minimum value is the 13956smallest signed value representable by this bit width. 13957 13958 13959Examples 13960""""""""" 13961 13962.. code-block:: llvm 13963 13964 %res = call i4 @llvm.sadd.sat.i4(i4 1, i4 2) ; %res = 3 13965 %res = call i4 @llvm.sadd.sat.i4(i4 5, i4 6) ; %res = 7 13966 %res = call i4 @llvm.sadd.sat.i4(i4 -4, i4 2) ; %res = -2 13967 %res = call i4 @llvm.sadd.sat.i4(i4 -4, i4 -5) ; %res = -8 13968 13969 13970'``llvm.uadd.sat.*``' Intrinsics 13971^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13972 13973Syntax 13974""""""" 13975 13976This is an overloaded intrinsic. You can use ``llvm.uadd.sat`` 13977on any integer bit width or vectors of integers. 13978 13979:: 13980 13981 declare i16 @llvm.uadd.sat.i16(i16 %a, i16 %b) 13982 declare i32 @llvm.uadd.sat.i32(i32 %a, i32 %b) 13983 declare i64 @llvm.uadd.sat.i64(i64 %a, i64 %b) 13984 declare <4 x i32> @llvm.uadd.sat.v4i32(<4 x i32> %a, <4 x i32> %b) 13985 13986Overview 13987""""""""" 13988 13989The '``llvm.uadd.sat``' family of intrinsic functions perform unsigned 13990saturation addition on the 2 arguments. 13991 13992Arguments 13993"""""""""" 13994 13995The arguments (%a and %b) and the result may be of integer types of any bit 13996width, but they must have the same bit width. ``%a`` and ``%b`` are the two 13997values that will undergo unsigned addition. 13998 13999Semantics: 14000"""""""""" 14001 14002The maximum value this operation can clamp to is the largest unsigned value 14003representable by the bit width of the arguments. Because this is an unsigned 14004operation, the result will never saturate towards zero. 14005 14006 14007Examples 14008""""""""" 14009 14010.. code-block:: llvm 14011 14012 %res = call i4 @llvm.uadd.sat.i4(i4 1, i4 2) ; %res = 3 14013 %res = call i4 @llvm.uadd.sat.i4(i4 5, i4 6) ; %res = 11 14014 %res = call i4 @llvm.uadd.sat.i4(i4 8, i4 8) ; %res = 15 14015 14016 14017'``llvm.ssub.sat.*``' Intrinsics 14018^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14019 14020Syntax 14021""""""" 14022 14023This is an overloaded intrinsic. You can use ``llvm.ssub.sat`` 14024on any integer bit width or vectors of integers. 14025 14026:: 14027 14028 declare i16 @llvm.ssub.sat.i16(i16 %a, i16 %b) 14029 declare i32 @llvm.ssub.sat.i32(i32 %a, i32 %b) 14030 declare i64 @llvm.ssub.sat.i64(i64 %a, i64 %b) 14031 declare <4 x i32> @llvm.ssub.sat.v4i32(<4 x i32> %a, <4 x i32> %b) 14032 14033Overview 14034""""""""" 14035 14036The '``llvm.ssub.sat``' family of intrinsic functions perform signed 14037saturation subtraction on the 2 arguments. 14038 14039Arguments 14040"""""""""" 14041 14042The arguments (%a and %b) and the result may be of integer types of any bit 14043width, but they must have the same bit width. ``%a`` and ``%b`` are the two 14044values that will undergo signed subtraction. 14045 14046Semantics: 14047"""""""""" 14048 14049The maximum value this operation can clamp to is the largest signed value 14050representable by the bit width of the arguments. The minimum value is the 14051smallest signed value representable by this bit width. 14052 14053 14054Examples 14055""""""""" 14056 14057.. code-block:: llvm 14058 14059 %res = call i4 @llvm.ssub.sat.i4(i4 2, i4 1) ; %res = 1 14060 %res = call i4 @llvm.ssub.sat.i4(i4 2, i4 6) ; %res = -4 14061 %res = call i4 @llvm.ssub.sat.i4(i4 -4, i4 5) ; %res = -8 14062 %res = call i4 @llvm.ssub.sat.i4(i4 4, i4 -5) ; %res = 7 14063 14064 14065'``llvm.usub.sat.*``' Intrinsics 14066^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14067 14068Syntax 14069""""""" 14070 14071This is an overloaded intrinsic. You can use ``llvm.usub.sat`` 14072on any integer bit width or vectors of integers. 14073 14074:: 14075 14076 declare i16 @llvm.usub.sat.i16(i16 %a, i16 %b) 14077 declare i32 @llvm.usub.sat.i32(i32 %a, i32 %b) 14078 declare i64 @llvm.usub.sat.i64(i64 %a, i64 %b) 14079 declare <4 x i32> @llvm.usub.sat.v4i32(<4 x i32> %a, <4 x i32> %b) 14080 14081Overview 14082""""""""" 14083 14084The '``llvm.usub.sat``' family of intrinsic functions perform unsigned 14085saturation subtraction on the 2 arguments. 14086 14087Arguments 14088"""""""""" 14089 14090The arguments (%a and %b) and the result may be of integer types of any bit 14091width, but they must have the same bit width. ``%a`` and ``%b`` are the two 14092values that will undergo unsigned subtraction. 14093 14094Semantics: 14095"""""""""" 14096 14097The minimum value this operation can clamp to is 0, which is the smallest 14098unsigned value representable by the bit width of the unsigned arguments. 14099Because this is an unsigned operation, the result will never saturate towards 14100the largest possible value representable by this bit width. 14101 14102 14103Examples 14104""""""""" 14105 14106.. code-block:: llvm 14107 14108 %res = call i4 @llvm.usub.sat.i4(i4 2, i4 1) ; %res = 1 14109 %res = call i4 @llvm.usub.sat.i4(i4 2, i4 6) ; %res = 0 14110 14111 14112Fixed Point Arithmetic Intrinsics 14113--------------------------------- 14114 14115A fixed point number represents a real data type for a number that has a fixed 14116number of digits after a radix point (equivalent to the decimal point '.'). 14117The number of digits after the radix point is referred as the `scale`. These 14118are useful for representing fractional values to a specific precision. The 14119following intrinsics perform fixed point arithmetic operations on 2 operands 14120of the same scale, specified as the third argument. 14121 14122The ``llvm.*mul.fix`` family of intrinsic functions represents a multiplication 14123of fixed point numbers through scaled integers. Therefore, fixed point 14124multiplication can be represented as 14125 14126.. code-block:: llvm 14127 14128 %result = call i4 @llvm.smul.fix.i4(i4 %a, i4 %b, i32 %scale) 14129 14130 ; Expands to 14131 %a2 = sext i4 %a to i8 14132 %b2 = sext i4 %b to i8 14133 %mul = mul nsw nuw i8 %a, %b 14134 %scale2 = trunc i32 %scale to i8 14135 %r = ashr i8 %mul, i8 %scale2 ; this is for a target rounding down towards negative infinity 14136 %result = trunc i8 %r to i4 14137 14138The ``llvm.*div.fix`` family of intrinsic functions represents a division of 14139fixed point numbers through scaled integers. Fixed point division can be 14140represented as: 14141 14142.. code-block:: llvm 14143 14144 %result call i4 @llvm.sdiv.fix.i4(i4 %a, i4 %b, i32 %scale) 14145 14146 ; Expands to 14147 %a2 = sext i4 %a to i8 14148 %b2 = sext i4 %b to i8 14149 %scale2 = trunc i32 %scale to i8 14150 %a3 = shl i8 %a2, %scale2 14151 %r = sdiv i8 %a3, %b2 ; this is for a target rounding towards zero 14152 %result = trunc i8 %r to i4 14153 14154For each of these functions, if the result cannot be represented exactly with 14155the provided scale, the result is rounded. Rounding is unspecified since 14156preferred rounding may vary for different targets. Rounding is specified 14157through a target hook. Different pipelines should legalize or optimize this 14158using the rounding specified by this hook if it is provided. Operations like 14159constant folding, instruction combining, KnownBits, and ValueTracking should 14160also use this hook, if provided, and not assume the direction of rounding. A 14161rounded result must always be within one unit of precision from the true 14162result. That is, the error between the returned result and the true result must 14163be less than 1/2^(scale). 14164 14165 14166'``llvm.smul.fix.*``' Intrinsics 14167^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14168 14169Syntax 14170""""""" 14171 14172This is an overloaded intrinsic. You can use ``llvm.smul.fix`` 14173on any integer bit width or vectors of integers. 14174 14175:: 14176 14177 declare i16 @llvm.smul.fix.i16(i16 %a, i16 %b, i32 %scale) 14178 declare i32 @llvm.smul.fix.i32(i32 %a, i32 %b, i32 %scale) 14179 declare i64 @llvm.smul.fix.i64(i64 %a, i64 %b, i32 %scale) 14180 declare <4 x i32> @llvm.smul.fix.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale) 14181 14182Overview 14183""""""""" 14184 14185The '``llvm.smul.fix``' family of intrinsic functions perform signed 14186fixed point multiplication on 2 arguments of the same scale. 14187 14188Arguments 14189"""""""""" 14190 14191The arguments (%a and %b) and the result may be of integer types of any bit 14192width, but they must have the same bit width. The arguments may also work with 14193int vectors of the same length and int size. ``%a`` and ``%b`` are the two 14194values that will undergo signed fixed point multiplication. The argument 14195``%scale`` represents the scale of both operands, and must be a constant 14196integer. 14197 14198Semantics: 14199"""""""""" 14200 14201This operation performs fixed point multiplication on the 2 arguments of a 14202specified scale. The result will also be returned in the same scale specified 14203in the third argument. 14204 14205If the result value cannot be precisely represented in the given scale, the 14206value is rounded up or down to the closest representable value. The rounding 14207direction is unspecified. 14208 14209It is undefined behavior if the result value does not fit within the range of 14210the fixed point type. 14211 14212 14213Examples 14214""""""""" 14215 14216.. code-block:: llvm 14217 14218 %res = call i4 @llvm.smul.fix.i4(i4 3, i4 2, i32 0) ; %res = 6 (2 x 3 = 6) 14219 %res = call i4 @llvm.smul.fix.i4(i4 3, i4 2, i32 1) ; %res = 3 (1.5 x 1 = 1.5) 14220 %res = call i4 @llvm.smul.fix.i4(i4 3, i4 -2, i32 1) ; %res = -3 (1.5 x -1 = -1.5) 14221 14222 ; The result in the following could be rounded up to -2 or down to -2.5 14223 %res = call i4 @llvm.smul.fix.i4(i4 3, i4 -3, i32 1) ; %res = -5 (or -4) (1.5 x -1.5 = -2.25) 14224 14225 14226'``llvm.umul.fix.*``' Intrinsics 14227^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14228 14229Syntax 14230""""""" 14231 14232This is an overloaded intrinsic. You can use ``llvm.umul.fix`` 14233on any integer bit width or vectors of integers. 14234 14235:: 14236 14237 declare i16 @llvm.umul.fix.i16(i16 %a, i16 %b, i32 %scale) 14238 declare i32 @llvm.umul.fix.i32(i32 %a, i32 %b, i32 %scale) 14239 declare i64 @llvm.umul.fix.i64(i64 %a, i64 %b, i32 %scale) 14240 declare <4 x i32> @llvm.umul.fix.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale) 14241 14242Overview 14243""""""""" 14244 14245The '``llvm.umul.fix``' family of intrinsic functions perform unsigned 14246fixed point multiplication on 2 arguments of the same scale. 14247 14248Arguments 14249"""""""""" 14250 14251The arguments (%a and %b) and the result may be of integer types of any bit 14252width, but they must have the same bit width. The arguments may also work with 14253int vectors of the same length and int size. ``%a`` and ``%b`` are the two 14254values that will undergo unsigned fixed point multiplication. The argument 14255``%scale`` represents the scale of both operands, and must be a constant 14256integer. 14257 14258Semantics: 14259"""""""""" 14260 14261This operation performs unsigned fixed point multiplication on the 2 arguments of a 14262specified scale. The result will also be returned in the same scale specified 14263in the third argument. 14264 14265If the result value cannot be precisely represented in the given scale, the 14266value is rounded up or down to the closest representable value. The rounding 14267direction is unspecified. 14268 14269It is undefined behavior if the result value does not fit within the range of 14270the fixed point type. 14271 14272 14273Examples 14274""""""""" 14275 14276.. code-block:: llvm 14277 14278 %res = call i4 @llvm.umul.fix.i4(i4 3, i4 2, i32 0) ; %res = 6 (2 x 3 = 6) 14279 %res = call i4 @llvm.umul.fix.i4(i4 3, i4 2, i32 1) ; %res = 3 (1.5 x 1 = 1.5) 14280 14281 ; The result in the following could be rounded down to 3.5 or up to 4 14282 %res = call i4 @llvm.umul.fix.i4(i4 15, i4 1, i32 1) ; %res = 7 (or 8) (7.5 x 0.5 = 3.75) 14283 14284 14285'``llvm.smul.fix.sat.*``' Intrinsics 14286^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14287 14288Syntax 14289""""""" 14290 14291This is an overloaded intrinsic. You can use ``llvm.smul.fix.sat`` 14292on any integer bit width or vectors of integers. 14293 14294:: 14295 14296 declare i16 @llvm.smul.fix.sat.i16(i16 %a, i16 %b, i32 %scale) 14297 declare i32 @llvm.smul.fix.sat.i32(i32 %a, i32 %b, i32 %scale) 14298 declare i64 @llvm.smul.fix.sat.i64(i64 %a, i64 %b, i32 %scale) 14299 declare <4 x i32> @llvm.smul.fix.sat.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale) 14300 14301Overview 14302""""""""" 14303 14304The '``llvm.smul.fix.sat``' family of intrinsic functions perform signed 14305fixed point saturation multiplication on 2 arguments of the same scale. 14306 14307Arguments 14308"""""""""" 14309 14310The arguments (%a and %b) and the result may be of integer types of any bit 14311width, but they must have the same bit width. ``%a`` and ``%b`` are the two 14312values that will undergo signed fixed point multiplication. The argument 14313``%scale`` represents the scale of both operands, and must be a constant 14314integer. 14315 14316Semantics: 14317"""""""""" 14318 14319This operation performs fixed point multiplication on the 2 arguments of a 14320specified scale. The result will also be returned in the same scale specified 14321in the third argument. 14322 14323If the result value cannot be precisely represented in the given scale, the 14324value is rounded up or down to the closest representable value. The rounding 14325direction is unspecified. 14326 14327The maximum value this operation can clamp to is the largest signed value 14328representable by the bit width of the first 2 arguments. The minimum value is the 14329smallest signed value representable by this bit width. 14330 14331 14332Examples 14333""""""""" 14334 14335.. code-block:: llvm 14336 14337 %res = call i4 @llvm.smul.fix.sat.i4(i4 3, i4 2, i32 0) ; %res = 6 (2 x 3 = 6) 14338 %res = call i4 @llvm.smul.fix.sat.i4(i4 3, i4 2, i32 1) ; %res = 3 (1.5 x 1 = 1.5) 14339 %res = call i4 @llvm.smul.fix.sat.i4(i4 3, i4 -2, i32 1) ; %res = -3 (1.5 x -1 = -1.5) 14340 14341 ; The result in the following could be rounded up to -2 or down to -2.5 14342 %res = call i4 @llvm.smul.fix.sat.i4(i4 3, i4 -3, i32 1) ; %res = -5 (or -4) (1.5 x -1.5 = -2.25) 14343 14344 ; Saturation 14345 %res = call i4 @llvm.smul.fix.sat.i4(i4 7, i4 2, i32 0) ; %res = 7 14346 %res = call i4 @llvm.smul.fix.sat.i4(i4 7, i4 4, i32 2) ; %res = 7 14347 %res = call i4 @llvm.smul.fix.sat.i4(i4 -8, i4 5, i32 2) ; %res = -8 14348 %res = call i4 @llvm.smul.fix.sat.i4(i4 -8, i4 -2, i32 1) ; %res = 7 14349 14350 ; Scale can affect the saturation result 14351 %res = call i4 @llvm.smul.fix.sat.i4(i4 2, i4 4, i32 0) ; %res = 7 (2 x 4 -> clamped to 7) 14352 %res = call i4 @llvm.smul.fix.sat.i4(i4 2, i4 4, i32 1) ; %res = 4 (1 x 2 = 2) 14353 14354 14355'``llvm.umul.fix.sat.*``' Intrinsics 14356^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14357 14358Syntax 14359""""""" 14360 14361This is an overloaded intrinsic. You can use ``llvm.umul.fix.sat`` 14362on any integer bit width or vectors of integers. 14363 14364:: 14365 14366 declare i16 @llvm.umul.fix.sat.i16(i16 %a, i16 %b, i32 %scale) 14367 declare i32 @llvm.umul.fix.sat.i32(i32 %a, i32 %b, i32 %scale) 14368 declare i64 @llvm.umul.fix.sat.i64(i64 %a, i64 %b, i32 %scale) 14369 declare <4 x i32> @llvm.umul.fix.sat.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale) 14370 14371Overview 14372""""""""" 14373 14374The '``llvm.umul.fix.sat``' family of intrinsic functions perform unsigned 14375fixed point saturation multiplication on 2 arguments of the same scale. 14376 14377Arguments 14378"""""""""" 14379 14380The arguments (%a and %b) and the result may be of integer types of any bit 14381width, but they must have the same bit width. ``%a`` and ``%b`` are the two 14382values that will undergo unsigned fixed point multiplication. The argument 14383``%scale`` represents the scale of both operands, and must be a constant 14384integer. 14385 14386Semantics: 14387"""""""""" 14388 14389This operation performs fixed point multiplication on the 2 arguments of a 14390specified scale. The result will also be returned in the same scale specified 14391in the third argument. 14392 14393If the result value cannot be precisely represented in the given scale, the 14394value is rounded up or down to the closest representable value. The rounding 14395direction is unspecified. 14396 14397The maximum value this operation can clamp to is the largest unsigned value 14398representable by the bit width of the first 2 arguments. The minimum value is the 14399smallest unsigned value representable by this bit width (zero). 14400 14401 14402Examples 14403""""""""" 14404 14405.. code-block:: llvm 14406 14407 %res = call i4 @llvm.umul.fix.sat.i4(i4 3, i4 2, i32 0) ; %res = 6 (2 x 3 = 6) 14408 %res = call i4 @llvm.umul.fix.sat.i4(i4 3, i4 2, i32 1) ; %res = 3 (1.5 x 1 = 1.5) 14409 14410 ; The result in the following could be rounded down to 2 or up to 2.5 14411 %res = call i4 @llvm.umul.fix.sat.i4(i4 3, i4 3, i32 1) ; %res = 4 (or 5) (1.5 x 1.5 = 2.25) 14412 14413 ; Saturation 14414 %res = call i4 @llvm.umul.fix.sat.i4(i4 8, i4 2, i32 0) ; %res = 15 (8 x 2 -> clamped to 15) 14415 %res = call i4 @llvm.umul.fix.sat.i4(i4 8, i4 8, i32 2) ; %res = 15 (2 x 2 -> clamped to 3.75) 14416 14417 ; Scale can affect the saturation result 14418 %res = call i4 @llvm.umul.fix.sat.i4(i4 2, i4 4, i32 0) ; %res = 7 (2 x 4 -> clamped to 7) 14419 %res = call i4 @llvm.umul.fix.sat.i4(i4 2, i4 4, i32 1) ; %res = 4 (1 x 2 = 2) 14420 14421 14422'``llvm.sdiv.fix.*``' Intrinsics 14423^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14424 14425Syntax 14426""""""" 14427 14428This is an overloaded intrinsic. You can use ``llvm.sdiv.fix`` 14429on any integer bit width or vectors of integers. 14430 14431:: 14432 14433 declare i16 @llvm.sdiv.fix.i16(i16 %a, i16 %b, i32 %scale) 14434 declare i32 @llvm.sdiv.fix.i32(i32 %a, i32 %b, i32 %scale) 14435 declare i64 @llvm.sdiv.fix.i64(i64 %a, i64 %b, i32 %scale) 14436 declare <4 x i32> @llvm.sdiv.fix.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale) 14437 14438Overview 14439""""""""" 14440 14441The '``llvm.sdiv.fix``' family of intrinsic functions perform signed 14442fixed point division on 2 arguments of the same scale. 14443 14444Arguments 14445"""""""""" 14446 14447The arguments (%a and %b) and the result may be of integer types of any bit 14448width, but they must have the same bit width. The arguments may also work with 14449int vectors of the same length and int size. ``%a`` and ``%b`` are the two 14450values that will undergo signed fixed point division. The argument 14451``%scale`` represents the scale of both operands, and must be a constant 14452integer. 14453 14454Semantics: 14455"""""""""" 14456 14457This operation performs fixed point division on the 2 arguments of a 14458specified scale. The result will also be returned in the same scale specified 14459in the third argument. 14460 14461If the result value cannot be precisely represented in the given scale, the 14462value is rounded up or down to the closest representable value. The rounding 14463direction is unspecified. 14464 14465It is undefined behavior if the result value does not fit within the range of 14466the fixed point type, or if the second argument is zero. 14467 14468 14469Examples 14470""""""""" 14471 14472.. code-block:: llvm 14473 14474 %res = call i4 @llvm.sdiv.fix.i4(i4 6, i4 2, i32 0) ; %res = 3 (6 / 2 = 3) 14475 %res = call i4 @llvm.sdiv.fix.i4(i4 6, i4 4, i32 1) ; %res = 3 (3 / 2 = 1.5) 14476 %res = call i4 @llvm.sdiv.fix.i4(i4 3, i4 -2, i32 1) ; %res = -3 (1.5 / -1 = -1.5) 14477 14478 ; The result in the following could be rounded up to 1 or down to 0.5 14479 %res = call i4 @llvm.sdiv.fix.i4(i4 3, i4 4, i32 1) ; %res = 2 (or 1) (1.5 / 2 = 0.75) 14480 14481 14482'``llvm.udiv.fix.*``' Intrinsics 14483^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14484 14485Syntax 14486""""""" 14487 14488This is an overloaded intrinsic. You can use ``llvm.udiv.fix`` 14489on any integer bit width or vectors of integers. 14490 14491:: 14492 14493 declare i16 @llvm.udiv.fix.i16(i16 %a, i16 %b, i32 %scale) 14494 declare i32 @llvm.udiv.fix.i32(i32 %a, i32 %b, i32 %scale) 14495 declare i64 @llvm.udiv.fix.i64(i64 %a, i64 %b, i32 %scale) 14496 declare <4 x i32> @llvm.udiv.fix.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale) 14497 14498Overview 14499""""""""" 14500 14501The '``llvm.udiv.fix``' family of intrinsic functions perform unsigned 14502fixed point division on 2 arguments of the same scale. 14503 14504Arguments 14505"""""""""" 14506 14507The arguments (%a and %b) and the result may be of integer types of any bit 14508width, but they must have the same bit width. The arguments may also work with 14509int vectors of the same length and int size. ``%a`` and ``%b`` are the two 14510values that will undergo unsigned fixed point division. The argument 14511``%scale`` represents the scale of both operands, and must be a constant 14512integer. 14513 14514Semantics: 14515"""""""""" 14516 14517This operation performs fixed point division on the 2 arguments of a 14518specified scale. The result will also be returned in the same scale specified 14519in the third argument. 14520 14521If the result value cannot be precisely represented in the given scale, the 14522value is rounded up or down to the closest representable value. The rounding 14523direction is unspecified. 14524 14525It is undefined behavior if the result value does not fit within the range of 14526the fixed point type, or if the second argument is zero. 14527 14528 14529Examples 14530""""""""" 14531 14532.. code-block:: llvm 14533 14534 %res = call i4 @llvm.udiv.fix.i4(i4 6, i4 2, i32 0) ; %res = 3 (6 / 2 = 3) 14535 %res = call i4 @llvm.udiv.fix.i4(i4 6, i4 4, i32 1) ; %res = 3 (3 / 2 = 1.5) 14536 %res = call i4 @llvm.udiv.fix.i4(i4 1, i4 -8, i32 4) ; %res = 2 (0.0625 / 0.5 = 0.125) 14537 14538 ; The result in the following could be rounded up to 1 or down to 0.5 14539 %res = call i4 @llvm.udiv.fix.i4(i4 3, i4 4, i32 1) ; %res = 2 (or 1) (1.5 / 2 = 0.75) 14540 14541 14542'``llvm.sdiv.fix.sat.*``' Intrinsics 14543^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14544 14545Syntax 14546""""""" 14547 14548This is an overloaded intrinsic. You can use ``llvm.sdiv.fix.sat`` 14549on any integer bit width or vectors of integers. 14550 14551:: 14552 14553 declare i16 @llvm.sdiv.fix.sat.i16(i16 %a, i16 %b, i32 %scale) 14554 declare i32 @llvm.sdiv.fix.sat.i32(i32 %a, i32 %b, i32 %scale) 14555 declare i64 @llvm.sdiv.fix.sat.i64(i64 %a, i64 %b, i32 %scale) 14556 declare <4 x i32> @llvm.sdiv.fix.sat.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale) 14557 14558Overview 14559""""""""" 14560 14561The '``llvm.sdiv.fix.sat``' family of intrinsic functions perform signed 14562fixed point saturation division on 2 arguments of the same scale. 14563 14564Arguments 14565"""""""""" 14566 14567The arguments (%a and %b) and the result may be of integer types of any bit 14568width, but they must have the same bit width. ``%a`` and ``%b`` are the two 14569values that will undergo signed fixed point division. The argument 14570``%scale`` represents the scale of both operands, and must be a constant 14571integer. 14572 14573Semantics: 14574"""""""""" 14575 14576This operation performs fixed point division on the 2 arguments of a 14577specified scale. The result will also be returned in the same scale specified 14578in the third argument. 14579 14580If the result value cannot be precisely represented in the given scale, the 14581value is rounded up or down to the closest representable value. The rounding 14582direction is unspecified. 14583 14584The maximum value this operation can clamp to is the largest signed value 14585representable by the bit width of the first 2 arguments. The minimum value is the 14586smallest signed value representable by this bit width. 14587 14588It is undefined behavior if the second argument is zero. 14589 14590 14591Examples 14592""""""""" 14593 14594.. code-block:: llvm 14595 14596 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 6, i4 2, i32 0) ; %res = 3 (6 / 2 = 3) 14597 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 6, i4 4, i32 1) ; %res = 3 (3 / 2 = 1.5) 14598 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 3, i4 -2, i32 1) ; %res = -3 (1.5 / -1 = -1.5) 14599 14600 ; The result in the following could be rounded up to 1 or down to 0.5 14601 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 3, i4 4, i32 1) ; %res = 2 (or 1) (1.5 / 2 = 0.75) 14602 14603 ; Saturation 14604 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 -8, i4 -1, i32 0) ; %res = 7 (-8 / -1 = 8 => 7) 14605 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 4, i4 2, i32 2) ; %res = 7 (1 / 0.5 = 2 => 1.75) 14606 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 -4, i4 1, i32 2) ; %res = -8 (-1 / 0.25 = -4 => -2) 14607 14608 14609'``llvm.udiv.fix.sat.*``' Intrinsics 14610^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14611 14612Syntax 14613""""""" 14614 14615This is an overloaded intrinsic. You can use ``llvm.udiv.fix.sat`` 14616on any integer bit width or vectors of integers. 14617 14618:: 14619 14620 declare i16 @llvm.udiv.fix.sat.i16(i16 %a, i16 %b, i32 %scale) 14621 declare i32 @llvm.udiv.fix.sat.i32(i32 %a, i32 %b, i32 %scale) 14622 declare i64 @llvm.udiv.fix.sat.i64(i64 %a, i64 %b, i32 %scale) 14623 declare <4 x i32> @llvm.udiv.fix.sat.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale) 14624 14625Overview 14626""""""""" 14627 14628The '``llvm.udiv.fix.sat``' family of intrinsic functions perform unsigned 14629fixed point saturation division on 2 arguments of the same scale. 14630 14631Arguments 14632"""""""""" 14633 14634The arguments (%a and %b) and the result may be of integer types of any bit 14635width, but they must have the same bit width. ``%a`` and ``%b`` are the two 14636values that will undergo unsigned fixed point division. The argument 14637``%scale`` represents the scale of both operands, and must be a constant 14638integer. 14639 14640Semantics: 14641"""""""""" 14642 14643This operation performs fixed point division on the 2 arguments of a 14644specified scale. The result will also be returned in the same scale specified 14645in the third argument. 14646 14647If the result value cannot be precisely represented in the given scale, the 14648value is rounded up or down to the closest representable value. The rounding 14649direction is unspecified. 14650 14651The maximum value this operation can clamp to is the largest unsigned value 14652representable by the bit width of the first 2 arguments. The minimum value is the 14653smallest unsigned value representable by this bit width (zero). 14654 14655It is undefined behavior if the second argument is zero. 14656 14657Examples 14658""""""""" 14659 14660.. code-block:: llvm 14661 14662 %res = call i4 @llvm.udiv.fix.sat.i4(i4 6, i4 2, i32 0) ; %res = 3 (6 / 2 = 3) 14663 %res = call i4 @llvm.udiv.fix.sat.i4(i4 6, i4 4, i32 1) ; %res = 3 (3 / 2 = 1.5) 14664 14665 ; The result in the following could be rounded down to 0.5 or up to 1 14666 %res = call i4 @llvm.udiv.fix.sat.i4(i4 3, i4 4, i32 1) ; %res = 1 (or 2) (1.5 / 2 = 0.75) 14667 14668 ; Saturation 14669 %res = call i4 @llvm.udiv.fix.sat.i4(i4 8, i4 2, i32 2) ; %res = 15 (2 / 0.5 = 4 => 3.75) 14670 14671 14672Specialised Arithmetic Intrinsics 14673--------------------------------- 14674 14675.. _i_intr_llvm_canonicalize: 14676 14677'``llvm.canonicalize.*``' Intrinsic 14678^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14679 14680Syntax: 14681""""""" 14682 14683:: 14684 14685 declare float @llvm.canonicalize.f32(float %a) 14686 declare double @llvm.canonicalize.f64(double %b) 14687 14688Overview: 14689""""""""" 14690 14691The '``llvm.canonicalize.*``' intrinsic returns the platform specific canonical 14692encoding of a floating-point number. This canonicalization is useful for 14693implementing certain numeric primitives such as frexp. The canonical encoding is 14694defined by IEEE-754-2008 to be: 14695 14696:: 14697 14698 2.1.8 canonical encoding: The preferred encoding of a floating-point 14699 representation in a format. Applied to declets, significands of finite 14700 numbers, infinities, and NaNs, especially in decimal formats. 14701 14702This operation can also be considered equivalent to the IEEE-754-2008 14703conversion of a floating-point value to the same format. NaNs are handled 14704according to section 6.2. 14705 14706Examples of non-canonical encodings: 14707 14708- x87 pseudo denormals, pseudo NaNs, pseudo Infinity, Unnormals. These are 14709 converted to a canonical representation per hardware-specific protocol. 14710- Many normal decimal floating-point numbers have non-canonical alternative 14711 encodings. 14712- Some machines, like GPUs or ARMv7 NEON, do not support subnormal values. 14713 These are treated as non-canonical encodings of zero and will be flushed to 14714 a zero of the same sign by this operation. 14715 14716Note that per IEEE-754-2008 6.2, systems that support signaling NaNs with 14717default exception handling must signal an invalid exception, and produce a 14718quiet NaN result. 14719 14720This function should always be implementable as multiplication by 1.0, provided 14721that the compiler does not constant fold the operation. Likewise, division by 147221.0 and ``llvm.minnum(x, x)`` are possible implementations. Addition with 14723-0.0 is also sufficient provided that the rounding mode is not -Infinity. 14724 14725``@llvm.canonicalize`` must preserve the equality relation. That is: 14726 14727- ``(@llvm.canonicalize(x) == x)`` is equivalent to ``(x == x)`` 14728- ``(@llvm.canonicalize(x) == @llvm.canonicalize(y))`` is equivalent to 14729 to ``(x == y)`` 14730 14731Additionally, the sign of zero must be conserved: 14732``@llvm.canonicalize(-0.0) = -0.0`` and ``@llvm.canonicalize(+0.0) = +0.0`` 14733 14734The payload bits of a NaN must be conserved, with two exceptions. 14735First, environments which use only a single canonical representation of NaN 14736must perform said canonicalization. Second, SNaNs must be quieted per the 14737usual methods. 14738 14739The canonicalization operation may be optimized away if: 14740 14741- The input is known to be canonical. For example, it was produced by a 14742 floating-point operation that is required by the standard to be canonical. 14743- The result is consumed only by (or fused with) other floating-point 14744 operations. That is, the bits of the floating-point value are not examined. 14745 14746'``llvm.fmuladd.*``' Intrinsic 14747^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14748 14749Syntax: 14750""""""" 14751 14752:: 14753 14754 declare float @llvm.fmuladd.f32(float %a, float %b, float %c) 14755 declare double @llvm.fmuladd.f64(double %a, double %b, double %c) 14756 14757Overview: 14758""""""""" 14759 14760The '``llvm.fmuladd.*``' intrinsic functions represent multiply-add 14761expressions that can be fused if the code generator determines that (a) the 14762target instruction set has support for a fused operation, and (b) that the 14763fused operation is more efficient than the equivalent, separate pair of mul 14764and add instructions. 14765 14766Arguments: 14767"""""""""" 14768 14769The '``llvm.fmuladd.*``' intrinsics each take three arguments: two 14770multiplicands, a and b, and an addend c. 14771 14772Semantics: 14773"""""""""" 14774 14775The expression: 14776 14777:: 14778 14779 %0 = call float @llvm.fmuladd.f32(%a, %b, %c) 14780 14781is equivalent to the expression a \* b + c, except that it is unspecified 14782whether rounding will be performed between the multiplication and addition 14783steps. Fusion is not guaranteed, even if the target platform supports it. 14784If a fused multiply-add is required, the corresponding 14785:ref:`llvm.fma <int_fma>` intrinsic function should be used instead. 14786This never sets errno, just as '``llvm.fma.*``'. 14787 14788Examples: 14789""""""""" 14790 14791.. code-block:: llvm 14792 14793 %r2 = call float @llvm.fmuladd.f32(float %a, float %b, float %c) ; yields float:r2 = (a * b) + c 14794 14795 14796Experimental Vector Reduction Intrinsics 14797---------------------------------------- 14798 14799Horizontal reductions of vectors can be expressed using the following 14800intrinsics. Each one takes a vector operand as an input and applies its 14801respective operation across all elements of the vector, returning a single 14802scalar result of the same element type. 14803 14804 14805'``llvm.experimental.vector.reduce.add.*``' Intrinsic 14806^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14807 14808Syntax: 14809""""""" 14810 14811:: 14812 14813 declare i32 @llvm.experimental.vector.reduce.add.v4i32(<4 x i32> %a) 14814 declare i64 @llvm.experimental.vector.reduce.add.v2i64(<2 x i64> %a) 14815 14816Overview: 14817""""""""" 14818 14819The '``llvm.experimental.vector.reduce.add.*``' intrinsics do an integer ``ADD`` 14820reduction of a vector, returning the result as a scalar. The return type matches 14821the element-type of the vector input. 14822 14823Arguments: 14824"""""""""" 14825The argument to this intrinsic must be a vector of integer values. 14826 14827'``llvm.experimental.vector.reduce.v2.fadd.*``' Intrinsic 14828^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14829 14830Syntax: 14831""""""" 14832 14833:: 14834 14835 declare float @llvm.experimental.vector.reduce.v2.fadd.f32.v4f32(float %start_value, <4 x float> %a) 14836 declare double @llvm.experimental.vector.reduce.v2.fadd.f64.v2f64(double %start_value, <2 x double> %a) 14837 14838Overview: 14839""""""""" 14840 14841The '``llvm.experimental.vector.reduce.v2.fadd.*``' intrinsics do a floating-point 14842``ADD`` reduction of a vector, returning the result as a scalar. The return type 14843matches the element-type of the vector input. 14844 14845If the intrinsic call has the 'reassoc' or 'fast' flags set, then the 14846reduction will not preserve the associativity of an equivalent scalarized 14847counterpart. Otherwise the reduction will be *ordered*, thus implying that 14848the operation respects the associativity of a scalarized reduction. 14849 14850 14851Arguments: 14852"""""""""" 14853The first argument to this intrinsic is a scalar start value for the reduction. 14854The type of the start value matches the element-type of the vector input. 14855The second argument must be a vector of floating-point values. 14856 14857Examples: 14858""""""""" 14859 14860:: 14861 14862 %unord = call reassoc float @llvm.experimental.vector.reduce.v2.fadd.f32.v4f32(float 0.0, <4 x float> %input) ; unordered reduction 14863 %ord = call float @llvm.experimental.vector.reduce.v2.fadd.f32.v4f32(float %start_value, <4 x float> %input) ; ordered reduction 14864 14865 14866'``llvm.experimental.vector.reduce.mul.*``' Intrinsic 14867^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14868 14869Syntax: 14870""""""" 14871 14872:: 14873 14874 declare i32 @llvm.experimental.vector.reduce.mul.v4i32(<4 x i32> %a) 14875 declare i64 @llvm.experimental.vector.reduce.mul.v2i64(<2 x i64> %a) 14876 14877Overview: 14878""""""""" 14879 14880The '``llvm.experimental.vector.reduce.mul.*``' intrinsics do an integer ``MUL`` 14881reduction of a vector, returning the result as a scalar. The return type matches 14882the element-type of the vector input. 14883 14884Arguments: 14885"""""""""" 14886The argument to this intrinsic must be a vector of integer values. 14887 14888'``llvm.experimental.vector.reduce.v2.fmul.*``' Intrinsic 14889^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14890 14891Syntax: 14892""""""" 14893 14894:: 14895 14896 declare float @llvm.experimental.vector.reduce.v2.fmul.f32.v4f32(float %start_value, <4 x float> %a) 14897 declare double @llvm.experimental.vector.reduce.v2.fmul.f64.v2f64(double %start_value, <2 x double> %a) 14898 14899Overview: 14900""""""""" 14901 14902The '``llvm.experimental.vector.reduce.v2.fmul.*``' intrinsics do a floating-point 14903``MUL`` reduction of a vector, returning the result as a scalar. The return type 14904matches the element-type of the vector input. 14905 14906If the intrinsic call has the 'reassoc' or 'fast' flags set, then the 14907reduction will not preserve the associativity of an equivalent scalarized 14908counterpart. Otherwise the reduction will be *ordered*, thus implying that 14909the operation respects the associativity of a scalarized reduction. 14910 14911 14912Arguments: 14913"""""""""" 14914The first argument to this intrinsic is a scalar start value for the reduction. 14915The type of the start value matches the element-type of the vector input. 14916The second argument must be a vector of floating-point values. 14917 14918Examples: 14919""""""""" 14920 14921:: 14922 14923 %unord = call reassoc float @llvm.experimental.vector.reduce.v2.fmul.f32.v4f32(float 1.0, <4 x float> %input) ; unordered reduction 14924 %ord = call float @llvm.experimental.vector.reduce.v2.fmul.f32.v4f32(float %start_value, <4 x float> %input) ; ordered reduction 14925 14926'``llvm.experimental.vector.reduce.and.*``' Intrinsic 14927^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14928 14929Syntax: 14930""""""" 14931 14932:: 14933 14934 declare i32 @llvm.experimental.vector.reduce.and.v4i32(<4 x i32> %a) 14935 14936Overview: 14937""""""""" 14938 14939The '``llvm.experimental.vector.reduce.and.*``' intrinsics do a bitwise ``AND`` 14940reduction of a vector, returning the result as a scalar. The return type matches 14941the element-type of the vector input. 14942 14943Arguments: 14944"""""""""" 14945The argument to this intrinsic must be a vector of integer values. 14946 14947'``llvm.experimental.vector.reduce.or.*``' Intrinsic 14948^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14949 14950Syntax: 14951""""""" 14952 14953:: 14954 14955 declare i32 @llvm.experimental.vector.reduce.or.v4i32(<4 x i32> %a) 14956 14957Overview: 14958""""""""" 14959 14960The '``llvm.experimental.vector.reduce.or.*``' intrinsics do a bitwise ``OR`` reduction 14961of a vector, returning the result as a scalar. The return type matches the 14962element-type of the vector input. 14963 14964Arguments: 14965"""""""""" 14966The argument to this intrinsic must be a vector of integer values. 14967 14968'``llvm.experimental.vector.reduce.xor.*``' Intrinsic 14969^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14970 14971Syntax: 14972""""""" 14973 14974:: 14975 14976 declare i32 @llvm.experimental.vector.reduce.xor.v4i32(<4 x i32> %a) 14977 14978Overview: 14979""""""""" 14980 14981The '``llvm.experimental.vector.reduce.xor.*``' intrinsics do a bitwise ``XOR`` 14982reduction of a vector, returning the result as a scalar. The return type matches 14983the element-type of the vector input. 14984 14985Arguments: 14986"""""""""" 14987The argument to this intrinsic must be a vector of integer values. 14988 14989'``llvm.experimental.vector.reduce.smax.*``' Intrinsic 14990^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14991 14992Syntax: 14993""""""" 14994 14995:: 14996 14997 declare i32 @llvm.experimental.vector.reduce.smax.v4i32(<4 x i32> %a) 14998 14999Overview: 15000""""""""" 15001 15002The '``llvm.experimental.vector.reduce.smax.*``' intrinsics do a signed integer 15003``MAX`` reduction of a vector, returning the result as a scalar. The return type 15004matches the element-type of the vector input. 15005 15006Arguments: 15007"""""""""" 15008The argument to this intrinsic must be a vector of integer values. 15009 15010'``llvm.experimental.vector.reduce.smin.*``' Intrinsic 15011^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15012 15013Syntax: 15014""""""" 15015 15016:: 15017 15018 declare i32 @llvm.experimental.vector.reduce.smin.v4i32(<4 x i32> %a) 15019 15020Overview: 15021""""""""" 15022 15023The '``llvm.experimental.vector.reduce.smin.*``' intrinsics do a signed integer 15024``MIN`` reduction of a vector, returning the result as a scalar. The return type 15025matches the element-type of the vector input. 15026 15027Arguments: 15028"""""""""" 15029The argument to this intrinsic must be a vector of integer values. 15030 15031'``llvm.experimental.vector.reduce.umax.*``' Intrinsic 15032^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15033 15034Syntax: 15035""""""" 15036 15037:: 15038 15039 declare i32 @llvm.experimental.vector.reduce.umax.v4i32(<4 x i32> %a) 15040 15041Overview: 15042""""""""" 15043 15044The '``llvm.experimental.vector.reduce.umax.*``' intrinsics do an unsigned 15045integer ``MAX`` reduction of a vector, returning the result as a scalar. The 15046return type matches the element-type of the vector input. 15047 15048Arguments: 15049"""""""""" 15050The argument to this intrinsic must be a vector of integer values. 15051 15052'``llvm.experimental.vector.reduce.umin.*``' Intrinsic 15053^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15054 15055Syntax: 15056""""""" 15057 15058:: 15059 15060 declare i32 @llvm.experimental.vector.reduce.umin.v4i32(<4 x i32> %a) 15061 15062Overview: 15063""""""""" 15064 15065The '``llvm.experimental.vector.reduce.umin.*``' intrinsics do an unsigned 15066integer ``MIN`` reduction of a vector, returning the result as a scalar. The 15067return type matches the element-type of the vector input. 15068 15069Arguments: 15070"""""""""" 15071The argument to this intrinsic must be a vector of integer values. 15072 15073'``llvm.experimental.vector.reduce.fmax.*``' Intrinsic 15074^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15075 15076Syntax: 15077""""""" 15078 15079:: 15080 15081 declare float @llvm.experimental.vector.reduce.fmax.v4f32(<4 x float> %a) 15082 declare double @llvm.experimental.vector.reduce.fmax.v2f64(<2 x double> %a) 15083 15084Overview: 15085""""""""" 15086 15087The '``llvm.experimental.vector.reduce.fmax.*``' intrinsics do a floating-point 15088``MAX`` reduction of a vector, returning the result as a scalar. The return type 15089matches the element-type of the vector input. 15090 15091If the intrinsic call has the ``nnan`` fast-math flag then the operation can 15092assume that NaNs are not present in the input vector. 15093 15094Arguments: 15095"""""""""" 15096The argument to this intrinsic must be a vector of floating-point values. 15097 15098'``llvm.experimental.vector.reduce.fmin.*``' Intrinsic 15099^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15100 15101Syntax: 15102""""""" 15103 15104:: 15105 15106 declare float @llvm.experimental.vector.reduce.fmin.v4f32(<4 x float> %a) 15107 declare double @llvm.experimental.vector.reduce.fmin.v2f64(<2 x double> %a) 15108 15109Overview: 15110""""""""" 15111 15112The '``llvm.experimental.vector.reduce.fmin.*``' intrinsics do a floating-point 15113``MIN`` reduction of a vector, returning the result as a scalar. The return type 15114matches the element-type of the vector input. 15115 15116If the intrinsic call has the ``nnan`` fast-math flag then the operation can 15117assume that NaNs are not present in the input vector. 15118 15119Arguments: 15120"""""""""" 15121The argument to this intrinsic must be a vector of floating-point values. 15122 15123Matrix Intrinsics 15124----------------- 15125 15126Operations on matrixes requiring shape information (like number of rows/columns 15127or the memory layout) can be expressed using the matrix intrinsics. Matrixes are 15128embedded in a flat vector and the intrinsics take the dimensions as arguments. 15129Currently column-major layout is assumed. The intrinsics support both integer 15130and floating point matrixes. 15131 15132 15133'``llvm.matrix.transpose.*``' Intrinsic 15134^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15135 15136Syntax: 15137""""""" 15138 15139:: 15140 15141 declare vectorty @llvm.matrix.transpose.*(vectorty %In, i32 <Rows>, i32 <Cols>) 15142 15143Overview: 15144""""""""" 15145 15146The '``llvm.matrix.transpose.*``' intrinsic treats %In as containing a matrix 15147with <Rows> rows and <Cols> columns and returns the transposed matrix embedded in 15148the result vector. 15149 15150Arguments: 15151"""""""""" 15152 15153The <Rows> and <Cols> arguments must be constant integers. The vector argument 15154%In and the returned vector must have <Rows> * <Cols> elements. 15155 15156'``llvm.matrix.multiply.*``' Intrinsic 15157^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15158 15159Syntax: 15160""""""" 15161 15162:: 15163 15164 declare vectorty @llvm.matrix.multiply.*(vectorty %A, vectorty %B, i32 <M>, i32 <N>, i32 <K>) 15165 15166Overview: 15167""""""""" 15168 15169The '``llvm.matrix.multiply.*``' intrinsic treats %A as matrix with <M> rows and <K> columns, %B as 15170matrix with <K> rows and <N> columns and multiplies them. The result matrix is returned embedded in the 15171result vector. 15172 15173Arguments: 15174"""""""""" 15175 15176The <M>, <N> and <K> arguments must be constant integers. The vector argument %A 15177must have <M> * <K> elements, %B must have <K> * <N> elements and the returned 15178vector must have <M> * <N> elements. 15179 15180 15181'``llvm.matrix.columnwise.load.*``' Intrinsic 15182^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15183 15184Syntax: 15185""""""" 15186 15187:: 15188 15189 declare vectorty @llvm.matrix.columnwise.load.*(ptrty %Ptr, i32 %Stride, i32 <Rows>, i32 <Cols>) 15190 15191Overview: 15192""""""""" 15193 15194The '``llvm.matrix.columnwise.load.*``' intrinsic loads a matrix with <Rows> 15195rows and <Cols> columns, using a stride of %Stride between columns. For two 15196consecutive columns A and B, %Stride refers to the distance (the number of 15197elements) between the start of column A and the start of column B. The result 15198matrix is returned embedded in the result vector. This allows for convenient 15199loading of sub matrixes. 15200 15201Arguments: 15202"""""""""" 15203 15204The <Rows> and <Cols> arguments must be constant integers. The returned vector 15205must have <Rows> * <Cols> elements. %Stride must be >= <Rows>. 15206 15207'``llvm.matrix.columnwise.store.*``' Intrinsic 15208^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15209 15210Syntax: 15211""""""" 15212 15213:: 15214 15215 declare void @llvm.matrix.columnwise.store.*(vectorty %In, ptrty %Ptr, i32 %Stride, i32 <Rows>, i32 <Cols>) 15216 15217Overview: 15218""""""""" 15219 15220The '``llvm.matrix.columnwise.store.*``' intrinsic stores the matrix with 15221<Rows> rows and <Cols> columns embedded in %In, using a stride of %Stride 15222between columns. For two consecutive columns A and B, %Stride refers to the 15223distance (the number of elements) between the start of column A and the start 15224of column B. 15225 15226Arguments: 15227"""""""""" 15228 15229The <Rows> and <Cols> arguments must be constant integers. The vector argument 15230%In must have <Rows> * <Cols> elements. %Stride must be >= <Rows>. 15231 15232Half Precision Floating-Point Intrinsics 15233---------------------------------------- 15234 15235For most target platforms, half precision floating-point is a 15236storage-only format. This means that it is a dense encoding (in memory) 15237but does not support computation in the format. 15238 15239This means that code must first load the half-precision floating-point 15240value as an i16, then convert it to float with 15241:ref:`llvm.convert.from.fp16 <int_convert_from_fp16>`. Computation can 15242then be performed on the float value (including extending to double 15243etc). To store the value back to memory, it is first converted to float 15244if needed, then converted to i16 with 15245:ref:`llvm.convert.to.fp16 <int_convert_to_fp16>`, then storing as an 15246i16 value. 15247 15248.. _int_convert_to_fp16: 15249 15250'``llvm.convert.to.fp16``' Intrinsic 15251^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15252 15253Syntax: 15254""""""" 15255 15256:: 15257 15258 declare i16 @llvm.convert.to.fp16.f32(float %a) 15259 declare i16 @llvm.convert.to.fp16.f64(double %a) 15260 15261Overview: 15262""""""""" 15263 15264The '``llvm.convert.to.fp16``' intrinsic function performs a conversion from a 15265conventional floating-point type to half precision floating-point format. 15266 15267Arguments: 15268"""""""""" 15269 15270The intrinsic function contains single argument - the value to be 15271converted. 15272 15273Semantics: 15274"""""""""" 15275 15276The '``llvm.convert.to.fp16``' intrinsic function performs a conversion from a 15277conventional floating-point format to half precision floating-point format. The 15278return value is an ``i16`` which contains the converted number. 15279 15280Examples: 15281""""""""" 15282 15283.. code-block:: llvm 15284 15285 %res = call i16 @llvm.convert.to.fp16.f32(float %a) 15286 store i16 %res, i16* @x, align 2 15287 15288.. _int_convert_from_fp16: 15289 15290'``llvm.convert.from.fp16``' Intrinsic 15291^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15292 15293Syntax: 15294""""""" 15295 15296:: 15297 15298 declare float @llvm.convert.from.fp16.f32(i16 %a) 15299 declare double @llvm.convert.from.fp16.f64(i16 %a) 15300 15301Overview: 15302""""""""" 15303 15304The '``llvm.convert.from.fp16``' intrinsic function performs a 15305conversion from half precision floating-point format to single precision 15306floating-point format. 15307 15308Arguments: 15309"""""""""" 15310 15311The intrinsic function contains single argument - the value to be 15312converted. 15313 15314Semantics: 15315"""""""""" 15316 15317The '``llvm.convert.from.fp16``' intrinsic function performs a 15318conversion from half single precision floating-point format to single 15319precision floating-point format. The input half-float value is 15320represented by an ``i16`` value. 15321 15322Examples: 15323""""""""" 15324 15325.. code-block:: llvm 15326 15327 %a = load i16, i16* @x, align 2 15328 %res = call float @llvm.convert.from.fp16(i16 %a) 15329 15330.. _dbg_intrinsics: 15331 15332Debugger Intrinsics 15333------------------- 15334 15335The LLVM debugger intrinsics (which all start with ``llvm.dbg.`` 15336prefix), are described in the `LLVM Source Level 15337Debugging <SourceLevelDebugging.html#format-common-intrinsics>`_ 15338document. 15339 15340Exception Handling Intrinsics 15341----------------------------- 15342 15343The LLVM exception handling intrinsics (which all start with 15344``llvm.eh.`` prefix), are described in the `LLVM Exception 15345Handling <ExceptionHandling.html#format-common-intrinsics>`_ document. 15346 15347.. _int_trampoline: 15348 15349Trampoline Intrinsics 15350--------------------- 15351 15352These intrinsics make it possible to excise one parameter, marked with 15353the :ref:`nest <nest>` attribute, from a function. The result is a 15354callable function pointer lacking the nest parameter - the caller does 15355not need to provide a value for it. Instead, the value to use is stored 15356in advance in a "trampoline", a block of memory usually allocated on the 15357stack, which also contains code to splice the nest value into the 15358argument list. This is used to implement the GCC nested function address 15359extension. 15360 15361For example, if the function is ``i32 f(i8* nest %c, i32 %x, i32 %y)`` 15362then the resulting function pointer has signature ``i32 (i32, i32)*``. 15363It can be created as follows: 15364 15365.. code-block:: llvm 15366 15367 %tramp = alloca [10 x i8], align 4 ; size and alignment only correct for X86 15368 %tramp1 = getelementptr [10 x i8], [10 x i8]* %tramp, i32 0, i32 0 15369 call i8* @llvm.init.trampoline(i8* %tramp1, i8* bitcast (i32 (i8*, i32, i32)* @f to i8*), i8* %nval) 15370 %p = call i8* @llvm.adjust.trampoline(i8* %tramp1) 15371 %fp = bitcast i8* %p to i32 (i32, i32)* 15372 15373The call ``%val = call i32 %fp(i32 %x, i32 %y)`` is then equivalent to 15374``%val = call i32 %f(i8* %nval, i32 %x, i32 %y)``. 15375 15376.. _int_it: 15377 15378'``llvm.init.trampoline``' Intrinsic 15379^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15380 15381Syntax: 15382""""""" 15383 15384:: 15385 15386 declare void @llvm.init.trampoline(i8* <tramp>, i8* <func>, i8* <nval>) 15387 15388Overview: 15389""""""""" 15390 15391This fills the memory pointed to by ``tramp`` with executable code, 15392turning it into a trampoline. 15393 15394Arguments: 15395"""""""""" 15396 15397The ``llvm.init.trampoline`` intrinsic takes three arguments, all 15398pointers. The ``tramp`` argument must point to a sufficiently large and 15399sufficiently aligned block of memory; this memory is written to by the 15400intrinsic. Note that the size and the alignment are target-specific - 15401LLVM currently provides no portable way of determining them, so a 15402front-end that generates this intrinsic needs to have some 15403target-specific knowledge. The ``func`` argument must hold a function 15404bitcast to an ``i8*``. 15405 15406Semantics: 15407"""""""""" 15408 15409The block of memory pointed to by ``tramp`` is filled with target 15410dependent code, turning it into a function. Then ``tramp`` needs to be 15411passed to :ref:`llvm.adjust.trampoline <int_at>` to get a pointer which can 15412be :ref:`bitcast (to a new function) and called <int_trampoline>`. The new 15413function's signature is the same as that of ``func`` with any arguments 15414marked with the ``nest`` attribute removed. At most one such ``nest`` 15415argument is allowed, and it must be of pointer type. Calling the new 15416function is equivalent to calling ``func`` with the same argument list, 15417but with ``nval`` used for the missing ``nest`` argument. If, after 15418calling ``llvm.init.trampoline``, the memory pointed to by ``tramp`` is 15419modified, then the effect of any later call to the returned function 15420pointer is undefined. 15421 15422.. _int_at: 15423 15424'``llvm.adjust.trampoline``' Intrinsic 15425^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15426 15427Syntax: 15428""""""" 15429 15430:: 15431 15432 declare i8* @llvm.adjust.trampoline(i8* <tramp>) 15433 15434Overview: 15435""""""""" 15436 15437This performs any required machine-specific adjustment to the address of 15438a trampoline (passed as ``tramp``). 15439 15440Arguments: 15441"""""""""" 15442 15443``tramp`` must point to a block of memory which already has trampoline 15444code filled in by a previous call to 15445:ref:`llvm.init.trampoline <int_it>`. 15446 15447Semantics: 15448"""""""""" 15449 15450On some architectures the address of the code to be executed needs to be 15451different than the address where the trampoline is actually stored. This 15452intrinsic returns the executable address corresponding to ``tramp`` 15453after performing the required machine specific adjustments. The pointer 15454returned can then be :ref:`bitcast and executed <int_trampoline>`. 15455 15456 15457.. _int_vp: 15458 15459Vector Predication Intrinsics 15460----------------------------- 15461VP intrinsics are intended for predicated SIMD/vector code. A typical VP 15462operation takes a vector mask and an explicit vector length parameter as in: 15463 15464:: 15465 15466 <W x T> llvm.vp.<opcode>.*(<W x T> %x, <W x T> %y, <W x i1> %mask, i32 %evl) 15467 15468The vector mask parameter (%mask) always has a vector of `i1` type, for example 15469`<32 x i1>`. The explicit vector length parameter always has the type `i32` and 15470is an unsigned integer value. The explicit vector length parameter (%evl) is in 15471the range: 15472 15473:: 15474 15475 0 <= %evl <= W, where W is the number of vector elements 15476 15477Note that for :ref:`scalable vector types <t_vector>` ``W`` is the runtime 15478length of the vector. 15479 15480The VP intrinsic has undefined behavior if ``%evl > W``. The explicit vector 15481length (%evl) creates a mask, %EVLmask, with all elements ``0 <= i < %evl`` set 15482to True, and all other lanes ``%evl <= i < W`` to False. A new mask %M is 15483calculated with an element-wise AND from %mask and %EVLmask: 15484 15485:: 15486 15487 M = %mask AND %EVLmask 15488 15489A vector operation ``<opcode>`` on vectors ``A`` and ``B`` calculates: 15490 15491:: 15492 15493 A <opcode> B = { A[i] <opcode> B[i] M[i] = True, and 15494 { undef otherwise 15495 15496Optimization Hint 15497^^^^^^^^^^^^^^^^^ 15498 15499Some targets, such as AVX512, do not support the %evl parameter in hardware. 15500The use of an effective %evl is discouraged for those targets. The function 15501``TargetTransformInfo::hasActiveVectorLength()`` returns true when the target 15502has native support for %evl. 15503 15504 15505.. _int_vp_add: 15506 15507'``llvm.vp.add.*``' Intrinsics 15508^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15509 15510Syntax: 15511""""""" 15512This is an overloaded intrinsic. 15513 15514:: 15515 15516 declare <16 x i32> @llvm.vp.add.v16i32 (<16 x i32> <left_op>, <16 x i32> <right_op>, <16 x i1> <mask>, i32 <vector_length>) 15517 declare <vscale x 4 x i32> @llvm.vp.add.nxv4i32 (<vscale x 4 x i32> <left_op>, <vscale x 4 x i32> <right_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>) 15518 declare <256 x i64> @llvm.vp.add.v256i64 (<256 x i64> <left_op>, <256 x i64> <right_op>, <256 x i1> <mask>, i32 <vector_length>) 15519 15520Overview: 15521""""""""" 15522 15523Predicated integer addition of two vectors of integers. 15524 15525 15526Arguments: 15527"""""""""" 15528 15529The first two operands and the result have the same vector of integer type. The 15530third operand is the vector mask and has the same number of elements as the 15531result vector type. The fourth operand is the explicit vector length of the 15532operation. 15533 15534Semantics: 15535"""""""""" 15536 15537The '``llvm.vp.add``' intrinsic performs integer addition (:ref:`add <i_add>`) 15538of the first and second vector operand on each enabled lane. The result on 15539disabled lanes is undefined. 15540 15541Examples: 15542""""""""" 15543 15544.. code-block:: llvm 15545 15546 %r = call <4 x i32> @llvm.vp.add.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 15547 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 15548 15549 %t = add <4 x i32> %a, %b 15550 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 15551 15552.. _int_vp_sub: 15553 15554'``llvm.vp.sub.*``' Intrinsics 15555^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15556 15557Syntax: 15558""""""" 15559This is an overloaded intrinsic. 15560 15561:: 15562 15563 declare <16 x i32> @llvm.vp.sub.v16i32 (<16 x i32> <left_op>, <16 x i32> <right_op>, <16 x i1> <mask>, i32 <vector_length>) 15564 declare <vscale x 4 x i32> @llvm.vp.sub.nxv4i32 (<vscale x 4 x i32> <left_op>, <vscale x 4 x i32> <right_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>) 15565 declare <256 x i64> @llvm.vp.sub.v256i64 (<256 x i64> <left_op>, <256 x i64> <right_op>, <256 x i1> <mask>, i32 <vector_length>) 15566 15567Overview: 15568""""""""" 15569 15570Predicated integer subtraction of two vectors of integers. 15571 15572 15573Arguments: 15574"""""""""" 15575 15576The first two operands and the result have the same vector of integer type. The 15577third operand is the vector mask and has the same number of elements as the 15578result vector type. The fourth operand is the explicit vector length of the 15579operation. 15580 15581Semantics: 15582"""""""""" 15583 15584The '``llvm.vp.sub``' intrinsic performs integer subtraction 15585(:ref:`sub <i_sub>`) of the first and second vector operand on each enabled 15586lane. The result on disabled lanes is undefined. 15587 15588Examples: 15589""""""""" 15590 15591.. code-block:: llvm 15592 15593 %r = call <4 x i32> @llvm.vp.sub.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 15594 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 15595 15596 %t = sub <4 x i32> %a, %b 15597 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 15598 15599 15600 15601.. _int_vp_mul: 15602 15603'``llvm.vp.mul.*``' Intrinsics 15604^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15605 15606Syntax: 15607""""""" 15608This is an overloaded intrinsic. 15609 15610:: 15611 15612 declare <16 x i32> @llvm.vp.mul.v16i32 (<16 x i32> <left_op>, <16 x i32> <right_op>, <16 x i1> <mask>, i32 <vector_length>) 15613 declare <vscale x 4 x i32> @llvm.vp.mul.nxv46i32 (<vscale x 4 x i32> <left_op>, <vscale x 4 x i32> <right_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>) 15614 declare <256 x i64> @llvm.vp.mul.v256i64 (<256 x i64> <left_op>, <256 x i64> <right_op>, <256 x i1> <mask>, i32 <vector_length>) 15615 15616Overview: 15617""""""""" 15618 15619Predicated integer multiplication of two vectors of integers. 15620 15621 15622Arguments: 15623"""""""""" 15624 15625The first two operands and the result have the same vector of integer type. The 15626third operand is the vector mask and has the same number of elements as the 15627result vector type. The fourth operand is the explicit vector length of the 15628operation. 15629 15630Semantics: 15631"""""""""" 15632The '``llvm.vp.mul``' intrinsic performs integer multiplication 15633(:ref:`mul <i_mul>`) of the first and second vector operand on each enabled 15634lane. The result on disabled lanes is undefined. 15635 15636Examples: 15637""""""""" 15638 15639.. code-block:: llvm 15640 15641 %r = call <4 x i32> @llvm.vp.mul.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 15642 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 15643 15644 %t = mul <4 x i32> %a, %b 15645 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 15646 15647 15648.. _int_vp_sdiv: 15649 15650'``llvm.vp.sdiv.*``' Intrinsics 15651^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15652 15653Syntax: 15654""""""" 15655This is an overloaded intrinsic. 15656 15657:: 15658 15659 declare <16 x i32> @llvm.vp.sdiv.v16i32 (<16 x i32> <left_op>, <16 x i32> <right_op>, <16 x i1> <mask>, i32 <vector_length>) 15660 declare <vscale x 4 x i32> @llvm.vp.sdiv.nxv4i32 (<vscale x 4 x i32> <left_op>, <vscale x 4 x i32> <right_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>) 15661 declare <256 x i64> @llvm.vp.sdiv.v256i64 (<256 x i64> <left_op>, <256 x i64> <right_op>, <256 x i1> <mask>, i32 <vector_length>) 15662 15663Overview: 15664""""""""" 15665 15666Predicated, signed division of two vectors of integers. 15667 15668 15669Arguments: 15670"""""""""" 15671 15672The first two operands and the result have the same vector of integer type. The 15673third operand is the vector mask and has the same number of elements as the 15674result vector type. The fourth operand is the explicit vector length of the 15675operation. 15676 15677Semantics: 15678"""""""""" 15679 15680The '``llvm.vp.sdiv``' intrinsic performs signed division (:ref:`sdiv <i_sdiv>`) 15681of the first and second vector operand on each enabled lane. The result on 15682disabled lanes is undefined. 15683 15684Examples: 15685""""""""" 15686 15687.. code-block:: llvm 15688 15689 %r = call <4 x i32> @llvm.vp.sdiv.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 15690 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 15691 15692 %t = sdiv <4 x i32> %a, %b 15693 %also.r = select <4 x ii> %mask, <4 x i32> %t, <4 x i32> undef 15694 15695 15696.. _int_vp_udiv: 15697 15698'``llvm.vp.udiv.*``' Intrinsics 15699^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15700 15701Syntax: 15702""""""" 15703This is an overloaded intrinsic. 15704 15705:: 15706 15707 declare <16 x i32> @llvm.vp.udiv.v16i32 (<16 x i32> <left_op>, <16 x i32> <right_op>, <16 x i1> <mask>, i32 <vector_length>) 15708 declare <vscale x 4 x i32> @llvm.vp.udiv.nxv4i32 (<vscale x 4 x i32> <left_op>, <vscale x 4 x i32> <right_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>) 15709 declare <256 x i64> @llvm.vp.udiv.v256i64 (<256 x i64> <left_op>, <256 x i64> <right_op>, <256 x i1> <mask>, i32 <vector_length>) 15710 15711Overview: 15712""""""""" 15713 15714Predicated, unsigned division of two vectors of integers. 15715 15716 15717Arguments: 15718"""""""""" 15719 15720The first two operands and the result have the same vector of integer type. The third operand is the vector mask and has the same number of elements as the result vector type. The fourth operand is the explicit vector length of the operation. 15721 15722Semantics: 15723"""""""""" 15724 15725The '``llvm.vp.udiv``' intrinsic performs unsigned division 15726(:ref:`udiv <i_udiv>`) of the first and second vector operand on each enabled 15727lane. The result on disabled lanes is undefined. 15728 15729Examples: 15730""""""""" 15731 15732.. code-block:: llvm 15733 15734 %r = call <4 x i32> @llvm.vp.udiv.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 15735 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 15736 15737 %t = udiv <4 x i32> %a, %b 15738 %also.r = select <4 x ii> %mask, <4 x i32> %t, <4 x i32> undef 15739 15740 15741 15742.. _int_vp_srem: 15743 15744'``llvm.vp.srem.*``' Intrinsics 15745^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15746 15747Syntax: 15748""""""" 15749This is an overloaded intrinsic. 15750 15751:: 15752 15753 declare <16 x i32> @llvm.vp.srem.v16i32 (<16 x i32> <left_op>, <16 x i32> <right_op>, <16 x i1> <mask>, i32 <vector_length>) 15754 declare <vscale x 4 x i32> @llvm.vp.srem.nxv4i32 (<vscale x 4 x i32> <left_op>, <vscale x 4 x i32> <right_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>) 15755 declare <256 x i64> @llvm.vp.srem.v256i64 (<256 x i64> <left_op>, <256 x i64> <right_op>, <256 x i1> <mask>, i32 <vector_length>) 15756 15757Overview: 15758""""""""" 15759 15760Predicated computations of the signed remainder of two integer vectors. 15761 15762 15763Arguments: 15764"""""""""" 15765 15766The first two operands and the result have the same vector of integer type. The 15767third operand is the vector mask and has the same number of elements as the 15768result vector type. The fourth operand is the explicit vector length of the 15769operation. 15770 15771Semantics: 15772"""""""""" 15773 15774The '``llvm.vp.srem``' intrinsic computes the remainder of the signed division 15775(:ref:`srem <i_srem>`) of the first and second vector operand on each enabled 15776lane. The result on disabled lanes is undefined. 15777 15778Examples: 15779""""""""" 15780 15781.. code-block:: llvm 15782 15783 %r = call <4 x i32> @llvm.vp.srem.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 15784 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 15785 15786 %t = srem <4 x i32> %a, %b 15787 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 15788 15789 15790 15791.. _int_vp_urem: 15792 15793'``llvm.vp.urem.*``' Intrinsics 15794^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15795 15796Syntax: 15797""""""" 15798This is an overloaded intrinsic. 15799 15800:: 15801 15802 declare <16 x i32> @llvm.vp.urem.v16i32 (<16 x i32> <left_op>, <16 x i32> <right_op>, <16 x i1> <mask>, i32 <vector_length>) 15803 declare <vscale x 4 x i32> @llvm.vp.urem.nxv4i32 (<vscale x 4 x i32> <left_op>, <vscale x 4 x i32> <right_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>) 15804 declare <256 x i64> @llvm.vp.urem.v256i64 (<256 x i64> <left_op>, <256 x i64> <right_op>, <256 x i1> <mask>, i32 <vector_length>) 15805 15806Overview: 15807""""""""" 15808 15809Predicated computation of the unsigned remainder of two integer vectors. 15810 15811 15812Arguments: 15813"""""""""" 15814 15815The first two operands and the result have the same vector of integer type. The 15816third operand is the vector mask and has the same number of elements as the 15817result vector type. The fourth operand is the explicit vector length of the 15818operation. 15819 15820Semantics: 15821"""""""""" 15822 15823The '``llvm.vp.urem``' intrinsic computes the remainder of the unsigned division 15824(:ref:`urem <i_urem>`) of the first and second vector operand on each enabled 15825lane. The result on disabled lanes is undefined. 15826 15827Examples: 15828""""""""" 15829 15830.. code-block:: llvm 15831 15832 %r = call <4 x i32> @llvm.vp.urem.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 15833 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 15834 15835 %t = urem <4 x i32> %a, %b 15836 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 15837 15838 15839.. _int_vp_ashr: 15840 15841'``llvm.vp.ashr.*``' Intrinsics 15842^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15843 15844Syntax: 15845""""""" 15846This is an overloaded intrinsic. 15847 15848:: 15849 15850 declare <16 x i32> @llvm.vp.ashr.v16i32 (<16 x i32> <left_op>, <16 x i32> <right_op>, <16 x i1> <mask>, i32 <vector_length>) 15851 declare <vscale x 4 x i32> @llvm.vp.ashr.nxv4i32 (<vscale x 4 x i32> <left_op>, <vscale x 4 x i32> <right_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>) 15852 declare <256 x i64> @llvm.vp.ashr.v256i64 (<256 x i64> <left_op>, <256 x i64> <right_op>, <256 x i1> <mask>, i32 <vector_length>) 15853 15854Overview: 15855""""""""" 15856 15857Vector-predicated arithmetic right-shift. 15858 15859 15860Arguments: 15861"""""""""" 15862 15863The first two operands and the result have the same vector of integer type. The 15864third operand is the vector mask and has the same number of elements as the 15865result vector type. The fourth operand is the explicit vector length of the 15866operation. 15867 15868Semantics: 15869"""""""""" 15870 15871The '``llvm.vp.ashr``' intrinsic computes the arithmetic right shift 15872(:ref:`ashr <i_ashr>`) of the first operand by the second operand on each 15873enabled lane. The result on disabled lanes is undefined. 15874 15875Examples: 15876""""""""" 15877 15878.. code-block:: llvm 15879 15880 %r = call <4 x i32> @llvm.vp.ashr.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 15881 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 15882 15883 %t = ashr <4 x i32> %a, %b 15884 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 15885 15886 15887.. _int_vp_lshr: 15888 15889 15890'``llvm.vp.lshr.*``' Intrinsics 15891^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15892 15893Syntax: 15894""""""" 15895This is an overloaded intrinsic. 15896 15897:: 15898 15899 declare <16 x i32> @llvm.vp.lshr.v16i32 (<16 x i32> <left_op>, <16 x i32> <right_op>, <16 x i1> <mask>, i32 <vector_length>) 15900 declare <vscale x 4 x i32> @llvm.vp.lshr.nxv4i32 (<vscale x 4 x i32> <left_op>, <vscale x 4 x i32> <right_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>) 15901 declare <256 x i64> @llvm.vp.lshr.v256i64 (<256 x i64> <left_op>, <256 x i64> <right_op>, <256 x i1> <mask>, i32 <vector_length>) 15902 15903Overview: 15904""""""""" 15905 15906Vector-predicated logical right-shift. 15907 15908 15909Arguments: 15910"""""""""" 15911 15912The first two operands and the result have the same vector of integer type. The 15913third operand is the vector mask and has the same number of elements as the 15914result vector type. The fourth operand is the explicit vector length of the 15915operation. 15916 15917Semantics: 15918"""""""""" 15919 15920The '``llvm.vp.lshr``' intrinsic computes the logical right shift 15921(:ref:`lshr <i_lshr>`) of the first operand by the second operand on each 15922enabled lane. The result on disabled lanes is undefined. 15923 15924Examples: 15925""""""""" 15926 15927.. code-block:: llvm 15928 15929 %r = call <4 x i32> @llvm.vp.lshr.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 15930 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 15931 15932 %t = lshr <4 x i32> %a, %b 15933 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 15934 15935 15936.. _int_vp_shl: 15937 15938'``llvm.vp.shl.*``' Intrinsics 15939^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15940 15941Syntax: 15942""""""" 15943This is an overloaded intrinsic. 15944 15945:: 15946 15947 declare <16 x i32> @llvm.vp.shl.v16i32 (<16 x i32> <left_op>, <16 x i32> <right_op>, <16 x i1> <mask>, i32 <vector_length>) 15948 declare <vscale x 4 x i32> @llvm.vp.shl.nxv4i32 (<vscale x 4 x i32> <left_op>, <vscale x 4 x i32> <right_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>) 15949 declare <256 x i64> @llvm.vp.shl.v256i64 (<256 x i64> <left_op>, <256 x i64> <right_op>, <256 x i1> <mask>, i32 <vector_length>) 15950 15951Overview: 15952""""""""" 15953 15954Vector-predicated left shift. 15955 15956 15957Arguments: 15958"""""""""" 15959 15960The first two operands and the result have the same vector of integer type. The 15961third operand is the vector mask and has the same number of elements as the 15962result vector type. The fourth operand is the explicit vector length of the 15963operation. 15964 15965Semantics: 15966"""""""""" 15967 15968The '``llvm.vp.shl``' intrinsic computes the left shift (:ref:`shl <i_shl>`) of 15969the first operand by the second operand on each enabled lane. The result on 15970disabled lanes is undefined. 15971 15972Examples: 15973""""""""" 15974 15975.. code-block:: llvm 15976 15977 %r = call <4 x i32> @llvm.vp.shl.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 15978 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 15979 15980 %t = shl <4 x i32> %a, %b 15981 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 15982 15983 15984.. _int_vp_or: 15985 15986'``llvm.vp.or.*``' Intrinsics 15987^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15988 15989Syntax: 15990""""""" 15991This is an overloaded intrinsic. 15992 15993:: 15994 15995 declare <16 x i32> @llvm.vp.or.v16i32 (<16 x i32> <left_op>, <16 x i32> <right_op>, <16 x i1> <mask>, i32 <vector_length>) 15996 declare <vscale x 4 x i32> @llvm.vp.or.nxv4i32 (<vscale x 4 x i32> <left_op>, <vscale x 4 x i32> <right_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>) 15997 declare <256 x i64> @llvm.vp.or.v256i64 (<256 x i64> <left_op>, <256 x i64> <right_op>, <256 x i1> <mask>, i32 <vector_length>) 15998 15999Overview: 16000""""""""" 16001 16002Vector-predicated or. 16003 16004 16005Arguments: 16006"""""""""" 16007 16008The first two operands and the result have the same vector of integer type. The 16009third operand is the vector mask and has the same number of elements as the 16010result vector type. The fourth operand is the explicit vector length of the 16011operation. 16012 16013Semantics: 16014"""""""""" 16015 16016The '``llvm.vp.or``' intrinsic performs a bitwise or (:ref:`or <i_or>`) of the 16017first two operands on each enabled lane. The result on disabled lanes is 16018undefined. 16019 16020Examples: 16021""""""""" 16022 16023.. code-block:: llvm 16024 16025 %r = call <4 x i32> @llvm.vp.or.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 16026 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 16027 16028 %t = or <4 x i32> %a, %b 16029 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 16030 16031 16032.. _int_vp_and: 16033 16034'``llvm.vp.and.*``' Intrinsics 16035^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16036 16037Syntax: 16038""""""" 16039This is an overloaded intrinsic. 16040 16041:: 16042 16043 declare <16 x i32> @llvm.vp.and.v16i32 (<16 x i32> <left_op>, <16 x i32> <right_op>, <16 x i1> <mask>, i32 <vector_length>) 16044 declare <vscale x 4 x i32> @llvm.vp.and.nxv4i32 (<vscale x 4 x i32> <left_op>, <vscale x 4 x i32> <right_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>) 16045 declare <256 x i64> @llvm.vp.and.v256i64 (<256 x i64> <left_op>, <256 x i64> <right_op>, <256 x i1> <mask>, i32 <vector_length>) 16046 16047Overview: 16048""""""""" 16049 16050Vector-predicated and. 16051 16052 16053Arguments: 16054"""""""""" 16055 16056The first two operands and the result have the same vector of integer type. The 16057third operand is the vector mask and has the same number of elements as the 16058result vector type. The fourth operand is the explicit vector length of the 16059operation. 16060 16061Semantics: 16062"""""""""" 16063 16064The '``llvm.vp.and``' intrinsic performs a bitwise and (:ref:`and <i_or>`) of 16065the first two operands on each enabled lane. The result on disabled lanes is 16066undefined. 16067 16068Examples: 16069""""""""" 16070 16071.. code-block:: llvm 16072 16073 %r = call <4 x i32> @llvm.vp.and.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 16074 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 16075 16076 %t = and <4 x i32> %a, %b 16077 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 16078 16079 16080.. _int_vp_xor: 16081 16082'``llvm.vp.xor.*``' Intrinsics 16083^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16084 16085Syntax: 16086""""""" 16087This is an overloaded intrinsic. 16088 16089:: 16090 16091 declare <16 x i32> @llvm.vp.xor.v16i32 (<16 x i32> <left_op>, <16 x i32> <right_op>, <16 x i1> <mask>, i32 <vector_length>) 16092 declare <vscale x 4 x i32> @llvm.vp.xor.nxv4i32 (<vscale x 4 x i32> <left_op>, <vscale x 4 x i32> <right_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>) 16093 declare <256 x i64> @llvm.vp.xor.v256i64 (<256 x i64> <left_op>, <256 x i64> <right_op>, <256 x i1> <mask>, i32 <vector_length>) 16094 16095Overview: 16096""""""""" 16097 16098Vector-predicated, bitwise xor. 16099 16100 16101Arguments: 16102"""""""""" 16103 16104The first two operands and the result have the same vector of integer type. The 16105third operand is the vector mask and has the same number of elements as the 16106result vector type. The fourth operand is the explicit vector length of the 16107operation. 16108 16109Semantics: 16110"""""""""" 16111 16112The '``llvm.vp.xor``' intrinsic performs a bitwise xor (:ref:`xor <i_xor>`) of 16113the first two operands on each enabled lane. 16114The result on disabled lanes is undefined. 16115 16116Examples: 16117""""""""" 16118 16119.. code-block:: llvm 16120 16121 %r = call <4 x i32> @llvm.vp.xor.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 16122 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 16123 16124 %t = xor <4 x i32> %a, %b 16125 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 16126 16127 16128.. _int_mload_mstore: 16129 16130Masked Vector Load and Store Intrinsics 16131--------------------------------------- 16132 16133LLVM 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. 16134 16135.. _int_mload: 16136 16137'``llvm.masked.load.*``' Intrinsics 16138^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16139 16140Syntax: 16141""""""" 16142This is an overloaded intrinsic. The loaded data is a vector of any integer, floating-point or pointer data type. 16143 16144:: 16145 16146 declare <16 x float> @llvm.masked.load.v16f32.p0v16f32 (<16 x float>* <ptr>, i32 <alignment>, <16 x i1> <mask>, <16 x float> <passthru>) 16147 declare <2 x double> @llvm.masked.load.v2f64.p0v2f64 (<2 x double>* <ptr>, i32 <alignment>, <2 x i1> <mask>, <2 x double> <passthru>) 16148 ;; The data is a vector of pointers to double 16149 declare <8 x double*> @llvm.masked.load.v8p0f64.p0v8p0f64 (<8 x double*>* <ptr>, i32 <alignment>, <8 x i1> <mask>, <8 x double*> <passthru>) 16150 ;; The data is a vector of function pointers 16151 declare <8 x i32 ()*> @llvm.masked.load.v8p0f_i32f.p0v8p0f_i32f (<8 x i32 ()*>* <ptr>, i32 <alignment>, <8 x i1> <mask>, <8 x i32 ()*> <passthru>) 16152 16153Overview: 16154""""""""" 16155 16156Reads 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. 16157 16158 16159Arguments: 16160"""""""""" 16161 16162The first operand is the base pointer for the load. The second operand is the alignment of the source location. It must be a power of two 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. 16163 16164Semantics: 16165"""""""""" 16166 16167The '``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. 16168The 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. 16169 16170 16171:: 16172 16173 %res = call <16 x float> @llvm.masked.load.v16f32.p0v16f32 (<16 x float>* %ptr, i32 4, <16 x i1>%mask, <16 x float> %passthru) 16174 16175 ;; The result of the two following instructions is identical aside from potential memory access exception 16176 %loadlal = load <16 x float>, <16 x float>* %ptr, align 4 16177 %res = select <16 x i1> %mask, <16 x float> %loadlal, <16 x float> %passthru 16178 16179.. _int_mstore: 16180 16181'``llvm.masked.store.*``' Intrinsics 16182^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16183 16184Syntax: 16185""""""" 16186This is an overloaded intrinsic. The data stored in memory is a vector of any integer, floating-point or pointer data type. 16187 16188:: 16189 16190 declare void @llvm.masked.store.v8i32.p0v8i32 (<8 x i32> <value>, <8 x i32>* <ptr>, i32 <alignment>, <8 x i1> <mask>) 16191 declare void @llvm.masked.store.v16f32.p0v16f32 (<16 x float> <value>, <16 x float>* <ptr>, i32 <alignment>, <16 x i1> <mask>) 16192 ;; The data is a vector of pointers to double 16193 declare void @llvm.masked.store.v8p0f64.p0v8p0f64 (<8 x double*> <value>, <8 x double*>* <ptr>, i32 <alignment>, <8 x i1> <mask>) 16194 ;; The data is a vector of function pointers 16195 declare void @llvm.masked.store.v4p0f_i32f.p0v4p0f_i32f (<4 x i32 ()*> <value>, <4 x i32 ()*>* <ptr>, i32 <alignment>, <4 x i1> <mask>) 16196 16197Overview: 16198""""""""" 16199 16200Writes 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. 16201 16202Arguments: 16203"""""""""" 16204 16205The 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. It must be a power of two constant integer value. 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. 16206 16207 16208Semantics: 16209"""""""""" 16210 16211The '``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. 16212The 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. 16213 16214:: 16215 16216 call void @llvm.masked.store.v16f32.p0v16f32(<16 x float> %value, <16 x float>* %ptr, i32 4, <16 x i1> %mask) 16217 16218 ;; The result of the following instructions is identical aside from potential data races and memory access exceptions 16219 %oldval = load <16 x float>, <16 x float>* %ptr, align 4 16220 %res = select <16 x i1> %mask, <16 x float> %value, <16 x float> %oldval 16221 store <16 x float> %res, <16 x float>* %ptr, align 4 16222 16223 16224Masked Vector Gather and Scatter Intrinsics 16225------------------------------------------- 16226 16227LLVM 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. 16228 16229.. _int_mgather: 16230 16231'``llvm.masked.gather.*``' Intrinsics 16232^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16233 16234Syntax: 16235""""""" 16236This is an overloaded intrinsic. The loaded data are multiple scalar values of any integer, floating-point or pointer data type gathered together into one vector. 16237 16238:: 16239 16240 declare <16 x float> @llvm.masked.gather.v16f32.v16p0f32 (<16 x float*> <ptrs>, i32 <alignment>, <16 x i1> <mask>, <16 x float> <passthru>) 16241 declare <2 x double> @llvm.masked.gather.v2f64.v2p1f64 (<2 x double addrspace(1)*> <ptrs>, i32 <alignment>, <2 x i1> <mask>, <2 x double> <passthru>) 16242 declare <8 x float*> @llvm.masked.gather.v8p0f32.v8p0p0f32 (<8 x float**> <ptrs>, i32 <alignment>, <8 x i1> <mask>, <8 x float*> <passthru>) 16243 16244Overview: 16245""""""""" 16246 16247Reads 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. 16248 16249 16250Arguments: 16251"""""""""" 16252 16253The 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 0 or a power of two 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. 16254 16255Semantics: 16256"""""""""" 16257 16258The '``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. 16259The 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. 16260 16261 16262:: 16263 16264 %res = call <4 x double> @llvm.masked.gather.v4f64.v4p0f64 (<4 x double*> %ptrs, i32 8, <4 x i1> <i1 true, i1 true, i1 true, i1 true>, <4 x double> undef) 16265 16266 ;; The gather with all-true mask is equivalent to the following instruction sequence 16267 %ptr0 = extractelement <4 x double*> %ptrs, i32 0 16268 %ptr1 = extractelement <4 x double*> %ptrs, i32 1 16269 %ptr2 = extractelement <4 x double*> %ptrs, i32 2 16270 %ptr3 = extractelement <4 x double*> %ptrs, i32 3 16271 16272 %val0 = load double, double* %ptr0, align 8 16273 %val1 = load double, double* %ptr1, align 8 16274 %val2 = load double, double* %ptr2, align 8 16275 %val3 = load double, double* %ptr3, align 8 16276 16277 %vec0 = insertelement <4 x double>undef, %val0, 0 16278 %vec01 = insertelement <4 x double>%vec0, %val1, 1 16279 %vec012 = insertelement <4 x double>%vec01, %val2, 2 16280 %vec0123 = insertelement <4 x double>%vec012, %val3, 3 16281 16282.. _int_mscatter: 16283 16284'``llvm.masked.scatter.*``' Intrinsics 16285^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16286 16287Syntax: 16288""""""" 16289This is an overloaded intrinsic. The data stored in memory is a vector of any integer, floating-point or pointer data type. Each vector element is stored in an arbitrary memory address. Scatter with overlapping addresses is guaranteed to be ordered from least-significant to most-significant element. 16290 16291:: 16292 16293 declare void @llvm.masked.scatter.v8i32.v8p0i32 (<8 x i32> <value>, <8 x i32*> <ptrs>, i32 <alignment>, <8 x i1> <mask>) 16294 declare void @llvm.masked.scatter.v16f32.v16p1f32 (<16 x float> <value>, <16 x float addrspace(1)*> <ptrs>, i32 <alignment>, <16 x i1> <mask>) 16295 declare void @llvm.masked.scatter.v4p0f64.v4p0p0f64 (<4 x double*> <value>, <4 x double**> <ptrs>, i32 <alignment>, <4 x i1> <mask>) 16296 16297Overview: 16298""""""""" 16299 16300Writes 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. 16301 16302Arguments: 16303"""""""""" 16304 16305The 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. It must be 0 or a power of two constant integer value. 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. 16306 16307Semantics: 16308"""""""""" 16309 16310The '``llvm.masked.scatter``' intrinsics is designed for writing selected vector elements to arbitrary memory addresses in a single IR operation. The operation may be conditional, when not all bits in the mask are switched on. It is useful for targets that support vector masked scatter and allows vectorizing basic blocks with data and control divergence. Other targets may support this intrinsic differently, for example by lowering it into a sequence of branches that guard scalar store operations. 16311 16312:: 16313 16314 ;; This instruction unconditionally stores data vector in multiple addresses 16315 call @llvm.masked.scatter.v8i32.v8p0i32 (<8 x i32> %value, <8 x i32*> %ptrs, i32 4, <8 x i1> <true, true, .. true>) 16316 16317 ;; It is equivalent to a list of scalar stores 16318 %val0 = extractelement <8 x i32> %value, i32 0 16319 %val1 = extractelement <8 x i32> %value, i32 1 16320 .. 16321 %val7 = extractelement <8 x i32> %value, i32 7 16322 %ptr0 = extractelement <8 x i32*> %ptrs, i32 0 16323 %ptr1 = extractelement <8 x i32*> %ptrs, i32 1 16324 .. 16325 %ptr7 = extractelement <8 x i32*> %ptrs, i32 7 16326 ;; Note: the order of the following stores is important when they overlap: 16327 store i32 %val0, i32* %ptr0, align 4 16328 store i32 %val1, i32* %ptr1, align 4 16329 .. 16330 store i32 %val7, i32* %ptr7, align 4 16331 16332 16333Masked Vector Expanding Load and Compressing Store Intrinsics 16334------------------------------------------------------------- 16335 16336LLVM provides intrinsics for expanding load and compressing store operations. Data selected from a vector according to a mask is stored in consecutive memory addresses (compressed store), and vice-versa (expanding load). These operations effective map to "if (cond.i) a[j++] = v.i" and "if (cond.i) v.i = a[j++]" patterns, respectively. Note that when the mask starts with '1' bits followed by '0' bits, these operations are identical to :ref:`llvm.masked.store <int_mstore>` and :ref:`llvm.masked.load <int_mload>`. 16337 16338.. _int_expandload: 16339 16340'``llvm.masked.expandload.*``' Intrinsics 16341^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16342 16343Syntax: 16344""""""" 16345This is an overloaded intrinsic. Several values of integer, floating point or pointer data type are loaded from consecutive memory addresses and stored into the elements of a vector according to the mask. 16346 16347:: 16348 16349 declare <16 x float> @llvm.masked.expandload.v16f32 (float* <ptr>, <16 x i1> <mask>, <16 x float> <passthru>) 16350 declare <2 x i64> @llvm.masked.expandload.v2i64 (i64* <ptr>, <2 x i1> <mask>, <2 x i64> <passthru>) 16351 16352Overview: 16353""""""""" 16354 16355Reads a number of scalar values sequentially from memory location provided in '``ptr``' and spreads them in a vector. The '``mask``' holds a bit for each vector lane. The number of elements read from memory is equal to the number of '1' bits in the mask. The loaded elements are positioned in the destination vector according to the sequence of '1' and '0' bits in the mask. E.g., if the mask vector is '10010001', "expandload" reads 3 values from memory addresses ptr, ptr+1, ptr+2 and places them in lanes 0, 3 and 7 accordingly. The masked-off lanes are filled by elements from the corresponding lanes of the '``passthru``' operand. 16356 16357 16358Arguments: 16359"""""""""" 16360 16361The first operand is the base pointer for the load. It has the same underlying type as the element of the returned vector. The second operand, mask, is a vector of boolean values with the same number of elements as the return type. The third is a pass-through value that is used to fill the masked-off lanes of the result. The return type and the type of the '``passthru``' operand have the same vector type. 16362 16363Semantics: 16364"""""""""" 16365 16366The '``llvm.masked.expandload``' intrinsic is designed for reading multiple scalar values from adjacent memory addresses into possibly non-adjacent vector lanes. It is useful for targets that support vector expanding loads and allows vectorizing loop with cross-iteration dependency like in the following example: 16367 16368.. code-block:: c 16369 16370 // In this loop we load from B and spread the elements into array A. 16371 double *A, B; int *C; 16372 for (int i = 0; i < size; ++i) { 16373 if (C[i] != 0) 16374 A[i] = B[j++]; 16375 } 16376 16377 16378.. code-block:: llvm 16379 16380 ; Load several elements from array B and expand them in a vector. 16381 ; The number of loaded elements is equal to the number of '1' elements in the Mask. 16382 %Tmp = call <8 x double> @llvm.masked.expandload.v8f64(double* %Bptr, <8 x i1> %Mask, <8 x double> undef) 16383 ; Store the result in A 16384 call void @llvm.masked.store.v8f64.p0v8f64(<8 x double> %Tmp, <8 x double>* %Aptr, i32 8, <8 x i1> %Mask) 16385 16386 ; %Bptr should be increased on each iteration according to the number of '1' elements in the Mask. 16387 %MaskI = bitcast <8 x i1> %Mask to i8 16388 %MaskIPopcnt = call i8 @llvm.ctpop.i8(i8 %MaskI) 16389 %MaskI64 = zext i8 %MaskIPopcnt to i64 16390 %BNextInd = add i64 %BInd, %MaskI64 16391 16392 16393Other targets may support this intrinsic differently, for example, by lowering it into a sequence of conditional scalar load operations and shuffles. 16394If all mask elements are '1', the intrinsic behavior is equivalent to the regular unmasked vector load. 16395 16396.. _int_compressstore: 16397 16398'``llvm.masked.compressstore.*``' Intrinsics 16399^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16400 16401Syntax: 16402""""""" 16403This is an overloaded intrinsic. A number of scalar values of integer, floating point or pointer data type are collected from an input vector and stored into adjacent memory addresses. A mask defines which elements to collect from the vector. 16404 16405:: 16406 16407 declare void @llvm.masked.compressstore.v8i32 (<8 x i32> <value>, i32* <ptr>, <8 x i1> <mask>) 16408 declare void @llvm.masked.compressstore.v16f32 (<16 x float> <value>, float* <ptr>, <16 x i1> <mask>) 16409 16410Overview: 16411""""""""" 16412 16413Selects elements from input vector '``value``' according to the '``mask``'. All selected elements are written into adjacent memory addresses starting at address '`ptr`', from lower to higher. The mask holds a bit for each vector lane, and is used to select elements to be stored. The number of elements to be stored is equal to the number of active bits in the mask. 16414 16415Arguments: 16416"""""""""" 16417 16418The first operand is the input vector, from which elements are collected and written to memory. The second operand is the base pointer for the store, it has the same underlying type as the element of the input vector operand. The third operand is the mask, a vector of boolean values. The mask and the input vector must have the same number of vector elements. 16419 16420 16421Semantics: 16422"""""""""" 16423 16424The '``llvm.masked.compressstore``' intrinsic is designed for compressing data in memory. It allows to collect elements from possibly non-adjacent lanes of a vector and store them contiguously in memory in one IR operation. It is useful for targets that support compressing store operations and allows vectorizing loops with cross-iteration dependences like in the following example: 16425 16426.. code-block:: c 16427 16428 // In this loop we load elements from A and store them consecutively in B 16429 double *A, B; int *C; 16430 for (int i = 0; i < size; ++i) { 16431 if (C[i] != 0) 16432 B[j++] = A[i] 16433 } 16434 16435 16436.. code-block:: llvm 16437 16438 ; Load elements from A. 16439 %Tmp = call <8 x double> @llvm.masked.load.v8f64.p0v8f64(<8 x double>* %Aptr, i32 8, <8 x i1> %Mask, <8 x double> undef) 16440 ; Store all selected elements consecutively in array B 16441 call <void> @llvm.masked.compressstore.v8f64(<8 x double> %Tmp, double* %Bptr, <8 x i1> %Mask) 16442 16443 ; %Bptr should be increased on each iteration according to the number of '1' elements in the Mask. 16444 %MaskI = bitcast <8 x i1> %Mask to i8 16445 %MaskIPopcnt = call i8 @llvm.ctpop.i8(i8 %MaskI) 16446 %MaskI64 = zext i8 %MaskIPopcnt to i64 16447 %BNextInd = add i64 %BInd, %MaskI64 16448 16449 16450Other targets may support this intrinsic differently, for example, by lowering it into a sequence of branches that guard scalar store operations. 16451 16452 16453Memory Use Markers 16454------------------ 16455 16456This class of intrinsics provides information about the lifetime of 16457memory objects and ranges where variables are immutable. 16458 16459.. _int_lifestart: 16460 16461'``llvm.lifetime.start``' Intrinsic 16462^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16463 16464Syntax: 16465""""""" 16466 16467:: 16468 16469 declare void @llvm.lifetime.start(i64 <size>, i8* nocapture <ptr>) 16470 16471Overview: 16472""""""""" 16473 16474The '``llvm.lifetime.start``' intrinsic specifies the start of a memory 16475object's lifetime. 16476 16477Arguments: 16478"""""""""" 16479 16480The first argument is a constant integer representing the size of the 16481object, or -1 if it is variable sized. The second argument is a pointer 16482to the object. 16483 16484Semantics: 16485"""""""""" 16486 16487This intrinsic indicates that before this point in the code, the value 16488of the memory pointed to by ``ptr`` is dead. This means that it is known 16489to never be used and has an undefined value. A load from the pointer 16490that precedes this intrinsic can be replaced with ``'undef'``. 16491 16492.. _int_lifeend: 16493 16494'``llvm.lifetime.end``' Intrinsic 16495^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16496 16497Syntax: 16498""""""" 16499 16500:: 16501 16502 declare void @llvm.lifetime.end(i64 <size>, i8* nocapture <ptr>) 16503 16504Overview: 16505""""""""" 16506 16507The '``llvm.lifetime.end``' intrinsic specifies the end of a memory 16508object's lifetime. 16509 16510Arguments: 16511"""""""""" 16512 16513The first argument is a constant integer representing the size of the 16514object, or -1 if it is variable sized. The second argument is a pointer 16515to the object. 16516 16517Semantics: 16518"""""""""" 16519 16520This intrinsic indicates that after this point in the code, the value of 16521the memory pointed to by ``ptr`` is dead. This means that it is known to 16522never be used and has an undefined value. Any stores into the memory 16523object following this intrinsic may be removed as dead. 16524 16525'``llvm.invariant.start``' Intrinsic 16526^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16527 16528Syntax: 16529""""""" 16530This is an overloaded intrinsic. The memory object can belong to any address space. 16531 16532:: 16533 16534 declare {}* @llvm.invariant.start.p0i8(i64 <size>, i8* nocapture <ptr>) 16535 16536Overview: 16537""""""""" 16538 16539The '``llvm.invariant.start``' intrinsic specifies that the contents of 16540a memory object will not change. 16541 16542Arguments: 16543"""""""""" 16544 16545The first argument is a constant integer representing the size of the 16546object, or -1 if it is variable sized. The second argument is a pointer 16547to the object. 16548 16549Semantics: 16550"""""""""" 16551 16552This intrinsic indicates that until an ``llvm.invariant.end`` that uses 16553the return value, the referenced memory location is constant and 16554unchanging. 16555 16556'``llvm.invariant.end``' Intrinsic 16557^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16558 16559Syntax: 16560""""""" 16561This is an overloaded intrinsic. The memory object can belong to any address space. 16562 16563:: 16564 16565 declare void @llvm.invariant.end.p0i8({}* <start>, i64 <size>, i8* nocapture <ptr>) 16566 16567Overview: 16568""""""""" 16569 16570The '``llvm.invariant.end``' intrinsic specifies that the contents of a 16571memory object are mutable. 16572 16573Arguments: 16574"""""""""" 16575 16576The first argument is the matching ``llvm.invariant.start`` intrinsic. 16577The second argument is a constant integer representing the size of the 16578object, or -1 if it is variable sized and the third argument is a 16579pointer to the object. 16580 16581Semantics: 16582"""""""""" 16583 16584This intrinsic indicates that the memory is mutable again. 16585 16586'``llvm.launder.invariant.group``' Intrinsic 16587^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16588 16589Syntax: 16590""""""" 16591This is an overloaded intrinsic. The memory object can belong to any address 16592space. The returned pointer must belong to the same address space as the 16593argument. 16594 16595:: 16596 16597 declare i8* @llvm.launder.invariant.group.p0i8(i8* <ptr>) 16598 16599Overview: 16600""""""""" 16601 16602The '``llvm.launder.invariant.group``' intrinsic can be used when an invariant 16603established by ``invariant.group`` metadata no longer holds, to obtain a new 16604pointer value that carries fresh invariant group information. It is an 16605experimental intrinsic, which means that its semantics might change in the 16606future. 16607 16608 16609Arguments: 16610"""""""""" 16611 16612The ``llvm.launder.invariant.group`` takes only one argument, which is a pointer 16613to the memory. 16614 16615Semantics: 16616"""""""""" 16617 16618Returns another pointer that aliases its argument but which is considered different 16619for the purposes of ``load``/``store`` ``invariant.group`` metadata. 16620It does not read any accessible memory and the execution can be speculated. 16621 16622'``llvm.strip.invariant.group``' Intrinsic 16623^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16624 16625Syntax: 16626""""""" 16627This is an overloaded intrinsic. The memory object can belong to any address 16628space. The returned pointer must belong to the same address space as the 16629argument. 16630 16631:: 16632 16633 declare i8* @llvm.strip.invariant.group.p0i8(i8* <ptr>) 16634 16635Overview: 16636""""""""" 16637 16638The '``llvm.strip.invariant.group``' intrinsic can be used when an invariant 16639established by ``invariant.group`` metadata no longer holds, to obtain a new pointer 16640value that does not carry the invariant information. It is an experimental 16641intrinsic, which means that its semantics might change in the future. 16642 16643 16644Arguments: 16645"""""""""" 16646 16647The ``llvm.strip.invariant.group`` takes only one argument, which is a pointer 16648to the memory. 16649 16650Semantics: 16651"""""""""" 16652 16653Returns another pointer that aliases its argument but which has no associated 16654``invariant.group`` metadata. 16655It does not read any memory and can be speculated. 16656 16657 16658 16659.. _constrainedfp: 16660 16661Constrained Floating-Point Intrinsics 16662------------------------------------- 16663 16664These intrinsics are used to provide special handling of floating-point 16665operations when specific rounding mode or floating-point exception behavior is 16666required. By default, LLVM optimization passes assume that the rounding mode is 16667round-to-nearest and that floating-point exceptions will not be monitored. 16668Constrained FP intrinsics are used to support non-default rounding modes and 16669accurately preserve exception behavior without compromising LLVM's ability to 16670optimize FP code when the default behavior is used. 16671 16672If any FP operation in a function is constrained then they all must be 16673constrained. This is required for correct LLVM IR. Optimizations that 16674move code around can create miscompiles if mixing of constrained and normal 16675operations is done. The correct way to mix constrained and less constrained 16676operations is to use the rounding mode and exception handling metadata to 16677mark constrained intrinsics as having LLVM's default behavior. 16678 16679Each of these intrinsics corresponds to a normal floating-point operation. The 16680data arguments and the return value are the same as the corresponding FP 16681operation. 16682 16683The rounding mode argument is a metadata string specifying what 16684assumptions, if any, the optimizer can make when transforming constant 16685values. Some constrained FP intrinsics omit this argument. If required 16686by the intrinsic, this argument must be one of the following strings: 16687 16688:: 16689 16690 "round.dynamic" 16691 "round.tonearest" 16692 "round.downward" 16693 "round.upward" 16694 "round.towardzero" 16695 "round.tonearestaway" 16696 16697If this argument is "round.dynamic" optimization passes must assume that the 16698rounding mode is unknown and may change at runtime. No transformations that 16699depend on rounding mode may be performed in this case. 16700 16701The other possible values for the rounding mode argument correspond to the 16702similarly named IEEE rounding modes. If the argument is any of these values 16703optimization passes may perform transformations as long as they are consistent 16704with the specified rounding mode. 16705 16706For example, 'x-0'->'x' is not a valid transformation if the rounding mode is 16707"round.downward" or "round.dynamic" because if the value of 'x' is +0 then 16708'x-0' should evaluate to '-0' when rounding downward. However, this 16709transformation is legal for all other rounding modes. 16710 16711For values other than "round.dynamic" optimization passes may assume that the 16712actual runtime rounding mode (as defined in a target-specific manner) matches 16713the specified rounding mode, but this is not guaranteed. Using a specific 16714non-dynamic rounding mode which does not match the actual rounding mode at 16715runtime results in undefined behavior. 16716 16717The exception behavior argument is a metadata string describing the floating 16718point exception semantics that required for the intrinsic. This argument 16719must be one of the following strings: 16720 16721:: 16722 16723 "fpexcept.ignore" 16724 "fpexcept.maytrap" 16725 "fpexcept.strict" 16726 16727If this argument is "fpexcept.ignore" optimization passes may assume that the 16728exception status flags will not be read and that floating-point exceptions will 16729be masked. This allows transformations to be performed that may change the 16730exception semantics of the original code. For example, FP operations may be 16731speculatively executed in this case whereas they must not be for either of the 16732other possible values of this argument. 16733 16734If the exception behavior argument is "fpexcept.maytrap" optimization passes 16735must avoid transformations that may raise exceptions that would not have been 16736raised by the original code (such as speculatively executing FP operations), but 16737passes are not required to preserve all exceptions that are implied by the 16738original code. For example, exceptions may be potentially hidden by constant 16739folding. 16740 16741If the exception behavior argument is "fpexcept.strict" all transformations must 16742strictly preserve the floating-point exception semantics of the original code. 16743Any FP exception that would have been raised by the original code must be raised 16744by the transformed code, and the transformed code must not raise any FP 16745exceptions that would not have been raised by the original code. This is the 16746exception behavior argument that will be used if the code being compiled reads 16747the FP exception status flags, but this mode can also be used with code that 16748unmasks FP exceptions. 16749 16750The number and order of floating-point exceptions is NOT guaranteed. For 16751example, a series of FP operations that each may raise exceptions may be 16752vectorized into a single instruction that raises each unique exception a single 16753time. 16754 16755Proper :ref:`function attributes <fnattrs>` usage is required for the 16756constrained intrinsics to function correctly. 16757 16758All function *calls* done in a function that uses constrained floating 16759point intrinsics must have the ``strictfp`` attribute. 16760 16761All function *definitions* that use constrained floating point intrinsics 16762must have the ``strictfp`` attribute. 16763 16764'``llvm.experimental.constrained.fadd``' Intrinsic 16765^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16766 16767Syntax: 16768""""""" 16769 16770:: 16771 16772 declare <type> 16773 @llvm.experimental.constrained.fadd(<type> <op1>, <type> <op2>, 16774 metadata <rounding mode>, 16775 metadata <exception behavior>) 16776 16777Overview: 16778""""""""" 16779 16780The '``llvm.experimental.constrained.fadd``' intrinsic returns the sum of its 16781two operands. 16782 16783 16784Arguments: 16785"""""""""" 16786 16787The first two arguments to the '``llvm.experimental.constrained.fadd``' 16788intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` 16789of floating-point values. Both arguments must have identical types. 16790 16791The third and fourth arguments specify the rounding mode and exception 16792behavior as described above. 16793 16794Semantics: 16795"""""""""" 16796 16797The value produced is the floating-point sum of the two value operands and has 16798the same type as the operands. 16799 16800 16801'``llvm.experimental.constrained.fsub``' Intrinsic 16802^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16803 16804Syntax: 16805""""""" 16806 16807:: 16808 16809 declare <type> 16810 @llvm.experimental.constrained.fsub(<type> <op1>, <type> <op2>, 16811 metadata <rounding mode>, 16812 metadata <exception behavior>) 16813 16814Overview: 16815""""""""" 16816 16817The '``llvm.experimental.constrained.fsub``' intrinsic returns the difference 16818of its two operands. 16819 16820 16821Arguments: 16822"""""""""" 16823 16824The first two arguments to the '``llvm.experimental.constrained.fsub``' 16825intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` 16826of floating-point values. Both arguments must have identical types. 16827 16828The third and fourth arguments specify the rounding mode and exception 16829behavior as described above. 16830 16831Semantics: 16832"""""""""" 16833 16834The value produced is the floating-point difference of the two value operands 16835and has the same type as the operands. 16836 16837 16838'``llvm.experimental.constrained.fmul``' Intrinsic 16839^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16840 16841Syntax: 16842""""""" 16843 16844:: 16845 16846 declare <type> 16847 @llvm.experimental.constrained.fmul(<type> <op1>, <type> <op2>, 16848 metadata <rounding mode>, 16849 metadata <exception behavior>) 16850 16851Overview: 16852""""""""" 16853 16854The '``llvm.experimental.constrained.fmul``' intrinsic returns the product of 16855its two operands. 16856 16857 16858Arguments: 16859"""""""""" 16860 16861The first two arguments to the '``llvm.experimental.constrained.fmul``' 16862intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` 16863of floating-point values. Both arguments must have identical types. 16864 16865The third and fourth arguments specify the rounding mode and exception 16866behavior as described above. 16867 16868Semantics: 16869"""""""""" 16870 16871The value produced is the floating-point product of the two value operands and 16872has the same type as the operands. 16873 16874 16875'``llvm.experimental.constrained.fdiv``' Intrinsic 16876^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16877 16878Syntax: 16879""""""" 16880 16881:: 16882 16883 declare <type> 16884 @llvm.experimental.constrained.fdiv(<type> <op1>, <type> <op2>, 16885 metadata <rounding mode>, 16886 metadata <exception behavior>) 16887 16888Overview: 16889""""""""" 16890 16891The '``llvm.experimental.constrained.fdiv``' intrinsic returns the quotient of 16892its two operands. 16893 16894 16895Arguments: 16896"""""""""" 16897 16898The first two arguments to the '``llvm.experimental.constrained.fdiv``' 16899intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` 16900of floating-point values. Both arguments must have identical types. 16901 16902The third and fourth arguments specify the rounding mode and exception 16903behavior as described above. 16904 16905Semantics: 16906"""""""""" 16907 16908The value produced is the floating-point quotient of the two value operands and 16909has the same type as the operands. 16910 16911 16912'``llvm.experimental.constrained.frem``' Intrinsic 16913^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16914 16915Syntax: 16916""""""" 16917 16918:: 16919 16920 declare <type> 16921 @llvm.experimental.constrained.frem(<type> <op1>, <type> <op2>, 16922 metadata <rounding mode>, 16923 metadata <exception behavior>) 16924 16925Overview: 16926""""""""" 16927 16928The '``llvm.experimental.constrained.frem``' intrinsic returns the remainder 16929from the division of its two operands. 16930 16931 16932Arguments: 16933"""""""""" 16934 16935The first two arguments to the '``llvm.experimental.constrained.frem``' 16936intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` 16937of floating-point values. Both arguments must have identical types. 16938 16939The third and fourth arguments specify the rounding mode and exception 16940behavior as described above. The rounding mode argument has no effect, since 16941the result of frem is never rounded, but the argument is included for 16942consistency with the other constrained floating-point intrinsics. 16943 16944Semantics: 16945"""""""""" 16946 16947The value produced is the floating-point remainder from the division of the two 16948value operands and has the same type as the operands. The remainder has the 16949same sign as the dividend. 16950 16951'``llvm.experimental.constrained.fma``' Intrinsic 16952^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16953 16954Syntax: 16955""""""" 16956 16957:: 16958 16959 declare <type> 16960 @llvm.experimental.constrained.fma(<type> <op1>, <type> <op2>, <type> <op3>, 16961 metadata <rounding mode>, 16962 metadata <exception behavior>) 16963 16964Overview: 16965""""""""" 16966 16967The '``llvm.experimental.constrained.fma``' intrinsic returns the result of a 16968fused-multiply-add operation on its operands. 16969 16970Arguments: 16971"""""""""" 16972 16973The first three arguments to the '``llvm.experimental.constrained.fma``' 16974intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector 16975<t_vector>` of floating-point values. All arguments must have identical types. 16976 16977The fourth and fifth arguments specify the rounding mode and exception behavior 16978as described above. 16979 16980Semantics: 16981"""""""""" 16982 16983The result produced is the product of the first two operands added to the third 16984operand computed with infinite precision, and then rounded to the target 16985precision. 16986 16987'``llvm.experimental.constrained.fptoui``' Intrinsic 16988^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16989 16990Syntax: 16991""""""" 16992 16993:: 16994 16995 declare <ty2> 16996 @llvm.experimental.constrained.fptoui(<type> <value>, 16997 metadata <exception behavior>) 16998 16999Overview: 17000""""""""" 17001 17002The '``llvm.experimental.constrained.fptoui``' intrinsic converts a 17003floating-point ``value`` to its unsigned integer equivalent of type ``ty2``. 17004 17005Arguments: 17006"""""""""" 17007 17008The first argument to the '``llvm.experimental.constrained.fptoui``' 17009intrinsic must be :ref:`floating point <t_floating>` or :ref:`vector 17010<t_vector>` of floating point values. 17011 17012The second argument specifies the exception behavior as described above. 17013 17014Semantics: 17015"""""""""" 17016 17017The result produced is an unsigned integer converted from the floating 17018point operand. The value is truncated, so it is rounded towards zero. 17019 17020'``llvm.experimental.constrained.fptosi``' Intrinsic 17021^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17022 17023Syntax: 17024""""""" 17025 17026:: 17027 17028 declare <ty2> 17029 @llvm.experimental.constrained.fptosi(<type> <value>, 17030 metadata <exception behavior>) 17031 17032Overview: 17033""""""""" 17034 17035The '``llvm.experimental.constrained.fptosi``' intrinsic converts 17036:ref:`floating-point <t_floating>` ``value`` to type ``ty2``. 17037 17038Arguments: 17039"""""""""" 17040 17041The first argument to the '``llvm.experimental.constrained.fptosi``' 17042intrinsic must be :ref:`floating point <t_floating>` or :ref:`vector 17043<t_vector>` of floating point values. 17044 17045The second argument specifies the exception behavior as described above. 17046 17047Semantics: 17048"""""""""" 17049 17050The result produced is a signed integer converted from the floating 17051point operand. The value is truncated, so it is rounded towards zero. 17052 17053'``llvm.experimental.constrained.uitofp``' Intrinsic 17054^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17055 17056Syntax: 17057""""""" 17058 17059:: 17060 17061 declare <ty2> 17062 @llvm.experimental.constrained.uitofp(<type> <value>, 17063 metadata <rounding mode>, 17064 metadata <exception behavior>) 17065 17066Overview: 17067""""""""" 17068 17069The '``llvm.experimental.constrained.uitofp``' intrinsic converts an 17070unsigned integer ``value`` to a floating-point of type ``ty2``. 17071 17072Arguments: 17073"""""""""" 17074 17075The first argument to the '``llvm.experimental.constrained.uitofp``' 17076intrinsic must be an :ref:`integer <t_integer>` or :ref:`vector 17077<t_vector>` of integer values. 17078 17079The second and third arguments specify the rounding mode and exception 17080behavior as described above. 17081 17082Semantics: 17083"""""""""" 17084 17085An inexact floating-point exception will be raised if rounding is required. 17086Any result produced is a floating point value converted from the input 17087integer operand. 17088 17089'``llvm.experimental.constrained.sitofp``' Intrinsic 17090^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17091 17092Syntax: 17093""""""" 17094 17095:: 17096 17097 declare <ty2> 17098 @llvm.experimental.constrained.sitofp(<type> <value>, 17099 metadata <rounding mode>, 17100 metadata <exception behavior>) 17101 17102Overview: 17103""""""""" 17104 17105The '``llvm.experimental.constrained.sitofp``' intrinsic converts a 17106signed integer ``value`` to a floating-point of type ``ty2``. 17107 17108Arguments: 17109"""""""""" 17110 17111The first argument to the '``llvm.experimental.constrained.sitofp``' 17112intrinsic must be an :ref:`integer <t_integer>` or :ref:`vector 17113<t_vector>` of integer values. 17114 17115The second and third arguments specify the rounding mode and exception 17116behavior as described above. 17117 17118Semantics: 17119"""""""""" 17120 17121An inexact floating-point exception will be raised if rounding is required. 17122Any result produced is a floating point value converted from the input 17123integer operand. 17124 17125'``llvm.experimental.constrained.fptrunc``' Intrinsic 17126^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17127 17128Syntax: 17129""""""" 17130 17131:: 17132 17133 declare <ty2> 17134 @llvm.experimental.constrained.fptrunc(<type> <value>, 17135 metadata <rounding mode>, 17136 metadata <exception behavior>) 17137 17138Overview: 17139""""""""" 17140 17141The '``llvm.experimental.constrained.fptrunc``' intrinsic truncates ``value`` 17142to type ``ty2``. 17143 17144Arguments: 17145"""""""""" 17146 17147The first argument to the '``llvm.experimental.constrained.fptrunc``' 17148intrinsic must be :ref:`floating point <t_floating>` or :ref:`vector 17149<t_vector>` of floating point values. This argument must be larger in size 17150than the result. 17151 17152The second and third arguments specify the rounding mode and exception 17153behavior as described above. 17154 17155Semantics: 17156"""""""""" 17157 17158The result produced is a floating point value truncated to be smaller in size 17159than the operand. 17160 17161'``llvm.experimental.constrained.fpext``' Intrinsic 17162^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17163 17164Syntax: 17165""""""" 17166 17167:: 17168 17169 declare <ty2> 17170 @llvm.experimental.constrained.fpext(<type> <value>, 17171 metadata <exception behavior>) 17172 17173Overview: 17174""""""""" 17175 17176The '``llvm.experimental.constrained.fpext``' intrinsic extends a 17177floating-point ``value`` to a larger floating-point value. 17178 17179Arguments: 17180"""""""""" 17181 17182The first argument to the '``llvm.experimental.constrained.fpext``' 17183intrinsic must be :ref:`floating point <t_floating>` or :ref:`vector 17184<t_vector>` of floating point values. This argument must be smaller in size 17185than the result. 17186 17187The second argument specifies the exception behavior as described above. 17188 17189Semantics: 17190"""""""""" 17191 17192The result produced is a floating point value extended to be larger in size 17193than the operand. All restrictions that apply to the fpext instruction also 17194apply to this intrinsic. 17195 17196'``llvm.experimental.constrained.fcmp``' and '``llvm.experimental.constrained.fcmps``' Intrinsics 17197^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17198 17199Syntax: 17200""""""" 17201 17202:: 17203 17204 declare <ty2> 17205 @llvm.experimental.constrained.fcmp(<type> <op1>, <type> <op2>, 17206 metadata <condition code>, 17207 metadata <exception behavior>) 17208 declare <ty2> 17209 @llvm.experimental.constrained.fcmps(<type> <op1>, <type> <op2>, 17210 metadata <condition code>, 17211 metadata <exception behavior>) 17212 17213Overview: 17214""""""""" 17215 17216The '``llvm.experimental.constrained.fcmp``' and 17217'``llvm.experimental.constrained.fcmps``' intrinsics return a boolean 17218value or vector of boolean values based on comparison of its operands. 17219 17220If the operands are floating-point scalars, then the result type is a 17221boolean (:ref:`i1 <t_integer>`). 17222 17223If the operands are floating-point vectors, then the result type is a 17224vector of boolean with the same number of elements as the operands being 17225compared. 17226 17227The '``llvm.experimental.constrained.fcmp``' intrinsic performs a quiet 17228comparison operation while the '``llvm.experimental.constrained.fcmps``' 17229intrinsic performs a signaling comparison operation. 17230 17231Arguments: 17232"""""""""" 17233 17234The first two arguments to the '``llvm.experimental.constrained.fcmp``' 17235and '``llvm.experimental.constrained.fcmps``' intrinsics must be 17236:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` 17237of floating-point values. Both arguments must have identical types. 17238 17239The third argument is the condition code indicating the kind of comparison 17240to perform. It must be a metadata string with one of the following values: 17241 17242- "``oeq``": ordered and equal 17243- "``ogt``": ordered and greater than 17244- "``oge``": ordered and greater than or equal 17245- "``olt``": ordered and less than 17246- "``ole``": ordered and less than or equal 17247- "``one``": ordered and not equal 17248- "``ord``": ordered (no nans) 17249- "``ueq``": unordered or equal 17250- "``ugt``": unordered or greater than 17251- "``uge``": unordered or greater than or equal 17252- "``ult``": unordered or less than 17253- "``ule``": unordered or less than or equal 17254- "``une``": unordered or not equal 17255- "``uno``": unordered (either nans) 17256 17257*Ordered* means that neither operand is a NAN while *unordered* means 17258that either operand may be a NAN. 17259 17260The fourth argument specifies the exception behavior as described above. 17261 17262Semantics: 17263"""""""""" 17264 17265``op1`` and ``op2`` are compared according to the condition code given 17266as the third argument. If the operands are vectors, then the 17267vectors are compared element by element. Each comparison performed 17268always yields an :ref:`i1 <t_integer>` result, as follows: 17269 17270- "``oeq``": yields ``true`` if both operands are not a NAN and ``op1`` 17271 is equal to ``op2``. 17272- "``ogt``": yields ``true`` if both operands are not a NAN and ``op1`` 17273 is greater than ``op2``. 17274- "``oge``": yields ``true`` if both operands are not a NAN and ``op1`` 17275 is greater than or equal to ``op2``. 17276- "``olt``": yields ``true`` if both operands are not a NAN and ``op1`` 17277 is less than ``op2``. 17278- "``ole``": yields ``true`` if both operands are not a NAN and ``op1`` 17279 is less than or equal to ``op2``. 17280- "``one``": yields ``true`` if both operands are not a NAN and ``op1`` 17281 is not equal to ``op2``. 17282- "``ord``": yields ``true`` if both operands are not a NAN. 17283- "``ueq``": yields ``true`` if either operand is a NAN or ``op1`` is 17284 equal to ``op2``. 17285- "``ugt``": yields ``true`` if either operand is a NAN or ``op1`` is 17286 greater than ``op2``. 17287- "``uge``": yields ``true`` if either operand is a NAN or ``op1`` is 17288 greater than or equal to ``op2``. 17289- "``ult``": yields ``true`` if either operand is a NAN or ``op1`` is 17290 less than ``op2``. 17291- "``ule``": yields ``true`` if either operand is a NAN or ``op1`` is 17292 less than or equal to ``op2``. 17293- "``une``": yields ``true`` if either operand is a NAN or ``op1`` is 17294 not equal to ``op2``. 17295- "``uno``": yields ``true`` if either operand is a NAN. 17296 17297The quiet comparison operation performed by 17298'``llvm.experimental.constrained.fcmp``' will only raise an exception 17299if either operand is a SNAN. The signaling comparison operation 17300performed by '``llvm.experimental.constrained.fcmps``' will raise an 17301exception if either operand is a NAN (QNAN or SNAN). 17302 17303'``llvm.experimental.constrained.fmuladd``' Intrinsic 17304^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17305 17306Syntax: 17307""""""" 17308 17309:: 17310 17311 declare <type> 17312 @llvm.experimental.constrained.fmuladd(<type> <op1>, <type> <op2>, 17313 <type> <op3>, 17314 metadata <rounding mode>, 17315 metadata <exception behavior>) 17316 17317Overview: 17318""""""""" 17319 17320The '``llvm.experimental.constrained.fmuladd``' intrinsic represents 17321multiply-add expressions that can be fused if the code generator determines 17322that (a) the target instruction set has support for a fused operation, 17323and (b) that the fused operation is more efficient than the equivalent, 17324separate pair of mul and add instructions. 17325 17326Arguments: 17327"""""""""" 17328 17329The first three arguments to the '``llvm.experimental.constrained.fmuladd``' 17330intrinsic must be floating-point or vector of floating-point values. 17331All three arguments must have identical types. 17332 17333The fourth and fifth arguments specify the rounding mode and exception behavior 17334as described above. 17335 17336Semantics: 17337"""""""""" 17338 17339The expression: 17340 17341:: 17342 17343 %0 = call float @llvm.experimental.constrained.fmuladd.f32(%a, %b, %c, 17344 metadata <rounding mode>, 17345 metadata <exception behavior>) 17346 17347is equivalent to the expression: 17348 17349:: 17350 17351 %0 = call float @llvm.experimental.constrained.fmul.f32(%a, %b, 17352 metadata <rounding mode>, 17353 metadata <exception behavior>) 17354 %1 = call float @llvm.experimental.constrained.fadd.f32(%0, %c, 17355 metadata <rounding mode>, 17356 metadata <exception behavior>) 17357 17358except that it is unspecified whether rounding will be performed between the 17359multiplication and addition steps. Fusion is not guaranteed, even if the target 17360platform supports it. 17361If a fused multiply-add is required, the corresponding 17362:ref:`llvm.experimental.constrained.fma <int_fma>` intrinsic function should be 17363used instead. 17364This never sets errno, just as '``llvm.experimental.constrained.fma.*``'. 17365 17366Constrained libm-equivalent Intrinsics 17367-------------------------------------- 17368 17369In addition to the basic floating-point operations for which constrained 17370intrinsics are described above, there are constrained versions of various 17371operations which provide equivalent behavior to a corresponding libm function. 17372These intrinsics allow the precise behavior of these operations with respect to 17373rounding mode and exception behavior to be controlled. 17374 17375As with the basic constrained floating-point intrinsics, the rounding mode 17376and exception behavior arguments only control the behavior of the optimizer. 17377They do not change the runtime floating-point environment. 17378 17379 17380'``llvm.experimental.constrained.sqrt``' Intrinsic 17381^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17382 17383Syntax: 17384""""""" 17385 17386:: 17387 17388 declare <type> 17389 @llvm.experimental.constrained.sqrt(<type> <op1>, 17390 metadata <rounding mode>, 17391 metadata <exception behavior>) 17392 17393Overview: 17394""""""""" 17395 17396The '``llvm.experimental.constrained.sqrt``' intrinsic returns the square root 17397of the specified value, returning the same value as the libm '``sqrt``' 17398functions would, but without setting ``errno``. 17399 17400Arguments: 17401"""""""""" 17402 17403The first argument and the return type are floating-point numbers of the same 17404type. 17405 17406The second and third arguments specify the rounding mode and exception 17407behavior as described above. 17408 17409Semantics: 17410"""""""""" 17411 17412This function returns the nonnegative square root of the specified value. 17413If the value is less than negative zero, a floating-point exception occurs 17414and the return value is architecture specific. 17415 17416 17417'``llvm.experimental.constrained.pow``' Intrinsic 17418^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17419 17420Syntax: 17421""""""" 17422 17423:: 17424 17425 declare <type> 17426 @llvm.experimental.constrained.pow(<type> <op1>, <type> <op2>, 17427 metadata <rounding mode>, 17428 metadata <exception behavior>) 17429 17430Overview: 17431""""""""" 17432 17433The '``llvm.experimental.constrained.pow``' intrinsic returns the first operand 17434raised to the (positive or negative) power specified by the second operand. 17435 17436Arguments: 17437"""""""""" 17438 17439The first two arguments and the return value are floating-point numbers of the 17440same type. The second argument specifies the power to which the first argument 17441should be raised. 17442 17443The third and fourth arguments specify the rounding mode and exception 17444behavior as described above. 17445 17446Semantics: 17447"""""""""" 17448 17449This function returns the first value raised to the second power, 17450returning the same values as the libm ``pow`` functions would, and 17451handles error conditions in the same way. 17452 17453 17454'``llvm.experimental.constrained.powi``' Intrinsic 17455^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17456 17457Syntax: 17458""""""" 17459 17460:: 17461 17462 declare <type> 17463 @llvm.experimental.constrained.powi(<type> <op1>, i32 <op2>, 17464 metadata <rounding mode>, 17465 metadata <exception behavior>) 17466 17467Overview: 17468""""""""" 17469 17470The '``llvm.experimental.constrained.powi``' intrinsic returns the first operand 17471raised to the (positive or negative) power specified by the second operand. The 17472order of evaluation of multiplications is not defined. When a vector of 17473floating-point type is used, the second argument remains a scalar integer value. 17474 17475 17476Arguments: 17477"""""""""" 17478 17479The first argument and the return value are floating-point numbers of the same 17480type. The second argument is a 32-bit signed integer specifying the power to 17481which the first argument should be raised. 17482 17483The third and fourth arguments specify the rounding mode and exception 17484behavior as described above. 17485 17486Semantics: 17487"""""""""" 17488 17489This function returns the first value raised to the second power with an 17490unspecified sequence of rounding operations. 17491 17492 17493'``llvm.experimental.constrained.sin``' Intrinsic 17494^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17495 17496Syntax: 17497""""""" 17498 17499:: 17500 17501 declare <type> 17502 @llvm.experimental.constrained.sin(<type> <op1>, 17503 metadata <rounding mode>, 17504 metadata <exception behavior>) 17505 17506Overview: 17507""""""""" 17508 17509The '``llvm.experimental.constrained.sin``' intrinsic returns the sine of the 17510first operand. 17511 17512Arguments: 17513"""""""""" 17514 17515The first argument and the return type are floating-point numbers of the same 17516type. 17517 17518The second and third arguments specify the rounding mode and exception 17519behavior as described above. 17520 17521Semantics: 17522"""""""""" 17523 17524This function returns the sine of the specified operand, returning the 17525same values as the libm ``sin`` functions would, and handles error 17526conditions in the same way. 17527 17528 17529'``llvm.experimental.constrained.cos``' Intrinsic 17530^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17531 17532Syntax: 17533""""""" 17534 17535:: 17536 17537 declare <type> 17538 @llvm.experimental.constrained.cos(<type> <op1>, 17539 metadata <rounding mode>, 17540 metadata <exception behavior>) 17541 17542Overview: 17543""""""""" 17544 17545The '``llvm.experimental.constrained.cos``' intrinsic returns the cosine of the 17546first operand. 17547 17548Arguments: 17549"""""""""" 17550 17551The first argument and the return type are floating-point numbers of the same 17552type. 17553 17554The second and third arguments specify the rounding mode and exception 17555behavior as described above. 17556 17557Semantics: 17558"""""""""" 17559 17560This function returns the cosine of the specified operand, returning the 17561same values as the libm ``cos`` functions would, and handles error 17562conditions in the same way. 17563 17564 17565'``llvm.experimental.constrained.exp``' Intrinsic 17566^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17567 17568Syntax: 17569""""""" 17570 17571:: 17572 17573 declare <type> 17574 @llvm.experimental.constrained.exp(<type> <op1>, 17575 metadata <rounding mode>, 17576 metadata <exception behavior>) 17577 17578Overview: 17579""""""""" 17580 17581The '``llvm.experimental.constrained.exp``' intrinsic computes the base-e 17582exponential of the specified value. 17583 17584Arguments: 17585"""""""""" 17586 17587The first argument and the return value are floating-point numbers of the same 17588type. 17589 17590The second and third arguments specify the rounding mode and exception 17591behavior as described above. 17592 17593Semantics: 17594"""""""""" 17595 17596This function returns the same values as the libm ``exp`` functions 17597would, and handles error conditions in the same way. 17598 17599 17600'``llvm.experimental.constrained.exp2``' Intrinsic 17601^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17602 17603Syntax: 17604""""""" 17605 17606:: 17607 17608 declare <type> 17609 @llvm.experimental.constrained.exp2(<type> <op1>, 17610 metadata <rounding mode>, 17611 metadata <exception behavior>) 17612 17613Overview: 17614""""""""" 17615 17616The '``llvm.experimental.constrained.exp2``' intrinsic computes the base-2 17617exponential of the specified value. 17618 17619 17620Arguments: 17621"""""""""" 17622 17623The first argument and the return value are floating-point numbers of the same 17624type. 17625 17626The second and third arguments specify the rounding mode and exception 17627behavior as described above. 17628 17629Semantics: 17630"""""""""" 17631 17632This function returns the same values as the libm ``exp2`` functions 17633would, and handles error conditions in the same way. 17634 17635 17636'``llvm.experimental.constrained.log``' Intrinsic 17637^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17638 17639Syntax: 17640""""""" 17641 17642:: 17643 17644 declare <type> 17645 @llvm.experimental.constrained.log(<type> <op1>, 17646 metadata <rounding mode>, 17647 metadata <exception behavior>) 17648 17649Overview: 17650""""""""" 17651 17652The '``llvm.experimental.constrained.log``' intrinsic computes the base-e 17653logarithm of the specified value. 17654 17655Arguments: 17656"""""""""" 17657 17658The first argument and the return value are floating-point numbers of the same 17659type. 17660 17661The second and third arguments specify the rounding mode and exception 17662behavior as described above. 17663 17664 17665Semantics: 17666"""""""""" 17667 17668This function returns the same values as the libm ``log`` functions 17669would, and handles error conditions in the same way. 17670 17671 17672'``llvm.experimental.constrained.log10``' Intrinsic 17673^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17674 17675Syntax: 17676""""""" 17677 17678:: 17679 17680 declare <type> 17681 @llvm.experimental.constrained.log10(<type> <op1>, 17682 metadata <rounding mode>, 17683 metadata <exception behavior>) 17684 17685Overview: 17686""""""""" 17687 17688The '``llvm.experimental.constrained.log10``' intrinsic computes the base-10 17689logarithm of the specified value. 17690 17691Arguments: 17692"""""""""" 17693 17694The first argument and the return value are floating-point numbers of the same 17695type. 17696 17697The second and third arguments specify the rounding mode and exception 17698behavior as described above. 17699 17700Semantics: 17701"""""""""" 17702 17703This function returns the same values as the libm ``log10`` functions 17704would, and handles error conditions in the same way. 17705 17706 17707'``llvm.experimental.constrained.log2``' Intrinsic 17708^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17709 17710Syntax: 17711""""""" 17712 17713:: 17714 17715 declare <type> 17716 @llvm.experimental.constrained.log2(<type> <op1>, 17717 metadata <rounding mode>, 17718 metadata <exception behavior>) 17719 17720Overview: 17721""""""""" 17722 17723The '``llvm.experimental.constrained.log2``' intrinsic computes the base-2 17724logarithm of the specified value. 17725 17726Arguments: 17727"""""""""" 17728 17729The first argument and the return value are floating-point numbers of the same 17730type. 17731 17732The second and third arguments specify the rounding mode and exception 17733behavior as described above. 17734 17735Semantics: 17736"""""""""" 17737 17738This function returns the same values as the libm ``log2`` functions 17739would, and handles error conditions in the same way. 17740 17741 17742'``llvm.experimental.constrained.rint``' Intrinsic 17743^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17744 17745Syntax: 17746""""""" 17747 17748:: 17749 17750 declare <type> 17751 @llvm.experimental.constrained.rint(<type> <op1>, 17752 metadata <rounding mode>, 17753 metadata <exception behavior>) 17754 17755Overview: 17756""""""""" 17757 17758The '``llvm.experimental.constrained.rint``' intrinsic returns the first 17759operand rounded to the nearest integer. It may raise an inexact floating-point 17760exception if the operand is not an integer. 17761 17762Arguments: 17763"""""""""" 17764 17765The first argument and the return value are floating-point numbers of the same 17766type. 17767 17768The second and third arguments specify the rounding mode and exception 17769behavior as described above. 17770 17771Semantics: 17772"""""""""" 17773 17774This function returns the same values as the libm ``rint`` functions 17775would, and handles error conditions in the same way. The rounding mode is 17776described, not determined, by the rounding mode argument. The actual rounding 17777mode is determined by the runtime floating-point environment. The rounding 17778mode argument is only intended as information to the compiler. 17779 17780 17781'``llvm.experimental.constrained.lrint``' Intrinsic 17782^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17783 17784Syntax: 17785""""""" 17786 17787:: 17788 17789 declare <inttype> 17790 @llvm.experimental.constrained.lrint(<fptype> <op1>, 17791 metadata <rounding mode>, 17792 metadata <exception behavior>) 17793 17794Overview: 17795""""""""" 17796 17797The '``llvm.experimental.constrained.lrint``' intrinsic returns the first 17798operand rounded to the nearest integer. An inexact floating-point exception 17799will be raised if the operand is not an integer. An invalid exception is 17800raised if the result is too large to fit into a supported integer type, 17801and in this case the result is undefined. 17802 17803Arguments: 17804"""""""""" 17805 17806The first argument is a floating-point number. The return value is an 17807integer type. Not all types are supported on all targets. The supported 17808types are the same as the ``llvm.lrint`` intrinsic and the ``lrint`` 17809libm functions. 17810 17811The second and third arguments specify the rounding mode and exception 17812behavior as described above. 17813 17814Semantics: 17815"""""""""" 17816 17817This function returns the same values as the libm ``lrint`` functions 17818would, and handles error conditions in the same way. 17819 17820The rounding mode is described, not determined, by the rounding mode 17821argument. The actual rounding mode is determined by the runtime floating-point 17822environment. The rounding mode argument is only intended as information 17823to the compiler. 17824 17825If the runtime floating-point environment is using the default rounding mode 17826then the results will be the same as the llvm.lrint intrinsic. 17827 17828 17829'``llvm.experimental.constrained.llrint``' Intrinsic 17830^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17831 17832Syntax: 17833""""""" 17834 17835:: 17836 17837 declare <inttype> 17838 @llvm.experimental.constrained.llrint(<fptype> <op1>, 17839 metadata <rounding mode>, 17840 metadata <exception behavior>) 17841 17842Overview: 17843""""""""" 17844 17845The '``llvm.experimental.constrained.llrint``' intrinsic returns the first 17846operand rounded to the nearest integer. An inexact floating-point exception 17847will be raised if the operand is not an integer. An invalid exception is 17848raised if the result is too large to fit into a supported integer type, 17849and in this case the result is undefined. 17850 17851Arguments: 17852"""""""""" 17853 17854The first argument is a floating-point number. The return value is an 17855integer type. Not all types are supported on all targets. The supported 17856types are the same as the ``llvm.llrint`` intrinsic and the ``llrint`` 17857libm functions. 17858 17859The second and third arguments specify the rounding mode and exception 17860behavior as described above. 17861 17862Semantics: 17863"""""""""" 17864 17865This function returns the same values as the libm ``llrint`` functions 17866would, and handles error conditions in the same way. 17867 17868The rounding mode is described, not determined, by the rounding mode 17869argument. The actual rounding mode is determined by the runtime floating-point 17870environment. The rounding mode argument is only intended as information 17871to the compiler. 17872 17873If the runtime floating-point environment is using the default rounding mode 17874then the results will be the same as the llvm.llrint intrinsic. 17875 17876 17877'``llvm.experimental.constrained.nearbyint``' Intrinsic 17878^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17879 17880Syntax: 17881""""""" 17882 17883:: 17884 17885 declare <type> 17886 @llvm.experimental.constrained.nearbyint(<type> <op1>, 17887 metadata <rounding mode>, 17888 metadata <exception behavior>) 17889 17890Overview: 17891""""""""" 17892 17893The '``llvm.experimental.constrained.nearbyint``' intrinsic returns the first 17894operand rounded to the nearest integer. It will not raise an inexact 17895floating-point exception if the operand is not an integer. 17896 17897 17898Arguments: 17899"""""""""" 17900 17901The first argument and the return value are floating-point numbers of the same 17902type. 17903 17904The second and third arguments specify the rounding mode and exception 17905behavior as described above. 17906 17907Semantics: 17908"""""""""" 17909 17910This function returns the same values as the libm ``nearbyint`` functions 17911would, and handles error conditions in the same way. The rounding mode is 17912described, not determined, by the rounding mode argument. The actual rounding 17913mode is determined by the runtime floating-point environment. The rounding 17914mode argument is only intended as information to the compiler. 17915 17916 17917'``llvm.experimental.constrained.maxnum``' Intrinsic 17918^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17919 17920Syntax: 17921""""""" 17922 17923:: 17924 17925 declare <type> 17926 @llvm.experimental.constrained.maxnum(<type> <op1>, <type> <op2> 17927 metadata <exception behavior>) 17928 17929Overview: 17930""""""""" 17931 17932The '``llvm.experimental.constrained.maxnum``' intrinsic returns the maximum 17933of the two arguments. 17934 17935Arguments: 17936"""""""""" 17937 17938The first two arguments and the return value are floating-point numbers 17939of the same type. 17940 17941The third argument specifies the exception behavior as described above. 17942 17943Semantics: 17944"""""""""" 17945 17946This function follows the IEEE-754 semantics for maxNum. 17947 17948 17949'``llvm.experimental.constrained.minnum``' Intrinsic 17950^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17951 17952Syntax: 17953""""""" 17954 17955:: 17956 17957 declare <type> 17958 @llvm.experimental.constrained.minnum(<type> <op1>, <type> <op2> 17959 metadata <exception behavior>) 17960 17961Overview: 17962""""""""" 17963 17964The '``llvm.experimental.constrained.minnum``' intrinsic returns the minimum 17965of the two arguments. 17966 17967Arguments: 17968"""""""""" 17969 17970The first two arguments and the return value are floating-point numbers 17971of the same type. 17972 17973The third argument specifies the exception behavior as described above. 17974 17975Semantics: 17976"""""""""" 17977 17978This function follows the IEEE-754 semantics for minNum. 17979 17980 17981'``llvm.experimental.constrained.maximum``' Intrinsic 17982^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17983 17984Syntax: 17985""""""" 17986 17987:: 17988 17989 declare <type> 17990 @llvm.experimental.constrained.maximum(<type> <op1>, <type> <op2> 17991 metadata <exception behavior>) 17992 17993Overview: 17994""""""""" 17995 17996The '``llvm.experimental.constrained.maximum``' intrinsic returns the maximum 17997of the two arguments, propagating NaNs and treating -0.0 as less than +0.0. 17998 17999Arguments: 18000"""""""""" 18001 18002The first two arguments and the return value are floating-point numbers 18003of the same type. 18004 18005The third argument specifies the exception behavior as described above. 18006 18007Semantics: 18008"""""""""" 18009 18010This function follows semantics specified in the draft of IEEE 754-2018. 18011 18012 18013'``llvm.experimental.constrained.minimum``' Intrinsic 18014^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18015 18016Syntax: 18017""""""" 18018 18019:: 18020 18021 declare <type> 18022 @llvm.experimental.constrained.minimum(<type> <op1>, <type> <op2> 18023 metadata <exception behavior>) 18024 18025Overview: 18026""""""""" 18027 18028The '``llvm.experimental.constrained.minimum``' intrinsic returns the minimum 18029of the two arguments, propagating NaNs and treating -0.0 as less than +0.0. 18030 18031Arguments: 18032"""""""""" 18033 18034The first two arguments and the return value are floating-point numbers 18035of the same type. 18036 18037The third argument specifies the exception behavior as described above. 18038 18039Semantics: 18040"""""""""" 18041 18042This function follows semantics specified in the draft of IEEE 754-2018. 18043 18044 18045'``llvm.experimental.constrained.ceil``' Intrinsic 18046^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18047 18048Syntax: 18049""""""" 18050 18051:: 18052 18053 declare <type> 18054 @llvm.experimental.constrained.ceil(<type> <op1>, 18055 metadata <exception behavior>) 18056 18057Overview: 18058""""""""" 18059 18060The '``llvm.experimental.constrained.ceil``' intrinsic returns the ceiling of the 18061first operand. 18062 18063Arguments: 18064"""""""""" 18065 18066The first argument and the return value are floating-point numbers of the same 18067type. 18068 18069The second argument specifies the exception behavior as described above. 18070 18071Semantics: 18072"""""""""" 18073 18074This function returns the same values as the libm ``ceil`` functions 18075would and handles error conditions in the same way. 18076 18077 18078'``llvm.experimental.constrained.floor``' Intrinsic 18079^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18080 18081Syntax: 18082""""""" 18083 18084:: 18085 18086 declare <type> 18087 @llvm.experimental.constrained.floor(<type> <op1>, 18088 metadata <exception behavior>) 18089 18090Overview: 18091""""""""" 18092 18093The '``llvm.experimental.constrained.floor``' intrinsic returns the floor of the 18094first operand. 18095 18096Arguments: 18097"""""""""" 18098 18099The first argument and the return value are floating-point numbers of the same 18100type. 18101 18102The second argument specifies the exception behavior as described above. 18103 18104Semantics: 18105"""""""""" 18106 18107This function returns the same values as the libm ``floor`` functions 18108would and handles error conditions in the same way. 18109 18110 18111'``llvm.experimental.constrained.round``' Intrinsic 18112^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18113 18114Syntax: 18115""""""" 18116 18117:: 18118 18119 declare <type> 18120 @llvm.experimental.constrained.round(<type> <op1>, 18121 metadata <exception behavior>) 18122 18123Overview: 18124""""""""" 18125 18126The '``llvm.experimental.constrained.round``' intrinsic returns the first 18127operand rounded to the nearest integer. 18128 18129Arguments: 18130"""""""""" 18131 18132The first argument and the return value are floating-point numbers of the same 18133type. 18134 18135The second argument specifies the exception behavior as described above. 18136 18137Semantics: 18138"""""""""" 18139 18140This function returns the same values as the libm ``round`` functions 18141would and handles error conditions in the same way. 18142 18143 18144'``llvm.experimental.constrained.lround``' Intrinsic 18145^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18146 18147Syntax: 18148""""""" 18149 18150:: 18151 18152 declare <inttype> 18153 @llvm.experimental.constrained.lround(<fptype> <op1>, 18154 metadata <exception behavior>) 18155 18156Overview: 18157""""""""" 18158 18159The '``llvm.experimental.constrained.lround``' intrinsic returns the first 18160operand rounded to the nearest integer with ties away from zero. It will 18161raise an inexact floating-point exception if the operand is not an integer. 18162An invalid exception is raised if the result is too large to fit into a 18163supported integer type, and in this case the result is undefined. 18164 18165Arguments: 18166"""""""""" 18167 18168The first argument is a floating-point number. The return value is an 18169integer type. Not all types are supported on all targets. The supported 18170types are the same as the ``llvm.lround`` intrinsic and the ``lround`` 18171libm functions. 18172 18173The second argument specifies the exception behavior as described above. 18174 18175Semantics: 18176"""""""""" 18177 18178This function returns the same values as the libm ``lround`` functions 18179would and handles error conditions in the same way. 18180 18181 18182'``llvm.experimental.constrained.llround``' Intrinsic 18183^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18184 18185Syntax: 18186""""""" 18187 18188:: 18189 18190 declare <inttype> 18191 @llvm.experimental.constrained.llround(<fptype> <op1>, 18192 metadata <exception behavior>) 18193 18194Overview: 18195""""""""" 18196 18197The '``llvm.experimental.constrained.llround``' intrinsic returns the first 18198operand rounded to the nearest integer with ties away from zero. It will 18199raise an inexact floating-point exception if the operand is not an integer. 18200An invalid exception is raised if the result is too large to fit into a 18201supported integer type, and in this case the result is undefined. 18202 18203Arguments: 18204"""""""""" 18205 18206The first argument is a floating-point number. The return value is an 18207integer type. Not all types are supported on all targets. The supported 18208types are the same as the ``llvm.llround`` intrinsic and the ``llround`` 18209libm functions. 18210 18211The second argument specifies the exception behavior as described above. 18212 18213Semantics: 18214"""""""""" 18215 18216This function returns the same values as the libm ``llround`` functions 18217would and handles error conditions in the same way. 18218 18219 18220'``llvm.experimental.constrained.trunc``' Intrinsic 18221^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18222 18223Syntax: 18224""""""" 18225 18226:: 18227 18228 declare <type> 18229 @llvm.experimental.constrained.trunc(<type> <op1>, 18230 metadata <exception behavior>) 18231 18232Overview: 18233""""""""" 18234 18235The '``llvm.experimental.constrained.trunc``' intrinsic returns the first 18236operand rounded to the nearest integer not larger in magnitude than the 18237operand. 18238 18239Arguments: 18240"""""""""" 18241 18242The first argument and the return value are floating-point numbers of the same 18243type. 18244 18245The second argument specifies the exception behavior as described above. 18246 18247Semantics: 18248"""""""""" 18249 18250This function returns the same values as the libm ``trunc`` functions 18251would and handles error conditions in the same way. 18252 18253 18254General Intrinsics 18255------------------ 18256 18257This class of intrinsics is designed to be generic and has no specific 18258purpose. 18259 18260'``llvm.var.annotation``' Intrinsic 18261^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18262 18263Syntax: 18264""""""" 18265 18266:: 18267 18268 declare void @llvm.var.annotation(i8* <val>, i8* <str>, i8* <str>, i32 <int>) 18269 18270Overview: 18271""""""""" 18272 18273The '``llvm.var.annotation``' intrinsic. 18274 18275Arguments: 18276"""""""""" 18277 18278The first argument is a pointer to a value, the second is a pointer to a 18279global string, the third is a pointer to a global string which is the 18280source file name, and the last argument is the line number. 18281 18282Semantics: 18283"""""""""" 18284 18285This intrinsic allows annotation of local variables with arbitrary 18286strings. This can be useful for special purpose optimizations that want 18287to look for these annotations. These have no other defined use; they are 18288ignored by code generation and optimization. 18289 18290'``llvm.ptr.annotation.*``' Intrinsic 18291^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18292 18293Syntax: 18294""""""" 18295 18296This is an overloaded intrinsic. You can use '``llvm.ptr.annotation``' on a 18297pointer to an integer of any width. *NOTE* you must specify an address space for 18298the pointer. The identifier for the default address space is the integer 18299'``0``'. 18300 18301:: 18302 18303 declare i8* @llvm.ptr.annotation.p<address space>i8(i8* <val>, i8* <str>, i8* <str>, i32 <int>) 18304 declare i16* @llvm.ptr.annotation.p<address space>i16(i16* <val>, i8* <str>, i8* <str>, i32 <int>) 18305 declare i32* @llvm.ptr.annotation.p<address space>i32(i32* <val>, i8* <str>, i8* <str>, i32 <int>) 18306 declare i64* @llvm.ptr.annotation.p<address space>i64(i64* <val>, i8* <str>, i8* <str>, i32 <int>) 18307 declare i256* @llvm.ptr.annotation.p<address space>i256(i256* <val>, i8* <str>, i8* <str>, i32 <int>) 18308 18309Overview: 18310""""""""" 18311 18312The '``llvm.ptr.annotation``' intrinsic. 18313 18314Arguments: 18315"""""""""" 18316 18317The first argument is a pointer to an integer value of arbitrary bitwidth 18318(result of some expression), the second is a pointer to a global string, the 18319third is a pointer to a global string which is the source file name, and the 18320last argument is the line number. It returns the value of the first argument. 18321 18322Semantics: 18323"""""""""" 18324 18325This intrinsic allows annotation of a pointer to an integer with arbitrary 18326strings. This can be useful for special purpose optimizations that want to look 18327for these annotations. These have no other defined use; they are ignored by code 18328generation and optimization. 18329 18330'``llvm.annotation.*``' Intrinsic 18331^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18332 18333Syntax: 18334""""""" 18335 18336This is an overloaded intrinsic. You can use '``llvm.annotation``' on 18337any integer bit width. 18338 18339:: 18340 18341 declare i8 @llvm.annotation.i8(i8 <val>, i8* <str>, i8* <str>, i32 <int>) 18342 declare i16 @llvm.annotation.i16(i16 <val>, i8* <str>, i8* <str>, i32 <int>) 18343 declare i32 @llvm.annotation.i32(i32 <val>, i8* <str>, i8* <str>, i32 <int>) 18344 declare i64 @llvm.annotation.i64(i64 <val>, i8* <str>, i8* <str>, i32 <int>) 18345 declare i256 @llvm.annotation.i256(i256 <val>, i8* <str>, i8* <str>, i32 <int>) 18346 18347Overview: 18348""""""""" 18349 18350The '``llvm.annotation``' intrinsic. 18351 18352Arguments: 18353"""""""""" 18354 18355The first argument is an integer value (result of some expression), the 18356second is a pointer to a global string, the third is a pointer to a 18357global string which is the source file name, and the last argument is 18358the line number. It returns the value of the first argument. 18359 18360Semantics: 18361"""""""""" 18362 18363This intrinsic allows annotations to be put on arbitrary expressions 18364with arbitrary strings. This can be useful for special purpose 18365optimizations that want to look for these annotations. These have no 18366other defined use; they are ignored by code generation and optimization. 18367 18368'``llvm.codeview.annotation``' Intrinsic 18369^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18370 18371Syntax: 18372""""""" 18373 18374This annotation emits a label at its program point and an associated 18375``S_ANNOTATION`` codeview record with some additional string metadata. This is 18376used to implement MSVC's ``__annotation`` intrinsic. It is marked 18377``noduplicate``, so calls to this intrinsic prevent inlining and should be 18378considered expensive. 18379 18380:: 18381 18382 declare void @llvm.codeview.annotation(metadata) 18383 18384Arguments: 18385"""""""""" 18386 18387The argument should be an MDTuple containing any number of MDStrings. 18388 18389'``llvm.trap``' Intrinsic 18390^^^^^^^^^^^^^^^^^^^^^^^^^ 18391 18392Syntax: 18393""""""" 18394 18395:: 18396 18397 declare void @llvm.trap() cold noreturn nounwind 18398 18399Overview: 18400""""""""" 18401 18402The '``llvm.trap``' intrinsic. 18403 18404Arguments: 18405"""""""""" 18406 18407None. 18408 18409Semantics: 18410"""""""""" 18411 18412This intrinsic is lowered to the target dependent trap instruction. If 18413the target does not have a trap instruction, this intrinsic will be 18414lowered to a call of the ``abort()`` function. 18415 18416'``llvm.debugtrap``' Intrinsic 18417^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18418 18419Syntax: 18420""""""" 18421 18422:: 18423 18424 declare void @llvm.debugtrap() nounwind 18425 18426Overview: 18427""""""""" 18428 18429The '``llvm.debugtrap``' intrinsic. 18430 18431Arguments: 18432"""""""""" 18433 18434None. 18435 18436Semantics: 18437"""""""""" 18438 18439This intrinsic is lowered to code which is intended to cause an 18440execution trap with the intention of requesting the attention of a 18441debugger. 18442 18443'``llvm.stackprotector``' Intrinsic 18444^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18445 18446Syntax: 18447""""""" 18448 18449:: 18450 18451 declare void @llvm.stackprotector(i8* <guard>, i8** <slot>) 18452 18453Overview: 18454""""""""" 18455 18456The ``llvm.stackprotector`` intrinsic takes the ``guard`` and stores it 18457onto the stack at ``slot``. The stack slot is adjusted to ensure that it 18458is placed on the stack before local variables. 18459 18460Arguments: 18461"""""""""" 18462 18463The ``llvm.stackprotector`` intrinsic requires two pointer arguments. 18464The first argument is the value loaded from the stack guard 18465``@__stack_chk_guard``. The second variable is an ``alloca`` that has 18466enough space to hold the value of the guard. 18467 18468Semantics: 18469"""""""""" 18470 18471This intrinsic causes the prologue/epilogue inserter to force the position of 18472the ``AllocaInst`` stack slot to be before local variables on the stack. This is 18473to ensure that if a local variable on the stack is overwritten, it will destroy 18474the value of the guard. When the function exits, the guard on the stack is 18475checked against the original guard by ``llvm.stackprotectorcheck``. If they are 18476different, then ``llvm.stackprotectorcheck`` causes the program to abort by 18477calling the ``__stack_chk_fail()`` function. 18478 18479'``llvm.stackguard``' Intrinsic 18480^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18481 18482Syntax: 18483""""""" 18484 18485:: 18486 18487 declare i8* @llvm.stackguard() 18488 18489Overview: 18490""""""""" 18491 18492The ``llvm.stackguard`` intrinsic returns the system stack guard value. 18493 18494It should not be generated by frontends, since it is only for internal usage. 18495The reason why we create this intrinsic is that we still support IR form Stack 18496Protector in FastISel. 18497 18498Arguments: 18499"""""""""" 18500 18501None. 18502 18503Semantics: 18504"""""""""" 18505 18506On some platforms, the value returned by this intrinsic remains unchanged 18507between loads in the same thread. On other platforms, it returns the same 18508global variable value, if any, e.g. ``@__stack_chk_guard``. 18509 18510Currently some platforms have IR-level customized stack guard loading (e.g. 18511X86 Linux) that is not handled by ``llvm.stackguard()``, while they should be 18512in the future. 18513 18514'``llvm.objectsize``' Intrinsic 18515^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18516 18517Syntax: 18518""""""" 18519 18520:: 18521 18522 declare i32 @llvm.objectsize.i32(i8* <object>, i1 <min>, i1 <nullunknown>, i1 <dynamic>) 18523 declare i64 @llvm.objectsize.i64(i8* <object>, i1 <min>, i1 <nullunknown>, i1 <dynamic>) 18524 18525Overview: 18526""""""""" 18527 18528The ``llvm.objectsize`` intrinsic is designed to provide information to the 18529optimizer to determine whether a) an operation (like memcpy) will overflow a 18530buffer that corresponds to an object, or b) that a runtime check for overflow 18531isn't necessary. An object in this context means an allocation of a specific 18532class, structure, array, or other object. 18533 18534Arguments: 18535"""""""""" 18536 18537The ``llvm.objectsize`` intrinsic takes four arguments. The first argument is a 18538pointer to or into the ``object``. The second argument determines whether 18539``llvm.objectsize`` returns 0 (if true) or -1 (if false) when the object size is 18540unknown. The third argument controls how ``llvm.objectsize`` acts when ``null`` 18541in address space 0 is used as its pointer argument. If it's ``false``, 18542``llvm.objectsize`` reports 0 bytes available when given ``null``. Otherwise, if 18543the ``null`` is in a non-zero address space or if ``true`` is given for the 18544third argument of ``llvm.objectsize``, we assume its size is unknown. The fourth 18545argument to ``llvm.objectsize`` determines if the value should be evaluated at 18546runtime. 18547 18548The second, third, and fourth arguments only accept constants. 18549 18550Semantics: 18551"""""""""" 18552 18553The ``llvm.objectsize`` intrinsic is lowered to a value representing the size of 18554the object concerned. If the size cannot be determined, ``llvm.objectsize`` 18555returns ``i32/i64 -1 or 0`` (depending on the ``min`` argument). 18556 18557'``llvm.expect``' Intrinsic 18558^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18559 18560Syntax: 18561""""""" 18562 18563This is an overloaded intrinsic. You can use ``llvm.expect`` on any 18564integer bit width. 18565 18566:: 18567 18568 declare i1 @llvm.expect.i1(i1 <val>, i1 <expected_val>) 18569 declare i32 @llvm.expect.i32(i32 <val>, i32 <expected_val>) 18570 declare i64 @llvm.expect.i64(i64 <val>, i64 <expected_val>) 18571 18572Overview: 18573""""""""" 18574 18575The ``llvm.expect`` intrinsic provides information about expected (the 18576most probable) value of ``val``, which can be used by optimizers. 18577 18578Arguments: 18579"""""""""" 18580 18581The ``llvm.expect`` intrinsic takes two arguments. The first argument is 18582a value. The second argument is an expected value. 18583 18584Semantics: 18585"""""""""" 18586 18587This intrinsic is lowered to the ``val``. 18588 18589.. _int_assume: 18590 18591'``llvm.assume``' Intrinsic 18592^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18593 18594Syntax: 18595""""""" 18596 18597:: 18598 18599 declare void @llvm.assume(i1 %cond) 18600 18601Overview: 18602""""""""" 18603 18604The ``llvm.assume`` allows the optimizer to assume that the provided 18605condition is true. This information can then be used in simplifying other parts 18606of the code. 18607 18608More complex assumptions can be encoded as 18609:ref:`assume operand bundles <assume_opbundles>`. 18610 18611Arguments: 18612"""""""""" 18613 18614The argument of the call is the condition which the optimizer may assume is 18615always true. 18616 18617Semantics: 18618"""""""""" 18619 18620The intrinsic allows the optimizer to assume that the provided condition is 18621always true whenever the control flow reaches the intrinsic call. No code is 18622generated for this intrinsic, and instructions that contribute only to the 18623provided condition are not used for code generation. If the condition is 18624violated during execution, the behavior is undefined. 18625 18626Note that the optimizer might limit the transformations performed on values 18627used by the ``llvm.assume`` intrinsic in order to preserve the instructions 18628only used to form the intrinsic's input argument. This might prove undesirable 18629if the extra information provided by the ``llvm.assume`` intrinsic does not cause 18630sufficient overall improvement in code quality. For this reason, 18631``llvm.assume`` should not be used to document basic mathematical invariants 18632that the optimizer can otherwise deduce or facts that are of little use to the 18633optimizer. 18634 18635.. _int_ssa_copy: 18636 18637'``llvm.ssa_copy``' Intrinsic 18638^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18639 18640Syntax: 18641""""""" 18642 18643:: 18644 18645 declare type @llvm.ssa_copy(type %operand) returned(1) readnone 18646 18647Arguments: 18648"""""""""" 18649 18650The first argument is an operand which is used as the returned value. 18651 18652Overview: 18653"""""""""" 18654 18655The ``llvm.ssa_copy`` intrinsic can be used to attach information to 18656operations by copying them and giving them new names. For example, 18657the PredicateInfo utility uses it to build Extended SSA form, and 18658attach various forms of information to operands that dominate specific 18659uses. It is not meant for general use, only for building temporary 18660renaming forms that require value splits at certain points. 18661 18662.. _type.test: 18663 18664'``llvm.type.test``' Intrinsic 18665^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18666 18667Syntax: 18668""""""" 18669 18670:: 18671 18672 declare i1 @llvm.type.test(i8* %ptr, metadata %type) nounwind readnone 18673 18674 18675Arguments: 18676"""""""""" 18677 18678The first argument is a pointer to be tested. The second argument is a 18679metadata object representing a :doc:`type identifier <TypeMetadata>`. 18680 18681Overview: 18682""""""""" 18683 18684The ``llvm.type.test`` intrinsic tests whether the given pointer is associated 18685with the given type identifier. 18686 18687.. _type.checked.load: 18688 18689'``llvm.type.checked.load``' Intrinsic 18690^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18691 18692Syntax: 18693""""""" 18694 18695:: 18696 18697 declare {i8*, i1} @llvm.type.checked.load(i8* %ptr, i32 %offset, metadata %type) argmemonly nounwind readonly 18698 18699 18700Arguments: 18701"""""""""" 18702 18703The first argument is a pointer from which to load a function pointer. The 18704second argument is the byte offset from which to load the function pointer. The 18705third argument is a metadata object representing a :doc:`type identifier 18706<TypeMetadata>`. 18707 18708Overview: 18709""""""""" 18710 18711The ``llvm.type.checked.load`` intrinsic safely loads a function pointer from a 18712virtual table pointer using type metadata. This intrinsic is used to implement 18713control flow integrity in conjunction with virtual call optimization. The 18714virtual call optimization pass will optimize away ``llvm.type.checked.load`` 18715intrinsics associated with devirtualized calls, thereby removing the type 18716check in cases where it is not needed to enforce the control flow integrity 18717constraint. 18718 18719If the given pointer is associated with a type metadata identifier, this 18720function returns true as the second element of its return value. (Note that 18721the function may also return true if the given pointer is not associated 18722with a type metadata identifier.) If the function's return value's second 18723element is true, the following rules apply to the first element: 18724 18725- If the given pointer is associated with the given type metadata identifier, 18726 it is the function pointer loaded from the given byte offset from the given 18727 pointer. 18728 18729- If the given pointer is not associated with the given type metadata 18730 identifier, it is one of the following (the choice of which is unspecified): 18731 18732 1. The function pointer that would have been loaded from an arbitrarily chosen 18733 (through an unspecified mechanism) pointer associated with the type 18734 metadata. 18735 18736 2. If the function has a non-void return type, a pointer to a function that 18737 returns an unspecified value without causing side effects. 18738 18739If the function's return value's second element is false, the value of the 18740first element is undefined. 18741 18742 18743'``llvm.donothing``' Intrinsic 18744^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18745 18746Syntax: 18747""""""" 18748 18749:: 18750 18751 declare void @llvm.donothing() nounwind readnone 18752 18753Overview: 18754""""""""" 18755 18756The ``llvm.donothing`` intrinsic doesn't perform any operation. It's one of only 18757three intrinsics (besides ``llvm.experimental.patchpoint`` and 18758``llvm.experimental.gc.statepoint``) that can be called with an invoke 18759instruction. 18760 18761Arguments: 18762"""""""""" 18763 18764None. 18765 18766Semantics: 18767"""""""""" 18768 18769This intrinsic does nothing, and it's removed by optimizers and ignored 18770by codegen. 18771 18772'``llvm.experimental.deoptimize``' Intrinsic 18773^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18774 18775Syntax: 18776""""""" 18777 18778:: 18779 18780 declare type @llvm.experimental.deoptimize(...) [ "deopt"(...) ] 18781 18782Overview: 18783""""""""" 18784 18785This intrinsic, together with :ref:`deoptimization operand bundles 18786<deopt_opbundles>`, allow frontends to express transfer of control and 18787frame-local state from the currently executing (typically more specialized, 18788hence faster) version of a function into another (typically more generic, hence 18789slower) version. 18790 18791In languages with a fully integrated managed runtime like Java and JavaScript 18792this intrinsic can be used to implement "uncommon trap" or "side exit" like 18793functionality. In unmanaged languages like C and C++, this intrinsic can be 18794used to represent the slow paths of specialized functions. 18795 18796 18797Arguments: 18798"""""""""" 18799 18800The intrinsic takes an arbitrary number of arguments, whose meaning is 18801decided by the :ref:`lowering strategy<deoptimize_lowering>`. 18802 18803Semantics: 18804"""""""""" 18805 18806The ``@llvm.experimental.deoptimize`` intrinsic executes an attached 18807deoptimization continuation (denoted using a :ref:`deoptimization 18808operand bundle <deopt_opbundles>`) and returns the value returned by 18809the deoptimization continuation. Defining the semantic properties of 18810the continuation itself is out of scope of the language reference -- 18811as far as LLVM is concerned, the deoptimization continuation can 18812invoke arbitrary side effects, including reading from and writing to 18813the entire heap. 18814 18815Deoptimization continuations expressed using ``"deopt"`` operand bundles always 18816continue execution to the end of the physical frame containing them, so all 18817calls to ``@llvm.experimental.deoptimize`` must be in "tail position": 18818 18819 - ``@llvm.experimental.deoptimize`` cannot be invoked. 18820 - The call must immediately precede a :ref:`ret <i_ret>` instruction. 18821 - The ``ret`` instruction must return the value produced by the 18822 ``@llvm.experimental.deoptimize`` call if there is one, or void. 18823 18824Note that the above restrictions imply that the return type for a call to 18825``@llvm.experimental.deoptimize`` will match the return type of its immediate 18826caller. 18827 18828The inliner composes the ``"deopt"`` continuations of the caller into the 18829``"deopt"`` continuations present in the inlinee, and also updates calls to this 18830intrinsic to return directly from the frame of the function it inlined into. 18831 18832All declarations of ``@llvm.experimental.deoptimize`` must share the 18833same calling convention. 18834 18835.. _deoptimize_lowering: 18836 18837Lowering: 18838""""""""" 18839 18840Calls to ``@llvm.experimental.deoptimize`` are lowered to calls to the 18841symbol ``__llvm_deoptimize`` (it is the frontend's responsibility to 18842ensure that this symbol is defined). The call arguments to 18843``@llvm.experimental.deoptimize`` are lowered as if they were formal 18844arguments of the specified types, and not as varargs. 18845 18846 18847'``llvm.experimental.guard``' Intrinsic 18848^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18849 18850Syntax: 18851""""""" 18852 18853:: 18854 18855 declare void @llvm.experimental.guard(i1, ...) [ "deopt"(...) ] 18856 18857Overview: 18858""""""""" 18859 18860This intrinsic, together with :ref:`deoptimization operand bundles 18861<deopt_opbundles>`, allows frontends to express guards or checks on 18862optimistic assumptions made during compilation. The semantics of 18863``@llvm.experimental.guard`` is defined in terms of 18864``@llvm.experimental.deoptimize`` -- its body is defined to be 18865equivalent to: 18866 18867.. code-block:: text 18868 18869 define void @llvm.experimental.guard(i1 %pred, <args...>) { 18870 %realPred = and i1 %pred, undef 18871 br i1 %realPred, label %continue, label %leave [, !make.implicit !{}] 18872 18873 leave: 18874 call void @llvm.experimental.deoptimize(<args...>) [ "deopt"() ] 18875 ret void 18876 18877 continue: 18878 ret void 18879 } 18880 18881 18882with the optional ``[, !make.implicit !{}]`` present if and only if it 18883is present on the call site. For more details on ``!make.implicit``, 18884see :doc:`FaultMaps`. 18885 18886In words, ``@llvm.experimental.guard`` executes the attached 18887``"deopt"`` continuation if (but **not** only if) its first argument 18888is ``false``. Since the optimizer is allowed to replace the ``undef`` 18889with an arbitrary value, it can optimize guard to fail "spuriously", 18890i.e. without the original condition being false (hence the "not only 18891if"); and this allows for "check widening" type optimizations. 18892 18893``@llvm.experimental.guard`` cannot be invoked. 18894 18895After ``@llvm.experimental.guard`` was first added, a more general 18896formulation was found in ``@llvm.experimental.widenable.condition``. 18897Support for ``@llvm.experimental.guard`` is slowly being rephrased in 18898terms of this alternate. 18899 18900'``llvm.experimental.widenable.condition``' Intrinsic 18901^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18902 18903Syntax: 18904""""""" 18905 18906:: 18907 18908 declare i1 @llvm.experimental.widenable.condition() 18909 18910Overview: 18911""""""""" 18912 18913This intrinsic represents a "widenable condition" which is 18914boolean expressions with the following property: whether this 18915expression is `true` or `false`, the program is correct and 18916well-defined. 18917 18918Together with :ref:`deoptimization operand bundles <deopt_opbundles>`, 18919``@llvm.experimental.widenable.condition`` allows frontends to 18920express guards or checks on optimistic assumptions made during 18921compilation and represent them as branch instructions on special 18922conditions. 18923 18924While this may appear similar in semantics to `undef`, it is very 18925different in that an invocation produces a particular, singular 18926value. It is also intended to be lowered late, and remain available 18927for specific optimizations and transforms that can benefit from its 18928special properties. 18929 18930Arguments: 18931"""""""""" 18932 18933None. 18934 18935Semantics: 18936"""""""""" 18937 18938The intrinsic ``@llvm.experimental.widenable.condition()`` 18939returns either `true` or `false`. For each evaluation of a call 18940to this intrinsic, the program must be valid and correct both if 18941it returns `true` and if it returns `false`. This allows 18942transformation passes to replace evaluations of this intrinsic 18943with either value whenever one is beneficial. 18944 18945When used in a branch condition, it allows us to choose between 18946two alternative correct solutions for the same problem, like 18947in example below: 18948 18949.. code-block:: text 18950 18951 %cond = call i1 @llvm.experimental.widenable.condition() 18952 br i1 %cond, label %solution_1, label %solution_2 18953 18954 label %fast_path: 18955 ; Apply memory-consuming but fast solution for a task. 18956 18957 label %slow_path: 18958 ; Cheap in memory but slow solution. 18959 18960Whether the result of intrinsic's call is `true` or `false`, 18961it should be correct to pick either solution. We can switch 18962between them by replacing the result of 18963``@llvm.experimental.widenable.condition`` with different 18964`i1` expressions. 18965 18966This is how it can be used to represent guards as widenable branches: 18967 18968.. code-block:: text 18969 18970 block: 18971 ; Unguarded instructions 18972 call void @llvm.experimental.guard(i1 %cond, <args...>) ["deopt"(<deopt_args...>)] 18973 ; Guarded instructions 18974 18975Can be expressed in an alternative equivalent form of explicit branch using 18976``@llvm.experimental.widenable.condition``: 18977 18978.. code-block:: text 18979 18980 block: 18981 ; Unguarded instructions 18982 %widenable_condition = call i1 @llvm.experimental.widenable.condition() 18983 %guard_condition = and i1 %cond, %widenable_condition 18984 br i1 %guard_condition, label %guarded, label %deopt 18985 18986 guarded: 18987 ; Guarded instructions 18988 18989 deopt: 18990 call type @llvm.experimental.deoptimize(<args...>) [ "deopt"(<deopt_args...>) ] 18991 18992So the block `guarded` is only reachable when `%cond` is `true`, 18993and it should be valid to go to the block `deopt` whenever `%cond` 18994is `true` or `false`. 18995 18996``@llvm.experimental.widenable.condition`` will never throw, thus 18997it cannot be invoked. 18998 18999Guard widening: 19000""""""""""""""" 19001 19002When ``@llvm.experimental.widenable.condition()`` is used in 19003condition of a guard represented as explicit branch, it is 19004legal to widen the guard's condition with any additional 19005conditions. 19006 19007Guard widening looks like replacement of 19008 19009.. code-block:: text 19010 19011 %widenable_cond = call i1 @llvm.experimental.widenable.condition() 19012 %guard_cond = and i1 %cond, %widenable_cond 19013 br i1 %guard_cond, label %guarded, label %deopt 19014 19015with 19016 19017.. code-block:: text 19018 19019 %widenable_cond = call i1 @llvm.experimental.widenable.condition() 19020 %new_cond = and i1 %any_other_cond, %widenable_cond 19021 %new_guard_cond = and i1 %cond, %new_cond 19022 br i1 %new_guard_cond, label %guarded, label %deopt 19023 19024for this branch. Here `%any_other_cond` is an arbitrarily chosen 19025well-defined `i1` value. By making guard widening, we may 19026impose stricter conditions on `guarded` block and bail to the 19027deopt when the new condition is not met. 19028 19029Lowering: 19030""""""""" 19031 19032Default lowering strategy is replacing the result of 19033call of ``@llvm.experimental.widenable.condition`` with 19034constant `true`. However it is always correct to replace 19035it with any other `i1` value. Any pass can 19036freely do it if it can benefit from non-default lowering. 19037 19038 19039'``llvm.load.relative``' Intrinsic 19040^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19041 19042Syntax: 19043""""""" 19044 19045:: 19046 19047 declare i8* @llvm.load.relative.iN(i8* %ptr, iN %offset) argmemonly nounwind readonly 19048 19049Overview: 19050""""""""" 19051 19052This intrinsic loads a 32-bit value from the address ``%ptr + %offset``, 19053adds ``%ptr`` to that value and returns it. The constant folder specifically 19054recognizes the form of this intrinsic and the constant initializers it may 19055load from; if a loaded constant initializer is known to have the form 19056``i32 trunc(x - %ptr)``, the intrinsic call is folded to ``x``. 19057 19058LLVM provides that the calculation of such a constant initializer will 19059not overflow at link time under the medium code model if ``x`` is an 19060``unnamed_addr`` function. However, it does not provide this guarantee for 19061a constant initializer folded into a function body. This intrinsic can be 19062used to avoid the possibility of overflows when loading from such a constant. 19063 19064'``llvm.sideeffect``' Intrinsic 19065^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19066 19067Syntax: 19068""""""" 19069 19070:: 19071 19072 declare void @llvm.sideeffect() inaccessiblememonly nounwind 19073 19074Overview: 19075""""""""" 19076 19077The ``llvm.sideeffect`` intrinsic doesn't perform any operation. Optimizers 19078treat it as having side effects, so it can be inserted into a loop to 19079indicate that the loop shouldn't be assumed to terminate (which could 19080potentially lead to the loop being optimized away entirely), even if it's 19081an infinite loop with no other side effects. 19082 19083Arguments: 19084"""""""""" 19085 19086None. 19087 19088Semantics: 19089"""""""""" 19090 19091This intrinsic actually does nothing, but optimizers must assume that it 19092has externally observable side effects. 19093 19094'``llvm.is.constant.*``' Intrinsic 19095^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19096 19097Syntax: 19098""""""" 19099 19100This is an overloaded intrinsic. You can use llvm.is.constant with any argument type. 19101 19102:: 19103 19104 declare i1 @llvm.is.constant.i32(i32 %operand) nounwind readnone 19105 declare i1 @llvm.is.constant.f32(float %operand) nounwind readnone 19106 declare i1 @llvm.is.constant.TYPENAME(TYPE %operand) nounwind readnone 19107 19108Overview: 19109""""""""" 19110 19111The '``llvm.is.constant``' intrinsic will return true if the argument 19112is known to be a manifest compile-time constant. It is guaranteed to 19113fold to either true or false before generating machine code. 19114 19115Semantics: 19116"""""""""" 19117 19118This intrinsic generates no code. If its argument is known to be a 19119manifest compile-time constant value, then the intrinsic will be 19120converted to a constant true value. Otherwise, it will be converted to 19121a constant false value. 19122 19123In particular, note that if the argument is a constant expression 19124which refers to a global (the address of which _is_ a constant, but 19125not manifest during the compile), then the intrinsic evaluates to 19126false. 19127 19128The result also intentionally depends on the result of optimization 19129passes -- e.g., the result can change depending on whether a 19130function gets inlined or not. A function's parameters are 19131obviously not constant. However, a call like 19132``llvm.is.constant.i32(i32 %param)`` *can* return true after the 19133function is inlined, if the value passed to the function parameter was 19134a constant. 19135 19136On the other hand, if constant folding is not run, it will never 19137evaluate to true, even in simple cases. 19138 19139.. _int_ptrmask: 19140 19141'``llvm.ptrmask``' Intrinsic 19142^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19143 19144Syntax: 19145""""""" 19146 19147:: 19148 19149 declare ptrty llvm.ptrmask(ptrty %ptr, intty %mask) readnone speculatable 19150 19151Arguments: 19152"""""""""" 19153 19154The first argument is a pointer. The second argument is an integer. 19155 19156Overview: 19157"""""""""" 19158 19159The ``llvm.ptrmask`` intrinsic masks out bits of the pointer according to a mask. 19160This allows stripping data from tagged pointers without converting them to an 19161integer (ptrtoint/inttoptr). As a consequence, we can preserve more information 19162to facilitate alias analysis and underlying-object detection. 19163 19164Semantics: 19165"""""""""" 19166 19167The result of ``ptrmask(ptr, mask)`` is equivalent to 19168``getelementptr ptr, (ptrtoint(ptr) & mask) - ptrtoint(ptr)``. Both the returned 19169pointer and the first argument are based on the same underlying object (for more 19170information on the *based on* terminology see 19171:ref:`the pointer aliasing rules <pointeraliasing>`). If the bitwidth of the 19172mask argument does not match the pointer size of the target, the mask is 19173zero-extended or truncated accordingly. 19174 19175.. _int_vscale: 19176 19177'``llvm.vscale``' Intrinsic 19178^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19179 19180Syntax: 19181""""""" 19182 19183:: 19184 19185 declare i32 llvm.vscale.i32() 19186 declare i64 llvm.vscale.i64() 19187 19188Overview: 19189""""""""" 19190 19191The ``llvm.vscale`` intrinsic returns the value for ``vscale`` in scalable 19192vectors such as ``<vscale x 16 x i8>``. 19193 19194Semantics: 19195"""""""""" 19196 19197``vscale`` is a positive value that is constant throughout program 19198execution, but is unknown at compile time. 19199If the result value does not fit in the result type, then the result is 19200a :ref:`poison value <poisonvalues>`. 19201 19202 19203Stack Map Intrinsics 19204-------------------- 19205 19206LLVM provides experimental intrinsics to support runtime patching 19207mechanisms commonly desired in dynamic language JITs. These intrinsics 19208are described in :doc:`StackMaps`. 19209 19210Element Wise Atomic Memory Intrinsics 19211------------------------------------- 19212 19213These intrinsics are similar to the standard library memory intrinsics except 19214that they perform memory transfer as a sequence of atomic memory accesses. 19215 19216.. _int_memcpy_element_unordered_atomic: 19217 19218'``llvm.memcpy.element.unordered.atomic``' Intrinsic 19219^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19220 19221Syntax: 19222""""""" 19223 19224This is an overloaded intrinsic. You can use ``llvm.memcpy.element.unordered.atomic`` on 19225any integer bit width and for different address spaces. Not all targets 19226support all bit widths however. 19227 19228:: 19229 19230 declare void @llvm.memcpy.element.unordered.atomic.p0i8.p0i8.i32(i8* <dest>, 19231 i8* <src>, 19232 i32 <len>, 19233 i32 <element_size>) 19234 declare void @llvm.memcpy.element.unordered.atomic.p0i8.p0i8.i64(i8* <dest>, 19235 i8* <src>, 19236 i64 <len>, 19237 i32 <element_size>) 19238 19239Overview: 19240""""""""" 19241 19242The '``llvm.memcpy.element.unordered.atomic.*``' intrinsic is a specialization of the 19243'``llvm.memcpy.*``' intrinsic. It differs in that the ``dest`` and ``src`` are treated 19244as arrays with elements that are exactly ``element_size`` bytes, and the copy between 19245buffers uses a sequence of :ref:`unordered atomic <ordering>` load/store operations 19246that are a positive integer multiple of the ``element_size`` in size. 19247 19248Arguments: 19249"""""""""" 19250 19251The first three arguments are the same as they are in the :ref:`@llvm.memcpy <int_memcpy>` 19252intrinsic, with the added constraint that ``len`` is required to be a positive integer 19253multiple of the ``element_size``. If ``len`` is not a positive integer multiple of 19254``element_size``, then the behaviour of the intrinsic is undefined. 19255 19256``element_size`` must be a compile-time constant positive power of two no greater than 19257target-specific atomic access size limit. 19258 19259For each of the input pointers ``align`` parameter attribute must be specified. It 19260must be a power of two no less than the ``element_size``. Caller guarantees that 19261both the source and destination pointers are aligned to that boundary. 19262 19263Semantics: 19264"""""""""" 19265 19266The '``llvm.memcpy.element.unordered.atomic.*``' intrinsic copies ``len`` bytes of 19267memory from the source location to the destination location. These locations are not 19268allowed to overlap. The memory copy is performed as a sequence of load/store operations 19269where each access is guaranteed to be a multiple of ``element_size`` bytes wide and 19270aligned at an ``element_size`` boundary. 19271 19272The order of the copy is unspecified. The same value may be read from the source 19273buffer many times, but only one write is issued to the destination buffer per 19274element. It is well defined to have concurrent reads and writes to both source and 19275destination provided those reads and writes are unordered atomic when specified. 19276 19277This intrinsic does not provide any additional ordering guarantees over those 19278provided by a set of unordered loads from the source location and stores to the 19279destination. 19280 19281Lowering: 19282""""""""" 19283 19284In the most general case call to the '``llvm.memcpy.element.unordered.atomic.*``' is 19285lowered to a call to the symbol ``__llvm_memcpy_element_unordered_atomic_*``. Where '*' 19286is replaced with an actual element size. 19287 19288Optimizer is allowed to inline memory copy when it's profitable to do so. 19289 19290'``llvm.memmove.element.unordered.atomic``' Intrinsic 19291^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19292 19293Syntax: 19294""""""" 19295 19296This is an overloaded intrinsic. You can use 19297``llvm.memmove.element.unordered.atomic`` on any integer bit width and for 19298different address spaces. Not all targets support all bit widths however. 19299 19300:: 19301 19302 declare void @llvm.memmove.element.unordered.atomic.p0i8.p0i8.i32(i8* <dest>, 19303 i8* <src>, 19304 i32 <len>, 19305 i32 <element_size>) 19306 declare void @llvm.memmove.element.unordered.atomic.p0i8.p0i8.i64(i8* <dest>, 19307 i8* <src>, 19308 i64 <len>, 19309 i32 <element_size>) 19310 19311Overview: 19312""""""""" 19313 19314The '``llvm.memmove.element.unordered.atomic.*``' intrinsic is a specialization 19315of the '``llvm.memmove.*``' intrinsic. It differs in that the ``dest`` and 19316``src`` are treated as arrays with elements that are exactly ``element_size`` 19317bytes, and the copy between buffers uses a sequence of 19318:ref:`unordered atomic <ordering>` load/store operations that are a positive 19319integer multiple of the ``element_size`` in size. 19320 19321Arguments: 19322"""""""""" 19323 19324The first three arguments are the same as they are in the 19325:ref:`@llvm.memmove <int_memmove>` intrinsic, with the added constraint that 19326``len`` is required to be a positive integer multiple of the ``element_size``. 19327If ``len`` is not a positive integer multiple of ``element_size``, then the 19328behaviour of the intrinsic is undefined. 19329 19330``element_size`` must be a compile-time constant positive power of two no 19331greater than a target-specific atomic access size limit. 19332 19333For each of the input pointers the ``align`` parameter attribute must be 19334specified. It must be a power of two no less than the ``element_size``. Caller 19335guarantees that both the source and destination pointers are aligned to that 19336boundary. 19337 19338Semantics: 19339"""""""""" 19340 19341The '``llvm.memmove.element.unordered.atomic.*``' intrinsic copies ``len`` bytes 19342of memory from the source location to the destination location. These locations 19343are allowed to overlap. The memory copy is performed as a sequence of load/store 19344operations where each access is guaranteed to be a multiple of ``element_size`` 19345bytes wide and aligned at an ``element_size`` boundary. 19346 19347The order of the copy is unspecified. The same value may be read from the source 19348buffer many times, but only one write is issued to the destination buffer per 19349element. It is well defined to have concurrent reads and writes to both source 19350and destination provided those reads and writes are unordered atomic when 19351specified. 19352 19353This intrinsic does not provide any additional ordering guarantees over those 19354provided by a set of unordered loads from the source location and stores to the 19355destination. 19356 19357Lowering: 19358""""""""" 19359 19360In the most general case call to the 19361'``llvm.memmove.element.unordered.atomic.*``' is lowered to a call to the symbol 19362``__llvm_memmove_element_unordered_atomic_*``. Where '*' is replaced with an 19363actual element size. 19364 19365The optimizer is allowed to inline the memory copy when it's profitable to do so. 19366 19367.. _int_memset_element_unordered_atomic: 19368 19369'``llvm.memset.element.unordered.atomic``' Intrinsic 19370^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19371 19372Syntax: 19373""""""" 19374 19375This is an overloaded intrinsic. You can use ``llvm.memset.element.unordered.atomic`` on 19376any integer bit width and for different address spaces. Not all targets 19377support all bit widths however. 19378 19379:: 19380 19381 declare void @llvm.memset.element.unordered.atomic.p0i8.i32(i8* <dest>, 19382 i8 <value>, 19383 i32 <len>, 19384 i32 <element_size>) 19385 declare void @llvm.memset.element.unordered.atomic.p0i8.i64(i8* <dest>, 19386 i8 <value>, 19387 i64 <len>, 19388 i32 <element_size>) 19389 19390Overview: 19391""""""""" 19392 19393The '``llvm.memset.element.unordered.atomic.*``' intrinsic is a specialization of the 19394'``llvm.memset.*``' intrinsic. It differs in that the ``dest`` is treated as an array 19395with elements that are exactly ``element_size`` bytes, and the assignment to that array 19396uses uses a sequence of :ref:`unordered atomic <ordering>` store operations 19397that are a positive integer multiple of the ``element_size`` in size. 19398 19399Arguments: 19400"""""""""" 19401 19402The first three arguments are the same as they are in the :ref:`@llvm.memset <int_memset>` 19403intrinsic, with the added constraint that ``len`` is required to be a positive integer 19404multiple of the ``element_size``. If ``len`` is not a positive integer multiple of 19405``element_size``, then the behaviour of the intrinsic is undefined. 19406 19407``element_size`` must be a compile-time constant positive power of two no greater than 19408target-specific atomic access size limit. 19409 19410The ``dest`` input pointer must have the ``align`` parameter attribute specified. It 19411must be a power of two no less than the ``element_size``. Caller guarantees that 19412the destination pointer is aligned to that boundary. 19413 19414Semantics: 19415"""""""""" 19416 19417The '``llvm.memset.element.unordered.atomic.*``' intrinsic sets the ``len`` bytes of 19418memory starting at the destination location to the given ``value``. The memory is 19419set with a sequence of store operations where each access is guaranteed to be a 19420multiple of ``element_size`` bytes wide and aligned at an ``element_size`` boundary. 19421 19422The order of the assignment is unspecified. Only one write is issued to the 19423destination buffer per element. It is well defined to have concurrent reads and 19424writes to the destination provided those reads and writes are unordered atomic 19425when specified. 19426 19427This intrinsic does not provide any additional ordering guarantees over those 19428provided by a set of unordered stores to the destination. 19429 19430Lowering: 19431""""""""" 19432 19433In the most general case call to the '``llvm.memset.element.unordered.atomic.*``' is 19434lowered to a call to the symbol ``__llvm_memset_element_unordered_atomic_*``. Where '*' 19435is replaced with an actual element size. 19436 19437The optimizer is allowed to inline the memory assignment when it's profitable to do so. 19438 19439Objective-C ARC Runtime Intrinsics 19440---------------------------------- 19441 19442LLVM provides intrinsics that lower to Objective-C ARC runtime entry points. 19443LLVM is aware of the semantics of these functions, and optimizes based on that 19444knowledge. You can read more about the details of Objective-C ARC `here 19445<https://clang.llvm.org/docs/AutomaticReferenceCounting.html>`_. 19446 19447'``llvm.objc.autorelease``' Intrinsic 19448^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19449 19450Syntax: 19451""""""" 19452:: 19453 19454 declare i8* @llvm.objc.autorelease(i8*) 19455 19456Lowering: 19457""""""""" 19458 19459Lowers to a call to `objc_autorelease <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-autorelease>`_. 19460 19461'``llvm.objc.autoreleasePoolPop``' Intrinsic 19462^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19463 19464Syntax: 19465""""""" 19466:: 19467 19468 declare void @llvm.objc.autoreleasePoolPop(i8*) 19469 19470Lowering: 19471""""""""" 19472 19473Lowers to a call to `objc_autoreleasePoolPop <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-autoreleasepoolpop-void-pool>`_. 19474 19475'``llvm.objc.autoreleasePoolPush``' Intrinsic 19476^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19477 19478Syntax: 19479""""""" 19480:: 19481 19482 declare i8* @llvm.objc.autoreleasePoolPush() 19483 19484Lowering: 19485""""""""" 19486 19487Lowers to a call to `objc_autoreleasePoolPush <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-autoreleasepoolpush-void>`_. 19488 19489'``llvm.objc.autoreleaseReturnValue``' Intrinsic 19490^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19491 19492Syntax: 19493""""""" 19494:: 19495 19496 declare i8* @llvm.objc.autoreleaseReturnValue(i8*) 19497 19498Lowering: 19499""""""""" 19500 19501Lowers to a call to `objc_autoreleaseReturnValue <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-autoreleasereturnvalue>`_. 19502 19503'``llvm.objc.copyWeak``' Intrinsic 19504^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19505 19506Syntax: 19507""""""" 19508:: 19509 19510 declare void @llvm.objc.copyWeak(i8**, i8**) 19511 19512Lowering: 19513""""""""" 19514 19515Lowers to a call to `objc_copyWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-copyweak-id-dest-id-src>`_. 19516 19517'``llvm.objc.destroyWeak``' Intrinsic 19518^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19519 19520Syntax: 19521""""""" 19522:: 19523 19524 declare void @llvm.objc.destroyWeak(i8**) 19525 19526Lowering: 19527""""""""" 19528 19529Lowers to a call to `objc_destroyWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-destroyweak-id-object>`_. 19530 19531'``llvm.objc.initWeak``' Intrinsic 19532^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19533 19534Syntax: 19535""""""" 19536:: 19537 19538 declare i8* @llvm.objc.initWeak(i8**, i8*) 19539 19540Lowering: 19541""""""""" 19542 19543Lowers to a call to `objc_initWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-initweak>`_. 19544 19545'``llvm.objc.loadWeak``' Intrinsic 19546^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19547 19548Syntax: 19549""""""" 19550:: 19551 19552 declare i8* @llvm.objc.loadWeak(i8**) 19553 19554Lowering: 19555""""""""" 19556 19557Lowers to a call to `objc_loadWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-loadweak>`_. 19558 19559'``llvm.objc.loadWeakRetained``' Intrinsic 19560^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19561 19562Syntax: 19563""""""" 19564:: 19565 19566 declare i8* @llvm.objc.loadWeakRetained(i8**) 19567 19568Lowering: 19569""""""""" 19570 19571Lowers to a call to `objc_loadWeakRetained <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-loadweakretained>`_. 19572 19573'``llvm.objc.moveWeak``' Intrinsic 19574^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19575 19576Syntax: 19577""""""" 19578:: 19579 19580 declare void @llvm.objc.moveWeak(i8**, i8**) 19581 19582Lowering: 19583""""""""" 19584 19585Lowers to a call to `objc_moveWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-moveweak-id-dest-id-src>`_. 19586 19587'``llvm.objc.release``' Intrinsic 19588^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19589 19590Syntax: 19591""""""" 19592:: 19593 19594 declare void @llvm.objc.release(i8*) 19595 19596Lowering: 19597""""""""" 19598 19599Lowers to a call to `objc_release <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-release-id-value>`_. 19600 19601'``llvm.objc.retain``' Intrinsic 19602^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19603 19604Syntax: 19605""""""" 19606:: 19607 19608 declare i8* @llvm.objc.retain(i8*) 19609 19610Lowering: 19611""""""""" 19612 19613Lowers to a call to `objc_retain <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retain>`_. 19614 19615'``llvm.objc.retainAutorelease``' Intrinsic 19616^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19617 19618Syntax: 19619""""""" 19620:: 19621 19622 declare i8* @llvm.objc.retainAutorelease(i8*) 19623 19624Lowering: 19625""""""""" 19626 19627Lowers to a call to `objc_retainAutorelease <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retainautorelease>`_. 19628 19629'``llvm.objc.retainAutoreleaseReturnValue``' Intrinsic 19630^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19631 19632Syntax: 19633""""""" 19634:: 19635 19636 declare i8* @llvm.objc.retainAutoreleaseReturnValue(i8*) 19637 19638Lowering: 19639""""""""" 19640 19641Lowers to a call to `objc_retainAutoreleaseReturnValue <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retainautoreleasereturnvalue>`_. 19642 19643'``llvm.objc.retainAutoreleasedReturnValue``' Intrinsic 19644^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19645 19646Syntax: 19647""""""" 19648:: 19649 19650 declare i8* @llvm.objc.retainAutoreleasedReturnValue(i8*) 19651 19652Lowering: 19653""""""""" 19654 19655Lowers to a call to `objc_retainAutoreleasedReturnValue <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retainautoreleasedreturnvalue>`_. 19656 19657'``llvm.objc.retainBlock``' Intrinsic 19658^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19659 19660Syntax: 19661""""""" 19662:: 19663 19664 declare i8* @llvm.objc.retainBlock(i8*) 19665 19666Lowering: 19667""""""""" 19668 19669Lowers to a call to `objc_retainBlock <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retainblock>`_. 19670 19671'``llvm.objc.storeStrong``' Intrinsic 19672^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19673 19674Syntax: 19675""""""" 19676:: 19677 19678 declare void @llvm.objc.storeStrong(i8**, i8*) 19679 19680Lowering: 19681""""""""" 19682 19683Lowers to a call to `objc_storeStrong <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-storestrong-id-object-id-value>`_. 19684 19685'``llvm.objc.storeWeak``' Intrinsic 19686^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19687 19688Syntax: 19689""""""" 19690:: 19691 19692 declare i8* @llvm.objc.storeWeak(i8**, i8*) 19693 19694Lowering: 19695""""""""" 19696 19697Lowers to a call to `objc_storeWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-storeweak>`_. 19698 19699Preserving Debug Information Intrinsics 19700^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19701 19702These intrinsics are used to carry certain debuginfo together with 19703IR-level operations. For example, it may be desirable to 19704know the structure/union name and the original user-level field 19705indices. Such information got lost in IR GetElementPtr instruction 19706since the IR types are different from debugInfo types and unions 19707are converted to structs in IR. 19708 19709'``llvm.preserve.array.access.index``' Intrinsic 19710^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19711 19712Syntax: 19713""""""" 19714:: 19715 19716 declare <ret_type> 19717 @llvm.preserve.array.access.index.p0s_union.anons.p0a10s_union.anons(<type> base, 19718 i32 dim, 19719 i32 index) 19720 19721Overview: 19722""""""""" 19723 19724The '``llvm.preserve.array.access.index``' intrinsic returns the getelementptr address 19725based on array base ``base``, array dimension ``dim`` and the last access index ``index`` 19726into the array. The return type ``ret_type`` is a pointer type to the array element. 19727The array ``dim`` and ``index`` are preserved which is more robust than 19728getelementptr instruction which may be subject to compiler transformation. 19729The ``llvm.preserve.access.index`` type of metadata is attached to this call instruction 19730to provide array or pointer debuginfo type. 19731The metadata is a ``DICompositeType`` or ``DIDerivedType`` representing the 19732debuginfo version of ``type``. 19733 19734Arguments: 19735"""""""""" 19736 19737The ``base`` is the array base address. The ``dim`` is the array dimension. 19738The ``base`` is a pointer if ``dim`` equals 0. 19739The ``index`` is the last access index into the array or pointer. 19740 19741Semantics: 19742"""""""""" 19743 19744The '``llvm.preserve.array.access.index``' intrinsic produces the same result 19745as a getelementptr with base ``base`` and access operands ``{dim's 0's, index}``. 19746 19747'``llvm.preserve.union.access.index``' Intrinsic 19748^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19749 19750Syntax: 19751""""""" 19752:: 19753 19754 declare <type> 19755 @llvm.preserve.union.access.index.p0s_union.anons.p0s_union.anons(<type> base, 19756 i32 di_index) 19757 19758Overview: 19759""""""""" 19760 19761The '``llvm.preserve.union.access.index``' intrinsic carries the debuginfo field index 19762``di_index`` and returns the ``base`` address. 19763The ``llvm.preserve.access.index`` type of metadata is attached to this call instruction 19764to provide union debuginfo type. 19765The metadata is a ``DICompositeType`` representing the debuginfo version of ``type``. 19766The return type ``type`` is the same as the ``base`` type. 19767 19768Arguments: 19769"""""""""" 19770 19771The ``base`` is the union base address. The ``di_index`` is the field index in debuginfo. 19772 19773Semantics: 19774"""""""""" 19775 19776The '``llvm.preserve.union.access.index``' intrinsic returns the ``base`` address. 19777 19778'``llvm.preserve.struct.access.index``' Intrinsic 19779^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19780 19781Syntax: 19782""""""" 19783:: 19784 19785 declare <ret_type> 19786 @llvm.preserve.struct.access.index.p0i8.p0s_struct.anon.0s(<type> base, 19787 i32 gep_index, 19788 i32 di_index) 19789 19790Overview: 19791""""""""" 19792 19793The '``llvm.preserve.struct.access.index``' intrinsic returns the getelementptr address 19794based on struct base ``base`` and IR struct member index ``gep_index``. 19795The ``llvm.preserve.access.index`` type of metadata is attached to this call instruction 19796to provide struct debuginfo type. 19797The metadata is a ``DICompositeType`` representing the debuginfo version of ``type``. 19798The return type ``ret_type`` is a pointer type to the structure member. 19799 19800Arguments: 19801"""""""""" 19802 19803The ``base`` is the structure base address. The ``gep_index`` is the struct member index 19804based on IR structures. The ``di_index`` is the struct member index based on debuginfo. 19805 19806Semantics: 19807"""""""""" 19808 19809The '``llvm.preserve.struct.access.index``' intrinsic produces the same result 19810as a getelementptr with base ``base`` and access operands ``{0, gep_index}``. 19811