1 ===============================
2 Contents Of PNaCl Bitcode Files
3 ===============================
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.
21 .. image:: /images/PNaClBitcodeFlow.png
23 PNaClAsm uses a *static single assignment* (SSA) based representation that
24 requires generated results to have a single (assignment) source.
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.
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.
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.
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.
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.
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.
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.
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
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.
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
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
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
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
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).
103 Blocks are used to organize records in the bitcode file. The kinds of blocks
104 defined in PNaClAsm are:
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
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.
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.
125 The :ref:`valuesymtab block<link_for_valuesymtab_block_section>` defines
126 textual names for external function addresses.
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.
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.
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.
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.
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
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
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.
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.
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.
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.
190 .. _link_for_pnacl_records:
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
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
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`\ .
218 A PNaCl record is denoted as follows: ::
220 a: <v0, v1, ... , vN>
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.
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.
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
245 .. _link_for_default_abbreviations:
247 Default Abbreviations
248 =====================
250 There are 4 predefined (default) abbreviation indices, used as the default
251 abbreviations for PNaCl records. They are:
254 Abbreviation index for the abbreviation used to bit-encode an exit block
258 Abbreviation index for the abbreviation used to bit-encode an enter block
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.
267 Abbreviation index for the default abbreviation to bit-encode all other
268 records in the bitcode file.
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::
276 In addition, the upper limit for ``B`` is ``16``.
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.
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
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.
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.
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.
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.
313 Global identifiers use the prefix character ``'@'`` while local identifiers use
314 the prefix character ``'%'``.
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.
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
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.
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)
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.
340 The kinds of identifiers used in PNaClAsm are:
343 Global abbreviation identifier.
346 Local abbreviation identifier.
349 Function basic block identifier.
352 Function constant identifier.
355 Global function address identifier.
358 Global variable/constant address identifier.
361 Function parameter identifier.
364 Global type identifier.
367 Value generated by an instruction in a function block.
370 Conventions For Describing Records
371 ==================================
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.
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.
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.
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>`.
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.
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.
414 For example, consider the following syntax rule::
416 %vN = add T O1, O2; <A>
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.
425 To be concrete, the syntactic rule above defines the structure of the following
428 %v10 = add i32 %v1, %v2; <@a5>
429 %v11 = add i32 %v10, %v3;
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.
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
444 In C, the factorial function can be defined as::
447 if (n == 1) return 1;
448 return n * fact(n-1);
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::
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
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
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;
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;
472 80:0| 1: <65535, 14, 2> | valuesymtab { // BlockID = 14
473 88:0| 3: <1, 0, 102, 97, 99, | @f0 : "fact";
476 100:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0) {
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> | }
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;
487 136:6| 3: <10, 2> | ret i32 %c0;
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> | }
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.
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
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``).
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.
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.
521 The types block (starting at bit address ``40:0``), defines 4 types: ``i1``,
522 ``i32``, ``void``, and function signature ``i32 (i32)``.
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``.
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``.
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)``.
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.
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.
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
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
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.
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>`.
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.
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.
586 Function definitions are defined by a sequence of instructions. There are
587 several types of instructions.
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.
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.
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>`.
604 One can also convert integer and floating point values using :ref:`conversion
605 instructions<link_for_conversion_instructions>`.
607 :ref:`Comparison instructions<link_for_compare_instructions>`
608 allow you to compare values.
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.
617 In addition, :ref:`other instructions<link_for_other_pnaclasm_instructions>` are
618 available. This includes function and procedure calls.
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
625 Finally, how to pack records is described in the
626 :ref:`abbreviations<link_for_abbreviations_section>` section.
628 .. _link_for_global_state_section:
633 This section describes the global state associated with PNaClAsm. It is used to
634 define contextual data that is carried between records.
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
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
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.
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.
658 .. _link_to_typing_functions:
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::
668 For each type in the :ref:`types block<link_for_types_block_section>`, a
669 corresponding inverse map::
673 is maintained to convert syntactic types to the corresponding type ID.
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.
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).
685 Function type signatures are maintained using::
687 TypeOfFcn: ID -> Type
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::
693 DefiningFcnIDs: set(ID)
695 .. _link_to_ID_Counters:
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
705 The number of types defined so far (in the :ref:`types
706 block<link_for_types_block_section>`).
709 The number of function addresses defined so far (in the :ref:`module
710 block<link_for_module_block>`).
713 The number of global variable/constant addresses defined so far (in the
714 :ref:`globals block<link_for_globals_block_section>`).
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.
723 The number of constants defined in a function so far (in the corresponding
724 nested :ref:`constants block<link_for_constants_block_section>`).
727 The number of basic blocks defined so far (within a :ref:`function
728 block<link_for_function_blocks_section>`).
731 The number of instructions, generating values, defined so far (within a
732 :ref:`function block<link_for_function_blocks_section>`).
734 .. _link_for_Size_Variables:
739 A number of blocks define expected sizes of constructs. These sizes are recorded
740 in the following size variables:
743 The expected :ref:`number of basic blocks<link_for_basic_blocks_count>` within
744 a function implementation.
747 The expected :ref:`number of types<link_for_types_count_record>` defined in
751 The expected :ref:`number of global variable/constant
752 addresses<link_for_globals_count_record>` in the globals block.
755 The expected :ref:`number of initializers<link_for_compound_initializer>` for
756 a global variable/constant address in the globals block.
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::
762 NumBasicBlocks < ExpectedBasicBlocks
763 NumTypes < ExpectedTypes
764 NumGlobalAddresses < ExpectedGlobals
766 .. _link_to_Other_Variables:
772 The function ID of the function block being processed.
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.
779 .. _link_for_global_record_codes:
784 Global records are records that can appear in any block. These records have
785 the same meaning in multiple kinds of blocks.
787 There are four global PNaCl records, each having its own record code. These
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.
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.
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.
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.
812 All global records can't have user-defined abbreviations associated with
813 them. The :ref:`default abbreviation<link_for_default_abbreviations>` is always
816 .. _link_for_header_record_section:
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.
827 There is no syntax for header records in PNaClAsm.
831 <65532, 80, 69, 88, 69, 1, 0, 8, 0, 17, 0, 4, 0, 2, 0, 0, 0>
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.
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
846 .. _link_for_enter_block_record_section:
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.
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.
869 The block ``ID`` value is dependent on the name ``N``. Valid names and
870 corresponding ``BlockID`` values are defined as follows:
872 ============= ========
874 ============= ========
882 ============= ========
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
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
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 ();
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;
905 .. _link_for_exit_block_record_section:
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
924 All exit records are identical, no matter what block they are ending. An exit
925 record defines the end of the block.
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
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 ();
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;
944 .. _link_for_abbreviation_record:
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.
956 A = abbrev <E1, ... , EM>;
960 2: <65533, M, EE1, ... , EEM>
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.
969 Abbreviations within a block (or a section within the abbreviations block), must
970 be enumerated in order, starting at index ``0``.
972 Valid encodings ``Ei``, and the corresponding sequence of (unsigned) integers
973 ``EEi``, ( for ``1 <= i <= M``) are defined by the following table:
975 ========= ======= ==================================================
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 ========= ======= ==================================================
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.
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
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)>;
1010 61:7| 2: <65533, 2, 1, 4, 0, 2,| @a1 = abbrev <4, vbr(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)>;
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)>;
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)>;
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)>;
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)>;
1037 116:4| 2: <65533, 2, 1, 2, 0, 2,| @a2 = abbrev <2, vbr(8)>;
1039 119:5| 2: <65533, 3, 1, 3, 0, 3,| @a3 = abbrev <3, array(fixed(8))>
1041 123:2| 2: <65533, 2, 1, 4, 0, 2,| @a4 = abbrev <4, vbr(6)>;
1043 126:3| 2: <65533, 3, 1, 4, 0, 2,| @a5 = abbrev <4, vbr(6), vbr(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) {
1063 192:0| 3: <1, 1> | blocks 1;
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> | }
1071 Note that the example above shows the standard abbreviations used by
1074 .. _link_for_types_block_section:
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>`.
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.
1092 Each record in the types block defines a type used by the program. Types can be
1093 broken into the following groups:
1095 Primitive value types
1096 Defines the set of base types for values. This includes various sizes of
1097 integer and floating point types.
1100 A primitive type that doesn't represent any value and has no size.
1103 The type signatures of functions.
1106 Defines vectors of primitive types.
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.
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.
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.
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
1127 To make this more concrete, consider the following example types block::
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> | }
1137 This example defines a types block that defines four type IDs:
1140 A 32-bit integer type.
1142 A 32-bit floating point type.
1146 A function, taking 32-bit integer and float point arguments that returns
1149 .. _link_for_types_count_record:
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
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.
1174 AA == AbbrevIndex(A) &
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> | }
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.
1207 The void type record defines the type that has no values and has no size.
1211 AA == AbbrevIndex(A) &
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> | }
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.
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).
1251 An integer type record defines an integer type. ``B`` defines the number of bits
1252 of the integer type.
1256 AA == AbbrevIndex(A) &
1258 B in {1, 8, 16, 32, 64}
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> | }
1278 32-Bit Floating Point Type
1279 --------------------------
1281 PNaClAsm allows computation on 32-bit floating point values. A floating point
1282 type record defines the 32-bit floating point type.
1294 A floating point type record defines the 32-bit floating point type.
1298 AA == AbbrevIndex(A) &
1304 TypeOf(@tN) = float;
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> | }
1316 64-bit Floating Point Type
1317 --------------------------
1319 PNaClAsm allows computation on 64-bit floating point values. A 64-bit floating
1320 type record defines the 64-bit floating point type.
1332 A double type record defines the 64-bit floating point type.
1336 AA == AbbrevIndex(A) &
1342 TypeOf(@tN) = double;
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> | }
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
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.
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:
1380 ====== ===================
1381 Type Valid element sizes
1382 ====== ===================
1388 ====== ===================
1392 AA == AbbrevIndex(A) &
1393 TT == AbsoluteIndex(TypeID(T)) &
1399 TypeOf(@tN) = <E x T>
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> | }
1421 .. _link_for_function_type:
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.
1431 %tN = RT (T1, ... , TM) <A>
1435 AA: <21, 0, IRT, IT1, ... , ITM>
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.
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.
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
1451 For :ref:`intrinsic functions<link_for_intrinsic_functions_section>`, all
1452 integer types are allowed for both return and parameter types.
1456 AA == AbbrevIndex(A) &
1458 IRT == AbsoluteIndex(TypeID(RT)) &
1459 IT1 == AbsoluteIndex(TypeID(T1)) &
1461 ITM == AbsoluteIndex(TypeID(TM)) &
1467 TypeOf(@tN) = RT (T1, ... , TM)
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> | }
1483 .. _link_for_globals_block_section:
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>`.
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.
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.
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.
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.
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.
1526 For example, consider the following pnacl-bcdis output snippet::
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;
1537 81:2| 0: <65534> | }
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``.
1543 .. _link_for_globals_count_record:
1548 The count record defines the number of global addresses used by the PNaCl
1561 This record must appear first in the globals block. The count record defines
1562 the number of global addresses used by the program.
1566 AA == AbbrevIndex(A)
1570 ExpectedGlobals = N;
1571 ExpectedInitializers = 0;
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;
1584 81:2| 0: <65534> | }
1586 .. _link_for_global_variable_address:
1588 Global Variable Addresses
1589 -------------------------
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.
1597 var @gN, align V, <A>
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.
1610 It is assumed that the memory, referenced by the global variable address, can be
1611 both read and written to.
1615 AA == AbbrevIndex(A) &
1616 N == NumGlobalAddresses &
1617 ExpectedInitializers == 0 &
1622 ++NumGlobalAddresses;
1623 ExpectedInitializers = 1;
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> | }
1637 .. _link_for_global_constant_address:
1639 Global Constant Addresses
1640 -------------------------
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.
1649 const @gN, align V, <A>
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.
1662 It is assumed that the memory, referenced by the global constant address, is
1663 only read, and can't be written to.
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.
1672 AA == AbbrevIndex(A) &
1673 N == NumGlobalAddresses &
1674 ExpectedInitializers == 0 &
1679 ++NumGlobalAddresses;
1680 ExpectedInitializers = 1;
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> | }
1693 Zerofill Initializer
1694 --------------------
1696 The zerofill initializer record initializes a sequence of bytes, associated with
1697 a global address, with zeros.
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``.
1714 AA == AbbrevIndex(A) &
1715 ExpectedInitializers > 0
1719 --ExpectedInitializers;
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> | }
1734 Data records define a sequence of bytes. These bytes define the initial value of
1735 the contents of the corresponding memory.
1739 { B1 , .... , BN } <A>
1743 AA: <3, B1, ..., BN>
1747 A data record defines a sequence of (unsigned) bytes ``B1`` through ``BN``, that
1748 initialize ``N`` bytes of memory.
1752 AA == AbbrevIndex(A) &
1753 ExpectedInitializers > 0
1757 --ExpectedInitializers;
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}
1773 105:2| 0: <65534> | }
1775 Relocation Initializer
1776 ----------------------
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.
1795 A relocation initializer record defines a 4-byte value containing the specified
1796 global address ``V``.
1800 AA == AbbrevIndex(A) &
1801 VV == AbsoluteIndex(V) &
1802 VV >= NumFuncAddresses &
1803 VV < NumFuncAddresses + ExpectedGlobals &
1804 ExpectedInitializers > 0
1808 --ExpectedInitializers;
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;
1826 83:6| 3: <0, 3, 0> | var @g1, align 4,
1827 87:0| 3: <2, 4> | zerofill 4;
1828 89:4| 0: <65534> | }
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.
1835 Subfield Relocation Initializer
1836 -------------------------------
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
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``.
1863 AA == AbbrevIndex(A)
1864 VV == AbsoluteIndex(V)
1865 VV >= NumFuncAddresses
1866 VV < NumFuncAddresses + ExpectedGlobals
1867 ExpectedInitializers > 0
1868 XXX == SignRotate(XX)
1872 --ExpectedInitializers;
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;
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> | }
1893 .. _link_for_compound_initializer:
1895 Compound Initializer
1896 --------------------
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.
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
1911 initializers N { <A>
1921 Defines that the next `N` initializers should be associated with the global
1922 address of the previous record.
1926 AA == AbbrevIndex(A) &
1927 ExpectedInitializers == 1
1931 ExpectedInitializers = N;
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}
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;
1950 88:4| 0: <65534> | }
1952 .. _link_for_valuesymtab_block_section:
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.
1969 The *entry* record defines a name for a function address.
1977 AA: <1, B1, ... , BN>
1981 The *entry* record defines a name ``NAME`` for function address ``V``. ``NAME``
1982 is a sequence of ASCII characters ``B1`` through ``BN``.
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,|
2002 145:4| 3: <1, 2, 95, 115, 116, | @f2 : "_start";
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> | }
2012 .. _link_for_module_block:
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):
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.
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.
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.
2040 The :ref:`types block<link_for_types_block_section>` defines the set of all
2041 types used in the program.
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.
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.
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
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.
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.
2081 .. _link_for_version_record:
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.
2094 Note that currently, only PNaCl bitcode version 2, and version record value 1 is
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.
2113 AA == AbbrevIndex(A)
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> | }
2122 .. _link_for_function_address_section:
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.
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>`.
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
2147 PN LN T0 @fN ( T1 , ... , TM ); <A>
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.
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``,
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.
2170 Valid prototype names ``PN``, and corresponding ``P`` values, are:
2179 Valid linkage names ``LN``, and corresponding ``L`` values, are:
2188 Currently, only one calling convention ``C`` is supported:
2190 = ====================
2191 C Calling Convention
2192 = ====================
2193 0 C calling convention
2194 = ====================
2198 AA = AbbrevIndex(A) &
2199 T = TypeID(TypeOf(T0 ( T1 , ... , TN ))) &
2200 N = NumFuncAddresses
2205 TypeOf(@fN) = TypeOf(TypeID(i32));
2206 TypeOfFcn(@fN) = TypeOf(@tT);
2209 DefiningFcnIDs += @FN;
2210 ++NumDefinedFunctionAddresses;
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();
2230 .. _link_for_constants_block_section:
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.
2240 Currently, only integer literals, floating point literals, and undefined vector
2241 constants can be defined.
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.
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.
2255 To make this more concrete, consider the following example constants block::
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> | }
2268 .. _link_for_constants_set_type_record:
2273 The *set type* record defines the type to use for the (immediately) succeeding
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
2296 ConstantsSetType = T;
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> | }
2311 .. _link_for_undefined_literal:
2316 The *undefined* literal record creates an undefined literal for the type *T*
2317 defined by the preceding *set type* record.
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.
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.
2340 T == ConstantsSetType &
2341 IsPrimitive(T) or IsVector(T)
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> | }
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> | }
2369 .. _link_for_integer_literal:
2374 The *integer literal* record creates an integer literal for the integer type *T*
2375 defined by the preceding *set type* record.
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
2395 T == ConstantsSetType &
2396 VV == SignRotate(V) &
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> | }
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> | }
2434 Floating Point Literal
2435 ----------------------
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.
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``.
2461 T == ConstantsSetType
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> | }
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> | }
2504 .. _link_for_function_blocks_section:
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
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>`
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.
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.
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>`.
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.
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.
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.
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
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.
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`.
2579 The following subsections define the remaining records that can appear in a
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.
2594 function TR @fN ( T0 %p0, ... , TM %pM ) { <B>
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.
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.
2613 @fN in DefiningFcnIDs &
2614 TypeOfFcn(@fN) == TypeOf(TypeID(TR (T0, ... , TM)))
2619 EnclosingFcnID = @fN;
2624 TypeOf(%pI) = TypeOf(TypeID(TI));
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> | }
2636 104:0| 1: <65535, 12, 2> | function void @f0() {
2638 112:0| 3: <1, 1> | blocks 1;
2640 114:4| 3: <10> | ret void;
2641 116:2| 0: <65534> | }
2642 120:0| 1: <65535, 12, 2> | function i32 @f1(i32 %p0) {
2644 128:0| 3: <1, 1> | blocks 1;
2646 130:4| 3: <10, 1> | ret i32 %p0;
2647 133:0| 0: <65534> | }
2649 .. _link_for_basic_blocks_count:
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
2669 The count record defines the number ``N`` of basic blocks in the implemented
2674 AA == AbbrevIndex(A) &
2675 ExpectedBasicBlocks == N &
2680 104:0| 1: <65535, 12, 2> | function void @f0() {
2682 112:0| 3: <1, 1> | blocks 1;
2684 114:4| 3: <10> | ret void;
2685 116:2| 0: <65534> | }
2686 120:0| 1: <65535, 12, 2> | function i32 @f1(i32 %p0) {
2688 128:0| 3: <1, 1> | blocks 1;
2690 130:4| 3: <10, 1> | ret i32 %p0;
2691 133:0| 0: <65534> | }
2693 .. _link_for_terminator_instruction_section:
2695 Terminator Instructions
2696 =======================
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>`.
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.
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
2715 B < ExpectedBasicBlocks
2717 That is, the label is omitted only if this terminator instruction is the last
2718 instruction in the function block.
2720 Return Void Instruction
2721 -----------------------
2723 The return void instruction is used to return control from a function back to
2724 the caller, without returning any value.
2737 The return void instruction returns control to the calling function.
2741 AA == AbbrevIndex(A) &
2742 B == NumBasicBlocks + 1 &
2743 ReturnType(TypeOf(EnclosingFcnID)) == void
2751 104:0| 1: <65535, 12, 2> | function void @f0() {
2753 112:0| 3: <1, 1> | blocks 1;
2755 114:4| 3: <10> | ret void;
2756 116:2| 0: <65534> | }
2758 Return Value Instruction
2759 ------------------------
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.
2776 The return value instruction returns control to the calling function, returning
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``.
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``.
2788 AA == AbbrevIndex(A) &
2789 VV == RelativeIndex(V) &
2790 B == NumBasicBlocks + 1 &
2791 T == TypeOf(V) == ReturnType(TypeOf(EnclosingFcnID))
2799 120:0| 1: <65535, 12, 2> | function i32 @f1(i32 %p0) {
2801 128:0| 3: <1, 1> | blocks 1;
2803 130:4| 3: <10, 1> | ret i32 %p0;
2805 Unconditional Branch Instruction
2806 --------------------------------
2808 The unconditional branch instruction is used to cause control flow to transfer
2809 to a different basic block of the function.
2822 The unconditional branch instruction causes control flow to transfer to basic
2827 AA == AbbrevIndex(A) &
2828 B == NumBasicBlocks + 1 &
2830 N < ExpectedBasicBlocks
2838 88:0| 1: <65535, 12, 2> | function void @f0() {
2840 96:0| 3: <1, 5> | blocks 5;
2842 98:4| 3: <11, 3> | br label %b3;
2844 101:0| 3: <11, 4> | br label %b4;
2846 103:4| 3: <11, 1> | br label %b1;
2848 106:0| 3: <11, 2> | br label %b2;
2850 108:4| 3: <10> | ret void;
2851 110:2| 0: <65534> | }
2853 Conditional Branch Instruction
2854 ------------------------------
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.
2861 br i1 C, %bT, %bBF; <A>
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``.
2876 AA == AbbrevIndex(A) &
2877 CC == RelativeIndex(C) &
2878 B == NumBasicBlocks + 1 &
2880 B1 < ExpectedBasicBlocks &
2882 B2 < ExpectedBasicBlocks &
2891 92:0| 1: <65535, 12, 2> | function void @f0() {
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> | }
2900 120:0| 3: <11, 3> | br label %b3;
2902 122:4| 3: <11, 2, 4, 2> | br i1 %c0, label %b2, label %b4;
2904 126:4| 3: <11, 3> | br label %b3;
2906 129:0| 3: <10> | ret void;
2908 130:6| 3: <11, 2, 3, 1> | br i1 %c1, label %b2, label %b3;
2909 134:6| 0: <65534> | }
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.
2929 Directive to the :ref:`PNaCl translator<link_for_pnacl_translator>` that
2930 this instruction is unreachable.
2934 AA == AbbrevIndex(A)
2935 B == NumBasicBlocks + 1 &
2943 108:0| 1: <65535, 12, 2> | function void @f0(i32 %p0) {
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> | }
2952 136:0| 3: <11, 1, 2, 2> | br i1 %c0, label %b1, label %b2;
2954 140:0| 3: <11, 3, 4, 1> | br i1 %c1, label %b3, label %b4;
2956 144:0| 3: <15> | unreachable;
2958 145:6| 3: <15> | unreachable;
2960 147:4| 3: <10> | ret void;
2961 149:2| 0: <65534> | }
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
2973 default: br label %bB0;
2974 T V1: br label %bB1;
2976 T VN: br label %bBN;
2982 AA: <12, TT, B0, N, (1, 1, VVI, BI | 1 <= i <= N)>
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``.
2996 AA == AbbrevIndex(A) &
2997 B == NumBasicBlocks + 1 &
2999 VI == SignRotate(VI) for all I, 1 <= I <= N &
3007 116:0| 1: <65535, 12, 2> | function void @f0(i32 %p0) {
3009 124:0| 3: <1, 6> | blocks 6;
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;
3019 143:2| 3: <11, 5> | br label %b5;
3021 145:6| 3: <11, 5> | br label %b5;
3023 148:2| 3: <11, 5> | br label %b5;
3025 150:6| 3: <11, 5> | br label %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) {
3031 164:0| 3: <1, 6> | blocks 6;
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;
3041 188:4| 3: <11, 5> | br label %b5;
3043 191:0| 3: <11, 5> | br label %b5;
3045 193:4| 3: <11, 5> | br label %b5;
3047 196:0| 3: <11, 5> | br label %b5;
3049 198:4| 3: <10> | ret void;
3050 200:2| 0: <65534> | }
3052 .. _link_for_integer_binary_instructions:
3054 Integer Binary Instructions
3055 ===========================
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.
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
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
3071 For most binary operations (except some of the logical operations), integer
3072 type i1 is disallowed.
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.
3083 %vN = add T V1, V2; <A>
3087 AA: <2, VV1, VV2, 0>
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.
3096 The result returned is the mathematical result modulo 2\ :sup:`n`\ , where ``n``
3097 is the bit width of the integer result.
3099 Because integers are assumed to use a two's complement representation,
3100 this instruction is appropriate for both signed and unsigned integers.
3102 In the add instruction, integer type ``i1`` (and a vector of integer type
3103 ``i1``) is disallowed.
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 &
3122 96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) {
3124 104:0| 3: <1, 1> | blocks 1;
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> | }
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.
3138 Note: Since there isn't a negate instruction, subtraction from constant zero
3139 should be used to negate values.
3143 %vN = sub T V1, V2; <A>
3147 AA: <2, VV1, VV2, 1>
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.
3156 The result returned is the mathematical result modulo 2\ :sup:`n`\ , where ``n``
3157 is the bit width of the integer result.
3159 Because integers are assumed to use a two's complement representation,
3160 this instruction is appropriate for both signed and unsigned integers.
3162 In the subtract instruction, integer type ``i1`` (and a vector of integer type
3163 ``i1``) is disallowed.
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 &
3182 96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) {
3184 104:0| 3: <1, 1> | blocks 1;
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> | }
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.
3200 &vN = mul T V1, V2; <A>
3204 AA: <2, VV1, VV2, 2>
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
3214 The result returned is the mathematical result modulo 2\ :sup:`n`\ , where ``n``
3215 is the bit width of the integer result.
3217 Because integers are assumed to use a two's complement representation,
3218 this instruction is appropriate for both signed and unsigned integers.
3220 In the subtract instruction, integer type ``i1`` (or a vector on integer type
3221 ``i1``) is disallowed.
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 &
3240 96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) {
3242 104:0| 3: <1, 1> | blocks 1;
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> | }
3249 Signed Integer Divide
3250 ---------------------
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.
3258 %vN = sdiv T V1, V2; <A>
3262 AA: <2, VV1, VV2, 4>
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
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).
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
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.
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 &
3300 96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) {
3302 104:0| 3: <1, 1> | blocks 1;
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> | }
3309 Unsigned Integer Divide
3310 -----------------------
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.
3318 %vN = udiv T V1, V2; <a>
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
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).
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.
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 &
3356 96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) {
3358 104:0| 3: <1, 1> | blocks 1;
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> | }
3365 Signed Integer Remainder
3366 ------------------------
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.
3374 %vN = srem T V1, V2; <A>
3378 AA: <2, VV1, VV2, 6>
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
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).
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.
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.
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 &
3415 96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) {
3417 104:0| 3: <1, 1> | blocks 1;
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> | }
3424 Unsigned Integer Remainder Instruction
3425 --------------------------------------
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.
3433 %vN = urem T V1, V2; <A>
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.
3447 Unsigned values are assumed. Note that signed and unsigned integer division are
3448 distinct operations. For signed integer division use the remainder instruction
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.
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 &
3471 96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) {
3473 104:0| 3: <1, 1> | blocks 1;
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> | }
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.
3489 %vN = shl T V1, V2; <A>
3493 AA: <2, VV1, VV2, 7>
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.
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``.
3508 In the shift left instruction, integer type ``i1`` (and a vector of integer type
3509 ``i1``) is disallowed.
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 &
3528 96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) {
3530 104:0| 3: <1, 1> | blocks 1;
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> | }
3540 The logical shift right instruction returns the first operand, shifted to the
3541 right a specified number of bits with zero fill.
3545 %vN = lshr T V1, V2; <A>
3549 AA: <2, VV1, VV2, 8>
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.
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``.
3564 In the logical shift right instruction, integer type ``i1`` (and a vector of
3565 integer type ``i1``) is disallowed.
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 &
3584 96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) {
3586 104:0| 3: <1, 1> | blocks 1;
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> | }
3593 Arithmetic Shift Right
3594 ----------------------
3596 The arithmetic shift right instruction returns the first operand, shifted to the
3597 right a specified number of bits with sign extension.
3601 %vN = ashr T V1, V2; <A>
3605 AA: <2, VV1, VVA2, 9>
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.
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``.
3620 In the arithmetic shift right instruction, integer type ``i1`` (and a vector of
3621 integral type ``i1``) is disallowed.
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 &
3640 96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) {
3642 104:0| 3: <1, 1> | blocks 1;
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> | }
3652 The *and* instruction returns the bitwise logical and of its two operands.
3656 %vN = and T V1, V2; <A>
3660 AA: <2, VV1, VV2, 10>
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.
3670 The truth table used for the *and* instruction is:
3683 AA == AbbrevIndex(A) &
3684 VV1 == RelativeIndex(V1) &
3685 VV2 == RelativeIndex(V2) &
3686 T == TypeOf(V1) == TypeOf(V2) &
3687 IsInteger(UnderlyingType(T))) &
3697 96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) {
3699 104:0| 3: <1, 1> | blocks 1;
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> | }
3709 The *or* instruction returns the bitwise logical inclusive or of its
3714 %vN = or T V1, V2; <A>
3718 AA: <2, VV1, VV2, 11>
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.
3727 The truth table used for the *or* instruction is:
3740 AA == AbbrevIndex(A) &
3741 VV1 == RelativeIndex(V1) &
3742 VV2 == RelativeIndex(V2) &
3743 T == TypeOf(V1) == TypeOf(V2) &
3744 IsInteger(UnderlyingType(T))) &
3754 96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) {
3756 104:0| 3: <1, 1> | blocks 1;
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> | }
3766 The *xor* instruction returns the bitwise logical exclusive or of its
3771 %vN = xor T V1, V2; <A>
3775 AA: <2, VV1, VV2, 12>
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.
3784 The truth table used for the *xor* instruction is:
3797 AA == AbbrevIndex(A) &
3798 A1 == RelativeIndex(V1) &
3799 A2 == RelativeIndex(V2) &
3800 T == TypeOf(V1) == TypeOf(V2) &
3801 IsInteger(UnderlyingType(T))) &
3811 96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) {
3813 104:0| 3: <1, 1> | blocks 1;
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> | }
3820 .. _link_for_floating_point_binary_instructions:
3822 Floating Point Binary Instructions
3823 ==================================
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.
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.
3839 %vN = fadd T V1, V2; <A>
3843 AA: <2, VV1, VV2, 0>
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
3855 AA == AbbrevIndex(A) &
3856 VV1 == RelativeIndex(V1) &
3857 VV2 == RelativeIndex(V2) &
3858 T == TypeOf(V1) == TypeOf(V2) &
3859 IsFloat(UnderlyingType(T)) &
3869 92:0| 1: <65535, 12, 2> | function
3870 | | float @f0(float %p0, float %p1) {
3872 100:0| 3: <1, 1> | blocks 1;
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> | }
3879 Floating Point Subtract
3880 -----------------------
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.
3888 %vN = fsub T V1, V2; <a>
3892 AA: <2, VV1, VV2, 1>
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.
3904 AA == AbbrevIndex(A) &
3905 VV1 == RelativeIndex(V1) &
3906 VV2 == RelativeIndex(V2) &
3907 T == TypeOf(V1) == TypeOf(V2) &
3908 IsFloat(UnderlyingType(T)) &
3918 92:0| 1: <65535, 12, 2> | function
3919 | | float @f0(float %p0, float %p1) {
3921 100:0| 3: <1, 1> | blocks 1;
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> | }
3928 Floating Point Multiply
3929 -----------------------
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.
3937 &vN = fmul T V1, V2; <A>
3941 AA: <2, VV1, VV2, 2>
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.
3953 AA == AbbrevIndex(A) &
3954 VV1 == RelativeIndex(V1) &
3955 VV2 == RelativeIndex(V2) &
3956 T == TypeOf(V1) == TypeOf(V2) &
3957 IsFloat(UnderlyingType(T)) &
3967 92:0| 1: <65535, 12, 2> | function
3968 | | float @f0(float %p0, float %p1) {
3970 100:0| 3: <1, 1> | blocks 1;
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> | }
3977 Floating Point Divide
3978 ---------------------
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.
3986 %vN = fdiv T V1, V2; <A>
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.
4002 AA == AbbrevIndex(A) &
4003 VV1 == RelativeIndex(V1) &
4004 VV22 == RelativeIndex(V2) &
4005 T == TypeOf(V1) == TypeOf(V2) &
4006 IsFloat(UnderlyingType(T)) &
4016 92:0| 1: <65535, 12, 2> | function
4018 | | @f0(double %p0, double %p1) {
4020 100:0| 3: <1, 1> | blocks 1;
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> | }
4027 Floating Point Remainder
4028 ------------------------
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
4037 %vN = frem T V1, V2; <A>
4041 AA: <2, VV1, VV2, 6>
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.
4053 AA == AbbrevIndex(A) &
4054 VV1 == RelativeIndex(V1) &
4055 VV2 == RelativeIndex(V2) &
4056 T == TypeOf(V1) == TypeOf(V2) &
4057 IsFloat(UnderlyingType(T)) &
4067 92:0| 1: <65535, 12, 2> | function
4069 | | @f0(double %p0, double %p1) {
4071 100:0| 3: <1, 1> | blocks 1;
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> | }
4078 .. _link_for_memory_creation_and_access_instructions:
4080 Memory Creation and Access Instructions
4081 =======================================
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.
4087 .. _link_for_alloca_instruction:
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.
4098 %vN = alloca i8, i32 S, align V; <A>
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.
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.
4118 AA == AbbrevIndex(A) &
4120 SS == RelativeIndex(S) &
4131 112:0| 1: <65535, 12, 2> | function void @f1() {
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> | }
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> | }
4150 The *load* instruction is used to read from memory.
4154 %vN = load T* P, align V; <A>
4158 AA: <20, PP, VV, TT>
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.
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
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.
4176 AA == AbbrevIndex(A) &
4178 PP == RelativeIndex(P) &
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> | }
4198 96:0| 1: <65535, 12, 2> | function void @f0(i32 %p0) {
4200 104:0| 3: <1, 1> | blocks 1;
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> | }
4210 The *store* instruction is used to write to memory.
4214 store T S, T* P, align V; <A>
4218 AA: <24, PP, SS, VV>
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.
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
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.
4238 AA == AbbrevIndex(A) &
4240 PP == RelativeIndex(P) &
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> | }
4253 96:0| 1: <65535, 12, 2> | function
4255 | | @f0(i32 %p0, i32 %p1, i32 %p2,
4258 104:0| 3: <1, 1> | blocks 1;
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,
4263 114:4| 3: <10> | ret void;
4264 116:2| 0: <65534> | }
4266 .. _link_for_conversion_instructions:
4268 Conversion Instructions
4269 =======================
4271 Conversion instructions all take a single operand and a type. The value is
4272 converted to the corresponding type.
4274 Integer Truncating Instruction
4275 ------------------------------
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
4285 %vN = trunc T1 V to T2; <A>
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.
4300 AA == AbbrevIndex(A) &
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)) &
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> | }
4326 100:0| 1: <65535, 12, 2> | function void @f0(i32 %p0) {
4328 108:0| 3: <1, 1> | blocks 1;
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> | }
4335 Floating Point Truncating Instruction
4336 --------------------------------------
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.
4346 %vN = fptrunc T1 V to T2; <A>
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.
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)) &
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> | }
4388 92:0| 1: <65535, 12, 2> | function float @f0(double %p0) {
4390 100:0| 3: <1, 1> | blocks 1;
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> | }
4397 Zero Extending Instruction
4398 --------------------------
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.
4407 %vN = zext T1 V to T2; <A>
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``.
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.
4426 AA == AbbrevIndex(A) &
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)) &
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> | }
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> | }
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> | }
4464 Sign Extending Instruction
4465 --------------------------
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.
4474 %vN = sext T1 V to T2; <A>
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``.
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.
4492 AA == AbbrevIndex(A) &
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)) &
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> | }
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> | }
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> | }
4530 Floating Point Extending Instruction
4531 ------------------------------------
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.
4541 %vN = fpext T1 V to T2; <A>
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``.
4557 AA == AbbrevIndex(A) &
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)) &
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> | }
4582 92:0| 1: <65535, 12, 2> | function double @f0(float %p0) {
4584 100:0| 3: <1, 1> | blocks 1;
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> | }
4590 Floating Point to Unsigned Integer Instruction
4591 ----------------------------------------------
4593 The floating point to unsigned integer instruction converts floating point
4594 values to unsigned integers.
4598 %vN = fptoui T1 V to T2; <A>
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.
4614 AA == AbbrevIndex(A) &
4616 VV == RelativeIndex(V) &
4617 %tTT2 == TypeID(T2) &
4618 UnderlyingCount(T1) == UnderlyingCount(T2) &
4619 IsFloat(UnderlyingType(T1)) &
4620 IsInteger(UnderlyingType(T2)) &
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> | }
4640 100:0| 1: <65535, 12, 2> | function
4641 | | void @f0(float %p0, double %p1) {
4643 108:0| 3: <1, 1> | blocks 1;
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> | }
4650 Floating Point to Signed Integer Instruction
4651 --------------------------------------------
4653 The floating point to signed integer instruction converts floating point
4654 values to signed integers.
4658 %vN = fptosi T1 V to T2; <A>
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.
4674 AA == AbbrevIndex(A) &
4676 VV == RelativeIndex(V) &
4677 %tTT2 = TypeID(T2) &
4678 UnderlyingCount(T1) = UnderlyingCount(T2) &
4679 IsFloat(UnderlyingType(T1)) &
4680 IsInteger(UnderlyingType(T2)) &
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> | }
4700 100:0| 1: <65535, 12, 2> | function
4701 | | void @f0(float %p0, double %p1) {
4703 108:0| 3: <1, 1> | blocks 1;
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> | }
4710 Unsigned Integer to Floating Point Instruction
4711 ----------------------------------------------
4713 The unsigned integer to floating point instruction converts unsigned integers to
4714 floating point values.
4718 %vN = uitofp T1 V to T2; <A>
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
4734 AA == AbbrevIndex(A) &
4736 VV == RelativeIndex(V) &
4737 %tTT2 = TypeID(T2) &
4738 UnderlyingCount(T1) == UnderlyingCount(T2) &
4739 IsInteger(UnderlyingType(T1)) &
4740 IsFloat(UnderlyingType(T2)) &
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> | }
4761 104:0| 1: <65535, 12, 2> | function void @f0(i32 %p0, i64 %p1) {
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> | }
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> | }
4775 Signed Integer to Floating Point Instruction
4776 --------------------------------------------
4778 The signed integer to floating point instruction converts signed integers to
4779 floating point values.
4783 %vN = sitofp T1 V to T2; <A>
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
4799 AA == AbbrevIndex(A) &
4801 VV == RelativeIndex(V) &
4802 %tTT2 = TypeID(T2) &
4803 UnderlyingCount(T1) == UnderlyingCount(T2) &
4804 IsInteger(UnderlyingType(T1)) &
4805 IsFloat(UnderlyingType(T2)) &
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> | }
4826 104:0| 1: <65535, 12, 2> | function void @f0(i32 %p0, i64 %p1) {
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> | }
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> | }
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.
4849 %vN = bitcast T1 V to T2; <A>
4853 AA: <3, VV, TT2, 11>
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
4863 AA == AbbrevIndex(A) &
4865 VV = RelativeIndex(V) &
4866 %tTT2 = TypeID(T2) &
4867 BitSizeOf(T1) == BitSizeOf(T2) &
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> | }
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;
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> | }
4896 .. _link_for_compare_instructions:
4898 Comparison Instructions
4899 =======================
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.
4906 Integer Comparison Instructions
4907 -------------------------------
4909 The integer comparison instruction compares integer values and returns a
4910 boolean (i1) result for each pair of compared values.
4914 %vN = icmp C T V1, V2; <A>
4918 AA: <9, VV1, VV2, CC>
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``.
4930 Legal test conditions are:
4932 === == ==============================
4934 === == ==============================
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 === == ==============================
4949 AA == AbbrevIndex(A) &
4950 IsInteger(UnderlyingType(T) &
4951 T == TypeOf(V1) == TypeOf(V2) &
4958 TypeOf(%vN) = <UnderlyingCount(T), i1>
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> | }
4973 108:0| 1: <65535, 12, 2> | function void @f0() {
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> | }
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> | }
4996 Floating Point Comparison Instructions
4997 --------------------------------------
4999 The floating point comparison instruction compares floating point values and
5000 returns a boolean (i1) result for each pair of compared values.
5004 %vN = fcmp C T V1, V2; <A>
5008 AA: <9, VV1, VV2, CC>
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``.
5020 Legal test conditions are:
5022 ===== == ==================================
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
5041 ===== == ==================================
5045 AA == AbbrevIndex(A) &
5046 IsFloat(UnderlyingType(T) &
5047 T == TypeOf(V1) == TypeOf(V2) &
5054 TypeOf(%vN) = <UnderlyingCount(T), i1>
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> | }
5069 108:0| 1: <65535, 12, 2> | function void @f0() {
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> | }
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> | }
5098 .. _link_for_vector_instructions:
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.
5110 .. _link_for_insert_element_instruction_section:
5112 Insert Element Instruction
5113 --------------------------
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.
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.
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.
5130 %vN = insertelement TV V, TE E, i32 I; <A>
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>`.
5144 If ``I`` exceeds the length of ``V``, the result is undefined.
5148 AA == AbbrevIndex(A) &
5151 UnderlyingType(TV) == TE &
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> | }
5171 116:0| 1: <65535, 12, 2> | function void @f0() {
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> | }
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> | }
5198 Extract Element Instruction
5199 ---------------------------
5201 The *extract element* instruction extracts a single scalar value from a vector
5202 at a specified index.
5206 %vN = extractelement TV V, i32 I; <A>
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
5220 If ``I`` exceeds the length of ``V``, the result is undefined.
5224 AA == AbbrevIndex(A) &
5233 TypeOf(%vN) = UnderlyingType(TV);
5237 96:0| 1: <65535, 12, 2> | function void @f0(<4 x i32> %p0) {
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> | }
5245 124:0| 3: <6, 2, 1> | %v0 =
5246 | | extractelement <4 x i32> %p0,
5248 127:2| 3: <10> | ret void;
5249 129:0| 0: <65534> | }
5251 .. _link_for_other_pnaclasm_instructions:
5256 This section defines miscellaneous instructions which defy better
5259 .. _link_for_forward_type_declaration_section:
5261 Forward Type Declaration
5262 ------------------------
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
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.
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.
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
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.
5302 AA = AbbrevIndex(A) &
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> | }
5319 108:0| 1: <65535, 12, 2> | function void @f0(i32 %p0) {
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> | }
5327 136:0| 3: <11, 4> | br label %b4;
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;
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;
5337 168:4| 3: <2, 4, 4294967295, 0> | %v2 = add i32 %p0, %v3;
5338 177:0| 3: <11, 6> | br label %b6;
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;
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;
5346 195:4| 3: <10> | ret void;
5347 197:2| 0: <65534> | }
5349 .. _link_for_phi_instruction_section:
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.
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.
5365 %vN = phi T [V1, %bB1], ... , [VM, %bBM]; <A>
5369 AA: <16, TT, VV1, B1, ..., VVM, BM>
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``.
5383 AA == AbbrevIndex(A) &
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 &
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> | }
5406 112:0| 1: <65535, 12, 2> | function void @f0() {
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> | }
5416 144:0| 3: <11, 1, 2, 1> | br i1 %c1, label %b1, label %b2;
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;
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;
5426 169:0| 3: <16, 0, 8, 1, 4, 2> | %v4 = phi i32 [%v0, %b1],
5428 174:4| 3: <16, 0, 8, 1, 4, 2> | %v5 = phi i32 [%v1, %b1],
5430 180:0| 3: <10> | ret void;
5431 181:6| 0: <65534> | }
5436 The *select* instruction is used to choose between pairs of values, based on a
5437 condition, without PNaClAsm-level branching.
5441 %vN = select CT C, T V1, T V2; <A>
5445 AA: <29, VV1, VV2, CC>
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
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
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) &
5479 96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) {
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> | }
5487 124:0| 3: <29, 3, 2, 1> | %v0 = select i1 %c0, i32 %p0,
5489 128:0| 3: <10, 1> | ret i32 %v0;
5490 130:4| 0: <65534> | }
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.
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
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*.
5512 Direct Procedure Call
5513 ^^^^^^^^^^^^^^^^^^^^^
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.
5521 TAIL call void @fF (T1 A1, ... , TN AN); <A>
5525 AA: <34, CC, F, AA1, ... , AAN>
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
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.
5538 TAIL is encoded into calling convention value ``CC`` as follows:
5549 AA == AbbrevIndex(A) &
5551 TypeOfFcn(%fF) == void (T1, ... , TN) &
5552 TypeOf(AI) == TI for all I, 1 <= I <= N
5560 72:0| 3: <8, 3, 0, 1, 0> | declare external
5561 | | void @f0(i32, i64, i32);
5563 116:0| 1: <65535, 12, 2> | function void @f1(i32 %p0) {
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> | }
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> | }
5576 Direct Function Call
5577 ^^^^^^^^^^^^^^^^^^^^
5579 The direct function call calls a defined function address whose type signature
5584 %vN = TAIL call RT %fF (T1 A1, ... , TM AM); <A>
5589 AA: <34, CC, F, AA1, ... , AAM>
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``.
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``.
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.
5606 TAIL is encoded into calling convention value ``CC`` as follows:
5617 AA == AbbrevIndex(A) &
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 &
5632 72:0| 3: <8, 2, 0, 1, 0> | declare external
5633 | | i32 @f0(i32, i64, i32);
5635 116:0| 1: <65535, 12, 2> | function i32 @f1(i32 %p0) {
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> | }
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> | }
5649 Indirect Procedure Call
5650 ^^^^^^^^^^^^^^^^^^^^^^^
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.
5659 TAIL call void V (T1 A1, ... , TN AN); <A>
5663 AA: <44, CC, TV, VV, AA1, ... , AAN>
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
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
5678 TAIL is encoded into calling convention value ``CC`` as follows:
5687 The type signature of the called procedure is assumed to be::
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
5697 AA == AbbrevIndex(A) &
5700 AbsoluteIndex(V) >= NumFuncAddresses &
5701 TypeOf(AI) == TI for all I, 1 <= I <= N &
5702 IsFcnArgType(TI) for all I, 1 <= I <= N
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> | }
5717 92:0| 1: <65535, 12, 2> | function void @f0(i32 %p0) {
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> | }
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> | }
5729 Indirect Function Call
5730 ^^^^^^^^^^^^^^^^^^^^^^
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.
5739 %vN = TAIL call RT V (T1 A1, ... , TM AM); <A>
5743 AA: <34, CC, RRT, VV, AA1, ... , AAM>
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``.
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.
5757 TAIL is encoded into calling convention value ``CC`` as follows:
5766 The type signature of the called function is assumed to be::
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
5776 AA == AbbrevIndex(A) &
5778 VV = RelativeIndex(V) &
5780 AbsoluteIndex(V) >= NumFcnAddresses &
5781 TypeOf(AI) == TI for all I, 1 <= I <= M &
5782 IsFcnArgType(TI) for all I, 1 <= I <= M &
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> | }
5803 104:0| 1: <65535, 12, 2> | function
5805 | | @f0(i32 %p0, float %p1,
5808 112:0| 3: <1, 1> | blocks 1;
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> | }
5815 .. _link_for_memory_blocks_and_alignment_section:
5817 Memory Blocks and Alignment
5818 ===========================
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.
5825 Alignment plays a role at two points:
5827 * When you create a local/global variable
5829 * When you load/store data using a pointer.
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.
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.
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
5848 In PNaClAsm, the valid load/store alignments are:
5850 =========== ==============
5852 =========== ==============
5860 <4 x i1> not applicable
5861 <8 x i1> not applicable
5862 <16 x i1> not applicable
5867 =========== ==============
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.
5873 .. _link_for_intrinsic_functions_section:
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.
5887 Examples of intrinsic function calls are for concurrent operations, atomic
5888 operations, bulk memory moves, thread pointer operations, and long jumps.
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``).
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.
5899 .. _link_for_support_functions_section:
5904 Defines functions used to convert syntactic representation to values in the
5905 corresponding record.
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.
5916 The definition of SignRotate(N) is:
5918 ======== ============= =========
5919 Argument Value Condition
5920 ======== ============= =========
5922 N abs(N)<<1 + 1 N < 0
5923 ======== ============= =========
5925 .. _link_for_absolute_index_section:
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.
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:
5942 ========== ===================================================================
5943 Bitcode ID AbsoluteIndex
5944 ========== ===================================================================
5947 @gN N + NumFcnAddresses
5948 @pN N + NumFcnAddresses + NumGlobalAddresses
5949 @cN N + NumFcnAddresses + NumGlobalAddresses + NumParams
5950 @vN N + NumFcnAddresses + NumGlobalAddresses + NumParams + NumFcnConsts
5951 ========== ===================================================================
5953 .. _link_for_relative_index:
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::
5962 RelativeIndex(J) = AbsoluteIndex(%vN) - AbsoluteIndex(J)
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,
5976 ========= ==============
5978 ========= ==============
5982 ========= ==============
5987 This is the 32-bit log2 value of its argument.
5992 Returns the number of bits needed to represent its argument (a type).
5994 ======= ================
5996 ======= ================
6004 <N X T> N * BitSizeOf(T)
6005 ======= ================
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
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).
6026 Returns true if the argument is in {i1, i8, i16, i32, i64}.
6031 Returns true if the argument is in {``float``, ``double``}.
6036 Returns true if the argument is a vector type.
6041 Returns true if the argument is a primitive type. That is::
6043 IsPrimitive(T) == IsInteger(T) or IsFloat(T)
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::
6051 IsFcnArgType(T) = (IsInteger(T) and (i32 = BitSizeOf(T)
6052 or i64 == BitSizeOf(T)))
6053 or IsFloat(T) or IsVector(T)
6055 .. _link_for_abbreviations_section:
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
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.
6070 .. _link_for_abbreviations_block_section:
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
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).
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>`_.