GitLab will continue to be upgraded from 11.4.5-ce.0 on November 25th 2019 at 4.00pm (AEDT) to 5.00pm (AEDT) due to Critical Security Patch Availability. During the update, GitLab and Mattermost services will not be available.

Commit cdb01047 authored by qinsoon's avatar qinsoon

[wip] working on coloring

parent 27231f1d
pub use inst_sel;
\ No newline at end of file
pub use inst_sel;
pub const GPR_COUNT : usize = 16;
pub const FPR_COUNT : usize = 16;
\ No newline at end of file
......@@ -116,6 +116,9 @@ lazy_static!{
pub static ref CALLEE_SAVED_FPRs : [P<Value>; 0] = [];
}
pub const GPR_COUNT : usize = 16;
pub const FPR_COUNT : usize = 16;
lazy_static! {
pub static ref ALL_MACHINE_REGs : Vec<P<Value>> = vec![
RAX.clone(),
......
......@@ -10,4 +10,14 @@ mod x86_64;
mod arm;
#[cfg(target_arch = "x86_64")]
pub use compiler::backend::x86_64::get_name_for_value;
\ No newline at end of file
pub use compiler::backend::x86_64::get_name_for_value;
#[cfg(target_arch = "x86_64")]
pub use compiler::backend::x86_64::GPR_COUNT;
#[cfg(target_arch = "x86_64")]
pub use compiler::backend::x86_64::FPR_COUNT;
#[cfg(target_arch = "arm")]
pub use compiler::backend::arm::GPR_COUNT;
#[cfg(target_arch = "arm")]
pub use compiler::backend::arm::FPR_COUNT;
\ No newline at end of file
use compiler::backend::reg_alloc::liveness::InterferenceGraph;
use vm::machine_code::CompiledFunction;
pub struct GraphColoring <'a> {
ig: InterferenceGraph,
cur_cf: &'a CompiledFunction,
}
impl <'a> GraphColoring <'a> {
pub fn start (cf: &CompiledFunction, ig: InterferenceGraph) {
let mut coloring = GraphColoring {
ig: ig,
cur_cf: cf,
};
coloring.init();
}
fn init (&mut self) {
}
}
\ No newline at end of file
......@@ -10,10 +10,10 @@ use std::collections::{HashMap, HashSet};
use self::nalgebra::DMatrix;
type MatrixIndex = usize;
type Node = usize;
pub struct InterferenceGraph {
nodes: HashMap<MuID, MatrixIndex>,
nodes: HashMap<MuID, Node>,
matrix: Option<DMatrix<bool>>,
color: HashMap<MuID, MuID>,
......@@ -31,21 +31,21 @@ impl InterferenceGraph {
}
}
fn new_node(&mut self, node: MuID) -> MatrixIndex {
if !self.nodes.contains_key(&node) {
fn new_node(&mut self, reg: MuID) -> Node {
if !self.nodes.contains_key(&reg) {
let index = self.nodes.len();
self.nodes.insert(node, index);
self.nodes.insert(reg, index);
index
} else {
* self.nodes.get(&node).unwrap()
* self.nodes.get(&reg).unwrap()
}
}
fn get_node(&self, node: MuID) -> MatrixIndex {
match self.nodes.get(&node) {
fn get_node(&self, reg: MuID) -> Node {
match self.nodes.get(&reg) {
Some(index) => *index,
None => panic!("do not have a node for {}", node)
None => panic!("do not have a node for {}", reg)
}
}
......@@ -65,28 +65,28 @@ impl InterferenceGraph {
self.matrix.as_mut().unwrap()[(from_ix, to_ix)] = true;
}
fn color_node(&mut self, node: MuID, color: MuID) {
self.color.insert(node, color);
fn color_node(&mut self, reg: MuID, color: MuID) {
self.color.insert(reg, color);
}
fn node_has_color(&self, node: MuID) -> bool {
self.color.contains_key(&node)
fn node_has_color(&self, reg: MuID) -> bool {
self.color.contains_key(&reg)
}
fn is_same_node(&self, node1: MuID, node2: MuID) -> bool {
let ix1 = self.get_node(node1);
let ix2 = self.get_node(node2);
fn is_same_node(&self, reg1: MuID, reg2: MuID) -> bool {
let node1 = self.get_node(reg1);
let node2 = self.get_node(reg2);
ix1 == ix2
node1 == node2
}
fn is_adj(&self, from: MuID, to: MuID) -> bool {
let from_ix = self.get_node(from);
let to_ix = self.get_node(to);
let from_node = self.get_node(from);
let to_node = self.get_node(to);
let ref matrix = self.matrix.as_ref().unwrap();
matrix[(from_ix, to_ix)] || matrix[(to_ix, from_ix)]
matrix[(from_node, to_node)] || matrix[(to_node, from_node)]
}
pub fn print(&self) {
......@@ -103,11 +103,11 @@ impl InterferenceGraph {
}
println!("graph:");
{
let idx_to_node_id = {
let mut ret : HashMap<MatrixIndex, MuID> = HashMap::new();
let node_to_reg_id = {
let mut ret : HashMap<Node, MuID> = HashMap::new();
for node_id in self.nodes.keys() {
ret.insert(*self.nodes.get(node_id).unwrap(), *node_id);
for reg in self.nodes.keys() {
ret.insert(*self.nodes.get(reg).unwrap(), *reg);
}
ret
......@@ -117,8 +117,8 @@ impl InterferenceGraph {
for i in 0..matrix.ncols() {
for j in 0..matrix.nrows() {
if matrix[(i, j)] {
let from_node = idx_to_node_id.get(&i).unwrap();
let to_node = idx_to_node_id.get(&j).unwrap();
let from_node = node_to_reg_id.get(&i).unwrap();
let to_node = node_to_reg_id.get(&j).unwrap();
println!("Node {} -> Node {}", from_node, to_node);
}
......@@ -146,7 +146,7 @@ impl InterferenceGraph {
println!("graph:");
{
let idx_to_node_id = {
let mut ret : HashMap<MatrixIndex, MuID> = HashMap::new();
let mut ret : HashMap<Node, MuID> = HashMap::new();
for node_id in self.nodes.keys() {
ret.insert(*self.nodes.get(node_id).unwrap(), *node_id);
......
......@@ -3,6 +3,7 @@ use ast::ir::*;
use vm::context::VMContext;
mod liveness;
mod coloring;
pub struct RegisterAllocation {
name: &'static str
......@@ -30,5 +31,7 @@ impl CompilerPass for RegisterAllocation {
let liveness = liveness::build(&mut cf);
liveness.print();
coloring::GraphColoring::start(&mut cf, liveness);
}
}
\ No newline at end of file
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