Commit 10e9b6f1 authored by Isaac Oscar Gariano's avatar Isaac Oscar Gariano

Merge branch 'malloc' into threadlocal_reg2

parents 044d9d4b 84cfb281
...@@ -1571,34 +1571,35 @@ impl<'a> InstructionSelection { ...@@ -1571,34 +1571,35 @@ impl<'a> InstructionSelection {
Instruction_::New(ref ty) => { Instruction_::New(ref ty) => {
trace!("instsel on NEW"); trace!("instsel on NEW");
if cfg!(debug_assertions) { let tmp_res = self.get_result_value(node, 0);
match ty.v {
MuType_::Hybrid(_) => {
panic!("cannot use NEW for hybrid, use NEWHYBRID instead")
}
_ => {}
}
}
let ty_info = vm.get_backend_type_info(ty.id()); let ty_info = vm.get_backend_type_info(ty.id());
let size = ty_info.size;
let ty_align = ty_info.alignment; let ty_align = ty_info.alignment;
let size = make_value_int_const(ty_info.size as u64, vm);
let const_size = make_value_int_const(size as u64, vm); if !vm.vm_options.flag_use_alloc {
self.emit_runtime_entry(
&entrypoints::MALLOC,
vec![size],
Some(vec![tmp_res]),
Some(node),
f_context,
vm
);
} else {
let tmp_allocator = self.emit_get_allocator(f_context, vm); let tmp_allocator = self.emit_get_allocator(f_context, vm);
let tmp_res = self.emit_alloc_sequence( let tmp_res = self.emit_alloc_sequence(
tmp_allocator.clone(), tmp_allocator.clone(),
const_size, size,
ty_align, ty_align,
node, node,
f_context, f_context,
vm vm
); );
// ASM: call muentry_init_object(%allocator, %tmp_res, %encode) let encode = make_value_int_const(
let encode = mm::get_gc_type_encode(ty_info.gc_type.id),
make_value_int_const(mm::get_gc_type_encode(ty_info.gc_type.id), vm); vm
);
self.emit_runtime_entry( self.emit_runtime_entry(
&entrypoints::INIT_OBJ, &entrypoints::INIT_OBJ,
vec![tmp_allocator.clone(), tmp_res.clone(), encode], vec![tmp_allocator.clone(), tmp_res.clone(), encode],
...@@ -1608,25 +1609,14 @@ impl<'a> InstructionSelection { ...@@ -1608,25 +1609,14 @@ impl<'a> InstructionSelection {
vm vm
); );
} }
}
Instruction_::NewHybrid(ref ty, var_len) => { Instruction_::NewHybrid(ref ty, var_len) => {
trace!("instsel on NEWHYBRID"); trace!("instsel on NEWHYBRID");
if cfg!(debug_assertions) {
match ty.v {
MuType_::Hybrid(_) => {}
_ => {
panic!(
"NEWHYBRID is only for allocating hybrid types, \
use NEW for others"
)
}
}
}
let ty_info = vm.get_backend_type_info(ty.id()); let ty_info = vm.get_backend_type_info(ty.id());
let ty_align = ty_info.alignment;
let fix_part_size = ty_info.size; let fix_part_size = ty_info.size;
let var_ty_size = ty_info.elem_size.unwrap(); let var_ty_size = ty_info.elem_size.unwrap();
let ty_align = ty_info.alignment;
// actual size = fix_part_size + var_ty_size * len // actual size = fix_part_size + var_ty_size * len
let (actual_size, length) = { let (actual_size, length) = {
...@@ -1641,15 +1631,16 @@ impl<'a> InstructionSelection { ...@@ -1641,15 +1631,16 @@ impl<'a> InstructionSelection {
make_value_int_const(var_len as u64, vm) make_value_int_const(var_len as u64, vm)
) )
} else { } else {
let var_len = self.emit_ireg(var_len, f_content, f_context, vm);
emit_zext(self.backend.as_mut(), &var_len); // this will zero
let tmp_actual_size = let tmp_actual_size =
make_temporary(f_context, UINT64_TYPE.clone(), vm); make_temporary(f_context, UINT64_TYPE.clone(), vm);
let tmp_var_len = self.emit_ireg(var_len, f_content, f_context, vm);
// tmp_actual_size = tmp_var_len*var_ty_size // tmp_actual_size = var_len*var_ty_size
emit_mul_u64( emit_mul_u64(
self.backend.as_mut(), self.backend.as_mut(),
&tmp_actual_size, &tmp_actual_size,
&tmp_var_len, &cast_value(&var_len, &UINT64_TYPE),
var_ty_size as u64 var_ty_size as u64
); );
// tmp_actual_size = tmp_var_len*var_ty_size + fix_part_size // tmp_actual_size = tmp_var_len*var_ty_size + fix_part_size
...@@ -1659,10 +1650,22 @@ impl<'a> InstructionSelection { ...@@ -1659,10 +1650,22 @@ impl<'a> InstructionSelection {
&tmp_actual_size, &tmp_actual_size,
fix_part_size as u64 fix_part_size as u64
); );
(tmp_actual_size, tmp_var_len) (tmp_actual_size, var_len)
} }
}; };
if !vm.vm_options.flag_use_alloc {
let tmp_res = self.get_result_value(node, 0);
self.emit_runtime_entry(
&entrypoints::MALLOC,
vec![actual_size],
Some(vec![tmp_res]),
Some(node),
f_context,
vm
);
} else {
let tmp_allocator = self.emit_get_allocator(f_context, vm); let tmp_allocator = self.emit_get_allocator(f_context, vm);
let tmp_res = self.emit_alloc_sequence( let tmp_res = self.emit_alloc_sequence(
tmp_allocator.clone(), tmp_allocator.clone(),
...@@ -1674,8 +1677,10 @@ impl<'a> InstructionSelection { ...@@ -1674,8 +1677,10 @@ impl<'a> InstructionSelection {
); );
// ASM: call muentry_init_object(%allocator, %tmp_res, %encode) // ASM: call muentry_init_object(%allocator, %tmp_res, %encode)
let encode = let encode = make_value_int_const(
make_value_int_const(mm::get_gc_type_encode(ty_info.gc_type.id), vm); mm::get_gc_type_encode(ty_info.gc_type.id),
vm
);
self.emit_runtime_entry( self.emit_runtime_entry(
&entrypoints::INIT_HYBRID, &entrypoints::INIT_HYBRID,
vec![tmp_allocator.clone(), tmp_res.clone(), encode, length], vec![tmp_allocator.clone(), tmp_res.clone(), encode, length],
...@@ -1684,6 +1689,8 @@ impl<'a> InstructionSelection { ...@@ -1684,6 +1689,8 @@ impl<'a> InstructionSelection {
f_context, f_context,
vm vm
); );
}
} }
Instruction_::AllocA(ref ty) => { Instruction_::AllocA(ref ty) => {
......
...@@ -1726,8 +1726,21 @@ impl<'a> InstructionSelection { ...@@ -1726,8 +1726,21 @@ impl<'a> InstructionSelection {
let ty_align = ty_info.alignment; let ty_align = ty_info.alignment;
let const_size = self.make_int_const(size as u64, vm); let const_size = self.make_int_const(size as u64, vm);
if !vm.vm_options.flag_use_alloc {
let tmp_res = self.get_result_value(node);
self.emit_runtime_entry(
&entrypoints::MALLOC,
vec![const_size],
Some(vec![tmp_res]),
Some(node),
f_content,
f_context,
vm
);
} else {
// get allocator // get allocator
let tmp_allocator = self.emit_get_allocator(node, f_content, f_context, vm); let tmp_allocator =
self.emit_get_allocator(node, f_content, f_context, vm);
// allocate // allocate
let tmp_res = self.emit_alloc_sequence( let tmp_res = self.emit_alloc_sequence(
tmp_allocator.clone(), tmp_allocator.clone(),
...@@ -1751,6 +1764,7 @@ impl<'a> InstructionSelection { ...@@ -1751,6 +1764,7 @@ impl<'a> InstructionSelection {
vm vm
); );
} }
}
Instruction_::NewHybrid(ref ty, var_len) => { Instruction_::NewHybrid(ref ty, var_len) => {
trace!("instsel on NEWHYBRID"); trace!("instsel on NEWHYBRID");
...@@ -1829,7 +1843,20 @@ impl<'a> InstructionSelection { ...@@ -1829,7 +1843,20 @@ impl<'a> InstructionSelection {
} }
}; };
let tmp_allocator = self.emit_get_allocator(node, f_content, f_context, vm); if !vm.vm_options.flag_use_alloc {
let tmp_res = self.get_result_value(node);
self.emit_runtime_entry(
&entrypoints::MALLOC,
vec![actual_size],
Some(vec![tmp_res]),
Some(node),
f_content,
f_context,
vm
);
} else {
let tmp_allocator =
self.emit_get_allocator(node, f_content, f_context, vm);
let tmp_res = self.emit_alloc_sequence( let tmp_res = self.emit_alloc_sequence(
tmp_allocator.clone(), tmp_allocator.clone(),
actual_size, actual_size,
...@@ -1853,6 +1880,7 @@ impl<'a> InstructionSelection { ...@@ -1853,6 +1880,7 @@ impl<'a> InstructionSelection {
vm vm
); );
} }
}
/*Instruction_::AllocA(ref ty) => { /*Instruction_::AllocA(ref ty) => {
trace!("instsel on AllocA"); trace!("instsel on AllocA");
......
...@@ -123,11 +123,15 @@ fn emit_muir_dot_inner(file: &mut File, f_name: MuName, f_content: &FunctionCont ...@@ -123,11 +123,15 @@ fn emit_muir_dot_inner(file: &mut File, f_name: MuName, f_content: &FunctionCont
// all the instructions // all the instructions
for inst in block_content.body.iter() { for inst in block_content.body.iter() {
<<<<<<< HEAD
write!( write!(
file, file,
" {}\\l", " {}\\l",
escape_string(format!("{}", inst.as_inst())) escape_string(format!("{}", inst.as_inst()))
).unwrap(); ).unwrap();
=======
write!(file, " {}\\l", escape_string(format!("{}", inst.as_inst_ref()))).unwrap();
>>>>>>> malloc
} }
// "]; // "];
......
...@@ -116,6 +116,11 @@ lazy_static! { ...@@ -116,6 +116,11 @@ lazy_static! {
"muentry_unpin_object", "muentry_unpin_object",
vec![ADDRESS_TYPE.clone()], vec![ADDRESS_TYPE.clone()],
vec![]); vec![]);
pub static ref MALLOC : RuntimeEntrypoint = RuntimeEntrypoint::new(
"alloc_mem_zero",
vec![UINT64_TYPE.clone()],
vec![ADDRESS_TYPE.clone()]);
} }
// decl: exception.rs // decl: exception.rs
......
...@@ -82,3 +82,7 @@ int32_t c_check_result() { ...@@ -82,3 +82,7 @@ int32_t c_check_result() {
char * alloc_mem(size_t size){ char * alloc_mem(size_t size){
return (char *) malloc(size); return (char *) malloc(size);
} }
void* alloc_mem_zero(size_t size){
return calloc(size, 1);
}
...@@ -54,3 +54,7 @@ void* resolve_symbol(const char* sym) { ...@@ -54,3 +54,7 @@ void* resolve_symbol(const char* sym) {
// printf("%s\n", sym); // printf("%s\n", sym);
return dlsym(RTLD_DEFAULT, sym); return dlsym(RTLD_DEFAULT, sym);
} }
void* alloc_mem_zero(size_t size){
return calloc(size, 1);
}
...@@ -34,6 +34,7 @@ Compiler: ...@@ -34,6 +34,7 @@ Compiler:
--disable-inline disable compiler function inlining --disable-inline disable compiler function inlining
--disable-regalloc-validate disable register allocation validation --disable-regalloc-validate disable register allocation validation
--disable-ir-validate disable IR validation --disable-ir-validate disable IR validation
--use-alloc Use alloc (instead of the faster calloc)
--emit-debug-info emit debugging information --emit-debug-info emit debugging information
AOT Compiler: AOT Compiler:
...@@ -64,6 +65,7 @@ pub struct VMOptions { ...@@ -64,6 +65,7 @@ pub struct VMOptions {
pub flag_disable_inline: bool, pub flag_disable_inline: bool,
pub flag_disable_regalloc_validate: bool, pub flag_disable_regalloc_validate: bool,
pub flag_disable_ir_validate: bool, pub flag_disable_ir_validate: bool,
pub flag_use_alloc: bool,
pub flag_emit_debug_info: bool, pub flag_emit_debug_info: bool,
// AOT compiler // AOT compiler
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment