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
95e9f764
Commit
95e9f764
authored
Apr 30, 2021
by
Sapphie
Browse files
Implement same argument reduction, as well as CSE (currently disabled)
parent
aa62f3c2
Changes
1
Hide whitespace changes
Inline
Side-by-side
compiler/src/l3/CPSOptimizer.scala
View file @
95e9f764
...
...
@@ -107,18 +107,32 @@ abstract class CPSOptimizer[T <: CPSTreeModule { type Name = Symbol }]
val
newState
=
s
.
withExp
(
name
,
prim
,
replacedArgs
)
lazy
val
shrunkBody
=
shrink
(
body
,
newState
)
// Dead code elim
if
(
s
.
dead
(
name
)
&&
!
impure
(
prim
))
{
shrunkBody
}
else
{
val
allLitOpt
=
replacedArgs
.
map
(
_
.
asLiteral
)
val
isAllLit
=
allLitOpt
.
forall
(
_
.
isDefined
)
lazy
val
asLit
=
allLitOpt
.
map
(
_
.
get
)
if
(
isAllLit
&&
vEvaluator
.
isDefinedAt
((
prim
,
asLit
)))
{
val
newNewState
=
newState
.
withASubst
(
name
,
vEvaluator
((
prim
,
asLit
)))
val
newBody
=
shrink
(
body
,
newNewState
)
newBody
if
(
false
&&
s
.
eInvEnv
.
isDefinedAt
((
prim
,
replacedArgs
)))
{
val
preComputedAtom
=
s
.
eInvEnv
((
prim
,
replacedArgs
))
shrink
(
body
,
newState
.
withASubst
(
name
,
preComputedAtom
))
}
else
{
LetP
(
name
,
prim
,
replacedArgs
,
shrunkBody
)
// Constant folding
if
(
isAllLit
&&
vEvaluator
.
isDefinedAt
((
prim
,
asLit
)))
{
val
newNewState
=
newState
.
withASubst
(
name
,
vEvaluator
((
prim
,
asLit
)))
val
newBody
=
shrink
(
body
,
newNewState
)
newBody
}
else
{
lazy
val
x
=
replacedArgs
(
0
)
lazy
val
y
=
replacedArgs
(
1
)
if
(
replacedArgs
.
length
==
2
&&
x
==
y
&&
sameArgReduce
.
isDefinedAt
((
prim
,
x
)))
{
val
newNewState
=
newState
.
withASubst
(
name
,
sameArgReduce
((
prim
,
x
)))
shrink
(
body
,
newNewState
)
}
else
{
LetP
(
name
,
prim
,
replacedArgs
,
shrunkBody
)
}
}
}
}
}
...
...
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