Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Haley Sapphie Owsianko
ACC-project
Commits
bfbb4735
Commit
bfbb4735
authored
May 07, 2021
by
Sapphie
Browse files
Add removal of block-set for unused blocks
parent
0f48f05e
Changes
5
Show whitespace changes
Inline
Side-by-side
compiler/src/l3/CPSOptimizer.scala
View file @
bfbb4735
...
@@ -12,7 +12,7 @@ abstract class CPSOptimizer[T <: CPSTreeModule { type Name = Symbol }]
...
@@ -12,7 +12,7 @@ abstract class CPSOptimizer[T <: CPSTreeModule { type Name = Symbol }]
fixedPoint
(
simplifiedTree
,
8
)
{
t
=>
inline
(
t
,
maxSize
)
}
fixedPoint
(
simplifiedTree
,
8
)
{
t
=>
inline
(
t
,
maxSize
)
}
}
}
private
case
class
Count
(
applied
:
Int
=
0
,
asValue
:
Int
=
0
)
private
case
class
Count
(
applied
:
Int
=
0
,
asValue
:
Int
=
0
,
writtenTo
:
Int
=
0
)
private
case
class
State
(
private
case
class
State
(
census
:
Map
[
Name
,
Count
],
census
:
Map
[
Name
,
Count
],
...
@@ -27,8 +27,11 @@ abstract class CPSOptimizer[T <: CPSTreeModule { type Name = Symbol }]
...
@@ -27,8 +27,11 @@ abstract class CPSOptimizer[T <: CPSTreeModule { type Name = Symbol }]
eInvEnv
.
map
(
_
.
swap
)
eInvEnv
.
map
(
_
.
swap
)
def
dead
(
s
:
Name
)
:
Boolean
=
def
dead
(
s
:
Name
)
:
Boolean
=
!
census
.
contains
(
s
)
!
census
.
contains
(
s
)
def
onlyWrittenTo
(
s
:
Name
)
:
Boolean
=
census
.
get
(
s
).
filter
(
c
=>
c
.
writtenTo
==
c
.
asValue
).
isDefined
def
appliedOnce
(
s
:
Name
)
:
Boolean
=
def
appliedOnce
(
s
:
Name
)
:
Boolean
=
census
.
get
(
s
).
contains
(
Count
(
applied
=
1
,
asValue
=
0
))
census
.
get
(
s
).
filter
(
c
=>
c
.
asValue
=
=
0
&&
c
.
applied
==
1
).
isDefined
def
withASubst
(
from
:
Atom
,
to
:
Atom
)
:
State
=
def
withASubst
(
from
:
Atom
,
to
:
Atom
)
:
State
=
copy
(
aSubst
=
aSubst
+
(
from
->
aSubst
(
to
)))
copy
(
aSubst
=
aSubst
+
(
from
->
aSubst
(
to
)))
...
@@ -159,6 +162,8 @@ abstract class CPSOptimizer[T <: CPSTreeModule { type Name = Symbol }]
...
@@ -159,6 +162,8 @@ abstract class CPSOptimizer[T <: CPSTreeModule { type Name = Symbol }]
if
(
isKnownConstant
)
{
if
(
isKnownConstant
)
{
val
newBody
=
shrink
(
body
,
newState
.
withBlockVal
(
b
,
idx
,
v
))
val
newBody
=
shrink
(
body
,
newState
.
withBlockVal
(
b
,
idx
,
v
))
LetP
(
name
,
prim
,
replacedArgs
,
newBody
)
LetP
(
name
,
prim
,
replacedArgs
,
newBody
)
}
else
if
(
b
.
asName
.
filter
(
s
.
onlyWrittenTo
).
isDefined
)
{
shrink
(
body
,
s
)
}
else
{
}
else
{
noOp
noOp
}
}
...
@@ -372,8 +377,16 @@ abstract class CPSOptimizer[T <: CPSTreeModule { type Name = Symbol }]
...
@@ -372,8 +377,16 @@ abstract class CPSOptimizer[T <: CPSTreeModule { type Name = Symbol }]
atom
.
asName
.
foreach
(
incValUseN
(
_
))
atom
.
asName
.
foreach
(
incValUseN
(
_
))
def
addToCensus
(
tree
:
Tree
)
:
Unit
=
(
tree
:
@unchecked
)
match
{
def
addToCensus
(
tree
:
Tree
)
:
Unit
=
(
tree
:
@unchecked
)
match
{
case
LetP
(
_
,
_
,
args
,
body
)
=>
case
LetP
(
name
,
prim
,
args
,
body
)
=>
args
foreach
incValUseA
;
addToCensus
(
body
)
args
foreach
incValUseA
;
lazy
val
block
=
args
(
0
)
if
(
prim
==
blockSet
&&
block
.
asName
.
isDefined
)
{
val
blockName
=
block
.
asName
.
get
val
writeCount
=
census
(
blockName
)
census
(
blockName
)
=
writeCount
.
copy
(
writtenTo
=
writeCount
.
writtenTo
+
1
)
// rhs.remove(blockName).foreach(addToCensus)
}
addToCensus
(
body
)
case
LetC
(
cnts
,
body
)
=>
case
LetC
(
cnts
,
body
)
=>
rhs
++=
(
cnts
map
{
c
=>
(
c
.
name
,
c
.
body
)
});
addToCensus
(
body
)
rhs
++=
(
cnts
map
{
c
=>
(
c
.
name
,
c
.
body
)
});
addToCensus
(
body
)
case
LetF
(
funs
,
body
)
=>
case
LetF
(
funs
,
body
)
=>
...
...
compiler/src/l3/Main.scala
View file @
bfbb4735
package
l3
package
l3
import
java.io.PrintWriter
import
java.io.
{
PrintWriter
,
File
}
import
java.nio.file.
{
Files
,
Paths
}
import
java.nio.file.
{
Files
,
Paths
}
import
l3.SymbolicCL3TreeModule.Tree
import
l3.SymbolicCL3TreeModule.Tree
...
@@ -46,19 +46,29 @@ object Main {
...
@@ -46,19 +46,29 @@ object Main {
}
}
}
}
private
lazy
val
outFileWriter
=
new
PrintWriter
(
new
File
(
"output.txt"
))
private
lazy
val
outPrintWriter
=
private
lazy
val
outPrintWriter
=
new
PrintWriter
(
System
.
out
,
true
)
new
PrintWriter
(
System
.
out
,
true
)
private
def
treeChecker
[
T
<:
CPSTreeModule
](
implicit
c
:
CPSTreeChecker
[
T
])
=
private
def
treeChecker
[
T
<:
CPSTreeModule
](
implicit
c
:
CPSTreeChecker
[
T
])
=
passThrough
(
c
)
passThrough
(
c
)
private
def
treePrinter
[
T
](
msg
:
String
)(
implicit
f
:
Formatter
[
T
])
:
T
=>
T
=
private
def
treeFilePrinter
[
T
](
msg
:
String
,
o
:
PrintWriter
)(
implicit
f
:
Formatter
[
T
])
:
T
=>
T
=
passThrough
{
tree
=>
passThrough
{
tree
=>
o
utPrintWriter
.
println
(
msg
)
o
.
println
(
msg
)
f
.
toDoc
(
tree
).
writeTo
(
80
,
o
utPrintWriter
)
f
.
toDoc
(
tree
).
writeTo
(
80
,
o
)
o
utPrintWriter
.
println
()
o
.
println
()
}
}
private
def
treePrinter
[
T
](
msg
:
String
)(
implicit
f
:
Formatter
[
T
])
:
T
=>
T
=
treeFilePrinter
(
msg
,
outPrintWriter
)
private
def
treeDumper
[
T
](
msg
:
String
)(
implicit
f
:
Formatter
[
T
])
:
T
=>
T
=
treeFilePrinter
(
msg
,
outFileWriter
)
private
def
seqPrinter
[
T
](
msg
:
String
)
:
Seq
[
T
]
=>
Seq
[
T
]
=
private
def
seqPrinter
[
T
](
msg
:
String
)
:
Seq
[
T
]
=>
Seq
[
T
]
=
passThrough
{
program
=>
passThrough
{
program
=>
outPrintWriter
.
println
(
msg
)
outPrintWriter
.
println
(
msg
)
...
...
examples/blocksetelim.l3
0 → 100644
View file @
bfbb4735
(let ((p (@block-alloc-20 1))) (let ((lol (@block-set! p 0 0))) (halt 0)))
\ No newline at end of file
examples/csetest.l3
0 → 100644
View file @
bfbb4735
(let ((x 3))
(let ((y (@- x 3)) (z (@- x 3)))
(let ((w (@+ y z)))
(halt w))))
\ No newline at end of file
examples/haltuntag.l3
0 → 100644
View file @
bfbb4735
(halt (@- 1 1))
\ No newline at end of file
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