Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
GHC
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
Alex D
GHC
Commits
7bff9fa8
Commit
7bff9fa8
authored
Aug 09, 2012
by
Simon Marlow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor flattenCmmAGraph
parent
987710c1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
17 deletions
+20
-17
compiler/cmm/MkGraph.hs
compiler/cmm/MkGraph.hs
+20
-17
No files found.
compiler/cmm/MkGraph.hs
View file @
7bff9fa8
...
...
@@ -69,34 +69,38 @@ flattenCmmAGraph id stmts =
CmmGraph
{
g_entry
=
id
,
g_graph
=
GMany
NothingO
body
NothingO
}
where
blocks
=
flatten1
(
fromOL
stmts
)
(
blockJoinHead
(
CmmEntry
id
)
emptyBlock
)
[]
body
=
foldr
addBlock
emptyBody
blocks
body
=
foldr
addBlock
emptyBody
$
flatten
id
stmts
[]
--
-- flatten: turn a list of CgStmt into a list of Blocks. We know
-- that any code before the first label is unreachable, so just drop
-- it.
-- flatten: given an entry label and a CmmAGraph, make a list of blocks.
--
-- NB. avoid the quadratic-append trap by passing in the tail of the
-- list. This is important for Very Long Functions (e.g. in T783).
--
flatten
::
[
CgStmt
]
->
[
Block
CmmNode
C
C
]
->
[
Block
CmmNode
C
C
]
flatten
[]
blocks
=
blocks
flatten
::
Label
->
CmmAGraph
->
[
Block
CmmNode
C
C
]
->
[
Block
CmmNode
C
C
]
flatten
id
g
blocks
=
flatten1
(
fromOL
g
)
(
blockJoinHead
(
CmmEntry
id
)
emptyBlock
)
blocks
flatten
(
CgLabel
id
:
stmts
)
blocks
--
-- flatten0: we are outside a block at this point: any code before
-- the first label is unreachable, so just drop it.
--
flatten0
::
[
CgStmt
]
->
[
Block
CmmNode
C
C
]
->
[
Block
CmmNode
C
C
]
flatten0
[]
blocks
=
blocks
flatten0
(
CgLabel
id
:
stmts
)
blocks
=
flatten1
stmts
block
blocks
where
!
block
=
blockJoinHead
(
CmmEntry
id
)
emptyBlock
flatten
(
CgFork
fork_id
stmts
:
rest
)
blocks
=
flatten1
(
fromOL
stmts
)
(
blockJoinHead
(
CmmEntry
fork_id
)
emptyBlock
)
$
flatten
rest
blocks
flatten0
(
CgFork
fork_id
stmts
:
rest
)
blocks
=
flatten
fork_id
stmts
$
flatten0
rest
blocks
flatten
(
CgLast
_
:
stmts
)
blocks
=
flatten
stmts
blocks
flatten
(
CgStmt
_
:
stmts
)
blocks
=
flatten
stmts
blocks
flatten
0
(
CgLast
_
:
stmts
)
blocks
=
flatten0
stmts
blocks
flatten
0
(
CgStmt
_
:
stmts
)
blocks
=
flatten0
stmts
blocks
--
-- flatten1: we have a partial block, collect statements until the
-- next last node to make a block, then call flatten to get the rest
-- next last node to make a block, then call flatten
0
to get the rest
-- of the blocks
--
flatten1
::
[
CgStmt
]
->
Block
CmmNode
C
O
...
...
@@ -112,7 +116,7 @@ flattenCmmAGraph id stmts =
=
blockJoinTail
block
(
CmmBranch
(
entryLabel
block
))
:
blocks
flatten1
(
CgLast
stmt
:
stmts
)
block
blocks
=
block'
:
flatten
stmts
blocks
=
block'
:
flatten
0
stmts
blocks
where
!
block'
=
blockJoinTail
block
stmt
flatten1
(
CgStmt
stmt
:
stmts
)
block
blocks
...
...
@@ -120,8 +124,7 @@ flattenCmmAGraph id stmts =
where
!
block'
=
blockSnoc
block
stmt
flatten1
(
CgFork
fork_id
stmts
:
rest
)
block
blocks
=
flatten1
(
fromOL
stmts
)
(
blockJoinHead
(
CmmEntry
fork_id
)
emptyBlock
)
$
flatten1
rest
block
blocks
=
flatten
fork_id
stmts
$
flatten1
rest
block
blocks
-- a label here means that we should start a new block, and the
-- current block should fall through to the new block.
...
...
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