1*9880d681SAndroid Build Coastguard Worker============================== 2*9880d681SAndroid Build Coastguard WorkerLLVM Language Reference Manual 3*9880d681SAndroid Build Coastguard Worker============================== 4*9880d681SAndroid Build Coastguard Worker 5*9880d681SAndroid Build Coastguard Worker.. contents:: 6*9880d681SAndroid Build Coastguard Worker :local: 7*9880d681SAndroid Build Coastguard Worker :depth: 4 8*9880d681SAndroid Build Coastguard Worker 9*9880d681SAndroid Build Coastguard WorkerAbstract 10*9880d681SAndroid Build Coastguard Worker======== 11*9880d681SAndroid Build Coastguard Worker 12*9880d681SAndroid Build Coastguard WorkerThis document is a reference manual for the LLVM assembly language. LLVM 13*9880d681SAndroid Build Coastguard Workeris a Static Single Assignment (SSA) based representation that provides 14*9880d681SAndroid Build Coastguard Workertype safety, low-level operations, flexibility, and the capability of 15*9880d681SAndroid Build Coastguard Workerrepresenting 'all' high-level languages cleanly. It is the common code 16*9880d681SAndroid Build Coastguard Workerrepresentation used throughout all phases of the LLVM compilation 17*9880d681SAndroid Build Coastguard Workerstrategy. 18*9880d681SAndroid Build Coastguard Worker 19*9880d681SAndroid Build Coastguard WorkerIntroduction 20*9880d681SAndroid Build Coastguard Worker============ 21*9880d681SAndroid Build Coastguard Worker 22*9880d681SAndroid Build Coastguard WorkerThe LLVM code representation is designed to be used in three different 23*9880d681SAndroid Build Coastguard Workerforms: as an in-memory compiler IR, as an on-disk bitcode representation 24*9880d681SAndroid Build Coastguard Worker(suitable for fast loading by a Just-In-Time compiler), and as a human 25*9880d681SAndroid Build Coastguard Workerreadable assembly language representation. This allows LLVM to provide a 26*9880d681SAndroid Build Coastguard Workerpowerful intermediate representation for efficient compiler 27*9880d681SAndroid Build Coastguard Workertransformations and analysis, while providing a natural means to debug 28*9880d681SAndroid Build Coastguard Workerand visualize the transformations. The three different forms of LLVM are 29*9880d681SAndroid Build Coastguard Workerall equivalent. This document describes the human readable 30*9880d681SAndroid Build Coastguard Workerrepresentation and notation. 31*9880d681SAndroid Build Coastguard Worker 32*9880d681SAndroid Build Coastguard WorkerThe LLVM representation aims to be light-weight and low-level while 33*9880d681SAndroid Build Coastguard Workerbeing expressive, typed, and extensible at the same time. It aims to be 34*9880d681SAndroid Build Coastguard Workera "universal IR" of sorts, by being at a low enough level that 35*9880d681SAndroid Build Coastguard Workerhigh-level ideas may be cleanly mapped to it (similar to how 36*9880d681SAndroid Build Coastguard Workermicroprocessors are "universal IR's", allowing many source languages to 37*9880d681SAndroid Build Coastguard Workerbe mapped to them). By providing type information, LLVM can be used as 38*9880d681SAndroid Build Coastguard Workerthe target of optimizations: for example, through pointer analysis, it 39*9880d681SAndroid Build Coastguard Workercan be proven that a C automatic variable is never accessed outside of 40*9880d681SAndroid Build Coastguard Workerthe current function, allowing it to be promoted to a simple SSA value 41*9880d681SAndroid Build Coastguard Workerinstead of a memory location. 42*9880d681SAndroid Build Coastguard Worker 43*9880d681SAndroid Build Coastguard Worker.. _wellformed: 44*9880d681SAndroid Build Coastguard Worker 45*9880d681SAndroid Build Coastguard WorkerWell-Formedness 46*9880d681SAndroid Build Coastguard Worker--------------- 47*9880d681SAndroid Build Coastguard Worker 48*9880d681SAndroid Build Coastguard WorkerIt is important to note that this document describes 'well formed' LLVM 49*9880d681SAndroid Build Coastguard Workerassembly language. There is a difference between what the parser accepts 50*9880d681SAndroid Build Coastguard Workerand what is considered 'well formed'. For example, the following 51*9880d681SAndroid Build Coastguard Workerinstruction is syntactically okay, but not well formed: 52*9880d681SAndroid Build Coastguard Worker 53*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 54*9880d681SAndroid Build Coastguard Worker 55*9880d681SAndroid Build Coastguard Worker %x = add i32 1, %x 56*9880d681SAndroid Build Coastguard Worker 57*9880d681SAndroid Build Coastguard Workerbecause the definition of ``%x`` does not dominate all of its uses. The 58*9880d681SAndroid Build Coastguard WorkerLLVM infrastructure provides a verification pass that may be used to 59*9880d681SAndroid Build Coastguard Workerverify that an LLVM module is well formed. This pass is automatically 60*9880d681SAndroid Build Coastguard Workerrun by the parser after parsing input assembly and by the optimizer 61*9880d681SAndroid Build Coastguard Workerbefore it outputs bitcode. The violations pointed out by the verifier 62*9880d681SAndroid Build Coastguard Workerpass indicate bugs in transformation passes or input to the parser. 63*9880d681SAndroid Build Coastguard Worker 64*9880d681SAndroid Build Coastguard Worker.. _identifiers: 65*9880d681SAndroid Build Coastguard Worker 66*9880d681SAndroid Build Coastguard WorkerIdentifiers 67*9880d681SAndroid Build Coastguard Worker=========== 68*9880d681SAndroid Build Coastguard Worker 69*9880d681SAndroid Build Coastguard WorkerLLVM identifiers come in two basic types: global and local. Global 70*9880d681SAndroid Build Coastguard Workeridentifiers (functions, global variables) begin with the ``'@'`` 71*9880d681SAndroid Build Coastguard Workercharacter. Local identifiers (register names, types) begin with the 72*9880d681SAndroid Build Coastguard Worker``'%'`` character. Additionally, there are three different formats for 73*9880d681SAndroid Build Coastguard Workeridentifiers, for different purposes: 74*9880d681SAndroid Build Coastguard Worker 75*9880d681SAndroid Build Coastguard Worker#. Named values are represented as a string of characters with their 76*9880d681SAndroid Build Coastguard Worker prefix. For example, ``%foo``, ``@DivisionByZero``, 77*9880d681SAndroid Build Coastguard Worker ``%a.really.long.identifier``. The actual regular expression used is 78*9880d681SAndroid Build Coastguard Worker '``[%@][-a-zA-Z$._][-a-zA-Z$._0-9]*``'. Identifiers that require other 79*9880d681SAndroid Build Coastguard Worker characters in their names can be surrounded with quotes. Special 80*9880d681SAndroid Build Coastguard Worker characters may be escaped using ``"\xx"`` where ``xx`` is the ASCII 81*9880d681SAndroid Build Coastguard Worker code for the character in hexadecimal. In this way, any character can 82*9880d681SAndroid Build Coastguard Worker be used in a name value, even quotes themselves. The ``"\01"`` prefix 83*9880d681SAndroid Build Coastguard Worker can be used on global variables to suppress mangling. 84*9880d681SAndroid Build Coastguard Worker#. Unnamed values are represented as an unsigned numeric value with 85*9880d681SAndroid Build Coastguard Worker their prefix. For example, ``%12``, ``@2``, ``%44``. 86*9880d681SAndroid Build Coastguard Worker#. Constants, which are described in the section Constants_ below. 87*9880d681SAndroid Build Coastguard Worker 88*9880d681SAndroid Build Coastguard WorkerLLVM requires that values start with a prefix for two reasons: Compilers 89*9880d681SAndroid Build Coastguard Workerdon't need to worry about name clashes with reserved words, and the set 90*9880d681SAndroid Build Coastguard Workerof reserved words may be expanded in the future without penalty. 91*9880d681SAndroid Build Coastguard WorkerAdditionally, unnamed identifiers allow a compiler to quickly come up 92*9880d681SAndroid Build Coastguard Workerwith a temporary variable without having to avoid symbol table 93*9880d681SAndroid Build Coastguard Workerconflicts. 94*9880d681SAndroid Build Coastguard Worker 95*9880d681SAndroid Build Coastguard WorkerReserved words in LLVM are very similar to reserved words in other 96*9880d681SAndroid Build Coastguard Workerlanguages. There are keywords for different opcodes ('``add``', 97*9880d681SAndroid Build Coastguard Worker'``bitcast``', '``ret``', etc...), for primitive type names ('``void``', 98*9880d681SAndroid Build Coastguard Worker'``i32``', etc...), and others. These reserved words cannot conflict 99*9880d681SAndroid Build Coastguard Workerwith variable names, because none of them start with a prefix character 100*9880d681SAndroid Build Coastguard Worker(``'%'`` or ``'@'``). 101*9880d681SAndroid Build Coastguard Worker 102*9880d681SAndroid Build Coastguard WorkerHere is an example of LLVM code to multiply the integer variable 103*9880d681SAndroid Build Coastguard Worker'``%X``' by 8: 104*9880d681SAndroid Build Coastguard Worker 105*9880d681SAndroid Build Coastguard WorkerThe easy way: 106*9880d681SAndroid Build Coastguard Worker 107*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 108*9880d681SAndroid Build Coastguard Worker 109*9880d681SAndroid Build Coastguard Worker %result = mul i32 %X, 8 110*9880d681SAndroid Build Coastguard Worker 111*9880d681SAndroid Build Coastguard WorkerAfter strength reduction: 112*9880d681SAndroid Build Coastguard Worker 113*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 114*9880d681SAndroid Build Coastguard Worker 115*9880d681SAndroid Build Coastguard Worker %result = shl i32 %X, 3 116*9880d681SAndroid Build Coastguard Worker 117*9880d681SAndroid Build Coastguard WorkerAnd the hard way: 118*9880d681SAndroid Build Coastguard Worker 119*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 120*9880d681SAndroid Build Coastguard Worker 121*9880d681SAndroid Build Coastguard Worker %0 = add i32 %X, %X ; yields i32:%0 122*9880d681SAndroid Build Coastguard Worker %1 = add i32 %0, %0 ; yields i32:%1 123*9880d681SAndroid Build Coastguard Worker %result = add i32 %1, %1 124*9880d681SAndroid Build Coastguard Worker 125*9880d681SAndroid Build Coastguard WorkerThis last way of multiplying ``%X`` by 8 illustrates several important 126*9880d681SAndroid Build Coastguard Workerlexical features of LLVM: 127*9880d681SAndroid Build Coastguard Worker 128*9880d681SAndroid Build Coastguard Worker#. Comments are delimited with a '``;``' and go until the end of line. 129*9880d681SAndroid Build Coastguard Worker#. Unnamed temporaries are created when the result of a computation is 130*9880d681SAndroid Build Coastguard Worker not assigned to a named value. 131*9880d681SAndroid Build Coastguard Worker#. Unnamed temporaries are numbered sequentially (using a per-function 132*9880d681SAndroid Build Coastguard Worker incrementing counter, starting with 0). Note that basic blocks and unnamed 133*9880d681SAndroid Build Coastguard Worker function parameters are included in this numbering. For example, if the 134*9880d681SAndroid Build Coastguard Worker entry basic block is not given a label name and all function parameters are 135*9880d681SAndroid Build Coastguard Worker named, then it will get number 0. 136*9880d681SAndroid Build Coastguard Worker 137*9880d681SAndroid Build Coastguard WorkerIt also shows a convention that we follow in this document. When 138*9880d681SAndroid Build Coastguard Workerdemonstrating instructions, we will follow an instruction with a comment 139*9880d681SAndroid Build Coastguard Workerthat defines the type and name of value produced. 140*9880d681SAndroid Build Coastguard Worker 141*9880d681SAndroid Build Coastguard WorkerHigh Level Structure 142*9880d681SAndroid Build Coastguard Worker==================== 143*9880d681SAndroid Build Coastguard Worker 144*9880d681SAndroid Build Coastguard WorkerModule Structure 145*9880d681SAndroid Build Coastguard Worker---------------- 146*9880d681SAndroid Build Coastguard Worker 147*9880d681SAndroid Build Coastguard WorkerLLVM programs are composed of ``Module``'s, each of which is a 148*9880d681SAndroid Build Coastguard Workertranslation unit of the input programs. Each module consists of 149*9880d681SAndroid Build Coastguard Workerfunctions, global variables, and symbol table entries. Modules may be 150*9880d681SAndroid Build Coastguard Workercombined together with the LLVM linker, which merges function (and 151*9880d681SAndroid Build Coastguard Workerglobal variable) definitions, resolves forward declarations, and merges 152*9880d681SAndroid Build Coastguard Workersymbol table entries. Here is an example of the "hello world" module: 153*9880d681SAndroid Build Coastguard Worker 154*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 155*9880d681SAndroid Build Coastguard Worker 156*9880d681SAndroid Build Coastguard Worker ; Declare the string constant as a global constant. 157*9880d681SAndroid Build Coastguard Worker @.str = private unnamed_addr constant [13 x i8] c"hello world\0A\00" 158*9880d681SAndroid Build Coastguard Worker 159*9880d681SAndroid Build Coastguard Worker ; External declaration of the puts function 160*9880d681SAndroid Build Coastguard Worker declare i32 @puts(i8* nocapture) nounwind 161*9880d681SAndroid Build Coastguard Worker 162*9880d681SAndroid Build Coastguard Worker ; Definition of main function 163*9880d681SAndroid Build Coastguard Worker define i32 @main() { ; i32()* 164*9880d681SAndroid Build Coastguard Worker ; Convert [13 x i8]* to i8 *... 165*9880d681SAndroid Build Coastguard Worker %cast210 = getelementptr [13 x i8], [13 x i8]* @.str, i64 0, i64 0 166*9880d681SAndroid Build Coastguard Worker 167*9880d681SAndroid Build Coastguard Worker ; Call puts function to write out the string to stdout. 168*9880d681SAndroid Build Coastguard Worker call i32 @puts(i8* %cast210) 169*9880d681SAndroid Build Coastguard Worker ret i32 0 170*9880d681SAndroid Build Coastguard Worker } 171*9880d681SAndroid Build Coastguard Worker 172*9880d681SAndroid Build Coastguard Worker ; Named metadata 173*9880d681SAndroid Build Coastguard Worker !0 = !{i32 42, null, !"string"} 174*9880d681SAndroid Build Coastguard Worker !foo = !{!0} 175*9880d681SAndroid Build Coastguard Worker 176*9880d681SAndroid Build Coastguard WorkerThis example is made up of a :ref:`global variable <globalvars>` named 177*9880d681SAndroid Build Coastguard Worker"``.str``", an external declaration of the "``puts``" function, a 178*9880d681SAndroid Build Coastguard Worker:ref:`function definition <functionstructure>` for "``main``" and 179*9880d681SAndroid Build Coastguard Worker:ref:`named metadata <namedmetadatastructure>` "``foo``". 180*9880d681SAndroid Build Coastguard Worker 181*9880d681SAndroid Build Coastguard WorkerIn general, a module is made up of a list of global values (where both 182*9880d681SAndroid Build Coastguard Workerfunctions and global variables are global values). Global values are 183*9880d681SAndroid Build Coastguard Workerrepresented by a pointer to a memory location (in this case, a pointer 184*9880d681SAndroid Build Coastguard Workerto an array of char, and a pointer to a function), and have one of the 185*9880d681SAndroid Build Coastguard Workerfollowing :ref:`linkage types <linkage>`. 186*9880d681SAndroid Build Coastguard Worker 187*9880d681SAndroid Build Coastguard Worker.. _linkage: 188*9880d681SAndroid Build Coastguard Worker 189*9880d681SAndroid Build Coastguard WorkerLinkage Types 190*9880d681SAndroid Build Coastguard Worker------------- 191*9880d681SAndroid Build Coastguard Worker 192*9880d681SAndroid Build Coastguard WorkerAll Global Variables and Functions have one of the following types of 193*9880d681SAndroid Build Coastguard Workerlinkage: 194*9880d681SAndroid Build Coastguard Worker 195*9880d681SAndroid Build Coastguard Worker``private`` 196*9880d681SAndroid Build Coastguard Worker Global values with "``private``" linkage are only directly 197*9880d681SAndroid Build Coastguard Worker accessible by objects in the current module. In particular, linking 198*9880d681SAndroid Build Coastguard Worker code into a module with an private global value may cause the 199*9880d681SAndroid Build Coastguard Worker private to be renamed as necessary to avoid collisions. Because the 200*9880d681SAndroid Build Coastguard Worker symbol is private to the module, all references can be updated. This 201*9880d681SAndroid Build Coastguard Worker doesn't show up in any symbol table in the object file. 202*9880d681SAndroid Build Coastguard Worker``internal`` 203*9880d681SAndroid Build Coastguard Worker Similar to private, but the value shows as a local symbol 204*9880d681SAndroid Build Coastguard Worker (``STB_LOCAL`` in the case of ELF) in the object file. This 205*9880d681SAndroid Build Coastguard Worker corresponds to the notion of the '``static``' keyword in C. 206*9880d681SAndroid Build Coastguard Worker``available_externally`` 207*9880d681SAndroid Build Coastguard Worker Globals with "``available_externally``" linkage are never emitted into 208*9880d681SAndroid Build Coastguard Worker the object file corresponding to the LLVM module. From the linker's 209*9880d681SAndroid Build Coastguard Worker perspective, an ``available_externally`` global is equivalent to 210*9880d681SAndroid Build Coastguard Worker an external declaration. They exist to allow inlining and other 211*9880d681SAndroid Build Coastguard Worker optimizations to take place given knowledge of the definition of the 212*9880d681SAndroid Build Coastguard Worker global, which is known to be somewhere outside the module. Globals 213*9880d681SAndroid Build Coastguard Worker with ``available_externally`` linkage are allowed to be discarded at 214*9880d681SAndroid Build Coastguard Worker will, and allow inlining and other optimizations. This linkage type is 215*9880d681SAndroid Build Coastguard Worker only allowed on definitions, not declarations. 216*9880d681SAndroid Build Coastguard Worker``linkonce`` 217*9880d681SAndroid Build Coastguard Worker Globals with "``linkonce``" linkage are merged with other globals of 218*9880d681SAndroid Build Coastguard Worker the same name when linkage occurs. This can be used to implement 219*9880d681SAndroid Build Coastguard Worker some forms of inline functions, templates, or other code which must 220*9880d681SAndroid Build Coastguard Worker be generated in each translation unit that uses it, but where the 221*9880d681SAndroid Build Coastguard Worker body may be overridden with a more definitive definition later. 222*9880d681SAndroid Build Coastguard Worker Unreferenced ``linkonce`` globals are allowed to be discarded. Note 223*9880d681SAndroid Build Coastguard Worker that ``linkonce`` linkage does not actually allow the optimizer to 224*9880d681SAndroid Build Coastguard Worker inline the body of this function into callers because it doesn't 225*9880d681SAndroid Build Coastguard Worker know if this definition of the function is the definitive definition 226*9880d681SAndroid Build Coastguard Worker within the program or whether it will be overridden by a stronger 227*9880d681SAndroid Build Coastguard Worker definition. To enable inlining and other optimizations, use 228*9880d681SAndroid Build Coastguard Worker "``linkonce_odr``" linkage. 229*9880d681SAndroid Build Coastguard Worker``weak`` 230*9880d681SAndroid Build Coastguard Worker "``weak``" linkage has the same merging semantics as ``linkonce`` 231*9880d681SAndroid Build Coastguard Worker linkage, except that unreferenced globals with ``weak`` linkage may 232*9880d681SAndroid Build Coastguard Worker not be discarded. This is used for globals that are declared "weak" 233*9880d681SAndroid Build Coastguard Worker in C source code. 234*9880d681SAndroid Build Coastguard Worker``common`` 235*9880d681SAndroid Build Coastguard Worker "``common``" linkage is most similar to "``weak``" linkage, but they 236*9880d681SAndroid Build Coastguard Worker are used for tentative definitions in C, such as "``int X;``" at 237*9880d681SAndroid Build Coastguard Worker global scope. Symbols with "``common``" linkage are merged in the 238*9880d681SAndroid Build Coastguard Worker same way as ``weak symbols``, and they may not be deleted if 239*9880d681SAndroid Build Coastguard Worker unreferenced. ``common`` symbols may not have an explicit section, 240*9880d681SAndroid Build Coastguard Worker must have a zero initializer, and may not be marked 241*9880d681SAndroid Build Coastguard Worker ':ref:`constant <globalvars>`'. Functions and aliases may not have 242*9880d681SAndroid Build Coastguard Worker common linkage. 243*9880d681SAndroid Build Coastguard Worker 244*9880d681SAndroid Build Coastguard Worker.. _linkage_appending: 245*9880d681SAndroid Build Coastguard Worker 246*9880d681SAndroid Build Coastguard Worker``appending`` 247*9880d681SAndroid Build Coastguard Worker "``appending``" linkage may only be applied to global variables of 248*9880d681SAndroid Build Coastguard Worker pointer to array type. When two global variables with appending 249*9880d681SAndroid Build Coastguard Worker linkage are linked together, the two global arrays are appended 250*9880d681SAndroid Build Coastguard Worker together. This is the LLVM, typesafe, equivalent of having the 251*9880d681SAndroid Build Coastguard Worker system linker append together "sections" with identical names when 252*9880d681SAndroid Build Coastguard Worker .o files are linked. 253*9880d681SAndroid Build Coastguard Worker 254*9880d681SAndroid Build Coastguard Worker Unfortunately this doesn't correspond to any feature in .o files, so it 255*9880d681SAndroid Build Coastguard Worker can only be used for variables like ``llvm.global_ctors`` which llvm 256*9880d681SAndroid Build Coastguard Worker interprets specially. 257*9880d681SAndroid Build Coastguard Worker 258*9880d681SAndroid Build Coastguard Worker``extern_weak`` 259*9880d681SAndroid Build Coastguard Worker The semantics of this linkage follow the ELF object file model: the 260*9880d681SAndroid Build Coastguard Worker symbol is weak until linked, if not linked, the symbol becomes null 261*9880d681SAndroid Build Coastguard Worker instead of being an undefined reference. 262*9880d681SAndroid Build Coastguard Worker``linkonce_odr``, ``weak_odr`` 263*9880d681SAndroid Build Coastguard Worker Some languages allow differing globals to be merged, such as two 264*9880d681SAndroid Build Coastguard Worker functions with different semantics. Other languages, such as 265*9880d681SAndroid Build Coastguard Worker ``C++``, ensure that only equivalent globals are ever merged (the 266*9880d681SAndroid Build Coastguard Worker "one definition rule" --- "ODR"). Such languages can use the 267*9880d681SAndroid Build Coastguard Worker ``linkonce_odr`` and ``weak_odr`` linkage types to indicate that the 268*9880d681SAndroid Build Coastguard Worker global will only be merged with equivalent globals. These linkage 269*9880d681SAndroid Build Coastguard Worker types are otherwise the same as their non-``odr`` versions. 270*9880d681SAndroid Build Coastguard Worker``external`` 271*9880d681SAndroid Build Coastguard Worker If none of the above identifiers are used, the global is externally 272*9880d681SAndroid Build Coastguard Worker visible, meaning that it participates in linkage and can be used to 273*9880d681SAndroid Build Coastguard Worker resolve external symbol references. 274*9880d681SAndroid Build Coastguard Worker 275*9880d681SAndroid Build Coastguard WorkerIt is illegal for a function *declaration* to have any linkage type 276*9880d681SAndroid Build Coastguard Workerother than ``external`` or ``extern_weak``. 277*9880d681SAndroid Build Coastguard Worker 278*9880d681SAndroid Build Coastguard Worker.. _callingconv: 279*9880d681SAndroid Build Coastguard Worker 280*9880d681SAndroid Build Coastguard WorkerCalling Conventions 281*9880d681SAndroid Build Coastguard Worker------------------- 282*9880d681SAndroid Build Coastguard Worker 283*9880d681SAndroid Build Coastguard WorkerLLVM :ref:`functions <functionstructure>`, :ref:`calls <i_call>` and 284*9880d681SAndroid Build Coastguard Worker:ref:`invokes <i_invoke>` can all have an optional calling convention 285*9880d681SAndroid Build Coastguard Workerspecified for the call. The calling convention of any pair of dynamic 286*9880d681SAndroid Build Coastguard Workercaller/callee must match, or the behavior of the program is undefined. 287*9880d681SAndroid Build Coastguard WorkerThe following calling conventions are supported by LLVM, and more may be 288*9880d681SAndroid Build Coastguard Workeradded in the future: 289*9880d681SAndroid Build Coastguard Worker 290*9880d681SAndroid Build Coastguard Worker"``ccc``" - The C calling convention 291*9880d681SAndroid Build Coastguard Worker This calling convention (the default if no other calling convention 292*9880d681SAndroid Build Coastguard Worker is specified) matches the target C calling conventions. This calling 293*9880d681SAndroid Build Coastguard Worker convention supports varargs function calls and tolerates some 294*9880d681SAndroid Build Coastguard Worker mismatch in the declared prototype and implemented declaration of 295*9880d681SAndroid Build Coastguard Worker the function (as does normal C). 296*9880d681SAndroid Build Coastguard Worker"``fastcc``" - The fast calling convention 297*9880d681SAndroid Build Coastguard Worker This calling convention attempts to make calls as fast as possible 298*9880d681SAndroid Build Coastguard Worker (e.g. by passing things in registers). This calling convention 299*9880d681SAndroid Build Coastguard Worker allows the target to use whatever tricks it wants to produce fast 300*9880d681SAndroid Build Coastguard Worker code for the target, without having to conform to an externally 301*9880d681SAndroid Build Coastguard Worker specified ABI (Application Binary Interface). `Tail calls can only 302*9880d681SAndroid Build Coastguard Worker be optimized when this, the GHC or the HiPE convention is 303*9880d681SAndroid Build Coastguard Worker used. <CodeGenerator.html#id80>`_ This calling convention does not 304*9880d681SAndroid Build Coastguard Worker support varargs and requires the prototype of all callees to exactly 305*9880d681SAndroid Build Coastguard Worker match the prototype of the function definition. 306*9880d681SAndroid Build Coastguard Worker"``coldcc``" - The cold calling convention 307*9880d681SAndroid Build Coastguard Worker This calling convention attempts to make code in the caller as 308*9880d681SAndroid Build Coastguard Worker efficient as possible under the assumption that the call is not 309*9880d681SAndroid Build Coastguard Worker commonly executed. As such, these calls often preserve all registers 310*9880d681SAndroid Build Coastguard Worker so that the call does not break any live ranges in the caller side. 311*9880d681SAndroid Build Coastguard Worker This calling convention does not support varargs and requires the 312*9880d681SAndroid Build Coastguard Worker prototype of all callees to exactly match the prototype of the 313*9880d681SAndroid Build Coastguard Worker function definition. Furthermore the inliner doesn't consider such function 314*9880d681SAndroid Build Coastguard Worker calls for inlining. 315*9880d681SAndroid Build Coastguard Worker"``cc 10``" - GHC convention 316*9880d681SAndroid Build Coastguard Worker This calling convention has been implemented specifically for use by 317*9880d681SAndroid Build Coastguard Worker the `Glasgow Haskell Compiler (GHC) <http://www.haskell.org/ghc>`_. 318*9880d681SAndroid Build Coastguard Worker It passes everything in registers, going to extremes to achieve this 319*9880d681SAndroid Build Coastguard Worker by disabling callee save registers. This calling convention should 320*9880d681SAndroid Build Coastguard Worker not be used lightly but only for specific situations such as an 321*9880d681SAndroid Build Coastguard Worker alternative to the *register pinning* performance technique often 322*9880d681SAndroid Build Coastguard Worker used when implementing functional programming languages. At the 323*9880d681SAndroid Build Coastguard Worker moment only X86 supports this convention and it has the following 324*9880d681SAndroid Build Coastguard Worker limitations: 325*9880d681SAndroid Build Coastguard Worker 326*9880d681SAndroid Build Coastguard Worker - On *X86-32* only supports up to 4 bit type parameters. No 327*9880d681SAndroid Build Coastguard Worker floating point types are supported. 328*9880d681SAndroid Build Coastguard Worker - On *X86-64* only supports up to 10 bit type parameters and 6 329*9880d681SAndroid Build Coastguard Worker floating point parameters. 330*9880d681SAndroid Build Coastguard Worker 331*9880d681SAndroid Build Coastguard Worker This calling convention supports `tail call 332*9880d681SAndroid Build Coastguard Worker optimization <CodeGenerator.html#id80>`_ but requires both the 333*9880d681SAndroid Build Coastguard Worker caller and callee are using it. 334*9880d681SAndroid Build Coastguard Worker"``cc 11``" - The HiPE calling convention 335*9880d681SAndroid Build Coastguard Worker This calling convention has been implemented specifically for use by 336*9880d681SAndroid Build Coastguard Worker the `High-Performance Erlang 337*9880d681SAndroid Build Coastguard Worker (HiPE) <http://www.it.uu.se/research/group/hipe/>`_ compiler, *the* 338*9880d681SAndroid Build Coastguard Worker native code compiler of the `Ericsson's Open Source Erlang/OTP 339*9880d681SAndroid Build Coastguard Worker system <http://www.erlang.org/download.shtml>`_. It uses more 340*9880d681SAndroid Build Coastguard Worker registers for argument passing than the ordinary C calling 341*9880d681SAndroid Build Coastguard Worker convention and defines no callee-saved registers. The calling 342*9880d681SAndroid Build Coastguard Worker convention properly supports `tail call 343*9880d681SAndroid Build Coastguard Worker optimization <CodeGenerator.html#id80>`_ but requires that both the 344*9880d681SAndroid Build Coastguard Worker caller and the callee use it. It uses a *register pinning* 345*9880d681SAndroid Build Coastguard Worker mechanism, similar to GHC's convention, for keeping frequently 346*9880d681SAndroid Build Coastguard Worker accessed runtime components pinned to specific hardware registers. 347*9880d681SAndroid Build Coastguard Worker At the moment only X86 supports this convention (both 32 and 64 348*9880d681SAndroid Build Coastguard Worker bit). 349*9880d681SAndroid Build Coastguard Worker"``webkit_jscc``" - WebKit's JavaScript calling convention 350*9880d681SAndroid Build Coastguard Worker This calling convention has been implemented for `WebKit FTL JIT 351*9880d681SAndroid Build Coastguard Worker <https://trac.webkit.org/wiki/FTLJIT>`_. It passes arguments on the 352*9880d681SAndroid Build Coastguard Worker stack right to left (as cdecl does), and returns a value in the 353*9880d681SAndroid Build Coastguard Worker platform's customary return register. 354*9880d681SAndroid Build Coastguard Worker"``anyregcc``" - Dynamic calling convention for code patching 355*9880d681SAndroid Build Coastguard Worker This is a special convention that supports patching an arbitrary code 356*9880d681SAndroid Build Coastguard Worker sequence in place of a call site. This convention forces the call 357*9880d681SAndroid Build Coastguard Worker arguments into registers but allows them to be dynamically 358*9880d681SAndroid Build Coastguard Worker allocated. This can currently only be used with calls to 359*9880d681SAndroid Build Coastguard Worker llvm.experimental.patchpoint because only this intrinsic records 360*9880d681SAndroid Build Coastguard Worker the location of its arguments in a side table. See :doc:`StackMaps`. 361*9880d681SAndroid Build Coastguard Worker"``preserve_mostcc``" - The `PreserveMost` calling convention 362*9880d681SAndroid Build Coastguard Worker This calling convention attempts to make the code in the caller as 363*9880d681SAndroid Build Coastguard Worker unintrusive as possible. This convention behaves identically to the `C` 364*9880d681SAndroid Build Coastguard Worker calling convention on how arguments and return values are passed, but it 365*9880d681SAndroid Build Coastguard Worker uses a different set of caller/callee-saved registers. This alleviates the 366*9880d681SAndroid Build Coastguard Worker burden of saving and recovering a large register set before and after the 367*9880d681SAndroid Build Coastguard Worker call in the caller. If the arguments are passed in callee-saved registers, 368*9880d681SAndroid Build Coastguard Worker then they will be preserved by the callee across the call. This doesn't 369*9880d681SAndroid Build Coastguard Worker apply for values returned in callee-saved registers. 370*9880d681SAndroid Build Coastguard Worker 371*9880d681SAndroid Build Coastguard Worker - On X86-64 the callee preserves all general purpose registers, except for 372*9880d681SAndroid Build Coastguard Worker R11. R11 can be used as a scratch register. Floating-point registers 373*9880d681SAndroid Build Coastguard Worker (XMMs/YMMs) are not preserved and need to be saved by the caller. 374*9880d681SAndroid Build Coastguard Worker 375*9880d681SAndroid Build Coastguard Worker The idea behind this convention is to support calls to runtime functions 376*9880d681SAndroid Build Coastguard Worker that have a hot path and a cold path. The hot path is usually a small piece 377*9880d681SAndroid Build Coastguard Worker of code that doesn't use many registers. The cold path might need to call out to 378*9880d681SAndroid Build Coastguard Worker another function and therefore only needs to preserve the caller-saved 379*9880d681SAndroid Build Coastguard Worker registers, which haven't already been saved by the caller. The 380*9880d681SAndroid Build Coastguard Worker `PreserveMost` calling convention is very similar to the `cold` calling 381*9880d681SAndroid Build Coastguard Worker convention in terms of caller/callee-saved registers, but they are used for 382*9880d681SAndroid Build Coastguard Worker different types of function calls. `coldcc` is for function calls that are 383*9880d681SAndroid Build Coastguard Worker rarely executed, whereas `preserve_mostcc` function calls are intended to be 384*9880d681SAndroid Build Coastguard Worker on the hot path and definitely executed a lot. Furthermore `preserve_mostcc` 385*9880d681SAndroid Build Coastguard Worker doesn't prevent the inliner from inlining the function call. 386*9880d681SAndroid Build Coastguard Worker 387*9880d681SAndroid Build Coastguard Worker This calling convention will be used by a future version of the ObjectiveC 388*9880d681SAndroid Build Coastguard Worker runtime and should therefore still be considered experimental at this time. 389*9880d681SAndroid Build Coastguard Worker Although this convention was created to optimize certain runtime calls to 390*9880d681SAndroid Build Coastguard Worker the ObjectiveC runtime, it is not limited to this runtime and might be used 391*9880d681SAndroid Build Coastguard Worker by other runtimes in the future too. The current implementation only 392*9880d681SAndroid Build Coastguard Worker supports X86-64, but the intention is to support more architectures in the 393*9880d681SAndroid Build Coastguard Worker future. 394*9880d681SAndroid Build Coastguard Worker"``preserve_allcc``" - The `PreserveAll` calling convention 395*9880d681SAndroid Build Coastguard Worker This calling convention attempts to make the code in the caller even less 396*9880d681SAndroid Build Coastguard Worker intrusive than the `PreserveMost` calling convention. This calling 397*9880d681SAndroid Build Coastguard Worker convention also behaves identical to the `C` calling convention on how 398*9880d681SAndroid Build Coastguard Worker arguments and return values are passed, but it uses a different set of 399*9880d681SAndroid Build Coastguard Worker caller/callee-saved registers. This removes the burden of saving and 400*9880d681SAndroid Build Coastguard Worker recovering a large register set before and after the call in the caller. If 401*9880d681SAndroid Build Coastguard Worker the arguments are passed in callee-saved registers, then they will be 402*9880d681SAndroid Build Coastguard Worker preserved by the callee across the call. This doesn't apply for values 403*9880d681SAndroid Build Coastguard Worker returned in callee-saved registers. 404*9880d681SAndroid Build Coastguard Worker 405*9880d681SAndroid Build Coastguard Worker - On X86-64 the callee preserves all general purpose registers, except for 406*9880d681SAndroid Build Coastguard Worker R11. R11 can be used as a scratch register. Furthermore it also preserves 407*9880d681SAndroid Build Coastguard Worker all floating-point registers (XMMs/YMMs). 408*9880d681SAndroid Build Coastguard Worker 409*9880d681SAndroid Build Coastguard Worker The idea behind this convention is to support calls to runtime functions 410*9880d681SAndroid Build Coastguard Worker that don't need to call out to any other functions. 411*9880d681SAndroid Build Coastguard Worker 412*9880d681SAndroid Build Coastguard Worker This calling convention, like the `PreserveMost` calling convention, will be 413*9880d681SAndroid Build Coastguard Worker used by a future version of the ObjectiveC runtime and should be considered 414*9880d681SAndroid Build Coastguard Worker experimental at this time. 415*9880d681SAndroid Build Coastguard Worker"``cxx_fast_tlscc``" - The `CXX_FAST_TLS` calling convention for access functions 416*9880d681SAndroid Build Coastguard Worker Clang generates an access function to access C++-style TLS. The access 417*9880d681SAndroid Build Coastguard Worker function generally has an entry block, an exit block and an initialization 418*9880d681SAndroid Build Coastguard Worker block that is run at the first time. The entry and exit blocks can access 419*9880d681SAndroid Build Coastguard Worker a few TLS IR variables, each access will be lowered to a platform-specific 420*9880d681SAndroid Build Coastguard Worker sequence. 421*9880d681SAndroid Build Coastguard Worker 422*9880d681SAndroid Build Coastguard Worker This calling convention aims to minimize overhead in the caller by 423*9880d681SAndroid Build Coastguard Worker preserving as many registers as possible (all the registers that are 424*9880d681SAndroid Build Coastguard Worker perserved on the fast path, composed of the entry and exit blocks). 425*9880d681SAndroid Build Coastguard Worker 426*9880d681SAndroid Build Coastguard Worker This calling convention behaves identical to the `C` calling convention on 427*9880d681SAndroid Build Coastguard Worker how arguments and return values are passed, but it uses a different set of 428*9880d681SAndroid Build Coastguard Worker caller/callee-saved registers. 429*9880d681SAndroid Build Coastguard Worker 430*9880d681SAndroid Build Coastguard Worker Given that each platform has its own lowering sequence, hence its own set 431*9880d681SAndroid Build Coastguard Worker of preserved registers, we can't use the existing `PreserveMost`. 432*9880d681SAndroid Build Coastguard Worker 433*9880d681SAndroid Build Coastguard Worker - On X86-64 the callee preserves all general purpose registers, except for 434*9880d681SAndroid Build Coastguard Worker RDI and RAX. 435*9880d681SAndroid Build Coastguard Worker"``swiftcc``" - This calling convention is used for Swift language. 436*9880d681SAndroid Build Coastguard Worker - On X86-64 RCX and R8 are available for additional integer returns, and 437*9880d681SAndroid Build Coastguard Worker XMM2 and XMM3 are available for additional FP/vector returns. 438*9880d681SAndroid Build Coastguard Worker - On iOS platforms, we use AAPCS-VFP calling convention. 439*9880d681SAndroid Build Coastguard Worker"``cc <n>``" - Numbered convention 440*9880d681SAndroid Build Coastguard Worker Any calling convention may be specified by number, allowing 441*9880d681SAndroid Build Coastguard Worker target-specific calling conventions to be used. Target specific 442*9880d681SAndroid Build Coastguard Worker calling conventions start at 64. 443*9880d681SAndroid Build Coastguard Worker 444*9880d681SAndroid Build Coastguard WorkerMore calling conventions can be added/defined on an as-needed basis, to 445*9880d681SAndroid Build Coastguard Workersupport Pascal conventions or any other well-known target-independent 446*9880d681SAndroid Build Coastguard Workerconvention. 447*9880d681SAndroid Build Coastguard Worker 448*9880d681SAndroid Build Coastguard Worker.. _visibilitystyles: 449*9880d681SAndroid Build Coastguard Worker 450*9880d681SAndroid Build Coastguard WorkerVisibility Styles 451*9880d681SAndroid Build Coastguard Worker----------------- 452*9880d681SAndroid Build Coastguard Worker 453*9880d681SAndroid Build Coastguard WorkerAll Global Variables and Functions have one of the following visibility 454*9880d681SAndroid Build Coastguard Workerstyles: 455*9880d681SAndroid Build Coastguard Worker 456*9880d681SAndroid Build Coastguard Worker"``default``" - Default style 457*9880d681SAndroid Build Coastguard Worker On targets that use the ELF object file format, default visibility 458*9880d681SAndroid Build Coastguard Worker means that the declaration is visible to other modules and, in 459*9880d681SAndroid Build Coastguard Worker shared libraries, means that the declared entity may be overridden. 460*9880d681SAndroid Build Coastguard Worker On Darwin, default visibility means that the declaration is visible 461*9880d681SAndroid Build Coastguard Worker to other modules. Default visibility corresponds to "external 462*9880d681SAndroid Build Coastguard Worker linkage" in the language. 463*9880d681SAndroid Build Coastguard Worker"``hidden``" - Hidden style 464*9880d681SAndroid Build Coastguard Worker Two declarations of an object with hidden visibility refer to the 465*9880d681SAndroid Build Coastguard Worker same object if they are in the same shared object. Usually, hidden 466*9880d681SAndroid Build Coastguard Worker visibility indicates that the symbol will not be placed into the 467*9880d681SAndroid Build Coastguard Worker dynamic symbol table, so no other module (executable or shared 468*9880d681SAndroid Build Coastguard Worker library) can reference it directly. 469*9880d681SAndroid Build Coastguard Worker"``protected``" - Protected style 470*9880d681SAndroid Build Coastguard Worker On ELF, protected visibility indicates that the symbol will be 471*9880d681SAndroid Build Coastguard Worker placed in the dynamic symbol table, but that references within the 472*9880d681SAndroid Build Coastguard Worker defining module will bind to the local symbol. That is, the symbol 473*9880d681SAndroid Build Coastguard Worker cannot be overridden by another module. 474*9880d681SAndroid Build Coastguard Worker 475*9880d681SAndroid Build Coastguard WorkerA symbol with ``internal`` or ``private`` linkage must have ``default`` 476*9880d681SAndroid Build Coastguard Workervisibility. 477*9880d681SAndroid Build Coastguard Worker 478*9880d681SAndroid Build Coastguard Worker.. _dllstorageclass: 479*9880d681SAndroid Build Coastguard Worker 480*9880d681SAndroid Build Coastguard WorkerDLL Storage Classes 481*9880d681SAndroid Build Coastguard Worker------------------- 482*9880d681SAndroid Build Coastguard Worker 483*9880d681SAndroid Build Coastguard WorkerAll Global Variables, Functions and Aliases can have one of the following 484*9880d681SAndroid Build Coastguard WorkerDLL storage class: 485*9880d681SAndroid Build Coastguard Worker 486*9880d681SAndroid Build Coastguard Worker``dllimport`` 487*9880d681SAndroid Build Coastguard Worker "``dllimport``" causes the compiler to reference a function or variable via 488*9880d681SAndroid Build Coastguard Worker a global pointer to a pointer that is set up by the DLL exporting the 489*9880d681SAndroid Build Coastguard Worker symbol. On Microsoft Windows targets, the pointer name is formed by 490*9880d681SAndroid Build Coastguard Worker combining ``__imp_`` and the function or variable name. 491*9880d681SAndroid Build Coastguard Worker``dllexport`` 492*9880d681SAndroid Build Coastguard Worker "``dllexport``" causes the compiler to provide a global pointer to a pointer 493*9880d681SAndroid Build Coastguard Worker in a DLL, so that it can be referenced with the ``dllimport`` attribute. On 494*9880d681SAndroid Build Coastguard Worker Microsoft Windows targets, the pointer name is formed by combining 495*9880d681SAndroid Build Coastguard Worker ``__imp_`` and the function or variable name. Since this storage class 496*9880d681SAndroid Build Coastguard Worker exists for defining a dll interface, the compiler, assembler and linker know 497*9880d681SAndroid Build Coastguard Worker it is externally referenced and must refrain from deleting the symbol. 498*9880d681SAndroid Build Coastguard Worker 499*9880d681SAndroid Build Coastguard Worker.. _tls_model: 500*9880d681SAndroid Build Coastguard Worker 501*9880d681SAndroid Build Coastguard WorkerThread Local Storage Models 502*9880d681SAndroid Build Coastguard Worker--------------------------- 503*9880d681SAndroid Build Coastguard Worker 504*9880d681SAndroid Build Coastguard WorkerA variable may be defined as ``thread_local``, which means that it will 505*9880d681SAndroid Build Coastguard Workernot be shared by threads (each thread will have a separated copy of the 506*9880d681SAndroid Build Coastguard Workervariable). Not all targets support thread-local variables. Optionally, a 507*9880d681SAndroid Build Coastguard WorkerTLS model may be specified: 508*9880d681SAndroid Build Coastguard Worker 509*9880d681SAndroid Build Coastguard Worker``localdynamic`` 510*9880d681SAndroid Build Coastguard Worker For variables that are only used within the current shared library. 511*9880d681SAndroid Build Coastguard Worker``initialexec`` 512*9880d681SAndroid Build Coastguard Worker For variables in modules that will not be loaded dynamically. 513*9880d681SAndroid Build Coastguard Worker``localexec`` 514*9880d681SAndroid Build Coastguard Worker For variables defined in the executable and only used within it. 515*9880d681SAndroid Build Coastguard Worker 516*9880d681SAndroid Build Coastguard WorkerIf no explicit model is given, the "general dynamic" model is used. 517*9880d681SAndroid Build Coastguard Worker 518*9880d681SAndroid Build Coastguard WorkerThe models correspond to the ELF TLS models; see `ELF Handling For 519*9880d681SAndroid Build Coastguard WorkerThread-Local Storage <http://people.redhat.com/drepper/tls.pdf>`_ for 520*9880d681SAndroid Build Coastguard Workermore information on under which circumstances the different models may 521*9880d681SAndroid Build Coastguard Workerbe used. The target may choose a different TLS model if the specified 522*9880d681SAndroid Build Coastguard Workermodel is not supported, or if a better choice of model can be made. 523*9880d681SAndroid Build Coastguard Worker 524*9880d681SAndroid Build Coastguard WorkerA model can also be specified in an alias, but then it only governs how 525*9880d681SAndroid Build Coastguard Workerthe alias is accessed. It will not have any effect in the aliasee. 526*9880d681SAndroid Build Coastguard Worker 527*9880d681SAndroid Build Coastguard WorkerFor platforms without linker support of ELF TLS model, the -femulated-tls 528*9880d681SAndroid Build Coastguard Workerflag can be used to generate GCC compatible emulated TLS code. 529*9880d681SAndroid Build Coastguard Worker 530*9880d681SAndroid Build Coastguard Worker.. _namedtypes: 531*9880d681SAndroid Build Coastguard Worker 532*9880d681SAndroid Build Coastguard WorkerStructure Types 533*9880d681SAndroid Build Coastguard Worker--------------- 534*9880d681SAndroid Build Coastguard Worker 535*9880d681SAndroid Build Coastguard WorkerLLVM IR allows you to specify both "identified" and "literal" :ref:`structure 536*9880d681SAndroid Build Coastguard Workertypes <t_struct>`. Literal types are uniqued structurally, but identified types 537*9880d681SAndroid Build Coastguard Workerare never uniqued. An :ref:`opaque structural type <t_opaque>` can also be used 538*9880d681SAndroid Build Coastguard Workerto forward declare a type that is not yet available. 539*9880d681SAndroid Build Coastguard Worker 540*9880d681SAndroid Build Coastguard WorkerAn example of an identified structure specification is: 541*9880d681SAndroid Build Coastguard Worker 542*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 543*9880d681SAndroid Build Coastguard Worker 544*9880d681SAndroid Build Coastguard Worker %mytype = type { %mytype*, i32 } 545*9880d681SAndroid Build Coastguard Worker 546*9880d681SAndroid Build Coastguard WorkerPrior to the LLVM 3.0 release, identified types were structurally uniqued. Only 547*9880d681SAndroid Build Coastguard Workerliteral types are uniqued in recent versions of LLVM. 548*9880d681SAndroid Build Coastguard Worker 549*9880d681SAndroid Build Coastguard Worker.. _globalvars: 550*9880d681SAndroid Build Coastguard Worker 551*9880d681SAndroid Build Coastguard WorkerGlobal Variables 552*9880d681SAndroid Build Coastguard Worker---------------- 553*9880d681SAndroid Build Coastguard Worker 554*9880d681SAndroid Build Coastguard WorkerGlobal variables define regions of memory allocated at compilation time 555*9880d681SAndroid Build Coastguard Workerinstead of run-time. 556*9880d681SAndroid Build Coastguard Worker 557*9880d681SAndroid Build Coastguard WorkerGlobal variable definitions must be initialized. 558*9880d681SAndroid Build Coastguard Worker 559*9880d681SAndroid Build Coastguard WorkerGlobal variables in other translation units can also be declared, in which 560*9880d681SAndroid Build Coastguard Workercase they don't have an initializer. 561*9880d681SAndroid Build Coastguard Worker 562*9880d681SAndroid Build Coastguard WorkerEither global variable definitions or declarations may have an explicit section 563*9880d681SAndroid Build Coastguard Workerto be placed in and may have an optional explicit alignment specified. 564*9880d681SAndroid Build Coastguard Worker 565*9880d681SAndroid Build Coastguard WorkerA variable may be defined as a global ``constant``, which indicates that 566*9880d681SAndroid Build Coastguard Workerthe contents of the variable will **never** be modified (enabling better 567*9880d681SAndroid Build Coastguard Workeroptimization, allowing the global data to be placed in the read-only 568*9880d681SAndroid Build Coastguard Workersection of an executable, etc). Note that variables that need runtime 569*9880d681SAndroid Build Coastguard Workerinitialization cannot be marked ``constant`` as there is a store to the 570*9880d681SAndroid Build Coastguard Workervariable. 571*9880d681SAndroid Build Coastguard Worker 572*9880d681SAndroid Build Coastguard WorkerLLVM explicitly allows *declarations* of global variables to be marked 573*9880d681SAndroid Build Coastguard Workerconstant, even if the final definition of the global is not. This 574*9880d681SAndroid Build Coastguard Workercapability can be used to enable slightly better optimization of the 575*9880d681SAndroid Build Coastguard Workerprogram, but requires the language definition to guarantee that 576*9880d681SAndroid Build Coastguard Workeroptimizations based on the 'constantness' are valid for the translation 577*9880d681SAndroid Build Coastguard Workerunits that do not include the definition. 578*9880d681SAndroid Build Coastguard Worker 579*9880d681SAndroid Build Coastguard WorkerAs SSA values, global variables define pointer values that are in scope 580*9880d681SAndroid Build Coastguard Worker(i.e. they dominate) all basic blocks in the program. Global variables 581*9880d681SAndroid Build Coastguard Workeralways define a pointer to their "content" type because they describe a 582*9880d681SAndroid Build Coastguard Workerregion of memory, and all memory objects in LLVM are accessed through 583*9880d681SAndroid Build Coastguard Workerpointers. 584*9880d681SAndroid Build Coastguard Worker 585*9880d681SAndroid Build Coastguard WorkerGlobal variables can be marked with ``unnamed_addr`` which indicates 586*9880d681SAndroid Build Coastguard Workerthat the address is not significant, only the content. Constants marked 587*9880d681SAndroid Build Coastguard Workerlike this can be merged with other constants if they have the same 588*9880d681SAndroid Build Coastguard Workerinitializer. Note that a constant with significant address *can* be 589*9880d681SAndroid Build Coastguard Workermerged with a ``unnamed_addr`` constant, the result being a constant 590*9880d681SAndroid Build Coastguard Workerwhose address is significant. 591*9880d681SAndroid Build Coastguard Worker 592*9880d681SAndroid Build Coastguard WorkerIf the ``local_unnamed_addr`` attribute is given, the address is known to 593*9880d681SAndroid Build Coastguard Workernot be significant within the module. 594*9880d681SAndroid Build Coastguard Worker 595*9880d681SAndroid Build Coastguard WorkerA global variable may be declared to reside in a target-specific 596*9880d681SAndroid Build Coastguard Workernumbered address space. For targets that support them, address spaces 597*9880d681SAndroid Build Coastguard Workermay affect how optimizations are performed and/or what target 598*9880d681SAndroid Build Coastguard Workerinstructions are used to access the variable. The default address space 599*9880d681SAndroid Build Coastguard Workeris zero. The address space qualifier must precede any other attributes. 600*9880d681SAndroid Build Coastguard Worker 601*9880d681SAndroid Build Coastguard WorkerLLVM allows an explicit section to be specified for globals. If the 602*9880d681SAndroid Build Coastguard Workertarget supports it, it will emit globals to the section specified. 603*9880d681SAndroid Build Coastguard WorkerAdditionally, the global can placed in a comdat if the target has the necessary 604*9880d681SAndroid Build Coastguard Workersupport. 605*9880d681SAndroid Build Coastguard Worker 606*9880d681SAndroid Build Coastguard WorkerBy default, global initializers are optimized by assuming that global 607*9880d681SAndroid Build Coastguard Workervariables defined within the module are not modified from their 608*9880d681SAndroid Build Coastguard Workerinitial values before the start of the global initializer. This is 609*9880d681SAndroid Build Coastguard Workertrue even for variables potentially accessible from outside the 610*9880d681SAndroid Build Coastguard Workermodule, including those with external linkage or appearing in 611*9880d681SAndroid Build Coastguard Worker``@llvm.used`` or dllexported variables. This assumption may be suppressed 612*9880d681SAndroid Build Coastguard Workerby marking the variable with ``externally_initialized``. 613*9880d681SAndroid Build Coastguard Worker 614*9880d681SAndroid Build Coastguard WorkerAn explicit alignment may be specified for a global, which must be a 615*9880d681SAndroid Build Coastguard Workerpower of 2. If not present, or if the alignment is set to zero, the 616*9880d681SAndroid Build Coastguard Workeralignment of the global is set by the target to whatever it feels 617*9880d681SAndroid Build Coastguard Workerconvenient. If an explicit alignment is specified, the global is forced 618*9880d681SAndroid Build Coastguard Workerto have exactly that alignment. Targets and optimizers are not allowed 619*9880d681SAndroid Build Coastguard Workerto over-align the global if the global has an assigned section. In this 620*9880d681SAndroid Build Coastguard Workercase, the extra alignment could be observable: for example, code could 621*9880d681SAndroid Build Coastguard Workerassume that the globals are densely packed in their section and try to 622*9880d681SAndroid Build Coastguard Workeriterate over them as an array, alignment padding would break this 623*9880d681SAndroid Build Coastguard Workeriteration. The maximum alignment is ``1 << 29``. 624*9880d681SAndroid Build Coastguard Worker 625*9880d681SAndroid Build Coastguard WorkerGlobals can also have a :ref:`DLL storage class <dllstorageclass>` and 626*9880d681SAndroid Build Coastguard Workeran optional list of attached :ref:`metadata <metadata>`, 627*9880d681SAndroid Build Coastguard Worker 628*9880d681SAndroid Build Coastguard WorkerVariables and aliases can have a 629*9880d681SAndroid Build Coastguard Worker:ref:`Thread Local Storage Model <tls_model>`. 630*9880d681SAndroid Build Coastguard Worker 631*9880d681SAndroid Build Coastguard WorkerSyntax:: 632*9880d681SAndroid Build Coastguard Worker 633*9880d681SAndroid Build Coastguard Worker @<GlobalVarName> = [Linkage] [Visibility] [DLLStorageClass] [ThreadLocal] 634*9880d681SAndroid Build Coastguard Worker [(unnamed_addr|local_unnamed_addr)] [AddrSpace] 635*9880d681SAndroid Build Coastguard Worker [ExternallyInitialized] 636*9880d681SAndroid Build Coastguard Worker <global | constant> <Type> [<InitializerConstant>] 637*9880d681SAndroid Build Coastguard Worker [, section "name"] [, comdat [($name)]] 638*9880d681SAndroid Build Coastguard Worker [, align <Alignment>] (, !name !N)* 639*9880d681SAndroid Build Coastguard Worker 640*9880d681SAndroid Build Coastguard WorkerFor example, the following defines a global in a numbered address space 641*9880d681SAndroid Build Coastguard Workerwith an initializer, section, and alignment: 642*9880d681SAndroid Build Coastguard Worker 643*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 644*9880d681SAndroid Build Coastguard Worker 645*9880d681SAndroid Build Coastguard Worker @G = addrspace(5) constant float 1.0, section "foo", align 4 646*9880d681SAndroid Build Coastguard Worker 647*9880d681SAndroid Build Coastguard WorkerThe following example just declares a global variable 648*9880d681SAndroid Build Coastguard Worker 649*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 650*9880d681SAndroid Build Coastguard Worker 651*9880d681SAndroid Build Coastguard Worker @G = external global i32 652*9880d681SAndroid Build Coastguard Worker 653*9880d681SAndroid Build Coastguard WorkerThe following example defines a thread-local global with the 654*9880d681SAndroid Build Coastguard Worker``initialexec`` TLS model: 655*9880d681SAndroid Build Coastguard Worker 656*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 657*9880d681SAndroid Build Coastguard Worker 658*9880d681SAndroid Build Coastguard Worker @G = thread_local(initialexec) global i32 0, align 4 659*9880d681SAndroid Build Coastguard Worker 660*9880d681SAndroid Build Coastguard Worker.. _functionstructure: 661*9880d681SAndroid Build Coastguard Worker 662*9880d681SAndroid Build Coastguard WorkerFunctions 663*9880d681SAndroid Build Coastguard Worker--------- 664*9880d681SAndroid Build Coastguard Worker 665*9880d681SAndroid Build Coastguard WorkerLLVM function definitions consist of the "``define``" keyword, an 666*9880d681SAndroid Build Coastguard Workeroptional :ref:`linkage type <linkage>`, an optional :ref:`visibility 667*9880d681SAndroid Build Coastguard Workerstyle <visibility>`, an optional :ref:`DLL storage class <dllstorageclass>`, 668*9880d681SAndroid Build Coastguard Workeran optional :ref:`calling convention <callingconv>`, 669*9880d681SAndroid Build Coastguard Workeran optional ``unnamed_addr`` attribute, a return type, an optional 670*9880d681SAndroid Build Coastguard Worker:ref:`parameter attribute <paramattrs>` for the return type, a function 671*9880d681SAndroid Build Coastguard Workername, a (possibly empty) argument list (each with optional :ref:`parameter 672*9880d681SAndroid Build Coastguard Workerattributes <paramattrs>`), optional :ref:`function attributes <fnattrs>`, 673*9880d681SAndroid Build Coastguard Workeran optional section, an optional alignment, 674*9880d681SAndroid Build Coastguard Workeran optional :ref:`comdat <langref_comdats>`, 675*9880d681SAndroid Build Coastguard Workeran optional :ref:`garbage collector name <gc>`, an optional :ref:`prefix <prefixdata>`, 676*9880d681SAndroid Build Coastguard Workeran optional :ref:`prologue <prologuedata>`, 677*9880d681SAndroid Build Coastguard Workeran optional :ref:`personality <personalityfn>`, 678*9880d681SAndroid Build Coastguard Workeran optional list of attached :ref:`metadata <metadata>`, 679*9880d681SAndroid Build Coastguard Workeran opening curly brace, a list of basic blocks, and a closing curly brace. 680*9880d681SAndroid Build Coastguard Worker 681*9880d681SAndroid Build Coastguard WorkerLLVM function declarations consist of the "``declare``" keyword, an 682*9880d681SAndroid Build Coastguard Workeroptional :ref:`linkage type <linkage>`, an optional :ref:`visibility style 683*9880d681SAndroid Build Coastguard Worker<visibility>`, an optional :ref:`DLL storage class <dllstorageclass>`, an 684*9880d681SAndroid Build Coastguard Workeroptional :ref:`calling convention <callingconv>`, an optional ``unnamed_addr`` 685*9880d681SAndroid Build Coastguard Workeror ``local_unnamed_addr`` attribute, a return type, an optional :ref:`parameter 686*9880d681SAndroid Build Coastguard Workerattribute <paramattrs>` for the return type, a function name, a possibly 687*9880d681SAndroid Build Coastguard Workerempty list of arguments, an optional alignment, an optional :ref:`garbage 688*9880d681SAndroid Build Coastguard Workercollector name <gc>`, an optional :ref:`prefix <prefixdata>`, and an optional 689*9880d681SAndroid Build Coastguard Worker:ref:`prologue <prologuedata>`. 690*9880d681SAndroid Build Coastguard Worker 691*9880d681SAndroid Build Coastguard WorkerA function definition contains a list of basic blocks, forming the CFG (Control 692*9880d681SAndroid Build Coastguard WorkerFlow Graph) for the function. Each basic block may optionally start with a label 693*9880d681SAndroid Build Coastguard Worker(giving the basic block a symbol table entry), contains a list of instructions, 694*9880d681SAndroid Build Coastguard Workerand ends with a :ref:`terminator <terminators>` instruction (such as a branch or 695*9880d681SAndroid Build Coastguard Workerfunction return). If an explicit label is not provided, a block is assigned an 696*9880d681SAndroid Build Coastguard Workerimplicit numbered label, using the next value from the same counter as used for 697*9880d681SAndroid Build Coastguard Workerunnamed temporaries (:ref:`see above<identifiers>`). For example, if a function 698*9880d681SAndroid Build Coastguard Workerentry block does not have an explicit label, it will be assigned label "%0", 699*9880d681SAndroid Build Coastguard Workerthen the first unnamed temporary in that block will be "%1", etc. 700*9880d681SAndroid Build Coastguard Worker 701*9880d681SAndroid Build Coastguard WorkerThe first basic block in a function is special in two ways: it is 702*9880d681SAndroid Build Coastguard Workerimmediately executed on entrance to the function, and it is not allowed 703*9880d681SAndroid Build Coastguard Workerto have predecessor basic blocks (i.e. there can not be any branches to 704*9880d681SAndroid Build Coastguard Workerthe entry block of a function). Because the block can have no 705*9880d681SAndroid Build Coastguard Workerpredecessors, it also cannot have any :ref:`PHI nodes <i_phi>`. 706*9880d681SAndroid Build Coastguard Worker 707*9880d681SAndroid Build Coastguard WorkerLLVM allows an explicit section to be specified for functions. If the 708*9880d681SAndroid Build Coastguard Workertarget supports it, it will emit functions to the section specified. 709*9880d681SAndroid Build Coastguard WorkerAdditionally, the function can be placed in a COMDAT. 710*9880d681SAndroid Build Coastguard Worker 711*9880d681SAndroid Build Coastguard WorkerAn explicit alignment may be specified for a function. If not present, 712*9880d681SAndroid Build Coastguard Workeror if the alignment is set to zero, the alignment of the function is set 713*9880d681SAndroid Build Coastguard Workerby the target to whatever it feels convenient. If an explicit alignment 714*9880d681SAndroid Build Coastguard Workeris specified, the function is forced to have at least that much 715*9880d681SAndroid Build Coastguard Workeralignment. All alignments must be a power of 2. 716*9880d681SAndroid Build Coastguard Worker 717*9880d681SAndroid Build Coastguard WorkerIf the ``unnamed_addr`` attribute is given, the address is known to not 718*9880d681SAndroid Build Coastguard Workerbe significant and two identical functions can be merged. 719*9880d681SAndroid Build Coastguard Worker 720*9880d681SAndroid Build Coastguard WorkerIf the ``local_unnamed_addr`` attribute is given, the address is known to 721*9880d681SAndroid Build Coastguard Workernot be significant within the module. 722*9880d681SAndroid Build Coastguard Worker 723*9880d681SAndroid Build Coastguard WorkerSyntax:: 724*9880d681SAndroid Build Coastguard Worker 725*9880d681SAndroid Build Coastguard Worker define [linkage] [visibility] [DLLStorageClass] 726*9880d681SAndroid Build Coastguard Worker [cconv] [ret attrs] 727*9880d681SAndroid Build Coastguard Worker <ResultType> @<FunctionName> ([argument list]) 728*9880d681SAndroid Build Coastguard Worker [(unnamed_addr|local_unnamed_addr)] [fn Attrs] [section "name"] 729*9880d681SAndroid Build Coastguard Worker [comdat [($name)]] [align N] [gc] [prefix Constant] 730*9880d681SAndroid Build Coastguard Worker [prologue Constant] [personality Constant] (!name !N)* { ... } 731*9880d681SAndroid Build Coastguard Worker 732*9880d681SAndroid Build Coastguard WorkerThe argument list is a comma separated sequence of arguments where each 733*9880d681SAndroid Build Coastguard Workerargument is of the following form: 734*9880d681SAndroid Build Coastguard Worker 735*9880d681SAndroid Build Coastguard WorkerSyntax:: 736*9880d681SAndroid Build Coastguard Worker 737*9880d681SAndroid Build Coastguard Worker <type> [parameter Attrs] [name] 738*9880d681SAndroid Build Coastguard Worker 739*9880d681SAndroid Build Coastguard Worker 740*9880d681SAndroid Build Coastguard Worker.. _langref_aliases: 741*9880d681SAndroid Build Coastguard Worker 742*9880d681SAndroid Build Coastguard WorkerAliases 743*9880d681SAndroid Build Coastguard Worker------- 744*9880d681SAndroid Build Coastguard Worker 745*9880d681SAndroid Build Coastguard WorkerAliases, unlike function or variables, don't create any new data. They 746*9880d681SAndroid Build Coastguard Workerare just a new symbol and metadata for an existing position. 747*9880d681SAndroid Build Coastguard Worker 748*9880d681SAndroid Build Coastguard WorkerAliases have a name and an aliasee that is either a global value or a 749*9880d681SAndroid Build Coastguard Workerconstant expression. 750*9880d681SAndroid Build Coastguard Worker 751*9880d681SAndroid Build Coastguard WorkerAliases may have an optional :ref:`linkage type <linkage>`, an optional 752*9880d681SAndroid Build Coastguard Worker:ref:`visibility style <visibility>`, an optional :ref:`DLL storage class 753*9880d681SAndroid Build Coastguard Worker<dllstorageclass>` and an optional :ref:`tls model <tls_model>`. 754*9880d681SAndroid Build Coastguard Worker 755*9880d681SAndroid Build Coastguard WorkerSyntax:: 756*9880d681SAndroid Build Coastguard Worker 757*9880d681SAndroid Build Coastguard Worker @<Name> = [Linkage] [Visibility] [DLLStorageClass] [ThreadLocal] [(unnamed_addr|local_unnamed_addr)] alias <AliaseeTy>, <AliaseeTy>* @<Aliasee> 758*9880d681SAndroid Build Coastguard Worker 759*9880d681SAndroid Build Coastguard WorkerThe linkage must be one of ``private``, ``internal``, ``linkonce``, ``weak``, 760*9880d681SAndroid Build Coastguard Worker``linkonce_odr``, ``weak_odr``, ``external``. Note that some system linkers 761*9880d681SAndroid Build Coastguard Workermight not correctly handle dropping a weak symbol that is aliased. 762*9880d681SAndroid Build Coastguard Worker 763*9880d681SAndroid Build Coastguard WorkerAliases that are not ``unnamed_addr`` are guaranteed to have the same address as 764*9880d681SAndroid Build Coastguard Workerthe aliasee expression. ``unnamed_addr`` ones are only guaranteed to point 765*9880d681SAndroid Build Coastguard Workerto the same content. 766*9880d681SAndroid Build Coastguard Worker 767*9880d681SAndroid Build Coastguard WorkerIf the ``local_unnamed_addr`` attribute is given, the address is known to 768*9880d681SAndroid Build Coastguard Workernot be significant within the module. 769*9880d681SAndroid Build Coastguard Worker 770*9880d681SAndroid Build Coastguard WorkerSince aliases are only a second name, some restrictions apply, of which 771*9880d681SAndroid Build Coastguard Workersome can only be checked when producing an object file: 772*9880d681SAndroid Build Coastguard Worker 773*9880d681SAndroid Build Coastguard Worker* The expression defining the aliasee must be computable at assembly 774*9880d681SAndroid Build Coastguard Worker time. Since it is just a name, no relocations can be used. 775*9880d681SAndroid Build Coastguard Worker 776*9880d681SAndroid Build Coastguard Worker* No alias in the expression can be weak as the possibility of the 777*9880d681SAndroid Build Coastguard Worker intermediate alias being overridden cannot be represented in an 778*9880d681SAndroid Build Coastguard Worker object file. 779*9880d681SAndroid Build Coastguard Worker 780*9880d681SAndroid Build Coastguard Worker* No global value in the expression can be a declaration, since that 781*9880d681SAndroid Build Coastguard Worker would require a relocation, which is not possible. 782*9880d681SAndroid Build Coastguard Worker 783*9880d681SAndroid Build Coastguard Worker.. _langref_ifunc: 784*9880d681SAndroid Build Coastguard Worker 785*9880d681SAndroid Build Coastguard WorkerIFuncs 786*9880d681SAndroid Build Coastguard Worker------- 787*9880d681SAndroid Build Coastguard Worker 788*9880d681SAndroid Build Coastguard WorkerIFuncs, like as aliases, don't create any new data or func. They are just a new 789*9880d681SAndroid Build Coastguard Workersymbol that dynamic linker resolves at runtime by calling a resolver function. 790*9880d681SAndroid Build Coastguard Worker 791*9880d681SAndroid Build Coastguard WorkerIFuncs have a name and a resolver that is a function called by dynamic linker 792*9880d681SAndroid Build Coastguard Workerthat returns address of another function associated with the name. 793*9880d681SAndroid Build Coastguard Worker 794*9880d681SAndroid Build Coastguard WorkerIFunc may have an optional :ref:`linkage type <linkage>` and an optional 795*9880d681SAndroid Build Coastguard Worker:ref:`visibility style <visibility>`. 796*9880d681SAndroid Build Coastguard Worker 797*9880d681SAndroid Build Coastguard WorkerSyntax:: 798*9880d681SAndroid Build Coastguard Worker 799*9880d681SAndroid Build Coastguard Worker @<Name> = [Linkage] [Visibility] ifunc <IFuncTy>, <ResolverTy>* @<Resolver> 800*9880d681SAndroid Build Coastguard Worker 801*9880d681SAndroid Build Coastguard Worker 802*9880d681SAndroid Build Coastguard Worker.. _langref_comdats: 803*9880d681SAndroid Build Coastguard Worker 804*9880d681SAndroid Build Coastguard WorkerComdats 805*9880d681SAndroid Build Coastguard Worker------- 806*9880d681SAndroid Build Coastguard Worker 807*9880d681SAndroid Build Coastguard WorkerComdat IR provides access to COFF and ELF object file COMDAT functionality. 808*9880d681SAndroid Build Coastguard Worker 809*9880d681SAndroid Build Coastguard WorkerComdats have a name which represents the COMDAT key. All global objects that 810*9880d681SAndroid Build Coastguard Workerspecify this key will only end up in the final object file if the linker chooses 811*9880d681SAndroid Build Coastguard Workerthat key over some other key. Aliases are placed in the same COMDAT that their 812*9880d681SAndroid Build Coastguard Workeraliasee computes to, if any. 813*9880d681SAndroid Build Coastguard Worker 814*9880d681SAndroid Build Coastguard WorkerComdats have a selection kind to provide input on how the linker should 815*9880d681SAndroid Build Coastguard Workerchoose between keys in two different object files. 816*9880d681SAndroid Build Coastguard Worker 817*9880d681SAndroid Build Coastguard WorkerSyntax:: 818*9880d681SAndroid Build Coastguard Worker 819*9880d681SAndroid Build Coastguard Worker $<Name> = comdat SelectionKind 820*9880d681SAndroid Build Coastguard Worker 821*9880d681SAndroid Build Coastguard WorkerThe selection kind must be one of the following: 822*9880d681SAndroid Build Coastguard Worker 823*9880d681SAndroid Build Coastguard Worker``any`` 824*9880d681SAndroid Build Coastguard Worker The linker may choose any COMDAT key, the choice is arbitrary. 825*9880d681SAndroid Build Coastguard Worker``exactmatch`` 826*9880d681SAndroid Build Coastguard Worker The linker may choose any COMDAT key but the sections must contain the 827*9880d681SAndroid Build Coastguard Worker same data. 828*9880d681SAndroid Build Coastguard Worker``largest`` 829*9880d681SAndroid Build Coastguard Worker The linker will choose the section containing the largest COMDAT key. 830*9880d681SAndroid Build Coastguard Worker``noduplicates`` 831*9880d681SAndroid Build Coastguard Worker The linker requires that only section with this COMDAT key exist. 832*9880d681SAndroid Build Coastguard Worker``samesize`` 833*9880d681SAndroid Build Coastguard Worker The linker may choose any COMDAT key but the sections must contain the 834*9880d681SAndroid Build Coastguard Worker same amount of data. 835*9880d681SAndroid Build Coastguard Worker 836*9880d681SAndroid Build Coastguard WorkerNote that the Mach-O platform doesn't support COMDATs and ELF only supports 837*9880d681SAndroid Build Coastguard Worker``any`` as a selection kind. 838*9880d681SAndroid Build Coastguard Worker 839*9880d681SAndroid Build Coastguard WorkerHere is an example of a COMDAT group where a function will only be selected if 840*9880d681SAndroid Build Coastguard Workerthe COMDAT key's section is the largest: 841*9880d681SAndroid Build Coastguard Worker 842*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 843*9880d681SAndroid Build Coastguard Worker 844*9880d681SAndroid Build Coastguard Worker $foo = comdat largest 845*9880d681SAndroid Build Coastguard Worker @foo = global i32 2, comdat($foo) 846*9880d681SAndroid Build Coastguard Worker 847*9880d681SAndroid Build Coastguard Worker define void @bar() comdat($foo) { 848*9880d681SAndroid Build Coastguard Worker ret void 849*9880d681SAndroid Build Coastguard Worker } 850*9880d681SAndroid Build Coastguard Worker 851*9880d681SAndroid Build Coastguard WorkerAs a syntactic sugar the ``$name`` can be omitted if the name is the same as 852*9880d681SAndroid Build Coastguard Workerthe global name: 853*9880d681SAndroid Build Coastguard Worker 854*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 855*9880d681SAndroid Build Coastguard Worker 856*9880d681SAndroid Build Coastguard Worker $foo = comdat any 857*9880d681SAndroid Build Coastguard Worker @foo = global i32 2, comdat 858*9880d681SAndroid Build Coastguard Worker 859*9880d681SAndroid Build Coastguard Worker 860*9880d681SAndroid Build Coastguard WorkerIn a COFF object file, this will create a COMDAT section with selection kind 861*9880d681SAndroid Build Coastguard Worker``IMAGE_COMDAT_SELECT_LARGEST`` containing the contents of the ``@foo`` symbol 862*9880d681SAndroid Build Coastguard Workerand another COMDAT section with selection kind 863*9880d681SAndroid Build Coastguard Worker``IMAGE_COMDAT_SELECT_ASSOCIATIVE`` which is associated with the first COMDAT 864*9880d681SAndroid Build Coastguard Workersection and contains the contents of the ``@bar`` symbol. 865*9880d681SAndroid Build Coastguard Worker 866*9880d681SAndroid Build Coastguard WorkerThere are some restrictions on the properties of the global object. 867*9880d681SAndroid Build Coastguard WorkerIt, or an alias to it, must have the same name as the COMDAT group when 868*9880d681SAndroid Build Coastguard Workertargeting COFF. 869*9880d681SAndroid Build Coastguard WorkerThe contents and size of this object may be used during link-time to determine 870*9880d681SAndroid Build Coastguard Workerwhich COMDAT groups get selected depending on the selection kind. 871*9880d681SAndroid Build Coastguard WorkerBecause the name of the object must match the name of the COMDAT group, the 872*9880d681SAndroid Build Coastguard Workerlinkage of the global object must not be local; local symbols can get renamed 873*9880d681SAndroid Build Coastguard Workerif a collision occurs in the symbol table. 874*9880d681SAndroid Build Coastguard Worker 875*9880d681SAndroid Build Coastguard WorkerThe combined use of COMDATS and section attributes may yield surprising results. 876*9880d681SAndroid Build Coastguard WorkerFor example: 877*9880d681SAndroid Build Coastguard Worker 878*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 879*9880d681SAndroid Build Coastguard Worker 880*9880d681SAndroid Build Coastguard Worker $foo = comdat any 881*9880d681SAndroid Build Coastguard Worker $bar = comdat any 882*9880d681SAndroid Build Coastguard Worker @g1 = global i32 42, section "sec", comdat($foo) 883*9880d681SAndroid Build Coastguard Worker @g2 = global i32 42, section "sec", comdat($bar) 884*9880d681SAndroid Build Coastguard Worker 885*9880d681SAndroid Build Coastguard WorkerFrom the object file perspective, this requires the creation of two sections 886*9880d681SAndroid Build Coastguard Workerwith the same name. This is necessary because both globals belong to different 887*9880d681SAndroid Build Coastguard WorkerCOMDAT groups and COMDATs, at the object file level, are represented by 888*9880d681SAndroid Build Coastguard Workersections. 889*9880d681SAndroid Build Coastguard Worker 890*9880d681SAndroid Build Coastguard WorkerNote that certain IR constructs like global variables and functions may 891*9880d681SAndroid Build Coastguard Workercreate COMDATs in the object file in addition to any which are specified using 892*9880d681SAndroid Build Coastguard WorkerCOMDAT IR. This arises when the code generator is configured to emit globals 893*9880d681SAndroid Build Coastguard Workerin individual sections (e.g. when `-data-sections` or `-function-sections` 894*9880d681SAndroid Build Coastguard Workeris supplied to `llc`). 895*9880d681SAndroid Build Coastguard Worker 896*9880d681SAndroid Build Coastguard Worker.. _namedmetadatastructure: 897*9880d681SAndroid Build Coastguard Worker 898*9880d681SAndroid Build Coastguard WorkerNamed Metadata 899*9880d681SAndroid Build Coastguard Worker-------------- 900*9880d681SAndroid Build Coastguard Worker 901*9880d681SAndroid Build Coastguard WorkerNamed metadata is a collection of metadata. :ref:`Metadata 902*9880d681SAndroid Build Coastguard Workernodes <metadata>` (but not metadata strings) are the only valid 903*9880d681SAndroid Build Coastguard Workeroperands for a named metadata. 904*9880d681SAndroid Build Coastguard Worker 905*9880d681SAndroid Build Coastguard Worker#. Named metadata are represented as a string of characters with the 906*9880d681SAndroid Build Coastguard Worker metadata prefix. The rules for metadata names are the same as for 907*9880d681SAndroid Build Coastguard Worker identifiers, but quoted names are not allowed. ``"\xx"`` type escapes 908*9880d681SAndroid Build Coastguard Worker are still valid, which allows any character to be part of a name. 909*9880d681SAndroid Build Coastguard Worker 910*9880d681SAndroid Build Coastguard WorkerSyntax:: 911*9880d681SAndroid Build Coastguard Worker 912*9880d681SAndroid Build Coastguard Worker ; Some unnamed metadata nodes, which are referenced by the named metadata. 913*9880d681SAndroid Build Coastguard Worker !0 = !{!"zero"} 914*9880d681SAndroid Build Coastguard Worker !1 = !{!"one"} 915*9880d681SAndroid Build Coastguard Worker !2 = !{!"two"} 916*9880d681SAndroid Build Coastguard Worker ; A named metadata. 917*9880d681SAndroid Build Coastguard Worker !name = !{!0, !1, !2} 918*9880d681SAndroid Build Coastguard Worker 919*9880d681SAndroid Build Coastguard Worker.. _paramattrs: 920*9880d681SAndroid Build Coastguard Worker 921*9880d681SAndroid Build Coastguard WorkerParameter Attributes 922*9880d681SAndroid Build Coastguard Worker-------------------- 923*9880d681SAndroid Build Coastguard Worker 924*9880d681SAndroid Build Coastguard WorkerThe return type and each parameter of a function type may have a set of 925*9880d681SAndroid Build Coastguard Worker*parameter attributes* associated with them. Parameter attributes are 926*9880d681SAndroid Build Coastguard Workerused to communicate additional information about the result or 927*9880d681SAndroid Build Coastguard Workerparameters of a function. Parameter attributes are considered to be part 928*9880d681SAndroid Build Coastguard Workerof the function, not of the function type, so functions with different 929*9880d681SAndroid Build Coastguard Workerparameter attributes can have the same function type. 930*9880d681SAndroid Build Coastguard Worker 931*9880d681SAndroid Build Coastguard WorkerParameter attributes are simple keywords that follow the type specified. 932*9880d681SAndroid Build Coastguard WorkerIf multiple parameter attributes are needed, they are space separated. 933*9880d681SAndroid Build Coastguard WorkerFor example: 934*9880d681SAndroid Build Coastguard Worker 935*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 936*9880d681SAndroid Build Coastguard Worker 937*9880d681SAndroid Build Coastguard Worker declare i32 @printf(i8* noalias nocapture, ...) 938*9880d681SAndroid Build Coastguard Worker declare i32 @atoi(i8 zeroext) 939*9880d681SAndroid Build Coastguard Worker declare signext i8 @returns_signed_char() 940*9880d681SAndroid Build Coastguard Worker 941*9880d681SAndroid Build Coastguard WorkerNote that any attributes for the function result (``nounwind``, 942*9880d681SAndroid Build Coastguard Worker``readonly``) come immediately after the argument list. 943*9880d681SAndroid Build Coastguard Worker 944*9880d681SAndroid Build Coastguard WorkerCurrently, only the following parameter attributes are defined: 945*9880d681SAndroid Build Coastguard Worker 946*9880d681SAndroid Build Coastguard Worker``zeroext`` 947*9880d681SAndroid Build Coastguard Worker This indicates to the code generator that the parameter or return 948*9880d681SAndroid Build Coastguard Worker value should be zero-extended to the extent required by the target's 949*9880d681SAndroid Build Coastguard Worker ABI by the caller (for a parameter) or the callee (for a return value). 950*9880d681SAndroid Build Coastguard Worker``signext`` 951*9880d681SAndroid Build Coastguard Worker This indicates to the code generator that the parameter or return 952*9880d681SAndroid Build Coastguard Worker value should be sign-extended to the extent required by the target's 953*9880d681SAndroid Build Coastguard Worker ABI (which is usually 32-bits) by the caller (for a parameter) or 954*9880d681SAndroid Build Coastguard Worker the callee (for a return value). 955*9880d681SAndroid Build Coastguard Worker``inreg`` 956*9880d681SAndroid Build Coastguard Worker This indicates that this parameter or return value should be treated 957*9880d681SAndroid Build Coastguard Worker in a special target-dependent fashion while emitting code for 958*9880d681SAndroid Build Coastguard Worker a function call or return (usually, by putting it in a register as 959*9880d681SAndroid Build Coastguard Worker opposed to memory, though some targets use it to distinguish between 960*9880d681SAndroid Build Coastguard Worker two different kinds of registers). Use of this attribute is 961*9880d681SAndroid Build Coastguard Worker target-specific. 962*9880d681SAndroid Build Coastguard Worker``byval`` 963*9880d681SAndroid Build Coastguard Worker This indicates that the pointer parameter should really be passed by 964*9880d681SAndroid Build Coastguard Worker value to the function. The attribute implies that a hidden copy of 965*9880d681SAndroid Build Coastguard Worker the pointee is made between the caller and the callee, so the callee 966*9880d681SAndroid Build Coastguard Worker is unable to modify the value in the caller. This attribute is only 967*9880d681SAndroid Build Coastguard Worker valid on LLVM pointer arguments. It is generally used to pass 968*9880d681SAndroid Build Coastguard Worker structs and arrays by value, but is also valid on pointers to 969*9880d681SAndroid Build Coastguard Worker scalars. The copy is considered to belong to the caller not the 970*9880d681SAndroid Build Coastguard Worker callee (for example, ``readonly`` functions should not write to 971*9880d681SAndroid Build Coastguard Worker ``byval`` parameters). This is not a valid attribute for return 972*9880d681SAndroid Build Coastguard Worker values. 973*9880d681SAndroid Build Coastguard Worker 974*9880d681SAndroid Build Coastguard Worker The byval attribute also supports specifying an alignment with the 975*9880d681SAndroid Build Coastguard Worker align attribute. It indicates the alignment of the stack slot to 976*9880d681SAndroid Build Coastguard Worker form and the known alignment of the pointer specified to the call 977*9880d681SAndroid Build Coastguard Worker site. If the alignment is not specified, then the code generator 978*9880d681SAndroid Build Coastguard Worker makes a target-specific assumption. 979*9880d681SAndroid Build Coastguard Worker 980*9880d681SAndroid Build Coastguard Worker.. _attr_inalloca: 981*9880d681SAndroid Build Coastguard Worker 982*9880d681SAndroid Build Coastguard Worker``inalloca`` 983*9880d681SAndroid Build Coastguard Worker 984*9880d681SAndroid Build Coastguard Worker The ``inalloca`` argument attribute allows the caller to take the 985*9880d681SAndroid Build Coastguard Worker address of outgoing stack arguments. An ``inalloca`` argument must 986*9880d681SAndroid Build Coastguard Worker be a pointer to stack memory produced by an ``alloca`` instruction. 987*9880d681SAndroid Build Coastguard Worker The alloca, or argument allocation, must also be tagged with the 988*9880d681SAndroid Build Coastguard Worker inalloca keyword. Only the last argument may have the ``inalloca`` 989*9880d681SAndroid Build Coastguard Worker attribute, and that argument is guaranteed to be passed in memory. 990*9880d681SAndroid Build Coastguard Worker 991*9880d681SAndroid Build Coastguard Worker An argument allocation may be used by a call at most once because 992*9880d681SAndroid Build Coastguard Worker the call may deallocate it. The ``inalloca`` attribute cannot be 993*9880d681SAndroid Build Coastguard Worker used in conjunction with other attributes that affect argument 994*9880d681SAndroid Build Coastguard Worker storage, like ``inreg``, ``nest``, ``sret``, or ``byval``. The 995*9880d681SAndroid Build Coastguard Worker ``inalloca`` attribute also disables LLVM's implicit lowering of 996*9880d681SAndroid Build Coastguard Worker large aggregate return values, which means that frontend authors 997*9880d681SAndroid Build Coastguard Worker must lower them with ``sret`` pointers. 998*9880d681SAndroid Build Coastguard Worker 999*9880d681SAndroid Build Coastguard Worker When the call site is reached, the argument allocation must have 1000*9880d681SAndroid Build Coastguard Worker been the most recent stack allocation that is still live, or the 1001*9880d681SAndroid Build Coastguard Worker results are undefined. It is possible to allocate additional stack 1002*9880d681SAndroid Build Coastguard Worker space after an argument allocation and before its call site, but it 1003*9880d681SAndroid Build Coastguard Worker must be cleared off with :ref:`llvm.stackrestore 1004*9880d681SAndroid Build Coastguard Worker <int_stackrestore>`. 1005*9880d681SAndroid Build Coastguard Worker 1006*9880d681SAndroid Build Coastguard Worker See :doc:`InAlloca` for more information on how to use this 1007*9880d681SAndroid Build Coastguard Worker attribute. 1008*9880d681SAndroid Build Coastguard Worker 1009*9880d681SAndroid Build Coastguard Worker``sret`` 1010*9880d681SAndroid Build Coastguard Worker This indicates that the pointer parameter specifies the address of a 1011*9880d681SAndroid Build Coastguard Worker structure that is the return value of the function in the source 1012*9880d681SAndroid Build Coastguard Worker program. This pointer must be guaranteed by the caller to be valid: 1013*9880d681SAndroid Build Coastguard Worker loads and stores to the structure may be assumed by the callee 1014*9880d681SAndroid Build Coastguard Worker not to trap and to be properly aligned. This may only be applied to 1015*9880d681SAndroid Build Coastguard Worker the first parameter. This is not a valid attribute for return 1016*9880d681SAndroid Build Coastguard Worker values. 1017*9880d681SAndroid Build Coastguard Worker 1018*9880d681SAndroid Build Coastguard Worker``align <n>`` 1019*9880d681SAndroid Build Coastguard Worker This indicates that the pointer value may be assumed by the optimizer to 1020*9880d681SAndroid Build Coastguard Worker have the specified alignment. 1021*9880d681SAndroid Build Coastguard Worker 1022*9880d681SAndroid Build Coastguard Worker Note that this attribute has additional semantics when combined with the 1023*9880d681SAndroid Build Coastguard Worker ``byval`` attribute. 1024*9880d681SAndroid Build Coastguard Worker 1025*9880d681SAndroid Build Coastguard Worker.. _noalias: 1026*9880d681SAndroid Build Coastguard Worker 1027*9880d681SAndroid Build Coastguard Worker``noalias`` 1028*9880d681SAndroid Build Coastguard Worker This indicates that objects accessed via pointer values 1029*9880d681SAndroid Build Coastguard Worker :ref:`based <pointeraliasing>` on the argument or return value are not also 1030*9880d681SAndroid Build Coastguard Worker accessed, during the execution of the function, via pointer values not 1031*9880d681SAndroid Build Coastguard Worker *based* on the argument or return value. The attribute on a return value 1032*9880d681SAndroid Build Coastguard Worker also has additional semantics described below. The caller shares the 1033*9880d681SAndroid Build Coastguard Worker responsibility with the callee for ensuring that these requirements are met. 1034*9880d681SAndroid Build Coastguard Worker For further details, please see the discussion of the NoAlias response in 1035*9880d681SAndroid Build Coastguard Worker :ref:`alias analysis <Must, May, or No>`. 1036*9880d681SAndroid Build Coastguard Worker 1037*9880d681SAndroid Build Coastguard Worker Note that this definition of ``noalias`` is intentionally similar 1038*9880d681SAndroid Build Coastguard Worker to the definition of ``restrict`` in C99 for function arguments. 1039*9880d681SAndroid Build Coastguard Worker 1040*9880d681SAndroid Build Coastguard Worker For function return values, C99's ``restrict`` is not meaningful, 1041*9880d681SAndroid Build Coastguard Worker while LLVM's ``noalias`` is. Furthermore, the semantics of the ``noalias`` 1042*9880d681SAndroid Build Coastguard Worker attribute on return values are stronger than the semantics of the attribute 1043*9880d681SAndroid Build Coastguard Worker when used on function arguments. On function return values, the ``noalias`` 1044*9880d681SAndroid Build Coastguard Worker attribute indicates that the function acts like a system memory allocation 1045*9880d681SAndroid Build Coastguard Worker function, returning a pointer to allocated storage disjoint from the 1046*9880d681SAndroid Build Coastguard Worker storage for any other object accessible to the caller. 1047*9880d681SAndroid Build Coastguard Worker 1048*9880d681SAndroid Build Coastguard Worker``nocapture`` 1049*9880d681SAndroid Build Coastguard Worker This indicates that the callee does not make any copies of the 1050*9880d681SAndroid Build Coastguard Worker pointer that outlive the callee itself. This is not a valid 1051*9880d681SAndroid Build Coastguard Worker attribute for return values. Addresses used in volatile operations 1052*9880d681SAndroid Build Coastguard Worker are considered to be captured. 1053*9880d681SAndroid Build Coastguard Worker 1054*9880d681SAndroid Build Coastguard Worker.. _nest: 1055*9880d681SAndroid Build Coastguard Worker 1056*9880d681SAndroid Build Coastguard Worker``nest`` 1057*9880d681SAndroid Build Coastguard Worker This indicates that the pointer parameter can be excised using the 1058*9880d681SAndroid Build Coastguard Worker :ref:`trampoline intrinsics <int_trampoline>`. This is not a valid 1059*9880d681SAndroid Build Coastguard Worker attribute for return values and can only be applied to one parameter. 1060*9880d681SAndroid Build Coastguard Worker 1061*9880d681SAndroid Build Coastguard Worker``returned`` 1062*9880d681SAndroid Build Coastguard Worker This indicates that the function always returns the argument as its return 1063*9880d681SAndroid Build Coastguard Worker value. This is a hint to the optimizer and code generator used when 1064*9880d681SAndroid Build Coastguard Worker generating the caller, allowing value propagation, tail call optimization, 1065*9880d681SAndroid Build Coastguard Worker and omission of register saves and restores in some cases; it is not 1066*9880d681SAndroid Build Coastguard Worker checked or enforced when generating the callee. The parameter and the 1067*9880d681SAndroid Build Coastguard Worker function return type must be valid operands for the 1068*9880d681SAndroid Build Coastguard Worker :ref:`bitcast instruction <i_bitcast>`. This is not a valid attribute for 1069*9880d681SAndroid Build Coastguard Worker return values and can only be applied to one parameter. 1070*9880d681SAndroid Build Coastguard Worker 1071*9880d681SAndroid Build Coastguard Worker``nonnull`` 1072*9880d681SAndroid Build Coastguard Worker This indicates that the parameter or return pointer is not null. This 1073*9880d681SAndroid Build Coastguard Worker attribute may only be applied to pointer typed parameters. This is not 1074*9880d681SAndroid Build Coastguard Worker checked or enforced by LLVM, the caller must ensure that the pointer 1075*9880d681SAndroid Build Coastguard Worker passed in is non-null, or the callee must ensure that the returned pointer 1076*9880d681SAndroid Build Coastguard Worker is non-null. 1077*9880d681SAndroid Build Coastguard Worker 1078*9880d681SAndroid Build Coastguard Worker``dereferenceable(<n>)`` 1079*9880d681SAndroid Build Coastguard Worker This indicates that the parameter or return pointer is dereferenceable. This 1080*9880d681SAndroid Build Coastguard Worker attribute may only be applied to pointer typed parameters. A pointer that 1081*9880d681SAndroid Build Coastguard Worker is dereferenceable can be loaded from speculatively without a risk of 1082*9880d681SAndroid Build Coastguard Worker trapping. The number of bytes known to be dereferenceable must be provided 1083*9880d681SAndroid Build Coastguard Worker in parentheses. It is legal for the number of bytes to be less than the 1084*9880d681SAndroid Build Coastguard Worker size of the pointee type. The ``nonnull`` attribute does not imply 1085*9880d681SAndroid Build Coastguard Worker dereferenceability (consider a pointer to one element past the end of an 1086*9880d681SAndroid Build Coastguard Worker array), however ``dereferenceable(<n>)`` does imply ``nonnull`` in 1087*9880d681SAndroid Build Coastguard Worker ``addrspace(0)`` (which is the default address space). 1088*9880d681SAndroid Build Coastguard Worker 1089*9880d681SAndroid Build Coastguard Worker``dereferenceable_or_null(<n>)`` 1090*9880d681SAndroid Build Coastguard Worker This indicates that the parameter or return value isn't both 1091*9880d681SAndroid Build Coastguard Worker non-null and non-dereferenceable (up to ``<n>`` bytes) at the same 1092*9880d681SAndroid Build Coastguard Worker time. All non-null pointers tagged with 1093*9880d681SAndroid Build Coastguard Worker ``dereferenceable_or_null(<n>)`` are ``dereferenceable(<n>)``. 1094*9880d681SAndroid Build Coastguard Worker For address space 0 ``dereferenceable_or_null(<n>)`` implies that 1095*9880d681SAndroid Build Coastguard Worker a pointer is exactly one of ``dereferenceable(<n>)`` or ``null``, 1096*9880d681SAndroid Build Coastguard Worker and in other address spaces ``dereferenceable_or_null(<n>)`` 1097*9880d681SAndroid Build Coastguard Worker implies that a pointer is at least one of ``dereferenceable(<n>)`` 1098*9880d681SAndroid Build Coastguard Worker or ``null`` (i.e. it may be both ``null`` and 1099*9880d681SAndroid Build Coastguard Worker ``dereferenceable(<n>)``). This attribute may only be applied to 1100*9880d681SAndroid Build Coastguard Worker pointer typed parameters. 1101*9880d681SAndroid Build Coastguard Worker 1102*9880d681SAndroid Build Coastguard Worker``swiftself`` 1103*9880d681SAndroid Build Coastguard Worker This indicates that the parameter is the self/context parameter. This is not 1104*9880d681SAndroid Build Coastguard Worker a valid attribute for return values and can only be applied to one 1105*9880d681SAndroid Build Coastguard Worker parameter. 1106*9880d681SAndroid Build Coastguard Worker 1107*9880d681SAndroid Build Coastguard Worker``swifterror`` 1108*9880d681SAndroid Build Coastguard Worker This attribute is motivated to model and optimize Swift error handling. It 1109*9880d681SAndroid Build Coastguard Worker can be applied to a parameter with pointer to pointer type or a 1110*9880d681SAndroid Build Coastguard Worker pointer-sized alloca. At the call site, the actual argument that corresponds 1111*9880d681SAndroid Build Coastguard Worker to a ``swifterror`` parameter has to come from a ``swifterror`` alloca. A 1112*9880d681SAndroid Build Coastguard Worker ``swifterror`` value (either the parameter or the alloca) can only be loaded 1113*9880d681SAndroid Build Coastguard Worker and stored from, or used as a ``swifterror`` argument. This is not a valid 1114*9880d681SAndroid Build Coastguard Worker attribute for return values and can only be applied to one parameter. 1115*9880d681SAndroid Build Coastguard Worker 1116*9880d681SAndroid Build Coastguard Worker These constraints allow the calling convention to optimize access to 1117*9880d681SAndroid Build Coastguard Worker ``swifterror`` variables by associating them with a specific register at 1118*9880d681SAndroid Build Coastguard Worker call boundaries rather than placing them in memory. Since this does change 1119*9880d681SAndroid Build Coastguard Worker the calling convention, a function which uses the ``swifterror`` attribute 1120*9880d681SAndroid Build Coastguard Worker on a parameter is not ABI-compatible with one which does not. 1121*9880d681SAndroid Build Coastguard Worker 1122*9880d681SAndroid Build Coastguard Worker These constraints also allow LLVM to assume that a ``swifterror`` argument 1123*9880d681SAndroid Build Coastguard Worker does not alias any other memory visible within a function and that a 1124*9880d681SAndroid Build Coastguard Worker ``swifterror`` alloca passed as an argument does not escape. 1125*9880d681SAndroid Build Coastguard Worker 1126*9880d681SAndroid Build Coastguard Worker.. _gc: 1127*9880d681SAndroid Build Coastguard Worker 1128*9880d681SAndroid Build Coastguard WorkerGarbage Collector Strategy Names 1129*9880d681SAndroid Build Coastguard Worker-------------------------------- 1130*9880d681SAndroid Build Coastguard Worker 1131*9880d681SAndroid Build Coastguard WorkerEach function may specify a garbage collector strategy name, which is simply a 1132*9880d681SAndroid Build Coastguard Workerstring: 1133*9880d681SAndroid Build Coastguard Worker 1134*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 1135*9880d681SAndroid Build Coastguard Worker 1136*9880d681SAndroid Build Coastguard Worker define void @f() gc "name" { ... } 1137*9880d681SAndroid Build Coastguard Worker 1138*9880d681SAndroid Build Coastguard WorkerThe supported values of *name* includes those :ref:`built in to LLVM 1139*9880d681SAndroid Build Coastguard Worker<builtin-gc-strategies>` and any provided by loaded plugins. Specifying a GC 1140*9880d681SAndroid Build Coastguard Workerstrategy will cause the compiler to alter its output in order to support the 1141*9880d681SAndroid Build Coastguard Workernamed garbage collection algorithm. Note that LLVM itself does not contain a 1142*9880d681SAndroid Build Coastguard Workergarbage collector, this functionality is restricted to generating machine code 1143*9880d681SAndroid Build Coastguard Workerwhich can interoperate with a collector provided externally. 1144*9880d681SAndroid Build Coastguard Worker 1145*9880d681SAndroid Build Coastguard Worker.. _prefixdata: 1146*9880d681SAndroid Build Coastguard Worker 1147*9880d681SAndroid Build Coastguard WorkerPrefix Data 1148*9880d681SAndroid Build Coastguard Worker----------- 1149*9880d681SAndroid Build Coastguard Worker 1150*9880d681SAndroid Build Coastguard WorkerPrefix data is data associated with a function which the code 1151*9880d681SAndroid Build Coastguard Workergenerator will emit immediately before the function's entrypoint. 1152*9880d681SAndroid Build Coastguard WorkerThe purpose of this feature is to allow frontends to associate 1153*9880d681SAndroid Build Coastguard Workerlanguage-specific runtime metadata with specific functions and make it 1154*9880d681SAndroid Build Coastguard Workeravailable through the function pointer while still allowing the 1155*9880d681SAndroid Build Coastguard Workerfunction pointer to be called. 1156*9880d681SAndroid Build Coastguard Worker 1157*9880d681SAndroid Build Coastguard WorkerTo access the data for a given function, a program may bitcast the 1158*9880d681SAndroid Build Coastguard Workerfunction pointer to a pointer to the constant's type and dereference 1159*9880d681SAndroid Build Coastguard Workerindex -1. This implies that the IR symbol points just past the end of 1160*9880d681SAndroid Build Coastguard Workerthe prefix data. For instance, take the example of a function annotated 1161*9880d681SAndroid Build Coastguard Workerwith a single ``i32``, 1162*9880d681SAndroid Build Coastguard Worker 1163*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 1164*9880d681SAndroid Build Coastguard Worker 1165*9880d681SAndroid Build Coastguard Worker define void @f() prefix i32 123 { ... } 1166*9880d681SAndroid Build Coastguard Worker 1167*9880d681SAndroid Build Coastguard WorkerThe prefix data can be referenced as, 1168*9880d681SAndroid Build Coastguard Worker 1169*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 1170*9880d681SAndroid Build Coastguard Worker 1171*9880d681SAndroid Build Coastguard Worker %0 = bitcast void* () @f to i32* 1172*9880d681SAndroid Build Coastguard Worker %a = getelementptr inbounds i32, i32* %0, i32 -1 1173*9880d681SAndroid Build Coastguard Worker %b = load i32, i32* %a 1174*9880d681SAndroid Build Coastguard Worker 1175*9880d681SAndroid Build Coastguard WorkerPrefix data is laid out as if it were an initializer for a global variable 1176*9880d681SAndroid Build Coastguard Workerof the prefix data's type. The function will be placed such that the 1177*9880d681SAndroid Build Coastguard Workerbeginning of the prefix data is aligned. This means that if the size 1178*9880d681SAndroid Build Coastguard Workerof the prefix data is not a multiple of the alignment size, the 1179*9880d681SAndroid Build Coastguard Workerfunction's entrypoint will not be aligned. If alignment of the 1180*9880d681SAndroid Build Coastguard Workerfunction's entrypoint is desired, padding must be added to the prefix 1181*9880d681SAndroid Build Coastguard Workerdata. 1182*9880d681SAndroid Build Coastguard Worker 1183*9880d681SAndroid Build Coastguard WorkerA function may have prefix data but no body. This has similar semantics 1184*9880d681SAndroid Build Coastguard Workerto the ``available_externally`` linkage in that the data may be used by the 1185*9880d681SAndroid Build Coastguard Workeroptimizers but will not be emitted in the object file. 1186*9880d681SAndroid Build Coastguard Worker 1187*9880d681SAndroid Build Coastguard Worker.. _prologuedata: 1188*9880d681SAndroid Build Coastguard Worker 1189*9880d681SAndroid Build Coastguard WorkerPrologue Data 1190*9880d681SAndroid Build Coastguard Worker------------- 1191*9880d681SAndroid Build Coastguard Worker 1192*9880d681SAndroid Build Coastguard WorkerThe ``prologue`` attribute allows arbitrary code (encoded as bytes) to 1193*9880d681SAndroid Build Coastguard Workerbe inserted prior to the function body. This can be used for enabling 1194*9880d681SAndroid Build Coastguard Workerfunction hot-patching and instrumentation. 1195*9880d681SAndroid Build Coastguard Worker 1196*9880d681SAndroid Build Coastguard WorkerTo maintain the semantics of ordinary function calls, the prologue data must 1197*9880d681SAndroid Build Coastguard Workerhave a particular format. Specifically, it must begin with a sequence of 1198*9880d681SAndroid Build Coastguard Workerbytes which decode to a sequence of machine instructions, valid for the 1199*9880d681SAndroid Build Coastguard Workermodule's target, which transfer control to the point immediately succeeding 1200*9880d681SAndroid Build Coastguard Workerthe prologue data, without performing any other visible action. This allows 1201*9880d681SAndroid Build Coastguard Workerthe inliner and other passes to reason about the semantics of the function 1202*9880d681SAndroid Build Coastguard Workerdefinition without needing to reason about the prologue data. Obviously this 1203*9880d681SAndroid Build Coastguard Workermakes the format of the prologue data highly target dependent. 1204*9880d681SAndroid Build Coastguard Worker 1205*9880d681SAndroid Build Coastguard WorkerA trivial example of valid prologue data for the x86 architecture is ``i8 144``, 1206*9880d681SAndroid Build Coastguard Workerwhich encodes the ``nop`` instruction: 1207*9880d681SAndroid Build Coastguard Worker 1208*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 1209*9880d681SAndroid Build Coastguard Worker 1210*9880d681SAndroid Build Coastguard Worker define void @f() prologue i8 144 { ... } 1211*9880d681SAndroid Build Coastguard Worker 1212*9880d681SAndroid Build Coastguard WorkerGenerally prologue data can be formed by encoding a relative branch instruction 1213*9880d681SAndroid Build Coastguard Workerwhich skips the metadata, as in this example of valid prologue data for the 1214*9880d681SAndroid Build Coastguard Workerx86_64 architecture, where the first two bytes encode ``jmp .+10``: 1215*9880d681SAndroid Build Coastguard Worker 1216*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 1217*9880d681SAndroid Build Coastguard Worker 1218*9880d681SAndroid Build Coastguard Worker %0 = type <{ i8, i8, i8* }> 1219*9880d681SAndroid Build Coastguard Worker 1220*9880d681SAndroid Build Coastguard Worker define void @f() prologue %0 <{ i8 235, i8 8, i8* @md}> { ... } 1221*9880d681SAndroid Build Coastguard Worker 1222*9880d681SAndroid Build Coastguard WorkerA function may have prologue data but no body. This has similar semantics 1223*9880d681SAndroid Build Coastguard Workerto the ``available_externally`` linkage in that the data may be used by the 1224*9880d681SAndroid Build Coastguard Workeroptimizers but will not be emitted in the object file. 1225*9880d681SAndroid Build Coastguard Worker 1226*9880d681SAndroid Build Coastguard Worker.. _personalityfn: 1227*9880d681SAndroid Build Coastguard Worker 1228*9880d681SAndroid Build Coastguard WorkerPersonality Function 1229*9880d681SAndroid Build Coastguard Worker-------------------- 1230*9880d681SAndroid Build Coastguard Worker 1231*9880d681SAndroid Build Coastguard WorkerThe ``personality`` attribute permits functions to specify what function 1232*9880d681SAndroid Build Coastguard Workerto use for exception handling. 1233*9880d681SAndroid Build Coastguard Worker 1234*9880d681SAndroid Build Coastguard Worker.. _attrgrp: 1235*9880d681SAndroid Build Coastguard Worker 1236*9880d681SAndroid Build Coastguard WorkerAttribute Groups 1237*9880d681SAndroid Build Coastguard Worker---------------- 1238*9880d681SAndroid Build Coastguard Worker 1239*9880d681SAndroid Build Coastguard WorkerAttribute groups are groups of attributes that are referenced by objects within 1240*9880d681SAndroid Build Coastguard Workerthe IR. They are important for keeping ``.ll`` files readable, because a lot of 1241*9880d681SAndroid Build Coastguard Workerfunctions will use the same set of attributes. In the degenerative case of a 1242*9880d681SAndroid Build Coastguard Worker``.ll`` file that corresponds to a single ``.c`` file, the single attribute 1243*9880d681SAndroid Build Coastguard Workergroup will capture the important command line flags used to build that file. 1244*9880d681SAndroid Build Coastguard Worker 1245*9880d681SAndroid Build Coastguard WorkerAn attribute group is a module-level object. To use an attribute group, an 1246*9880d681SAndroid Build Coastguard Workerobject references the attribute group's ID (e.g. ``#37``). An object may refer 1247*9880d681SAndroid Build Coastguard Workerto more than one attribute group. In that situation, the attributes from the 1248*9880d681SAndroid Build Coastguard Workerdifferent groups are merged. 1249*9880d681SAndroid Build Coastguard Worker 1250*9880d681SAndroid Build Coastguard WorkerHere is an example of attribute groups for a function that should always be 1251*9880d681SAndroid Build Coastguard Workerinlined, has a stack alignment of 4, and which shouldn't use SSE instructions: 1252*9880d681SAndroid Build Coastguard Worker 1253*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 1254*9880d681SAndroid Build Coastguard Worker 1255*9880d681SAndroid Build Coastguard Worker ; Target-independent attributes: 1256*9880d681SAndroid Build Coastguard Worker attributes #0 = { alwaysinline alignstack=4 } 1257*9880d681SAndroid Build Coastguard Worker 1258*9880d681SAndroid Build Coastguard Worker ; Target-dependent attributes: 1259*9880d681SAndroid Build Coastguard Worker attributes #1 = { "no-sse" } 1260*9880d681SAndroid Build Coastguard Worker 1261*9880d681SAndroid Build Coastguard Worker ; Function @f has attributes: alwaysinline, alignstack=4, and "no-sse". 1262*9880d681SAndroid Build Coastguard Worker define void @f() #0 #1 { ... } 1263*9880d681SAndroid Build Coastguard Worker 1264*9880d681SAndroid Build Coastguard Worker.. _fnattrs: 1265*9880d681SAndroid Build Coastguard Worker 1266*9880d681SAndroid Build Coastguard WorkerFunction Attributes 1267*9880d681SAndroid Build Coastguard Worker------------------- 1268*9880d681SAndroid Build Coastguard Worker 1269*9880d681SAndroid Build Coastguard WorkerFunction attributes are set to communicate additional information about 1270*9880d681SAndroid Build Coastguard Workera function. Function attributes are considered to be part of the 1271*9880d681SAndroid Build Coastguard Workerfunction, not of the function type, so functions with different function 1272*9880d681SAndroid Build Coastguard Workerattributes can have the same function type. 1273*9880d681SAndroid Build Coastguard Worker 1274*9880d681SAndroid Build Coastguard WorkerFunction attributes are simple keywords that follow the type specified. 1275*9880d681SAndroid Build Coastguard WorkerIf multiple attributes are needed, they are space separated. For 1276*9880d681SAndroid Build Coastguard Workerexample: 1277*9880d681SAndroid Build Coastguard Worker 1278*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 1279*9880d681SAndroid Build Coastguard Worker 1280*9880d681SAndroid Build Coastguard Worker define void @f() noinline { ... } 1281*9880d681SAndroid Build Coastguard Worker define void @f() alwaysinline { ... } 1282*9880d681SAndroid Build Coastguard Worker define void @f() alwaysinline optsize { ... } 1283*9880d681SAndroid Build Coastguard Worker define void @f() optsize { ... } 1284*9880d681SAndroid Build Coastguard Worker 1285*9880d681SAndroid Build Coastguard Worker``alignstack(<n>)`` 1286*9880d681SAndroid Build Coastguard Worker This attribute indicates that, when emitting the prologue and 1287*9880d681SAndroid Build Coastguard Worker epilogue, the backend should forcibly align the stack pointer. 1288*9880d681SAndroid Build Coastguard Worker Specify the desired alignment, which must be a power of two, in 1289*9880d681SAndroid Build Coastguard Worker parentheses. 1290*9880d681SAndroid Build Coastguard Worker``allocsize(<EltSizeParam>[, <NumEltsParam>])`` 1291*9880d681SAndroid Build Coastguard Worker This attribute indicates that the annotated function will always return at 1292*9880d681SAndroid Build Coastguard Worker least a given number of bytes (or null). Its arguments are zero-indexed 1293*9880d681SAndroid Build Coastguard Worker parameter numbers; if one argument is provided, then it's assumed that at 1294*9880d681SAndroid Build Coastguard Worker least ``CallSite.Args[EltSizeParam]`` bytes will be available at the 1295*9880d681SAndroid Build Coastguard Worker returned pointer. If two are provided, then it's assumed that 1296*9880d681SAndroid Build Coastguard Worker ``CallSite.Args[EltSizeParam] * CallSite.Args[NumEltsParam]`` bytes are 1297*9880d681SAndroid Build Coastguard Worker available. The referenced parameters must be integer types. No assumptions 1298*9880d681SAndroid Build Coastguard Worker are made about the contents of the returned block of memory. 1299*9880d681SAndroid Build Coastguard Worker``alwaysinline`` 1300*9880d681SAndroid Build Coastguard Worker This attribute indicates that the inliner should attempt to inline 1301*9880d681SAndroid Build Coastguard Worker this function into callers whenever possible, ignoring any active 1302*9880d681SAndroid Build Coastguard Worker inlining size threshold for this caller. 1303*9880d681SAndroid Build Coastguard Worker``builtin`` 1304*9880d681SAndroid Build Coastguard Worker This indicates that the callee function at a call site should be 1305*9880d681SAndroid Build Coastguard Worker recognized as a built-in function, even though the function's declaration 1306*9880d681SAndroid Build Coastguard Worker uses the ``nobuiltin`` attribute. This is only valid at call sites for 1307*9880d681SAndroid Build Coastguard Worker direct calls to functions that are declared with the ``nobuiltin`` 1308*9880d681SAndroid Build Coastguard Worker attribute. 1309*9880d681SAndroid Build Coastguard Worker``cold`` 1310*9880d681SAndroid Build Coastguard Worker This attribute indicates that this function is rarely called. When 1311*9880d681SAndroid Build Coastguard Worker computing edge weights, basic blocks post-dominated by a cold 1312*9880d681SAndroid Build Coastguard Worker function call are also considered to be cold; and, thus, given low 1313*9880d681SAndroid Build Coastguard Worker weight. 1314*9880d681SAndroid Build Coastguard Worker``convergent`` 1315*9880d681SAndroid Build Coastguard Worker In some parallel execution models, there exist operations that cannot be 1316*9880d681SAndroid Build Coastguard Worker made control-dependent on any additional values. We call such operations 1317*9880d681SAndroid Build Coastguard Worker ``convergent``, and mark them with this attribute. 1318*9880d681SAndroid Build Coastguard Worker 1319*9880d681SAndroid Build Coastguard Worker The ``convergent`` attribute may appear on functions or call/invoke 1320*9880d681SAndroid Build Coastguard Worker instructions. When it appears on a function, it indicates that calls to 1321*9880d681SAndroid Build Coastguard Worker this function should not be made control-dependent on additional values. 1322*9880d681SAndroid Build Coastguard Worker For example, the intrinsic ``llvm.nvvm.barrier0`` is ``convergent``, so 1323*9880d681SAndroid Build Coastguard Worker calls to this intrinsic cannot be made control-dependent on additional 1324*9880d681SAndroid Build Coastguard Worker values. 1325*9880d681SAndroid Build Coastguard Worker 1326*9880d681SAndroid Build Coastguard Worker When it appears on a call/invoke, the ``convergent`` attribute indicates 1327*9880d681SAndroid Build Coastguard Worker that we should treat the call as though we're calling a convergent 1328*9880d681SAndroid Build Coastguard Worker function. This is particularly useful on indirect calls; without this we 1329*9880d681SAndroid Build Coastguard Worker may treat such calls as though the target is non-convergent. 1330*9880d681SAndroid Build Coastguard Worker 1331*9880d681SAndroid Build Coastguard Worker The optimizer may remove the ``convergent`` attribute on functions when it 1332*9880d681SAndroid Build Coastguard Worker can prove that the function does not execute any convergent operations. 1333*9880d681SAndroid Build Coastguard Worker Similarly, the optimizer may remove ``convergent`` on calls/invokes when it 1334*9880d681SAndroid Build Coastguard Worker can prove that the call/invoke cannot call a convergent function. 1335*9880d681SAndroid Build Coastguard Worker``inaccessiblememonly`` 1336*9880d681SAndroid Build Coastguard Worker This attribute indicates that the function may only access memory that 1337*9880d681SAndroid Build Coastguard Worker is not accessible by the module being compiled. This is a weaker form 1338*9880d681SAndroid Build Coastguard Worker of ``readnone``. 1339*9880d681SAndroid Build Coastguard Worker``inaccessiblemem_or_argmemonly`` 1340*9880d681SAndroid Build Coastguard Worker This attribute indicates that the function may only access memory that is 1341*9880d681SAndroid Build Coastguard Worker either not accessible by the module being compiled, or is pointed to 1342*9880d681SAndroid Build Coastguard Worker by its pointer arguments. This is a weaker form of ``argmemonly`` 1343*9880d681SAndroid Build Coastguard Worker``inlinehint`` 1344*9880d681SAndroid Build Coastguard Worker This attribute indicates that the source code contained a hint that 1345*9880d681SAndroid Build Coastguard Worker inlining this function is desirable (such as the "inline" keyword in 1346*9880d681SAndroid Build Coastguard Worker C/C++). It is just a hint; it imposes no requirements on the 1347*9880d681SAndroid Build Coastguard Worker inliner. 1348*9880d681SAndroid Build Coastguard Worker``jumptable`` 1349*9880d681SAndroid Build Coastguard Worker This attribute indicates that the function should be added to a 1350*9880d681SAndroid Build Coastguard Worker jump-instruction table at code-generation time, and that all address-taken 1351*9880d681SAndroid Build Coastguard Worker references to this function should be replaced with a reference to the 1352*9880d681SAndroid Build Coastguard Worker appropriate jump-instruction-table function pointer. Note that this creates 1353*9880d681SAndroid Build Coastguard Worker a new pointer for the original function, which means that code that depends 1354*9880d681SAndroid Build Coastguard Worker on function-pointer identity can break. So, any function annotated with 1355*9880d681SAndroid Build Coastguard Worker ``jumptable`` must also be ``unnamed_addr``. 1356*9880d681SAndroid Build Coastguard Worker``minsize`` 1357*9880d681SAndroid Build Coastguard Worker This attribute suggests that optimization passes and code generator 1358*9880d681SAndroid Build Coastguard Worker passes make choices that keep the code size of this function as small 1359*9880d681SAndroid Build Coastguard Worker as possible and perform optimizations that may sacrifice runtime 1360*9880d681SAndroid Build Coastguard Worker performance in order to minimize the size of the generated code. 1361*9880d681SAndroid Build Coastguard Worker``naked`` 1362*9880d681SAndroid Build Coastguard Worker This attribute disables prologue / epilogue emission for the 1363*9880d681SAndroid Build Coastguard Worker function. This can have very system-specific consequences. 1364*9880d681SAndroid Build Coastguard Worker``nobuiltin`` 1365*9880d681SAndroid Build Coastguard Worker This indicates that the callee function at a call site is not recognized as 1366*9880d681SAndroid Build Coastguard Worker a built-in function. LLVM will retain the original call and not replace it 1367*9880d681SAndroid Build Coastguard Worker with equivalent code based on the semantics of the built-in function, unless 1368*9880d681SAndroid Build Coastguard Worker the call site uses the ``builtin`` attribute. This is valid at call sites 1369*9880d681SAndroid Build Coastguard Worker and on function declarations and definitions. 1370*9880d681SAndroid Build Coastguard Worker``noduplicate`` 1371*9880d681SAndroid Build Coastguard Worker This attribute indicates that calls to the function cannot be 1372*9880d681SAndroid Build Coastguard Worker duplicated. A call to a ``noduplicate`` function may be moved 1373*9880d681SAndroid Build Coastguard Worker within its parent function, but may not be duplicated within 1374*9880d681SAndroid Build Coastguard Worker its parent function. 1375*9880d681SAndroid Build Coastguard Worker 1376*9880d681SAndroid Build Coastguard Worker A function containing a ``noduplicate`` call may still 1377*9880d681SAndroid Build Coastguard Worker be an inlining candidate, provided that the call is not 1378*9880d681SAndroid Build Coastguard Worker duplicated by inlining. That implies that the function has 1379*9880d681SAndroid Build Coastguard Worker internal linkage and only has one call site, so the original 1380*9880d681SAndroid Build Coastguard Worker call is dead after inlining. 1381*9880d681SAndroid Build Coastguard Worker``noimplicitfloat`` 1382*9880d681SAndroid Build Coastguard Worker This attributes disables implicit floating point instructions. 1383*9880d681SAndroid Build Coastguard Worker``noinline`` 1384*9880d681SAndroid Build Coastguard Worker This attribute indicates that the inliner should never inline this 1385*9880d681SAndroid Build Coastguard Worker function in any situation. This attribute may not be used together 1386*9880d681SAndroid Build Coastguard Worker with the ``alwaysinline`` attribute. 1387*9880d681SAndroid Build Coastguard Worker``nonlazybind`` 1388*9880d681SAndroid Build Coastguard Worker This attribute suppresses lazy symbol binding for the function. This 1389*9880d681SAndroid Build Coastguard Worker may make calls to the function faster, at the cost of extra program 1390*9880d681SAndroid Build Coastguard Worker startup time if the function is not called during program startup. 1391*9880d681SAndroid Build Coastguard Worker``noredzone`` 1392*9880d681SAndroid Build Coastguard Worker This attribute indicates that the code generator should not use a 1393*9880d681SAndroid Build Coastguard Worker red zone, even if the target-specific ABI normally permits it. 1394*9880d681SAndroid Build Coastguard Worker``noreturn`` 1395*9880d681SAndroid Build Coastguard Worker This function attribute indicates that the function never returns 1396*9880d681SAndroid Build Coastguard Worker normally. This produces undefined behavior at runtime if the 1397*9880d681SAndroid Build Coastguard Worker function ever does dynamically return. 1398*9880d681SAndroid Build Coastguard Worker``norecurse`` 1399*9880d681SAndroid Build Coastguard Worker This function attribute indicates that the function does not call itself 1400*9880d681SAndroid Build Coastguard Worker either directly or indirectly down any possible call path. This produces 1401*9880d681SAndroid Build Coastguard Worker undefined behavior at runtime if the function ever does recurse. 1402*9880d681SAndroid Build Coastguard Worker``nounwind`` 1403*9880d681SAndroid Build Coastguard Worker This function attribute indicates that the function never raises an 1404*9880d681SAndroid Build Coastguard Worker exception. If the function does raise an exception, its runtime 1405*9880d681SAndroid Build Coastguard Worker behavior is undefined. However, functions marked nounwind may still 1406*9880d681SAndroid Build Coastguard Worker trap or generate asynchronous exceptions. Exception handling schemes 1407*9880d681SAndroid Build Coastguard Worker that are recognized by LLVM to handle asynchronous exceptions, such 1408*9880d681SAndroid Build Coastguard Worker as SEH, will still provide their implementation defined semantics. 1409*9880d681SAndroid Build Coastguard Worker``optnone`` 1410*9880d681SAndroid Build Coastguard Worker This function attribute indicates that most optimization passes will skip 1411*9880d681SAndroid Build Coastguard Worker this function, with the exception of interprocedural optimization passes. 1412*9880d681SAndroid Build Coastguard Worker Code generation defaults to the "fast" instruction selector. 1413*9880d681SAndroid Build Coastguard Worker This attribute cannot be used together with the ``alwaysinline`` 1414*9880d681SAndroid Build Coastguard Worker attribute; this attribute is also incompatible 1415*9880d681SAndroid Build Coastguard Worker with the ``minsize`` attribute and the ``optsize`` attribute. 1416*9880d681SAndroid Build Coastguard Worker 1417*9880d681SAndroid Build Coastguard Worker This attribute requires the ``noinline`` attribute to be specified on 1418*9880d681SAndroid Build Coastguard Worker the function as well, so the function is never inlined into any caller. 1419*9880d681SAndroid Build Coastguard Worker Only functions with the ``alwaysinline`` attribute are valid 1420*9880d681SAndroid Build Coastguard Worker candidates for inlining into the body of this function. 1421*9880d681SAndroid Build Coastguard Worker``optsize`` 1422*9880d681SAndroid Build Coastguard Worker This attribute suggests that optimization passes and code generator 1423*9880d681SAndroid Build Coastguard Worker passes make choices that keep the code size of this function low, 1424*9880d681SAndroid Build Coastguard Worker and otherwise do optimizations specifically to reduce code size as 1425*9880d681SAndroid Build Coastguard Worker long as they do not significantly impact runtime performance. 1426*9880d681SAndroid Build Coastguard Worker``"patchable-function"`` 1427*9880d681SAndroid Build Coastguard Worker This attribute tells the code generator that the code 1428*9880d681SAndroid Build Coastguard Worker generated for this function needs to follow certain conventions that 1429*9880d681SAndroid Build Coastguard Worker make it possible for a runtime function to patch over it later. 1430*9880d681SAndroid Build Coastguard Worker The exact effect of this attribute depends on its string value, 1431*9880d681SAndroid Build Coastguard Worker for which there currently is one legal possibility: 1432*9880d681SAndroid Build Coastguard Worker 1433*9880d681SAndroid Build Coastguard Worker * ``"prologue-short-redirect"`` - This style of patchable 1434*9880d681SAndroid Build Coastguard Worker function is intended to support patching a function prologue to 1435*9880d681SAndroid Build Coastguard Worker redirect control away from the function in a thread safe 1436*9880d681SAndroid Build Coastguard Worker manner. It guarantees that the first instruction of the 1437*9880d681SAndroid Build Coastguard Worker function will be large enough to accommodate a short jump 1438*9880d681SAndroid Build Coastguard Worker instruction, and will be sufficiently aligned to allow being 1439*9880d681SAndroid Build Coastguard Worker fully changed via an atomic compare-and-swap instruction. 1440*9880d681SAndroid Build Coastguard Worker While the first requirement can be satisfied by inserting large 1441*9880d681SAndroid Build Coastguard Worker enough NOP, LLVM can and will try to re-purpose an existing 1442*9880d681SAndroid Build Coastguard Worker instruction (i.e. one that would have to be emitted anyway) as 1443*9880d681SAndroid Build Coastguard Worker the patchable instruction larger than a short jump. 1444*9880d681SAndroid Build Coastguard Worker 1445*9880d681SAndroid Build Coastguard Worker ``"prologue-short-redirect"`` is currently only supported on 1446*9880d681SAndroid Build Coastguard Worker x86-64. 1447*9880d681SAndroid Build Coastguard Worker 1448*9880d681SAndroid Build Coastguard Worker This attribute by itself does not imply restrictions on 1449*9880d681SAndroid Build Coastguard Worker inter-procedural optimizations. All of the semantic effects the 1450*9880d681SAndroid Build Coastguard Worker patching may have to be separately conveyed via the linkage type. 1451*9880d681SAndroid Build Coastguard Worker``readnone`` 1452*9880d681SAndroid Build Coastguard Worker On a function, this attribute indicates that the function computes its 1453*9880d681SAndroid Build Coastguard Worker result (or decides to unwind an exception) based strictly on its arguments, 1454*9880d681SAndroid Build Coastguard Worker without dereferencing any pointer arguments or otherwise accessing 1455*9880d681SAndroid Build Coastguard Worker any mutable state (e.g. memory, control registers, etc) visible to 1456*9880d681SAndroid Build Coastguard Worker caller functions. It does not write through any pointer arguments 1457*9880d681SAndroid Build Coastguard Worker (including ``byval`` arguments) and never changes any state visible 1458*9880d681SAndroid Build Coastguard Worker to callers. This means that it cannot unwind exceptions by calling 1459*9880d681SAndroid Build Coastguard Worker the ``C++`` exception throwing methods. 1460*9880d681SAndroid Build Coastguard Worker 1461*9880d681SAndroid Build Coastguard Worker On an argument, this attribute indicates that the function does not 1462*9880d681SAndroid Build Coastguard Worker dereference that pointer argument, even though it may read or write the 1463*9880d681SAndroid Build Coastguard Worker memory that the pointer points to if accessed through other pointers. 1464*9880d681SAndroid Build Coastguard Worker``readonly`` 1465*9880d681SAndroid Build Coastguard Worker On a function, this attribute indicates that the function does not write 1466*9880d681SAndroid Build Coastguard Worker through any pointer arguments (including ``byval`` arguments) or otherwise 1467*9880d681SAndroid Build Coastguard Worker modify any state (e.g. memory, control registers, etc) visible to 1468*9880d681SAndroid Build Coastguard Worker caller functions. It may dereference pointer arguments and read 1469*9880d681SAndroid Build Coastguard Worker state that may be set in the caller. A readonly function always 1470*9880d681SAndroid Build Coastguard Worker returns the same value (or unwinds an exception identically) when 1471*9880d681SAndroid Build Coastguard Worker called with the same set of arguments and global state. It cannot 1472*9880d681SAndroid Build Coastguard Worker unwind an exception by calling the ``C++`` exception throwing 1473*9880d681SAndroid Build Coastguard Worker methods. 1474*9880d681SAndroid Build Coastguard Worker 1475*9880d681SAndroid Build Coastguard Worker On an argument, this attribute indicates that the function does not write 1476*9880d681SAndroid Build Coastguard Worker through this pointer argument, even though it may write to the memory that 1477*9880d681SAndroid Build Coastguard Worker the pointer points to. 1478*9880d681SAndroid Build Coastguard Worker``writeonly`` 1479*9880d681SAndroid Build Coastguard Worker On a function, this attribute indicates that the function may write to but 1480*9880d681SAndroid Build Coastguard Worker does not read from memory. 1481*9880d681SAndroid Build Coastguard Worker 1482*9880d681SAndroid Build Coastguard Worker On an argument, this attribute indicates that the function may write to but 1483*9880d681SAndroid Build Coastguard Worker does not read through this pointer argument (even though it may read from 1484*9880d681SAndroid Build Coastguard Worker the memory that the pointer points to). 1485*9880d681SAndroid Build Coastguard Worker``argmemonly`` 1486*9880d681SAndroid Build Coastguard Worker This attribute indicates that the only memory accesses inside function are 1487*9880d681SAndroid Build Coastguard Worker loads and stores from objects pointed to by its pointer-typed arguments, 1488*9880d681SAndroid Build Coastguard Worker with arbitrary offsets. Or in other words, all memory operations in the 1489*9880d681SAndroid Build Coastguard Worker function can refer to memory only using pointers based on its function 1490*9880d681SAndroid Build Coastguard Worker arguments. 1491*9880d681SAndroid Build Coastguard Worker Note that ``argmemonly`` can be used together with ``readonly`` attribute 1492*9880d681SAndroid Build Coastguard Worker in order to specify that function reads only from its arguments. 1493*9880d681SAndroid Build Coastguard Worker``returns_twice`` 1494*9880d681SAndroid Build Coastguard Worker This attribute indicates that this function can return twice. The C 1495*9880d681SAndroid Build Coastguard Worker ``setjmp`` is an example of such a function. The compiler disables 1496*9880d681SAndroid Build Coastguard Worker some optimizations (like tail calls) in the caller of these 1497*9880d681SAndroid Build Coastguard Worker functions. 1498*9880d681SAndroid Build Coastguard Worker``safestack`` 1499*9880d681SAndroid Build Coastguard Worker This attribute indicates that 1500*9880d681SAndroid Build Coastguard Worker `SafeStack <http://clang.llvm.org/docs/SafeStack.html>`_ 1501*9880d681SAndroid Build Coastguard Worker protection is enabled for this function. 1502*9880d681SAndroid Build Coastguard Worker 1503*9880d681SAndroid Build Coastguard Worker If a function that has a ``safestack`` attribute is inlined into a 1504*9880d681SAndroid Build Coastguard Worker function that doesn't have a ``safestack`` attribute or which has an 1505*9880d681SAndroid Build Coastguard Worker ``ssp``, ``sspstrong`` or ``sspreq`` attribute, then the resulting 1506*9880d681SAndroid Build Coastguard Worker function will have a ``safestack`` attribute. 1507*9880d681SAndroid Build Coastguard Worker``sanitize_address`` 1508*9880d681SAndroid Build Coastguard Worker This attribute indicates that AddressSanitizer checks 1509*9880d681SAndroid Build Coastguard Worker (dynamic address safety analysis) are enabled for this function. 1510*9880d681SAndroid Build Coastguard Worker``sanitize_memory`` 1511*9880d681SAndroid Build Coastguard Worker This attribute indicates that MemorySanitizer checks (dynamic detection 1512*9880d681SAndroid Build Coastguard Worker of accesses to uninitialized memory) are enabled for this function. 1513*9880d681SAndroid Build Coastguard Worker``sanitize_thread`` 1514*9880d681SAndroid Build Coastguard Worker This attribute indicates that ThreadSanitizer checks 1515*9880d681SAndroid Build Coastguard Worker (dynamic thread safety analysis) are enabled for this function. 1516*9880d681SAndroid Build Coastguard Worker``ssp`` 1517*9880d681SAndroid Build Coastguard Worker This attribute indicates that the function should emit a stack 1518*9880d681SAndroid Build Coastguard Worker smashing protector. It is in the form of a "canary" --- a random value 1519*9880d681SAndroid Build Coastguard Worker placed on the stack before the local variables that's checked upon 1520*9880d681SAndroid Build Coastguard Worker return from the function to see if it has been overwritten. A 1521*9880d681SAndroid Build Coastguard Worker heuristic is used to determine if a function needs stack protectors 1522*9880d681SAndroid Build Coastguard Worker or not. The heuristic used will enable protectors for functions with: 1523*9880d681SAndroid Build Coastguard Worker 1524*9880d681SAndroid Build Coastguard Worker - Character arrays larger than ``ssp-buffer-size`` (default 8). 1525*9880d681SAndroid Build Coastguard Worker - Aggregates containing character arrays larger than ``ssp-buffer-size``. 1526*9880d681SAndroid Build Coastguard Worker - Calls to alloca() with variable sizes or constant sizes greater than 1527*9880d681SAndroid Build Coastguard Worker ``ssp-buffer-size``. 1528*9880d681SAndroid Build Coastguard Worker 1529*9880d681SAndroid Build Coastguard Worker Variables that are identified as requiring a protector will be arranged 1530*9880d681SAndroid Build Coastguard Worker on the stack such that they are adjacent to the stack protector guard. 1531*9880d681SAndroid Build Coastguard Worker 1532*9880d681SAndroid Build Coastguard Worker If a function that has an ``ssp`` attribute is inlined into a 1533*9880d681SAndroid Build Coastguard Worker function that doesn't have an ``ssp`` attribute, then the resulting 1534*9880d681SAndroid Build Coastguard Worker function will have an ``ssp`` attribute. 1535*9880d681SAndroid Build Coastguard Worker``sspreq`` 1536*9880d681SAndroid Build Coastguard Worker This attribute indicates that the function should *always* emit a 1537*9880d681SAndroid Build Coastguard Worker stack smashing protector. This overrides the ``ssp`` function 1538*9880d681SAndroid Build Coastguard Worker attribute. 1539*9880d681SAndroid Build Coastguard Worker 1540*9880d681SAndroid Build Coastguard Worker Variables that are identified as requiring a protector will be arranged 1541*9880d681SAndroid Build Coastguard Worker on the stack such that they are adjacent to the stack protector guard. 1542*9880d681SAndroid Build Coastguard Worker The specific layout rules are: 1543*9880d681SAndroid Build Coastguard Worker 1544*9880d681SAndroid Build Coastguard Worker #. Large arrays and structures containing large arrays 1545*9880d681SAndroid Build Coastguard Worker (``>= ssp-buffer-size``) are closest to the stack protector. 1546*9880d681SAndroid Build Coastguard Worker #. Small arrays and structures containing small arrays 1547*9880d681SAndroid Build Coastguard Worker (``< ssp-buffer-size``) are 2nd closest to the protector. 1548*9880d681SAndroid Build Coastguard Worker #. Variables that have had their address taken are 3rd closest to the 1549*9880d681SAndroid Build Coastguard Worker protector. 1550*9880d681SAndroid Build Coastguard Worker 1551*9880d681SAndroid Build Coastguard Worker If a function that has an ``sspreq`` attribute is inlined into a 1552*9880d681SAndroid Build Coastguard Worker function that doesn't have an ``sspreq`` attribute or which has an 1553*9880d681SAndroid Build Coastguard Worker ``ssp`` or ``sspstrong`` attribute, then the resulting function will have 1554*9880d681SAndroid Build Coastguard Worker an ``sspreq`` attribute. 1555*9880d681SAndroid Build Coastguard Worker``sspstrong`` 1556*9880d681SAndroid Build Coastguard Worker This attribute indicates that the function should emit a stack smashing 1557*9880d681SAndroid Build Coastguard Worker protector. This attribute causes a strong heuristic to be used when 1558*9880d681SAndroid Build Coastguard Worker determining if a function needs stack protectors. The strong heuristic 1559*9880d681SAndroid Build Coastguard Worker will enable protectors for functions with: 1560*9880d681SAndroid Build Coastguard Worker 1561*9880d681SAndroid Build Coastguard Worker - Arrays of any size and type 1562*9880d681SAndroid Build Coastguard Worker - Aggregates containing an array of any size and type. 1563*9880d681SAndroid Build Coastguard Worker - Calls to alloca(). 1564*9880d681SAndroid Build Coastguard Worker - Local variables that have had their address taken. 1565*9880d681SAndroid Build Coastguard Worker 1566*9880d681SAndroid Build Coastguard Worker Variables that are identified as requiring a protector will be arranged 1567*9880d681SAndroid Build Coastguard Worker on the stack such that they are adjacent to the stack protector guard. 1568*9880d681SAndroid Build Coastguard Worker The specific layout rules are: 1569*9880d681SAndroid Build Coastguard Worker 1570*9880d681SAndroid Build Coastguard Worker #. Large arrays and structures containing large arrays 1571*9880d681SAndroid Build Coastguard Worker (``>= ssp-buffer-size``) are closest to the stack protector. 1572*9880d681SAndroid Build Coastguard Worker #. Small arrays and structures containing small arrays 1573*9880d681SAndroid Build Coastguard Worker (``< ssp-buffer-size``) are 2nd closest to the protector. 1574*9880d681SAndroid Build Coastguard Worker #. Variables that have had their address taken are 3rd closest to the 1575*9880d681SAndroid Build Coastguard Worker protector. 1576*9880d681SAndroid Build Coastguard Worker 1577*9880d681SAndroid Build Coastguard Worker This overrides the ``ssp`` function attribute. 1578*9880d681SAndroid Build Coastguard Worker 1579*9880d681SAndroid Build Coastguard Worker If a function that has an ``sspstrong`` attribute is inlined into a 1580*9880d681SAndroid Build Coastguard Worker function that doesn't have an ``sspstrong`` attribute, then the 1581*9880d681SAndroid Build Coastguard Worker resulting function will have an ``sspstrong`` attribute. 1582*9880d681SAndroid Build Coastguard Worker``"thunk"`` 1583*9880d681SAndroid Build Coastguard Worker This attribute indicates that the function will delegate to some other 1584*9880d681SAndroid Build Coastguard Worker function with a tail call. The prototype of a thunk should not be used for 1585*9880d681SAndroid Build Coastguard Worker optimization purposes. The caller is expected to cast the thunk prototype to 1586*9880d681SAndroid Build Coastguard Worker match the thunk target prototype. 1587*9880d681SAndroid Build Coastguard Worker``uwtable`` 1588*9880d681SAndroid Build Coastguard Worker This attribute indicates that the ABI being targeted requires that 1589*9880d681SAndroid Build Coastguard Worker an unwind table entry be produced for this function even if we can 1590*9880d681SAndroid Build Coastguard Worker show that no exceptions passes by it. This is normally the case for 1591*9880d681SAndroid Build Coastguard Worker the ELF x86-64 abi, but it can be disabled for some compilation 1592*9880d681SAndroid Build Coastguard Worker units. 1593*9880d681SAndroid Build Coastguard Worker 1594*9880d681SAndroid Build Coastguard Worker 1595*9880d681SAndroid Build Coastguard Worker.. _opbundles: 1596*9880d681SAndroid Build Coastguard Worker 1597*9880d681SAndroid Build Coastguard WorkerOperand Bundles 1598*9880d681SAndroid Build Coastguard Worker--------------- 1599*9880d681SAndroid Build Coastguard Worker 1600*9880d681SAndroid Build Coastguard WorkerNote: operand bundles are a work in progress, and they should be 1601*9880d681SAndroid Build Coastguard Workerconsidered experimental at this time. 1602*9880d681SAndroid Build Coastguard Worker 1603*9880d681SAndroid Build Coastguard WorkerOperand bundles are tagged sets of SSA values that can be associated 1604*9880d681SAndroid Build Coastguard Workerwith certain LLVM instructions (currently only ``call`` s and 1605*9880d681SAndroid Build Coastguard Worker``invoke`` s). In a way they are like metadata, but dropping them is 1606*9880d681SAndroid Build Coastguard Workerincorrect and will change program semantics. 1607*9880d681SAndroid Build Coastguard Worker 1608*9880d681SAndroid Build Coastguard WorkerSyntax:: 1609*9880d681SAndroid Build Coastguard Worker 1610*9880d681SAndroid Build Coastguard Worker operand bundle set ::= '[' operand bundle (, operand bundle )* ']' 1611*9880d681SAndroid Build Coastguard Worker operand bundle ::= tag '(' [ bundle operand ] (, bundle operand )* ')' 1612*9880d681SAndroid Build Coastguard Worker bundle operand ::= SSA value 1613*9880d681SAndroid Build Coastguard Worker tag ::= string constant 1614*9880d681SAndroid Build Coastguard Worker 1615*9880d681SAndroid Build Coastguard WorkerOperand bundles are **not** part of a function's signature, and a 1616*9880d681SAndroid Build Coastguard Workergiven function may be called from multiple places with different kinds 1617*9880d681SAndroid Build Coastguard Workerof operand bundles. This reflects the fact that the operand bundles 1618*9880d681SAndroid Build Coastguard Workerare conceptually a part of the ``call`` (or ``invoke``), not the 1619*9880d681SAndroid Build Coastguard Workercallee being dispatched to. 1620*9880d681SAndroid Build Coastguard Worker 1621*9880d681SAndroid Build Coastguard WorkerOperand bundles are a generic mechanism intended to support 1622*9880d681SAndroid Build Coastguard Workerruntime-introspection-like functionality for managed languages. While 1623*9880d681SAndroid Build Coastguard Workerthe exact semantics of an operand bundle depend on the bundle tag, 1624*9880d681SAndroid Build Coastguard Workerthere are certain limitations to how much the presence of an operand 1625*9880d681SAndroid Build Coastguard Workerbundle can influence the semantics of a program. These restrictions 1626*9880d681SAndroid Build Coastguard Workerare described as the semantics of an "unknown" operand bundle. As 1627*9880d681SAndroid Build Coastguard Workerlong as the behavior of an operand bundle is describable within these 1628*9880d681SAndroid Build Coastguard Workerrestrictions, LLVM does not need to have special knowledge of the 1629*9880d681SAndroid Build Coastguard Workeroperand bundle to not miscompile programs containing it. 1630*9880d681SAndroid Build Coastguard Worker 1631*9880d681SAndroid Build Coastguard Worker- The bundle operands for an unknown operand bundle escape in unknown 1632*9880d681SAndroid Build Coastguard Worker ways before control is transferred to the callee or invokee. 1633*9880d681SAndroid Build Coastguard Worker- Calls and invokes with operand bundles have unknown read / write 1634*9880d681SAndroid Build Coastguard Worker effect on the heap on entry and exit (even if the call target is 1635*9880d681SAndroid Build Coastguard Worker ``readnone`` or ``readonly``), unless they're overridden with 1636*9880d681SAndroid Build Coastguard Worker callsite specific attributes. 1637*9880d681SAndroid Build Coastguard Worker- An operand bundle at a call site cannot change the implementation 1638*9880d681SAndroid Build Coastguard Worker of the called function. Inter-procedural optimizations work as 1639*9880d681SAndroid Build Coastguard Worker usual as long as they take into account the first two properties. 1640*9880d681SAndroid Build Coastguard Worker 1641*9880d681SAndroid Build Coastguard WorkerMore specific types of operand bundles are described below. 1642*9880d681SAndroid Build Coastguard Worker 1643*9880d681SAndroid Build Coastguard Worker.. _deopt_opbundles: 1644*9880d681SAndroid Build Coastguard Worker 1645*9880d681SAndroid Build Coastguard WorkerDeoptimization Operand Bundles 1646*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 1647*9880d681SAndroid Build Coastguard Worker 1648*9880d681SAndroid Build Coastguard WorkerDeoptimization operand bundles are characterized by the ``"deopt"`` 1649*9880d681SAndroid Build Coastguard Workeroperand bundle tag. These operand bundles represent an alternate 1650*9880d681SAndroid Build Coastguard Worker"safe" continuation for the call site they're attached to, and can be 1651*9880d681SAndroid Build Coastguard Workerused by a suitable runtime to deoptimize the compiled frame at the 1652*9880d681SAndroid Build Coastguard Workerspecified call site. There can be at most one ``"deopt"`` operand 1653*9880d681SAndroid Build Coastguard Workerbundle attached to a call site. Exact details of deoptimization is 1654*9880d681SAndroid Build Coastguard Workerout of scope for the language reference, but it usually involves 1655*9880d681SAndroid Build Coastguard Workerrewriting a compiled frame into a set of interpreted frames. 1656*9880d681SAndroid Build Coastguard Worker 1657*9880d681SAndroid Build Coastguard WorkerFrom the compiler's perspective, deoptimization operand bundles make 1658*9880d681SAndroid Build Coastguard Workerthe call sites they're attached to at least ``readonly``. They read 1659*9880d681SAndroid Build Coastguard Workerthrough all of their pointer typed operands (even if they're not 1660*9880d681SAndroid Build Coastguard Workerotherwise escaped) and the entire visible heap. Deoptimization 1661*9880d681SAndroid Build Coastguard Workeroperand bundles do not capture their operands except during 1662*9880d681SAndroid Build Coastguard Workerdeoptimization, in which case control will not be returned to the 1663*9880d681SAndroid Build Coastguard Workercompiled frame. 1664*9880d681SAndroid Build Coastguard Worker 1665*9880d681SAndroid Build Coastguard WorkerThe inliner knows how to inline through calls that have deoptimization 1666*9880d681SAndroid Build Coastguard Workeroperand bundles. Just like inlining through a normal call site 1667*9880d681SAndroid Build Coastguard Workerinvolves composing the normal and exceptional continuations, inlining 1668*9880d681SAndroid Build Coastguard Workerthrough a call site with a deoptimization operand bundle needs to 1669*9880d681SAndroid Build Coastguard Workerappropriately compose the "safe" deoptimization continuation. The 1670*9880d681SAndroid Build Coastguard Workerinliner does this by prepending the parent's deoptimization 1671*9880d681SAndroid Build Coastguard Workercontinuation to every deoptimization continuation in the inlined body. 1672*9880d681SAndroid Build Coastguard WorkerE.g. inlining ``@f`` into ``@g`` in the following example 1673*9880d681SAndroid Build Coastguard Worker 1674*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 1675*9880d681SAndroid Build Coastguard Worker 1676*9880d681SAndroid Build Coastguard Worker define void @f() { 1677*9880d681SAndroid Build Coastguard Worker call void @x() ;; no deopt state 1678*9880d681SAndroid Build Coastguard Worker call void @y() [ "deopt"(i32 10) ] 1679*9880d681SAndroid Build Coastguard Worker call void @y() [ "deopt"(i32 10), "unknown"(i8* null) ] 1680*9880d681SAndroid Build Coastguard Worker ret void 1681*9880d681SAndroid Build Coastguard Worker } 1682*9880d681SAndroid Build Coastguard Worker 1683*9880d681SAndroid Build Coastguard Worker define void @g() { 1684*9880d681SAndroid Build Coastguard Worker call void @f() [ "deopt"(i32 20) ] 1685*9880d681SAndroid Build Coastguard Worker ret void 1686*9880d681SAndroid Build Coastguard Worker } 1687*9880d681SAndroid Build Coastguard Worker 1688*9880d681SAndroid Build Coastguard Workerwill result in 1689*9880d681SAndroid Build Coastguard Worker 1690*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 1691*9880d681SAndroid Build Coastguard Worker 1692*9880d681SAndroid Build Coastguard Worker define void @g() { 1693*9880d681SAndroid Build Coastguard Worker call void @x() ;; still no deopt state 1694*9880d681SAndroid Build Coastguard Worker call void @y() [ "deopt"(i32 20, i32 10) ] 1695*9880d681SAndroid Build Coastguard Worker call void @y() [ "deopt"(i32 20, i32 10), "unknown"(i8* null) ] 1696*9880d681SAndroid Build Coastguard Worker ret void 1697*9880d681SAndroid Build Coastguard Worker } 1698*9880d681SAndroid Build Coastguard Worker 1699*9880d681SAndroid Build Coastguard WorkerIt is the frontend's responsibility to structure or encode the 1700*9880d681SAndroid Build Coastguard Workerdeoptimization state in a way that syntactically prepending the 1701*9880d681SAndroid Build Coastguard Workercaller's deoptimization state to the callee's deoptimization state is 1702*9880d681SAndroid Build Coastguard Workersemantically equivalent to composing the caller's deoptimization 1703*9880d681SAndroid Build Coastguard Workercontinuation after the callee's deoptimization continuation. 1704*9880d681SAndroid Build Coastguard Worker 1705*9880d681SAndroid Build Coastguard Worker.. _ob_funclet: 1706*9880d681SAndroid Build Coastguard Worker 1707*9880d681SAndroid Build Coastguard WorkerFunclet Operand Bundles 1708*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^ 1709*9880d681SAndroid Build Coastguard Worker 1710*9880d681SAndroid Build Coastguard WorkerFunclet operand bundles are characterized by the ``"funclet"`` 1711*9880d681SAndroid Build Coastguard Workeroperand bundle tag. These operand bundles indicate that a call site 1712*9880d681SAndroid Build Coastguard Workeris within a particular funclet. There can be at most one 1713*9880d681SAndroid Build Coastguard Worker``"funclet"`` operand bundle attached to a call site and it must have 1714*9880d681SAndroid Build Coastguard Workerexactly one bundle operand. 1715*9880d681SAndroid Build Coastguard Worker 1716*9880d681SAndroid Build Coastguard WorkerIf any funclet EH pads have been "entered" but not "exited" (per the 1717*9880d681SAndroid Build Coastguard Worker`description in the EH doc\ <ExceptionHandling.html#wineh-constraints>`_), 1718*9880d681SAndroid Build Coastguard Workerit is undefined behavior to execute a ``call`` or ``invoke`` which: 1719*9880d681SAndroid Build Coastguard Worker 1720*9880d681SAndroid Build Coastguard Worker* does not have a ``"funclet"`` bundle and is not a ``call`` to a nounwind 1721*9880d681SAndroid Build Coastguard Worker intrinsic, or 1722*9880d681SAndroid Build Coastguard Worker* has a ``"funclet"`` bundle whose operand is not the most-recently-entered 1723*9880d681SAndroid Build Coastguard Worker not-yet-exited funclet EH pad. 1724*9880d681SAndroid Build Coastguard Worker 1725*9880d681SAndroid Build Coastguard WorkerSimilarly, if no funclet EH pads have been entered-but-not-yet-exited, 1726*9880d681SAndroid Build Coastguard Workerexecuting a ``call`` or ``invoke`` with a ``"funclet"`` bundle is undefined behavior. 1727*9880d681SAndroid Build Coastguard Worker 1728*9880d681SAndroid Build Coastguard WorkerGC Transition Operand Bundles 1729*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 1730*9880d681SAndroid Build Coastguard Worker 1731*9880d681SAndroid Build Coastguard WorkerGC transition operand bundles are characterized by the 1732*9880d681SAndroid Build Coastguard Worker``"gc-transition"`` operand bundle tag. These operand bundles mark a 1733*9880d681SAndroid Build Coastguard Workercall as a transition between a function with one GC strategy to a 1734*9880d681SAndroid Build Coastguard Workerfunction with a different GC strategy. If coordinating the transition 1735*9880d681SAndroid Build Coastguard Workerbetween GC strategies requires additional code generation at the call 1736*9880d681SAndroid Build Coastguard Workersite, these bundles may contain any values that are needed by the 1737*9880d681SAndroid Build Coastguard Workergenerated code. For more details, see :ref:`GC Transitions 1738*9880d681SAndroid Build Coastguard Worker<gc_transition_args>`. 1739*9880d681SAndroid Build Coastguard Worker 1740*9880d681SAndroid Build Coastguard Worker.. _moduleasm: 1741*9880d681SAndroid Build Coastguard Worker 1742*9880d681SAndroid Build Coastguard WorkerModule-Level Inline Assembly 1743*9880d681SAndroid Build Coastguard Worker---------------------------- 1744*9880d681SAndroid Build Coastguard Worker 1745*9880d681SAndroid Build Coastguard WorkerModules may contain "module-level inline asm" blocks, which corresponds 1746*9880d681SAndroid Build Coastguard Workerto the GCC "file scope inline asm" blocks. These blocks are internally 1747*9880d681SAndroid Build Coastguard Workerconcatenated by LLVM and treated as a single unit, but may be separated 1748*9880d681SAndroid Build Coastguard Workerin the ``.ll`` file if desired. The syntax is very simple: 1749*9880d681SAndroid Build Coastguard Worker 1750*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 1751*9880d681SAndroid Build Coastguard Worker 1752*9880d681SAndroid Build Coastguard Worker module asm "inline asm code goes here" 1753*9880d681SAndroid Build Coastguard Worker module asm "more can go here" 1754*9880d681SAndroid Build Coastguard Worker 1755*9880d681SAndroid Build Coastguard WorkerThe strings can contain any character by escaping non-printable 1756*9880d681SAndroid Build Coastguard Workercharacters. The escape sequence used is simply "\\xx" where "xx" is the 1757*9880d681SAndroid Build Coastguard Workertwo digit hex code for the number. 1758*9880d681SAndroid Build Coastguard Worker 1759*9880d681SAndroid Build Coastguard WorkerNote that the assembly string *must* be parseable by LLVM's integrated assembler 1760*9880d681SAndroid Build Coastguard Worker(unless it is disabled), even when emitting a ``.s`` file. 1761*9880d681SAndroid Build Coastguard Worker 1762*9880d681SAndroid Build Coastguard Worker.. _langref_datalayout: 1763*9880d681SAndroid Build Coastguard Worker 1764*9880d681SAndroid Build Coastguard WorkerData Layout 1765*9880d681SAndroid Build Coastguard Worker----------- 1766*9880d681SAndroid Build Coastguard Worker 1767*9880d681SAndroid Build Coastguard WorkerA module may specify a target specific data layout string that specifies 1768*9880d681SAndroid Build Coastguard Workerhow data is to be laid out in memory. The syntax for the data layout is 1769*9880d681SAndroid Build Coastguard Workersimply: 1770*9880d681SAndroid Build Coastguard Worker 1771*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 1772*9880d681SAndroid Build Coastguard Worker 1773*9880d681SAndroid Build Coastguard Worker target datalayout = "layout specification" 1774*9880d681SAndroid Build Coastguard Worker 1775*9880d681SAndroid Build Coastguard WorkerThe *layout specification* consists of a list of specifications 1776*9880d681SAndroid Build Coastguard Workerseparated by the minus sign character ('-'). Each specification starts 1777*9880d681SAndroid Build Coastguard Workerwith a letter and may include other information after the letter to 1778*9880d681SAndroid Build Coastguard Workerdefine some aspect of the data layout. The specifications accepted are 1779*9880d681SAndroid Build Coastguard Workeras follows: 1780*9880d681SAndroid Build Coastguard Worker 1781*9880d681SAndroid Build Coastguard Worker``E`` 1782*9880d681SAndroid Build Coastguard Worker Specifies that the target lays out data in big-endian form. That is, 1783*9880d681SAndroid Build Coastguard Worker the bits with the most significance have the lowest address 1784*9880d681SAndroid Build Coastguard Worker location. 1785*9880d681SAndroid Build Coastguard Worker``e`` 1786*9880d681SAndroid Build Coastguard Worker Specifies that the target lays out data in little-endian form. That 1787*9880d681SAndroid Build Coastguard Worker is, the bits with the least significance have the lowest address 1788*9880d681SAndroid Build Coastguard Worker location. 1789*9880d681SAndroid Build Coastguard Worker``S<size>`` 1790*9880d681SAndroid Build Coastguard Worker Specifies the natural alignment of the stack in bits. Alignment 1791*9880d681SAndroid Build Coastguard Worker promotion of stack variables is limited to the natural stack 1792*9880d681SAndroid Build Coastguard Worker alignment to avoid dynamic stack realignment. The stack alignment 1793*9880d681SAndroid Build Coastguard Worker must be a multiple of 8-bits. If omitted, the natural stack 1794*9880d681SAndroid Build Coastguard Worker alignment defaults to "unspecified", which does not prevent any 1795*9880d681SAndroid Build Coastguard Worker alignment promotions. 1796*9880d681SAndroid Build Coastguard Worker``p[n]:<size>:<abi>:<pref>`` 1797*9880d681SAndroid Build Coastguard Worker This specifies the *size* of a pointer and its ``<abi>`` and 1798*9880d681SAndroid Build Coastguard Worker ``<pref>``\erred alignments for address space ``n``. All sizes are in 1799*9880d681SAndroid Build Coastguard Worker bits. The address space, ``n``, is optional, and if not specified, 1800*9880d681SAndroid Build Coastguard Worker denotes the default address space 0. The value of ``n`` must be 1801*9880d681SAndroid Build Coastguard Worker in the range [1,2^23). 1802*9880d681SAndroid Build Coastguard Worker``i<size>:<abi>:<pref>`` 1803*9880d681SAndroid Build Coastguard Worker This specifies the alignment for an integer type of a given bit 1804*9880d681SAndroid Build Coastguard Worker ``<size>``. The value of ``<size>`` must be in the range [1,2^23). 1805*9880d681SAndroid Build Coastguard Worker``v<size>:<abi>:<pref>`` 1806*9880d681SAndroid Build Coastguard Worker This specifies the alignment for a vector type of a given bit 1807*9880d681SAndroid Build Coastguard Worker ``<size>``. 1808*9880d681SAndroid Build Coastguard Worker``f<size>:<abi>:<pref>`` 1809*9880d681SAndroid Build Coastguard Worker This specifies the alignment for a floating point type of a given bit 1810*9880d681SAndroid Build Coastguard Worker ``<size>``. Only values of ``<size>`` that are supported by the target 1811*9880d681SAndroid Build Coastguard Worker will work. 32 (float) and 64 (double) are supported on all targets; 80 1812*9880d681SAndroid Build Coastguard Worker or 128 (different flavors of long double) are also supported on some 1813*9880d681SAndroid Build Coastguard Worker targets. 1814*9880d681SAndroid Build Coastguard Worker``a:<abi>:<pref>`` 1815*9880d681SAndroid Build Coastguard Worker This specifies the alignment for an object of aggregate type. 1816*9880d681SAndroid Build Coastguard Worker``m:<mangling>`` 1817*9880d681SAndroid Build Coastguard Worker If present, specifies that llvm names are mangled in the output. The 1818*9880d681SAndroid Build Coastguard Worker options are 1819*9880d681SAndroid Build Coastguard Worker 1820*9880d681SAndroid Build Coastguard Worker * ``e``: ELF mangling: Private symbols get a ``.L`` prefix. 1821*9880d681SAndroid Build Coastguard Worker * ``m``: Mips mangling: Private symbols get a ``$`` prefix. 1822*9880d681SAndroid Build Coastguard Worker * ``o``: Mach-O mangling: Private symbols get ``L`` prefix. Other 1823*9880d681SAndroid Build Coastguard Worker symbols get a ``_`` prefix. 1824*9880d681SAndroid Build Coastguard Worker * ``w``: Windows COFF prefix: Similar to Mach-O, but stdcall and fastcall 1825*9880d681SAndroid Build Coastguard Worker functions also get a suffix based on the frame size. 1826*9880d681SAndroid Build Coastguard Worker * ``x``: Windows x86 COFF prefix: Similar to Windows COFF, but use a ``_`` 1827*9880d681SAndroid Build Coastguard Worker prefix for ``__cdecl`` functions. 1828*9880d681SAndroid Build Coastguard Worker``n<size1>:<size2>:<size3>...`` 1829*9880d681SAndroid Build Coastguard Worker This specifies a set of native integer widths for the target CPU in 1830*9880d681SAndroid Build Coastguard Worker bits. For example, it might contain ``n32`` for 32-bit PowerPC, 1831*9880d681SAndroid Build Coastguard Worker ``n32:64`` for PowerPC 64, or ``n8:16:32:64`` for X86-64. Elements of 1832*9880d681SAndroid Build Coastguard Worker this set are considered to support most general arithmetic operations 1833*9880d681SAndroid Build Coastguard Worker efficiently. 1834*9880d681SAndroid Build Coastguard Worker 1835*9880d681SAndroid Build Coastguard WorkerOn every specification that takes a ``<abi>:<pref>``, specifying the 1836*9880d681SAndroid Build Coastguard Worker``<pref>`` alignment is optional. If omitted, the preceding ``:`` 1837*9880d681SAndroid Build Coastguard Workershould be omitted too and ``<pref>`` will be equal to ``<abi>``. 1838*9880d681SAndroid Build Coastguard Worker 1839*9880d681SAndroid Build Coastguard WorkerWhen constructing the data layout for a given target, LLVM starts with a 1840*9880d681SAndroid Build Coastguard Workerdefault set of specifications which are then (possibly) overridden by 1841*9880d681SAndroid Build Coastguard Workerthe specifications in the ``datalayout`` keyword. The default 1842*9880d681SAndroid Build Coastguard Workerspecifications are given in this list: 1843*9880d681SAndroid Build Coastguard Worker 1844*9880d681SAndroid Build Coastguard Worker- ``E`` - big endian 1845*9880d681SAndroid Build Coastguard Worker- ``p:64:64:64`` - 64-bit pointers with 64-bit alignment. 1846*9880d681SAndroid Build Coastguard Worker- ``p[n]:64:64:64`` - Other address spaces are assumed to be the 1847*9880d681SAndroid Build Coastguard Worker same as the default address space. 1848*9880d681SAndroid Build Coastguard Worker- ``S0`` - natural stack alignment is unspecified 1849*9880d681SAndroid Build Coastguard Worker- ``i1:8:8`` - i1 is 8-bit (byte) aligned 1850*9880d681SAndroid Build Coastguard Worker- ``i8:8:8`` - i8 is 8-bit (byte) aligned 1851*9880d681SAndroid Build Coastguard Worker- ``i16:16:16`` - i16 is 16-bit aligned 1852*9880d681SAndroid Build Coastguard Worker- ``i32:32:32`` - i32 is 32-bit aligned 1853*9880d681SAndroid Build Coastguard Worker- ``i64:32:64`` - i64 has ABI alignment of 32-bits but preferred 1854*9880d681SAndroid Build Coastguard Worker alignment of 64-bits 1855*9880d681SAndroid Build Coastguard Worker- ``f16:16:16`` - half is 16-bit aligned 1856*9880d681SAndroid Build Coastguard Worker- ``f32:32:32`` - float is 32-bit aligned 1857*9880d681SAndroid Build Coastguard Worker- ``f64:64:64`` - double is 64-bit aligned 1858*9880d681SAndroid Build Coastguard Worker- ``f128:128:128`` - quad is 128-bit aligned 1859*9880d681SAndroid Build Coastguard Worker- ``v64:64:64`` - 64-bit vector is 64-bit aligned 1860*9880d681SAndroid Build Coastguard Worker- ``v128:128:128`` - 128-bit vector is 128-bit aligned 1861*9880d681SAndroid Build Coastguard Worker- ``a:0:64`` - aggregates are 64-bit aligned 1862*9880d681SAndroid Build Coastguard Worker 1863*9880d681SAndroid Build Coastguard WorkerWhen LLVM is determining the alignment for a given type, it uses the 1864*9880d681SAndroid Build Coastguard Workerfollowing rules: 1865*9880d681SAndroid Build Coastguard Worker 1866*9880d681SAndroid Build Coastguard Worker#. If the type sought is an exact match for one of the specifications, 1867*9880d681SAndroid Build Coastguard Worker that specification is used. 1868*9880d681SAndroid Build Coastguard Worker#. If no match is found, and the type sought is an integer type, then 1869*9880d681SAndroid Build Coastguard Worker the smallest integer type that is larger than the bitwidth of the 1870*9880d681SAndroid Build Coastguard Worker sought type is used. If none of the specifications are larger than 1871*9880d681SAndroid Build Coastguard Worker the bitwidth then the largest integer type is used. For example, 1872*9880d681SAndroid Build Coastguard Worker given the default specifications above, the i7 type will use the 1873*9880d681SAndroid Build Coastguard Worker alignment of i8 (next largest) while both i65 and i256 will use the 1874*9880d681SAndroid Build Coastguard Worker alignment of i64 (largest specified). 1875*9880d681SAndroid Build Coastguard Worker#. If no match is found, and the type sought is a vector type, then the 1876*9880d681SAndroid Build Coastguard Worker largest vector type that is smaller than the sought vector type will 1877*9880d681SAndroid Build Coastguard Worker be used as a fall back. This happens because <128 x double> can be 1878*9880d681SAndroid Build Coastguard Worker implemented in terms of 64 <2 x double>, for example. 1879*9880d681SAndroid Build Coastguard Worker 1880*9880d681SAndroid Build Coastguard WorkerThe function of the data layout string may not be what you expect. 1881*9880d681SAndroid Build Coastguard WorkerNotably, this is not a specification from the frontend of what alignment 1882*9880d681SAndroid Build Coastguard Workerthe code generator should use. 1883*9880d681SAndroid Build Coastguard Worker 1884*9880d681SAndroid Build Coastguard WorkerInstead, if specified, the target data layout is required to match what 1885*9880d681SAndroid Build Coastguard Workerthe ultimate *code generator* expects. This string is used by the 1886*9880d681SAndroid Build Coastguard Workermid-level optimizers to improve code, and this only works if it matches 1887*9880d681SAndroid Build Coastguard Workerwhat the ultimate code generator uses. There is no way to generate IR 1888*9880d681SAndroid Build Coastguard Workerthat does not embed this target-specific detail into the IR. If you 1889*9880d681SAndroid Build Coastguard Workerdon't specify the string, the default specifications will be used to 1890*9880d681SAndroid Build Coastguard Workergenerate a Data Layout and the optimization phases will operate 1891*9880d681SAndroid Build Coastguard Workeraccordingly and introduce target specificity into the IR with respect to 1892*9880d681SAndroid Build Coastguard Workerthese default specifications. 1893*9880d681SAndroid Build Coastguard Worker 1894*9880d681SAndroid Build Coastguard Worker.. _langref_triple: 1895*9880d681SAndroid Build Coastguard Worker 1896*9880d681SAndroid Build Coastguard WorkerTarget Triple 1897*9880d681SAndroid Build Coastguard Worker------------- 1898*9880d681SAndroid Build Coastguard Worker 1899*9880d681SAndroid Build Coastguard WorkerA module may specify a target triple string that describes the target 1900*9880d681SAndroid Build Coastguard Workerhost. The syntax for the target triple is simply: 1901*9880d681SAndroid Build Coastguard Worker 1902*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 1903*9880d681SAndroid Build Coastguard Worker 1904*9880d681SAndroid Build Coastguard Worker target triple = "x86_64-apple-macosx10.7.0" 1905*9880d681SAndroid Build Coastguard Worker 1906*9880d681SAndroid Build Coastguard WorkerThe *target triple* string consists of a series of identifiers delimited 1907*9880d681SAndroid Build Coastguard Workerby the minus sign character ('-'). The canonical forms are: 1908*9880d681SAndroid Build Coastguard Worker 1909*9880d681SAndroid Build Coastguard Worker:: 1910*9880d681SAndroid Build Coastguard Worker 1911*9880d681SAndroid Build Coastguard Worker ARCHITECTURE-VENDOR-OPERATING_SYSTEM 1912*9880d681SAndroid Build Coastguard Worker ARCHITECTURE-VENDOR-OPERATING_SYSTEM-ENVIRONMENT 1913*9880d681SAndroid Build Coastguard Worker 1914*9880d681SAndroid Build Coastguard WorkerThis information is passed along to the backend so that it generates 1915*9880d681SAndroid Build Coastguard Workercode for the proper architecture. It's possible to override this on the 1916*9880d681SAndroid Build Coastguard Workercommand line with the ``-mtriple`` command line option. 1917*9880d681SAndroid Build Coastguard Worker 1918*9880d681SAndroid Build Coastguard Worker.. _pointeraliasing: 1919*9880d681SAndroid Build Coastguard Worker 1920*9880d681SAndroid Build Coastguard WorkerPointer Aliasing Rules 1921*9880d681SAndroid Build Coastguard Worker---------------------- 1922*9880d681SAndroid Build Coastguard Worker 1923*9880d681SAndroid Build Coastguard WorkerAny memory access must be done through a pointer value associated with 1924*9880d681SAndroid Build Coastguard Workeran address range of the memory access, otherwise the behavior is 1925*9880d681SAndroid Build Coastguard Workerundefined. Pointer values are associated with address ranges according 1926*9880d681SAndroid Build Coastguard Workerto the following rules: 1927*9880d681SAndroid Build Coastguard Worker 1928*9880d681SAndroid Build Coastguard Worker- A pointer value is associated with the addresses associated with any 1929*9880d681SAndroid Build Coastguard Worker value it is *based* on. 1930*9880d681SAndroid Build Coastguard Worker- An address of a global variable is associated with the address range 1931*9880d681SAndroid Build Coastguard Worker of the variable's storage. 1932*9880d681SAndroid Build Coastguard Worker- The result value of an allocation instruction is associated with the 1933*9880d681SAndroid Build Coastguard Worker address range of the allocated storage. 1934*9880d681SAndroid Build Coastguard Worker- A null pointer in the default address-space is associated with no 1935*9880d681SAndroid Build Coastguard Worker address. 1936*9880d681SAndroid Build Coastguard Worker- An integer constant other than zero or a pointer value returned from 1937*9880d681SAndroid Build Coastguard Worker a function not defined within LLVM may be associated with address 1938*9880d681SAndroid Build Coastguard Worker ranges allocated through mechanisms other than those provided by 1939*9880d681SAndroid Build Coastguard Worker LLVM. Such ranges shall not overlap with any ranges of addresses 1940*9880d681SAndroid Build Coastguard Worker allocated by mechanisms provided by LLVM. 1941*9880d681SAndroid Build Coastguard Worker 1942*9880d681SAndroid Build Coastguard WorkerA pointer value is *based* on another pointer value according to the 1943*9880d681SAndroid Build Coastguard Workerfollowing rules: 1944*9880d681SAndroid Build Coastguard Worker 1945*9880d681SAndroid Build Coastguard Worker- A pointer value formed from a ``getelementptr`` operation is *based* 1946*9880d681SAndroid Build Coastguard Worker on the first value operand of the ``getelementptr``. 1947*9880d681SAndroid Build Coastguard Worker- The result value of a ``bitcast`` is *based* on the operand of the 1948*9880d681SAndroid Build Coastguard Worker ``bitcast``. 1949*9880d681SAndroid Build Coastguard Worker- A pointer value formed by an ``inttoptr`` is *based* on all pointer 1950*9880d681SAndroid Build Coastguard Worker values that contribute (directly or indirectly) to the computation of 1951*9880d681SAndroid Build Coastguard Worker the pointer's value. 1952*9880d681SAndroid Build Coastguard Worker- The "*based* on" relationship is transitive. 1953*9880d681SAndroid Build Coastguard Worker 1954*9880d681SAndroid Build Coastguard WorkerNote that this definition of *"based"* is intentionally similar to the 1955*9880d681SAndroid Build Coastguard Workerdefinition of *"based"* in C99, though it is slightly weaker. 1956*9880d681SAndroid Build Coastguard Worker 1957*9880d681SAndroid Build Coastguard WorkerLLVM IR does not associate types with memory. The result type of a 1958*9880d681SAndroid Build Coastguard Worker``load`` merely indicates the size and alignment of the memory from 1959*9880d681SAndroid Build Coastguard Workerwhich to load, as well as the interpretation of the value. The first 1960*9880d681SAndroid Build Coastguard Workeroperand type of a ``store`` similarly only indicates the size and 1961*9880d681SAndroid Build Coastguard Workeralignment of the store. 1962*9880d681SAndroid Build Coastguard Worker 1963*9880d681SAndroid Build Coastguard WorkerConsequently, type-based alias analysis, aka TBAA, aka 1964*9880d681SAndroid Build Coastguard Worker``-fstrict-aliasing``, is not applicable to general unadorned LLVM IR. 1965*9880d681SAndroid Build Coastguard Worker:ref:`Metadata <metadata>` may be used to encode additional information 1966*9880d681SAndroid Build Coastguard Workerwhich specialized optimization passes may use to implement type-based 1967*9880d681SAndroid Build Coastguard Workeralias analysis. 1968*9880d681SAndroid Build Coastguard Worker 1969*9880d681SAndroid Build Coastguard Worker.. _volatile: 1970*9880d681SAndroid Build Coastguard Worker 1971*9880d681SAndroid Build Coastguard WorkerVolatile Memory Accesses 1972*9880d681SAndroid Build Coastguard Worker------------------------ 1973*9880d681SAndroid Build Coastguard Worker 1974*9880d681SAndroid Build Coastguard WorkerCertain memory accesses, such as :ref:`load <i_load>`'s, 1975*9880d681SAndroid Build Coastguard Worker:ref:`store <i_store>`'s, and :ref:`llvm.memcpy <int_memcpy>`'s may be 1976*9880d681SAndroid Build Coastguard Workermarked ``volatile``. The optimizers must not change the number of 1977*9880d681SAndroid Build Coastguard Workervolatile operations or change their order of execution relative to other 1978*9880d681SAndroid Build Coastguard Workervolatile operations. The optimizers *may* change the order of volatile 1979*9880d681SAndroid Build Coastguard Workeroperations relative to non-volatile operations. This is not Java's 1980*9880d681SAndroid Build Coastguard Worker"volatile" and has no cross-thread synchronization behavior. 1981*9880d681SAndroid Build Coastguard Worker 1982*9880d681SAndroid Build Coastguard WorkerIR-level volatile loads and stores cannot safely be optimized into 1983*9880d681SAndroid Build Coastguard Workerllvm.memcpy or llvm.memmove intrinsics even when those intrinsics are 1984*9880d681SAndroid Build Coastguard Workerflagged volatile. Likewise, the backend should never split or merge 1985*9880d681SAndroid Build Coastguard Workertarget-legal volatile load/store instructions. 1986*9880d681SAndroid Build Coastguard Worker 1987*9880d681SAndroid Build Coastguard Worker.. admonition:: Rationale 1988*9880d681SAndroid Build Coastguard Worker 1989*9880d681SAndroid Build Coastguard Worker Platforms may rely on volatile loads and stores of natively supported 1990*9880d681SAndroid Build Coastguard Worker data width to be executed as single instruction. For example, in C 1991*9880d681SAndroid Build Coastguard Worker this holds for an l-value of volatile primitive type with native 1992*9880d681SAndroid Build Coastguard Worker hardware support, but not necessarily for aggregate types. The 1993*9880d681SAndroid Build Coastguard Worker frontend upholds these expectations, which are intentionally 1994*9880d681SAndroid Build Coastguard Worker unspecified in the IR. The rules above ensure that IR transformations 1995*9880d681SAndroid Build Coastguard Worker do not violate the frontend's contract with the language. 1996*9880d681SAndroid Build Coastguard Worker 1997*9880d681SAndroid Build Coastguard Worker.. _memmodel: 1998*9880d681SAndroid Build Coastguard Worker 1999*9880d681SAndroid Build Coastguard WorkerMemory Model for Concurrent Operations 2000*9880d681SAndroid Build Coastguard Worker-------------------------------------- 2001*9880d681SAndroid Build Coastguard Worker 2002*9880d681SAndroid Build Coastguard WorkerThe LLVM IR does not define any way to start parallel threads of 2003*9880d681SAndroid Build Coastguard Workerexecution or to register signal handlers. Nonetheless, there are 2004*9880d681SAndroid Build Coastguard Workerplatform-specific ways to create them, and we define LLVM IR's behavior 2005*9880d681SAndroid Build Coastguard Workerin their presence. This model is inspired by the C++0x memory model. 2006*9880d681SAndroid Build Coastguard Worker 2007*9880d681SAndroid Build Coastguard WorkerFor a more informal introduction to this model, see the :doc:`Atomics`. 2008*9880d681SAndroid Build Coastguard Worker 2009*9880d681SAndroid Build Coastguard WorkerWe define a *happens-before* partial order as the least partial order 2010*9880d681SAndroid Build Coastguard Workerthat 2011*9880d681SAndroid Build Coastguard Worker 2012*9880d681SAndroid Build Coastguard Worker- Is a superset of single-thread program order, and 2013*9880d681SAndroid Build Coastguard Worker- When a *synchronizes-with* ``b``, includes an edge from ``a`` to 2014*9880d681SAndroid Build Coastguard Worker ``b``. *Synchronizes-with* pairs are introduced by platform-specific 2015*9880d681SAndroid Build Coastguard Worker techniques, like pthread locks, thread creation, thread joining, 2016*9880d681SAndroid Build Coastguard Worker etc., and by atomic instructions. (See also :ref:`Atomic Memory Ordering 2017*9880d681SAndroid Build Coastguard Worker Constraints <ordering>`). 2018*9880d681SAndroid Build Coastguard Worker 2019*9880d681SAndroid Build Coastguard WorkerNote that program order does not introduce *happens-before* edges 2020*9880d681SAndroid Build Coastguard Workerbetween a thread and signals executing inside that thread. 2021*9880d681SAndroid Build Coastguard Worker 2022*9880d681SAndroid Build Coastguard WorkerEvery (defined) read operation (load instructions, memcpy, atomic 2023*9880d681SAndroid Build Coastguard Workerloads/read-modify-writes, etc.) R reads a series of bytes written by 2024*9880d681SAndroid Build Coastguard Worker(defined) write operations (store instructions, atomic 2025*9880d681SAndroid Build Coastguard Workerstores/read-modify-writes, memcpy, etc.). For the purposes of this 2026*9880d681SAndroid Build Coastguard Workersection, initialized globals are considered to have a write of the 2027*9880d681SAndroid Build Coastguard Workerinitializer which is atomic and happens before any other read or write 2028*9880d681SAndroid Build Coastguard Workerof the memory in question. For each byte of a read R, R\ :sub:`byte` 2029*9880d681SAndroid Build Coastguard Workermay see any write to the same byte, except: 2030*9880d681SAndroid Build Coastguard Worker 2031*9880d681SAndroid Build Coastguard Worker- If write\ :sub:`1` happens before write\ :sub:`2`, and 2032*9880d681SAndroid Build Coastguard Worker write\ :sub:`2` happens before R\ :sub:`byte`, then 2033*9880d681SAndroid Build Coastguard Worker R\ :sub:`byte` does not see write\ :sub:`1`. 2034*9880d681SAndroid Build Coastguard Worker- If R\ :sub:`byte` happens before write\ :sub:`3`, then 2035*9880d681SAndroid Build Coastguard Worker R\ :sub:`byte` does not see write\ :sub:`3`. 2036*9880d681SAndroid Build Coastguard Worker 2037*9880d681SAndroid Build Coastguard WorkerGiven that definition, R\ :sub:`byte` is defined as follows: 2038*9880d681SAndroid Build Coastguard Worker 2039*9880d681SAndroid Build Coastguard Worker- If R is volatile, the result is target-dependent. (Volatile is 2040*9880d681SAndroid Build Coastguard Worker supposed to give guarantees which can support ``sig_atomic_t`` in 2041*9880d681SAndroid Build Coastguard Worker C/C++, and may be used for accesses to addresses that do not behave 2042*9880d681SAndroid Build Coastguard Worker like normal memory. It does not generally provide cross-thread 2043*9880d681SAndroid Build Coastguard Worker synchronization.) 2044*9880d681SAndroid Build Coastguard Worker- Otherwise, if there is no write to the same byte that happens before 2045*9880d681SAndroid Build Coastguard Worker R\ :sub:`byte`, R\ :sub:`byte` returns ``undef`` for that byte. 2046*9880d681SAndroid Build Coastguard Worker- Otherwise, if R\ :sub:`byte` may see exactly one write, 2047*9880d681SAndroid Build Coastguard Worker R\ :sub:`byte` returns the value written by that write. 2048*9880d681SAndroid Build Coastguard Worker- Otherwise, if R is atomic, and all the writes R\ :sub:`byte` may 2049*9880d681SAndroid Build Coastguard Worker see are atomic, it chooses one of the values written. See the :ref:`Atomic 2050*9880d681SAndroid Build Coastguard Worker Memory Ordering Constraints <ordering>` section for additional 2051*9880d681SAndroid Build Coastguard Worker constraints on how the choice is made. 2052*9880d681SAndroid Build Coastguard Worker- Otherwise R\ :sub:`byte` returns ``undef``. 2053*9880d681SAndroid Build Coastguard Worker 2054*9880d681SAndroid Build Coastguard WorkerR returns the value composed of the series of bytes it read. This 2055*9880d681SAndroid Build Coastguard Workerimplies that some bytes within the value may be ``undef`` **without** 2056*9880d681SAndroid Build Coastguard Workerthe entire value being ``undef``. Note that this only defines the 2057*9880d681SAndroid Build Coastguard Workersemantics of the operation; it doesn't mean that targets will emit more 2058*9880d681SAndroid Build Coastguard Workerthan one instruction to read the series of bytes. 2059*9880d681SAndroid Build Coastguard Worker 2060*9880d681SAndroid Build Coastguard WorkerNote that in cases where none of the atomic intrinsics are used, this 2061*9880d681SAndroid Build Coastguard Workermodel places only one restriction on IR transformations on top of what 2062*9880d681SAndroid Build Coastguard Workeris required for single-threaded execution: introducing a store to a byte 2063*9880d681SAndroid Build Coastguard Workerwhich might not otherwise be stored is not allowed in general. 2064*9880d681SAndroid Build Coastguard Worker(Specifically, in the case where another thread might write to and read 2065*9880d681SAndroid Build Coastguard Workerfrom an address, introducing a store can change a load that may see 2066*9880d681SAndroid Build Coastguard Workerexactly one write into a load that may see multiple writes.) 2067*9880d681SAndroid Build Coastguard Worker 2068*9880d681SAndroid Build Coastguard Worker.. _ordering: 2069*9880d681SAndroid Build Coastguard Worker 2070*9880d681SAndroid Build Coastguard WorkerAtomic Memory Ordering Constraints 2071*9880d681SAndroid Build Coastguard Worker---------------------------------- 2072*9880d681SAndroid Build Coastguard Worker 2073*9880d681SAndroid Build Coastguard WorkerAtomic instructions (:ref:`cmpxchg <i_cmpxchg>`, 2074*9880d681SAndroid Build Coastguard Worker:ref:`atomicrmw <i_atomicrmw>`, :ref:`fence <i_fence>`, 2075*9880d681SAndroid Build Coastguard Worker:ref:`atomic load <i_load>`, and :ref:`atomic store <i_store>`) take 2076*9880d681SAndroid Build Coastguard Workerordering parameters that determine which other atomic instructions on 2077*9880d681SAndroid Build Coastguard Workerthe same address they *synchronize with*. These semantics are borrowed 2078*9880d681SAndroid Build Coastguard Workerfrom Java and C++0x, but are somewhat more colloquial. If these 2079*9880d681SAndroid Build Coastguard Workerdescriptions aren't precise enough, check those specs (see spec 2080*9880d681SAndroid Build Coastguard Workerreferences in the :doc:`atomics guide <Atomics>`). 2081*9880d681SAndroid Build Coastguard Worker:ref:`fence <i_fence>` instructions treat these orderings somewhat 2082*9880d681SAndroid Build Coastguard Workerdifferently since they don't take an address. See that instruction's 2083*9880d681SAndroid Build Coastguard Workerdocumentation for details. 2084*9880d681SAndroid Build Coastguard Worker 2085*9880d681SAndroid Build Coastguard WorkerFor a simpler introduction to the ordering constraints, see the 2086*9880d681SAndroid Build Coastguard Worker:doc:`Atomics`. 2087*9880d681SAndroid Build Coastguard Worker 2088*9880d681SAndroid Build Coastguard Worker``unordered`` 2089*9880d681SAndroid Build Coastguard Worker The set of values that can be read is governed by the happens-before 2090*9880d681SAndroid Build Coastguard Worker partial order. A value cannot be read unless some operation wrote 2091*9880d681SAndroid Build Coastguard Worker it. This is intended to provide a guarantee strong enough to model 2092*9880d681SAndroid Build Coastguard Worker Java's non-volatile shared variables. This ordering cannot be 2093*9880d681SAndroid Build Coastguard Worker specified for read-modify-write operations; it is not strong enough 2094*9880d681SAndroid Build Coastguard Worker to make them atomic in any interesting way. 2095*9880d681SAndroid Build Coastguard Worker``monotonic`` 2096*9880d681SAndroid Build Coastguard Worker In addition to the guarantees of ``unordered``, there is a single 2097*9880d681SAndroid Build Coastguard Worker total order for modifications by ``monotonic`` operations on each 2098*9880d681SAndroid Build Coastguard Worker address. All modification orders must be compatible with the 2099*9880d681SAndroid Build Coastguard Worker happens-before order. There is no guarantee that the modification 2100*9880d681SAndroid Build Coastguard Worker orders can be combined to a global total order for the whole program 2101*9880d681SAndroid Build Coastguard Worker (and this often will not be possible). The read in an atomic 2102*9880d681SAndroid Build Coastguard Worker read-modify-write operation (:ref:`cmpxchg <i_cmpxchg>` and 2103*9880d681SAndroid Build Coastguard Worker :ref:`atomicrmw <i_atomicrmw>`) reads the value in the modification 2104*9880d681SAndroid Build Coastguard Worker order immediately before the value it writes. If one atomic read 2105*9880d681SAndroid Build Coastguard Worker happens before another atomic read of the same address, the later 2106*9880d681SAndroid Build Coastguard Worker read must see the same value or a later value in the address's 2107*9880d681SAndroid Build Coastguard Worker modification order. This disallows reordering of ``monotonic`` (or 2108*9880d681SAndroid Build Coastguard Worker stronger) operations on the same address. If an address is written 2109*9880d681SAndroid Build Coastguard Worker ``monotonic``-ally by one thread, and other threads ``monotonic``-ally 2110*9880d681SAndroid Build Coastguard Worker read that address repeatedly, the other threads must eventually see 2111*9880d681SAndroid Build Coastguard Worker the write. This corresponds to the C++0x/C1x 2112*9880d681SAndroid Build Coastguard Worker ``memory_order_relaxed``. 2113*9880d681SAndroid Build Coastguard Worker``acquire`` 2114*9880d681SAndroid Build Coastguard Worker In addition to the guarantees of ``monotonic``, a 2115*9880d681SAndroid Build Coastguard Worker *synchronizes-with* edge may be formed with a ``release`` operation. 2116*9880d681SAndroid Build Coastguard Worker This is intended to model C++'s ``memory_order_acquire``. 2117*9880d681SAndroid Build Coastguard Worker``release`` 2118*9880d681SAndroid Build Coastguard Worker In addition to the guarantees of ``monotonic``, if this operation 2119*9880d681SAndroid Build Coastguard Worker writes a value which is subsequently read by an ``acquire`` 2120*9880d681SAndroid Build Coastguard Worker operation, it *synchronizes-with* that operation. (This isn't a 2121*9880d681SAndroid Build Coastguard Worker complete description; see the C++0x definition of a release 2122*9880d681SAndroid Build Coastguard Worker sequence.) This corresponds to the C++0x/C1x 2123*9880d681SAndroid Build Coastguard Worker ``memory_order_release``. 2124*9880d681SAndroid Build Coastguard Worker``acq_rel`` (acquire+release) 2125*9880d681SAndroid Build Coastguard Worker Acts as both an ``acquire`` and ``release`` operation on its 2126*9880d681SAndroid Build Coastguard Worker address. This corresponds to the C++0x/C1x ``memory_order_acq_rel``. 2127*9880d681SAndroid Build Coastguard Worker``seq_cst`` (sequentially consistent) 2128*9880d681SAndroid Build Coastguard Worker In addition to the guarantees of ``acq_rel`` (``acquire`` for an 2129*9880d681SAndroid Build Coastguard Worker operation that only reads, ``release`` for an operation that only 2130*9880d681SAndroid Build Coastguard Worker writes), there is a global total order on all 2131*9880d681SAndroid Build Coastguard Worker sequentially-consistent operations on all addresses, which is 2132*9880d681SAndroid Build Coastguard Worker consistent with the *happens-before* partial order and with the 2133*9880d681SAndroid Build Coastguard Worker modification orders of all the affected addresses. Each 2134*9880d681SAndroid Build Coastguard Worker sequentially-consistent read sees the last preceding write to the 2135*9880d681SAndroid Build Coastguard Worker same address in this global order. This corresponds to the C++0x/C1x 2136*9880d681SAndroid Build Coastguard Worker ``memory_order_seq_cst`` and Java volatile. 2137*9880d681SAndroid Build Coastguard Worker 2138*9880d681SAndroid Build Coastguard Worker.. _singlethread: 2139*9880d681SAndroid Build Coastguard Worker 2140*9880d681SAndroid Build Coastguard WorkerIf an atomic operation is marked ``singlethread``, it only *synchronizes 2141*9880d681SAndroid Build Coastguard Workerwith* or participates in modification and seq\_cst total orderings with 2142*9880d681SAndroid Build Coastguard Workerother operations running in the same thread (for example, in signal 2143*9880d681SAndroid Build Coastguard Workerhandlers). 2144*9880d681SAndroid Build Coastguard Worker 2145*9880d681SAndroid Build Coastguard Worker.. _fastmath: 2146*9880d681SAndroid Build Coastguard Worker 2147*9880d681SAndroid Build Coastguard WorkerFast-Math Flags 2148*9880d681SAndroid Build Coastguard Worker--------------- 2149*9880d681SAndroid Build Coastguard Worker 2150*9880d681SAndroid Build Coastguard WorkerLLVM IR floating-point binary ops (:ref:`fadd <i_fadd>`, 2151*9880d681SAndroid Build Coastguard Worker:ref:`fsub <i_fsub>`, :ref:`fmul <i_fmul>`, :ref:`fdiv <i_fdiv>`, 2152*9880d681SAndroid Build Coastguard Worker:ref:`frem <i_frem>`, :ref:`fcmp <i_fcmp>`) have the following flags that can 2153*9880d681SAndroid Build Coastguard Workerbe set to enable otherwise unsafe floating point operations 2154*9880d681SAndroid Build Coastguard Worker 2155*9880d681SAndroid Build Coastguard Worker``nnan`` 2156*9880d681SAndroid Build Coastguard Worker No NaNs - Allow optimizations to assume the arguments and result are not 2157*9880d681SAndroid Build Coastguard Worker NaN. Such optimizations are required to retain defined behavior over 2158*9880d681SAndroid Build Coastguard Worker NaNs, but the value of the result is undefined. 2159*9880d681SAndroid Build Coastguard Worker 2160*9880d681SAndroid Build Coastguard Worker``ninf`` 2161*9880d681SAndroid Build Coastguard Worker No Infs - Allow optimizations to assume the arguments and result are not 2162*9880d681SAndroid Build Coastguard Worker +/-Inf. Such optimizations are required to retain defined behavior over 2163*9880d681SAndroid Build Coastguard Worker +/-Inf, but the value of the result is undefined. 2164*9880d681SAndroid Build Coastguard Worker 2165*9880d681SAndroid Build Coastguard Worker``nsz`` 2166*9880d681SAndroid Build Coastguard Worker No Signed Zeros - Allow optimizations to treat the sign of a zero 2167*9880d681SAndroid Build Coastguard Worker argument or result as insignificant. 2168*9880d681SAndroid Build Coastguard Worker 2169*9880d681SAndroid Build Coastguard Worker``arcp`` 2170*9880d681SAndroid Build Coastguard Worker Allow Reciprocal - Allow optimizations to use the reciprocal of an 2171*9880d681SAndroid Build Coastguard Worker argument rather than perform division. 2172*9880d681SAndroid Build Coastguard Worker 2173*9880d681SAndroid Build Coastguard Worker``fast`` 2174*9880d681SAndroid Build Coastguard Worker Fast - Allow algebraically equivalent transformations that may 2175*9880d681SAndroid Build Coastguard Worker dramatically change results in floating point (e.g. reassociate). This 2176*9880d681SAndroid Build Coastguard Worker flag implies all the others. 2177*9880d681SAndroid Build Coastguard Worker 2178*9880d681SAndroid Build Coastguard Worker.. _uselistorder: 2179*9880d681SAndroid Build Coastguard Worker 2180*9880d681SAndroid Build Coastguard WorkerUse-list Order Directives 2181*9880d681SAndroid Build Coastguard Worker------------------------- 2182*9880d681SAndroid Build Coastguard Worker 2183*9880d681SAndroid Build Coastguard WorkerUse-list directives encode the in-memory order of each use-list, allowing the 2184*9880d681SAndroid Build Coastguard Workerorder to be recreated. ``<order-indexes>`` is a comma-separated list of 2185*9880d681SAndroid Build Coastguard Workerindexes that are assigned to the referenced value's uses. The referenced 2186*9880d681SAndroid Build Coastguard Workervalue's use-list is immediately sorted by these indexes. 2187*9880d681SAndroid Build Coastguard Worker 2188*9880d681SAndroid Build Coastguard WorkerUse-list directives may appear at function scope or global scope. They are not 2189*9880d681SAndroid Build Coastguard Workerinstructions, and have no effect on the semantics of the IR. When they're at 2190*9880d681SAndroid Build Coastguard Workerfunction scope, they must appear after the terminator of the final basic block. 2191*9880d681SAndroid Build Coastguard Worker 2192*9880d681SAndroid Build Coastguard WorkerIf basic blocks have their address taken via ``blockaddress()`` expressions, 2193*9880d681SAndroid Build Coastguard Worker``uselistorder_bb`` can be used to reorder their use-lists from outside their 2194*9880d681SAndroid Build Coastguard Workerfunction's scope. 2195*9880d681SAndroid Build Coastguard Worker 2196*9880d681SAndroid Build Coastguard Worker:Syntax: 2197*9880d681SAndroid Build Coastguard Worker 2198*9880d681SAndroid Build Coastguard Worker:: 2199*9880d681SAndroid Build Coastguard Worker 2200*9880d681SAndroid Build Coastguard Worker uselistorder <ty> <value>, { <order-indexes> } 2201*9880d681SAndroid Build Coastguard Worker uselistorder_bb @function, %block { <order-indexes> } 2202*9880d681SAndroid Build Coastguard Worker 2203*9880d681SAndroid Build Coastguard Worker:Examples: 2204*9880d681SAndroid Build Coastguard Worker 2205*9880d681SAndroid Build Coastguard Worker:: 2206*9880d681SAndroid Build Coastguard Worker 2207*9880d681SAndroid Build Coastguard Worker define void @foo(i32 %arg1, i32 %arg2) { 2208*9880d681SAndroid Build Coastguard Worker entry: 2209*9880d681SAndroid Build Coastguard Worker ; ... instructions ... 2210*9880d681SAndroid Build Coastguard Worker bb: 2211*9880d681SAndroid Build Coastguard Worker ; ... instructions ... 2212*9880d681SAndroid Build Coastguard Worker 2213*9880d681SAndroid Build Coastguard Worker ; At function scope. 2214*9880d681SAndroid Build Coastguard Worker uselistorder i32 %arg1, { 1, 0, 2 } 2215*9880d681SAndroid Build Coastguard Worker uselistorder label %bb, { 1, 0 } 2216*9880d681SAndroid Build Coastguard Worker } 2217*9880d681SAndroid Build Coastguard Worker 2218*9880d681SAndroid Build Coastguard Worker ; At global scope. 2219*9880d681SAndroid Build Coastguard Worker uselistorder i32* @global, { 1, 2, 0 } 2220*9880d681SAndroid Build Coastguard Worker uselistorder i32 7, { 1, 0 } 2221*9880d681SAndroid Build Coastguard Worker uselistorder i32 (i32) @bar, { 1, 0 } 2222*9880d681SAndroid Build Coastguard Worker uselistorder_bb @foo, %bb, { 5, 1, 3, 2, 0, 4 } 2223*9880d681SAndroid Build Coastguard Worker 2224*9880d681SAndroid Build Coastguard Worker.. _source_filename: 2225*9880d681SAndroid Build Coastguard Worker 2226*9880d681SAndroid Build Coastguard WorkerSource Filename 2227*9880d681SAndroid Build Coastguard Worker--------------- 2228*9880d681SAndroid Build Coastguard Worker 2229*9880d681SAndroid Build Coastguard WorkerThe *source filename* string is set to the original module identifier, 2230*9880d681SAndroid Build Coastguard Workerwhich will be the name of the compiled source file when compiling from 2231*9880d681SAndroid Build Coastguard Workersource through the clang front end, for example. It is then preserved through 2232*9880d681SAndroid Build Coastguard Workerthe IR and bitcode. 2233*9880d681SAndroid Build Coastguard Worker 2234*9880d681SAndroid Build Coastguard WorkerThis is currently necessary to generate a consistent unique global 2235*9880d681SAndroid Build Coastguard Workeridentifier for local functions used in profile data, which prepends the 2236*9880d681SAndroid Build Coastguard Workersource file name to the local function name. 2237*9880d681SAndroid Build Coastguard Worker 2238*9880d681SAndroid Build Coastguard WorkerThe syntax for the source file name is simply: 2239*9880d681SAndroid Build Coastguard Worker 2240*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 2241*9880d681SAndroid Build Coastguard Worker 2242*9880d681SAndroid Build Coastguard Worker source_filename = "/path/to/source.c" 2243*9880d681SAndroid Build Coastguard Worker 2244*9880d681SAndroid Build Coastguard Worker.. _typesystem: 2245*9880d681SAndroid Build Coastguard Worker 2246*9880d681SAndroid Build Coastguard WorkerType System 2247*9880d681SAndroid Build Coastguard Worker=========== 2248*9880d681SAndroid Build Coastguard Worker 2249*9880d681SAndroid Build Coastguard WorkerThe LLVM type system is one of the most important features of the 2250*9880d681SAndroid Build Coastguard Workerintermediate representation. Being typed enables a number of 2251*9880d681SAndroid Build Coastguard Workeroptimizations to be performed on the intermediate representation 2252*9880d681SAndroid Build Coastguard Workerdirectly, without having to do extra analyses on the side before the 2253*9880d681SAndroid Build Coastguard Workertransformation. A strong type system makes it easier to read the 2254*9880d681SAndroid Build Coastguard Workergenerated code and enables novel analyses and transformations that are 2255*9880d681SAndroid Build Coastguard Workernot feasible to perform on normal three address code representations. 2256*9880d681SAndroid Build Coastguard Worker 2257*9880d681SAndroid Build Coastguard Worker.. _t_void: 2258*9880d681SAndroid Build Coastguard Worker 2259*9880d681SAndroid Build Coastguard WorkerVoid Type 2260*9880d681SAndroid Build Coastguard Worker--------- 2261*9880d681SAndroid Build Coastguard Worker 2262*9880d681SAndroid Build Coastguard Worker:Overview: 2263*9880d681SAndroid Build Coastguard Worker 2264*9880d681SAndroid Build Coastguard Worker 2265*9880d681SAndroid Build Coastguard WorkerThe void type does not represent any value and has no size. 2266*9880d681SAndroid Build Coastguard Worker 2267*9880d681SAndroid Build Coastguard Worker:Syntax: 2268*9880d681SAndroid Build Coastguard Worker 2269*9880d681SAndroid Build Coastguard Worker 2270*9880d681SAndroid Build Coastguard Worker:: 2271*9880d681SAndroid Build Coastguard Worker 2272*9880d681SAndroid Build Coastguard Worker void 2273*9880d681SAndroid Build Coastguard Worker 2274*9880d681SAndroid Build Coastguard Worker 2275*9880d681SAndroid Build Coastguard Worker.. _t_function: 2276*9880d681SAndroid Build Coastguard Worker 2277*9880d681SAndroid Build Coastguard WorkerFunction Type 2278*9880d681SAndroid Build Coastguard Worker------------- 2279*9880d681SAndroid Build Coastguard Worker 2280*9880d681SAndroid Build Coastguard Worker:Overview: 2281*9880d681SAndroid Build Coastguard Worker 2282*9880d681SAndroid Build Coastguard Worker 2283*9880d681SAndroid Build Coastguard WorkerThe function type can be thought of as a function signature. It consists of a 2284*9880d681SAndroid Build Coastguard Workerreturn type and a list of formal parameter types. The return type of a function 2285*9880d681SAndroid Build Coastguard Workertype is a void type or first class type --- except for :ref:`label <t_label>` 2286*9880d681SAndroid Build Coastguard Workerand :ref:`metadata <t_metadata>` types. 2287*9880d681SAndroid Build Coastguard Worker 2288*9880d681SAndroid Build Coastguard Worker:Syntax: 2289*9880d681SAndroid Build Coastguard Worker 2290*9880d681SAndroid Build Coastguard Worker:: 2291*9880d681SAndroid Build Coastguard Worker 2292*9880d681SAndroid Build Coastguard Worker <returntype> (<parameter list>) 2293*9880d681SAndroid Build Coastguard Worker 2294*9880d681SAndroid Build Coastguard Worker...where '``<parameter list>``' is a comma-separated list of type 2295*9880d681SAndroid Build Coastguard Workerspecifiers. Optionally, the parameter list may include a type ``...``, which 2296*9880d681SAndroid Build Coastguard Workerindicates that the function takes a variable number of arguments. Variable 2297*9880d681SAndroid Build Coastguard Workerargument functions can access their arguments with the :ref:`variable argument 2298*9880d681SAndroid Build Coastguard Workerhandling intrinsic <int_varargs>` functions. '``<returntype>``' is any type 2299*9880d681SAndroid Build Coastguard Workerexcept :ref:`label <t_label>` and :ref:`metadata <t_metadata>`. 2300*9880d681SAndroid Build Coastguard Worker 2301*9880d681SAndroid Build Coastguard Worker:Examples: 2302*9880d681SAndroid Build Coastguard Worker 2303*9880d681SAndroid Build Coastguard Worker+---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 2304*9880d681SAndroid Build Coastguard Worker| ``i32 (i32)`` | function taking an ``i32``, returning an ``i32`` | 2305*9880d681SAndroid Build Coastguard Worker+---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 2306*9880d681SAndroid Build Coastguard Worker| ``float (i16, i32 *) *`` | :ref:`Pointer <t_pointer>` to a function that takes an ``i16`` and a :ref:`pointer <t_pointer>` to ``i32``, returning ``float``. | 2307*9880d681SAndroid Build Coastguard Worker+---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 2308*9880d681SAndroid Build Coastguard Worker| ``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. | 2309*9880d681SAndroid Build Coastguard Worker+---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 2310*9880d681SAndroid Build Coastguard Worker| ``{i32, i32} (i32)`` | A function taking an ``i32``, returning a :ref:`structure <t_struct>` containing two ``i32`` values | 2311*9880d681SAndroid Build Coastguard Worker+---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 2312*9880d681SAndroid Build Coastguard Worker 2313*9880d681SAndroid Build Coastguard Worker.. _t_firstclass: 2314*9880d681SAndroid Build Coastguard Worker 2315*9880d681SAndroid Build Coastguard WorkerFirst Class Types 2316*9880d681SAndroid Build Coastguard Worker----------------- 2317*9880d681SAndroid Build Coastguard Worker 2318*9880d681SAndroid Build Coastguard WorkerThe :ref:`first class <t_firstclass>` types are perhaps the most important. 2319*9880d681SAndroid Build Coastguard WorkerValues of these types are the only ones which can be produced by 2320*9880d681SAndroid Build Coastguard Workerinstructions. 2321*9880d681SAndroid Build Coastguard Worker 2322*9880d681SAndroid Build Coastguard Worker.. _t_single_value: 2323*9880d681SAndroid Build Coastguard Worker 2324*9880d681SAndroid Build Coastguard WorkerSingle Value Types 2325*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^ 2326*9880d681SAndroid Build Coastguard Worker 2327*9880d681SAndroid Build Coastguard WorkerThese are the types that are valid in registers from CodeGen's perspective. 2328*9880d681SAndroid Build Coastguard Worker 2329*9880d681SAndroid Build Coastguard Worker.. _t_integer: 2330*9880d681SAndroid Build Coastguard Worker 2331*9880d681SAndroid Build Coastguard WorkerInteger Type 2332*9880d681SAndroid Build Coastguard Worker"""""""""""" 2333*9880d681SAndroid Build Coastguard Worker 2334*9880d681SAndroid Build Coastguard Worker:Overview: 2335*9880d681SAndroid Build Coastguard Worker 2336*9880d681SAndroid Build Coastguard WorkerThe integer type is a very simple type that simply specifies an 2337*9880d681SAndroid Build Coastguard Workerarbitrary bit width for the integer type desired. Any bit width from 1 2338*9880d681SAndroid Build Coastguard Workerbit to 2\ :sup:`23`\ -1 (about 8 million) can be specified. 2339*9880d681SAndroid Build Coastguard Worker 2340*9880d681SAndroid Build Coastguard Worker:Syntax: 2341*9880d681SAndroid Build Coastguard Worker 2342*9880d681SAndroid Build Coastguard Worker:: 2343*9880d681SAndroid Build Coastguard Worker 2344*9880d681SAndroid Build Coastguard Worker iN 2345*9880d681SAndroid Build Coastguard Worker 2346*9880d681SAndroid Build Coastguard WorkerThe number of bits the integer will occupy is specified by the ``N`` 2347*9880d681SAndroid Build Coastguard Workervalue. 2348*9880d681SAndroid Build Coastguard Worker 2349*9880d681SAndroid Build Coastguard WorkerExamples: 2350*9880d681SAndroid Build Coastguard Worker********* 2351*9880d681SAndroid Build Coastguard Worker 2352*9880d681SAndroid Build Coastguard Worker+----------------+------------------------------------------------+ 2353*9880d681SAndroid Build Coastguard Worker| ``i1`` | a single-bit integer. | 2354*9880d681SAndroid Build Coastguard Worker+----------------+------------------------------------------------+ 2355*9880d681SAndroid Build Coastguard Worker| ``i32`` | a 32-bit integer. | 2356*9880d681SAndroid Build Coastguard Worker+----------------+------------------------------------------------+ 2357*9880d681SAndroid Build Coastguard Worker| ``i1942652`` | a really big integer of over 1 million bits. | 2358*9880d681SAndroid Build Coastguard Worker+----------------+------------------------------------------------+ 2359*9880d681SAndroid Build Coastguard Worker 2360*9880d681SAndroid Build Coastguard Worker.. _t_floating: 2361*9880d681SAndroid Build Coastguard Worker 2362*9880d681SAndroid Build Coastguard WorkerFloating Point Types 2363*9880d681SAndroid Build Coastguard Worker"""""""""""""""""""" 2364*9880d681SAndroid Build Coastguard Worker 2365*9880d681SAndroid Build Coastguard Worker.. list-table:: 2366*9880d681SAndroid Build Coastguard Worker :header-rows: 1 2367*9880d681SAndroid Build Coastguard Worker 2368*9880d681SAndroid Build Coastguard Worker * - Type 2369*9880d681SAndroid Build Coastguard Worker - Description 2370*9880d681SAndroid Build Coastguard Worker 2371*9880d681SAndroid Build Coastguard Worker * - ``half`` 2372*9880d681SAndroid Build Coastguard Worker - 16-bit floating point value 2373*9880d681SAndroid Build Coastguard Worker 2374*9880d681SAndroid Build Coastguard Worker * - ``float`` 2375*9880d681SAndroid Build Coastguard Worker - 32-bit floating point value 2376*9880d681SAndroid Build Coastguard Worker 2377*9880d681SAndroid Build Coastguard Worker * - ``double`` 2378*9880d681SAndroid Build Coastguard Worker - 64-bit floating point value 2379*9880d681SAndroid Build Coastguard Worker 2380*9880d681SAndroid Build Coastguard Worker * - ``fp128`` 2381*9880d681SAndroid Build Coastguard Worker - 128-bit floating point value (112-bit mantissa) 2382*9880d681SAndroid Build Coastguard Worker 2383*9880d681SAndroid Build Coastguard Worker * - ``x86_fp80`` 2384*9880d681SAndroid Build Coastguard Worker - 80-bit floating point value (X87) 2385*9880d681SAndroid Build Coastguard Worker 2386*9880d681SAndroid Build Coastguard Worker * - ``ppc_fp128`` 2387*9880d681SAndroid Build Coastguard Worker - 128-bit floating point value (two 64-bits) 2388*9880d681SAndroid Build Coastguard Worker 2389*9880d681SAndroid Build Coastguard WorkerX86_mmx Type 2390*9880d681SAndroid Build Coastguard Worker"""""""""""" 2391*9880d681SAndroid Build Coastguard Worker 2392*9880d681SAndroid Build Coastguard Worker:Overview: 2393*9880d681SAndroid Build Coastguard Worker 2394*9880d681SAndroid Build Coastguard WorkerThe x86_mmx type represents a value held in an MMX register on an x86 2395*9880d681SAndroid Build Coastguard Workermachine. The operations allowed on it are quite limited: parameters and 2396*9880d681SAndroid Build Coastguard Workerreturn values, load and store, and bitcast. User-specified MMX 2397*9880d681SAndroid Build Coastguard Workerinstructions are represented as intrinsic or asm calls with arguments 2398*9880d681SAndroid Build Coastguard Workerand/or results of this type. There are no arrays, vectors or constants 2399*9880d681SAndroid Build Coastguard Workerof this type. 2400*9880d681SAndroid Build Coastguard Worker 2401*9880d681SAndroid Build Coastguard Worker:Syntax: 2402*9880d681SAndroid Build Coastguard Worker 2403*9880d681SAndroid Build Coastguard Worker:: 2404*9880d681SAndroid Build Coastguard Worker 2405*9880d681SAndroid Build Coastguard Worker x86_mmx 2406*9880d681SAndroid Build Coastguard Worker 2407*9880d681SAndroid Build Coastguard Worker 2408*9880d681SAndroid Build Coastguard Worker.. _t_pointer: 2409*9880d681SAndroid Build Coastguard Worker 2410*9880d681SAndroid Build Coastguard WorkerPointer Type 2411*9880d681SAndroid Build Coastguard Worker"""""""""""" 2412*9880d681SAndroid Build Coastguard Worker 2413*9880d681SAndroid Build Coastguard Worker:Overview: 2414*9880d681SAndroid Build Coastguard Worker 2415*9880d681SAndroid Build Coastguard WorkerThe pointer type is used to specify memory locations. Pointers are 2416*9880d681SAndroid Build Coastguard Workercommonly used to reference objects in memory. 2417*9880d681SAndroid Build Coastguard Worker 2418*9880d681SAndroid Build Coastguard WorkerPointer types may have an optional address space attribute defining the 2419*9880d681SAndroid Build Coastguard Workernumbered address space where the pointed-to object resides. The default 2420*9880d681SAndroid Build Coastguard Workeraddress space is number zero. The semantics of non-zero address spaces 2421*9880d681SAndroid Build Coastguard Workerare target-specific. 2422*9880d681SAndroid Build Coastguard Worker 2423*9880d681SAndroid Build Coastguard WorkerNote that LLVM does not permit pointers to void (``void*``) nor does it 2424*9880d681SAndroid Build Coastguard Workerpermit pointers to labels (``label*``). Use ``i8*`` instead. 2425*9880d681SAndroid Build Coastguard Worker 2426*9880d681SAndroid Build Coastguard Worker:Syntax: 2427*9880d681SAndroid Build Coastguard Worker 2428*9880d681SAndroid Build Coastguard Worker:: 2429*9880d681SAndroid Build Coastguard Worker 2430*9880d681SAndroid Build Coastguard Worker <type> * 2431*9880d681SAndroid Build Coastguard Worker 2432*9880d681SAndroid Build Coastguard Worker:Examples: 2433*9880d681SAndroid Build Coastguard Worker 2434*9880d681SAndroid Build Coastguard Worker+-------------------------+--------------------------------------------------------------------------------------------------------------+ 2435*9880d681SAndroid Build Coastguard Worker| ``[4 x i32]*`` | A :ref:`pointer <t_pointer>` to :ref:`array <t_array>` of four ``i32`` values. | 2436*9880d681SAndroid Build Coastguard Worker+-------------------------+--------------------------------------------------------------------------------------------------------------+ 2437*9880d681SAndroid Build Coastguard Worker| ``i32 (i32*) *`` | A :ref:`pointer <t_pointer>` to a :ref:`function <t_function>` that takes an ``i32*``, returning an ``i32``. | 2438*9880d681SAndroid Build Coastguard Worker+-------------------------+--------------------------------------------------------------------------------------------------------------+ 2439*9880d681SAndroid Build Coastguard Worker| ``i32 addrspace(5)*`` | A :ref:`pointer <t_pointer>` to an ``i32`` value that resides in address space #5. | 2440*9880d681SAndroid Build Coastguard Worker+-------------------------+--------------------------------------------------------------------------------------------------------------+ 2441*9880d681SAndroid Build Coastguard Worker 2442*9880d681SAndroid Build Coastguard Worker.. _t_vector: 2443*9880d681SAndroid Build Coastguard Worker 2444*9880d681SAndroid Build Coastguard WorkerVector Type 2445*9880d681SAndroid Build Coastguard Worker""""""""""" 2446*9880d681SAndroid Build Coastguard Worker 2447*9880d681SAndroid Build Coastguard Worker:Overview: 2448*9880d681SAndroid Build Coastguard Worker 2449*9880d681SAndroid Build Coastguard WorkerA vector type is a simple derived type that represents a vector of 2450*9880d681SAndroid Build Coastguard Workerelements. Vector types are used when multiple primitive data are 2451*9880d681SAndroid Build Coastguard Workeroperated in parallel using a single instruction (SIMD). A vector type 2452*9880d681SAndroid Build Coastguard Workerrequires a size (number of elements) and an underlying primitive data 2453*9880d681SAndroid Build Coastguard Workertype. Vector types are considered :ref:`first class <t_firstclass>`. 2454*9880d681SAndroid Build Coastguard Worker 2455*9880d681SAndroid Build Coastguard Worker:Syntax: 2456*9880d681SAndroid Build Coastguard Worker 2457*9880d681SAndroid Build Coastguard Worker:: 2458*9880d681SAndroid Build Coastguard Worker 2459*9880d681SAndroid Build Coastguard Worker < <# elements> x <elementtype> > 2460*9880d681SAndroid Build Coastguard Worker 2461*9880d681SAndroid Build Coastguard WorkerThe number of elements is a constant integer value larger than 0; 2462*9880d681SAndroid Build Coastguard Workerelementtype may be any integer, floating point or pointer type. Vectors 2463*9880d681SAndroid Build Coastguard Workerof size zero are not allowed. 2464*9880d681SAndroid Build Coastguard Worker 2465*9880d681SAndroid Build Coastguard Worker:Examples: 2466*9880d681SAndroid Build Coastguard Worker 2467*9880d681SAndroid Build Coastguard Worker+-------------------+--------------------------------------------------+ 2468*9880d681SAndroid Build Coastguard Worker| ``<4 x i32>`` | Vector of 4 32-bit integer values. | 2469*9880d681SAndroid Build Coastguard Worker+-------------------+--------------------------------------------------+ 2470*9880d681SAndroid Build Coastguard Worker| ``<8 x float>`` | Vector of 8 32-bit floating-point values. | 2471*9880d681SAndroid Build Coastguard Worker+-------------------+--------------------------------------------------+ 2472*9880d681SAndroid Build Coastguard Worker| ``<2 x i64>`` | Vector of 2 64-bit integer values. | 2473*9880d681SAndroid Build Coastguard Worker+-------------------+--------------------------------------------------+ 2474*9880d681SAndroid Build Coastguard Worker| ``<4 x i64*>`` | Vector of 4 pointers to 64-bit integer values. | 2475*9880d681SAndroid Build Coastguard Worker+-------------------+--------------------------------------------------+ 2476*9880d681SAndroid Build Coastguard Worker 2477*9880d681SAndroid Build Coastguard Worker.. _t_label: 2478*9880d681SAndroid Build Coastguard Worker 2479*9880d681SAndroid Build Coastguard WorkerLabel Type 2480*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^ 2481*9880d681SAndroid Build Coastguard Worker 2482*9880d681SAndroid Build Coastguard Worker:Overview: 2483*9880d681SAndroid Build Coastguard Worker 2484*9880d681SAndroid Build Coastguard WorkerThe label type represents code labels. 2485*9880d681SAndroid Build Coastguard Worker 2486*9880d681SAndroid Build Coastguard Worker:Syntax: 2487*9880d681SAndroid Build Coastguard Worker 2488*9880d681SAndroid Build Coastguard Worker:: 2489*9880d681SAndroid Build Coastguard Worker 2490*9880d681SAndroid Build Coastguard Worker label 2491*9880d681SAndroid Build Coastguard Worker 2492*9880d681SAndroid Build Coastguard Worker.. _t_token: 2493*9880d681SAndroid Build Coastguard Worker 2494*9880d681SAndroid Build Coastguard WorkerToken Type 2495*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^ 2496*9880d681SAndroid Build Coastguard Worker 2497*9880d681SAndroid Build Coastguard Worker:Overview: 2498*9880d681SAndroid Build Coastguard Worker 2499*9880d681SAndroid Build Coastguard WorkerThe token type is used when a value is associated with an instruction 2500*9880d681SAndroid Build Coastguard Workerbut all uses of the value must not attempt to introspect or obscure it. 2501*9880d681SAndroid Build Coastguard WorkerAs such, it is not appropriate to have a :ref:`phi <i_phi>` or 2502*9880d681SAndroid Build Coastguard Worker:ref:`select <i_select>` of type token. 2503*9880d681SAndroid Build Coastguard Worker 2504*9880d681SAndroid Build Coastguard Worker:Syntax: 2505*9880d681SAndroid Build Coastguard Worker 2506*9880d681SAndroid Build Coastguard Worker:: 2507*9880d681SAndroid Build Coastguard Worker 2508*9880d681SAndroid Build Coastguard Worker token 2509*9880d681SAndroid Build Coastguard Worker 2510*9880d681SAndroid Build Coastguard Worker 2511*9880d681SAndroid Build Coastguard Worker 2512*9880d681SAndroid Build Coastguard Worker.. _t_metadata: 2513*9880d681SAndroid Build Coastguard Worker 2514*9880d681SAndroid Build Coastguard WorkerMetadata Type 2515*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^ 2516*9880d681SAndroid Build Coastguard Worker 2517*9880d681SAndroid Build Coastguard Worker:Overview: 2518*9880d681SAndroid Build Coastguard Worker 2519*9880d681SAndroid Build Coastguard WorkerThe metadata type represents embedded metadata. No derived types may be 2520*9880d681SAndroid Build Coastguard Workercreated from metadata except for :ref:`function <t_function>` arguments. 2521*9880d681SAndroid Build Coastguard Worker 2522*9880d681SAndroid Build Coastguard Worker:Syntax: 2523*9880d681SAndroid Build Coastguard Worker 2524*9880d681SAndroid Build Coastguard Worker:: 2525*9880d681SAndroid Build Coastguard Worker 2526*9880d681SAndroid Build Coastguard Worker metadata 2527*9880d681SAndroid Build Coastguard Worker 2528*9880d681SAndroid Build Coastguard Worker.. _t_aggregate: 2529*9880d681SAndroid Build Coastguard Worker 2530*9880d681SAndroid Build Coastguard WorkerAggregate Types 2531*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^ 2532*9880d681SAndroid Build Coastguard Worker 2533*9880d681SAndroid Build Coastguard WorkerAggregate Types are a subset of derived types that can contain multiple 2534*9880d681SAndroid Build Coastguard Workermember types. :ref:`Arrays <t_array>` and :ref:`structs <t_struct>` are 2535*9880d681SAndroid Build Coastguard Workeraggregate types. :ref:`Vectors <t_vector>` are not considered to be 2536*9880d681SAndroid Build Coastguard Workeraggregate types. 2537*9880d681SAndroid Build Coastguard Worker 2538*9880d681SAndroid Build Coastguard Worker.. _t_array: 2539*9880d681SAndroid Build Coastguard Worker 2540*9880d681SAndroid Build Coastguard WorkerArray Type 2541*9880d681SAndroid Build Coastguard Worker"""""""""" 2542*9880d681SAndroid Build Coastguard Worker 2543*9880d681SAndroid Build Coastguard Worker:Overview: 2544*9880d681SAndroid Build Coastguard Worker 2545*9880d681SAndroid Build Coastguard WorkerThe array type is a very simple derived type that arranges elements 2546*9880d681SAndroid Build Coastguard Workersequentially in memory. The array type requires a size (number of 2547*9880d681SAndroid Build Coastguard Workerelements) and an underlying data type. 2548*9880d681SAndroid Build Coastguard Worker 2549*9880d681SAndroid Build Coastguard Worker:Syntax: 2550*9880d681SAndroid Build Coastguard Worker 2551*9880d681SAndroid Build Coastguard Worker:: 2552*9880d681SAndroid Build Coastguard Worker 2553*9880d681SAndroid Build Coastguard Worker [<# elements> x <elementtype>] 2554*9880d681SAndroid Build Coastguard Worker 2555*9880d681SAndroid Build Coastguard WorkerThe number of elements is a constant integer value; ``elementtype`` may 2556*9880d681SAndroid Build Coastguard Workerbe any type with a size. 2557*9880d681SAndroid Build Coastguard Worker 2558*9880d681SAndroid Build Coastguard Worker:Examples: 2559*9880d681SAndroid Build Coastguard Worker 2560*9880d681SAndroid Build Coastguard Worker+------------------+--------------------------------------+ 2561*9880d681SAndroid Build Coastguard Worker| ``[40 x i32]`` | Array of 40 32-bit integer values. | 2562*9880d681SAndroid Build Coastguard Worker+------------------+--------------------------------------+ 2563*9880d681SAndroid Build Coastguard Worker| ``[41 x i32]`` | Array of 41 32-bit integer values. | 2564*9880d681SAndroid Build Coastguard Worker+------------------+--------------------------------------+ 2565*9880d681SAndroid Build Coastguard Worker| ``[4 x i8]`` | Array of 4 8-bit integer values. | 2566*9880d681SAndroid Build Coastguard Worker+------------------+--------------------------------------+ 2567*9880d681SAndroid Build Coastguard Worker 2568*9880d681SAndroid Build Coastguard WorkerHere are some examples of multidimensional arrays: 2569*9880d681SAndroid Build Coastguard Worker 2570*9880d681SAndroid Build Coastguard Worker+-----------------------------+----------------------------------------------------------+ 2571*9880d681SAndroid Build Coastguard Worker| ``[3 x [4 x i32]]`` | 3x4 array of 32-bit integer values. | 2572*9880d681SAndroid Build Coastguard Worker+-----------------------------+----------------------------------------------------------+ 2573*9880d681SAndroid Build Coastguard Worker| ``[12 x [10 x float]]`` | 12x10 array of single precision floating point values. | 2574*9880d681SAndroid Build Coastguard Worker+-----------------------------+----------------------------------------------------------+ 2575*9880d681SAndroid Build Coastguard Worker| ``[2 x [3 x [4 x i16]]]`` | 2x3x4 array of 16-bit integer values. | 2576*9880d681SAndroid Build Coastguard Worker+-----------------------------+----------------------------------------------------------+ 2577*9880d681SAndroid Build Coastguard Worker 2578*9880d681SAndroid Build Coastguard WorkerThere is no restriction on indexing beyond the end of the array implied 2579*9880d681SAndroid Build Coastguard Workerby a static type (though there are restrictions on indexing beyond the 2580*9880d681SAndroid Build Coastguard Workerbounds of an allocated object in some cases). This means that 2581*9880d681SAndroid Build Coastguard Workersingle-dimension 'variable sized array' addressing can be implemented in 2582*9880d681SAndroid Build Coastguard WorkerLLVM with a zero length array type. An implementation of 'pascal style 2583*9880d681SAndroid Build Coastguard Workerarrays' in LLVM could use the type "``{ i32, [0 x float]}``", for 2584*9880d681SAndroid Build Coastguard Workerexample. 2585*9880d681SAndroid Build Coastguard Worker 2586*9880d681SAndroid Build Coastguard Worker.. _t_struct: 2587*9880d681SAndroid Build Coastguard Worker 2588*9880d681SAndroid Build Coastguard WorkerStructure Type 2589*9880d681SAndroid Build Coastguard Worker"""""""""""""" 2590*9880d681SAndroid Build Coastguard Worker 2591*9880d681SAndroid Build Coastguard Worker:Overview: 2592*9880d681SAndroid Build Coastguard Worker 2593*9880d681SAndroid Build Coastguard WorkerThe structure type is used to represent a collection of data members 2594*9880d681SAndroid Build Coastguard Workertogether in memory. The elements of a structure may be any type that has 2595*9880d681SAndroid Build Coastguard Workera size. 2596*9880d681SAndroid Build Coastguard Worker 2597*9880d681SAndroid Build Coastguard WorkerStructures in memory are accessed using '``load``' and '``store``' by 2598*9880d681SAndroid Build Coastguard Workergetting a pointer to a field with the '``getelementptr``' instruction. 2599*9880d681SAndroid Build Coastguard WorkerStructures in registers are accessed using the '``extractvalue``' and 2600*9880d681SAndroid Build Coastguard Worker'``insertvalue``' instructions. 2601*9880d681SAndroid Build Coastguard Worker 2602*9880d681SAndroid Build Coastguard WorkerStructures may optionally be "packed" structures, which indicate that 2603*9880d681SAndroid Build Coastguard Workerthe alignment of the struct is one byte, and that there is no padding 2604*9880d681SAndroid Build Coastguard Workerbetween the elements. In non-packed structs, padding between field types 2605*9880d681SAndroid Build Coastguard Workeris inserted as defined by the DataLayout string in the module, which is 2606*9880d681SAndroid Build Coastguard Workerrequired to match what the underlying code generator expects. 2607*9880d681SAndroid Build Coastguard Worker 2608*9880d681SAndroid Build Coastguard WorkerStructures can either be "literal" or "identified". A literal structure 2609*9880d681SAndroid Build Coastguard Workeris defined inline with other types (e.g. ``{i32, i32}*``) whereas 2610*9880d681SAndroid Build Coastguard Workeridentified types are always defined at the top level with a name. 2611*9880d681SAndroid Build Coastguard WorkerLiteral types are uniqued by their contents and can never be recursive 2612*9880d681SAndroid Build Coastguard Workeror opaque since there is no way to write one. Identified types can be 2613*9880d681SAndroid Build Coastguard Workerrecursive, can be opaqued, and are never uniqued. 2614*9880d681SAndroid Build Coastguard Worker 2615*9880d681SAndroid Build Coastguard Worker:Syntax: 2616*9880d681SAndroid Build Coastguard Worker 2617*9880d681SAndroid Build Coastguard Worker:: 2618*9880d681SAndroid Build Coastguard Worker 2619*9880d681SAndroid Build Coastguard Worker %T1 = type { <type list> } ; Identified normal struct type 2620*9880d681SAndroid Build Coastguard Worker %T2 = type <{ <type list> }> ; Identified packed struct type 2621*9880d681SAndroid Build Coastguard Worker 2622*9880d681SAndroid Build Coastguard Worker:Examples: 2623*9880d681SAndroid Build Coastguard Worker 2624*9880d681SAndroid Build Coastguard Worker+------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 2625*9880d681SAndroid Build Coastguard Worker| ``{ i32, i32, i32 }`` | A triple of three ``i32`` values | 2626*9880d681SAndroid Build Coastguard Worker+------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 2627*9880d681SAndroid Build Coastguard Worker| ``{ 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``. | 2628*9880d681SAndroid Build Coastguard Worker+------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 2629*9880d681SAndroid Build Coastguard Worker| ``<{ i8, i32 }>`` | A packed struct known to be 5 bytes in size. | 2630*9880d681SAndroid Build Coastguard Worker+------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 2631*9880d681SAndroid Build Coastguard Worker 2632*9880d681SAndroid Build Coastguard Worker.. _t_opaque: 2633*9880d681SAndroid Build Coastguard Worker 2634*9880d681SAndroid Build Coastguard WorkerOpaque Structure Types 2635*9880d681SAndroid Build Coastguard Worker"""""""""""""""""""""" 2636*9880d681SAndroid Build Coastguard Worker 2637*9880d681SAndroid Build Coastguard Worker:Overview: 2638*9880d681SAndroid Build Coastguard Worker 2639*9880d681SAndroid Build Coastguard WorkerOpaque structure types are used to represent named structure types that 2640*9880d681SAndroid Build Coastguard Workerdo not have a body specified. This corresponds (for example) to the C 2641*9880d681SAndroid Build Coastguard Workernotion of a forward declared structure. 2642*9880d681SAndroid Build Coastguard Worker 2643*9880d681SAndroid Build Coastguard Worker:Syntax: 2644*9880d681SAndroid Build Coastguard Worker 2645*9880d681SAndroid Build Coastguard Worker:: 2646*9880d681SAndroid Build Coastguard Worker 2647*9880d681SAndroid Build Coastguard Worker %X = type opaque 2648*9880d681SAndroid Build Coastguard Worker %52 = type opaque 2649*9880d681SAndroid Build Coastguard Worker 2650*9880d681SAndroid Build Coastguard Worker:Examples: 2651*9880d681SAndroid Build Coastguard Worker 2652*9880d681SAndroid Build Coastguard Worker+--------------+-------------------+ 2653*9880d681SAndroid Build Coastguard Worker| ``opaque`` | An opaque type. | 2654*9880d681SAndroid Build Coastguard Worker+--------------+-------------------+ 2655*9880d681SAndroid Build Coastguard Worker 2656*9880d681SAndroid Build Coastguard Worker.. _constants: 2657*9880d681SAndroid Build Coastguard Worker 2658*9880d681SAndroid Build Coastguard WorkerConstants 2659*9880d681SAndroid Build Coastguard Worker========= 2660*9880d681SAndroid Build Coastguard Worker 2661*9880d681SAndroid Build Coastguard WorkerLLVM has several different basic types of constants. This section 2662*9880d681SAndroid Build Coastguard Workerdescribes them all and their syntax. 2663*9880d681SAndroid Build Coastguard Worker 2664*9880d681SAndroid Build Coastguard WorkerSimple Constants 2665*9880d681SAndroid Build Coastguard Worker---------------- 2666*9880d681SAndroid Build Coastguard Worker 2667*9880d681SAndroid Build Coastguard Worker**Boolean constants** 2668*9880d681SAndroid Build Coastguard Worker The two strings '``true``' and '``false``' are both valid constants 2669*9880d681SAndroid Build Coastguard Worker of the ``i1`` type. 2670*9880d681SAndroid Build Coastguard Worker**Integer constants** 2671*9880d681SAndroid Build Coastguard Worker Standard integers (such as '4') are constants of the 2672*9880d681SAndroid Build Coastguard Worker :ref:`integer <t_integer>` type. Negative numbers may be used with 2673*9880d681SAndroid Build Coastguard Worker integer types. 2674*9880d681SAndroid Build Coastguard Worker**Floating point constants** 2675*9880d681SAndroid Build Coastguard Worker Floating point constants use standard decimal notation (e.g. 2676*9880d681SAndroid Build Coastguard Worker 123.421), exponential notation (e.g. 1.23421e+2), or a more precise 2677*9880d681SAndroid Build Coastguard Worker hexadecimal notation (see below). The assembler requires the exact 2678*9880d681SAndroid Build Coastguard Worker decimal value of a floating-point constant. For example, the 2679*9880d681SAndroid Build Coastguard Worker assembler accepts 1.25 but rejects 1.3 because 1.3 is a repeating 2680*9880d681SAndroid Build Coastguard Worker decimal in binary. Floating point constants must have a :ref:`floating 2681*9880d681SAndroid Build Coastguard Worker point <t_floating>` type. 2682*9880d681SAndroid Build Coastguard Worker**Null pointer constants** 2683*9880d681SAndroid Build Coastguard Worker The identifier '``null``' is recognized as a null pointer constant 2684*9880d681SAndroid Build Coastguard Worker and must be of :ref:`pointer type <t_pointer>`. 2685*9880d681SAndroid Build Coastguard Worker**Token constants** 2686*9880d681SAndroid Build Coastguard Worker The identifier '``none``' is recognized as an empty token constant 2687*9880d681SAndroid Build Coastguard Worker and must be of :ref:`token type <t_token>`. 2688*9880d681SAndroid Build Coastguard Worker 2689*9880d681SAndroid Build Coastguard WorkerThe one non-intuitive notation for constants is the hexadecimal form of 2690*9880d681SAndroid Build Coastguard Workerfloating point constants. For example, the form 2691*9880d681SAndroid Build Coastguard Worker'``double 0x432ff973cafa8000``' is equivalent to (but harder to read 2692*9880d681SAndroid Build Coastguard Workerthan) '``double 4.5e+15``'. The only time hexadecimal floating point 2693*9880d681SAndroid Build Coastguard Workerconstants are required (and the only time that they are generated by the 2694*9880d681SAndroid Build Coastguard Workerdisassembler) is when a floating point constant must be emitted but it 2695*9880d681SAndroid Build Coastguard Workercannot be represented as a decimal floating point number in a reasonable 2696*9880d681SAndroid Build Coastguard Workernumber of digits. For example, NaN's, infinities, and other special 2697*9880d681SAndroid Build Coastguard Workervalues are represented in their IEEE hexadecimal format so that assembly 2698*9880d681SAndroid Build Coastguard Workerand disassembly do not cause any bits to change in the constants. 2699*9880d681SAndroid Build Coastguard Worker 2700*9880d681SAndroid Build Coastguard WorkerWhen using the hexadecimal form, constants of types half, float, and 2701*9880d681SAndroid Build Coastguard Workerdouble are represented using the 16-digit form shown above (which 2702*9880d681SAndroid Build Coastguard Workermatches the IEEE754 representation for double); half and float values 2703*9880d681SAndroid Build Coastguard Workermust, however, be exactly representable as IEEE 754 half and single 2704*9880d681SAndroid Build Coastguard Workerprecision, respectively. Hexadecimal format is always used for long 2705*9880d681SAndroid Build Coastguard Workerdouble, and there are three forms of long double. The 80-bit format used 2706*9880d681SAndroid Build Coastguard Workerby x86 is represented as ``0xK`` followed by 20 hexadecimal digits. The 2707*9880d681SAndroid Build Coastguard Worker128-bit format used by PowerPC (two adjacent doubles) is represented by 2708*9880d681SAndroid Build Coastguard Worker``0xM`` followed by 32 hexadecimal digits. The IEEE 128-bit format is 2709*9880d681SAndroid Build Coastguard Workerrepresented by ``0xL`` followed by 32 hexadecimal digits. Long doubles 2710*9880d681SAndroid Build Coastguard Workerwill only work if they match the long double format on your target. 2711*9880d681SAndroid Build Coastguard WorkerThe IEEE 16-bit format (half precision) is represented by ``0xH`` 2712*9880d681SAndroid Build Coastguard Workerfollowed by 4 hexadecimal digits. All hexadecimal formats are big-endian 2713*9880d681SAndroid Build Coastguard Worker(sign bit at the left). 2714*9880d681SAndroid Build Coastguard Worker 2715*9880d681SAndroid Build Coastguard WorkerThere are no constants of type x86_mmx. 2716*9880d681SAndroid Build Coastguard Worker 2717*9880d681SAndroid Build Coastguard Worker.. _complexconstants: 2718*9880d681SAndroid Build Coastguard Worker 2719*9880d681SAndroid Build Coastguard WorkerComplex Constants 2720*9880d681SAndroid Build Coastguard Worker----------------- 2721*9880d681SAndroid Build Coastguard Worker 2722*9880d681SAndroid Build Coastguard WorkerComplex constants are a (potentially recursive) combination of simple 2723*9880d681SAndroid Build Coastguard Workerconstants and smaller complex constants. 2724*9880d681SAndroid Build Coastguard Worker 2725*9880d681SAndroid Build Coastguard Worker**Structure constants** 2726*9880d681SAndroid Build Coastguard Worker Structure constants are represented with notation similar to 2727*9880d681SAndroid Build Coastguard Worker structure type definitions (a comma separated list of elements, 2728*9880d681SAndroid Build Coastguard Worker surrounded by braces (``{}``)). For example: 2729*9880d681SAndroid Build Coastguard Worker "``{ i32 4, float 17.0, i32* @G }``", where "``@G``" is declared as 2730*9880d681SAndroid Build Coastguard Worker "``@G = external global i32``". Structure constants must have 2731*9880d681SAndroid Build Coastguard Worker :ref:`structure type <t_struct>`, and the number and types of elements 2732*9880d681SAndroid Build Coastguard Worker must match those specified by the type. 2733*9880d681SAndroid Build Coastguard Worker**Array constants** 2734*9880d681SAndroid Build Coastguard Worker Array constants are represented with notation similar to array type 2735*9880d681SAndroid Build Coastguard Worker definitions (a comma separated list of elements, surrounded by 2736*9880d681SAndroid Build Coastguard Worker square brackets (``[]``)). For example: 2737*9880d681SAndroid Build Coastguard Worker "``[ i32 42, i32 11, i32 74 ]``". Array constants must have 2738*9880d681SAndroid Build Coastguard Worker :ref:`array type <t_array>`, and the number and types of elements must 2739*9880d681SAndroid Build Coastguard Worker match those specified by the type. As a special case, character array 2740*9880d681SAndroid Build Coastguard Worker constants may also be represented as a double-quoted string using the ``c`` 2741*9880d681SAndroid Build Coastguard Worker prefix. For example: "``c"Hello World\0A\00"``". 2742*9880d681SAndroid Build Coastguard Worker**Vector constants** 2743*9880d681SAndroid Build Coastguard Worker Vector constants are represented with notation similar to vector 2744*9880d681SAndroid Build Coastguard Worker type definitions (a comma separated list of elements, surrounded by 2745*9880d681SAndroid Build Coastguard Worker less-than/greater-than's (``<>``)). For example: 2746*9880d681SAndroid Build Coastguard Worker "``< i32 42, i32 11, i32 74, i32 100 >``". Vector constants 2747*9880d681SAndroid Build Coastguard Worker must have :ref:`vector type <t_vector>`, and the number and types of 2748*9880d681SAndroid Build Coastguard Worker elements must match those specified by the type. 2749*9880d681SAndroid Build Coastguard Worker**Zero initialization** 2750*9880d681SAndroid Build Coastguard Worker The string '``zeroinitializer``' can be used to zero initialize a 2751*9880d681SAndroid Build Coastguard Worker value to zero of *any* type, including scalar and 2752*9880d681SAndroid Build Coastguard Worker :ref:`aggregate <t_aggregate>` types. This is often used to avoid 2753*9880d681SAndroid Build Coastguard Worker having to print large zero initializers (e.g. for large arrays) and 2754*9880d681SAndroid Build Coastguard Worker is always exactly equivalent to using explicit zero initializers. 2755*9880d681SAndroid Build Coastguard Worker**Metadata node** 2756*9880d681SAndroid Build Coastguard Worker A metadata node is a constant tuple without types. For example: 2757*9880d681SAndroid Build Coastguard Worker "``!{!0, !{!2, !0}, !"test"}``". Metadata can reference constant values, 2758*9880d681SAndroid Build Coastguard Worker for example: "``!{!0, i32 0, i8* @global, i64 (i64)* @function, !"str"}``". 2759*9880d681SAndroid Build Coastguard Worker Unlike other typed constants that are meant to be interpreted as part of 2760*9880d681SAndroid Build Coastguard Worker the instruction stream, metadata is a place to attach additional 2761*9880d681SAndroid Build Coastguard Worker information such as debug info. 2762*9880d681SAndroid Build Coastguard Worker 2763*9880d681SAndroid Build Coastguard WorkerGlobal Variable and Function Addresses 2764*9880d681SAndroid Build Coastguard Worker-------------------------------------- 2765*9880d681SAndroid Build Coastguard Worker 2766*9880d681SAndroid Build Coastguard WorkerThe addresses of :ref:`global variables <globalvars>` and 2767*9880d681SAndroid Build Coastguard Worker:ref:`functions <functionstructure>` are always implicitly valid 2768*9880d681SAndroid Build Coastguard Worker(link-time) constants. These constants are explicitly referenced when 2769*9880d681SAndroid Build Coastguard Workerthe :ref:`identifier for the global <identifiers>` is used and always have 2770*9880d681SAndroid Build Coastguard Worker:ref:`pointer <t_pointer>` type. For example, the following is a legal LLVM 2771*9880d681SAndroid Build Coastguard Workerfile: 2772*9880d681SAndroid Build Coastguard Worker 2773*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 2774*9880d681SAndroid Build Coastguard Worker 2775*9880d681SAndroid Build Coastguard Worker @X = global i32 17 2776*9880d681SAndroid Build Coastguard Worker @Y = global i32 42 2777*9880d681SAndroid Build Coastguard Worker @Z = global [2 x i32*] [ i32* @X, i32* @Y ] 2778*9880d681SAndroid Build Coastguard Worker 2779*9880d681SAndroid Build Coastguard Worker.. _undefvalues: 2780*9880d681SAndroid Build Coastguard Worker 2781*9880d681SAndroid Build Coastguard WorkerUndefined Values 2782*9880d681SAndroid Build Coastguard Worker---------------- 2783*9880d681SAndroid Build Coastguard Worker 2784*9880d681SAndroid Build Coastguard WorkerThe string '``undef``' can be used anywhere a constant is expected, and 2785*9880d681SAndroid Build Coastguard Workerindicates that the user of the value may receive an unspecified 2786*9880d681SAndroid Build Coastguard Workerbit-pattern. Undefined values may be of any type (other than '``label``' 2787*9880d681SAndroid Build Coastguard Workeror '``void``') and be used anywhere a constant is permitted. 2788*9880d681SAndroid Build Coastguard Worker 2789*9880d681SAndroid Build Coastguard WorkerUndefined values are useful because they indicate to the compiler that 2790*9880d681SAndroid Build Coastguard Workerthe program is well defined no matter what value is used. This gives the 2791*9880d681SAndroid Build Coastguard Workercompiler more freedom to optimize. Here are some examples of 2792*9880d681SAndroid Build Coastguard Worker(potentially surprising) transformations that are valid (in pseudo IR): 2793*9880d681SAndroid Build Coastguard Worker 2794*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 2795*9880d681SAndroid Build Coastguard Worker 2796*9880d681SAndroid Build Coastguard Worker %A = add %X, undef 2797*9880d681SAndroid Build Coastguard Worker %B = sub %X, undef 2798*9880d681SAndroid Build Coastguard Worker %C = xor %X, undef 2799*9880d681SAndroid Build Coastguard Worker Safe: 2800*9880d681SAndroid Build Coastguard Worker %A = undef 2801*9880d681SAndroid Build Coastguard Worker %B = undef 2802*9880d681SAndroid Build Coastguard Worker %C = undef 2803*9880d681SAndroid Build Coastguard Worker 2804*9880d681SAndroid Build Coastguard WorkerThis is safe because all of the output bits are affected by the undef 2805*9880d681SAndroid Build Coastguard Workerbits. Any output bit can have a zero or one depending on the input bits. 2806*9880d681SAndroid Build Coastguard Worker 2807*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 2808*9880d681SAndroid Build Coastguard Worker 2809*9880d681SAndroid Build Coastguard Worker %A = or %X, undef 2810*9880d681SAndroid Build Coastguard Worker %B = and %X, undef 2811*9880d681SAndroid Build Coastguard Worker Safe: 2812*9880d681SAndroid Build Coastguard Worker %A = -1 2813*9880d681SAndroid Build Coastguard Worker %B = 0 2814*9880d681SAndroid Build Coastguard Worker Unsafe: 2815*9880d681SAndroid Build Coastguard Worker %A = undef 2816*9880d681SAndroid Build Coastguard Worker %B = undef 2817*9880d681SAndroid Build Coastguard Worker 2818*9880d681SAndroid Build Coastguard WorkerThese logical operations have bits that are not always affected by the 2819*9880d681SAndroid Build Coastguard Workerinput. For example, if ``%X`` has a zero bit, then the output of the 2820*9880d681SAndroid Build Coastguard Worker'``and``' operation will always be a zero for that bit, no matter what 2821*9880d681SAndroid Build Coastguard Workerthe corresponding bit from the '``undef``' is. As such, it is unsafe to 2822*9880d681SAndroid Build Coastguard Workeroptimize or assume that the result of the '``and``' is '``undef``'. 2823*9880d681SAndroid Build Coastguard WorkerHowever, it is safe to assume that all bits of the '``undef``' could be 2824*9880d681SAndroid Build Coastguard Worker0, and optimize the '``and``' to 0. Likewise, it is safe to assume that 2825*9880d681SAndroid Build Coastguard Workerall the bits of the '``undef``' operand to the '``or``' could be set, 2826*9880d681SAndroid Build Coastguard Workerallowing the '``or``' to be folded to -1. 2827*9880d681SAndroid Build Coastguard Worker 2828*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 2829*9880d681SAndroid Build Coastguard Worker 2830*9880d681SAndroid Build Coastguard Worker %A = select undef, %X, %Y 2831*9880d681SAndroid Build Coastguard Worker %B = select undef, 42, %Y 2832*9880d681SAndroid Build Coastguard Worker %C = select %X, %Y, undef 2833*9880d681SAndroid Build Coastguard Worker Safe: 2834*9880d681SAndroid Build Coastguard Worker %A = %X (or %Y) 2835*9880d681SAndroid Build Coastguard Worker %B = 42 (or %Y) 2836*9880d681SAndroid Build Coastguard Worker %C = %Y 2837*9880d681SAndroid Build Coastguard Worker Unsafe: 2838*9880d681SAndroid Build Coastguard Worker %A = undef 2839*9880d681SAndroid Build Coastguard Worker %B = undef 2840*9880d681SAndroid Build Coastguard Worker %C = undef 2841*9880d681SAndroid Build Coastguard Worker 2842*9880d681SAndroid Build Coastguard WorkerThis set of examples shows that undefined '``select``' (and conditional 2843*9880d681SAndroid Build Coastguard Workerbranch) conditions can go *either way*, but they have to come from one 2844*9880d681SAndroid Build Coastguard Workerof the two operands. In the ``%A`` example, if ``%X`` and ``%Y`` were 2845*9880d681SAndroid Build Coastguard Workerboth known to have a clear low bit, then ``%A`` would have to have a 2846*9880d681SAndroid Build Coastguard Workercleared low bit. However, in the ``%C`` example, the optimizer is 2847*9880d681SAndroid Build Coastguard Workerallowed to assume that the '``undef``' operand could be the same as 2848*9880d681SAndroid Build Coastguard Worker``%Y``, allowing the whole '``select``' to be eliminated. 2849*9880d681SAndroid Build Coastguard Worker 2850*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 2851*9880d681SAndroid Build Coastguard Worker 2852*9880d681SAndroid Build Coastguard Worker %A = xor undef, undef 2853*9880d681SAndroid Build Coastguard Worker 2854*9880d681SAndroid Build Coastguard Worker %B = undef 2855*9880d681SAndroid Build Coastguard Worker %C = xor %B, %B 2856*9880d681SAndroid Build Coastguard Worker 2857*9880d681SAndroid Build Coastguard Worker %D = undef 2858*9880d681SAndroid Build Coastguard Worker %E = icmp slt %D, 4 2859*9880d681SAndroid Build Coastguard Worker %F = icmp gte %D, 4 2860*9880d681SAndroid Build Coastguard Worker 2861*9880d681SAndroid Build Coastguard Worker Safe: 2862*9880d681SAndroid Build Coastguard Worker %A = undef 2863*9880d681SAndroid Build Coastguard Worker %B = undef 2864*9880d681SAndroid Build Coastguard Worker %C = undef 2865*9880d681SAndroid Build Coastguard Worker %D = undef 2866*9880d681SAndroid Build Coastguard Worker %E = undef 2867*9880d681SAndroid Build Coastguard Worker %F = undef 2868*9880d681SAndroid Build Coastguard Worker 2869*9880d681SAndroid Build Coastguard WorkerThis example points out that two '``undef``' operands are not 2870*9880d681SAndroid Build Coastguard Workernecessarily the same. This can be surprising to people (and also matches 2871*9880d681SAndroid Build Coastguard WorkerC semantics) where they assume that "``X^X``" is always zero, even if 2872*9880d681SAndroid Build Coastguard Worker``X`` is undefined. This isn't true for a number of reasons, but the 2873*9880d681SAndroid Build Coastguard Workershort answer is that an '``undef``' "variable" can arbitrarily change 2874*9880d681SAndroid Build Coastguard Workerits value over its "live range". This is true because the variable 2875*9880d681SAndroid Build Coastguard Workerdoesn't actually *have a live range*. Instead, the value is logically 2876*9880d681SAndroid Build Coastguard Workerread from arbitrary registers that happen to be around when needed, so 2877*9880d681SAndroid Build Coastguard Workerthe value is not necessarily consistent over time. In fact, ``%A`` and 2878*9880d681SAndroid Build Coastguard Worker``%C`` need to have the same semantics or the core LLVM "replace all 2879*9880d681SAndroid Build Coastguard Workeruses with" concept would not hold. 2880*9880d681SAndroid Build Coastguard Worker 2881*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 2882*9880d681SAndroid Build Coastguard Worker 2883*9880d681SAndroid Build Coastguard Worker %A = fdiv undef, %X 2884*9880d681SAndroid Build Coastguard Worker %B = fdiv %X, undef 2885*9880d681SAndroid Build Coastguard Worker Safe: 2886*9880d681SAndroid Build Coastguard Worker %A = undef 2887*9880d681SAndroid Build Coastguard Worker b: unreachable 2888*9880d681SAndroid Build Coastguard Worker 2889*9880d681SAndroid Build Coastguard WorkerThese examples show the crucial difference between an *undefined value* 2890*9880d681SAndroid Build Coastguard Workerand *undefined behavior*. An undefined value (like '``undef``') is 2891*9880d681SAndroid Build Coastguard Workerallowed to have an arbitrary bit-pattern. This means that the ``%A`` 2892*9880d681SAndroid Build Coastguard Workeroperation can be constant folded to '``undef``', because the '``undef``' 2893*9880d681SAndroid Build Coastguard Workercould be an SNaN, and ``fdiv`` is not (currently) defined on SNaN's. 2894*9880d681SAndroid Build Coastguard WorkerHowever, in the second example, we can make a more aggressive 2895*9880d681SAndroid Build Coastguard Workerassumption: because the ``undef`` is allowed to be an arbitrary value, 2896*9880d681SAndroid Build Coastguard Workerwe are allowed to assume that it could be zero. Since a divide by zero 2897*9880d681SAndroid Build Coastguard Workerhas *undefined behavior*, we are allowed to assume that the operation 2898*9880d681SAndroid Build Coastguard Workerdoes not execute at all. This allows us to delete the divide and all 2899*9880d681SAndroid Build Coastguard Workercode after it. Because the undefined operation "can't happen", the 2900*9880d681SAndroid Build Coastguard Workeroptimizer can assume that it occurs in dead code. 2901*9880d681SAndroid Build Coastguard Worker 2902*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 2903*9880d681SAndroid Build Coastguard Worker 2904*9880d681SAndroid Build Coastguard Worker a: store undef -> %X 2905*9880d681SAndroid Build Coastguard Worker b: store %X -> undef 2906*9880d681SAndroid Build Coastguard Worker Safe: 2907*9880d681SAndroid Build Coastguard Worker a: <deleted> 2908*9880d681SAndroid Build Coastguard Worker b: unreachable 2909*9880d681SAndroid Build Coastguard Worker 2910*9880d681SAndroid Build Coastguard WorkerThese examples reiterate the ``fdiv`` example: a store *of* an undefined 2911*9880d681SAndroid Build Coastguard Workervalue can be assumed to not have any effect; we can assume that the 2912*9880d681SAndroid Build Coastguard Workervalue is overwritten with bits that happen to match what was already 2913*9880d681SAndroid Build Coastguard Workerthere. However, a store *to* an undefined location could clobber 2914*9880d681SAndroid Build Coastguard Workerarbitrary memory, therefore, it has undefined behavior. 2915*9880d681SAndroid Build Coastguard Worker 2916*9880d681SAndroid Build Coastguard Worker.. _poisonvalues: 2917*9880d681SAndroid Build Coastguard Worker 2918*9880d681SAndroid Build Coastguard WorkerPoison Values 2919*9880d681SAndroid Build Coastguard Worker------------- 2920*9880d681SAndroid Build Coastguard Worker 2921*9880d681SAndroid Build Coastguard WorkerPoison values are similar to :ref:`undef values <undefvalues>`, however 2922*9880d681SAndroid Build Coastguard Workerthey also represent the fact that an instruction or constant expression 2923*9880d681SAndroid Build Coastguard Workerthat cannot evoke side effects has nevertheless detected a condition 2924*9880d681SAndroid Build Coastguard Workerthat results in undefined behavior. 2925*9880d681SAndroid Build Coastguard Worker 2926*9880d681SAndroid Build Coastguard WorkerThere is currently no way of representing a poison value in the IR; they 2927*9880d681SAndroid Build Coastguard Workeronly exist when produced by operations such as :ref:`add <i_add>` with 2928*9880d681SAndroid Build Coastguard Workerthe ``nsw`` flag. 2929*9880d681SAndroid Build Coastguard Worker 2930*9880d681SAndroid Build Coastguard WorkerPoison value behavior is defined in terms of value *dependence*: 2931*9880d681SAndroid Build Coastguard Worker 2932*9880d681SAndroid Build Coastguard Worker- Values other than :ref:`phi <i_phi>` nodes depend on their operands. 2933*9880d681SAndroid Build Coastguard Worker- :ref:`Phi <i_phi>` nodes depend on the operand corresponding to 2934*9880d681SAndroid Build Coastguard Worker their dynamic predecessor basic block. 2935*9880d681SAndroid Build Coastguard Worker- Function arguments depend on the corresponding actual argument values 2936*9880d681SAndroid Build Coastguard Worker in the dynamic callers of their functions. 2937*9880d681SAndroid Build Coastguard Worker- :ref:`Call <i_call>` instructions depend on the :ref:`ret <i_ret>` 2938*9880d681SAndroid Build Coastguard Worker instructions that dynamically transfer control back to them. 2939*9880d681SAndroid Build Coastguard Worker- :ref:`Invoke <i_invoke>` instructions depend on the 2940*9880d681SAndroid Build Coastguard Worker :ref:`ret <i_ret>`, :ref:`resume <i_resume>`, or exception-throwing 2941*9880d681SAndroid Build Coastguard Worker call instructions that dynamically transfer control back to them. 2942*9880d681SAndroid Build Coastguard Worker- Non-volatile loads and stores depend on the most recent stores to all 2943*9880d681SAndroid Build Coastguard Worker of the referenced memory addresses, following the order in the IR 2944*9880d681SAndroid Build Coastguard Worker (including loads and stores implied by intrinsics such as 2945*9880d681SAndroid Build Coastguard Worker :ref:`@llvm.memcpy <int_memcpy>`.) 2946*9880d681SAndroid Build Coastguard Worker- An instruction with externally visible side effects depends on the 2947*9880d681SAndroid Build Coastguard Worker most recent preceding instruction with externally visible side 2948*9880d681SAndroid Build Coastguard Worker effects, following the order in the IR. (This includes :ref:`volatile 2949*9880d681SAndroid Build Coastguard Worker operations <volatile>`.) 2950*9880d681SAndroid Build Coastguard Worker- An instruction *control-depends* on a :ref:`terminator 2951*9880d681SAndroid Build Coastguard Worker instruction <terminators>` if the terminator instruction has 2952*9880d681SAndroid Build Coastguard Worker multiple successors and the instruction is always executed when 2953*9880d681SAndroid Build Coastguard Worker control transfers to one of the successors, and may not be executed 2954*9880d681SAndroid Build Coastguard Worker when control is transferred to another. 2955*9880d681SAndroid Build Coastguard Worker- Additionally, an instruction also *control-depends* on a terminator 2956*9880d681SAndroid Build Coastguard Worker instruction if the set of instructions it otherwise depends on would 2957*9880d681SAndroid Build Coastguard Worker be different if the terminator had transferred control to a different 2958*9880d681SAndroid Build Coastguard Worker successor. 2959*9880d681SAndroid Build Coastguard Worker- Dependence is transitive. 2960*9880d681SAndroid Build Coastguard Worker 2961*9880d681SAndroid Build Coastguard WorkerPoison values have the same behavior as :ref:`undef values <undefvalues>`, 2962*9880d681SAndroid Build Coastguard Workerwith the additional effect that any instruction that has a *dependence* 2963*9880d681SAndroid Build Coastguard Workeron a poison value has undefined behavior. 2964*9880d681SAndroid Build Coastguard Worker 2965*9880d681SAndroid Build Coastguard WorkerHere are some examples: 2966*9880d681SAndroid Build Coastguard Worker 2967*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 2968*9880d681SAndroid Build Coastguard Worker 2969*9880d681SAndroid Build Coastguard Worker entry: 2970*9880d681SAndroid Build Coastguard Worker %poison = sub nuw i32 0, 1 ; Results in a poison value. 2971*9880d681SAndroid Build Coastguard Worker %still_poison = and i32 %poison, 0 ; 0, but also poison. 2972*9880d681SAndroid Build Coastguard Worker %poison_yet_again = getelementptr i32, i32* @h, i32 %still_poison 2973*9880d681SAndroid Build Coastguard Worker store i32 0, i32* %poison_yet_again ; memory at @h[0] is poisoned 2974*9880d681SAndroid Build Coastguard Worker 2975*9880d681SAndroid Build Coastguard Worker store i32 %poison, i32* @g ; Poison value stored to memory. 2976*9880d681SAndroid Build Coastguard Worker %poison2 = load i32, i32* @g ; Poison value loaded back from memory. 2977*9880d681SAndroid Build Coastguard Worker 2978*9880d681SAndroid Build Coastguard Worker store volatile i32 %poison, i32* @g ; External observation; undefined behavior. 2979*9880d681SAndroid Build Coastguard Worker 2980*9880d681SAndroid Build Coastguard Worker %narrowaddr = bitcast i32* @g to i16* 2981*9880d681SAndroid Build Coastguard Worker %wideaddr = bitcast i32* @g to i64* 2982*9880d681SAndroid Build Coastguard Worker %poison3 = load i16, i16* %narrowaddr ; Returns a poison value. 2983*9880d681SAndroid Build Coastguard Worker %poison4 = load i64, i64* %wideaddr ; Returns a poison value. 2984*9880d681SAndroid Build Coastguard Worker 2985*9880d681SAndroid Build Coastguard Worker %cmp = icmp slt i32 %poison, 0 ; Returns a poison value. 2986*9880d681SAndroid Build Coastguard Worker br i1 %cmp, label %true, label %end ; Branch to either destination. 2987*9880d681SAndroid Build Coastguard Worker 2988*9880d681SAndroid Build Coastguard Worker true: 2989*9880d681SAndroid Build Coastguard Worker store volatile i32 0, i32* @g ; This is control-dependent on %cmp, so 2990*9880d681SAndroid Build Coastguard Worker ; it has undefined behavior. 2991*9880d681SAndroid Build Coastguard Worker br label %end 2992*9880d681SAndroid Build Coastguard Worker 2993*9880d681SAndroid Build Coastguard Worker end: 2994*9880d681SAndroid Build Coastguard Worker %p = phi i32 [ 0, %entry ], [ 1, %true ] 2995*9880d681SAndroid Build Coastguard Worker ; Both edges into this PHI are 2996*9880d681SAndroid Build Coastguard Worker ; control-dependent on %cmp, so this 2997*9880d681SAndroid Build Coastguard Worker ; always results in a poison value. 2998*9880d681SAndroid Build Coastguard Worker 2999*9880d681SAndroid Build Coastguard Worker store volatile i32 0, i32* @g ; This would depend on the store in %true 3000*9880d681SAndroid Build Coastguard Worker ; if %cmp is true, or the store in %entry 3001*9880d681SAndroid Build Coastguard Worker ; otherwise, so this is undefined behavior. 3002*9880d681SAndroid Build Coastguard Worker 3003*9880d681SAndroid Build Coastguard Worker br i1 %cmp, label %second_true, label %second_end 3004*9880d681SAndroid Build Coastguard Worker ; The same branch again, but this time the 3005*9880d681SAndroid Build Coastguard Worker ; true block doesn't have side effects. 3006*9880d681SAndroid Build Coastguard Worker 3007*9880d681SAndroid Build Coastguard Worker second_true: 3008*9880d681SAndroid Build Coastguard Worker ; No side effects! 3009*9880d681SAndroid Build Coastguard Worker ret void 3010*9880d681SAndroid Build Coastguard Worker 3011*9880d681SAndroid Build Coastguard Worker second_end: 3012*9880d681SAndroid Build Coastguard Worker store volatile i32 0, i32* @g ; This time, the instruction always depends 3013*9880d681SAndroid Build Coastguard Worker ; on the store in %end. Also, it is 3014*9880d681SAndroid Build Coastguard Worker ; control-equivalent to %end, so this is 3015*9880d681SAndroid Build Coastguard Worker ; well-defined (ignoring earlier undefined 3016*9880d681SAndroid Build Coastguard Worker ; behavior in this example). 3017*9880d681SAndroid Build Coastguard Worker 3018*9880d681SAndroid Build Coastguard Worker.. _blockaddress: 3019*9880d681SAndroid Build Coastguard Worker 3020*9880d681SAndroid Build Coastguard WorkerAddresses of Basic Blocks 3021*9880d681SAndroid Build Coastguard Worker------------------------- 3022*9880d681SAndroid Build Coastguard Worker 3023*9880d681SAndroid Build Coastguard Worker``blockaddress(@function, %block)`` 3024*9880d681SAndroid Build Coastguard Worker 3025*9880d681SAndroid Build Coastguard WorkerThe '``blockaddress``' constant computes the address of the specified 3026*9880d681SAndroid Build Coastguard Workerbasic block in the specified function, and always has an ``i8*`` type. 3027*9880d681SAndroid Build Coastguard WorkerTaking the address of the entry block is illegal. 3028*9880d681SAndroid Build Coastguard Worker 3029*9880d681SAndroid Build Coastguard WorkerThis value only has defined behavior when used as an operand to the 3030*9880d681SAndroid Build Coastguard Worker':ref:`indirectbr <i_indirectbr>`' instruction, or for comparisons 3031*9880d681SAndroid Build Coastguard Workeragainst null. Pointer equality tests between labels addresses results in 3032*9880d681SAndroid Build Coastguard Workerundefined behavior --- though, again, comparison against null is ok, and 3033*9880d681SAndroid Build Coastguard Workerno label is equal to the null pointer. This may be passed around as an 3034*9880d681SAndroid Build Coastguard Workeropaque pointer sized value as long as the bits are not inspected. This 3035*9880d681SAndroid Build Coastguard Workerallows ``ptrtoint`` and arithmetic to be performed on these values so 3036*9880d681SAndroid Build Coastguard Workerlong as the original value is reconstituted before the ``indirectbr`` 3037*9880d681SAndroid Build Coastguard Workerinstruction. 3038*9880d681SAndroid Build Coastguard Worker 3039*9880d681SAndroid Build Coastguard WorkerFinally, some targets may provide defined semantics when using the value 3040*9880d681SAndroid Build Coastguard Workeras the operand to an inline assembly, but that is target specific. 3041*9880d681SAndroid Build Coastguard Worker 3042*9880d681SAndroid Build Coastguard Worker.. _constantexprs: 3043*9880d681SAndroid Build Coastguard Worker 3044*9880d681SAndroid Build Coastguard WorkerConstant Expressions 3045*9880d681SAndroid Build Coastguard Worker-------------------- 3046*9880d681SAndroid Build Coastguard Worker 3047*9880d681SAndroid Build Coastguard WorkerConstant expressions are used to allow expressions involving other 3048*9880d681SAndroid Build Coastguard Workerconstants to be used as constants. Constant expressions may be of any 3049*9880d681SAndroid Build Coastguard Worker:ref:`first class <t_firstclass>` type and may involve any LLVM operation 3050*9880d681SAndroid Build Coastguard Workerthat does not have side effects (e.g. load and call are not supported). 3051*9880d681SAndroid Build Coastguard WorkerThe following is the syntax for constant expressions: 3052*9880d681SAndroid Build Coastguard Worker 3053*9880d681SAndroid Build Coastguard Worker``trunc (CST to TYPE)`` 3054*9880d681SAndroid Build Coastguard Worker Truncate a constant to another type. The bit size of CST must be 3055*9880d681SAndroid Build Coastguard Worker larger than the bit size of TYPE. Both types must be integers. 3056*9880d681SAndroid Build Coastguard Worker``zext (CST to TYPE)`` 3057*9880d681SAndroid Build Coastguard Worker Zero extend a constant to another type. The bit size of CST must be 3058*9880d681SAndroid Build Coastguard Worker smaller than the bit size of TYPE. Both types must be integers. 3059*9880d681SAndroid Build Coastguard Worker``sext (CST to TYPE)`` 3060*9880d681SAndroid Build Coastguard Worker Sign extend a constant to another type. The bit size of CST must be 3061*9880d681SAndroid Build Coastguard Worker smaller than the bit size of TYPE. Both types must be integers. 3062*9880d681SAndroid Build Coastguard Worker``fptrunc (CST to TYPE)`` 3063*9880d681SAndroid Build Coastguard Worker Truncate a floating point constant to another floating point type. 3064*9880d681SAndroid Build Coastguard Worker The size of CST must be larger than the size of TYPE. Both types 3065*9880d681SAndroid Build Coastguard Worker must be floating point. 3066*9880d681SAndroid Build Coastguard Worker``fpext (CST to TYPE)`` 3067*9880d681SAndroid Build Coastguard Worker Floating point extend a constant to another type. The size of CST 3068*9880d681SAndroid Build Coastguard Worker must be smaller or equal to the size of TYPE. Both types must be 3069*9880d681SAndroid Build Coastguard Worker floating point. 3070*9880d681SAndroid Build Coastguard Worker``fptoui (CST to TYPE)`` 3071*9880d681SAndroid Build Coastguard Worker Convert a floating point constant to the corresponding unsigned 3072*9880d681SAndroid Build Coastguard Worker integer constant. TYPE must be a scalar or vector integer type. CST 3073*9880d681SAndroid Build Coastguard Worker must be of scalar or vector floating point type. Both CST and TYPE 3074*9880d681SAndroid Build Coastguard Worker must be scalars, or vectors of the same number of elements. If the 3075*9880d681SAndroid Build Coastguard Worker value won't fit in the integer type, the results are undefined. 3076*9880d681SAndroid Build Coastguard Worker``fptosi (CST to TYPE)`` 3077*9880d681SAndroid Build Coastguard Worker Convert a floating point constant to the corresponding signed 3078*9880d681SAndroid Build Coastguard Worker integer constant. TYPE must be a scalar or vector integer type. CST 3079*9880d681SAndroid Build Coastguard Worker must be of scalar or vector floating point type. Both CST and TYPE 3080*9880d681SAndroid Build Coastguard Worker must be scalars, or vectors of the same number of elements. If the 3081*9880d681SAndroid Build Coastguard Worker value won't fit in the integer type, the results are undefined. 3082*9880d681SAndroid Build Coastguard Worker``uitofp (CST to TYPE)`` 3083*9880d681SAndroid Build Coastguard Worker Convert an unsigned integer constant to the corresponding floating 3084*9880d681SAndroid Build Coastguard Worker point constant. TYPE must be a scalar or vector floating point type. 3085*9880d681SAndroid Build Coastguard Worker CST must be of scalar or vector integer type. Both CST and TYPE must 3086*9880d681SAndroid Build Coastguard Worker be scalars, or vectors of the same number of elements. If the value 3087*9880d681SAndroid Build Coastguard Worker won't fit in the floating point type, the results are undefined. 3088*9880d681SAndroid Build Coastguard Worker``sitofp (CST to TYPE)`` 3089*9880d681SAndroid Build Coastguard Worker Convert a signed integer constant to the corresponding floating 3090*9880d681SAndroid Build Coastguard Worker point constant. TYPE must be a scalar or vector floating point type. 3091*9880d681SAndroid Build Coastguard Worker CST must be of scalar or vector integer type. Both CST and TYPE must 3092*9880d681SAndroid Build Coastguard Worker be scalars, or vectors of the same number of elements. If the value 3093*9880d681SAndroid Build Coastguard Worker won't fit in the floating point type, the results are undefined. 3094*9880d681SAndroid Build Coastguard Worker``ptrtoint (CST to TYPE)`` 3095*9880d681SAndroid Build Coastguard Worker Convert a pointer typed constant to the corresponding integer 3096*9880d681SAndroid Build Coastguard Worker constant. ``TYPE`` must be an integer type. ``CST`` must be of 3097*9880d681SAndroid Build Coastguard Worker pointer type. The ``CST`` value is zero extended, truncated, or 3098*9880d681SAndroid Build Coastguard Worker unchanged to make it fit in ``TYPE``. 3099*9880d681SAndroid Build Coastguard Worker``inttoptr (CST to TYPE)`` 3100*9880d681SAndroid Build Coastguard Worker Convert an integer constant to a pointer constant. TYPE must be a 3101*9880d681SAndroid Build Coastguard Worker pointer type. CST must be of integer type. The CST value is zero 3102*9880d681SAndroid Build Coastguard Worker extended, truncated, or unchanged to make it fit in a pointer size. 3103*9880d681SAndroid Build Coastguard Worker This one is *really* dangerous! 3104*9880d681SAndroid Build Coastguard Worker``bitcast (CST to TYPE)`` 3105*9880d681SAndroid Build Coastguard Worker Convert a constant, CST, to another TYPE. The constraints of the 3106*9880d681SAndroid Build Coastguard Worker operands are the same as those for the :ref:`bitcast 3107*9880d681SAndroid Build Coastguard Worker instruction <i_bitcast>`. 3108*9880d681SAndroid Build Coastguard Worker``addrspacecast (CST to TYPE)`` 3109*9880d681SAndroid Build Coastguard Worker Convert a constant pointer or constant vector of pointer, CST, to another 3110*9880d681SAndroid Build Coastguard Worker TYPE in a different address space. The constraints of the operands are the 3111*9880d681SAndroid Build Coastguard Worker same as those for the :ref:`addrspacecast instruction <i_addrspacecast>`. 3112*9880d681SAndroid Build Coastguard Worker``getelementptr (TY, CSTPTR, IDX0, IDX1, ...)``, ``getelementptr inbounds (TY, CSTPTR, IDX0, IDX1, ...)`` 3113*9880d681SAndroid Build Coastguard Worker Perform the :ref:`getelementptr operation <i_getelementptr>` on 3114*9880d681SAndroid Build Coastguard Worker constants. As with the :ref:`getelementptr <i_getelementptr>` 3115*9880d681SAndroid Build Coastguard Worker instruction, the index list may have zero or more indexes, which are 3116*9880d681SAndroid Build Coastguard Worker required to make sense for the type of "pointer to TY". 3117*9880d681SAndroid Build Coastguard Worker``select (COND, VAL1, VAL2)`` 3118*9880d681SAndroid Build Coastguard Worker Perform the :ref:`select operation <i_select>` on constants. 3119*9880d681SAndroid Build Coastguard Worker``icmp COND (VAL1, VAL2)`` 3120*9880d681SAndroid Build Coastguard Worker Performs the :ref:`icmp operation <i_icmp>` on constants. 3121*9880d681SAndroid Build Coastguard Worker``fcmp COND (VAL1, VAL2)`` 3122*9880d681SAndroid Build Coastguard Worker Performs the :ref:`fcmp operation <i_fcmp>` on constants. 3123*9880d681SAndroid Build Coastguard Worker``extractelement (VAL, IDX)`` 3124*9880d681SAndroid Build Coastguard Worker Perform the :ref:`extractelement operation <i_extractelement>` on 3125*9880d681SAndroid Build Coastguard Worker constants. 3126*9880d681SAndroid Build Coastguard Worker``insertelement (VAL, ELT, IDX)`` 3127*9880d681SAndroid Build Coastguard Worker Perform the :ref:`insertelement operation <i_insertelement>` on 3128*9880d681SAndroid Build Coastguard Worker constants. 3129*9880d681SAndroid Build Coastguard Worker``shufflevector (VEC1, VEC2, IDXMASK)`` 3130*9880d681SAndroid Build Coastguard Worker Perform the :ref:`shufflevector operation <i_shufflevector>` on 3131*9880d681SAndroid Build Coastguard Worker constants. 3132*9880d681SAndroid Build Coastguard Worker``extractvalue (VAL, IDX0, IDX1, ...)`` 3133*9880d681SAndroid Build Coastguard Worker Perform the :ref:`extractvalue operation <i_extractvalue>` on 3134*9880d681SAndroid Build Coastguard Worker constants. The index list is interpreted in a similar manner as 3135*9880d681SAndroid Build Coastguard Worker indices in a ':ref:`getelementptr <i_getelementptr>`' operation. At 3136*9880d681SAndroid Build Coastguard Worker least one index value must be specified. 3137*9880d681SAndroid Build Coastguard Worker``insertvalue (VAL, ELT, IDX0, IDX1, ...)`` 3138*9880d681SAndroid Build Coastguard Worker Perform the :ref:`insertvalue operation <i_insertvalue>` on constants. 3139*9880d681SAndroid Build Coastguard Worker The index list is interpreted in a similar manner as indices in a 3140*9880d681SAndroid Build Coastguard Worker ':ref:`getelementptr <i_getelementptr>`' operation. At least one index 3141*9880d681SAndroid Build Coastguard Worker value must be specified. 3142*9880d681SAndroid Build Coastguard Worker``OPCODE (LHS, RHS)`` 3143*9880d681SAndroid Build Coastguard Worker Perform the specified operation of the LHS and RHS constants. OPCODE 3144*9880d681SAndroid Build Coastguard Worker may be any of the :ref:`binary <binaryops>` or :ref:`bitwise 3145*9880d681SAndroid Build Coastguard Worker binary <bitwiseops>` operations. The constraints on operands are 3146*9880d681SAndroid Build Coastguard Worker the same as those for the corresponding instruction (e.g. no bitwise 3147*9880d681SAndroid Build Coastguard Worker operations on floating point values are allowed). 3148*9880d681SAndroid Build Coastguard Worker 3149*9880d681SAndroid Build Coastguard WorkerOther Values 3150*9880d681SAndroid Build Coastguard Worker============ 3151*9880d681SAndroid Build Coastguard Worker 3152*9880d681SAndroid Build Coastguard Worker.. _inlineasmexprs: 3153*9880d681SAndroid Build Coastguard Worker 3154*9880d681SAndroid Build Coastguard WorkerInline Assembler Expressions 3155*9880d681SAndroid Build Coastguard Worker---------------------------- 3156*9880d681SAndroid Build Coastguard Worker 3157*9880d681SAndroid Build Coastguard WorkerLLVM supports inline assembler expressions (as opposed to :ref:`Module-Level 3158*9880d681SAndroid Build Coastguard WorkerInline Assembly <moduleasm>`) through the use of a special value. This value 3159*9880d681SAndroid Build Coastguard Workerrepresents the inline assembler as a template string (containing the 3160*9880d681SAndroid Build Coastguard Workerinstructions to emit), a list of operand constraints (stored as a string), a 3161*9880d681SAndroid Build Coastguard Workerflag that indicates whether or not the inline asm expression has side effects, 3162*9880d681SAndroid Build Coastguard Workerand a flag indicating whether the function containing the asm needs to align its 3163*9880d681SAndroid Build Coastguard Workerstack conservatively. 3164*9880d681SAndroid Build Coastguard Worker 3165*9880d681SAndroid Build Coastguard WorkerThe template string supports argument substitution of the operands using "``$``" 3166*9880d681SAndroid Build Coastguard Workerfollowed by a number, to indicate substitution of the given register/memory 3167*9880d681SAndroid Build Coastguard Workerlocation, as specified by the constraint string. "``${NUM:MODIFIER}``" may also 3168*9880d681SAndroid Build Coastguard Workerbe used, where ``MODIFIER`` is a target-specific annotation for how to print the 3169*9880d681SAndroid Build Coastguard Workeroperand (See :ref:`inline-asm-modifiers`). 3170*9880d681SAndroid Build Coastguard Worker 3171*9880d681SAndroid Build Coastguard WorkerA literal "``$``" may be included by using "``$$``" in the template. To include 3172*9880d681SAndroid Build Coastguard Workerother special characters into the output, the usual "``\XX``" escapes may be 3173*9880d681SAndroid Build Coastguard Workerused, just as in other strings. Note that after template substitution, the 3174*9880d681SAndroid Build Coastguard Workerresulting assembly string is parsed by LLVM's integrated assembler unless it is 3175*9880d681SAndroid Build Coastguard Workerdisabled -- even when emitting a ``.s`` file -- and thus must contain assembly 3176*9880d681SAndroid Build Coastguard Workersyntax known to LLVM. 3177*9880d681SAndroid Build Coastguard Worker 3178*9880d681SAndroid Build Coastguard WorkerLLVM's support for inline asm is modeled closely on the requirements of Clang's 3179*9880d681SAndroid Build Coastguard WorkerGCC-compatible inline-asm support. Thus, the feature-set and the constraint and 3180*9880d681SAndroid Build Coastguard Workermodifier codes listed here are similar or identical to those in GCC's inline asm 3181*9880d681SAndroid Build Coastguard Workersupport. However, to be clear, the syntax of the template and constraint strings 3182*9880d681SAndroid Build Coastguard Workerdescribed here is *not* the same as the syntax accepted by GCC and Clang, and, 3183*9880d681SAndroid Build Coastguard Workerwhile most constraint letters are passed through as-is by Clang, some get 3184*9880d681SAndroid Build Coastguard Workertranslated to other codes when converting from the C source to the LLVM 3185*9880d681SAndroid Build Coastguard Workerassembly. 3186*9880d681SAndroid Build Coastguard Worker 3187*9880d681SAndroid Build Coastguard WorkerAn example inline assembler expression is: 3188*9880d681SAndroid Build Coastguard Worker 3189*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 3190*9880d681SAndroid Build Coastguard Worker 3191*9880d681SAndroid Build Coastguard Worker i32 (i32) asm "bswap $0", "=r,r" 3192*9880d681SAndroid Build Coastguard Worker 3193*9880d681SAndroid Build Coastguard WorkerInline assembler expressions may **only** be used as the callee operand 3194*9880d681SAndroid Build Coastguard Workerof a :ref:`call <i_call>` or an :ref:`invoke <i_invoke>` instruction. 3195*9880d681SAndroid Build Coastguard WorkerThus, typically we have: 3196*9880d681SAndroid Build Coastguard Worker 3197*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 3198*9880d681SAndroid Build Coastguard Worker 3199*9880d681SAndroid Build Coastguard Worker %X = call i32 asm "bswap $0", "=r,r"(i32 %Y) 3200*9880d681SAndroid Build Coastguard Worker 3201*9880d681SAndroid Build Coastguard WorkerInline asms with side effects not visible in the constraint list must be 3202*9880d681SAndroid Build Coastguard Workermarked as having side effects. This is done through the use of the 3203*9880d681SAndroid Build Coastguard Worker'``sideeffect``' keyword, like so: 3204*9880d681SAndroid Build Coastguard Worker 3205*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 3206*9880d681SAndroid Build Coastguard Worker 3207*9880d681SAndroid Build Coastguard Worker call void asm sideeffect "eieio", ""() 3208*9880d681SAndroid Build Coastguard Worker 3209*9880d681SAndroid Build Coastguard WorkerIn some cases inline asms will contain code that will not work unless 3210*9880d681SAndroid Build Coastguard Workerthe stack is aligned in some way, such as calls or SSE instructions on 3211*9880d681SAndroid Build Coastguard Workerx86, yet will not contain code that does that alignment within the asm. 3212*9880d681SAndroid Build Coastguard WorkerThe compiler should make conservative assumptions about what the asm 3213*9880d681SAndroid Build Coastguard Workermight contain and should generate its usual stack alignment code in the 3214*9880d681SAndroid Build Coastguard Workerprologue if the '``alignstack``' keyword is present: 3215*9880d681SAndroid Build Coastguard Worker 3216*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 3217*9880d681SAndroid Build Coastguard Worker 3218*9880d681SAndroid Build Coastguard Worker call void asm alignstack "eieio", ""() 3219*9880d681SAndroid Build Coastguard Worker 3220*9880d681SAndroid Build Coastguard WorkerInline asms also support using non-standard assembly dialects. The 3221*9880d681SAndroid Build Coastguard Workerassumed dialect is ATT. When the '``inteldialect``' keyword is present, 3222*9880d681SAndroid Build Coastguard Workerthe inline asm is using the Intel dialect. Currently, ATT and Intel are 3223*9880d681SAndroid Build Coastguard Workerthe only supported dialects. An example is: 3224*9880d681SAndroid Build Coastguard Worker 3225*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 3226*9880d681SAndroid Build Coastguard Worker 3227*9880d681SAndroid Build Coastguard Worker call void asm inteldialect "eieio", ""() 3228*9880d681SAndroid Build Coastguard Worker 3229*9880d681SAndroid Build Coastguard WorkerIf multiple keywords appear the '``sideeffect``' keyword must come 3230*9880d681SAndroid Build Coastguard Workerfirst, the '``alignstack``' keyword second and the '``inteldialect``' 3231*9880d681SAndroid Build Coastguard Workerkeyword last. 3232*9880d681SAndroid Build Coastguard Worker 3233*9880d681SAndroid Build Coastguard WorkerInline Asm Constraint String 3234*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 3235*9880d681SAndroid Build Coastguard Worker 3236*9880d681SAndroid Build Coastguard WorkerThe constraint list is a comma-separated string, each element containing one or 3237*9880d681SAndroid Build Coastguard Workermore constraint codes. 3238*9880d681SAndroid Build Coastguard Worker 3239*9880d681SAndroid Build Coastguard WorkerFor each element in the constraint list an appropriate register or memory 3240*9880d681SAndroid Build Coastguard Workeroperand will be chosen, and it will be made available to assembly template 3241*9880d681SAndroid Build Coastguard Workerstring expansion as ``$0`` for the first constraint in the list, ``$1`` for the 3242*9880d681SAndroid Build Coastguard Workersecond, etc. 3243*9880d681SAndroid Build Coastguard Worker 3244*9880d681SAndroid Build Coastguard WorkerThere are three different types of constraints, which are distinguished by a 3245*9880d681SAndroid Build Coastguard Workerprefix symbol in front of the constraint code: Output, Input, and Clobber. The 3246*9880d681SAndroid Build Coastguard Workerconstraints must always be given in that order: outputs first, then inputs, then 3247*9880d681SAndroid Build Coastguard Workerclobbers. They cannot be intermingled. 3248*9880d681SAndroid Build Coastguard Worker 3249*9880d681SAndroid Build Coastguard WorkerThere are also three different categories of constraint codes: 3250*9880d681SAndroid Build Coastguard Worker 3251*9880d681SAndroid Build Coastguard Worker- Register constraint. This is either a register class, or a fixed physical 3252*9880d681SAndroid Build Coastguard Worker register. This kind of constraint will allocate a register, and if necessary, 3253*9880d681SAndroid Build Coastguard Worker bitcast the argument or result to the appropriate type. 3254*9880d681SAndroid Build Coastguard Worker- Memory constraint. This kind of constraint is for use with an instruction 3255*9880d681SAndroid Build Coastguard Worker taking a memory operand. Different constraints allow for different addressing 3256*9880d681SAndroid Build Coastguard Worker modes used by the target. 3257*9880d681SAndroid Build Coastguard Worker- Immediate value constraint. This kind of constraint is for an integer or other 3258*9880d681SAndroid Build Coastguard Worker immediate value which can be rendered directly into an instruction. The 3259*9880d681SAndroid Build Coastguard Worker various target-specific constraints allow the selection of a value in the 3260*9880d681SAndroid Build Coastguard Worker proper range for the instruction you wish to use it with. 3261*9880d681SAndroid Build Coastguard Worker 3262*9880d681SAndroid Build Coastguard WorkerOutput constraints 3263*9880d681SAndroid Build Coastguard Worker"""""""""""""""""" 3264*9880d681SAndroid Build Coastguard Worker 3265*9880d681SAndroid Build Coastguard WorkerOutput constraints are specified by an "``=``" prefix (e.g. "``=r``"). This 3266*9880d681SAndroid Build Coastguard Workerindicates that the assembly will write to this operand, and the operand will 3267*9880d681SAndroid Build Coastguard Workerthen be made available as a return value of the ``asm`` expression. Output 3268*9880d681SAndroid Build Coastguard Workerconstraints do not consume an argument from the call instruction. (Except, see 3269*9880d681SAndroid Build Coastguard Workerbelow about indirect outputs). 3270*9880d681SAndroid Build Coastguard Worker 3271*9880d681SAndroid Build Coastguard WorkerNormally, it is expected that no output locations are written to by the assembly 3272*9880d681SAndroid Build Coastguard Workerexpression until *all* of the inputs have been read. As such, LLVM may assign 3273*9880d681SAndroid Build Coastguard Workerthe same register to an output and an input. If this is not safe (e.g. if the 3274*9880d681SAndroid Build Coastguard Workerassembly contains two instructions, where the first writes to one output, and 3275*9880d681SAndroid Build Coastguard Workerthe second reads an input and writes to a second output), then the "``&``" 3276*9880d681SAndroid Build Coastguard Workermodifier must be used (e.g. "``=&r``") to specify that the output is an 3277*9880d681SAndroid Build Coastguard Worker"early-clobber" output. Marking an output as "early-clobber" ensures that LLVM 3278*9880d681SAndroid Build Coastguard Workerwill not use the same register for any inputs (other than an input tied to this 3279*9880d681SAndroid Build Coastguard Workeroutput). 3280*9880d681SAndroid Build Coastguard Worker 3281*9880d681SAndroid Build Coastguard WorkerInput constraints 3282*9880d681SAndroid Build Coastguard Worker""""""""""""""""" 3283*9880d681SAndroid Build Coastguard Worker 3284*9880d681SAndroid Build Coastguard WorkerInput constraints do not have a prefix -- just the constraint codes. Each input 3285*9880d681SAndroid Build Coastguard Workerconstraint will consume one argument from the call instruction. It is not 3286*9880d681SAndroid Build Coastguard Workerpermitted for the asm to write to any input register or memory location (unless 3287*9880d681SAndroid Build Coastguard Workerthat input is tied to an output). Note also that multiple inputs may all be 3288*9880d681SAndroid Build Coastguard Workerassigned to the same register, if LLVM can determine that they necessarily all 3289*9880d681SAndroid Build Coastguard Workercontain the same value. 3290*9880d681SAndroid Build Coastguard Worker 3291*9880d681SAndroid Build Coastguard WorkerInstead of providing a Constraint Code, input constraints may also "tie" 3292*9880d681SAndroid Build Coastguard Workerthemselves to an output constraint, by providing an integer as the constraint 3293*9880d681SAndroid Build Coastguard Workerstring. Tied inputs still consume an argument from the call instruction, and 3294*9880d681SAndroid Build Coastguard Workertake up a position in the asm template numbering as is usual -- they will simply 3295*9880d681SAndroid Build Coastguard Workerbe constrained to always use the same register as the output they've been tied 3296*9880d681SAndroid Build Coastguard Workerto. For example, a constraint string of "``=r,0``" says to assign a register for 3297*9880d681SAndroid Build Coastguard Workeroutput, and use that register as an input as well (it being the 0'th 3298*9880d681SAndroid Build Coastguard Workerconstraint). 3299*9880d681SAndroid Build Coastguard Worker 3300*9880d681SAndroid Build Coastguard WorkerIt is permitted to tie an input to an "early-clobber" output. In that case, no 3301*9880d681SAndroid Build Coastguard Worker*other* input may share the same register as the input tied to the early-clobber 3302*9880d681SAndroid Build Coastguard Worker(even when the other input has the same value). 3303*9880d681SAndroid Build Coastguard Worker 3304*9880d681SAndroid Build Coastguard WorkerYou may only tie an input to an output which has a register constraint, not a 3305*9880d681SAndroid Build Coastguard Workermemory constraint. Only a single input may be tied to an output. 3306*9880d681SAndroid Build Coastguard Worker 3307*9880d681SAndroid Build Coastguard WorkerThere is also an "interesting" feature which deserves a bit of explanation: if a 3308*9880d681SAndroid Build Coastguard Workerregister class constraint allocates a register which is too small for the value 3309*9880d681SAndroid Build Coastguard Workertype operand provided as input, the input value will be split into multiple 3310*9880d681SAndroid Build Coastguard Workerregisters, and all of them passed to the inline asm. 3311*9880d681SAndroid Build Coastguard Worker 3312*9880d681SAndroid Build Coastguard WorkerHowever, this feature is often not as useful as you might think. 3313*9880d681SAndroid Build Coastguard Worker 3314*9880d681SAndroid Build Coastguard WorkerFirstly, the registers are *not* guaranteed to be consecutive. So, on those 3315*9880d681SAndroid Build Coastguard Workerarchitectures that have instructions which operate on multiple consecutive 3316*9880d681SAndroid Build Coastguard Workerinstructions, this is not an appropriate way to support them. (e.g. the 32-bit 3317*9880d681SAndroid Build Coastguard WorkerSparcV8 has a 64-bit load, which instruction takes a single 32-bit register. The 3318*9880d681SAndroid Build Coastguard Workerhardware then loads into both the named register, and the next register. This 3319*9880d681SAndroid Build Coastguard Workerfeature of inline asm would not be useful to support that.) 3320*9880d681SAndroid Build Coastguard Worker 3321*9880d681SAndroid Build Coastguard WorkerA few of the targets provide a template string modifier allowing explicit access 3322*9880d681SAndroid Build Coastguard Workerto the second register of a two-register operand (e.g. MIPS ``L``, ``M``, and 3323*9880d681SAndroid Build Coastguard Worker``D``). On such an architecture, you can actually access the second allocated 3324*9880d681SAndroid Build Coastguard Workerregister (yet, still, not any subsequent ones). But, in that case, you're still 3325*9880d681SAndroid Build Coastguard Workerprobably better off simply splitting the value into two separate operands, for 3326*9880d681SAndroid Build Coastguard Workerclarity. (e.g. see the description of the ``A`` constraint on X86, which, 3327*9880d681SAndroid Build Coastguard Workerdespite existing only for use with this feature, is not really a good idea to 3328*9880d681SAndroid Build Coastguard Workeruse) 3329*9880d681SAndroid Build Coastguard Worker 3330*9880d681SAndroid Build Coastguard WorkerIndirect inputs and outputs 3331*9880d681SAndroid Build Coastguard Worker""""""""""""""""""""""""""" 3332*9880d681SAndroid Build Coastguard Worker 3333*9880d681SAndroid Build Coastguard WorkerIndirect output or input constraints can be specified by the "``*``" modifier 3334*9880d681SAndroid Build Coastguard Worker(which goes after the "``=``" in case of an output). This indicates that the asm 3335*9880d681SAndroid Build Coastguard Workerwill write to or read from the contents of an *address* provided as an input 3336*9880d681SAndroid Build Coastguard Workerargument. (Note that in this way, indirect outputs act more like an *input* than 3337*9880d681SAndroid Build Coastguard Workeran output: just like an input, they consume an argument of the call expression, 3338*9880d681SAndroid Build Coastguard Workerrather than producing a return value. An indirect output constraint is an 3339*9880d681SAndroid Build Coastguard Worker"output" only in that the asm is expected to write to the contents of the input 3340*9880d681SAndroid Build Coastguard Workermemory location, instead of just read from it). 3341*9880d681SAndroid Build Coastguard Worker 3342*9880d681SAndroid Build Coastguard WorkerThis is most typically used for memory constraint, e.g. "``=*m``", to pass the 3343*9880d681SAndroid Build Coastguard Workeraddress of a variable as a value. 3344*9880d681SAndroid Build Coastguard Worker 3345*9880d681SAndroid Build Coastguard WorkerIt is also possible to use an indirect *register* constraint, but only on output 3346*9880d681SAndroid Build Coastguard Worker(e.g. "``=*r``"). This will cause LLVM to allocate a register for an output 3347*9880d681SAndroid Build Coastguard Workervalue normally, and then, separately emit a store to the address provided as 3348*9880d681SAndroid Build Coastguard Workerinput, after the provided inline asm. (It's not clear what value this 3349*9880d681SAndroid Build Coastguard Workerfunctionality provides, compared to writing the store explicitly after the asm 3350*9880d681SAndroid Build Coastguard Workerstatement, and it can only produce worse code, since it bypasses many 3351*9880d681SAndroid Build Coastguard Workeroptimization passes. I would recommend not using it.) 3352*9880d681SAndroid Build Coastguard Worker 3353*9880d681SAndroid Build Coastguard Worker 3354*9880d681SAndroid Build Coastguard WorkerClobber constraints 3355*9880d681SAndroid Build Coastguard Worker""""""""""""""""""" 3356*9880d681SAndroid Build Coastguard Worker 3357*9880d681SAndroid Build Coastguard WorkerA clobber constraint is indicated by a "``~``" prefix. A clobber does not 3358*9880d681SAndroid Build Coastguard Workerconsume an input operand, nor generate an output. Clobbers cannot use any of the 3359*9880d681SAndroid Build Coastguard Workergeneral constraint code letters -- they may use only explicit register 3360*9880d681SAndroid Build Coastguard Workerconstraints, e.g. "``~{eax}``". The one exception is that a clobber string of 3361*9880d681SAndroid Build Coastguard Worker"``~{memory}``" indicates that the assembly writes to arbitrary undeclared 3362*9880d681SAndroid Build Coastguard Workermemory locations -- not only the memory pointed to by a declared indirect 3363*9880d681SAndroid Build Coastguard Workeroutput. 3364*9880d681SAndroid Build Coastguard Worker 3365*9880d681SAndroid Build Coastguard Worker 3366*9880d681SAndroid Build Coastguard WorkerConstraint Codes 3367*9880d681SAndroid Build Coastguard Worker"""""""""""""""" 3368*9880d681SAndroid Build Coastguard WorkerAfter a potential prefix comes constraint code, or codes. 3369*9880d681SAndroid Build Coastguard Worker 3370*9880d681SAndroid Build Coastguard WorkerA Constraint Code is either a single letter (e.g. "``r``"), a "``^``" character 3371*9880d681SAndroid Build Coastguard Workerfollowed by two letters (e.g. "``^wc``"), or "``{``" register-name "``}``" 3372*9880d681SAndroid Build Coastguard Worker(e.g. "``{eax}``"). 3373*9880d681SAndroid Build Coastguard Worker 3374*9880d681SAndroid Build Coastguard WorkerThe one and two letter constraint codes are typically chosen to be the same as 3375*9880d681SAndroid Build Coastguard WorkerGCC's constraint codes. 3376*9880d681SAndroid Build Coastguard Worker 3377*9880d681SAndroid Build Coastguard WorkerA single constraint may include one or more than constraint code in it, leaving 3378*9880d681SAndroid Build Coastguard Workerit up to LLVM to choose which one to use. This is included mainly for 3379*9880d681SAndroid Build Coastguard Workercompatibility with the translation of GCC inline asm coming from clang. 3380*9880d681SAndroid Build Coastguard Worker 3381*9880d681SAndroid Build Coastguard WorkerThere are two ways to specify alternatives, and either or both may be used in an 3382*9880d681SAndroid Build Coastguard Workerinline asm constraint list: 3383*9880d681SAndroid Build Coastguard Worker 3384*9880d681SAndroid Build Coastguard Worker1) Append the codes to each other, making a constraint code set. E.g. "``im``" 3385*9880d681SAndroid Build Coastguard Worker or "``{eax}m``". This means "choose any of the options in the set". The 3386*9880d681SAndroid Build Coastguard Worker choice of constraint is made independently for each constraint in the 3387*9880d681SAndroid Build Coastguard Worker constraint list. 3388*9880d681SAndroid Build Coastguard Worker 3389*9880d681SAndroid Build Coastguard Worker2) Use "``|``" between constraint code sets, creating alternatives. Every 3390*9880d681SAndroid Build Coastguard Worker constraint in the constraint list must have the same number of alternative 3391*9880d681SAndroid Build Coastguard Worker sets. With this syntax, the same alternative in *all* of the items in the 3392*9880d681SAndroid Build Coastguard Worker constraint list will be chosen together. 3393*9880d681SAndroid Build Coastguard Worker 3394*9880d681SAndroid Build Coastguard WorkerPutting those together, you might have a two operand constraint string like 3395*9880d681SAndroid Build Coastguard Worker``"rm|r,ri|rm"``. This indicates that if operand 0 is ``r`` or ``m``, then 3396*9880d681SAndroid Build Coastguard Workeroperand 1 may be one of ``r`` or ``i``. If operand 0 is ``r``, then operand 1 3397*9880d681SAndroid Build Coastguard Workermay be one of ``r`` or ``m``. But, operand 0 and 1 cannot both be of type m. 3398*9880d681SAndroid Build Coastguard Worker 3399*9880d681SAndroid Build Coastguard WorkerHowever, the use of either of the alternatives features is *NOT* recommended, as 3400*9880d681SAndroid Build Coastguard WorkerLLVM is not able to make an intelligent choice about which one to use. (At the 3401*9880d681SAndroid Build Coastguard Workerpoint it currently needs to choose, not enough information is available to do so 3402*9880d681SAndroid Build Coastguard Workerin a smart way.) Thus, it simply tries to make a choice that's most likely to 3403*9880d681SAndroid Build Coastguard Workercompile, not one that will be optimal performance. (e.g., given "``rm``", it'll 3404*9880d681SAndroid Build Coastguard Workeralways choose to use memory, not registers). And, if given multiple registers, 3405*9880d681SAndroid Build Coastguard Workeror multiple register classes, it will simply choose the first one. (In fact, it 3406*9880d681SAndroid Build Coastguard Workerdoesn't currently even ensure explicitly specified physical registers are 3407*9880d681SAndroid Build Coastguard Workerunique, so specifying multiple physical registers as alternatives, like 3408*9880d681SAndroid Build Coastguard Worker``{r11}{r12},{r11}{r12}``, will assign r11 to both operands, not at all what was 3409*9880d681SAndroid Build Coastguard Workerintended.) 3410*9880d681SAndroid Build Coastguard Worker 3411*9880d681SAndroid Build Coastguard WorkerSupported Constraint Code List 3412*9880d681SAndroid Build Coastguard Worker"""""""""""""""""""""""""""""" 3413*9880d681SAndroid Build Coastguard Worker 3414*9880d681SAndroid Build Coastguard WorkerThe constraint codes are, in general, expected to behave the same way they do in 3415*9880d681SAndroid Build Coastguard WorkerGCC. LLVM's support is often implemented on an 'as-needed' basis, to support C 3416*9880d681SAndroid Build Coastguard Workerinline asm code which was supported by GCC. A mismatch in behavior between LLVM 3417*9880d681SAndroid Build Coastguard Workerand GCC likely indicates a bug in LLVM. 3418*9880d681SAndroid Build Coastguard Worker 3419*9880d681SAndroid Build Coastguard WorkerSome constraint codes are typically supported by all targets: 3420*9880d681SAndroid Build Coastguard Worker 3421*9880d681SAndroid Build Coastguard Worker- ``r``: A register in the target's general purpose register class. 3422*9880d681SAndroid Build Coastguard Worker- ``m``: A memory address operand. It is target-specific what addressing modes 3423*9880d681SAndroid Build Coastguard Worker are supported, typical examples are register, or register + register offset, 3424*9880d681SAndroid Build Coastguard Worker or register + immediate offset (of some target-specific size). 3425*9880d681SAndroid Build Coastguard Worker- ``i``: An integer constant (of target-specific width). Allows either a simple 3426*9880d681SAndroid Build Coastguard Worker immediate, or a relocatable value. 3427*9880d681SAndroid Build Coastguard Worker- ``n``: An integer constant -- *not* including relocatable values. 3428*9880d681SAndroid Build Coastguard Worker- ``s``: An integer constant, but allowing *only* relocatable values. 3429*9880d681SAndroid Build Coastguard Worker- ``X``: Allows an operand of any kind, no constraint whatsoever. Typically 3430*9880d681SAndroid Build Coastguard Worker useful to pass a label for an asm branch or call. 3431*9880d681SAndroid Build Coastguard Worker 3432*9880d681SAndroid Build Coastguard Worker .. FIXME: but that surely isn't actually okay to jump out of an asm 3433*9880d681SAndroid Build Coastguard Worker block without telling llvm about the control transfer???) 3434*9880d681SAndroid Build Coastguard Worker 3435*9880d681SAndroid Build Coastguard Worker- ``{register-name}``: Requires exactly the named physical register. 3436*9880d681SAndroid Build Coastguard Worker 3437*9880d681SAndroid Build Coastguard WorkerOther constraints are target-specific: 3438*9880d681SAndroid Build Coastguard Worker 3439*9880d681SAndroid Build Coastguard WorkerAArch64: 3440*9880d681SAndroid Build Coastguard Worker 3441*9880d681SAndroid Build Coastguard Worker- ``z``: An immediate integer 0. Outputs ``WZR`` or ``XZR``, as appropriate. 3442*9880d681SAndroid Build Coastguard Worker- ``I``: An immediate integer valid for an ``ADD`` or ``SUB`` instruction, 3443*9880d681SAndroid Build Coastguard Worker i.e. 0 to 4095 with optional shift by 12. 3444*9880d681SAndroid Build Coastguard Worker- ``J``: An immediate integer that, when negated, is valid for an ``ADD`` or 3445*9880d681SAndroid Build Coastguard Worker ``SUB`` instruction, i.e. -1 to -4095 with optional left shift by 12. 3446*9880d681SAndroid Build Coastguard Worker- ``K``: An immediate integer that is valid for the 'bitmask immediate 32' of a 3447*9880d681SAndroid Build Coastguard Worker logical instruction like ``AND``, ``EOR``, or ``ORR`` with a 32-bit register. 3448*9880d681SAndroid Build Coastguard Worker- ``L``: An immediate integer that is valid for the 'bitmask immediate 64' of a 3449*9880d681SAndroid Build Coastguard Worker logical instruction like ``AND``, ``EOR``, or ``ORR`` with a 64-bit register. 3450*9880d681SAndroid Build Coastguard Worker- ``M``: An immediate integer for use with the ``MOV`` assembly alias on a 3451*9880d681SAndroid Build Coastguard Worker 32-bit register. This is a superset of ``K``: in addition to the bitmask 3452*9880d681SAndroid Build Coastguard Worker immediate, also allows immediate integers which can be loaded with a single 3453*9880d681SAndroid Build Coastguard Worker ``MOVZ`` or ``MOVL`` instruction. 3454*9880d681SAndroid Build Coastguard Worker- ``N``: An immediate integer for use with the ``MOV`` assembly alias on a 3455*9880d681SAndroid Build Coastguard Worker 64-bit register. This is a superset of ``L``. 3456*9880d681SAndroid Build Coastguard Worker- ``Q``: Memory address operand must be in a single register (no 3457*9880d681SAndroid Build Coastguard Worker offsets). (However, LLVM currently does this for the ``m`` constraint as 3458*9880d681SAndroid Build Coastguard Worker well.) 3459*9880d681SAndroid Build Coastguard Worker- ``r``: A 32 or 64-bit integer register (W* or X*). 3460*9880d681SAndroid Build Coastguard Worker- ``w``: A 32, 64, or 128-bit floating-point/SIMD register. 3461*9880d681SAndroid Build Coastguard Worker- ``x``: A lower 128-bit floating-point/SIMD register (``V0`` to ``V15``). 3462*9880d681SAndroid Build Coastguard Worker 3463*9880d681SAndroid Build Coastguard WorkerAMDGPU: 3464*9880d681SAndroid Build Coastguard Worker 3465*9880d681SAndroid Build Coastguard Worker- ``r``: A 32 or 64-bit integer register. 3466*9880d681SAndroid Build Coastguard Worker- ``[0-9]v``: The 32-bit VGPR register, number 0-9. 3467*9880d681SAndroid Build Coastguard Worker- ``[0-9]s``: The 32-bit SGPR register, number 0-9. 3468*9880d681SAndroid Build Coastguard Worker 3469*9880d681SAndroid Build Coastguard Worker 3470*9880d681SAndroid Build Coastguard WorkerAll ARM modes: 3471*9880d681SAndroid Build Coastguard Worker 3472*9880d681SAndroid Build Coastguard Worker- ``Q``, ``Um``, ``Un``, ``Uq``, ``Us``, ``Ut``, ``Uv``, ``Uy``: Memory address 3473*9880d681SAndroid Build Coastguard Worker operand. Treated the same as operand ``m``, at the moment. 3474*9880d681SAndroid Build Coastguard Worker 3475*9880d681SAndroid Build Coastguard WorkerARM and ARM's Thumb2 mode: 3476*9880d681SAndroid Build Coastguard Worker 3477*9880d681SAndroid Build Coastguard Worker- ``j``: An immediate integer between 0 and 65535 (valid for ``MOVW``) 3478*9880d681SAndroid Build Coastguard Worker- ``I``: An immediate integer valid for a data-processing instruction. 3479*9880d681SAndroid Build Coastguard Worker- ``J``: An immediate integer between -4095 and 4095. 3480*9880d681SAndroid Build Coastguard Worker- ``K``: An immediate integer whose bitwise inverse is valid for a 3481*9880d681SAndroid Build Coastguard Worker data-processing instruction. (Can be used with template modifier "``B``" to 3482*9880d681SAndroid Build Coastguard Worker print the inverted value). 3483*9880d681SAndroid Build Coastguard Worker- ``L``: An immediate integer whose negation is valid for a data-processing 3484*9880d681SAndroid Build Coastguard Worker instruction. (Can be used with template modifier "``n``" to print the negated 3485*9880d681SAndroid Build Coastguard Worker value). 3486*9880d681SAndroid Build Coastguard Worker- ``M``: A power of two or a integer between 0 and 32. 3487*9880d681SAndroid Build Coastguard Worker- ``N``: Invalid immediate constraint. 3488*9880d681SAndroid Build Coastguard Worker- ``O``: Invalid immediate constraint. 3489*9880d681SAndroid Build Coastguard Worker- ``r``: A general-purpose 32-bit integer register (``r0-r15``). 3490*9880d681SAndroid Build Coastguard Worker- ``l``: In Thumb2 mode, low 32-bit GPR registers (``r0-r7``). In ARM mode, same 3491*9880d681SAndroid Build Coastguard Worker as ``r``. 3492*9880d681SAndroid Build Coastguard Worker- ``h``: In Thumb2 mode, a high 32-bit GPR register (``r8-r15``). In ARM mode, 3493*9880d681SAndroid Build Coastguard Worker invalid. 3494*9880d681SAndroid Build Coastguard Worker- ``w``: A 32, 64, or 128-bit floating-point/SIMD register: ``s0-s31``, 3495*9880d681SAndroid Build Coastguard Worker ``d0-d31``, or ``q0-q15``. 3496*9880d681SAndroid Build Coastguard Worker- ``x``: A 32, 64, or 128-bit floating-point/SIMD register: ``s0-s15``, 3497*9880d681SAndroid Build Coastguard Worker ``d0-d7``, or ``q0-q3``. 3498*9880d681SAndroid Build Coastguard Worker- ``t``: A floating-point/SIMD register, only supports 32-bit values: 3499*9880d681SAndroid Build Coastguard Worker ``s0-s31``. 3500*9880d681SAndroid Build Coastguard Worker 3501*9880d681SAndroid Build Coastguard WorkerARM's Thumb1 mode: 3502*9880d681SAndroid Build Coastguard Worker 3503*9880d681SAndroid Build Coastguard Worker- ``I``: An immediate integer between 0 and 255. 3504*9880d681SAndroid Build Coastguard Worker- ``J``: An immediate integer between -255 and -1. 3505*9880d681SAndroid Build Coastguard Worker- ``K``: An immediate integer between 0 and 255, with optional left-shift by 3506*9880d681SAndroid Build Coastguard Worker some amount. 3507*9880d681SAndroid Build Coastguard Worker- ``L``: An immediate integer between -7 and 7. 3508*9880d681SAndroid Build Coastguard Worker- ``M``: An immediate integer which is a multiple of 4 between 0 and 1020. 3509*9880d681SAndroid Build Coastguard Worker- ``N``: An immediate integer between 0 and 31. 3510*9880d681SAndroid Build Coastguard Worker- ``O``: An immediate integer which is a multiple of 4 between -508 and 508. 3511*9880d681SAndroid Build Coastguard Worker- ``r``: A low 32-bit GPR register (``r0-r7``). 3512*9880d681SAndroid Build Coastguard Worker- ``l``: A low 32-bit GPR register (``r0-r7``). 3513*9880d681SAndroid Build Coastguard Worker- ``h``: A high GPR register (``r0-r7``). 3514*9880d681SAndroid Build Coastguard Worker- ``w``: A 32, 64, or 128-bit floating-point/SIMD register: ``s0-s31``, 3515*9880d681SAndroid Build Coastguard Worker ``d0-d31``, or ``q0-q15``. 3516*9880d681SAndroid Build Coastguard Worker- ``x``: A 32, 64, or 128-bit floating-point/SIMD register: ``s0-s15``, 3517*9880d681SAndroid Build Coastguard Worker ``d0-d7``, or ``q0-q3``. 3518*9880d681SAndroid Build Coastguard Worker- ``t``: A floating-point/SIMD register, only supports 32-bit values: 3519*9880d681SAndroid Build Coastguard Worker ``s0-s31``. 3520*9880d681SAndroid Build Coastguard Worker 3521*9880d681SAndroid Build Coastguard Worker 3522*9880d681SAndroid Build Coastguard WorkerHexagon: 3523*9880d681SAndroid Build Coastguard Worker 3524*9880d681SAndroid Build Coastguard Worker- ``o``, ``v``: A memory address operand, treated the same as constraint ``m``, 3525*9880d681SAndroid Build Coastguard Worker at the moment. 3526*9880d681SAndroid Build Coastguard Worker- ``r``: A 32 or 64-bit register. 3527*9880d681SAndroid Build Coastguard Worker 3528*9880d681SAndroid Build Coastguard WorkerMSP430: 3529*9880d681SAndroid Build Coastguard Worker 3530*9880d681SAndroid Build Coastguard Worker- ``r``: An 8 or 16-bit register. 3531*9880d681SAndroid Build Coastguard Worker 3532*9880d681SAndroid Build Coastguard WorkerMIPS: 3533*9880d681SAndroid Build Coastguard Worker 3534*9880d681SAndroid Build Coastguard Worker- ``I``: An immediate signed 16-bit integer. 3535*9880d681SAndroid Build Coastguard Worker- ``J``: An immediate integer zero. 3536*9880d681SAndroid Build Coastguard Worker- ``K``: An immediate unsigned 16-bit integer. 3537*9880d681SAndroid Build Coastguard Worker- ``L``: An immediate 32-bit integer, where the lower 16 bits are 0. 3538*9880d681SAndroid Build Coastguard Worker- ``N``: An immediate integer between -65535 and -1. 3539*9880d681SAndroid Build Coastguard Worker- ``O``: An immediate signed 15-bit integer. 3540*9880d681SAndroid Build Coastguard Worker- ``P``: An immediate integer between 1 and 65535. 3541*9880d681SAndroid Build Coastguard Worker- ``m``: A memory address operand. In MIPS-SE mode, allows a base address 3542*9880d681SAndroid Build Coastguard Worker register plus 16-bit immediate offset. In MIPS mode, just a base register. 3543*9880d681SAndroid Build Coastguard Worker- ``R``: A memory address operand. In MIPS-SE mode, allows a base address 3544*9880d681SAndroid Build Coastguard Worker register plus a 9-bit signed offset. In MIPS mode, the same as constraint 3545*9880d681SAndroid Build Coastguard Worker ``m``. 3546*9880d681SAndroid Build Coastguard Worker- ``ZC``: A memory address operand, suitable for use in a ``pref``, ``ll``, or 3547*9880d681SAndroid Build Coastguard Worker ``sc`` instruction on the given subtarget (details vary). 3548*9880d681SAndroid Build Coastguard Worker- ``r``, ``d``, ``y``: A 32 or 64-bit GPR register. 3549*9880d681SAndroid Build Coastguard Worker- ``f``: A 32 or 64-bit FPU register (``F0-F31``), or a 128-bit MSA register 3550*9880d681SAndroid Build Coastguard Worker (``W0-W31``). In the case of MSA registers, it is recommended to use the ``w`` 3551*9880d681SAndroid Build Coastguard Worker argument modifier for compatibility with GCC. 3552*9880d681SAndroid Build Coastguard Worker- ``c``: A 32-bit or 64-bit GPR register suitable for indirect jump (always 3553*9880d681SAndroid Build Coastguard Worker ``25``). 3554*9880d681SAndroid Build Coastguard Worker- ``l``: The ``lo`` register, 32 or 64-bit. 3555*9880d681SAndroid Build Coastguard Worker- ``x``: Invalid. 3556*9880d681SAndroid Build Coastguard Worker 3557*9880d681SAndroid Build Coastguard WorkerNVPTX: 3558*9880d681SAndroid Build Coastguard Worker 3559*9880d681SAndroid Build Coastguard Worker- ``b``: A 1-bit integer register. 3560*9880d681SAndroid Build Coastguard Worker- ``c`` or ``h``: A 16-bit integer register. 3561*9880d681SAndroid Build Coastguard Worker- ``r``: A 32-bit integer register. 3562*9880d681SAndroid Build Coastguard Worker- ``l`` or ``N``: A 64-bit integer register. 3563*9880d681SAndroid Build Coastguard Worker- ``f``: A 32-bit float register. 3564*9880d681SAndroid Build Coastguard Worker- ``d``: A 64-bit float register. 3565*9880d681SAndroid Build Coastguard Worker 3566*9880d681SAndroid Build Coastguard Worker 3567*9880d681SAndroid Build Coastguard WorkerPowerPC: 3568*9880d681SAndroid Build Coastguard Worker 3569*9880d681SAndroid Build Coastguard Worker- ``I``: An immediate signed 16-bit integer. 3570*9880d681SAndroid Build Coastguard Worker- ``J``: An immediate unsigned 16-bit integer, shifted left 16 bits. 3571*9880d681SAndroid Build Coastguard Worker- ``K``: An immediate unsigned 16-bit integer. 3572*9880d681SAndroid Build Coastguard Worker- ``L``: An immediate signed 16-bit integer, shifted left 16 bits. 3573*9880d681SAndroid Build Coastguard Worker- ``M``: An immediate integer greater than 31. 3574*9880d681SAndroid Build Coastguard Worker- ``N``: An immediate integer that is an exact power of 2. 3575*9880d681SAndroid Build Coastguard Worker- ``O``: The immediate integer constant 0. 3576*9880d681SAndroid Build Coastguard Worker- ``P``: An immediate integer constant whose negation is a signed 16-bit 3577*9880d681SAndroid Build Coastguard Worker constant. 3578*9880d681SAndroid Build Coastguard Worker- ``es``, ``o``, ``Q``, ``Z``, ``Zy``: A memory address operand, currently 3579*9880d681SAndroid Build Coastguard Worker treated the same as ``m``. 3580*9880d681SAndroid Build Coastguard Worker- ``r``: A 32 or 64-bit integer register. 3581*9880d681SAndroid Build Coastguard Worker- ``b``: A 32 or 64-bit integer register, excluding ``R0`` (that is: 3582*9880d681SAndroid Build Coastguard Worker ``R1-R31``). 3583*9880d681SAndroid Build Coastguard Worker- ``f``: A 32 or 64-bit float register (``F0-F31``), or when QPX is enabled, a 3584*9880d681SAndroid Build Coastguard Worker 128 or 256-bit QPX register (``Q0-Q31``; aliases the ``F`` registers). 3585*9880d681SAndroid Build Coastguard Worker- ``v``: For ``4 x f32`` or ``4 x f64`` types, when QPX is enabled, a 3586*9880d681SAndroid Build Coastguard Worker 128 or 256-bit QPX register (``Q0-Q31``), otherwise a 128-bit 3587*9880d681SAndroid Build Coastguard Worker altivec vector register (``V0-V31``). 3588*9880d681SAndroid Build Coastguard Worker 3589*9880d681SAndroid Build Coastguard Worker .. FIXME: is this a bug that v accepts QPX registers? I think this 3590*9880d681SAndroid Build Coastguard Worker is supposed to only use the altivec vector registers? 3591*9880d681SAndroid Build Coastguard Worker 3592*9880d681SAndroid Build Coastguard Worker- ``y``: Condition register (``CR0-CR7``). 3593*9880d681SAndroid Build Coastguard Worker- ``wc``: An individual CR bit in a CR register. 3594*9880d681SAndroid Build Coastguard Worker- ``wa``, ``wd``, ``wf``: Any 128-bit VSX vector register, from the full VSX 3595*9880d681SAndroid Build Coastguard Worker register set (overlapping both the floating-point and vector register files). 3596*9880d681SAndroid Build Coastguard Worker- ``ws``: A 32 or 64-bit floating point register, from the full VSX register 3597*9880d681SAndroid Build Coastguard Worker set. 3598*9880d681SAndroid Build Coastguard Worker 3599*9880d681SAndroid Build Coastguard WorkerSparc: 3600*9880d681SAndroid Build Coastguard Worker 3601*9880d681SAndroid Build Coastguard Worker- ``I``: An immediate 13-bit signed integer. 3602*9880d681SAndroid Build Coastguard Worker- ``r``: A 32-bit integer register. 3603*9880d681SAndroid Build Coastguard Worker 3604*9880d681SAndroid Build Coastguard WorkerSystemZ: 3605*9880d681SAndroid Build Coastguard Worker 3606*9880d681SAndroid Build Coastguard Worker- ``I``: An immediate unsigned 8-bit integer. 3607*9880d681SAndroid Build Coastguard Worker- ``J``: An immediate unsigned 12-bit integer. 3608*9880d681SAndroid Build Coastguard Worker- ``K``: An immediate signed 16-bit integer. 3609*9880d681SAndroid Build Coastguard Worker- ``L``: An immediate signed 20-bit integer. 3610*9880d681SAndroid Build Coastguard Worker- ``M``: An immediate integer 0x7fffffff. 3611*9880d681SAndroid Build Coastguard Worker- ``Q``: A memory address operand with a base address and a 12-bit immediate 3612*9880d681SAndroid Build Coastguard Worker unsigned displacement. 3613*9880d681SAndroid Build Coastguard Worker- ``R``: A memory address operand with a base address, a 12-bit immediate 3614*9880d681SAndroid Build Coastguard Worker unsigned displacement, and an index register. 3615*9880d681SAndroid Build Coastguard Worker- ``S``: A memory address operand with a base address and a 20-bit immediate 3616*9880d681SAndroid Build Coastguard Worker signed displacement. 3617*9880d681SAndroid Build Coastguard Worker- ``T``: A memory address operand with a base address, a 20-bit immediate 3618*9880d681SAndroid Build Coastguard Worker signed displacement, and an index register. 3619*9880d681SAndroid Build Coastguard Worker- ``r`` or ``d``: A 32, 64, or 128-bit integer register. 3620*9880d681SAndroid Build Coastguard Worker- ``a``: A 32, 64, or 128-bit integer address register (excludes R0, which in an 3621*9880d681SAndroid Build Coastguard Worker address context evaluates as zero). 3622*9880d681SAndroid Build Coastguard Worker- ``h``: A 32-bit value in the high part of a 64bit data register 3623*9880d681SAndroid Build Coastguard Worker (LLVM-specific) 3624*9880d681SAndroid Build Coastguard Worker- ``f``: A 32, 64, or 128-bit floating point register. 3625*9880d681SAndroid Build Coastguard Worker 3626*9880d681SAndroid Build Coastguard WorkerX86: 3627*9880d681SAndroid Build Coastguard Worker 3628*9880d681SAndroid Build Coastguard Worker- ``I``: An immediate integer between 0 and 31. 3629*9880d681SAndroid Build Coastguard Worker- ``J``: An immediate integer between 0 and 64. 3630*9880d681SAndroid Build Coastguard Worker- ``K``: An immediate signed 8-bit integer. 3631*9880d681SAndroid Build Coastguard Worker- ``L``: An immediate integer, 0xff or 0xffff or (in 64-bit mode only) 3632*9880d681SAndroid Build Coastguard Worker 0xffffffff. 3633*9880d681SAndroid Build Coastguard Worker- ``M``: An immediate integer between 0 and 3. 3634*9880d681SAndroid Build Coastguard Worker- ``N``: An immediate unsigned 8-bit integer. 3635*9880d681SAndroid Build Coastguard Worker- ``O``: An immediate integer between 0 and 127. 3636*9880d681SAndroid Build Coastguard Worker- ``e``: An immediate 32-bit signed integer. 3637*9880d681SAndroid Build Coastguard Worker- ``Z``: An immediate 32-bit unsigned integer. 3638*9880d681SAndroid Build Coastguard Worker- ``o``, ``v``: Treated the same as ``m``, at the moment. 3639*9880d681SAndroid Build Coastguard Worker- ``q``: An 8, 16, 32, or 64-bit register which can be accessed as an 8-bit 3640*9880d681SAndroid Build Coastguard Worker ``l`` integer register. On X86-32, this is the ``a``, ``b``, ``c``, and ``d`` 3641*9880d681SAndroid Build Coastguard Worker registers, and on X86-64, it is all of the integer registers. 3642*9880d681SAndroid Build Coastguard Worker- ``Q``: An 8, 16, 32, or 64-bit register which can be accessed as an 8-bit 3643*9880d681SAndroid Build Coastguard Worker ``h`` integer register. This is the ``a``, ``b``, ``c``, and ``d`` registers. 3644*9880d681SAndroid Build Coastguard Worker- ``r`` or ``l``: An 8, 16, 32, or 64-bit integer register. 3645*9880d681SAndroid Build Coastguard Worker- ``R``: An 8, 16, 32, or 64-bit "legacy" integer register -- one which has 3646*9880d681SAndroid Build Coastguard Worker existed since i386, and can be accessed without the REX prefix. 3647*9880d681SAndroid Build Coastguard Worker- ``f``: A 32, 64, or 80-bit '387 FPU stack pseudo-register. 3648*9880d681SAndroid Build Coastguard Worker- ``y``: A 64-bit MMX register, if MMX is enabled. 3649*9880d681SAndroid Build Coastguard Worker- ``x``: If SSE is enabled: a 32 or 64-bit scalar operand, or 128-bit vector 3650*9880d681SAndroid Build Coastguard Worker operand in a SSE register. If AVX is also enabled, can also be a 256-bit 3651*9880d681SAndroid Build Coastguard Worker vector operand in an AVX register. If AVX-512 is also enabled, can also be a 3652*9880d681SAndroid Build Coastguard Worker 512-bit vector operand in an AVX512 register, Otherwise, an error. 3653*9880d681SAndroid Build Coastguard Worker- ``Y``: The same as ``x``, if *SSE2* is enabled, otherwise an error. 3654*9880d681SAndroid Build Coastguard Worker- ``A``: Special case: allocates EAX first, then EDX, for a single operand (in 3655*9880d681SAndroid Build Coastguard Worker 32-bit mode, a 64-bit integer operand will get split into two registers). It 3656*9880d681SAndroid Build Coastguard Worker is not recommended to use this constraint, as in 64-bit mode, the 64-bit 3657*9880d681SAndroid Build Coastguard Worker operand will get allocated only to RAX -- if two 32-bit operands are needed, 3658*9880d681SAndroid Build Coastguard Worker you're better off splitting it yourself, before passing it to the asm 3659*9880d681SAndroid Build Coastguard Worker statement. 3660*9880d681SAndroid Build Coastguard Worker 3661*9880d681SAndroid Build Coastguard WorkerXCore: 3662*9880d681SAndroid Build Coastguard Worker 3663*9880d681SAndroid Build Coastguard Worker- ``r``: A 32-bit integer register. 3664*9880d681SAndroid Build Coastguard Worker 3665*9880d681SAndroid Build Coastguard Worker 3666*9880d681SAndroid Build Coastguard Worker.. _inline-asm-modifiers: 3667*9880d681SAndroid Build Coastguard Worker 3668*9880d681SAndroid Build Coastguard WorkerAsm template argument modifiers 3669*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 3670*9880d681SAndroid Build Coastguard Worker 3671*9880d681SAndroid Build Coastguard WorkerIn the asm template string, modifiers can be used on the operand reference, like 3672*9880d681SAndroid Build Coastguard Worker"``${0:n}``". 3673*9880d681SAndroid Build Coastguard Worker 3674*9880d681SAndroid Build Coastguard WorkerThe modifiers are, in general, expected to behave the same way they do in 3675*9880d681SAndroid Build Coastguard WorkerGCC. LLVM's support is often implemented on an 'as-needed' basis, to support C 3676*9880d681SAndroid Build Coastguard Workerinline asm code which was supported by GCC. A mismatch in behavior between LLVM 3677*9880d681SAndroid Build Coastguard Workerand GCC likely indicates a bug in LLVM. 3678*9880d681SAndroid Build Coastguard Worker 3679*9880d681SAndroid Build Coastguard WorkerTarget-independent: 3680*9880d681SAndroid Build Coastguard Worker 3681*9880d681SAndroid Build Coastguard Worker- ``c``: Print an immediate integer constant unadorned, without 3682*9880d681SAndroid Build Coastguard Worker the target-specific immediate punctuation (e.g. no ``$`` prefix). 3683*9880d681SAndroid Build Coastguard Worker- ``n``: Negate and print immediate integer constant unadorned, without the 3684*9880d681SAndroid Build Coastguard Worker target-specific immediate punctuation (e.g. no ``$`` prefix). 3685*9880d681SAndroid Build Coastguard Worker- ``l``: Print as an unadorned label, without the target-specific label 3686*9880d681SAndroid Build Coastguard Worker punctuation (e.g. no ``$`` prefix). 3687*9880d681SAndroid Build Coastguard Worker 3688*9880d681SAndroid Build Coastguard WorkerAArch64: 3689*9880d681SAndroid Build Coastguard Worker 3690*9880d681SAndroid Build Coastguard Worker- ``w``: Print a GPR register with a ``w*`` name instead of ``x*`` name. E.g., 3691*9880d681SAndroid Build Coastguard Worker instead of ``x30``, print ``w30``. 3692*9880d681SAndroid Build Coastguard Worker- ``x``: Print a GPR register with a ``x*`` name. (this is the default, anyhow). 3693*9880d681SAndroid Build Coastguard Worker- ``b``, ``h``, ``s``, ``d``, ``q``: Print a floating-point/SIMD register with a 3694*9880d681SAndroid Build Coastguard Worker ``b*``, ``h*``, ``s*``, ``d*``, or ``q*`` name, rather than the default of 3695*9880d681SAndroid Build Coastguard Worker ``v*``. 3696*9880d681SAndroid Build Coastguard Worker 3697*9880d681SAndroid Build Coastguard WorkerAMDGPU: 3698*9880d681SAndroid Build Coastguard Worker 3699*9880d681SAndroid Build Coastguard Worker- ``r``: No effect. 3700*9880d681SAndroid Build Coastguard Worker 3701*9880d681SAndroid Build Coastguard WorkerARM: 3702*9880d681SAndroid Build Coastguard Worker 3703*9880d681SAndroid Build Coastguard Worker- ``a``: Print an operand as an address (with ``[`` and ``]`` surrounding a 3704*9880d681SAndroid Build Coastguard Worker register). 3705*9880d681SAndroid Build Coastguard Worker- ``P``: No effect. 3706*9880d681SAndroid Build Coastguard Worker- ``q``: No effect. 3707*9880d681SAndroid Build Coastguard Worker- ``y``: Print a VFP single-precision register as an indexed double (e.g. print 3708*9880d681SAndroid Build Coastguard Worker as ``d4[1]`` instead of ``s9``) 3709*9880d681SAndroid Build Coastguard Worker- ``B``: Bitwise invert and print an immediate integer constant without ``#`` 3710*9880d681SAndroid Build Coastguard Worker prefix. 3711*9880d681SAndroid Build Coastguard Worker- ``L``: Print the low 16-bits of an immediate integer constant. 3712*9880d681SAndroid Build Coastguard Worker- ``M``: Print as a register set suitable for ldm/stm. Also prints *all* 3713*9880d681SAndroid Build Coastguard Worker register operands subsequent to the specified one (!), so use carefully. 3714*9880d681SAndroid Build Coastguard Worker- ``Q``: Print the low-order register of a register-pair, or the low-order 3715*9880d681SAndroid Build Coastguard Worker register of a two-register operand. 3716*9880d681SAndroid Build Coastguard Worker- ``R``: Print the high-order register of a register-pair, or the high-order 3717*9880d681SAndroid Build Coastguard Worker register of a two-register operand. 3718*9880d681SAndroid Build Coastguard Worker- ``H``: Print the second register of a register-pair. (On a big-endian system, 3719*9880d681SAndroid Build Coastguard Worker ``H`` is equivalent to ``Q``, and on little-endian system, ``H`` is equivalent 3720*9880d681SAndroid Build Coastguard Worker to ``R``.) 3721*9880d681SAndroid Build Coastguard Worker 3722*9880d681SAndroid Build Coastguard Worker .. FIXME: H doesn't currently support printing the second register 3723*9880d681SAndroid Build Coastguard Worker of a two-register operand. 3724*9880d681SAndroid Build Coastguard Worker 3725*9880d681SAndroid Build Coastguard Worker- ``e``: Print the low doubleword register of a NEON quad register. 3726*9880d681SAndroid Build Coastguard Worker- ``f``: Print the high doubleword register of a NEON quad register. 3727*9880d681SAndroid Build Coastguard Worker- ``m``: Print the base register of a memory operand without the ``[`` and ``]`` 3728*9880d681SAndroid Build Coastguard Worker adornment. 3729*9880d681SAndroid Build Coastguard Worker 3730*9880d681SAndroid Build Coastguard WorkerHexagon: 3731*9880d681SAndroid Build Coastguard Worker 3732*9880d681SAndroid Build Coastguard Worker- ``L``: Print the second register of a two-register operand. Requires that it 3733*9880d681SAndroid Build Coastguard Worker has been allocated consecutively to the first. 3734*9880d681SAndroid Build Coastguard Worker 3735*9880d681SAndroid Build Coastguard Worker .. FIXME: why is it restricted to consecutive ones? And there's 3736*9880d681SAndroid Build Coastguard Worker nothing that ensures that happens, is there? 3737*9880d681SAndroid Build Coastguard Worker 3738*9880d681SAndroid Build Coastguard Worker- ``I``: Print the letter 'i' if the operand is an integer constant, otherwise 3739*9880d681SAndroid Build Coastguard Worker nothing. Used to print 'addi' vs 'add' instructions. 3740*9880d681SAndroid Build Coastguard Worker 3741*9880d681SAndroid Build Coastguard WorkerMSP430: 3742*9880d681SAndroid Build Coastguard Worker 3743*9880d681SAndroid Build Coastguard WorkerNo additional modifiers. 3744*9880d681SAndroid Build Coastguard Worker 3745*9880d681SAndroid Build Coastguard WorkerMIPS: 3746*9880d681SAndroid Build Coastguard Worker 3747*9880d681SAndroid Build Coastguard Worker- ``X``: Print an immediate integer as hexadecimal 3748*9880d681SAndroid Build Coastguard Worker- ``x``: Print the low 16 bits of an immediate integer as hexadecimal. 3749*9880d681SAndroid Build Coastguard Worker- ``d``: Print an immediate integer as decimal. 3750*9880d681SAndroid Build Coastguard Worker- ``m``: Subtract one and print an immediate integer as decimal. 3751*9880d681SAndroid Build Coastguard Worker- ``z``: Print $0 if an immediate zero, otherwise print normally. 3752*9880d681SAndroid Build Coastguard Worker- ``L``: Print the low-order register of a two-register operand, or prints the 3753*9880d681SAndroid Build Coastguard Worker address of the low-order word of a double-word memory operand. 3754*9880d681SAndroid Build Coastguard Worker 3755*9880d681SAndroid Build Coastguard Worker .. FIXME: L seems to be missing memory operand support. 3756*9880d681SAndroid Build Coastguard Worker 3757*9880d681SAndroid Build Coastguard Worker- ``M``: Print the high-order register of a two-register operand, or prints the 3758*9880d681SAndroid Build Coastguard Worker address of the high-order word of a double-word memory operand. 3759*9880d681SAndroid Build Coastguard Worker 3760*9880d681SAndroid Build Coastguard Worker .. FIXME: M seems to be missing memory operand support. 3761*9880d681SAndroid Build Coastguard Worker 3762*9880d681SAndroid Build Coastguard Worker- ``D``: Print the second register of a two-register operand, or prints the 3763*9880d681SAndroid Build Coastguard Worker second word of a double-word memory operand. (On a big-endian system, ``D`` is 3764*9880d681SAndroid Build Coastguard Worker equivalent to ``L``, and on little-endian system, ``D`` is equivalent to 3765*9880d681SAndroid Build Coastguard Worker ``M``.) 3766*9880d681SAndroid Build Coastguard Worker- ``w``: No effect. Provided for compatibility with GCC which requires this 3767*9880d681SAndroid Build Coastguard Worker modifier in order to print MSA registers (``W0-W31``) with the ``f`` 3768*9880d681SAndroid Build Coastguard Worker constraint. 3769*9880d681SAndroid Build Coastguard Worker 3770*9880d681SAndroid Build Coastguard WorkerNVPTX: 3771*9880d681SAndroid Build Coastguard Worker 3772*9880d681SAndroid Build Coastguard Worker- ``r``: No effect. 3773*9880d681SAndroid Build Coastguard Worker 3774*9880d681SAndroid Build Coastguard WorkerPowerPC: 3775*9880d681SAndroid Build Coastguard Worker 3776*9880d681SAndroid Build Coastguard Worker- ``L``: Print the second register of a two-register operand. Requires that it 3777*9880d681SAndroid Build Coastguard Worker has been allocated consecutively to the first. 3778*9880d681SAndroid Build Coastguard Worker 3779*9880d681SAndroid Build Coastguard Worker .. FIXME: why is it restricted to consecutive ones? And there's 3780*9880d681SAndroid Build Coastguard Worker nothing that ensures that happens, is there? 3781*9880d681SAndroid Build Coastguard Worker 3782*9880d681SAndroid Build Coastguard Worker- ``I``: Print the letter 'i' if the operand is an integer constant, otherwise 3783*9880d681SAndroid Build Coastguard Worker nothing. Used to print 'addi' vs 'add' instructions. 3784*9880d681SAndroid Build Coastguard Worker- ``y``: For a memory operand, prints formatter for a two-register X-form 3785*9880d681SAndroid Build Coastguard Worker instruction. (Currently always prints ``r0,OPERAND``). 3786*9880d681SAndroid Build Coastguard Worker- ``U``: Prints 'u' if the memory operand is an update form, and nothing 3787*9880d681SAndroid Build Coastguard Worker otherwise. (NOTE: LLVM does not support update form, so this will currently 3788*9880d681SAndroid Build Coastguard Worker always print nothing) 3789*9880d681SAndroid Build Coastguard Worker- ``X``: Prints 'x' if the memory operand is an indexed form. (NOTE: LLVM does 3790*9880d681SAndroid Build Coastguard Worker not support indexed form, so this will currently always print nothing) 3791*9880d681SAndroid Build Coastguard Worker 3792*9880d681SAndroid Build Coastguard WorkerSparc: 3793*9880d681SAndroid Build Coastguard Worker 3794*9880d681SAndroid Build Coastguard Worker- ``r``: No effect. 3795*9880d681SAndroid Build Coastguard Worker 3796*9880d681SAndroid Build Coastguard WorkerSystemZ: 3797*9880d681SAndroid Build Coastguard Worker 3798*9880d681SAndroid Build Coastguard WorkerSystemZ implements only ``n``, and does *not* support any of the other 3799*9880d681SAndroid Build Coastguard Workertarget-independent modifiers. 3800*9880d681SAndroid Build Coastguard Worker 3801*9880d681SAndroid Build Coastguard WorkerX86: 3802*9880d681SAndroid Build Coastguard Worker 3803*9880d681SAndroid Build Coastguard Worker- ``c``: Print an unadorned integer or symbol name. (The latter is 3804*9880d681SAndroid Build Coastguard Worker target-specific behavior for this typically target-independent modifier). 3805*9880d681SAndroid Build Coastguard Worker- ``A``: Print a register name with a '``*``' before it. 3806*9880d681SAndroid Build Coastguard Worker- ``b``: Print an 8-bit register name (e.g. ``al``); do nothing on a memory 3807*9880d681SAndroid Build Coastguard Worker operand. 3808*9880d681SAndroid Build Coastguard Worker- ``h``: Print the upper 8-bit register name (e.g. ``ah``); do nothing on a 3809*9880d681SAndroid Build Coastguard Worker memory operand. 3810*9880d681SAndroid Build Coastguard Worker- ``w``: Print the 16-bit register name (e.g. ``ax``); do nothing on a memory 3811*9880d681SAndroid Build Coastguard Worker operand. 3812*9880d681SAndroid Build Coastguard Worker- ``k``: Print the 32-bit register name (e.g. ``eax``); do nothing on a memory 3813*9880d681SAndroid Build Coastguard Worker operand. 3814*9880d681SAndroid Build Coastguard Worker- ``q``: Print the 64-bit register name (e.g. ``rax``), if 64-bit registers are 3815*9880d681SAndroid Build Coastguard Worker available, otherwise the 32-bit register name; do nothing on a memory operand. 3816*9880d681SAndroid Build Coastguard Worker- ``n``: Negate and print an unadorned integer, or, for operands other than an 3817*9880d681SAndroid Build Coastguard Worker immediate integer (e.g. a relocatable symbol expression), print a '-' before 3818*9880d681SAndroid Build Coastguard Worker the operand. (The behavior for relocatable symbol expressions is a 3819*9880d681SAndroid Build Coastguard Worker target-specific behavior for this typically target-independent modifier) 3820*9880d681SAndroid Build Coastguard Worker- ``H``: Print a memory reference with additional offset +8. 3821*9880d681SAndroid Build Coastguard Worker- ``P``: Print a memory reference or operand for use as the argument of a call 3822*9880d681SAndroid Build Coastguard Worker instruction. (E.g. omit ``(rip)``, even though it's PC-relative.) 3823*9880d681SAndroid Build Coastguard Worker 3824*9880d681SAndroid Build Coastguard WorkerXCore: 3825*9880d681SAndroid Build Coastguard Worker 3826*9880d681SAndroid Build Coastguard WorkerNo additional modifiers. 3827*9880d681SAndroid Build Coastguard Worker 3828*9880d681SAndroid Build Coastguard Worker 3829*9880d681SAndroid Build Coastguard WorkerInline Asm Metadata 3830*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^ 3831*9880d681SAndroid Build Coastguard Worker 3832*9880d681SAndroid Build Coastguard WorkerThe call instructions that wrap inline asm nodes may have a 3833*9880d681SAndroid Build Coastguard Worker"``!srcloc``" MDNode attached to it that contains a list of constant 3834*9880d681SAndroid Build Coastguard Workerintegers. If present, the code generator will use the integer as the 3835*9880d681SAndroid Build Coastguard Workerlocation cookie value when report errors through the ``LLVMContext`` 3836*9880d681SAndroid Build Coastguard Workererror reporting mechanisms. This allows a front-end to correlate backend 3837*9880d681SAndroid Build Coastguard Workererrors that occur with inline asm back to the source code that produced 3838*9880d681SAndroid Build Coastguard Workerit. For example: 3839*9880d681SAndroid Build Coastguard Worker 3840*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 3841*9880d681SAndroid Build Coastguard Worker 3842*9880d681SAndroid Build Coastguard Worker call void asm sideeffect "something bad", ""(), !srcloc !42 3843*9880d681SAndroid Build Coastguard Worker ... 3844*9880d681SAndroid Build Coastguard Worker !42 = !{ i32 1234567 } 3845*9880d681SAndroid Build Coastguard Worker 3846*9880d681SAndroid Build Coastguard WorkerIt is up to the front-end to make sense of the magic numbers it places 3847*9880d681SAndroid Build Coastguard Workerin the IR. If the MDNode contains multiple constants, the code generator 3848*9880d681SAndroid Build Coastguard Workerwill use the one that corresponds to the line of the asm that the error 3849*9880d681SAndroid Build Coastguard Workeroccurs on. 3850*9880d681SAndroid Build Coastguard Worker 3851*9880d681SAndroid Build Coastguard Worker.. _metadata: 3852*9880d681SAndroid Build Coastguard Worker 3853*9880d681SAndroid Build Coastguard WorkerMetadata 3854*9880d681SAndroid Build Coastguard Worker======== 3855*9880d681SAndroid Build Coastguard Worker 3856*9880d681SAndroid Build Coastguard WorkerLLVM IR allows metadata to be attached to instructions in the program 3857*9880d681SAndroid Build Coastguard Workerthat can convey extra information about the code to the optimizers and 3858*9880d681SAndroid Build Coastguard Workercode generator. One example application of metadata is source-level 3859*9880d681SAndroid Build Coastguard Workerdebug information. There are two metadata primitives: strings and nodes. 3860*9880d681SAndroid Build Coastguard Worker 3861*9880d681SAndroid Build Coastguard WorkerMetadata does not have a type, and is not a value. If referenced from a 3862*9880d681SAndroid Build Coastguard Worker``call`` instruction, it uses the ``metadata`` type. 3863*9880d681SAndroid Build Coastguard Worker 3864*9880d681SAndroid Build Coastguard WorkerAll metadata are identified in syntax by a exclamation point ('``!``'). 3865*9880d681SAndroid Build Coastguard Worker 3866*9880d681SAndroid Build Coastguard Worker.. _metadata-string: 3867*9880d681SAndroid Build Coastguard Worker 3868*9880d681SAndroid Build Coastguard WorkerMetadata Nodes and Metadata Strings 3869*9880d681SAndroid Build Coastguard Worker----------------------------------- 3870*9880d681SAndroid Build Coastguard Worker 3871*9880d681SAndroid Build Coastguard WorkerA metadata string is a string surrounded by double quotes. It can 3872*9880d681SAndroid Build Coastguard Workercontain any character by escaping non-printable characters with 3873*9880d681SAndroid Build Coastguard Worker"``\xx``" where "``xx``" is the two digit hex code. For example: 3874*9880d681SAndroid Build Coastguard Worker"``!"test\00"``". 3875*9880d681SAndroid Build Coastguard Worker 3876*9880d681SAndroid Build Coastguard WorkerMetadata nodes are represented with notation similar to structure 3877*9880d681SAndroid Build Coastguard Workerconstants (a comma separated list of elements, surrounded by braces and 3878*9880d681SAndroid Build Coastguard Workerpreceded by an exclamation point). Metadata nodes can have any values as 3879*9880d681SAndroid Build Coastguard Workertheir operand. For example: 3880*9880d681SAndroid Build Coastguard Worker 3881*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 3882*9880d681SAndroid Build Coastguard Worker 3883*9880d681SAndroid Build Coastguard Worker !{ !"test\00", i32 10} 3884*9880d681SAndroid Build Coastguard Worker 3885*9880d681SAndroid Build Coastguard WorkerMetadata nodes that aren't uniqued use the ``distinct`` keyword. For example: 3886*9880d681SAndroid Build Coastguard Worker 3887*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 3888*9880d681SAndroid Build Coastguard Worker 3889*9880d681SAndroid Build Coastguard Worker !0 = distinct !{!"test\00", i32 10} 3890*9880d681SAndroid Build Coastguard Worker 3891*9880d681SAndroid Build Coastguard Worker``distinct`` nodes are useful when nodes shouldn't be merged based on their 3892*9880d681SAndroid Build Coastguard Workercontent. They can also occur when transformations cause uniquing collisions 3893*9880d681SAndroid Build Coastguard Workerwhen metadata operands change. 3894*9880d681SAndroid Build Coastguard Worker 3895*9880d681SAndroid Build Coastguard WorkerA :ref:`named metadata <namedmetadatastructure>` is a collection of 3896*9880d681SAndroid Build Coastguard Workermetadata nodes, which can be looked up in the module symbol table. For 3897*9880d681SAndroid Build Coastguard Workerexample: 3898*9880d681SAndroid Build Coastguard Worker 3899*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 3900*9880d681SAndroid Build Coastguard Worker 3901*9880d681SAndroid Build Coastguard Worker !foo = !{!4, !3} 3902*9880d681SAndroid Build Coastguard Worker 3903*9880d681SAndroid Build Coastguard WorkerMetadata can be used as function arguments. Here ``llvm.dbg.value`` 3904*9880d681SAndroid Build Coastguard Workerfunction is using two metadata arguments: 3905*9880d681SAndroid Build Coastguard Worker 3906*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 3907*9880d681SAndroid Build Coastguard Worker 3908*9880d681SAndroid Build Coastguard Worker call void @llvm.dbg.value(metadata !24, i64 0, metadata !25) 3909*9880d681SAndroid Build Coastguard Worker 3910*9880d681SAndroid Build Coastguard WorkerMetadata can be attached to an instruction. Here metadata ``!21`` is attached 3911*9880d681SAndroid Build Coastguard Workerto the ``add`` instruction using the ``!dbg`` identifier: 3912*9880d681SAndroid Build Coastguard Worker 3913*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 3914*9880d681SAndroid Build Coastguard Worker 3915*9880d681SAndroid Build Coastguard Worker %indvar.next = add i64 %indvar, 1, !dbg !21 3916*9880d681SAndroid Build Coastguard Worker 3917*9880d681SAndroid Build Coastguard WorkerMetadata can also be attached to a function definition. Here metadata ``!22`` 3918*9880d681SAndroid Build Coastguard Workeris attached to the ``foo`` function using the ``!dbg`` identifier: 3919*9880d681SAndroid Build Coastguard Worker 3920*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 3921*9880d681SAndroid Build Coastguard Worker 3922*9880d681SAndroid Build Coastguard Worker define void @foo() !dbg !22 { 3923*9880d681SAndroid Build Coastguard Worker ret void 3924*9880d681SAndroid Build Coastguard Worker } 3925*9880d681SAndroid Build Coastguard Worker 3926*9880d681SAndroid Build Coastguard WorkerMore information about specific metadata nodes recognized by the 3927*9880d681SAndroid Build Coastguard Workeroptimizers and code generator is found below. 3928*9880d681SAndroid Build Coastguard Worker 3929*9880d681SAndroid Build Coastguard Worker.. _specialized-metadata: 3930*9880d681SAndroid Build Coastguard Worker 3931*9880d681SAndroid Build Coastguard WorkerSpecialized Metadata Nodes 3932*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^ 3933*9880d681SAndroid Build Coastguard Worker 3934*9880d681SAndroid Build Coastguard WorkerSpecialized metadata nodes are custom data structures in metadata (as opposed 3935*9880d681SAndroid Build Coastguard Workerto generic tuples). Their fields are labelled, and can be specified in any 3936*9880d681SAndroid Build Coastguard Workerorder. 3937*9880d681SAndroid Build Coastguard Worker 3938*9880d681SAndroid Build Coastguard WorkerThese aren't inherently debug info centric, but currently all the specialized 3939*9880d681SAndroid Build Coastguard Workermetadata nodes are related to debug info. 3940*9880d681SAndroid Build Coastguard Worker 3941*9880d681SAndroid Build Coastguard Worker.. _DICompileUnit: 3942*9880d681SAndroid Build Coastguard Worker 3943*9880d681SAndroid Build Coastguard WorkerDICompileUnit 3944*9880d681SAndroid Build Coastguard Worker""""""""""""" 3945*9880d681SAndroid Build Coastguard Worker 3946*9880d681SAndroid Build Coastguard Worker``DICompileUnit`` nodes represent a compile unit. The ``enums:``, 3947*9880d681SAndroid Build Coastguard Worker``retainedTypes:``, ``subprograms:``, ``globals:``, ``imports:`` and ``macros:`` 3948*9880d681SAndroid Build Coastguard Workerfields are tuples containing the debug info to be emitted along with the compile 3949*9880d681SAndroid Build Coastguard Workerunit, regardless of code optimizations (some nodes are only emitted if there are 3950*9880d681SAndroid Build Coastguard Workerreferences to them from instructions). 3951*9880d681SAndroid Build Coastguard Worker 3952*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 3953*9880d681SAndroid Build Coastguard Worker 3954*9880d681SAndroid Build Coastguard Worker !0 = !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang", 3955*9880d681SAndroid Build Coastguard Worker isOptimized: true, flags: "-O2", runtimeVersion: 2, 3956*9880d681SAndroid Build Coastguard Worker splitDebugFilename: "abc.debug", emissionKind: FullDebug, 3957*9880d681SAndroid Build Coastguard Worker enums: !2, retainedTypes: !3, subprograms: !4, 3958*9880d681SAndroid Build Coastguard Worker globals: !5, imports: !6, macros: !7, dwoId: 0x0abcd) 3959*9880d681SAndroid Build Coastguard Worker 3960*9880d681SAndroid Build Coastguard WorkerCompile unit descriptors provide the root scope for objects declared in a 3961*9880d681SAndroid Build Coastguard Workerspecific compilation unit. File descriptors are defined using this scope. 3962*9880d681SAndroid Build Coastguard WorkerThese descriptors are collected by a named metadata ``!llvm.dbg.cu``. They 3963*9880d681SAndroid Build Coastguard Workerkeep track of subprograms, global variables, type information, and imported 3964*9880d681SAndroid Build Coastguard Workerentities (declarations and namespaces). 3965*9880d681SAndroid Build Coastguard Worker 3966*9880d681SAndroid Build Coastguard Worker.. _DIFile: 3967*9880d681SAndroid Build Coastguard Worker 3968*9880d681SAndroid Build Coastguard WorkerDIFile 3969*9880d681SAndroid Build Coastguard Worker"""""" 3970*9880d681SAndroid Build Coastguard Worker 3971*9880d681SAndroid Build Coastguard Worker``DIFile`` nodes represent files. The ``filename:`` can include slashes. 3972*9880d681SAndroid Build Coastguard Worker 3973*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 3974*9880d681SAndroid Build Coastguard Worker 3975*9880d681SAndroid Build Coastguard Worker !0 = !DIFile(filename: "path/to/file", directory: "/path/to/dir") 3976*9880d681SAndroid Build Coastguard Worker 3977*9880d681SAndroid Build Coastguard WorkerFiles are sometimes used in ``scope:`` fields, and are the only valid target 3978*9880d681SAndroid Build Coastguard Workerfor ``file:`` fields. 3979*9880d681SAndroid Build Coastguard Worker 3980*9880d681SAndroid Build Coastguard Worker.. _DIBasicType: 3981*9880d681SAndroid Build Coastguard Worker 3982*9880d681SAndroid Build Coastguard WorkerDIBasicType 3983*9880d681SAndroid Build Coastguard Worker""""""""""" 3984*9880d681SAndroid Build Coastguard Worker 3985*9880d681SAndroid Build Coastguard Worker``DIBasicType`` nodes represent primitive types, such as ``int``, ``bool`` and 3986*9880d681SAndroid Build Coastguard Worker``float``. ``tag:`` defaults to ``DW_TAG_base_type``. 3987*9880d681SAndroid Build Coastguard Worker 3988*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 3989*9880d681SAndroid Build Coastguard Worker 3990*9880d681SAndroid Build Coastguard Worker !0 = !DIBasicType(name: "unsigned char", size: 8, align: 8, 3991*9880d681SAndroid Build Coastguard Worker encoding: DW_ATE_unsigned_char) 3992*9880d681SAndroid Build Coastguard Worker !1 = !DIBasicType(tag: DW_TAG_unspecified_type, name: "decltype(nullptr)") 3993*9880d681SAndroid Build Coastguard Worker 3994*9880d681SAndroid Build Coastguard WorkerThe ``encoding:`` describes the details of the type. Usually it's one of the 3995*9880d681SAndroid Build Coastguard Workerfollowing: 3996*9880d681SAndroid Build Coastguard Worker 3997*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 3998*9880d681SAndroid Build Coastguard Worker 3999*9880d681SAndroid Build Coastguard Worker DW_ATE_address = 1 4000*9880d681SAndroid Build Coastguard Worker DW_ATE_boolean = 2 4001*9880d681SAndroid Build Coastguard Worker DW_ATE_float = 4 4002*9880d681SAndroid Build Coastguard Worker DW_ATE_signed = 5 4003*9880d681SAndroid Build Coastguard Worker DW_ATE_signed_char = 6 4004*9880d681SAndroid Build Coastguard Worker DW_ATE_unsigned = 7 4005*9880d681SAndroid Build Coastguard Worker DW_ATE_unsigned_char = 8 4006*9880d681SAndroid Build Coastguard Worker 4007*9880d681SAndroid Build Coastguard Worker.. _DISubroutineType: 4008*9880d681SAndroid Build Coastguard Worker 4009*9880d681SAndroid Build Coastguard WorkerDISubroutineType 4010*9880d681SAndroid Build Coastguard Worker"""""""""""""""" 4011*9880d681SAndroid Build Coastguard Worker 4012*9880d681SAndroid Build Coastguard Worker``DISubroutineType`` nodes represent subroutine types. Their ``types:`` field 4013*9880d681SAndroid Build Coastguard Workerrefers to a tuple; the first operand is the return type, while the rest are the 4014*9880d681SAndroid Build Coastguard Workertypes of the formal arguments in order. If the first operand is ``null``, that 4015*9880d681SAndroid Build Coastguard Workerrepresents a function with no return value (such as ``void foo() {}`` in C++). 4016*9880d681SAndroid Build Coastguard Worker 4017*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 4018*9880d681SAndroid Build Coastguard Worker 4019*9880d681SAndroid Build Coastguard Worker !0 = !BasicType(name: "int", size: 32, align: 32, DW_ATE_signed) 4020*9880d681SAndroid Build Coastguard Worker !1 = !BasicType(name: "char", size: 8, align: 8, DW_ATE_signed_char) 4021*9880d681SAndroid Build Coastguard Worker !2 = !DISubroutineType(types: !{null, !0, !1}) ; void (int, char) 4022*9880d681SAndroid Build Coastguard Worker 4023*9880d681SAndroid Build Coastguard Worker.. _DIDerivedType: 4024*9880d681SAndroid Build Coastguard Worker 4025*9880d681SAndroid Build Coastguard WorkerDIDerivedType 4026*9880d681SAndroid Build Coastguard Worker""""""""""""" 4027*9880d681SAndroid Build Coastguard Worker 4028*9880d681SAndroid Build Coastguard Worker``DIDerivedType`` nodes represent types derived from other types, such as 4029*9880d681SAndroid Build Coastguard Workerqualified types. 4030*9880d681SAndroid Build Coastguard Worker 4031*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 4032*9880d681SAndroid Build Coastguard Worker 4033*9880d681SAndroid Build Coastguard Worker !0 = !DIBasicType(name: "unsigned char", size: 8, align: 8, 4034*9880d681SAndroid Build Coastguard Worker encoding: DW_ATE_unsigned_char) 4035*9880d681SAndroid Build Coastguard Worker !1 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !0, size: 32, 4036*9880d681SAndroid Build Coastguard Worker align: 32) 4037*9880d681SAndroid Build Coastguard Worker 4038*9880d681SAndroid Build Coastguard WorkerThe following ``tag:`` values are valid: 4039*9880d681SAndroid Build Coastguard Worker 4040*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 4041*9880d681SAndroid Build Coastguard Worker 4042*9880d681SAndroid Build Coastguard Worker DW_TAG_member = 13 4043*9880d681SAndroid Build Coastguard Worker DW_TAG_pointer_type = 15 4044*9880d681SAndroid Build Coastguard Worker DW_TAG_reference_type = 16 4045*9880d681SAndroid Build Coastguard Worker DW_TAG_typedef = 22 4046*9880d681SAndroid Build Coastguard Worker DW_TAG_inheritance = 28 4047*9880d681SAndroid Build Coastguard Worker DW_TAG_ptr_to_member_type = 31 4048*9880d681SAndroid Build Coastguard Worker DW_TAG_const_type = 38 4049*9880d681SAndroid Build Coastguard Worker DW_TAG_friend = 42 4050*9880d681SAndroid Build Coastguard Worker DW_TAG_volatile_type = 53 4051*9880d681SAndroid Build Coastguard Worker DW_TAG_restrict_type = 55 4052*9880d681SAndroid Build Coastguard Worker 4053*9880d681SAndroid Build Coastguard Worker.. _DIDerivedTypeMember: 4054*9880d681SAndroid Build Coastguard Worker 4055*9880d681SAndroid Build Coastguard Worker``DW_TAG_member`` is used to define a member of a :ref:`composite type 4056*9880d681SAndroid Build Coastguard Worker<DICompositeType>`. The type of the member is the ``baseType:``. The 4057*9880d681SAndroid Build Coastguard Worker``offset:`` is the member's bit offset. If the composite type has an ODR 4058*9880d681SAndroid Build Coastguard Worker``identifier:`` and does not set ``flags: DIFwdDecl``, then the member is 4059*9880d681SAndroid Build Coastguard Workeruniqued based only on its ``name:`` and ``scope:``. 4060*9880d681SAndroid Build Coastguard Worker 4061*9880d681SAndroid Build Coastguard Worker``DW_TAG_inheritance`` and ``DW_TAG_friend`` are used in the ``elements:`` 4062*9880d681SAndroid Build Coastguard Workerfield of :ref:`composite types <DICompositeType>` to describe parents and 4063*9880d681SAndroid Build Coastguard Workerfriends. 4064*9880d681SAndroid Build Coastguard Worker 4065*9880d681SAndroid Build Coastguard Worker``DW_TAG_typedef`` is used to provide a name for the ``baseType:``. 4066*9880d681SAndroid Build Coastguard Worker 4067*9880d681SAndroid Build Coastguard Worker``DW_TAG_pointer_type``, ``DW_TAG_reference_type``, ``DW_TAG_const_type``, 4068*9880d681SAndroid Build Coastguard Worker``DW_TAG_volatile_type`` and ``DW_TAG_restrict_type`` are used to qualify the 4069*9880d681SAndroid Build Coastguard Worker``baseType:``. 4070*9880d681SAndroid Build Coastguard Worker 4071*9880d681SAndroid Build Coastguard WorkerNote that the ``void *`` type is expressed as a type derived from NULL. 4072*9880d681SAndroid Build Coastguard Worker 4073*9880d681SAndroid Build Coastguard Worker.. _DICompositeType: 4074*9880d681SAndroid Build Coastguard Worker 4075*9880d681SAndroid Build Coastguard WorkerDICompositeType 4076*9880d681SAndroid Build Coastguard Worker""""""""""""""" 4077*9880d681SAndroid Build Coastguard Worker 4078*9880d681SAndroid Build Coastguard Worker``DICompositeType`` nodes represent types composed of other types, like 4079*9880d681SAndroid Build Coastguard Workerstructures and unions. ``elements:`` points to a tuple of the composed types. 4080*9880d681SAndroid Build Coastguard Worker 4081*9880d681SAndroid Build Coastguard WorkerIf the source language supports ODR, the ``identifier:`` field gives the unique 4082*9880d681SAndroid Build Coastguard Workeridentifier used for type merging between modules. When specified, 4083*9880d681SAndroid Build Coastguard Worker:ref:`subprogram declarations <DISubprogramDeclaration>` and :ref:`member 4084*9880d681SAndroid Build Coastguard Workerderived types <DIDerivedTypeMember>` that reference the ODR-type in their 4085*9880d681SAndroid Build Coastguard Worker``scope:`` change uniquing rules. 4086*9880d681SAndroid Build Coastguard Worker 4087*9880d681SAndroid Build Coastguard WorkerFor a given ``identifier:``, there should only be a single composite type that 4088*9880d681SAndroid Build Coastguard Workerdoes not have ``flags: DIFlagFwdDecl`` set. LLVM tools that link modules 4089*9880d681SAndroid Build Coastguard Workertogether will unique such definitions at parse time via the ``identifier:`` 4090*9880d681SAndroid Build Coastguard Workerfield, even if the nodes are ``distinct``. 4091*9880d681SAndroid Build Coastguard Worker 4092*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 4093*9880d681SAndroid Build Coastguard Worker 4094*9880d681SAndroid Build Coastguard Worker !0 = !DIEnumerator(name: "SixKind", value: 7) 4095*9880d681SAndroid Build Coastguard Worker !1 = !DIEnumerator(name: "SevenKind", value: 7) 4096*9880d681SAndroid Build Coastguard Worker !2 = !DIEnumerator(name: "NegEightKind", value: -8) 4097*9880d681SAndroid Build Coastguard Worker !3 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "Enum", file: !12, 4098*9880d681SAndroid Build Coastguard Worker line: 2, size: 32, align: 32, identifier: "_M4Enum", 4099*9880d681SAndroid Build Coastguard Worker elements: !{!0, !1, !2}) 4100*9880d681SAndroid Build Coastguard Worker 4101*9880d681SAndroid Build Coastguard WorkerThe following ``tag:`` values are valid: 4102*9880d681SAndroid Build Coastguard Worker 4103*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 4104*9880d681SAndroid Build Coastguard Worker 4105*9880d681SAndroid Build Coastguard Worker DW_TAG_array_type = 1 4106*9880d681SAndroid Build Coastguard Worker DW_TAG_class_type = 2 4107*9880d681SAndroid Build Coastguard Worker DW_TAG_enumeration_type = 4 4108*9880d681SAndroid Build Coastguard Worker DW_TAG_structure_type = 19 4109*9880d681SAndroid Build Coastguard Worker DW_TAG_union_type = 23 4110*9880d681SAndroid Build Coastguard Worker 4111*9880d681SAndroid Build Coastguard WorkerFor ``DW_TAG_array_type``, the ``elements:`` should be :ref:`subrange 4112*9880d681SAndroid Build Coastguard Workerdescriptors <DISubrange>`, each representing the range of subscripts at that 4113*9880d681SAndroid Build Coastguard Workerlevel of indexing. The ``DIFlagVector`` flag to ``flags:`` indicates that an 4114*9880d681SAndroid Build Coastguard Workerarray type is a native packed vector. 4115*9880d681SAndroid Build Coastguard Worker 4116*9880d681SAndroid Build Coastguard WorkerFor ``DW_TAG_enumeration_type``, the ``elements:`` should be :ref:`enumerator 4117*9880d681SAndroid Build Coastguard Workerdescriptors <DIEnumerator>`, each representing the definition of an enumeration 4118*9880d681SAndroid Build Coastguard Workervalue for the set. All enumeration type descriptors are collected in the 4119*9880d681SAndroid Build Coastguard Worker``enums:`` field of the :ref:`compile unit <DICompileUnit>`. 4120*9880d681SAndroid Build Coastguard Worker 4121*9880d681SAndroid Build Coastguard WorkerFor ``DW_TAG_structure_type``, ``DW_TAG_class_type``, and 4122*9880d681SAndroid Build Coastguard Worker``DW_TAG_union_type``, the ``elements:`` should be :ref:`derived types 4123*9880d681SAndroid Build Coastguard Worker<DIDerivedType>` with ``tag: DW_TAG_member``, ``tag: DW_TAG_inheritance``, or 4124*9880d681SAndroid Build Coastguard Worker``tag: DW_TAG_friend``; or :ref:`subprograms <DISubprogram>` with 4125*9880d681SAndroid Build Coastguard Worker``isDefinition: false``. 4126*9880d681SAndroid Build Coastguard Worker 4127*9880d681SAndroid Build Coastguard Worker.. _DISubrange: 4128*9880d681SAndroid Build Coastguard Worker 4129*9880d681SAndroid Build Coastguard WorkerDISubrange 4130*9880d681SAndroid Build Coastguard Worker"""""""""" 4131*9880d681SAndroid Build Coastguard Worker 4132*9880d681SAndroid Build Coastguard Worker``DISubrange`` nodes are the elements for ``DW_TAG_array_type`` variants of 4133*9880d681SAndroid Build Coastguard Worker:ref:`DICompositeType`. ``count: -1`` indicates an empty array. 4134*9880d681SAndroid Build Coastguard Worker 4135*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 4136*9880d681SAndroid Build Coastguard Worker 4137*9880d681SAndroid Build Coastguard Worker !0 = !DISubrange(count: 5, lowerBound: 0) ; array counting from 0 4138*9880d681SAndroid Build Coastguard Worker !1 = !DISubrange(count: 5, lowerBound: 1) ; array counting from 1 4139*9880d681SAndroid Build Coastguard Worker !2 = !DISubrange(count: -1) ; empty array. 4140*9880d681SAndroid Build Coastguard Worker 4141*9880d681SAndroid Build Coastguard Worker.. _DIEnumerator: 4142*9880d681SAndroid Build Coastguard Worker 4143*9880d681SAndroid Build Coastguard WorkerDIEnumerator 4144*9880d681SAndroid Build Coastguard Worker"""""""""""" 4145*9880d681SAndroid Build Coastguard Worker 4146*9880d681SAndroid Build Coastguard Worker``DIEnumerator`` nodes are the elements for ``DW_TAG_enumeration_type`` 4147*9880d681SAndroid Build Coastguard Workervariants of :ref:`DICompositeType`. 4148*9880d681SAndroid Build Coastguard Worker 4149*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 4150*9880d681SAndroid Build Coastguard Worker 4151*9880d681SAndroid Build Coastguard Worker !0 = !DIEnumerator(name: "SixKind", value: 7) 4152*9880d681SAndroid Build Coastguard Worker !1 = !DIEnumerator(name: "SevenKind", value: 7) 4153*9880d681SAndroid Build Coastguard Worker !2 = !DIEnumerator(name: "NegEightKind", value: -8) 4154*9880d681SAndroid Build Coastguard Worker 4155*9880d681SAndroid Build Coastguard WorkerDITemplateTypeParameter 4156*9880d681SAndroid Build Coastguard Worker""""""""""""""""""""""" 4157*9880d681SAndroid Build Coastguard Worker 4158*9880d681SAndroid Build Coastguard Worker``DITemplateTypeParameter`` nodes represent type parameters to generic source 4159*9880d681SAndroid Build Coastguard Workerlanguage constructs. They are used (optionally) in :ref:`DICompositeType` and 4160*9880d681SAndroid Build Coastguard Worker:ref:`DISubprogram` ``templateParams:`` fields. 4161*9880d681SAndroid Build Coastguard Worker 4162*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 4163*9880d681SAndroid Build Coastguard Worker 4164*9880d681SAndroid Build Coastguard Worker !0 = !DITemplateTypeParameter(name: "Ty", type: !1) 4165*9880d681SAndroid Build Coastguard Worker 4166*9880d681SAndroid Build Coastguard WorkerDITemplateValueParameter 4167*9880d681SAndroid Build Coastguard Worker"""""""""""""""""""""""" 4168*9880d681SAndroid Build Coastguard Worker 4169*9880d681SAndroid Build Coastguard Worker``DITemplateValueParameter`` nodes represent value parameters to generic source 4170*9880d681SAndroid Build Coastguard Workerlanguage constructs. ``tag:`` defaults to ``DW_TAG_template_value_parameter``, 4171*9880d681SAndroid Build Coastguard Workerbut if specified can also be set to ``DW_TAG_GNU_template_template_param`` or 4172*9880d681SAndroid Build Coastguard Worker``DW_TAG_GNU_template_param_pack``. They are used (optionally) in 4173*9880d681SAndroid Build Coastguard Worker:ref:`DICompositeType` and :ref:`DISubprogram` ``templateParams:`` fields. 4174*9880d681SAndroid Build Coastguard Worker 4175*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 4176*9880d681SAndroid Build Coastguard Worker 4177*9880d681SAndroid Build Coastguard Worker !0 = !DITemplateValueParameter(name: "Ty", type: !1, value: i32 7) 4178*9880d681SAndroid Build Coastguard Worker 4179*9880d681SAndroid Build Coastguard WorkerDINamespace 4180*9880d681SAndroid Build Coastguard Worker""""""""""" 4181*9880d681SAndroid Build Coastguard Worker 4182*9880d681SAndroid Build Coastguard Worker``DINamespace`` nodes represent namespaces in the source language. 4183*9880d681SAndroid Build Coastguard Worker 4184*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 4185*9880d681SAndroid Build Coastguard Worker 4186*9880d681SAndroid Build Coastguard Worker !0 = !DINamespace(name: "myawesomeproject", scope: !1, file: !2, line: 7) 4187*9880d681SAndroid Build Coastguard Worker 4188*9880d681SAndroid Build Coastguard WorkerDIGlobalVariable 4189*9880d681SAndroid Build Coastguard Worker"""""""""""""""" 4190*9880d681SAndroid Build Coastguard Worker 4191*9880d681SAndroid Build Coastguard Worker``DIGlobalVariable`` nodes represent global variables in the source language. 4192*9880d681SAndroid Build Coastguard Worker 4193*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 4194*9880d681SAndroid Build Coastguard Worker 4195*9880d681SAndroid Build Coastguard Worker !0 = !DIGlobalVariable(name: "foo", linkageName: "foo", scope: !1, 4196*9880d681SAndroid Build Coastguard Worker file: !2, line: 7, type: !3, isLocal: true, 4197*9880d681SAndroid Build Coastguard Worker isDefinition: false, variable: i32* @foo, 4198*9880d681SAndroid Build Coastguard Worker declaration: !4) 4199*9880d681SAndroid Build Coastguard Worker 4200*9880d681SAndroid Build Coastguard WorkerAll global variables should be referenced by the `globals:` field of a 4201*9880d681SAndroid Build Coastguard Worker:ref:`compile unit <DICompileUnit>`. 4202*9880d681SAndroid Build Coastguard Worker 4203*9880d681SAndroid Build Coastguard Worker.. _DISubprogram: 4204*9880d681SAndroid Build Coastguard Worker 4205*9880d681SAndroid Build Coastguard WorkerDISubprogram 4206*9880d681SAndroid Build Coastguard Worker"""""""""""" 4207*9880d681SAndroid Build Coastguard Worker 4208*9880d681SAndroid Build Coastguard Worker``DISubprogram`` nodes represent functions from the source language. A 4209*9880d681SAndroid Build Coastguard Worker``DISubprogram`` may be attached to a function definition using ``!dbg`` 4210*9880d681SAndroid Build Coastguard Workermetadata. The ``variables:`` field points at :ref:`variables <DILocalVariable>` 4211*9880d681SAndroid Build Coastguard Workerthat must be retained, even if their IR counterparts are optimized out of 4212*9880d681SAndroid Build Coastguard Workerthe IR. The ``type:`` field must point at an :ref:`DISubroutineType`. 4213*9880d681SAndroid Build Coastguard Worker 4214*9880d681SAndroid Build Coastguard Worker.. _DISubprogramDeclaration: 4215*9880d681SAndroid Build Coastguard Worker 4216*9880d681SAndroid Build Coastguard WorkerWhen ``isDefinition: false``, subprograms describe a declaration in the type 4217*9880d681SAndroid Build Coastguard Workertree as opposed to a definition of a function. If the scope is a composite 4218*9880d681SAndroid Build Coastguard Workertype with an ODR ``identifier:`` and that does not set ``flags: DIFwdDecl``, 4219*9880d681SAndroid Build Coastguard Workerthen the subprogram declaration is uniqued based only on its ``linkageName:`` 4220*9880d681SAndroid Build Coastguard Workerand ``scope:``. 4221*9880d681SAndroid Build Coastguard Worker 4222*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 4223*9880d681SAndroid Build Coastguard Worker 4224*9880d681SAndroid Build Coastguard Worker define void @_Z3foov() !dbg !0 { 4225*9880d681SAndroid Build Coastguard Worker ... 4226*9880d681SAndroid Build Coastguard Worker } 4227*9880d681SAndroid Build Coastguard Worker 4228*9880d681SAndroid Build Coastguard Worker !0 = distinct !DISubprogram(name: "foo", linkageName: "_Zfoov", scope: !1, 4229*9880d681SAndroid Build Coastguard Worker file: !2, line: 7, type: !3, isLocal: true, 4230*9880d681SAndroid Build Coastguard Worker isDefinition: true, scopeLine: 8, 4231*9880d681SAndroid Build Coastguard Worker containingType: !4, 4232*9880d681SAndroid Build Coastguard Worker virtuality: DW_VIRTUALITY_pure_virtual, 4233*9880d681SAndroid Build Coastguard Worker virtualIndex: 10, flags: DIFlagPrototyped, 4234*9880d681SAndroid Build Coastguard Worker isOptimized: true, templateParams: !5, 4235*9880d681SAndroid Build Coastguard Worker declaration: !6, variables: !7) 4236*9880d681SAndroid Build Coastguard Worker 4237*9880d681SAndroid Build Coastguard Worker.. _DILexicalBlock: 4238*9880d681SAndroid Build Coastguard Worker 4239*9880d681SAndroid Build Coastguard WorkerDILexicalBlock 4240*9880d681SAndroid Build Coastguard Worker"""""""""""""" 4241*9880d681SAndroid Build Coastguard Worker 4242*9880d681SAndroid Build Coastguard Worker``DILexicalBlock`` nodes describe nested blocks within a :ref:`subprogram 4243*9880d681SAndroid Build Coastguard Worker<DISubprogram>`. The line number and column numbers are used to distinguish 4244*9880d681SAndroid Build Coastguard Workertwo lexical blocks at same depth. They are valid targets for ``scope:`` 4245*9880d681SAndroid Build Coastguard Workerfields. 4246*9880d681SAndroid Build Coastguard Worker 4247*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 4248*9880d681SAndroid Build Coastguard Worker 4249*9880d681SAndroid Build Coastguard Worker !0 = distinct !DILexicalBlock(scope: !1, file: !2, line: 7, column: 35) 4250*9880d681SAndroid Build Coastguard Worker 4251*9880d681SAndroid Build Coastguard WorkerUsually lexical blocks are ``distinct`` to prevent node merging based on 4252*9880d681SAndroid Build Coastguard Workeroperands. 4253*9880d681SAndroid Build Coastguard Worker 4254*9880d681SAndroid Build Coastguard Worker.. _DILexicalBlockFile: 4255*9880d681SAndroid Build Coastguard Worker 4256*9880d681SAndroid Build Coastguard WorkerDILexicalBlockFile 4257*9880d681SAndroid Build Coastguard Worker"""""""""""""""""" 4258*9880d681SAndroid Build Coastguard Worker 4259*9880d681SAndroid Build Coastguard Worker``DILexicalBlockFile`` nodes are used to discriminate between sections of a 4260*9880d681SAndroid Build Coastguard Worker:ref:`lexical block <DILexicalBlock>`. The ``file:`` field can be changed to 4261*9880d681SAndroid Build Coastguard Workerindicate textual inclusion, or the ``discriminator:`` field can be used to 4262*9880d681SAndroid Build Coastguard Workerdiscriminate between control flow within a single block in the source language. 4263*9880d681SAndroid Build Coastguard Worker 4264*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 4265*9880d681SAndroid Build Coastguard Worker 4266*9880d681SAndroid Build Coastguard Worker !0 = !DILexicalBlock(scope: !3, file: !4, line: 7, column: 35) 4267*9880d681SAndroid Build Coastguard Worker !1 = !DILexicalBlockFile(scope: !0, file: !4, discriminator: 0) 4268*9880d681SAndroid Build Coastguard Worker !2 = !DILexicalBlockFile(scope: !0, file: !4, discriminator: 1) 4269*9880d681SAndroid Build Coastguard Worker 4270*9880d681SAndroid Build Coastguard Worker.. _DILocation: 4271*9880d681SAndroid Build Coastguard Worker 4272*9880d681SAndroid Build Coastguard WorkerDILocation 4273*9880d681SAndroid Build Coastguard Worker"""""""""" 4274*9880d681SAndroid Build Coastguard Worker 4275*9880d681SAndroid Build Coastguard Worker``DILocation`` nodes represent source debug locations. The ``scope:`` field is 4276*9880d681SAndroid Build Coastguard Workermandatory, and points at an :ref:`DILexicalBlockFile`, an 4277*9880d681SAndroid Build Coastguard Worker:ref:`DILexicalBlock`, or an :ref:`DISubprogram`. 4278*9880d681SAndroid Build Coastguard Worker 4279*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 4280*9880d681SAndroid Build Coastguard Worker 4281*9880d681SAndroid Build Coastguard Worker !0 = !DILocation(line: 2900, column: 42, scope: !1, inlinedAt: !2) 4282*9880d681SAndroid Build Coastguard Worker 4283*9880d681SAndroid Build Coastguard Worker.. _DILocalVariable: 4284*9880d681SAndroid Build Coastguard Worker 4285*9880d681SAndroid Build Coastguard WorkerDILocalVariable 4286*9880d681SAndroid Build Coastguard Worker""""""""""""""" 4287*9880d681SAndroid Build Coastguard Worker 4288*9880d681SAndroid Build Coastguard Worker``DILocalVariable`` nodes represent local variables in the source language. If 4289*9880d681SAndroid Build Coastguard Workerthe ``arg:`` field is set to non-zero, then this variable is a subprogram 4290*9880d681SAndroid Build Coastguard Workerparameter, and it will be included in the ``variables:`` field of its 4291*9880d681SAndroid Build Coastguard Worker:ref:`DISubprogram`. 4292*9880d681SAndroid Build Coastguard Worker 4293*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 4294*9880d681SAndroid Build Coastguard Worker 4295*9880d681SAndroid Build Coastguard Worker !0 = !DILocalVariable(name: "this", arg: 1, scope: !3, file: !2, line: 7, 4296*9880d681SAndroid Build Coastguard Worker type: !3, flags: DIFlagArtificial) 4297*9880d681SAndroid Build Coastguard Worker !1 = !DILocalVariable(name: "x", arg: 2, scope: !4, file: !2, line: 7, 4298*9880d681SAndroid Build Coastguard Worker type: !3) 4299*9880d681SAndroid Build Coastguard Worker !2 = !DILocalVariable(name: "y", scope: !5, file: !2, line: 7, type: !3) 4300*9880d681SAndroid Build Coastguard Worker 4301*9880d681SAndroid Build Coastguard WorkerDIExpression 4302*9880d681SAndroid Build Coastguard Worker"""""""""""" 4303*9880d681SAndroid Build Coastguard Worker 4304*9880d681SAndroid Build Coastguard Worker``DIExpression`` nodes represent DWARF expression sequences. They are used in 4305*9880d681SAndroid Build Coastguard Worker:ref:`debug intrinsics<dbg_intrinsics>` (such as ``llvm.dbg.declare``) to 4306*9880d681SAndroid Build Coastguard Workerdescribe how the referenced LLVM variable relates to the source language 4307*9880d681SAndroid Build Coastguard Workervariable. 4308*9880d681SAndroid Build Coastguard Worker 4309*9880d681SAndroid Build Coastguard WorkerThe current supported vocabulary is limited: 4310*9880d681SAndroid Build Coastguard Worker 4311*9880d681SAndroid Build Coastguard Worker- ``DW_OP_deref`` dereferences the working expression. 4312*9880d681SAndroid Build Coastguard Worker- ``DW_OP_plus, 93`` adds ``93`` to the working expression. 4313*9880d681SAndroid Build Coastguard Worker- ``DW_OP_bit_piece, 16, 8`` specifies the offset and size (``16`` and ``8`` 4314*9880d681SAndroid Build Coastguard Worker here, respectively) of the variable piece from the working expression. 4315*9880d681SAndroid Build Coastguard Worker 4316*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 4317*9880d681SAndroid Build Coastguard Worker 4318*9880d681SAndroid Build Coastguard Worker !0 = !DIExpression(DW_OP_deref) 4319*9880d681SAndroid Build Coastguard Worker !1 = !DIExpression(DW_OP_plus, 3) 4320*9880d681SAndroid Build Coastguard Worker !2 = !DIExpression(DW_OP_bit_piece, 3, 7) 4321*9880d681SAndroid Build Coastguard Worker !3 = !DIExpression(DW_OP_deref, DW_OP_plus, 3, DW_OP_bit_piece, 3, 7) 4322*9880d681SAndroid Build Coastguard Worker 4323*9880d681SAndroid Build Coastguard WorkerDIObjCProperty 4324*9880d681SAndroid Build Coastguard Worker"""""""""""""" 4325*9880d681SAndroid Build Coastguard Worker 4326*9880d681SAndroid Build Coastguard Worker``DIObjCProperty`` nodes represent Objective-C property nodes. 4327*9880d681SAndroid Build Coastguard Worker 4328*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 4329*9880d681SAndroid Build Coastguard Worker 4330*9880d681SAndroid Build Coastguard Worker !3 = !DIObjCProperty(name: "foo", file: !1, line: 7, setter: "setFoo", 4331*9880d681SAndroid Build Coastguard Worker getter: "getFoo", attributes: 7, type: !2) 4332*9880d681SAndroid Build Coastguard Worker 4333*9880d681SAndroid Build Coastguard WorkerDIImportedEntity 4334*9880d681SAndroid Build Coastguard Worker"""""""""""""""" 4335*9880d681SAndroid Build Coastguard Worker 4336*9880d681SAndroid Build Coastguard Worker``DIImportedEntity`` nodes represent entities (such as modules) imported into a 4337*9880d681SAndroid Build Coastguard Workercompile unit. 4338*9880d681SAndroid Build Coastguard Worker 4339*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 4340*9880d681SAndroid Build Coastguard Worker 4341*9880d681SAndroid Build Coastguard Worker !2 = !DIImportedEntity(tag: DW_TAG_imported_module, name: "foo", scope: !0, 4342*9880d681SAndroid Build Coastguard Worker entity: !1, line: 7) 4343*9880d681SAndroid Build Coastguard Worker 4344*9880d681SAndroid Build Coastguard WorkerDIMacro 4345*9880d681SAndroid Build Coastguard Worker""""""" 4346*9880d681SAndroid Build Coastguard Worker 4347*9880d681SAndroid Build Coastguard Worker``DIMacro`` nodes represent definition or undefinition of a macro identifiers. 4348*9880d681SAndroid Build Coastguard WorkerThe ``name:`` field is the macro identifier, followed by macro parameters when 4349*9880d681SAndroid Build Coastguard Workerdefining a function-like macro, and the ``value`` field is the token-string 4350*9880d681SAndroid Build Coastguard Workerused to expand the macro identifier. 4351*9880d681SAndroid Build Coastguard Worker 4352*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 4353*9880d681SAndroid Build Coastguard Worker 4354*9880d681SAndroid Build Coastguard Worker !2 = !DIMacro(macinfo: DW_MACINFO_define, line: 7, name: "foo(x)", 4355*9880d681SAndroid Build Coastguard Worker value: "((x) + 1)") 4356*9880d681SAndroid Build Coastguard Worker !3 = !DIMacro(macinfo: DW_MACINFO_undef, line: 30, name: "foo") 4357*9880d681SAndroid Build Coastguard Worker 4358*9880d681SAndroid Build Coastguard WorkerDIMacroFile 4359*9880d681SAndroid Build Coastguard Worker""""""""""" 4360*9880d681SAndroid Build Coastguard Worker 4361*9880d681SAndroid Build Coastguard Worker``DIMacroFile`` nodes represent inclusion of source files. 4362*9880d681SAndroid Build Coastguard WorkerThe ``nodes:`` field is a list of ``DIMacro`` and ``DIMacroFile`` nodes that 4363*9880d681SAndroid Build Coastguard Workerappear in the included source file. 4364*9880d681SAndroid Build Coastguard Worker 4365*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 4366*9880d681SAndroid Build Coastguard Worker 4367*9880d681SAndroid Build Coastguard Worker !2 = !DIMacroFile(macinfo: DW_MACINFO_start_file, line: 7, file: !2, 4368*9880d681SAndroid Build Coastguard Worker nodes: !3) 4369*9880d681SAndroid Build Coastguard Worker 4370*9880d681SAndroid Build Coastguard Worker'``tbaa``' Metadata 4371*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^ 4372*9880d681SAndroid Build Coastguard Worker 4373*9880d681SAndroid Build Coastguard WorkerIn LLVM IR, memory does not have types, so LLVM's own type system is not 4374*9880d681SAndroid Build Coastguard Workersuitable for doing TBAA. Instead, metadata is added to the IR to 4375*9880d681SAndroid Build Coastguard Workerdescribe a type system of a higher level language. This can be used to 4376*9880d681SAndroid Build Coastguard Workerimplement typical C/C++ TBAA, but it can also be used to implement 4377*9880d681SAndroid Build Coastguard Workercustom alias analysis behavior for other languages. 4378*9880d681SAndroid Build Coastguard Worker 4379*9880d681SAndroid Build Coastguard WorkerThe current metadata format is very simple. TBAA metadata nodes have up 4380*9880d681SAndroid Build Coastguard Workerto three fields, e.g.: 4381*9880d681SAndroid Build Coastguard Worker 4382*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 4383*9880d681SAndroid Build Coastguard Worker 4384*9880d681SAndroid Build Coastguard Worker !0 = !{ !"an example type tree" } 4385*9880d681SAndroid Build Coastguard Worker !1 = !{ !"int", !0 } 4386*9880d681SAndroid Build Coastguard Worker !2 = !{ !"float", !0 } 4387*9880d681SAndroid Build Coastguard Worker !3 = !{ !"const float", !2, i64 1 } 4388*9880d681SAndroid Build Coastguard Worker 4389*9880d681SAndroid Build Coastguard WorkerThe first field is an identity field. It can be any value, usually a 4390*9880d681SAndroid Build Coastguard Workermetadata string, which uniquely identifies the type. The most important 4391*9880d681SAndroid Build Coastguard Workername in the tree is the name of the root node. Two trees with different 4392*9880d681SAndroid Build Coastguard Workerroot node names are entirely disjoint, even if they have leaves with 4393*9880d681SAndroid Build Coastguard Workercommon names. 4394*9880d681SAndroid Build Coastguard Worker 4395*9880d681SAndroid Build Coastguard WorkerThe second field identifies the type's parent node in the tree, or is 4396*9880d681SAndroid Build Coastguard Workernull or omitted for a root node. A type is considered to alias all of 4397*9880d681SAndroid Build Coastguard Workerits descendants and all of its ancestors in the tree. Also, a type is 4398*9880d681SAndroid Build Coastguard Workerconsidered to alias all types in other trees, so that bitcode produced 4399*9880d681SAndroid Build Coastguard Workerfrom multiple front-ends is handled conservatively. 4400*9880d681SAndroid Build Coastguard Worker 4401*9880d681SAndroid Build Coastguard WorkerIf the third field is present, it's an integer which if equal to 1 4402*9880d681SAndroid Build Coastguard Workerindicates that the type is "constant" (meaning 4403*9880d681SAndroid Build Coastguard Worker``pointsToConstantMemory`` should return true; see `other useful 4404*9880d681SAndroid Build Coastguard WorkerAliasAnalysis methods <AliasAnalysis.html#OtherItfs>`_). 4405*9880d681SAndroid Build Coastguard Worker 4406*9880d681SAndroid Build Coastguard Worker'``tbaa.struct``' Metadata 4407*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^ 4408*9880d681SAndroid Build Coastguard Worker 4409*9880d681SAndroid Build Coastguard WorkerThe :ref:`llvm.memcpy <int_memcpy>` is often used to implement 4410*9880d681SAndroid Build Coastguard Workeraggregate assignment operations in C and similar languages, however it 4411*9880d681SAndroid Build Coastguard Workeris defined to copy a contiguous region of memory, which is more than 4412*9880d681SAndroid Build Coastguard Workerstrictly necessary for aggregate types which contain holes due to 4413*9880d681SAndroid Build Coastguard Workerpadding. Also, it doesn't contain any TBAA information about the fields 4414*9880d681SAndroid Build Coastguard Workerof the aggregate. 4415*9880d681SAndroid Build Coastguard Worker 4416*9880d681SAndroid Build Coastguard Worker``!tbaa.struct`` metadata can describe which memory subregions in a 4417*9880d681SAndroid Build Coastguard Workermemcpy are padding and what the TBAA tags of the struct are. 4418*9880d681SAndroid Build Coastguard Worker 4419*9880d681SAndroid Build Coastguard WorkerThe current metadata format is very simple. ``!tbaa.struct`` metadata 4420*9880d681SAndroid Build Coastguard Workernodes are a list of operands which are in conceptual groups of three. 4421*9880d681SAndroid Build Coastguard WorkerFor each group of three, the first operand gives the byte offset of a 4422*9880d681SAndroid Build Coastguard Workerfield in bytes, the second gives its size in bytes, and the third gives 4423*9880d681SAndroid Build Coastguard Workerits tbaa tag. e.g.: 4424*9880d681SAndroid Build Coastguard Worker 4425*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 4426*9880d681SAndroid Build Coastguard Worker 4427*9880d681SAndroid Build Coastguard Worker !4 = !{ i64 0, i64 4, !1, i64 8, i64 4, !2 } 4428*9880d681SAndroid Build Coastguard Worker 4429*9880d681SAndroid Build Coastguard WorkerThis describes a struct with two fields. The first is at offset 0 bytes 4430*9880d681SAndroid Build Coastguard Workerwith size 4 bytes, and has tbaa tag !1. The second is at offset 8 bytes 4431*9880d681SAndroid Build Coastguard Workerand has size 4 bytes and has tbaa tag !2. 4432*9880d681SAndroid Build Coastguard Worker 4433*9880d681SAndroid Build Coastguard WorkerNote that the fields need not be contiguous. In this example, there is a 4434*9880d681SAndroid Build Coastguard Worker4 byte gap between the two fields. This gap represents padding which 4435*9880d681SAndroid Build Coastguard Workerdoes not carry useful data and need not be preserved. 4436*9880d681SAndroid Build Coastguard Worker 4437*9880d681SAndroid Build Coastguard Worker'``noalias``' and '``alias.scope``' Metadata 4438*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 4439*9880d681SAndroid Build Coastguard Worker 4440*9880d681SAndroid Build Coastguard Worker``noalias`` and ``alias.scope`` metadata provide the ability to specify generic 4441*9880d681SAndroid Build Coastguard Workernoalias memory-access sets. This means that some collection of memory access 4442*9880d681SAndroid Build Coastguard Workerinstructions (loads, stores, memory-accessing calls, etc.) that carry 4443*9880d681SAndroid Build Coastguard Worker``noalias`` metadata can specifically be specified not to alias with some other 4444*9880d681SAndroid Build Coastguard Workercollection of memory access instructions that carry ``alias.scope`` metadata. 4445*9880d681SAndroid Build Coastguard WorkerEach type of metadata specifies a list of scopes where each scope has an id and 4446*9880d681SAndroid Build Coastguard Workera domain. 4447*9880d681SAndroid Build Coastguard Worker 4448*9880d681SAndroid Build Coastguard WorkerWhen evaluating an aliasing query, if for some domain, the set 4449*9880d681SAndroid Build Coastguard Workerof scopes with that domain in one instruction's ``alias.scope`` list is a 4450*9880d681SAndroid Build Coastguard Workersubset of (or equal to) the set of scopes for that domain in another 4451*9880d681SAndroid Build Coastguard Workerinstruction's ``noalias`` list, then the two memory accesses are assumed not to 4452*9880d681SAndroid Build Coastguard Workeralias. 4453*9880d681SAndroid Build Coastguard Worker 4454*9880d681SAndroid Build Coastguard WorkerBecause scopes in one domain don't affect scopes in other domains, separate 4455*9880d681SAndroid Build Coastguard Workerdomains can be used to compose multiple independent noalias sets. This is 4456*9880d681SAndroid Build Coastguard Workerused for example during inlining. As the noalias function parameters are 4457*9880d681SAndroid Build Coastguard Workerturned into noalias scope metadata, a new domain is used every time the 4458*9880d681SAndroid Build Coastguard Workerfunction is inlined. 4459*9880d681SAndroid Build Coastguard Worker 4460*9880d681SAndroid Build Coastguard WorkerThe metadata identifying each domain is itself a list containing one or two 4461*9880d681SAndroid Build Coastguard Workerentries. The first entry is the name of the domain. Note that if the name is a 4462*9880d681SAndroid Build Coastguard Workerstring then it can be combined across functions and translation units. A 4463*9880d681SAndroid Build Coastguard Workerself-reference can be used to create globally unique domain names. A 4464*9880d681SAndroid Build Coastguard Workerdescriptive string may optionally be provided as a second list entry. 4465*9880d681SAndroid Build Coastguard Worker 4466*9880d681SAndroid Build Coastguard WorkerThe metadata identifying each scope is also itself a list containing two or 4467*9880d681SAndroid Build Coastguard Workerthree entries. The first entry is the name of the scope. Note that if the name 4468*9880d681SAndroid Build Coastguard Workeris a string then it can be combined across functions and translation units. A 4469*9880d681SAndroid Build Coastguard Workerself-reference can be used to create globally unique scope names. A metadata 4470*9880d681SAndroid Build Coastguard Workerreference to the scope's domain is the second entry. A descriptive string may 4471*9880d681SAndroid Build Coastguard Workeroptionally be provided as a third list entry. 4472*9880d681SAndroid Build Coastguard Worker 4473*9880d681SAndroid Build Coastguard WorkerFor example, 4474*9880d681SAndroid Build Coastguard Worker 4475*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 4476*9880d681SAndroid Build Coastguard Worker 4477*9880d681SAndroid Build Coastguard Worker ; Two scope domains: 4478*9880d681SAndroid Build Coastguard Worker !0 = !{!0} 4479*9880d681SAndroid Build Coastguard Worker !1 = !{!1} 4480*9880d681SAndroid Build Coastguard Worker 4481*9880d681SAndroid Build Coastguard Worker ; Some scopes in these domains: 4482*9880d681SAndroid Build Coastguard Worker !2 = !{!2, !0} 4483*9880d681SAndroid Build Coastguard Worker !3 = !{!3, !0} 4484*9880d681SAndroid Build Coastguard Worker !4 = !{!4, !1} 4485*9880d681SAndroid Build Coastguard Worker 4486*9880d681SAndroid Build Coastguard Worker ; Some scope lists: 4487*9880d681SAndroid Build Coastguard Worker !5 = !{!4} ; A list containing only scope !4 4488*9880d681SAndroid Build Coastguard Worker !6 = !{!4, !3, !2} 4489*9880d681SAndroid Build Coastguard Worker !7 = !{!3} 4490*9880d681SAndroid Build Coastguard Worker 4491*9880d681SAndroid Build Coastguard Worker ; These two instructions don't alias: 4492*9880d681SAndroid Build Coastguard Worker %0 = load float, float* %c, align 4, !alias.scope !5 4493*9880d681SAndroid Build Coastguard Worker store float %0, float* %arrayidx.i, align 4, !noalias !5 4494*9880d681SAndroid Build Coastguard Worker 4495*9880d681SAndroid Build Coastguard Worker ; These two instructions also don't alias (for domain !1, the set of scopes 4496*9880d681SAndroid Build Coastguard Worker ; in the !alias.scope equals that in the !noalias list): 4497*9880d681SAndroid Build Coastguard Worker %2 = load float, float* %c, align 4, !alias.scope !5 4498*9880d681SAndroid Build Coastguard Worker store float %2, float* %arrayidx.i2, align 4, !noalias !6 4499*9880d681SAndroid Build Coastguard Worker 4500*9880d681SAndroid Build Coastguard Worker ; These two instructions may alias (for domain !0, the set of scopes in 4501*9880d681SAndroid Build Coastguard Worker ; the !noalias list is not a superset of, or equal to, the scopes in the 4502*9880d681SAndroid Build Coastguard Worker ; !alias.scope list): 4503*9880d681SAndroid Build Coastguard Worker %2 = load float, float* %c, align 4, !alias.scope !6 4504*9880d681SAndroid Build Coastguard Worker store float %0, float* %arrayidx.i, align 4, !noalias !7 4505*9880d681SAndroid Build Coastguard Worker 4506*9880d681SAndroid Build Coastguard Worker'``fpmath``' Metadata 4507*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^ 4508*9880d681SAndroid Build Coastguard Worker 4509*9880d681SAndroid Build Coastguard Worker``fpmath`` metadata may be attached to any instruction of floating point 4510*9880d681SAndroid Build Coastguard Workertype. It can be used to express the maximum acceptable error in the 4511*9880d681SAndroid Build Coastguard Workerresult of that instruction, in ULPs, thus potentially allowing the 4512*9880d681SAndroid Build Coastguard Workercompiler to use a more efficient but less accurate method of computing 4513*9880d681SAndroid Build Coastguard Workerit. ULP is defined as follows: 4514*9880d681SAndroid Build Coastguard Worker 4515*9880d681SAndroid Build Coastguard Worker If ``x`` is a real number that lies between two finite consecutive 4516*9880d681SAndroid Build Coastguard Worker floating-point numbers ``a`` and ``b``, without being equal to one 4517*9880d681SAndroid Build Coastguard Worker of them, then ``ulp(x) = |b - a|``, otherwise ``ulp(x)`` is the 4518*9880d681SAndroid Build Coastguard Worker distance between the two non-equal finite floating-point numbers 4519*9880d681SAndroid Build Coastguard Worker nearest ``x``. Moreover, ``ulp(NaN)`` is ``NaN``. 4520*9880d681SAndroid Build Coastguard Worker 4521*9880d681SAndroid Build Coastguard WorkerThe metadata node shall consist of a single positive float type number 4522*9880d681SAndroid Build Coastguard Workerrepresenting the maximum relative error, for example: 4523*9880d681SAndroid Build Coastguard Worker 4524*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 4525*9880d681SAndroid Build Coastguard Worker 4526*9880d681SAndroid Build Coastguard Worker !0 = !{ float 2.5 } ; maximum acceptable inaccuracy is 2.5 ULPs 4527*9880d681SAndroid Build Coastguard Worker 4528*9880d681SAndroid Build Coastguard Worker.. _range-metadata: 4529*9880d681SAndroid Build Coastguard Worker 4530*9880d681SAndroid Build Coastguard Worker'``range``' Metadata 4531*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^ 4532*9880d681SAndroid Build Coastguard Worker 4533*9880d681SAndroid Build Coastguard Worker``range`` metadata may be attached only to ``load``, ``call`` and ``invoke`` of 4534*9880d681SAndroid Build Coastguard Workerinteger types. It expresses the possible ranges the loaded value or the value 4535*9880d681SAndroid Build Coastguard Workerreturned by the called function at this call site is in. The ranges are 4536*9880d681SAndroid Build Coastguard Workerrepresented with a flattened list of integers. The loaded value or the value 4537*9880d681SAndroid Build Coastguard Workerreturned is known to be in the union of the ranges defined by each consecutive 4538*9880d681SAndroid Build Coastguard Workerpair. Each pair has the following properties: 4539*9880d681SAndroid Build Coastguard Worker 4540*9880d681SAndroid Build Coastguard Worker- The type must match the type loaded by the instruction. 4541*9880d681SAndroid Build Coastguard Worker- The pair ``a,b`` represents the range ``[a,b)``. 4542*9880d681SAndroid Build Coastguard Worker- Both ``a`` and ``b`` are constants. 4543*9880d681SAndroid Build Coastguard Worker- The range is allowed to wrap. 4544*9880d681SAndroid Build Coastguard Worker- The range should not represent the full or empty set. That is, 4545*9880d681SAndroid Build Coastguard Worker ``a!=b``. 4546*9880d681SAndroid Build Coastguard Worker 4547*9880d681SAndroid Build Coastguard WorkerIn addition, the pairs must be in signed order of the lower bound and 4548*9880d681SAndroid Build Coastguard Workerthey must be non-contiguous. 4549*9880d681SAndroid Build Coastguard Worker 4550*9880d681SAndroid Build Coastguard WorkerExamples: 4551*9880d681SAndroid Build Coastguard Worker 4552*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 4553*9880d681SAndroid Build Coastguard Worker 4554*9880d681SAndroid Build Coastguard Worker %a = load i8, i8* %x, align 1, !range !0 ; Can only be 0 or 1 4555*9880d681SAndroid Build Coastguard Worker %b = load i8, i8* %y, align 1, !range !1 ; Can only be 255 (-1), 0 or 1 4556*9880d681SAndroid Build Coastguard Worker %c = call i8 @foo(), !range !2 ; Can only be 0, 1, 3, 4 or 5 4557*9880d681SAndroid Build Coastguard Worker %d = invoke i8 @bar() to label %cont 4558*9880d681SAndroid Build Coastguard Worker unwind label %lpad, !range !3 ; Can only be -2, -1, 3, 4 or 5 4559*9880d681SAndroid Build Coastguard Worker ... 4560*9880d681SAndroid Build Coastguard Worker !0 = !{ i8 0, i8 2 } 4561*9880d681SAndroid Build Coastguard Worker !1 = !{ i8 255, i8 2 } 4562*9880d681SAndroid Build Coastguard Worker !2 = !{ i8 0, i8 2, i8 3, i8 6 } 4563*9880d681SAndroid Build Coastguard Worker !3 = !{ i8 -2, i8 0, i8 3, i8 6 } 4564*9880d681SAndroid Build Coastguard Worker 4565*9880d681SAndroid Build Coastguard Worker'``unpredictable``' Metadata 4566*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 4567*9880d681SAndroid Build Coastguard Worker 4568*9880d681SAndroid Build Coastguard Worker``unpredictable`` metadata may be attached to any branch or switch 4569*9880d681SAndroid Build Coastguard Workerinstruction. It can be used to express the unpredictability of control 4570*9880d681SAndroid Build Coastguard Workerflow. Similar to the llvm.expect intrinsic, it may be used to alter 4571*9880d681SAndroid Build Coastguard Workeroptimizations related to compare and branch instructions. The metadata 4572*9880d681SAndroid Build Coastguard Workeris treated as a boolean value; if it exists, it signals that the branch 4573*9880d681SAndroid Build Coastguard Workeror switch that it is attached to is completely unpredictable. 4574*9880d681SAndroid Build Coastguard Worker 4575*9880d681SAndroid Build Coastguard Worker'``llvm.loop``' 4576*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^ 4577*9880d681SAndroid Build Coastguard Worker 4578*9880d681SAndroid Build Coastguard WorkerIt is sometimes useful to attach information to loop constructs. Currently, 4579*9880d681SAndroid Build Coastguard Workerloop metadata is implemented as metadata attached to the branch instruction 4580*9880d681SAndroid Build Coastguard Workerin the loop latch block. This type of metadata refer to a metadata node that is 4581*9880d681SAndroid Build Coastguard Workerguaranteed to be separate for each loop. The loop identifier metadata is 4582*9880d681SAndroid Build Coastguard Workerspecified with the name ``llvm.loop``. 4583*9880d681SAndroid Build Coastguard Worker 4584*9880d681SAndroid Build Coastguard WorkerThe loop identifier metadata is implemented using a metadata that refers to 4585*9880d681SAndroid Build Coastguard Workeritself to avoid merging it with any other identifier metadata, e.g., 4586*9880d681SAndroid Build Coastguard Workerduring module linkage or function inlining. That is, each loop should refer 4587*9880d681SAndroid Build Coastguard Workerto their own identification metadata even if they reside in separate functions. 4588*9880d681SAndroid Build Coastguard WorkerThe following example contains loop identifier metadata for two separate loop 4589*9880d681SAndroid Build Coastguard Workerconstructs: 4590*9880d681SAndroid Build Coastguard Worker 4591*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 4592*9880d681SAndroid Build Coastguard Worker 4593*9880d681SAndroid Build Coastguard Worker !0 = !{!0} 4594*9880d681SAndroid Build Coastguard Worker !1 = !{!1} 4595*9880d681SAndroid Build Coastguard Worker 4596*9880d681SAndroid Build Coastguard WorkerThe loop identifier metadata can be used to specify additional 4597*9880d681SAndroid Build Coastguard Workerper-loop metadata. Any operands after the first operand can be treated 4598*9880d681SAndroid Build Coastguard Workeras user-defined metadata. For example the ``llvm.loop.unroll.count`` 4599*9880d681SAndroid Build Coastguard Workersuggests an unroll factor to the loop unroller: 4600*9880d681SAndroid Build Coastguard Worker 4601*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 4602*9880d681SAndroid Build Coastguard Worker 4603*9880d681SAndroid Build Coastguard Worker br i1 %exitcond, label %._crit_edge, label %.lr.ph, !llvm.loop !0 4604*9880d681SAndroid Build Coastguard Worker ... 4605*9880d681SAndroid Build Coastguard Worker !0 = !{!0, !1} 4606*9880d681SAndroid Build Coastguard Worker !1 = !{!"llvm.loop.unroll.count", i32 4} 4607*9880d681SAndroid Build Coastguard Worker 4608*9880d681SAndroid Build Coastguard Worker'``llvm.loop.vectorize``' and '``llvm.loop.interleave``' 4609*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 4610*9880d681SAndroid Build Coastguard Worker 4611*9880d681SAndroid Build Coastguard WorkerMetadata prefixed with ``llvm.loop.vectorize`` or ``llvm.loop.interleave`` are 4612*9880d681SAndroid Build Coastguard Workerused to control per-loop vectorization and interleaving parameters such as 4613*9880d681SAndroid Build Coastguard Workervectorization width and interleave count. These metadata should be used in 4614*9880d681SAndroid Build Coastguard Workerconjunction with ``llvm.loop`` loop identification metadata. The 4615*9880d681SAndroid Build Coastguard Worker``llvm.loop.vectorize`` and ``llvm.loop.interleave`` metadata are only 4616*9880d681SAndroid Build Coastguard Workeroptimization hints and the optimizer will only interleave and vectorize loops if 4617*9880d681SAndroid Build Coastguard Workerit believes it is safe to do so. The ``llvm.mem.parallel_loop_access`` metadata 4618*9880d681SAndroid Build Coastguard Workerwhich contains information about loop-carried memory dependencies can be helpful 4619*9880d681SAndroid Build Coastguard Workerin determining the safety of these transformations. 4620*9880d681SAndroid Build Coastguard Worker 4621*9880d681SAndroid Build Coastguard Worker'``llvm.loop.interleave.count``' Metadata 4622*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 4623*9880d681SAndroid Build Coastguard Worker 4624*9880d681SAndroid Build Coastguard WorkerThis metadata suggests an interleave count to the loop interleaver. 4625*9880d681SAndroid Build Coastguard WorkerThe first operand is the string ``llvm.loop.interleave.count`` and the 4626*9880d681SAndroid Build Coastguard Workersecond operand is an integer specifying the interleave count. For 4627*9880d681SAndroid Build Coastguard Workerexample: 4628*9880d681SAndroid Build Coastguard Worker 4629*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 4630*9880d681SAndroid Build Coastguard Worker 4631*9880d681SAndroid Build Coastguard Worker !0 = !{!"llvm.loop.interleave.count", i32 4} 4632*9880d681SAndroid Build Coastguard Worker 4633*9880d681SAndroid Build Coastguard WorkerNote that setting ``llvm.loop.interleave.count`` to 1 disables interleaving 4634*9880d681SAndroid Build Coastguard Workermultiple iterations of the loop. If ``llvm.loop.interleave.count`` is set to 0 4635*9880d681SAndroid Build Coastguard Workerthen the interleave count will be determined automatically. 4636*9880d681SAndroid Build Coastguard Worker 4637*9880d681SAndroid Build Coastguard Worker'``llvm.loop.vectorize.enable``' Metadata 4638*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 4639*9880d681SAndroid Build Coastguard Worker 4640*9880d681SAndroid Build Coastguard WorkerThis metadata selectively enables or disables vectorization for the loop. The 4641*9880d681SAndroid Build Coastguard Workerfirst operand is the string ``llvm.loop.vectorize.enable`` and the second operand 4642*9880d681SAndroid Build Coastguard Workeris a bit. If the bit operand value is 1 vectorization is enabled. A value of 4643*9880d681SAndroid Build Coastguard Worker0 disables vectorization: 4644*9880d681SAndroid Build Coastguard Worker 4645*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 4646*9880d681SAndroid Build Coastguard Worker 4647*9880d681SAndroid Build Coastguard Worker !0 = !{!"llvm.loop.vectorize.enable", i1 0} 4648*9880d681SAndroid Build Coastguard Worker !1 = !{!"llvm.loop.vectorize.enable", i1 1} 4649*9880d681SAndroid Build Coastguard Worker 4650*9880d681SAndroid Build Coastguard Worker'``llvm.loop.vectorize.width``' Metadata 4651*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 4652*9880d681SAndroid Build Coastguard Worker 4653*9880d681SAndroid Build Coastguard WorkerThis metadata sets the target width of the vectorizer. The first 4654*9880d681SAndroid Build Coastguard Workeroperand is the string ``llvm.loop.vectorize.width`` and the second 4655*9880d681SAndroid Build Coastguard Workeroperand is an integer specifying the width. For example: 4656*9880d681SAndroid Build Coastguard Worker 4657*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 4658*9880d681SAndroid Build Coastguard Worker 4659*9880d681SAndroid Build Coastguard Worker !0 = !{!"llvm.loop.vectorize.width", i32 4} 4660*9880d681SAndroid Build Coastguard Worker 4661*9880d681SAndroid Build Coastguard WorkerNote that setting ``llvm.loop.vectorize.width`` to 1 disables 4662*9880d681SAndroid Build Coastguard Workervectorization of the loop. If ``llvm.loop.vectorize.width`` is set to 4663*9880d681SAndroid Build Coastguard Worker0 or if the loop does not have this metadata the width will be 4664*9880d681SAndroid Build Coastguard Workerdetermined automatically. 4665*9880d681SAndroid Build Coastguard Worker 4666*9880d681SAndroid Build Coastguard Worker'``llvm.loop.unroll``' 4667*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^ 4668*9880d681SAndroid Build Coastguard Worker 4669*9880d681SAndroid Build Coastguard WorkerMetadata prefixed with ``llvm.loop.unroll`` are loop unrolling 4670*9880d681SAndroid Build Coastguard Workeroptimization hints such as the unroll factor. ``llvm.loop.unroll`` 4671*9880d681SAndroid Build Coastguard Workermetadata should be used in conjunction with ``llvm.loop`` loop 4672*9880d681SAndroid Build Coastguard Workeridentification metadata. The ``llvm.loop.unroll`` metadata are only 4673*9880d681SAndroid Build Coastguard Workeroptimization hints and the unrolling will only be performed if the 4674*9880d681SAndroid Build Coastguard Workeroptimizer believes it is safe to do so. 4675*9880d681SAndroid Build Coastguard Worker 4676*9880d681SAndroid Build Coastguard Worker'``llvm.loop.unroll.count``' Metadata 4677*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 4678*9880d681SAndroid Build Coastguard Worker 4679*9880d681SAndroid Build Coastguard WorkerThis metadata suggests an unroll factor to the loop unroller. The 4680*9880d681SAndroid Build Coastguard Workerfirst operand is the string ``llvm.loop.unroll.count`` and the second 4681*9880d681SAndroid Build Coastguard Workeroperand is a positive integer specifying the unroll factor. For 4682*9880d681SAndroid Build Coastguard Workerexample: 4683*9880d681SAndroid Build Coastguard Worker 4684*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 4685*9880d681SAndroid Build Coastguard Worker 4686*9880d681SAndroid Build Coastguard Worker !0 = !{!"llvm.loop.unroll.count", i32 4} 4687*9880d681SAndroid Build Coastguard Worker 4688*9880d681SAndroid Build Coastguard WorkerIf the trip count of the loop is less than the unroll count the loop 4689*9880d681SAndroid Build Coastguard Workerwill be partially unrolled. 4690*9880d681SAndroid Build Coastguard Worker 4691*9880d681SAndroid Build Coastguard Worker'``llvm.loop.unroll.disable``' Metadata 4692*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 4693*9880d681SAndroid Build Coastguard Worker 4694*9880d681SAndroid Build Coastguard WorkerThis metadata disables loop unrolling. The metadata has a single operand 4695*9880d681SAndroid Build Coastguard Workerwhich is the string ``llvm.loop.unroll.disable``. For example: 4696*9880d681SAndroid Build Coastguard Worker 4697*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 4698*9880d681SAndroid Build Coastguard Worker 4699*9880d681SAndroid Build Coastguard Worker !0 = !{!"llvm.loop.unroll.disable"} 4700*9880d681SAndroid Build Coastguard Worker 4701*9880d681SAndroid Build Coastguard Worker'``llvm.loop.unroll.runtime.disable``' Metadata 4702*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 4703*9880d681SAndroid Build Coastguard Worker 4704*9880d681SAndroid Build Coastguard WorkerThis metadata disables runtime loop unrolling. The metadata has a single 4705*9880d681SAndroid Build Coastguard Workeroperand which is the string ``llvm.loop.unroll.runtime.disable``. For example: 4706*9880d681SAndroid Build Coastguard Worker 4707*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 4708*9880d681SAndroid Build Coastguard Worker 4709*9880d681SAndroid Build Coastguard Worker !0 = !{!"llvm.loop.unroll.runtime.disable"} 4710*9880d681SAndroid Build Coastguard Worker 4711*9880d681SAndroid Build Coastguard Worker'``llvm.loop.unroll.enable``' Metadata 4712*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 4713*9880d681SAndroid Build Coastguard Worker 4714*9880d681SAndroid Build Coastguard WorkerThis metadata suggests that the loop should be fully unrolled if the trip count 4715*9880d681SAndroid Build Coastguard Workeris known at compile time and partially unrolled if the trip count is not known 4716*9880d681SAndroid Build Coastguard Workerat compile time. The metadata has a single operand which is the string 4717*9880d681SAndroid Build Coastguard Worker``llvm.loop.unroll.enable``. For example: 4718*9880d681SAndroid Build Coastguard Worker 4719*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 4720*9880d681SAndroid Build Coastguard Worker 4721*9880d681SAndroid Build Coastguard Worker !0 = !{!"llvm.loop.unroll.enable"} 4722*9880d681SAndroid Build Coastguard Worker 4723*9880d681SAndroid Build Coastguard Worker'``llvm.loop.unroll.full``' Metadata 4724*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 4725*9880d681SAndroid Build Coastguard Worker 4726*9880d681SAndroid Build Coastguard WorkerThis metadata suggests that the loop should be unrolled fully. The 4727*9880d681SAndroid Build Coastguard Workermetadata has a single operand which is the string ``llvm.loop.unroll.full``. 4728*9880d681SAndroid Build Coastguard WorkerFor example: 4729*9880d681SAndroid Build Coastguard Worker 4730*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 4731*9880d681SAndroid Build Coastguard Worker 4732*9880d681SAndroid Build Coastguard Worker !0 = !{!"llvm.loop.unroll.full"} 4733*9880d681SAndroid Build Coastguard Worker 4734*9880d681SAndroid Build Coastguard Worker'``llvm.loop.licm_versioning.disable``' Metadata 4735*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 4736*9880d681SAndroid Build Coastguard Worker 4737*9880d681SAndroid Build Coastguard WorkerThis metadata indicates that the loop should not be versioned for the purpose 4738*9880d681SAndroid Build Coastguard Workerof enabling loop-invariant code motion (LICM). The metadata has a single operand 4739*9880d681SAndroid Build Coastguard Workerwhich is the string ``llvm.loop.licm_versioning.disable``. For example: 4740*9880d681SAndroid Build Coastguard Worker 4741*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 4742*9880d681SAndroid Build Coastguard Worker 4743*9880d681SAndroid Build Coastguard Worker !0 = !{!"llvm.loop.licm_versioning.disable"} 4744*9880d681SAndroid Build Coastguard Worker 4745*9880d681SAndroid Build Coastguard Worker'``llvm.loop.distribute.enable``' Metadata 4746*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 4747*9880d681SAndroid Build Coastguard Worker 4748*9880d681SAndroid Build Coastguard WorkerLoop distribution allows splitting a loop into multiple loops. Currently, 4749*9880d681SAndroid Build Coastguard Workerthis is only performed if the entire loop cannot be vectorized due to unsafe 4750*9880d681SAndroid Build Coastguard Workermemory dependencies. The transformation will atempt to isolate the unsafe 4751*9880d681SAndroid Build Coastguard Workerdependencies into their own loop. 4752*9880d681SAndroid Build Coastguard Worker 4753*9880d681SAndroid Build Coastguard WorkerThis metadata can be used to selectively enable or disable distribution of the 4754*9880d681SAndroid Build Coastguard Workerloop. The first operand is the string ``llvm.loop.distribute.enable`` and the 4755*9880d681SAndroid Build Coastguard Workersecond operand is a bit. If the bit operand value is 1 distribution is 4756*9880d681SAndroid Build Coastguard Workerenabled. A value of 0 disables distribution: 4757*9880d681SAndroid Build Coastguard Worker 4758*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 4759*9880d681SAndroid Build Coastguard Worker 4760*9880d681SAndroid Build Coastguard Worker !0 = !{!"llvm.loop.distribute.enable", i1 0} 4761*9880d681SAndroid Build Coastguard Worker !1 = !{!"llvm.loop.distribute.enable", i1 1} 4762*9880d681SAndroid Build Coastguard Worker 4763*9880d681SAndroid Build Coastguard WorkerThis metadata should be used in conjunction with ``llvm.loop`` loop 4764*9880d681SAndroid Build Coastguard Workeridentification metadata. 4765*9880d681SAndroid Build Coastguard Worker 4766*9880d681SAndroid Build Coastguard Worker'``llvm.mem``' 4767*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^ 4768*9880d681SAndroid Build Coastguard Worker 4769*9880d681SAndroid Build Coastguard WorkerMetadata types used to annotate memory accesses with information helpful 4770*9880d681SAndroid Build Coastguard Workerfor optimizations are prefixed with ``llvm.mem``. 4771*9880d681SAndroid Build Coastguard Worker 4772*9880d681SAndroid Build Coastguard Worker'``llvm.mem.parallel_loop_access``' Metadata 4773*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 4774*9880d681SAndroid Build Coastguard Worker 4775*9880d681SAndroid Build Coastguard WorkerThe ``llvm.mem.parallel_loop_access`` metadata refers to a loop identifier, 4776*9880d681SAndroid Build Coastguard Workeror metadata containing a list of loop identifiers for nested loops. 4777*9880d681SAndroid Build Coastguard WorkerThe metadata is attached to memory accessing instructions and denotes that 4778*9880d681SAndroid Build Coastguard Workerno loop carried memory dependence exist between it and other instructions denoted 4779*9880d681SAndroid Build Coastguard Workerwith the same loop identifier. The metadata on memory reads also implies that 4780*9880d681SAndroid Build Coastguard Workerif conversion (i.e. speculative execution within a loop iteration) is safe. 4781*9880d681SAndroid Build Coastguard Worker 4782*9880d681SAndroid Build Coastguard WorkerPrecisely, given two instructions ``m1`` and ``m2`` that both have the 4783*9880d681SAndroid Build Coastguard Worker``llvm.mem.parallel_loop_access`` metadata, with ``L1`` and ``L2`` being the 4784*9880d681SAndroid Build Coastguard Workerset of loops associated with that metadata, respectively, then there is no loop 4785*9880d681SAndroid Build Coastguard Workercarried dependence between ``m1`` and ``m2`` for loops in both ``L1`` and 4786*9880d681SAndroid Build Coastguard Worker``L2``. 4787*9880d681SAndroid Build Coastguard Worker 4788*9880d681SAndroid Build Coastguard WorkerAs a special case, if all memory accessing instructions in a loop have 4789*9880d681SAndroid Build Coastguard Worker``llvm.mem.parallel_loop_access`` metadata that refers to that loop, then the 4790*9880d681SAndroid Build Coastguard Workerloop has no loop carried memory dependences and is considered to be a parallel 4791*9880d681SAndroid Build Coastguard Workerloop. 4792*9880d681SAndroid Build Coastguard Worker 4793*9880d681SAndroid Build Coastguard WorkerNote that if not all memory access instructions have such metadata referring to 4794*9880d681SAndroid Build Coastguard Workerthe loop, then the loop is considered not being trivially parallel. Additional 4795*9880d681SAndroid Build Coastguard Workermemory dependence analysis is required to make that determination. As a fail 4796*9880d681SAndroid Build Coastguard Workersafe mechanism, this causes loops that were originally parallel to be considered 4797*9880d681SAndroid Build Coastguard Workersequential (if optimization passes that are unaware of the parallel semantics 4798*9880d681SAndroid Build Coastguard Workerinsert new memory instructions into the loop body). 4799*9880d681SAndroid Build Coastguard Worker 4800*9880d681SAndroid Build Coastguard WorkerExample of a loop that is considered parallel due to its correct use of 4801*9880d681SAndroid Build Coastguard Workerboth ``llvm.loop`` and ``llvm.mem.parallel_loop_access`` 4802*9880d681SAndroid Build Coastguard Workermetadata types that refer to the same loop identifier metadata. 4803*9880d681SAndroid Build Coastguard Worker 4804*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 4805*9880d681SAndroid Build Coastguard Worker 4806*9880d681SAndroid Build Coastguard Worker for.body: 4807*9880d681SAndroid Build Coastguard Worker ... 4808*9880d681SAndroid Build Coastguard Worker %val0 = load i32, i32* %arrayidx, !llvm.mem.parallel_loop_access !0 4809*9880d681SAndroid Build Coastguard Worker ... 4810*9880d681SAndroid Build Coastguard Worker store i32 %val0, i32* %arrayidx1, !llvm.mem.parallel_loop_access !0 4811*9880d681SAndroid Build Coastguard Worker ... 4812*9880d681SAndroid Build Coastguard Worker br i1 %exitcond, label %for.end, label %for.body, !llvm.loop !0 4813*9880d681SAndroid Build Coastguard Worker 4814*9880d681SAndroid Build Coastguard Worker for.end: 4815*9880d681SAndroid Build Coastguard Worker ... 4816*9880d681SAndroid Build Coastguard Worker !0 = !{!0} 4817*9880d681SAndroid Build Coastguard Worker 4818*9880d681SAndroid Build Coastguard WorkerIt is also possible to have nested parallel loops. In that case the 4819*9880d681SAndroid Build Coastguard Workermemory accesses refer to a list of loop identifier metadata nodes instead of 4820*9880d681SAndroid Build Coastguard Workerthe loop identifier metadata node directly: 4821*9880d681SAndroid Build Coastguard Worker 4822*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 4823*9880d681SAndroid Build Coastguard Worker 4824*9880d681SAndroid Build Coastguard Worker outer.for.body: 4825*9880d681SAndroid Build Coastguard Worker ... 4826*9880d681SAndroid Build Coastguard Worker %val1 = load i32, i32* %arrayidx3, !llvm.mem.parallel_loop_access !2 4827*9880d681SAndroid Build Coastguard Worker ... 4828*9880d681SAndroid Build Coastguard Worker br label %inner.for.body 4829*9880d681SAndroid Build Coastguard Worker 4830*9880d681SAndroid Build Coastguard Worker inner.for.body: 4831*9880d681SAndroid Build Coastguard Worker ... 4832*9880d681SAndroid Build Coastguard Worker %val0 = load i32, i32* %arrayidx1, !llvm.mem.parallel_loop_access !0 4833*9880d681SAndroid Build Coastguard Worker ... 4834*9880d681SAndroid Build Coastguard Worker store i32 %val0, i32* %arrayidx2, !llvm.mem.parallel_loop_access !0 4835*9880d681SAndroid Build Coastguard Worker ... 4836*9880d681SAndroid Build Coastguard Worker br i1 %exitcond, label %inner.for.end, label %inner.for.body, !llvm.loop !1 4837*9880d681SAndroid Build Coastguard Worker 4838*9880d681SAndroid Build Coastguard Worker inner.for.end: 4839*9880d681SAndroid Build Coastguard Worker ... 4840*9880d681SAndroid Build Coastguard Worker store i32 %val1, i32* %arrayidx4, !llvm.mem.parallel_loop_access !2 4841*9880d681SAndroid Build Coastguard Worker ... 4842*9880d681SAndroid Build Coastguard Worker br i1 %exitcond, label %outer.for.end, label %outer.for.body, !llvm.loop !2 4843*9880d681SAndroid Build Coastguard Worker 4844*9880d681SAndroid Build Coastguard Worker outer.for.end: ; preds = %for.body 4845*9880d681SAndroid Build Coastguard Worker ... 4846*9880d681SAndroid Build Coastguard Worker !0 = !{!1, !2} ; a list of loop identifiers 4847*9880d681SAndroid Build Coastguard Worker !1 = !{!1} ; an identifier for the inner loop 4848*9880d681SAndroid Build Coastguard Worker !2 = !{!2} ; an identifier for the outer loop 4849*9880d681SAndroid Build Coastguard Worker 4850*9880d681SAndroid Build Coastguard Worker'``invariant.group``' Metadata 4851*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 4852*9880d681SAndroid Build Coastguard Worker 4853*9880d681SAndroid Build Coastguard WorkerThe ``invariant.group`` metadata may be attached to ``load``/``store`` instructions. 4854*9880d681SAndroid Build Coastguard WorkerThe existence of the ``invariant.group`` metadata on the instruction tells 4855*9880d681SAndroid Build Coastguard Workerthe optimizer that every ``load`` and ``store`` to the same pointer operand 4856*9880d681SAndroid Build Coastguard Workerwithin the same invariant group can be assumed to load or store the same 4857*9880d681SAndroid Build Coastguard Workervalue (but see the ``llvm.invariant.group.barrier`` intrinsic which affects 4858*9880d681SAndroid Build Coastguard Workerwhen two pointers are considered the same). 4859*9880d681SAndroid Build Coastguard Worker 4860*9880d681SAndroid Build Coastguard WorkerExamples: 4861*9880d681SAndroid Build Coastguard Worker 4862*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 4863*9880d681SAndroid Build Coastguard Worker 4864*9880d681SAndroid Build Coastguard Worker @unknownPtr = external global i8 4865*9880d681SAndroid Build Coastguard Worker ... 4866*9880d681SAndroid Build Coastguard Worker %ptr = alloca i8 4867*9880d681SAndroid Build Coastguard Worker store i8 42, i8* %ptr, !invariant.group !0 4868*9880d681SAndroid Build Coastguard Worker call void @foo(i8* %ptr) 4869*9880d681SAndroid Build Coastguard Worker 4870*9880d681SAndroid Build Coastguard Worker %a = load i8, i8* %ptr, !invariant.group !0 ; Can assume that value under %ptr didn't change 4871*9880d681SAndroid Build Coastguard Worker call void @foo(i8* %ptr) 4872*9880d681SAndroid Build Coastguard Worker %b = load i8, i8* %ptr, !invariant.group !1 ; Can't assume anything, because group changed 4873*9880d681SAndroid Build Coastguard Worker 4874*9880d681SAndroid Build Coastguard Worker %newPtr = call i8* @getPointer(i8* %ptr) 4875*9880d681SAndroid Build Coastguard Worker %c = load i8, i8* %newPtr, !invariant.group !0 ; Can't assume anything, because we only have information about %ptr 4876*9880d681SAndroid Build Coastguard Worker 4877*9880d681SAndroid Build Coastguard Worker %unknownValue = load i8, i8* @unknownPtr 4878*9880d681SAndroid Build Coastguard Worker store i8 %unknownValue, i8* %ptr, !invariant.group !0 ; Can assume that %unknownValue == 42 4879*9880d681SAndroid Build Coastguard Worker 4880*9880d681SAndroid Build Coastguard Worker call void @foo(i8* %ptr) 4881*9880d681SAndroid Build Coastguard Worker %newPtr2 = call i8* @llvm.invariant.group.barrier(i8* %ptr) 4882*9880d681SAndroid Build Coastguard Worker %d = load i8, i8* %newPtr2, !invariant.group !0 ; Can't step through invariant.group.barrier to get value of %ptr 4883*9880d681SAndroid Build Coastguard Worker 4884*9880d681SAndroid Build Coastguard Worker ... 4885*9880d681SAndroid Build Coastguard Worker declare void @foo(i8*) 4886*9880d681SAndroid Build Coastguard Worker declare i8* @getPointer(i8*) 4887*9880d681SAndroid Build Coastguard Worker declare i8* @llvm.invariant.group.barrier(i8*) 4888*9880d681SAndroid Build Coastguard Worker 4889*9880d681SAndroid Build Coastguard Worker !0 = !{!"magic ptr"} 4890*9880d681SAndroid Build Coastguard Worker !1 = !{!"other ptr"} 4891*9880d681SAndroid Build Coastguard Worker 4892*9880d681SAndroid Build Coastguard Worker 4893*9880d681SAndroid Build Coastguard Worker 4894*9880d681SAndroid Build Coastguard WorkerModule Flags Metadata 4895*9880d681SAndroid Build Coastguard Worker===================== 4896*9880d681SAndroid Build Coastguard Worker 4897*9880d681SAndroid Build Coastguard WorkerInformation about the module as a whole is difficult to convey to LLVM's 4898*9880d681SAndroid Build Coastguard Workersubsystems. The LLVM IR isn't sufficient to transmit this information. 4899*9880d681SAndroid Build Coastguard WorkerThe ``llvm.module.flags`` named metadata exists in order to facilitate 4900*9880d681SAndroid Build Coastguard Workerthis. These flags are in the form of key / value pairs --- much like a 4901*9880d681SAndroid Build Coastguard Workerdictionary --- making it easy for any subsystem who cares about a flag to 4902*9880d681SAndroid Build Coastguard Workerlook it up. 4903*9880d681SAndroid Build Coastguard Worker 4904*9880d681SAndroid Build Coastguard WorkerThe ``llvm.module.flags`` metadata contains a list of metadata triplets. 4905*9880d681SAndroid Build Coastguard WorkerEach triplet has the following form: 4906*9880d681SAndroid Build Coastguard Worker 4907*9880d681SAndroid Build Coastguard Worker- The first element is a *behavior* flag, which specifies the behavior 4908*9880d681SAndroid Build Coastguard Worker when two (or more) modules are merged together, and it encounters two 4909*9880d681SAndroid Build Coastguard Worker (or more) metadata with the same ID. The supported behaviors are 4910*9880d681SAndroid Build Coastguard Worker described below. 4911*9880d681SAndroid Build Coastguard Worker- The second element is a metadata string that is a unique ID for the 4912*9880d681SAndroid Build Coastguard Worker metadata. Each module may only have one flag entry for each unique ID (not 4913*9880d681SAndroid Build Coastguard Worker including entries with the **Require** behavior). 4914*9880d681SAndroid Build Coastguard Worker- The third element is the value of the flag. 4915*9880d681SAndroid Build Coastguard Worker 4916*9880d681SAndroid Build Coastguard WorkerWhen two (or more) modules are merged together, the resulting 4917*9880d681SAndroid Build Coastguard Worker``llvm.module.flags`` metadata is the union of the modules' flags. That is, for 4918*9880d681SAndroid Build Coastguard Workereach unique metadata ID string, there will be exactly one entry in the merged 4919*9880d681SAndroid Build Coastguard Workermodules ``llvm.module.flags`` metadata table, and the value for that entry will 4920*9880d681SAndroid Build Coastguard Workerbe determined by the merge behavior flag, as described below. The only exception 4921*9880d681SAndroid Build Coastguard Workeris that entries with the *Require* behavior are always preserved. 4922*9880d681SAndroid Build Coastguard Worker 4923*9880d681SAndroid Build Coastguard WorkerThe following behaviors are supported: 4924*9880d681SAndroid Build Coastguard Worker 4925*9880d681SAndroid Build Coastguard Worker.. list-table:: 4926*9880d681SAndroid Build Coastguard Worker :header-rows: 1 4927*9880d681SAndroid Build Coastguard Worker :widths: 10 90 4928*9880d681SAndroid Build Coastguard Worker 4929*9880d681SAndroid Build Coastguard Worker * - Value 4930*9880d681SAndroid Build Coastguard Worker - Behavior 4931*9880d681SAndroid Build Coastguard Worker 4932*9880d681SAndroid Build Coastguard Worker * - 1 4933*9880d681SAndroid Build Coastguard Worker - **Error** 4934*9880d681SAndroid Build Coastguard Worker Emits an error if two values disagree, otherwise the resulting value 4935*9880d681SAndroid Build Coastguard Worker is that of the operands. 4936*9880d681SAndroid Build Coastguard Worker 4937*9880d681SAndroid Build Coastguard Worker * - 2 4938*9880d681SAndroid Build Coastguard Worker - **Warning** 4939*9880d681SAndroid Build Coastguard Worker Emits a warning if two values disagree. The result value will be the 4940*9880d681SAndroid Build Coastguard Worker operand for the flag from the first module being linked. 4941*9880d681SAndroid Build Coastguard Worker 4942*9880d681SAndroid Build Coastguard Worker * - 3 4943*9880d681SAndroid Build Coastguard Worker - **Require** 4944*9880d681SAndroid Build Coastguard Worker Adds a requirement that another module flag be present and have a 4945*9880d681SAndroid Build Coastguard Worker specified value after linking is performed. The value must be a 4946*9880d681SAndroid Build Coastguard Worker metadata pair, where the first element of the pair is the ID of the 4947*9880d681SAndroid Build Coastguard Worker module flag to be restricted, and the second element of the pair is 4948*9880d681SAndroid Build Coastguard Worker the value the module flag should be restricted to. This behavior can 4949*9880d681SAndroid Build Coastguard Worker be used to restrict the allowable results (via triggering of an 4950*9880d681SAndroid Build Coastguard Worker error) of linking IDs with the **Override** behavior. 4951*9880d681SAndroid Build Coastguard Worker 4952*9880d681SAndroid Build Coastguard Worker * - 4 4953*9880d681SAndroid Build Coastguard Worker - **Override** 4954*9880d681SAndroid Build Coastguard Worker Uses the specified value, regardless of the behavior or value of the 4955*9880d681SAndroid Build Coastguard Worker other module. If both modules specify **Override**, but the values 4956*9880d681SAndroid Build Coastguard Worker differ, an error will be emitted. 4957*9880d681SAndroid Build Coastguard Worker 4958*9880d681SAndroid Build Coastguard Worker * - 5 4959*9880d681SAndroid Build Coastguard Worker - **Append** 4960*9880d681SAndroid Build Coastguard Worker Appends the two values, which are required to be metadata nodes. 4961*9880d681SAndroid Build Coastguard Worker 4962*9880d681SAndroid Build Coastguard Worker * - 6 4963*9880d681SAndroid Build Coastguard Worker - **AppendUnique** 4964*9880d681SAndroid Build Coastguard Worker Appends the two values, which are required to be metadata 4965*9880d681SAndroid Build Coastguard Worker nodes. However, duplicate entries in the second list are dropped 4966*9880d681SAndroid Build Coastguard Worker during the append operation. 4967*9880d681SAndroid Build Coastguard Worker 4968*9880d681SAndroid Build Coastguard WorkerIt is an error for a particular unique flag ID to have multiple behaviors, 4969*9880d681SAndroid Build Coastguard Workerexcept in the case of **Require** (which adds restrictions on another metadata 4970*9880d681SAndroid Build Coastguard Workervalue) or **Override**. 4971*9880d681SAndroid Build Coastguard Worker 4972*9880d681SAndroid Build Coastguard WorkerAn example of module flags: 4973*9880d681SAndroid Build Coastguard Worker 4974*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 4975*9880d681SAndroid Build Coastguard Worker 4976*9880d681SAndroid Build Coastguard Worker !0 = !{ i32 1, !"foo", i32 1 } 4977*9880d681SAndroid Build Coastguard Worker !1 = !{ i32 4, !"bar", i32 37 } 4978*9880d681SAndroid Build Coastguard Worker !2 = !{ i32 2, !"qux", i32 42 } 4979*9880d681SAndroid Build Coastguard Worker !3 = !{ i32 3, !"qux", 4980*9880d681SAndroid Build Coastguard Worker !{ 4981*9880d681SAndroid Build Coastguard Worker !"foo", i32 1 4982*9880d681SAndroid Build Coastguard Worker } 4983*9880d681SAndroid Build Coastguard Worker } 4984*9880d681SAndroid Build Coastguard Worker !llvm.module.flags = !{ !0, !1, !2, !3 } 4985*9880d681SAndroid Build Coastguard Worker 4986*9880d681SAndroid Build Coastguard Worker- Metadata ``!0`` has the ID ``!"foo"`` and the value '1'. The behavior 4987*9880d681SAndroid Build Coastguard Worker if two or more ``!"foo"`` flags are seen is to emit an error if their 4988*9880d681SAndroid Build Coastguard Worker values are not equal. 4989*9880d681SAndroid Build Coastguard Worker 4990*9880d681SAndroid Build Coastguard Worker- Metadata ``!1`` has the ID ``!"bar"`` and the value '37'. The 4991*9880d681SAndroid Build Coastguard Worker behavior if two or more ``!"bar"`` flags are seen is to use the value 4992*9880d681SAndroid Build Coastguard Worker '37'. 4993*9880d681SAndroid Build Coastguard Worker 4994*9880d681SAndroid Build Coastguard Worker- Metadata ``!2`` has the ID ``!"qux"`` and the value '42'. The 4995*9880d681SAndroid Build Coastguard Worker behavior if two or more ``!"qux"`` flags are seen is to emit a 4996*9880d681SAndroid Build Coastguard Worker warning if their values are not equal. 4997*9880d681SAndroid Build Coastguard Worker 4998*9880d681SAndroid Build Coastguard Worker- Metadata ``!3`` has the ID ``!"qux"`` and the value: 4999*9880d681SAndroid Build Coastguard Worker 5000*9880d681SAndroid Build Coastguard Worker :: 5001*9880d681SAndroid Build Coastguard Worker 5002*9880d681SAndroid Build Coastguard Worker !{ !"foo", i32 1 } 5003*9880d681SAndroid Build Coastguard Worker 5004*9880d681SAndroid Build Coastguard Worker The behavior is to emit an error if the ``llvm.module.flags`` does not 5005*9880d681SAndroid Build Coastguard Worker contain a flag with the ID ``!"foo"`` that has the value '1' after linking is 5006*9880d681SAndroid Build Coastguard Worker performed. 5007*9880d681SAndroid Build Coastguard Worker 5008*9880d681SAndroid Build Coastguard WorkerObjective-C Garbage Collection Module Flags Metadata 5009*9880d681SAndroid Build Coastguard Worker---------------------------------------------------- 5010*9880d681SAndroid Build Coastguard Worker 5011*9880d681SAndroid Build Coastguard WorkerOn the Mach-O platform, Objective-C stores metadata about garbage 5012*9880d681SAndroid Build Coastguard Workercollection in a special section called "image info". The metadata 5013*9880d681SAndroid Build Coastguard Workerconsists of a version number and a bitmask specifying what types of 5014*9880d681SAndroid Build Coastguard Workergarbage collection are supported (if any) by the file. If two or more 5015*9880d681SAndroid Build Coastguard Workermodules are linked together their garbage collection metadata needs to 5016*9880d681SAndroid Build Coastguard Workerbe merged rather than appended together. 5017*9880d681SAndroid Build Coastguard Worker 5018*9880d681SAndroid Build Coastguard WorkerThe Objective-C garbage collection module flags metadata consists of the 5019*9880d681SAndroid Build Coastguard Workerfollowing key-value pairs: 5020*9880d681SAndroid Build Coastguard Worker 5021*9880d681SAndroid Build Coastguard Worker.. list-table:: 5022*9880d681SAndroid Build Coastguard Worker :header-rows: 1 5023*9880d681SAndroid Build Coastguard Worker :widths: 30 70 5024*9880d681SAndroid Build Coastguard Worker 5025*9880d681SAndroid Build Coastguard Worker * - Key 5026*9880d681SAndroid Build Coastguard Worker - Value 5027*9880d681SAndroid Build Coastguard Worker 5028*9880d681SAndroid Build Coastguard Worker * - ``Objective-C Version`` 5029*9880d681SAndroid Build Coastguard Worker - **[Required]** --- The Objective-C ABI version. Valid values are 1 and 2. 5030*9880d681SAndroid Build Coastguard Worker 5031*9880d681SAndroid Build Coastguard Worker * - ``Objective-C Image Info Version`` 5032*9880d681SAndroid Build Coastguard Worker - **[Required]** --- The version of the image info section. Currently 5033*9880d681SAndroid Build Coastguard Worker always 0. 5034*9880d681SAndroid Build Coastguard Worker 5035*9880d681SAndroid Build Coastguard Worker * - ``Objective-C Image Info Section`` 5036*9880d681SAndroid Build Coastguard Worker - **[Required]** --- The section to place the metadata. Valid values are 5037*9880d681SAndroid Build Coastguard Worker ``"__OBJC, __image_info, regular"`` for Objective-C ABI version 1, and 5038*9880d681SAndroid Build Coastguard Worker ``"__DATA,__objc_imageinfo, regular, no_dead_strip"`` for 5039*9880d681SAndroid Build Coastguard Worker Objective-C ABI version 2. 5040*9880d681SAndroid Build Coastguard Worker 5041*9880d681SAndroid Build Coastguard Worker * - ``Objective-C Garbage Collection`` 5042*9880d681SAndroid Build Coastguard Worker - **[Required]** --- Specifies whether garbage collection is supported or 5043*9880d681SAndroid Build Coastguard Worker not. Valid values are 0, for no garbage collection, and 2, for garbage 5044*9880d681SAndroid Build Coastguard Worker collection supported. 5045*9880d681SAndroid Build Coastguard Worker 5046*9880d681SAndroid Build Coastguard Worker * - ``Objective-C GC Only`` 5047*9880d681SAndroid Build Coastguard Worker - **[Optional]** --- Specifies that only garbage collection is supported. 5048*9880d681SAndroid Build Coastguard Worker If present, its value must be 6. This flag requires that the 5049*9880d681SAndroid Build Coastguard Worker ``Objective-C Garbage Collection`` flag have the value 2. 5050*9880d681SAndroid Build Coastguard Worker 5051*9880d681SAndroid Build Coastguard WorkerSome important flag interactions: 5052*9880d681SAndroid Build Coastguard Worker 5053*9880d681SAndroid Build Coastguard Worker- If a module with ``Objective-C Garbage Collection`` set to 0 is 5054*9880d681SAndroid Build Coastguard Worker merged with a module with ``Objective-C Garbage Collection`` set to 5055*9880d681SAndroid Build Coastguard Worker 2, then the resulting module has the 5056*9880d681SAndroid Build Coastguard Worker ``Objective-C Garbage Collection`` flag set to 0. 5057*9880d681SAndroid Build Coastguard Worker- A module with ``Objective-C Garbage Collection`` set to 0 cannot be 5058*9880d681SAndroid Build Coastguard Worker merged with a module with ``Objective-C GC Only`` set to 6. 5059*9880d681SAndroid Build Coastguard Worker 5060*9880d681SAndroid Build Coastguard WorkerAutomatic Linker Flags Module Flags Metadata 5061*9880d681SAndroid Build Coastguard Worker-------------------------------------------- 5062*9880d681SAndroid Build Coastguard Worker 5063*9880d681SAndroid Build Coastguard WorkerSome targets support embedding flags to the linker inside individual object 5064*9880d681SAndroid Build Coastguard Workerfiles. Typically this is used in conjunction with language extensions which 5065*9880d681SAndroid Build Coastguard Workerallow source files to explicitly declare the libraries they depend on, and have 5066*9880d681SAndroid Build Coastguard Workerthese automatically be transmitted to the linker via object files. 5067*9880d681SAndroid Build Coastguard Worker 5068*9880d681SAndroid Build Coastguard WorkerThese flags are encoded in the IR using metadata in the module flags section, 5069*9880d681SAndroid Build Coastguard Workerusing the ``Linker Options`` key. The merge behavior for this flag is required 5070*9880d681SAndroid Build Coastguard Workerto be ``AppendUnique``, and the value for the key is expected to be a metadata 5071*9880d681SAndroid Build Coastguard Workernode which should be a list of other metadata nodes, each of which should be a 5072*9880d681SAndroid Build Coastguard Workerlist of metadata strings defining linker options. 5073*9880d681SAndroid Build Coastguard Worker 5074*9880d681SAndroid Build Coastguard WorkerFor example, the following metadata section specifies two separate sets of 5075*9880d681SAndroid Build Coastguard Workerlinker options, presumably to link against ``libz`` and the ``Cocoa`` 5076*9880d681SAndroid Build Coastguard Workerframework:: 5077*9880d681SAndroid Build Coastguard Worker 5078*9880d681SAndroid Build Coastguard Worker !0 = !{ i32 6, !"Linker Options", 5079*9880d681SAndroid Build Coastguard Worker !{ 5080*9880d681SAndroid Build Coastguard Worker !{ !"-lz" }, 5081*9880d681SAndroid Build Coastguard Worker !{ !"-framework", !"Cocoa" } } } 5082*9880d681SAndroid Build Coastguard Worker !llvm.module.flags = !{ !0 } 5083*9880d681SAndroid Build Coastguard Worker 5084*9880d681SAndroid Build Coastguard WorkerThe metadata encoding as lists of lists of options, as opposed to a collapsed 5085*9880d681SAndroid Build Coastguard Workerlist of options, is chosen so that the IR encoding can use multiple option 5086*9880d681SAndroid Build Coastguard Workerstrings to specify e.g., a single library, while still having that specifier be 5087*9880d681SAndroid Build Coastguard Workerpreserved as an atomic element that can be recognized by a target specific 5088*9880d681SAndroid Build Coastguard Workerassembly writer or object file emitter. 5089*9880d681SAndroid Build Coastguard Worker 5090*9880d681SAndroid Build Coastguard WorkerEach individual option is required to be either a valid option for the target's 5091*9880d681SAndroid Build Coastguard Workerlinker, or an option that is reserved by the target specific assembly writer or 5092*9880d681SAndroid Build Coastguard Workerobject file emitter. No other aspect of these options is defined by the IR. 5093*9880d681SAndroid Build Coastguard Worker 5094*9880d681SAndroid Build Coastguard WorkerC type width Module Flags Metadata 5095*9880d681SAndroid Build Coastguard Worker---------------------------------- 5096*9880d681SAndroid Build Coastguard Worker 5097*9880d681SAndroid Build Coastguard WorkerThe ARM backend emits a section into each generated object file describing the 5098*9880d681SAndroid Build Coastguard Workeroptions that it was compiled with (in a compiler-independent way) to prevent 5099*9880d681SAndroid Build Coastguard Workerlinking incompatible objects, and to allow automatic library selection. Some 5100*9880d681SAndroid Build Coastguard Workerof these options are not visible at the IR level, namely wchar_t width and enum 5101*9880d681SAndroid Build Coastguard Workerwidth. 5102*9880d681SAndroid Build Coastguard Worker 5103*9880d681SAndroid Build Coastguard WorkerTo pass this information to the backend, these options are encoded in module 5104*9880d681SAndroid Build Coastguard Workerflags metadata, using the following key-value pairs: 5105*9880d681SAndroid Build Coastguard Worker 5106*9880d681SAndroid Build Coastguard Worker.. list-table:: 5107*9880d681SAndroid Build Coastguard Worker :header-rows: 1 5108*9880d681SAndroid Build Coastguard Worker :widths: 30 70 5109*9880d681SAndroid Build Coastguard Worker 5110*9880d681SAndroid Build Coastguard Worker * - Key 5111*9880d681SAndroid Build Coastguard Worker - Value 5112*9880d681SAndroid Build Coastguard Worker 5113*9880d681SAndroid Build Coastguard Worker * - short_wchar 5114*9880d681SAndroid Build Coastguard Worker - * 0 --- sizeof(wchar_t) == 4 5115*9880d681SAndroid Build Coastguard Worker * 1 --- sizeof(wchar_t) == 2 5116*9880d681SAndroid Build Coastguard Worker 5117*9880d681SAndroid Build Coastguard Worker * - short_enum 5118*9880d681SAndroid Build Coastguard Worker - * 0 --- Enums are at least as large as an ``int``. 5119*9880d681SAndroid Build Coastguard Worker * 1 --- Enums are stored in the smallest integer type which can 5120*9880d681SAndroid Build Coastguard Worker represent all of its values. 5121*9880d681SAndroid Build Coastguard Worker 5122*9880d681SAndroid Build Coastguard WorkerFor example, the following metadata section specifies that the module was 5123*9880d681SAndroid Build Coastguard Workercompiled with a ``wchar_t`` width of 4 bytes, and the underlying type of an 5124*9880d681SAndroid Build Coastguard Workerenum is the smallest type which can represent all of its values:: 5125*9880d681SAndroid Build Coastguard Worker 5126*9880d681SAndroid Build Coastguard Worker !llvm.module.flags = !{!0, !1} 5127*9880d681SAndroid Build Coastguard Worker !0 = !{i32 1, !"short_wchar", i32 1} 5128*9880d681SAndroid Build Coastguard Worker !1 = !{i32 1, !"short_enum", i32 0} 5129*9880d681SAndroid Build Coastguard Worker 5130*9880d681SAndroid Build Coastguard Worker.. _intrinsicglobalvariables: 5131*9880d681SAndroid Build Coastguard Worker 5132*9880d681SAndroid Build Coastguard WorkerIntrinsic Global Variables 5133*9880d681SAndroid Build Coastguard Worker========================== 5134*9880d681SAndroid Build Coastguard Worker 5135*9880d681SAndroid Build Coastguard WorkerLLVM has a number of "magic" global variables that contain data that 5136*9880d681SAndroid Build Coastguard Workeraffect code generation or other IR semantics. These are documented here. 5137*9880d681SAndroid Build Coastguard WorkerAll globals of this sort should have a section specified as 5138*9880d681SAndroid Build Coastguard Worker"``llvm.metadata``". This section and all globals that start with 5139*9880d681SAndroid Build Coastguard Worker"``llvm.``" are reserved for use by LLVM. 5140*9880d681SAndroid Build Coastguard Worker 5141*9880d681SAndroid Build Coastguard Worker.. _gv_llvmused: 5142*9880d681SAndroid Build Coastguard Worker 5143*9880d681SAndroid Build Coastguard WorkerThe '``llvm.used``' Global Variable 5144*9880d681SAndroid Build Coastguard Worker----------------------------------- 5145*9880d681SAndroid Build Coastguard Worker 5146*9880d681SAndroid Build Coastguard WorkerThe ``@llvm.used`` global is an array which has 5147*9880d681SAndroid Build Coastguard Worker:ref:`appending linkage <linkage_appending>`. This array contains a list of 5148*9880d681SAndroid Build Coastguard Workerpointers to named global variables, functions and aliases which may optionally 5149*9880d681SAndroid Build Coastguard Workerhave a pointer cast formed of bitcast or getelementptr. For example, a legal 5150*9880d681SAndroid Build Coastguard Workeruse of it is: 5151*9880d681SAndroid Build Coastguard Worker 5152*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 5153*9880d681SAndroid Build Coastguard Worker 5154*9880d681SAndroid Build Coastguard Worker @X = global i8 4 5155*9880d681SAndroid Build Coastguard Worker @Y = global i32 123 5156*9880d681SAndroid Build Coastguard Worker 5157*9880d681SAndroid Build Coastguard Worker @llvm.used = appending global [2 x i8*] [ 5158*9880d681SAndroid Build Coastguard Worker i8* @X, 5159*9880d681SAndroid Build Coastguard Worker i8* bitcast (i32* @Y to i8*) 5160*9880d681SAndroid Build Coastguard Worker ], section "llvm.metadata" 5161*9880d681SAndroid Build Coastguard Worker 5162*9880d681SAndroid Build Coastguard WorkerIf a symbol appears in the ``@llvm.used`` list, then the compiler, assembler, 5163*9880d681SAndroid Build Coastguard Workerand linker are required to treat the symbol as if there is a reference to the 5164*9880d681SAndroid Build Coastguard Workersymbol that it cannot see (which is why they have to be named). For example, if 5165*9880d681SAndroid Build Coastguard Workera variable has internal linkage and no references other than that from the 5166*9880d681SAndroid Build Coastguard Worker``@llvm.used`` list, it cannot be deleted. This is commonly used to represent 5167*9880d681SAndroid Build Coastguard Workerreferences from inline asms and other things the compiler cannot "see", and 5168*9880d681SAndroid Build Coastguard Workercorresponds to "``attribute((used))``" in GNU C. 5169*9880d681SAndroid Build Coastguard Worker 5170*9880d681SAndroid Build Coastguard WorkerOn some targets, the code generator must emit a directive to the 5171*9880d681SAndroid Build Coastguard Workerassembler or object file to prevent the assembler and linker from 5172*9880d681SAndroid Build Coastguard Workermolesting the symbol. 5173*9880d681SAndroid Build Coastguard Worker 5174*9880d681SAndroid Build Coastguard Worker.. _gv_llvmcompilerused: 5175*9880d681SAndroid Build Coastguard Worker 5176*9880d681SAndroid Build Coastguard WorkerThe '``llvm.compiler.used``' Global Variable 5177*9880d681SAndroid Build Coastguard Worker-------------------------------------------- 5178*9880d681SAndroid Build Coastguard Worker 5179*9880d681SAndroid Build Coastguard WorkerThe ``@llvm.compiler.used`` directive is the same as the ``@llvm.used`` 5180*9880d681SAndroid Build Coastguard Workerdirective, except that it only prevents the compiler from touching the 5181*9880d681SAndroid Build Coastguard Workersymbol. On targets that support it, this allows an intelligent linker to 5182*9880d681SAndroid Build Coastguard Workeroptimize references to the symbol without being impeded as it would be 5183*9880d681SAndroid Build Coastguard Workerby ``@llvm.used``. 5184*9880d681SAndroid Build Coastguard Worker 5185*9880d681SAndroid Build Coastguard WorkerThis is a rare construct that should only be used in rare circumstances, 5186*9880d681SAndroid Build Coastguard Workerand should not be exposed to source languages. 5187*9880d681SAndroid Build Coastguard Worker 5188*9880d681SAndroid Build Coastguard Worker.. _gv_llvmglobalctors: 5189*9880d681SAndroid Build Coastguard Worker 5190*9880d681SAndroid Build Coastguard WorkerThe '``llvm.global_ctors``' Global Variable 5191*9880d681SAndroid Build Coastguard Worker------------------------------------------- 5192*9880d681SAndroid Build Coastguard Worker 5193*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 5194*9880d681SAndroid Build Coastguard Worker 5195*9880d681SAndroid Build Coastguard Worker %0 = type { i32, void ()*, i8* } 5196*9880d681SAndroid Build Coastguard Worker @llvm.global_ctors = appending global [1 x %0] [%0 { i32 65535, void ()* @ctor, i8* @data }] 5197*9880d681SAndroid Build Coastguard Worker 5198*9880d681SAndroid Build Coastguard WorkerThe ``@llvm.global_ctors`` array contains a list of constructor 5199*9880d681SAndroid Build Coastguard Workerfunctions, priorities, and an optional associated global or function. 5200*9880d681SAndroid Build Coastguard WorkerThe functions referenced by this array will be called in ascending order 5201*9880d681SAndroid Build Coastguard Workerof priority (i.e. lowest first) when the module is loaded. The order of 5202*9880d681SAndroid Build Coastguard Workerfunctions with the same priority is not defined. 5203*9880d681SAndroid Build Coastguard Worker 5204*9880d681SAndroid Build Coastguard WorkerIf the third field is present, non-null, and points to a global variable 5205*9880d681SAndroid Build Coastguard Workeror function, the initializer function will only run if the associated 5206*9880d681SAndroid Build Coastguard Workerdata from the current module is not discarded. 5207*9880d681SAndroid Build Coastguard Worker 5208*9880d681SAndroid Build Coastguard Worker.. _llvmglobaldtors: 5209*9880d681SAndroid Build Coastguard Worker 5210*9880d681SAndroid Build Coastguard WorkerThe '``llvm.global_dtors``' Global Variable 5211*9880d681SAndroid Build Coastguard Worker------------------------------------------- 5212*9880d681SAndroid Build Coastguard Worker 5213*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 5214*9880d681SAndroid Build Coastguard Worker 5215*9880d681SAndroid Build Coastguard Worker %0 = type { i32, void ()*, i8* } 5216*9880d681SAndroid Build Coastguard Worker @llvm.global_dtors = appending global [1 x %0] [%0 { i32 65535, void ()* @dtor, i8* @data }] 5217*9880d681SAndroid Build Coastguard Worker 5218*9880d681SAndroid Build Coastguard WorkerThe ``@llvm.global_dtors`` array contains a list of destructor 5219*9880d681SAndroid Build Coastguard Workerfunctions, priorities, and an optional associated global or function. 5220*9880d681SAndroid Build Coastguard WorkerThe functions referenced by this array will be called in descending 5221*9880d681SAndroid Build Coastguard Workerorder of priority (i.e. highest first) when the module is unloaded. The 5222*9880d681SAndroid Build Coastguard Workerorder of functions with the same priority is not defined. 5223*9880d681SAndroid Build Coastguard Worker 5224*9880d681SAndroid Build Coastguard WorkerIf the third field is present, non-null, and points to a global variable 5225*9880d681SAndroid Build Coastguard Workeror function, the destructor function will only run if the associated 5226*9880d681SAndroid Build Coastguard Workerdata from the current module is not discarded. 5227*9880d681SAndroid Build Coastguard Worker 5228*9880d681SAndroid Build Coastguard WorkerInstruction Reference 5229*9880d681SAndroid Build Coastguard Worker===================== 5230*9880d681SAndroid Build Coastguard Worker 5231*9880d681SAndroid Build Coastguard WorkerThe LLVM instruction set consists of several different classifications 5232*9880d681SAndroid Build Coastguard Workerof instructions: :ref:`terminator instructions <terminators>`, :ref:`binary 5233*9880d681SAndroid Build Coastguard Workerinstructions <binaryops>`, :ref:`bitwise binary 5234*9880d681SAndroid Build Coastguard Workerinstructions <bitwiseops>`, :ref:`memory instructions <memoryops>`, and 5235*9880d681SAndroid Build Coastguard Worker:ref:`other instructions <otherops>`. 5236*9880d681SAndroid Build Coastguard Worker 5237*9880d681SAndroid Build Coastguard Worker.. _terminators: 5238*9880d681SAndroid Build Coastguard Worker 5239*9880d681SAndroid Build Coastguard WorkerTerminator Instructions 5240*9880d681SAndroid Build Coastguard Worker----------------------- 5241*9880d681SAndroid Build Coastguard Worker 5242*9880d681SAndroid Build Coastguard WorkerAs mentioned :ref:`previously <functionstructure>`, every basic block in a 5243*9880d681SAndroid Build Coastguard Workerprogram ends with a "Terminator" instruction, which indicates which 5244*9880d681SAndroid Build Coastguard Workerblock should be executed after the current block is finished. These 5245*9880d681SAndroid Build Coastguard Workerterminator instructions typically yield a '``void``' value: they produce 5246*9880d681SAndroid Build Coastguard Workercontrol flow, not values (the one exception being the 5247*9880d681SAndroid Build Coastguard Worker':ref:`invoke <i_invoke>`' instruction). 5248*9880d681SAndroid Build Coastguard Worker 5249*9880d681SAndroid Build Coastguard WorkerThe terminator instructions are: ':ref:`ret <i_ret>`', 5250*9880d681SAndroid Build Coastguard Worker':ref:`br <i_br>`', ':ref:`switch <i_switch>`', 5251*9880d681SAndroid Build Coastguard Worker':ref:`indirectbr <i_indirectbr>`', ':ref:`invoke <i_invoke>`', 5252*9880d681SAndroid Build Coastguard Worker':ref:`resume <i_resume>`', ':ref:`catchswitch <i_catchswitch>`', 5253*9880d681SAndroid Build Coastguard Worker':ref:`catchret <i_catchret>`', 5254*9880d681SAndroid Build Coastguard Worker':ref:`cleanupret <i_cleanupret>`', 5255*9880d681SAndroid Build Coastguard Workerand ':ref:`unreachable <i_unreachable>`'. 5256*9880d681SAndroid Build Coastguard Worker 5257*9880d681SAndroid Build Coastguard Worker.. _i_ret: 5258*9880d681SAndroid Build Coastguard Worker 5259*9880d681SAndroid Build Coastguard Worker'``ret``' Instruction 5260*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^ 5261*9880d681SAndroid Build Coastguard Worker 5262*9880d681SAndroid Build Coastguard WorkerSyntax: 5263*9880d681SAndroid Build Coastguard Worker""""""" 5264*9880d681SAndroid Build Coastguard Worker 5265*9880d681SAndroid Build Coastguard Worker:: 5266*9880d681SAndroid Build Coastguard Worker 5267*9880d681SAndroid Build Coastguard Worker ret <type> <value> ; Return a value from a non-void function 5268*9880d681SAndroid Build Coastguard Worker ret void ; Return from void function 5269*9880d681SAndroid Build Coastguard Worker 5270*9880d681SAndroid Build Coastguard WorkerOverview: 5271*9880d681SAndroid Build Coastguard Worker""""""""" 5272*9880d681SAndroid Build Coastguard Worker 5273*9880d681SAndroid Build Coastguard WorkerThe '``ret``' instruction is used to return control flow (and optionally 5274*9880d681SAndroid Build Coastguard Workera value) from a function back to the caller. 5275*9880d681SAndroid Build Coastguard Worker 5276*9880d681SAndroid Build Coastguard WorkerThere are two forms of the '``ret``' instruction: one that returns a 5277*9880d681SAndroid Build Coastguard Workervalue and then causes control flow, and one that just causes control 5278*9880d681SAndroid Build Coastguard Workerflow to occur. 5279*9880d681SAndroid Build Coastguard Worker 5280*9880d681SAndroid Build Coastguard WorkerArguments: 5281*9880d681SAndroid Build Coastguard Worker"""""""""" 5282*9880d681SAndroid Build Coastguard Worker 5283*9880d681SAndroid Build Coastguard WorkerThe '``ret``' instruction optionally accepts a single argument, the 5284*9880d681SAndroid Build Coastguard Workerreturn value. The type of the return value must be a ':ref:`first 5285*9880d681SAndroid Build Coastguard Workerclass <t_firstclass>`' type. 5286*9880d681SAndroid Build Coastguard Worker 5287*9880d681SAndroid Build Coastguard WorkerA function is not :ref:`well formed <wellformed>` if it it has a non-void 5288*9880d681SAndroid Build Coastguard Workerreturn type and contains a '``ret``' instruction with no return value or 5289*9880d681SAndroid Build Coastguard Workera return value with a type that does not match its type, or if it has a 5290*9880d681SAndroid Build Coastguard Workervoid return type and contains a '``ret``' instruction with a return 5291*9880d681SAndroid Build Coastguard Workervalue. 5292*9880d681SAndroid Build Coastguard Worker 5293*9880d681SAndroid Build Coastguard WorkerSemantics: 5294*9880d681SAndroid Build Coastguard Worker"""""""""" 5295*9880d681SAndroid Build Coastguard Worker 5296*9880d681SAndroid Build Coastguard WorkerWhen the '``ret``' instruction is executed, control flow returns back to 5297*9880d681SAndroid Build Coastguard Workerthe calling function's context. If the caller is a 5298*9880d681SAndroid Build Coastguard Worker":ref:`call <i_call>`" instruction, execution continues at the 5299*9880d681SAndroid Build Coastguard Workerinstruction after the call. If the caller was an 5300*9880d681SAndroid Build Coastguard Worker":ref:`invoke <i_invoke>`" instruction, execution continues at the 5301*9880d681SAndroid Build Coastguard Workerbeginning of the "normal" destination block. If the instruction returns 5302*9880d681SAndroid Build Coastguard Workera value, that value shall set the call or invoke instruction's return 5303*9880d681SAndroid Build Coastguard Workervalue. 5304*9880d681SAndroid Build Coastguard Worker 5305*9880d681SAndroid Build Coastguard WorkerExample: 5306*9880d681SAndroid Build Coastguard Worker"""""""" 5307*9880d681SAndroid Build Coastguard Worker 5308*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 5309*9880d681SAndroid Build Coastguard Worker 5310*9880d681SAndroid Build Coastguard Worker ret i32 5 ; Return an integer value of 5 5311*9880d681SAndroid Build Coastguard Worker ret void ; Return from a void function 5312*9880d681SAndroid Build Coastguard Worker ret { i32, i8 } { i32 4, i8 2 } ; Return a struct of values 4 and 2 5313*9880d681SAndroid Build Coastguard Worker 5314*9880d681SAndroid Build Coastguard Worker.. _i_br: 5315*9880d681SAndroid Build Coastguard Worker 5316*9880d681SAndroid Build Coastguard Worker'``br``' Instruction 5317*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^ 5318*9880d681SAndroid Build Coastguard Worker 5319*9880d681SAndroid Build Coastguard WorkerSyntax: 5320*9880d681SAndroid Build Coastguard Worker""""""" 5321*9880d681SAndroid Build Coastguard Worker 5322*9880d681SAndroid Build Coastguard Worker:: 5323*9880d681SAndroid Build Coastguard Worker 5324*9880d681SAndroid Build Coastguard Worker br i1 <cond>, label <iftrue>, label <iffalse> 5325*9880d681SAndroid Build Coastguard Worker br label <dest> ; Unconditional branch 5326*9880d681SAndroid Build Coastguard Worker 5327*9880d681SAndroid Build Coastguard WorkerOverview: 5328*9880d681SAndroid Build Coastguard Worker""""""""" 5329*9880d681SAndroid Build Coastguard Worker 5330*9880d681SAndroid Build Coastguard WorkerThe '``br``' instruction is used to cause control flow to transfer to a 5331*9880d681SAndroid Build Coastguard Workerdifferent basic block in the current function. There are two forms of 5332*9880d681SAndroid Build Coastguard Workerthis instruction, corresponding to a conditional branch and an 5333*9880d681SAndroid Build Coastguard Workerunconditional branch. 5334*9880d681SAndroid Build Coastguard Worker 5335*9880d681SAndroid Build Coastguard WorkerArguments: 5336*9880d681SAndroid Build Coastguard Worker"""""""""" 5337*9880d681SAndroid Build Coastguard Worker 5338*9880d681SAndroid Build Coastguard WorkerThe conditional branch form of the '``br``' instruction takes a single 5339*9880d681SAndroid Build Coastguard Worker'``i1``' value and two '``label``' values. The unconditional form of the 5340*9880d681SAndroid Build Coastguard Worker'``br``' instruction takes a single '``label``' value as a target. 5341*9880d681SAndroid Build Coastguard Worker 5342*9880d681SAndroid Build Coastguard WorkerSemantics: 5343*9880d681SAndroid Build Coastguard Worker"""""""""" 5344*9880d681SAndroid Build Coastguard Worker 5345*9880d681SAndroid Build Coastguard WorkerUpon execution of a conditional '``br``' instruction, the '``i1``' 5346*9880d681SAndroid Build Coastguard Workerargument is evaluated. If the value is ``true``, control flows to the 5347*9880d681SAndroid Build Coastguard Worker'``iftrue``' ``label`` argument. If "cond" is ``false``, control flows 5348*9880d681SAndroid Build Coastguard Workerto the '``iffalse``' ``label`` argument. 5349*9880d681SAndroid Build Coastguard Worker 5350*9880d681SAndroid Build Coastguard WorkerExample: 5351*9880d681SAndroid Build Coastguard Worker"""""""" 5352*9880d681SAndroid Build Coastguard Worker 5353*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 5354*9880d681SAndroid Build Coastguard Worker 5355*9880d681SAndroid Build Coastguard Worker Test: 5356*9880d681SAndroid Build Coastguard Worker %cond = icmp eq i32 %a, %b 5357*9880d681SAndroid Build Coastguard Worker br i1 %cond, label %IfEqual, label %IfUnequal 5358*9880d681SAndroid Build Coastguard Worker IfEqual: 5359*9880d681SAndroid Build Coastguard Worker ret i32 1 5360*9880d681SAndroid Build Coastguard Worker IfUnequal: 5361*9880d681SAndroid Build Coastguard Worker ret i32 0 5362*9880d681SAndroid Build Coastguard Worker 5363*9880d681SAndroid Build Coastguard Worker.. _i_switch: 5364*9880d681SAndroid Build Coastguard Worker 5365*9880d681SAndroid Build Coastguard Worker'``switch``' Instruction 5366*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^ 5367*9880d681SAndroid Build Coastguard Worker 5368*9880d681SAndroid Build Coastguard WorkerSyntax: 5369*9880d681SAndroid Build Coastguard Worker""""""" 5370*9880d681SAndroid Build Coastguard Worker 5371*9880d681SAndroid Build Coastguard Worker:: 5372*9880d681SAndroid Build Coastguard Worker 5373*9880d681SAndroid Build Coastguard Worker switch <intty> <value>, label <defaultdest> [ <intty> <val>, label <dest> ... ] 5374*9880d681SAndroid Build Coastguard Worker 5375*9880d681SAndroid Build Coastguard WorkerOverview: 5376*9880d681SAndroid Build Coastguard Worker""""""""" 5377*9880d681SAndroid Build Coastguard Worker 5378*9880d681SAndroid Build Coastguard WorkerThe '``switch``' instruction is used to transfer control flow to one of 5379*9880d681SAndroid Build Coastguard Workerseveral different places. It is a generalization of the '``br``' 5380*9880d681SAndroid Build Coastguard Workerinstruction, allowing a branch to occur to one of many possible 5381*9880d681SAndroid Build Coastguard Workerdestinations. 5382*9880d681SAndroid Build Coastguard Worker 5383*9880d681SAndroid Build Coastguard WorkerArguments: 5384*9880d681SAndroid Build Coastguard Worker"""""""""" 5385*9880d681SAndroid Build Coastguard Worker 5386*9880d681SAndroid Build Coastguard WorkerThe '``switch``' instruction uses three parameters: an integer 5387*9880d681SAndroid Build Coastguard Workercomparison value '``value``', a default '``label``' destination, and an 5388*9880d681SAndroid Build Coastguard Workerarray of pairs of comparison value constants and '``label``'s. The table 5389*9880d681SAndroid Build Coastguard Workeris not allowed to contain duplicate constant entries. 5390*9880d681SAndroid Build Coastguard Worker 5391*9880d681SAndroid Build Coastguard WorkerSemantics: 5392*9880d681SAndroid Build Coastguard Worker"""""""""" 5393*9880d681SAndroid Build Coastguard Worker 5394*9880d681SAndroid Build Coastguard WorkerThe ``switch`` instruction specifies a table of values and destinations. 5395*9880d681SAndroid Build Coastguard WorkerWhen the '``switch``' instruction is executed, this table is searched 5396*9880d681SAndroid Build Coastguard Workerfor the given value. If the value is found, control flow is transferred 5397*9880d681SAndroid Build Coastguard Workerto the corresponding destination; otherwise, control flow is transferred 5398*9880d681SAndroid Build Coastguard Workerto the default destination. 5399*9880d681SAndroid Build Coastguard Worker 5400*9880d681SAndroid Build Coastguard WorkerImplementation: 5401*9880d681SAndroid Build Coastguard Worker""""""""""""""" 5402*9880d681SAndroid Build Coastguard Worker 5403*9880d681SAndroid Build Coastguard WorkerDepending on properties of the target machine and the particular 5404*9880d681SAndroid Build Coastguard Worker``switch`` instruction, this instruction may be code generated in 5405*9880d681SAndroid Build Coastguard Workerdifferent ways. For example, it could be generated as a series of 5406*9880d681SAndroid Build Coastguard Workerchained conditional branches or with a lookup table. 5407*9880d681SAndroid Build Coastguard Worker 5408*9880d681SAndroid Build Coastguard WorkerExample: 5409*9880d681SAndroid Build Coastguard Worker"""""""" 5410*9880d681SAndroid Build Coastguard Worker 5411*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 5412*9880d681SAndroid Build Coastguard Worker 5413*9880d681SAndroid Build Coastguard Worker ; Emulate a conditional br instruction 5414*9880d681SAndroid Build Coastguard Worker %Val = zext i1 %value to i32 5415*9880d681SAndroid Build Coastguard Worker switch i32 %Val, label %truedest [ i32 0, label %falsedest ] 5416*9880d681SAndroid Build Coastguard Worker 5417*9880d681SAndroid Build Coastguard Worker ; Emulate an unconditional br instruction 5418*9880d681SAndroid Build Coastguard Worker switch i32 0, label %dest [ ] 5419*9880d681SAndroid Build Coastguard Worker 5420*9880d681SAndroid Build Coastguard Worker ; Implement a jump table: 5421*9880d681SAndroid Build Coastguard Worker switch i32 %val, label %otherwise [ i32 0, label %onzero 5422*9880d681SAndroid Build Coastguard Worker i32 1, label %onone 5423*9880d681SAndroid Build Coastguard Worker i32 2, label %ontwo ] 5424*9880d681SAndroid Build Coastguard Worker 5425*9880d681SAndroid Build Coastguard Worker.. _i_indirectbr: 5426*9880d681SAndroid Build Coastguard Worker 5427*9880d681SAndroid Build Coastguard Worker'``indirectbr``' Instruction 5428*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 5429*9880d681SAndroid Build Coastguard Worker 5430*9880d681SAndroid Build Coastguard WorkerSyntax: 5431*9880d681SAndroid Build Coastguard Worker""""""" 5432*9880d681SAndroid Build Coastguard Worker 5433*9880d681SAndroid Build Coastguard Worker:: 5434*9880d681SAndroid Build Coastguard Worker 5435*9880d681SAndroid Build Coastguard Worker indirectbr <somety>* <address>, [ label <dest1>, label <dest2>, ... ] 5436*9880d681SAndroid Build Coastguard Worker 5437*9880d681SAndroid Build Coastguard WorkerOverview: 5438*9880d681SAndroid Build Coastguard Worker""""""""" 5439*9880d681SAndroid Build Coastguard Worker 5440*9880d681SAndroid Build Coastguard WorkerThe '``indirectbr``' instruction implements an indirect branch to a 5441*9880d681SAndroid Build Coastguard Workerlabel within the current function, whose address is specified by 5442*9880d681SAndroid Build Coastguard Worker"``address``". Address must be derived from a 5443*9880d681SAndroid Build Coastguard Worker:ref:`blockaddress <blockaddress>` constant. 5444*9880d681SAndroid Build Coastguard Worker 5445*9880d681SAndroid Build Coastguard WorkerArguments: 5446*9880d681SAndroid Build Coastguard Worker"""""""""" 5447*9880d681SAndroid Build Coastguard Worker 5448*9880d681SAndroid Build Coastguard WorkerThe '``address``' argument is the address of the label to jump to. The 5449*9880d681SAndroid Build Coastguard Workerrest of the arguments indicate the full set of possible destinations 5450*9880d681SAndroid Build Coastguard Workerthat the address may point to. Blocks are allowed to occur multiple 5451*9880d681SAndroid Build Coastguard Workertimes in the destination list, though this isn't particularly useful. 5452*9880d681SAndroid Build Coastguard Worker 5453*9880d681SAndroid Build Coastguard WorkerThis destination list is required so that dataflow analysis has an 5454*9880d681SAndroid Build Coastguard Workeraccurate understanding of the CFG. 5455*9880d681SAndroid Build Coastguard Worker 5456*9880d681SAndroid Build Coastguard WorkerSemantics: 5457*9880d681SAndroid Build Coastguard Worker"""""""""" 5458*9880d681SAndroid Build Coastguard Worker 5459*9880d681SAndroid Build Coastguard WorkerControl transfers to the block specified in the address argument. All 5460*9880d681SAndroid Build Coastguard Workerpossible destination blocks must be listed in the label list, otherwise 5461*9880d681SAndroid Build Coastguard Workerthis instruction has undefined behavior. This implies that jumps to 5462*9880d681SAndroid Build Coastguard Workerlabels defined in other functions have undefined behavior as well. 5463*9880d681SAndroid Build Coastguard Worker 5464*9880d681SAndroid Build Coastguard WorkerImplementation: 5465*9880d681SAndroid Build Coastguard Worker""""""""""""""" 5466*9880d681SAndroid Build Coastguard Worker 5467*9880d681SAndroid Build Coastguard WorkerThis is typically implemented with a jump through a register. 5468*9880d681SAndroid Build Coastguard Worker 5469*9880d681SAndroid Build Coastguard WorkerExample: 5470*9880d681SAndroid Build Coastguard Worker"""""""" 5471*9880d681SAndroid Build Coastguard Worker 5472*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 5473*9880d681SAndroid Build Coastguard Worker 5474*9880d681SAndroid Build Coastguard Worker indirectbr i8* %Addr, [ label %bb1, label %bb2, label %bb3 ] 5475*9880d681SAndroid Build Coastguard Worker 5476*9880d681SAndroid Build Coastguard Worker.. _i_invoke: 5477*9880d681SAndroid Build Coastguard Worker 5478*9880d681SAndroid Build Coastguard Worker'``invoke``' Instruction 5479*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^ 5480*9880d681SAndroid Build Coastguard Worker 5481*9880d681SAndroid Build Coastguard WorkerSyntax: 5482*9880d681SAndroid Build Coastguard Worker""""""" 5483*9880d681SAndroid Build Coastguard Worker 5484*9880d681SAndroid Build Coastguard Worker:: 5485*9880d681SAndroid Build Coastguard Worker 5486*9880d681SAndroid Build Coastguard Worker <result> = invoke [cconv] [ret attrs] <ty>|<fnty> <fnptrval>(<function args>) [fn attrs] 5487*9880d681SAndroid Build Coastguard Worker [operand bundles] to label <normal label> unwind label <exception label> 5488*9880d681SAndroid Build Coastguard Worker 5489*9880d681SAndroid Build Coastguard WorkerOverview: 5490*9880d681SAndroid Build Coastguard Worker""""""""" 5491*9880d681SAndroid Build Coastguard Worker 5492*9880d681SAndroid Build Coastguard WorkerThe '``invoke``' instruction causes control to transfer to a specified 5493*9880d681SAndroid Build Coastguard Workerfunction, with the possibility of control flow transfer to either the 5494*9880d681SAndroid Build Coastguard Worker'``normal``' label or the '``exception``' label. If the callee function 5495*9880d681SAndroid Build Coastguard Workerreturns with the "``ret``" instruction, control flow will return to the 5496*9880d681SAndroid Build Coastguard Worker"normal" label. If the callee (or any indirect callees) returns via the 5497*9880d681SAndroid Build Coastguard Worker":ref:`resume <i_resume>`" instruction or other exception handling 5498*9880d681SAndroid Build Coastguard Workermechanism, control is interrupted and continued at the dynamically 5499*9880d681SAndroid Build Coastguard Workernearest "exception" label. 5500*9880d681SAndroid Build Coastguard Worker 5501*9880d681SAndroid Build Coastguard WorkerThe '``exception``' label is a `landing 5502*9880d681SAndroid Build Coastguard Workerpad <ExceptionHandling.html#overview>`_ for the exception. As such, 5503*9880d681SAndroid Build Coastguard Worker'``exception``' label is required to have the 5504*9880d681SAndroid Build Coastguard Worker":ref:`landingpad <i_landingpad>`" instruction, which contains the 5505*9880d681SAndroid Build Coastguard Workerinformation about the behavior of the program after unwinding happens, 5506*9880d681SAndroid Build Coastguard Workeras its first non-PHI instruction. The restrictions on the 5507*9880d681SAndroid Build Coastguard Worker"``landingpad``" instruction's tightly couples it to the "``invoke``" 5508*9880d681SAndroid Build Coastguard Workerinstruction, so that the important information contained within the 5509*9880d681SAndroid Build Coastguard Worker"``landingpad``" instruction can't be lost through normal code motion. 5510*9880d681SAndroid Build Coastguard Worker 5511*9880d681SAndroid Build Coastguard WorkerArguments: 5512*9880d681SAndroid Build Coastguard Worker"""""""""" 5513*9880d681SAndroid Build Coastguard Worker 5514*9880d681SAndroid Build Coastguard WorkerThis instruction requires several arguments: 5515*9880d681SAndroid Build Coastguard Worker 5516*9880d681SAndroid Build Coastguard Worker#. The optional "cconv" marker indicates which :ref:`calling 5517*9880d681SAndroid Build Coastguard Worker convention <callingconv>` the call should use. If none is 5518*9880d681SAndroid Build Coastguard Worker specified, the call defaults to using C calling conventions. 5519*9880d681SAndroid Build Coastguard Worker#. The optional :ref:`Parameter Attributes <paramattrs>` list for return 5520*9880d681SAndroid Build Coastguard Worker values. Only '``zeroext``', '``signext``', and '``inreg``' attributes 5521*9880d681SAndroid Build Coastguard Worker are valid here. 5522*9880d681SAndroid Build Coastguard Worker#. '``ty``': the type of the call instruction itself which is also the 5523*9880d681SAndroid Build Coastguard Worker type of the return value. Functions that return no value are marked 5524*9880d681SAndroid Build Coastguard Worker ``void``. 5525*9880d681SAndroid Build Coastguard Worker#. '``fnty``': shall be the signature of the function being invoked. The 5526*9880d681SAndroid Build Coastguard Worker argument types must match the types implied by this signature. This 5527*9880d681SAndroid Build Coastguard Worker type can be omitted if the function is not varargs. 5528*9880d681SAndroid Build Coastguard Worker#. '``fnptrval``': An LLVM value containing a pointer to a function to 5529*9880d681SAndroid Build Coastguard Worker be invoked. In most cases, this is a direct function invocation, but 5530*9880d681SAndroid Build Coastguard Worker indirect ``invoke``'s are just as possible, calling an arbitrary pointer 5531*9880d681SAndroid Build Coastguard Worker to function value. 5532*9880d681SAndroid Build Coastguard Worker#. '``function args``': argument list whose types match the function 5533*9880d681SAndroid Build Coastguard Worker signature argument types and parameter attributes. All arguments must 5534*9880d681SAndroid Build Coastguard Worker be of :ref:`first class <t_firstclass>` type. If the function signature 5535*9880d681SAndroid Build Coastguard Worker indicates the function accepts a variable number of arguments, the 5536*9880d681SAndroid Build Coastguard Worker extra arguments can be specified. 5537*9880d681SAndroid Build Coastguard Worker#. '``normal label``': the label reached when the called function 5538*9880d681SAndroid Build Coastguard Worker executes a '``ret``' instruction. 5539*9880d681SAndroid Build Coastguard Worker#. '``exception label``': the label reached when a callee returns via 5540*9880d681SAndroid Build Coastguard Worker the :ref:`resume <i_resume>` instruction or other exception handling 5541*9880d681SAndroid Build Coastguard Worker mechanism. 5542*9880d681SAndroid Build Coastguard Worker#. The optional :ref:`function attributes <fnattrs>` list. Only 5543*9880d681SAndroid Build Coastguard Worker '``noreturn``', '``nounwind``', '``readonly``' and '``readnone``' 5544*9880d681SAndroid Build Coastguard Worker attributes are valid here. 5545*9880d681SAndroid Build Coastguard Worker#. The optional :ref:`operand bundles <opbundles>` list. 5546*9880d681SAndroid Build Coastguard Worker 5547*9880d681SAndroid Build Coastguard WorkerSemantics: 5548*9880d681SAndroid Build Coastguard Worker"""""""""" 5549*9880d681SAndroid Build Coastguard Worker 5550*9880d681SAndroid Build Coastguard WorkerThis instruction is designed to operate as a standard '``call``' 5551*9880d681SAndroid Build Coastguard Workerinstruction in most regards. The primary difference is that it 5552*9880d681SAndroid Build Coastguard Workerestablishes an association with a label, which is used by the runtime 5553*9880d681SAndroid Build Coastguard Workerlibrary to unwind the stack. 5554*9880d681SAndroid Build Coastguard Worker 5555*9880d681SAndroid Build Coastguard WorkerThis instruction is used in languages with destructors to ensure that 5556*9880d681SAndroid Build Coastguard Workerproper cleanup is performed in the case of either a ``longjmp`` or a 5557*9880d681SAndroid Build Coastguard Workerthrown exception. Additionally, this is important for implementation of 5558*9880d681SAndroid Build Coastguard Worker'``catch``' clauses in high-level languages that support them. 5559*9880d681SAndroid Build Coastguard Worker 5560*9880d681SAndroid Build Coastguard WorkerFor the purposes of the SSA form, the definition of the value returned 5561*9880d681SAndroid Build Coastguard Workerby the '``invoke``' instruction is deemed to occur on the edge from the 5562*9880d681SAndroid Build Coastguard Workercurrent block to the "normal" label. If the callee unwinds then no 5563*9880d681SAndroid Build Coastguard Workerreturn value is available. 5564*9880d681SAndroid Build Coastguard Worker 5565*9880d681SAndroid Build Coastguard WorkerExample: 5566*9880d681SAndroid Build Coastguard Worker"""""""" 5567*9880d681SAndroid Build Coastguard Worker 5568*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 5569*9880d681SAndroid Build Coastguard Worker 5570*9880d681SAndroid Build Coastguard Worker %retval = invoke i32 @Test(i32 15) to label %Continue 5571*9880d681SAndroid Build Coastguard Worker unwind label %TestCleanup ; i32:retval set 5572*9880d681SAndroid Build Coastguard Worker %retval = invoke coldcc i32 %Testfnptr(i32 15) to label %Continue 5573*9880d681SAndroid Build Coastguard Worker unwind label %TestCleanup ; i32:retval set 5574*9880d681SAndroid Build Coastguard Worker 5575*9880d681SAndroid Build Coastguard Worker.. _i_resume: 5576*9880d681SAndroid Build Coastguard Worker 5577*9880d681SAndroid Build Coastguard Worker'``resume``' Instruction 5578*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^ 5579*9880d681SAndroid Build Coastguard Worker 5580*9880d681SAndroid Build Coastguard WorkerSyntax: 5581*9880d681SAndroid Build Coastguard Worker""""""" 5582*9880d681SAndroid Build Coastguard Worker 5583*9880d681SAndroid Build Coastguard Worker:: 5584*9880d681SAndroid Build Coastguard Worker 5585*9880d681SAndroid Build Coastguard Worker resume <type> <value> 5586*9880d681SAndroid Build Coastguard Worker 5587*9880d681SAndroid Build Coastguard WorkerOverview: 5588*9880d681SAndroid Build Coastguard Worker""""""""" 5589*9880d681SAndroid Build Coastguard Worker 5590*9880d681SAndroid Build Coastguard WorkerThe '``resume``' instruction is a terminator instruction that has no 5591*9880d681SAndroid Build Coastguard Workersuccessors. 5592*9880d681SAndroid Build Coastguard Worker 5593*9880d681SAndroid Build Coastguard WorkerArguments: 5594*9880d681SAndroid Build Coastguard Worker"""""""""" 5595*9880d681SAndroid Build Coastguard Worker 5596*9880d681SAndroid Build Coastguard WorkerThe '``resume``' instruction requires one argument, which must have the 5597*9880d681SAndroid Build Coastguard Workersame type as the result of any '``landingpad``' instruction in the same 5598*9880d681SAndroid Build Coastguard Workerfunction. 5599*9880d681SAndroid Build Coastguard Worker 5600*9880d681SAndroid Build Coastguard WorkerSemantics: 5601*9880d681SAndroid Build Coastguard Worker"""""""""" 5602*9880d681SAndroid Build Coastguard Worker 5603*9880d681SAndroid Build Coastguard WorkerThe '``resume``' instruction resumes propagation of an existing 5604*9880d681SAndroid Build Coastguard Worker(in-flight) exception whose unwinding was interrupted with a 5605*9880d681SAndroid Build Coastguard Worker:ref:`landingpad <i_landingpad>` instruction. 5606*9880d681SAndroid Build Coastguard Worker 5607*9880d681SAndroid Build Coastguard WorkerExample: 5608*9880d681SAndroid Build Coastguard Worker"""""""" 5609*9880d681SAndroid Build Coastguard Worker 5610*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 5611*9880d681SAndroid Build Coastguard Worker 5612*9880d681SAndroid Build Coastguard Worker resume { i8*, i32 } %exn 5613*9880d681SAndroid Build Coastguard Worker 5614*9880d681SAndroid Build Coastguard Worker.. _i_catchswitch: 5615*9880d681SAndroid Build Coastguard Worker 5616*9880d681SAndroid Build Coastguard Worker'``catchswitch``' Instruction 5617*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 5618*9880d681SAndroid Build Coastguard Worker 5619*9880d681SAndroid Build Coastguard WorkerSyntax: 5620*9880d681SAndroid Build Coastguard Worker""""""" 5621*9880d681SAndroid Build Coastguard Worker 5622*9880d681SAndroid Build Coastguard Worker:: 5623*9880d681SAndroid Build Coastguard Worker 5624*9880d681SAndroid Build Coastguard Worker <resultval> = catchswitch within <parent> [ label <handler1>, label <handler2>, ... ] unwind to caller 5625*9880d681SAndroid Build Coastguard Worker <resultval> = catchswitch within <parent> [ label <handler1>, label <handler2>, ... ] unwind label <default> 5626*9880d681SAndroid Build Coastguard Worker 5627*9880d681SAndroid Build Coastguard WorkerOverview: 5628*9880d681SAndroid Build Coastguard Worker""""""""" 5629*9880d681SAndroid Build Coastguard Worker 5630*9880d681SAndroid Build Coastguard WorkerThe '``catchswitch``' instruction is used by `LLVM's exception handling system 5631*9880d681SAndroid Build Coastguard Worker<ExceptionHandling.html#overview>`_ to describe the set of possible catch handlers 5632*9880d681SAndroid Build Coastguard Workerthat may be executed by the :ref:`EH personality routine <personalityfn>`. 5633*9880d681SAndroid Build Coastguard Worker 5634*9880d681SAndroid Build Coastguard WorkerArguments: 5635*9880d681SAndroid Build Coastguard Worker"""""""""" 5636*9880d681SAndroid Build Coastguard Worker 5637*9880d681SAndroid Build Coastguard WorkerThe ``parent`` argument is the token of the funclet that contains the 5638*9880d681SAndroid Build Coastguard Worker``catchswitch`` instruction. If the ``catchswitch`` is not inside a funclet, 5639*9880d681SAndroid Build Coastguard Workerthis operand may be the token ``none``. 5640*9880d681SAndroid Build Coastguard Worker 5641*9880d681SAndroid Build Coastguard WorkerThe ``default`` argument is the label of another basic block beginning with 5642*9880d681SAndroid Build Coastguard Workereither a ``cleanuppad`` or ``catchswitch`` instruction. This unwind destination 5643*9880d681SAndroid Build Coastguard Workermust be a legal target with respect to the ``parent`` links, as described in 5644*9880d681SAndroid Build Coastguard Workerthe `exception handling documentation\ <ExceptionHandling.html#wineh-constraints>`_. 5645*9880d681SAndroid Build Coastguard Worker 5646*9880d681SAndroid Build Coastguard WorkerThe ``handlers`` are a nonempty list of successor blocks that each begin with a 5647*9880d681SAndroid Build Coastguard Worker:ref:`catchpad <i_catchpad>` instruction. 5648*9880d681SAndroid Build Coastguard Worker 5649*9880d681SAndroid Build Coastguard WorkerSemantics: 5650*9880d681SAndroid Build Coastguard Worker"""""""""" 5651*9880d681SAndroid Build Coastguard Worker 5652*9880d681SAndroid Build Coastguard WorkerExecuting this instruction transfers control to one of the successors in 5653*9880d681SAndroid Build Coastguard Worker``handlers``, if appropriate, or continues to unwind via the unwind label if 5654*9880d681SAndroid Build Coastguard Workerpresent. 5655*9880d681SAndroid Build Coastguard Worker 5656*9880d681SAndroid Build Coastguard WorkerThe ``catchswitch`` is both a terminator and a "pad" instruction, meaning that 5657*9880d681SAndroid Build Coastguard Workerit must be both the first non-phi instruction and last instruction in the basic 5658*9880d681SAndroid Build Coastguard Workerblock. Therefore, it must be the only non-phi instruction in the block. 5659*9880d681SAndroid Build Coastguard Worker 5660*9880d681SAndroid Build Coastguard WorkerExample: 5661*9880d681SAndroid Build Coastguard Worker"""""""" 5662*9880d681SAndroid Build Coastguard Worker 5663*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 5664*9880d681SAndroid Build Coastguard Worker 5665*9880d681SAndroid Build Coastguard Worker dispatch1: 5666*9880d681SAndroid Build Coastguard Worker %cs1 = catchswitch within none [label %handler0, label %handler1] unwind to caller 5667*9880d681SAndroid Build Coastguard Worker dispatch2: 5668*9880d681SAndroid Build Coastguard Worker %cs2 = catchswitch within %parenthandler [label %handler0] unwind label %cleanup 5669*9880d681SAndroid Build Coastguard Worker 5670*9880d681SAndroid Build Coastguard Worker.. _i_catchret: 5671*9880d681SAndroid Build Coastguard Worker 5672*9880d681SAndroid Build Coastguard Worker'``catchret``' Instruction 5673*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^ 5674*9880d681SAndroid Build Coastguard Worker 5675*9880d681SAndroid Build Coastguard WorkerSyntax: 5676*9880d681SAndroid Build Coastguard Worker""""""" 5677*9880d681SAndroid Build Coastguard Worker 5678*9880d681SAndroid Build Coastguard Worker:: 5679*9880d681SAndroid Build Coastguard Worker 5680*9880d681SAndroid Build Coastguard Worker catchret from <token> to label <normal> 5681*9880d681SAndroid Build Coastguard Worker 5682*9880d681SAndroid Build Coastguard WorkerOverview: 5683*9880d681SAndroid Build Coastguard Worker""""""""" 5684*9880d681SAndroid Build Coastguard Worker 5685*9880d681SAndroid Build Coastguard WorkerThe '``catchret``' instruction is a terminator instruction that has a 5686*9880d681SAndroid Build Coastguard Workersingle successor. 5687*9880d681SAndroid Build Coastguard Worker 5688*9880d681SAndroid Build Coastguard Worker 5689*9880d681SAndroid Build Coastguard WorkerArguments: 5690*9880d681SAndroid Build Coastguard Worker"""""""""" 5691*9880d681SAndroid Build Coastguard Worker 5692*9880d681SAndroid Build Coastguard WorkerThe first argument to a '``catchret``' indicates which ``catchpad`` it 5693*9880d681SAndroid Build Coastguard Workerexits. It must be a :ref:`catchpad <i_catchpad>`. 5694*9880d681SAndroid Build Coastguard WorkerThe second argument to a '``catchret``' specifies where control will 5695*9880d681SAndroid Build Coastguard Workertransfer to next. 5696*9880d681SAndroid Build Coastguard Worker 5697*9880d681SAndroid Build Coastguard WorkerSemantics: 5698*9880d681SAndroid Build Coastguard Worker"""""""""" 5699*9880d681SAndroid Build Coastguard Worker 5700*9880d681SAndroid Build Coastguard WorkerThe '``catchret``' instruction ends an existing (in-flight) exception whose 5701*9880d681SAndroid Build Coastguard Workerunwinding was interrupted with a :ref:`catchpad <i_catchpad>` instruction. The 5702*9880d681SAndroid Build Coastguard Worker:ref:`personality function <personalityfn>` gets a chance to execute arbitrary 5703*9880d681SAndroid Build Coastguard Workercode to, for example, destroy the active exception. Control then transfers to 5704*9880d681SAndroid Build Coastguard Worker``normal``. 5705*9880d681SAndroid Build Coastguard Worker 5706*9880d681SAndroid Build Coastguard WorkerThe ``token`` argument must be a token produced by a ``catchpad`` instruction. 5707*9880d681SAndroid Build Coastguard WorkerIf the specified ``catchpad`` is not the most-recently-entered not-yet-exited 5708*9880d681SAndroid Build Coastguard Workerfunclet pad (as described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_), 5709*9880d681SAndroid Build Coastguard Workerthe ``catchret``'s behavior is undefined. 5710*9880d681SAndroid Build Coastguard Worker 5711*9880d681SAndroid Build Coastguard WorkerExample: 5712*9880d681SAndroid Build Coastguard Worker"""""""" 5713*9880d681SAndroid Build Coastguard Worker 5714*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 5715*9880d681SAndroid Build Coastguard Worker 5716*9880d681SAndroid Build Coastguard Worker catchret from %catch label %continue 5717*9880d681SAndroid Build Coastguard Worker 5718*9880d681SAndroid Build Coastguard Worker.. _i_cleanupret: 5719*9880d681SAndroid Build Coastguard Worker 5720*9880d681SAndroid Build Coastguard Worker'``cleanupret``' Instruction 5721*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 5722*9880d681SAndroid Build Coastguard Worker 5723*9880d681SAndroid Build Coastguard WorkerSyntax: 5724*9880d681SAndroid Build Coastguard Worker""""""" 5725*9880d681SAndroid Build Coastguard Worker 5726*9880d681SAndroid Build Coastguard Worker:: 5727*9880d681SAndroid Build Coastguard Worker 5728*9880d681SAndroid Build Coastguard Worker cleanupret from <value> unwind label <continue> 5729*9880d681SAndroid Build Coastguard Worker cleanupret from <value> unwind to caller 5730*9880d681SAndroid Build Coastguard Worker 5731*9880d681SAndroid Build Coastguard WorkerOverview: 5732*9880d681SAndroid Build Coastguard Worker""""""""" 5733*9880d681SAndroid Build Coastguard Worker 5734*9880d681SAndroid Build Coastguard WorkerThe '``cleanupret``' instruction is a terminator instruction that has 5735*9880d681SAndroid Build Coastguard Workeran optional successor. 5736*9880d681SAndroid Build Coastguard Worker 5737*9880d681SAndroid Build Coastguard Worker 5738*9880d681SAndroid Build Coastguard WorkerArguments: 5739*9880d681SAndroid Build Coastguard Worker"""""""""" 5740*9880d681SAndroid Build Coastguard Worker 5741*9880d681SAndroid Build Coastguard WorkerThe '``cleanupret``' instruction requires one argument, which indicates 5742*9880d681SAndroid Build Coastguard Workerwhich ``cleanuppad`` it exits, and must be a :ref:`cleanuppad <i_cleanuppad>`. 5743*9880d681SAndroid Build Coastguard WorkerIf the specified ``cleanuppad`` is not the most-recently-entered not-yet-exited 5744*9880d681SAndroid Build Coastguard Workerfunclet pad (as described in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_), 5745*9880d681SAndroid Build Coastguard Workerthe ``cleanupret``'s behavior is undefined. 5746*9880d681SAndroid Build Coastguard Worker 5747*9880d681SAndroid Build Coastguard WorkerThe '``cleanupret``' instruction also has an optional successor, ``continue``, 5748*9880d681SAndroid Build Coastguard Workerwhich must be the label of another basic block beginning with either a 5749*9880d681SAndroid Build Coastguard Worker``cleanuppad`` or ``catchswitch`` instruction. This unwind destination must 5750*9880d681SAndroid Build Coastguard Workerbe a legal target with respect to the ``parent`` links, as described in the 5751*9880d681SAndroid Build Coastguard Worker`exception handling documentation\ <ExceptionHandling.html#wineh-constraints>`_. 5752*9880d681SAndroid Build Coastguard Worker 5753*9880d681SAndroid Build Coastguard WorkerSemantics: 5754*9880d681SAndroid Build Coastguard Worker"""""""""" 5755*9880d681SAndroid Build Coastguard Worker 5756*9880d681SAndroid Build Coastguard WorkerThe '``cleanupret``' instruction indicates to the 5757*9880d681SAndroid Build Coastguard Worker:ref:`personality function <personalityfn>` that one 5758*9880d681SAndroid Build Coastguard Worker:ref:`cleanuppad <i_cleanuppad>` it transferred control to has ended. 5759*9880d681SAndroid Build Coastguard WorkerIt transfers control to ``continue`` or unwinds out of the function. 5760*9880d681SAndroid Build Coastguard Worker 5761*9880d681SAndroid Build Coastguard WorkerExample: 5762*9880d681SAndroid Build Coastguard Worker"""""""" 5763*9880d681SAndroid Build Coastguard Worker 5764*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 5765*9880d681SAndroid Build Coastguard Worker 5766*9880d681SAndroid Build Coastguard Worker cleanupret from %cleanup unwind to caller 5767*9880d681SAndroid Build Coastguard Worker cleanupret from %cleanup unwind label %continue 5768*9880d681SAndroid Build Coastguard Worker 5769*9880d681SAndroid Build Coastguard Worker.. _i_unreachable: 5770*9880d681SAndroid Build Coastguard Worker 5771*9880d681SAndroid Build Coastguard Worker'``unreachable``' Instruction 5772*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 5773*9880d681SAndroid Build Coastguard Worker 5774*9880d681SAndroid Build Coastguard WorkerSyntax: 5775*9880d681SAndroid Build Coastguard Worker""""""" 5776*9880d681SAndroid Build Coastguard Worker 5777*9880d681SAndroid Build Coastguard Worker:: 5778*9880d681SAndroid Build Coastguard Worker 5779*9880d681SAndroid Build Coastguard Worker unreachable 5780*9880d681SAndroid Build Coastguard Worker 5781*9880d681SAndroid Build Coastguard WorkerOverview: 5782*9880d681SAndroid Build Coastguard Worker""""""""" 5783*9880d681SAndroid Build Coastguard Worker 5784*9880d681SAndroid Build Coastguard WorkerThe '``unreachable``' instruction has no defined semantics. This 5785*9880d681SAndroid Build Coastguard Workerinstruction is used to inform the optimizer that a particular portion of 5786*9880d681SAndroid Build Coastguard Workerthe code is not reachable. This can be used to indicate that the code 5787*9880d681SAndroid Build Coastguard Workerafter a no-return function cannot be reached, and other facts. 5788*9880d681SAndroid Build Coastguard Worker 5789*9880d681SAndroid Build Coastguard WorkerSemantics: 5790*9880d681SAndroid Build Coastguard Worker"""""""""" 5791*9880d681SAndroid Build Coastguard Worker 5792*9880d681SAndroid Build Coastguard WorkerThe '``unreachable``' instruction has no defined semantics. 5793*9880d681SAndroid Build Coastguard Worker 5794*9880d681SAndroid Build Coastguard Worker.. _binaryops: 5795*9880d681SAndroid Build Coastguard Worker 5796*9880d681SAndroid Build Coastguard WorkerBinary Operations 5797*9880d681SAndroid Build Coastguard Worker----------------- 5798*9880d681SAndroid Build Coastguard Worker 5799*9880d681SAndroid Build Coastguard WorkerBinary operators are used to do most of the computation in a program. 5800*9880d681SAndroid Build Coastguard WorkerThey require two operands of the same type, execute an operation on 5801*9880d681SAndroid Build Coastguard Workerthem, and produce a single value. The operands might represent multiple 5802*9880d681SAndroid Build Coastguard Workerdata, as is the case with the :ref:`vector <t_vector>` data type. The 5803*9880d681SAndroid Build Coastguard Workerresult value has the same type as its operands. 5804*9880d681SAndroid Build Coastguard Worker 5805*9880d681SAndroid Build Coastguard WorkerThere are several different binary operators: 5806*9880d681SAndroid Build Coastguard Worker 5807*9880d681SAndroid Build Coastguard Worker.. _i_add: 5808*9880d681SAndroid Build Coastguard Worker 5809*9880d681SAndroid Build Coastguard Worker'``add``' Instruction 5810*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^ 5811*9880d681SAndroid Build Coastguard Worker 5812*9880d681SAndroid Build Coastguard WorkerSyntax: 5813*9880d681SAndroid Build Coastguard Worker""""""" 5814*9880d681SAndroid Build Coastguard Worker 5815*9880d681SAndroid Build Coastguard Worker:: 5816*9880d681SAndroid Build Coastguard Worker 5817*9880d681SAndroid Build Coastguard Worker <result> = add <ty> <op1>, <op2> ; yields ty:result 5818*9880d681SAndroid Build Coastguard Worker <result> = add nuw <ty> <op1>, <op2> ; yields ty:result 5819*9880d681SAndroid Build Coastguard Worker <result> = add nsw <ty> <op1>, <op2> ; yields ty:result 5820*9880d681SAndroid Build Coastguard Worker <result> = add nuw nsw <ty> <op1>, <op2> ; yields ty:result 5821*9880d681SAndroid Build Coastguard Worker 5822*9880d681SAndroid Build Coastguard WorkerOverview: 5823*9880d681SAndroid Build Coastguard Worker""""""""" 5824*9880d681SAndroid Build Coastguard Worker 5825*9880d681SAndroid Build Coastguard WorkerThe '``add``' instruction returns the sum of its two operands. 5826*9880d681SAndroid Build Coastguard Worker 5827*9880d681SAndroid Build Coastguard WorkerArguments: 5828*9880d681SAndroid Build Coastguard Worker"""""""""" 5829*9880d681SAndroid Build Coastguard Worker 5830*9880d681SAndroid Build Coastguard WorkerThe two arguments to the '``add``' instruction must be 5831*9880d681SAndroid Build Coastguard Worker:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 5832*9880d681SAndroid Build Coastguard Workerarguments must have identical types. 5833*9880d681SAndroid Build Coastguard Worker 5834*9880d681SAndroid Build Coastguard WorkerSemantics: 5835*9880d681SAndroid Build Coastguard Worker"""""""""" 5836*9880d681SAndroid Build Coastguard Worker 5837*9880d681SAndroid Build Coastguard WorkerThe value produced is the integer sum of the two operands. 5838*9880d681SAndroid Build Coastguard Worker 5839*9880d681SAndroid Build Coastguard WorkerIf the sum has unsigned overflow, the result returned is the 5840*9880d681SAndroid Build Coastguard Workermathematical result modulo 2\ :sup:`n`\ , where n is the bit width of 5841*9880d681SAndroid Build Coastguard Workerthe result. 5842*9880d681SAndroid Build Coastguard Worker 5843*9880d681SAndroid Build Coastguard WorkerBecause LLVM integers use a two's complement representation, this 5844*9880d681SAndroid Build Coastguard Workerinstruction is appropriate for both signed and unsigned integers. 5845*9880d681SAndroid Build Coastguard Worker 5846*9880d681SAndroid Build Coastguard Worker``nuw`` and ``nsw`` stand for "No Unsigned Wrap" and "No Signed Wrap", 5847*9880d681SAndroid Build Coastguard Workerrespectively. If the ``nuw`` and/or ``nsw`` keywords are present, the 5848*9880d681SAndroid Build Coastguard Workerresult value of the ``add`` is a :ref:`poison value <poisonvalues>` if 5849*9880d681SAndroid Build Coastguard Workerunsigned and/or signed overflow, respectively, occurs. 5850*9880d681SAndroid Build Coastguard Worker 5851*9880d681SAndroid Build Coastguard WorkerExample: 5852*9880d681SAndroid Build Coastguard Worker"""""""" 5853*9880d681SAndroid Build Coastguard Worker 5854*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 5855*9880d681SAndroid Build Coastguard Worker 5856*9880d681SAndroid Build Coastguard Worker <result> = add i32 4, %var ; yields i32:result = 4 + %var 5857*9880d681SAndroid Build Coastguard Worker 5858*9880d681SAndroid Build Coastguard Worker.. _i_fadd: 5859*9880d681SAndroid Build Coastguard Worker 5860*9880d681SAndroid Build Coastguard Worker'``fadd``' Instruction 5861*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^ 5862*9880d681SAndroid Build Coastguard Worker 5863*9880d681SAndroid Build Coastguard WorkerSyntax: 5864*9880d681SAndroid Build Coastguard Worker""""""" 5865*9880d681SAndroid Build Coastguard Worker 5866*9880d681SAndroid Build Coastguard Worker:: 5867*9880d681SAndroid Build Coastguard Worker 5868*9880d681SAndroid Build Coastguard Worker <result> = fadd [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result 5869*9880d681SAndroid Build Coastguard Worker 5870*9880d681SAndroid Build Coastguard WorkerOverview: 5871*9880d681SAndroid Build Coastguard Worker""""""""" 5872*9880d681SAndroid Build Coastguard Worker 5873*9880d681SAndroid Build Coastguard WorkerThe '``fadd``' instruction returns the sum of its two operands. 5874*9880d681SAndroid Build Coastguard Worker 5875*9880d681SAndroid Build Coastguard WorkerArguments: 5876*9880d681SAndroid Build Coastguard Worker"""""""""" 5877*9880d681SAndroid Build Coastguard Worker 5878*9880d681SAndroid Build Coastguard WorkerThe two arguments to the '``fadd``' instruction must be :ref:`floating 5879*9880d681SAndroid Build Coastguard Workerpoint <t_floating>` or :ref:`vector <t_vector>` of floating point values. 5880*9880d681SAndroid Build Coastguard WorkerBoth arguments must have identical types. 5881*9880d681SAndroid Build Coastguard Worker 5882*9880d681SAndroid Build Coastguard WorkerSemantics: 5883*9880d681SAndroid Build Coastguard Worker"""""""""" 5884*9880d681SAndroid Build Coastguard Worker 5885*9880d681SAndroid Build Coastguard WorkerThe value produced is the floating point sum of the two operands. This 5886*9880d681SAndroid Build Coastguard Workerinstruction can also take any number of :ref:`fast-math flags <fastmath>`, 5887*9880d681SAndroid Build Coastguard Workerwhich are optimization hints to enable otherwise unsafe floating point 5888*9880d681SAndroid Build Coastguard Workeroptimizations: 5889*9880d681SAndroid Build Coastguard Worker 5890*9880d681SAndroid Build Coastguard WorkerExample: 5891*9880d681SAndroid Build Coastguard Worker"""""""" 5892*9880d681SAndroid Build Coastguard Worker 5893*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 5894*9880d681SAndroid Build Coastguard Worker 5895*9880d681SAndroid Build Coastguard Worker <result> = fadd float 4.0, %var ; yields float:result = 4.0 + %var 5896*9880d681SAndroid Build Coastguard Worker 5897*9880d681SAndroid Build Coastguard Worker'``sub``' Instruction 5898*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^ 5899*9880d681SAndroid Build Coastguard Worker 5900*9880d681SAndroid Build Coastguard WorkerSyntax: 5901*9880d681SAndroid Build Coastguard Worker""""""" 5902*9880d681SAndroid Build Coastguard Worker 5903*9880d681SAndroid Build Coastguard Worker:: 5904*9880d681SAndroid Build Coastguard Worker 5905*9880d681SAndroid Build Coastguard Worker <result> = sub <ty> <op1>, <op2> ; yields ty:result 5906*9880d681SAndroid Build Coastguard Worker <result> = sub nuw <ty> <op1>, <op2> ; yields ty:result 5907*9880d681SAndroid Build Coastguard Worker <result> = sub nsw <ty> <op1>, <op2> ; yields ty:result 5908*9880d681SAndroid Build Coastguard Worker <result> = sub nuw nsw <ty> <op1>, <op2> ; yields ty:result 5909*9880d681SAndroid Build Coastguard Worker 5910*9880d681SAndroid Build Coastguard WorkerOverview: 5911*9880d681SAndroid Build Coastguard Worker""""""""" 5912*9880d681SAndroid Build Coastguard Worker 5913*9880d681SAndroid Build Coastguard WorkerThe '``sub``' instruction returns the difference of its two operands. 5914*9880d681SAndroid Build Coastguard Worker 5915*9880d681SAndroid Build Coastguard WorkerNote that the '``sub``' instruction is used to represent the '``neg``' 5916*9880d681SAndroid Build Coastguard Workerinstruction present in most other intermediate representations. 5917*9880d681SAndroid Build Coastguard Worker 5918*9880d681SAndroid Build Coastguard WorkerArguments: 5919*9880d681SAndroid Build Coastguard Worker"""""""""" 5920*9880d681SAndroid Build Coastguard Worker 5921*9880d681SAndroid Build Coastguard WorkerThe two arguments to the '``sub``' instruction must be 5922*9880d681SAndroid Build Coastguard Worker:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 5923*9880d681SAndroid Build Coastguard Workerarguments must have identical types. 5924*9880d681SAndroid Build Coastguard Worker 5925*9880d681SAndroid Build Coastguard WorkerSemantics: 5926*9880d681SAndroid Build Coastguard Worker"""""""""" 5927*9880d681SAndroid Build Coastguard Worker 5928*9880d681SAndroid Build Coastguard WorkerThe value produced is the integer difference of the two operands. 5929*9880d681SAndroid Build Coastguard Worker 5930*9880d681SAndroid Build Coastguard WorkerIf the difference has unsigned overflow, the result returned is the 5931*9880d681SAndroid Build Coastguard Workermathematical result modulo 2\ :sup:`n`\ , where n is the bit width of 5932*9880d681SAndroid Build Coastguard Workerthe result. 5933*9880d681SAndroid Build Coastguard Worker 5934*9880d681SAndroid Build Coastguard WorkerBecause LLVM integers use a two's complement representation, this 5935*9880d681SAndroid Build Coastguard Workerinstruction is appropriate for both signed and unsigned integers. 5936*9880d681SAndroid Build Coastguard Worker 5937*9880d681SAndroid Build Coastguard Worker``nuw`` and ``nsw`` stand for "No Unsigned Wrap" and "No Signed Wrap", 5938*9880d681SAndroid Build Coastguard Workerrespectively. If the ``nuw`` and/or ``nsw`` keywords are present, the 5939*9880d681SAndroid Build Coastguard Workerresult value of the ``sub`` is a :ref:`poison value <poisonvalues>` if 5940*9880d681SAndroid Build Coastguard Workerunsigned and/or signed overflow, respectively, occurs. 5941*9880d681SAndroid Build Coastguard Worker 5942*9880d681SAndroid Build Coastguard WorkerExample: 5943*9880d681SAndroid Build Coastguard Worker"""""""" 5944*9880d681SAndroid Build Coastguard Worker 5945*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 5946*9880d681SAndroid Build Coastguard Worker 5947*9880d681SAndroid Build Coastguard Worker <result> = sub i32 4, %var ; yields i32:result = 4 - %var 5948*9880d681SAndroid Build Coastguard Worker <result> = sub i32 0, %val ; yields i32:result = -%var 5949*9880d681SAndroid Build Coastguard Worker 5950*9880d681SAndroid Build Coastguard Worker.. _i_fsub: 5951*9880d681SAndroid Build Coastguard Worker 5952*9880d681SAndroid Build Coastguard Worker'``fsub``' Instruction 5953*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^ 5954*9880d681SAndroid Build Coastguard Worker 5955*9880d681SAndroid Build Coastguard WorkerSyntax: 5956*9880d681SAndroid Build Coastguard Worker""""""" 5957*9880d681SAndroid Build Coastguard Worker 5958*9880d681SAndroid Build Coastguard Worker:: 5959*9880d681SAndroid Build Coastguard Worker 5960*9880d681SAndroid Build Coastguard Worker <result> = fsub [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result 5961*9880d681SAndroid Build Coastguard Worker 5962*9880d681SAndroid Build Coastguard WorkerOverview: 5963*9880d681SAndroid Build Coastguard Worker""""""""" 5964*9880d681SAndroid Build Coastguard Worker 5965*9880d681SAndroid Build Coastguard WorkerThe '``fsub``' instruction returns the difference of its two operands. 5966*9880d681SAndroid Build Coastguard Worker 5967*9880d681SAndroid Build Coastguard WorkerNote that the '``fsub``' instruction is used to represent the '``fneg``' 5968*9880d681SAndroid Build Coastguard Workerinstruction present in most other intermediate representations. 5969*9880d681SAndroid Build Coastguard Worker 5970*9880d681SAndroid Build Coastguard WorkerArguments: 5971*9880d681SAndroid Build Coastguard Worker"""""""""" 5972*9880d681SAndroid Build Coastguard Worker 5973*9880d681SAndroid Build Coastguard WorkerThe two arguments to the '``fsub``' instruction must be :ref:`floating 5974*9880d681SAndroid Build Coastguard Workerpoint <t_floating>` or :ref:`vector <t_vector>` of floating point values. 5975*9880d681SAndroid Build Coastguard WorkerBoth arguments must have identical types. 5976*9880d681SAndroid Build Coastguard Worker 5977*9880d681SAndroid Build Coastguard WorkerSemantics: 5978*9880d681SAndroid Build Coastguard Worker"""""""""" 5979*9880d681SAndroid Build Coastguard Worker 5980*9880d681SAndroid Build Coastguard WorkerThe value produced is the floating point difference of the two operands. 5981*9880d681SAndroid Build Coastguard WorkerThis instruction can also take any number of :ref:`fast-math 5982*9880d681SAndroid Build Coastguard Workerflags <fastmath>`, which are optimization hints to enable otherwise 5983*9880d681SAndroid Build Coastguard Workerunsafe floating point optimizations: 5984*9880d681SAndroid Build Coastguard Worker 5985*9880d681SAndroid Build Coastguard WorkerExample: 5986*9880d681SAndroid Build Coastguard Worker"""""""" 5987*9880d681SAndroid Build Coastguard Worker 5988*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 5989*9880d681SAndroid Build Coastguard Worker 5990*9880d681SAndroid Build Coastguard Worker <result> = fsub float 4.0, %var ; yields float:result = 4.0 - %var 5991*9880d681SAndroid Build Coastguard Worker <result> = fsub float -0.0, %val ; yields float:result = -%var 5992*9880d681SAndroid Build Coastguard Worker 5993*9880d681SAndroid Build Coastguard Worker'``mul``' Instruction 5994*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^ 5995*9880d681SAndroid Build Coastguard Worker 5996*9880d681SAndroid Build Coastguard WorkerSyntax: 5997*9880d681SAndroid Build Coastguard Worker""""""" 5998*9880d681SAndroid Build Coastguard Worker 5999*9880d681SAndroid Build Coastguard Worker:: 6000*9880d681SAndroid Build Coastguard Worker 6001*9880d681SAndroid Build Coastguard Worker <result> = mul <ty> <op1>, <op2> ; yields ty:result 6002*9880d681SAndroid Build Coastguard Worker <result> = mul nuw <ty> <op1>, <op2> ; yields ty:result 6003*9880d681SAndroid Build Coastguard Worker <result> = mul nsw <ty> <op1>, <op2> ; yields ty:result 6004*9880d681SAndroid Build Coastguard Worker <result> = mul nuw nsw <ty> <op1>, <op2> ; yields ty:result 6005*9880d681SAndroid Build Coastguard Worker 6006*9880d681SAndroid Build Coastguard WorkerOverview: 6007*9880d681SAndroid Build Coastguard Worker""""""""" 6008*9880d681SAndroid Build Coastguard Worker 6009*9880d681SAndroid Build Coastguard WorkerThe '``mul``' instruction returns the product of its two operands. 6010*9880d681SAndroid Build Coastguard Worker 6011*9880d681SAndroid Build Coastguard WorkerArguments: 6012*9880d681SAndroid Build Coastguard Worker"""""""""" 6013*9880d681SAndroid Build Coastguard Worker 6014*9880d681SAndroid Build Coastguard WorkerThe two arguments to the '``mul``' instruction must be 6015*9880d681SAndroid Build Coastguard Worker:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 6016*9880d681SAndroid Build Coastguard Workerarguments must have identical types. 6017*9880d681SAndroid Build Coastguard Worker 6018*9880d681SAndroid Build Coastguard WorkerSemantics: 6019*9880d681SAndroid Build Coastguard Worker"""""""""" 6020*9880d681SAndroid Build Coastguard Worker 6021*9880d681SAndroid Build Coastguard WorkerThe value produced is the integer product of the two operands. 6022*9880d681SAndroid Build Coastguard Worker 6023*9880d681SAndroid Build Coastguard WorkerIf the result of the multiplication has unsigned overflow, the result 6024*9880d681SAndroid Build Coastguard Workerreturned is the mathematical result modulo 2\ :sup:`n`\ , where n is the 6025*9880d681SAndroid Build Coastguard Workerbit width of the result. 6026*9880d681SAndroid Build Coastguard Worker 6027*9880d681SAndroid Build Coastguard WorkerBecause LLVM integers use a two's complement representation, and the 6028*9880d681SAndroid Build Coastguard Workerresult is the same width as the operands, this instruction returns the 6029*9880d681SAndroid Build Coastguard Workercorrect result for both signed and unsigned integers. If a full product 6030*9880d681SAndroid Build Coastguard Worker(e.g. ``i32`` * ``i32`` -> ``i64``) is needed, the operands should be 6031*9880d681SAndroid Build Coastguard Workersign-extended or zero-extended as appropriate to the width of the full 6032*9880d681SAndroid Build Coastguard Workerproduct. 6033*9880d681SAndroid Build Coastguard Worker 6034*9880d681SAndroid Build Coastguard Worker``nuw`` and ``nsw`` stand for "No Unsigned Wrap" and "No Signed Wrap", 6035*9880d681SAndroid Build Coastguard Workerrespectively. If the ``nuw`` and/or ``nsw`` keywords are present, the 6036*9880d681SAndroid Build Coastguard Workerresult value of the ``mul`` is a :ref:`poison value <poisonvalues>` if 6037*9880d681SAndroid Build Coastguard Workerunsigned and/or signed overflow, respectively, occurs. 6038*9880d681SAndroid Build Coastguard Worker 6039*9880d681SAndroid Build Coastguard WorkerExample: 6040*9880d681SAndroid Build Coastguard Worker"""""""" 6041*9880d681SAndroid Build Coastguard Worker 6042*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 6043*9880d681SAndroid Build Coastguard Worker 6044*9880d681SAndroid Build Coastguard Worker <result> = mul i32 4, %var ; yields i32:result = 4 * %var 6045*9880d681SAndroid Build Coastguard Worker 6046*9880d681SAndroid Build Coastguard Worker.. _i_fmul: 6047*9880d681SAndroid Build Coastguard Worker 6048*9880d681SAndroid Build Coastguard Worker'``fmul``' Instruction 6049*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^ 6050*9880d681SAndroid Build Coastguard Worker 6051*9880d681SAndroid Build Coastguard WorkerSyntax: 6052*9880d681SAndroid Build Coastguard Worker""""""" 6053*9880d681SAndroid Build Coastguard Worker 6054*9880d681SAndroid Build Coastguard Worker:: 6055*9880d681SAndroid Build Coastguard Worker 6056*9880d681SAndroid Build Coastguard Worker <result> = fmul [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result 6057*9880d681SAndroid Build Coastguard Worker 6058*9880d681SAndroid Build Coastguard WorkerOverview: 6059*9880d681SAndroid Build Coastguard Worker""""""""" 6060*9880d681SAndroid Build Coastguard Worker 6061*9880d681SAndroid Build Coastguard WorkerThe '``fmul``' instruction returns the product of its two operands. 6062*9880d681SAndroid Build Coastguard Worker 6063*9880d681SAndroid Build Coastguard WorkerArguments: 6064*9880d681SAndroid Build Coastguard Worker"""""""""" 6065*9880d681SAndroid Build Coastguard Worker 6066*9880d681SAndroid Build Coastguard WorkerThe two arguments to the '``fmul``' instruction must be :ref:`floating 6067*9880d681SAndroid Build Coastguard Workerpoint <t_floating>` or :ref:`vector <t_vector>` of floating point values. 6068*9880d681SAndroid Build Coastguard WorkerBoth arguments must have identical types. 6069*9880d681SAndroid Build Coastguard Worker 6070*9880d681SAndroid Build Coastguard WorkerSemantics: 6071*9880d681SAndroid Build Coastguard Worker"""""""""" 6072*9880d681SAndroid Build Coastguard Worker 6073*9880d681SAndroid Build Coastguard WorkerThe value produced is the floating point product of the two operands. 6074*9880d681SAndroid Build Coastguard WorkerThis instruction can also take any number of :ref:`fast-math 6075*9880d681SAndroid Build Coastguard Workerflags <fastmath>`, which are optimization hints to enable otherwise 6076*9880d681SAndroid Build Coastguard Workerunsafe floating point optimizations: 6077*9880d681SAndroid Build Coastguard Worker 6078*9880d681SAndroid Build Coastguard WorkerExample: 6079*9880d681SAndroid Build Coastguard Worker"""""""" 6080*9880d681SAndroid Build Coastguard Worker 6081*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 6082*9880d681SAndroid Build Coastguard Worker 6083*9880d681SAndroid Build Coastguard Worker <result> = fmul float 4.0, %var ; yields float:result = 4.0 * %var 6084*9880d681SAndroid Build Coastguard Worker 6085*9880d681SAndroid Build Coastguard Worker'``udiv``' Instruction 6086*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^ 6087*9880d681SAndroid Build Coastguard Worker 6088*9880d681SAndroid Build Coastguard WorkerSyntax: 6089*9880d681SAndroid Build Coastguard Worker""""""" 6090*9880d681SAndroid Build Coastguard Worker 6091*9880d681SAndroid Build Coastguard Worker:: 6092*9880d681SAndroid Build Coastguard Worker 6093*9880d681SAndroid Build Coastguard Worker <result> = udiv <ty> <op1>, <op2> ; yields ty:result 6094*9880d681SAndroid Build Coastguard Worker <result> = udiv exact <ty> <op1>, <op2> ; yields ty:result 6095*9880d681SAndroid Build Coastguard Worker 6096*9880d681SAndroid Build Coastguard WorkerOverview: 6097*9880d681SAndroid Build Coastguard Worker""""""""" 6098*9880d681SAndroid Build Coastguard Worker 6099*9880d681SAndroid Build Coastguard WorkerThe '``udiv``' instruction returns the quotient of its two operands. 6100*9880d681SAndroid Build Coastguard Worker 6101*9880d681SAndroid Build Coastguard WorkerArguments: 6102*9880d681SAndroid Build Coastguard Worker"""""""""" 6103*9880d681SAndroid Build Coastguard Worker 6104*9880d681SAndroid Build Coastguard WorkerThe two arguments to the '``udiv``' instruction must be 6105*9880d681SAndroid Build Coastguard Worker:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 6106*9880d681SAndroid Build Coastguard Workerarguments must have identical types. 6107*9880d681SAndroid Build Coastguard Worker 6108*9880d681SAndroid Build Coastguard WorkerSemantics: 6109*9880d681SAndroid Build Coastguard Worker"""""""""" 6110*9880d681SAndroid Build Coastguard Worker 6111*9880d681SAndroid Build Coastguard WorkerThe value produced is the unsigned integer quotient of the two operands. 6112*9880d681SAndroid Build Coastguard Worker 6113*9880d681SAndroid Build Coastguard WorkerNote that unsigned integer division and signed integer division are 6114*9880d681SAndroid Build Coastguard Workerdistinct operations; for signed integer division, use '``sdiv``'. 6115*9880d681SAndroid Build Coastguard Worker 6116*9880d681SAndroid Build Coastguard WorkerDivision by zero leads to undefined behavior. 6117*9880d681SAndroid Build Coastguard Worker 6118*9880d681SAndroid Build Coastguard WorkerIf the ``exact`` keyword is present, the result value of the ``udiv`` is 6119*9880d681SAndroid Build Coastguard Workera :ref:`poison value <poisonvalues>` if %op1 is not a multiple of %op2 (as 6120*9880d681SAndroid Build Coastguard Workersuch, "((a udiv exact b) mul b) == a"). 6121*9880d681SAndroid Build Coastguard Worker 6122*9880d681SAndroid Build Coastguard WorkerExample: 6123*9880d681SAndroid Build Coastguard Worker"""""""" 6124*9880d681SAndroid Build Coastguard Worker 6125*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 6126*9880d681SAndroid Build Coastguard Worker 6127*9880d681SAndroid Build Coastguard Worker <result> = udiv i32 4, %var ; yields i32:result = 4 / %var 6128*9880d681SAndroid Build Coastguard Worker 6129*9880d681SAndroid Build Coastguard Worker'``sdiv``' Instruction 6130*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^ 6131*9880d681SAndroid Build Coastguard Worker 6132*9880d681SAndroid Build Coastguard WorkerSyntax: 6133*9880d681SAndroid Build Coastguard Worker""""""" 6134*9880d681SAndroid Build Coastguard Worker 6135*9880d681SAndroid Build Coastguard Worker:: 6136*9880d681SAndroid Build Coastguard Worker 6137*9880d681SAndroid Build Coastguard Worker <result> = sdiv <ty> <op1>, <op2> ; yields ty:result 6138*9880d681SAndroid Build Coastguard Worker <result> = sdiv exact <ty> <op1>, <op2> ; yields ty:result 6139*9880d681SAndroid Build Coastguard Worker 6140*9880d681SAndroid Build Coastguard WorkerOverview: 6141*9880d681SAndroid Build Coastguard Worker""""""""" 6142*9880d681SAndroid Build Coastguard Worker 6143*9880d681SAndroid Build Coastguard WorkerThe '``sdiv``' instruction returns the quotient of its two operands. 6144*9880d681SAndroid Build Coastguard Worker 6145*9880d681SAndroid Build Coastguard WorkerArguments: 6146*9880d681SAndroid Build Coastguard Worker"""""""""" 6147*9880d681SAndroid Build Coastguard Worker 6148*9880d681SAndroid Build Coastguard WorkerThe two arguments to the '``sdiv``' instruction must be 6149*9880d681SAndroid Build Coastguard Worker:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 6150*9880d681SAndroid Build Coastguard Workerarguments must have identical types. 6151*9880d681SAndroid Build Coastguard Worker 6152*9880d681SAndroid Build Coastguard WorkerSemantics: 6153*9880d681SAndroid Build Coastguard Worker"""""""""" 6154*9880d681SAndroid Build Coastguard Worker 6155*9880d681SAndroid Build Coastguard WorkerThe value produced is the signed integer quotient of the two operands 6156*9880d681SAndroid Build Coastguard Workerrounded towards zero. 6157*9880d681SAndroid Build Coastguard Worker 6158*9880d681SAndroid Build Coastguard WorkerNote that signed integer division and unsigned integer division are 6159*9880d681SAndroid Build Coastguard Workerdistinct operations; for unsigned integer division, use '``udiv``'. 6160*9880d681SAndroid Build Coastguard Worker 6161*9880d681SAndroid Build Coastguard WorkerDivision by zero leads to undefined behavior. Overflow also leads to 6162*9880d681SAndroid Build Coastguard Workerundefined behavior; this is a rare case, but can occur, for example, by 6163*9880d681SAndroid Build Coastguard Workerdoing a 32-bit division of -2147483648 by -1. 6164*9880d681SAndroid Build Coastguard Worker 6165*9880d681SAndroid Build Coastguard WorkerIf the ``exact`` keyword is present, the result value of the ``sdiv`` is 6166*9880d681SAndroid Build Coastguard Workera :ref:`poison value <poisonvalues>` if the result would be rounded. 6167*9880d681SAndroid Build Coastguard Worker 6168*9880d681SAndroid Build Coastguard WorkerExample: 6169*9880d681SAndroid Build Coastguard Worker"""""""" 6170*9880d681SAndroid Build Coastguard Worker 6171*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 6172*9880d681SAndroid Build Coastguard Worker 6173*9880d681SAndroid Build Coastguard Worker <result> = sdiv i32 4, %var ; yields i32:result = 4 / %var 6174*9880d681SAndroid Build Coastguard Worker 6175*9880d681SAndroid Build Coastguard Worker.. _i_fdiv: 6176*9880d681SAndroid Build Coastguard Worker 6177*9880d681SAndroid Build Coastguard Worker'``fdiv``' Instruction 6178*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^ 6179*9880d681SAndroid Build Coastguard Worker 6180*9880d681SAndroid Build Coastguard WorkerSyntax: 6181*9880d681SAndroid Build Coastguard Worker""""""" 6182*9880d681SAndroid Build Coastguard Worker 6183*9880d681SAndroid Build Coastguard Worker:: 6184*9880d681SAndroid Build Coastguard Worker 6185*9880d681SAndroid Build Coastguard Worker <result> = fdiv [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result 6186*9880d681SAndroid Build Coastguard Worker 6187*9880d681SAndroid Build Coastguard WorkerOverview: 6188*9880d681SAndroid Build Coastguard Worker""""""""" 6189*9880d681SAndroid Build Coastguard Worker 6190*9880d681SAndroid Build Coastguard WorkerThe '``fdiv``' instruction returns the quotient of its two operands. 6191*9880d681SAndroid Build Coastguard Worker 6192*9880d681SAndroid Build Coastguard WorkerArguments: 6193*9880d681SAndroid Build Coastguard Worker"""""""""" 6194*9880d681SAndroid Build Coastguard Worker 6195*9880d681SAndroid Build Coastguard WorkerThe two arguments to the '``fdiv``' instruction must be :ref:`floating 6196*9880d681SAndroid Build Coastguard Workerpoint <t_floating>` or :ref:`vector <t_vector>` of floating point values. 6197*9880d681SAndroid Build Coastguard WorkerBoth arguments must have identical types. 6198*9880d681SAndroid Build Coastguard Worker 6199*9880d681SAndroid Build Coastguard WorkerSemantics: 6200*9880d681SAndroid Build Coastguard Worker"""""""""" 6201*9880d681SAndroid Build Coastguard Worker 6202*9880d681SAndroid Build Coastguard WorkerThe value produced is the floating point quotient of the two operands. 6203*9880d681SAndroid Build Coastguard WorkerThis instruction can also take any number of :ref:`fast-math 6204*9880d681SAndroid Build Coastguard Workerflags <fastmath>`, which are optimization hints to enable otherwise 6205*9880d681SAndroid Build Coastguard Workerunsafe floating point optimizations: 6206*9880d681SAndroid Build Coastguard Worker 6207*9880d681SAndroid Build Coastguard WorkerExample: 6208*9880d681SAndroid Build Coastguard Worker"""""""" 6209*9880d681SAndroid Build Coastguard Worker 6210*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 6211*9880d681SAndroid Build Coastguard Worker 6212*9880d681SAndroid Build Coastguard Worker <result> = fdiv float 4.0, %var ; yields float:result = 4.0 / %var 6213*9880d681SAndroid Build Coastguard Worker 6214*9880d681SAndroid Build Coastguard Worker'``urem``' Instruction 6215*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^ 6216*9880d681SAndroid Build Coastguard Worker 6217*9880d681SAndroid Build Coastguard WorkerSyntax: 6218*9880d681SAndroid Build Coastguard Worker""""""" 6219*9880d681SAndroid Build Coastguard Worker 6220*9880d681SAndroid Build Coastguard Worker:: 6221*9880d681SAndroid Build Coastguard Worker 6222*9880d681SAndroid Build Coastguard Worker <result> = urem <ty> <op1>, <op2> ; yields ty:result 6223*9880d681SAndroid Build Coastguard Worker 6224*9880d681SAndroid Build Coastguard WorkerOverview: 6225*9880d681SAndroid Build Coastguard Worker""""""""" 6226*9880d681SAndroid Build Coastguard Worker 6227*9880d681SAndroid Build Coastguard WorkerThe '``urem``' instruction returns the remainder from the unsigned 6228*9880d681SAndroid Build Coastguard Workerdivision of its two arguments. 6229*9880d681SAndroid Build Coastguard Worker 6230*9880d681SAndroid Build Coastguard WorkerArguments: 6231*9880d681SAndroid Build Coastguard Worker"""""""""" 6232*9880d681SAndroid Build Coastguard Worker 6233*9880d681SAndroid Build Coastguard WorkerThe two arguments to the '``urem``' instruction must be 6234*9880d681SAndroid Build Coastguard Worker:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 6235*9880d681SAndroid Build Coastguard Workerarguments must have identical types. 6236*9880d681SAndroid Build Coastguard Worker 6237*9880d681SAndroid Build Coastguard WorkerSemantics: 6238*9880d681SAndroid Build Coastguard Worker"""""""""" 6239*9880d681SAndroid Build Coastguard Worker 6240*9880d681SAndroid Build Coastguard WorkerThis instruction returns the unsigned integer *remainder* of a division. 6241*9880d681SAndroid Build Coastguard WorkerThis instruction always performs an unsigned division to get the 6242*9880d681SAndroid Build Coastguard Workerremainder. 6243*9880d681SAndroid Build Coastguard Worker 6244*9880d681SAndroid Build Coastguard WorkerNote that unsigned integer remainder and signed integer remainder are 6245*9880d681SAndroid Build Coastguard Workerdistinct operations; for signed integer remainder, use '``srem``'. 6246*9880d681SAndroid Build Coastguard Worker 6247*9880d681SAndroid Build Coastguard WorkerTaking the remainder of a division by zero leads to undefined behavior. 6248*9880d681SAndroid Build Coastguard Worker 6249*9880d681SAndroid Build Coastguard WorkerExample: 6250*9880d681SAndroid Build Coastguard Worker"""""""" 6251*9880d681SAndroid Build Coastguard Worker 6252*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 6253*9880d681SAndroid Build Coastguard Worker 6254*9880d681SAndroid Build Coastguard Worker <result> = urem i32 4, %var ; yields i32:result = 4 % %var 6255*9880d681SAndroid Build Coastguard Worker 6256*9880d681SAndroid Build Coastguard Worker'``srem``' Instruction 6257*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^ 6258*9880d681SAndroid Build Coastguard Worker 6259*9880d681SAndroid Build Coastguard WorkerSyntax: 6260*9880d681SAndroid Build Coastguard Worker""""""" 6261*9880d681SAndroid Build Coastguard Worker 6262*9880d681SAndroid Build Coastguard Worker:: 6263*9880d681SAndroid Build Coastguard Worker 6264*9880d681SAndroid Build Coastguard Worker <result> = srem <ty> <op1>, <op2> ; yields ty:result 6265*9880d681SAndroid Build Coastguard Worker 6266*9880d681SAndroid Build Coastguard WorkerOverview: 6267*9880d681SAndroid Build Coastguard Worker""""""""" 6268*9880d681SAndroid Build Coastguard Worker 6269*9880d681SAndroid Build Coastguard WorkerThe '``srem``' instruction returns the remainder from the signed 6270*9880d681SAndroid Build Coastguard Workerdivision of its two operands. This instruction can also take 6271*9880d681SAndroid Build Coastguard Worker:ref:`vector <t_vector>` versions of the values in which case the elements 6272*9880d681SAndroid Build Coastguard Workermust be integers. 6273*9880d681SAndroid Build Coastguard Worker 6274*9880d681SAndroid Build Coastguard WorkerArguments: 6275*9880d681SAndroid Build Coastguard Worker"""""""""" 6276*9880d681SAndroid Build Coastguard Worker 6277*9880d681SAndroid Build Coastguard WorkerThe two arguments to the '``srem``' instruction must be 6278*9880d681SAndroid Build Coastguard Worker:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 6279*9880d681SAndroid Build Coastguard Workerarguments must have identical types. 6280*9880d681SAndroid Build Coastguard Worker 6281*9880d681SAndroid Build Coastguard WorkerSemantics: 6282*9880d681SAndroid Build Coastguard Worker"""""""""" 6283*9880d681SAndroid Build Coastguard Worker 6284*9880d681SAndroid Build Coastguard WorkerThis instruction returns the *remainder* of a division (where the result 6285*9880d681SAndroid Build Coastguard Workeris either zero or has the same sign as the dividend, ``op1``), not the 6286*9880d681SAndroid Build Coastguard Worker*modulo* operator (where the result is either zero or has the same sign 6287*9880d681SAndroid Build Coastguard Workeras the divisor, ``op2``) of a value. For more information about the 6288*9880d681SAndroid Build Coastguard Workerdifference, see `The Math 6289*9880d681SAndroid Build Coastguard WorkerForum <http://mathforum.org/dr.math/problems/anne.4.28.99.html>`_. For a 6290*9880d681SAndroid Build Coastguard Workertable of how this is implemented in various languages, please see 6291*9880d681SAndroid Build Coastguard Worker`Wikipedia: modulo 6292*9880d681SAndroid Build Coastguard Workeroperation <http://en.wikipedia.org/wiki/Modulo_operation>`_. 6293*9880d681SAndroid Build Coastguard Worker 6294*9880d681SAndroid Build Coastguard WorkerNote that signed integer remainder and unsigned integer remainder are 6295*9880d681SAndroid Build Coastguard Workerdistinct operations; for unsigned integer remainder, use '``urem``'. 6296*9880d681SAndroid Build Coastguard Worker 6297*9880d681SAndroid Build Coastguard WorkerTaking the remainder of a division by zero leads to undefined behavior. 6298*9880d681SAndroid Build Coastguard WorkerOverflow also leads to undefined behavior; this is a rare case, but can 6299*9880d681SAndroid Build Coastguard Workeroccur, for example, by taking the remainder of a 32-bit division of 6300*9880d681SAndroid Build Coastguard Worker-2147483648 by -1. (The remainder doesn't actually overflow, but this 6301*9880d681SAndroid Build Coastguard Workerrule lets srem be implemented using instructions that return both the 6302*9880d681SAndroid Build Coastguard Workerresult of the division and the remainder.) 6303*9880d681SAndroid Build Coastguard Worker 6304*9880d681SAndroid Build Coastguard WorkerExample: 6305*9880d681SAndroid Build Coastguard Worker"""""""" 6306*9880d681SAndroid Build Coastguard Worker 6307*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 6308*9880d681SAndroid Build Coastguard Worker 6309*9880d681SAndroid Build Coastguard Worker <result> = srem i32 4, %var ; yields i32:result = 4 % %var 6310*9880d681SAndroid Build Coastguard Worker 6311*9880d681SAndroid Build Coastguard Worker.. _i_frem: 6312*9880d681SAndroid Build Coastguard Worker 6313*9880d681SAndroid Build Coastguard Worker'``frem``' Instruction 6314*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^ 6315*9880d681SAndroid Build Coastguard Worker 6316*9880d681SAndroid Build Coastguard WorkerSyntax: 6317*9880d681SAndroid Build Coastguard Worker""""""" 6318*9880d681SAndroid Build Coastguard Worker 6319*9880d681SAndroid Build Coastguard Worker:: 6320*9880d681SAndroid Build Coastguard Worker 6321*9880d681SAndroid Build Coastguard Worker <result> = frem [fast-math flags]* <ty> <op1>, <op2> ; yields ty:result 6322*9880d681SAndroid Build Coastguard Worker 6323*9880d681SAndroid Build Coastguard WorkerOverview: 6324*9880d681SAndroid Build Coastguard Worker""""""""" 6325*9880d681SAndroid Build Coastguard Worker 6326*9880d681SAndroid Build Coastguard WorkerThe '``frem``' instruction returns the remainder from the division of 6327*9880d681SAndroid Build Coastguard Workerits two operands. 6328*9880d681SAndroid Build Coastguard Worker 6329*9880d681SAndroid Build Coastguard WorkerArguments: 6330*9880d681SAndroid Build Coastguard Worker"""""""""" 6331*9880d681SAndroid Build Coastguard Worker 6332*9880d681SAndroid Build Coastguard WorkerThe two arguments to the '``frem``' instruction must be :ref:`floating 6333*9880d681SAndroid Build Coastguard Workerpoint <t_floating>` or :ref:`vector <t_vector>` of floating point values. 6334*9880d681SAndroid Build Coastguard WorkerBoth arguments must have identical types. 6335*9880d681SAndroid Build Coastguard Worker 6336*9880d681SAndroid Build Coastguard WorkerSemantics: 6337*9880d681SAndroid Build Coastguard Worker"""""""""" 6338*9880d681SAndroid Build Coastguard Worker 6339*9880d681SAndroid Build Coastguard WorkerThis instruction returns the *remainder* of a division. The remainder 6340*9880d681SAndroid Build Coastguard Workerhas the same sign as the dividend. This instruction can also take any 6341*9880d681SAndroid Build Coastguard Workernumber of :ref:`fast-math flags <fastmath>`, which are optimization hints 6342*9880d681SAndroid Build Coastguard Workerto enable otherwise unsafe floating point optimizations: 6343*9880d681SAndroid Build Coastguard Worker 6344*9880d681SAndroid Build Coastguard WorkerExample: 6345*9880d681SAndroid Build Coastguard Worker"""""""" 6346*9880d681SAndroid Build Coastguard Worker 6347*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 6348*9880d681SAndroid Build Coastguard Worker 6349*9880d681SAndroid Build Coastguard Worker <result> = frem float 4.0, %var ; yields float:result = 4.0 % %var 6350*9880d681SAndroid Build Coastguard Worker 6351*9880d681SAndroid Build Coastguard Worker.. _bitwiseops: 6352*9880d681SAndroid Build Coastguard Worker 6353*9880d681SAndroid Build Coastguard WorkerBitwise Binary Operations 6354*9880d681SAndroid Build Coastguard Worker------------------------- 6355*9880d681SAndroid Build Coastguard Worker 6356*9880d681SAndroid Build Coastguard WorkerBitwise binary operators are used to do various forms of bit-twiddling 6357*9880d681SAndroid Build Coastguard Workerin a program. They are generally very efficient instructions and can 6358*9880d681SAndroid Build Coastguard Workercommonly be strength reduced from other instructions. They require two 6359*9880d681SAndroid Build Coastguard Workeroperands of the same type, execute an operation on them, and produce a 6360*9880d681SAndroid Build Coastguard Workersingle value. The resulting value is the same type as its operands. 6361*9880d681SAndroid Build Coastguard Worker 6362*9880d681SAndroid Build Coastguard Worker'``shl``' Instruction 6363*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^ 6364*9880d681SAndroid Build Coastguard Worker 6365*9880d681SAndroid Build Coastguard WorkerSyntax: 6366*9880d681SAndroid Build Coastguard Worker""""""" 6367*9880d681SAndroid Build Coastguard Worker 6368*9880d681SAndroid Build Coastguard Worker:: 6369*9880d681SAndroid Build Coastguard Worker 6370*9880d681SAndroid Build Coastguard Worker <result> = shl <ty> <op1>, <op2> ; yields ty:result 6371*9880d681SAndroid Build Coastguard Worker <result> = shl nuw <ty> <op1>, <op2> ; yields ty:result 6372*9880d681SAndroid Build Coastguard Worker <result> = shl nsw <ty> <op1>, <op2> ; yields ty:result 6373*9880d681SAndroid Build Coastguard Worker <result> = shl nuw nsw <ty> <op1>, <op2> ; yields ty:result 6374*9880d681SAndroid Build Coastguard Worker 6375*9880d681SAndroid Build Coastguard WorkerOverview: 6376*9880d681SAndroid Build Coastguard Worker""""""""" 6377*9880d681SAndroid Build Coastguard Worker 6378*9880d681SAndroid Build Coastguard WorkerThe '``shl``' instruction returns the first operand shifted to the left 6379*9880d681SAndroid Build Coastguard Workera specified number of bits. 6380*9880d681SAndroid Build Coastguard Worker 6381*9880d681SAndroid Build Coastguard WorkerArguments: 6382*9880d681SAndroid Build Coastguard Worker"""""""""" 6383*9880d681SAndroid Build Coastguard Worker 6384*9880d681SAndroid Build Coastguard WorkerBoth arguments to the '``shl``' instruction must be the same 6385*9880d681SAndroid Build Coastguard Worker:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer type. 6386*9880d681SAndroid Build Coastguard Worker'``op2``' is treated as an unsigned value. 6387*9880d681SAndroid Build Coastguard Worker 6388*9880d681SAndroid Build Coastguard WorkerSemantics: 6389*9880d681SAndroid Build Coastguard Worker"""""""""" 6390*9880d681SAndroid Build Coastguard Worker 6391*9880d681SAndroid Build Coastguard WorkerThe value produced is ``op1`` \* 2\ :sup:`op2` mod 2\ :sup:`n`, 6392*9880d681SAndroid Build Coastguard Workerwhere ``n`` is the width of the result. If ``op2`` is (statically or 6393*9880d681SAndroid Build Coastguard Workerdynamically) equal to or larger than the number of bits in 6394*9880d681SAndroid Build Coastguard Worker``op1``, the result is undefined. If the arguments are vectors, each 6395*9880d681SAndroid Build Coastguard Workervector element of ``op1`` is shifted by the corresponding shift amount 6396*9880d681SAndroid Build Coastguard Workerin ``op2``. 6397*9880d681SAndroid Build Coastguard Worker 6398*9880d681SAndroid Build Coastguard WorkerIf the ``nuw`` keyword is present, then the shift produces a :ref:`poison 6399*9880d681SAndroid Build Coastguard Workervalue <poisonvalues>` if it shifts out any non-zero bits. If the 6400*9880d681SAndroid Build Coastguard Worker``nsw`` keyword is present, then the shift produces a :ref:`poison 6401*9880d681SAndroid Build Coastguard Workervalue <poisonvalues>` if it shifts out any bits that disagree with the 6402*9880d681SAndroid Build Coastguard Workerresultant sign bit. As such, NUW/NSW have the same semantics as they 6403*9880d681SAndroid Build Coastguard Workerwould if the shift were expressed as a mul instruction with the same 6404*9880d681SAndroid Build Coastguard Workernsw/nuw bits in (mul %op1, (shl 1, %op2)). 6405*9880d681SAndroid Build Coastguard Worker 6406*9880d681SAndroid Build Coastguard WorkerExample: 6407*9880d681SAndroid Build Coastguard Worker"""""""" 6408*9880d681SAndroid Build Coastguard Worker 6409*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 6410*9880d681SAndroid Build Coastguard Worker 6411*9880d681SAndroid Build Coastguard Worker <result> = shl i32 4, %var ; yields i32: 4 << %var 6412*9880d681SAndroid Build Coastguard Worker <result> = shl i32 4, 2 ; yields i32: 16 6413*9880d681SAndroid Build Coastguard Worker <result> = shl i32 1, 10 ; yields i32: 1024 6414*9880d681SAndroid Build Coastguard Worker <result> = shl i32 1, 32 ; undefined 6415*9880d681SAndroid Build Coastguard Worker <result> = shl <2 x i32> < i32 1, i32 1>, < i32 1, i32 2> ; yields: result=<2 x i32> < i32 2, i32 4> 6416*9880d681SAndroid Build Coastguard Worker 6417*9880d681SAndroid Build Coastguard Worker'``lshr``' Instruction 6418*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^ 6419*9880d681SAndroid Build Coastguard Worker 6420*9880d681SAndroid Build Coastguard WorkerSyntax: 6421*9880d681SAndroid Build Coastguard Worker""""""" 6422*9880d681SAndroid Build Coastguard Worker 6423*9880d681SAndroid Build Coastguard Worker:: 6424*9880d681SAndroid Build Coastguard Worker 6425*9880d681SAndroid Build Coastguard Worker <result> = lshr <ty> <op1>, <op2> ; yields ty:result 6426*9880d681SAndroid Build Coastguard Worker <result> = lshr exact <ty> <op1>, <op2> ; yields ty:result 6427*9880d681SAndroid Build Coastguard Worker 6428*9880d681SAndroid Build Coastguard WorkerOverview: 6429*9880d681SAndroid Build Coastguard Worker""""""""" 6430*9880d681SAndroid Build Coastguard Worker 6431*9880d681SAndroid Build Coastguard WorkerThe '``lshr``' instruction (logical shift right) returns the first 6432*9880d681SAndroid Build Coastguard Workeroperand shifted to the right a specified number of bits with zero fill. 6433*9880d681SAndroid Build Coastguard Worker 6434*9880d681SAndroid Build Coastguard WorkerArguments: 6435*9880d681SAndroid Build Coastguard Worker"""""""""" 6436*9880d681SAndroid Build Coastguard Worker 6437*9880d681SAndroid Build Coastguard WorkerBoth arguments to the '``lshr``' instruction must be the same 6438*9880d681SAndroid Build Coastguard Worker:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer type. 6439*9880d681SAndroid Build Coastguard Worker'``op2``' is treated as an unsigned value. 6440*9880d681SAndroid Build Coastguard Worker 6441*9880d681SAndroid Build Coastguard WorkerSemantics: 6442*9880d681SAndroid Build Coastguard Worker"""""""""" 6443*9880d681SAndroid Build Coastguard Worker 6444*9880d681SAndroid Build Coastguard WorkerThis instruction always performs a logical shift right operation. The 6445*9880d681SAndroid Build Coastguard Workermost significant bits of the result will be filled with zero bits after 6446*9880d681SAndroid Build Coastguard Workerthe shift. If ``op2`` is (statically or dynamically) equal to or larger 6447*9880d681SAndroid Build Coastguard Workerthan the number of bits in ``op1``, the result is undefined. If the 6448*9880d681SAndroid Build Coastguard Workerarguments are vectors, each vector element of ``op1`` is shifted by the 6449*9880d681SAndroid Build Coastguard Workercorresponding shift amount in ``op2``. 6450*9880d681SAndroid Build Coastguard Worker 6451*9880d681SAndroid Build Coastguard WorkerIf the ``exact`` keyword is present, the result value of the ``lshr`` is 6452*9880d681SAndroid Build Coastguard Workera :ref:`poison value <poisonvalues>` if any of the bits shifted out are 6453*9880d681SAndroid Build Coastguard Workernon-zero. 6454*9880d681SAndroid Build Coastguard Worker 6455*9880d681SAndroid Build Coastguard WorkerExample: 6456*9880d681SAndroid Build Coastguard Worker"""""""" 6457*9880d681SAndroid Build Coastguard Worker 6458*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 6459*9880d681SAndroid Build Coastguard Worker 6460*9880d681SAndroid Build Coastguard Worker <result> = lshr i32 4, 1 ; yields i32:result = 2 6461*9880d681SAndroid Build Coastguard Worker <result> = lshr i32 4, 2 ; yields i32:result = 1 6462*9880d681SAndroid Build Coastguard Worker <result> = lshr i8 4, 3 ; yields i8:result = 0 6463*9880d681SAndroid Build Coastguard Worker <result> = lshr i8 -2, 1 ; yields i8:result = 0x7F 6464*9880d681SAndroid Build Coastguard Worker <result> = lshr i32 1, 32 ; undefined 6465*9880d681SAndroid Build Coastguard Worker <result> = lshr <2 x i32> < i32 -2, i32 4>, < i32 1, i32 2> ; yields: result=<2 x i32> < i32 0x7FFFFFFF, i32 1> 6466*9880d681SAndroid Build Coastguard Worker 6467*9880d681SAndroid Build Coastguard Worker'``ashr``' Instruction 6468*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^ 6469*9880d681SAndroid Build Coastguard Worker 6470*9880d681SAndroid Build Coastguard WorkerSyntax: 6471*9880d681SAndroid Build Coastguard Worker""""""" 6472*9880d681SAndroid Build Coastguard Worker 6473*9880d681SAndroid Build Coastguard Worker:: 6474*9880d681SAndroid Build Coastguard Worker 6475*9880d681SAndroid Build Coastguard Worker <result> = ashr <ty> <op1>, <op2> ; yields ty:result 6476*9880d681SAndroid Build Coastguard Worker <result> = ashr exact <ty> <op1>, <op2> ; yields ty:result 6477*9880d681SAndroid Build Coastguard Worker 6478*9880d681SAndroid Build Coastguard WorkerOverview: 6479*9880d681SAndroid Build Coastguard Worker""""""""" 6480*9880d681SAndroid Build Coastguard Worker 6481*9880d681SAndroid Build Coastguard WorkerThe '``ashr``' instruction (arithmetic shift right) returns the first 6482*9880d681SAndroid Build Coastguard Workeroperand shifted to the right a specified number of bits with sign 6483*9880d681SAndroid Build Coastguard Workerextension. 6484*9880d681SAndroid Build Coastguard Worker 6485*9880d681SAndroid Build Coastguard WorkerArguments: 6486*9880d681SAndroid Build Coastguard Worker"""""""""" 6487*9880d681SAndroid Build Coastguard Worker 6488*9880d681SAndroid Build Coastguard WorkerBoth arguments to the '``ashr``' instruction must be the same 6489*9880d681SAndroid Build Coastguard Worker:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer type. 6490*9880d681SAndroid Build Coastguard Worker'``op2``' is treated as an unsigned value. 6491*9880d681SAndroid Build Coastguard Worker 6492*9880d681SAndroid Build Coastguard WorkerSemantics: 6493*9880d681SAndroid Build Coastguard Worker"""""""""" 6494*9880d681SAndroid Build Coastguard Worker 6495*9880d681SAndroid Build Coastguard WorkerThis instruction always performs an arithmetic shift right operation, 6496*9880d681SAndroid Build Coastguard WorkerThe most significant bits of the result will be filled with the sign bit 6497*9880d681SAndroid Build Coastguard Workerof ``op1``. If ``op2`` is (statically or dynamically) equal to or larger 6498*9880d681SAndroid Build Coastguard Workerthan the number of bits in ``op1``, the result is undefined. If the 6499*9880d681SAndroid Build Coastguard Workerarguments are vectors, each vector element of ``op1`` is shifted by the 6500*9880d681SAndroid Build Coastguard Workercorresponding shift amount in ``op2``. 6501*9880d681SAndroid Build Coastguard Worker 6502*9880d681SAndroid Build Coastguard WorkerIf the ``exact`` keyword is present, the result value of the ``ashr`` is 6503*9880d681SAndroid Build Coastguard Workera :ref:`poison value <poisonvalues>` if any of the bits shifted out are 6504*9880d681SAndroid Build Coastguard Workernon-zero. 6505*9880d681SAndroid Build Coastguard Worker 6506*9880d681SAndroid Build Coastguard WorkerExample: 6507*9880d681SAndroid Build Coastguard Worker"""""""" 6508*9880d681SAndroid Build Coastguard Worker 6509*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 6510*9880d681SAndroid Build Coastguard Worker 6511*9880d681SAndroid Build Coastguard Worker <result> = ashr i32 4, 1 ; yields i32:result = 2 6512*9880d681SAndroid Build Coastguard Worker <result> = ashr i32 4, 2 ; yields i32:result = 1 6513*9880d681SAndroid Build Coastguard Worker <result> = ashr i8 4, 3 ; yields i8:result = 0 6514*9880d681SAndroid Build Coastguard Worker <result> = ashr i8 -2, 1 ; yields i8:result = -1 6515*9880d681SAndroid Build Coastguard Worker <result> = ashr i32 1, 32 ; undefined 6516*9880d681SAndroid Build Coastguard Worker <result> = ashr <2 x i32> < i32 -2, i32 4>, < i32 1, i32 3> ; yields: result=<2 x i32> < i32 -1, i32 0> 6517*9880d681SAndroid Build Coastguard Worker 6518*9880d681SAndroid Build Coastguard Worker'``and``' Instruction 6519*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^ 6520*9880d681SAndroid Build Coastguard Worker 6521*9880d681SAndroid Build Coastguard WorkerSyntax: 6522*9880d681SAndroid Build Coastguard Worker""""""" 6523*9880d681SAndroid Build Coastguard Worker 6524*9880d681SAndroid Build Coastguard Worker:: 6525*9880d681SAndroid Build Coastguard Worker 6526*9880d681SAndroid Build Coastguard Worker <result> = and <ty> <op1>, <op2> ; yields ty:result 6527*9880d681SAndroid Build Coastguard Worker 6528*9880d681SAndroid Build Coastguard WorkerOverview: 6529*9880d681SAndroid Build Coastguard Worker""""""""" 6530*9880d681SAndroid Build Coastguard Worker 6531*9880d681SAndroid Build Coastguard WorkerThe '``and``' instruction returns the bitwise logical and of its two 6532*9880d681SAndroid Build Coastguard Workeroperands. 6533*9880d681SAndroid Build Coastguard Worker 6534*9880d681SAndroid Build Coastguard WorkerArguments: 6535*9880d681SAndroid Build Coastguard Worker"""""""""" 6536*9880d681SAndroid Build Coastguard Worker 6537*9880d681SAndroid Build Coastguard WorkerThe two arguments to the '``and``' instruction must be 6538*9880d681SAndroid Build Coastguard Worker:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 6539*9880d681SAndroid Build Coastguard Workerarguments must have identical types. 6540*9880d681SAndroid Build Coastguard Worker 6541*9880d681SAndroid Build Coastguard WorkerSemantics: 6542*9880d681SAndroid Build Coastguard Worker"""""""""" 6543*9880d681SAndroid Build Coastguard Worker 6544*9880d681SAndroid Build Coastguard WorkerThe truth table used for the '``and``' instruction is: 6545*9880d681SAndroid Build Coastguard Worker 6546*9880d681SAndroid Build Coastguard Worker+-----+-----+-----+ 6547*9880d681SAndroid Build Coastguard Worker| In0 | In1 | Out | 6548*9880d681SAndroid Build Coastguard Worker+-----+-----+-----+ 6549*9880d681SAndroid Build Coastguard Worker| 0 | 0 | 0 | 6550*9880d681SAndroid Build Coastguard Worker+-----+-----+-----+ 6551*9880d681SAndroid Build Coastguard Worker| 0 | 1 | 0 | 6552*9880d681SAndroid Build Coastguard Worker+-----+-----+-----+ 6553*9880d681SAndroid Build Coastguard Worker| 1 | 0 | 0 | 6554*9880d681SAndroid Build Coastguard Worker+-----+-----+-----+ 6555*9880d681SAndroid Build Coastguard Worker| 1 | 1 | 1 | 6556*9880d681SAndroid Build Coastguard Worker+-----+-----+-----+ 6557*9880d681SAndroid Build Coastguard Worker 6558*9880d681SAndroid Build Coastguard WorkerExample: 6559*9880d681SAndroid Build Coastguard Worker"""""""" 6560*9880d681SAndroid Build Coastguard Worker 6561*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 6562*9880d681SAndroid Build Coastguard Worker 6563*9880d681SAndroid Build Coastguard Worker <result> = and i32 4, %var ; yields i32:result = 4 & %var 6564*9880d681SAndroid Build Coastguard Worker <result> = and i32 15, 40 ; yields i32:result = 8 6565*9880d681SAndroid Build Coastguard Worker <result> = and i32 4, 8 ; yields i32:result = 0 6566*9880d681SAndroid Build Coastguard Worker 6567*9880d681SAndroid Build Coastguard Worker'``or``' Instruction 6568*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^ 6569*9880d681SAndroid Build Coastguard Worker 6570*9880d681SAndroid Build Coastguard WorkerSyntax: 6571*9880d681SAndroid Build Coastguard Worker""""""" 6572*9880d681SAndroid Build Coastguard Worker 6573*9880d681SAndroid Build Coastguard Worker:: 6574*9880d681SAndroid Build Coastguard Worker 6575*9880d681SAndroid Build Coastguard Worker <result> = or <ty> <op1>, <op2> ; yields ty:result 6576*9880d681SAndroid Build Coastguard Worker 6577*9880d681SAndroid Build Coastguard WorkerOverview: 6578*9880d681SAndroid Build Coastguard Worker""""""""" 6579*9880d681SAndroid Build Coastguard Worker 6580*9880d681SAndroid Build Coastguard WorkerThe '``or``' instruction returns the bitwise logical inclusive or of its 6581*9880d681SAndroid Build Coastguard Workertwo operands. 6582*9880d681SAndroid Build Coastguard Worker 6583*9880d681SAndroid Build Coastguard WorkerArguments: 6584*9880d681SAndroid Build Coastguard Worker"""""""""" 6585*9880d681SAndroid Build Coastguard Worker 6586*9880d681SAndroid Build Coastguard WorkerThe two arguments to the '``or``' instruction must be 6587*9880d681SAndroid Build Coastguard Worker:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 6588*9880d681SAndroid Build Coastguard Workerarguments must have identical types. 6589*9880d681SAndroid Build Coastguard Worker 6590*9880d681SAndroid Build Coastguard WorkerSemantics: 6591*9880d681SAndroid Build Coastguard Worker"""""""""" 6592*9880d681SAndroid Build Coastguard Worker 6593*9880d681SAndroid Build Coastguard WorkerThe truth table used for the '``or``' instruction is: 6594*9880d681SAndroid Build Coastguard Worker 6595*9880d681SAndroid Build Coastguard Worker+-----+-----+-----+ 6596*9880d681SAndroid Build Coastguard Worker| In0 | In1 | Out | 6597*9880d681SAndroid Build Coastguard Worker+-----+-----+-----+ 6598*9880d681SAndroid Build Coastguard Worker| 0 | 0 | 0 | 6599*9880d681SAndroid Build Coastguard Worker+-----+-----+-----+ 6600*9880d681SAndroid Build Coastguard Worker| 0 | 1 | 1 | 6601*9880d681SAndroid Build Coastguard Worker+-----+-----+-----+ 6602*9880d681SAndroid Build Coastguard Worker| 1 | 0 | 1 | 6603*9880d681SAndroid Build Coastguard Worker+-----+-----+-----+ 6604*9880d681SAndroid Build Coastguard Worker| 1 | 1 | 1 | 6605*9880d681SAndroid Build Coastguard Worker+-----+-----+-----+ 6606*9880d681SAndroid Build Coastguard Worker 6607*9880d681SAndroid Build Coastguard WorkerExample: 6608*9880d681SAndroid Build Coastguard Worker"""""""" 6609*9880d681SAndroid Build Coastguard Worker 6610*9880d681SAndroid Build Coastguard Worker:: 6611*9880d681SAndroid Build Coastguard Worker 6612*9880d681SAndroid Build Coastguard Worker <result> = or i32 4, %var ; yields i32:result = 4 | %var 6613*9880d681SAndroid Build Coastguard Worker <result> = or i32 15, 40 ; yields i32:result = 47 6614*9880d681SAndroid Build Coastguard Worker <result> = or i32 4, 8 ; yields i32:result = 12 6615*9880d681SAndroid Build Coastguard Worker 6616*9880d681SAndroid Build Coastguard Worker'``xor``' Instruction 6617*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^ 6618*9880d681SAndroid Build Coastguard Worker 6619*9880d681SAndroid Build Coastguard WorkerSyntax: 6620*9880d681SAndroid Build Coastguard Worker""""""" 6621*9880d681SAndroid Build Coastguard Worker 6622*9880d681SAndroid Build Coastguard Worker:: 6623*9880d681SAndroid Build Coastguard Worker 6624*9880d681SAndroid Build Coastguard Worker <result> = xor <ty> <op1>, <op2> ; yields ty:result 6625*9880d681SAndroid Build Coastguard Worker 6626*9880d681SAndroid Build Coastguard WorkerOverview: 6627*9880d681SAndroid Build Coastguard Worker""""""""" 6628*9880d681SAndroid Build Coastguard Worker 6629*9880d681SAndroid Build Coastguard WorkerThe '``xor``' instruction returns the bitwise logical exclusive or of 6630*9880d681SAndroid Build Coastguard Workerits two operands. The ``xor`` is used to implement the "one's 6631*9880d681SAndroid Build Coastguard Workercomplement" operation, which is the "~" operator in C. 6632*9880d681SAndroid Build Coastguard Worker 6633*9880d681SAndroid Build Coastguard WorkerArguments: 6634*9880d681SAndroid Build Coastguard Worker"""""""""" 6635*9880d681SAndroid Build Coastguard Worker 6636*9880d681SAndroid Build Coastguard WorkerThe two arguments to the '``xor``' instruction must be 6637*9880d681SAndroid Build Coastguard Worker:ref:`integer <t_integer>` or :ref:`vector <t_vector>` of integer values. Both 6638*9880d681SAndroid Build Coastguard Workerarguments must have identical types. 6639*9880d681SAndroid Build Coastguard Worker 6640*9880d681SAndroid Build Coastguard WorkerSemantics: 6641*9880d681SAndroid Build Coastguard Worker"""""""""" 6642*9880d681SAndroid Build Coastguard Worker 6643*9880d681SAndroid Build Coastguard WorkerThe truth table used for the '``xor``' instruction is: 6644*9880d681SAndroid Build Coastguard Worker 6645*9880d681SAndroid Build Coastguard Worker+-----+-----+-----+ 6646*9880d681SAndroid Build Coastguard Worker| In0 | In1 | Out | 6647*9880d681SAndroid Build Coastguard Worker+-----+-----+-----+ 6648*9880d681SAndroid Build Coastguard Worker| 0 | 0 | 0 | 6649*9880d681SAndroid Build Coastguard Worker+-----+-----+-----+ 6650*9880d681SAndroid Build Coastguard Worker| 0 | 1 | 1 | 6651*9880d681SAndroid Build Coastguard Worker+-----+-----+-----+ 6652*9880d681SAndroid Build Coastguard Worker| 1 | 0 | 1 | 6653*9880d681SAndroid Build Coastguard Worker+-----+-----+-----+ 6654*9880d681SAndroid Build Coastguard Worker| 1 | 1 | 0 | 6655*9880d681SAndroid Build Coastguard Worker+-----+-----+-----+ 6656*9880d681SAndroid Build Coastguard Worker 6657*9880d681SAndroid Build Coastguard WorkerExample: 6658*9880d681SAndroid Build Coastguard Worker"""""""" 6659*9880d681SAndroid Build Coastguard Worker 6660*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 6661*9880d681SAndroid Build Coastguard Worker 6662*9880d681SAndroid Build Coastguard Worker <result> = xor i32 4, %var ; yields i32:result = 4 ^ %var 6663*9880d681SAndroid Build Coastguard Worker <result> = xor i32 15, 40 ; yields i32:result = 39 6664*9880d681SAndroid Build Coastguard Worker <result> = xor i32 4, 8 ; yields i32:result = 12 6665*9880d681SAndroid Build Coastguard Worker <result> = xor i32 %V, -1 ; yields i32:result = ~%V 6666*9880d681SAndroid Build Coastguard Worker 6667*9880d681SAndroid Build Coastguard WorkerVector Operations 6668*9880d681SAndroid Build Coastguard Worker----------------- 6669*9880d681SAndroid Build Coastguard Worker 6670*9880d681SAndroid Build Coastguard WorkerLLVM supports several instructions to represent vector operations in a 6671*9880d681SAndroid Build Coastguard Workertarget-independent manner. These instructions cover the element-access 6672*9880d681SAndroid Build Coastguard Workerand vector-specific operations needed to process vectors effectively. 6673*9880d681SAndroid Build Coastguard WorkerWhile LLVM does directly support these vector operations, many 6674*9880d681SAndroid Build Coastguard Workersophisticated algorithms will want to use target-specific intrinsics to 6675*9880d681SAndroid Build Coastguard Workertake full advantage of a specific target. 6676*9880d681SAndroid Build Coastguard Worker 6677*9880d681SAndroid Build Coastguard Worker.. _i_extractelement: 6678*9880d681SAndroid Build Coastguard Worker 6679*9880d681SAndroid Build Coastguard Worker'``extractelement``' Instruction 6680*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6681*9880d681SAndroid Build Coastguard Worker 6682*9880d681SAndroid Build Coastguard WorkerSyntax: 6683*9880d681SAndroid Build Coastguard Worker""""""" 6684*9880d681SAndroid Build Coastguard Worker 6685*9880d681SAndroid Build Coastguard Worker:: 6686*9880d681SAndroid Build Coastguard Worker 6687*9880d681SAndroid Build Coastguard Worker <result> = extractelement <n x <ty>> <val>, <ty2> <idx> ; yields <ty> 6688*9880d681SAndroid Build Coastguard Worker 6689*9880d681SAndroid Build Coastguard WorkerOverview: 6690*9880d681SAndroid Build Coastguard Worker""""""""" 6691*9880d681SAndroid Build Coastguard Worker 6692*9880d681SAndroid Build Coastguard WorkerThe '``extractelement``' instruction extracts a single scalar element 6693*9880d681SAndroid Build Coastguard Workerfrom a vector at a specified index. 6694*9880d681SAndroid Build Coastguard Worker 6695*9880d681SAndroid Build Coastguard WorkerArguments: 6696*9880d681SAndroid Build Coastguard Worker"""""""""" 6697*9880d681SAndroid Build Coastguard Worker 6698*9880d681SAndroid Build Coastguard WorkerThe first operand of an '``extractelement``' instruction is a value of 6699*9880d681SAndroid Build Coastguard Worker:ref:`vector <t_vector>` type. The second operand is an index indicating 6700*9880d681SAndroid Build Coastguard Workerthe position from which to extract the element. The index may be a 6701*9880d681SAndroid Build Coastguard Workervariable of any integer type. 6702*9880d681SAndroid Build Coastguard Worker 6703*9880d681SAndroid Build Coastguard WorkerSemantics: 6704*9880d681SAndroid Build Coastguard Worker"""""""""" 6705*9880d681SAndroid Build Coastguard Worker 6706*9880d681SAndroid Build Coastguard WorkerThe result is a scalar of the same type as the element type of ``val``. 6707*9880d681SAndroid Build Coastguard WorkerIts value is the value at position ``idx`` of ``val``. If ``idx`` 6708*9880d681SAndroid Build Coastguard Workerexceeds the length of ``val``, the results are undefined. 6709*9880d681SAndroid Build Coastguard Worker 6710*9880d681SAndroid Build Coastguard WorkerExample: 6711*9880d681SAndroid Build Coastguard Worker"""""""" 6712*9880d681SAndroid Build Coastguard Worker 6713*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 6714*9880d681SAndroid Build Coastguard Worker 6715*9880d681SAndroid Build Coastguard Worker <result> = extractelement <4 x i32> %vec, i32 0 ; yields i32 6716*9880d681SAndroid Build Coastguard Worker 6717*9880d681SAndroid Build Coastguard Worker.. _i_insertelement: 6718*9880d681SAndroid Build Coastguard Worker 6719*9880d681SAndroid Build Coastguard Worker'``insertelement``' Instruction 6720*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6721*9880d681SAndroid Build Coastguard Worker 6722*9880d681SAndroid Build Coastguard WorkerSyntax: 6723*9880d681SAndroid Build Coastguard Worker""""""" 6724*9880d681SAndroid Build Coastguard Worker 6725*9880d681SAndroid Build Coastguard Worker:: 6726*9880d681SAndroid Build Coastguard Worker 6727*9880d681SAndroid Build Coastguard Worker <result> = insertelement <n x <ty>> <val>, <ty> <elt>, <ty2> <idx> ; yields <n x <ty>> 6728*9880d681SAndroid Build Coastguard Worker 6729*9880d681SAndroid Build Coastguard WorkerOverview: 6730*9880d681SAndroid Build Coastguard Worker""""""""" 6731*9880d681SAndroid Build Coastguard Worker 6732*9880d681SAndroid Build Coastguard WorkerThe '``insertelement``' instruction inserts a scalar element into a 6733*9880d681SAndroid Build Coastguard Workervector at a specified index. 6734*9880d681SAndroid Build Coastguard Worker 6735*9880d681SAndroid Build Coastguard WorkerArguments: 6736*9880d681SAndroid Build Coastguard Worker"""""""""" 6737*9880d681SAndroid Build Coastguard Worker 6738*9880d681SAndroid Build Coastguard WorkerThe first operand of an '``insertelement``' instruction is a value of 6739*9880d681SAndroid Build Coastguard Worker:ref:`vector <t_vector>` type. The second operand is a scalar value whose 6740*9880d681SAndroid Build Coastguard Workertype must equal the element type of the first operand. The third operand 6741*9880d681SAndroid Build Coastguard Workeris an index indicating the position at which to insert the value. The 6742*9880d681SAndroid Build Coastguard Workerindex may be a variable of any integer type. 6743*9880d681SAndroid Build Coastguard Worker 6744*9880d681SAndroid Build Coastguard WorkerSemantics: 6745*9880d681SAndroid Build Coastguard Worker"""""""""" 6746*9880d681SAndroid Build Coastguard Worker 6747*9880d681SAndroid Build Coastguard WorkerThe result is a vector of the same type as ``val``. Its element values 6748*9880d681SAndroid Build Coastguard Workerare those of ``val`` except at position ``idx``, where it gets the value 6749*9880d681SAndroid Build Coastguard Worker``elt``. If ``idx`` exceeds the length of ``val``, the results are 6750*9880d681SAndroid Build Coastguard Workerundefined. 6751*9880d681SAndroid Build Coastguard Worker 6752*9880d681SAndroid Build Coastguard WorkerExample: 6753*9880d681SAndroid Build Coastguard Worker"""""""" 6754*9880d681SAndroid Build Coastguard Worker 6755*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 6756*9880d681SAndroid Build Coastguard Worker 6757*9880d681SAndroid Build Coastguard Worker <result> = insertelement <4 x i32> %vec, i32 1, i32 0 ; yields <4 x i32> 6758*9880d681SAndroid Build Coastguard Worker 6759*9880d681SAndroid Build Coastguard Worker.. _i_shufflevector: 6760*9880d681SAndroid Build Coastguard Worker 6761*9880d681SAndroid Build Coastguard Worker'``shufflevector``' Instruction 6762*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6763*9880d681SAndroid Build Coastguard Worker 6764*9880d681SAndroid Build Coastguard WorkerSyntax: 6765*9880d681SAndroid Build Coastguard Worker""""""" 6766*9880d681SAndroid Build Coastguard Worker 6767*9880d681SAndroid Build Coastguard Worker:: 6768*9880d681SAndroid Build Coastguard Worker 6769*9880d681SAndroid Build Coastguard Worker <result> = shufflevector <n x <ty>> <v1>, <n x <ty>> <v2>, <m x i32> <mask> ; yields <m x <ty>> 6770*9880d681SAndroid Build Coastguard Worker 6771*9880d681SAndroid Build Coastguard WorkerOverview: 6772*9880d681SAndroid Build Coastguard Worker""""""""" 6773*9880d681SAndroid Build Coastguard Worker 6774*9880d681SAndroid Build Coastguard WorkerThe '``shufflevector``' instruction constructs a permutation of elements 6775*9880d681SAndroid Build Coastguard Workerfrom two input vectors, returning a vector with the same element type as 6776*9880d681SAndroid Build Coastguard Workerthe input and length that is the same as the shuffle mask. 6777*9880d681SAndroid Build Coastguard Worker 6778*9880d681SAndroid Build Coastguard WorkerArguments: 6779*9880d681SAndroid Build Coastguard Worker"""""""""" 6780*9880d681SAndroid Build Coastguard Worker 6781*9880d681SAndroid Build Coastguard WorkerThe first two operands of a '``shufflevector``' instruction are vectors 6782*9880d681SAndroid Build Coastguard Workerwith the same type. The third argument is a shuffle mask whose element 6783*9880d681SAndroid Build Coastguard Workertype is always 'i32'. The result of the instruction is a vector whose 6784*9880d681SAndroid Build Coastguard Workerlength is the same as the shuffle mask and whose element type is the 6785*9880d681SAndroid Build Coastguard Workersame as the element type of the first two operands. 6786*9880d681SAndroid Build Coastguard Worker 6787*9880d681SAndroid Build Coastguard WorkerThe shuffle mask operand is required to be a constant vector with either 6788*9880d681SAndroid Build Coastguard Workerconstant integer or undef values. 6789*9880d681SAndroid Build Coastguard Worker 6790*9880d681SAndroid Build Coastguard WorkerSemantics: 6791*9880d681SAndroid Build Coastguard Worker"""""""""" 6792*9880d681SAndroid Build Coastguard Worker 6793*9880d681SAndroid Build Coastguard WorkerThe elements of the two input vectors are numbered from left to right 6794*9880d681SAndroid Build Coastguard Workeracross both of the vectors. The shuffle mask operand specifies, for each 6795*9880d681SAndroid Build Coastguard Workerelement of the result vector, which element of the two input vectors the 6796*9880d681SAndroid Build Coastguard Workerresult element gets. The element selector may be undef (meaning "don't 6797*9880d681SAndroid Build Coastguard Workercare") and the second operand may be undef if performing a shuffle from 6798*9880d681SAndroid Build Coastguard Workeronly one vector. 6799*9880d681SAndroid Build Coastguard Worker 6800*9880d681SAndroid Build Coastguard WorkerExample: 6801*9880d681SAndroid Build Coastguard Worker"""""""" 6802*9880d681SAndroid Build Coastguard Worker 6803*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 6804*9880d681SAndroid Build Coastguard Worker 6805*9880d681SAndroid Build Coastguard Worker <result> = shufflevector <4 x i32> %v1, <4 x i32> %v2, 6806*9880d681SAndroid Build Coastguard Worker <4 x i32> <i32 0, i32 4, i32 1, i32 5> ; yields <4 x i32> 6807*9880d681SAndroid Build Coastguard Worker <result> = shufflevector <4 x i32> %v1, <4 x i32> undef, 6808*9880d681SAndroid Build Coastguard Worker <4 x i32> <i32 0, i32 1, i32 2, i32 3> ; yields <4 x i32> - Identity shuffle. 6809*9880d681SAndroid Build Coastguard Worker <result> = shufflevector <8 x i32> %v1, <8 x i32> undef, 6810*9880d681SAndroid Build Coastguard Worker <4 x i32> <i32 0, i32 1, i32 2, i32 3> ; yields <4 x i32> 6811*9880d681SAndroid Build Coastguard Worker <result> = shufflevector <4 x i32> %v1, <4 x i32> %v2, 6812*9880d681SAndroid Build Coastguard Worker <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7 > ; yields <8 x i32> 6813*9880d681SAndroid Build Coastguard Worker 6814*9880d681SAndroid Build Coastguard WorkerAggregate Operations 6815*9880d681SAndroid Build Coastguard Worker-------------------- 6816*9880d681SAndroid Build Coastguard Worker 6817*9880d681SAndroid Build Coastguard WorkerLLVM supports several instructions for working with 6818*9880d681SAndroid Build Coastguard Worker:ref:`aggregate <t_aggregate>` values. 6819*9880d681SAndroid Build Coastguard Worker 6820*9880d681SAndroid Build Coastguard Worker.. _i_extractvalue: 6821*9880d681SAndroid Build Coastguard Worker 6822*9880d681SAndroid Build Coastguard Worker'``extractvalue``' Instruction 6823*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6824*9880d681SAndroid Build Coastguard Worker 6825*9880d681SAndroid Build Coastguard WorkerSyntax: 6826*9880d681SAndroid Build Coastguard Worker""""""" 6827*9880d681SAndroid Build Coastguard Worker 6828*9880d681SAndroid Build Coastguard Worker:: 6829*9880d681SAndroid Build Coastguard Worker 6830*9880d681SAndroid Build Coastguard Worker <result> = extractvalue <aggregate type> <val>, <idx>{, <idx>}* 6831*9880d681SAndroid Build Coastguard Worker 6832*9880d681SAndroid Build Coastguard WorkerOverview: 6833*9880d681SAndroid Build Coastguard Worker""""""""" 6834*9880d681SAndroid Build Coastguard Worker 6835*9880d681SAndroid Build Coastguard WorkerThe '``extractvalue``' instruction extracts the value of a member field 6836*9880d681SAndroid Build Coastguard Workerfrom an :ref:`aggregate <t_aggregate>` value. 6837*9880d681SAndroid Build Coastguard Worker 6838*9880d681SAndroid Build Coastguard WorkerArguments: 6839*9880d681SAndroid Build Coastguard Worker"""""""""" 6840*9880d681SAndroid Build Coastguard Worker 6841*9880d681SAndroid Build Coastguard WorkerThe first operand of an '``extractvalue``' instruction is a value of 6842*9880d681SAndroid Build Coastguard Worker:ref:`struct <t_struct>` or :ref:`array <t_array>` type. The other operands are 6843*9880d681SAndroid Build Coastguard Workerconstant indices to specify which value to extract in a similar manner 6844*9880d681SAndroid Build Coastguard Workeras indices in a '``getelementptr``' instruction. 6845*9880d681SAndroid Build Coastguard Worker 6846*9880d681SAndroid Build Coastguard WorkerThe major differences to ``getelementptr`` indexing are: 6847*9880d681SAndroid Build Coastguard Worker 6848*9880d681SAndroid Build Coastguard Worker- Since the value being indexed is not a pointer, the first index is 6849*9880d681SAndroid Build Coastguard Worker omitted and assumed to be zero. 6850*9880d681SAndroid Build Coastguard Worker- At least one index must be specified. 6851*9880d681SAndroid Build Coastguard Worker- Not only struct indices but also array indices must be in bounds. 6852*9880d681SAndroid Build Coastguard Worker 6853*9880d681SAndroid Build Coastguard WorkerSemantics: 6854*9880d681SAndroid Build Coastguard Worker"""""""""" 6855*9880d681SAndroid Build Coastguard Worker 6856*9880d681SAndroid Build Coastguard WorkerThe result is the value at the position in the aggregate specified by 6857*9880d681SAndroid Build Coastguard Workerthe index operands. 6858*9880d681SAndroid Build Coastguard Worker 6859*9880d681SAndroid Build Coastguard WorkerExample: 6860*9880d681SAndroid Build Coastguard Worker"""""""" 6861*9880d681SAndroid Build Coastguard Worker 6862*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 6863*9880d681SAndroid Build Coastguard Worker 6864*9880d681SAndroid Build Coastguard Worker <result> = extractvalue {i32, float} %agg, 0 ; yields i32 6865*9880d681SAndroid Build Coastguard Worker 6866*9880d681SAndroid Build Coastguard Worker.. _i_insertvalue: 6867*9880d681SAndroid Build Coastguard Worker 6868*9880d681SAndroid Build Coastguard Worker'``insertvalue``' Instruction 6869*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6870*9880d681SAndroid Build Coastguard Worker 6871*9880d681SAndroid Build Coastguard WorkerSyntax: 6872*9880d681SAndroid Build Coastguard Worker""""""" 6873*9880d681SAndroid Build Coastguard Worker 6874*9880d681SAndroid Build Coastguard Worker:: 6875*9880d681SAndroid Build Coastguard Worker 6876*9880d681SAndroid Build Coastguard Worker <result> = insertvalue <aggregate type> <val>, <ty> <elt>, <idx>{, <idx>}* ; yields <aggregate type> 6877*9880d681SAndroid Build Coastguard Worker 6878*9880d681SAndroid Build Coastguard WorkerOverview: 6879*9880d681SAndroid Build Coastguard Worker""""""""" 6880*9880d681SAndroid Build Coastguard Worker 6881*9880d681SAndroid Build Coastguard WorkerThe '``insertvalue``' instruction inserts a value into a member field in 6882*9880d681SAndroid Build Coastguard Workeran :ref:`aggregate <t_aggregate>` value. 6883*9880d681SAndroid Build Coastguard Worker 6884*9880d681SAndroid Build Coastguard WorkerArguments: 6885*9880d681SAndroid Build Coastguard Worker"""""""""" 6886*9880d681SAndroid Build Coastguard Worker 6887*9880d681SAndroid Build Coastguard WorkerThe first operand of an '``insertvalue``' instruction is a value of 6888*9880d681SAndroid Build Coastguard Worker:ref:`struct <t_struct>` or :ref:`array <t_array>` type. The second operand is 6889*9880d681SAndroid Build Coastguard Workera first-class value to insert. The following operands are constant 6890*9880d681SAndroid Build Coastguard Workerindices indicating the position at which to insert the value in a 6891*9880d681SAndroid Build Coastguard Workersimilar manner as indices in a '``extractvalue``' instruction. The value 6892*9880d681SAndroid Build Coastguard Workerto insert must have the same type as the value identified by the 6893*9880d681SAndroid Build Coastguard Workerindices. 6894*9880d681SAndroid Build Coastguard Worker 6895*9880d681SAndroid Build Coastguard WorkerSemantics: 6896*9880d681SAndroid Build Coastguard Worker"""""""""" 6897*9880d681SAndroid Build Coastguard Worker 6898*9880d681SAndroid Build Coastguard WorkerThe result is an aggregate of the same type as ``val``. Its value is 6899*9880d681SAndroid Build Coastguard Workerthat of ``val`` except that the value at the position specified by the 6900*9880d681SAndroid Build Coastguard Workerindices is that of ``elt``. 6901*9880d681SAndroid Build Coastguard Worker 6902*9880d681SAndroid Build Coastguard WorkerExample: 6903*9880d681SAndroid Build Coastguard Worker"""""""" 6904*9880d681SAndroid Build Coastguard Worker 6905*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 6906*9880d681SAndroid Build Coastguard Worker 6907*9880d681SAndroid Build Coastguard Worker %agg1 = insertvalue {i32, float} undef, i32 1, 0 ; yields {i32 1, float undef} 6908*9880d681SAndroid Build Coastguard Worker %agg2 = insertvalue {i32, float} %agg1, float %val, 1 ; yields {i32 1, float %val} 6909*9880d681SAndroid Build Coastguard Worker %agg3 = insertvalue {i32, {float}} undef, float %val, 1, 0 ; yields {i32 undef, {float %val}} 6910*9880d681SAndroid Build Coastguard Worker 6911*9880d681SAndroid Build Coastguard Worker.. _memoryops: 6912*9880d681SAndroid Build Coastguard Worker 6913*9880d681SAndroid Build Coastguard WorkerMemory Access and Addressing Operations 6914*9880d681SAndroid Build Coastguard Worker--------------------------------------- 6915*9880d681SAndroid Build Coastguard Worker 6916*9880d681SAndroid Build Coastguard WorkerA key design point of an SSA-based representation is how it represents 6917*9880d681SAndroid Build Coastguard Workermemory. In LLVM, no memory locations are in SSA form, which makes things 6918*9880d681SAndroid Build Coastguard Workervery simple. This section describes how to read, write, and allocate 6919*9880d681SAndroid Build Coastguard Workermemory in LLVM. 6920*9880d681SAndroid Build Coastguard Worker 6921*9880d681SAndroid Build Coastguard Worker.. _i_alloca: 6922*9880d681SAndroid Build Coastguard Worker 6923*9880d681SAndroid Build Coastguard Worker'``alloca``' Instruction 6924*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^ 6925*9880d681SAndroid Build Coastguard Worker 6926*9880d681SAndroid Build Coastguard WorkerSyntax: 6927*9880d681SAndroid Build Coastguard Worker""""""" 6928*9880d681SAndroid Build Coastguard Worker 6929*9880d681SAndroid Build Coastguard Worker:: 6930*9880d681SAndroid Build Coastguard Worker 6931*9880d681SAndroid Build Coastguard Worker <result> = alloca [inalloca] <type> [, <ty> <NumElements>] [, align <alignment>] ; yields type*:result 6932*9880d681SAndroid Build Coastguard Worker 6933*9880d681SAndroid Build Coastguard WorkerOverview: 6934*9880d681SAndroid Build Coastguard Worker""""""""" 6935*9880d681SAndroid Build Coastguard Worker 6936*9880d681SAndroid Build Coastguard WorkerThe '``alloca``' instruction allocates memory on the stack frame of the 6937*9880d681SAndroid Build Coastguard Workercurrently executing function, to be automatically released when this 6938*9880d681SAndroid Build Coastguard Workerfunction returns to its caller. The object is always allocated in the 6939*9880d681SAndroid Build Coastguard Workergeneric address space (address space zero). 6940*9880d681SAndroid Build Coastguard Worker 6941*9880d681SAndroid Build Coastguard WorkerArguments: 6942*9880d681SAndroid Build Coastguard Worker"""""""""" 6943*9880d681SAndroid Build Coastguard Worker 6944*9880d681SAndroid Build Coastguard WorkerThe '``alloca``' instruction allocates ``sizeof(<type>)*NumElements`` 6945*9880d681SAndroid Build Coastguard Workerbytes of memory on the runtime stack, returning a pointer of the 6946*9880d681SAndroid Build Coastguard Workerappropriate type to the program. If "NumElements" is specified, it is 6947*9880d681SAndroid Build Coastguard Workerthe number of elements allocated, otherwise "NumElements" is defaulted 6948*9880d681SAndroid Build Coastguard Workerto be one. If a constant alignment is specified, the value result of the 6949*9880d681SAndroid Build Coastguard Workerallocation is guaranteed to be aligned to at least that boundary. The 6950*9880d681SAndroid Build Coastguard Workeralignment may not be greater than ``1 << 29``. If not specified, or if 6951*9880d681SAndroid Build Coastguard Workerzero, the target can choose to align the allocation on any convenient 6952*9880d681SAndroid Build Coastguard Workerboundary compatible with the type. 6953*9880d681SAndroid Build Coastguard Worker 6954*9880d681SAndroid Build Coastguard Worker'``type``' may be any sized type. 6955*9880d681SAndroid Build Coastguard Worker 6956*9880d681SAndroid Build Coastguard WorkerSemantics: 6957*9880d681SAndroid Build Coastguard Worker"""""""""" 6958*9880d681SAndroid Build Coastguard Worker 6959*9880d681SAndroid Build Coastguard WorkerMemory is allocated; a pointer is returned. The operation is undefined 6960*9880d681SAndroid Build Coastguard Workerif there is insufficient stack space for the allocation. '``alloca``'d 6961*9880d681SAndroid Build Coastguard Workermemory is automatically released when the function returns. The 6962*9880d681SAndroid Build Coastguard Worker'``alloca``' instruction is commonly used to represent automatic 6963*9880d681SAndroid Build Coastguard Workervariables that must have an address available. When the function returns 6964*9880d681SAndroid Build Coastguard Worker(either with the ``ret`` or ``resume`` instructions), the memory is 6965*9880d681SAndroid Build Coastguard Workerreclaimed. Allocating zero bytes is legal, but the result is undefined. 6966*9880d681SAndroid Build Coastguard WorkerThe order in which memory is allocated (ie., which way the stack grows) 6967*9880d681SAndroid Build Coastguard Workeris not specified. 6968*9880d681SAndroid Build Coastguard Worker 6969*9880d681SAndroid Build Coastguard WorkerExample: 6970*9880d681SAndroid Build Coastguard Worker"""""""" 6971*9880d681SAndroid Build Coastguard Worker 6972*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 6973*9880d681SAndroid Build Coastguard Worker 6974*9880d681SAndroid Build Coastguard Worker %ptr = alloca i32 ; yields i32*:ptr 6975*9880d681SAndroid Build Coastguard Worker %ptr = alloca i32, i32 4 ; yields i32*:ptr 6976*9880d681SAndroid Build Coastguard Worker %ptr = alloca i32, i32 4, align 1024 ; yields i32*:ptr 6977*9880d681SAndroid Build Coastguard Worker %ptr = alloca i32, align 1024 ; yields i32*:ptr 6978*9880d681SAndroid Build Coastguard Worker 6979*9880d681SAndroid Build Coastguard Worker.. _i_load: 6980*9880d681SAndroid Build Coastguard Worker 6981*9880d681SAndroid Build Coastguard Worker'``load``' Instruction 6982*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^ 6983*9880d681SAndroid Build Coastguard Worker 6984*9880d681SAndroid Build Coastguard WorkerSyntax: 6985*9880d681SAndroid Build Coastguard Worker""""""" 6986*9880d681SAndroid Build Coastguard Worker 6987*9880d681SAndroid Build Coastguard Worker:: 6988*9880d681SAndroid Build Coastguard Worker 6989*9880d681SAndroid Build Coastguard Worker <result> = load [volatile] <ty>, <ty>* <pointer>[, align <alignment>][, !nontemporal !<index>][, !invariant.load !<index>][, !invariant.group !<index>][, !nonnull !<index>][, !dereferenceable !<deref_bytes_node>][, !dereferenceable_or_null !<deref_bytes_node>][, !align !<align_node>] 6990*9880d681SAndroid Build Coastguard Worker <result> = load atomic [volatile] <ty>, <ty>* <pointer> [singlethread] <ordering>, align <alignment> [, !invariant.group !<index>] 6991*9880d681SAndroid Build Coastguard Worker !<index> = !{ i32 1 } 6992*9880d681SAndroid Build Coastguard Worker !<deref_bytes_node> = !{i64 <dereferenceable_bytes>} 6993*9880d681SAndroid Build Coastguard Worker !<align_node> = !{ i64 <value_alignment> } 6994*9880d681SAndroid Build Coastguard Worker 6995*9880d681SAndroid Build Coastguard WorkerOverview: 6996*9880d681SAndroid Build Coastguard Worker""""""""" 6997*9880d681SAndroid Build Coastguard Worker 6998*9880d681SAndroid Build Coastguard WorkerThe '``load``' instruction is used to read from memory. 6999*9880d681SAndroid Build Coastguard Worker 7000*9880d681SAndroid Build Coastguard WorkerArguments: 7001*9880d681SAndroid Build Coastguard Worker"""""""""" 7002*9880d681SAndroid Build Coastguard Worker 7003*9880d681SAndroid Build Coastguard WorkerThe argument to the ``load`` instruction specifies the memory address from which 7004*9880d681SAndroid Build Coastguard Workerto load. The type specified must be a :ref:`first class <t_firstclass>` type of 7005*9880d681SAndroid Build Coastguard Workerknown size (i.e. not containing an :ref:`opaque structural type <t_opaque>`). If 7006*9880d681SAndroid Build Coastguard Workerthe ``load`` is marked as ``volatile``, then the optimizer is not allowed to 7007*9880d681SAndroid Build Coastguard Workermodify the number or order of execution of this ``load`` with other 7008*9880d681SAndroid Build Coastguard Worker:ref:`volatile operations <volatile>`. 7009*9880d681SAndroid Build Coastguard Worker 7010*9880d681SAndroid Build Coastguard WorkerIf the ``load`` is marked as ``atomic``, it takes an extra :ref:`ordering 7011*9880d681SAndroid Build Coastguard Worker<ordering>` and optional ``singlethread`` argument. The ``release`` and 7012*9880d681SAndroid Build Coastguard Worker``acq_rel`` orderings are not valid on ``load`` instructions. Atomic loads 7013*9880d681SAndroid Build Coastguard Workerproduce :ref:`defined <memmodel>` results when they may see multiple atomic 7014*9880d681SAndroid Build Coastguard Workerstores. The type of the pointee must be an integer, pointer, or floating-point 7015*9880d681SAndroid Build Coastguard Workertype whose bit width is a power of two greater than or equal to eight and less 7016*9880d681SAndroid Build Coastguard Workerthan or equal to a target-specific size limit. ``align`` must be explicitly 7017*9880d681SAndroid Build Coastguard Workerspecified on atomic loads, and the load has undefined behavior if the alignment 7018*9880d681SAndroid Build Coastguard Workeris not set to a value which is at least the size in bytes of the 7019*9880d681SAndroid Build Coastguard Workerpointee. ``!nontemporal`` does not have any defined semantics for atomic loads. 7020*9880d681SAndroid Build Coastguard Worker 7021*9880d681SAndroid Build Coastguard WorkerThe optional constant ``align`` argument specifies the alignment of the 7022*9880d681SAndroid Build Coastguard Workeroperation (that is, the alignment of the memory address). A value of 0 7023*9880d681SAndroid Build Coastguard Workeror an omitted ``align`` argument means that the operation has the ABI 7024*9880d681SAndroid Build Coastguard Workeralignment for the target. It is the responsibility of the code emitter 7025*9880d681SAndroid Build Coastguard Workerto ensure that the alignment information is correct. Overestimating the 7026*9880d681SAndroid Build Coastguard Workeralignment results in undefined behavior. Underestimating the alignment 7027*9880d681SAndroid Build Coastguard Workermay produce less efficient code. An alignment of 1 is always safe. The 7028*9880d681SAndroid Build Coastguard Workermaximum possible alignment is ``1 << 29``. An alignment value higher 7029*9880d681SAndroid Build Coastguard Workerthan the size of the loaded type implies memory up to the alignment 7030*9880d681SAndroid Build Coastguard Workervalue bytes can be safely loaded without trapping in the default 7031*9880d681SAndroid Build Coastguard Workeraddress space. Access of the high bytes can interfere with debugging 7032*9880d681SAndroid Build Coastguard Workertools, so should not be accessed if the function has the 7033*9880d681SAndroid Build Coastguard Worker``sanitize_thread`` or ``sanitize_address`` attributes. 7034*9880d681SAndroid Build Coastguard Worker 7035*9880d681SAndroid Build Coastguard WorkerThe optional ``!nontemporal`` metadata must reference a single 7036*9880d681SAndroid Build Coastguard Workermetadata name ``<index>`` corresponding to a metadata node with one 7037*9880d681SAndroid Build Coastguard Worker``i32`` entry of value 1. The existence of the ``!nontemporal`` 7038*9880d681SAndroid Build Coastguard Workermetadata on the instruction tells the optimizer and code generator 7039*9880d681SAndroid Build Coastguard Workerthat this load is not expected to be reused in the cache. The code 7040*9880d681SAndroid Build Coastguard Workergenerator may select special instructions to save cache bandwidth, such 7041*9880d681SAndroid Build Coastguard Workeras the ``MOVNT`` instruction on x86. 7042*9880d681SAndroid Build Coastguard Worker 7043*9880d681SAndroid Build Coastguard WorkerThe optional ``!invariant.load`` metadata must reference a single 7044*9880d681SAndroid Build Coastguard Workermetadata name ``<index>`` corresponding to a metadata node with no 7045*9880d681SAndroid Build Coastguard Workerentries. The existence of the ``!invariant.load`` metadata on the 7046*9880d681SAndroid Build Coastguard Workerinstruction tells the optimizer and code generator that the address 7047*9880d681SAndroid Build Coastguard Workeroperand to this load points to memory which can be assumed unchanged. 7048*9880d681SAndroid Build Coastguard WorkerBeing invariant does not imply that a location is dereferenceable, 7049*9880d681SAndroid Build Coastguard Workerbut it does imply that once the location is known dereferenceable 7050*9880d681SAndroid Build Coastguard Workerits value is henceforth unchanging. 7051*9880d681SAndroid Build Coastguard Worker 7052*9880d681SAndroid Build Coastguard WorkerThe optional ``!invariant.group`` metadata must reference a single metadata name 7053*9880d681SAndroid Build Coastguard Worker ``<index>`` corresponding to a metadata node. See ``invariant.group`` metadata. 7054*9880d681SAndroid Build Coastguard Worker 7055*9880d681SAndroid Build Coastguard WorkerThe optional ``!nonnull`` metadata must reference a single 7056*9880d681SAndroid Build Coastguard Workermetadata name ``<index>`` corresponding to a metadata node with no 7057*9880d681SAndroid Build Coastguard Workerentries. The existence of the ``!nonnull`` metadata on the 7058*9880d681SAndroid Build Coastguard Workerinstruction tells the optimizer that the value loaded is known to 7059*9880d681SAndroid Build Coastguard Workernever be null. This is analogous to the ``nonnull`` attribute 7060*9880d681SAndroid Build Coastguard Workeron parameters and return values. This metadata can only be applied 7061*9880d681SAndroid Build Coastguard Workerto loads of a pointer type. 7062*9880d681SAndroid Build Coastguard Worker 7063*9880d681SAndroid Build Coastguard WorkerThe optional ``!dereferenceable`` metadata must reference a single metadata 7064*9880d681SAndroid Build Coastguard Workername ``<deref_bytes_node>`` corresponding to a metadata node with one ``i64`` 7065*9880d681SAndroid Build Coastguard Workerentry. The existence of the ``!dereferenceable`` metadata on the instruction 7066*9880d681SAndroid Build Coastguard Workertells the optimizer that the value loaded is known to be dereferenceable. 7067*9880d681SAndroid Build Coastguard WorkerThe number of bytes known to be dereferenceable is specified by the integer 7068*9880d681SAndroid Build Coastguard Workervalue in the metadata node. This is analogous to the ''dereferenceable'' 7069*9880d681SAndroid Build Coastguard Workerattribute on parameters and return values. This metadata can only be applied 7070*9880d681SAndroid Build Coastguard Workerto loads of a pointer type. 7071*9880d681SAndroid Build Coastguard Worker 7072*9880d681SAndroid Build Coastguard WorkerThe optional ``!dereferenceable_or_null`` metadata must reference a single 7073*9880d681SAndroid Build Coastguard Workermetadata name ``<deref_bytes_node>`` corresponding to a metadata node with one 7074*9880d681SAndroid Build Coastguard Worker``i64`` entry. The existence of the ``!dereferenceable_or_null`` metadata on the 7075*9880d681SAndroid Build Coastguard Workerinstruction tells the optimizer that the value loaded is known to be either 7076*9880d681SAndroid Build Coastguard Workerdereferenceable or null. 7077*9880d681SAndroid Build Coastguard WorkerThe number of bytes known to be dereferenceable is specified by the integer 7078*9880d681SAndroid Build Coastguard Workervalue in the metadata node. This is analogous to the ''dereferenceable_or_null'' 7079*9880d681SAndroid Build Coastguard Workerattribute on parameters and return values. This metadata can only be applied 7080*9880d681SAndroid Build Coastguard Workerto loads of a pointer type. 7081*9880d681SAndroid Build Coastguard Worker 7082*9880d681SAndroid Build Coastguard WorkerThe optional ``!align`` metadata must reference a single metadata name 7083*9880d681SAndroid Build Coastguard Worker``<align_node>`` corresponding to a metadata node with one ``i64`` entry. 7084*9880d681SAndroid Build Coastguard WorkerThe existence of the ``!align`` metadata on the instruction tells the 7085*9880d681SAndroid Build Coastguard Workeroptimizer that the value loaded is known to be aligned to a boundary specified 7086*9880d681SAndroid Build Coastguard Workerby the integer value in the metadata node. The alignment must be a power of 2. 7087*9880d681SAndroid Build Coastguard WorkerThis is analogous to the ''align'' attribute on parameters and return values. 7088*9880d681SAndroid Build Coastguard WorkerThis metadata can only be applied to loads of a pointer type. 7089*9880d681SAndroid Build Coastguard Worker 7090*9880d681SAndroid Build Coastguard WorkerSemantics: 7091*9880d681SAndroid Build Coastguard Worker"""""""""" 7092*9880d681SAndroid Build Coastguard Worker 7093*9880d681SAndroid Build Coastguard WorkerThe location of memory pointed to is loaded. If the value being loaded 7094*9880d681SAndroid Build Coastguard Workeris of scalar type then the number of bytes read does not exceed the 7095*9880d681SAndroid Build Coastguard Workerminimum number of bytes needed to hold all bits of the type. For 7096*9880d681SAndroid Build Coastguard Workerexample, loading an ``i24`` reads at most three bytes. When loading a 7097*9880d681SAndroid Build Coastguard Workervalue of a type like ``i20`` with a size that is not an integral number 7098*9880d681SAndroid Build Coastguard Workerof bytes, the result is undefined if the value was not originally 7099*9880d681SAndroid Build Coastguard Workerwritten using a store of the same type. 7100*9880d681SAndroid Build Coastguard Worker 7101*9880d681SAndroid Build Coastguard WorkerExamples: 7102*9880d681SAndroid Build Coastguard Worker""""""""" 7103*9880d681SAndroid Build Coastguard Worker 7104*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 7105*9880d681SAndroid Build Coastguard Worker 7106*9880d681SAndroid Build Coastguard Worker %ptr = alloca i32 ; yields i32*:ptr 7107*9880d681SAndroid Build Coastguard Worker store i32 3, i32* %ptr ; yields void 7108*9880d681SAndroid Build Coastguard Worker %val = load i32, i32* %ptr ; yields i32:val = i32 3 7109*9880d681SAndroid Build Coastguard Worker 7110*9880d681SAndroid Build Coastguard Worker.. _i_store: 7111*9880d681SAndroid Build Coastguard Worker 7112*9880d681SAndroid Build Coastguard Worker'``store``' Instruction 7113*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^ 7114*9880d681SAndroid Build Coastguard Worker 7115*9880d681SAndroid Build Coastguard WorkerSyntax: 7116*9880d681SAndroid Build Coastguard Worker""""""" 7117*9880d681SAndroid Build Coastguard Worker 7118*9880d681SAndroid Build Coastguard Worker:: 7119*9880d681SAndroid Build Coastguard Worker 7120*9880d681SAndroid Build Coastguard Worker store [volatile] <ty> <value>, <ty>* <pointer>[, align <alignment>][, !nontemporal !<index>][, !invariant.group !<index>] ; yields void 7121*9880d681SAndroid Build Coastguard Worker store atomic [volatile] <ty> <value>, <ty>* <pointer> [singlethread] <ordering>, align <alignment> [, !invariant.group !<index>] ; yields void 7122*9880d681SAndroid Build Coastguard Worker 7123*9880d681SAndroid Build Coastguard WorkerOverview: 7124*9880d681SAndroid Build Coastguard Worker""""""""" 7125*9880d681SAndroid Build Coastguard Worker 7126*9880d681SAndroid Build Coastguard WorkerThe '``store``' instruction is used to write to memory. 7127*9880d681SAndroid Build Coastguard Worker 7128*9880d681SAndroid Build Coastguard WorkerArguments: 7129*9880d681SAndroid Build Coastguard Worker"""""""""" 7130*9880d681SAndroid Build Coastguard Worker 7131*9880d681SAndroid Build Coastguard WorkerThere are two arguments to the ``store`` instruction: a value to store and an 7132*9880d681SAndroid Build Coastguard Workeraddress at which to store it. The type of the ``<pointer>`` operand must be a 7133*9880d681SAndroid Build Coastguard Workerpointer to the :ref:`first class <t_firstclass>` type of the ``<value>`` 7134*9880d681SAndroid Build Coastguard Workeroperand. If the ``store`` is marked as ``volatile``, then the optimizer is not 7135*9880d681SAndroid Build Coastguard Workerallowed to modify the number or order of execution of this ``store`` with other 7136*9880d681SAndroid Build Coastguard Worker:ref:`volatile operations <volatile>`. Only values of :ref:`first class 7137*9880d681SAndroid Build Coastguard Worker<t_firstclass>` types of known size (i.e. not containing an :ref:`opaque 7138*9880d681SAndroid Build Coastguard Workerstructural type <t_opaque>`) can be stored. 7139*9880d681SAndroid Build Coastguard Worker 7140*9880d681SAndroid Build Coastguard WorkerIf the ``store`` is marked as ``atomic``, it takes an extra :ref:`ordering 7141*9880d681SAndroid Build Coastguard Worker<ordering>` and optional ``singlethread`` argument. The ``acquire`` and 7142*9880d681SAndroid Build Coastguard Worker``acq_rel`` orderings aren't valid on ``store`` instructions. Atomic loads 7143*9880d681SAndroid Build Coastguard Workerproduce :ref:`defined <memmodel>` results when they may see multiple atomic 7144*9880d681SAndroid Build Coastguard Workerstores. The type of the pointee must be an integer, pointer, or floating-point 7145*9880d681SAndroid Build Coastguard Workertype whose bit width is a power of two greater than or equal to eight and less 7146*9880d681SAndroid Build Coastguard Workerthan or equal to a target-specific size limit. ``align`` must be explicitly 7147*9880d681SAndroid Build Coastguard Workerspecified on atomic stores, and the store has undefined behavior if the 7148*9880d681SAndroid Build Coastguard Workeralignment is not set to a value which is at least the size in bytes of the 7149*9880d681SAndroid Build Coastguard Workerpointee. ``!nontemporal`` does not have any defined semantics for atomic stores. 7150*9880d681SAndroid Build Coastguard Worker 7151*9880d681SAndroid Build Coastguard WorkerThe optional constant ``align`` argument specifies the alignment of the 7152*9880d681SAndroid Build Coastguard Workeroperation (that is, the alignment of the memory address). A value of 0 7153*9880d681SAndroid Build Coastguard Workeror an omitted ``align`` argument means that the operation has the ABI 7154*9880d681SAndroid Build Coastguard Workeralignment for the target. It is the responsibility of the code emitter 7155*9880d681SAndroid Build Coastguard Workerto ensure that the alignment information is correct. Overestimating the 7156*9880d681SAndroid Build Coastguard Workeralignment results in undefined behavior. Underestimating the 7157*9880d681SAndroid Build Coastguard Workeralignment may produce less efficient code. An alignment of 1 is always 7158*9880d681SAndroid Build Coastguard Workersafe. The maximum possible alignment is ``1 << 29``. An alignment 7159*9880d681SAndroid Build Coastguard Workervalue higher than the size of the stored type implies memory up to the 7160*9880d681SAndroid Build Coastguard Workeralignment value bytes can be stored to without trapping in the default 7161*9880d681SAndroid Build Coastguard Workeraddress space. Storing to the higher bytes however may result in data 7162*9880d681SAndroid Build Coastguard Workerraces if another thread can access the same address. Introducing a 7163*9880d681SAndroid Build Coastguard Workerdata race is not allowed. Storing to the extra bytes is not allowed 7164*9880d681SAndroid Build Coastguard Workereven in situations where a data race is known to not exist if the 7165*9880d681SAndroid Build Coastguard Workerfunction has the ``sanitize_address`` attribute. 7166*9880d681SAndroid Build Coastguard Worker 7167*9880d681SAndroid Build Coastguard WorkerThe optional ``!nontemporal`` metadata must reference a single metadata 7168*9880d681SAndroid Build Coastguard Workername ``<index>`` corresponding to a metadata node with one ``i32`` entry of 7169*9880d681SAndroid Build Coastguard Workervalue 1. The existence of the ``!nontemporal`` metadata on the instruction 7170*9880d681SAndroid Build Coastguard Workertells the optimizer and code generator that this load is not expected to 7171*9880d681SAndroid Build Coastguard Workerbe reused in the cache. The code generator may select special 7172*9880d681SAndroid Build Coastguard Workerinstructions to save cache bandwidth, such as the ``MOVNT`` instruction on 7173*9880d681SAndroid Build Coastguard Workerx86. 7174*9880d681SAndroid Build Coastguard Worker 7175*9880d681SAndroid Build Coastguard WorkerThe optional ``!invariant.group`` metadata must reference a 7176*9880d681SAndroid Build Coastguard Workersingle metadata name ``<index>``. See ``invariant.group`` metadata. 7177*9880d681SAndroid Build Coastguard Worker 7178*9880d681SAndroid Build Coastguard WorkerSemantics: 7179*9880d681SAndroid Build Coastguard Worker"""""""""" 7180*9880d681SAndroid Build Coastguard Worker 7181*9880d681SAndroid Build Coastguard WorkerThe contents of memory are updated to contain ``<value>`` at the 7182*9880d681SAndroid Build Coastguard Workerlocation specified by the ``<pointer>`` operand. If ``<value>`` is 7183*9880d681SAndroid Build Coastguard Workerof scalar type then the number of bytes written does not exceed the 7184*9880d681SAndroid Build Coastguard Workerminimum number of bytes needed to hold all bits of the type. For 7185*9880d681SAndroid Build Coastguard Workerexample, storing an ``i24`` writes at most three bytes. When writing a 7186*9880d681SAndroid Build Coastguard Workervalue of a type like ``i20`` with a size that is not an integral number 7187*9880d681SAndroid Build Coastguard Workerof bytes, it is unspecified what happens to the extra bits that do not 7188*9880d681SAndroid Build Coastguard Workerbelong to the type, but they will typically be overwritten. 7189*9880d681SAndroid Build Coastguard Worker 7190*9880d681SAndroid Build Coastguard WorkerExample: 7191*9880d681SAndroid Build Coastguard Worker"""""""" 7192*9880d681SAndroid Build Coastguard Worker 7193*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 7194*9880d681SAndroid Build Coastguard Worker 7195*9880d681SAndroid Build Coastguard Worker %ptr = alloca i32 ; yields i32*:ptr 7196*9880d681SAndroid Build Coastguard Worker store i32 3, i32* %ptr ; yields void 7197*9880d681SAndroid Build Coastguard Worker %val = load i32, i32* %ptr ; yields i32:val = i32 3 7198*9880d681SAndroid Build Coastguard Worker 7199*9880d681SAndroid Build Coastguard Worker.. _i_fence: 7200*9880d681SAndroid Build Coastguard Worker 7201*9880d681SAndroid Build Coastguard Worker'``fence``' Instruction 7202*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^ 7203*9880d681SAndroid Build Coastguard Worker 7204*9880d681SAndroid Build Coastguard WorkerSyntax: 7205*9880d681SAndroid Build Coastguard Worker""""""" 7206*9880d681SAndroid Build Coastguard Worker 7207*9880d681SAndroid Build Coastguard Worker:: 7208*9880d681SAndroid Build Coastguard Worker 7209*9880d681SAndroid Build Coastguard Worker fence [singlethread] <ordering> ; yields void 7210*9880d681SAndroid Build Coastguard Worker 7211*9880d681SAndroid Build Coastguard WorkerOverview: 7212*9880d681SAndroid Build Coastguard Worker""""""""" 7213*9880d681SAndroid Build Coastguard Worker 7214*9880d681SAndroid Build Coastguard WorkerThe '``fence``' instruction is used to introduce happens-before edges 7215*9880d681SAndroid Build Coastguard Workerbetween operations. 7216*9880d681SAndroid Build Coastguard Worker 7217*9880d681SAndroid Build Coastguard WorkerArguments: 7218*9880d681SAndroid Build Coastguard Worker"""""""""" 7219*9880d681SAndroid Build Coastguard Worker 7220*9880d681SAndroid Build Coastguard Worker'``fence``' instructions take an :ref:`ordering <ordering>` argument which 7221*9880d681SAndroid Build Coastguard Workerdefines what *synchronizes-with* edges they add. They can only be given 7222*9880d681SAndroid Build Coastguard Worker``acquire``, ``release``, ``acq_rel``, and ``seq_cst`` orderings. 7223*9880d681SAndroid Build Coastguard Worker 7224*9880d681SAndroid Build Coastguard WorkerSemantics: 7225*9880d681SAndroid Build Coastguard Worker"""""""""" 7226*9880d681SAndroid Build Coastguard Worker 7227*9880d681SAndroid Build Coastguard WorkerA fence A which has (at least) ``release`` ordering semantics 7228*9880d681SAndroid Build Coastguard Worker*synchronizes with* a fence B with (at least) ``acquire`` ordering 7229*9880d681SAndroid Build Coastguard Workersemantics if and only if there exist atomic operations X and Y, both 7230*9880d681SAndroid Build Coastguard Workeroperating on some atomic object M, such that A is sequenced before X, X 7231*9880d681SAndroid Build Coastguard Workermodifies M (either directly or through some side effect of a sequence 7232*9880d681SAndroid Build Coastguard Workerheaded by X), Y is sequenced before B, and Y observes M. This provides a 7233*9880d681SAndroid Build Coastguard Worker*happens-before* dependency between A and B. Rather than an explicit 7234*9880d681SAndroid Build Coastguard Worker``fence``, one (but not both) of the atomic operations X or Y might 7235*9880d681SAndroid Build Coastguard Workerprovide a ``release`` or ``acquire`` (resp.) ordering constraint and 7236*9880d681SAndroid Build Coastguard Workerstill *synchronize-with* the explicit ``fence`` and establish the 7237*9880d681SAndroid Build Coastguard Worker*happens-before* edge. 7238*9880d681SAndroid Build Coastguard Worker 7239*9880d681SAndroid Build Coastguard WorkerA ``fence`` which has ``seq_cst`` ordering, in addition to having both 7240*9880d681SAndroid Build Coastguard Worker``acquire`` and ``release`` semantics specified above, participates in 7241*9880d681SAndroid Build Coastguard Workerthe global program order of other ``seq_cst`` operations and/or fences. 7242*9880d681SAndroid Build Coastguard Worker 7243*9880d681SAndroid Build Coastguard WorkerThe optional ":ref:`singlethread <singlethread>`" argument specifies 7244*9880d681SAndroid Build Coastguard Workerthat the fence only synchronizes with other fences in the same thread. 7245*9880d681SAndroid Build Coastguard Worker(This is useful for interacting with signal handlers.) 7246*9880d681SAndroid Build Coastguard Worker 7247*9880d681SAndroid Build Coastguard WorkerExample: 7248*9880d681SAndroid Build Coastguard Worker"""""""" 7249*9880d681SAndroid Build Coastguard Worker 7250*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 7251*9880d681SAndroid Build Coastguard Worker 7252*9880d681SAndroid Build Coastguard Worker fence acquire ; yields void 7253*9880d681SAndroid Build Coastguard Worker fence singlethread seq_cst ; yields void 7254*9880d681SAndroid Build Coastguard Worker 7255*9880d681SAndroid Build Coastguard Worker.. _i_cmpxchg: 7256*9880d681SAndroid Build Coastguard Worker 7257*9880d681SAndroid Build Coastguard Worker'``cmpxchg``' Instruction 7258*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^ 7259*9880d681SAndroid Build Coastguard Worker 7260*9880d681SAndroid Build Coastguard WorkerSyntax: 7261*9880d681SAndroid Build Coastguard Worker""""""" 7262*9880d681SAndroid Build Coastguard Worker 7263*9880d681SAndroid Build Coastguard Worker:: 7264*9880d681SAndroid Build Coastguard Worker 7265*9880d681SAndroid Build Coastguard Worker cmpxchg [weak] [volatile] <ty>* <pointer>, <ty> <cmp>, <ty> <new> [singlethread] <success ordering> <failure ordering> ; yields { ty, i1 } 7266*9880d681SAndroid Build Coastguard Worker 7267*9880d681SAndroid Build Coastguard WorkerOverview: 7268*9880d681SAndroid Build Coastguard Worker""""""""" 7269*9880d681SAndroid Build Coastguard Worker 7270*9880d681SAndroid Build Coastguard WorkerThe '``cmpxchg``' instruction is used to atomically modify memory. It 7271*9880d681SAndroid Build Coastguard Workerloads a value in memory and compares it to a given value. If they are 7272*9880d681SAndroid Build Coastguard Workerequal, it tries to store a new value into the memory. 7273*9880d681SAndroid Build Coastguard Worker 7274*9880d681SAndroid Build Coastguard WorkerArguments: 7275*9880d681SAndroid Build Coastguard Worker"""""""""" 7276*9880d681SAndroid Build Coastguard Worker 7277*9880d681SAndroid Build Coastguard WorkerThere are three arguments to the '``cmpxchg``' instruction: an address 7278*9880d681SAndroid Build Coastguard Workerto operate on, a value to compare to the value currently be at that 7279*9880d681SAndroid Build Coastguard Workeraddress, and a new value to place at that address if the compared values 7280*9880d681SAndroid Build Coastguard Workerare equal. The type of '<cmp>' must be an integer or pointer type whose 7281*9880d681SAndroid Build Coastguard Workerbit width is a power of two greater than or equal to eight and less 7282*9880d681SAndroid Build Coastguard Workerthan or equal to a target-specific size limit. '<cmp>' and '<new>' must 7283*9880d681SAndroid Build Coastguard Workerhave the same type, and the type of '<pointer>' must be a pointer to 7284*9880d681SAndroid Build Coastguard Workerthat type. If the ``cmpxchg`` is marked as ``volatile``, then the 7285*9880d681SAndroid Build Coastguard Workeroptimizer is not allowed to modify the number or order of execution of 7286*9880d681SAndroid Build Coastguard Workerthis ``cmpxchg`` with other :ref:`volatile operations <volatile>`. 7287*9880d681SAndroid Build Coastguard Worker 7288*9880d681SAndroid Build Coastguard WorkerThe success and failure :ref:`ordering <ordering>` arguments specify how this 7289*9880d681SAndroid Build Coastguard Worker``cmpxchg`` synchronizes with other atomic operations. Both ordering parameters 7290*9880d681SAndroid Build Coastguard Workermust be at least ``monotonic``, the ordering constraint on failure must be no 7291*9880d681SAndroid Build Coastguard Workerstronger than that on success, and the failure ordering cannot be either 7292*9880d681SAndroid Build Coastguard Worker``release`` or ``acq_rel``. 7293*9880d681SAndroid Build Coastguard Worker 7294*9880d681SAndroid Build Coastguard WorkerThe optional "``singlethread``" argument declares that the ``cmpxchg`` 7295*9880d681SAndroid Build Coastguard Workeris only atomic with respect to code (usually signal handlers) running in 7296*9880d681SAndroid Build Coastguard Workerthe same thread as the ``cmpxchg``. Otherwise the cmpxchg is atomic with 7297*9880d681SAndroid Build Coastguard Workerrespect to all other code in the system. 7298*9880d681SAndroid Build Coastguard Worker 7299*9880d681SAndroid Build Coastguard WorkerThe pointer passed into cmpxchg must have alignment greater than or 7300*9880d681SAndroid Build Coastguard Workerequal to the size in memory of the operand. 7301*9880d681SAndroid Build Coastguard Worker 7302*9880d681SAndroid Build Coastguard WorkerSemantics: 7303*9880d681SAndroid Build Coastguard Worker"""""""""" 7304*9880d681SAndroid Build Coastguard Worker 7305*9880d681SAndroid Build Coastguard WorkerThe contents of memory at the location specified by the '``<pointer>``' operand 7306*9880d681SAndroid Build Coastguard Workeris read and compared to '``<cmp>``'; if the read value is the equal, the 7307*9880d681SAndroid Build Coastguard Worker'``<new>``' is written. The original value at the location is returned, together 7308*9880d681SAndroid Build Coastguard Workerwith a flag indicating success (true) or failure (false). 7309*9880d681SAndroid Build Coastguard Worker 7310*9880d681SAndroid Build Coastguard WorkerIf the cmpxchg operation is marked as ``weak`` then a spurious failure is 7311*9880d681SAndroid Build Coastguard Workerpermitted: the operation may not write ``<new>`` even if the comparison 7312*9880d681SAndroid Build Coastguard Workermatched. 7313*9880d681SAndroid Build Coastguard Worker 7314*9880d681SAndroid Build Coastguard WorkerIf the cmpxchg operation is strong (the default), the i1 value is 1 if and only 7315*9880d681SAndroid Build Coastguard Workerif the value loaded equals ``cmp``. 7316*9880d681SAndroid Build Coastguard Worker 7317*9880d681SAndroid Build Coastguard WorkerA successful ``cmpxchg`` is a read-modify-write instruction for the purpose of 7318*9880d681SAndroid Build Coastguard Workeridentifying release sequences. A failed ``cmpxchg`` is equivalent to an atomic 7319*9880d681SAndroid Build Coastguard Workerload with an ordering parameter determined the second ordering parameter. 7320*9880d681SAndroid Build Coastguard Worker 7321*9880d681SAndroid Build Coastguard WorkerExample: 7322*9880d681SAndroid Build Coastguard Worker"""""""" 7323*9880d681SAndroid Build Coastguard Worker 7324*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 7325*9880d681SAndroid Build Coastguard Worker 7326*9880d681SAndroid Build Coastguard Worker entry: 7327*9880d681SAndroid Build Coastguard Worker %orig = load atomic i32, i32* %ptr unordered, align 4 ; yields i32 7328*9880d681SAndroid Build Coastguard Worker br label %loop 7329*9880d681SAndroid Build Coastguard Worker 7330*9880d681SAndroid Build Coastguard Worker loop: 7331*9880d681SAndroid Build Coastguard Worker %cmp = phi i32 [ %orig, %entry ], [%value_loaded, %loop] 7332*9880d681SAndroid Build Coastguard Worker %squared = mul i32 %cmp, %cmp 7333*9880d681SAndroid Build Coastguard Worker %val_success = cmpxchg i32* %ptr, i32 %cmp, i32 %squared acq_rel monotonic ; yields { i32, i1 } 7334*9880d681SAndroid Build Coastguard Worker %value_loaded = extractvalue { i32, i1 } %val_success, 0 7335*9880d681SAndroid Build Coastguard Worker %success = extractvalue { i32, i1 } %val_success, 1 7336*9880d681SAndroid Build Coastguard Worker br i1 %success, label %done, label %loop 7337*9880d681SAndroid Build Coastguard Worker 7338*9880d681SAndroid Build Coastguard Worker done: 7339*9880d681SAndroid Build Coastguard Worker ... 7340*9880d681SAndroid Build Coastguard Worker 7341*9880d681SAndroid Build Coastguard Worker.. _i_atomicrmw: 7342*9880d681SAndroid Build Coastguard Worker 7343*9880d681SAndroid Build Coastguard Worker'``atomicrmw``' Instruction 7344*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^ 7345*9880d681SAndroid Build Coastguard Worker 7346*9880d681SAndroid Build Coastguard WorkerSyntax: 7347*9880d681SAndroid Build Coastguard Worker""""""" 7348*9880d681SAndroid Build Coastguard Worker 7349*9880d681SAndroid Build Coastguard Worker:: 7350*9880d681SAndroid Build Coastguard Worker 7351*9880d681SAndroid Build Coastguard Worker atomicrmw [volatile] <operation> <ty>* <pointer>, <ty> <value> [singlethread] <ordering> ; yields ty 7352*9880d681SAndroid Build Coastguard Worker 7353*9880d681SAndroid Build Coastguard WorkerOverview: 7354*9880d681SAndroid Build Coastguard Worker""""""""" 7355*9880d681SAndroid Build Coastguard Worker 7356*9880d681SAndroid Build Coastguard WorkerThe '``atomicrmw``' instruction is used to atomically modify memory. 7357*9880d681SAndroid Build Coastguard Worker 7358*9880d681SAndroid Build Coastguard WorkerArguments: 7359*9880d681SAndroid Build Coastguard Worker"""""""""" 7360*9880d681SAndroid Build Coastguard Worker 7361*9880d681SAndroid Build Coastguard WorkerThere are three arguments to the '``atomicrmw``' instruction: an 7362*9880d681SAndroid Build Coastguard Workeroperation to apply, an address whose value to modify, an argument to the 7363*9880d681SAndroid Build Coastguard Workeroperation. The operation must be one of the following keywords: 7364*9880d681SAndroid Build Coastguard Worker 7365*9880d681SAndroid Build Coastguard Worker- xchg 7366*9880d681SAndroid Build Coastguard Worker- add 7367*9880d681SAndroid Build Coastguard Worker- sub 7368*9880d681SAndroid Build Coastguard Worker- and 7369*9880d681SAndroid Build Coastguard Worker- nand 7370*9880d681SAndroid Build Coastguard Worker- or 7371*9880d681SAndroid Build Coastguard Worker- xor 7372*9880d681SAndroid Build Coastguard Worker- max 7373*9880d681SAndroid Build Coastguard Worker- min 7374*9880d681SAndroid Build Coastguard Worker- umax 7375*9880d681SAndroid Build Coastguard Worker- umin 7376*9880d681SAndroid Build Coastguard Worker 7377*9880d681SAndroid Build Coastguard WorkerThe type of '<value>' must be an integer type whose bit width is a power 7378*9880d681SAndroid Build Coastguard Workerof two greater than or equal to eight and less than or equal to a 7379*9880d681SAndroid Build Coastguard Workertarget-specific size limit. The type of the '``<pointer>``' operand must 7380*9880d681SAndroid Build Coastguard Workerbe a pointer to that type. If the ``atomicrmw`` is marked as 7381*9880d681SAndroid Build Coastguard Worker``volatile``, then the optimizer is not allowed to modify the number or 7382*9880d681SAndroid Build Coastguard Workerorder of execution of this ``atomicrmw`` with other :ref:`volatile 7383*9880d681SAndroid Build Coastguard Workeroperations <volatile>`. 7384*9880d681SAndroid Build Coastguard Worker 7385*9880d681SAndroid Build Coastguard WorkerSemantics: 7386*9880d681SAndroid Build Coastguard Worker"""""""""" 7387*9880d681SAndroid Build Coastguard Worker 7388*9880d681SAndroid Build Coastguard WorkerThe contents of memory at the location specified by the '``<pointer>``' 7389*9880d681SAndroid Build Coastguard Workeroperand are atomically read, modified, and written back. The original 7390*9880d681SAndroid Build Coastguard Workervalue at the location is returned. The modification is specified by the 7391*9880d681SAndroid Build Coastguard Workeroperation argument: 7392*9880d681SAndroid Build Coastguard Worker 7393*9880d681SAndroid Build Coastguard Worker- xchg: ``*ptr = val`` 7394*9880d681SAndroid Build Coastguard Worker- add: ``*ptr = *ptr + val`` 7395*9880d681SAndroid Build Coastguard Worker- sub: ``*ptr = *ptr - val`` 7396*9880d681SAndroid Build Coastguard Worker- and: ``*ptr = *ptr & val`` 7397*9880d681SAndroid Build Coastguard Worker- nand: ``*ptr = ~(*ptr & val)`` 7398*9880d681SAndroid Build Coastguard Worker- or: ``*ptr = *ptr | val`` 7399*9880d681SAndroid Build Coastguard Worker- xor: ``*ptr = *ptr ^ val`` 7400*9880d681SAndroid Build Coastguard Worker- max: ``*ptr = *ptr > val ? *ptr : val`` (using a signed comparison) 7401*9880d681SAndroid Build Coastguard Worker- min: ``*ptr = *ptr < val ? *ptr : val`` (using a signed comparison) 7402*9880d681SAndroid Build Coastguard Worker- umax: ``*ptr = *ptr > val ? *ptr : val`` (using an unsigned 7403*9880d681SAndroid Build Coastguard Worker comparison) 7404*9880d681SAndroid Build Coastguard Worker- umin: ``*ptr = *ptr < val ? *ptr : val`` (using an unsigned 7405*9880d681SAndroid Build Coastguard Worker comparison) 7406*9880d681SAndroid Build Coastguard Worker 7407*9880d681SAndroid Build Coastguard WorkerExample: 7408*9880d681SAndroid Build Coastguard Worker"""""""" 7409*9880d681SAndroid Build Coastguard Worker 7410*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 7411*9880d681SAndroid Build Coastguard Worker 7412*9880d681SAndroid Build Coastguard Worker %old = atomicrmw add i32* %ptr, i32 1 acquire ; yields i32 7413*9880d681SAndroid Build Coastguard Worker 7414*9880d681SAndroid Build Coastguard Worker.. _i_getelementptr: 7415*9880d681SAndroid Build Coastguard Worker 7416*9880d681SAndroid Build Coastguard Worker'``getelementptr``' Instruction 7417*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 7418*9880d681SAndroid Build Coastguard Worker 7419*9880d681SAndroid Build Coastguard WorkerSyntax: 7420*9880d681SAndroid Build Coastguard Worker""""""" 7421*9880d681SAndroid Build Coastguard Worker 7422*9880d681SAndroid Build Coastguard Worker:: 7423*9880d681SAndroid Build Coastguard Worker 7424*9880d681SAndroid Build Coastguard Worker <result> = getelementptr <ty>, <ty>* <ptrval>{, <ty> <idx>}* 7425*9880d681SAndroid Build Coastguard Worker <result> = getelementptr inbounds <ty>, <ty>* <ptrval>{, <ty> <idx>}* 7426*9880d681SAndroid Build Coastguard Worker <result> = getelementptr <ty>, <ptr vector> <ptrval>, <vector index type> <idx> 7427*9880d681SAndroid Build Coastguard Worker 7428*9880d681SAndroid Build Coastguard WorkerOverview: 7429*9880d681SAndroid Build Coastguard Worker""""""""" 7430*9880d681SAndroid Build Coastguard Worker 7431*9880d681SAndroid Build Coastguard WorkerThe '``getelementptr``' instruction is used to get the address of a 7432*9880d681SAndroid Build Coastguard Workersubelement of an :ref:`aggregate <t_aggregate>` data structure. It performs 7433*9880d681SAndroid Build Coastguard Workeraddress calculation only and does not access memory. The instruction can also 7434*9880d681SAndroid Build Coastguard Workerbe used to calculate a vector of such addresses. 7435*9880d681SAndroid Build Coastguard Worker 7436*9880d681SAndroid Build Coastguard WorkerArguments: 7437*9880d681SAndroid Build Coastguard Worker"""""""""" 7438*9880d681SAndroid Build Coastguard Worker 7439*9880d681SAndroid Build Coastguard WorkerThe first argument is always a type used as the basis for the calculations. 7440*9880d681SAndroid Build Coastguard WorkerThe second argument is always a pointer or a vector of pointers, and is the 7441*9880d681SAndroid Build Coastguard Workerbase address to start from. The remaining arguments are indices 7442*9880d681SAndroid Build Coastguard Workerthat indicate which of the elements of the aggregate object are indexed. 7443*9880d681SAndroid Build Coastguard WorkerThe interpretation of each index is dependent on the type being indexed 7444*9880d681SAndroid Build Coastguard Workerinto. The first index always indexes the pointer value given as the 7445*9880d681SAndroid Build Coastguard Workerfirst argument, the second index indexes a value of the type pointed to 7446*9880d681SAndroid Build Coastguard Worker(not necessarily the value directly pointed to, since the first index 7447*9880d681SAndroid Build Coastguard Workercan be non-zero), etc. The first type indexed into must be a pointer 7448*9880d681SAndroid Build Coastguard Workervalue, subsequent types can be arrays, vectors, and structs. Note that 7449*9880d681SAndroid Build Coastguard Workersubsequent types being indexed into can never be pointers, since that 7450*9880d681SAndroid Build Coastguard Workerwould require loading the pointer before continuing calculation. 7451*9880d681SAndroid Build Coastguard Worker 7452*9880d681SAndroid Build Coastguard WorkerThe type of each index argument depends on the type it is indexing into. 7453*9880d681SAndroid Build Coastguard WorkerWhen indexing into a (optionally packed) structure, only ``i32`` integer 7454*9880d681SAndroid Build Coastguard Worker**constants** are allowed (when using a vector of indices they must all 7455*9880d681SAndroid Build Coastguard Workerbe the **same** ``i32`` integer constant). When indexing into an array, 7456*9880d681SAndroid Build Coastguard Workerpointer or vector, integers of any width are allowed, and they are not 7457*9880d681SAndroid Build Coastguard Workerrequired to be constant. These integers are treated as signed values 7458*9880d681SAndroid Build Coastguard Workerwhere relevant. 7459*9880d681SAndroid Build Coastguard Worker 7460*9880d681SAndroid Build Coastguard WorkerFor example, let's consider a C code fragment and how it gets compiled 7461*9880d681SAndroid Build Coastguard Workerto LLVM: 7462*9880d681SAndroid Build Coastguard Worker 7463*9880d681SAndroid Build Coastguard Worker.. code-block:: c 7464*9880d681SAndroid Build Coastguard Worker 7465*9880d681SAndroid Build Coastguard Worker struct RT { 7466*9880d681SAndroid Build Coastguard Worker char A; 7467*9880d681SAndroid Build Coastguard Worker int B[10][20]; 7468*9880d681SAndroid Build Coastguard Worker char C; 7469*9880d681SAndroid Build Coastguard Worker }; 7470*9880d681SAndroid Build Coastguard Worker struct ST { 7471*9880d681SAndroid Build Coastguard Worker int X; 7472*9880d681SAndroid Build Coastguard Worker double Y; 7473*9880d681SAndroid Build Coastguard Worker struct RT Z; 7474*9880d681SAndroid Build Coastguard Worker }; 7475*9880d681SAndroid Build Coastguard Worker 7476*9880d681SAndroid Build Coastguard Worker int *foo(struct ST *s) { 7477*9880d681SAndroid Build Coastguard Worker return &s[1].Z.B[5][13]; 7478*9880d681SAndroid Build Coastguard Worker } 7479*9880d681SAndroid Build Coastguard Worker 7480*9880d681SAndroid Build Coastguard WorkerThe LLVM code generated by Clang is: 7481*9880d681SAndroid Build Coastguard Worker 7482*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 7483*9880d681SAndroid Build Coastguard Worker 7484*9880d681SAndroid Build Coastguard Worker %struct.RT = type { i8, [10 x [20 x i32]], i8 } 7485*9880d681SAndroid Build Coastguard Worker %struct.ST = type { i32, double, %struct.RT } 7486*9880d681SAndroid Build Coastguard Worker 7487*9880d681SAndroid Build Coastguard Worker define i32* @foo(%struct.ST* %s) nounwind uwtable readnone optsize ssp { 7488*9880d681SAndroid Build Coastguard Worker entry: 7489*9880d681SAndroid Build Coastguard Worker %arrayidx = getelementptr inbounds %struct.ST, %struct.ST* %s, i64 1, i32 2, i32 1, i64 5, i64 13 7490*9880d681SAndroid Build Coastguard Worker ret i32* %arrayidx 7491*9880d681SAndroid Build Coastguard Worker } 7492*9880d681SAndroid Build Coastguard Worker 7493*9880d681SAndroid Build Coastguard WorkerSemantics: 7494*9880d681SAndroid Build Coastguard Worker"""""""""" 7495*9880d681SAndroid Build Coastguard Worker 7496*9880d681SAndroid Build Coastguard WorkerIn the example above, the first index is indexing into the 7497*9880d681SAndroid Build Coastguard Worker'``%struct.ST*``' type, which is a pointer, yielding a '``%struct.ST``' 7498*9880d681SAndroid Build Coastguard Worker= '``{ i32, double, %struct.RT }``' type, a structure. The second index 7499*9880d681SAndroid Build Coastguard Workerindexes into the third element of the structure, yielding a 7500*9880d681SAndroid Build Coastguard Worker'``%struct.RT``' = '``{ i8 , [10 x [20 x i32]], i8 }``' type, another 7501*9880d681SAndroid Build Coastguard Workerstructure. The third index indexes into the second element of the 7502*9880d681SAndroid Build Coastguard Workerstructure, yielding a '``[10 x [20 x i32]]``' type, an array. The two 7503*9880d681SAndroid Build Coastguard Workerdimensions of the array are subscripted into, yielding an '``i32``' 7504*9880d681SAndroid Build Coastguard Workertype. The '``getelementptr``' instruction returns a pointer to this 7505*9880d681SAndroid Build Coastguard Workerelement, thus computing a value of '``i32*``' type. 7506*9880d681SAndroid Build Coastguard Worker 7507*9880d681SAndroid Build Coastguard WorkerNote that it is perfectly legal to index partially through a structure, 7508*9880d681SAndroid Build Coastguard Workerreturning a pointer to an inner element. Because of this, the LLVM code 7509*9880d681SAndroid Build Coastguard Workerfor the given testcase is equivalent to: 7510*9880d681SAndroid Build Coastguard Worker 7511*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 7512*9880d681SAndroid Build Coastguard Worker 7513*9880d681SAndroid Build Coastguard Worker define i32* @foo(%struct.ST* %s) { 7514*9880d681SAndroid Build Coastguard Worker %t1 = getelementptr %struct.ST, %struct.ST* %s, i32 1 ; yields %struct.ST*:%t1 7515*9880d681SAndroid Build Coastguard Worker %t2 = getelementptr %struct.ST, %struct.ST* %t1, i32 0, i32 2 ; yields %struct.RT*:%t2 7516*9880d681SAndroid Build Coastguard Worker %t3 = getelementptr %struct.RT, %struct.RT* %t2, i32 0, i32 1 ; yields [10 x [20 x i32]]*:%t3 7517*9880d681SAndroid Build Coastguard Worker %t4 = getelementptr [10 x [20 x i32]], [10 x [20 x i32]]* %t3, i32 0, i32 5 ; yields [20 x i32]*:%t4 7518*9880d681SAndroid Build Coastguard Worker %t5 = getelementptr [20 x i32], [20 x i32]* %t4, i32 0, i32 13 ; yields i32*:%t5 7519*9880d681SAndroid Build Coastguard Worker ret i32* %t5 7520*9880d681SAndroid Build Coastguard Worker } 7521*9880d681SAndroid Build Coastguard Worker 7522*9880d681SAndroid Build Coastguard WorkerIf the ``inbounds`` keyword is present, the result value of the 7523*9880d681SAndroid Build Coastguard Worker``getelementptr`` is a :ref:`poison value <poisonvalues>` if the base 7524*9880d681SAndroid Build Coastguard Workerpointer is not an *in bounds* address of an allocated object, or if any 7525*9880d681SAndroid Build Coastguard Workerof the addresses that would be formed by successive addition of the 7526*9880d681SAndroid Build Coastguard Workeroffsets implied by the indices to the base address with infinitely 7527*9880d681SAndroid Build Coastguard Workerprecise signed arithmetic are not an *in bounds* address of that 7528*9880d681SAndroid Build Coastguard Workerallocated object. The *in bounds* addresses for an allocated object are 7529*9880d681SAndroid Build Coastguard Workerall the addresses that point into the object, plus the address one byte 7530*9880d681SAndroid Build Coastguard Workerpast the end. In cases where the base is a vector of pointers the 7531*9880d681SAndroid Build Coastguard Worker``inbounds`` keyword applies to each of the computations element-wise. 7532*9880d681SAndroid Build Coastguard Worker 7533*9880d681SAndroid Build Coastguard WorkerIf the ``inbounds`` keyword is not present, the offsets are added to the 7534*9880d681SAndroid Build Coastguard Workerbase address with silently-wrapping two's complement arithmetic. If the 7535*9880d681SAndroid Build Coastguard Workeroffsets have a different width from the pointer, they are sign-extended 7536*9880d681SAndroid Build Coastguard Workeror truncated to the width of the pointer. The result value of the 7537*9880d681SAndroid Build Coastguard Worker``getelementptr`` may be outside the object pointed to by the base 7538*9880d681SAndroid Build Coastguard Workerpointer. The result value may not necessarily be used to access memory 7539*9880d681SAndroid Build Coastguard Workerthough, even if it happens to point into allocated storage. See the 7540*9880d681SAndroid Build Coastguard Worker:ref:`Pointer Aliasing Rules <pointeraliasing>` section for more 7541*9880d681SAndroid Build Coastguard Workerinformation. 7542*9880d681SAndroid Build Coastguard Worker 7543*9880d681SAndroid Build Coastguard WorkerThe getelementptr instruction is often confusing. For some more insight 7544*9880d681SAndroid Build Coastguard Workerinto how it works, see :doc:`the getelementptr FAQ <GetElementPtr>`. 7545*9880d681SAndroid Build Coastguard Worker 7546*9880d681SAndroid Build Coastguard WorkerExample: 7547*9880d681SAndroid Build Coastguard Worker"""""""" 7548*9880d681SAndroid Build Coastguard Worker 7549*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 7550*9880d681SAndroid Build Coastguard Worker 7551*9880d681SAndroid Build Coastguard Worker ; yields [12 x i8]*:aptr 7552*9880d681SAndroid Build Coastguard Worker %aptr = getelementptr {i32, [12 x i8]}, {i32, [12 x i8]}* %saptr, i64 0, i32 1 7553*9880d681SAndroid Build Coastguard Worker ; yields i8*:vptr 7554*9880d681SAndroid Build Coastguard Worker %vptr = getelementptr {i32, <2 x i8>}, {i32, <2 x i8>}* %svptr, i64 0, i32 1, i32 1 7555*9880d681SAndroid Build Coastguard Worker ; yields i8*:eptr 7556*9880d681SAndroid Build Coastguard Worker %eptr = getelementptr [12 x i8], [12 x i8]* %aptr, i64 0, i32 1 7557*9880d681SAndroid Build Coastguard Worker ; yields i32*:iptr 7558*9880d681SAndroid Build Coastguard Worker %iptr = getelementptr [10 x i32], [10 x i32]* @arr, i16 0, i16 0 7559*9880d681SAndroid Build Coastguard Worker 7560*9880d681SAndroid Build Coastguard WorkerVector of pointers: 7561*9880d681SAndroid Build Coastguard Worker""""""""""""""""""" 7562*9880d681SAndroid Build Coastguard Worker 7563*9880d681SAndroid Build Coastguard WorkerThe ``getelementptr`` returns a vector of pointers, instead of a single address, 7564*9880d681SAndroid Build Coastguard Workerwhen one or more of its arguments is a vector. In such cases, all vector 7565*9880d681SAndroid Build Coastguard Workerarguments should have the same number of elements, and every scalar argument 7566*9880d681SAndroid Build Coastguard Workerwill be effectively broadcast into a vector during address calculation. 7567*9880d681SAndroid Build Coastguard Worker 7568*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 7569*9880d681SAndroid Build Coastguard Worker 7570*9880d681SAndroid Build Coastguard Worker ; All arguments are vectors: 7571*9880d681SAndroid Build Coastguard Worker ; A[i] = ptrs[i] + offsets[i]*sizeof(i8) 7572*9880d681SAndroid Build Coastguard Worker %A = getelementptr i8, <4 x i8*> %ptrs, <4 x i64> %offsets 7573*9880d681SAndroid Build Coastguard Worker 7574*9880d681SAndroid Build Coastguard Worker ; Add the same scalar offset to each pointer of a vector: 7575*9880d681SAndroid Build Coastguard Worker ; A[i] = ptrs[i] + offset*sizeof(i8) 7576*9880d681SAndroid Build Coastguard Worker %A = getelementptr i8, <4 x i8*> %ptrs, i64 %offset 7577*9880d681SAndroid Build Coastguard Worker 7578*9880d681SAndroid Build Coastguard Worker ; Add distinct offsets to the same pointer: 7579*9880d681SAndroid Build Coastguard Worker ; A[i] = ptr + offsets[i]*sizeof(i8) 7580*9880d681SAndroid Build Coastguard Worker %A = getelementptr i8, i8* %ptr, <4 x i64> %offsets 7581*9880d681SAndroid Build Coastguard Worker 7582*9880d681SAndroid Build Coastguard Worker ; In all cases described above the type of the result is <4 x i8*> 7583*9880d681SAndroid Build Coastguard Worker 7584*9880d681SAndroid Build Coastguard WorkerThe two following instructions are equivalent: 7585*9880d681SAndroid Build Coastguard Worker 7586*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 7587*9880d681SAndroid Build Coastguard Worker 7588*9880d681SAndroid Build Coastguard Worker getelementptr %struct.ST, <4 x %struct.ST*> %s, <4 x i64> %ind1, 7589*9880d681SAndroid Build Coastguard Worker <4 x i32> <i32 2, i32 2, i32 2, i32 2>, 7590*9880d681SAndroid Build Coastguard Worker <4 x i32> <i32 1, i32 1, i32 1, i32 1>, 7591*9880d681SAndroid Build Coastguard Worker <4 x i32> %ind4, 7592*9880d681SAndroid Build Coastguard Worker <4 x i64> <i64 13, i64 13, i64 13, i64 13> 7593*9880d681SAndroid Build Coastguard Worker 7594*9880d681SAndroid Build Coastguard Worker getelementptr %struct.ST, <4 x %struct.ST*> %s, <4 x i64> %ind1, 7595*9880d681SAndroid Build Coastguard Worker i32 2, i32 1, <4 x i32> %ind4, i64 13 7596*9880d681SAndroid Build Coastguard Worker 7597*9880d681SAndroid Build Coastguard WorkerLet's look at the C code, where the vector version of ``getelementptr`` 7598*9880d681SAndroid Build Coastguard Workermakes sense: 7599*9880d681SAndroid Build Coastguard Worker 7600*9880d681SAndroid Build Coastguard Worker.. code-block:: c 7601*9880d681SAndroid Build Coastguard Worker 7602*9880d681SAndroid Build Coastguard Worker // Let's assume that we vectorize the following loop: 7603*9880d681SAndroid Build Coastguard Worker double *A, B; int *C; 7604*9880d681SAndroid Build Coastguard Worker for (int i = 0; i < size; ++i) { 7605*9880d681SAndroid Build Coastguard Worker A[i] = B[C[i]]; 7606*9880d681SAndroid Build Coastguard Worker } 7607*9880d681SAndroid Build Coastguard Worker 7608*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 7609*9880d681SAndroid Build Coastguard Worker 7610*9880d681SAndroid Build Coastguard Worker ; get pointers for 8 elements from array B 7611*9880d681SAndroid Build Coastguard Worker %ptrs = getelementptr double, double* %B, <8 x i32> %C 7612*9880d681SAndroid Build Coastguard Worker ; load 8 elements from array B into A 7613*9880d681SAndroid Build Coastguard Worker %A = call <8 x double> @llvm.masked.gather.v8f64(<8 x double*> %ptrs, 7614*9880d681SAndroid Build Coastguard Worker i32 8, <8 x i1> %mask, <8 x double> %passthru) 7615*9880d681SAndroid Build Coastguard Worker 7616*9880d681SAndroid Build Coastguard WorkerConversion Operations 7617*9880d681SAndroid Build Coastguard Worker--------------------- 7618*9880d681SAndroid Build Coastguard Worker 7619*9880d681SAndroid Build Coastguard WorkerThe instructions in this category are the conversion instructions 7620*9880d681SAndroid Build Coastguard Worker(casting) which all take a single operand and a type. They perform 7621*9880d681SAndroid Build Coastguard Workervarious bit conversions on the operand. 7622*9880d681SAndroid Build Coastguard Worker 7623*9880d681SAndroid Build Coastguard Worker'``trunc .. to``' Instruction 7624*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 7625*9880d681SAndroid Build Coastguard Worker 7626*9880d681SAndroid Build Coastguard WorkerSyntax: 7627*9880d681SAndroid Build Coastguard Worker""""""" 7628*9880d681SAndroid Build Coastguard Worker 7629*9880d681SAndroid Build Coastguard Worker:: 7630*9880d681SAndroid Build Coastguard Worker 7631*9880d681SAndroid Build Coastguard Worker <result> = trunc <ty> <value> to <ty2> ; yields ty2 7632*9880d681SAndroid Build Coastguard Worker 7633*9880d681SAndroid Build Coastguard WorkerOverview: 7634*9880d681SAndroid Build Coastguard Worker""""""""" 7635*9880d681SAndroid Build Coastguard Worker 7636*9880d681SAndroid Build Coastguard WorkerThe '``trunc``' instruction truncates its operand to the type ``ty2``. 7637*9880d681SAndroid Build Coastguard Worker 7638*9880d681SAndroid Build Coastguard WorkerArguments: 7639*9880d681SAndroid Build Coastguard Worker"""""""""" 7640*9880d681SAndroid Build Coastguard Worker 7641*9880d681SAndroid Build Coastguard WorkerThe '``trunc``' instruction takes a value to trunc, and a type to trunc 7642*9880d681SAndroid Build Coastguard Workerit to. Both types must be of :ref:`integer <t_integer>` types, or vectors 7643*9880d681SAndroid Build Coastguard Workerof the same number of integers. The bit size of the ``value`` must be 7644*9880d681SAndroid Build Coastguard Workerlarger than the bit size of the destination type, ``ty2``. Equal sized 7645*9880d681SAndroid Build Coastguard Workertypes are not allowed. 7646*9880d681SAndroid Build Coastguard Worker 7647*9880d681SAndroid Build Coastguard WorkerSemantics: 7648*9880d681SAndroid Build Coastguard Worker"""""""""" 7649*9880d681SAndroid Build Coastguard Worker 7650*9880d681SAndroid Build Coastguard WorkerThe '``trunc``' instruction truncates the high order bits in ``value`` 7651*9880d681SAndroid Build Coastguard Workerand converts the remaining bits to ``ty2``. Since the source size must 7652*9880d681SAndroid Build Coastguard Workerbe larger than the destination size, ``trunc`` cannot be a *no-op cast*. 7653*9880d681SAndroid Build Coastguard WorkerIt will always truncate bits. 7654*9880d681SAndroid Build Coastguard Worker 7655*9880d681SAndroid Build Coastguard WorkerExample: 7656*9880d681SAndroid Build Coastguard Worker"""""""" 7657*9880d681SAndroid Build Coastguard Worker 7658*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 7659*9880d681SAndroid Build Coastguard Worker 7660*9880d681SAndroid Build Coastguard Worker %X = trunc i32 257 to i8 ; yields i8:1 7661*9880d681SAndroid Build Coastguard Worker %Y = trunc i32 123 to i1 ; yields i1:true 7662*9880d681SAndroid Build Coastguard Worker %Z = trunc i32 122 to i1 ; yields i1:false 7663*9880d681SAndroid Build Coastguard Worker %W = trunc <2 x i16> <i16 8, i16 7> to <2 x i8> ; yields <i8 8, i8 7> 7664*9880d681SAndroid Build Coastguard Worker 7665*9880d681SAndroid Build Coastguard Worker'``zext .. to``' Instruction 7666*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 7667*9880d681SAndroid Build Coastguard Worker 7668*9880d681SAndroid Build Coastguard WorkerSyntax: 7669*9880d681SAndroid Build Coastguard Worker""""""" 7670*9880d681SAndroid Build Coastguard Worker 7671*9880d681SAndroid Build Coastguard Worker:: 7672*9880d681SAndroid Build Coastguard Worker 7673*9880d681SAndroid Build Coastguard Worker <result> = zext <ty> <value> to <ty2> ; yields ty2 7674*9880d681SAndroid Build Coastguard Worker 7675*9880d681SAndroid Build Coastguard WorkerOverview: 7676*9880d681SAndroid Build Coastguard Worker""""""""" 7677*9880d681SAndroid Build Coastguard Worker 7678*9880d681SAndroid Build Coastguard WorkerThe '``zext``' instruction zero extends its operand to type ``ty2``. 7679*9880d681SAndroid Build Coastguard Worker 7680*9880d681SAndroid Build Coastguard WorkerArguments: 7681*9880d681SAndroid Build Coastguard Worker"""""""""" 7682*9880d681SAndroid Build Coastguard Worker 7683*9880d681SAndroid Build Coastguard WorkerThe '``zext``' instruction takes a value to cast, and a type to cast it 7684*9880d681SAndroid Build Coastguard Workerto. Both types must be of :ref:`integer <t_integer>` types, or vectors of 7685*9880d681SAndroid Build Coastguard Workerthe same number of integers. The bit size of the ``value`` must be 7686*9880d681SAndroid Build Coastguard Workersmaller than the bit size of the destination type, ``ty2``. 7687*9880d681SAndroid Build Coastguard Worker 7688*9880d681SAndroid Build Coastguard WorkerSemantics: 7689*9880d681SAndroid Build Coastguard Worker"""""""""" 7690*9880d681SAndroid Build Coastguard Worker 7691*9880d681SAndroid Build Coastguard WorkerThe ``zext`` fills the high order bits of the ``value`` with zero bits 7692*9880d681SAndroid Build Coastguard Workeruntil it reaches the size of the destination type, ``ty2``. 7693*9880d681SAndroid Build Coastguard Worker 7694*9880d681SAndroid Build Coastguard WorkerWhen zero extending from i1, the result will always be either 0 or 1. 7695*9880d681SAndroid Build Coastguard Worker 7696*9880d681SAndroid Build Coastguard WorkerExample: 7697*9880d681SAndroid Build Coastguard Worker"""""""" 7698*9880d681SAndroid Build Coastguard Worker 7699*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 7700*9880d681SAndroid Build Coastguard Worker 7701*9880d681SAndroid Build Coastguard Worker %X = zext i32 257 to i64 ; yields i64:257 7702*9880d681SAndroid Build Coastguard Worker %Y = zext i1 true to i32 ; yields i32:1 7703*9880d681SAndroid Build Coastguard Worker %Z = zext <2 x i16> <i16 8, i16 7> to <2 x i32> ; yields <i32 8, i32 7> 7704*9880d681SAndroid Build Coastguard Worker 7705*9880d681SAndroid Build Coastguard Worker'``sext .. to``' Instruction 7706*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 7707*9880d681SAndroid Build Coastguard Worker 7708*9880d681SAndroid Build Coastguard WorkerSyntax: 7709*9880d681SAndroid Build Coastguard Worker""""""" 7710*9880d681SAndroid Build Coastguard Worker 7711*9880d681SAndroid Build Coastguard Worker:: 7712*9880d681SAndroid Build Coastguard Worker 7713*9880d681SAndroid Build Coastguard Worker <result> = sext <ty> <value> to <ty2> ; yields ty2 7714*9880d681SAndroid Build Coastguard Worker 7715*9880d681SAndroid Build Coastguard WorkerOverview: 7716*9880d681SAndroid Build Coastguard Worker""""""""" 7717*9880d681SAndroid Build Coastguard Worker 7718*9880d681SAndroid Build Coastguard WorkerThe '``sext``' sign extends ``value`` to the type ``ty2``. 7719*9880d681SAndroid Build Coastguard Worker 7720*9880d681SAndroid Build Coastguard WorkerArguments: 7721*9880d681SAndroid Build Coastguard Worker"""""""""" 7722*9880d681SAndroid Build Coastguard Worker 7723*9880d681SAndroid Build Coastguard WorkerThe '``sext``' instruction takes a value to cast, and a type to cast it 7724*9880d681SAndroid Build Coastguard Workerto. Both types must be of :ref:`integer <t_integer>` types, or vectors of 7725*9880d681SAndroid Build Coastguard Workerthe same number of integers. The bit size of the ``value`` must be 7726*9880d681SAndroid Build Coastguard Workersmaller than the bit size of the destination type, ``ty2``. 7727*9880d681SAndroid Build Coastguard Worker 7728*9880d681SAndroid Build Coastguard WorkerSemantics: 7729*9880d681SAndroid Build Coastguard Worker"""""""""" 7730*9880d681SAndroid Build Coastguard Worker 7731*9880d681SAndroid Build Coastguard WorkerThe '``sext``' instruction performs a sign extension by copying the sign 7732*9880d681SAndroid Build Coastguard Workerbit (highest order bit) of the ``value`` until it reaches the bit size 7733*9880d681SAndroid Build Coastguard Workerof the type ``ty2``. 7734*9880d681SAndroid Build Coastguard Worker 7735*9880d681SAndroid Build Coastguard WorkerWhen sign extending from i1, the extension always results in -1 or 0. 7736*9880d681SAndroid Build Coastguard Worker 7737*9880d681SAndroid Build Coastguard WorkerExample: 7738*9880d681SAndroid Build Coastguard Worker"""""""" 7739*9880d681SAndroid Build Coastguard Worker 7740*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 7741*9880d681SAndroid Build Coastguard Worker 7742*9880d681SAndroid Build Coastguard Worker %X = sext i8 -1 to i16 ; yields i16 :65535 7743*9880d681SAndroid Build Coastguard Worker %Y = sext i1 true to i32 ; yields i32:-1 7744*9880d681SAndroid Build Coastguard Worker %Z = sext <2 x i16> <i16 8, i16 7> to <2 x i32> ; yields <i32 8, i32 7> 7745*9880d681SAndroid Build Coastguard Worker 7746*9880d681SAndroid Build Coastguard Worker'``fptrunc .. to``' Instruction 7747*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 7748*9880d681SAndroid Build Coastguard Worker 7749*9880d681SAndroid Build Coastguard WorkerSyntax: 7750*9880d681SAndroid Build Coastguard Worker""""""" 7751*9880d681SAndroid Build Coastguard Worker 7752*9880d681SAndroid Build Coastguard Worker:: 7753*9880d681SAndroid Build Coastguard Worker 7754*9880d681SAndroid Build Coastguard Worker <result> = fptrunc <ty> <value> to <ty2> ; yields ty2 7755*9880d681SAndroid Build Coastguard Worker 7756*9880d681SAndroid Build Coastguard WorkerOverview: 7757*9880d681SAndroid Build Coastguard Worker""""""""" 7758*9880d681SAndroid Build Coastguard Worker 7759*9880d681SAndroid Build Coastguard WorkerThe '``fptrunc``' instruction truncates ``value`` to type ``ty2``. 7760*9880d681SAndroid Build Coastguard Worker 7761*9880d681SAndroid Build Coastguard WorkerArguments: 7762*9880d681SAndroid Build Coastguard Worker"""""""""" 7763*9880d681SAndroid Build Coastguard Worker 7764*9880d681SAndroid Build Coastguard WorkerThe '``fptrunc``' instruction takes a :ref:`floating point <t_floating>` 7765*9880d681SAndroid Build Coastguard Workervalue to cast and a :ref:`floating point <t_floating>` type to cast it to. 7766*9880d681SAndroid Build Coastguard WorkerThe size of ``value`` must be larger than the size of ``ty2``. This 7767*9880d681SAndroid Build Coastguard Workerimplies that ``fptrunc`` cannot be used to make a *no-op cast*. 7768*9880d681SAndroid Build Coastguard Worker 7769*9880d681SAndroid Build Coastguard WorkerSemantics: 7770*9880d681SAndroid Build Coastguard Worker"""""""""" 7771*9880d681SAndroid Build Coastguard Worker 7772*9880d681SAndroid Build Coastguard WorkerThe '``fptrunc``' instruction casts a ``value`` from a larger 7773*9880d681SAndroid Build Coastguard Worker:ref:`floating point <t_floating>` type to a smaller :ref:`floating 7774*9880d681SAndroid Build Coastguard Workerpoint <t_floating>` type. If the value cannot fit (i.e. overflows) within the 7775*9880d681SAndroid Build Coastguard Workerdestination type, ``ty2``, then the results are undefined. If the cast produces 7776*9880d681SAndroid Build Coastguard Workeran inexact result, how rounding is performed (e.g. truncation, also known as 7777*9880d681SAndroid Build Coastguard Workerround to zero) is undefined. 7778*9880d681SAndroid Build Coastguard Worker 7779*9880d681SAndroid Build Coastguard WorkerExample: 7780*9880d681SAndroid Build Coastguard Worker"""""""" 7781*9880d681SAndroid Build Coastguard Worker 7782*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 7783*9880d681SAndroid Build Coastguard Worker 7784*9880d681SAndroid Build Coastguard Worker %X = fptrunc double 123.0 to float ; yields float:123.0 7785*9880d681SAndroid Build Coastguard Worker %Y = fptrunc double 1.0E+300 to float ; yields undefined 7786*9880d681SAndroid Build Coastguard Worker 7787*9880d681SAndroid Build Coastguard Worker'``fpext .. to``' Instruction 7788*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 7789*9880d681SAndroid Build Coastguard Worker 7790*9880d681SAndroid Build Coastguard WorkerSyntax: 7791*9880d681SAndroid Build Coastguard Worker""""""" 7792*9880d681SAndroid Build Coastguard Worker 7793*9880d681SAndroid Build Coastguard Worker:: 7794*9880d681SAndroid Build Coastguard Worker 7795*9880d681SAndroid Build Coastguard Worker <result> = fpext <ty> <value> to <ty2> ; yields ty2 7796*9880d681SAndroid Build Coastguard Worker 7797*9880d681SAndroid Build Coastguard WorkerOverview: 7798*9880d681SAndroid Build Coastguard Worker""""""""" 7799*9880d681SAndroid Build Coastguard Worker 7800*9880d681SAndroid Build Coastguard WorkerThe '``fpext``' extends a floating point ``value`` to a larger floating 7801*9880d681SAndroid Build Coastguard Workerpoint value. 7802*9880d681SAndroid Build Coastguard Worker 7803*9880d681SAndroid Build Coastguard WorkerArguments: 7804*9880d681SAndroid Build Coastguard Worker"""""""""" 7805*9880d681SAndroid Build Coastguard Worker 7806*9880d681SAndroid Build Coastguard WorkerThe '``fpext``' instruction takes a :ref:`floating point <t_floating>` 7807*9880d681SAndroid Build Coastguard Worker``value`` to cast, and a :ref:`floating point <t_floating>` type to cast it 7808*9880d681SAndroid Build Coastguard Workerto. The source type must be smaller than the destination type. 7809*9880d681SAndroid Build Coastguard Worker 7810*9880d681SAndroid Build Coastguard WorkerSemantics: 7811*9880d681SAndroid Build Coastguard Worker"""""""""" 7812*9880d681SAndroid Build Coastguard Worker 7813*9880d681SAndroid Build Coastguard WorkerThe '``fpext``' instruction extends the ``value`` from a smaller 7814*9880d681SAndroid Build Coastguard Worker:ref:`floating point <t_floating>` type to a larger :ref:`floating 7815*9880d681SAndroid Build Coastguard Workerpoint <t_floating>` type. The ``fpext`` cannot be used to make a 7816*9880d681SAndroid Build Coastguard Worker*no-op cast* because it always changes bits. Use ``bitcast`` to make a 7817*9880d681SAndroid Build Coastguard Worker*no-op cast* for a floating point cast. 7818*9880d681SAndroid Build Coastguard Worker 7819*9880d681SAndroid Build Coastguard WorkerExample: 7820*9880d681SAndroid Build Coastguard Worker"""""""" 7821*9880d681SAndroid Build Coastguard Worker 7822*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 7823*9880d681SAndroid Build Coastguard Worker 7824*9880d681SAndroid Build Coastguard Worker %X = fpext float 3.125 to double ; yields double:3.125000e+00 7825*9880d681SAndroid Build Coastguard Worker %Y = fpext double %X to fp128 ; yields fp128:0xL00000000000000004000900000000000 7826*9880d681SAndroid Build Coastguard Worker 7827*9880d681SAndroid Build Coastguard Worker'``fptoui .. to``' Instruction 7828*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 7829*9880d681SAndroid Build Coastguard Worker 7830*9880d681SAndroid Build Coastguard WorkerSyntax: 7831*9880d681SAndroid Build Coastguard Worker""""""" 7832*9880d681SAndroid Build Coastguard Worker 7833*9880d681SAndroid Build Coastguard Worker:: 7834*9880d681SAndroid Build Coastguard Worker 7835*9880d681SAndroid Build Coastguard Worker <result> = fptoui <ty> <value> to <ty2> ; yields ty2 7836*9880d681SAndroid Build Coastguard Worker 7837*9880d681SAndroid Build Coastguard WorkerOverview: 7838*9880d681SAndroid Build Coastguard Worker""""""""" 7839*9880d681SAndroid Build Coastguard Worker 7840*9880d681SAndroid Build Coastguard WorkerThe '``fptoui``' converts a floating point ``value`` to its unsigned 7841*9880d681SAndroid Build Coastguard Workerinteger equivalent of type ``ty2``. 7842*9880d681SAndroid Build Coastguard Worker 7843*9880d681SAndroid Build Coastguard WorkerArguments: 7844*9880d681SAndroid Build Coastguard Worker"""""""""" 7845*9880d681SAndroid Build Coastguard Worker 7846*9880d681SAndroid Build Coastguard WorkerThe '``fptoui``' instruction takes a value to cast, which must be a 7847*9880d681SAndroid Build Coastguard Workerscalar or vector :ref:`floating point <t_floating>` value, and a type to 7848*9880d681SAndroid Build Coastguard Workercast it to ``ty2``, which must be an :ref:`integer <t_integer>` type. If 7849*9880d681SAndroid Build Coastguard Worker``ty`` is a vector floating point type, ``ty2`` must be a vector integer 7850*9880d681SAndroid Build Coastguard Workertype with the same number of elements as ``ty`` 7851*9880d681SAndroid Build Coastguard Worker 7852*9880d681SAndroid Build Coastguard WorkerSemantics: 7853*9880d681SAndroid Build Coastguard Worker"""""""""" 7854*9880d681SAndroid Build Coastguard Worker 7855*9880d681SAndroid Build Coastguard WorkerThe '``fptoui``' instruction converts its :ref:`floating 7856*9880d681SAndroid Build Coastguard Workerpoint <t_floating>` operand into the nearest (rounding towards zero) 7857*9880d681SAndroid Build Coastguard Workerunsigned integer value. If the value cannot fit in ``ty2``, the results 7858*9880d681SAndroid Build Coastguard Workerare undefined. 7859*9880d681SAndroid Build Coastguard Worker 7860*9880d681SAndroid Build Coastguard WorkerExample: 7861*9880d681SAndroid Build Coastguard Worker"""""""" 7862*9880d681SAndroid Build Coastguard Worker 7863*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 7864*9880d681SAndroid Build Coastguard Worker 7865*9880d681SAndroid Build Coastguard Worker %X = fptoui double 123.0 to i32 ; yields i32:123 7866*9880d681SAndroid Build Coastguard Worker %Y = fptoui float 1.0E+300 to i1 ; yields undefined:1 7867*9880d681SAndroid Build Coastguard Worker %Z = fptoui float 1.04E+17 to i8 ; yields undefined:1 7868*9880d681SAndroid Build Coastguard Worker 7869*9880d681SAndroid Build Coastguard Worker'``fptosi .. to``' Instruction 7870*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 7871*9880d681SAndroid Build Coastguard Worker 7872*9880d681SAndroid Build Coastguard WorkerSyntax: 7873*9880d681SAndroid Build Coastguard Worker""""""" 7874*9880d681SAndroid Build Coastguard Worker 7875*9880d681SAndroid Build Coastguard Worker:: 7876*9880d681SAndroid Build Coastguard Worker 7877*9880d681SAndroid Build Coastguard Worker <result> = fptosi <ty> <value> to <ty2> ; yields ty2 7878*9880d681SAndroid Build Coastguard Worker 7879*9880d681SAndroid Build Coastguard WorkerOverview: 7880*9880d681SAndroid Build Coastguard Worker""""""""" 7881*9880d681SAndroid Build Coastguard Worker 7882*9880d681SAndroid Build Coastguard WorkerThe '``fptosi``' instruction converts :ref:`floating point <t_floating>` 7883*9880d681SAndroid Build Coastguard Worker``value`` to type ``ty2``. 7884*9880d681SAndroid Build Coastguard Worker 7885*9880d681SAndroid Build Coastguard WorkerArguments: 7886*9880d681SAndroid Build Coastguard Worker"""""""""" 7887*9880d681SAndroid Build Coastguard Worker 7888*9880d681SAndroid Build Coastguard WorkerThe '``fptosi``' instruction takes a value to cast, which must be a 7889*9880d681SAndroid Build Coastguard Workerscalar or vector :ref:`floating point <t_floating>` value, and a type to 7890*9880d681SAndroid Build Coastguard Workercast it to ``ty2``, which must be an :ref:`integer <t_integer>` type. If 7891*9880d681SAndroid Build Coastguard Worker``ty`` is a vector floating point type, ``ty2`` must be a vector integer 7892*9880d681SAndroid Build Coastguard Workertype with the same number of elements as ``ty`` 7893*9880d681SAndroid Build Coastguard Worker 7894*9880d681SAndroid Build Coastguard WorkerSemantics: 7895*9880d681SAndroid Build Coastguard Worker"""""""""" 7896*9880d681SAndroid Build Coastguard Worker 7897*9880d681SAndroid Build Coastguard WorkerThe '``fptosi``' instruction converts its :ref:`floating 7898*9880d681SAndroid Build Coastguard Workerpoint <t_floating>` operand into the nearest (rounding towards zero) 7899*9880d681SAndroid Build Coastguard Workersigned integer value. If the value cannot fit in ``ty2``, the results 7900*9880d681SAndroid Build Coastguard Workerare undefined. 7901*9880d681SAndroid Build Coastguard Worker 7902*9880d681SAndroid Build Coastguard WorkerExample: 7903*9880d681SAndroid Build Coastguard Worker"""""""" 7904*9880d681SAndroid Build Coastguard Worker 7905*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 7906*9880d681SAndroid Build Coastguard Worker 7907*9880d681SAndroid Build Coastguard Worker %X = fptosi double -123.0 to i32 ; yields i32:-123 7908*9880d681SAndroid Build Coastguard Worker %Y = fptosi float 1.0E-247 to i1 ; yields undefined:1 7909*9880d681SAndroid Build Coastguard Worker %Z = fptosi float 1.04E+17 to i8 ; yields undefined:1 7910*9880d681SAndroid Build Coastguard Worker 7911*9880d681SAndroid Build Coastguard Worker'``uitofp .. to``' Instruction 7912*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 7913*9880d681SAndroid Build Coastguard Worker 7914*9880d681SAndroid Build Coastguard WorkerSyntax: 7915*9880d681SAndroid Build Coastguard Worker""""""" 7916*9880d681SAndroid Build Coastguard Worker 7917*9880d681SAndroid Build Coastguard Worker:: 7918*9880d681SAndroid Build Coastguard Worker 7919*9880d681SAndroid Build Coastguard Worker <result> = uitofp <ty> <value> to <ty2> ; yields ty2 7920*9880d681SAndroid Build Coastguard Worker 7921*9880d681SAndroid Build Coastguard WorkerOverview: 7922*9880d681SAndroid Build Coastguard Worker""""""""" 7923*9880d681SAndroid Build Coastguard Worker 7924*9880d681SAndroid Build Coastguard WorkerThe '``uitofp``' instruction regards ``value`` as an unsigned integer 7925*9880d681SAndroid Build Coastguard Workerand converts that value to the ``ty2`` type. 7926*9880d681SAndroid Build Coastguard Worker 7927*9880d681SAndroid Build Coastguard WorkerArguments: 7928*9880d681SAndroid Build Coastguard Worker"""""""""" 7929*9880d681SAndroid Build Coastguard Worker 7930*9880d681SAndroid Build Coastguard WorkerThe '``uitofp``' instruction takes a value to cast, which must be a 7931*9880d681SAndroid Build Coastguard Workerscalar or vector :ref:`integer <t_integer>` value, and a type to cast it to 7932*9880d681SAndroid Build Coastguard Worker``ty2``, which must be an :ref:`floating point <t_floating>` type. If 7933*9880d681SAndroid Build Coastguard Worker``ty`` is a vector integer type, ``ty2`` must be a vector floating point 7934*9880d681SAndroid Build Coastguard Workertype with the same number of elements as ``ty`` 7935*9880d681SAndroid Build Coastguard Worker 7936*9880d681SAndroid Build Coastguard WorkerSemantics: 7937*9880d681SAndroid Build Coastguard Worker"""""""""" 7938*9880d681SAndroid Build Coastguard Worker 7939*9880d681SAndroid Build Coastguard WorkerThe '``uitofp``' instruction interprets its operand as an unsigned 7940*9880d681SAndroid Build Coastguard Workerinteger quantity and converts it to the corresponding floating point 7941*9880d681SAndroid Build Coastguard Workervalue. If the value cannot fit in the floating point value, the results 7942*9880d681SAndroid Build Coastguard Workerare undefined. 7943*9880d681SAndroid Build Coastguard Worker 7944*9880d681SAndroid Build Coastguard WorkerExample: 7945*9880d681SAndroid Build Coastguard Worker"""""""" 7946*9880d681SAndroid Build Coastguard Worker 7947*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 7948*9880d681SAndroid Build Coastguard Worker 7949*9880d681SAndroid Build Coastguard Worker %X = uitofp i32 257 to float ; yields float:257.0 7950*9880d681SAndroid Build Coastguard Worker %Y = uitofp i8 -1 to double ; yields double:255.0 7951*9880d681SAndroid Build Coastguard Worker 7952*9880d681SAndroid Build Coastguard Worker'``sitofp .. to``' Instruction 7953*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 7954*9880d681SAndroid Build Coastguard Worker 7955*9880d681SAndroid Build Coastguard WorkerSyntax: 7956*9880d681SAndroid Build Coastguard Worker""""""" 7957*9880d681SAndroid Build Coastguard Worker 7958*9880d681SAndroid Build Coastguard Worker:: 7959*9880d681SAndroid Build Coastguard Worker 7960*9880d681SAndroid Build Coastguard Worker <result> = sitofp <ty> <value> to <ty2> ; yields ty2 7961*9880d681SAndroid Build Coastguard Worker 7962*9880d681SAndroid Build Coastguard WorkerOverview: 7963*9880d681SAndroid Build Coastguard Worker""""""""" 7964*9880d681SAndroid Build Coastguard Worker 7965*9880d681SAndroid Build Coastguard WorkerThe '``sitofp``' instruction regards ``value`` as a signed integer and 7966*9880d681SAndroid Build Coastguard Workerconverts that value to the ``ty2`` type. 7967*9880d681SAndroid Build Coastguard Worker 7968*9880d681SAndroid Build Coastguard WorkerArguments: 7969*9880d681SAndroid Build Coastguard Worker"""""""""" 7970*9880d681SAndroid Build Coastguard Worker 7971*9880d681SAndroid Build Coastguard WorkerThe '``sitofp``' instruction takes a value to cast, which must be a 7972*9880d681SAndroid Build Coastguard Workerscalar or vector :ref:`integer <t_integer>` value, and a type to cast it to 7973*9880d681SAndroid Build Coastguard Worker``ty2``, which must be an :ref:`floating point <t_floating>` type. If 7974*9880d681SAndroid Build Coastguard Worker``ty`` is a vector integer type, ``ty2`` must be a vector floating point 7975*9880d681SAndroid Build Coastguard Workertype with the same number of elements as ``ty`` 7976*9880d681SAndroid Build Coastguard Worker 7977*9880d681SAndroid Build Coastguard WorkerSemantics: 7978*9880d681SAndroid Build Coastguard Worker"""""""""" 7979*9880d681SAndroid Build Coastguard Worker 7980*9880d681SAndroid Build Coastguard WorkerThe '``sitofp``' instruction interprets its operand as a signed integer 7981*9880d681SAndroid Build Coastguard Workerquantity and converts it to the corresponding floating point value. If 7982*9880d681SAndroid Build Coastguard Workerthe value cannot fit in the floating point value, the results are 7983*9880d681SAndroid Build Coastguard Workerundefined. 7984*9880d681SAndroid Build Coastguard Worker 7985*9880d681SAndroid Build Coastguard WorkerExample: 7986*9880d681SAndroid Build Coastguard Worker"""""""" 7987*9880d681SAndroid Build Coastguard Worker 7988*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 7989*9880d681SAndroid Build Coastguard Worker 7990*9880d681SAndroid Build Coastguard Worker %X = sitofp i32 257 to float ; yields float:257.0 7991*9880d681SAndroid Build Coastguard Worker %Y = sitofp i8 -1 to double ; yields double:-1.0 7992*9880d681SAndroid Build Coastguard Worker 7993*9880d681SAndroid Build Coastguard Worker.. _i_ptrtoint: 7994*9880d681SAndroid Build Coastguard Worker 7995*9880d681SAndroid Build Coastguard Worker'``ptrtoint .. to``' Instruction 7996*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 7997*9880d681SAndroid Build Coastguard Worker 7998*9880d681SAndroid Build Coastguard WorkerSyntax: 7999*9880d681SAndroid Build Coastguard Worker""""""" 8000*9880d681SAndroid Build Coastguard Worker 8001*9880d681SAndroid Build Coastguard Worker:: 8002*9880d681SAndroid Build Coastguard Worker 8003*9880d681SAndroid Build Coastguard Worker <result> = ptrtoint <ty> <value> to <ty2> ; yields ty2 8004*9880d681SAndroid Build Coastguard Worker 8005*9880d681SAndroid Build Coastguard WorkerOverview: 8006*9880d681SAndroid Build Coastguard Worker""""""""" 8007*9880d681SAndroid Build Coastguard Worker 8008*9880d681SAndroid Build Coastguard WorkerThe '``ptrtoint``' instruction converts the pointer or a vector of 8009*9880d681SAndroid Build Coastguard Workerpointers ``value`` to the integer (or vector of integers) type ``ty2``. 8010*9880d681SAndroid Build Coastguard Worker 8011*9880d681SAndroid Build Coastguard WorkerArguments: 8012*9880d681SAndroid Build Coastguard Worker"""""""""" 8013*9880d681SAndroid Build Coastguard Worker 8014*9880d681SAndroid Build Coastguard WorkerThe '``ptrtoint``' instruction takes a ``value`` to cast, which must be 8015*9880d681SAndroid Build Coastguard Workera value of type :ref:`pointer <t_pointer>` or a vector of pointers, and a 8016*9880d681SAndroid Build Coastguard Workertype to cast it to ``ty2``, which must be an :ref:`integer <t_integer>` or 8017*9880d681SAndroid Build Coastguard Workera vector of integers type. 8018*9880d681SAndroid Build Coastguard Worker 8019*9880d681SAndroid Build Coastguard WorkerSemantics: 8020*9880d681SAndroid Build Coastguard Worker"""""""""" 8021*9880d681SAndroid Build Coastguard Worker 8022*9880d681SAndroid Build Coastguard WorkerThe '``ptrtoint``' instruction converts ``value`` to integer type 8023*9880d681SAndroid Build Coastguard Worker``ty2`` by interpreting the pointer value as an integer and either 8024*9880d681SAndroid Build Coastguard Workertruncating or zero extending that value to the size of the integer type. 8025*9880d681SAndroid Build Coastguard WorkerIf ``value`` is smaller than ``ty2`` then a zero extension is done. If 8026*9880d681SAndroid Build Coastguard Worker``value`` is larger than ``ty2`` then a truncation is done. If they are 8027*9880d681SAndroid Build Coastguard Workerthe same size, then nothing is done (*no-op cast*) other than a type 8028*9880d681SAndroid Build Coastguard Workerchange. 8029*9880d681SAndroid Build Coastguard Worker 8030*9880d681SAndroid Build Coastguard WorkerExample: 8031*9880d681SAndroid Build Coastguard Worker"""""""" 8032*9880d681SAndroid Build Coastguard Worker 8033*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 8034*9880d681SAndroid Build Coastguard Worker 8035*9880d681SAndroid Build Coastguard Worker %X = ptrtoint i32* %P to i8 ; yields truncation on 32-bit architecture 8036*9880d681SAndroid Build Coastguard Worker %Y = ptrtoint i32* %P to i64 ; yields zero extension on 32-bit architecture 8037*9880d681SAndroid Build Coastguard Worker %Z = ptrtoint <4 x i32*> %P to <4 x i64>; yields vector zero extension for a vector of addresses on 32-bit architecture 8038*9880d681SAndroid Build Coastguard Worker 8039*9880d681SAndroid Build Coastguard Worker.. _i_inttoptr: 8040*9880d681SAndroid Build Coastguard Worker 8041*9880d681SAndroid Build Coastguard Worker'``inttoptr .. to``' Instruction 8042*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 8043*9880d681SAndroid Build Coastguard Worker 8044*9880d681SAndroid Build Coastguard WorkerSyntax: 8045*9880d681SAndroid Build Coastguard Worker""""""" 8046*9880d681SAndroid Build Coastguard Worker 8047*9880d681SAndroid Build Coastguard Worker:: 8048*9880d681SAndroid Build Coastguard Worker 8049*9880d681SAndroid Build Coastguard Worker <result> = inttoptr <ty> <value> to <ty2> ; yields ty2 8050*9880d681SAndroid Build Coastguard Worker 8051*9880d681SAndroid Build Coastguard WorkerOverview: 8052*9880d681SAndroid Build Coastguard Worker""""""""" 8053*9880d681SAndroid Build Coastguard Worker 8054*9880d681SAndroid Build Coastguard WorkerThe '``inttoptr``' instruction converts an integer ``value`` to a 8055*9880d681SAndroid Build Coastguard Workerpointer type, ``ty2``. 8056*9880d681SAndroid Build Coastguard Worker 8057*9880d681SAndroid Build Coastguard WorkerArguments: 8058*9880d681SAndroid Build Coastguard Worker"""""""""" 8059*9880d681SAndroid Build Coastguard Worker 8060*9880d681SAndroid Build Coastguard WorkerThe '``inttoptr``' instruction takes an :ref:`integer <t_integer>` value to 8061*9880d681SAndroid Build Coastguard Workercast, and a type to cast it to, which must be a :ref:`pointer <t_pointer>` 8062*9880d681SAndroid Build Coastguard Workertype. 8063*9880d681SAndroid Build Coastguard Worker 8064*9880d681SAndroid Build Coastguard WorkerSemantics: 8065*9880d681SAndroid Build Coastguard Worker"""""""""" 8066*9880d681SAndroid Build Coastguard Worker 8067*9880d681SAndroid Build Coastguard WorkerThe '``inttoptr``' instruction converts ``value`` to type ``ty2`` by 8068*9880d681SAndroid Build Coastguard Workerapplying either a zero extension or a truncation depending on the size 8069*9880d681SAndroid Build Coastguard Workerof the integer ``value``. If ``value`` is larger than the size of a 8070*9880d681SAndroid Build Coastguard Workerpointer then a truncation is done. If ``value`` is smaller than the size 8071*9880d681SAndroid Build Coastguard Workerof a pointer then a zero extension is done. If they are the same size, 8072*9880d681SAndroid Build Coastguard Workernothing is done (*no-op cast*). 8073*9880d681SAndroid Build Coastguard Worker 8074*9880d681SAndroid Build Coastguard WorkerExample: 8075*9880d681SAndroid Build Coastguard Worker"""""""" 8076*9880d681SAndroid Build Coastguard Worker 8077*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 8078*9880d681SAndroid Build Coastguard Worker 8079*9880d681SAndroid Build Coastguard Worker %X = inttoptr i32 255 to i32* ; yields zero extension on 64-bit architecture 8080*9880d681SAndroid Build Coastguard Worker %Y = inttoptr i32 255 to i32* ; yields no-op on 32-bit architecture 8081*9880d681SAndroid Build Coastguard Worker %Z = inttoptr i64 0 to i32* ; yields truncation on 32-bit architecture 8082*9880d681SAndroid Build Coastguard Worker %Z = inttoptr <4 x i32> %G to <4 x i8*>; yields truncation of vector G to four pointers 8083*9880d681SAndroid Build Coastguard Worker 8084*9880d681SAndroid Build Coastguard Worker.. _i_bitcast: 8085*9880d681SAndroid Build Coastguard Worker 8086*9880d681SAndroid Build Coastguard Worker'``bitcast .. to``' Instruction 8087*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 8088*9880d681SAndroid Build Coastguard Worker 8089*9880d681SAndroid Build Coastguard WorkerSyntax: 8090*9880d681SAndroid Build Coastguard Worker""""""" 8091*9880d681SAndroid Build Coastguard Worker 8092*9880d681SAndroid Build Coastguard Worker:: 8093*9880d681SAndroid Build Coastguard Worker 8094*9880d681SAndroid Build Coastguard Worker <result> = bitcast <ty> <value> to <ty2> ; yields ty2 8095*9880d681SAndroid Build Coastguard Worker 8096*9880d681SAndroid Build Coastguard WorkerOverview: 8097*9880d681SAndroid Build Coastguard Worker""""""""" 8098*9880d681SAndroid Build Coastguard Worker 8099*9880d681SAndroid Build Coastguard WorkerThe '``bitcast``' instruction converts ``value`` to type ``ty2`` without 8100*9880d681SAndroid Build Coastguard Workerchanging any bits. 8101*9880d681SAndroid Build Coastguard Worker 8102*9880d681SAndroid Build Coastguard WorkerArguments: 8103*9880d681SAndroid Build Coastguard Worker"""""""""" 8104*9880d681SAndroid Build Coastguard Worker 8105*9880d681SAndroid Build Coastguard WorkerThe '``bitcast``' instruction takes a value to cast, which must be a 8106*9880d681SAndroid Build Coastguard Workernon-aggregate first class value, and a type to cast it to, which must 8107*9880d681SAndroid Build Coastguard Workeralso be a non-aggregate :ref:`first class <t_firstclass>` type. The 8108*9880d681SAndroid Build Coastguard Workerbit sizes of ``value`` and the destination type, ``ty2``, must be 8109*9880d681SAndroid Build Coastguard Workeridentical. If the source type is a pointer, the destination type must 8110*9880d681SAndroid Build Coastguard Workeralso be a pointer of the same size. This instruction supports bitwise 8111*9880d681SAndroid Build Coastguard Workerconversion of vectors to integers and to vectors of other types (as 8112*9880d681SAndroid Build Coastguard Workerlong as they have the same size). 8113*9880d681SAndroid Build Coastguard Worker 8114*9880d681SAndroid Build Coastguard WorkerSemantics: 8115*9880d681SAndroid Build Coastguard Worker"""""""""" 8116*9880d681SAndroid Build Coastguard Worker 8117*9880d681SAndroid Build Coastguard WorkerThe '``bitcast``' instruction converts ``value`` to type ``ty2``. It 8118*9880d681SAndroid Build Coastguard Workeris always a *no-op cast* because no bits change with this 8119*9880d681SAndroid Build Coastguard Workerconversion. The conversion is done as if the ``value`` had been stored 8120*9880d681SAndroid Build Coastguard Workerto memory and read back as type ``ty2``. Pointer (or vector of 8121*9880d681SAndroid Build Coastguard Workerpointers) types may only be converted to other pointer (or vector of 8122*9880d681SAndroid Build Coastguard Workerpointers) types with the same address space through this instruction. 8123*9880d681SAndroid Build Coastguard WorkerTo convert pointers to other types, use the :ref:`inttoptr <i_inttoptr>` 8124*9880d681SAndroid Build Coastguard Workeror :ref:`ptrtoint <i_ptrtoint>` instructions first. 8125*9880d681SAndroid Build Coastguard Worker 8126*9880d681SAndroid Build Coastguard WorkerExample: 8127*9880d681SAndroid Build Coastguard Worker"""""""" 8128*9880d681SAndroid Build Coastguard Worker 8129*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 8130*9880d681SAndroid Build Coastguard Worker 8131*9880d681SAndroid Build Coastguard Worker %X = bitcast i8 255 to i8 ; yields i8 :-1 8132*9880d681SAndroid Build Coastguard Worker %Y = bitcast i32* %x to sint* ; yields sint*:%x 8133*9880d681SAndroid Build Coastguard Worker %Z = bitcast <2 x int> %V to i64; ; yields i64: %V 8134*9880d681SAndroid Build Coastguard Worker %Z = bitcast <2 x i32*> %V to <2 x i64*> ; yields <2 x i64*> 8135*9880d681SAndroid Build Coastguard Worker 8136*9880d681SAndroid Build Coastguard Worker.. _i_addrspacecast: 8137*9880d681SAndroid Build Coastguard Worker 8138*9880d681SAndroid Build Coastguard Worker'``addrspacecast .. to``' Instruction 8139*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 8140*9880d681SAndroid Build Coastguard Worker 8141*9880d681SAndroid Build Coastguard WorkerSyntax: 8142*9880d681SAndroid Build Coastguard Worker""""""" 8143*9880d681SAndroid Build Coastguard Worker 8144*9880d681SAndroid Build Coastguard Worker:: 8145*9880d681SAndroid Build Coastguard Worker 8146*9880d681SAndroid Build Coastguard Worker <result> = addrspacecast <pty> <ptrval> to <pty2> ; yields pty2 8147*9880d681SAndroid Build Coastguard Worker 8148*9880d681SAndroid Build Coastguard WorkerOverview: 8149*9880d681SAndroid Build Coastguard Worker""""""""" 8150*9880d681SAndroid Build Coastguard Worker 8151*9880d681SAndroid Build Coastguard WorkerThe '``addrspacecast``' instruction converts ``ptrval`` from ``pty`` in 8152*9880d681SAndroid Build Coastguard Workeraddress space ``n`` to type ``pty2`` in address space ``m``. 8153*9880d681SAndroid Build Coastguard Worker 8154*9880d681SAndroid Build Coastguard WorkerArguments: 8155*9880d681SAndroid Build Coastguard Worker"""""""""" 8156*9880d681SAndroid Build Coastguard Worker 8157*9880d681SAndroid Build Coastguard WorkerThe '``addrspacecast``' instruction takes a pointer or vector of pointer value 8158*9880d681SAndroid Build Coastguard Workerto cast and a pointer type to cast it to, which must have a different 8159*9880d681SAndroid Build Coastguard Workeraddress space. 8160*9880d681SAndroid Build Coastguard Worker 8161*9880d681SAndroid Build Coastguard WorkerSemantics: 8162*9880d681SAndroid Build Coastguard Worker"""""""""" 8163*9880d681SAndroid Build Coastguard Worker 8164*9880d681SAndroid Build Coastguard WorkerThe '``addrspacecast``' instruction converts the pointer value 8165*9880d681SAndroid Build Coastguard Worker``ptrval`` to type ``pty2``. It can be a *no-op cast* or a complex 8166*9880d681SAndroid Build Coastguard Workervalue modification, depending on the target and the address space 8167*9880d681SAndroid Build Coastguard Workerpair. Pointer conversions within the same address space must be 8168*9880d681SAndroid Build Coastguard Workerperformed with the ``bitcast`` instruction. Note that if the address space 8169*9880d681SAndroid Build Coastguard Workerconversion is legal then both result and operand refer to the same memory 8170*9880d681SAndroid Build Coastguard Workerlocation. 8171*9880d681SAndroid Build Coastguard Worker 8172*9880d681SAndroid Build Coastguard WorkerExample: 8173*9880d681SAndroid Build Coastguard Worker"""""""" 8174*9880d681SAndroid Build Coastguard Worker 8175*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 8176*9880d681SAndroid Build Coastguard Worker 8177*9880d681SAndroid Build Coastguard Worker %X = addrspacecast i32* %x to i32 addrspace(1)* ; yields i32 addrspace(1)*:%x 8178*9880d681SAndroid Build Coastguard Worker %Y = addrspacecast i32 addrspace(1)* %y to i64 addrspace(2)* ; yields i64 addrspace(2)*:%y 8179*9880d681SAndroid Build Coastguard Worker %Z = addrspacecast <4 x i32*> %z to <4 x float addrspace(3)*> ; yields <4 x float addrspace(3)*>:%z 8180*9880d681SAndroid Build Coastguard Worker 8181*9880d681SAndroid Build Coastguard Worker.. _otherops: 8182*9880d681SAndroid Build Coastguard Worker 8183*9880d681SAndroid Build Coastguard WorkerOther Operations 8184*9880d681SAndroid Build Coastguard Worker---------------- 8185*9880d681SAndroid Build Coastguard Worker 8186*9880d681SAndroid Build Coastguard WorkerThe instructions in this category are the "miscellaneous" instructions, 8187*9880d681SAndroid Build Coastguard Workerwhich defy better classification. 8188*9880d681SAndroid Build Coastguard Worker 8189*9880d681SAndroid Build Coastguard Worker.. _i_icmp: 8190*9880d681SAndroid Build Coastguard Worker 8191*9880d681SAndroid Build Coastguard Worker'``icmp``' Instruction 8192*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^ 8193*9880d681SAndroid Build Coastguard Worker 8194*9880d681SAndroid Build Coastguard WorkerSyntax: 8195*9880d681SAndroid Build Coastguard Worker""""""" 8196*9880d681SAndroid Build Coastguard Worker 8197*9880d681SAndroid Build Coastguard Worker:: 8198*9880d681SAndroid Build Coastguard Worker 8199*9880d681SAndroid Build Coastguard Worker <result> = icmp <cond> <ty> <op1>, <op2> ; yields i1 or <N x i1>:result 8200*9880d681SAndroid Build Coastguard Worker 8201*9880d681SAndroid Build Coastguard WorkerOverview: 8202*9880d681SAndroid Build Coastguard Worker""""""""" 8203*9880d681SAndroid Build Coastguard Worker 8204*9880d681SAndroid Build Coastguard WorkerThe '``icmp``' instruction returns a boolean value or a vector of 8205*9880d681SAndroid Build Coastguard Workerboolean values based on comparison of its two integer, integer vector, 8206*9880d681SAndroid Build Coastguard Workerpointer, or pointer vector operands. 8207*9880d681SAndroid Build Coastguard Worker 8208*9880d681SAndroid Build Coastguard WorkerArguments: 8209*9880d681SAndroid Build Coastguard Worker"""""""""" 8210*9880d681SAndroid Build Coastguard Worker 8211*9880d681SAndroid Build Coastguard WorkerThe '``icmp``' instruction takes three operands. The first operand is 8212*9880d681SAndroid Build Coastguard Workerthe condition code indicating the kind of comparison to perform. It is 8213*9880d681SAndroid Build Coastguard Workernot a value, just a keyword. The possible condition codes are: 8214*9880d681SAndroid Build Coastguard Worker 8215*9880d681SAndroid Build Coastguard Worker#. ``eq``: equal 8216*9880d681SAndroid Build Coastguard Worker#. ``ne``: not equal 8217*9880d681SAndroid Build Coastguard Worker#. ``ugt``: unsigned greater than 8218*9880d681SAndroid Build Coastguard Worker#. ``uge``: unsigned greater or equal 8219*9880d681SAndroid Build Coastguard Worker#. ``ult``: unsigned less than 8220*9880d681SAndroid Build Coastguard Worker#. ``ule``: unsigned less or equal 8221*9880d681SAndroid Build Coastguard Worker#. ``sgt``: signed greater than 8222*9880d681SAndroid Build Coastguard Worker#. ``sge``: signed greater or equal 8223*9880d681SAndroid Build Coastguard Worker#. ``slt``: signed less than 8224*9880d681SAndroid Build Coastguard Worker#. ``sle``: signed less or equal 8225*9880d681SAndroid Build Coastguard Worker 8226*9880d681SAndroid Build Coastguard WorkerThe remaining two arguments must be :ref:`integer <t_integer>` or 8227*9880d681SAndroid Build Coastguard Worker:ref:`pointer <t_pointer>` or integer :ref:`vector <t_vector>` typed. They 8228*9880d681SAndroid Build Coastguard Workermust also be identical types. 8229*9880d681SAndroid Build Coastguard Worker 8230*9880d681SAndroid Build Coastguard WorkerSemantics: 8231*9880d681SAndroid Build Coastguard Worker"""""""""" 8232*9880d681SAndroid Build Coastguard Worker 8233*9880d681SAndroid Build Coastguard WorkerThe '``icmp``' compares ``op1`` and ``op2`` according to the condition 8234*9880d681SAndroid Build Coastguard Workercode given as ``cond``. The comparison performed always yields either an 8235*9880d681SAndroid Build Coastguard Worker:ref:`i1 <t_integer>` or vector of ``i1`` result, as follows: 8236*9880d681SAndroid Build Coastguard Worker 8237*9880d681SAndroid Build Coastguard Worker#. ``eq``: yields ``true`` if the operands are equal, ``false`` 8238*9880d681SAndroid Build Coastguard Worker otherwise. No sign interpretation is necessary or performed. 8239*9880d681SAndroid Build Coastguard Worker#. ``ne``: yields ``true`` if the operands are unequal, ``false`` 8240*9880d681SAndroid Build Coastguard Worker otherwise. No sign interpretation is necessary or performed. 8241*9880d681SAndroid Build Coastguard Worker#. ``ugt``: interprets the operands as unsigned values and yields 8242*9880d681SAndroid Build Coastguard Worker ``true`` if ``op1`` is greater than ``op2``. 8243*9880d681SAndroid Build Coastguard Worker#. ``uge``: interprets the operands as unsigned values and yields 8244*9880d681SAndroid Build Coastguard Worker ``true`` if ``op1`` is greater than or equal to ``op2``. 8245*9880d681SAndroid Build Coastguard Worker#. ``ult``: interprets the operands as unsigned values and yields 8246*9880d681SAndroid Build Coastguard Worker ``true`` if ``op1`` is less than ``op2``. 8247*9880d681SAndroid Build Coastguard Worker#. ``ule``: interprets the operands as unsigned values and yields 8248*9880d681SAndroid Build Coastguard Worker ``true`` if ``op1`` is less than or equal to ``op2``. 8249*9880d681SAndroid Build Coastguard Worker#. ``sgt``: interprets the operands as signed values and yields ``true`` 8250*9880d681SAndroid Build Coastguard Worker if ``op1`` is greater than ``op2``. 8251*9880d681SAndroid Build Coastguard Worker#. ``sge``: interprets the operands as signed values and yields ``true`` 8252*9880d681SAndroid Build Coastguard Worker if ``op1`` is greater than or equal to ``op2``. 8253*9880d681SAndroid Build Coastguard Worker#. ``slt``: interprets the operands as signed values and yields ``true`` 8254*9880d681SAndroid Build Coastguard Worker if ``op1`` is less than ``op2``. 8255*9880d681SAndroid Build Coastguard Worker#. ``sle``: interprets the operands as signed values and yields ``true`` 8256*9880d681SAndroid Build Coastguard Worker if ``op1`` is less than or equal to ``op2``. 8257*9880d681SAndroid Build Coastguard Worker 8258*9880d681SAndroid Build Coastguard WorkerIf the operands are :ref:`pointer <t_pointer>` typed, the pointer values 8259*9880d681SAndroid Build Coastguard Workerare compared as if they were integers. 8260*9880d681SAndroid Build Coastguard Worker 8261*9880d681SAndroid Build Coastguard WorkerIf the operands are integer vectors, then they are compared element by 8262*9880d681SAndroid Build Coastguard Workerelement. The result is an ``i1`` vector with the same number of elements 8263*9880d681SAndroid Build Coastguard Workeras the values being compared. Otherwise, the result is an ``i1``. 8264*9880d681SAndroid Build Coastguard Worker 8265*9880d681SAndroid Build Coastguard WorkerExample: 8266*9880d681SAndroid Build Coastguard Worker"""""""" 8267*9880d681SAndroid Build Coastguard Worker 8268*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 8269*9880d681SAndroid Build Coastguard Worker 8270*9880d681SAndroid Build Coastguard Worker <result> = icmp eq i32 4, 5 ; yields: result=false 8271*9880d681SAndroid Build Coastguard Worker <result> = icmp ne float* %X, %X ; yields: result=false 8272*9880d681SAndroid Build Coastguard Worker <result> = icmp ult i16 4, 5 ; yields: result=true 8273*9880d681SAndroid Build Coastguard Worker <result> = icmp sgt i16 4, 5 ; yields: result=false 8274*9880d681SAndroid Build Coastguard Worker <result> = icmp ule i16 -4, 5 ; yields: result=false 8275*9880d681SAndroid Build Coastguard Worker <result> = icmp sge i16 4, 5 ; yields: result=false 8276*9880d681SAndroid Build Coastguard Worker 8277*9880d681SAndroid Build Coastguard Worker.. _i_fcmp: 8278*9880d681SAndroid Build Coastguard Worker 8279*9880d681SAndroid Build Coastguard Worker'``fcmp``' Instruction 8280*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^ 8281*9880d681SAndroid Build Coastguard Worker 8282*9880d681SAndroid Build Coastguard WorkerSyntax: 8283*9880d681SAndroid Build Coastguard Worker""""""" 8284*9880d681SAndroid Build Coastguard Worker 8285*9880d681SAndroid Build Coastguard Worker:: 8286*9880d681SAndroid Build Coastguard Worker 8287*9880d681SAndroid Build Coastguard Worker <result> = fcmp [fast-math flags]* <cond> <ty> <op1>, <op2> ; yields i1 or <N x i1>:result 8288*9880d681SAndroid Build Coastguard Worker 8289*9880d681SAndroid Build Coastguard WorkerOverview: 8290*9880d681SAndroid Build Coastguard Worker""""""""" 8291*9880d681SAndroid Build Coastguard Worker 8292*9880d681SAndroid Build Coastguard WorkerThe '``fcmp``' instruction returns a boolean value or vector of boolean 8293*9880d681SAndroid Build Coastguard Workervalues based on comparison of its operands. 8294*9880d681SAndroid Build Coastguard Worker 8295*9880d681SAndroid Build Coastguard WorkerIf the operands are floating point scalars, then the result type is a 8296*9880d681SAndroid Build Coastguard Workerboolean (:ref:`i1 <t_integer>`). 8297*9880d681SAndroid Build Coastguard Worker 8298*9880d681SAndroid Build Coastguard WorkerIf the operands are floating point vectors, then the result type is a 8299*9880d681SAndroid Build Coastguard Workervector of boolean with the same number of elements as the operands being 8300*9880d681SAndroid Build Coastguard Workercompared. 8301*9880d681SAndroid Build Coastguard Worker 8302*9880d681SAndroid Build Coastguard WorkerArguments: 8303*9880d681SAndroid Build Coastguard Worker"""""""""" 8304*9880d681SAndroid Build Coastguard Worker 8305*9880d681SAndroid Build Coastguard WorkerThe '``fcmp``' instruction takes three operands. The first operand is 8306*9880d681SAndroid Build Coastguard Workerthe condition code indicating the kind of comparison to perform. It is 8307*9880d681SAndroid Build Coastguard Workernot a value, just a keyword. The possible condition codes are: 8308*9880d681SAndroid Build Coastguard Worker 8309*9880d681SAndroid Build Coastguard Worker#. ``false``: no comparison, always returns false 8310*9880d681SAndroid Build Coastguard Worker#. ``oeq``: ordered and equal 8311*9880d681SAndroid Build Coastguard Worker#. ``ogt``: ordered and greater than 8312*9880d681SAndroid Build Coastguard Worker#. ``oge``: ordered and greater than or equal 8313*9880d681SAndroid Build Coastguard Worker#. ``olt``: ordered and less than 8314*9880d681SAndroid Build Coastguard Worker#. ``ole``: ordered and less than or equal 8315*9880d681SAndroid Build Coastguard Worker#. ``one``: ordered and not equal 8316*9880d681SAndroid Build Coastguard Worker#. ``ord``: ordered (no nans) 8317*9880d681SAndroid Build Coastguard Worker#. ``ueq``: unordered or equal 8318*9880d681SAndroid Build Coastguard Worker#. ``ugt``: unordered or greater than 8319*9880d681SAndroid Build Coastguard Worker#. ``uge``: unordered or greater than or equal 8320*9880d681SAndroid Build Coastguard Worker#. ``ult``: unordered or less than 8321*9880d681SAndroid Build Coastguard Worker#. ``ule``: unordered or less than or equal 8322*9880d681SAndroid Build Coastguard Worker#. ``une``: unordered or not equal 8323*9880d681SAndroid Build Coastguard Worker#. ``uno``: unordered (either nans) 8324*9880d681SAndroid Build Coastguard Worker#. ``true``: no comparison, always returns true 8325*9880d681SAndroid Build Coastguard Worker 8326*9880d681SAndroid Build Coastguard Worker*Ordered* means that neither operand is a QNAN while *unordered* means 8327*9880d681SAndroid Build Coastguard Workerthat either operand may be a QNAN. 8328*9880d681SAndroid Build Coastguard Worker 8329*9880d681SAndroid Build Coastguard WorkerEach of ``val1`` and ``val2`` arguments must be either a :ref:`floating 8330*9880d681SAndroid Build Coastguard Workerpoint <t_floating>` type or a :ref:`vector <t_vector>` of floating point 8331*9880d681SAndroid Build Coastguard Workertype. They must have identical types. 8332*9880d681SAndroid Build Coastguard Worker 8333*9880d681SAndroid Build Coastguard WorkerSemantics: 8334*9880d681SAndroid Build Coastguard Worker"""""""""" 8335*9880d681SAndroid Build Coastguard Worker 8336*9880d681SAndroid Build Coastguard WorkerThe '``fcmp``' instruction compares ``op1`` and ``op2`` according to the 8337*9880d681SAndroid Build Coastguard Workercondition code given as ``cond``. If the operands are vectors, then the 8338*9880d681SAndroid Build Coastguard Workervectors are compared element by element. Each comparison performed 8339*9880d681SAndroid Build Coastguard Workeralways yields an :ref:`i1 <t_integer>` result, as follows: 8340*9880d681SAndroid Build Coastguard Worker 8341*9880d681SAndroid Build Coastguard Worker#. ``false``: always yields ``false``, regardless of operands. 8342*9880d681SAndroid Build Coastguard Worker#. ``oeq``: yields ``true`` if both operands are not a QNAN and ``op1`` 8343*9880d681SAndroid Build Coastguard Worker is equal to ``op2``. 8344*9880d681SAndroid Build Coastguard Worker#. ``ogt``: yields ``true`` if both operands are not a QNAN and ``op1`` 8345*9880d681SAndroid Build Coastguard Worker is greater than ``op2``. 8346*9880d681SAndroid Build Coastguard Worker#. ``oge``: yields ``true`` if both operands are not a QNAN and ``op1`` 8347*9880d681SAndroid Build Coastguard Worker is greater than or equal to ``op2``. 8348*9880d681SAndroid Build Coastguard Worker#. ``olt``: yields ``true`` if both operands are not a QNAN and ``op1`` 8349*9880d681SAndroid Build Coastguard Worker is less than ``op2``. 8350*9880d681SAndroid Build Coastguard Worker#. ``ole``: yields ``true`` if both operands are not a QNAN and ``op1`` 8351*9880d681SAndroid Build Coastguard Worker is less than or equal to ``op2``. 8352*9880d681SAndroid Build Coastguard Worker#. ``one``: yields ``true`` if both operands are not a QNAN and ``op1`` 8353*9880d681SAndroid Build Coastguard Worker is not equal to ``op2``. 8354*9880d681SAndroid Build Coastguard Worker#. ``ord``: yields ``true`` if both operands are not a QNAN. 8355*9880d681SAndroid Build Coastguard Worker#. ``ueq``: yields ``true`` if either operand is a QNAN or ``op1`` is 8356*9880d681SAndroid Build Coastguard Worker equal to ``op2``. 8357*9880d681SAndroid Build Coastguard Worker#. ``ugt``: yields ``true`` if either operand is a QNAN or ``op1`` is 8358*9880d681SAndroid Build Coastguard Worker greater than ``op2``. 8359*9880d681SAndroid Build Coastguard Worker#. ``uge``: yields ``true`` if either operand is a QNAN or ``op1`` is 8360*9880d681SAndroid Build Coastguard Worker greater than or equal to ``op2``. 8361*9880d681SAndroid Build Coastguard Worker#. ``ult``: yields ``true`` if either operand is a QNAN or ``op1`` is 8362*9880d681SAndroid Build Coastguard Worker less than ``op2``. 8363*9880d681SAndroid Build Coastguard Worker#. ``ule``: yields ``true`` if either operand is a QNAN or ``op1`` is 8364*9880d681SAndroid Build Coastguard Worker less than or equal to ``op2``. 8365*9880d681SAndroid Build Coastguard Worker#. ``une``: yields ``true`` if either operand is a QNAN or ``op1`` is 8366*9880d681SAndroid Build Coastguard Worker not equal to ``op2``. 8367*9880d681SAndroid Build Coastguard Worker#. ``uno``: yields ``true`` if either operand is a QNAN. 8368*9880d681SAndroid Build Coastguard Worker#. ``true``: always yields ``true``, regardless of operands. 8369*9880d681SAndroid Build Coastguard Worker 8370*9880d681SAndroid Build Coastguard WorkerThe ``fcmp`` instruction can also optionally take any number of 8371*9880d681SAndroid Build Coastguard Worker:ref:`fast-math flags <fastmath>`, which are optimization hints to enable 8372*9880d681SAndroid Build Coastguard Workerotherwise unsafe floating point optimizations. 8373*9880d681SAndroid Build Coastguard Worker 8374*9880d681SAndroid Build Coastguard WorkerAny set of fast-math flags are legal on an ``fcmp`` instruction, but the 8375*9880d681SAndroid Build Coastguard Workeronly flags that have any effect on its semantics are those that allow 8376*9880d681SAndroid Build Coastguard Workerassumptions to be made about the values of input arguments; namely 8377*9880d681SAndroid Build Coastguard Worker``nnan``, ``ninf``, and ``nsz``. See :ref:`fastmath` for more information. 8378*9880d681SAndroid Build Coastguard Worker 8379*9880d681SAndroid Build Coastguard WorkerExample: 8380*9880d681SAndroid Build Coastguard Worker"""""""" 8381*9880d681SAndroid Build Coastguard Worker 8382*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 8383*9880d681SAndroid Build Coastguard Worker 8384*9880d681SAndroid Build Coastguard Worker <result> = fcmp oeq float 4.0, 5.0 ; yields: result=false 8385*9880d681SAndroid Build Coastguard Worker <result> = fcmp one float 4.0, 5.0 ; yields: result=true 8386*9880d681SAndroid Build Coastguard Worker <result> = fcmp olt float 4.0, 5.0 ; yields: result=true 8387*9880d681SAndroid Build Coastguard Worker <result> = fcmp ueq double 1.0, 2.0 ; yields: result=false 8388*9880d681SAndroid Build Coastguard Worker 8389*9880d681SAndroid Build Coastguard Worker.. _i_phi: 8390*9880d681SAndroid Build Coastguard Worker 8391*9880d681SAndroid Build Coastguard Worker'``phi``' Instruction 8392*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^ 8393*9880d681SAndroid Build Coastguard Worker 8394*9880d681SAndroid Build Coastguard WorkerSyntax: 8395*9880d681SAndroid Build Coastguard Worker""""""" 8396*9880d681SAndroid Build Coastguard Worker 8397*9880d681SAndroid Build Coastguard Worker:: 8398*9880d681SAndroid Build Coastguard Worker 8399*9880d681SAndroid Build Coastguard Worker <result> = phi <ty> [ <val0>, <label0>], ... 8400*9880d681SAndroid Build Coastguard Worker 8401*9880d681SAndroid Build Coastguard WorkerOverview: 8402*9880d681SAndroid Build Coastguard Worker""""""""" 8403*9880d681SAndroid Build Coastguard Worker 8404*9880d681SAndroid Build Coastguard WorkerThe '``phi``' instruction is used to implement the φ node in the SSA 8405*9880d681SAndroid Build Coastguard Workergraph representing the function. 8406*9880d681SAndroid Build Coastguard Worker 8407*9880d681SAndroid Build Coastguard WorkerArguments: 8408*9880d681SAndroid Build Coastguard Worker"""""""""" 8409*9880d681SAndroid Build Coastguard Worker 8410*9880d681SAndroid Build Coastguard WorkerThe type of the incoming values is specified with the first type field. 8411*9880d681SAndroid Build Coastguard WorkerAfter this, the '``phi``' instruction takes a list of pairs as 8412*9880d681SAndroid Build Coastguard Workerarguments, with one pair for each predecessor basic block of the current 8413*9880d681SAndroid Build Coastguard Workerblock. Only values of :ref:`first class <t_firstclass>` type may be used as 8414*9880d681SAndroid Build Coastguard Workerthe value arguments to the PHI node. Only labels may be used as the 8415*9880d681SAndroid Build Coastguard Workerlabel arguments. 8416*9880d681SAndroid Build Coastguard Worker 8417*9880d681SAndroid Build Coastguard WorkerThere must be no non-phi instructions between the start of a basic block 8418*9880d681SAndroid Build Coastguard Workerand the PHI instructions: i.e. PHI instructions must be first in a basic 8419*9880d681SAndroid Build Coastguard Workerblock. 8420*9880d681SAndroid Build Coastguard Worker 8421*9880d681SAndroid Build Coastguard WorkerFor the purposes of the SSA form, the use of each incoming value is 8422*9880d681SAndroid Build Coastguard Workerdeemed to occur on the edge from the corresponding predecessor block to 8423*9880d681SAndroid Build Coastguard Workerthe current block (but after any definition of an '``invoke``' 8424*9880d681SAndroid Build Coastguard Workerinstruction's return value on the same edge). 8425*9880d681SAndroid Build Coastguard Worker 8426*9880d681SAndroid Build Coastguard WorkerSemantics: 8427*9880d681SAndroid Build Coastguard Worker"""""""""" 8428*9880d681SAndroid Build Coastguard Worker 8429*9880d681SAndroid Build Coastguard WorkerAt runtime, the '``phi``' instruction logically takes on the value 8430*9880d681SAndroid Build Coastguard Workerspecified by the pair corresponding to the predecessor basic block that 8431*9880d681SAndroid Build Coastguard Workerexecuted just prior to the current block. 8432*9880d681SAndroid Build Coastguard Worker 8433*9880d681SAndroid Build Coastguard WorkerExample: 8434*9880d681SAndroid Build Coastguard Worker"""""""" 8435*9880d681SAndroid Build Coastguard Worker 8436*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 8437*9880d681SAndroid Build Coastguard Worker 8438*9880d681SAndroid Build Coastguard Worker Loop: ; Infinite loop that counts from 0 on up... 8439*9880d681SAndroid Build Coastguard Worker %indvar = phi i32 [ 0, %LoopHeader ], [ %nextindvar, %Loop ] 8440*9880d681SAndroid Build Coastguard Worker %nextindvar = add i32 %indvar, 1 8441*9880d681SAndroid Build Coastguard Worker br label %Loop 8442*9880d681SAndroid Build Coastguard Worker 8443*9880d681SAndroid Build Coastguard Worker.. _i_select: 8444*9880d681SAndroid Build Coastguard Worker 8445*9880d681SAndroid Build Coastguard Worker'``select``' Instruction 8446*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^ 8447*9880d681SAndroid Build Coastguard Worker 8448*9880d681SAndroid Build Coastguard WorkerSyntax: 8449*9880d681SAndroid Build Coastguard Worker""""""" 8450*9880d681SAndroid Build Coastguard Worker 8451*9880d681SAndroid Build Coastguard Worker:: 8452*9880d681SAndroid Build Coastguard Worker 8453*9880d681SAndroid Build Coastguard Worker <result> = select selty <cond>, <ty> <val1>, <ty> <val2> ; yields ty 8454*9880d681SAndroid Build Coastguard Worker 8455*9880d681SAndroid Build Coastguard Worker selty is either i1 or {<N x i1>} 8456*9880d681SAndroid Build Coastguard Worker 8457*9880d681SAndroid Build Coastguard WorkerOverview: 8458*9880d681SAndroid Build Coastguard Worker""""""""" 8459*9880d681SAndroid Build Coastguard Worker 8460*9880d681SAndroid Build Coastguard WorkerThe '``select``' instruction is used to choose one value based on a 8461*9880d681SAndroid Build Coastguard Workercondition, without IR-level branching. 8462*9880d681SAndroid Build Coastguard Worker 8463*9880d681SAndroid Build Coastguard WorkerArguments: 8464*9880d681SAndroid Build Coastguard Worker"""""""""" 8465*9880d681SAndroid Build Coastguard Worker 8466*9880d681SAndroid Build Coastguard WorkerThe '``select``' instruction requires an 'i1' value or a vector of 'i1' 8467*9880d681SAndroid Build Coastguard Workervalues indicating the condition, and two values of the same :ref:`first 8468*9880d681SAndroid Build Coastguard Workerclass <t_firstclass>` type. 8469*9880d681SAndroid Build Coastguard Worker 8470*9880d681SAndroid Build Coastguard WorkerSemantics: 8471*9880d681SAndroid Build Coastguard Worker"""""""""" 8472*9880d681SAndroid Build Coastguard Worker 8473*9880d681SAndroid Build Coastguard WorkerIf the condition is an i1 and it evaluates to 1, the instruction returns 8474*9880d681SAndroid Build Coastguard Workerthe first value argument; otherwise, it returns the second value 8475*9880d681SAndroid Build Coastguard Workerargument. 8476*9880d681SAndroid Build Coastguard Worker 8477*9880d681SAndroid Build Coastguard WorkerIf the condition is a vector of i1, then the value arguments must be 8478*9880d681SAndroid Build Coastguard Workervectors of the same size, and the selection is done element by element. 8479*9880d681SAndroid Build Coastguard Worker 8480*9880d681SAndroid Build Coastguard WorkerIf the condition is an i1 and the value arguments are vectors of the 8481*9880d681SAndroid Build Coastguard Workersame size, then an entire vector is selected. 8482*9880d681SAndroid Build Coastguard Worker 8483*9880d681SAndroid Build Coastguard WorkerExample: 8484*9880d681SAndroid Build Coastguard Worker"""""""" 8485*9880d681SAndroid Build Coastguard Worker 8486*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 8487*9880d681SAndroid Build Coastguard Worker 8488*9880d681SAndroid Build Coastguard Worker %X = select i1 true, i8 17, i8 42 ; yields i8:17 8489*9880d681SAndroid Build Coastguard Worker 8490*9880d681SAndroid Build Coastguard Worker.. _i_call: 8491*9880d681SAndroid Build Coastguard Worker 8492*9880d681SAndroid Build Coastguard Worker'``call``' Instruction 8493*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^ 8494*9880d681SAndroid Build Coastguard Worker 8495*9880d681SAndroid Build Coastguard WorkerSyntax: 8496*9880d681SAndroid Build Coastguard Worker""""""" 8497*9880d681SAndroid Build Coastguard Worker 8498*9880d681SAndroid Build Coastguard Worker:: 8499*9880d681SAndroid Build Coastguard Worker 8500*9880d681SAndroid Build Coastguard Worker <result> = [tail | musttail | notail ] call [fast-math flags] [cconv] [ret attrs] <ty>|<fnty> <fnptrval>(<function args>) [fn attrs] 8501*9880d681SAndroid Build Coastguard Worker [ operand bundles ] 8502*9880d681SAndroid Build Coastguard Worker 8503*9880d681SAndroid Build Coastguard WorkerOverview: 8504*9880d681SAndroid Build Coastguard Worker""""""""" 8505*9880d681SAndroid Build Coastguard Worker 8506*9880d681SAndroid Build Coastguard WorkerThe '``call``' instruction represents a simple function call. 8507*9880d681SAndroid Build Coastguard Worker 8508*9880d681SAndroid Build Coastguard WorkerArguments: 8509*9880d681SAndroid Build Coastguard Worker"""""""""" 8510*9880d681SAndroid Build Coastguard Worker 8511*9880d681SAndroid Build Coastguard WorkerThis instruction requires several arguments: 8512*9880d681SAndroid Build Coastguard Worker 8513*9880d681SAndroid Build Coastguard Worker#. The optional ``tail`` and ``musttail`` markers indicate that the optimizers 8514*9880d681SAndroid Build Coastguard Worker should perform tail call optimization. The ``tail`` marker is a hint that 8515*9880d681SAndroid Build Coastguard Worker `can be ignored <CodeGenerator.html#sibcallopt>`_. The ``musttail`` marker 8516*9880d681SAndroid Build Coastguard Worker means that the call must be tail call optimized in order for the program to 8517*9880d681SAndroid Build Coastguard Worker be correct. The ``musttail`` marker provides these guarantees: 8518*9880d681SAndroid Build Coastguard Worker 8519*9880d681SAndroid Build Coastguard Worker #. The call will not cause unbounded stack growth if it is part of a 8520*9880d681SAndroid Build Coastguard Worker recursive cycle in the call graph. 8521*9880d681SAndroid Build Coastguard Worker #. Arguments with the :ref:`inalloca <attr_inalloca>` attribute are 8522*9880d681SAndroid Build Coastguard Worker forwarded in place. 8523*9880d681SAndroid Build Coastguard Worker 8524*9880d681SAndroid Build Coastguard Worker Both markers imply that the callee does not access allocas or varargs from 8525*9880d681SAndroid Build Coastguard Worker the caller. Calls marked ``musttail`` must obey the following additional 8526*9880d681SAndroid Build Coastguard Worker rules: 8527*9880d681SAndroid Build Coastguard Worker 8528*9880d681SAndroid Build Coastguard Worker - The call must immediately precede a :ref:`ret <i_ret>` instruction, 8529*9880d681SAndroid Build Coastguard Worker or a pointer bitcast followed by a ret instruction. 8530*9880d681SAndroid Build Coastguard Worker - The ret instruction must return the (possibly bitcasted) value 8531*9880d681SAndroid Build Coastguard Worker produced by the call or void. 8532*9880d681SAndroid Build Coastguard Worker - The caller and callee prototypes must match. Pointer types of 8533*9880d681SAndroid Build Coastguard Worker parameters or return types may differ in pointee type, but not 8534*9880d681SAndroid Build Coastguard Worker in address space. 8535*9880d681SAndroid Build Coastguard Worker - The calling conventions of the caller and callee must match. 8536*9880d681SAndroid Build Coastguard Worker - All ABI-impacting function attributes, such as sret, byval, inreg, 8537*9880d681SAndroid Build Coastguard Worker returned, and inalloca, must match. 8538*9880d681SAndroid Build Coastguard Worker - The callee must be varargs iff the caller is varargs. Bitcasting a 8539*9880d681SAndroid Build Coastguard Worker non-varargs function to the appropriate varargs type is legal so 8540*9880d681SAndroid Build Coastguard Worker long as the non-varargs prefixes obey the other rules. 8541*9880d681SAndroid Build Coastguard Worker 8542*9880d681SAndroid Build Coastguard Worker Tail call optimization for calls marked ``tail`` is guaranteed to occur if 8543*9880d681SAndroid Build Coastguard Worker the following conditions are met: 8544*9880d681SAndroid Build Coastguard Worker 8545*9880d681SAndroid Build Coastguard Worker - Caller and callee both have the calling convention ``fastcc``. 8546*9880d681SAndroid Build Coastguard Worker - The call is in tail position (ret immediately follows call and ret 8547*9880d681SAndroid Build Coastguard Worker uses value of call or is void). 8548*9880d681SAndroid Build Coastguard Worker - Option ``-tailcallopt`` is enabled, or 8549*9880d681SAndroid Build Coastguard Worker ``llvm::GuaranteedTailCallOpt`` is ``true``. 8550*9880d681SAndroid Build Coastguard Worker - `Platform-specific constraints are 8551*9880d681SAndroid Build Coastguard Worker met. <CodeGenerator.html#tailcallopt>`_ 8552*9880d681SAndroid Build Coastguard Worker 8553*9880d681SAndroid Build Coastguard Worker#. The optional ``notail`` marker indicates that the optimizers should not add 8554*9880d681SAndroid Build Coastguard Worker ``tail`` or ``musttail`` markers to the call. It is used to prevent tail 8555*9880d681SAndroid Build Coastguard Worker call optimization from being performed on the call. 8556*9880d681SAndroid Build Coastguard Worker 8557*9880d681SAndroid Build Coastguard Worker#. The optional ``fast-math flags`` marker indicates that the call has one or more 8558*9880d681SAndroid Build Coastguard Worker :ref:`fast-math flags <fastmath>`, which are optimization hints to enable 8559*9880d681SAndroid Build Coastguard Worker otherwise unsafe floating-point optimizations. Fast-math flags are only valid 8560*9880d681SAndroid Build Coastguard Worker for calls that return a floating-point scalar or vector type. 8561*9880d681SAndroid Build Coastguard Worker 8562*9880d681SAndroid Build Coastguard Worker#. The optional "cconv" marker indicates which :ref:`calling 8563*9880d681SAndroid Build Coastguard Worker convention <callingconv>` the call should use. If none is 8564*9880d681SAndroid Build Coastguard Worker specified, the call defaults to using C calling conventions. The 8565*9880d681SAndroid Build Coastguard Worker calling convention of the call must match the calling convention of 8566*9880d681SAndroid Build Coastguard Worker the target function, or else the behavior is undefined. 8567*9880d681SAndroid Build Coastguard Worker#. The optional :ref:`Parameter Attributes <paramattrs>` list for return 8568*9880d681SAndroid Build Coastguard Worker values. Only '``zeroext``', '``signext``', and '``inreg``' attributes 8569*9880d681SAndroid Build Coastguard Worker are valid here. 8570*9880d681SAndroid Build Coastguard Worker#. '``ty``': the type of the call instruction itself which is also the 8571*9880d681SAndroid Build Coastguard Worker type of the return value. Functions that return no value are marked 8572*9880d681SAndroid Build Coastguard Worker ``void``. 8573*9880d681SAndroid Build Coastguard Worker#. '``fnty``': shall be the signature of the function being called. The 8574*9880d681SAndroid Build Coastguard Worker argument types must match the types implied by this signature. This 8575*9880d681SAndroid Build Coastguard Worker type can be omitted if the function is not varargs. 8576*9880d681SAndroid Build Coastguard Worker#. '``fnptrval``': An LLVM value containing a pointer to a function to 8577*9880d681SAndroid Build Coastguard Worker be called. In most cases, this is a direct function call, but 8578*9880d681SAndroid Build Coastguard Worker indirect ``call``'s are just as possible, calling an arbitrary pointer 8579*9880d681SAndroid Build Coastguard Worker to function value. 8580*9880d681SAndroid Build Coastguard Worker#. '``function args``': argument list whose types match the function 8581*9880d681SAndroid Build Coastguard Worker signature argument types and parameter attributes. All arguments must 8582*9880d681SAndroid Build Coastguard Worker be of :ref:`first class <t_firstclass>` type. If the function signature 8583*9880d681SAndroid Build Coastguard Worker indicates the function accepts a variable number of arguments, the 8584*9880d681SAndroid Build Coastguard Worker extra arguments can be specified. 8585*9880d681SAndroid Build Coastguard Worker#. The optional :ref:`function attributes <fnattrs>` list. Only 8586*9880d681SAndroid Build Coastguard Worker '``noreturn``', '``nounwind``', '``readonly``' , '``readnone``', 8587*9880d681SAndroid Build Coastguard Worker and '``convergent``' attributes are valid here. 8588*9880d681SAndroid Build Coastguard Worker#. The optional :ref:`operand bundles <opbundles>` list. 8589*9880d681SAndroid Build Coastguard Worker 8590*9880d681SAndroid Build Coastguard WorkerSemantics: 8591*9880d681SAndroid Build Coastguard Worker"""""""""" 8592*9880d681SAndroid Build Coastguard Worker 8593*9880d681SAndroid Build Coastguard WorkerThe '``call``' instruction is used to cause control flow to transfer to 8594*9880d681SAndroid Build Coastguard Workera specified function, with its incoming arguments bound to the specified 8595*9880d681SAndroid Build Coastguard Workervalues. Upon a '``ret``' instruction in the called function, control 8596*9880d681SAndroid Build Coastguard Workerflow continues with the instruction after the function call, and the 8597*9880d681SAndroid Build Coastguard Workerreturn value of the function is bound to the result argument. 8598*9880d681SAndroid Build Coastguard Worker 8599*9880d681SAndroid Build Coastguard WorkerExample: 8600*9880d681SAndroid Build Coastguard Worker"""""""" 8601*9880d681SAndroid Build Coastguard Worker 8602*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 8603*9880d681SAndroid Build Coastguard Worker 8604*9880d681SAndroid Build Coastguard Worker %retval = call i32 @test(i32 %argc) 8605*9880d681SAndroid Build Coastguard Worker call i32 (i8*, ...)* @printf(i8* %msg, i32 12, i8 42) ; yields i32 8606*9880d681SAndroid Build Coastguard Worker %X = tail call i32 @foo() ; yields i32 8607*9880d681SAndroid Build Coastguard Worker %Y = tail call fastcc i32 @foo() ; yields i32 8608*9880d681SAndroid Build Coastguard Worker call void %foo(i8 97 signext) 8609*9880d681SAndroid Build Coastguard Worker 8610*9880d681SAndroid Build Coastguard Worker %struct.A = type { i32, i8 } 8611*9880d681SAndroid Build Coastguard Worker %r = call %struct.A @foo() ; yields { i32, i8 } 8612*9880d681SAndroid Build Coastguard Worker %gr = extractvalue %struct.A %r, 0 ; yields i32 8613*9880d681SAndroid Build Coastguard Worker %gr1 = extractvalue %struct.A %r, 1 ; yields i8 8614*9880d681SAndroid Build Coastguard Worker %Z = call void @foo() noreturn ; indicates that %foo never returns normally 8615*9880d681SAndroid Build Coastguard Worker %ZZ = call zeroext i32 @bar() ; Return value is %zero extended 8616*9880d681SAndroid Build Coastguard Worker 8617*9880d681SAndroid Build Coastguard Workerllvm treats calls to some functions with names and arguments that match 8618*9880d681SAndroid Build Coastguard Workerthe standard C99 library as being the C99 library functions, and may 8619*9880d681SAndroid Build Coastguard Workerperform optimizations or generate code for them under that assumption. 8620*9880d681SAndroid Build Coastguard WorkerThis is something we'd like to change in the future to provide better 8621*9880d681SAndroid Build Coastguard Workersupport for freestanding environments and non-C-based languages. 8622*9880d681SAndroid Build Coastguard Worker 8623*9880d681SAndroid Build Coastguard Worker.. _i_va_arg: 8624*9880d681SAndroid Build Coastguard Worker 8625*9880d681SAndroid Build Coastguard Worker'``va_arg``' Instruction 8626*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^ 8627*9880d681SAndroid Build Coastguard Worker 8628*9880d681SAndroid Build Coastguard WorkerSyntax: 8629*9880d681SAndroid Build Coastguard Worker""""""" 8630*9880d681SAndroid Build Coastguard Worker 8631*9880d681SAndroid Build Coastguard Worker:: 8632*9880d681SAndroid Build Coastguard Worker 8633*9880d681SAndroid Build Coastguard Worker <resultval> = va_arg <va_list*> <arglist>, <argty> 8634*9880d681SAndroid Build Coastguard Worker 8635*9880d681SAndroid Build Coastguard WorkerOverview: 8636*9880d681SAndroid Build Coastguard Worker""""""""" 8637*9880d681SAndroid Build Coastguard Worker 8638*9880d681SAndroid Build Coastguard WorkerThe '``va_arg``' instruction is used to access arguments passed through 8639*9880d681SAndroid Build Coastguard Workerthe "variable argument" area of a function call. It is used to implement 8640*9880d681SAndroid Build Coastguard Workerthe ``va_arg`` macro in C. 8641*9880d681SAndroid Build Coastguard Worker 8642*9880d681SAndroid Build Coastguard WorkerArguments: 8643*9880d681SAndroid Build Coastguard Worker"""""""""" 8644*9880d681SAndroid Build Coastguard Worker 8645*9880d681SAndroid Build Coastguard WorkerThis instruction takes a ``va_list*`` value and the type of the 8646*9880d681SAndroid Build Coastguard Workerargument. It returns a value of the specified argument type and 8647*9880d681SAndroid Build Coastguard Workerincrements the ``va_list`` to point to the next argument. The actual 8648*9880d681SAndroid Build Coastguard Workertype of ``va_list`` is target specific. 8649*9880d681SAndroid Build Coastguard Worker 8650*9880d681SAndroid Build Coastguard WorkerSemantics: 8651*9880d681SAndroid Build Coastguard Worker"""""""""" 8652*9880d681SAndroid Build Coastguard Worker 8653*9880d681SAndroid Build Coastguard WorkerThe '``va_arg``' instruction loads an argument of the specified type 8654*9880d681SAndroid Build Coastguard Workerfrom the specified ``va_list`` and causes the ``va_list`` to point to 8655*9880d681SAndroid Build Coastguard Workerthe next argument. For more information, see the variable argument 8656*9880d681SAndroid Build Coastguard Workerhandling :ref:`Intrinsic Functions <int_varargs>`. 8657*9880d681SAndroid Build Coastguard Worker 8658*9880d681SAndroid Build Coastguard WorkerIt is legal for this instruction to be called in a function which does 8659*9880d681SAndroid Build Coastguard Workernot take a variable number of arguments, for example, the ``vfprintf`` 8660*9880d681SAndroid Build Coastguard Workerfunction. 8661*9880d681SAndroid Build Coastguard Worker 8662*9880d681SAndroid Build Coastguard Worker``va_arg`` is an LLVM instruction instead of an :ref:`intrinsic 8663*9880d681SAndroid Build Coastguard Workerfunction <intrinsics>` because it takes a type as an argument. 8664*9880d681SAndroid Build Coastguard Worker 8665*9880d681SAndroid Build Coastguard WorkerExample: 8666*9880d681SAndroid Build Coastguard Worker"""""""" 8667*9880d681SAndroid Build Coastguard Worker 8668*9880d681SAndroid Build Coastguard WorkerSee the :ref:`variable argument processing <int_varargs>` section. 8669*9880d681SAndroid Build Coastguard Worker 8670*9880d681SAndroid Build Coastguard WorkerNote that the code generator does not yet fully support va\_arg on many 8671*9880d681SAndroid Build Coastguard Workertargets. Also, it does not currently support va\_arg with aggregate 8672*9880d681SAndroid Build Coastguard Workertypes on any target. 8673*9880d681SAndroid Build Coastguard Worker 8674*9880d681SAndroid Build Coastguard Worker.. _i_landingpad: 8675*9880d681SAndroid Build Coastguard Worker 8676*9880d681SAndroid Build Coastguard Worker'``landingpad``' Instruction 8677*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 8678*9880d681SAndroid Build Coastguard Worker 8679*9880d681SAndroid Build Coastguard WorkerSyntax: 8680*9880d681SAndroid Build Coastguard Worker""""""" 8681*9880d681SAndroid Build Coastguard Worker 8682*9880d681SAndroid Build Coastguard Worker:: 8683*9880d681SAndroid Build Coastguard Worker 8684*9880d681SAndroid Build Coastguard Worker <resultval> = landingpad <resultty> <clause>+ 8685*9880d681SAndroid Build Coastguard Worker <resultval> = landingpad <resultty> cleanup <clause>* 8686*9880d681SAndroid Build Coastguard Worker 8687*9880d681SAndroid Build Coastguard Worker <clause> := catch <type> <value> 8688*9880d681SAndroid Build Coastguard Worker <clause> := filter <array constant type> <array constant> 8689*9880d681SAndroid Build Coastguard Worker 8690*9880d681SAndroid Build Coastguard WorkerOverview: 8691*9880d681SAndroid Build Coastguard Worker""""""""" 8692*9880d681SAndroid Build Coastguard Worker 8693*9880d681SAndroid Build Coastguard WorkerThe '``landingpad``' instruction is used by `LLVM's exception handling 8694*9880d681SAndroid Build Coastguard Workersystem <ExceptionHandling.html#overview>`_ to specify that a basic block 8695*9880d681SAndroid Build Coastguard Workeris a landing pad --- one where the exception lands, and corresponds to the 8696*9880d681SAndroid Build Coastguard Workercode found in the ``catch`` portion of a ``try``/``catch`` sequence. It 8697*9880d681SAndroid Build Coastguard Workerdefines values supplied by the :ref:`personality function <personalityfn>` upon 8698*9880d681SAndroid Build Coastguard Workerre-entry to the function. The ``resultval`` has the type ``resultty``. 8699*9880d681SAndroid Build Coastguard Worker 8700*9880d681SAndroid Build Coastguard WorkerArguments: 8701*9880d681SAndroid Build Coastguard Worker"""""""""" 8702*9880d681SAndroid Build Coastguard Worker 8703*9880d681SAndroid Build Coastguard WorkerThe optional 8704*9880d681SAndroid Build Coastguard Worker``cleanup`` flag indicates that the landing pad block is a cleanup. 8705*9880d681SAndroid Build Coastguard Worker 8706*9880d681SAndroid Build Coastguard WorkerA ``clause`` begins with the clause type --- ``catch`` or ``filter`` --- and 8707*9880d681SAndroid Build Coastguard Workercontains the global variable representing the "type" that may be caught 8708*9880d681SAndroid Build Coastguard Workeror filtered respectively. Unlike the ``catch`` clause, the ``filter`` 8709*9880d681SAndroid Build Coastguard Workerclause takes an array constant as its argument. Use 8710*9880d681SAndroid Build Coastguard Worker"``[0 x i8**] undef``" for a filter which cannot throw. The 8711*9880d681SAndroid Build Coastguard Worker'``landingpad``' instruction must contain *at least* one ``clause`` or 8712*9880d681SAndroid Build Coastguard Workerthe ``cleanup`` flag. 8713*9880d681SAndroid Build Coastguard Worker 8714*9880d681SAndroid Build Coastguard WorkerSemantics: 8715*9880d681SAndroid Build Coastguard Worker"""""""""" 8716*9880d681SAndroid Build Coastguard Worker 8717*9880d681SAndroid Build Coastguard WorkerThe '``landingpad``' instruction defines the values which are set by the 8718*9880d681SAndroid Build Coastguard Worker:ref:`personality function <personalityfn>` upon re-entry to the function, and 8719*9880d681SAndroid Build Coastguard Workertherefore the "result type" of the ``landingpad`` instruction. As with 8720*9880d681SAndroid Build Coastguard Workercalling conventions, how the personality function results are 8721*9880d681SAndroid Build Coastguard Workerrepresented in LLVM IR is target specific. 8722*9880d681SAndroid Build Coastguard Worker 8723*9880d681SAndroid Build Coastguard WorkerThe clauses are applied in order from top to bottom. If two 8724*9880d681SAndroid Build Coastguard Worker``landingpad`` instructions are merged together through inlining, the 8725*9880d681SAndroid Build Coastguard Workerclauses from the calling function are appended to the list of clauses. 8726*9880d681SAndroid Build Coastguard WorkerWhen the call stack is being unwound due to an exception being thrown, 8727*9880d681SAndroid Build Coastguard Workerthe exception is compared against each ``clause`` in turn. If it doesn't 8728*9880d681SAndroid Build Coastguard Workermatch any of the clauses, and the ``cleanup`` flag is not set, then 8729*9880d681SAndroid Build Coastguard Workerunwinding continues further up the call stack. 8730*9880d681SAndroid Build Coastguard Worker 8731*9880d681SAndroid Build Coastguard WorkerThe ``landingpad`` instruction has several restrictions: 8732*9880d681SAndroid Build Coastguard Worker 8733*9880d681SAndroid Build Coastguard Worker- A landing pad block is a basic block which is the unwind destination 8734*9880d681SAndroid Build Coastguard Worker of an '``invoke``' instruction. 8735*9880d681SAndroid Build Coastguard Worker- A landing pad block must have a '``landingpad``' instruction as its 8736*9880d681SAndroid Build Coastguard Worker first non-PHI instruction. 8737*9880d681SAndroid Build Coastguard Worker- There can be only one '``landingpad``' instruction within the landing 8738*9880d681SAndroid Build Coastguard Worker pad block. 8739*9880d681SAndroid Build Coastguard Worker- A basic block that is not a landing pad block may not include a 8740*9880d681SAndroid Build Coastguard Worker '``landingpad``' instruction. 8741*9880d681SAndroid Build Coastguard Worker 8742*9880d681SAndroid Build Coastguard WorkerExample: 8743*9880d681SAndroid Build Coastguard Worker"""""""" 8744*9880d681SAndroid Build Coastguard Worker 8745*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 8746*9880d681SAndroid Build Coastguard Worker 8747*9880d681SAndroid Build Coastguard Worker ;; A landing pad which can catch an integer. 8748*9880d681SAndroid Build Coastguard Worker %res = landingpad { i8*, i32 } 8749*9880d681SAndroid Build Coastguard Worker catch i8** @_ZTIi 8750*9880d681SAndroid Build Coastguard Worker ;; A landing pad that is a cleanup. 8751*9880d681SAndroid Build Coastguard Worker %res = landingpad { i8*, i32 } 8752*9880d681SAndroid Build Coastguard Worker cleanup 8753*9880d681SAndroid Build Coastguard Worker ;; A landing pad which can catch an integer and can only throw a double. 8754*9880d681SAndroid Build Coastguard Worker %res = landingpad { i8*, i32 } 8755*9880d681SAndroid Build Coastguard Worker catch i8** @_ZTIi 8756*9880d681SAndroid Build Coastguard Worker filter [1 x i8**] [@_ZTId] 8757*9880d681SAndroid Build Coastguard Worker 8758*9880d681SAndroid Build Coastguard Worker.. _i_catchpad: 8759*9880d681SAndroid Build Coastguard Worker 8760*9880d681SAndroid Build Coastguard Worker'``catchpad``' Instruction 8761*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^ 8762*9880d681SAndroid Build Coastguard Worker 8763*9880d681SAndroid Build Coastguard WorkerSyntax: 8764*9880d681SAndroid Build Coastguard Worker""""""" 8765*9880d681SAndroid Build Coastguard Worker 8766*9880d681SAndroid Build Coastguard Worker:: 8767*9880d681SAndroid Build Coastguard Worker 8768*9880d681SAndroid Build Coastguard Worker <resultval> = catchpad within <catchswitch> [<args>*] 8769*9880d681SAndroid Build Coastguard Worker 8770*9880d681SAndroid Build Coastguard WorkerOverview: 8771*9880d681SAndroid Build Coastguard Worker""""""""" 8772*9880d681SAndroid Build Coastguard Worker 8773*9880d681SAndroid Build Coastguard WorkerThe '``catchpad``' instruction is used by `LLVM's exception handling 8774*9880d681SAndroid Build Coastguard Workersystem <ExceptionHandling.html#overview>`_ to specify that a basic block 8775*9880d681SAndroid Build Coastguard Workerbegins a catch handler --- one where a personality routine attempts to transfer 8776*9880d681SAndroid Build Coastguard Workercontrol to catch an exception. 8777*9880d681SAndroid Build Coastguard Worker 8778*9880d681SAndroid Build Coastguard WorkerArguments: 8779*9880d681SAndroid Build Coastguard Worker"""""""""" 8780*9880d681SAndroid Build Coastguard Worker 8781*9880d681SAndroid Build Coastguard WorkerThe ``catchswitch`` operand must always be a token produced by a 8782*9880d681SAndroid Build Coastguard Worker:ref:`catchswitch <i_catchswitch>` instruction in a predecessor block. This 8783*9880d681SAndroid Build Coastguard Workerensures that each ``catchpad`` has exactly one predecessor block, and it always 8784*9880d681SAndroid Build Coastguard Workerterminates in a ``catchswitch``. 8785*9880d681SAndroid Build Coastguard Worker 8786*9880d681SAndroid Build Coastguard WorkerThe ``args`` correspond to whatever information the personality routine 8787*9880d681SAndroid Build Coastguard Workerrequires to know if this is an appropriate handler for the exception. Control 8788*9880d681SAndroid Build Coastguard Workerwill transfer to the ``catchpad`` if this is the first appropriate handler for 8789*9880d681SAndroid Build Coastguard Workerthe exception. 8790*9880d681SAndroid Build Coastguard Worker 8791*9880d681SAndroid Build Coastguard WorkerThe ``resultval`` has the type :ref:`token <t_token>` and is used to match the 8792*9880d681SAndroid Build Coastguard Worker``catchpad`` to corresponding :ref:`catchrets <i_catchret>` and other nested EH 8793*9880d681SAndroid Build Coastguard Workerpads. 8794*9880d681SAndroid Build Coastguard Worker 8795*9880d681SAndroid Build Coastguard WorkerSemantics: 8796*9880d681SAndroid Build Coastguard Worker"""""""""" 8797*9880d681SAndroid Build Coastguard Worker 8798*9880d681SAndroid Build Coastguard WorkerWhen the call stack is being unwound due to an exception being thrown, the 8799*9880d681SAndroid Build Coastguard Workerexception is compared against the ``args``. If it doesn't match, control will 8800*9880d681SAndroid Build Coastguard Workernot reach the ``catchpad`` instruction. The representation of ``args`` is 8801*9880d681SAndroid Build Coastguard Workerentirely target and personality function-specific. 8802*9880d681SAndroid Build Coastguard Worker 8803*9880d681SAndroid Build Coastguard WorkerLike the :ref:`landingpad <i_landingpad>` instruction, the ``catchpad`` 8804*9880d681SAndroid Build Coastguard Workerinstruction must be the first non-phi of its parent basic block. 8805*9880d681SAndroid Build Coastguard Worker 8806*9880d681SAndroid Build Coastguard WorkerThe meaning of the tokens produced and consumed by ``catchpad`` and other "pad" 8807*9880d681SAndroid Build Coastguard Workerinstructions is described in the 8808*9880d681SAndroid Build Coastguard Worker`Windows exception handling documentation\ <ExceptionHandling.html#wineh>`_. 8809*9880d681SAndroid Build Coastguard Worker 8810*9880d681SAndroid Build Coastguard WorkerWhen a ``catchpad`` has been "entered" but not yet "exited" (as 8811*9880d681SAndroid Build Coastguard Workerdescribed in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_), 8812*9880d681SAndroid Build Coastguard Workerit is undefined behavior to execute a :ref:`call <i_call>` or :ref:`invoke <i_invoke>` 8813*9880d681SAndroid Build Coastguard Workerthat does not carry an appropriate :ref:`"funclet" bundle <ob_funclet>`. 8814*9880d681SAndroid Build Coastguard Worker 8815*9880d681SAndroid Build Coastguard WorkerExample: 8816*9880d681SAndroid Build Coastguard Worker"""""""" 8817*9880d681SAndroid Build Coastguard Worker 8818*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 8819*9880d681SAndroid Build Coastguard Worker 8820*9880d681SAndroid Build Coastguard Worker dispatch: 8821*9880d681SAndroid Build Coastguard Worker %cs = catchswitch within none [label %handler0] unwind to caller 8822*9880d681SAndroid Build Coastguard Worker ;; A catch block which can catch an integer. 8823*9880d681SAndroid Build Coastguard Worker handler0: 8824*9880d681SAndroid Build Coastguard Worker %tok = catchpad within %cs [i8** @_ZTIi] 8825*9880d681SAndroid Build Coastguard Worker 8826*9880d681SAndroid Build Coastguard Worker.. _i_cleanuppad: 8827*9880d681SAndroid Build Coastguard Worker 8828*9880d681SAndroid Build Coastguard Worker'``cleanuppad``' Instruction 8829*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 8830*9880d681SAndroid Build Coastguard Worker 8831*9880d681SAndroid Build Coastguard WorkerSyntax: 8832*9880d681SAndroid Build Coastguard Worker""""""" 8833*9880d681SAndroid Build Coastguard Worker 8834*9880d681SAndroid Build Coastguard Worker:: 8835*9880d681SAndroid Build Coastguard Worker 8836*9880d681SAndroid Build Coastguard Worker <resultval> = cleanuppad within <parent> [<args>*] 8837*9880d681SAndroid Build Coastguard Worker 8838*9880d681SAndroid Build Coastguard WorkerOverview: 8839*9880d681SAndroid Build Coastguard Worker""""""""" 8840*9880d681SAndroid Build Coastguard Worker 8841*9880d681SAndroid Build Coastguard WorkerThe '``cleanuppad``' instruction is used by `LLVM's exception handling 8842*9880d681SAndroid Build Coastguard Workersystem <ExceptionHandling.html#overview>`_ to specify that a basic block 8843*9880d681SAndroid Build Coastguard Workeris a cleanup block --- one where a personality routine attempts to 8844*9880d681SAndroid Build Coastguard Workertransfer control to run cleanup actions. 8845*9880d681SAndroid Build Coastguard WorkerThe ``args`` correspond to whatever additional 8846*9880d681SAndroid Build Coastguard Workerinformation the :ref:`personality function <personalityfn>` requires to 8847*9880d681SAndroid Build Coastguard Workerexecute the cleanup. 8848*9880d681SAndroid Build Coastguard WorkerThe ``resultval`` has the type :ref:`token <t_token>` and is used to 8849*9880d681SAndroid Build Coastguard Workermatch the ``cleanuppad`` to corresponding :ref:`cleanuprets <i_cleanupret>`. 8850*9880d681SAndroid Build Coastguard WorkerThe ``parent`` argument is the token of the funclet that contains the 8851*9880d681SAndroid Build Coastguard Worker``cleanuppad`` instruction. If the ``cleanuppad`` is not inside a funclet, 8852*9880d681SAndroid Build Coastguard Workerthis operand may be the token ``none``. 8853*9880d681SAndroid Build Coastguard Worker 8854*9880d681SAndroid Build Coastguard WorkerArguments: 8855*9880d681SAndroid Build Coastguard Worker"""""""""" 8856*9880d681SAndroid Build Coastguard Worker 8857*9880d681SAndroid Build Coastguard WorkerThe instruction takes a list of arbitrary values which are interpreted 8858*9880d681SAndroid Build Coastguard Workerby the :ref:`personality function <personalityfn>`. 8859*9880d681SAndroid Build Coastguard Worker 8860*9880d681SAndroid Build Coastguard WorkerSemantics: 8861*9880d681SAndroid Build Coastguard Worker"""""""""" 8862*9880d681SAndroid Build Coastguard Worker 8863*9880d681SAndroid Build Coastguard WorkerWhen the call stack is being unwound due to an exception being thrown, 8864*9880d681SAndroid Build Coastguard Workerthe :ref:`personality function <personalityfn>` transfers control to the 8865*9880d681SAndroid Build Coastguard Worker``cleanuppad`` with the aid of the personality-specific arguments. 8866*9880d681SAndroid Build Coastguard WorkerAs with calling conventions, how the personality function results are 8867*9880d681SAndroid Build Coastguard Workerrepresented in LLVM IR is target specific. 8868*9880d681SAndroid Build Coastguard Worker 8869*9880d681SAndroid Build Coastguard WorkerThe ``cleanuppad`` instruction has several restrictions: 8870*9880d681SAndroid Build Coastguard Worker 8871*9880d681SAndroid Build Coastguard Worker- A cleanup block is a basic block which is the unwind destination of 8872*9880d681SAndroid Build Coastguard Worker an exceptional instruction. 8873*9880d681SAndroid Build Coastguard Worker- A cleanup block must have a '``cleanuppad``' instruction as its 8874*9880d681SAndroid Build Coastguard Worker first non-PHI instruction. 8875*9880d681SAndroid Build Coastguard Worker- There can be only one '``cleanuppad``' instruction within the 8876*9880d681SAndroid Build Coastguard Worker cleanup block. 8877*9880d681SAndroid Build Coastguard Worker- A basic block that is not a cleanup block may not include a 8878*9880d681SAndroid Build Coastguard Worker '``cleanuppad``' instruction. 8879*9880d681SAndroid Build Coastguard Worker 8880*9880d681SAndroid Build Coastguard WorkerWhen a ``cleanuppad`` has been "entered" but not yet "exited" (as 8881*9880d681SAndroid Build Coastguard Workerdescribed in the `EH documentation\ <ExceptionHandling.html#wineh-constraints>`_), 8882*9880d681SAndroid Build Coastguard Workerit is undefined behavior to execute a :ref:`call <i_call>` or :ref:`invoke <i_invoke>` 8883*9880d681SAndroid Build Coastguard Workerthat does not carry an appropriate :ref:`"funclet" bundle <ob_funclet>`. 8884*9880d681SAndroid Build Coastguard Worker 8885*9880d681SAndroid Build Coastguard WorkerExample: 8886*9880d681SAndroid Build Coastguard Worker"""""""" 8887*9880d681SAndroid Build Coastguard Worker 8888*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 8889*9880d681SAndroid Build Coastguard Worker 8890*9880d681SAndroid Build Coastguard Worker %tok = cleanuppad within %cs [] 8891*9880d681SAndroid Build Coastguard Worker 8892*9880d681SAndroid Build Coastguard Worker.. _intrinsics: 8893*9880d681SAndroid Build Coastguard Worker 8894*9880d681SAndroid Build Coastguard WorkerIntrinsic Functions 8895*9880d681SAndroid Build Coastguard Worker=================== 8896*9880d681SAndroid Build Coastguard Worker 8897*9880d681SAndroid Build Coastguard WorkerLLVM supports the notion of an "intrinsic function". These functions 8898*9880d681SAndroid Build Coastguard Workerhave well known names and semantics and are required to follow certain 8899*9880d681SAndroid Build Coastguard Workerrestrictions. Overall, these intrinsics represent an extension mechanism 8900*9880d681SAndroid Build Coastguard Workerfor the LLVM language that does not require changing all of the 8901*9880d681SAndroid Build Coastguard Workertransformations in LLVM when adding to the language (or the bitcode 8902*9880d681SAndroid Build Coastguard Workerreader/writer, the parser, etc...). 8903*9880d681SAndroid Build Coastguard Worker 8904*9880d681SAndroid Build Coastguard WorkerIntrinsic function names must all start with an "``llvm.``" prefix. This 8905*9880d681SAndroid Build Coastguard Workerprefix is reserved in LLVM for intrinsic names; thus, function names may 8906*9880d681SAndroid Build Coastguard Workernot begin with this prefix. Intrinsic functions must always be external 8907*9880d681SAndroid Build Coastguard Workerfunctions: you cannot define the body of intrinsic functions. Intrinsic 8908*9880d681SAndroid Build Coastguard Workerfunctions may only be used in call or invoke instructions: it is illegal 8909*9880d681SAndroid Build Coastguard Workerto take the address of an intrinsic function. Additionally, because 8910*9880d681SAndroid Build Coastguard Workerintrinsic functions are part of the LLVM language, it is required if any 8911*9880d681SAndroid Build Coastguard Workerare added that they be documented here. 8912*9880d681SAndroid Build Coastguard Worker 8913*9880d681SAndroid Build Coastguard WorkerSome intrinsic functions can be overloaded, i.e., the intrinsic 8914*9880d681SAndroid Build Coastguard Workerrepresents a family of functions that perform the same operation but on 8915*9880d681SAndroid Build Coastguard Workerdifferent data types. Because LLVM can represent over 8 million 8916*9880d681SAndroid Build Coastguard Workerdifferent integer types, overloading is used commonly to allow an 8917*9880d681SAndroid Build Coastguard Workerintrinsic function to operate on any integer type. One or more of the 8918*9880d681SAndroid Build Coastguard Workerargument types or the result type can be overloaded to accept any 8919*9880d681SAndroid Build Coastguard Workerinteger type. Argument types may also be defined as exactly matching a 8920*9880d681SAndroid Build Coastguard Workerprevious argument's type or the result type. This allows an intrinsic 8921*9880d681SAndroid Build Coastguard Workerfunction which accepts multiple arguments, but needs all of them to be 8922*9880d681SAndroid Build Coastguard Workerof the same type, to only be overloaded with respect to a single 8923*9880d681SAndroid Build Coastguard Workerargument or the result. 8924*9880d681SAndroid Build Coastguard Worker 8925*9880d681SAndroid Build Coastguard WorkerOverloaded intrinsics will have the names of its overloaded argument 8926*9880d681SAndroid Build Coastguard Workertypes encoded into its function name, each preceded by a period. Only 8927*9880d681SAndroid Build Coastguard Workerthose types which are overloaded result in a name suffix. Arguments 8928*9880d681SAndroid Build Coastguard Workerwhose type is matched against another type do not. For example, the 8929*9880d681SAndroid Build Coastguard Worker``llvm.ctpop`` function can take an integer of any width and returns an 8930*9880d681SAndroid Build Coastguard Workerinteger of exactly the same integer width. This leads to a family of 8931*9880d681SAndroid Build Coastguard Workerfunctions such as ``i8 @llvm.ctpop.i8(i8 %val)`` and 8932*9880d681SAndroid Build Coastguard Worker``i29 @llvm.ctpop.i29(i29 %val)``. Only one type, the return type, is 8933*9880d681SAndroid Build Coastguard Workeroverloaded, and only one type suffix is required. Because the argument's 8934*9880d681SAndroid Build Coastguard Workertype is matched against the return type, it does not require its own 8935*9880d681SAndroid Build Coastguard Workername suffix. 8936*9880d681SAndroid Build Coastguard Worker 8937*9880d681SAndroid Build Coastguard WorkerTo learn how to add an intrinsic function, please see the `Extending 8938*9880d681SAndroid Build Coastguard WorkerLLVM Guide <ExtendingLLVM.html>`_. 8939*9880d681SAndroid Build Coastguard Worker 8940*9880d681SAndroid Build Coastguard Worker.. _int_varargs: 8941*9880d681SAndroid Build Coastguard Worker 8942*9880d681SAndroid Build Coastguard WorkerVariable Argument Handling Intrinsics 8943*9880d681SAndroid Build Coastguard Worker------------------------------------- 8944*9880d681SAndroid Build Coastguard Worker 8945*9880d681SAndroid Build Coastguard WorkerVariable argument support is defined in LLVM with the 8946*9880d681SAndroid Build Coastguard Worker:ref:`va_arg <i_va_arg>` instruction and these three intrinsic 8947*9880d681SAndroid Build Coastguard Workerfunctions. These functions are related to the similarly named macros 8948*9880d681SAndroid Build Coastguard Workerdefined in the ``<stdarg.h>`` header file. 8949*9880d681SAndroid Build Coastguard Worker 8950*9880d681SAndroid Build Coastguard WorkerAll of these functions operate on arguments that use a target-specific 8951*9880d681SAndroid Build Coastguard Workervalue type "``va_list``". The LLVM assembly language reference manual 8952*9880d681SAndroid Build Coastguard Workerdoes not define what this type is, so all transformations should be 8953*9880d681SAndroid Build Coastguard Workerprepared to handle these functions regardless of the type used. 8954*9880d681SAndroid Build Coastguard Worker 8955*9880d681SAndroid Build Coastguard WorkerThis example shows how the :ref:`va_arg <i_va_arg>` instruction and the 8956*9880d681SAndroid Build Coastguard Workervariable argument handling intrinsic functions are used. 8957*9880d681SAndroid Build Coastguard Worker 8958*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 8959*9880d681SAndroid Build Coastguard Worker 8960*9880d681SAndroid Build Coastguard Worker ; This struct is different for every platform. For most platforms, 8961*9880d681SAndroid Build Coastguard Worker ; it is merely an i8*. 8962*9880d681SAndroid Build Coastguard Worker %struct.va_list = type { i8* } 8963*9880d681SAndroid Build Coastguard Worker 8964*9880d681SAndroid Build Coastguard Worker ; For Unix x86_64 platforms, va_list is the following struct: 8965*9880d681SAndroid Build Coastguard Worker ; %struct.va_list = type { i32, i32, i8*, i8* } 8966*9880d681SAndroid Build Coastguard Worker 8967*9880d681SAndroid Build Coastguard Worker define i32 @test(i32 %X, ...) { 8968*9880d681SAndroid Build Coastguard Worker ; Initialize variable argument processing 8969*9880d681SAndroid Build Coastguard Worker %ap = alloca %struct.va_list 8970*9880d681SAndroid Build Coastguard Worker %ap2 = bitcast %struct.va_list* %ap to i8* 8971*9880d681SAndroid Build Coastguard Worker call void @llvm.va_start(i8* %ap2) 8972*9880d681SAndroid Build Coastguard Worker 8973*9880d681SAndroid Build Coastguard Worker ; Read a single integer argument 8974*9880d681SAndroid Build Coastguard Worker %tmp = va_arg i8* %ap2, i32 8975*9880d681SAndroid Build Coastguard Worker 8976*9880d681SAndroid Build Coastguard Worker ; Demonstrate usage of llvm.va_copy and llvm.va_end 8977*9880d681SAndroid Build Coastguard Worker %aq = alloca i8* 8978*9880d681SAndroid Build Coastguard Worker %aq2 = bitcast i8** %aq to i8* 8979*9880d681SAndroid Build Coastguard Worker call void @llvm.va_copy(i8* %aq2, i8* %ap2) 8980*9880d681SAndroid Build Coastguard Worker call void @llvm.va_end(i8* %aq2) 8981*9880d681SAndroid Build Coastguard Worker 8982*9880d681SAndroid Build Coastguard Worker ; Stop processing of arguments. 8983*9880d681SAndroid Build Coastguard Worker call void @llvm.va_end(i8* %ap2) 8984*9880d681SAndroid Build Coastguard Worker ret i32 %tmp 8985*9880d681SAndroid Build Coastguard Worker } 8986*9880d681SAndroid Build Coastguard Worker 8987*9880d681SAndroid Build Coastguard Worker declare void @llvm.va_start(i8*) 8988*9880d681SAndroid Build Coastguard Worker declare void @llvm.va_copy(i8*, i8*) 8989*9880d681SAndroid Build Coastguard Worker declare void @llvm.va_end(i8*) 8990*9880d681SAndroid Build Coastguard Worker 8991*9880d681SAndroid Build Coastguard Worker.. _int_va_start: 8992*9880d681SAndroid Build Coastguard Worker 8993*9880d681SAndroid Build Coastguard Worker'``llvm.va_start``' Intrinsic 8994*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 8995*9880d681SAndroid Build Coastguard Worker 8996*9880d681SAndroid Build Coastguard WorkerSyntax: 8997*9880d681SAndroid Build Coastguard Worker""""""" 8998*9880d681SAndroid Build Coastguard Worker 8999*9880d681SAndroid Build Coastguard Worker:: 9000*9880d681SAndroid Build Coastguard Worker 9001*9880d681SAndroid Build Coastguard Worker declare void @llvm.va_start(i8* <arglist>) 9002*9880d681SAndroid Build Coastguard Worker 9003*9880d681SAndroid Build Coastguard WorkerOverview: 9004*9880d681SAndroid Build Coastguard Worker""""""""" 9005*9880d681SAndroid Build Coastguard Worker 9006*9880d681SAndroid Build Coastguard WorkerThe '``llvm.va_start``' intrinsic initializes ``*<arglist>`` for 9007*9880d681SAndroid Build Coastguard Workersubsequent use by ``va_arg``. 9008*9880d681SAndroid Build Coastguard Worker 9009*9880d681SAndroid Build Coastguard WorkerArguments: 9010*9880d681SAndroid Build Coastguard Worker"""""""""" 9011*9880d681SAndroid Build Coastguard Worker 9012*9880d681SAndroid Build Coastguard WorkerThe argument is a pointer to a ``va_list`` element to initialize. 9013*9880d681SAndroid Build Coastguard Worker 9014*9880d681SAndroid Build Coastguard WorkerSemantics: 9015*9880d681SAndroid Build Coastguard Worker"""""""""" 9016*9880d681SAndroid Build Coastguard Worker 9017*9880d681SAndroid Build Coastguard WorkerThe '``llvm.va_start``' intrinsic works just like the ``va_start`` macro 9018*9880d681SAndroid Build Coastguard Workeravailable in C. In a target-dependent way, it initializes the 9019*9880d681SAndroid Build Coastguard Worker``va_list`` element to which the argument points, so that the next call 9020*9880d681SAndroid Build Coastguard Workerto ``va_arg`` will produce the first variable argument passed to the 9021*9880d681SAndroid Build Coastguard Workerfunction. Unlike the C ``va_start`` macro, this intrinsic does not need 9022*9880d681SAndroid Build Coastguard Workerto know the last argument of the function as the compiler can figure 9023*9880d681SAndroid Build Coastguard Workerthat out. 9024*9880d681SAndroid Build Coastguard Worker 9025*9880d681SAndroid Build Coastguard Worker'``llvm.va_end``' Intrinsic 9026*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9027*9880d681SAndroid Build Coastguard Worker 9028*9880d681SAndroid Build Coastguard WorkerSyntax: 9029*9880d681SAndroid Build Coastguard Worker""""""" 9030*9880d681SAndroid Build Coastguard Worker 9031*9880d681SAndroid Build Coastguard Worker:: 9032*9880d681SAndroid Build Coastguard Worker 9033*9880d681SAndroid Build Coastguard Worker declare void @llvm.va_end(i8* <arglist>) 9034*9880d681SAndroid Build Coastguard Worker 9035*9880d681SAndroid Build Coastguard WorkerOverview: 9036*9880d681SAndroid Build Coastguard Worker""""""""" 9037*9880d681SAndroid Build Coastguard Worker 9038*9880d681SAndroid Build Coastguard WorkerThe '``llvm.va_end``' intrinsic destroys ``*<arglist>``, which has been 9039*9880d681SAndroid Build Coastguard Workerinitialized previously with ``llvm.va_start`` or ``llvm.va_copy``. 9040*9880d681SAndroid Build Coastguard Worker 9041*9880d681SAndroid Build Coastguard WorkerArguments: 9042*9880d681SAndroid Build Coastguard Worker"""""""""" 9043*9880d681SAndroid Build Coastguard Worker 9044*9880d681SAndroid Build Coastguard WorkerThe argument is a pointer to a ``va_list`` to destroy. 9045*9880d681SAndroid Build Coastguard Worker 9046*9880d681SAndroid Build Coastguard WorkerSemantics: 9047*9880d681SAndroid Build Coastguard Worker"""""""""" 9048*9880d681SAndroid Build Coastguard Worker 9049*9880d681SAndroid Build Coastguard WorkerThe '``llvm.va_end``' intrinsic works just like the ``va_end`` macro 9050*9880d681SAndroid Build Coastguard Workeravailable in C. In a target-dependent way, it destroys the ``va_list`` 9051*9880d681SAndroid Build Coastguard Workerelement to which the argument points. Calls to 9052*9880d681SAndroid Build Coastguard Worker:ref:`llvm.va_start <int_va_start>` and 9053*9880d681SAndroid Build Coastguard Worker:ref:`llvm.va_copy <int_va_copy>` must be matched exactly with calls to 9054*9880d681SAndroid Build Coastguard Worker``llvm.va_end``. 9055*9880d681SAndroid Build Coastguard Worker 9056*9880d681SAndroid Build Coastguard Worker.. _int_va_copy: 9057*9880d681SAndroid Build Coastguard Worker 9058*9880d681SAndroid Build Coastguard Worker'``llvm.va_copy``' Intrinsic 9059*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9060*9880d681SAndroid Build Coastguard Worker 9061*9880d681SAndroid Build Coastguard WorkerSyntax: 9062*9880d681SAndroid Build Coastguard Worker""""""" 9063*9880d681SAndroid Build Coastguard Worker 9064*9880d681SAndroid Build Coastguard Worker:: 9065*9880d681SAndroid Build Coastguard Worker 9066*9880d681SAndroid Build Coastguard Worker declare void @llvm.va_copy(i8* <destarglist>, i8* <srcarglist>) 9067*9880d681SAndroid Build Coastguard Worker 9068*9880d681SAndroid Build Coastguard WorkerOverview: 9069*9880d681SAndroid Build Coastguard Worker""""""""" 9070*9880d681SAndroid Build Coastguard Worker 9071*9880d681SAndroid Build Coastguard WorkerThe '``llvm.va_copy``' intrinsic copies the current argument position 9072*9880d681SAndroid Build Coastguard Workerfrom the source argument list to the destination argument list. 9073*9880d681SAndroid Build Coastguard Worker 9074*9880d681SAndroid Build Coastguard WorkerArguments: 9075*9880d681SAndroid Build Coastguard Worker"""""""""" 9076*9880d681SAndroid Build Coastguard Worker 9077*9880d681SAndroid Build Coastguard WorkerThe first argument is a pointer to a ``va_list`` element to initialize. 9078*9880d681SAndroid Build Coastguard WorkerThe second argument is a pointer to a ``va_list`` element to copy from. 9079*9880d681SAndroid Build Coastguard Worker 9080*9880d681SAndroid Build Coastguard WorkerSemantics: 9081*9880d681SAndroid Build Coastguard Worker"""""""""" 9082*9880d681SAndroid Build Coastguard Worker 9083*9880d681SAndroid Build Coastguard WorkerThe '``llvm.va_copy``' intrinsic works just like the ``va_copy`` macro 9084*9880d681SAndroid Build Coastguard Workeravailable in C. In a target-dependent way, it copies the source 9085*9880d681SAndroid Build Coastguard Worker``va_list`` element into the destination ``va_list`` element. This 9086*9880d681SAndroid Build Coastguard Workerintrinsic is necessary because the `` llvm.va_start`` intrinsic may be 9087*9880d681SAndroid Build Coastguard Workerarbitrarily complex and require, for example, memory allocation. 9088*9880d681SAndroid Build Coastguard Worker 9089*9880d681SAndroid Build Coastguard WorkerAccurate Garbage Collection Intrinsics 9090*9880d681SAndroid Build Coastguard Worker-------------------------------------- 9091*9880d681SAndroid Build Coastguard Worker 9092*9880d681SAndroid Build Coastguard WorkerLLVM's support for `Accurate Garbage Collection <GarbageCollection.html>`_ 9093*9880d681SAndroid Build Coastguard Worker(GC) requires the frontend to generate code containing appropriate intrinsic 9094*9880d681SAndroid Build Coastguard Workercalls and select an appropriate GC strategy which knows how to lower these 9095*9880d681SAndroid Build Coastguard Workerintrinsics in a manner which is appropriate for the target collector. 9096*9880d681SAndroid Build Coastguard Worker 9097*9880d681SAndroid Build Coastguard WorkerThese intrinsics allow identification of :ref:`GC roots on the 9098*9880d681SAndroid Build Coastguard Workerstack <int_gcroot>`, as well as garbage collector implementations that 9099*9880d681SAndroid Build Coastguard Workerrequire :ref:`read <int_gcread>` and :ref:`write <int_gcwrite>` barriers. 9100*9880d681SAndroid Build Coastguard WorkerFrontends for type-safe garbage collected languages should generate 9101*9880d681SAndroid Build Coastguard Workerthese intrinsics to make use of the LLVM garbage collectors. For more 9102*9880d681SAndroid Build Coastguard Workerdetails, see `Garbage Collection with LLVM <GarbageCollection.html>`_. 9103*9880d681SAndroid Build Coastguard Worker 9104*9880d681SAndroid Build Coastguard WorkerExperimental Statepoint Intrinsics 9105*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9106*9880d681SAndroid Build Coastguard Worker 9107*9880d681SAndroid Build Coastguard WorkerLLVM provides an second experimental set of intrinsics for describing garbage 9108*9880d681SAndroid Build Coastguard Workercollection safepoints in compiled code. These intrinsics are an alternative 9109*9880d681SAndroid Build Coastguard Workerto the ``llvm.gcroot`` intrinsics, but are compatible with the ones for 9110*9880d681SAndroid Build Coastguard Worker:ref:`read <int_gcread>` and :ref:`write <int_gcwrite>` barriers. The 9111*9880d681SAndroid Build Coastguard Workerdifferences in approach are covered in the `Garbage Collection with LLVM 9112*9880d681SAndroid Build Coastguard Worker<GarbageCollection.html>`_ documentation. The intrinsics themselves are 9113*9880d681SAndroid Build Coastguard Workerdescribed in :doc:`Statepoints`. 9114*9880d681SAndroid Build Coastguard Worker 9115*9880d681SAndroid Build Coastguard Worker.. _int_gcroot: 9116*9880d681SAndroid Build Coastguard Worker 9117*9880d681SAndroid Build Coastguard Worker'``llvm.gcroot``' Intrinsic 9118*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9119*9880d681SAndroid Build Coastguard Worker 9120*9880d681SAndroid Build Coastguard WorkerSyntax: 9121*9880d681SAndroid Build Coastguard Worker""""""" 9122*9880d681SAndroid Build Coastguard Worker 9123*9880d681SAndroid Build Coastguard Worker:: 9124*9880d681SAndroid Build Coastguard Worker 9125*9880d681SAndroid Build Coastguard Worker declare void @llvm.gcroot(i8** %ptrloc, i8* %metadata) 9126*9880d681SAndroid Build Coastguard Worker 9127*9880d681SAndroid Build Coastguard WorkerOverview: 9128*9880d681SAndroid Build Coastguard Worker""""""""" 9129*9880d681SAndroid Build Coastguard Worker 9130*9880d681SAndroid Build Coastguard WorkerThe '``llvm.gcroot``' intrinsic declares the existence of a GC root to 9131*9880d681SAndroid Build Coastguard Workerthe code generator, and allows some metadata to be associated with it. 9132*9880d681SAndroid Build Coastguard Worker 9133*9880d681SAndroid Build Coastguard WorkerArguments: 9134*9880d681SAndroid Build Coastguard Worker"""""""""" 9135*9880d681SAndroid Build Coastguard Worker 9136*9880d681SAndroid Build Coastguard WorkerThe first argument specifies the address of a stack object that contains 9137*9880d681SAndroid Build Coastguard Workerthe root pointer. The second pointer (which must be either a constant or 9138*9880d681SAndroid Build Coastguard Workera global value address) contains the meta-data to be associated with the 9139*9880d681SAndroid Build Coastguard Workerroot. 9140*9880d681SAndroid Build Coastguard Worker 9141*9880d681SAndroid Build Coastguard WorkerSemantics: 9142*9880d681SAndroid Build Coastguard Worker"""""""""" 9143*9880d681SAndroid Build Coastguard Worker 9144*9880d681SAndroid Build Coastguard WorkerAt runtime, a call to this intrinsic stores a null pointer into the 9145*9880d681SAndroid Build Coastguard Worker"ptrloc" location. At compile-time, the code generator generates 9146*9880d681SAndroid Build Coastguard Workerinformation to allow the runtime to find the pointer at GC safe points. 9147*9880d681SAndroid Build Coastguard WorkerThe '``llvm.gcroot``' intrinsic may only be used in a function which 9148*9880d681SAndroid Build Coastguard Worker:ref:`specifies a GC algorithm <gc>`. 9149*9880d681SAndroid Build Coastguard Worker 9150*9880d681SAndroid Build Coastguard Worker.. _int_gcread: 9151*9880d681SAndroid Build Coastguard Worker 9152*9880d681SAndroid Build Coastguard Worker'``llvm.gcread``' Intrinsic 9153*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9154*9880d681SAndroid Build Coastguard Worker 9155*9880d681SAndroid Build Coastguard WorkerSyntax: 9156*9880d681SAndroid Build Coastguard Worker""""""" 9157*9880d681SAndroid Build Coastguard Worker 9158*9880d681SAndroid Build Coastguard Worker:: 9159*9880d681SAndroid Build Coastguard Worker 9160*9880d681SAndroid Build Coastguard Worker declare i8* @llvm.gcread(i8* %ObjPtr, i8** %Ptr) 9161*9880d681SAndroid Build Coastguard Worker 9162*9880d681SAndroid Build Coastguard WorkerOverview: 9163*9880d681SAndroid Build Coastguard Worker""""""""" 9164*9880d681SAndroid Build Coastguard Worker 9165*9880d681SAndroid Build Coastguard WorkerThe '``llvm.gcread``' intrinsic identifies reads of references from heap 9166*9880d681SAndroid Build Coastguard Workerlocations, allowing garbage collector implementations that require read 9167*9880d681SAndroid Build Coastguard Workerbarriers. 9168*9880d681SAndroid Build Coastguard Worker 9169*9880d681SAndroid Build Coastguard WorkerArguments: 9170*9880d681SAndroid Build Coastguard Worker"""""""""" 9171*9880d681SAndroid Build Coastguard Worker 9172*9880d681SAndroid Build Coastguard WorkerThe second argument is the address to read from, which should be an 9173*9880d681SAndroid Build Coastguard Workeraddress allocated from the garbage collector. The first object is a 9174*9880d681SAndroid Build Coastguard Workerpointer to the start of the referenced object, if needed by the language 9175*9880d681SAndroid Build Coastguard Workerruntime (otherwise null). 9176*9880d681SAndroid Build Coastguard Worker 9177*9880d681SAndroid Build Coastguard WorkerSemantics: 9178*9880d681SAndroid Build Coastguard Worker"""""""""" 9179*9880d681SAndroid Build Coastguard Worker 9180*9880d681SAndroid Build Coastguard WorkerThe '``llvm.gcread``' intrinsic has the same semantics as a load 9181*9880d681SAndroid Build Coastguard Workerinstruction, but may be replaced with substantially more complex code by 9182*9880d681SAndroid Build Coastguard Workerthe garbage collector runtime, as needed. The '``llvm.gcread``' 9183*9880d681SAndroid Build Coastguard Workerintrinsic may only be used in a function which :ref:`specifies a GC 9184*9880d681SAndroid Build Coastguard Workeralgorithm <gc>`. 9185*9880d681SAndroid Build Coastguard Worker 9186*9880d681SAndroid Build Coastguard Worker.. _int_gcwrite: 9187*9880d681SAndroid Build Coastguard Worker 9188*9880d681SAndroid Build Coastguard Worker'``llvm.gcwrite``' Intrinsic 9189*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9190*9880d681SAndroid Build Coastguard Worker 9191*9880d681SAndroid Build Coastguard WorkerSyntax: 9192*9880d681SAndroid Build Coastguard Worker""""""" 9193*9880d681SAndroid Build Coastguard Worker 9194*9880d681SAndroid Build Coastguard Worker:: 9195*9880d681SAndroid Build Coastguard Worker 9196*9880d681SAndroid Build Coastguard Worker declare void @llvm.gcwrite(i8* %P1, i8* %Obj, i8** %P2) 9197*9880d681SAndroid Build Coastguard Worker 9198*9880d681SAndroid Build Coastguard WorkerOverview: 9199*9880d681SAndroid Build Coastguard Worker""""""""" 9200*9880d681SAndroid Build Coastguard Worker 9201*9880d681SAndroid Build Coastguard WorkerThe '``llvm.gcwrite``' intrinsic identifies writes of references to heap 9202*9880d681SAndroid Build Coastguard Workerlocations, allowing garbage collector implementations that require write 9203*9880d681SAndroid Build Coastguard Workerbarriers (such as generational or reference counting collectors). 9204*9880d681SAndroid Build Coastguard Worker 9205*9880d681SAndroid Build Coastguard WorkerArguments: 9206*9880d681SAndroid Build Coastguard Worker"""""""""" 9207*9880d681SAndroid Build Coastguard Worker 9208*9880d681SAndroid Build Coastguard WorkerThe first argument is the reference to store, the second is the start of 9209*9880d681SAndroid Build Coastguard Workerthe object to store it to, and the third is the address of the field of 9210*9880d681SAndroid Build Coastguard WorkerObj to store to. If the runtime does not require a pointer to the 9211*9880d681SAndroid Build Coastguard Workerobject, Obj may be null. 9212*9880d681SAndroid Build Coastguard Worker 9213*9880d681SAndroid Build Coastguard WorkerSemantics: 9214*9880d681SAndroid Build Coastguard Worker"""""""""" 9215*9880d681SAndroid Build Coastguard Worker 9216*9880d681SAndroid Build Coastguard WorkerThe '``llvm.gcwrite``' intrinsic has the same semantics as a store 9217*9880d681SAndroid Build Coastguard Workerinstruction, but may be replaced with substantially more complex code by 9218*9880d681SAndroid Build Coastguard Workerthe garbage collector runtime, as needed. The '``llvm.gcwrite``' 9219*9880d681SAndroid Build Coastguard Workerintrinsic may only be used in a function which :ref:`specifies a GC 9220*9880d681SAndroid Build Coastguard Workeralgorithm <gc>`. 9221*9880d681SAndroid Build Coastguard Worker 9222*9880d681SAndroid Build Coastguard WorkerCode Generator Intrinsics 9223*9880d681SAndroid Build Coastguard Worker------------------------- 9224*9880d681SAndroid Build Coastguard Worker 9225*9880d681SAndroid Build Coastguard WorkerThese intrinsics are provided by LLVM to expose special features that 9226*9880d681SAndroid Build Coastguard Workermay only be implemented with code generator support. 9227*9880d681SAndroid Build Coastguard Worker 9228*9880d681SAndroid Build Coastguard Worker'``llvm.returnaddress``' Intrinsic 9229*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9230*9880d681SAndroid Build Coastguard Worker 9231*9880d681SAndroid Build Coastguard WorkerSyntax: 9232*9880d681SAndroid Build Coastguard Worker""""""" 9233*9880d681SAndroid Build Coastguard Worker 9234*9880d681SAndroid Build Coastguard Worker:: 9235*9880d681SAndroid Build Coastguard Worker 9236*9880d681SAndroid Build Coastguard Worker declare i8 *@llvm.returnaddress(i32 <level>) 9237*9880d681SAndroid Build Coastguard Worker 9238*9880d681SAndroid Build Coastguard WorkerOverview: 9239*9880d681SAndroid Build Coastguard Worker""""""""" 9240*9880d681SAndroid Build Coastguard Worker 9241*9880d681SAndroid Build Coastguard WorkerThe '``llvm.returnaddress``' intrinsic attempts to compute a 9242*9880d681SAndroid Build Coastguard Workertarget-specific value indicating the return address of the current 9243*9880d681SAndroid Build Coastguard Workerfunction or one of its callers. 9244*9880d681SAndroid Build Coastguard Worker 9245*9880d681SAndroid Build Coastguard WorkerArguments: 9246*9880d681SAndroid Build Coastguard Worker"""""""""" 9247*9880d681SAndroid Build Coastguard Worker 9248*9880d681SAndroid Build Coastguard WorkerThe argument to this intrinsic indicates which function to return the 9249*9880d681SAndroid Build Coastguard Workeraddress for. Zero indicates the calling function, one indicates its 9250*9880d681SAndroid Build Coastguard Workercaller, etc. The argument is **required** to be a constant integer 9251*9880d681SAndroid Build Coastguard Workervalue. 9252*9880d681SAndroid Build Coastguard Worker 9253*9880d681SAndroid Build Coastguard WorkerSemantics: 9254*9880d681SAndroid Build Coastguard Worker"""""""""" 9255*9880d681SAndroid Build Coastguard Worker 9256*9880d681SAndroid Build Coastguard WorkerThe '``llvm.returnaddress``' intrinsic either returns a pointer 9257*9880d681SAndroid Build Coastguard Workerindicating the return address of the specified call frame, or zero if it 9258*9880d681SAndroid Build Coastguard Workercannot be identified. The value returned by this intrinsic is likely to 9259*9880d681SAndroid Build Coastguard Workerbe incorrect or 0 for arguments other than zero, so it should only be 9260*9880d681SAndroid Build Coastguard Workerused for debugging purposes. 9261*9880d681SAndroid Build Coastguard Worker 9262*9880d681SAndroid Build Coastguard WorkerNote that calling this intrinsic does not prevent function inlining or 9263*9880d681SAndroid Build Coastguard Workerother aggressive transformations, so the value returned may not be that 9264*9880d681SAndroid Build Coastguard Workerof the obvious source-language caller. 9265*9880d681SAndroid Build Coastguard Worker 9266*9880d681SAndroid Build Coastguard Worker'``llvm.frameaddress``' Intrinsic 9267*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9268*9880d681SAndroid Build Coastguard Worker 9269*9880d681SAndroid Build Coastguard WorkerSyntax: 9270*9880d681SAndroid Build Coastguard Worker""""""" 9271*9880d681SAndroid Build Coastguard Worker 9272*9880d681SAndroid Build Coastguard Worker:: 9273*9880d681SAndroid Build Coastguard Worker 9274*9880d681SAndroid Build Coastguard Worker declare i8* @llvm.frameaddress(i32 <level>) 9275*9880d681SAndroid Build Coastguard Worker 9276*9880d681SAndroid Build Coastguard WorkerOverview: 9277*9880d681SAndroid Build Coastguard Worker""""""""" 9278*9880d681SAndroid Build Coastguard Worker 9279*9880d681SAndroid Build Coastguard WorkerThe '``llvm.frameaddress``' intrinsic attempts to return the 9280*9880d681SAndroid Build Coastguard Workertarget-specific frame pointer value for the specified stack frame. 9281*9880d681SAndroid Build Coastguard Worker 9282*9880d681SAndroid Build Coastguard WorkerArguments: 9283*9880d681SAndroid Build Coastguard Worker"""""""""" 9284*9880d681SAndroid Build Coastguard Worker 9285*9880d681SAndroid Build Coastguard WorkerThe argument to this intrinsic indicates which function to return the 9286*9880d681SAndroid Build Coastguard Workerframe pointer for. Zero indicates the calling function, one indicates 9287*9880d681SAndroid Build Coastguard Workerits caller, etc. The argument is **required** to be a constant integer 9288*9880d681SAndroid Build Coastguard Workervalue. 9289*9880d681SAndroid Build Coastguard Worker 9290*9880d681SAndroid Build Coastguard WorkerSemantics: 9291*9880d681SAndroid Build Coastguard Worker"""""""""" 9292*9880d681SAndroid Build Coastguard Worker 9293*9880d681SAndroid Build Coastguard WorkerThe '``llvm.frameaddress``' intrinsic either returns a pointer 9294*9880d681SAndroid Build Coastguard Workerindicating the frame address of the specified call frame, or zero if it 9295*9880d681SAndroid Build Coastguard Workercannot be identified. The value returned by this intrinsic is likely to 9296*9880d681SAndroid Build Coastguard Workerbe incorrect or 0 for arguments other than zero, so it should only be 9297*9880d681SAndroid Build Coastguard Workerused for debugging purposes. 9298*9880d681SAndroid Build Coastguard Worker 9299*9880d681SAndroid Build Coastguard WorkerNote that calling this intrinsic does not prevent function inlining or 9300*9880d681SAndroid Build Coastguard Workerother aggressive transformations, so the value returned may not be that 9301*9880d681SAndroid Build Coastguard Workerof the obvious source-language caller. 9302*9880d681SAndroid Build Coastguard Worker 9303*9880d681SAndroid Build Coastguard Worker'``llvm.localescape``' and '``llvm.localrecover``' Intrinsics 9304*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9305*9880d681SAndroid Build Coastguard Worker 9306*9880d681SAndroid Build Coastguard WorkerSyntax: 9307*9880d681SAndroid Build Coastguard Worker""""""" 9308*9880d681SAndroid Build Coastguard Worker 9309*9880d681SAndroid Build Coastguard Worker:: 9310*9880d681SAndroid Build Coastguard Worker 9311*9880d681SAndroid Build Coastguard Worker declare void @llvm.localescape(...) 9312*9880d681SAndroid Build Coastguard Worker declare i8* @llvm.localrecover(i8* %func, i8* %fp, i32 %idx) 9313*9880d681SAndroid Build Coastguard Worker 9314*9880d681SAndroid Build Coastguard WorkerOverview: 9315*9880d681SAndroid Build Coastguard Worker""""""""" 9316*9880d681SAndroid Build Coastguard Worker 9317*9880d681SAndroid Build Coastguard WorkerThe '``llvm.localescape``' intrinsic escapes offsets of a collection of static 9318*9880d681SAndroid Build Coastguard Workerallocas, and the '``llvm.localrecover``' intrinsic applies those offsets to a 9319*9880d681SAndroid Build Coastguard Workerlive frame pointer to recover the address of the allocation. The offset is 9320*9880d681SAndroid Build Coastguard Workercomputed during frame layout of the caller of ``llvm.localescape``. 9321*9880d681SAndroid Build Coastguard Worker 9322*9880d681SAndroid Build Coastguard WorkerArguments: 9323*9880d681SAndroid Build Coastguard Worker"""""""""" 9324*9880d681SAndroid Build Coastguard Worker 9325*9880d681SAndroid Build Coastguard WorkerAll arguments to '``llvm.localescape``' must be pointers to static allocas or 9326*9880d681SAndroid Build Coastguard Workercasts of static allocas. Each function can only call '``llvm.localescape``' 9327*9880d681SAndroid Build Coastguard Workeronce, and it can only do so from the entry block. 9328*9880d681SAndroid Build Coastguard Worker 9329*9880d681SAndroid Build Coastguard WorkerThe ``func`` argument to '``llvm.localrecover``' must be a constant 9330*9880d681SAndroid Build Coastguard Workerbitcasted pointer to a function defined in the current module. The code 9331*9880d681SAndroid Build Coastguard Workergenerator cannot determine the frame allocation offset of functions defined in 9332*9880d681SAndroid Build Coastguard Workerother modules. 9333*9880d681SAndroid Build Coastguard Worker 9334*9880d681SAndroid Build Coastguard WorkerThe ``fp`` argument to '``llvm.localrecover``' must be a frame pointer of a 9335*9880d681SAndroid Build Coastguard Workercall frame that is currently live. The return value of '``llvm.localaddress``' 9336*9880d681SAndroid Build Coastguard Workeris one way to produce such a value, but various runtimes also expose a suitable 9337*9880d681SAndroid Build Coastguard Workerpointer in platform-specific ways. 9338*9880d681SAndroid Build Coastguard Worker 9339*9880d681SAndroid Build Coastguard WorkerThe ``idx`` argument to '``llvm.localrecover``' indicates which alloca passed to 9340*9880d681SAndroid Build Coastguard Worker'``llvm.localescape``' to recover. It is zero-indexed. 9341*9880d681SAndroid Build Coastguard Worker 9342*9880d681SAndroid Build Coastguard WorkerSemantics: 9343*9880d681SAndroid Build Coastguard Worker"""""""""" 9344*9880d681SAndroid Build Coastguard Worker 9345*9880d681SAndroid Build Coastguard WorkerThese intrinsics allow a group of functions to share access to a set of local 9346*9880d681SAndroid Build Coastguard Workerstack allocations of a one parent function. The parent function may call the 9347*9880d681SAndroid Build Coastguard Worker'``llvm.localescape``' intrinsic once from the function entry block, and the 9348*9880d681SAndroid Build Coastguard Workerchild functions can use '``llvm.localrecover``' to access the escaped allocas. 9349*9880d681SAndroid Build Coastguard WorkerThe '``llvm.localescape``' intrinsic blocks inlining, as inlining changes where 9350*9880d681SAndroid Build Coastguard Workerthe escaped allocas are allocated, which would break attempts to use 9351*9880d681SAndroid Build Coastguard Worker'``llvm.localrecover``'. 9352*9880d681SAndroid Build Coastguard Worker 9353*9880d681SAndroid Build Coastguard Worker.. _int_read_register: 9354*9880d681SAndroid Build Coastguard Worker.. _int_write_register: 9355*9880d681SAndroid Build Coastguard Worker 9356*9880d681SAndroid Build Coastguard Worker'``llvm.read_register``' and '``llvm.write_register``' Intrinsics 9357*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9358*9880d681SAndroid Build Coastguard Worker 9359*9880d681SAndroid Build Coastguard WorkerSyntax: 9360*9880d681SAndroid Build Coastguard Worker""""""" 9361*9880d681SAndroid Build Coastguard Worker 9362*9880d681SAndroid Build Coastguard Worker:: 9363*9880d681SAndroid Build Coastguard Worker 9364*9880d681SAndroid Build Coastguard Worker declare i32 @llvm.read_register.i32(metadata) 9365*9880d681SAndroid Build Coastguard Worker declare i64 @llvm.read_register.i64(metadata) 9366*9880d681SAndroid Build Coastguard Worker declare void @llvm.write_register.i32(metadata, i32 @value) 9367*9880d681SAndroid Build Coastguard Worker declare void @llvm.write_register.i64(metadata, i64 @value) 9368*9880d681SAndroid Build Coastguard Worker !0 = !{!"sp\00"} 9369*9880d681SAndroid Build Coastguard Worker 9370*9880d681SAndroid Build Coastguard WorkerOverview: 9371*9880d681SAndroid Build Coastguard Worker""""""""" 9372*9880d681SAndroid Build Coastguard Worker 9373*9880d681SAndroid Build Coastguard WorkerThe '``llvm.read_register``' and '``llvm.write_register``' intrinsics 9374*9880d681SAndroid Build Coastguard Workerprovides access to the named register. The register must be valid on 9375*9880d681SAndroid Build Coastguard Workerthe architecture being compiled to. The type needs to be compatible 9376*9880d681SAndroid Build Coastguard Workerwith the register being read. 9377*9880d681SAndroid Build Coastguard Worker 9378*9880d681SAndroid Build Coastguard WorkerSemantics: 9379*9880d681SAndroid Build Coastguard Worker"""""""""" 9380*9880d681SAndroid Build Coastguard Worker 9381*9880d681SAndroid Build Coastguard WorkerThe '``llvm.read_register``' intrinsic returns the current value of the 9382*9880d681SAndroid Build Coastguard Workerregister, where possible. The '``llvm.write_register``' intrinsic sets 9383*9880d681SAndroid Build Coastguard Workerthe current value of the register, where possible. 9384*9880d681SAndroid Build Coastguard Worker 9385*9880d681SAndroid Build Coastguard WorkerThis is useful to implement named register global variables that need 9386*9880d681SAndroid Build Coastguard Workerto always be mapped to a specific register, as is common practice on 9387*9880d681SAndroid Build Coastguard Workerbare-metal programs including OS kernels. 9388*9880d681SAndroid Build Coastguard Worker 9389*9880d681SAndroid Build Coastguard WorkerThe compiler doesn't check for register availability or use of the used 9390*9880d681SAndroid Build Coastguard Workerregister in surrounding code, including inline assembly. Because of that, 9391*9880d681SAndroid Build Coastguard Workerallocatable registers are not supported. 9392*9880d681SAndroid Build Coastguard Worker 9393*9880d681SAndroid Build Coastguard WorkerWarning: So far it only works with the stack pointer on selected 9394*9880d681SAndroid Build Coastguard Workerarchitectures (ARM, AArch64, PowerPC and x86_64). Significant amount of 9395*9880d681SAndroid Build Coastguard Workerwork is needed to support other registers and even more so, allocatable 9396*9880d681SAndroid Build Coastguard Workerregisters. 9397*9880d681SAndroid Build Coastguard Worker 9398*9880d681SAndroid Build Coastguard Worker.. _int_stacksave: 9399*9880d681SAndroid Build Coastguard Worker 9400*9880d681SAndroid Build Coastguard Worker'``llvm.stacksave``' Intrinsic 9401*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9402*9880d681SAndroid Build Coastguard Worker 9403*9880d681SAndroid Build Coastguard WorkerSyntax: 9404*9880d681SAndroid Build Coastguard Worker""""""" 9405*9880d681SAndroid Build Coastguard Worker 9406*9880d681SAndroid Build Coastguard Worker:: 9407*9880d681SAndroid Build Coastguard Worker 9408*9880d681SAndroid Build Coastguard Worker declare i8* @llvm.stacksave() 9409*9880d681SAndroid Build Coastguard Worker 9410*9880d681SAndroid Build Coastguard WorkerOverview: 9411*9880d681SAndroid Build Coastguard Worker""""""""" 9412*9880d681SAndroid Build Coastguard Worker 9413*9880d681SAndroid Build Coastguard WorkerThe '``llvm.stacksave``' intrinsic is used to remember the current state 9414*9880d681SAndroid Build Coastguard Workerof the function stack, for use with 9415*9880d681SAndroid Build Coastguard Worker:ref:`llvm.stackrestore <int_stackrestore>`. This is useful for 9416*9880d681SAndroid Build Coastguard Workerimplementing language features like scoped automatic variable sized 9417*9880d681SAndroid Build Coastguard Workerarrays in C99. 9418*9880d681SAndroid Build Coastguard Worker 9419*9880d681SAndroid Build Coastguard WorkerSemantics: 9420*9880d681SAndroid Build Coastguard Worker"""""""""" 9421*9880d681SAndroid Build Coastguard Worker 9422*9880d681SAndroid Build Coastguard WorkerThis intrinsic returns a opaque pointer value that can be passed to 9423*9880d681SAndroid Build Coastguard Worker:ref:`llvm.stackrestore <int_stackrestore>`. When an 9424*9880d681SAndroid Build Coastguard Worker``llvm.stackrestore`` intrinsic is executed with a value saved from 9425*9880d681SAndroid Build Coastguard Worker``llvm.stacksave``, it effectively restores the state of the stack to 9426*9880d681SAndroid Build Coastguard Workerthe state it was in when the ``llvm.stacksave`` intrinsic executed. In 9427*9880d681SAndroid Build Coastguard Workerpractice, this pops any :ref:`alloca <i_alloca>` blocks from the stack that 9428*9880d681SAndroid Build Coastguard Workerwere allocated after the ``llvm.stacksave`` was executed. 9429*9880d681SAndroid Build Coastguard Worker 9430*9880d681SAndroid Build Coastguard Worker.. _int_stackrestore: 9431*9880d681SAndroid Build Coastguard Worker 9432*9880d681SAndroid Build Coastguard Worker'``llvm.stackrestore``' Intrinsic 9433*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9434*9880d681SAndroid Build Coastguard Worker 9435*9880d681SAndroid Build Coastguard WorkerSyntax: 9436*9880d681SAndroid Build Coastguard Worker""""""" 9437*9880d681SAndroid Build Coastguard Worker 9438*9880d681SAndroid Build Coastguard Worker:: 9439*9880d681SAndroid Build Coastguard Worker 9440*9880d681SAndroid Build Coastguard Worker declare void @llvm.stackrestore(i8* %ptr) 9441*9880d681SAndroid Build Coastguard Worker 9442*9880d681SAndroid Build Coastguard WorkerOverview: 9443*9880d681SAndroid Build Coastguard Worker""""""""" 9444*9880d681SAndroid Build Coastguard Worker 9445*9880d681SAndroid Build Coastguard WorkerThe '``llvm.stackrestore``' intrinsic is used to restore the state of 9446*9880d681SAndroid Build Coastguard Workerthe function stack to the state it was in when the corresponding 9447*9880d681SAndroid Build Coastguard Worker:ref:`llvm.stacksave <int_stacksave>` intrinsic executed. This is 9448*9880d681SAndroid Build Coastguard Workeruseful for implementing language features like scoped automatic variable 9449*9880d681SAndroid Build Coastguard Workersized arrays in C99. 9450*9880d681SAndroid Build Coastguard Worker 9451*9880d681SAndroid Build Coastguard WorkerSemantics: 9452*9880d681SAndroid Build Coastguard Worker"""""""""" 9453*9880d681SAndroid Build Coastguard Worker 9454*9880d681SAndroid Build Coastguard WorkerSee the description for :ref:`llvm.stacksave <int_stacksave>`. 9455*9880d681SAndroid Build Coastguard Worker 9456*9880d681SAndroid Build Coastguard Worker.. _int_get_dynamic_area_offset: 9457*9880d681SAndroid Build Coastguard Worker 9458*9880d681SAndroid Build Coastguard Worker'``llvm.get.dynamic.area.offset``' Intrinsic 9459*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9460*9880d681SAndroid Build Coastguard Worker 9461*9880d681SAndroid Build Coastguard WorkerSyntax: 9462*9880d681SAndroid Build Coastguard Worker""""""" 9463*9880d681SAndroid Build Coastguard Worker 9464*9880d681SAndroid Build Coastguard Worker:: 9465*9880d681SAndroid Build Coastguard Worker 9466*9880d681SAndroid Build Coastguard Worker declare i32 @llvm.get.dynamic.area.offset.i32() 9467*9880d681SAndroid Build Coastguard Worker declare i64 @llvm.get.dynamic.area.offset.i64() 9468*9880d681SAndroid Build Coastguard Worker 9469*9880d681SAndroid Build Coastguard Worker Overview: 9470*9880d681SAndroid Build Coastguard Worker """"""""" 9471*9880d681SAndroid Build Coastguard Worker 9472*9880d681SAndroid Build Coastguard Worker The '``llvm.get.dynamic.area.offset.*``' intrinsic family is used to 9473*9880d681SAndroid Build Coastguard Worker get the offset from native stack pointer to the address of the most 9474*9880d681SAndroid Build Coastguard Worker recent dynamic alloca on the caller's stack. These intrinsics are 9475*9880d681SAndroid Build Coastguard Worker intendend for use in combination with 9476*9880d681SAndroid Build Coastguard Worker :ref:`llvm.stacksave <int_stacksave>` to get a 9477*9880d681SAndroid Build Coastguard Worker pointer to the most recent dynamic alloca. This is useful, for example, 9478*9880d681SAndroid Build Coastguard Worker for AddressSanitizer's stack unpoisoning routines. 9479*9880d681SAndroid Build Coastguard Worker 9480*9880d681SAndroid Build Coastguard WorkerSemantics: 9481*9880d681SAndroid Build Coastguard Worker"""""""""" 9482*9880d681SAndroid Build Coastguard Worker 9483*9880d681SAndroid Build Coastguard Worker These intrinsics return a non-negative integer value that can be used to 9484*9880d681SAndroid Build Coastguard Worker get the address of the most recent dynamic alloca, allocated by :ref:`alloca <i_alloca>` 9485*9880d681SAndroid Build Coastguard Worker on the caller's stack. In particular, for targets where stack grows downwards, 9486*9880d681SAndroid Build Coastguard Worker adding this offset to the native stack pointer would get the address of the most 9487*9880d681SAndroid Build Coastguard Worker recent dynamic alloca. For targets where stack grows upwards, the situation is a bit more 9488*9880d681SAndroid Build Coastguard Worker complicated, because substracting this value from stack pointer would get the address 9489*9880d681SAndroid Build Coastguard Worker one past the end of the most recent dynamic alloca. 9490*9880d681SAndroid Build Coastguard Worker 9491*9880d681SAndroid Build Coastguard Worker Although for most targets `llvm.get.dynamic.area.offset <int_get_dynamic_area_offset>` 9492*9880d681SAndroid Build Coastguard Worker returns just a zero, for others, such as PowerPC and PowerPC64, it returns a 9493*9880d681SAndroid Build Coastguard Worker compile-time-known constant value. 9494*9880d681SAndroid Build Coastguard Worker 9495*9880d681SAndroid Build Coastguard Worker The return value type of :ref:`llvm.get.dynamic.area.offset <int_get_dynamic_area_offset>` 9496*9880d681SAndroid Build Coastguard Worker must match the target's generic address space's (address space 0) pointer type. 9497*9880d681SAndroid Build Coastguard Worker 9498*9880d681SAndroid Build Coastguard Worker'``llvm.prefetch``' Intrinsic 9499*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9500*9880d681SAndroid Build Coastguard Worker 9501*9880d681SAndroid Build Coastguard WorkerSyntax: 9502*9880d681SAndroid Build Coastguard Worker""""""" 9503*9880d681SAndroid Build Coastguard Worker 9504*9880d681SAndroid Build Coastguard Worker:: 9505*9880d681SAndroid Build Coastguard Worker 9506*9880d681SAndroid Build Coastguard Worker declare void @llvm.prefetch(i8* <address>, i32 <rw>, i32 <locality>, i32 <cache type>) 9507*9880d681SAndroid Build Coastguard Worker 9508*9880d681SAndroid Build Coastguard WorkerOverview: 9509*9880d681SAndroid Build Coastguard Worker""""""""" 9510*9880d681SAndroid Build Coastguard Worker 9511*9880d681SAndroid Build Coastguard WorkerThe '``llvm.prefetch``' intrinsic is a hint to the code generator to 9512*9880d681SAndroid Build Coastguard Workerinsert a prefetch instruction if supported; otherwise, it is a noop. 9513*9880d681SAndroid Build Coastguard WorkerPrefetches have no effect on the behavior of the program but can change 9514*9880d681SAndroid Build Coastguard Workerits performance characteristics. 9515*9880d681SAndroid Build Coastguard Worker 9516*9880d681SAndroid Build Coastguard WorkerArguments: 9517*9880d681SAndroid Build Coastguard Worker"""""""""" 9518*9880d681SAndroid Build Coastguard Worker 9519*9880d681SAndroid Build Coastguard Worker``address`` is the address to be prefetched, ``rw`` is the specifier 9520*9880d681SAndroid Build Coastguard Workerdetermining if the fetch should be for a read (0) or write (1), and 9521*9880d681SAndroid Build Coastguard Worker``locality`` is a temporal locality specifier ranging from (0) - no 9522*9880d681SAndroid Build Coastguard Workerlocality, to (3) - extremely local keep in cache. The ``cache type`` 9523*9880d681SAndroid Build Coastguard Workerspecifies whether the prefetch is performed on the data (1) or 9524*9880d681SAndroid Build Coastguard Workerinstruction (0) cache. The ``rw``, ``locality`` and ``cache type`` 9525*9880d681SAndroid Build Coastguard Workerarguments must be constant integers. 9526*9880d681SAndroid Build Coastguard Worker 9527*9880d681SAndroid Build Coastguard WorkerSemantics: 9528*9880d681SAndroid Build Coastguard Worker"""""""""" 9529*9880d681SAndroid Build Coastguard Worker 9530*9880d681SAndroid Build Coastguard WorkerThis intrinsic does not modify the behavior of the program. In 9531*9880d681SAndroid Build Coastguard Workerparticular, prefetches cannot trap and do not produce a value. On 9532*9880d681SAndroid Build Coastguard Workertargets that support this intrinsic, the prefetch can provide hints to 9533*9880d681SAndroid Build Coastguard Workerthe processor cache for better performance. 9534*9880d681SAndroid Build Coastguard Worker 9535*9880d681SAndroid Build Coastguard Worker'``llvm.pcmarker``' Intrinsic 9536*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9537*9880d681SAndroid Build Coastguard Worker 9538*9880d681SAndroid Build Coastguard WorkerSyntax: 9539*9880d681SAndroid Build Coastguard Worker""""""" 9540*9880d681SAndroid Build Coastguard Worker 9541*9880d681SAndroid Build Coastguard Worker:: 9542*9880d681SAndroid Build Coastguard Worker 9543*9880d681SAndroid Build Coastguard Worker declare void @llvm.pcmarker(i32 <id>) 9544*9880d681SAndroid Build Coastguard Worker 9545*9880d681SAndroid Build Coastguard WorkerOverview: 9546*9880d681SAndroid Build Coastguard Worker""""""""" 9547*9880d681SAndroid Build Coastguard Worker 9548*9880d681SAndroid Build Coastguard WorkerThe '``llvm.pcmarker``' intrinsic is a method to export a Program 9549*9880d681SAndroid Build Coastguard WorkerCounter (PC) in a region of code to simulators and other tools. The 9550*9880d681SAndroid Build Coastguard Workermethod is target specific, but it is expected that the marker will use 9551*9880d681SAndroid Build Coastguard Workerexported symbols to transmit the PC of the marker. The marker makes no 9552*9880d681SAndroid Build Coastguard Workerguarantees that it will remain with any specific instruction after 9553*9880d681SAndroid Build Coastguard Workeroptimizations. It is possible that the presence of a marker will inhibit 9554*9880d681SAndroid Build Coastguard Workeroptimizations. The intended use is to be inserted after optimizations to 9555*9880d681SAndroid Build Coastguard Workerallow correlations of simulation runs. 9556*9880d681SAndroid Build Coastguard Worker 9557*9880d681SAndroid Build Coastguard WorkerArguments: 9558*9880d681SAndroid Build Coastguard Worker"""""""""" 9559*9880d681SAndroid Build Coastguard Worker 9560*9880d681SAndroid Build Coastguard Worker``id`` is a numerical id identifying the marker. 9561*9880d681SAndroid Build Coastguard Worker 9562*9880d681SAndroid Build Coastguard WorkerSemantics: 9563*9880d681SAndroid Build Coastguard Worker"""""""""" 9564*9880d681SAndroid Build Coastguard Worker 9565*9880d681SAndroid Build Coastguard WorkerThis intrinsic does not modify the behavior of the program. Backends 9566*9880d681SAndroid Build Coastguard Workerthat do not support this intrinsic may ignore it. 9567*9880d681SAndroid Build Coastguard Worker 9568*9880d681SAndroid Build Coastguard Worker'``llvm.readcyclecounter``' Intrinsic 9569*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9570*9880d681SAndroid Build Coastguard Worker 9571*9880d681SAndroid Build Coastguard WorkerSyntax: 9572*9880d681SAndroid Build Coastguard Worker""""""" 9573*9880d681SAndroid Build Coastguard Worker 9574*9880d681SAndroid Build Coastguard Worker:: 9575*9880d681SAndroid Build Coastguard Worker 9576*9880d681SAndroid Build Coastguard Worker declare i64 @llvm.readcyclecounter() 9577*9880d681SAndroid Build Coastguard Worker 9578*9880d681SAndroid Build Coastguard WorkerOverview: 9579*9880d681SAndroid Build Coastguard Worker""""""""" 9580*9880d681SAndroid Build Coastguard Worker 9581*9880d681SAndroid Build Coastguard WorkerThe '``llvm.readcyclecounter``' intrinsic provides access to the cycle 9582*9880d681SAndroid Build Coastguard Workercounter register (or similar low latency, high accuracy clocks) on those 9583*9880d681SAndroid Build Coastguard Workertargets that support it. On X86, it should map to RDTSC. On Alpha, it 9584*9880d681SAndroid Build Coastguard Workershould map to RPCC. As the backing counters overflow quickly (on the 9585*9880d681SAndroid Build Coastguard Workerorder of 9 seconds on alpha), this should only be used for small 9586*9880d681SAndroid Build Coastguard Workertimings. 9587*9880d681SAndroid Build Coastguard Worker 9588*9880d681SAndroid Build Coastguard WorkerSemantics: 9589*9880d681SAndroid Build Coastguard Worker"""""""""" 9590*9880d681SAndroid Build Coastguard Worker 9591*9880d681SAndroid Build Coastguard WorkerWhen directly supported, reading the cycle counter should not modify any 9592*9880d681SAndroid Build Coastguard Workermemory. Implementations are allowed to either return a application 9593*9880d681SAndroid Build Coastguard Workerspecific value or a system wide value. On backends without support, this 9594*9880d681SAndroid Build Coastguard Workeris lowered to a constant 0. 9595*9880d681SAndroid Build Coastguard Worker 9596*9880d681SAndroid Build Coastguard WorkerNote that runtime support may be conditional on the privilege-level code is 9597*9880d681SAndroid Build Coastguard Workerrunning at and the host platform. 9598*9880d681SAndroid Build Coastguard Worker 9599*9880d681SAndroid Build Coastguard Worker'``llvm.clear_cache``' Intrinsic 9600*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9601*9880d681SAndroid Build Coastguard Worker 9602*9880d681SAndroid Build Coastguard WorkerSyntax: 9603*9880d681SAndroid Build Coastguard Worker""""""" 9604*9880d681SAndroid Build Coastguard Worker 9605*9880d681SAndroid Build Coastguard Worker:: 9606*9880d681SAndroid Build Coastguard Worker 9607*9880d681SAndroid Build Coastguard Worker declare void @llvm.clear_cache(i8*, i8*) 9608*9880d681SAndroid Build Coastguard Worker 9609*9880d681SAndroid Build Coastguard WorkerOverview: 9610*9880d681SAndroid Build Coastguard Worker""""""""" 9611*9880d681SAndroid Build Coastguard Worker 9612*9880d681SAndroid Build Coastguard WorkerThe '``llvm.clear_cache``' intrinsic ensures visibility of modifications 9613*9880d681SAndroid Build Coastguard Workerin the specified range to the execution unit of the processor. On 9614*9880d681SAndroid Build Coastguard Workertargets with non-unified instruction and data cache, the implementation 9615*9880d681SAndroid Build Coastguard Workerflushes the instruction cache. 9616*9880d681SAndroid Build Coastguard Worker 9617*9880d681SAndroid Build Coastguard WorkerSemantics: 9618*9880d681SAndroid Build Coastguard Worker"""""""""" 9619*9880d681SAndroid Build Coastguard Worker 9620*9880d681SAndroid Build Coastguard WorkerOn platforms with coherent instruction and data caches (e.g. x86), this 9621*9880d681SAndroid Build Coastguard Workerintrinsic is a nop. On platforms with non-coherent instruction and data 9622*9880d681SAndroid Build Coastguard Workercache (e.g. ARM, MIPS), the intrinsic is lowered either to appropriate 9623*9880d681SAndroid Build Coastguard Workerinstructions or a system call, if cache flushing requires special 9624*9880d681SAndroid Build Coastguard Workerprivileges. 9625*9880d681SAndroid Build Coastguard Worker 9626*9880d681SAndroid Build Coastguard WorkerThe default behavior is to emit a call to ``__clear_cache`` from the run 9627*9880d681SAndroid Build Coastguard Workertime library. 9628*9880d681SAndroid Build Coastguard Worker 9629*9880d681SAndroid Build Coastguard WorkerThis instrinsic does *not* empty the instruction pipeline. Modifications 9630*9880d681SAndroid Build Coastguard Workerof the current function are outside the scope of the intrinsic. 9631*9880d681SAndroid Build Coastguard Worker 9632*9880d681SAndroid Build Coastguard Worker'``llvm.instrprof_increment``' Intrinsic 9633*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9634*9880d681SAndroid Build Coastguard Worker 9635*9880d681SAndroid Build Coastguard WorkerSyntax: 9636*9880d681SAndroid Build Coastguard Worker""""""" 9637*9880d681SAndroid Build Coastguard Worker 9638*9880d681SAndroid Build Coastguard Worker:: 9639*9880d681SAndroid Build Coastguard Worker 9640*9880d681SAndroid Build Coastguard Worker declare void @llvm.instrprof_increment(i8* <name>, i64 <hash>, 9641*9880d681SAndroid Build Coastguard Worker i32 <num-counters>, i32 <index>) 9642*9880d681SAndroid Build Coastguard Worker 9643*9880d681SAndroid Build Coastguard WorkerOverview: 9644*9880d681SAndroid Build Coastguard Worker""""""""" 9645*9880d681SAndroid Build Coastguard Worker 9646*9880d681SAndroid Build Coastguard WorkerThe '``llvm.instrprof_increment``' intrinsic can be emitted by a 9647*9880d681SAndroid Build Coastguard Workerfrontend for use with instrumentation based profiling. These will be 9648*9880d681SAndroid Build Coastguard Workerlowered by the ``-instrprof`` pass to generate execution counts of a 9649*9880d681SAndroid Build Coastguard Workerprogram at runtime. 9650*9880d681SAndroid Build Coastguard Worker 9651*9880d681SAndroid Build Coastguard WorkerArguments: 9652*9880d681SAndroid Build Coastguard Worker"""""""""" 9653*9880d681SAndroid Build Coastguard Worker 9654*9880d681SAndroid Build Coastguard WorkerThe first argument is a pointer to a global variable containing the 9655*9880d681SAndroid Build Coastguard Workername of the entity being instrumented. This should generally be the 9656*9880d681SAndroid Build Coastguard Worker(mangled) function name for a set of counters. 9657*9880d681SAndroid Build Coastguard Worker 9658*9880d681SAndroid Build Coastguard WorkerThe second argument is a hash value that can be used by the consumer 9659*9880d681SAndroid Build Coastguard Workerof the profile data to detect changes to the instrumented source, and 9660*9880d681SAndroid Build Coastguard Workerthe third is the number of counters associated with ``name``. It is an 9661*9880d681SAndroid Build Coastguard Workererror if ``hash`` or ``num-counters`` differ between two instances of 9662*9880d681SAndroid Build Coastguard Worker``instrprof_increment`` that refer to the same name. 9663*9880d681SAndroid Build Coastguard Worker 9664*9880d681SAndroid Build Coastguard WorkerThe last argument refers to which of the counters for ``name`` should 9665*9880d681SAndroid Build Coastguard Workerbe incremented. It should be a value between 0 and ``num-counters``. 9666*9880d681SAndroid Build Coastguard Worker 9667*9880d681SAndroid Build Coastguard WorkerSemantics: 9668*9880d681SAndroid Build Coastguard Worker"""""""""" 9669*9880d681SAndroid Build Coastguard Worker 9670*9880d681SAndroid Build Coastguard WorkerThis intrinsic represents an increment of a profiling counter. It will 9671*9880d681SAndroid Build Coastguard Workercause the ``-instrprof`` pass to generate the appropriate data 9672*9880d681SAndroid Build Coastguard Workerstructures and the code to increment the appropriate value, in a 9673*9880d681SAndroid Build Coastguard Workerformat that can be written out by a compiler runtime and consumed via 9674*9880d681SAndroid Build Coastguard Workerthe ``llvm-profdata`` tool. 9675*9880d681SAndroid Build Coastguard Worker 9676*9880d681SAndroid Build Coastguard Worker'``llvm.instrprof_value_profile``' Intrinsic 9677*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9678*9880d681SAndroid Build Coastguard Worker 9679*9880d681SAndroid Build Coastguard WorkerSyntax: 9680*9880d681SAndroid Build Coastguard Worker""""""" 9681*9880d681SAndroid Build Coastguard Worker 9682*9880d681SAndroid Build Coastguard Worker:: 9683*9880d681SAndroid Build Coastguard Worker 9684*9880d681SAndroid Build Coastguard Worker declare void @llvm.instrprof_value_profile(i8* <name>, i64 <hash>, 9685*9880d681SAndroid Build Coastguard Worker i64 <value>, i32 <value_kind>, 9686*9880d681SAndroid Build Coastguard Worker i32 <index>) 9687*9880d681SAndroid Build Coastguard Worker 9688*9880d681SAndroid Build Coastguard WorkerOverview: 9689*9880d681SAndroid Build Coastguard Worker""""""""" 9690*9880d681SAndroid Build Coastguard Worker 9691*9880d681SAndroid Build Coastguard WorkerThe '``llvm.instrprof_value_profile``' intrinsic can be emitted by a 9692*9880d681SAndroid Build Coastguard Workerfrontend for use with instrumentation based profiling. This will be 9693*9880d681SAndroid Build Coastguard Workerlowered by the ``-instrprof`` pass to find out the target values, 9694*9880d681SAndroid Build Coastguard Workerinstrumented expressions take in a program at runtime. 9695*9880d681SAndroid Build Coastguard Worker 9696*9880d681SAndroid Build Coastguard WorkerArguments: 9697*9880d681SAndroid Build Coastguard Worker"""""""""" 9698*9880d681SAndroid Build Coastguard Worker 9699*9880d681SAndroid Build Coastguard WorkerThe first argument is a pointer to a global variable containing the 9700*9880d681SAndroid Build Coastguard Workername of the entity being instrumented. ``name`` should generally be the 9701*9880d681SAndroid Build Coastguard Worker(mangled) function name for a set of counters. 9702*9880d681SAndroid Build Coastguard Worker 9703*9880d681SAndroid Build Coastguard WorkerThe second argument is a hash value that can be used by the consumer 9704*9880d681SAndroid Build Coastguard Workerof the profile data to detect changes to the instrumented source. It 9705*9880d681SAndroid Build Coastguard Workeris an error if ``hash`` differs between two instances of 9706*9880d681SAndroid Build Coastguard Worker``llvm.instrprof_*`` that refer to the same name. 9707*9880d681SAndroid Build Coastguard Worker 9708*9880d681SAndroid Build Coastguard WorkerThe third argument is the value of the expression being profiled. The profiled 9709*9880d681SAndroid Build Coastguard Workerexpression's value should be representable as an unsigned 64-bit value. The 9710*9880d681SAndroid Build Coastguard Workerfourth argument represents the kind of value profiling that is being done. The 9711*9880d681SAndroid Build Coastguard Workersupported value profiling kinds are enumerated through the 9712*9880d681SAndroid Build Coastguard Worker``InstrProfValueKind`` type declared in the 9713*9880d681SAndroid Build Coastguard Worker``<include/llvm/ProfileData/InstrProf.h>`` header file. The last argument is the 9714*9880d681SAndroid Build Coastguard Workerindex of the instrumented expression within ``name``. It should be >= 0. 9715*9880d681SAndroid Build Coastguard Worker 9716*9880d681SAndroid Build Coastguard WorkerSemantics: 9717*9880d681SAndroid Build Coastguard Worker"""""""""" 9718*9880d681SAndroid Build Coastguard Worker 9719*9880d681SAndroid Build Coastguard WorkerThis intrinsic represents the point where a call to a runtime routine 9720*9880d681SAndroid Build Coastguard Workershould be inserted for value profiling of target expressions. ``-instrprof`` 9721*9880d681SAndroid Build Coastguard Workerpass will generate the appropriate data structures and replace the 9722*9880d681SAndroid Build Coastguard Worker``llvm.instrprof_value_profile`` intrinsic with the call to the profile 9723*9880d681SAndroid Build Coastguard Workerruntime library with proper arguments. 9724*9880d681SAndroid Build Coastguard Worker 9725*9880d681SAndroid Build Coastguard Worker'``llvm.thread.pointer``' Intrinsic 9726*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9727*9880d681SAndroid Build Coastguard Worker 9728*9880d681SAndroid Build Coastguard WorkerSyntax: 9729*9880d681SAndroid Build Coastguard Worker""""""" 9730*9880d681SAndroid Build Coastguard Worker 9731*9880d681SAndroid Build Coastguard Worker:: 9732*9880d681SAndroid Build Coastguard Worker 9733*9880d681SAndroid Build Coastguard Worker declare i8* @llvm.thread.pointer() 9734*9880d681SAndroid Build Coastguard Worker 9735*9880d681SAndroid Build Coastguard WorkerOverview: 9736*9880d681SAndroid Build Coastguard Worker""""""""" 9737*9880d681SAndroid Build Coastguard Worker 9738*9880d681SAndroid Build Coastguard WorkerThe '``llvm.thread.pointer``' intrinsic returns the value of the thread 9739*9880d681SAndroid Build Coastguard Workerpointer. 9740*9880d681SAndroid Build Coastguard Worker 9741*9880d681SAndroid Build Coastguard WorkerSemantics: 9742*9880d681SAndroid Build Coastguard Worker"""""""""" 9743*9880d681SAndroid Build Coastguard Worker 9744*9880d681SAndroid Build Coastguard WorkerThe '``llvm.thread.pointer``' intrinsic returns a pointer to the TLS area 9745*9880d681SAndroid Build Coastguard Workerfor the current thread. The exact semantics of this value are target 9746*9880d681SAndroid Build Coastguard Workerspecific: it may point to the start of TLS area, to the end, or somewhere 9747*9880d681SAndroid Build Coastguard Workerin the middle. Depending on the target, this intrinsic may read a register, 9748*9880d681SAndroid Build Coastguard Workercall a helper function, read from an alternate memory space, or perform 9749*9880d681SAndroid Build Coastguard Workerother operations necessary to locate the TLS area. Not all targets support 9750*9880d681SAndroid Build Coastguard Workerthis intrinsic. 9751*9880d681SAndroid Build Coastguard Worker 9752*9880d681SAndroid Build Coastguard WorkerStandard C Library Intrinsics 9753*9880d681SAndroid Build Coastguard Worker----------------------------- 9754*9880d681SAndroid Build Coastguard Worker 9755*9880d681SAndroid Build Coastguard WorkerLLVM provides intrinsics for a few important standard C library 9756*9880d681SAndroid Build Coastguard Workerfunctions. These intrinsics allow source-language front-ends to pass 9757*9880d681SAndroid Build Coastguard Workerinformation about the alignment of the pointer arguments to the code 9758*9880d681SAndroid Build Coastguard Workergenerator, providing opportunity for more efficient code generation. 9759*9880d681SAndroid Build Coastguard Worker 9760*9880d681SAndroid Build Coastguard Worker.. _int_memcpy: 9761*9880d681SAndroid Build Coastguard Worker 9762*9880d681SAndroid Build Coastguard Worker'``llvm.memcpy``' Intrinsic 9763*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9764*9880d681SAndroid Build Coastguard Worker 9765*9880d681SAndroid Build Coastguard WorkerSyntax: 9766*9880d681SAndroid Build Coastguard Worker""""""" 9767*9880d681SAndroid Build Coastguard Worker 9768*9880d681SAndroid Build Coastguard WorkerThis is an overloaded intrinsic. You can use ``llvm.memcpy`` on any 9769*9880d681SAndroid Build Coastguard Workerinteger bit width and for different address spaces. Not all targets 9770*9880d681SAndroid Build Coastguard Workersupport all bit widths however. 9771*9880d681SAndroid Build Coastguard Worker 9772*9880d681SAndroid Build Coastguard Worker:: 9773*9880d681SAndroid Build Coastguard Worker 9774*9880d681SAndroid Build Coastguard Worker declare void @llvm.memcpy.p0i8.p0i8.i32(i8* <dest>, i8* <src>, 9775*9880d681SAndroid Build Coastguard Worker i32 <len>, i32 <align>, i1 <isvolatile>) 9776*9880d681SAndroid Build Coastguard Worker declare void @llvm.memcpy.p0i8.p0i8.i64(i8* <dest>, i8* <src>, 9777*9880d681SAndroid Build Coastguard Worker i64 <len>, i32 <align>, i1 <isvolatile>) 9778*9880d681SAndroid Build Coastguard Worker 9779*9880d681SAndroid Build Coastguard WorkerOverview: 9780*9880d681SAndroid Build Coastguard Worker""""""""" 9781*9880d681SAndroid Build Coastguard Worker 9782*9880d681SAndroid Build Coastguard WorkerThe '``llvm.memcpy.*``' intrinsics copy a block of memory from the 9783*9880d681SAndroid Build Coastguard Workersource location to the destination location. 9784*9880d681SAndroid Build Coastguard Worker 9785*9880d681SAndroid Build Coastguard WorkerNote that, unlike the standard libc function, the ``llvm.memcpy.*`` 9786*9880d681SAndroid Build Coastguard Workerintrinsics do not return a value, takes extra alignment/isvolatile 9787*9880d681SAndroid Build Coastguard Workerarguments and the pointers can be in specified address spaces. 9788*9880d681SAndroid Build Coastguard Worker 9789*9880d681SAndroid Build Coastguard WorkerArguments: 9790*9880d681SAndroid Build Coastguard Worker"""""""""" 9791*9880d681SAndroid Build Coastguard Worker 9792*9880d681SAndroid Build Coastguard WorkerThe first argument is a pointer to the destination, the second is a 9793*9880d681SAndroid Build Coastguard Workerpointer to the source. The third argument is an integer argument 9794*9880d681SAndroid Build Coastguard Workerspecifying the number of bytes to copy, the fourth argument is the 9795*9880d681SAndroid Build Coastguard Workeralignment of the source and destination locations, and the fifth is a 9796*9880d681SAndroid Build Coastguard Workerboolean indicating a volatile access. 9797*9880d681SAndroid Build Coastguard Worker 9798*9880d681SAndroid Build Coastguard WorkerIf the call to this intrinsic has an alignment value that is not 0 or 1, 9799*9880d681SAndroid Build Coastguard Workerthen the caller guarantees that both the source and destination pointers 9800*9880d681SAndroid Build Coastguard Workerare aligned to that boundary. 9801*9880d681SAndroid Build Coastguard Worker 9802*9880d681SAndroid Build Coastguard WorkerIf the ``isvolatile`` parameter is ``true``, the ``llvm.memcpy`` call is 9803*9880d681SAndroid Build Coastguard Workera :ref:`volatile operation <volatile>`. The detailed access behavior is not 9804*9880d681SAndroid Build Coastguard Workervery cleanly specified and it is unwise to depend on it. 9805*9880d681SAndroid Build Coastguard Worker 9806*9880d681SAndroid Build Coastguard WorkerSemantics: 9807*9880d681SAndroid Build Coastguard Worker"""""""""" 9808*9880d681SAndroid Build Coastguard Worker 9809*9880d681SAndroid Build Coastguard WorkerThe '``llvm.memcpy.*``' intrinsics copy a block of memory from the 9810*9880d681SAndroid Build Coastguard Workersource location to the destination location, which are not allowed to 9811*9880d681SAndroid Build Coastguard Workeroverlap. It copies "len" bytes of memory over. If the argument is known 9812*9880d681SAndroid Build Coastguard Workerto be aligned to some boundary, this can be specified as the fourth 9813*9880d681SAndroid Build Coastguard Workerargument, otherwise it should be set to 0 or 1 (both meaning no alignment). 9814*9880d681SAndroid Build Coastguard Worker 9815*9880d681SAndroid Build Coastguard Worker'``llvm.memmove``' Intrinsic 9816*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9817*9880d681SAndroid Build Coastguard Worker 9818*9880d681SAndroid Build Coastguard WorkerSyntax: 9819*9880d681SAndroid Build Coastguard Worker""""""" 9820*9880d681SAndroid Build Coastguard Worker 9821*9880d681SAndroid Build Coastguard WorkerThis is an overloaded intrinsic. You can use llvm.memmove on any integer 9822*9880d681SAndroid Build Coastguard Workerbit width and for different address space. Not all targets support all 9823*9880d681SAndroid Build Coastguard Workerbit widths however. 9824*9880d681SAndroid Build Coastguard Worker 9825*9880d681SAndroid Build Coastguard Worker:: 9826*9880d681SAndroid Build Coastguard Worker 9827*9880d681SAndroid Build Coastguard Worker declare void @llvm.memmove.p0i8.p0i8.i32(i8* <dest>, i8* <src>, 9828*9880d681SAndroid Build Coastguard Worker i32 <len>, i32 <align>, i1 <isvolatile>) 9829*9880d681SAndroid Build Coastguard Worker declare void @llvm.memmove.p0i8.p0i8.i64(i8* <dest>, i8* <src>, 9830*9880d681SAndroid Build Coastguard Worker i64 <len>, i32 <align>, i1 <isvolatile>) 9831*9880d681SAndroid Build Coastguard Worker 9832*9880d681SAndroid Build Coastguard WorkerOverview: 9833*9880d681SAndroid Build Coastguard Worker""""""""" 9834*9880d681SAndroid Build Coastguard Worker 9835*9880d681SAndroid Build Coastguard WorkerThe '``llvm.memmove.*``' intrinsics move a block of memory from the 9836*9880d681SAndroid Build Coastguard Workersource location to the destination location. It is similar to the 9837*9880d681SAndroid Build Coastguard Worker'``llvm.memcpy``' intrinsic but allows the two memory locations to 9838*9880d681SAndroid Build Coastguard Workeroverlap. 9839*9880d681SAndroid Build Coastguard Worker 9840*9880d681SAndroid Build Coastguard WorkerNote that, unlike the standard libc function, the ``llvm.memmove.*`` 9841*9880d681SAndroid Build Coastguard Workerintrinsics do not return a value, takes extra alignment/isvolatile 9842*9880d681SAndroid Build Coastguard Workerarguments and the pointers can be in specified address spaces. 9843*9880d681SAndroid Build Coastguard Worker 9844*9880d681SAndroid Build Coastguard WorkerArguments: 9845*9880d681SAndroid Build Coastguard Worker"""""""""" 9846*9880d681SAndroid Build Coastguard Worker 9847*9880d681SAndroid Build Coastguard WorkerThe first argument is a pointer to the destination, the second is a 9848*9880d681SAndroid Build Coastguard Workerpointer to the source. The third argument is an integer argument 9849*9880d681SAndroid Build Coastguard Workerspecifying the number of bytes to copy, the fourth argument is the 9850*9880d681SAndroid Build Coastguard Workeralignment of the source and destination locations, and the fifth is a 9851*9880d681SAndroid Build Coastguard Workerboolean indicating a volatile access. 9852*9880d681SAndroid Build Coastguard Worker 9853*9880d681SAndroid Build Coastguard WorkerIf the call to this intrinsic has an alignment value that is not 0 or 1, 9854*9880d681SAndroid Build Coastguard Workerthen the caller guarantees that the source and destination pointers are 9855*9880d681SAndroid Build Coastguard Workeraligned to that boundary. 9856*9880d681SAndroid Build Coastguard Worker 9857*9880d681SAndroid Build Coastguard WorkerIf the ``isvolatile`` parameter is ``true``, the ``llvm.memmove`` call 9858*9880d681SAndroid Build Coastguard Workeris a :ref:`volatile operation <volatile>`. The detailed access behavior is 9859*9880d681SAndroid Build Coastguard Workernot very cleanly specified and it is unwise to depend on it. 9860*9880d681SAndroid Build Coastguard Worker 9861*9880d681SAndroid Build Coastguard WorkerSemantics: 9862*9880d681SAndroid Build Coastguard Worker"""""""""" 9863*9880d681SAndroid Build Coastguard Worker 9864*9880d681SAndroid Build Coastguard WorkerThe '``llvm.memmove.*``' intrinsics copy a block of memory from the 9865*9880d681SAndroid Build Coastguard Workersource location to the destination location, which may overlap. It 9866*9880d681SAndroid Build Coastguard Workercopies "len" bytes of memory over. If the argument is known to be 9867*9880d681SAndroid Build Coastguard Workeraligned to some boundary, this can be specified as the fourth argument, 9868*9880d681SAndroid Build Coastguard Workerotherwise it should be set to 0 or 1 (both meaning no alignment). 9869*9880d681SAndroid Build Coastguard Worker 9870*9880d681SAndroid Build Coastguard Worker'``llvm.memset.*``' Intrinsics 9871*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9872*9880d681SAndroid Build Coastguard Worker 9873*9880d681SAndroid Build Coastguard WorkerSyntax: 9874*9880d681SAndroid Build Coastguard Worker""""""" 9875*9880d681SAndroid Build Coastguard Worker 9876*9880d681SAndroid Build Coastguard WorkerThis is an overloaded intrinsic. You can use llvm.memset on any integer 9877*9880d681SAndroid Build Coastguard Workerbit width and for different address spaces. However, not all targets 9878*9880d681SAndroid Build Coastguard Workersupport all bit widths. 9879*9880d681SAndroid Build Coastguard Worker 9880*9880d681SAndroid Build Coastguard Worker:: 9881*9880d681SAndroid Build Coastguard Worker 9882*9880d681SAndroid Build Coastguard Worker declare void @llvm.memset.p0i8.i32(i8* <dest>, i8 <val>, 9883*9880d681SAndroid Build Coastguard Worker i32 <len>, i32 <align>, i1 <isvolatile>) 9884*9880d681SAndroid Build Coastguard Worker declare void @llvm.memset.p0i8.i64(i8* <dest>, i8 <val>, 9885*9880d681SAndroid Build Coastguard Worker i64 <len>, i32 <align>, i1 <isvolatile>) 9886*9880d681SAndroid Build Coastguard Worker 9887*9880d681SAndroid Build Coastguard WorkerOverview: 9888*9880d681SAndroid Build Coastguard Worker""""""""" 9889*9880d681SAndroid Build Coastguard Worker 9890*9880d681SAndroid Build Coastguard WorkerThe '``llvm.memset.*``' intrinsics fill a block of memory with a 9891*9880d681SAndroid Build Coastguard Workerparticular byte value. 9892*9880d681SAndroid Build Coastguard Worker 9893*9880d681SAndroid Build Coastguard WorkerNote that, unlike the standard libc function, the ``llvm.memset`` 9894*9880d681SAndroid Build Coastguard Workerintrinsic does not return a value and takes extra alignment/volatile 9895*9880d681SAndroid Build Coastguard Workerarguments. Also, the destination can be in an arbitrary address space. 9896*9880d681SAndroid Build Coastguard Worker 9897*9880d681SAndroid Build Coastguard WorkerArguments: 9898*9880d681SAndroid Build Coastguard Worker"""""""""" 9899*9880d681SAndroid Build Coastguard Worker 9900*9880d681SAndroid Build Coastguard WorkerThe first argument is a pointer to the destination to fill, the second 9901*9880d681SAndroid Build Coastguard Workeris the byte value with which to fill it, the third argument is an 9902*9880d681SAndroid Build Coastguard Workerinteger argument specifying the number of bytes to fill, and the fourth 9903*9880d681SAndroid Build Coastguard Workerargument is the known alignment of the destination location. 9904*9880d681SAndroid Build Coastguard Worker 9905*9880d681SAndroid Build Coastguard WorkerIf the call to this intrinsic has an alignment value that is not 0 or 1, 9906*9880d681SAndroid Build Coastguard Workerthen the caller guarantees that the destination pointer is aligned to 9907*9880d681SAndroid Build Coastguard Workerthat boundary. 9908*9880d681SAndroid Build Coastguard Worker 9909*9880d681SAndroid Build Coastguard WorkerIf the ``isvolatile`` parameter is ``true``, the ``llvm.memset`` call is 9910*9880d681SAndroid Build Coastguard Workera :ref:`volatile operation <volatile>`. The detailed access behavior is not 9911*9880d681SAndroid Build Coastguard Workervery cleanly specified and it is unwise to depend on it. 9912*9880d681SAndroid Build Coastguard Worker 9913*9880d681SAndroid Build Coastguard WorkerSemantics: 9914*9880d681SAndroid Build Coastguard Worker"""""""""" 9915*9880d681SAndroid Build Coastguard Worker 9916*9880d681SAndroid Build Coastguard WorkerThe '``llvm.memset.*``' intrinsics fill "len" bytes of memory starting 9917*9880d681SAndroid Build Coastguard Workerat the destination location. If the argument is known to be aligned to 9918*9880d681SAndroid Build Coastguard Workersome boundary, this can be specified as the fourth argument, otherwise 9919*9880d681SAndroid Build Coastguard Workerit should be set to 0 or 1 (both meaning no alignment). 9920*9880d681SAndroid Build Coastguard Worker 9921*9880d681SAndroid Build Coastguard Worker'``llvm.sqrt.*``' Intrinsic 9922*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9923*9880d681SAndroid Build Coastguard Worker 9924*9880d681SAndroid Build Coastguard WorkerSyntax: 9925*9880d681SAndroid Build Coastguard Worker""""""" 9926*9880d681SAndroid Build Coastguard Worker 9927*9880d681SAndroid Build Coastguard WorkerThis is an overloaded intrinsic. You can use ``llvm.sqrt`` on any 9928*9880d681SAndroid Build Coastguard Workerfloating point or vector of floating point type. Not all targets support 9929*9880d681SAndroid Build Coastguard Workerall types however. 9930*9880d681SAndroid Build Coastguard Worker 9931*9880d681SAndroid Build Coastguard Worker:: 9932*9880d681SAndroid Build Coastguard Worker 9933*9880d681SAndroid Build Coastguard Worker declare float @llvm.sqrt.f32(float %Val) 9934*9880d681SAndroid Build Coastguard Worker declare double @llvm.sqrt.f64(double %Val) 9935*9880d681SAndroid Build Coastguard Worker declare x86_fp80 @llvm.sqrt.f80(x86_fp80 %Val) 9936*9880d681SAndroid Build Coastguard Worker declare fp128 @llvm.sqrt.f128(fp128 %Val) 9937*9880d681SAndroid Build Coastguard Worker declare ppc_fp128 @llvm.sqrt.ppcf128(ppc_fp128 %Val) 9938*9880d681SAndroid Build Coastguard Worker 9939*9880d681SAndroid Build Coastguard WorkerOverview: 9940*9880d681SAndroid Build Coastguard Worker""""""""" 9941*9880d681SAndroid Build Coastguard Worker 9942*9880d681SAndroid Build Coastguard WorkerThe '``llvm.sqrt``' intrinsics return the sqrt of the specified operand, 9943*9880d681SAndroid Build Coastguard Workerreturning the same value as the libm '``sqrt``' functions would. Unlike 9944*9880d681SAndroid Build Coastguard Worker``sqrt`` in libm, however, ``llvm.sqrt`` has undefined behavior for 9945*9880d681SAndroid Build Coastguard Workernegative numbers other than -0.0 (which allows for better optimization, 9946*9880d681SAndroid Build Coastguard Workerbecause there is no need to worry about errno being set). 9947*9880d681SAndroid Build Coastguard Worker``llvm.sqrt(-0.0)`` is defined to return -0.0 like IEEE sqrt. 9948*9880d681SAndroid Build Coastguard Worker 9949*9880d681SAndroid Build Coastguard WorkerArguments: 9950*9880d681SAndroid Build Coastguard Worker"""""""""" 9951*9880d681SAndroid Build Coastguard Worker 9952*9880d681SAndroid Build Coastguard WorkerThe argument and return value are floating point numbers of the same 9953*9880d681SAndroid Build Coastguard Workertype. 9954*9880d681SAndroid Build Coastguard Worker 9955*9880d681SAndroid Build Coastguard WorkerSemantics: 9956*9880d681SAndroid Build Coastguard Worker"""""""""" 9957*9880d681SAndroid Build Coastguard Worker 9958*9880d681SAndroid Build Coastguard WorkerThis function returns the sqrt of the specified operand if it is a 9959*9880d681SAndroid Build Coastguard Workernonnegative floating point number. 9960*9880d681SAndroid Build Coastguard Worker 9961*9880d681SAndroid Build Coastguard Worker'``llvm.powi.*``' Intrinsic 9962*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9963*9880d681SAndroid Build Coastguard Worker 9964*9880d681SAndroid Build Coastguard WorkerSyntax: 9965*9880d681SAndroid Build Coastguard Worker""""""" 9966*9880d681SAndroid Build Coastguard Worker 9967*9880d681SAndroid Build Coastguard WorkerThis is an overloaded intrinsic. You can use ``llvm.powi`` on any 9968*9880d681SAndroid Build Coastguard Workerfloating point or vector of floating point type. Not all targets support 9969*9880d681SAndroid Build Coastguard Workerall types however. 9970*9880d681SAndroid Build Coastguard Worker 9971*9880d681SAndroid Build Coastguard Worker:: 9972*9880d681SAndroid Build Coastguard Worker 9973*9880d681SAndroid Build Coastguard Worker declare float @llvm.powi.f32(float %Val, i32 %power) 9974*9880d681SAndroid Build Coastguard Worker declare double @llvm.powi.f64(double %Val, i32 %power) 9975*9880d681SAndroid Build Coastguard Worker declare x86_fp80 @llvm.powi.f80(x86_fp80 %Val, i32 %power) 9976*9880d681SAndroid Build Coastguard Worker declare fp128 @llvm.powi.f128(fp128 %Val, i32 %power) 9977*9880d681SAndroid Build Coastguard Worker declare ppc_fp128 @llvm.powi.ppcf128(ppc_fp128 %Val, i32 %power) 9978*9880d681SAndroid Build Coastguard Worker 9979*9880d681SAndroid Build Coastguard WorkerOverview: 9980*9880d681SAndroid Build Coastguard Worker""""""""" 9981*9880d681SAndroid Build Coastguard Worker 9982*9880d681SAndroid Build Coastguard WorkerThe '``llvm.powi.*``' intrinsics return the first operand raised to the 9983*9880d681SAndroid Build Coastguard Workerspecified (positive or negative) power. The order of evaluation of 9984*9880d681SAndroid Build Coastguard Workermultiplications is not defined. When a vector of floating point type is 9985*9880d681SAndroid Build Coastguard Workerused, the second argument remains a scalar integer value. 9986*9880d681SAndroid Build Coastguard Worker 9987*9880d681SAndroid Build Coastguard WorkerArguments: 9988*9880d681SAndroid Build Coastguard Worker"""""""""" 9989*9880d681SAndroid Build Coastguard Worker 9990*9880d681SAndroid Build Coastguard WorkerThe second argument is an integer power, and the first is a value to 9991*9880d681SAndroid Build Coastguard Workerraise to that power. 9992*9880d681SAndroid Build Coastguard Worker 9993*9880d681SAndroid Build Coastguard WorkerSemantics: 9994*9880d681SAndroid Build Coastguard Worker"""""""""" 9995*9880d681SAndroid Build Coastguard Worker 9996*9880d681SAndroid Build Coastguard WorkerThis function returns the first value raised to the second power with an 9997*9880d681SAndroid Build Coastguard Workerunspecified sequence of rounding operations. 9998*9880d681SAndroid Build Coastguard Worker 9999*9880d681SAndroid Build Coastguard Worker'``llvm.sin.*``' Intrinsic 10000*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^ 10001*9880d681SAndroid Build Coastguard Worker 10002*9880d681SAndroid Build Coastguard WorkerSyntax: 10003*9880d681SAndroid Build Coastguard Worker""""""" 10004*9880d681SAndroid Build Coastguard Worker 10005*9880d681SAndroid Build Coastguard WorkerThis is an overloaded intrinsic. You can use ``llvm.sin`` on any 10006*9880d681SAndroid Build Coastguard Workerfloating point or vector of floating point type. Not all targets support 10007*9880d681SAndroid Build Coastguard Workerall types however. 10008*9880d681SAndroid Build Coastguard Worker 10009*9880d681SAndroid Build Coastguard Worker:: 10010*9880d681SAndroid Build Coastguard Worker 10011*9880d681SAndroid Build Coastguard Worker declare float @llvm.sin.f32(float %Val) 10012*9880d681SAndroid Build Coastguard Worker declare double @llvm.sin.f64(double %Val) 10013*9880d681SAndroid Build Coastguard Worker declare x86_fp80 @llvm.sin.f80(x86_fp80 %Val) 10014*9880d681SAndroid Build Coastguard Worker declare fp128 @llvm.sin.f128(fp128 %Val) 10015*9880d681SAndroid Build Coastguard Worker declare ppc_fp128 @llvm.sin.ppcf128(ppc_fp128 %Val) 10016*9880d681SAndroid Build Coastguard Worker 10017*9880d681SAndroid Build Coastguard WorkerOverview: 10018*9880d681SAndroid Build Coastguard Worker""""""""" 10019*9880d681SAndroid Build Coastguard Worker 10020*9880d681SAndroid Build Coastguard WorkerThe '``llvm.sin.*``' intrinsics return the sine of the operand. 10021*9880d681SAndroid Build Coastguard Worker 10022*9880d681SAndroid Build Coastguard WorkerArguments: 10023*9880d681SAndroid Build Coastguard Worker"""""""""" 10024*9880d681SAndroid Build Coastguard Worker 10025*9880d681SAndroid Build Coastguard WorkerThe argument and return value are floating point numbers of the same 10026*9880d681SAndroid Build Coastguard Workertype. 10027*9880d681SAndroid Build Coastguard Worker 10028*9880d681SAndroid Build Coastguard WorkerSemantics: 10029*9880d681SAndroid Build Coastguard Worker"""""""""" 10030*9880d681SAndroid Build Coastguard Worker 10031*9880d681SAndroid Build Coastguard WorkerThis function returns the sine of the specified operand, returning the 10032*9880d681SAndroid Build Coastguard Workersame values as the libm ``sin`` functions would, and handles error 10033*9880d681SAndroid Build Coastguard Workerconditions in the same way. 10034*9880d681SAndroid Build Coastguard Worker 10035*9880d681SAndroid Build Coastguard Worker'``llvm.cos.*``' Intrinsic 10036*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^ 10037*9880d681SAndroid Build Coastguard Worker 10038*9880d681SAndroid Build Coastguard WorkerSyntax: 10039*9880d681SAndroid Build Coastguard Worker""""""" 10040*9880d681SAndroid Build Coastguard Worker 10041*9880d681SAndroid Build Coastguard WorkerThis is an overloaded intrinsic. You can use ``llvm.cos`` on any 10042*9880d681SAndroid Build Coastguard Workerfloating point or vector of floating point type. Not all targets support 10043*9880d681SAndroid Build Coastguard Workerall types however. 10044*9880d681SAndroid Build Coastguard Worker 10045*9880d681SAndroid Build Coastguard Worker:: 10046*9880d681SAndroid Build Coastguard Worker 10047*9880d681SAndroid Build Coastguard Worker declare float @llvm.cos.f32(float %Val) 10048*9880d681SAndroid Build Coastguard Worker declare double @llvm.cos.f64(double %Val) 10049*9880d681SAndroid Build Coastguard Worker declare x86_fp80 @llvm.cos.f80(x86_fp80 %Val) 10050*9880d681SAndroid Build Coastguard Worker declare fp128 @llvm.cos.f128(fp128 %Val) 10051*9880d681SAndroid Build Coastguard Worker declare ppc_fp128 @llvm.cos.ppcf128(ppc_fp128 %Val) 10052*9880d681SAndroid Build Coastguard Worker 10053*9880d681SAndroid Build Coastguard WorkerOverview: 10054*9880d681SAndroid Build Coastguard Worker""""""""" 10055*9880d681SAndroid Build Coastguard Worker 10056*9880d681SAndroid Build Coastguard WorkerThe '``llvm.cos.*``' intrinsics return the cosine of the operand. 10057*9880d681SAndroid Build Coastguard Worker 10058*9880d681SAndroid Build Coastguard WorkerArguments: 10059*9880d681SAndroid Build Coastguard Worker"""""""""" 10060*9880d681SAndroid Build Coastguard Worker 10061*9880d681SAndroid Build Coastguard WorkerThe argument and return value are floating point numbers of the same 10062*9880d681SAndroid Build Coastguard Workertype. 10063*9880d681SAndroid Build Coastguard Worker 10064*9880d681SAndroid Build Coastguard WorkerSemantics: 10065*9880d681SAndroid Build Coastguard Worker"""""""""" 10066*9880d681SAndroid Build Coastguard Worker 10067*9880d681SAndroid Build Coastguard WorkerThis function returns the cosine of the specified operand, returning the 10068*9880d681SAndroid Build Coastguard Workersame values as the libm ``cos`` functions would, and handles error 10069*9880d681SAndroid Build Coastguard Workerconditions in the same way. 10070*9880d681SAndroid Build Coastguard Worker 10071*9880d681SAndroid Build Coastguard Worker'``llvm.pow.*``' Intrinsic 10072*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^ 10073*9880d681SAndroid Build Coastguard Worker 10074*9880d681SAndroid Build Coastguard WorkerSyntax: 10075*9880d681SAndroid Build Coastguard Worker""""""" 10076*9880d681SAndroid Build Coastguard Worker 10077*9880d681SAndroid Build Coastguard WorkerThis is an overloaded intrinsic. You can use ``llvm.pow`` on any 10078*9880d681SAndroid Build Coastguard Workerfloating point or vector of floating point type. Not all targets support 10079*9880d681SAndroid Build Coastguard Workerall types however. 10080*9880d681SAndroid Build Coastguard Worker 10081*9880d681SAndroid Build Coastguard Worker:: 10082*9880d681SAndroid Build Coastguard Worker 10083*9880d681SAndroid Build Coastguard Worker declare float @llvm.pow.f32(float %Val, float %Power) 10084*9880d681SAndroid Build Coastguard Worker declare double @llvm.pow.f64(double %Val, double %Power) 10085*9880d681SAndroid Build Coastguard Worker declare x86_fp80 @llvm.pow.f80(x86_fp80 %Val, x86_fp80 %Power) 10086*9880d681SAndroid Build Coastguard Worker declare fp128 @llvm.pow.f128(fp128 %Val, fp128 %Power) 10087*9880d681SAndroid Build Coastguard Worker declare ppc_fp128 @llvm.pow.ppcf128(ppc_fp128 %Val, ppc_fp128 Power) 10088*9880d681SAndroid Build Coastguard Worker 10089*9880d681SAndroid Build Coastguard WorkerOverview: 10090*9880d681SAndroid Build Coastguard Worker""""""""" 10091*9880d681SAndroid Build Coastguard Worker 10092*9880d681SAndroid Build Coastguard WorkerThe '``llvm.pow.*``' intrinsics return the first operand raised to the 10093*9880d681SAndroid Build Coastguard Workerspecified (positive or negative) power. 10094*9880d681SAndroid Build Coastguard Worker 10095*9880d681SAndroid Build Coastguard WorkerArguments: 10096*9880d681SAndroid Build Coastguard Worker"""""""""" 10097*9880d681SAndroid Build Coastguard Worker 10098*9880d681SAndroid Build Coastguard WorkerThe second argument is a floating point power, and the first is a value 10099*9880d681SAndroid Build Coastguard Workerto raise to that power. 10100*9880d681SAndroid Build Coastguard Worker 10101*9880d681SAndroid Build Coastguard WorkerSemantics: 10102*9880d681SAndroid Build Coastguard Worker"""""""""" 10103*9880d681SAndroid Build Coastguard Worker 10104*9880d681SAndroid Build Coastguard WorkerThis function returns the first value raised to the second power, 10105*9880d681SAndroid Build Coastguard Workerreturning the same values as the libm ``pow`` functions would, and 10106*9880d681SAndroid Build Coastguard Workerhandles error conditions in the same way. 10107*9880d681SAndroid Build Coastguard Worker 10108*9880d681SAndroid Build Coastguard Worker'``llvm.exp.*``' Intrinsic 10109*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^ 10110*9880d681SAndroid Build Coastguard Worker 10111*9880d681SAndroid Build Coastguard WorkerSyntax: 10112*9880d681SAndroid Build Coastguard Worker""""""" 10113*9880d681SAndroid Build Coastguard Worker 10114*9880d681SAndroid Build Coastguard WorkerThis is an overloaded intrinsic. You can use ``llvm.exp`` on any 10115*9880d681SAndroid Build Coastguard Workerfloating point or vector of floating point type. Not all targets support 10116*9880d681SAndroid Build Coastguard Workerall types however. 10117*9880d681SAndroid Build Coastguard Worker 10118*9880d681SAndroid Build Coastguard Worker:: 10119*9880d681SAndroid Build Coastguard Worker 10120*9880d681SAndroid Build Coastguard Worker declare float @llvm.exp.f32(float %Val) 10121*9880d681SAndroid Build Coastguard Worker declare double @llvm.exp.f64(double %Val) 10122*9880d681SAndroid Build Coastguard Worker declare x86_fp80 @llvm.exp.f80(x86_fp80 %Val) 10123*9880d681SAndroid Build Coastguard Worker declare fp128 @llvm.exp.f128(fp128 %Val) 10124*9880d681SAndroid Build Coastguard Worker declare ppc_fp128 @llvm.exp.ppcf128(ppc_fp128 %Val) 10125*9880d681SAndroid Build Coastguard Worker 10126*9880d681SAndroid Build Coastguard WorkerOverview: 10127*9880d681SAndroid Build Coastguard Worker""""""""" 10128*9880d681SAndroid Build Coastguard Worker 10129*9880d681SAndroid Build Coastguard WorkerThe '``llvm.exp.*``' intrinsics perform the exp function. 10130*9880d681SAndroid Build Coastguard Worker 10131*9880d681SAndroid Build Coastguard WorkerArguments: 10132*9880d681SAndroid Build Coastguard Worker"""""""""" 10133*9880d681SAndroid Build Coastguard Worker 10134*9880d681SAndroid Build Coastguard WorkerThe argument and return value are floating point numbers of the same 10135*9880d681SAndroid Build Coastguard Workertype. 10136*9880d681SAndroid Build Coastguard Worker 10137*9880d681SAndroid Build Coastguard WorkerSemantics: 10138*9880d681SAndroid Build Coastguard Worker"""""""""" 10139*9880d681SAndroid Build Coastguard Worker 10140*9880d681SAndroid Build Coastguard WorkerThis function returns the same values as the libm ``exp`` functions 10141*9880d681SAndroid Build Coastguard Workerwould, and handles error conditions in the same way. 10142*9880d681SAndroid Build Coastguard Worker 10143*9880d681SAndroid Build Coastguard Worker'``llvm.exp2.*``' Intrinsic 10144*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10145*9880d681SAndroid Build Coastguard Worker 10146*9880d681SAndroid Build Coastguard WorkerSyntax: 10147*9880d681SAndroid Build Coastguard Worker""""""" 10148*9880d681SAndroid Build Coastguard Worker 10149*9880d681SAndroid Build Coastguard WorkerThis is an overloaded intrinsic. You can use ``llvm.exp2`` on any 10150*9880d681SAndroid Build Coastguard Workerfloating point or vector of floating point type. Not all targets support 10151*9880d681SAndroid Build Coastguard Workerall types however. 10152*9880d681SAndroid Build Coastguard Worker 10153*9880d681SAndroid Build Coastguard Worker:: 10154*9880d681SAndroid Build Coastguard Worker 10155*9880d681SAndroid Build Coastguard Worker declare float @llvm.exp2.f32(float %Val) 10156*9880d681SAndroid Build Coastguard Worker declare double @llvm.exp2.f64(double %Val) 10157*9880d681SAndroid Build Coastguard Worker declare x86_fp80 @llvm.exp2.f80(x86_fp80 %Val) 10158*9880d681SAndroid Build Coastguard Worker declare fp128 @llvm.exp2.f128(fp128 %Val) 10159*9880d681SAndroid Build Coastguard Worker declare ppc_fp128 @llvm.exp2.ppcf128(ppc_fp128 %Val) 10160*9880d681SAndroid Build Coastguard Worker 10161*9880d681SAndroid Build Coastguard WorkerOverview: 10162*9880d681SAndroid Build Coastguard Worker""""""""" 10163*9880d681SAndroid Build Coastguard Worker 10164*9880d681SAndroid Build Coastguard WorkerThe '``llvm.exp2.*``' intrinsics perform the exp2 function. 10165*9880d681SAndroid Build Coastguard Worker 10166*9880d681SAndroid Build Coastguard WorkerArguments: 10167*9880d681SAndroid Build Coastguard Worker"""""""""" 10168*9880d681SAndroid Build Coastguard Worker 10169*9880d681SAndroid Build Coastguard WorkerThe argument and return value are floating point numbers of the same 10170*9880d681SAndroid Build Coastguard Workertype. 10171*9880d681SAndroid Build Coastguard Worker 10172*9880d681SAndroid Build Coastguard WorkerSemantics: 10173*9880d681SAndroid Build Coastguard Worker"""""""""" 10174*9880d681SAndroid Build Coastguard Worker 10175*9880d681SAndroid Build Coastguard WorkerThis function returns the same values as the libm ``exp2`` functions 10176*9880d681SAndroid Build Coastguard Workerwould, and handles error conditions in the same way. 10177*9880d681SAndroid Build Coastguard Worker 10178*9880d681SAndroid Build Coastguard Worker'``llvm.log.*``' Intrinsic 10179*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^ 10180*9880d681SAndroid Build Coastguard Worker 10181*9880d681SAndroid Build Coastguard WorkerSyntax: 10182*9880d681SAndroid Build Coastguard Worker""""""" 10183*9880d681SAndroid Build Coastguard Worker 10184*9880d681SAndroid Build Coastguard WorkerThis is an overloaded intrinsic. You can use ``llvm.log`` on any 10185*9880d681SAndroid Build Coastguard Workerfloating point or vector of floating point type. Not all targets support 10186*9880d681SAndroid Build Coastguard Workerall types however. 10187*9880d681SAndroid Build Coastguard Worker 10188*9880d681SAndroid Build Coastguard Worker:: 10189*9880d681SAndroid Build Coastguard Worker 10190*9880d681SAndroid Build Coastguard Worker declare float @llvm.log.f32(float %Val) 10191*9880d681SAndroid Build Coastguard Worker declare double @llvm.log.f64(double %Val) 10192*9880d681SAndroid Build Coastguard Worker declare x86_fp80 @llvm.log.f80(x86_fp80 %Val) 10193*9880d681SAndroid Build Coastguard Worker declare fp128 @llvm.log.f128(fp128 %Val) 10194*9880d681SAndroid Build Coastguard Worker declare ppc_fp128 @llvm.log.ppcf128(ppc_fp128 %Val) 10195*9880d681SAndroid Build Coastguard Worker 10196*9880d681SAndroid Build Coastguard WorkerOverview: 10197*9880d681SAndroid Build Coastguard Worker""""""""" 10198*9880d681SAndroid Build Coastguard Worker 10199*9880d681SAndroid Build Coastguard WorkerThe '``llvm.log.*``' intrinsics perform the log function. 10200*9880d681SAndroid Build Coastguard Worker 10201*9880d681SAndroid Build Coastguard WorkerArguments: 10202*9880d681SAndroid Build Coastguard Worker"""""""""" 10203*9880d681SAndroid Build Coastguard Worker 10204*9880d681SAndroid Build Coastguard WorkerThe argument and return value are floating point numbers of the same 10205*9880d681SAndroid Build Coastguard Workertype. 10206*9880d681SAndroid Build Coastguard Worker 10207*9880d681SAndroid Build Coastguard WorkerSemantics: 10208*9880d681SAndroid Build Coastguard Worker"""""""""" 10209*9880d681SAndroid Build Coastguard Worker 10210*9880d681SAndroid Build Coastguard WorkerThis function returns the same values as the libm ``log`` functions 10211*9880d681SAndroid Build Coastguard Workerwould, and handles error conditions in the same way. 10212*9880d681SAndroid Build Coastguard Worker 10213*9880d681SAndroid Build Coastguard Worker'``llvm.log10.*``' Intrinsic 10214*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10215*9880d681SAndroid Build Coastguard Worker 10216*9880d681SAndroid Build Coastguard WorkerSyntax: 10217*9880d681SAndroid Build Coastguard Worker""""""" 10218*9880d681SAndroid Build Coastguard Worker 10219*9880d681SAndroid Build Coastguard WorkerThis is an overloaded intrinsic. You can use ``llvm.log10`` on any 10220*9880d681SAndroid Build Coastguard Workerfloating point or vector of floating point type. Not all targets support 10221*9880d681SAndroid Build Coastguard Workerall types however. 10222*9880d681SAndroid Build Coastguard Worker 10223*9880d681SAndroid Build Coastguard Worker:: 10224*9880d681SAndroid Build Coastguard Worker 10225*9880d681SAndroid Build Coastguard Worker declare float @llvm.log10.f32(float %Val) 10226*9880d681SAndroid Build Coastguard Worker declare double @llvm.log10.f64(double %Val) 10227*9880d681SAndroid Build Coastguard Worker declare x86_fp80 @llvm.log10.f80(x86_fp80 %Val) 10228*9880d681SAndroid Build Coastguard Worker declare fp128 @llvm.log10.f128(fp128 %Val) 10229*9880d681SAndroid Build Coastguard Worker declare ppc_fp128 @llvm.log10.ppcf128(ppc_fp128 %Val) 10230*9880d681SAndroid Build Coastguard Worker 10231*9880d681SAndroid Build Coastguard WorkerOverview: 10232*9880d681SAndroid Build Coastguard Worker""""""""" 10233*9880d681SAndroid Build Coastguard Worker 10234*9880d681SAndroid Build Coastguard WorkerThe '``llvm.log10.*``' intrinsics perform the log10 function. 10235*9880d681SAndroid Build Coastguard Worker 10236*9880d681SAndroid Build Coastguard WorkerArguments: 10237*9880d681SAndroid Build Coastguard Worker"""""""""" 10238*9880d681SAndroid Build Coastguard Worker 10239*9880d681SAndroid Build Coastguard WorkerThe argument and return value are floating point numbers of the same 10240*9880d681SAndroid Build Coastguard Workertype. 10241*9880d681SAndroid Build Coastguard Worker 10242*9880d681SAndroid Build Coastguard WorkerSemantics: 10243*9880d681SAndroid Build Coastguard Worker"""""""""" 10244*9880d681SAndroid Build Coastguard Worker 10245*9880d681SAndroid Build Coastguard WorkerThis function returns the same values as the libm ``log10`` functions 10246*9880d681SAndroid Build Coastguard Workerwould, and handles error conditions in the same way. 10247*9880d681SAndroid Build Coastguard Worker 10248*9880d681SAndroid Build Coastguard Worker'``llvm.log2.*``' Intrinsic 10249*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10250*9880d681SAndroid Build Coastguard Worker 10251*9880d681SAndroid Build Coastguard WorkerSyntax: 10252*9880d681SAndroid Build Coastguard Worker""""""" 10253*9880d681SAndroid Build Coastguard Worker 10254*9880d681SAndroid Build Coastguard WorkerThis is an overloaded intrinsic. You can use ``llvm.log2`` on any 10255*9880d681SAndroid Build Coastguard Workerfloating point or vector of floating point type. Not all targets support 10256*9880d681SAndroid Build Coastguard Workerall types however. 10257*9880d681SAndroid Build Coastguard Worker 10258*9880d681SAndroid Build Coastguard Worker:: 10259*9880d681SAndroid Build Coastguard Worker 10260*9880d681SAndroid Build Coastguard Worker declare float @llvm.log2.f32(float %Val) 10261*9880d681SAndroid Build Coastguard Worker declare double @llvm.log2.f64(double %Val) 10262*9880d681SAndroid Build Coastguard Worker declare x86_fp80 @llvm.log2.f80(x86_fp80 %Val) 10263*9880d681SAndroid Build Coastguard Worker declare fp128 @llvm.log2.f128(fp128 %Val) 10264*9880d681SAndroid Build Coastguard Worker declare ppc_fp128 @llvm.log2.ppcf128(ppc_fp128 %Val) 10265*9880d681SAndroid Build Coastguard Worker 10266*9880d681SAndroid Build Coastguard WorkerOverview: 10267*9880d681SAndroid Build Coastguard Worker""""""""" 10268*9880d681SAndroid Build Coastguard Worker 10269*9880d681SAndroid Build Coastguard WorkerThe '``llvm.log2.*``' intrinsics perform the log2 function. 10270*9880d681SAndroid Build Coastguard Worker 10271*9880d681SAndroid Build Coastguard WorkerArguments: 10272*9880d681SAndroid Build Coastguard Worker"""""""""" 10273*9880d681SAndroid Build Coastguard Worker 10274*9880d681SAndroid Build Coastguard WorkerThe argument and return value are floating point numbers of the same 10275*9880d681SAndroid Build Coastguard Workertype. 10276*9880d681SAndroid Build Coastguard Worker 10277*9880d681SAndroid Build Coastguard WorkerSemantics: 10278*9880d681SAndroid Build Coastguard Worker"""""""""" 10279*9880d681SAndroid Build Coastguard Worker 10280*9880d681SAndroid Build Coastguard WorkerThis function returns the same values as the libm ``log2`` functions 10281*9880d681SAndroid Build Coastguard Workerwould, and handles error conditions in the same way. 10282*9880d681SAndroid Build Coastguard Worker 10283*9880d681SAndroid Build Coastguard Worker'``llvm.fma.*``' Intrinsic 10284*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^ 10285*9880d681SAndroid Build Coastguard Worker 10286*9880d681SAndroid Build Coastguard WorkerSyntax: 10287*9880d681SAndroid Build Coastguard Worker""""""" 10288*9880d681SAndroid Build Coastguard Worker 10289*9880d681SAndroid Build Coastguard WorkerThis is an overloaded intrinsic. You can use ``llvm.fma`` on any 10290*9880d681SAndroid Build Coastguard Workerfloating point or vector of floating point type. Not all targets support 10291*9880d681SAndroid Build Coastguard Workerall types however. 10292*9880d681SAndroid Build Coastguard Worker 10293*9880d681SAndroid Build Coastguard Worker:: 10294*9880d681SAndroid Build Coastguard Worker 10295*9880d681SAndroid Build Coastguard Worker declare float @llvm.fma.f32(float %a, float %b, float %c) 10296*9880d681SAndroid Build Coastguard Worker declare double @llvm.fma.f64(double %a, double %b, double %c) 10297*9880d681SAndroid Build Coastguard Worker declare x86_fp80 @llvm.fma.f80(x86_fp80 %a, x86_fp80 %b, x86_fp80 %c) 10298*9880d681SAndroid Build Coastguard Worker declare fp128 @llvm.fma.f128(fp128 %a, fp128 %b, fp128 %c) 10299*9880d681SAndroid Build Coastguard Worker declare ppc_fp128 @llvm.fma.ppcf128(ppc_fp128 %a, ppc_fp128 %b, ppc_fp128 %c) 10300*9880d681SAndroid Build Coastguard Worker 10301*9880d681SAndroid Build Coastguard WorkerOverview: 10302*9880d681SAndroid Build Coastguard Worker""""""""" 10303*9880d681SAndroid Build Coastguard Worker 10304*9880d681SAndroid Build Coastguard WorkerThe '``llvm.fma.*``' intrinsics perform the fused multiply-add 10305*9880d681SAndroid Build Coastguard Workeroperation. 10306*9880d681SAndroid Build Coastguard Worker 10307*9880d681SAndroid Build Coastguard WorkerArguments: 10308*9880d681SAndroid Build Coastguard Worker"""""""""" 10309*9880d681SAndroid Build Coastguard Worker 10310*9880d681SAndroid Build Coastguard WorkerThe argument and return value are floating point numbers of the same 10311*9880d681SAndroid Build Coastguard Workertype. 10312*9880d681SAndroid Build Coastguard Worker 10313*9880d681SAndroid Build Coastguard WorkerSemantics: 10314*9880d681SAndroid Build Coastguard Worker"""""""""" 10315*9880d681SAndroid Build Coastguard Worker 10316*9880d681SAndroid Build Coastguard WorkerThis function returns the same values as the libm ``fma`` functions 10317*9880d681SAndroid Build Coastguard Workerwould, and does not set errno. 10318*9880d681SAndroid Build Coastguard Worker 10319*9880d681SAndroid Build Coastguard Worker'``llvm.fabs.*``' Intrinsic 10320*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10321*9880d681SAndroid Build Coastguard Worker 10322*9880d681SAndroid Build Coastguard WorkerSyntax: 10323*9880d681SAndroid Build Coastguard Worker""""""" 10324*9880d681SAndroid Build Coastguard Worker 10325*9880d681SAndroid Build Coastguard WorkerThis is an overloaded intrinsic. You can use ``llvm.fabs`` on any 10326*9880d681SAndroid Build Coastguard Workerfloating point or vector of floating point type. Not all targets support 10327*9880d681SAndroid Build Coastguard Workerall types however. 10328*9880d681SAndroid Build Coastguard Worker 10329*9880d681SAndroid Build Coastguard Worker:: 10330*9880d681SAndroid Build Coastguard Worker 10331*9880d681SAndroid Build Coastguard Worker declare float @llvm.fabs.f32(float %Val) 10332*9880d681SAndroid Build Coastguard Worker declare double @llvm.fabs.f64(double %Val) 10333*9880d681SAndroid Build Coastguard Worker declare x86_fp80 @llvm.fabs.f80(x86_fp80 %Val) 10334*9880d681SAndroid Build Coastguard Worker declare fp128 @llvm.fabs.f128(fp128 %Val) 10335*9880d681SAndroid Build Coastguard Worker declare ppc_fp128 @llvm.fabs.ppcf128(ppc_fp128 %Val) 10336*9880d681SAndroid Build Coastguard Worker 10337*9880d681SAndroid Build Coastguard WorkerOverview: 10338*9880d681SAndroid Build Coastguard Worker""""""""" 10339*9880d681SAndroid Build Coastguard Worker 10340*9880d681SAndroid Build Coastguard WorkerThe '``llvm.fabs.*``' intrinsics return the absolute value of the 10341*9880d681SAndroid Build Coastguard Workeroperand. 10342*9880d681SAndroid Build Coastguard Worker 10343*9880d681SAndroid Build Coastguard WorkerArguments: 10344*9880d681SAndroid Build Coastguard Worker"""""""""" 10345*9880d681SAndroid Build Coastguard Worker 10346*9880d681SAndroid Build Coastguard WorkerThe argument and return value are floating point numbers of the same 10347*9880d681SAndroid Build Coastguard Workertype. 10348*9880d681SAndroid Build Coastguard Worker 10349*9880d681SAndroid Build Coastguard WorkerSemantics: 10350*9880d681SAndroid Build Coastguard Worker"""""""""" 10351*9880d681SAndroid Build Coastguard Worker 10352*9880d681SAndroid Build Coastguard WorkerThis function returns the same values as the libm ``fabs`` functions 10353*9880d681SAndroid Build Coastguard Workerwould, and handles error conditions in the same way. 10354*9880d681SAndroid Build Coastguard Worker 10355*9880d681SAndroid Build Coastguard Worker'``llvm.minnum.*``' Intrinsic 10356*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10357*9880d681SAndroid Build Coastguard Worker 10358*9880d681SAndroid Build Coastguard WorkerSyntax: 10359*9880d681SAndroid Build Coastguard Worker""""""" 10360*9880d681SAndroid Build Coastguard Worker 10361*9880d681SAndroid Build Coastguard WorkerThis is an overloaded intrinsic. You can use ``llvm.minnum`` on any 10362*9880d681SAndroid Build Coastguard Workerfloating point or vector of floating point type. Not all targets support 10363*9880d681SAndroid Build Coastguard Workerall types however. 10364*9880d681SAndroid Build Coastguard Worker 10365*9880d681SAndroid Build Coastguard Worker:: 10366*9880d681SAndroid Build Coastguard Worker 10367*9880d681SAndroid Build Coastguard Worker declare float @llvm.minnum.f32(float %Val0, float %Val1) 10368*9880d681SAndroid Build Coastguard Worker declare double @llvm.minnum.f64(double %Val0, double %Val1) 10369*9880d681SAndroid Build Coastguard Worker declare x86_fp80 @llvm.minnum.f80(x86_fp80 %Val0, x86_fp80 %Val1) 10370*9880d681SAndroid Build Coastguard Worker declare fp128 @llvm.minnum.f128(fp128 %Val0, fp128 %Val1) 10371*9880d681SAndroid Build Coastguard Worker declare ppc_fp128 @llvm.minnum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1) 10372*9880d681SAndroid Build Coastguard Worker 10373*9880d681SAndroid Build Coastguard WorkerOverview: 10374*9880d681SAndroid Build Coastguard Worker""""""""" 10375*9880d681SAndroid Build Coastguard Worker 10376*9880d681SAndroid Build Coastguard WorkerThe '``llvm.minnum.*``' intrinsics return the minimum of the two 10377*9880d681SAndroid Build Coastguard Workerarguments. 10378*9880d681SAndroid Build Coastguard Worker 10379*9880d681SAndroid Build Coastguard Worker 10380*9880d681SAndroid Build Coastguard WorkerArguments: 10381*9880d681SAndroid Build Coastguard Worker"""""""""" 10382*9880d681SAndroid Build Coastguard Worker 10383*9880d681SAndroid Build Coastguard WorkerThe arguments and return value are floating point numbers of the same 10384*9880d681SAndroid Build Coastguard Workertype. 10385*9880d681SAndroid Build Coastguard Worker 10386*9880d681SAndroid Build Coastguard WorkerSemantics: 10387*9880d681SAndroid Build Coastguard Worker"""""""""" 10388*9880d681SAndroid Build Coastguard Worker 10389*9880d681SAndroid Build Coastguard WorkerFollows the IEEE-754 semantics for minNum, which also match for libm's 10390*9880d681SAndroid Build Coastguard Workerfmin. 10391*9880d681SAndroid Build Coastguard Worker 10392*9880d681SAndroid Build Coastguard WorkerIf either operand is a NaN, returns the other non-NaN operand. Returns 10393*9880d681SAndroid Build Coastguard WorkerNaN only if both operands are NaN. If the operands compare equal, 10394*9880d681SAndroid Build Coastguard Workerreturns a value that compares equal to both operands. This means that 10395*9880d681SAndroid Build Coastguard Workerfmin(+/-0.0, +/-0.0) could return either -0.0 or 0.0. 10396*9880d681SAndroid Build Coastguard Worker 10397*9880d681SAndroid Build Coastguard Worker'``llvm.maxnum.*``' Intrinsic 10398*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10399*9880d681SAndroid Build Coastguard Worker 10400*9880d681SAndroid Build Coastguard WorkerSyntax: 10401*9880d681SAndroid Build Coastguard Worker""""""" 10402*9880d681SAndroid Build Coastguard Worker 10403*9880d681SAndroid Build Coastguard WorkerThis is an overloaded intrinsic. You can use ``llvm.maxnum`` on any 10404*9880d681SAndroid Build Coastguard Workerfloating point or vector of floating point type. Not all targets support 10405*9880d681SAndroid Build Coastguard Workerall types however. 10406*9880d681SAndroid Build Coastguard Worker 10407*9880d681SAndroid Build Coastguard Worker:: 10408*9880d681SAndroid Build Coastguard Worker 10409*9880d681SAndroid Build Coastguard Worker declare float @llvm.maxnum.f32(float %Val0, float %Val1l) 10410*9880d681SAndroid Build Coastguard Worker declare double @llvm.maxnum.f64(double %Val0, double %Val1) 10411*9880d681SAndroid Build Coastguard Worker declare x86_fp80 @llvm.maxnum.f80(x86_fp80 %Val0, x86_fp80 %Val1) 10412*9880d681SAndroid Build Coastguard Worker declare fp128 @llvm.maxnum.f128(fp128 %Val0, fp128 %Val1) 10413*9880d681SAndroid Build Coastguard Worker declare ppc_fp128 @llvm.maxnum.ppcf128(ppc_fp128 %Val0, ppc_fp128 %Val1) 10414*9880d681SAndroid Build Coastguard Worker 10415*9880d681SAndroid Build Coastguard WorkerOverview: 10416*9880d681SAndroid Build Coastguard Worker""""""""" 10417*9880d681SAndroid Build Coastguard Worker 10418*9880d681SAndroid Build Coastguard WorkerThe '``llvm.maxnum.*``' intrinsics return the maximum of the two 10419*9880d681SAndroid Build Coastguard Workerarguments. 10420*9880d681SAndroid Build Coastguard Worker 10421*9880d681SAndroid Build Coastguard Worker 10422*9880d681SAndroid Build Coastguard WorkerArguments: 10423*9880d681SAndroid Build Coastguard Worker"""""""""" 10424*9880d681SAndroid Build Coastguard Worker 10425*9880d681SAndroid Build Coastguard WorkerThe arguments and return value are floating point numbers of the same 10426*9880d681SAndroid Build Coastguard Workertype. 10427*9880d681SAndroid Build Coastguard Worker 10428*9880d681SAndroid Build Coastguard WorkerSemantics: 10429*9880d681SAndroid Build Coastguard Worker"""""""""" 10430*9880d681SAndroid Build Coastguard WorkerFollows the IEEE-754 semantics for maxNum, which also match for libm's 10431*9880d681SAndroid Build Coastguard Workerfmax. 10432*9880d681SAndroid Build Coastguard Worker 10433*9880d681SAndroid Build Coastguard WorkerIf either operand is a NaN, returns the other non-NaN operand. Returns 10434*9880d681SAndroid Build Coastguard WorkerNaN only if both operands are NaN. If the operands compare equal, 10435*9880d681SAndroid Build Coastguard Workerreturns a value that compares equal to both operands. This means that 10436*9880d681SAndroid Build Coastguard Workerfmax(+/-0.0, +/-0.0) could return either -0.0 or 0.0. 10437*9880d681SAndroid Build Coastguard Worker 10438*9880d681SAndroid Build Coastguard Worker'``llvm.copysign.*``' Intrinsic 10439*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10440*9880d681SAndroid Build Coastguard Worker 10441*9880d681SAndroid Build Coastguard WorkerSyntax: 10442*9880d681SAndroid Build Coastguard Worker""""""" 10443*9880d681SAndroid Build Coastguard Worker 10444*9880d681SAndroid Build Coastguard WorkerThis is an overloaded intrinsic. You can use ``llvm.copysign`` on any 10445*9880d681SAndroid Build Coastguard Workerfloating point or vector of floating point type. Not all targets support 10446*9880d681SAndroid Build Coastguard Workerall types however. 10447*9880d681SAndroid Build Coastguard Worker 10448*9880d681SAndroid Build Coastguard Worker:: 10449*9880d681SAndroid Build Coastguard Worker 10450*9880d681SAndroid Build Coastguard Worker declare float @llvm.copysign.f32(float %Mag, float %Sgn) 10451*9880d681SAndroid Build Coastguard Worker declare double @llvm.copysign.f64(double %Mag, double %Sgn) 10452*9880d681SAndroid Build Coastguard Worker declare x86_fp80 @llvm.copysign.f80(x86_fp80 %Mag, x86_fp80 %Sgn) 10453*9880d681SAndroid Build Coastguard Worker declare fp128 @llvm.copysign.f128(fp128 %Mag, fp128 %Sgn) 10454*9880d681SAndroid Build Coastguard Worker declare ppc_fp128 @llvm.copysign.ppcf128(ppc_fp128 %Mag, ppc_fp128 %Sgn) 10455*9880d681SAndroid Build Coastguard Worker 10456*9880d681SAndroid Build Coastguard WorkerOverview: 10457*9880d681SAndroid Build Coastguard Worker""""""""" 10458*9880d681SAndroid Build Coastguard Worker 10459*9880d681SAndroid Build Coastguard WorkerThe '``llvm.copysign.*``' intrinsics return a value with the magnitude of the 10460*9880d681SAndroid Build Coastguard Workerfirst operand and the sign of the second operand. 10461*9880d681SAndroid Build Coastguard Worker 10462*9880d681SAndroid Build Coastguard WorkerArguments: 10463*9880d681SAndroid Build Coastguard Worker"""""""""" 10464*9880d681SAndroid Build Coastguard Worker 10465*9880d681SAndroid Build Coastguard WorkerThe arguments and return value are floating point numbers of the same 10466*9880d681SAndroid Build Coastguard Workertype. 10467*9880d681SAndroid Build Coastguard Worker 10468*9880d681SAndroid Build Coastguard WorkerSemantics: 10469*9880d681SAndroid Build Coastguard Worker"""""""""" 10470*9880d681SAndroid Build Coastguard Worker 10471*9880d681SAndroid Build Coastguard WorkerThis function returns the same values as the libm ``copysign`` 10472*9880d681SAndroid Build Coastguard Workerfunctions would, and handles error conditions in the same way. 10473*9880d681SAndroid Build Coastguard Worker 10474*9880d681SAndroid Build Coastguard Worker'``llvm.floor.*``' Intrinsic 10475*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10476*9880d681SAndroid Build Coastguard Worker 10477*9880d681SAndroid Build Coastguard WorkerSyntax: 10478*9880d681SAndroid Build Coastguard Worker""""""" 10479*9880d681SAndroid Build Coastguard Worker 10480*9880d681SAndroid Build Coastguard WorkerThis is an overloaded intrinsic. You can use ``llvm.floor`` on any 10481*9880d681SAndroid Build Coastguard Workerfloating point or vector of floating point type. Not all targets support 10482*9880d681SAndroid Build Coastguard Workerall types however. 10483*9880d681SAndroid Build Coastguard Worker 10484*9880d681SAndroid Build Coastguard Worker:: 10485*9880d681SAndroid Build Coastguard Worker 10486*9880d681SAndroid Build Coastguard Worker declare float @llvm.floor.f32(float %Val) 10487*9880d681SAndroid Build Coastguard Worker declare double @llvm.floor.f64(double %Val) 10488*9880d681SAndroid Build Coastguard Worker declare x86_fp80 @llvm.floor.f80(x86_fp80 %Val) 10489*9880d681SAndroid Build Coastguard Worker declare fp128 @llvm.floor.f128(fp128 %Val) 10490*9880d681SAndroid Build Coastguard Worker declare ppc_fp128 @llvm.floor.ppcf128(ppc_fp128 %Val) 10491*9880d681SAndroid Build Coastguard Worker 10492*9880d681SAndroid Build Coastguard WorkerOverview: 10493*9880d681SAndroid Build Coastguard Worker""""""""" 10494*9880d681SAndroid Build Coastguard Worker 10495*9880d681SAndroid Build Coastguard WorkerThe '``llvm.floor.*``' intrinsics return the floor of the operand. 10496*9880d681SAndroid Build Coastguard Worker 10497*9880d681SAndroid Build Coastguard WorkerArguments: 10498*9880d681SAndroid Build Coastguard Worker"""""""""" 10499*9880d681SAndroid Build Coastguard Worker 10500*9880d681SAndroid Build Coastguard WorkerThe argument and return value are floating point numbers of the same 10501*9880d681SAndroid Build Coastguard Workertype. 10502*9880d681SAndroid Build Coastguard Worker 10503*9880d681SAndroid Build Coastguard WorkerSemantics: 10504*9880d681SAndroid Build Coastguard Worker"""""""""" 10505*9880d681SAndroid Build Coastguard Worker 10506*9880d681SAndroid Build Coastguard WorkerThis function returns the same values as the libm ``floor`` functions 10507*9880d681SAndroid Build Coastguard Workerwould, and handles error conditions in the same way. 10508*9880d681SAndroid Build Coastguard Worker 10509*9880d681SAndroid Build Coastguard Worker'``llvm.ceil.*``' Intrinsic 10510*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10511*9880d681SAndroid Build Coastguard Worker 10512*9880d681SAndroid Build Coastguard WorkerSyntax: 10513*9880d681SAndroid Build Coastguard Worker""""""" 10514*9880d681SAndroid Build Coastguard Worker 10515*9880d681SAndroid Build Coastguard WorkerThis is an overloaded intrinsic. You can use ``llvm.ceil`` on any 10516*9880d681SAndroid Build Coastguard Workerfloating point or vector of floating point type. Not all targets support 10517*9880d681SAndroid Build Coastguard Workerall types however. 10518*9880d681SAndroid Build Coastguard Worker 10519*9880d681SAndroid Build Coastguard Worker:: 10520*9880d681SAndroid Build Coastguard Worker 10521*9880d681SAndroid Build Coastguard Worker declare float @llvm.ceil.f32(float %Val) 10522*9880d681SAndroid Build Coastguard Worker declare double @llvm.ceil.f64(double %Val) 10523*9880d681SAndroid Build Coastguard Worker declare x86_fp80 @llvm.ceil.f80(x86_fp80 %Val) 10524*9880d681SAndroid Build Coastguard Worker declare fp128 @llvm.ceil.f128(fp128 %Val) 10525*9880d681SAndroid Build Coastguard Worker declare ppc_fp128 @llvm.ceil.ppcf128(ppc_fp128 %Val) 10526*9880d681SAndroid Build Coastguard Worker 10527*9880d681SAndroid Build Coastguard WorkerOverview: 10528*9880d681SAndroid Build Coastguard Worker""""""""" 10529*9880d681SAndroid Build Coastguard Worker 10530*9880d681SAndroid Build Coastguard WorkerThe '``llvm.ceil.*``' intrinsics return the ceiling of the operand. 10531*9880d681SAndroid Build Coastguard Worker 10532*9880d681SAndroid Build Coastguard WorkerArguments: 10533*9880d681SAndroid Build Coastguard Worker"""""""""" 10534*9880d681SAndroid Build Coastguard Worker 10535*9880d681SAndroid Build Coastguard WorkerThe argument and return value are floating point numbers of the same 10536*9880d681SAndroid Build Coastguard Workertype. 10537*9880d681SAndroid Build Coastguard Worker 10538*9880d681SAndroid Build Coastguard WorkerSemantics: 10539*9880d681SAndroid Build Coastguard Worker"""""""""" 10540*9880d681SAndroid Build Coastguard Worker 10541*9880d681SAndroid Build Coastguard WorkerThis function returns the same values as the libm ``ceil`` functions 10542*9880d681SAndroid Build Coastguard Workerwould, and handles error conditions in the same way. 10543*9880d681SAndroid Build Coastguard Worker 10544*9880d681SAndroid Build Coastguard Worker'``llvm.trunc.*``' Intrinsic 10545*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10546*9880d681SAndroid Build Coastguard Worker 10547*9880d681SAndroid Build Coastguard WorkerSyntax: 10548*9880d681SAndroid Build Coastguard Worker""""""" 10549*9880d681SAndroid Build Coastguard Worker 10550*9880d681SAndroid Build Coastguard WorkerThis is an overloaded intrinsic. You can use ``llvm.trunc`` on any 10551*9880d681SAndroid Build Coastguard Workerfloating point or vector of floating point type. Not all targets support 10552*9880d681SAndroid Build Coastguard Workerall types however. 10553*9880d681SAndroid Build Coastguard Worker 10554*9880d681SAndroid Build Coastguard Worker:: 10555*9880d681SAndroid Build Coastguard Worker 10556*9880d681SAndroid Build Coastguard Worker declare float @llvm.trunc.f32(float %Val) 10557*9880d681SAndroid Build Coastguard Worker declare double @llvm.trunc.f64(double %Val) 10558*9880d681SAndroid Build Coastguard Worker declare x86_fp80 @llvm.trunc.f80(x86_fp80 %Val) 10559*9880d681SAndroid Build Coastguard Worker declare fp128 @llvm.trunc.f128(fp128 %Val) 10560*9880d681SAndroid Build Coastguard Worker declare ppc_fp128 @llvm.trunc.ppcf128(ppc_fp128 %Val) 10561*9880d681SAndroid Build Coastguard Worker 10562*9880d681SAndroid Build Coastguard WorkerOverview: 10563*9880d681SAndroid Build Coastguard Worker""""""""" 10564*9880d681SAndroid Build Coastguard Worker 10565*9880d681SAndroid Build Coastguard WorkerThe '``llvm.trunc.*``' intrinsics returns the operand rounded to the 10566*9880d681SAndroid Build Coastguard Workernearest integer not larger in magnitude than the operand. 10567*9880d681SAndroid Build Coastguard Worker 10568*9880d681SAndroid Build Coastguard WorkerArguments: 10569*9880d681SAndroid Build Coastguard Worker"""""""""" 10570*9880d681SAndroid Build Coastguard Worker 10571*9880d681SAndroid Build Coastguard WorkerThe argument and return value are floating point numbers of the same 10572*9880d681SAndroid Build Coastguard Workertype. 10573*9880d681SAndroid Build Coastguard Worker 10574*9880d681SAndroid Build Coastguard WorkerSemantics: 10575*9880d681SAndroid Build Coastguard Worker"""""""""" 10576*9880d681SAndroid Build Coastguard Worker 10577*9880d681SAndroid Build Coastguard WorkerThis function returns the same values as the libm ``trunc`` functions 10578*9880d681SAndroid Build Coastguard Workerwould, and handles error conditions in the same way. 10579*9880d681SAndroid Build Coastguard Worker 10580*9880d681SAndroid Build Coastguard Worker'``llvm.rint.*``' Intrinsic 10581*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10582*9880d681SAndroid Build Coastguard Worker 10583*9880d681SAndroid Build Coastguard WorkerSyntax: 10584*9880d681SAndroid Build Coastguard Worker""""""" 10585*9880d681SAndroid Build Coastguard Worker 10586*9880d681SAndroid Build Coastguard WorkerThis is an overloaded intrinsic. You can use ``llvm.rint`` on any 10587*9880d681SAndroid Build Coastguard Workerfloating point or vector of floating point type. Not all targets support 10588*9880d681SAndroid Build Coastguard Workerall types however. 10589*9880d681SAndroid Build Coastguard Worker 10590*9880d681SAndroid Build Coastguard Worker:: 10591*9880d681SAndroid Build Coastguard Worker 10592*9880d681SAndroid Build Coastguard Worker declare float @llvm.rint.f32(float %Val) 10593*9880d681SAndroid Build Coastguard Worker declare double @llvm.rint.f64(double %Val) 10594*9880d681SAndroid Build Coastguard Worker declare x86_fp80 @llvm.rint.f80(x86_fp80 %Val) 10595*9880d681SAndroid Build Coastguard Worker declare fp128 @llvm.rint.f128(fp128 %Val) 10596*9880d681SAndroid Build Coastguard Worker declare ppc_fp128 @llvm.rint.ppcf128(ppc_fp128 %Val) 10597*9880d681SAndroid Build Coastguard Worker 10598*9880d681SAndroid Build Coastguard WorkerOverview: 10599*9880d681SAndroid Build Coastguard Worker""""""""" 10600*9880d681SAndroid Build Coastguard Worker 10601*9880d681SAndroid Build Coastguard WorkerThe '``llvm.rint.*``' intrinsics returns the operand rounded to the 10602*9880d681SAndroid Build Coastguard Workernearest integer. It may raise an inexact floating-point exception if the 10603*9880d681SAndroid Build Coastguard Workeroperand isn't an integer. 10604*9880d681SAndroid Build Coastguard Worker 10605*9880d681SAndroid Build Coastguard WorkerArguments: 10606*9880d681SAndroid Build Coastguard Worker"""""""""" 10607*9880d681SAndroid Build Coastguard Worker 10608*9880d681SAndroid Build Coastguard WorkerThe argument and return value are floating point numbers of the same 10609*9880d681SAndroid Build Coastguard Workertype. 10610*9880d681SAndroid Build Coastguard Worker 10611*9880d681SAndroid Build Coastguard WorkerSemantics: 10612*9880d681SAndroid Build Coastguard Worker"""""""""" 10613*9880d681SAndroid Build Coastguard Worker 10614*9880d681SAndroid Build Coastguard WorkerThis function returns the same values as the libm ``rint`` functions 10615*9880d681SAndroid Build Coastguard Workerwould, and handles error conditions in the same way. 10616*9880d681SAndroid Build Coastguard Worker 10617*9880d681SAndroid Build Coastguard Worker'``llvm.nearbyint.*``' Intrinsic 10618*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10619*9880d681SAndroid Build Coastguard Worker 10620*9880d681SAndroid Build Coastguard WorkerSyntax: 10621*9880d681SAndroid Build Coastguard Worker""""""" 10622*9880d681SAndroid Build Coastguard Worker 10623*9880d681SAndroid Build Coastguard WorkerThis is an overloaded intrinsic. You can use ``llvm.nearbyint`` on any 10624*9880d681SAndroid Build Coastguard Workerfloating point or vector of floating point type. Not all targets support 10625*9880d681SAndroid Build Coastguard Workerall types however. 10626*9880d681SAndroid Build Coastguard Worker 10627*9880d681SAndroid Build Coastguard Worker:: 10628*9880d681SAndroid Build Coastguard Worker 10629*9880d681SAndroid Build Coastguard Worker declare float @llvm.nearbyint.f32(float %Val) 10630*9880d681SAndroid Build Coastguard Worker declare double @llvm.nearbyint.f64(double %Val) 10631*9880d681SAndroid Build Coastguard Worker declare x86_fp80 @llvm.nearbyint.f80(x86_fp80 %Val) 10632*9880d681SAndroid Build Coastguard Worker declare fp128 @llvm.nearbyint.f128(fp128 %Val) 10633*9880d681SAndroid Build Coastguard Worker declare ppc_fp128 @llvm.nearbyint.ppcf128(ppc_fp128 %Val) 10634*9880d681SAndroid Build Coastguard Worker 10635*9880d681SAndroid Build Coastguard WorkerOverview: 10636*9880d681SAndroid Build Coastguard Worker""""""""" 10637*9880d681SAndroid Build Coastguard Worker 10638*9880d681SAndroid Build Coastguard WorkerThe '``llvm.nearbyint.*``' intrinsics returns the operand rounded to the 10639*9880d681SAndroid Build Coastguard Workernearest integer. 10640*9880d681SAndroid Build Coastguard Worker 10641*9880d681SAndroid Build Coastguard WorkerArguments: 10642*9880d681SAndroid Build Coastguard Worker"""""""""" 10643*9880d681SAndroid Build Coastguard Worker 10644*9880d681SAndroid Build Coastguard WorkerThe argument and return value are floating point numbers of the same 10645*9880d681SAndroid Build Coastguard Workertype. 10646*9880d681SAndroid Build Coastguard Worker 10647*9880d681SAndroid Build Coastguard WorkerSemantics: 10648*9880d681SAndroid Build Coastguard Worker"""""""""" 10649*9880d681SAndroid Build Coastguard Worker 10650*9880d681SAndroid Build Coastguard WorkerThis function returns the same values as the libm ``nearbyint`` 10651*9880d681SAndroid Build Coastguard Workerfunctions would, and handles error conditions in the same way. 10652*9880d681SAndroid Build Coastguard Worker 10653*9880d681SAndroid Build Coastguard Worker'``llvm.round.*``' Intrinsic 10654*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10655*9880d681SAndroid Build Coastguard Worker 10656*9880d681SAndroid Build Coastguard WorkerSyntax: 10657*9880d681SAndroid Build Coastguard Worker""""""" 10658*9880d681SAndroid Build Coastguard Worker 10659*9880d681SAndroid Build Coastguard WorkerThis is an overloaded intrinsic. You can use ``llvm.round`` on any 10660*9880d681SAndroid Build Coastguard Workerfloating point or vector of floating point type. Not all targets support 10661*9880d681SAndroid Build Coastguard Workerall types however. 10662*9880d681SAndroid Build Coastguard Worker 10663*9880d681SAndroid Build Coastguard Worker:: 10664*9880d681SAndroid Build Coastguard Worker 10665*9880d681SAndroid Build Coastguard Worker declare float @llvm.round.f32(float %Val) 10666*9880d681SAndroid Build Coastguard Worker declare double @llvm.round.f64(double %Val) 10667*9880d681SAndroid Build Coastguard Worker declare x86_fp80 @llvm.round.f80(x86_fp80 %Val) 10668*9880d681SAndroid Build Coastguard Worker declare fp128 @llvm.round.f128(fp128 %Val) 10669*9880d681SAndroid Build Coastguard Worker declare ppc_fp128 @llvm.round.ppcf128(ppc_fp128 %Val) 10670*9880d681SAndroid Build Coastguard Worker 10671*9880d681SAndroid Build Coastguard WorkerOverview: 10672*9880d681SAndroid Build Coastguard Worker""""""""" 10673*9880d681SAndroid Build Coastguard Worker 10674*9880d681SAndroid Build Coastguard WorkerThe '``llvm.round.*``' intrinsics returns the operand rounded to the 10675*9880d681SAndroid Build Coastguard Workernearest integer. 10676*9880d681SAndroid Build Coastguard Worker 10677*9880d681SAndroid Build Coastguard WorkerArguments: 10678*9880d681SAndroid Build Coastguard Worker"""""""""" 10679*9880d681SAndroid Build Coastguard Worker 10680*9880d681SAndroid Build Coastguard WorkerThe argument and return value are floating point numbers of the same 10681*9880d681SAndroid Build Coastguard Workertype. 10682*9880d681SAndroid Build Coastguard Worker 10683*9880d681SAndroid Build Coastguard WorkerSemantics: 10684*9880d681SAndroid Build Coastguard Worker"""""""""" 10685*9880d681SAndroid Build Coastguard Worker 10686*9880d681SAndroid Build Coastguard WorkerThis function returns the same values as the libm ``round`` 10687*9880d681SAndroid Build Coastguard Workerfunctions would, and handles error conditions in the same way. 10688*9880d681SAndroid Build Coastguard Worker 10689*9880d681SAndroid Build Coastguard WorkerBit Manipulation Intrinsics 10690*9880d681SAndroid Build Coastguard Worker--------------------------- 10691*9880d681SAndroid Build Coastguard Worker 10692*9880d681SAndroid Build Coastguard WorkerLLVM provides intrinsics for a few important bit manipulation 10693*9880d681SAndroid Build Coastguard Workeroperations. These allow efficient code generation for some algorithms. 10694*9880d681SAndroid Build Coastguard Worker 10695*9880d681SAndroid Build Coastguard Worker'``llvm.bitreverse.*``' Intrinsics 10696*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10697*9880d681SAndroid Build Coastguard Worker 10698*9880d681SAndroid Build Coastguard WorkerSyntax: 10699*9880d681SAndroid Build Coastguard Worker""""""" 10700*9880d681SAndroid Build Coastguard Worker 10701*9880d681SAndroid Build Coastguard WorkerThis is an overloaded intrinsic function. You can use bitreverse on any 10702*9880d681SAndroid Build Coastguard Workerinteger type. 10703*9880d681SAndroid Build Coastguard Worker 10704*9880d681SAndroid Build Coastguard Worker:: 10705*9880d681SAndroid Build Coastguard Worker 10706*9880d681SAndroid Build Coastguard Worker declare i16 @llvm.bitreverse.i16(i16 <id>) 10707*9880d681SAndroid Build Coastguard Worker declare i32 @llvm.bitreverse.i32(i32 <id>) 10708*9880d681SAndroid Build Coastguard Worker declare i64 @llvm.bitreverse.i64(i64 <id>) 10709*9880d681SAndroid Build Coastguard Worker 10710*9880d681SAndroid Build Coastguard WorkerOverview: 10711*9880d681SAndroid Build Coastguard Worker""""""""" 10712*9880d681SAndroid Build Coastguard Worker 10713*9880d681SAndroid Build Coastguard WorkerThe '``llvm.bitreverse``' family of intrinsics is used to reverse the 10714*9880d681SAndroid Build Coastguard Workerbitpattern of an integer value; for example ``0b10110110`` becomes 10715*9880d681SAndroid Build Coastguard Worker``0b01101101``. 10716*9880d681SAndroid Build Coastguard Worker 10717*9880d681SAndroid Build Coastguard WorkerSemantics: 10718*9880d681SAndroid Build Coastguard Worker"""""""""" 10719*9880d681SAndroid Build Coastguard Worker 10720*9880d681SAndroid Build Coastguard WorkerThe ``llvm.bitreverse.iN`` intrinsic returns an i16 value that has bit 10721*9880d681SAndroid Build Coastguard Worker``M`` in the input moved to bit ``N-M`` in the output. 10722*9880d681SAndroid Build Coastguard Worker 10723*9880d681SAndroid Build Coastguard Worker'``llvm.bswap.*``' Intrinsics 10724*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10725*9880d681SAndroid Build Coastguard Worker 10726*9880d681SAndroid Build Coastguard WorkerSyntax: 10727*9880d681SAndroid Build Coastguard Worker""""""" 10728*9880d681SAndroid Build Coastguard Worker 10729*9880d681SAndroid Build Coastguard WorkerThis is an overloaded intrinsic function. You can use bswap on any 10730*9880d681SAndroid Build Coastguard Workerinteger type that is an even number of bytes (i.e. BitWidth % 16 == 0). 10731*9880d681SAndroid Build Coastguard Worker 10732*9880d681SAndroid Build Coastguard Worker:: 10733*9880d681SAndroid Build Coastguard Worker 10734*9880d681SAndroid Build Coastguard Worker declare i16 @llvm.bswap.i16(i16 <id>) 10735*9880d681SAndroid Build Coastguard Worker declare i32 @llvm.bswap.i32(i32 <id>) 10736*9880d681SAndroid Build Coastguard Worker declare i64 @llvm.bswap.i64(i64 <id>) 10737*9880d681SAndroid Build Coastguard Worker 10738*9880d681SAndroid Build Coastguard WorkerOverview: 10739*9880d681SAndroid Build Coastguard Worker""""""""" 10740*9880d681SAndroid Build Coastguard Worker 10741*9880d681SAndroid Build Coastguard WorkerThe '``llvm.bswap``' family of intrinsics is used to byte swap integer 10742*9880d681SAndroid Build Coastguard Workervalues with an even number of bytes (positive multiple of 16 bits). 10743*9880d681SAndroid Build Coastguard WorkerThese are useful for performing operations on data that is not in the 10744*9880d681SAndroid Build Coastguard Workertarget's native byte order. 10745*9880d681SAndroid Build Coastguard Worker 10746*9880d681SAndroid Build Coastguard WorkerSemantics: 10747*9880d681SAndroid Build Coastguard Worker"""""""""" 10748*9880d681SAndroid Build Coastguard Worker 10749*9880d681SAndroid Build Coastguard WorkerThe ``llvm.bswap.i16`` intrinsic returns an i16 value that has the high 10750*9880d681SAndroid Build Coastguard Workerand low byte of the input i16 swapped. Similarly, the ``llvm.bswap.i32`` 10751*9880d681SAndroid Build Coastguard Workerintrinsic returns an i32 value that has the four bytes of the input i32 10752*9880d681SAndroid Build Coastguard Workerswapped, so that if the input bytes are numbered 0, 1, 2, 3 then the 10753*9880d681SAndroid Build Coastguard Workerreturned i32 will have its bytes in 3, 2, 1, 0 order. The 10754*9880d681SAndroid Build Coastguard Worker``llvm.bswap.i48``, ``llvm.bswap.i64`` and other intrinsics extend this 10755*9880d681SAndroid Build Coastguard Workerconcept to additional even-byte lengths (6 bytes, 8 bytes and more, 10756*9880d681SAndroid Build Coastguard Workerrespectively). 10757*9880d681SAndroid Build Coastguard Worker 10758*9880d681SAndroid Build Coastguard Worker'``llvm.ctpop.*``' Intrinsic 10759*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10760*9880d681SAndroid Build Coastguard Worker 10761*9880d681SAndroid Build Coastguard WorkerSyntax: 10762*9880d681SAndroid Build Coastguard Worker""""""" 10763*9880d681SAndroid Build Coastguard Worker 10764*9880d681SAndroid Build Coastguard WorkerThis is an overloaded intrinsic. You can use llvm.ctpop on any integer 10765*9880d681SAndroid Build Coastguard Workerbit width, or on any vector with integer elements. Not all targets 10766*9880d681SAndroid Build Coastguard Workersupport all bit widths or vector types, however. 10767*9880d681SAndroid Build Coastguard Worker 10768*9880d681SAndroid Build Coastguard Worker:: 10769*9880d681SAndroid Build Coastguard Worker 10770*9880d681SAndroid Build Coastguard Worker declare i8 @llvm.ctpop.i8(i8 <src>) 10771*9880d681SAndroid Build Coastguard Worker declare i16 @llvm.ctpop.i16(i16 <src>) 10772*9880d681SAndroid Build Coastguard Worker declare i32 @llvm.ctpop.i32(i32 <src>) 10773*9880d681SAndroid Build Coastguard Worker declare i64 @llvm.ctpop.i64(i64 <src>) 10774*9880d681SAndroid Build Coastguard Worker declare i256 @llvm.ctpop.i256(i256 <src>) 10775*9880d681SAndroid Build Coastguard Worker declare <2 x i32> @llvm.ctpop.v2i32(<2 x i32> <src>) 10776*9880d681SAndroid Build Coastguard Worker 10777*9880d681SAndroid Build Coastguard WorkerOverview: 10778*9880d681SAndroid Build Coastguard Worker""""""""" 10779*9880d681SAndroid Build Coastguard Worker 10780*9880d681SAndroid Build Coastguard WorkerThe '``llvm.ctpop``' family of intrinsics counts the number of bits set 10781*9880d681SAndroid Build Coastguard Workerin a value. 10782*9880d681SAndroid Build Coastguard Worker 10783*9880d681SAndroid Build Coastguard WorkerArguments: 10784*9880d681SAndroid Build Coastguard Worker"""""""""" 10785*9880d681SAndroid Build Coastguard Worker 10786*9880d681SAndroid Build Coastguard WorkerThe only argument is the value to be counted. The argument may be of any 10787*9880d681SAndroid Build Coastguard Workerinteger type, or a vector with integer elements. The return type must 10788*9880d681SAndroid Build Coastguard Workermatch the argument type. 10789*9880d681SAndroid Build Coastguard Worker 10790*9880d681SAndroid Build Coastguard WorkerSemantics: 10791*9880d681SAndroid Build Coastguard Worker"""""""""" 10792*9880d681SAndroid Build Coastguard Worker 10793*9880d681SAndroid Build Coastguard WorkerThe '``llvm.ctpop``' intrinsic counts the 1's in a variable, or within 10794*9880d681SAndroid Build Coastguard Workereach element of a vector. 10795*9880d681SAndroid Build Coastguard Worker 10796*9880d681SAndroid Build Coastguard Worker'``llvm.ctlz.*``' Intrinsic 10797*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10798*9880d681SAndroid Build Coastguard Worker 10799*9880d681SAndroid Build Coastguard WorkerSyntax: 10800*9880d681SAndroid Build Coastguard Worker""""""" 10801*9880d681SAndroid Build Coastguard Worker 10802*9880d681SAndroid Build Coastguard WorkerThis is an overloaded intrinsic. You can use ``llvm.ctlz`` on any 10803*9880d681SAndroid Build Coastguard Workerinteger bit width, or any vector whose elements are integers. Not all 10804*9880d681SAndroid Build Coastguard Workertargets support all bit widths or vector types, however. 10805*9880d681SAndroid Build Coastguard Worker 10806*9880d681SAndroid Build Coastguard Worker:: 10807*9880d681SAndroid Build Coastguard Worker 10808*9880d681SAndroid Build Coastguard Worker declare i8 @llvm.ctlz.i8 (i8 <src>, i1 <is_zero_undef>) 10809*9880d681SAndroid Build Coastguard Worker declare i16 @llvm.ctlz.i16 (i16 <src>, i1 <is_zero_undef>) 10810*9880d681SAndroid Build Coastguard Worker declare i32 @llvm.ctlz.i32 (i32 <src>, i1 <is_zero_undef>) 10811*9880d681SAndroid Build Coastguard Worker declare i64 @llvm.ctlz.i64 (i64 <src>, i1 <is_zero_undef>) 10812*9880d681SAndroid Build Coastguard Worker declare i256 @llvm.ctlz.i256(i256 <src>, i1 <is_zero_undef>) 10813*9880d681SAndroid Build Coastguard Worker declare <2 x i32> @llvm.ctlz.v2i32(<2 x i32> <src>, i1 <is_zero_undef>) 10814*9880d681SAndroid Build Coastguard Worker 10815*9880d681SAndroid Build Coastguard WorkerOverview: 10816*9880d681SAndroid Build Coastguard Worker""""""""" 10817*9880d681SAndroid Build Coastguard Worker 10818*9880d681SAndroid Build Coastguard WorkerThe '``llvm.ctlz``' family of intrinsic functions counts the number of 10819*9880d681SAndroid Build Coastguard Workerleading zeros in a variable. 10820*9880d681SAndroid Build Coastguard Worker 10821*9880d681SAndroid Build Coastguard WorkerArguments: 10822*9880d681SAndroid Build Coastguard Worker"""""""""" 10823*9880d681SAndroid Build Coastguard Worker 10824*9880d681SAndroid Build Coastguard WorkerThe first argument is the value to be counted. This argument may be of 10825*9880d681SAndroid Build Coastguard Workerany integer type, or a vector with integer element type. The return 10826*9880d681SAndroid Build Coastguard Workertype must match the first argument type. 10827*9880d681SAndroid Build Coastguard Worker 10828*9880d681SAndroid Build Coastguard WorkerThe second argument must be a constant and is a flag to indicate whether 10829*9880d681SAndroid Build Coastguard Workerthe intrinsic should ensure that a zero as the first argument produces a 10830*9880d681SAndroid Build Coastguard Workerdefined result. Historically some architectures did not provide a 10831*9880d681SAndroid Build Coastguard Workerdefined result for zero values as efficiently, and many algorithms are 10832*9880d681SAndroid Build Coastguard Workernow predicated on avoiding zero-value inputs. 10833*9880d681SAndroid Build Coastguard Worker 10834*9880d681SAndroid Build Coastguard WorkerSemantics: 10835*9880d681SAndroid Build Coastguard Worker"""""""""" 10836*9880d681SAndroid Build Coastguard Worker 10837*9880d681SAndroid Build Coastguard WorkerThe '``llvm.ctlz``' intrinsic counts the leading (most significant) 10838*9880d681SAndroid Build Coastguard Workerzeros in a variable, or within each element of the vector. If 10839*9880d681SAndroid Build Coastguard Worker``src == 0`` then the result is the size in bits of the type of ``src`` 10840*9880d681SAndroid Build Coastguard Workerif ``is_zero_undef == 0`` and ``undef`` otherwise. For example, 10841*9880d681SAndroid Build Coastguard Worker``llvm.ctlz(i32 2) = 30``. 10842*9880d681SAndroid Build Coastguard Worker 10843*9880d681SAndroid Build Coastguard Worker'``llvm.cttz.*``' Intrinsic 10844*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10845*9880d681SAndroid Build Coastguard Worker 10846*9880d681SAndroid Build Coastguard WorkerSyntax: 10847*9880d681SAndroid Build Coastguard Worker""""""" 10848*9880d681SAndroid Build Coastguard Worker 10849*9880d681SAndroid Build Coastguard WorkerThis is an overloaded intrinsic. You can use ``llvm.cttz`` on any 10850*9880d681SAndroid Build Coastguard Workerinteger bit width, or any vector of integer elements. Not all targets 10851*9880d681SAndroid Build Coastguard Workersupport all bit widths or vector types, however. 10852*9880d681SAndroid Build Coastguard Worker 10853*9880d681SAndroid Build Coastguard Worker:: 10854*9880d681SAndroid Build Coastguard Worker 10855*9880d681SAndroid Build Coastguard Worker declare i8 @llvm.cttz.i8 (i8 <src>, i1 <is_zero_undef>) 10856*9880d681SAndroid Build Coastguard Worker declare i16 @llvm.cttz.i16 (i16 <src>, i1 <is_zero_undef>) 10857*9880d681SAndroid Build Coastguard Worker declare i32 @llvm.cttz.i32 (i32 <src>, i1 <is_zero_undef>) 10858*9880d681SAndroid Build Coastguard Worker declare i64 @llvm.cttz.i64 (i64 <src>, i1 <is_zero_undef>) 10859*9880d681SAndroid Build Coastguard Worker declare i256 @llvm.cttz.i256(i256 <src>, i1 <is_zero_undef>) 10860*9880d681SAndroid Build Coastguard Worker declare <2 x i32> @llvm.cttz.v2i32(<2 x i32> <src>, i1 <is_zero_undef>) 10861*9880d681SAndroid Build Coastguard Worker 10862*9880d681SAndroid Build Coastguard WorkerOverview: 10863*9880d681SAndroid Build Coastguard Worker""""""""" 10864*9880d681SAndroid Build Coastguard Worker 10865*9880d681SAndroid Build Coastguard WorkerThe '``llvm.cttz``' family of intrinsic functions counts the number of 10866*9880d681SAndroid Build Coastguard Workertrailing zeros. 10867*9880d681SAndroid Build Coastguard Worker 10868*9880d681SAndroid Build Coastguard WorkerArguments: 10869*9880d681SAndroid Build Coastguard Worker"""""""""" 10870*9880d681SAndroid Build Coastguard Worker 10871*9880d681SAndroid Build Coastguard WorkerThe first argument is the value to be counted. This argument may be of 10872*9880d681SAndroid Build Coastguard Workerany integer type, or a vector with integer element type. The return 10873*9880d681SAndroid Build Coastguard Workertype must match the first argument type. 10874*9880d681SAndroid Build Coastguard Worker 10875*9880d681SAndroid Build Coastguard WorkerThe second argument must be a constant and is a flag to indicate whether 10876*9880d681SAndroid Build Coastguard Workerthe intrinsic should ensure that a zero as the first argument produces a 10877*9880d681SAndroid Build Coastguard Workerdefined result. Historically some architectures did not provide a 10878*9880d681SAndroid Build Coastguard Workerdefined result for zero values as efficiently, and many algorithms are 10879*9880d681SAndroid Build Coastguard Workernow predicated on avoiding zero-value inputs. 10880*9880d681SAndroid Build Coastguard Worker 10881*9880d681SAndroid Build Coastguard WorkerSemantics: 10882*9880d681SAndroid Build Coastguard Worker"""""""""" 10883*9880d681SAndroid Build Coastguard Worker 10884*9880d681SAndroid Build Coastguard WorkerThe '``llvm.cttz``' intrinsic counts the trailing (least significant) 10885*9880d681SAndroid Build Coastguard Workerzeros in a variable, or within each element of a vector. If ``src == 0`` 10886*9880d681SAndroid Build Coastguard Workerthen the result is the size in bits of the type of ``src`` if 10887*9880d681SAndroid Build Coastguard Worker``is_zero_undef == 0`` and ``undef`` otherwise. For example, 10888*9880d681SAndroid Build Coastguard Worker``llvm.cttz(2) = 1``. 10889*9880d681SAndroid Build Coastguard Worker 10890*9880d681SAndroid Build Coastguard Worker.. _int_overflow: 10891*9880d681SAndroid Build Coastguard Worker 10892*9880d681SAndroid Build Coastguard WorkerArithmetic with Overflow Intrinsics 10893*9880d681SAndroid Build Coastguard Worker----------------------------------- 10894*9880d681SAndroid Build Coastguard Worker 10895*9880d681SAndroid Build Coastguard WorkerLLVM provides intrinsics for fast arithmetic overflow checking. 10896*9880d681SAndroid Build Coastguard Worker 10897*9880d681SAndroid Build Coastguard WorkerEach of these intrinsics returns a two-element struct. The first 10898*9880d681SAndroid Build Coastguard Workerelement of this struct contains the result of the corresponding 10899*9880d681SAndroid Build Coastguard Workerarithmetic operation modulo 2\ :sup:`n`\ , where n is the bit width of 10900*9880d681SAndroid Build Coastguard Workerthe result. Therefore, for example, the first element of the struct 10901*9880d681SAndroid Build Coastguard Workerreturned by ``llvm.sadd.with.overflow.i32`` is always the same as the 10902*9880d681SAndroid Build Coastguard Workerresult of a 32-bit ``add`` instruction with the same operands, where 10903*9880d681SAndroid Build Coastguard Workerthe ``add`` is *not* modified by an ``nsw`` or ``nuw`` flag. 10904*9880d681SAndroid Build Coastguard Worker 10905*9880d681SAndroid Build Coastguard WorkerThe second element of the result is an ``i1`` that is 1 if the 10906*9880d681SAndroid Build Coastguard Workerarithmetic operation overflowed and 0 otherwise. An operation 10907*9880d681SAndroid Build Coastguard Workeroverflows if, for any values of its operands ``A`` and ``B`` and for 10908*9880d681SAndroid Build Coastguard Workerany ``N`` larger than the operands' width, ``ext(A op B) to iN`` is 10909*9880d681SAndroid Build Coastguard Workernot equal to ``(ext(A) to iN) op (ext(B) to iN)`` where ``ext`` is 10910*9880d681SAndroid Build Coastguard Worker``sext`` for signed overflow and ``zext`` for unsigned overflow, and 10911*9880d681SAndroid Build Coastguard Worker``op`` is the underlying arithmetic operation. 10912*9880d681SAndroid Build Coastguard Worker 10913*9880d681SAndroid Build Coastguard WorkerThe behavior of these intrinsics is well-defined for all argument 10914*9880d681SAndroid Build Coastguard Workervalues. 10915*9880d681SAndroid Build Coastguard Worker 10916*9880d681SAndroid Build Coastguard Worker'``llvm.sadd.with.overflow.*``' Intrinsics 10917*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10918*9880d681SAndroid Build Coastguard Worker 10919*9880d681SAndroid Build Coastguard WorkerSyntax: 10920*9880d681SAndroid Build Coastguard Worker""""""" 10921*9880d681SAndroid Build Coastguard Worker 10922*9880d681SAndroid Build Coastguard WorkerThis is an overloaded intrinsic. You can use ``llvm.sadd.with.overflow`` 10923*9880d681SAndroid Build Coastguard Workeron any integer bit width. 10924*9880d681SAndroid Build Coastguard Worker 10925*9880d681SAndroid Build Coastguard Worker:: 10926*9880d681SAndroid Build Coastguard Worker 10927*9880d681SAndroid Build Coastguard Worker declare {i16, i1} @llvm.sadd.with.overflow.i16(i16 %a, i16 %b) 10928*9880d681SAndroid Build Coastguard Worker declare {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b) 10929*9880d681SAndroid Build Coastguard Worker declare {i64, i1} @llvm.sadd.with.overflow.i64(i64 %a, i64 %b) 10930*9880d681SAndroid Build Coastguard Worker 10931*9880d681SAndroid Build Coastguard WorkerOverview: 10932*9880d681SAndroid Build Coastguard Worker""""""""" 10933*9880d681SAndroid Build Coastguard Worker 10934*9880d681SAndroid Build Coastguard WorkerThe '``llvm.sadd.with.overflow``' family of intrinsic functions perform 10935*9880d681SAndroid Build Coastguard Workera signed addition of the two arguments, and indicate whether an overflow 10936*9880d681SAndroid Build Coastguard Workeroccurred during the signed summation. 10937*9880d681SAndroid Build Coastguard Worker 10938*9880d681SAndroid Build Coastguard WorkerArguments: 10939*9880d681SAndroid Build Coastguard Worker"""""""""" 10940*9880d681SAndroid Build Coastguard Worker 10941*9880d681SAndroid Build Coastguard WorkerThe arguments (%a and %b) and the first element of the result structure 10942*9880d681SAndroid Build Coastguard Workermay be of integer types of any bit width, but they must have the same 10943*9880d681SAndroid Build Coastguard Workerbit width. The second element of the result structure must be of type 10944*9880d681SAndroid Build Coastguard Worker``i1``. ``%a`` and ``%b`` are the two values that will undergo signed 10945*9880d681SAndroid Build Coastguard Workeraddition. 10946*9880d681SAndroid Build Coastguard Worker 10947*9880d681SAndroid Build Coastguard WorkerSemantics: 10948*9880d681SAndroid Build Coastguard Worker"""""""""" 10949*9880d681SAndroid Build Coastguard Worker 10950*9880d681SAndroid Build Coastguard WorkerThe '``llvm.sadd.with.overflow``' family of intrinsic functions perform 10951*9880d681SAndroid Build Coastguard Workera signed addition of the two variables. They return a structure --- the 10952*9880d681SAndroid Build Coastguard Workerfirst element of which is the signed summation, and the second element 10953*9880d681SAndroid Build Coastguard Workerof which is a bit specifying if the signed summation resulted in an 10954*9880d681SAndroid Build Coastguard Workeroverflow. 10955*9880d681SAndroid Build Coastguard Worker 10956*9880d681SAndroid Build Coastguard WorkerExamples: 10957*9880d681SAndroid Build Coastguard Worker""""""""" 10958*9880d681SAndroid Build Coastguard Worker 10959*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 10960*9880d681SAndroid Build Coastguard Worker 10961*9880d681SAndroid Build Coastguard Worker %res = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b) 10962*9880d681SAndroid Build Coastguard Worker %sum = extractvalue {i32, i1} %res, 0 10963*9880d681SAndroid Build Coastguard Worker %obit = extractvalue {i32, i1} %res, 1 10964*9880d681SAndroid Build Coastguard Worker br i1 %obit, label %overflow, label %normal 10965*9880d681SAndroid Build Coastguard Worker 10966*9880d681SAndroid Build Coastguard Worker'``llvm.uadd.with.overflow.*``' Intrinsics 10967*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10968*9880d681SAndroid Build Coastguard Worker 10969*9880d681SAndroid Build Coastguard WorkerSyntax: 10970*9880d681SAndroid Build Coastguard Worker""""""" 10971*9880d681SAndroid Build Coastguard Worker 10972*9880d681SAndroid Build Coastguard WorkerThis is an overloaded intrinsic. You can use ``llvm.uadd.with.overflow`` 10973*9880d681SAndroid Build Coastguard Workeron any integer bit width. 10974*9880d681SAndroid Build Coastguard Worker 10975*9880d681SAndroid Build Coastguard Worker:: 10976*9880d681SAndroid Build Coastguard Worker 10977*9880d681SAndroid Build Coastguard Worker declare {i16, i1} @llvm.uadd.with.overflow.i16(i16 %a, i16 %b) 10978*9880d681SAndroid Build Coastguard Worker declare {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b) 10979*9880d681SAndroid Build Coastguard Worker declare {i64, i1} @llvm.uadd.with.overflow.i64(i64 %a, i64 %b) 10980*9880d681SAndroid Build Coastguard Worker 10981*9880d681SAndroid Build Coastguard WorkerOverview: 10982*9880d681SAndroid Build Coastguard Worker""""""""" 10983*9880d681SAndroid Build Coastguard Worker 10984*9880d681SAndroid Build Coastguard WorkerThe '``llvm.uadd.with.overflow``' family of intrinsic functions perform 10985*9880d681SAndroid Build Coastguard Workeran unsigned addition of the two arguments, and indicate whether a carry 10986*9880d681SAndroid Build Coastguard Workeroccurred during the unsigned summation. 10987*9880d681SAndroid Build Coastguard Worker 10988*9880d681SAndroid Build Coastguard WorkerArguments: 10989*9880d681SAndroid Build Coastguard Worker"""""""""" 10990*9880d681SAndroid Build Coastguard Worker 10991*9880d681SAndroid Build Coastguard WorkerThe arguments (%a and %b) and the first element of the result structure 10992*9880d681SAndroid Build Coastguard Workermay be of integer types of any bit width, but they must have the same 10993*9880d681SAndroid Build Coastguard Workerbit width. The second element of the result structure must be of type 10994*9880d681SAndroid Build Coastguard Worker``i1``. ``%a`` and ``%b`` are the two values that will undergo unsigned 10995*9880d681SAndroid Build Coastguard Workeraddition. 10996*9880d681SAndroid Build Coastguard Worker 10997*9880d681SAndroid Build Coastguard WorkerSemantics: 10998*9880d681SAndroid Build Coastguard Worker"""""""""" 10999*9880d681SAndroid Build Coastguard Worker 11000*9880d681SAndroid Build Coastguard WorkerThe '``llvm.uadd.with.overflow``' family of intrinsic functions perform 11001*9880d681SAndroid Build Coastguard Workeran unsigned addition of the two arguments. They return a structure --- the 11002*9880d681SAndroid Build Coastguard Workerfirst element of which is the sum, and the second element of which is a 11003*9880d681SAndroid Build Coastguard Workerbit specifying if the unsigned summation resulted in a carry. 11004*9880d681SAndroid Build Coastguard Worker 11005*9880d681SAndroid Build Coastguard WorkerExamples: 11006*9880d681SAndroid Build Coastguard Worker""""""""" 11007*9880d681SAndroid Build Coastguard Worker 11008*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 11009*9880d681SAndroid Build Coastguard Worker 11010*9880d681SAndroid Build Coastguard Worker %res = call {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b) 11011*9880d681SAndroid Build Coastguard Worker %sum = extractvalue {i32, i1} %res, 0 11012*9880d681SAndroid Build Coastguard Worker %obit = extractvalue {i32, i1} %res, 1 11013*9880d681SAndroid Build Coastguard Worker br i1 %obit, label %carry, label %normal 11014*9880d681SAndroid Build Coastguard Worker 11015*9880d681SAndroid Build Coastguard Worker'``llvm.ssub.with.overflow.*``' Intrinsics 11016*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11017*9880d681SAndroid Build Coastguard Worker 11018*9880d681SAndroid Build Coastguard WorkerSyntax: 11019*9880d681SAndroid Build Coastguard Worker""""""" 11020*9880d681SAndroid Build Coastguard Worker 11021*9880d681SAndroid Build Coastguard WorkerThis is an overloaded intrinsic. You can use ``llvm.ssub.with.overflow`` 11022*9880d681SAndroid Build Coastguard Workeron any integer bit width. 11023*9880d681SAndroid Build Coastguard Worker 11024*9880d681SAndroid Build Coastguard Worker:: 11025*9880d681SAndroid Build Coastguard Worker 11026*9880d681SAndroid Build Coastguard Worker declare {i16, i1} @llvm.ssub.with.overflow.i16(i16 %a, i16 %b) 11027*9880d681SAndroid Build Coastguard Worker declare {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a, i32 %b) 11028*9880d681SAndroid Build Coastguard Worker declare {i64, i1} @llvm.ssub.with.overflow.i64(i64 %a, i64 %b) 11029*9880d681SAndroid Build Coastguard Worker 11030*9880d681SAndroid Build Coastguard WorkerOverview: 11031*9880d681SAndroid Build Coastguard Worker""""""""" 11032*9880d681SAndroid Build Coastguard Worker 11033*9880d681SAndroid Build Coastguard WorkerThe '``llvm.ssub.with.overflow``' family of intrinsic functions perform 11034*9880d681SAndroid Build Coastguard Workera signed subtraction of the two arguments, and indicate whether an 11035*9880d681SAndroid Build Coastguard Workeroverflow occurred during the signed subtraction. 11036*9880d681SAndroid Build Coastguard Worker 11037*9880d681SAndroid Build Coastguard WorkerArguments: 11038*9880d681SAndroid Build Coastguard Worker"""""""""" 11039*9880d681SAndroid Build Coastguard Worker 11040*9880d681SAndroid Build Coastguard WorkerThe arguments (%a and %b) and the first element of the result structure 11041*9880d681SAndroid Build Coastguard Workermay be of integer types of any bit width, but they must have the same 11042*9880d681SAndroid Build Coastguard Workerbit width. The second element of the result structure must be of type 11043*9880d681SAndroid Build Coastguard Worker``i1``. ``%a`` and ``%b`` are the two values that will undergo signed 11044*9880d681SAndroid Build Coastguard Workersubtraction. 11045*9880d681SAndroid Build Coastguard Worker 11046*9880d681SAndroid Build Coastguard WorkerSemantics: 11047*9880d681SAndroid Build Coastguard Worker"""""""""" 11048*9880d681SAndroid Build Coastguard Worker 11049*9880d681SAndroid Build Coastguard WorkerThe '``llvm.ssub.with.overflow``' family of intrinsic functions perform 11050*9880d681SAndroid Build Coastguard Workera signed subtraction of the two arguments. They return a structure --- the 11051*9880d681SAndroid Build Coastguard Workerfirst element of which is the subtraction, and the second element of 11052*9880d681SAndroid Build Coastguard Workerwhich is a bit specifying if the signed subtraction resulted in an 11053*9880d681SAndroid Build Coastguard Workeroverflow. 11054*9880d681SAndroid Build Coastguard Worker 11055*9880d681SAndroid Build Coastguard WorkerExamples: 11056*9880d681SAndroid Build Coastguard Worker""""""""" 11057*9880d681SAndroid Build Coastguard Worker 11058*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 11059*9880d681SAndroid Build Coastguard Worker 11060*9880d681SAndroid Build Coastguard Worker %res = call {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a, i32 %b) 11061*9880d681SAndroid Build Coastguard Worker %sum = extractvalue {i32, i1} %res, 0 11062*9880d681SAndroid Build Coastguard Worker %obit = extractvalue {i32, i1} %res, 1 11063*9880d681SAndroid Build Coastguard Worker br i1 %obit, label %overflow, label %normal 11064*9880d681SAndroid Build Coastguard Worker 11065*9880d681SAndroid Build Coastguard Worker'``llvm.usub.with.overflow.*``' Intrinsics 11066*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11067*9880d681SAndroid Build Coastguard Worker 11068*9880d681SAndroid Build Coastguard WorkerSyntax: 11069*9880d681SAndroid Build Coastguard Worker""""""" 11070*9880d681SAndroid Build Coastguard Worker 11071*9880d681SAndroid Build Coastguard WorkerThis is an overloaded intrinsic. You can use ``llvm.usub.with.overflow`` 11072*9880d681SAndroid Build Coastguard Workeron any integer bit width. 11073*9880d681SAndroid Build Coastguard Worker 11074*9880d681SAndroid Build Coastguard Worker:: 11075*9880d681SAndroid Build Coastguard Worker 11076*9880d681SAndroid Build Coastguard Worker declare {i16, i1} @llvm.usub.with.overflow.i16(i16 %a, i16 %b) 11077*9880d681SAndroid Build Coastguard Worker declare {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b) 11078*9880d681SAndroid Build Coastguard Worker declare {i64, i1} @llvm.usub.with.overflow.i64(i64 %a, i64 %b) 11079*9880d681SAndroid Build Coastguard Worker 11080*9880d681SAndroid Build Coastguard WorkerOverview: 11081*9880d681SAndroid Build Coastguard Worker""""""""" 11082*9880d681SAndroid Build Coastguard Worker 11083*9880d681SAndroid Build Coastguard WorkerThe '``llvm.usub.with.overflow``' family of intrinsic functions perform 11084*9880d681SAndroid Build Coastguard Workeran unsigned subtraction of the two arguments, and indicate whether an 11085*9880d681SAndroid Build Coastguard Workeroverflow occurred during the unsigned subtraction. 11086*9880d681SAndroid Build Coastguard Worker 11087*9880d681SAndroid Build Coastguard WorkerArguments: 11088*9880d681SAndroid Build Coastguard Worker"""""""""" 11089*9880d681SAndroid Build Coastguard Worker 11090*9880d681SAndroid Build Coastguard WorkerThe arguments (%a and %b) and the first element of the result structure 11091*9880d681SAndroid Build Coastguard Workermay be of integer types of any bit width, but they must have the same 11092*9880d681SAndroid Build Coastguard Workerbit width. The second element of the result structure must be of type 11093*9880d681SAndroid Build Coastguard Worker``i1``. ``%a`` and ``%b`` are the two values that will undergo unsigned 11094*9880d681SAndroid Build Coastguard Workersubtraction. 11095*9880d681SAndroid Build Coastguard Worker 11096*9880d681SAndroid Build Coastguard WorkerSemantics: 11097*9880d681SAndroid Build Coastguard Worker"""""""""" 11098*9880d681SAndroid Build Coastguard Worker 11099*9880d681SAndroid Build Coastguard WorkerThe '``llvm.usub.with.overflow``' family of intrinsic functions perform 11100*9880d681SAndroid Build Coastguard Workeran unsigned subtraction of the two arguments. They return a structure --- 11101*9880d681SAndroid Build Coastguard Workerthe first element of which is the subtraction, and the second element of 11102*9880d681SAndroid Build Coastguard Workerwhich is a bit specifying if the unsigned subtraction resulted in an 11103*9880d681SAndroid Build Coastguard Workeroverflow. 11104*9880d681SAndroid Build Coastguard Worker 11105*9880d681SAndroid Build Coastguard WorkerExamples: 11106*9880d681SAndroid Build Coastguard Worker""""""""" 11107*9880d681SAndroid Build Coastguard Worker 11108*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 11109*9880d681SAndroid Build Coastguard Worker 11110*9880d681SAndroid Build Coastguard Worker %res = call {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b) 11111*9880d681SAndroid Build Coastguard Worker %sum = extractvalue {i32, i1} %res, 0 11112*9880d681SAndroid Build Coastguard Worker %obit = extractvalue {i32, i1} %res, 1 11113*9880d681SAndroid Build Coastguard Worker br i1 %obit, label %overflow, label %normal 11114*9880d681SAndroid Build Coastguard Worker 11115*9880d681SAndroid Build Coastguard Worker'``llvm.smul.with.overflow.*``' Intrinsics 11116*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11117*9880d681SAndroid Build Coastguard Worker 11118*9880d681SAndroid Build Coastguard WorkerSyntax: 11119*9880d681SAndroid Build Coastguard Worker""""""" 11120*9880d681SAndroid Build Coastguard Worker 11121*9880d681SAndroid Build Coastguard WorkerThis is an overloaded intrinsic. You can use ``llvm.smul.with.overflow`` 11122*9880d681SAndroid Build Coastguard Workeron any integer bit width. 11123*9880d681SAndroid Build Coastguard Worker 11124*9880d681SAndroid Build Coastguard Worker:: 11125*9880d681SAndroid Build Coastguard Worker 11126*9880d681SAndroid Build Coastguard Worker declare {i16, i1} @llvm.smul.with.overflow.i16(i16 %a, i16 %b) 11127*9880d681SAndroid Build Coastguard Worker declare {i32, i1} @llvm.smul.with.overflow.i32(i32 %a, i32 %b) 11128*9880d681SAndroid Build Coastguard Worker declare {i64, i1} @llvm.smul.with.overflow.i64(i64 %a, i64 %b) 11129*9880d681SAndroid Build Coastguard Worker 11130*9880d681SAndroid Build Coastguard WorkerOverview: 11131*9880d681SAndroid Build Coastguard Worker""""""""" 11132*9880d681SAndroid Build Coastguard Worker 11133*9880d681SAndroid Build Coastguard WorkerThe '``llvm.smul.with.overflow``' family of intrinsic functions perform 11134*9880d681SAndroid Build Coastguard Workera signed multiplication of the two arguments, and indicate whether an 11135*9880d681SAndroid Build Coastguard Workeroverflow occurred during the signed multiplication. 11136*9880d681SAndroid Build Coastguard Worker 11137*9880d681SAndroid Build Coastguard WorkerArguments: 11138*9880d681SAndroid Build Coastguard Worker"""""""""" 11139*9880d681SAndroid Build Coastguard Worker 11140*9880d681SAndroid Build Coastguard WorkerThe arguments (%a and %b) and the first element of the result structure 11141*9880d681SAndroid Build Coastguard Workermay be of integer types of any bit width, but they must have the same 11142*9880d681SAndroid Build Coastguard Workerbit width. The second element of the result structure must be of type 11143*9880d681SAndroid Build Coastguard Worker``i1``. ``%a`` and ``%b`` are the two values that will undergo signed 11144*9880d681SAndroid Build Coastguard Workermultiplication. 11145*9880d681SAndroid Build Coastguard Worker 11146*9880d681SAndroid Build Coastguard WorkerSemantics: 11147*9880d681SAndroid Build Coastguard Worker"""""""""" 11148*9880d681SAndroid Build Coastguard Worker 11149*9880d681SAndroid Build Coastguard WorkerThe '``llvm.smul.with.overflow``' family of intrinsic functions perform 11150*9880d681SAndroid Build Coastguard Workera signed multiplication of the two arguments. They return a structure --- 11151*9880d681SAndroid Build Coastguard Workerthe first element of which is the multiplication, and the second element 11152*9880d681SAndroid Build Coastguard Workerof which is a bit specifying if the signed multiplication resulted in an 11153*9880d681SAndroid Build Coastguard Workeroverflow. 11154*9880d681SAndroid Build Coastguard Worker 11155*9880d681SAndroid Build Coastguard WorkerExamples: 11156*9880d681SAndroid Build Coastguard Worker""""""""" 11157*9880d681SAndroid Build Coastguard Worker 11158*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 11159*9880d681SAndroid Build Coastguard Worker 11160*9880d681SAndroid Build Coastguard Worker %res = call {i32, i1} @llvm.smul.with.overflow.i32(i32 %a, i32 %b) 11161*9880d681SAndroid Build Coastguard Worker %sum = extractvalue {i32, i1} %res, 0 11162*9880d681SAndroid Build Coastguard Worker %obit = extractvalue {i32, i1} %res, 1 11163*9880d681SAndroid Build Coastguard Worker br i1 %obit, label %overflow, label %normal 11164*9880d681SAndroid Build Coastguard Worker 11165*9880d681SAndroid Build Coastguard Worker'``llvm.umul.with.overflow.*``' Intrinsics 11166*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11167*9880d681SAndroid Build Coastguard Worker 11168*9880d681SAndroid Build Coastguard WorkerSyntax: 11169*9880d681SAndroid Build Coastguard Worker""""""" 11170*9880d681SAndroid Build Coastguard Worker 11171*9880d681SAndroid Build Coastguard WorkerThis is an overloaded intrinsic. You can use ``llvm.umul.with.overflow`` 11172*9880d681SAndroid Build Coastguard Workeron any integer bit width. 11173*9880d681SAndroid Build Coastguard Worker 11174*9880d681SAndroid Build Coastguard Worker:: 11175*9880d681SAndroid Build Coastguard Worker 11176*9880d681SAndroid Build Coastguard Worker declare {i16, i1} @llvm.umul.with.overflow.i16(i16 %a, i16 %b) 11177*9880d681SAndroid Build Coastguard Worker declare {i32, i1} @llvm.umul.with.overflow.i32(i32 %a, i32 %b) 11178*9880d681SAndroid Build Coastguard Worker declare {i64, i1} @llvm.umul.with.overflow.i64(i64 %a, i64 %b) 11179*9880d681SAndroid Build Coastguard Worker 11180*9880d681SAndroid Build Coastguard WorkerOverview: 11181*9880d681SAndroid Build Coastguard Worker""""""""" 11182*9880d681SAndroid Build Coastguard Worker 11183*9880d681SAndroid Build Coastguard WorkerThe '``llvm.umul.with.overflow``' family of intrinsic functions perform 11184*9880d681SAndroid Build Coastguard Workera unsigned multiplication of the two arguments, and indicate whether an 11185*9880d681SAndroid Build Coastguard Workeroverflow occurred during the unsigned multiplication. 11186*9880d681SAndroid Build Coastguard Worker 11187*9880d681SAndroid Build Coastguard WorkerArguments: 11188*9880d681SAndroid Build Coastguard Worker"""""""""" 11189*9880d681SAndroid Build Coastguard Worker 11190*9880d681SAndroid Build Coastguard WorkerThe arguments (%a and %b) and the first element of the result structure 11191*9880d681SAndroid Build Coastguard Workermay be of integer types of any bit width, but they must have the same 11192*9880d681SAndroid Build Coastguard Workerbit width. The second element of the result structure must be of type 11193*9880d681SAndroid Build Coastguard Worker``i1``. ``%a`` and ``%b`` are the two values that will undergo unsigned 11194*9880d681SAndroid Build Coastguard Workermultiplication. 11195*9880d681SAndroid Build Coastguard Worker 11196*9880d681SAndroid Build Coastguard WorkerSemantics: 11197*9880d681SAndroid Build Coastguard Worker"""""""""" 11198*9880d681SAndroid Build Coastguard Worker 11199*9880d681SAndroid Build Coastguard WorkerThe '``llvm.umul.with.overflow``' family of intrinsic functions perform 11200*9880d681SAndroid Build Coastguard Workeran unsigned multiplication of the two arguments. They return a structure --- 11201*9880d681SAndroid Build Coastguard Workerthe first element of which is the multiplication, and the second 11202*9880d681SAndroid Build Coastguard Workerelement of which is a bit specifying if the unsigned multiplication 11203*9880d681SAndroid Build Coastguard Workerresulted in an overflow. 11204*9880d681SAndroid Build Coastguard Worker 11205*9880d681SAndroid Build Coastguard WorkerExamples: 11206*9880d681SAndroid Build Coastguard Worker""""""""" 11207*9880d681SAndroid Build Coastguard Worker 11208*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 11209*9880d681SAndroid Build Coastguard Worker 11210*9880d681SAndroid Build Coastguard Worker %res = call {i32, i1} @llvm.umul.with.overflow.i32(i32 %a, i32 %b) 11211*9880d681SAndroid Build Coastguard Worker %sum = extractvalue {i32, i1} %res, 0 11212*9880d681SAndroid Build Coastguard Worker %obit = extractvalue {i32, i1} %res, 1 11213*9880d681SAndroid Build Coastguard Worker br i1 %obit, label %overflow, label %normal 11214*9880d681SAndroid Build Coastguard Worker 11215*9880d681SAndroid Build Coastguard WorkerSpecialised Arithmetic Intrinsics 11216*9880d681SAndroid Build Coastguard Worker--------------------------------- 11217*9880d681SAndroid Build Coastguard Worker 11218*9880d681SAndroid Build Coastguard Worker'``llvm.canonicalize.*``' Intrinsic 11219*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11220*9880d681SAndroid Build Coastguard Worker 11221*9880d681SAndroid Build Coastguard WorkerSyntax: 11222*9880d681SAndroid Build Coastguard Worker""""""" 11223*9880d681SAndroid Build Coastguard Worker 11224*9880d681SAndroid Build Coastguard Worker:: 11225*9880d681SAndroid Build Coastguard Worker 11226*9880d681SAndroid Build Coastguard Worker declare float @llvm.canonicalize.f32(float %a) 11227*9880d681SAndroid Build Coastguard Worker declare double @llvm.canonicalize.f64(double %b) 11228*9880d681SAndroid Build Coastguard Worker 11229*9880d681SAndroid Build Coastguard WorkerOverview: 11230*9880d681SAndroid Build Coastguard Worker""""""""" 11231*9880d681SAndroid Build Coastguard Worker 11232*9880d681SAndroid Build Coastguard WorkerThe '``llvm.canonicalize.*``' intrinsic returns the platform specific canonical 11233*9880d681SAndroid Build Coastguard Workerencoding of a floating point number. This canonicalization is useful for 11234*9880d681SAndroid Build Coastguard Workerimplementing certain numeric primitives such as frexp. The canonical encoding is 11235*9880d681SAndroid Build Coastguard Workerdefined by IEEE-754-2008 to be: 11236*9880d681SAndroid Build Coastguard Worker 11237*9880d681SAndroid Build Coastguard Worker:: 11238*9880d681SAndroid Build Coastguard Worker 11239*9880d681SAndroid Build Coastguard Worker 2.1.8 canonical encoding: The preferred encoding of a floating-point 11240*9880d681SAndroid Build Coastguard Worker representation in a format. Applied to declets, significands of finite 11241*9880d681SAndroid Build Coastguard Worker numbers, infinities, and NaNs, especially in decimal formats. 11242*9880d681SAndroid Build Coastguard Worker 11243*9880d681SAndroid Build Coastguard WorkerThis operation can also be considered equivalent to the IEEE-754-2008 11244*9880d681SAndroid Build Coastguard Workerconversion of a floating-point value to the same format. NaNs are handled 11245*9880d681SAndroid Build Coastguard Workeraccording to section 6.2. 11246*9880d681SAndroid Build Coastguard Worker 11247*9880d681SAndroid Build Coastguard WorkerExamples of non-canonical encodings: 11248*9880d681SAndroid Build Coastguard Worker 11249*9880d681SAndroid Build Coastguard Worker- x87 pseudo denormals, pseudo NaNs, pseudo Infinity, Unnormals. These are 11250*9880d681SAndroid Build Coastguard Worker converted to a canonical representation per hardware-specific protocol. 11251*9880d681SAndroid Build Coastguard Worker- Many normal decimal floating point numbers have non-canonical alternative 11252*9880d681SAndroid Build Coastguard Worker encodings. 11253*9880d681SAndroid Build Coastguard Worker- Some machines, like GPUs or ARMv7 NEON, do not support subnormal values. 11254*9880d681SAndroid Build Coastguard Worker These are treated as non-canonical encodings of zero and will be flushed to 11255*9880d681SAndroid Build Coastguard Worker a zero of the same sign by this operation. 11256*9880d681SAndroid Build Coastguard Worker 11257*9880d681SAndroid Build Coastguard WorkerNote that per IEEE-754-2008 6.2, systems that support signaling NaNs with 11258*9880d681SAndroid Build Coastguard Workerdefault exception handling must signal an invalid exception, and produce a 11259*9880d681SAndroid Build Coastguard Workerquiet NaN result. 11260*9880d681SAndroid Build Coastguard Worker 11261*9880d681SAndroid Build Coastguard WorkerThis function should always be implementable as multiplication by 1.0, provided 11262*9880d681SAndroid Build Coastguard Workerthat the compiler does not constant fold the operation. Likewise, division by 11263*9880d681SAndroid Build Coastguard Worker1.0 and ``llvm.minnum(x, x)`` are possible implementations. Addition with 11264*9880d681SAndroid Build Coastguard Worker-0.0 is also sufficient provided that the rounding mode is not -Infinity. 11265*9880d681SAndroid Build Coastguard Worker 11266*9880d681SAndroid Build Coastguard Worker``@llvm.canonicalize`` must preserve the equality relation. That is: 11267*9880d681SAndroid Build Coastguard Worker 11268*9880d681SAndroid Build Coastguard Worker- ``(@llvm.canonicalize(x) == x)`` is equivalent to ``(x == x)`` 11269*9880d681SAndroid Build Coastguard Worker- ``(@llvm.canonicalize(x) == @llvm.canonicalize(y))`` is equivalent to 11270*9880d681SAndroid Build Coastguard Worker to ``(x == y)`` 11271*9880d681SAndroid Build Coastguard Worker 11272*9880d681SAndroid Build Coastguard WorkerAdditionally, the sign of zero must be conserved: 11273*9880d681SAndroid Build Coastguard Worker``@llvm.canonicalize(-0.0) = -0.0`` and ``@llvm.canonicalize(+0.0) = +0.0`` 11274*9880d681SAndroid Build Coastguard Worker 11275*9880d681SAndroid Build Coastguard WorkerThe payload bits of a NaN must be conserved, with two exceptions. 11276*9880d681SAndroid Build Coastguard WorkerFirst, environments which use only a single canonical representation of NaN 11277*9880d681SAndroid Build Coastguard Workermust perform said canonicalization. Second, SNaNs must be quieted per the 11278*9880d681SAndroid Build Coastguard Workerusual methods. 11279*9880d681SAndroid Build Coastguard Worker 11280*9880d681SAndroid Build Coastguard WorkerThe canonicalization operation may be optimized away if: 11281*9880d681SAndroid Build Coastguard Worker 11282*9880d681SAndroid Build Coastguard Worker- The input is known to be canonical. For example, it was produced by a 11283*9880d681SAndroid Build Coastguard Worker floating-point operation that is required by the standard to be canonical. 11284*9880d681SAndroid Build Coastguard Worker- The result is consumed only by (or fused with) other floating-point 11285*9880d681SAndroid Build Coastguard Worker operations. That is, the bits of the floating point value are not examined. 11286*9880d681SAndroid Build Coastguard Worker 11287*9880d681SAndroid Build Coastguard Worker'``llvm.fmuladd.*``' Intrinsic 11288*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11289*9880d681SAndroid Build Coastguard Worker 11290*9880d681SAndroid Build Coastguard WorkerSyntax: 11291*9880d681SAndroid Build Coastguard Worker""""""" 11292*9880d681SAndroid Build Coastguard Worker 11293*9880d681SAndroid Build Coastguard Worker:: 11294*9880d681SAndroid Build Coastguard Worker 11295*9880d681SAndroid Build Coastguard Worker declare float @llvm.fmuladd.f32(float %a, float %b, float %c) 11296*9880d681SAndroid Build Coastguard Worker declare double @llvm.fmuladd.f64(double %a, double %b, double %c) 11297*9880d681SAndroid Build Coastguard Worker 11298*9880d681SAndroid Build Coastguard WorkerOverview: 11299*9880d681SAndroid Build Coastguard Worker""""""""" 11300*9880d681SAndroid Build Coastguard Worker 11301*9880d681SAndroid Build Coastguard WorkerThe '``llvm.fmuladd.*``' intrinsic functions represent multiply-add 11302*9880d681SAndroid Build Coastguard Workerexpressions that can be fused if the code generator determines that (a) the 11303*9880d681SAndroid Build Coastguard Workertarget instruction set has support for a fused operation, and (b) that the 11304*9880d681SAndroid Build Coastguard Workerfused operation is more efficient than the equivalent, separate pair of mul 11305*9880d681SAndroid Build Coastguard Workerand add instructions. 11306*9880d681SAndroid Build Coastguard Worker 11307*9880d681SAndroid Build Coastguard WorkerArguments: 11308*9880d681SAndroid Build Coastguard Worker"""""""""" 11309*9880d681SAndroid Build Coastguard Worker 11310*9880d681SAndroid Build Coastguard WorkerThe '``llvm.fmuladd.*``' intrinsics each take three arguments: two 11311*9880d681SAndroid Build Coastguard Workermultiplicands, a and b, and an addend c. 11312*9880d681SAndroid Build Coastguard Worker 11313*9880d681SAndroid Build Coastguard WorkerSemantics: 11314*9880d681SAndroid Build Coastguard Worker"""""""""" 11315*9880d681SAndroid Build Coastguard Worker 11316*9880d681SAndroid Build Coastguard WorkerThe expression: 11317*9880d681SAndroid Build Coastguard Worker 11318*9880d681SAndroid Build Coastguard Worker:: 11319*9880d681SAndroid Build Coastguard Worker 11320*9880d681SAndroid Build Coastguard Worker %0 = call float @llvm.fmuladd.f32(%a, %b, %c) 11321*9880d681SAndroid Build Coastguard Worker 11322*9880d681SAndroid Build Coastguard Workeris equivalent to the expression a \* b + c, except that rounding will 11323*9880d681SAndroid Build Coastguard Workernot be performed between the multiplication and addition steps if the 11324*9880d681SAndroid Build Coastguard Workercode generator fuses the operations. Fusion is not guaranteed, even if 11325*9880d681SAndroid Build Coastguard Workerthe target platform supports it. If a fused multiply-add is required the 11326*9880d681SAndroid Build Coastguard Workercorresponding llvm.fma.\* intrinsic function should be used 11327*9880d681SAndroid Build Coastguard Workerinstead. This never sets errno, just as '``llvm.fma.*``'. 11328*9880d681SAndroid Build Coastguard Worker 11329*9880d681SAndroid Build Coastguard WorkerExamples: 11330*9880d681SAndroid Build Coastguard Worker""""""""" 11331*9880d681SAndroid Build Coastguard Worker 11332*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 11333*9880d681SAndroid Build Coastguard Worker 11334*9880d681SAndroid Build Coastguard Worker %r2 = call float @llvm.fmuladd.f32(float %a, float %b, float %c) ; yields float:r2 = (a * b) + c 11335*9880d681SAndroid Build Coastguard Worker 11336*9880d681SAndroid Build Coastguard WorkerHalf Precision Floating Point Intrinsics 11337*9880d681SAndroid Build Coastguard Worker---------------------------------------- 11338*9880d681SAndroid Build Coastguard Worker 11339*9880d681SAndroid Build Coastguard WorkerFor most target platforms, half precision floating point is a 11340*9880d681SAndroid Build Coastguard Workerstorage-only format. This means that it is a dense encoding (in memory) 11341*9880d681SAndroid Build Coastguard Workerbut does not support computation in the format. 11342*9880d681SAndroid Build Coastguard Worker 11343*9880d681SAndroid Build Coastguard WorkerThis means that code must first load the half-precision floating point 11344*9880d681SAndroid Build Coastguard Workervalue as an i16, then convert it to float with 11345*9880d681SAndroid Build Coastguard Worker:ref:`llvm.convert.from.fp16 <int_convert_from_fp16>`. Computation can 11346*9880d681SAndroid Build Coastguard Workerthen be performed on the float value (including extending to double 11347*9880d681SAndroid Build Coastguard Workeretc). To store the value back to memory, it is first converted to float 11348*9880d681SAndroid Build Coastguard Workerif needed, then converted to i16 with 11349*9880d681SAndroid Build Coastguard Worker:ref:`llvm.convert.to.fp16 <int_convert_to_fp16>`, then storing as an 11350*9880d681SAndroid Build Coastguard Workeri16 value. 11351*9880d681SAndroid Build Coastguard Worker 11352*9880d681SAndroid Build Coastguard Worker.. _int_convert_to_fp16: 11353*9880d681SAndroid Build Coastguard Worker 11354*9880d681SAndroid Build Coastguard Worker'``llvm.convert.to.fp16``' Intrinsic 11355*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11356*9880d681SAndroid Build Coastguard Worker 11357*9880d681SAndroid Build Coastguard WorkerSyntax: 11358*9880d681SAndroid Build Coastguard Worker""""""" 11359*9880d681SAndroid Build Coastguard Worker 11360*9880d681SAndroid Build Coastguard Worker:: 11361*9880d681SAndroid Build Coastguard Worker 11362*9880d681SAndroid Build Coastguard Worker declare i16 @llvm.convert.to.fp16.f32(float %a) 11363*9880d681SAndroid Build Coastguard Worker declare i16 @llvm.convert.to.fp16.f64(double %a) 11364*9880d681SAndroid Build Coastguard Worker 11365*9880d681SAndroid Build Coastguard WorkerOverview: 11366*9880d681SAndroid Build Coastguard Worker""""""""" 11367*9880d681SAndroid Build Coastguard Worker 11368*9880d681SAndroid Build Coastguard WorkerThe '``llvm.convert.to.fp16``' intrinsic function performs a conversion from a 11369*9880d681SAndroid Build Coastguard Workerconventional floating point type to half precision floating point format. 11370*9880d681SAndroid Build Coastguard Worker 11371*9880d681SAndroid Build Coastguard WorkerArguments: 11372*9880d681SAndroid Build Coastguard Worker"""""""""" 11373*9880d681SAndroid Build Coastguard Worker 11374*9880d681SAndroid Build Coastguard WorkerThe intrinsic function contains single argument - the value to be 11375*9880d681SAndroid Build Coastguard Workerconverted. 11376*9880d681SAndroid Build Coastguard Worker 11377*9880d681SAndroid Build Coastguard WorkerSemantics: 11378*9880d681SAndroid Build Coastguard Worker"""""""""" 11379*9880d681SAndroid Build Coastguard Worker 11380*9880d681SAndroid Build Coastguard WorkerThe '``llvm.convert.to.fp16``' intrinsic function performs a conversion from a 11381*9880d681SAndroid Build Coastguard Workerconventional floating point format to half precision floating point format. The 11382*9880d681SAndroid Build Coastguard Workerreturn value is an ``i16`` which contains the converted number. 11383*9880d681SAndroid Build Coastguard Worker 11384*9880d681SAndroid Build Coastguard WorkerExamples: 11385*9880d681SAndroid Build Coastguard Worker""""""""" 11386*9880d681SAndroid Build Coastguard Worker 11387*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 11388*9880d681SAndroid Build Coastguard Worker 11389*9880d681SAndroid Build Coastguard Worker %res = call i16 @llvm.convert.to.fp16.f32(float %a) 11390*9880d681SAndroid Build Coastguard Worker store i16 %res, i16* @x, align 2 11391*9880d681SAndroid Build Coastguard Worker 11392*9880d681SAndroid Build Coastguard Worker.. _int_convert_from_fp16: 11393*9880d681SAndroid Build Coastguard Worker 11394*9880d681SAndroid Build Coastguard Worker'``llvm.convert.from.fp16``' Intrinsic 11395*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11396*9880d681SAndroid Build Coastguard Worker 11397*9880d681SAndroid Build Coastguard WorkerSyntax: 11398*9880d681SAndroid Build Coastguard Worker""""""" 11399*9880d681SAndroid Build Coastguard Worker 11400*9880d681SAndroid Build Coastguard Worker:: 11401*9880d681SAndroid Build Coastguard Worker 11402*9880d681SAndroid Build Coastguard Worker declare float @llvm.convert.from.fp16.f32(i16 %a) 11403*9880d681SAndroid Build Coastguard Worker declare double @llvm.convert.from.fp16.f64(i16 %a) 11404*9880d681SAndroid Build Coastguard Worker 11405*9880d681SAndroid Build Coastguard WorkerOverview: 11406*9880d681SAndroid Build Coastguard Worker""""""""" 11407*9880d681SAndroid Build Coastguard Worker 11408*9880d681SAndroid Build Coastguard WorkerThe '``llvm.convert.from.fp16``' intrinsic function performs a 11409*9880d681SAndroid Build Coastguard Workerconversion from half precision floating point format to single precision 11410*9880d681SAndroid Build Coastguard Workerfloating point format. 11411*9880d681SAndroid Build Coastguard Worker 11412*9880d681SAndroid Build Coastguard WorkerArguments: 11413*9880d681SAndroid Build Coastguard Worker"""""""""" 11414*9880d681SAndroid Build Coastguard Worker 11415*9880d681SAndroid Build Coastguard WorkerThe intrinsic function contains single argument - the value to be 11416*9880d681SAndroid Build Coastguard Workerconverted. 11417*9880d681SAndroid Build Coastguard Worker 11418*9880d681SAndroid Build Coastguard WorkerSemantics: 11419*9880d681SAndroid Build Coastguard Worker"""""""""" 11420*9880d681SAndroid Build Coastguard Worker 11421*9880d681SAndroid Build Coastguard WorkerThe '``llvm.convert.from.fp16``' intrinsic function performs a 11422*9880d681SAndroid Build Coastguard Workerconversion from half single precision floating point format to single 11423*9880d681SAndroid Build Coastguard Workerprecision floating point format. The input half-float value is 11424*9880d681SAndroid Build Coastguard Workerrepresented by an ``i16`` value. 11425*9880d681SAndroid Build Coastguard Worker 11426*9880d681SAndroid Build Coastguard WorkerExamples: 11427*9880d681SAndroid Build Coastguard Worker""""""""" 11428*9880d681SAndroid Build Coastguard Worker 11429*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 11430*9880d681SAndroid Build Coastguard Worker 11431*9880d681SAndroid Build Coastguard Worker %a = load i16, i16* @x, align 2 11432*9880d681SAndroid Build Coastguard Worker %res = call float @llvm.convert.from.fp16(i16 %a) 11433*9880d681SAndroid Build Coastguard Worker 11434*9880d681SAndroid Build Coastguard Worker.. _dbg_intrinsics: 11435*9880d681SAndroid Build Coastguard Worker 11436*9880d681SAndroid Build Coastguard WorkerDebugger Intrinsics 11437*9880d681SAndroid Build Coastguard Worker------------------- 11438*9880d681SAndroid Build Coastguard Worker 11439*9880d681SAndroid Build Coastguard WorkerThe LLVM debugger intrinsics (which all start with ``llvm.dbg.`` 11440*9880d681SAndroid Build Coastguard Workerprefix), are described in the `LLVM Source Level 11441*9880d681SAndroid Build Coastguard WorkerDebugging <SourceLevelDebugging.html#format_common_intrinsics>`_ 11442*9880d681SAndroid Build Coastguard Workerdocument. 11443*9880d681SAndroid Build Coastguard Worker 11444*9880d681SAndroid Build Coastguard WorkerException Handling Intrinsics 11445*9880d681SAndroid Build Coastguard Worker----------------------------- 11446*9880d681SAndroid Build Coastguard Worker 11447*9880d681SAndroid Build Coastguard WorkerThe LLVM exception handling intrinsics (which all start with 11448*9880d681SAndroid Build Coastguard Worker``llvm.eh.`` prefix), are described in the `LLVM Exception 11449*9880d681SAndroid Build Coastguard WorkerHandling <ExceptionHandling.html#format_common_intrinsics>`_ document. 11450*9880d681SAndroid Build Coastguard Worker 11451*9880d681SAndroid Build Coastguard Worker.. _int_trampoline: 11452*9880d681SAndroid Build Coastguard Worker 11453*9880d681SAndroid Build Coastguard WorkerTrampoline Intrinsics 11454*9880d681SAndroid Build Coastguard Worker--------------------- 11455*9880d681SAndroid Build Coastguard Worker 11456*9880d681SAndroid Build Coastguard WorkerThese intrinsics make it possible to excise one parameter, marked with 11457*9880d681SAndroid Build Coastguard Workerthe :ref:`nest <nest>` attribute, from a function. The result is a 11458*9880d681SAndroid Build Coastguard Workercallable function pointer lacking the nest parameter - the caller does 11459*9880d681SAndroid Build Coastguard Workernot need to provide a value for it. Instead, the value to use is stored 11460*9880d681SAndroid Build Coastguard Workerin advance in a "trampoline", a block of memory usually allocated on the 11461*9880d681SAndroid Build Coastguard Workerstack, which also contains code to splice the nest value into the 11462*9880d681SAndroid Build Coastguard Workerargument list. This is used to implement the GCC nested function address 11463*9880d681SAndroid Build Coastguard Workerextension. 11464*9880d681SAndroid Build Coastguard Worker 11465*9880d681SAndroid Build Coastguard WorkerFor example, if the function is ``i32 f(i8* nest %c, i32 %x, i32 %y)`` 11466*9880d681SAndroid Build Coastguard Workerthen the resulting function pointer has signature ``i32 (i32, i32)*``. 11467*9880d681SAndroid Build Coastguard WorkerIt can be created as follows: 11468*9880d681SAndroid Build Coastguard Worker 11469*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 11470*9880d681SAndroid Build Coastguard Worker 11471*9880d681SAndroid Build Coastguard Worker %tramp = alloca [10 x i8], align 4 ; size and alignment only correct for X86 11472*9880d681SAndroid Build Coastguard Worker %tramp1 = getelementptr [10 x i8], [10 x i8]* %tramp, i32 0, i32 0 11473*9880d681SAndroid Build Coastguard Worker call i8* @llvm.init.trampoline(i8* %tramp1, i8* bitcast (i32 (i8*, i32, i32)* @f to i8*), i8* %nval) 11474*9880d681SAndroid Build Coastguard Worker %p = call i8* @llvm.adjust.trampoline(i8* %tramp1) 11475*9880d681SAndroid Build Coastguard Worker %fp = bitcast i8* %p to i32 (i32, i32)* 11476*9880d681SAndroid Build Coastguard Worker 11477*9880d681SAndroid Build Coastguard WorkerThe call ``%val = call i32 %fp(i32 %x, i32 %y)`` is then equivalent to 11478*9880d681SAndroid Build Coastguard Worker``%val = call i32 %f(i8* %nval, i32 %x, i32 %y)``. 11479*9880d681SAndroid Build Coastguard Worker 11480*9880d681SAndroid Build Coastguard Worker.. _int_it: 11481*9880d681SAndroid Build Coastguard Worker 11482*9880d681SAndroid Build Coastguard Worker'``llvm.init.trampoline``' Intrinsic 11483*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11484*9880d681SAndroid Build Coastguard Worker 11485*9880d681SAndroid Build Coastguard WorkerSyntax: 11486*9880d681SAndroid Build Coastguard Worker""""""" 11487*9880d681SAndroid Build Coastguard Worker 11488*9880d681SAndroid Build Coastguard Worker:: 11489*9880d681SAndroid Build Coastguard Worker 11490*9880d681SAndroid Build Coastguard Worker declare void @llvm.init.trampoline(i8* <tramp>, i8* <func>, i8* <nval>) 11491*9880d681SAndroid Build Coastguard Worker 11492*9880d681SAndroid Build Coastguard WorkerOverview: 11493*9880d681SAndroid Build Coastguard Worker""""""""" 11494*9880d681SAndroid Build Coastguard Worker 11495*9880d681SAndroid Build Coastguard WorkerThis fills the memory pointed to by ``tramp`` with executable code, 11496*9880d681SAndroid Build Coastguard Workerturning it into a trampoline. 11497*9880d681SAndroid Build Coastguard Worker 11498*9880d681SAndroid Build Coastguard WorkerArguments: 11499*9880d681SAndroid Build Coastguard Worker"""""""""" 11500*9880d681SAndroid Build Coastguard Worker 11501*9880d681SAndroid Build Coastguard WorkerThe ``llvm.init.trampoline`` intrinsic takes three arguments, all 11502*9880d681SAndroid Build Coastguard Workerpointers. The ``tramp`` argument must point to a sufficiently large and 11503*9880d681SAndroid Build Coastguard Workersufficiently aligned block of memory; this memory is written to by the 11504*9880d681SAndroid Build Coastguard Workerintrinsic. Note that the size and the alignment are target-specific - 11505*9880d681SAndroid Build Coastguard WorkerLLVM currently provides no portable way of determining them, so a 11506*9880d681SAndroid Build Coastguard Workerfront-end that generates this intrinsic needs to have some 11507*9880d681SAndroid Build Coastguard Workertarget-specific knowledge. The ``func`` argument must hold a function 11508*9880d681SAndroid Build Coastguard Workerbitcast to an ``i8*``. 11509*9880d681SAndroid Build Coastguard Worker 11510*9880d681SAndroid Build Coastguard WorkerSemantics: 11511*9880d681SAndroid Build Coastguard Worker"""""""""" 11512*9880d681SAndroid Build Coastguard Worker 11513*9880d681SAndroid Build Coastguard WorkerThe block of memory pointed to by ``tramp`` is filled with target 11514*9880d681SAndroid Build Coastguard Workerdependent code, turning it into a function. Then ``tramp`` needs to be 11515*9880d681SAndroid Build Coastguard Workerpassed to :ref:`llvm.adjust.trampoline <int_at>` to get a pointer which can 11516*9880d681SAndroid Build Coastguard Workerbe :ref:`bitcast (to a new function) and called <int_trampoline>`. The new 11517*9880d681SAndroid Build Coastguard Workerfunction's signature is the same as that of ``func`` with any arguments 11518*9880d681SAndroid Build Coastguard Workermarked with the ``nest`` attribute removed. At most one such ``nest`` 11519*9880d681SAndroid Build Coastguard Workerargument is allowed, and it must be of pointer type. Calling the new 11520*9880d681SAndroid Build Coastguard Workerfunction is equivalent to calling ``func`` with the same argument list, 11521*9880d681SAndroid Build Coastguard Workerbut with ``nval`` used for the missing ``nest`` argument. If, after 11522*9880d681SAndroid Build Coastguard Workercalling ``llvm.init.trampoline``, the memory pointed to by ``tramp`` is 11523*9880d681SAndroid Build Coastguard Workermodified, then the effect of any later call to the returned function 11524*9880d681SAndroid Build Coastguard Workerpointer is undefined. 11525*9880d681SAndroid Build Coastguard Worker 11526*9880d681SAndroid Build Coastguard Worker.. _int_at: 11527*9880d681SAndroid Build Coastguard Worker 11528*9880d681SAndroid Build Coastguard Worker'``llvm.adjust.trampoline``' Intrinsic 11529*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11530*9880d681SAndroid Build Coastguard Worker 11531*9880d681SAndroid Build Coastguard WorkerSyntax: 11532*9880d681SAndroid Build Coastguard Worker""""""" 11533*9880d681SAndroid Build Coastguard Worker 11534*9880d681SAndroid Build Coastguard Worker:: 11535*9880d681SAndroid Build Coastguard Worker 11536*9880d681SAndroid Build Coastguard Worker declare i8* @llvm.adjust.trampoline(i8* <tramp>) 11537*9880d681SAndroid Build Coastguard Worker 11538*9880d681SAndroid Build Coastguard WorkerOverview: 11539*9880d681SAndroid Build Coastguard Worker""""""""" 11540*9880d681SAndroid Build Coastguard Worker 11541*9880d681SAndroid Build Coastguard WorkerThis performs any required machine-specific adjustment to the address of 11542*9880d681SAndroid Build Coastguard Workera trampoline (passed as ``tramp``). 11543*9880d681SAndroid Build Coastguard Worker 11544*9880d681SAndroid Build Coastguard WorkerArguments: 11545*9880d681SAndroid Build Coastguard Worker"""""""""" 11546*9880d681SAndroid Build Coastguard Worker 11547*9880d681SAndroid Build Coastguard Worker``tramp`` must point to a block of memory which already has trampoline 11548*9880d681SAndroid Build Coastguard Workercode filled in by a previous call to 11549*9880d681SAndroid Build Coastguard Worker:ref:`llvm.init.trampoline <int_it>`. 11550*9880d681SAndroid Build Coastguard Worker 11551*9880d681SAndroid Build Coastguard WorkerSemantics: 11552*9880d681SAndroid Build Coastguard Worker"""""""""" 11553*9880d681SAndroid Build Coastguard Worker 11554*9880d681SAndroid Build Coastguard WorkerOn some architectures the address of the code to be executed needs to be 11555*9880d681SAndroid Build Coastguard Workerdifferent than the address where the trampoline is actually stored. This 11556*9880d681SAndroid Build Coastguard Workerintrinsic returns the executable address corresponding to ``tramp`` 11557*9880d681SAndroid Build Coastguard Workerafter performing the required machine specific adjustments. The pointer 11558*9880d681SAndroid Build Coastguard Workerreturned can then be :ref:`bitcast and executed <int_trampoline>`. 11559*9880d681SAndroid Build Coastguard Worker 11560*9880d681SAndroid Build Coastguard Worker.. _int_mload_mstore: 11561*9880d681SAndroid Build Coastguard Worker 11562*9880d681SAndroid Build Coastguard WorkerMasked Vector Load and Store Intrinsics 11563*9880d681SAndroid Build Coastguard Worker--------------------------------------- 11564*9880d681SAndroid Build Coastguard Worker 11565*9880d681SAndroid Build Coastguard WorkerLLVM 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. 11566*9880d681SAndroid Build Coastguard Worker 11567*9880d681SAndroid Build Coastguard Worker.. _int_mload: 11568*9880d681SAndroid Build Coastguard Worker 11569*9880d681SAndroid Build Coastguard Worker'``llvm.masked.load.*``' Intrinsics 11570*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11571*9880d681SAndroid Build Coastguard Worker 11572*9880d681SAndroid Build Coastguard WorkerSyntax: 11573*9880d681SAndroid Build Coastguard Worker""""""" 11574*9880d681SAndroid Build Coastguard WorkerThis is an overloaded intrinsic. The loaded data is a vector of any integer, floating point or pointer data type. 11575*9880d681SAndroid Build Coastguard Worker 11576*9880d681SAndroid Build Coastguard Worker:: 11577*9880d681SAndroid Build Coastguard Worker 11578*9880d681SAndroid Build Coastguard Worker declare <16 x float> @llvm.masked.load.v16f32.p0v16f32 (<16 x float>* <ptr>, i32 <alignment>, <16 x i1> <mask>, <16 x float> <passthru>) 11579*9880d681SAndroid Build Coastguard Worker declare <2 x double> @llvm.masked.load.v2f64.p0v2f64 (<2 x double>* <ptr>, i32 <alignment>, <2 x i1> <mask>, <2 x double> <passthru>) 11580*9880d681SAndroid Build Coastguard Worker ;; The data is a vector of pointers to double 11581*9880d681SAndroid Build Coastguard Worker declare <8 x double*> @llvm.masked.load.v8p0f64.p0v8p0f64 (<8 x double*>* <ptr>, i32 <alignment>, <8 x i1> <mask>, <8 x double*> <passthru>) 11582*9880d681SAndroid Build Coastguard Worker ;; The data is a vector of function pointers 11583*9880d681SAndroid Build Coastguard Worker 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>) 11584*9880d681SAndroid Build Coastguard Worker 11585*9880d681SAndroid Build Coastguard WorkerOverview: 11586*9880d681SAndroid Build Coastguard Worker""""""""" 11587*9880d681SAndroid Build Coastguard Worker 11588*9880d681SAndroid Build Coastguard WorkerReads 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. 11589*9880d681SAndroid Build Coastguard Worker 11590*9880d681SAndroid Build Coastguard Worker 11591*9880d681SAndroid Build Coastguard WorkerArguments: 11592*9880d681SAndroid Build Coastguard Worker"""""""""" 11593*9880d681SAndroid Build Coastguard Worker 11594*9880d681SAndroid Build Coastguard WorkerThe first operand is the base pointer for the load. The second operand is the alignment of the source location. It must be a constant integer value. The third operand, mask, is a vector of boolean values with the same number of elements as the return type. The fourth is a pass-through value that is used to fill the masked-off lanes of the result. The return type, underlying type of the base pointer and the type of the '``passthru``' operand are the same vector types. 11595*9880d681SAndroid Build Coastguard Worker 11596*9880d681SAndroid Build Coastguard Worker 11597*9880d681SAndroid Build Coastguard WorkerSemantics: 11598*9880d681SAndroid Build Coastguard Worker"""""""""" 11599*9880d681SAndroid Build Coastguard Worker 11600*9880d681SAndroid Build Coastguard WorkerThe '``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. 11601*9880d681SAndroid Build Coastguard WorkerThe 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. 11602*9880d681SAndroid Build Coastguard Worker 11603*9880d681SAndroid Build Coastguard Worker 11604*9880d681SAndroid Build Coastguard Worker:: 11605*9880d681SAndroid Build Coastguard Worker 11606*9880d681SAndroid Build Coastguard Worker %res = call <16 x float> @llvm.masked.load.v16f32.p0v16f32 (<16 x float>* %ptr, i32 4, <16 x i1>%mask, <16 x float> %passthru) 11607*9880d681SAndroid Build Coastguard Worker 11608*9880d681SAndroid Build Coastguard Worker ;; The result of the two following instructions is identical aside from potential memory access exception 11609*9880d681SAndroid Build Coastguard Worker %loadlal = load <16 x float>, <16 x float>* %ptr, align 4 11610*9880d681SAndroid Build Coastguard Worker %res = select <16 x i1> %mask, <16 x float> %loadlal, <16 x float> %passthru 11611*9880d681SAndroid Build Coastguard Worker 11612*9880d681SAndroid Build Coastguard Worker.. _int_mstore: 11613*9880d681SAndroid Build Coastguard Worker 11614*9880d681SAndroid Build Coastguard Worker'``llvm.masked.store.*``' Intrinsics 11615*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11616*9880d681SAndroid Build Coastguard Worker 11617*9880d681SAndroid Build Coastguard WorkerSyntax: 11618*9880d681SAndroid Build Coastguard Worker""""""" 11619*9880d681SAndroid Build Coastguard WorkerThis is an overloaded intrinsic. The data stored in memory is a vector of any integer, floating point or pointer data type. 11620*9880d681SAndroid Build Coastguard Worker 11621*9880d681SAndroid Build Coastguard Worker:: 11622*9880d681SAndroid Build Coastguard Worker 11623*9880d681SAndroid Build Coastguard Worker declare void @llvm.masked.store.v8i32.p0v8i32 (<8 x i32> <value>, <8 x i32>* <ptr>, i32 <alignment>, <8 x i1> <mask>) 11624*9880d681SAndroid Build Coastguard Worker declare void @llvm.masked.store.v16f32.p0v16f32 (<16 x float> <value>, <16 x float>* <ptr>, i32 <alignment>, <16 x i1> <mask>) 11625*9880d681SAndroid Build Coastguard Worker ;; The data is a vector of pointers to double 11626*9880d681SAndroid Build Coastguard Worker declare void @llvm.masked.store.v8p0f64.p0v8p0f64 (<8 x double*> <value>, <8 x double*>* <ptr>, i32 <alignment>, <8 x i1> <mask>) 11627*9880d681SAndroid Build Coastguard Worker ;; The data is a vector of function pointers 11628*9880d681SAndroid Build Coastguard Worker declare void @llvm.masked.store.v4p0f_i32f.p0v4p0f_i32f (<4 x i32 ()*> <value>, <4 x i32 ()*>* <ptr>, i32 <alignment>, <4 x i1> <mask>) 11629*9880d681SAndroid Build Coastguard Worker 11630*9880d681SAndroid Build Coastguard WorkerOverview: 11631*9880d681SAndroid Build Coastguard Worker""""""""" 11632*9880d681SAndroid Build Coastguard Worker 11633*9880d681SAndroid Build Coastguard WorkerWrites 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. 11634*9880d681SAndroid Build Coastguard Worker 11635*9880d681SAndroid Build Coastguard WorkerArguments: 11636*9880d681SAndroid Build Coastguard Worker"""""""""" 11637*9880d681SAndroid Build Coastguard Worker 11638*9880d681SAndroid Build Coastguard WorkerThe first operand is the vector value to be written to memory. The second operand is the base pointer for the store, it has the same underlying type as the value operand. The third operand is the alignment of the destination location. The fourth operand, mask, is a vector of boolean values. The types of the mask and the value operand must have the same number of vector elements. 11639*9880d681SAndroid Build Coastguard Worker 11640*9880d681SAndroid Build Coastguard Worker 11641*9880d681SAndroid Build Coastguard WorkerSemantics: 11642*9880d681SAndroid Build Coastguard Worker"""""""""" 11643*9880d681SAndroid Build Coastguard Worker 11644*9880d681SAndroid Build Coastguard WorkerThe '``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. 11645*9880d681SAndroid Build Coastguard WorkerThe 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. 11646*9880d681SAndroid Build Coastguard Worker 11647*9880d681SAndroid Build Coastguard Worker:: 11648*9880d681SAndroid Build Coastguard Worker 11649*9880d681SAndroid Build Coastguard Worker call void @llvm.masked.store.v16f32.p0v16f32(<16 x float> %value, <16 x float>* %ptr, i32 4, <16 x i1> %mask) 11650*9880d681SAndroid Build Coastguard Worker 11651*9880d681SAndroid Build Coastguard Worker ;; The result of the following instructions is identical aside from potential data races and memory access exceptions 11652*9880d681SAndroid Build Coastguard Worker %oldval = load <16 x float>, <16 x float>* %ptr, align 4 11653*9880d681SAndroid Build Coastguard Worker %res = select <16 x i1> %mask, <16 x float> %value, <16 x float> %oldval 11654*9880d681SAndroid Build Coastguard Worker store <16 x float> %res, <16 x float>* %ptr, align 4 11655*9880d681SAndroid Build Coastguard Worker 11656*9880d681SAndroid Build Coastguard Worker 11657*9880d681SAndroid Build Coastguard WorkerMasked Vector Gather and Scatter Intrinsics 11658*9880d681SAndroid Build Coastguard Worker------------------------------------------- 11659*9880d681SAndroid Build Coastguard Worker 11660*9880d681SAndroid Build Coastguard WorkerLLVM 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. 11661*9880d681SAndroid Build Coastguard Worker 11662*9880d681SAndroid Build Coastguard Worker.. _int_mgather: 11663*9880d681SAndroid Build Coastguard Worker 11664*9880d681SAndroid Build Coastguard Worker'``llvm.masked.gather.*``' Intrinsics 11665*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11666*9880d681SAndroid Build Coastguard Worker 11667*9880d681SAndroid Build Coastguard WorkerSyntax: 11668*9880d681SAndroid Build Coastguard Worker""""""" 11669*9880d681SAndroid Build Coastguard WorkerThis 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. 11670*9880d681SAndroid Build Coastguard Worker 11671*9880d681SAndroid Build Coastguard Worker:: 11672*9880d681SAndroid Build Coastguard Worker 11673*9880d681SAndroid Build Coastguard Worker declare <16 x float> @llvm.masked.gather.v16f32 (<16 x float*> <ptrs>, i32 <alignment>, <16 x i1> <mask>, <16 x float> <passthru>) 11674*9880d681SAndroid Build Coastguard Worker declare <2 x double> @llvm.masked.gather.v2f64 (<2 x double*> <ptrs>, i32 <alignment>, <2 x i1> <mask>, <2 x double> <passthru>) 11675*9880d681SAndroid Build Coastguard Worker declare <8 x float*> @llvm.masked.gather.v8p0f32 (<8 x float**> <ptrs>, i32 <alignment>, <8 x i1> <mask>, <8 x float*> <passthru>) 11676*9880d681SAndroid Build Coastguard Worker 11677*9880d681SAndroid Build Coastguard WorkerOverview: 11678*9880d681SAndroid Build Coastguard Worker""""""""" 11679*9880d681SAndroid Build Coastguard Worker 11680*9880d681SAndroid Build Coastguard WorkerReads 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. 11681*9880d681SAndroid Build Coastguard Worker 11682*9880d681SAndroid Build Coastguard Worker 11683*9880d681SAndroid Build Coastguard WorkerArguments: 11684*9880d681SAndroid Build Coastguard Worker"""""""""" 11685*9880d681SAndroid Build Coastguard Worker 11686*9880d681SAndroid Build Coastguard WorkerThe first operand is a vector of pointers which holds all memory addresses to read. The second operand is an alignment of the source addresses. It must be a constant integer value. The third operand, mask, is a vector of boolean values with the same number of elements as the return type. The fourth is a pass-through value that is used to fill the masked-off lanes of the result. The return type, underlying type of the vector of pointers and the type of the '``passthru``' operand are the same vector types. 11687*9880d681SAndroid Build Coastguard Worker 11688*9880d681SAndroid Build Coastguard Worker 11689*9880d681SAndroid Build Coastguard WorkerSemantics: 11690*9880d681SAndroid Build Coastguard Worker"""""""""" 11691*9880d681SAndroid Build Coastguard Worker 11692*9880d681SAndroid Build Coastguard WorkerThe '``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. 11693*9880d681SAndroid Build Coastguard WorkerThe 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. 11694*9880d681SAndroid Build Coastguard Worker 11695*9880d681SAndroid Build Coastguard Worker 11696*9880d681SAndroid Build Coastguard Worker:: 11697*9880d681SAndroid Build Coastguard Worker 11698*9880d681SAndroid Build Coastguard Worker %res = call <4 x double> @llvm.masked.gather.v4f64 (<4 x double*> %ptrs, i32 8, <4 x i1>%mask, <4 x double> <true, true, true, true>) 11699*9880d681SAndroid Build Coastguard Worker 11700*9880d681SAndroid Build Coastguard Worker ;; The gather with all-true mask is equivalent to the following instruction sequence 11701*9880d681SAndroid Build Coastguard Worker %ptr0 = extractelement <4 x double*> %ptrs, i32 0 11702*9880d681SAndroid Build Coastguard Worker %ptr1 = extractelement <4 x double*> %ptrs, i32 1 11703*9880d681SAndroid Build Coastguard Worker %ptr2 = extractelement <4 x double*> %ptrs, i32 2 11704*9880d681SAndroid Build Coastguard Worker %ptr3 = extractelement <4 x double*> %ptrs, i32 3 11705*9880d681SAndroid Build Coastguard Worker 11706*9880d681SAndroid Build Coastguard Worker %val0 = load double, double* %ptr0, align 8 11707*9880d681SAndroid Build Coastguard Worker %val1 = load double, double* %ptr1, align 8 11708*9880d681SAndroid Build Coastguard Worker %val2 = load double, double* %ptr2, align 8 11709*9880d681SAndroid Build Coastguard Worker %val3 = load double, double* %ptr3, align 8 11710*9880d681SAndroid Build Coastguard Worker 11711*9880d681SAndroid Build Coastguard Worker %vec0 = insertelement <4 x double>undef, %val0, 0 11712*9880d681SAndroid Build Coastguard Worker %vec01 = insertelement <4 x double>%vec0, %val1, 1 11713*9880d681SAndroid Build Coastguard Worker %vec012 = insertelement <4 x double>%vec01, %val2, 2 11714*9880d681SAndroid Build Coastguard Worker %vec0123 = insertelement <4 x double>%vec012, %val3, 3 11715*9880d681SAndroid Build Coastguard Worker 11716*9880d681SAndroid Build Coastguard Worker.. _int_mscatter: 11717*9880d681SAndroid Build Coastguard Worker 11718*9880d681SAndroid Build Coastguard Worker'``llvm.masked.scatter.*``' Intrinsics 11719*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11720*9880d681SAndroid Build Coastguard Worker 11721*9880d681SAndroid Build Coastguard WorkerSyntax: 11722*9880d681SAndroid Build Coastguard Worker""""""" 11723*9880d681SAndroid Build Coastguard WorkerThis 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. 11724*9880d681SAndroid Build Coastguard Worker 11725*9880d681SAndroid Build Coastguard Worker:: 11726*9880d681SAndroid Build Coastguard Worker 11727*9880d681SAndroid Build Coastguard Worker declare void @llvm.masked.scatter.v8i32 (<8 x i32> <value>, <8 x i32*> <ptrs>, i32 <alignment>, <8 x i1> <mask>) 11728*9880d681SAndroid Build Coastguard Worker declare void @llvm.masked.scatter.v16f32 (<16 x float> <value>, <16 x float*> <ptrs>, i32 <alignment>, <16 x i1> <mask>) 11729*9880d681SAndroid Build Coastguard Worker declare void @llvm.masked.scatter.v4p0f64 (<4 x double*> <value>, <4 x double**> <ptrs>, i32 <alignment>, <4 x i1> <mask>) 11730*9880d681SAndroid Build Coastguard Worker 11731*9880d681SAndroid Build Coastguard WorkerOverview: 11732*9880d681SAndroid Build Coastguard Worker""""""""" 11733*9880d681SAndroid Build Coastguard Worker 11734*9880d681SAndroid Build Coastguard WorkerWrites 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. 11735*9880d681SAndroid Build Coastguard Worker 11736*9880d681SAndroid Build Coastguard WorkerArguments: 11737*9880d681SAndroid Build Coastguard Worker"""""""""" 11738*9880d681SAndroid Build Coastguard Worker 11739*9880d681SAndroid Build Coastguard WorkerThe first operand is a vector value to be written to memory. The second operand is a vector of pointers, pointing to where the value elements should be stored. It has the same underlying type as the value operand. The third operand is an alignment of the destination addresses. The fourth operand, mask, is a vector of boolean values. The types of the mask and the value operand must have the same number of vector elements. 11740*9880d681SAndroid Build Coastguard Worker 11741*9880d681SAndroid Build Coastguard Worker 11742*9880d681SAndroid Build Coastguard WorkerSemantics: 11743*9880d681SAndroid Build Coastguard Worker"""""""""" 11744*9880d681SAndroid Build Coastguard Worker 11745*9880d681SAndroid Build Coastguard WorkerThe '``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. 11746*9880d681SAndroid Build Coastguard Worker 11747*9880d681SAndroid Build Coastguard Worker:: 11748*9880d681SAndroid Build Coastguard Worker 11749*9880d681SAndroid Build Coastguard Worker ;; This instruction unconditionally stores data vector in multiple addresses 11750*9880d681SAndroid Build Coastguard Worker call @llvm.masked.scatter.v8i32 (<8 x i32> %value, <8 x i32*> %ptrs, i32 4, <8 x i1> <true, true, .. true>) 11751*9880d681SAndroid Build Coastguard Worker 11752*9880d681SAndroid Build Coastguard Worker ;; It is equivalent to a list of scalar stores 11753*9880d681SAndroid Build Coastguard Worker %val0 = extractelement <8 x i32> %value, i32 0 11754*9880d681SAndroid Build Coastguard Worker %val1 = extractelement <8 x i32> %value, i32 1 11755*9880d681SAndroid Build Coastguard Worker .. 11756*9880d681SAndroid Build Coastguard Worker %val7 = extractelement <8 x i32> %value, i32 7 11757*9880d681SAndroid Build Coastguard Worker %ptr0 = extractelement <8 x i32*> %ptrs, i32 0 11758*9880d681SAndroid Build Coastguard Worker %ptr1 = extractelement <8 x i32*> %ptrs, i32 1 11759*9880d681SAndroid Build Coastguard Worker .. 11760*9880d681SAndroid Build Coastguard Worker %ptr7 = extractelement <8 x i32*> %ptrs, i32 7 11761*9880d681SAndroid Build Coastguard Worker ;; Note: the order of the following stores is important when they overlap: 11762*9880d681SAndroid Build Coastguard Worker store i32 %val0, i32* %ptr0, align 4 11763*9880d681SAndroid Build Coastguard Worker store i32 %val1, i32* %ptr1, align 4 11764*9880d681SAndroid Build Coastguard Worker .. 11765*9880d681SAndroid Build Coastguard Worker store i32 %val7, i32* %ptr7, align 4 11766*9880d681SAndroid Build Coastguard Worker 11767*9880d681SAndroid Build Coastguard Worker 11768*9880d681SAndroid Build Coastguard WorkerMemory Use Markers 11769*9880d681SAndroid Build Coastguard Worker------------------ 11770*9880d681SAndroid Build Coastguard Worker 11771*9880d681SAndroid Build Coastguard WorkerThis class of intrinsics provides information about the lifetime of 11772*9880d681SAndroid Build Coastguard Workermemory objects and ranges where variables are immutable. 11773*9880d681SAndroid Build Coastguard Worker 11774*9880d681SAndroid Build Coastguard Worker.. _int_lifestart: 11775*9880d681SAndroid Build Coastguard Worker 11776*9880d681SAndroid Build Coastguard Worker'``llvm.lifetime.start``' Intrinsic 11777*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11778*9880d681SAndroid Build Coastguard Worker 11779*9880d681SAndroid Build Coastguard WorkerSyntax: 11780*9880d681SAndroid Build Coastguard Worker""""""" 11781*9880d681SAndroid Build Coastguard Worker 11782*9880d681SAndroid Build Coastguard Worker:: 11783*9880d681SAndroid Build Coastguard Worker 11784*9880d681SAndroid Build Coastguard Worker declare void @llvm.lifetime.start(i64 <size>, i8* nocapture <ptr>) 11785*9880d681SAndroid Build Coastguard Worker 11786*9880d681SAndroid Build Coastguard WorkerOverview: 11787*9880d681SAndroid Build Coastguard Worker""""""""" 11788*9880d681SAndroid Build Coastguard Worker 11789*9880d681SAndroid Build Coastguard WorkerThe '``llvm.lifetime.start``' intrinsic specifies the start of a memory 11790*9880d681SAndroid Build Coastguard Workerobject's lifetime. 11791*9880d681SAndroid Build Coastguard Worker 11792*9880d681SAndroid Build Coastguard WorkerArguments: 11793*9880d681SAndroid Build Coastguard Worker"""""""""" 11794*9880d681SAndroid Build Coastguard Worker 11795*9880d681SAndroid Build Coastguard WorkerThe first argument is a constant integer representing the size of the 11796*9880d681SAndroid Build Coastguard Workerobject, or -1 if it is variable sized. The second argument is a pointer 11797*9880d681SAndroid Build Coastguard Workerto the object. 11798*9880d681SAndroid Build Coastguard Worker 11799*9880d681SAndroid Build Coastguard WorkerSemantics: 11800*9880d681SAndroid Build Coastguard Worker"""""""""" 11801*9880d681SAndroid Build Coastguard Worker 11802*9880d681SAndroid Build Coastguard WorkerThis intrinsic indicates that before this point in the code, the value 11803*9880d681SAndroid Build Coastguard Workerof the memory pointed to by ``ptr`` is dead. This means that it is known 11804*9880d681SAndroid Build Coastguard Workerto never be used and has an undefined value. A load from the pointer 11805*9880d681SAndroid Build Coastguard Workerthat precedes this intrinsic can be replaced with ``'undef'``. 11806*9880d681SAndroid Build Coastguard Worker 11807*9880d681SAndroid Build Coastguard Worker.. _int_lifeend: 11808*9880d681SAndroid Build Coastguard Worker 11809*9880d681SAndroid Build Coastguard Worker'``llvm.lifetime.end``' Intrinsic 11810*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11811*9880d681SAndroid Build Coastguard Worker 11812*9880d681SAndroid Build Coastguard WorkerSyntax: 11813*9880d681SAndroid Build Coastguard Worker""""""" 11814*9880d681SAndroid Build Coastguard Worker 11815*9880d681SAndroid Build Coastguard Worker:: 11816*9880d681SAndroid Build Coastguard Worker 11817*9880d681SAndroid Build Coastguard Worker declare void @llvm.lifetime.end(i64 <size>, i8* nocapture <ptr>) 11818*9880d681SAndroid Build Coastguard Worker 11819*9880d681SAndroid Build Coastguard WorkerOverview: 11820*9880d681SAndroid Build Coastguard Worker""""""""" 11821*9880d681SAndroid Build Coastguard Worker 11822*9880d681SAndroid Build Coastguard WorkerThe '``llvm.lifetime.end``' intrinsic specifies the end of a memory 11823*9880d681SAndroid Build Coastguard Workerobject's lifetime. 11824*9880d681SAndroid Build Coastguard Worker 11825*9880d681SAndroid Build Coastguard WorkerArguments: 11826*9880d681SAndroid Build Coastguard Worker"""""""""" 11827*9880d681SAndroid Build Coastguard Worker 11828*9880d681SAndroid Build Coastguard WorkerThe first argument is a constant integer representing the size of the 11829*9880d681SAndroid Build Coastguard Workerobject, or -1 if it is variable sized. The second argument is a pointer 11830*9880d681SAndroid Build Coastguard Workerto the object. 11831*9880d681SAndroid Build Coastguard Worker 11832*9880d681SAndroid Build Coastguard WorkerSemantics: 11833*9880d681SAndroid Build Coastguard Worker"""""""""" 11834*9880d681SAndroid Build Coastguard Worker 11835*9880d681SAndroid Build Coastguard WorkerThis intrinsic indicates that after this point in the code, the value of 11836*9880d681SAndroid Build Coastguard Workerthe memory pointed to by ``ptr`` is dead. This means that it is known to 11837*9880d681SAndroid Build Coastguard Workernever be used and has an undefined value. Any stores into the memory 11838*9880d681SAndroid Build Coastguard Workerobject following this intrinsic may be removed as dead. 11839*9880d681SAndroid Build Coastguard Worker 11840*9880d681SAndroid Build Coastguard Worker'``llvm.invariant.start``' Intrinsic 11841*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11842*9880d681SAndroid Build Coastguard Worker 11843*9880d681SAndroid Build Coastguard WorkerSyntax: 11844*9880d681SAndroid Build Coastguard Worker""""""" 11845*9880d681SAndroid Build Coastguard Worker 11846*9880d681SAndroid Build Coastguard Worker:: 11847*9880d681SAndroid Build Coastguard Worker 11848*9880d681SAndroid Build Coastguard Worker declare {}* @llvm.invariant.start(i64 <size>, i8* nocapture <ptr>) 11849*9880d681SAndroid Build Coastguard Worker 11850*9880d681SAndroid Build Coastguard WorkerOverview: 11851*9880d681SAndroid Build Coastguard Worker""""""""" 11852*9880d681SAndroid Build Coastguard Worker 11853*9880d681SAndroid Build Coastguard WorkerThe '``llvm.invariant.start``' intrinsic specifies that the contents of 11854*9880d681SAndroid Build Coastguard Workera memory object will not change. 11855*9880d681SAndroid Build Coastguard Worker 11856*9880d681SAndroid Build Coastguard WorkerArguments: 11857*9880d681SAndroid Build Coastguard Worker"""""""""" 11858*9880d681SAndroid Build Coastguard Worker 11859*9880d681SAndroid Build Coastguard WorkerThe first argument is a constant integer representing the size of the 11860*9880d681SAndroid Build Coastguard Workerobject, or -1 if it is variable sized. The second argument is a pointer 11861*9880d681SAndroid Build Coastguard Workerto the object. 11862*9880d681SAndroid Build Coastguard Worker 11863*9880d681SAndroid Build Coastguard WorkerSemantics: 11864*9880d681SAndroid Build Coastguard Worker"""""""""" 11865*9880d681SAndroid Build Coastguard Worker 11866*9880d681SAndroid Build Coastguard WorkerThis intrinsic indicates that until an ``llvm.invariant.end`` that uses 11867*9880d681SAndroid Build Coastguard Workerthe return value, the referenced memory location is constant and 11868*9880d681SAndroid Build Coastguard Workerunchanging. 11869*9880d681SAndroid Build Coastguard Worker 11870*9880d681SAndroid Build Coastguard Worker'``llvm.invariant.end``' Intrinsic 11871*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11872*9880d681SAndroid Build Coastguard Worker 11873*9880d681SAndroid Build Coastguard WorkerSyntax: 11874*9880d681SAndroid Build Coastguard Worker""""""" 11875*9880d681SAndroid Build Coastguard Worker 11876*9880d681SAndroid Build Coastguard Worker:: 11877*9880d681SAndroid Build Coastguard Worker 11878*9880d681SAndroid Build Coastguard Worker declare void @llvm.invariant.end({}* <start>, i64 <size>, i8* nocapture <ptr>) 11879*9880d681SAndroid Build Coastguard Worker 11880*9880d681SAndroid Build Coastguard WorkerOverview: 11881*9880d681SAndroid Build Coastguard Worker""""""""" 11882*9880d681SAndroid Build Coastguard Worker 11883*9880d681SAndroid Build Coastguard WorkerThe '``llvm.invariant.end``' intrinsic specifies that the contents of a 11884*9880d681SAndroid Build Coastguard Workermemory object are mutable. 11885*9880d681SAndroid Build Coastguard Worker 11886*9880d681SAndroid Build Coastguard WorkerArguments: 11887*9880d681SAndroid Build Coastguard Worker"""""""""" 11888*9880d681SAndroid Build Coastguard Worker 11889*9880d681SAndroid Build Coastguard WorkerThe first argument is the matching ``llvm.invariant.start`` intrinsic. 11890*9880d681SAndroid Build Coastguard WorkerThe second argument is a constant integer representing the size of the 11891*9880d681SAndroid Build Coastguard Workerobject, or -1 if it is variable sized and the third argument is a 11892*9880d681SAndroid Build Coastguard Workerpointer to the object. 11893*9880d681SAndroid Build Coastguard Worker 11894*9880d681SAndroid Build Coastguard WorkerSemantics: 11895*9880d681SAndroid Build Coastguard Worker"""""""""" 11896*9880d681SAndroid Build Coastguard Worker 11897*9880d681SAndroid Build Coastguard WorkerThis intrinsic indicates that the memory is mutable again. 11898*9880d681SAndroid Build Coastguard Worker 11899*9880d681SAndroid Build Coastguard Worker'``llvm.invariant.group.barrier``' Intrinsic 11900*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11901*9880d681SAndroid Build Coastguard Worker 11902*9880d681SAndroid Build Coastguard WorkerSyntax: 11903*9880d681SAndroid Build Coastguard Worker""""""" 11904*9880d681SAndroid Build Coastguard Worker 11905*9880d681SAndroid Build Coastguard Worker:: 11906*9880d681SAndroid Build Coastguard Worker 11907*9880d681SAndroid Build Coastguard Worker declare i8* @llvm.invariant.group.barrier(i8* <ptr>) 11908*9880d681SAndroid Build Coastguard Worker 11909*9880d681SAndroid Build Coastguard WorkerOverview: 11910*9880d681SAndroid Build Coastguard Worker""""""""" 11911*9880d681SAndroid Build Coastguard Worker 11912*9880d681SAndroid Build Coastguard WorkerThe '``llvm.invariant.group.barrier``' intrinsic can be used when an invariant 11913*9880d681SAndroid Build Coastguard Workerestablished by invariant.group metadata no longer holds, to obtain a new pointer 11914*9880d681SAndroid Build Coastguard Workervalue that does not carry the invariant information. 11915*9880d681SAndroid Build Coastguard Worker 11916*9880d681SAndroid Build Coastguard Worker 11917*9880d681SAndroid Build Coastguard WorkerArguments: 11918*9880d681SAndroid Build Coastguard Worker"""""""""" 11919*9880d681SAndroid Build Coastguard Worker 11920*9880d681SAndroid Build Coastguard WorkerThe ``llvm.invariant.group.barrier`` takes only one argument, which is 11921*9880d681SAndroid Build Coastguard Workerthe pointer to the memory for which the ``invariant.group`` no longer holds. 11922*9880d681SAndroid Build Coastguard Worker 11923*9880d681SAndroid Build Coastguard WorkerSemantics: 11924*9880d681SAndroid Build Coastguard Worker"""""""""" 11925*9880d681SAndroid Build Coastguard Worker 11926*9880d681SAndroid Build Coastguard WorkerReturns another pointer that aliases its argument but which is considered different 11927*9880d681SAndroid Build Coastguard Workerfor the purposes of ``load``/``store`` ``invariant.group`` metadata. 11928*9880d681SAndroid Build Coastguard Worker 11929*9880d681SAndroid Build Coastguard WorkerGeneral Intrinsics 11930*9880d681SAndroid Build Coastguard Worker------------------ 11931*9880d681SAndroid Build Coastguard Worker 11932*9880d681SAndroid Build Coastguard WorkerThis class of intrinsics is designed to be generic and has no specific 11933*9880d681SAndroid Build Coastguard Workerpurpose. 11934*9880d681SAndroid Build Coastguard Worker 11935*9880d681SAndroid Build Coastguard Worker'``llvm.var.annotation``' Intrinsic 11936*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11937*9880d681SAndroid Build Coastguard Worker 11938*9880d681SAndroid Build Coastguard WorkerSyntax: 11939*9880d681SAndroid Build Coastguard Worker""""""" 11940*9880d681SAndroid Build Coastguard Worker 11941*9880d681SAndroid Build Coastguard Worker:: 11942*9880d681SAndroid Build Coastguard Worker 11943*9880d681SAndroid Build Coastguard Worker declare void @llvm.var.annotation(i8* <val>, i8* <str>, i8* <str>, i32 <int>) 11944*9880d681SAndroid Build Coastguard Worker 11945*9880d681SAndroid Build Coastguard WorkerOverview: 11946*9880d681SAndroid Build Coastguard Worker""""""""" 11947*9880d681SAndroid Build Coastguard Worker 11948*9880d681SAndroid Build Coastguard WorkerThe '``llvm.var.annotation``' intrinsic. 11949*9880d681SAndroid Build Coastguard Worker 11950*9880d681SAndroid Build Coastguard WorkerArguments: 11951*9880d681SAndroid Build Coastguard Worker"""""""""" 11952*9880d681SAndroid Build Coastguard Worker 11953*9880d681SAndroid Build Coastguard WorkerThe first argument is a pointer to a value, the second is a pointer to a 11954*9880d681SAndroid Build Coastguard Workerglobal string, the third is a pointer to a global string which is the 11955*9880d681SAndroid Build Coastguard Workersource file name, and the last argument is the line number. 11956*9880d681SAndroid Build Coastguard Worker 11957*9880d681SAndroid Build Coastguard WorkerSemantics: 11958*9880d681SAndroid Build Coastguard Worker"""""""""" 11959*9880d681SAndroid Build Coastguard Worker 11960*9880d681SAndroid Build Coastguard WorkerThis intrinsic allows annotation of local variables with arbitrary 11961*9880d681SAndroid Build Coastguard Workerstrings. This can be useful for special purpose optimizations that want 11962*9880d681SAndroid Build Coastguard Workerto look for these annotations. These have no other defined use; they are 11963*9880d681SAndroid Build Coastguard Workerignored by code generation and optimization. 11964*9880d681SAndroid Build Coastguard Worker 11965*9880d681SAndroid Build Coastguard Worker'``llvm.ptr.annotation.*``' Intrinsic 11966*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11967*9880d681SAndroid Build Coastguard Worker 11968*9880d681SAndroid Build Coastguard WorkerSyntax: 11969*9880d681SAndroid Build Coastguard Worker""""""" 11970*9880d681SAndroid Build Coastguard Worker 11971*9880d681SAndroid Build Coastguard WorkerThis is an overloaded intrinsic. You can use '``llvm.ptr.annotation``' on a 11972*9880d681SAndroid Build Coastguard Workerpointer to an integer of any width. *NOTE* you must specify an address space for 11973*9880d681SAndroid Build Coastguard Workerthe pointer. The identifier for the default address space is the integer 11974*9880d681SAndroid Build Coastguard Worker'``0``'. 11975*9880d681SAndroid Build Coastguard Worker 11976*9880d681SAndroid Build Coastguard Worker:: 11977*9880d681SAndroid Build Coastguard Worker 11978*9880d681SAndroid Build Coastguard Worker declare i8* @llvm.ptr.annotation.p<address space>i8(i8* <val>, i8* <str>, i8* <str>, i32 <int>) 11979*9880d681SAndroid Build Coastguard Worker declare i16* @llvm.ptr.annotation.p<address space>i16(i16* <val>, i8* <str>, i8* <str>, i32 <int>) 11980*9880d681SAndroid Build Coastguard Worker declare i32* @llvm.ptr.annotation.p<address space>i32(i32* <val>, i8* <str>, i8* <str>, i32 <int>) 11981*9880d681SAndroid Build Coastguard Worker declare i64* @llvm.ptr.annotation.p<address space>i64(i64* <val>, i8* <str>, i8* <str>, i32 <int>) 11982*9880d681SAndroid Build Coastguard Worker declare i256* @llvm.ptr.annotation.p<address space>i256(i256* <val>, i8* <str>, i8* <str>, i32 <int>) 11983*9880d681SAndroid Build Coastguard Worker 11984*9880d681SAndroid Build Coastguard WorkerOverview: 11985*9880d681SAndroid Build Coastguard Worker""""""""" 11986*9880d681SAndroid Build Coastguard Worker 11987*9880d681SAndroid Build Coastguard WorkerThe '``llvm.ptr.annotation``' intrinsic. 11988*9880d681SAndroid Build Coastguard Worker 11989*9880d681SAndroid Build Coastguard WorkerArguments: 11990*9880d681SAndroid Build Coastguard Worker"""""""""" 11991*9880d681SAndroid Build Coastguard Worker 11992*9880d681SAndroid Build Coastguard WorkerThe first argument is a pointer to an integer value of arbitrary bitwidth 11993*9880d681SAndroid Build Coastguard Worker(result of some expression), the second is a pointer to a global string, the 11994*9880d681SAndroid Build Coastguard Workerthird is a pointer to a global string which is the source file name, and the 11995*9880d681SAndroid Build Coastguard Workerlast argument is the line number. It returns the value of the first argument. 11996*9880d681SAndroid Build Coastguard Worker 11997*9880d681SAndroid Build Coastguard WorkerSemantics: 11998*9880d681SAndroid Build Coastguard Worker"""""""""" 11999*9880d681SAndroid Build Coastguard Worker 12000*9880d681SAndroid Build Coastguard WorkerThis intrinsic allows annotation of a pointer to an integer with arbitrary 12001*9880d681SAndroid Build Coastguard Workerstrings. This can be useful for special purpose optimizations that want to look 12002*9880d681SAndroid Build Coastguard Workerfor these annotations. These have no other defined use; they are ignored by code 12003*9880d681SAndroid Build Coastguard Workergeneration and optimization. 12004*9880d681SAndroid Build Coastguard Worker 12005*9880d681SAndroid Build Coastguard Worker'``llvm.annotation.*``' Intrinsic 12006*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12007*9880d681SAndroid Build Coastguard Worker 12008*9880d681SAndroid Build Coastguard WorkerSyntax: 12009*9880d681SAndroid Build Coastguard Worker""""""" 12010*9880d681SAndroid Build Coastguard Worker 12011*9880d681SAndroid Build Coastguard WorkerThis is an overloaded intrinsic. You can use '``llvm.annotation``' on 12012*9880d681SAndroid Build Coastguard Workerany integer bit width. 12013*9880d681SAndroid Build Coastguard Worker 12014*9880d681SAndroid Build Coastguard Worker:: 12015*9880d681SAndroid Build Coastguard Worker 12016*9880d681SAndroid Build Coastguard Worker declare i8 @llvm.annotation.i8(i8 <val>, i8* <str>, i8* <str>, i32 <int>) 12017*9880d681SAndroid Build Coastguard Worker declare i16 @llvm.annotation.i16(i16 <val>, i8* <str>, i8* <str>, i32 <int>) 12018*9880d681SAndroid Build Coastguard Worker declare i32 @llvm.annotation.i32(i32 <val>, i8* <str>, i8* <str>, i32 <int>) 12019*9880d681SAndroid Build Coastguard Worker declare i64 @llvm.annotation.i64(i64 <val>, i8* <str>, i8* <str>, i32 <int>) 12020*9880d681SAndroid Build Coastguard Worker declare i256 @llvm.annotation.i256(i256 <val>, i8* <str>, i8* <str>, i32 <int>) 12021*9880d681SAndroid Build Coastguard Worker 12022*9880d681SAndroid Build Coastguard WorkerOverview: 12023*9880d681SAndroid Build Coastguard Worker""""""""" 12024*9880d681SAndroid Build Coastguard Worker 12025*9880d681SAndroid Build Coastguard WorkerThe '``llvm.annotation``' intrinsic. 12026*9880d681SAndroid Build Coastguard Worker 12027*9880d681SAndroid Build Coastguard WorkerArguments: 12028*9880d681SAndroid Build Coastguard Worker"""""""""" 12029*9880d681SAndroid Build Coastguard Worker 12030*9880d681SAndroid Build Coastguard WorkerThe first argument is an integer value (result of some expression), the 12031*9880d681SAndroid Build Coastguard Workersecond is a pointer to a global string, the third is a pointer to a 12032*9880d681SAndroid Build Coastguard Workerglobal string which is the source file name, and the last argument is 12033*9880d681SAndroid Build Coastguard Workerthe line number. It returns the value of the first argument. 12034*9880d681SAndroid Build Coastguard Worker 12035*9880d681SAndroid Build Coastguard WorkerSemantics: 12036*9880d681SAndroid Build Coastguard Worker"""""""""" 12037*9880d681SAndroid Build Coastguard Worker 12038*9880d681SAndroid Build Coastguard WorkerThis intrinsic allows annotations to be put on arbitrary expressions 12039*9880d681SAndroid Build Coastguard Workerwith arbitrary strings. This can be useful for special purpose 12040*9880d681SAndroid Build Coastguard Workeroptimizations that want to look for these annotations. These have no 12041*9880d681SAndroid Build Coastguard Workerother defined use; they are ignored by code generation and optimization. 12042*9880d681SAndroid Build Coastguard Worker 12043*9880d681SAndroid Build Coastguard Worker'``llvm.trap``' Intrinsic 12044*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^ 12045*9880d681SAndroid Build Coastguard Worker 12046*9880d681SAndroid Build Coastguard WorkerSyntax: 12047*9880d681SAndroid Build Coastguard Worker""""""" 12048*9880d681SAndroid Build Coastguard Worker 12049*9880d681SAndroid Build Coastguard Worker:: 12050*9880d681SAndroid Build Coastguard Worker 12051*9880d681SAndroid Build Coastguard Worker declare void @llvm.trap() noreturn nounwind 12052*9880d681SAndroid Build Coastguard Worker 12053*9880d681SAndroid Build Coastguard WorkerOverview: 12054*9880d681SAndroid Build Coastguard Worker""""""""" 12055*9880d681SAndroid Build Coastguard Worker 12056*9880d681SAndroid Build Coastguard WorkerThe '``llvm.trap``' intrinsic. 12057*9880d681SAndroid Build Coastguard Worker 12058*9880d681SAndroid Build Coastguard WorkerArguments: 12059*9880d681SAndroid Build Coastguard Worker"""""""""" 12060*9880d681SAndroid Build Coastguard Worker 12061*9880d681SAndroid Build Coastguard WorkerNone. 12062*9880d681SAndroid Build Coastguard Worker 12063*9880d681SAndroid Build Coastguard WorkerSemantics: 12064*9880d681SAndroid Build Coastguard Worker"""""""""" 12065*9880d681SAndroid Build Coastguard Worker 12066*9880d681SAndroid Build Coastguard WorkerThis intrinsic is lowered to the target dependent trap instruction. If 12067*9880d681SAndroid Build Coastguard Workerthe target does not have a trap instruction, this intrinsic will be 12068*9880d681SAndroid Build Coastguard Workerlowered to a call of the ``abort()`` function. 12069*9880d681SAndroid Build Coastguard Worker 12070*9880d681SAndroid Build Coastguard Worker'``llvm.debugtrap``' Intrinsic 12071*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12072*9880d681SAndroid Build Coastguard Worker 12073*9880d681SAndroid Build Coastguard WorkerSyntax: 12074*9880d681SAndroid Build Coastguard Worker""""""" 12075*9880d681SAndroid Build Coastguard Worker 12076*9880d681SAndroid Build Coastguard Worker:: 12077*9880d681SAndroid Build Coastguard Worker 12078*9880d681SAndroid Build Coastguard Worker declare void @llvm.debugtrap() nounwind 12079*9880d681SAndroid Build Coastguard Worker 12080*9880d681SAndroid Build Coastguard WorkerOverview: 12081*9880d681SAndroid Build Coastguard Worker""""""""" 12082*9880d681SAndroid Build Coastguard Worker 12083*9880d681SAndroid Build Coastguard WorkerThe '``llvm.debugtrap``' intrinsic. 12084*9880d681SAndroid Build Coastguard Worker 12085*9880d681SAndroid Build Coastguard WorkerArguments: 12086*9880d681SAndroid Build Coastguard Worker"""""""""" 12087*9880d681SAndroid Build Coastguard Worker 12088*9880d681SAndroid Build Coastguard WorkerNone. 12089*9880d681SAndroid Build Coastguard Worker 12090*9880d681SAndroid Build Coastguard WorkerSemantics: 12091*9880d681SAndroid Build Coastguard Worker"""""""""" 12092*9880d681SAndroid Build Coastguard Worker 12093*9880d681SAndroid Build Coastguard WorkerThis intrinsic is lowered to code which is intended to cause an 12094*9880d681SAndroid Build Coastguard Workerexecution trap with the intention of requesting the attention of a 12095*9880d681SAndroid Build Coastguard Workerdebugger. 12096*9880d681SAndroid Build Coastguard Worker 12097*9880d681SAndroid Build Coastguard Worker'``llvm.stackprotector``' Intrinsic 12098*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12099*9880d681SAndroid Build Coastguard Worker 12100*9880d681SAndroid Build Coastguard WorkerSyntax: 12101*9880d681SAndroid Build Coastguard Worker""""""" 12102*9880d681SAndroid Build Coastguard Worker 12103*9880d681SAndroid Build Coastguard Worker:: 12104*9880d681SAndroid Build Coastguard Worker 12105*9880d681SAndroid Build Coastguard Worker declare void @llvm.stackprotector(i8* <guard>, i8** <slot>) 12106*9880d681SAndroid Build Coastguard Worker 12107*9880d681SAndroid Build Coastguard WorkerOverview: 12108*9880d681SAndroid Build Coastguard Worker""""""""" 12109*9880d681SAndroid Build Coastguard Worker 12110*9880d681SAndroid Build Coastguard WorkerThe ``llvm.stackprotector`` intrinsic takes the ``guard`` and stores it 12111*9880d681SAndroid Build Coastguard Workeronto the stack at ``slot``. The stack slot is adjusted to ensure that it 12112*9880d681SAndroid Build Coastguard Workeris placed on the stack before local variables. 12113*9880d681SAndroid Build Coastguard Worker 12114*9880d681SAndroid Build Coastguard WorkerArguments: 12115*9880d681SAndroid Build Coastguard Worker"""""""""" 12116*9880d681SAndroid Build Coastguard Worker 12117*9880d681SAndroid Build Coastguard WorkerThe ``llvm.stackprotector`` intrinsic requires two pointer arguments. 12118*9880d681SAndroid Build Coastguard WorkerThe first argument is the value loaded from the stack guard 12119*9880d681SAndroid Build Coastguard Worker``@__stack_chk_guard``. The second variable is an ``alloca`` that has 12120*9880d681SAndroid Build Coastguard Workerenough space to hold the value of the guard. 12121*9880d681SAndroid Build Coastguard Worker 12122*9880d681SAndroid Build Coastguard WorkerSemantics: 12123*9880d681SAndroid Build Coastguard Worker"""""""""" 12124*9880d681SAndroid Build Coastguard Worker 12125*9880d681SAndroid Build Coastguard WorkerThis intrinsic causes the prologue/epilogue inserter to force the position of 12126*9880d681SAndroid Build Coastguard Workerthe ``AllocaInst`` stack slot to be before local variables on the stack. This is 12127*9880d681SAndroid Build Coastguard Workerto ensure that if a local variable on the stack is overwritten, it will destroy 12128*9880d681SAndroid Build Coastguard Workerthe value of the guard. When the function exits, the guard on the stack is 12129*9880d681SAndroid Build Coastguard Workerchecked against the original guard by ``llvm.stackprotectorcheck``. If they are 12130*9880d681SAndroid Build Coastguard Workerdifferent, then ``llvm.stackprotectorcheck`` causes the program to abort by 12131*9880d681SAndroid Build Coastguard Workercalling the ``__stack_chk_fail()`` function. 12132*9880d681SAndroid Build Coastguard Worker 12133*9880d681SAndroid Build Coastguard Worker'``llvm.stackguard``' Intrinsic 12134*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12135*9880d681SAndroid Build Coastguard Worker 12136*9880d681SAndroid Build Coastguard WorkerSyntax: 12137*9880d681SAndroid Build Coastguard Worker""""""" 12138*9880d681SAndroid Build Coastguard Worker 12139*9880d681SAndroid Build Coastguard Worker:: 12140*9880d681SAndroid Build Coastguard Worker 12141*9880d681SAndroid Build Coastguard Worker declare i8* @llvm.stackguard() 12142*9880d681SAndroid Build Coastguard Worker 12143*9880d681SAndroid Build Coastguard WorkerOverview: 12144*9880d681SAndroid Build Coastguard Worker""""""""" 12145*9880d681SAndroid Build Coastguard Worker 12146*9880d681SAndroid Build Coastguard WorkerThe ``llvm.stackguard`` intrinsic returns the system stack guard value. 12147*9880d681SAndroid Build Coastguard Worker 12148*9880d681SAndroid Build Coastguard WorkerIt should not be generated by frontends, since it is only for internal usage. 12149*9880d681SAndroid Build Coastguard WorkerThe reason why we create this intrinsic is that we still support IR form Stack 12150*9880d681SAndroid Build Coastguard WorkerProtector in FastISel. 12151*9880d681SAndroid Build Coastguard Worker 12152*9880d681SAndroid Build Coastguard WorkerArguments: 12153*9880d681SAndroid Build Coastguard Worker"""""""""" 12154*9880d681SAndroid Build Coastguard Worker 12155*9880d681SAndroid Build Coastguard WorkerNone. 12156*9880d681SAndroid Build Coastguard Worker 12157*9880d681SAndroid Build Coastguard WorkerSemantics: 12158*9880d681SAndroid Build Coastguard Worker"""""""""" 12159*9880d681SAndroid Build Coastguard Worker 12160*9880d681SAndroid Build Coastguard WorkerOn some platforms, the value returned by this intrinsic remains unchanged 12161*9880d681SAndroid Build Coastguard Workerbetween loads in the same thread. On other platforms, it returns the same 12162*9880d681SAndroid Build Coastguard Workerglobal variable value, if any, e.g. ``@__stack_chk_guard``. 12163*9880d681SAndroid Build Coastguard Worker 12164*9880d681SAndroid Build Coastguard WorkerCurrently some platforms have IR-level customized stack guard loading (e.g. 12165*9880d681SAndroid Build Coastguard WorkerX86 Linux) that is not handled by ``llvm.stackguard()``, while they should be 12166*9880d681SAndroid Build Coastguard Workerin the future. 12167*9880d681SAndroid Build Coastguard Worker 12168*9880d681SAndroid Build Coastguard Worker'``llvm.objectsize``' Intrinsic 12169*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12170*9880d681SAndroid Build Coastguard Worker 12171*9880d681SAndroid Build Coastguard WorkerSyntax: 12172*9880d681SAndroid Build Coastguard Worker""""""" 12173*9880d681SAndroid Build Coastguard Worker 12174*9880d681SAndroid Build Coastguard Worker:: 12175*9880d681SAndroid Build Coastguard Worker 12176*9880d681SAndroid Build Coastguard Worker declare i32 @llvm.objectsize.i32(i8* <object>, i1 <min>) 12177*9880d681SAndroid Build Coastguard Worker declare i64 @llvm.objectsize.i64(i8* <object>, i1 <min>) 12178*9880d681SAndroid Build Coastguard Worker 12179*9880d681SAndroid Build Coastguard WorkerOverview: 12180*9880d681SAndroid Build Coastguard Worker""""""""" 12181*9880d681SAndroid Build Coastguard Worker 12182*9880d681SAndroid Build Coastguard WorkerThe ``llvm.objectsize`` intrinsic is designed to provide information to 12183*9880d681SAndroid Build Coastguard Workerthe optimizers to determine at compile time whether a) an operation 12184*9880d681SAndroid Build Coastguard Worker(like memcpy) will overflow a buffer that corresponds to an object, or 12185*9880d681SAndroid Build Coastguard Workerb) that a runtime check for overflow isn't necessary. An object in this 12186*9880d681SAndroid Build Coastguard Workercontext means an allocation of a specific class, structure, array, or 12187*9880d681SAndroid Build Coastguard Workerother object. 12188*9880d681SAndroid Build Coastguard Worker 12189*9880d681SAndroid Build Coastguard WorkerArguments: 12190*9880d681SAndroid Build Coastguard Worker"""""""""" 12191*9880d681SAndroid Build Coastguard Worker 12192*9880d681SAndroid Build Coastguard WorkerThe ``llvm.objectsize`` intrinsic takes two arguments. The first 12193*9880d681SAndroid Build Coastguard Workerargument is a pointer to or into the ``object``. The second argument is 12194*9880d681SAndroid Build Coastguard Workera boolean and determines whether ``llvm.objectsize`` returns 0 (if true) 12195*9880d681SAndroid Build Coastguard Workeror -1 (if false) when the object size is unknown. The second argument 12196*9880d681SAndroid Build Coastguard Workeronly accepts constants. 12197*9880d681SAndroid Build Coastguard Worker 12198*9880d681SAndroid Build Coastguard WorkerSemantics: 12199*9880d681SAndroid Build Coastguard Worker"""""""""" 12200*9880d681SAndroid Build Coastguard Worker 12201*9880d681SAndroid Build Coastguard WorkerThe ``llvm.objectsize`` intrinsic is lowered to a constant representing 12202*9880d681SAndroid Build Coastguard Workerthe size of the object concerned. If the size cannot be determined at 12203*9880d681SAndroid Build Coastguard Workercompile time, ``llvm.objectsize`` returns ``i32/i64 -1 or 0`` (depending 12204*9880d681SAndroid Build Coastguard Workeron the ``min`` argument). 12205*9880d681SAndroid Build Coastguard Worker 12206*9880d681SAndroid Build Coastguard Worker'``llvm.expect``' Intrinsic 12207*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12208*9880d681SAndroid Build Coastguard Worker 12209*9880d681SAndroid Build Coastguard WorkerSyntax: 12210*9880d681SAndroid Build Coastguard Worker""""""" 12211*9880d681SAndroid Build Coastguard Worker 12212*9880d681SAndroid Build Coastguard WorkerThis is an overloaded intrinsic. You can use ``llvm.expect`` on any 12213*9880d681SAndroid Build Coastguard Workerinteger bit width. 12214*9880d681SAndroid Build Coastguard Worker 12215*9880d681SAndroid Build Coastguard Worker:: 12216*9880d681SAndroid Build Coastguard Worker 12217*9880d681SAndroid Build Coastguard Worker declare i1 @llvm.expect.i1(i1 <val>, i1 <expected_val>) 12218*9880d681SAndroid Build Coastguard Worker declare i32 @llvm.expect.i32(i32 <val>, i32 <expected_val>) 12219*9880d681SAndroid Build Coastguard Worker declare i64 @llvm.expect.i64(i64 <val>, i64 <expected_val>) 12220*9880d681SAndroid Build Coastguard Worker 12221*9880d681SAndroid Build Coastguard WorkerOverview: 12222*9880d681SAndroid Build Coastguard Worker""""""""" 12223*9880d681SAndroid Build Coastguard Worker 12224*9880d681SAndroid Build Coastguard WorkerThe ``llvm.expect`` intrinsic provides information about expected (the 12225*9880d681SAndroid Build Coastguard Workermost probable) value of ``val``, which can be used by optimizers. 12226*9880d681SAndroid Build Coastguard Worker 12227*9880d681SAndroid Build Coastguard WorkerArguments: 12228*9880d681SAndroid Build Coastguard Worker"""""""""" 12229*9880d681SAndroid Build Coastguard Worker 12230*9880d681SAndroid Build Coastguard WorkerThe ``llvm.expect`` intrinsic takes two arguments. The first argument is 12231*9880d681SAndroid Build Coastguard Workera value. The second argument is an expected value, this needs to be a 12232*9880d681SAndroid Build Coastguard Workerconstant value, variables are not allowed. 12233*9880d681SAndroid Build Coastguard Worker 12234*9880d681SAndroid Build Coastguard WorkerSemantics: 12235*9880d681SAndroid Build Coastguard Worker"""""""""" 12236*9880d681SAndroid Build Coastguard Worker 12237*9880d681SAndroid Build Coastguard WorkerThis intrinsic is lowered to the ``val``. 12238*9880d681SAndroid Build Coastguard Worker 12239*9880d681SAndroid Build Coastguard Worker.. _int_assume: 12240*9880d681SAndroid Build Coastguard Worker 12241*9880d681SAndroid Build Coastguard Worker'``llvm.assume``' Intrinsic 12242*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12243*9880d681SAndroid Build Coastguard Worker 12244*9880d681SAndroid Build Coastguard WorkerSyntax: 12245*9880d681SAndroid Build Coastguard Worker""""""" 12246*9880d681SAndroid Build Coastguard Worker 12247*9880d681SAndroid Build Coastguard Worker:: 12248*9880d681SAndroid Build Coastguard Worker 12249*9880d681SAndroid Build Coastguard Worker declare void @llvm.assume(i1 %cond) 12250*9880d681SAndroid Build Coastguard Worker 12251*9880d681SAndroid Build Coastguard WorkerOverview: 12252*9880d681SAndroid Build Coastguard Worker""""""""" 12253*9880d681SAndroid Build Coastguard Worker 12254*9880d681SAndroid Build Coastguard WorkerThe ``llvm.assume`` allows the optimizer to assume that the provided 12255*9880d681SAndroid Build Coastguard Workercondition is true. This information can then be used in simplifying other parts 12256*9880d681SAndroid Build Coastguard Workerof the code. 12257*9880d681SAndroid Build Coastguard Worker 12258*9880d681SAndroid Build Coastguard WorkerArguments: 12259*9880d681SAndroid Build Coastguard Worker"""""""""" 12260*9880d681SAndroid Build Coastguard Worker 12261*9880d681SAndroid Build Coastguard WorkerThe condition which the optimizer may assume is always true. 12262*9880d681SAndroid Build Coastguard Worker 12263*9880d681SAndroid Build Coastguard WorkerSemantics: 12264*9880d681SAndroid Build Coastguard Worker"""""""""" 12265*9880d681SAndroid Build Coastguard Worker 12266*9880d681SAndroid Build Coastguard WorkerThe intrinsic allows the optimizer to assume that the provided condition is 12267*9880d681SAndroid Build Coastguard Workeralways true whenever the control flow reaches the intrinsic call. No code is 12268*9880d681SAndroid Build Coastguard Workergenerated for this intrinsic, and instructions that contribute only to the 12269*9880d681SAndroid Build Coastguard Workerprovided condition are not used for code generation. If the condition is 12270*9880d681SAndroid Build Coastguard Workerviolated during execution, the behavior is undefined. 12271*9880d681SAndroid Build Coastguard Worker 12272*9880d681SAndroid Build Coastguard WorkerNote that the optimizer might limit the transformations performed on values 12273*9880d681SAndroid Build Coastguard Workerused by the ``llvm.assume`` intrinsic in order to preserve the instructions 12274*9880d681SAndroid Build Coastguard Workeronly used to form the intrinsic's input argument. This might prove undesirable 12275*9880d681SAndroid Build Coastguard Workerif the extra information provided by the ``llvm.assume`` intrinsic does not cause 12276*9880d681SAndroid Build Coastguard Workersufficient overall improvement in code quality. For this reason, 12277*9880d681SAndroid Build Coastguard Worker``llvm.assume`` should not be used to document basic mathematical invariants 12278*9880d681SAndroid Build Coastguard Workerthat the optimizer can otherwise deduce or facts that are of little use to the 12279*9880d681SAndroid Build Coastguard Workeroptimizer. 12280*9880d681SAndroid Build Coastguard Worker 12281*9880d681SAndroid Build Coastguard Worker.. _type.test: 12282*9880d681SAndroid Build Coastguard Worker 12283*9880d681SAndroid Build Coastguard Worker'``llvm.type.test``' Intrinsic 12284*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12285*9880d681SAndroid Build Coastguard Worker 12286*9880d681SAndroid Build Coastguard WorkerSyntax: 12287*9880d681SAndroid Build Coastguard Worker""""""" 12288*9880d681SAndroid Build Coastguard Worker 12289*9880d681SAndroid Build Coastguard Worker:: 12290*9880d681SAndroid Build Coastguard Worker 12291*9880d681SAndroid Build Coastguard Worker declare i1 @llvm.type.test(i8* %ptr, metadata %type) nounwind readnone 12292*9880d681SAndroid Build Coastguard Worker 12293*9880d681SAndroid Build Coastguard Worker 12294*9880d681SAndroid Build Coastguard WorkerArguments: 12295*9880d681SAndroid Build Coastguard Worker"""""""""" 12296*9880d681SAndroid Build Coastguard Worker 12297*9880d681SAndroid Build Coastguard WorkerThe first argument is a pointer to be tested. The second argument is a 12298*9880d681SAndroid Build Coastguard Workermetadata object representing a :doc:`type identifier <TypeMetadata>`. 12299*9880d681SAndroid Build Coastguard Worker 12300*9880d681SAndroid Build Coastguard WorkerOverview: 12301*9880d681SAndroid Build Coastguard Worker""""""""" 12302*9880d681SAndroid Build Coastguard Worker 12303*9880d681SAndroid Build Coastguard WorkerThe ``llvm.type.test`` intrinsic tests whether the given pointer is associated 12304*9880d681SAndroid Build Coastguard Workerwith the given type identifier. 12305*9880d681SAndroid Build Coastguard Worker 12306*9880d681SAndroid Build Coastguard Worker'``llvm.type.checked.load``' Intrinsic 12307*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12308*9880d681SAndroid Build Coastguard Worker 12309*9880d681SAndroid Build Coastguard WorkerSyntax: 12310*9880d681SAndroid Build Coastguard Worker""""""" 12311*9880d681SAndroid Build Coastguard Worker 12312*9880d681SAndroid Build Coastguard Worker:: 12313*9880d681SAndroid Build Coastguard Worker 12314*9880d681SAndroid Build Coastguard Worker declare {i8*, i1} @llvm.type.checked.load(i8* %ptr, i32 %offset, metadata %type) argmemonly nounwind readonly 12315*9880d681SAndroid Build Coastguard Worker 12316*9880d681SAndroid Build Coastguard Worker 12317*9880d681SAndroid Build Coastguard WorkerArguments: 12318*9880d681SAndroid Build Coastguard Worker"""""""""" 12319*9880d681SAndroid Build Coastguard Worker 12320*9880d681SAndroid Build Coastguard WorkerThe first argument is a pointer from which to load a function pointer. The 12321*9880d681SAndroid Build Coastguard Workersecond argument is the byte offset from which to load the function pointer. The 12322*9880d681SAndroid Build Coastguard Workerthird argument is a metadata object representing a :doc:`type identifier 12323*9880d681SAndroid Build Coastguard Worker<TypeMetadata>`. 12324*9880d681SAndroid Build Coastguard Worker 12325*9880d681SAndroid Build Coastguard WorkerOverview: 12326*9880d681SAndroid Build Coastguard Worker""""""""" 12327*9880d681SAndroid Build Coastguard Worker 12328*9880d681SAndroid Build Coastguard WorkerThe ``llvm.type.checked.load`` intrinsic safely loads a function pointer from a 12329*9880d681SAndroid Build Coastguard Workervirtual table pointer using type metadata. This intrinsic is used to implement 12330*9880d681SAndroid Build Coastguard Workercontrol flow integrity in conjunction with virtual call optimization. The 12331*9880d681SAndroid Build Coastguard Workervirtual call optimization pass will optimize away ``llvm.type.checked.load`` 12332*9880d681SAndroid Build Coastguard Workerintrinsics associated with devirtualized calls, thereby removing the type 12333*9880d681SAndroid Build Coastguard Workercheck in cases where it is not needed to enforce the control flow integrity 12334*9880d681SAndroid Build Coastguard Workerconstraint. 12335*9880d681SAndroid Build Coastguard Worker 12336*9880d681SAndroid Build Coastguard WorkerIf the given pointer is associated with a type metadata identifier, this 12337*9880d681SAndroid Build Coastguard Workerfunction returns true as the second element of its return value. (Note that 12338*9880d681SAndroid Build Coastguard Workerthe function may also return true if the given pointer is not associated 12339*9880d681SAndroid Build Coastguard Workerwith a type metadata identifier.) If the function's return value's second 12340*9880d681SAndroid Build Coastguard Workerelement is true, the following rules apply to the first element: 12341*9880d681SAndroid Build Coastguard Worker 12342*9880d681SAndroid Build Coastguard Worker- If the given pointer is associated with the given type metadata identifier, 12343*9880d681SAndroid Build Coastguard Worker it is the function pointer loaded from the given byte offset from the given 12344*9880d681SAndroid Build Coastguard Worker pointer. 12345*9880d681SAndroid Build Coastguard Worker 12346*9880d681SAndroid Build Coastguard Worker- If the given pointer is not associated with the given type metadata 12347*9880d681SAndroid Build Coastguard Worker identifier, it is one of the following (the choice of which is unspecified): 12348*9880d681SAndroid Build Coastguard Worker 12349*9880d681SAndroid Build Coastguard Worker 1. The function pointer that would have been loaded from an arbitrarily chosen 12350*9880d681SAndroid Build Coastguard Worker (through an unspecified mechanism) pointer associated with the type 12351*9880d681SAndroid Build Coastguard Worker metadata. 12352*9880d681SAndroid Build Coastguard Worker 12353*9880d681SAndroid Build Coastguard Worker 2. If the function has a non-void return type, a pointer to a function that 12354*9880d681SAndroid Build Coastguard Worker returns an unspecified value without causing side effects. 12355*9880d681SAndroid Build Coastguard Worker 12356*9880d681SAndroid Build Coastguard WorkerIf the function's return value's second element is false, the value of the 12357*9880d681SAndroid Build Coastguard Workerfirst element is undefined. 12358*9880d681SAndroid Build Coastguard Worker 12359*9880d681SAndroid Build Coastguard Worker 12360*9880d681SAndroid Build Coastguard Worker'``llvm.donothing``' Intrinsic 12361*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12362*9880d681SAndroid Build Coastguard Worker 12363*9880d681SAndroid Build Coastguard WorkerSyntax: 12364*9880d681SAndroid Build Coastguard Worker""""""" 12365*9880d681SAndroid Build Coastguard Worker 12366*9880d681SAndroid Build Coastguard Worker:: 12367*9880d681SAndroid Build Coastguard Worker 12368*9880d681SAndroid Build Coastguard Worker declare void @llvm.donothing() nounwind readnone 12369*9880d681SAndroid Build Coastguard Worker 12370*9880d681SAndroid Build Coastguard WorkerOverview: 12371*9880d681SAndroid Build Coastguard Worker""""""""" 12372*9880d681SAndroid Build Coastguard Worker 12373*9880d681SAndroid Build Coastguard WorkerThe ``llvm.donothing`` intrinsic doesn't perform any operation. It's one of only 12374*9880d681SAndroid Build Coastguard Workerthree intrinsics (besides ``llvm.experimental.patchpoint`` and 12375*9880d681SAndroid Build Coastguard Worker``llvm.experimental.gc.statepoint``) that can be called with an invoke 12376*9880d681SAndroid Build Coastguard Workerinstruction. 12377*9880d681SAndroid Build Coastguard Worker 12378*9880d681SAndroid Build Coastguard WorkerArguments: 12379*9880d681SAndroid Build Coastguard Worker"""""""""" 12380*9880d681SAndroid Build Coastguard Worker 12381*9880d681SAndroid Build Coastguard WorkerNone. 12382*9880d681SAndroid Build Coastguard Worker 12383*9880d681SAndroid Build Coastguard WorkerSemantics: 12384*9880d681SAndroid Build Coastguard Worker"""""""""" 12385*9880d681SAndroid Build Coastguard Worker 12386*9880d681SAndroid Build Coastguard WorkerThis intrinsic does nothing, and it's removed by optimizers and ignored 12387*9880d681SAndroid Build Coastguard Workerby codegen. 12388*9880d681SAndroid Build Coastguard Worker 12389*9880d681SAndroid Build Coastguard Worker'``llvm.experimental.deoptimize``' Intrinsic 12390*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12391*9880d681SAndroid Build Coastguard Worker 12392*9880d681SAndroid Build Coastguard WorkerSyntax: 12393*9880d681SAndroid Build Coastguard Worker""""""" 12394*9880d681SAndroid Build Coastguard Worker 12395*9880d681SAndroid Build Coastguard Worker:: 12396*9880d681SAndroid Build Coastguard Worker 12397*9880d681SAndroid Build Coastguard Worker declare type @llvm.experimental.deoptimize(...) [ "deopt"(...) ] 12398*9880d681SAndroid Build Coastguard Worker 12399*9880d681SAndroid Build Coastguard WorkerOverview: 12400*9880d681SAndroid Build Coastguard Worker""""""""" 12401*9880d681SAndroid Build Coastguard Worker 12402*9880d681SAndroid Build Coastguard WorkerThis intrinsic, together with :ref:`deoptimization operand bundles 12403*9880d681SAndroid Build Coastguard Worker<deopt_opbundles>`, allow frontends to express transfer of control and 12404*9880d681SAndroid Build Coastguard Workerframe-local state from the currently executing (typically more specialized, 12405*9880d681SAndroid Build Coastguard Workerhence faster) version of a function into another (typically more generic, hence 12406*9880d681SAndroid Build Coastguard Workerslower) version. 12407*9880d681SAndroid Build Coastguard Worker 12408*9880d681SAndroid Build Coastguard WorkerIn languages with a fully integrated managed runtime like Java and JavaScript 12409*9880d681SAndroid Build Coastguard Workerthis intrinsic can be used to implement "uncommon trap" or "side exit" like 12410*9880d681SAndroid Build Coastguard Workerfunctionality. In unmanaged languages like C and C++, this intrinsic can be 12411*9880d681SAndroid Build Coastguard Workerused to represent the slow paths of specialized functions. 12412*9880d681SAndroid Build Coastguard Worker 12413*9880d681SAndroid Build Coastguard Worker 12414*9880d681SAndroid Build Coastguard WorkerArguments: 12415*9880d681SAndroid Build Coastguard Worker"""""""""" 12416*9880d681SAndroid Build Coastguard Worker 12417*9880d681SAndroid Build Coastguard WorkerThe intrinsic takes an arbitrary number of arguments, whose meaning is 12418*9880d681SAndroid Build Coastguard Workerdecided by the :ref:`lowering strategy<deoptimize_lowering>`. 12419*9880d681SAndroid Build Coastguard Worker 12420*9880d681SAndroid Build Coastguard WorkerSemantics: 12421*9880d681SAndroid Build Coastguard Worker"""""""""" 12422*9880d681SAndroid Build Coastguard Worker 12423*9880d681SAndroid Build Coastguard WorkerThe ``@llvm.experimental.deoptimize`` intrinsic executes an attached 12424*9880d681SAndroid Build Coastguard Workerdeoptimization continuation (denoted using a :ref:`deoptimization 12425*9880d681SAndroid Build Coastguard Workeroperand bundle <deopt_opbundles>`) and returns the value returned by 12426*9880d681SAndroid Build Coastguard Workerthe deoptimization continuation. Defining the semantic properties of 12427*9880d681SAndroid Build Coastguard Workerthe continuation itself is out of scope of the language reference -- 12428*9880d681SAndroid Build Coastguard Workeras far as LLVM is concerned, the deoptimization continuation can 12429*9880d681SAndroid Build Coastguard Workerinvoke arbitrary side effects, including reading from and writing to 12430*9880d681SAndroid Build Coastguard Workerthe entire heap. 12431*9880d681SAndroid Build Coastguard Worker 12432*9880d681SAndroid Build Coastguard WorkerDeoptimization continuations expressed using ``"deopt"`` operand bundles always 12433*9880d681SAndroid Build Coastguard Workercontinue execution to the end of the physical frame containing them, so all 12434*9880d681SAndroid Build Coastguard Workercalls to ``@llvm.experimental.deoptimize`` must be in "tail position": 12435*9880d681SAndroid Build Coastguard Worker 12436*9880d681SAndroid Build Coastguard Worker - ``@llvm.experimental.deoptimize`` cannot be invoked. 12437*9880d681SAndroid Build Coastguard Worker - The call must immediately precede a :ref:`ret <i_ret>` instruction. 12438*9880d681SAndroid Build Coastguard Worker - The ``ret`` instruction must return the value produced by the 12439*9880d681SAndroid Build Coastguard Worker ``@llvm.experimental.deoptimize`` call if there is one, or void. 12440*9880d681SAndroid Build Coastguard Worker 12441*9880d681SAndroid Build Coastguard WorkerNote that the above restrictions imply that the return type for a call to 12442*9880d681SAndroid Build Coastguard Worker``@llvm.experimental.deoptimize`` will match the return type of its immediate 12443*9880d681SAndroid Build Coastguard Workercaller. 12444*9880d681SAndroid Build Coastguard Worker 12445*9880d681SAndroid Build Coastguard WorkerThe inliner composes the ``"deopt"`` continuations of the caller into the 12446*9880d681SAndroid Build Coastguard Worker``"deopt"`` continuations present in the inlinee, and also updates calls to this 12447*9880d681SAndroid Build Coastguard Workerintrinsic to return directly from the frame of the function it inlined into. 12448*9880d681SAndroid Build Coastguard Worker 12449*9880d681SAndroid Build Coastguard WorkerAll declarations of ``@llvm.experimental.deoptimize`` must share the 12450*9880d681SAndroid Build Coastguard Workersame calling convention. 12451*9880d681SAndroid Build Coastguard Worker 12452*9880d681SAndroid Build Coastguard Worker.. _deoptimize_lowering: 12453*9880d681SAndroid Build Coastguard Worker 12454*9880d681SAndroid Build Coastguard WorkerLowering: 12455*9880d681SAndroid Build Coastguard Worker""""""""" 12456*9880d681SAndroid Build Coastguard Worker 12457*9880d681SAndroid Build Coastguard WorkerCalls to ``@llvm.experimental.deoptimize`` are lowered to calls to the 12458*9880d681SAndroid Build Coastguard Workersymbol ``__llvm_deoptimize`` (it is the frontend's responsibility to 12459*9880d681SAndroid Build Coastguard Workerensure that this symbol is defined). The call arguments to 12460*9880d681SAndroid Build Coastguard Worker``@llvm.experimental.deoptimize`` are lowered as if they were formal 12461*9880d681SAndroid Build Coastguard Workerarguments of the specified types, and not as varargs. 12462*9880d681SAndroid Build Coastguard Worker 12463*9880d681SAndroid Build Coastguard Worker 12464*9880d681SAndroid Build Coastguard Worker'``llvm.experimental.guard``' Intrinsic 12465*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12466*9880d681SAndroid Build Coastguard Worker 12467*9880d681SAndroid Build Coastguard WorkerSyntax: 12468*9880d681SAndroid Build Coastguard Worker""""""" 12469*9880d681SAndroid Build Coastguard Worker 12470*9880d681SAndroid Build Coastguard Worker:: 12471*9880d681SAndroid Build Coastguard Worker 12472*9880d681SAndroid Build Coastguard Worker declare void @llvm.experimental.guard(i1, ...) [ "deopt"(...) ] 12473*9880d681SAndroid Build Coastguard Worker 12474*9880d681SAndroid Build Coastguard WorkerOverview: 12475*9880d681SAndroid Build Coastguard Worker""""""""" 12476*9880d681SAndroid Build Coastguard Worker 12477*9880d681SAndroid Build Coastguard WorkerThis intrinsic, together with :ref:`deoptimization operand bundles 12478*9880d681SAndroid Build Coastguard Worker<deopt_opbundles>`, allows frontends to express guards or checks on 12479*9880d681SAndroid Build Coastguard Workeroptimistic assumptions made during compilation. The semantics of 12480*9880d681SAndroid Build Coastguard Worker``@llvm.experimental.guard`` is defined in terms of 12481*9880d681SAndroid Build Coastguard Worker``@llvm.experimental.deoptimize`` -- its body is defined to be 12482*9880d681SAndroid Build Coastguard Workerequivalent to: 12483*9880d681SAndroid Build Coastguard Worker 12484*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm 12485*9880d681SAndroid Build Coastguard Worker 12486*9880d681SAndroid Build Coastguard Worker define void @llvm.experimental.guard(i1 %pred, <args...>) { 12487*9880d681SAndroid Build Coastguard Worker %realPred = and i1 %pred, undef 12488*9880d681SAndroid Build Coastguard Worker br i1 %realPred, label %continue, label %leave [, !make.implicit !{}] 12489*9880d681SAndroid Build Coastguard Worker 12490*9880d681SAndroid Build Coastguard Worker leave: 12491*9880d681SAndroid Build Coastguard Worker call void @llvm.experimental.deoptimize(<args...>) [ "deopt"() ] 12492*9880d681SAndroid Build Coastguard Worker ret void 12493*9880d681SAndroid Build Coastguard Worker 12494*9880d681SAndroid Build Coastguard Worker continue: 12495*9880d681SAndroid Build Coastguard Worker ret void 12496*9880d681SAndroid Build Coastguard Worker } 12497*9880d681SAndroid Build Coastguard Worker 12498*9880d681SAndroid Build Coastguard Worker 12499*9880d681SAndroid Build Coastguard Workerwith the optional ``[, !make.implicit !{}]`` present if and only if it 12500*9880d681SAndroid Build Coastguard Workeris present on the call site. For more details on ``!make.implicit``, 12501*9880d681SAndroid Build Coastguard Workersee :doc:`FaultMaps`. 12502*9880d681SAndroid Build Coastguard Worker 12503*9880d681SAndroid Build Coastguard WorkerIn words, ``@llvm.experimental.guard`` executes the attached 12504*9880d681SAndroid Build Coastguard Worker``"deopt"`` continuation if (but **not** only if) its first argument 12505*9880d681SAndroid Build Coastguard Workeris ``false``. Since the optimizer is allowed to replace the ``undef`` 12506*9880d681SAndroid Build Coastguard Workerwith an arbitrary value, it can optimize guard to fail "spuriously", 12507*9880d681SAndroid Build Coastguard Workeri.e. without the original condition being false (hence the "not only 12508*9880d681SAndroid Build Coastguard Workerif"); and this allows for "check widening" type optimizations. 12509*9880d681SAndroid Build Coastguard Worker 12510*9880d681SAndroid Build Coastguard Worker``@llvm.experimental.guard`` cannot be invoked. 12511*9880d681SAndroid Build Coastguard Worker 12512*9880d681SAndroid Build Coastguard Worker 12513*9880d681SAndroid Build Coastguard Worker'``llvm.load.relative``' Intrinsic 12514*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12515*9880d681SAndroid Build Coastguard Worker 12516*9880d681SAndroid Build Coastguard WorkerSyntax: 12517*9880d681SAndroid Build Coastguard Worker""""""" 12518*9880d681SAndroid Build Coastguard Worker 12519*9880d681SAndroid Build Coastguard Worker:: 12520*9880d681SAndroid Build Coastguard Worker 12521*9880d681SAndroid Build Coastguard Worker declare i8* @llvm.load.relative.iN(i8* %ptr, iN %offset) argmemonly nounwind readonly 12522*9880d681SAndroid Build Coastguard Worker 12523*9880d681SAndroid Build Coastguard WorkerOverview: 12524*9880d681SAndroid Build Coastguard Worker""""""""" 12525*9880d681SAndroid Build Coastguard Worker 12526*9880d681SAndroid Build Coastguard WorkerThis intrinsic loads a 32-bit value from the address ``%ptr + %offset``, 12527*9880d681SAndroid Build Coastguard Workeradds ``%ptr`` to that value and returns it. The constant folder specifically 12528*9880d681SAndroid Build Coastguard Workerrecognizes the form of this intrinsic and the constant initializers it may 12529*9880d681SAndroid Build Coastguard Workerload from; if a loaded constant initializer is known to have the form 12530*9880d681SAndroid Build Coastguard Worker``i32 trunc(x - %ptr)``, the intrinsic call is folded to ``x``. 12531*9880d681SAndroid Build Coastguard Worker 12532*9880d681SAndroid Build Coastguard WorkerLLVM provides that the calculation of such a constant initializer will 12533*9880d681SAndroid Build Coastguard Workernot overflow at link time under the medium code model if ``x`` is an 12534*9880d681SAndroid Build Coastguard Worker``unnamed_addr`` function. However, it does not provide this guarantee for 12535*9880d681SAndroid Build Coastguard Workera constant initializer folded into a function body. This intrinsic can be 12536*9880d681SAndroid Build Coastguard Workerused to avoid the possibility of overflows when loading from such a constant. 12537*9880d681SAndroid Build Coastguard Worker 12538*9880d681SAndroid Build Coastguard WorkerStack Map Intrinsics 12539*9880d681SAndroid Build Coastguard Worker-------------------- 12540*9880d681SAndroid Build Coastguard Worker 12541*9880d681SAndroid Build Coastguard WorkerLLVM provides experimental intrinsics to support runtime patching 12542*9880d681SAndroid Build Coastguard Workermechanisms commonly desired in dynamic language JITs. These intrinsics 12543*9880d681SAndroid Build Coastguard Workerare described in :doc:`StackMaps`. 12544