Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
peephole
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
peephole
Commits
55c2f6c7
Commit
55c2f6c7
authored
Dec 28, 2011
by
Jayke Meijer
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of github.com:taddeus/peephole
parents
ed8637b8
1912905a
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
76 additions
and
8 deletions
+76
-8
benchmarks/build/hello.s
benchmarks/build/hello.s
+33
-7
benchmarks/hello.c
benchmarks/hello.c
+5
-0
src/optimize/__init__.py
src/optimize/__init__.py
+1
-1
src/optimize/advanced.py
src/optimize/advanced.py
+37
-0
No files found.
benchmarks/build/hello.s
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
,
24
,
$
31
#
vars
=
0
,
regs
=
2
/
0
,
args
=
16
,
extra
=
0
.
frame
$fp
,
64
,
$
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
benchmarks/hello.c
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
;
}
src/optimize/__init__.py
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
)
...
...
src/optimize/advanced.py
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
):
...
...
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