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
impl Context
Sourcepub fn new() -> Self
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.
Sourcepub fn for_function(func: Function) -> Self
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.
Sourcepub fn compiled_code(&self) -> Option<&CompiledCode>
pub fn compiled_code(&self) -> Option<&CompiledCode>
Returns the compilation result for this function, available after any compile
function
has been called.
Sourcepub fn take_compiled_code(&mut self) -> Option<CompiledCode>
pub fn take_compiled_code(&mut self) -> Option<CompiledCode>
Returns the compilation result for this function, available after any compile
function
has been called.
Sourcepub fn set_disasm(&mut self, val: bool)
pub fn set_disasm(&mut self, val: bool)
Set the flag to request a disassembly when compiling with a
MachBackend
backend.
Sourcepub fn compile_and_emit(
&mut self,
isa: &dyn TargetIsa,
mem: &mut Vec<u8>,
ctrl_plane: &mut ControlPlane,
) -> Result<&CompiledCode, CompileError<'_>>
👎Deprecated: use Context::compile
pub fn compile_and_emit( &mut self, isa: &dyn TargetIsa, mem: &mut Vec<u8>, ctrl_plane: &mut ControlPlane, ) -> Result<&CompiledCode, CompileError<'_>>
Compile the function, and emit machine code into a Vec<u8>
.
Sourcepub fn compile_stencil(
&mut self,
isa: &dyn TargetIsa,
ctrl_plane: &mut ControlPlane,
) -> CodegenResult<CompiledCodeBase<Stencil>>
pub fn compile_stencil( &mut self, isa: &dyn TargetIsa, ctrl_plane: &mut ControlPlane, ) -> CodegenResult<CompiledCodeBase<Stencil>>
Internally compiles the function into a stencil.
Public only for testing and fuzzing purposes.
Sourcepub fn optimize(
&mut self,
isa: &dyn TargetIsa,
ctrl_plane: &mut ControlPlane,
) -> CodegenResult<()>
pub fn optimize( &mut self, isa: &dyn TargetIsa, ctrl_plane: &mut ControlPlane, ) -> CodegenResult<()>
Optimize the function, performing all compilation steps up to but not including machine-code lowering and register allocation.
Public only for testing purposes.
Sourcepub fn compile(
&mut self,
isa: &dyn TargetIsa,
ctrl_plane: &mut ControlPlane,
) -> Result<&CompiledCode, CompileError<'_>>
pub fn compile( &mut self, isa: &dyn TargetIsa, ctrl_plane: &mut ControlPlane, ) -> Result<&CompiledCode, CompileError<'_>>
Compile the function,
Run the function through all the passes necessary to generate
code for the target ISA represented by isa
. The generated
machine code is not relocated. Instead, any relocations can be
obtained from compiled_code.buffer.relocs()
.
Performs any optimizations that are enabled, unless
optimize()
was already invoked.
Returns the generated machine code as well as information about the function’s code and read-only data.
Sourcepub fn get_code_bb_layout(&self) -> Option<(Vec<usize>, Vec<(usize, usize)>)>
👎Deprecated: use CompiledCode::get_code_bb_layout
pub fn get_code_bb_layout(&self) -> Option<(Vec<usize>, Vec<(usize, usize)>)>
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.
Sourcepub fn create_unwind_info(
&self,
isa: &dyn TargetIsa,
) -> CodegenResult<Option<UnwindInfo>>
👎Deprecated: use CompiledCode::create_unwind_infoAvailable on crate feature unwind
only.
pub fn create_unwind_info( &self, isa: &dyn TargetIsa, ) -> CodegenResult<Option<UnwindInfo>>
unwind
only.Creates unwind information for the function.
Returns None
if the function has no unwind information.
Sourcepub fn verify<'a, FOI: Into<FlagsOrIsa<'a>>>(
&self,
fisa: FOI,
) -> VerifierResult<()>
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.
TODO: rename to “CLIF validate” or similar.
Sourcepub fn verify_if<'a, FOI: Into<FlagsOrIsa<'a>>>(
&self,
fisa: FOI,
) -> CodegenResult<()>
pub fn verify_if<'a, FOI: Into<FlagsOrIsa<'a>>>( &self, fisa: FOI, ) -> CodegenResult<()>
Run the verifier only if the enable_verifier
setting is true.
Sourcepub fn remove_constant_phis<'a, FOI: Into<FlagsOrIsa<'a>>>(
&mut self,
fisa: FOI,
) -> CodegenResult<()>
pub fn remove_constant_phis<'a, FOI: Into<FlagsOrIsa<'a>>>( &mut self, fisa: FOI, ) -> CodegenResult<()>
Perform constant-phi removal on the function.
Sourcepub fn canonicalize_nans(&mut self, isa: &dyn TargetIsa) -> CodegenResult<()>
pub fn canonicalize_nans(&mut self, isa: &dyn TargetIsa) -> CodegenResult<()>
Perform NaN canonicalizing rewrites on the function.
Sourcepub fn legalize(&mut self, isa: &dyn TargetIsa) -> CodegenResult<()>
pub fn legalize(&mut self, isa: &dyn TargetIsa) -> CodegenResult<()>
Run the legalizer for isa
on the function.
Sourcepub fn compute_cfg(&mut self)
pub fn compute_cfg(&mut self)
Compute the control flow graph.
Sourcepub fn compute_domtree(&mut self)
pub fn compute_domtree(&mut self)
Compute dominator tree.
Sourcepub fn compute_loop_analysis(&mut self)
pub fn compute_loop_analysis(&mut self)
Compute the loop analysis.
Sourcepub fn eliminate_unreachable_code<'a, FOI>(
&mut self,
fisa: FOI,
) -> CodegenResult<()>where
FOI: Into<FlagsOrIsa<'a>>,
pub fn eliminate_unreachable_code<'a, FOI>(
&mut self,
fisa: FOI,
) -> CodegenResult<()>where
FOI: Into<FlagsOrIsa<'a>>,
Perform unreachable code elimination.
Sourcepub fn replace_redundant_loads(&mut self) -> CodegenResult<()>
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”).
Sourcepub fn souper_harvest(&mut self, out: &mut Sender<String>) -> CodegenResult<()>
Available on crate feature souper-harvest
only.
pub fn souper_harvest(&mut self, out: &mut Sender<String>) -> CodegenResult<()>
souper-harvest
only.Harvest candidate left-hand sides for superoptimization with Souper.
Sourcepub fn egraph_pass<'a, FOI>(
&mut self,
fisa: FOI,
ctrl_plane: &mut ControlPlane,
) -> CodegenResult<()>where
FOI: Into<FlagsOrIsa<'a>>,
pub fn egraph_pass<'a, FOI>(
&mut self,
fisa: FOI,
ctrl_plane: &mut ControlPlane,
) -> CodegenResult<()>where
FOI: Into<FlagsOrIsa<'a>>,
Run optimizations via the egraph infrastructure.
Source§impl Context
impl Context
Sourcepub fn compile_with_cache(
&mut self,
isa: &dyn TargetIsa,
cache_store: &mut dyn CacheKvStore,
ctrl_plane: &mut ControlPlane,
) -> Result<(&CompiledCode, bool), CompileError<'_>>
Available on crate feature incremental-cache
only.
pub fn compile_with_cache( &mut self, isa: &dyn TargetIsa, cache_store: &mut dyn CacheKvStore, ctrl_plane: &mut ControlPlane, ) -> Result<(&CompiledCode, bool), CompileError<'_>>
incremental-cache
only.Compile the function, as in compile
, but tries to reuse compiled artifacts from former
compilations using the provided cache store.