Struct cranelift_codegen::Context
source · [−]pub struct Context {
pub func: Function,
pub cfg: ControlFlowGraph,
pub domtree: DominatorTree,
pub regalloc: Context,
pub loop_analysis: LoopAnalysis,
pub redundant_reload_remover: RedundantReloadRemover,
pub mach_compile_result: Option<MachCompileResult>,
pub want_disasm: bool,
}
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
.
regalloc: Context
Register allocation context.
loop_analysis: LoopAnalysis
Loop analysis of func
.
redundant_reload_remover: RedundantReloadRemover
Redundant-reload remover context.
mach_compile_result: Option<MachCompileResult>
Result of MachBackend compilation, if computed.
want_disasm: bool
Flag: do we want a disassembly with the MachCompileResult?
Implementations
sourceimpl 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 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>,
relocs: &mut dyn RelocSink,
traps: &mut dyn TrapSink,
stack_maps: &mut dyn StackMapSink
) -> CodegenResult<CodeInfo>
pub fn compile_and_emit(
&mut self,
isa: &dyn TargetIsa,
mem: &mut Vec<u8>,
relocs: &mut dyn RelocSink,
traps: &mut dyn TrapSink,
stack_maps: &mut dyn StackMapSink
) -> CodegenResult<CodeInfo>
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 are emitted
into relocs
.
This function calls compile
and emit_to_memory
, taking care to resize mem
as
needed, so it provides a safe interface.
Returns information about the function’s code and read-only data.
sourcepub fn compile(&mut self, isa: &dyn TargetIsa) -> CodegenResult<CodeInfo>
pub fn compile(&mut self, isa: &dyn TargetIsa) -> CodegenResult<CodeInfo>
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.
sourcepub unsafe fn emit_to_memory(
&self,
isa: &dyn TargetIsa,
mem: *mut u8,
relocs: &mut dyn RelocSink,
traps: &mut dyn TrapSink,
stack_maps: &mut dyn StackMapSink
) -> CodeInfo
pub unsafe fn emit_to_memory(
&self,
isa: &dyn TargetIsa,
mem: *mut u8,
relocs: &mut dyn RelocSink,
traps: &mut dyn TrapSink,
stack_maps: &mut dyn StackMapSink
) -> CodeInfo
Emit machine code directly into raw memory.
Write all of the function’s machine code to the memory at mem
. The size of the machine
code is returned by compile
above.
The machine code is not relocated. Instead, any relocations are emitted into relocs
.
Safety
This function is unsafe since it does not perform bounds checking on the memory buffer,
and it can’t guarantee that the mem
pointer is valid.
Returns information about the emitted code and data.
sourcepub fn create_unwind_info(
&self,
isa: &dyn TargetIsa
) -> CodegenResult<Option<UnwindInfo>>
pub fn create_unwind_info(
&self,
isa: &dyn TargetIsa
) -> CodegenResult<Option<UnwindInfo>>
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.
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 verify_locations(&self, isa: &dyn TargetIsa) -> VerifierResult<()>
pub fn verify_locations(&self, isa: &dyn TargetIsa) -> VerifierResult<()>
Run the locations verifier on the function.
sourcepub fn verify_locations_if(&self, isa: &dyn TargetIsa) -> CodegenResult<()>
pub fn verify_locations_if(&self, isa: &dyn TargetIsa) -> CodegenResult<()>
Run the locations verifier only if the enable_verifier
setting is true.
sourcepub fn dce<'a, FOI: Into<FlagsOrIsa<'a>>>(
&mut self,
fisa: FOI
) -> CodegenResult<()>
pub fn dce<'a, FOI: Into<FlagsOrIsa<'a>>>(
&mut self,
fisa: FOI
) -> CodegenResult<()>
Perform dead-code elimination on the function.
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 preopt(&mut self, isa: &dyn TargetIsa) -> CodegenResult<()>
pub fn preopt(&mut self, isa: &dyn TargetIsa) -> CodegenResult<()>
Perform pre-legalization rewrites 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 postopt(&mut self, isa: &dyn TargetIsa) -> CodegenResult<()>
pub fn postopt(&mut self, isa: &dyn TargetIsa) -> CodegenResult<()>
Perform post-legalization rewrites 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 simple_gvn<'a, FOI: Into<FlagsOrIsa<'a>>>(
&mut self,
fisa: FOI
) -> CodegenResult<()>
pub fn simple_gvn<'a, FOI: Into<FlagsOrIsa<'a>>>(
&mut self,
fisa: FOI
) -> CodegenResult<()>
Perform simple GVN on the function.
sourcepub fn licm(&mut self, isa: &dyn TargetIsa) -> CodegenResult<()>
pub fn licm(&mut self, isa: &dyn TargetIsa) -> CodegenResult<()>
Perform LICM on the function.
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 regalloc(&mut self, isa: &dyn TargetIsa) -> CodegenResult<()>
pub fn regalloc(&mut self, isa: &dyn TargetIsa) -> CodegenResult<()>
Run the register allocator.
sourcepub fn prologue_epilogue(&mut self, isa: &dyn TargetIsa) -> CodegenResult<()>
pub fn prologue_epilogue(&mut self, isa: &dyn TargetIsa) -> CodegenResult<()>
Insert prologue and epilogues after computing the stack frame layout.
sourcepub fn redundant_reload_remover(
&mut self,
isa: &dyn TargetIsa
) -> CodegenResult<()>
pub fn redundant_reload_remover(
&mut self,
isa: &dyn TargetIsa
) -> CodegenResult<()>
Do redundant-reload removal after allocation of both registers and stack slots.
sourcepub fn shrink_instructions(&mut self, isa: &dyn TargetIsa) -> CodegenResult<()>
pub fn shrink_instructions(&mut self, isa: &dyn TargetIsa) -> CodegenResult<()>
Run the instruction shrinking pass.
sourcepub fn relax_branches(&mut self, isa: &dyn TargetIsa) -> CodegenResult<CodeInfo>
pub fn relax_branches(&mut self, isa: &dyn TargetIsa) -> CodegenResult<CodeInfo>
Run the branch relaxation pass and return information about the function’s code and read-only data.
sourcepub fn build_value_labels_ranges(
&self,
isa: &dyn TargetIsa
) -> CodegenResult<ValueLabelsRanges>
pub fn build_value_labels_ranges(
&self,
isa: &dyn TargetIsa
) -> CodegenResult<ValueLabelsRanges>
Builds ranges and location for specified value labels.
Auto Trait Implementations
impl RefUnwindSafe for Context
impl !Send for Context
impl !Sync for Context
impl Unpin for Context
impl UnwindSafe for Context
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more