OLD | NEW |
(Empty) | |
| 1 =============================== |
| 2 Contents Of PNaCl Bitcode Files |
| 3 =============================== |
| 4 |
| 5 .. contents:: |
| 6 :local: |
| 7 :backlinks: none |
| 8 :depth: 3 |
| 9 |
| 10 |
| 11 Introduction |
| 12 ============ |
| 13 |
| 14 This document is a reference manual for the contents of PNaCl bitcode files. We |
| 15 define bitcode files via three layers. The first layer is presented using |
| 16 assembly language *PNaClAsm*, and defines the textual form of the bitcode |
| 17 file. The textual form is then lowered to a sequence of :ref:`PNaCl |
| 18 records<link_for_pnacl_records>`. The final layer applies abbreviations that |
| 19 convert each PNaCl record into a corresponding sequence of bits. |
| 20 |
| 21 .. image:: /images/PNaClBitcodeFlow.png |
| 22 |
| 23 PNaClAsm uses a *static single assignment* (SSA) based representation that |
| 24 requires generated results to have a single (assignment) source. |
| 25 |
| 26 PNaClAsm focuses on the semantic content of the file, not the bit-encoding of |
| 27 that content. However, it does provide annotations that allow one to specify how |
| 28 the :ref:`abbreviations<link_for_abbreviations_section>` are used to convert |
| 29 PNaCl records into the sequence of bits. |
| 30 |
| 31 Each construct in PNaClAsm defines a corresponding :ref:`PNaCl |
| 32 record<link_for_pnacl_records>`. A PNaCl bitcode file is simply a sequence of |
| 33 PNaCl records. The goal of PNaClAsm is to make records easier to read, and not |
| 34 to define a high-level user programming language. |
| 35 |
| 36 PNaCl records are an abstract encoding of structured data, similar to XML. Like |
| 37 XML, A PNaCl record has a notion of a tag (i.e. the first element in a record, |
| 38 called a *code*). PNaCl records can be nested. Nesting is defined by a |
| 39 corresponding :ref:`enter<link_for_enter_block_record_section>` and |
| 40 :ref:`exit<link_for_exit_block_record_section>` block record. |
| 41 |
| 42 These block records must be used like balanced parentheses to define the block |
| 43 structure that is imposed on top of records. Each exit record must be preceded |
| 44 by a corresponding enter record. Blocks can be nested by nesting enter/exit |
| 45 records appropriately. |
| 46 |
| 47 The *PNaCl bitcode writer* takes the sequence of records, defined by a PNaClAsm |
| 48 program, and converts each record into a (variable-length) sequence of bits. The |
| 49 output of each bit sequence is appended together. The resulting generated |
| 50 sequence of bits is the contents of the PNaCl bitcode file. |
| 51 |
| 52 For every kind of record, there is a method for converting records into bit |
| 53 sequences. These methods correspond to a notion of |
| 54 :ref:`abbreviations<link_for_abbreviations_section>`. Each abbreviation defines |
| 55 a specific bit sequence conversion to be applied. |
| 56 |
| 57 Abbreviations can be user-defined, but there are also predefined defaults. All |
| 58 user-specified abbreviations are included in the generated bitcode |
| 59 file. Predefined defaults are not. |
| 60 |
| 61 Each abbreviation defines how a record is converted to a bit sequence. The |
| 62 :ref:`PNaCl translator<link_for_pnacl_translator>` uses these abbreviations |
| 63 to convert the bit sequence back to the corresponding sequence of PNaCl records. |
| 64 As a result, all records have an abbreviation (user or default) associated with |
| 65 them. |
| 66 |
| 67 Conceptually, abbreviations are used to define how to pack the contents of |
| 68 records into bit sequences. The main reason for defining abbreviations is to |
| 69 save space. The default abbreviations are simplistic and are intended to handle |
| 70 all possible records. The default abbreviations do not really worry about being |
| 71 efficient, in terms of the number of bits generated. |
| 72 |
| 73 By separating the concepts of PNaCl records and abbreviations, the notion of |
| 74 data compression is cleanly separated from semantic content. This allows |
| 75 different use cases to decide how much effort should be spent on compressing |
| 76 records. |
| 77 |
| 78 For a JIT compiler that produces bitcode, little (if any) compression should be |
| 79 applied. In fact, the API to the JIT may just be the records themselves. The |
| 80 goal of a JIT is to perform the final translation to machine code as quickly as |
| 81 possible. |
| 82 |
| 83 On the other hand, when delivering across the web, one may want to compress the |
| 84 sequence of bits considerably, to reduce costs in delivering web pages. Note |
| 85 that :ref:`pnacl-compress<pnacl_compress>` is provided as part of the SDK to do |
| 86 this job. |
| 87 |
| 88 Data Model |
| 89 ========== |
| 90 |
| 91 The data model for PNaCl bitcode is fixed at little-endian ILP32: pointers are |
| 92 32 bits in size. 64-bit integer types are also supported natively via the i64 |
| 93 type (for example, a front-end can generate these from the C/C++ type ``long |
| 94 long``). |
| 95 |
| 96 Integers are assumed to be modeled using two's complement. Floating point |
| 97 support is fixed at :ref:`IEEE 754<c_cpp_floating_point>` 32-bit and 64-bit |
| 98 values (float and double, respectively). |
| 99 |
| 100 PNaCl Blocks |
| 101 ============ |
| 102 |
| 103 Blocks are used to organize records in the bitcode file. The kinds of blocks |
| 104 defined in PNaClAsm are: |
| 105 |
| 106 Module block |
| 107 A top-level block defining the program. The :ref:`module |
| 108 block<link_for_module_block>` defines global information used by the program, |
| 109 followed by function blocks defining the implementation of functions within |
| 110 the program. All other blocks (listed below) must appear within a module |
| 111 block. |
| 112 |
| 113 Types block |
| 114 The :ref:`types block<link_for_types_block_section>` defines the set of types |
| 115 used by the program. All types used in the program must be defined in the |
| 116 types block. These types consist of primitive types as well as high level |
| 117 constructs such as vectors and function signatures. |
| 118 |
| 119 Globals block |
| 120 The :ref:`globals block<link_for_globals_block_section>` defines the set of |
| 121 addresses of global variables and constants used by the program. It also |
| 122 defines how each global (associated with the global address) is initialized. |
| 123 |
| 124 Valuesymtab block |
| 125 The :ref:`valuesymtab block<link_for_valuesymtab_block_section>` defines |
| 126 textual names for external function addresses. |
| 127 |
| 128 Function block |
| 129 Each function (implemented) in a program has its own :ref:`function |
| 130 block<link_for_function_blocks_section>` that defines the implementation of |
| 131 the corresponding function. |
| 132 |
| 133 Constants block |
| 134 Each implemented function that uses constants in its instructions defines a |
| 135 :ref:`constants block<link_for_constants_block_section>`. Constants blocks |
| 136 appear within the corresponding function block of the implemented function. |
| 137 |
| 138 Abbreviations block |
| 139 Defines global abbreviations that are used to compress PNaCl records. The |
| 140 :ref:`abbreviations block<link_for_abbreviations_block_section>` is segmented |
| 141 into multiple sections, one section for each kind of block. This block appears |
| 142 at the beginning of the module block. |
| 143 |
| 144 This section is only intended as a high-level discussion of blocks. Later |
| 145 sections will dive more deeply into the constraints on how blocks must be laid |
| 146 out. This section only presents the overall concepts of what kinds of data are |
| 147 stored in each of the blocks. |
| 148 |
| 149 A PNaCl program consists of a :ref:`header |
| 150 record<link_for_header_record_section>` and a :ref:`module |
| 151 block<link_for_module_block>`. The header record defines a sequence of bytes |
| 152 uniquely identifying the file as a bitcode file. The module block defines the |
| 153 program to run. |
| 154 |
| 155 Each block, within a bitcode file, defines values. These values are associated |
| 156 with IDs. Each type of block defines different kinds of IDs. The |
| 157 :ref:`module<link_for_module_block>`, |
| 158 :ref:`types<link_for_types_block_section>`, |
| 159 :ref:`globals<link_for_globals_block_section>`, and |
| 160 :ref:`abbreviations<link_for_abbreviations_block_section>` blocks define global |
| 161 identifiers, and only a single instance can appear. The |
| 162 :ref:`function<link_for_function_blocks_section>` and |
| 163 :ref:`constant<link_for_constants_block_section>` blocks define local |
| 164 identifiers, and can have multiple instances (one for each implemented |
| 165 function). |
| 166 |
| 167 The only records in the module block that define values, are :ref:`function |
| 168 address<link_for_function_address_section>` records. Each function address |
| 169 record defines a different function address, and the :ref:`type |
| 170 signature<link_for_function_type>` associated with that function address. |
| 171 |
| 172 Each :ref:`function block<link_for_function_blocks_section>` defines the |
| 173 implementation of a single function. Each function block defines the |
| 174 intermediate representation of the function, consisting of basic blocks and |
| 175 instructions. If constants are used within instructions, they are defined in a |
| 176 :ref:`constants block<link_for_constants_block_section>`, nested within the |
| 177 corresponding function block. |
| 178 |
| 179 All function blocks are associated with a corresponding function address. This |
| 180 association is positional rather than explicit. That is, the Nth function block |
| 181 in a module block corresponds to the Nth |
| 182 :ref:`defining<link_for_function_address_section>` (rather than declared) |
| 183 function address record in the module block. |
| 184 |
| 185 Hence, within a function block, there is no explicit reference to the function |
| 186 address the block defines. For readability, PNaClAsm uses the corresponding |
| 187 function signature, associated with the corresponding function address record, |
| 188 even though that data does not appear in the corresponding records. |
| 189 |
| 190 .. _link_for_pnacl_records: |
| 191 |
| 192 PNaCl Records |
| 193 ============= |
| 194 |
| 195 A PNaCl record is a non-empty sequence of unsigned, 64-bit, integers. A record |
| 196 is identified by the record *code*, which is the first element in the |
| 197 sequence. Record codes are unique within a specific kind of block, but are not |
| 198 necessarily unique across different kinds of blocks. The record code acts as the |
| 199 variant discriminator (i.e. tag) within a block, to identify what kind of record |
| 200 it is. |
| 201 |
| 202 Record codes that are local to a specific kind of block are small values |
| 203 (starting from zero). In an ideal world, they would be a consecutive sequence of |
| 204 integers, starting at zero. However, the reality is that PNaCl records evolved |
| 205 over time (and actually started as `LLVM records |
| 206 <http://llvm.org/docs/BitCodeFormat.html>`_). For backward compatibility, |
| 207 obsolete numbers have not been reused, leaving gaps in the actual record code |
| 208 values used. |
| 209 |
| 210 Global record codes are record codes that have the same meaning in multiple |
| 211 kinds of blocks. To separate global record codes from local record codes, large |
| 212 values are used. Currently there are four :ref:`global record |
| 213 codes<link_for_global_record_codes>`. To make these cases clear, and to leave |
| 214 ample room for future growth in PNaClAsm, these special records have record |
| 215 codes close to the value 2\ :sup:`16`\ . Note: Well-formed PNaCl bitcode files |
| 216 do not have record codes >= 2\ :sup:`16`\ . |
| 217 |
| 218 A PNaCl record is denoted as follows: :: |
| 219 |
| 220 a: <v0, v1, ... , vN> |
| 221 |
| 222 The value ``v0`` is the record code. The remaining values, ``v1`` through |
| 223 ``vN``, are parameters that fill in additional information needed by the |
| 224 construct it represents. All records must have a record code. Hence, empty PNaCl |
| 225 records are not allowed. ``a`` is the index to the abbreviation used to convert |
| 226 the record to a bit sequence. |
| 227 |
| 228 While most records (for a given record code) have the same length, it is not |
| 229 true of all record codes. Some record codes can have arbitrary length. In |
| 230 particular, function type signatures, call instructions, phi instructions, |
| 231 switch instructions, and global variable initialization records all have |
| 232 variable length. The expected length is predefined and part of the PNaClAsm |
| 233 language. See the corresponding construct (associated with the record) to |
| 234 determine the expected length. |
| 235 |
| 236 The *PNaCl bitstream writer*, which converts records to bit sequences, does |
| 237 this by writing out the abbreviation index used to encode the record, followed |
| 238 by the contents of the record. The details of this are left to the section on |
| 239 :ref:`abbreviations<link_for_abbreviations_section>`. However, at the record |
| 240 level, one important aspect of this appears in :ref:`block |
| 241 enter<link_for_enter_block_record_section>` records. These records must define |
| 242 how many bits are required to hold abbreviation indices associated with records |
| 243 of that block. |
| 244 |
| 245 .. _link_for_default_abbreviations: |
| 246 |
| 247 Default Abbreviations |
| 248 ===================== |
| 249 |
| 250 There are 4 predefined (default) abbreviation indices, used as the default |
| 251 abbreviations for PNaCl records. They are: |
| 252 |
| 253 0 |
| 254 Abbreviation index for the abbreviation used to bit-encode an exit block |
| 255 record. |
| 256 |
| 257 1 |
| 258 Abbreviation index for the abbreviation used to bit-encode an enter block |
| 259 record. |
| 260 |
| 261 2 |
| 262 Abbreviation index for the abbreviation used to bit-encode a user-defined |
| 263 abbreviation. Note: User-defined abbreviations are also encoded as records, |
| 264 and hence need an abbreviation index to bit-encode them. |
| 265 |
| 266 3 |
| 267 Abbreviation index for the default abbreviation to bit-encode all other |
| 268 records in the bitcode file. |
| 269 |
| 270 A block may, in addition, define a list of block specific, user-defined, |
| 271 abbreviations (of length ``U``). The number of bits ``B`` specified for an enter |
| 272 record must be sufficiently large such that:: |
| 273 |
| 274 2**B >= U + 4 |
| 275 |
| 276 In addition, the upper limit for ``B`` is ``16``. |
| 277 |
| 278 PNaClAsm requires specifying the number of bits needed to read abbreviations as |
| 279 part of the enter block record. This allows the PNaCl bitcode reader/writer to |
| 280 use the specified number of bits to encode abbreviation indices. |
| 281 |
| 282 PNaCl Identifiers |
| 283 ================= |
| 284 |
| 285 A program is defined by a :ref:`module block<link_for_module_block>`. Blocks can |
| 286 be nested within other blocks, including the module block. Each block defines a |
| 287 sequence of records. |
| 288 |
| 289 Most of the records, within a block, also define unique values. Each unique |
| 290 value is given a corresponding unique identifier (i.e. *ID*). In PNaClAsm, each |
| 291 kind of block defines its own kind of identifiers. The names of these |
| 292 identifiers are defined by concatenating a prefix character (``'@'`` or |
| 293 ``'%'``), the kind of block (a single character), and a suffix index. The suffix |
| 294 index is defined by the positional location of the defined value within the |
| 295 records of the corresponding block. The indices are all zero based, meaning that |
| 296 the first defined value (within a block) is defined using index 0. |
| 297 |
| 298 Identifiers are categorized into two types, *local* and *global*. Local |
| 299 identifiers are identifiers that are associated with the implementation of a |
| 300 single function. In that sense, they are local to the block they appear in. |
| 301 |
| 302 All other identifiers are global, and can appear in multiple blocks. This split |
| 303 is intentional. Global identifiers are used by multiple functions, and therefore |
| 304 must be known in all function implementations. Local identifiers only apply to a |
| 305 single function, and can be reused between functions. The :ref:`PNaCl |
| 306 translator<link_for_pnacl_translator>` uses this separation to parallelize the |
| 307 compilation of functions. |
| 308 |
| 309 Note that local abbreviation identifiers are unique to the block they appear |
| 310 in. Global abbreviation identifiers are only unique to the block type they are |
| 311 defined for. Different block types can reuse global abbreviation identifiers. |
| 312 |
| 313 Global identifiers use the prefix character ``'@'`` while local identifiers use |
| 314 the prefix character ``'%'``. |
| 315 |
| 316 Note that by using positional location to define identifiers (within a block), |
| 317 the values defined in PNaCl bitcode files need not be explicitly included in the |
| 318 bitcode file. Rather, they are inferred by the (ordered) position of the record |
| 319 in the block. This is also intentional. It is used to reduce the amount of data |
| 320 that must be (explicitly) passed to the :ref:`PNaCl |
| 321 translator<link_for_pnacl_translator>`, when downloaded into Chrome. |
| 322 |
| 323 In general, most of the records within blocks are assumed to be topologically |
| 324 sorted, putting value definitions before their uses. This implies that records |
| 325 do not need to encode data if they can deduce the corresponding information from |
| 326 their uses. |
| 327 |
| 328 The most common use of this is that many instructions use the type of their |
| 329 operands to determine the type of the instruction. Again, this is |
| 330 intentional. It allows less information to be stored. |
| 331 |
| 332 However, for function blocks (which define instructions), a topological sort may |
| 333 not exist. Loop carried value dependencies simply do not allow topologically |
| 334 sorting. To deal with this, function blocks have a notion of (instruction value) |
| 335 :ref:`forward type |
| 336 declarations<link_for_forward_type_declaration_section>`. These declarations |
| 337 must appear before any of the uses of that value, if the (instruction) value is |
| 338 defined later in the function than its first use. |
| 339 |
| 340 The kinds of identifiers used in PNaClAsm are: |
| 341 |
| 342 @a |
| 343 Global abbreviation identifier. |
| 344 |
| 345 %a |
| 346 Local abbreviation identifier. |
| 347 |
| 348 %b |
| 349 Function basic block identifier. |
| 350 |
| 351 %c |
| 352 Function constant identifier. |
| 353 |
| 354 @f |
| 355 Global function address identifier. |
| 356 |
| 357 @g |
| 358 Global variable/constant address identifier. |
| 359 |
| 360 %p |
| 361 Function parameter identifier. |
| 362 |
| 363 @t |
| 364 Global type identifier. |
| 365 |
| 366 %v |
| 367 Value generated by an instruction in a function block. |
| 368 |
| 369 |
| 370 Conventions For Describing Records |
| 371 ================================== |
| 372 |
| 373 PNaClAsm is the textual representation of :ref:`PNaCl |
| 374 records<link_for_pnacl_records>`. Each PNaCl record is described by a |
| 375 corresponding PNaClAsm construct. These constructs are described using syntax |
| 376 rules, and semantics on how they are converted to records. Along with the rules, |
| 377 is a notion of :ref:`global state<link_for_global_state_section>`. The global |
| 378 state is updated by syntax rules. The purpose of the global state is to track |
| 379 positional dependencies between records. |
| 380 |
| 381 For each PNaCl construct, we define multiple sections. The **Syntax** |
| 382 section defines a syntax rule for the construct. The **Record** section |
| 383 defines the corresponding record associated with the syntax rule. The |
| 384 **Semantics** section describes the semantics associated with the record, in |
| 385 terms of data within the global state and the corresponding syntax. It also |
| 386 includes other high-level semantics, when appropriate. |
| 387 |
| 388 The **Constraints** section (if present) defines any constraints associated |
| 389 with the construct, including the global state. The **Updates** section (if |
| 390 present) defines how the global state is updated when the construct is |
| 391 processed. The **Examples** section gives one or more examples of using the |
| 392 corresponding PNaClAsm construct. |
| 393 |
| 394 Some semantics sections use functions to compute values. The meaning of |
| 395 functions can be found in :ref:`support |
| 396 functions<link_for_support_functions_section>`. |
| 397 |
| 398 The syntax rule may include the |
| 399 :ref:`abbreviation<link_for_abbreviations_section>` to use, when converting to a |
| 400 bit-sequence. These abbreviations, if allowed, are at the end of the construct, |
| 401 and enclosed in ``<`` and ``>`` brackets. These abbreviations are optional in |
| 402 the syntax, and can be omitted. If they are used, the abbreviation brackets are |
| 403 part of the actual syntax of the construct. If the abbreviation is omitted, the |
| 404 default abbreviation index is used. To make it clear that abbreviations are |
| 405 optional, syntax rules separate abbreviations using plenty of whitespace. |
| 406 |
| 407 Within a syntax rule, lower case characters are literal values. Sequences of |
| 408 upper case alphanumeric characters are named values. If we mix lower and upper |
| 409 case letters within a name appearing in a syntax rule, the lower case letters |
| 410 are literal while the upper case sequence of alphanumeric characters denote rule |
| 411 specific values. The valid values for each of these names will be defined in |
| 412 the corresponding semantics and constraints subsections. |
| 413 |
| 414 For example, consider the following syntax rule:: |
| 415 |
| 416 %vN = add T O1, O2; <A> |
| 417 |
| 418 This rule defines a PNaClAsm add instruction. This construct defines an |
| 419 instruction that adds two values (``O1`` and ``O2``) to generate instruction |
| 420 value ``%vN``. The types of the arguments, and the result, are all of type |
| 421 ``T``. If abbreviation ID ``A`` is present, the record is encoded using that |
| 422 abbreviation. Otherwise the corresponding :ref:`default abbreviation |
| 423 index<link_for_default_abbreviations>` is used. |
| 424 |
| 425 To be concrete, the syntactic rule above defines the structure of the following |
| 426 PNaClAsm examples:: |
| 427 |
| 428 %v10 = add i32 %v1, %v2; <@a5> |
| 429 %v11 = add i32 %v10, %v3; |
| 430 |
| 431 In addition to specifying the syntax, each syntax rule can also also specify the |
| 432 contents of the corresponding record in the corresponding record subsection. In |
| 433 simple cases, the elements of the corresponding record are predefined (literal) |
| 434 constants. Otherwise the record element is an identifier from another subsection |
| 435 associated with the construct. |
| 436 |
| 437 Factorial Example |
| 438 ================= |
| 439 |
| 440 This section provides a simple example of a PNaCl bitcode file. Its contents |
| 441 describe a bitcode file that only defines a function to compute the factorial |
| 442 value of a number. |
| 443 |
| 444 In C, the factorial function can be defined as:: |
| 445 |
| 446 int fact(int n) { |
| 447 if (n == 1) return 1; |
| 448 return n * fact(n-1); |
| 449 } |
| 450 |
| 451 Compiling this into a PNaCl bitcode file, and dumping out its contents with |
| 452 utility :ref:`pnacl-bcdis<pnacl-bcdis>`, the corresponding output is:: |
| 453 |
| 454 0:0|<65532, 80, 69, 88, 69, 1, 0,|Magic Number: 'PEXE' (80, 69, 88, 69) |
| 455 | 8, 0, 17, 0, 4, 0, 2, 0, 0, |PNaCl Version: 2 |
| 456 | 0> | |
| 457 16:0|1: <65535, 8, 2> |module { // BlockID = 8 |
| 458 24:0| 3: <1, 1> | version 1; |
| 459 26:4| 1: <65535, 0, 2> | abbreviations { // BlockID = 0 |
| 460 36:0| 0: <65534> | } |
| 461 40:0| 1: <65535, 17, 2> | types { // BlockID = 17 |
| 462 48:0| 3: <1, 4> | count 4; |
| 463 50:4| 3: <7, 32> | @t0 = i32; |
| 464 53:6| 3: <2> | @t1 = void; |
| 465 55:4| 3: <21, 0, 0, 0> | @t2 = i32 (i32); |
| 466 59:4| 3: <7, 1> | @t3 = i1; |
| 467 62:0| 0: <65534> | } |
| 468 64:0| 3: <8, 2, 0, 0, 0> | define external i32 @f0(i32); |
| 469 68:6| 1: <65535, 19, 2> | globals { // BlockID = 19 |
| 470 76:0| 3: <5, 0> | count 0; |
| 471 78:4| 0: <65534> | } |
| 472 80:0| 1: <65535, 14, 2> | valuesymtab { // BlockID = 14 |
| 473 88:0| 3: <1, 0, 102, 97, 99, | @f0 : "fact"; |
| 474 | 116> | |
| 475 96:4| 0: <65534> | } |
| 476 100:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0) { |
| 477 | | // BlockID = 12 |
| 478 108:0| 3: <1, 3> | blocks 3; |
| 479 110:4| 1: <65535, 11, 2> | constants { // BlockID = 11 |
| 480 120:0| 3: <1, 0> | i32: |
| 481 122:4| 3: <4, 2> | %c0 = i32 1; |
| 482 125:0| 0: <65534> | } |
| 483 | | %b0: |
| 484 128:0| 3: <28, 2, 1, 32> | %v0 = icmp eq i32 %p0, %c0; |
| 485 132:6| 3: <11, 1, 2, 1> | br i1 %v0, label %b1, label %b2; |
| 486 | | %b1: |
| 487 136:6| 3: <10, 2> | ret i32 %c0; |
| 488 | | %b2: |
| 489 139:2| 3: <2, 3, 2, 1> | %v1 = sub i32 %p0, %c0; |
| 490 143:2| 3: <34, 0, 5, 1> | %v2 = call i32 @f0(i32 %v1); |
| 491 148:0| 3: <2, 5, 1, 2> | %v3 = mul i32 %p0, %v2; |
| 492 152:0| 3: <10, 1> | ret i32 %v3; |
| 493 154:4| 0: <65534> | } |
| 494 156:0|0: <65534> |} |
| 495 |
| 496 Note that there are three columns in this output. The first column contains the |
| 497 bit positions of the records within the bitcode file. The second column contains |
| 498 the sequence of records within the bitcode file. The third column contains the |
| 499 corresponding PNaClAsm program. |
| 500 |
| 501 Bit positions are defined by a pair ``B:N``. ``B`` is the number of bytes, while |
| 502 ``N`` is the bit offset within the ``B``-th byte. Hence, the bit position (in |
| 503 bits) is:: |
| 504 |
| 505 B*8 + N |
| 506 |
| 507 Hence, the first record is at bit offset ``0`` (``0*8+0``). The second record is |
| 508 at bit offset ``128`` (``16*8+0``). The third record is at bit offset ``192`` |
| 509 (``24*8+0``). The fourth record is at bit offset ``212`` (``26*8+4``). |
| 510 |
| 511 The :ref:`header record<link_for_header_record_section>` is a sequence of 16 |
| 512 bytes, defining the contents of the first 16 bytes of the bitcode file. These |
| 513 bytes never change, and are expected for all version 2, PNaCl bitcode files. The |
| 514 first four bytes define the magic number of the file, i.e. 'PEXE'. All PEXE |
| 515 bitcode files begin with these four bytes. |
| 516 |
| 517 All but the header record has an abbreviation index associated with it. Since no |
| 518 user-defined abbreviations are provided, all records were converted to |
| 519 bit sequences using default abbreviations. |
| 520 |
| 521 The types block (starting at bit address ``40:0``), defines 4 types: ``i1``, |
| 522 ``i32``, ``void``, and function signature ``i32 (i32)``. |
| 523 |
| 524 Bit address ``64:0`` declares the factorial function address ``@f0``, and its |
| 525 corresponding type signature. Bit address ``88:0`` associates the name ``fact`` |
| 526 with function address ``@f0``. |
| 527 |
| 528 Bit address ``100:0`` defines the function block that implements function |
| 529 ``fact``. The entry point is ``%b0`` (at bit address ``128:0``). It uses the |
| 530 32-bit integer constant ``1`` (defined at bit addresses ``122:4``). Bit address |
| 531 ``128:0`` defines an equality comparison of the argument ``%p0`` with ``1`` |
| 532 (constant ``%c0``). Bit address ``132:6`` defines a conditional branch. If the |
| 533 result of the previous comparison (``%v0``) is true, the program will branch to |
| 534 block ``%b1``. Otherwise it will branch to block ``%b2``. |
| 535 |
| 536 Bit address ``136:6`` returns constant ``1`` (``%c0``) when the input parameter |
| 537 is 1. Instructions between bit address ``139:2`` and ``154:4`` compute and |
| 538 return ``n * fact(n-1)``. |
| 539 |
| 540 Road Map |
| 541 ======== |
| 542 |
| 543 At this point, this document transitions from basic concepts to the details |
| 544 of how records should be formatted. This section defines the road map to |
| 545 the remaining sections in this document. |
| 546 |
| 547 Many records have implicit information associated with them, and must be |
| 548 maintained across records. :ref:`Global state<link_for_global_state_section>` |
| 549 describes how this implicit information is modeled. In addition, there are |
| 550 various :ref:`support functions<link_for_support_functions_section>` that are |
| 551 used to define the semantics of records, and how they update the global state. |
| 552 |
| 553 There are just a handful of global records (records that either don't appear in |
| 554 any block, or can appear in all blocks). :ref:`Global |
| 555 records<link_for_global_record_codes>` describes these records. This includes |
| 556 the block delimiter records :ref:`enter<link_for_enter_block_record_section>` |
| 557 and :ref:`exit<link_for_exit_block_record_section>` that define block |
| 558 boundaries. |
| 559 |
| 560 PNaClAsm is a strongly typed language, and most block values are typed. |
| 561 :ref:`types<link_for_types_block_section>` describes the set of legal types, and |
| 562 how to define types. |
| 563 |
| 564 Global variables and their initializers are presented in the :ref:`globals |
| 565 block<link_for_globals_block_section>`. :ref:`Function |
| 566 addresses<link_for_function_address_section>` are part of the :ref:`module |
| 567 block<link_for_module_block>`, but must be defined before any global variables. |
| 568 |
| 569 Names to be associated with global variables and function addresses, are defined |
| 570 in the :ref:`valuesymtab block<link_for_valuesymtab_block_section>`, and must |
| 571 appear after the :ref:`globals block<link_for_globals_block_section>`, but |
| 572 before any :ref:`function definition<link_for_function_blocks_section>`. |
| 573 |
| 574 The :ref:`module block<link_for_module_block>` is the top-most block, and all |
| 575 other blocks must appear within the module block. The module block defines the |
| 576 executable in the bitcode file. |
| 577 |
| 578 Constants used within a :ref:`function |
| 579 definition<link_for_function_blocks_section>` must be defined using a |
| 580 :ref:`constants block<link_for_constants_block_section>`. Each function |
| 581 definition is defined by a :ref:`function |
| 582 block<link_for_function_blocks_section>` and constant blocks can only appear |
| 583 within function blocks. Constants defined within a constant block can only be |
| 584 used in the enclosing function block. |
| 585 |
| 586 Function definitions are defined by a sequence of instructions. There are |
| 587 several types of instructions. |
| 588 |
| 589 A :ref:`terminator instruction<link_for_terminator_instruction_section>` is the |
| 590 last instruction in a :ref:`basic block<link_for_function_blocks_section>`, and |
| 591 is a branch, return, or unreachable instruction. |
| 592 |
| 593 There are :ref:`integer<link_for_integer_binary_instructions>` and |
| 594 :ref:`floating point<link_for_floating_point_binary_instructions>` binary |
| 595 operations. Integer binary instructions include both arithmetic and logical |
| 596 operations. Floating point instructions define arithmetic operations. |
| 597 |
| 598 There are also :ref:`memory |
| 599 access<link_for_memory_creation_and_access_instructions>` instructions that |
| 600 allow one to load and store values. That section also includes how to define |
| 601 local variables using the :ref:`alloca |
| 602 instruction<link_for_alloca_instruction>`. |
| 603 |
| 604 One can also convert integer and floating point values using :ref:`conversion |
| 605 instructions<link_for_conversion_instructions>`. |
| 606 |
| 607 :ref:`Comparison instructions<link_for_compare_instructions>` |
| 608 allow you to compare values. |
| 609 |
| 610 :ref:`Vector instructions<link_for_vector_instructions>` allow you to build and |
| 611 update vectors. Corresponding :ref:`intrinsic |
| 612 functions<link_for_intrinsic_functions_section>`, as well as |
| 613 :ref:`integer<link_for_integer_binary_instructions>` and :ref:`floating |
| 614 point<link_for_floating_point_binary_instructions>` binary instructions allow |
| 615 you to apply operations to vectors. |
| 616 |
| 617 In addition, :ref:`other instructions<link_for_other_pnaclasm_instructions>` are |
| 618 available. This includes function and procedure calls. |
| 619 |
| 620 There are also :ref:`memory |
| 621 alignment<link_for_memory_blocks_and_alignment_section>` issues that should be |
| 622 considered for global and local variables, as well as load and store |
| 623 instructions. |
| 624 |
| 625 Finally, how to pack records is described in the |
| 626 :ref:`abbreviations<link_for_abbreviations_section>` section. |
| 627 |
| 628 .. _link_for_global_state_section: |
| 629 |
| 630 Global State |
| 631 ============ |
| 632 |
| 633 This section describes the global state associated with PNaClAsm. It is used to |
| 634 define contextual data that is carried between records. |
| 635 |
| 636 In particular, PNaClAsm is a strongly typed language, and hence, we must track |
| 637 the type associated with values. Subsection :ref:`link_to_typing_functions` |
| 638 describes the functions used to maintain typing information associated with |
| 639 values. |
| 640 |
| 641 Values are implicitly ordered within a block, and the indices associated with |
| 642 the values do not appear in records. Rather, ID counters are used to figure out |
| 643 what corresponding ID name is associated with a value generating record. |
| 644 Subsection :ref:`link_to_ID_Counters` defines counters maintained in the global |
| 645 state. |
| 646 |
| 647 In several blocks, one of the first records in the block defines how many values |
| 648 are defined in in the block. The main purpose of these counts is to communicate |
| 649 to the :ref:`PNaCl translator<link_for_pnacl_translator>` space requirements, or |
| 650 a limit so that it can detect bad references to values. Subsection |
| 651 :ref:`link_for_Size_Variables` defines variables that hold size definitions in |
| 652 the corresponding records. |
| 653 |
| 654 Finally, the function and constants block contain implicit context between |
| 655 records in those blocks. Subsection :ref:`link_to_Other_Variables` defines the |
| 656 variables that contain this implicit context. |
| 657 |
| 658 .. _link_to_typing_functions: |
| 659 |
| 660 Typing Functions |
| 661 ---------------- |
| 662 |
| 663 Associated with most identifiers is a type. This type defines what type the |
| 664 corresponding value has. It is defined by the (initially empty) map:: |
| 665 |
| 666 TypeOf: ID -> Type |
| 667 |
| 668 For each type in the :ref:`types block<link_for_types_block_section>`, a |
| 669 corresponding inverse map:: |
| 670 |
| 671 TypeID: Type -> ID |
| 672 |
| 673 is maintained to convert syntactic types to the corresponding type ID. |
| 674 |
| 675 Note: This document assumes that map ``TypeID`` is automatically maintained |
| 676 during updates to map ``TypeOf`` (when given a type ``ID``). Hence, *Updates* |
| 677 subsections will not contain assignments to this map. |
| 678 |
| 679 Associated with each function identifier is its :ref:`type |
| 680 signature<link_for_function_type>`. This is different than the type of the |
| 681 function identifier, since function identifiers represent the function address |
| 682 which is a pointer (and pointers are always implemented as a 32-bit integer |
| 683 following the ILP32 data model). |
| 684 |
| 685 Function type signatures are maintained using:: |
| 686 |
| 687 TypeOfFcn: ID -> Type |
| 688 |
| 689 In addition, if a function address has an implementing block, there is a |
| 690 corresponding implementation associated with the function address. To indicate |
| 691 which function addresses have implementations, we use the set:: |
| 692 |
| 693 DefiningFcnIDs: set(ID) |
| 694 |
| 695 .. _link_to_ID_Counters: |
| 696 |
| 697 ID Counters |
| 698 ----------- |
| 699 |
| 700 Each block defines one or more kinds of values. Value indices are generated |
| 701 sequentially, starting at zero. To capture this, the following counters are |
| 702 defined: |
| 703 |
| 704 NumTypes |
| 705 The number of types defined so far (in the :ref:`types |
| 706 block<link_for_types_block_section>`). |
| 707 |
| 708 NumFuncAddresses |
| 709 The number of function addresses defined so far (in the :ref:`module |
| 710 block<link_for_module_block>`). |
| 711 |
| 712 NumGlobalAddresses |
| 713 The number of global variable/constant addresses defined so far (in the |
| 714 :ref:`globals block<link_for_globals_block_section>`). |
| 715 |
| 716 NumParams |
| 717 The number of parameters defined for a function. Note: Unlike other counters, |
| 718 this value is set once, at the beginning of the corresponding :ref:`function |
| 719 block<link_for_function_blocks_section>`, based on the type signature |
| 720 associated with the function. |
| 721 |
| 722 NumFcnConsts |
| 723 The number of constants defined in a function so far (in the corresponding |
| 724 nested :ref:`constants block<link_for_constants_block_section>`). |
| 725 |
| 726 NumBasicBlocks |
| 727 The number of basic blocks defined so far (within a :ref:`function |
| 728 block<link_for_function_blocks_section>`). |
| 729 |
| 730 NumValuedInsts |
| 731 The number of instructions, generating values, defined so far (within a |
| 732 :ref:`function block<link_for_function_blocks_section>`). |
| 733 |
| 734 .. _link_for_Size_Variables: |
| 735 |
| 736 Size Variables |
| 737 -------------- |
| 738 |
| 739 A number of blocks define expected sizes of constructs. These sizes are recorded |
| 740 in the following size variables: |
| 741 |
| 742 ExpectedBasicBlocks |
| 743 The expected :ref:`number of basic blocks<link_for_basic_blocks_count>` within |
| 744 a function implementation. |
| 745 |
| 746 ExpectedTypes |
| 747 The expected :ref:`number of types<link_for_types_count_record>` defined in |
| 748 the types block. |
| 749 |
| 750 ExpectedGlobals |
| 751 The expected :ref:`number of global variable/constant |
| 752 addresses<link_for_globals_count_record>` in the globals block. |
| 753 |
| 754 ExpectedInitializers |
| 755 The expected :ref:`number of initializers<link_for_compound_initializer>` for |
| 756 a global variable/constant address in the globals block. |
| 757 |
| 758 It is assumed that the corresponding :ref:`ID counters<link_to_ID_counters>` are |
| 759 always smaller than the corresponding size variables (except |
| 760 ExpectedInitializers). That is:: |
| 761 |
| 762 NumBasicBlocks < ExpectedBasicBlocks |
| 763 NumTypes < ExpectedTypes |
| 764 NumGlobalAddresses < ExpectedGlobals |
| 765 |
| 766 .. _link_to_Other_Variables: |
| 767 |
| 768 Other Variables |
| 769 --------------- |
| 770 |
| 771 EnclosingFcnID |
| 772 The function ID of the function block being processed. |
| 773 |
| 774 ConstantsSetType |
| 775 Holds the type associated with the last :ref:`set type |
| 776 record<link_for_constants_set_type_record>` in the constants block. Note: at |
| 777 the beginning of each constants block, this variable is set to type void. |
| 778 |
| 779 .. _link_for_global_record_codes: |
| 780 |
| 781 Global Records |
| 782 ============== |
| 783 |
| 784 Global records are records that can appear in any block. These records have |
| 785 the same meaning in multiple kinds of blocks. |
| 786 |
| 787 There are four global PNaCl records, each having its own record code. These |
| 788 global records are: |
| 789 |
| 790 Header |
| 791 The :ref:`header record<link_for_header_record_section>` is the first record |
| 792 of a PNaCl bitcode file, and identifies the file's magic number, as well as |
| 793 the bitcode version it uses. The record defines the sequence of bytes that |
| 794 make up the header and uniquely identifies the file as a PNaCl bitcode file. |
| 795 |
| 796 Enter |
| 797 An :ref:`enter record<link_for_enter_block_record_section>` defines the |
| 798 beginning of a block. Since blocks can be nested, one can appear inside other |
| 799 blocks, as well as at the top level. |
| 800 |
| 801 Exit |
| 802 An :ref:`exit record<link_for_exit_block_record_section>` defines the end of a |
| 803 block. Hence, it must appear in every block, to end the block. |
| 804 |
| 805 Abbreviation |
| 806 An :ref:`abbreviation record<link_for_abbreviation_record>` defines a |
| 807 user-defined abbreviation to be applied to records within blocks. |
| 808 Abbreviation records appearing in the abbreviations block define global |
| 809 abbreviations. All other abbreviations are local to the block they appear in, |
| 810 and can only be used in that block. |
| 811 |
| 812 All global records can't have user-defined abbreviations associated with |
| 813 them. The :ref:`default abbreviation<link_for_default_abbreviations>` is always |
| 814 used. |
| 815 |
| 816 .. _link_for_header_record_section: |
| 817 |
| 818 Header Record |
| 819 ------------- |
| 820 |
| 821 The header record must be the first record in the file. It is the only record in |
| 822 the bitcode file that doesn't have a corresponding construct in PNaClAsm. In |
| 823 addition, no abbreviation index is associated with it. |
| 824 |
| 825 **Syntax**: |
| 826 |
| 827 There is no syntax for header records in PNaClAsm. |
| 828 |
| 829 **Record**:: |
| 830 |
| 831 <65532, 80, 69, 88, 69, 1, 0, 8, 0, 17, 0, 4, 0, 2, 0, 0, 0> |
| 832 |
| 833 **Semantics**: |
| 834 |
| 835 The header record defines the initial sequence of bytes that must appear at the |
| 836 beginning of all (PNaCl bitcode version 2) files. That sequence is the list of |
| 837 bytes inside the record (excluding the record code). As such, it uniquely |
| 838 identifies all PNaCl bitcode files. |
| 839 |
| 840 **Examples**:: |
| 841 |
| 842 0:0|<65532, 80, 69, 88, 69, 1, 0,|Magic Number: 'PEXE' (80, 69, 88, 69) |
| 843 | 8, 0, 17, 0, 4, 0, 2, 0, 0, |PNaCl Version: 2 |
| 844 | 0> | |
| 845 |
| 846 .. _link_for_enter_block_record_section: |
| 847 |
| 848 Enter Block Record |
| 849 ------------------ |
| 850 |
| 851 Block records can be top-level, as well as nested in other blocks. Blocks must |
| 852 begin with an *enter* record, and end with an |
| 853 :ref:`exit<link_for_exit_block_record_section>` record. |
| 854 |
| 855 **Syntax**:: |
| 856 |
| 857 N { <B> |
| 858 |
| 859 **Record**:: |
| 860 |
| 861 1: <65535, ID, B> |
| 862 |
| 863 **Semantics**: |
| 864 |
| 865 Enter block records define the beginning of a block. ``B``, if present, is the |
| 866 number of bits needed to represent all possible abbreviation indices used within |
| 867 the block. If omitted, ``B=2`` is assumed. |
| 868 |
| 869 The block ``ID`` value is dependent on the name ``N``. Valid names and |
| 870 corresponding ``BlockID`` values are defined as follows: |
| 871 |
| 872 ============= ======== |
| 873 N Block ID |
| 874 ============= ======== |
| 875 abbreviations 0 |
| 876 constants 11 |
| 877 function 12 |
| 878 globals 19 |
| 879 module 8 |
| 880 types 17 |
| 881 valuesymtab 14 |
| 882 ============= ======== |
| 883 |
| 884 Note: For readability, PNaClAsm defines a more readable form of a function block |
| 885 enter record. See :ref:`function blocks<link_for_function_blocks_section>` for |
| 886 more details. |
| 887 |
| 888 **Examples**:: |
| 889 |
| 890 16:0|1: <65535, 8, 2> |module { // BlockID = 8 |
| 891 24:0| 3: <1, 1> | version 1; |
| 892 26:4| 1: <65535, 0, 2> | abbreviations { // BlockID = 0 |
| 893 36:0| 0: <65534> | } |
| 894 40:0| 1: <65535, 17, 2> | types { // BlockID = 17 |
| 895 48:0| 3: <1, 2> | count 2; |
| 896 50:4| 3: <2> | @t0 = void; |
| 897 52:2| 3: <21, 0, 0> | @t1 = void (); |
| 898 55:4| 0: <65534> | } |
| 899 56:0| 3: <8, 1, 0, 1, 0> | declare external void @f0(); |
| 900 60:6| 1: <65535, 19, 2> | globals { // BlockID = 19 |
| 901 68:0| 3: <5, 0> | count 0; |
| 902 70:4| 0: <65534> | } |
| 903 72:0|0: <65534> |} |
| 904 |
| 905 .. _link_for_exit_block_record_section: |
| 906 |
| 907 Exit Block Record |
| 908 ----------------- |
| 909 |
| 910 Block records can be top-level, as well as nested, records. Blocks must begin |
| 911 with an :ref:`enter<link_for_enter_block_record_section>` record, and end with |
| 912 an *exit* record. |
| 913 |
| 914 **Syntax**:: |
| 915 |
| 916 } |
| 917 |
| 918 **Record**:: |
| 919 |
| 920 0: <65534> |
| 921 |
| 922 **Semantics**: |
| 923 |
| 924 All exit records are identical, no matter what block they are ending. An exit |
| 925 record defines the end of the block. |
| 926 |
| 927 **Examples**:: |
| 928 |
| 929 16:0|1: <65535, 8, 2> |module { // BlockID = 8 |
| 930 24:0| 3: <1, 1> | version 1; |
| 931 26:4| 1: <65535, 0, 2> | abbreviations { // BlockID = 0 |
| 932 36:0| 0: <65534> | } |
| 933 40:0| 1: <65535, 17, 2> | types { // BlockID = 17 |
| 934 48:0| 3: <1, 2> | count 2; |
| 935 50:4| 3: <2> | @t0 = void; |
| 936 52:2| 3: <21, 0, 0> | @t1 = void (); |
| 937 55:4| 0: <65534> | } |
| 938 56:0| 3: <8, 1, 0, 1, 0> | declare external void @f0(); |
| 939 60:6| 1: <65535, 19, 2> | globals { // BlockID = 19 |
| 940 68:0| 3: <5, 0> | count 0; |
| 941 70:4| 0: <65534> | } |
| 942 72:0|0: <65534> |} |
| 943 |
| 944 .. _link_for_abbreviation_record: |
| 945 |
| 946 Abbreviation Record |
| 947 ------------------- |
| 948 |
| 949 Abbreviation records define abbreviations. See |
| 950 :ref:`abbreviations<link_for_abbreviations_section>` for details on how |
| 951 abbreviations should be written. This section only presents the mechanical |
| 952 details for converting an abbreviation into a PNaCl record. |
| 953 |
| 954 **Syntax**:: |
| 955 |
| 956 A = abbrev <E1, ... , EM>; |
| 957 |
| 958 **Record**:: |
| 959 |
| 960 2: <65533, M, EE1, ... , EEM> |
| 961 |
| 962 **Semantics**: |
| 963 |
| 964 Defines an abbreviation ``A`` as the sequence of encodings ``E1`` through |
| 965 ``EM``. If the abbreviation appears within the :ref:`abbreviations |
| 966 block<link_for_abbreviations_block_section>`, ``A`` must be a global |
| 967 abbreviation. Otherwise, ``A`` must be a local abbreviation. |
| 968 |
| 969 Abbreviations within a block (or a section within the abbreviations block), must |
| 970 be enumerated in order, starting at index ``0``. |
| 971 |
| 972 Valid encodings ``Ei``, and the corresponding sequence of (unsigned) integers |
| 973 ``EEi``, ( for ``1 <= i <= M``) are defined by the following table: |
| 974 |
| 975 ========= ======= ================================================== |
| 976 Ei EEi Form |
| 977 ========= ======= ================================================== |
| 978 C 1, C Literal C in corresponding position in record. |
| 979 fixed(N) 0, 1, N Encode value as a fixed sequence of N bits. |
| 980 vbr(N) 0, 2, N Encode value using a variable bit rate of N. |
| 981 char6 0, 4 Encode value as 6-bit char containing |
| 982 characters [a-zA-Z0-9._]. |
| 983 array 0, 3 Allow zero or more of the succeeding abbreviation. |
| 984 ========= ======= ================================================== |
| 985 |
| 986 Note that 'array' can only appear as the second to last element in the |
| 987 abbreviation. Notationally, ``array(EM)`` is used in place of ``array`` and |
| 988 ``EM``, the last two entries in an abbreviation. |
| 989 |
| 990 **Examples**:: |
| 991 |
| 992 0:0|<65532, 80, 69, 88, 69, 1, 0,|Magic Number: 'PEXE' (80, 69, 88, 69) |
| 993 | 8, 0, 17, 0, 4, 0, 2, 0, 0, |PNaCl Version: 2 |
| 994 | 0> | |
| 995 16:0|1: <65535, 8, 2> |module { // BlockID = 8 |
| 996 24:0| 3: <1, 1> | version 1; |
| 997 26:4| 1: <65535, 0, 2> | abbreviations { // BlockID = 0 |
| 998 36:0| 1: <1, 14> | valuesymtab: |
| 999 38:4| 2: <65533, 4, 0, 1, 3, 0,| @a0 = abbrev <fixed(3), vbr(8), |
| 1000 | 2, 8, 0, 3, 0, 1, 8> | array(fixed(8))>; |
| 1001 43:2| 2: <65533, 4, 1, 1, 0, 2,| @a1 = abbrev <1, vbr(8), |
| 1002 | 8, 0, 3, 0, 1, 7> | array(fixed(7))>; |
| 1003 48:0| 2: <65533, 4, 1, 1, 0, 2,| @a2 = abbrev <1, vbr(8), |
| 1004 | 8, 0, 3, 0, 4> | array(char6)>; |
| 1005 52:1| 2: <65533, 4, 1, 2, 0, 2,| @a3 = abbrev <2, vbr(8), |
| 1006 | 8, 0, 3, 0, 4> | array(char6)>; |
| 1007 56:2| 1: <1, 11> | constants: |
| 1008 58:6| 2: <65533, 2, 1, 1, 0, 1,| @a0 = abbrev <1, fixed(2)>; |
| 1009 | 2> | |
| 1010 61:7| 2: <65533, 2, 1, 4, 0, 2,| @a1 = abbrev <4, vbr(8)>; |
| 1011 | 8> | |
| 1012 65:0| 2: <65533, 2, 1, 4, 1, 0>| @a2 = abbrev <4, 0>; |
| 1013 68:1| 2: <65533, 2, 1, 6, 0, 2,| @a3 = abbrev <6, vbr(8)>; |
| 1014 | 8> | |
| 1015 71:2| 1: <1, 12> | function: |
| 1016 73:6| 2: <65533, 4, 1, 20, 0, | @a0 = abbrev <20, vbr(6), vbr(4), |
| 1017 | 2, 6, 0, 2, 4, 0, 2, | vbr(4)>; |
| 1018 | 4> | |
| 1019 79:1| 2: <65533, 4, 1, 2, 0, 2,| @a1 = abbrev <2, vbr(6), vbr(6), |
| 1020 | 6, 0, 2, 6, 0, 1, 4> | fixed(4)>; |
| 1021 84:4| 2: <65533, 4, 1, 3, 0, 2,| @a2 = abbrev <3, vbr(6), |
| 1022 | 6, 0, 1, 2, 0, 1, 4> | fixed(2), fixed(4)>; |
| 1023 89:7| 2: <65533, 1, 1, 10> | @a3 = abbrev <10>; |
| 1024 91:7| 2: <65533, 2, 1, 10, 0, | @a4 = abbrev <10, vbr(6)>; |
| 1025 | 2, 6> | |
| 1026 95:0| 2: <65533, 1, 1, 15> | @a5 = abbrev <15>; |
| 1027 97:0| 2: <65533, 3, 1, 43, 0, | @a6 = abbrev <43, vbr(6), |
| 1028 | 2, 6, 0, 1, 2> | fixed(2)>; |
| 1029 101:2| 2: <65533, 4, 1, 24, 0, | @a7 = abbrev <24, vbr(6), vbr(6), |
| 1030 | 2, 6, 0, 2, 6, 0, 2, | vbr(4)>; |
| 1031 | 4> | |
| 1032 106:5| 1: <1, 19> | globals: |
| 1033 109:1| 2: <65533, 3, 1, 0, 0, 2,| @a0 = abbrev <0, vbr(6), |
| 1034 | 6, 0, 1, 1> | fixed(1)>; |
| 1035 113:3| 2: <65533, 2, 1, 1, 0, 2,| @a1 = abbrev <1, vbr(8)>; |
| 1036 | 8> | |
| 1037 116:4| 2: <65533, 2, 1, 2, 0, 2,| @a2 = abbrev <2, vbr(8)>; |
| 1038 | 8> | |
| 1039 119:5| 2: <65533, 3, 1, 3, 0, 3,| @a3 = abbrev <3, array(fixed(8))> |
| 1040 | 0, 1, 8> | ; |
| 1041 123:2| 2: <65533, 2, 1, 4, 0, 2,| @a4 = abbrev <4, vbr(6)>; |
| 1042 | 6> | |
| 1043 126:3| 2: <65533, 3, 1, 4, 0, 2,| @a5 = abbrev <4, vbr(6), vbr(6)>; |
| 1044 | 6, 0, 2, 6> | |
| 1045 130:5| 0: <65534> | } |
| 1046 132:0| 1: <65535, 17, 3> | types { // BlockID = 17 |
| 1047 140:0| 2: <65533, 4, 1, 21, 0, | %a0 = abbrev <21, fixed(1), |
| 1048 | 1, 1, 0, 3, 0, 1, 2> | array(fixed(2))>; |
| 1049 144:7| 3: <1, 3> | count 3; |
| 1050 147:4| 3: <7, 32> | @t0 = i32; |
| 1051 150:7| 4: <21, 0, 0, 0, 0> | @t1 = i32 (i32, i32); <%a0> |
| 1052 152:7| 3: <2> | @t2 = void; |
| 1053 154:6| 0: <65534> | } |
| 1054 156:0| 3: <8, 1, 0, 0, 0> | define external i32 @f0(i32, i32); |
| 1055 160:6| 1: <65535, 19, 4> | globals { // BlockID = 19 |
| 1056 168:0| 3: <5, 0> | count 0; |
| 1057 170:6| 0: <65534> | } |
| 1058 172:0| 1: <65535, 14, 3> | valuesymtab { // BlockID = 14 |
| 1059 180:0| 6: <1, 0, 102> | @f0 : "f"; <@a2> |
| 1060 182:7| 0: <65534> | } |
| 1061 184:0| 1: <65535, 12, 4> | function i32 @f0(i32 %p0, i32 %p1) { |
| 1062 | | // BlockID = 12 |
| 1063 192:0| 3: <1, 1> | blocks 1; |
| 1064 | | %b0: |
| 1065 194:6| 5: <2, 2, 1, 0> | %v0 = add i32 %p0, %p1; <@a1> |
| 1066 197:2| 5: <2, 3, 1, 0> | %v1 = add i32 %p0, %v0; <@a1> |
| 1067 199:6| 8: <10, 1> | ret i32 %v1; <@a4> |
| 1068 201:0| 0: <65534> | } |
| 1069 204:0|0: <65534> |} |
| 1070 |
| 1071 Note that the example above shows the standard abbreviations used by |
| 1072 *pnacl-finalize*. |
| 1073 |
| 1074 .. _link_for_types_block_section: |
| 1075 |
| 1076 Types Block |
| 1077 =========== |
| 1078 |
| 1079 The types block defines all types used in a program. It must appear in the |
| 1080 :ref:`module block<link_for_module_block>`, before any :ref:`function |
| 1081 address<link_for_function_address_section>` records, the :ref:`globals |
| 1082 block<link_for_globals_block_section>`, the :ref:`valuesymtab |
| 1083 block<link_for_valuesymtab_block_section>`, and any :ref:`function |
| 1084 blocks<link_for_function_blocks_section>`. |
| 1085 |
| 1086 All types used in a program must be defined in the types block. Many PNaClAsm |
| 1087 constructs allow one to use explicit type names, rather than the type |
| 1088 identifiers defined by this block. However, they are internally converted to the |
| 1089 corresponding type identifier in the types block. Hence, the requirement that |
| 1090 the types block must appear early in the module block. |
| 1091 |
| 1092 Each record in the types block defines a type used by the program. Types can be |
| 1093 broken into the following groups: |
| 1094 |
| 1095 Primitive value types |
| 1096 Defines the set of base types for values. This includes various sizes of |
| 1097 integer and floating point types. |
| 1098 |
| 1099 Void type |
| 1100 A primitive type that doesn't represent any value and has no size. |
| 1101 |
| 1102 Function types |
| 1103 The type signatures of functions. |
| 1104 |
| 1105 Vector type |
| 1106 Defines vectors of primitive types. |
| 1107 |
| 1108 In addition, any type that is not defined using another type is a primitive |
| 1109 type. All other types (i.e. function and vector) are composite types. |
| 1110 |
| 1111 Types must be defined in a topological order, causing primitive types to appear |
| 1112 before the composite types that use them. Each type must be unique. There are no |
| 1113 additional restrictions on the order that types can be defined in a types block. |
| 1114 |
| 1115 The following subsections introduce each valid PNaClAsm type, and the |
| 1116 corresponding PNaClAsm construct that defines the type. Types not defined in the |
| 1117 types block, can't be used in a PNaCl program. |
| 1118 |
| 1119 The first record of a types block must be a :ref:`count |
| 1120 record<link_for_types_count_record>`, defining how many types are defined by the |
| 1121 types block. All remaining records defines a type. The following subsections |
| 1122 defines valid records within a types block. The order of type records is |
| 1123 important. The position of each defining record implicitly defines the type ID |
| 1124 that will be used to denote that type, within other PNaCl records of the bitcode |
| 1125 file. |
| 1126 |
| 1127 To make this more concrete, consider the following example types block:: |
| 1128 |
| 1129 40:0| 1: <65535, 17, 2> | types { // BlockID = 17 |
| 1130 48:0| 3: <1, 4> | count 4; |
| 1131 50:4| 3: <7, 32> | @t0 = i32; |
| 1132 53:6| 3: <3> | @t1 = float; |
| 1133 55:4| 3: <2> | @t2 = void; |
| 1134 57:2| 3: <21, 0, 2, 0, 1> | @t3 = void (i32, float); |
| 1135 62:0| 0: <65534> | } |
| 1136 |
| 1137 This example defines a types block that defines four type IDs: |
| 1138 |
| 1139 @t0 |
| 1140 A 32-bit integer type. |
| 1141 @t1 |
| 1142 A 32-bit floating point type. |
| 1143 @t2 |
| 1144 The void type. |
| 1145 @t3 |
| 1146 A function, taking 32-bit integer and float point arguments that returns |
| 1147 void. |
| 1148 |
| 1149 .. _link_for_types_count_record: |
| 1150 |
| 1151 Count Record |
| 1152 ------------ |
| 1153 |
| 1154 The *count record* defines how many types are defined in the types |
| 1155 block. Following the types count record are records that define types used by |
| 1156 the PNaCl program. |
| 1157 |
| 1158 **Syntax**:: |
| 1159 |
| 1160 count N; <A> |
| 1161 |
| 1162 **Record**:: |
| 1163 |
| 1164 AA: <1, N> |
| 1165 |
| 1166 **Semantics**: |
| 1167 |
| 1168 This construct defines the number of types used by the PNaCl program. ``N`` is |
| 1169 the number of types defined in the types block. It is an error to define more |
| 1170 (or fewer) types than value ``N``, within the enclosing types block. |
| 1171 |
| 1172 **Constraints**:: |
| 1173 |
| 1174 AA == AbbrevIndex(A) & |
| 1175 0 == NumTypes |
| 1176 |
| 1177 **Updates**:: |
| 1178 |
| 1179 ExpectedTypes = N; |
| 1180 |
| 1181 **Examples**:: |
| 1182 |
| 1183 40:0| 1: <65535, 17, 2> | types { // BlockID = 17 |
| 1184 48:0| 3: <1, 4> | count 4; |
| 1185 50:4| 3: <7, 32> | @t0 = i32; |
| 1186 53:6| 3: <3> | @t1 = float; |
| 1187 55:4| 3: <2> | @t2 = void; |
| 1188 57:2| 3: <21, 0, 2, 0, 1> | @t3 = void (i32, float); |
| 1189 62:0| 0: <65534> | } |
| 1190 |
| 1191 Void Type |
| 1192 --------- |
| 1193 |
| 1194 The *void* type record defines the void type, which corresponds to the type that |
| 1195 doesn't define any value, and has no size. |
| 1196 |
| 1197 **Syntax**:: |
| 1198 |
| 1199 @tN = void; <A> |
| 1200 |
| 1201 **Record**:: |
| 1202 |
| 1203 AA: <2> |
| 1204 |
| 1205 **Semantics**: |
| 1206 |
| 1207 The void type record defines the type that has no values and has no size. |
| 1208 |
| 1209 **Constraints**:: |
| 1210 |
| 1211 AA == AbbrevIndex(A) & |
| 1212 N == NumTypes |
| 1213 |
| 1214 **Updates**:: |
| 1215 |
| 1216 ++NumTypes; |
| 1217 TypeOf(@tN) = void; |
| 1218 |
| 1219 **Examples**:: |
| 1220 |
| 1221 40:0| 1: <65535, 17, 2> | types { // BlockID = 17 |
| 1222 48:0| 3: <1, 4> | count 4; |
| 1223 50:4| 3: <7, 32> | @t0 = i32; |
| 1224 53:6| 3: <3> | @t1 = float; |
| 1225 55:4| 3: <2> | @t2 = void; |
| 1226 62:0| 0: <65534> | } |
| 1227 |
| 1228 Integer Types |
| 1229 ------------- |
| 1230 |
| 1231 PNaClAsm allows integer types for various bit sizes. Valid bit sizes are 1, 8, |
| 1232 16, 32, and 64. Integers can be signed or unsigned, but the signed component of |
| 1233 an integer is not specified by the type. Rather, individual instructions |
| 1234 determine whether the value is assumed to be signed or unsigned. |
| 1235 |
| 1236 It should be noted that in PNaClAsm, all pointers are implemented as 32-bit |
| 1237 (unsigned) integers. There isn't a separate type for pointers. The only way to |
| 1238 tell that a 32-bit integer is a pointer, is when it is used in an instruction |
| 1239 that requires a pointer (such as load and store instructions). |
| 1240 |
| 1241 **Syntax**:: |
| 1242 |
| 1243 @tN = iB; <A> |
| 1244 |
| 1245 **Record**:: |
| 1246 |
| 1247 AA: <7, B> |
| 1248 |
| 1249 **Semantics**: |
| 1250 |
| 1251 An integer type record defines an integer type. ``B`` defines the number of bits |
| 1252 of the integer type. |
| 1253 |
| 1254 **Constraints**:: |
| 1255 |
| 1256 AA == AbbrevIndex(A) & |
| 1257 N == NumTypes & |
| 1258 B in {1, 8, 16, 32, 64} |
| 1259 |
| 1260 **Updates**:: |
| 1261 |
| 1262 ++NumTypes; |
| 1263 TypeOf(@tN) = iB; |
| 1264 |
| 1265 **Examples**:: |
| 1266 |
| 1267 40:0| 1: <65535, 17, 2> | types { // BlockID = 17 |
| 1268 48:0| 3: <1, 7> | count 7; |
| 1269 50:4| 3: <7, 64> | @t0 = i64; |
| 1270 53:6| 3: <7, 1> | @t1 = i1; |
| 1271 56:2| 3: <7, 8> | @t2 = i8; |
| 1272 58:6| 3: <7, 16> | @t3 = i16; |
| 1273 61:2| 3: <7, 32> | @t4 = i32; |
| 1274 64:4| 3: <21, 0, 0, 1> | @t5 = i64 (i1); |
| 1275 68:4| 3: <2> | @t6 = void; |
| 1276 70:2| 0: <65534> | } |
| 1277 |
| 1278 32-Bit Floating Point Type |
| 1279 -------------------------- |
| 1280 |
| 1281 PNaClAsm allows computation on 32-bit floating point values. A floating point |
| 1282 type record defines the 32-bit floating point type. |
| 1283 |
| 1284 **Syntax**:: |
| 1285 |
| 1286 @tN = float; <A> |
| 1287 |
| 1288 **Record**:: |
| 1289 |
| 1290 AA: <3> |
| 1291 |
| 1292 **Semantics**: |
| 1293 |
| 1294 A floating point type record defines the 32-bit floating point type. |
| 1295 |
| 1296 **Constraints**:: |
| 1297 |
| 1298 AA == AbbrevIndex(A) & |
| 1299 N == NumTypes |
| 1300 |
| 1301 **Updates**:: |
| 1302 |
| 1303 ++NumTypes; |
| 1304 TypeOf(@tN) = float; |
| 1305 |
| 1306 **Examples**:: |
| 1307 |
| 1308 40:0| 1: <65535, 17, 2> | types { // BlockID = 17 |
| 1309 48:0| 3: <1, 4> | count 4; |
| 1310 50:4| 3: <4> | @t0 = double; |
| 1311 52:2| 3: <3> | @t1 = float; |
| 1312 54:0| 3: <21, 0, 0, 1> | @t2 = double (float); |
| 1313 58:0| 3: <2> | @t3 = void; |
| 1314 59:6| 0: <65534> | } |
| 1315 |
| 1316 64-bit Floating Point Type |
| 1317 -------------------------- |
| 1318 |
| 1319 PNaClAsm allows computation on 64-bit floating point values. A 64-bit floating |
| 1320 type record defines the 64-bit floating point type. |
| 1321 |
| 1322 **Syntax**:: |
| 1323 |
| 1324 @tN = double; <A> |
| 1325 |
| 1326 **Record**:: |
| 1327 |
| 1328 AA: <4> |
| 1329 |
| 1330 **Semantics**: |
| 1331 |
| 1332 A double type record defines the 64-bit floating point type. |
| 1333 |
| 1334 **Constraints**:: |
| 1335 |
| 1336 AA == AbbrevIndex(A) & |
| 1337 N == NumTypes |
| 1338 |
| 1339 **Updates**:: |
| 1340 |
| 1341 ++NumTypes; |
| 1342 TypeOf(@tN) = double; |
| 1343 |
| 1344 **Examples**:: |
| 1345 |
| 1346 40:0| 1: <65535, 17, 2> | types { // BlockID = 17 |
| 1347 48:0| 3: <1, 4> | count 4; |
| 1348 50:4| 3: <4> | @t0 = double; |
| 1349 52:2| 3: <3> | @t1 = float; |
| 1350 54:0| 3: <21, 0, 0, 1> | @t2 = double (float); |
| 1351 58:0| 3: <2> | @t3 = void; |
| 1352 59:6| 0: <65534> | } |
| 1353 |
| 1354 Vector Types |
| 1355 ------------ |
| 1356 |
| 1357 A vector type is a derived type that represents a vector of elements. Vector |
| 1358 types are used when multiple primitive data values are operated in parallel |
| 1359 using a single (SIMD) :ref:`vector instruction<link_for_vector_instructions>`. A |
| 1360 vector type requires a size (number of elements) and an underlying primitive |
| 1361 data type. |
| 1362 |
| 1363 **Syntax**:: |
| 1364 |
| 1365 @tN = < E x T > <A> |
| 1366 |
| 1367 **Record**:: |
| 1368 |
| 1369 AA: <12, E, TT> |
| 1370 |
| 1371 **Semantics**: |
| 1372 |
| 1373 The vector type defines a vector of elements. ``T`` is the type of each |
| 1374 element. ``E`` is the number of elements in the vector. |
| 1375 |
| 1376 Vector types can only be defined on ``i1``, ``i8``, ``i16``, ``i32``, and |
| 1377 ``float``. All vector types, except those on ``i1``, must contain exactly 128 |
| 1378 bits. The valid element sizes are restricted as follows: |
| 1379 |
| 1380 ====== =================== |
| 1381 Type Valid element sizes |
| 1382 ====== =================== |
| 1383 i1 4, 8, 16 |
| 1384 i8 16 |
| 1385 i16 8 |
| 1386 i32 4 |
| 1387 float 4 |
| 1388 ====== =================== |
| 1389 |
| 1390 **Constraints**:: |
| 1391 |
| 1392 AA == AbbrevIndex(A) & |
| 1393 TT == AbsoluteIndex(TypeID(T)) & |
| 1394 N == NumTypes |
| 1395 |
| 1396 **Updates**:: |
| 1397 |
| 1398 ++NumTypes |
| 1399 TypeOf(@tN) = <E x T> |
| 1400 |
| 1401 **Examples**:: |
| 1402 |
| 1403 40:0| 1: <65535, 17, 2> | types { // BlockID = 17 |
| 1404 48:0| 3: <1, 14> | count 14; |
| 1405 50:4| 3: <7, 32> | @t0 = i32; |
| 1406 53:6| 3: <7, 1> | @t1 = i1; |
| 1407 56:2| 3: <2> | @t2 = void; |
| 1408 58:0| 3: <12, 4, 1> | @t3 = <4 x i1>; |
| 1409 61:2| 3: <12, 8, 1> | @t4 = <8 x i1>; |
| 1410 64:4| 3: <12, 16, 1> | @t5 = <16 x i1>; |
| 1411 67:6| 3: <7, 8> | @t6 = i8; |
| 1412 70:2| 3: <12, 16, 6> | @t7 = <16 x i8>; |
| 1413 73:4| 3: <7, 16> | @t8 = i16; |
| 1414 76:0| 3: <12, 8, 8> | @t9 = <8 x i16>; |
| 1415 79:2| 3: <12, 4, 0> | @t10 = <4 x i32>; |
| 1416 82:4| 3: <3> | @t11 = float; |
| 1417 84:2| 3: <12, 4, 11> | @t12 = <4 x float>; |
| 1418 87:4| 3: <21, 0, 2> | @t13 = void (); |
| 1419 90:6| 0: <65534> | } |
| 1420 |
| 1421 .. _link_for_function_type: |
| 1422 |
| 1423 Function Type |
| 1424 ------------- |
| 1425 |
| 1426 The *function* type can be thought of as a function signature. It consists of a |
| 1427 return type, and a (possibly empty) list of formal parameter types. |
| 1428 |
| 1429 **Syntax**:: |
| 1430 |
| 1431 %tN = RT (T1, ... , TM) <A> |
| 1432 |
| 1433 **Record**:: |
| 1434 |
| 1435 AA: <21, 0, IRT, IT1, ... , ITM> |
| 1436 |
| 1437 **Semantics**: |
| 1438 |
| 1439 The function type defines the signature of a function. ``RT`` is the return type |
| 1440 of the function, while types ``T1`` through ``TM`` are the types of the |
| 1441 arguments. Indices to the corresponding type identifiers are stored in the |
| 1442 corresponding record. |
| 1443 |
| 1444 The return value must either be a primitive type, type ``void``, or a vector |
| 1445 type. Parameter types can be a primitive or vector type. |
| 1446 |
| 1447 For ordinary functions, the only valid integer types that can be used for a |
| 1448 return or parameter type are ``i32`` and ``i64``. All other integer types are |
| 1449 not allowed. |
| 1450 |
| 1451 For :ref:`intrinsic functions<link_for_intrinsic_functions_section>`, all |
| 1452 integer types are allowed for both return and parameter types. |
| 1453 |
| 1454 **Constraints**:: |
| 1455 |
| 1456 AA == AbbrevIndex(A) & |
| 1457 M >= 0 & |
| 1458 IRT == AbsoluteIndex(TypeID(RT)) & |
| 1459 IT1 == AbsoluteIndex(TypeID(T1)) & |
| 1460 ... |
| 1461 ITM == AbsoluteIndex(TypeID(TM)) & |
| 1462 N == NumTypes |
| 1463 |
| 1464 **Updates**:: |
| 1465 |
| 1466 ++NumTypes |
| 1467 TypeOf(@tN) = RT (T1, ... , TM) |
| 1468 |
| 1469 **Examples**:: |
| 1470 |
| 1471 40:0| 1: <65535, 17, 2> | types { // BlockID = 17 |
| 1472 48:0| 3: <1, 7> | count 7; |
| 1473 50:4| 3: <7, 32> | @t0 = i32; |
| 1474 53:6| 3: <3> | @t1 = float; |
| 1475 55:4| 3: <4> | @t2 = double; |
| 1476 57:2| 3: <21, 0, 2, 1> | @t3 = double (float); |
| 1477 61:2| 3: <2> | @t4 = void; |
| 1478 63:0| 3: <21, 0, 4> | @t5 = void (); |
| 1479 66:2| 3: <21, 0, 0, 0, 1, 0, 2>| @t6 = |
| 1480 | | i32 (i32, float, i32, double); |
| 1481 72:4| 0: <65534> | } |
| 1482 |
| 1483 .. _link_for_globals_block_section: |
| 1484 |
| 1485 Globals Block |
| 1486 ============= |
| 1487 |
| 1488 The globals block defines global addresses of variables and constants, used by |
| 1489 the PNaCl program. It also defines the memory associated with the global |
| 1490 addresses, and how to initialize each global variable/constant. It must appear |
| 1491 in the :ref:`module block<link_for_module_block>`. It must appear after the |
| 1492 :ref:`types block<link_for_types_block_section>`, as well as after all |
| 1493 :ref:`function address<link_for_function_address_section>` records. But, it must |
| 1494 also appear before the :ref:`valuesymtab |
| 1495 block<link_for_valuesymtab_block_section>`, and any |
| 1496 :ref:`function blocks<link_for_function_blocks_section>`. |
| 1497 |
| 1498 The globals block begins with a :ref:`count |
| 1499 record<link_for_globals_count_record>`, defining how many global addresses are |
| 1500 defined by the PNaCl program. It is then followed by a sequence of records that |
| 1501 defines each global address, and how each global address is initialized. |
| 1502 |
| 1503 The standard sequence, for defining global addresses, begins with a global |
| 1504 address record. It is then followed by a sequence of records defining how the |
| 1505 global address is initialized. If the initializer is simple, a single record is |
| 1506 used. Otherwise, the initializer is preceded with a :ref:`compound |
| 1507 record<link_for_compound_initializer>`, specifying a number *N*, followed by |
| 1508 sequence of *N* simple initializer records. |
| 1509 |
| 1510 The size of the memory referenced by each global address is defined by its |
| 1511 initializer records. All simple initializer records define a sequence of |
| 1512 bytes. A compound initializer defines the sequence of bytes by concatenating the |
| 1513 corresponding sequence of bytes for each of its simple initializer records. |
| 1514 |
| 1515 For notational convenience, PNaClAsm begins a compound record with a "{", and |
| 1516 inserts a "}" after the last initializer record associated with the compound |
| 1517 record. This latter "}" does not correspond to any record. It is implicitly |
| 1518 assumed by the size specified in the compound record, and is added only to |
| 1519 improve readability. |
| 1520 |
| 1521 Explicit alignment is specified for global addresses, and must be a power of |
| 1522 2. See :ref:`memory blocks and |
| 1523 alignment<link_for_memory_blocks_and_alignment_section>` for a more detailed |
| 1524 discussion on how to define alignment. |
| 1525 |
| 1526 For example, consider the following pnacl-bcdis output snippet:: |
| 1527 |
| 1528 52:0| 1: <65535, 19, 2> | globals { // BlockID = 19 |
| 1529 60:0| 3: <5, 2> | count 2; |
| 1530 62:4| 3: <0, 1, 1> | const @g0, align 1, |
| 1531 65:6| 3: <2, 8> | zerofill 8; |
| 1532 68:2| 3: <0, 1, 0> | var @g1, align 1, |
| 1533 71:4| 3: <1, 2> | initializers 2 { |
| 1534 74:0| 3: <3, 1, 2, 3, 4> | { 1, 2, 3, 4} |
| 1535 78:6| 3: <2, 2> | zerofill 2; |
| 1536 | | } |
| 1537 81:2| 0: <65534> | } |
| 1538 |
| 1539 This snippet defines the global constant ``@g0``, and the global variable |
| 1540 ``@g1``. ``@g0`` is 8 bytes long, and initialized to zero. ``@g1`` is |
| 1541 initialized with 6 bytes: ``1 2 3 4 0 0``. |
| 1542 |
| 1543 .. _link_for_globals_count_record: |
| 1544 |
| 1545 Count Record |
| 1546 ------------ |
| 1547 |
| 1548 The count record defines the number of global addresses used by the PNaCl |
| 1549 program. |
| 1550 |
| 1551 **Syntax**:: |
| 1552 |
| 1553 count N; <A> |
| 1554 |
| 1555 **Record**:: |
| 1556 |
| 1557 AA: <5, N> |
| 1558 |
| 1559 **Semantics**: |
| 1560 |
| 1561 This record must appear first in the globals block. The count record defines |
| 1562 the number of global addresses used by the program. |
| 1563 |
| 1564 **Constraints**:: |
| 1565 |
| 1566 AA == AbbrevIndex(A) |
| 1567 |
| 1568 **Updates**:: |
| 1569 |
| 1570 ExpectedGlobals = N; |
| 1571 ExpectedInitializers = 0; |
| 1572 |
| 1573 **Examples**:: |
| 1574 |
| 1575 52:0| 1: <65535, 19, 2> | globals { // BlockID = 19 |
| 1576 60:0| 3: <5, 2> | count 2; |
| 1577 62:4| 3: <0, 1, 1> | const @g0, align 1, |
| 1578 65:6| 3: <2, 8> | zerofill 8; |
| 1579 68:2| 3: <0, 1, 0> | var @g1, align 1, |
| 1580 71:4| 3: <1, 2> | initializers 2 { |
| 1581 74:0| 3: <3, 1, 2, 3, 4> | { 1, 2, 3, 4} |
| 1582 78:6| 3: <2, 2> | zerofill 2; |
| 1583 | | } |
| 1584 81:2| 0: <65534> | } |
| 1585 |
| 1586 .. _link_for_global_variable_address: |
| 1587 |
| 1588 Global Variable Addresses |
| 1589 ------------------------- |
| 1590 |
| 1591 A global variable address record defines a global address to global data. The |
| 1592 global variable address record must be immediately followed by initializer |
| 1593 record(s) that define how the corresponding global variable is initialized. |
| 1594 |
| 1595 **Syntax**:: |
| 1596 |
| 1597 var @gN, align V, <A> |
| 1598 |
| 1599 **Record**:: |
| 1600 |
| 1601 AA: <0, VV, 0> |
| 1602 |
| 1603 **Semantics**: |
| 1604 |
| 1605 A global variable address record defines a global address for a global variable. |
| 1606 ``V`` is the :ref:`memory |
| 1607 alignment<link_for_memory_blocks_and_alignment_section>` for the global variable |
| 1608 address, and is a power of 2. |
| 1609 |
| 1610 It is assumed that the memory, referenced by the global variable address, can be |
| 1611 both read and written to. |
| 1612 |
| 1613 **Constraints**:: |
| 1614 |
| 1615 AA == AbbrevIndex(A) & |
| 1616 N == NumGlobalAddresses & |
| 1617 ExpectedInitializers == 0 & |
| 1618 VV == Log2(V+1) |
| 1619 |
| 1620 **Updates**:: |
| 1621 |
| 1622 ++NumGlobalAddresses; |
| 1623 ExpectedInitializers = 1; |
| 1624 TypeOf(@gN) = i32; |
| 1625 |
| 1626 **Examples**:: |
| 1627 |
| 1628 52:0| 1: <65535, 19, 2> | globals { // BlockID = 19 |
| 1629 60:0| 3: <5, 2> | count 2; |
| 1630 62:4| 3: <0, 3, 0> | var @g0, align 4, |
| 1631 65:6| 3: <2, 8> | zerofill 8; |
| 1632 68:2| 3: <0, 1, 0> | var @g1, align 1, |
| 1633 71:4| 3: <3, 1, 2, 3, 4> | { 1, 2, 3, 4} |
| 1634 76:2| 0: <65534> | } |
| 1635 80:0|0: <65534> |} |
| 1636 |
| 1637 .. _link_for_global_constant_address: |
| 1638 |
| 1639 Global Constant Addresses |
| 1640 ------------------------- |
| 1641 |
| 1642 A global constant address record defines an address corresponding to a global |
| 1643 constant that can't be modified by the program. The global constant address |
| 1644 record must be immediately followed by initializer record(s) that define how |
| 1645 the corresponding global constant is initialized. |
| 1646 |
| 1647 **Syntax**:: |
| 1648 |
| 1649 const @gN, align V, <A> |
| 1650 |
| 1651 **Record**:: |
| 1652 |
| 1653 AA: <0, VV, 1> |
| 1654 |
| 1655 **Semantics**: |
| 1656 |
| 1657 A global constant address record defines a global address for a global constant. |
| 1658 ``V`` is the :ref:`memory |
| 1659 alignment<link_for_memory_blocks_and_alignment_section>` for the global constant |
| 1660 address, and is a power of 2. |
| 1661 |
| 1662 It is assumed that the memory, referenced by the global constant address, is |
| 1663 only read, and can't be written to. |
| 1664 |
| 1665 Note that the only difference between a global variable address and a global |
| 1666 constant address record is the third element of the record. If the value is |
| 1667 zero, it defines a global variable address. If the value is one, it defines a |
| 1668 global constant address. |
| 1669 |
| 1670 **Constraints**:: |
| 1671 |
| 1672 AA == AbbrevIndex(A) & |
| 1673 N == NumGlobalAddresses & |
| 1674 ExpectedInitializers == 0 & |
| 1675 VV == Log2(V+1) |
| 1676 |
| 1677 **Updates**:: |
| 1678 |
| 1679 ++NumGlobalAddresses; |
| 1680 ExpectedInitializers = 1; |
| 1681 TypeOf(@gN) = i32; |
| 1682 |
| 1683 **Examples**:: |
| 1684 |
| 1685 52:0| 1: <65535, 19, 2> | globals { // BlockID = 19 |
| 1686 60:0| 3: <5, 2> | count 2; |
| 1687 62:4| 3: <0, 3, 1> | const @g0, align 4, |
| 1688 65:6| 3: <2, 8> | zerofill 8; |
| 1689 68:2| 3: <0, 1, 1> | const @g1, align 1, |
| 1690 71:4| 3: <3, 1, 2, 3, 4> | { 1, 2, 3, 4} |
| 1691 76:2| 0: <65534> | } |
| 1692 |
| 1693 Zerofill Initializer |
| 1694 -------------------- |
| 1695 |
| 1696 The zerofill initializer record initializes a sequence of bytes, associated with |
| 1697 a global address, with zeros. |
| 1698 |
| 1699 **Syntax**:: |
| 1700 |
| 1701 zerofill N; <A> |
| 1702 |
| 1703 **Record**:: |
| 1704 |
| 1705 AA: <2, N> |
| 1706 |
| 1707 **Semantics**: |
| 1708 |
| 1709 A zerofill initializer record initializes a sequence of bytes, associated with a |
| 1710 global address, with zeros. The number of bytes initialized to zero is ``N``. |
| 1711 |
| 1712 **Constraints**:: |
| 1713 |
| 1714 AA == AbbrevIndex(A) & |
| 1715 ExpectedInitializers > 0 |
| 1716 |
| 1717 **Updates**:: |
| 1718 |
| 1719 --ExpectedInitializers; |
| 1720 |
| 1721 **Examples**:: |
| 1722 |
| 1723 52:0| 1: <65535, 19, 2> | globals { // BlockID = 19 |
| 1724 60:0| 3: <5, 2> | count 2; |
| 1725 62:4| 3: <0, 3, 1> | const @g0, align 4, |
| 1726 65:6| 3: <2, 8> | zerofill 8; |
| 1727 68:2| 3: <0, 1, 0> | var @g1, align 1, |
| 1728 71:4| 3: <2, 4> | zerofill 4; |
| 1729 74:0| 0: <65534> | } |
| 1730 |
| 1731 Data Initializer |
| 1732 ---------------- |
| 1733 |
| 1734 Data records define a sequence of bytes. These bytes define the initial value of |
| 1735 the contents of the corresponding memory. |
| 1736 |
| 1737 **Syntax**:: |
| 1738 |
| 1739 { B1 , .... , BN } <A> |
| 1740 |
| 1741 **Record**:: |
| 1742 |
| 1743 AA: <3, B1, ..., BN> |
| 1744 |
| 1745 **Semantics**: |
| 1746 |
| 1747 A data record defines a sequence of (unsigned) bytes ``B1`` through ``BN``, that |
| 1748 initialize ``N`` bytes of memory. |
| 1749 |
| 1750 **Constraints**:: |
| 1751 |
| 1752 AA == AbbrevIndex(A) & |
| 1753 ExpectedInitializers > 0 |
| 1754 |
| 1755 **Updates**:: |
| 1756 |
| 1757 --ExpectedInitializers; |
| 1758 |
| 1759 **Examples**:: |
| 1760 |
| 1761 56:0| 3: <8, 1, 0, 1, 0> | declare external void @f0(); |
| 1762 60:6| 1: <65535, 19, 2> | globals { // BlockID = 19 |
| 1763 68:0| 3: <5, 2> | count 2; |
| 1764 70:4| 3: <0, 1, 1> | const @g0, align 1, |
| 1765 73:6| 3: <3, 1, 2, 97, 36, 44, | { 1, 2, 97, 36, 44, 88, |
| 1766 | 88, 44, 50> | 44, 50} |
| 1767 86:0| 3: <0, 1, 1> | const @g1, align 1, |
| 1768 89:2| 3: <1, 3> | initializers 3 { |
| 1769 91:6| 3: <3, 1, 2, 3, 4> | { 1, 2, 3, 4} |
| 1770 96:4| 3: <4, 0> | reloc @f0; |
| 1771 99:0| 3: <3, 99, 66, 22, 12> | { 99, 66, 22, 12} |
| 1772 | | } |
| 1773 105:2| 0: <65534> | } |
| 1774 |
| 1775 Relocation Initializer |
| 1776 ---------------------- |
| 1777 |
| 1778 A relocation initializer record allows one to define the initial value of a |
| 1779 global address with the value of another global address (i.e. either |
| 1780 :ref:`function<link_for_function_address_section>`, |
| 1781 :ref:`variable<link_for_global_variable_address>`, or |
| 1782 :ref:`constant<link_for_global_constant_address>`). Since addresses are |
| 1783 pointers, a relocation initializer record defines 4 bytes of memory. |
| 1784 |
| 1785 **Syntax**:: |
| 1786 |
| 1787 reloc V; <A> |
| 1788 |
| 1789 **Record**:: |
| 1790 |
| 1791 AA: <4, VV> |
| 1792 |
| 1793 **Semantics**: |
| 1794 |
| 1795 A relocation initializer record defines a 4-byte value containing the specified |
| 1796 global address ``V``. |
| 1797 |
| 1798 **Constraints**:: |
| 1799 |
| 1800 AA == AbbrevIndex(A) & |
| 1801 VV == AbsoluteIndex(V) & |
| 1802 VV >= NumFuncAddresses & |
| 1803 VV < NumFuncAddresses + ExpectedGlobals & |
| 1804 ExpectedInitializers > 0 |
| 1805 |
| 1806 **Updates**:: |
| 1807 |
| 1808 --ExpectedInitializers; |
| 1809 |
| 1810 **Examples**:: |
| 1811 |
| 1812 40:0| 1: <65535, 17, 2> | types { // BlockID = 17 |
| 1813 48:0| 3: <1, 2> | count 2; |
| 1814 50:4| 3: <2> | @t0 = void; |
| 1815 52:2| 3: <21, 0, 0> | @t1 = void (); |
| 1816 55:4| 0: <65534> | } |
| 1817 56:0| 3: <8, 1, 0, 1, 0> | declare external void @f0(); |
| 1818 60:6| 1: <65535, 19, 2> | globals { // BlockID = 19 |
| 1819 68:0| 3: <5, 2> | count 2; |
| 1820 70:4| 3: <0, 1, 0> | var @g0, align 1, |
| 1821 73:6| 3: <1, 3> | initializers 3 { |
| 1822 76:2| 3: <4, 0> | reloc @f0; |
| 1823 78:6| 3: <4, 1> | reloc @g0; |
| 1824 81:2| 3: <4, 2> | reloc @g1; |
| 1825 | | } |
| 1826 83:6| 3: <0, 3, 0> | var @g1, align 4, |
| 1827 87:0| 3: <2, 4> | zerofill 4; |
| 1828 89:4| 0: <65534> | } |
| 1829 |
| 1830 This example defines global address ``@g0`` and ``@g1``. ``@g0`` defines 12 |
| 1831 bytes of memory, and is initialized with three addresses ``@f1``, ``@g0``, and |
| 1832 ``@g1``. Note that all global addresses can be used in a relocation |
| 1833 initialization record, even if it isn't defined yet. |
| 1834 |
| 1835 Subfield Relocation Initializer |
| 1836 ------------------------------- |
| 1837 |
| 1838 A subfield relocation initializer record allows one to define the initial value |
| 1839 of a global address with the value of another (non-function) global address |
| 1840 (i.e. either :ref:`variable<link_for_global_variable_address>` or |
| 1841 :ref:`constant<link_for_global_constant_address>` address), plus a |
| 1842 constant. Since addresses are pointers, a relocation initializer record defines |
| 1843 4 bytes of memory. |
| 1844 |
| 1845 **Syntax**:: |
| 1846 |
| 1847 reloc V + X; <A> |
| 1848 reloc V - X; <A> |
| 1849 |
| 1850 **Record**:: |
| 1851 |
| 1852 AA: <4, VV, XXX> |
| 1853 |
| 1854 **Semantics**: |
| 1855 |
| 1856 A subfield relocation initializer record defines a 4-byte value containing the |
| 1857 specified global (non-function) address ``V``, modified by the unsigned offset |
| 1858 ``X``. ``XX`` is the corresponding signed offset. In the first form, ``XX == |
| 1859 X``. In the second form, ``XX == -X``. |
| 1860 |
| 1861 **Constraints**:: |
| 1862 |
| 1863 AA == AbbrevIndex(A) |
| 1864 VV == AbsoluteIndex(V) |
| 1865 VV >= NumFuncAddresses |
| 1866 VV < NumFuncAddresses + ExpectedGlobals |
| 1867 ExpectedInitializers > 0 |
| 1868 XXX == SignRotate(XX) |
| 1869 |
| 1870 **Updates**:: |
| 1871 |
| 1872 --ExpectedInitializers; |
| 1873 |
| 1874 **Examples**:: |
| 1875 |
| 1876 40:0| 1: <65535, 17, 2> | types { // BlockID = 17 |
| 1877 48:0| 3: <1, 0> | count 0; |
| 1878 50:4| 0: <65534> | } |
| 1879 52:0| 1: <65535, 19, 2> | globals { // BlockID = 19 |
| 1880 60:0| 3: <5, 3> | count 3; |
| 1881 62:4| 3: <0, 1, 0> | var @g0, align 1, |
| 1882 65:6| 3: <1, 3> | initializers 3 { |
| 1883 68:2| 3: <4, 0, 1> | reloc @g0 + 1; |
| 1884 71:4| 3: <4, 1, 4294967295> | reloc @g1 - 1; |
| 1885 79:2| 3: <4, 2, 4> | reloc @g2 + 4; |
| 1886 | | } |
| 1887 82:4| 3: <0, 3, 0> | var @g1, align 4, |
| 1888 85:6| 3: <2, 4> | zerofill 4; |
| 1889 88:2| 3: <0, 3, 0> | var @g2, align 4, |
| 1890 91:4| 3: <2, 8> | zerofill 8; |
| 1891 94:0| 0: <65534> | } |
| 1892 |
| 1893 .. _link_for_compound_initializer: |
| 1894 |
| 1895 Compound Initializer |
| 1896 -------------------- |
| 1897 |
| 1898 The compound initializer record must immediately follow a global |
| 1899 :ref:`variable<link_for_global_variable_address>` or |
| 1900 :ref:`constant<link_for_global_constant_address>` address record. It defines how |
| 1901 many simple initializer records are used to define the initializer. The size of |
| 1902 the corresponding memory is the sum of the bytes needed for each of the |
| 1903 succeeding initializers. |
| 1904 |
| 1905 Note that a compound initializer can't be used as a simple initializer of |
| 1906 another compound initializer (i.e. nested compound initializers are not |
| 1907 allowed). |
| 1908 |
| 1909 **Syntax**:: |
| 1910 |
| 1911 initializers N { <A> |
| 1912 ... |
| 1913 } |
| 1914 |
| 1915 **Record**:: |
| 1916 |
| 1917 AA: <1, N> |
| 1918 |
| 1919 **Semantics**: |
| 1920 |
| 1921 Defines that the next `N` initializers should be associated with the global |
| 1922 address of the previous record. |
| 1923 |
| 1924 **Constraints**:: |
| 1925 |
| 1926 AA == AbbrevIndex(A) & |
| 1927 ExpectedInitializers == 1 |
| 1928 |
| 1929 **Updates**:: |
| 1930 |
| 1931 ExpectedInitializers = N; |
| 1932 |
| 1933 **Examples**:: |
| 1934 |
| 1935 40:0| 1: <65535, 17, 2> | types { // BlockID = 17 |
| 1936 48:0| 3: <1, 0> | count 0; |
| 1937 50:4| 0: <65534> | } |
| 1938 52:0| 1: <65535, 19, 2> | globals { // BlockID = 19 |
| 1939 60:0| 3: <5, 2> | count 2; |
| 1940 62:4| 3: <0, 0, 1> | const @g0, align 0, |
| 1941 65:6| 3: <1, 2> | initializers 2 { |
| 1942 68:2| 3: <2, 8> | zerofill 8; |
| 1943 70:6| 3: <3, 3, 2, 1, 0> | { 3, 2, 1, 0} |
| 1944 | | } |
| 1945 75:4| 3: <0, 0, 0> | var @g1, align 0, |
| 1946 78:6| 3: <1, 2> | initializers 2 { |
| 1947 81:2| 3: <3, 1, 2, 3, 4> | { 1, 2, 3, 4} |
| 1948 86:0| 3: <2, 2> | zerofill 2; |
| 1949 | | } |
| 1950 88:4| 0: <65534> | } |
| 1951 |
| 1952 .. _link_for_valuesymtab_block_section: |
| 1953 |
| 1954 Valuesymtab Block |
| 1955 ================= |
| 1956 |
| 1957 The valuesymtab block does not define any values. Its only goal is to associate |
| 1958 text names with external :ref:`function |
| 1959 addresses<link_for_function_address_section>`. Each association is defined by a |
| 1960 record in the valuesymtab block. Currently, only |
| 1961 :ref:`intrinsic<link_for_intrinsic_functions_section>` function addresses and |
| 1962 the (external) start function (``_start``) can be named. All named function |
| 1963 addresses must be external. Each record in the valuesymtab block is a *entry* |
| 1964 record, defining a single name association. |
| 1965 |
| 1966 Entry Record |
| 1967 ------------ |
| 1968 |
| 1969 The *entry* record defines a name for a function address. |
| 1970 |
| 1971 **Syntax**:: |
| 1972 |
| 1973 V : "NAME"; <A> |
| 1974 |
| 1975 **Record**:: |
| 1976 |
| 1977 AA: <1, B1, ... , BN> |
| 1978 |
| 1979 **Semantics**: |
| 1980 |
| 1981 The *entry* record defines a name ``NAME`` for function address ``V``. ``NAME`` |
| 1982 is a sequence of ASCII characters ``B1`` through ``BN``. |
| 1983 |
| 1984 **Examples**:: |
| 1985 |
| 1986 72:0| 3: <8, 4, 0, 1, 0> | declare external |
| 1987 | | void @f0(i32, i32, i32, i32, i1); |
| 1988 76:6| 3: <8, 4, 0, 1, 0> | declare external |
| 1989 | | void @f1(i32, i32, i32, i32, i1); |
| 1990 81:4| 3: <8, 5, 0, 0, 0> | define external void @f2(i32); |
| 1991 86:2| 1: <65535, 19, 2> | globals { // BlockID = 19 |
| 1992 92:0| 3: <5, 0> | count 0; |
| 1993 94:4| 0: <65534> | } |
| 1994 96:0| 1: <65535, 14, 2> | valuesymtab { // BlockID = 14 |
| 1995 104:0| 3: <1, 1, 108, 108, 118, | @f1 : "llvm.memmove.p0i8.p0i8.i32"; |
| 1996 | 109, 46, 109, 101, | |
| 1997 | 109, 109, 111, 118, | |
| 1998 | 101, 46, 112, 48, | |
| 1999 | 105, 56, 46, 112, 48,| |
| 2000 | 105, 56, 46, 105, 51,| |
| 2001 | 50> | |
| 2002 145:4| 3: <1, 2, 95, 115, 116, | @f2 : "_start"; |
| 2003 | 97, 114, 116> | |
| 2004 157:0| 3: <1, 0, 108, 108, 118, | @f0 : "llvm.memcpy.p0i8.p0i8.i32"; |
| 2005 | 109, 46, 109, 101, | |
| 2006 | 109, 99, 112, 121, | |
| 2007 | 46, 112, 48, 105, 56,| |
| 2008 | 46, 112, 48, 105, 56,| |
| 2009 | 46, 105, 51, 50> | |
| 2010 197:0| 0: <65534> | } |
| 2011 |
| 2012 .. _link_for_module_block: |
| 2013 |
| 2014 Module Block |
| 2015 ============ |
| 2016 |
| 2017 The module block, like all blocks, is enclosed in a pair of |
| 2018 :ref:`enter<link_for_enter_block_record_section>` / |
| 2019 :ref:`exit<link_for_exit_block_record_section>` records, using block ID 8. A |
| 2020 well-formed module block consists of the following records (in order): |
| 2021 |
| 2022 A version record |
| 2023 The :ref:`version record<link_for_version_record>` communicates which version |
| 2024 of the PNaCl bitcode reader/writer should be used. Note that this is |
| 2025 different than the PNaCl bitcode (ABI) version. The PNaCl bitcode (ABI) |
| 2026 version defines what is expected in records, and is defined in the header |
| 2027 record of the bitcode file. The version record defines the version of the |
| 2028 PNaCl bitcode reader/writer to use to convert records into bit sequences. |
| 2029 |
| 2030 Optional local abbreviations |
| 2031 Defines a list of local :ref:`abbreviations<link_for_abbreviations_section>` |
| 2032 to use for records within the module block. |
| 2033 |
| 2034 An abbreviations block |
| 2035 The :ref:`abbreviations block<link_for_abbreviations_block_section>` defines |
| 2036 user-defined, global abbreviations that are used to convert PNaCl records to |
| 2037 bit sequences in blocks following the abbreviations block. |
| 2038 |
| 2039 A types block |
| 2040 The :ref:`types block<link_for_types_block_section>` defines the set of all |
| 2041 types used in the program. |
| 2042 |
| 2043 A non-empty sequence of function address records |
| 2044 Each record defines a :ref:`function |
| 2045 address<link_for_function_address_section>` used by the program. Function |
| 2046 addresses must either be external, or defined internally by the program. If |
| 2047 they are defined by the program, there must be a :ref:`function |
| 2048 block<link_for_function_blocks_section>` (appearing later in the module) that |
| 2049 defines the sequence of instructions for each defined function. |
| 2050 |
| 2051 A globals block defining the global variables. |
| 2052 This :ref:`block<link_for_globals_block_section>` defines the set of |
| 2053 global :ref:`variable<link_for_global_variable_address>` and |
| 2054 :ref:`constant<link_for_global_constant_address>` addresses used by the |
| 2055 program. In addition to the addresses, each global variable also defines how |
| 2056 the corresponding global variable is initialized. |
| 2057 |
| 2058 An optional value symbol table block. |
| 2059 This :ref:`block<link_for_valuesymtab_block_section>`, if defined, provides |
| 2060 textual names for :ref:`function |
| 2061 addresses<link_for_function_address_section>` (previously defined in the |
| 2062 module). Note that only names for intrinsic functions and the start function |
| 2063 are specified. |
| 2064 |
| 2065 A sequence of function blocks. |
| 2066 Each :ref:`function block<link_for_Function_blocks_section>` defines the |
| 2067 corresponding intermediate representation for each defined function. The |
| 2068 order of function blocks is used to associate them with :ref:`function |
| 2069 addresses<link_for_function_address_section>`. The order of the defined |
| 2070 function blocks must follow the same order as the corresponding function |
| 2071 addresses defined in the module block. |
| 2072 |
| 2073 Descriptions of the :ref:`abbreviations<link_for_abbreviations_section>`, |
| 2074 :ref:`types<link_for_types_block_section>`, |
| 2075 :ref:`globals<link_for_globals_block_section>`, :ref:`value symbol |
| 2076 table<link_for_valuesymtab_block_section>`, and |
| 2077 :ref:`function<link_for_function_blocks_section>` blocks are not provided |
| 2078 here. See the appropriate reference for more details. The following subsections |
| 2079 describe each of the records that can appear in a module block. |
| 2080 |
| 2081 .. _link_for_version_record: |
| 2082 |
| 2083 Version Record |
| 2084 -------------- |
| 2085 |
| 2086 The version record defines the implementation of the PNaCl bitstream |
| 2087 reader/writer to use. That is, the implementation that converts PNaCl records to |
| 2088 bit sequences, and converts them back to PNaCl records. Note that this is |
| 2089 different than the PNaCl version of the bitcode file (encoded in the header |
| 2090 record of the bitcode file). The PNaCl version defines the valid forms of PNaCl |
| 2091 records. The version record is specific to the PNaCl version, and may have |
| 2092 different values for different PNaCl versions. |
| 2093 |
| 2094 Note that currently, only PNaCl bitcode version 2, and version record value 1 is |
| 2095 defined. |
| 2096 |
| 2097 **Syntax**:: |
| 2098 |
| 2099 version N; <A> |
| 2100 |
| 2101 **Record**:: |
| 2102 |
| 2103 AA: <1, N> |
| 2104 |
| 2105 **Semantics**: |
| 2106 |
| 2107 The version record defines which PNaCl reader/writer rules should be |
| 2108 followed. ``N`` is the version number. Currently ``N`` must be 1. Future |
| 2109 versions of PNaCl may define additional legal values. |
| 2110 |
| 2111 **Constraints**:: |
| 2112 |
| 2113 AA == AbbrevIndex(A) |
| 2114 |
| 2115 *Examples*:: |
| 2116 |
| 2117 16:0|1: <65535, 8, 2> |module { // BlockID = 8 |
| 2118 24:0| 3: <1, 1> | version 1; |
| 2119 26:4| 1: <65535, 0, 2> | abbreviations { // BlockID = 0 |
| 2120 36:0| 0: <65534> | } |
| 2121 |
| 2122 .. _link_for_function_address_section: |
| 2123 |
| 2124 Function Address |
| 2125 ---------------- |
| 2126 |
| 2127 A function address record describes a function address. *Defined* function |
| 2128 addresses define :ref:`implementations<link_for_function_blocks_section>` while |
| 2129 *declared* function addresses do not. |
| 2130 |
| 2131 Since a PNaCl program is assumed to be a complete (statically linked) |
| 2132 executable, All functions should be *defined* and *internal*. The exception to |
| 2133 this are :ref:`intrinsic functions<link_for_intrinsic_functions_section>`, which |
| 2134 should only be *declared* and *external*, since intrinsic functions will be |
| 2135 automatically converted to appropriate code by the :ref:`PNaCl |
| 2136 translator<link_for_pnacl_translator>`. |
| 2137 |
| 2138 The implementation of a *defined* function address is provided by a |
| 2139 corresponding function block, appearing later in the module block. The |
| 2140 association of a *defined* function address with the corresponding function |
| 2141 block is based on position. The *Nth* defined function address record, in the |
| 2142 module block, has its implementation in the *Nth* function block of that module |
| 2143 block. |
| 2144 |
| 2145 **Syntax**:: |
| 2146 |
| 2147 PN LN T0 @fN ( T1 , ... , TM ); <A> |
| 2148 |
| 2149 **Record**:: |
| 2150 |
| 2151 AA: <8, T, C, P, L> |
| 2152 |
| 2153 **Semantics**: |
| 2154 |
| 2155 Describes the function address ``@fN``. ``PN`` is the name that specifies the |
| 2156 prototype value ``P`` associated with the function. A function address is |
| 2157 *defined* only if ``P == 0``. Otherwise, it is only *declared*. The type of the |
| 2158 function is :ref:`function type<link_for_function_type>` ``@tT``. ``L`` is the |
| 2159 linkage specification corresponding to name ``LN``. ``C`` is the calling |
| 2160 convention used by the function. |
| 2161 |
| 2162 Note that function signature must be defined by a function type in the types |
| 2163 block. Hence, the return value must either be a primitive type, type ``void``, |
| 2164 or a vector type. |
| 2165 |
| 2166 For ordinary functions, integer parameter and types can only be ``i32`` and |
| 2167 ``i64``. All other integer types are not allowed. For intrinsic functions, all |
| 2168 integer types are allowed. |
| 2169 |
| 2170 Valid prototype names ``PN``, and corresponding ``P`` values, are: |
| 2171 |
| 2172 = ======= |
| 2173 P PN |
| 2174 = ======= |
| 2175 1 declare |
| 2176 0 define |
| 2177 = ======= |
| 2178 |
| 2179 Valid linkage names ``LN``, and corresponding ``L`` values, are: |
| 2180 |
| 2181 = ======== |
| 2182 L LN |
| 2183 = ======== |
| 2184 3 internal |
| 2185 0 external |
| 2186 = ======== |
| 2187 |
| 2188 Currently, only one calling convention ``C`` is supported: |
| 2189 |
| 2190 = ==================== |
| 2191 C Calling Convention |
| 2192 = ==================== |
| 2193 0 C calling convention |
| 2194 = ==================== |
| 2195 |
| 2196 **Constraints**:: |
| 2197 |
| 2198 AA = AbbrevIndex(A) & |
| 2199 T = TypeID(TypeOf(T0 ( T1 , ... , TN ))) & |
| 2200 N = NumFuncAddresses |
| 2201 |
| 2202 **Updates**:: |
| 2203 |
| 2204 ++NumFuncAddresses; |
| 2205 TypeOf(@fN) = TypeOf(TypeID(i32)); |
| 2206 TypeOfFcn(@fN) = TypeOf(@tT); |
| 2207 |
| 2208 if PN == 0: |
| 2209 DefiningFcnIDs += @FN; |
| 2210 ++NumDefinedFunctionAddresses; |
| 2211 |
| 2212 **Examples**:: |
| 2213 |
| 2214 40:0| 1: <65535, 17, 2> | types { // BlockID = 17 |
| 2215 48:0| 3: <1, 7> | count 7; |
| 2216 50:4| 3: <7, 32> | @t0 = i32; |
| 2217 53:6| 3: <3> | @t1 = float; |
| 2218 55:4| 3: <4> | @t2 = double; |
| 2219 57:2| 3: <2> | @t3 = void; |
| 2220 59:0| 3: <21, 0, 2, 1> | @t4 = double (float); |
| 2221 63:0| 3: <21, 0, 0, 0, 1, 0, 2>| @t5 = |
| 2222 | | i32 (i32, float, i32, double); |
| 2223 69:2| 3: <21, 0, 3> | @t6 = void (); |
| 2224 72:4| 0: <65534> | } |
| 2225 76:0| 3: <8, 4, 0, 1, 0> | declare external double @f0(float); |
| 2226 80:6| 3: <8, 5, 0, 1, 0> | declare external |
| 2227 | | i32 @f1(i32, float, i32, double); |
| 2228 85:4| 3: <8, 6, 0, 0, 0> | define external void @f2(); |
| 2229 |
| 2230 .. _link_for_constants_block_section: |
| 2231 |
| 2232 Constants Blocks |
| 2233 ================ |
| 2234 |
| 2235 Constants blocks define literal constants used within each function. Its intent |
| 2236 is to define them once, before instructions. A constants block can only appear |
| 2237 in a :ref:`function block<link_for_function_blocks_section>`, and must appear |
| 2238 before any instructions in the function block. |
| 2239 |
| 2240 Currently, only integer literals, floating point literals, and undefined vector |
| 2241 constants can be defined. |
| 2242 |
| 2243 To minimize type information put in a constants block, the type information is |
| 2244 separated from the constants. This allows a sequence of constants to be given |
| 2245 the same type. This is done by defining a :ref:`set type |
| 2246 record<link_for_constants_set_type_record>`, followed by a sequence of literal |
| 2247 constants. These literal constants all get converted to the type of the |
| 2248 preceding set type record. |
| 2249 |
| 2250 Note that constants that are used for switch case selectors should not be added |
| 2251 to the constants block, since the switch instruction contains the constants used |
| 2252 for case selectors. All other constants in the function block must be put into a |
| 2253 constants block, so that instructions can use them. |
| 2254 |
| 2255 To make this more concrete, consider the following example constants block:: |
| 2256 |
| 2257 106:4| 1: <65535, 11, 2> | constants { // BlockID = 11 |
| 2258 116:0| 3: <1, 0> | i32: |
| 2259 118:4| 3: <4, 2> | %c0 = i32 1; |
| 2260 121:0| 3: <4, 4> | %c1 = i32 2; |
| 2261 123:4| 3: <1, 2> | i8: |
| 2262 126:0| 3: <4, 8> | %c2 = i8 4; |
| 2263 128:4| 3: <4, 6> | %c3 = i8 3; |
| 2264 131:0| 3: <1, 1> | float: |
| 2265 133:4| 3: <6, 1065353216> | %c4 = float 1; |
| 2266 139:6| 0: <65534> | } |
| 2267 |
| 2268 .. _link_for_constants_set_type_record: |
| 2269 |
| 2270 Set Type Record |
| 2271 --------------- |
| 2272 |
| 2273 The *set type* record defines the type to use for the (immediately) succeeding |
| 2274 literals. |
| 2275 |
| 2276 **Syntax**:: |
| 2277 |
| 2278 T: <A> |
| 2279 |
| 2280 **Record**:: |
| 2281 |
| 2282 AA: <1, TT> |
| 2283 |
| 2284 **Semantics**: |
| 2285 |
| 2286 The *set type* record defines type ``T`` to be used to type the (immediately) |
| 2287 succeeding literals. ``T`` must be a non-void primitive value type or a vector |
| 2288 type. |
| 2289 |
| 2290 **Constraints**:: |
| 2291 |
| 2292 TT == TypeID(T) |
| 2293 |
| 2294 **Updates**:: |
| 2295 |
| 2296 ConstantsSetType = T; |
| 2297 |
| 2298 **Examples**:: |
| 2299 |
| 2300 106:4| 1: <65535, 11, 2> | constants { // BlockID = 11 |
| 2301 116:0| 3: <1, 0> | i32: |
| 2302 118:4| 3: <4, 2> | %c0 = i32 1; |
| 2303 121:0| 3: <4, 4> | %c1 = i32 2; |
| 2304 123:4| 3: <1, 2> | i8: |
| 2305 126:0| 3: <4, 8> | %c2 = i8 4; |
| 2306 128:4| 3: <4, 6> | %c3 = i8 3; |
| 2307 131:0| 3: <1, 1> | float: |
| 2308 133:4| 3: <6, 1065353216> | %c4 = float 1; |
| 2309 139:6| 0: <65534> | } |
| 2310 |
| 2311 .. _link_for_undefined_literal: |
| 2312 |
| 2313 Undefined Literal |
| 2314 ----------------- |
| 2315 |
| 2316 The *undefined* literal record creates an undefined literal for the type *T* |
| 2317 defined by the preceding *set type* record. |
| 2318 |
| 2319 Note: See :ref:`insert element |
| 2320 instruction<link_for_insert_element_instruction_section>` for an example of how |
| 2321 you would use the undefined literal with vector types. |
| 2322 |
| 2323 **Syntax**:: |
| 2324 |
| 2325 %cN = T undef; <50> |
| 2326 |
| 2327 **Record**:: |
| 2328 |
| 2329 AA: <3> |
| 2330 |
| 2331 **Semantics**: |
| 2332 |
| 2333 The *undefined* literal record creates an undefined literal constant ``%cN`` for |
| 2334 type ``T``. ``T`` must be the type defined by the preceding *set type* record, |
| 2335 and be a primitive value type or a vector type. |
| 2336 |
| 2337 **Constraints**:: |
| 2338 |
| 2339 N == NumFcnConsts & |
| 2340 T == ConstantsSetType & |
| 2341 IsPrimitive(T) or IsVector(T) |
| 2342 |
| 2343 **Updates**:: |
| 2344 |
| 2345 ++NumFcnConsts; |
| 2346 TypeOf(%cN) = T; |
| 2347 |
| 2348 **Examples**:: |
| 2349 |
| 2350 40:0| 1: <65535, 17, 2> | types { // BlockID = 17 |
| 2351 48:0| 3: <1, 5> | count 5; |
| 2352 50:4| 3: <7, 32> | @t0 = i32; |
| 2353 53:6| 3: <3> | @t1 = float; |
| 2354 55:4| 3: <2> | @t2 = void; |
| 2355 57:2| 3: <12, 4, 0> | @t3 = <4 x i32>; |
| 2356 60:4| 3: <21, 0, 2> | @t4 = void (); |
| 2357 63:6| 0: <65534> | } |
| 2358 ... |
| 2359 106:4| 1: <65535, 11, 2> | constants { // BlockID = 11 |
| 2360 116:0| 3: <1, 0> | i32: |
| 2361 118:4| 3: <3> | %c0 = i32 undef; |
| 2362 120:2| 3: <4, 2> | %c1 = i32 1; |
| 2363 122:6| 3: <1, 3> | <4 x i32>: |
| 2364 125:2| 3: <3> | %c2 = <4 x i32> undef; |
| 2365 127:0| 3: <1, 1> | float: |
| 2366 129:4| 3: <3> | %c3 = float undef; |
| 2367 131:2| 0: <65534> | } |
| 2368 |
| 2369 .. _link_for_integer_literal: |
| 2370 |
| 2371 Integer Literal |
| 2372 --------------- |
| 2373 |
| 2374 The *integer literal* record creates an integer literal for the integer type *T* |
| 2375 defined by the preceding *set type* record. |
| 2376 |
| 2377 **Syntax**:: |
| 2378 |
| 2379 %cN = T V; <A> |
| 2380 |
| 2381 **Record**:: |
| 2382 |
| 2383 AA: <4, VV> |
| 2384 |
| 2385 **Semantics**: |
| 2386 |
| 2387 The *integer literal* record creates an integer literal constant ``%cN`` for |
| 2388 type ``T``. ``T`` must be the type defined by the preceding *set type* record, |
| 2389 and an integer type. The literal ``V`` can be signed, but must be definable by |
| 2390 type ``T``. |
| 2391 |
| 2392 **Constraints**:: |
| 2393 |
| 2394 N == NumFcnConsts & |
| 2395 T == ConstantsSetType & |
| 2396 VV == SignRotate(V) & |
| 2397 IsInteger(T) |
| 2398 |
| 2399 **Updates**:: |
| 2400 |
| 2401 TypeOf(%cN) = T; |
| 2402 |
| 2403 **Examples**:: |
| 2404 |
| 2405 40:0| 1: <65535, 17, 2> | types { // BlockID = 17 |
| 2406 48:0| 3: <1, 7> | count 7; |
| 2407 50:4| 3: <7, 8> | @t0 = i8; |
| 2408 53:0| 3: <7, 16> | @t1 = i16; |
| 2409 55:4| 3: <7, 32> | @t2 = i32; |
| 2410 58:6| 3: <7, 64> | @t3 = i64; |
| 2411 62:0| 3: <7, 1> | @t4 = i1; |
| 2412 64:4| 3: <2> | @t5 = void; |
| 2413 66:2| 3: <21, 0, 5> | @t6 = void (); |
| 2414 69:4| 0: <65534> | } |
| 2415 ... |
| 2416 114:4| 1: <65535, 11, 2> | constants { // BlockID = 11 |
| 2417 124:0| 3: <1, 0> | i8: |
| 2418 126:4| 3: <4, 2> | %c0 = i8 1; |
| 2419 129:0| 3: <4, 4> | %c1 = i8 2; |
| 2420 131:4| 3: <1, 1> | i16: |
| 2421 134:0| 3: <4, 6> | %c2 = i16 3; |
| 2422 136:4| 3: <4, 8> | %c3 = i16 4; |
| 2423 139:0| 3: <1, 2> | i32: |
| 2424 141:4| 3: <4, 10> | %c4 = i32 5; |
| 2425 144:0| 3: <4, 12> | %c5 = i32 6; |
| 2426 146:4| 3: <1, 3> | i64: |
| 2427 149:0| 3: <4, 3> | %c6 = i64 -1; |
| 2428 151:4| 3: <4, 5> | %c7 = i64 -2; |
| 2429 154:0| 3: <1, 4> | i1: |
| 2430 156:4| 3: <4, 3> | %c8 = i1 1; |
| 2431 159:0| 3: <4, 0> | %c9 = i1 0; |
| 2432 161:4| 0: <65534> | } |
| 2433 |
| 2434 Floating Point Literal |
| 2435 ---------------------- |
| 2436 |
| 2437 The *floating point literal* record creates a floating point literal for the |
| 2438 floating point type *T* defined by the preceding *set type* record. |
| 2439 |
| 2440 **Syntax**:: |
| 2441 |
| 2442 %cN = T V; <A> |
| 2443 |
| 2444 **Record**:: |
| 2445 |
| 2446 AA: <6, VV> |
| 2447 |
| 2448 **Semantics**: |
| 2449 |
| 2450 The *floating point literal* record creates a floating point literal constant |
| 2451 ``%cN`` for type ``T``. ``T`` must the type type defined by the preceding *set |
| 2452 type* record, and be a floating point type. The literal ``V`` is the floating |
| 2453 value to be defined. The value ``VV`` if the corresponding IEEE unsigned integer |
| 2454 that defines value ``V``. That is, the literal ``VV`` must be a valid IEEE 754 |
| 2455 32-bit (unsigned integer) value if ``T`` is ``float``, and a valid IEEE 754 |
| 2456 64-bit (unsigned integer) value if ``T`` is ``double``. |
| 2457 |
| 2458 **Constraints**:: |
| 2459 |
| 2460 N == NumFcnConsts |
| 2461 T == ConstantsSetType |
| 2462 IsFloat(T) |
| 2463 |
| 2464 **Updates**:: |
| 2465 |
| 2466 TypeOf(%cN) = T; |
| 2467 |
| 2468 **Examples**:: |
| 2469 |
| 2470 40:0| 1: <65535, 17, 2> | types { // BlockID = 17 |
| 2471 48:0| 3: <1, 4> | count 4; |
| 2472 50:4| 3: <3> | @t0 = float; |
| 2473 52:2| 3: <4> | @t1 = double; |
| 2474 54:0| 3: <2> | @t2 = void; |
| 2475 55:6| 3: <21, 0, 2> | @t3 = void (); |
| 2476 59:0| 0: <65534> | } |
| 2477 ... |
| 2478 102:4| 1: <65535, 11, 2> | constants { // BlockID = 11 |
| 2479 112:0| 3: <1, 0> | float: |
| 2480 114:4| 3: <6, 0> | %c0 = float 0; |
| 2481 117:0| 3: <6, 1065353216> | %c1 = float 1; |
| 2482 123:2| 3: <6, 1088421888> | %c2 = float 7; |
| 2483 130:2| 3: <6, 1090519040> | %c3 = float 8; |
| 2484 137:2| 3: <3> | %c4 = float undef; |
| 2485 139:0| 3: <6, 2143289344> | %c5 = float nan; |
| 2486 146:0| 3: <6, 2139095040> | %c6 = float inf; |
| 2487 153:0| 3: <6, 4286578688> | %c7 = float -inf; |
| 2488 160:0| 3: <1, 1> | double: |
| 2489 162:4| 3: <6, | %c8 = double 1; |
| 2490 | 4607182418800017408> | |
| 2491 174:0| 3: <6, 0> | %c9 = double 0; |
| 2492 176:4| 3: <6, | %c10 = double 5; |
| 2493 | 4617315517961601024> | |
| 2494 188:0| 3: <6, | %c11 = double 6; |
| 2495 | 4618441417868443648> | |
| 2496 199:4| 3: <6, | %c12 = double nan; |
| 2497 | 9221120237041090560> | |
| 2498 211:0| 3: <6, | %c13 = double inf; |
| 2499 | 9218868437227405312> | |
| 2500 222:4| 3: <6, | %c14 = double -inf; |
| 2501 | 18442240474082181120>| |
| 2502 234:0| 0: <65534> | } |
| 2503 |
| 2504 .. _link_for_function_blocks_section: |
| 2505 |
| 2506 Function Blocks |
| 2507 =============== |
| 2508 |
| 2509 A function block defines the implementation of a defined :ref:`function |
| 2510 address<link_for_function_address_section>`. The function address it defines is |
| 2511 based on the position of the corresponding defined function address. The Nth |
| 2512 defined function address always corresponds to the Nth function block in the |
| 2513 module block. |
| 2514 |
| 2515 A function implementation contains a list of basic blocks, forming the control |
| 2516 flow graph. Each *basic block* contains a list of instructions, and ends with a |
| 2517 :ref:`terminator instruction<link_for_terminator_instruction_section>` |
| 2518 (e.g. branch). |
| 2519 |
| 2520 Basic blocks are not represented by records. Rather, context is implicit. The |
| 2521 first basic block begins with the first instruction record in the function |
| 2522 block. Block boundaries are determined by terminator instructions. The |
| 2523 instruction that follows a terminator instruction begins a new basic block. |
| 2524 |
| 2525 The first basic block in a function is special in two ways: it is immediately |
| 2526 executed on entrance to the function, and it is not allowed to have predecessor |
| 2527 basic blocks (i.e. there can't be any branches to the entry block of a |
| 2528 function). Because the entry block has no predecessors, it also can't have any |
| 2529 :ref:`phi<link_for_phi_instruction_section>` instructions. |
| 2530 |
| 2531 The parameters are implied by the type of the corresponding function |
| 2532 address. One parameter is defined for each argument of the function :ref:`type |
| 2533 signature<link_for_function_type>` of the corresponding :ref:`function |
| 2534 address<link_for_function_address_section>`. |
| 2535 |
| 2536 The number of basic blocks is defined by the :ref:`count |
| 2537 record<link_for_basic_blocks_count>`. Each :ref:`terminator |
| 2538 instruction<link_for_terminator_instruction_section>` ends the current basic |
| 2539 block, and the next instruction begins a new basic block. Basic blocks are |
| 2540 numbered by the order they appear (starting with index 0). Basic block IDs have |
| 2541 the form ``%bN``, where ``N`` corresponds to the position of the basic block |
| 2542 within the function block. |
| 2543 |
| 2544 Each instruction, within a function block, corresponds to a corresponding PNaCl |
| 2545 record. The layout of a function block is the (basic block) count record, |
| 2546 followed by a sequence of instruction records. |
| 2547 |
| 2548 For readability, PNaClAsm introduces basic block IDs. These basic block IDs do |
| 2549 not correspond to PNaCl records, since basic block boundaries are defined |
| 2550 implicitly, after terminator instructions. They appear only for readability. |
| 2551 |
| 2552 Operands of instructions are defined using an :ref:`absolute |
| 2553 index<link_for_absolute_index_section>`. This absolute index implicitly encodes |
| 2554 function addresses, global addresses, parameters, constants, and instructions |
| 2555 that generate values. The encoding takes advantage of the implied ordering of |
| 2556 these values in the bitcode file, defining a contiguous sequence of indices for |
| 2557 each kind of identifier. That is, indices are ordered by putting function |
| 2558 address identifiers first, followed by global address identifiers, followed by |
| 2559 parameter identifiers, followed by constant identifiers, and lastly instruction |
| 2560 value identifiers. |
| 2561 |
| 2562 To save space in the encoded bitcode file, most operands are encoded using a |
| 2563 :ref:`relative index<link_for_relative_index>` value, rather than |
| 2564 :ref:`absolute<link_for_absolute_index_section>`. This |
| 2565 is done because most instruction operands refer to values defined earlier in the |
| 2566 (same) basic block. As a result, the relative distance (back) from the next |
| 2567 value defining instruction is frequently a small number. Small numbers tend to |
| 2568 require fewer bits when they are converted to bit sequences. |
| 2569 |
| 2570 Note that instructions that can appear in a function block are defined in |
| 2571 sections :ref:`link_for_terminator_instruction_section`, |
| 2572 :ref:`link_for_integer_binary_instructions`, |
| 2573 :ref:`link_for_floating_point_binary_instructions`, |
| 2574 :ref:`link_for_memory_creation_and_access_instructions`, |
| 2575 :ref:`link_for_conversion_instructions`, :ref:`link_for_compare_instructions`, |
| 2576 :ref:`link_for_vector_instructions`, and |
| 2577 :ref:`link_for_other_pnaclasm_instructions`. |
| 2578 |
| 2579 The following subsections define the remaining records that can appear in a |
| 2580 function block. |
| 2581 |
| 2582 Function Enter |
| 2583 -------------- |
| 2584 |
| 2585 PNaClAsm defines a function enter block construct. The corresponding record is |
| 2586 simply an :ref:`enter block<link_for_enter_block_record_section>` record, with |
| 2587 BlockID value ``12``. All context about the defining address is implicit by the |
| 2588 position of the function block, and the corresponding defining :ref:`function |
| 2589 address<link_for_function_address_section>`. To improve readability, PNaClAsm |
| 2590 includes the function signature into the syntax rule. |
| 2591 |
| 2592 **Syntax**:: |
| 2593 |
| 2594 function TR @fN ( T0 %p0, ... , TM %pM ) { <B> |
| 2595 |
| 2596 **Record**:: |
| 2597 |
| 2598 1: <65535, 12, B> |
| 2599 |
| 2600 **Semantics**: |
| 2601 |
| 2602 ``B`` is the number of bits reserved for abbreviations in the block. If it is |
| 2603 omitted, 2 is assumed. See :ref:`enter<link_for_enter_block_record_section>` |
| 2604 block records for more details. |
| 2605 |
| 2606 The value of ``N`` corresponds to the positional index of the corresponding |
| 2607 defining function address this block is associated with. ``M`` is the number of |
| 2608 defined parameters (minus one) in the function heading. |
| 2609 |
| 2610 **Constraints**:: |
| 2611 |
| 2612 N == NumFcnImpls & |
| 2613 @fN in DefiningFcnIDs & |
| 2614 TypeOfFcn(@fN) == TypeOf(TypeID(TR (T0, ... , TM))) |
| 2615 |
| 2616 **Updates**:: |
| 2617 |
| 2618 ++NumFcnImpls; |
| 2619 EnclosingFcnID = @fN; |
| 2620 NumBasicBlocks = 0; |
| 2621 ExpectedBlocks = 0; |
| 2622 NumParams = M; |
| 2623 for I in [0..M]: |
| 2624 TypeOf(%pI) = TypeOf(TypeID(TI)); |
| 2625 |
| 2626 **Examples**:: |
| 2627 |
| 2628 40:0| 1: <65535, 17, 2> | types { // BlockID = 17 |
| 2629 48:0| 3: <1, 4> | count 4; |
| 2630 50:4| 3: <7, 32> | @t0 = i32; |
| 2631 53:6| 3: <2> | @t1 = void; |
| 2632 55:4| 3: <21, 0, 1> | @t2 = void (); |
| 2633 58:6| 3: <21, 0, 0, 0> | @t3 = i32 (i32); |
| 2634 62:6| 0: <65534> | } |
| 2635 ... |
| 2636 104:0| 1: <65535, 12, 2> | function void @f0() { |
| 2637 | | // BlockID = 12 |
| 2638 112:0| 3: <1, 1> | blocks 1; |
| 2639 | | %b0: |
| 2640 114:4| 3: <10> | ret void; |
| 2641 116:2| 0: <65534> | } |
| 2642 120:0| 1: <65535, 12, 2> | function i32 @f1(i32 %p0) { |
| 2643 | | // BlockID = 12 |
| 2644 128:0| 3: <1, 1> | blocks 1; |
| 2645 | | %b0: |
| 2646 130:4| 3: <10, 1> | ret i32 %p0; |
| 2647 133:0| 0: <65534> | } |
| 2648 |
| 2649 .. _link_for_basic_blocks_count: |
| 2650 |
| 2651 Count Record |
| 2652 ------------ |
| 2653 |
| 2654 The count record, within a function block, defines the number of basic blocks |
| 2655 used to define the function implementation. It must be the first record in the |
| 2656 function block. |
| 2657 |
| 2658 **Syntax**:: |
| 2659 |
| 2660 blocks: N; <A> |
| 2661 %b0: |
| 2662 |
| 2663 **Record**:: |
| 2664 |
| 2665 AA: <1, N> |
| 2666 |
| 2667 **Semantics**: |
| 2668 |
| 2669 The count record defines the number ``N`` of basic blocks in the implemented |
| 2670 function. |
| 2671 |
| 2672 **Constraints**:: |
| 2673 |
| 2674 AA == AbbrevIndex(A) & |
| 2675 ExpectedBasicBlocks == N & |
| 2676 NumBasicBlocks == 0 |
| 2677 |
| 2678 **Updates**:: |
| 2679 |
| 2680 104:0| 1: <65535, 12, 2> | function void @f0() { |
| 2681 | | // BlockID = 12 |
| 2682 112:0| 3: <1, 1> | blocks 1; |
| 2683 | | %b0: |
| 2684 114:4| 3: <10> | ret void; |
| 2685 116:2| 0: <65534> | } |
| 2686 120:0| 1: <65535, 12, 2> | function i32 @f1(i32 %p0) { |
| 2687 | | // BlockID = 12 |
| 2688 128:0| 3: <1, 1> | blocks 1; |
| 2689 | | %b0: |
| 2690 130:4| 3: <10, 1> | ret i32 %p0; |
| 2691 133:0| 0: <65534> | } |
| 2692 |
| 2693 .. _link_for_terminator_instruction_section: |
| 2694 |
| 2695 Terminator Instructions |
| 2696 ======================= |
| 2697 |
| 2698 Terminator instructions are instructions that appear in a :ref:`function |
| 2699 block<link_for_function_blocks_section>`, and define the end of the current |
| 2700 basic block. A terminator instruction indicates which block should be executed |
| 2701 after the current block is finished. The function block is well formed only if |
| 2702 the number of terminator instructions, in the function block, corresponds to the |
| 2703 value defined by the corresponding function basic block :ref:`count |
| 2704 record<link_for_basic_blocks_count>`. |
| 2705 |
| 2706 Note that any branch instruction to label ``%bN``, where ``N >= |
| 2707 ExpectedBasicBlocks``, is illegal. For ease of readability, this constraint |
| 2708 hasn't been put on branch instructions. Rather it is only implied. |
| 2709 |
| 2710 In addition, it must be the case that ``NumBasicBlocks < ExpectedBasicBlocks``, |
| 2711 and will not be listed as a constraint. Further, if ``B = NumBasicBlocks + 1`` |
| 2712 is the number associated with the next basic block. Label `%bB:` only appears |
| 2713 if:: |
| 2714 |
| 2715 B < ExpectedBasicBlocks |
| 2716 |
| 2717 That is, the label is omitted only if this terminator instruction is the last |
| 2718 instruction in the function block. |
| 2719 |
| 2720 Return Void Instruction |
| 2721 ----------------------- |
| 2722 |
| 2723 The return void instruction is used to return control from a function back to |
| 2724 the caller, without returning any value. |
| 2725 |
| 2726 **Syntax**:: |
| 2727 |
| 2728 ret void; <A> |
| 2729 %bB: |
| 2730 |
| 2731 **Record**:: |
| 2732 |
| 2733 AA: <10> |
| 2734 |
| 2735 **Semantics**: |
| 2736 |
| 2737 The return void instruction returns control to the calling function. |
| 2738 |
| 2739 **Constraints**:: |
| 2740 |
| 2741 AA == AbbrevIndex(A) & |
| 2742 B == NumBasicBlocks + 1 & |
| 2743 ReturnType(TypeOf(EnclosingFcnID)) == void |
| 2744 |
| 2745 **Updates**:: |
| 2746 |
| 2747 ++NumBasicBlocks; |
| 2748 |
| 2749 **Examples**:: |
| 2750 |
| 2751 104:0| 1: <65535, 12, 2> | function void @f0() { |
| 2752 | | // BlockID = 12 |
| 2753 112:0| 3: <1, 1> | blocks 1; |
| 2754 | | %b0: |
| 2755 114:4| 3: <10> | ret void; |
| 2756 116:2| 0: <65534> | } |
| 2757 |
| 2758 Return Value Instruction |
| 2759 ------------------------ |
| 2760 |
| 2761 The return value instruction is used to return control from a function back to |
| 2762 the caller, including a value. The value must correspond to the return type of |
| 2763 the enclosing function. |
| 2764 |
| 2765 **Syntax**:: |
| 2766 |
| 2767 ret T V; <A> |
| 2768 %bB: |
| 2769 |
| 2770 **Record**:: |
| 2771 |
| 2772 AA: <10, VV> |
| 2773 |
| 2774 **Semantics**: |
| 2775 |
| 2776 The return value instruction returns control to the calling function, returning |
| 2777 the provided value. |
| 2778 |
| 2779 ``V`` is the value to return. Type ``T`` must be of the type returned by the |
| 2780 function. It must also be the type associated with value ``V``. |
| 2781 |
| 2782 The return type ``T`` must either be a (non-void) primitive type, or a vector |
| 2783 type. If the function block is implementing an ordinary function, and the return |
| 2784 type is an integer type, it must be either ``i32`` or ``i64``. |
| 2785 |
| 2786 **Constraints**:: |
| 2787 |
| 2788 AA == AbbrevIndex(A) & |
| 2789 VV == RelativeIndex(V) & |
| 2790 B == NumBasicBlocks + 1 & |
| 2791 T == TypeOf(V) == ReturnType(TypeOf(EnclosingFcnID)) |
| 2792 |
| 2793 **Updates**:: |
| 2794 |
| 2795 ++NumBasicBlocks; |
| 2796 |
| 2797 **Examples**:: |
| 2798 |
| 2799 120:0| 1: <65535, 12, 2> | function i32 @f1(i32 %p0) { |
| 2800 | | // BlockID = 12 |
| 2801 128:0| 3: <1, 1> | blocks 1; |
| 2802 | | %b0: |
| 2803 130:4| 3: <10, 1> | ret i32 %p0; |
| 2804 |
| 2805 Unconditional Branch Instruction |
| 2806 -------------------------------- |
| 2807 |
| 2808 The unconditional branch instruction is used to cause control flow to transfer |
| 2809 to a different basic block of the function. |
| 2810 |
| 2811 **Syntax**:: |
| 2812 |
| 2813 br %bN; <A> |
| 2814 %bB: |
| 2815 |
| 2816 **Record**:: |
| 2817 |
| 2818 AA: <11, N> |
| 2819 |
| 2820 **Semantics**: |
| 2821 |
| 2822 The unconditional branch instruction causes control flow to transfer to basic |
| 2823 block ``N``. |
| 2824 |
| 2825 **Constraints**:: |
| 2826 |
| 2827 AA == AbbrevIndex(A) & |
| 2828 B == NumBasicBlocks + 1 & |
| 2829 0 < N & |
| 2830 N < ExpectedBasicBlocks |
| 2831 |
| 2832 **Updates**:: |
| 2833 |
| 2834 ++NumBasicBlocks; |
| 2835 |
| 2836 **Examples**:: |
| 2837 |
| 2838 88:0| 1: <65535, 12, 2> | function void @f0() { |
| 2839 | | // BlockID = 12 |
| 2840 96:0| 3: <1, 5> | blocks 5; |
| 2841 | | %b0: |
| 2842 98:4| 3: <11, 3> | br label %b3; |
| 2843 | | %b1: |
| 2844 101:0| 3: <11, 4> | br label %b4; |
| 2845 | | %b2: |
| 2846 103:4| 3: <11, 1> | br label %b1; |
| 2847 | | %b3: |
| 2848 106:0| 3: <11, 2> | br label %b2; |
| 2849 | | %b4: |
| 2850 108:4| 3: <10> | ret void; |
| 2851 110:2| 0: <65534> | } |
| 2852 |
| 2853 Conditional Branch Instruction |
| 2854 ------------------------------ |
| 2855 |
| 2856 The conditional branch instruction is used to cause control flow to transfer to |
| 2857 a different basic block of the function, based on a boolean test condition. |
| 2858 |
| 2859 **Syntax**:: |
| 2860 |
| 2861 br i1 C, %bT, %bBF; <A> |
| 2862 %bB: |
| 2863 |
| 2864 **Record**:: |
| 2865 |
| 2866 AA: <11, T, F, CC> |
| 2867 |
| 2868 **Semantics**: |
| 2869 |
| 2870 Upon execution of a conditional branch instruction, the *i1* (boolean) argument |
| 2871 ``C`` is evaluated. If the value is ``true``, control flows to basic block |
| 2872 ``%bT``. Otherwise control flows to basic block ``%bF``. |
| 2873 |
| 2874 **Constraints**:: |
| 2875 |
| 2876 AA == AbbrevIndex(A) & |
| 2877 CC == RelativeIndex(C) & |
| 2878 B == NumBasicBlocks + 1 & |
| 2879 0 < T & |
| 2880 B1 < ExpectedBasicBlocks & |
| 2881 0 < F & |
| 2882 B2 < ExpectedBasicBlocks & |
| 2883 TypeOf(C) == i1 |
| 2884 |
| 2885 **Updates**:: |
| 2886 |
| 2887 ++NumBasicBlocks; |
| 2888 |
| 2889 **Examples**:: |
| 2890 |
| 2891 92:0| 1: <65535, 12, 2> | function void @f0() { |
| 2892 | | // BlockID = 12 |
| 2893 100:0| 3: <1, 5> | blocks 5; |
| 2894 102:4| 1: <65535, 11, 2> | constants { // BlockID = 11 |
| 2895 112:0| 3: <1, 1> | i1: |
| 2896 114:4| 3: <4, 3> | %c0 = i1 1; |
| 2897 117:0| 3: <4, 0> | %c1 = i1 0; |
| 2898 119:4| 0: <65534> | } |
| 2899 | | %b0: |
| 2900 120:0| 3: <11, 3> | br label %b3; |
| 2901 | | %b1: |
| 2902 122:4| 3: <11, 2, 4, 2> | br i1 %c0, label %b2, label %b4; |
| 2903 | | %b2: |
| 2904 126:4| 3: <11, 3> | br label %b3; |
| 2905 | | %b3: |
| 2906 129:0| 3: <10> | ret void; |
| 2907 | | %b4: |
| 2908 130:6| 3: <11, 2, 3, 1> | br i1 %c1, label %b2, label %b3; |
| 2909 134:6| 0: <65534> | } |
| 2910 |
| 2911 Unreachable |
| 2912 ----------- |
| 2913 |
| 2914 The unreachable instruction has no defined semantics. The instruction is used to |
| 2915 inform the :ref:`PNaCl translator<link_for_pnacl_translator>` that control |
| 2916 can't reach this instruction. |
| 2917 |
| 2918 **Syntax**:: |
| 2919 |
| 2920 unreachable; <A> |
| 2921 %bB: |
| 2922 |
| 2923 **Record**:: |
| 2924 |
| 2925 AA: <15> |
| 2926 |
| 2927 **Semantics**: |
| 2928 |
| 2929 Directive to the :ref:`PNaCl translator<link_for_pnacl_translator>` that |
| 2930 this instruction is unreachable. |
| 2931 |
| 2932 **Constraints**:: |
| 2933 |
| 2934 AA == AbbrevIndex(A) |
| 2935 B == NumBasicBlocks + 1 & |
| 2936 |
| 2937 **Updates**:: |
| 2938 |
| 2939 ++NumBasicBlocks; |
| 2940 |
| 2941 **Examples**:: |
| 2942 |
| 2943 108:0| 1: <65535, 12, 2> | function void @f0(i32 %p0) { |
| 2944 | | // BlockID = 12 |
| 2945 116:0| 3: <1, 5> | blocks 5; |
| 2946 118:4| 1: <65535, 11, 2> | constants { // BlockID = 11 |
| 2947 128:0| 3: <1, 2> | i1: |
| 2948 130:4| 3: <4, 3> | %c0 = i1 1; |
| 2949 133:0| 3: <4, 0> | %c1 = i1 0; |
| 2950 135:4| 0: <65534> | } |
| 2951 | | %b0: |
| 2952 136:0| 3: <11, 1, 2, 2> | br i1 %c0, label %b1, label %b2; |
| 2953 | | %b1: |
| 2954 140:0| 3: <11, 3, 4, 1> | br i1 %c1, label %b3, label %b4; |
| 2955 | | %b2: |
| 2956 144:0| 3: <15> | unreachable; |
| 2957 | | %b3: |
| 2958 145:6| 3: <15> | unreachable; |
| 2959 | | %b4: |
| 2960 147:4| 3: <10> | ret void; |
| 2961 149:2| 0: <65534> | } |
| 2962 |
| 2963 Switch Instruction |
| 2964 ------------------ |
| 2965 |
| 2966 The *switch* instruction transfers control flow to one of several different |
| 2967 places, based on a selector value. It is a generalization of the conditional |
| 2968 branch instruction. |
| 2969 |
| 2970 **Syntax**:: |
| 2971 |
| 2972 switch T V0 { |
| 2973 default: br label %bB0; |
| 2974 T V1: br label %bB1; |
| 2975 ... |
| 2976 T VN: br label %bBN; |
| 2977 } <A> |
| 2978 %bB: |
| 2979 |
| 2980 **Record**:: |
| 2981 |
| 2982 AA: <12, TT, B0, N, (1, 1, VVI, BI | 1 <= i <= N)> |
| 2983 |
| 2984 **Semantics**: |
| 2985 |
| 2986 The switch instruction transfers control to a basic block in ``B0`` through |
| 2987 ``BN``. Value ``V`` is used to conditionally select which block to branch |
| 2988 to. ``T`` is the type of ``V`` and ``V1`` through ``VN``, and must be an integer |
| 2989 type. Value ``V1`` through ``VN`` are integers to compare against ``V``. If |
| 2990 selector ``V`` matches ``VI`` (for some ``I``, ``1 <= I <= N``), then the |
| 2991 instruction branches to block ``BI``. If ``V`` is not in ``V1`` through ``VN``, |
| 2992 the instruction branches to block ``B0``. |
| 2993 |
| 2994 **Constraints**:: |
| 2995 |
| 2996 AA == AbbrevIndex(A) & |
| 2997 B == NumBasicBlocks + 1 & |
| 2998 TT == TypeID(T) & |
| 2999 VI == SignRotate(VI) for all I, 1 <= I <= N & |
| 3000 |
| 3001 **Updates**:: |
| 3002 |
| 3003 ++NumBasicBlocks; |
| 3004 |
| 3005 **Examples**:: |
| 3006 |
| 3007 116:0| 1: <65535, 12, 2> | function void @f0(i32 %p0) { |
| 3008 | | // BlockID = 12 |
| 3009 124:0| 3: <1, 6> | blocks 6; |
| 3010 | | %b0: |
| 3011 126:4| 3: <12, 1, 1, 2, 4, 1, 1,| switch i32 %p0 { |
| 3012 | 2, 3, 1, 1, 4, 3, 1, | default: br label %b2; |
| 3013 | 1, 8, 4, 1, 1, 10, 4>| i32 1: br label %b3; |
| 3014 | | i32 2: br label %b3; |
| 3015 | | i32 4: br label %b4; |
| 3016 | | i32 5: br label %b4; |
| 3017 | | } |
| 3018 | | %b1: |
| 3019 143:2| 3: <11, 5> | br label %b5; |
| 3020 | | %b2: |
| 3021 145:6| 3: <11, 5> | br label %b5; |
| 3022 | | %b3: |
| 3023 148:2| 3: <11, 5> | br label %b5; |
| 3024 | | %b4: |
| 3025 150:6| 3: <11, 5> | br label %b5; |
| 3026 | | %b5: |
| 3027 153:2| 3: <10> | ret void; |
| 3028 155:0| 0: <65534> | } |
| 3029 156:0| 1: <65535, 12, 2> | function void @f1(i64 %p0) { |
| 3030 | | // BlockID = 12 |
| 3031 164:0| 3: <1, 6> | blocks 6; |
| 3032 | | %b0: |
| 3033 166:4| 3: <12, 2, 1, 2, 4, 1, 1,| switch i64 %p0 { |
| 3034 | 2, 3, 1, 1, 4, 3, 1, | default: br label %b2; |
| 3035 | 1, 8, 4, 1, 1, | i64 1: br label %b3; |
| 3036 | 39777555332, 4> | i64 2: br label %b3; |
| 3037 | | i64 4: br label %b4; |
| 3038 | | i64 19888777666: br label %b4; |
| 3039 | | } |
| 3040 | | %b1: |
| 3041 188:4| 3: <11, 5> | br label %b5; |
| 3042 | | %b2: |
| 3043 191:0| 3: <11, 5> | br label %b5; |
| 3044 | | %b3: |
| 3045 193:4| 3: <11, 5> | br label %b5; |
| 3046 | | %b4: |
| 3047 196:0| 3: <11, 5> | br label %b5; |
| 3048 | | %b5: |
| 3049 198:4| 3: <10> | ret void; |
| 3050 200:2| 0: <65534> | } |
| 3051 |
| 3052 .. _link_for_integer_binary_instructions: |
| 3053 |
| 3054 Integer Binary Instructions |
| 3055 =========================== |
| 3056 |
| 3057 Binary instructions are used to do most of the computation in a program. This |
| 3058 section focuses on binary instructions that operator on integer values, or |
| 3059 vectors of integer values. |
| 3060 |
| 3061 All binary operations require two operands of the same type, execute an |
| 3062 operation on them, and produce a value. The value may represent multiple values |
| 3063 if the type is a vector type. The result value always has the same type as its |
| 3064 operands. |
| 3065 |
| 3066 Some integer binary operations can be applied to both signed and unsigned |
| 3067 integers. Others, the sign is significant. In general, if the sign plays a role |
| 3068 in the instruction, the sign information is encoded into the name of the |
| 3069 instruction. |
| 3070 |
| 3071 For most binary operations (except some of the logical operations), integer |
| 3072 type i1 is disallowed. |
| 3073 |
| 3074 Integer Add |
| 3075 ----------- |
| 3076 |
| 3077 The integer add instruction returns the sum of its two arguments. Both arguments |
| 3078 and the result must be of the same type. That type must be integer, or an |
| 3079 integer vector type. |
| 3080 |
| 3081 **Syntax**:: |
| 3082 |
| 3083 %vN = add T V1, V2; <A> |
| 3084 |
| 3085 **Record**:: |
| 3086 |
| 3087 AA: <2, VV1, VV2, 0> |
| 3088 |
| 3089 **Semantics**: |
| 3090 |
| 3091 The integer add instruction returns the sum of its two arguments. Arguments |
| 3092 ``V1`` and ``V2``, and the result ``%vN``, must be of type ``T``. ``T`` must be |
| 3093 an integer type, or an integer vector type. ``N`` is defined by the record |
| 3094 position, defining the corresponding value generated by the instruction. |
| 3095 |
| 3096 The result returned is the mathematical result modulo 2\ :sup:`n`\ , where ``n`` |
| 3097 is the bit width of the integer result. |
| 3098 |
| 3099 Because integers are assumed to use a two's complement representation, |
| 3100 this instruction is appropriate for both signed and unsigned integers. |
| 3101 |
| 3102 In the add instruction, integer type ``i1`` (and a vector of integer type |
| 3103 ``i1``) is disallowed. |
| 3104 |
| 3105 **Constraints**:: |
| 3106 |
| 3107 AA == AbbrevIndex(A) & |
| 3108 VV1 == RelativeIndex(V1) & |
| 3109 VV2 == RelativeIndex(V2) & |
| 3110 T == TypeOf(V1) == TypeOf(V2) & |
| 3111 IsInteger(UnderlyingType(T)) & |
| 3112 UnderlyingType(T) != i1 & |
| 3113 N == NumValuedInsts |
| 3114 |
| 3115 **Updates**:: |
| 3116 |
| 3117 ++NumValuedInsts; |
| 3118 TypeOf(%vN) = T |
| 3119 |
| 3120 **Examples**:: |
| 3121 |
| 3122 96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) { |
| 3123 | | // BlockID = 12 |
| 3124 104:0| 3: <1, 1> | blocks 1; |
| 3125 | | %b0: |
| 3126 106:4| 3: <2, 2, 1, 0> | %v0 = add i32 %p0, %p1; |
| 3127 110:4| 3: <2, 3, 1, 0> | %v1 = add i32 %p0, %v0; |
| 3128 114:4| 3: <10, 1> | ret i32 %v1; |
| 3129 117:0| 0: <65534> | } |
| 3130 |
| 3131 Integer Subtract |
| 3132 ---------------- |
| 3133 |
| 3134 The integer subtract instruction returns the difference of its two arguments. |
| 3135 Both arguments and the result must be of the same type. That type must be |
| 3136 integer, or an integer vector type. |
| 3137 |
| 3138 Note: Since there isn't a negate instruction, subtraction from constant zero |
| 3139 should be used to negate values. |
| 3140 |
| 3141 **Syntax**:: |
| 3142 |
| 3143 %vN = sub T V1, V2; <A> |
| 3144 |
| 3145 **Record**:: |
| 3146 |
| 3147 AA: <2, VV1, VV2, 1> |
| 3148 |
| 3149 **Semantics**: |
| 3150 |
| 3151 The integer subtract returns the difference of its two arguments. Arguments |
| 3152 ``V1`` and ``V2``, and the result ``%vN`` must be of type ``T``. ``T`` must be |
| 3153 an integer type, or an integer vector type. ``N`` is defined by the record |
| 3154 position, defining the corresponding value generated by the instruction. |
| 3155 |
| 3156 The result returned is the mathematical result modulo 2\ :sup:`n`\ , where ``n`` |
| 3157 is the bit width of the integer result. |
| 3158 |
| 3159 Because integers are assumed to use a two's complement representation, |
| 3160 this instruction is appropriate for both signed and unsigned integers. |
| 3161 |
| 3162 In the subtract instruction, integer type ``i1`` (and a vector of integer type |
| 3163 ``i1``) is disallowed. |
| 3164 |
| 3165 **Constraints**:: |
| 3166 |
| 3167 AA == AbbrevIndex(A) & |
| 3168 VV1 == RelativeIndex(V1) & |
| 3169 VV2 == RelativeIndex(V2) & |
| 3170 T == TypeOf(V1) == TypeOf(V2) & |
| 3171 IsInteger(UnderlyingType(T)) & |
| 3172 UnderlyingType(T) != i1 & |
| 3173 N == NumValuedInsts |
| 3174 |
| 3175 **Updates**:: |
| 3176 |
| 3177 ++NumValuedInsts; |
| 3178 TypeOf(%vN) = T |
| 3179 |
| 3180 **Examples**:: |
| 3181 |
| 3182 96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) { |
| 3183 | | // BlockID = 12 |
| 3184 104:0| 3: <1, 1> | blocks 1; |
| 3185 | | %b0: |
| 3186 106:4| 3: <2, 2, 1, 1> | %v0 = sub i32 %p0, %p1; |
| 3187 110:4| 3: <2, 3, 1, 1> | %v1 = sub i32 %p0, %v0; |
| 3188 114:4| 3: <10, 1> | ret i32 %v1; |
| 3189 117:0| 0: <65534> | } |
| 3190 |
| 3191 Integer Multiply |
| 3192 ---------------- |
| 3193 |
| 3194 The integer multiply instruction returns the product of its two arguments. Both |
| 3195 arguments and the result must be of the same type. That type must be integer, |
| 3196 or an integer based vector type. |
| 3197 |
| 3198 **Syntax**:: |
| 3199 |
| 3200 &vN = mul T V1, V2; <A> |
| 3201 |
| 3202 **Record**:: |
| 3203 |
| 3204 AA: <2, VV1, VV2, 2> |
| 3205 |
| 3206 **Semantics**: |
| 3207 |
| 3208 The integer multiply instruction returns the product of its two |
| 3209 arguments. Arguments ``V1`` and ``V2``, and the result ``%vN``, must be of type |
| 3210 ``T``. ``T`` must be an integer type, or an integer vector type. ``N`` is |
| 3211 defined by the record position, defining the corresponding value generated by |
| 3212 the instruction. |
| 3213 |
| 3214 The result returned is the mathematical result modulo 2\ :sup:`n`\ , where ``n`` |
| 3215 is the bit width of the integer result. |
| 3216 |
| 3217 Because integers are assumed to use a two's complement representation, |
| 3218 this instruction is appropriate for both signed and unsigned integers. |
| 3219 |
| 3220 In the subtract instruction, integer type ``i1`` (or a vector on integer type |
| 3221 ``i1``) is disallowed. |
| 3222 |
| 3223 **Constraints**:: |
| 3224 |
| 3225 AA == AbbrevIndex(A) & |
| 3226 VV1 == RelativeIndex(V1) & |
| 3227 VV2 == RelativeIndex(V2) & |
| 3228 T == TypeOf(V1) == TypeOf(V2) & |
| 3229 IsInteger(UnderlyingType(T)) & |
| 3230 UnderlyingType(T) != i1 & |
| 3231 N == NumValuedInsts |
| 3232 |
| 3233 **Updates**:: |
| 3234 |
| 3235 ++NumValuedInsts; |
| 3236 TypeOf(%vN) = T |
| 3237 |
| 3238 **Examples**:: |
| 3239 |
| 3240 96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) { |
| 3241 | | // BlockID = 12 |
| 3242 104:0| 3: <1, 1> | blocks 1; |
| 3243 | | %b0: |
| 3244 106:4| 3: <2, 2, 1, 2> | %v0 = mul i32 %p0, %p1; |
| 3245 110:4| 3: <2, 1, 3, 2> | %v1 = mul i32 %v0, %p0; |
| 3246 114:4| 3: <10, 1> | ret i32 %v1; |
| 3247 117:0| 0: <65534> | } |
| 3248 |
| 3249 Signed Integer Divide |
| 3250 --------------------- |
| 3251 |
| 3252 The signed integer divide instruction returns the quotient of its two arguments. |
| 3253 Both arguments and the result must be of the same type. That type must be |
| 3254 integer, or an integer vector type. |
| 3255 |
| 3256 **Syntax**:: |
| 3257 |
| 3258 %vN = sdiv T V1, V2; <A> |
| 3259 |
| 3260 **Record**:: |
| 3261 |
| 3262 AA: <2, VV1, VV2, 4> |
| 3263 |
| 3264 **Semantics**: |
| 3265 |
| 3266 The signed integer divide instruction returns the quotient of its two |
| 3267 arguments. Arguments ``V1`` and ``V2``, and the result ``%vN``, must be of type |
| 3268 ``T``. ``T`` must be a integer type, or an integer vector type. ``N`` is defined |
| 3269 by the record position, defining the corresponding value generated by the |
| 3270 instruction. |
| 3271 |
| 3272 Signed values are assumed. Note that signed and unsigned integer division are |
| 3273 distinct operations. For unsigned integer division use the unsigned integer |
| 3274 divide instruction (udiv). |
| 3275 |
| 3276 In the signed integer divide instruction, integer type ``i1`` (and a vector of |
| 3277 integer type ``i1``) is disallowed. Integer division by zero is guaranteed to |
| 3278 trap. |
| 3279 |
| 3280 Note that overflow can happen with this instruction when dividing the maximum |
| 3281 negative integer by ``-1``. The behavior for this case is currently undefined. |
| 3282 |
| 3283 **Constraints**:: |
| 3284 |
| 3285 AA == AbbrevIndex(A) & |
| 3286 VV1 == RelativeIndex(V1) & |
| 3287 VV2 == RelativeIndex(V2) & |
| 3288 T == TypeOf(V1) == TypeOf(V2) & |
| 3289 IsInteger(UnderlyingType(T)) & |
| 3290 UnderlyingType(T) != i1 & |
| 3291 N == NumValuedInsts |
| 3292 |
| 3293 **Updates**:: |
| 3294 |
| 3295 ++NumValuedInsts; |
| 3296 TypeOf(%vN) = T |
| 3297 |
| 3298 **Examples**:: |
| 3299 |
| 3300 96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) { |
| 3301 | | // BlockID = 12 |
| 3302 104:0| 3: <1, 1> | blocks 1; |
| 3303 | | %b0: |
| 3304 106:4| 3: <2, 2, 1, 4> | %v0 = sdiv i32 %p0, %p1; |
| 3305 110:4| 3: <2, 1, 2, 4> | %v1 = sdiv i32 %v0, %p1; |
| 3306 114:4| 3: <10, 1> | ret i32 %v1; |
| 3307 117:0| 0: <65534> | } |
| 3308 |
| 3309 Unsigned Integer Divide |
| 3310 ----------------------- |
| 3311 |
| 3312 The unsigned integer divide instruction returns the quotient of its two |
| 3313 arguments. Both the arguments and the result must be of the same type. That type |
| 3314 must be integer, or an integer vector type. |
| 3315 |
| 3316 **Syntax**:: |
| 3317 |
| 3318 %vN = udiv T V1, V2; <a> |
| 3319 |
| 3320 **Record**:: |
| 3321 |
| 3322 AA: <2, A1, A2, 3> |
| 3323 |
| 3324 **Semantics**: |
| 3325 |
| 3326 The unsigned integer divide instruction returns the quotient of its two |
| 3327 arguments. Arguments ``V1`` and ``V2``, and the result ``%vN``, must be of type |
| 3328 ``T``. ``T`` must be an integer type, or an integer vector type. ``N`` is |
| 3329 defined by the record position, defining the corresponding value generated by |
| 3330 the instruction. |
| 3331 |
| 3332 Unsigned integer values are assumed. Note that signed and unsigned integer |
| 3333 division are distinct operations. For signed integer division use the signed |
| 3334 integer divide instruction (sdiv). |
| 3335 |
| 3336 In the unsigned integer divide instruction, integer type ``i1`` (and a vector of |
| 3337 integer type ``i1``) is disallowed. Division by zero is guaranteed to trap. |
| 3338 |
| 3339 **Constraints**:: |
| 3340 |
| 3341 AA == AbbrevIndex(A) & |
| 3342 VV1 == RelativeIndex(V1) & |
| 3343 VV2 == RelativeIndex(V2) & |
| 3344 T == TypeOf(V1) == TypeOf(V2) & |
| 3345 IsInteger(UnderlyingType(T)) & |
| 3346 UnderlyingType(T) != i1 & |
| 3347 N == NumValuedInsts |
| 3348 |
| 3349 **Updates**:: |
| 3350 |
| 3351 ++NumValuedInsts; |
| 3352 TypeOf(%vN) = T |
| 3353 |
| 3354 **Examples**:: |
| 3355 |
| 3356 96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) { |
| 3357 | | // BlockID = 12 |
| 3358 104:0| 3: <1, 1> | blocks 1; |
| 3359 | | %b0: |
| 3360 106:4| 3: <2, 2, 1, 3> | %v0 = udiv i32 %p0, %p1; |
| 3361 110:4| 3: <2, 1, 2, 3> | %v1 = udiv i32 %v0, %p1; |
| 3362 114:4| 3: <10, 1> | ret i32 %v1; |
| 3363 117:0| 0: <65534> | } |
| 3364 |
| 3365 Signed Integer Remainder |
| 3366 ------------------------ |
| 3367 |
| 3368 The signed integer remainder instruction returns the remainder of the quotient |
| 3369 of its two arguments. Both arguments and the result must be of the same |
| 3370 type. That type must be integer, or an integer based vector type. |
| 3371 |
| 3372 **Syntax**:: |
| 3373 |
| 3374 %vN = srem T V1, V2; <A> |
| 3375 |
| 3376 **Record**:: |
| 3377 |
| 3378 AA: <2, VV1, VV2, 6> |
| 3379 |
| 3380 **Semantics**: |
| 3381 |
| 3382 The signed integer remainder instruction returns the remainder of the quotient |
| 3383 of its two arguments. Arguments ``V1`` and ``V2``, and the result ``%vN``, must |
| 3384 be of type ``T``. ``T`` must be a integer type, or an integer vector type. ``N`` |
| 3385 is defined by the record position, defining the corresponding value generated by |
| 3386 the instruction. |
| 3387 |
| 3388 Signed values are assumed. Note that signed and unsigned integer division are |
| 3389 distinct operations. For unsigned integer division use the unsigned integer |
| 3390 remainder instruction (urem). |
| 3391 |
| 3392 In the signed integer remainder instruction, integer type ``i1`` (and a vector |
| 3393 of integer type ``i1``) is disallowed. Division by zero is guaranteed to trap. |
| 3394 |
| 3395 Note that overflow can happen with this instruction when dividing the maximum |
| 3396 negative integer by ``-1``. The behavior for this case is currently undefined. |
| 3397 |
| 3398 **Constraints**:: |
| 3399 |
| 3400 AA == AbbrevIndex(A) & |
| 3401 VV1 == RelativeIndex(V1) & |
| 3402 VV2 == RelativeIndex(V2) & |
| 3403 T == TypeOf(V1) == TypeOf(V2) & |
| 3404 IsInteger(UnderlyingType(T)) & |
| 3405 UnderlyingType(T) != i1 & |
| 3406 N == NumValuedInsts |
| 3407 |
| 3408 **Updates**:: |
| 3409 |
| 3410 ++NumValuedInsts; |
| 3411 TypeOf(%vN) = T |
| 3412 |
| 3413 **Examples**:: |
| 3414 |
| 3415 96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) { |
| 3416 | | // BlockID = 12 |
| 3417 104:0| 3: <1, 1> | blocks 1; |
| 3418 | | %b0: |
| 3419 106:4| 3: <2, 2, 1, 6> | %v0 = srem i32 %p0, %p1; |
| 3420 110:4| 3: <2, 1, 2, 6> | %v1 = srem i32 %v0, %p1; |
| 3421 114:4| 3: <10, 1> | ret i32 %v1; |
| 3422 117:0| 0: <65534> | } |
| 3423 |
| 3424 Unsigned Integer Remainder Instruction |
| 3425 -------------------------------------- |
| 3426 |
| 3427 The unsigned integer remainder instruction returns the remainder of the quotient |
| 3428 of its two arguments. Both the arguments and the result must be of the same |
| 3429 type. The type must be integer, or an integer vector type. |
| 3430 |
| 3431 **Syntax**:: |
| 3432 |
| 3433 %vN = urem T V1, V2; <A> |
| 3434 |
| 3435 **Record**:: |
| 3436 |
| 3437 AA: <2, A1, A2, 5> |
| 3438 |
| 3439 **Semantics**: |
| 3440 |
| 3441 The unsigned integer remainder instruction returns the remainder of the quotient |
| 3442 of its two arguments. Arguments ``V1`` and ``V2``, and the result ``%vN``, must |
| 3443 be of type ``T``. ``T`` must be an integer type, or an integer vector type. |
| 3444 ``N`` is defined by the record position, defining the corresponding value |
| 3445 generated by the instruction. |
| 3446 |
| 3447 Unsigned values are assumed. Note that signed and unsigned integer division are |
| 3448 distinct operations. For signed integer division use the remainder instruction |
| 3449 (srem). |
| 3450 |
| 3451 In the unsigned integer remainder instruction, integer type ``i1`` (and a vector |
| 3452 of integer type ``i1``) is disallowed. Division by zero is guaranteed to trap. |
| 3453 |
| 3454 **Constraints**:: |
| 3455 |
| 3456 AA == AbbrevIndex(A) & |
| 3457 VV1 == RelativeIndex(V1) & |
| 3458 VV2 == RelativeIndex(V2) & |
| 3459 T == TypeOf(V1) == TypeOf(V2) & |
| 3460 IsInteger(UnderlyingType(T)) & |
| 3461 UnderlyingType(T) != i1 & |
| 3462 N == NumValuedInsts |
| 3463 |
| 3464 **Updates**:: |
| 3465 |
| 3466 ++NumValuedInsts; |
| 3467 TypeOf(%vN) = T |
| 3468 |
| 3469 **Examples**:: |
| 3470 |
| 3471 96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) { |
| 3472 | | // BlockID = 12 |
| 3473 104:0| 3: <1, 1> | blocks 1; |
| 3474 | | %b0: |
| 3475 106:4| 3: <2, 2, 1, 5> | %v0 = urem i32 %p0, %p1; |
| 3476 110:4| 3: <2, 1, 2, 5> | %v1 = urem i32 %v0, %p1; |
| 3477 114:4| 3: <10, 1> | ret i32 %v1; |
| 3478 117:0| 0: <65534> | } |
| 3479 |
| 3480 Shift Left |
| 3481 ---------- |
| 3482 |
| 3483 The (integer) shift left instruction returns the first operand, shifted to the |
| 3484 left a specified number of bits with zero fill. The shifted value must be |
| 3485 integer, or an integer vector type. |
| 3486 |
| 3487 **Syntax**:: |
| 3488 |
| 3489 %vN = shl T V1, V2; <A> |
| 3490 |
| 3491 **Record**:: |
| 3492 |
| 3493 AA: <2, VV1, VV2, 7> |
| 3494 |
| 3495 **Semantics**: |
| 3496 |
| 3497 This instruction performs a shift left operation. Arguments ``V1`` and ``V2`` |
| 3498 and the result ``%vN`` must be of type ``T``. ``T`` must be an integer, or a |
| 3499 vector of integers. ``N`` is defined by the record position, defining the |
| 3500 corresponding value generated by the instruction. |
| 3501 |
| 3502 ``V2`` is assumed to be unsigned. The least significant bits of the result will |
| 3503 be filled with zero bits after the shift. If ``V2`` is (statically or |
| 3504 dynamically) negative or equal to or larger than the number of bits in |
| 3505 ``V1``, the result is undefined. If the arguments are vectors, each vector |
| 3506 element of ``V1`` is shifted by the corresponding shift amount in ``V2``. |
| 3507 |
| 3508 In the shift left instruction, integer type ``i1`` (and a vector of integer type |
| 3509 ``i1``) is disallowed. |
| 3510 |
| 3511 **Constraints**:: |
| 3512 |
| 3513 AA == AbbrevIndex(A) & |
| 3514 VV1 == RelativeIndex(V1) & |
| 3515 VV2 == RelativeIndex(V2) & |
| 3516 T == TypeOf(V1) == TypeOf(V2) & |
| 3517 IsInteger(UnderlyingType(T)) & |
| 3518 UnderlyingType(T) != i1 & |
| 3519 N == NumValuedInsts |
| 3520 |
| 3521 **Updates**:: |
| 3522 |
| 3523 ++NumValuedInsts; |
| 3524 TypeOf(%vN) = T |
| 3525 |
| 3526 **Examples**:: |
| 3527 |
| 3528 96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) { |
| 3529 | | // BlockID = 12 |
| 3530 104:0| 3: <1, 1> | blocks 1; |
| 3531 | | %b0: |
| 3532 106:4| 3: <2, 2, 1, 7> | %v0 = shl i32 %p0, %p1; |
| 3533 110:4| 3: <2, 1, 2, 7> | %v1 = shl i32 %v0, %p1; |
| 3534 114:4| 3: <10, 1> | ret i32 %v1; |
| 3535 117:0| 0: <65534> | } |
| 3536 |
| 3537 Logical Shift Right |
| 3538 ------------------- |
| 3539 |
| 3540 The logical shift right instruction returns the first operand, shifted to the |
| 3541 right a specified number of bits with zero fill. |
| 3542 |
| 3543 **Syntax**:: |
| 3544 |
| 3545 %vN = lshr T V1, V2; <A> |
| 3546 |
| 3547 **Record**:: |
| 3548 |
| 3549 AA: <2, VV1, VV2, 8> |
| 3550 |
| 3551 **Semantics**: |
| 3552 |
| 3553 This instruction performs a logical shift right operation. Arguments ``V1`` and |
| 3554 ``V2`` and the result ``%vN`` must be of type ``T``. ``T`` must be an integer, |
| 3555 or a vector of integers. ``N`` is defined by the record position, defining the |
| 3556 corresponding value generated by the instruction. |
| 3557 |
| 3558 ``V2`` is assumed to be unsigned. The most significant bits of the result will |
| 3559 be filled with zero bits after the shift. If ``V2`` is (statically or |
| 3560 dynamically) negative or equal to or larger than the number of bits in ``V1``, |
| 3561 the result is undefined. If the arguments are vectors, each vector element of |
| 3562 ``V1`` is shifted by the corresponding shift amount in ``V2``. |
| 3563 |
| 3564 In the logical shift right instruction, integer type ``i1`` (and a vector of |
| 3565 integer type ``i1``) is disallowed. |
| 3566 |
| 3567 **Constraints**:: |
| 3568 |
| 3569 AA == AbbrevIndex(A) & |
| 3570 VV1 == RelativeIndex(V1) & |
| 3571 VV2 == RelativeIndex(V2) & |
| 3572 T == TypeOf(V1) == TypeOf(V2) & |
| 3573 IsInteger(UnderlyingType(T)) & |
| 3574 UnderlyingType(T) != i1 & |
| 3575 N == NumValuedInsts |
| 3576 |
| 3577 **Updates**:: |
| 3578 |
| 3579 ++NumValuedInsts; |
| 3580 TypeOf(%vN) = T |
| 3581 |
| 3582 **Examples**:: |
| 3583 |
| 3584 96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) { |
| 3585 | | // BlockID = 12 |
| 3586 104:0| 3: <1, 1> | blocks 1; |
| 3587 | | %b0: |
| 3588 106:4| 3: <2, 2, 1, 8> | %v0 = lshr i32 %p0, %p1; |
| 3589 110:4| 3: <2, 1, 2, 8> | %v1 = lshr i32 %v0, %p1; |
| 3590 114:4| 3: <10, 1> | ret i32 %v1; |
| 3591 117:0| 0: <65534> | } |
| 3592 |
| 3593 Arithmetic Shift Right |
| 3594 ---------------------- |
| 3595 |
| 3596 The arithmetic shift right instruction returns the first operand, shifted to the |
| 3597 right a specified number of bits with sign extension. |
| 3598 |
| 3599 **Syntax**:: |
| 3600 |
| 3601 %vN = ashr T V1, V2; <A> |
| 3602 |
| 3603 **Record**:: |
| 3604 |
| 3605 AA: <2, VV1, VVA2, 9> |
| 3606 |
| 3607 **Semantics**: |
| 3608 |
| 3609 This instruction performs an arithmetic shift right operation. Arguments ``V1`` |
| 3610 and ``V2`` and and the result ``%vN`` must be of type ``T``. ``T`` must be an |
| 3611 integer, or a vector of integers. ``N`` is defined by the record position, |
| 3612 defining the corresponding value generated by the instruction. |
| 3613 |
| 3614 ``V2`` is assumed to be unsigned. The most significant bits of the result will |
| 3615 be filled with the sign bit of ``V1``. If ``V2`` is (statically or dynamically) |
| 3616 negative or equal to or larger than the number of bits in ``V1``, the result is |
| 3617 undefined. If the arguments are vectors, each vector element of ``V1`` is |
| 3618 shifted by the corresponding shift amount in ``V2``. |
| 3619 |
| 3620 In the arithmetic shift right instruction, integer type ``i1`` (and a vector of |
| 3621 integral type ``i1``) is disallowed. |
| 3622 |
| 3623 **Constraints**:: |
| 3624 |
| 3625 AA == AbbrevIndex(A) & |
| 3626 VV1 == RelativeIndex(V1) & |
| 3627 VV2 == RelativeIndex(V2) & |
| 3628 T == TypeOf(V1) == TypeOf(V2) & |
| 3629 IsInteger(UnderlyingType(T)) & |
| 3630 UnderlyingType(T) != i1 & |
| 3631 N == NumValuedInsts |
| 3632 |
| 3633 **Updates**:: |
| 3634 |
| 3635 ++NumValuedInsts; |
| 3636 TypeOf(%vN) = T |
| 3637 |
| 3638 **Examples**:: |
| 3639 |
| 3640 96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) { |
| 3641 | | // BlockID = 12 |
| 3642 104:0| 3: <1, 1> | blocks 1; |
| 3643 | | %b0: |
| 3644 106:4| 3: <2, 2, 1, 9> | %v0 = ashr i32 %p0, %p1; |
| 3645 110:4| 3: <2, 1, 2, 9> | %v1 = ashr i32 %v0, %p1; |
| 3646 114:4| 3: <10, 1> | ret i32 %v1; |
| 3647 117:0| 0: <65534> | } |
| 3648 |
| 3649 Logical And |
| 3650 ----------- |
| 3651 |
| 3652 The *and* instruction returns the bitwise logical and of its two operands. |
| 3653 |
| 3654 **Syntax**:: |
| 3655 |
| 3656 %vN = and T V1, V2; <A> |
| 3657 |
| 3658 **Record**:: |
| 3659 |
| 3660 AA: <2, VV1, VV2, 10> |
| 3661 |
| 3662 **Semantics**: |
| 3663 |
| 3664 This instruction performs a bitwise logical and of its arguments. Arguments |
| 3665 ``V1`` and ``V2``, and the result ``%vN`` must be of type ``T``. ``T`` must be |
| 3666 an integer, or a vector of integers. ``N`` is defined by the record position, |
| 3667 defining the corresponding value generated by the instruction. ``A`` is the |
| 3668 (optional) abbreviation associated with the corresponding record. |
| 3669 |
| 3670 The truth table used for the *and* instruction is: |
| 3671 |
| 3672 ===== ===== ====== |
| 3673 Arg 1 Arg 2 Result |
| 3674 ===== ===== ====== |
| 3675 0 0 0 |
| 3676 0 1 0 |
| 3677 1 0 0 |
| 3678 1 1 1 |
| 3679 ===== ===== ====== |
| 3680 |
| 3681 **Constraints**:: |
| 3682 |
| 3683 AA == AbbrevIndex(A) & |
| 3684 VV1 == RelativeIndex(V1) & |
| 3685 VV2 == RelativeIndex(V2) & |
| 3686 T == TypeOf(V1) == TypeOf(V2) & |
| 3687 IsInteger(UnderlyingType(T))) & |
| 3688 N == NumValuedInsts |
| 3689 |
| 3690 **Updates**:: |
| 3691 |
| 3692 ++NumValuedInsts; |
| 3693 TypeOf(%vN) = T |
| 3694 |
| 3695 **Examples**:: |
| 3696 |
| 3697 96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) { |
| 3698 | | // BlockID = 12 |
| 3699 104:0| 3: <1, 1> | blocks 1; |
| 3700 | | %b0: |
| 3701 106:4| 3: <2, 2, 1, 10> | %v0 = and i32 %p0, %p1; |
| 3702 110:4| 3: <2, 1, 2, 10> | %v1 = and i32 %v0, %p1; |
| 3703 114:4| 3: <10, 1> | ret i32 %v1; |
| 3704 117:0| 0: <65534> | } |
| 3705 |
| 3706 Logical Or |
| 3707 ---------- |
| 3708 |
| 3709 The *or* instruction returns the bitwise logical inclusive or of its |
| 3710 two operands. |
| 3711 |
| 3712 **Syntax**:: |
| 3713 |
| 3714 %vN = or T V1, V2; <A> |
| 3715 |
| 3716 **Record**:: |
| 3717 |
| 3718 AA: <2, VV1, VV2, 11> |
| 3719 |
| 3720 **Semantics**: |
| 3721 |
| 3722 This instruction performs a bitwise logical inclusive or of its arguments. |
| 3723 Arguments ``V1`` and ``V2``, and the result ``%vN`` must be of type ``T``. ``T`` |
| 3724 must be an integer, or a vector of integers. ``N`` is defined by the record |
| 3725 position, defining the corresponding value generated by the instruction. |
| 3726 |
| 3727 The truth table used for the *or* instruction is: |
| 3728 |
| 3729 ===== ===== ====== |
| 3730 Arg 1 Arg 2 Result |
| 3731 ===== ===== ====== |
| 3732 0 0 0 |
| 3733 0 1 1 |
| 3734 1 0 1 |
| 3735 1 1 1 |
| 3736 ===== ===== ====== |
| 3737 |
| 3738 **Constraints**:: |
| 3739 |
| 3740 AA == AbbrevIndex(A) & |
| 3741 VV1 == RelativeIndex(V1) & |
| 3742 VV2 == RelativeIndex(V2) & |
| 3743 T == TypeOf(V1) == TypeOf(V2) & |
| 3744 IsInteger(UnderlyingType(T))) & |
| 3745 N == NumValuedInsts |
| 3746 |
| 3747 **Updates**:: |
| 3748 |
| 3749 ++NumValuedInsts; |
| 3750 TypeOf(%vN) = T |
| 3751 |
| 3752 **Examples**:: |
| 3753 |
| 3754 96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) { |
| 3755 | | // BlockID = 12 |
| 3756 104:0| 3: <1, 1> | blocks 1; |
| 3757 | | %b0: |
| 3758 106:4| 3: <2, 2, 1, 11> | %v0 = or i32 %p0, %p1; |
| 3759 110:4| 3: <2, 1, 2, 11> | %v1 = or i32 %v0, %p1; |
| 3760 114:4| 3: <10, 1> | ret i32 %v1; |
| 3761 117:0| 0: <65534> | } |
| 3762 |
| 3763 Logical Xor |
| 3764 ----------- |
| 3765 |
| 3766 The *xor* instruction returns the bitwise logical exclusive or of its |
| 3767 two operands. |
| 3768 |
| 3769 **Syntax**:: |
| 3770 |
| 3771 %vN = xor T V1, V2; <A> |
| 3772 |
| 3773 **Record**:: |
| 3774 |
| 3775 AA: <2, VV1, VV2, 12> |
| 3776 |
| 3777 **Semantics**: |
| 3778 |
| 3779 This instruction performs a bitwise logical exclusive or of its arguments. |
| 3780 Arguments ``V1`` and ``V2``, and the result ``%vN`` must be of type ``T``. ``T`` |
| 3781 must be an integer, or a vector of integers. ``N`` is defined by the record |
| 3782 position, defining the corresponding value generated by the instruction. |
| 3783 |
| 3784 The truth table used for the *xor* instruction is: |
| 3785 |
| 3786 ===== ===== ====== |
| 3787 Arg 1 Arg 2 Result |
| 3788 ===== ===== ====== |
| 3789 0 0 0 |
| 3790 0 1 1 |
| 3791 1 0 1 |
| 3792 1 1 0 |
| 3793 ===== ===== ====== |
| 3794 |
| 3795 **Constraints**:: |
| 3796 |
| 3797 AA == AbbrevIndex(A) & |
| 3798 A1 == RelativeIndex(V1) & |
| 3799 A2 == RelativeIndex(V2) & |
| 3800 T == TypeOf(V1) == TypeOf(V2) & |
| 3801 IsInteger(UnderlyingType(T))) & |
| 3802 N == NumValuedInsts |
| 3803 |
| 3804 **Updates**:: |
| 3805 |
| 3806 ++NumValuedInsts; |
| 3807 TypeOf(%vN) = T |
| 3808 |
| 3809 **Examples**:: |
| 3810 |
| 3811 96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) { |
| 3812 | | // BlockID = 12 |
| 3813 104:0| 3: <1, 1> | blocks 1; |
| 3814 | | %b0: |
| 3815 106:4| 3: <2, 2, 1, 12> | %v0 = xor i32 %p0, %p1; |
| 3816 110:4| 3: <2, 1, 2, 12> | %v1 = xor i32 %v0, %p1; |
| 3817 114:4| 3: <10, 1> | ret i32 %v1; |
| 3818 117:0| 0: <65534> | } |
| 3819 |
| 3820 .. _link_for_floating_point_binary_instructions: |
| 3821 |
| 3822 Floating Point Binary Instructions |
| 3823 ================================== |
| 3824 |
| 3825 Floating point binary instructions require two operands of the same type, |
| 3826 execute an operation on them, and produce a value. The value may represent |
| 3827 multiple values if the type is a vector type. The result value always has the |
| 3828 same type as its operands. |
| 3829 |
| 3830 Floating Point Add |
| 3831 ------------------ |
| 3832 |
| 3833 The floating point add instruction returns the sum of its two arguments. Both |
| 3834 arguments and the result must be of the same type. That type must be a floating |
| 3835 point type, or a vector of a floating point type. |
| 3836 |
| 3837 **Syntax**:: |
| 3838 |
| 3839 %vN = fadd T V1, V2; <A> |
| 3840 |
| 3841 **Record**:: |
| 3842 |
| 3843 AA: <2, VV1, VV2, 0> |
| 3844 |
| 3845 **Semantics**: |
| 3846 |
| 3847 The floating point add instruction returns the sum of its two arguments. |
| 3848 Arguments ``V1`` and ``V2`` and the result ``%vN`` must be of type ``T``. ``T`` |
| 3849 must be a floating point type, or a vector of a floating point type. ``N`` is |
| 3850 defined by the record position, defining the corresponding value generated by |
| 3851 the instruction. |
| 3852 |
| 3853 **Constraints**:: |
| 3854 |
| 3855 AA == AbbrevIndex(A) & |
| 3856 VV1 == RelativeIndex(V1) & |
| 3857 VV2 == RelativeIndex(V2) & |
| 3858 T == TypeOf(V1) == TypeOf(V2) & |
| 3859 IsFloat(UnderlyingType(T)) & |
| 3860 N == NumValuedInsts |
| 3861 |
| 3862 **Updates**:: |
| 3863 |
| 3864 ++NumValuedInsts; |
| 3865 TypeOf(%vN) = T |
| 3866 |
| 3867 **Examples**:: |
| 3868 |
| 3869 92:0| 1: <65535, 12, 2> | function |
| 3870 | | float @f0(float %p0, float %p1) { |
| 3871 | | // BlockID = 12 |
| 3872 100:0| 3: <1, 1> | blocks 1; |
| 3873 | | %b0: |
| 3874 102:4| 3: <2, 2, 1, 0> | %v0 = fadd float %p0, %p1; |
| 3875 106:4| 3: <2, 3, 1, 0> | %v1 = fadd float %p0, %v0; |
| 3876 110:4| 3: <10, 1> | ret float %v1; |
| 3877 113:0| 0: <65534> | } |
| 3878 |
| 3879 Floating Point Subtract |
| 3880 ----------------------- |
| 3881 |
| 3882 The floating point subtract instruction returns the difference of its two |
| 3883 arguments. Both arguments and the result must be of the same type. That type |
| 3884 must be a floating point type, or a vector of a floating point type. |
| 3885 |
| 3886 **Syntax**:: |
| 3887 |
| 3888 %vN = fsub T V1, V2; <a> |
| 3889 |
| 3890 **Record**:: |
| 3891 |
| 3892 AA: <2, VV1, VV2, 1> |
| 3893 |
| 3894 **Semantics**: |
| 3895 |
| 3896 The floating point subtract instruction returns the difference of its two |
| 3897 arguments. Arguments ``V1`` and ``V2``, and the result ``%vN`` must be of type |
| 3898 ``T``. ``T`` must be a floating point type, or a vector of a floating point |
| 3899 type. ``N`` is defined by the record position, defining the corresponding value |
| 3900 generated by the instruction. |
| 3901 |
| 3902 **Constraints**:: |
| 3903 |
| 3904 AA == AbbrevIndex(A) & |
| 3905 VV1 == RelativeIndex(V1) & |
| 3906 VV2 == RelativeIndex(V2) & |
| 3907 T == TypeOf(V1) == TypeOf(V2) & |
| 3908 IsFloat(UnderlyingType(T)) & |
| 3909 N == NumValuedInsts |
| 3910 |
| 3911 **Updates**:: |
| 3912 |
| 3913 ++NumValuedInsts; |
| 3914 TypeOf(%vN) = T |
| 3915 |
| 3916 **Examples**:: |
| 3917 |
| 3918 92:0| 1: <65535, 12, 2> | function |
| 3919 | | float @f0(float %p0, float %p1) { |
| 3920 | | // BlockID = 12 |
| 3921 100:0| 3: <1, 1> | blocks 1; |
| 3922 | | %b0: |
| 3923 102:4| 3: <2, 2, 1, 1> | %v0 = fsub float %p0, %p1; |
| 3924 106:4| 3: <2, 3, 1, 1> | %v1 = fsub float %p0, %v0; |
| 3925 110:4| 3: <10, 1> | ret float %v1; |
| 3926 113:0| 0: <65534> | } |
| 3927 |
| 3928 Floating Point Multiply |
| 3929 ----------------------- |
| 3930 |
| 3931 The floating point multiply instruction returns the product of its two |
| 3932 arguments. Both arguments and the result must be of the same type. That type |
| 3933 must be a floating point type, or a vector of a floating point type. |
| 3934 |
| 3935 **Syntax**:: |
| 3936 |
| 3937 &vN = fmul T V1, V2; <A> |
| 3938 |
| 3939 **Record**:: |
| 3940 |
| 3941 AA: <2, VV1, VV2, 2> |
| 3942 |
| 3943 **Semantics**: |
| 3944 |
| 3945 The floating point multiply instruction returns the product of its two |
| 3946 arguments. Arguments ``V1`` and ``V2``, and the result ``%vN`` must be of type |
| 3947 ``T``. ``T`` must be a floating point type, or a vector of a floating point |
| 3948 type. ``N`` is defined by the record position, defining the corresponding value |
| 3949 generated by the instruction. |
| 3950 |
| 3951 **Constraints**:: |
| 3952 |
| 3953 AA == AbbrevIndex(A) & |
| 3954 VV1 == RelativeIndex(V1) & |
| 3955 VV2 == RelativeIndex(V2) & |
| 3956 T == TypeOf(V1) == TypeOf(V2) & |
| 3957 IsFloat(UnderlyingType(T)) & |
| 3958 N == NumValuedInsts |
| 3959 |
| 3960 **Updates**:: |
| 3961 |
| 3962 ++NumValuedInsts; |
| 3963 TypeOf(%vN) = T |
| 3964 |
| 3965 **Examples**:: |
| 3966 |
| 3967 92:0| 1: <65535, 12, 2> | function |
| 3968 | | float @f0(float %p0, float %p1) { |
| 3969 | | // BlockID = 12 |
| 3970 100:0| 3: <1, 1> | blocks 1; |
| 3971 | | %b0: |
| 3972 102:4| 3: <2, 2, 1, 2> | %v0 = fmul float %p0, %p1; |
| 3973 106:4| 3: <2, 3, 1, 2> | %v1 = fmul float %p0, %v0; |
| 3974 110:4| 3: <10, 1> | ret float %v1; |
| 3975 113:0| 0: <65534> | } |
| 3976 |
| 3977 Floating Point Divide |
| 3978 --------------------- |
| 3979 |
| 3980 The floating point divide instruction returns the quotient of its two |
| 3981 arguments. Both arguments and the result must be of the same type. That type |
| 3982 must be a floating point type, or a vector of a floating point type. |
| 3983 |
| 3984 **Syntax**:: |
| 3985 |
| 3986 %vN = fdiv T V1, V2; <A> |
| 3987 |
| 3988 **Record**:: |
| 3989 |
| 3990 AA: <2, V1, V2, 4> |
| 3991 |
| 3992 **Semantics**: |
| 3993 |
| 3994 The floating point divide instruction returns the quotient of its two |
| 3995 arguments. Arguments ``V1`` and ``V2``, and the result ``%vN`` must be of type |
| 3996 ``T``. ``T`` must be a floating point type, or a vector of a floating point |
| 3997 type. ``N`` is defined by the record position, defining the corresponding value |
| 3998 generated by the instruction. |
| 3999 |
| 4000 **Constraints**:: |
| 4001 |
| 4002 AA == AbbrevIndex(A) & |
| 4003 VV1 == RelativeIndex(V1) & |
| 4004 VV22 == RelativeIndex(V2) & |
| 4005 T == TypeOf(V1) == TypeOf(V2) & |
| 4006 IsFloat(UnderlyingType(T)) & |
| 4007 N == NumValuedInsts |
| 4008 |
| 4009 **Updates**:: |
| 4010 |
| 4011 ++NumValuedInsts; |
| 4012 TypeOf(%vN) = T; |
| 4013 |
| 4014 **Examples**:: |
| 4015 |
| 4016 92:0| 1: <65535, 12, 2> | function |
| 4017 | | double |
| 4018 | | @f0(double %p0, double %p1) { |
| 4019 | | // BlockID = 12 |
| 4020 100:0| 3: <1, 1> | blocks 1; |
| 4021 | | %b0: |
| 4022 102:4| 3: <2, 2, 1, 4> | %v0 = fdiv double %p0, %p1; |
| 4023 106:4| 3: <2, 3, 1, 4> | %v1 = fdiv double %p0, %v0; |
| 4024 110:4| 3: <10, 1> | ret double %v1; |
| 4025 113:0| 0: <65534> | } |
| 4026 |
| 4027 Floating Point Remainder |
| 4028 ------------------------ |
| 4029 |
| 4030 The floating point remainder instruction returns the remainder of the quotient |
| 4031 of its two arguments. Both arguments and the result must be of the same |
| 4032 type. That type must be a floating point type, or a vector of a floating point |
| 4033 type. |
| 4034 |
| 4035 **Syntax**:: |
| 4036 |
| 4037 %vN = frem T V1, V2; <A> |
| 4038 |
| 4039 **Record**:: |
| 4040 |
| 4041 AA: <2, VV1, VV2, 6> |
| 4042 |
| 4043 **Semantics**: |
| 4044 |
| 4045 The floating point remainder instruction returns the remainder of the quotient |
| 4046 of its two arguments. Arguments ``V1`` and ``V2``, and the result ``%vN`` must |
| 4047 be of type ``T``. ``T`` must be a floating point type, or a vector of a floating |
| 4048 point type. ``N`` is defined by the record position, defining the corresponding |
| 4049 value generated by the instruction. |
| 4050 |
| 4051 **Constraints**:: |
| 4052 |
| 4053 AA == AbbrevIndex(A) & |
| 4054 VV1 == RelativeIndex(V1) & |
| 4055 VV2 == RelativeIndex(V2) & |
| 4056 T == TypeOf(V1) == TypeOf(V2) & |
| 4057 IsFloat(UnderlyingType(T)) & |
| 4058 N == NumValuedInsts |
| 4059 |
| 4060 **Updates**:: |
| 4061 |
| 4062 ++NumValuedInsts; |
| 4063 TypeOf(%vN) = T |
| 4064 |
| 4065 **Examples**:: |
| 4066 |
| 4067 92:0| 1: <65535, 12, 2> | function |
| 4068 | | double |
| 4069 | | @f0(double %p0, double %p1) { |
| 4070 | | // BlockID = 12 |
| 4071 100:0| 3: <1, 1> | blocks 1; |
| 4072 | | %b0: |
| 4073 102:4| 3: <2, 2, 1, 6> | %v0 = frem double %p0, %p1; |
| 4074 106:4| 3: <2, 3, 1, 6> | %v1 = frem double %p0, %v0; |
| 4075 110:4| 3: <10, 1> | ret double %v1; |
| 4076 113:0| 0: <65534> | } |
| 4077 |
| 4078 .. _link_for_memory_creation_and_access_instructions: |
| 4079 |
| 4080 Memory Creation and Access Instructions |
| 4081 ======================================= |
| 4082 |
| 4083 A key design point of SSA-based representation is how it represents |
| 4084 memory. In PNaCl bitcode files, no memory locations are in SSA |
| 4085 form. This makes things very simple. |
| 4086 |
| 4087 .. _link_for_alloca_instruction: |
| 4088 |
| 4089 Alloca Instruction |
| 4090 ------------------ |
| 4091 |
| 4092 The *alloca* instruction allocates memory on the stack frame of the |
| 4093 currently executing function. This memory is automatically released |
| 4094 when the function returns to its caller. |
| 4095 |
| 4096 **Syntax**:: |
| 4097 |
| 4098 %vN = alloca i8, i32 S, align V; <A> |
| 4099 |
| 4100 **Record**:: |
| 4101 |
| 4102 AA: <19, SS, VV> |
| 4103 |
| 4104 **Semantics**: |
| 4105 |
| 4106 The *alloca* instruction allocates memory on the stack frame of the currently |
| 4107 executing function. The resulting value is a pointer to the allocated memory |
| 4108 (i.e. of type i32). ``S`` is the number of bytes that are allocated on the |
| 4109 stack. ``S`` must be of integer type i32. ``V`` is the alignment of the |
| 4110 generated stack address. |
| 4111 |
| 4112 Alignment must be a power of 2. See :ref:`memory blocks and |
| 4113 alignment<link_for_memory_blocks_and_alignment_section>` for a more detailed |
| 4114 discussion on how to define alignment. |
| 4115 |
| 4116 **Constraints**:: |
| 4117 |
| 4118 AA == AbbrevIndex(A) & |
| 4119 VV == Log2(V+1) & |
| 4120 SS == RelativeIndex(S) & |
| 4121 i32 == TypeOf(S) & |
| 4122 N == NumValuedInsts |
| 4123 |
| 4124 **Updates**:: |
| 4125 |
| 4126 ++NumValuedInsts; |
| 4127 TypeOf(%vN) = i32; |
| 4128 |
| 4129 **Examples**:: |
| 4130 |
| 4131 112:0| 1: <65535, 12, 2> | function void @f1() { |
| 4132 | | // BlockID = 12 |
| 4133 120:0| 3: <1, 1> | blocks 1; |
| 4134 122:4| 1: <65535, 11, 2> | constants { // BlockID = 11 |
| 4135 132:0| 3: <1, 0> | i32: |
| 4136 134:4| 3: <4, 4> | %c0 = i32 2; |
| 4137 137:0| 3: <4, 8> | %c1 = i32 4; |
| 4138 139:4| 3: <4, 16> | %c2 = i32 8; |
| 4139 142:0| 0: <65534> | } |
| 4140 | | %b0: |
| 4141 144:0| 3: <19, 3, 1> | %v0 = alloca i8, i32 %c0, align 1; |
| 4142 147:2| 3: <19, 3, 3> | %v1 = alloca i8, i32 %c1, align 4; |
| 4143 150:4| 3: <19, 3, 4> | %v2 = alloca i8, i32 %c2, align 8; |
| 4144 153:6| 3: <10> | ret void; |
| 4145 155:4| 0: <65534> | } |
| 4146 |
| 4147 Load Instruction |
| 4148 ---------------- |
| 4149 |
| 4150 The *load* instruction is used to read from memory. |
| 4151 |
| 4152 **Syntax**:: |
| 4153 |
| 4154 %vN = load T* P, align V; <A> |
| 4155 |
| 4156 **Record**:: |
| 4157 |
| 4158 AA: <20, PP, VV, TT> |
| 4159 |
| 4160 **Semantics**: |
| 4161 |
| 4162 The load instruction is used to read from memory. ``P`` is the identifier of the |
| 4163 memory address to read. The type of ``P`` must be an ``i32``. ``T`` is the type |
| 4164 of value to read. ``V`` is the alignment of the memory address. |
| 4165 |
| 4166 Type ``T`` must be a vector, integer, or floating point type. Both ``float`` and |
| 4167 ``double`` types are allowed for floating point types. All integer types except |
| 4168 i1 are allowed. |
| 4169 |
| 4170 Alignment must be a power of 2. See :ref:`memory blocks and |
| 4171 alignment<link_for_memory_blocks_and_alignment_section>` for a more detailed |
| 4172 discussion on how to define alignment. |
| 4173 |
| 4174 **Constraints**:: |
| 4175 |
| 4176 AA == AbbrevIndex(A) & |
| 4177 i32 == TypeOf(P) & |
| 4178 PP == RelativeIndex(P) & |
| 4179 VV == Log2(V+1) & |
| 4180 %tTT == TypeID(T) & |
| 4181 N == NumValuedInsts |
| 4182 |
| 4183 **Updates**:: |
| 4184 |
| 4185 ++NumValuedInsts; |
| 4186 TypeOf(%vN) = T; |
| 4187 |
| 4188 **Examples**:: |
| 4189 |
| 4190 40:0| 1: <65535, 17, 2> | types { // BlockID = 17 |
| 4191 48:0| 3: <1, 4> | count 4; |
| 4192 50:4| 3: <7, 32> | @t0 = i32; |
| 4193 53:6| 3: <2> | @t1 = void; |
| 4194 55:4| 3: <4> | @t2 = double; |
| 4195 57:2| 3: <21, 0, 1, 0> | @t3 = void (i32); |
| 4196 61:2| 0: <65534> | } |
| 4197 ... |
| 4198 96:0| 1: <65535, 12, 2> | function void @f0(i32 %p0) { |
| 4199 | | // BlockID = 12 |
| 4200 104:0| 3: <1, 1> | blocks 1; |
| 4201 | | %b0: |
| 4202 106:4| 3: <20, 1, 1, 0> | %v0 = load i32* %p0, align 1; |
| 4203 110:4| 3: <20, 1, 4, 2> | %v1 = load double* %v0, align 8; |
| 4204 114:4| 3: <10> | ret void; |
| 4205 116:2| 0: <65534> | } |
| 4206 |
| 4207 Store Instruction |
| 4208 ----------------- |
| 4209 |
| 4210 The *store* instruction is used to write to memory. |
| 4211 |
| 4212 **Syntax**:: |
| 4213 |
| 4214 store T S, T* P, align V; <A> |
| 4215 |
| 4216 **Record**:: |
| 4217 |
| 4218 AA: <24, PP, SS, VV> |
| 4219 |
| 4220 **Semantics**: |
| 4221 |
| 4222 The store instruction is used to write to memory. ``P`` is the identifier of the |
| 4223 memory address to write to. The type of ``P`` must be an i32 integer. ``T`` is |
| 4224 the type of value to store. ``S`` is the value to store, and must be of type |
| 4225 ``T``. ``V`` is the alignment of the memory address. ``A`` is the (optional) |
| 4226 abbreviation index associated with the record. |
| 4227 |
| 4228 Type ``T`` must be an integer or floating point type. Both ``float`` and |
| 4229 ``double`` types are allowed for floating point types. All integer types except |
| 4230 i1 are allowed. |
| 4231 |
| 4232 Alignment must be a power of 2. See :ref:`memory blocks and |
| 4233 alignment<link_for_memory_Blocks_and_alignment_section>` for a more detailed |
| 4234 discussion on how to define alignment. |
| 4235 |
| 4236 **Constraints**:: |
| 4237 |
| 4238 AA == AbbrevIndex(A) & |
| 4239 i32 == TypeOf(P) & |
| 4240 PP == RelativeIndex(P) & |
| 4241 VV == Log2(V+1) |
| 4242 |
| 4243 **Examples**:: |
| 4244 |
| 4245 40:0| 1: <65535, 17, 2> | types { // BlockID = 17 |
| 4246 48:0| 3: <1, 4> | count 4; |
| 4247 50:4| 3: <7, 32> | @t0 = i32; |
| 4248 53:6| 3: <2> | @t1 = void; |
| 4249 55:4| 3: <4> | @t2 = double; |
| 4250 57:2| 3: <21, 0, 1, 0, 0, 0, 2>| @t3 = void (i32, i32, i32, double); |
| 4251 63:4| 0: <65534> | } |
| 4252 ... |
| 4253 96:0| 1: <65535, 12, 2> | function |
| 4254 | | void |
| 4255 | | @f0(i32 %p0, i32 %p1, i32 %p2, |
| 4256 | | double %p3) { |
| 4257 | | // BlockID = 12 |
| 4258 104:0| 3: <1, 1> | blocks 1; |
| 4259 | | %b0: |
| 4260 106:4| 3: <24, 4, 3, 1> | store i32 %p1, i32* %p0, align 1; |
| 4261 110:4| 3: <24, 2, 1, 4> | store double %p3, double* %p2, |
| 4262 | | align 8; |
| 4263 114:4| 3: <10> | ret void; |
| 4264 116:2| 0: <65534> | } |
| 4265 |
| 4266 .. _link_for_conversion_instructions: |
| 4267 |
| 4268 Conversion Instructions |
| 4269 ======================= |
| 4270 |
| 4271 Conversion instructions all take a single operand and a type. The value is |
| 4272 converted to the corresponding type. |
| 4273 |
| 4274 Integer Truncating Instruction |
| 4275 ------------------------------ |
| 4276 |
| 4277 The integer truncating instruction takes a value to truncate, and a type |
| 4278 defining the truncated type. Both types must be integer types, or integer |
| 4279 vectors with the same number of elements. The bit size of the value must be |
| 4280 larger than the bit size of the destination type. Equal sized types are not |
| 4281 allowed. |
| 4282 |
| 4283 **Syntax**:: |
| 4284 |
| 4285 %vN = trunc T1 V to T2; <A> |
| 4286 |
| 4287 **Record**:: |
| 4288 |
| 4289 AA: <3, VV, TT2, 0> |
| 4290 |
| 4291 **Semantics**: |
| 4292 |
| 4293 The integer truncating instruction takes a value ``V``, and truncates to type |
| 4294 ``T2``. Both ``T1`` and ``T2`` must be integer types, or integer vectors with |
| 4295 the same number of elements. ``T1`` has to be wider than ``T2``. If the value |
| 4296 doesn't fit in in ``T2``, then the higher order bits are dropped. |
| 4297 |
| 4298 **Constraints**:: |
| 4299 |
| 4300 AA == AbbrevIndex(A) & |
| 4301 TypeOf(V) == T1 & |
| 4302 VV == RelativeIndex(V) & |
| 4303 %tTT2 == TypeID(T2) & |
| 4304 BitSizeOf(UnderlyingType(T1)) > BitSizeOf(UnderlyingType(T2)) & |
| 4305 UnderlyingCount(T1) == UnderlyingCount(T2) & |
| 4306 IsInteger(UnderlyingType(T1)) & |
| 4307 IsInteger(UnderlyingType(T2)) & |
| 4308 N == NumValuedInsts |
| 4309 |
| 4310 **Updates**:: |
| 4311 |
| 4312 ++NumValuedInsts; |
| 4313 TypeOf(%vN) = T2; |
| 4314 |
| 4315 **Examples**:: |
| 4316 |
| 4317 40:0| 1: <65535, 17, 2> | types { // BlockID = 17 |
| 4318 48:0| 3: <1, 5> | count 5; |
| 4319 50:4| 3: <7, 32> | @t0 = i32; |
| 4320 53:6| 3: <2> | @t1 = void; |
| 4321 55:4| 3: <7, 16> | @t2 = i16; |
| 4322 58:0| 3: <21, 0, 1, 0> | @t3 = void (i32); |
| 4323 62:0| 3: <7, 8> | @t4 = i8; |
| 4324 64:4| 0: <65534> | } |
| 4325 ... |
| 4326 100:0| 1: <65535, 12, 2> | function void @f0(i32 %p0) { |
| 4327 | | // BlockID = 12 |
| 4328 108:0| 3: <1, 1> | blocks 1; |
| 4329 | | %b0: |
| 4330 110:4| 3: <3, 1, 2, 0> | %v0 = trunc i32 %p0 to i16; |
| 4331 114:4| 3: <3, 1, 4, 0> | %v1 = trunc i16 %v0 to i8; |
| 4332 118:4| 3: <10> | ret void; |
| 4333 120:2| 0: <65534> | } |
| 4334 |
| 4335 Floating Point Truncating Instruction |
| 4336 -------------------------------------- |
| 4337 |
| 4338 The floating point truncating instruction takes a value to truncate, and a type |
| 4339 defining the truncated type. Both types must be floating point types, or |
| 4340 floating point vectors with the same number of elements. The source must be |
| 4341 ``double`` while the destination is ``float``. If the source is a vector, the |
| 4342 destination must also be vector with the same size as the source. |
| 4343 |
| 4344 **Syntax**:: |
| 4345 |
| 4346 %vN = fptrunc T1 V to T2; <A> |
| 4347 |
| 4348 **Record**:: |
| 4349 |
| 4350 AA: <3, VV, TT2, 7> |
| 4351 |
| 4352 **Semantics** |
| 4353 |
| 4354 The floating point truncating instruction takes a value ``V``, and truncates to |
| 4355 type ``T2``. Both ``T1`` and ``T2`` must be floating point types, or floating |
| 4356 point vectors with the same number of elements. ``T1`` must be defined on |
| 4357 ``double`` while ``T2`` is defined on ``float``. If the value can't fit within |
| 4358 the destination type ``T2``, the results are undefined. |
| 4359 |
| 4360 **Constraints**:: |
| 4361 |
| 4362 TypeOf(V) == T1 & |
| 4363 double == UnderlyingType(T1) & |
| 4364 float == UnderlyingType(T2) & |
| 4365 VV == RelativeIndex(V) & |
| 4366 %tTT2 == TypeID(T2) & |
| 4367 BitSizeOf(UnderlyingType(T1)) > BitSizeOf(UnderlyingType(T2)) & |
| 4368 UnderlyingCount(T1) == UnderlyingCount(T2) & |
| 4369 IsFloat(UnderlyingType(T1)) & |
| 4370 IsFloat(UnderlyingType(T2)) & |
| 4371 N == NumValuedInsts |
| 4372 |
| 4373 **Updates**:: |
| 4374 |
| 4375 ++NumValuedInsts; |
| 4376 TypeOf(%vN) = T2; |
| 4377 |
| 4378 **Examples**:: |
| 4379 |
| 4380 40:0| 1: <65535, 17, 2> | types { // BlockID = 17 |
| 4381 48:0| 3: <1, 4> | count 4; |
| 4382 50:4| 3: <3> | @t0 = float; |
| 4383 52:2| 3: <4> | @t1 = double; |
| 4384 54:0| 3: <21, 0, 0, 1> | @t2 = float (double); |
| 4385 58:0| 3: <2> | @t3 = void; |
| 4386 59:6| 0: <65534> | } |
| 4387 ... |
| 4388 92:0| 1: <65535, 12, 2> | function float @f0(double %p0) { |
| 4389 | | // BlockID = 12 |
| 4390 100:0| 3: <1, 1> | blocks 1; |
| 4391 | | %b0: |
| 4392 102:4| 3: <3, 1, 0, 7> | %v0 = fptrunc double %p0 to float; |
| 4393 106:4| 3: <10, 1> | ret float %v0; |
| 4394 109:0| 0: <65534> | } |
| 4395 |
| 4396 |
| 4397 Zero Extending Instruction |
| 4398 -------------------------- |
| 4399 |
| 4400 The zero extending instruction takes a value to extend, and a type to extend it |
| 4401 to. Both types must be integer types, or integer vectors with the same number |
| 4402 of elements. The bit size of the source type must be smaller than the bit size |
| 4403 of the destination type. Equal sized types are not allowed. |
| 4404 |
| 4405 **Syntax**:: |
| 4406 |
| 4407 %vN = zext T1 V to T2; <A> |
| 4408 |
| 4409 **Record**:: |
| 4410 |
| 4411 AA: <3, VV, TT2, 1> |
| 4412 |
| 4413 |
| 4414 **Semantics**: |
| 4415 |
| 4416 The zero extending instruction takes a value ``V``, and expands it to type |
| 4417 ``T2``. Both ``T1`` and ``T2`` must be integer types, or integer vectors with |
| 4418 the same number of elements. ``T2`` must be wider than ``T1``. |
| 4419 |
| 4420 The instruction fills the high order bits of the value with zero bits until it |
| 4421 reaches the size of the destination type. When zero extending from i1, the |
| 4422 result will always be either 0 or 1. |
| 4423 |
| 4424 **Constraints**:: |
| 4425 |
| 4426 AA == AbbrevIndex(A) & |
| 4427 TypeOf(V) == T1 & |
| 4428 VV == RelativeIndex(V) & |
| 4429 %tTT2 == TypeID(T2) & |
| 4430 BitSizeOf(UnderlyingType(T1)) < BitSizeOf(UnderlyingType(T2)) & |
| 4431 UnderlyingCount(T1) == UnderlyingCount(T2) & |
| 4432 IsInteger(UnderlyingType(T1)) & |
| 4433 IsInteger(UnderlyingType(T2)) & |
| 4434 N == NumValuedInsts |
| 4435 |
| 4436 **Updates**:: |
| 4437 |
| 4438 ++NumValuedInsts; |
| 4439 TypeOf(%vN) = T2; |
| 4440 |
| 4441 **Examples**:: |
| 4442 |
| 4443 40:0| 1: <65535, 17, 2> | types { // BlockID = 17 |
| 4444 48:0| 3: <1, 5> | count 5; |
| 4445 50:4| 3: <7, 64> | @t0 = i64; |
| 4446 53:6| 3: <7, 32> | @t1 = i32; |
| 4447 57:0| 3: <21, 0, 0> | @t2 = i64 (); |
| 4448 60:2| 3: <7, 8> | @t3 = i8; |
| 4449 62:6| 3: <2> | @t4 = void; |
| 4450 64:4| 0: <65534> | } |
| 4451 ... |
| 4452 100:0| 1: <65535, 12, 2> | function i64 @f0() { // BlockID = 12 |
| 4453 108:0| 3: <1, 1> | blocks 1; |
| 4454 110:4| 1: <65535, 11, 2> | constants { // BlockID = 11 |
| 4455 120:0| 3: <1, 3> | i8: |
| 4456 122:4| 3: <4, 2> | %c0 = i8 1; |
| 4457 125:0| 0: <65534> | } |
| 4458 | | %b0: |
| 4459 128:0| 3: <3, 1, 1, 1> | %v0 = zext i8 %c0 to i32; |
| 4460 132:0| 3: <3, 1, 0, 1> | %v1 = zext i32 %v0 to i64; |
| 4461 136:0| 3: <10, 1> | ret i64 %v1; |
| 4462 138:4| 0: <65534> | } |
| 4463 |
| 4464 Sign Extending Instruction |
| 4465 -------------------------- |
| 4466 |
| 4467 The sign extending instruction takes a value to cast, and a type to extend it |
| 4468 to. Both types must be integer types, or integral vectors with the same number |
| 4469 of elements. The bit size of the source type must be smaller than the bit size |
| 4470 of the destination type. Equal sized types are not allowed. |
| 4471 |
| 4472 **Syntax**:: |
| 4473 |
| 4474 %vN = sext T1 V to T2; <A> |
| 4475 |
| 4476 **Record**:: |
| 4477 |
| 4478 AA: <3, VV, TT2, 2> |
| 4479 |
| 4480 **Semantics**: |
| 4481 |
| 4482 The sign extending instruction takes a value ``V``, and expands it to type |
| 4483 ``T2``. Both ``T1`` and ``T2`` must be integer types, or integer vectors with |
| 4484 the same number of integers. ``T2`` has to be wider than ``T1``. |
| 4485 |
| 4486 When sign extending, the instruction fills the high order bits of the value with |
| 4487 the (current) high order bit of the value. When sign extending from i1, the |
| 4488 extension always results in -1 or 0. |
| 4489 |
| 4490 **Constraints**:: |
| 4491 |
| 4492 AA == AbbrevIndex(A) & |
| 4493 TypeOf(V) == T1 & |
| 4494 VV == RelativeIndex(V) & |
| 4495 %tTT2 == TypeID(T2) & |
| 4496 BitSizeOf(UnderlyingType(T1)) < BitSizeOf(UnderlyingType(T2)) & |
| 4497 UnderlyingCount(T1) == UnderlyingCount(T2) & |
| 4498 IsInteger(UnderlyingType(T1)) & |
| 4499 IsInteger(UnderlyingType(T2)) & |
| 4500 N == NumValuedInsts |
| 4501 |
| 4502 **Updates**:: |
| 4503 |
| 4504 ++NumValuedInsts; |
| 4505 TypeOf(%vN) = T2; |
| 4506 |
| 4507 **Examples**:: |
| 4508 |
| 4509 40:0| 1: <65535, 17, 2> | types { // BlockID = 17 |
| 4510 48:0| 3: <1, 5> | count 5; |
| 4511 50:4| 3: <7, 64> | @t0 = i64; |
| 4512 53:6| 3: <7, 32> | @t1 = i32; |
| 4513 57:0| 3: <21, 0, 0> | @t2 = i64 (); |
| 4514 60:2| 3: <7, 8> | @t3 = i8; |
| 4515 62:6| 3: <2> | @t4 = void; |
| 4516 64:4| 0: <65534> | } |
| 4517 ... |
| 4518 100:0| 1: <65535, 12, 2> | function i64 @f0() { // BlockID = 12 |
| 4519 108:0| 3: <1, 1> | blocks 1; |
| 4520 110:4| 1: <65535, 11, 2> | constants { // BlockID = 11 |
| 4521 120:0| 3: <1, 3> | i8: |
| 4522 122:4| 3: <4, 3> | %c0 = i8 -1; |
| 4523 125:0| 0: <65534> | } |
| 4524 | | %b0: |
| 4525 128:0| 3: <3, 1, 1, 2> | %v0 = sext i8 %c0 to i32; |
| 4526 132:0| 3: <3, 1, 0, 2> | %v1 = sext i32 %v0 to i64; |
| 4527 136:0| 3: <10, 1> | ret i64 %v1; |
| 4528 138:4| 0: <65534> | } |
| 4529 |
| 4530 Floating Point Extending Instruction |
| 4531 ------------------------------------ |
| 4532 |
| 4533 The floating point extending instruction takes a value to extend, and a type to |
| 4534 extend it to. Both types must either be floating point types, or vectors of |
| 4535 floating point types with the same number of elements. The source value must be |
| 4536 ``float`` while the destination is ``double``. If the source is a vector, the |
| 4537 destination must also be vector with the same size as the source. |
| 4538 |
| 4539 **Syntax**:: |
| 4540 |
| 4541 %vN = fpext T1 V to T2; <A> |
| 4542 |
| 4543 **Record**:: |
| 4544 |
| 4545 AA: <3, VV, TT2, 8> |
| 4546 |
| 4547 **Semantics**: |
| 4548 |
| 4549 The floating point extending instruction converts floating point values. |
| 4550 ``V`` is the value to extend, and ``T2`` is the type to extend it |
| 4551 to. Both ``T1`` and ``T2`` must be floating point types, or floating point |
| 4552 vector types with the same number of floating point values. ``T1`` contains |
| 4553 ``float`` while ``T2`` contains ``double``. |
| 4554 |
| 4555 **Constraints**:: |
| 4556 |
| 4557 AA == AbbrevIndex(A) & |
| 4558 TypeOf(V) == T1 & |
| 4559 VV == RelativeIndex(V) & |
| 4560 %tTT2 == TypeID(T2) & |
| 4561 BitSizeOf(UnderlyingType(T1)) < BitSizeOf(UnderlyingType(T2)) & |
| 4562 UnderlyingCount(T1) == UnderlyingCount(T2) & |
| 4563 IsFloat(UnderlyingType(T1)) & |
| 4564 IsFloat(UnderlyingType(T2)) & |
| 4565 N == NumValuedInsts |
| 4566 |
| 4567 **Updates**:: |
| 4568 |
| 4569 ++NumValuedInsts; |
| 4570 TypeOf(%vN) = T2; |
| 4571 |
| 4572 **Examples**:: |
| 4573 |
| 4574 40:0| 1: <65535, 17, 2> | types { // BlockID = 17 |
| 4575 48:0| 3: <1, 4> | count 4; |
| 4576 50:4| 3: <4> | @t0 = double; |
| 4577 52:2| 3: <3> | @t1 = float; |
| 4578 54:0| 3: <21, 0, 0, 1> | @t2 = double (float); |
| 4579 58:0| 3: <2> | @t3 = void; |
| 4580 59:6| 0: <65534> | } |
| 4581 ... |
| 4582 92:0| 1: <65535, 12, 2> | function double @f0(float %p0) { |
| 4583 | | // BlockID = 12 |
| 4584 100:0| 3: <1, 1> | blocks 1; |
| 4585 | | %b0: |
| 4586 102:4| 3: <3, 1, 0, 8> | %v0 = fpext float %p0 to double; |
| 4587 106:4| 3: <10, 1> | ret double %v0; |
| 4588 109:0| 0: <65534> | } |
| 4589 |
| 4590 Floating Point to Unsigned Integer Instruction |
| 4591 ---------------------------------------------- |
| 4592 |
| 4593 The floating point to unsigned integer instruction converts floating point |
| 4594 values to unsigned integers. |
| 4595 |
| 4596 **Syntax**:: |
| 4597 |
| 4598 %vN = fptoui T1 V to T2; <A> |
| 4599 |
| 4600 **Record**:: |
| 4601 |
| 4602 AA: <3, VV, TT2, 3> |
| 4603 |
| 4604 **Semantics**: |
| 4605 |
| 4606 The floating point to unsigned integer instruction converts floating point |
| 4607 value(s) in ``V`` to its unsigned integer equivalent of type ``T2``. ``T1`` must |
| 4608 be a floating point type, or a floating point vector type. ``T2`` must be an |
| 4609 integer type, or an integer vector type. If either type is a vector type, they |
| 4610 both must have the same number of elements. |
| 4611 |
| 4612 **Constraints**:: |
| 4613 |
| 4614 AA == AbbrevIndex(A) & |
| 4615 TypeOf(V) == T1 & |
| 4616 VV == RelativeIndex(V) & |
| 4617 %tTT2 == TypeID(T2) & |
| 4618 UnderlyingCount(T1) == UnderlyingCount(T2) & |
| 4619 IsFloat(UnderlyingType(T1)) & |
| 4620 IsInteger(UnderlyingType(T2)) & |
| 4621 N == NumValuedInsts |
| 4622 |
| 4623 **Updates**:: |
| 4624 |
| 4625 ++NumValuedInsts; |
| 4626 TypeOf(%vN) = T2; |
| 4627 |
| 4628 **Examples**:: |
| 4629 |
| 4630 40:0| 1: <65535, 17, 2> | types { // BlockID = 17 |
| 4631 48:0| 3: <1, 6> | count 6; |
| 4632 50:4| 3: <3> | @t0 = float; |
| 4633 52:2| 3: <4> | @t1 = double; |
| 4634 54:0| 3: <2> | @t2 = void; |
| 4635 55:6| 3: <21, 0, 2, 0, 1> | @t3 = void (float, double); |
| 4636 60:4| 3: <7, 32> | @t4 = i32; |
| 4637 63:6| 3: <7, 16> | @t5 = i16; |
| 4638 66:2| 0: <65534> | } |
| 4639 ... |
| 4640 100:0| 1: <65535, 12, 2> | function |
| 4641 | | void @f0(float %p0, double %p1) { |
| 4642 | | // BlockID = 12 |
| 4643 108:0| 3: <1, 1> | blocks 1; |
| 4644 | | %b0: |
| 4645 110:4| 3: <3, 2, 4, 3> | %v0 = fptoui float %p0 to i32; |
| 4646 114:4| 3: <3, 2, 5, 3> | %v1 = fptoui double %p1 to i16; |
| 4647 118:4| 3: <10> | ret void; |
| 4648 120:2| 0: <65534> | } |
| 4649 |
| 4650 Floating Point to Signed Integer Instruction |
| 4651 -------------------------------------------- |
| 4652 |
| 4653 The floating point to signed integer instruction converts floating point |
| 4654 values to signed integers. |
| 4655 |
| 4656 **Syntax**:: |
| 4657 |
| 4658 %vN = fptosi T1 V to T2; <A> |
| 4659 |
| 4660 **Record**:: |
| 4661 |
| 4662 AA: <3, VV, TT2, 4> |
| 4663 |
| 4664 **Semantics**: |
| 4665 |
| 4666 The floating point to signed integer instruction converts floating point |
| 4667 value(s) in ``V`` to its signed integer equivalent of type ``T2``. ``T1`` must |
| 4668 be a floating point type, or a floating point vector type. ``T2`` must be an |
| 4669 integer type, or an integer vector type. If either type is a vector type, they |
| 4670 both must have the same number of elements. |
| 4671 |
| 4672 **Constraints**:: |
| 4673 |
| 4674 AA == AbbrevIndex(A) & |
| 4675 TypeOf(V) == T1 & |
| 4676 VV == RelativeIndex(V) & |
| 4677 %tTT2 = TypeID(T2) & |
| 4678 UnderlyingCount(T1) = UnderlyingCount(T2) & |
| 4679 IsFloat(UnderlyingType(T1)) & |
| 4680 IsInteger(UnderlyingType(T2)) & |
| 4681 N = NumValuedInsts |
| 4682 |
| 4683 **Updates**:: |
| 4684 |
| 4685 ++NumValuedInsts; |
| 4686 TypeOf(%vN) = T2; |
| 4687 |
| 4688 **Examples**:: |
| 4689 |
| 4690 40:0| 1: <65535, 17, 2> | types { // BlockID = 17 |
| 4691 48:0| 3: <1, 6> | count 6; |
| 4692 50:4| 3: <3> | @t0 = float; |
| 4693 52:2| 3: <4> | @t1 = double; |
| 4694 54:0| 3: <2> | @t2 = void; |
| 4695 55:6| 3: <21, 0, 2, 0, 1> | @t3 = void (float, double); |
| 4696 60:4| 3: <7, 8> | @t4 = i8; |
| 4697 63:0| 3: <7, 16> | @t5 = i16; |
| 4698 65:4| 0: <65534> | } |
| 4699 ... |
| 4700 100:0| 1: <65535, 12, 2> | function |
| 4701 | | void @f0(float %p0, double %p1) { |
| 4702 | | // BlockID = 12 |
| 4703 108:0| 3: <1, 1> | blocks 1; |
| 4704 | | %b0: |
| 4705 110:4| 3: <3, 2, 4, 4> | %v0 = fptosi float %p0 to i8; |
| 4706 114:4| 3: <3, 2, 5, 4> | %v1 = fptosi double %p1 to i16; |
| 4707 118:4| 3: <10> | ret void; |
| 4708 120:2| 0: <65534> | } |
| 4709 |
| 4710 Unsigned Integer to Floating Point Instruction |
| 4711 ---------------------------------------------- |
| 4712 |
| 4713 The unsigned integer to floating point instruction converts unsigned integers to |
| 4714 floating point values. |
| 4715 |
| 4716 **Syntax**:: |
| 4717 |
| 4718 %vN = uitofp T1 V to T2; <A> |
| 4719 |
| 4720 **Record**:: |
| 4721 |
| 4722 AA: <3, VV, TT2, 5> |
| 4723 |
| 4724 **Semantics**: |
| 4725 |
| 4726 The unsigned integer to floating point instruction converts unsigned integer(s) |
| 4727 to its floating point equivalent of type ``T2``. ``T1`` must be an integer type, |
| 4728 or a integer vector type. ``T2`` must be a floating point type, or a floating |
| 4729 point vector type. If either type is a vector type, they both must have the same |
| 4730 number of elements. |
| 4731 |
| 4732 **Constraints**:: |
| 4733 |
| 4734 AA == AbbrevIndex(A) & |
| 4735 TypeOf(V) == T1 & |
| 4736 VV == RelativeIndex(V) & |
| 4737 %tTT2 = TypeID(T2) & |
| 4738 UnderlyingCount(T1) == UnderlyingCount(T2) & |
| 4739 IsInteger(UnderlyingType(T1)) & |
| 4740 IsFloat(UnderlyingType(T2)) & |
| 4741 N == NumValuedInsts |
| 4742 |
| 4743 **Updates**:: |
| 4744 |
| 4745 ++NumValuedInsts; |
| 4746 TypeOf(%vN) == T2; |
| 4747 |
| 4748 **Examples**:: |
| 4749 |
| 4750 40:0| 1: <65535, 17, 2> | types { // BlockID = 17 |
| 4751 48:0| 3: <1, 7> | count 7; |
| 4752 50:4| 3: <7, 32> | @t0 = i32; |
| 4753 53:6| 3: <7, 64> | @t1 = i64; |
| 4754 57:0| 3: <2> | @t2 = void; |
| 4755 58:6| 3: <3> | @t3 = float; |
| 4756 60:4| 3: <21, 0, 2, 0, 1> | @t4 = void (i32, i64); |
| 4757 65:2| 3: <7, 1> | @t5 = i1; |
| 4758 67:6| 3: <4> | @t6 = double; |
| 4759 69:4| 0: <65534> | } |
| 4760 ... |
| 4761 104:0| 1: <65535, 12, 2> | function void @f0(i32 %p0, i64 %p1) { |
| 4762 | | // BlockID = 12 |
| 4763 112:0| 3: <1, 1> | blocks 1; |
| 4764 114:4| 1: <65535, 11, 2> | constants { // BlockID = 11 |
| 4765 124:0| 3: <1, 5> | i1: |
| 4766 126:4| 3: <4, 3> | %c0 = i1 1; |
| 4767 129:0| 0: <65534> | } |
| 4768 | | %b0: |
| 4769 132:0| 3: <3, 1, 6, 5> | %v0 = uitofp i1 %c0 to double; |
| 4770 136:0| 3: <3, 4, 3, 5> | %v1 = uitofp i32 %p0 to float; |
| 4771 140:0| 3: <3, 4, 3, 5> | %v2 = uitofp i64 %p1 to float; |
| 4772 144:0| 3: <10> | ret void; |
| 4773 145:6| 0: <65534> | } |
| 4774 |
| 4775 Signed Integer to Floating Point Instruction |
| 4776 -------------------------------------------- |
| 4777 |
| 4778 The signed integer to floating point instruction converts signed integers to |
| 4779 floating point values. |
| 4780 |
| 4781 **Syntax**:: |
| 4782 |
| 4783 %vN = sitofp T1 V to T2; <A> |
| 4784 |
| 4785 **Record**:: |
| 4786 |
| 4787 AA: <3, VV, TT2, 6> |
| 4788 |
| 4789 **Semantics**: |
| 4790 |
| 4791 The signed integer to floating point instruction converts signed integer(s) to |
| 4792 its floating point equivalent of type ``T2``. ``T1`` must be an integer type, or |
| 4793 a integer vector type. ``T2`` must be a floating point type, or a floating point |
| 4794 vector type. If either type is a vector type, they both must have the same |
| 4795 number of elements. |
| 4796 |
| 4797 **Constraints**:: |
| 4798 |
| 4799 AA == AbbrevIndex(A) & |
| 4800 TypeOf(V) == T1 & |
| 4801 VV == RelativeIndex(V) & |
| 4802 %tTT2 = TypeID(T2) & |
| 4803 UnderlyingCount(T1) == UnderlyingCount(T2) & |
| 4804 IsInteger(UnderlyingType(T1)) & |
| 4805 IsFloat(UnderlyingType(T2)) & |
| 4806 N == NumValuedInsts |
| 4807 |
| 4808 **Updates**:: |
| 4809 |
| 4810 ++NumValuedInsts; |
| 4811 TypeOf(%vN) = T2; |
| 4812 |
| 4813 **Examples**:: |
| 4814 |
| 4815 40:0| 1: <65535, 17, 2> | types { // BlockID = 17 |
| 4816 48:0| 3: <1, 7> | count 7; |
| 4817 50:4| 3: <7, 32> | @t0 = i32; |
| 4818 53:6| 3: <7, 64> | @t1 = i64; |
| 4819 57:0| 3: <2> | @t2 = void; |
| 4820 58:6| 3: <3> | @t3 = float; |
| 4821 60:4| 3: <21, 0, 2, 0, 1> | @t4 = void (i32, i64); |
| 4822 65:2| 3: <7, 8> | @t5 = i8; |
| 4823 67:6| 3: <4> | @t6 = double; |
| 4824 69:4| 0: <65534> | } |
| 4825 ... |
| 4826 104:0| 1: <65535, 12, 2> | function void @f0(i32 %p0, i64 %p1) { |
| 4827 | | // BlockID = 12 |
| 4828 112:0| 3: <1, 1> | blocks 1; |
| 4829 114:4| 1: <65535, 11, 2> | constants { // BlockID = 11 |
| 4830 124:0| 3: <1, 5> | i8: |
| 4831 126:4| 3: <4, 3> | %c0 = i8 -1; |
| 4832 129:0| 0: <65534> | } |
| 4833 | | %b0: |
| 4834 132:0| 3: <3, 1, 6, 6> | %v0 = sitofp i8 %c0 to double; |
| 4835 136:0| 3: <3, 4, 3, 6> | %v1 = sitofp i32 %p0 to float; |
| 4836 140:0| 3: <3, 4, 3, 6> | %v2 = sitofp i64 %p1 to float; |
| 4837 144:0| 3: <10> | ret void; |
| 4838 145:6| 0: <65534> | } |
| 4839 |
| 4840 Bitcast Instruction |
| 4841 ------------------- |
| 4842 |
| 4843 The bitcast instruction converts the type of the value without changing the bit |
| 4844 contents of the value. The bit size of the type of the value must be the same as |
| 4845 the bit size of the cast type. |
| 4846 |
| 4847 **Syntax**:: |
| 4848 |
| 4849 %vN = bitcast T1 V to T2; <A> |
| 4850 |
| 4851 **Record**:: |
| 4852 |
| 4853 AA: <3, VV, TT2, 11> |
| 4854 |
| 4855 **Semantics**: |
| 4856 |
| 4857 The bitcast instruction converts the type of value ``V`` to type ``T2``. ``T1`` |
| 4858 and ``T2`` must be primitive types or vectors, and define the same number of |
| 4859 bits. |
| 4860 |
| 4861 **Constraints**:: |
| 4862 |
| 4863 AA == AbbrevIndex(A) & |
| 4864 TypeOf(V) == T1 & |
| 4865 VV = RelativeIndex(V) & |
| 4866 %tTT2 = TypeID(T2) & |
| 4867 BitSizeOf(T1) == BitSizeOf(T2) & |
| 4868 N == NumValuedInsts |
| 4869 |
| 4870 **Updates**:: |
| 4871 |
| 4872 ++NumValuedInsts; |
| 4873 TypeOf(%vN) = T2; |
| 4874 |
| 4875 **Examples**:: |
| 4876 |
| 4877 40:0| 1: <65535, 17, 2> | types { // BlockID = 17 |
| 4878 48:0| 3: <1, 6> | count 6; |
| 4879 50:4| 3: <3> | @t0 = float; |
| 4880 52:2| 3: <7, 64> | @t1 = i64; |
| 4881 55:4| 3: <2> | @t2 = void; |
| 4882 57:2| 3: <21, 0, 2, 0, 1> | @t3 = void (float, i64); |
| 4883 62:0| 3: <7, 32> | @t4 = i32; |
| 4884 65:2| 3: <4> | @t5 = double; |
| 4885 67:0| 0: <65534> | } |
| 4886 ... |
| 4887 100:0| 1: <65535, 12, 2> | function void @f0(float %p0, i64 %p1) |
| 4888 | | { // BlockID = 12 |
| 4889 108:0| 3: <1, 1> | blocks 1; |
| 4890 | | %b0: |
| 4891 110:4| 3: <3, 2, 4, 11> | %v0 = bitcast float %p0 to i32; |
| 4892 114:4| 3: <3, 2, 5, 11> | %v1 = bitcast i64 %p1 to double; |
| 4893 118:4| 3: <10> | ret void; |
| 4894 120:2| 0: <65534> | } |
| 4895 |
| 4896 .. _link_for_compare_instructions: |
| 4897 |
| 4898 Comparison Instructions |
| 4899 ======================= |
| 4900 |
| 4901 The comparison instructions compare values and generates a boolean (i1) result |
| 4902 for each pair of compared values. There are different comparison operations for |
| 4903 integer and floating point values. |
| 4904 |
| 4905 |
| 4906 Integer Comparison Instructions |
| 4907 ------------------------------- |
| 4908 |
| 4909 The integer comparison instruction compares integer values and returns a |
| 4910 boolean (i1) result for each pair of compared values. |
| 4911 |
| 4912 **Syntax**:: |
| 4913 |
| 4914 %vN = icmp C T V1, V2; <A> |
| 4915 |
| 4916 **Record**:: |
| 4917 |
| 4918 AA: <9, VV1, VV2, CC> |
| 4919 |
| 4920 **Semantics**: |
| 4921 |
| 4922 The integer comparison instruction compares integer values and returns a boolean |
| 4923 (i1) result for each pair of compared values in ``V1`` and ``V2``. ``V1`` and |
| 4924 ``V2`` must be of type ``T``. ``T`` must be an integer type, or an integer |
| 4925 vector type. Condition code ``C`` is the condition applied to all elements in |
| 4926 ``V1`` and ``V2``. Each comparison always yields an i1. If ``T`` is a primitive |
| 4927 type, the resulting type is i1. If ``T`` is a vector, then the resulting type is |
| 4928 a vector of i1 with the same size as ``T``. |
| 4929 |
| 4930 Legal test conditions are: |
| 4931 |
| 4932 === == ============================== |
| 4933 C CC Operator |
| 4934 === == ============================== |
| 4935 eq 32 equal |
| 4936 ne 33 not equal |
| 4937 ugt 34 unsigned greater than |
| 4938 uge 35 unsigned greater than or equal |
| 4939 ult 36 unsigned less than |
| 4940 ule 37 unsigned less than or equal |
| 4941 sgt 38 signed greater than |
| 4942 sge 39 signed greater than or equal |
| 4943 slt 40 signed less than |
| 4944 sle 41 signed less than or equal |
| 4945 === == ============================== |
| 4946 |
| 4947 **Constraints**:: |
| 4948 |
| 4949 AA == AbbrevIndex(A) & |
| 4950 IsInteger(UnderlyingType(T) & |
| 4951 T == TypeOf(V1) == TypeOf(V2) & |
| 4952 N == NumValuedInsts |
| 4953 |
| 4954 **Updates**:: |
| 4955 |
| 4956 ++NumValuedInsts; |
| 4957 if IsVector(T) then |
| 4958 TypeOf(%vN) = <UnderlyingCount(T), i1> |
| 4959 else |
| 4960 TypeOf(%vN) = i1 |
| 4961 endif |
| 4962 |
| 4963 **Examples**:: |
| 4964 |
| 4965 40:0| 1: <65535, 17, 2> | types { // BlockID = 17 |
| 4966 48:0| 3: <1, 4> | count 4; |
| 4967 50:4| 3: <7, 32> | @t0 = i32; |
| 4968 53:6| 3: <7, 1> | @t1 = i1; |
| 4969 56:2| 3: <2> | @t2 = void; |
| 4970 58:0| 3: <21, 0, 2> | @t3 = void (); |
| 4971 61:2| 0: <65534> | } |
| 4972 ... |
| 4973 108:0| 1: <65535, 12, 2> | function void @f0() { |
| 4974 | | // BlockID = 12 |
| 4975 116:0| 3: <1, 1> | blocks 1; |
| 4976 118:4| 1: <65535, 11, 2> | constants { // BlockID = 11 |
| 4977 128:0| 3: <1, 0> | i32: |
| 4978 130:4| 3: <4, 0> | %c0 = i32 0; |
| 4979 133:0| 3: <4, 2> | %c1 = i32 1; |
| 4980 135:4| 0: <65534> | } |
| 4981 | | %b0: |
| 4982 136:0| 3: <28, 2, 1, 32> | %v0 = icmp eq i32 %c0, %c1; |
| 4983 140:6| 3: <28, 3, 2, 33> | %v1 = icmp ne i32 %c0, %c1; |
| 4984 145:4| 3: <28, 4, 3, 34> | %v2 = icmp ugt i32 %c0, %c1; |
| 4985 150:2| 3: <28, 5, 4, 36> | %v3 = icmp ult i32 %c0, %c1; |
| 4986 155:0| 3: <28, 6, 5, 37> | %v4 = icmp ule i32 %c0, %c1; |
| 4987 159:6| 3: <28, 7, 6, 38> | %v5 = icmp sgt i32 %c0, %c1; |
| 4988 164:4| 3: <28, 8, 7, 38> | %v6 = icmp sgt i32 %c0, %c1; |
| 4989 169:2| 3: <28, 9, 8, 39> | %v7 = icmp sge i32 %c0, %c1; |
| 4990 174:0| 3: <28, 10, 9, 40> | %v8 = icmp slt i32 %c0, %c1; |
| 4991 178:6| 3: <28, 11, 10, 41> | %v9 = icmp sle i32 %c0, %c1; |
| 4992 183:4| 3: <10> | ret void; |
| 4993 185:2| 0: <65534> | } |
| 4994 |
| 4995 |
| 4996 Floating Point Comparison Instructions |
| 4997 -------------------------------------- |
| 4998 |
| 4999 The floating point comparison instruction compares floating point values and |
| 5000 returns a boolean (i1) result for each pair of compared values. |
| 5001 |
| 5002 **Syntax**:: |
| 5003 |
| 5004 %vN = fcmp C T V1, V2; <A> |
| 5005 |
| 5006 **Record**:: |
| 5007 |
| 5008 AA: <9, VV1, VV2, CC> |
| 5009 |
| 5010 **Semantics**: |
| 5011 |
| 5012 The floating point comparison instruction compares floating point values and |
| 5013 returns a boolean (i1) result for each pair of compared values in ``V1`` and |
| 5014 ``V2``. ``V1`` and ``V2`` must be of type ``T``. ``T`` must be a floating point |
| 5015 type, or a floating point vector type. Condition code ``C`` is the condition |
| 5016 applied to all elements in ``V1`` and ``V2``. Each comparison always yields an |
| 5017 i1. If ``T`` is a primitive type, the resulting type is i1. If ``T`` is a |
| 5018 vector, then the resulting type is a vector of i1 with the same size as ``T``. |
| 5019 |
| 5020 Legal test conditions are: |
| 5021 |
| 5022 ===== == ================================== |
| 5023 C CC Operator |
| 5024 ===== == ================================== |
| 5025 false 0 Always false |
| 5026 oeq 1 Ordered and equal |
| 5027 ogt 2 Ordered and greater than |
| 5028 oge 3 Ordered and greater than or equal |
| 5029 olt 4 Ordered and less than |
| 5030 ole 5 Ordered and less than or equal |
| 5031 one 6 Ordered and not equal |
| 5032 ord 7 Ordered (no NaNs) |
| 5033 uno 8 Unordered (either NaNs) |
| 5034 ueq 9 Unordered or equal |
| 5035 ugt 10 Unordered or greater than |
| 5036 uge 11 Unordered or greater than or equal |
| 5037 ult 12 Unordered or less than |
| 5038 ule 13 Unordered or less than or equal |
| 5039 une 14 Unordered or not equal |
| 5040 true 15 Always true |
| 5041 ===== == ================================== |
| 5042 |
| 5043 **Constraints**:: |
| 5044 |
| 5045 AA == AbbrevIndex(A) & |
| 5046 IsFloat(UnderlyingType(T) & |
| 5047 T == TypeOf(V1) == TypeOf(V2) & |
| 5048 N == NumValuedInsts |
| 5049 |
| 5050 **Updates**:: |
| 5051 |
| 5052 ++NumValuedInsts; |
| 5053 if IsVector(T) then |
| 5054 TypeOf(%vN) = <UnderlyingCount(T), i1> |
| 5055 else |
| 5056 TypeOf(%vN) = i1 |
| 5057 endif |
| 5058 |
| 5059 **Examples**:: |
| 5060 |
| 5061 40:0| 1: <65535, 17, 2> | types { // BlockID = 17 |
| 5062 48:0| 3: <1, 4> | count 4; |
| 5063 50:4| 3: <3> | @t0 = float; |
| 5064 52:2| 3: <7, 1> | @t1 = i1; |
| 5065 54:6| 3: <2> | @t2 = void; |
| 5066 56:4| 3: <21, 0, 2> | @t3 = void (); |
| 5067 59:6| 0: <65534> | } |
| 5068 ... |
| 5069 108:0| 1: <65535, 12, 2> | function void @f0() { |
| 5070 | | // BlockID = 12 |
| 5071 116:0| 3: <1, 1> | blocks 1; |
| 5072 118:4| 1: <65535, 11, 2> | constants { // BlockID = 11 |
| 5073 128:0| 3: <1, 0> | float: |
| 5074 130:4| 3: <6, 0> | %c0 = float 0; |
| 5075 133:0| 3: <6, 1065353216> | %c1 = float 1; |
| 5076 139:2| 0: <65534> | } |
| 5077 | | %b0: |
| 5078 140:0| 3: <28, 2, 1, 0> | %v0 = fcmp false float %c0, %c1; |
| 5079 144:0| 3: <28, 3, 2, 1> | %v1 = fcmp oeq float %c0, %c1; |
| 5080 148:0| 3: <28, 4, 3, 2> | %v2 = fcmp ogt float %c0, %c1; |
| 5081 152:0| 3: <28, 5, 4, 3> | %v3 = fcmp oge float %c0, %c1; |
| 5082 156:0| 3: <28, 6, 5, 4> | %v4 = fcmp olt float %c0, %c1; |
| 5083 160:0| 3: <28, 7, 6, 5> | %v5 = fcmp ole float %c0, %c1; |
| 5084 164:0| 3: <28, 8, 7, 6> | %v6 = fcmp one float %c0, %c1; |
| 5085 168:0| 3: <28, 9, 8, 7> | %v7 = fcmp ord float %c0, %c1; |
| 5086 172:0| 3: <28, 10, 9, 9> | %v8 = fcmp ueq float %c0, %c1; |
| 5087 176:0| 3: <28, 11, 10, 10> | %v9 = fcmp ugt float %c0, %c1; |
| 5088 180:0| 3: <28, 12, 11, 11> | %v10 = fcmp uge float %c0, %c1; |
| 5089 184:0| 3: <28, 13, 12, 12> | %v11 = fcmp ult float %c0, %c1; |
| 5090 188:0| 3: <28, 14, 13, 13> | %v12 = fcmp ule float %c0, %c1; |
| 5091 192:0| 3: <28, 15, 14, 14> | %v13 = fcmp une float %c0, %c1; |
| 5092 196:0| 3: <28, 16, 15, 8> | %v14 = fcmp uno float %c0, %c1; |
| 5093 200:0| 3: <28, 17, 16, 15> | %v15 = fcmp true float %c0, %c1; |
| 5094 204:0| 3: <10> | ret void; |
| 5095 205:6| 0: <65534> | } |
| 5096 208:0|0: <65534> |} |
| 5097 |
| 5098 .. _link_for_vector_instructions: |
| 5099 |
| 5100 Vector Instructions |
| 5101 =================== |
| 5102 |
| 5103 PNaClAsm supports several instructions that process vectors. This includes the |
| 5104 :ref:`integer<link_for_integer_binary_instructions>` and :ref:`floating |
| 5105 point<link_for_floating_point_binary_instructions>` binary instructions as well |
| 5106 as :ref:`compare<link_for_compare_instructions>` instructions. These |
| 5107 instructions work with vectors and generate resulting (new) vectors. This |
| 5108 section introduces the instructions to construct vectors and extract results. |
| 5109 |
| 5110 .. _link_for_insert_element_instruction_section: |
| 5111 |
| 5112 Insert Element Instruction |
| 5113 -------------------------- |
| 5114 |
| 5115 The *insert element* instruction inserts a scalar value into a vector at a |
| 5116 specified index. The *insert element* instruction takes an existing vector and |
| 5117 puts a scalar value in one of the elements of the vector. |
| 5118 |
| 5119 The *insert element* instruction can be used to construct a vector, one element |
| 5120 at a time. At first glance, it may appear that one can't construct a vector, |
| 5121 since the *insert element* instruction needs a vector to insert elements into. |
| 5122 |
| 5123 The key to understanding vector construction is understand that one can create |
| 5124 an :ref:`undefined<link_for_undefined_literal>` vector literal. Using that |
| 5125 constant as a starting point, one can built up the wanted vector by a sequence |
| 5126 of *insert element* instructions. |
| 5127 |
| 5128 **Syntax**:: |
| 5129 |
| 5130 %vN = insertelement TV V, TE E, i32 I; <A> |
| 5131 |
| 5132 **Record**:: |
| 5133 |
| 5134 AA: <7, VV, EE, II> |
| 5135 |
| 5136 **Semantics**: |
| 5137 |
| 5138 The *insert element* instruction inserts scalar value ``E`` into index ``I`` of |
| 5139 vector ``V``. ``%vN`` holds the updated vector. Type ``TV`` is the type of |
| 5140 vector. It is also the type of updated vector ``%vN``. Type ``TE`` is the type |
| 5141 of scalar value ``E`` and must be the element type of vector ``V``. ``I`` must |
| 5142 be an :ref:`i32 literal<link_for_integer_literal>`. |
| 5143 |
| 5144 If ``I`` exceeds the length of ``V``, the result is undefined. |
| 5145 |
| 5146 **Constraints**:: |
| 5147 |
| 5148 AA == AbbrevIndex(A) & |
| 5149 IsVector(TV) & |
| 5150 TypeOf(V) == TV & |
| 5151 UnderlyingType(TV) == TE & |
| 5152 TypeOf(I) == i32 & |
| 5153 N == NumValuedInsts |
| 5154 |
| 5155 **Updates**:: |
| 5156 |
| 5157 ++NumValuedInsts; |
| 5158 TypeOf(%vN) = TV; |
| 5159 |
| 5160 **Examples**:: |
| 5161 |
| 5162 40:0| 1: <65535, 17, 2> | types { // BlockID = 17 |
| 5163 48:0| 3: <1, 5> | count 5; |
| 5164 50:4| 3: <7, 1> | @t0 = i1; |
| 5165 53:0| 3: <12, 4, 0> | @t1 = <4 x i1>; |
| 5166 56:2| 3: <7, 32> | @t2 = i32; |
| 5167 59:4| 3: <2> | @t3 = void; |
| 5168 61:2| 3: <21, 0, 3> | @t4 = void (); |
| 5169 64:4| 0: <65534> | } |
| 5170 ... |
| 5171 116:0| 1: <65535, 12, 2> | function void @f0() { |
| 5172 | | // BlockID = 12 |
| 5173 124:0| 3: <1, 1> | blocks 1; |
| 5174 126:4| 1: <65535, 11, 2> | constants { // BlockID = 11 |
| 5175 136:0| 3: <1, 0> | i1: |
| 5176 138:4| 3: <4, 0> | %c0 = i1 0; |
| 5177 141:0| 3: <4, 3> | %c1 = i1 1; |
| 5178 143:4| 3: <1, 1> | <4 x i1>: |
| 5179 146:0| 3: <3> | %c2 = <4 x i1> undef; |
| 5180 147:6| 3: <1, 2> | i32: |
| 5181 150:2| 3: <4, 0> | %c3 = i32 0; |
| 5182 152:6| 3: <4, 2> | %c4 = i32 1; |
| 5183 155:2| 3: <4, 4> | %c5 = i32 2; |
| 5184 157:6| 3: <4, 6> | %c6 = i32 3; |
| 5185 160:2| 0: <65534> | } |
| 5186 | | %b0: |
| 5187 164:0| 3: <7, 5, 7, 4> | %v0 = insertelement <4 x i1> %c2, |
| 5188 | | i1 %c0, i32 %c3; |
| 5189 168:0| 3: <7, 1, 7, 4> | %v1 = insertelement <4 x i1> %v0, |
| 5190 | | i1 %c1, i32 %c4; |
| 5191 172:0| 3: <7, 1, 9, 4> | %v2 = insertelement <4 x i1> %v1, |
| 5192 | | i1 %c0, i32 %c5; |
| 5193 176:0| 3: <7, 1, 9, 4> | %v3 = insertelement <4 x i1> %v2, |
| 5194 | | i1 %c1, i32 %c6; |
| 5195 180:0| 3: <10> | ret void; |
| 5196 181:6| 0: <65534> | } |
| 5197 |
| 5198 Extract Element Instruction |
| 5199 --------------------------- |
| 5200 |
| 5201 The *extract element* instruction extracts a single scalar value from a vector |
| 5202 at a specified index. |
| 5203 |
| 5204 **Syntax**:: |
| 5205 |
| 5206 %vN = extractelement TV V, i32 I; <A> |
| 5207 |
| 5208 **Record**:: |
| 5209 |
| 5210 AA: <6, VV, II> |
| 5211 |
| 5212 **Semantics**: |
| 5213 |
| 5214 The *extract element* instruction extracts the scalar value at index ``I`` from |
| 5215 vector ``V``. The extracted value is assigned to ``%vN``. Type ``TV`` is the |
| 5216 type of vector ``V``. ``I`` must be an :ref:`i32 |
| 5217 literal<link_for_integer_literal>`. The type of ``vN`` must be the element type |
| 5218 of vector ``V``. |
| 5219 |
| 5220 If ``I`` exceeds the length of ``V``, the result is undefined. |
| 5221 |
| 5222 **Constraints**:: |
| 5223 |
| 5224 AA == AbbrevIndex(A) & |
| 5225 IsVector(TV) & |
| 5226 TypeOf(V) == TV & |
| 5227 TypeOf(I) == i32 & |
| 5228 N == NumValuedInsts |
| 5229 |
| 5230 **Updates**:: |
| 5231 |
| 5232 ++NumValuedInsts; |
| 5233 TypeOf(%vN) = UnderlyingType(TV); |
| 5234 |
| 5235 **Examples**:: |
| 5236 |
| 5237 96:0| 1: <65535, 12, 2> | function void @f0(<4 x i32> %p0) { |
| 5238 | | // BlockID = 12 |
| 5239 104:0| 3: <1, 1> | blocks 1; |
| 5240 106:4| 1: <65535, 11, 2> | constants { // BlockID = 11 |
| 5241 116:0| 3: <1, 0> | i32: |
| 5242 118:4| 3: <4, 0> | %c0 = i32 0; |
| 5243 121:0| 0: <65534> | } |
| 5244 | | %b0: |
| 5245 124:0| 3: <6, 2, 1> | %v0 = |
| 5246 | | extractelement <4 x i32> %p0, |
| 5247 | | i32 %c0; |
| 5248 127:2| 3: <10> | ret void; |
| 5249 129:0| 0: <65534> | } |
| 5250 |
| 5251 .. _link_for_other_pnaclasm_instructions: |
| 5252 |
| 5253 Other Instructions |
| 5254 ================== |
| 5255 |
| 5256 This section defines miscellaneous instructions which defy better |
| 5257 classification. |
| 5258 |
| 5259 .. _link_for_forward_type_declaration_section: |
| 5260 |
| 5261 Forward Type Declaration |
| 5262 ------------------------ |
| 5263 |
| 5264 The forward type declaration exists to deal with the fact that all instruction |
| 5265 values must have a type associated with them before they are used. For some |
| 5266 simple functions one can easily topologically sort instructions so that |
| 5267 instruction values are defined before they are used. However, if the |
| 5268 implementation contains loops, the loop induced values can't be defined before |
| 5269 they are used. |
| 5270 |
| 5271 The solution is to forward declare the type of an instruction value. One could |
| 5272 forward declare the types of all instructions at the beginning of the function |
| 5273 block. However, this would make the corresponding file size considerably |
| 5274 larger. Rather, one should only generate these forward type declarations |
| 5275 sparingly and only when needed. |
| 5276 |
| 5277 **Syntax**:: |
| 5278 |
| 5279 declare T %vN; <A> |
| 5280 |
| 5281 **Record**:: |
| 5282 |
| 5283 AA: <43, N, TT> |
| 5284 |
| 5285 **Semantics**: |
| 5286 |
| 5287 The forward declare type declaration defines the type to be associated with a |
| 5288 (not yet defined) instruction value ``%vN``. ``T`` is the type of the value |
| 5289 generated by the ``Nth`` value generating instruction in the function block. |
| 5290 |
| 5291 Note: It is an error to define the type of ``%vN`` with a different type than |
| 5292 will be generated by the ``Nth`` value generating instruction in the function |
| 5293 block. |
| 5294 |
| 5295 Also note that this construct is a declaration and not considered an |
| 5296 instruction, even though it appears in the list of instruction records. Hence, |
| 5297 they may appear before and between :ref:`phi<link_for_phi_instruction_section>` |
| 5298 instructions in a basic block. |
| 5299 |
| 5300 **Constraints**:: |
| 5301 |
| 5302 AA = AbbrevIndex(A) & |
| 5303 TT = TypeID(T) |
| 5304 |
| 5305 **Updates**:: |
| 5306 |
| 5307 TypeOf(%vN) = T; |
| 5308 |
| 5309 **Examples**:: |
| 5310 |
| 5311 40:0| 1: <65535, 17, 2> | types { // BlockID = 17 |
| 5312 48:0| 3: <1, 4> | count 4; |
| 5313 50:4| 3: <7, 32> | @t0 = i32; |
| 5314 53:6| 3: <2> | @t1 = void; |
| 5315 55:4| 3: <7, 1> | @t2 = i1; |
| 5316 58:0| 3: <21, 0, 1, 0> | @t3 = void (i32); |
| 5317 62:0| 0: <65534> | } |
| 5318 ... |
| 5319 108:0| 1: <65535, 12, 2> | function void @f0(i32 %p0) { |
| 5320 | | // BlockID = 12 |
| 5321 116:0| 3: <1, 7> | blocks 7; |
| 5322 118:4| 1: <65535, 11, 2> | constants { // BlockID = 11 |
| 5323 128:0| 3: <1, 2> | i1: |
| 5324 130:4| 3: <4, 3> | %c0 = i1 1; |
| 5325 133:0| 0: <65534> | } |
| 5326 | | %b0: |
| 5327 136:0| 3: <11, 4> | br label %b4; |
| 5328 | | %b1: |
| 5329 138:4| 3: <43, 6, 0> | declare i32 %v3; |
| 5330 142:4| 3: <2, 2, 4294967293, 0> | %v0 = add i32 %p0, %v3; |
| 5331 151:0| 3: <11, 6> | br label %b6; |
| 5332 | | %b2: |
| 5333 153:4| 3: <43, 7, 0> | declare i32 %v4; |
| 5334 157:4| 3: <2, 3, 4294967293, 0> | %v1 = add i32 %p0, %v4; |
| 5335 166:0| 3: <11, 6> | br label %b6; |
| 5336 | | %b3: |
| 5337 168:4| 3: <2, 4, 4294967295, 0> | %v2 = add i32 %p0, %v3; |
| 5338 177:0| 3: <11, 6> | br label %b6; |
| 5339 | | %b4: |
| 5340 179:4| 3: <2, 5, 5, 0> | %v3 = add i32 %p0, %p0; |
| 5341 183:4| 3: <11, 1, 5, 5> | br i1 %c0, label %b1, label %b5; |
| 5342 | | %b5: |
| 5343 187:4| 3: <2, 1, 6, 0> | %v4 = add i32 %v3, %p0; |
| 5344 191:4| 3: <11, 2, 3, 6> | br i1 %c0, label %b2, label %b3; |
| 5345 | | %b6: |
| 5346 195:4| 3: <10> | ret void; |
| 5347 197:2| 0: <65534> | } |
| 5348 |
| 5349 .. _link_for_phi_instruction_section: |
| 5350 |
| 5351 Phi Instruction |
| 5352 --------------- |
| 5353 |
| 5354 The *phi* instruction is used to implement phi nodes in the SSA graph |
| 5355 representing the function. Phi instructions can only appear at the beginning of |
| 5356 a basic block. There must be no non-phi instructions (other than forward type |
| 5357 declarations) between the start of the basic block and the *phi* instruction. |
| 5358 |
| 5359 To clarify the origin of each incoming value, the incoming value is associated |
| 5360 with the incoming edge from the corresponding predecessor block that the |
| 5361 incoming value comes from. |
| 5362 |
| 5363 **Syntax**:: |
| 5364 |
| 5365 %vN = phi T [V1, %bB1], ... , [VM, %bBM]; <A> |
| 5366 |
| 5367 **Record**:: |
| 5368 |
| 5369 AA: <16, TT, VV1, B1, ..., VVM, BM> |
| 5370 |
| 5371 **Semantics**: |
| 5372 |
| 5373 The phi instruction is used to implement phi nodes in the SSA graph representing |
| 5374 the function. ``%vN`` is the resulting value of the corresponding phi |
| 5375 node. ``T`` is the type of the phi node. Values ``V1`` through ``VM`` are the |
| 5376 reaching definitions for the phi node while ``%bB1`` through ``%bBM`` are the |
| 5377 corresponding predecessor blocks. Each ``VI`` reaches via the incoming |
| 5378 predecessor edge from block ``%bBI`` (for 1 <= I <= M). Type ``T`` must be the |
| 5379 type associated with each ``VI``. |
| 5380 |
| 5381 **Constraints**:: |
| 5382 |
| 5383 AA == AbbrevIndex(A) & |
| 5384 M > 1 & |
| 5385 TT == TypeID(T) & |
| 5386 T = TypeOf(VI) for all I, 1 <= I <= M & |
| 5387 BI < ExpectedBasicBlocks for all I, 1 <= I <= M & |
| 5388 VVI = SignRotate(RelativeIndex(VI)) for all I, 1 <= I <= M & |
| 5389 N == NumValuedInsts |
| 5390 |
| 5391 **Updates**:: |
| 5392 |
| 5393 ++NumValuedInsts; |
| 5394 TypeOf(%vN) = T; |
| 5395 |
| 5396 **Examples**:: |
| 5397 |
| 5398 40:0| 1: <65535, 17, 2> | types { // BlockID = 17 |
| 5399 48:0| 3: <1, 4> | count 4; |
| 5400 50:4| 3: <7, 32> | @t0 = i32; |
| 5401 53:6| 3: <2> | @t1 = void; |
| 5402 55:4| 3: <21, 0, 1> | @t2 = void (); |
| 5403 58:6| 3: <7, 1> | @t3 = i1; |
| 5404 61:2| 0: <65534> | } |
| 5405 ... |
| 5406 112:0| 1: <65535, 12, 2> | function void @f0() { |
| 5407 | | // BlockID = 12 |
| 5408 120:0| 3: <1, 4> | blocks 4; |
| 5409 122:4| 1: <65535, 11, 2> | constants { // BlockID = 11 |
| 5410 132:0| 3: <1, 0> | i32: |
| 5411 134:4| 3: <4, 2> | %c0 = i32 1; |
| 5412 137:0| 3: <1, 3> | i1: |
| 5413 139:4| 3: <4, 0> | %c1 = i1 0; |
| 5414 142:0| 0: <65534> | } |
| 5415 | | %b0: |
| 5416 144:0| 3: <11, 1, 2, 1> | br i1 %c1, label %b1, label %b2; |
| 5417 | | %b1: |
| 5418 148:0| 3: <2, 2, 2, 0> | %v0 = add i32 %c0, %c0; |
| 5419 152:0| 3: <2, 3, 3, 1> | %v1 = sub i32 %c0, %c0; |
| 5420 156:0| 3: <11, 3> | br label %b3; |
| 5421 | | %b2: |
| 5422 158:4| 3: <2, 4, 4, 2> | %v2 = mul i32 %c0, %c0; |
| 5423 162:4| 3: <2, 5, 5, 3> | %v3 = udiv i32 %c0, %c0; |
| 5424 166:4| 3: <11, 3> | br label %b3; |
| 5425 | | %b3: |
| 5426 169:0| 3: <16, 0, 8, 1, 4, 2> | %v4 = phi i32 [%v0, %b1], |
| 5427 | | [%v2, %b2]; |
| 5428 174:4| 3: <16, 0, 8, 1, 4, 2> | %v5 = phi i32 [%v1, %b1], |
| 5429 | | [%v3, %b2]; |
| 5430 180:0| 3: <10> | ret void; |
| 5431 181:6| 0: <65534> | } |
| 5432 |
| 5433 Select Instruction |
| 5434 ------------------ |
| 5435 |
| 5436 The *select* instruction is used to choose between pairs of values, based on a |
| 5437 condition, without PNaClAsm-level branching. |
| 5438 |
| 5439 **Syntax**:: |
| 5440 |
| 5441 %vN = select CT C, T V1, T V2; <A> |
| 5442 |
| 5443 **Record**:: |
| 5444 |
| 5445 AA: <29, VV1, VV2, CC> |
| 5446 |
| 5447 **Semantics**: |
| 5448 |
| 5449 The *select* instruction chooses pairs of values ``V1`` and ``V2``, based on |
| 5450 condition value ``C``. The type ``CT`` of value ``C`` must either be an i1, or |
| 5451 a vector of type i1. The type of values ``V1`` and ``V2`` must be of type |
| 5452 ``T``. Type ``T`` must either be a primitive type, or a vector of a primitive |
| 5453 type. |
| 5454 |
| 5455 Both ``CT`` and ``T`` must be primitive types, or both must be vector types of |
| 5456 the same size. When the contents of ``C`` is 1, the corresponding value from |
| 5457 ``V1`` will be chosen. Otherwise the corresponding value from ``V2`` will be |
| 5458 chosen. |
| 5459 |
| 5460 **Constraints**:: |
| 5461 |
| 5462 AA == AbbrevIndex(A) & |
| 5463 CC == RelativeIndex(C) & |
| 5464 VV1 == RelativeIndex(V1) & |
| 5465 VV2 == RelativeIndex(V2) & |
| 5466 T == TypeOf(V1) == TypeOf(V2) & |
| 5467 UnderlyingType(CT) == i1 & |
| 5468 IsInteger(UnderlyingType(T)) or IsFloat(UnderlyingType(T)) & |
| 5469 UnderlyingCount(C) == UnderlyingCount(T) & |
| 5470 N == NumValuedInsts |
| 5471 |
| 5472 **Updates**:: |
| 5473 |
| 5474 ++NumValuedInsts; |
| 5475 TypeOf(%vN) = T; |
| 5476 |
| 5477 **Examples**:: |
| 5478 |
| 5479 96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) { |
| 5480 | | // BlockID = 12 |
| 5481 104:0| 3: <1, 1> | blocks 1; |
| 5482 106:4| 1: <65535, 11, 2> | constants { // BlockID = 11 |
| 5483 116:0| 3: <1, 2> | i1: |
| 5484 118:4| 3: <4, 3> | %c0 = i1 1; |
| 5485 121:0| 0: <65534> | } |
| 5486 | | %b0: |
| 5487 124:0| 3: <29, 3, 2, 1> | %v0 = select i1 %c0, i32 %p0, |
| 5488 | | i32 %p1; |
| 5489 128:0| 3: <10, 1> | ret i32 %v0; |
| 5490 130:4| 0: <65534> | } |
| 5491 |
| 5492 |
| 5493 Call Instructions |
| 5494 ----------------- |
| 5495 |
| 5496 The *call* instruction does a function call. The call instruction is used to |
| 5497 cause control flow to transfer to a specified routine, with its incoming |
| 5498 arguments bound to the specified values. When a return instruction in the called |
| 5499 function is reached, control flow continues with the instruction after the |
| 5500 function call. If the call is to a function, the returned value is the value |
| 5501 generated by the call instruction. Otherwise no result is defined by the call. |
| 5502 |
| 5503 If the *tail* flag is associated with the call instruction, then the :ref:`PNaCl |
| 5504 translator<link_for_pnacl_translator>` is free to perform tail call |
| 5505 optimization. That is, the *tail* flag is a hint that may be ignored by the |
| 5506 PNaCl translator. |
| 5507 |
| 5508 There are two kinds of calls: *direct* and *indirect*. A *direct* call calls a |
| 5509 defined :ref:`function address<link_for_function_address_section>` (i.e. a |
| 5510 reference to a bitcode ID of the form ``%fF``). All other calls are *indirect*. |
| 5511 |
| 5512 Direct Procedure Call |
| 5513 ^^^^^^^^^^^^^^^^^^^^^ |
| 5514 |
| 5515 The direct procedure call calls a defined :ref:`function |
| 5516 address<link_for_function_address_section>` whose :ref:`type |
| 5517 signature<link_for_function_type>` returns type void. |
| 5518 |
| 5519 **Syntax**:: |
| 5520 |
| 5521 TAIL call void @fF (T1 A1, ... , TN AN); <A> |
| 5522 |
| 5523 **Record**:: |
| 5524 |
| 5525 AA: <34, CC, F, AA1, ... , AAN> |
| 5526 |
| 5527 **Semantics**: |
| 5528 |
| 5529 The direct procedure call calls a define function address ``%fF`` whose type |
| 5530 signature return type is void. The arguments ``A1`` through ``AN`` are passed in |
| 5531 the order specified. The type of argument ``AI`` must be type ``TI`` (for all I, |
| 5532 1 <=I <= N). Flag ``TAIL`` is optional. If it is included, it must be the |
| 5533 literal ``tail``. |
| 5534 |
| 5535 The types of the arguments must match the corresponding types of the function |
| 5536 signature associated with ``%fF``. The return type of ``%f`` must be void. |
| 5537 |
| 5538 TAIL is encoded into calling convention value ``CC`` as follows: |
| 5539 |
| 5540 ====== == |
| 5541 TAIL CC |
| 5542 ====== == |
| 5543 "" 0 |
| 5544 "tail" 1 |
| 5545 ====== == |
| 5546 |
| 5547 **Constraints**:: |
| 5548 |
| 5549 AA == AbbrevIndex(A) & |
| 5550 N >= 0 & |
| 5551 TypeOfFcn(%fF) == void (T1, ... , TN) & |
| 5552 TypeOf(AI) == TI for all I, 1 <= I <= N |
| 5553 |
| 5554 **Updates**:: |
| 5555 |
| 5556 ++NumValuedInsts; |
| 5557 |
| 5558 **Examples**:: |
| 5559 |
| 5560 72:0| 3: <8, 3, 0, 1, 0> | declare external |
| 5561 | | void @f0(i32, i64, i32); |
| 5562 ... |
| 5563 116:0| 1: <65535, 12, 2> | function void @f1(i32 %p0) { |
| 5564 | | // BlockID = 12 |
| 5565 124:0| 3: <1, 1> | blocks 1; |
| 5566 126:4| 1: <65535, 11, 2> | constants { // BlockID = 11 |
| 5567 136:0| 3: <1, 2> | i64: |
| 5568 138:4| 3: <4, 2> | %c0 = i64 1; |
| 5569 141:0| 0: <65534> | } |
| 5570 | | %b0: |
| 5571 144:0| 3: <34, 0, 4, 2, 1, 2> | call void |
| 5572 | | @f0(i32 %p0, i64 %c0, i32 %p0); |
| 5573 150:2| 3: <10> | ret void; |
| 5574 152:0| 0: <65534> | } |
| 5575 |
| 5576 Direct Function Call |
| 5577 ^^^^^^^^^^^^^^^^^^^^ |
| 5578 |
| 5579 The direct function call calls a defined function address whose type signature |
| 5580 returns a value. |
| 5581 |
| 5582 **Syntax**:: |
| 5583 |
| 5584 %vN = TAIL call RT %fF (T1 A1, ... , TM AM); <A> |
| 5585 |
| 5586 |
| 5587 **Record**:: |
| 5588 |
| 5589 AA: <34, CC, F, AA1, ... , AAM> |
| 5590 |
| 5591 **Semantics**: |
| 5592 |
| 5593 The direct function call calls a defined function address ``%fF`` whose type |
| 5594 signature returned is not type void. The arguments ``A1`` through ``AM`` are |
| 5595 passed in the order specified. The type of argument ``AI`` must be type ``TI`` |
| 5596 (for all I, 1 <= I <= N). Flag ``TAIL`` is optional. If it is included, it must |
| 5597 be the literal ``tail``. |
| 5598 |
| 5599 The types of the arguments must match the corresponding types of the function |
| 5600 signature associated with ``%fF``. The return type must match ``RT``. |
| 5601 |
| 5602 Each parameter type ``TI``, and return type ``RT``, must either be a primitive |
| 5603 type, or a vector type. If the parameter type is an integer type, it must |
| 5604 either be i32 or i64. |
| 5605 |
| 5606 TAIL is encoded into calling convention value ``CC`` as follows: |
| 5607 |
| 5608 ====== == |
| 5609 TAIL CC |
| 5610 ====== == |
| 5611 "" 0 |
| 5612 "tail" 1 |
| 5613 ====== == |
| 5614 |
| 5615 **Constraints**:: |
| 5616 |
| 5617 AA == AbbrevIndex(A) & |
| 5618 N >= 0 & |
| 5619 TypeOfFcn(%fF) == RT (T1, ... , TN) & |
| 5620 TypeOf(AI) == TI for all I, 1 <= I <= M & |
| 5621 IsFcnArgType(TI) for all I, 1 <= I <= M & |
| 5622 IsFcnArgType(RT) & |
| 5623 N == NumValuedInsts |
| 5624 |
| 5625 **Updates**:: |
| 5626 |
| 5627 ++NumValuedInsts; |
| 5628 TypeOf(%vN) = RT; |
| 5629 |
| 5630 **Examples**:: |
| 5631 |
| 5632 72:0| 3: <8, 2, 0, 1, 0> | declare external |
| 5633 | | i32 @f0(i32, i64, i32); |
| 5634 ... |
| 5635 116:0| 1: <65535, 12, 2> | function i32 @f1(i32 %p0) { |
| 5636 | | // BlockID = 12 |
| 5637 124:0| 3: <1, 1> | blocks 1; |
| 5638 126:4| 1: <65535, 11, 2> | constants { // BlockID = 11 |
| 5639 136:0| 3: <1, 1> | i64: |
| 5640 138:4| 3: <4, 2> | %c0 = i64 1; |
| 5641 141:0| 0: <65534> | } |
| 5642 | | %b0: |
| 5643 144:0| 3: <34, 0, 4, 2, 1, 2> | %v0 = call i32 |
| 5644 | | @f0(i32 %p0, i64 %c0, i32 %p0); |
| 5645 150:2| 3: <34, 1, 4, 1> | %v1 = tail call i32 @f1(i32 %v0); |
| 5646 155:0| 3: <10, 2> | ret i32 %v0; |
| 5647 157:4| 0: <65534> | } |
| 5648 |
| 5649 Indirect Procedure Call |
| 5650 ^^^^^^^^^^^^^^^^^^^^^^^ |
| 5651 |
| 5652 The indirect procedure call calls a function using an indirect function address, |
| 5653 and whose type signature is assumed to return type void. It is different from |
| 5654 the direct procedure call because we can't use the type signature of the |
| 5655 corresponding direct function address to type check the construct. |
| 5656 |
| 5657 **Syntax**:: |
| 5658 |
| 5659 TAIL call void V (T1 A1, ... , TN AN); <A> |
| 5660 |
| 5661 **Record**:: |
| 5662 |
| 5663 AA: <44, CC, TV, VV, AA1, ... , AAN> |
| 5664 |
| 5665 **Semantics**: |
| 5666 |
| 5667 The indirect call procedure calls a function using value ``V`` that is an |
| 5668 indirect function address, and whose type signature is assumed to return type |
| 5669 void. The arguments ``A1`` through ``AN`` are passed in the order |
| 5670 specified. The type of argument ``AI`` must be type ``TI`` (for all I, 1 <= I <= |
| 5671 N). Flag ``TAIL`` is optional. If it is included, it must be the literal |
| 5672 ``tail``. |
| 5673 |
| 5674 Each parameter type ``TI`` (1 <= I <= N) must either be a primitive type, or a |
| 5675 vector type. If the parameter type is an integer type, it must either be i32 |
| 5676 or i64. |
| 5677 |
| 5678 TAIL is encoded into calling convention value ``CC`` as follows: |
| 5679 |
| 5680 ====== == |
| 5681 TAIL CC |
| 5682 ====== == |
| 5683 "" 0 |
| 5684 "tail" 1 |
| 5685 ====== == |
| 5686 |
| 5687 The type signature of the called procedure is assumed to be:: |
| 5688 |
| 5689 void (T1, ... , TN) |
| 5690 |
| 5691 It isn't necessary to define this type in the :ref:`types |
| 5692 block<link_for_types_block_section>`, since the type is inferred rather than |
| 5693 used. |
| 5694 |
| 5695 **Constraints**:: |
| 5696 |
| 5697 AA == AbbrevIndex(A) & |
| 5698 N >= 0 & |
| 5699 TV = TypeID(void) & |
| 5700 AbsoluteIndex(V) >= NumFuncAddresses & |
| 5701 TypeOf(AI) == TI for all I, 1 <= I <= N & |
| 5702 IsFcnArgType(TI) for all I, 1 <= I <= N |
| 5703 |
| 5704 **Updates**:: |
| 5705 |
| 5706 ++NumValuedInsts; |
| 5707 |
| 5708 **Examples**:: |
| 5709 |
| 5710 40:0| 1: <65535, 17, 2> | types { // BlockID = 17 |
| 5711 48:0| 3: <1, 3> | count 3; |
| 5712 50:4| 3: <2> | @t0 = void; |
| 5713 52:2| 3: <7, 32> | @t1 = i32; |
| 5714 55:4| 3: <21, 0, 0, 1> | @t2 = void (i32); |
| 5715 59:4| 0: <65534> | } |
| 5716 ... |
| 5717 92:0| 1: <65535, 12, 2> | function void @f0(i32 %p0) { |
| 5718 | | // BlockID = 12 |
| 5719 100:0| 3: <1, 1> | blocks 1; |
| 5720 102:4| 1: <65535, 11, 2> | constants { // BlockID = 11 |
| 5721 112:0| 3: <1, 1> | i32: |
| 5722 114:4| 3: <4, 2> | %c0 = i32 1; |
| 5723 117:0| 0: <65534> | } |
| 5724 | | %b0: |
| 5725 120:0| 3: <44, 0, 2, 0, 1> | call void %p0(i32 %c0); |
| 5726 125:4| 3: <10> | ret void; |
| 5727 127:2| 0: <65534> | } |
| 5728 |
| 5729 Indirect Function Call |
| 5730 ^^^^^^^^^^^^^^^^^^^^^^ |
| 5731 |
| 5732 The indirect function call calls a function using a value that is an indirect |
| 5733 function address. It is different from the direct function call because we can't |
| 5734 use the type signature of the corresponding literal function address to type |
| 5735 check the construct. |
| 5736 |
| 5737 **Syntax**:: |
| 5738 |
| 5739 %vN = TAIL call RT V (T1 A1, ... , TM AM); <A> |
| 5740 |
| 5741 **Record**:: |
| 5742 |
| 5743 AA: <34, CC, RRT, VV, AA1, ... , AAM> |
| 5744 |
| 5745 **Semantics**: |
| 5746 |
| 5747 The indirect function call calls a function using a value ``V`` that is an |
| 5748 indirect function address, and is assumed to return type ``RT``. The arguments |
| 5749 ``A1`` through ``AM`` are passed in the order specified. The type of argument |
| 5750 ``AI`` must be type ``TI`` (for all I, 1 <= I <= N). Flag ``TAIL`` is |
| 5751 optional. If it is included, it must be the literal ``tail``. |
| 5752 |
| 5753 Each parameter type ``TI`` (1 <= I <= M), and return type ``RT``, must either be |
| 5754 a primitive type, or a vector type. If the parameter type is an integer type, |
| 5755 it must either be i32 or i64. |
| 5756 |
| 5757 TAIL is encoded into calling convention value ``CC`` as follows: |
| 5758 |
| 5759 ====== == |
| 5760 TAIL CC |
| 5761 ====== == |
| 5762 '' 0 |
| 5763 'tail' 1 |
| 5764 ====== == |
| 5765 |
| 5766 The type signature of the called function is assumed to be:: |
| 5767 |
| 5768 RT (T1, ... , TN) |
| 5769 |
| 5770 It isn't necessary to define this type in the :ref:`types |
| 5771 block<link_for_types_block_section>`, since the type is inferred rather than |
| 5772 used. |
| 5773 |
| 5774 **Constraints**:: |
| 5775 |
| 5776 AA == AbbrevIndex(A) & |
| 5777 RRT = TypeID(RT) & |
| 5778 VV = RelativeIndex(V) & |
| 5779 M >= 0 & |
| 5780 AbsoluteIndex(V) >= NumFcnAddresses & |
| 5781 TypeOf(AI) == TI for all I, 1 <= I <= M & |
| 5782 IsFcnArgType(TI) for all I, 1 <= I <= M & |
| 5783 IsFcnArgType(RT) & |
| 5784 N == NumValuedInsts |
| 5785 |
| 5786 **Updates**:: |
| 5787 |
| 5788 ++NumValuedInsts; |
| 5789 TypeOf(%vN) = RT; |
| 5790 |
| 5791 **Examples**:: |
| 5792 |
| 5793 40:0| 1: <65535, 17, 2> | types { // BlockID = 17 |
| 5794 48:0| 3: <1, 6> | count 6; |
| 5795 50:4| 3: <7, 32> | @t0 = i32; |
| 5796 53:6| 3: <3> | @t1 = float; |
| 5797 55:4| 3: <4> | @t2 = double; |
| 5798 57:2| 3: <21, 0, 0, 0, 1, 2> | @t3 = i32 (i32, float, double); |
| 5799 62:6| 3: <21, 0, 0, 1, 2> | @t4 = i32 (float, double); |
| 5800 67:4| 3: <2> | @t5 = void; |
| 5801 69:2| 0: <65534> | } |
| 5802 ... |
| 5803 104:0| 1: <65535, 12, 2> | function |
| 5804 | | i32 |
| 5805 | | @f0(i32 %p0, float %p1, |
| 5806 | | double %p2) { |
| 5807 | | // BlockID = 12 |
| 5808 112:0| 3: <1, 1> | blocks 1; |
| 5809 | | %b0: |
| 5810 114:4| 3: <44, 0, 3, 0, 2, 1> | %v0 = call i32 |
| 5811 | | %p0(float %p1, double %p2); |
| 5812 120:6| 3: <10, 1> | ret i32 %v0; |
| 5813 123:2| 0: <65534> | } |
| 5814 |
| 5815 .. _link_for_memory_blocks_and_alignment_section: |
| 5816 |
| 5817 Memory Blocks and Alignment |
| 5818 =========================== |
| 5819 |
| 5820 In general, variable and heap allocated data are represented as byte addressable |
| 5821 memory blocks. Alignment is always a power of 2, and defines an expectation on |
| 5822 the memory address. That is, an alignment is met if the memory address is |
| 5823 (evenly) divisible by the alignment. Note that alignment of 0 is never allowed. |
| 5824 |
| 5825 Alignment plays a role at two points: |
| 5826 |
| 5827 * When you create a local/global variable |
| 5828 |
| 5829 * When you load/store data using a pointer. |
| 5830 |
| 5831 PNaClAsm allows most types to be placed at any address, and therefore can |
| 5832 have alignment of 1. However, many architectures can load more efficiently |
| 5833 if the data has an alignment that is larger than 1. As such, choosing a larger |
| 5834 alignment can make load/stores more efficient. |
| 5835 |
| 5836 On loads and stores, the alignment in the instruction is used to communicate |
| 5837 what assumptions the :ref:`PNaCl translator<link_for_pnacl_translator>` can |
| 5838 make when choosing the appropriate machine instructions. If the alignment is 1, |
| 5839 it can't assume anything about the memory address used by the instruction. When |
| 5840 the alignment is greater than one, it can use that information to potentially |
| 5841 chose a more efficient sequence of instructions to do the load/store. |
| 5842 |
| 5843 When laying out data within a variable, one also considers alignment. The reason |
| 5844 for this is that if you want an address to be aligned, within the bytes defining |
| 5845 the variable, you must choose an alignment for the variable that guarantees that |
| 5846 alignment. |
| 5847 |
| 5848 In PNaClAsm, the valid load/store alignments are: |
| 5849 |
| 5850 =========== ============== |
| 5851 Type Alignment |
| 5852 =========== ============== |
| 5853 i1 1 |
| 5854 i8 1 |
| 5855 i16 1 |
| 5856 i32 1 |
| 5857 i64 1 |
| 5858 Float 1, 4 |
| 5859 Double 1, 8 |
| 5860 <4 x i1> not applicable |
| 5861 <8 x i1> not applicable |
| 5862 <16 x i1> not applicable |
| 5863 <16 x i8> 1 |
| 5864 <8 x i16> 2 |
| 5865 <4 x i32> 4 |
| 5866 <4 x float> 4 |
| 5867 =========== ============== |
| 5868 |
| 5869 Note that only vectors do not have an alignment value of 1. Hence, they can't be |
| 5870 placed at an arbitrary memory address. Also, since vectors on ``i1`` can't be |
| 5871 loaded/stored, the alignment is not applicable for these types. |
| 5872 |
| 5873 .. _link_for_intrinsic_functions_section: |
| 5874 |
| 5875 Intrinsic Functions |
| 5876 =================== |
| 5877 |
| 5878 Intrinsic functions are special in PNaClAsm. They are implemented as specially |
| 5879 named (external) function calls. The purpose of these intrinsic functions is to |
| 5880 extend the PNaClAsm instruction set with additional functionality that is |
| 5881 architecture specific. Hence, they either can't be implemented within PNaClAsm, |
| 5882 or a non-architecture specific implementation may be too slow on some |
| 5883 architectures. In such cases, the :ref:`PNaCl |
| 5884 translator<link_for_pnacl_translator>` must fill in the corresponding |
| 5885 implementation, since only it knows the architecture it is compiling down to. |
| 5886 |
| 5887 Examples of intrinsic function calls are for concurrent operations, atomic |
| 5888 operations, bulk memory moves, thread pointer operations, and long jumps. |
| 5889 |
| 5890 It should be noted that calls to intrinsic functions do not have the same |
| 5891 calling type constraints as ordinary functions. That is, an intrinsic can use |
| 5892 any integer type for arguments/results, unlike ordinary functions (which |
| 5893 restrict integer types to ``i32`` and ``i64``). |
| 5894 |
| 5895 See the :doc:`PNaCl bitcode reference manual<pnacl-bitcode-abi>` for the full |
| 5896 set of intrinsic functions allowed. Note that in PNaClAsm, all pointer types to |
| 5897 an (LLVM) intrinsic function is converted to type i32. |
| 5898 |
| 5899 .. _link_for_support_functions_section: |
| 5900 |
| 5901 Support Functions |
| 5902 ================= |
| 5903 |
| 5904 Defines functions used to convert syntactic representation to values in the |
| 5905 corresponding record. |
| 5906 |
| 5907 SignRotate |
| 5908 ---------- |
| 5909 |
| 5910 The SignRotate function encodes a signed integer in an easily compressible |
| 5911 form. This is done by rotating the sign bit to the rightmost bit, rather than |
| 5912 the leftmost bit. By doing this rotation, both small positive and negative |
| 5913 integers are small (unsigned) integers. Therefore, all small integers can be |
| 5914 encoded as a small (unsigned) integers. |
| 5915 |
| 5916 The definition of SignRotate(N) is: |
| 5917 |
| 5918 ======== ============= ========= |
| 5919 Argument Value Condition |
| 5920 ======== ============= ========= |
| 5921 N abs(N)<<1 N >= 0 |
| 5922 N abs(N)<<1 + 1 N < 0 |
| 5923 ======== ============= ========= |
| 5924 |
| 5925 .. _link_for_absolute_index_section: |
| 5926 |
| 5927 AbsoluteIndex |
| 5928 ------------- |
| 5929 |
| 5930 Bitcode IDs of the forms ``@fN``, ``@gN``, ``%pN``, ``%cN``, and ``%vN``, are |
| 5931 combined into a single index space. This can be done because of the ordering |
| 5932 imposed by PNaClAsm. All function address bitcode IDs must be defined before any |
| 5933 of the other forms of bitcode IDs. All global address bitcode IDs must be |
| 5934 defined before any local bitcode IDs. Within a function block, the parameter |
| 5935 bitcode IDs must be defined before constant IDs, and constant IDs must be |
| 5936 defined before instruction value IDs. |
| 5937 |
| 5938 Hence, within a function block, it is safe to refer to all of these |
| 5939 bitcode IDs using a single *absolute* index. The absolute index for |
| 5940 each kind of bitcode ID is computed as follows: |
| 5941 |
| 5942 ========== =================================================================== |
| 5943 Bitcode ID AbsoluteIndex |
| 5944 ========== =================================================================== |
| 5945 @tN N |
| 5946 @fN N |
| 5947 @gN N + NumFcnAddresses |
| 5948 @pN N + NumFcnAddresses + NumGlobalAddresses |
| 5949 @cN N + NumFcnAddresses + NumGlobalAddresses + NumParams |
| 5950 @vN N + NumFcnAddresses + NumGlobalAddresses + NumParams + NumFcnConsts |
| 5951 ========== =================================================================== |
| 5952 |
| 5953 .. _link_for_relative_index: |
| 5954 |
| 5955 RelativeIndex |
| 5956 ------------- |
| 5957 |
| 5958 Relative indices are used to refer to values within instructions of a function. |
| 5959 The relative index of an ID is always defined in terms of the index associated |
| 5960 with the next value generating instruction. It is defined as follows:: |
| 5961 |
| 5962 RelativeIndex(J) = AbsoluteIndex(%vN) - AbsoluteIndex(J) |
| 5963 |
| 5964 where:: |
| 5965 |
| 5966 N = NumValuedInsts |
| 5967 |
| 5968 AbbrevIndex |
| 5969 ----------- |
| 5970 |
| 5971 This function converts user-defined abbreviation indices to the corresponding |
| 5972 internal abbreviation index saved in the bitcode file. It adds 4 to its |
| 5973 argument, since there are 4 predefined internal abbreviation indices (0, 1, 2, |
| 5974 and 3). |
| 5975 |
| 5976 ========= ============== |
| 5977 N AbbrevIndex(N) |
| 5978 ========= ============== |
| 5979 undefined 3 |
| 5980 %aA A + 4 |
| 5981 @aA A + 4 |
| 5982 ========= ============== |
| 5983 |
| 5984 Log2 |
| 5985 ---- |
| 5986 |
| 5987 This is the 32-bit log2 value of its argument. |
| 5988 |
| 5989 BitSizeOf |
| 5990 --------- |
| 5991 |
| 5992 Returns the number of bits needed to represent its argument (a type). |
| 5993 |
| 5994 ======= ================ |
| 5995 T BitSizeOf |
| 5996 ======= ================ |
| 5997 i1 1 |
| 5998 i8 8 |
| 5999 i16 16 |
| 6000 i32 32 |
| 6001 i64 64 |
| 6002 float 32 |
| 6003 double 64 |
| 6004 <N X T> N * BitSizeOf(T) |
| 6005 ======= ================ |
| 6006 |
| 6007 UnderlyingType |
| 6008 -------------- |
| 6009 |
| 6010 Returns the primitive type of the type construct. For primitive types, the |
| 6011 *UnderlyingType* is itself. For vector types, the base type of the vector is the |
| 6012 underlying type. |
| 6013 |
| 6014 UnderlyingCount |
| 6015 --------------- |
| 6016 |
| 6017 Returns the size of the vector if given a vector, and 0 for primitive types. |
| 6018 Note that this function is used to check if two vectors are of the same size. |
| 6019 It is also used to test if two types are either primitive (i.e. UnderlyingCount |
| 6020 returns 0 for both types) or are vectors of the same size (i.e. UnderlyingCount |
| 6021 returns the same non-zero value). |
| 6022 |
| 6023 IsInteger |
| 6024 --------- |
| 6025 |
| 6026 Returns true if the argument is in {i1, i8, i16, i32, i64}. |
| 6027 |
| 6028 IsFloat |
| 6029 ------- |
| 6030 |
| 6031 Returns true if the argument is in {``float``, ``double``}. |
| 6032 |
| 6033 IsVector |
| 6034 -------- |
| 6035 |
| 6036 Returns true if the argument is a vector type. |
| 6037 |
| 6038 IsPrimitive |
| 6039 ----------- |
| 6040 |
| 6041 Returns true if the argument is a primitive type. That is:: |
| 6042 |
| 6043 IsPrimitive(T) == IsInteger(T) or IsFloat(T) |
| 6044 |
| 6045 IsFcnArgType |
| 6046 ------------ |
| 6047 |
| 6048 Returns true if the argument is a primitive type or a vector type. Further, |
| 6049 if it is an integer type, it must be i32 or i64. That is:: |
| 6050 |
| 6051 IsFcnArgType(T) = (IsInteger(T) and (i32 = BitSizeOf(T) |
| 6052 or i64 == BitSizeOf(T))) |
| 6053 or IsFloat(T) or IsVector(T) |
| 6054 |
| 6055 .. _link_for_abbreviations_section: |
| 6056 |
| 6057 Abbreviations |
| 6058 ============= |
| 6059 |
| 6060 Abbreviations are used to convert PNaCl records to a sequence of bits. PNaCl |
| 6061 uses the same strategy as `LLVM's bitcode file format |
| 6062 <http://llvm.org/docs/BitCodeFormat.html>`_. See that document for more |
| 6063 details. |
| 6064 |
| 6065 It should be noted that we replace LLVM's header (called the *Bitcode Wrapper |
| 6066 Format*) with the bytes of the :ref:`PNaCl record |
| 6067 header<link_for_header_record_section>`. In addition, PNaCl bitcode files do |
| 6068 not allow *blob* abbreviation. |
| 6069 |
| 6070 .. _link_for_abbreviations_block_section: |
| 6071 |
| 6072 Abbreviations Block |
| 6073 ------------------- |
| 6074 |
| 6075 The abbreviations block is the first block in the module build. The |
| 6076 block is divided into sections. Each section is a sequence of records. Each |
| 6077 record in the sequence defines a user-defined abbreviation. Each section |
| 6078 defines abbreviations that can be applied to all (succeeding) blocks of a |
| 6079 particular kind. These abbreviations are denoted by the (global) ID of the form |
| 6080 *@aN*. |
| 6081 |
| 6082 In terms of `LLVM's bitcode file format |
| 6083 <http://llvm.org/docs/BitCodeFormat.html>`_, the abbreviations block is called a |
| 6084 *BLOCKINFO* block. Records *SETBID* and *DEFINE_ABBREV* are the only records |
| 6085 allowed in PNaCl's abbreviation block (i.e. it doesn't allow *BLOCKNAME* and |
| 6086 *SETRECORDNAME* records). |
| 6087 |
| 6088 TODO |
| 6089 ---- |
| 6090 |
| 6091 Extend this document to describe PNaCl's bitcode bit sequencer |
| 6092 without requiring the reader to refer to `LLVM's bitcode file |
| 6093 format <http://llvm.org/docs/BitCodeFormat.html>`_. |
OLD | NEW |