Skip to content

Commit 19038bf

Browse files
feat: new binopt superinstructions
Signed-off-by: Henry <mail@henrygressmann.de>
1 parent 5b31817 commit 19038bf

6 files changed

Lines changed: 519 additions & 127 deletions

File tree

crates/parser/src/optimize.rs

Lines changed: 323 additions & 39 deletions
Large diffs are not rendered by default.

crates/parser/src/visit.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,8 @@ impl<'a, R: WasmModuleResources> wasmparser::VisitOperator<'a> for FunctionBuild
240240
}
241241

242242
fn visit_loop(&mut self, _ty: wasmparser::BlockType) -> Self::Output {
243-
if !matches!(self.instructions.last(), Some(Instruction::Nop)) {
244-
self.instructions.push(Instruction::Nop); // add nop to ensure that no superinstruction can be merged across block boundaries
243+
if !matches!(self.instructions.last(), Some(Instruction::Nop | Instruction::MergeBarrier)) {
244+
self.instructions.push(Instruction::MergeBarrier); // prevent superinstructions from merging across block boundaries
245245
}
246246
let start_ip = self.instructions.len();
247247
self.ctx_stack.push(LoweringCtx { kind: BlockKind::Loop, has_else: false, start_ip, branch_jumps: Vec::new() });
@@ -266,8 +266,8 @@ impl<'a, R: WasmModuleResources> wasmparser::VisitOperator<'a> for FunctionBuild
266266
ctx.has_else = true;
267267
ctx.branch_jumps.push(jump_ip);
268268
self.patch_jump_if_zero(cond_jump_ip, self.instructions.len());
269-
if !matches!(self.instructions.last(), Some(Instruction::Nop)) {
270-
self.instructions.push(Instruction::Nop); // add nop to ensure that no superinstruction can be merged across block boundaries
269+
if !matches!(self.instructions.last(), Some(Instruction::Nop | Instruction::MergeBarrier)) {
270+
self.instructions.push(Instruction::MergeBarrier); // prevent superinstructions from merging across block boundaries
271271
}
272272
};
273273
};
@@ -276,8 +276,8 @@ impl<'a, R: WasmModuleResources> wasmparser::VisitOperator<'a> for FunctionBuild
276276
fn visit_end(&mut self) -> Self::Output {
277277
if let Some(ctx) = self.ctx_stack.pop() {
278278
self.patch_end_jumps(ctx, self.instructions.len());
279-
if !matches!(self.instructions.last(), Some(Instruction::Nop)) {
280-
self.instructions.push(Instruction::Nop); // add nop to ensure that no superinstruction can be merged across block boundaries
279+
if !matches!(self.instructions.last(), Some(Instruction::Nop | Instruction::MergeBarrier)) {
280+
self.instructions.push(Instruction::MergeBarrier); // prevent superinstructions from merging across block boundaries
281281
}
282282
} else {
283283
self.instructions.push(Instruction::Return);

0 commit comments

Comments
 (0)