Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Alex D
GHC
Commits
308af7d2
Commit
308af7d2
authored
May 23, 2007
by
Michael D. Adams
Browse files
Minor re-organizing of compiler/cmm/CmmCPS.hs
parent
b3ccd6d5
Changes
1
Hide whitespace changes
Inline
Side-by-side
compiler/cmm/CmmCPS.hs
View file @
308af7d2
...
...
@@ -93,10 +93,10 @@ collectNonProcPointTargets proc_points blocks current_targets block =
-- TODO: remove redundant uniqSetToList
new_targets
=
current_targets
`
unionUniqSets
`
(
mkUniqSet
targets
)
build
Continuation
::
procPointTo
Continuation
::
UniqSet
BlockId
->
BlockEnv
BrokenBlock
->
BlockId
->
Continuation
build
Continuation
proc_points
blocks
start
=
procPointTo
Continuation
proc_points
blocks
start
=
Continuation
is_entry
info_table
clabel
params
body
where
children
=
(
collectNonProcPointTargets
proc_points
blocks
(
unitUniqSet
start
)
start
)
`
delOneFromUniqSet
`
start
...
...
@@ -119,8 +119,8 @@ buildContinuation proc_points blocks start =
--------------------------------------------------------------------------------
-- For now just select the continuation orders in the order they are in the set with no gaps
selectStackFormat
2
::
BlockEnv
CmmLive
->
[
Continuation
]
->
[(
CLabel
,
StackFormat
)]
selectStackFormat
2
live
continuations
=
selectStackFormat
::
BlockEnv
CmmLive
->
[
Continuation
]
->
[(
CLabel
,
StackFormat
)]
selectStackFormat
live
continuations
=
map
(
\
c
->
(
continuationLabel
c
,
selectStackFormat'
c
))
continuations
where
selectStackFormat'
(
Continuation
True
info_table
label
formals
blocks
)
=
...
...
@@ -142,44 +142,45 @@ selectStackFormat2 live continuations =
extend_format
(
StackFormat
label
size
offsets
)
reg
=
StackFormat
label
(
slot_size
reg
+
size
)
((
CmmLocal
reg
,
size
)
:
offsets
)
unknown_block
=
panic
"unknown BlockId in selectStackFormat"
slot_size
reg
=
((
machRepByteWidth
(
localRegRep
reg
)
-
1
)
`
div
`
wORD_SIZE
)
+
1
slot_size
::
LocalReg
->
Int
slot_size
reg
=
((
machRepByteWidth
(
localRegRep
reg
)
-
1
)
`
div
`
wORD_SIZE
)
+
1
constructContinuation
::
[(
CLabel
,
StackFormat
)]
->
Continuation
->
CmmTop
constructContinuation
formats
(
Continuation
is_entry
info
label
formals
blocks
)
=
CmmProc
info
label
formals
(
map
(
constructContinuation2'
label
formats
)
blocks
)
unknown_block
=
panic
"unknown BlockId in selectStackFormat"
constructContinuation2'
::
CLabel
->
[(
CLabel
,
StackFormat
)]
->
BrokenBlock
->
CmmBasicBlock
constructContinuation2'
curr_ident
formats
(
BrokenBlock
ident
entry
stmts
_
exit
)
=
BasicBlock
ident
(
prefix
++
stmts
++
postfix
)
continuationToProc
::
[(
CLabel
,
StackFormat
)]
->
Continuation
->
CmmTop
continuationToProc
formats
(
Continuation
is_entry
info
label
formals
blocks
)
=
CmmProc
info
label
formals
(
map
(
continuationToProc'
label
formats
)
blocks
)
where
curr_format
=
maybe
unknown_block
id
$
lookup
curr_ident
formats
unknown_block
=
panic
"unknown BlockId in constructContinuation"
prefix
=
case
entry
of
ControlEntry
->
[]
FunctionEntry
_
_
->
[]
ContinuationEntry
formals
->
unpack_continuation
curr_format
postfix
=
case
exit
of
FinalBranch
next
->
[
CmmBranch
next
]
FinalSwitch
expr
targets
->
[
CmmSwitch
expr
targets
]
FinalReturn
arguments
->
exit_function
curr_format
(
CmmLoad
(
CmmReg
spReg
)
wordRep
)
arguments
FinalJump
target
arguments
->
exit_function
curr_format
target
arguments
-- TODO: do something about global saves
FinalCall
next
(
CmmForeignCall
target
CmmCallConv
)
continuationToProc'
::
CLabel
->
[(
CLabel
,
StackFormat
)]
->
BrokenBlock
->
CmmBasicBlock
continuationToProc'
curr_ident
formats
(
BrokenBlock
ident
entry
stmts
_
exit
)
=
BasicBlock
ident
(
prefix
++
stmts
++
postfix
)
where
curr_format
=
maybe
unknown_block
id
$
lookup
curr_ident
formats
unknown_block
=
panic
"unknown BlockId in continuationToProc"
prefix
=
case
entry
of
ControlEntry
->
[]
FunctionEntry
_
_
->
[]
ContinuationEntry
formals
->
unpack_continuation
curr_format
postfix
=
case
exit
of
FinalBranch
next
->
[
CmmBranch
next
]
FinalSwitch
expr
targets
->
[
CmmSwitch
expr
targets
]
FinalReturn
arguments
->
exit_function
curr_format
(
CmmLoad
(
CmmReg
spReg
)
wordRep
)
arguments
FinalJump
target
arguments
->
exit_function
curr_format
target
arguments
-- TODO: do something about global saves
FinalCall
next
(
CmmForeignCall
target
CmmCallConv
)
results
arguments
saves
->
pack_continuation
curr_format
cont_format
++
[
CmmJump
target
arguments
]
where
cont_format
=
maybe
unknown_block
id
$
lookup
(
mkReturnPtLabel
$
getUnique
next
)
formats
FinalCall
next
_
results
arguments
saves
->
panic
"unimplemented CmmCall"
FinalCall
next
_
results
arguments
saves
->
panic
"unimplemented CmmCall"
--------------------------------------------------------------------------------
-- Functions that generate CmmStmt sequences
...
...
@@ -330,9 +331,7 @@ cmmBlockFromBrokenBlock (BrokenBlock ident _ stmts _ exit) =
cpsProc
::
UniqSupply
->
CmmTop
->
[
CmmTop
]
cpsProc
uniqSupply
x
@
(
CmmData
_
_
)
=
[
x
]
cpsProc
uniqSupply
x
@
(
CmmProc
info_table
ident
params
blocks
)
=
--[CmmProc info_table ident params cps_blocks]
cps_continuations
cpsProc
uniqSupply
x
@
(
CmmProc
info_table
ident
params
blocks
)
=
cps_procs
where
uniqes
::
[[
Unique
]]
uniqes
=
map
uniqsFromSupply
$
listSplitUniqSupply
uniqSupply
...
...
@@ -350,25 +349,21 @@ cpsProc uniqSupply x@(CmmProc info_table ident params blocks) =
proc_points
::
UniqSet
BlockId
proc_points
=
calculateProcPoints
broken_blocks
continuations
::
[
Continuation
]
continuations
=
map
(
buildContinuation
proc_points
(
blocksToBlockEnv
broken_blocks
))
(
uniqSetToList
proc_points
)
-- TODO: insert proc point code here
-- * Branches and switches to proc points may cause new blocks to be created
-- (or proc points could leave behind phantom blocks that just jump to them)
-- * Proc points might get some live variables passed as arguments
-- TODO: let blocks_with_live = map (cmmLivenessComment live . snd) broken_blocks
--procs = groupBlocksIntoContinuations live broken_blocks
continuations
::
[
Continuation
]
continuations
=
map
(
procPointToContinuation
proc_points
(
blocksToBlockEnv
broken_blocks
))
(
uniqSetToList
proc_points
)
-- Select the stack format on entry to each block
formats
2
::
[(
CLabel
,
StackFormat
)]
formats
2
=
selectStackFormat
2
live
continuations
formats
::
[(
CLabel
,
StackFormat
)]
formats
=
selectStackFormat
live
continuations
-- Do the actual CPS transform
cps_
continuation
s
::
[
CmmTop
]
cps_
continuation
s
=
map
(
con
structCon
tinuation
formats
2
)
continuations
cps_
proc
s
::
[
CmmTop
]
cps_
proc
s
=
map
(
continuation
ToProc
formats
)
continuations
--------------------------------------------------------------------------------
cmmCPS
::
DynFlags
...
...
Write
Preview
Supports
Markdown
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