pub struct DataFlowGraph {
    pub value_lists: ValueListPool,
    pub signatures: PrimaryMap<SigRef, Signature>,
    pub old_signatures: SecondaryMap<SigRef, Option<Signature>>,
    pub ext_funcs: PrimaryMap<FuncRef, ExtFuncData>,
    pub values_labels: Option<HashMap<Value, ValueLabelAssignments>>,
    pub constants: ConstantPool,
    pub immediates: PrimaryMap<Immediate, ConstantData>,
    /* private fields */
}
Expand description

A data flow graph defines all instructions and basic blocks in a function as well as the data flow dependencies between them. The DFG also tracks values which can be either instruction results or block parameters.

The layout of blocks in the function and of instructions in each block is recorded by the Layout data structure which forms the other half of the function representation.

Fields

value_lists: ValueListPool

Memory pool of value lists.

The ValueList references into this pool appear in many places:

  • Instructions in insts that don’t have room for their entire argument list inline.
  • Instruction result values in results.
  • block parameters in blocks.
signatures: PrimaryMap<SigRef, Signature>

Function signature table. These signatures are referenced by indirect call instructions as well as the external function references.

old_signatures: SecondaryMap<SigRef, Option<Signature>>

The pre-legalization signature for each entry in signatures, if any.

ext_funcs: PrimaryMap<FuncRef, ExtFuncData>

External function references. These are functions that can be called directly.

values_labels: Option<HashMap<Value, ValueLabelAssignments>>

Saves Value labels.

constants: ConstantPool

Constants used within the function

immediates: PrimaryMap<Immediate, ConstantData>

Stores large immediates that otherwise will not fit on InstructionData

Implementations

Create a new empty DataFlowGraph.

Clear everything.

Get the total number of instructions created in this function, whether they are currently inserted in the layout or not.

This is intended for use with SecondaryMap::with_capacity.

Returns true if the given instruction reference is valid.

Get the total number of basic blocks created in this function, whether they are currently inserted in the layout or not.

This is intended for use with SecondaryMap::with_capacity.

Returns true if the given block reference is valid.

Get the total number of values.

Starts collection of debug information.

Inserts a ValueLabelAssignments::Alias for to_alias if debug info collection is enabled.

Handling values.

Values are either block parameters or instruction results.

Get an iterator over all values.

Check if a value reference is valid.

Get the type of a value.

Get the definition of a value.

This is either the instruction that defined it or the Block that has the value as an parameter.

Determine if v is an attached instruction result / block parameter.

An attached value can’t be attached to something else without first being detached.

Value aliases are not considered to be attached to anything. Use resolve_aliases() to determine if the original aliased value is attached.

Resolve value aliases.

Find the original SSA value that value aliases.

Resolve all aliases among inst’s arguments.

For each argument of inst which is defined by an alias, replace the alias with the aliased value.

Turn a value into an alias of another.

Change the dest value to behave as an alias of src. This means that all uses of dest will behave as if they used that value src.

The dest value can’t be attached to an instruction or block.

Replace the results of one instruction with aliases to the results of another.

Change all the results of dest_inst to behave as aliases of corresponding results of src_inst, as if calling change_to_alias for each.

After calling this instruction, dest_inst will have had its results cleared, so it likely needs to be removed from the graph.

Instructions.

Create a new instruction.

The type of the first result is indicated by data.ty. If the instruction produces multiple results, also call make_inst_results to allocate value table entries.

Returns an object that displays inst.

Get all value arguments on inst as a slice.

Get all value arguments on inst as a mutable slice.

Get the fixed value arguments on inst as a slice.

Get the fixed value arguments on inst as a mutable slice.

Get the variable value arguments on inst as a slice.

Get the variable value arguments on inst as a mutable slice.

Create result values for an instruction that produces multiple results.

Instructions that produce no result values only need to be created with make_inst, otherwise call make_inst_results to allocate value table entries for the results.

The result value types are determined from the instruction’s value type constraints and the provided ctrl_typevar type for polymorphic instructions. For non-polymorphic instructions, ctrl_typevar is ignored, and INVALID can be used.

The type of the first result value is also set, even if it was already set in the InstructionData passed to make_inst. If this function is called with a single-result instruction, that is the only effect.

Create result values for inst, reusing the provided detached values.

Create a new set of result values for inst using ctrl_typevar to determine the result types. Any values provided by reuse will be reused. When reuse is exhausted or when it produces None, a new value is created.

Create a ReplaceBuilder that will replace inst with a new instruction in place.

Detach the list of result values from inst and return it.

This leaves inst without any result values. New result values can be created by calling make_inst_results or by using a replace(inst) builder.

Clear the list of result values from inst.

This leaves inst without any result values. New result values can be created by calling make_inst_results or by using a replace(inst) builder.

Attach an existing value to the result value list for inst.

The res value is appended to the end of the result list.

This is a very low-level operation. Usually, instruction results with the correct types are created automatically. The res value must not be attached to anything else.

Replace an instruction result with a new value of type new_type.

The old_value must be an attached instruction result.

The old value is left detached, so it should probably be changed into something else.

Returns the new value.

Append a new instruction result value to inst.

Append a new value argument to an instruction.

Panics if the instruction doesn’t support arguments.

Get the first result of an instruction.

This function panics if the instruction doesn’t have any result.

Test if inst has any result values currently.

Return all the results of an instruction.

Return all the results of an instruction as ValueList.

Get the call signature of a direct or indirect call instruction. Returns None if inst is not a call instruction.

Check if inst is a branch.

Compute the type of an instruction result from opcode constraints and call signatures.

This computes the same sequence of result types that make_inst_results() above would assign to the created result values, but it does not depend on make_inst_results() being called first.

Returns None if asked about a result index that is too large.

Get the controlling type variable, or INVALID if inst isn’t polymorphic.

basic blocks.

Create a new basic block.

Get the number of parameters on block.

Get the parameters on block.

Get the types of the parameters on block.

Append a parameter with type ty to block.

Removes val from block’s parameters by swapping it with the last parameter on block. Returns the position of val before removal.

Important: to ensure O(1) deletion, this method swaps the removed parameter with the last block parameter. This can disrupt all the branch instructions jumping to this block for which you have to change the branch argument order if necessary.

Panics if val is not a block parameter.

Removes val from block‘s parameters by a standard linear time list removal which preserves ordering. Also updates the values’ data.

Append an existing value to block’s parameters.

The appended value can’t already be attached to something else.

In almost all cases, you should be using append_block_param() instead of this method.

Replace a block parameter with a new value of type ty.

The old_value must be an attached block parameter. It is removed from its place in the list of parameters and replaced by a new value of type new_type. The new value gets the same position in the list, and other parameters are not disturbed.

The old value is left detached, so it should probably be changed into something else.

Returns the new value.

Detach all the parameters from block and return them as a ValueList.

This is a quite low-level operation. Sensible things to do with the detached block parameters is to put them back on the same block with attach_block_param() or change them into aliases with change_to_alias().

Parser routines. These routines should not be used outside the parser.

Create result values for inst, reusing the provided detached values. This is similar to make_inst_results_reusing except it’s only for use in the parser, which needs to reuse previously invalid values.

Similar to append_block_param, append a parameter with type ty to block, but using value val. This is only for use by the parser to create parameters with specific values.

Create a new value alias. This is only for use by the parser to create aliases with specific values, and the printer for testing.

If v is already defined as an alias, return its destination value. Otherwise return None. This allows the parser to coalesce identical alias definitions, and the printer to identify an alias’s immediate target.

Compute the type of an alias. This is only for use in the parser. Returns false if an alias cycle was encountered.

Create an invalid value, to pad the index space. This is only for use by the parser to pad out the value index space.

Check if a value reference is valid, while being aware of aliases which may be unresolved while parsing.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Allow immutable access to instructions via indexing.

The returned type after indexing.

Performs the indexing (container[index]) operation. Read more

Allow mutable access to instructions via indexing.

Performs the mutable indexing (container[index]) operation. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.