Commit ae1e02a5 authored by Isaac Oscar Gariano's avatar Isaac Oscar Gariano

Finished swapstack implementation

parent b6005b2e
......@@ -125,8 +125,12 @@ pub struct MuType {
rodal_struct!(MuType { hdr, v });
impl PartialEq for MuType {
fn eq(&self, other: &MuType) -> bool { self.v == other.v }
fn ne(&self, other: &MuType) -> bool { self.v != other.v }
fn eq(&self, other: &MuType) -> bool {
self.v == other.v
}
fn ne(&self, other: &MuType) -> bool {
self.v != other.v
}
}
impl MuType {
......@@ -206,7 +210,8 @@ impl MuType {
}
pub fn is_eq_comparable(&self) -> bool {
self.is_int() || self.is_ptr() || self.is_iref() || self.is_ref() || self.is_opaque_reference()
self.is_int() || self.is_ptr() || self.is_iref() || self.is_ref() ||
self.is_opaque_reference()
}
pub fn is_ult_comparable(&self) -> bool {
......
......@@ -2117,7 +2117,16 @@ impl ASMCodeGen {
self.add_asm_inst(asm, ignore_zero_register(id1, vec![loc1]), uses, false)
}
fn internal_call(&mut self, callsite: Option<String>, code: String, pe: Option<MuName>, args: Vec<P<Value>>, ret: Vec<P<Value>>, target: Option<(MuID, ASMLocation)>, may_return: bool) -> Option<ValueLocation> {
fn internal_call(
&mut self,
callsite: Option<String>,
code: String,
pe: Option<MuName>,
args: Vec<P<Value>>,
ret: Vec<P<Value>>,
target: Option<(MuID, ASMLocation)>,
may_return: bool
) -> Option<ValueLocation> {
let mut uses: LinkedHashMap<MuID, Vec<ASMLocation>> = LinkedHashMap::new();
if target.is_some() {
let (id, loc) = target.unwrap();
......
......@@ -133,9 +133,9 @@ pub trait CodeGenerator {
func: Reg,
pe: Option<MuName>,
args: Vec<P<Value>>,
ret: Vec<P<Value>>,
ret: Vec<P<Value>>
) -> Option<ValueLocation>;
// Branches
// Branches
fn emit_b(&mut self, dest_name: MuName);
fn emit_b_cond(&mut self, cond: &str, dest_name: MuName);
fn emit_br(&mut self, dest_address: Reg);
......
......@@ -267,7 +267,9 @@ pub fn get_alias_for_length(id: MuID, length: usize) -> P<Value> {
}
pub fn is_aliased(id1: MuID, id2: MuID) -> bool {
return id1 == id2 || (id1 < MACHINE_ID_END && id2 < MACHINE_ID_END && get_color_for_precolored(id1) == get_color_for_precolored(id2));
return id1 == id2 ||
(id1 < MACHINE_ID_END && id2 < MACHINE_ID_END &&
get_color_for_precolored(id1) == get_color_for_precolored(id2));
}
pub fn get_color_for_precolored(id: MuID) -> MuID {
......@@ -958,7 +960,9 @@ pub fn estimate_insts_for_ir(inst: &Instruction) -> usize {
// runtime
New(_) | NewHybrid(_, _) => 10,
NewStack(_) | NewThread(_, _) | NewThreadExn(_, _) | NewFrameCursor(_) => 10,
ThreadExit => 10, CurrentStack => 10, KillStack(_) => 10,
ThreadExit => 10,
CurrentStack => 10,
KillStack(_) => 10,
Throw(_) => 10,
SwapStackExpr { .. } | SwapStackExc { .. } | SwapStackKill { .. } => 10,
CommonInst_GetThreadLocal | CommonInst_SetThreadLocal(_) => 10,
......
......@@ -234,7 +234,12 @@ impl CompilerPass for GenMovPhi {
}
Instruction_::Watchpoint { .. } => unimplemented!(),
Instruction_::WPBranch { .. } => unimplemented!(),
Instruction_::SwapStackExc { stack, is_exception, args, resume } => {
Instruction_::SwapStackExc {
stack,
is_exception,
args,
resume
} => {
let norm_dest = process_dest(
resume.normal_dest,
&mut new_blocks_to_insert,
......@@ -269,7 +274,7 @@ impl CompilerPass for GenMovPhi {
trace!("rewrite to {}", new_inst);
new_body.push(new_inst);
},
}
Instruction_::ExnInstruction { .. } => unimplemented!(),
_ => {
trace!("no rewrite");
......
......@@ -587,7 +587,6 @@ fn copy_inline_blocks(
is_exception,
ref args,
ref resume
} => {
let swapstack = Instruction {
hdr: hdr,
......
......@@ -38,8 +38,7 @@ use runtime::*;
/// (and are accessed by get/set_return_address and get/set_previous_frame and may be passed
/// real frame pointers or the frame cursor)
#[no_mangle]
pub extern "C" fn throw_exception_internal(exception_obj: Address, frame_cursor: Address) ->
! {
pub extern "C" fn throw_exception_internal(exception_obj: Address, frame_cursor: Address) -> ! {
trace!("throwing exception: {}", exception_obj);
if cfg!(debug_assertions) {
......
......@@ -60,14 +60,14 @@ begin_func muthread_start_normal
MOV SP, X0
// Pop the argument registers from the new stack
LDP D0, D1, [SP, #14*8]
LDP D2, D3, [SP, #12*8]
LDP D4, D5, [SP, #10*8]
LDP D6, D7, [SP, #8*8]
LDP X0, X1, [SP, #6*8]
LDP X2, X3, [SP, #4*8]
LDP X4, X5, [SP, #2*8]
LDP X6, X7, [SP, #0*8]
LDP D1, D0 , [SP, #14*8]
LDP D3, D2, [SP, #12*8]
LDP D5, D4, [SP, #10*8]
LDP D7, D6, [SP, #8*8]
LDP X1, X0, [SP, #6*8]
LDP X3, X2, [SP, #4*8]
LDP X5, X4, [SP, #2*8]
LDP X7, X6, [SP, #0*8]
ADD SP, SP, #16*8
// Jump to the new stack
......
......@@ -147,11 +147,15 @@ impl MuStack {
// Push entry as the return address
sp -= POINTER_SIZE;
unsafe { sp.store(func_addr); }
unsafe {
sp.store(func_addr);
}
// Push a null frame pointer
sp -= POINTER_SIZE;
unsafe { sp.store(Address::zero()); }
unsafe {
sp.store(Address::zero());
}
debug!("creating stack {} with entry address {:?}", id, func_addr);
debug!("overflow_guard : {}", overflow_guard);
......@@ -285,7 +289,7 @@ pub enum MuStackState {
Active,
/// can be destroyed
Dead,
Unknown,
Unknown
}
/// MuThread represents metadata for a Mu thread.
......@@ -341,11 +345,7 @@ impl fmt::Display for MuThread {
"- allocator @{:?}\n",
&self.allocator as *const mm::Mutator
).unwrap();
write!(
f,
"- stack @{:?}\n",
&self.stack as *const *mut MuStack
).unwrap();
write!(f, "- stack @{:?}\n", &self.stack as *const *mut MuStack).unwrap();
write!(
f,
"- native sp @{:?}: {}\n",
......@@ -475,7 +475,6 @@ impl MuThread {
// set thread local
unsafe { set_thread_local(&mut muthread) };
trace!("new MuThread @{}", Address::from_ref(&mut muthread));
let addr = unsafe { muentry_get_thread_local() };
let sp_threadlocal_loc = addr + *NATIVE_SP_LOC_OFFSET;
......@@ -636,9 +635,7 @@ rodal_struct!(PrimordialThreadInfo {
pub unsafe extern "C" fn muentry_new_stack(entry: Address, stack_size: usize) -> *mut MuStack {
let ref vm = MuThread::current_mut().vm;
let stack = Box::new(MuStack::new(vm.next_id(), entry, stack_size));
let res = Box::into_raw(stack);
trace!("<- MuStack @{}", Address::from_ptr(res));
res
Box::into_raw(stack)
}
// Kills the given stack. WARNING! do not call this whilst on the given stack
......@@ -646,4 +643,4 @@ pub unsafe extern "C" fn muentry_new_stack(entry: Address, stack_size: usize) ->
pub unsafe extern "C" fn muentry_kill_stack(stack: *mut MuStack) {
// This new box will be destroyed upon returning
Box::from_raw(stack);
}
\ No newline at end of file
}
......@@ -1201,13 +1201,7 @@ impl<'a> VM {
let func_addr = resolve_symbol(self.name_of(func_id));
let stack_arg_size = backend::call_stack_size(func.sig.clone(), self);
let b = Box::into_raw(Box::new(MuStack::new(
self.next_id(),
func_addr,
stack_arg_size
)));
trace!("<- MuStack @{}", Address::from_ptr(b));
unsafe { Box::from_raw(b) }
Box::new(MuStack::new(self.next_id(), func_addr, stack_arg_size))
}
/// creates a handle that we can return to the client
......
......@@ -18,7 +18,6 @@ extern crate libloading;
use mu::linkutils;
use mu::linkutils::aot;
use mu::utils::LinkedHashMap;
use mu::compiler::backend::x86_64;
use test_compiler::test_call::gen_ccall_exit;
use self::mu::compiler::*;
use self::mu::ast::ir::*;
......@@ -2115,4 +2114,4 @@ fn coalesce_unusable_reg() -> VM {
});
vm
}
\ No newline at end of file
}
This diff is collapsed.
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