Struct cranelift_codegen::Context [−][src]
pub struct Context {
pub func: Function,
pub cfg: ControlFlowGraph,
pub domtree: DominatorTree,
pub loop_analysis: LoopAnalysis,
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
.
loop_analysis: LoopAnalysis
Loop analysis of func
.
mach_compile_result: Option<MachCompileResult>
Result of MachBackend compilation, if computed.
want_disasm: bool
Flag: do we want a disassembly with the MachCompileResult?
Implementations
Allocate a new compilation context.
The returned instance should be reused for compiling multiple functions in order to avoid needless allocator thrashing.
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.
Set the flag to request a disassembly when compiling with a
MachBackend
backend.
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<()>
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<()>
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.
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.
pub unsafe fn emit_to_memory(
&self,
mem: *mut u8,
relocs: &mut dyn RelocSink,
traps: &mut dyn TrapSink,
stack_maps: &mut dyn StackMapSink
) -> CodeInfo
pub unsafe fn emit_to_memory(
&self,
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.
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.
Creates unwind information for the function.
Returns None
if the function has no unwind information.
Run the verifier on the function.
Also check that the dominator tree and control flow graph are consistent with the function.
Run the verifier only if the enable_verifier
setting is true.
Perform dead-code elimination on the function.
pub 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.
Perform pre-legalization rewrites on the function.
Perform NaN canonicalizing rewrites on the function.
Run the legalizer for isa
on the function.
Compute the control flow graph.
Compute dominator tree.
Compute the loop analysis.
Perform simple GVN on the function.
Perform LICM on the function.
pub 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.