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 global variable or function *declaration* to have any 276linkage type other 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"``tailcc``" - Tail callable calling convention 436 This calling convention ensures that calls in tail position will always be 437 tail call optimized. This calling convention is equivalent to fastcc, 438 except for an additional guarantee that tail calls will be produced 439 whenever possible. `Tail calls can only be optimized when this, the fastcc, 440 the GHC or the HiPE convention is used. <CodeGenerator.html#id80>`_ This 441 calling convention does not support varargs and requires the prototype of 442 all callees to exactly match the prototype of the function definition. 443"``swiftcc``" - This calling convention is used for Swift language. 444 - On X86-64 RCX and R8 are available for additional integer returns, and 445 XMM2 and XMM3 are available for additional FP/vector returns. 446 - On iOS platforms, we use AAPCS-VFP calling convention. 447"``swifttailcc``" 448 This calling convention is like ``swiftcc`` in most respects, but also the 449 callee pops the argument area of the stack so that mandatory tail calls are 450 possible as in ``tailcc``. 451"``cfguard_checkcc``" - Windows Control Flow Guard (Check mechanism) 452 This calling convention is used for the Control Flow Guard check function, 453 calls to which can be inserted before indirect calls to check that the call 454 target is a valid function address. The check function has no return value, 455 but it will trigger an OS-level error if the address is not a valid target. 456 The set of registers preserved by the check function, and the register 457 containing the target address are architecture-specific. 458 459 - On X86 the target address is passed in ECX. 460 - On ARM the target address is passed in R0. 461 - On AArch64 the target address is passed in X15. 462"``cc <n>``" - Numbered convention 463 Any calling convention may be specified by number, allowing 464 target-specific calling conventions to be used. Target specific 465 calling conventions start at 64. 466 467More calling conventions can be added/defined on an as-needed basis, to 468support Pascal conventions or any other well-known target-independent 469convention. 470 471.. _visibilitystyles: 472 473Visibility Styles 474----------------- 475 476All Global Variables and Functions have one of the following visibility 477styles: 478 479"``default``" - Default style 480 On targets that use the ELF object file format, default visibility 481 means that the declaration is visible to other modules and, in 482 shared libraries, means that the declared entity may be overridden. 483 On Darwin, default visibility means that the declaration is visible 484 to other modules. Default visibility corresponds to "external 485 linkage" in the language. 486"``hidden``" - Hidden style 487 Two declarations of an object with hidden visibility refer to the 488 same object if they are in the same shared object. Usually, hidden 489 visibility indicates that the symbol will not be placed into the 490 dynamic symbol table, so no other module (executable or shared 491 library) can reference it directly. 492"``protected``" - Protected style 493 On ELF, protected visibility indicates that the symbol will be 494 placed in the dynamic symbol table, but that references within the 495 defining module will bind to the local symbol. That is, the symbol 496 cannot be overridden by another module. 497 498A symbol with ``internal`` or ``private`` linkage must have ``default`` 499visibility. 500 501.. _dllstorageclass: 502 503DLL Storage Classes 504------------------- 505 506All Global Variables, Functions and Aliases can have one of the following 507DLL storage class: 508 509``dllimport`` 510 "``dllimport``" causes the compiler to reference a function or variable via 511 a global pointer to a pointer that is set up by the DLL exporting the 512 symbol. On Microsoft Windows targets, the pointer name is formed by 513 combining ``__imp_`` and the function or variable name. 514``dllexport`` 515 "``dllexport``" causes the compiler to provide a global pointer to a pointer 516 in a DLL, so that it can be referenced with the ``dllimport`` attribute. On 517 Microsoft Windows targets, the pointer name is formed by combining 518 ``__imp_`` and the function or variable name. Since this storage class 519 exists for defining a dll interface, the compiler, assembler and linker know 520 it is externally referenced and must refrain from deleting the symbol. 521 522.. _tls_model: 523 524Thread Local Storage Models 525--------------------------- 526 527A variable may be defined as ``thread_local``, which means that it will 528not be shared by threads (each thread will have a separated copy of the 529variable). Not all targets support thread-local variables. Optionally, a 530TLS model may be specified: 531 532``localdynamic`` 533 For variables that are only used within the current shared library. 534``initialexec`` 535 For variables in modules that will not be loaded dynamically. 536``localexec`` 537 For variables defined in the executable and only used within it. 538 539If no explicit model is given, the "general dynamic" model is used. 540 541The models correspond to the ELF TLS models; see `ELF Handling For 542Thread-Local Storage <http://people.redhat.com/drepper/tls.pdf>`_ for 543more information on under which circumstances the different models may 544be used. The target may choose a different TLS model if the specified 545model is not supported, or if a better choice of model can be made. 546 547A model can also be specified in an alias, but then it only governs how 548the alias is accessed. It will not have any effect in the aliasee. 549 550For platforms without linker support of ELF TLS model, the -femulated-tls 551flag can be used to generate GCC compatible emulated TLS code. 552 553.. _runtime_preemption_model: 554 555Runtime Preemption Specifiers 556----------------------------- 557 558Global variables, functions and aliases may have an optional runtime preemption 559specifier. If a preemption specifier isn't given explicitly, then a 560symbol is assumed to be ``dso_preemptable``. 561 562``dso_preemptable`` 563 Indicates that the function or variable may be replaced by a symbol from 564 outside the linkage unit at runtime. 565 566``dso_local`` 567 The compiler may assume that a function or variable marked as ``dso_local`` 568 will resolve to a symbol within the same linkage unit. Direct access will 569 be generated even if the definition is not within this compilation unit. 570 571.. _namedtypes: 572 573Structure Types 574--------------- 575 576LLVM IR allows you to specify both "identified" and "literal" :ref:`structure 577types <t_struct>`. Literal types are uniqued structurally, but identified types 578are never uniqued. An :ref:`opaque structural type <t_opaque>` can also be used 579to forward declare a type that is not yet available. 580 581An example of an identified structure specification is: 582 583.. code-block:: llvm 584 585 %mytype = type { %mytype*, i32 } 586 587Prior to the LLVM 3.0 release, identified types were structurally uniqued. Only 588literal types are uniqued in recent versions of LLVM. 589 590.. _nointptrtype: 591 592Non-Integral Pointer Type 593------------------------- 594 595Note: non-integral pointer types are a work in progress, and they should be 596considered experimental at this time. 597 598LLVM IR optionally allows the frontend to denote pointers in certain address 599spaces as "non-integral" via the :ref:`datalayout string<langref_datalayout>`. 600Non-integral pointer types represent pointers that have an *unspecified* bitwise 601representation; that is, the integral representation may be target dependent or 602unstable (not backed by a fixed integer). 603 604``inttoptr`` and ``ptrtoint`` instructions have the same semantics as for 605integral (i.e. normal) pointers in that they convert integers to and from 606corresponding pointer types, but there are additional implications to be 607aware of. Because the bit-representation of a non-integral pointer may 608not be stable, two identical casts of the same operand may or may not 609return the same value. Said differently, the conversion to or from the 610non-integral type depends on environmental state in an implementation 611defined manner. 612 613If the frontend wishes to observe a *particular* value following a cast, the 614generated IR must fence with the underlying environment in an implementation 615defined manner. (In practice, this tends to require ``noinline`` routines for 616such operations.) 617 618From the perspective of the optimizer, ``inttoptr`` and ``ptrtoint`` for 619non-integral types are analogous to ones on integral types with one 620key exception: the optimizer may not, in general, insert new dynamic 621occurrences of such casts. If a new cast is inserted, the optimizer would 622need to either ensure that a) all possible values are valid, or b) 623appropriate fencing is inserted. Since the appropriate fencing is 624implementation defined, the optimizer can't do the latter. The former is 625challenging as many commonly expected properties, such as 626``ptrtoint(v)-ptrtoint(v) == 0``, don't hold for non-integral types. 627 628.. _globalvars: 629 630Global Variables 631---------------- 632 633Global variables define regions of memory allocated at compilation time 634instead of run-time. 635 636Global variable definitions must be initialized. 637 638Global variables in other translation units can also be declared, in which 639case they don't have an initializer. 640 641Global variables can optionally specify a :ref:`linkage type <linkage>`. 642 643Either global variable definitions or declarations may have an explicit section 644to be placed in and may have an optional explicit alignment specified. If there 645is a mismatch between the explicit or inferred section information for the 646variable declaration and its definition the resulting behavior is undefined. 647 648A variable may be defined as a global ``constant``, which indicates that 649the contents of the variable will **never** be modified (enabling better 650optimization, allowing the global data to be placed in the read-only 651section of an executable, etc). Note that variables that need runtime 652initialization cannot be marked ``constant`` as there is a store to the 653variable. 654 655LLVM explicitly allows *declarations* of global variables to be marked 656constant, even if the final definition of the global is not. This 657capability can be used to enable slightly better optimization of the 658program, but requires the language definition to guarantee that 659optimizations based on the 'constantness' are valid for the translation 660units that do not include the definition. 661 662As SSA values, global variables define pointer values that are in scope 663(i.e. they dominate) all basic blocks in the program. Global variables 664always define a pointer to their "content" type because they describe a 665region of memory, and all memory objects in LLVM are accessed through 666pointers. 667 668Global variables can be marked with ``unnamed_addr`` which indicates 669that the address is not significant, only the content. Constants marked 670like this can be merged with other constants if they have the same 671initializer. Note that a constant with significant address *can* be 672merged with a ``unnamed_addr`` constant, the result being a constant 673whose address is significant. 674 675If the ``local_unnamed_addr`` attribute is given, the address is known to 676not be significant within the module. 677 678A global variable may be declared to reside in a target-specific 679numbered address space. For targets that support them, address spaces 680may affect how optimizations are performed and/or what target 681instructions are used to access the variable. The default address space 682is zero. The address space qualifier must precede any other attributes. 683 684LLVM allows an explicit section to be specified for globals. If the 685target supports it, it will emit globals to the section specified. 686Additionally, the global can placed in a comdat if the target has the necessary 687support. 688 689External declarations may have an explicit section specified. Section 690information is retained in LLVM IR for targets that make use of this 691information. Attaching section information to an external declaration is an 692assertion that its definition is located in the specified section. If the 693definition is located in a different section, the behavior is undefined. 694 695By default, global initializers are optimized by assuming that global 696variables defined within the module are not modified from their 697initial values before the start of the global initializer. This is 698true even for variables potentially accessible from outside the 699module, including those with external linkage or appearing in 700``@llvm.used`` or dllexported variables. This assumption may be suppressed 701by marking the variable with ``externally_initialized``. 702 703An explicit alignment may be specified for a global, which must be a 704power of 2. If not present, or if the alignment is set to zero, the 705alignment of the global is set by the target to whatever it feels 706convenient. If an explicit alignment is specified, the global is forced 707to have exactly that alignment. Targets and optimizers are not allowed 708to over-align the global if the global has an assigned section. In this 709case, the extra alignment could be observable: for example, code could 710assume that the globals are densely packed in their section and try to 711iterate over them as an array, alignment padding would break this 712iteration. The maximum alignment is ``1 << 29``. 713 714For global variables declarations, as well as definitions that may be 715replaced at link time (``linkonce``, ``weak``, ``extern_weak`` and ``common`` 716linkage types), LLVM makes no assumptions about the allocation size of the 717variables, except that they may not overlap. The alignment of a global variable 718declaration or replaceable definition must not be greater than the alignment of 719the definition it resolves to. 720 721Globals can also have a :ref:`DLL storage class <dllstorageclass>`, 722an optional :ref:`runtime preemption specifier <runtime_preemption_model>`, 723an optional :ref:`global attributes <glattrs>` and 724an optional list of attached :ref:`metadata <metadata>`. 725 726Variables and aliases can have a 727:ref:`Thread Local Storage Model <tls_model>`. 728 729:ref:`Scalable vectors <t_vector>` cannot be global variables or members of 730arrays because their size is unknown at compile time. They are allowed in 731structs to facilitate intrinsics returning multiple values. Structs containing 732scalable vectors cannot be used in loads, stores, allocas, or GEPs. 733 734Syntax:: 735 736 @<GlobalVarName> = [Linkage] [PreemptionSpecifier] [Visibility] 737 [DLLStorageClass] [ThreadLocal] 738 [(unnamed_addr|local_unnamed_addr)] [AddrSpace] 739 [ExternallyInitialized] 740 <global | constant> <Type> [<InitializerConstant>] 741 [, section "name"] [, comdat [($name)]] 742 [, align <Alignment>] (, !name !N)* 743 744For example, the following defines a global in a numbered address space 745with an initializer, section, and alignment: 746 747.. code-block:: llvm 748 749 @G = addrspace(5) constant float 1.0, section "foo", align 4 750 751The following example just declares a global variable 752 753.. code-block:: llvm 754 755 @G = external global i32 756 757The following example defines a thread-local global with the 758``initialexec`` TLS model: 759 760.. code-block:: llvm 761 762 @G = thread_local(initialexec) global i32 0, align 4 763 764.. _functionstructure: 765 766Functions 767--------- 768 769LLVM function definitions consist of the "``define``" keyword, an 770optional :ref:`linkage type <linkage>`, an optional :ref:`runtime preemption 771specifier <runtime_preemption_model>`, an optional :ref:`visibility 772style <visibility>`, an optional :ref:`DLL storage class <dllstorageclass>`, 773an optional :ref:`calling convention <callingconv>`, 774an optional ``unnamed_addr`` attribute, a return type, an optional 775:ref:`parameter attribute <paramattrs>` for the return type, a function 776name, a (possibly empty) argument list (each with optional :ref:`parameter 777attributes <paramattrs>`), optional :ref:`function attributes <fnattrs>`, 778an optional address space, an optional section, an optional alignment, 779an optional :ref:`comdat <langref_comdats>`, 780an optional :ref:`garbage collector name <gc>`, an optional :ref:`prefix <prefixdata>`, 781an optional :ref:`prologue <prologuedata>`, 782an optional :ref:`personality <personalityfn>`, 783an optional list of attached :ref:`metadata <metadata>`, 784an opening curly brace, a list of basic blocks, and a closing curly brace. 785 786LLVM function declarations consist of the "``declare``" keyword, an 787optional :ref:`linkage type <linkage>`, an optional :ref:`visibility style 788<visibility>`, an optional :ref:`DLL storage class <dllstorageclass>`, an 789optional :ref:`calling convention <callingconv>`, an optional ``unnamed_addr`` 790or ``local_unnamed_addr`` attribute, an optional address space, a return type, 791an optional :ref:`parameter attribute <paramattrs>` for the return type, a function name, a possibly 792empty list of arguments, an optional alignment, an optional :ref:`garbage 793collector name <gc>`, an optional :ref:`prefix <prefixdata>`, and an optional 794:ref:`prologue <prologuedata>`. 795 796A function definition contains a list of basic blocks, forming the CFG (Control 797Flow Graph) for the function. Each basic block may optionally start with a label 798(giving the basic block a symbol table entry), contains a list of instructions, 799and ends with a :ref:`terminator <terminators>` instruction (such as a branch or 800function return). If an explicit label name is not provided, a block is assigned 801an implicit numbered label, using the next value from the same counter as used 802for unnamed temporaries (:ref:`see above<identifiers>`). For example, if a 803function entry block does not have an explicit label, it will be assigned label 804"%0", then the first unnamed temporary in that block will be "%1", etc. If a 805numeric label is explicitly specified, it must match the numeric label that 806would be used implicitly. 807 808The first basic block in a function is special in two ways: it is 809immediately executed on entrance to the function, and it is not allowed 810to have predecessor basic blocks (i.e. there can not be any branches to 811the entry block of a function). Because the block can have no 812predecessors, it also cannot have any :ref:`PHI nodes <i_phi>`. 813 814LLVM allows an explicit section to be specified for functions. If the 815target supports it, it will emit functions to the section specified. 816Additionally, the function can be placed in a COMDAT. 817 818An explicit alignment may be specified for a function. If not present, 819or if the alignment is set to zero, the alignment of the function is set 820by the target to whatever it feels convenient. If an explicit alignment 821is specified, the function is forced to have at least that much 822alignment. All alignments must be a power of 2. 823 824If the ``unnamed_addr`` attribute is given, the address is known to not 825be significant and two identical functions can be merged. 826 827If the ``local_unnamed_addr`` attribute is given, the address is known to 828not be significant within the module. 829 830If an explicit address space is not given, it will default to the program 831address space from the :ref:`datalayout string<langref_datalayout>`. 832 833Syntax:: 834 835 define [linkage] [PreemptionSpecifier] [visibility] [DLLStorageClass] 836 [cconv] [ret attrs] 837 <ResultType> @<FunctionName> ([argument list]) 838 [(unnamed_addr|local_unnamed_addr)] [AddrSpace] [fn Attrs] 839 [section "name"] [comdat [($name)]] [align N] [gc] [prefix Constant] 840 [prologue Constant] [personality Constant] (!name !N)* { ... } 841 842The argument list is a comma separated sequence of arguments where each 843argument is of the following form: 844 845Syntax:: 846 847 <type> [parameter Attrs] [name] 848 849 850.. _langref_aliases: 851 852Aliases 853------- 854 855Aliases, unlike function or variables, don't create any new data. They 856are just a new symbol and metadata for an existing position. 857 858Aliases have a name and an aliasee that is either a global value or a 859constant expression. 860 861Aliases may have an optional :ref:`linkage type <linkage>`, an optional 862:ref:`runtime preemption specifier <runtime_preemption_model>`, an optional 863:ref:`visibility style <visibility>`, an optional :ref:`DLL storage class 864<dllstorageclass>` and an optional :ref:`tls model <tls_model>`. 865 866Syntax:: 867 868 @<Name> = [Linkage] [PreemptionSpecifier] [Visibility] [DLLStorageClass] [ThreadLocal] [(unnamed_addr|local_unnamed_addr)] alias <AliaseeTy>, <AliaseeTy>* @<Aliasee> 869 870The linkage must be one of ``private``, ``internal``, ``linkonce``, ``weak``, 871``linkonce_odr``, ``weak_odr``, ``external``. Note that some system linkers 872might not correctly handle dropping a weak symbol that is aliased. 873 874Aliases that are not ``unnamed_addr`` are guaranteed to have the same address as 875the aliasee expression. ``unnamed_addr`` ones are only guaranteed to point 876to the same content. 877 878If the ``local_unnamed_addr`` attribute is given, the address is known to 879not be significant within the module. 880 881Since aliases are only a second name, some restrictions apply, of which 882some can only be checked when producing an object file: 883 884* The expression defining the aliasee must be computable at assembly 885 time. Since it is just a name, no relocations can be used. 886 887* No alias in the expression can be weak as the possibility of the 888 intermediate alias being overridden cannot be represented in an 889 object file. 890 891* No global value in the expression can be a declaration, since that 892 would require a relocation, which is not possible. 893 894.. _langref_ifunc: 895 896IFuncs 897------- 898 899IFuncs, like as aliases, don't create any new data or func. They are just a new 900symbol that dynamic linker resolves at runtime by calling a resolver function. 901 902IFuncs have a name and a resolver that is a function called by dynamic linker 903that returns address of another function associated with the name. 904 905IFunc may have an optional :ref:`linkage type <linkage>` and an optional 906:ref:`visibility style <visibility>`. 907 908Syntax:: 909 910 @<Name> = [Linkage] [Visibility] ifunc <IFuncTy>, <ResolverTy>* @<Resolver> 911 912 913.. _langref_comdats: 914 915Comdats 916------- 917 918Comdat IR provides access to object file COMDAT/section group functionality 919which represents interrelated sections. 920 921Comdats have a name which represents the COMDAT key and a selection kind to 922provide input on how the linker deduplicates comdats with the same key in two 923different object files. A comdat must be included or omitted as a unit. 924Discarding the whole comdat is allowed but discarding a subset is not. 925 926A global object may be a member of at most one comdat. Aliases are placed in the 927same COMDAT that their aliasee computes to, if any. 928 929Syntax:: 930 931 $<Name> = comdat SelectionKind 932 933For selection kinds other than ``nodeduplicate``, only one of the duplicate 934comdats may be retained by the linker and the members of the remaining comdats 935must be discarded. The following selection kinds are supported: 936 937``any`` 938 The linker may choose any COMDAT key, the choice is arbitrary. 939``exactmatch`` 940 The linker may choose any COMDAT key but the sections must contain the 941 same data. 942``largest`` 943 The linker will choose the section containing the largest COMDAT key. 944``nodeduplicate`` 945 No deduplication is performed. 946``samesize`` 947 The linker may choose any COMDAT key but the sections must contain the 948 same amount of data. 949 950- XCOFF and Mach-O don't support COMDATs. 951- COFF supports all selection kinds. Non-``nodeduplicate`` selection kinds need 952 a non-local linkage COMDAT symbol. 953- ELF supports ``any`` and ``nodeduplicate``. 954- WebAssembly only supports ``any``. 955 956Here is an example of a COFF COMDAT where a function will only be selected if 957the COMDAT key's section is the largest: 958 959.. code-block:: text 960 961 $foo = comdat largest 962 @foo = global i32 2, comdat($foo) 963 964 define void @bar() comdat($foo) { 965 ret void 966 } 967 968In a COFF object file, this will create a COMDAT section with selection kind 969``IMAGE_COMDAT_SELECT_LARGEST`` containing the contents of the ``@foo`` symbol 970and another COMDAT section with selection kind 971``IMAGE_COMDAT_SELECT_ASSOCIATIVE`` which is associated with the first COMDAT 972section and contains the contents of the ``@bar`` symbol. 973 974As a syntactic sugar the ``$name`` can be omitted if the name is the same as 975the global name: 976 977.. code-block:: llvm 978 979 $foo = comdat any 980 @foo = global i32 2, comdat 981 @bar = global i32 3, comdat($foo) 982 983There are some restrictions on the properties of the global object. 984It, or an alias to it, must have the same name as the COMDAT group when 985targeting COFF. 986The contents and size of this object may be used during link-time to determine 987which COMDAT groups get selected depending on the selection kind. 988Because the name of the object must match the name of the COMDAT group, the 989linkage of the global object must not be local; local symbols can get renamed 990if a collision occurs in the symbol table. 991 992The combined use of COMDATS and section attributes may yield surprising results. 993For example: 994 995.. code-block:: llvm 996 997 $foo = comdat any 998 $bar = comdat any 999 @g1 = global i32 42, section "sec", comdat($foo) 1000 @g2 = global i32 42, section "sec", comdat($bar) 1001 1002From the object file perspective, this requires the creation of two sections 1003with the same name. This is necessary because both globals belong to different 1004COMDAT groups and COMDATs, at the object file level, are represented by 1005sections. 1006 1007Note that certain IR constructs like global variables and functions may 1008create COMDATs in the object file in addition to any which are specified using 1009COMDAT IR. This arises when the code generator is configured to emit globals 1010in individual sections (e.g. when `-data-sections` or `-function-sections` 1011is supplied to `llc`). 1012 1013.. _namedmetadatastructure: 1014 1015Named Metadata 1016-------------- 1017 1018Named metadata is a collection of metadata. :ref:`Metadata 1019nodes <metadata>` (but not metadata strings) are the only valid 1020operands for a named metadata. 1021 1022#. Named metadata are represented as a string of characters with the 1023 metadata prefix. The rules for metadata names are the same as for 1024 identifiers, but quoted names are not allowed. ``"\xx"`` type escapes 1025 are still valid, which allows any character to be part of a name. 1026 1027Syntax:: 1028 1029 ; Some unnamed metadata nodes, which are referenced by the named metadata. 1030 !0 = !{!"zero"} 1031 !1 = !{!"one"} 1032 !2 = !{!"two"} 1033 ; A named metadata. 1034 !name = !{!0, !1, !2} 1035 1036.. _paramattrs: 1037 1038Parameter Attributes 1039-------------------- 1040 1041The return type and each parameter of a function type may have a set of 1042*parameter attributes* associated with them. Parameter attributes are 1043used to communicate additional information about the result or 1044parameters of a function. Parameter attributes are considered to be part 1045of the function, not of the function type, so functions with different 1046parameter attributes can have the same function type. 1047 1048Parameter attributes are simple keywords that follow the type specified. 1049If multiple parameter attributes are needed, they are space separated. 1050For example: 1051 1052.. code-block:: llvm 1053 1054 declare i32 @printf(i8* noalias nocapture, ...) 1055 declare i32 @atoi(i8 zeroext) 1056 declare signext i8 @returns_signed_char() 1057 1058Note that any attributes for the function result (``nounwind``, 1059``readonly``) come immediately after the argument list. 1060 1061Currently, only the following parameter attributes are defined: 1062 1063``zeroext`` 1064 This indicates to the code generator that the parameter or return 1065 value should be zero-extended to the extent required by the target's 1066 ABI by the caller (for a parameter) or the callee (for a return value). 1067``signext`` 1068 This indicates to the code generator that the parameter or return 1069 value should be sign-extended to the extent required by the target's 1070 ABI (which is usually 32-bits) by the caller (for a parameter) or 1071 the callee (for a return value). 1072``inreg`` 1073 This indicates that this parameter or return value should be treated 1074 in a special target-dependent fashion while emitting code for 1075 a function call or return (usually, by putting it in a register as 1076 opposed to memory, though some targets use it to distinguish between 1077 two different kinds of registers). Use of this attribute is 1078 target-specific. 1079``byval(<ty>)`` 1080 This indicates that the pointer parameter should really be passed by 1081 value to the function. The attribute implies that a hidden copy of 1082 the pointee is made between the caller and the callee, so the callee 1083 is unable to modify the value in the caller. This attribute is only 1084 valid on LLVM pointer arguments. It is generally used to pass 1085 structs and arrays by value, but is also valid on pointers to 1086 scalars. The copy is considered to belong to the caller not the 1087 callee (for example, ``readonly`` functions should not write to 1088 ``byval`` parameters). This is not a valid attribute for return 1089 values. 1090 1091 The byval type argument indicates the in-memory value type, and 1092 must be the same as the pointee type of the argument. 1093 1094 The byval attribute also supports specifying an alignment with the 1095 align attribute. It indicates the alignment of the stack slot to 1096 form and the known alignment of the pointer specified to the call 1097 site. If the alignment is not specified, then the code generator 1098 makes a target-specific assumption. 1099 1100.. _attr_byref: 1101 1102``byref(<ty>)`` 1103 1104 The ``byref`` argument attribute allows specifying the pointee 1105 memory type of an argument. This is similar to ``byval``, but does 1106 not imply a copy is made anywhere, or that the argument is passed 1107 on the stack. This implies the pointer is dereferenceable up to 1108 the storage size of the type. 1109 1110 It is not generally permissible to introduce a write to an 1111 ``byref`` pointer. The pointer may have any address space and may 1112 be read only. 1113 1114 This is not a valid attribute for return values. 1115 1116 The alignment for an ``byref`` parameter can be explicitly 1117 specified by combining it with the ``align`` attribute, similar to 1118 ``byval``. If the alignment is not specified, then the code generator 1119 makes a target-specific assumption. 1120 1121 This is intended for representing ABI constraints, and is not 1122 intended to be inferred for optimization use. 1123 1124.. _attr_preallocated: 1125 1126``preallocated(<ty>)`` 1127 This indicates that the pointer parameter should really be passed by 1128 value to the function, and that the pointer parameter's pointee has 1129 already been initialized before the call instruction. This attribute 1130 is only valid on LLVM pointer arguments. The argument must be the value 1131 returned by the appropriate 1132 :ref:`llvm.call.preallocated.arg<int_call_preallocated_arg>` on non 1133 ``musttail`` calls, or the corresponding caller parameter in ``musttail`` 1134 calls, although it is ignored during codegen. 1135 1136 A non ``musttail`` function call with a ``preallocated`` attribute in 1137 any parameter must have a ``"preallocated"`` operand bundle. A ``musttail`` 1138 function call cannot have a ``"preallocated"`` operand bundle. 1139 1140 The preallocated attribute requires a type argument, which must be 1141 the same as the pointee type of the argument. 1142 1143 The preallocated attribute also supports specifying an alignment with the 1144 align attribute. It indicates the alignment of the stack slot to 1145 form and the known alignment of the pointer specified to the call 1146 site. If the alignment is not specified, then the code generator 1147 makes a target-specific assumption. 1148 1149.. _attr_inalloca: 1150 1151``inalloca(<ty>)`` 1152 1153 The ``inalloca`` argument attribute allows the caller to take the 1154 address of outgoing stack arguments. An ``inalloca`` argument must 1155 be a pointer to stack memory produced by an ``alloca`` instruction. 1156 The alloca, or argument allocation, must also be tagged with the 1157 inalloca keyword. Only the last argument may have the ``inalloca`` 1158 attribute, and that argument is guaranteed to be passed in memory. 1159 1160 An argument allocation may be used by a call at most once because 1161 the call may deallocate it. The ``inalloca`` attribute cannot be 1162 used in conjunction with other attributes that affect argument 1163 storage, like ``inreg``, ``nest``, ``sret``, or ``byval``. The 1164 ``inalloca`` attribute also disables LLVM's implicit lowering of 1165 large aggregate return values, which means that frontend authors 1166 must lower them with ``sret`` pointers. 1167 1168 When the call site is reached, the argument allocation must have 1169 been the most recent stack allocation that is still live, or the 1170 behavior is undefined. It is possible to allocate additional stack 1171 space after an argument allocation and before its call site, but it 1172 must be cleared off with :ref:`llvm.stackrestore 1173 <int_stackrestore>`. 1174 1175 The inalloca attribute requires a type argument, which must be the 1176 same as the pointee type of the argument. 1177 1178 See :doc:`InAlloca` for more information on how to use this 1179 attribute. 1180 1181``sret(<ty>)`` 1182 This indicates that the pointer parameter specifies the address of a 1183 structure that is the return value of the function in the source 1184 program. This pointer must be guaranteed by the caller to be valid: 1185 loads and stores to the structure may be assumed by the callee not 1186 to trap and to be properly aligned. This is not a valid attribute 1187 for return values. 1188 1189 The sret type argument specifies the in memory type, which must be 1190 the same as the pointee type of the argument. 1191 1192.. _attr_elementtype: 1193 1194``elementtype(<ty>)`` 1195 1196 The ``elementtype`` argument attribute can be used to specify a pointer 1197 element type in a way that is compatible with `opaque pointers 1198 <OpaquePointers.html>`. 1199 1200 The ``elementtype`` attribute by itself does not carry any specific 1201 semantics. However, certain intrinsics may require this attribute to be 1202 present and assign it particular semantics. This will be documented on 1203 individual intrinsics. 1204 1205 The attribute may only be applied to pointer typed arguments of intrinsic 1206 calls. It cannot be applied to non-intrinsic calls, and cannot be applied 1207 to parameters on function declarations. For non-opaque pointers, the type 1208 passed to ``elementtype`` must match the pointer element type. 1209 1210.. _attr_align: 1211 1212``align <n>`` or ``align(<n>)`` 1213 This indicates that the pointer value has the specified alignment. 1214 If the pointer value does not have the specified alignment, 1215 :ref:`poison value <poisonvalues>` is returned or passed instead. The 1216 ``align`` attribute should be combined with the ``noundef`` attribute to 1217 ensure a pointer is aligned, or otherwise the behavior is undefined. Note 1218 that ``align 1`` has no effect on non-byval, non-preallocated arguments. 1219 1220 Note that this attribute has additional semantics when combined with the 1221 ``byval`` or ``preallocated`` attribute, which are documented there. 1222 1223.. _noalias: 1224 1225``noalias`` 1226 This indicates that memory locations accessed via pointer values 1227 :ref:`based <pointeraliasing>` on the argument or return value are not also 1228 accessed, during the execution of the function, via pointer values not 1229 *based* on the argument or return value. This guarantee only holds for 1230 memory locations that are *modified*, by any means, during the execution of 1231 the function. The attribute on a return value also has additional semantics 1232 described below. The caller shares the responsibility with the callee for 1233 ensuring that these requirements are met. For further details, please see 1234 the discussion of the NoAlias response in :ref:`alias analysis <Must, May, 1235 or No>`. 1236 1237 Note that this definition of ``noalias`` is intentionally similar 1238 to the definition of ``restrict`` in C99 for function arguments. 1239 1240 For function return values, C99's ``restrict`` is not meaningful, 1241 while LLVM's ``noalias`` is. Furthermore, the semantics of the ``noalias`` 1242 attribute on return values are stronger than the semantics of the attribute 1243 when used on function arguments. On function return values, the ``noalias`` 1244 attribute indicates that the function acts like a system memory allocation 1245 function, returning a pointer to allocated storage disjoint from the 1246 storage for any other object accessible to the caller. 1247 1248.. _nocapture: 1249 1250``nocapture`` 1251 This indicates that the callee does not :ref:`capture <pointercapture>` the 1252 pointer. This is not a valid attribute for return values. 1253 This attribute applies only to the particular copy of the pointer passed in 1254 this argument. A caller could pass two copies of the same pointer with one 1255 being annotated nocapture and the other not, and the callee could validly 1256 capture through the non annotated parameter. 1257 1258.. code-block:: llvm 1259 1260 define void @f(i8* nocapture %a, i8* %b) { 1261 ; (capture %b) 1262 } 1263 1264 call void @f(i8* @glb, i8* @glb) ; well-defined 1265 1266``nofree`` 1267 This indicates that callee does not free the pointer argument. This is not 1268 a valid attribute for return values. 1269 1270.. _nest: 1271 1272``nest`` 1273 This indicates that the pointer parameter can be excised using the 1274 :ref:`trampoline intrinsics <int_trampoline>`. This is not a valid 1275 attribute for return values and can only be applied to one parameter. 1276 1277``returned`` 1278 This indicates that the function always returns the argument as its return 1279 value. This is a hint to the optimizer and code generator used when 1280 generating the caller, allowing value propagation, tail call optimization, 1281 and omission of register saves and restores in some cases; it is not 1282 checked or enforced when generating the callee. The parameter and the 1283 function return type must be valid operands for the 1284 :ref:`bitcast instruction <i_bitcast>`. This is not a valid attribute for 1285 return values and can only be applied to one parameter. 1286 1287``nonnull`` 1288 This indicates that the parameter or return pointer is not null. This 1289 attribute may only be applied to pointer typed parameters. This is not 1290 checked or enforced by LLVM; if the parameter or return pointer is null, 1291 :ref:`poison value <poisonvalues>` is returned or passed instead. 1292 The ``nonnull`` attribute should be combined with the ``noundef`` attribute 1293 to ensure a pointer is not null or otherwise the behavior is undefined. 1294 1295``dereferenceable(<n>)`` 1296 This indicates that the parameter or return pointer is dereferenceable. This 1297 attribute may only be applied to pointer typed parameters. A pointer that 1298 is dereferenceable can be loaded from speculatively without a risk of 1299 trapping. The number of bytes known to be dereferenceable must be provided 1300 in parentheses. It is legal for the number of bytes to be less than the 1301 size of the pointee type. The ``nonnull`` attribute does not imply 1302 dereferenceability (consider a pointer to one element past the end of an 1303 array), however ``dereferenceable(<n>)`` does imply ``nonnull`` in 1304 ``addrspace(0)`` (which is the default address space), except if the 1305 ``null_pointer_is_valid`` function attribute is present. 1306 ``n`` should be a positive number. The pointer should be well defined, 1307 otherwise it is undefined behavior. This means ``dereferenceable(<n>)`` 1308 implies ``noundef``. 1309 1310``dereferenceable_or_null(<n>)`` 1311 This indicates that the parameter or return value isn't both 1312 non-null and non-dereferenceable (up to ``<n>`` bytes) at the same 1313 time. All non-null pointers tagged with 1314 ``dereferenceable_or_null(<n>)`` are ``dereferenceable(<n>)``. 1315 For address space 0 ``dereferenceable_or_null(<n>)`` implies that 1316 a pointer is exactly one of ``dereferenceable(<n>)`` or ``null``, 1317 and in other address spaces ``dereferenceable_or_null(<n>)`` 1318 implies that a pointer is at least one of ``dereferenceable(<n>)`` 1319 or ``null`` (i.e. it may be both ``null`` and 1320 ``dereferenceable(<n>)``). This attribute may only be applied to 1321 pointer typed parameters. 1322 1323``swiftself`` 1324 This indicates that the parameter is the self/context parameter. This is not 1325 a valid attribute for return values and can only be applied to one 1326 parameter. 1327 1328``swiftasync`` 1329 This indicates that the parameter is the asynchronous context parameter and 1330 triggers the creation of a target-specific extended frame record to store 1331 this pointer. This is not a valid attribute for return values and can only 1332 be applied to one parameter. 1333 1334``swifterror`` 1335 This attribute is motivated to model and optimize Swift error handling. It 1336 can be applied to a parameter with pointer to pointer type or a 1337 pointer-sized alloca. At the call site, the actual argument that corresponds 1338 to a ``swifterror`` parameter has to come from a ``swifterror`` alloca or 1339 the ``swifterror`` parameter of the caller. A ``swifterror`` value (either 1340 the parameter or the alloca) can only be loaded and stored from, or used as 1341 a ``swifterror`` argument. This is not a valid attribute for return values 1342 and can only be applied to one parameter. 1343 1344 These constraints allow the calling convention to optimize access to 1345 ``swifterror`` variables by associating them with a specific register at 1346 call boundaries rather than placing them in memory. Since this does change 1347 the calling convention, a function which uses the ``swifterror`` attribute 1348 on a parameter is not ABI-compatible with one which does not. 1349 1350 These constraints also allow LLVM to assume that a ``swifterror`` argument 1351 does not alias any other memory visible within a function and that a 1352 ``swifterror`` alloca passed as an argument does not escape. 1353 1354``immarg`` 1355 This indicates the parameter is required to be an immediate 1356 value. This must be a trivial immediate integer or floating-point 1357 constant. Undef or constant expressions are not valid. This is 1358 only valid on intrinsic declarations and cannot be applied to a 1359 call site or arbitrary function. 1360 1361``noundef`` 1362 This attribute applies to parameters and return values. If the value 1363 representation contains any undefined or poison bits, the behavior is 1364 undefined. Note that this does not refer to padding introduced by the 1365 type's storage representation. 1366 1367``alignstack(<n>)`` 1368 This indicates the alignment that should be considered by the backend when 1369 assigning this parameter to a stack slot during calling convention 1370 lowering. The enforcement of the specified alignment is target-dependent, 1371 as target-specific calling convention rules may override this value. This 1372 attribute serves the purpose of carrying language specific alignment 1373 information that is not mapped to base types in the backend (for example, 1374 over-alignment specification through language attributes). 1375 1376.. _gc: 1377 1378Garbage Collector Strategy Names 1379-------------------------------- 1380 1381Each function may specify a garbage collector strategy name, which is simply a 1382string: 1383 1384.. code-block:: llvm 1385 1386 define void @f() gc "name" { ... } 1387 1388The supported values of *name* includes those :ref:`built in to LLVM 1389<builtin-gc-strategies>` and any provided by loaded plugins. Specifying a GC 1390strategy will cause the compiler to alter its output in order to support the 1391named garbage collection algorithm. Note that LLVM itself does not contain a 1392garbage collector, this functionality is restricted to generating machine code 1393which can interoperate with a collector provided externally. 1394 1395.. _prefixdata: 1396 1397Prefix Data 1398----------- 1399 1400Prefix data is data associated with a function which the code 1401generator will emit immediately before the function's entrypoint. 1402The purpose of this feature is to allow frontends to associate 1403language-specific runtime metadata with specific functions and make it 1404available through the function pointer while still allowing the 1405function pointer to be called. 1406 1407To access the data for a given function, a program may bitcast the 1408function pointer to a pointer to the constant's type and dereference 1409index -1. This implies that the IR symbol points just past the end of 1410the prefix data. For instance, take the example of a function annotated 1411with a single ``i32``, 1412 1413.. code-block:: llvm 1414 1415 define void @f() prefix i32 123 { ... } 1416 1417The prefix data can be referenced as, 1418 1419.. code-block:: llvm 1420 1421 %0 = bitcast void* () @f to i32* 1422 %a = getelementptr inbounds i32, i32* %0, i32 -1 1423 %b = load i32, i32* %a 1424 1425Prefix data is laid out as if it were an initializer for a global variable 1426of the prefix data's type. The function will be placed such that the 1427beginning of the prefix data is aligned. This means that if the size 1428of the prefix data is not a multiple of the alignment size, the 1429function's entrypoint will not be aligned. If alignment of the 1430function's entrypoint is desired, padding must be added to the prefix 1431data. 1432 1433A function may have prefix data but no body. This has similar semantics 1434to the ``available_externally`` linkage in that the data may be used by the 1435optimizers but will not be emitted in the object file. 1436 1437.. _prologuedata: 1438 1439Prologue Data 1440------------- 1441 1442The ``prologue`` attribute allows arbitrary code (encoded as bytes) to 1443be inserted prior to the function body. This can be used for enabling 1444function hot-patching and instrumentation. 1445 1446To maintain the semantics of ordinary function calls, the prologue data must 1447have a particular format. Specifically, it must begin with a sequence of 1448bytes which decode to a sequence of machine instructions, valid for the 1449module's target, which transfer control to the point immediately succeeding 1450the prologue data, without performing any other visible action. This allows 1451the inliner and other passes to reason about the semantics of the function 1452definition without needing to reason about the prologue data. Obviously this 1453makes the format of the prologue data highly target dependent. 1454 1455A trivial example of valid prologue data for the x86 architecture is ``i8 144``, 1456which encodes the ``nop`` instruction: 1457 1458.. code-block:: text 1459 1460 define void @f() prologue i8 144 { ... } 1461 1462Generally prologue data can be formed by encoding a relative branch instruction 1463which skips the metadata, as in this example of valid prologue data for the 1464x86_64 architecture, where the first two bytes encode ``jmp .+10``: 1465 1466.. code-block:: text 1467 1468 %0 = type <{ i8, i8, i8* }> 1469 1470 define void @f() prologue %0 <{ i8 235, i8 8, i8* @md}> { ... } 1471 1472A function may have prologue data but no body. This has similar semantics 1473to the ``available_externally`` linkage in that the data may be used by the 1474optimizers but will not be emitted in the object file. 1475 1476.. _personalityfn: 1477 1478Personality Function 1479-------------------- 1480 1481The ``personality`` attribute permits functions to specify what function 1482to use for exception handling. 1483 1484.. _attrgrp: 1485 1486Attribute Groups 1487---------------- 1488 1489Attribute groups are groups of attributes that are referenced by objects within 1490the IR. They are important for keeping ``.ll`` files readable, because a lot of 1491functions will use the same set of attributes. In the degenerative case of a 1492``.ll`` file that corresponds to a single ``.c`` file, the single attribute 1493group will capture the important command line flags used to build that file. 1494 1495An attribute group is a module-level object. To use an attribute group, an 1496object references the attribute group's ID (e.g. ``#37``). An object may refer 1497to more than one attribute group. In that situation, the attributes from the 1498different groups are merged. 1499 1500Here is an example of attribute groups for a function that should always be 1501inlined, has a stack alignment of 4, and which shouldn't use SSE instructions: 1502 1503.. code-block:: llvm 1504 1505 ; Target-independent attributes: 1506 attributes #0 = { alwaysinline alignstack=4 } 1507 1508 ; Target-dependent attributes: 1509 attributes #1 = { "no-sse" } 1510 1511 ; Function @f has attributes: alwaysinline, alignstack=4, and "no-sse". 1512 define void @f() #0 #1 { ... } 1513 1514.. _fnattrs: 1515 1516Function Attributes 1517------------------- 1518 1519Function attributes are set to communicate additional information about 1520a function. Function attributes are considered to be part of the 1521function, not of the function type, so functions with different function 1522attributes can have the same function type. 1523 1524Function attributes are simple keywords that follow the type specified. 1525If multiple attributes are needed, they are space separated. For 1526example: 1527 1528.. code-block:: llvm 1529 1530 define void @f() noinline { ... } 1531 define void @f() alwaysinline { ... } 1532 define void @f() alwaysinline optsize { ... } 1533 define void @f() optsize { ... } 1534 1535``alignstack(<n>)`` 1536 This attribute indicates that, when emitting the prologue and 1537 epilogue, the backend should forcibly align the stack pointer. 1538 Specify the desired alignment, which must be a power of two, in 1539 parentheses. 1540``allocsize(<EltSizeParam>[, <NumEltsParam>])`` 1541 This attribute indicates that the annotated function will always return at 1542 least a given number of bytes (or null). Its arguments are zero-indexed 1543 parameter numbers; if one argument is provided, then it's assumed that at 1544 least ``CallSite.Args[EltSizeParam]`` bytes will be available at the 1545 returned pointer. If two are provided, then it's assumed that 1546 ``CallSite.Args[EltSizeParam] * CallSite.Args[NumEltsParam]`` bytes are 1547 available. The referenced parameters must be integer types. No assumptions 1548 are made about the contents of the returned block of memory. 1549``alwaysinline`` 1550 This attribute indicates that the inliner should attempt to inline 1551 this function into callers whenever possible, ignoring any active 1552 inlining size threshold for this caller. 1553``builtin`` 1554 This indicates that the callee function at a call site should be 1555 recognized as a built-in function, even though the function's declaration 1556 uses the ``nobuiltin`` attribute. This is only valid at call sites for 1557 direct calls to functions that are declared with the ``nobuiltin`` 1558 attribute. 1559``cold`` 1560 This attribute indicates that this function is rarely called. When 1561 computing edge weights, basic blocks post-dominated by a cold 1562 function call are also considered to be cold; and, thus, given low 1563 weight. 1564``convergent`` 1565 In some parallel execution models, there exist operations that cannot be 1566 made control-dependent on any additional values. We call such operations 1567 ``convergent``, and mark them with this attribute. 1568 1569 The ``convergent`` attribute may appear on functions or call/invoke 1570 instructions. When it appears on a function, it indicates that calls to 1571 this function should not be made control-dependent on additional values. 1572 For example, the intrinsic ``llvm.nvvm.barrier0`` is ``convergent``, so 1573 calls to this intrinsic cannot be made control-dependent on additional 1574 values. 1575 1576 When it appears on a call/invoke, the ``convergent`` attribute indicates 1577 that we should treat the call as though we're calling a convergent 1578 function. This is particularly useful on indirect calls; without this we 1579 may treat such calls as though the target is non-convergent. 1580 1581 The optimizer may remove the ``convergent`` attribute on functions when it 1582 can prove that the function does not execute any convergent operations. 1583 Similarly, the optimizer may remove ``convergent`` on calls/invokes when it 1584 can prove that the call/invoke cannot call a convergent function. 1585``"frame-pointer"`` 1586 This attribute tells the code generator whether the function 1587 should keep the frame pointer. The code generator may emit the frame pointer 1588 even if this attribute says the frame pointer can be eliminated. 1589 The allowed string values are: 1590 1591 * ``"none"`` (default) - the frame pointer can be eliminated. 1592 * ``"non-leaf"`` - the frame pointer should be kept if the function calls 1593 other functions. 1594 * ``"all"`` - the frame pointer should be kept. 1595``hot`` 1596 This attribute indicates that this function is a hot spot of the program 1597 execution. The function will be optimized more aggressively and will be 1598 placed into special subsection of the text section to improving locality. 1599 1600 When profile feedback is enabled, this attribute has the precedence over 1601 the profile information. By marking a function ``hot``, users can work 1602 around the cases where the training input does not have good coverage 1603 on all the hot functions. 1604``inaccessiblememonly`` 1605 This attribute indicates that the function may only access memory that 1606 is not accessible by the module being compiled. This is a weaker form 1607 of ``readnone``. If the function reads or writes other memory, the 1608 behavior is undefined. 1609``inaccessiblemem_or_argmemonly`` 1610 This attribute indicates that the function may only access memory that is 1611 either not accessible by the module being compiled, or is pointed to 1612 by its pointer arguments. This is a weaker form of ``argmemonly``. If the 1613 function reads or writes other memory, the behavior is undefined. 1614``inlinehint`` 1615 This attribute indicates that the source code contained a hint that 1616 inlining this function is desirable (such as the "inline" keyword in 1617 C/C++). It is just a hint; it imposes no requirements on the 1618 inliner. 1619``jumptable`` 1620 This attribute indicates that the function should be added to a 1621 jump-instruction table at code-generation time, and that all address-taken 1622 references to this function should be replaced with a reference to the 1623 appropriate jump-instruction-table function pointer. Note that this creates 1624 a new pointer for the original function, which means that code that depends 1625 on function-pointer identity can break. So, any function annotated with 1626 ``jumptable`` must also be ``unnamed_addr``. 1627``minsize`` 1628 This attribute suggests that optimization passes and code generator 1629 passes make choices that keep the code size of this function as small 1630 as possible and perform optimizations that may sacrifice runtime 1631 performance in order to minimize the size of the generated code. 1632``naked`` 1633 This attribute disables prologue / epilogue emission for the 1634 function. This can have very system-specific consequences. 1635``"no-inline-line-tables"`` 1636 When this attribute is set to true, the inliner discards source locations 1637 when inlining code and instead uses the source location of the call site. 1638 Breakpoints set on code that was inlined into the current function will 1639 not fire during the execution of the inlined call sites. If the debugger 1640 stops inside an inlined call site, it will appear to be stopped at the 1641 outermost inlined call site. 1642``no-jump-tables`` 1643 When this attribute is set to true, the jump tables and lookup tables that 1644 can be generated from a switch case lowering are disabled. 1645``nobuiltin`` 1646 This indicates that the callee function at a call site is not recognized as 1647 a built-in function. LLVM will retain the original call and not replace it 1648 with equivalent code based on the semantics of the built-in function, unless 1649 the call site uses the ``builtin`` attribute. This is valid at call sites 1650 and on function declarations and definitions. 1651``noduplicate`` 1652 This attribute indicates that calls to the function cannot be 1653 duplicated. A call to a ``noduplicate`` function may be moved 1654 within its parent function, but may not be duplicated within 1655 its parent function. 1656 1657 A function containing a ``noduplicate`` call may still 1658 be an inlining candidate, provided that the call is not 1659 duplicated by inlining. That implies that the function has 1660 internal linkage and only has one call site, so the original 1661 call is dead after inlining. 1662``nofree`` 1663 This function attribute indicates that the function does not, directly or 1664 transitively, call a memory-deallocation function (``free``, for example) 1665 on a memory allocation which existed before the call. 1666 1667 As a result, uncaptured pointers that are known to be dereferenceable 1668 prior to a call to a function with the ``nofree`` attribute are still 1669 known to be dereferenceable after the call. The capturing condition is 1670 necessary in environments where the function might communicate the 1671 pointer to another thread which then deallocates the memory. Alternatively, 1672 ``nosync`` would ensure such communication cannot happen and even captured 1673 pointers cannot be freed by the function. 1674 1675 A ``nofree`` function is explicitly allowed to free memory which it 1676 allocated or (if not ``nosync``) arrange for another thread to free 1677 memory on it's behalf. As a result, perhaps surprisingly, a ``nofree`` 1678 function can return a pointer to a previously deallocated memory object. 1679``noimplicitfloat`` 1680 Disallows implicit floating-point code. This inhibits optimizations that 1681 use floating-point code and floating-point/SIMD/vector registers for 1682 operations that are not nominally floating-point. LLVM instructions that 1683 perform floating-point operations or require access to floating-point 1684 registers may still cause floating-point code to be generated. 1685``noinline`` 1686 This attribute indicates that the inliner should never inline this 1687 function in any situation. This attribute may not be used together 1688 with the ``alwaysinline`` attribute. 1689``nomerge`` 1690 This attribute indicates that calls to this function should never be merged 1691 during optimization. For example, it will prevent tail merging otherwise 1692 identical code sequences that raise an exception or terminate the program. 1693 Tail merging normally reduces the precision of source location information, 1694 making stack traces less useful for debugging. This attribute gives the 1695 user control over the tradeoff between code size and debug information 1696 precision. 1697``nonlazybind`` 1698 This attribute suppresses lazy symbol binding for the function. This 1699 may make calls to the function faster, at the cost of extra program 1700 startup time if the function is not called during program startup. 1701``noprofile`` 1702 This function attribute prevents instrumentation based profiling, used for 1703 coverage or profile based optimization, from being added to a function, 1704 even when inlined. 1705``noredzone`` 1706 This attribute indicates that the code generator should not use a 1707 red zone, even if the target-specific ABI normally permits it. 1708``indirect-tls-seg-refs`` 1709 This attribute indicates that the code generator should not use 1710 direct TLS access through segment registers, even if the 1711 target-specific ABI normally permits it. 1712``noreturn`` 1713 This function attribute indicates that the function never returns 1714 normally, hence through a return instruction. This produces undefined 1715 behavior at runtime if the function ever does dynamically return. Annotated 1716 functions may still raise an exception, i.a., ``nounwind`` is not implied. 1717``norecurse`` 1718 This function attribute indicates that the function does not call itself 1719 either directly or indirectly down any possible call path. This produces 1720 undefined behavior at runtime if the function ever does recurse. 1721``willreturn`` 1722 This function attribute indicates that a call of this function will 1723 either exhibit undefined behavior or comes back and continues execution 1724 at a point in the existing call stack that includes the current invocation. 1725 Annotated functions may still raise an exception, i.a., ``nounwind`` is not implied. 1726 If an invocation of an annotated function does not return control back 1727 to a point in the call stack, the behavior is undefined. 1728``nosync`` 1729 This function attribute indicates that the function does not communicate 1730 (synchronize) with another thread through memory or other well-defined means. 1731 Synchronization is considered possible in the presence of `atomic` accesses 1732 that enforce an order, thus not "unordered" and "monotonic", `volatile` accesses, 1733 as well as `convergent` function calls. Note that through `convergent` function calls 1734 non-memory communication, e.g., cross-lane operations, are possible and are also 1735 considered synchronization. However `convergent` does not contradict `nosync`. 1736 If an annotated function does ever synchronize with another thread, 1737 the behavior is undefined. 1738``nounwind`` 1739 This function attribute indicates that the function never raises an 1740 exception. If the function does raise an exception, its runtime 1741 behavior is undefined. However, functions marked nounwind may still 1742 trap or generate asynchronous exceptions. Exception handling schemes 1743 that are recognized by LLVM to handle asynchronous exceptions, such 1744 as SEH, will still provide their implementation defined semantics. 1745``nosanitize_coverage`` 1746 This attribute indicates that SanitizerCoverage instrumentation is disabled 1747 for this function. 1748``null_pointer_is_valid`` 1749 If ``null_pointer_is_valid`` is set, then the ``null`` address 1750 in address-space 0 is considered to be a valid address for memory loads and 1751 stores. Any analysis or optimization should not treat dereferencing a 1752 pointer to ``null`` as undefined behavior in this function. 1753 Note: Comparing address of a global variable to ``null`` may still 1754 evaluate to false because of a limitation in querying this attribute inside 1755 constant expressions. 1756``optforfuzzing`` 1757 This attribute indicates that this function should be optimized 1758 for maximum fuzzing signal. 1759``optnone`` 1760 This function attribute indicates that most optimization passes will skip 1761 this function, with the exception of interprocedural optimization passes. 1762 Code generation defaults to the "fast" instruction selector. 1763 This attribute cannot be used together with the ``alwaysinline`` 1764 attribute; this attribute is also incompatible 1765 with the ``minsize`` attribute and the ``optsize`` attribute. 1766 1767 This attribute requires the ``noinline`` attribute to be specified on 1768 the function as well, so the function is never inlined into any caller. 1769 Only functions with the ``alwaysinline`` attribute are valid 1770 candidates for inlining into the body of this function. 1771``optsize`` 1772 This attribute suggests that optimization passes and code generator 1773 passes make choices that keep the code size of this function low, 1774 and otherwise do optimizations specifically to reduce code size as 1775 long as they do not significantly impact runtime performance. 1776``"patchable-function"`` 1777 This attribute tells the code generator that the code 1778 generated for this function needs to follow certain conventions that 1779 make it possible for a runtime function to patch over it later. 1780 The exact effect of this attribute depends on its string value, 1781 for which there currently is one legal possibility: 1782 1783 * ``"prologue-short-redirect"`` - This style of patchable 1784 function is intended to support patching a function prologue to 1785 redirect control away from the function in a thread safe 1786 manner. It guarantees that the first instruction of the 1787 function will be large enough to accommodate a short jump 1788 instruction, and will be sufficiently aligned to allow being 1789 fully changed via an atomic compare-and-swap instruction. 1790 While the first requirement can be satisfied by inserting large 1791 enough NOP, LLVM can and will try to re-purpose an existing 1792 instruction (i.e. one that would have to be emitted anyway) as 1793 the patchable instruction larger than a short jump. 1794 1795 ``"prologue-short-redirect"`` is currently only supported on 1796 x86-64. 1797 1798 This attribute by itself does not imply restrictions on 1799 inter-procedural optimizations. All of the semantic effects the 1800 patching may have to be separately conveyed via the linkage type. 1801``"probe-stack"`` 1802 This attribute indicates that the function will trigger a guard region 1803 in the end of the stack. It ensures that accesses to the stack must be 1804 no further apart than the size of the guard region to a previous 1805 access of the stack. It takes one required string value, the name of 1806 the stack probing function that will be called. 1807 1808 If a function that has a ``"probe-stack"`` attribute is inlined into 1809 a function with another ``"probe-stack"`` attribute, the resulting 1810 function has the ``"probe-stack"`` attribute of the caller. If a 1811 function that has a ``"probe-stack"`` attribute is inlined into a 1812 function that has no ``"probe-stack"`` attribute at all, the resulting 1813 function has the ``"probe-stack"`` attribute of the callee. 1814``readnone`` 1815 On a function, this attribute indicates that the function computes its 1816 result (or decides to unwind an exception) based strictly on its arguments, 1817 without dereferencing any pointer arguments or otherwise accessing 1818 any mutable state (e.g. memory, control registers, etc) visible to 1819 caller functions. It does not write through any pointer arguments 1820 (including ``byval`` arguments) and never changes any state visible 1821 to callers. This means while it cannot unwind exceptions by calling 1822 the ``C++`` exception throwing methods (since they write to memory), there may 1823 be non-``C++`` mechanisms that throw exceptions without writing to LLVM 1824 visible memory. 1825 1826 On an argument, this attribute indicates that the function does not 1827 dereference that pointer argument, even though it may read or write the 1828 memory that the pointer points to if accessed through other pointers. 1829 1830 If a readnone function reads or writes memory visible to the program, or 1831 has other side-effects, the behavior is undefined. If a function reads from 1832 or writes to a readnone pointer argument, the behavior is undefined. 1833``readonly`` 1834 On a function, this attribute indicates that the function does not write 1835 through any pointer arguments (including ``byval`` arguments) or otherwise 1836 modify any state (e.g. memory, control registers, etc) visible to 1837 caller functions. It may dereference pointer arguments and read 1838 state that may be set in the caller. A readonly function always 1839 returns the same value (or unwinds an exception identically) when 1840 called with the same set of arguments and global state. This means while it 1841 cannot unwind exceptions by calling the ``C++`` exception throwing methods 1842 (since they write to memory), there may be non-``C++`` mechanisms that throw 1843 exceptions without writing to LLVM visible memory. 1844 1845 On an argument, this attribute indicates that the function does not write 1846 through this pointer argument, even though it may write to the memory that 1847 the pointer points to. 1848 1849 If a readonly function writes memory visible to the program, or 1850 has other side-effects, the behavior is undefined. If a function writes to 1851 a readonly pointer argument, the behavior is undefined. 1852``"stack-probe-size"`` 1853 This attribute controls the behavior of stack probes: either 1854 the ``"probe-stack"`` attribute, or ABI-required stack probes, if any. 1855 It defines the size of the guard region. It ensures that if the function 1856 may use more stack space than the size of the guard region, stack probing 1857 sequence will be emitted. It takes one required integer value, which 1858 is 4096 by default. 1859 1860 If a function that has a ``"stack-probe-size"`` attribute is inlined into 1861 a function with another ``"stack-probe-size"`` attribute, the resulting 1862 function has the ``"stack-probe-size"`` attribute that has the lower 1863 numeric value. If a function that has a ``"stack-probe-size"`` attribute is 1864 inlined into a function that has no ``"stack-probe-size"`` attribute 1865 at all, the resulting function has the ``"stack-probe-size"`` attribute 1866 of the callee. 1867``"no-stack-arg-probe"`` 1868 This attribute disables ABI-required stack probes, if any. 1869``writeonly`` 1870 On a function, this attribute indicates that the function may write to but 1871 does not read from memory. 1872 1873 On an argument, this attribute indicates that the function may write to but 1874 does not read through this pointer argument (even though it may read from 1875 the memory that the pointer points to). 1876 1877 If a writeonly function reads memory visible to the program, or 1878 has other side-effects, the behavior is undefined. If a function reads 1879 from a writeonly pointer argument, the behavior is undefined. 1880``argmemonly`` 1881 This attribute indicates that the only memory accesses inside function are 1882 loads and stores from objects pointed to by its pointer-typed arguments, 1883 with arbitrary offsets. Or in other words, all memory operations in the 1884 function can refer to memory only using pointers based on its function 1885 arguments. 1886 1887 Note that ``argmemonly`` can be used together with ``readonly`` attribute 1888 in order to specify that function reads only from its arguments. 1889 1890 If an argmemonly function reads or writes memory other than the pointer 1891 arguments, or has other side-effects, the behavior is undefined. 1892``returns_twice`` 1893 This attribute indicates that this function can return twice. The C 1894 ``setjmp`` is an example of such a function. The compiler disables 1895 some optimizations (like tail calls) in the caller of these 1896 functions. 1897``safestack`` 1898 This attribute indicates that 1899 `SafeStack <https://clang.llvm.org/docs/SafeStack.html>`_ 1900 protection is enabled for this function. 1901 1902 If a function that has a ``safestack`` attribute is inlined into a 1903 function that doesn't have a ``safestack`` attribute or which has an 1904 ``ssp``, ``sspstrong`` or ``sspreq`` attribute, then the resulting 1905 function will have a ``safestack`` attribute. 1906``sanitize_address`` 1907 This attribute indicates that AddressSanitizer checks 1908 (dynamic address safety analysis) are enabled for this function. 1909``sanitize_memory`` 1910 This attribute indicates that MemorySanitizer checks (dynamic detection 1911 of accesses to uninitialized memory) are enabled for this function. 1912``sanitize_thread`` 1913 This attribute indicates that ThreadSanitizer checks 1914 (dynamic thread safety analysis) are enabled for this function. 1915``sanitize_hwaddress`` 1916 This attribute indicates that HWAddressSanitizer checks 1917 (dynamic address safety analysis based on tagged pointers) are enabled for 1918 this function. 1919``sanitize_memtag`` 1920 This attribute indicates that MemTagSanitizer checks 1921 (dynamic address safety analysis based on Armv8 MTE) are enabled for 1922 this function. 1923``speculative_load_hardening`` 1924 This attribute indicates that 1925 `Speculative Load Hardening <https://llvm.org/docs/SpeculativeLoadHardening.html>`_ 1926 should be enabled for the function body. 1927 1928 Speculative Load Hardening is a best-effort mitigation against 1929 information leak attacks that make use of control flow 1930 miss-speculation - specifically miss-speculation of whether a branch 1931 is taken or not. Typically vulnerabilities enabling such attacks are 1932 classified as "Spectre variant #1". Notably, this does not attempt to 1933 mitigate against miss-speculation of branch target, classified as 1934 "Spectre variant #2" vulnerabilities. 1935 1936 When inlining, the attribute is sticky. Inlining a function that carries 1937 this attribute will cause the caller to gain the attribute. This is intended 1938 to provide a maximally conservative model where the code in a function 1939 annotated with this attribute will always (even after inlining) end up 1940 hardened. 1941``speculatable`` 1942 This function attribute indicates that the function does not have any 1943 effects besides calculating its result and does not have undefined behavior. 1944 Note that ``speculatable`` is not enough to conclude that along any 1945 particular execution path the number of calls to this function will not be 1946 externally observable. This attribute is only valid on functions 1947 and declarations, not on individual call sites. If a function is 1948 incorrectly marked as speculatable and really does exhibit 1949 undefined behavior, the undefined behavior may be observed even 1950 if the call site is dead code. 1951 1952``ssp`` 1953 This attribute indicates that the function should emit a stack 1954 smashing protector. It is in the form of a "canary" --- a random value 1955 placed on the stack before the local variables that's checked upon 1956 return from the function to see if it has been overwritten. A 1957 heuristic is used to determine if a function needs stack protectors 1958 or not. The heuristic used will enable protectors for functions with: 1959 1960 - Character arrays larger than ``ssp-buffer-size`` (default 8). 1961 - Aggregates containing character arrays larger than ``ssp-buffer-size``. 1962 - Calls to alloca() with variable sizes or constant sizes greater than 1963 ``ssp-buffer-size``. 1964 1965 Variables that are identified as requiring a protector will be arranged 1966 on the stack such that they are adjacent to the stack protector guard. 1967 1968 A function with the ``ssp`` attribute but without the ``alwaysinline`` 1969 attribute cannot be inlined into a function without a 1970 ``ssp/sspreq/sspstrong`` attribute. If inlined, the caller will get the 1971 ``ssp`` attribute. ``call``, ``invoke``, and ``callbr`` instructions with 1972 the ``alwaysinline`` attribute force inlining. 1973``sspstrong`` 1974 This attribute indicates that the function should emit a stack smashing 1975 protector. This attribute causes a strong heuristic to be used when 1976 determining if a function needs stack protectors. The strong heuristic 1977 will enable protectors for functions with: 1978 1979 - Arrays of any size and type 1980 - Aggregates containing an array of any size and type. 1981 - Calls to alloca(). 1982 - Local variables that have had their address taken. 1983 1984 Variables that are identified as requiring a protector will be arranged 1985 on the stack such that they are adjacent to the stack protector guard. 1986 The specific layout rules are: 1987 1988 #. Large arrays and structures containing large arrays 1989 (``>= ssp-buffer-size``) are closest to the stack protector. 1990 #. Small arrays and structures containing small arrays 1991 (``< ssp-buffer-size``) are 2nd closest to the protector. 1992 #. Variables that have had their address taken are 3rd closest to the 1993 protector. 1994 1995 This overrides the ``ssp`` function attribute. 1996 1997 A function with the ``sspstrong`` attribute but without the 1998 ``alwaysinline`` attribute cannot be inlined into a function without a 1999 ``ssp/sspstrong/sspreq`` attribute. If inlined, the caller will get the 2000 ``sspstrong`` attribute unless the ``sspreq`` attribute exists. ``call``, 2001 ``invoke``, and ``callbr`` instructions with the ``alwaysinline`` attribute 2002 force inlining. 2003``sspreq`` 2004 This attribute indicates that the function should *always* emit a stack 2005 smashing protector. This overrides the ``ssp`` and ``sspstrong`` function 2006 attributes. 2007 2008 Variables that are identified as requiring a protector will be arranged 2009 on the stack such that they are adjacent to the stack protector guard. 2010 The specific layout rules are: 2011 2012 #. Large arrays and structures containing large arrays 2013 (``>= ssp-buffer-size``) are closest to the stack protector. 2014 #. Small arrays and structures containing small arrays 2015 (``< ssp-buffer-size``) are 2nd closest to the protector. 2016 #. Variables that have had their address taken are 3rd closest to the 2017 protector. 2018 2019 A function with the ``sspreq`` attribute but without the ``alwaysinline`` 2020 attribute cannot be inlined into a function without a 2021 ``ssp/sspstrong/sspreq`` attribute. If inlined, the caller will get the 2022 ``sspreq`` attribute. ``call``, ``invoke``, and ``callbr`` instructions 2023 with the ``alwaysinline`` attribute force inlining. 2024 2025``strictfp`` 2026 This attribute indicates that the function was called from a scope that 2027 requires strict floating-point semantics. LLVM will not attempt any 2028 optimizations that require assumptions about the floating-point rounding 2029 mode or that might alter the state of floating-point status flags that 2030 might otherwise be set or cleared by calling this function. LLVM will 2031 not introduce any new floating-point instructions that may trap. 2032 2033``"denormal-fp-math"`` 2034 This indicates the denormal (subnormal) handling that may be 2035 assumed for the default floating-point environment. This is a 2036 comma separated pair. The elements may be one of ``"ieee"``, 2037 ``"preserve-sign"``, or ``"positive-zero"``. The first entry 2038 indicates the flushing mode for the result of floating point 2039 operations. The second indicates the handling of denormal inputs 2040 to floating point instructions. For compatibility with older 2041 bitcode, if the second value is omitted, both input and output 2042 modes will assume the same mode. 2043 2044 If this is attribute is not specified, the default is 2045 ``"ieee,ieee"``. 2046 2047 If the output mode is ``"preserve-sign"``, or ``"positive-zero"``, 2048 denormal outputs may be flushed to zero by standard floating-point 2049 operations. It is not mandated that flushing to zero occurs, but if 2050 a denormal output is flushed to zero, it must respect the sign 2051 mode. Not all targets support all modes. While this indicates the 2052 expected floating point mode the function will be executed with, 2053 this does not make any attempt to ensure the mode is 2054 consistent. User or platform code is expected to set the floating 2055 point mode appropriately before function entry. 2056 2057 If the input mode is ``"preserve-sign"``, or ``"positive-zero"``, a 2058 floating-point operation must treat any input denormal value as 2059 zero. In some situations, if an instruction does not respect this 2060 mode, the input may need to be converted to 0 as if by 2061 ``@llvm.canonicalize`` during lowering for correctness. 2062 2063``"denormal-fp-math-f32"`` 2064 Same as ``"denormal-fp-math"``, but only controls the behavior of 2065 the 32-bit float type (or vectors of 32-bit floats). If both are 2066 are present, this overrides ``"denormal-fp-math"``. Not all targets 2067 support separately setting the denormal mode per type, and no 2068 attempt is made to diagnose unsupported uses. Currently this 2069 attribute is respected by the AMDGPU and NVPTX backends. 2070 2071``"thunk"`` 2072 This attribute indicates that the function will delegate to some other 2073 function with a tail call. The prototype of a thunk should not be used for 2074 optimization purposes. The caller is expected to cast the thunk prototype to 2075 match the thunk target prototype. 2076``uwtable`` 2077 This attribute indicates that the ABI being targeted requires that 2078 an unwind table entry be produced for this function even if we can 2079 show that no exceptions passes by it. This is normally the case for 2080 the ELF x86-64 abi, but it can be disabled for some compilation 2081 units. 2082``nocf_check`` 2083 This attribute indicates that no control-flow check will be performed on 2084 the attributed entity. It disables -fcf-protection=<> for a specific 2085 entity to fine grain the HW control flow protection mechanism. The flag 2086 is target independent and currently appertains to a function or function 2087 pointer. 2088``shadowcallstack`` 2089 This attribute indicates that the ShadowCallStack checks are enabled for 2090 the function. The instrumentation checks that the return address for the 2091 function has not changed between the function prolog and epilog. It is 2092 currently x86_64-specific. 2093``mustprogress`` 2094 This attribute indicates that the function is required to return, unwind, 2095 or interact with the environment in an observable way e.g. via a volatile 2096 memory access, I/O, or other synchronization. The ``mustprogress`` 2097 attribute is intended to model the requirements of the first section of 2098 [intro.progress] of the C++ Standard. As a consequence, a loop in a 2099 function with the `mustprogress` attribute can be assumed to terminate if 2100 it does not interact with the environment in an observable way, and 2101 terminating loops without side-effects can be removed. If a `mustprogress` 2102 function does not satisfy this contract, the behavior is undefined. This 2103 attribute does not apply transitively to callees, but does apply to call 2104 sites within the function. Note that `willreturn` implies `mustprogress`. 2105``"warn-stack-size"="<threshold>"`` 2106 This attribute sets a threshold to emit diagnostics once the frame size is 2107 known should the frame size exceed the specified value. It takes one 2108 required integer value, which should be a non-negative integer, and less 2109 than `UINT_MAX`. It's unspecified which threshold will be used when 2110 duplicate definitions are linked together with differing values. 2111``vscale_range(<min>[, <max>])`` 2112 This attribute indicates the minimum and maximum vscale value for the given 2113 function. A value of 0 means unbounded. If the optional max value is omitted 2114 then max is set to the value of min. If the attribute is not present, no 2115 assumptions are made about the range of vscale. 2116 2117Call Site Attributes 2118---------------------- 2119 2120In addition to function attributes the following call site only 2121attributes are supported: 2122 2123``vector-function-abi-variant`` 2124 This attribute can be attached to a :ref:`call <i_call>` to list 2125 the vector functions associated to the function. Notice that the 2126 attribute cannot be attached to a :ref:`invoke <i_invoke>` or a 2127 :ref:`callbr <i_callbr>` instruction. The attribute consists of a 2128 comma separated list of mangled names. The order of the list does 2129 not imply preference (it is logically a set). The compiler is free 2130 to pick any listed vector function of its choosing. 2131 2132 The syntax for the mangled names is as follows::: 2133 2134 _ZGV<isa><mask><vlen><parameters>_<scalar_name>[(<vector_redirection>)] 2135 2136 When present, the attribute informs the compiler that the function 2137 ``<scalar_name>`` has a corresponding vector variant that can be 2138 used to perform the concurrent invocation of ``<scalar_name>`` on 2139 vectors. The shape of the vector function is described by the 2140 tokens between the prefix ``_ZGV`` and the ``<scalar_name>`` 2141 token. The standard name of the vector function is 2142 ``_ZGV<isa><mask><vlen><parameters>_<scalar_name>``. When present, 2143 the optional token ``(<vector_redirection>)`` informs the compiler 2144 that a custom name is provided in addition to the standard one 2145 (custom names can be provided for example via the use of ``declare 2146 variant`` in OpenMP 5.0). The declaration of the variant must be 2147 present in the IR Module. The signature of the vector variant is 2148 determined by the rules of the Vector Function ABI (VFABI) 2149 specifications of the target. For Arm and X86, the VFABI can be 2150 found at https://github.com/ARM-software/abi-aa and 2151 https://software.intel.com/content/www/us/en/develop/download/vector-simd-function-abi.html, 2152 respectively. 2153 2154 For X86 and Arm targets, the values of the tokens in the standard 2155 name are those that are defined in the VFABI. LLVM has an internal 2156 ``<isa>`` token that can be used to create scalar-to-vector 2157 mappings for functions that are not directly associated to any of 2158 the target ISAs (for example, some of the mappings stored in the 2159 TargetLibraryInfo). Valid values for the ``<isa>`` token are::: 2160 2161 <isa>:= b | c | d | e -> X86 SSE, AVX, AVX2, AVX512 2162 | n | s -> Armv8 Advanced SIMD, SVE 2163 | __LLVM__ -> Internal LLVM Vector ISA 2164 2165 For all targets currently supported (x86, Arm and Internal LLVM), 2166 the remaining tokens can have the following values::: 2167 2168 <mask>:= M | N -> mask | no mask 2169 2170 <vlen>:= number -> number of lanes 2171 | x -> VLA (Vector Length Agnostic) 2172 2173 <parameters>:= v -> vector 2174 | l | l <number> -> linear 2175 | R | R <number> -> linear with ref modifier 2176 | L | L <number> -> linear with val modifier 2177 | U | U <number> -> linear with uval modifier 2178 | ls <pos> -> runtime linear 2179 | Rs <pos> -> runtime linear with ref modifier 2180 | Ls <pos> -> runtime linear with val modifier 2181 | Us <pos> -> runtime linear with uval modifier 2182 | u -> uniform 2183 2184 <scalar_name>:= name of the scalar function 2185 2186 <vector_redirection>:= optional, custom name of the vector function 2187 2188``preallocated(<ty>)`` 2189 This attribute is required on calls to ``llvm.call.preallocated.arg`` 2190 and cannot be used on any other call. See 2191 :ref:`llvm.call.preallocated.arg<int_call_preallocated_arg>` for more 2192 details. 2193 2194.. _glattrs: 2195 2196Global Attributes 2197----------------- 2198 2199Attributes may be set to communicate additional information about a global variable. 2200Unlike :ref:`function attributes <fnattrs>`, attributes on a global variable 2201are grouped into a single :ref:`attribute group <attrgrp>`. 2202 2203.. _opbundles: 2204 2205Operand Bundles 2206--------------- 2207 2208Operand bundles are tagged sets of SSA values that can be associated 2209with certain LLVM instructions (currently only ``call`` s and 2210``invoke`` s). In a way they are like metadata, but dropping them is 2211incorrect and will change program semantics. 2212 2213Syntax:: 2214 2215 operand bundle set ::= '[' operand bundle (, operand bundle )* ']' 2216 operand bundle ::= tag '(' [ bundle operand ] (, bundle operand )* ')' 2217 bundle operand ::= SSA value 2218 tag ::= string constant 2219 2220Operand bundles are **not** part of a function's signature, and a 2221given function may be called from multiple places with different kinds 2222of operand bundles. This reflects the fact that the operand bundles 2223are conceptually a part of the ``call`` (or ``invoke``), not the 2224callee being dispatched to. 2225 2226Operand bundles are a generic mechanism intended to support 2227runtime-introspection-like functionality for managed languages. While 2228the exact semantics of an operand bundle depend on the bundle tag, 2229there are certain limitations to how much the presence of an operand 2230bundle can influence the semantics of a program. These restrictions 2231are described as the semantics of an "unknown" operand bundle. As 2232long as the behavior of an operand bundle is describable within these 2233restrictions, LLVM does not need to have special knowledge of the 2234operand bundle to not miscompile programs containing it. 2235 2236- The bundle operands for an unknown operand bundle escape in unknown 2237 ways before control is transferred to the callee or invokee. 2238- Calls and invokes with operand bundles have unknown read / write 2239 effect on the heap on entry and exit (even if the call target is 2240 ``readnone`` or ``readonly``), unless they're overridden with 2241 callsite specific attributes. 2242- An operand bundle at a call site cannot change the implementation 2243 of the called function. Inter-procedural optimizations work as 2244 usual as long as they take into account the first two properties. 2245 2246More specific types of operand bundles are described below. 2247 2248.. _deopt_opbundles: 2249 2250Deoptimization Operand Bundles 2251^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2252 2253Deoptimization operand bundles are characterized by the ``"deopt"`` 2254operand bundle tag. These operand bundles represent an alternate 2255"safe" continuation for the call site they're attached to, and can be 2256used by a suitable runtime to deoptimize the compiled frame at the 2257specified call site. There can be at most one ``"deopt"`` operand 2258bundle attached to a call site. Exact details of deoptimization is 2259out of scope for the language reference, but it usually involves 2260rewriting a compiled frame into a set of interpreted frames. 2261 2262From the compiler's perspective, deoptimization operand bundles make 2263the call sites they're attached to at least ``readonly``. They read 2264through all of their pointer typed operands (even if they're not 2265otherwise escaped) and the entire visible heap. Deoptimization 2266operand bundles do not capture their operands except during 2267deoptimization, in which case control will not be returned to the 2268compiled frame. 2269 2270The inliner knows how to inline through calls that have deoptimization 2271operand bundles. Just like inlining through a normal call site 2272involves composing the normal and exceptional continuations, inlining 2273through a call site with a deoptimization operand bundle needs to 2274appropriately compose the "safe" deoptimization continuation. The 2275inliner does this by prepending the parent's deoptimization 2276continuation to every deoptimization continuation in the inlined body. 2277E.g. inlining ``@f`` into ``@g`` in the following example 2278 2279.. code-block:: llvm 2280 2281 define void @f() { 2282 call void @x() ;; no deopt state 2283 call void @y() [ "deopt"(i32 10) ] 2284 call void @y() [ "deopt"(i32 10), "unknown"(i8* null) ] 2285 ret void 2286 } 2287 2288 define void @g() { 2289 call void @f() [ "deopt"(i32 20) ] 2290 ret void 2291 } 2292 2293will result in 2294 2295.. code-block:: llvm 2296 2297 define void @g() { 2298 call void @x() ;; still no deopt state 2299 call void @y() [ "deopt"(i32 20, i32 10) ] 2300 call void @y() [ "deopt"(i32 20, i32 10), "unknown"(i8* null) ] 2301 ret void 2302 } 2303 2304It is the frontend's responsibility to structure or encode the 2305deoptimization state in a way that syntactically prepending the 2306caller's deoptimization state to the callee's deoptimization state is 2307semantically equivalent to composing the caller's deoptimization 2308continuation after the callee's deoptimization continuation. 2309 2310.. _ob_funclet: 2311 2312Funclet Operand Bundles 2313^^^^^^^^^^^^^^^^^^^^^^^ 2314 2315Funclet operand bundles are characterized by the ``"funclet"`` 2316operand bundle tag. These operand bundles indicate that a call site 2317is within a particular funclet. There can be at most one 2318``"funclet"`` operand bundle attached to a call site and it must have 2319exactly one bundle operand. 2320 2321If any funclet EH pads have been "entered" but not "exited" (per the 2322`description in the EH doc\ <ExceptionHandling.html#wineh-constraints>`_), 2323it is undefined behavior to execute a ``call`` or ``invoke`` which: 2324 2325* does not have a ``"funclet"`` bundle and is not a ``call`` to a nounwind 2326 intrinsic, or 2327* has a ``"funclet"`` bundle whose operand is not the most-recently-entered 2328 not-yet-exited funclet EH pad. 2329 2330Similarly, if no funclet EH pads have been entered-but-not-yet-exited, 2331executing a ``call`` or ``invoke`` with a ``"funclet"`` bundle is undefined behavior. 2332 2333GC Transition Operand Bundles 2334^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2335 2336GC transition operand bundles are characterized by the 2337``"gc-transition"`` operand bundle tag. These operand bundles mark a 2338call as a transition between a function with one GC strategy to a 2339function with a different GC strategy. If coordinating the transition 2340between GC strategies requires additional code generation at the call 2341site, these bundles may contain any values that are needed by the 2342generated code. For more details, see :ref:`GC Transitions 2343<gc_transition_args>`. 2344 2345The bundle contain an arbitrary list of Values which need to be passed 2346to GC transition code. They will be lowered and passed as operands to 2347the appropriate GC_TRANSITION nodes in the selection DAG. It is assumed 2348that these arguments must be available before and after (but not 2349necessarily during) the execution of the callee. 2350 2351.. _assume_opbundles: 2352 2353Assume Operand Bundles 2354^^^^^^^^^^^^^^^^^^^^^^ 2355 2356Operand bundles on an :ref:`llvm.assume <int_assume>` allows representing 2357assumptions that a :ref:`parameter attribute <paramattrs>` or a 2358:ref:`function attribute <fnattrs>` holds for a certain value at a certain 2359location. Operand bundles enable assumptions that are either hard or impossible 2360to represent as a boolean argument of an :ref:`llvm.assume <int_assume>`. 2361 2362An assume operand bundle has the form: 2363 2364:: 2365 2366 "<tag>"([ <holds for value> [, <attribute argument>] ]) 2367 2368* The tag of the operand bundle is usually the name of attribute that can be 2369 assumed to hold. It can also be `ignore`, this tag doesn't contain any 2370 information and should be ignored. 2371* The first argument if present is the value for which the attribute hold. 2372* The second argument if present is an argument of the attribute. 2373 2374If there are no arguments the attribute is a property of the call location. 2375 2376If the represented attribute expects a constant argument, the argument provided 2377to the operand bundle should be a constant as well. 2378 2379For example: 2380 2381.. code-block:: llvm 2382 2383 call void @llvm.assume(i1 true) ["align"(i32* %val, i32 8)] 2384 2385allows the optimizer to assume that at location of call to 2386:ref:`llvm.assume <int_assume>` ``%val`` has an alignment of at least 8. 2387 2388.. code-block:: llvm 2389 2390 call void @llvm.assume(i1 %cond) ["cold"(), "nonnull"(i64* %val)] 2391 2392allows the optimizer to assume that the :ref:`llvm.assume <int_assume>` 2393call location is cold and that ``%val`` may not be null. 2394 2395Just like for the argument of :ref:`llvm.assume <int_assume>`, if any of the 2396provided guarantees are violated at runtime the behavior is undefined. 2397 2398Even if the assumed property can be encoded as a boolean value, like 2399``nonnull``, using operand bundles to express the property can still have 2400benefits: 2401 2402* Attributes that can be expressed via operand bundles are directly the 2403 property that the optimizer uses and cares about. Encoding attributes as 2404 operand bundles removes the need for an instruction sequence that represents 2405 the property (e.g., `icmp ne i32* %p, null` for `nonnull`) and for the 2406 optimizer to deduce the property from that instruction sequence. 2407* Expressing the property using operand bundles makes it easy to identify the 2408 use of the value as a use in an :ref:`llvm.assume <int_assume>`. This then 2409 simplifies and improves heuristics, e.g., for use "use-sensitive" 2410 optimizations. 2411 2412.. _ob_preallocated: 2413 2414Preallocated Operand Bundles 2415^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2416 2417Preallocated operand bundles are characterized by the ``"preallocated"`` 2418operand bundle tag. These operand bundles allow separation of the allocation 2419of the call argument memory from the call site. This is necessary to pass 2420non-trivially copyable objects by value in a way that is compatible with MSVC 2421on some targets. There can be at most one ``"preallocated"`` operand bundle 2422attached to a call site and it must have exactly one bundle operand, which is 2423a token generated by ``@llvm.call.preallocated.setup``. A call with this 2424operand bundle should not adjust the stack before entering the function, as 2425that will have been done by one of the ``@llvm.call.preallocated.*`` intrinsics. 2426 2427.. code-block:: llvm 2428 2429 %foo = type { i64, i32 } 2430 2431 ... 2432 2433 %t = call token @llvm.call.preallocated.setup(i32 1) 2434 %a = call i8* @llvm.call.preallocated.arg(token %t, i32 0) preallocated(%foo) 2435 %b = bitcast i8* %a to %foo* 2436 ; initialize %b 2437 call void @bar(i32 42, %foo* preallocated(%foo) %b) ["preallocated"(token %t)] 2438 2439.. _ob_gc_live: 2440 2441GC Live Operand Bundles 2442^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2443 2444A "gc-live" operand bundle is only valid on a :ref:`gc.statepoint <gc_statepoint>` 2445intrinsic. The operand bundle must contain every pointer to a garbage collected 2446object which potentially needs to be updated by the garbage collector. 2447 2448When lowered, any relocated value will be recorded in the corresponding 2449:ref:`stackmap entry <statepoint-stackmap-format>`. See the intrinsic description 2450for further details. 2451 2452ObjC ARC Attached Call Operand Bundles 2453^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2454 2455A ``"clang.arc.attachedcall`` operand bundle on a call indicates the call is 2456implicitly followed by a marker instruction and a call to an ObjC runtime 2457function that uses the result of the call. If the argument passed to the operand 2458bundle is 0, ``@objc_retainAutoreleasedReturnValue`` is called. If 1 is passed, 2459``@objc_unsafeClaimAutoreleasedReturnValue`` is called. The return value of a 2460call with this bundle is used by a call to ``@llvm.objc.clang.arc.noop.use`` 2461unless the called function's return type is void, in which case the operand 2462bundle is ignored. 2463 2464The operand bundle is needed to ensure the call is immediately followed by the 2465marker instruction or the ObjC runtime call in the final output. 2466 2467.. _moduleasm: 2468 2469Module-Level Inline Assembly 2470---------------------------- 2471 2472Modules may contain "module-level inline asm" blocks, which corresponds 2473to the GCC "file scope inline asm" blocks. These blocks are internally 2474concatenated by LLVM and treated as a single unit, but may be separated 2475in the ``.ll`` file if desired. The syntax is very simple: 2476 2477.. code-block:: llvm 2478 2479 module asm "inline asm code goes here" 2480 module asm "more can go here" 2481 2482The strings can contain any character by escaping non-printable 2483characters. The escape sequence used is simply "\\xx" where "xx" is the 2484two digit hex code for the number. 2485 2486Note that the assembly string *must* be parseable by LLVM's integrated assembler 2487(unless it is disabled), even when emitting a ``.s`` file. 2488 2489.. _langref_datalayout: 2490 2491Data Layout 2492----------- 2493 2494A module may specify a target specific data layout string that specifies 2495how data is to be laid out in memory. The syntax for the data layout is 2496simply: 2497 2498.. code-block:: llvm 2499 2500 target datalayout = "layout specification" 2501 2502The *layout specification* consists of a list of specifications 2503separated by the minus sign character ('-'). Each specification starts 2504with a letter and may include other information after the letter to 2505define some aspect of the data layout. The specifications accepted are 2506as follows: 2507 2508``E`` 2509 Specifies that the target lays out data in big-endian form. That is, 2510 the bits with the most significance have the lowest address 2511 location. 2512``e`` 2513 Specifies that the target lays out data in little-endian form. That 2514 is, the bits with the least significance have the lowest address 2515 location. 2516``S<size>`` 2517 Specifies the natural alignment of the stack in bits. Alignment 2518 promotion of stack variables is limited to the natural stack 2519 alignment to avoid dynamic stack realignment. The stack alignment 2520 must be a multiple of 8-bits. If omitted, the natural stack 2521 alignment defaults to "unspecified", which does not prevent any 2522 alignment promotions. 2523``P<address space>`` 2524 Specifies the address space that corresponds to program memory. 2525 Harvard architectures can use this to specify what space LLVM 2526 should place things such as functions into. If omitted, the 2527 program memory space defaults to the default address space of 0, 2528 which corresponds to a Von Neumann architecture that has code 2529 and data in the same space. 2530``G<address space>`` 2531 Specifies the address space to be used by default when creating global 2532 variables. If omitted, the globals address space defaults to the default 2533 address space 0. 2534 Note: variable declarations without an address space are always created in 2535 address space 0, this property only affects the default value to be used 2536 when creating globals without additional contextual information (e.g. in 2537 LLVM passes). 2538``A<address space>`` 2539 Specifies the address space of objects created by '``alloca``'. 2540 Defaults to the default address space of 0. 2541``p[n]:<size>:<abi>:<pref>:<idx>`` 2542 This specifies the *size* of a pointer and its ``<abi>`` and 2543 ``<pref>``\erred alignments for address space ``n``. The fourth parameter 2544 ``<idx>`` is a size of index that used for address calculation. If not 2545 specified, the default index size is equal to the pointer size. All sizes 2546 are in bits. The address space, ``n``, is optional, and if not specified, 2547 denotes the default address space 0. The value of ``n`` must be 2548 in the range [1,2^23). 2549``i<size>:<abi>:<pref>`` 2550 This specifies the alignment for an integer type of a given bit 2551 ``<size>``. The value of ``<size>`` must be in the range [1,2^23). 2552``v<size>:<abi>:<pref>`` 2553 This specifies the alignment for a vector type of a given bit 2554 ``<size>``. 2555``f<size>:<abi>:<pref>`` 2556 This specifies the alignment for a floating-point type of a given bit 2557 ``<size>``. Only values of ``<size>`` that are supported by the target 2558 will work. 32 (float) and 64 (double) are supported on all targets; 80 2559 or 128 (different flavors of long double) are also supported on some 2560 targets. 2561``a:<abi>:<pref>`` 2562 This specifies the alignment for an object of aggregate type. 2563``F<type><abi>`` 2564 This specifies the alignment for function pointers. 2565 The options for ``<type>`` are: 2566 2567 * ``i``: The alignment of function pointers is independent of the alignment 2568 of functions, and is a multiple of ``<abi>``. 2569 * ``n``: The alignment of function pointers is a multiple of the explicit 2570 alignment specified on the function, and is a multiple of ``<abi>``. 2571``m:<mangling>`` 2572 If present, specifies that llvm names are mangled in the output. Symbols 2573 prefixed with the mangling escape character ``\01`` are passed through 2574 directly to the assembler without the escape character. The mangling style 2575 options are 2576 2577 * ``e``: ELF mangling: Private symbols get a ``.L`` prefix. 2578 * ``m``: Mips mangling: Private symbols get a ``$`` prefix. 2579 * ``o``: Mach-O mangling: Private symbols get ``L`` prefix. Other 2580 symbols get a ``_`` prefix. 2581 * ``x``: Windows x86 COFF mangling: Private symbols get the usual prefix. 2582 Regular C symbols get a ``_`` prefix. Functions with ``__stdcall``, 2583 ``__fastcall``, and ``__vectorcall`` have custom mangling that appends 2584 ``@N`` where N is the number of bytes used to pass parameters. C++ symbols 2585 starting with ``?`` are not mangled in any way. 2586 * ``w``: Windows COFF mangling: Similar to ``x``, except that normal C 2587 symbols do not receive a ``_`` prefix. 2588 * ``a``: XCOFF mangling: Private symbols get a ``L..`` prefix. 2589``n<size1>:<size2>:<size3>...`` 2590 This specifies a set of native integer widths for the target CPU in 2591 bits. For example, it might contain ``n32`` for 32-bit PowerPC, 2592 ``n32:64`` for PowerPC 64, or ``n8:16:32:64`` for X86-64. Elements of 2593 this set are considered to support most general arithmetic operations 2594 efficiently. 2595``ni:<address space0>:<address space1>:<address space2>...`` 2596 This specifies pointer types with the specified address spaces 2597 as :ref:`Non-Integral Pointer Type <nointptrtype>` s. The ``0`` 2598 address space cannot be specified as non-integral. 2599 2600On every specification that takes a ``<abi>:<pref>``, specifying the 2601``<pref>`` alignment is optional. If omitted, the preceding ``:`` 2602should be omitted too and ``<pref>`` will be equal to ``<abi>``. 2603 2604When constructing the data layout for a given target, LLVM starts with a 2605default set of specifications which are then (possibly) overridden by 2606the specifications in the ``datalayout`` keyword. The default 2607specifications are given in this list: 2608 2609- ``E`` - big endian 2610- ``p:64:64:64`` - 64-bit pointers with 64-bit alignment. 2611- ``p[n]:64:64:64`` - Other address spaces are assumed to be the 2612 same as the default address space. 2613- ``S0`` - natural stack alignment is unspecified 2614- ``i1:8:8`` - i1 is 8-bit (byte) aligned 2615- ``i8:8:8`` - i8 is 8-bit (byte) aligned 2616- ``i16:16:16`` - i16 is 16-bit aligned 2617- ``i32:32:32`` - i32 is 32-bit aligned 2618- ``i64:32:64`` - i64 has ABI alignment of 32-bits but preferred 2619 alignment of 64-bits 2620- ``f16:16:16`` - half is 16-bit aligned 2621- ``f32:32:32`` - float is 32-bit aligned 2622- ``f64:64:64`` - double is 64-bit aligned 2623- ``f128:128:128`` - quad is 128-bit aligned 2624- ``v64:64:64`` - 64-bit vector is 64-bit aligned 2625- ``v128:128:128`` - 128-bit vector is 128-bit aligned 2626- ``a:0:64`` - aggregates are 64-bit aligned 2627 2628When LLVM is determining the alignment for a given type, it uses the 2629following rules: 2630 2631#. If the type sought is an exact match for one of the specifications, 2632 that specification is used. 2633#. If no match is found, and the type sought is an integer type, then 2634 the smallest integer type that is larger than the bitwidth of the 2635 sought type is used. If none of the specifications are larger than 2636 the bitwidth then the largest integer type is used. For example, 2637 given the default specifications above, the i7 type will use the 2638 alignment of i8 (next largest) while both i65 and i256 will use the 2639 alignment of i64 (largest specified). 2640#. If no match is found, and the type sought is a vector type, then the 2641 largest vector type that is smaller than the sought vector type will 2642 be used as a fall back. This happens because <128 x double> can be 2643 implemented in terms of 64 <2 x double>, for example. 2644 2645The function of the data layout string may not be what you expect. 2646Notably, this is not a specification from the frontend of what alignment 2647the code generator should use. 2648 2649Instead, if specified, the target data layout is required to match what 2650the ultimate *code generator* expects. This string is used by the 2651mid-level optimizers to improve code, and this only works if it matches 2652what the ultimate code generator uses. There is no way to generate IR 2653that does not embed this target-specific detail into the IR. If you 2654don't specify the string, the default specifications will be used to 2655generate a Data Layout and the optimization phases will operate 2656accordingly and introduce target specificity into the IR with respect to 2657these default specifications. 2658 2659.. _langref_triple: 2660 2661Target Triple 2662------------- 2663 2664A module may specify a target triple string that describes the target 2665host. The syntax for the target triple is simply: 2666 2667.. code-block:: llvm 2668 2669 target triple = "x86_64-apple-macosx10.7.0" 2670 2671The *target triple* string consists of a series of identifiers delimited 2672by the minus sign character ('-'). The canonical forms are: 2673 2674:: 2675 2676 ARCHITECTURE-VENDOR-OPERATING_SYSTEM 2677 ARCHITECTURE-VENDOR-OPERATING_SYSTEM-ENVIRONMENT 2678 2679This information is passed along to the backend so that it generates 2680code for the proper architecture. It's possible to override this on the 2681command line with the ``-mtriple`` command line option. 2682 2683.. _objectlifetime: 2684 2685Object Lifetime 2686---------------------- 2687 2688A memory object, or simply object, is a region of a memory space that is 2689reserved by a memory allocation such as :ref:`alloca <i_alloca>`, heap 2690allocation calls, and global variable definitions. 2691Once it is allocated, the bytes stored in the region can only be read or written 2692through a pointer that is :ref:`based on <pointeraliasing>` the allocation 2693value. 2694If a pointer that is not based on the object tries to read or write to the 2695object, it is undefined behavior. 2696 2697A lifetime of a memory object is a property that decides its accessibility. 2698Unless stated otherwise, a memory object is alive since its allocation, and 2699dead after its deallocation. 2700It is undefined behavior to access a memory object that isn't alive, but 2701operations that don't dereference it such as 2702:ref:`getelementptr <i_getelementptr>`, :ref:`ptrtoint <i_ptrtoint>` and 2703:ref:`icmp <i_icmp>` return a valid result. 2704This explains code motion of these instructions across operations that 2705impact the object's lifetime. 2706A stack object's lifetime can be explicitly specified using 2707:ref:`llvm.lifetime.start <int_lifestart>` and 2708:ref:`llvm.lifetime.end <int_lifeend>` intrinsic function calls. 2709 2710.. _pointeraliasing: 2711 2712Pointer Aliasing Rules 2713---------------------- 2714 2715Any memory access must be done through a pointer value associated with 2716an address range of the memory access, otherwise the behavior is 2717undefined. Pointer values are associated with address ranges according 2718to the following rules: 2719 2720- A pointer value is associated with the addresses associated with any 2721 value it is *based* on. 2722- An address of a global variable is associated with the address range 2723 of the variable's storage. 2724- The result value of an allocation instruction is associated with the 2725 address range of the allocated storage. 2726- A null pointer in the default address-space is associated with no 2727 address. 2728- An :ref:`undef value <undefvalues>` in *any* address-space is 2729 associated with no address. 2730- An integer constant other than zero or a pointer value returned from 2731 a function not defined within LLVM may be associated with address 2732 ranges allocated through mechanisms other than those provided by 2733 LLVM. Such ranges shall not overlap with any ranges of addresses 2734 allocated by mechanisms provided by LLVM. 2735 2736A pointer value is *based* on another pointer value according to the 2737following rules: 2738 2739- A pointer value formed from a scalar ``getelementptr`` operation is *based* on 2740 the pointer-typed operand of the ``getelementptr``. 2741- The pointer in lane *l* of the result of a vector ``getelementptr`` operation 2742 is *based* on the pointer in lane *l* of the vector-of-pointers-typed operand 2743 of the ``getelementptr``. 2744- The result value of a ``bitcast`` is *based* on the operand of the 2745 ``bitcast``. 2746- A pointer value formed by an ``inttoptr`` is *based* on all pointer 2747 values that contribute (directly or indirectly) to the computation of 2748 the pointer's value. 2749- The "*based* on" relationship is transitive. 2750 2751Note that this definition of *"based"* is intentionally similar to the 2752definition of *"based"* in C99, though it is slightly weaker. 2753 2754LLVM IR does not associate types with memory. The result type of a 2755``load`` merely indicates the size and alignment of the memory from 2756which to load, as well as the interpretation of the value. The first 2757operand type of a ``store`` similarly only indicates the size and 2758alignment of the store. 2759 2760Consequently, type-based alias analysis, aka TBAA, aka 2761``-fstrict-aliasing``, is not applicable to general unadorned LLVM IR. 2762:ref:`Metadata <metadata>` may be used to encode additional information 2763which specialized optimization passes may use to implement type-based 2764alias analysis. 2765 2766.. _pointercapture: 2767 2768Pointer Capture 2769--------------- 2770 2771Given a function call and a pointer that is passed as an argument or stored in 2772the memory before the call, a pointer is *captured* by the call if it makes a 2773copy of any part of the pointer that outlives the call. 2774To be precise, a pointer is captured if one or more of the following conditions 2775hold: 2776 27771. The call stores any bit of the pointer carrying information into a place, 2778 and the stored bits can be read from the place by the caller after this call 2779 exits. 2780 2781.. code-block:: llvm 2782 2783 @glb = global i8* null 2784 @glb2 = global i8* null 2785 @glb3 = global i8* null 2786 @glbi = global i32 0 2787 2788 define i8* @f(i8* %a, i8* %b, i8* %c, i8* %d, i8* %e) { 2789 store i8* %a, i8** @glb ; %a is captured by this call 2790 2791 store i8* %b, i8** @glb2 ; %b isn't captured because the stored value is overwritten by the store below 2792 store i8* null, i8** @glb2 2793 2794 store i8* %c, i8** @glb3 2795 call void @g() ; If @g makes a copy of %c that outlives this call (@f), %c is captured 2796 store i8* null, i8** @glb3 2797 2798 %i = ptrtoint i8* %d to i64 2799 %j = trunc i64 %i to i32 2800 store i32 %j, i32* @glbi ; %d is captured 2801 2802 ret i8* %e ; %e is captured 2803 } 2804 28052. The call stores any bit of the pointer carrying information into a place, 2806 and the stored bits can be safely read from the place by another thread via 2807 synchronization. 2808 2809.. code-block:: llvm 2810 2811 @lock = global i1 true 2812 2813 define void @f(i8* %a) { 2814 store i8* %a, i8** @glb 2815 store atomic i1 false, i1* @lock release ; %a is captured because another thread can safely read @glb 2816 store i8* null, i8** @glb 2817 ret void 2818 } 2819 28203. The call's behavior depends on any bit of the pointer carrying information. 2821 2822.. code-block:: llvm 2823 2824 @glb = global i8 0 2825 2826 define void @f(i8* %a) { 2827 %c = icmp eq i8* %a, @glb 2828 br i1 %c, label %BB_EXIT, label %BB_CONTINUE ; escapes %a 2829 BB_EXIT: 2830 call void @exit() 2831 unreachable 2832 BB_CONTINUE: 2833 ret void 2834 } 2835 28364. The pointer is used in a volatile access as its address. 2837 2838 2839.. _volatile: 2840 2841Volatile Memory Accesses 2842------------------------ 2843 2844Certain memory accesses, such as :ref:`load <i_load>`'s, 2845:ref:`store <i_store>`'s, and :ref:`llvm.memcpy <int_memcpy>`'s may be 2846marked ``volatile``. The optimizers must not change the number of 2847volatile operations or change their order of execution relative to other 2848volatile operations. The optimizers *may* change the order of volatile 2849operations relative to non-volatile operations. This is not Java's 2850"volatile" and has no cross-thread synchronization behavior. 2851 2852A volatile load or store may have additional target-specific semantics. 2853Any volatile operation can have side effects, and any volatile operation 2854can read and/or modify state which is not accessible via a regular load 2855or store in this module. Volatile operations may use addresses which do 2856not point to memory (like MMIO registers). This means the compiler may 2857not use a volatile operation to prove a non-volatile access to that 2858address has defined behavior. 2859 2860The allowed side-effects for volatile accesses are limited. If a 2861non-volatile store to a given address would be legal, a volatile 2862operation may modify the memory at that address. A volatile operation 2863may not modify any other memory accessible by the module being compiled. 2864A volatile operation may not call any code in the current module. 2865 2866The compiler may assume execution will continue after a volatile operation, 2867so operations which modify memory or may have undefined behavior can be 2868hoisted past a volatile operation. 2869 2870As an exception to the preceding rule, the compiler may not assume execution 2871will continue after a volatile store operation. This restriction is necessary 2872to support the somewhat common pattern in C of intentionally storing to an 2873invalid pointer to crash the program. In the future, it might make sense to 2874allow frontends to control this behavior. 2875 2876IR-level volatile loads and stores cannot safely be optimized into llvm.memcpy 2877or llvm.memmove intrinsics even when those intrinsics are flagged volatile. 2878Likewise, the backend should never split or merge target-legal volatile 2879load/store instructions. Similarly, IR-level volatile loads and stores cannot 2880change from integer to floating-point or vice versa. 2881 2882.. admonition:: Rationale 2883 2884 Platforms may rely on volatile loads and stores of natively supported 2885 data width to be executed as single instruction. For example, in C 2886 this holds for an l-value of volatile primitive type with native 2887 hardware support, but not necessarily for aggregate types. The 2888 frontend upholds these expectations, which are intentionally 2889 unspecified in the IR. The rules above ensure that IR transformations 2890 do not violate the frontend's contract with the language. 2891 2892.. _memmodel: 2893 2894Memory Model for Concurrent Operations 2895-------------------------------------- 2896 2897The LLVM IR does not define any way to start parallel threads of 2898execution or to register signal handlers. Nonetheless, there are 2899platform-specific ways to create them, and we define LLVM IR's behavior 2900in their presence. This model is inspired by the C++0x memory model. 2901 2902For a more informal introduction to this model, see the :doc:`Atomics`. 2903 2904We define a *happens-before* partial order as the least partial order 2905that 2906 2907- Is a superset of single-thread program order, and 2908- When a *synchronizes-with* ``b``, includes an edge from ``a`` to 2909 ``b``. *Synchronizes-with* pairs are introduced by platform-specific 2910 techniques, like pthread locks, thread creation, thread joining, 2911 etc., and by atomic instructions. (See also :ref:`Atomic Memory Ordering 2912 Constraints <ordering>`). 2913 2914Note that program order does not introduce *happens-before* edges 2915between a thread and signals executing inside that thread. 2916 2917Every (defined) read operation (load instructions, memcpy, atomic 2918loads/read-modify-writes, etc.) R reads a series of bytes written by 2919(defined) write operations (store instructions, atomic 2920stores/read-modify-writes, memcpy, etc.). For the purposes of this 2921section, initialized globals are considered to have a write of the 2922initializer which is atomic and happens before any other read or write 2923of the memory in question. For each byte of a read R, R\ :sub:`byte` 2924may see any write to the same byte, except: 2925 2926- If write\ :sub:`1` happens before write\ :sub:`2`, and 2927 write\ :sub:`2` happens before R\ :sub:`byte`, then 2928 R\ :sub:`byte` does not see write\ :sub:`1`. 2929- If R\ :sub:`byte` happens before write\ :sub:`3`, then 2930 R\ :sub:`byte` does not see write\ :sub:`3`. 2931 2932Given that definition, R\ :sub:`byte` is defined as follows: 2933 2934- If R is volatile, the result is target-dependent. (Volatile is 2935 supposed to give guarantees which can support ``sig_atomic_t`` in 2936 C/C++, and may be used for accesses to addresses that do not behave 2937 like normal memory. It does not generally provide cross-thread 2938 synchronization.) 2939- Otherwise, if there is no write to the same byte that happens before 2940 R\ :sub:`byte`, R\ :sub:`byte` returns ``undef`` for that byte. 2941- Otherwise, if R\ :sub:`byte` may see exactly one write, 2942 R\ :sub:`byte` returns the value written by that write. 2943- Otherwise, if R is atomic, and all the writes R\ :sub:`byte` may 2944 see are atomic, it chooses one of the values written. See the :ref:`Atomic 2945 Memory Ordering Constraints <ordering>` section for additional 2946 constraints on how the choice is made. 2947- Otherwise R\ :sub:`byte` returns ``undef``. 2948 2949R returns the value composed of the series of bytes it read. This 2950implies that some bytes within the value may be ``undef`` **without** 2951the entire value being ``undef``. Note that this only defines the 2952semantics of the operation; it doesn't mean that targets will emit more 2953than one instruction to read the series of bytes. 2954 2955Note that in cases where none of the atomic intrinsics are used, this 2956model places only one restriction on IR transformations on top of what 2957is required for single-threaded execution: introducing a store to a byte 2958which might not otherwise be stored is not allowed in general. 2959(Specifically, in the case where another thread might write to and read 2960from an address, introducing a store can change a load that may see 2961exactly one write into a load that may see multiple writes.) 2962 2963.. _ordering: 2964 2965Atomic Memory Ordering Constraints 2966---------------------------------- 2967 2968Atomic instructions (:ref:`cmpxchg <i_cmpxchg>`, 2969:ref:`atomicrmw <i_atomicrmw>`, :ref:`fence <i_fence>`, 2970:ref:`atomic load <i_load>`, and :ref:`atomic store <i_store>`) take 2971ordering parameters that determine which other atomic instructions on 2972the same address they *synchronize with*. These semantics are borrowed 2973from Java and C++0x, but are somewhat more colloquial. If these 2974descriptions aren't precise enough, check those specs (see spec 2975references in the :doc:`atomics guide <Atomics>`). 2976:ref:`fence <i_fence>` instructions treat these orderings somewhat 2977differently since they don't take an address. See that instruction's 2978documentation for details. 2979 2980For a simpler introduction to the ordering constraints, see the 2981:doc:`Atomics`. 2982 2983``unordered`` 2984 The set of values that can be read is governed by the happens-before 2985 partial order. A value cannot be read unless some operation wrote 2986 it. This is intended to provide a guarantee strong enough to model 2987 Java's non-volatile shared variables. This ordering cannot be 2988 specified for read-modify-write operations; it is not strong enough 2989 to make them atomic in any interesting way. 2990``monotonic`` 2991 In addition to the guarantees of ``unordered``, there is a single 2992 total order for modifications by ``monotonic`` operations on each 2993 address. All modification orders must be compatible with the 2994 happens-before order. There is no guarantee that the modification 2995 orders can be combined to a global total order for the whole program 2996 (and this often will not be possible). The read in an atomic 2997 read-modify-write operation (:ref:`cmpxchg <i_cmpxchg>` and 2998 :ref:`atomicrmw <i_atomicrmw>`) reads the value in the modification 2999 order immediately before the value it writes. If one atomic read 3000 happens before another atomic read of the same address, the later 3001 read must see the same value or a later value in the address's 3002 modification order. This disallows reordering of ``monotonic`` (or 3003 stronger) operations on the same address. If an address is written 3004 ``monotonic``-ally by one thread, and other threads ``monotonic``-ally 3005 read that address repeatedly, the other threads must eventually see 3006 the write. This corresponds to the C++0x/C1x 3007 ``memory_order_relaxed``. 3008``acquire`` 3009 In addition to the guarantees of ``monotonic``, a 3010 *synchronizes-with* edge may be formed with a ``release`` operation. 3011 This is intended to model C++'s ``memory_order_acquire``. 3012``release`` 3013 In addition to the guarantees of ``monotonic``, if this operation 3014 writes a value which is subsequently read by an ``acquire`` 3015 operation, it *synchronizes-with* that operation. (This isn't a 3016 complete description; see the C++0x definition of a release 3017 sequence.) This corresponds to the C++0x/C1x 3018 ``memory_order_release``. 3019``acq_rel`` (acquire+release) 3020 Acts as both an ``acquire`` and ``release`` operation on its 3021 address. This corresponds to the C++0x/C1x ``memory_order_acq_rel``. 3022``seq_cst`` (sequentially consistent) 3023 In addition to the guarantees of ``acq_rel`` (``acquire`` for an 3024 operation that only reads, ``release`` for an operation that only 3025 writes), there is a global total order on all 3026 sequentially-consistent operations on all addresses, which is 3027 consistent with the *happens-before* partial order and with the 3028 modification orders of all the affected addresses. Each 3029 sequentially-consistent read sees the last preceding write to the 3030 same address in this global order. This corresponds to the C++0x/C1x 3031 ``memory_order_seq_cst`` and Java volatile. 3032 3033.. _syncscope: 3034 3035If an atomic operation is marked ``syncscope("singlethread")``, it only 3036*synchronizes with* and only participates in the seq\_cst total orderings of 3037other operations running in the same thread (for example, in signal handlers). 3038 3039If an atomic operation is marked ``syncscope("<target-scope>")``, where 3040``<target-scope>`` is a target specific synchronization scope, then it is target 3041dependent if it *synchronizes with* and participates in the seq\_cst total 3042orderings of other operations. 3043 3044Otherwise, an atomic operation that is not marked ``syncscope("singlethread")`` 3045or ``syncscope("<target-scope>")`` *synchronizes with* and participates in the 3046seq\_cst total orderings of other operations that are not marked 3047``syncscope("singlethread")`` or ``syncscope("<target-scope>")``. 3048 3049.. _floatenv: 3050 3051Floating-Point Environment 3052-------------------------- 3053 3054The default LLVM floating-point environment assumes that floating-point 3055instructions do not have side effects. Results assume the round-to-nearest 3056rounding mode. No floating-point exception state is maintained in this 3057environment. Therefore, there is no attempt to create or preserve invalid 3058operation (SNaN) or division-by-zero exceptions. 3059 3060The benefit of this exception-free assumption is that floating-point 3061operations may be speculated freely without any other fast-math relaxations 3062to the floating-point model. 3063 3064Code that requires different behavior than this should use the 3065:ref:`Constrained Floating-Point Intrinsics <constrainedfp>`. 3066 3067.. _fastmath: 3068 3069Fast-Math Flags 3070--------------- 3071 3072LLVM IR floating-point operations (:ref:`fneg <i_fneg>`, :ref:`fadd <i_fadd>`, 3073:ref:`fsub <i_fsub>`, :ref:`fmul <i_fmul>`, :ref:`fdiv <i_fdiv>`, 3074:ref:`frem <i_frem>`, :ref:`fcmp <i_fcmp>`), :ref:`phi <i_phi>`, 3075:ref:`select <i_select>` and :ref:`call <i_call>` 3076may use the following flags to enable otherwise unsafe 3077floating-point transformations. 3078 3079``nnan`` 3080 No NaNs - Allow optimizations to assume the arguments and result are not 3081 NaN. If an argument is a nan, or the result would be a nan, it produces 3082 a :ref:`poison value <poisonvalues>` instead. 3083 3084``ninf`` 3085 No Infs - Allow optimizations to assume the arguments and result are not 3086 +/-Inf. If an argument is +/-Inf, or the result would be +/-Inf, it 3087 produces a :ref:`poison value <poisonvalues>` instead. 3088 3089``nsz`` 3090 No Signed Zeros - Allow optimizations to treat the sign of a zero 3091 argument or result as insignificant. This does not imply that -0.0 3092 is poison and/or guaranteed to not exist in the operation. 3093 3094``arcp`` 3095 Allow Reciprocal - Allow optimizations to use the reciprocal of an 3096 argument rather than perform division. 3097 3098``contract`` 3099 Allow floating-point contraction (e.g. fusing a multiply followed by an 3100 addition into a fused multiply-and-add). This does not enable reassociating 3101 to form arbitrary contractions. For example, ``(a*b) + (c*d) + e`` can not 3102 be transformed into ``(a*b) + ((c*d) + e)`` to create two fma operations. 3103 3104``afn`` 3105 Approximate functions - Allow substitution of approximate calculations for 3106 functions (sin, log, sqrt, etc). See floating-point intrinsic definitions 3107 for places where this can apply to LLVM's intrinsic math functions. 3108 3109``reassoc`` 3110 Allow reassociation transformations for floating-point instructions. 3111 This may dramatically change results in floating-point. 3112 3113``fast`` 3114 This flag implies all of the others. 3115 3116.. _uselistorder: 3117 3118Use-list Order Directives 3119------------------------- 3120 3121Use-list directives encode the in-memory order of each use-list, allowing the 3122order to be recreated. ``<order-indexes>`` is a comma-separated list of 3123indexes that are assigned to the referenced value's uses. The referenced 3124value's use-list is immediately sorted by these indexes. 3125 3126Use-list directives may appear at function scope or global scope. They are not 3127instructions, and have no effect on the semantics of the IR. When they're at 3128function scope, they must appear after the terminator of the final basic block. 3129 3130If basic blocks have their address taken via ``blockaddress()`` expressions, 3131``uselistorder_bb`` can be used to reorder their use-lists from outside their 3132function's scope. 3133 3134:Syntax: 3135 3136:: 3137 3138 uselistorder <ty> <value>, { <order-indexes> } 3139 uselistorder_bb @function, %block { <order-indexes> } 3140 3141:Examples: 3142 3143:: 3144 3145 define void @foo(i32 %arg1, i32 %arg2) { 3146 entry: 3147 ; ... instructions ... 3148 bb: 3149 ; ... instructions ... 3150 3151 ; At function scope. 3152 uselistorder i32 %arg1, { 1, 0, 2 } 3153 uselistorder label %bb, { 1, 0 } 3154 } 3155 3156 ; At global scope. 3157 uselistorder i32* @global, { 1, 2, 0 } 3158 uselistorder i32 7, { 1, 0 } 3159 uselistorder i32 (i32) @bar, { 1, 0 } 3160 uselistorder_bb @foo, %bb, { 5, 1, 3, 2, 0, 4 } 3161 3162.. _source_filename: 3163 3164Source Filename 3165--------------- 3166 3167The *source filename* string is set to the original module identifier, 3168which will be the name of the compiled source file when compiling from 3169source through the clang front end, for example. It is then preserved through 3170the IR and bitcode. 3171 3172This is currently necessary to generate a consistent unique global 3173identifier for local functions used in profile data, which prepends the 3174source file name to the local function name. 3175 3176The syntax for the source file name is simply: 3177 3178.. code-block:: text 3179 3180 source_filename = "/path/to/source.c" 3181 3182.. _typesystem: 3183 3184Type System 3185=========== 3186 3187The LLVM type system is one of the most important features of the 3188intermediate representation. Being typed enables a number of 3189optimizations to be performed on the intermediate representation 3190directly, without having to do extra analyses on the side before the 3191transformation. A strong type system makes it easier to read the 3192generated code and enables novel analyses and transformations that are 3193not feasible to perform on normal three address code representations. 3194 3195.. _t_void: 3196 3197Void Type 3198--------- 3199 3200:Overview: 3201 3202 3203The void type does not represent any value and has no size. 3204 3205:Syntax: 3206 3207 3208:: 3209 3210 void 3211 3212 3213.. _t_function: 3214 3215Function Type 3216------------- 3217 3218:Overview: 3219 3220 3221The function type can be thought of as a function signature. It consists of a 3222return type and a list of formal parameter types. The return type of a function 3223type is a void type or first class type --- except for :ref:`label <t_label>` 3224and :ref:`metadata <t_metadata>` types. 3225 3226:Syntax: 3227 3228:: 3229 3230 <returntype> (<parameter list>) 3231 3232...where '``<parameter list>``' is a comma-separated list of type 3233specifiers. Optionally, the parameter list may include a type ``...``, which 3234indicates that the function takes a variable number of arguments. Variable 3235argument functions can access their arguments with the :ref:`variable argument 3236handling intrinsic <int_varargs>` functions. '``<returntype>``' is any type 3237except :ref:`label <t_label>` and :ref:`metadata <t_metadata>`. 3238 3239:Examples: 3240 3241+---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 3242| ``i32 (i32)`` | function taking an ``i32``, returning an ``i32`` | 3243+---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 3244| ``float (i16, i32 *) *`` | :ref:`Pointer <t_pointer>` to a function that takes an ``i16`` and a :ref:`pointer <t_pointer>` to ``i32``, returning ``float``. | 3245+---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 3246| ``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. | 3247+---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 3248| ``{i32, i32} (i32)`` | A function taking an ``i32``, returning a :ref:`structure <t_struct>` containing two ``i32`` values | 3249+---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 3250 3251.. _t_firstclass: 3252 3253First Class Types 3254----------------- 3255 3256The :ref:`first class <t_firstclass>` types are perhaps the most important. 3257Values of these types are the only ones which can be produced by 3258instructions. 3259 3260.. _t_single_value: 3261 3262Single Value Types 3263^^^^^^^^^^^^^^^^^^ 3264 3265These are the types that are valid in registers from CodeGen's perspective. 3266 3267.. _t_integer: 3268 3269Integer Type 3270"""""""""""" 3271 3272:Overview: 3273 3274The integer type is a very simple type that simply specifies an 3275arbitrary bit width for the integer type desired. Any bit width from 1 3276bit to 2\ :sup:`23`\ -1 (about 8 million) can be specified. 3277 3278:Syntax: 3279 3280:: 3281 3282 iN 3283 3284The number of bits the integer will occupy is specified by the ``N`` 3285value. 3286 3287Examples: 3288********* 3289 3290+----------------+------------------------------------------------+ 3291| ``i1`` | a single-bit integer. | 3292+----------------+------------------------------------------------+ 3293| ``i32`` | a 32-bit integer. | 3294+----------------+------------------------------------------------+ 3295| ``i1942652`` | a really big integer of over 1 million bits. | 3296+----------------+------------------------------------------------+ 3297 3298.. _t_floating: 3299 3300Floating-Point Types 3301"""""""""""""""""""" 3302 3303.. list-table:: 3304 :header-rows: 1 3305 3306 * - Type 3307 - Description 3308 3309 * - ``half`` 3310 - 16-bit floating-point value 3311 3312 * - ``bfloat`` 3313 - 16-bit "brain" floating-point value (7-bit significand). Provides the 3314 same number of exponent bits as ``float``, so that it matches its dynamic 3315 range, but with greatly reduced precision. Used in Intel's AVX-512 BF16 3316 extensions and Arm's ARMv8.6-A extensions, among others. 3317 3318 * - ``float`` 3319 - 32-bit floating-point value 3320 3321 * - ``double`` 3322 - 64-bit floating-point value 3323 3324 * - ``fp128`` 3325 - 128-bit floating-point value (113-bit significand) 3326 3327 * - ``x86_fp80`` 3328 - 80-bit floating-point value (X87) 3329 3330 * - ``ppc_fp128`` 3331 - 128-bit floating-point value (two 64-bits) 3332 3333The binary format of half, float, double, and fp128 correspond to the 3334IEEE-754-2008 specifications for binary16, binary32, binary64, and binary128 3335respectively. 3336 3337X86_amx Type 3338"""""""""""" 3339 3340:Overview: 3341 3342The x86_amx type represents a value held in an AMX tile register on an x86 3343machine. The operations allowed on it are quite limited. Only few intrinsics 3344are allowed: stride load and store, zero and dot product. No instruction is 3345allowed for this type. There are no arguments, arrays, pointers, vectors 3346or constants of this type. 3347 3348:Syntax: 3349 3350:: 3351 3352 x86_amx 3353 3354 3355X86_mmx Type 3356"""""""""""" 3357 3358:Overview: 3359 3360The x86_mmx type represents a value held in an MMX register on an x86 3361machine. The operations allowed on it are quite limited: parameters and 3362return values, load and store, and bitcast. User-specified MMX 3363instructions are represented as intrinsic or asm calls with arguments 3364and/or results of this type. There are no arrays, vectors or constants 3365of this type. 3366 3367:Syntax: 3368 3369:: 3370 3371 x86_mmx 3372 3373 3374.. _t_pointer: 3375 3376Pointer Type 3377"""""""""""" 3378 3379:Overview: 3380 3381The pointer type is used to specify memory locations. Pointers are 3382commonly used to reference objects in memory. 3383 3384Pointer types may have an optional address space attribute defining the 3385numbered address space where the pointed-to object resides. The default 3386address space is number zero. The semantics of non-zero address spaces 3387are target-specific. 3388 3389Note that LLVM does not permit pointers to void (``void*``) nor does it 3390permit pointers to labels (``label*``). Use ``i8*`` instead. 3391 3392LLVM is in the process of transitioning to 3393`opaque pointers <OpaquePointers.html#opaque-pointers>`_. 3394Opaque pointers do not have a pointee type. Rather, instructions 3395interacting through pointers specify the type of the underlying memory 3396they are interacting with. Opaque pointers are still in the process of 3397being worked on and are not complete. 3398 3399:Syntax: 3400 3401:: 3402 3403 <type> * 3404 ptr 3405 3406:Examples: 3407 3408+-------------------------+--------------------------------------------------------------------------------------------------------------+ 3409| ``[4 x i32]*`` | A :ref:`pointer <t_pointer>` to :ref:`array <t_array>` of four ``i32`` values. | 3410+-------------------------+--------------------------------------------------------------------------------------------------------------+ 3411| ``i32 (i32*) *`` | A :ref:`pointer <t_pointer>` to a :ref:`function <t_function>` that takes an ``i32*``, returning an ``i32``. | 3412+-------------------------+--------------------------------------------------------------------------------------------------------------+ 3413| ``i32 addrspace(5)*`` | A :ref:`pointer <t_pointer>` to an ``i32`` value that resides in address space 5. | 3414+-------------------------+--------------------------------------------------------------------------------------------------------------+ 3415| ``ptr`` | An opaque pointer type to a value that resides in address space 0. | 3416+-------------------------+--------------------------------------------------------------------------------------------------------------+ 3417| ``ptr addrspace(5)`` | An opaque pointer type to a value that resides in address space 5. | 3418+-------------------------+--------------------------------------------------------------------------------------------------------------+ 3419 3420.. _t_vector: 3421 3422Vector Type 3423""""""""""" 3424 3425:Overview: 3426 3427A vector type is a simple derived type that represents a vector of 3428elements. Vector types are used when multiple primitive data are 3429operated in parallel using a single instruction (SIMD). A vector type 3430requires a size (number of elements), an underlying primitive data type, 3431and a scalable property to represent vectors where the exact hardware 3432vector length is unknown at compile time. Vector types are considered 3433:ref:`first class <t_firstclass>`. 3434 3435:Memory Layout: 3436 3437In general vector elements are laid out in memory in the same way as 3438:ref:`array types <t_array>`. Such an analogy works fine as long as the vector 3439elements are byte sized. However, when the elements of the vector aren't byte 3440sized it gets a bit more complicated. One way to describe the layout is by 3441describing what happens when a vector such as <N x iM> is bitcasted to an 3442integer type with N*M bits, and then following the rules for storing such an 3443integer to memory. 3444 3445A bitcast from a vector type to a scalar integer type will see the elements 3446being packed together (without padding). The order in which elements are 3447inserted in the integer depends on endianess. For little endian element zero 3448is put in the least significant bits of the integer, and for big endian 3449element zero is put in the most significant bits. 3450 3451Using a vector such as ``<i4 1, i4 2, i4 3, i4 5>`` as an example, together 3452with the analogy that we can replace a vector store by a bitcast followed by 3453an integer store, we get this for big endian: 3454 3455.. code-block:: llvm 3456 3457 %val = bitcast <4 x i4> <i4 1, i4 2, i4 3, i4 5> to i16 3458 3459 ; Bitcasting from a vector to an integral type can be seen as 3460 ; concatenating the values: 3461 ; %val now has the hexadecimal value 0x1235. 3462 3463 store i16 %val, i16* %ptr 3464 3465 ; In memory the content will be (8-bit addressing): 3466 ; 3467 ; [%ptr + 0]: 00010010 (0x12) 3468 ; [%ptr + 1]: 00110101 (0x35) 3469 3470The same example for little endian: 3471 3472.. code-block:: llvm 3473 3474 %val = bitcast <4 x i4> <i4 1, i4 2, i4 3, i4 5> to i16 3475 3476 ; Bitcasting from a vector to an integral type can be seen as 3477 ; concatenating the values: 3478 ; %val now has the hexadecimal value 0x5321. 3479 3480 store i16 %val, i16* %ptr 3481 3482 ; In memory the content will be (8-bit addressing): 3483 ; 3484 ; [%ptr + 0]: 01010011 (0x53) 3485 ; [%ptr + 1]: 00100001 (0x21) 3486 3487When ``<N*M>`` isn't evenly divisible by the byte size the exact memory layout 3488is unspecified (just like it is for an integral type of the same size). This 3489is because different targets could put the padding at different positions when 3490the type size is smaller than the type's store size. 3491 3492:Syntax: 3493 3494:: 3495 3496 < <# elements> x <elementtype> > ; Fixed-length vector 3497 < vscale x <# elements> x <elementtype> > ; Scalable vector 3498 3499The number of elements is a constant integer value larger than 0; 3500elementtype may be any integer, floating-point or pointer type. Vectors 3501of size zero are not allowed. For scalable vectors, the total number of 3502elements is a constant multiple (called vscale) of the specified number 3503of elements; vscale is a positive integer that is unknown at compile time 3504and the same hardware-dependent constant for all scalable vectors at run 3505time. The size of a specific scalable vector type is thus constant within 3506IR, even if the exact size in bytes cannot be determined until run time. 3507 3508:Examples: 3509 3510+------------------------+----------------------------------------------------+ 3511| ``<4 x i32>`` | Vector of 4 32-bit integer values. | 3512+------------------------+----------------------------------------------------+ 3513| ``<8 x float>`` | Vector of 8 32-bit floating-point values. | 3514+------------------------+----------------------------------------------------+ 3515| ``<2 x i64>`` | Vector of 2 64-bit integer values. | 3516+------------------------+----------------------------------------------------+ 3517| ``<4 x i64*>`` | Vector of 4 pointers to 64-bit integer values. | 3518+------------------------+----------------------------------------------------+ 3519| ``<vscale x 4 x i32>`` | Vector with a multiple of 4 32-bit integer values. | 3520+------------------------+----------------------------------------------------+ 3521 3522.. _t_label: 3523 3524Label Type 3525^^^^^^^^^^ 3526 3527:Overview: 3528 3529The label type represents code labels. 3530 3531:Syntax: 3532 3533:: 3534 3535 label 3536 3537.. _t_token: 3538 3539Token Type 3540^^^^^^^^^^ 3541 3542:Overview: 3543 3544The token type is used when a value is associated with an instruction 3545but all uses of the value must not attempt to introspect or obscure it. 3546As such, it is not appropriate to have a :ref:`phi <i_phi>` or 3547:ref:`select <i_select>` of type token. 3548 3549:Syntax: 3550 3551:: 3552 3553 token 3554 3555 3556 3557.. _t_metadata: 3558 3559Metadata Type 3560^^^^^^^^^^^^^ 3561 3562:Overview: 3563 3564The metadata type represents embedded metadata. No derived types may be 3565created from metadata except for :ref:`function <t_function>` arguments. 3566 3567:Syntax: 3568 3569:: 3570 3571 metadata 3572 3573.. _t_aggregate: 3574 3575Aggregate Types 3576^^^^^^^^^^^^^^^ 3577 3578Aggregate Types are a subset of derived types that can contain multiple 3579member types. :ref:`Arrays <t_array>` and :ref:`structs <t_struct>` are 3580aggregate types. :ref:`Vectors <t_vector>` are not considered to be 3581aggregate types. 3582 3583.. _t_array: 3584 3585Array Type 3586"""""""""" 3587 3588:Overview: 3589 3590The array type is a very simple derived type that arranges elements 3591sequentially in memory. The array type requires a size (number of 3592elements) and an underlying data type. 3593 3594:Syntax: 3595 3596:: 3597 3598 [<# elements> x <elementtype>] 3599 3600The number of elements is a constant integer value; ``elementtype`` may 3601be any type with a size. 3602 3603:Examples: 3604 3605+------------------+--------------------------------------+ 3606| ``[40 x i32]`` | Array of 40 32-bit integer values. | 3607+------------------+--------------------------------------+ 3608| ``[41 x i32]`` | Array of 41 32-bit integer values. | 3609+------------------+--------------------------------------+ 3610| ``[4 x i8]`` | Array of 4 8-bit integer values. | 3611+------------------+--------------------------------------+ 3612 3613Here are some examples of multidimensional arrays: 3614 3615+-----------------------------+----------------------------------------------------------+ 3616| ``[3 x [4 x i32]]`` | 3x4 array of 32-bit integer values. | 3617+-----------------------------+----------------------------------------------------------+ 3618| ``[12 x [10 x float]]`` | 12x10 array of single precision floating-point values. | 3619+-----------------------------+----------------------------------------------------------+ 3620| ``[2 x [3 x [4 x i16]]]`` | 2x3x4 array of 16-bit integer values. | 3621+-----------------------------+----------------------------------------------------------+ 3622 3623There is no restriction on indexing beyond the end of the array implied 3624by a static type (though there are restrictions on indexing beyond the 3625bounds of an allocated object in some cases). This means that 3626single-dimension 'variable sized array' addressing can be implemented in 3627LLVM with a zero length array type. An implementation of 'pascal style 3628arrays' in LLVM could use the type "``{ i32, [0 x float]}``", for 3629example. 3630 3631.. _t_struct: 3632 3633Structure Type 3634"""""""""""""" 3635 3636:Overview: 3637 3638The structure type is used to represent a collection of data members 3639together in memory. The elements of a structure may be any type that has 3640a size. 3641 3642Structures in memory are accessed using '``load``' and '``store``' by 3643getting a pointer to a field with the '``getelementptr``' instruction. 3644Structures in registers are accessed using the '``extractvalue``' and 3645'``insertvalue``' instructions. 3646 3647Structures may optionally be "packed" structures, which indicate that 3648the alignment of the struct is one byte, and that there is no padding 3649between the elements. In non-packed structs, padding between field types 3650is inserted as defined by the DataLayout string in the module, which is 3651required to match what the underlying code generator expects. 3652 3653Structures can either be "literal" or "identified". A literal structure 3654is defined inline with other types (e.g. ``{i32, i32}*``) whereas 3655identified types are always defined at the top level with a name. 3656Literal types are uniqued by their contents and can never be recursive 3657or opaque since there is no way to write one. Identified types can be 3658recursive, can be opaqued, and are never uniqued. 3659 3660:Syntax: 3661 3662:: 3663 3664 %T1 = type { <type list> } ; Identified normal struct type 3665 %T2 = type <{ <type list> }> ; Identified packed struct type 3666 3667:Examples: 3668 3669+------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 3670| ``{ i32, i32, i32 }`` | A triple of three ``i32`` values | 3671+------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 3672| ``{ 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``. | 3673+------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 3674| ``<{ i8, i32 }>`` | A packed struct known to be 5 bytes in size. | 3675+------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 3676 3677.. _t_opaque: 3678 3679Opaque Structure Types 3680"""""""""""""""""""""" 3681 3682:Overview: 3683 3684Opaque structure types are used to represent structure types that 3685do not have a body specified. This corresponds (for example) to the C 3686notion of a forward declared structure. They can be named (``%X``) or 3687unnamed (``%52``). 3688 3689:Syntax: 3690 3691:: 3692 3693 %X = type opaque 3694 %52 = type opaque 3695 3696:Examples: 3697 3698+--------------+-------------------+ 3699| ``opaque`` | An opaque type. | 3700+--------------+-------------------+ 3701 3702.. _constants: 3703 3704Constants 3705========= 3706 3707LLVM has several different basic types of constants. This section 3708describes them all and their syntax. 3709 3710Simple Constants 3711---------------- 3712 3713**Boolean constants** 3714 The two strings '``true``' and '``false``' are both valid constants 3715 of the ``i1`` type. 3716**Integer constants** 3717 Standard integers (such as '4') are constants of the 3718 :ref:`integer <t_integer>` type. Negative numbers may be used with 3719 integer types. 3720**Floating-point constants** 3721 Floating-point constants use standard decimal notation (e.g. 3722 123.421), exponential notation (e.g. 1.23421e+2), or a more precise 3723 hexadecimal notation (see below). The assembler requires the exact 3724 decimal value of a floating-point constant. For example, the 3725 assembler accepts 1.25 but rejects 1.3 because 1.3 is a repeating 3726 decimal in binary. Floating-point constants must have a 3727 :ref:`floating-point <t_floating>` type. 3728**Null pointer constants** 3729 The identifier '``null``' is recognized as a null pointer constant 3730 and must be of :ref:`pointer type <t_pointer>`. 3731**Token constants** 3732 The identifier '``none``' is recognized as an empty token constant 3733 and must be of :ref:`token type <t_token>`. 3734 3735The one non-intuitive notation for constants is the hexadecimal form of 3736floating-point constants. For example, the form 3737'``double 0x432ff973cafa8000``' is equivalent to (but harder to read 3738than) '``double 4.5e+15``'. The only time hexadecimal floating-point 3739constants are required (and the only time that they are generated by the 3740disassembler) is when a floating-point constant must be emitted but it 3741cannot be represented as a decimal floating-point number in a reasonable 3742number of digits. For example, NaN's, infinities, and other special 3743values are represented in their IEEE hexadecimal format so that assembly 3744and disassembly do not cause any bits to change in the constants. 3745 3746When using the hexadecimal form, constants of types bfloat, half, float, and 3747double are represented using the 16-digit form shown above (which matches the 3748IEEE754 representation for double); bfloat, half and float values must, however, 3749be exactly representable as bfloat, IEEE 754 half, and IEEE 754 single 3750precision respectively. Hexadecimal format is always used for long double, and 3751there are three forms of long double. The 80-bit format used by x86 is 3752represented as ``0xK`` followed by 20 hexadecimal digits. The 128-bit format 3753used by PowerPC (two adjacent doubles) is represented by ``0xM`` followed by 32 3754hexadecimal digits. The IEEE 128-bit format is represented by ``0xL`` followed 3755by 32 hexadecimal digits. Long doubles will only work if they match the long 3756double format on your target. The IEEE 16-bit format (half precision) is 3757represented by ``0xH`` followed by 4 hexadecimal digits. The bfloat 16-bit 3758format is represented by ``0xR`` followed by 4 hexadecimal digits. All 3759hexadecimal formats are big-endian (sign bit at the left). 3760 3761There are no constants of type x86_mmx and x86_amx. 3762 3763.. _complexconstants: 3764 3765Complex Constants 3766----------------- 3767 3768Complex constants are a (potentially recursive) combination of simple 3769constants and smaller complex constants. 3770 3771**Structure constants** 3772 Structure constants are represented with notation similar to 3773 structure type definitions (a comma separated list of elements, 3774 surrounded by braces (``{}``)). For example: 3775 "``{ i32 4, float 17.0, i32* @G }``", where "``@G``" is declared as 3776 "``@G = external global i32``". Structure constants must have 3777 :ref:`structure type <t_struct>`, and the number and types of elements 3778 must match those specified by the type. 3779**Array constants** 3780 Array constants are represented with notation similar to array type 3781 definitions (a comma separated list of elements, surrounded by 3782 square brackets (``[]``)). For example: 3783 "``[ i32 42, i32 11, i32 74 ]``". Array constants must have 3784 :ref:`array type <t_array>`, and the number and types of elements must 3785 match those specified by the type. As a special case, character array 3786 constants may also be represented as a double-quoted string using the ``c`` 3787 prefix. For example: "``c"Hello World\0A\00"``". 3788**Vector constants** 3789 Vector constants are represented with notation similar to vector 3790 type definitions (a comma separated list of elements, surrounded by 3791 less-than/greater-than's (``<>``)). For example: 3792 "``< i32 42, i32 11, i32 74, i32 100 >``". Vector constants 3793 must have :ref:`vector type <t_vector>`, and the number and types of 3794 elements must match those specified by the type. 3795**Zero initialization** 3796 The string '``zeroinitializer``' can be used to zero initialize a 3797 value to zero of *any* type, including scalar and 3798 :ref:`aggregate <t_aggregate>` types. This is often used to avoid 3799 having to print large zero initializers (e.g. for large arrays) and 3800 is always exactly equivalent to using explicit zero initializers. 3801**Metadata node** 3802 A metadata node is a constant tuple without types. For example: 3803 "``!{!0, !{!2, !0}, !"test"}``". Metadata can reference constant values, 3804 for example: "``!{!0, i32 0, i8* @global, i64 (i64)* @function, !"str"}``". 3805 Unlike other typed constants that are meant to be interpreted as part of 3806 the instruction stream, metadata is a place to attach additional 3807 information such as debug info. 3808 3809Global Variable and Function Addresses 3810-------------------------------------- 3811 3812The addresses of :ref:`global variables <globalvars>` and 3813:ref:`functions <functionstructure>` are always implicitly valid 3814(link-time) constants. These constants are explicitly referenced when 3815the :ref:`identifier for the global <identifiers>` is used and always have 3816:ref:`pointer <t_pointer>` type. For example, the following is a legal LLVM 3817file: 3818 3819.. code-block:: llvm 3820 3821 @X = global i32 17 3822 @Y = global i32 42 3823 @Z = global [2 x i32*] [ i32* @X, i32* @Y ] 3824 3825.. _undefvalues: 3826 3827Undefined Values 3828---------------- 3829 3830The string '``undef``' can be used anywhere a constant is expected, and 3831indicates that the user of the value may receive an unspecified 3832bit-pattern. Undefined values may be of any type (other than '``label``' 3833or '``void``') and be used anywhere a constant is permitted. 3834 3835Undefined values are useful because they indicate to the compiler that 3836the program is well defined no matter what value is used. This gives the 3837compiler more freedom to optimize. Here are some examples of 3838(potentially surprising) transformations that are valid (in pseudo IR): 3839 3840.. code-block:: llvm 3841 3842 %A = add %X, undef 3843 %B = sub %X, undef 3844 %C = xor %X, undef 3845 Safe: 3846 %A = undef 3847 %B = undef 3848 %C = undef 3849 3850This is safe because all of the output bits are affected by the undef 3851bits. Any output bit can have a zero or one depending on the input bits. 3852 3853.. code-block:: llvm 3854 3855 %A = or %X, undef 3856 %B = and %X, undef 3857 Safe: 3858 %A = -1 3859 %B = 0 3860 Safe: 3861 %A = %X ;; By choosing undef as 0 3862 %B = %X ;; By choosing undef as -1 3863 Unsafe: 3864 %A = undef 3865 %B = undef 3866 3867These logical operations have bits that are not always affected by the 3868input. For example, if ``%X`` has a zero bit, then the output of the 3869'``and``' operation will always be a zero for that bit, no matter what 3870the corresponding bit from the '``undef``' is. As such, it is unsafe to 3871optimize or assume that the result of the '``and``' is '``undef``'. 3872However, it is safe to assume that all bits of the '``undef``' could be 38730, and optimize the '``and``' to 0. Likewise, it is safe to assume that 3874all the bits of the '``undef``' operand to the '``or``' could be set, 3875allowing the '``or``' to be folded to -1. 3876 3877.. code-block:: llvm 3878 3879 %A = select undef, %X, %Y 3880 %B = select undef, 42, %Y 3881 %C = select %X, %Y, undef 3882 Safe: 3883 %A = %X (or %Y) 3884 %B = 42 (or %Y) 3885 %C = %Y 3886 Unsafe: 3887 %A = undef 3888 %B = undef 3889 %C = undef 3890 3891This set of examples shows that undefined '``select``' (and conditional 3892branch) conditions can go *either way*, but they have to come from one 3893of the two operands. In the ``%A`` example, if ``%X`` and ``%Y`` were 3894both known to have a clear low bit, then ``%A`` would have to have a 3895cleared low bit. However, in the ``%C`` example, the optimizer is 3896allowed to assume that the '``undef``' operand could be the same as 3897``%Y``, allowing the whole '``select``' to be eliminated. 3898 3899.. code-block:: llvm 3900 3901 %A = xor undef, undef 3902 3903 %B = undef 3904 %C = xor %B, %B 3905 3906 %D = undef 3907 %E = icmp slt %D, 4 3908 %F = icmp gte %D, 4 3909 3910 Safe: 3911 %A = undef 3912 %B = undef 3913 %C = undef 3914 %D = undef 3915 %E = undef 3916 %F = undef 3917 3918This example points out that two '``undef``' operands are not 3919necessarily the same. This can be surprising to people (and also matches 3920C semantics) where they assume that "``X^X``" is always zero, even if 3921``X`` is undefined. This isn't true for a number of reasons, but the 3922short answer is that an '``undef``' "variable" can arbitrarily change 3923its value over its "live range". This is true because the variable 3924doesn't actually *have a live range*. Instead, the value is logically 3925read from arbitrary registers that happen to be around when needed, so 3926the value is not necessarily consistent over time. In fact, ``%A`` and 3927``%C`` need to have the same semantics or the core LLVM "replace all 3928uses with" concept would not hold. 3929 3930To ensure all uses of a given register observe the same value (even if 3931'``undef``'), the :ref:`freeze instruction <i_freeze>` can be used. 3932 3933.. code-block:: llvm 3934 3935 %A = sdiv undef, %X 3936 %B = sdiv %X, undef 3937 Safe: 3938 %A = 0 3939 b: unreachable 3940 3941These examples show the crucial difference between an *undefined value* 3942and *undefined behavior*. An undefined value (like '``undef``') is 3943allowed to have an arbitrary bit-pattern. This means that the ``%A`` 3944operation can be constant folded to '``0``', because the '``undef``' 3945could be zero, and zero divided by any value is zero. 3946However, in the second example, we can make a more aggressive 3947assumption: because the ``undef`` is allowed to be an arbitrary value, 3948we are allowed to assume that it could be zero. Since a divide by zero 3949has *undefined behavior*, we are allowed to assume that the operation 3950does not execute at all. This allows us to delete the divide and all 3951code after it. Because the undefined operation "can't happen", the 3952optimizer can assume that it occurs in dead code. 3953 3954.. code-block:: text 3955 3956 a: store undef -> %X 3957 b: store %X -> undef 3958 Safe: 3959 a: <deleted> 3960 b: unreachable 3961 3962A store *of* an undefined value can be assumed to not have any effect; 3963we can assume that the value is overwritten with bits that happen to 3964match what was already there. However, a store *to* an undefined 3965location could clobber arbitrary memory, therefore, it has undefined 3966behavior. 3967 3968Branching on an undefined value is undefined behavior. 3969This explains optimizations that depend on branch conditions to construct 3970predicates, such as Correlated Value Propagation and Global Value Numbering. 3971In case of switch instruction, the branch condition should be frozen, otherwise 3972it is undefined behavior. 3973 3974.. code-block:: llvm 3975 3976 Unsafe: 3977 br undef, BB1, BB2 ; UB 3978 3979 %X = and i32 undef, 255 3980 switch %X, label %ret [ .. ] ; UB 3981 3982 store undef, i8* %ptr 3983 %X = load i8* %ptr ; %X is undef 3984 switch i8 %X, label %ret [ .. ] ; UB 3985 3986 Safe: 3987 %X = or i8 undef, 255 ; always 255 3988 switch i8 %X, label %ret [ .. ] ; Well-defined 3989 3990 %X = freeze i1 undef 3991 br %X, BB1, BB2 ; Well-defined (non-deterministic jump) 3992 3993 3994This is also consistent with the behavior of MemorySanitizer. 3995MemorySanitizer, detector of uses of uninitialized memory, 3996defines a branch with condition that depends on an undef value (or 3997certain other values, like e.g. a result of a load from heap-allocated 3998memory that has never been stored to) to have an externally visible 3999side effect. For this reason functions with *sanitize_memory* 4000attribute are not allowed to produce such branches "out of thin 4001air". More strictly, an optimization that inserts a conditional branch 4002is only valid if in all executions where the branch condition has at 4003least one undefined bit, the same branch condition is evaluated in the 4004input IR as well. 4005 4006.. _poisonvalues: 4007 4008Poison Values 4009------------- 4010 4011A poison value is a result of an erroneous operation. 4012In order to facilitate speculative execution, many instructions do not 4013invoke immediate undefined behavior when provided with illegal operands, 4014and return a poison value instead. 4015The string '``poison``' can be used anywhere a constant is expected, and 4016operations such as :ref:`add <i_add>` with the ``nsw`` flag can produce 4017a poison value. 4018 4019Poison value behavior is defined in terms of value *dependence*: 4020 4021- Values other than :ref:`phi <i_phi>` nodes, :ref:`select <i_select>`, and 4022 :ref:`freeze <i_freeze>` instructions depend on their operands. 4023- :ref:`Phi <i_phi>` nodes depend on the operand corresponding to 4024 their dynamic predecessor basic block. 4025- :ref:`Select <i_select>` instructions depend on their condition operand and 4026 their selected operand. 4027- Function arguments depend on the corresponding actual argument values 4028 in the dynamic callers of their functions. 4029- :ref:`Call <i_call>` instructions depend on the :ref:`ret <i_ret>` 4030 instructions that dynamically transfer control back to them. 4031- :ref:`Invoke <i_invoke>` instructions depend on the 4032 :ref:`ret <i_ret>`, :ref:`resume <i_resume>`, or exception-throwing 4033 call instructions that dynamically transfer control back to them. 4034- Non-volatile loads and stores depend on the most recent stores to all 4035 of the referenced memory addresses, following the order in the IR 4036 (including loads and stores implied by intrinsics such as 4037 :ref:`@llvm.memcpy <int_memcpy>`.) 4038- An instruction with externally visible side effects depends on the 4039 most recent preceding instruction with externally visible side 4040 effects, following the order in the IR. (This includes :ref:`volatile 4041 operations <volatile>`.) 4042- An instruction *control-depends* on a :ref:`terminator 4043 instruction <terminators>` if the terminator instruction has 4044 multiple successors and the instruction is always executed when 4045 control transfers to one of the successors, and may not be executed 4046 when control is transferred to another. 4047- Additionally, an instruction also *control-depends* on a terminator 4048 instruction if the set of instructions it otherwise depends on would 4049 be different if the terminator had transferred control to a different 4050 successor. 4051- Dependence is transitive. 4052- Vector elements may be independently poisoned. Therefore, transforms 4053 on instructions such as shufflevector must be careful to propagate 4054 poison across values or elements only as allowed by the original code. 4055 4056An instruction that *depends* on a poison value, produces a poison value 4057itself. A poison value may be relaxed into an 4058:ref:`undef value <undefvalues>`, which takes an arbitrary bit-pattern. 4059Propagation of poison can be stopped with the 4060:ref:`freeze instruction <i_freeze>`. 4061 4062This means that immediate undefined behavior occurs if a poison value is 4063used as an instruction operand that has any values that trigger undefined 4064behavior. Notably this includes (but is not limited to): 4065 4066- The pointer operand of a :ref:`load <i_load>`, :ref:`store <i_store>` or 4067 any other pointer dereferencing instruction (independent of address 4068 space). 4069- The divisor operand of a ``udiv``, ``sdiv``, ``urem`` or ``srem`` 4070 instruction. 4071- The condition operand of a :ref:`br <i_br>` instruction. 4072- The callee operand of a :ref:`call <i_call>` or :ref:`invoke <i_invoke>` 4073 instruction. 4074- The parameter operand of a :ref:`call <i_call>` or :ref:`invoke <i_invoke>` 4075 instruction, when the function or invoking call site has a ``noundef`` 4076 attribute in the corresponding position. 4077- The operand of a :ref:`ret <i_ret>` instruction if the function or invoking 4078 call site has a `noundef` attribute in the return value position. 4079 4080Here are some examples: 4081 4082.. code-block:: llvm 4083 4084 entry: 4085 %poison = sub nuw i32 0, 1 ; Results in a poison value. 4086 %poison2 = sub i32 poison, 1 ; Also results in a poison value. 4087 %still_poison = and i32 %poison, 0 ; 0, but also poison. 4088 %poison_yet_again = getelementptr i32, i32* @h, i32 %still_poison 4089 store i32 0, i32* %poison_yet_again ; Undefined behavior due to 4090 ; store to poison. 4091 4092 store i32 %poison, i32* @g ; Poison value stored to memory. 4093 %poison3 = load i32, i32* @g ; Poison value loaded back from memory. 4094 4095 %narrowaddr = bitcast i32* @g to i16* 4096 %wideaddr = bitcast i32* @g to i64* 4097 %poison4 = load i16, i16* %narrowaddr ; Returns a poison value. 4098 %poison5 = load i64, i64* %wideaddr ; Returns a poison value. 4099 4100 %cmp = icmp slt i32 %poison, 0 ; Returns a poison value. 4101 br i1 %cmp, label %end, label %end ; undefined behavior 4102 4103 end: 4104 4105.. _welldefinedvalues: 4106 4107Well-Defined Values 4108------------------- 4109 4110Given a program execution, a value is *well defined* if the value does not 4111have an undef bit and is not poison in the execution. 4112An aggregate value or vector is well defined if its elements are well defined. 4113The padding of an aggregate isn't considered, since it isn't visible 4114without storing it into memory and loading it with a different type. 4115 4116A constant of a :ref:`single value <t_single_value>`, non-vector type is well 4117defined if it is neither '``undef``' constant nor '``poison``' constant. 4118The result of :ref:`freeze instruction <i_freeze>` is well defined regardless 4119of its operand. 4120 4121.. _blockaddress: 4122 4123Addresses of Basic Blocks 4124------------------------- 4125 4126``blockaddress(@function, %block)`` 4127 4128The '``blockaddress``' constant computes the address of the specified 4129basic block in the specified function. 4130 4131It always has an ``i8 addrspace(P)*`` type, where ``P`` is the address space 4132of the function containing ``%block`` (usually ``addrspace(0)``). 4133 4134Taking the address of the entry block is illegal. 4135 4136This value only has defined behavior when used as an operand to the 4137':ref:`indirectbr <i_indirectbr>`' or ':ref:`callbr <i_callbr>`'instruction, or 4138for comparisons against null. Pointer equality tests between labels addresses 4139results in undefined behavior --- though, again, comparison against null is ok, 4140and no label is equal to the null pointer. This may be passed around as an 4141opaque pointer sized value as long as the bits are not inspected. This 4142allows ``ptrtoint`` and arithmetic to be performed on these values so 4143long as the original value is reconstituted before the ``indirectbr`` or 4144``callbr`` instruction. 4145 4146Finally, some targets may provide defined semantics when using the value 4147as the operand to an inline assembly, but that is target specific. 4148 4149.. _dso_local_equivalent: 4150 4151DSO Local Equivalent 4152-------------------- 4153 4154``dso_local_equivalent @func`` 4155 4156A '``dso_local_equivalent``' constant represents a function which is 4157functionally equivalent to a given function, but is always defined in the 4158current linkage unit. The resulting pointer has the same type as the underlying 4159function. The resulting pointer is permitted, but not required, to be different 4160from a pointer to the function, and it may have different values in different 4161translation units. 4162 4163The target function may not have ``extern_weak`` linkage. 4164 4165``dso_local_equivalent`` can be implemented as such: 4166 4167- If the function has local linkage, hidden visibility, or is 4168 ``dso_local``, ``dso_local_equivalent`` can be implemented as simply a pointer 4169 to the function. 4170- ``dso_local_equivalent`` can be implemented with a stub that tail-calls the 4171 function. Many targets support relocations that resolve at link time to either 4172 a function or a stub for it, depending on if the function is defined within the 4173 linkage unit; LLVM will use this when available. (This is commonly called a 4174 "PLT stub".) On other targets, the stub may need to be emitted explicitly. 4175 4176This can be used wherever a ``dso_local`` instance of a function is needed without 4177needing to explicitly make the original function ``dso_local``. An instance where 4178this can be used is for static offset calculations between a function and some other 4179``dso_local`` symbol. This is especially useful for the Relative VTables C++ ABI, 4180where dynamic relocations for function pointers in VTables can be replaced with 4181static relocations for offsets between the VTable and virtual functions which 4182may not be ``dso_local``. 4183 4184This is currently only supported for ELF binary formats. 4185 4186.. _constantexprs: 4187 4188Constant Expressions 4189-------------------- 4190 4191Constant expressions are used to allow expressions involving other 4192constants to be used as constants. Constant expressions may be of any 4193:ref:`first class <t_firstclass>` type and may involve any LLVM operation 4194that does not have side effects (e.g. load and call are not supported). 4195The following is the syntax for constant expressions: 4196 4197``trunc (CST to TYPE)`` 4198 Perform the :ref:`trunc operation <i_trunc>` on constants. 4199``zext (CST to TYPE)`` 4200 Perform the :ref:`zext operation <i_zext>` on constants. 4201``sext (CST to TYPE)`` 4202 Perform the :ref:`sext operation <i_sext>` on constants. 4203``fptrunc (CST to TYPE)`` 4204 Truncate a floating-point constant to another floating-point type. 4205 The size of CST must be larger than the size of TYPE. Both types 4206 must be floating-point. 4207``fpext (CST to TYPE)`` 4208 Floating-point extend a constant to another type. The size of CST 4209 must be smaller or equal to the size of TYPE. Both types must be 4210 floating-point. 4211``fptoui (CST to TYPE)`` 4212 Convert a floating-point constant to the corresponding unsigned 4213 integer constant. TYPE must be a scalar or vector integer type. CST 4214 must be of scalar or vector floating-point type. Both CST and TYPE 4215 must be scalars, or vectors of the same number of elements. If the 4216 value won't fit in the integer type, the result is a 4217 :ref:`poison value <poisonvalues>`. 4218``fptosi (CST to TYPE)`` 4219 Convert a floating-point constant to the corresponding signed 4220 integer constant. TYPE must be a scalar or vector integer type. CST 4221 must be of scalar or vector floating-point type. Both CST and TYPE 4222 must be scalars, or vectors of the same number of elements. If the 4223 value won't fit in the integer type, the result is a 4224 :ref:`poison value <poisonvalues>`. 4225``uitofp (CST to TYPE)`` 4226 Convert an unsigned integer constant to the corresponding 4227 floating-point constant. TYPE must be a scalar or vector floating-point 4228 type. CST must be of scalar or vector integer type. Both CST and TYPE must 4229 be scalars, or vectors of the same number of elements. 4230``sitofp (CST to TYPE)`` 4231 Convert a signed integer constant to the corresponding floating-point 4232 constant. TYPE must be a scalar or vector floating-point type. 4233 CST must be of scalar or vector integer type. Both CST and TYPE must 4234 be scalars, or vectors of the same number of elements. 4235``ptrtoint (CST to TYPE)`` 4236 Perform the :ref:`ptrtoint operation <i_ptrtoint>` on constants. 4237``inttoptr (CST to TYPE)`` 4238 Perform the :ref:`inttoptr operation <i_inttoptr>` on constants. 4239 This one is *really* dangerous! 4240``bitcast (CST to TYPE)`` 4241 Convert a constant, CST, to another TYPE. 4242 The constraints of the operands are the same as those for the 4243 :ref:`bitcast instruction <i_bitcast>`. 4244``addrspacecast (CST to TYPE)`` 4245 Convert a constant pointer or constant vector of pointer, CST, to another 4246 TYPE in a different address space. The constraints of the operands are the 4247 same as those for the :ref:`addrspacecast instruction <i_addrspacecast>`. 4248``getelementptr (TY, CSTPTR, IDX0, IDX1, ...)``, ``getelementptr inbounds (TY, CSTPTR, IDX0, IDX1, ...)`` 4249 Perform the :ref:`getelementptr operation <i_getelementptr>` on 4250 constants. As with the :ref:`getelementptr <i_getelementptr>` 4251 instruction, the index list may have one or more indexes, which are 4252 required to make sense for the type of "pointer to TY". 4253``select (COND, VAL1, VAL2)`` 4254 Perform the :ref:`select operation <i_select>` on constants. 4255``icmp COND (VAL1, VAL2)`` 4256 Perform the :ref:`icmp operation <i_icmp>` on constants. 4257``fcmp COND (VAL1, VAL2)`` 4258 Perform the :ref:`fcmp operation <i_fcmp>` on constants. 4259``extractelement (VAL, IDX)`` 4260 Perform the :ref:`extractelement operation <i_extractelement>` on 4261 constants. 4262``insertelement (VAL, ELT, IDX)`` 4263 Perform the :ref:`insertelement operation <i_insertelement>` on 4264 constants. 4265``shufflevector (VEC1, VEC2, IDXMASK)`` 4266 Perform the :ref:`shufflevector operation <i_shufflevector>` on 4267 constants. 4268``extractvalue (VAL, IDX0, IDX1, ...)`` 4269 Perform the :ref:`extractvalue operation <i_extractvalue>` on 4270 constants. The index list is interpreted in a similar manner as 4271 indices in a ':ref:`getelementptr <i_getelementptr>`' operation. At 4272 least one index value must be specified. 4273``insertvalue (VAL, ELT, IDX0, IDX1, ...)`` 4274 Perform the :ref:`insertvalue operation <i_insertvalue>` on constants. 4275 The index list is interpreted in a similar manner as indices in a 4276 ':ref:`getelementptr <i_getelementptr>`' operation. At least one index 4277 value must be specified. 4278``OPCODE (LHS, RHS)`` 4279 Perform the specified operation of the LHS and RHS constants. OPCODE 4280 may be any of the :ref:`binary <binaryops>` or :ref:`bitwise 4281 binary <bitwiseops>` operations. The constraints on operands are 4282 the same as those for the corresponding instruction (e.g. no bitwise 4283 operations on floating-point values are allowed). 4284 4285Other Values 4286============ 4287 4288.. _inlineasmexprs: 4289 4290Inline Assembler Expressions 4291---------------------------- 4292 4293LLVM supports inline assembler expressions (as opposed to :ref:`Module-Level 4294Inline Assembly <moduleasm>`) through the use of a special value. This value 4295represents the inline assembler as a template string (containing the 4296instructions to emit), a list of operand constraints (stored as a string), a 4297flag that indicates whether or not the inline asm expression has side effects, 4298and a flag indicating whether the function containing the asm needs to align its 4299stack conservatively. 4300 4301The template string supports argument substitution of the operands using "``$``" 4302followed by a number, to indicate substitution of the given register/memory 4303location, as specified by the constraint string. "``${NUM:MODIFIER}``" may also 4304be used, where ``MODIFIER`` is a target-specific annotation for how to print the 4305operand (See :ref:`inline-asm-modifiers`). 4306 4307A literal "``$``" may be included by using "``$$``" in the template. To include 4308other special characters into the output, the usual "``\XX``" escapes may be 4309used, just as in other strings. Note that after template substitution, the 4310resulting assembly string is parsed by LLVM's integrated assembler unless it is 4311disabled -- even when emitting a ``.s`` file -- and thus must contain assembly 4312syntax known to LLVM. 4313 4314LLVM also supports a few more substitutions useful for writing inline assembly: 4315 4316- ``${:uid}``: Expands to a decimal integer unique to this inline assembly blob. 4317 This substitution is useful when declaring a local label. Many standard 4318 compiler optimizations, such as inlining, may duplicate an inline asm blob. 4319 Adding a blob-unique identifier ensures that the two labels will not conflict 4320 during assembly. This is used to implement `GCC's %= special format 4321 string <https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html>`_. 4322- ``${:comment}``: Expands to the comment character of the current target's 4323 assembly dialect. This is usually ``#``, but many targets use other strings, 4324 such as ``;``, ``//``, or ``!``. 4325- ``${:private}``: Expands to the assembler private label prefix. Labels with 4326 this prefix will not appear in the symbol table of the assembled object. 4327 Typically the prefix is ``L``, but targets may use other strings. ``.L`` is 4328 relatively popular. 4329 4330LLVM's support for inline asm is modeled closely on the requirements of Clang's 4331GCC-compatible inline-asm support. Thus, the feature-set and the constraint and 4332modifier codes listed here are similar or identical to those in GCC's inline asm 4333support. However, to be clear, the syntax of the template and constraint strings 4334described here is *not* the same as the syntax accepted by GCC and Clang, and, 4335while most constraint letters are passed through as-is by Clang, some get 4336translated to other codes when converting from the C source to the LLVM 4337assembly. 4338 4339An example inline assembler expression is: 4340 4341.. code-block:: llvm 4342 4343 i32 (i32) asm "bswap $0", "=r,r" 4344 4345Inline assembler expressions may **only** be used as the callee operand 4346of a :ref:`call <i_call>` or an :ref:`invoke <i_invoke>` instruction. 4347Thus, typically we have: 4348 4349.. code-block:: llvm 4350 4351 %X = call i32 asm "bswap $0", "=r,r"(i32 %Y) 4352 4353Inline asms with side effects not visible in the constraint list must be 4354marked as having side effects. This is done through the use of the 4355'``sideeffect``' keyword, like so: 4356 4357.. code-block:: llvm 4358 4359 call void asm sideeffect "eieio", ""() 4360 4361In some cases inline asms will contain code that will not work unless 4362the stack is aligned in some way, such as calls or SSE instructions on 4363x86, yet will not contain code that does that alignment within the asm. 4364The compiler should make conservative assumptions about what the asm 4365might contain and should generate its usual stack alignment code in the 4366prologue if the '``alignstack``' keyword is present: 4367 4368.. code-block:: llvm 4369 4370 call void asm alignstack "eieio", ""() 4371 4372Inline asms also support using non-standard assembly dialects. The 4373assumed dialect is ATT. When the '``inteldialect``' keyword is present, 4374the inline asm is using the Intel dialect. Currently, ATT and Intel are 4375the only supported dialects. An example is: 4376 4377.. code-block:: llvm 4378 4379 call void asm inteldialect "eieio", ""() 4380 4381In the case that the inline asm might unwind the stack, 4382the '``unwind``' keyword must be used, so that the compiler emits 4383unwinding information: 4384 4385.. code-block:: llvm 4386 4387 call void asm unwind "call func", ""() 4388 4389If the inline asm unwinds the stack and isn't marked with 4390the '``unwind``' keyword, the behavior is undefined. 4391 4392If multiple keywords appear, the '``sideeffect``' keyword must come 4393first, the '``alignstack``' keyword second, the '``inteldialect``' keyword 4394third and the '``unwind``' keyword last. 4395 4396Inline Asm Constraint String 4397^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 4398 4399The constraint list is a comma-separated string, each element containing one or 4400more constraint codes. 4401 4402For each element in the constraint list an appropriate register or memory 4403operand will be chosen, and it will be made available to assembly template 4404string expansion as ``$0`` for the first constraint in the list, ``$1`` for the 4405second, etc. 4406 4407There are three different types of constraints, which are distinguished by a 4408prefix symbol in front of the constraint code: Output, Input, and Clobber. The 4409constraints must always be given in that order: outputs first, then inputs, then 4410clobbers. They cannot be intermingled. 4411 4412There are also three different categories of constraint codes: 4413 4414- Register constraint. This is either a register class, or a fixed physical 4415 register. This kind of constraint will allocate a register, and if necessary, 4416 bitcast the argument or result to the appropriate type. 4417- Memory constraint. This kind of constraint is for use with an instruction 4418 taking a memory operand. Different constraints allow for different addressing 4419 modes used by the target. 4420- Immediate value constraint. This kind of constraint is for an integer or other 4421 immediate value which can be rendered directly into an instruction. The 4422 various target-specific constraints allow the selection of a value in the 4423 proper range for the instruction you wish to use it with. 4424 4425Output constraints 4426"""""""""""""""""" 4427 4428Output constraints are specified by an "``=``" prefix (e.g. "``=r``"). This 4429indicates that the assembly will write to this operand, and the operand will 4430then be made available as a return value of the ``asm`` expression. Output 4431constraints do not consume an argument from the call instruction. (Except, see 4432below about indirect outputs). 4433 4434Normally, it is expected that no output locations are written to by the assembly 4435expression until *all* of the inputs have been read. As such, LLVM may assign 4436the same register to an output and an input. If this is not safe (e.g. if the 4437assembly contains two instructions, where the first writes to one output, and 4438the second reads an input and writes to a second output), then the "``&``" 4439modifier must be used (e.g. "``=&r``") to specify that the output is an 4440"early-clobber" output. Marking an output as "early-clobber" ensures that LLVM 4441will not use the same register for any inputs (other than an input tied to this 4442output). 4443 4444Input constraints 4445""""""""""""""""" 4446 4447Input constraints do not have a prefix -- just the constraint codes. Each input 4448constraint will consume one argument from the call instruction. It is not 4449permitted for the asm to write to any input register or memory location (unless 4450that input is tied to an output). Note also that multiple inputs may all be 4451assigned to the same register, if LLVM can determine that they necessarily all 4452contain the same value. 4453 4454Instead of providing a Constraint Code, input constraints may also "tie" 4455themselves to an output constraint, by providing an integer as the constraint 4456string. Tied inputs still consume an argument from the call instruction, and 4457take up a position in the asm template numbering as is usual -- they will simply 4458be constrained to always use the same register as the output they've been tied 4459to. For example, a constraint string of "``=r,0``" says to assign a register for 4460output, and use that register as an input as well (it being the 0'th 4461constraint). 4462 4463It is permitted to tie an input to an "early-clobber" output. In that case, no 4464*other* input may share the same register as the input tied to the early-clobber 4465(even when the other input has the same value). 4466 4467You may only tie an input to an output which has a register constraint, not a 4468memory constraint. Only a single input may be tied to an output. 4469 4470There is also an "interesting" feature which deserves a bit of explanation: if a 4471register class constraint allocates a register which is too small for the value 4472type operand provided as input, the input value will be split into multiple 4473registers, and all of them passed to the inline asm. 4474 4475However, this feature is often not as useful as you might think. 4476 4477Firstly, the registers are *not* guaranteed to be consecutive. So, on those 4478architectures that have instructions which operate on multiple consecutive 4479instructions, this is not an appropriate way to support them. (e.g. the 32-bit 4480SparcV8 has a 64-bit load, which instruction takes a single 32-bit register. The 4481hardware then loads into both the named register, and the next register. This 4482feature of inline asm would not be useful to support that.) 4483 4484A few of the targets provide a template string modifier allowing explicit access 4485to the second register of a two-register operand (e.g. MIPS ``L``, ``M``, and 4486``D``). On such an architecture, you can actually access the second allocated 4487register (yet, still, not any subsequent ones). But, in that case, you're still 4488probably better off simply splitting the value into two separate operands, for 4489clarity. (e.g. see the description of the ``A`` constraint on X86, which, 4490despite existing only for use with this feature, is not really a good idea to 4491use) 4492 4493Indirect inputs and outputs 4494""""""""""""""""""""""""""" 4495 4496Indirect output or input constraints can be specified by the "``*``" modifier 4497(which goes after the "``=``" in case of an output). This indicates that the asm 4498will write to or read from the contents of an *address* provided as an input 4499argument. (Note that in this way, indirect outputs act more like an *input* than 4500an output: just like an input, they consume an argument of the call expression, 4501rather than producing a return value. An indirect output constraint is an 4502"output" only in that the asm is expected to write to the contents of the input 4503memory location, instead of just read from it). 4504 4505This is most typically used for memory constraint, e.g. "``=*m``", to pass the 4506address of a variable as a value. 4507 4508It is also possible to use an indirect *register* constraint, but only on output 4509(e.g. "``=*r``"). This will cause LLVM to allocate a register for an output 4510value normally, and then, separately emit a store to the address provided as 4511input, after the provided inline asm. (It's not clear what value this 4512functionality provides, compared to writing the store explicitly after the asm 4513statement, and it can only produce worse code, since it bypasses many 4514optimization passes. I would recommend not using it.) 4515 4516 4517Clobber constraints 4518""""""""""""""""""" 4519 4520A clobber constraint is indicated by a "``~``" prefix. A clobber does not 4521consume an input operand, nor generate an output. Clobbers cannot use any of the 4522general constraint code letters -- they may use only explicit register 4523constraints, e.g. "``~{eax}``". The one exception is that a clobber string of 4524"``~{memory}``" indicates that the assembly writes to arbitrary undeclared 4525memory locations -- not only the memory pointed to by a declared indirect 4526output. 4527 4528Note that clobbering named registers that are also present in output 4529constraints is not legal. 4530 4531 4532Constraint Codes 4533"""""""""""""""" 4534After a potential prefix comes constraint code, or codes. 4535 4536A Constraint Code is either a single letter (e.g. "``r``"), a "``^``" character 4537followed by two letters (e.g. "``^wc``"), or "``{``" register-name "``}``" 4538(e.g. "``{eax}``"). 4539 4540The one and two letter constraint codes are typically chosen to be the same as 4541GCC's constraint codes. 4542 4543A single constraint may include one or more than constraint code in it, leaving 4544it up to LLVM to choose which one to use. This is included mainly for 4545compatibility with the translation of GCC inline asm coming from clang. 4546 4547There are two ways to specify alternatives, and either or both may be used in an 4548inline asm constraint list: 4549 45501) Append the codes to each other, making a constraint code set. E.g. "``im``" 4551 or "``{eax}m``". This means "choose any of the options in the set". The 4552 choice of constraint is made independently for each constraint in the 4553 constraint list. 4554 45552) Use "``|``" between constraint code sets, creating alternatives. Every 4556 constraint in the constraint list must have the same number of alternative 4557 sets. With this syntax, the same alternative in *all* of the items in the 4558 constraint list will be chosen together. 4559 4560Putting those together, you might have a two operand constraint string like 4561``"rm|r,ri|rm"``. This indicates that if operand 0 is ``r`` or ``m``, then 4562operand 1 may be one of ``r`` or ``i``. If operand 0 is ``r``, then operand 1 4563may be one of ``r`` or ``m``. But, operand 0 and 1 cannot both be of type m. 4564 4565However, the use of either of the alternatives features is *NOT* recommended, as 4566LLVM is not able to make an intelligent choice about which one to use. (At the 4567point it currently needs to choose, not enough information is available to do so 4568in a smart way.) Thus, it simply tries to make a choice that's most likely to 4569compile, not one that will be optimal performance. (e.g., given "``rm``", it'll 4570always choose to use memory, not registers). And, if given multiple registers, 4571or multiple register classes, it will simply choose the first one. (In fact, it 4572doesn't currently even ensure explicitly specified physical registers are 4573unique, so specifying multiple physical registers as alternatives, like 4574``{r11}{r12},{r11}{r12}``, will assign r11 to both operands, not at all what was 4575intended.) 4576 4577Supported Constraint Code List 4578"""""""""""""""""""""""""""""" 4579 4580The constraint codes are, in general, expected to behave the same way they do in 4581GCC. LLVM's support is often implemented on an 'as-needed' basis, to support C 4582inline asm code which was supported by GCC. A mismatch in behavior between LLVM 4583and GCC likely indicates a bug in LLVM. 4584 4585Some constraint codes are typically supported by all targets: 4586 4587- ``r``: A register in the target's general purpose register class. 4588- ``m``: A memory address operand. It is target-specific what addressing modes 4589 are supported, typical examples are register, or register + register offset, 4590 or register + immediate offset (of some target-specific size). 4591- ``i``: An integer constant (of target-specific width). Allows either a simple 4592 immediate, or a relocatable value. 4593- ``n``: An integer constant -- *not* including relocatable values. 4594- ``s``: An integer constant, but allowing *only* relocatable values. 4595- ``X``: Allows an operand of any kind, no constraint whatsoever. Typically 4596 useful to pass a label for an asm branch or call. 4597 4598 .. FIXME: but that surely isn't actually okay to jump out of an asm 4599 block without telling llvm about the control transfer???) 4600 4601- ``{register-name}``: Requires exactly the named physical register. 4602 4603Other constraints are target-specific: 4604 4605AArch64: 4606 4607- ``z``: An immediate integer 0. Outputs ``WZR`` or ``XZR``, as appropriate. 4608- ``I``: An immediate integer valid for an ``ADD`` or ``SUB`` instruction, 4609 i.e. 0 to 4095 with optional shift by 12. 4610- ``J``: An immediate integer that, when negated, is valid for an ``ADD`` or 4611 ``SUB`` instruction, i.e. -1 to -4095 with optional left shift by 12. 4612- ``K``: An immediate integer that is valid for the 'bitmask immediate 32' of a 4613 logical instruction like ``AND``, ``EOR``, or ``ORR`` with a 32-bit register. 4614- ``L``: An immediate integer that is valid for the 'bitmask immediate 64' of a 4615 logical instruction like ``AND``, ``EOR``, or ``ORR`` with a 64-bit register. 4616- ``M``: An immediate integer for use with the ``MOV`` assembly alias on a 4617 32-bit register. This is a superset of ``K``: in addition to the bitmask 4618 immediate, also allows immediate integers which can be loaded with a single 4619 ``MOVZ`` or ``MOVL`` instruction. 4620- ``N``: An immediate integer for use with the ``MOV`` assembly alias on a 4621 64-bit register. This is a superset of ``L``. 4622- ``Q``: Memory address operand must be in a single register (no 4623 offsets). (However, LLVM currently does this for the ``m`` constraint as 4624 well.) 4625- ``r``: A 32 or 64-bit integer register (W* or X*). 4626- ``w``: A 32, 64, or 128-bit floating-point, SIMD or SVE vector register. 4627- ``x``: Like w, but restricted to registers 0 to 15 inclusive. 4628- ``y``: Like w, but restricted to SVE vector registers Z0 to Z7 inclusive. 4629- ``Upl``: One of the low eight SVE predicate registers (P0 to P7) 4630- ``Upa``: Any of the SVE predicate registers (P0 to P15) 4631 4632AMDGPU: 4633 4634- ``r``: A 32 or 64-bit integer register. 4635- ``[0-9]v``: The 32-bit VGPR register, number 0-9. 4636- ``[0-9]s``: The 32-bit SGPR register, number 0-9. 4637- ``[0-9]a``: The 32-bit AGPR register, number 0-9. 4638- ``I``: An integer inline constant in the range from -16 to 64. 4639- ``J``: A 16-bit signed integer constant. 4640- ``A``: An integer or a floating-point inline constant. 4641- ``B``: A 32-bit signed integer constant. 4642- ``C``: A 32-bit unsigned integer constant or an integer inline constant in the range from -16 to 64. 4643- ``DA``: A 64-bit constant that can be split into two "A" constants. 4644- ``DB``: A 64-bit constant that can be split into two "B" constants. 4645 4646All ARM modes: 4647 4648- ``Q``, ``Um``, ``Un``, ``Uq``, ``Us``, ``Ut``, ``Uv``, ``Uy``: Memory address 4649 operand. Treated the same as operand ``m``, at the moment. 4650- ``Te``: An even general-purpose 32-bit integer register: ``r0,r2,...,r12,r14`` 4651- ``To``: An odd general-purpose 32-bit integer register: ``r1,r3,...,r11`` 4652 4653ARM and ARM's Thumb2 mode: 4654 4655- ``j``: An immediate integer between 0 and 65535 (valid for ``MOVW``) 4656- ``I``: An immediate integer valid for a data-processing instruction. 4657- ``J``: An immediate integer between -4095 and 4095. 4658- ``K``: An immediate integer whose bitwise inverse is valid for a 4659 data-processing instruction. (Can be used with template modifier "``B``" to 4660 print the inverted value). 4661- ``L``: An immediate integer whose negation is valid for a data-processing 4662 instruction. (Can be used with template modifier "``n``" to print the negated 4663 value). 4664- ``M``: A power of two or an integer between 0 and 32. 4665- ``N``: Invalid immediate constraint. 4666- ``O``: Invalid immediate constraint. 4667- ``r``: A general-purpose 32-bit integer register (``r0-r15``). 4668- ``l``: In Thumb2 mode, low 32-bit GPR registers (``r0-r7``). In ARM mode, same 4669 as ``r``. 4670- ``h``: In Thumb2 mode, a high 32-bit GPR register (``r8-r15``). In ARM mode, 4671 invalid. 4672- ``w``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges 4673 ``s0-s31``, ``d0-d31``, or ``q0-q15``, respectively. 4674- ``t``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges 4675 ``s0-s31``, ``d0-d15``, or ``q0-q7``, respectively. 4676- ``x``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges 4677 ``s0-s15``, ``d0-d7``, or ``q0-q3``, respectively. 4678 4679ARM's Thumb1 mode: 4680 4681- ``I``: An immediate integer between 0 and 255. 4682- ``J``: An immediate integer between -255 and -1. 4683- ``K``: An immediate integer between 0 and 255, with optional left-shift by 4684 some amount. 4685- ``L``: An immediate integer between -7 and 7. 4686- ``M``: An immediate integer which is a multiple of 4 between 0 and 1020. 4687- ``N``: An immediate integer between 0 and 31. 4688- ``O``: An immediate integer which is a multiple of 4 between -508 and 508. 4689- ``r``: A low 32-bit GPR register (``r0-r7``). 4690- ``l``: A low 32-bit GPR register (``r0-r7``). 4691- ``h``: A high GPR register (``r0-r7``). 4692- ``w``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges 4693 ``s0-s31``, ``d0-d31``, or ``q0-q15``, respectively. 4694- ``t``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges 4695 ``s0-s31``, ``d0-d15``, or ``q0-q7``, respectively. 4696- ``x``: A 32, 64, or 128-bit floating-point/SIMD register in the ranges 4697 ``s0-s15``, ``d0-d7``, or ``q0-q3``, respectively. 4698 4699 4700Hexagon: 4701 4702- ``o``, ``v``: A memory address operand, treated the same as constraint ``m``, 4703 at the moment. 4704- ``r``: A 32 or 64-bit register. 4705 4706MSP430: 4707 4708- ``r``: An 8 or 16-bit register. 4709 4710MIPS: 4711 4712- ``I``: An immediate signed 16-bit integer. 4713- ``J``: An immediate integer zero. 4714- ``K``: An immediate unsigned 16-bit integer. 4715- ``L``: An immediate 32-bit integer, where the lower 16 bits are 0. 4716- ``N``: An immediate integer between -65535 and -1. 4717- ``O``: An immediate signed 15-bit integer. 4718- ``P``: An immediate integer between 1 and 65535. 4719- ``m``: A memory address operand. In MIPS-SE mode, allows a base address 4720 register plus 16-bit immediate offset. In MIPS mode, just a base register. 4721- ``R``: A memory address operand. In MIPS-SE mode, allows a base address 4722 register plus a 9-bit signed offset. In MIPS mode, the same as constraint 4723 ``m``. 4724- ``ZC``: A memory address operand, suitable for use in a ``pref``, ``ll``, or 4725 ``sc`` instruction on the given subtarget (details vary). 4726- ``r``, ``d``, ``y``: A 32 or 64-bit GPR register. 4727- ``f``: A 32 or 64-bit FPU register (``F0-F31``), or a 128-bit MSA register 4728 (``W0-W31``). In the case of MSA registers, it is recommended to use the ``w`` 4729 argument modifier for compatibility with GCC. 4730- ``c``: A 32-bit or 64-bit GPR register suitable for indirect jump (always 4731 ``25``). 4732- ``l``: The ``lo`` register, 32 or 64-bit. 4733- ``x``: Invalid. 4734 4735NVPTX: 4736 4737- ``b``: A 1-bit integer register. 4738- ``c`` or ``h``: A 16-bit integer register. 4739- ``r``: A 32-bit integer register. 4740- ``l`` or ``N``: A 64-bit integer register. 4741- ``f``: A 32-bit float register. 4742- ``d``: A 64-bit float register. 4743 4744 4745PowerPC: 4746 4747- ``I``: An immediate signed 16-bit integer. 4748- ``J``: An immediate unsigned 16-bit integer, shifted left 16 bits. 4749- ``K``: An immediate unsigned 16-bit integer. 4750- ``L``: An immediate signed 16-bit integer, shifted left 16 bits. 4751- ``M``: An immediate integer greater than 31. 4752- ``N``: An immediate integer that is an exact power of 2. 4753- ``O``: The immediate integer constant 0. 4754- ``P``: An immediate integer constant whose negation is a signed 16-bit 4755 constant. 4756- ``es``, ``o``, ``Q``, ``Z``, ``Zy``: A memory address operand, currently 4757 treated the same as ``m``. 4758- ``r``: A 32 or 64-bit integer register. 4759- ``b``: A 32 or 64-bit integer register, excluding ``R0`` (that is: 4760 ``R1-R31``). 4761- ``f``: A 32 or 64-bit float register (``F0-F31``), 4762- ``v``: For ``4 x f32`` or ``4 x f64`` types, a 128-bit altivec vector 4763 register (``V0-V31``). 4764 4765- ``y``: Condition register (``CR0-CR7``). 4766- ``wc``: An individual CR bit in a CR register. 4767- ``wa``, ``wd``, ``wf``: Any 128-bit VSX vector register, from the full VSX 4768 register set (overlapping both the floating-point and vector register files). 4769- ``ws``: A 32 or 64-bit floating-point register, from the full VSX register 4770 set. 4771 4772RISC-V: 4773 4774- ``A``: An address operand (using a general-purpose register, without an 4775 offset). 4776- ``I``: A 12-bit signed integer immediate operand. 4777- ``J``: A zero integer immediate operand. 4778- ``K``: A 5-bit unsigned integer immediate operand. 4779- ``f``: A 32- or 64-bit floating-point register (requires F or D extension). 4780- ``r``: A 32- or 64-bit general-purpose register (depending on the platform 4781 ``XLEN``). 4782 4783Sparc: 4784 4785- ``I``: An immediate 13-bit signed integer. 4786- ``r``: A 32-bit integer register. 4787- ``f``: Any floating-point register on SparcV8, or a floating-point 4788 register in the "low" half of the registers on SparcV9. 4789- ``e``: Any floating-point register. (Same as ``f`` on SparcV8.) 4790 4791SystemZ: 4792 4793- ``I``: An immediate unsigned 8-bit integer. 4794- ``J``: An immediate unsigned 12-bit integer. 4795- ``K``: An immediate signed 16-bit integer. 4796- ``L``: An immediate signed 20-bit integer. 4797- ``M``: An immediate integer 0x7fffffff. 4798- ``Q``: A memory address operand with a base address and a 12-bit immediate 4799 unsigned displacement. 4800- ``R``: A memory address operand with a base address, a 12-bit immediate 4801 unsigned displacement, and an index register. 4802- ``S``: A memory address operand with a base address and a 20-bit immediate 4803 signed displacement. 4804- ``T``: A memory address operand with a base address, a 20-bit immediate 4805 signed displacement, and an index register. 4806- ``r`` or ``d``: A 32, 64, or 128-bit integer register. 4807- ``a``: A 32, 64, or 128-bit integer address register (excludes R0, which in an 4808 address context evaluates as zero). 4809- ``h``: A 32-bit value in the high part of a 64bit data register 4810 (LLVM-specific) 4811- ``f``: A 32, 64, or 128-bit floating-point register. 4812 4813X86: 4814 4815- ``I``: An immediate integer between 0 and 31. 4816- ``J``: An immediate integer between 0 and 64. 4817- ``K``: An immediate signed 8-bit integer. 4818- ``L``: An immediate integer, 0xff or 0xffff or (in 64-bit mode only) 4819 0xffffffff. 4820- ``M``: An immediate integer between 0 and 3. 4821- ``N``: An immediate unsigned 8-bit integer. 4822- ``O``: An immediate integer between 0 and 127. 4823- ``e``: An immediate 32-bit signed integer. 4824- ``Z``: An immediate 32-bit unsigned integer. 4825- ``o``, ``v``: Treated the same as ``m``, at the moment. 4826- ``q``: An 8, 16, 32, or 64-bit register which can be accessed as an 8-bit 4827 ``l`` integer register. On X86-32, this is the ``a``, ``b``, ``c``, and ``d`` 4828 registers, and on X86-64, it is all of the integer registers. 4829- ``Q``: An 8, 16, 32, or 64-bit register which can be accessed as an 8-bit 4830 ``h`` integer register. This is the ``a``, ``b``, ``c``, and ``d`` registers. 4831- ``r`` or ``l``: An 8, 16, 32, or 64-bit integer register. 4832- ``R``: An 8, 16, 32, or 64-bit "legacy" integer register -- one which has 4833 existed since i386, and can be accessed without the REX prefix. 4834- ``f``: A 32, 64, or 80-bit '387 FPU stack pseudo-register. 4835- ``y``: A 64-bit MMX register, if MMX is enabled. 4836- ``x``: If SSE is enabled: a 32 or 64-bit scalar operand, or 128-bit vector 4837 operand in a SSE register. If AVX is also enabled, can also be a 256-bit 4838 vector operand in an AVX register. If AVX-512 is also enabled, can also be a 4839 512-bit vector operand in an AVX512 register, Otherwise, an error. 4840- ``Y``: The same as ``x``, if *SSE2* is enabled, otherwise an error. 4841- ``A``: Special case: allocates EAX first, then EDX, for a single operand (in 4842 32-bit mode, a 64-bit integer operand will get split into two registers). It 4843 is not recommended to use this constraint, as in 64-bit mode, the 64-bit 4844 operand will get allocated only to RAX -- if two 32-bit operands are needed, 4845 you're better off splitting it yourself, before passing it to the asm 4846 statement. 4847 4848XCore: 4849 4850- ``r``: A 32-bit integer register. 4851 4852 4853.. _inline-asm-modifiers: 4854 4855Asm template argument modifiers 4856^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 4857 4858In the asm template string, modifiers can be used on the operand reference, like 4859"``${0:n}``". 4860 4861The modifiers are, in general, expected to behave the same way they do in 4862GCC. LLVM's support is often implemented on an 'as-needed' basis, to support C 4863inline asm code which was supported by GCC. A mismatch in behavior between LLVM 4864and GCC likely indicates a bug in LLVM. 4865 4866Target-independent: 4867 4868- ``c``: Print an immediate integer constant unadorned, without 4869 the target-specific immediate punctuation (e.g. no ``$`` prefix). 4870- ``n``: Negate and print immediate integer constant unadorned, without the 4871 target-specific immediate punctuation (e.g. no ``$`` prefix). 4872- ``l``: Print as an unadorned label, without the target-specific label 4873 punctuation (e.g. no ``$`` prefix). 4874 4875AArch64: 4876 4877- ``w``: Print a GPR register with a ``w*`` name instead of ``x*`` name. E.g., 4878 instead of ``x30``, print ``w30``. 4879- ``x``: Print a GPR register with a ``x*`` name. (this is the default, anyhow). 4880- ``b``, ``h``, ``s``, ``d``, ``q``: Print a floating-point/SIMD register with a 4881 ``b*``, ``h*``, ``s*``, ``d*``, or ``q*`` name, rather than the default of 4882 ``v*``. 4883 4884AMDGPU: 4885 4886- ``r``: No effect. 4887 4888ARM: 4889 4890- ``a``: Print an operand as an address (with ``[`` and ``]`` surrounding a 4891 register). 4892- ``P``: No effect. 4893- ``q``: No effect. 4894- ``y``: Print a VFP single-precision register as an indexed double (e.g. print 4895 as ``d4[1]`` instead of ``s9``) 4896- ``B``: Bitwise invert and print an immediate integer constant without ``#`` 4897 prefix. 4898- ``L``: Print the low 16-bits of an immediate integer constant. 4899- ``M``: Print as a register set suitable for ldm/stm. Also prints *all* 4900 register operands subsequent to the specified one (!), so use carefully. 4901- ``Q``: Print the low-order register of a register-pair, or the low-order 4902 register of a two-register operand. 4903- ``R``: Print the high-order register of a register-pair, or the high-order 4904 register of a two-register operand. 4905- ``H``: Print the second register of a register-pair. (On a big-endian system, 4906 ``H`` is equivalent to ``Q``, and on little-endian system, ``H`` is equivalent 4907 to ``R``.) 4908 4909 .. FIXME: H doesn't currently support printing the second register 4910 of a two-register operand. 4911 4912- ``e``: Print the low doubleword register of a NEON quad register. 4913- ``f``: Print the high doubleword register of a NEON quad register. 4914- ``m``: Print the base register of a memory operand without the ``[`` and ``]`` 4915 adornment. 4916 4917Hexagon: 4918 4919- ``L``: Print the second register of a two-register operand. Requires that it 4920 has been allocated consecutively to the first. 4921 4922 .. FIXME: why is it restricted to consecutive ones? And there's 4923 nothing that ensures that happens, is there? 4924 4925- ``I``: Print the letter 'i' if the operand is an integer constant, otherwise 4926 nothing. Used to print 'addi' vs 'add' instructions. 4927 4928MSP430: 4929 4930No additional modifiers. 4931 4932MIPS: 4933 4934- ``X``: Print an immediate integer as hexadecimal 4935- ``x``: Print the low 16 bits of an immediate integer as hexadecimal. 4936- ``d``: Print an immediate integer as decimal. 4937- ``m``: Subtract one and print an immediate integer as decimal. 4938- ``z``: Print $0 if an immediate zero, otherwise print normally. 4939- ``L``: Print the low-order register of a two-register operand, or prints the 4940 address of the low-order word of a double-word memory operand. 4941 4942 .. FIXME: L seems to be missing memory operand support. 4943 4944- ``M``: Print the high-order register of a two-register operand, or prints the 4945 address of the high-order word of a double-word memory operand. 4946 4947 .. FIXME: M seems to be missing memory operand support. 4948 4949- ``D``: Print the second register of a two-register operand, or prints the 4950 second word of a double-word memory operand. (On a big-endian system, ``D`` is 4951 equivalent to ``L``, and on little-endian system, ``D`` is equivalent to 4952 ``M``.) 4953- ``w``: No effect. Provided for compatibility with GCC which requires this 4954 modifier in order to print MSA registers (``W0-W31``) with the ``f`` 4955 constraint. 4956 4957NVPTX: 4958 4959- ``r``: No effect. 4960 4961PowerPC: 4962 4963- ``L``: Print the second register of a two-register operand. Requires that it 4964 has been allocated consecutively to the first. 4965 4966 .. FIXME: why is it restricted to consecutive ones? And there's 4967 nothing that ensures that happens, is there? 4968 4969- ``I``: Print the letter 'i' if the operand is an integer constant, otherwise 4970 nothing. Used to print 'addi' vs 'add' instructions. 4971- ``y``: For a memory operand, prints formatter for a two-register X-form 4972 instruction. (Currently always prints ``r0,OPERAND``). 4973- ``U``: Prints 'u' if the memory operand is an update form, and nothing 4974 otherwise. (NOTE: LLVM does not support update form, so this will currently 4975 always print nothing) 4976- ``X``: Prints 'x' if the memory operand is an indexed form. (NOTE: LLVM does 4977 not support indexed form, so this will currently always print nothing) 4978 4979RISC-V: 4980 4981- ``i``: Print the letter 'i' if the operand is not a register, otherwise print 4982 nothing. Used to print 'addi' vs 'add' instructions, etc. 4983- ``z``: Print the register ``zero`` if an immediate zero, otherwise print 4984 normally. 4985 4986Sparc: 4987 4988- ``r``: No effect. 4989 4990SystemZ: 4991 4992SystemZ implements only ``n``, and does *not* support any of the other 4993target-independent modifiers. 4994 4995X86: 4996 4997- ``c``: Print an unadorned integer or symbol name. (The latter is 4998 target-specific behavior for this typically target-independent modifier). 4999- ``A``: Print a register name with a '``*``' before it. 5000- ``b``: Print an 8-bit register name (e.g. ``al``); do nothing on a memory 5001 operand. 5002- ``h``: Print the upper 8-bit register name (e.g. ``ah``); do nothing on a 5003 memory operand. 5004- ``w``: Print the 16-bit register name (e.g. ``ax``); do nothing on a memory 5005 operand. 5006- ``k``: Print the 32-bit register name (e.g. ``eax``); do nothing on a memory 5007 operand. 5008- ``q``: Print the 64-bit register name (e.g. ``rax``), if 64-bit registers are 5009 available, otherwise the 32-bit register name; do nothing on a memory operand. 5010- ``n``: Negate and print an unadorned integer, or, for operands other than an 5011 immediate integer (e.g. a relocatable symbol expression), print a '-' before 5012 the operand. (The behavior for relocatable symbol expressions is a 5013 target-specific behavior for this typically target-independent modifier) 5014- ``H``: Print a memory reference with additional offset +8. 5015- ``P``: Print a memory reference or operand for use as the argument of a call 5016 instruction. (E.g. omit ``(rip)``, even though it's PC-relative.) 5017 5018XCore: 5019 5020No additional modifiers. 5021 5022 5023Inline Asm Metadata 5024^^^^^^^^^^^^^^^^^^^ 5025 5026The call instructions that wrap inline asm nodes may have a 5027"``!srcloc``" MDNode attached to it that contains a list of constant 5028integers. If present, the code generator will use the integer as the 5029location cookie value when report errors through the ``LLVMContext`` 5030error reporting mechanisms. This allows a front-end to correlate backend 5031errors that occur with inline asm back to the source code that produced 5032it. For example: 5033 5034.. code-block:: llvm 5035 5036 call void asm sideeffect "something bad", ""(), !srcloc !42 5037 ... 5038 !42 = !{ i32 1234567 } 5039 5040It is up to the front-end to make sense of the magic numbers it places 5041in the IR. If the MDNode contains multiple constants, the code generator 5042will use the one that corresponds to the line of the asm that the error 5043occurs on. 5044 5045.. _metadata: 5046 5047Metadata 5048======== 5049 5050LLVM IR allows metadata to be attached to instructions and global objects in the 5051program that can convey extra information about the code to the optimizers and 5052code generator. One example application of metadata is source-level 5053debug information. There are two metadata primitives: strings and nodes. 5054 5055Metadata does not have a type, and is not a value. If referenced from a 5056``call`` instruction, it uses the ``metadata`` type. 5057 5058All metadata are identified in syntax by an exclamation point ('``!``'). 5059 5060.. _metadata-string: 5061 5062Metadata Nodes and Metadata Strings 5063----------------------------------- 5064 5065A metadata string is a string surrounded by double quotes. It can 5066contain any character by escaping non-printable characters with 5067"``\xx``" where "``xx``" is the two digit hex code. For example: 5068"``!"test\00"``". 5069 5070Metadata nodes are represented with notation similar to structure 5071constants (a comma separated list of elements, surrounded by braces and 5072preceded by an exclamation point). Metadata nodes can have any values as 5073their operand. For example: 5074 5075.. code-block:: llvm 5076 5077 !{ !"test\00", i32 10} 5078 5079Metadata nodes that aren't uniqued use the ``distinct`` keyword. For example: 5080 5081.. code-block:: text 5082 5083 !0 = distinct !{!"test\00", i32 10} 5084 5085``distinct`` nodes are useful when nodes shouldn't be merged based on their 5086content. They can also occur when transformations cause uniquing collisions 5087when metadata operands change. 5088 5089A :ref:`named metadata <namedmetadatastructure>` is a collection of 5090metadata nodes, which can be looked up in the module symbol table. For 5091example: 5092 5093.. code-block:: llvm 5094 5095 !foo = !{!4, !3} 5096 5097Metadata can be used as function arguments. Here the ``llvm.dbg.value`` 5098intrinsic is using three metadata arguments: 5099 5100.. code-block:: llvm 5101 5102 call void @llvm.dbg.value(metadata !24, metadata !25, metadata !26) 5103 5104Metadata can be attached to an instruction. Here metadata ``!21`` is attached 5105to the ``add`` instruction using the ``!dbg`` identifier: 5106 5107.. code-block:: llvm 5108 5109 %indvar.next = add i64 %indvar, 1, !dbg !21 5110 5111Instructions may not have multiple metadata attachments with the same 5112identifier. 5113 5114Metadata can also be attached to a function or a global variable. Here metadata 5115``!22`` is attached to the ``f1`` and ``f2`` functions, and the globals ``g1`` 5116and ``g2`` using the ``!dbg`` identifier: 5117 5118.. code-block:: llvm 5119 5120 declare !dbg !22 void @f1() 5121 define void @f2() !dbg !22 { 5122 ret void 5123 } 5124 5125 @g1 = global i32 0, !dbg !22 5126 @g2 = external global i32, !dbg !22 5127 5128Unlike instructions, global objects (functions and global variables) may have 5129multiple metadata attachments with the same identifier. 5130 5131A transformation is required to drop any metadata attachment that it does not 5132know or know it can't preserve. Currently there is an exception for metadata 5133attachment to globals for ``!type`` and ``!absolute_symbol`` which can't be 5134unconditionally dropped unless the global is itself deleted. 5135 5136Metadata attached to a module using named metadata may not be dropped, with 5137the exception of debug metadata (named metadata with the name ``!llvm.dbg.*``). 5138 5139More information about specific metadata nodes recognized by the 5140optimizers and code generator is found below. 5141 5142.. _specialized-metadata: 5143 5144Specialized Metadata Nodes 5145^^^^^^^^^^^^^^^^^^^^^^^^^^ 5146 5147Specialized metadata nodes are custom data structures in metadata (as opposed 5148to generic tuples). Their fields are labelled, and can be specified in any 5149order. 5150 5151These aren't inherently debug info centric, but currently all the specialized 5152metadata nodes are related to debug info. 5153 5154.. _DICompileUnit: 5155 5156DICompileUnit 5157""""""""""""" 5158 5159``DICompileUnit`` nodes represent a compile unit. The ``enums:``, 5160``retainedTypes:``, ``globals:``, ``imports:`` and ``macros:`` fields are tuples 5161containing the debug info to be emitted along with the compile unit, regardless 5162of code optimizations (some nodes are only emitted if there are references to 5163them from instructions). The ``debugInfoForProfiling:`` field is a boolean 5164indicating whether or not line-table discriminators are updated to provide 5165more-accurate debug info for profiling results. 5166 5167.. code-block:: text 5168 5169 !0 = !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang", 5170 isOptimized: true, flags: "-O2", runtimeVersion: 2, 5171 splitDebugFilename: "abc.debug", emissionKind: FullDebug, 5172 enums: !2, retainedTypes: !3, globals: !4, imports: !5, 5173 macros: !6, dwoId: 0x0abcd) 5174 5175Compile unit descriptors provide the root scope for objects declared in a 5176specific compilation unit. File descriptors are defined using this scope. These 5177descriptors are collected by a named metadata node ``!llvm.dbg.cu``. They keep 5178track of global variables, type information, and imported entities (declarations 5179and namespaces). 5180 5181.. _DIFile: 5182 5183DIFile 5184"""""" 5185 5186``DIFile`` nodes represent files. The ``filename:`` can include slashes. 5187 5188.. code-block:: none 5189 5190 !0 = !DIFile(filename: "path/to/file", directory: "/path/to/dir", 5191 checksumkind: CSK_MD5, 5192 checksum: "000102030405060708090a0b0c0d0e0f") 5193 5194Files are sometimes used in ``scope:`` fields, and are the only valid target 5195for ``file:`` fields. 5196Valid values for ``checksumkind:`` field are: {CSK_None, CSK_MD5, CSK_SHA1, CSK_SHA256} 5197 5198.. _DIBasicType: 5199 5200DIBasicType 5201""""""""""" 5202 5203``DIBasicType`` nodes represent primitive types, such as ``int``, ``bool`` and 5204``float``. ``tag:`` defaults to ``DW_TAG_base_type``. 5205 5206.. code-block:: text 5207 5208 !0 = !DIBasicType(name: "unsigned char", size: 8, align: 8, 5209 encoding: DW_ATE_unsigned_char) 5210 !1 = !DIBasicType(tag: DW_TAG_unspecified_type, name: "decltype(nullptr)") 5211 5212The ``encoding:`` describes the details of the type. Usually it's one of the 5213following: 5214 5215.. code-block:: text 5216 5217 DW_ATE_address = 1 5218 DW_ATE_boolean = 2 5219 DW_ATE_float = 4 5220 DW_ATE_signed = 5 5221 DW_ATE_signed_char = 6 5222 DW_ATE_unsigned = 7 5223 DW_ATE_unsigned_char = 8 5224 5225.. _DISubroutineType: 5226 5227DISubroutineType 5228"""""""""""""""" 5229 5230``DISubroutineType`` nodes represent subroutine types. Their ``types:`` field 5231refers to a tuple; the first operand is the return type, while the rest are the 5232types of the formal arguments in order. If the first operand is ``null``, that 5233represents a function with no return value (such as ``void foo() {}`` in C++). 5234 5235.. code-block:: text 5236 5237 !0 = !BasicType(name: "int", size: 32, align: 32, DW_ATE_signed) 5238 !1 = !BasicType(name: "char", size: 8, align: 8, DW_ATE_signed_char) 5239 !2 = !DISubroutineType(types: !{null, !0, !1}) ; void (int, char) 5240 5241.. _DIDerivedType: 5242 5243DIDerivedType 5244""""""""""""" 5245 5246``DIDerivedType`` nodes represent types derived from other types, such as 5247qualified types. 5248 5249.. code-block:: text 5250 5251 !0 = !DIBasicType(name: "unsigned char", size: 8, align: 8, 5252 encoding: DW_ATE_unsigned_char) 5253 !1 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !0, size: 32, 5254 align: 32) 5255 5256The following ``tag:`` values are valid: 5257 5258.. code-block:: text 5259 5260 DW_TAG_member = 13 5261 DW_TAG_pointer_type = 15 5262 DW_TAG_reference_type = 16 5263 DW_TAG_typedef = 22 5264 DW_TAG_inheritance = 28 5265 DW_TAG_ptr_to_member_type = 31 5266 DW_TAG_const_type = 38 5267 DW_TAG_friend = 42 5268 DW_TAG_volatile_type = 53 5269 DW_TAG_restrict_type = 55 5270 DW_TAG_atomic_type = 71 5271 5272.. _DIDerivedTypeMember: 5273 5274``DW_TAG_member`` is used to define a member of a :ref:`composite type 5275<DICompositeType>`. The type of the member is the ``baseType:``. The 5276``offset:`` is the member's bit offset. If the composite type has an ODR 5277``identifier:`` and does not set ``flags: DIFwdDecl``, then the member is 5278uniqued based only on its ``name:`` and ``scope:``. 5279 5280``DW_TAG_inheritance`` and ``DW_TAG_friend`` are used in the ``elements:`` 5281field of :ref:`composite types <DICompositeType>` to describe parents and 5282friends. 5283 5284``DW_TAG_typedef`` is used to provide a name for the ``baseType:``. 5285 5286``DW_TAG_pointer_type``, ``DW_TAG_reference_type``, ``DW_TAG_const_type``, 5287``DW_TAG_volatile_type``, ``DW_TAG_restrict_type`` and ``DW_TAG_atomic_type`` 5288are used to qualify the ``baseType:``. 5289 5290Note that the ``void *`` type is expressed as a type derived from NULL. 5291 5292.. _DICompositeType: 5293 5294DICompositeType 5295""""""""""""""" 5296 5297``DICompositeType`` nodes represent types composed of other types, like 5298structures and unions. ``elements:`` points to a tuple of the composed types. 5299 5300If the source language supports ODR, the ``identifier:`` field gives the unique 5301identifier used for type merging between modules. When specified, 5302:ref:`subprogram declarations <DISubprogramDeclaration>` and :ref:`member 5303derived types <DIDerivedTypeMember>` that reference the ODR-type in their 5304``scope:`` change uniquing rules. 5305 5306For a given ``identifier:``, there should only be a single composite type that 5307does not have ``flags: DIFlagFwdDecl`` set. LLVM tools that link modules 5308together will unique such definitions at parse time via the ``identifier:`` 5309field, even if the nodes are ``distinct``. 5310 5311.. code-block:: text 5312 5313 !0 = !DIEnumerator(name: "SixKind", value: 7) 5314 !1 = !DIEnumerator(name: "SevenKind", value: 7) 5315 !2 = !DIEnumerator(name: "NegEightKind", value: -8) 5316 !3 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "Enum", file: !12, 5317 line: 2, size: 32, align: 32, identifier: "_M4Enum", 5318 elements: !{!0, !1, !2}) 5319 5320The following ``tag:`` values are valid: 5321 5322.. code-block:: text 5323 5324 DW_TAG_array_type = 1 5325 DW_TAG_class_type = 2 5326 DW_TAG_enumeration_type = 4 5327 DW_TAG_structure_type = 19 5328 DW_TAG_union_type = 23 5329 5330For ``DW_TAG_array_type``, the ``elements:`` should be :ref:`subrange 5331descriptors <DISubrange>`, each representing the range of subscripts at that 5332level of indexing. The ``DIFlagVector`` flag to ``flags:`` indicates that an 5333array type is a native packed vector. The optional ``dataLocation`` is a 5334DIExpression that describes how to get from an object's address to the actual 5335raw data, if they aren't equivalent. This is only supported for array types, 5336particularly to describe Fortran arrays, which have an array descriptor in 5337addition to the array data. Alternatively it can also be DIVariable which 5338has the address of the actual raw data. The Fortran language supports pointer 5339arrays which can be attached to actual arrays, this attachment between pointer 5340and pointee is called association. The optional ``associated`` is a 5341DIExpression that describes whether the pointer array is currently associated. 5342The optional ``allocated`` is a DIExpression that describes whether the 5343allocatable array is currently allocated. The optional ``rank`` is a 5344DIExpression that describes the rank (number of dimensions) of fortran assumed 5345rank array (rank is known at runtime). 5346 5347For ``DW_TAG_enumeration_type``, the ``elements:`` should be :ref:`enumerator 5348descriptors <DIEnumerator>`, each representing the definition of an enumeration 5349value for the set. All enumeration type descriptors are collected in the 5350``enums:`` field of the :ref:`compile unit <DICompileUnit>`. 5351 5352For ``DW_TAG_structure_type``, ``DW_TAG_class_type``, and 5353``DW_TAG_union_type``, the ``elements:`` should be :ref:`derived types 5354<DIDerivedType>` with ``tag: DW_TAG_member``, ``tag: DW_TAG_inheritance``, or 5355``tag: DW_TAG_friend``; or :ref:`subprograms <DISubprogram>` with 5356``isDefinition: false``. 5357 5358.. _DISubrange: 5359 5360DISubrange 5361"""""""""" 5362 5363``DISubrange`` nodes are the elements for ``DW_TAG_array_type`` variants of 5364:ref:`DICompositeType`. 5365 5366- ``count: -1`` indicates an empty array. 5367- ``count: !9`` describes the count with a :ref:`DILocalVariable`. 5368- ``count: !11`` describes the count with a :ref:`DIGlobalVariable`. 5369 5370.. code-block:: text 5371 5372 !0 = !DISubrange(count: 5, lowerBound: 0) ; array counting from 0 5373 !1 = !DISubrange(count: 5, lowerBound: 1) ; array counting from 1 5374 !2 = !DISubrange(count: -1) ; empty array. 5375 5376 ; Scopes used in rest of example 5377 !6 = !DIFile(filename: "vla.c", directory: "/path/to/file") 5378 !7 = distinct !DICompileUnit(language: DW_LANG_C99, file: !6) 5379 !8 = distinct !DISubprogram(name: "foo", scope: !7, file: !6, line: 5) 5380 5381 ; Use of local variable as count value 5382 !9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 5383 !10 = !DILocalVariable(name: "count", scope: !8, file: !6, line: 42, type: !9) 5384 !11 = !DISubrange(count: !10, lowerBound: 0) 5385 5386 ; Use of global variable as count value 5387 !12 = !DIGlobalVariable(name: "count", scope: !8, file: !6, line: 22, type: !9) 5388 !13 = !DISubrange(count: !12, lowerBound: 0) 5389 5390.. _DIEnumerator: 5391 5392DIEnumerator 5393"""""""""""" 5394 5395``DIEnumerator`` nodes are the elements for ``DW_TAG_enumeration_type`` 5396variants of :ref:`DICompositeType`. 5397 5398.. code-block:: text 5399 5400 !0 = !DIEnumerator(name: "SixKind", value: 7) 5401 !1 = !DIEnumerator(name: "SevenKind", value: 7) 5402 !2 = !DIEnumerator(name: "NegEightKind", value: -8) 5403 5404DITemplateTypeParameter 5405""""""""""""""""""""""" 5406 5407``DITemplateTypeParameter`` nodes represent type parameters to generic source 5408language constructs. They are used (optionally) in :ref:`DICompositeType` and 5409:ref:`DISubprogram` ``templateParams:`` fields. 5410 5411.. code-block:: text 5412 5413 !0 = !DITemplateTypeParameter(name: "Ty", type: !1) 5414 5415DITemplateValueParameter 5416"""""""""""""""""""""""" 5417 5418``DITemplateValueParameter`` nodes represent value parameters to generic source 5419language constructs. ``tag:`` defaults to ``DW_TAG_template_value_parameter``, 5420but if specified can also be set to ``DW_TAG_GNU_template_template_param`` or 5421``DW_TAG_GNU_template_param_pack``. They are used (optionally) in 5422:ref:`DICompositeType` and :ref:`DISubprogram` ``templateParams:`` fields. 5423 5424.. code-block:: text 5425 5426 !0 = !DITemplateValueParameter(name: "Ty", type: !1, value: i32 7) 5427 5428DINamespace 5429""""""""""" 5430 5431``DINamespace`` nodes represent namespaces in the source language. 5432 5433.. code-block:: text 5434 5435 !0 = !DINamespace(name: "myawesomeproject", scope: !1, file: !2, line: 7) 5436 5437.. _DIGlobalVariable: 5438 5439DIGlobalVariable 5440"""""""""""""""" 5441 5442``DIGlobalVariable`` nodes represent global variables in the source language. 5443 5444.. code-block:: text 5445 5446 @foo = global i32, !dbg !0 5447 !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) 5448 !1 = !DIGlobalVariable(name: "foo", linkageName: "foo", scope: !2, 5449 file: !3, line: 7, type: !4, isLocal: true, 5450 isDefinition: false, declaration: !5) 5451 5452 5453DIGlobalVariableExpression 5454"""""""""""""""""""""""""" 5455 5456``DIGlobalVariableExpression`` nodes tie a :ref:`DIGlobalVariable` together 5457with a :ref:`DIExpression`. 5458 5459.. code-block:: text 5460 5461 @lower = global i32, !dbg !0 5462 @upper = global i32, !dbg !1 5463 !0 = !DIGlobalVariableExpression( 5464 var: !2, 5465 expr: !DIExpression(DW_OP_LLVM_fragment, 0, 32) 5466 ) 5467 !1 = !DIGlobalVariableExpression( 5468 var: !2, 5469 expr: !DIExpression(DW_OP_LLVM_fragment, 32, 32) 5470 ) 5471 !2 = !DIGlobalVariable(name: "split64", linkageName: "split64", scope: !3, 5472 file: !4, line: 8, type: !5, declaration: !6) 5473 5474All global variable expressions should be referenced by the `globals:` field of 5475a :ref:`compile unit <DICompileUnit>`. 5476 5477.. _DISubprogram: 5478 5479DISubprogram 5480"""""""""""" 5481 5482``DISubprogram`` nodes represent functions from the source language. A distinct 5483``DISubprogram`` may be attached to a function definition using ``!dbg`` 5484metadata. A unique ``DISubprogram`` may be attached to a function declaration 5485used for call site debug info. The ``retainedNodes:`` field is a list of 5486:ref:`variables <DILocalVariable>` and :ref:`labels <DILabel>` that must be 5487retained, even if their IR counterparts are optimized out of the IR. The 5488``type:`` field must point at an :ref:`DISubroutineType`. 5489 5490.. _DISubprogramDeclaration: 5491 5492When ``isDefinition: false``, subprograms describe a declaration in the type 5493tree as opposed to a definition of a function. If the scope is a composite 5494type with an ODR ``identifier:`` and that does not set ``flags: DIFwdDecl``, 5495then the subprogram declaration is uniqued based only on its ``linkageName:`` 5496and ``scope:``. 5497 5498.. code-block:: text 5499 5500 define void @_Z3foov() !dbg !0 { 5501 ... 5502 } 5503 5504 !0 = distinct !DISubprogram(name: "foo", linkageName: "_Zfoov", scope: !1, 5505 file: !2, line: 7, type: !3, isLocal: true, 5506 isDefinition: true, scopeLine: 8, 5507 containingType: !4, 5508 virtuality: DW_VIRTUALITY_pure_virtual, 5509 virtualIndex: 10, flags: DIFlagPrototyped, 5510 isOptimized: true, unit: !5, templateParams: !6, 5511 declaration: !7, retainedNodes: !8, 5512 thrownTypes: !9) 5513 5514.. _DILexicalBlock: 5515 5516DILexicalBlock 5517"""""""""""""" 5518 5519``DILexicalBlock`` nodes describe nested blocks within a :ref:`subprogram 5520<DISubprogram>`. The line number and column numbers are used to distinguish 5521two lexical blocks at same depth. They are valid targets for ``scope:`` 5522fields. 5523 5524.. code-block:: text 5525 5526 !0 = distinct !DILexicalBlock(scope: !1, file: !2, line: 7, column: 35) 5527 5528Usually lexical blocks are ``distinct`` to prevent node merging based on 5529operands. 5530 5531.. _DILexicalBlockFile: 5532 5533DILexicalBlockFile 5534"""""""""""""""""" 5535 5536``DILexicalBlockFile`` nodes are used to discriminate between sections of a 5537:ref:`lexical block <DILexicalBlock>`. The ``file:`` field can be changed to 5538indicate textual inclusion, or the ``discriminator:`` field can be used to 5539discriminate between control flow within a single block in the source language. 5540 5541.. code-block:: text 5542 5543 !0 = !DILexicalBlock(scope: !3, file: !4, line: 7, column: 35) 5544 !1 = !DILexicalBlockFile(scope: !0, file: !4, discriminator: 0) 5545 !2 = !DILexicalBlockFile(scope: !0, file: !4, discriminator: 1) 5546 5547.. _DILocation: 5548 5549DILocation 5550"""""""""" 5551 5552``DILocation`` nodes represent source debug locations. The ``scope:`` field is 5553mandatory, and points at an :ref:`DILexicalBlockFile`, an 5554:ref:`DILexicalBlock`, or an :ref:`DISubprogram`. 5555 5556.. code-block:: text 5557 5558 !0 = !DILocation(line: 2900, column: 42, scope: !1, inlinedAt: !2) 5559 5560.. _DILocalVariable: 5561 5562DILocalVariable 5563""""""""""""""" 5564 5565``DILocalVariable`` nodes represent local variables in the source language. If 5566the ``arg:`` field is set to non-zero, then this variable is a subprogram 5567parameter, and it will be included in the ``variables:`` field of its 5568:ref:`DISubprogram`. 5569 5570.. code-block:: text 5571 5572 !0 = !DILocalVariable(name: "this", arg: 1, scope: !3, file: !2, line: 7, 5573 type: !3, flags: DIFlagArtificial) 5574 !1 = !DILocalVariable(name: "x", arg: 2, scope: !4, file: !2, line: 7, 5575 type: !3) 5576 !2 = !DILocalVariable(name: "y", scope: !5, file: !2, line: 7, type: !3) 5577 5578.. _DIExpression: 5579 5580DIExpression 5581"""""""""""" 5582 5583``DIExpression`` nodes represent expressions that are inspired by the DWARF 5584expression language. They are used in :ref:`debug intrinsics<dbg_intrinsics>` 5585(such as ``llvm.dbg.declare`` and ``llvm.dbg.value``) to describe how the 5586referenced LLVM variable relates to the source language variable. Debug 5587intrinsics are interpreted left-to-right: start by pushing the value/address 5588operand of the intrinsic onto a stack, then repeatedly push and evaluate 5589opcodes from the DIExpression until the final variable description is produced. 5590 5591The current supported opcode vocabulary is limited: 5592 5593- ``DW_OP_deref`` dereferences the top of the expression stack. 5594- ``DW_OP_plus`` pops the last two entries from the expression stack, adds 5595 them together and appends the result to the expression stack. 5596- ``DW_OP_minus`` pops the last two entries from the expression stack, subtracts 5597 the last entry from the second last entry and appends the result to the 5598 expression stack. 5599- ``DW_OP_plus_uconst, 93`` adds ``93`` to the working expression. 5600- ``DW_OP_LLVM_fragment, 16, 8`` specifies the offset and size (``16`` and ``8`` 5601 here, respectively) of the variable fragment from the working expression. Note 5602 that contrary to DW_OP_bit_piece, the offset is describing the location 5603 within the described source variable. 5604- ``DW_OP_LLVM_convert, 16, DW_ATE_signed`` specifies a bit size and encoding 5605 (``16`` and ``DW_ATE_signed`` here, respectively) to which the top of the 5606 expression stack is to be converted. Maps into a ``DW_OP_convert`` operation 5607 that references a base type constructed from the supplied values. 5608- ``DW_OP_LLVM_tag_offset, tag_offset`` specifies that a memory tag should be 5609 optionally applied to the pointer. The memory tag is derived from the 5610 given tag offset in an implementation-defined manner. 5611- ``DW_OP_swap`` swaps top two stack entries. 5612- ``DW_OP_xderef`` provides extended dereference mechanism. The entry at the top 5613 of the stack is treated as an address. The second stack entry is treated as an 5614 address space identifier. 5615- ``DW_OP_stack_value`` marks a constant value. 5616- ``DW_OP_LLVM_entry_value, N`` may only appear in MIR and at the 5617 beginning of a ``DIExpression``. In DWARF a ``DBG_VALUE`` 5618 instruction binding a ``DIExpression(DW_OP_LLVM_entry_value`` to a 5619 register is lowered to a ``DW_OP_entry_value [reg]``, pushing the 5620 value the register had upon function entry onto the stack. The next 5621 ``(N - 1)`` operations will be part of the ``DW_OP_entry_value`` 5622 block argument. For example, ``!DIExpression(DW_OP_LLVM_entry_value, 5623 1, DW_OP_plus_uconst, 123, DW_OP_stack_value)`` specifies an 5624 expression where the entry value of the debug value instruction's 5625 value/address operand is pushed to the stack, and is added 5626 with 123. Due to framework limitations ``N`` can currently only 5627 be 1. 5628 5629 The operation is introduced by the ``LiveDebugValues`` pass, which 5630 applies it only to function parameters that are unmodified 5631 throughout the function. Support is limited to simple register 5632 location descriptions, or as indirect locations (e.g., when a struct 5633 is passed-by-value to a callee via a pointer to a temporary copy 5634 made in the caller). The entry value op is also introduced by the 5635 ``AsmPrinter`` pass when a call site parameter value 5636 (``DW_AT_call_site_parameter_value``) is represented as entry value 5637 of the parameter. 5638- ``DW_OP_LLVM_arg, N`` is used in debug intrinsics that refer to more than one 5639 value, such as one that calculates the sum of two registers. This is always 5640 used in combination with an ordered list of values, such that 5641 ``DW_OP_LLVM_arg, N`` refers to the ``N``th element in that list. For 5642 example, ``!DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_minus, 5643 DW_OP_stack_value)`` used with the list ``(%reg1, %reg2)`` would evaluate to 5644 ``%reg1 - reg2``. This list of values should be provided by the containing 5645 intrinsic/instruction. 5646- ``DW_OP_breg`` (or ``DW_OP_bregx``) represents a content on the provided 5647 signed offset of the specified register. The opcode is only generated by the 5648 ``AsmPrinter`` pass to describe call site parameter value which requires an 5649 expression over two registers. 5650- ``DW_OP_push_object_address`` pushes the address of the object which can then 5651 serve as a descriptor in subsequent calculation. This opcode can be used to 5652 calculate bounds of fortran allocatable array which has array descriptors. 5653- ``DW_OP_over`` duplicates the entry currently second in the stack at the top 5654 of the stack. This opcode can be used to calculate bounds of fortran assumed 5655 rank array which has rank known at run time and current dimension number is 5656 implicitly first element of the stack. 5657- ``DW_OP_LLVM_implicit_pointer`` It specifies the dereferenced value. It can 5658 be used to represent pointer variables which are optimized out but the value 5659 it points to is known. This operator is required as it is different than DWARF 5660 operator DW_OP_implicit_pointer in representation and specification (number 5661 and types of operands) and later can not be used as multiple level. 5662 5663.. code-block:: text 5664 5665 IR for "*ptr = 4;" 5666 -------------- 5667 call void @llvm.dbg.value(metadata i32 4, metadata !17, metadata !20) 5668 !17 = !DILocalVariable(name: "ptr1", scope: !12, file: !3, line: 5, 5669 type: !18) 5670 !18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !19, size: 64) 5671 !19 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 5672 !20 = !DIExpression(DW_OP_LLVM_implicit_pointer)) 5673 5674 IR for "**ptr = 4;" 5675 -------------- 5676 call void @llvm.dbg.value(metadata i32 4, metadata !17, metadata !21) 5677 !17 = !DILocalVariable(name: "ptr1", scope: !12, file: !3, line: 5, 5678 type: !18) 5679 !18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !19, size: 64) 5680 !19 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !20, size: 64) 5681 !20 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 5682 !21 = !DIExpression(DW_OP_LLVM_implicit_pointer, 5683 DW_OP_LLVM_implicit_pointer)) 5684 5685DWARF specifies three kinds of simple location descriptions: Register, memory, 5686and implicit location descriptions. Note that a location description is 5687defined over certain ranges of a program, i.e the location of a variable may 5688change over the course of the program. Register and memory location 5689descriptions describe the *concrete location* of a source variable (in the 5690sense that a debugger might modify its value), whereas *implicit locations* 5691describe merely the actual *value* of a source variable which might not exist 5692in registers or in memory (see ``DW_OP_stack_value``). 5693 5694A ``llvm.dbg.addr`` or ``llvm.dbg.declare`` intrinsic describes an indirect 5695value (the address) of a source variable. The first operand of the intrinsic 5696must be an address of some kind. A DIExpression attached to the intrinsic 5697refines this address to produce a concrete location for the source variable. 5698 5699A ``llvm.dbg.value`` intrinsic describes the direct value of a source variable. 5700The first operand of the intrinsic may be a direct or indirect value. A 5701DIExpression attached to the intrinsic refines the first operand to produce a 5702direct value. For example, if the first operand is an indirect value, it may be 5703necessary to insert ``DW_OP_deref`` into the DIExpression in order to produce a 5704valid debug intrinsic. 5705 5706.. note:: 5707 5708 A DIExpression is interpreted in the same way regardless of which kind of 5709 debug intrinsic it's attached to. 5710 5711.. code-block:: text 5712 5713 !0 = !DIExpression(DW_OP_deref) 5714 !1 = !DIExpression(DW_OP_plus_uconst, 3) 5715 !1 = !DIExpression(DW_OP_constu, 3, DW_OP_plus) 5716 !2 = !DIExpression(DW_OP_bit_piece, 3, 7) 5717 !3 = !DIExpression(DW_OP_deref, DW_OP_constu, 3, DW_OP_plus, DW_OP_LLVM_fragment, 3, 7) 5718 !4 = !DIExpression(DW_OP_constu, 2, DW_OP_swap, DW_OP_xderef) 5719 !5 = !DIExpression(DW_OP_constu, 42, DW_OP_stack_value) 5720 5721DIArgList 5722"""""""""""" 5723 5724``DIArgList`` nodes hold a list of constant or SSA value references. These are 5725used in :ref:`debug intrinsics<dbg_intrinsics>` (currently only in 5726``llvm.dbg.value``) in combination with a ``DIExpression`` that uses the 5727``DW_OP_LLVM_arg`` operator. Because a DIArgList may refer to local values 5728within a function, it must only be used as a function argument, must always be 5729inlined, and cannot appear in named metadata. 5730 5731.. code-block:: text 5732 5733 llvm.dbg.value(metadata !DIArgList(i32 %a, i32 %b), 5734 metadata !16, 5735 metadata !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_plus)) 5736 5737DIFlags 5738""""""""""""""" 5739 5740These flags encode various properties of DINodes. 5741 5742The `ExportSymbols` flag marks a class, struct or union whose members 5743may be referenced as if they were defined in the containing class or 5744union. This flag is used to decide whether the DW_AT_export_symbols can 5745be used for the structure type. 5746 5747DIObjCProperty 5748"""""""""""""" 5749 5750``DIObjCProperty`` nodes represent Objective-C property nodes. 5751 5752.. code-block:: text 5753 5754 !3 = !DIObjCProperty(name: "foo", file: !1, line: 7, setter: "setFoo", 5755 getter: "getFoo", attributes: 7, type: !2) 5756 5757DIImportedEntity 5758"""""""""""""""" 5759 5760``DIImportedEntity`` nodes represent entities (such as modules) imported into a 5761compile unit. 5762 5763.. code-block:: text 5764 5765 !2 = !DIImportedEntity(tag: DW_TAG_imported_module, name: "foo", scope: !0, 5766 entity: !1, line: 7) 5767 5768DIMacro 5769""""""" 5770 5771``DIMacro`` nodes represent definition or undefinition of a macro identifiers. 5772The ``name:`` field is the macro identifier, followed by macro parameters when 5773defining a function-like macro, and the ``value`` field is the token-string 5774used to expand the macro identifier. 5775 5776.. code-block:: text 5777 5778 !2 = !DIMacro(macinfo: DW_MACINFO_define, line: 7, name: "foo(x)", 5779 value: "((x) + 1)") 5780 !3 = !DIMacro(macinfo: DW_MACINFO_undef, line: 30, name: "foo") 5781 5782DIMacroFile 5783""""""""""" 5784 5785``DIMacroFile`` nodes represent inclusion of source files. 5786The ``nodes:`` field is a list of ``DIMacro`` and ``DIMacroFile`` nodes that 5787appear in the included source file. 5788 5789.. code-block:: text 5790 5791 !2 = !DIMacroFile(macinfo: DW_MACINFO_start_file, line: 7, file: !2, 5792 nodes: !3) 5793 5794.. _DILabel: 5795 5796DILabel 5797""""""" 5798 5799``DILabel`` nodes represent labels within a :ref:`DISubprogram`. All fields of 5800a ``DILabel`` are mandatory. The ``scope:`` field must be one of either a 5801:ref:`DILexicalBlockFile`, a :ref:`DILexicalBlock`, or a :ref:`DISubprogram`. 5802The ``name:`` field is the label identifier. The ``file:`` field is the 5803:ref:`DIFile` the label is present in. The ``line:`` field is the source line 5804within the file where the label is declared. 5805 5806.. code-block:: text 5807 5808 !2 = !DILabel(scope: !0, name: "foo", file: !1, line: 7) 5809 5810'``tbaa``' Metadata 5811^^^^^^^^^^^^^^^^^^^ 5812 5813In LLVM IR, memory does not have types, so LLVM's own type system is not 5814suitable for doing type based alias analysis (TBAA). Instead, metadata is 5815added to the IR to describe a type system of a higher level language. This 5816can be used to implement C/C++ strict type aliasing rules, but it can also 5817be used to implement custom alias analysis behavior for other languages. 5818 5819This description of LLVM's TBAA system is broken into two parts: 5820:ref:`Semantics<tbaa_node_semantics>` talks about high level issues, and 5821:ref:`Representation<tbaa_node_representation>` talks about the metadata 5822encoding of various entities. 5823 5824It is always possible to trace any TBAA node to a "root" TBAA node (details 5825in the :ref:`Representation<tbaa_node_representation>` section). TBAA 5826nodes with different roots have an unknown aliasing relationship, and LLVM 5827conservatively infers ``MayAlias`` between them. The rules mentioned in 5828this section only pertain to TBAA nodes living under the same root. 5829 5830.. _tbaa_node_semantics: 5831 5832Semantics 5833""""""""" 5834 5835The TBAA metadata system, referred to as "struct path TBAA" (not to be 5836confused with ``tbaa.struct``), consists of the following high level 5837concepts: *Type Descriptors*, further subdivided into scalar type 5838descriptors and struct type descriptors; and *Access Tags*. 5839 5840**Type descriptors** describe the type system of the higher level language 5841being compiled. **Scalar type descriptors** describe types that do not 5842contain other types. Each scalar type has a parent type, which must also 5843be a scalar type or the TBAA root. Via this parent relation, scalar types 5844within a TBAA root form a tree. **Struct type descriptors** denote types 5845that contain a sequence of other type descriptors, at known offsets. These 5846contained type descriptors can either be struct type descriptors themselves 5847or scalar type descriptors. 5848 5849**Access tags** are metadata nodes attached to load and store instructions. 5850Access tags use type descriptors to describe the *location* being accessed 5851in terms of the type system of the higher level language. Access tags are 5852tuples consisting of a base type, an access type and an offset. The base 5853type is a scalar type descriptor or a struct type descriptor, the access 5854type is a scalar type descriptor, and the offset is a constant integer. 5855 5856The access tag ``(BaseTy, AccessTy, Offset)`` can describe one of two 5857things: 5858 5859 * If ``BaseTy`` is a struct type, the tag describes a memory access (load 5860 or store) of a value of type ``AccessTy`` contained in the struct type 5861 ``BaseTy`` at offset ``Offset``. 5862 5863 * If ``BaseTy`` is a scalar type, ``Offset`` must be 0 and ``BaseTy`` and 5864 ``AccessTy`` must be the same; and the access tag describes a scalar 5865 access with scalar type ``AccessTy``. 5866 5867We first define an ``ImmediateParent`` relation on ``(BaseTy, Offset)`` 5868tuples this way: 5869 5870 * If ``BaseTy`` is a scalar type then ``ImmediateParent(BaseTy, 0)`` is 5871 ``(ParentTy, 0)`` where ``ParentTy`` is the parent of the scalar type as 5872 described in the TBAA metadata. ``ImmediateParent(BaseTy, Offset)`` is 5873 undefined if ``Offset`` is non-zero. 5874 5875 * If ``BaseTy`` is a struct type then ``ImmediateParent(BaseTy, Offset)`` 5876 is ``(NewTy, NewOffset)`` where ``NewTy`` is the type contained in 5877 ``BaseTy`` at offset ``Offset`` and ``NewOffset`` is ``Offset`` adjusted 5878 to be relative within that inner type. 5879 5880A memory access with an access tag ``(BaseTy1, AccessTy1, Offset1)`` 5881aliases a memory access with an access tag ``(BaseTy2, AccessTy2, 5882Offset2)`` if either ``(BaseTy1, Offset1)`` is reachable from ``(Base2, 5883Offset2)`` via the ``Parent`` relation or vice versa. 5884 5885As a concrete example, the type descriptor graph for the following program 5886 5887.. code-block:: c 5888 5889 struct Inner { 5890 int i; // offset 0 5891 float f; // offset 4 5892 }; 5893 5894 struct Outer { 5895 float f; // offset 0 5896 double d; // offset 4 5897 struct Inner inner_a; // offset 12 5898 }; 5899 5900 void f(struct Outer* outer, struct Inner* inner, float* f, int* i, char* c) { 5901 outer->f = 0; // tag0: (OuterStructTy, FloatScalarTy, 0) 5902 outer->inner_a.i = 0; // tag1: (OuterStructTy, IntScalarTy, 12) 5903 outer->inner_a.f = 0.0; // tag2: (OuterStructTy, FloatScalarTy, 16) 5904 *f = 0.0; // tag3: (FloatScalarTy, FloatScalarTy, 0) 5905 } 5906 5907is (note that in C and C++, ``char`` can be used to access any arbitrary 5908type): 5909 5910.. code-block:: text 5911 5912 Root = "TBAA Root" 5913 CharScalarTy = ("char", Root, 0) 5914 FloatScalarTy = ("float", CharScalarTy, 0) 5915 DoubleScalarTy = ("double", CharScalarTy, 0) 5916 IntScalarTy = ("int", CharScalarTy, 0) 5917 InnerStructTy = {"Inner" (IntScalarTy, 0), (FloatScalarTy, 4)} 5918 OuterStructTy = {"Outer", (FloatScalarTy, 0), (DoubleScalarTy, 4), 5919 (InnerStructTy, 12)} 5920 5921 5922with (e.g.) ``ImmediateParent(OuterStructTy, 12)`` = ``(InnerStructTy, 59230)``, ``ImmediateParent(InnerStructTy, 0)`` = ``(IntScalarTy, 0)``, and 5924``ImmediateParent(IntScalarTy, 0)`` = ``(CharScalarTy, 0)``. 5925 5926.. _tbaa_node_representation: 5927 5928Representation 5929"""""""""""""" 5930 5931The root node of a TBAA type hierarchy is an ``MDNode`` with 0 operands or 5932with exactly one ``MDString`` operand. 5933 5934Scalar type descriptors are represented as an ``MDNode`` s with two 5935operands. The first operand is an ``MDString`` denoting the name of the 5936struct type. LLVM does not assign meaning to the value of this operand, it 5937only cares about it being an ``MDString``. The second operand is an 5938``MDNode`` which points to the parent for said scalar type descriptor, 5939which is either another scalar type descriptor or the TBAA root. Scalar 5940type descriptors can have an optional third argument, but that must be the 5941constant integer zero. 5942 5943Struct type descriptors are represented as ``MDNode`` s with an odd number 5944of operands greater than 1. The first operand is an ``MDString`` denoting 5945the name of the struct type. Like in scalar type descriptors the actual 5946value of this name operand is irrelevant to LLVM. After the name operand, 5947the struct type descriptors have a sequence of alternating ``MDNode`` and 5948``ConstantInt`` operands. With N starting from 1, the 2N - 1 th operand, 5949an ``MDNode``, denotes a contained field, and the 2N th operand, a 5950``ConstantInt``, is the offset of the said contained field. The offsets 5951must be in non-decreasing order. 5952 5953Access tags are represented as ``MDNode`` s with either 3 or 4 operands. 5954The first operand is an ``MDNode`` pointing to the node representing the 5955base type. The second operand is an ``MDNode`` pointing to the node 5956representing the access type. The third operand is a ``ConstantInt`` that 5957states the offset of the access. If a fourth field is present, it must be 5958a ``ConstantInt`` valued at 0 or 1. If it is 1 then the access tag states 5959that the location being accessed is "constant" (meaning 5960``pointsToConstantMemory`` should return true; see `other useful 5961AliasAnalysis methods <AliasAnalysis.html#OtherItfs>`_). The TBAA root of 5962the access type and the base type of an access tag must be the same, and 5963that is the TBAA root of the access tag. 5964 5965'``tbaa.struct``' Metadata 5966^^^^^^^^^^^^^^^^^^^^^^^^^^ 5967 5968The :ref:`llvm.memcpy <int_memcpy>` is often used to implement 5969aggregate assignment operations in C and similar languages, however it 5970is defined to copy a contiguous region of memory, which is more than 5971strictly necessary for aggregate types which contain holes due to 5972padding. Also, it doesn't contain any TBAA information about the fields 5973of the aggregate. 5974 5975``!tbaa.struct`` metadata can describe which memory subregions in a 5976memcpy are padding and what the TBAA tags of the struct are. 5977 5978The current metadata format is very simple. ``!tbaa.struct`` metadata 5979nodes are a list of operands which are in conceptual groups of three. 5980For each group of three, the first operand gives the byte offset of a 5981field in bytes, the second gives its size in bytes, and the third gives 5982its tbaa tag. e.g.: 5983 5984.. code-block:: llvm 5985 5986 !4 = !{ i64 0, i64 4, !1, i64 8, i64 4, !2 } 5987 5988This describes a struct with two fields. The first is at offset 0 bytes 5989with size 4 bytes, and has tbaa tag !1. The second is at offset 8 bytes 5990and has size 4 bytes and has tbaa tag !2. 5991 5992Note that the fields need not be contiguous. In this example, there is a 59934 byte gap between the two fields. This gap represents padding which 5994does not carry useful data and need not be preserved. 5995 5996'``noalias``' and '``alias.scope``' Metadata 5997^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 5998 5999``noalias`` and ``alias.scope`` metadata provide the ability to specify generic 6000noalias memory-access sets. This means that some collection of memory access 6001instructions (loads, stores, memory-accessing calls, etc.) that carry 6002``noalias`` metadata can specifically be specified not to alias with some other 6003collection of memory access instructions that carry ``alias.scope`` metadata. 6004Each type of metadata specifies a list of scopes where each scope has an id and 6005a domain. 6006 6007When evaluating an aliasing query, if for some domain, the set 6008of scopes with that domain in one instruction's ``alias.scope`` list is a 6009subset of (or equal to) the set of scopes for that domain in another 6010instruction's ``noalias`` list, then the two memory accesses are assumed not to 6011alias. 6012 6013Because scopes in one domain don't affect scopes in other domains, separate 6014domains can be used to compose multiple independent noalias sets. This is 6015used for example during inlining. As the noalias function parameters are 6016turned into noalias scope metadata, a new domain is used every time the 6017function is inlined. 6018 6019The metadata identifying each domain is itself a list containing one or two 6020entries. The first entry is the name of the domain. Note that if the name is a 6021string then it can be combined across functions and translation units. A 6022self-reference can be used to create globally unique domain names. A 6023descriptive string may optionally be provided as a second list entry. 6024 6025The metadata identifying each scope is also itself a list containing two or 6026three entries. The first entry is the name of the scope. Note that if the name 6027is a string then it can be combined across functions and translation units. A 6028self-reference can be used to create globally unique scope names. A metadata 6029reference to the scope's domain is the second entry. A descriptive string may 6030optionally be provided as a third list entry. 6031 6032For example, 6033 6034.. code-block:: llvm 6035 6036 ; Two scope domains: 6037 !0 = !{!0} 6038 !1 = !{!1} 6039 6040 ; Some scopes in these domains: 6041 !2 = !{!2, !0} 6042 !3 = !{!3, !0} 6043 !4 = !{!4, !1} 6044 6045 ; Some scope lists: 6046 !5 = !{!4} ; A list containing only scope !4 6047 !6 = !{!4, !3, !2} 6048 !7 = !{!3} 6049 6050 ; These two instructions don't alias: 6051 %0 = load float, float* %c, align 4, !alias.scope !5 6052 store float %0, float* %arrayidx.i, align 4, !noalias !5 6053 6054 ; These two instructions also don't alias (for domain !1, the set of scopes 6055 ; in the !alias.scope equals that in the !noalias list): 6056 %2 = load float, float* %c, align 4, !alias.scope !5 6057 store float %2, float* %arrayidx.i2, align 4, !noalias !6 6058 6059 ; These two instructions may alias (for domain !0, the set of scopes in 6060 ; the !noalias list is not a superset of, or equal to, the scopes in the 6061 ; !alias.scope list): 6062 %2 = load float, float* %c, align 4, !alias.scope !6 6063 store float %0, float* %arrayidx.i, align 4, !noalias !7 6064 6065'``fpmath``' Metadata 6066^^^^^^^^^^^^^^^^^^^^^ 6067 6068``fpmath`` metadata may be attached to any instruction of floating-point 6069type. It can be used to express the maximum acceptable error in the 6070result of that instruction, in ULPs, thus potentially allowing the 6071compiler to use a more efficient but less accurate method of computing 6072it. ULP is defined as follows: 6073 6074 If ``x`` is a real number that lies between two finite consecutive 6075 floating-point numbers ``a`` and ``b``, without being equal to one 6076 of them, then ``ulp(x) = |b - a|``, otherwise ``ulp(x)`` is the 6077 distance between the two non-equal finite floating-point numbers 6078 nearest ``x``. Moreover, ``ulp(NaN)`` is ``NaN``. 6079 6080The metadata node shall consist of a single positive float type number 6081representing the maximum relative error, for example: 6082 6083.. code-block:: llvm 6084 6085 !0 = !{ float 2.5 } ; maximum acceptable inaccuracy is 2.5 ULPs 6086 6087.. _range-metadata: 6088 6089'``range``' Metadata 6090^^^^^^^^^^^^^^^^^^^^ 6091 6092``range`` metadata may be attached only to ``load``, ``call`` and ``invoke`` of 6093integer types. It expresses the possible ranges the loaded value or the value 6094returned by the called function at this call site is in. If the loaded or 6095returned value is not in the specified range, the behavior is undefined. The 6096ranges are represented with a flattened list of integers. The loaded value or 6097the value returned is known to be in the union of the ranges defined by each 6098consecutive pair. Each pair has the following properties: 6099 6100- The type must match the type loaded by the instruction. 6101- The pair ``a,b`` represents the range ``[a,b)``. 6102- Both ``a`` and ``b`` are constants. 6103- The range is allowed to wrap. 6104- The range should not represent the full or empty set. That is, 6105 ``a!=b``. 6106 6107In addition, the pairs must be in signed order of the lower bound and 6108they must be non-contiguous. 6109 6110Examples: 6111 6112.. code-block:: llvm 6113 6114 %a = load i8, i8* %x, align 1, !range !0 ; Can only be 0 or 1 6115 %b = load i8, i8* %y, align 1, !range !1 ; Can only be 255 (-1), 0 or 1 6116 %c = call i8 @foo(), !range !2 ; Can only be 0, 1, 3, 4 or 5 6117 %d = invoke i8 @bar() to label %cont 6118 unwind label %lpad, !range !3 ; Can only be -2, -1, 3, 4 or 5 6119 ... 6120 !0 = !{ i8 0, i8 2 } 6121 !1 = !{ i8 255, i8 2 } 6122 !2 = !{ i8 0, i8 2, i8 3, i8 6 } 6123 !3 = !{ i8 -2, i8 0, i8 3, i8 6 } 6124 6125'``absolute_symbol``' Metadata 6126^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6127 6128``absolute_symbol`` metadata may be attached to a global variable 6129declaration. It marks the declaration as a reference to an absolute symbol, 6130which causes the backend to use absolute relocations for the symbol even 6131in position independent code, and expresses the possible ranges that the 6132global variable's *address* (not its value) is in, in the same format as 6133``range`` metadata, with the extension that the pair ``all-ones,all-ones`` 6134may be used to represent the full set. 6135 6136Example (assuming 64-bit pointers): 6137 6138.. code-block:: llvm 6139 6140 @a = external global i8, !absolute_symbol !0 ; Absolute symbol in range [0,256) 6141 @b = external global i8, !absolute_symbol !1 ; Absolute symbol in range [0,2^64) 6142 6143 ... 6144 !0 = !{ i64 0, i64 256 } 6145 !1 = !{ i64 -1, i64 -1 } 6146 6147'``callees``' Metadata 6148^^^^^^^^^^^^^^^^^^^^^^ 6149 6150``callees`` metadata may be attached to indirect call sites. If ``callees`` 6151metadata is attached to a call site, and any callee is not among the set of 6152functions provided by the metadata, the behavior is undefined. The intent of 6153this metadata is to facilitate optimizations such as indirect-call promotion. 6154For example, in the code below, the call instruction may only target the 6155``add`` or ``sub`` functions: 6156 6157.. code-block:: llvm 6158 6159 %result = call i64 %binop(i64 %x, i64 %y), !callees !0 6160 6161 ... 6162 !0 = !{i64 (i64, i64)* @add, i64 (i64, i64)* @sub} 6163 6164'``callback``' Metadata 6165^^^^^^^^^^^^^^^^^^^^^^^ 6166 6167``callback`` metadata may be attached to a function declaration, or definition. 6168(Call sites are excluded only due to the lack of a use case.) For ease of 6169exposition, we'll refer to the function annotated w/ metadata as a broker 6170function. The metadata describes how the arguments of a call to the broker are 6171in turn passed to the callback function specified by the metadata. Thus, the 6172``callback`` metadata provides a partial description of a call site inside the 6173broker function with regards to the arguments of a call to the broker. The only 6174semantic restriction on the broker function itself is that it is not allowed to 6175inspect or modify arguments referenced in the ``callback`` metadata as 6176pass-through to the callback function. 6177 6178The broker is not required to actually invoke the callback function at runtime. 6179However, the assumptions about not inspecting or modifying arguments that would 6180be passed to the specified callback function still hold, even if the callback 6181function is not dynamically invoked. The broker is allowed to invoke the 6182callback function more than once per invocation of the broker. The broker is 6183also allowed to invoke (directly or indirectly) the function passed as a 6184callback through another use. Finally, the broker is also allowed to relay the 6185callback callee invocation to a different thread. 6186 6187The metadata is structured as follows: At the outer level, ``callback`` 6188metadata is a list of ``callback`` encodings. Each encoding starts with a 6189constant ``i64`` which describes the argument position of the callback function 6190in the call to the broker. The following elements, except the last, describe 6191what arguments are passed to the callback function. Each element is again an 6192``i64`` constant identifying the argument of the broker that is passed through, 6193or ``i64 -1`` to indicate an unknown or inspected argument. The order in which 6194they are listed has to be the same in which they are passed to the callback 6195callee. The last element of the encoding is a boolean which specifies how 6196variadic arguments of the broker are handled. If it is true, all variadic 6197arguments of the broker are passed through to the callback function *after* the 6198arguments encoded explicitly before. 6199 6200In the code below, the ``pthread_create`` function is marked as a broker 6201through the ``!callback !1`` metadata. In the example, there is only one 6202callback encoding, namely ``!2``, associated with the broker. This encoding 6203identifies the callback function as the second argument of the broker (``i64 62042``) and the sole argument of the callback function as the third one of the 6205broker function (``i64 3``). 6206 6207.. FIXME why does the llvm-sphinx-docs builder give a highlighting 6208 error if the below is set to highlight as 'llvm', despite that we 6209 have misc.highlighting_failure set? 6210 6211.. code-block:: text 6212 6213 declare !callback !1 dso_local i32 @pthread_create(i64*, %union.pthread_attr_t*, i8* (i8*)*, i8*) 6214 6215 ... 6216 !2 = !{i64 2, i64 3, i1 false} 6217 !1 = !{!2} 6218 6219Another example is shown below. The callback callee is the second argument of 6220the ``__kmpc_fork_call`` function (``i64 2``). The callee is given two unknown 6221values (each identified by a ``i64 -1``) and afterwards all 6222variadic arguments that are passed to the ``__kmpc_fork_call`` call (due to the 6223final ``i1 true``). 6224 6225.. FIXME why does the llvm-sphinx-docs builder give a highlighting 6226 error if the below is set to highlight as 'llvm', despite that we 6227 have misc.highlighting_failure set? 6228 6229.. code-block:: text 6230 6231 declare !callback !0 dso_local void @__kmpc_fork_call(%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) 6232 6233 ... 6234 !1 = !{i64 2, i64 -1, i64 -1, i1 true} 6235 !0 = !{!1} 6236 6237 6238'``unpredictable``' Metadata 6239^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6240 6241``unpredictable`` metadata may be attached to any branch or switch 6242instruction. It can be used to express the unpredictability of control 6243flow. Similar to the llvm.expect intrinsic, it may be used to alter 6244optimizations related to compare and branch instructions. The metadata 6245is treated as a boolean value; if it exists, it signals that the branch 6246or switch that it is attached to is completely unpredictable. 6247 6248.. _md_dereferenceable: 6249 6250'``dereferenceable``' Metadata 6251^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6252 6253The existence of the ``!dereferenceable`` metadata on the instruction 6254tells the optimizer that the value loaded is known to be dereferenceable. 6255The number of bytes known to be dereferenceable is specified by the integer 6256value in the metadata node. This is analogous to the ''dereferenceable'' 6257attribute on parameters and return values. 6258 6259.. _md_dereferenceable_or_null: 6260 6261'``dereferenceable_or_null``' Metadata 6262^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6263 6264The existence of the ``!dereferenceable_or_null`` metadata on the 6265instruction tells the optimizer that the value loaded is known to be either 6266dereferenceable or null. 6267The number of bytes known to be dereferenceable is specified by the integer 6268value in the metadata node. This is analogous to the ''dereferenceable_or_null'' 6269attribute on parameters and return values. 6270 6271.. _llvm.loop: 6272 6273'``llvm.loop``' 6274^^^^^^^^^^^^^^^ 6275 6276It is sometimes useful to attach information to loop constructs. Currently, 6277loop metadata is implemented as metadata attached to the branch instruction 6278in the loop latch block. The loop metadata node is a list of 6279other metadata nodes, each representing a property of the loop. Usually, 6280the first item of the property node is a string. For example, the 6281``llvm.loop.unroll.count`` suggests an unroll factor to the loop 6282unroller: 6283 6284.. code-block:: llvm 6285 6286 br i1 %exitcond, label %._crit_edge, label %.lr.ph, !llvm.loop !0 6287 ... 6288 !0 = !{!0, !1, !2} 6289 !1 = !{!"llvm.loop.unroll.enable"} 6290 !2 = !{!"llvm.loop.unroll.count", i32 4} 6291 6292For legacy reasons, the first item of a loop metadata node must be a 6293reference to itself. Before the advent of the 'distinct' keyword, this 6294forced the preservation of otherwise identical metadata nodes. Since 6295the loop-metadata node can be attached to multiple nodes, the 'distinct' 6296keyword has become unnecessary. 6297 6298Prior to the property nodes, one or two ``DILocation`` (debug location) 6299nodes can be present in the list. The first, if present, identifies the 6300source-code location where the loop begins. The second, if present, 6301identifies the source-code location where the loop ends. 6302 6303Loop metadata nodes cannot be used as unique identifiers. They are 6304neither persistent for the same loop through transformations nor 6305necessarily unique to just one loop. 6306 6307'``llvm.loop.disable_nonforced``' 6308^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6309 6310This metadata disables all optional loop transformations unless 6311explicitly instructed using other transformation metadata such as 6312``llvm.loop.unroll.enable``. That is, no heuristic will try to determine 6313whether a transformation is profitable. The purpose is to avoid that the 6314loop is transformed to a different loop before an explicitly requested 6315(forced) transformation is applied. For instance, loop fusion can make 6316other transformations impossible. Mandatory loop canonicalizations such 6317as loop rotation are still applied. 6318 6319It is recommended to use this metadata in addition to any llvm.loop.* 6320transformation directive. Also, any loop should have at most one 6321directive applied to it (and a sequence of transformations built using 6322followup-attributes). Otherwise, which transformation will be applied 6323depends on implementation details such as the pass pipeline order. 6324 6325See :ref:`transformation-metadata` for details. 6326 6327'``llvm.loop.vectorize``' and '``llvm.loop.interleave``' 6328^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6329 6330Metadata prefixed with ``llvm.loop.vectorize`` or ``llvm.loop.interleave`` are 6331used to control per-loop vectorization and interleaving parameters such as 6332vectorization width and interleave count. These metadata should be used in 6333conjunction with ``llvm.loop`` loop identification metadata. The 6334``llvm.loop.vectorize`` and ``llvm.loop.interleave`` metadata are only 6335optimization hints and the optimizer will only interleave and vectorize loops if 6336it believes it is safe to do so. The ``llvm.loop.parallel_accesses`` metadata 6337which contains information about loop-carried memory dependencies can be helpful 6338in determining the safety of these transformations. 6339 6340'``llvm.loop.interleave.count``' Metadata 6341^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6342 6343This metadata suggests an interleave count to the loop interleaver. 6344The first operand is the string ``llvm.loop.interleave.count`` and the 6345second operand is an integer specifying the interleave count. For 6346example: 6347 6348.. code-block:: llvm 6349 6350 !0 = !{!"llvm.loop.interleave.count", i32 4} 6351 6352Note that setting ``llvm.loop.interleave.count`` to 1 disables interleaving 6353multiple iterations of the loop. If ``llvm.loop.interleave.count`` is set to 0 6354then the interleave count will be determined automatically. 6355 6356'``llvm.loop.vectorize.enable``' Metadata 6357^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6358 6359This metadata selectively enables or disables vectorization for the loop. The 6360first operand is the string ``llvm.loop.vectorize.enable`` and the second operand 6361is a bit. If the bit operand value is 1 vectorization is enabled. A value of 63620 disables vectorization: 6363 6364.. code-block:: llvm 6365 6366 !0 = !{!"llvm.loop.vectorize.enable", i1 0} 6367 !1 = !{!"llvm.loop.vectorize.enable", i1 1} 6368 6369'``llvm.loop.vectorize.predicate.enable``' Metadata 6370^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6371 6372This metadata selectively enables or disables creating predicated instructions 6373for the loop, which can enable folding of the scalar epilogue loop into the 6374main loop. The first operand is the string 6375``llvm.loop.vectorize.predicate.enable`` and the second operand is a bit. If 6376the bit operand value is 1 vectorization is enabled. A value of 0 disables 6377vectorization: 6378 6379.. code-block:: llvm 6380 6381 !0 = !{!"llvm.loop.vectorize.predicate.enable", i1 0} 6382 !1 = !{!"llvm.loop.vectorize.predicate.enable", i1 1} 6383 6384'``llvm.loop.vectorize.scalable.enable``' Metadata 6385^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6386 6387This metadata selectively enables or disables scalable vectorization for the 6388loop, and only has any effect if vectorization for the loop is already enabled. 6389The first operand is the string ``llvm.loop.vectorize.scalable.enable`` 6390and the second operand is a bit. If the bit operand value is 1 scalable 6391vectorization is enabled, whereas a value of 0 reverts to the default fixed 6392width vectorization: 6393 6394.. code-block:: llvm 6395 6396 !0 = !{!"llvm.loop.vectorize.scalable.enable", i1 0} 6397 !1 = !{!"llvm.loop.vectorize.scalable.enable", i1 1} 6398 6399'``llvm.loop.vectorize.width``' Metadata 6400^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6401 6402This metadata sets the target width of the vectorizer. The first 6403operand is the string ``llvm.loop.vectorize.width`` and the second 6404operand is an integer specifying the width. For example: 6405 6406.. code-block:: llvm 6407 6408 !0 = !{!"llvm.loop.vectorize.width", i32 4} 6409 6410Note that setting ``llvm.loop.vectorize.width`` to 1 disables 6411vectorization of the loop. If ``llvm.loop.vectorize.width`` is set to 64120 or if the loop does not have this metadata the width will be 6413determined automatically. 6414 6415'``llvm.loop.vectorize.followup_vectorized``' Metadata 6416^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6417 6418This metadata defines which loop attributes the vectorized loop will 6419have. See :ref:`transformation-metadata` for details. 6420 6421'``llvm.loop.vectorize.followup_epilogue``' Metadata 6422^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6423 6424This metadata defines which loop attributes the epilogue will have. The 6425epilogue is not vectorized and is executed when either the vectorized 6426loop is not known to preserve semantics (because e.g., it processes two 6427arrays that are found to alias by a runtime check) or for the last 6428iterations that do not fill a complete set of vector lanes. See 6429:ref:`Transformation Metadata <transformation-metadata>` for details. 6430 6431'``llvm.loop.vectorize.followup_all``' Metadata 6432^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6433 6434Attributes in the metadata will be added to both the vectorized and 6435epilogue loop. 6436See :ref:`Transformation Metadata <transformation-metadata>` for details. 6437 6438'``llvm.loop.unroll``' 6439^^^^^^^^^^^^^^^^^^^^^^ 6440 6441Metadata prefixed with ``llvm.loop.unroll`` are loop unrolling 6442optimization hints such as the unroll factor. ``llvm.loop.unroll`` 6443metadata should be used in conjunction with ``llvm.loop`` loop 6444identification metadata. The ``llvm.loop.unroll`` metadata are only 6445optimization hints and the unrolling will only be performed if the 6446optimizer believes it is safe to do so. 6447 6448'``llvm.loop.unroll.count``' Metadata 6449^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6450 6451This metadata suggests an unroll factor to the loop unroller. The 6452first operand is the string ``llvm.loop.unroll.count`` and the second 6453operand is a positive integer specifying the unroll factor. For 6454example: 6455 6456.. code-block:: llvm 6457 6458 !0 = !{!"llvm.loop.unroll.count", i32 4} 6459 6460If the trip count of the loop is less than the unroll count the loop 6461will be partially unrolled. 6462 6463'``llvm.loop.unroll.disable``' Metadata 6464^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6465 6466This metadata disables loop unrolling. The metadata has a single operand 6467which is the string ``llvm.loop.unroll.disable``. For example: 6468 6469.. code-block:: llvm 6470 6471 !0 = !{!"llvm.loop.unroll.disable"} 6472 6473'``llvm.loop.unroll.runtime.disable``' Metadata 6474^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6475 6476This metadata disables runtime loop unrolling. The metadata has a single 6477operand which is the string ``llvm.loop.unroll.runtime.disable``. For example: 6478 6479.. code-block:: llvm 6480 6481 !0 = !{!"llvm.loop.unroll.runtime.disable"} 6482 6483'``llvm.loop.unroll.enable``' Metadata 6484^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6485 6486This metadata suggests that the loop should be fully unrolled if the trip count 6487is known at compile time and partially unrolled if the trip count is not known 6488at compile time. The metadata has a single operand which is the string 6489``llvm.loop.unroll.enable``. For example: 6490 6491.. code-block:: llvm 6492 6493 !0 = !{!"llvm.loop.unroll.enable"} 6494 6495'``llvm.loop.unroll.full``' Metadata 6496^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6497 6498This metadata suggests that the loop should be unrolled fully. The 6499metadata has a single operand which is the string ``llvm.loop.unroll.full``. 6500For example: 6501 6502.. code-block:: llvm 6503 6504 !0 = !{!"llvm.loop.unroll.full"} 6505 6506'``llvm.loop.unroll.followup``' Metadata 6507^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6508 6509This metadata defines which loop attributes the unrolled loop will have. 6510See :ref:`Transformation Metadata <transformation-metadata>` for details. 6511 6512'``llvm.loop.unroll.followup_remainder``' Metadata 6513^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6514 6515This metadata defines which loop attributes the remainder loop after 6516partial/runtime unrolling will have. See 6517:ref:`Transformation Metadata <transformation-metadata>` for details. 6518 6519'``llvm.loop.unroll_and_jam``' 6520^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6521 6522This metadata is treated very similarly to the ``llvm.loop.unroll`` metadata 6523above, but affect the unroll and jam pass. In addition any loop with 6524``llvm.loop.unroll`` metadata but no ``llvm.loop.unroll_and_jam`` metadata will 6525disable unroll and jam (so ``llvm.loop.unroll`` metadata will be left to the 6526unroller, plus ``llvm.loop.unroll.disable`` metadata will disable unroll and jam 6527too.) 6528 6529The metadata for unroll and jam otherwise is the same as for ``unroll``. 6530``llvm.loop.unroll_and_jam.enable``, ``llvm.loop.unroll_and_jam.disable`` and 6531``llvm.loop.unroll_and_jam.count`` do the same as for unroll. 6532``llvm.loop.unroll_and_jam.full`` is not supported. Again these are only hints 6533and the normal safety checks will still be performed. 6534 6535'``llvm.loop.unroll_and_jam.count``' Metadata 6536^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6537 6538This metadata suggests an unroll and jam factor to use, similarly to 6539``llvm.loop.unroll.count``. The first operand is the string 6540``llvm.loop.unroll_and_jam.count`` and the second operand is a positive integer 6541specifying the unroll factor. For example: 6542 6543.. code-block:: llvm 6544 6545 !0 = !{!"llvm.loop.unroll_and_jam.count", i32 4} 6546 6547If the trip count of the loop is less than the unroll count the loop 6548will be partially unroll and jammed. 6549 6550'``llvm.loop.unroll_and_jam.disable``' Metadata 6551^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6552 6553This metadata disables loop unroll and jamming. The metadata has a single 6554operand which is the string ``llvm.loop.unroll_and_jam.disable``. For example: 6555 6556.. code-block:: llvm 6557 6558 !0 = !{!"llvm.loop.unroll_and_jam.disable"} 6559 6560'``llvm.loop.unroll_and_jam.enable``' Metadata 6561^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6562 6563This metadata suggests that the loop should be fully unroll and jammed if the 6564trip count is known at compile time and partially unrolled if the trip count is 6565not known at compile time. The metadata has a single operand which is the 6566string ``llvm.loop.unroll_and_jam.enable``. For example: 6567 6568.. code-block:: llvm 6569 6570 !0 = !{!"llvm.loop.unroll_and_jam.enable"} 6571 6572'``llvm.loop.unroll_and_jam.followup_outer``' Metadata 6573^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6574 6575This metadata defines which loop attributes the outer unrolled loop will 6576have. See :ref:`Transformation Metadata <transformation-metadata>` for 6577details. 6578 6579'``llvm.loop.unroll_and_jam.followup_inner``' Metadata 6580^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6581 6582This metadata defines which loop attributes the inner jammed loop will 6583have. See :ref:`Transformation Metadata <transformation-metadata>` for 6584details. 6585 6586'``llvm.loop.unroll_and_jam.followup_remainder_outer``' Metadata 6587^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6588 6589This metadata defines which attributes the epilogue of the outer loop 6590will have. This loop is usually unrolled, meaning there is no such 6591loop. This attribute will be ignored in this case. See 6592:ref:`Transformation Metadata <transformation-metadata>` for details. 6593 6594'``llvm.loop.unroll_and_jam.followup_remainder_inner``' Metadata 6595^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6596 6597This metadata defines which attributes the inner loop of the epilogue 6598will have. The outer epilogue will usually be unrolled, meaning there 6599can be multiple inner remainder loops. See 6600:ref:`Transformation Metadata <transformation-metadata>` for details. 6601 6602'``llvm.loop.unroll_and_jam.followup_all``' Metadata 6603^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6604 6605Attributes specified in the metadata is added to all 6606``llvm.loop.unroll_and_jam.*`` loops. See 6607:ref:`Transformation Metadata <transformation-metadata>` for details. 6608 6609'``llvm.loop.licm_versioning.disable``' Metadata 6610^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6611 6612This metadata indicates that the loop should not be versioned for the purpose 6613of enabling loop-invariant code motion (LICM). The metadata has a single operand 6614which is the string ``llvm.loop.licm_versioning.disable``. For example: 6615 6616.. code-block:: llvm 6617 6618 !0 = !{!"llvm.loop.licm_versioning.disable"} 6619 6620'``llvm.loop.distribute.enable``' Metadata 6621^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6622 6623Loop distribution allows splitting a loop into multiple loops. Currently, 6624this is only performed if the entire loop cannot be vectorized due to unsafe 6625memory dependencies. The transformation will attempt to isolate the unsafe 6626dependencies into their own loop. 6627 6628This metadata can be used to selectively enable or disable distribution of the 6629loop. The first operand is the string ``llvm.loop.distribute.enable`` and the 6630second operand is a bit. If the bit operand value is 1 distribution is 6631enabled. A value of 0 disables distribution: 6632 6633.. code-block:: llvm 6634 6635 !0 = !{!"llvm.loop.distribute.enable", i1 0} 6636 !1 = !{!"llvm.loop.distribute.enable", i1 1} 6637 6638This metadata should be used in conjunction with ``llvm.loop`` loop 6639identification metadata. 6640 6641'``llvm.loop.distribute.followup_coincident``' Metadata 6642^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6643 6644This metadata defines which attributes extracted loops with no cyclic 6645dependencies will have (i.e. can be vectorized). See 6646:ref:`Transformation Metadata <transformation-metadata>` for details. 6647 6648'``llvm.loop.distribute.followup_sequential``' Metadata 6649^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6650 6651This metadata defines which attributes the isolated loops with unsafe 6652memory dependencies will have. See 6653:ref:`Transformation Metadata <transformation-metadata>` for details. 6654 6655'``llvm.loop.distribute.followup_fallback``' Metadata 6656^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6657 6658If loop versioning is necessary, this metadata defined the attributes 6659the non-distributed fallback version will have. See 6660:ref:`Transformation Metadata <transformation-metadata>` for details. 6661 6662'``llvm.loop.distribute.followup_all``' Metadata 6663^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6664 6665The attributes in this metadata is added to all followup loops of the 6666loop distribution pass. See 6667:ref:`Transformation Metadata <transformation-metadata>` for details. 6668 6669'``llvm.licm.disable``' Metadata 6670^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6671 6672This metadata indicates that loop-invariant code motion (LICM) should not be 6673performed on this loop. The metadata has a single operand which is the string 6674``llvm.licm.disable``. For example: 6675 6676.. code-block:: llvm 6677 6678 !0 = !{!"llvm.licm.disable"} 6679 6680Note that although it operates per loop it isn't given the llvm.loop prefix 6681as it is not affected by the ``llvm.loop.disable_nonforced`` metadata. 6682 6683'``llvm.access.group``' Metadata 6684^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6685 6686``llvm.access.group`` metadata can be attached to any instruction that 6687potentially accesses memory. It can point to a single distinct metadata 6688node, which we call access group. This node represents all memory access 6689instructions referring to it via ``llvm.access.group``. When an 6690instruction belongs to multiple access groups, it can also point to a 6691list of accesses groups, illustrated by the following example. 6692 6693.. code-block:: llvm 6694 6695 %val = load i32, i32* %arrayidx, !llvm.access.group !0 6696 ... 6697 !0 = !{!1, !2} 6698 !1 = distinct !{} 6699 !2 = distinct !{} 6700 6701It is illegal for the list node to be empty since it might be confused 6702with an access group. 6703 6704The access group metadata node must be 'distinct' to avoid collapsing 6705multiple access groups by content. A access group metadata node must 6706always be empty which can be used to distinguish an access group 6707metadata node from a list of access groups. Being empty avoids the 6708situation that the content must be updated which, because metadata is 6709immutable by design, would required finding and updating all references 6710to the access group node. 6711 6712The access group can be used to refer to a memory access instruction 6713without pointing to it directly (which is not possible in global 6714metadata). Currently, the only metadata making use of it is 6715``llvm.loop.parallel_accesses``. 6716 6717'``llvm.loop.parallel_accesses``' Metadata 6718^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6719 6720The ``llvm.loop.parallel_accesses`` metadata refers to one or more 6721access group metadata nodes (see ``llvm.access.group``). It denotes that 6722no loop-carried memory dependence exist between it and other instructions 6723in the loop with this metadata. 6724 6725Let ``m1`` and ``m2`` be two instructions that both have the 6726``llvm.access.group`` metadata to the access group ``g1``, respectively 6727``g2`` (which might be identical). If a loop contains both access groups 6728in its ``llvm.loop.parallel_accesses`` metadata, then the compiler can 6729assume that there is no dependency between ``m1`` and ``m2`` carried by 6730this loop. Instructions that belong to multiple access groups are 6731considered having this property if at least one of the access groups 6732matches the ``llvm.loop.parallel_accesses`` list. 6733 6734If all memory-accessing instructions in a loop have 6735``llvm.access.group`` metadata that each refer to one of the access 6736groups of a loop's ``llvm.loop.parallel_accesses`` metadata, then the 6737loop has no loop carried memory dependences and is considered to be a 6738parallel loop. 6739 6740Note that if not all memory access instructions belong to an access 6741group referred to by ``llvm.loop.parallel_accesses``, then the loop must 6742not be considered trivially parallel. Additional 6743memory dependence analysis is required to make that determination. As a fail 6744safe mechanism, this causes loops that were originally parallel to be considered 6745sequential (if optimization passes that are unaware of the parallel semantics 6746insert new memory instructions into the loop body). 6747 6748Example of a loop that is considered parallel due to its correct use of 6749both ``llvm.access.group`` and ``llvm.loop.parallel_accesses`` 6750metadata types. 6751 6752.. code-block:: llvm 6753 6754 for.body: 6755 ... 6756 %val0 = load i32, i32* %arrayidx, !llvm.access.group !1 6757 ... 6758 store i32 %val0, i32* %arrayidx1, !llvm.access.group !1 6759 ... 6760 br i1 %exitcond, label %for.end, label %for.body, !llvm.loop !0 6761 6762 for.end: 6763 ... 6764 !0 = distinct !{!0, !{!"llvm.loop.parallel_accesses", !1}} 6765 !1 = distinct !{} 6766 6767It is also possible to have nested parallel loops: 6768 6769.. code-block:: llvm 6770 6771 outer.for.body: 6772 ... 6773 %val1 = load i32, i32* %arrayidx3, !llvm.access.group !4 6774 ... 6775 br label %inner.for.body 6776 6777 inner.for.body: 6778 ... 6779 %val0 = load i32, i32* %arrayidx1, !llvm.access.group !3 6780 ... 6781 store i32 %val0, i32* %arrayidx2, !llvm.access.group !3 6782 ... 6783 br i1 %exitcond, label %inner.for.end, label %inner.for.body, !llvm.loop !1 6784 6785 inner.for.end: 6786 ... 6787 store i32 %val1, i32* %arrayidx4, !llvm.access.group !4 6788 ... 6789 br i1 %exitcond, label %outer.for.end, label %outer.for.body, !llvm.loop !2 6790 6791 outer.for.end: ; preds = %for.body 6792 ... 6793 !1 = distinct !{!1, !{!"llvm.loop.parallel_accesses", !3}} ; metadata for the inner loop 6794 !2 = distinct !{!2, !{!"llvm.loop.parallel_accesses", !3, !4}} ; metadata for the outer loop 6795 !3 = distinct !{} ; access group for instructions in the inner loop (which are implicitly contained in outer loop as well) 6796 !4 = distinct !{} ; access group for instructions in the outer, but not the inner loop 6797 6798'``llvm.loop.mustprogress``' Metadata 6799^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6800 6801The ``llvm.loop.mustprogress`` metadata indicates that this loop is required to 6802terminate, unwind, or interact with the environment in an observable way e.g. 6803via a volatile memory access, I/O, or other synchronization. If such a loop is 6804not found to interact with the environment in an observable way, the loop may 6805be removed. This corresponds to the ``mustprogress`` function attribute. 6806 6807'``irr_loop``' Metadata 6808^^^^^^^^^^^^^^^^^^^^^^^ 6809 6810``irr_loop`` metadata may be attached to the terminator instruction of a basic 6811block that's an irreducible loop header (note that an irreducible loop has more 6812than once header basic blocks.) If ``irr_loop`` metadata is attached to the 6813terminator instruction of a basic block that is not really an irreducible loop 6814header, the behavior is undefined. The intent of this metadata is to improve the 6815accuracy of the block frequency propagation. For example, in the code below, the 6816block ``header0`` may have a loop header weight (relative to the other headers of 6817the irreducible loop) of 100: 6818 6819.. code-block:: llvm 6820 6821 header0: 6822 ... 6823 br i1 %cmp, label %t1, label %t2, !irr_loop !0 6824 6825 ... 6826 !0 = !{"loop_header_weight", i64 100} 6827 6828Irreducible loop header weights are typically based on profile data. 6829 6830.. _md_invariant.group: 6831 6832'``invariant.group``' Metadata 6833^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6834 6835The experimental ``invariant.group`` metadata may be attached to 6836``load``/``store`` instructions referencing a single metadata with no entries. 6837The existence of the ``invariant.group`` metadata on the instruction tells 6838the optimizer that every ``load`` and ``store`` to the same pointer operand 6839can be assumed to load or store the same 6840value (but see the ``llvm.launder.invariant.group`` intrinsic which affects 6841when two pointers are considered the same). Pointers returned by bitcast or 6842getelementptr with only zero indices are considered the same. 6843 6844Examples: 6845 6846.. code-block:: llvm 6847 6848 @unknownPtr = external global i8 6849 ... 6850 %ptr = alloca i8 6851 store i8 42, i8* %ptr, !invariant.group !0 6852 call void @foo(i8* %ptr) 6853 6854 %a = load i8, i8* %ptr, !invariant.group !0 ; Can assume that value under %ptr didn't change 6855 call void @foo(i8* %ptr) 6856 6857 %newPtr = call i8* @getPointer(i8* %ptr) 6858 %c = load i8, i8* %newPtr, !invariant.group !0 ; Can't assume anything, because we only have information about %ptr 6859 6860 %unknownValue = load i8, i8* @unknownPtr 6861 store i8 %unknownValue, i8* %ptr, !invariant.group !0 ; Can assume that %unknownValue == 42 6862 6863 call void @foo(i8* %ptr) 6864 %newPtr2 = call i8* @llvm.launder.invariant.group(i8* %ptr) 6865 %d = load i8, i8* %newPtr2, !invariant.group !0 ; Can't step through launder.invariant.group to get value of %ptr 6866 6867 ... 6868 declare void @foo(i8*) 6869 declare i8* @getPointer(i8*) 6870 declare i8* @llvm.launder.invariant.group(i8*) 6871 6872 !0 = !{} 6873 6874The invariant.group metadata must be dropped when replacing one pointer by 6875another based on aliasing information. This is because invariant.group is tied 6876to the SSA value of the pointer operand. 6877 6878.. code-block:: llvm 6879 6880 %v = load i8, i8* %x, !invariant.group !0 6881 ; if %x mustalias %y then we can replace the above instruction with 6882 %v = load i8, i8* %y 6883 6884Note that this is an experimental feature, which means that its semantics might 6885change in the future. 6886 6887'``type``' Metadata 6888^^^^^^^^^^^^^^^^^^^ 6889 6890See :doc:`TypeMetadata`. 6891 6892'``associated``' Metadata 6893^^^^^^^^^^^^^^^^^^^^^^^^^ 6894 6895The ``associated`` metadata may be attached to a global variable definition with 6896a single argument that references a global object (optionally through an alias). 6897 6898This metadata lowers to the ELF section flag ``SHF_LINK_ORDER`` which prevents 6899discarding of the global variable in linker GC unless the referenced object is 6900also discarded. The linker support for this feature is spotty. For best 6901compatibility, globals carrying this metadata should: 6902 6903- Be in ``@llvm.compiler.used``. 6904- If the referenced global variable is in a comdat, be in the same comdat. 6905 6906``!associated`` can not express many-to-one relationship. A global variable with 6907the metadata should generally not be referenced by a function: the function may 6908be inlined into other functions, leading to more references to the metadata. 6909Ideally we would want to keep metadata alive as long as any inline location is 6910alive, but this many-to-one relationship is not representable. Moreover, if the 6911metadata is retained while the function is discarded, the linker will report an 6912error of a relocation referencing a discarded section. 6913 6914The metadata is often used with an explicit section consisting of valid C 6915identifiers so that the runtime can find the metadata section with 6916linker-defined encapsulation symbols ``__start_<section_name>`` and 6917``__stop_<section_name>``. 6918 6919It does not have any effect on non-ELF targets. 6920 6921Example: 6922 6923.. code-block:: text 6924 6925 $a = comdat any 6926 @a = global i32 1, comdat $a 6927 @b = internal global i32 2, comdat $a, section "abc", !associated !0 6928 !0 = !{i32* @a} 6929 6930 6931'``prof``' Metadata 6932^^^^^^^^^^^^^^^^^^^ 6933 6934The ``prof`` metadata is used to record profile data in the IR. 6935The first operand of the metadata node indicates the profile metadata 6936type. There are currently 3 types: 6937:ref:`branch_weights<prof_node_branch_weights>`, 6938:ref:`function_entry_count<prof_node_function_entry_count>`, and 6939:ref:`VP<prof_node_VP>`. 6940 6941.. _prof_node_branch_weights: 6942 6943branch_weights 6944"""""""""""""" 6945 6946Branch weight metadata attached to a branch, select, switch or call instruction 6947represents the likeliness of the associated branch being taken. 6948For more information, see :doc:`BranchWeightMetadata`. 6949 6950.. _prof_node_function_entry_count: 6951 6952function_entry_count 6953"""""""""""""""""""" 6954 6955Function entry count metadata can be attached to function definitions 6956to record the number of times the function is called. Used with BFI 6957information, it is also used to derive the basic block profile count. 6958For more information, see :doc:`BranchWeightMetadata`. 6959 6960.. _prof_node_VP: 6961 6962VP 6963"" 6964 6965VP (value profile) metadata can be attached to instructions that have 6966value profile information. Currently this is indirect calls (where it 6967records the hottest callees) and calls to memory intrinsics such as memcpy, 6968memmove, and memset (where it records the hottest byte lengths). 6969 6970Each VP metadata node contains "VP" string, then a uint32_t value for the value 6971profiling kind, a uint64_t value for the total number of times the instruction 6972is executed, followed by uint64_t value and execution count pairs. 6973The value profiling kind is 0 for indirect call targets and 1 for memory 6974operations. For indirect call targets, each profile value is a hash 6975of the callee function name, and for memory operations each value is the 6976byte length. 6977 6978Note that the value counts do not need to add up to the total count 6979listed in the third operand (in practice only the top hottest values 6980are tracked and reported). 6981 6982Indirect call example: 6983 6984.. code-block:: llvm 6985 6986 call void %f(), !prof !1 6987 !1 = !{!"VP", i32 0, i64 1600, i64 7651369219802541373, i64 1030, i64 -4377547752858689819, i64 410} 6988 6989Note that the VP type is 0 (the second operand), which indicates this is 6990an indirect call value profile data. The third operand indicates that the 6991indirect call executed 1600 times. The 4th and 6th operands give the 6992hashes of the 2 hottest target functions' names (this is the same hash used 6993to represent function names in the profile database), and the 5th and 7th 6994operands give the execution count that each of the respective prior target 6995functions was called. 6996 6997.. _md_annotation: 6998 6999'``annotation``' Metadata 7000^^^^^^^^^^^^^^^^^^^^^^^^^ 7001 7002The ``annotation`` metadata can be used to attach a tuple of annotation strings 7003to any instruction. This metadata does not impact the semantics of the program 7004and may only be used to provide additional insight about the program and 7005transformations to users. 7006 7007Example: 7008 7009.. code-block:: text 7010 7011 %a.addr = alloca float*, align 8, !annotation !0 7012 !0 = !{!"auto-init"} 7013 7014Module Flags Metadata 7015===================== 7016 7017Information about the module as a whole is difficult to convey to LLVM's 7018subsystems. The LLVM IR isn't sufficient to transmit this information. 7019The ``llvm.module.flags`` named metadata exists in order to facilitate 7020this. These flags are in the form of key / value pairs --- much like a 7021dictionary --- making it easy for any subsystem who cares about a flag to 7022look it up. 7023 7024The ``llvm.module.flags`` metadata contains a list of metadata triplets. 7025Each triplet has the following form: 7026 7027- The first element is a *behavior* flag, which specifies the behavior 7028 when two (or more) modules are merged together, and it encounters two 7029 (or more) metadata with the same ID. The supported behaviors are 7030 described below. 7031- The second element is a metadata string that is a unique ID for the 7032 metadata. Each module may only have one flag entry for each unique ID (not 7033 including entries with the **Require** behavior). 7034- The third element is the value of the flag. 7035 7036When two (or more) modules are merged together, the resulting 7037``llvm.module.flags`` metadata is the union of the modules' flags. That is, for 7038each unique metadata ID string, there will be exactly one entry in the merged 7039modules ``llvm.module.flags`` metadata table, and the value for that entry will 7040be determined by the merge behavior flag, as described below. The only exception 7041is that entries with the *Require* behavior are always preserved. 7042 7043The following behaviors are supported: 7044 7045.. list-table:: 7046 :header-rows: 1 7047 :widths: 10 90 7048 7049 * - Value 7050 - Behavior 7051 7052 * - 1 7053 - **Error** 7054 Emits an error if two values disagree, otherwise the resulting value 7055 is that of the operands. 7056 7057 * - 2 7058 - **Warning** 7059 Emits a warning if two values disagree. The result value will be the 7060 operand for the flag from the first module being linked, or the max 7061 if the other module uses **Max** (in which case the resulting flag 7062 will be **Max**). 7063 7064 * - 3 7065 - **Require** 7066 Adds a requirement that another module flag be present and have a 7067 specified value after linking is performed. The value must be a 7068 metadata pair, where the first element of the pair is the ID of the 7069 module flag to be restricted, and the second element of the pair is 7070 the value the module flag should be restricted to. This behavior can 7071 be used to restrict the allowable results (via triggering of an 7072 error) of linking IDs with the **Override** behavior. 7073 7074 * - 4 7075 - **Override** 7076 Uses the specified value, regardless of the behavior or value of the 7077 other module. If both modules specify **Override**, but the values 7078 differ, an error will be emitted. 7079 7080 * - 5 7081 - **Append** 7082 Appends the two values, which are required to be metadata nodes. 7083 7084 * - 6 7085 - **AppendUnique** 7086 Appends the two values, which are required to be metadata 7087 nodes. However, duplicate entries in the second list are dropped 7088 during the append operation. 7089 7090 * - 7 7091 - **Max** 7092 Takes the max of the two values, which are required to be integers. 7093 7094It is an error for a particular unique flag ID to have multiple behaviors, 7095except in the case of **Require** (which adds restrictions on another metadata 7096value) or **Override**. 7097 7098An example of module flags: 7099 7100.. code-block:: llvm 7101 7102 !0 = !{ i32 1, !"foo", i32 1 } 7103 !1 = !{ i32 4, !"bar", i32 37 } 7104 !2 = !{ i32 2, !"qux", i32 42 } 7105 !3 = !{ i32 3, !"qux", 7106 !{ 7107 !"foo", i32 1 7108 } 7109 } 7110 !llvm.module.flags = !{ !0, !1, !2, !3 } 7111 7112- Metadata ``!0`` has the ID ``!"foo"`` and the value '1'. The behavior 7113 if two or more ``!"foo"`` flags are seen is to emit an error if their 7114 values are not equal. 7115 7116- Metadata ``!1`` has the ID ``!"bar"`` and the value '37'. The 7117 behavior if two or more ``!"bar"`` flags are seen is to use the value 7118 '37'. 7119 7120- Metadata ``!2`` has the ID ``!"qux"`` and the value '42'. The 7121 behavior if two or more ``!"qux"`` flags are seen is to emit a 7122 warning if their values are not equal. 7123 7124- Metadata ``!3`` has the ID ``!"qux"`` and the value: 7125 7126 :: 7127 7128 !{ !"foo", i32 1 } 7129 7130 The behavior is to emit an error if the ``llvm.module.flags`` does not 7131 contain a flag with the ID ``!"foo"`` that has the value '1' after linking is 7132 performed. 7133 7134Synthesized Functions Module Flags Metadata 7135------------------------------------------- 7136 7137These metadata specify the default attributes synthesized functions should have. 7138These metadata are currently respected by a few instrumentation passes, such as 7139sanitizers. 7140 7141These metadata correspond to a few function attributes with significant code 7142generation behaviors. Function attributes with just optimization purposes 7143should not be listed because the performance impact of these synthesized 7144functions is small. 7145 7146- "frame-pointer": **Max**. The value can be 0, 1, or 2. A synthesized function 7147 will get the "frame-pointer" function attribute, with value being "none", 7148 "non-leaf", or "all", respectively. 7149- "uwtable": **Max**. The value can be 0 or 1. If the value is 1, a synthesized 7150 function will get the ``uwtable`` function attribute. 7151 7152Objective-C Garbage Collection Module Flags Metadata 7153---------------------------------------------------- 7154 7155On the Mach-O platform, Objective-C stores metadata about garbage 7156collection in a special section called "image info". The metadata 7157consists of a version number and a bitmask specifying what types of 7158garbage collection are supported (if any) by the file. If two or more 7159modules are linked together their garbage collection metadata needs to 7160be merged rather than appended together. 7161 7162The Objective-C garbage collection module flags metadata consists of the 7163following key-value pairs: 7164 7165.. list-table:: 7166 :header-rows: 1 7167 :widths: 30 70 7168 7169 * - Key 7170 - Value 7171 7172 * - ``Objective-C Version`` 7173 - **[Required]** --- The Objective-C ABI version. Valid values are 1 and 2. 7174 7175 * - ``Objective-C Image Info Version`` 7176 - **[Required]** --- The version of the image info section. Currently 7177 always 0. 7178 7179 * - ``Objective-C Image Info Section`` 7180 - **[Required]** --- The section to place the metadata. Valid values are 7181 ``"__OBJC, __image_info, regular"`` for Objective-C ABI version 1, and 7182 ``"__DATA,__objc_imageinfo, regular, no_dead_strip"`` for 7183 Objective-C ABI version 2. 7184 7185 * - ``Objective-C Garbage Collection`` 7186 - **[Required]** --- Specifies whether garbage collection is supported or 7187 not. Valid values are 0, for no garbage collection, and 2, for garbage 7188 collection supported. 7189 7190 * - ``Objective-C GC Only`` 7191 - **[Optional]** --- Specifies that only garbage collection is supported. 7192 If present, its value must be 6. This flag requires that the 7193 ``Objective-C Garbage Collection`` flag have the value 2. 7194 7195Some important flag interactions: 7196 7197- If a module with ``Objective-C Garbage Collection`` set to 0 is 7198 merged with a module with ``Objective-C Garbage Collection`` set to 7199 2, then the resulting module has the 7200 ``Objective-C Garbage Collection`` flag set to 0. 7201- A module with ``Objective-C Garbage Collection`` set to 0 cannot be 7202 merged with a module with ``Objective-C GC Only`` set to 6. 7203 7204C type width Module Flags Metadata 7205---------------------------------- 7206 7207The ARM backend emits a section into each generated object file describing the 7208options that it was compiled with (in a compiler-independent way) to prevent 7209linking incompatible objects, and to allow automatic library selection. Some 7210of these options are not visible at the IR level, namely wchar_t width and enum 7211width. 7212 7213To pass this information to the backend, these options are encoded in module 7214flags metadata, using the following key-value pairs: 7215 7216.. list-table:: 7217 :header-rows: 1 7218 :widths: 30 70 7219 7220 * - Key 7221 - Value 7222 7223 * - short_wchar 7224 - * 0 --- sizeof(wchar_t) == 4 7225 * 1 --- sizeof(wchar_t) == 2 7226 7227 * - short_enum 7228 - * 0 --- Enums are at least as large as an ``int``. 7229 * 1 --- Enums are stored in the smallest integer type which can 7230 represent all of its values. 7231 7232For example, the following metadata section specifies that the module was 7233compiled with a ``wchar_t`` width of 4 bytes, and the underlying type of an 7234enum is the smallest type which can represent all of its values:: 7235 7236 !llvm.module.flags = !{!0, !1} 7237 !0 = !{i32 1, !"short_wchar", i32 1} 7238 !1 = !{i32 1, !"short_enum", i32 0} 7239 7240LTO Post-Link Module Flags Metadata 7241----------------------------------- 7242 7243Some optimisations are only when the entire LTO unit is present in the current 7244module. This is represented by the ``LTOPostLink`` module flags metadata, which 7245will be created with a value of ``1`` when LTO linking occurs. 7246 7247Automatic Linker Flags Named Metadata 7248===================================== 7249 7250Some targets support embedding of flags to the linker inside individual object 7251files. Typically this is used in conjunction with language extensions which 7252allow source files to contain linker command line options, and have these 7253automatically be transmitted to the linker via object files. 7254 7255These flags are encoded in the IR using named metadata with the name 7256``!llvm.linker.options``. Each operand is expected to be a metadata node 7257which should be a list of other metadata nodes, each of which should be a 7258list of metadata strings defining linker options. 7259 7260For example, the following metadata section specifies two separate sets of 7261linker options, presumably to link against ``libz`` and the ``Cocoa`` 7262framework:: 7263 7264 !0 = !{ !"-lz" } 7265 !1 = !{ !"-framework", !"Cocoa" } 7266 !llvm.linker.options = !{ !0, !1 } 7267 7268The metadata encoding as lists of lists of options, as opposed to a collapsed 7269list of options, is chosen so that the IR encoding can use multiple option 7270strings to specify e.g., a single library, while still having that specifier be 7271preserved as an atomic element that can be recognized by a target specific 7272assembly writer or object file emitter. 7273 7274Each individual option is required to be either a valid option for the target's 7275linker, or an option that is reserved by the target specific assembly writer or 7276object file emitter. No other aspect of these options is defined by the IR. 7277 7278Dependent Libs Named Metadata 7279============================= 7280 7281Some targets support embedding of strings into object files to indicate 7282a set of libraries to add to the link. Typically this is used in conjunction 7283with language extensions which allow source files to explicitly declare the 7284libraries they depend on, and have these automatically be transmitted to the 7285linker via object files. 7286 7287The list is encoded in the IR using named metadata with the name 7288``!llvm.dependent-libraries``. Each operand is expected to be a metadata node 7289which should contain a single string operand. 7290 7291For example, the following metadata section contains two library specifiers:: 7292 7293 !0 = !{!"a library specifier"} 7294 !1 = !{!"another library specifier"} 7295 !llvm.dependent-libraries = !{ !0, !1 } 7296 7297Each library specifier will be handled independently by the consuming linker. 7298The effect of the library specifiers are defined by the consuming linker. 7299 7300.. _summary: 7301 7302ThinLTO Summary 7303=============== 7304 7305Compiling with `ThinLTO <https://clang.llvm.org/docs/ThinLTO.html>`_ 7306causes the building of a compact summary of the module that is emitted into 7307the bitcode. The summary is emitted into the LLVM assembly and identified 7308in syntax by a caret ('``^``'). 7309 7310The summary is parsed into a bitcode output, along with the Module 7311IR, via the "``llvm-as``" tool. Tools that parse the Module IR for the purposes 7312of optimization (e.g. "``clang -x ir``" and "``opt``"), will ignore the 7313summary entries (just as they currently ignore summary entries in a bitcode 7314input file). 7315 7316Eventually, the summary will be parsed into a ModuleSummaryIndex object under 7317the same conditions where summary index is currently built from bitcode. 7318Specifically, tools that test the Thin Link portion of a ThinLTO compile 7319(i.e. llvm-lto and llvm-lto2), or when parsing a combined index 7320for a distributed ThinLTO backend via clang's "``-fthinlto-index=<>``" flag 7321(this part is not yet implemented, use llvm-as to create a bitcode object 7322before feeding into thin link tools for now). 7323 7324There are currently 3 types of summary entries in the LLVM assembly: 7325:ref:`module paths<module_path_summary>`, 7326:ref:`global values<gv_summary>`, and 7327:ref:`type identifiers<typeid_summary>`. 7328 7329.. _module_path_summary: 7330 7331Module Path Summary Entry 7332------------------------- 7333 7334Each module path summary entry lists a module containing global values included 7335in the summary. For a single IR module there will be one such entry, but 7336in a combined summary index produced during the thin link, there will be 7337one module path entry per linked module with summary. 7338 7339Example: 7340 7341.. code-block:: text 7342 7343 ^0 = module: (path: "/path/to/file.o", hash: (2468601609, 1329373163, 1565878005, 638838075, 3148790418)) 7344 7345The ``path`` field is a string path to the bitcode file, and the ``hash`` 7346field is the 160-bit SHA-1 hash of the IR bitcode contents, used for 7347incremental builds and caching. 7348 7349.. _gv_summary: 7350 7351Global Value Summary Entry 7352-------------------------- 7353 7354Each global value summary entry corresponds to a global value defined or 7355referenced by a summarized module. 7356 7357Example: 7358 7359.. code-block:: text 7360 7361 ^4 = gv: (name: "f"[, summaries: (Summary)[, (Summary)]*]?) ; guid = 14740650423002898831 7362 7363For declarations, there will not be a summary list. For definitions, a 7364global value will contain a list of summaries, one per module containing 7365a definition. There can be multiple entries in a combined summary index 7366for symbols with weak linkage. 7367 7368Each ``Summary`` format will depend on whether the global value is a 7369:ref:`function<function_summary>`, :ref:`variable<variable_summary>`, or 7370:ref:`alias<alias_summary>`. 7371 7372.. _function_summary: 7373 7374Function Summary 7375^^^^^^^^^^^^^^^^ 7376 7377If the global value is a function, the ``Summary`` entry will look like: 7378 7379.. code-block:: text 7380 7381 function: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0), insts: 2[, FuncFlags]?[, Calls]?[, TypeIdInfo]?[, Params]?[, Refs]? 7382 7383The ``module`` field includes the summary entry id for the module containing 7384this definition, and the ``flags`` field contains information such as 7385the linkage type, a flag indicating whether it is legal to import the 7386definition, whether it is globally live and whether the linker resolved it 7387to a local definition (the latter two are populated during the thin link). 7388The ``insts`` field contains the number of IR instructions in the function. 7389Finally, there are several optional fields: :ref:`FuncFlags<funcflags_summary>`, 7390:ref:`Calls<calls_summary>`, :ref:`TypeIdInfo<typeidinfo_summary>`, 7391:ref:`Params<params_summary>`, :ref:`Refs<refs_summary>`. 7392 7393.. _variable_summary: 7394 7395Global Variable Summary 7396^^^^^^^^^^^^^^^^^^^^^^^ 7397 7398If the global value is a variable, the ``Summary`` entry will look like: 7399 7400.. code-block:: text 7401 7402 variable: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0)[, Refs]? 7403 7404The variable entry contains a subset of the fields in a 7405:ref:`function summary <function_summary>`, see the descriptions there. 7406 7407.. _alias_summary: 7408 7409Alias Summary 7410^^^^^^^^^^^^^ 7411 7412If the global value is an alias, the ``Summary`` entry will look like: 7413 7414.. code-block:: text 7415 7416 alias: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0), aliasee: ^2) 7417 7418The ``module`` and ``flags`` fields are as described for a 7419:ref:`function summary <function_summary>`. The ``aliasee`` field 7420contains a reference to the global value summary entry of the aliasee. 7421 7422.. _funcflags_summary: 7423 7424Function Flags 7425^^^^^^^^^^^^^^ 7426 7427The optional ``FuncFlags`` field looks like: 7428 7429.. code-block:: text 7430 7431 funcFlags: (readNone: 0, readOnly: 0, noRecurse: 0, returnDoesNotAlias: 0) 7432 7433If unspecified, flags are assumed to hold the conservative ``false`` value of 7434``0``. 7435 7436.. _calls_summary: 7437 7438Calls 7439^^^^^ 7440 7441The optional ``Calls`` field looks like: 7442 7443.. code-block:: text 7444 7445 calls: ((Callee)[, (Callee)]*) 7446 7447where each ``Callee`` looks like: 7448 7449.. code-block:: text 7450 7451 callee: ^1[, hotness: None]?[, relbf: 0]? 7452 7453The ``callee`` refers to the summary entry id of the callee. At most one 7454of ``hotness`` (which can take the values ``Unknown``, ``Cold``, ``None``, 7455``Hot``, and ``Critical``), and ``relbf`` (which holds the integer 7456branch frequency relative to the entry frequency, scaled down by 2^8) 7457may be specified. The defaults are ``Unknown`` and ``0``, respectively. 7458 7459.. _params_summary: 7460 7461Params 7462^^^^^^ 7463 7464The optional ``Params`` is used by ``StackSafety`` and looks like: 7465 7466.. code-block:: text 7467 7468 Params: ((Param)[, (Param)]*) 7469 7470where each ``Param`` describes pointer parameter access inside of the 7471function and looks like: 7472 7473.. code-block:: text 7474 7475 param: 4, offset: [0, 5][, calls: ((Callee)[, (Callee)]*)]? 7476 7477where the first ``param`` is the number of the parameter it describes, 7478``offset`` is the inclusive range of offsets from the pointer parameter to bytes 7479which can be accessed by the function. This range does not include accesses by 7480function calls from ``calls`` list. 7481 7482where each ``Callee`` describes how parameter is forwarded into other 7483functions and looks like: 7484 7485.. code-block:: text 7486 7487 callee: ^3, param: 5, offset: [-3, 3] 7488 7489The ``callee`` refers to the summary entry id of the callee, ``param`` is 7490the number of the callee parameter which points into the callers parameter 7491with offset known to be inside of the ``offset`` range. ``calls`` will be 7492consumed and removed by thin link stage to update ``Param::offset`` so it 7493covers all accesses possible by ``calls``. 7494 7495Pointer parameter without corresponding ``Param`` is considered unsafe and we 7496assume that access with any offset is possible. 7497 7498Example: 7499 7500If we have the following function: 7501 7502.. code-block:: text 7503 7504 define i64 @foo(i64* %0, i32* %1, i8* %2, i8 %3) { 7505 store i32* %1, i32** @x 7506 %5 = getelementptr inbounds i8, i8* %2, i64 5 7507 %6 = load i8, i8* %5 7508 %7 = getelementptr inbounds i8, i8* %2, i8 %3 7509 tail call void @bar(i8 %3, i8* %7) 7510 %8 = load i64, i64* %0 7511 ret i64 %8 7512 } 7513 7514We can expect the record like this: 7515 7516.. code-block:: text 7517 7518 params: ((param: 0, offset: [0, 7]),(param: 2, offset: [5, 5], calls: ((callee: ^3, param: 1, offset: [-128, 127])))) 7519 7520The function may access just 8 bytes of the parameter %0 . ``calls`` is empty, 7521so the parameter is either not used for function calls or ``offset`` already 7522covers all accesses from nested function calls. 7523Parameter %1 escapes, so access is unknown. 7524The function itself can access just a single byte of the parameter %2. Additional 7525access is possible inside of the ``@bar`` or ``^3``. The function adds signed 7526offset to the pointer and passes the result as the argument %1 into ``^3``. 7527This record itself does not tell us how ``^3`` will access the parameter. 7528Parameter %3 is not a pointer. 7529 7530.. _refs_summary: 7531 7532Refs 7533^^^^ 7534 7535The optional ``Refs`` field looks like: 7536 7537.. code-block:: text 7538 7539 refs: ((Ref)[, (Ref)]*) 7540 7541where each ``Ref`` contains a reference to the summary id of the referenced 7542value (e.g. ``^1``). 7543 7544.. _typeidinfo_summary: 7545 7546TypeIdInfo 7547^^^^^^^^^^ 7548 7549The optional ``TypeIdInfo`` field, used for 7550`Control Flow Integrity <https://clang.llvm.org/docs/ControlFlowIntegrity.html>`_, 7551looks like: 7552 7553.. code-block:: text 7554 7555 typeIdInfo: [(TypeTests)]?[, (TypeTestAssumeVCalls)]?[, (TypeCheckedLoadVCalls)]?[, (TypeTestAssumeConstVCalls)]?[, (TypeCheckedLoadConstVCalls)]? 7556 7557These optional fields have the following forms: 7558 7559TypeTests 7560""""""""" 7561 7562.. code-block:: text 7563 7564 typeTests: (TypeIdRef[, TypeIdRef]*) 7565 7566Where each ``TypeIdRef`` refers to a :ref:`type id<typeid_summary>` 7567by summary id or ``GUID``. 7568 7569TypeTestAssumeVCalls 7570"""""""""""""""""""" 7571 7572.. code-block:: text 7573 7574 typeTestAssumeVCalls: (VFuncId[, VFuncId]*) 7575 7576Where each VFuncId has the format: 7577 7578.. code-block:: text 7579 7580 vFuncId: (TypeIdRef, offset: 16) 7581 7582Where each ``TypeIdRef`` refers to a :ref:`type id<typeid_summary>` 7583by summary id or ``GUID`` preceded by a ``guid:`` tag. 7584 7585TypeCheckedLoadVCalls 7586""""""""""""""""""""" 7587 7588.. code-block:: text 7589 7590 typeCheckedLoadVCalls: (VFuncId[, VFuncId]*) 7591 7592Where each VFuncId has the format described for ``TypeTestAssumeVCalls``. 7593 7594TypeTestAssumeConstVCalls 7595""""""""""""""""""""""""" 7596 7597.. code-block:: text 7598 7599 typeTestAssumeConstVCalls: (ConstVCall[, ConstVCall]*) 7600 7601Where each ConstVCall has the format: 7602 7603.. code-block:: text 7604 7605 (VFuncId, args: (Arg[, Arg]*)) 7606 7607and where each VFuncId has the format described for ``TypeTestAssumeVCalls``, 7608and each Arg is an integer argument number. 7609 7610TypeCheckedLoadConstVCalls 7611"""""""""""""""""""""""""" 7612 7613.. code-block:: text 7614 7615 typeCheckedLoadConstVCalls: (ConstVCall[, ConstVCall]*) 7616 7617Where each ConstVCall has the format described for 7618``TypeTestAssumeConstVCalls``. 7619 7620.. _typeid_summary: 7621 7622Type ID Summary Entry 7623--------------------- 7624 7625Each type id summary entry corresponds to a type identifier resolution 7626which is generated during the LTO link portion of the compile when building 7627with `Control Flow Integrity <https://clang.llvm.org/docs/ControlFlowIntegrity.html>`_, 7628so these are only present in a combined summary index. 7629 7630Example: 7631 7632.. code-block:: text 7633 7634 ^4 = typeid: (name: "_ZTS1A", summary: (typeTestRes: (kind: allOnes, sizeM1BitWidth: 7[, alignLog2: 0]?[, sizeM1: 0]?[, bitMask: 0]?[, inlineBits: 0]?)[, WpdResolutions]?)) ; guid = 7004155349499253778 7635 7636The ``typeTestRes`` gives the type test resolution ``kind`` (which may 7637be ``unsat``, ``byteArray``, ``inline``, ``single``, or ``allOnes``), and 7638the ``size-1`` bit width. It is followed by optional flags, which default to 0, 7639and an optional WpdResolutions (whole program devirtualization resolution) 7640field that looks like: 7641 7642.. code-block:: text 7643 7644 wpdResolutions: ((offset: 0, WpdRes)[, (offset: 1, WpdRes)]* 7645 7646where each entry is a mapping from the given byte offset to the whole-program 7647devirtualization resolution WpdRes, that has one of the following formats: 7648 7649.. code-block:: text 7650 7651 wpdRes: (kind: branchFunnel) 7652 wpdRes: (kind: singleImpl, singleImplName: "_ZN1A1nEi") 7653 wpdRes: (kind: indir) 7654 7655Additionally, each wpdRes has an optional ``resByArg`` field, which 7656describes the resolutions for calls with all constant integer arguments: 7657 7658.. code-block:: text 7659 7660 resByArg: (ResByArg[, ResByArg]*) 7661 7662where ResByArg is: 7663 7664.. code-block:: text 7665 7666 args: (Arg[, Arg]*), byArg: (kind: UniformRetVal[, info: 0][, byte: 0][, bit: 0]) 7667 7668Where the ``kind`` can be ``Indir``, ``UniformRetVal``, ``UniqueRetVal`` 7669or ``VirtualConstProp``. The ``info`` field is only used if the kind 7670is ``UniformRetVal`` (indicates the uniform return value), or 7671``UniqueRetVal`` (holds the return value associated with the unique vtable 7672(0 or 1)). The ``byte`` and ``bit`` fields are only used if the target does 7673not support the use of absolute symbols to store constants. 7674 7675.. _intrinsicglobalvariables: 7676 7677Intrinsic Global Variables 7678========================== 7679 7680LLVM has a number of "magic" global variables that contain data that 7681affect code generation or other IR semantics. These are documented here. 7682All globals of this sort should have a section specified as 7683"``llvm.metadata``". This section and all globals that start with 7684"``llvm.``" are reserved for use by LLVM. 7685 7686.. _gv_llvmused: 7687 7688The '``llvm.used``' Global Variable 7689----------------------------------- 7690 7691The ``@llvm.used`` global is an array which has 7692:ref:`appending linkage <linkage_appending>`. This array contains a list of 7693pointers to named global variables, functions and aliases which may optionally 7694have a pointer cast formed of bitcast or getelementptr. For example, a legal 7695use of it is: 7696 7697.. code-block:: llvm 7698 7699 @X = global i8 4 7700 @Y = global i32 123 7701 7702 @llvm.used = appending global [2 x i8*] [ 7703 i8* @X, 7704 i8* bitcast (i32* @Y to i8*) 7705 ], section "llvm.metadata" 7706 7707If a symbol appears in the ``@llvm.used`` list, then the compiler, assembler, 7708and linker are required to treat the symbol as if there is a reference to the 7709symbol that it cannot see (which is why they have to be named). For example, if 7710a variable has internal linkage and no references other than that from the 7711``@llvm.used`` list, it cannot be deleted. This is commonly used to represent 7712references from inline asms and other things the compiler cannot "see", and 7713corresponds to "``attribute((used))``" in GNU C. 7714 7715On some targets, the code generator must emit a directive to the 7716assembler or object file to prevent the assembler and linker from 7717removing the symbol. 7718 7719.. _gv_llvmcompilerused: 7720 7721The '``llvm.compiler.used``' Global Variable 7722-------------------------------------------- 7723 7724The ``@llvm.compiler.used`` directive is the same as the ``@llvm.used`` 7725directive, except that it only prevents the compiler from touching the 7726symbol. On targets that support it, this allows an intelligent linker to 7727optimize references to the symbol without being impeded as it would be 7728by ``@llvm.used``. 7729 7730This is a rare construct that should only be used in rare circumstances, 7731and should not be exposed to source languages. 7732 7733.. _gv_llvmglobalctors: 7734 7735The '``llvm.global_ctors``' Global Variable 7736------------------------------------------- 7737 7738.. code-block:: llvm 7739 7740 %0 = type { i32, void ()*, i8* } 7741 @llvm.global_ctors = appending global [1 x %0] [%0 { i32 65535, void ()* @ctor, i8* @data }] 7742 7743The ``@llvm.global_ctors`` array contains a list of constructor 7744functions, priorities, and an associated global or function. 7745The functions referenced by this array will be called in ascending order 7746of priority (i.e. lowest first) when the module is loaded. The order of 7747functions with the same priority is not defined. 7748 7749If the third field is non-null, and points to a global variable 7750or function, the initializer function will only run if the associated 7751data from the current module is not discarded. 7752On ELF the referenced global variable or function must be in a comdat. 7753 7754.. _llvmglobaldtors: 7755 7756The '``llvm.global_dtors``' Global Variable 7757------------------------------------------- 7758 7759.. code-block:: llvm 7760 7761 %0 = type { i32, void ()*, i8* } 7762 @llvm.global_dtors = appending global [1 x %0] [%0 { i32 65535, void ()* @dtor, i8* @data }] 7763 7764The ``@llvm.global_dtors`` array contains a list of destructor 7765functions, priorities, and an associated global or function. 7766The functions referenced by this array will be called in descending 7767order of priority (i.e. highest first) when the module is unloaded. The 7768order of functions with the same priority is not defined. 7769 7770If the third field is non-null, and points to a global variable 7771or function, the destructor function will only run if the associated 7772data from the current module is not discarded. 7773On ELF the referenced global variable or function must be in a comdat. 7774 7775Instruction Reference 7776===================== 7777 7778The LLVM instruction set consists of several different classifications 7779of instructions: :ref:`terminator instructions <terminators>`, :ref:`binary 7780instructions <binaryops>`, :ref:`bitwise binary 7781instructions <bitwiseops>`, :ref:`memory instructions <memoryops>`, and 7782:ref:`other instructions <otherops>`. 7783 7784.. _terminators: 7785 7786Terminator Instructions 7787----------------------- 7788 7789As mentioned :ref:`previously <functionstructure>`, every basic block in a 7790program ends with a "Terminator" instruction, which indicates which 7791block should be executed after the current block is finished. These 7792terminator instructions typically yield a '``void``' value: they produce 7793control flow, not values (the one exception being the 7794':ref:`invoke <i_invoke>`' instruction). 7795 7796The terminator instructions are: ':ref:`ret <i_ret>`', 7797':ref:`br <i_br>`', ':ref:`switch <i_switch>`', 7798':ref:`indirectbr <i_indirectbr>`', ':ref:`invoke <i_invoke>`', 7799':ref:`callbr <i_callbr>`' 7800':ref:`resume <i_resume>`', ':ref:`catchswitch <i_catchswitch>`', 7801':ref:`catchret <i_catchret>`', 7802':ref:`cleanupret <i_cleanupret>`', 7803and ':ref:`unreachable <i_unreachable>`'. 7804 7805.. _i_ret: 7806 7807'``ret``' Instruction 7808^^^^^^^^^^^^^^^^^^^^^ 7809 7810Syntax: 7811""""""" 7812 7813:: 7814 7815 ret <type> <value> ; Return a value from a non-void function 7816 ret void ; Return from void function 7817 7818Overview: 7819""""""""" 7820 7821The '``ret``' instruction is used to return control flow (and optionally 7822a value) from a function back to the caller. 7823 7824There are two forms of the '``ret``' instruction: one that returns a 7825value and then causes control flow, and one that just causes control 7826flow to occur. 7827 7828Arguments: 7829"""""""""" 7830 7831The '``ret``' instruction optionally accepts a single argument, the 7832return value. The type of the return value must be a ':ref:`first 7833class <t_firstclass>`' type. 7834 7835A function is not :ref:`well formed <wellformed>` if it has a non-void 7836return type and contains a '``ret``' instruction with no return value or 7837a return value with a type that does not match its type, or if it has a 7838void return type and contains a '``ret``' instruction with a return 7839value. 7840 7841Semantics: 7842"""""""""" 7843 7844When the '``ret``' instruction is executed, control flow returns back to 7845the calling function's context. If the caller is a 7846":ref:`call <i_call>`" instruction, execution continues at the 7847instruction after the call. If the caller was an 7848":ref:`invoke <i_invoke>`" instruction, execution continues at the 7849beginning of the "normal" destination block. If the instruction returns 7850a value, that value shall set the call or invoke instruction's return 7851value. 7852 7853Example: 7854"""""""" 7855 7856.. code-block:: llvm 7857 7858 ret i32 5 ; Return an integer value of 5 7859 ret void ; Return from a void function 7860 ret { i32, i8 } { i32 4, i8 2 } ; Return a struct of values 4 and 2 7861 7862.. _i_br: 7863 7864'``br``' Instruction 7865^^^^^^^^^^^^^^^^^^^^ 7866 7867Syntax: 7868""""""" 7869 7870:: 7871 7872 br i1 <cond>, label <iftrue>, label <iffalse> 7873 br label <dest> ; Unconditional branch 7874 7875Overview: 7876""""""""" 7877 7878The '``br``' instruction is used to cause control flow to transfer to a 7879different basic block in the current function. There are two forms of 7880this instruction, corresponding to a conditional branch and an 7881unconditional branch. 7882 7883Arguments: 7884"""""""""" 7885 7886The conditional branch form of the '``br``' instruction takes a single 7887'``i1``' value and two '``label``' values. The unconditional form of the 7888'``br``' instruction takes a single '``label``' value as a target. 7889 7890Semantics: 7891"""""""""" 7892 7893Upon execution of a conditional '``br``' instruction, the '``i1``' 7894argument is evaluated. If the value is ``true``, control flows to the 7895'``iftrue``' ``label`` argument. If "cond" is ``false``, control flows 7896to the '``iffalse``' ``label`` argument. 7897If '``cond``' is ``poison`` or ``undef``, this instruction has undefined 7898behavior. 7899 7900Example: 7901"""""""" 7902 7903.. code-block:: llvm 7904 7905 Test: 7906 %cond = icmp eq i32 %a, %b 7907 br i1 %cond, label %IfEqual, label %IfUnequal 7908 IfEqual: 7909 ret i32 1 7910 IfUnequal: 7911 ret i32 0 7912 7913.. _i_switch: 7914 7915'``switch``' Instruction 7916^^^^^^^^^^^^^^^^^^^^^^^^ 7917 7918Syntax: 7919""""""" 7920 7921:: 7922 7923 switch <intty> <value>, label <defaultdest> [ <intty> <val>, label <dest> ... ] 7924 7925Overview: 7926""""""""" 7927 7928The '``switch``' instruction is used to transfer control flow to one of 7929several different places. It is a generalization of the '``br``' 7930instruction, allowing a branch to occur to one of many possible 7931destinations. 7932 7933Arguments: 7934"""""""""" 7935 7936The '``switch``' instruction uses three parameters: an integer 7937comparison value '``value``', a default '``label``' destination, and an 7938array of pairs of comparison value constants and '``label``'s. The table 7939is not allowed to contain duplicate constant entries. 7940 7941Semantics: 7942"""""""""" 7943 7944The ``switch`` instruction specifies a table of values and destinations. 7945When the '``switch``' instruction is executed, this table is searched 7946for the given value. If the value is found, control flow is transferred 7947to the corresponding destination; otherwise, control flow is transferred 7948to the default destination. 7949If '``value``' is ``poison`` or ``undef``, this instruction has undefined 7950behavior. 7951 7952Implementation: 7953""""""""""""""" 7954 7955Depending on properties of the target machine and the particular 7956``switch`` instruction, this instruction may be code generated in 7957different ways. For example, it could be generated as a series of 7958chained conditional branches or with a lookup table. 7959 7960Example: 7961"""""""" 7962 7963.. code-block:: llvm 7964 7965 ; Emulate a conditional br instruction 7966 %Val = zext i1 %value to i32 7967 switch i32 %Val, label %truedest [ i32 0, label %falsedest ] 7968 7969 ; Emulate an unconditional br instruction 7970 switch i32 0, label %dest [ ] 7971 7972 ; Implement a jump table: 7973 switch i32 %val, label %otherwise [ i32 0, label %onzero 7974 i32 1, label %onone 7975 i32 2, label %ontwo ] 7976 7977.. _i_indirectbr: 7978 7979'``indirectbr``' Instruction 7980^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 7981 7982Syntax: 7983""""""" 7984 7985:: 7986 7987 indirectbr <somety>* <address>, [ label <dest1>, label <dest2>, ... ] 7988 7989Overview: 7990""""""""" 7991 7992The '``indirectbr``' instruction implements an indirect branch to a 7993label within the current function, whose address is specified by 7994"``address``". Address must be derived from a 7995:ref:`blockaddress <blockaddress>` constant. 7996 7997Arguments: 7998"""""""""" 7999 8000The '``address``' argument is the address of the label to jump to. The 8001rest of the arguments indicate the full set of possible destinations 8002that the address may point to. Blocks are allowed to occur multiple 8003times in the destination list, though this isn't particularly useful. 8004 8005This destination list is required so that dataflow analysis has an 8006accurate understanding of the CFG. 8007 8008Semantics: 8009"""""""""" 8010 8011Control transfers to the block specified in the address argument. All 8012possible destination blocks must be listed in the label list, otherwise 8013this instruction has undefined behavior. This implies that jumps to 8014labels defined in other functions have undefined behavior as well. 8015If '``address``' is ``poison`` or ``undef``, this instruction has undefined 8016behavior. 8017 8018Implementation: 8019""""""""""""""" 8020 8021This is typically implemented with a jump through a register. 8022 8023Example: 8024"""""""" 8025 8026.. code-block:: llvm 8027 8028 indirectbr i8* %Addr, [ label %bb1, label %bb2, label %bb3 ] 8029 8030.. _i_invoke: 8031 8032'``invoke``' Instruction 8033^^^^^^^^^^^^^^^^^^^^^^^^ 8034 8035Syntax: 8036""""""" 8037 8038:: 8039 8040 <result> = invoke [cconv] [ret attrs] [addrspace(<num>)] <ty>|<fnty> <fnptrval>(<function args>) [fn attrs] 8041 [operand bundles] to label <normal label> unwind label <exception label> 8042 8043Overview: 8044""""""""" 8045 8046The '``invoke``' instruction causes control to transfer to a specified 8047function, with the possibility of control flow transfer to either the 8048'``normal``' label or the '``exception``' label. If the callee function 8049returns with the "``ret``" instruction, control flow will return to the 8050"normal" label. If the callee (or any indirect callees) returns via the 8051":ref:`resume <i_resume>`" instruction or other exception handling 8052mechanism, control is interrupted and continued at the dynamically 8053nearest "exception" label. 8054 8055The '``exception``' label is a `landing 8056pad <ExceptionHandling.html#overview>`_ for the exception. As such, 8057'``exception``' label is required to have the 8058":ref:`landingpad <i_landingpad>`" instruction, which contains the 8059information about the behavior of the program after unwinding happens, 8060as its first non-PHI instruction. The restrictions on the 8061"``landingpad``" instruction's tightly couples it to the "``invoke``" 8062instruction, so that the important information contained within the 8063"``landingpad``" instruction can't be lost through normal code motion. 8064 8065Arguments: 8066"""""""""" 8067 8068This instruction requires several arguments: 8069 8070#. The optional "cconv" marker indicates which :ref:`calling 8071 convention <callingconv>` the call should use. If none is 8072 specified, the call defaults to using C calling conventions. 8073#. The optional :ref:`Parameter Attributes <paramattrs>` list for return 8074 values. Only '``zeroext``', '``signext``', and '``inreg``' attributes 8075 are valid here. 8076#. The optional addrspace attribute can be used to indicate the address space 8077 of the called function. If it is not specified, the program address space 8078 from the :ref:`datalayout string<langref_datalayout>` will be used. 8079#. '``ty``': the type of the call instruction itself which is also the 8080 type of the return value. Functions that return no value are marked 8081 ``void``. 8082#. '``fnty``': shall be the signature of the function being invoked. The 8083 argument types must match the types implied by this signature. This 8084 type can be omitted if the function is not varargs. 8085#. '``fnptrval``': An LLVM value containing a pointer to a function to 8086 be invoked. In most cases, this is a direct function invocation, but 8087 indirect ``invoke``'s are just as possible, calling an arbitrary pointer 8088 to function value. 8089#. '``function args``': argument list whose types match the function 8090 signature argument types and parameter attributes. All arguments must 8091 be of :ref:`first class <t_firstclass>` type. If the function signature 8092 indicates the function accepts a variable number of arguments, the 8093 extra arguments can be specified. 8094#. '``normal label``': the label reached when the called function 8095 executes a '``ret``' instruction. 8096#. '``exception label``': the label reached when a callee returns via 8097 the :ref:`resume <i_resume>` instruction or other exception handling 8098 mechanism. 8099#. The optional :ref:`function attributes <fnattrs>` list. 8100#. The optional :ref:`operand bundles <opbundles>` list. 8101 8102Semantics: 8103"""""""""" 8104 8105This instruction is designed to operate as a standard '``call``' 8106instruction in most regards. The primary difference is that it 8107establishes an association with a label, which is used by the runtime 8108library to unwind the stack. 8109 8110This instruction is used in languages with destructors to ensure that 8111proper cleanup is performed in the case of either a ``longjmp`` or a 8112thrown exception. Additionally, this is important for implementation of 8113'``catch``' clauses in high-level languages that support them. 8114 8115For the purposes of the SSA form, the definition of the value returned 8116by the '``invoke``' instruction is deemed to occur on the edge from the 8117current block to the "normal" label. If the callee unwinds then no 8118return value is available. 8119 8120Example: 8121"""""""" 8122 8123.. code-block:: llvm 8124 8125 %retval = invoke i32 @Test(i32 15) to label %Continue 8126 unwind label %TestCleanup ; i32:retval set 8127 %retval = invoke coldcc i32 %Testfnptr(i32 15) to label %Continue 8128 unwind label %TestCleanup ; i32:retval set 8129 8130.. _i_callbr: 8131 8132'``callbr``' Instruction 8133^^^^^^^^^^^^^^^^^^^^^^^^ 8134 8135Syntax: 8136""""""" 8137 8138:: 8139 8140 <result> = callbr [cconv] [ret attrs] [addrspace(<num>)] <ty>|<fnty> <fnptrval>(<function args>) [fn attrs] 8141 [operand bundles] to label <fallthrough label> [indirect labels] 8142 8143Overview: 8144""""""""" 8145 8146The '``callbr``' instruction causes control to transfer to a specified 8147function, with the possibility of control flow transfer to either the 8148'``fallthrough``' label or one of the '``indirect``' labels. 8149 8150This instruction should only be used to implement the "goto" feature of gcc 8151style inline assembly. Any other usage is an error in the IR verifier. 8152 8153Arguments: 8154"""""""""" 8155 8156This instruction requires several arguments: 8157 8158#. The optional "cconv" marker indicates which :ref:`calling 8159 convention <callingconv>` the call should use. If none is 8160 specified, the call defaults to using C calling conventions. 8161#. The optional :ref:`Parameter Attributes <paramattrs>` list for return 8162 values. Only '``zeroext``', '``signext``', and '``inreg``' attributes 8163 are valid here. 8164#. The optional addrspace attribute can be used to indicate the address space 8165 of the called function. If it is not specified, the program address space 8166 from the :ref:`datalayout string<langref_datalayout>` will be used. 8167#. '``ty``': the type of the call instruction itself which is also the 8168 type of the return value. Functions that return no value are marked 8169 ``void``. 8170#. '``fnty``': shall be the signature of the function being called. The 8171 argument types must match the types implied by this signature. This 8172 type can be omitted if the function is not varargs. 8173#. '``fnptrval``': An LLVM value containing a pointer to a function to 8174 be called. In most cases, this is a direct function call, but 8175 other ``callbr``'s are just as possible, calling an arbitrary pointer 8176 to function value. 8177#. '``function args``': argument list whose types match the function 8178 signature argument types and parameter attributes. All arguments must 8179 be of :ref:`first class <t_firstclass>` type. If the function signature 8180 indicates the function accepts a variable number of arguments, the 8181 extra arguments can be specified. 8182#. '``fallthrough label``': the label reached when the inline assembly's 8183 execution exits the bottom. 8184#. '``indirect labels``': the labels reached when a callee transfers control 8185 to a location other than the '``fallthrough label``'. The blockaddress 8186 constant for these should also be in the list of '``function args``'. 8187#. The optional :ref:`function attributes <fnattrs>` list. 8188#. The optional :ref:`operand bundles <opbundles>` list. 8189 8190Semantics: 8191"""""""""" 8192 8193This instruction is designed to operate as a standard '``call``' 8194instruction in most regards. The primary difference is that it 8195establishes an association with additional labels to define where control 8196flow goes after the call. 8197 8198The output values of a '``callbr``' instruction are available only to 8199the '``fallthrough``' block, not to any '``indirect``' blocks(s). 8200 8201The only use of this today is to implement the "goto" feature of gcc inline 8202assembly where additional labels can be provided as locations for the inline 8203assembly to jump to. 8204 8205Example: 8206"""""""" 8207 8208.. code-block:: llvm 8209 8210 ; "asm goto" without output constraints. 8211 callbr void asm "", "r,X"(i32 %x, i8 *blockaddress(@foo, %indirect)) 8212 to label %fallthrough [label %indirect] 8213 8214 ; "asm goto" with output constraints. 8215 <result> = callbr i32 asm "", "=r,r,X"(i32 %x, i8 *blockaddress(@foo, %indirect)) 8216 to label %fallthrough [label %indirect] 8217 8218.. _i_resume: 8219 8220'``resume``' Instruction 8221^^^^^^^^^^^^^^^^^^^^^^^^ 8222 8223Syntax: 8224""""""" 8225 8226:: 8227 8228 resume <type> <value> 8229 8230Overview: 8231""""""""" 8232 8233The '``resume``' instruction is a terminator instruction that has no 8234successors. 8235 8236Arguments: 8237"""""""""" 8238 8239The '``resume``' instruction requires one argument, which must have the 8240same type as the result of any '``landingpad``' instruction in the same 8241function. 8242 8243Semantics: 8244"""""""""" 8245 8246The '``resume``' instruction resumes propagation of an existing 8247(in-flight) exception whose unwinding was interrupted with a 8248:ref:`landingpad <i_landingpad>` instruction. 8249 8250Example: 8251"""""""" 8252 8253.. code-block:: llvm 8254 8255 resume { i8*, i32 } %exn 8256 8257.. _i_catchswitch: 8258 8259'``catchswitch``' Instruction 8260^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 8261 8262Syntax: 8263""""""" 8264 8265:: 8266 8267 <resultval> = catchswitch within <parent> [ label <handler1>, label <handler2>, ... ] unwind to caller 8268 <resultval> = catchswitch within <parent> [ label <handler1>, label <handler2>, ... ] unwind label <default> 8269 8270Overview: 8271""""""""" 8272 8273The '``catchswitch``' instruction is used by `LLVM's exception handling system 8274<ExceptionHandling.html#overview>`_ to describe the set of possible catch handlers 8275that may be executed by the :ref:`EH personality routine <personalityfn>`. 8276 8277Arguments: 8278"""""""""" 8279 8280The ``parent`` argument is the token of the funclet that contains the 8281``catchswitch`` instruction. If the ``catchswitch`` is not inside a funclet, 8282this operand may be the token ``none``. 8283 8284The ``default`` argument is the label of another basic block beginning with 8285either a ``cleanuppad`` or ``catchswitch`` instruction. This unwind destination 8286must be a legal target with respect to the ``parent`` links, as described in 8287the `exception handling documentation\ <ExceptionHandling.html#wineh-constraints>`_. 8288 8289The ``handlers`` are a nonempty list of successor blocks that each begin with a 8290:ref:`catchpad <i_catchpad>` instruction. 8291 8292Semantics: 8293"""""""""" 8294 8295Executing this instruction transfers control to one of the successors in 8296``handlers``, if appropriate, or continues to unwind via the unwind label if 8297present. 8298 8299The ``catchswitch`` is both a terminator and a "pad" instruction, meaning that 8300it must be both the first non-phi instruction and last instruction in the basic 8301block. Therefore, it must be the only non-phi instruction in the block. 8302 8303Example: 8304"""""""" 8305 8306.. code-block:: text 8307 8308 dispatch1: 8309 %cs1 = catchswitch within none [label %handler0, label %handler1] unwind to caller 8310 dispatch2: 8311 %cs2 = catchswitch within %parenthandler [label %handler0] unwind label %cleanup 8312 8313.. _i_catchret: 8314 8315'``catchret``' Instruction 8316^^^^^^^^^^^^^^^^^^^^^^^^^^ 8317 8318Syntax: 8319""""""" 8320 8321:: 8322 8323 catchret from <token> to label <normal> 8324 8325Overview: 8326""""""""" 8327 8328The '``catchret``' instruction is a terminator instruction that has a 8329single successor. 8330 8331 8332Arguments: 8333"""""""""" 8334 8335The first argument to a '``catchret``' indicates which ``catchpad`` it 8336exits. It must be a :ref:`catchpad <i_catchpad>`. 8337The second argument to a '``catchret``' specifies where control will 8338transfer to next. 8339 8340Semantics: 8341"""""""""" 8342 8343The '``catchret``' instruction ends an existing (in-flight) exception whose 8344unwinding was interrupted with a :ref:`catchpad <i_catchpad>` instruction. The 8345:ref:`personality function <personalityfn>` gets a chance to execute arbitrary 8346code to, for example, destroy the active exception. Control then transfers to 8347``normal``. 8348 8349The ``token`` argument must be a token produced by a ``catchpad`` instruction. 8350If the specified ``catchpad`` is not the most-recently-entered not-yet-exited 8351funclet pad (as described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_), 8352the ``catchret``'s behavior is undefined. 8353 8354Example: 8355"""""""" 8356 8357.. code-block:: text 8358 8359 catchret from %catch label %continue 8360 8361.. _i_cleanupret: 8362 8363'``cleanupret``' Instruction 8364^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 8365 8366Syntax: 8367""""""" 8368 8369:: 8370 8371 cleanupret from <value> unwind label <continue> 8372 cleanupret from <value> unwind to caller 8373 8374Overview: 8375""""""""" 8376 8377The '``cleanupret``' instruction is a terminator instruction that has 8378an optional successor. 8379 8380 8381Arguments: 8382"""""""""" 8383 8384The '``cleanupret``' instruction requires one argument, which indicates 8385which ``cleanuppad`` it exits, and must be a :ref:`cleanuppad <i_cleanuppad>`. 8386If the specified ``cleanuppad`` is not the most-recently-entered not-yet-exited 8387funclet pad (as described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_), 8388the ``cleanupret``'s behavior is undefined. 8389 8390The '``cleanupret``' instruction also has an optional successor, ``continue``, 8391which must be the label of another basic block beginning with either a 8392``cleanuppad`` or ``catchswitch`` instruction. This unwind destination must 8393be a legal target with respect to the ``parent`` links, as described in the 8394`exception handling documentation\ <ExceptionHandling.html#wineh-constraints>`_. 8395 8396Semantics: 8397"""""""""" 8398 8399The '``cleanupret``' instruction indicates to the 8400:ref:`personality function <personalityfn>` that one 8401:ref:`cleanuppad <i_cleanuppad>` it transferred control to has ended. 8402It transfers control to ``continue`` or unwinds out of the function. 8403 8404Example: 8405"""""""" 8406 8407.. code-block:: text 8408 8409 cleanupret from %cleanup unwind to caller 8410 cleanupret from %cleanup unwind label %continue 8411 8412.. _i_unreachable: 8413 8414'``unreachable``' Instruction 8415^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 8416 8417Syntax: 8418""""""" 8419 8420:: 8421 8422 unreachable 8423 8424Overview: 8425""""""""" 8426 8427The '``unreachable``' instruction has no defined semantics. This 8428instruction is used to inform the optimizer that a particular portion of 8429the code is not reachable. This can be used to indicate that the code 8430after a no-return function cannot be reached, and other facts. 8431 8432Semantics: 8433"""""""""" 8434 8435The '``unreachable``' instruction has no defined semantics. 8436 8437.. _unaryops: 8438 8439Unary Operations 8440----------------- 8441 8442Unary operators require a single operand, execute an operation on 8443it, and produce a single value. The operand might represent multiple 8444data, as is the case with the :ref:`vector <t_vector>` data type. The 8445result value has the same type as its operand. 8446 8447.. _i_fneg: 8448 8449'``fneg``' Instruction 8450^^^^^^^^^^^^^^^^^^^^^^ 8451 8452Syntax: 8453""""""" 8454 8455:: 8456 8457 <result> = fneg [fast-math flags]* <ty> <op1> ; yields ty:result 8458 8459Overview: 8460""""""""" 8461 8462The '``fneg``' instruction returns the negation of its operand. 8463 8464Arguments: 8465"""""""""" 8466 8467The argument to the '``fneg``' instruction must be a 8468:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of 8469floating-point values. 8470 8471Semantics: 8472"""""""""" 8473 8474The value produced is a copy of the operand with its sign bit flipped. 8475This instruction can also take any number of :ref:`fast-math 8476flags <fastmath>`, which are optimization hints to enable otherwise 8477unsafe floating-point optimizations: 8478 8479Example: 8480"""""""" 8481 8482.. code-block:: text 8483 8484 <result> = fneg float %val ; yields float:result = -%var 8485 8486.. _binaryops: 8487 8488Binary Operations 8489----------------- 8490 8491Binary operators are used to do most of the computation in a program. 8492They require two operands of the same type, execute an operation on 8493them, and produce a single value. The operands might represent multiple 8494data, as is the case with the :ref:`vector <t_vector>` data type. The 8495result value has the same type as its operands. 8496 8497There are several different binary operators: 8498 8499.. _i_add: 8500 8501'``add``' Instruction 8502^^^^^^^^^^^^^^^^^^^^^ 8503 8504Syntax: 8505""""""" 8506 8507:: 8508 8509 <result> = add <ty> <op1>, <op2> ; yields ty:result 8510 <result> = add nuw <ty> <op1>, <op2> ; yields ty:result 8511 <result> = add nsw <ty> <op1>, <op2> ; yields ty:result 8512 <result> = add nuw nsw <ty> <op1>, <op2> ; yields ty:result 8513 8514Overview: 8515""""""""" 8516 8517The '``add``' instruction returns the sum of its two operands. 8518 8519Arguments: 8520"""""""""" 8521 8522The two arguments to the '``add``' instruction must be 8523:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 8524arguments must have identical types. 8525 8526Semantics: 8527"""""""""" 8528 8529The value produced is the integer sum of the two operands. 8530 8531If the sum has unsigned overflow, the result returned is the 8532mathematical result modulo 2\ :sup:`n`\ , where n is the bit width of 8533the result. 8534 8535Because LLVM integers use a two's complement representation, this 8536instruction is appropriate for both signed and unsigned integers. 8537 8538``nuw`` and ``nsw`` stand for "No Unsigned Wrap" and "No Signed Wrap", 8539respectively. If the ``nuw`` and/or ``nsw`` keywords are present, the 8540result value of the ``add`` is a :ref:`poison value <poisonvalues>` if 8541unsigned and/or signed overflow, respectively, occurs. 8542 8543Example: 8544"""""""" 8545 8546.. code-block:: text 8547 8548 <result> = add i32 4, %var ; yields i32:result = 4 + %var 8549 8550.. _i_fadd: 8551 8552'``fadd``' Instruction 8553^^^^^^^^^^^^^^^^^^^^^^ 8554 8555Syntax: 8556""""""" 8557 8558:: 8559 8560 <result> = fadd [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result 8561 8562Overview: 8563""""""""" 8564 8565The '``fadd``' instruction returns the sum of its two operands. 8566 8567Arguments: 8568"""""""""" 8569 8570The two arguments to the '``fadd``' instruction must be 8571:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of 8572floating-point values. Both arguments must have identical types. 8573 8574Semantics: 8575"""""""""" 8576 8577The value produced is the floating-point sum of the two operands. 8578This instruction is assumed to execute in the default :ref:`floating-point 8579environment <floatenv>`. 8580This instruction can also take any number of :ref:`fast-math 8581flags <fastmath>`, which are optimization hints to enable otherwise 8582unsafe floating-point optimizations: 8583 8584Example: 8585"""""""" 8586 8587.. code-block:: text 8588 8589 <result> = fadd float 4.0, %var ; yields float:result = 4.0 + %var 8590 8591.. _i_sub: 8592 8593'``sub``' Instruction 8594^^^^^^^^^^^^^^^^^^^^^ 8595 8596Syntax: 8597""""""" 8598 8599:: 8600 8601 <result> = sub <ty> <op1>, <op2> ; yields ty:result 8602 <result> = sub nuw <ty> <op1>, <op2> ; yields ty:result 8603 <result> = sub nsw <ty> <op1>, <op2> ; yields ty:result 8604 <result> = sub nuw nsw <ty> <op1>, <op2> ; yields ty:result 8605 8606Overview: 8607""""""""" 8608 8609The '``sub``' instruction returns the difference of its two operands. 8610 8611Note that the '``sub``' instruction is used to represent the '``neg``' 8612instruction present in most other intermediate representations. 8613 8614Arguments: 8615"""""""""" 8616 8617The two arguments to the '``sub``' instruction must be 8618:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 8619arguments must have identical types. 8620 8621Semantics: 8622"""""""""" 8623 8624The value produced is the integer difference of the two operands. 8625 8626If the difference has unsigned overflow, the result returned is the 8627mathematical result modulo 2\ :sup:`n`\ , where n is the bit width of 8628the result. 8629 8630Because LLVM integers use a two's complement representation, this 8631instruction is appropriate for both signed and unsigned integers. 8632 8633``nuw`` and ``nsw`` stand for "No Unsigned Wrap" and "No Signed Wrap", 8634respectively. If the ``nuw`` and/or ``nsw`` keywords are present, the 8635result value of the ``sub`` is a :ref:`poison value <poisonvalues>` if 8636unsigned and/or signed overflow, respectively, occurs. 8637 8638Example: 8639"""""""" 8640 8641.. code-block:: text 8642 8643 <result> = sub i32 4, %var ; yields i32:result = 4 - %var 8644 <result> = sub i32 0, %val ; yields i32:result = -%var 8645 8646.. _i_fsub: 8647 8648'``fsub``' Instruction 8649^^^^^^^^^^^^^^^^^^^^^^ 8650 8651Syntax: 8652""""""" 8653 8654:: 8655 8656 <result> = fsub [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result 8657 8658Overview: 8659""""""""" 8660 8661The '``fsub``' instruction returns the difference of its two operands. 8662 8663Arguments: 8664"""""""""" 8665 8666The two arguments to the '``fsub``' instruction must be 8667:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of 8668floating-point values. Both arguments must have identical types. 8669 8670Semantics: 8671"""""""""" 8672 8673The value produced is the floating-point difference of the two operands. 8674This instruction is assumed to execute in the default :ref:`floating-point 8675environment <floatenv>`. 8676This instruction can also take any number of :ref:`fast-math 8677flags <fastmath>`, which are optimization hints to enable otherwise 8678unsafe floating-point optimizations: 8679 8680Example: 8681"""""""" 8682 8683.. code-block:: text 8684 8685 <result> = fsub float 4.0, %var ; yields float:result = 4.0 - %var 8686 <result> = fsub float -0.0, %val ; yields float:result = -%var 8687 8688.. _i_mul: 8689 8690'``mul``' Instruction 8691^^^^^^^^^^^^^^^^^^^^^ 8692 8693Syntax: 8694""""""" 8695 8696:: 8697 8698 <result> = mul <ty> <op1>, <op2> ; yields ty:result 8699 <result> = mul nuw <ty> <op1>, <op2> ; yields ty:result 8700 <result> = mul nsw <ty> <op1>, <op2> ; yields ty:result 8701 <result> = mul nuw nsw <ty> <op1>, <op2> ; yields ty:result 8702 8703Overview: 8704""""""""" 8705 8706The '``mul``' instruction returns the product of its two operands. 8707 8708Arguments: 8709"""""""""" 8710 8711The two arguments to the '``mul``' instruction must be 8712:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 8713arguments must have identical types. 8714 8715Semantics: 8716"""""""""" 8717 8718The value produced is the integer product of the two operands. 8719 8720If the result of the multiplication has unsigned overflow, the result 8721returned is the mathematical result modulo 2\ :sup:`n`\ , where n is the 8722bit width of the result. 8723 8724Because LLVM integers use a two's complement representation, and the 8725result is the same width as the operands, this instruction returns the 8726correct result for both signed and unsigned integers. If a full product 8727(e.g. ``i32`` * ``i32`` -> ``i64``) is needed, the operands should be 8728sign-extended or zero-extended as appropriate to the width of the full 8729product. 8730 8731``nuw`` and ``nsw`` stand for "No Unsigned Wrap" and "No Signed Wrap", 8732respectively. If the ``nuw`` and/or ``nsw`` keywords are present, the 8733result value of the ``mul`` is a :ref:`poison value <poisonvalues>` if 8734unsigned and/or signed overflow, respectively, occurs. 8735 8736Example: 8737"""""""" 8738 8739.. code-block:: text 8740 8741 <result> = mul i32 4, %var ; yields i32:result = 4 * %var 8742 8743.. _i_fmul: 8744 8745'``fmul``' Instruction 8746^^^^^^^^^^^^^^^^^^^^^^ 8747 8748Syntax: 8749""""""" 8750 8751:: 8752 8753 <result> = fmul [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result 8754 8755Overview: 8756""""""""" 8757 8758The '``fmul``' instruction returns the product of its two operands. 8759 8760Arguments: 8761"""""""""" 8762 8763The two arguments to the '``fmul``' instruction must be 8764:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of 8765floating-point values. Both arguments must have identical types. 8766 8767Semantics: 8768"""""""""" 8769 8770The value produced is the floating-point product of the two operands. 8771This instruction is assumed to execute in the default :ref:`floating-point 8772environment <floatenv>`. 8773This instruction can also take any number of :ref:`fast-math 8774flags <fastmath>`, which are optimization hints to enable otherwise 8775unsafe floating-point optimizations: 8776 8777Example: 8778"""""""" 8779 8780.. code-block:: text 8781 8782 <result> = fmul float 4.0, %var ; yields float:result = 4.0 * %var 8783 8784.. _i_udiv: 8785 8786'``udiv``' Instruction 8787^^^^^^^^^^^^^^^^^^^^^^ 8788 8789Syntax: 8790""""""" 8791 8792:: 8793 8794 <result> = udiv <ty> <op1>, <op2> ; yields ty:result 8795 <result> = udiv exact <ty> <op1>, <op2> ; yields ty:result 8796 8797Overview: 8798""""""""" 8799 8800The '``udiv``' instruction returns the quotient of its two operands. 8801 8802Arguments: 8803"""""""""" 8804 8805The two arguments to the '``udiv``' instruction must be 8806:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 8807arguments must have identical types. 8808 8809Semantics: 8810"""""""""" 8811 8812The value produced is the unsigned integer quotient of the two operands. 8813 8814Note that unsigned integer division and signed integer division are 8815distinct operations; for signed integer division, use '``sdiv``'. 8816 8817Division by zero is undefined behavior. For vectors, if any element 8818of the divisor is zero, the operation has undefined behavior. 8819 8820 8821If the ``exact`` keyword is present, the result value of the ``udiv`` is 8822a :ref:`poison value <poisonvalues>` if %op1 is not a multiple of %op2 (as 8823such, "((a udiv exact b) mul b) == a"). 8824 8825Example: 8826"""""""" 8827 8828.. code-block:: text 8829 8830 <result> = udiv i32 4, %var ; yields i32:result = 4 / %var 8831 8832.. _i_sdiv: 8833 8834'``sdiv``' Instruction 8835^^^^^^^^^^^^^^^^^^^^^^ 8836 8837Syntax: 8838""""""" 8839 8840:: 8841 8842 <result> = sdiv <ty> <op1>, <op2> ; yields ty:result 8843 <result> = sdiv exact <ty> <op1>, <op2> ; yields ty:result 8844 8845Overview: 8846""""""""" 8847 8848The '``sdiv``' instruction returns the quotient of its two operands. 8849 8850Arguments: 8851"""""""""" 8852 8853The two arguments to the '``sdiv``' instruction must be 8854:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 8855arguments must have identical types. 8856 8857Semantics: 8858"""""""""" 8859 8860The value produced is the signed integer quotient of the two operands 8861rounded towards zero. 8862 8863Note that signed integer division and unsigned integer division are 8864distinct operations; for unsigned integer division, use '``udiv``'. 8865 8866Division by zero is undefined behavior. For vectors, if any element 8867of the divisor is zero, the operation has undefined behavior. 8868Overflow also leads to undefined behavior; this is a rare case, but can 8869occur, for example, by doing a 32-bit division of -2147483648 by -1. 8870 8871If the ``exact`` keyword is present, the result value of the ``sdiv`` is 8872a :ref:`poison value <poisonvalues>` if the result would be rounded. 8873 8874Example: 8875"""""""" 8876 8877.. code-block:: text 8878 8879 <result> = sdiv i32 4, %var ; yields i32:result = 4 / %var 8880 8881.. _i_fdiv: 8882 8883'``fdiv``' Instruction 8884^^^^^^^^^^^^^^^^^^^^^^ 8885 8886Syntax: 8887""""""" 8888 8889:: 8890 8891 <result> = fdiv [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result 8892 8893Overview: 8894""""""""" 8895 8896The '``fdiv``' instruction returns the quotient of its two operands. 8897 8898Arguments: 8899"""""""""" 8900 8901The two arguments to the '``fdiv``' instruction must be 8902:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of 8903floating-point values. Both arguments must have identical types. 8904 8905Semantics: 8906"""""""""" 8907 8908The value produced is the floating-point quotient of the two operands. 8909This instruction is assumed to execute in the default :ref:`floating-point 8910environment <floatenv>`. 8911This instruction can also take any number of :ref:`fast-math 8912flags <fastmath>`, which are optimization hints to enable otherwise 8913unsafe floating-point optimizations: 8914 8915Example: 8916"""""""" 8917 8918.. code-block:: text 8919 8920 <result> = fdiv float 4.0, %var ; yields float:result = 4.0 / %var 8921 8922.. _i_urem: 8923 8924'``urem``' Instruction 8925^^^^^^^^^^^^^^^^^^^^^^ 8926 8927Syntax: 8928""""""" 8929 8930:: 8931 8932 <result> = urem <ty> <op1>, <op2> ; yields ty:result 8933 8934Overview: 8935""""""""" 8936 8937The '``urem``' instruction returns the remainder from the unsigned 8938division of its two arguments. 8939 8940Arguments: 8941"""""""""" 8942 8943The two arguments to the '``urem``' instruction must be 8944:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 8945arguments must have identical types. 8946 8947Semantics: 8948"""""""""" 8949 8950This instruction returns the unsigned integer *remainder* of a division. 8951This instruction always performs an unsigned division to get the 8952remainder. 8953 8954Note that unsigned integer remainder and signed integer remainder are 8955distinct operations; for signed integer remainder, use '``srem``'. 8956 8957Taking the remainder of a division by zero is undefined behavior. 8958For vectors, if any element of the divisor is zero, the operation has 8959undefined behavior. 8960 8961Example: 8962"""""""" 8963 8964.. code-block:: text 8965 8966 <result> = urem i32 4, %var ; yields i32:result = 4 % %var 8967 8968.. _i_srem: 8969 8970'``srem``' Instruction 8971^^^^^^^^^^^^^^^^^^^^^^ 8972 8973Syntax: 8974""""""" 8975 8976:: 8977 8978 <result> = srem <ty> <op1>, <op2> ; yields ty:result 8979 8980Overview: 8981""""""""" 8982 8983The '``srem``' instruction returns the remainder from the signed 8984division of its two operands. This instruction can also take 8985:ref:`vector <t_vector>` versions of the values in which case the elements 8986must be integers. 8987 8988Arguments: 8989"""""""""" 8990 8991The two arguments to the '``srem``' instruction must be 8992:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 8993arguments must have identical types. 8994 8995Semantics: 8996"""""""""" 8997 8998This instruction returns the *remainder* of a division (where the result 8999is either zero or has the same sign as the dividend, ``op1``), not the 9000*modulo* operator (where the result is either zero or has the same sign 9001as the divisor, ``op2``) of a value. For more information about the 9002difference, see `The Math 9003Forum <http://mathforum.org/dr.math/problems/anne.4.28.99.html>`_. For a 9004table of how this is implemented in various languages, please see 9005`Wikipedia: modulo 9006operation <http://en.wikipedia.org/wiki/Modulo_operation>`_. 9007 9008Note that signed integer remainder and unsigned integer remainder are 9009distinct operations; for unsigned integer remainder, use '``urem``'. 9010 9011Taking the remainder of a division by zero is undefined behavior. 9012For vectors, if any element of the divisor is zero, the operation has 9013undefined behavior. 9014Overflow also leads to undefined behavior; this is a rare case, but can 9015occur, for example, by taking the remainder of a 32-bit division of 9016-2147483648 by -1. (The remainder doesn't actually overflow, but this 9017rule lets srem be implemented using instructions that return both the 9018result of the division and the remainder.) 9019 9020Example: 9021"""""""" 9022 9023.. code-block:: text 9024 9025 <result> = srem i32 4, %var ; yields i32:result = 4 % %var 9026 9027.. _i_frem: 9028 9029'``frem``' Instruction 9030^^^^^^^^^^^^^^^^^^^^^^ 9031 9032Syntax: 9033""""""" 9034 9035:: 9036 9037 <result> = frem [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result 9038 9039Overview: 9040""""""""" 9041 9042The '``frem``' instruction returns the remainder from the division of 9043its two operands. 9044 9045Arguments: 9046"""""""""" 9047 9048The two arguments to the '``frem``' instruction must be 9049:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` of 9050floating-point values. Both arguments must have identical types. 9051 9052Semantics: 9053"""""""""" 9054 9055The value produced is the floating-point remainder of the two operands. 9056This is the same output as a libm '``fmod``' function, but without any 9057possibility of setting ``errno``. The remainder has the same sign as the 9058dividend. 9059This instruction is assumed to execute in the default :ref:`floating-point 9060environment <floatenv>`. 9061This instruction can also take any number of :ref:`fast-math 9062flags <fastmath>`, which are optimization hints to enable otherwise 9063unsafe floating-point optimizations: 9064 9065Example: 9066"""""""" 9067 9068.. code-block:: text 9069 9070 <result> = frem float 4.0, %var ; yields float:result = 4.0 % %var 9071 9072.. _bitwiseops: 9073 9074Bitwise Binary Operations 9075------------------------- 9076 9077Bitwise binary operators are used to do various forms of bit-twiddling 9078in a program. They are generally very efficient instructions and can 9079commonly be strength reduced from other instructions. They require two 9080operands of the same type, execute an operation on them, and produce a 9081single value. The resulting value is the same type as its operands. 9082 9083.. _i_shl: 9084 9085'``shl``' Instruction 9086^^^^^^^^^^^^^^^^^^^^^ 9087 9088Syntax: 9089""""""" 9090 9091:: 9092 9093 <result> = shl <ty> <op1>, <op2> ; yields ty:result 9094 <result> = shl nuw <ty> <op1>, <op2> ; yields ty:result 9095 <result> = shl nsw <ty> <op1>, <op2> ; yields ty:result 9096 <result> = shl nuw nsw <ty> <op1>, <op2> ; yields ty:result 9097 9098Overview: 9099""""""""" 9100 9101The '``shl``' instruction returns the first operand shifted to the left 9102a specified number of bits. 9103 9104Arguments: 9105"""""""""" 9106 9107Both arguments to the '``shl``' instruction must be the same 9108:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer type. 9109'``op2``' is treated as an unsigned value. 9110 9111Semantics: 9112"""""""""" 9113 9114The value produced is ``op1`` \* 2\ :sup:`op2` mod 2\ :sup:`n`, 9115where ``n`` is the width of the result. If ``op2`` is (statically or 9116dynamically) equal to or larger than the number of bits in 9117``op1``, this instruction returns a :ref:`poison value <poisonvalues>`. 9118If the arguments are vectors, each vector element of ``op1`` is shifted 9119by the corresponding shift amount in ``op2``. 9120 9121If the ``nuw`` keyword is present, then the shift produces a poison 9122value if it shifts out any non-zero bits. 9123If the ``nsw`` keyword is present, then the shift produces a poison 9124value if it shifts out any bits that disagree with the resultant sign bit. 9125 9126Example: 9127"""""""" 9128 9129.. code-block:: text 9130 9131 <result> = shl i32 4, %var ; yields i32: 4 << %var 9132 <result> = shl i32 4, 2 ; yields i32: 16 9133 <result> = shl i32 1, 10 ; yields i32: 1024 9134 <result> = shl i32 1, 32 ; undefined 9135 <result> = shl <2 x i32> < i32 1, i32 1>, < i32 1, i32 2> ; yields: result=<2 x i32> < i32 2, i32 4> 9136 9137.. _i_lshr: 9138 9139 9140'``lshr``' Instruction 9141^^^^^^^^^^^^^^^^^^^^^^ 9142 9143Syntax: 9144""""""" 9145 9146:: 9147 9148 <result> = lshr <ty> <op1>, <op2> ; yields ty:result 9149 <result> = lshr exact <ty> <op1>, <op2> ; yields ty:result 9150 9151Overview: 9152""""""""" 9153 9154The '``lshr``' instruction (logical shift right) returns the first 9155operand shifted to the right a specified number of bits with zero fill. 9156 9157Arguments: 9158"""""""""" 9159 9160Both arguments to the '``lshr``' instruction must be the same 9161:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer type. 9162'``op2``' is treated as an unsigned value. 9163 9164Semantics: 9165"""""""""" 9166 9167This instruction always performs a logical shift right operation. The 9168most significant bits of the result will be filled with zero bits after 9169the shift. If ``op2`` is (statically or dynamically) equal to or larger 9170than the number of bits in ``op1``, this instruction returns a :ref:`poison 9171value <poisonvalues>`. If the arguments are vectors, each vector element 9172of ``op1`` is shifted by the corresponding shift amount in ``op2``. 9173 9174If the ``exact`` keyword is present, the result value of the ``lshr`` is 9175a poison value if any of the bits shifted out are non-zero. 9176 9177Example: 9178"""""""" 9179 9180.. code-block:: text 9181 9182 <result> = lshr i32 4, 1 ; yields i32:result = 2 9183 <result> = lshr i32 4, 2 ; yields i32:result = 1 9184 <result> = lshr i8 4, 3 ; yields i8:result = 0 9185 <result> = lshr i8 -2, 1 ; yields i8:result = 0x7F 9186 <result> = lshr i32 1, 32 ; undefined 9187 <result> = lshr <2 x i32> < i32 -2, i32 4>, < i32 1, i32 2> ; yields: result=<2 x i32> < i32 0x7FFFFFFF, i32 1> 9188 9189.. _i_ashr: 9190 9191'``ashr``' Instruction 9192^^^^^^^^^^^^^^^^^^^^^^ 9193 9194Syntax: 9195""""""" 9196 9197:: 9198 9199 <result> = ashr <ty> <op1>, <op2> ; yields ty:result 9200 <result> = ashr exact <ty> <op1>, <op2> ; yields ty:result 9201 9202Overview: 9203""""""""" 9204 9205The '``ashr``' instruction (arithmetic shift right) returns the first 9206operand shifted to the right a specified number of bits with sign 9207extension. 9208 9209Arguments: 9210"""""""""" 9211 9212Both arguments to the '``ashr``' instruction must be the same 9213:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer type. 9214'``op2``' is treated as an unsigned value. 9215 9216Semantics: 9217"""""""""" 9218 9219This instruction always performs an arithmetic shift right operation, 9220The most significant bits of the result will be filled with the sign bit 9221of ``op1``. If ``op2`` is (statically or dynamically) equal to or larger 9222than the number of bits in ``op1``, this instruction returns a :ref:`poison 9223value <poisonvalues>`. If the arguments are vectors, each vector element 9224of ``op1`` is shifted by the corresponding shift amount in ``op2``. 9225 9226If the ``exact`` keyword is present, the result value of the ``ashr`` is 9227a poison value if any of the bits shifted out are non-zero. 9228 9229Example: 9230"""""""" 9231 9232.. code-block:: text 9233 9234 <result> = ashr i32 4, 1 ; yields i32:result = 2 9235 <result> = ashr i32 4, 2 ; yields i32:result = 1 9236 <result> = ashr i8 4, 3 ; yields i8:result = 0 9237 <result> = ashr i8 -2, 1 ; yields i8:result = -1 9238 <result> = ashr i32 1, 32 ; undefined 9239 <result> = ashr <2 x i32> < i32 -2, i32 4>, < i32 1, i32 3> ; yields: result=<2 x i32> < i32 -1, i32 0> 9240 9241.. _i_and: 9242 9243'``and``' Instruction 9244^^^^^^^^^^^^^^^^^^^^^ 9245 9246Syntax: 9247""""""" 9248 9249:: 9250 9251 <result> = and <ty> <op1>, <op2> ; yields ty:result 9252 9253Overview: 9254""""""""" 9255 9256The '``and``' instruction returns the bitwise logical and of its two 9257operands. 9258 9259Arguments: 9260"""""""""" 9261 9262The two arguments to the '``and``' instruction must be 9263:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 9264arguments must have identical types. 9265 9266Semantics: 9267"""""""""" 9268 9269The truth table used for the '``and``' instruction is: 9270 9271+-----+-----+-----+ 9272| In0 | In1 | Out | 9273+-----+-----+-----+ 9274| 0 | 0 | 0 | 9275+-----+-----+-----+ 9276| 0 | 1 | 0 | 9277+-----+-----+-----+ 9278| 1 | 0 | 0 | 9279+-----+-----+-----+ 9280| 1 | 1 | 1 | 9281+-----+-----+-----+ 9282 9283Example: 9284"""""""" 9285 9286.. code-block:: text 9287 9288 <result> = and i32 4, %var ; yields i32:result = 4 & %var 9289 <result> = and i32 15, 40 ; yields i32:result = 8 9290 <result> = and i32 4, 8 ; yields i32:result = 0 9291 9292.. _i_or: 9293 9294'``or``' Instruction 9295^^^^^^^^^^^^^^^^^^^^ 9296 9297Syntax: 9298""""""" 9299 9300:: 9301 9302 <result> = or <ty> <op1>, <op2> ; yields ty:result 9303 9304Overview: 9305""""""""" 9306 9307The '``or``' instruction returns the bitwise logical inclusive or of its 9308two operands. 9309 9310Arguments: 9311"""""""""" 9312 9313The two arguments to the '``or``' instruction must be 9314:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 9315arguments must have identical types. 9316 9317Semantics: 9318"""""""""" 9319 9320The truth table used for the '``or``' instruction is: 9321 9322+-----+-----+-----+ 9323| In0 | In1 | Out | 9324+-----+-----+-----+ 9325| 0 | 0 | 0 | 9326+-----+-----+-----+ 9327| 0 | 1 | 1 | 9328+-----+-----+-----+ 9329| 1 | 0 | 1 | 9330+-----+-----+-----+ 9331| 1 | 1 | 1 | 9332+-----+-----+-----+ 9333 9334Example: 9335"""""""" 9336 9337:: 9338 9339 <result> = or i32 4, %var ; yields i32:result = 4 | %var 9340 <result> = or i32 15, 40 ; yields i32:result = 47 9341 <result> = or i32 4, 8 ; yields i32:result = 12 9342 9343.. _i_xor: 9344 9345'``xor``' Instruction 9346^^^^^^^^^^^^^^^^^^^^^ 9347 9348Syntax: 9349""""""" 9350 9351:: 9352 9353 <result> = xor <ty> <op1>, <op2> ; yields ty:result 9354 9355Overview: 9356""""""""" 9357 9358The '``xor``' instruction returns the bitwise logical exclusive or of 9359its two operands. The ``xor`` is used to implement the "one's 9360complement" operation, which is the "~" operator in C. 9361 9362Arguments: 9363"""""""""" 9364 9365The two arguments to the '``xor``' instruction must be 9366:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 9367arguments must have identical types. 9368 9369Semantics: 9370"""""""""" 9371 9372The truth table used for the '``xor``' instruction is: 9373 9374+-----+-----+-----+ 9375| In0 | In1 | Out | 9376+-----+-----+-----+ 9377| 0 | 0 | 0 | 9378+-----+-----+-----+ 9379| 0 | 1 | 1 | 9380+-----+-----+-----+ 9381| 1 | 0 | 1 | 9382+-----+-----+-----+ 9383| 1 | 1 | 0 | 9384+-----+-----+-----+ 9385 9386Example: 9387"""""""" 9388 9389.. code-block:: text 9390 9391 <result> = xor i32 4, %var ; yields i32:result = 4 ^ %var 9392 <result> = xor i32 15, 40 ; yields i32:result = 39 9393 <result> = xor i32 4, 8 ; yields i32:result = 12 9394 <result> = xor i32 %V, -1 ; yields i32:result = ~%V 9395 9396Vector Operations 9397----------------- 9398 9399LLVM supports several instructions to represent vector operations in a 9400target-independent manner. These instructions cover the element-access 9401and vector-specific operations needed to process vectors effectively. 9402While LLVM does directly support these vector operations, many 9403sophisticated algorithms will want to use target-specific intrinsics to 9404take full advantage of a specific target. 9405 9406.. _i_extractelement: 9407 9408'``extractelement``' Instruction 9409^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9410 9411Syntax: 9412""""""" 9413 9414:: 9415 9416 <result> = extractelement <n x <ty>> <val>, <ty2> <idx> ; yields <ty> 9417 <result> = extractelement <vscale x n x <ty>> <val>, <ty2> <idx> ; yields <ty> 9418 9419Overview: 9420""""""""" 9421 9422The '``extractelement``' instruction extracts a single scalar element 9423from a vector at a specified index. 9424 9425Arguments: 9426"""""""""" 9427 9428The first operand of an '``extractelement``' instruction is a value of 9429:ref:`vector <t_vector>` type. The second operand is an index indicating 9430the position from which to extract the element. The index may be a 9431variable of any integer type. 9432 9433Semantics: 9434"""""""""" 9435 9436The result is a scalar of the same type as the element type of ``val``. 9437Its value is the value at position ``idx`` of ``val``. If ``idx`` 9438exceeds the length of ``val`` for a fixed-length vector, the result is a 9439:ref:`poison value <poisonvalues>`. For a scalable vector, if the value 9440of ``idx`` exceeds the runtime length of the vector, the result is a 9441:ref:`poison value <poisonvalues>`. 9442 9443Example: 9444"""""""" 9445 9446.. code-block:: text 9447 9448 <result> = extractelement <4 x i32> %vec, i32 0 ; yields i32 9449 9450.. _i_insertelement: 9451 9452'``insertelement``' Instruction 9453^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9454 9455Syntax: 9456""""""" 9457 9458:: 9459 9460 <result> = insertelement <n x <ty>> <val>, <ty> <elt>, <ty2> <idx> ; yields <n x <ty>> 9461 <result> = insertelement <vscale x n x <ty>> <val>, <ty> <elt>, <ty2> <idx> ; yields <vscale x n x <ty>> 9462 9463Overview: 9464""""""""" 9465 9466The '``insertelement``' instruction inserts a scalar element into a 9467vector at a specified index. 9468 9469Arguments: 9470"""""""""" 9471 9472The first operand of an '``insertelement``' instruction is a value of 9473:ref:`vector <t_vector>` type. The second operand is a scalar value whose 9474type must equal the element type of the first operand. The third operand 9475is an index indicating the position at which to insert the value. The 9476index may be a variable of any integer type. 9477 9478Semantics: 9479"""""""""" 9480 9481The result is a vector of the same type as ``val``. Its element values 9482are those of ``val`` except at position ``idx``, where it gets the value 9483``elt``. If ``idx`` exceeds the length of ``val`` for a fixed-length vector, 9484the result is a :ref:`poison value <poisonvalues>`. For a scalable vector, 9485if the value of ``idx`` exceeds the runtime length of the vector, the result 9486is a :ref:`poison value <poisonvalues>`. 9487 9488Example: 9489"""""""" 9490 9491.. code-block:: text 9492 9493 <result> = insertelement <4 x i32> %vec, i32 1, i32 0 ; yields <4 x i32> 9494 9495.. _i_shufflevector: 9496 9497'``shufflevector``' Instruction 9498^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9499 9500Syntax: 9501""""""" 9502 9503:: 9504 9505 <result> = shufflevector <n x <ty>> <v1>, <n x <ty>> <v2>, <m x i32> <mask> ; yields <m x <ty>> 9506 <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>> 9507 9508Overview: 9509""""""""" 9510 9511The '``shufflevector``' instruction constructs a permutation of elements 9512from two input vectors, returning a vector with the same element type as 9513the input and length that is the same as the shuffle mask. 9514 9515Arguments: 9516"""""""""" 9517 9518The first two operands of a '``shufflevector``' instruction are vectors 9519with the same type. The third argument is a shuffle mask vector constant 9520whose element type is ``i32``. The mask vector elements must be constant 9521integers or ``undef`` values. The result of the instruction is a vector 9522whose length is the same as the shuffle mask and whose element type is the 9523same as the element type of the first two operands. 9524 9525Semantics: 9526"""""""""" 9527 9528The elements of the two input vectors are numbered from left to right 9529across both of the vectors. For each element of the result vector, the 9530shuffle mask selects an element from one of the input vectors to copy 9531to the result. Non-negative elements in the mask represent an index 9532into the concatenated pair of input vectors. 9533 9534If the shuffle mask is undefined, the result vector is undefined. If 9535the shuffle mask selects an undefined element from one of the input 9536vectors, the resulting element is undefined. An undefined element 9537in the mask vector specifies that the resulting element is undefined. 9538An undefined element in the mask vector prevents a poisoned vector 9539element from propagating. 9540 9541For scalable vectors, the only valid mask values at present are 9542``zeroinitializer`` and ``undef``, since we cannot write all indices as 9543literals for a vector with a length unknown at compile time. 9544 9545Example: 9546"""""""" 9547 9548.. code-block:: text 9549 9550 <result> = shufflevector <4 x i32> %v1, <4 x i32> %v2, 9551 <4 x i32> <i32 0, i32 4, i32 1, i32 5> ; yields <4 x i32> 9552 <result> = shufflevector <4 x i32> %v1, <4 x i32> undef, 9553 <4 x i32> <i32 0, i32 1, i32 2, i32 3> ; yields <4 x i32> - Identity shuffle. 9554 <result> = shufflevector <8 x i32> %v1, <8 x i32> undef, 9555 <4 x i32> <i32 0, i32 1, i32 2, i32 3> ; yields <4 x i32> 9556 <result> = shufflevector <4 x i32> %v1, <4 x i32> %v2, 9557 <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7 > ; yields <8 x i32> 9558 9559Aggregate Operations 9560-------------------- 9561 9562LLVM supports several instructions for working with 9563:ref:`aggregate <t_aggregate>` values. 9564 9565.. _i_extractvalue: 9566 9567'``extractvalue``' Instruction 9568^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9569 9570Syntax: 9571""""""" 9572 9573:: 9574 9575 <result> = extractvalue <aggregate type> <val>, <idx>{, <idx>}* 9576 9577Overview: 9578""""""""" 9579 9580The '``extractvalue``' instruction extracts the value of a member field 9581from an :ref:`aggregate <t_aggregate>` value. 9582 9583Arguments: 9584"""""""""" 9585 9586The first operand of an '``extractvalue``' instruction is a value of 9587:ref:`struct <t_struct>` or :ref:`array <t_array>` type. The other operands are 9588constant indices to specify which value to extract in a similar manner 9589as indices in a '``getelementptr``' instruction. 9590 9591The major differences to ``getelementptr`` indexing are: 9592 9593- Since the value being indexed is not a pointer, the first index is 9594 omitted and assumed to be zero. 9595- At least one index must be specified. 9596- Not only struct indices but also array indices must be in bounds. 9597 9598Semantics: 9599"""""""""" 9600 9601The result is the value at the position in the aggregate specified by 9602the index operands. 9603 9604Example: 9605"""""""" 9606 9607.. code-block:: text 9608 9609 <result> = extractvalue {i32, float} %agg, 0 ; yields i32 9610 9611.. _i_insertvalue: 9612 9613'``insertvalue``' Instruction 9614^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9615 9616Syntax: 9617""""""" 9618 9619:: 9620 9621 <result> = insertvalue <aggregate type> <val>, <ty> <elt>, <idx>{, <idx>}* ; yields <aggregate type> 9622 9623Overview: 9624""""""""" 9625 9626The '``insertvalue``' instruction inserts a value into a member field in 9627an :ref:`aggregate <t_aggregate>` value. 9628 9629Arguments: 9630"""""""""" 9631 9632The first operand of an '``insertvalue``' instruction is a value of 9633:ref:`struct <t_struct>` or :ref:`array <t_array>` type. The second operand is 9634a first-class value to insert. The following operands are constant 9635indices indicating the position at which to insert the value in a 9636similar manner as indices in a '``extractvalue``' instruction. The value 9637to insert must have the same type as the value identified by the 9638indices. 9639 9640Semantics: 9641"""""""""" 9642 9643The result is an aggregate of the same type as ``val``. Its value is 9644that of ``val`` except that the value at the position specified by the 9645indices is that of ``elt``. 9646 9647Example: 9648"""""""" 9649 9650.. code-block:: llvm 9651 9652 %agg1 = insertvalue {i32, float} undef, i32 1, 0 ; yields {i32 1, float undef} 9653 %agg2 = insertvalue {i32, float} %agg1, float %val, 1 ; yields {i32 1, float %val} 9654 %agg3 = insertvalue {i32, {float}} undef, float %val, 1, 0 ; yields {i32 undef, {float %val}} 9655 9656.. _memoryops: 9657 9658Memory Access and Addressing Operations 9659--------------------------------------- 9660 9661A key design point of an SSA-based representation is how it represents 9662memory. In LLVM, no memory locations are in SSA form, which makes things 9663very simple. This section describes how to read, write, and allocate 9664memory in LLVM. 9665 9666.. _i_alloca: 9667 9668'``alloca``' Instruction 9669^^^^^^^^^^^^^^^^^^^^^^^^ 9670 9671Syntax: 9672""""""" 9673 9674:: 9675 9676 <result> = alloca [inalloca] <type> [, <ty> <NumElements>] [, align <alignment>] [, addrspace(<num>)] ; yields type addrspace(num)*:result 9677 9678Overview: 9679""""""""" 9680 9681The '``alloca``' instruction allocates memory on the stack frame of the 9682currently executing function, to be automatically released when this 9683function returns to its caller. If the address space is not explicitly 9684specified, the object is allocated in the alloca address space from the 9685:ref:`datalayout string<langref_datalayout>`. 9686 9687Arguments: 9688"""""""""" 9689 9690The '``alloca``' instruction allocates ``sizeof(<type>)*NumElements`` 9691bytes of memory on the runtime stack, returning a pointer of the 9692appropriate type to the program. If "NumElements" is specified, it is 9693the number of elements allocated, otherwise "NumElements" is defaulted 9694to be one. If a constant alignment is specified, the value result of the 9695allocation is guaranteed to be aligned to at least that boundary. The 9696alignment may not be greater than ``1 << 29``. If not specified, or if 9697zero, the target can choose to align the allocation on any convenient 9698boundary compatible with the type. 9699 9700'``type``' may be any sized type. 9701 9702Semantics: 9703"""""""""" 9704 9705Memory is allocated; a pointer is returned. The allocated memory is 9706uninitialized, and loading from uninitialized memory produces an undefined 9707value. The operation itself is undefined if there is insufficient stack 9708space for the allocation.'``alloca``'d memory is automatically released 9709when the function returns. The '``alloca``' instruction is commonly used 9710to represent automatic variables that must have an address available. When 9711the function returns (either with the ``ret`` or ``resume`` instructions), 9712the memory is reclaimed. Allocating zero bytes is legal, but the returned 9713pointer may not be unique. The order in which memory is allocated (ie., 9714which way the stack grows) is not specified. 9715 9716Note that '``alloca``' outside of the alloca address space from the 9717:ref:`datalayout string<langref_datalayout>` is meaningful only if the 9718target has assigned it a semantics. 9719 9720If the returned pointer is used by :ref:`llvm.lifetime.start <int_lifestart>`, 9721the returned object is initially dead. 9722See :ref:`llvm.lifetime.start <int_lifestart>` and 9723:ref:`llvm.lifetime.end <int_lifeend>` for the precise semantics of 9724lifetime-manipulating intrinsics. 9725 9726Example: 9727"""""""" 9728 9729.. code-block:: llvm 9730 9731 %ptr = alloca i32 ; yields i32*:ptr 9732 %ptr = alloca i32, i32 4 ; yields i32*:ptr 9733 %ptr = alloca i32, i32 4, align 1024 ; yields i32*:ptr 9734 %ptr = alloca i32, align 1024 ; yields i32*:ptr 9735 9736.. _i_load: 9737 9738'``load``' Instruction 9739^^^^^^^^^^^^^^^^^^^^^^ 9740 9741Syntax: 9742""""""" 9743 9744:: 9745 9746 <result> = load [volatile] <ty>, <ty>* <pointer>[, align <alignment>][, !nontemporal !<nontemp_node>][, !invariant.load !<empty_node>][, !invariant.group !<empty_node>][, !nonnull !<empty_node>][, !dereferenceable !<deref_bytes_node>][, !dereferenceable_or_null !<deref_bytes_node>][, !align !<align_node>][, !noundef !<empty_node>] 9747 <result> = load atomic [volatile] <ty>, <ty>* <pointer> [syncscope("<target-scope>")] <ordering>, align <alignment> [, !invariant.group !<empty_node>] 9748 !<nontemp_node> = !{ i32 1 } 9749 !<empty_node> = !{} 9750 !<deref_bytes_node> = !{ i64 <dereferenceable_bytes> } 9751 !<align_node> = !{ i64 <value_alignment> } 9752 9753Overview: 9754""""""""" 9755 9756The '``load``' instruction is used to read from memory. 9757 9758Arguments: 9759"""""""""" 9760 9761The argument to the ``load`` instruction specifies the memory address from which 9762to load. The type specified must be a :ref:`first class <t_firstclass>` type of 9763known size (i.e. not containing an :ref:`opaque structural type <t_opaque>`). If 9764the ``load`` is marked as ``volatile``, then the optimizer is not allowed to 9765modify the number or order of execution of this ``load`` with other 9766:ref:`volatile operations <volatile>`. 9767 9768If the ``load`` is marked as ``atomic``, it takes an extra :ref:`ordering 9769<ordering>` and optional ``syncscope("<target-scope>")`` argument. The 9770``release`` and ``acq_rel`` orderings are not valid on ``load`` instructions. 9771Atomic loads produce :ref:`defined <memmodel>` results when they may see 9772multiple atomic stores. The type of the pointee must be an integer, pointer, or 9773floating-point type whose bit width is a power of two greater than or equal to 9774eight and less than or equal to a target-specific size limit. ``align`` must be 9775explicitly specified on atomic loads, and the load has undefined behavior if the 9776alignment is not set to a value which is at least the size in bytes of the 9777pointee. ``!nontemporal`` does not have any defined semantics for atomic loads. 9778 9779The optional constant ``align`` argument specifies the alignment of the 9780operation (that is, the alignment of the memory address). A value of 0 9781or an omitted ``align`` argument means that the operation has the ABI 9782alignment for the target. It is the responsibility of the code emitter 9783to ensure that the alignment information is correct. Overestimating the 9784alignment results in undefined behavior. Underestimating the alignment 9785may produce less efficient code. An alignment of 1 is always safe. The 9786maximum possible alignment is ``1 << 29``. An alignment value higher 9787than the size of the loaded type implies memory up to the alignment 9788value bytes can be safely loaded without trapping in the default 9789address space. Access of the high bytes can interfere with debugging 9790tools, so should not be accessed if the function has the 9791``sanitize_thread`` or ``sanitize_address`` attributes. 9792 9793The optional ``!nontemporal`` metadata must reference a single 9794metadata name ``<nontemp_node>`` corresponding to a metadata node with one 9795``i32`` entry of value 1. The existence of the ``!nontemporal`` 9796metadata on the instruction tells the optimizer and code generator 9797that this load is not expected to be reused in the cache. The code 9798generator may select special instructions to save cache bandwidth, such 9799as the ``MOVNT`` instruction on x86. 9800 9801The optional ``!invariant.load`` metadata must reference a single 9802metadata name ``<empty_node>`` corresponding to a metadata node with no 9803entries. If a load instruction tagged with the ``!invariant.load`` 9804metadata is executed, the memory location referenced by the load has 9805to contain the same value at all points in the program where the 9806memory location is dereferenceable; otherwise, the behavior is 9807undefined. 9808 9809The optional ``!invariant.group`` metadata must reference a single metadata name 9810 ``<empty_node>`` corresponding to a metadata node with no entries. 9811 See ``invariant.group`` metadata :ref:`invariant.group <md_invariant.group>`. 9812 9813The optional ``!nonnull`` metadata must reference a single 9814metadata name ``<empty_node>`` corresponding to a metadata node with no 9815entries. The existence of the ``!nonnull`` metadata on the 9816instruction tells the optimizer that the value loaded is known to 9817never be null. If the value is null at runtime, the behavior is undefined. 9818This is analogous to the ``nonnull`` attribute on parameters and return 9819values. This metadata can only be applied to loads of a pointer type. 9820 9821The optional ``!dereferenceable`` metadata must reference a single metadata 9822name ``<deref_bytes_node>`` corresponding to a metadata node with one ``i64`` 9823entry. 9824See ``dereferenceable`` metadata :ref:`dereferenceable <md_dereferenceable>`. 9825 9826The optional ``!dereferenceable_or_null`` metadata must reference a single 9827metadata name ``<deref_bytes_node>`` corresponding to a metadata node with one 9828``i64`` entry. 9829See ``dereferenceable_or_null`` metadata :ref:`dereferenceable_or_null 9830<md_dereferenceable_or_null>`. 9831 9832The optional ``!align`` metadata must reference a single metadata name 9833``<align_node>`` corresponding to a metadata node with one ``i64`` entry. 9834The existence of the ``!align`` metadata on the instruction tells the 9835optimizer that the value loaded is known to be aligned to a boundary specified 9836by the integer value in the metadata node. The alignment must be a power of 2. 9837This is analogous to the ''align'' attribute on parameters and return values. 9838This metadata can only be applied to loads of a pointer type. If the returned 9839value is not appropriately aligned at runtime, the behavior is undefined. 9840 9841The optional ``!noundef`` metadata must reference a single metadata name 9842``<empty_node>`` corresponding to a node with no entries. The existence of 9843``!noundef`` metadata on the instruction tells the optimizer that the value 9844loaded is known to be :ref:`well defined <welldefinedvalues>`. 9845If the value isn't well defined, the behavior is undefined. 9846 9847Semantics: 9848"""""""""" 9849 9850The location of memory pointed to is loaded. If the value being loaded 9851is of scalar type then the number of bytes read does not exceed the 9852minimum number of bytes needed to hold all bits of the type. For 9853example, loading an ``i24`` reads at most three bytes. When loading a 9854value of a type like ``i20`` with a size that is not an integral number 9855of bytes, the result is undefined if the value was not originally 9856written using a store of the same type. 9857If the value being loaded is of aggregate type, the bytes that correspond to 9858padding may be accessed but are ignored, because it is impossible to observe 9859padding from the loaded aggregate value. 9860If ``<pointer>`` is not a well-defined value, the behavior is undefined. 9861 9862Examples: 9863""""""""" 9864 9865.. code-block:: llvm 9866 9867 %ptr = alloca i32 ; yields i32*:ptr 9868 store i32 3, i32* %ptr ; yields void 9869 %val = load i32, i32* %ptr ; yields i32:val = i32 3 9870 9871.. _i_store: 9872 9873'``store``' Instruction 9874^^^^^^^^^^^^^^^^^^^^^^^ 9875 9876Syntax: 9877""""""" 9878 9879:: 9880 9881 store [volatile] <ty> <value>, <ty>* <pointer>[, align <alignment>][, !nontemporal !<nontemp_node>][, !invariant.group !<empty_node>] ; yields void 9882 store atomic [volatile] <ty> <value>, <ty>* <pointer> [syncscope("<target-scope>")] <ordering>, align <alignment> [, !invariant.group !<empty_node>] ; yields void 9883 !<nontemp_node> = !{ i32 1 } 9884 !<empty_node> = !{} 9885 9886Overview: 9887""""""""" 9888 9889The '``store``' instruction is used to write to memory. 9890 9891Arguments: 9892"""""""""" 9893 9894There are two arguments to the ``store`` instruction: a value to store and an 9895address at which to store it. The type of the ``<pointer>`` operand must be a 9896pointer to the :ref:`first class <t_firstclass>` type of the ``<value>`` 9897operand. If the ``store`` is marked as ``volatile``, then the optimizer is not 9898allowed to modify the number or order of execution of this ``store`` with other 9899:ref:`volatile operations <volatile>`. Only values of :ref:`first class 9900<t_firstclass>` types of known size (i.e. not containing an :ref:`opaque 9901structural type <t_opaque>`) can be stored. 9902 9903If the ``store`` is marked as ``atomic``, it takes an extra :ref:`ordering 9904<ordering>` and optional ``syncscope("<target-scope>")`` argument. The 9905``acquire`` and ``acq_rel`` orderings aren't valid on ``store`` instructions. 9906Atomic loads produce :ref:`defined <memmodel>` results when they may see 9907multiple atomic stores. The type of the pointee must be an integer, pointer, or 9908floating-point type whose bit width is a power of two greater than or equal to 9909eight and less than or equal to a target-specific size limit. ``align`` must be 9910explicitly specified on atomic stores, and the store has undefined behavior if 9911the alignment is not set to a value which is at least the size in bytes of the 9912pointee. ``!nontemporal`` does not have any defined semantics for atomic stores. 9913 9914The optional constant ``align`` argument specifies the alignment of the 9915operation (that is, the alignment of the memory address). A value of 0 9916or an omitted ``align`` argument means that the operation has the ABI 9917alignment for the target. It is the responsibility of the code emitter 9918to ensure that the alignment information is correct. Overestimating the 9919alignment results in undefined behavior. Underestimating the 9920alignment may produce less efficient code. An alignment of 1 is always 9921safe. The maximum possible alignment is ``1 << 29``. An alignment 9922value higher than the size of the stored type implies memory up to the 9923alignment value bytes can be stored to without trapping in the default 9924address space. Storing to the higher bytes however may result in data 9925races if another thread can access the same address. Introducing a 9926data race is not allowed. Storing to the extra bytes is not allowed 9927even in situations where a data race is known to not exist if the 9928function has the ``sanitize_address`` attribute. 9929 9930The optional ``!nontemporal`` metadata must reference a single metadata 9931name ``<nontemp_node>`` corresponding to a metadata node with one ``i32`` entry 9932of value 1. The existence of the ``!nontemporal`` metadata on the instruction 9933tells the optimizer and code generator that this load is not expected to 9934be reused in the cache. The code generator may select special 9935instructions to save cache bandwidth, such as the ``MOVNT`` instruction on 9936x86. 9937 9938The optional ``!invariant.group`` metadata must reference a 9939single metadata name ``<empty_node>``. See ``invariant.group`` metadata. 9940 9941Semantics: 9942"""""""""" 9943 9944The contents of memory are updated to contain ``<value>`` at the 9945location specified by the ``<pointer>`` operand. If ``<value>`` is 9946of scalar type then the number of bytes written does not exceed the 9947minimum number of bytes needed to hold all bits of the type. For 9948example, storing an ``i24`` writes at most three bytes. When writing a 9949value of a type like ``i20`` with a size that is not an integral number 9950of bytes, it is unspecified what happens to the extra bits that do not 9951belong to the type, but they will typically be overwritten. 9952If ``<value>`` is of aggregate type, padding is filled with 9953:ref:`undef <undefvalues>`. 9954If ``<pointer>`` is not a well-defined value, the behavior is undefined. 9955 9956Example: 9957"""""""" 9958 9959.. code-block:: llvm 9960 9961 %ptr = alloca i32 ; yields i32*:ptr 9962 store i32 3, i32* %ptr ; yields void 9963 %val = load i32, i32* %ptr ; yields i32:val = i32 3 9964 9965.. _i_fence: 9966 9967'``fence``' Instruction 9968^^^^^^^^^^^^^^^^^^^^^^^ 9969 9970Syntax: 9971""""""" 9972 9973:: 9974 9975 fence [syncscope("<target-scope>")] <ordering> ; yields void 9976 9977Overview: 9978""""""""" 9979 9980The '``fence``' instruction is used to introduce happens-before edges 9981between operations. 9982 9983Arguments: 9984"""""""""" 9985 9986'``fence``' instructions take an :ref:`ordering <ordering>` argument which 9987defines what *synchronizes-with* edges they add. They can only be given 9988``acquire``, ``release``, ``acq_rel``, and ``seq_cst`` orderings. 9989 9990Semantics: 9991"""""""""" 9992 9993A fence A which has (at least) ``release`` ordering semantics 9994*synchronizes with* a fence B with (at least) ``acquire`` ordering 9995semantics if and only if there exist atomic operations X and Y, both 9996operating on some atomic object M, such that A is sequenced before X, X 9997modifies M (either directly or through some side effect of a sequence 9998headed by X), Y is sequenced before B, and Y observes M. This provides a 9999*happens-before* dependency between A and B. Rather than an explicit 10000``fence``, one (but not both) of the atomic operations X or Y might 10001provide a ``release`` or ``acquire`` (resp.) ordering constraint and 10002still *synchronize-with* the explicit ``fence`` and establish the 10003*happens-before* edge. 10004 10005A ``fence`` which has ``seq_cst`` ordering, in addition to having both 10006``acquire`` and ``release`` semantics specified above, participates in 10007the global program order of other ``seq_cst`` operations and/or fences. 10008 10009A ``fence`` instruction can also take an optional 10010":ref:`syncscope <syncscope>`" argument. 10011 10012Example: 10013"""""""" 10014 10015.. code-block:: text 10016 10017 fence acquire ; yields void 10018 fence syncscope("singlethread") seq_cst ; yields void 10019 fence syncscope("agent") seq_cst ; yields void 10020 10021.. _i_cmpxchg: 10022 10023'``cmpxchg``' Instruction 10024^^^^^^^^^^^^^^^^^^^^^^^^^ 10025 10026Syntax: 10027""""""" 10028 10029:: 10030 10031 cmpxchg [weak] [volatile] <ty>* <pointer>, <ty> <cmp>, <ty> <new> [syncscope("<target-scope>")] <success ordering> <failure ordering>[, align <alignment>] ; yields { ty, i1 } 10032 10033Overview: 10034""""""""" 10035 10036The '``cmpxchg``' instruction is used to atomically modify memory. It 10037loads a value in memory and compares it to a given value. If they are 10038equal, it tries to store a new value into the memory. 10039 10040Arguments: 10041"""""""""" 10042 10043There are three arguments to the '``cmpxchg``' instruction: an address 10044to operate on, a value to compare to the value currently be at that 10045address, and a new value to place at that address if the compared values 10046are equal. The type of '<cmp>' must be an integer or pointer type whose 10047bit width is a power of two greater than or equal to eight and less 10048than or equal to a target-specific size limit. '<cmp>' and '<new>' must 10049have the same type, and the type of '<pointer>' must be a pointer to 10050that type. If the ``cmpxchg`` is marked as ``volatile``, then the 10051optimizer is not allowed to modify the number or order of execution of 10052this ``cmpxchg`` with other :ref:`volatile operations <volatile>`. 10053 10054The success and failure :ref:`ordering <ordering>` arguments specify how this 10055``cmpxchg`` synchronizes with other atomic operations. Both ordering parameters 10056must be at least ``monotonic``, the failure ordering cannot be either 10057``release`` or ``acq_rel``. 10058 10059A ``cmpxchg`` instruction can also take an optional 10060":ref:`syncscope <syncscope>`" argument. 10061 10062The instruction can take an optional ``align`` attribute. 10063The alignment must be a power of two greater or equal to the size of the 10064`<value>` type. If unspecified, the alignment is assumed to be equal to the 10065size of the '<value>' type. Note that this default alignment assumption is 10066different from the alignment used for the load/store instructions when align 10067isn't specified. 10068 10069The pointer passed into cmpxchg must have alignment greater than or 10070equal to the size in memory of the operand. 10071 10072Semantics: 10073"""""""""" 10074 10075The contents of memory at the location specified by the '``<pointer>``' operand 10076is read and compared to '``<cmp>``'; if the values are equal, '``<new>``' is 10077written to the location. The original value at the location is returned, 10078together with a flag indicating success (true) or failure (false). 10079 10080If the cmpxchg operation is marked as ``weak`` then a spurious failure is 10081permitted: the operation may not write ``<new>`` even if the comparison 10082matched. 10083 10084If the cmpxchg operation is strong (the default), the i1 value is 1 if and only 10085if the value loaded equals ``cmp``. 10086 10087A successful ``cmpxchg`` is a read-modify-write instruction for the purpose of 10088identifying release sequences. A failed ``cmpxchg`` is equivalent to an atomic 10089load with an ordering parameter determined the second ordering parameter. 10090 10091Example: 10092"""""""" 10093 10094.. code-block:: llvm 10095 10096 entry: 10097 %orig = load atomic i32, i32* %ptr unordered, align 4 ; yields i32 10098 br label %loop 10099 10100 loop: 10101 %cmp = phi i32 [ %orig, %entry ], [%value_loaded, %loop] 10102 %squared = mul i32 %cmp, %cmp 10103 %val_success = cmpxchg i32* %ptr, i32 %cmp, i32 %squared acq_rel monotonic ; yields { i32, i1 } 10104 %value_loaded = extractvalue { i32, i1 } %val_success, 0 10105 %success = extractvalue { i32, i1 } %val_success, 1 10106 br i1 %success, label %done, label %loop 10107 10108 done: 10109 ... 10110 10111.. _i_atomicrmw: 10112 10113'``atomicrmw``' Instruction 10114^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10115 10116Syntax: 10117""""""" 10118 10119:: 10120 10121 atomicrmw [volatile] <operation> <ty>* <pointer>, <ty> <value> [syncscope("<target-scope>")] <ordering>[, align <alignment>] ; yields ty 10122 10123Overview: 10124""""""""" 10125 10126The '``atomicrmw``' instruction is used to atomically modify memory. 10127 10128Arguments: 10129"""""""""" 10130 10131There are three arguments to the '``atomicrmw``' instruction: an 10132operation to apply, an address whose value to modify, an argument to the 10133operation. The operation must be one of the following keywords: 10134 10135- xchg 10136- add 10137- sub 10138- and 10139- nand 10140- or 10141- xor 10142- max 10143- min 10144- umax 10145- umin 10146- fadd 10147- fsub 10148 10149For most of these operations, the type of '<value>' must be an integer 10150type whose bit width is a power of two greater than or equal to eight 10151and less than or equal to a target-specific size limit. For xchg, this 10152may also be a floating point type with the same size constraints as 10153integers. For fadd/fsub, this must be a floating point type. The 10154type of the '``<pointer>``' operand must be a pointer to that type. If 10155the ``atomicrmw`` is marked as ``volatile``, then the optimizer is not 10156allowed to modify the number or order of execution of this 10157``atomicrmw`` with other :ref:`volatile operations <volatile>`. 10158 10159The instruction can take an optional ``align`` attribute. 10160The alignment must be a power of two greater or equal to the size of the 10161`<value>` type. If unspecified, the alignment is assumed to be equal to the 10162size of the '<value>' type. Note that this default alignment assumption is 10163different from the alignment used for the load/store instructions when align 10164isn't specified. 10165 10166A ``atomicrmw`` instruction can also take an optional 10167":ref:`syncscope <syncscope>`" argument. 10168 10169Semantics: 10170"""""""""" 10171 10172The contents of memory at the location specified by the '``<pointer>``' 10173operand are atomically read, modified, and written back. The original 10174value at the location is returned. The modification is specified by the 10175operation argument: 10176 10177- xchg: ``*ptr = val`` 10178- add: ``*ptr = *ptr + val`` 10179- sub: ``*ptr = *ptr - val`` 10180- and: ``*ptr = *ptr & val`` 10181- nand: ``*ptr = ~(*ptr & val)`` 10182- or: ``*ptr = *ptr | val`` 10183- xor: ``*ptr = *ptr ^ val`` 10184- max: ``*ptr = *ptr > val ? *ptr : val`` (using a signed comparison) 10185- min: ``*ptr = *ptr < val ? *ptr : val`` (using a signed comparison) 10186- umax: ``*ptr = *ptr > val ? *ptr : val`` (using an unsigned comparison) 10187- umin: ``*ptr = *ptr < val ? *ptr : val`` (using an unsigned comparison) 10188- fadd: ``*ptr = *ptr + val`` (using floating point arithmetic) 10189- fsub: ``*ptr = *ptr - val`` (using floating point arithmetic) 10190 10191Example: 10192"""""""" 10193 10194.. code-block:: llvm 10195 10196 %old = atomicrmw add i32* %ptr, i32 1 acquire ; yields i32 10197 10198.. _i_getelementptr: 10199 10200'``getelementptr``' Instruction 10201^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10202 10203Syntax: 10204""""""" 10205 10206:: 10207 10208 <result> = getelementptr <ty>, <ty>* <ptrval>{, [inrange] <ty> <idx>}* 10209 <result> = getelementptr inbounds <ty>, <ty>* <ptrval>{, [inrange] <ty> <idx>}* 10210 <result> = getelementptr <ty>, <ptr vector> <ptrval>, [inrange] <vector index type> <idx> 10211 10212Overview: 10213""""""""" 10214 10215The '``getelementptr``' instruction is used to get the address of a 10216subelement of an :ref:`aggregate <t_aggregate>` data structure. It performs 10217address calculation only and does not access memory. The instruction can also 10218be used to calculate a vector of such addresses. 10219 10220Arguments: 10221"""""""""" 10222 10223The first argument is always a type used as the basis for the calculations. 10224The second argument is always a pointer or a vector of pointers, and is the 10225base address to start from. The remaining arguments are indices 10226that indicate which of the elements of the aggregate object are indexed. 10227The interpretation of each index is dependent on the type being indexed 10228into. The first index always indexes the pointer value given as the 10229second argument, the second index indexes a value of the type pointed to 10230(not necessarily the value directly pointed to, since the first index 10231can be non-zero), etc. The first type indexed into must be a pointer 10232value, subsequent types can be arrays, vectors, and structs. Note that 10233subsequent types being indexed into can never be pointers, since that 10234would require loading the pointer before continuing calculation. 10235 10236The type of each index argument depends on the type it is indexing into. 10237When indexing into a (optionally packed) structure, only ``i32`` integer 10238**constants** are allowed (when using a vector of indices they must all 10239be the **same** ``i32`` integer constant). When indexing into an array, 10240pointer or vector, integers of any width are allowed, and they are not 10241required to be constant. These integers are treated as signed values 10242where relevant. 10243 10244For example, let's consider a C code fragment and how it gets compiled 10245to LLVM: 10246 10247.. code-block:: c 10248 10249 struct RT { 10250 char A; 10251 int B[10][20]; 10252 char C; 10253 }; 10254 struct ST { 10255 int X; 10256 double Y; 10257 struct RT Z; 10258 }; 10259 10260 int *foo(struct ST *s) { 10261 return &s[1].Z.B[5][13]; 10262 } 10263 10264The LLVM code generated by Clang is: 10265 10266.. code-block:: llvm 10267 10268 %struct.RT = type { i8, [10 x [20 x i32]], i8 } 10269 %struct.ST = type { i32, double, %struct.RT } 10270 10271 define i32* @foo(%struct.ST* %s) nounwind uwtable readnone optsize ssp { 10272 entry: 10273 %arrayidx = getelementptr inbounds %struct.ST, %struct.ST* %s, i64 1, i32 2, i32 1, i64 5, i64 13 10274 ret i32* %arrayidx 10275 } 10276 10277Semantics: 10278"""""""""" 10279 10280In the example above, the first index is indexing into the 10281'``%struct.ST*``' type, which is a pointer, yielding a '``%struct.ST``' 10282= '``{ i32, double, %struct.RT }``' type, a structure. The second index 10283indexes into the third element of the structure, yielding a 10284'``%struct.RT``' = '``{ i8 , [10 x [20 x i32]], i8 }``' type, another 10285structure. The third index indexes into the second element of the 10286structure, yielding a '``[10 x [20 x i32]]``' type, an array. The two 10287dimensions of the array are subscripted into, yielding an '``i32``' 10288type. The '``getelementptr``' instruction returns a pointer to this 10289element, thus computing a value of '``i32*``' type. 10290 10291Note that it is perfectly legal to index partially through a structure, 10292returning a pointer to an inner element. Because of this, the LLVM code 10293for the given testcase is equivalent to: 10294 10295.. code-block:: llvm 10296 10297 define i32* @foo(%struct.ST* %s) { 10298 %t1 = getelementptr %struct.ST, %struct.ST* %s, i32 1 ; yields %struct.ST*:%t1 10299 %t2 = getelementptr %struct.ST, %struct.ST* %t1, i32 0, i32 2 ; yields %struct.RT*:%t2 10300 %t3 = getelementptr %struct.RT, %struct.RT* %t2, i32 0, i32 1 ; yields [10 x [20 x i32]]*:%t3 10301 %t4 = getelementptr [10 x [20 x i32]], [10 x [20 x i32]]* %t3, i32 0, i32 5 ; yields [20 x i32]*:%t4 10302 %t5 = getelementptr [20 x i32], [20 x i32]* %t4, i32 0, i32 13 ; yields i32*:%t5 10303 ret i32* %t5 10304 } 10305 10306If the ``inbounds`` keyword is present, the result value of the 10307``getelementptr`` is a :ref:`poison value <poisonvalues>` if one of the 10308following rules is violated: 10309 10310* The base pointer has an *in bounds* address of an allocated object, which 10311 means that it points into an allocated object, or to its end. The only 10312 *in bounds* address for a null pointer in the default address-space is the 10313 null pointer itself. 10314* If the type of an index is larger than the pointer index type, the 10315 truncation to the pointer index type preserves the signed value. 10316* The multiplication of an index by the type size does not wrap the pointer 10317 index type in a signed sense (``nsw``). 10318* The successive addition of offsets (without adding the base address) does 10319 not wrap the pointer index type in a signed sense (``nsw``). 10320* The successive addition of the current address, interpreted as an unsigned 10321 number, and an offset, interpreted as a signed number, does not wrap the 10322 unsigned address space and remains *in bounds* of the allocated object. 10323 As a corollary, if the added offset is non-negative, the addition does not 10324 wrap in an unsigned sense (``nuw``). 10325* In cases where the base is a vector of pointers, the ``inbounds`` keyword 10326 applies to each of the computations element-wise. 10327 10328These rules are based on the assumption that no allocated object may cross 10329the unsigned address space boundary, and no allocated object may be larger 10330than half the pointer index type space. 10331 10332If the ``inbounds`` keyword is not present, the offsets are added to the 10333base address with silently-wrapping two's complement arithmetic. If the 10334offsets have a different width from the pointer, they are sign-extended 10335or truncated to the width of the pointer. The result value of the 10336``getelementptr`` may be outside the object pointed to by the base 10337pointer. The result value may not necessarily be used to access memory 10338though, even if it happens to point into allocated storage. See the 10339:ref:`Pointer Aliasing Rules <pointeraliasing>` section for more 10340information. 10341 10342If the ``inrange`` keyword is present before any index, loading from or 10343storing to any pointer derived from the ``getelementptr`` has undefined 10344behavior if the load or store would access memory outside of the bounds of 10345the element selected by the index marked as ``inrange``. The result of a 10346pointer comparison or ``ptrtoint`` (including ``ptrtoint``-like operations 10347involving memory) involving a pointer derived from a ``getelementptr`` with 10348the ``inrange`` keyword is undefined, with the exception of comparisons 10349in the case where both operands are in the range of the element selected 10350by the ``inrange`` keyword, inclusive of the address one past the end of 10351that element. Note that the ``inrange`` keyword is currently only allowed 10352in constant ``getelementptr`` expressions. 10353 10354The getelementptr instruction is often confusing. For some more insight 10355into how it works, see :doc:`the getelementptr FAQ <GetElementPtr>`. 10356 10357Example: 10358"""""""" 10359 10360.. code-block:: llvm 10361 10362 ; yields [12 x i8]*:aptr 10363 %aptr = getelementptr {i32, [12 x i8]}, {i32, [12 x i8]}* %saptr, i64 0, i32 1 10364 ; yields i8*:vptr 10365 %vptr = getelementptr {i32, <2 x i8>}, {i32, <2 x i8>}* %svptr, i64 0, i32 1, i32 1 10366 ; yields i8*:eptr 10367 %eptr = getelementptr [12 x i8], [12 x i8]* %aptr, i64 0, i32 1 10368 ; yields i32*:iptr 10369 %iptr = getelementptr [10 x i32], [10 x i32]* @arr, i16 0, i16 0 10370 10371Vector of pointers: 10372""""""""""""""""""" 10373 10374The ``getelementptr`` returns a vector of pointers, instead of a single address, 10375when one or more of its arguments is a vector. In such cases, all vector 10376arguments should have the same number of elements, and every scalar argument 10377will be effectively broadcast into a vector during address calculation. 10378 10379.. code-block:: llvm 10380 10381 ; All arguments are vectors: 10382 ; A[i] = ptrs[i] + offsets[i]*sizeof(i8) 10383 %A = getelementptr i8, <4 x i8*> %ptrs, <4 x i64> %offsets 10384 10385 ; Add the same scalar offset to each pointer of a vector: 10386 ; A[i] = ptrs[i] + offset*sizeof(i8) 10387 %A = getelementptr i8, <4 x i8*> %ptrs, i64 %offset 10388 10389 ; Add distinct offsets to the same pointer: 10390 ; A[i] = ptr + offsets[i]*sizeof(i8) 10391 %A = getelementptr i8, i8* %ptr, <4 x i64> %offsets 10392 10393 ; In all cases described above the type of the result is <4 x i8*> 10394 10395The two following instructions are equivalent: 10396 10397.. code-block:: llvm 10398 10399 getelementptr %struct.ST, <4 x %struct.ST*> %s, <4 x i64> %ind1, 10400 <4 x i32> <i32 2, i32 2, i32 2, i32 2>, 10401 <4 x i32> <i32 1, i32 1, i32 1, i32 1>, 10402 <4 x i32> %ind4, 10403 <4 x i64> <i64 13, i64 13, i64 13, i64 13> 10404 10405 getelementptr %struct.ST, <4 x %struct.ST*> %s, <4 x i64> %ind1, 10406 i32 2, i32 1, <4 x i32> %ind4, i64 13 10407 10408Let's look at the C code, where the vector version of ``getelementptr`` 10409makes sense: 10410 10411.. code-block:: c 10412 10413 // Let's assume that we vectorize the following loop: 10414 double *A, *B; int *C; 10415 for (int i = 0; i < size; ++i) { 10416 A[i] = B[C[i]]; 10417 } 10418 10419.. code-block:: llvm 10420 10421 ; get pointers for 8 elements from array B 10422 %ptrs = getelementptr double, double* %B, <8 x i32> %C 10423 ; load 8 elements from array B into A 10424 %A = call <8 x double> @llvm.masked.gather.v8f64.v8p0f64(<8 x double*> %ptrs, 10425 i32 8, <8 x i1> %mask, <8 x double> %passthru) 10426 10427Conversion Operations 10428--------------------- 10429 10430The instructions in this category are the conversion instructions 10431(casting) which all take a single operand and a type. They perform 10432various bit conversions on the operand. 10433 10434.. _i_trunc: 10435 10436'``trunc .. to``' Instruction 10437^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10438 10439Syntax: 10440""""""" 10441 10442:: 10443 10444 <result> = trunc <ty> <value> to <ty2> ; yields ty2 10445 10446Overview: 10447""""""""" 10448 10449The '``trunc``' instruction truncates its operand to the type ``ty2``. 10450 10451Arguments: 10452"""""""""" 10453 10454The '``trunc``' instruction takes a value to trunc, and a type to trunc 10455it to. Both types must be of :ref:`integer <t_integer>` types, or vectors 10456of the same number of integers. The bit size of the ``value`` must be 10457larger than the bit size of the destination type, ``ty2``. Equal sized 10458types are not allowed. 10459 10460Semantics: 10461"""""""""" 10462 10463The '``trunc``' instruction truncates the high order bits in ``value`` 10464and converts the remaining bits to ``ty2``. Since the source size must 10465be larger than the destination size, ``trunc`` cannot be a *no-op cast*. 10466It will always truncate bits. 10467 10468Example: 10469"""""""" 10470 10471.. code-block:: llvm 10472 10473 %X = trunc i32 257 to i8 ; yields i8:1 10474 %Y = trunc i32 123 to i1 ; yields i1:true 10475 %Z = trunc i32 122 to i1 ; yields i1:false 10476 %W = trunc <2 x i16> <i16 8, i16 7> to <2 x i8> ; yields <i8 8, i8 7> 10477 10478.. _i_zext: 10479 10480'``zext .. to``' Instruction 10481^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10482 10483Syntax: 10484""""""" 10485 10486:: 10487 10488 <result> = zext <ty> <value> to <ty2> ; yields ty2 10489 10490Overview: 10491""""""""" 10492 10493The '``zext``' instruction zero extends its operand to type ``ty2``. 10494 10495Arguments: 10496"""""""""" 10497 10498The '``zext``' instruction takes a value to cast, and a type to cast it 10499to. Both types must be of :ref:`integer <t_integer>` types, or vectors of 10500the same number of integers. The bit size of the ``value`` must be 10501smaller than the bit size of the destination type, ``ty2``. 10502 10503Semantics: 10504"""""""""" 10505 10506The ``zext`` fills the high order bits of the ``value`` with zero bits 10507until it reaches the size of the destination type, ``ty2``. 10508 10509When zero extending from i1, the result will always be either 0 or 1. 10510 10511Example: 10512"""""""" 10513 10514.. code-block:: llvm 10515 10516 %X = zext i32 257 to i64 ; yields i64:257 10517 %Y = zext i1 true to i32 ; yields i32:1 10518 %Z = zext <2 x i16> <i16 8, i16 7> to <2 x i32> ; yields <i32 8, i32 7> 10519 10520.. _i_sext: 10521 10522'``sext .. to``' Instruction 10523^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10524 10525Syntax: 10526""""""" 10527 10528:: 10529 10530 <result> = sext <ty> <value> to <ty2> ; yields ty2 10531 10532Overview: 10533""""""""" 10534 10535The '``sext``' sign extends ``value`` to the type ``ty2``. 10536 10537Arguments: 10538"""""""""" 10539 10540The '``sext``' instruction takes a value to cast, and a type to cast it 10541to. Both types must be of :ref:`integer <t_integer>` types, or vectors of 10542the same number of integers. The bit size of the ``value`` must be 10543smaller than the bit size of the destination type, ``ty2``. 10544 10545Semantics: 10546"""""""""" 10547 10548The '``sext``' instruction performs a sign extension by copying the sign 10549bit (highest order bit) of the ``value`` until it reaches the bit size 10550of the type ``ty2``. 10551 10552When sign extending from i1, the extension always results in -1 or 0. 10553 10554Example: 10555"""""""" 10556 10557.. code-block:: llvm 10558 10559 %X = sext i8 -1 to i16 ; yields i16 :65535 10560 %Y = sext i1 true to i32 ; yields i32:-1 10561 %Z = sext <2 x i16> <i16 8, i16 7> to <2 x i32> ; yields <i32 8, i32 7> 10562 10563'``fptrunc .. to``' Instruction 10564^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10565 10566Syntax: 10567""""""" 10568 10569:: 10570 10571 <result> = fptrunc <ty> <value> to <ty2> ; yields ty2 10572 10573Overview: 10574""""""""" 10575 10576The '``fptrunc``' instruction truncates ``value`` to type ``ty2``. 10577 10578Arguments: 10579"""""""""" 10580 10581The '``fptrunc``' instruction takes a :ref:`floating-point <t_floating>` 10582value to cast and a :ref:`floating-point <t_floating>` type to cast it to. 10583The size of ``value`` must be larger than the size of ``ty2``. This 10584implies that ``fptrunc`` cannot be used to make a *no-op cast*. 10585 10586Semantics: 10587"""""""""" 10588 10589The '``fptrunc``' instruction casts a ``value`` from a larger 10590:ref:`floating-point <t_floating>` type to a smaller :ref:`floating-point 10591<t_floating>` type. 10592This instruction is assumed to execute in the default :ref:`floating-point 10593environment <floatenv>`. 10594 10595Example: 10596"""""""" 10597 10598.. code-block:: llvm 10599 10600 %X = fptrunc double 16777217.0 to float ; yields float:16777216.0 10601 %Y = fptrunc double 1.0E+300 to half ; yields half:+infinity 10602 10603'``fpext .. to``' Instruction 10604^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10605 10606Syntax: 10607""""""" 10608 10609:: 10610 10611 <result> = fpext <ty> <value> to <ty2> ; yields ty2 10612 10613Overview: 10614""""""""" 10615 10616The '``fpext``' extends a floating-point ``value`` to a larger floating-point 10617value. 10618 10619Arguments: 10620"""""""""" 10621 10622The '``fpext``' instruction takes a :ref:`floating-point <t_floating>` 10623``value`` to cast, and a :ref:`floating-point <t_floating>` type to cast it 10624to. The source type must be smaller than the destination type. 10625 10626Semantics: 10627"""""""""" 10628 10629The '``fpext``' instruction extends the ``value`` from a smaller 10630:ref:`floating-point <t_floating>` type to a larger :ref:`floating-point 10631<t_floating>` type. The ``fpext`` cannot be used to make a 10632*no-op cast* because it always changes bits. Use ``bitcast`` to make a 10633*no-op cast* for a floating-point cast. 10634 10635Example: 10636"""""""" 10637 10638.. code-block:: llvm 10639 10640 %X = fpext float 3.125 to double ; yields double:3.125000e+00 10641 %Y = fpext double %X to fp128 ; yields fp128:0xL00000000000000004000900000000000 10642 10643'``fptoui .. to``' Instruction 10644^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10645 10646Syntax: 10647""""""" 10648 10649:: 10650 10651 <result> = fptoui <ty> <value> to <ty2> ; yields ty2 10652 10653Overview: 10654""""""""" 10655 10656The '``fptoui``' converts a floating-point ``value`` to its unsigned 10657integer equivalent of type ``ty2``. 10658 10659Arguments: 10660"""""""""" 10661 10662The '``fptoui``' instruction takes a value to cast, which must be a 10663scalar or vector :ref:`floating-point <t_floating>` value, and a type to 10664cast it to ``ty2``, which must be an :ref:`integer <t_integer>` type. If 10665``ty`` is a vector floating-point type, ``ty2`` must be a vector integer 10666type with the same number of elements as ``ty`` 10667 10668Semantics: 10669"""""""""" 10670 10671The '``fptoui``' instruction converts its :ref:`floating-point 10672<t_floating>` operand into the nearest (rounding towards zero) 10673unsigned integer value. If the value cannot fit in ``ty2``, the result 10674is a :ref:`poison value <poisonvalues>`. 10675 10676Example: 10677"""""""" 10678 10679.. code-block:: llvm 10680 10681 %X = fptoui double 123.0 to i32 ; yields i32:123 10682 %Y = fptoui float 1.0E+300 to i1 ; yields undefined:1 10683 %Z = fptoui float 1.04E+17 to i8 ; yields undefined:1 10684 10685'``fptosi .. to``' Instruction 10686^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10687 10688Syntax: 10689""""""" 10690 10691:: 10692 10693 <result> = fptosi <ty> <value> to <ty2> ; yields ty2 10694 10695Overview: 10696""""""""" 10697 10698The '``fptosi``' instruction converts :ref:`floating-point <t_floating>` 10699``value`` to type ``ty2``. 10700 10701Arguments: 10702"""""""""" 10703 10704The '``fptosi``' instruction takes a value to cast, which must be a 10705scalar or vector :ref:`floating-point <t_floating>` value, and a type to 10706cast it to ``ty2``, which must be an :ref:`integer <t_integer>` type. If 10707``ty`` is a vector floating-point type, ``ty2`` must be a vector integer 10708type with the same number of elements as ``ty`` 10709 10710Semantics: 10711"""""""""" 10712 10713The '``fptosi``' instruction converts its :ref:`floating-point 10714<t_floating>` operand into the nearest (rounding towards zero) 10715signed integer value. If the value cannot fit in ``ty2``, the result 10716is a :ref:`poison value <poisonvalues>`. 10717 10718Example: 10719"""""""" 10720 10721.. code-block:: llvm 10722 10723 %X = fptosi double -123.0 to i32 ; yields i32:-123 10724 %Y = fptosi float 1.0E-247 to i1 ; yields undefined:1 10725 %Z = fptosi float 1.04E+17 to i8 ; yields undefined:1 10726 10727'``uitofp .. to``' Instruction 10728^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10729 10730Syntax: 10731""""""" 10732 10733:: 10734 10735 <result> = uitofp <ty> <value> to <ty2> ; yields ty2 10736 10737Overview: 10738""""""""" 10739 10740The '``uitofp``' instruction regards ``value`` as an unsigned integer 10741and converts that value to the ``ty2`` type. 10742 10743Arguments: 10744"""""""""" 10745 10746The '``uitofp``' instruction takes a value to cast, which must be a 10747scalar or vector :ref:`integer <t_integer>` value, and a type to cast it to 10748``ty2``, which must be an :ref:`floating-point <t_floating>` type. If 10749``ty`` is a vector integer type, ``ty2`` must be a vector floating-point 10750type with the same number of elements as ``ty`` 10751 10752Semantics: 10753"""""""""" 10754 10755The '``uitofp``' instruction interprets its operand as an unsigned 10756integer quantity and converts it to the corresponding floating-point 10757value. If the value cannot be exactly represented, it is rounded using 10758the default rounding mode. 10759 10760 10761Example: 10762"""""""" 10763 10764.. code-block:: llvm 10765 10766 %X = uitofp i32 257 to float ; yields float:257.0 10767 %Y = uitofp i8 -1 to double ; yields double:255.0 10768 10769'``sitofp .. to``' Instruction 10770^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10771 10772Syntax: 10773""""""" 10774 10775:: 10776 10777 <result> = sitofp <ty> <value> to <ty2> ; yields ty2 10778 10779Overview: 10780""""""""" 10781 10782The '``sitofp``' instruction regards ``value`` as a signed integer and 10783converts that value to the ``ty2`` type. 10784 10785Arguments: 10786"""""""""" 10787 10788The '``sitofp``' instruction takes a value to cast, which must be a 10789scalar or vector :ref:`integer <t_integer>` value, and a type to cast it to 10790``ty2``, which must be an :ref:`floating-point <t_floating>` type. If 10791``ty`` is a vector integer type, ``ty2`` must be a vector floating-point 10792type with the same number of elements as ``ty`` 10793 10794Semantics: 10795"""""""""" 10796 10797The '``sitofp``' instruction interprets its operand as a signed integer 10798quantity and converts it to the corresponding floating-point value. If the 10799value cannot be exactly represented, it is rounded using the default rounding 10800mode. 10801 10802Example: 10803"""""""" 10804 10805.. code-block:: llvm 10806 10807 %X = sitofp i32 257 to float ; yields float:257.0 10808 %Y = sitofp i8 -1 to double ; yields double:-1.0 10809 10810.. _i_ptrtoint: 10811 10812'``ptrtoint .. to``' Instruction 10813^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10814 10815Syntax: 10816""""""" 10817 10818:: 10819 10820 <result> = ptrtoint <ty> <value> to <ty2> ; yields ty2 10821 10822Overview: 10823""""""""" 10824 10825The '``ptrtoint``' instruction converts the pointer or a vector of 10826pointers ``value`` to the integer (or vector of integers) type ``ty2``. 10827 10828Arguments: 10829"""""""""" 10830 10831The '``ptrtoint``' instruction takes a ``value`` to cast, which must be 10832a value of type :ref:`pointer <t_pointer>` or a vector of pointers, and a 10833type to cast it to ``ty2``, which must be an :ref:`integer <t_integer>` or 10834a vector of integers type. 10835 10836Semantics: 10837"""""""""" 10838 10839The '``ptrtoint``' instruction converts ``value`` to integer type 10840``ty2`` by interpreting the pointer value as an integer and either 10841truncating or zero extending that value to the size of the integer type. 10842If ``value`` is smaller than ``ty2`` then a zero extension is done. If 10843``value`` is larger than ``ty2`` then a truncation is done. If they are 10844the same size, then nothing is done (*no-op cast*) other than a type 10845change. 10846 10847Example: 10848"""""""" 10849 10850.. code-block:: llvm 10851 10852 %X = ptrtoint i32* %P to i8 ; yields truncation on 32-bit architecture 10853 %Y = ptrtoint i32* %P to i64 ; yields zero extension on 32-bit architecture 10854 %Z = ptrtoint <4 x i32*> %P to <4 x i64>; yields vector zero extension for a vector of addresses on 32-bit architecture 10855 10856.. _i_inttoptr: 10857 10858'``inttoptr .. to``' Instruction 10859^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10860 10861Syntax: 10862""""""" 10863 10864:: 10865 10866 <result> = inttoptr <ty> <value> to <ty2>[, !dereferenceable !<deref_bytes_node>][, !dereferenceable_or_null !<deref_bytes_node>] ; yields ty2 10867 10868Overview: 10869""""""""" 10870 10871The '``inttoptr``' instruction converts an integer ``value`` to a 10872pointer type, ``ty2``. 10873 10874Arguments: 10875"""""""""" 10876 10877The '``inttoptr``' instruction takes an :ref:`integer <t_integer>` value to 10878cast, and a type to cast it to, which must be a :ref:`pointer <t_pointer>` 10879type. 10880 10881The optional ``!dereferenceable`` metadata must reference a single metadata 10882name ``<deref_bytes_node>`` corresponding to a metadata node with one ``i64`` 10883entry. 10884See ``dereferenceable`` metadata. 10885 10886The optional ``!dereferenceable_or_null`` metadata must reference a single 10887metadata name ``<deref_bytes_node>`` corresponding to a metadata node with one 10888``i64`` entry. 10889See ``dereferenceable_or_null`` metadata. 10890 10891Semantics: 10892"""""""""" 10893 10894The '``inttoptr``' instruction converts ``value`` to type ``ty2`` by 10895applying either a zero extension or a truncation depending on the size 10896of the integer ``value``. If ``value`` is larger than the size of a 10897pointer then a truncation is done. If ``value`` is smaller than the size 10898of a pointer then a zero extension is done. If they are the same size, 10899nothing is done (*no-op cast*). 10900 10901Example: 10902"""""""" 10903 10904.. code-block:: llvm 10905 10906 %X = inttoptr i32 255 to i32* ; yields zero extension on 64-bit architecture 10907 %Y = inttoptr i32 255 to i32* ; yields no-op on 32-bit architecture 10908 %Z = inttoptr i64 0 to i32* ; yields truncation on 32-bit architecture 10909 %Z = inttoptr <4 x i32> %G to <4 x i8*>; yields truncation of vector G to four pointers 10910 10911.. _i_bitcast: 10912 10913'``bitcast .. to``' Instruction 10914^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10915 10916Syntax: 10917""""""" 10918 10919:: 10920 10921 <result> = bitcast <ty> <value> to <ty2> ; yields ty2 10922 10923Overview: 10924""""""""" 10925 10926The '``bitcast``' instruction converts ``value`` to type ``ty2`` without 10927changing any bits. 10928 10929Arguments: 10930"""""""""" 10931 10932The '``bitcast``' instruction takes a value to cast, which must be a 10933non-aggregate first class value, and a type to cast it to, which must 10934also be a non-aggregate :ref:`first class <t_firstclass>` type. The 10935bit sizes of ``value`` and the destination type, ``ty2``, must be 10936identical. If the source type is a pointer, the destination type must 10937also be a pointer of the same size. This instruction supports bitwise 10938conversion of vectors to integers and to vectors of other types (as 10939long as they have the same size). 10940 10941Semantics: 10942"""""""""" 10943 10944The '``bitcast``' instruction converts ``value`` to type ``ty2``. It 10945is always a *no-op cast* because no bits change with this 10946conversion. The conversion is done as if the ``value`` had been stored 10947to memory and read back as type ``ty2``. Pointer (or vector of 10948pointers) types may only be converted to other pointer (or vector of 10949pointers) types with the same address space through this instruction. 10950To convert pointers to other types, use the :ref:`inttoptr <i_inttoptr>` 10951or :ref:`ptrtoint <i_ptrtoint>` instructions first. 10952 10953There is a caveat for bitcasts involving vector types in relation to 10954endianess. For example ``bitcast <2 x i8> <value> to i16`` puts element zero 10955of the vector in the least significant bits of the i16 for little-endian while 10956element zero ends up in the most significant bits for big-endian. 10957 10958Example: 10959"""""""" 10960 10961.. code-block:: text 10962 10963 %X = bitcast i8 255 to i8 ; yields i8 :-1 10964 %Y = bitcast i32* %x to sint* ; yields sint*:%x 10965 %Z = bitcast <2 x int> %V to i64; ; yields i64: %V (depends on endianess) 10966 %Z = bitcast <2 x i32*> %V to <2 x i64*> ; yields <2 x i64*> 10967 10968.. _i_addrspacecast: 10969 10970'``addrspacecast .. to``' Instruction 10971^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10972 10973Syntax: 10974""""""" 10975 10976:: 10977 10978 <result> = addrspacecast <pty> <ptrval> to <pty2> ; yields pty2 10979 10980Overview: 10981""""""""" 10982 10983The '``addrspacecast``' instruction converts ``ptrval`` from ``pty`` in 10984address space ``n`` to type ``pty2`` in address space ``m``. 10985 10986Arguments: 10987"""""""""" 10988 10989The '``addrspacecast``' instruction takes a pointer or vector of pointer value 10990to cast and a pointer type to cast it to, which must have a different 10991address space. 10992 10993Semantics: 10994"""""""""" 10995 10996The '``addrspacecast``' instruction converts the pointer value 10997``ptrval`` to type ``pty2``. It can be a *no-op cast* or a complex 10998value modification, depending on the target and the address space 10999pair. Pointer conversions within the same address space must be 11000performed with the ``bitcast`` instruction. Note that if the address space 11001conversion is legal then both result and operand refer to the same memory 11002location. 11003 11004Example: 11005"""""""" 11006 11007.. code-block:: llvm 11008 11009 %X = addrspacecast i32* %x to i32 addrspace(1)* ; yields i32 addrspace(1)*:%x 11010 %Y = addrspacecast i32 addrspace(1)* %y to i64 addrspace(2)* ; yields i64 addrspace(2)*:%y 11011 %Z = addrspacecast <4 x i32*> %z to <4 x float addrspace(3)*> ; yields <4 x float addrspace(3)*>:%z 11012 11013.. _otherops: 11014 11015Other Operations 11016---------------- 11017 11018The instructions in this category are the "miscellaneous" instructions, 11019which defy better classification. 11020 11021.. _i_icmp: 11022 11023'``icmp``' Instruction 11024^^^^^^^^^^^^^^^^^^^^^^ 11025 11026Syntax: 11027""""""" 11028 11029:: 11030 11031 <result> = icmp <cond> <ty> <op1>, <op2> ; yields i1 or <N x i1>:result 11032 11033Overview: 11034""""""""" 11035 11036The '``icmp``' instruction returns a boolean value or a vector of 11037boolean values based on comparison of its two integer, integer vector, 11038pointer, or pointer vector operands. 11039 11040Arguments: 11041"""""""""" 11042 11043The '``icmp``' instruction takes three operands. The first operand is 11044the condition code indicating the kind of comparison to perform. It is 11045not a value, just a keyword. The possible condition codes are: 11046 11047#. ``eq``: equal 11048#. ``ne``: not equal 11049#. ``ugt``: unsigned greater than 11050#. ``uge``: unsigned greater or equal 11051#. ``ult``: unsigned less than 11052#. ``ule``: unsigned less or equal 11053#. ``sgt``: signed greater than 11054#. ``sge``: signed greater or equal 11055#. ``slt``: signed less than 11056#. ``sle``: signed less or equal 11057 11058The remaining two arguments must be :ref:`integer <t_integer>` or 11059:ref:`pointer <t_pointer>` or integer :ref:`vector <t_vector>` typed. They 11060must also be identical types. 11061 11062Semantics: 11063"""""""""" 11064 11065The '``icmp``' compares ``op1`` and ``op2`` according to the condition 11066code given as ``cond``. The comparison performed always yields either an 11067:ref:`i1 <t_integer>` or vector of ``i1`` result, as follows: 11068 11069#. ``eq``: yields ``true`` if the operands are equal, ``false`` 11070 otherwise. No sign interpretation is necessary or performed. 11071#. ``ne``: yields ``true`` if the operands are unequal, ``false`` 11072 otherwise. No sign interpretation is necessary or performed. 11073#. ``ugt``: interprets the operands as unsigned values and yields 11074 ``true`` if ``op1`` is greater than ``op2``. 11075#. ``uge``: interprets the operands as unsigned values and yields 11076 ``true`` if ``op1`` is greater than or equal to ``op2``. 11077#. ``ult``: interprets the operands as unsigned values and yields 11078 ``true`` if ``op1`` is less than ``op2``. 11079#. ``ule``: interprets the operands as unsigned values and yields 11080 ``true`` if ``op1`` is less than or equal to ``op2``. 11081#. ``sgt``: interprets the operands as signed values and yields ``true`` 11082 if ``op1`` is greater than ``op2``. 11083#. ``sge``: interprets the operands as signed values and yields ``true`` 11084 if ``op1`` is greater than or equal to ``op2``. 11085#. ``slt``: interprets the operands as signed values and yields ``true`` 11086 if ``op1`` is less than ``op2``. 11087#. ``sle``: interprets the operands as signed values and yields ``true`` 11088 if ``op1`` is less than or equal to ``op2``. 11089 11090If the operands are :ref:`pointer <t_pointer>` typed, the pointer values 11091are compared as if they were integers. 11092 11093If the operands are integer vectors, then they are compared element by 11094element. The result is an ``i1`` vector with the same number of elements 11095as the values being compared. Otherwise, the result is an ``i1``. 11096 11097Example: 11098"""""""" 11099 11100.. code-block:: text 11101 11102 <result> = icmp eq i32 4, 5 ; yields: result=false 11103 <result> = icmp ne float* %X, %X ; yields: result=false 11104 <result> = icmp ult i16 4, 5 ; yields: result=true 11105 <result> = icmp sgt i16 4, 5 ; yields: result=false 11106 <result> = icmp ule i16 -4, 5 ; yields: result=false 11107 <result> = icmp sge i16 4, 5 ; yields: result=false 11108 11109.. _i_fcmp: 11110 11111'``fcmp``' Instruction 11112^^^^^^^^^^^^^^^^^^^^^^ 11113 11114Syntax: 11115""""""" 11116 11117:: 11118 11119 <result> = fcmp [fast-math flags]* <cond> <ty> <op1>, <op2> ; yields i1 or <N x i1>:result 11120 11121Overview: 11122""""""""" 11123 11124The '``fcmp``' instruction returns a boolean value or vector of boolean 11125values based on comparison of its operands. 11126 11127If the operands are floating-point scalars, then the result type is a 11128boolean (:ref:`i1 <t_integer>`). 11129 11130If the operands are floating-point vectors, then the result type is a 11131vector of boolean with the same number of elements as the operands being 11132compared. 11133 11134Arguments: 11135"""""""""" 11136 11137The '``fcmp``' instruction takes three operands. The first operand is 11138the condition code indicating the kind of comparison to perform. It is 11139not a value, just a keyword. The possible condition codes are: 11140 11141#. ``false``: no comparison, always returns false 11142#. ``oeq``: ordered and equal 11143#. ``ogt``: ordered and greater than 11144#. ``oge``: ordered and greater than or equal 11145#. ``olt``: ordered and less than 11146#. ``ole``: ordered and less than or equal 11147#. ``one``: ordered and not equal 11148#. ``ord``: ordered (no nans) 11149#. ``ueq``: unordered or equal 11150#. ``ugt``: unordered or greater than 11151#. ``uge``: unordered or greater than or equal 11152#. ``ult``: unordered or less than 11153#. ``ule``: unordered or less than or equal 11154#. ``une``: unordered or not equal 11155#. ``uno``: unordered (either nans) 11156#. ``true``: no comparison, always returns true 11157 11158*Ordered* means that neither operand is a QNAN while *unordered* means 11159that either operand may be a QNAN. 11160 11161Each of ``val1`` and ``val2`` arguments must be either a :ref:`floating-point 11162<t_floating>` type or a :ref:`vector <t_vector>` of floating-point type. 11163They must have identical types. 11164 11165Semantics: 11166"""""""""" 11167 11168The '``fcmp``' instruction compares ``op1`` and ``op2`` according to the 11169condition code given as ``cond``. If the operands are vectors, then the 11170vectors are compared element by element. Each comparison performed 11171always yields an :ref:`i1 <t_integer>` result, as follows: 11172 11173#. ``false``: always yields ``false``, regardless of operands. 11174#. ``oeq``: yields ``true`` if both operands are not a QNAN and ``op1`` 11175 is equal to ``op2``. 11176#. ``ogt``: yields ``true`` if both operands are not a QNAN and ``op1`` 11177 is greater than ``op2``. 11178#. ``oge``: yields ``true`` if both operands are not a QNAN and ``op1`` 11179 is greater than or equal to ``op2``. 11180#. ``olt``: yields ``true`` if both operands are not a QNAN and ``op1`` 11181 is less than ``op2``. 11182#. ``ole``: yields ``true`` if both operands are not a QNAN and ``op1`` 11183 is less than or equal to ``op2``. 11184#. ``one``: yields ``true`` if both operands are not a QNAN and ``op1`` 11185 is not equal to ``op2``. 11186#. ``ord``: yields ``true`` if both operands are not a QNAN. 11187#. ``ueq``: yields ``true`` if either operand is a QNAN or ``op1`` is 11188 equal to ``op2``. 11189#. ``ugt``: yields ``true`` if either operand is a QNAN or ``op1`` is 11190 greater than ``op2``. 11191#. ``uge``: yields ``true`` if either operand is a QNAN or ``op1`` is 11192 greater than or equal to ``op2``. 11193#. ``ult``: yields ``true`` if either operand is a QNAN or ``op1`` is 11194 less than ``op2``. 11195#. ``ule``: yields ``true`` if either operand is a QNAN or ``op1`` is 11196 less than or equal to ``op2``. 11197#. ``une``: yields ``true`` if either operand is a QNAN or ``op1`` is 11198 not equal to ``op2``. 11199#. ``uno``: yields ``true`` if either operand is a QNAN. 11200#. ``true``: always yields ``true``, regardless of operands. 11201 11202The ``fcmp`` instruction can also optionally take any number of 11203:ref:`fast-math flags <fastmath>`, which are optimization hints to enable 11204otherwise unsafe floating-point optimizations. 11205 11206Any set of fast-math flags are legal on an ``fcmp`` instruction, but the 11207only flags that have any effect on its semantics are those that allow 11208assumptions to be made about the values of input arguments; namely 11209``nnan``, ``ninf``, and ``reassoc``. See :ref:`fastmath` for more information. 11210 11211Example: 11212"""""""" 11213 11214.. code-block:: text 11215 11216 <result> = fcmp oeq float 4.0, 5.0 ; yields: result=false 11217 <result> = fcmp one float 4.0, 5.0 ; yields: result=true 11218 <result> = fcmp olt float 4.0, 5.0 ; yields: result=true 11219 <result> = fcmp ueq double 1.0, 2.0 ; yields: result=false 11220 11221.. _i_phi: 11222 11223'``phi``' Instruction 11224^^^^^^^^^^^^^^^^^^^^^ 11225 11226Syntax: 11227""""""" 11228 11229:: 11230 11231 <result> = phi [fast-math-flags] <ty> [ <val0>, <label0>], ... 11232 11233Overview: 11234""""""""" 11235 11236The '``phi``' instruction is used to implement the φ node in the SSA 11237graph representing the function. 11238 11239Arguments: 11240"""""""""" 11241 11242The type of the incoming values is specified with the first type field. 11243After this, the '``phi``' instruction takes a list of pairs as 11244arguments, with one pair for each predecessor basic block of the current 11245block. Only values of :ref:`first class <t_firstclass>` type may be used as 11246the value arguments to the PHI node. Only labels may be used as the 11247label arguments. 11248 11249There must be no non-phi instructions between the start of a basic block 11250and the PHI instructions: i.e. PHI instructions must be first in a basic 11251block. 11252 11253For the purposes of the SSA form, the use of each incoming value is 11254deemed to occur on the edge from the corresponding predecessor block to 11255the current block (but after any definition of an '``invoke``' 11256instruction's return value on the same edge). 11257 11258The optional ``fast-math-flags`` marker indicates that the phi has one 11259or more :ref:`fast-math-flags <fastmath>`. These are optimization hints 11260to enable otherwise unsafe floating-point optimizations. Fast-math-flags 11261are only valid for phis that return a floating-point scalar or vector 11262type, or an array (nested to any depth) of floating-point scalar or vector 11263types. 11264 11265Semantics: 11266"""""""""" 11267 11268At runtime, the '``phi``' instruction logically takes on the value 11269specified by the pair corresponding to the predecessor basic block that 11270executed just prior to the current block. 11271 11272Example: 11273"""""""" 11274 11275.. code-block:: llvm 11276 11277 Loop: ; Infinite loop that counts from 0 on up... 11278 %indvar = phi i32 [ 0, %LoopHeader ], [ %nextindvar, %Loop ] 11279 %nextindvar = add i32 %indvar, 1 11280 br label %Loop 11281 11282.. _i_select: 11283 11284'``select``' Instruction 11285^^^^^^^^^^^^^^^^^^^^^^^^ 11286 11287Syntax: 11288""""""" 11289 11290:: 11291 11292 <result> = select [fast-math flags] selty <cond>, <ty> <val1>, <ty> <val2> ; yields ty 11293 11294 selty is either i1 or {<N x i1>} 11295 11296Overview: 11297""""""""" 11298 11299The '``select``' instruction is used to choose one value based on a 11300condition, without IR-level branching. 11301 11302Arguments: 11303"""""""""" 11304 11305The '``select``' instruction requires an 'i1' value or a vector of 'i1' 11306values indicating the condition, and two values of the same :ref:`first 11307class <t_firstclass>` type. 11308 11309#. The optional ``fast-math flags`` marker indicates that the select has one or more 11310 :ref:`fast-math flags <fastmath>`. These are optimization hints to enable 11311 otherwise unsafe floating-point optimizations. Fast-math flags are only valid 11312 for selects that return a floating-point scalar or vector type, or an array 11313 (nested to any depth) of floating-point scalar or vector types. 11314 11315Semantics: 11316"""""""""" 11317 11318If the condition is an i1 and it evaluates to 1, the instruction returns 11319the first value argument; otherwise, it returns the second value 11320argument. 11321 11322If the condition is a vector of i1, then the value arguments must be 11323vectors of the same size, and the selection is done element by element. 11324 11325If the condition is an i1 and the value arguments are vectors of the 11326same size, then an entire vector is selected. 11327 11328Example: 11329"""""""" 11330 11331.. code-block:: llvm 11332 11333 %X = select i1 true, i8 17, i8 42 ; yields i8:17 11334 11335 11336.. _i_freeze: 11337 11338'``freeze``' Instruction 11339^^^^^^^^^^^^^^^^^^^^^^^^ 11340 11341Syntax: 11342""""""" 11343 11344:: 11345 11346 <result> = freeze ty <val> ; yields ty:result 11347 11348Overview: 11349""""""""" 11350 11351The '``freeze``' instruction is used to stop propagation of 11352:ref:`undef <undefvalues>` and :ref:`poison <poisonvalues>` values. 11353 11354Arguments: 11355"""""""""" 11356 11357The '``freeze``' instruction takes a single argument. 11358 11359Semantics: 11360"""""""""" 11361 11362If the argument is ``undef`` or ``poison``, '``freeze``' returns an 11363arbitrary, but fixed, value of type '``ty``'. 11364Otherwise, this instruction is a no-op and returns the input argument. 11365All uses of a value returned by the same '``freeze``' instruction are 11366guaranteed to always observe the same value, while different '``freeze``' 11367instructions may yield different values. 11368 11369While ``undef`` and ``poison`` pointers can be frozen, the result is a 11370non-dereferenceable pointer. See the 11371:ref:`Pointer Aliasing Rules <pointeraliasing>` section for more information. 11372If an aggregate value or vector is frozen, the operand is frozen element-wise. 11373The padding of an aggregate isn't considered, since it isn't visible 11374without storing it into memory and loading it with a different type. 11375 11376 11377Example: 11378"""""""" 11379 11380.. code-block:: text 11381 11382 %w = i32 undef 11383 %x = freeze i32 %w 11384 %y = add i32 %w, %w ; undef 11385 %z = add i32 %x, %x ; even number because all uses of %x observe 11386 ; the same value 11387 %x2 = freeze i32 %w 11388 %cmp = icmp eq i32 %x, %x2 ; can be true or false 11389 11390 ; example with vectors 11391 %v = <2 x i32> <i32 undef, i32 poison> 11392 %a = extractelement <2 x i32> %v, i32 0 ; undef 11393 %b = extractelement <2 x i32> %v, i32 1 ; poison 11394 %add = add i32 %a, %a ; undef 11395 11396 %v.fr = freeze <2 x i32> %v ; element-wise freeze 11397 %d = extractelement <2 x i32> %v.fr, i32 0 ; not undef 11398 %add.f = add i32 %d, %d ; even number 11399 11400 ; branching on frozen value 11401 %poison = add nsw i1 %k, undef ; poison 11402 %c = freeze i1 %poison 11403 br i1 %c, label %foo, label %bar ; non-deterministic branch to %foo or %bar 11404 11405 11406.. _i_call: 11407 11408'``call``' Instruction 11409^^^^^^^^^^^^^^^^^^^^^^ 11410 11411Syntax: 11412""""""" 11413 11414:: 11415 11416 <result> = [tail | musttail | notail ] call [fast-math flags] [cconv] [ret attrs] [addrspace(<num>)] 11417 <ty>|<fnty> <fnptrval>(<function args>) [fn attrs] [ operand bundles ] 11418 11419Overview: 11420""""""""" 11421 11422The '``call``' instruction represents a simple function call. 11423 11424Arguments: 11425"""""""""" 11426 11427This instruction requires several arguments: 11428 11429#. The optional ``tail`` and ``musttail`` markers indicate that the optimizers 11430 should perform tail call optimization. The ``tail`` marker is a hint that 11431 `can be ignored <CodeGenerator.html#sibcallopt>`_. The ``musttail`` marker 11432 means that the call must be tail call optimized in order for the program to 11433 be correct. The ``musttail`` marker provides these guarantees: 11434 11435 #. The call will not cause unbounded stack growth if it is part of a 11436 recursive cycle in the call graph. 11437 #. Arguments with the :ref:`inalloca <attr_inalloca>` or 11438 :ref:`preallocated <attr_preallocated>` attribute are forwarded in place. 11439 #. If the musttail call appears in a function with the ``"thunk"`` attribute 11440 and the caller and callee both have varargs, than any unprototyped 11441 arguments in register or memory are forwarded to the callee. Similarly, 11442 the return value of the callee is returned to the caller's caller, even 11443 if a void return type is in use. 11444 11445 Both markers imply that the callee does not access allocas from the caller. 11446 The ``tail`` marker additionally implies that the callee does not access 11447 varargs from the caller. Calls marked ``musttail`` must obey the following 11448 additional rules: 11449 11450 - The call must immediately precede a :ref:`ret <i_ret>` instruction, 11451 or a pointer bitcast followed by a ret instruction. 11452 - The ret instruction must return the (possibly bitcasted) value 11453 produced by the call, undef, or void. 11454 - The calling conventions of the caller and callee must match. 11455 - The callee must be varargs iff the caller is varargs. Bitcasting a 11456 non-varargs function to the appropriate varargs type is legal so 11457 long as the non-varargs prefixes obey the other rules. 11458 - The return type must not undergo automatic conversion to an `sret` pointer. 11459 11460 In addition, if the calling convention is not `swifttailcc` or `tailcc`: 11461 11462 - All ABI-impacting function attributes, such as sret, byval, inreg, 11463 returned, and inalloca, must match. 11464 - The caller and callee prototypes must match. Pointer types of parameters 11465 or return types may differ in pointee type, but not in address space. 11466 11467 On the other hand, if the calling convention is `swifttailcc` or `swiftcc`: 11468 11469 - Only these ABI-impacting attributes attributes are allowed: sret, byval, 11470 swiftself, and swiftasync. 11471 - Prototypes are not required to match. 11472 11473 Tail call optimization for calls marked ``tail`` is guaranteed to occur if 11474 the following conditions are met: 11475 11476 - Caller and callee both have the calling convention ``fastcc`` or ``tailcc``. 11477 - The call is in tail position (ret immediately follows call and ret 11478 uses value of call or is void). 11479 - Option ``-tailcallopt`` is enabled, 11480 ``llvm::GuaranteedTailCallOpt`` is ``true``, or the calling convention 11481 is ``tailcc`` 11482 - `Platform-specific constraints are 11483 met. <CodeGenerator.html#tailcallopt>`_ 11484 11485#. The optional ``notail`` marker indicates that the optimizers should not add 11486 ``tail`` or ``musttail`` markers to the call. It is used to prevent tail 11487 call optimization from being performed on the call. 11488 11489#. The optional ``fast-math flags`` marker indicates that the call has one or more 11490 :ref:`fast-math flags <fastmath>`, which are optimization hints to enable 11491 otherwise unsafe floating-point optimizations. Fast-math flags are only valid 11492 for calls that return a floating-point scalar or vector type, or an array 11493 (nested to any depth) of floating-point scalar or vector types. 11494 11495#. The optional "cconv" marker indicates which :ref:`calling 11496 convention <callingconv>` the call should use. If none is 11497 specified, the call defaults to using C calling conventions. The 11498 calling convention of the call must match the calling convention of 11499 the target function, or else the behavior is undefined. 11500#. The optional :ref:`Parameter Attributes <paramattrs>` list for return 11501 values. Only '``zeroext``', '``signext``', and '``inreg``' attributes 11502 are valid here. 11503#. The optional addrspace attribute can be used to indicate the address space 11504 of the called function. If it is not specified, the program address space 11505 from the :ref:`datalayout string<langref_datalayout>` will be used. 11506#. '``ty``': the type of the call instruction itself which is also the 11507 type of the return value. Functions that return no value are marked 11508 ``void``. 11509#. '``fnty``': shall be the signature of the function being called. The 11510 argument types must match the types implied by this signature. This 11511 type can be omitted if the function is not varargs. 11512#. '``fnptrval``': An LLVM value containing a pointer to a function to 11513 be called. In most cases, this is a direct function call, but 11514 indirect ``call``'s are just as possible, calling an arbitrary pointer 11515 to function value. 11516#. '``function args``': argument list whose types match the function 11517 signature argument types and parameter attributes. All arguments must 11518 be of :ref:`first class <t_firstclass>` type. If the function signature 11519 indicates the function accepts a variable number of arguments, the 11520 extra arguments can be specified. 11521#. The optional :ref:`function attributes <fnattrs>` list. 11522#. The optional :ref:`operand bundles <opbundles>` list. 11523 11524Semantics: 11525"""""""""" 11526 11527The '``call``' instruction is used to cause control flow to transfer to 11528a specified function, with its incoming arguments bound to the specified 11529values. Upon a '``ret``' instruction in the called function, control 11530flow continues with the instruction after the function call, and the 11531return value of the function is bound to the result argument. 11532 11533Example: 11534"""""""" 11535 11536.. code-block:: llvm 11537 11538 %retval = call i32 @test(i32 %argc) 11539 call i32 (i8*, ...)* @printf(i8* %msg, i32 12, i8 42) ; yields i32 11540 %X = tail call i32 @foo() ; yields i32 11541 %Y = tail call fastcc i32 @foo() ; yields i32 11542 call void %foo(i8 97 signext) 11543 11544 %struct.A = type { i32, i8 } 11545 %r = call %struct.A @foo() ; yields { i32, i8 } 11546 %gr = extractvalue %struct.A %r, 0 ; yields i32 11547 %gr1 = extractvalue %struct.A %r, 1 ; yields i8 11548 %Z = call void @foo() noreturn ; indicates that %foo never returns normally 11549 %ZZ = call zeroext i32 @bar() ; Return value is %zero extended 11550 11551llvm treats calls to some functions with names and arguments that match 11552the standard C99 library as being the C99 library functions, and may 11553perform optimizations or generate code for them under that assumption. 11554This is something we'd like to change in the future to provide better 11555support for freestanding environments and non-C-based languages. 11556 11557.. _i_va_arg: 11558 11559'``va_arg``' Instruction 11560^^^^^^^^^^^^^^^^^^^^^^^^ 11561 11562Syntax: 11563""""""" 11564 11565:: 11566 11567 <resultval> = va_arg <va_list*> <arglist>, <argty> 11568 11569Overview: 11570""""""""" 11571 11572The '``va_arg``' instruction is used to access arguments passed through 11573the "variable argument" area of a function call. It is used to implement 11574the ``va_arg`` macro in C. 11575 11576Arguments: 11577"""""""""" 11578 11579This instruction takes a ``va_list*`` value and the type of the 11580argument. It returns a value of the specified argument type and 11581increments the ``va_list`` to point to the next argument. The actual 11582type of ``va_list`` is target specific. 11583 11584Semantics: 11585"""""""""" 11586 11587The '``va_arg``' instruction loads an argument of the specified type 11588from the specified ``va_list`` and causes the ``va_list`` to point to 11589the next argument. For more information, see the variable argument 11590handling :ref:`Intrinsic Functions <int_varargs>`. 11591 11592It is legal for this instruction to be called in a function which does 11593not take a variable number of arguments, for example, the ``vfprintf`` 11594function. 11595 11596``va_arg`` is an LLVM instruction instead of an :ref:`intrinsic 11597function <intrinsics>` because it takes a type as an argument. 11598 11599Example: 11600"""""""" 11601 11602See the :ref:`variable argument processing <int_varargs>` section. 11603 11604Note that the code generator does not yet fully support va\_arg on many 11605targets. Also, it does not currently support va\_arg with aggregate 11606types on any target. 11607 11608.. _i_landingpad: 11609 11610'``landingpad``' Instruction 11611^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11612 11613Syntax: 11614""""""" 11615 11616:: 11617 11618 <resultval> = landingpad <resultty> <clause>+ 11619 <resultval> = landingpad <resultty> cleanup <clause>* 11620 11621 <clause> := catch <type> <value> 11622 <clause> := filter <array constant type> <array constant> 11623 11624Overview: 11625""""""""" 11626 11627The '``landingpad``' instruction is used by `LLVM's exception handling 11628system <ExceptionHandling.html#overview>`_ to specify that a basic block 11629is a landing pad --- one where the exception lands, and corresponds to the 11630code found in the ``catch`` portion of a ``try``/``catch`` sequence. It 11631defines values supplied by the :ref:`personality function <personalityfn>` upon 11632re-entry to the function. The ``resultval`` has the type ``resultty``. 11633 11634Arguments: 11635"""""""""" 11636 11637The optional 11638``cleanup`` flag indicates that the landing pad block is a cleanup. 11639 11640A ``clause`` begins with the clause type --- ``catch`` or ``filter`` --- and 11641contains the global variable representing the "type" that may be caught 11642or filtered respectively. Unlike the ``catch`` clause, the ``filter`` 11643clause takes an array constant as its argument. Use 11644"``[0 x i8**] undef``" for a filter which cannot throw. The 11645'``landingpad``' instruction must contain *at least* one ``clause`` or 11646the ``cleanup`` flag. 11647 11648Semantics: 11649"""""""""" 11650 11651The '``landingpad``' instruction defines the values which are set by the 11652:ref:`personality function <personalityfn>` upon re-entry to the function, and 11653therefore the "result type" of the ``landingpad`` instruction. As with 11654calling conventions, how the personality function results are 11655represented in LLVM IR is target specific. 11656 11657The clauses are applied in order from top to bottom. If two 11658``landingpad`` instructions are merged together through inlining, the 11659clauses from the calling function are appended to the list of clauses. 11660When the call stack is being unwound due to an exception being thrown, 11661the exception is compared against each ``clause`` in turn. If it doesn't 11662match any of the clauses, and the ``cleanup`` flag is not set, then 11663unwinding continues further up the call stack. 11664 11665The ``landingpad`` instruction has several restrictions: 11666 11667- A landing pad block is a basic block which is the unwind destination 11668 of an '``invoke``' instruction. 11669- A landing pad block must have a '``landingpad``' instruction as its 11670 first non-PHI instruction. 11671- There can be only one '``landingpad``' instruction within the landing 11672 pad block. 11673- A basic block that is not a landing pad block may not include a 11674 '``landingpad``' instruction. 11675 11676Example: 11677"""""""" 11678 11679.. code-block:: llvm 11680 11681 ;; A landing pad which can catch an integer. 11682 %res = landingpad { i8*, i32 } 11683 catch i8** @_ZTIi 11684 ;; A landing pad that is a cleanup. 11685 %res = landingpad { i8*, i32 } 11686 cleanup 11687 ;; A landing pad which can catch an integer and can only throw a double. 11688 %res = landingpad { i8*, i32 } 11689 catch i8** @_ZTIi 11690 filter [1 x i8**] [@_ZTId] 11691 11692.. _i_catchpad: 11693 11694'``catchpad``' Instruction 11695^^^^^^^^^^^^^^^^^^^^^^^^^^ 11696 11697Syntax: 11698""""""" 11699 11700:: 11701 11702 <resultval> = catchpad within <catchswitch> [<args>*] 11703 11704Overview: 11705""""""""" 11706 11707The '``catchpad``' instruction is used by `LLVM's exception handling 11708system <ExceptionHandling.html#overview>`_ to specify that a basic block 11709begins a catch handler --- one where a personality routine attempts to transfer 11710control to catch an exception. 11711 11712Arguments: 11713"""""""""" 11714 11715The ``catchswitch`` operand must always be a token produced by a 11716:ref:`catchswitch <i_catchswitch>` instruction in a predecessor block. This 11717ensures that each ``catchpad`` has exactly one predecessor block, and it always 11718terminates in a ``catchswitch``. 11719 11720The ``args`` correspond to whatever information the personality routine 11721requires to know if this is an appropriate handler for the exception. Control 11722will transfer to the ``catchpad`` if this is the first appropriate handler for 11723the exception. 11724 11725The ``resultval`` has the type :ref:`token <t_token>` and is used to match the 11726``catchpad`` to corresponding :ref:`catchrets <i_catchret>` and other nested EH 11727pads. 11728 11729Semantics: 11730"""""""""" 11731 11732When the call stack is being unwound due to an exception being thrown, the 11733exception is compared against the ``args``. If it doesn't match, control will 11734not reach the ``catchpad`` instruction. The representation of ``args`` is 11735entirely target and personality function-specific. 11736 11737Like the :ref:`landingpad <i_landingpad>` instruction, the ``catchpad`` 11738instruction must be the first non-phi of its parent basic block. 11739 11740The meaning of the tokens produced and consumed by ``catchpad`` and other "pad" 11741instructions is described in the 11742`Windows exception handling documentation\ <ExceptionHandling.html#wineh>`_. 11743 11744When a ``catchpad`` has been "entered" but not yet "exited" (as 11745described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_), 11746it is undefined behavior to execute a :ref:`call <i_call>` or :ref:`invoke <i_invoke>` 11747that does not carry an appropriate :ref:`"funclet" bundle <ob_funclet>`. 11748 11749Example: 11750"""""""" 11751 11752.. code-block:: text 11753 11754 dispatch: 11755 %cs = catchswitch within none [label %handler0] unwind to caller 11756 ;; A catch block which can catch an integer. 11757 handler0: 11758 %tok = catchpad within %cs [i8** @_ZTIi] 11759 11760.. _i_cleanuppad: 11761 11762'``cleanuppad``' Instruction 11763^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11764 11765Syntax: 11766""""""" 11767 11768:: 11769 11770 <resultval> = cleanuppad within <parent> [<args>*] 11771 11772Overview: 11773""""""""" 11774 11775The '``cleanuppad``' instruction is used by `LLVM's exception handling 11776system <ExceptionHandling.html#overview>`_ to specify that a basic block 11777is a cleanup block --- one where a personality routine attempts to 11778transfer control to run cleanup actions. 11779The ``args`` correspond to whatever additional 11780information the :ref:`personality function <personalityfn>` requires to 11781execute the cleanup. 11782The ``resultval`` has the type :ref:`token <t_token>` and is used to 11783match the ``cleanuppad`` to corresponding :ref:`cleanuprets <i_cleanupret>`. 11784The ``parent`` argument is the token of the funclet that contains the 11785``cleanuppad`` instruction. If the ``cleanuppad`` is not inside a funclet, 11786this operand may be the token ``none``. 11787 11788Arguments: 11789"""""""""" 11790 11791The instruction takes a list of arbitrary values which are interpreted 11792by the :ref:`personality function <personalityfn>`. 11793 11794Semantics: 11795"""""""""" 11796 11797When the call stack is being unwound due to an exception being thrown, 11798the :ref:`personality function <personalityfn>` transfers control to the 11799``cleanuppad`` with the aid of the personality-specific arguments. 11800As with calling conventions, how the personality function results are 11801represented in LLVM IR is target specific. 11802 11803The ``cleanuppad`` instruction has several restrictions: 11804 11805- A cleanup block is a basic block which is the unwind destination of 11806 an exceptional instruction. 11807- A cleanup block must have a '``cleanuppad``' instruction as its 11808 first non-PHI instruction. 11809- There can be only one '``cleanuppad``' instruction within the 11810 cleanup block. 11811- A basic block that is not a cleanup block may not include a 11812 '``cleanuppad``' instruction. 11813 11814When a ``cleanuppad`` has been "entered" but not yet "exited" (as 11815described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_), 11816it is undefined behavior to execute a :ref:`call <i_call>` or :ref:`invoke <i_invoke>` 11817that does not carry an appropriate :ref:`"funclet" bundle <ob_funclet>`. 11818 11819Example: 11820"""""""" 11821 11822.. code-block:: text 11823 11824 %tok = cleanuppad within %cs [] 11825 11826.. _intrinsics: 11827 11828Intrinsic Functions 11829=================== 11830 11831LLVM supports the notion of an "intrinsic function". These functions 11832have well known names and semantics and are required to follow certain 11833restrictions. Overall, these intrinsics represent an extension mechanism 11834for the LLVM language that does not require changing all of the 11835transformations in LLVM when adding to the language (or the bitcode 11836reader/writer, the parser, etc...). 11837 11838Intrinsic function names must all start with an "``llvm.``" prefix. This 11839prefix is reserved in LLVM for intrinsic names; thus, function names may 11840not begin with this prefix. Intrinsic functions must always be external 11841functions: you cannot define the body of intrinsic functions. Intrinsic 11842functions may only be used in call or invoke instructions: it is illegal 11843to take the address of an intrinsic function. Additionally, because 11844intrinsic functions are part of the LLVM language, it is required if any 11845are added that they be documented here. 11846 11847Some intrinsic functions can be overloaded, i.e., the intrinsic 11848represents a family of functions that perform the same operation but on 11849different data types. Because LLVM can represent over 8 million 11850different integer types, overloading is used commonly to allow an 11851intrinsic function to operate on any integer type. One or more of the 11852argument types or the result type can be overloaded to accept any 11853integer type. Argument types may also be defined as exactly matching a 11854previous argument's type or the result type. This allows an intrinsic 11855function which accepts multiple arguments, but needs all of them to be 11856of the same type, to only be overloaded with respect to a single 11857argument or the result. 11858 11859Overloaded intrinsics will have the names of its overloaded argument 11860types encoded into its function name, each preceded by a period. Only 11861those types which are overloaded result in a name suffix. Arguments 11862whose type is matched against another type do not. For example, the 11863``llvm.ctpop`` function can take an integer of any width and returns an 11864integer of exactly the same integer width. This leads to a family of 11865functions such as ``i8 @llvm.ctpop.i8(i8 %val)`` and 11866``i29 @llvm.ctpop.i29(i29 %val)``. Only one type, the return type, is 11867overloaded, and only one type suffix is required. Because the argument's 11868type is matched against the return type, it does not require its own 11869name suffix. 11870 11871:ref:`Unnamed types <t_opaque>` are encoded as ``s_s``. Overloaded intrinsics 11872that depend on an unnamed type in one of its overloaded argument types get an 11873additional ``.<number>`` suffix. This allows differentiating intrinsics with 11874different unnamed types as arguments. (For example: 11875``llvm.ssa.copy.p0s_s.2(%42*)``) The number is tracked in the LLVM module and 11876it ensures unique names in the module. While linking together two modules, it is 11877still possible to get a name clash. In that case one of the names will be 11878changed by getting a new number. 11879 11880For target developers who are defining intrinsics for back-end code 11881generation, any intrinsic overloads based solely the distinction between 11882integer or floating point types should not be relied upon for correct 11883code generation. In such cases, the recommended approach for target 11884maintainers when defining intrinsics is to create separate integer and 11885FP intrinsics rather than rely on overloading. For example, if different 11886codegen is required for ``llvm.target.foo(<4 x i32>)`` and 11887``llvm.target.foo(<4 x float>)`` then these should be split into 11888different intrinsics. 11889 11890To learn how to add an intrinsic function, please see the `Extending 11891LLVM Guide <ExtendingLLVM.html>`_. 11892 11893.. _int_varargs: 11894 11895Variable Argument Handling Intrinsics 11896------------------------------------- 11897 11898Variable argument support is defined in LLVM with the 11899:ref:`va_arg <i_va_arg>` instruction and these three intrinsic 11900functions. These functions are related to the similarly named macros 11901defined in the ``<stdarg.h>`` header file. 11902 11903All of these functions operate on arguments that use a target-specific 11904value type "``va_list``". The LLVM assembly language reference manual 11905does not define what this type is, so all transformations should be 11906prepared to handle these functions regardless of the type used. 11907 11908This example shows how the :ref:`va_arg <i_va_arg>` instruction and the 11909variable argument handling intrinsic functions are used. 11910 11911.. code-block:: llvm 11912 11913 ; This struct is different for every platform. For most platforms, 11914 ; it is merely an i8*. 11915 %struct.va_list = type { i8* } 11916 11917 ; For Unix x86_64 platforms, va_list is the following struct: 11918 ; %struct.va_list = type { i32, i32, i8*, i8* } 11919 11920 define i32 @test(i32 %X, ...) { 11921 ; Initialize variable argument processing 11922 %ap = alloca %struct.va_list 11923 %ap2 = bitcast %struct.va_list* %ap to i8* 11924 call void @llvm.va_start(i8* %ap2) 11925 11926 ; Read a single integer argument 11927 %tmp = va_arg i8* %ap2, i32 11928 11929 ; Demonstrate usage of llvm.va_copy and llvm.va_end 11930 %aq = alloca i8* 11931 %aq2 = bitcast i8** %aq to i8* 11932 call void @llvm.va_copy(i8* %aq2, i8* %ap2) 11933 call void @llvm.va_end(i8* %aq2) 11934 11935 ; Stop processing of arguments. 11936 call void @llvm.va_end(i8* %ap2) 11937 ret i32 %tmp 11938 } 11939 11940 declare void @llvm.va_start(i8*) 11941 declare void @llvm.va_copy(i8*, i8*) 11942 declare void @llvm.va_end(i8*) 11943 11944.. _int_va_start: 11945 11946'``llvm.va_start``' Intrinsic 11947^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11948 11949Syntax: 11950""""""" 11951 11952:: 11953 11954 declare void @llvm.va_start(i8* <arglist>) 11955 11956Overview: 11957""""""""" 11958 11959The '``llvm.va_start``' intrinsic initializes ``*<arglist>`` for 11960subsequent use by ``va_arg``. 11961 11962Arguments: 11963"""""""""" 11964 11965The argument is a pointer to a ``va_list`` element to initialize. 11966 11967Semantics: 11968"""""""""" 11969 11970The '``llvm.va_start``' intrinsic works just like the ``va_start`` macro 11971available in C. In a target-dependent way, it initializes the 11972``va_list`` element to which the argument points, so that the next call 11973to ``va_arg`` will produce the first variable argument passed to the 11974function. Unlike the C ``va_start`` macro, this intrinsic does not need 11975to know the last argument of the function as the compiler can figure 11976that out. 11977 11978'``llvm.va_end``' Intrinsic 11979^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11980 11981Syntax: 11982""""""" 11983 11984:: 11985 11986 declare void @llvm.va_end(i8* <arglist>) 11987 11988Overview: 11989""""""""" 11990 11991The '``llvm.va_end``' intrinsic destroys ``*<arglist>``, which has been 11992initialized previously with ``llvm.va_start`` or ``llvm.va_copy``. 11993 11994Arguments: 11995"""""""""" 11996 11997The argument is a pointer to a ``va_list`` to destroy. 11998 11999Semantics: 12000"""""""""" 12001 12002The '``llvm.va_end``' intrinsic works just like the ``va_end`` macro 12003available in C. In a target-dependent way, it destroys the ``va_list`` 12004element to which the argument points. Calls to 12005:ref:`llvm.va_start <int_va_start>` and 12006:ref:`llvm.va_copy <int_va_copy>` must be matched exactly with calls to 12007``llvm.va_end``. 12008 12009.. _int_va_copy: 12010 12011'``llvm.va_copy``' Intrinsic 12012^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12013 12014Syntax: 12015""""""" 12016 12017:: 12018 12019 declare void @llvm.va_copy(i8* <destarglist>, i8* <srcarglist>) 12020 12021Overview: 12022""""""""" 12023 12024The '``llvm.va_copy``' intrinsic copies the current argument position 12025from the source argument list to the destination argument list. 12026 12027Arguments: 12028"""""""""" 12029 12030The first argument is a pointer to a ``va_list`` element to initialize. 12031The second argument is a pointer to a ``va_list`` element to copy from. 12032 12033Semantics: 12034"""""""""" 12035 12036The '``llvm.va_copy``' intrinsic works just like the ``va_copy`` macro 12037available in C. In a target-dependent way, it copies the source 12038``va_list`` element into the destination ``va_list`` element. This 12039intrinsic is necessary because the `` llvm.va_start`` intrinsic may be 12040arbitrarily complex and require, for example, memory allocation. 12041 12042Accurate Garbage Collection Intrinsics 12043-------------------------------------- 12044 12045LLVM's support for `Accurate Garbage Collection <GarbageCollection.html>`_ 12046(GC) requires the frontend to generate code containing appropriate intrinsic 12047calls and select an appropriate GC strategy which knows how to lower these 12048intrinsics in a manner which is appropriate for the target collector. 12049 12050These intrinsics allow identification of :ref:`GC roots on the 12051stack <int_gcroot>`, as well as garbage collector implementations that 12052require :ref:`read <int_gcread>` and :ref:`write <int_gcwrite>` barriers. 12053Frontends for type-safe garbage collected languages should generate 12054these intrinsics to make use of the LLVM garbage collectors. For more 12055details, see `Garbage Collection with LLVM <GarbageCollection.html>`_. 12056 12057LLVM provides an second experimental set of intrinsics for describing garbage 12058collection safepoints in compiled code. These intrinsics are an alternative 12059to the ``llvm.gcroot`` intrinsics, but are compatible with the ones for 12060:ref:`read <int_gcread>` and :ref:`write <int_gcwrite>` barriers. The 12061differences in approach are covered in the `Garbage Collection with LLVM 12062<GarbageCollection.html>`_ documentation. The intrinsics themselves are 12063described in :doc:`Statepoints`. 12064 12065.. _int_gcroot: 12066 12067'``llvm.gcroot``' Intrinsic 12068^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12069 12070Syntax: 12071""""""" 12072 12073:: 12074 12075 declare void @llvm.gcroot(i8** %ptrloc, i8* %metadata) 12076 12077Overview: 12078""""""""" 12079 12080The '``llvm.gcroot``' intrinsic declares the existence of a GC root to 12081the code generator, and allows some metadata to be associated with it. 12082 12083Arguments: 12084"""""""""" 12085 12086The first argument specifies the address of a stack object that contains 12087the root pointer. The second pointer (which must be either a constant or 12088a global value address) contains the meta-data to be associated with the 12089root. 12090 12091Semantics: 12092"""""""""" 12093 12094At runtime, a call to this intrinsic stores a null pointer into the 12095"ptrloc" location. At compile-time, the code generator generates 12096information to allow the runtime to find the pointer at GC safe points. 12097The '``llvm.gcroot``' intrinsic may only be used in a function which 12098:ref:`specifies a GC algorithm <gc>`. 12099 12100.. _int_gcread: 12101 12102'``llvm.gcread``' Intrinsic 12103^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12104 12105Syntax: 12106""""""" 12107 12108:: 12109 12110 declare i8* @llvm.gcread(i8* %ObjPtr, i8** %Ptr) 12111 12112Overview: 12113""""""""" 12114 12115The '``llvm.gcread``' intrinsic identifies reads of references from heap 12116locations, allowing garbage collector implementations that require read 12117barriers. 12118 12119Arguments: 12120"""""""""" 12121 12122The second argument is the address to read from, which should be an 12123address allocated from the garbage collector. The first object is a 12124pointer to the start of the referenced object, if needed by the language 12125runtime (otherwise null). 12126 12127Semantics: 12128"""""""""" 12129 12130The '``llvm.gcread``' intrinsic has the same semantics as a load 12131instruction, but may be replaced with substantially more complex code by 12132the garbage collector runtime, as needed. The '``llvm.gcread``' 12133intrinsic may only be used in a function which :ref:`specifies a GC 12134algorithm <gc>`. 12135 12136.. _int_gcwrite: 12137 12138'``llvm.gcwrite``' Intrinsic 12139^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12140 12141Syntax: 12142""""""" 12143 12144:: 12145 12146 declare void @llvm.gcwrite(i8* %P1, i8* %Obj, i8** %P2) 12147 12148Overview: 12149""""""""" 12150 12151The '``llvm.gcwrite``' intrinsic identifies writes of references to heap 12152locations, allowing garbage collector implementations that require write 12153barriers (such as generational or reference counting collectors). 12154 12155Arguments: 12156"""""""""" 12157 12158The first argument is the reference to store, the second is the start of 12159the object to store it to, and the third is the address of the field of 12160Obj to store to. If the runtime does not require a pointer to the 12161object, Obj may be null. 12162 12163Semantics: 12164"""""""""" 12165 12166The '``llvm.gcwrite``' intrinsic has the same semantics as a store 12167instruction, but may be replaced with substantially more complex code by 12168the garbage collector runtime, as needed. The '``llvm.gcwrite``' 12169intrinsic may only be used in a function which :ref:`specifies a GC 12170algorithm <gc>`. 12171 12172 12173.. _gc_statepoint: 12174 12175'llvm.experimental.gc.statepoint' Intrinsic 12176^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12177 12178Syntax: 12179""""""" 12180 12181:: 12182 12183 declare token 12184 @llvm.experimental.gc.statepoint(i64 <id>, i32 <num patch bytes>, 12185 func_type <target>, 12186 i64 <#call args>, i64 <flags>, 12187 ... (call parameters), 12188 i64 0, i64 0) 12189 12190Overview: 12191""""""""" 12192 12193The statepoint intrinsic represents a call which is parse-able by the 12194runtime. 12195 12196Operands: 12197""""""""" 12198 12199The 'id' operand is a constant integer that is reported as the ID 12200field in the generated stackmap. LLVM does not interpret this 12201parameter in any way and its meaning is up to the statepoint user to 12202decide. Note that LLVM is free to duplicate code containing 12203statepoint calls, and this may transform IR that had a unique 'id' per 12204lexical call to statepoint to IR that does not. 12205 12206If 'num patch bytes' is non-zero then the call instruction 12207corresponding to the statepoint is not emitted and LLVM emits 'num 12208patch bytes' bytes of nops in its place. LLVM will emit code to 12209prepare the function arguments and retrieve the function return value 12210in accordance to the calling convention; the former before the nop 12211sequence and the latter after the nop sequence. It is expected that 12212the user will patch over the 'num patch bytes' bytes of nops with a 12213calling sequence specific to their runtime before executing the 12214generated machine code. There are no guarantees with respect to the 12215alignment of the nop sequence. Unlike :doc:`StackMaps` statepoints do 12216not have a concept of shadow bytes. Note that semantically the 12217statepoint still represents a call or invoke to 'target', and the nop 12218sequence after patching is expected to represent an operation 12219equivalent to a call or invoke to 'target'. 12220 12221The 'target' operand is the function actually being called. The 12222target can be specified as either a symbolic LLVM function, or as an 12223arbitrary Value of appropriate function type. Note that the function 12224type must match the signature of the callee and the types of the 'call 12225parameters' arguments. 12226 12227The '#call args' operand is the number of arguments to the actual 12228call. It must exactly match the number of arguments passed in the 12229'call parameters' variable length section. 12230 12231The 'flags' operand is used to specify extra information about the 12232statepoint. This is currently only used to mark certain statepoints 12233as GC transitions. This operand is a 64-bit integer with the following 12234layout, where bit 0 is the least significant bit: 12235 12236 +-------+---------------------------------------------------+ 12237 | Bit # | Usage | 12238 +=======+===================================================+ 12239 | 0 | Set if the statepoint is a GC transition, cleared | 12240 | | otherwise. | 12241 +-------+---------------------------------------------------+ 12242 | 1-63 | Reserved for future use; must be cleared. | 12243 +-------+---------------------------------------------------+ 12244 12245The 'call parameters' arguments are simply the arguments which need to 12246be passed to the call target. They will be lowered according to the 12247specified calling convention and otherwise handled like a normal call 12248instruction. The number of arguments must exactly match what is 12249specified in '# call args'. The types must match the signature of 12250'target'. 12251 12252The 'call parameter' attributes must be followed by two 'i64 0' constants. 12253These were originally the length prefixes for 'gc transition parameter' and 12254'deopt parameter' arguments, but the role of these parameter sets have been 12255entirely replaced with the corresponding operand bundles. In a future 12256revision, these now redundant arguments will be removed. 12257 12258Semantics: 12259"""""""""" 12260 12261A statepoint is assumed to read and write all memory. As a result, 12262memory operations can not be reordered past a statepoint. It is 12263illegal to mark a statepoint as being either 'readonly' or 'readnone'. 12264 12265Note that legal IR can not perform any memory operation on a 'gc 12266pointer' argument of the statepoint in a location statically reachable 12267from the statepoint. Instead, the explicitly relocated value (from a 12268``gc.relocate``) must be used. 12269 12270'llvm.experimental.gc.result' Intrinsic 12271^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12272 12273Syntax: 12274""""""" 12275 12276:: 12277 12278 declare type* 12279 @llvm.experimental.gc.result(token %statepoint_token) 12280 12281Overview: 12282""""""""" 12283 12284``gc.result`` extracts the result of the original call instruction 12285which was replaced by the ``gc.statepoint``. The ``gc.result`` 12286intrinsic is actually a family of three intrinsics due to an 12287implementation limitation. Other than the type of the return value, 12288the semantics are the same. 12289 12290Operands: 12291""""""""" 12292 12293The first and only argument is the ``gc.statepoint`` which starts 12294the safepoint sequence of which this ``gc.result`` is a part. 12295Despite the typing of this as a generic token, *only* the value defined 12296by a ``gc.statepoint`` is legal here. 12297 12298Semantics: 12299"""""""""" 12300 12301The ``gc.result`` represents the return value of the call target of 12302the ``statepoint``. The type of the ``gc.result`` must exactly match 12303the type of the target. If the call target returns void, there will 12304be no ``gc.result``. 12305 12306A ``gc.result`` is modeled as a 'readnone' pure function. It has no 12307side effects since it is just a projection of the return value of the 12308previous call represented by the ``gc.statepoint``. 12309 12310'llvm.experimental.gc.relocate' Intrinsic 12311^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12312 12313Syntax: 12314""""""" 12315 12316:: 12317 12318 declare <pointer type> 12319 @llvm.experimental.gc.relocate(token %statepoint_token, 12320 i32 %base_offset, 12321 i32 %pointer_offset) 12322 12323Overview: 12324""""""""" 12325 12326A ``gc.relocate`` returns the potentially relocated value of a pointer 12327at the safepoint. 12328 12329Operands: 12330""""""""" 12331 12332The first argument is the ``gc.statepoint`` which starts the 12333safepoint sequence of which this ``gc.relocation`` is a part. 12334Despite the typing of this as a generic token, *only* the value defined 12335by a ``gc.statepoint`` is legal here. 12336 12337The second and third arguments are both indices into operands of the 12338corresponding statepoint's :ref:`gc-live <ob_gc_live>` operand bundle. 12339 12340The second argument is an index which specifies the allocation for the pointer 12341being relocated. The associated value must be within the object with which the 12342pointer being relocated is associated. The optimizer is free to change *which* 12343interior derived pointer is reported, provided that it does not replace an 12344actual base pointer with another interior derived pointer. Collectors are 12345allowed to rely on the base pointer operand remaining an actual base pointer if 12346so constructed. 12347 12348The third argument is an index which specify the (potentially) derived pointer 12349being relocated. It is legal for this index to be the same as the second 12350argument if-and-only-if a base pointer is being relocated. 12351 12352Semantics: 12353"""""""""" 12354 12355The return value of ``gc.relocate`` is the potentially relocated value 12356of the pointer specified by its arguments. It is unspecified how the 12357value of the returned pointer relates to the argument to the 12358``gc.statepoint`` other than that a) it points to the same source 12359language object with the same offset, and b) the 'based-on' 12360relationship of the newly relocated pointers is a projection of the 12361unrelocated pointers. In particular, the integer value of the pointer 12362returned is unspecified. 12363 12364A ``gc.relocate`` is modeled as a ``readnone`` pure function. It has no 12365side effects since it is just a way to extract information about work 12366done during the actual call modeled by the ``gc.statepoint``. 12367 12368.. _gc.get.pointer.base: 12369 12370'llvm.experimental.gc.get.pointer.base' Intrinsic 12371^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12372 12373Syntax: 12374""""""" 12375 12376:: 12377 12378 declare <pointer type> 12379 @llvm.experimental.gc.get.pointer.base( 12380 <pointer type> readnone nocapture %derived_ptr) 12381 nounwind readnone willreturn 12382 12383Overview: 12384""""""""" 12385 12386``gc.get.pointer.base`` for a derived pointer returns its base pointer. 12387 12388Operands: 12389""""""""" 12390 12391The only argument is a pointer which is based on some object with 12392an unknown offset from the base of said object. 12393 12394Semantics: 12395"""""""""" 12396 12397This intrinsic is used in the abstract machine model for GC to represent 12398the base pointer for an arbitrary derived pointer. 12399 12400This intrinsic is inlined by the :ref:`RewriteStatepointsForGC` pass by 12401replacing all uses of this callsite with the offset of a derived pointer from 12402its base pointer value. The replacement is done as part of the lowering to the 12403explicit statepoint model. 12404 12405The return pointer type must be the same as the type of the parameter. 12406 12407 12408'llvm.experimental.gc.get.pointer.offset' Intrinsic 12409^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12410 12411Syntax: 12412""""""" 12413 12414:: 12415 12416 declare i64 12417 @llvm.experimental.gc.get.pointer.offset( 12418 <pointer type> readnone nocapture %derived_ptr) 12419 nounwind readnone willreturn 12420 12421Overview: 12422""""""""" 12423 12424``gc.get.pointer.offset`` for a derived pointer returns the offset from its 12425base pointer. 12426 12427Operands: 12428""""""""" 12429 12430The only argument is a pointer which is based on some object with 12431an unknown offset from the base of said object. 12432 12433Semantics: 12434"""""""""" 12435 12436This intrinsic is used in the abstract machine model for GC to represent 12437the offset of an arbitrary derived pointer from its base pointer. 12438 12439This intrinsic is inlined by the :ref:`RewriteStatepointsForGC` pass by 12440replacing all uses of this callsite with the offset of a derived pointer from 12441its base pointer value. The replacement is done as part of the lowering to the 12442explicit statepoint model. 12443 12444Basically this call calculates difference between the derived pointer and its 12445base pointer (see :ref:`gc.get.pointer.base`) both ptrtoint casted. But 12446this cast done outside the :ref:`RewriteStatepointsForGC` pass could result 12447in the pointers lost for further lowering from the abstract model to the 12448explicit physical one. 12449 12450Code Generator Intrinsics 12451------------------------- 12452 12453These intrinsics are provided by LLVM to expose special features that 12454may only be implemented with code generator support. 12455 12456'``llvm.returnaddress``' Intrinsic 12457^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12458 12459Syntax: 12460""""""" 12461 12462:: 12463 12464 declare i8* @llvm.returnaddress(i32 <level>) 12465 12466Overview: 12467""""""""" 12468 12469The '``llvm.returnaddress``' intrinsic attempts to compute a 12470target-specific value indicating the return address of the current 12471function or one of its callers. 12472 12473Arguments: 12474"""""""""" 12475 12476The argument to this intrinsic indicates which function to return the 12477address for. Zero indicates the calling function, one indicates its 12478caller, etc. The argument is **required** to be a constant integer 12479value. 12480 12481Semantics: 12482"""""""""" 12483 12484The '``llvm.returnaddress``' intrinsic either returns a pointer 12485indicating the return address of the specified call frame, or zero if it 12486cannot be identified. The value returned by this intrinsic is likely to 12487be incorrect or 0 for arguments other than zero, so it should only be 12488used for debugging purposes. 12489 12490Note that calling this intrinsic does not prevent function inlining or 12491other aggressive transformations, so the value returned may not be that 12492of the obvious source-language caller. 12493 12494'``llvm.addressofreturnaddress``' Intrinsic 12495^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12496 12497Syntax: 12498""""""" 12499 12500:: 12501 12502 declare i8* @llvm.addressofreturnaddress() 12503 12504Overview: 12505""""""""" 12506 12507The '``llvm.addressofreturnaddress``' intrinsic returns a target-specific 12508pointer to the place in the stack frame where the return address of the 12509current function is stored. 12510 12511Semantics: 12512"""""""""" 12513 12514Note that calling this intrinsic does not prevent function inlining or 12515other aggressive transformations, so the value returned may not be that 12516of the obvious source-language caller. 12517 12518This intrinsic is only implemented for x86 and aarch64. 12519 12520'``llvm.sponentry``' Intrinsic 12521^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12522 12523Syntax: 12524""""""" 12525 12526:: 12527 12528 declare i8* @llvm.sponentry() 12529 12530Overview: 12531""""""""" 12532 12533The '``llvm.sponentry``' intrinsic returns the stack pointer value at 12534the entry of the current function calling this intrinsic. 12535 12536Semantics: 12537"""""""""" 12538 12539Note this intrinsic is only verified on AArch64. 12540 12541'``llvm.frameaddress``' Intrinsic 12542^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12543 12544Syntax: 12545""""""" 12546 12547:: 12548 12549 declare i8* @llvm.frameaddress(i32 <level>) 12550 12551Overview: 12552""""""""" 12553 12554The '``llvm.frameaddress``' intrinsic attempts to return the 12555target-specific frame pointer value for the specified stack frame. 12556 12557Arguments: 12558"""""""""" 12559 12560The argument to this intrinsic indicates which function to return the 12561frame pointer for. Zero indicates the calling function, one indicates 12562its caller, etc. The argument is **required** to be a constant integer 12563value. 12564 12565Semantics: 12566"""""""""" 12567 12568The '``llvm.frameaddress``' intrinsic either returns a pointer 12569indicating the frame address of the specified call frame, or zero if it 12570cannot be identified. The value returned by this intrinsic is likely to 12571be incorrect or 0 for arguments other than zero, so it should only be 12572used for debugging purposes. 12573 12574Note that calling this intrinsic does not prevent function inlining or 12575other aggressive transformations, so the value returned may not be that 12576of the obvious source-language caller. 12577 12578'``llvm.swift.async.context.addr``' Intrinsic 12579^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12580 12581Syntax: 12582""""""" 12583 12584:: 12585 12586 declare i8** @llvm.swift.async.context.addr() 12587 12588Overview: 12589""""""""" 12590 12591The '``llvm.swift.async.context.addr``' intrinsic returns a pointer to 12592the part of the extended frame record containing the asynchronous 12593context of a Swift execution. 12594 12595Semantics: 12596"""""""""" 12597 12598If the caller has a ``swiftasync`` parameter, that argument will initially 12599be stored at the returned address. If not, it will be initialized to null. 12600 12601'``llvm.localescape``' and '``llvm.localrecover``' Intrinsics 12602^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12603 12604Syntax: 12605""""""" 12606 12607:: 12608 12609 declare void @llvm.localescape(...) 12610 declare i8* @llvm.localrecover(i8* %func, i8* %fp, i32 %idx) 12611 12612Overview: 12613""""""""" 12614 12615The '``llvm.localescape``' intrinsic escapes offsets of a collection of static 12616allocas, and the '``llvm.localrecover``' intrinsic applies those offsets to a 12617live frame pointer to recover the address of the allocation. The offset is 12618computed during frame layout of the caller of ``llvm.localescape``. 12619 12620Arguments: 12621"""""""""" 12622 12623All arguments to '``llvm.localescape``' must be pointers to static allocas or 12624casts of static allocas. Each function can only call '``llvm.localescape``' 12625once, and it can only do so from the entry block. 12626 12627The ``func`` argument to '``llvm.localrecover``' must be a constant 12628bitcasted pointer to a function defined in the current module. The code 12629generator cannot determine the frame allocation offset of functions defined in 12630other modules. 12631 12632The ``fp`` argument to '``llvm.localrecover``' must be a frame pointer of a 12633call frame that is currently live. The return value of '``llvm.localaddress``' 12634is one way to produce such a value, but various runtimes also expose a suitable 12635pointer in platform-specific ways. 12636 12637The ``idx`` argument to '``llvm.localrecover``' indicates which alloca passed to 12638'``llvm.localescape``' to recover. It is zero-indexed. 12639 12640Semantics: 12641"""""""""" 12642 12643These intrinsics allow a group of functions to share access to a set of local 12644stack allocations of a one parent function. The parent function may call the 12645'``llvm.localescape``' intrinsic once from the function entry block, and the 12646child functions can use '``llvm.localrecover``' to access the escaped allocas. 12647The '``llvm.localescape``' intrinsic blocks inlining, as inlining changes where 12648the escaped allocas are allocated, which would break attempts to use 12649'``llvm.localrecover``'. 12650 12651'``llvm.seh.try.begin``' and '``llvm.seh.try.end``' Intrinsics 12652^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12653 12654Syntax: 12655""""""" 12656 12657:: 12658 12659 declare void @llvm.seh.try.begin() 12660 declare void @llvm.seh.try.end() 12661 12662Overview: 12663""""""""" 12664 12665The '``llvm.seh.try.begin``' and '``llvm.seh.try.end``' intrinsics mark 12666the boundary of a _try region for Windows SEH Asynchrous Exception Handling. 12667 12668Semantics: 12669"""""""""" 12670 12671When a C-function is compiled with Windows SEH Asynchrous Exception option, 12672-feh_asynch (aka MSVC -EHa), these two intrinsics are injected to mark _try 12673boundary and to prevent potential exceptions from being moved across boundary. 12674Any set of operations can then be confined to the region by reading their leaf 12675inputs via volatile loads and writing their root outputs via volatile stores. 12676 12677'``llvm.seh.scope.begin``' and '``llvm.seh.scope.end``' Intrinsics 12678^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12679 12680Syntax: 12681""""""" 12682 12683:: 12684 12685 declare void @llvm.seh.scope.begin() 12686 declare void @llvm.seh.scope.end() 12687 12688Overview: 12689""""""""" 12690 12691The '``llvm.seh.scope.begin``' and '``llvm.seh.scope.end``' intrinsics mark 12692the boundary of a CPP object lifetime for Windows SEH Asynchrous Exception 12693Handling (MSVC option -EHa). 12694 12695Semantics: 12696"""""""""" 12697 12698LLVM's ordinary exception-handling representation associates EH cleanups and 12699handlers only with ``invoke``s, which normally correspond only to call sites. To 12700support arbitrary faulting instructions, it must be possible to recover the current 12701EH scope for any instruction. Turning every operation in LLVM that could fault 12702into an ``invoke`` of a new, potentially-throwing intrinsic would require adding a 12703large number of intrinsics, impede optimization of those operations, and make 12704compilation slower by introducing many extra basic blocks. These intrinsics can 12705be used instead to mark the region protected by a cleanup, such as for a local 12706C++ object with a non-trivial destructor. ``llvm.seh.scope.begin`` is used to mark 12707the start of the region; it is always called with ``invoke``, with the unwind block 12708being the desired unwind destination for any potentially-throwing instructions 12709within the region. `llvm.seh.scope.end` is used to mark when the scope ends 12710and the EH cleanup is no longer required (e.g. because the destructor is being 12711called). 12712 12713.. _int_read_register: 12714.. _int_read_volatile_register: 12715.. _int_write_register: 12716 12717'``llvm.read_register``', '``llvm.read_volatile_register``', and '``llvm.write_register``' Intrinsics 12718^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12719 12720Syntax: 12721""""""" 12722 12723:: 12724 12725 declare i32 @llvm.read_register.i32(metadata) 12726 declare i64 @llvm.read_register.i64(metadata) 12727 declare i32 @llvm.read_volatile_register.i32(metadata) 12728 declare i64 @llvm.read_volatile_register.i64(metadata) 12729 declare void @llvm.write_register.i32(metadata, i32 @value) 12730 declare void @llvm.write_register.i64(metadata, i64 @value) 12731 !0 = !{!"sp\00"} 12732 12733Overview: 12734""""""""" 12735 12736The '``llvm.read_register``', '``llvm.read_volatile_register``', and 12737'``llvm.write_register``' intrinsics provide access to the named register. 12738The register must be valid on the architecture being compiled to. The type 12739needs to be compatible with the register being read. 12740 12741Semantics: 12742"""""""""" 12743 12744The '``llvm.read_register``' and '``llvm.read_volatile_register``' intrinsics 12745return the current value of the register, where possible. The 12746'``llvm.write_register``' intrinsic sets the current value of the register, 12747where possible. 12748 12749A call to '``llvm.read_volatile_register``' is assumed to have side-effects 12750and possibly return a different value each time (e.g. for a timer register). 12751 12752This is useful to implement named register global variables that need 12753to always be mapped to a specific register, as is common practice on 12754bare-metal programs including OS kernels. 12755 12756The compiler doesn't check for register availability or use of the used 12757register in surrounding code, including inline assembly. Because of that, 12758allocatable registers are not supported. 12759 12760Warning: So far it only works with the stack pointer on selected 12761architectures (ARM, AArch64, PowerPC and x86_64). Significant amount of 12762work is needed to support other registers and even more so, allocatable 12763registers. 12764 12765.. _int_stacksave: 12766 12767'``llvm.stacksave``' Intrinsic 12768^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12769 12770Syntax: 12771""""""" 12772 12773:: 12774 12775 declare i8* @llvm.stacksave() 12776 12777Overview: 12778""""""""" 12779 12780The '``llvm.stacksave``' intrinsic is used to remember the current state 12781of the function stack, for use with 12782:ref:`llvm.stackrestore <int_stackrestore>`. This is useful for 12783implementing language features like scoped automatic variable sized 12784arrays in C99. 12785 12786Semantics: 12787"""""""""" 12788 12789This intrinsic returns an opaque pointer value that can be passed to 12790:ref:`llvm.stackrestore <int_stackrestore>`. When an 12791``llvm.stackrestore`` intrinsic is executed with a value saved from 12792``llvm.stacksave``, it effectively restores the state of the stack to 12793the state it was in when the ``llvm.stacksave`` intrinsic executed. In 12794practice, this pops any :ref:`alloca <i_alloca>` blocks from the stack that 12795were allocated after the ``llvm.stacksave`` was executed. 12796 12797.. _int_stackrestore: 12798 12799'``llvm.stackrestore``' Intrinsic 12800^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12801 12802Syntax: 12803""""""" 12804 12805:: 12806 12807 declare void @llvm.stackrestore(i8* %ptr) 12808 12809Overview: 12810""""""""" 12811 12812The '``llvm.stackrestore``' intrinsic is used to restore the state of 12813the function stack to the state it was in when the corresponding 12814:ref:`llvm.stacksave <int_stacksave>` intrinsic executed. This is 12815useful for implementing language features like scoped automatic variable 12816sized arrays in C99. 12817 12818Semantics: 12819"""""""""" 12820 12821See the description for :ref:`llvm.stacksave <int_stacksave>`. 12822 12823.. _int_get_dynamic_area_offset: 12824 12825'``llvm.get.dynamic.area.offset``' Intrinsic 12826^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12827 12828Syntax: 12829""""""" 12830 12831:: 12832 12833 declare i32 @llvm.get.dynamic.area.offset.i32() 12834 declare i64 @llvm.get.dynamic.area.offset.i64() 12835 12836Overview: 12837""""""""" 12838 12839 The '``llvm.get.dynamic.area.offset.*``' intrinsic family is used to 12840 get the offset from native stack pointer to the address of the most 12841 recent dynamic alloca on the caller's stack. These intrinsics are 12842 intended for use in combination with 12843 :ref:`llvm.stacksave <int_stacksave>` to get a 12844 pointer to the most recent dynamic alloca. This is useful, for example, 12845 for AddressSanitizer's stack unpoisoning routines. 12846 12847Semantics: 12848"""""""""" 12849 12850 These intrinsics return a non-negative integer value that can be used to 12851 get the address of the most recent dynamic alloca, allocated by :ref:`alloca <i_alloca>` 12852 on the caller's stack. In particular, for targets where stack grows downwards, 12853 adding this offset to the native stack pointer would get the address of the most 12854 recent dynamic alloca. For targets where stack grows upwards, the situation is a bit more 12855 complicated, because subtracting this value from stack pointer would get the address 12856 one past the end of the most recent dynamic alloca. 12857 12858 Although for most targets `llvm.get.dynamic.area.offset <int_get_dynamic_area_offset>` 12859 returns just a zero, for others, such as PowerPC and PowerPC64, it returns a 12860 compile-time-known constant value. 12861 12862 The return value type of :ref:`llvm.get.dynamic.area.offset <int_get_dynamic_area_offset>` 12863 must match the target's default address space's (address space 0) pointer type. 12864 12865'``llvm.prefetch``' Intrinsic 12866^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12867 12868Syntax: 12869""""""" 12870 12871:: 12872 12873 declare void @llvm.prefetch(i8* <address>, i32 <rw>, i32 <locality>, i32 <cache type>) 12874 12875Overview: 12876""""""""" 12877 12878The '``llvm.prefetch``' intrinsic is a hint to the code generator to 12879insert a prefetch instruction if supported; otherwise, it is a noop. 12880Prefetches have no effect on the behavior of the program but can change 12881its performance characteristics. 12882 12883Arguments: 12884"""""""""" 12885 12886``address`` is the address to be prefetched, ``rw`` is the specifier 12887determining if the fetch should be for a read (0) or write (1), and 12888``locality`` is a temporal locality specifier ranging from (0) - no 12889locality, to (3) - extremely local keep in cache. The ``cache type`` 12890specifies whether the prefetch is performed on the data (1) or 12891instruction (0) cache. The ``rw``, ``locality`` and ``cache type`` 12892arguments must be constant integers. 12893 12894Semantics: 12895"""""""""" 12896 12897This intrinsic does not modify the behavior of the program. In 12898particular, prefetches cannot trap and do not produce a value. On 12899targets that support this intrinsic, the prefetch can provide hints to 12900the processor cache for better performance. 12901 12902'``llvm.pcmarker``' Intrinsic 12903^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12904 12905Syntax: 12906""""""" 12907 12908:: 12909 12910 declare void @llvm.pcmarker(i32 <id>) 12911 12912Overview: 12913""""""""" 12914 12915The '``llvm.pcmarker``' intrinsic is a method to export a Program 12916Counter (PC) in a region of code to simulators and other tools. The 12917method is target specific, but it is expected that the marker will use 12918exported symbols to transmit the PC of the marker. The marker makes no 12919guarantees that it will remain with any specific instruction after 12920optimizations. It is possible that the presence of a marker will inhibit 12921optimizations. The intended use is to be inserted after optimizations to 12922allow correlations of simulation runs. 12923 12924Arguments: 12925"""""""""" 12926 12927``id`` is a numerical id identifying the marker. 12928 12929Semantics: 12930"""""""""" 12931 12932This intrinsic does not modify the behavior of the program. Backends 12933that do not support this intrinsic may ignore it. 12934 12935'``llvm.readcyclecounter``' Intrinsic 12936^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12937 12938Syntax: 12939""""""" 12940 12941:: 12942 12943 declare i64 @llvm.readcyclecounter() 12944 12945Overview: 12946""""""""" 12947 12948The '``llvm.readcyclecounter``' intrinsic provides access to the cycle 12949counter register (or similar low latency, high accuracy clocks) on those 12950targets that support it. On X86, it should map to RDTSC. On Alpha, it 12951should map to RPCC. As the backing counters overflow quickly (on the 12952order of 9 seconds on alpha), this should only be used for small 12953timings. 12954 12955Semantics: 12956"""""""""" 12957 12958When directly supported, reading the cycle counter should not modify any 12959memory. Implementations are allowed to either return an application 12960specific value or a system wide value. On backends without support, this 12961is lowered to a constant 0. 12962 12963Note that runtime support may be conditional on the privilege-level code is 12964running at and the host platform. 12965 12966'``llvm.clear_cache``' Intrinsic 12967^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12968 12969Syntax: 12970""""""" 12971 12972:: 12973 12974 declare void @llvm.clear_cache(i8*, i8*) 12975 12976Overview: 12977""""""""" 12978 12979The '``llvm.clear_cache``' intrinsic ensures visibility of modifications 12980in the specified range to the execution unit of the processor. On 12981targets with non-unified instruction and data cache, the implementation 12982flushes the instruction cache. 12983 12984Semantics: 12985"""""""""" 12986 12987On platforms with coherent instruction and data caches (e.g. x86), this 12988intrinsic is a nop. On platforms with non-coherent instruction and data 12989cache (e.g. ARM, MIPS), the intrinsic is lowered either to appropriate 12990instructions or a system call, if cache flushing requires special 12991privileges. 12992 12993The default behavior is to emit a call to ``__clear_cache`` from the run 12994time library. 12995 12996This intrinsic does *not* empty the instruction pipeline. Modifications 12997of the current function are outside the scope of the intrinsic. 12998 12999'``llvm.instrprof.increment``' Intrinsic 13000^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13001 13002Syntax: 13003""""""" 13004 13005:: 13006 13007 declare void @llvm.instrprof.increment(i8* <name>, i64 <hash>, 13008 i32 <num-counters>, i32 <index>) 13009 13010Overview: 13011""""""""" 13012 13013The '``llvm.instrprof.increment``' intrinsic can be emitted by a 13014frontend for use with instrumentation based profiling. These will be 13015lowered by the ``-instrprof`` pass to generate execution counts of a 13016program at runtime. 13017 13018Arguments: 13019"""""""""" 13020 13021The first argument is a pointer to a global variable containing the 13022name of the entity being instrumented. This should generally be the 13023(mangled) function name for a set of counters. 13024 13025The second argument is a hash value that can be used by the consumer 13026of the profile data to detect changes to the instrumented source, and 13027the third is the number of counters associated with ``name``. It is an 13028error if ``hash`` or ``num-counters`` differ between two instances of 13029``instrprof.increment`` that refer to the same name. 13030 13031The last argument refers to which of the counters for ``name`` should 13032be incremented. It should be a value between 0 and ``num-counters``. 13033 13034Semantics: 13035"""""""""" 13036 13037This intrinsic represents an increment of a profiling counter. It will 13038cause the ``-instrprof`` pass to generate the appropriate data 13039structures and the code to increment the appropriate value, in a 13040format that can be written out by a compiler runtime and consumed via 13041the ``llvm-profdata`` tool. 13042 13043'``llvm.instrprof.increment.step``' Intrinsic 13044^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13045 13046Syntax: 13047""""""" 13048 13049:: 13050 13051 declare void @llvm.instrprof.increment.step(i8* <name>, i64 <hash>, 13052 i32 <num-counters>, 13053 i32 <index>, i64 <step>) 13054 13055Overview: 13056""""""""" 13057 13058The '``llvm.instrprof.increment.step``' intrinsic is an extension to 13059the '``llvm.instrprof.increment``' intrinsic with an additional fifth 13060argument to specify the step of the increment. 13061 13062Arguments: 13063"""""""""" 13064The first four arguments are the same as '``llvm.instrprof.increment``' 13065intrinsic. 13066 13067The last argument specifies the value of the increment of the counter variable. 13068 13069Semantics: 13070"""""""""" 13071See description of '``llvm.instrprof.increment``' intrinsic. 13072 13073 13074'``llvm.instrprof.value.profile``' Intrinsic 13075^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13076 13077Syntax: 13078""""""" 13079 13080:: 13081 13082 declare void @llvm.instrprof.value.profile(i8* <name>, i64 <hash>, 13083 i64 <value>, i32 <value_kind>, 13084 i32 <index>) 13085 13086Overview: 13087""""""""" 13088 13089The '``llvm.instrprof.value.profile``' intrinsic can be emitted by a 13090frontend for use with instrumentation based profiling. This will be 13091lowered by the ``-instrprof`` pass to find out the target values, 13092instrumented expressions take in a program at runtime. 13093 13094Arguments: 13095"""""""""" 13096 13097The first argument is a pointer to a global variable containing the 13098name of the entity being instrumented. ``name`` should generally be the 13099(mangled) function name for a set of counters. 13100 13101The second argument is a hash value that can be used by the consumer 13102of the profile data to detect changes to the instrumented source. It 13103is an error if ``hash`` differs between two instances of 13104``llvm.instrprof.*`` that refer to the same name. 13105 13106The third argument is the value of the expression being profiled. The profiled 13107expression's value should be representable as an unsigned 64-bit value. The 13108fourth argument represents the kind of value profiling that is being done. The 13109supported value profiling kinds are enumerated through the 13110``InstrProfValueKind`` type declared in the 13111``<include/llvm/ProfileData/InstrProf.h>`` header file. The last argument is the 13112index of the instrumented expression within ``name``. It should be >= 0. 13113 13114Semantics: 13115"""""""""" 13116 13117This intrinsic represents the point where a call to a runtime routine 13118should be inserted for value profiling of target expressions. ``-instrprof`` 13119pass will generate the appropriate data structures and replace the 13120``llvm.instrprof.value.profile`` intrinsic with the call to the profile 13121runtime library with proper arguments. 13122 13123'``llvm.thread.pointer``' Intrinsic 13124^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13125 13126Syntax: 13127""""""" 13128 13129:: 13130 13131 declare i8* @llvm.thread.pointer() 13132 13133Overview: 13134""""""""" 13135 13136The '``llvm.thread.pointer``' intrinsic returns the value of the thread 13137pointer. 13138 13139Semantics: 13140"""""""""" 13141 13142The '``llvm.thread.pointer``' intrinsic returns a pointer to the TLS area 13143for the current thread. The exact semantics of this value are target 13144specific: it may point to the start of TLS area, to the end, or somewhere 13145in the middle. Depending on the target, this intrinsic may read a register, 13146call a helper function, read from an alternate memory space, or perform 13147other operations necessary to locate the TLS area. Not all targets support 13148this intrinsic. 13149 13150'``llvm.call.preallocated.setup``' Intrinsic 13151^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13152 13153Syntax: 13154""""""" 13155 13156:: 13157 13158 declare token @llvm.call.preallocated.setup(i32 %num_args) 13159 13160Overview: 13161""""""""" 13162 13163The '``llvm.call.preallocated.setup``' intrinsic returns a token which can 13164be used with a call's ``"preallocated"`` operand bundle to indicate that 13165certain arguments are allocated and initialized before the call. 13166 13167Semantics: 13168"""""""""" 13169 13170The '``llvm.call.preallocated.setup``' intrinsic returns a token which is 13171associated with at most one call. The token can be passed to 13172'``@llvm.call.preallocated.arg``' to get a pointer to get that 13173corresponding argument. The token must be the parameter to a 13174``"preallocated"`` operand bundle for the corresponding call. 13175 13176Nested calls to '``llvm.call.preallocated.setup``' are allowed, but must 13177be properly nested. e.g. 13178 13179:: code-block:: llvm 13180 13181 %t1 = call token @llvm.call.preallocated.setup(i32 0) 13182 %t2 = call token @llvm.call.preallocated.setup(i32 0) 13183 call void foo() ["preallocated"(token %t2)] 13184 call void foo() ["preallocated"(token %t1)] 13185 13186is allowed, but not 13187 13188:: code-block:: llvm 13189 13190 %t1 = call token @llvm.call.preallocated.setup(i32 0) 13191 %t2 = call token @llvm.call.preallocated.setup(i32 0) 13192 call void foo() ["preallocated"(token %t1)] 13193 call void foo() ["preallocated"(token %t2)] 13194 13195.. _int_call_preallocated_arg: 13196 13197'``llvm.call.preallocated.arg``' Intrinsic 13198^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13199 13200Syntax: 13201""""""" 13202 13203:: 13204 13205 declare i8* @llvm.call.preallocated.arg(token %setup_token, i32 %arg_index) 13206 13207Overview: 13208""""""""" 13209 13210The '``llvm.call.preallocated.arg``' intrinsic returns a pointer to the 13211corresponding preallocated argument for the preallocated call. 13212 13213Semantics: 13214"""""""""" 13215 13216The '``llvm.call.preallocated.arg``' intrinsic returns a pointer to the 13217``%arg_index``th argument with the ``preallocated`` attribute for 13218the call associated with the ``%setup_token``, which must be from 13219'``llvm.call.preallocated.setup``'. 13220 13221A call to '``llvm.call.preallocated.arg``' must have a call site 13222``preallocated`` attribute. The type of the ``preallocated`` attribute must 13223match the type used by the ``preallocated`` attribute of the corresponding 13224argument at the preallocated call. The type is used in the case that an 13225``llvm.call.preallocated.setup`` does not have a corresponding call (e.g. due 13226to DCE), where otherwise we cannot know how large the arguments are. 13227 13228It is undefined behavior if this is called with a token from an 13229'``llvm.call.preallocated.setup``' if another 13230'``llvm.call.preallocated.setup``' has already been called or if the 13231preallocated call corresponding to the '``llvm.call.preallocated.setup``' 13232has already been called. 13233 13234.. _int_call_preallocated_teardown: 13235 13236'``llvm.call.preallocated.teardown``' Intrinsic 13237^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13238 13239Syntax: 13240""""""" 13241 13242:: 13243 13244 declare i8* @llvm.call.preallocated.teardown(token %setup_token) 13245 13246Overview: 13247""""""""" 13248 13249The '``llvm.call.preallocated.teardown``' intrinsic cleans up the stack 13250created by a '``llvm.call.preallocated.setup``'. 13251 13252Semantics: 13253"""""""""" 13254 13255The token argument must be a '``llvm.call.preallocated.setup``'. 13256 13257The '``llvm.call.preallocated.teardown``' intrinsic cleans up the stack 13258allocated by the corresponding '``llvm.call.preallocated.setup``'. Exactly 13259one of this or the preallocated call must be called to prevent stack leaks. 13260It is undefined behavior to call both a '``llvm.call.preallocated.teardown``' 13261and the preallocated call for a given '``llvm.call.preallocated.setup``'. 13262 13263For example, if the stack is allocated for a preallocated call by a 13264'``llvm.call.preallocated.setup``', then an initializer function called on an 13265allocated argument throws an exception, there should be a 13266'``llvm.call.preallocated.teardown``' in the exception handler to prevent 13267stack leaks. 13268 13269Following the nesting rules in '``llvm.call.preallocated.setup``', nested 13270calls to '``llvm.call.preallocated.setup``' and 13271'``llvm.call.preallocated.teardown``' are allowed but must be properly 13272nested. 13273 13274Example: 13275"""""""" 13276 13277.. code-block:: llvm 13278 13279 %cs = call token @llvm.call.preallocated.setup(i32 1) 13280 %x = call i8* @llvm.call.preallocated.arg(token %cs, i32 0) preallocated(i32) 13281 %y = bitcast i8* %x to i32* 13282 invoke void @constructor(i32* %y) to label %conta unwind label %contb 13283 conta: 13284 call void @foo1(i32* preallocated(i32) %y) ["preallocated"(token %cs)] 13285 ret void 13286 contb: 13287 %s = catchswitch within none [label %catch] unwind to caller 13288 catch: 13289 %p = catchpad within %s [] 13290 call void @llvm.call.preallocated.teardown(token %cs) 13291 ret void 13292 13293Standard C/C++ Library Intrinsics 13294--------------------------------- 13295 13296LLVM provides intrinsics for a few important standard C/C++ library 13297functions. These intrinsics allow source-language front-ends to pass 13298information about the alignment of the pointer arguments to the code 13299generator, providing opportunity for more efficient code generation. 13300 13301 13302'``llvm.abs.*``' Intrinsic 13303^^^^^^^^^^^^^^^^^^^^^^^^^^ 13304 13305Syntax: 13306""""""" 13307 13308This is an overloaded intrinsic. You can use ``llvm.abs`` on any 13309integer bit width or any vector of integer elements. 13310 13311:: 13312 13313 declare i32 @llvm.abs.i32(i32 <src>, i1 <is_int_min_poison>) 13314 declare <4 x i32> @llvm.abs.v4i32(<4 x i32> <src>, i1 <is_int_min_poison>) 13315 13316Overview: 13317""""""""" 13318 13319The '``llvm.abs``' family of intrinsic functions returns the absolute value 13320of an argument. 13321 13322Arguments: 13323"""""""""" 13324 13325The first argument is the value for which the absolute value is to be returned. 13326This argument may be of any integer type or a vector with integer element type. 13327The return type must match the first argument type. 13328 13329The second argument must be a constant and is a flag to indicate whether the 13330result value of the '``llvm.abs``' intrinsic is a 13331:ref:`poison value <poisonvalues>` if the argument is statically or dynamically 13332an ``INT_MIN`` value. 13333 13334Semantics: 13335"""""""""" 13336 13337The '``llvm.abs``' intrinsic returns the magnitude (always positive) of the 13338argument or each element of a vector argument.". If the argument is ``INT_MIN``, 13339then the result is also ``INT_MIN`` if ``is_int_min_poison == 0`` and 13340``poison`` otherwise. 13341 13342 13343'``llvm.smax.*``' Intrinsic 13344^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13345 13346Syntax: 13347""""""" 13348 13349This is an overloaded intrinsic. You can use ``@llvm.smax`` on any 13350integer bit width or any vector of integer elements. 13351 13352:: 13353 13354 declare i32 @llvm.smax.i32(i32 %a, i32 %b) 13355 declare <4 x i32> @llvm.smax.v4i32(<4 x i32> %a, <4 x i32> %b) 13356 13357Overview: 13358""""""""" 13359 13360Return the larger of ``%a`` and ``%b`` comparing the values as signed integers. 13361Vector intrinsics operate on a per-element basis. The larger element of ``%a`` 13362and ``%b`` at a given index is returned for that index. 13363 13364Arguments: 13365"""""""""" 13366 13367The arguments (``%a`` and ``%b``) may be of any integer type or a vector with 13368integer element type. The argument types must match each other, and the return 13369type must match the argument type. 13370 13371 13372'``llvm.smin.*``' Intrinsic 13373^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13374 13375Syntax: 13376""""""" 13377 13378This is an overloaded intrinsic. You can use ``@llvm.smin`` on any 13379integer bit width or any vector of integer elements. 13380 13381:: 13382 13383 declare i32 @llvm.smin.i32(i32 %a, i32 %b) 13384 declare <4 x i32> @llvm.smin.v4i32(<4 x i32> %a, <4 x i32> %b) 13385 13386Overview: 13387""""""""" 13388 13389Return the smaller of ``%a`` and ``%b`` comparing the values as signed integers. 13390Vector intrinsics operate on a per-element basis. The smaller element of ``%a`` 13391and ``%b`` at a given index is returned for that index. 13392 13393Arguments: 13394"""""""""" 13395 13396The arguments (``%a`` and ``%b``) may be of any integer type or a vector with 13397integer element type. The argument types must match each other, and the return 13398type must match the argument type. 13399 13400 13401'``llvm.umax.*``' Intrinsic 13402^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13403 13404Syntax: 13405""""""" 13406 13407This is an overloaded intrinsic. You can use ``@llvm.umax`` on any 13408integer bit width or any vector of integer elements. 13409 13410:: 13411 13412 declare i32 @llvm.umax.i32(i32 %a, i32 %b) 13413 declare <4 x i32> @llvm.umax.v4i32(<4 x i32> %a, <4 x i32> %b) 13414 13415Overview: 13416""""""""" 13417 13418Return the larger of ``%a`` and ``%b`` comparing the values as unsigned 13419integers. Vector intrinsics operate on a per-element basis. The larger element 13420of ``%a`` and ``%b`` at a given index is returned for that index. 13421 13422Arguments: 13423"""""""""" 13424 13425The arguments (``%a`` and ``%b``) may be of any integer type or a vector with 13426integer element type. The argument types must match each other, and the return 13427type must match the argument type. 13428 13429 13430'``llvm.umin.*``' Intrinsic 13431^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13432 13433Syntax: 13434""""""" 13435 13436This is an overloaded intrinsic. You can use ``@llvm.umin`` on any 13437integer bit width or any vector of integer elements. 13438 13439:: 13440 13441 declare i32 @llvm.umin.i32(i32 %a, i32 %b) 13442 declare <4 x i32> @llvm.umin.v4i32(<4 x i32> %a, <4 x i32> %b) 13443 13444Overview: 13445""""""""" 13446 13447Return the smaller of ``%a`` and ``%b`` comparing the values as unsigned 13448integers. Vector intrinsics operate on a per-element basis. The smaller element 13449of ``%a`` and ``%b`` at a given index is returned for that index. 13450 13451Arguments: 13452"""""""""" 13453 13454The arguments (``%a`` and ``%b``) may be of any integer type or a vector with 13455integer element type. The argument types must match each other, and the return 13456type must match the argument type. 13457 13458 13459.. _int_memcpy: 13460 13461'``llvm.memcpy``' Intrinsic 13462^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13463 13464Syntax: 13465""""""" 13466 13467This is an overloaded intrinsic. You can use ``llvm.memcpy`` on any 13468integer bit width and for different address spaces. Not all targets 13469support all bit widths however. 13470 13471:: 13472 13473 declare void @llvm.memcpy.p0i8.p0i8.i32(i8* <dest>, i8* <src>, 13474 i32 <len>, i1 <isvolatile>) 13475 declare void @llvm.memcpy.p0i8.p0i8.i64(i8* <dest>, i8* <src>, 13476 i64 <len>, i1 <isvolatile>) 13477 13478Overview: 13479""""""""" 13480 13481The '``llvm.memcpy.*``' intrinsics copy a block of memory from the 13482source location to the destination location. 13483 13484Note that, unlike the standard libc function, the ``llvm.memcpy.*`` 13485intrinsics do not return a value, takes extra isvolatile 13486arguments and the pointers can be in specified address spaces. 13487 13488Arguments: 13489"""""""""" 13490 13491The first argument is a pointer to the destination, the second is a 13492pointer to the source. The third argument is an integer argument 13493specifying the number of bytes to copy, and the fourth is a 13494boolean indicating a volatile access. 13495 13496The :ref:`align <attr_align>` parameter attribute can be provided 13497for the first and second arguments. 13498 13499If the ``isvolatile`` parameter is ``true``, the ``llvm.memcpy`` call is 13500a :ref:`volatile operation <volatile>`. The detailed access behavior is not 13501very cleanly specified and it is unwise to depend on it. 13502 13503Semantics: 13504"""""""""" 13505 13506The '``llvm.memcpy.*``' intrinsics copy a block of memory from the source 13507location to the destination location, which must either be equal or 13508non-overlapping. It copies "len" bytes of memory over. If the argument is known 13509to be aligned to some boundary, this can be specified as an attribute on the 13510argument. 13511 13512If ``<len>`` is 0, it is no-op modulo the behavior of attributes attached to 13513the arguments. 13514If ``<len>`` is not a well-defined value, the behavior is undefined. 13515If ``<len>`` is not zero, both ``<dest>`` and ``<src>`` should be well-defined, 13516otherwise the behavior is undefined. 13517 13518.. _int_memcpy_inline: 13519 13520'``llvm.memcpy.inline``' Intrinsic 13521^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13522 13523Syntax: 13524""""""" 13525 13526This is an overloaded intrinsic. You can use ``llvm.memcpy.inline`` on any 13527integer bit width and for different address spaces. Not all targets 13528support all bit widths however. 13529 13530:: 13531 13532 declare void @llvm.memcpy.inline.p0i8.p0i8.i32(i8* <dest>, i8* <src>, 13533 i32 <len>, i1 <isvolatile>) 13534 declare void @llvm.memcpy.inline.p0i8.p0i8.i64(i8* <dest>, i8* <src>, 13535 i64 <len>, i1 <isvolatile>) 13536 13537Overview: 13538""""""""" 13539 13540The '``llvm.memcpy.inline.*``' intrinsics copy a block of memory from the 13541source location to the destination location and guarantees that no external 13542functions are called. 13543 13544Note that, unlike the standard libc function, the ``llvm.memcpy.inline.*`` 13545intrinsics do not return a value, takes extra isvolatile 13546arguments and the pointers can be in specified address spaces. 13547 13548Arguments: 13549"""""""""" 13550 13551The first argument is a pointer to the destination, the second is a 13552pointer to the source. The third argument is a constant integer argument 13553specifying the number of bytes to copy, and the fourth is a 13554boolean indicating a volatile access. 13555 13556The :ref:`align <attr_align>` parameter attribute can be provided 13557for the first and second arguments. 13558 13559If the ``isvolatile`` parameter is ``true``, the ``llvm.memcpy.inline`` call is 13560a :ref:`volatile operation <volatile>`. The detailed access behavior is not 13561very cleanly specified and it is unwise to depend on it. 13562 13563Semantics: 13564"""""""""" 13565 13566The '``llvm.memcpy.inline.*``' intrinsics copy a block of memory from the 13567source location to the destination location, which are not allowed to 13568overlap. It copies "len" bytes of memory over. If the argument is known 13569to be aligned to some boundary, this can be specified as an attribute on 13570the argument. 13571The behavior of '``llvm.memcpy.inline.*``' is equivalent to the behavior of 13572'``llvm.memcpy.*``', but the generated code is guaranteed not to call any 13573external functions. 13574 13575.. _int_memmove: 13576 13577'``llvm.memmove``' Intrinsic 13578^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13579 13580Syntax: 13581""""""" 13582 13583This is an overloaded intrinsic. You can use llvm.memmove on any integer 13584bit width and for different address space. Not all targets support all 13585bit widths however. 13586 13587:: 13588 13589 declare void @llvm.memmove.p0i8.p0i8.i32(i8* <dest>, i8* <src>, 13590 i32 <len>, i1 <isvolatile>) 13591 declare void @llvm.memmove.p0i8.p0i8.i64(i8* <dest>, i8* <src>, 13592 i64 <len>, i1 <isvolatile>) 13593 13594Overview: 13595""""""""" 13596 13597The '``llvm.memmove.*``' intrinsics move a block of memory from the 13598source location to the destination location. It is similar to the 13599'``llvm.memcpy``' intrinsic but allows the two memory locations to 13600overlap. 13601 13602Note that, unlike the standard libc function, the ``llvm.memmove.*`` 13603intrinsics do not return a value, takes an extra isvolatile 13604argument and the pointers can be in specified address spaces. 13605 13606Arguments: 13607"""""""""" 13608 13609The first argument is a pointer to the destination, the second is a 13610pointer to the source. The third argument is an integer argument 13611specifying the number of bytes to copy, and the fourth is a 13612boolean indicating a volatile access. 13613 13614The :ref:`align <attr_align>` parameter attribute can be provided 13615for the first and second arguments. 13616 13617If the ``isvolatile`` parameter is ``true``, the ``llvm.memmove`` call 13618is a :ref:`volatile operation <volatile>`. The detailed access behavior is 13619not very cleanly specified and it is unwise to depend on it. 13620 13621Semantics: 13622"""""""""" 13623 13624The '``llvm.memmove.*``' intrinsics copy a block of memory from the 13625source location to the destination location, which may overlap. It 13626copies "len" bytes of memory over. If the argument is known to be 13627aligned to some boundary, this can be specified as an attribute on 13628the argument. 13629 13630If ``<len>`` is 0, it is no-op modulo the behavior of attributes attached to 13631the arguments. 13632If ``<len>`` is not a well-defined value, the behavior is undefined. 13633If ``<len>`` is not zero, both ``<dest>`` and ``<src>`` should be well-defined, 13634otherwise the behavior is undefined. 13635 13636.. _int_memset: 13637 13638'``llvm.memset.*``' Intrinsics 13639^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13640 13641Syntax: 13642""""""" 13643 13644This is an overloaded intrinsic. You can use llvm.memset on any integer 13645bit width and for different address spaces. However, not all targets 13646support all bit widths. 13647 13648:: 13649 13650 declare void @llvm.memset.p0i8.i32(i8* <dest>, i8 <val>, 13651 i32 <len>, i1 <isvolatile>) 13652 declare void @llvm.memset.p0i8.i64(i8* <dest>, i8 <val>, 13653 i64 <len>, i1 <isvolatile>) 13654 13655Overview: 13656""""""""" 13657 13658The '``llvm.memset.*``' intrinsics fill a block of memory with a 13659particular byte value. 13660 13661Note that, unlike the standard libc function, the ``llvm.memset`` 13662intrinsic does not return a value and takes an extra volatile 13663argument. Also, the destination can be in an arbitrary address space. 13664 13665Arguments: 13666"""""""""" 13667 13668The first argument is a pointer to the destination to fill, the second 13669is the byte value with which to fill it, the third argument is an 13670integer argument specifying the number of bytes to fill, and the fourth 13671is a boolean indicating a volatile access. 13672 13673The :ref:`align <attr_align>` parameter attribute can be provided 13674for the first arguments. 13675 13676If the ``isvolatile`` parameter is ``true``, the ``llvm.memset`` call is 13677a :ref:`volatile operation <volatile>`. The detailed access behavior is not 13678very cleanly specified and it is unwise to depend on it. 13679 13680Semantics: 13681"""""""""" 13682 13683The '``llvm.memset.*``' intrinsics fill "len" bytes of memory starting 13684at the destination location. If the argument is known to be 13685aligned to some boundary, this can be specified as an attribute on 13686the argument. 13687 13688If ``<len>`` is 0, it is no-op modulo the behavior of attributes attached to 13689the arguments. 13690If ``<len>`` is not a well-defined value, the behavior is undefined. 13691If ``<len>`` is not zero, both ``<dest>`` and ``<src>`` should be well-defined, 13692otherwise the behavior is undefined. 13693 13694'``llvm.sqrt.*``' Intrinsic 13695^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13696 13697Syntax: 13698""""""" 13699 13700This is an overloaded intrinsic. You can use ``llvm.sqrt`` on any 13701floating-point or vector of floating-point type. Not all targets support 13702all types however. 13703 13704:: 13705 13706 declare float @llvm.sqrt.f32(float %Val) 13707 declare double @llvm.sqrt.f64(double %Val) 13708 declare x86_fp80 @llvm.sqrt.f80(x86_fp80 %Val) 13709 declare fp128 @llvm.sqrt.f128(fp128 %Val) 13710 declare ppc_fp128 @llvm.sqrt.ppcf128(ppc_fp128 %Val) 13711 13712Overview: 13713""""""""" 13714 13715The '``llvm.sqrt``' intrinsics return the square root of the specified value. 13716 13717Arguments: 13718"""""""""" 13719 13720The argument and return value are floating-point numbers of the same type. 13721 13722Semantics: 13723"""""""""" 13724 13725Return the same value as a corresponding libm '``sqrt``' function but without 13726trapping or setting ``errno``. For types specified by IEEE-754, the result 13727matches a conforming libm implementation. 13728 13729When specified with the fast-math-flag 'afn', the result may be approximated 13730using a less accurate calculation. 13731 13732'``llvm.powi.*``' Intrinsic 13733^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13734 13735Syntax: 13736""""""" 13737 13738This is an overloaded intrinsic. You can use ``llvm.powi`` on any 13739floating-point or vector of floating-point type. Not all targets support 13740all types however. 13741 13742Generally, the only supported type for the exponent is the one matching 13743with the C type ``int``. 13744 13745:: 13746 13747 declare float @llvm.powi.f32.i32(float %Val, i32 %power) 13748 declare double @llvm.powi.f64.i16(double %Val, i16 %power) 13749 declare x86_fp80 @llvm.powi.f80.i32(x86_fp80 %Val, i32 %power) 13750 declare fp128 @llvm.powi.f128.i32(fp128 %Val, i32 %power) 13751 declare ppc_fp128 @llvm.powi.ppcf128.i32(ppc_fp128 %Val, i32 %power) 13752 13753Overview: 13754""""""""" 13755 13756The '``llvm.powi.*``' intrinsics return the first operand raised to the 13757specified (positive or negative) power. The order of evaluation of 13758multiplications is not defined. When a vector of floating-point type is 13759used, the second argument remains a scalar integer value. 13760 13761Arguments: 13762"""""""""" 13763 13764The second argument is an integer power, and the first is a value to 13765raise to that power. 13766 13767Semantics: 13768"""""""""" 13769 13770This function returns the first value raised to the second power with an 13771unspecified sequence of rounding operations. 13772 13773'``llvm.sin.*``' Intrinsic 13774^^^^^^^^^^^^^^^^^^^^^^^^^^ 13775 13776Syntax: 13777""""""" 13778 13779This is an overloaded intrinsic. You can use ``llvm.sin`` on any 13780floating-point or vector of floating-point type. Not all targets support 13781all types however. 13782 13783:: 13784 13785 declare float @llvm.sin.f32(float %Val) 13786 declare double @llvm.sin.f64(double %Val) 13787 declare x86_fp80 @llvm.sin.f80(x86_fp80 %Val) 13788 declare fp128 @llvm.sin.f128(fp128 %Val) 13789 declare ppc_fp128 @llvm.sin.ppcf128(ppc_fp128 %Val) 13790 13791Overview: 13792""""""""" 13793 13794The '``llvm.sin.*``' intrinsics return the sine of the operand. 13795 13796Arguments: 13797"""""""""" 13798 13799The argument and return value are floating-point numbers of the same type. 13800 13801Semantics: 13802"""""""""" 13803 13804Return the same value as a corresponding libm '``sin``' function but without 13805trapping or setting ``errno``. 13806 13807When specified with the fast-math-flag 'afn', the result may be approximated 13808using a less accurate calculation. 13809 13810'``llvm.cos.*``' Intrinsic 13811^^^^^^^^^^^^^^^^^^^^^^^^^^ 13812 13813Syntax: 13814""""""" 13815 13816This is an overloaded intrinsic. You can use ``llvm.cos`` on any 13817floating-point or vector of floating-point type. Not all targets support 13818all types however. 13819 13820:: 13821 13822 declare float @llvm.cos.f32(float %Val) 13823 declare double @llvm.cos.f64(double %Val) 13824 declare x86_fp80 @llvm.cos.f80(x86_fp80 %Val) 13825 declare fp128 @llvm.cos.f128(fp128 %Val) 13826 declare ppc_fp128 @llvm.cos.ppcf128(ppc_fp128 %Val) 13827 13828Overview: 13829""""""""" 13830 13831The '``llvm.cos.*``' intrinsics return the cosine of the operand. 13832 13833Arguments: 13834"""""""""" 13835 13836The argument and return value are floating-point numbers of the same type. 13837 13838Semantics: 13839"""""""""" 13840 13841Return the same value as a corresponding libm '``cos``' function but without 13842trapping or setting ``errno``. 13843 13844When specified with the fast-math-flag 'afn', the result may be approximated 13845using a less accurate calculation. 13846 13847'``llvm.pow.*``' Intrinsic 13848^^^^^^^^^^^^^^^^^^^^^^^^^^ 13849 13850Syntax: 13851""""""" 13852 13853This is an overloaded intrinsic. You can use ``llvm.pow`` on any 13854floating-point or vector of floating-point type. Not all targets support 13855all types however. 13856 13857:: 13858 13859 declare float @llvm.pow.f32(float %Val, float %Power) 13860 declare double @llvm.pow.f64(double %Val, double %Power) 13861 declare x86_fp80 @llvm.pow.f80(x86_fp80 %Val, x86_fp80 %Power) 13862 declare fp128 @llvm.pow.f128(fp128 %Val, fp128 %Power) 13863 declare ppc_fp128 @llvm.pow.ppcf128(ppc_fp128 %Val, ppc_fp128 Power) 13864 13865Overview: 13866""""""""" 13867 13868The '``llvm.pow.*``' intrinsics return the first operand raised to the 13869specified (positive or negative) power. 13870 13871Arguments: 13872"""""""""" 13873 13874The arguments and return value are floating-point numbers of the same type. 13875 13876Semantics: 13877"""""""""" 13878 13879Return the same value as a corresponding libm '``pow``' function but without 13880trapping or setting ``errno``. 13881 13882When specified with the fast-math-flag 'afn', the result may be approximated 13883using a less accurate calculation. 13884 13885'``llvm.exp.*``' Intrinsic 13886^^^^^^^^^^^^^^^^^^^^^^^^^^ 13887 13888Syntax: 13889""""""" 13890 13891This is an overloaded intrinsic. You can use ``llvm.exp`` on any 13892floating-point or vector of floating-point type. Not all targets support 13893all types however. 13894 13895:: 13896 13897 declare float @llvm.exp.f32(float %Val) 13898 declare double @llvm.exp.f64(double %Val) 13899 declare x86_fp80 @llvm.exp.f80(x86_fp80 %Val) 13900 declare fp128 @llvm.exp.f128(fp128 %Val) 13901 declare ppc_fp128 @llvm.exp.ppcf128(ppc_fp128 %Val) 13902 13903Overview: 13904""""""""" 13905 13906The '``llvm.exp.*``' intrinsics compute the base-e exponential of the specified 13907value. 13908 13909Arguments: 13910"""""""""" 13911 13912The argument and return value are floating-point numbers of the same type. 13913 13914Semantics: 13915"""""""""" 13916 13917Return the same value as a corresponding libm '``exp``' function but without 13918trapping or setting ``errno``. 13919 13920When specified with the fast-math-flag 'afn', the result may be approximated 13921using a less accurate calculation. 13922 13923'``llvm.exp2.*``' Intrinsic 13924^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13925 13926Syntax: 13927""""""" 13928 13929This is an overloaded intrinsic. You can use ``llvm.exp2`` on any 13930floating-point or vector of floating-point type. Not all targets support 13931all types however. 13932 13933:: 13934 13935 declare float @llvm.exp2.f32(float %Val) 13936 declare double @llvm.exp2.f64(double %Val) 13937 declare x86_fp80 @llvm.exp2.f80(x86_fp80 %Val) 13938 declare fp128 @llvm.exp2.f128(fp128 %Val) 13939 declare ppc_fp128 @llvm.exp2.ppcf128(ppc_fp128 %Val) 13940 13941Overview: 13942""""""""" 13943 13944The '``llvm.exp2.*``' intrinsics compute the base-2 exponential of the 13945specified value. 13946 13947Arguments: 13948"""""""""" 13949 13950The argument and return value are floating-point numbers of the same type. 13951 13952Semantics: 13953"""""""""" 13954 13955Return the same value as a corresponding libm '``exp2``' function but without 13956trapping or setting ``errno``. 13957 13958When specified with the fast-math-flag 'afn', the result may be approximated 13959using a less accurate calculation. 13960 13961'``llvm.log.*``' Intrinsic 13962^^^^^^^^^^^^^^^^^^^^^^^^^^ 13963 13964Syntax: 13965""""""" 13966 13967This is an overloaded intrinsic. You can use ``llvm.log`` on any 13968floating-point or vector of floating-point type. Not all targets support 13969all types however. 13970 13971:: 13972 13973 declare float @llvm.log.f32(float %Val) 13974 declare double @llvm.log.f64(double %Val) 13975 declare x86_fp80 @llvm.log.f80(x86_fp80 %Val) 13976 declare fp128 @llvm.log.f128(fp128 %Val) 13977 declare ppc_fp128 @llvm.log.ppcf128(ppc_fp128 %Val) 13978 13979Overview: 13980""""""""" 13981 13982The '``llvm.log.*``' intrinsics compute the base-e logarithm of the specified 13983value. 13984 13985Arguments: 13986"""""""""" 13987 13988The argument and return value are floating-point numbers of the same type. 13989 13990Semantics: 13991"""""""""" 13992 13993Return the same value as a corresponding libm '``log``' function but without 13994trapping or setting ``errno``. 13995 13996When specified with the fast-math-flag 'afn', the result may be approximated 13997using a less accurate calculation. 13998 13999'``llvm.log10.*``' Intrinsic 14000^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14001 14002Syntax: 14003""""""" 14004 14005This is an overloaded intrinsic. You can use ``llvm.log10`` on any 14006floating-point or vector of floating-point type. Not all targets support 14007all types however. 14008 14009:: 14010 14011 declare float @llvm.log10.f32(float %Val) 14012 declare double @llvm.log10.f64(double %Val) 14013 declare x86_fp80 @llvm.log10.f80(x86_fp80 %Val) 14014 declare fp128 @llvm.log10.f128(fp128 %Val) 14015 declare ppc_fp128 @llvm.log10.ppcf128(ppc_fp128 %Val) 14016 14017Overview: 14018""""""""" 14019 14020The '``llvm.log10.*``' intrinsics compute the base-10 logarithm of the 14021specified value. 14022 14023Arguments: 14024"""""""""" 14025 14026The argument and return value are floating-point numbers of the same type. 14027 14028Semantics: 14029"""""""""" 14030 14031Return the same value as a corresponding libm '``log10``' function but without 14032trapping or setting ``errno``. 14033 14034When specified with the fast-math-flag 'afn', the result may be approximated 14035using a less accurate calculation. 14036 14037'``llvm.log2.*``' Intrinsic 14038^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14039 14040Syntax: 14041""""""" 14042 14043This is an overloaded intrinsic. You can use ``llvm.log2`` on any 14044floating-point or vector of floating-point type. Not all targets support 14045all types however. 14046 14047:: 14048 14049 declare float @llvm.log2.f32(float %Val) 14050 declare double @llvm.log2.f64(double %Val) 14051 declare x86_fp80 @llvm.log2.f80(x86_fp80 %Val) 14052 declare fp128 @llvm.log2.f128(fp128 %Val) 14053 declare ppc_fp128 @llvm.log2.ppcf128(ppc_fp128 %Val) 14054 14055Overview: 14056""""""""" 14057 14058The '``llvm.log2.*``' intrinsics compute the base-2 logarithm of the specified 14059value. 14060 14061Arguments: 14062"""""""""" 14063 14064The argument and return value are floating-point numbers of the same type. 14065 14066Semantics: 14067"""""""""" 14068 14069Return the same value as a corresponding libm '``log2``' function but without 14070trapping or setting ``errno``. 14071 14072When specified with the fast-math-flag 'afn', the result may be approximated 14073using a less accurate calculation. 14074 14075.. _int_fma: 14076 14077'``llvm.fma.*``' Intrinsic 14078^^^^^^^^^^^^^^^^^^^^^^^^^^ 14079 14080Syntax: 14081""""""" 14082 14083This is an overloaded intrinsic. You can use ``llvm.fma`` on any 14084floating-point or vector of floating-point type. Not all targets support 14085all types however. 14086 14087:: 14088 14089 declare float @llvm.fma.f32(float %a, float %b, float %c) 14090 declare double @llvm.fma.f64(double %a, double %b, double %c) 14091 declare x86_fp80 @llvm.fma.f80(x86_fp80 %a, x86_fp80 %b, x86_fp80 %c) 14092 declare fp128 @llvm.fma.f128(fp128 %a, fp128 %b, fp128 %c) 14093 declare ppc_fp128 @llvm.fma.ppcf128(ppc_fp128 %a, ppc_fp128 %b, ppc_fp128 %c) 14094 14095Overview: 14096""""""""" 14097 14098The '``llvm.fma.*``' intrinsics perform the fused multiply-add operation. 14099 14100Arguments: 14101"""""""""" 14102 14103The arguments and return value are floating-point numbers of the same type. 14104 14105Semantics: 14106"""""""""" 14107 14108Return the same value as a corresponding libm '``fma``' function but without 14109trapping or setting ``errno``. 14110 14111When specified with the fast-math-flag 'afn', the result may be approximated 14112using a less accurate calculation. 14113 14114'``llvm.fabs.*``' Intrinsic 14115^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14116 14117Syntax: 14118""""""" 14119 14120This is an overloaded intrinsic. You can use ``llvm.fabs`` on any 14121floating-point or vector of floating-point type. Not all targets support 14122all types however. 14123 14124:: 14125 14126 declare float @llvm.fabs.f32(float %Val) 14127 declare double @llvm.fabs.f64(double %Val) 14128 declare x86_fp80 @llvm.fabs.f80(x86_fp80 %Val) 14129 declare fp128 @llvm.fabs.f128(fp128 %Val) 14130 declare ppc_fp128 @llvm.fabs.ppcf128(ppc_fp128 %Val) 14131 14132Overview: 14133""""""""" 14134 14135The '``llvm.fabs.*``' intrinsics return the absolute value of the 14136operand. 14137 14138Arguments: 14139"""""""""" 14140 14141The argument and return value are floating-point numbers of the same 14142type. 14143 14144Semantics: 14145"""""""""" 14146 14147This function returns the same values as the libm ``fabs`` functions 14148would, and handles error conditions in the same way. 14149 14150'``llvm.minnum.*``' Intrinsic 14151^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14152 14153Syntax: 14154""""""" 14155 14156This is an overloaded intrinsic. You can use ``llvm.minnum`` on any 14157floating-point or vector of floating-point type. Not all targets support 14158all types however. 14159 14160:: 14161 14162 declare float @llvm.minnum.f32(float %Val0, float %Val1) 14163 declare double @llvm.minnum.f64(double %Val0, double %Val1) 14164 declare x86_fp80 @llvm.minnum.f80(x86_fp80 %Val0, x86_fp80 %Val1) 14165 declare fp128 @llvm.minnum.f128(fp128 %Val0, fp128 %Val1) 14166 declare ppc_fp128 @llvm.minnum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1) 14167 14168Overview: 14169""""""""" 14170 14171The '``llvm.minnum.*``' intrinsics return the minimum of the two 14172arguments. 14173 14174 14175Arguments: 14176"""""""""" 14177 14178The arguments and return value are floating-point numbers of the same 14179type. 14180 14181Semantics: 14182"""""""""" 14183 14184Follows the IEEE-754 semantics for minNum, except for handling of 14185signaling NaNs. This match's the behavior of libm's fmin. 14186 14187If either operand is a NaN, returns the other non-NaN operand. Returns 14188NaN only if both operands are NaN. The returned NaN is always 14189quiet. If the operands compare equal, returns a value that compares 14190equal to both operands. This means that fmin(+/-0.0, +/-0.0) could 14191return either -0.0 or 0.0. 14192 14193Unlike the IEEE-754 2008 behavior, this does not distinguish between 14194signaling and quiet NaN inputs. If a target's implementation follows 14195the standard and returns a quiet NaN if either input is a signaling 14196NaN, the intrinsic lowering is responsible for quieting the inputs to 14197correctly return the non-NaN input (e.g. by using the equivalent of 14198``llvm.canonicalize``). 14199 14200 14201'``llvm.maxnum.*``' Intrinsic 14202^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14203 14204Syntax: 14205""""""" 14206 14207This is an overloaded intrinsic. You can use ``llvm.maxnum`` on any 14208floating-point or vector of floating-point type. Not all targets support 14209all types however. 14210 14211:: 14212 14213 declare float @llvm.maxnum.f32(float %Val0, float %Val1) 14214 declare double @llvm.maxnum.f64(double %Val0, double %Val1) 14215 declare x86_fp80 @llvm.maxnum.f80(x86_fp80 %Val0, x86_fp80 %Val1) 14216 declare fp128 @llvm.maxnum.f128(fp128 %Val0, fp128 %Val1) 14217 declare ppc_fp128 @llvm.maxnum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1) 14218 14219Overview: 14220""""""""" 14221 14222The '``llvm.maxnum.*``' intrinsics return the maximum of the two 14223arguments. 14224 14225 14226Arguments: 14227"""""""""" 14228 14229The arguments and return value are floating-point numbers of the same 14230type. 14231 14232Semantics: 14233"""""""""" 14234Follows the IEEE-754 semantics for maxNum except for the handling of 14235signaling NaNs. This matches the behavior of libm's fmax. 14236 14237If either operand is a NaN, returns the other non-NaN operand. Returns 14238NaN only if both operands are NaN. The returned NaN is always 14239quiet. If the operands compare equal, returns a value that compares 14240equal to both operands. This means that fmax(+/-0.0, +/-0.0) could 14241return either -0.0 or 0.0. 14242 14243Unlike the IEEE-754 2008 behavior, this does not distinguish between 14244signaling and quiet NaN inputs. If a target's implementation follows 14245the standard and returns a quiet NaN if either input is a signaling 14246NaN, the intrinsic lowering is responsible for quieting the inputs to 14247correctly return the non-NaN input (e.g. by using the equivalent of 14248``llvm.canonicalize``). 14249 14250'``llvm.minimum.*``' Intrinsic 14251^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14252 14253Syntax: 14254""""""" 14255 14256This is an overloaded intrinsic. You can use ``llvm.minimum`` on any 14257floating-point or vector of floating-point type. Not all targets support 14258all types however. 14259 14260:: 14261 14262 declare float @llvm.minimum.f32(float %Val0, float %Val1) 14263 declare double @llvm.minimum.f64(double %Val0, double %Val1) 14264 declare x86_fp80 @llvm.minimum.f80(x86_fp80 %Val0, x86_fp80 %Val1) 14265 declare fp128 @llvm.minimum.f128(fp128 %Val0, fp128 %Val1) 14266 declare ppc_fp128 @llvm.minimum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1) 14267 14268Overview: 14269""""""""" 14270 14271The '``llvm.minimum.*``' intrinsics return the minimum of the two 14272arguments, propagating NaNs and treating -0.0 as less than +0.0. 14273 14274 14275Arguments: 14276"""""""""" 14277 14278The arguments and return value are floating-point numbers of the same 14279type. 14280 14281Semantics: 14282"""""""""" 14283If either operand is a NaN, returns NaN. Otherwise returns the lesser 14284of the two arguments. -0.0 is considered to be less than +0.0 for this 14285intrinsic. Note that these are the semantics specified in the draft of 14286IEEE 754-2018. 14287 14288'``llvm.maximum.*``' Intrinsic 14289^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14290 14291Syntax: 14292""""""" 14293 14294This is an overloaded intrinsic. You can use ``llvm.maximum`` on any 14295floating-point or vector of floating-point type. Not all targets support 14296all types however. 14297 14298:: 14299 14300 declare float @llvm.maximum.f32(float %Val0, float %Val1) 14301 declare double @llvm.maximum.f64(double %Val0, double %Val1) 14302 declare x86_fp80 @llvm.maximum.f80(x86_fp80 %Val0, x86_fp80 %Val1) 14303 declare fp128 @llvm.maximum.f128(fp128 %Val0, fp128 %Val1) 14304 declare ppc_fp128 @llvm.maximum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1) 14305 14306Overview: 14307""""""""" 14308 14309The '``llvm.maximum.*``' intrinsics return the maximum of the two 14310arguments, propagating NaNs and treating -0.0 as less than +0.0. 14311 14312 14313Arguments: 14314"""""""""" 14315 14316The arguments and return value are floating-point numbers of the same 14317type. 14318 14319Semantics: 14320"""""""""" 14321If either operand is a NaN, returns NaN. Otherwise returns the greater 14322of the two arguments. -0.0 is considered to be less than +0.0 for this 14323intrinsic. Note that these are the semantics specified in the draft of 14324IEEE 754-2018. 14325 14326'``llvm.copysign.*``' Intrinsic 14327^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14328 14329Syntax: 14330""""""" 14331 14332This is an overloaded intrinsic. You can use ``llvm.copysign`` on any 14333floating-point or vector of floating-point type. Not all targets support 14334all types however. 14335 14336:: 14337 14338 declare float @llvm.copysign.f32(float %Mag, float %Sgn) 14339 declare double @llvm.copysign.f64(double %Mag, double %Sgn) 14340 declare x86_fp80 @llvm.copysign.f80(x86_fp80 %Mag, x86_fp80 %Sgn) 14341 declare fp128 @llvm.copysign.f128(fp128 %Mag, fp128 %Sgn) 14342 declare ppc_fp128 @llvm.copysign.ppcf128(ppc_fp128 %Mag, ppc_fp128 %Sgn) 14343 14344Overview: 14345""""""""" 14346 14347The '``llvm.copysign.*``' intrinsics return a value with the magnitude of the 14348first operand and the sign of the second operand. 14349 14350Arguments: 14351"""""""""" 14352 14353The arguments and return value are floating-point numbers of the same 14354type. 14355 14356Semantics: 14357"""""""""" 14358 14359This function returns the same values as the libm ``copysign`` 14360functions would, and handles error conditions in the same way. 14361 14362'``llvm.floor.*``' Intrinsic 14363^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14364 14365Syntax: 14366""""""" 14367 14368This is an overloaded intrinsic. You can use ``llvm.floor`` on any 14369floating-point or vector of floating-point type. Not all targets support 14370all types however. 14371 14372:: 14373 14374 declare float @llvm.floor.f32(float %Val) 14375 declare double @llvm.floor.f64(double %Val) 14376 declare x86_fp80 @llvm.floor.f80(x86_fp80 %Val) 14377 declare fp128 @llvm.floor.f128(fp128 %Val) 14378 declare ppc_fp128 @llvm.floor.ppcf128(ppc_fp128 %Val) 14379 14380Overview: 14381""""""""" 14382 14383The '``llvm.floor.*``' intrinsics return the floor of the operand. 14384 14385Arguments: 14386"""""""""" 14387 14388The argument and return value are floating-point numbers of the same 14389type. 14390 14391Semantics: 14392"""""""""" 14393 14394This function returns the same values as the libm ``floor`` functions 14395would, and handles error conditions in the same way. 14396 14397'``llvm.ceil.*``' Intrinsic 14398^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14399 14400Syntax: 14401""""""" 14402 14403This is an overloaded intrinsic. You can use ``llvm.ceil`` on any 14404floating-point or vector of floating-point type. Not all targets support 14405all types however. 14406 14407:: 14408 14409 declare float @llvm.ceil.f32(float %Val) 14410 declare double @llvm.ceil.f64(double %Val) 14411 declare x86_fp80 @llvm.ceil.f80(x86_fp80 %Val) 14412 declare fp128 @llvm.ceil.f128(fp128 %Val) 14413 declare ppc_fp128 @llvm.ceil.ppcf128(ppc_fp128 %Val) 14414 14415Overview: 14416""""""""" 14417 14418The '``llvm.ceil.*``' intrinsics return the ceiling of the operand. 14419 14420Arguments: 14421"""""""""" 14422 14423The argument and return value are floating-point numbers of the same 14424type. 14425 14426Semantics: 14427"""""""""" 14428 14429This function returns the same values as the libm ``ceil`` functions 14430would, and handles error conditions in the same way. 14431 14432'``llvm.trunc.*``' Intrinsic 14433^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14434 14435Syntax: 14436""""""" 14437 14438This is an overloaded intrinsic. You can use ``llvm.trunc`` on any 14439floating-point or vector of floating-point type. Not all targets support 14440all types however. 14441 14442:: 14443 14444 declare float @llvm.trunc.f32(float %Val) 14445 declare double @llvm.trunc.f64(double %Val) 14446 declare x86_fp80 @llvm.trunc.f80(x86_fp80 %Val) 14447 declare fp128 @llvm.trunc.f128(fp128 %Val) 14448 declare ppc_fp128 @llvm.trunc.ppcf128(ppc_fp128 %Val) 14449 14450Overview: 14451""""""""" 14452 14453The '``llvm.trunc.*``' intrinsics returns the operand rounded to the 14454nearest integer not larger in magnitude than the operand. 14455 14456Arguments: 14457"""""""""" 14458 14459The argument and return value are floating-point numbers of the same 14460type. 14461 14462Semantics: 14463"""""""""" 14464 14465This function returns the same values as the libm ``trunc`` functions 14466would, and handles error conditions in the same way. 14467 14468'``llvm.rint.*``' Intrinsic 14469^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14470 14471Syntax: 14472""""""" 14473 14474This is an overloaded intrinsic. You can use ``llvm.rint`` on any 14475floating-point or vector of floating-point type. Not all targets support 14476all types however. 14477 14478:: 14479 14480 declare float @llvm.rint.f32(float %Val) 14481 declare double @llvm.rint.f64(double %Val) 14482 declare x86_fp80 @llvm.rint.f80(x86_fp80 %Val) 14483 declare fp128 @llvm.rint.f128(fp128 %Val) 14484 declare ppc_fp128 @llvm.rint.ppcf128(ppc_fp128 %Val) 14485 14486Overview: 14487""""""""" 14488 14489The '``llvm.rint.*``' intrinsics returns the operand rounded to the 14490nearest integer. It may raise an inexact floating-point exception if the 14491operand isn't an integer. 14492 14493Arguments: 14494"""""""""" 14495 14496The argument and return value are floating-point numbers of the same 14497type. 14498 14499Semantics: 14500"""""""""" 14501 14502This function returns the same values as the libm ``rint`` functions 14503would, and handles error conditions in the same way. 14504 14505'``llvm.nearbyint.*``' Intrinsic 14506^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14507 14508Syntax: 14509""""""" 14510 14511This is an overloaded intrinsic. You can use ``llvm.nearbyint`` on any 14512floating-point or vector of floating-point type. Not all targets support 14513all types however. 14514 14515:: 14516 14517 declare float @llvm.nearbyint.f32(float %Val) 14518 declare double @llvm.nearbyint.f64(double %Val) 14519 declare x86_fp80 @llvm.nearbyint.f80(x86_fp80 %Val) 14520 declare fp128 @llvm.nearbyint.f128(fp128 %Val) 14521 declare ppc_fp128 @llvm.nearbyint.ppcf128(ppc_fp128 %Val) 14522 14523Overview: 14524""""""""" 14525 14526The '``llvm.nearbyint.*``' intrinsics returns the operand rounded to the 14527nearest integer. 14528 14529Arguments: 14530"""""""""" 14531 14532The argument and return value are floating-point numbers of the same 14533type. 14534 14535Semantics: 14536"""""""""" 14537 14538This function returns the same values as the libm ``nearbyint`` 14539functions would, and handles error conditions in the same way. 14540 14541'``llvm.round.*``' Intrinsic 14542^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14543 14544Syntax: 14545""""""" 14546 14547This is an overloaded intrinsic. You can use ``llvm.round`` on any 14548floating-point or vector of floating-point type. Not all targets support 14549all types however. 14550 14551:: 14552 14553 declare float @llvm.round.f32(float %Val) 14554 declare double @llvm.round.f64(double %Val) 14555 declare x86_fp80 @llvm.round.f80(x86_fp80 %Val) 14556 declare fp128 @llvm.round.f128(fp128 %Val) 14557 declare ppc_fp128 @llvm.round.ppcf128(ppc_fp128 %Val) 14558 14559Overview: 14560""""""""" 14561 14562The '``llvm.round.*``' intrinsics returns the operand rounded to the 14563nearest integer. 14564 14565Arguments: 14566"""""""""" 14567 14568The argument and return value are floating-point numbers of the same 14569type. 14570 14571Semantics: 14572"""""""""" 14573 14574This function returns the same values as the libm ``round`` 14575functions would, and handles error conditions in the same way. 14576 14577'``llvm.roundeven.*``' Intrinsic 14578^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14579 14580Syntax: 14581""""""" 14582 14583This is an overloaded intrinsic. You can use ``llvm.roundeven`` on any 14584floating-point or vector of floating-point type. Not all targets support 14585all types however. 14586 14587:: 14588 14589 declare float @llvm.roundeven.f32(float %Val) 14590 declare double @llvm.roundeven.f64(double %Val) 14591 declare x86_fp80 @llvm.roundeven.f80(x86_fp80 %Val) 14592 declare fp128 @llvm.roundeven.f128(fp128 %Val) 14593 declare ppc_fp128 @llvm.roundeven.ppcf128(ppc_fp128 %Val) 14594 14595Overview: 14596""""""""" 14597 14598The '``llvm.roundeven.*``' intrinsics returns the operand rounded to the nearest 14599integer in floating-point format rounding halfway cases to even (that is, to the 14600nearest value that is an even integer). 14601 14602Arguments: 14603"""""""""" 14604 14605The argument and return value are floating-point numbers of the same type. 14606 14607Semantics: 14608"""""""""" 14609 14610This function implements IEEE-754 operation ``roundToIntegralTiesToEven``. It 14611also behaves in the same way as C standard function ``roundeven``, except that 14612it does not raise floating point exceptions. 14613 14614 14615'``llvm.lround.*``' Intrinsic 14616^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14617 14618Syntax: 14619""""""" 14620 14621This is an overloaded intrinsic. You can use ``llvm.lround`` on any 14622floating-point type. Not all targets support all types however. 14623 14624:: 14625 14626 declare i32 @llvm.lround.i32.f32(float %Val) 14627 declare i32 @llvm.lround.i32.f64(double %Val) 14628 declare i32 @llvm.lround.i32.f80(float %Val) 14629 declare i32 @llvm.lround.i32.f128(double %Val) 14630 declare i32 @llvm.lround.i32.ppcf128(double %Val) 14631 14632 declare i64 @llvm.lround.i64.f32(float %Val) 14633 declare i64 @llvm.lround.i64.f64(double %Val) 14634 declare i64 @llvm.lround.i64.f80(float %Val) 14635 declare i64 @llvm.lround.i64.f128(double %Val) 14636 declare i64 @llvm.lround.i64.ppcf128(double %Val) 14637 14638Overview: 14639""""""""" 14640 14641The '``llvm.lround.*``' intrinsics return the operand rounded to the nearest 14642integer with ties away from zero. 14643 14644 14645Arguments: 14646"""""""""" 14647 14648The argument is a floating-point number and the return value is an integer 14649type. 14650 14651Semantics: 14652"""""""""" 14653 14654This function returns the same values as the libm ``lround`` 14655functions would, but without setting errno. 14656 14657'``llvm.llround.*``' Intrinsic 14658^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14659 14660Syntax: 14661""""""" 14662 14663This is an overloaded intrinsic. You can use ``llvm.llround`` on any 14664floating-point type. Not all targets support all types however. 14665 14666:: 14667 14668 declare i64 @llvm.lround.i64.f32(float %Val) 14669 declare i64 @llvm.lround.i64.f64(double %Val) 14670 declare i64 @llvm.lround.i64.f80(float %Val) 14671 declare i64 @llvm.lround.i64.f128(double %Val) 14672 declare i64 @llvm.lround.i64.ppcf128(double %Val) 14673 14674Overview: 14675""""""""" 14676 14677The '``llvm.llround.*``' intrinsics return the operand rounded to the nearest 14678integer with ties away from zero. 14679 14680Arguments: 14681"""""""""" 14682 14683The argument is a floating-point number and the return value is an integer 14684type. 14685 14686Semantics: 14687"""""""""" 14688 14689This function returns the same values as the libm ``llround`` 14690functions would, but without setting errno. 14691 14692'``llvm.lrint.*``' Intrinsic 14693^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14694 14695Syntax: 14696""""""" 14697 14698This is an overloaded intrinsic. You can use ``llvm.lrint`` on any 14699floating-point type. Not all targets support all types however. 14700 14701:: 14702 14703 declare i32 @llvm.lrint.i32.f32(float %Val) 14704 declare i32 @llvm.lrint.i32.f64(double %Val) 14705 declare i32 @llvm.lrint.i32.f80(float %Val) 14706 declare i32 @llvm.lrint.i32.f128(double %Val) 14707 declare i32 @llvm.lrint.i32.ppcf128(double %Val) 14708 14709 declare i64 @llvm.lrint.i64.f32(float %Val) 14710 declare i64 @llvm.lrint.i64.f64(double %Val) 14711 declare i64 @llvm.lrint.i64.f80(float %Val) 14712 declare i64 @llvm.lrint.i64.f128(double %Val) 14713 declare i64 @llvm.lrint.i64.ppcf128(double %Val) 14714 14715Overview: 14716""""""""" 14717 14718The '``llvm.lrint.*``' intrinsics return the operand rounded to the nearest 14719integer. 14720 14721 14722Arguments: 14723"""""""""" 14724 14725The argument is a floating-point number and the return value is an integer 14726type. 14727 14728Semantics: 14729"""""""""" 14730 14731This function returns the same values as the libm ``lrint`` 14732functions would, but without setting errno. 14733 14734'``llvm.llrint.*``' Intrinsic 14735^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14736 14737Syntax: 14738""""""" 14739 14740This is an overloaded intrinsic. You can use ``llvm.llrint`` on any 14741floating-point type. Not all targets support all types however. 14742 14743:: 14744 14745 declare i64 @llvm.llrint.i64.f32(float %Val) 14746 declare i64 @llvm.llrint.i64.f64(double %Val) 14747 declare i64 @llvm.llrint.i64.f80(float %Val) 14748 declare i64 @llvm.llrint.i64.f128(double %Val) 14749 declare i64 @llvm.llrint.i64.ppcf128(double %Val) 14750 14751Overview: 14752""""""""" 14753 14754The '``llvm.llrint.*``' intrinsics return the operand rounded to the nearest 14755integer. 14756 14757Arguments: 14758"""""""""" 14759 14760The argument is a floating-point number and the return value is an integer 14761type. 14762 14763Semantics: 14764"""""""""" 14765 14766This function returns the same values as the libm ``llrint`` 14767functions would, but without setting errno. 14768 14769Bit Manipulation Intrinsics 14770--------------------------- 14771 14772LLVM provides intrinsics for a few important bit manipulation 14773operations. These allow efficient code generation for some algorithms. 14774 14775'``llvm.bitreverse.*``' Intrinsics 14776^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14777 14778Syntax: 14779""""""" 14780 14781This is an overloaded intrinsic function. You can use bitreverse on any 14782integer type. 14783 14784:: 14785 14786 declare i16 @llvm.bitreverse.i16(i16 <id>) 14787 declare i32 @llvm.bitreverse.i32(i32 <id>) 14788 declare i64 @llvm.bitreverse.i64(i64 <id>) 14789 declare <4 x i32> @llvm.bitreverse.v4i32(<4 x i32> <id>) 14790 14791Overview: 14792""""""""" 14793 14794The '``llvm.bitreverse``' family of intrinsics is used to reverse the 14795bitpattern of an integer value or vector of integer values; for example 14796``0b10110110`` becomes ``0b01101101``. 14797 14798Semantics: 14799"""""""""" 14800 14801The ``llvm.bitreverse.iN`` intrinsic returns an iN value that has bit 14802``M`` in the input moved to bit ``N-M`` in the output. The vector 14803intrinsics, such as ``llvm.bitreverse.v4i32``, operate on a per-element 14804basis and the element order is not affected. 14805 14806'``llvm.bswap.*``' Intrinsics 14807^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14808 14809Syntax: 14810""""""" 14811 14812This is an overloaded intrinsic function. You can use bswap on any 14813integer type that is an even number of bytes (i.e. BitWidth % 16 == 0). 14814 14815:: 14816 14817 declare i16 @llvm.bswap.i16(i16 <id>) 14818 declare i32 @llvm.bswap.i32(i32 <id>) 14819 declare i64 @llvm.bswap.i64(i64 <id>) 14820 declare <4 x i32> @llvm.bswap.v4i32(<4 x i32> <id>) 14821 14822Overview: 14823""""""""" 14824 14825The '``llvm.bswap``' family of intrinsics is used to byte swap an integer 14826value or vector of integer values with an even number of bytes (positive 14827multiple of 16 bits). 14828 14829Semantics: 14830"""""""""" 14831 14832The ``llvm.bswap.i16`` intrinsic returns an i16 value that has the high 14833and low byte of the input i16 swapped. Similarly, the ``llvm.bswap.i32`` 14834intrinsic returns an i32 value that has the four bytes of the input i32 14835swapped, so that if the input bytes are numbered 0, 1, 2, 3 then the 14836returned i32 will have its bytes in 3, 2, 1, 0 order. The 14837``llvm.bswap.i48``, ``llvm.bswap.i64`` and other intrinsics extend this 14838concept to additional even-byte lengths (6 bytes, 8 bytes and more, 14839respectively). The vector intrinsics, such as ``llvm.bswap.v4i32``, 14840operate on a per-element basis and the element order is not affected. 14841 14842'``llvm.ctpop.*``' Intrinsic 14843^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14844 14845Syntax: 14846""""""" 14847 14848This is an overloaded intrinsic. You can use llvm.ctpop on any integer 14849bit width, or on any vector with integer elements. Not all targets 14850support all bit widths or vector types, however. 14851 14852:: 14853 14854 declare i8 @llvm.ctpop.i8(i8 <src>) 14855 declare i16 @llvm.ctpop.i16(i16 <src>) 14856 declare i32 @llvm.ctpop.i32(i32 <src>) 14857 declare i64 @llvm.ctpop.i64(i64 <src>) 14858 declare i256 @llvm.ctpop.i256(i256 <src>) 14859 declare <2 x i32> @llvm.ctpop.v2i32(<2 x i32> <src>) 14860 14861Overview: 14862""""""""" 14863 14864The '``llvm.ctpop``' family of intrinsics counts the number of bits set 14865in a value. 14866 14867Arguments: 14868"""""""""" 14869 14870The only argument is the value to be counted. The argument may be of any 14871integer type, or a vector with integer elements. The return type must 14872match the argument type. 14873 14874Semantics: 14875"""""""""" 14876 14877The '``llvm.ctpop``' intrinsic counts the 1's in a variable, or within 14878each element of a vector. 14879 14880'``llvm.ctlz.*``' Intrinsic 14881^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14882 14883Syntax: 14884""""""" 14885 14886This is an overloaded intrinsic. You can use ``llvm.ctlz`` on any 14887integer bit width, or any vector whose elements are integers. Not all 14888targets support all bit widths or vector types, however. 14889 14890:: 14891 14892 declare i8 @llvm.ctlz.i8 (i8 <src>, i1 <is_zero_undef>) 14893 declare i16 @llvm.ctlz.i16 (i16 <src>, i1 <is_zero_undef>) 14894 declare i32 @llvm.ctlz.i32 (i32 <src>, i1 <is_zero_undef>) 14895 declare i64 @llvm.ctlz.i64 (i64 <src>, i1 <is_zero_undef>) 14896 declare i256 @llvm.ctlz.i256(i256 <src>, i1 <is_zero_undef>) 14897 declare <2 x i32> @llvm.ctlz.v2i32(<2 x i32> <src>, i1 <is_zero_undef>) 14898 14899Overview: 14900""""""""" 14901 14902The '``llvm.ctlz``' family of intrinsic functions counts the number of 14903leading zeros in a variable. 14904 14905Arguments: 14906"""""""""" 14907 14908The first argument is the value to be counted. This argument may be of 14909any integer type, or a vector with integer element type. The return 14910type must match the first argument type. 14911 14912The second argument must be a constant and is a flag to indicate whether 14913the intrinsic should ensure that a zero as the first argument produces a 14914defined result. Historically some architectures did not provide a 14915defined result for zero values as efficiently, and many algorithms are 14916now predicated on avoiding zero-value inputs. 14917 14918Semantics: 14919"""""""""" 14920 14921The '``llvm.ctlz``' intrinsic counts the leading (most significant) 14922zeros in a variable, or within each element of the vector. If 14923``src == 0`` then the result is the size in bits of the type of ``src`` 14924if ``is_zero_undef == 0`` and ``undef`` otherwise. For example, 14925``llvm.ctlz(i32 2) = 30``. 14926 14927'``llvm.cttz.*``' Intrinsic 14928^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14929 14930Syntax: 14931""""""" 14932 14933This is an overloaded intrinsic. You can use ``llvm.cttz`` on any 14934integer bit width, or any vector of integer elements. Not all targets 14935support all bit widths or vector types, however. 14936 14937:: 14938 14939 declare i8 @llvm.cttz.i8 (i8 <src>, i1 <is_zero_undef>) 14940 declare i16 @llvm.cttz.i16 (i16 <src>, i1 <is_zero_undef>) 14941 declare i32 @llvm.cttz.i32 (i32 <src>, i1 <is_zero_undef>) 14942 declare i64 @llvm.cttz.i64 (i64 <src>, i1 <is_zero_undef>) 14943 declare i256 @llvm.cttz.i256(i256 <src>, i1 <is_zero_undef>) 14944 declare <2 x i32> @llvm.cttz.v2i32(<2 x i32> <src>, i1 <is_zero_undef>) 14945 14946Overview: 14947""""""""" 14948 14949The '``llvm.cttz``' family of intrinsic functions counts the number of 14950trailing zeros. 14951 14952Arguments: 14953"""""""""" 14954 14955The first argument is the value to be counted. This argument may be of 14956any integer type, or a vector with integer element type. The return 14957type must match the first argument type. 14958 14959The second argument must be a constant and is a flag to indicate whether 14960the intrinsic should ensure that a zero as the first argument produces a 14961defined result. Historically some architectures did not provide a 14962defined result for zero values as efficiently, and many algorithms are 14963now predicated on avoiding zero-value inputs. 14964 14965Semantics: 14966"""""""""" 14967 14968The '``llvm.cttz``' intrinsic counts the trailing (least significant) 14969zeros in a variable, or within each element of a vector. If ``src == 0`` 14970then the result is the size in bits of the type of ``src`` if 14971``is_zero_undef == 0`` and ``undef`` otherwise. For example, 14972``llvm.cttz(2) = 1``. 14973 14974.. _int_overflow: 14975 14976'``llvm.fshl.*``' Intrinsic 14977^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14978 14979Syntax: 14980""""""" 14981 14982This is an overloaded intrinsic. You can use ``llvm.fshl`` on any 14983integer bit width or any vector of integer elements. Not all targets 14984support all bit widths or vector types, however. 14985 14986:: 14987 14988 declare i8 @llvm.fshl.i8 (i8 %a, i8 %b, i8 %c) 14989 declare i67 @llvm.fshl.i67(i67 %a, i67 %b, i67 %c) 14990 declare <2 x i32> @llvm.fshl.v2i32(<2 x i32> %a, <2 x i32> %b, <2 x i32> %c) 14991 14992Overview: 14993""""""""" 14994 14995The '``llvm.fshl``' family of intrinsic functions performs a funnel shift left: 14996the first two values are concatenated as { %a : %b } (%a is the most significant 14997bits of the wide value), the combined value is shifted left, and the most 14998significant bits are extracted to produce a result that is the same size as the 14999original arguments. If the first 2 arguments are identical, this is equivalent 15000to a rotate left operation. For vector types, the operation occurs for each 15001element of the vector. The shift argument is treated as an unsigned amount 15002modulo the element size of the arguments. 15003 15004Arguments: 15005"""""""""" 15006 15007The first two arguments are the values to be concatenated. The third 15008argument is the shift amount. The arguments may be any integer type or a 15009vector with integer element type. All arguments and the return value must 15010have the same type. 15011 15012Example: 15013"""""""" 15014 15015.. code-block:: text 15016 15017 %r = call i8 @llvm.fshl.i8(i8 %x, i8 %y, i8 %z) ; %r = i8: msb_extract((concat(x, y) << (z % 8)), 8) 15018 %r = call i8 @llvm.fshl.i8(i8 255, i8 0, i8 15) ; %r = i8: 128 (0b10000000) 15019 %r = call i8 @llvm.fshl.i8(i8 15, i8 15, i8 11) ; %r = i8: 120 (0b01111000) 15020 %r = call i8 @llvm.fshl.i8(i8 0, i8 255, i8 8) ; %r = i8: 0 (0b00000000) 15021 15022'``llvm.fshr.*``' Intrinsic 15023^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15024 15025Syntax: 15026""""""" 15027 15028This is an overloaded intrinsic. You can use ``llvm.fshr`` on any 15029integer bit width or any vector of integer elements. Not all targets 15030support all bit widths or vector types, however. 15031 15032:: 15033 15034 declare i8 @llvm.fshr.i8 (i8 %a, i8 %b, i8 %c) 15035 declare i67 @llvm.fshr.i67(i67 %a, i67 %b, i67 %c) 15036 declare <2 x i32> @llvm.fshr.v2i32(<2 x i32> %a, <2 x i32> %b, <2 x i32> %c) 15037 15038Overview: 15039""""""""" 15040 15041The '``llvm.fshr``' family of intrinsic functions performs a funnel shift right: 15042the first two values are concatenated as { %a : %b } (%a is the most significant 15043bits of the wide value), the combined value is shifted right, and the least 15044significant bits are extracted to produce a result that is the same size as the 15045original arguments. If the first 2 arguments are identical, this is equivalent 15046to a rotate right operation. For vector types, the operation occurs for each 15047element of the vector. The shift argument is treated as an unsigned amount 15048modulo the element size of the arguments. 15049 15050Arguments: 15051"""""""""" 15052 15053The first two arguments are the values to be concatenated. The third 15054argument is the shift amount. The arguments may be any integer type or a 15055vector with integer element type. All arguments and the return value must 15056have the same type. 15057 15058Example: 15059"""""""" 15060 15061.. code-block:: text 15062 15063 %r = call i8 @llvm.fshr.i8(i8 %x, i8 %y, i8 %z) ; %r = i8: lsb_extract((concat(x, y) >> (z % 8)), 8) 15064 %r = call i8 @llvm.fshr.i8(i8 255, i8 0, i8 15) ; %r = i8: 254 (0b11111110) 15065 %r = call i8 @llvm.fshr.i8(i8 15, i8 15, i8 11) ; %r = i8: 225 (0b11100001) 15066 %r = call i8 @llvm.fshr.i8(i8 0, i8 255, i8 8) ; %r = i8: 255 (0b11111111) 15067 15068Arithmetic with Overflow Intrinsics 15069----------------------------------- 15070 15071LLVM provides intrinsics for fast arithmetic overflow checking. 15072 15073Each of these intrinsics returns a two-element struct. The first 15074element of this struct contains the result of the corresponding 15075arithmetic operation modulo 2\ :sup:`n`\ , where n is the bit width of 15076the result. Therefore, for example, the first element of the struct 15077returned by ``llvm.sadd.with.overflow.i32`` is always the same as the 15078result of a 32-bit ``add`` instruction with the same operands, where 15079the ``add`` is *not* modified by an ``nsw`` or ``nuw`` flag. 15080 15081The second element of the result is an ``i1`` that is 1 if the 15082arithmetic operation overflowed and 0 otherwise. An operation 15083overflows if, for any values of its operands ``A`` and ``B`` and for 15084any ``N`` larger than the operands' width, ``ext(A op B) to iN`` is 15085not equal to ``(ext(A) to iN) op (ext(B) to iN)`` where ``ext`` is 15086``sext`` for signed overflow and ``zext`` for unsigned overflow, and 15087``op`` is the underlying arithmetic operation. 15088 15089The behavior of these intrinsics is well-defined for all argument 15090values. 15091 15092'``llvm.sadd.with.overflow.*``' Intrinsics 15093^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15094 15095Syntax: 15096""""""" 15097 15098This is an overloaded intrinsic. You can use ``llvm.sadd.with.overflow`` 15099on any integer bit width or vectors of integers. 15100 15101:: 15102 15103 declare {i16, i1} @llvm.sadd.with.overflow.i16(i16 %a, i16 %b) 15104 declare {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b) 15105 declare {i64, i1} @llvm.sadd.with.overflow.i64(i64 %a, i64 %b) 15106 declare {<4 x i32>, <4 x i1>} @llvm.sadd.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b) 15107 15108Overview: 15109""""""""" 15110 15111The '``llvm.sadd.with.overflow``' family of intrinsic functions perform 15112a signed addition of the two arguments, and indicate whether an overflow 15113occurred during the signed summation. 15114 15115Arguments: 15116"""""""""" 15117 15118The arguments (%a and %b) and the first element of the result structure 15119may be of integer types of any bit width, but they must have the same 15120bit width. The second element of the result structure must be of type 15121``i1``. ``%a`` and ``%b`` are the two values that will undergo signed 15122addition. 15123 15124Semantics: 15125"""""""""" 15126 15127The '``llvm.sadd.with.overflow``' family of intrinsic functions perform 15128a signed addition of the two variables. They return a structure --- the 15129first element of which is the signed summation, and the second element 15130of which is a bit specifying if the signed summation resulted in an 15131overflow. 15132 15133Examples: 15134""""""""" 15135 15136.. code-block:: llvm 15137 15138 %res = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b) 15139 %sum = extractvalue {i32, i1} %res, 0 15140 %obit = extractvalue {i32, i1} %res, 1 15141 br i1 %obit, label %overflow, label %normal 15142 15143'``llvm.uadd.with.overflow.*``' Intrinsics 15144^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15145 15146Syntax: 15147""""""" 15148 15149This is an overloaded intrinsic. You can use ``llvm.uadd.with.overflow`` 15150on any integer bit width or vectors of integers. 15151 15152:: 15153 15154 declare {i16, i1} @llvm.uadd.with.overflow.i16(i16 %a, i16 %b) 15155 declare {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b) 15156 declare {i64, i1} @llvm.uadd.with.overflow.i64(i64 %a, i64 %b) 15157 declare {<4 x i32>, <4 x i1>} @llvm.uadd.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b) 15158 15159Overview: 15160""""""""" 15161 15162The '``llvm.uadd.with.overflow``' family of intrinsic functions perform 15163an unsigned addition of the two arguments, and indicate whether a carry 15164occurred during the unsigned summation. 15165 15166Arguments: 15167"""""""""" 15168 15169The arguments (%a and %b) and the first element of the result structure 15170may be of integer types of any bit width, but they must have the same 15171bit width. The second element of the result structure must be of type 15172``i1``. ``%a`` and ``%b`` are the two values that will undergo unsigned 15173addition. 15174 15175Semantics: 15176"""""""""" 15177 15178The '``llvm.uadd.with.overflow``' family of intrinsic functions perform 15179an unsigned addition of the two arguments. They return a structure --- the 15180first element of which is the sum, and the second element of which is a 15181bit specifying if the unsigned summation resulted in a carry. 15182 15183Examples: 15184""""""""" 15185 15186.. code-block:: llvm 15187 15188 %res = call {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b) 15189 %sum = extractvalue {i32, i1} %res, 0 15190 %obit = extractvalue {i32, i1} %res, 1 15191 br i1 %obit, label %carry, label %normal 15192 15193'``llvm.ssub.with.overflow.*``' Intrinsics 15194^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15195 15196Syntax: 15197""""""" 15198 15199This is an overloaded intrinsic. You can use ``llvm.ssub.with.overflow`` 15200on any integer bit width or vectors of integers. 15201 15202:: 15203 15204 declare {i16, i1} @llvm.ssub.with.overflow.i16(i16 %a, i16 %b) 15205 declare {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a, i32 %b) 15206 declare {i64, i1} @llvm.ssub.with.overflow.i64(i64 %a, i64 %b) 15207 declare {<4 x i32>, <4 x i1>} @llvm.ssub.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b) 15208 15209Overview: 15210""""""""" 15211 15212The '``llvm.ssub.with.overflow``' family of intrinsic functions perform 15213a signed subtraction of the two arguments, and indicate whether an 15214overflow occurred during the signed subtraction. 15215 15216Arguments: 15217"""""""""" 15218 15219The arguments (%a and %b) and the first element of the result structure 15220may be of integer types of any bit width, but they must have the same 15221bit width. The second element of the result structure must be of type 15222``i1``. ``%a`` and ``%b`` are the two values that will undergo signed 15223subtraction. 15224 15225Semantics: 15226"""""""""" 15227 15228The '``llvm.ssub.with.overflow``' family of intrinsic functions perform 15229a signed subtraction of the two arguments. They return a structure --- the 15230first element of which is the subtraction, and the second element of 15231which is a bit specifying if the signed subtraction resulted in an 15232overflow. 15233 15234Examples: 15235""""""""" 15236 15237.. code-block:: llvm 15238 15239 %res = call {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a, i32 %b) 15240 %sum = extractvalue {i32, i1} %res, 0 15241 %obit = extractvalue {i32, i1} %res, 1 15242 br i1 %obit, label %overflow, label %normal 15243 15244'``llvm.usub.with.overflow.*``' Intrinsics 15245^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15246 15247Syntax: 15248""""""" 15249 15250This is an overloaded intrinsic. You can use ``llvm.usub.with.overflow`` 15251on any integer bit width or vectors of integers. 15252 15253:: 15254 15255 declare {i16, i1} @llvm.usub.with.overflow.i16(i16 %a, i16 %b) 15256 declare {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b) 15257 declare {i64, i1} @llvm.usub.with.overflow.i64(i64 %a, i64 %b) 15258 declare {<4 x i32>, <4 x i1>} @llvm.usub.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b) 15259 15260Overview: 15261""""""""" 15262 15263The '``llvm.usub.with.overflow``' family of intrinsic functions perform 15264an unsigned subtraction of the two arguments, and indicate whether an 15265overflow occurred during the unsigned subtraction. 15266 15267Arguments: 15268"""""""""" 15269 15270The arguments (%a and %b) and the first element of the result structure 15271may be of integer types of any bit width, but they must have the same 15272bit width. The second element of the result structure must be of type 15273``i1``. ``%a`` and ``%b`` are the two values that will undergo unsigned 15274subtraction. 15275 15276Semantics: 15277"""""""""" 15278 15279The '``llvm.usub.with.overflow``' family of intrinsic functions perform 15280an unsigned subtraction of the two arguments. They return a structure --- 15281the first element of which is the subtraction, and the second element of 15282which is a bit specifying if the unsigned subtraction resulted in an 15283overflow. 15284 15285Examples: 15286""""""""" 15287 15288.. code-block:: llvm 15289 15290 %res = call {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b) 15291 %sum = extractvalue {i32, i1} %res, 0 15292 %obit = extractvalue {i32, i1} %res, 1 15293 br i1 %obit, label %overflow, label %normal 15294 15295'``llvm.smul.with.overflow.*``' Intrinsics 15296^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15297 15298Syntax: 15299""""""" 15300 15301This is an overloaded intrinsic. You can use ``llvm.smul.with.overflow`` 15302on any integer bit width or vectors of integers. 15303 15304:: 15305 15306 declare {i16, i1} @llvm.smul.with.overflow.i16(i16 %a, i16 %b) 15307 declare {i32, i1} @llvm.smul.with.overflow.i32(i32 %a, i32 %b) 15308 declare {i64, i1} @llvm.smul.with.overflow.i64(i64 %a, i64 %b) 15309 declare {<4 x i32>, <4 x i1>} @llvm.smul.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b) 15310 15311Overview: 15312""""""""" 15313 15314The '``llvm.smul.with.overflow``' family of intrinsic functions perform 15315a signed multiplication of the two arguments, and indicate whether an 15316overflow occurred during the signed multiplication. 15317 15318Arguments: 15319"""""""""" 15320 15321The arguments (%a and %b) and the first element of the result structure 15322may be of integer types of any bit width, but they must have the same 15323bit width. The second element of the result structure must be of type 15324``i1``. ``%a`` and ``%b`` are the two values that will undergo signed 15325multiplication. 15326 15327Semantics: 15328"""""""""" 15329 15330The '``llvm.smul.with.overflow``' family of intrinsic functions perform 15331a signed multiplication of the two arguments. They return a structure --- 15332the first element of which is the multiplication, and the second element 15333of which is a bit specifying if the signed multiplication resulted in an 15334overflow. 15335 15336Examples: 15337""""""""" 15338 15339.. code-block:: llvm 15340 15341 %res = call {i32, i1} @llvm.smul.with.overflow.i32(i32 %a, i32 %b) 15342 %sum = extractvalue {i32, i1} %res, 0 15343 %obit = extractvalue {i32, i1} %res, 1 15344 br i1 %obit, label %overflow, label %normal 15345 15346'``llvm.umul.with.overflow.*``' Intrinsics 15347^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15348 15349Syntax: 15350""""""" 15351 15352This is an overloaded intrinsic. You can use ``llvm.umul.with.overflow`` 15353on any integer bit width or vectors of integers. 15354 15355:: 15356 15357 declare {i16, i1} @llvm.umul.with.overflow.i16(i16 %a, i16 %b) 15358 declare {i32, i1} @llvm.umul.with.overflow.i32(i32 %a, i32 %b) 15359 declare {i64, i1} @llvm.umul.with.overflow.i64(i64 %a, i64 %b) 15360 declare {<4 x i32>, <4 x i1>} @llvm.umul.with.overflow.v4i32(<4 x i32> %a, <4 x i32> %b) 15361 15362Overview: 15363""""""""" 15364 15365The '``llvm.umul.with.overflow``' family of intrinsic functions perform 15366a unsigned multiplication of the two arguments, and indicate whether an 15367overflow occurred during the unsigned multiplication. 15368 15369Arguments: 15370"""""""""" 15371 15372The arguments (%a and %b) and the first element of the result structure 15373may be of integer types of any bit width, but they must have the same 15374bit width. The second element of the result structure must be of type 15375``i1``. ``%a`` and ``%b`` are the two values that will undergo unsigned 15376multiplication. 15377 15378Semantics: 15379"""""""""" 15380 15381The '``llvm.umul.with.overflow``' family of intrinsic functions perform 15382an unsigned multiplication of the two arguments. They return a structure --- 15383the first element of which is the multiplication, and the second 15384element of which is a bit specifying if the unsigned multiplication 15385resulted in an overflow. 15386 15387Examples: 15388""""""""" 15389 15390.. code-block:: llvm 15391 15392 %res = call {i32, i1} @llvm.umul.with.overflow.i32(i32 %a, i32 %b) 15393 %sum = extractvalue {i32, i1} %res, 0 15394 %obit = extractvalue {i32, i1} %res, 1 15395 br i1 %obit, label %overflow, label %normal 15396 15397Saturation Arithmetic Intrinsics 15398--------------------------------- 15399 15400Saturation arithmetic is a version of arithmetic in which operations are 15401limited to a fixed range between a minimum and maximum value. If the result of 15402an operation is greater than the maximum value, the result is set (or 15403"clamped") to this maximum. If it is below the minimum, it is clamped to this 15404minimum. 15405 15406 15407'``llvm.sadd.sat.*``' Intrinsics 15408^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15409 15410Syntax 15411""""""" 15412 15413This is an overloaded intrinsic. You can use ``llvm.sadd.sat`` 15414on any integer bit width or vectors of integers. 15415 15416:: 15417 15418 declare i16 @llvm.sadd.sat.i16(i16 %a, i16 %b) 15419 declare i32 @llvm.sadd.sat.i32(i32 %a, i32 %b) 15420 declare i64 @llvm.sadd.sat.i64(i64 %a, i64 %b) 15421 declare <4 x i32> @llvm.sadd.sat.v4i32(<4 x i32> %a, <4 x i32> %b) 15422 15423Overview 15424""""""""" 15425 15426The '``llvm.sadd.sat``' family of intrinsic functions perform signed 15427saturating addition on the 2 arguments. 15428 15429Arguments 15430"""""""""" 15431 15432The arguments (%a and %b) and the result may be of integer types of any bit 15433width, but they must have the same bit width. ``%a`` and ``%b`` are the two 15434values that will undergo signed addition. 15435 15436Semantics: 15437"""""""""" 15438 15439The maximum value this operation can clamp to is the largest signed value 15440representable by the bit width of the arguments. The minimum value is the 15441smallest signed value representable by this bit width. 15442 15443 15444Examples 15445""""""""" 15446 15447.. code-block:: llvm 15448 15449 %res = call i4 @llvm.sadd.sat.i4(i4 1, i4 2) ; %res = 3 15450 %res = call i4 @llvm.sadd.sat.i4(i4 5, i4 6) ; %res = 7 15451 %res = call i4 @llvm.sadd.sat.i4(i4 -4, i4 2) ; %res = -2 15452 %res = call i4 @llvm.sadd.sat.i4(i4 -4, i4 -5) ; %res = -8 15453 15454 15455'``llvm.uadd.sat.*``' Intrinsics 15456^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15457 15458Syntax 15459""""""" 15460 15461This is an overloaded intrinsic. You can use ``llvm.uadd.sat`` 15462on any integer bit width or vectors of integers. 15463 15464:: 15465 15466 declare i16 @llvm.uadd.sat.i16(i16 %a, i16 %b) 15467 declare i32 @llvm.uadd.sat.i32(i32 %a, i32 %b) 15468 declare i64 @llvm.uadd.sat.i64(i64 %a, i64 %b) 15469 declare <4 x i32> @llvm.uadd.sat.v4i32(<4 x i32> %a, <4 x i32> %b) 15470 15471Overview 15472""""""""" 15473 15474The '``llvm.uadd.sat``' family of intrinsic functions perform unsigned 15475saturating addition on the 2 arguments. 15476 15477Arguments 15478"""""""""" 15479 15480The arguments (%a and %b) and the result may be of integer types of any bit 15481width, but they must have the same bit width. ``%a`` and ``%b`` are the two 15482values that will undergo unsigned addition. 15483 15484Semantics: 15485"""""""""" 15486 15487The maximum value this operation can clamp to is the largest unsigned value 15488representable by the bit width of the arguments. Because this is an unsigned 15489operation, the result will never saturate towards zero. 15490 15491 15492Examples 15493""""""""" 15494 15495.. code-block:: llvm 15496 15497 %res = call i4 @llvm.uadd.sat.i4(i4 1, i4 2) ; %res = 3 15498 %res = call i4 @llvm.uadd.sat.i4(i4 5, i4 6) ; %res = 11 15499 %res = call i4 @llvm.uadd.sat.i4(i4 8, i4 8) ; %res = 15 15500 15501 15502'``llvm.ssub.sat.*``' Intrinsics 15503^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15504 15505Syntax 15506""""""" 15507 15508This is an overloaded intrinsic. You can use ``llvm.ssub.sat`` 15509on any integer bit width or vectors of integers. 15510 15511:: 15512 15513 declare i16 @llvm.ssub.sat.i16(i16 %a, i16 %b) 15514 declare i32 @llvm.ssub.sat.i32(i32 %a, i32 %b) 15515 declare i64 @llvm.ssub.sat.i64(i64 %a, i64 %b) 15516 declare <4 x i32> @llvm.ssub.sat.v4i32(<4 x i32> %a, <4 x i32> %b) 15517 15518Overview 15519""""""""" 15520 15521The '``llvm.ssub.sat``' family of intrinsic functions perform signed 15522saturating subtraction on the 2 arguments. 15523 15524Arguments 15525"""""""""" 15526 15527The arguments (%a and %b) and the result may be of integer types of any bit 15528width, but they must have the same bit width. ``%a`` and ``%b`` are the two 15529values that will undergo signed subtraction. 15530 15531Semantics: 15532"""""""""" 15533 15534The maximum value this operation can clamp to is the largest signed value 15535representable by the bit width of the arguments. The minimum value is the 15536smallest signed value representable by this bit width. 15537 15538 15539Examples 15540""""""""" 15541 15542.. code-block:: llvm 15543 15544 %res = call i4 @llvm.ssub.sat.i4(i4 2, i4 1) ; %res = 1 15545 %res = call i4 @llvm.ssub.sat.i4(i4 2, i4 6) ; %res = -4 15546 %res = call i4 @llvm.ssub.sat.i4(i4 -4, i4 5) ; %res = -8 15547 %res = call i4 @llvm.ssub.sat.i4(i4 4, i4 -5) ; %res = 7 15548 15549 15550'``llvm.usub.sat.*``' Intrinsics 15551^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15552 15553Syntax 15554""""""" 15555 15556This is an overloaded intrinsic. You can use ``llvm.usub.sat`` 15557on any integer bit width or vectors of integers. 15558 15559:: 15560 15561 declare i16 @llvm.usub.sat.i16(i16 %a, i16 %b) 15562 declare i32 @llvm.usub.sat.i32(i32 %a, i32 %b) 15563 declare i64 @llvm.usub.sat.i64(i64 %a, i64 %b) 15564 declare <4 x i32> @llvm.usub.sat.v4i32(<4 x i32> %a, <4 x i32> %b) 15565 15566Overview 15567""""""""" 15568 15569The '``llvm.usub.sat``' family of intrinsic functions perform unsigned 15570saturating subtraction on the 2 arguments. 15571 15572Arguments 15573"""""""""" 15574 15575The arguments (%a and %b) and the result may be of integer types of any bit 15576width, but they must have the same bit width. ``%a`` and ``%b`` are the two 15577values that will undergo unsigned subtraction. 15578 15579Semantics: 15580"""""""""" 15581 15582The minimum value this operation can clamp to is 0, which is the smallest 15583unsigned value representable by the bit width of the unsigned arguments. 15584Because this is an unsigned operation, the result will never saturate towards 15585the largest possible value representable by this bit width. 15586 15587 15588Examples 15589""""""""" 15590 15591.. code-block:: llvm 15592 15593 %res = call i4 @llvm.usub.sat.i4(i4 2, i4 1) ; %res = 1 15594 %res = call i4 @llvm.usub.sat.i4(i4 2, i4 6) ; %res = 0 15595 15596 15597'``llvm.sshl.sat.*``' Intrinsics 15598^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15599 15600Syntax 15601""""""" 15602 15603This is an overloaded intrinsic. You can use ``llvm.sshl.sat`` 15604on integers or vectors of integers of any bit width. 15605 15606:: 15607 15608 declare i16 @llvm.sshl.sat.i16(i16 %a, i16 %b) 15609 declare i32 @llvm.sshl.sat.i32(i32 %a, i32 %b) 15610 declare i64 @llvm.sshl.sat.i64(i64 %a, i64 %b) 15611 declare <4 x i32> @llvm.sshl.sat.v4i32(<4 x i32> %a, <4 x i32> %b) 15612 15613Overview 15614""""""""" 15615 15616The '``llvm.sshl.sat``' family of intrinsic functions perform signed 15617saturating left shift on the first argument. 15618 15619Arguments 15620"""""""""" 15621 15622The arguments (``%a`` and ``%b``) and the result may be of integer types of any 15623bit width, but they must have the same bit width. ``%a`` is the value to be 15624shifted, and ``%b`` is the amount to shift by. If ``b`` is (statically or 15625dynamically) equal to or larger than the integer bit width of the arguments, 15626the result is a :ref:`poison value <poisonvalues>`. If the arguments are 15627vectors, each vector element of ``a`` is shifted by the corresponding shift 15628amount in ``b``. 15629 15630 15631Semantics: 15632"""""""""" 15633 15634The maximum value this operation can clamp to is the largest signed value 15635representable by the bit width of the arguments. The minimum value is the 15636smallest signed value representable by this bit width. 15637 15638 15639Examples 15640""""""""" 15641 15642.. code-block:: llvm 15643 15644 %res = call i4 @llvm.sshl.sat.i4(i4 2, i4 1) ; %res = 4 15645 %res = call i4 @llvm.sshl.sat.i4(i4 2, i4 2) ; %res = 7 15646 %res = call i4 @llvm.sshl.sat.i4(i4 -5, i4 1) ; %res = -8 15647 %res = call i4 @llvm.sshl.sat.i4(i4 -1, i4 1) ; %res = -2 15648 15649 15650'``llvm.ushl.sat.*``' Intrinsics 15651^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15652 15653Syntax 15654""""""" 15655 15656This is an overloaded intrinsic. You can use ``llvm.ushl.sat`` 15657on integers or vectors of integers of any bit width. 15658 15659:: 15660 15661 declare i16 @llvm.ushl.sat.i16(i16 %a, i16 %b) 15662 declare i32 @llvm.ushl.sat.i32(i32 %a, i32 %b) 15663 declare i64 @llvm.ushl.sat.i64(i64 %a, i64 %b) 15664 declare <4 x i32> @llvm.ushl.sat.v4i32(<4 x i32> %a, <4 x i32> %b) 15665 15666Overview 15667""""""""" 15668 15669The '``llvm.ushl.sat``' family of intrinsic functions perform unsigned 15670saturating left shift on the first argument. 15671 15672Arguments 15673"""""""""" 15674 15675The arguments (``%a`` and ``%b``) and the result may be of integer types of any 15676bit width, but they must have the same bit width. ``%a`` is the value to be 15677shifted, and ``%b`` is the amount to shift by. If ``b`` is (statically or 15678dynamically) equal to or larger than the integer bit width of the arguments, 15679the result is a :ref:`poison value <poisonvalues>`. If the arguments are 15680vectors, each vector element of ``a`` is shifted by the corresponding shift 15681amount in ``b``. 15682 15683Semantics: 15684"""""""""" 15685 15686The maximum value this operation can clamp to is the largest unsigned value 15687representable by the bit width of the arguments. 15688 15689 15690Examples 15691""""""""" 15692 15693.. code-block:: llvm 15694 15695 %res = call i4 @llvm.ushl.sat.i4(i4 2, i4 1) ; %res = 4 15696 %res = call i4 @llvm.ushl.sat.i4(i4 3, i4 3) ; %res = 15 15697 15698 15699Fixed Point Arithmetic Intrinsics 15700--------------------------------- 15701 15702A fixed point number represents a real data type for a number that has a fixed 15703number of digits after a radix point (equivalent to the decimal point '.'). 15704The number of digits after the radix point is referred as the `scale`. These 15705are useful for representing fractional values to a specific precision. The 15706following intrinsics perform fixed point arithmetic operations on 2 operands 15707of the same scale, specified as the third argument. 15708 15709The ``llvm.*mul.fix`` family of intrinsic functions represents a multiplication 15710of fixed point numbers through scaled integers. Therefore, fixed point 15711multiplication can be represented as 15712 15713.. code-block:: llvm 15714 15715 %result = call i4 @llvm.smul.fix.i4(i4 %a, i4 %b, i32 %scale) 15716 15717 ; Expands to 15718 %a2 = sext i4 %a to i8 15719 %b2 = sext i4 %b to i8 15720 %mul = mul nsw nuw i8 %a, %b 15721 %scale2 = trunc i32 %scale to i8 15722 %r = ashr i8 %mul, i8 %scale2 ; this is for a target rounding down towards negative infinity 15723 %result = trunc i8 %r to i4 15724 15725The ``llvm.*div.fix`` family of intrinsic functions represents a division of 15726fixed point numbers through scaled integers. Fixed point division can be 15727represented as: 15728 15729.. code-block:: llvm 15730 15731 %result call i4 @llvm.sdiv.fix.i4(i4 %a, i4 %b, i32 %scale) 15732 15733 ; Expands to 15734 %a2 = sext i4 %a to i8 15735 %b2 = sext i4 %b to i8 15736 %scale2 = trunc i32 %scale to i8 15737 %a3 = shl i8 %a2, %scale2 15738 %r = sdiv i8 %a3, %b2 ; this is for a target rounding towards zero 15739 %result = trunc i8 %r to i4 15740 15741For each of these functions, if the result cannot be represented exactly with 15742the provided scale, the result is rounded. Rounding is unspecified since 15743preferred rounding may vary for different targets. Rounding is specified 15744through a target hook. Different pipelines should legalize or optimize this 15745using the rounding specified by this hook if it is provided. Operations like 15746constant folding, instruction combining, KnownBits, and ValueTracking should 15747also use this hook, if provided, and not assume the direction of rounding. A 15748rounded result must always be within one unit of precision from the true 15749result. That is, the error between the returned result and the true result must 15750be less than 1/2^(scale). 15751 15752 15753'``llvm.smul.fix.*``' Intrinsics 15754^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15755 15756Syntax 15757""""""" 15758 15759This is an overloaded intrinsic. You can use ``llvm.smul.fix`` 15760on any integer bit width or vectors of integers. 15761 15762:: 15763 15764 declare i16 @llvm.smul.fix.i16(i16 %a, i16 %b, i32 %scale) 15765 declare i32 @llvm.smul.fix.i32(i32 %a, i32 %b, i32 %scale) 15766 declare i64 @llvm.smul.fix.i64(i64 %a, i64 %b, i32 %scale) 15767 declare <4 x i32> @llvm.smul.fix.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale) 15768 15769Overview 15770""""""""" 15771 15772The '``llvm.smul.fix``' family of intrinsic functions perform signed 15773fixed point multiplication on 2 arguments of the same scale. 15774 15775Arguments 15776"""""""""" 15777 15778The arguments (%a and %b) and the result may be of integer types of any bit 15779width, but they must have the same bit width. The arguments may also work with 15780int vectors of the same length and int size. ``%a`` and ``%b`` are the two 15781values that will undergo signed fixed point multiplication. The argument 15782``%scale`` represents the scale of both operands, and must be a constant 15783integer. 15784 15785Semantics: 15786"""""""""" 15787 15788This operation performs fixed point multiplication on the 2 arguments of a 15789specified scale. The result will also be returned in the same scale specified 15790in the third argument. 15791 15792If the result value cannot be precisely represented in the given scale, the 15793value is rounded up or down to the closest representable value. The rounding 15794direction is unspecified. 15795 15796It is undefined behavior if the result value does not fit within the range of 15797the fixed point type. 15798 15799 15800Examples 15801""""""""" 15802 15803.. code-block:: llvm 15804 15805 %res = call i4 @llvm.smul.fix.i4(i4 3, i4 2, i32 0) ; %res = 6 (2 x 3 = 6) 15806 %res = call i4 @llvm.smul.fix.i4(i4 3, i4 2, i32 1) ; %res = 3 (1.5 x 1 = 1.5) 15807 %res = call i4 @llvm.smul.fix.i4(i4 3, i4 -2, i32 1) ; %res = -3 (1.5 x -1 = -1.5) 15808 15809 ; The result in the following could be rounded up to -2 or down to -2.5 15810 %res = call i4 @llvm.smul.fix.i4(i4 3, i4 -3, i32 1) ; %res = -5 (or -4) (1.5 x -1.5 = -2.25) 15811 15812 15813'``llvm.umul.fix.*``' Intrinsics 15814^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15815 15816Syntax 15817""""""" 15818 15819This is an overloaded intrinsic. You can use ``llvm.umul.fix`` 15820on any integer bit width or vectors of integers. 15821 15822:: 15823 15824 declare i16 @llvm.umul.fix.i16(i16 %a, i16 %b, i32 %scale) 15825 declare i32 @llvm.umul.fix.i32(i32 %a, i32 %b, i32 %scale) 15826 declare i64 @llvm.umul.fix.i64(i64 %a, i64 %b, i32 %scale) 15827 declare <4 x i32> @llvm.umul.fix.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale) 15828 15829Overview 15830""""""""" 15831 15832The '``llvm.umul.fix``' family of intrinsic functions perform unsigned 15833fixed point multiplication on 2 arguments of the same scale. 15834 15835Arguments 15836"""""""""" 15837 15838The arguments (%a and %b) and the result may be of integer types of any bit 15839width, but they must have the same bit width. The arguments may also work with 15840int vectors of the same length and int size. ``%a`` and ``%b`` are the two 15841values that will undergo unsigned fixed point multiplication. The argument 15842``%scale`` represents the scale of both operands, and must be a constant 15843integer. 15844 15845Semantics: 15846"""""""""" 15847 15848This operation performs unsigned fixed point multiplication on the 2 arguments of a 15849specified scale. The result will also be returned in the same scale specified 15850in the third argument. 15851 15852If the result value cannot be precisely represented in the given scale, the 15853value is rounded up or down to the closest representable value. The rounding 15854direction is unspecified. 15855 15856It is undefined behavior if the result value does not fit within the range of 15857the fixed point type. 15858 15859 15860Examples 15861""""""""" 15862 15863.. code-block:: llvm 15864 15865 %res = call i4 @llvm.umul.fix.i4(i4 3, i4 2, i32 0) ; %res = 6 (2 x 3 = 6) 15866 %res = call i4 @llvm.umul.fix.i4(i4 3, i4 2, i32 1) ; %res = 3 (1.5 x 1 = 1.5) 15867 15868 ; The result in the following could be rounded down to 3.5 or up to 4 15869 %res = call i4 @llvm.umul.fix.i4(i4 15, i4 1, i32 1) ; %res = 7 (or 8) (7.5 x 0.5 = 3.75) 15870 15871 15872'``llvm.smul.fix.sat.*``' Intrinsics 15873^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15874 15875Syntax 15876""""""" 15877 15878This is an overloaded intrinsic. You can use ``llvm.smul.fix.sat`` 15879on any integer bit width or vectors of integers. 15880 15881:: 15882 15883 declare i16 @llvm.smul.fix.sat.i16(i16 %a, i16 %b, i32 %scale) 15884 declare i32 @llvm.smul.fix.sat.i32(i32 %a, i32 %b, i32 %scale) 15885 declare i64 @llvm.smul.fix.sat.i64(i64 %a, i64 %b, i32 %scale) 15886 declare <4 x i32> @llvm.smul.fix.sat.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale) 15887 15888Overview 15889""""""""" 15890 15891The '``llvm.smul.fix.sat``' family of intrinsic functions perform signed 15892fixed point saturating multiplication on 2 arguments of the same scale. 15893 15894Arguments 15895"""""""""" 15896 15897The arguments (%a and %b) and the result may be of integer types of any bit 15898width, but they must have the same bit width. ``%a`` and ``%b`` are the two 15899values that will undergo signed fixed point multiplication. The argument 15900``%scale`` represents the scale of both operands, and must be a constant 15901integer. 15902 15903Semantics: 15904"""""""""" 15905 15906This operation performs fixed point multiplication on the 2 arguments of a 15907specified scale. The result will also be returned in the same scale specified 15908in the third argument. 15909 15910If the result value cannot be precisely represented in the given scale, the 15911value is rounded up or down to the closest representable value. The rounding 15912direction is unspecified. 15913 15914The maximum value this operation can clamp to is the largest signed value 15915representable by the bit width of the first 2 arguments. The minimum value is the 15916smallest signed value representable by this bit width. 15917 15918 15919Examples 15920""""""""" 15921 15922.. code-block:: llvm 15923 15924 %res = call i4 @llvm.smul.fix.sat.i4(i4 3, i4 2, i32 0) ; %res = 6 (2 x 3 = 6) 15925 %res = call i4 @llvm.smul.fix.sat.i4(i4 3, i4 2, i32 1) ; %res = 3 (1.5 x 1 = 1.5) 15926 %res = call i4 @llvm.smul.fix.sat.i4(i4 3, i4 -2, i32 1) ; %res = -3 (1.5 x -1 = -1.5) 15927 15928 ; The result in the following could be rounded up to -2 or down to -2.5 15929 %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) 15930 15931 ; Saturation 15932 %res = call i4 @llvm.smul.fix.sat.i4(i4 7, i4 2, i32 0) ; %res = 7 15933 %res = call i4 @llvm.smul.fix.sat.i4(i4 7, i4 4, i32 2) ; %res = 7 15934 %res = call i4 @llvm.smul.fix.sat.i4(i4 -8, i4 5, i32 2) ; %res = -8 15935 %res = call i4 @llvm.smul.fix.sat.i4(i4 -8, i4 -2, i32 1) ; %res = 7 15936 15937 ; Scale can affect the saturation result 15938 %res = call i4 @llvm.smul.fix.sat.i4(i4 2, i4 4, i32 0) ; %res = 7 (2 x 4 -> clamped to 7) 15939 %res = call i4 @llvm.smul.fix.sat.i4(i4 2, i4 4, i32 1) ; %res = 4 (1 x 2 = 2) 15940 15941 15942'``llvm.umul.fix.sat.*``' Intrinsics 15943^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15944 15945Syntax 15946""""""" 15947 15948This is an overloaded intrinsic. You can use ``llvm.umul.fix.sat`` 15949on any integer bit width or vectors of integers. 15950 15951:: 15952 15953 declare i16 @llvm.umul.fix.sat.i16(i16 %a, i16 %b, i32 %scale) 15954 declare i32 @llvm.umul.fix.sat.i32(i32 %a, i32 %b, i32 %scale) 15955 declare i64 @llvm.umul.fix.sat.i64(i64 %a, i64 %b, i32 %scale) 15956 declare <4 x i32> @llvm.umul.fix.sat.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale) 15957 15958Overview 15959""""""""" 15960 15961The '``llvm.umul.fix.sat``' family of intrinsic functions perform unsigned 15962fixed point saturating multiplication on 2 arguments of the same scale. 15963 15964Arguments 15965"""""""""" 15966 15967The arguments (%a and %b) and the result may be of integer types of any bit 15968width, but they must have the same bit width. ``%a`` and ``%b`` are the two 15969values that will undergo unsigned fixed point multiplication. The argument 15970``%scale`` represents the scale of both operands, and must be a constant 15971integer. 15972 15973Semantics: 15974"""""""""" 15975 15976This operation performs fixed point multiplication on the 2 arguments of a 15977specified scale. The result will also be returned in the same scale specified 15978in the third argument. 15979 15980If the result value cannot be precisely represented in the given scale, the 15981value is rounded up or down to the closest representable value. The rounding 15982direction is unspecified. 15983 15984The maximum value this operation can clamp to is the largest unsigned value 15985representable by the bit width of the first 2 arguments. The minimum value is the 15986smallest unsigned value representable by this bit width (zero). 15987 15988 15989Examples 15990""""""""" 15991 15992.. code-block:: llvm 15993 15994 %res = call i4 @llvm.umul.fix.sat.i4(i4 3, i4 2, i32 0) ; %res = 6 (2 x 3 = 6) 15995 %res = call i4 @llvm.umul.fix.sat.i4(i4 3, i4 2, i32 1) ; %res = 3 (1.5 x 1 = 1.5) 15996 15997 ; The result in the following could be rounded down to 2 or up to 2.5 15998 %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) 15999 16000 ; Saturation 16001 %res = call i4 @llvm.umul.fix.sat.i4(i4 8, i4 2, i32 0) ; %res = 15 (8 x 2 -> clamped to 15) 16002 %res = call i4 @llvm.umul.fix.sat.i4(i4 8, i4 8, i32 2) ; %res = 15 (2 x 2 -> clamped to 3.75) 16003 16004 ; Scale can affect the saturation result 16005 %res = call i4 @llvm.umul.fix.sat.i4(i4 2, i4 4, i32 0) ; %res = 7 (2 x 4 -> clamped to 7) 16006 %res = call i4 @llvm.umul.fix.sat.i4(i4 2, i4 4, i32 1) ; %res = 4 (1 x 2 = 2) 16007 16008 16009'``llvm.sdiv.fix.*``' Intrinsics 16010^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16011 16012Syntax 16013""""""" 16014 16015This is an overloaded intrinsic. You can use ``llvm.sdiv.fix`` 16016on any integer bit width or vectors of integers. 16017 16018:: 16019 16020 declare i16 @llvm.sdiv.fix.i16(i16 %a, i16 %b, i32 %scale) 16021 declare i32 @llvm.sdiv.fix.i32(i32 %a, i32 %b, i32 %scale) 16022 declare i64 @llvm.sdiv.fix.i64(i64 %a, i64 %b, i32 %scale) 16023 declare <4 x i32> @llvm.sdiv.fix.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale) 16024 16025Overview 16026""""""""" 16027 16028The '``llvm.sdiv.fix``' family of intrinsic functions perform signed 16029fixed point division on 2 arguments of the same scale. 16030 16031Arguments 16032"""""""""" 16033 16034The arguments (%a and %b) and the result may be of integer types of any bit 16035width, but they must have the same bit width. The arguments may also work with 16036int vectors of the same length and int size. ``%a`` and ``%b`` are the two 16037values that will undergo signed fixed point division. The argument 16038``%scale`` represents the scale of both operands, and must be a constant 16039integer. 16040 16041Semantics: 16042"""""""""" 16043 16044This operation performs fixed point division on the 2 arguments of a 16045specified scale. The result will also be returned in the same scale specified 16046in the third argument. 16047 16048If the result value cannot be precisely represented in the given scale, the 16049value is rounded up or down to the closest representable value. The rounding 16050direction is unspecified. 16051 16052It is undefined behavior if the result value does not fit within the range of 16053the fixed point type, or if the second argument is zero. 16054 16055 16056Examples 16057""""""""" 16058 16059.. code-block:: llvm 16060 16061 %res = call i4 @llvm.sdiv.fix.i4(i4 6, i4 2, i32 0) ; %res = 3 (6 / 2 = 3) 16062 %res = call i4 @llvm.sdiv.fix.i4(i4 6, i4 4, i32 1) ; %res = 3 (3 / 2 = 1.5) 16063 %res = call i4 @llvm.sdiv.fix.i4(i4 3, i4 -2, i32 1) ; %res = -3 (1.5 / -1 = -1.5) 16064 16065 ; The result in the following could be rounded up to 1 or down to 0.5 16066 %res = call i4 @llvm.sdiv.fix.i4(i4 3, i4 4, i32 1) ; %res = 2 (or 1) (1.5 / 2 = 0.75) 16067 16068 16069'``llvm.udiv.fix.*``' Intrinsics 16070^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16071 16072Syntax 16073""""""" 16074 16075This is an overloaded intrinsic. You can use ``llvm.udiv.fix`` 16076on any integer bit width or vectors of integers. 16077 16078:: 16079 16080 declare i16 @llvm.udiv.fix.i16(i16 %a, i16 %b, i32 %scale) 16081 declare i32 @llvm.udiv.fix.i32(i32 %a, i32 %b, i32 %scale) 16082 declare i64 @llvm.udiv.fix.i64(i64 %a, i64 %b, i32 %scale) 16083 declare <4 x i32> @llvm.udiv.fix.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale) 16084 16085Overview 16086""""""""" 16087 16088The '``llvm.udiv.fix``' family of intrinsic functions perform unsigned 16089fixed point division on 2 arguments of the same scale. 16090 16091Arguments 16092"""""""""" 16093 16094The arguments (%a and %b) and the result may be of integer types of any bit 16095width, but they must have the same bit width. The arguments may also work with 16096int vectors of the same length and int size. ``%a`` and ``%b`` are the two 16097values that will undergo unsigned fixed point division. The argument 16098``%scale`` represents the scale of both operands, and must be a constant 16099integer. 16100 16101Semantics: 16102"""""""""" 16103 16104This operation performs fixed point division on the 2 arguments of a 16105specified scale. The result will also be returned in the same scale specified 16106in the third argument. 16107 16108If the result value cannot be precisely represented in the given scale, the 16109value is rounded up or down to the closest representable value. The rounding 16110direction is unspecified. 16111 16112It is undefined behavior if the result value does not fit within the range of 16113the fixed point type, or if the second argument is zero. 16114 16115 16116Examples 16117""""""""" 16118 16119.. code-block:: llvm 16120 16121 %res = call i4 @llvm.udiv.fix.i4(i4 6, i4 2, i32 0) ; %res = 3 (6 / 2 = 3) 16122 %res = call i4 @llvm.udiv.fix.i4(i4 6, i4 4, i32 1) ; %res = 3 (3 / 2 = 1.5) 16123 %res = call i4 @llvm.udiv.fix.i4(i4 1, i4 -8, i32 4) ; %res = 2 (0.0625 / 0.5 = 0.125) 16124 16125 ; The result in the following could be rounded up to 1 or down to 0.5 16126 %res = call i4 @llvm.udiv.fix.i4(i4 3, i4 4, i32 1) ; %res = 2 (or 1) (1.5 / 2 = 0.75) 16127 16128 16129'``llvm.sdiv.fix.sat.*``' Intrinsics 16130^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16131 16132Syntax 16133""""""" 16134 16135This is an overloaded intrinsic. You can use ``llvm.sdiv.fix.sat`` 16136on any integer bit width or vectors of integers. 16137 16138:: 16139 16140 declare i16 @llvm.sdiv.fix.sat.i16(i16 %a, i16 %b, i32 %scale) 16141 declare i32 @llvm.sdiv.fix.sat.i32(i32 %a, i32 %b, i32 %scale) 16142 declare i64 @llvm.sdiv.fix.sat.i64(i64 %a, i64 %b, i32 %scale) 16143 declare <4 x i32> @llvm.sdiv.fix.sat.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale) 16144 16145Overview 16146""""""""" 16147 16148The '``llvm.sdiv.fix.sat``' family of intrinsic functions perform signed 16149fixed point saturating division on 2 arguments of the same scale. 16150 16151Arguments 16152"""""""""" 16153 16154The arguments (%a and %b) and the result may be of integer types of any bit 16155width, but they must have the same bit width. ``%a`` and ``%b`` are the two 16156values that will undergo signed fixed point division. The argument 16157``%scale`` represents the scale of both operands, and must be a constant 16158integer. 16159 16160Semantics: 16161"""""""""" 16162 16163This operation performs fixed point division on the 2 arguments of a 16164specified scale. The result will also be returned in the same scale specified 16165in the third argument. 16166 16167If the result value cannot be precisely represented in the given scale, the 16168value is rounded up or down to the closest representable value. The rounding 16169direction is unspecified. 16170 16171The maximum value this operation can clamp to is the largest signed value 16172representable by the bit width of the first 2 arguments. The minimum value is the 16173smallest signed value representable by this bit width. 16174 16175It is undefined behavior if the second argument is zero. 16176 16177 16178Examples 16179""""""""" 16180 16181.. code-block:: llvm 16182 16183 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 6, i4 2, i32 0) ; %res = 3 (6 / 2 = 3) 16184 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 6, i4 4, i32 1) ; %res = 3 (3 / 2 = 1.5) 16185 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 3, i4 -2, i32 1) ; %res = -3 (1.5 / -1 = -1.5) 16186 16187 ; The result in the following could be rounded up to 1 or down to 0.5 16188 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 3, i4 4, i32 1) ; %res = 2 (or 1) (1.5 / 2 = 0.75) 16189 16190 ; Saturation 16191 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 -8, i4 -1, i32 0) ; %res = 7 (-8 / -1 = 8 => 7) 16192 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 4, i4 2, i32 2) ; %res = 7 (1 / 0.5 = 2 => 1.75) 16193 %res = call i4 @llvm.sdiv.fix.sat.i4(i4 -4, i4 1, i32 2) ; %res = -8 (-1 / 0.25 = -4 => -2) 16194 16195 16196'``llvm.udiv.fix.sat.*``' Intrinsics 16197^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16198 16199Syntax 16200""""""" 16201 16202This is an overloaded intrinsic. You can use ``llvm.udiv.fix.sat`` 16203on any integer bit width or vectors of integers. 16204 16205:: 16206 16207 declare i16 @llvm.udiv.fix.sat.i16(i16 %a, i16 %b, i32 %scale) 16208 declare i32 @llvm.udiv.fix.sat.i32(i32 %a, i32 %b, i32 %scale) 16209 declare i64 @llvm.udiv.fix.sat.i64(i64 %a, i64 %b, i32 %scale) 16210 declare <4 x i32> @llvm.udiv.fix.sat.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %scale) 16211 16212Overview 16213""""""""" 16214 16215The '``llvm.udiv.fix.sat``' family of intrinsic functions perform unsigned 16216fixed point saturating division on 2 arguments of the same scale. 16217 16218Arguments 16219"""""""""" 16220 16221The arguments (%a and %b) and the result may be of integer types of any bit 16222width, but they must have the same bit width. ``%a`` and ``%b`` are the two 16223values that will undergo unsigned fixed point division. The argument 16224``%scale`` represents the scale of both operands, and must be a constant 16225integer. 16226 16227Semantics: 16228"""""""""" 16229 16230This operation performs fixed point division on the 2 arguments of a 16231specified scale. The result will also be returned in the same scale specified 16232in the third argument. 16233 16234If the result value cannot be precisely represented in the given scale, the 16235value is rounded up or down to the closest representable value. The rounding 16236direction is unspecified. 16237 16238The maximum value this operation can clamp to is the largest unsigned value 16239representable by the bit width of the first 2 arguments. The minimum value is the 16240smallest unsigned value representable by this bit width (zero). 16241 16242It is undefined behavior if the second argument is zero. 16243 16244Examples 16245""""""""" 16246 16247.. code-block:: llvm 16248 16249 %res = call i4 @llvm.udiv.fix.sat.i4(i4 6, i4 2, i32 0) ; %res = 3 (6 / 2 = 3) 16250 %res = call i4 @llvm.udiv.fix.sat.i4(i4 6, i4 4, i32 1) ; %res = 3 (3 / 2 = 1.5) 16251 16252 ; The result in the following could be rounded down to 0.5 or up to 1 16253 %res = call i4 @llvm.udiv.fix.sat.i4(i4 3, i4 4, i32 1) ; %res = 1 (or 2) (1.5 / 2 = 0.75) 16254 16255 ; Saturation 16256 %res = call i4 @llvm.udiv.fix.sat.i4(i4 8, i4 2, i32 2) ; %res = 15 (2 / 0.5 = 4 => 3.75) 16257 16258 16259Specialised Arithmetic Intrinsics 16260--------------------------------- 16261 16262.. _i_intr_llvm_canonicalize: 16263 16264'``llvm.canonicalize.*``' Intrinsic 16265^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16266 16267Syntax: 16268""""""" 16269 16270:: 16271 16272 declare float @llvm.canonicalize.f32(float %a) 16273 declare double @llvm.canonicalize.f64(double %b) 16274 16275Overview: 16276""""""""" 16277 16278The '``llvm.canonicalize.*``' intrinsic returns the platform specific canonical 16279encoding of a floating-point number. This canonicalization is useful for 16280implementing certain numeric primitives such as frexp. The canonical encoding is 16281defined by IEEE-754-2008 to be: 16282 16283:: 16284 16285 2.1.8 canonical encoding: The preferred encoding of a floating-point 16286 representation in a format. Applied to declets, significands of finite 16287 numbers, infinities, and NaNs, especially in decimal formats. 16288 16289This operation can also be considered equivalent to the IEEE-754-2008 16290conversion of a floating-point value to the same format. NaNs are handled 16291according to section 6.2. 16292 16293Examples of non-canonical encodings: 16294 16295- x87 pseudo denormals, pseudo NaNs, pseudo Infinity, Unnormals. These are 16296 converted to a canonical representation per hardware-specific protocol. 16297- Many normal decimal floating-point numbers have non-canonical alternative 16298 encodings. 16299- Some machines, like GPUs or ARMv7 NEON, do not support subnormal values. 16300 These are treated as non-canonical encodings of zero and will be flushed to 16301 a zero of the same sign by this operation. 16302 16303Note that per IEEE-754-2008 6.2, systems that support signaling NaNs with 16304default exception handling must signal an invalid exception, and produce a 16305quiet NaN result. 16306 16307This function should always be implementable as multiplication by 1.0, provided 16308that the compiler does not constant fold the operation. Likewise, division by 163091.0 and ``llvm.minnum(x, x)`` are possible implementations. Addition with 16310-0.0 is also sufficient provided that the rounding mode is not -Infinity. 16311 16312``@llvm.canonicalize`` must preserve the equality relation. That is: 16313 16314- ``(@llvm.canonicalize(x) == x)`` is equivalent to ``(x == x)`` 16315- ``(@llvm.canonicalize(x) == @llvm.canonicalize(y))`` is equivalent to 16316 to ``(x == y)`` 16317 16318Additionally, the sign of zero must be conserved: 16319``@llvm.canonicalize(-0.0) = -0.0`` and ``@llvm.canonicalize(+0.0) = +0.0`` 16320 16321The payload bits of a NaN must be conserved, with two exceptions. 16322First, environments which use only a single canonical representation of NaN 16323must perform said canonicalization. Second, SNaNs must be quieted per the 16324usual methods. 16325 16326The canonicalization operation may be optimized away if: 16327 16328- The input is known to be canonical. For example, it was produced by a 16329 floating-point operation that is required by the standard to be canonical. 16330- The result is consumed only by (or fused with) other floating-point 16331 operations. That is, the bits of the floating-point value are not examined. 16332 16333'``llvm.fmuladd.*``' Intrinsic 16334^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16335 16336Syntax: 16337""""""" 16338 16339:: 16340 16341 declare float @llvm.fmuladd.f32(float %a, float %b, float %c) 16342 declare double @llvm.fmuladd.f64(double %a, double %b, double %c) 16343 16344Overview: 16345""""""""" 16346 16347The '``llvm.fmuladd.*``' intrinsic functions represent multiply-add 16348expressions that can be fused if the code generator determines that (a) the 16349target instruction set has support for a fused operation, and (b) that the 16350fused operation is more efficient than the equivalent, separate pair of mul 16351and add instructions. 16352 16353Arguments: 16354"""""""""" 16355 16356The '``llvm.fmuladd.*``' intrinsics each take three arguments: two 16357multiplicands, a and b, and an addend c. 16358 16359Semantics: 16360"""""""""" 16361 16362The expression: 16363 16364:: 16365 16366 %0 = call float @llvm.fmuladd.f32(%a, %b, %c) 16367 16368is equivalent to the expression a \* b + c, except that it is unspecified 16369whether rounding will be performed between the multiplication and addition 16370steps. Fusion is not guaranteed, even if the target platform supports it. 16371If a fused multiply-add is required, the corresponding 16372:ref:`llvm.fma <int_fma>` intrinsic function should be used instead. 16373This never sets errno, just as '``llvm.fma.*``'. 16374 16375Examples: 16376""""""""" 16377 16378.. code-block:: llvm 16379 16380 %r2 = call float @llvm.fmuladd.f32(float %a, float %b, float %c) ; yields float:r2 = (a * b) + c 16381 16382 16383Hardware-Loop Intrinsics 16384------------------------ 16385 16386LLVM support several intrinsics to mark a loop as a hardware-loop. They are 16387hints to the backend which are required to lower these intrinsics further to target 16388specific instructions, or revert the hardware-loop to a normal loop if target 16389specific restriction are not met and a hardware-loop can't be generated. 16390 16391These intrinsics may be modified in the future and are not intended to be used 16392outside the backend. Thus, front-end and mid-level optimizations should not be 16393generating these intrinsics. 16394 16395 16396'``llvm.set.loop.iterations.*``' Intrinsic 16397^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16398 16399Syntax: 16400""""""" 16401 16402This is an overloaded intrinsic. 16403 16404:: 16405 16406 declare void @llvm.set.loop.iterations.i32(i32) 16407 declare void @llvm.set.loop.iterations.i64(i64) 16408 16409Overview: 16410""""""""" 16411 16412The '``llvm.set.loop.iterations.*``' intrinsics are used to specify the 16413hardware-loop trip count. They are placed in the loop preheader basic block and 16414are marked as ``IntrNoDuplicate`` to avoid optimizers duplicating these 16415instructions. 16416 16417Arguments: 16418"""""""""" 16419 16420The integer operand is the loop trip count of the hardware-loop, and thus 16421not e.g. the loop back-edge taken count. 16422 16423Semantics: 16424"""""""""" 16425 16426The '``llvm.set.loop.iterations.*``' intrinsics do not perform any arithmetic 16427on their operand. It's a hint to the backend that can use this to set up the 16428hardware-loop count with a target specific instruction, usually a move of this 16429value to a special register or a hardware-loop instruction. 16430 16431 16432'``llvm.start.loop.iterations.*``' Intrinsic 16433^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16434 16435Syntax: 16436""""""" 16437 16438This is an overloaded intrinsic. 16439 16440:: 16441 16442 declare i32 @llvm.start.loop.iterations.i32(i32) 16443 declare i64 @llvm.start.loop.iterations.i64(i64) 16444 16445Overview: 16446""""""""" 16447 16448The '``llvm.start.loop.iterations.*``' intrinsics are similar to the 16449'``llvm.set.loop.iterations.*``' intrinsics, used to specify the 16450hardware-loop trip count but also produce a value identical to the input 16451that can be used as the input to the loop. They are placed in the loop 16452preheader basic block and the output is expected to be the input to the 16453phi for the induction variable of the loop, decremented by the 16454'``llvm.loop.decrement.reg.*``'. 16455 16456Arguments: 16457"""""""""" 16458 16459The integer operand is the loop trip count of the hardware-loop, and thus 16460not e.g. the loop back-edge taken count. 16461 16462Semantics: 16463"""""""""" 16464 16465The '``llvm.start.loop.iterations.*``' intrinsics do not perform any arithmetic 16466on their operand. It's a hint to the backend that can use this to set up the 16467hardware-loop count with a target specific instruction, usually a move of this 16468value to a special register or a hardware-loop instruction. 16469 16470'``llvm.test.set.loop.iterations.*``' Intrinsic 16471^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16472 16473Syntax: 16474""""""" 16475 16476This is an overloaded intrinsic. 16477 16478:: 16479 16480 declare i1 @llvm.test.set.loop.iterations.i32(i32) 16481 declare i1 @llvm.test.set.loop.iterations.i64(i64) 16482 16483Overview: 16484""""""""" 16485 16486The '``llvm.test.set.loop.iterations.*``' intrinsics are used to specify the 16487the loop trip count, and also test that the given count is not zero, allowing 16488it to control entry to a while-loop. They are placed in the loop preheader's 16489predecessor basic block, and are marked as ``IntrNoDuplicate`` to avoid 16490optimizers duplicating these instructions. 16491 16492Arguments: 16493"""""""""" 16494 16495The integer operand is the loop trip count of the hardware-loop, and thus 16496not e.g. the loop back-edge taken count. 16497 16498Semantics: 16499"""""""""" 16500 16501The '``llvm.test.set.loop.iterations.*``' intrinsics do not perform any 16502arithmetic on their operand. It's a hint to the backend that can use this to 16503set up the hardware-loop count with a target specific instruction, usually a 16504move of this value to a special register or a hardware-loop instruction. 16505The result is the conditional value of whether the given count is not zero. 16506 16507 16508'``llvm.test.start.loop.iterations.*``' Intrinsic 16509^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16510 16511Syntax: 16512""""""" 16513 16514This is an overloaded intrinsic. 16515 16516:: 16517 16518 declare {i32, i1} @llvm.test.start.loop.iterations.i32(i32) 16519 declare {i64, i1} @llvm.test.start.loop.iterations.i64(i64) 16520 16521Overview: 16522""""""""" 16523 16524The '``llvm.test.start.loop.iterations.*``' intrinsics are similar to the 16525'``llvm.test.set.loop.iterations.*``' and '``llvm.start.loop.iterations.*``' 16526intrinsics, used to specify the hardware-loop trip count, but also produce a 16527value identical to the input that can be used as the input to the loop. The 16528second i1 output controls entry to a while-loop. 16529 16530Arguments: 16531"""""""""" 16532 16533The integer operand is the loop trip count of the hardware-loop, and thus 16534not e.g. the loop back-edge taken count. 16535 16536Semantics: 16537"""""""""" 16538 16539The '``llvm.test.start.loop.iterations.*``' intrinsics do not perform any 16540arithmetic on their operand. It's a hint to the backend that can use this to 16541set up the hardware-loop count with a target specific instruction, usually a 16542move of this value to a special register or a hardware-loop instruction. 16543The result is a pair of the input and a conditional value of whether the 16544given count is not zero. 16545 16546 16547'``llvm.loop.decrement.reg.*``' Intrinsic 16548^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16549 16550Syntax: 16551""""""" 16552 16553This is an overloaded intrinsic. 16554 16555:: 16556 16557 declare i32 @llvm.loop.decrement.reg.i32(i32, i32) 16558 declare i64 @llvm.loop.decrement.reg.i64(i64, i64) 16559 16560Overview: 16561""""""""" 16562 16563The '``llvm.loop.decrement.reg.*``' intrinsics are used to lower the loop 16564iteration counter and return an updated value that will be used in the next 16565loop test check. 16566 16567Arguments: 16568"""""""""" 16569 16570Both arguments must have identical integer types. The first operand is the 16571loop iteration counter. The second operand is the maximum number of elements 16572processed in an iteration. 16573 16574Semantics: 16575"""""""""" 16576 16577The '``llvm.loop.decrement.reg.*``' intrinsics do an integer ``SUB`` of its 16578two operands, which is not allowed to wrap. They return the remaining number of 16579iterations still to be executed, and can be used together with a ``PHI``, 16580``ICMP`` and ``BR`` to control the number of loop iterations executed. Any 16581optimisations are allowed to treat it is a ``SUB``, and it is supported by 16582SCEV, so it's the backends responsibility to handle cases where it may be 16583optimised. These intrinsics are marked as ``IntrNoDuplicate`` to avoid 16584optimizers duplicating these instructions. 16585 16586 16587'``llvm.loop.decrement.*``' Intrinsic 16588^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16589 16590Syntax: 16591""""""" 16592 16593This is an overloaded intrinsic. 16594 16595:: 16596 16597 declare i1 @llvm.loop.decrement.i32(i32) 16598 declare i1 @llvm.loop.decrement.i64(i64) 16599 16600Overview: 16601""""""""" 16602 16603The HardwareLoops pass allows the loop decrement value to be specified with an 16604option. It defaults to a loop decrement value of 1, but it can be an unsigned 16605integer value provided by this option. The '``llvm.loop.decrement.*``' 16606intrinsics decrement the loop iteration counter with this value, and return a 16607false predicate if the loop should exit, and true otherwise. 16608This is emitted if the loop counter is not updated via a ``PHI`` node, which 16609can also be controlled with an option. 16610 16611Arguments: 16612"""""""""" 16613 16614The integer argument is the loop decrement value used to decrement the loop 16615iteration counter. 16616 16617Semantics: 16618"""""""""" 16619 16620The '``llvm.loop.decrement.*``' intrinsics do a ``SUB`` of the loop iteration 16621counter with the given loop decrement value, and return false if the loop 16622should exit, this ``SUB`` is not allowed to wrap. The result is a condition 16623that is used by the conditional branch controlling the loop. 16624 16625 16626Vector Reduction Intrinsics 16627--------------------------- 16628 16629Horizontal reductions of vectors can be expressed using the following 16630intrinsics. Each one takes a vector operand as an input and applies its 16631respective operation across all elements of the vector, returning a single 16632scalar result of the same element type. 16633 16634 16635'``llvm.vector.reduce.add.*``' Intrinsic 16636^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16637 16638Syntax: 16639""""""" 16640 16641:: 16642 16643 declare i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %a) 16644 declare i64 @llvm.vector.reduce.add.v2i64(<2 x i64> %a) 16645 16646Overview: 16647""""""""" 16648 16649The '``llvm.vector.reduce.add.*``' intrinsics do an integer ``ADD`` 16650reduction of a vector, returning the result as a scalar. The return type matches 16651the element-type of the vector input. 16652 16653Arguments: 16654"""""""""" 16655The argument to this intrinsic must be a vector of integer values. 16656 16657'``llvm.vector.reduce.fadd.*``' Intrinsic 16658^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16659 16660Syntax: 16661""""""" 16662 16663:: 16664 16665 declare float @llvm.vector.reduce.fadd.v4f32(float %start_value, <4 x float> %a) 16666 declare double @llvm.vector.reduce.fadd.v2f64(double %start_value, <2 x double> %a) 16667 16668Overview: 16669""""""""" 16670 16671The '``llvm.vector.reduce.fadd.*``' intrinsics do a floating-point 16672``ADD`` reduction of a vector, returning the result as a scalar. The return type 16673matches the element-type of the vector input. 16674 16675If the intrinsic call has the 'reassoc' flag set, then the reduction will not 16676preserve the associativity of an equivalent scalarized counterpart. Otherwise 16677the reduction will be *sequential*, thus implying that the operation respects 16678the associativity of a scalarized reduction. That is, the reduction begins with 16679the start value and performs an fadd operation with consecutively increasing 16680vector element indices. See the following pseudocode: 16681 16682:: 16683 16684 float sequential_fadd(start_value, input_vector) 16685 result = start_value 16686 for i = 0 to length(input_vector) 16687 result = result + input_vector[i] 16688 return result 16689 16690 16691Arguments: 16692"""""""""" 16693The first argument to this intrinsic is a scalar start value for the reduction. 16694The type of the start value matches the element-type of the vector input. 16695The second argument must be a vector of floating-point values. 16696 16697To ignore the start value, negative zero (``-0.0``) can be used, as it is 16698the neutral value of floating point addition. 16699 16700Examples: 16701""""""""" 16702 16703:: 16704 16705 %unord = call reassoc float @llvm.vector.reduce.fadd.v4f32(float -0.0, <4 x float> %input) ; relaxed reduction 16706 %ord = call float @llvm.vector.reduce.fadd.v4f32(float %start_value, <4 x float> %input) ; sequential reduction 16707 16708 16709'``llvm.vector.reduce.mul.*``' Intrinsic 16710^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16711 16712Syntax: 16713""""""" 16714 16715:: 16716 16717 declare i32 @llvm.vector.reduce.mul.v4i32(<4 x i32> %a) 16718 declare i64 @llvm.vector.reduce.mul.v2i64(<2 x i64> %a) 16719 16720Overview: 16721""""""""" 16722 16723The '``llvm.vector.reduce.mul.*``' intrinsics do an integer ``MUL`` 16724reduction of a vector, returning the result as a scalar. The return type matches 16725the element-type of the vector input. 16726 16727Arguments: 16728"""""""""" 16729The argument to this intrinsic must be a vector of integer values. 16730 16731'``llvm.vector.reduce.fmul.*``' Intrinsic 16732^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16733 16734Syntax: 16735""""""" 16736 16737:: 16738 16739 declare float @llvm.vector.reduce.fmul.v4f32(float %start_value, <4 x float> %a) 16740 declare double @llvm.vector.reduce.fmul.v2f64(double %start_value, <2 x double> %a) 16741 16742Overview: 16743""""""""" 16744 16745The '``llvm.vector.reduce.fmul.*``' intrinsics do a floating-point 16746``MUL`` reduction of a vector, returning the result as a scalar. The return type 16747matches the element-type of the vector input. 16748 16749If the intrinsic call has the 'reassoc' flag set, then the reduction will not 16750preserve the associativity of an equivalent scalarized counterpart. Otherwise 16751the reduction will be *sequential*, thus implying that the operation respects 16752the associativity of a scalarized reduction. That is, the reduction begins with 16753the start value and performs an fmul operation with consecutively increasing 16754vector element indices. See the following pseudocode: 16755 16756:: 16757 16758 float sequential_fmul(start_value, input_vector) 16759 result = start_value 16760 for i = 0 to length(input_vector) 16761 result = result * input_vector[i] 16762 return result 16763 16764 16765Arguments: 16766"""""""""" 16767The first argument to this intrinsic is a scalar start value for the reduction. 16768The type of the start value matches the element-type of the vector input. 16769The second argument must be a vector of floating-point values. 16770 16771To ignore the start value, one (``1.0``) can be used, as it is the neutral 16772value of floating point multiplication. 16773 16774Examples: 16775""""""""" 16776 16777:: 16778 16779 %unord = call reassoc float @llvm.vector.reduce.fmul.v4f32(float 1.0, <4 x float> %input) ; relaxed reduction 16780 %ord = call float @llvm.vector.reduce.fmul.v4f32(float %start_value, <4 x float> %input) ; sequential reduction 16781 16782'``llvm.vector.reduce.and.*``' Intrinsic 16783^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16784 16785Syntax: 16786""""""" 16787 16788:: 16789 16790 declare i32 @llvm.vector.reduce.and.v4i32(<4 x i32> %a) 16791 16792Overview: 16793""""""""" 16794 16795The '``llvm.vector.reduce.and.*``' intrinsics do a bitwise ``AND`` 16796reduction of a vector, returning the result as a scalar. The return type matches 16797the element-type of the vector input. 16798 16799Arguments: 16800"""""""""" 16801The argument to this intrinsic must be a vector of integer values. 16802 16803'``llvm.vector.reduce.or.*``' Intrinsic 16804^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16805 16806Syntax: 16807""""""" 16808 16809:: 16810 16811 declare i32 @llvm.vector.reduce.or.v4i32(<4 x i32> %a) 16812 16813Overview: 16814""""""""" 16815 16816The '``llvm.vector.reduce.or.*``' intrinsics do a bitwise ``OR`` reduction 16817of a vector, returning the result as a scalar. The return type matches the 16818element-type of the vector input. 16819 16820Arguments: 16821"""""""""" 16822The argument to this intrinsic must be a vector of integer values. 16823 16824'``llvm.vector.reduce.xor.*``' Intrinsic 16825^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16826 16827Syntax: 16828""""""" 16829 16830:: 16831 16832 declare i32 @llvm.vector.reduce.xor.v4i32(<4 x i32> %a) 16833 16834Overview: 16835""""""""" 16836 16837The '``llvm.vector.reduce.xor.*``' intrinsics do a bitwise ``XOR`` 16838reduction of a vector, returning the result as a scalar. The return type matches 16839the element-type of the vector input. 16840 16841Arguments: 16842"""""""""" 16843The argument to this intrinsic must be a vector of integer values. 16844 16845'``llvm.vector.reduce.smax.*``' Intrinsic 16846^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16847 16848Syntax: 16849""""""" 16850 16851:: 16852 16853 declare i32 @llvm.vector.reduce.smax.v4i32(<4 x i32> %a) 16854 16855Overview: 16856""""""""" 16857 16858The '``llvm.vector.reduce.smax.*``' intrinsics do a signed integer 16859``MAX`` reduction of a vector, returning the result as a scalar. The return type 16860matches the element-type of the vector input. 16861 16862Arguments: 16863"""""""""" 16864The argument to this intrinsic must be a vector of integer values. 16865 16866'``llvm.vector.reduce.smin.*``' Intrinsic 16867^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16868 16869Syntax: 16870""""""" 16871 16872:: 16873 16874 declare i32 @llvm.vector.reduce.smin.v4i32(<4 x i32> %a) 16875 16876Overview: 16877""""""""" 16878 16879The '``llvm.vector.reduce.smin.*``' intrinsics do a signed integer 16880``MIN`` reduction of a vector, returning the result as a scalar. The return type 16881matches the element-type of the vector input. 16882 16883Arguments: 16884"""""""""" 16885The argument to this intrinsic must be a vector of integer values. 16886 16887'``llvm.vector.reduce.umax.*``' Intrinsic 16888^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16889 16890Syntax: 16891""""""" 16892 16893:: 16894 16895 declare i32 @llvm.vector.reduce.umax.v4i32(<4 x i32> %a) 16896 16897Overview: 16898""""""""" 16899 16900The '``llvm.vector.reduce.umax.*``' intrinsics do an unsigned 16901integer ``MAX`` reduction of a vector, returning the result as a scalar. The 16902return type matches the element-type of the vector input. 16903 16904Arguments: 16905"""""""""" 16906The argument to this intrinsic must be a vector of integer values. 16907 16908'``llvm.vector.reduce.umin.*``' Intrinsic 16909^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16910 16911Syntax: 16912""""""" 16913 16914:: 16915 16916 declare i32 @llvm.vector.reduce.umin.v4i32(<4 x i32> %a) 16917 16918Overview: 16919""""""""" 16920 16921The '``llvm.vector.reduce.umin.*``' intrinsics do an unsigned 16922integer ``MIN`` reduction of a vector, returning the result as a scalar. The 16923return type matches the element-type of the vector input. 16924 16925Arguments: 16926"""""""""" 16927The argument to this intrinsic must be a vector of integer values. 16928 16929'``llvm.vector.reduce.fmax.*``' Intrinsic 16930^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16931 16932Syntax: 16933""""""" 16934 16935:: 16936 16937 declare float @llvm.vector.reduce.fmax.v4f32(<4 x float> %a) 16938 declare double @llvm.vector.reduce.fmax.v2f64(<2 x double> %a) 16939 16940Overview: 16941""""""""" 16942 16943The '``llvm.vector.reduce.fmax.*``' intrinsics do a floating-point 16944``MAX`` reduction of a vector, returning the result as a scalar. The return type 16945matches the element-type of the vector input. 16946 16947This instruction has the same comparison semantics as the '``llvm.maxnum.*``' 16948intrinsic. That is, the result will always be a number unless all elements of 16949the vector are NaN. For a vector with maximum element magnitude 0.0 and 16950containing both +0.0 and -0.0 elements, the sign of the result is unspecified. 16951 16952If the intrinsic call has the ``nnan`` fast-math flag, then the operation can 16953assume that NaNs are not present in the input vector. 16954 16955Arguments: 16956"""""""""" 16957The argument to this intrinsic must be a vector of floating-point values. 16958 16959'``llvm.vector.reduce.fmin.*``' Intrinsic 16960^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16961 16962Syntax: 16963""""""" 16964This is an overloaded intrinsic. 16965 16966:: 16967 16968 declare float @llvm.vector.reduce.fmin.v4f32(<4 x float> %a) 16969 declare double @llvm.vector.reduce.fmin.v2f64(<2 x double> %a) 16970 16971Overview: 16972""""""""" 16973 16974The '``llvm.vector.reduce.fmin.*``' intrinsics do a floating-point 16975``MIN`` reduction of a vector, returning the result as a scalar. The return type 16976matches the element-type of the vector input. 16977 16978This instruction has the same comparison semantics as the '``llvm.minnum.*``' 16979intrinsic. That is, the result will always be a number unless all elements of 16980the vector are NaN. For a vector with minimum element magnitude 0.0 and 16981containing both +0.0 and -0.0 elements, the sign of the result is unspecified. 16982 16983If the intrinsic call has the ``nnan`` fast-math flag, then the operation can 16984assume that NaNs are not present in the input vector. 16985 16986Arguments: 16987"""""""""" 16988The argument to this intrinsic must be a vector of floating-point values. 16989 16990'``llvm.experimental.vector.insert``' Intrinsic 16991^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 16992 16993Syntax: 16994""""""" 16995This is an overloaded intrinsic. You can use ``llvm.experimental.vector.insert`` 16996to insert a fixed-width vector into a scalable vector, but not the other way 16997around. 16998 16999:: 17000 17001 declare <vscale x 4 x float> @llvm.experimental.vector.insert.v4f32(<vscale x 4 x float> %vec, <4 x float> %subvec, i64 %idx) 17002 declare <vscale x 2 x double> @llvm.experimental.vector.insert.v2f64(<vscale x 2 x double> %vec, <2 x double> %subvec, i64 %idx) 17003 17004Overview: 17005""""""""" 17006 17007The '``llvm.experimental.vector.insert.*``' intrinsics insert a vector into another vector 17008starting from a given index. The return type matches the type of the vector we 17009insert into. Conceptually, this can be used to build a scalable vector out of 17010non-scalable vectors. 17011 17012Arguments: 17013"""""""""" 17014 17015The ``vec`` is the vector which ``subvec`` will be inserted into. 17016The ``subvec`` is the vector that will be inserted. 17017 17018``idx`` represents the starting element number at which ``subvec`` will be 17019inserted. ``idx`` must be a constant multiple of ``subvec``'s known minimum 17020vector length. If ``subvec`` is a scalable vector, ``idx`` is first scaled by 17021the runtime scaling factor of ``subvec``. The elements of ``vec`` starting at 17022``idx`` are overwritten with ``subvec``. Elements ``idx`` through (``idx`` + 17023num_elements(``subvec``) - 1) must be valid ``vec`` indices. If this condition 17024cannot be determined statically but is false at runtime, then the result vector 17025is undefined. 17026 17027 17028'``llvm.experimental.vector.extract``' Intrinsic 17029^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17030 17031Syntax: 17032""""""" 17033This is an overloaded intrinsic. You can use 17034``llvm.experimental.vector.extract`` to extract a fixed-width vector from a 17035scalable vector, but not the other way around. 17036 17037:: 17038 17039 declare <4 x float> @llvm.experimental.vector.extract.v4f32(<vscale x 4 x float> %vec, i64 %idx) 17040 declare <2 x double> @llvm.experimental.vector.extract.v2f64(<vscale x 2 x double> %vec, i64 %idx) 17041 17042Overview: 17043""""""""" 17044 17045The '``llvm.experimental.vector.extract.*``' intrinsics extract a vector from 17046within another vector starting from a given index. The return type must be 17047explicitly specified. Conceptually, this can be used to decompose a scalable 17048vector into non-scalable parts. 17049 17050Arguments: 17051"""""""""" 17052 17053The ``vec`` is the vector from which we will extract a subvector. 17054 17055The ``idx`` specifies the starting element number within ``vec`` from which a 17056subvector is extracted. ``idx`` must be a constant multiple of the known-minimum 17057vector length of the result type. If the result type is a scalable vector, 17058``idx`` is first scaled by the result type's runtime scaling factor. Elements 17059``idx`` through (``idx`` + num_elements(result_type) - 1) must be valid vector 17060indices. If this condition cannot be determined statically but is false at 17061runtime, then the result vector is undefined. The ``idx`` parameter must be a 17062vector index constant type (for most targets this will be an integer pointer 17063type). 17064 17065'``llvm.experimental.vector.reverse``' Intrinsic 17066^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17067 17068Syntax: 17069""""""" 17070This is an overloaded intrinsic. 17071 17072:: 17073 17074 declare <2 x i8> @llvm.experimental.vector.reverse.v2i8(<2 x i8> %a) 17075 declare <vscale x 4 x i32> @llvm.experimental.vector.reverse.nxv4i32(<vscale x 4 x i32> %a) 17076 17077Overview: 17078""""""""" 17079 17080The '``llvm.experimental.vector.reverse.*``' intrinsics reverse a vector. 17081The intrinsic takes a single vector and returns a vector of matching type but 17082with the original lane order reversed. These intrinsics work for both fixed 17083and scalable vectors. While this intrinsic is marked as experimental the 17084recommended way to express reverse operations for fixed-width vectors is still 17085to use a shufflevector, as that may allow for more optimization opportunities. 17086 17087Arguments: 17088"""""""""" 17089 17090The argument to this intrinsic must be a vector. 17091 17092'``llvm.experimental.vector.splice``' Intrinsic 17093^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17094 17095Syntax: 17096""""""" 17097This is an overloaded intrinsic. 17098 17099:: 17100 17101 declare <2 x double> @llvm.experimental.vector.splice.v2f64(<2 x double> %vec1, <2 x double> %vec2, i32 %imm) 17102 declare <vscale x 4 x i32> @llvm.experimental.vector.splice.nxv4i32(<vscale x 4 x i32> %vec1, <vscale x 4 x i32> %vec2, i32 %imm) 17103 17104Overview: 17105""""""""" 17106 17107The '``llvm.experimental.vector.splice.*``' intrinsics construct a vector by 17108concatenating elements from the first input vector with elements of the second 17109input vector, returning a vector of the same type as the input vectors. The 17110signed immediate, modulo the number of elements in the vector, is the index 17111into the first vector from which to extract the result value. This means 17112conceptually that for a positive immediate, a vector is extracted from 17113``concat(%vec1, %vec2)`` starting at index ``imm``, whereas for a negative 17114immediate, it extracts ``-imm`` trailing elements from the first vector, and 17115the remaining elements from ``%vec2``. 17116 17117These intrinsics work for both fixed and scalable vectors. While this intrinsic 17118is marked as experimental, the recommended way to express this operation for 17119fixed-width vectors is still to use a shufflevector, as that may allow for more 17120optimization opportunities. 17121 17122For example: 17123 17124.. code-block:: text 17125 17126 llvm.experimental.vector.splice(<A,B,C,D>, <E,F,G,H>, 1) ==> <B, C, D, E> ; index 17127 llvm.experimental.vector.splice(<A,B,C,D>, <E,F,G,H>, -3) ==> <B, C, D, E> ; trailing elements 17128 17129 17130Arguments: 17131"""""""""" 17132 17133The first two operands are vectors with the same type. The third argument 17134``imm`` is the start index, modulo VL, where VL is the runtime vector length of 17135the source/result vector. The ``imm`` is a signed integer constant in the range 17136``-VL <= imm < VL``. For values outside of this range the result is poison. 17137 17138'``llvm.experimental.stepvector``' Intrinsic 17139^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17140 17141This is an overloaded intrinsic. You can use ``llvm.experimental.stepvector`` 17142to generate a vector whose lane values comprise the linear sequence 17143<0, 1, 2, ...>. It is primarily intended for scalable vectors. 17144 17145:: 17146 17147 declare <vscale x 4 x i32> @llvm.experimental.stepvector.nxv4i32() 17148 declare <vscale x 8 x i16> @llvm.experimental.stepvector.nxv8i16() 17149 17150The '``llvm.experimental.stepvector``' intrinsics are used to create vectors 17151of integers whose elements contain a linear sequence of values starting from 0 17152with a step of 1. This experimental intrinsic can only be used for vectors 17153with integer elements that are at least 8 bits in size. If the sequence value 17154exceeds the allowed limit for the element type then the result for that lane is 17155undefined. 17156 17157These intrinsics work for both fixed and scalable vectors. While this intrinsic 17158is marked as experimental, the recommended way to express this operation for 17159fixed-width vectors is still to generate a constant vector instead. 17160 17161 17162Arguments: 17163"""""""""" 17164 17165None. 17166 17167 17168Matrix Intrinsics 17169----------------- 17170 17171Operations on matrixes requiring shape information (like number of rows/columns 17172or the memory layout) can be expressed using the matrix intrinsics. These 17173intrinsics require matrix dimensions to be passed as immediate arguments, and 17174matrixes are passed and returned as vectors. This means that for a ``R`` x 17175``C`` matrix, element ``i`` of column ``j`` is at index ``j * R + i`` in the 17176corresponding vector, with indices starting at 0. Currently column-major layout 17177is assumed. The intrinsics support both integer and floating point matrixes. 17178 17179 17180'``llvm.matrix.transpose.*``' Intrinsic 17181^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17182 17183Syntax: 17184""""""" 17185This is an overloaded intrinsic. 17186 17187:: 17188 17189 declare vectorty @llvm.matrix.transpose.*(vectorty %In, i32 <Rows>, i32 <Cols>) 17190 17191Overview: 17192""""""""" 17193 17194The '``llvm.matrix.transpose.*``' intrinsics treat ``%In`` as a ``<Rows> x 17195<Cols>`` matrix and return the transposed matrix in the result vector. 17196 17197Arguments: 17198"""""""""" 17199 17200The first argument ``%In`` is a vector that corresponds to a ``<Rows> x 17201<Cols>`` matrix. Thus, arguments ``<Rows>`` and ``<Cols>`` correspond to the 17202number of rows and columns, respectively, and must be positive, constant 17203integers. The returned vector must have ``<Rows> * <Cols>`` elements, and have 17204the same float or integer element type as ``%In``. 17205 17206'``llvm.matrix.multiply.*``' Intrinsic 17207^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17208 17209Syntax: 17210""""""" 17211This is an overloaded intrinsic. 17212 17213:: 17214 17215 declare vectorty @llvm.matrix.multiply.*(vectorty %A, vectorty %B, i32 <OuterRows>, i32 <Inner>, i32 <OuterColumns>) 17216 17217Overview: 17218""""""""" 17219 17220The '``llvm.matrix.multiply.*``' intrinsics treat ``%A`` as a ``<OuterRows> x 17221<Inner>`` matrix, ``%B`` as a ``<Inner> x <OuterColumns>`` matrix, and 17222multiplies them. The result matrix is returned in the result vector. 17223 17224Arguments: 17225"""""""""" 17226 17227The first vector argument ``%A`` corresponds to a matrix with ``<OuterRows> * 17228<Inner>`` elements, and the second argument ``%B`` to a matrix with 17229``<Inner> * <OuterColumns>`` elements. Arguments ``<OuterRows>``, 17230``<Inner>`` and ``<OuterColumns>`` must be positive, constant integers. The 17231returned vector must have ``<OuterRows> * <OuterColumns>`` elements. 17232Vectors ``%A``, ``%B``, and the returned vector all have the same float or 17233integer element type. 17234 17235 17236'``llvm.matrix.column.major.load.*``' Intrinsic 17237^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17238 17239Syntax: 17240""""""" 17241This is an overloaded intrinsic. 17242 17243:: 17244 17245 declare vectorty @llvm.matrix.column.major.load.*( 17246 ptrty %Ptr, i64 %Stride, i1 <IsVolatile>, i32 <Rows>, i32 <Cols>) 17247 17248Overview: 17249""""""""" 17250 17251The '``llvm.matrix.column.major.load.*``' intrinsics load a ``<Rows> x <Cols>`` 17252matrix using a stride of ``%Stride`` to compute the start address of the 17253different columns. This allows for convenient loading of sub matrixes. If 17254``<IsVolatile>`` is true, the intrinsic is considered a :ref:`volatile memory 17255access <volatile>`. The result matrix is returned in the result vector. If the 17256``%Ptr`` argument is known to be aligned to some boundary, this can be 17257specified as an attribute on the argument. 17258 17259Arguments: 17260"""""""""" 17261 17262The first argument ``%Ptr`` is a pointer type to the returned vector type, and 17263corresponds to the start address to load from. The second argument ``%Stride`` 17264is a positive, constant integer with ``%Stride >= <Rows>``. ``%Stride`` is used 17265to compute the column memory addresses. I.e., for a column ``C``, its start 17266memory addresses is calculated with ``%Ptr + C * %Stride``. The third Argument 17267``<IsVolatile>`` is a boolean value. The fourth and fifth arguments, 17268``<Rows>`` and ``<Cols>``, correspond to the number of rows and columns, 17269respectively, and must be positive, constant integers. The returned vector must 17270have ``<Rows> * <Cols>`` elements. 17271 17272The :ref:`align <attr_align>` parameter attribute can be provided for the 17273``%Ptr`` arguments. 17274 17275 17276'``llvm.matrix.column.major.store.*``' Intrinsic 17277^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17278 17279Syntax: 17280""""""" 17281 17282:: 17283 17284 declare void @llvm.matrix.column.major.store.*( 17285 vectorty %In, ptrty %Ptr, i64 %Stride, i1 <IsVolatile>, i32 <Rows>, i32 <Cols>) 17286 17287Overview: 17288""""""""" 17289 17290The '``llvm.matrix.column.major.store.*``' intrinsics store the ``<Rows> x 17291<Cols>`` matrix in ``%In`` to memory using a stride of ``%Stride`` between 17292columns. If ``<IsVolatile>`` is true, the intrinsic is considered a 17293:ref:`volatile memory access <volatile>`. 17294 17295If the ``%Ptr`` argument is known to be aligned to some boundary, this can be 17296specified as an attribute on the argument. 17297 17298Arguments: 17299"""""""""" 17300 17301The first argument ``%In`` is a vector that corresponds to a ``<Rows> x 17302<Cols>`` matrix to be stored to memory. The second argument ``%Ptr`` is a 17303pointer to the vector type of ``%In``, and is the start address of the matrix 17304in memory. The third argument ``%Stride`` is a positive, constant integer with 17305``%Stride >= <Rows>``. ``%Stride`` is used to compute the column memory 17306addresses. I.e., for a column ``C``, its start memory addresses is calculated 17307with ``%Ptr + C * %Stride``. The fourth argument ``<IsVolatile>`` is a boolean 17308value. The arguments ``<Rows>`` and ``<Cols>`` correspond to the number of rows 17309and columns, respectively, and must be positive, constant integers. 17310 17311The :ref:`align <attr_align>` parameter attribute can be provided 17312for the ``%Ptr`` arguments. 17313 17314 17315Half Precision Floating-Point Intrinsics 17316---------------------------------------- 17317 17318For most target platforms, half precision floating-point is a 17319storage-only format. This means that it is a dense encoding (in memory) 17320but does not support computation in the format. 17321 17322This means that code must first load the half-precision floating-point 17323value as an i16, then convert it to float with 17324:ref:`llvm.convert.from.fp16 <int_convert_from_fp16>`. Computation can 17325then be performed on the float value (including extending to double 17326etc). To store the value back to memory, it is first converted to float 17327if needed, then converted to i16 with 17328:ref:`llvm.convert.to.fp16 <int_convert_to_fp16>`, then storing as an 17329i16 value. 17330 17331.. _int_convert_to_fp16: 17332 17333'``llvm.convert.to.fp16``' Intrinsic 17334^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17335 17336Syntax: 17337""""""" 17338 17339:: 17340 17341 declare i16 @llvm.convert.to.fp16.f32(float %a) 17342 declare i16 @llvm.convert.to.fp16.f64(double %a) 17343 17344Overview: 17345""""""""" 17346 17347The '``llvm.convert.to.fp16``' intrinsic function performs a conversion from a 17348conventional floating-point type to half precision floating-point format. 17349 17350Arguments: 17351"""""""""" 17352 17353The intrinsic function contains single argument - the value to be 17354converted. 17355 17356Semantics: 17357"""""""""" 17358 17359The '``llvm.convert.to.fp16``' intrinsic function performs a conversion from a 17360conventional floating-point format to half precision floating-point format. The 17361return value is an ``i16`` which contains the converted number. 17362 17363Examples: 17364""""""""" 17365 17366.. code-block:: llvm 17367 17368 %res = call i16 @llvm.convert.to.fp16.f32(float %a) 17369 store i16 %res, i16* @x, align 2 17370 17371.. _int_convert_from_fp16: 17372 17373'``llvm.convert.from.fp16``' Intrinsic 17374^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17375 17376Syntax: 17377""""""" 17378 17379:: 17380 17381 declare float @llvm.convert.from.fp16.f32(i16 %a) 17382 declare double @llvm.convert.from.fp16.f64(i16 %a) 17383 17384Overview: 17385""""""""" 17386 17387The '``llvm.convert.from.fp16``' intrinsic function performs a 17388conversion from half precision floating-point format to single precision 17389floating-point format. 17390 17391Arguments: 17392"""""""""" 17393 17394The intrinsic function contains single argument - the value to be 17395converted. 17396 17397Semantics: 17398"""""""""" 17399 17400The '``llvm.convert.from.fp16``' intrinsic function performs a 17401conversion from half single precision floating-point format to single 17402precision floating-point format. The input half-float value is 17403represented by an ``i16`` value. 17404 17405Examples: 17406""""""""" 17407 17408.. code-block:: llvm 17409 17410 %a = load i16, i16* @x, align 2 17411 %res = call float @llvm.convert.from.fp16(i16 %a) 17412 17413Saturating floating-point to integer conversions 17414------------------------------------------------ 17415 17416The ``fptoui`` and ``fptosi`` instructions return a 17417:ref:`poison value <poisonvalues>` if the rounded-towards-zero value is not 17418representable by the result type. These intrinsics provide an alternative 17419conversion, which will saturate towards the smallest and largest representable 17420integer values instead. 17421 17422'``llvm.fptoui.sat.*``' Intrinsic 17423^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17424 17425Syntax: 17426""""""" 17427 17428This is an overloaded intrinsic. You can use ``llvm.fptoui.sat`` on any 17429floating-point argument type and any integer result type, or vectors thereof. 17430Not all targets may support all types, however. 17431 17432:: 17433 17434 declare i32 @llvm.fptoui.sat.i32.f32(float %f) 17435 declare i19 @llvm.fptoui.sat.i19.f64(double %f) 17436 declare <4 x i100> @llvm.fptoui.sat.v4i100.v4f128(<4 x fp128> %f) 17437 17438Overview: 17439""""""""" 17440 17441This intrinsic converts the argument into an unsigned integer using saturating 17442semantics. 17443 17444Arguments: 17445"""""""""" 17446 17447The argument may be any floating-point or vector of floating-point type. The 17448return value may be any integer or vector of integer type. The number of vector 17449elements in argument and return must be the same. 17450 17451Semantics: 17452"""""""""" 17453 17454The conversion to integer is performed subject to the following rules: 17455 17456- If the argument is any NaN, zero is returned. 17457- If the argument is smaller than zero (this includes negative infinity), 17458 zero is returned. 17459- If the argument is larger than the largest representable unsigned integer of 17460 the result type (this includes positive infinity), the largest representable 17461 unsigned integer is returned. 17462- Otherwise, the result of rounding the argument towards zero is returned. 17463 17464Example: 17465"""""""" 17466 17467.. code-block:: text 17468 17469 %a = call i8 @llvm.fptoui.sat.i8.f32(float 123.9) ; yields i8: 123 17470 %b = call i8 @llvm.fptoui.sat.i8.f32(float -5.7) ; yields i8: 0 17471 %c = call i8 @llvm.fptoui.sat.i8.f32(float 377.0) ; yields i8: 255 17472 %d = call i8 @llvm.fptoui.sat.i8.f32(float 0xFFF8000000000000) ; yields i8: 0 17473 17474'``llvm.fptosi.sat.*``' Intrinsic 17475^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17476 17477Syntax: 17478""""""" 17479 17480This is an overloaded intrinsic. You can use ``llvm.fptosi.sat`` on any 17481floating-point argument type and any integer result type, or vectors thereof. 17482Not all targets may support all types, however. 17483 17484:: 17485 17486 declare i32 @llvm.fptosi.sat.i32.f32(float %f) 17487 declare i19 @llvm.fptosi.sat.i19.f64(double %f) 17488 declare <4 x i100> @llvm.fptosi.sat.v4i100.v4f128(<4 x fp128> %f) 17489 17490Overview: 17491""""""""" 17492 17493This intrinsic converts the argument into a signed integer using saturating 17494semantics. 17495 17496Arguments: 17497"""""""""" 17498 17499The argument may be any floating-point or vector of floating-point type. The 17500return value may be any integer or vector of integer type. The number of vector 17501elements in argument and return must be the same. 17502 17503Semantics: 17504"""""""""" 17505 17506The conversion to integer is performed subject to the following rules: 17507 17508- If the argument is any NaN, zero is returned. 17509- If the argument is smaller than the smallest representable signed integer of 17510 the result type (this includes negative infinity), the smallest 17511 representable signed integer is returned. 17512- If the argument is larger than the largest representable signed integer of 17513 the result type (this includes positive infinity), the largest representable 17514 signed integer is returned. 17515- Otherwise, the result of rounding the argument towards zero is returned. 17516 17517Example: 17518"""""""" 17519 17520.. code-block:: text 17521 17522 %a = call i8 @llvm.fptosi.sat.i8.f32(float 23.9) ; yields i8: 23 17523 %b = call i8 @llvm.fptosi.sat.i8.f32(float -130.8) ; yields i8: -128 17524 %c = call i8 @llvm.fptosi.sat.i8.f32(float 999.0) ; yields i8: 127 17525 %d = call i8 @llvm.fptosi.sat.i8.f32(float 0xFFF8000000000000) ; yields i8: 0 17526 17527.. _dbg_intrinsics: 17528 17529Debugger Intrinsics 17530------------------- 17531 17532The LLVM debugger intrinsics (which all start with ``llvm.dbg.`` 17533prefix), are described in the `LLVM Source Level 17534Debugging <SourceLevelDebugging.html#format-common-intrinsics>`_ 17535document. 17536 17537Exception Handling Intrinsics 17538----------------------------- 17539 17540The LLVM exception handling intrinsics (which all start with 17541``llvm.eh.`` prefix), are described in the `LLVM Exception 17542Handling <ExceptionHandling.html#format-common-intrinsics>`_ document. 17543 17544.. _int_trampoline: 17545 17546Trampoline Intrinsics 17547--------------------- 17548 17549These intrinsics make it possible to excise one parameter, marked with 17550the :ref:`nest <nest>` attribute, from a function. The result is a 17551callable function pointer lacking the nest parameter - the caller does 17552not need to provide a value for it. Instead, the value to use is stored 17553in advance in a "trampoline", a block of memory usually allocated on the 17554stack, which also contains code to splice the nest value into the 17555argument list. This is used to implement the GCC nested function address 17556extension. 17557 17558For example, if the function is ``i32 f(i8* nest %c, i32 %x, i32 %y)`` 17559then the resulting function pointer has signature ``i32 (i32, i32)*``. 17560It can be created as follows: 17561 17562.. code-block:: llvm 17563 17564 %tramp = alloca [10 x i8], align 4 ; size and alignment only correct for X86 17565 %tramp1 = getelementptr [10 x i8], [10 x i8]* %tramp, i32 0, i32 0 17566 call i8* @llvm.init.trampoline(i8* %tramp1, i8* bitcast (i32 (i8*, i32, i32)* @f to i8*), i8* %nval) 17567 %p = call i8* @llvm.adjust.trampoline(i8* %tramp1) 17568 %fp = bitcast i8* %p to i32 (i32, i32)* 17569 17570The call ``%val = call i32 %fp(i32 %x, i32 %y)`` is then equivalent to 17571``%val = call i32 %f(i8* %nval, i32 %x, i32 %y)``. 17572 17573.. _int_it: 17574 17575'``llvm.init.trampoline``' Intrinsic 17576^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17577 17578Syntax: 17579""""""" 17580 17581:: 17582 17583 declare void @llvm.init.trampoline(i8* <tramp>, i8* <func>, i8* <nval>) 17584 17585Overview: 17586""""""""" 17587 17588This fills the memory pointed to by ``tramp`` with executable code, 17589turning it into a trampoline. 17590 17591Arguments: 17592"""""""""" 17593 17594The ``llvm.init.trampoline`` intrinsic takes three arguments, all 17595pointers. The ``tramp`` argument must point to a sufficiently large and 17596sufficiently aligned block of memory; this memory is written to by the 17597intrinsic. Note that the size and the alignment are target-specific - 17598LLVM currently provides no portable way of determining them, so a 17599front-end that generates this intrinsic needs to have some 17600target-specific knowledge. The ``func`` argument must hold a function 17601bitcast to an ``i8*``. 17602 17603Semantics: 17604"""""""""" 17605 17606The block of memory pointed to by ``tramp`` is filled with target 17607dependent code, turning it into a function. Then ``tramp`` needs to be 17608passed to :ref:`llvm.adjust.trampoline <int_at>` to get a pointer which can 17609be :ref:`bitcast (to a new function) and called <int_trampoline>`. The new 17610function's signature is the same as that of ``func`` with any arguments 17611marked with the ``nest`` attribute removed. At most one such ``nest`` 17612argument is allowed, and it must be of pointer type. Calling the new 17613function is equivalent to calling ``func`` with the same argument list, 17614but with ``nval`` used for the missing ``nest`` argument. If, after 17615calling ``llvm.init.trampoline``, the memory pointed to by ``tramp`` is 17616modified, then the effect of any later call to the returned function 17617pointer is undefined. 17618 17619.. _int_at: 17620 17621'``llvm.adjust.trampoline``' Intrinsic 17622^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17623 17624Syntax: 17625""""""" 17626 17627:: 17628 17629 declare i8* @llvm.adjust.trampoline(i8* <tramp>) 17630 17631Overview: 17632""""""""" 17633 17634This performs any required machine-specific adjustment to the address of 17635a trampoline (passed as ``tramp``). 17636 17637Arguments: 17638"""""""""" 17639 17640``tramp`` must point to a block of memory which already has trampoline 17641code filled in by a previous call to 17642:ref:`llvm.init.trampoline <int_it>`. 17643 17644Semantics: 17645"""""""""" 17646 17647On some architectures the address of the code to be executed needs to be 17648different than the address where the trampoline is actually stored. This 17649intrinsic returns the executable address corresponding to ``tramp`` 17650after performing the required machine specific adjustments. The pointer 17651returned can then be :ref:`bitcast and executed <int_trampoline>`. 17652 17653 17654.. _int_vp: 17655 17656Vector Predication Intrinsics 17657----------------------------- 17658VP intrinsics are intended for predicated SIMD/vector code. A typical VP 17659operation takes a vector mask and an explicit vector length parameter as in: 17660 17661:: 17662 17663 <W x T> llvm.vp.<opcode>.*(<W x T> %x, <W x T> %y, <W x i1> %mask, i32 %evl) 17664 17665The vector mask parameter (%mask) always has a vector of `i1` type, for example 17666`<32 x i1>`. The explicit vector length parameter always has the type `i32` and 17667is an unsigned integer value. The explicit vector length parameter (%evl) is in 17668the range: 17669 17670:: 17671 17672 0 <= %evl <= W, where W is the number of vector elements 17673 17674Note that for :ref:`scalable vector types <t_vector>` ``W`` is the runtime 17675length of the vector. 17676 17677The VP intrinsic has undefined behavior if ``%evl > W``. The explicit vector 17678length (%evl) creates a mask, %EVLmask, with all elements ``0 <= i < %evl`` set 17679to True, and all other lanes ``%evl <= i < W`` to False. A new mask %M is 17680calculated with an element-wise AND from %mask and %EVLmask: 17681 17682:: 17683 17684 M = %mask AND %EVLmask 17685 17686A vector operation ``<opcode>`` on vectors ``A`` and ``B`` calculates: 17687 17688:: 17689 17690 A <opcode> B = { A[i] <opcode> B[i] M[i] = True, and 17691 { undef otherwise 17692 17693Optimization Hint 17694^^^^^^^^^^^^^^^^^ 17695 17696Some targets, such as AVX512, do not support the %evl parameter in hardware. 17697The use of an effective %evl is discouraged for those targets. The function 17698``TargetTransformInfo::hasActiveVectorLength()`` returns true when the target 17699has native support for %evl. 17700 17701 17702.. _int_vp_add: 17703 17704'``llvm.vp.add.*``' Intrinsics 17705^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17706 17707Syntax: 17708""""""" 17709This is an overloaded intrinsic. 17710 17711:: 17712 17713 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>) 17714 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>) 17715 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>) 17716 17717Overview: 17718""""""""" 17719 17720Predicated integer addition of two vectors of integers. 17721 17722 17723Arguments: 17724"""""""""" 17725 17726The first two operands and the result have the same vector of integer type. The 17727third operand is the vector mask and has the same number of elements as the 17728result vector type. The fourth operand is the explicit vector length of the 17729operation. 17730 17731Semantics: 17732"""""""""" 17733 17734The '``llvm.vp.add``' intrinsic performs integer addition (:ref:`add <i_add>`) 17735of the first and second vector operand on each enabled lane. The result on 17736disabled lanes is undefined. 17737 17738Examples: 17739""""""""" 17740 17741.. code-block:: llvm 17742 17743 %r = call <4 x i32> @llvm.vp.add.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 17744 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 17745 17746 %t = add <4 x i32> %a, %b 17747 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 17748 17749.. _int_vp_sub: 17750 17751'``llvm.vp.sub.*``' Intrinsics 17752^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17753 17754Syntax: 17755""""""" 17756This is an overloaded intrinsic. 17757 17758:: 17759 17760 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>) 17761 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>) 17762 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>) 17763 17764Overview: 17765""""""""" 17766 17767Predicated integer subtraction of two vectors of integers. 17768 17769 17770Arguments: 17771"""""""""" 17772 17773The first two operands and the result have the same vector of integer type. The 17774third operand is the vector mask and has the same number of elements as the 17775result vector type. The fourth operand is the explicit vector length of the 17776operation. 17777 17778Semantics: 17779"""""""""" 17780 17781The '``llvm.vp.sub``' intrinsic performs integer subtraction 17782(:ref:`sub <i_sub>`) of the first and second vector operand on each enabled 17783lane. The result on disabled lanes is undefined. 17784 17785Examples: 17786""""""""" 17787 17788.. code-block:: llvm 17789 17790 %r = call <4 x i32> @llvm.vp.sub.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 17791 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 17792 17793 %t = sub <4 x i32> %a, %b 17794 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 17795 17796 17797 17798.. _int_vp_mul: 17799 17800'``llvm.vp.mul.*``' Intrinsics 17801^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17802 17803Syntax: 17804""""""" 17805This is an overloaded intrinsic. 17806 17807:: 17808 17809 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>) 17810 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>) 17811 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>) 17812 17813Overview: 17814""""""""" 17815 17816Predicated integer multiplication of two vectors of integers. 17817 17818 17819Arguments: 17820"""""""""" 17821 17822The first two operands and the result have the same vector of integer type. The 17823third operand is the vector mask and has the same number of elements as the 17824result vector type. The fourth operand is the explicit vector length of the 17825operation. 17826 17827Semantics: 17828"""""""""" 17829The '``llvm.vp.mul``' intrinsic performs integer multiplication 17830(:ref:`mul <i_mul>`) of the first and second vector operand on each enabled 17831lane. The result on disabled lanes is undefined. 17832 17833Examples: 17834""""""""" 17835 17836.. code-block:: llvm 17837 17838 %r = call <4 x i32> @llvm.vp.mul.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 17839 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 17840 17841 %t = mul <4 x i32> %a, %b 17842 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 17843 17844 17845.. _int_vp_sdiv: 17846 17847'``llvm.vp.sdiv.*``' Intrinsics 17848^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17849 17850Syntax: 17851""""""" 17852This is an overloaded intrinsic. 17853 17854:: 17855 17856 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>) 17857 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>) 17858 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>) 17859 17860Overview: 17861""""""""" 17862 17863Predicated, signed division of two vectors of integers. 17864 17865 17866Arguments: 17867"""""""""" 17868 17869The first two operands and the result have the same vector of integer type. The 17870third operand is the vector mask and has the same number of elements as the 17871result vector type. The fourth operand is the explicit vector length of the 17872operation. 17873 17874Semantics: 17875"""""""""" 17876 17877The '``llvm.vp.sdiv``' intrinsic performs signed division (:ref:`sdiv <i_sdiv>`) 17878of the first and second vector operand on each enabled lane. The result on 17879disabled lanes is undefined. 17880 17881Examples: 17882""""""""" 17883 17884.. code-block:: llvm 17885 17886 %r = call <4 x i32> @llvm.vp.sdiv.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 17887 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 17888 17889 %t = sdiv <4 x i32> %a, %b 17890 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 17891 17892 17893.. _int_vp_udiv: 17894 17895'``llvm.vp.udiv.*``' Intrinsics 17896^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17897 17898Syntax: 17899""""""" 17900This is an overloaded intrinsic. 17901 17902:: 17903 17904 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>) 17905 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>) 17906 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>) 17907 17908Overview: 17909""""""""" 17910 17911Predicated, unsigned division of two vectors of integers. 17912 17913 17914Arguments: 17915"""""""""" 17916 17917The 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. 17918 17919Semantics: 17920"""""""""" 17921 17922The '``llvm.vp.udiv``' intrinsic performs unsigned division 17923(:ref:`udiv <i_udiv>`) of the first and second vector operand on each enabled 17924lane. The result on disabled lanes is undefined. 17925 17926Examples: 17927""""""""" 17928 17929.. code-block:: llvm 17930 17931 %r = call <4 x i32> @llvm.vp.udiv.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 17932 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 17933 17934 %t = udiv <4 x i32> %a, %b 17935 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 17936 17937 17938 17939.. _int_vp_srem: 17940 17941'``llvm.vp.srem.*``' Intrinsics 17942^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17943 17944Syntax: 17945""""""" 17946This is an overloaded intrinsic. 17947 17948:: 17949 17950 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>) 17951 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>) 17952 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>) 17953 17954Overview: 17955""""""""" 17956 17957Predicated computations of the signed remainder of two integer vectors. 17958 17959 17960Arguments: 17961"""""""""" 17962 17963The first two operands and the result have the same vector of integer type. The 17964third operand is the vector mask and has the same number of elements as the 17965result vector type. The fourth operand is the explicit vector length of the 17966operation. 17967 17968Semantics: 17969"""""""""" 17970 17971The '``llvm.vp.srem``' intrinsic computes the remainder of the signed division 17972(:ref:`srem <i_srem>`) of the first and second vector operand on each enabled 17973lane. The result on disabled lanes is undefined. 17974 17975Examples: 17976""""""""" 17977 17978.. code-block:: llvm 17979 17980 %r = call <4 x i32> @llvm.vp.srem.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 17981 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 17982 17983 %t = srem <4 x i32> %a, %b 17984 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 17985 17986 17987 17988.. _int_vp_urem: 17989 17990'``llvm.vp.urem.*``' Intrinsics 17991^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17992 17993Syntax: 17994""""""" 17995This is an overloaded intrinsic. 17996 17997:: 17998 17999 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>) 18000 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>) 18001 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>) 18002 18003Overview: 18004""""""""" 18005 18006Predicated computation of the unsigned remainder of two integer vectors. 18007 18008 18009Arguments: 18010"""""""""" 18011 18012The first two operands and the result have the same vector of integer type. The 18013third operand is the vector mask and has the same number of elements as the 18014result vector type. The fourth operand is the explicit vector length of the 18015operation. 18016 18017Semantics: 18018"""""""""" 18019 18020The '``llvm.vp.urem``' intrinsic computes the remainder of the unsigned division 18021(:ref:`urem <i_urem>`) of the first and second vector operand on each enabled 18022lane. The result on disabled lanes is undefined. 18023 18024Examples: 18025""""""""" 18026 18027.. code-block:: llvm 18028 18029 %r = call <4 x i32> @llvm.vp.urem.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 18030 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18031 18032 %t = urem <4 x i32> %a, %b 18033 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 18034 18035 18036.. _int_vp_ashr: 18037 18038'``llvm.vp.ashr.*``' Intrinsics 18039^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18040 18041Syntax: 18042""""""" 18043This is an overloaded intrinsic. 18044 18045:: 18046 18047 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>) 18048 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>) 18049 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>) 18050 18051Overview: 18052""""""""" 18053 18054Vector-predicated arithmetic right-shift. 18055 18056 18057Arguments: 18058"""""""""" 18059 18060The first two operands and the result have the same vector of integer type. The 18061third operand is the vector mask and has the same number of elements as the 18062result vector type. The fourth operand is the explicit vector length of the 18063operation. 18064 18065Semantics: 18066"""""""""" 18067 18068The '``llvm.vp.ashr``' intrinsic computes the arithmetic right shift 18069(:ref:`ashr <i_ashr>`) of the first operand by the second operand on each 18070enabled lane. The result on disabled lanes is undefined. 18071 18072Examples: 18073""""""""" 18074 18075.. code-block:: llvm 18076 18077 %r = call <4 x i32> @llvm.vp.ashr.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 18078 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18079 18080 %t = ashr <4 x i32> %a, %b 18081 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 18082 18083 18084.. _int_vp_lshr: 18085 18086 18087'``llvm.vp.lshr.*``' Intrinsics 18088^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18089 18090Syntax: 18091""""""" 18092This is an overloaded intrinsic. 18093 18094:: 18095 18096 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>) 18097 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>) 18098 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>) 18099 18100Overview: 18101""""""""" 18102 18103Vector-predicated logical right-shift. 18104 18105 18106Arguments: 18107"""""""""" 18108 18109The first two operands and the result have the same vector of integer type. The 18110third operand is the vector mask and has the same number of elements as the 18111result vector type. The fourth operand is the explicit vector length of the 18112operation. 18113 18114Semantics: 18115"""""""""" 18116 18117The '``llvm.vp.lshr``' intrinsic computes the logical right shift 18118(:ref:`lshr <i_lshr>`) of the first operand by the second operand on each 18119enabled lane. The result on disabled lanes is undefined. 18120 18121Examples: 18122""""""""" 18123 18124.. code-block:: llvm 18125 18126 %r = call <4 x i32> @llvm.vp.lshr.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 18127 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18128 18129 %t = lshr <4 x i32> %a, %b 18130 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 18131 18132 18133.. _int_vp_shl: 18134 18135'``llvm.vp.shl.*``' Intrinsics 18136^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18137 18138Syntax: 18139""""""" 18140This is an overloaded intrinsic. 18141 18142:: 18143 18144 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>) 18145 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>) 18146 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>) 18147 18148Overview: 18149""""""""" 18150 18151Vector-predicated left shift. 18152 18153 18154Arguments: 18155"""""""""" 18156 18157The first two operands and the result have the same vector of integer type. The 18158third operand is the vector mask and has the same number of elements as the 18159result vector type. The fourth operand is the explicit vector length of the 18160operation. 18161 18162Semantics: 18163"""""""""" 18164 18165The '``llvm.vp.shl``' intrinsic computes the left shift (:ref:`shl <i_shl>`) of 18166the first operand by the second operand on each enabled lane. The result on 18167disabled lanes is undefined. 18168 18169Examples: 18170""""""""" 18171 18172.. code-block:: llvm 18173 18174 %r = call <4 x i32> @llvm.vp.shl.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 18175 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18176 18177 %t = shl <4 x i32> %a, %b 18178 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 18179 18180 18181.. _int_vp_or: 18182 18183'``llvm.vp.or.*``' Intrinsics 18184^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18185 18186Syntax: 18187""""""" 18188This is an overloaded intrinsic. 18189 18190:: 18191 18192 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>) 18193 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>) 18194 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>) 18195 18196Overview: 18197""""""""" 18198 18199Vector-predicated or. 18200 18201 18202Arguments: 18203"""""""""" 18204 18205The first two operands and the result have the same vector of integer type. The 18206third operand is the vector mask and has the same number of elements as the 18207result vector type. The fourth operand is the explicit vector length of the 18208operation. 18209 18210Semantics: 18211"""""""""" 18212 18213The '``llvm.vp.or``' intrinsic performs a bitwise or (:ref:`or <i_or>`) of the 18214first two operands on each enabled lane. The result on disabled lanes is 18215undefined. 18216 18217Examples: 18218""""""""" 18219 18220.. code-block:: llvm 18221 18222 %r = call <4 x i32> @llvm.vp.or.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 18223 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18224 18225 %t = or <4 x i32> %a, %b 18226 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 18227 18228 18229.. _int_vp_and: 18230 18231'``llvm.vp.and.*``' Intrinsics 18232^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18233 18234Syntax: 18235""""""" 18236This is an overloaded intrinsic. 18237 18238:: 18239 18240 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>) 18241 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>) 18242 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>) 18243 18244Overview: 18245""""""""" 18246 18247Vector-predicated and. 18248 18249 18250Arguments: 18251"""""""""" 18252 18253The first two operands and the result have the same vector of integer type. The 18254third operand is the vector mask and has the same number of elements as the 18255result vector type. The fourth operand is the explicit vector length of the 18256operation. 18257 18258Semantics: 18259"""""""""" 18260 18261The '``llvm.vp.and``' intrinsic performs a bitwise and (:ref:`and <i_or>`) of 18262the first two operands on each enabled lane. The result on disabled lanes is 18263undefined. 18264 18265Examples: 18266""""""""" 18267 18268.. code-block:: llvm 18269 18270 %r = call <4 x i32> @llvm.vp.and.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 18271 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18272 18273 %t = and <4 x i32> %a, %b 18274 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 18275 18276 18277.. _int_vp_xor: 18278 18279'``llvm.vp.xor.*``' Intrinsics 18280^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18281 18282Syntax: 18283""""""" 18284This is an overloaded intrinsic. 18285 18286:: 18287 18288 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>) 18289 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>) 18290 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>) 18291 18292Overview: 18293""""""""" 18294 18295Vector-predicated, bitwise xor. 18296 18297 18298Arguments: 18299"""""""""" 18300 18301The first two operands and the result have the same vector of integer type. The 18302third operand is the vector mask and has the same number of elements as the 18303result vector type. The fourth operand is the explicit vector length of the 18304operation. 18305 18306Semantics: 18307"""""""""" 18308 18309The '``llvm.vp.xor``' intrinsic performs a bitwise xor (:ref:`xor <i_xor>`) of 18310the first two operands on each enabled lane. 18311The result on disabled lanes is undefined. 18312 18313Examples: 18314""""""""" 18315 18316.. code-block:: llvm 18317 18318 %r = call <4 x i32> @llvm.vp.xor.v4i32(<4 x i32> %a, <4 x i32> %b, <4 x i1> %mask, i32 %evl) 18319 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18320 18321 %t = xor <4 x i32> %a, %b 18322 %also.r = select <4 x i1> %mask, <4 x i32> %t, <4 x i32> undef 18323 18324 18325.. _int_vp_fadd: 18326 18327'``llvm.vp.fadd.*``' Intrinsics 18328^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18329 18330Syntax: 18331""""""" 18332This is an overloaded intrinsic. 18333 18334:: 18335 18336 declare <16 x float> @llvm.vp.fadd.v16f32 (<16 x float> <left_op>, <16 x float> <right_op>, <16 x i1> <mask>, i32 <vector_length>) 18337 declare <vscale x 4 x float> @llvm.vp.fadd.nxv4f32 (<vscale x 4 x float> <left_op>, <vscale x 4 x float> <right_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>) 18338 declare <256 x double> @llvm.vp.fadd.v256f64 (<256 x double> <left_op>, <256 x double> <right_op>, <256 x i1> <mask>, i32 <vector_length>) 18339 18340Overview: 18341""""""""" 18342 18343Predicated floating-point addition of two vectors of floating-point values. 18344 18345 18346Arguments: 18347"""""""""" 18348 18349The first two operands and the result have the same vector of floating-point type. The 18350third operand is the vector mask and has the same number of elements as the 18351result vector type. The fourth operand is the explicit vector length of the 18352operation. 18353 18354Semantics: 18355"""""""""" 18356 18357The '``llvm.vp.fadd``' intrinsic performs floating-point addition (:ref:`add <i_fadd>`) 18358of the first and second vector operand on each enabled lane. The result on 18359disabled lanes is undefined. The operation is performed in the default 18360floating-point environment. 18361 18362Examples: 18363""""""""" 18364 18365.. code-block:: llvm 18366 18367 %r = call <4 x float> @llvm.vp.fadd.v4f32(<4 x float> %a, <4 x float> %b, <4 x i1> %mask, i32 %evl) 18368 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18369 18370 %t = fadd <4 x float> %a, %b 18371 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> undef 18372 18373 18374.. _int_vp_fsub: 18375 18376'``llvm.vp.fsub.*``' Intrinsics 18377^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18378 18379Syntax: 18380""""""" 18381This is an overloaded intrinsic. 18382 18383:: 18384 18385 declare <16 x float> @llvm.vp.fsub.v16f32 (<16 x float> <left_op>, <16 x float> <right_op>, <16 x i1> <mask>, i32 <vector_length>) 18386 declare <vscale x 4 x float> @llvm.vp.fsub.nxv4f32 (<vscale x 4 x float> <left_op>, <vscale x 4 x float> <right_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>) 18387 declare <256 x double> @llvm.vp.fsub.v256f64 (<256 x double> <left_op>, <256 x double> <right_op>, <256 x i1> <mask>, i32 <vector_length>) 18388 18389Overview: 18390""""""""" 18391 18392Predicated floating-point subtraction of two vectors of floating-point values. 18393 18394 18395Arguments: 18396"""""""""" 18397 18398The first two operands and the result have the same vector of floating-point type. The 18399third operand is the vector mask and has the same number of elements as the 18400result vector type. The fourth operand is the explicit vector length of the 18401operation. 18402 18403Semantics: 18404"""""""""" 18405 18406The '``llvm.vp.fsub``' intrinsic performs floating-point subtraction (:ref:`add <i_fsub>`) 18407of the first and second vector operand on each enabled lane. The result on 18408disabled lanes is undefined. The operation is performed in the default 18409floating-point environment. 18410 18411Examples: 18412""""""""" 18413 18414.. code-block:: llvm 18415 18416 %r = call <4 x float> @llvm.vp.fsub.v4f32(<4 x float> %a, <4 x float> %b, <4 x i1> %mask, i32 %evl) 18417 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18418 18419 %t = fsub <4 x float> %a, %b 18420 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> undef 18421 18422 18423.. _int_vp_fmul: 18424 18425'``llvm.vp.fmul.*``' Intrinsics 18426^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18427 18428Syntax: 18429""""""" 18430This is an overloaded intrinsic. 18431 18432:: 18433 18434 declare <16 x float> @llvm.vp.fmul.v16f32 (<16 x float> <left_op>, <16 x float> <right_op>, <16 x i1> <mask>, i32 <vector_length>) 18435 declare <vscale x 4 x float> @llvm.vp.fmul.nxv4f32 (<vscale x 4 x float> <left_op>, <vscale x 4 x float> <right_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>) 18436 declare <256 x double> @llvm.vp.fmul.v256f64 (<256 x double> <left_op>, <256 x double> <right_op>, <256 x i1> <mask>, i32 <vector_length>) 18437 18438Overview: 18439""""""""" 18440 18441Predicated floating-point multiplication of two vectors of floating-point values. 18442 18443 18444Arguments: 18445"""""""""" 18446 18447The first two operands and the result have the same vector of floating-point type. The 18448third operand is the vector mask and has the same number of elements as the 18449result vector type. The fourth operand is the explicit vector length of the 18450operation. 18451 18452Semantics: 18453"""""""""" 18454 18455The '``llvm.vp.fmul``' intrinsic performs floating-point multiplication (:ref:`add <i_fmul>`) 18456of the first and second vector operand on each enabled lane. The result on 18457disabled lanes is undefined. The operation is performed in the default 18458floating-point environment. 18459 18460Examples: 18461""""""""" 18462 18463.. code-block:: llvm 18464 18465 %r = call <4 x float> @llvm.vp.fmul.v4f32(<4 x float> %a, <4 x float> %b, <4 x i1> %mask, i32 %evl) 18466 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18467 18468 %t = fmul <4 x float> %a, %b 18469 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> undef 18470 18471 18472.. _int_vp_fdiv: 18473 18474'``llvm.vp.fdiv.*``' Intrinsics 18475^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18476 18477Syntax: 18478""""""" 18479This is an overloaded intrinsic. 18480 18481:: 18482 18483 declare <16 x float> @llvm.vp.fdiv.v16f32 (<16 x float> <left_op>, <16 x float> <right_op>, <16 x i1> <mask>, i32 <vector_length>) 18484 declare <vscale x 4 x float> @llvm.vp.fdiv.nxv4f32 (<vscale x 4 x float> <left_op>, <vscale x 4 x float> <right_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>) 18485 declare <256 x double> @llvm.vp.fdiv.v256f64 (<256 x double> <left_op>, <256 x double> <right_op>, <256 x i1> <mask>, i32 <vector_length>) 18486 18487Overview: 18488""""""""" 18489 18490Predicated floating-point division of two vectors of floating-point values. 18491 18492 18493Arguments: 18494"""""""""" 18495 18496The first two operands and the result have the same vector of floating-point type. The 18497third operand is the vector mask and has the same number of elements as the 18498result vector type. The fourth operand is the explicit vector length of the 18499operation. 18500 18501Semantics: 18502"""""""""" 18503 18504The '``llvm.vp.fdiv``' intrinsic performs floating-point division (:ref:`add <i_fdiv>`) 18505of the first and second vector operand on each enabled lane. The result on 18506disabled lanes is undefined. The operation is performed in the default 18507floating-point environment. 18508 18509Examples: 18510""""""""" 18511 18512.. code-block:: llvm 18513 18514 %r = call <4 x float> @llvm.vp.fdiv.v4f32(<4 x float> %a, <4 x float> %b, <4 x i1> %mask, i32 %evl) 18515 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18516 18517 %t = fdiv <4 x float> %a, %b 18518 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> undef 18519 18520 18521.. _int_vp_frem: 18522 18523'``llvm.vp.frem.*``' Intrinsics 18524^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18525 18526Syntax: 18527""""""" 18528This is an overloaded intrinsic. 18529 18530:: 18531 18532 declare <16 x float> @llvm.vp.frem.v16f32 (<16 x float> <left_op>, <16 x float> <right_op>, <16 x i1> <mask>, i32 <vector_length>) 18533 declare <vscale x 4 x float> @llvm.vp.frem.nxv4f32 (<vscale x 4 x float> <left_op>, <vscale x 4 x float> <right_op>, <vscale x 4 x i1> <mask>, i32 <vector_length>) 18534 declare <256 x double> @llvm.vp.frem.v256f64 (<256 x double> <left_op>, <256 x double> <right_op>, <256 x i1> <mask>, i32 <vector_length>) 18535 18536Overview: 18537""""""""" 18538 18539Predicated floating-point remainder of two vectors of floating-point values. 18540 18541 18542Arguments: 18543"""""""""" 18544 18545The first two operands and the result have the same vector of floating-point type. The 18546third operand is the vector mask and has the same number of elements as the 18547result vector type. The fourth operand is the explicit vector length of the 18548operation. 18549 18550Semantics: 18551"""""""""" 18552 18553The '``llvm.vp.frem``' intrinsic performs floating-point remainder (:ref:`add <i_frem>`) 18554of the first and second vector operand on each enabled lane. The result on 18555disabled lanes is undefined. The operation is performed in the default 18556floating-point environment. 18557 18558Examples: 18559""""""""" 18560 18561.. code-block:: llvm 18562 18563 %r = call <4 x float> @llvm.vp.frem.v4f32(<4 x float> %a, <4 x float> %b, <4 x i1> %mask, i32 %evl) 18564 ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r 18565 18566 %t = frem <4 x float> %a, %b 18567 %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> undef 18568 18569 18570 18571.. _int_get_active_lane_mask: 18572 18573'``llvm.get.active.lane.mask.*``' Intrinsics 18574^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18575 18576Syntax: 18577""""""" 18578This is an overloaded intrinsic. 18579 18580:: 18581 18582 declare <4 x i1> @llvm.get.active.lane.mask.v4i1.i32(i32 %base, i32 %n) 18583 declare <8 x i1> @llvm.get.active.lane.mask.v8i1.i64(i64 %base, i64 %n) 18584 declare <16 x i1> @llvm.get.active.lane.mask.v16i1.i64(i64 %base, i64 %n) 18585 declare <vscale x 16 x i1> @llvm.get.active.lane.mask.nxv16i1.i64(i64 %base, i64 %n) 18586 18587 18588Overview: 18589""""""""" 18590 18591Create a mask representing active and inactive vector lanes. 18592 18593 18594Arguments: 18595"""""""""" 18596 18597Both operands have the same scalar integer type. The result is a vector with 18598the i1 element type. 18599 18600Semantics: 18601"""""""""" 18602 18603The '``llvm.get.active.lane.mask.*``' intrinsics are semantically equivalent 18604to: 18605 18606:: 18607 18608 %m[i] = icmp ult (%base + i), %n 18609 18610where ``%m`` is a vector (mask) of active/inactive lanes with its elements 18611indexed by ``i``, and ``%base``, ``%n`` are the two arguments to 18612``llvm.get.active.lane.mask.*``, ``%icmp`` is an integer compare and ``ult`` 18613the unsigned less-than comparison operator. Overflow cannot occur in 18614``(%base + i)`` and its comparison against ``%n`` as it is performed in integer 18615numbers and not in machine numbers. If ``%n`` is ``0``, then the result is a 18616poison value. The above is equivalent to: 18617 18618:: 18619 18620 %m = @llvm.get.active.lane.mask(%base, %n) 18621 18622This can, for example, be emitted by the loop vectorizer in which case 18623``%base`` is the first element of the vector induction variable (VIV) and 18624``%n`` is the loop tripcount. Thus, these intrinsics perform an element-wise 18625less than comparison of VIV with the loop tripcount, producing a mask of 18626true/false values representing active/inactive vector lanes, except if the VIV 18627overflows in which case they return false in the lanes where the VIV overflows. 18628The arguments are scalar types to accommodate scalable vector types, for which 18629it is unknown what the type of the step vector needs to be that enumerate its 18630lanes without overflow. 18631 18632This mask ``%m`` can e.g. be used in masked load/store instructions. These 18633intrinsics provide a hint to the backend. I.e., for a vector loop, the 18634back-edge taken count of the original scalar loop is explicit as the second 18635argument. 18636 18637 18638Examples: 18639""""""""" 18640 18641.. code-block:: llvm 18642 18643 %active.lane.mask = call <4 x i1> @llvm.get.active.lane.mask.v4i1.i64(i64 %elem0, i64 429) 18644 %wide.masked.load = call <4 x i32> @llvm.masked.load.v4i32.p0v4i32(<4 x i32>* %3, i32 4, <4 x i1> %active.lane.mask, <4 x i32> undef) 18645 18646 18647.. _int_mload_mstore: 18648 18649Masked Vector Load and Store Intrinsics 18650--------------------------------------- 18651 18652LLVM 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. 18653 18654.. _int_mload: 18655 18656'``llvm.masked.load.*``' Intrinsics 18657^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18658 18659Syntax: 18660""""""" 18661This is an overloaded intrinsic. The loaded data is a vector of any integer, floating-point or pointer data type. 18662 18663:: 18664 18665 declare <16 x float> @llvm.masked.load.v16f32.p0v16f32 (<16 x float>* <ptr>, i32 <alignment>, <16 x i1> <mask>, <16 x float> <passthru>) 18666 declare <2 x double> @llvm.masked.load.v2f64.p0v2f64 (<2 x double>* <ptr>, i32 <alignment>, <2 x i1> <mask>, <2 x double> <passthru>) 18667 ;; The data is a vector of pointers to double 18668 declare <8 x double*> @llvm.masked.load.v8p0f64.p0v8p0f64 (<8 x double*>* <ptr>, i32 <alignment>, <8 x i1> <mask>, <8 x double*> <passthru>) 18669 ;; The data is a vector of function pointers 18670 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>) 18671 18672Overview: 18673""""""""" 18674 18675Reads 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. 18676 18677 18678Arguments: 18679"""""""""" 18680 18681The 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. 18682 18683Semantics: 18684"""""""""" 18685 18686The '``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. 18687The 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. 18688 18689 18690:: 18691 18692 %res = call <16 x float> @llvm.masked.load.v16f32.p0v16f32 (<16 x float>* %ptr, i32 4, <16 x i1>%mask, <16 x float> %passthru) 18693 18694 ;; The result of the two following instructions is identical aside from potential memory access exception 18695 %loadlal = load <16 x float>, <16 x float>* %ptr, align 4 18696 %res = select <16 x i1> %mask, <16 x float> %loadlal, <16 x float> %passthru 18697 18698.. _int_mstore: 18699 18700'``llvm.masked.store.*``' Intrinsics 18701^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18702 18703Syntax: 18704""""""" 18705This is an overloaded intrinsic. The data stored in memory is a vector of any integer, floating-point or pointer data type. 18706 18707:: 18708 18709 declare void @llvm.masked.store.v8i32.p0v8i32 (<8 x i32> <value>, <8 x i32>* <ptr>, i32 <alignment>, <8 x i1> <mask>) 18710 declare void @llvm.masked.store.v16f32.p0v16f32 (<16 x float> <value>, <16 x float>* <ptr>, i32 <alignment>, <16 x i1> <mask>) 18711 ;; The data is a vector of pointers to double 18712 declare void @llvm.masked.store.v8p0f64.p0v8p0f64 (<8 x double*> <value>, <8 x double*>* <ptr>, i32 <alignment>, <8 x i1> <mask>) 18713 ;; The data is a vector of function pointers 18714 declare void @llvm.masked.store.v4p0f_i32f.p0v4p0f_i32f (<4 x i32 ()*> <value>, <4 x i32 ()*>* <ptr>, i32 <alignment>, <4 x i1> <mask>) 18715 18716Overview: 18717""""""""" 18718 18719Writes 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. 18720 18721Arguments: 18722"""""""""" 18723 18724The 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. 18725 18726 18727Semantics: 18728"""""""""" 18729 18730The '``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. 18731The 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. 18732 18733:: 18734 18735 call void @llvm.masked.store.v16f32.p0v16f32(<16 x float> %value, <16 x float>* %ptr, i32 4, <16 x i1> %mask) 18736 18737 ;; The result of the following instructions is identical aside from potential data races and memory access exceptions 18738 %oldval = load <16 x float>, <16 x float>* %ptr, align 4 18739 %res = select <16 x i1> %mask, <16 x float> %value, <16 x float> %oldval 18740 store <16 x float> %res, <16 x float>* %ptr, align 4 18741 18742 18743Masked Vector Gather and Scatter Intrinsics 18744------------------------------------------- 18745 18746LLVM 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. 18747 18748.. _int_mgather: 18749 18750'``llvm.masked.gather.*``' Intrinsics 18751^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18752 18753Syntax: 18754""""""" 18755This 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. 18756 18757:: 18758 18759 declare <16 x float> @llvm.masked.gather.v16f32.v16p0f32 (<16 x float*> <ptrs>, i32 <alignment>, <16 x i1> <mask>, <16 x float> <passthru>) 18760 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>) 18761 declare <8 x float*> @llvm.masked.gather.v8p0f32.v8p0p0f32 (<8 x float**> <ptrs>, i32 <alignment>, <8 x i1> <mask>, <8 x float*> <passthru>) 18762 18763Overview: 18764""""""""" 18765 18766Reads 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. 18767 18768 18769Arguments: 18770"""""""""" 18771 18772The 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. 18773 18774Semantics: 18775"""""""""" 18776 18777The '``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. 18778The 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. 18779 18780 18781:: 18782 18783 %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) 18784 18785 ;; The gather with all-true mask is equivalent to the following instruction sequence 18786 %ptr0 = extractelement <4 x double*> %ptrs, i32 0 18787 %ptr1 = extractelement <4 x double*> %ptrs, i32 1 18788 %ptr2 = extractelement <4 x double*> %ptrs, i32 2 18789 %ptr3 = extractelement <4 x double*> %ptrs, i32 3 18790 18791 %val0 = load double, double* %ptr0, align 8 18792 %val1 = load double, double* %ptr1, align 8 18793 %val2 = load double, double* %ptr2, align 8 18794 %val3 = load double, double* %ptr3, align 8 18795 18796 %vec0 = insertelement <4 x double>undef, %val0, 0 18797 %vec01 = insertelement <4 x double>%vec0, %val1, 1 18798 %vec012 = insertelement <4 x double>%vec01, %val2, 2 18799 %vec0123 = insertelement <4 x double>%vec012, %val3, 3 18800 18801.. _int_mscatter: 18802 18803'``llvm.masked.scatter.*``' Intrinsics 18804^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18805 18806Syntax: 18807""""""" 18808This 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. 18809 18810:: 18811 18812 declare void @llvm.masked.scatter.v8i32.v8p0i32 (<8 x i32> <value>, <8 x i32*> <ptrs>, i32 <alignment>, <8 x i1> <mask>) 18813 declare void @llvm.masked.scatter.v16f32.v16p1f32 (<16 x float> <value>, <16 x float addrspace(1)*> <ptrs>, i32 <alignment>, <16 x i1> <mask>) 18814 declare void @llvm.masked.scatter.v4p0f64.v4p0p0f64 (<4 x double*> <value>, <4 x double**> <ptrs>, i32 <alignment>, <4 x i1> <mask>) 18815 18816Overview: 18817""""""""" 18818 18819Writes 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. 18820 18821Arguments: 18822"""""""""" 18823 18824The 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. 18825 18826Semantics: 18827"""""""""" 18828 18829The '``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. 18830 18831:: 18832 18833 ;; This instruction unconditionally stores data vector in multiple addresses 18834 call @llvm.masked.scatter.v8i32.v8p0i32 (<8 x i32> %value, <8 x i32*> %ptrs, i32 4, <8 x i1> <true, true, .. true>) 18835 18836 ;; It is equivalent to a list of scalar stores 18837 %val0 = extractelement <8 x i32> %value, i32 0 18838 %val1 = extractelement <8 x i32> %value, i32 1 18839 .. 18840 %val7 = extractelement <8 x i32> %value, i32 7 18841 %ptr0 = extractelement <8 x i32*> %ptrs, i32 0 18842 %ptr1 = extractelement <8 x i32*> %ptrs, i32 1 18843 .. 18844 %ptr7 = extractelement <8 x i32*> %ptrs, i32 7 18845 ;; Note: the order of the following stores is important when they overlap: 18846 store i32 %val0, i32* %ptr0, align 4 18847 store i32 %val1, i32* %ptr1, align 4 18848 .. 18849 store i32 %val7, i32* %ptr7, align 4 18850 18851 18852Masked Vector Expanding Load and Compressing Store Intrinsics 18853------------------------------------------------------------- 18854 18855LLVM 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>`. 18856 18857.. _int_expandload: 18858 18859'``llvm.masked.expandload.*``' Intrinsics 18860^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18861 18862Syntax: 18863""""""" 18864This 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. 18865 18866:: 18867 18868 declare <16 x float> @llvm.masked.expandload.v16f32 (float* <ptr>, <16 x i1> <mask>, <16 x float> <passthru>) 18869 declare <2 x i64> @llvm.masked.expandload.v2i64 (i64* <ptr>, <2 x i1> <mask>, <2 x i64> <passthru>) 18870 18871Overview: 18872""""""""" 18873 18874Reads 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. 18875 18876 18877Arguments: 18878"""""""""" 18879 18880The 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. 18881 18882Semantics: 18883"""""""""" 18884 18885The '``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: 18886 18887.. code-block:: c 18888 18889 // In this loop we load from B and spread the elements into array A. 18890 double *A, B; int *C; 18891 for (int i = 0; i < size; ++i) { 18892 if (C[i] != 0) 18893 A[i] = B[j++]; 18894 } 18895 18896 18897.. code-block:: llvm 18898 18899 ; Load several elements from array B and expand them in a vector. 18900 ; The number of loaded elements is equal to the number of '1' elements in the Mask. 18901 %Tmp = call <8 x double> @llvm.masked.expandload.v8f64(double* %Bptr, <8 x i1> %Mask, <8 x double> undef) 18902 ; Store the result in A 18903 call void @llvm.masked.store.v8f64.p0v8f64(<8 x double> %Tmp, <8 x double>* %Aptr, i32 8, <8 x i1> %Mask) 18904 18905 ; %Bptr should be increased on each iteration according to the number of '1' elements in the Mask. 18906 %MaskI = bitcast <8 x i1> %Mask to i8 18907 %MaskIPopcnt = call i8 @llvm.ctpop.i8(i8 %MaskI) 18908 %MaskI64 = zext i8 %MaskIPopcnt to i64 18909 %BNextInd = add i64 %BInd, %MaskI64 18910 18911 18912Other targets may support this intrinsic differently, for example, by lowering it into a sequence of conditional scalar load operations and shuffles. 18913If all mask elements are '1', the intrinsic behavior is equivalent to the regular unmasked vector load. 18914 18915.. _int_compressstore: 18916 18917'``llvm.masked.compressstore.*``' Intrinsics 18918^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18919 18920Syntax: 18921""""""" 18922This 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. 18923 18924:: 18925 18926 declare void @llvm.masked.compressstore.v8i32 (<8 x i32> <value>, i32* <ptr>, <8 x i1> <mask>) 18927 declare void @llvm.masked.compressstore.v16f32 (<16 x float> <value>, float* <ptr>, <16 x i1> <mask>) 18928 18929Overview: 18930""""""""" 18931 18932Selects 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. 18933 18934Arguments: 18935"""""""""" 18936 18937The 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. 18938 18939 18940Semantics: 18941"""""""""" 18942 18943The '``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: 18944 18945.. code-block:: c 18946 18947 // In this loop we load elements from A and store them consecutively in B 18948 double *A, B; int *C; 18949 for (int i = 0; i < size; ++i) { 18950 if (C[i] != 0) 18951 B[j++] = A[i] 18952 } 18953 18954 18955.. code-block:: llvm 18956 18957 ; Load elements from A. 18958 %Tmp = call <8 x double> @llvm.masked.load.v8f64.p0v8f64(<8 x double>* %Aptr, i32 8, <8 x i1> %Mask, <8 x double> undef) 18959 ; Store all selected elements consecutively in array B 18960 call <void> @llvm.masked.compressstore.v8f64(<8 x double> %Tmp, double* %Bptr, <8 x i1> %Mask) 18961 18962 ; %Bptr should be increased on each iteration according to the number of '1' elements in the Mask. 18963 %MaskI = bitcast <8 x i1> %Mask to i8 18964 %MaskIPopcnt = call i8 @llvm.ctpop.i8(i8 %MaskI) 18965 %MaskI64 = zext i8 %MaskIPopcnt to i64 18966 %BNextInd = add i64 %BInd, %MaskI64 18967 18968 18969Other targets may support this intrinsic differently, for example, by lowering it into a sequence of branches that guard scalar store operations. 18970 18971 18972Memory Use Markers 18973------------------ 18974 18975This class of intrinsics provides information about the 18976:ref:`lifetime of memory objects <objectlifetime>` and ranges where variables 18977are immutable. 18978 18979.. _int_lifestart: 18980 18981'``llvm.lifetime.start``' Intrinsic 18982^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18983 18984Syntax: 18985""""""" 18986 18987:: 18988 18989 declare void @llvm.lifetime.start(i64 <size>, i8* nocapture <ptr>) 18990 18991Overview: 18992""""""""" 18993 18994The '``llvm.lifetime.start``' intrinsic specifies the start of a memory 18995object's lifetime. 18996 18997Arguments: 18998"""""""""" 18999 19000The first argument is a constant integer representing the size of the 19001object, or -1 if it is variable sized. The second argument is a pointer 19002to the object. 19003 19004Semantics: 19005"""""""""" 19006 19007If ``ptr`` is a stack-allocated object and it points to the first byte of 19008the object, the object is initially marked as dead. 19009``ptr`` is conservatively considered as a non-stack-allocated object if 19010the stack coloring algorithm that is used in the optimization pipeline cannot 19011conclude that ``ptr`` is a stack-allocated object. 19012 19013After '``llvm.lifetime.start``', the stack object that ``ptr`` points is marked 19014as alive and has an uninitialized value. 19015The stack object is marked as dead when either 19016:ref:`llvm.lifetime.end <int_lifeend>` to the alloca is executed or the 19017function returns. 19018 19019After :ref:`llvm.lifetime.end <int_lifeend>` is called, 19020'``llvm.lifetime.start``' on the stack object can be called again. 19021The second '``llvm.lifetime.start``' call marks the object as alive, but it 19022does not change the address of the object. 19023 19024If ``ptr`` is a non-stack-allocated object, it does not point to the first 19025byte of the object or it is a stack object that is already alive, it simply 19026fills all bytes of the object with ``poison``. 19027 19028 19029.. _int_lifeend: 19030 19031'``llvm.lifetime.end``' Intrinsic 19032^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19033 19034Syntax: 19035""""""" 19036 19037:: 19038 19039 declare void @llvm.lifetime.end(i64 <size>, i8* nocapture <ptr>) 19040 19041Overview: 19042""""""""" 19043 19044The '``llvm.lifetime.end``' intrinsic specifies the end of a memory object's 19045lifetime. 19046 19047Arguments: 19048"""""""""" 19049 19050The first argument is a constant integer representing the size of the 19051object, or -1 if it is variable sized. The second argument is a pointer 19052to the object. 19053 19054Semantics: 19055"""""""""" 19056 19057If ``ptr`` is a stack-allocated object and it points to the first byte of the 19058object, the object is dead. 19059``ptr`` is conservatively considered as a non-stack-allocated object if 19060the stack coloring algorithm that is used in the optimization pipeline cannot 19061conclude that ``ptr`` is a stack-allocated object. 19062 19063Calling ``llvm.lifetime.end`` on an already dead alloca is no-op. 19064 19065If ``ptr`` is a non-stack-allocated object or it does not point to the first 19066byte of the object, it is equivalent to simply filling all bytes of the object 19067with ``poison``. 19068 19069 19070'``llvm.invariant.start``' Intrinsic 19071^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19072 19073Syntax: 19074""""""" 19075This is an overloaded intrinsic. The memory object can belong to any address space. 19076 19077:: 19078 19079 declare {}* @llvm.invariant.start.p0i8(i64 <size>, i8* nocapture <ptr>) 19080 19081Overview: 19082""""""""" 19083 19084The '``llvm.invariant.start``' intrinsic specifies that the contents of 19085a memory object will not change. 19086 19087Arguments: 19088"""""""""" 19089 19090The first argument is a constant integer representing the size of the 19091object, or -1 if it is variable sized. The second argument is a pointer 19092to the object. 19093 19094Semantics: 19095"""""""""" 19096 19097This intrinsic indicates that until an ``llvm.invariant.end`` that uses 19098the return value, the referenced memory location is constant and 19099unchanging. 19100 19101'``llvm.invariant.end``' Intrinsic 19102^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19103 19104Syntax: 19105""""""" 19106This is an overloaded intrinsic. The memory object can belong to any address space. 19107 19108:: 19109 19110 declare void @llvm.invariant.end.p0i8({}* <start>, i64 <size>, i8* nocapture <ptr>) 19111 19112Overview: 19113""""""""" 19114 19115The '``llvm.invariant.end``' intrinsic specifies that the contents of a 19116memory object are mutable. 19117 19118Arguments: 19119"""""""""" 19120 19121The first argument is the matching ``llvm.invariant.start`` intrinsic. 19122The second argument is a constant integer representing the size of the 19123object, or -1 if it is variable sized and the third argument is a 19124pointer to the object. 19125 19126Semantics: 19127"""""""""" 19128 19129This intrinsic indicates that the memory is mutable again. 19130 19131'``llvm.launder.invariant.group``' Intrinsic 19132^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19133 19134Syntax: 19135""""""" 19136This is an overloaded intrinsic. The memory object can belong to any address 19137space. The returned pointer must belong to the same address space as the 19138argument. 19139 19140:: 19141 19142 declare i8* @llvm.launder.invariant.group.p0i8(i8* <ptr>) 19143 19144Overview: 19145""""""""" 19146 19147The '``llvm.launder.invariant.group``' intrinsic can be used when an invariant 19148established by ``invariant.group`` metadata no longer holds, to obtain a new 19149pointer value that carries fresh invariant group information. It is an 19150experimental intrinsic, which means that its semantics might change in the 19151future. 19152 19153 19154Arguments: 19155"""""""""" 19156 19157The ``llvm.launder.invariant.group`` takes only one argument, which is a pointer 19158to the memory. 19159 19160Semantics: 19161"""""""""" 19162 19163Returns another pointer that aliases its argument but which is considered different 19164for the purposes of ``load``/``store`` ``invariant.group`` metadata. 19165It does not read any accessible memory and the execution can be speculated. 19166 19167'``llvm.strip.invariant.group``' Intrinsic 19168^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19169 19170Syntax: 19171""""""" 19172This is an overloaded intrinsic. The memory object can belong to any address 19173space. The returned pointer must belong to the same address space as the 19174argument. 19175 19176:: 19177 19178 declare i8* @llvm.strip.invariant.group.p0i8(i8* <ptr>) 19179 19180Overview: 19181""""""""" 19182 19183The '``llvm.strip.invariant.group``' intrinsic can be used when an invariant 19184established by ``invariant.group`` metadata no longer holds, to obtain a new pointer 19185value that does not carry the invariant information. It is an experimental 19186intrinsic, which means that its semantics might change in the future. 19187 19188 19189Arguments: 19190"""""""""" 19191 19192The ``llvm.strip.invariant.group`` takes only one argument, which is a pointer 19193to the memory. 19194 19195Semantics: 19196"""""""""" 19197 19198Returns another pointer that aliases its argument but which has no associated 19199``invariant.group`` metadata. 19200It does not read any memory and can be speculated. 19201 19202 19203 19204.. _constrainedfp: 19205 19206Constrained Floating-Point Intrinsics 19207------------------------------------- 19208 19209These intrinsics are used to provide special handling of floating-point 19210operations when specific rounding mode or floating-point exception behavior is 19211required. By default, LLVM optimization passes assume that the rounding mode is 19212round-to-nearest and that floating-point exceptions will not be monitored. 19213Constrained FP intrinsics are used to support non-default rounding modes and 19214accurately preserve exception behavior without compromising LLVM's ability to 19215optimize FP code when the default behavior is used. 19216 19217If any FP operation in a function is constrained then they all must be 19218constrained. This is required for correct LLVM IR. Optimizations that 19219move code around can create miscompiles if mixing of constrained and normal 19220operations is done. The correct way to mix constrained and less constrained 19221operations is to use the rounding mode and exception handling metadata to 19222mark constrained intrinsics as having LLVM's default behavior. 19223 19224Each of these intrinsics corresponds to a normal floating-point operation. The 19225data arguments and the return value are the same as the corresponding FP 19226operation. 19227 19228The rounding mode argument is a metadata string specifying what 19229assumptions, if any, the optimizer can make when transforming constant 19230values. Some constrained FP intrinsics omit this argument. If required 19231by the intrinsic, this argument must be one of the following strings: 19232 19233:: 19234 19235 "round.dynamic" 19236 "round.tonearest" 19237 "round.downward" 19238 "round.upward" 19239 "round.towardzero" 19240 "round.tonearestaway" 19241 19242If this argument is "round.dynamic" optimization passes must assume that the 19243rounding mode is unknown and may change at runtime. No transformations that 19244depend on rounding mode may be performed in this case. 19245 19246The other possible values for the rounding mode argument correspond to the 19247similarly named IEEE rounding modes. If the argument is any of these values 19248optimization passes may perform transformations as long as they are consistent 19249with the specified rounding mode. 19250 19251For example, 'x-0'->'x' is not a valid transformation if the rounding mode is 19252"round.downward" or "round.dynamic" because if the value of 'x' is +0 then 19253'x-0' should evaluate to '-0' when rounding downward. However, this 19254transformation is legal for all other rounding modes. 19255 19256For values other than "round.dynamic" optimization passes may assume that the 19257actual runtime rounding mode (as defined in a target-specific manner) matches 19258the specified rounding mode, but this is not guaranteed. Using a specific 19259non-dynamic rounding mode which does not match the actual rounding mode at 19260runtime results in undefined behavior. 19261 19262The exception behavior argument is a metadata string describing the floating 19263point exception semantics that required for the intrinsic. This argument 19264must be one of the following strings: 19265 19266:: 19267 19268 "fpexcept.ignore" 19269 "fpexcept.maytrap" 19270 "fpexcept.strict" 19271 19272If this argument is "fpexcept.ignore" optimization passes may assume that the 19273exception status flags will not be read and that floating-point exceptions will 19274be masked. This allows transformations to be performed that may change the 19275exception semantics of the original code. For example, FP operations may be 19276speculatively executed in this case whereas they must not be for either of the 19277other possible values of this argument. 19278 19279If the exception behavior argument is "fpexcept.maytrap" optimization passes 19280must avoid transformations that may raise exceptions that would not have been 19281raised by the original code (such as speculatively executing FP operations), but 19282passes are not required to preserve all exceptions that are implied by the 19283original code. For example, exceptions may be potentially hidden by constant 19284folding. 19285 19286If the exception behavior argument is "fpexcept.strict" all transformations must 19287strictly preserve the floating-point exception semantics of the original code. 19288Any FP exception that would have been raised by the original code must be raised 19289by the transformed code, and the transformed code must not raise any FP 19290exceptions that would not have been raised by the original code. This is the 19291exception behavior argument that will be used if the code being compiled reads 19292the FP exception status flags, but this mode can also be used with code that 19293unmasks FP exceptions. 19294 19295The number and order of floating-point exceptions is NOT guaranteed. For 19296example, a series of FP operations that each may raise exceptions may be 19297vectorized into a single instruction that raises each unique exception a single 19298time. 19299 19300Proper :ref:`function attributes <fnattrs>` usage is required for the 19301constrained intrinsics to function correctly. 19302 19303All function *calls* done in a function that uses constrained floating 19304point intrinsics must have the ``strictfp`` attribute. 19305 19306All function *definitions* that use constrained floating point intrinsics 19307must have the ``strictfp`` attribute. 19308 19309'``llvm.experimental.constrained.fadd``' Intrinsic 19310^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19311 19312Syntax: 19313""""""" 19314 19315:: 19316 19317 declare <type> 19318 @llvm.experimental.constrained.fadd(<type> <op1>, <type> <op2>, 19319 metadata <rounding mode>, 19320 metadata <exception behavior>) 19321 19322Overview: 19323""""""""" 19324 19325The '``llvm.experimental.constrained.fadd``' intrinsic returns the sum of its 19326two operands. 19327 19328 19329Arguments: 19330"""""""""" 19331 19332The first two arguments to the '``llvm.experimental.constrained.fadd``' 19333intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` 19334of floating-point values. Both arguments must have identical types. 19335 19336The third and fourth arguments specify the rounding mode and exception 19337behavior as described above. 19338 19339Semantics: 19340"""""""""" 19341 19342The value produced is the floating-point sum of the two value operands and has 19343the same type as the operands. 19344 19345 19346'``llvm.experimental.constrained.fsub``' Intrinsic 19347^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19348 19349Syntax: 19350""""""" 19351 19352:: 19353 19354 declare <type> 19355 @llvm.experimental.constrained.fsub(<type> <op1>, <type> <op2>, 19356 metadata <rounding mode>, 19357 metadata <exception behavior>) 19358 19359Overview: 19360""""""""" 19361 19362The '``llvm.experimental.constrained.fsub``' intrinsic returns the difference 19363of its two operands. 19364 19365 19366Arguments: 19367"""""""""" 19368 19369The first two arguments to the '``llvm.experimental.constrained.fsub``' 19370intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` 19371of floating-point values. Both arguments must have identical types. 19372 19373The third and fourth arguments specify the rounding mode and exception 19374behavior as described above. 19375 19376Semantics: 19377"""""""""" 19378 19379The value produced is the floating-point difference of the two value operands 19380and has the same type as the operands. 19381 19382 19383'``llvm.experimental.constrained.fmul``' Intrinsic 19384^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19385 19386Syntax: 19387""""""" 19388 19389:: 19390 19391 declare <type> 19392 @llvm.experimental.constrained.fmul(<type> <op1>, <type> <op2>, 19393 metadata <rounding mode>, 19394 metadata <exception behavior>) 19395 19396Overview: 19397""""""""" 19398 19399The '``llvm.experimental.constrained.fmul``' intrinsic returns the product of 19400its two operands. 19401 19402 19403Arguments: 19404"""""""""" 19405 19406The first two arguments to the '``llvm.experimental.constrained.fmul``' 19407intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` 19408of floating-point values. Both arguments must have identical types. 19409 19410The third and fourth arguments specify the rounding mode and exception 19411behavior as described above. 19412 19413Semantics: 19414"""""""""" 19415 19416The value produced is the floating-point product of the two value operands and 19417has the same type as the operands. 19418 19419 19420'``llvm.experimental.constrained.fdiv``' Intrinsic 19421^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19422 19423Syntax: 19424""""""" 19425 19426:: 19427 19428 declare <type> 19429 @llvm.experimental.constrained.fdiv(<type> <op1>, <type> <op2>, 19430 metadata <rounding mode>, 19431 metadata <exception behavior>) 19432 19433Overview: 19434""""""""" 19435 19436The '``llvm.experimental.constrained.fdiv``' intrinsic returns the quotient of 19437its two operands. 19438 19439 19440Arguments: 19441"""""""""" 19442 19443The first two arguments to the '``llvm.experimental.constrained.fdiv``' 19444intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` 19445of floating-point values. Both arguments must have identical types. 19446 19447The third and fourth arguments specify the rounding mode and exception 19448behavior as described above. 19449 19450Semantics: 19451"""""""""" 19452 19453The value produced is the floating-point quotient of the two value operands and 19454has the same type as the operands. 19455 19456 19457'``llvm.experimental.constrained.frem``' Intrinsic 19458^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19459 19460Syntax: 19461""""""" 19462 19463:: 19464 19465 declare <type> 19466 @llvm.experimental.constrained.frem(<type> <op1>, <type> <op2>, 19467 metadata <rounding mode>, 19468 metadata <exception behavior>) 19469 19470Overview: 19471""""""""" 19472 19473The '``llvm.experimental.constrained.frem``' intrinsic returns the remainder 19474from the division of its two operands. 19475 19476 19477Arguments: 19478"""""""""" 19479 19480The first two arguments to the '``llvm.experimental.constrained.frem``' 19481intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` 19482of floating-point values. Both arguments must have identical types. 19483 19484The third and fourth arguments specify the rounding mode and exception 19485behavior as described above. The rounding mode argument has no effect, since 19486the result of frem is never rounded, but the argument is included for 19487consistency with the other constrained floating-point intrinsics. 19488 19489Semantics: 19490"""""""""" 19491 19492The value produced is the floating-point remainder from the division of the two 19493value operands and has the same type as the operands. The remainder has the 19494same sign as the dividend. 19495 19496'``llvm.experimental.constrained.fma``' Intrinsic 19497^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19498 19499Syntax: 19500""""""" 19501 19502:: 19503 19504 declare <type> 19505 @llvm.experimental.constrained.fma(<type> <op1>, <type> <op2>, <type> <op3>, 19506 metadata <rounding mode>, 19507 metadata <exception behavior>) 19508 19509Overview: 19510""""""""" 19511 19512The '``llvm.experimental.constrained.fma``' intrinsic returns the result of a 19513fused-multiply-add operation on its operands. 19514 19515Arguments: 19516"""""""""" 19517 19518The first three arguments to the '``llvm.experimental.constrained.fma``' 19519intrinsic must be :ref:`floating-point <t_floating>` or :ref:`vector 19520<t_vector>` of floating-point values. All arguments must have identical types. 19521 19522The fourth and fifth arguments specify the rounding mode and exception behavior 19523as described above. 19524 19525Semantics: 19526"""""""""" 19527 19528The result produced is the product of the first two operands added to the third 19529operand computed with infinite precision, and then rounded to the target 19530precision. 19531 19532'``llvm.experimental.constrained.fptoui``' Intrinsic 19533^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19534 19535Syntax: 19536""""""" 19537 19538:: 19539 19540 declare <ty2> 19541 @llvm.experimental.constrained.fptoui(<type> <value>, 19542 metadata <exception behavior>) 19543 19544Overview: 19545""""""""" 19546 19547The '``llvm.experimental.constrained.fptoui``' intrinsic converts a 19548floating-point ``value`` to its unsigned integer equivalent of type ``ty2``. 19549 19550Arguments: 19551"""""""""" 19552 19553The first argument to the '``llvm.experimental.constrained.fptoui``' 19554intrinsic must be :ref:`floating point <t_floating>` or :ref:`vector 19555<t_vector>` of floating point values. 19556 19557The second argument specifies the exception behavior as described above. 19558 19559Semantics: 19560"""""""""" 19561 19562The result produced is an unsigned integer converted from the floating 19563point operand. The value is truncated, so it is rounded towards zero. 19564 19565'``llvm.experimental.constrained.fptosi``' Intrinsic 19566^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19567 19568Syntax: 19569""""""" 19570 19571:: 19572 19573 declare <ty2> 19574 @llvm.experimental.constrained.fptosi(<type> <value>, 19575 metadata <exception behavior>) 19576 19577Overview: 19578""""""""" 19579 19580The '``llvm.experimental.constrained.fptosi``' intrinsic converts 19581:ref:`floating-point <t_floating>` ``value`` to type ``ty2``. 19582 19583Arguments: 19584"""""""""" 19585 19586The first argument to the '``llvm.experimental.constrained.fptosi``' 19587intrinsic must be :ref:`floating point <t_floating>` or :ref:`vector 19588<t_vector>` of floating point values. 19589 19590The second argument specifies the exception behavior as described above. 19591 19592Semantics: 19593"""""""""" 19594 19595The result produced is a signed integer converted from the floating 19596point operand. The value is truncated, so it is rounded towards zero. 19597 19598'``llvm.experimental.constrained.uitofp``' Intrinsic 19599^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19600 19601Syntax: 19602""""""" 19603 19604:: 19605 19606 declare <ty2> 19607 @llvm.experimental.constrained.uitofp(<type> <value>, 19608 metadata <rounding mode>, 19609 metadata <exception behavior>) 19610 19611Overview: 19612""""""""" 19613 19614The '``llvm.experimental.constrained.uitofp``' intrinsic converts an 19615unsigned integer ``value`` to a floating-point of type ``ty2``. 19616 19617Arguments: 19618"""""""""" 19619 19620The first argument to the '``llvm.experimental.constrained.uitofp``' 19621intrinsic must be an :ref:`integer <t_integer>` or :ref:`vector 19622<t_vector>` of integer values. 19623 19624The second and third arguments specify the rounding mode and exception 19625behavior as described above. 19626 19627Semantics: 19628"""""""""" 19629 19630An inexact floating-point exception will be raised if rounding is required. 19631Any result produced is a floating point value converted from the input 19632integer operand. 19633 19634'``llvm.experimental.constrained.sitofp``' Intrinsic 19635^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19636 19637Syntax: 19638""""""" 19639 19640:: 19641 19642 declare <ty2> 19643 @llvm.experimental.constrained.sitofp(<type> <value>, 19644 metadata <rounding mode>, 19645 metadata <exception behavior>) 19646 19647Overview: 19648""""""""" 19649 19650The '``llvm.experimental.constrained.sitofp``' intrinsic converts a 19651signed integer ``value`` to a floating-point of type ``ty2``. 19652 19653Arguments: 19654"""""""""" 19655 19656The first argument to the '``llvm.experimental.constrained.sitofp``' 19657intrinsic must be an :ref:`integer <t_integer>` or :ref:`vector 19658<t_vector>` of integer values. 19659 19660The second and third arguments specify the rounding mode and exception 19661behavior as described above. 19662 19663Semantics: 19664"""""""""" 19665 19666An inexact floating-point exception will be raised if rounding is required. 19667Any result produced is a floating point value converted from the input 19668integer operand. 19669 19670'``llvm.experimental.constrained.fptrunc``' Intrinsic 19671^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19672 19673Syntax: 19674""""""" 19675 19676:: 19677 19678 declare <ty2> 19679 @llvm.experimental.constrained.fptrunc(<type> <value>, 19680 metadata <rounding mode>, 19681 metadata <exception behavior>) 19682 19683Overview: 19684""""""""" 19685 19686The '``llvm.experimental.constrained.fptrunc``' intrinsic truncates ``value`` 19687to type ``ty2``. 19688 19689Arguments: 19690"""""""""" 19691 19692The first argument to the '``llvm.experimental.constrained.fptrunc``' 19693intrinsic must be :ref:`floating point <t_floating>` or :ref:`vector 19694<t_vector>` of floating point values. This argument must be larger in size 19695than the result. 19696 19697The second and third arguments specify the rounding mode and exception 19698behavior as described above. 19699 19700Semantics: 19701"""""""""" 19702 19703The result produced is a floating point value truncated to be smaller in size 19704than the operand. 19705 19706'``llvm.experimental.constrained.fpext``' Intrinsic 19707^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19708 19709Syntax: 19710""""""" 19711 19712:: 19713 19714 declare <ty2> 19715 @llvm.experimental.constrained.fpext(<type> <value>, 19716 metadata <exception behavior>) 19717 19718Overview: 19719""""""""" 19720 19721The '``llvm.experimental.constrained.fpext``' intrinsic extends a 19722floating-point ``value`` to a larger floating-point value. 19723 19724Arguments: 19725"""""""""" 19726 19727The first argument to the '``llvm.experimental.constrained.fpext``' 19728intrinsic must be :ref:`floating point <t_floating>` or :ref:`vector 19729<t_vector>` of floating point values. This argument must be smaller in size 19730than the result. 19731 19732The second argument specifies the exception behavior as described above. 19733 19734Semantics: 19735"""""""""" 19736 19737The result produced is a floating point value extended to be larger in size 19738than the operand. All restrictions that apply to the fpext instruction also 19739apply to this intrinsic. 19740 19741'``llvm.experimental.constrained.fcmp``' and '``llvm.experimental.constrained.fcmps``' Intrinsics 19742^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19743 19744Syntax: 19745""""""" 19746 19747:: 19748 19749 declare <ty2> 19750 @llvm.experimental.constrained.fcmp(<type> <op1>, <type> <op2>, 19751 metadata <condition code>, 19752 metadata <exception behavior>) 19753 declare <ty2> 19754 @llvm.experimental.constrained.fcmps(<type> <op1>, <type> <op2>, 19755 metadata <condition code>, 19756 metadata <exception behavior>) 19757 19758Overview: 19759""""""""" 19760 19761The '``llvm.experimental.constrained.fcmp``' and 19762'``llvm.experimental.constrained.fcmps``' intrinsics return a boolean 19763value or vector of boolean values based on comparison of its operands. 19764 19765If the operands are floating-point scalars, then the result type is a 19766boolean (:ref:`i1 <t_integer>`). 19767 19768If the operands are floating-point vectors, then the result type is a 19769vector of boolean with the same number of elements as the operands being 19770compared. 19771 19772The '``llvm.experimental.constrained.fcmp``' intrinsic performs a quiet 19773comparison operation while the '``llvm.experimental.constrained.fcmps``' 19774intrinsic performs a signaling comparison operation. 19775 19776Arguments: 19777"""""""""" 19778 19779The first two arguments to the '``llvm.experimental.constrained.fcmp``' 19780and '``llvm.experimental.constrained.fcmps``' intrinsics must be 19781:ref:`floating-point <t_floating>` or :ref:`vector <t_vector>` 19782of floating-point values. Both arguments must have identical types. 19783 19784The third argument is the condition code indicating the kind of comparison 19785to perform. It must be a metadata string with one of the following values: 19786 19787- "``oeq``": ordered and equal 19788- "``ogt``": ordered and greater than 19789- "``oge``": ordered and greater than or equal 19790- "``olt``": ordered and less than 19791- "``ole``": ordered and less than or equal 19792- "``one``": ordered and not equal 19793- "``ord``": ordered (no nans) 19794- "``ueq``": unordered or equal 19795- "``ugt``": unordered or greater than 19796- "``uge``": unordered or greater than or equal 19797- "``ult``": unordered or less than 19798- "``ule``": unordered or less than or equal 19799- "``une``": unordered or not equal 19800- "``uno``": unordered (either nans) 19801 19802*Ordered* means that neither operand is a NAN while *unordered* means 19803that either operand may be a NAN. 19804 19805The fourth argument specifies the exception behavior as described above. 19806 19807Semantics: 19808"""""""""" 19809 19810``op1`` and ``op2`` are compared according to the condition code given 19811as the third argument. If the operands are vectors, then the 19812vectors are compared element by element. Each comparison performed 19813always yields an :ref:`i1 <t_integer>` result, as follows: 19814 19815- "``oeq``": yields ``true`` if both operands are not a NAN and ``op1`` 19816 is equal to ``op2``. 19817- "``ogt``": yields ``true`` if both operands are not a NAN and ``op1`` 19818 is greater than ``op2``. 19819- "``oge``": yields ``true`` if both operands are not a NAN and ``op1`` 19820 is greater than or equal to ``op2``. 19821- "``olt``": yields ``true`` if both operands are not a NAN and ``op1`` 19822 is less than ``op2``. 19823- "``ole``": yields ``true`` if both operands are not a NAN and ``op1`` 19824 is less than or equal to ``op2``. 19825- "``one``": yields ``true`` if both operands are not a NAN and ``op1`` 19826 is not equal to ``op2``. 19827- "``ord``": yields ``true`` if both operands are not a NAN. 19828- "``ueq``": yields ``true`` if either operand is a NAN or ``op1`` is 19829 equal to ``op2``. 19830- "``ugt``": yields ``true`` if either operand is a NAN or ``op1`` is 19831 greater than ``op2``. 19832- "``uge``": yields ``true`` if either operand is a NAN or ``op1`` is 19833 greater than or equal to ``op2``. 19834- "``ult``": yields ``true`` if either operand is a NAN or ``op1`` is 19835 less than ``op2``. 19836- "``ule``": yields ``true`` if either operand is a NAN or ``op1`` is 19837 less than or equal to ``op2``. 19838- "``une``": yields ``true`` if either operand is a NAN or ``op1`` is 19839 not equal to ``op2``. 19840- "``uno``": yields ``true`` if either operand is a NAN. 19841 19842The quiet comparison operation performed by 19843'``llvm.experimental.constrained.fcmp``' will only raise an exception 19844if either operand is a SNAN. The signaling comparison operation 19845performed by '``llvm.experimental.constrained.fcmps``' will raise an 19846exception if either operand is a NAN (QNAN or SNAN). Such an exception 19847does not preclude a result being produced (e.g. exception might only 19848set a flag), therefore the distinction between ordered and unordered 19849comparisons is also relevant for the 19850'``llvm.experimental.constrained.fcmps``' intrinsic. 19851 19852'``llvm.experimental.constrained.fmuladd``' Intrinsic 19853^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19854 19855Syntax: 19856""""""" 19857 19858:: 19859 19860 declare <type> 19861 @llvm.experimental.constrained.fmuladd(<type> <op1>, <type> <op2>, 19862 <type> <op3>, 19863 metadata <rounding mode>, 19864 metadata <exception behavior>) 19865 19866Overview: 19867""""""""" 19868 19869The '``llvm.experimental.constrained.fmuladd``' intrinsic represents 19870multiply-add expressions that can be fused if the code generator determines 19871that (a) the target instruction set has support for a fused operation, 19872and (b) that the fused operation is more efficient than the equivalent, 19873separate pair of mul and add instructions. 19874 19875Arguments: 19876"""""""""" 19877 19878The first three arguments to the '``llvm.experimental.constrained.fmuladd``' 19879intrinsic must be floating-point or vector of floating-point values. 19880All three arguments must have identical types. 19881 19882The fourth and fifth arguments specify the rounding mode and exception behavior 19883as described above. 19884 19885Semantics: 19886"""""""""" 19887 19888The expression: 19889 19890:: 19891 19892 %0 = call float @llvm.experimental.constrained.fmuladd.f32(%a, %b, %c, 19893 metadata <rounding mode>, 19894 metadata <exception behavior>) 19895 19896is equivalent to the expression: 19897 19898:: 19899 19900 %0 = call float @llvm.experimental.constrained.fmul.f32(%a, %b, 19901 metadata <rounding mode>, 19902 metadata <exception behavior>) 19903 %1 = call float @llvm.experimental.constrained.fadd.f32(%0, %c, 19904 metadata <rounding mode>, 19905 metadata <exception behavior>) 19906 19907except that it is unspecified whether rounding will be performed between the 19908multiplication and addition steps. Fusion is not guaranteed, even if the target 19909platform supports it. 19910If a fused multiply-add is required, the corresponding 19911:ref:`llvm.experimental.constrained.fma <int_fma>` intrinsic function should be 19912used instead. 19913This never sets errno, just as '``llvm.experimental.constrained.fma.*``'. 19914 19915Constrained libm-equivalent Intrinsics 19916-------------------------------------- 19917 19918In addition to the basic floating-point operations for which constrained 19919intrinsics are described above, there are constrained versions of various 19920operations which provide equivalent behavior to a corresponding libm function. 19921These intrinsics allow the precise behavior of these operations with respect to 19922rounding mode and exception behavior to be controlled. 19923 19924As with the basic constrained floating-point intrinsics, the rounding mode 19925and exception behavior arguments only control the behavior of the optimizer. 19926They do not change the runtime floating-point environment. 19927 19928 19929'``llvm.experimental.constrained.sqrt``' Intrinsic 19930^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19931 19932Syntax: 19933""""""" 19934 19935:: 19936 19937 declare <type> 19938 @llvm.experimental.constrained.sqrt(<type> <op1>, 19939 metadata <rounding mode>, 19940 metadata <exception behavior>) 19941 19942Overview: 19943""""""""" 19944 19945The '``llvm.experimental.constrained.sqrt``' intrinsic returns the square root 19946of the specified value, returning the same value as the libm '``sqrt``' 19947functions would, but without setting ``errno``. 19948 19949Arguments: 19950"""""""""" 19951 19952The first argument and the return type are floating-point numbers of the same 19953type. 19954 19955The second and third arguments specify the rounding mode and exception 19956behavior as described above. 19957 19958Semantics: 19959"""""""""" 19960 19961This function returns the nonnegative square root of the specified value. 19962If the value is less than negative zero, a floating-point exception occurs 19963and the return value is architecture specific. 19964 19965 19966'``llvm.experimental.constrained.pow``' Intrinsic 19967^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19968 19969Syntax: 19970""""""" 19971 19972:: 19973 19974 declare <type> 19975 @llvm.experimental.constrained.pow(<type> <op1>, <type> <op2>, 19976 metadata <rounding mode>, 19977 metadata <exception behavior>) 19978 19979Overview: 19980""""""""" 19981 19982The '``llvm.experimental.constrained.pow``' intrinsic returns the first operand 19983raised to the (positive or negative) power specified by the second operand. 19984 19985Arguments: 19986"""""""""" 19987 19988The first two arguments and the return value are floating-point numbers of the 19989same type. The second argument specifies the power to which the first argument 19990should be raised. 19991 19992The third and fourth arguments specify the rounding mode and exception 19993behavior as described above. 19994 19995Semantics: 19996"""""""""" 19997 19998This function returns the first value raised to the second power, 19999returning the same values as the libm ``pow`` functions would, and 20000handles error conditions in the same way. 20001 20002 20003'``llvm.experimental.constrained.powi``' Intrinsic 20004^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20005 20006Syntax: 20007""""""" 20008 20009:: 20010 20011 declare <type> 20012 @llvm.experimental.constrained.powi(<type> <op1>, i32 <op2>, 20013 metadata <rounding mode>, 20014 metadata <exception behavior>) 20015 20016Overview: 20017""""""""" 20018 20019The '``llvm.experimental.constrained.powi``' intrinsic returns the first operand 20020raised to the (positive or negative) power specified by the second operand. The 20021order of evaluation of multiplications is not defined. When a vector of 20022floating-point type is used, the second argument remains a scalar integer value. 20023 20024 20025Arguments: 20026"""""""""" 20027 20028The first argument and the return value are floating-point numbers of the same 20029type. The second argument is a 32-bit signed integer specifying the power to 20030which the first argument should be raised. 20031 20032The third and fourth arguments specify the rounding mode and exception 20033behavior as described above. 20034 20035Semantics: 20036"""""""""" 20037 20038This function returns the first value raised to the second power with an 20039unspecified sequence of rounding operations. 20040 20041 20042'``llvm.experimental.constrained.sin``' Intrinsic 20043^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20044 20045Syntax: 20046""""""" 20047 20048:: 20049 20050 declare <type> 20051 @llvm.experimental.constrained.sin(<type> <op1>, 20052 metadata <rounding mode>, 20053 metadata <exception behavior>) 20054 20055Overview: 20056""""""""" 20057 20058The '``llvm.experimental.constrained.sin``' intrinsic returns the sine of the 20059first operand. 20060 20061Arguments: 20062"""""""""" 20063 20064The first argument and the return type are floating-point numbers of the same 20065type. 20066 20067The second and third arguments specify the rounding mode and exception 20068behavior as described above. 20069 20070Semantics: 20071"""""""""" 20072 20073This function returns the sine of the specified operand, returning the 20074same values as the libm ``sin`` functions would, and handles error 20075conditions in the same way. 20076 20077 20078'``llvm.experimental.constrained.cos``' Intrinsic 20079^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20080 20081Syntax: 20082""""""" 20083 20084:: 20085 20086 declare <type> 20087 @llvm.experimental.constrained.cos(<type> <op1>, 20088 metadata <rounding mode>, 20089 metadata <exception behavior>) 20090 20091Overview: 20092""""""""" 20093 20094The '``llvm.experimental.constrained.cos``' intrinsic returns the cosine of the 20095first operand. 20096 20097Arguments: 20098"""""""""" 20099 20100The first argument and the return type are floating-point numbers of the same 20101type. 20102 20103The second and third arguments specify the rounding mode and exception 20104behavior as described above. 20105 20106Semantics: 20107"""""""""" 20108 20109This function returns the cosine of the specified operand, returning the 20110same values as the libm ``cos`` functions would, and handles error 20111conditions in the same way. 20112 20113 20114'``llvm.experimental.constrained.exp``' Intrinsic 20115^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20116 20117Syntax: 20118""""""" 20119 20120:: 20121 20122 declare <type> 20123 @llvm.experimental.constrained.exp(<type> <op1>, 20124 metadata <rounding mode>, 20125 metadata <exception behavior>) 20126 20127Overview: 20128""""""""" 20129 20130The '``llvm.experimental.constrained.exp``' intrinsic computes the base-e 20131exponential of the specified value. 20132 20133Arguments: 20134"""""""""" 20135 20136The first argument and the return value are floating-point numbers of the same 20137type. 20138 20139The second and third arguments specify the rounding mode and exception 20140behavior as described above. 20141 20142Semantics: 20143"""""""""" 20144 20145This function returns the same values as the libm ``exp`` functions 20146would, and handles error conditions in the same way. 20147 20148 20149'``llvm.experimental.constrained.exp2``' Intrinsic 20150^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20151 20152Syntax: 20153""""""" 20154 20155:: 20156 20157 declare <type> 20158 @llvm.experimental.constrained.exp2(<type> <op1>, 20159 metadata <rounding mode>, 20160 metadata <exception behavior>) 20161 20162Overview: 20163""""""""" 20164 20165The '``llvm.experimental.constrained.exp2``' intrinsic computes the base-2 20166exponential of the specified value. 20167 20168 20169Arguments: 20170"""""""""" 20171 20172The first argument and the return value are floating-point numbers of the same 20173type. 20174 20175The second and third arguments specify the rounding mode and exception 20176behavior as described above. 20177 20178Semantics: 20179"""""""""" 20180 20181This function returns the same values as the libm ``exp2`` functions 20182would, and handles error conditions in the same way. 20183 20184 20185'``llvm.experimental.constrained.log``' Intrinsic 20186^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20187 20188Syntax: 20189""""""" 20190 20191:: 20192 20193 declare <type> 20194 @llvm.experimental.constrained.log(<type> <op1>, 20195 metadata <rounding mode>, 20196 metadata <exception behavior>) 20197 20198Overview: 20199""""""""" 20200 20201The '``llvm.experimental.constrained.log``' intrinsic computes the base-e 20202logarithm of the specified value. 20203 20204Arguments: 20205"""""""""" 20206 20207The first argument and the return value are floating-point numbers of the same 20208type. 20209 20210The second and third arguments specify the rounding mode and exception 20211behavior as described above. 20212 20213 20214Semantics: 20215"""""""""" 20216 20217This function returns the same values as the libm ``log`` functions 20218would, and handles error conditions in the same way. 20219 20220 20221'``llvm.experimental.constrained.log10``' Intrinsic 20222^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20223 20224Syntax: 20225""""""" 20226 20227:: 20228 20229 declare <type> 20230 @llvm.experimental.constrained.log10(<type> <op1>, 20231 metadata <rounding mode>, 20232 metadata <exception behavior>) 20233 20234Overview: 20235""""""""" 20236 20237The '``llvm.experimental.constrained.log10``' intrinsic computes the base-10 20238logarithm of the specified value. 20239 20240Arguments: 20241"""""""""" 20242 20243The first argument and the return value are floating-point numbers of the same 20244type. 20245 20246The second and third arguments specify the rounding mode and exception 20247behavior as described above. 20248 20249Semantics: 20250"""""""""" 20251 20252This function returns the same values as the libm ``log10`` functions 20253would, and handles error conditions in the same way. 20254 20255 20256'``llvm.experimental.constrained.log2``' Intrinsic 20257^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20258 20259Syntax: 20260""""""" 20261 20262:: 20263 20264 declare <type> 20265 @llvm.experimental.constrained.log2(<type> <op1>, 20266 metadata <rounding mode>, 20267 metadata <exception behavior>) 20268 20269Overview: 20270""""""""" 20271 20272The '``llvm.experimental.constrained.log2``' intrinsic computes the base-2 20273logarithm of the specified value. 20274 20275Arguments: 20276"""""""""" 20277 20278The first argument and the return value are floating-point numbers of the same 20279type. 20280 20281The second and third arguments specify the rounding mode and exception 20282behavior as described above. 20283 20284Semantics: 20285"""""""""" 20286 20287This function returns the same values as the libm ``log2`` functions 20288would, and handles error conditions in the same way. 20289 20290 20291'``llvm.experimental.constrained.rint``' Intrinsic 20292^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20293 20294Syntax: 20295""""""" 20296 20297:: 20298 20299 declare <type> 20300 @llvm.experimental.constrained.rint(<type> <op1>, 20301 metadata <rounding mode>, 20302 metadata <exception behavior>) 20303 20304Overview: 20305""""""""" 20306 20307The '``llvm.experimental.constrained.rint``' intrinsic returns the first 20308operand rounded to the nearest integer. It may raise an inexact floating-point 20309exception if the operand is not an integer. 20310 20311Arguments: 20312"""""""""" 20313 20314The first argument and the return value are floating-point numbers of the same 20315type. 20316 20317The second and third arguments specify the rounding mode and exception 20318behavior as described above. 20319 20320Semantics: 20321"""""""""" 20322 20323This function returns the same values as the libm ``rint`` functions 20324would, and handles error conditions in the same way. The rounding mode is 20325described, not determined, by the rounding mode argument. The actual rounding 20326mode is determined by the runtime floating-point environment. The rounding 20327mode argument is only intended as information to the compiler. 20328 20329 20330'``llvm.experimental.constrained.lrint``' Intrinsic 20331^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20332 20333Syntax: 20334""""""" 20335 20336:: 20337 20338 declare <inttype> 20339 @llvm.experimental.constrained.lrint(<fptype> <op1>, 20340 metadata <rounding mode>, 20341 metadata <exception behavior>) 20342 20343Overview: 20344""""""""" 20345 20346The '``llvm.experimental.constrained.lrint``' intrinsic returns the first 20347operand rounded to the nearest integer. An inexact floating-point exception 20348will be raised if the operand is not an integer. An invalid exception is 20349raised if the result is too large to fit into a supported integer type, 20350and in this case the result is undefined. 20351 20352Arguments: 20353"""""""""" 20354 20355The first argument is a floating-point number. The return value is an 20356integer type. Not all types are supported on all targets. The supported 20357types are the same as the ``llvm.lrint`` intrinsic and the ``lrint`` 20358libm functions. 20359 20360The second and third arguments specify the rounding mode and exception 20361behavior as described above. 20362 20363Semantics: 20364"""""""""" 20365 20366This function returns the same values as the libm ``lrint`` functions 20367would, and handles error conditions in the same way. 20368 20369The rounding mode is described, not determined, by the rounding mode 20370argument. The actual rounding mode is determined by the runtime floating-point 20371environment. The rounding mode argument is only intended as information 20372to the compiler. 20373 20374If the runtime floating-point environment is using the default rounding mode 20375then the results will be the same as the llvm.lrint intrinsic. 20376 20377 20378'``llvm.experimental.constrained.llrint``' Intrinsic 20379^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20380 20381Syntax: 20382""""""" 20383 20384:: 20385 20386 declare <inttype> 20387 @llvm.experimental.constrained.llrint(<fptype> <op1>, 20388 metadata <rounding mode>, 20389 metadata <exception behavior>) 20390 20391Overview: 20392""""""""" 20393 20394The '``llvm.experimental.constrained.llrint``' intrinsic returns the first 20395operand rounded to the nearest integer. An inexact floating-point exception 20396will be raised if the operand is not an integer. An invalid exception is 20397raised if the result is too large to fit into a supported integer type, 20398and in this case the result is undefined. 20399 20400Arguments: 20401"""""""""" 20402 20403The first argument is a floating-point number. The return value is an 20404integer type. Not all types are supported on all targets. The supported 20405types are the same as the ``llvm.llrint`` intrinsic and the ``llrint`` 20406libm functions. 20407 20408The second and third arguments specify the rounding mode and exception 20409behavior as described above. 20410 20411Semantics: 20412"""""""""" 20413 20414This function returns the same values as the libm ``llrint`` functions 20415would, and handles error conditions in the same way. 20416 20417The rounding mode is described, not determined, by the rounding mode 20418argument. The actual rounding mode is determined by the runtime floating-point 20419environment. The rounding mode argument is only intended as information 20420to the compiler. 20421 20422If the runtime floating-point environment is using the default rounding mode 20423then the results will be the same as the llvm.llrint intrinsic. 20424 20425 20426'``llvm.experimental.constrained.nearbyint``' Intrinsic 20427^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20428 20429Syntax: 20430""""""" 20431 20432:: 20433 20434 declare <type> 20435 @llvm.experimental.constrained.nearbyint(<type> <op1>, 20436 metadata <rounding mode>, 20437 metadata <exception behavior>) 20438 20439Overview: 20440""""""""" 20441 20442The '``llvm.experimental.constrained.nearbyint``' intrinsic returns the first 20443operand rounded to the nearest integer. It will not raise an inexact 20444floating-point exception if the operand is not an integer. 20445 20446 20447Arguments: 20448"""""""""" 20449 20450The first argument and the return value are floating-point numbers of the same 20451type. 20452 20453The second and third arguments specify the rounding mode and exception 20454behavior as described above. 20455 20456Semantics: 20457"""""""""" 20458 20459This function returns the same values as the libm ``nearbyint`` functions 20460would, and handles error conditions in the same way. The rounding mode is 20461described, not determined, by the rounding mode argument. The actual rounding 20462mode is determined by the runtime floating-point environment. The rounding 20463mode argument is only intended as information to the compiler. 20464 20465 20466'``llvm.experimental.constrained.maxnum``' Intrinsic 20467^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20468 20469Syntax: 20470""""""" 20471 20472:: 20473 20474 declare <type> 20475 @llvm.experimental.constrained.maxnum(<type> <op1>, <type> <op2> 20476 metadata <exception behavior>) 20477 20478Overview: 20479""""""""" 20480 20481The '``llvm.experimental.constrained.maxnum``' intrinsic returns the maximum 20482of the two arguments. 20483 20484Arguments: 20485"""""""""" 20486 20487The first two arguments and the return value are floating-point numbers 20488of the same type. 20489 20490The third argument specifies the exception behavior as described above. 20491 20492Semantics: 20493"""""""""" 20494 20495This function follows the IEEE-754 semantics for maxNum. 20496 20497 20498'``llvm.experimental.constrained.minnum``' Intrinsic 20499^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20500 20501Syntax: 20502""""""" 20503 20504:: 20505 20506 declare <type> 20507 @llvm.experimental.constrained.minnum(<type> <op1>, <type> <op2> 20508 metadata <exception behavior>) 20509 20510Overview: 20511""""""""" 20512 20513The '``llvm.experimental.constrained.minnum``' intrinsic returns the minimum 20514of the two arguments. 20515 20516Arguments: 20517"""""""""" 20518 20519The first two arguments and the return value are floating-point numbers 20520of the same type. 20521 20522The third argument specifies the exception behavior as described above. 20523 20524Semantics: 20525"""""""""" 20526 20527This function follows the IEEE-754 semantics for minNum. 20528 20529 20530'``llvm.experimental.constrained.maximum``' Intrinsic 20531^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20532 20533Syntax: 20534""""""" 20535 20536:: 20537 20538 declare <type> 20539 @llvm.experimental.constrained.maximum(<type> <op1>, <type> <op2> 20540 metadata <exception behavior>) 20541 20542Overview: 20543""""""""" 20544 20545The '``llvm.experimental.constrained.maximum``' intrinsic returns the maximum 20546of the two arguments, propagating NaNs and treating -0.0 as less than +0.0. 20547 20548Arguments: 20549"""""""""" 20550 20551The first two arguments and the return value are floating-point numbers 20552of the same type. 20553 20554The third argument specifies the exception behavior as described above. 20555 20556Semantics: 20557"""""""""" 20558 20559This function follows semantics specified in the draft of IEEE 754-2018. 20560 20561 20562'``llvm.experimental.constrained.minimum``' Intrinsic 20563^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20564 20565Syntax: 20566""""""" 20567 20568:: 20569 20570 declare <type> 20571 @llvm.experimental.constrained.minimum(<type> <op1>, <type> <op2> 20572 metadata <exception behavior>) 20573 20574Overview: 20575""""""""" 20576 20577The '``llvm.experimental.constrained.minimum``' intrinsic returns the minimum 20578of the two arguments, propagating NaNs and treating -0.0 as less than +0.0. 20579 20580Arguments: 20581"""""""""" 20582 20583The first two arguments and the return value are floating-point numbers 20584of the same type. 20585 20586The third argument specifies the exception behavior as described above. 20587 20588Semantics: 20589"""""""""" 20590 20591This function follows semantics specified in the draft of IEEE 754-2018. 20592 20593 20594'``llvm.experimental.constrained.ceil``' Intrinsic 20595^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20596 20597Syntax: 20598""""""" 20599 20600:: 20601 20602 declare <type> 20603 @llvm.experimental.constrained.ceil(<type> <op1>, 20604 metadata <exception behavior>) 20605 20606Overview: 20607""""""""" 20608 20609The '``llvm.experimental.constrained.ceil``' intrinsic returns the ceiling of the 20610first operand. 20611 20612Arguments: 20613"""""""""" 20614 20615The first argument and the return value are floating-point numbers of the same 20616type. 20617 20618The second argument specifies the exception behavior as described above. 20619 20620Semantics: 20621"""""""""" 20622 20623This function returns the same values as the libm ``ceil`` functions 20624would and handles error conditions in the same way. 20625 20626 20627'``llvm.experimental.constrained.floor``' Intrinsic 20628^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20629 20630Syntax: 20631""""""" 20632 20633:: 20634 20635 declare <type> 20636 @llvm.experimental.constrained.floor(<type> <op1>, 20637 metadata <exception behavior>) 20638 20639Overview: 20640""""""""" 20641 20642The '``llvm.experimental.constrained.floor``' intrinsic returns the floor of the 20643first operand. 20644 20645Arguments: 20646"""""""""" 20647 20648The first argument and the return value are floating-point numbers of the same 20649type. 20650 20651The second argument specifies the exception behavior as described above. 20652 20653Semantics: 20654"""""""""" 20655 20656This function returns the same values as the libm ``floor`` functions 20657would and handles error conditions in the same way. 20658 20659 20660'``llvm.experimental.constrained.round``' Intrinsic 20661^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20662 20663Syntax: 20664""""""" 20665 20666:: 20667 20668 declare <type> 20669 @llvm.experimental.constrained.round(<type> <op1>, 20670 metadata <exception behavior>) 20671 20672Overview: 20673""""""""" 20674 20675The '``llvm.experimental.constrained.round``' intrinsic returns the first 20676operand rounded to the nearest integer. 20677 20678Arguments: 20679"""""""""" 20680 20681The first argument and the return value are floating-point numbers of the same 20682type. 20683 20684The second argument specifies the exception behavior as described above. 20685 20686Semantics: 20687"""""""""" 20688 20689This function returns the same values as the libm ``round`` functions 20690would and handles error conditions in the same way. 20691 20692 20693'``llvm.experimental.constrained.roundeven``' Intrinsic 20694^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20695 20696Syntax: 20697""""""" 20698 20699:: 20700 20701 declare <type> 20702 @llvm.experimental.constrained.roundeven(<type> <op1>, 20703 metadata <exception behavior>) 20704 20705Overview: 20706""""""""" 20707 20708The '``llvm.experimental.constrained.roundeven``' intrinsic returns the first 20709operand rounded to the nearest integer in floating-point format, rounding 20710halfway cases to even (that is, to the nearest value that is an even integer), 20711regardless of the current rounding direction. 20712 20713Arguments: 20714"""""""""" 20715 20716The first argument and the return value are floating-point numbers of the same 20717type. 20718 20719The second argument specifies the exception behavior as described above. 20720 20721Semantics: 20722"""""""""" 20723 20724This function implements IEEE-754 operation ``roundToIntegralTiesToEven``. It 20725also behaves in the same way as C standard function ``roundeven`` and can signal 20726the invalid operation exception for a SNAN operand. 20727 20728 20729'``llvm.experimental.constrained.lround``' Intrinsic 20730^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20731 20732Syntax: 20733""""""" 20734 20735:: 20736 20737 declare <inttype> 20738 @llvm.experimental.constrained.lround(<fptype> <op1>, 20739 metadata <exception behavior>) 20740 20741Overview: 20742""""""""" 20743 20744The '``llvm.experimental.constrained.lround``' intrinsic returns the first 20745operand rounded to the nearest integer with ties away from zero. It will 20746raise an inexact floating-point exception if the operand is not an integer. 20747An invalid exception is raised if the result is too large to fit into a 20748supported integer type, and in this case the result is undefined. 20749 20750Arguments: 20751"""""""""" 20752 20753The first argument is a floating-point number. The return value is an 20754integer type. Not all types are supported on all targets. The supported 20755types are the same as the ``llvm.lround`` intrinsic and the ``lround`` 20756libm functions. 20757 20758The second argument specifies the exception behavior as described above. 20759 20760Semantics: 20761"""""""""" 20762 20763This function returns the same values as the libm ``lround`` functions 20764would and handles error conditions in the same way. 20765 20766 20767'``llvm.experimental.constrained.llround``' Intrinsic 20768^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20769 20770Syntax: 20771""""""" 20772 20773:: 20774 20775 declare <inttype> 20776 @llvm.experimental.constrained.llround(<fptype> <op1>, 20777 metadata <exception behavior>) 20778 20779Overview: 20780""""""""" 20781 20782The '``llvm.experimental.constrained.llround``' intrinsic returns the first 20783operand rounded to the nearest integer with ties away from zero. It will 20784raise an inexact floating-point exception if the operand is not an integer. 20785An invalid exception is raised if the result is too large to fit into a 20786supported integer type, and in this case the result is undefined. 20787 20788Arguments: 20789"""""""""" 20790 20791The first argument is a floating-point number. The return value is an 20792integer type. Not all types are supported on all targets. The supported 20793types are the same as the ``llvm.llround`` intrinsic and the ``llround`` 20794libm functions. 20795 20796The second argument specifies the exception behavior as described above. 20797 20798Semantics: 20799"""""""""" 20800 20801This function returns the same values as the libm ``llround`` functions 20802would and handles error conditions in the same way. 20803 20804 20805'``llvm.experimental.constrained.trunc``' Intrinsic 20806^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20807 20808Syntax: 20809""""""" 20810 20811:: 20812 20813 declare <type> 20814 @llvm.experimental.constrained.trunc(<type> <op1>, 20815 metadata <exception behavior>) 20816 20817Overview: 20818""""""""" 20819 20820The '``llvm.experimental.constrained.trunc``' intrinsic returns the first 20821operand rounded to the nearest integer not larger in magnitude than the 20822operand. 20823 20824Arguments: 20825"""""""""" 20826 20827The first argument and the return value are floating-point numbers of the same 20828type. 20829 20830The second argument specifies the exception behavior as described above. 20831 20832Semantics: 20833"""""""""" 20834 20835This function returns the same values as the libm ``trunc`` functions 20836would and handles error conditions in the same way. 20837 20838.. _int_experimental_noalias_scope_decl: 20839 20840'``llvm.experimental.noalias.scope.decl``' Intrinsic 20841^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20842 20843Syntax: 20844""""""" 20845 20846 20847:: 20848 20849 declare void @llvm.experimental.noalias.scope.decl(metadata !id.scope.list) 20850 20851Overview: 20852""""""""" 20853 20854The ``llvm.experimental.noalias.scope.decl`` intrinsic identifies where a 20855noalias scope is declared. When the intrinsic is duplicated, a decision must 20856also be made about the scope: depending on the reason of the duplication, 20857the scope might need to be duplicated as well. 20858 20859 20860Arguments: 20861"""""""""" 20862 20863The ``!id.scope.list`` argument is metadata that is a list of ``noalias`` 20864metadata references. The format is identical to that required for ``noalias`` 20865metadata. This list must have exactly one element. 20866 20867Semantics: 20868"""""""""" 20869 20870The ``llvm.experimental.noalias.scope.decl`` intrinsic identifies where a 20871noalias scope is declared. When the intrinsic is duplicated, a decision must 20872also be made about the scope: depending on the reason of the duplication, 20873the scope might need to be duplicated as well. 20874 20875For example, when the intrinsic is used inside a loop body, and that loop is 20876unrolled, the associated noalias scope must also be duplicated. Otherwise, the 20877noalias property it signifies would spill across loop iterations, whereas it 20878was only valid within a single iteration. 20879 20880.. code-block:: llvm 20881 20882 ; This examples shows two possible positions for noalias.decl and how they impact the semantics: 20883 ; If it is outside the loop (Version 1), then %a and %b are noalias across *all* iterations. 20884 ; If it is inside the loop (Version 2), then %a and %b are noalias only within *one* iteration. 20885 declare void @decl_in_loop(i8* %a.base, i8* %b.base) { 20886 entry: 20887 ; call void @llvm.experimental.noalias.scope.decl(metadata !2) ; Version 1: noalias decl outside loop 20888 br label %loop 20889 20890 loop: 20891 %a = phi i8* [ %a.base, %entry ], [ %a.inc, %loop ] 20892 %b = phi i8* [ %b.base, %entry ], [ %b.inc, %loop ] 20893 ; call void @llvm.experimental.noalias.scope.decl(metadata !2) ; Version 2: noalias decl inside loop 20894 %val = load i8, i8* %a, !alias.scope !2 20895 store i8 %val, i8* %b, !noalias !2 20896 %a.inc = getelementptr inbounds i8, i8* %a, i64 1 20897 %b.inc = getelementptr inbounds i8, i8* %b, i64 1 20898 %cond = call i1 @cond() 20899 br i1 %cond, label %loop, label %exit 20900 20901 exit: 20902 ret void 20903 } 20904 20905 !0 = !{!0} ; domain 20906 !1 = !{!1, !0} ; scope 20907 !2 = !{!1} ; scope list 20908 20909Multiple calls to `@llvm.experimental.noalias.scope.decl` for the same scope 20910are possible, but one should never dominate another. Violations are pointed out 20911by the verifier as they indicate a problem in either a transformation pass or 20912the input. 20913 20914 20915Floating Point Environment Manipulation intrinsics 20916-------------------------------------------------- 20917 20918These functions read or write floating point environment, such as rounding 20919mode or state of floating point exceptions. Altering the floating point 20920environment requires special care. See :ref:`Floating Point Environment <floatenv>`. 20921 20922'``llvm.flt.rounds``' Intrinsic 20923^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20924 20925Syntax: 20926""""""" 20927 20928:: 20929 20930 declare i32 @llvm.flt.rounds() 20931 20932Overview: 20933""""""""" 20934 20935The '``llvm.flt.rounds``' intrinsic reads the current rounding mode. 20936 20937Semantics: 20938"""""""""" 20939 20940The '``llvm.flt.rounds``' intrinsic returns the current rounding mode. 20941Encoding of the returned values is same as the result of ``FLT_ROUNDS``, 20942specified by C standard: 20943 20944:: 20945 20946 0 - toward zero 20947 1 - to nearest, ties to even 20948 2 - toward positive infinity 20949 3 - toward negative infinity 20950 4 - to nearest, ties away from zero 20951 20952Other values may be used to represent additional rounding modes, supported by a 20953target. These values are target-specific. 20954 20955 20956'``llvm.set.rounding``' Intrinsic 20957^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20958 20959Syntax: 20960""""""" 20961 20962:: 20963 20964 declare void @llvm.set.rounding(i32 <val>) 20965 20966Overview: 20967""""""""" 20968 20969The '``llvm.set.rounding``' intrinsic sets current rounding mode. 20970 20971Arguments: 20972"""""""""" 20973 20974The argument is the required rounding mode. Encoding of rounding mode is 20975the same as used by '``llvm.flt.rounds``'. 20976 20977Semantics: 20978"""""""""" 20979 20980The '``llvm.set.rounding``' intrinsic sets the current rounding mode. It is 20981similar to C library function 'fesetround', however this intrinsic does not 20982return any value and uses platform-independent representation of IEEE rounding 20983modes. 20984 20985 20986General Intrinsics 20987------------------ 20988 20989This class of intrinsics is designed to be generic and has no specific 20990purpose. 20991 20992'``llvm.var.annotation``' Intrinsic 20993^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20994 20995Syntax: 20996""""""" 20997 20998:: 20999 21000 declare void @llvm.var.annotation(i8* <val>, i8* <str>, i8* <str>, i32 <int>) 21001 21002Overview: 21003""""""""" 21004 21005The '``llvm.var.annotation``' intrinsic. 21006 21007Arguments: 21008"""""""""" 21009 21010The first argument is a pointer to a value, the second is a pointer to a 21011global string, the third is a pointer to a global string which is the 21012source file name, and the last argument is the line number. 21013 21014Semantics: 21015"""""""""" 21016 21017This intrinsic allows annotation of local variables with arbitrary 21018strings. This can be useful for special purpose optimizations that want 21019to look for these annotations. These have no other defined use; they are 21020ignored by code generation and optimization. 21021 21022'``llvm.ptr.annotation.*``' Intrinsic 21023^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21024 21025Syntax: 21026""""""" 21027 21028This is an overloaded intrinsic. You can use '``llvm.ptr.annotation``' on a 21029pointer to an integer of any width. *NOTE* you must specify an address space for 21030the pointer. The identifier for the default address space is the integer 21031'``0``'. 21032 21033:: 21034 21035 declare i8* @llvm.ptr.annotation.p<address space>i8(i8* <val>, i8* <str>, i8* <str>, i32 <int>) 21036 declare i16* @llvm.ptr.annotation.p<address space>i16(i16* <val>, i8* <str>, i8* <str>, i32 <int>) 21037 declare i32* @llvm.ptr.annotation.p<address space>i32(i32* <val>, i8* <str>, i8* <str>, i32 <int>) 21038 declare i64* @llvm.ptr.annotation.p<address space>i64(i64* <val>, i8* <str>, i8* <str>, i32 <int>) 21039 declare i256* @llvm.ptr.annotation.p<address space>i256(i256* <val>, i8* <str>, i8* <str>, i32 <int>) 21040 21041Overview: 21042""""""""" 21043 21044The '``llvm.ptr.annotation``' intrinsic. 21045 21046Arguments: 21047"""""""""" 21048 21049The first argument is a pointer to an integer value of arbitrary bitwidth 21050(result of some expression), the second is a pointer to a global string, the 21051third is a pointer to a global string which is the source file name, and the 21052last argument is the line number. It returns the value of the first argument. 21053 21054Semantics: 21055"""""""""" 21056 21057This intrinsic allows annotation of a pointer to an integer with arbitrary 21058strings. This can be useful for special purpose optimizations that want to look 21059for these annotations. These have no other defined use; they are ignored by code 21060generation and optimization. 21061 21062'``llvm.annotation.*``' Intrinsic 21063^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21064 21065Syntax: 21066""""""" 21067 21068This is an overloaded intrinsic. You can use '``llvm.annotation``' on 21069any integer bit width. 21070 21071:: 21072 21073 declare i8 @llvm.annotation.i8(i8 <val>, i8* <str>, i8* <str>, i32 <int>) 21074 declare i16 @llvm.annotation.i16(i16 <val>, i8* <str>, i8* <str>, i32 <int>) 21075 declare i32 @llvm.annotation.i32(i32 <val>, i8* <str>, i8* <str>, i32 <int>) 21076 declare i64 @llvm.annotation.i64(i64 <val>, i8* <str>, i8* <str>, i32 <int>) 21077 declare i256 @llvm.annotation.i256(i256 <val>, i8* <str>, i8* <str>, i32 <int>) 21078 21079Overview: 21080""""""""" 21081 21082The '``llvm.annotation``' intrinsic. 21083 21084Arguments: 21085"""""""""" 21086 21087The first argument is an integer value (result of some expression), the 21088second is a pointer to a global string, the third is a pointer to a 21089global string which is the source file name, and the last argument is 21090the line number. It returns the value of the first argument. 21091 21092Semantics: 21093"""""""""" 21094 21095This intrinsic allows annotations to be put on arbitrary expressions 21096with arbitrary strings. This can be useful for special purpose 21097optimizations that want to look for these annotations. These have no 21098other defined use; they are ignored by code generation and optimization. 21099 21100'``llvm.codeview.annotation``' Intrinsic 21101^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21102 21103Syntax: 21104""""""" 21105 21106This annotation emits a label at its program point and an associated 21107``S_ANNOTATION`` codeview record with some additional string metadata. This is 21108used to implement MSVC's ``__annotation`` intrinsic. It is marked 21109``noduplicate``, so calls to this intrinsic prevent inlining and should be 21110considered expensive. 21111 21112:: 21113 21114 declare void @llvm.codeview.annotation(metadata) 21115 21116Arguments: 21117"""""""""" 21118 21119The argument should be an MDTuple containing any number of MDStrings. 21120 21121'``llvm.trap``' Intrinsic 21122^^^^^^^^^^^^^^^^^^^^^^^^^ 21123 21124Syntax: 21125""""""" 21126 21127:: 21128 21129 declare void @llvm.trap() cold noreturn nounwind 21130 21131Overview: 21132""""""""" 21133 21134The '``llvm.trap``' intrinsic. 21135 21136Arguments: 21137"""""""""" 21138 21139None. 21140 21141Semantics: 21142"""""""""" 21143 21144This intrinsic is lowered to the target dependent trap instruction. If 21145the target does not have a trap instruction, this intrinsic will be 21146lowered to a call of the ``abort()`` function. 21147 21148'``llvm.debugtrap``' Intrinsic 21149^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21150 21151Syntax: 21152""""""" 21153 21154:: 21155 21156 declare void @llvm.debugtrap() nounwind 21157 21158Overview: 21159""""""""" 21160 21161The '``llvm.debugtrap``' intrinsic. 21162 21163Arguments: 21164"""""""""" 21165 21166None. 21167 21168Semantics: 21169"""""""""" 21170 21171This intrinsic is lowered to code which is intended to cause an 21172execution trap with the intention of requesting the attention of a 21173debugger. 21174 21175'``llvm.ubsantrap``' Intrinsic 21176^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21177 21178Syntax: 21179""""""" 21180 21181:: 21182 21183 declare void @llvm.ubsantrap(i8 immarg) cold noreturn nounwind 21184 21185Overview: 21186""""""""" 21187 21188The '``llvm.ubsantrap``' intrinsic. 21189 21190Arguments: 21191"""""""""" 21192 21193An integer describing the kind of failure detected. 21194 21195Semantics: 21196"""""""""" 21197 21198This intrinsic is lowered to code which is intended to cause an execution trap, 21199embedding the argument into encoding of that trap somehow to discriminate 21200crashes if possible. 21201 21202Equivalent to ``@llvm.trap`` for targets that do not support this behaviour. 21203 21204'``llvm.stackprotector``' Intrinsic 21205^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21206 21207Syntax: 21208""""""" 21209 21210:: 21211 21212 declare void @llvm.stackprotector(i8* <guard>, i8** <slot>) 21213 21214Overview: 21215""""""""" 21216 21217The ``llvm.stackprotector`` intrinsic takes the ``guard`` and stores it 21218onto the stack at ``slot``. The stack slot is adjusted to ensure that it 21219is placed on the stack before local variables. 21220 21221Arguments: 21222"""""""""" 21223 21224The ``llvm.stackprotector`` intrinsic requires two pointer arguments. 21225The first argument is the value loaded from the stack guard 21226``@__stack_chk_guard``. The second variable is an ``alloca`` that has 21227enough space to hold the value of the guard. 21228 21229Semantics: 21230"""""""""" 21231 21232This intrinsic causes the prologue/epilogue inserter to force the position of 21233the ``AllocaInst`` stack slot to be before local variables on the stack. This is 21234to ensure that if a local variable on the stack is overwritten, it will destroy 21235the value of the guard. When the function exits, the guard on the stack is 21236checked against the original guard by ``llvm.stackprotectorcheck``. If they are 21237different, then ``llvm.stackprotectorcheck`` causes the program to abort by 21238calling the ``__stack_chk_fail()`` function. 21239 21240'``llvm.stackguard``' Intrinsic 21241^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21242 21243Syntax: 21244""""""" 21245 21246:: 21247 21248 declare i8* @llvm.stackguard() 21249 21250Overview: 21251""""""""" 21252 21253The ``llvm.stackguard`` intrinsic returns the system stack guard value. 21254 21255It should not be generated by frontends, since it is only for internal usage. 21256The reason why we create this intrinsic is that we still support IR form Stack 21257Protector in FastISel. 21258 21259Arguments: 21260"""""""""" 21261 21262None. 21263 21264Semantics: 21265"""""""""" 21266 21267On some platforms, the value returned by this intrinsic remains unchanged 21268between loads in the same thread. On other platforms, it returns the same 21269global variable value, if any, e.g. ``@__stack_chk_guard``. 21270 21271Currently some platforms have IR-level customized stack guard loading (e.g. 21272X86 Linux) that is not handled by ``llvm.stackguard()``, while they should be 21273in the future. 21274 21275'``llvm.objectsize``' Intrinsic 21276^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21277 21278Syntax: 21279""""""" 21280 21281:: 21282 21283 declare i32 @llvm.objectsize.i32(i8* <object>, i1 <min>, i1 <nullunknown>, i1 <dynamic>) 21284 declare i64 @llvm.objectsize.i64(i8* <object>, i1 <min>, i1 <nullunknown>, i1 <dynamic>) 21285 21286Overview: 21287""""""""" 21288 21289The ``llvm.objectsize`` intrinsic is designed to provide information to the 21290optimizer to determine whether a) an operation (like memcpy) will overflow a 21291buffer that corresponds to an object, or b) that a runtime check for overflow 21292isn't necessary. An object in this context means an allocation of a specific 21293class, structure, array, or other object. 21294 21295Arguments: 21296"""""""""" 21297 21298The ``llvm.objectsize`` intrinsic takes four arguments. The first argument is a 21299pointer to or into the ``object``. The second argument determines whether 21300``llvm.objectsize`` returns 0 (if true) or -1 (if false) when the object size is 21301unknown. The third argument controls how ``llvm.objectsize`` acts when ``null`` 21302in address space 0 is used as its pointer argument. If it's ``false``, 21303``llvm.objectsize`` reports 0 bytes available when given ``null``. Otherwise, if 21304the ``null`` is in a non-zero address space or if ``true`` is given for the 21305third argument of ``llvm.objectsize``, we assume its size is unknown. The fourth 21306argument to ``llvm.objectsize`` determines if the value should be evaluated at 21307runtime. 21308 21309The second, third, and fourth arguments only accept constants. 21310 21311Semantics: 21312"""""""""" 21313 21314The ``llvm.objectsize`` intrinsic is lowered to a value representing the size of 21315the object concerned. If the size cannot be determined, ``llvm.objectsize`` 21316returns ``i32/i64 -1 or 0`` (depending on the ``min`` argument). 21317 21318'``llvm.expect``' Intrinsic 21319^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21320 21321Syntax: 21322""""""" 21323 21324This is an overloaded intrinsic. You can use ``llvm.expect`` on any 21325integer bit width. 21326 21327:: 21328 21329 declare i1 @llvm.expect.i1(i1 <val>, i1 <expected_val>) 21330 declare i32 @llvm.expect.i32(i32 <val>, i32 <expected_val>) 21331 declare i64 @llvm.expect.i64(i64 <val>, i64 <expected_val>) 21332 21333Overview: 21334""""""""" 21335 21336The ``llvm.expect`` intrinsic provides information about expected (the 21337most probable) value of ``val``, which can be used by optimizers. 21338 21339Arguments: 21340"""""""""" 21341 21342The ``llvm.expect`` intrinsic takes two arguments. The first argument is 21343a value. The second argument is an expected value. 21344 21345Semantics: 21346"""""""""" 21347 21348This intrinsic is lowered to the ``val``. 21349 21350'``llvm.expect.with.probability``' Intrinsic 21351^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21352 21353Syntax: 21354""""""" 21355 21356This intrinsic is similar to ``llvm.expect``. This is an overloaded intrinsic. 21357You can use ``llvm.expect.with.probability`` on any integer bit width. 21358 21359:: 21360 21361 declare i1 @llvm.expect.with.probability.i1(i1 <val>, i1 <expected_val>, double <prob>) 21362 declare i32 @llvm.expect.with.probability.i32(i32 <val>, i32 <expected_val>, double <prob>) 21363 declare i64 @llvm.expect.with.probability.i64(i64 <val>, i64 <expected_val>, double <prob>) 21364 21365Overview: 21366""""""""" 21367 21368The ``llvm.expect.with.probability`` intrinsic provides information about 21369expected value of ``val`` with probability(or confidence) ``prob``, which can 21370be used by optimizers. 21371 21372Arguments: 21373"""""""""" 21374 21375The ``llvm.expect.with.probability`` intrinsic takes three arguments. The first 21376argument is a value. The second argument is an expected value. The third 21377argument is a probability. 21378 21379Semantics: 21380"""""""""" 21381 21382This intrinsic is lowered to the ``val``. 21383 21384.. _int_assume: 21385 21386'``llvm.assume``' Intrinsic 21387^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21388 21389Syntax: 21390""""""" 21391 21392:: 21393 21394 declare void @llvm.assume(i1 %cond) 21395 21396Overview: 21397""""""""" 21398 21399The ``llvm.assume`` allows the optimizer to assume that the provided 21400condition is true. This information can then be used in simplifying other parts 21401of the code. 21402 21403More complex assumptions can be encoded as 21404:ref:`assume operand bundles <assume_opbundles>`. 21405 21406Arguments: 21407"""""""""" 21408 21409The argument of the call is the condition which the optimizer may assume is 21410always true. 21411 21412Semantics: 21413"""""""""" 21414 21415The intrinsic allows the optimizer to assume that the provided condition is 21416always true whenever the control flow reaches the intrinsic call. No code is 21417generated for this intrinsic, and instructions that contribute only to the 21418provided condition are not used for code generation. If the condition is 21419violated during execution, the behavior is undefined. 21420 21421Note that the optimizer might limit the transformations performed on values 21422used by the ``llvm.assume`` intrinsic in order to preserve the instructions 21423only used to form the intrinsic's input argument. This might prove undesirable 21424if the extra information provided by the ``llvm.assume`` intrinsic does not cause 21425sufficient overall improvement in code quality. For this reason, 21426``llvm.assume`` should not be used to document basic mathematical invariants 21427that the optimizer can otherwise deduce or facts that are of little use to the 21428optimizer. 21429 21430.. _int_ssa_copy: 21431 21432'``llvm.ssa.copy``' Intrinsic 21433^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21434 21435Syntax: 21436""""""" 21437 21438:: 21439 21440 declare type @llvm.ssa.copy(type %operand) returned(1) readnone 21441 21442Arguments: 21443"""""""""" 21444 21445The first argument is an operand which is used as the returned value. 21446 21447Overview: 21448"""""""""" 21449 21450The ``llvm.ssa.copy`` intrinsic can be used to attach information to 21451operations by copying them and giving them new names. For example, 21452the PredicateInfo utility uses it to build Extended SSA form, and 21453attach various forms of information to operands that dominate specific 21454uses. It is not meant for general use, only for building temporary 21455renaming forms that require value splits at certain points. 21456 21457.. _type.test: 21458 21459'``llvm.type.test``' Intrinsic 21460^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21461 21462Syntax: 21463""""""" 21464 21465:: 21466 21467 declare i1 @llvm.type.test(i8* %ptr, metadata %type) nounwind readnone 21468 21469 21470Arguments: 21471"""""""""" 21472 21473The first argument is a pointer to be tested. The second argument is a 21474metadata object representing a :doc:`type identifier <TypeMetadata>`. 21475 21476Overview: 21477""""""""" 21478 21479The ``llvm.type.test`` intrinsic tests whether the given pointer is associated 21480with the given type identifier. 21481 21482.. _type.checked.load: 21483 21484'``llvm.type.checked.load``' Intrinsic 21485^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21486 21487Syntax: 21488""""""" 21489 21490:: 21491 21492 declare {i8*, i1} @llvm.type.checked.load(i8* %ptr, i32 %offset, metadata %type) argmemonly nounwind readonly 21493 21494 21495Arguments: 21496"""""""""" 21497 21498The first argument is a pointer from which to load a function pointer. The 21499second argument is the byte offset from which to load the function pointer. The 21500third argument is a metadata object representing a :doc:`type identifier 21501<TypeMetadata>`. 21502 21503Overview: 21504""""""""" 21505 21506The ``llvm.type.checked.load`` intrinsic safely loads a function pointer from a 21507virtual table pointer using type metadata. This intrinsic is used to implement 21508control flow integrity in conjunction with virtual call optimization. The 21509virtual call optimization pass will optimize away ``llvm.type.checked.load`` 21510intrinsics associated with devirtualized calls, thereby removing the type 21511check in cases where it is not needed to enforce the control flow integrity 21512constraint. 21513 21514If the given pointer is associated with a type metadata identifier, this 21515function returns true as the second element of its return value. (Note that 21516the function may also return true if the given pointer is not associated 21517with a type metadata identifier.) If the function's return value's second 21518element is true, the following rules apply to the first element: 21519 21520- If the given pointer is associated with the given type metadata identifier, 21521 it is the function pointer loaded from the given byte offset from the given 21522 pointer. 21523 21524- If the given pointer is not associated with the given type metadata 21525 identifier, it is one of the following (the choice of which is unspecified): 21526 21527 1. The function pointer that would have been loaded from an arbitrarily chosen 21528 (through an unspecified mechanism) pointer associated with the type 21529 metadata. 21530 21531 2. If the function has a non-void return type, a pointer to a function that 21532 returns an unspecified value without causing side effects. 21533 21534If the function's return value's second element is false, the value of the 21535first element is undefined. 21536 21537 21538'``llvm.arithmetic.fence``' Intrinsic 21539^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21540 21541Syntax: 21542""""""" 21543 21544:: 21545 21546 declare <type> 21547 @llvm.arithmetic.fence(<type> <op>) 21548 21549Overview: 21550""""""""" 21551 21552The purpose of the ``llvm.arithmetic.fence`` intrinsic 21553is to prevent the optimizer from performaing fast-math optimizations, 21554particularly reassociation, 21555between the argument and the expression that contains the argument. 21556It can be used to preserve the parentheses in the source language. 21557 21558Arguments: 21559"""""""""" 21560 21561The ``llvm.arithmetic.fence`` intrinsic takes only one argument. 21562The argument and the return value are floating-point numbers, 21563or vector floating-point numbers, of the same type. 21564 21565Semantics: 21566"""""""""" 21567 21568This intrinsic returns the value of its operand. The optimizer can optimize 21569the argument, but the optimizer cannot hoist any component of the operand 21570to the containing context, and the optimizer cannot move the calculation of 21571any expression in the containing context into the operand. 21572 21573 21574'``llvm.donothing``' Intrinsic 21575^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21576 21577Syntax: 21578""""""" 21579 21580:: 21581 21582 declare void @llvm.donothing() nounwind readnone 21583 21584Overview: 21585""""""""" 21586 21587The ``llvm.donothing`` intrinsic doesn't perform any operation. It's one of only 21588three intrinsics (besides ``llvm.experimental.patchpoint`` and 21589``llvm.experimental.gc.statepoint``) that can be called with an invoke 21590instruction. 21591 21592Arguments: 21593"""""""""" 21594 21595None. 21596 21597Semantics: 21598"""""""""" 21599 21600This intrinsic does nothing, and it's removed by optimizers and ignored 21601by codegen. 21602 21603'``llvm.experimental.deoptimize``' Intrinsic 21604^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21605 21606Syntax: 21607""""""" 21608 21609:: 21610 21611 declare type @llvm.experimental.deoptimize(...) [ "deopt"(...) ] 21612 21613Overview: 21614""""""""" 21615 21616This intrinsic, together with :ref:`deoptimization operand bundles 21617<deopt_opbundles>`, allow frontends to express transfer of control and 21618frame-local state from the currently executing (typically more specialized, 21619hence faster) version of a function into another (typically more generic, hence 21620slower) version. 21621 21622In languages with a fully integrated managed runtime like Java and JavaScript 21623this intrinsic can be used to implement "uncommon trap" or "side exit" like 21624functionality. In unmanaged languages like C and C++, this intrinsic can be 21625used to represent the slow paths of specialized functions. 21626 21627 21628Arguments: 21629"""""""""" 21630 21631The intrinsic takes an arbitrary number of arguments, whose meaning is 21632decided by the :ref:`lowering strategy<deoptimize_lowering>`. 21633 21634Semantics: 21635"""""""""" 21636 21637The ``@llvm.experimental.deoptimize`` intrinsic executes an attached 21638deoptimization continuation (denoted using a :ref:`deoptimization 21639operand bundle <deopt_opbundles>`) and returns the value returned by 21640the deoptimization continuation. Defining the semantic properties of 21641the continuation itself is out of scope of the language reference -- 21642as far as LLVM is concerned, the deoptimization continuation can 21643invoke arbitrary side effects, including reading from and writing to 21644the entire heap. 21645 21646Deoptimization continuations expressed using ``"deopt"`` operand bundles always 21647continue execution to the end of the physical frame containing them, so all 21648calls to ``@llvm.experimental.deoptimize`` must be in "tail position": 21649 21650 - ``@llvm.experimental.deoptimize`` cannot be invoked. 21651 - The call must immediately precede a :ref:`ret <i_ret>` instruction. 21652 - The ``ret`` instruction must return the value produced by the 21653 ``@llvm.experimental.deoptimize`` call if there is one, or void. 21654 21655Note that the above restrictions imply that the return type for a call to 21656``@llvm.experimental.deoptimize`` will match the return type of its immediate 21657caller. 21658 21659The inliner composes the ``"deopt"`` continuations of the caller into the 21660``"deopt"`` continuations present in the inlinee, and also updates calls to this 21661intrinsic to return directly from the frame of the function it inlined into. 21662 21663All declarations of ``@llvm.experimental.deoptimize`` must share the 21664same calling convention. 21665 21666.. _deoptimize_lowering: 21667 21668Lowering: 21669""""""""" 21670 21671Calls to ``@llvm.experimental.deoptimize`` are lowered to calls to the 21672symbol ``__llvm_deoptimize`` (it is the frontend's responsibility to 21673ensure that this symbol is defined). The call arguments to 21674``@llvm.experimental.deoptimize`` are lowered as if they were formal 21675arguments of the specified types, and not as varargs. 21676 21677 21678'``llvm.experimental.guard``' Intrinsic 21679^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21680 21681Syntax: 21682""""""" 21683 21684:: 21685 21686 declare void @llvm.experimental.guard(i1, ...) [ "deopt"(...) ] 21687 21688Overview: 21689""""""""" 21690 21691This intrinsic, together with :ref:`deoptimization operand bundles 21692<deopt_opbundles>`, allows frontends to express guards or checks on 21693optimistic assumptions made during compilation. The semantics of 21694``@llvm.experimental.guard`` is defined in terms of 21695``@llvm.experimental.deoptimize`` -- its body is defined to be 21696equivalent to: 21697 21698.. code-block:: text 21699 21700 define void @llvm.experimental.guard(i1 %pred, <args...>) { 21701 %realPred = and i1 %pred, undef 21702 br i1 %realPred, label %continue, label %leave [, !make.implicit !{}] 21703 21704 leave: 21705 call void @llvm.experimental.deoptimize(<args...>) [ "deopt"() ] 21706 ret void 21707 21708 continue: 21709 ret void 21710 } 21711 21712 21713with the optional ``[, !make.implicit !{}]`` present if and only if it 21714is present on the call site. For more details on ``!make.implicit``, 21715see :doc:`FaultMaps`. 21716 21717In words, ``@llvm.experimental.guard`` executes the attached 21718``"deopt"`` continuation if (but **not** only if) its first argument 21719is ``false``. Since the optimizer is allowed to replace the ``undef`` 21720with an arbitrary value, it can optimize guard to fail "spuriously", 21721i.e. without the original condition being false (hence the "not only 21722if"); and this allows for "check widening" type optimizations. 21723 21724``@llvm.experimental.guard`` cannot be invoked. 21725 21726After ``@llvm.experimental.guard`` was first added, a more general 21727formulation was found in ``@llvm.experimental.widenable.condition``. 21728Support for ``@llvm.experimental.guard`` is slowly being rephrased in 21729terms of this alternate. 21730 21731'``llvm.experimental.widenable.condition``' Intrinsic 21732^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21733 21734Syntax: 21735""""""" 21736 21737:: 21738 21739 declare i1 @llvm.experimental.widenable.condition() 21740 21741Overview: 21742""""""""" 21743 21744This intrinsic represents a "widenable condition" which is 21745boolean expressions with the following property: whether this 21746expression is `true` or `false`, the program is correct and 21747well-defined. 21748 21749Together with :ref:`deoptimization operand bundles <deopt_opbundles>`, 21750``@llvm.experimental.widenable.condition`` allows frontends to 21751express guards or checks on optimistic assumptions made during 21752compilation and represent them as branch instructions on special 21753conditions. 21754 21755While this may appear similar in semantics to `undef`, it is very 21756different in that an invocation produces a particular, singular 21757value. It is also intended to be lowered late, and remain available 21758for specific optimizations and transforms that can benefit from its 21759special properties. 21760 21761Arguments: 21762"""""""""" 21763 21764None. 21765 21766Semantics: 21767"""""""""" 21768 21769The intrinsic ``@llvm.experimental.widenable.condition()`` 21770returns either `true` or `false`. For each evaluation of a call 21771to this intrinsic, the program must be valid and correct both if 21772it returns `true` and if it returns `false`. This allows 21773transformation passes to replace evaluations of this intrinsic 21774with either value whenever one is beneficial. 21775 21776When used in a branch condition, it allows us to choose between 21777two alternative correct solutions for the same problem, like 21778in example below: 21779 21780.. code-block:: text 21781 21782 %cond = call i1 @llvm.experimental.widenable.condition() 21783 br i1 %cond, label %solution_1, label %solution_2 21784 21785 label %fast_path: 21786 ; Apply memory-consuming but fast solution for a task. 21787 21788 label %slow_path: 21789 ; Cheap in memory but slow solution. 21790 21791Whether the result of intrinsic's call is `true` or `false`, 21792it should be correct to pick either solution. We can switch 21793between them by replacing the result of 21794``@llvm.experimental.widenable.condition`` with different 21795`i1` expressions. 21796 21797This is how it can be used to represent guards as widenable branches: 21798 21799.. code-block:: text 21800 21801 block: 21802 ; Unguarded instructions 21803 call void @llvm.experimental.guard(i1 %cond, <args...>) ["deopt"(<deopt_args...>)] 21804 ; Guarded instructions 21805 21806Can be expressed in an alternative equivalent form of explicit branch using 21807``@llvm.experimental.widenable.condition``: 21808 21809.. code-block:: text 21810 21811 block: 21812 ; Unguarded instructions 21813 %widenable_condition = call i1 @llvm.experimental.widenable.condition() 21814 %guard_condition = and i1 %cond, %widenable_condition 21815 br i1 %guard_condition, label %guarded, label %deopt 21816 21817 guarded: 21818 ; Guarded instructions 21819 21820 deopt: 21821 call type @llvm.experimental.deoptimize(<args...>) [ "deopt"(<deopt_args...>) ] 21822 21823So the block `guarded` is only reachable when `%cond` is `true`, 21824and it should be valid to go to the block `deopt` whenever `%cond` 21825is `true` or `false`. 21826 21827``@llvm.experimental.widenable.condition`` will never throw, thus 21828it cannot be invoked. 21829 21830Guard widening: 21831""""""""""""""" 21832 21833When ``@llvm.experimental.widenable.condition()`` is used in 21834condition of a guard represented as explicit branch, it is 21835legal to widen the guard's condition with any additional 21836conditions. 21837 21838Guard widening looks like replacement of 21839 21840.. code-block:: text 21841 21842 %widenable_cond = call i1 @llvm.experimental.widenable.condition() 21843 %guard_cond = and i1 %cond, %widenable_cond 21844 br i1 %guard_cond, label %guarded, label %deopt 21845 21846with 21847 21848.. code-block:: text 21849 21850 %widenable_cond = call i1 @llvm.experimental.widenable.condition() 21851 %new_cond = and i1 %any_other_cond, %widenable_cond 21852 %new_guard_cond = and i1 %cond, %new_cond 21853 br i1 %new_guard_cond, label %guarded, label %deopt 21854 21855for this branch. Here `%any_other_cond` is an arbitrarily chosen 21856well-defined `i1` value. By making guard widening, we may 21857impose stricter conditions on `guarded` block and bail to the 21858deopt when the new condition is not met. 21859 21860Lowering: 21861""""""""" 21862 21863Default lowering strategy is replacing the result of 21864call of ``@llvm.experimental.widenable.condition`` with 21865constant `true`. However it is always correct to replace 21866it with any other `i1` value. Any pass can 21867freely do it if it can benefit from non-default lowering. 21868 21869 21870'``llvm.load.relative``' Intrinsic 21871^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21872 21873Syntax: 21874""""""" 21875 21876:: 21877 21878 declare i8* @llvm.load.relative.iN(i8* %ptr, iN %offset) argmemonly nounwind readonly 21879 21880Overview: 21881""""""""" 21882 21883This intrinsic loads a 32-bit value from the address ``%ptr + %offset``, 21884adds ``%ptr`` to that value and returns it. The constant folder specifically 21885recognizes the form of this intrinsic and the constant initializers it may 21886load from; if a loaded constant initializer is known to have the form 21887``i32 trunc(x - %ptr)``, the intrinsic call is folded to ``x``. 21888 21889LLVM provides that the calculation of such a constant initializer will 21890not overflow at link time under the medium code model if ``x`` is an 21891``unnamed_addr`` function. However, it does not provide this guarantee for 21892a constant initializer folded into a function body. This intrinsic can be 21893used to avoid the possibility of overflows when loading from such a constant. 21894 21895.. _llvm_sideeffect: 21896 21897'``llvm.sideeffect``' Intrinsic 21898^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21899 21900Syntax: 21901""""""" 21902 21903:: 21904 21905 declare void @llvm.sideeffect() inaccessiblememonly nounwind 21906 21907Overview: 21908""""""""" 21909 21910The ``llvm.sideeffect`` intrinsic doesn't perform any operation. Optimizers 21911treat it as having side effects, so it can be inserted into a loop to 21912indicate that the loop shouldn't be assumed to terminate (which could 21913potentially lead to the loop being optimized away entirely), even if it's 21914an infinite loop with no other side effects. 21915 21916Arguments: 21917"""""""""" 21918 21919None. 21920 21921Semantics: 21922"""""""""" 21923 21924This intrinsic actually does nothing, but optimizers must assume that it 21925has externally observable side effects. 21926 21927'``llvm.is.constant.*``' Intrinsic 21928^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21929 21930Syntax: 21931""""""" 21932 21933This is an overloaded intrinsic. You can use llvm.is.constant with any argument type. 21934 21935:: 21936 21937 declare i1 @llvm.is.constant.i32(i32 %operand) nounwind readnone 21938 declare i1 @llvm.is.constant.f32(float %operand) nounwind readnone 21939 declare i1 @llvm.is.constant.TYPENAME(TYPE %operand) nounwind readnone 21940 21941Overview: 21942""""""""" 21943 21944The '``llvm.is.constant``' intrinsic will return true if the argument 21945is known to be a manifest compile-time constant. It is guaranteed to 21946fold to either true or false before generating machine code. 21947 21948Semantics: 21949"""""""""" 21950 21951This intrinsic generates no code. If its argument is known to be a 21952manifest compile-time constant value, then the intrinsic will be 21953converted to a constant true value. Otherwise, it will be converted to 21954a constant false value. 21955 21956In particular, note that if the argument is a constant expression 21957which refers to a global (the address of which _is_ a constant, but 21958not manifest during the compile), then the intrinsic evaluates to 21959false. 21960 21961The result also intentionally depends on the result of optimization 21962passes -- e.g., the result can change depending on whether a 21963function gets inlined or not. A function's parameters are 21964obviously not constant. However, a call like 21965``llvm.is.constant.i32(i32 %param)`` *can* return true after the 21966function is inlined, if the value passed to the function parameter was 21967a constant. 21968 21969On the other hand, if constant folding is not run, it will never 21970evaluate to true, even in simple cases. 21971 21972.. _int_ptrmask: 21973 21974'``llvm.ptrmask``' Intrinsic 21975^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21976 21977Syntax: 21978""""""" 21979 21980:: 21981 21982 declare ptrty llvm.ptrmask(ptrty %ptr, intty %mask) readnone speculatable 21983 21984Arguments: 21985"""""""""" 21986 21987The first argument is a pointer. The second argument is an integer. 21988 21989Overview: 21990"""""""""" 21991 21992The ``llvm.ptrmask`` intrinsic masks out bits of the pointer according to a mask. 21993This allows stripping data from tagged pointers without converting them to an 21994integer (ptrtoint/inttoptr). As a consequence, we can preserve more information 21995to facilitate alias analysis and underlying-object detection. 21996 21997Semantics: 21998"""""""""" 21999 22000The result of ``ptrmask(ptr, mask)`` is equivalent to 22001``getelementptr ptr, (ptrtoint(ptr) & mask) - ptrtoint(ptr)``. Both the returned 22002pointer and the first argument are based on the same underlying object (for more 22003information on the *based on* terminology see 22004:ref:`the pointer aliasing rules <pointeraliasing>`). If the bitwidth of the 22005mask argument does not match the pointer size of the target, the mask is 22006zero-extended or truncated accordingly. 22007 22008.. _int_vscale: 22009 22010'``llvm.vscale``' Intrinsic 22011^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22012 22013Syntax: 22014""""""" 22015 22016:: 22017 22018 declare i32 llvm.vscale.i32() 22019 declare i64 llvm.vscale.i64() 22020 22021Overview: 22022""""""""" 22023 22024The ``llvm.vscale`` intrinsic returns the value for ``vscale`` in scalable 22025vectors such as ``<vscale x 16 x i8>``. 22026 22027Semantics: 22028"""""""""" 22029 22030``vscale`` is a positive value that is constant throughout program 22031execution, but is unknown at compile time. 22032If the result value does not fit in the result type, then the result is 22033a :ref:`poison value <poisonvalues>`. 22034 22035 22036Stack Map Intrinsics 22037-------------------- 22038 22039LLVM provides experimental intrinsics to support runtime patching 22040mechanisms commonly desired in dynamic language JITs. These intrinsics 22041are described in :doc:`StackMaps`. 22042 22043Element Wise Atomic Memory Intrinsics 22044------------------------------------- 22045 22046These intrinsics are similar to the standard library memory intrinsics except 22047that they perform memory transfer as a sequence of atomic memory accesses. 22048 22049.. _int_memcpy_element_unordered_atomic: 22050 22051'``llvm.memcpy.element.unordered.atomic``' Intrinsic 22052^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22053 22054Syntax: 22055""""""" 22056 22057This is an overloaded intrinsic. You can use ``llvm.memcpy.element.unordered.atomic`` on 22058any integer bit width and for different address spaces. Not all targets 22059support all bit widths however. 22060 22061:: 22062 22063 declare void @llvm.memcpy.element.unordered.atomic.p0i8.p0i8.i32(i8* <dest>, 22064 i8* <src>, 22065 i32 <len>, 22066 i32 <element_size>) 22067 declare void @llvm.memcpy.element.unordered.atomic.p0i8.p0i8.i64(i8* <dest>, 22068 i8* <src>, 22069 i64 <len>, 22070 i32 <element_size>) 22071 22072Overview: 22073""""""""" 22074 22075The '``llvm.memcpy.element.unordered.atomic.*``' intrinsic is a specialization of the 22076'``llvm.memcpy.*``' intrinsic. It differs in that the ``dest`` and ``src`` are treated 22077as arrays with elements that are exactly ``element_size`` bytes, and the copy between 22078buffers uses a sequence of :ref:`unordered atomic <ordering>` load/store operations 22079that are a positive integer multiple of the ``element_size`` in size. 22080 22081Arguments: 22082"""""""""" 22083 22084The first three arguments are the same as they are in the :ref:`@llvm.memcpy <int_memcpy>` 22085intrinsic, with the added constraint that ``len`` is required to be a positive integer 22086multiple of the ``element_size``. If ``len`` is not a positive integer multiple of 22087``element_size``, then the behaviour of the intrinsic is undefined. 22088 22089``element_size`` must be a compile-time constant positive power of two no greater than 22090target-specific atomic access size limit. 22091 22092For each of the input pointers ``align`` parameter attribute must be specified. It 22093must be a power of two no less than the ``element_size``. Caller guarantees that 22094both the source and destination pointers are aligned to that boundary. 22095 22096Semantics: 22097"""""""""" 22098 22099The '``llvm.memcpy.element.unordered.atomic.*``' intrinsic copies ``len`` bytes of 22100memory from the source location to the destination location. These locations are not 22101allowed to overlap. The memory copy is performed as a sequence of load/store operations 22102where each access is guaranteed to be a multiple of ``element_size`` bytes wide and 22103aligned at an ``element_size`` boundary. 22104 22105The order of the copy is unspecified. The same value may be read from the source 22106buffer many times, but only one write is issued to the destination buffer per 22107element. It is well defined to have concurrent reads and writes to both source and 22108destination provided those reads and writes are unordered atomic when specified. 22109 22110This intrinsic does not provide any additional ordering guarantees over those 22111provided by a set of unordered loads from the source location and stores to the 22112destination. 22113 22114Lowering: 22115""""""""" 22116 22117In the most general case call to the '``llvm.memcpy.element.unordered.atomic.*``' is 22118lowered to a call to the symbol ``__llvm_memcpy_element_unordered_atomic_*``. Where '*' 22119is replaced with an actual element size. See :ref:`RewriteStatepointsForGC intrinsic 22120lowering <RewriteStatepointsForGC_intrinsic_lowering>` for details on GC specific 22121lowering. 22122 22123Optimizer is allowed to inline memory copy when it's profitable to do so. 22124 22125'``llvm.memmove.element.unordered.atomic``' Intrinsic 22126^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22127 22128Syntax: 22129""""""" 22130 22131This is an overloaded intrinsic. You can use 22132``llvm.memmove.element.unordered.atomic`` on any integer bit width and for 22133different address spaces. Not all targets support all bit widths however. 22134 22135:: 22136 22137 declare void @llvm.memmove.element.unordered.atomic.p0i8.p0i8.i32(i8* <dest>, 22138 i8* <src>, 22139 i32 <len>, 22140 i32 <element_size>) 22141 declare void @llvm.memmove.element.unordered.atomic.p0i8.p0i8.i64(i8* <dest>, 22142 i8* <src>, 22143 i64 <len>, 22144 i32 <element_size>) 22145 22146Overview: 22147""""""""" 22148 22149The '``llvm.memmove.element.unordered.atomic.*``' intrinsic is a specialization 22150of the '``llvm.memmove.*``' intrinsic. It differs in that the ``dest`` and 22151``src`` are treated as arrays with elements that are exactly ``element_size`` 22152bytes, and the copy between buffers uses a sequence of 22153:ref:`unordered atomic <ordering>` load/store operations that are a positive 22154integer multiple of the ``element_size`` in size. 22155 22156Arguments: 22157"""""""""" 22158 22159The first three arguments are the same as they are in the 22160:ref:`@llvm.memmove <int_memmove>` intrinsic, with the added constraint that 22161``len`` is required to be a positive integer multiple of the ``element_size``. 22162If ``len`` is not a positive integer multiple of ``element_size``, then the 22163behaviour of the intrinsic is undefined. 22164 22165``element_size`` must be a compile-time constant positive power of two no 22166greater than a target-specific atomic access size limit. 22167 22168For each of the input pointers the ``align`` parameter attribute must be 22169specified. It must be a power of two no less than the ``element_size``. Caller 22170guarantees that both the source and destination pointers are aligned to that 22171boundary. 22172 22173Semantics: 22174"""""""""" 22175 22176The '``llvm.memmove.element.unordered.atomic.*``' intrinsic copies ``len`` bytes 22177of memory from the source location to the destination location. These locations 22178are allowed to overlap. The memory copy is performed as a sequence of load/store 22179operations where each access is guaranteed to be a multiple of ``element_size`` 22180bytes wide and aligned at an ``element_size`` boundary. 22181 22182The order of the copy is unspecified. The same value may be read from the source 22183buffer many times, but only one write is issued to the destination buffer per 22184element. It is well defined to have concurrent reads and writes to both source 22185and destination provided those reads and writes are unordered atomic when 22186specified. 22187 22188This intrinsic does not provide any additional ordering guarantees over those 22189provided by a set of unordered loads from the source location and stores to the 22190destination. 22191 22192Lowering: 22193""""""""" 22194 22195In the most general case call to the 22196'``llvm.memmove.element.unordered.atomic.*``' is lowered to a call to the symbol 22197``__llvm_memmove_element_unordered_atomic_*``. Where '*' is replaced with an 22198actual element size. See :ref:`RewriteStatepointsForGC intrinsic lowering 22199<RewriteStatepointsForGC_intrinsic_lowering>` for details on GC specific 22200lowering. 22201 22202The optimizer is allowed to inline the memory copy when it's profitable to do so. 22203 22204.. _int_memset_element_unordered_atomic: 22205 22206'``llvm.memset.element.unordered.atomic``' Intrinsic 22207^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22208 22209Syntax: 22210""""""" 22211 22212This is an overloaded intrinsic. You can use ``llvm.memset.element.unordered.atomic`` on 22213any integer bit width and for different address spaces. Not all targets 22214support all bit widths however. 22215 22216:: 22217 22218 declare void @llvm.memset.element.unordered.atomic.p0i8.i32(i8* <dest>, 22219 i8 <value>, 22220 i32 <len>, 22221 i32 <element_size>) 22222 declare void @llvm.memset.element.unordered.atomic.p0i8.i64(i8* <dest>, 22223 i8 <value>, 22224 i64 <len>, 22225 i32 <element_size>) 22226 22227Overview: 22228""""""""" 22229 22230The '``llvm.memset.element.unordered.atomic.*``' intrinsic is a specialization of the 22231'``llvm.memset.*``' intrinsic. It differs in that the ``dest`` is treated as an array 22232with elements that are exactly ``element_size`` bytes, and the assignment to that array 22233uses uses a sequence of :ref:`unordered atomic <ordering>` store operations 22234that are a positive integer multiple of the ``element_size`` in size. 22235 22236Arguments: 22237"""""""""" 22238 22239The first three arguments are the same as they are in the :ref:`@llvm.memset <int_memset>` 22240intrinsic, with the added constraint that ``len`` is required to be a positive integer 22241multiple of the ``element_size``. If ``len`` is not a positive integer multiple of 22242``element_size``, then the behaviour of the intrinsic is undefined. 22243 22244``element_size`` must be a compile-time constant positive power of two no greater than 22245target-specific atomic access size limit. 22246 22247The ``dest`` input pointer must have the ``align`` parameter attribute specified. It 22248must be a power of two no less than the ``element_size``. Caller guarantees that 22249the destination pointer is aligned to that boundary. 22250 22251Semantics: 22252"""""""""" 22253 22254The '``llvm.memset.element.unordered.atomic.*``' intrinsic sets the ``len`` bytes of 22255memory starting at the destination location to the given ``value``. The memory is 22256set with a sequence of store operations where each access is guaranteed to be a 22257multiple of ``element_size`` bytes wide and aligned at an ``element_size`` boundary. 22258 22259The order of the assignment is unspecified. Only one write is issued to the 22260destination buffer per element. It is well defined to have concurrent reads and 22261writes to the destination provided those reads and writes are unordered atomic 22262when specified. 22263 22264This intrinsic does not provide any additional ordering guarantees over those 22265provided by a set of unordered stores to the destination. 22266 22267Lowering: 22268""""""""" 22269 22270In the most general case call to the '``llvm.memset.element.unordered.atomic.*``' is 22271lowered to a call to the symbol ``__llvm_memset_element_unordered_atomic_*``. Where '*' 22272is replaced with an actual element size. 22273 22274The optimizer is allowed to inline the memory assignment when it's profitable to do so. 22275 22276Objective-C ARC Runtime Intrinsics 22277---------------------------------- 22278 22279LLVM provides intrinsics that lower to Objective-C ARC runtime entry points. 22280LLVM is aware of the semantics of these functions, and optimizes based on that 22281knowledge. You can read more about the details of Objective-C ARC `here 22282<https://clang.llvm.org/docs/AutomaticReferenceCounting.html>`_. 22283 22284'``llvm.objc.autorelease``' Intrinsic 22285^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22286 22287Syntax: 22288""""""" 22289:: 22290 22291 declare i8* @llvm.objc.autorelease(i8*) 22292 22293Lowering: 22294""""""""" 22295 22296Lowers to a call to `objc_autorelease <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-autorelease>`_. 22297 22298'``llvm.objc.autoreleasePoolPop``' Intrinsic 22299^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22300 22301Syntax: 22302""""""" 22303:: 22304 22305 declare void @llvm.objc.autoreleasePoolPop(i8*) 22306 22307Lowering: 22308""""""""" 22309 22310Lowers to a call to `objc_autoreleasePoolPop <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-autoreleasepoolpop-void-pool>`_. 22311 22312'``llvm.objc.autoreleasePoolPush``' Intrinsic 22313^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22314 22315Syntax: 22316""""""" 22317:: 22318 22319 declare i8* @llvm.objc.autoreleasePoolPush() 22320 22321Lowering: 22322""""""""" 22323 22324Lowers to a call to `objc_autoreleasePoolPush <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-autoreleasepoolpush-void>`_. 22325 22326'``llvm.objc.autoreleaseReturnValue``' Intrinsic 22327^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22328 22329Syntax: 22330""""""" 22331:: 22332 22333 declare i8* @llvm.objc.autoreleaseReturnValue(i8*) 22334 22335Lowering: 22336""""""""" 22337 22338Lowers to a call to `objc_autoreleaseReturnValue <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-autoreleasereturnvalue>`_. 22339 22340'``llvm.objc.copyWeak``' Intrinsic 22341^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22342 22343Syntax: 22344""""""" 22345:: 22346 22347 declare void @llvm.objc.copyWeak(i8**, i8**) 22348 22349Lowering: 22350""""""""" 22351 22352Lowers to a call to `objc_copyWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-copyweak-id-dest-id-src>`_. 22353 22354'``llvm.objc.destroyWeak``' Intrinsic 22355^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22356 22357Syntax: 22358""""""" 22359:: 22360 22361 declare void @llvm.objc.destroyWeak(i8**) 22362 22363Lowering: 22364""""""""" 22365 22366Lowers to a call to `objc_destroyWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-destroyweak-id-object>`_. 22367 22368'``llvm.objc.initWeak``' Intrinsic 22369^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22370 22371Syntax: 22372""""""" 22373:: 22374 22375 declare i8* @llvm.objc.initWeak(i8**, i8*) 22376 22377Lowering: 22378""""""""" 22379 22380Lowers to a call to `objc_initWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-initweak>`_. 22381 22382'``llvm.objc.loadWeak``' Intrinsic 22383^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22384 22385Syntax: 22386""""""" 22387:: 22388 22389 declare i8* @llvm.objc.loadWeak(i8**) 22390 22391Lowering: 22392""""""""" 22393 22394Lowers to a call to `objc_loadWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-loadweak>`_. 22395 22396'``llvm.objc.loadWeakRetained``' Intrinsic 22397^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22398 22399Syntax: 22400""""""" 22401:: 22402 22403 declare i8* @llvm.objc.loadWeakRetained(i8**) 22404 22405Lowering: 22406""""""""" 22407 22408Lowers to a call to `objc_loadWeakRetained <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-loadweakretained>`_. 22409 22410'``llvm.objc.moveWeak``' Intrinsic 22411^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22412 22413Syntax: 22414""""""" 22415:: 22416 22417 declare void @llvm.objc.moveWeak(i8**, i8**) 22418 22419Lowering: 22420""""""""" 22421 22422Lowers to a call to `objc_moveWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-moveweak-id-dest-id-src>`_. 22423 22424'``llvm.objc.release``' Intrinsic 22425^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22426 22427Syntax: 22428""""""" 22429:: 22430 22431 declare void @llvm.objc.release(i8*) 22432 22433Lowering: 22434""""""""" 22435 22436Lowers to a call to `objc_release <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-release-id-value>`_. 22437 22438'``llvm.objc.retain``' Intrinsic 22439^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22440 22441Syntax: 22442""""""" 22443:: 22444 22445 declare i8* @llvm.objc.retain(i8*) 22446 22447Lowering: 22448""""""""" 22449 22450Lowers to a call to `objc_retain <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retain>`_. 22451 22452'``llvm.objc.retainAutorelease``' Intrinsic 22453^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22454 22455Syntax: 22456""""""" 22457:: 22458 22459 declare i8* @llvm.objc.retainAutorelease(i8*) 22460 22461Lowering: 22462""""""""" 22463 22464Lowers to a call to `objc_retainAutorelease <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retainautorelease>`_. 22465 22466'``llvm.objc.retainAutoreleaseReturnValue``' Intrinsic 22467^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22468 22469Syntax: 22470""""""" 22471:: 22472 22473 declare i8* @llvm.objc.retainAutoreleaseReturnValue(i8*) 22474 22475Lowering: 22476""""""""" 22477 22478Lowers to a call to `objc_retainAutoreleaseReturnValue <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retainautoreleasereturnvalue>`_. 22479 22480'``llvm.objc.retainAutoreleasedReturnValue``' Intrinsic 22481^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22482 22483Syntax: 22484""""""" 22485:: 22486 22487 declare i8* @llvm.objc.retainAutoreleasedReturnValue(i8*) 22488 22489Lowering: 22490""""""""" 22491 22492Lowers to a call to `objc_retainAutoreleasedReturnValue <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retainautoreleasedreturnvalue>`_. 22493 22494'``llvm.objc.retainBlock``' Intrinsic 22495^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22496 22497Syntax: 22498""""""" 22499:: 22500 22501 declare i8* @llvm.objc.retainBlock(i8*) 22502 22503Lowering: 22504""""""""" 22505 22506Lowers to a call to `objc_retainBlock <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retainblock>`_. 22507 22508'``llvm.objc.storeStrong``' Intrinsic 22509^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22510 22511Syntax: 22512""""""" 22513:: 22514 22515 declare void @llvm.objc.storeStrong(i8**, i8*) 22516 22517Lowering: 22518""""""""" 22519 22520Lowers to a call to `objc_storeStrong <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#void-objc-storestrong-id-object-id-value>`_. 22521 22522'``llvm.objc.storeWeak``' Intrinsic 22523^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22524 22525Syntax: 22526""""""" 22527:: 22528 22529 declare i8* @llvm.objc.storeWeak(i8**, i8*) 22530 22531Lowering: 22532""""""""" 22533 22534Lowers to a call to `objc_storeWeak <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-storeweak>`_. 22535 22536Preserving Debug Information Intrinsics 22537^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22538 22539These intrinsics are used to carry certain debuginfo together with 22540IR-level operations. For example, it may be desirable to 22541know the structure/union name and the original user-level field 22542indices. Such information got lost in IR GetElementPtr instruction 22543since the IR types are different from debugInfo types and unions 22544are converted to structs in IR. 22545 22546'``llvm.preserve.array.access.index``' Intrinsic 22547^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22548 22549Syntax: 22550""""""" 22551:: 22552 22553 declare <ret_type> 22554 @llvm.preserve.array.access.index.p0s_union.anons.p0a10s_union.anons(<type> base, 22555 i32 dim, 22556 i32 index) 22557 22558Overview: 22559""""""""" 22560 22561The '``llvm.preserve.array.access.index``' intrinsic returns the getelementptr address 22562based on array base ``base``, array dimension ``dim`` and the last access index ``index`` 22563into the array. The return type ``ret_type`` is a pointer type to the array element. 22564The array ``dim`` and ``index`` are preserved which is more robust than 22565getelementptr instruction which may be subject to compiler transformation. 22566The ``llvm.preserve.access.index`` type of metadata is attached to this call instruction 22567to provide array or pointer debuginfo type. 22568The metadata is a ``DICompositeType`` or ``DIDerivedType`` representing the 22569debuginfo version of ``type``. 22570 22571Arguments: 22572"""""""""" 22573 22574The ``base`` is the array base address. The ``dim`` is the array dimension. 22575The ``base`` is a pointer if ``dim`` equals 0. 22576The ``index`` is the last access index into the array or pointer. 22577 22578The ``base`` argument must be annotated with an :ref:`elementtype 22579<attr_elementtype>` attribute at the call-site. This attribute specifies the 22580getelementptr element type. 22581 22582Semantics: 22583"""""""""" 22584 22585The '``llvm.preserve.array.access.index``' intrinsic produces the same result 22586as a getelementptr with base ``base`` and access operands ``{dim's 0's, index}``. 22587 22588'``llvm.preserve.union.access.index``' Intrinsic 22589^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22590 22591Syntax: 22592""""""" 22593:: 22594 22595 declare <type> 22596 @llvm.preserve.union.access.index.p0s_union.anons.p0s_union.anons(<type> base, 22597 i32 di_index) 22598 22599Overview: 22600""""""""" 22601 22602The '``llvm.preserve.union.access.index``' intrinsic carries the debuginfo field index 22603``di_index`` and returns the ``base`` address. 22604The ``llvm.preserve.access.index`` type of metadata is attached to this call instruction 22605to provide union debuginfo type. 22606The metadata is a ``DICompositeType`` representing the debuginfo version of ``type``. 22607The return type ``type`` is the same as the ``base`` type. 22608 22609Arguments: 22610"""""""""" 22611 22612The ``base`` is the union base address. The ``di_index`` is the field index in debuginfo. 22613 22614Semantics: 22615"""""""""" 22616 22617The '``llvm.preserve.union.access.index``' intrinsic returns the ``base`` address. 22618 22619'``llvm.preserve.struct.access.index``' Intrinsic 22620^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22621 22622Syntax: 22623""""""" 22624:: 22625 22626 declare <ret_type> 22627 @llvm.preserve.struct.access.index.p0i8.p0s_struct.anon.0s(<type> base, 22628 i32 gep_index, 22629 i32 di_index) 22630 22631Overview: 22632""""""""" 22633 22634The '``llvm.preserve.struct.access.index``' intrinsic returns the getelementptr address 22635based on struct base ``base`` and IR struct member index ``gep_index``. 22636The ``llvm.preserve.access.index`` type of metadata is attached to this call instruction 22637to provide struct debuginfo type. 22638The metadata is a ``DICompositeType`` representing the debuginfo version of ``type``. 22639The return type ``ret_type`` is a pointer type to the structure member. 22640 22641Arguments: 22642"""""""""" 22643 22644The ``base`` is the structure base address. The ``gep_index`` is the struct member index 22645based on IR structures. The ``di_index`` is the struct member index based on debuginfo. 22646 22647The ``base`` argument must be annotated with an :ref:`elementtype 22648<attr_elementtype>` attribute at the call-site. This attribute specifies the 22649getelementptr element type. 22650 22651Semantics: 22652"""""""""" 22653 22654The '``llvm.preserve.struct.access.index``' intrinsic produces the same result 22655as a getelementptr with base ``base`` and access operands ``{0, gep_index}``. 22656