pub trait LowerCtx {
type I: VCodeInst;
Show 26 methods
fn abi(&mut self) -> &mut dyn ABICallee<I = Self::I>;
fn retval(&self, idx: usize) -> ValueRegs<Writable<Reg>>;
fn get_vm_context(&self) -> Option<Reg>;
fn data(&self, ir_inst: Inst) -> &InstructionData;
fn ty(&self, ir_inst: Inst) -> Type;
fn call_target<'b>(
&'b self,
ir_inst: Inst
) -> Option<(&'b ExternalName, RelocDistance)>;
fn call_sig<'b>(&'b self, ir_inst: Inst) -> Option<&'b Signature>;
fn symbol_value<'b>(
&'b self,
ir_inst: Inst
) -> Option<(&'b ExternalName, RelocDistance, i64)>;
fn memflags(&self, ir_inst: Inst) -> Option<MemFlags>;
fn srcloc(&self, ir_inst: Inst) -> SourceLoc;
fn num_inputs(&self, ir_inst: Inst) -> usize;
fn num_outputs(&self, ir_inst: Inst) -> usize;
fn input_ty(&self, ir_inst: Inst, idx: usize) -> Type;
fn output_ty(&self, ir_inst: Inst, idx: usize) -> Type;
fn get_constant(&self, ir_inst: Inst) -> Option<u64>;
fn get_input_as_source_or_const(
&self,
ir_inst: Inst,
idx: usize
) -> NonRegInput;
fn put_input_in_regs(&mut self, ir_inst: Inst, idx: usize) -> ValueRegs<Reg>;
fn get_output(&self, ir_inst: Inst, idx: usize) -> ValueRegs<Writable<Reg>>;
fn alloc_tmp(&mut self, ty: Type) -> ValueRegs<Writable<Reg>>;
fn emit(&mut self, mach_inst: Self::I);
fn emit_safepoint(&mut self, mach_inst: Self::I);
fn sink_inst(&mut self, ir_inst: Inst);
fn get_constant_data(&self, constant_handle: Constant) -> &ConstantData;
fn use_constant(&mut self, constant: VCodeConstantData) -> VCodeConstant;
fn get_immediate(&self, ir_inst: Inst) -> Option<DataValue>;
fn ensure_in_vreg(&mut self, reg: Reg, ty: Type) -> Reg;
}
Expand description
A context that machine-specific lowering code can use to emit lowered instructions. This is the view of the machine-independent per-function lowering context that is seen by the machine backend.
Associated Types
Required methods
Get the (virtual) register that receives the return value. A return instruction should lower into a sequence that fills this register. (Why not allow the backend to specify its own result register for the return? Because there may be multiple return points.)
fn get_vm_context(&self) -> Option<Reg>
fn get_vm_context(&self) -> Option<Reg>
Returns the vreg containing the VmContext parameter, if there’s one.
fn data(&self, ir_inst: Inst) -> &InstructionData
fn data(&self, ir_inst: Inst) -> &InstructionData
Get the instdata for a given IR instruction.
fn call_target<'b>(
&'b self,
ir_inst: Inst
) -> Option<(&'b ExternalName, RelocDistance)>
fn call_target<'b>(
&'b self,
ir_inst: Inst
) -> Option<(&'b ExternalName, RelocDistance)>
Get the target for a call instruction, as an ExternalName
. Returns a tuple
providing this name and the “relocation distance”, i.e., whether the backend
can assume the target will be “nearby” (within some small offset) or an
arbitrary address. (This comes from the colocated
bit in the CLIF.)
Get the signature for a call or call-indirect instruction.
fn symbol_value<'b>(
&'b self,
ir_inst: Inst
) -> Option<(&'b ExternalName, RelocDistance, i64)>
fn symbol_value<'b>(
&'b self,
ir_inst: Inst
) -> Option<(&'b ExternalName, RelocDistance, i64)>
Get the symbol name, relocation distance estimate, and offset for a symbol_value instruction.
Returns the memory flags of a given memory access.
fn num_inputs(&self, ir_inst: Inst) -> usize
fn num_inputs(&self, ir_inst: Inst) -> usize
Get the number of inputs to the given IR instruction.
fn num_outputs(&self, ir_inst: Inst) -> usize
fn num_outputs(&self, ir_inst: Inst) -> usize
Get the number of outputs to the given IR instruction.
Get the type for an instruction’s output.
fn get_constant(&self, ir_inst: Inst) -> Option<u64>
fn get_constant(&self, ir_inst: Inst) -> Option<u64>
Get the value of a constant instruction (iconst
, etc.) as a 64-bit
value, if possible.
fn get_input_as_source_or_const(&self, ir_inst: Inst, idx: usize) -> NonRegInput
fn get_input_as_source_or_const(&self, ir_inst: Inst, idx: usize) -> NonRegInput
Get the input as one of two options other than a direct register:
- An instruction, given that it is effect-free or able to sink its effect to the current instruction being lowered, and given it has only one output, and if effect-ful, given that this is the only use;
- A constant, if the value is a constant.
The instruction input may be available in either of these forms. It may
be available in neither form, if the conditions are not met; if so, use
put_input_in_regs()
instead to get it in a register.
If the backend merges the effect of a side-effecting instruction, it
must call sink_inst()
. When this is called, it indicates that the
effect has been sunk to the current scan location. The sunk
instruction’s result(s) must have no uses remaining, because it will
not be codegen’d (it has been integrated into the current instruction).
Put the idx
th input into register(s) and return the assigned register.
Get the idx
th output register(s) of the given IR instruction. When
backend.lower_inst_to_regs(ctx, inst)
is called, it is expected that
the backend will write results to these output register(s). This
register will always be “fresh”; it is guaranteed not to overlap with
any of the inputs, and can be freely used as a scratch register within
the lowered instruction sequence, as long as its final value is the
result of the computation.
fn emit_safepoint(&mut self, mach_inst: Self::I)
fn emit_safepoint(&mut self, mach_inst: Self::I)
Emit a machine instruction that is a safepoint.
Indicate that the side-effect of an instruction has been sunk to the
current scan location. This should only be done with the instruction’s
original results are not used (i.e., put_input_in_regs
is not invoked
for the input produced by the sunk instruction), otherwise the
side-effect will occur twice.
fn get_constant_data(&self, constant_handle: Constant) -> &ConstantData
fn get_constant_data(&self, constant_handle: Constant) -> &ConstantData
Retrieve constant data given a handle.
fn use_constant(&mut self, constant: VCodeConstantData) -> VCodeConstant
fn use_constant(&mut self, constant: VCodeConstantData) -> VCodeConstant
Indicate that a constant should be emitted.
fn get_immediate(&self, ir_inst: Inst) -> Option<DataValue>
fn get_immediate(&self, ir_inst: Inst) -> Option<DataValue>
Retrieve the value immediate from an instruction. This will perform necessary lookups on the
DataFlowGraph
to retrieve even large immediates.
fn ensure_in_vreg(&mut self, reg: Reg, ty: Type) -> Reg
fn ensure_in_vreg(&mut self, reg: Reg, ty: Type) -> Reg
Cause the value in reg
to be in a virtual reg, by copying it into a new virtual reg
if reg
is a real reg. ty
describes the type of the value in reg
.