Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in
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
6
Merge Requests
6
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
efbf4233
You need to sign in or sign up before continuing.
Commit
efbf4233
authored
Dec 02, 2022
by
李晓奇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
follow update
parent
f0f0bb81
Changes
7
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
399 additions
and
187 deletions
+399
-187
.clang-format
.clang-format
+2
-1
Documentations/4.2-gvn/README.md
Documentations/4.2-gvn/README.md
+117
-108
Documentations/4.2-gvn/gvn.pdf
Documentations/4.2-gvn/gvn.pdf
+0
-0
include/lightir/Instruction.h
include/lightir/Instruction.h
+3
-4
include/optimization/GVN.h
include/optimization/GVN.h
+8
-0
src/optimization/.gitignore
src/optimization/.gitignore
+1
-0
src/optimization/GVN.cpp
src/optimization/GVN.cpp
+268
-74
No files found.
.clang-format
View file @
efbf4233
...
...
@@ -6,7 +6,7 @@ AlwaysBreakTemplateDeclarations: true
BinPackArguments: false
BinPackParameters: false
BreakConstructorInitializers: BeforeComma
ColumnLimit:
12
0
ColumnLimit:
8
0
CommentPragmas: '^(!|NOLINT)'
ConstructorInitializerAllOnOneLineOrOnePerLine: true
IncludeBlocks: Regroup
...
...
@@ -23,4 +23,5 @@ PenaltyReturnTypeOnItsOwnLine: 200
SpacesBeforeTrailingComments: 1
TabWidth: 4
UseTab: Never
AlwaysBreakAfterReturnType: TopLevelDefinitions
...
Documentations/4.2-gvn/README.md
View file @
efbf4233
# Lab4 实验文档
-
[
Lab4 实验文档
](
#lab4-实验文档
)
-
[
0. 前言
](
#0-前言
)
-
[
1. GVN 基础知识
](
#1-gvn-基础知识
)
...
...
@@ -25,9 +26,11 @@
-
[
4. 提交要求
](
#4-提交要求
)
-
[
目录结构
](
#目录结构
)
-
[
提交要求和评分标准
](
#提交要求和评分标准
)
## 0. 前言
## 0. 前言
在 Lab4.1 中,我们介绍了 SSA IR,并阐明了其优势。本次实验中我们需要在 SSA IR 基础上,实现一个基于数据流分析的冗余消除的优化 Pass : Global Value Numbering(全局值编号)。
## 1. GVN 基础知识
### 1.1 GVN 简介
...
...
@@ -110,6 +113,7 @@ bb3:
一个 Partition (分区)由一系列等价类组成,一个等价类是由一个值编号,和一系列成员组成。每个成员可以是:变量,常量,值表达式。同时,一个等价类可能会关联一个 value-phi-function。
#### 7. Join 操作
Join 操作检测到达此处的所有路径共有的等价项。在 SSA 格式的 IR 中,变量只会被赋值一次,当程序点 p 支配 join block 时,在 p 点成立的等价关系,在 join block 处仍然成立。通过对 join block 的前驱 Partition 取交集,可以保留所有支配 join block 的程序点的等价关系。对于在每个路径的等价的探测,我们将在
[
2.GVN算法
](
#2-gvn-算法论文中提供的伪代码
)
中通过伪代码进行阐述。对于表达式的等价关系与变量等价关系的检测与判定,我们会分别阐述。
#### 8. 变量等价与表达式等价
...
...
@@ -263,6 +267,7 @@ valuePhiFunc(ve,P)
## 3. 实验内容
在本次实验中,请仔细阅读
[
3.1 GVN pass 实现内容要求
](
#31-gvn-pass-实现内容要求
)
,根据要求补全
`src/optimization/GVN.cpp`
,
`include/optimization/GVN.h`
中关于 GVN pass 数据流分析部分,同时需要在
`Reports/4-ir-opt/`
目录下撰写实验报告。
**为了在评测中统一分析结果,请大家采用 lab3 的 TA-impl 分支提供的[答案](http://202.38.79.174/compiler_staff/2022fall-compiler_cminus/-/blob/TA-impl/src/cminusfc/cminusf_builder.cpp)来完成后续实验。**
### 3.1 GVN pass 实现内容要求
GVN 通过数据流分析来检测冗余的变量和计算,通过替换和死代码删除结合,实现优化效果。前述的例子中主要以二元运算语句来解释原理,且助教为大家提供了代码替换和删除的逻辑,除此之外,需要完成的方向有:
...
...
@@ -469,8 +474,8 @@ root@3fd22a9ed627:/labs/2022fall-compiler_cminus-taversion/tests/4-ir-opt#
└── 4-ir-opt
├── testcases 助教提供的测试样例
└── lab4_test.py 助教提供的测试脚本
```
### 提交要求和评分标准
*
提交要求
...
...
@@ -488,6 +493,7 @@ root@3fd22a9ed627:/labs/2022fall-compiler_cminus-taversion/tests/4-ir-opt#
*
本次实验报告以 pdf 格式提交到希冀平台对应提交通道
*
评分标准: 实验完成分(总分 60 分)组成如下:
*
实验报告 (5 分)
需要回答 Reports 目录下实验报告模板的思考题。
...
...
@@ -505,10 +511,10 @@ root@3fd22a9ed627:/labs/2022fall-compiler_cminus-taversion/tests/4-ir-opt#
"label7"
:
[[
"%op0"
,
],
[
"%op1"
,
],
[
"%op2"
,
],
[
"%op10"
,
],
[
"%op9"
,
],
[
"%op11"
,
"%op8"
,
],
],
"label12"
:
[[
"%op0"
,
],
[
"%op1"
,
],
[
"%op2"
,
],
[
"%op13"
,
"%op10"
,
],
[
"%op14"
,
"%op9"
,
],
[
"%op15"
,
"%op8"
,
],
],}
```
对于分值为 x,n 个基本块的程序,每个 bb 分析结果为$
`x/n`
$分,某个bb的分析结果多或者少一个等价类,或有分析错误的等价类,该 bb 分析结果没有分值。
对于分值为 x,n 个基本块的程序,每个 bb 分析结果为$
`x/n`
$分,某个bb的分析结果多或者少一个等价类,或有分析错误的等价类,该 bb 分析结果没有分值。
*
performance case(15分)
*
performance case(15分)
助教提供了 2 个公开case,并保留 2 个隐藏用例。以及助教实现优化后的 baseline.ll ,优化效果按照如下方式给分(执行结果不正确则此项分数为0)
...
...
@@ -519,7 +525,7 @@ root@3fd22a9ed627:/labs/2022fall-compiler_cminus-taversion/tests/4-ir-opt#
(before_optimization-after_optimization)/(before_optimization-baseline) > 0.2 得60%分数
```
*
禁止执行恶意代码,违者本次实验0分处理
*
禁止执行恶意代码,违者本次实验0分处理
*
迟交规定
...
...
@@ -528,14 +534,17 @@ root@3fd22a9ed627:/labs/2022fall-compiler_cminus-taversion/tests/4-ir-opt#
*
`Hard Deadline`
: 2022/12/19 23:59:59 (北京标准时间,UTC+8)
*
迟交需要邮件通知 TA :
*
邮箱:
chen16614@mail.ustc.edu.cn 抄送 farmerzhang1@mail.ustc.edu.cn
*
邮件主题: lab4.2迟交-学号
*
内容: 包括迟交原因、最后版本commitID、迟交时间等
*
迟交分数
*
x为迟交天数(对于
`Soft Deadline`
而言),grade为满分
```
bash
```
bash
final_grade
=
grade, x
=
0
final_grade
=
grade
*
(
0.9
)
^x, 0 < x <
=
7
final_grade
=
0, x
>
7
# 这一条严格执行,请对自己负责
...
...
Documentations/4.2-gvn/gvn.pdf
View file @
efbf4233
No preview for this file type
include/lightir/Instruction.h
View file @
efbf4233
...
...
@@ -56,6 +56,7 @@ class Instruction : public User, public llvm::ilist_node<Instruction>
Module
*
get_module
();
OpID
get_instr_type
()
const
{
return
op_id_
;
}
// clang-format off
static
std
::
string
get_instr_op_name
(
OpID
id
)
{
switch
(
id
)
{
case
ret
:
return
"ret"
;
break
;
...
...
@@ -79,12 +80,10 @@ class Instruction : public User, public llvm::ilist_node<Instruction>
case
zext
:
return
"zext"
;
break
;
case
fptosi
:
return
"fptosi"
;
break
;
case
sitofp
:
return
"sitofp"
;
break
;
default:
return
""
;
break
;
default:
return
""
;
break
;
}
}
// clang-format on
std
::
string
get_instr_op_name
()
{
return
get_instr_op_name
(
op_id_
);
}
bool
is_void
()
...
...
include/optimization/GVN.h
View file @
efbf4233
...
...
@@ -159,6 +159,7 @@ class GVN : public Pass {
partitions
join
(
const
partitions
&
P1
,
const
partitions
&
P2
);
std
::
shared_ptr
<
CongruenceClass
>
intersect
(
std
::
shared_ptr
<
CongruenceClass
>
,
std
::
shared_ptr
<
CongruenceClass
>
);
partitions
transferFunction
(
Instruction
*
x
,
Value
*
e
,
partitions
pin
);
partitions
transferFunction
(
BasicBlock
*
bb
);
std
::
shared_ptr
<
GVNExpression
::
PhiExpression
>
valuePhiFunc
(
std
::
shared_ptr
<
GVNExpression
::
Expression
>
,
const
partitions
&
);
std
::
shared_ptr
<
GVNExpression
::
Expression
>
valueExpr
(
Instruction
*
instr
);
...
...
@@ -176,6 +177,10 @@ class GVN : public Pass {
return
std
::
make_shared
<
CongruenceClass
>
(
index
);
}
// self add
//
std
::
uint64_t
new_number
()
{
return
next_value_number_
++
;
}
private:
bool
dump_json_
;
std
::
uint64_t
next_value_number_
=
1
;
...
...
@@ -184,6 +189,9 @@ class GVN : public Pass {
std
::
unique_ptr
<
FuncInfo
>
func_info_
;
std
::
unique_ptr
<
GVNExpression
::
ConstFolder
>
folder_
;
std
::
unique_ptr
<
DeadCode
>
dce_
;
// self add
std
::
map
<
Instruction
*
,
bool
>
_TOP
;
};
bool
operator
==
(
const
GVN
::
partitions
&
p1
,
const
GVN
::
partitions
&
p2
);
src/optimization/.gitignore
0 → 100644
View file @
efbf4233
todo
src/optimization/GVN.cpp
View file @
efbf4233
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