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: FunctionThe function we’re compiling.
cfg: ControlFlowGraphThe control flow graph of func.
domtree: DominatorTreeDominator tree for func.
loop_analysis: LoopAnalysisLoop analysis of func.
want_disasm: boolFlag: do we want a disassembly with the CompiledCode?
Implementations§
Source§impl Context
impl Context
Sourcepub fn new() -> Context
pub fn new() -> Context
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) -> Context
pub fn for_function(func: Function) -> Context
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<&CompiledCodeBase<Final>>
pub fn compiled_code(&self) -> Option<&CompiledCodeBase<Final>>
Returns the compilation result for this function, available after any compile function
has been called.
Sourcepub fn take_compiled_code(&mut self) -> Option<CompiledCodeBase<Final>>
pub fn take_compiled_code(&mut self) -> Option<CompiledCodeBase<Final>>
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<&CompiledCodeBase<Final>, CompileError<'_>>
👎Deprecated: use Context::compile
pub fn compile_and_emit( &mut self, isa: &dyn TargetIsa, mem: &mut Vec<u8>, ctrl_plane: &mut ControlPlane, ) -> Result<&CompiledCodeBase<Final>, 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,
) -> Result<CompiledCodeBase<Stencil>, CodegenError>
pub fn compile_stencil( &mut self, isa: &dyn TargetIsa, ctrl_plane: &mut ControlPlane, ) -> Result<CompiledCodeBase<Stencil>, CodegenError>
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,
) -> Result<(), CodegenError>
pub fn optimize( &mut self, isa: &dyn TargetIsa, ctrl_plane: &mut ControlPlane, ) -> Result<(), CodegenError>
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 inline(&mut self, inliner: impl Inline) -> Result<bool, CodegenError>
pub fn inline(&mut self, inliner: impl Inline) -> Result<bool, CodegenError>
Perform function call inlining.
Returns true if any function call was inlined, false otherwise.
Sourcepub fn compile(
&mut self,
isa: &dyn TargetIsa,
ctrl_plane: &mut ControlPlane,
) -> Result<&CompiledCodeBase<Final>, CompileError<'_>>
pub fn compile( &mut self, isa: &dyn TargetIsa, ctrl_plane: &mut ControlPlane, ) -> Result<&CompiledCodeBase<Final>, 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,
) -> Result<Option<UnwindInfo>, CodegenError>
👎Deprecated: use CompiledCode::create_unwind_info
pub fn create_unwind_info( &self, isa: &dyn TargetIsa, ) -> Result<Option<UnwindInfo>, CodegenError>
Creates unwind information for the function.
Returns None if the function has no unwind information.
Sourcepub fn verify<'a, FOI>(&self, fisa: FOI) -> Result<(), VerifierErrors>where
FOI: Into<FlagsOrIsa<'a>>,
pub fn verify<'a, FOI>(&self, fisa: FOI) -> Result<(), VerifierErrors>where
FOI: Into<FlagsOrIsa<'a>>,
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>(&self, fisa: FOI) -> Result<(), CodegenError>where
FOI: Into<FlagsOrIsa<'a>>,
pub fn verify_if<'a, FOI>(&self, fisa: FOI) -> Result<(), CodegenError>where
FOI: Into<FlagsOrIsa<'a>>,
Run the verifier only if the enable_verifier setting is true.
Sourcepub fn remove_constant_phis<'a, FOI>(
&mut self,
fisa: FOI,
) -> Result<(), CodegenError>where
FOI: Into<FlagsOrIsa<'a>>,
pub fn remove_constant_phis<'a, FOI>(
&mut self,
fisa: FOI,
) -> Result<(), CodegenError>where
FOI: Into<FlagsOrIsa<'a>>,
Perform constant-phi removal on the function.
Sourcepub fn canonicalize_nans(
&mut self,
isa: &dyn TargetIsa,
) -> Result<(), CodegenError>
pub fn canonicalize_nans( &mut self, isa: &dyn TargetIsa, ) -> Result<(), CodegenError>
Perform NaN canonicalizing rewrites on the function.
Sourcepub fn legalize(&mut self, isa: &dyn TargetIsa) -> Result<(), CodegenError>
pub fn legalize(&mut self, isa: &dyn TargetIsa) -> Result<(), CodegenError>
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,
) -> Result<(), CodegenError>where
FOI: Into<FlagsOrIsa<'a>>,
pub fn eliminate_unreachable_code<'a, FOI>(
&mut self,
fisa: FOI,
) -> Result<(), CodegenError>where
FOI: Into<FlagsOrIsa<'a>>,
Perform unreachable code elimination.
Sourcepub fn replace_redundant_loads(&mut self) -> Result<(), CodegenError>
pub fn replace_redundant_loads(&mut self) -> Result<(), CodegenError>
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 egraph_pass<'a, FOI>(
&mut self,
fisa: FOI,
ctrl_plane: &mut ControlPlane,
) -> Result<(), CodegenError>where
FOI: Into<FlagsOrIsa<'a>>,
pub fn egraph_pass<'a, FOI>(
&mut self,
fisa: FOI,
ctrl_plane: &mut ControlPlane,
) -> Result<(), CodegenError>where
FOI: Into<FlagsOrIsa<'a>>,
Run optimizations via the egraph infrastructure.
Auto Trait Implementations§
impl Freeze for Context
impl RefUnwindSafe for Context
impl Send for Context
impl Sync for Context
impl Unpin for Context
impl UnwindSafe for Context
Blanket Implementations§
Source§impl<T> AlignerFor<1> for T
impl<T> AlignerFor<1> for T
Source§impl<T> AlignerFor<1024> for T
impl<T> AlignerFor<1024> for T
Source§type Aligner = AlignTo1024<T>
type Aligner = AlignTo1024<T>
AlignTo* type which aligns Self to ALIGNMENT.Source§impl<T> AlignerFor<128> for T
impl<T> AlignerFor<128> for T
Source§type Aligner = AlignTo128<T>
type Aligner = AlignTo128<T>
AlignTo* type which aligns Self to ALIGNMENT.Source§impl<T> AlignerFor<16> for T
impl<T> AlignerFor<16> for T
Source§impl<T> AlignerFor<16384> for T
impl<T> AlignerFor<16384> for T
Source§type Aligner = AlignTo16384<T>
type Aligner = AlignTo16384<T>
AlignTo* type which aligns Self to ALIGNMENT.Source§impl<T> AlignerFor<2> for T
impl<T> AlignerFor<2> for T
Source§impl<T> AlignerFor<2048> for T
impl<T> AlignerFor<2048> for T
Source§type Aligner = AlignTo2048<T>
type Aligner = AlignTo2048<T>
AlignTo* type which aligns Self to ALIGNMENT.Source§impl<T> AlignerFor<256> for T
impl<T> AlignerFor<256> for T
Source§type Aligner = AlignTo256<T>
type Aligner = AlignTo256<T>
AlignTo* type which aligns Self to ALIGNMENT.Source§impl<T> AlignerFor<32> for T
impl<T> AlignerFor<32> for T
Source§impl<T> AlignerFor<32768> for T
impl<T> AlignerFor<32768> for T
Source§type Aligner = AlignTo32768<T>
type Aligner = AlignTo32768<T>
AlignTo* type which aligns Self to ALIGNMENT.Source§impl<T> AlignerFor<4> for T
impl<T> AlignerFor<4> for T
Source§impl<T> AlignerFor<4096> for T
impl<T> AlignerFor<4096> for T
Source§type Aligner = AlignTo4096<T>
type Aligner = AlignTo4096<T>
AlignTo* type which aligns Self to ALIGNMENT.Source§impl<T> AlignerFor<512> for T
impl<T> AlignerFor<512> for T
Source§type Aligner = AlignTo512<T>
type Aligner = AlignTo512<T>
AlignTo* type which aligns Self to ALIGNMENT.Source§impl<T> AlignerFor<64> for T
impl<T> AlignerFor<64> for T
Source§impl<T> AlignerFor<8> for T
impl<T> AlignerFor<8> for T
Source§impl<T> AlignerFor<8192> for T
impl<T> AlignerFor<8192> for T
Source§type Aligner = AlignTo8192<T>
type Aligner = AlignTo8192<T>
AlignTo* type which aligns Self to ALIGNMENT.Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<S> ROExtAcc for S
impl<S> ROExtAcc for S
Source§fn f_get<F>(&self, offset: FieldOffset<S, F, Aligned>) -> &F
fn f_get<F>(&self, offset: FieldOffset<S, F, Aligned>) -> &F
offset. Read moreSource§fn f_get_mut<F>(&mut self, offset: FieldOffset<S, F, Aligned>) -> &mut F
fn f_get_mut<F>(&mut self, offset: FieldOffset<S, F, Aligned>) -> &mut F
offset. Read moreSource§fn f_get_ptr<F, A>(&self, offset: FieldOffset<S, F, A>) -> *const F
fn f_get_ptr<F, A>(&self, offset: FieldOffset<S, F, A>) -> *const F
offset. Read moreSource§fn f_get_mut_ptr<F, A>(&mut self, offset: FieldOffset<S, F, A>) -> *mut F
fn f_get_mut_ptr<F, A>(&mut self, offset: FieldOffset<S, F, A>) -> *mut F
offset. Read moreSource§impl<S> ROExtOps<Aligned> for S
impl<S> ROExtOps<Aligned> for S
Source§fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Aligned>, value: F) -> F
fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Aligned>, value: F) -> F
offset) with value,
returning the previous value of the field. Read moreSource§fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Aligned>) -> Fwhere
F: Copy,
fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Aligned>) -> Fwhere
F: Copy,
Source§impl<S> ROExtOps<Unaligned> for S
impl<S> ROExtOps<Unaligned> for S
Source§fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Unaligned>, value: F) -> F
fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Unaligned>, value: F) -> F
offset) with value,
returning the previous value of the field. Read moreSource§fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Unaligned>) -> Fwhere
F: Copy,
fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Unaligned>) -> Fwhere
F: Copy,
Source§impl<T> SelfOps for Twhere
T: ?Sized,
impl<T> SelfOps for Twhere
T: ?Sized,
Source§fn piped<F, U>(self, f: F) -> U
fn piped<F, U>(self, f: F) -> U
Source§fn piped_ref<'a, F, U>(&'a self, f: F) -> Uwhere
F: FnOnce(&'a Self) -> U,
fn piped_ref<'a, F, U>(&'a self, f: F) -> Uwhere
F: FnOnce(&'a Self) -> U,
piped except that the function takes &Self
Useful for functions that take &Self instead of Self. Read moreSource§fn piped_mut<'a, F, U>(&'a mut self, f: F) -> Uwhere
F: FnOnce(&'a mut Self) -> U,
fn piped_mut<'a, F, U>(&'a mut self, f: F) -> Uwhere
F: FnOnce(&'a mut Self) -> U,
piped, except that the function takes &mut Self.
Useful for functions that take &mut Self instead of Self.Source§fn mutated<F>(self, f: F) -> Self
fn mutated<F>(self, f: F) -> Self
Source§fn observe<F>(self, f: F) -> Self
fn observe<F>(self, f: F) -> Self
Source§fn as_ref_<T>(&self) -> &T
fn as_ref_<T>(&self) -> &T
AsRef,
using the turbofish .as_ref_::<_>() syntax. Read moreSource§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§unsafe fn to_subset_unchecked(&self) -> SS
unsafe fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.