Skip to main content

Module isel

Module isel 

Source
Expand description

Instruction selection: one ir-lang 2.0 function to a MIR function on virtual registers.

Blocks and block parameters map one to one (IR.md §15): an IR edge’s arguments become the MIR branch’s arguments, resolved as a parallel copy at emission. Every value of an integer, bool, ptr, or ref type lives in one general-purpose virtual register.

§Value representation

A value of a type narrower than 64 bits occupies the low bits of its register; the bits above its width are unspecified, exactly as the x86-64 32-bit operations leave them. Arithmetic on 8-, 16-, and 32-bit types runs at 32 bits; wherever the upper bits matter (comparisons, division, right shifts, overflow checks, widening conversions, switch values, array indices) the value is extended first by its type’s signedness. bool is the exception: always exactly 0 or 1, so it can be tested, stored, and converted directly; booleans entering from outside (parameters, call results, loads) are normalized.

§Policies

Every OPS integer operation is selected under every policy ir-lang can carry (IR.md §4): wrap computes modulo the width; trap branches to a per-function trap block that calls the runtime trap handler (Options::trap_symbol) with the OPS code; error (only inside a check terminator) branches to the error edge, passing the OPS code as err. Division checks zero, then MIN / -1, before it divides, so the processor never faults. Shifts check or mask their amount.

§What is not selected yet

Floating-point types and operations wait on isa-lang’s SSE forms (ISSUES P11), as do lock-prefixed atomic read-modify-writes other than xchg and cmpxchg; aapcs64 waits on the AArch64 target; 32-bit pointer modules on a 32-bit target. Each is reported as IselError::Unsupported, never miscompiled.

Enums§

IselError
Why a function could not be selected.

Functions§

select
Selects func of a validated module into a MIR function on virtual registers, named after the function and under the calling convention its signature selects. The module is validated first.