Inline jump tables in parsed br_table instructions (#5755)
As jump tables are used by at most one br_table instruction, inline their definition in those instructions instead of requiring them to be declared as function-level metadata.
This commit is contained in:
@@ -81,7 +81,7 @@ impl JumpTableData {
|
||||
|
||||
impl Display for JumpTableData {
|
||||
fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
|
||||
write!(fmt, "jump_table [")?;
|
||||
write!(fmt, "[")?;
|
||||
match self.table.first() {
|
||||
None => (),
|
||||
Some(first) => write!(fmt, "{}", first)?,
|
||||
@@ -107,7 +107,7 @@ mod tests {
|
||||
assert_eq!(jt.as_slice().get(0), None);
|
||||
assert_eq!(jt.as_slice().get(10), None);
|
||||
|
||||
assert_eq!(jt.to_string(), "jump_table []");
|
||||
assert_eq!(jt.to_string(), "[]");
|
||||
|
||||
let v = jt.as_slice();
|
||||
assert_eq!(v, []);
|
||||
@@ -124,7 +124,7 @@ mod tests {
|
||||
jt.push_entry(e2);
|
||||
jt.push_entry(e1);
|
||||
|
||||
assert_eq!(jt.to_string(), "jump_table [block1, block2, block1]");
|
||||
assert_eq!(jt.to_string(), "[block1, block2, block1]");
|
||||
|
||||
let v = jt.as_slice();
|
||||
assert_eq!(v, [e1, e2, e1]);
|
||||
|
||||
@@ -446,15 +446,6 @@ impl<'a> Verifier<'a> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn verify_jump_tables(&self, errors: &mut VerifierErrors) -> VerifierStepResult<()> {
|
||||
for (jt, jt_data) in &self.func.stencil.dfg.jump_tables {
|
||||
for &block in jt_data.iter() {
|
||||
self.verify_block(jt, block, errors)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Check that the given block can be encoded as a BB, by checking that only
|
||||
/// branching instructions are ending the block.
|
||||
fn encodable_as_bb(&self, block: Block, errors: &mut VerifierErrors) -> VerifierStepResult<()> {
|
||||
@@ -861,6 +852,9 @@ impl<'a> Verifier<'a> {
|
||||
format!("invalid jump table reference {}", j),
|
||||
))
|
||||
} else {
|
||||
for &block in self.func.stencil.dfg.jump_tables[j].as_slice() {
|
||||
self.verify_block(inst, block, errors)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -1792,7 +1786,6 @@ impl<'a> Verifier<'a> {
|
||||
pub fn run(&self, errors: &mut VerifierErrors) -> VerifierStepResult<()> {
|
||||
self.verify_global_values(errors)?;
|
||||
self.verify_tables(errors)?;
|
||||
self.verify_jump_tables(errors)?;
|
||||
self.typecheck_entry_block_params(errors)?;
|
||||
self.check_entry_not_cold(errors)?;
|
||||
self.typecheck_function_signature(errors)?;
|
||||
|
||||
@@ -82,11 +82,6 @@ pub trait FuncWriter {
|
||||
}
|
||||
}
|
||||
|
||||
for (jt, jt_data) in &func.stencil.dfg.jump_tables {
|
||||
any = true;
|
||||
self.write_entity_definition(w, func, jt.into(), jt_data)?;
|
||||
}
|
||||
|
||||
for (&cref, cval) in func.dfg.constants.iter() {
|
||||
any = true;
|
||||
self.write_entity_definition(w, func, cref.into(), cval)?;
|
||||
@@ -377,6 +372,7 @@ fn write_instruction(
|
||||
/// Write the operands of `inst` to `w` with a prepended space.
|
||||
pub fn write_operands(w: &mut dyn Write, dfg: &DataFlowGraph, inst: Inst) -> fmt::Result {
|
||||
let pool = &dfg.value_lists;
|
||||
let jump_tables = &dfg.jump_tables;
|
||||
use crate::ir::instructions::InstructionData::*;
|
||||
match dfg.insts[inst] {
|
||||
AtomicRmw { op, args, .. } => write!(w, " {} {}, {}", op, args[0], args[1]),
|
||||
@@ -430,7 +426,7 @@ pub fn write_operands(w: &mut dyn Write, dfg: &DataFlowGraph, inst: Inst) -> fmt
|
||||
destination,
|
||||
table,
|
||||
..
|
||||
} => write!(w, " {}, {}, {}", arg, destination, table),
|
||||
} => write!(w, " {}, {}, {}", arg, destination, jump_tables[table]),
|
||||
Call {
|
||||
func_ref, ref args, ..
|
||||
} => write!(w, " {}({})", func_ref, DisplayValues(args.as_slice(pool))),
|
||||
|
||||
Reference in New Issue
Block a user