From a8cb2b48700335058a6c8fd1cd34eff4147e6389 Mon Sep 17 00:00:00 2001 From: Haled Odat <8566042+HalidOdat@users.noreply.github.com> Date: Sun, 18 Jun 2023 03:05:22 +0200 Subject: [PATCH] Add more opcodes to terminator --- .../control_flow_graph/basic_block.rs | 7 +++ .../src/optimizer/control_flow_graph/mod.rs | 60 ++++++++++++++++++- boa_engine/src/vm/opcode/mod.rs | 2 +- 3 files changed, 67 insertions(+), 2 deletions(-) diff --git a/boa_engine/src/optimizer/control_flow_graph/basic_block.rs b/boa_engine/src/optimizer/control_flow_graph/basic_block.rs index 05ced4aeae1..35f6f1419e7 100644 --- a/boa_engine/src/optimizer/control_flow_graph/basic_block.rs +++ b/boa_engine/src/optimizer/control_flow_graph/basic_block.rs @@ -110,6 +110,9 @@ impl BasicBlock { Terminator::JumpConditional { no, yes, .. } => { vec![no.clone(), yes.clone()] } + Terminator::TemplateLookup { no, yes, .. } => { + vec![no.clone(), yes.clone()] + } Terminator::Return { finally } => { let mut successors = Vec::new(); if let Some(finally) = finally { @@ -130,6 +133,10 @@ impl BasicBlock { nexts.push(no.clone()); nexts.push(yes.clone()); } + Terminator::TemplateLookup { no, yes, .. } => { + nexts.push(no.clone()); + nexts.push(yes.clone()); + } Terminator::Return { finally } => { if let Some(_finally) = finally { // FIXME: should we include this?? diff --git a/boa_engine/src/optimizer/control_flow_graph/mod.rs b/boa_engine/src/optimizer/control_flow_graph/mod.rs index b3cee00f7a4..dbc4df8da78 100644 --- a/boa_engine/src/optimizer/control_flow_graph/mod.rs +++ b/boa_engine/src/optimizer/control_flow_graph/mod.rs @@ -41,6 +41,18 @@ pub enum Terminator { yes: RcBasicBlock, }, + /// TODO: doc + TemplateLookup { + /// TODO: doc + no: RcBasicBlock, + + /// TODO: doc + yes: RcBasicBlock, + + /// TODO: doc + site: u64, + }, + /// TODO: doc Return { /// Finally block that the return should jump to, if exists. @@ -152,6 +164,14 @@ impl Debug for ControlFlowGraph { let target = index_from_basic_block(yes); write!(f, "{} B{target}", opcode.as_str())?; } + Terminator::TemplateLookup { + no: _, + yes, + site: _, + } => { + let target = index_from_basic_block(yes); + write!(f, "TemplateLookup B{target}")?; + } Terminator::Return { finally } => { write!(f, "Return")?; if let Some(finally) = finally { @@ -182,6 +202,12 @@ const fn is_jump_kind_opcode(opcode: Opcode) -> bool { | Opcode::JumpIfNullOrUndefined | Opcode::Case | Opcode::Default + | Opcode::LogicalAnd + | Opcode::LogicalOr + | Opcode::Coalesce + | Opcode::Break + | Opcode::BreakLabel + | Opcode::Continue ) } @@ -214,6 +240,10 @@ impl ControlFlowGraph { let exit = result.read::(0); leaders.push(exit); } + Opcode::TemplateLookup => { + let exit = result.read::(0); + leaders.push(exit); + } opcode if is_jump_kind_opcode(opcode) => { let target = result.read::(0); @@ -300,6 +330,23 @@ impl ControlFlowGraph { false } + Opcode::TemplateLookup => { + let address = result.read::(0); + let site = result.read::(4); + let yes = basic_block_from_bytecode_position(address); + let no = basic_blocks[i + 1].clone(); + + yes.borrow_mut() + .predecessors + .push(basic_blocks[i].downgrade()); + no.borrow_mut() + .predecessors + .push(basic_blocks[i].downgrade()); + + terminator = Terminator::TemplateLookup { no, yes, site }; + + false + } opcode if is_jump_kind_opcode(opcode) => { let address = result.read::(0); let yes = basic_block_from_bytecode_position(address); @@ -308,7 +355,9 @@ impl ControlFlowGraph { yes.borrow_mut() .predecessors .push(basic_blocks[i].downgrade()); - yes.borrow_mut().predecessors.push(no.downgrade()); + no.borrow_mut() + .predecessors + .push(basic_blocks[i].downgrade()); terminator = Terminator::JumpConditional { opcode, no, yes }; @@ -410,6 +459,15 @@ impl ControlFlowGraph { let target = index_from_basic_block(yes); labels.push((start as u32, target)); } + Terminator::TemplateLookup { yes, site, .. } => { + results.extend_from_slice(&[Opcode::TemplateLookup as u8]); + let start = results.len(); + results.extend_from_slice(&[0, 0, 0, 0]); + results.extend_from_slice(&site.to_ne_bytes()); + + let target = index_from_basic_block(yes); + labels.push((start as u32, target)); + } Terminator::Return { .. } => { results.push(Opcode::Return as u8); } diff --git a/boa_engine/src/vm/opcode/mod.rs b/boa_engine/src/vm/opcode/mod.rs index cac4b28b046..91fb0171ac6 100644 --- a/boa_engine/src/vm/opcode/mod.rs +++ b/boa_engine/src/vm/opcode/mod.rs @@ -1168,7 +1168,7 @@ generate_impl! { /// Start of a finally block. /// - /// Operands: + /// Operands: finally_end_address: u32 /// /// Stack: **=>** FinallyStart,