[−][src]Module cranelift_codegen_meta::gen_encodings
Generate sources for instruction encoding.
The tables and functions generated here support the TargetISA::encode()
function which
determines if a given instruction is legal, and if so, its Encoding
data which consists of a
recipe and some encoding bits.
The encode
function doesn't actually generate the binary machine bits. Each recipe has a
corresponding hand-written function to do that after registers are allocated.
This is the information available to us:
- The instruction to be encoded as an
InstructionData
reference. - The controlling type variable.
- The data-flow graph giving us access to the types of all values involved. This is needed for testing any secondary type variables.
- A
PredicateView
reference for the ISA-specific settings for evaluating ISA predicates. - The currently active CPU mode is determined by the ISA.
Level 1 table lookup
The CPU mode provides the first table. The key is the instruction's controlling type variable.
If the instruction is not polymorphic, use INVALID
for the type variable. The table values
are level 2 tables.
Level 2 table lookup
The level 2 table is keyed by the instruction's opcode. The table values are encoding lists.
The two-level table lookup allows the level 2 tables to be much smaller with good locality. Code in any given function usually only uses a few different types, so many of the level 2 tables will be cold.
Encoding lists
An encoding list is a non-empty sequence of list entries. Each entry has one of these forms:
- Recipe + bits. Use this encoding if the recipe predicate is satisfied.
- Recipe + bits, final entry. Use this encoding if the recipe predicate is satisfied. Otherwise, stop with the default legalization code.
- Stop with legalization code.
- Predicate + skip count. Test predicate and skip N entries if it is false.
- Predicate + stop. Test predicate and stop with the default legalization code if it is false.
The instruction predicate is also used to distinguish between polymorphic instructions with different types for secondary type variables.
Structs
Encoder | Encoder for the list format above. |
EncodingList | List of instructions for encoding a given type + opcode pair. |
Level1Table | Level 1 table mapping types to |
Level2HashTableEntry | |
Level2Table | Level 2 table mapping instruction opcodes to |
Constants
CODE_BITS | The u16 values in an encoding list entry are interpreted as follows: |
PRED_BITS | Number of bits used to hold a predicate number (instruction + ISA predicates). |
PRED_MASK | Mask for extracting the predicate number. |
PRED_START | Beginning of the predicate code words. |
Functions
emit_encoding_tables | |
emit_inst_predicates | Emit private functions for matching instruction predicates as well as a static
|
emit_instp | Emit code for matching an instruction predicate against an |
emit_operand_constraints | Emit a struct field initializer for an array of operand constraints. |
emit_recipe_constraints | Emit a table of encoding recipe operand constraints keyed by recipe number. |
emit_recipe_names | Emit a table of encoding recipe names keyed by recipe number. |
emit_recipe_predicates | Emit private functions for checking recipe predicates as well as a static |
emit_recipe_sizing | Emit a table of encoding recipe code size information. |
encode_enclists | Compute encodings and doc comments for encoding lists in |
encode_level2_hashtables | |
gen_isa | |
generate | |
get_fixed_registers | Returns a set of all the registers involved in fixed register constraints. |
make_tables |