Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
CompilerHIT
Compiler2023
Commits
1e9ba3bd
Commit
1e9ba3bd
authored
1 year ago
by
XMky
Browse files
Options
Download
Plain Diff
doxygen a1-a7
parents
2ee22451
b0259887
master
basealloc
change_inst_structure
check36_39
check39
checkdef
commit_test
commit_test2
fixindex
gvn-opt
hc
para
peelhole
test39
tmp
yjh
No related merge requests found
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
src/backend/func.rs
+1
-1
src/backend/func.rs
src/backend/regalloc/base_alloc.rs
+12
-1
src/backend/regalloc/base_alloc.rs
src/backend/regalloc/easy_gc_alloc.rs
+1
-3
src/backend/regalloc/easy_gc_alloc.rs
src/backend/regalloc/easy_ls_alloc.rs
+4
-53
src/backend/regalloc/easy_ls_alloc.rs
src/backend/regalloc/regalloc.rs
+52
-0
src/backend/regalloc/regalloc.rs
src/backend/regalloc/structs.rs
+10
-9
src/backend/regalloc/structs.rs
with
80 additions
and
67 deletions
+80
-67
src/backend/func.rs
+
1
−
1
View file @
1e9ba3bd
...
...
@@ -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
);
...
...
This diff is collapsed.
Click to expand it.
src/backend/regalloc/base_alloc.rs
+
12
−
1
View file @
1e9ba3bd
...
...
@@ -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:{:?}
\n
spillings:{:?}"
,
dstr
,
spillings
);
...
...
This diff is collapsed.
Click to expand it.
src/backend/regalloc/easy_gc_alloc.rs
+
1
−
3
View file @
1e9ba3bd
...
...
@@ -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);
...
...
This diff is collapsed.
Click to expand it.
src/backend/regalloc/easy_ls_alloc.rs
+
4
−
53
View file @
1e9ba3bd
...
...
@@ -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
,
...
...
This diff is collapsed.
Click to expand it.
src/backend/regalloc/regalloc.rs
+
52
−
0
View file @
1e9ba3bd
...
...
@@ -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
This diff is collapsed.
Click to expand it.
src/backend/regalloc/structs.rs
+
10
−
9
View file @
1e9ba3bd
...
...
@@ -20,15 +20,15 @@ impl RegUsedStat {
}
pub
fn
is_available_ireg
(
&
self
,
ireg
:
i32
)
->
bool
{
if
(
1
<<
ireg
&
self
.iregs_used
)
!=
0
{
return
tru
e
;
return
fals
e
;
}
return
false
;
return
true
}
pub
fn
is_available_freg
(
&
self
,
freg
:
i32
)
->
bool
{
if
(
1
<<
freg
&
self
.fregs_used
)
!=
0
{
return
tru
e
;
return
fals
e
;
}
return
fals
e
;
return
tru
e
;
}
// 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 {
}
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets