Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Glasgow Haskell Compiler
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Shayne Fletcher
Glasgow Haskell Compiler
Commits
0dba52a5
Commit
0dba52a5
authored
Mar 13, 2012
by
Simon Marlow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactoring and comments
parent
643eb066
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
26 deletions
+34
-26
compiler/cmm/CmmLayoutStack.hs
compiler/cmm/CmmLayoutStack.hs
+34
-26
No files found.
compiler/cmm/CmmLayoutStack.hs
View file @
0dba52a5
...
@@ -467,7 +467,7 @@ setupStackFrame
...
@@ -467,7 +467,7 @@ setupStackFrame
->
(
StackMap
,
[
CmmNode
O
O
])
->
(
StackMap
,
[
CmmNode
O
O
])
setupStackFrame
lbl
liveness
updfr_off
ret_args
stack0
setupStackFrame
lbl
liveness
updfr_off
ret_args
stack0
=
(
cont_stack
,
assigs
)
=
(
cont_stack
,
assig
nment
s
)
where
where
-- get the set of LocalRegs live in the continuation
-- get the set of LocalRegs live in the continuation
live
=
mapFindWithDefault
Set
.
empty
lbl
liveness
live
=
mapFindWithDefault
Set
.
empty
lbl
liveness
...
@@ -482,7 +482,7 @@ setupStackFrame lbl liveness updfr_off ret_args stack0
...
@@ -482,7 +482,7 @@ setupStackFrame lbl liveness updfr_off ret_args stack0
-- everything up to updfr_off is off-limits
-- everything up to updfr_off is off-limits
-- stack1 contains updfr_off, plus everything we need to save
-- stack1 contains updfr_off, plus everything we need to save
(
stack1
,
assigs
)
=
allocate
updfr_off
live
stack0
(
stack1
,
assig
nment
s
)
=
allocate
updfr_off
live
stack0
-- And the Sp at the continuation is:
-- And the Sp at the continuation is:
-- sm_sp stack1 + ret_args
-- sm_sp stack1 + ret_args
...
@@ -498,45 +498,53 @@ setupStackFrame lbl liveness updfr_off ret_args stack0
...
@@ -498,45 +498,53 @@ setupStackFrame lbl liveness updfr_off ret_args stack0
-- This special case looks for the pattern we get from a typical
-- This special case looks for the pattern we get from a typical
-- tagged case expression:
-- tagged case expression:
--
--
-- Sp[young(L1)] = L1
--
Sp[young(L1)] = L1
-- if (R1 & 7) != 0 goto L1 else goto L2
--
if (R1 & 7) != 0 goto L1 else goto L2
-- L2:
-- L2:
-- call [R1] returns to L1
--
call [R1] returns to L1
-- L1: live: {y}
-- L1: live: {y}
-- x = R1
-- x = R1
--
--
--
-- If we let the generic case handle this, we get
-- If we let the generic case handle this, we get
--
--
-- Sp[-16] = L1
--
Sp[-16] = L1
-- if (R1 & 7) != 0 goto L1a else goto L2
--
if (R1 & 7) != 0 goto L1a else goto L2
-- L2:
-- L2:
-- Sp[-8] = y
--
Sp[-8] = y
-- Sp = Sp - 16
--
Sp = Sp - 16
-- call [R1] returns to L1
--
call [R1] returns to L1
-- L1a:
-- L1a:
-- Sp[-8] = y
--
Sp[-8] = y
-- Sp = Sp - 16
--
Sp = Sp - 16
-- goto L1
--
goto L1
-- L1:
-- L1:
-- x = R1
--
x = R1
--
--
-- The code for saving the live vars is duplicated in each branch, and
-- The code for saving the live vars is duplicated in each branch, and
-- furthermore there is an extra jump (assuming L1 is a proc point,
-- furthermore there is an extra jump in the fast path (assuming L1 is
-- which it probably is if there is a heap check).
-- a proc point, which it probably is if there is a heap check).
--
-- So to fix this we want to set up the stack frame before the
-- conditional jump. How do we know when to do this, and when it is
-- safe? The basic idea is, when we see the assignment
--
-- Sp[young(L)] = L
--
-- we know that
-- * we are definitely heading for L
-- * there can be no more reads from another stack area, because young(L)
-- overlaps with it.
--
-- We don't necessarily know that everything live at L is live now
-- (some might be assigned between here and the jump to L). So we
-- simplify and only do the optimisation when we see
--
--
-- So to fix this we look for
-- (1) a block containing an assignment of a return address L
-- (1) a block containing an assignment of a return address L
-- (2) ending in a branch where one (and only) continuation goes to L,
-- (2) ending in a branch where one (and only) continuation goes to L,
-- and no other continuations go to proc points.
-- and no other continuations go to proc points.
--
--
-- If this happens, then we allocate the stack frame for L in the
-- then we allocate the stack frame for L at the end of the block,
-- current block.
-- before the branch.
--
-- We know that it is safe to allocate the stack frame and save the
-- live variables after the assignment of the return address, because
-- stack areas are defined as overlapping, so there can be no reads
-- from other stack areas after the return address assignment.
--
--
-- We could generalise (2), but that would make it a bit more
-- We could generalise (2), but that would make it a bit more
-- complicated to handle, and this currently catches the common case.
-- complicated to handle, and this currently catches the common case.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment