Commit 1e9ba3bd authored by XMky's avatar XMky
Browse files

doxygen a1-a7

Showing with 80 additions and 67 deletions
+80 -67
......@@ -393,7 +393,7 @@ impl Func {
let alloc_stat = allocator.alloc(self);
// TODO
simulate_assign::Simulator::simulate(&self, &alloc_stat);
// simulate_assign::Simulator::simulate(&self, &alloc_stat);
self.reg_alloc_info = alloc_stat;
self.context.as_mut().set_reg_map(&self.reg_alloc_info.dstr);
......
......@@ -98,10 +98,21 @@ impl Regalloc for Allocator {
}
};
let mut remove_spillings=|bb:ObjPtr<BB>| {
// let mut livenow=HashSet::new();
// let mut used=HashSet::new();
// for inst in bb.insts.iter() {
// }
};
for bb in func.blocks.iter() {
count(*bb);
}
let (func_stack,bbstacks)=regalloc::easy_ls_alloc::Allocator::countStackSize(func,&spillings);
let (func_stack,bbstacks)=regalloc::regalloc::countStackSize(func,&spillings);
log_file!(calout,"\n\n{} final:\n",func.label);
log_file!(calout,"dstr:{:?}\nspillings:{:?}",dstr ,spillings);
......
......@@ -474,9 +474,7 @@ impl Regalloc for Allocator {
self.spill();
}
let (spillings, dstr) = self.alloc_register();
let (func_stack_size, bb_sizes) =
crate::backend::regalloc::easy_ls_alloc::Allocator
::countStackSize(func, &spillings);
let (func_stack_size, bb_sizes) =regalloc::countStackSize(func, &spillings);
//println!("dstr:{:?}",self.dstr);
//println!("spillings:{:?}",self.spillings);
......
......@@ -13,6 +13,8 @@ use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use super::regalloc;
// 摆烂的深度优先指令编码简单实现的线性扫描寄存器分配
pub struct Allocator {
depths: HashMap<ObjPtr<BB>, usize>,
......@@ -158,58 +160,7 @@ impl Allocator {
out
}
pub fn countStackSize(
func: &Func,
spillings: &HashSet<i32>,
) -> (usize, HashMap<ObjPtr<BB>, usize>) {
// 遍历所有块,找到每个块中的spillings大小,返回其中大小的最大值,
let mut stackSize: usize = 0;
let mut bb_stack_sizes: HashMap<ObjPtr<BB>, usize> = HashMap::new();
let mut passed: HashSet<ObjPtr<BB>> = HashSet::new();
let mut walk: VecDeque<ObjPtr<BB>> = VecDeque::new();
walk.push_back(func.entry.unwrap().clone());
passed.insert(func.entry.unwrap());
// TOTEST
while !walk.is_empty() {
let cur = walk.pop_front().unwrap();
let mut bbspillings: HashSet<i32> = HashSet::new();
//println!("{}",cur.label);
for reg in &cur.as_ref().live_in {
if spillings.contains(&reg.get_id()) {
bbspillings.insert(reg.get_id());
}
}
let start = bbspillings.len() * 8;
bb_stack_sizes.insert(cur, start);
bbspillings.clear();
// 统计spilling数量
for inst in &cur.as_ref().insts {
for reg in inst.as_ref().get_reg_def() {
if spillings.contains(&reg.get_id()) {
bbspillings.insert(reg.get_id());
}
}
for reg in inst.as_ref().get_reg_use() {
if spillings.contains(&reg.get_id()) {
bbspillings.insert(reg.get_id());
}
}
}
if bbspillings.len() * 8 + start > stackSize {
stackSize = bbspillings.len() * 8 + start;
}
// 扩展未扩展的节点
for bb in &cur.as_ref().out_edge {
if passed.contains(&bb) {
continue;
}
passed.insert(bb.clone());
walk.push_back(bb.clone());
}
}
(stackSize, bb_stack_sizes)
}
// 基于剩余interval长度贪心的线性扫描寄存器分配
fn allocRegister(&mut self) -> (HashSet<i32>, HashMap<i32, i32>) {
let mut spillings: HashSet<i32> = HashSet::new();
......@@ -362,7 +313,7 @@ impl Regalloc for Allocator {
// //println!("_______________________________________________");
// //println!("{}",func.label);
// //println!("{:?}",spillings);
let (stack_size, bb_stack_sizes) = Allocator::countStackSize(func, &spillings);
let (stack_size, bb_stack_sizes) = regalloc::countStackSize(func, &spillings);
// let stack_size=spillings.len(); //TO REMOVE
let mut out = FuncAllocStat {
stack_size,
......
......@@ -11,3 +11,55 @@ pub trait Regalloc {
fn alloc(&mut self, func: &Func) -> FuncAllocStat;
}
pub fn countStackSize(
func: &Func,
spillings: &HashSet<i32>,
) -> (usize, HashMap<ObjPtr<BB>, usize>) {
// 遍历所有块,找到每个块中的spillings大小,返回其中大小的最大值,
let mut stackSize: usize = 0;
let mut bb_stack_sizes: HashMap<ObjPtr<BB>, usize> = HashMap::new();
let mut passed: HashSet<ObjPtr<BB>> = HashSet::new();
let mut walk: VecDeque<ObjPtr<BB>> = VecDeque::new();
walk.push_back(func.entry.unwrap().clone());
passed.insert(func.entry.unwrap());
// TOTEST
while !walk.is_empty() {
let cur = walk.pop_front().unwrap();
let mut bbspillings: HashSet<i32> = HashSet::new();
//println!("{}",cur.label);
for reg in &cur.as_ref().live_in {
if spillings.contains(&reg.get_id()) {
bbspillings.insert(reg.get_id());
}
}
let start = bbspillings.len() * 8;
bb_stack_sizes.insert(cur, start);
bbspillings.clear();
// 统计spilling数量
for inst in &cur.as_ref().insts {
for reg in inst.as_ref().get_reg_def() {
if spillings.contains(&reg.get_id()) {
bbspillings.insert(reg.get_id());
}
}
for reg in inst.as_ref().get_reg_use() {
if spillings.contains(&reg.get_id()) {
bbspillings.insert(reg.get_id());
}
}
}
if bbspillings.len() * 8 + start > stackSize {
stackSize = bbspillings.len() * 8 + start;
}
// 扩展未扩展的节点
for bb in &cur.as_ref().out_edge {
if passed.contains(&bb) {
continue;
}
passed.insert(bb.clone());
walk.push_back(bb.clone());
}
}
(spillings.len()*8, bb_stack_sizes)
}
\ No newline at end of file
......@@ -20,15 +20,15 @@ impl RegUsedStat {
}
pub fn is_available_ireg(&self, ireg: i32) -> bool {
if (1 << ireg & self.iregs_used) != 0 {
return true;
return false;
}
return false;
return true
}
pub fn is_available_freg(&self, freg: i32) -> bool {
if (1 << freg & self.fregs_used) != 0 {
return true;
return false;
}
return false;
return true;
}
// pub fn num_available_iregs(&self)->i32 {
......@@ -83,11 +83,11 @@ impl RegUsedStat {
}
// 但是a1-a7自由使用
for i in 11..=17 {
if self.iregs_used & (1 << i) == 0 {
return Some(i);
}
}
// for i in 11..=17 {
// if self.iregs_used & (1 << i) == 0 {
// return Some(i);
// }
// }
None
}
......@@ -199,3 +199,4 @@ impl BlockAllocStat {
}
}
}
Supports Markdown
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