pub struct Context {
    pub func: Function,
    pub cfg: ControlFlowGraph,
    pub domtree: DominatorTree,
    pub loop_analysis: LoopAnalysis,
    pub want_disasm: bool,
    /* private fields */
}
Expand description

Persistent data structures and compilation pipeline.

Fields§

§func: Function

The function we’re compiling.

§cfg: ControlFlowGraph

The control flow graph of func.

§domtree: DominatorTree

Dominator tree for func.

§loop_analysis: LoopAnalysis

Loop analysis of func.

§want_disasm: bool

Flag: do we want a disassembly with the CompiledCode?

Implementations§

source§

impl Context

source

pub fn new() -> Self

Allocate a new compilation context.

The returned instance should be reused for compiling multiple functions in order to avoid needless allocator thrashing.

source

pub fn for_function(func: Function) -> Self

Allocate a new compilation context with an existing Function.

The returned instance should be reused for compiling multiple functions in order to avoid needless allocator thrashing.

source

pub fn clear(&mut self)

Clear all data structures in this context.

source

pub fn compiled_code(&self) -> Option<&CompiledCode>

Returns the compilation result for this function, available after any compile function has been called.

source

pub fn set_disasm(&mut self, val: bool)

Set the flag to request a disassembly when compiling with a MachBackend backend.

source

pub fn compile_and_emit( &mut self, isa: &dyn TargetIsa, mem: &mut Vec<u8> ) -> Result<&CompiledCode, CompileError<'_>>

Compile the function, and emit machine code into a Vec<u8>.

Run the function through all the passes necessary to generate code for the target ISA represented by isa, as well as the final step of emitting machine code into a Vec<u8>. The machine code is not relocated. Instead, any relocations can be obtained from compiled_code().

Performs any optimizations that are enabled, unless optimize() was already invoked.

This function calls compile, taking care to resize mem as needed.

Returns information about the function’s code and read-only data.

source

pub fn compile_stencil( &mut self, isa: &dyn TargetIsa ) -> CodegenResult<CompiledCodeBase<Stencil>>

Internally compiles the function into a stencil.

Public only for testing and fuzzing purposes.

source

pub fn optimize(&mut self, isa: &dyn TargetIsa) -> CodegenResult<()>

Optimize the function, performing all compilation steps up to but not including machine-code lowering and register allocation.

Public only for testing purposes.

source

pub fn compile( &mut self, isa: &dyn TargetIsa ) -> Result<&CompiledCode, CompileError<'_>>

Compile the function.

Run the function through all the passes necessary to generate code for the target ISA represented by isa. This does not include the final step of emitting machine code into a code sink.

Returns information about the function’s code and read-only data.

source

pub fn get_code_bb_layout(&self) -> Option<(Vec<usize>, Vec<(usize, usize)>)>

👎Deprecated: use CompiledCode::get_code_bb_layout

If available, return information about the code layout in the final machine code: the offsets (in bytes) of each basic-block start, and all basic-block edges.

source

pub fn create_unwind_info( &self, isa: &dyn TargetIsa ) -> CodegenResult<Option<UnwindInfo>>

👎Deprecated: use CompiledCode::create_unwind_info

Creates unwind information for the function.

Returns None if the function has no unwind information.

source

pub fn verify<'a, FOI: Into<FlagsOrIsa<'a>>>( &self, fisa: FOI ) -> VerifierResult<()>

Run the verifier on the function.

Also check that the dominator tree and control flow graph are consistent with the function.

source

pub fn verify_if<'a, FOI: Into<FlagsOrIsa<'a>>>( &self, fisa: FOI ) -> CodegenResult<()>

Run the verifier only if the enable_verifier setting is true.

source

pub fn dce<'a, FOI: Into<FlagsOrIsa<'a>>>( &mut self, fisa: FOI ) -> CodegenResult<()>

Perform dead-code elimination on the function.

source

pub fn remove_constant_phis<'a, FOI: Into<FlagsOrIsa<'a>>>( &mut self, fisa: FOI ) -> CodegenResult<()>

Perform constant-phi removal on the function.

source

pub fn preopt(&mut self, isa: &dyn TargetIsa) -> CodegenResult<()>

Perform pre-legalization rewrites on the function.

source

pub fn canonicalize_nans(&mut self, isa: &dyn TargetIsa) -> CodegenResult<()>

Perform NaN canonicalizing rewrites on the function.

source

pub fn legalize(&mut self, isa: &dyn TargetIsa) -> CodegenResult<()>

Run the legalizer for isa on the function.

source

pub fn compute_cfg(&mut self)

Compute the control flow graph.

source

pub fn compute_domtree(&mut self)

Compute dominator tree.

source

pub fn compute_loop_analysis(&mut self)

Compute the loop analysis.

source

pub fn flowgraph(&mut self)

Compute the control flow graph and dominator tree.

source

pub fn simple_gvn<'a, FOI: Into<FlagsOrIsa<'a>>>( &mut self, fisa: FOI ) -> CodegenResult<()>

Perform simple GVN on the function.

source

pub fn licm(&mut self, isa: &dyn TargetIsa) -> CodegenResult<()>

Perform LICM on the function.

source

pub fn eliminate_unreachable_code<'a, FOI>( &mut self, fisa: FOI ) -> CodegenResult<()>where FOI: Into<FlagsOrIsa<'a>>,

Perform unreachable code elimination.

source

pub fn replace_redundant_loads(&mut self) -> CodegenResult<()>

Replace all redundant loads with the known values in memory. These are loads whose values were already loaded by other loads earlier, as well as loads whose values were stored by a store instruction to the same instruction (so-called “store-to-load forwarding”).

source

pub fn egraph_pass(&mut self) -> CodegenResult<()>

Run optimizations via the egraph infrastructure.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.