mirror of
https://github.com/fluencelabs/wasmer
synced 2025-04-01 23:41:03 +00:00
Set target triple and datalayout when creating the LLVM module.
This commit is contained in:
parent
aa8b968d40
commit
bc64b4ce6c
@ -4,8 +4,7 @@ use crate::structs::{Callbacks, LLVMModule, LLVMResult, MemProtect};
|
|||||||
use inkwell::{
|
use inkwell::{
|
||||||
memory_buffer::MemoryBuffer,
|
memory_buffer::MemoryBuffer,
|
||||||
module::Module,
|
module::Module,
|
||||||
targets::{CodeModel, FileType, InitializationConfig, RelocMode, Target, TargetMachine},
|
targets::{FileType, TargetMachine},
|
||||||
OptimizationLevel,
|
|
||||||
};
|
};
|
||||||
use libc::c_char;
|
use libc::c_char;
|
||||||
use std::{
|
use std::{
|
||||||
@ -172,28 +171,8 @@ impl LLVMBackend {
|
|||||||
_intrinsics: Intrinsics,
|
_intrinsics: Intrinsics,
|
||||||
_stackmaps: &StackmapRegistry,
|
_stackmaps: &StackmapRegistry,
|
||||||
_module_info: &ModuleInfo,
|
_module_info: &ModuleInfo,
|
||||||
|
target_machine: &TargetMachine,
|
||||||
) -> (Self, LLVMCache) {
|
) -> (Self, LLVMCache) {
|
||||||
Target::initialize_x86(&InitializationConfig {
|
|
||||||
asm_parser: true,
|
|
||||||
asm_printer: true,
|
|
||||||
base: true,
|
|
||||||
disassembler: true,
|
|
||||||
info: true,
|
|
||||||
machine_code: true,
|
|
||||||
});
|
|
||||||
let triple = TargetMachine::get_default_triple().to_string();
|
|
||||||
let target = Target::from_triple(&triple).unwrap();
|
|
||||||
let target_machine = target
|
|
||||||
.create_target_machine(
|
|
||||||
&triple,
|
|
||||||
&TargetMachine::get_host_cpu_name().to_string(),
|
|
||||||
&TargetMachine::get_host_cpu_features().to_string(),
|
|
||||||
OptimizationLevel::Aggressive,
|
|
||||||
RelocMode::Static,
|
|
||||||
CodeModel::Large,
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let memory_buffer = target_machine
|
let memory_buffer = target_machine
|
||||||
.write_to_memory_buffer(&module, FileType::Object)
|
.write_to_memory_buffer(&module, FileType::Object)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -3,12 +3,13 @@ use inkwell::{
|
|||||||
context::Context,
|
context::Context,
|
||||||
module::{Linkage, Module},
|
module::{Linkage, Module},
|
||||||
passes::PassManager,
|
passes::PassManager,
|
||||||
|
targets::{CodeModel, InitializationConfig, RelocMode, Target, TargetMachine},
|
||||||
types::{BasicType, BasicTypeEnum, FunctionType, PointerType, VectorType},
|
types::{BasicType, BasicTypeEnum, FunctionType, PointerType, VectorType},
|
||||||
values::{
|
values::{
|
||||||
BasicValue, BasicValueEnum, FloatValue, FunctionValue, IntValue, PhiValue, PointerValue,
|
BasicValue, BasicValueEnum, FloatValue, FunctionValue, IntValue, PhiValue, PointerValue,
|
||||||
VectorValue,
|
VectorValue,
|
||||||
},
|
},
|
||||||
AddressSpace, AtomicOrdering, AtomicRMWBinOp, FloatPredicate, IntPredicate,
|
AddressSpace, AtomicOrdering, AtomicRMWBinOp, FloatPredicate, IntPredicate, OptimizationLevel,
|
||||||
};
|
};
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
@ -677,6 +678,7 @@ pub struct LLVMModuleCodeGenerator {
|
|||||||
module: Module,
|
module: Module,
|
||||||
stackmaps: Rc<RefCell<StackmapRegistry>>,
|
stackmaps: Rc<RefCell<StackmapRegistry>>,
|
||||||
track_state: bool,
|
track_state: bool,
|
||||||
|
target_machine: TargetMachine,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct LLVMFunctionCodeGenerator {
|
pub struct LLVMFunctionCodeGenerator {
|
||||||
@ -7234,6 +7236,31 @@ impl ModuleCodeGenerator<LLVMFunctionCodeGenerator, LLVMBackend, CodegenError>
|
|||||||
fn new() -> LLVMModuleCodeGenerator {
|
fn new() -> LLVMModuleCodeGenerator {
|
||||||
let context = Context::create();
|
let context = Context::create();
|
||||||
let module = context.create_module("module");
|
let module = context.create_module("module");
|
||||||
|
|
||||||
|
Target::initialize_x86(&InitializationConfig {
|
||||||
|
asm_parser: true,
|
||||||
|
asm_printer: true,
|
||||||
|
base: true,
|
||||||
|
disassembler: true,
|
||||||
|
info: true,
|
||||||
|
machine_code: true,
|
||||||
|
});
|
||||||
|
let triple = TargetMachine::get_default_triple().to_string();
|
||||||
|
let target = Target::from_triple(&triple).unwrap();
|
||||||
|
let target_machine = target
|
||||||
|
.create_target_machine(
|
||||||
|
&triple,
|
||||||
|
&TargetMachine::get_host_cpu_name().to_string(),
|
||||||
|
&TargetMachine::get_host_cpu_features().to_string(),
|
||||||
|
OptimizationLevel::Aggressive,
|
||||||
|
RelocMode::Static,
|
||||||
|
CodeModel::Large,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
module.set_target(&target);
|
||||||
|
module.set_data_layout(&target_machine.get_target_data().get_data_layout());
|
||||||
|
|
||||||
let builder = context.create_builder();
|
let builder = context.create_builder();
|
||||||
|
|
||||||
let intrinsics = Intrinsics::declare(&module, &context);
|
let intrinsics = Intrinsics::declare(&module, &context);
|
||||||
@ -7259,6 +7286,7 @@ impl ModuleCodeGenerator<LLVMFunctionCodeGenerator, LLVMBackend, CodegenError>
|
|||||||
personality_func,
|
personality_func,
|
||||||
stackmaps: Rc::new(RefCell::new(StackmapRegistry::default())),
|
stackmaps: Rc::new(RefCell::new(StackmapRegistry::default())),
|
||||||
track_state: false,
|
track_state: false,
|
||||||
|
target_machine: target_machine,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -7430,6 +7458,7 @@ impl ModuleCodeGenerator<LLVMFunctionCodeGenerator, LLVMBackend, CodegenError>
|
|||||||
self.intrinsics.take().unwrap(),
|
self.intrinsics.take().unwrap(),
|
||||||
&*stackmaps,
|
&*stackmaps,
|
||||||
module_info,
|
module_info,
|
||||||
|
&self.target_machine,
|
||||||
);
|
);
|
||||||
Ok((backend, Box::new(cache_gen)))
|
Ok((backend, Box::new(cache_gen)))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user