Skip to content
GitLab
Menu
Projects
Groups
Snippets
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
63f24da2
Commit
63f24da2
authored
May 04, 2021
by
Luca Bataillard
Browse files
fix constant folding (all tests pass)
parent
79a9e1d0
Changes
1
Hide whitespace changes
Inline
Side-by-side
compiler/src/l3/CPSOptimizer.scala
View file @
63f24da2
...
...
@@ -9,7 +9,7 @@ abstract class CPSOptimizer[T <: CPSTreeModule { type Name = Symbol }]
protected
def
rewrite
(
tree
:
Tree
)
:
Tree
=
{
val
simplifiedTree
=
fixedPoint
(
tree
)(
shrink
)
val
maxSize
=
size
(
simplifiedTree
)
*
3
/
2
fixedPoint
(
simplifiedTree
,
2
)
{
t
=>
inline
(
t
,
maxSize
)
}
fixedPoint
(
simplifiedTree
,
8
)
{
t
=>
inline
(
t
,
maxSize
)
}
}
private
case
class
Count
(
applied
:
Int
=
0
,
asValue
:
Int
=
0
)
...
...
@@ -168,7 +168,7 @@ abstract class CPSOptimizer[T <: CPSTreeModule { type Name = Symbol }]
val
newArgs
=
replaceArgs
(
args
,
s
)
def
getApp
(
b
:
Boolean
)
:
AppC
=
{
val
contToUse
=
if
(
b
)
thenC
else
elseC
AppC
(
contToUse
,
newArgs
)
AppC
(
contToUse
,
Seq
()
)
}
val
allLitOpt
=
newArgs
.
map
(
_
.
asLiteral
)
val
isAllLit
=
allLitOpt
.
forall
(
_
.
isDefined
)
...
...
@@ -271,7 +271,6 @@ abstract class CPSOptimizer[T <: CPSTreeModule { type Name = Symbol }]
val
notUsedAsValue
=
s
.
census
.
get
(
oldFun
.
name
).
fold
(
false
)(
count
=>
count
.
asValue
==
0
)
val
nonRecursive
=
notUsedAsValue
&&
!
census
(
oldFun
.
body
).
contains
(
oldFun
.
name
)
/* TODO ask about stopping inlining of recursive functions */
if
(
nonRecursive
&&
sameLen
(
oldFun
.
args
,
args
))
{
val
fun
=
copyF
(
oldFun
,
s
.
aSubst
,
s
.
cSubst
)
val
newState
=
s
.
withASubst
(
fun
.
args
,
args
).
withCSubst
(
fun
.
retC
,
retC
)
...
...
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