Skip to main content

EvmLlvmBackend

Struct EvmLlvmBackend 

Source
pub struct EvmLlvmBackend {
Show 23 fields pub(crate) cx: &'static Context, pub(crate) _dh: DiagnosticHandlerGuard, pub(crate) bcx: Builder<'static>, pub(crate) module: Module<'static>, pub(crate) machine: TargetMachine, pub(crate) orc: Option<OrcJitState>, pub(crate) _tscx: Option<ThreadSafeContext>, pub(crate) _cx_handle: Option<Box<ManuallyDrop<Context>>>, pub(crate) _aot_cx: Option<Box<Context>>, pub(crate) di_state: Option<DiState>, pub(crate) ty_void: VoidType<'static>, pub(crate) ty_ptr: PointerType<'static>, pub(crate) ty_i1: IntType<'static>, pub(crate) ty_i8: IntType<'static>, pub(crate) ty_i32: IntType<'static>, pub(crate) ty_i64: IntType<'static>, pub(crate) ty_i256: IntType<'static>, pub(crate) ty_isize: IntType<'static>, pub(crate) aot: bool, pub(crate) backend_config: BackendConfig, pub(crate) scratch: String, pub(crate) function_counter: u32, pub(crate) function_names: HashMap<u32, String, FxBuildHasher>,
}
Expand description

The LLVM-based EVM bytecode compiler backend.

Fields§

§cx: &'static Context§_dh: DiagnosticHandlerGuard§bcx: Builder<'static>§module: Module<'static>§machine: TargetMachine§orc: Option<OrcJitState>

ORC JIT state. None in AOT mode. Dropped before _tscx so the JIT engine is disposed before the context.

§_tscx: Option<ThreadSafeContext>

ORC thread-safe context that owns the LLVM context (JIT mode only).

§_cx_handle: Option<Box<ManuallyDrop<Context>>>

Non-owning context handle for JIT mode. See create_orc_context.

§_aot_cx: Option<Box<Context>>

Owned context for AOT mode. None in JIT mode.

§di_state: Option<DiState>

LLVM debug info builder and compile unit, created lazily when debug_file is set.

§ty_void: VoidType<'static>§ty_ptr: PointerType<'static>§ty_i1: IntType<'static>§ty_i8: IntType<'static>§ty_i32: IntType<'static>§ty_i64: IntType<'static>§ty_i256: IntType<'static>§ty_isize: IntType<'static>§aot: bool§backend_config: BackendConfig§scratch: String§function_counter: u32

Separate from function_names to have always increasing IDs.

§function_names: HashMap<u32, String, FxBuildHasher>

Persistent mapping from function ID to symbol name.

Implementations§

Source§

impl EvmLlvmBackend

Source

pub fn new(aot: bool) -> Result<Self>

Creates a new LLVM backend for the host machine.

Source

pub fn cx(&self) -> &Context

Returns the LLVM context.

Source

pub(crate) fn module(&self) -> &Module<'static>

Source

pub(crate) fn ensure_orc(&mut self) -> Result<&mut OrcJitState>

Source

pub(crate) fn fn_type( &self, ret: Option<BasicTypeEnum<'static>>, params: &[BasicTypeEnum<'static>], ) -> FunctionType<'static>

Source

pub(crate) fn name<'a>(&self, name: &'a str) -> &'a str

Returns the given name if IR output is being dumped, otherwise an empty string. LLVM skips internal name processing for empty names, avoiding overhead when names are not needed for readability.

Source

pub(crate) fn id_to_name(&self, id: u32) -> &str

Source

pub(crate) fn ensure_di_state(&mut self)

Lazily initializes the debug info builder and compile unit for the module.

Source

pub(crate) fn commit_staged_module(&mut self) -> Result<()>

Commits the current staging module to the ORC JIT if there are pending functions.

Source

pub(crate) fn reset_jit(&mut self) -> Result<()>

Clears all code from this compiler’s JITDylib, freeing JIT-compiled code. The LLVM context and global LLJIT are reused across resets.

Source

pub fn take_last_resource_tracker(&mut self) -> Option<ResourceTracker>

Pops and returns the ResourceTracker for the last committed JIT module.

Each call to jit_function commits a module with its own tracker. The caller takes ownership and is responsible for calling tracker.remove() to free the machine code when it is no longer needed.

The caller must also hold a JitDylibGuard to prevent the owning JITDylib from being recycled before the tracker is removed.

Returns None in AOT mode or if no modules have been committed.

Source

pub fn jit_dylib_guard(&self) -> Arc<JitDylibGuard>

Returns a shared handle that keeps this backend’s JITDylib alive.

The JITDylib will not be cleared or recycled until all JitDylibGuard handles (and the backend itself) are dropped. Callers holding JIT function pointers must retain a guard to prevent the backing code from being freed.

Trait Implementations§

Source§

impl Backend for EvmLlvmBackend

Source§

type Builder<'a> = EvmLlvmBuilder<'a> where Self: 'a

Source§

type FuncId = u32

Source§

fn ir_extension(&self) -> &'static str

Source§

fn set_module_name(&mut self, name: &str)

Source§

fn config(&self) -> &BackendConfig

Returns the current backend configuration.
Source§

fn apply_config(&mut self, config: BackendConfig)

Applies the given configuration snapshot. Read more
Source§

fn finalize_debug_info(&mut self) -> Result<()>

Finalizes any pending debug info metadata. Read more
Source§

fn is_aot(&self) -> bool

Source§

fn function_name_is_unique(&self, name: &str) -> bool

Source§

fn dump_ir(&mut self, path: &Path) -> Result<()>

Source§

fn dump_disasm(&mut self, path: &Path) -> Result<()>

Source§

fn build_function( &mut self, name: &str, ret: Option<Self::Type>, params: &[Self::Type], param_names: &[&str], linkage: Linkage, ) -> Result<(Self::Builder<'_>, Self::FuncId)>

Source§

fn verify_module(&mut self) -> Result<()>

Source§

fn optimize_module(&mut self) -> Result<()>

Source§

fn write_object<W: Write>(&mut self, w: W) -> Result<()>

Source§

fn jit_function(&mut self, id: Self::FuncId) -> Result<usize>

Source§

fn function_name(&self, id: Self::FuncId) -> Option<&str>

Returns the name of a compiled function by its ID.
Source§

fn function_sizes(&self) -> Vec<(String, usize)>

Returns the estimated sizes of compiled functions as (name, size) pairs.
Source§

fn clear_ir(&mut self) -> Result<()>

Clears the IR module, freeing memory used by IR representations. Read more
Source§

unsafe fn free_function(&mut self, id: Self::FuncId) -> Result<()>

Source§

unsafe fn free_all_functions(&mut self) -> Result<()>

Source§

impl BackendTypes for EvmLlvmBackend

Source§

type Type = BasicTypeEnum<'static>

Source§

type Value = BasicValueEnum<'static>

Source§

type StackSlot = PointerValue<'static>

Source§

type BasicBlock = BasicBlock<'static>

Source§

type Function = FunctionValue<'static>

Source§

impl Debug for EvmLlvmBackend

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl TypeMethods for EvmLlvmBackend

Source§

fn type_ptr(&self) -> Self::Type

Source§

fn type_ptr_sized_int(&self) -> Self::Type

Source§

fn type_int(&self, bits: u32) -> Self::Type

Source§

fn type_array(&self, ty: Self::Type, size: u32) -> Self::Type

Source§

fn type_bit_width(&self, ty: Self::Type) -> u32

Source§

impl Send for EvmLlvmBackend

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where 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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 512 bytes