Allow offloading compilation in cranelift-object (#2371)

This commit is a slight refactoring of the `Module` trait and backend in
`cranelift-object`. The goal is to enable parallelization of compilation
when using `cranelift-object`. Currently this is difficult because
`ObjectModule::define_function` requires `&mut self`. This instead
soups up the `define_function_bytes` interface to handle relocations so
compilation can happen externally before defining it in a `Module`. This
also means that `define_function` is now a convenience wrapper around
`define_function_bytes`.
This commit is contained in:
Alex Crichton
2020-11-06 09:56:44 -06:00
committed by GitHub
parent b2b7bc10e2
commit 8af2dbfbac
4 changed files with 113 additions and 125 deletions

View File

@@ -10,7 +10,7 @@ use cranelift_codegen::{self, ir, settings};
use cranelift_entity::SecondaryMap;
use cranelift_module::{
DataContext, DataDescription, DataId, FuncId, FuncOrDataId, Init, Linkage, Module,
ModuleCompiledFunction, ModuleDeclarations, ModuleError, ModuleResult,
ModuleCompiledFunction, ModuleDeclarations, ModuleError, ModuleResult, RelocRecord,
};
use cranelift_native;
#[cfg(not(windows))]
@@ -134,15 +134,6 @@ pub struct SimpleJITModule {
data_objects_to_finalize: Vec<DataId>,
}
/// A record of a relocation to perform.
#[derive(Clone)]
struct RelocRecord {
offset: CodeOffset,
reloc: Reloc,
name: ir::ExternalName,
addend: Addend,
}
struct StackMapRecord {
#[allow(dead_code)]
offset: CodeOffset,
@@ -528,6 +519,7 @@ impl<'simple_jit_backend> Module for SimpleJITModule {
&mut self,
id: FuncId,
bytes: &[u8],
relocs: &[RelocRecord],
) -> ModuleResult<ModuleCompiledFunction> {
let decl = self.declarations.get_function_decl(id);
if !decl.linkage.is_definable() {
@@ -560,7 +552,7 @@ impl<'simple_jit_backend> Module for SimpleJITModule {
self.functions[id] = Some(CompiledBlob {
ptr,
size,
relocs: vec![],
relocs: relocs.to_vec(),
});
Ok(ModuleCompiledFunction { size: total_size })