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
08898ecb
Commit
08898ecb
authored
Dec 06, 2022
by
李晓奇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
now shuold pass loop3!
parent
b1f2b21d
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
244 additions
and
67 deletions
+244
-67
include/optimization/GVN.h
include/optimization/GVN.h
+22
-8
src/optimization/GVN.cpp
src/optimization/GVN.cpp
+218
-59
tests/4-ir-opt/testcases/GVN/functional/.gitignore
tests/4-ir-opt/testcases/GVN/functional/.gitignore
+3
-0
tests/4-ir-opt/testcases/GVN/functional/clear.sh
tests/4-ir-opt/testcases/GVN/functional/clear.sh
+1
-0
No files found.
include/optimization/GVN.h
View file @
08898ecb
...
...
@@ -69,6 +69,8 @@ class ConstantExpression : public Expression {
}
ConstantExpression
(
Constant
*
c
)
:
Expression
(
e_constant
),
c_
(
c
)
{}
Constant
*
get_val
()
{
return
c_
;
}
private:
Constant
*
c_
;
};
...
...
@@ -199,20 +201,24 @@ class GEPExpression : public Expression {
// unique expression: not equal to any one else
class
UniqueExpression
:
public
Expression
{
public:
static
std
::
shared_ptr
<
UniqueExpression
>
create
(
Instruction
*
instr
)
{
return
std
::
make_shared
<
UniqueExpression
>
(
instr
);
static
std
::
shared_ptr
<
UniqueExpression
>
create
(
Instruction
*
instr
,
size_t
index
)
{
return
std
::
make_shared
<
UniqueExpression
>
(
instr
,
index
);
}
virtual
std
::
string
print
()
{
return
"(UNIQUE "
+
instr_
->
print
()
+
")"
;
}
// virtual std::string print() { return "(UNIQUE " + instr_->print() + ")";
// }
virtual
std
::
string
print
()
{
return
"v"
+
std
::
to_string
(
index_
);
}
bool
equiv
(
const
UniqueExpression
*
other
)
const
{
return
instr_
==
other
->
instr_
;
}
UniqueExpression
(
Instruction
*
instr
)
:
Expression
(
e_unique
),
instr_
(
instr
)
{}
UniqueExpression
(
Instruction
*
instr
,
size_t
index
)
:
Expression
(
e_unique
),
instr_
(
instr
)
,
index_
(
index
)
{}
private:
Instruction
*
instr_
;
size_t
index_
;
};
}
// namespace GVNExpression
...
...
@@ -276,7 +282,8 @@ class GVN : public Pass {
partitions
transferFunction
(
BasicBlock
*
bb
);
std
::
shared_ptr
<
GVNExpression
::
PhiExpression
>
valuePhiFunc
(
std
::
shared_ptr
<
GVNExpression
::
Expression
>
,
BasicBlock
*
bb
);
BasicBlock
*
bb
,
Instruction
*
instr
);
std
::
shared_ptr
<
GVNExpression
::
Expression
>
valueExpr
(
Instruction
*
instr
,
const
partitions
&
part
);
...
...
@@ -308,6 +315,7 @@ class GVN : public Pass {
std
::
map
<
BasicBlock
*
,
bool
>
_TOP
;
partitions
join_helper
(
BasicBlock
*
pre1
,
BasicBlock
*
pre2
);
BasicBlock
*
curr_bb
;
std
::
map
<
std
::
pair
<
Instruction
*
,
Value
*>
,
size_t
>
start_idx_
;
//
// self add function
//
...
...
@@ -317,11 +325,17 @@ class GVN : public Pass {
Value
*
v
,
const
partitions
&
part
);
std
::
vector
<
std
::
shared_ptr
<
GVNExpression
::
Expression
>>
core_
(
std
::
vector
<
std
::
shared_ptr
<
GVNExpression
::
Expression
>>
valueExpr_
core_
(
Instruction
*
instr
,
const
partitions
&
part
,
size_t
count
,
const
size_t
count
,
bool
fold_
=
true
);
Constant
*
constFold_core
(
const
size_t
count
,
const
partitions
&
part
,
Instruction
*
instr
,
const
std
::
vector
<
Value
*>
&
operands
);
void
assign_start_idx_
();
void
dump_tmp
(
Function
&
);
};
bool
operator
==
(
const
GVN
::
partitions
&
p1
,
const
GVN
::
partitions
&
p2
);
src/optimization/GVN.cpp
View file @
08898ecb
This diff is collapsed.
Click to expand it.
tests/4-ir-opt/testcases/GVN/functional/.gitignore
View file @
08898ecb
*.ll
*th
tmp*
gvn.json
tests/4-ir-opt/testcases/GVN/functional/clear.sh
View file @
08898ecb
rm
-rf
*
.ll
rm
-rf
gvn.json
rm
-rf
`
ls
|
grep
-v
"
\.
"
`
rm
-rf
tmp
*
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