Commit 044d9d4b authored by Isaac Oscar Gariano's avatar Isaac Oscar Gariano

Implemented threadlocal register

parent 6cc6b97f
......@@ -1429,11 +1429,10 @@ impl<'a> InstructionSelection {
// emit a call to swap_back_to_native_stack(sp_loc: Address)
// get thread local and add offset to get sp_loc
let tl = self.emit_get_threadlocal(f_context, vm);
emit_load_base_offset(
self.backend.as_mut(),
&tl,
&tl,
&MU_TL,
&MU_TL,
*thread::NATIVE_SP_LOC_OFFSET as i64,
f_context,
vm
......@@ -1441,7 +1440,7 @@ impl<'a> InstructionSelection {
self.emit_runtime_entry(
&entrypoints::THREAD_EXIT,
vec![tl.clone()],
vec![MU_TL.clone()],
None,
Some(node),
f_context,
......@@ -1488,16 +1487,13 @@ impl<'a> InstructionSelection {
Instruction_::CurrentStack => {
trace!("instsel on CURRENT_STACK");
// get thread local
let tl = self.emit_get_threadlocal(f_context, vm);
let tmp_res = self.get_result_value(node, 0);
// load [tl + STACK_OFFSET] -> tmp_res
emit_load_base_offset(
self.backend.as_mut(),
&tmp_res,
&tl,
&MU_TL,
*thread::STACK_OFFSET as i64,
f_context,
vm
......@@ -1506,15 +1502,13 @@ impl<'a> InstructionSelection {
Instruction_::CommonInst_GetThreadLocal => {
trace!("instsel on GETTHREADLOCAL");
// get thread local
let tl = self.emit_get_threadlocal(f_context, vm);
let tmp_res = self.get_result_value(node, 0);
// load [tl + USER_TLS_OFFSET] -> tmp_res
emit_load_base_offset(
self.backend.as_mut(),
&tmp_res,
&tl,
&MU_TL,
*thread::USER_TLS_OFFSET as i64,
f_context,
vm
......@@ -1530,13 +1524,10 @@ impl<'a> InstructionSelection {
let tmp_op = self.emit_ireg(op, f_content, f_context, vm);
// get thread local
let tl = self.emit_get_threadlocal(f_context, vm);
// store tmp_op -> [tl + USER_TLS_OFFSTE]
emit_store_base_offset(
self.backend.as_mut(),
&tl,
&MU_TL,
*thread::USER_TLS_OFFSET as i64,
&tmp_op,
f_context,
......@@ -3685,16 +3676,13 @@ impl<'a> InstructionSelection {
}
fn emit_get_allocator(&mut self, f_context: &mut FunctionContext, vm: &VM) -> P<Value> {
// ASM: %tl = get_thread_local()
let tmp_tl = self.emit_get_threadlocal(f_context, vm);
// ASM: lea [%tl + allocator_offset] -> %tmp_allocator
let allocator_offset = *thread::ALLOCATOR_OFFSET;
let tmp_allocator = make_temporary(f_context, ADDRESS_TYPE.clone(), vm);
emit_add_u64(
self.backend.as_mut(),
&tmp_allocator,
&tmp_tl,
&MU_TL,
allocator_offset as u64
);
tmp_allocator
......@@ -3756,20 +3744,6 @@ impl<'a> InstructionSelection {
}
}
// This generates code identical to (though it may use different registers)
// the function muentry_get_thread_local
fn emit_get_threadlocal(&mut self, f_context: &mut FunctionContext, vm: &VM) -> P<Value> {
let mut rets = self.emit_runtime_entry(
&entrypoints::GET_THREAD_LOCAL,
vec![],
None,
None,
f_context,
vm
);
rets.pop().unwrap()
}
// ret: Option<Vec<P<Value>>
// if ret is Some, return values will put stored in given temporaries
// otherwise create temporaries
......@@ -4508,14 +4482,12 @@ impl<'a> InstructionSelection {
// Compute all the arguments...
let mut arg_values = self.emit_arg_values(&args, ops, f_content, f_context, vm);
let tl = self.emit_get_threadlocal(f_context, vm);
let cur_stackref = make_temporary(f_context, STACKREF_TYPE.clone(), vm);
// Load the current stackref
emit_load_base_offset(
self.backend.as_mut(),
&cur_stackref,
&tl,
&MU_TL,
*thread::STACK_OFFSET as i64,
f_context,
vm
......@@ -4525,7 +4497,7 @@ impl<'a> InstructionSelection {
let swapee = self.emit_ireg(&ops[swapee], f_content, f_context, vm);
emit_store_base_offset(
self.backend.as_mut(),
&tl,
&MU_TL,
*thread::STACK_OFFSET as i64,
&swapee,
f_context,
......@@ -5936,11 +5908,10 @@ impl<'a> InstructionSelection {
vm: &VM
) {
// get thread local and add offset to get exception_obj
let tl = self.emit_get_threadlocal(f_context, vm);
emit_load_base_offset(
self.backend.as_mut(),
exception_arg,
&tl,
&MU_TL,
*thread::EXCEPTION_OBJ_OFFSET as i64,
f_context,
vm
......
......@@ -148,6 +148,9 @@ ALIAS!(X29 -> FP);
// Link Register (not supposed to be used for any other purpose)
ALIAS!(X30 -> LR);
// Mu thread local
ALIAS!(X28 -> MU_TL);
lazy_static! {
pub static ref GPR_ALIAS_TABLE : LinkedHashMap<MuID, Vec<P<Value>>> = {
let mut ret = LinkedHashMap::new();
......@@ -356,7 +359,7 @@ lazy_static! {
X7.clone()
];
pub static ref CALLEE_SAVED_GPRS : [P<Value>; 10] = [
pub static ref CALLEE_SAVED_GPRS : [P<Value>; 9] = [
X19.clone(),
X20.clone(),
X21.clone(),
......@@ -366,7 +369,7 @@ lazy_static! {
X25.clone(),
X26.clone(),
X27.clone(),
X28.clone(),
// X28.clone(), // Mu Thread Local Register
// Note: These two are technically CALLEE saved but need to be dealt with specially
//X29.clone(), // Frame Pointer
......@@ -745,7 +748,7 @@ lazy_static! {
X25.clone(),
X26.clone(),
X27.clone(),
X28.clone(),
//X28.clone(), Mu thread-local
//X29.clone(), // Frame Pointer
//X30.clone(), // Link Register
];
......
......@@ -59,6 +59,10 @@ begin_func muthread_start_normal
// Swap to the new stack
MOV SP, X0
// Update the MU_TL register
BL muentry_get_thread_local
MOV X28, X0
// Pop the argument registers from the new stack
LDP D1, D0, [SP, #14*8 ]
LDP D3, D2, [SP, #12*8 ]
......@@ -86,6 +90,10 @@ begin_func muthread_start_exceptional
MOV X11, SP
STR X11, [X2]
// Update the MU_TL register
BL muentry_get_thread_local
MOV X28, X0
// Swap to the new stack
MOV SP, X1
SUB SP, SP, #144 // Alocate space for callee saved registers
......
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