Skip to content

Commit

Permalink
cleanup cairo
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszcz authored and paulcadman committed Jun 26, 2024
1 parent 76a5918 commit 3e833e4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/Juvix/Compiler/Reg/Data/TransformationId.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Juvix.Prelude

data TransformationId
= IdentityTrans
| CleanupCairo
| Cleanup
| SSA
| InitBranchVars
Expand Down Expand Up @@ -33,12 +34,13 @@ toRustTransformations :: [TransformationId]
toRustTransformations = [Cleanup]

toCasmTransformations :: [TransformationId]
toCasmTransformations = [Cleanup, SSA, OptPhaseCairo]
toCasmTransformations = [CleanupCairo, SSA, OptPhaseCairo]

instance TransformationId' TransformationId where
transformationText :: TransformationId -> Text
transformationText = \case
IdentityTrans -> strIdentity
CleanupCairo -> strCleanupCairo
Cleanup -> strCleanup
SSA -> strSSA
InitBranchVars -> strInitBranchVars
Expand Down
3 changes: 3 additions & 0 deletions src/Juvix/Compiler/Reg/Data/TransformationId/Strings.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ strIdentity = "identity"
strCleanup :: Text
strCleanup = "cleanup"

strCleanupCairo :: Text
strCleanupCairo = "cleanup-cairo"

strSSA :: Text
strSSA = "ssa"

Expand Down
1 change: 1 addition & 0 deletions src/Juvix/Compiler/Reg/Transformation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ applyTransformations ts tbl = foldM (flip appTrans) tbl ts
appTrans = \case
IdentityTrans -> return . identity
Cleanup -> return . cleanup
CleanupCairo -> return . cleanup' True
SSA -> return . computeSSA
InitBranchVars -> return . initBranchVars
CopyPropagation -> return . copyPropagate
Expand Down
10 changes: 8 additions & 2 deletions src/Juvix/Compiler/Reg/Transformation/Cleanup.hs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
module Juvix.Compiler.Reg.Transformation.Cleanup where

import Juvix.Compiler.Reg.Extra.Base (updateLiveVars')
import Juvix.Compiler.Reg.Extra.Recursors
import Juvix.Compiler.Reg.Transformation.Base
import Juvix.Compiler.Tree.Extra.Rep

cleanup :: InfoTable -> InfoTable
cleanup tab = mapT (const (cmap go)) tab
cleanup' :: Bool -> InfoTable -> InfoTable
cleanup' bCairo tab = mapT (const (cmap go)) tab
where
go :: Code -> Code
go = \case
Expand All @@ -17,4 +18,9 @@ cleanup tab = mapT (const (cmap go)) tab
_caseBranchCode ++ is
[] ->
fromJust _instrCaseDefault ++ is
Prealloc {} : is | bCairo -> is
i : is | bCairo -> updateLiveVars' (const Nothing) i : is
is -> is

cleanup :: InfoTable -> InfoTable
cleanup = cleanup' False

0 comments on commit 3e833e4

Please sign in to comment.