pub struct FunctionCx<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> {
Show 16 fields instance: Instance<'tcx>, mir: &'tcx Body<'tcx>, debug_context: Option<FunctionDebugContext<'tcx, Bx::DIScope, Bx::DILocation>>, llfn: Bx::Function, cx: &'a Bx::CodegenCx, fn_abi: &'tcx FnAbi<'tcx, Ty<'tcx>>, personality_slot: Option<PlaceRef<'tcx, Bx::Value>>, cached_llbbs: IndexVec<BasicBlock, CachedLlbb<Bx::BasicBlock>>, cleanup_kinds: Option<IndexVec<BasicBlock, CleanupKind>>, funclets: IndexVec<BasicBlock, Option<Bx::Funclet>>, landing_pads: IndexVec<BasicBlock, Option<Bx::BasicBlock>>, unreachable_block: Option<Bx::BasicBlock>, terminate_block: Option<(Bx::BasicBlock, UnwindTerminateReason)>, locals: Locals<'tcx, Bx::Value>, per_local_var_debug_info: Option<IndexVec<Local, Vec<PerLocalVarDebugInfo<'tcx, Bx::DIVariable>>>>, caller_location: Option<OperandRef<'tcx, Bx::Value>>,
}
Expand description

Master context for codegenning from MIR.

Fields§

§instance: Instance<'tcx>§mir: &'tcx Body<'tcx>§debug_context: Option<FunctionDebugContext<'tcx, Bx::DIScope, Bx::DILocation>>§llfn: Bx::Function§cx: &'a Bx::CodegenCx§fn_abi: &'tcx FnAbi<'tcx, Ty<'tcx>>§personality_slot: Option<PlaceRef<'tcx, Bx::Value>>

When unwinding is initiated, we have to store this personality value somewhere so that we can load it and re-use it in the resume instruction. The personality is (afaik) some kind of value used for C++ unwinding, which must filter by type: we don’t really care about it very much. Anyway, this value contains an alloca into which the personality is stored and then later loaded when generating the DIVERGE_BLOCK.

§cached_llbbs: IndexVec<BasicBlock, CachedLlbb<Bx::BasicBlock>>

A backend BasicBlock for each MIR BasicBlock, created lazily as-needed (e.g. RPO reaching it or another block branching to it).

§cleanup_kinds: Option<IndexVec<BasicBlock, CleanupKind>>

The funclet status of each basic block

§funclets: IndexVec<BasicBlock, Option<Bx::Funclet>>

When targeting MSVC, this stores the cleanup info for each funclet BB. This is initialized at the same time as the landing_pads entry for the funclets’ head block, i.e. when needed by an unwind / cleanup_ret edge.

§landing_pads: IndexVec<BasicBlock, Option<Bx::BasicBlock>>

This stores the cached landing/cleanup pad block for a given BB.

§unreachable_block: Option<Bx::BasicBlock>

Cached unreachable block

§terminate_block: Option<(Bx::BasicBlock, UnwindTerminateReason)>

Cached terminate upon unwinding block and its reason

§locals: Locals<'tcx, Bx::Value>

The location where each MIR arg/var/tmp/ret is stored. This is usually an PlaceRef representing an alloca, but not always: sometimes we can skip the alloca and just store the value directly using an OperandRef, which makes for tighter LLVM IR. The conditions for using an OperandRef are as follows:

  • the type of the local must be judged “immediate” by is_llvm_immediate
  • the operand must never be referenced indirectly
    • we should not take its address using the & operator
    • nor should it appear in a place path like tmp.a
  • the operand must be defined by an rvalue that can generate immediate values

Avoiding allocs can also be important for certain intrinsics, notably expect.

§per_local_var_debug_info: Option<IndexVec<Local, Vec<PerLocalVarDebugInfo<'tcx, Bx::DIVariable>>>>

All VarDebugInfo from the MIR body, partitioned by Local. This is None if no var#[non_exhaustive]iable debuginfo/names are needed.

§caller_location: Option<OperandRef<'tcx, Bx::Value>>

Caller location propagated if this function has #[track_caller].

Implementations§

source§

impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx>

Codegen implementations for some terminator variants.

source

fn codegen_resume_terminator( &mut self, helper: TerminatorCodegenHelper<'tcx>, bx: &mut Bx )

Generates code for a Resume terminator.

source

fn codegen_switchint_terminator( &mut self, helper: TerminatorCodegenHelper<'tcx>, bx: &mut Bx, discr: &Operand<'tcx>, targets: &SwitchTargets )

source

fn codegen_return_terminator(&mut self, bx: &mut Bx)

source

fn codegen_drop_terminator( &mut self, helper: TerminatorCodegenHelper<'tcx>, bx: &mut Bx, location: Place<'tcx>, target: BasicBlock, unwind: UnwindAction, mergeable_succ: bool ) -> MergingSucc

source

fn codegen_assert_terminator( &mut self, helper: TerminatorCodegenHelper<'tcx>, bx: &mut Bx, terminator: &Terminator<'tcx>, cond: &Operand<'tcx>, expected: bool, msg: &AssertMessage<'tcx>, target: BasicBlock, unwind: UnwindAction, mergeable_succ: bool ) -> MergingSucc

source

fn codegen_terminate_terminator( &mut self, helper: TerminatorCodegenHelper<'tcx>, bx: &mut Bx, terminator: &Terminator<'tcx>, reason: UnwindTerminateReason )

source

fn codegen_panic_intrinsic( &mut self, helper: &TerminatorCodegenHelper<'tcx>, bx: &mut Bx, intrinsic: Option<Symbol>, instance: Option<Instance<'tcx>>, source_info: SourceInfo, target: Option<BasicBlock>, unwind: UnwindAction, mergeable_succ: bool ) -> Option<MergingSucc>

Returns Some if this is indeed a panic intrinsic and codegen is done.

source

fn codegen_call_terminator( &mut self, helper: TerminatorCodegenHelper<'tcx>, bx: &mut Bx, terminator: &Terminator<'tcx>, func: &Operand<'tcx>, args: &[Operand<'tcx>], destination: Place<'tcx>, target: Option<BasicBlock>, unwind: UnwindAction, fn_span: Span, mergeable_succ: bool ) -> MergingSucc

source

fn codegen_asm_terminator( &mut self, helper: TerminatorCodegenHelper<'tcx>, bx: &mut Bx, terminator: &Terminator<'tcx>, template: &[InlineAsmTemplatePiece], operands: &[InlineAsmOperand<'tcx>], options: InlineAsmOptions, line_spans: &[Span], destination: Option<BasicBlock>, unwind: UnwindAction, instance: Instance<'_>, mergeable_succ: bool ) -> MergingSucc

source§

impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx>

source

pub fn codegen_block(&mut self, bb: BasicBlock)

source

fn codegen_terminator( &mut self, bx: &mut Bx, bb: BasicBlock, terminator: &'tcx Terminator<'tcx> ) -> MergingSucc

source

fn codegen_argument( &mut self, bx: &mut Bx, op: OperandRef<'tcx, Bx::Value>, llargs: &mut Vec<Bx::Value>, arg: &ArgAbi<'tcx, Ty<'tcx>> )

source

fn codegen_arguments_untupled( &mut self, bx: &mut Bx, operand: &Operand<'tcx>, llargs: &mut Vec<Bx::Value>, args: &[ArgAbi<'tcx, Ty<'tcx>>] ) -> usize

source

fn get_caller_location( &mut self, bx: &mut Bx, source_info: SourceInfo ) -> OperandRef<'tcx, Bx::Value>

source

fn get_personality_slot(&mut self, bx: &mut Bx) -> PlaceRef<'tcx, Bx::Value>

source

fn landing_pad_for(&mut self, bb: BasicBlock) -> Bx::BasicBlock

Returns the landing/cleanup pad wrapper around the given basic block.

source

fn landing_pad_for_uncached(&mut self, bb: BasicBlock) -> Bx::BasicBlock

source

fn unreachable_block(&mut self) -> Bx::BasicBlock

source

fn terminate_block(&mut self, reason: UnwindTerminateReason) -> Bx::BasicBlock

source

pub fn llbb(&mut self, bb: BasicBlock) -> Bx::BasicBlock

Get the backend BasicBlock for a MIR BasicBlock, either already cached in self.cached_llbbs, or created on demand (and cached).

source

pub fn try_llbb(&mut self, bb: BasicBlock) -> Option<Bx::BasicBlock>

Like llbb, but may fail if the basic block should be skipped.

source

fn make_return_dest( &mut self, bx: &mut Bx, dest: Place<'tcx>, fn_ret: &ArgAbi<'tcx, Ty<'tcx>>, llargs: &mut Vec<Bx::Value>, is_intrinsic: bool ) -> ReturnDest<'tcx, Bx::Value>

source

fn store_return( &mut self, bx: &mut Bx, dest: ReturnDest<'tcx, Bx::Value>, ret_abi: &ArgAbi<'tcx, Ty<'tcx>>, llval: Bx::Value )

source§

impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx>

source

pub fn eval_mir_constant_to_operand( &self, bx: &mut Bx, constant: &ConstOperand<'tcx> ) -> OperandRef<'tcx, Bx::Value>

source

pub fn eval_mir_constant( &self, constant: &ConstOperand<'tcx> ) -> ConstValue<'tcx>

source

pub fn eval_unevaluated_mir_constant_to_valtree( &self, constant: &ConstOperand<'tcx> ) -> Result<Option<ValTree<'tcx>>, ErrorHandled>

This is a convenience helper for simd_shuffle_indices. It has the precondition that the given constant is an Const::Unevaluated and must be convertible to a ValTree. If you want a more general version of this, talk to wg-const-eval on zulip.

Note that this function is cursed, since usually MIR consts should not be evaluated to valtrees!

source

pub fn simd_shuffle_indices( &mut self, bx: &Bx, constant: &ConstOperand<'tcx> ) -> (Bx::Value, Ty<'tcx>)

process constant containing SIMD shuffle indices

source§

impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx>

source

pub fn codegen_coverage( &self, bx: &mut Bx, coverage: &Coverage, scope: SourceScope )

source§

impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx>

source

pub fn set_debug_loc(&self, bx: &mut Bx, source_info: SourceInfo)

source

fn dbg_loc(&self, source_info: SourceInfo) -> Option<Bx::DILocation>

source

fn adjusted_span_and_dbg_scope( &self, source_info: SourceInfo ) -> Option<(Bx::DIScope, Option<Bx::DILocation>, Span)>

source

fn adjust_span_for_debugging(&self, span: Span) -> Span

In order to have a good line stepping behavior in debugger, we overwrite debug locations of macro expansions with that of the outermost expansion site (when the macro is annotated with #[collapse_debuginfo] or when -Zdebug-macros is provided).

source

fn spill_operand_to_stack( operand: OperandRef<'tcx, Bx::Value>, name: Option<String>, bx: &mut Bx ) -> PlaceRef<'tcx, Bx::Value>

source

pub fn debug_introduce_local(&self, bx: &mut Bx, local: Local)

Apply debuginfo and/or name, after creating the alloca for a local, or initializing the local with an operand (whichever applies).

source

fn debug_introduce_local_as_var( &self, bx: &mut Bx, local: Local, base: PlaceRef<'tcx, Bx::Value>, var: PerLocalVarDebugInfo<'tcx, Bx::DIVariable> )

source

pub fn debug_introduce_locals(&self, bx: &mut Bx)

source

pub fn compute_per_local_var_debug_info( &self, bx: &mut Bx ) -> Option<IndexVec<Local, Vec<PerLocalVarDebugInfo<'tcx, Bx::DIVariable>>>>

Partition all VarDebugInfo in self.mir, by their base Local.

source§

impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx>

source

pub fn codegen_intrinsic_call( bx: &mut Bx, instance: Instance<'tcx>, fn_abi: &FnAbi<'tcx, Ty<'tcx>>, args: &[OperandRef<'tcx, Bx::Value>], llresult: Bx::Value, span: Span )

source§

impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx>

source

pub(super) fn initialize_locals( &mut self, values: Vec<LocalRef<'tcx, Bx::Value>> )

source

pub(super) fn overwrite_local( &mut self, local: Local, value: LocalRef<'tcx, Bx::Value> )

source§

impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx>

source

fn maybe_codegen_consume_direct( &mut self, bx: &mut Bx, place_ref: PlaceRef<'tcx> ) -> Option<OperandRef<'tcx, Bx::Value>>

source

pub fn codegen_consume( &mut self, bx: &mut Bx, place_ref: PlaceRef<'tcx> ) -> OperandRef<'tcx, Bx::Value>

source

pub fn codegen_operand( &mut self, bx: &mut Bx, operand: &Operand<'tcx> ) -> OperandRef<'tcx, Bx::Value>

source§

impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx>

source

pub fn codegen_place( &mut self, bx: &mut Bx, place_ref: PlaceRef<'tcx> ) -> PlaceRef<'tcx, Bx::Value>

source

pub fn monomorphized_place_ty(&self, place_ref: PlaceRef<'tcx>) -> Ty<'tcx>

source§

impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx>

source

pub fn codegen_rvalue( &mut self, bx: &mut Bx, dest: PlaceRef<'tcx, Bx::Value>, rvalue: &Rvalue<'tcx> )

source

fn codegen_transmute( &mut self, bx: &mut Bx, src: OperandRef<'tcx, Bx::Value>, dst: PlaceRef<'tcx, Bx::Value> )

source

fn codegen_transmute_operand( &mut self, bx: &mut Bx, operand: OperandRef<'tcx, Bx::Value>, cast: TyAndLayout<'tcx> ) -> Option<OperandValue<Bx::Value>>

Attempts to transmute an OperandValue to another OperandValue.

Returns None for cases that can’t work in that framework, such as for Immediate->Ref that needs an alloc to get the location.

source

fn transmute_immediate( &self, bx: &mut Bx, imm: Bx::Value, from_scalar: Scalar, from_backend_ty: Bx::Type, to_scalar: Scalar, to_backend_ty: Bx::Type ) -> Bx::Value

Transmutes one of the immediates from an OperandValue::Immediate or an OperandValue::Pair to an immediate of the target type.

to_backend_ty must be the non-immediate backend type (so it will be i8, not i1, for bool-like types.)

source

fn assume_scalar_range( &self, bx: &mut Bx, imm: Bx::Value, scalar: Scalar, backend_ty: Bx::Type )

source

pub fn codegen_rvalue_unsized( &mut self, bx: &mut Bx, indirect_dest: PlaceRef<'tcx, Bx::Value>, rvalue: &Rvalue<'tcx> )

source

pub fn codegen_rvalue_operand( &mut self, bx: &mut Bx, rvalue: &Rvalue<'tcx> ) -> OperandRef<'tcx, Bx::Value>

source

fn evaluate_array_len(&mut self, bx: &mut Bx, place: Place<'tcx>) -> Bx::Value

source

fn codegen_place_to_pointer( &mut self, bx: &mut Bx, place: Place<'tcx>, mk_ptr_ty: impl FnOnce(TyCtxt<'tcx>, Ty<'tcx>) -> Ty<'tcx> ) -> OperandRef<'tcx, Bx::Value>

Codegen an Rvalue::AddressOf or Rvalue::Ref

source

pub fn codegen_scalar_binop( &mut self, bx: &mut Bx, op: BinOp, lhs: Bx::Value, rhs: Bx::Value, input_ty: Ty<'tcx> ) -> Bx::Value

source

pub fn codegen_fat_ptr_binop( &mut self, bx: &mut Bx, op: BinOp, lhs_addr: Bx::Value, lhs_extra: Bx::Value, rhs_addr: Bx::Value, rhs_extra: Bx::Value, _input_ty: Ty<'tcx> ) -> Bx::Value

source

pub fn codegen_scalar_checked_binop( &mut self, bx: &mut Bx, op: BinOp, lhs: Bx::Value, rhs: Bx::Value, input_ty: Ty<'tcx> ) -> OperandValue<Bx::Value>

source§

impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx>

source

pub fn rvalue_creates_operand(&self, rvalue: &Rvalue<'tcx>, span: Span) -> bool

source

fn value_kind(&self, layout: TyAndLayout<'tcx>) -> OperandValueKind

Gets which variant of OperandValue is expected for a particular type.

source§

impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx>

source

pub fn codegen_statement(&mut self, bx: &mut Bx, statement: &Statement<'tcx>)

source§

impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx>

source

pub fn monomorphize<T>(&self, value: T) -> Twhere T: Copy + TypeFoldable<TyCtxt<'tcx>>,

Auto Trait Implementations§

§

impl<'a, 'tcx, Bx> !RefUnwindSafe for FunctionCx<'a, 'tcx, Bx>

§

impl<'a, 'tcx, Bx> !Send for FunctionCx<'a, 'tcx, Bx>

§

impl<'a, 'tcx, Bx> !Sync for FunctionCx<'a, 'tcx, Bx>

§

impl<'a, 'tcx, Bx> Unpin for FunctionCx<'a, 'tcx, Bx>where <Bx as BackendTypes>::BasicBlock: Unpin, <Bx as BackendTypes>::DILocation: Unpin, <Bx as BackendTypes>::DIScope: Unpin, <Bx as BackendTypes>::DIVariable: Unpin, <Bx as BackendTypes>::Funclet: Unpin, <Bx as BackendTypes>::Function: Unpin, <Bx as BackendTypes>::Value: Unpin,

§

impl<'a, 'tcx, Bx> !UnwindSafe for FunctionCx<'a, 'tcx, Bx>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

impl<T, U> Into<U> for Twhere 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, U> TryFrom<U> for Twhere U: Into<T>,

§

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

§

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.

Layout§

Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.