-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
128 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/Juvix/Compiler/Tree/Transformation/Optimize/ConvertUnaryCalls.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
module Juvix.Compiler.Tree.Transformation.Optimize.ConvertUnaryCalls where | ||
|
||
import Juvix.Compiler.Core.Data.BinderList qualified as BL | ||
import Juvix.Compiler.Tree.Data.InfoTable | ||
import Juvix.Compiler.Tree.Extra.Recursors | ||
import Juvix.Compiler.Tree.Extra.Type | ||
import Juvix.Compiler.Tree.Transformation.Base | ||
|
||
convertUnaryCalls :: InfoTable -> InfoTable | ||
convertUnaryCalls tab = mapT convert tab | ||
where | ||
convert :: Symbol -> Node -> Node | ||
convert sym = umapL (go argtys) | ||
where | ||
funInfo = lookupFunInfo tab sym | ||
argtys | ||
| funInfo ^. functionArgsNum == 0 = [] | ||
| otherwise = typeArgs (funInfo ^. functionType) | ||
|
||
go :: [Type] -> BinderList TempVar -> Node -> Node | ||
go argtys tmps node = case node of | ||
CallClosures ncl@NodeCallClosures {..} | ||
| length _nodeCallClosuresArgs == 1 -> | ||
case _nodeCallClosuresFun of | ||
MemRef NodeMemRef {..} | ||
| DRef (ArgRef OffsetRef {..}) <- _nodeMemRef, | ||
isUnaryWithAtomicTarget (argtys !! _offsetRefOffset) -> | ||
mkClosureCall ncl | ||
| DRef (TempRef (RefTemp OffsetRef {..})) <- _nodeMemRef, | ||
isUnaryWithAtomicTarget (BL.lookupLevel _offsetRefOffset tmps ^. tempVarType) -> | ||
mkClosureCall ncl | ||
| ConstrRef (Field {..}) <- _nodeMemRef, | ||
constrInfo <- lookupConstrInfo tab _fieldTag, | ||
isUnaryWithAtomicTarget (typeArgs (constrInfo ^. constructorType) !! _fieldOffset) -> | ||
mkClosureCall ncl | ||
_ -> node | ||
_ -> node | ||
|
||
mkClosureCall :: NodeCallClosures -> Node | ||
mkClosureCall NodeCallClosures {..} = | ||
Call | ||
NodeCall | ||
{ _nodeCallInfo = _nodeCallClosuresInfo, | ||
_nodeCallType = CallClosure _nodeCallClosuresFun, | ||
_nodeCallArgs = toList _nodeCallClosuresArgs | ||
} | ||
|
||
isUnaryWithAtomicTarget :: Type -> Bool | ||
isUnaryWithAtomicTarget ty = | ||
length (typeArgs ty) == 1 | ||
&& isConcreteAtomType (typeTarget ty) |
9 changes: 9 additions & 0 deletions
9
src/Juvix/Compiler/Tree/Transformation/Optimize/Phase/Main.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Juvix.Compiler.Tree.Transformation.Optimize.Phase.Main where | ||
|
||
import Juvix.Compiler.Tree.Transformation.Base | ||
import Juvix.Compiler.Tree.Transformation.Optimize.ConvertUnaryCalls | ||
|
||
optimize :: (Member (Reader Options) r) => InfoTable -> Sem r InfoTable | ||
optimize = | ||
withOptimizationLevel 1 $ | ||
return . convertUnaryCalls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters