Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions crates/trunk-ir/src/arena/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,19 @@ impl IrContext {
self.block_arg_values[b].as_slice(&self.value_pool)
}

/// Add a new argument to an existing block and return its `ValueRef`.
pub fn add_block_arg(&mut self, block: BlockRef, arg: BlockArgData) -> ValueRef {
let index = self.blocks[block].args.len() as u32;
let ty = arg.ty;
self.blocks[block].args.push(arg);
let v = self.values.push(ValueData {
def: ValueDef::BlockArg(block, index),
ty,
});
self.block_arg_values[block].push(v, &mut self.value_pool);
v
}

/// Append an operation to the end of a block.
///
/// # Panics
Expand Down Expand Up @@ -361,6 +374,17 @@ impl IrContext {
}
}

/// Detach an operation from its parent block.
///
/// This is a convenience wrapper around `remove_op_from_block` that uses
/// the operation's own `parent_block` field. Does nothing if the operation
/// is not attached to any block.
pub fn detach_op(&mut self, op: OpRef) {
if let Some(block) = self.ops[op].parent_block {
self.remove_op_from_block(block, op);
}
}

// ========================================================================
// Region
// ========================================================================
Expand Down
1 change: 1 addition & 0 deletions crates/trunk-ir/src/arena/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub mod ops;
pub mod printer;
pub mod refs;
pub mod rewrite;
pub mod transforms;
pub mod types;
pub mod walk;

Expand Down
Loading
Loading