Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
2
2022fall-Compiler_CMinus
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
李晓奇
2022fall-Compiler_CMinus
Commits
689749e4
Commit
689749e4
authored
2 years ago
by
lxq
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
report
parent
11042e7a
Changes
10
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
237 additions
and
66 deletions
+237
-66
Reports/5-bonus/.gitignore
Reports/5-bonus/.gitignore
+1
-0
Reports/5-bonus/figures/5-while_aft.png
Reports/5-bonus/figures/5-while_aft.png
+0
-0
Reports/5-bonus/figures/5-while_bef.png
Reports/5-bonus/figures/5-while_bef.png
+0
-0
Reports/5-bonus/figures/5-while_final.png
Reports/5-bonus/figures/5-while_final.png
+0
-0
Reports/5-bonus/figures/pass.png
Reports/5-bonus/figures/pass.png
+0
-0
Reports/5-bonus/figures/simpleloop.png
Reports/5-bonus/figures/simpleloop.png
+0
-0
Reports/5-bonus/report.md
Reports/5-bonus/report.md
+193
-38
src/cminusfc/cminusfc.cpp
src/cminusfc/cminusfc.cpp
+4
-4
src/optimization/BrMerge.cpp
src/optimization/BrMerge.cpp
+39
-21
src/optimization/LoopUnroll.cpp
src/optimization/LoopUnroll.cpp
+0
-3
No files found.
Reports/5-bonus/.gitignore
0 → 100644
View file @
689749e4
report.pdf
This diff is collapsed.
Click to expand it.
Reports/5-bonus/figures/5-while_aft.png
0 → 100644
View file @
689749e4
128 KB
This diff is collapsed.
Click to expand it.
Reports/5-bonus/figures/5-while_bef.png
0 → 100644
View file @
689749e4
43.7 KB
This diff is collapsed.
Click to expand it.
Reports/5-bonus/figures/5-while_final.png
0 → 100644
View file @
689749e4
18.7 KB
This diff is collapsed.
Click to expand it.
Reports/5-bonus/figures/pass.png
0 → 100644
View file @
689749e4
107 KB
This diff is collapsed.
Click to expand it.
Reports/5-bonus/figures/simpleloop.png
0 → 100644
View file @
689749e4
1.51 MB
This diff is collapsed.
Click to expand it.
Reports/5-bonus/report.md
View file @
689749e4
This diff is collapsed.
Click to expand it.
src/cminusfc/cminusfc.cpp
View file @
689749e4
...
...
@@ -127,10 +127,10 @@ main(int argc, char **argv) {
if
(
loopunroll
)
{
PM
.
add_pass
<
NegCallMerge
>
(
false
);
PM
.
add_pass
<
LoopUnroll
>
(
false
);
PM
.
add_pass
<
DeadCode
>
(
false
);
PM
.
add_pass
<
GVN
>
(
false
,
dump_json
);
PM
.
add_pass
<
DeadCode
>
(
false
);
PM
.
add_pass
<
BrMerge
>
(
false
);
/*
PM.add_pass<DeadCode>(false);
*
PM.add_pass<GVN>(false, dump_json);
* PM.add_pass<DeadCode>(false); */
//
PM.add_pass<BrMerge>(false);
}
PM
.
run
();
...
...
This diff is collapsed.
Click to expand it.
src/optimization/BrMerge.cpp
View file @
689749e4
...
...
@@ -4,15 +4,23 @@
#include "Constant.h"
#include "Instruction.h"
#include <iostream>
using
std
::
cout
;
using
std
::
endl
;
void
BrMerge
::
run
()
{
m_
->
set_print_name
();
BranchInst
*
br
;
ReturnInst
*
ret
;
for
(
auto
&
func
:
m_
->
get_functions
())
{
if
(
func
.
is_declaration
())
continue
;
bool
cont
=
true
;
while
(
cont
)
{
cont
=
false
;
for
(
auto
&
bb
:
func
.
get_basic_blocks
())
{
cout
<<
bb
.
get_name
()
<<
endl
;
if
(
&
bb
==
func
.
get_entry_block
())
continue
;
auto
&
instructions
=
bb
.
get_instructions
();
...
...
@@ -28,14 +36,21 @@ BrMerge::run() {
}
else
if
(
dynamic_cast
<
Constant
*>
(
br
->
get_operand
(
0
)))
{
assert
(
bb
.
get_succ_basic_blocks
().
size
()
==
2
);
succ
=
static_cast
<
BasicBlock
*>
(
auto
const_bool
=
dynamic_cast
<
ConstantInt
*>
(
br
->
get_operand
(
0
))
->
get_value
()
?
br
->
get_operand
(
1
)
->
get_value
();
succ
=
static_cast
<
BasicBlock
*>
(
const_bool
?
br
->
get_operand
(
1
)
:
br
->
get_operand
(
2
));
static_cast
<
BasicBlock
*>
(
(
const_bool
?
br
->
get_operand
(
2
)
:
br
->
get_operand
(
1
)))
->
remove_pre_basic_block
(
&
bb
);
}
else
continue
;
for
(
auto
pre
:
bb
.
get_pre_basic_blocks
())
{
if
(
bb
.
get_pre_basic_blocks
().
size
()
!=
1
)
continue
;
auto
pre
=
*
bb
.
get_pre_basic_blocks
().
begin
();
// change br's op
auto
ins
=
&*
pre
->
get_instructions
().
rbegin
();
bool
set
=
false
;
...
...
@@ -43,6 +58,7 @@ BrMerge::run() {
if
(
ins
->
get_operand
(
i
)
==
&
bb
)
{
ins
->
set_operand
(
i
,
succ
);
set
=
true
;
bb
.
remove_use
(
ins
);
break
;
}
assert
(
set
);
...
...
@@ -51,12 +67,14 @@ BrMerge::run() {
pre
->
add_succ_basic_block
(
&
bb
);
// change succ's pre
succ
->
add_pre_basic_block
(
pre
);
}
// change succ's pre
succ
->
remove_pre_basic_block
(
&
bb
);
// remove useless block
func
.
get_basic_blocks
().
remove
(
&
bb
);
// replace use
bb
.
replace_all_use_with
(
pre
);
cont
=
true
;
break
;
}
else
{
// ret: do not change
}
}
else
{
...
...
This diff is collapsed.
Click to expand it.
src/optimization/LoopUnroll.cpp
View file @
689749e4
...
...
@@ -128,9 +128,6 @@ LoopUnroll::unroll_loop(SimpleLoop &sl) {
// neg block's pre blocks
// replace use
m_
->
set_print_name
();
for
(
auto
[
k
,
v
]
:
old2new
)
cout
<<
"[debug]"
<<
k
->
get_name
()
<<
"-"
<<
v
->
get_name
()
<<
endl
;
for
(
auto
&
bb
:
func
->
get_basic_blocks
())
{
for
(
auto
&
instr
:
bb
.
get_instructions
())
{
for
(
int
i
=
0
;
i
<
instr
.
get_num_operand
();
++
i
)
{
...
...
This diff is collapsed.
Click to expand it.
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