Skip to content

Commit

Permalink
add tree optimization to pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszcz committed Jan 10, 2025
1 parent a5c7388 commit 83f148d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Juvix/Compiler/Tree/Data/TransformationId.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ data TransformationId
= IdentityTrans
| IdentityU
| IdentityD
| ConvertUnaryCalls
| OptPhaseMain
| Apply
| FilterUnreachable
| Validate
Expand All @@ -24,20 +26,22 @@ data PipelineId
type TransformationLikeId = TransformationLikeId' TransformationId PipelineId

toNockmaTransformations :: [TransformationId]
toNockmaTransformations = [Validate, Apply, FilterUnreachable]
toNockmaTransformations = [Validate, OptPhaseMain, Apply, FilterUnreachable]

toAsmTransformations :: [TransformationId]
toAsmTransformations = [Validate, CheckNoAnoma, CheckNoByteArray]
toAsmTransformations = [Validate, CheckNoAnoma, CheckNoByteArray, OptPhaseMain]

toCairoAsmTransformations :: [TransformationId]
toCairoAsmTransformations = [Validate, Apply, FilterUnreachable]
toCairoAsmTransformations = [Validate, OptPhaseMain, Apply, FilterUnreachable]

instance TransformationId' TransformationId where
transformationText :: TransformationId -> Text
transformationText = \case
IdentityTrans -> strIdentity
IdentityU -> strIdentityU
IdentityD -> strIdentityD
ConvertUnaryCalls -> strConvertUnaryCalls
OptPhaseMain -> strOptPhaseMain
Apply -> strApply
FilterUnreachable -> strFilterUnreachable
Validate -> strValidate
Expand Down
6 changes: 6 additions & 0 deletions src/Juvix/Compiler/Tree/Data/TransformationId/Strings.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ strIdentityU = "identity-umap"
strIdentityD :: Text
strIdentityD = "identity-dmap"

strConvertUnaryCalls :: Text
strConvertUnaryCalls = "convert-unary-calls"

strOptPhaseMain :: Text
strOptPhaseMain = "opt-phase-main"

strApply :: Text
strApply = "apply"

Expand Down
4 changes: 4 additions & 0 deletions src/Juvix/Compiler/Tree/Transformation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import Juvix.Compiler.Tree.Transformation.CheckNoAnoma
import Juvix.Compiler.Tree.Transformation.CheckNoByteArray
import Juvix.Compiler.Tree.Transformation.FilterUnreachable
import Juvix.Compiler.Tree.Transformation.IdentityTrans
import Juvix.Compiler.Tree.Transformation.Optimize.ConvertUnaryCalls
import Juvix.Compiler.Tree.Transformation.Optimize.Phase.Main
import Juvix.Compiler.Tree.Transformation.Validate

applyTransformations :: forall r. (Members '[Error JuvixError, Reader Options] r) => [TransformationId] -> InfoTable -> Sem r InfoTable
Expand All @@ -24,6 +26,8 @@ applyTransformations ts tbl = foldM (flip appTrans) tbl ts
IdentityTrans -> return . identity
IdentityU -> return . identityU
IdentityD -> return . identityD
ConvertUnaryCalls -> return . convertUnaryCalls
OptPhaseMain -> optimize
Apply -> return . computeApply
FilterUnreachable -> return . filterUnreachable
Validate -> mapError (JuvixError @TreeError) . validate
Expand Down

0 comments on commit 83f148d

Please sign in to comment.