WARNING! Access to this system is limited to authorised users only.
Unauthorised users may be subject to prosecution.
Unauthorised access to this system is a criminal offence under Australian law (Federal Crimes Act 1914 Part VIA)
It is a criminal offence to:
(1) Obtain access to data without authority. -Penalty 2 years imprisonment.
(2) Damage, delete, alter or insert data without authority. -Penalty 10 years imprisonment.
User activity is monitored and recorded. Anyone using this system expressly consents to such monitoring and recording.

Commit 470eac11 authored by qinsoon's avatar qinsoon
Browse files

[wip] refactored TreeNode

parent 8f9266c0
...@@ -10,21 +10,25 @@ use std::sync::RwLock; ...@@ -10,21 +10,25 @@ use std::sync::RwLock;
#[derive(Debug)] #[derive(Debug)]
pub struct Instruction { pub struct Instruction {
pub hdr: MuEntityHeader,
pub value : Option<Vec<P<Value>>>, pub value : Option<Vec<P<Value>>>,
pub ops : RwLock<Vec<P<TreeNode>>>, pub ops : RwLock<Vec<P<TreeNode>>>,
pub v: Instruction_ pub v: Instruction_
} }
impl_mu_entity!(Instruction);
use rustc_serialize::{Encodable, Encoder, Decodable, Decoder}; use rustc_serialize::{Encodable, Encoder, Decodable, Decoder};
impl Encodable for Instruction { impl Encodable for Instruction {
fn encode<S: Encoder> (&self, s: &mut S) -> Result<(), S::Error> { fn encode<S: Encoder> (&self, s: &mut S) -> Result<(), S::Error> {
s.emit_struct("Instruction", 3, |s| { s.emit_struct("Instruction", 4, |s| {
try!(s.emit_struct_field("value", 0, |s| self.value.encode(s))); try!(s.emit_struct_field("hdr", 0, |s| self.hdr.encode(s)));
try!(s.emit_struct_field("value", 1, |s| self.value.encode(s)));
let ops = &self.ops.read().unwrap(); let ops = &self.ops.read().unwrap();
try!(s.emit_struct_field("ops", 1, |s| ops.encode(s))); try!(s.emit_struct_field("ops", 2, |s| ops.encode(s)));
try!(s.emit_struct_field("v", 2, |s| self.v.encode(s))); try!(s.emit_struct_field("v", 3, |s| self.v.encode(s)));
Ok(()) Ok(())
}) })
...@@ -33,14 +37,16 @@ impl Encodable for Instruction { ...@@ -33,14 +37,16 @@ impl Encodable for Instruction {
impl Decodable for Instruction { impl Decodable for Instruction {
fn decode<D: Decoder>(d: &mut D) -> Result<Instruction, D::Error> { fn decode<D: Decoder>(d: &mut D) -> Result<Instruction, D::Error> {
d.read_struct("Instruction", 3, |d| { d.read_struct("Instruction", 4, |d| {
let value = try!(d.read_struct_field("value", 0, |d| Decodable::decode(d))); let hdr = try!(d.read_struct_field("hdr", 0, |d| Decodable::decode(d)));
let value = try!(d.read_struct_field("value", 1, |d| Decodable::decode(d)));
let ops = try!(d.read_struct_field("ops", 1, |d| Decodable::decode(d))); let ops = try!(d.read_struct_field("ops", 2, |d| Decodable::decode(d)));
let v = try!(d.read_struct_field("v", 2, |d| Decodable::decode(d))); let v = try!(d.read_struct_field("v", 3, |d| Decodable::decode(d)));
Ok(Instruction{ Ok(Instruction{
hdr: hdr,
value: value, value: value,
ops: RwLock::new(ops), ops: RwLock::new(ops),
v: v v: v
...@@ -52,6 +58,7 @@ impl Decodable for Instruction { ...@@ -52,6 +58,7 @@ impl Decodable for Instruction {
impl Clone for Instruction { impl Clone for Instruction {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Instruction { Instruction {
hdr: self.hdr.clone(),
value: self.value.clone(), value: self.value.clone(),
ops: RwLock::new(self.ops.read().unwrap().clone()), ops: RwLock::new(self.ops.read().unwrap().clone()),
v: self.v.clone() v: self.v.clone()
......
...@@ -158,31 +158,27 @@ impl MuFunctionVersion { ...@@ -158,31 +158,27 @@ impl MuFunctionVersion {
self.context.values.insert(id, SSAVarEntry::new(val.clone())); self.context.values.insert(id, SSAVarEntry::new(val.clone()));
P(TreeNode { P(TreeNode {
hdr: MuEntityHeader::unnamed(id),
op: pick_op_code_for_ssa(&val.ty), op: pick_op_code_for_ssa(&val.ty),
v: TreeNode_::Value(val) v: TreeNode_::Value(val)
}) })
} }
pub fn new_constant(&mut self, id: MuID, v: P<Value>) -> P<TreeNode> { pub fn new_constant(&mut self, v: P<Value>) -> P<TreeNode> {
P(TreeNode{ P(TreeNode{
hdr: MuEntityHeader::unnamed(id),
op: pick_op_code_for_value(&v.ty), op: pick_op_code_for_value(&v.ty),
v: TreeNode_::Value(v) v: TreeNode_::Value(v)
}) })
} }
pub fn new_global(&mut self, id: MuID, v: P<Value>) -> P<TreeNode> { pub fn new_global(&mut self, v: P<Value>) -> P<TreeNode> {
P(TreeNode{ P(TreeNode{
hdr: MuEntityHeader::unnamed(id),
op: pick_op_code_for_value(&v.ty), op: pick_op_code_for_value(&v.ty),
v: TreeNode_::Value(v) v: TreeNode_::Value(v)
}) })
} }
pub fn new_inst(&mut self, id: MuID, v: Instruction) -> Box<TreeNode> { pub fn new_inst(&mut self, v: Instruction) -> Box<TreeNode> {
Box::new(TreeNode{ Box::new(TreeNode{
hdr: MuEntityHeader::unnamed(id),
op: pick_op_code_for_inst(&v), op: pick_op_code_for_inst(&v),
v: TreeNode_::Instruction(v), v: TreeNode_::Instruction(v),
}) })
...@@ -257,7 +253,6 @@ impl FunctionContext { ...@@ -257,7 +253,6 @@ impl FunctionContext {
self.values.insert(id, SSAVarEntry::new(val.clone())); self.values.insert(id, SSAVarEntry::new(val.clone()));
P(TreeNode { P(TreeNode {
hdr: MuEntityHeader::unnamed(id),
op: pick_op_code_for_ssa(&val.ty), op: pick_op_code_for_ssa(&val.ty),
v: TreeNode_::Value(val) v: TreeNode_::Value(val)
}) })
...@@ -459,16 +454,14 @@ impl BlockContent { ...@@ -459,16 +454,14 @@ impl BlockContent {
#[derive(Debug, RustcEncodable, RustcDecodable, Clone)] #[derive(Debug, RustcEncodable, RustcDecodable, Clone)]
/// always use with P<TreeNode> /// always use with P<TreeNode>
pub struct TreeNode { pub struct TreeNode {
pub hdr: MuEntityHeader,
pub op: OpCode, pub op: OpCode,
pub v: TreeNode_, pub v: TreeNode_,
} }
impl TreeNode { impl TreeNode {
// this is a hack to allow creating TreeNode without using a &mut MuFunctionVersion // this is a hack to allow creating TreeNode without using a &mut MuFunctionVersion
pub fn new_inst(id: MuID, v: Instruction) -> P<TreeNode> { pub fn new_inst(v: Instruction) -> P<TreeNode> {
P(TreeNode{ P(TreeNode{
hdr: MuEntityHeader::unnamed(id),
op: pick_op_code_for_inst(&v), op: pick_op_code_for_inst(&v),
v: TreeNode_::Instruction(v), v: TreeNode_::Instruction(v),
}) })
...@@ -895,11 +888,40 @@ pub trait MuEntity { ...@@ -895,11 +888,40 @@ pub trait MuEntity {
impl_mu_entity!(MuFunction); impl_mu_entity!(MuFunction);
impl_mu_entity!(MuFunctionVersion); impl_mu_entity!(MuFunctionVersion);
impl_mu_entity!(Block); impl_mu_entity!(Block);
impl_mu_entity!(TreeNode);
impl_mu_entity!(MuType); impl_mu_entity!(MuType);
impl_mu_entity!(Value); impl_mu_entity!(Value);
impl_mu_entity!(MuFuncSig); impl_mu_entity!(MuFuncSig);
impl MuEntity for TreeNode {
fn id(&self) -> MuID {
match self.v {
TreeNode_::Instruction(ref inst) => inst.id(),
TreeNode_::Value(ref pv) => pv.id()
}
}
fn name(&self) -> Option<MuName> {
match self.v {
TreeNode_::Instruction(ref inst) => inst.name(),
TreeNode_::Value(ref pv) => pv.name()
}
}
fn set_name(&self, name: MuName) {
match self.v {
TreeNode_::Instruction(ref inst) => inst.set_name(name),
TreeNode_::Value(ref pv) => pv.set_name(name)
}
}
fn as_entity(&self) -> &MuEntity {
match self.v {
TreeNode_::Instruction(ref inst) => inst.as_entity(),
TreeNode_::Value(ref pv) => pv.as_entity()
}
}
}
pub fn op_vector_str(vec: &Vec<OpIndex>, ops: &Vec<P<TreeNode>>) -> String { pub fn op_vector_str(vec: &Vec<OpIndex>, ops: &Vec<P<TreeNode>>) -> String {
let mut ret = String::new(); let mut ret = String::new();
for i in 0..vec.len() { for i in 0..vec.len() {
......
...@@ -52,7 +52,7 @@ pub type P<T> = Arc<T>; ...@@ -52,7 +52,7 @@ pub type P<T> = Arc<T>;
#[allow(non_snake_case)] #[allow(non_snake_case)]
/// Construct a `P<T>` from a `T` value. /// Construct a `P<T>` from a `T` value.
pub fn P<T: MuEntity>(value: T) -> P<T> { pub fn P<T>(value: T) -> P<T> {
// P {ptr: Arc::new(value)} // P {ptr: Arc::new(value)}
Arc::new(value) Arc::new(value)
} }
......
...@@ -60,7 +60,7 @@ impl CompilerPass for TreeGen { ...@@ -60,7 +60,7 @@ impl CompilerPass for TreeGen {
let expr = entry_value.take_expr(); let expr = entry_value.take_expr();
trace!("{} replaced by {}", ops[index], expr); trace!("{} replaced by {}", ops[index], expr);
ops[index] = TreeNode::new_inst(vm.next_id(), expr); ops[index] = TreeNode::new_inst(expr);
} }
} else { } else {
trace!("{} cant be replaced", ops[index]); trace!("{} cant be replaced", ops[index]);
......
...@@ -79,7 +79,8 @@ pub fn alloc_new() -> VM { ...@@ -79,7 +79,8 @@ pub fn alloc_new() -> VM {
// %a = NEW <@int64_t> // %a = NEW <@int64_t>
let blk_0_a = func_ver.new_ssa(vm.next_id(), type_def_ref_int64.clone()); let blk_0_a = func_ver.new_ssa(vm.next_id(), type_def_ref_int64.clone());
vm.set_name(blk_0_a.as_entity(), "blk_0_a".to_string()); vm.set_name(blk_0_a.as_entity(), "blk_0_a".to_string());
let blk_0_inst0 = func_ver.new_inst(vm.next_id(), Instruction{ let blk_0_inst0 = func_ver.new_inst(Instruction{
hdr: MuEntityHeader::unnamed(vm.next_id()),
value: Some(vec![blk_0_a.clone_value()]), value: Some(vec![blk_0_a.clone_value()]),
ops: RwLock::new(vec![]), ops: RwLock::new(vec![]),
v: Instruction_::New(type_def_int64.clone()) v: Instruction_::New(type_def_int64.clone())
...@@ -88,15 +89,17 @@ pub fn alloc_new() -> VM { ...@@ -88,15 +89,17 @@ pub fn alloc_new() -> VM {
// %a_iref = GETIREF <@int_64> @a // %a_iref = GETIREF <@int_64> @a
let blk_0_a_iref = func_ver.new_ssa(vm.next_id(), type_def_iref_int64.clone()); let blk_0_a_iref = func_ver.new_ssa(vm.next_id(), type_def_iref_int64.clone());
vm.set_name(blk_0_a.as_entity(), "blk_0_a_iref".to_string()); vm.set_name(blk_0_a.as_entity(), "blk_0_a_iref".to_string());
let blk_0_inst1 = func_ver.new_inst(vm.next_id(), Instruction{ let blk_0_inst1 = func_ver.new_inst(Instruction{
hdr: MuEntityHeader::unnamed(vm.next_id()),
value: Some(vec![blk_0_a_iref.clone_value()]), value: Some(vec![blk_0_a_iref.clone_value()]),
ops: RwLock::new(vec![blk_0_a.clone()]), ops: RwLock::new(vec![blk_0_a.clone()]),
v: Instruction_::GetIRef(0) v: Instruction_::GetIRef(0)
}); });
// STORE <@int_64> @a_iref @int_64_1 // STORE <@int_64> @a_iref @int_64_1
let blk_0_const_int64_1 = func_ver.new_constant(vm.next_id(), const_def_int64_1.clone()); let blk_0_const_int64_1 = func_ver.new_constant(const_def_int64_1.clone());
let blk_0_inst2 = func_ver.new_inst(vm.next_id(), Instruction{ let blk_0_inst2 = func_ver.new_inst(Instruction{
hdr: MuEntityHeader::unnamed(vm.next_id()),
value: None, value: None,
ops: RwLock::new(vec![blk_0_a_iref.clone(), blk_0_const_int64_1.clone()]), ops: RwLock::new(vec![blk_0_a_iref.clone(), blk_0_const_int64_1.clone()]),
v: Instruction_::Store{ v: Instruction_::Store{
...@@ -120,7 +123,8 @@ pub fn alloc_new() -> VM { ...@@ -120,7 +123,8 @@ pub fn alloc_new() -> VM {
// } // }
// }); // });
let blk_0_term = func_ver.new_inst(vm.next_id(), Instruction { let blk_0_term = func_ver.new_inst(Instruction {
hdr: MuEntityHeader::unnamed(vm.next_id()),
value: None, value: None,
ops: RwLock::new(vec![]), ops: RwLock::new(vec![]),
v: Instruction_::ThreadExit v: Instruction_::ThreadExit
......
...@@ -104,8 +104,9 @@ fn create_catch_exception_func (vm: &VM) { ...@@ -104,8 +104,9 @@ fn create_catch_exception_func (vm: &VM) {
let blk_normal_cont_id = vm.next_id(); let blk_normal_cont_id = vm.next_id();
let blk_exn_cont_id = vm.next_id(); let blk_exn_cont_id = vm.next_id();
let blk_0_throw = func_ver.new_constant(vm.next_id(), const_funcref_throw_exception.clone()); let blk_0_throw = func_ver.new_constant(const_funcref_throw_exception.clone());
let blk_0_term = func_ver.new_inst(vm.next_id(), Instruction { let blk_0_term = func_ver.new_inst(Instruction {
hdr: MuEntityHeader::unnamed(vm.next_id()),
value: None, value: None,
ops: RwLock::new(vec![blk_0_throw]), ops: RwLock::new(vec![blk_0_throw]),
v: Instruction_::Call { v: Instruction_::Call {
...@@ -138,7 +139,8 @@ fn create_catch_exception_func (vm: &VM) { ...@@ -138,7 +139,8 @@ fn create_catch_exception_func (vm: &VM) {
// %blk_normal_cont(): // %blk_normal_cont():
let mut blk_normal_cont = Block::new(blk_normal_cont_id); let mut blk_normal_cont = Block::new(blk_normal_cont_id);
vm.set_name(blk_normal_cont.as_entity(), Mu("blk_normal_cont")); vm.set_name(blk_normal_cont.as_entity(), Mu("blk_normal_cont"));
let blk_normal_cont_thread_exit = func_ver.new_inst(vm.next_id(), Instruction { let blk_normal_cont_thread_exit = func_ver.new_inst(Instruction {
hdr: MuEntityHeader::unnamed(vm.next_id()),
value: None, value: None,
ops: RwLock::new(vec![]), ops: RwLock::new(vec![]),
v: Instruction_::ThreadExit v: Instruction_::ThreadExit
...@@ -156,7 +158,8 @@ fn create_catch_exception_func (vm: &VM) { ...@@ -156,7 +158,8 @@ fn create_catch_exception_func (vm: &VM) {
let type_ref_int64 = vm.get_type(vm.id_of("ref_int64")); let type_ref_int64 = vm.get_type(vm.id_of("ref_int64"));
let blk_exn_cont_exception_arg = func_ver.new_ssa(vm.next_id(), type_ref_int64.clone()); let blk_exn_cont_exception_arg = func_ver.new_ssa(vm.next_id(), type_ref_int64.clone());
vm.set_name(blk_exn_cont_exception_arg.as_entity(), Mu("blk_0_exception_arg")); vm.set_name(blk_exn_cont_exception_arg.as_entity(), Mu("blk_0_exception_arg"));
let blk_exn_cont_thread_exit = func_ver.new_inst(vm.next_id(), Instruction { let blk_exn_cont_thread_exit = func_ver.new_inst(Instruction {
hdr: MuEntityHeader::unnamed(vm.next_id()),
value: None, value: None,
ops: RwLock::new(vec![]), ops: RwLock::new(vec![]),
v: Instruction_::ThreadExit v: Instruction_::ThreadExit
...@@ -206,25 +209,28 @@ fn create_throw_exception_func (vm: &VM) { ...@@ -206,25 +209,28 @@ fn create_throw_exception_func (vm: &VM) {
// %exception_obj = NEW <@int64> // %exception_obj = NEW <@int64>
let blk_0_exception_obj = func_ver.new_ssa(vm.next_id(), type_ref_int64.clone()); let blk_0_exception_obj = func_ver.new_ssa(vm.next_id(), type_ref_int64.clone());
vm.set_name(blk_0_exception_obj.as_entity(), Mu("blk_0_exception_obj")); vm.set_name(blk_0_exception_obj.as_entity(), Mu("blk_0_exception_obj"));
let blk_0_inst0 = func_ver.new_inst(vm.next_id(), Instruction { let blk_0_inst0 = func_ver.new_inst(Instruction {
value: Some(vec![blk_0_exception_obj.clone_value()]), hdr: MuEntityHeader::unnamed(vm.next_id()),
ops: RwLock::new(vec![]), value: Some(vec![blk_0_exception_obj.clone_value()]),
v: Instruction_::New(type_ref_int64.clone()) ops: RwLock::new(vec![]),
v: Instruction_::New(type_ref_int64.clone())
}); });
// %exception_obj_iref = GETIREF <@int64> %exception_obj // %exception_obj_iref = GETIREF <@int64> %exception_obj
let blk_0_exception_obj_iref = func_ver.new_ssa(vm.next_id(), type_iref_int64.clone()); let blk_0_exception_obj_iref = func_ver.new_ssa(vm.next_id(), type_iref_int64.clone());
vm.set_name(blk_0_exception_obj_iref.as_entity(), Mu("blk_0_exception_obj_iref")); vm.set_name(blk_0_exception_obj_iref.as_entity(), Mu("blk_0_exception_obj_iref"));
let blk_0_inst1 = func_ver.new_inst(vm.next_id(), Instruction { let blk_0_inst1 = func_ver.new_inst(Instruction {
value: Some(vec![blk_0_exception_obj_iref.clone_value()]), hdr: MuEntityHeader::unnamed(vm.next_id()),
ops: RwLock::new(vec![blk_0_exception_obj.clone()]), value: Some(vec![blk_0_exception_obj_iref.clone_value()]),
v: Instruction_::GetIRef(0) ops: RwLock::new(vec![blk_0_exception_obj.clone()]),
v: Instruction_::GetIRef(0)
}); });
// STORE <@int64> %exception_obj_iref @int64_1 // STORE <@int64> %exception_obj_iref @int64_1
let const_int64_1 = vm.get_const(vm.id_of("int64_1")); let const_int64_1 = vm.get_const(vm.id_of("int64_1"));
let blk_0_const_int64_1 = func_ver.new_constant(vm.next_id(), const_int64_1); let blk_0_const_int64_1 = func_ver.new_constant(const_int64_1);
let blk_0_inst2 = func_ver.new_inst(vm.next_id(), Instruction { let blk_0_inst2 = func_ver.new_inst(Instruction {
hdr: MuEntityHeader::unnamed(vm.next_id()),
value: None, value: None,
ops: RwLock::new(vec![blk_0_exception_obj_iref.clone(), blk_0_const_int64_1.clone()]), ops: RwLock::new(vec![blk_0_exception_obj_iref.clone(), blk_0_const_int64_1.clone()]),
v: Instruction_::Store { v: Instruction_::Store {
...@@ -235,7 +241,8 @@ fn create_throw_exception_func (vm: &VM) { ...@@ -235,7 +241,8 @@ fn create_throw_exception_func (vm: &VM) {
} }
}); });
let blk_0_term = func_ver.new_inst(vm.next_id(), Instruction { let blk_0_term = func_ver.new_inst(Instruction {
hdr: MuEntityHeader::unnamed(vm.next_id()),
value: None, value: None,
ops: RwLock::new(vec![blk_0_exception_obj.clone()]), ops: RwLock::new(vec![blk_0_exception_obj.clone()]),
v: Instruction_::Throw(0) v: Instruction_::Throw(0)
......
...@@ -123,7 +123,7 @@ fn create_spill1() -> VM { ...@@ -123,7 +123,7 @@ fn create_spill1() -> VM {
vm.set_name(blk_entry.as_entity(), Mu("entry")); vm.set_name(blk_entry.as_entity(), Mu("entry"));
// callee // callee
let blk_entry_spill1_funcref = func_ver.new_constant(vm.next_id(), const_func_spill1.clone()); let blk_entry_spill1_funcref = func_ver.new_constant(const_func_spill1.clone());
// args // args
let blk_entry_t1 = func_ver.new_ssa(vm.next_id(), type_def_int64.clone()); let blk_entry_t1 = func_ver.new_ssa(vm.next_id(), type_def_int64.clone());
vm.set_name(blk_entry_t1.as_entity(), Mu("blk_entry_t1")); vm.set_name(blk_entry_t1.as_entity(), Mu("blk_entry_t1"));
...@@ -148,7 +148,8 @@ fn create_spill1() -> VM { ...@@ -148,7 +148,8 @@ fn create_spill1() -> VM {
// %x = CALL spill1(%t1, %t2, ... t10) // %x = CALL spill1(%t1, %t2, ... t10)
let blk_entry_x = func_ver.new_ssa(vm.next_id(), type_def_int64.clone()); let blk_entry_x = func_ver.new_ssa(vm.next_id(), type_def_int64.clone());
let blk_entry_call = func_ver.new_inst(vm.next_id(), Instruction{ let blk_entry_call = func_ver.new_inst(Instruction{
hdr: MuEntityHeader::unnamed(vm.next_id()),
value: Some(vec![blk_entry_x.clone_value()]), value: Some(vec![blk_entry_x.clone_value()]),
ops: RwLock::new(vec![ ops: RwLock::new(vec![
blk_entry_spill1_funcref, blk_entry_spill1_funcref,
...@@ -176,7 +177,8 @@ fn create_spill1() -> VM { ...@@ -176,7 +177,8 @@ fn create_spill1() -> VM {
// %res0 = ADD %t1 %t2 // %res0 = ADD %t1 %t2
let blk_entry_res0 = func_ver.new_ssa(vm.next_id(), type_def_int64.clone()); let blk_entry_res0 = func_ver.new_ssa(vm.next_id(), type_def_int64.clone());
vm.set_name(blk_entry_res0.as_entity(), Mu("blk_entry_res0")); vm.set_name(blk_entry_res0.as_entity(), Mu("blk_entry_res0"));
let blk_entry_add0 = func_ver.new_inst(vm.next_id(), Instruction { let blk_entry_add0 = func_ver.new_inst(Instruction {
hdr: MuEntityHeader::unnamed(vm.next_id()),
value: Some(vec![blk_entry_res0.clone_value()]), value: Some(vec![blk_entry_res0.clone_value()]),
ops: RwLock::new(vec![blk_entry_t1.clone(), blk_entry_t2.clone()]), ops: RwLock::new(vec![blk_entry_t1.clone(), blk_entry_t2.clone()]),
v: Instruction_::BinOp(BinOp::Add, 0, 1) v: Instruction_::BinOp(BinOp::Add, 0, 1)
...@@ -185,7 +187,8 @@ fn create_spill1() -> VM { ...@@ -185,7 +187,8 @@ fn create_spill1() -> VM {
// %res1 = ADD %res0 %t3 // %res1 = ADD %res0 %t3
let blk_entry_res1 = func_ver.new_ssa(vm.next_id(), type_def_int64.clone()); let blk_entry_res1 = func_ver.new_ssa(vm.next_id(), type_def_int64.clone());
vm.set_name(blk_entry_res1.as_entity(), Mu("blk_entry_res1")); vm.set_name(blk_entry_res1.as_entity(), Mu("blk_entry_res1"));
let blk_entry_add1 = func_ver.new_inst(vm.next_id(), Instruction { let blk_entry_add1 = func_ver.new_inst(Instruction {
hdr: MuEntityHeader::unnamed(vm.next_id()),
value: Some(vec![blk_entry_res1.clone_value()]), value: Some(vec![blk_entry_res1.clone_value()]),
ops: RwLock::new(vec![blk_entry_res0.clone(), blk_entry_t3.clone()]), ops: RwLock::new(vec![blk_entry_res0.clone(), blk_entry_t3.clone()]),
v: Instruction_::BinOp(BinOp::Add, 0, 1) v: Instruction_::BinOp(BinOp::Add, 0, 1)
...@@ -194,7 +197,8 @@ fn create_spill1() -> VM { ...@@ -194,7 +197,8 @@ fn create_spill1() -> VM {
// %res2 = ADD %res1 %t4 // %res2 = ADD %res1 %t4
let blk_entry_res2 = func_ver.new_ssa(vm.next_id(), type_def_int64.clone()); let blk_entry_res2 = func_ver.new_ssa(vm.next_id(), type_def_int64.clone());
vm.set_name(blk_entry_res2.as_entity(), Mu("blk_entry_res2")); vm.set_name(blk_entry_res2.as_entity(), Mu("blk_entry_res2"));
let blk_entry_add2 = func_ver.new_inst(vm.next_id(), Instruction { let blk_entry_add2 = func_ver.new_inst(Instruction {
hdr: MuEntityHeader::unnamed(vm.next_id()),
value: Some(vec![blk_entry_res2.clone_value()]), value: Some(vec![blk_entry_res2.clone_value()]),
ops: RwLock::new(vec![blk_entry_res1.clone(), blk_entry_t4.clone()]), ops: RwLock::new(vec![blk_entry_res1.clone(), blk_entry_t4.clone()]),
v: Instruction_::BinOp(BinOp::Add, 0, 1) v: Instruction_::BinOp(BinOp::Add, 0, 1)
...@@ -203,14 +207,16 @@ fn create_spill1() -> VM { ...@@ -203,14 +207,16 @@ fn create_spill1() -> VM {
// %res3 = ADD %res2 %t5 // %res3 = ADD %res2 %t5
let blk_entry_res3 = func_ver.new_ssa(vm.next_id(), type_def_int64.clone()); let blk_entry_res3 = func_ver.new_ssa(vm.next_id(), type_def_int64.clone());
vm.set_name(blk_entry_res3.as_entity(), Mu("blk_entry_res3")); vm.set_name(blk_entry_res3.as_entity(), Mu("blk_entry_res3"));
let blk_entry_add3 = func_ver.new_inst(vm.next_id(), Instruction { let blk_entry_add3 = func_ver.new_inst(Instruction {
hdr: MuEntityHeader::unnamed(vm.next_id()),
value: Some(vec![blk_entry_res3.clone_value()]), value: Some(vec![blk_entry_res3.clone_value()]),
ops: RwLock::new(vec![blk_entry_res2.clone(), blk_entry_t5.clone()]), ops: RwLock::new(vec![blk_entry_res2.clone(), blk_entry_t5.clone()]),
v: Instruction_::BinOp(BinOp::Add, 0, 1) v: Instruction_::BinOp(BinOp::Add, 0, 1)
}); });
// RET %res3 // RET %res3
let blk_entry_ret = func_ver.new_inst(vm.next_id(), Instruction{ let blk_entry_ret = func_ver.new_inst(Instruction{
hdr: MuEntityHeader::unnamed(vm.next_id()),
value: None, value: None,
ops: RwLock::new(vec![blk_entry_res3.clone()]), ops: RwLock::new(vec![blk_entry_res3.clone()]),
v: Instruction_::Return(vec![0]) v: Instruction_::Return(vec![0])
......
...@@ -55,7 +55,8 @@ fn primordial_main() -> VM { ...@@ -55,7 +55,8 @@ fn primordial_main() -> VM {
let mut blk_entry = Block::new(vm.next_id()); let mut blk_entry = Block::new(vm.next_id());
vm.set_name(blk_entry.as_entity(), "entry".to_string()); vm.set_name(blk_entry.as_entity(), "entry".to_string());
let thread_exit = func_ver.new_inst(vm.next_id(), Instruction { let thread_exit = func_ver.new_inst(Instruction {
hdr: MuEntityHeader::unnamed(vm.next_id()),
value: None, value: None,
ops: RwLock::new(vec![]), ops: RwLock::new(vec![]),
v: Instruction_::ThreadExit v: Instruction_::ThreadExit
......
...@@ -51,13 +51,14 @@ pub fn sum() -> VM { ...@@ -51,13 +51,14 @@ pub fn sum() -> VM {
let blk_entry_n = func_ver.new_ssa(vm.next_id(), type_def_int64.clone()); let blk_entry_n = func_ver.new_ssa(vm.next_id(), type_def_int64.clone());
vm.set_name(blk_entry_n.as_entity(), "blk_entry_n".to_string()); vm.set_name(blk_entry_n.as_entity(), "blk_entry_n".to_string());
let const_def_int64_0_local = func_ver.new_constant(vm.next_id(), const_def_int64_0.clone()); // FIXME: why we need a local version? let const_def_int64_0_local = func_ver.new_constant(const_def_int64_0.clone()); // FIXME: why we need a local version?
let const_def_int64_1_local = func_ver.new_constant(vm.next_id(), const_def_int64_1.clone()); let const_def_int64_1_local = func_ver.new_constant(const_def_int64_1.clone());
// BRANCH %head // BRANCH %head
let mut blk_head = Block::new(vm.next_id()); let mut blk_head = Block::new(vm.next_id());
vm.set_name(blk_head.as_entity(), "head".to_string()); vm.set_name(blk_head.as_entity(), "head".to_string());
let blk_entry_term = func_ver.new_inst(vm.next_id(), Instruction { let blk_entry_term = func_ver.new_inst(Instruction {
hdr: MuEntityHeader::unnamed(vm.next_id()),
value: None, value: None,
ops: RwLock::new(vec![blk_entry_n.clone(), const_def_int64_0_local.clone(), const_def_int64_0_local.clone()]), ops: RwLock::new(vec![blk_entry_n.clone(), const_def_int64_0_local.clone(), const_def_int64_0_local.clone()]),
v: Instruction_::Branch1(Destination{ v: Instruction_::Branch1(Destination{
...@@ -86,7 +87,8 @@ pub fn sum() -> VM { ...@@ -86,7 +87,8 @@ pub fn sum() -> VM {
// %s2 = ADD %s %i // %s2 = ADD %s %i
let blk_head_s2 = func_ver.new_ssa(vm.next_id(), type_def_int64.clone()); let blk_head_s2 = func_ver.new_ssa(vm.next_id(), type_def_int64.clone());
vm.set_name(blk_head_s2.as_entity(), "blk_head_s2".to_string()); vm.set_name(blk_head_s2.as_entity(), "blk_head_s2".to_string());
let blk_head_inst0 = func_ver.new_inst(vm.next_id(), Instruction { let blk_head_inst0 = func_ver.new_inst(Instruction {
hdr: MuEntityHeader::unnamed(vm.next_id()),
value: Some(vec![blk_head_s2.clone_value()]), value: Some(vec![blk_head_s2.clone_value()]),
ops: RwLock::new(vec![blk_head_s.clone(), blk_head_i.clone()]), ops: RwLock::new(vec![blk_head_s.clone(), blk_head_i.clone()]),
v: Instruction_::BinOp(BinOp::Add, 0, 1) v: Instruction_::BinOp(BinOp::Add, 0, 1)
...@@ -95,7 +97,8 @@ pub fn sum() -> VM { ...@@ -95,7 +97,8 @@ pub fn sum() -> VM {
// %i2 = ADD %i 1 // %i2 = ADD %i 1
let blk_head_i2 = func_ver.new_ssa(vm.next_id(), type_def_int64.clone()); let blk_head_i2 = func_ver.new_ssa(vm.next_id(), type_def_int64.clone());
vm.set_name(blk_head_i2.as_entity(), "blk_head_i2".to_string());