pub struct Builder<'a> { /* private fields */ }Expand description
A cursor that appends to the end of one block.
This is the shape lowering wants: it works on one block at a time, it appends, and it wants
the value back so it can use it in the next instruction. Everything here is a thin wrapper
over Func::create_inst and Func::append_inst, and anything the wrappers do not
cover is done with those two directly.
Implementations§
Source§impl<'a> Builder<'a>
impl<'a> Builder<'a>
Sourcepub fn new(func: &'a mut Func, block: Block) -> Self
pub fn new(func: &'a mut Func, block: Block) -> Self
A cursor appending to that block, with every instruction taking that source location.
Sourcepub fn at(self, span: Span) -> Self
pub fn at(self, span: Span) -> Self
The same cursor, with a source location for the instructions after this.
Sourcepub fn set_span(&mut self, span: Span)
pub fn set_span(&mut self, span: Span)
Sets the source location for the instructions after this.
Sourcepub fn inst(&mut self, data: InstData, results: &[Type]) -> Inst
pub fn inst(&mut self, data: InstData, results: &[Type]) -> Inst
Appends an instruction as it is, and gives back its results.
Sourcepub fn fconst(&mut self, ty: Type, bits: u128) -> Value
pub fn fconst(&mut self, ty: Type, bits: u128) -> Value
A floating point constant, given as the bits of its format.
Sourcepub fn binary(
&mut self,
opcode: Opcode,
lhs: Value,
rhs: Value,
flags: Flags,
) -> Value
pub fn binary( &mut self, opcode: Opcode, lhs: Value, rhs: Value, flags: Flags, ) -> Value
A two-operand instruction whose result has the type of its operands.
Sourcepub fn unary(&mut self, opcode: Opcode, arg: Value, ty: Type) -> Value
pub fn unary(&mut self, opcode: Opcode, arg: Value, ty: Type) -> Value
A one-operand instruction whose result has the type given.
Sourcepub fn icmp(&mut self, pred: IntPred, lhs: Value, rhs: Value) -> Value
pub fn icmp(&mut self, pred: IntPred, lhs: Value, rhs: Value) -> Value
An integer comparison, which produces one i1 per lane.
Sourcepub fn fcmp(
&mut self,
pred: FloatPred,
lhs: Value,
rhs: Value,
flags: Flags,
) -> Value
pub fn fcmp( &mut self, pred: FloatPred, lhs: Value, rhs: Value, flags: Flags, ) -> Value
A floating point comparison, which produces one i1 per lane.
Sourcepub fn load(
&mut self,
ty: Type,
addr: Value,
info: MemInfo,
flags: Flags,
) -> Value
pub fn load( &mut self, ty: Type, addr: Value, info: MemInfo, flags: Flags, ) -> Value
A read of that type from that address.
Sourcepub fn store(
&mut self,
value: Value,
addr: Value,
info: MemInfo,
flags: Flags,
) -> Inst
pub fn store( &mut self, value: Value, addr: Value, info: MemInfo, flags: Flags, ) -> Inst
A write of a value to an address.
Sourcepub fn block_addr(&mut self, target: Block) -> Value
pub fn block_addr(&mut self, target: Block) -> Value
The address of a block, which is a value a later indirect_br can branch to.
The block is a target here in the same sense a branch’s is, so everything that asks an instruction which blocks it names finds this one, and a block whose address is taken is not mistaken for a block nothing mentions.
Sourcepub fn indirect_br(&mut self, addr: Value, targets: &[Block]) -> Inst
pub fn indirect_br(&mut self, addr: Value, targets: &[Block]) -> Inst
A branch to an address, which arrives at one of the blocks listed.
Every block the address can hold has to be there. The list is what the rest of the compiler reads, so a block left out of it is a block the branch is saying it never reaches, and none of it is checked against the addresses anybody took.
Sourcepub fn br_if(
&mut self,
cond: Value,
then_block: Block,
then_args: &[Value],
else_block: Block,
else_args: &[Value],
) -> Inst
pub fn br_if( &mut self, cond: Value, then_block: Block, then_args: &[Value], else_block: Block, else_args: &[Value], ) -> Inst
A two-way branch, taking the first target when the condition is one.
Sourcepub fn switch(
&mut self,
value: Value,
default: Block,
cases: &[(i128, Block)],
) -> Inst
pub fn switch( &mut self, value: Value, default: Block, cases: &[(i128, Block)], ) -> Inst
A branch on an integer, taking the target its value selects and the default when it selects none.
The cases are values and blocks rather than a table with the default in it, because the
order the side table wants, which is the default first, is not an order anybody building
a switch has their cases in.
Sourcepub fn unreachable(&mut self) -> Inst
pub fn unreachable(&mut self) -> Inst
A place control does not reach.
Sourcepub fn call(&mut self, callee: Symbol, signature: Sig, args: &[Value]) -> Inst
pub fn call(&mut self, callee: Symbol, signature: Sig, args: &[Value]) -> Inst
A direct call, with the results its signature says it produces.
Sourcepub fn inline_asm(
&mut self,
info: AsmInfo,
args: &[Value],
results: &[Type],
flags: Flags,
) -> Inst
pub fn inline_asm( &mut self, info: AsmInfo, args: &[Value], results: &[Type], flags: Flags, ) -> Inst
Inline assembly, which is a terminator when the info carries targets.
The targets are built by the caller, because the frontend is the only thing that knows which block is the one control reaches when the assembly does not jump, and that block has to come first.