Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mu-impl-fast
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
40
Issues
40
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
mu
mu-impl-fast
Commits
cdb01047
Commit
cdb01047
authored
Jun 17, 2016
by
qinsoon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[wip] working on coloring
parent
27231f1d
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
70 additions
and
29 deletions
+70
-29
src/compiler/backend/arch/arm/mod.rs
src/compiler/backend/arch/arm/mod.rs
+4
-1
src/compiler/backend/arch/x86_64/mod.rs
src/compiler/backend/arch/x86_64/mod.rs
+3
-0
src/compiler/backend/mod.rs
src/compiler/backend/mod.rs
+11
-1
src/compiler/backend/reg_alloc/coloring.rs
src/compiler/backend/reg_alloc/coloring.rs
+22
-0
src/compiler/backend/reg_alloc/liveness.rs
src/compiler/backend/reg_alloc/liveness.rs
+27
-27
src/compiler/backend/reg_alloc/mod.rs
src/compiler/backend/reg_alloc/mod.rs
+3
-0
No files found.
src/compiler/backend/arch/arm/mod.rs
View file @
cdb01047
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
src/compiler/backend/arch/x86_64/mod.rs
View file @
cdb01047
...
...
@@ -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
(),
...
...
src/compiler/backend/mod.rs
View file @
cdb01047
...
...
@@ -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
src/compiler/backend/reg_alloc/coloring.rs
0 → 100644
View file @
cdb01047
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
src/compiler/backend/reg_alloc/liveness.rs
View file @
cdb01047
...
...
@@ -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
,
node
2
:
MuID
)
->
bool
{
let
ix1
=
self
.get_node
(
node
1
);
let
ix2
=
self
.get_node
(
node
2
);
fn
is_same_node
(
&
self
,
reg1
:
MuID
,
reg
2
:
MuID
)
->
bool
{
let
node1
=
self
.get_node
(
reg
1
);
let
node2
=
self
.get_node
(
reg
2
);
ix1
==
ix
2
node1
==
node
2
}
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
);
...
...
src/compiler/backend/reg_alloc/mod.rs
View file @
cdb01047
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment