Do more Vec reserving.

This commit is contained in:
Dan Gohman
2019-02-22 17:10:23 -08:00
parent 538ef20f50
commit e2f79ae405
3 changed files with 27 additions and 20 deletions

View File

@@ -160,6 +160,9 @@ impl<'data> cranelift_wasm::ModuleEnvironment<'data> for ModuleEnvironment<'data
fn reserve_func_types(&mut self, num: u32) { fn reserve_func_types(&mut self, num: u32) {
self.result.module.functions.reserve_exact(cast::usize(num)); self.result.module.functions.reserve_exact(cast::usize(num));
self.result
.function_body_inputs
.reserve_exact(cast::usize(num));
} }
fn declare_func_type(&mut self, sig_index: SignatureIndex) { fn declare_func_type(&mut self, sig_index: SignatureIndex) {

View File

@@ -154,7 +154,6 @@ fn make_trampoline(
builder.switch_to_block(block0); builder.switch_to_block(block0);
builder.seal_block(block0); builder.seal_block(block0);
let mut callee_args = Vec::new();
let (vmctx_ptr_val, values_vec_ptr_val) = { let (vmctx_ptr_val, values_vec_ptr_val) = {
let params = builder.func.dfg.ebb_params(block0); let params = builder.func.dfg.ebb_params(block0);
(params[0], params[1]) (params[0], params[1])
@@ -162,20 +161,24 @@ fn make_trampoline(
// Load the argument values out of `values_vec`. // Load the argument values out of `values_vec`.
let mflags = ir::MemFlags::trusted(); let mflags = ir::MemFlags::trusted();
for (i, r) in signature.params.iter().enumerate() { let callee_args = signature
let value = match r.purpose { .params
// i - 1 because vmctx isn't passed through `values_vec`. .iter()
ir::ArgumentPurpose::Normal => builder.ins().load( .enumerate()
r.value_type, .map(|(i, r)| {
mflags, match r.purpose {
values_vec_ptr_val, // i - 1 because vmctx isn't passed through `values_vec`.
((i - 1) * value_size) as i32, ir::ArgumentPurpose::Normal => builder.ins().load(
), r.value_type,
ir::ArgumentPurpose::VMContext => vmctx_ptr_val, mflags,
other => panic!("unsupported argument purpose {}", other), values_vec_ptr_val,
}; ((i - 1) * value_size) as i32,
callee_args.push(value); ),
} ir::ArgumentPurpose::VMContext => vmctx_ptr_val,
other => panic!("unsupported argument purpose {}", other),
}
})
.collect::<Vec<_>>();
let new_sig = builder.import_signature(signature.clone()); let new_sig = builder.import_signature(signature.clone());

View File

@@ -87,11 +87,12 @@ impl<'data> RawCompiledModule<'data> {
// Compute indices into the shared signature table. // Compute indices into the shared signature table.
let signatures = { let signatures = {
let signature_registry = compiler.signatures(); let signature_registry = compiler.signatures();
let mut signatures = PrimaryMap::new(); translation
for sig in translation.module.signatures.values() { .module
signatures.push(signature_registry.register(sig)); .signatures
} .values()
signatures .map(|sig| signature_registry.register(sig))
.collect::<PrimaryMap<_, _>>()
}; };
// Make all code compiled thus far executable. // Make all code compiled thus far executable.