Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
peephole
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Taddeüs Kroes
peephole
Commits
55c2f6c7
Commit
55c2f6c7
authored
13 years ago
by
Jayke Meijer
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' of github.com:taddeus/peephole
parents
ed8637b8
1912905a
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
benchmarks/build/hello.s
+33
-7
33 additions, 7 deletions
benchmarks/build/hello.s
benchmarks/hello.c
+5
-0
5 additions, 0 deletions
benchmarks/hello.c
src/optimize/__init__.py
+1
-1
1 addition, 1 deletion
src/optimize/__init__.py
src/optimize/advanced.py
+37
-0
37 additions, 0 deletions
src/optimize/advanced.py
with
76 additions
and
8 deletions
benchmarks/build/hello.s
+
33
−
7
View file @
55c2f6c7
...
...
@@ -10,6 +10,15 @@
gcc2_compiled
.:
__gnu_compiled_c
:
.
sdata
.
align
3
$LC0
:
.
word
0x00000000
#
2
.
word
0x40000000
.
align
3
$LC1
:
.
word
0x00000000
#
3
.5
.
word
0x400c0000
.
text
.
align
2
.
globl
main
...
...
@@ -19,20 +28,37 @@ __gnu_compiled_c:
.
loc
1
2
.
ent
main
main
:
.
frame
$fp
,
2
4
,
$
31
#
vars
=
0
,
regs
=
2
/
0
,
args
=
16
,
extra
=
0
.
frame
$fp
,
6
4
,
$
31
#
vars
=
4
0
,
regs
=
2
/
0
,
args
=
16
,
extra
=
0
.
mask
0xc0000000
,-
4
.
fmask
0x00000000
,
0
subu
$sp
,
$sp
,
2
4
sw
$
31
,
2
0
(
$sp
)
sw
$fp
,
1
6
(
$sp
)
subu
$sp
,
$sp
,
6
4
sw
$
31
,
6
0
(
$sp
)
sw
$fp
,
5
6
(
$sp
)
move
$fp
,
$sp
jal
__main
li
$
2
,
0x00000001
#
1
sw
$
2
,
16
(
$fp
)
li
$
2
,
0x00000005
#
5
sw
$
2
,
20
(
$fp
)
lw
$
2
,
16
(
$fp
)
lw
$
3
,
20
(
$fp
)
addu
$
2
,
$
2
,
$
3
sw
$
2
,
24
(
$fp
)
lw
$
2
,
16
(
$fp
)
addu
$
3
,
$
2
,
10
sw
$
3
,
28
(
$fp
)
l.d
$f0
,
$LC0
s.d
$f0
,
32
(
$fp
)
l.d
$f0
,
$LC1
s.d
$f0
,
40
(
$fp
)
li
$
2
,
0x00000061
#
97
sb
$
2
,
48
(
$fp
)
move
$
2
,
$
0
j
$L1
$L1
:
move
$sp
,
$fp
#
sp
not
trusted
here
lw
$
31
,
2
0
(
$sp
)
lw
$fp
,
1
6
(
$sp
)
addu
$sp
,
$sp
,
2
4
lw
$
31
,
6
0
(
$sp
)
lw
$fp
,
5
6
(
$sp
)
addu
$sp
,
$sp
,
6
4
j
$
31
.
end
main
This diff is collapsed.
Click to expand it.
benchmarks/hello.c
+
5
−
0
View file @
55c2f6c7
int
main
(
void
)
{
int
x
=
1
,
b
=
5
,
d
=
x
+
b
,
e
=
x
+
10
;
double
y
=
2
.,
z
=
3
.
5
;
char
c
=
'a'
;
return
0
;
}
This diff is collapsed.
Click to expand it.
src/optimize/__init__.py
+
1
−
1
View file @
55c2f6c7
...
...
@@ -61,7 +61,7 @@ def optimize_block(block):
pass
def
optimize
(
statements
,
verbose
=
0
):
"""
o
ptimization wrapper function, calls global and basic-block level
"""
O
ptimization wrapper function, calls global and basic-block level
optimization functions.
"""
# Optimize on a global level
o
=
len
(
statements
)
...
...
This diff is collapsed.
Click to expand it.
src/optimize/advanced.py
+
37
−
0
View file @
55c2f6c7
from
statement
import
Statement
as
S
def
create_variable
():
return
'
$15
'
def
eliminate_common_subexpressions
(
block
):
"""
Common subexpression elimination:
...
...
@@ -21,6 +25,7 @@ def eliminate_common_subexpressions(block):
if
s
.
is_arith
():
pointer
=
block
.
pointer
last
=
False
new_reg
=
False
args
=
s
[
1
:]
# Collect similar statements
...
...
@@ -33,6 +38,9 @@ def eliminate_common_subexpressions(block):
# Replace a similar expression by a move instruction
if
s2
.
name
==
s
.
name
and
s2
[
1
:]
==
args
:
if
not
new_reg
:
new_reg
=
create_variable
()
block
.
replace
(
1
,
[
S
(
'
command
'
,
'
move
'
,
s2
[
0
],
new_reg
)])
last
=
block
.
pointer
...
...
@@ -49,10 +57,39 @@ def eliminate_common_subexpressions(block):
return
found
def
to_hex
(
value
):
"""
Create the hexadecimal string of an integer.
"""
return
'
0x%08x
'
%
value
def
fold_constants
(
block
):
"""
Constant folding:
"""
constants
=
{}
while
not
block
.
end
():
s
=
block
.
read
()
if
s
.
is_load
():
constants
[
s
[
0
]]
=
s
[
1
]
elif
s
.
is_command
()
and
len
(
s
)
==
3
:
d
,
s
,
t
=
s
if
s
in
constants
and
t
in
constants
:
if
s
.
name
==
'
addu
'
:
result
=
s
+
t
elif
s
.
name
==
'
subu
'
:
result
=
s
-
t
elif
s
.
name
==
'
mult
'
:
result
=
s
*
t
elif
s
.
name
==
'
div
'
:
result
=
s
/
t
block
.
replace
(
1
,
[
S
(
'
command
'
,
'
li
'
,
to_hex
(
result
))])
constants
[
d
]
=
result
#else:
return
False
def
copy_propagation
(
block
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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