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
3e52250f
Commit
3e52250f
authored
Feb 08, 2023
by
lxq
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
optimize for constant int get
parent
06a9b882
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
0 deletions
+9
-0
src/codegen/codegen.cpp
src/codegen/codegen.cpp
+9
-0
No files found.
src/codegen/codegen.cpp
View file @
3e52250f
...
@@ -197,6 +197,15 @@ CodeGen::value2reg(Value *v, int i, string recommend) {
...
@@ -197,6 +197,15 @@ CodeGen::value2reg(Value *v, int i, string recommend) {
if
(
dynamic_cast
<
Constant
*>
(
v
))
{
if
(
dynamic_cast
<
Constant
*>
(
v
))
{
if
(
v
==
CONST_0
)
if
(
v
==
CONST_0
)
return
"$zero"
;
return
"$zero"
;
if
(
dynamic_cast
<
ConstantInt
*>
(
v
))
{
auto
const_int_v
=
static_cast
<
ConstantInt
*>
(
v
)
->
get_value
();
auto
[
l
,
h
]
=
immRange
(
12
,
false
);
if
(
l
<=
const_int_v
and
const_int_v
<=
h
)
{
output
.
push_back
(
"addi.d "
+
reg_name
+
", $zero, "
+
to_string
(
const_int_v
));
return
reg_name
;
}
}
auto
constant
=
static_cast
<
Constant
*>
(
v
);
auto
constant
=
static_cast
<
Constant
*>
(
v
);
if
(
ROdata
.
find
(
constant
)
==
ROdata
.
end
())
if
(
ROdata
.
find
(
constant
)
==
ROdata
.
end
())
ROdata
[
constant
]
=
".LC"
+
to_string
(
ROdata
.
size
());
ROdata
[
constant
]
=
".LC"
+
to_string
(
ROdata
.
size
());
...
...
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