From 83f148dc641f346b3f324c6041a6de2485df2e7f Mon Sep 17 00:00:00 2001 From: Lukasz Czajka Date: Tue, 7 Jan 2025 18:37:50 +0100 Subject: [PATCH] add tree optimization to pipeline --- src/Juvix/Compiler/Tree/Data/TransformationId.hs | 10 +++++++--- .../Compiler/Tree/Data/TransformationId/Strings.hs | 6 ++++++ src/Juvix/Compiler/Tree/Transformation.hs | 4 ++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Juvix/Compiler/Tree/Data/TransformationId.hs b/src/Juvix/Compiler/Tree/Data/TransformationId.hs index 86f2437401..8dccc5daae 100644 --- a/src/Juvix/Compiler/Tree/Data/TransformationId.hs +++ b/src/Juvix/Compiler/Tree/Data/TransformationId.hs @@ -8,6 +8,8 @@ data TransformationId = IdentityTrans | IdentityU | IdentityD + | ConvertUnaryCalls + | OptPhaseMain | Apply | FilterUnreachable | Validate @@ -24,13 +26,13 @@ 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 @@ -38,6 +40,8 @@ instance TransformationId' TransformationId where IdentityTrans -> strIdentity IdentityU -> strIdentityU IdentityD -> strIdentityD + ConvertUnaryCalls -> strConvertUnaryCalls + OptPhaseMain -> strOptPhaseMain Apply -> strApply FilterUnreachable -> strFilterUnreachable Validate -> strValidate diff --git a/src/Juvix/Compiler/Tree/Data/TransformationId/Strings.hs b/src/Juvix/Compiler/Tree/Data/TransformationId/Strings.hs index 8b270ccc27..060394cae5 100644 --- a/src/Juvix/Compiler/Tree/Data/TransformationId/Strings.hs +++ b/src/Juvix/Compiler/Tree/Data/TransformationId/Strings.hs @@ -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" diff --git a/src/Juvix/Compiler/Tree/Transformation.hs b/src/Juvix/Compiler/Tree/Transformation.hs index 2af38010bf..7bc8ff633c 100644 --- a/src/Juvix/Compiler/Tree/Transformation.hs +++ b/src/Juvix/Compiler/Tree/Transformation.hs @@ -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 @@ -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