Commit 99351616 authored by qinsoon's avatar qinsoon

replace use of HashMap/Set with LinkedHashMap/Set

parent e87ea8ce
...@@ -2,20 +2,20 @@ use ir::*; ...@@ -2,20 +2,20 @@ use ir::*;
use ptr::*; use ptr::*;
use types::*; use types::*;
use std::collections::HashMap; use utils::LinkedHashMap;
pub struct MuBundle { pub struct MuBundle {
pub id: MuID, pub id: MuID,
pub type_defs: HashMap<MuID, P<MuType>>, pub type_defs: LinkedHashMap<MuID, P<MuType>>,
pub func_sigs: HashMap<MuID, P<MuFuncSig>>, pub func_sigs: LinkedHashMap<MuID, P<MuFuncSig>>,
pub constants: HashMap<MuID, P<Value>>, pub constants: LinkedHashMap<MuID, P<Value>>,
pub globals : HashMap<MuID, P<Value>>, pub globals : LinkedHashMap<MuID, P<Value>>,
pub func_defs: HashMap<MuID, MuFunction>, pub func_defs: LinkedHashMap<MuID, MuFunction>,
pub func_decls: HashMap<MuID, MuFunctionVersion>, pub func_decls: LinkedHashMap<MuID, MuFunctionVersion>,
// id_name_map: HashMap<MuID, MuName>, // id_name_map: LinkedHashMap<MuID, MuName>,
// name_id_map: HashMap<MuName, MuID> // name_id_map: LinkedHashMap<MuName, MuID>
} }
impl MuBundle { impl MuBundle {
...@@ -23,15 +23,15 @@ impl MuBundle { ...@@ -23,15 +23,15 @@ impl MuBundle {
MuBundle { MuBundle {
id: id, id: id,
type_defs: HashMap::new(), type_defs: LinkedHashMap::new(),
func_sigs: HashMap::new(), func_sigs: LinkedHashMap::new(),
constants: HashMap::new(), constants: LinkedHashMap::new(),
globals: HashMap::new(), globals: LinkedHashMap::new(),
func_defs: HashMap::new(), func_defs: LinkedHashMap::new(),
func_decls: HashMap::new(), func_decls: LinkedHashMap::new(),
// id_name_map: HashMap::new(), // id_name_map: LinkedHashMap::new(),
// name_id_map: HashMap::new() // name_id_map: LinkedHashMap::new()
} }
} }
} }
\ No newline at end of file
...@@ -6,7 +6,6 @@ use op::*; ...@@ -6,7 +6,6 @@ use op::*;
use utils::vec_utils; use utils::vec_utils;
use utils::LinkedHashMap; use utils::LinkedHashMap;
use std::collections::HashMap;
use std::fmt; use std::fmt;
use std::default; use std::default;
use std::sync::RwLock; use std::sync::RwLock;
...@@ -231,8 +230,8 @@ impl MuFunctionVersion { ...@@ -231,8 +230,8 @@ impl MuFunctionVersion {
} }
/// get Map(CallSiteID -> FuncID) that are called by this function /// get Map(CallSiteID -> FuncID) that are called by this function
pub fn get_static_call_edges(&self) -> HashMap<MuID, MuID> { pub fn get_static_call_edges(&self) -> LinkedHashMap<MuID, MuID> {
let mut ret = HashMap::new(); let mut ret = LinkedHashMap::new();
let f_content = self.content.as_ref().unwrap(); let f_content = self.content.as_ref().unwrap();
...@@ -366,13 +365,13 @@ impl FunctionContent { ...@@ -366,13 +365,13 @@ impl FunctionContent {
#[derive(Default, Debug, RustcEncodable, RustcDecodable)] #[derive(Default, Debug, RustcEncodable, RustcDecodable)]
pub struct FunctionContext { pub struct FunctionContext {
pub values: HashMap<MuID, SSAVarEntry> pub values: LinkedHashMap<MuID, SSAVarEntry>
} }
impl FunctionContext { impl FunctionContext {
fn new() -> FunctionContext { fn new() -> FunctionContext {
FunctionContext { FunctionContext {
values: HashMap::new() values: LinkedHashMap::new()
} }
} }
......
...@@ -5,7 +5,7 @@ use utils::POINTER_SIZE; ...@@ -5,7 +5,7 @@ use utils::POINTER_SIZE;
use utils::vec_utils; use utils::vec_utils;
use std::fmt; use std::fmt;
use std::collections::HashMap; use utils::LinkedHashMap;
use std::sync::RwLock; use std::sync::RwLock;
lazy_static! { lazy_static! {
...@@ -264,9 +264,9 @@ impl fmt::Display for MuType_ { ...@@ -264,9 +264,9 @@ impl fmt::Display for MuType_ {
lazy_static! { lazy_static! {
/// storing a map from MuName to StructType_ /// storing a map from MuName to StructType_
pub static ref STRUCT_TAG_MAP : RwLock<HashMap<StructTag, StructType_>> = RwLock::new(HashMap::new()); pub static ref STRUCT_TAG_MAP : RwLock<LinkedHashMap<StructTag, StructType_>> = RwLock::new(LinkedHashMap::new());
/// storing a map from MuName to HybridType_ /// storing a map from MuName to HybridType_
pub static ref HYBRID_TAG_MAP : RwLock<HashMap<HybridTag, HybridType_>> = RwLock::new(HashMap::new()); pub static ref HYBRID_TAG_MAP : RwLock<LinkedHashMap<HybridTag, HybridType_>> = RwLock::new(LinkedHashMap::new());
} }
#[derive(PartialEq, Debug, RustcEncodable, RustcDecodable)] #[derive(PartialEq, Debug, RustcEncodable, RustcDecodable)]
......
...@@ -21,7 +21,6 @@ use ast::ptr::P; ...@@ -21,7 +21,6 @@ use ast::ptr::P;
use ast::ir::*; use ast::ir::*;
use ast::types::*; use ast::types::*;
use std::collections::HashMap;
use std::str; use std::str;
use std::usize; use std::usize;
use std::slice::Iter; use std::slice::Iter;
...@@ -110,8 +109,8 @@ impl ASMCode { ...@@ -110,8 +109,8 @@ impl ASMCode {
fn rewrite_insert( fn rewrite_insert(
&self, &self,
insert_before: HashMap<usize, Vec<Box<ASMCode>>>, insert_before: LinkedHashMap<usize, Vec<Box<ASMCode>>>,
insert_after: HashMap<usize, Vec<Box<ASMCode>>>) -> Box<ASMCode> insert_after: LinkedHashMap<usize, Vec<Box<ASMCode>>>) -> Box<ASMCode>
{ {
trace!("insert spilling code"); trace!("insert spilling code");
let mut ret = ASMCode { let mut ret = ASMCode {
...@@ -127,7 +126,7 @@ impl ASMCode { ...@@ -127,7 +126,7 @@ impl ASMCode {
// inst N in old machine code is N' in new machine code // inst N in old machine code is N' in new machine code
// this map stores the relationship // this map stores the relationship
let mut location_map : HashMap<usize, usize> = HashMap::new(); let mut location_map : LinkedHashMap<usize, usize> = LinkedHashMap::new();
for i in 0..self.number_of_insts() { for i in 0..self.number_of_insts() {
trace!("Inst{}", i); trace!("Inst{}", i);
...@@ -3081,6 +3080,7 @@ fn write_const_value(f: &mut File, constant: P<Value>) { ...@@ -3081,6 +3080,7 @@ fn write_const_value(f: &mut File, constant: P<Value>) {
} }
} }
use std::collections::HashMap;
pub fn emit_context_with_reloc(vm: &VM, pub fn emit_context_with_reloc(vm: &VM,
symbols: HashMap<Address, String>, symbols: HashMap<Address, String>,
fields : HashMap<Address, String>) { fields : HashMap<Address, String>) {
...@@ -3281,7 +3281,7 @@ pub fn pic_symbol(name: String) -> String { ...@@ -3281,7 +3281,7 @@ pub fn pic_symbol(name: String) -> String {
use compiler::machine_code::CompiledFunction; use compiler::machine_code::CompiledFunction;
pub fn spill_rewrite( pub fn spill_rewrite(
spills: &HashMap<MuID, P<Value>>, spills: &LinkedHashMap<MuID, P<Value>>,
func: &mut MuFunctionVersion, func: &mut MuFunctionVersion,
cf: &mut CompiledFunction, cf: &mut CompiledFunction,
vm: &VM) -> Vec<P<Value>> vm: &VM) -> Vec<P<Value>>
...@@ -3294,11 +3294,11 @@ pub fn spill_rewrite( ...@@ -3294,11 +3294,11 @@ pub fn spill_rewrite(
let mut new_nodes = vec![]; let mut new_nodes = vec![];
// record code and their insertion point, so we can do the copy/insertion all at once // record code and their insertion point, so we can do the copy/insertion all at once
let mut spill_code_before: HashMap<usize, Vec<Box<ASMCode>>> = HashMap::new(); let mut spill_code_before: LinkedHashMap<usize, Vec<Box<ASMCode>>> = LinkedHashMap::new();
let mut spill_code_after: HashMap<usize, Vec<Box<ASMCode>>> = HashMap::new(); let mut spill_code_after: LinkedHashMap<usize, Vec<Box<ASMCode>>> = LinkedHashMap::new();
// map from old to new // map from old to new
let mut temp_for_cur_inst : HashMap<MuID, P<Value>> = HashMap::new(); let mut temp_for_cur_inst : LinkedHashMap<MuID, P<Value>> = LinkedHashMap::new();
// iterate through all instructions // iterate through all instructions
for i in 0..cf.mc().number_of_insts() { for i in 0..cf.mc().number_of_insts() {
......
...@@ -10,7 +10,6 @@ use vm::VM; ...@@ -10,7 +10,6 @@ use vm::VM;
use utils::vec_utils; use utils::vec_utils;
use utils::LinkedHashSet; use utils::LinkedHashSet;
use utils::LinkedHashMap; use utils::LinkedHashMap;
use std::collections::HashMap;
use std::cell::RefCell; use std::cell::RefCell;
...@@ -189,7 +188,7 @@ impl <'a> GraphColoring<'a> { ...@@ -189,7 +188,7 @@ impl <'a> GraphColoring<'a> {
trace!("coalescing enabled, build move list"); trace!("coalescing enabled, build move list");
let ref ig = self.ig; let ref ig = self.ig;
let ref mut movelist = self.movelist; let ref mut movelist = self.movelist;
for m in ig.moves() { for m in ig.moves().iter() {
trace!("add to movelist: {:?}", m); trace!("add to movelist: {:?}", m);
self.worklist_moves.push(m.clone()); self.worklist_moves.push(m.clone());
GraphColoring::movelist_mut(movelist, m.from).borrow_mut().push(m.clone()); GraphColoring::movelist_mut(movelist, m.from).borrow_mut().push(m.clone());
...@@ -655,7 +654,7 @@ impl <'a> GraphColoring<'a> { ...@@ -655,7 +654,7 @@ impl <'a> GraphColoring<'a> {
fn rewrite_program(&mut self) { fn rewrite_program(&mut self) {
let spills = self.spills(); let spills = self.spills();
let mut spilled_mem = HashMap::new(); let mut spilled_mem = LinkedHashMap::new();
// allocating frame slots for every spilled temp // allocating frame slots for every spilled temp
for reg_id in spills.iter() { for reg_id in spills.iter() {
......
...@@ -4,8 +4,7 @@ use compiler::machine_code::CompiledFunction; ...@@ -4,8 +4,7 @@ use compiler::machine_code::CompiledFunction;
use ast::ir::*; use ast::ir::*;
use compiler::backend; use compiler::backend;
use utils::LinkedHashSet; use utils::LinkedHashSet;
use utils::LinkedHashMap;
use std::collections::{HashMap, HashSet};
use compiler::backend::reg_alloc::graph_coloring::petgraph; use compiler::backend::reg_alloc::graph_coloring::petgraph;
use compiler::backend::reg_alloc::graph_coloring::petgraph::Graph; use compiler::backend::reg_alloc::graph_coloring::petgraph::Graph;
...@@ -24,16 +23,16 @@ pub struct Move{pub from: NodeIndex, pub to: NodeIndex} ...@@ -24,16 +23,16 @@ pub struct Move{pub from: NodeIndex, pub to: NodeIndex}
pub struct InterferenceGraph { pub struct InterferenceGraph {
graph: Graph<GraphNode, (), petgraph::Undirected>, graph: Graph<GraphNode, (), petgraph::Undirected>,
nodes: HashMap<MuID, NodeIndex>, nodes: LinkedHashMap<MuID, NodeIndex>,
moves: HashSet<Move>, moves: LinkedHashSet<Move>,
} }
impl InterferenceGraph { impl InterferenceGraph {
fn new() -> InterferenceGraph { fn new() -> InterferenceGraph {
InterferenceGraph { InterferenceGraph {
graph: Graph::new_undirected(), graph: Graph::new_undirected(),
nodes: HashMap::new(), nodes: LinkedHashMap::new(),
moves: HashSet::new() moves: LinkedHashSet::new()
} }
} }
...@@ -85,7 +84,7 @@ impl InterferenceGraph { ...@@ -85,7 +84,7 @@ impl InterferenceGraph {
ret ret
} }
pub fn moves(&self) -> &HashSet<Move> { pub fn moves(&self) -> &LinkedHashSet<Move> {
&self.moves &self.moves
} }
...@@ -255,17 +254,17 @@ struct CFGBlockNode { ...@@ -255,17 +254,17 @@ struct CFGBlockNode {
defs: Vec<MuID> defs: Vec<MuID>
} }
fn local_liveness_analysis (cf: &mut CompiledFunction) -> HashMap<String, CFGBlockNode> { fn local_liveness_analysis (cf: &mut CompiledFunction) -> LinkedHashMap<String, CFGBlockNode> {
info!("---local liveness analysis---"); info!("---local liveness analysis---");
let mc = cf.mc(); let mc = cf.mc();
let mut ret = hashmap!{}; let mut ret = LinkedHashMap::new();
let all_blocks = mc.get_all_blocks(); let all_blocks = mc.get_all_blocks();
// create maps (start_inst -> name) and (end_inst -> name) // create maps (start_inst -> name) and (end_inst -> name)
let mut start_inst_map : HashMap<usize, &str> = hashmap!{}; let mut start_inst_map : LinkedHashMap<usize, &str> = LinkedHashMap::new();
let mut end_inst_map : HashMap<usize, &str> = hashmap!{}; let mut end_inst_map : LinkedHashMap<usize, &str> = LinkedHashMap::new();
for block in all_blocks.iter() { for block in all_blocks.iter() {
let range = match mc.get_block_range(block) { let range = match mc.get_block_range(block) {
Some(range) => range, Some(range) => range,
...@@ -286,7 +285,7 @@ fn local_liveness_analysis (cf: &mut CompiledFunction) -> HashMap<String, CFGBlo ...@@ -286,7 +285,7 @@ fn local_liveness_analysis (cf: &mut CompiledFunction) -> HashMap<String, CFGBlo
let end = range.end; let end = range.end;
let mut livein = vec![]; let mut livein = vec![];
let mut all_defined : HashSet<MuID> = HashSet::new(); let mut all_defined : LinkedHashSet<MuID> = LinkedHashSet::new();
for i in start_inst..end { for i in start_inst..end {
let reg_uses = mc.get_inst_reg_uses(i); let reg_uses = mc.get_inst_reg_uses(i);
...@@ -304,7 +303,7 @@ fn local_liveness_analysis (cf: &mut CompiledFunction) -> HashMap<String, CFGBlo ...@@ -304,7 +303,7 @@ fn local_liveness_analysis (cf: &mut CompiledFunction) -> HashMap<String, CFGBlo
} }
} }
let defs : Vec<MuID> = all_defined.into_iter().collect(); let defs : Vec<MuID> = all_defined.iter().map(|x| *x).collect();
let preds : Vec<String> = { let preds : Vec<String> = {
let mut ret = vec![]; let mut ret = vec![];
...@@ -353,12 +352,12 @@ fn local_liveness_analysis (cf: &mut CompiledFunction) -> HashMap<String, CFGBlo ...@@ -353,12 +352,12 @@ fn local_liveness_analysis (cf: &mut CompiledFunction) -> HashMap<String, CFGBlo
ret ret
} }
//fn topological_sort_cfg(entry: String, cfg: HashMap<String, CFGBlockNode>) -> Vec<CFGBlockNode> { //fn topological_sort_cfg(entry: String, cfg: LinkedHashMap<String, CFGBlockNode>) -> Vec<CFGBlockNode> {
// let mut ret = vec![]; // let mut ret = vec![];
// // for all nodes i // // for all nodes i
// // mark[i] <- false // // mark[i] <- false
// let mut mark = { // let mut mark = {
// let mut ret = hashmap!{}; // let mut ret = LinkedHashMap::new();
// for str in cfg.keys() { // for str in cfg.keys() {
// ret.insert(str.clone(), false); // ret.insert(str.clone(), false);
// } // }
...@@ -374,7 +373,7 @@ fn local_liveness_analysis (cf: &mut CompiledFunction) -> HashMap<String, CFGBlo ...@@ -374,7 +373,7 @@ fn local_liveness_analysis (cf: &mut CompiledFunction) -> HashMap<String, CFGBlo
// ret // ret
//} //}
// //
//fn dfs(node: String, cfg: &HashMap<String, CFGBlockNode>, mark: &mut HashMap<String, bool>, sorted: &mut Vec<CFGBlockNode>) { //fn dfs(node: String, cfg: &LinkedHashMap<String, CFGBlockNode>, mark: &mut LinkedHashMap<String, bool>, sorted: &mut Vec<CFGBlockNode>) {
// // if mark[i] = false // // if mark[i] = false
// if !mark.get(&node).unwrap() { // if !mark.get(&node).unwrap() {
// mark.insert(node.clone(), true); // mark.insert(node.clone(), true);
...@@ -388,20 +387,20 @@ fn local_liveness_analysis (cf: &mut CompiledFunction) -> HashMap<String, CFGBlo ...@@ -388,20 +387,20 @@ fn local_liveness_analysis (cf: &mut CompiledFunction) -> HashMap<String, CFGBlo
// } // }
//} //}
fn global_liveness_analysis(blocks: HashMap<String, CFGBlockNode>, cf: &mut CompiledFunction, func: &MuFunctionVersion) { fn global_liveness_analysis(blocks: LinkedHashMap<String, CFGBlockNode>, cf: &mut CompiledFunction, func: &MuFunctionVersion) {
info!("---global liveness analysis---"); info!("---global liveness analysis---");
info!("{} blocks", blocks.len()); info!("{} blocks", blocks.len());
// init live in and live out // init live in and live out
let mut livein : HashMap<String, LinkedHashSet<MuID>> = { let mut livein : LinkedHashMap<String, LinkedHashSet<MuID>> = {
let mut ret = hashmap!{}; let mut ret = LinkedHashMap::new();
for name in blocks.keys() { for name in blocks.keys() {
ret.insert(name.clone(), LinkedHashSet::new()); ret.insert(name.clone(), LinkedHashSet::new());
} }
ret ret
}; };
let mut liveout : HashMap<String, LinkedHashSet<MuID>> = { let mut liveout : LinkedHashMap<String, LinkedHashSet<MuID>> = {
let mut ret = hashmap!{}; let mut ret = LinkedHashMap::new();
for name in blocks.keys() { for name in blocks.keys() {
ret.insert(name.clone(), LinkedHashSet::new()); ret.insert(name.clone(), LinkedHashSet::new());
} }
......
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