Crate rustc_mir_transform[−][src]
Modules
This pass adds validation calls (AcquireValid, ReleaseValid) where appropriate. It has to be run really early, before transformations like inlining, because introducing these calls adds UB – so, conceptually, this pass is actually part of MIR building, and only after this pass we think of the program has having the normal MIR semantics.
This module provides a pass to replacing the following statements with
Nop
s
Finds locals which are assigned once to a const and unused except for debuginfo and converts their debuginfo to use the const directly, allowing the local to be removed.
This pass optimizes the following sequence
Propagates constants for early reporting of statically known assertion failures
This pass finds basic blocks that are completely equal, and replaces all uses with just one of them.
Propagates assignment destinations backwards in the CFG to eliminate redundant assignments.
This pass just dumps MIR at a specified point.
This is the implementation of the pass which transforms generators into state machines.
Inlining pass for MIR functions
Performs various peephole optimizations.
Lowers intrinsic calls
This pass lowers calls to core::slice::len to just Len op. It should run before inlining!
This pass removes jumps to basic blocks containing only a return, and replaces them with a return instead.
This pass eliminates casting of arrays into slices when their length
is taken using .len()
method. Handy to preserve information in MIR for const prop
See the docs for RenameReturnPlace
.
This pass removes storage markers if they won’t be emitted during codegen.
This pass replaces a drop of a type that does not need dropping, with a goto
Removes assignments to ZST places.
A pass that duplicates switch-terminated blocks into a new copy for each predecessor, provided the predecessor sets the value being switched over to a constant.
A number of passes which remove various redundancies in the CFG.
A pass that simplifies branches when their condition is known.
The general point of the optimizations provided here is to simplify something like:
A pass that eliminates branches on uninhabited enum variants.
A pass that propagates the unreachable terminator of a block to its predecessors when all of their successors are unreachable. This is achieved through a post-order traversal of the blocks.
Traits
A streamlined trait that you can implement to create a pass; the
pass will be named after the type, and it will consist of a main
loop that goes over each available MIR and applies run_pass
.
Functions
Make MIR ready for const evaluation. This is run on all MIR, not just on consts!
Obtain just the main MIR (no promoteds) and run some cleanups on it. This also runs mir borrowck before doing so in order to ensure that borrowck can be run and doesn’t end up missing the source MIR due to stealing happening.
Compute the MIR that is used during CTFE (and thus has no optimizations run on it)
Same as mir_for_ctfe
, but used to get the MIR of a const generic parameter.
The docs on WithOptConstParam
explain this a bit more, but the TLDR is that
we’d get cycle errors with mir_for_ctfe
, because typeck would need to typeck
the const parameter while type checking the main body, which in turn would try
to type check the main body again.
Finds the full set of DefId
s within the current crate that have
MIR associated with them.
Compute the main MIR body and the list of MIR bodies of the promoteds.
Optimize the MIR and prepare it for codegen.
Fetch all the promoteds of an item and prepare their MIR bodies to be ready for constant evaluation once all substitutions become known.
After this series of passes, no lifetime analysis based on borrowing can be done.