Skip to content

Commit

Permalink
cranelift-frontend: Add the FunctionBuilder::insert_block_after method
Browse files Browse the repository at this point in the history
  • Loading branch information
fitzgen committed Jun 30, 2020
1 parent 98e899f commit a2f4202
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 36 deletions.
5 changes: 5 additions & 0 deletions cranelift/frontend/src/frontend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,11 @@ impl<'a> FunctionBuilder<'a> {
block
}

/// Insert `block` in the layout *after* the existing block `after`.
pub fn insert_block_after(&mut self, block: Block, after: Block) {
self.func.layout.insert_block_after(block, after);
}

/// After the call to this function, new instructions will be inserted into the designated
/// block, in the order they are declared. You must declare the types of the Block arguments
/// you will use here.
Expand Down
45 changes: 9 additions & 36 deletions crates/environ/src/func_environ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -735,22 +735,10 @@ impl<'module_environment> cranelift_wasm::FuncEnvironment for FuncEnvironment<'m
let gc_block = builder.create_block();
let no_gc_block = builder.create_block();
let current_block = builder.current_block().unwrap();
builder
.func
.layout
.insert_block_after(non_null_elem_block, current_block);
builder
.func
.layout
.insert_block_after(no_gc_block, non_null_elem_block);
builder
.func
.layout
.insert_block_after(gc_block, no_gc_block);
builder
.func
.layout
.insert_block_after(continue_block, gc_block);
builder.insert_block_after(non_null_elem_block, current_block);
builder.insert_block_after(no_gc_block, non_null_elem_block);
builder.insert_block_after(gc_block, no_gc_block);
builder.insert_block_after(continue_block, gc_block);

// Load the table element.
let elem_addr = builder.ins().table_addr(pointer_type, table, index, 0);
Expand Down Expand Up @@ -893,30 +881,15 @@ impl<'module_environment> cranelift_wasm::FuncEnvironment for FuncEnvironment<'m

let current_block = builder.current_block().unwrap();
let inc_ref_count_block = builder.create_block();
builder
.func
.layout
.insert_block_after(inc_ref_count_block, current_block);
builder.insert_block_after(inc_ref_count_block, current_block);
let check_current_elem_block = builder.create_block();
builder
.func
.layout
.insert_block_after(check_current_elem_block, inc_ref_count_block);
builder.insert_block_after(check_current_elem_block, inc_ref_count_block);
let dec_ref_count_block = builder.create_block();
builder
.func
.layout
.insert_block_after(dec_ref_count_block, check_current_elem_block);
builder.insert_block_after(dec_ref_count_block, check_current_elem_block);
let drop_block = builder.create_block();
builder
.func
.layout
.insert_block_after(drop_block, dec_ref_count_block);
builder.insert_block_after(drop_block, dec_ref_count_block);
let continue_block = builder.create_block();
builder
.func
.layout
.insert_block_after(continue_block, drop_block);
builder.insert_block_after(continue_block, drop_block);

// Calculate the table address of the current element and do
// bounds checks. This is the first thing we do, because we
Expand Down

0 comments on commit a2f4202

Please sign in to comment.