Emit dynamic trampoline for each function index, not just each signature.

Emit names for trampolines when building through that experimental native pipeline.
This commit is contained in:
Nick Lewycky
2020-08-06 13:39:41 -07:00
parent ed878db40d
commit c68e7da972
2 changed files with 25 additions and 14 deletions

View File

@@ -122,7 +122,7 @@ impl LLVMCompiler {
compile_info
.module
.signatures
.values()
.into_iter()
.collect::<Vec<_>>()
.par_iter()
.map_init(
@@ -130,8 +130,9 @@ impl LLVMCompiler {
let target_machine = self.config().target_machine(target);
FuncTrampoline::new(target_machine)
},
|func_trampoline, sig| {
let module = func_trampoline.trampoline_to_module(sig, self.config())?;
|func_trampoline, (i, sig)| {
let name = symbol_registry.symbol_to_name(Symbol::FunctionCallTrampoline(*i));
let module = func_trampoline.trampoline_to_module(sig, self.config(), &name)?;
Ok(module.write_bitcode_to_memory().as_slice().to_vec())
},
)
@@ -145,18 +146,24 @@ impl LLVMCompiler {
compile_info
.module
.signatures
.values()
.functions
.into_iter()
.collect::<Vec<_>>()
.par_iter()
.map_init(
|| {
let target_machine = self.config().target_machine(target);
FuncTrampoline::new(target_machine)
(
FuncTrampoline::new(target_machine),
&compile_info.module.signatures,
)
},
|func_trampoline, sig| {
|(func_trampoline, signatures), (i, sig)| {
let sig = &signatures[**sig];
let name =
symbol_registry.symbol_to_name(Symbol::DynamicFunctionTrampoline(*i));
let module =
func_trampoline.dynamic_trampoline_to_module(sig, self.config())?;
func_trampoline.dynamic_trampoline_to_module(sig, self.config(), &name)?;
Ok(module.write_bitcode_to_memory().as_slice().to_vec())
},
)
@@ -337,7 +344,7 @@ impl Compiler for LLVMCompiler {
let target_machine = self.config().target_machine(target);
FuncTrampoline::new(target_machine)
},
|func_trampoline, sig| func_trampoline.trampoline(sig, self.config()),
|func_trampoline, sig| func_trampoline.trampoline(sig, self.config(), ""),
)
.collect::<Vec<_>>()
.into_iter()
@@ -353,7 +360,7 @@ impl Compiler for LLVMCompiler {
FuncTrampoline::new(target_machine)
},
|func_trampoline, func_type| {
func_trampoline.dynamic_trampoline(&func_type, self.config())
func_trampoline.dynamic_trampoline(&func_type, self.config(), "")
},
)
.collect::<Result<Vec<_>, CompileError>>()?

View File

@@ -39,6 +39,7 @@ impl FuncTrampoline {
&self,
ty: &FunctionType,
config: &LLVM,
name: &str,
) -> Result<Module, CompileError> {
// The function type, used for the callbacks.
let function = CompiledFunctionKind::FunctionCallTrampoline(ty.clone());
@@ -61,7 +62,7 @@ impl FuncTrampoline {
false,
);
let trampoline_func = module.add_function("", trampoline_ty, Some(Linkage::External));
let trampoline_func = module.add_function(name, trampoline_ty, Some(Linkage::External));
trampoline_func
.as_global_value()
.set_section(FUNCTION_SECTION);
@@ -92,8 +93,9 @@ impl FuncTrampoline {
&self,
ty: &FunctionType,
config: &LLVM,
name: &str,
) -> Result<FunctionBody, CompileError> {
let module = self.trampoline_to_module(ty, config)?;
let module = self.trampoline_to_module(ty, config, name)?;
let function = CompiledFunctionKind::FunctionCallTrampoline(ty.clone());
let target_machine = &self.target_machine;
@@ -161,6 +163,7 @@ impl FuncTrampoline {
&self,
ty: &FunctionType,
config: &LLVM,
name: &str,
) -> Result<Module, CompileError> {
// The function type, used for the callbacks
let function = CompiledFunctionKind::DynamicFunctionTrampoline(ty.clone());
@@ -172,7 +175,7 @@ impl FuncTrampoline {
let intrinsics = Intrinsics::declare(&module, &self.ctx);
let (trampoline_ty, trampoline_attrs) = func_type_to_llvm(&self.ctx, &intrinsics, ty)?;
let trampoline_func = module.add_function("", trampoline_ty, Some(Linkage::External));
let trampoline_func = module.add_function(name, trampoline_ty, Some(Linkage::External));
for (attr, attr_loc) in trampoline_attrs {
trampoline_func.add_attribute(attr_loc, attr);
}
@@ -205,11 +208,12 @@ impl FuncTrampoline {
&self,
ty: &FunctionType,
config: &LLVM,
name: &str,
) -> Result<FunctionBody, CompileError> {
let function = CompiledFunctionKind::DynamicFunctionTrampoline(ty.clone());
let target_machine = &self.target_machine;
let module = self.dynamic_trampoline_to_module(ty, config)?;
let module = self.dynamic_trampoline_to_module(ty, config, name)?;
let memory_buffer = target_machine
.write_to_memory_buffer(&module, FileType::Object)