Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compute temporary stack height in JuvixTree #2596

Merged
merged 1 commit into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Juvix/Compiler/Asm/Pipeline.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ toReg' = validate >=> filterUnreachable >=> computeStackUsage >=> computePreallo
-- | Perform transformations on JuvixAsm necessary before the translation to
-- Nockma
toNockma' :: (Members '[Error AsmError, Reader Options] r) => InfoTable -> Sem r InfoTable
toNockma' = validate >=> filterUnreachable >=> computeTempHeight
toNockma' = validate >=> filterUnreachable

toReg :: (Members '[Error JuvixError, Reader EntryPoint] r) => InfoTable -> Sem r InfoTable
toReg = mapReader fromEntryPoint . mapError (JuvixError @AsmError) . toReg'
Expand Down
2 changes: 0 additions & 2 deletions src/Juvix/Compiler/Asm/Transformation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ module Juvix.Compiler.Asm.Transformation
module Juvix.Compiler.Asm.Transformation.Prealloc,
module Juvix.Compiler.Asm.Transformation.Validate,
module Juvix.Compiler.Asm.Transformation.FilterUnreachable,
module Juvix.Compiler.Asm.Transformation.TempHeight,
)
where

import Juvix.Compiler.Asm.Transformation.FilterUnreachable
import Juvix.Compiler.Asm.Transformation.Prealloc
import Juvix.Compiler.Asm.Transformation.StackUsage
import Juvix.Compiler.Asm.Transformation.TempHeight
import Juvix.Compiler.Asm.Transformation.Validate
75 changes: 0 additions & 75 deletions src/Juvix/Compiler/Asm/Transformation/TempHeight.hs

This file was deleted.

4 changes: 3 additions & 1 deletion src/Juvix/Compiler/Tree/Data/TransformationId.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ data TransformationId
| IdentityU
| IdentityD
| Apply
| TempHeight
deriving stock (Data, Bounded, Enum, Show)

data PipelineId
Expand All @@ -19,7 +20,7 @@ data PipelineId
type TransformationLikeId = TransformationLikeId' TransformationId PipelineId

toNockmaTransformations :: [TransformationId]
toNockmaTransformations = [Apply]
toNockmaTransformations = [Apply, TempHeight]

toAsmTransformations :: [TransformationId]
toAsmTransformations = []
Expand All @@ -31,6 +32,7 @@ instance TransformationId' TransformationId where
IdentityU -> strIdentityU
IdentityD -> strIdentityD
Apply -> strApply
TempHeight -> strTempHeight

instance PipelineId' TransformationId PipelineId where
pipelineText :: PipelineId -> Text
Expand Down
3 changes: 3 additions & 0 deletions src/Juvix/Compiler/Tree/Data/TransformationId/Strings.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ strIdentityD = "identity-dmap"

strApply :: Text
strApply = "apply"

strTempHeight :: Text
strTempHeight = "temp-height"
2 changes: 2 additions & 0 deletions src/Juvix/Compiler/Tree/Transformation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Juvix.Compiler.Tree.Data.TransformationId
import Juvix.Compiler.Tree.Transformation.Apply
import Juvix.Compiler.Tree.Transformation.Base
import Juvix.Compiler.Tree.Transformation.Identity
import Juvix.Compiler.Tree.Transformation.TempHeight

applyTransformations :: forall r. [TransformationId] -> InfoTable -> Sem r InfoTable
applyTransformations ts tbl = foldM (flip appTrans) tbl ts
Expand All @@ -19,3 +20,4 @@ applyTransformations ts tbl = foldM (flip appTrans) tbl ts
IdentityU -> return . identityU
IdentityD -> return . identityD
Apply -> return . computeApply
TempHeight -> return . computeTempHeight
25 changes: 25 additions & 0 deletions src/Juvix/Compiler/Tree/Transformation/TempHeight.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module Juvix.Compiler.Tree.Transformation.TempHeight where

import Juvix.Compiler.Tree.Extra.Recursors
import Juvix.Compiler.Tree.Transformation.Base

computeFunctionTempHeight :: Node -> Node
computeFunctionTempHeight = umapN go
where
go :: Int -> Node -> Node
go k = \case
MemRef (DRef (TempRef r)) ->
let r' = set refTempTempHeight (Just k) r
in MemRef $ DRef (TempRef r')
MemRef (ConstrRef field@Field {_fieldRef = TempRef r}) ->
let r' = set refTempTempHeight (Just k) r
in MemRef
( ConstrRef
field
{ _fieldRef = TempRef r'
}
)
node -> node

computeTempHeight :: InfoTable -> InfoTable
computeTempHeight = mapT (const computeFunctionTempHeight)
Loading