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
53d3416c
Commit
53d3416c
authored
Dec 29, 2011
by
Richard Torenvliet
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of github.com:taddeus/peephole
parents
9383aba4
9b1c56f0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
85 additions
and
12 deletions
+85
-12
benchmarks/build/test.s
benchmarks/build/test.s
+55
-0
benchmarks/test.c
benchmarks/test.c
+7
-0
src/optimize/advanced.py
src/optimize/advanced.py
+23
-12
No files found.
benchmarks/build/test.s
0 → 100644
View file @
53d3416c
.
file
1
"test.c"
#
GNU
C
2
.7.2.3
[
AL
1
.1
,
MM
40
,
tma
0
.1
]
SimpleScalar
running
sstrix
compiled
by
GNU
C
#
Cc1
defaults
:
#
-
mgas
-
mgpOPT
#
Cc1
arguments
(-
G
value
=
8
,
Cpu
=
default
,
ISA
=
1
)
:
#
-
quiet
-
dumpbase
-
O0
-
o
gcc2_compiled
.:
__gnu_compiled_c
:
.
text
.
align
2
.
globl
main
.
text
.
loc
1
3
.
ent
main
main
:
.
frame
$fp
,
48
,
$
31
#
vars
=
24
,
regs
=
2
/
0
,
args
=
16
,
extra
=
0
.
mask
0xc0000000
,-
4
.
fmask
0x00000000
,
0
subu
$sp
,
$sp
,
48
sw
$
31
,
44
(
$sp
)
sw
$fp
,
40
(
$sp
)
move
$fp
,
$sp
jal
__main
li
$
2
,
0x00000002
#
2
sw
$
2
,
16
(
$fp
)
li
$
2
,
0x00000005
#
5
sw
$
2
,
20
(
$fp
)
lw
$
2
,
16
(
$fp
)
lw
$
3
,
20
(
$fp
)
mult
$
2
,
$
3
mflo
$
2
sw
$
2
,
24
(
$fp
)
lw
$
2
,
16
(
$fp
)
move
$
4
,
$
2
sll
$
3
,
$
4
,
1
addu
$
3
,
$
3
,
$
2
sll
$
2
,
$
3
,
1
sw
$
2
,
28
(
$fp
)
li
$
2
,
0x00000015
#
21
sw
$
2
,
32
(
$fp
)
move
$
2
,
$
0
j
$L1
$L1
:
move
$sp
,
$fp
#
sp
not
trusted
here
lw
$
31
,
44
(
$sp
)
lw
$fp
,
40
(
$sp
)
addu
$sp
,
$sp
,
48
j
$
31
.
end
main
benchmarks/test.c
0 → 100644
View file @
53d3416c
#include <stdio.h>
int
main
(
void
)
{
int
a
=
2
,
b
=
5
,
c
=
a
*
b
,
d
=
a
*
6
,
e
=
3
*
7
;
return
0
;
}
src/optimize/advanced.py
View file @
53d3416c
...
...
@@ -147,10 +147,27 @@ def fold_constants(block):
elif
s
.
name
==
'lw'
and
s
[
1
]
in
constants
:
# Usage of variable with constant value
register
[
s
[
0
]]
=
constants
[
s
[
1
]]
elif
s
.
name
in
[
'addu'
,
'subu'
,
'mult'
,
'div'
]:
# TODO: implement 'mult' optimization
# Calculation with constants
rd
,
rs
,
rt
=
s
[
0
],
s
[
1
],
s
[
2
]
elif
s
.
name
==
'mflo'
:
# Move of `Lo' register to another register
register
[
s
[
0
]]
=
register
[
'Lo'
]
elif
s
.
name
==
'mfhi'
:
# Move of `Hi' register to another register
register
[
s
[
0
]]
=
register
[
'Hi'
]
elif
s
.
name
in
[
'mult'
,
'div'
]
\
and
s
[
0
]
in
register
and
s
[
1
]
in
register
:
# Multiplication/division with constants
rs
,
rt
=
s
if
s
.
name
==
'mult'
:
binary
=
bin
(
register
[
rs
]
*
register
[
rt
])[
2
:]
binary
=
'0'
*
(
64
-
len
(
binary
))
+
binary
register
[
'Hi'
]
=
int
(
binary
[:
32
],
base
=
2
)
register
[
'Lo'
]
=
int
(
binary
[
32
:],
base
=
2
)
elif
s
.
name
==
'div'
:
register
[
'Lo'
],
register
[
'Hi'
]
=
divmod
(
rs
,
rt
)
elif
s
.
name
in
[
'addu'
,
'subu'
]:
# Addition/subtraction with constants
rd
,
rs
,
rt
=
s
rs_known
=
rs
in
register
rt_known
=
rt
in
register
...
...
@@ -167,22 +184,16 @@ def fold_constants(block):
if
s
.
name
==
'subu'
:
result
=
to_hex
(
rs_val
-
rt_val
)
if
s
.
name
==
'mult'
:
result
=
to_hex
(
rs_val
*
rt_val
)
if
s
.
name
==
'div'
:
result
=
to_hex
(
rs_val
/
rt_val
)
block
.
replace
(
1
,
[
S
(
'command'
,
'li'
,
rd
,
result
)])
register
[
rd
]
=
result
changed
=
True
elif
rt_known
:
#
c = 10 -> b = a
+ 10
#
a = 10 -> b = c
+ 10
# b = c + a
s
[
2
]
=
register
[
rt
]
changed
=
True
elif
rs_known
and
s
.
name
==
'addu'
:
#
a = 10 -> b = c
+ 10
#
c = 10 -> b = a
+ 10
# b = c + a
s
[
1
]
=
rt
s
[
2
]
=
register
[
rs
]
...
...
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