mirror of
https://github.com/fluencelabs/wasm-utils
synced 2025-05-22 04:01:25 +00:00
optimize virtual calls
This commit is contained in:
parent
f260bb8bb5
commit
d45f0d51d5
@ -1,7 +1,7 @@
|
|||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use parity_wasm::elements;
|
use parity_wasm::elements;
|
||||||
|
|
||||||
use symbols::{Symbol, expand_symbols, push_code_symbols, resolve_function};
|
use symbols::{Symbol, expand_symbols, push_code_symbols};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
@ -33,14 +33,14 @@ pub fn optimize(
|
|||||||
push_code_symbols(&module, segment.offset().code(), &mut init_symbols);
|
push_code_symbols(&module, segment.offset().code(), &mut init_symbols);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(elements_section) = module.elements_section() {
|
// if let Some(elements_section) = module.elements_section() {
|
||||||
for segment in elements_section.entries() {
|
// for segment in elements_section.entries() {
|
||||||
push_code_symbols(&module, segment.offset().code(), &mut init_symbols);
|
// push_code_symbols(&module, segment.offset().code(), &mut init_symbols);
|
||||||
for func_index in segment.members() {
|
// for func_index in segment.members() {
|
||||||
stay.insert(resolve_function(&module, *func_index));
|
// stay.insert(resolve_function(&module, *func_index));
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
for symbol in init_symbols.drain(..) { stay.insert(symbol); }
|
for symbol in init_symbols.drain(..) { stay.insert(symbol); }
|
||||||
|
|
||||||
// Call function which will traverse the list recursively, filling stay with all symbols
|
// Call function which will traverse the list recursively, filling stay with all symbols
|
||||||
|
@ -8,6 +8,7 @@ pub enum Symbol {
|
|||||||
Global(usize),
|
Global(usize),
|
||||||
Function(usize),
|
Function(usize),
|
||||||
Export(usize),
|
Export(usize),
|
||||||
|
IndirectCall,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn resolve_function(module: &elements::Module, index: u32) -> Symbol {
|
pub fn resolve_function(module: &elements::Module, index: u32) -> Symbol {
|
||||||
@ -58,6 +59,7 @@ pub fn push_code_symbols(module: &elements::Module, opcodes: &[elements::Opcode]
|
|||||||
},
|
},
|
||||||
&CallIndirect(idx, _) => {
|
&CallIndirect(idx, _) => {
|
||||||
dest.push(Symbol::Type(idx as usize));
|
dest.push(Symbol::Type(idx as usize));
|
||||||
|
dest.push(Symbol::IndirectCall);
|
||||||
},
|
},
|
||||||
&GetGlobal(idx) | &SetGlobal(idx) => {
|
&GetGlobal(idx) | &SetGlobal(idx) => {
|
||||||
dest.push(resolve_global(module, idx))
|
dest.push(resolve_global(module, idx))
|
||||||
@ -143,7 +145,16 @@ pub fn expand_symbols(module: &elements::Module, set: &mut HashSet<Symbol>) {
|
|||||||
}
|
}
|
||||||
set.insert(symbol);
|
set.insert(symbol);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
IndirectCall => {
|
||||||
|
for entry in module.elements_section().map(|s| s.entries()).unwrap_or(&[]) {
|
||||||
|
for func_index in entry.members() {
|
||||||
|
let symbol = resolve_function(&module, *func_index);
|
||||||
|
if !stop.contains(&symbol) { fringe.push(symbol); }
|
||||||
|
set.insert(symbol);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user