Expand description
The SSA IR with block parameters, and its printer, parser and verifier.
Design: spec/08-ir.md. Layer rank 8, see spec/18-package-layout.md.
One IR, target-independent, in SSA form, produced by lowering the typed AST and consumed by the optimizer and the code generator. The MIR is a second, target-dependent representation and lives in its own crate.
Block parameters, not phi nodes. A phi is a pseudo-instruction whose operands are
positionally tied to a predecessor list stored somewhere else, and every IR built that way
collects bugs where the two get out of step during a CFG edit. Block parameters put the
correspondence in the branch, where it belongs: br_if %c, block2(%a, %b), block3(%d).
Removing a predecessor is then a local edit, and there is no such thing as a malformed phi.
§What is here so far
The vocabulary: Type and Float for the type system, Opcode with IntPred and
FloatPred for the instruction set, Flags with MemOrder and RmwOp for what
rides on an instruction, and Attrs for what is true of a whole function rather than of
one instruction in it. Signature for what a function takes and returns, with Abi on
each Param for what a call asks of it beyond its type, which is the one thing about a C
function that reading the C cannot answer. The containers: Func, holding BlockData and
InstData and ValueData in flat tables, with Builder to append to it, and
Module, holding the functions with the Globals and the Aliases and the target
they are all for. The textual form: print(), which writes a module out, and parse(),
which reads it back byte for byte. And verify(), which says whether a module is one the
rest of the compiler may believe.
Every crate in the workspace is published, and publishing implies a promise. This one is
tier 3: its Rust API is explicitly unstable and will change without a major version bump.
Depend on the rucc binary’s behaviour, not on this.
Structs§
- Alias
- A second name for something else.
- AsmInfo
- What inline assembly needs.
- AttrSet
- The attributes that are either set or not.
- Attrs
- Everything true of a whole function.
- Block
Call - A branch target, and the values passed to it.
- Block
Data - One basic block: parameters, then instructions, then exactly one terminator.
- Builder
- A cursor that appends to the end of one block.
- Byte
- Marker for the byte pool, so that a range into it cannot be confused with any other range.
- Call
Info - What a call needs beyond its arguments.
- Counts
- How many of each thing a function holds.
- Data
Layout - The layout facts a printed module carries so it can be compiled without the command line that produced it.
- Flags
- The flags on one instruction.
- Func
- One function.
- Global
- A global variable.
- Imm
- A constant, in the immediate table.
- Inst
Data - One instruction.
- Inst
Layout - Where one instruction sits.
- MemInfo
- What an access does beyond naming an address.
- Meta
Node - A node of the metadata graph, which for now is only what aliasing needs.
- Module
- One translation unit, or after LTO the several that were linked into one.
- Module
Counts - How much is in a module, from
Module::counts. - Param
- One parameter, or one return value: a type and how it travels.
- Parse
Error - Why a module could not be read.
- Printer
- A module being written out.
- Reloc
- The address of a symbol, written into a global’s image by the linker.
- Signature
- What a function takes and returns.
- Switch
Info - What a
switchneeds beyond the value it switches on. - Type
- An IR type.
- Value
Data - One value.
- Value
Ref - The table of references to values, which is what an operand list is a run of.
- Verify
Error - One thing wrong with a module.
Enums§
- Abi
- How one parameter or one return value travels, beyond what its type says.
- Alias
Kind - What an alias resolves to at link time.
- Datum
- One piece of a global’s initial image.
- Def
- What defines a value.
- Extra
- Everything an instruction carries that is not a value operand.
- Extra
Kind - Which of
Extra’s shapes an instruction carries. - Float
- A floating point format, named by its width in bits.
- Float
Pred - The floating point comparisons, ordered and unordered.
- FpContract
- How far a multiply and an addition may be fused into one rounding.
- IntPred
- The ten integer comparisons.
- Kind
- Which of the four kinds a
Typeis. - Linkage
- How a symbol is seen outside the object it is defined in.
- MemOrder
- How strongly an atomic operation is ordered against everything around it.
- Opcode
- One instruction of the IR.
- RmwOp
- Which operation an
atomic_rmwperforms. - Symbol
Ref - What a name in a module refers to.
- TlsModel
- How a thread-local variable is reached.
- Visibility
- What the dynamic linker is allowed to do with a symbol.
Constants§
- FORMAT_
VERSION - The version of the textual form, written in the module header.
- MILESTONE
- The milestone in
spec/17-milestones.mdthat fills this crate in.
Functions§
- parse
- Reads a module from the text the printer writes.
- The whole module, as text.
- print_
func - One function of a module, as text, for a dump of a single function.
- verify
- Checks a whole module.
- verify_
func - Checks one function, and nothing else in the module it is in.
Type Aliases§
- AliasId
- An alias in a module.
- Block
- One basic block, in the function that owns it.
- Block
Call List - A run of branch targets, which is what a terminator’s successors are.
- Byte
Range - A run of literal bytes in a module’s byte pool.
- Data
List - A run of
Datums in a module’s data pool, which is what a global’s initializer is. - FuncId
- A function in a module.
- Global
Id - A global variable in a module.
- ImmList
- A run of immediates, which is what a
switchholds its case values in. - Inst
- One instruction, in the function that owns it.
- Meta
- A metadata node, in the module’s table.
- Sig
- A signature, in the function’s table.
- Value
- One value: the result of an instruction, or a parameter of a block.
- Value
List - A run of value operands.