Commit 99351616 authored by qinsoon's avatar qinsoon

replace use of HashMap/Set with LinkedHashMap/Set

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