Misc cleanups (#5014)
* Replace resize+copy_from_slice with extend_from_slice Vec::resize initializes the new space, which is wasted effort if we're just going to call `copy_from_slice` on it immediately afterward. Using `extend_from_slice` is simpler, and very slightly faster. If the new size were bigger than the buffer we're copying from, then it would make sense to initialize the excess. But it isn't: it's always exactly the same size. * Move helpers from Context to CompiledCode These methods only use information from Context::compiled_code, so they should live on CompiledCode instead. * Remove an unnecessary #[cfg_attr] There are other uses of `#[allow(clippy::too_many_arguments)]` in this file, so apparently it doesn't need to be guarded by the "cargo-clippy" feature. * Fix a few comments Two of these were wrong/misleading: - `FunctionBuilder::new` does not clear the provided func_ctx. It does debug-assert that the context is already clear, but I don't think that's worth a comment. - `switch_to_block` does not "create values for the arguments." That's done by the combination of `append_block_params_for_function_params` and `declare_wasm_parameters`. * wasmtime-cranelift: Misc cleanups The main change is to use the `CompiledCode` reference we already had instead of getting it out of `Context` repeatedly. This removes a bunch of `unwrap()` calls. * wasmtime-cranelift: Factor out uncached compile
This commit is contained in:
@@ -119,10 +119,7 @@ impl Context {
|
||||
mem: &mut Vec<u8>,
|
||||
) -> CompileResult<&CompiledCode> {
|
||||
let compiled_code = self.compile(isa)?;
|
||||
let code_info = compiled_code.code_info();
|
||||
let old_len = mem.len();
|
||||
mem.resize(old_len + code_info.total_size as usize, 0);
|
||||
mem[old_len..].copy_from_slice(compiled_code.code_buffer());
|
||||
mem.extend_from_slice(compiled_code.code_buffer());
|
||||
Ok(compiled_code)
|
||||
}
|
||||
|
||||
@@ -194,32 +191,21 @@ impl Context {
|
||||
/// If available, return information about the code layout in the
|
||||
/// final machine code: the offsets (in bytes) of each basic-block
|
||||
/// start, and all basic-block edges.
|
||||
#[deprecated = "use CompiledCode::get_code_bb_layout"]
|
||||
pub fn get_code_bb_layout(&self) -> Option<(Vec<usize>, Vec<(usize, usize)>)> {
|
||||
if let Some(result) = self.compiled_code.as_ref() {
|
||||
Some((
|
||||
result.bb_starts.iter().map(|&off| off as usize).collect(),
|
||||
result
|
||||
.bb_edges
|
||||
.iter()
|
||||
.map(|&(from, to)| (from as usize, to as usize))
|
||||
.collect(),
|
||||
))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
self.compiled_code().map(CompiledCode::get_code_bb_layout)
|
||||
}
|
||||
|
||||
/// Creates unwind information for the function.
|
||||
///
|
||||
/// Returns `None` if the function has no unwind information.
|
||||
#[cfg(feature = "unwind")]
|
||||
#[deprecated = "use CompiledCode::create_unwind_info"]
|
||||
pub fn create_unwind_info(
|
||||
&self,
|
||||
isa: &dyn TargetIsa,
|
||||
) -> CodegenResult<Option<crate::isa::unwind::UnwindInfo>> {
|
||||
let unwind_info_kind = isa.unwind_info_kind();
|
||||
let result = self.compiled_code.as_ref().unwrap();
|
||||
isa.emit_unwind_info(result, unwind_info_kind)
|
||||
self.compiled_code().unwrap().create_unwind_info(isa)
|
||||
}
|
||||
|
||||
/// Run the verifier on the function.
|
||||
|
||||
Reference in New Issue
Block a user