1 {-# LANGUAGE GADTs, DisambiguateRecordFields #-}
2 {-# OPTIONS_GHC -fno-warn-warnings-deprecations #-}
4 module CmmProcPoint
5 ( ProcPointSet, Status(..)
6 , callProcPoints, minimalProcPointSet
7 , addProcPointProtocols, splitAtProcPoints, procPointAnalysis
8 )
9 where
11 import Prelude hiding (last, unzip, succ, zip)
13 import BlockId
14 import CLabel
15 import Cmm
16 import CmmExpr
17 import CmmUtils
18 import CmmContFlowOpt
19 import CmmInfo
20 import CmmLive
21 import Constants
22 import Data.List (sortBy)
23 import Maybes
24 import MkGraph
25 import Control.Monad
26 import OptimizationFuel
27 import Outputable
28 import Platform
29 import UniqSet
30 import UniqSupply
32 import Compiler.Hoopl
34 import qualified Data.Map as Map
36 -- Compute a minimal set of proc points for a control-flow graph.
38 -- Determine a protocol for each proc point (which live variables will
39 -- be passed as arguments and which will be on the stack).
41 {-
42 A proc point is a basic block that, after CPS transformation, will
43 start a new function. The entry block of the original function is a
44 proc point, as is the continuation of each function call.
45 A third kind of proc point arises if we want to avoid copying code.
46 Suppose we have code like the following:
48 f() {
49 if (...) { ..1..; call foo(); ..2..}
50 else { ..3..; call bar(); ..4..}
51 x = y + z;
52 return x;
53 }
55 The statement 'x = y + z' can be reached from two different proc
56 points: the continuations of foo() and bar(). We would prefer not to
57 put a copy in each continuation; instead we would like 'x = y + z' to
58 be the start of a new procedure to which the continuations can jump:
60 f_cps () {
61 if (...) { ..1..; push k_foo; jump foo_cps(); }
62 else { ..3..; push k_bar; jump bar_cps(); }
63 }
64 k_foo() { ..2..; jump k_join(y, z); }
65 k_bar() { ..4..; jump k_join(y, z); }
66 k_join(y, z) { x = y + z; return x; }
68 You might think then that a criterion to make a node a proc point is
69 that it is directly reached by two distinct proc points. (Note
70 [Direct reachability].) But this criterion is a bit too simple; for
71 example, 'return x' is also reached by two proc points, yet there is
72 no point in pulling it out of k_join. A good criterion would be to
73 say that a node should be made a proc point if it is reached by a set
74 of proc points that is different than its immediate dominator. NR
75 believes this criterion can be shown to produce a minimum set of proc
76 points, and given a dominator tree, the proc points can be chosen in
77 time linear in the number of blocks. Lacking a dominator analysis,
78 however, we turn instead to an iterative solution, starting with no
79 proc points and adding them according to these rules:
81 1. The entry block is a proc point.
82 2. The continuation of a call is a proc point.
83 3. A node is a proc point if it is directly reached by more proc
84 points than one of its predecessors.
86 Because we don't understand the problem very well, we apply rule 3 at
87 most once per iteration, then recompute the reachability information.
88 (See Note [No simple dataflow].) The choice of the new proc point is
89 arbitrary, and I don't know if the choice affects the final solution,
90 so I don't know if the number of proc points chosen is the
91 minimum---but the set will be minimal.
92 -}
94 type ProcPointSet = BlockSet
96 data Status
97 = ReachedBy ProcPointSet -- set of proc points that directly reach the block
98 | ProcPoint -- this block is itself a proc point
100 instance Outputable Status where
101 ppr (ReachedBy ps)
102 | setNull ps = text "<not-reached>"
103 | otherwise = text "reached by" <+>
104 (hsep \$ punctuate comma \$ map ppr \$ setElems ps)
105 ppr ProcPoint = text "<procpt>"
107 lattice :: DataflowLattice Status
108 lattice = DataflowLattice "direct proc-point reachability" unreached add_to
109 where unreached = ReachedBy setEmpty
110 add_to _ (OldFact ProcPoint) _ = (NoChange, ProcPoint)
111 add_to _ _ (NewFact ProcPoint) = (SomeChange, ProcPoint) -- because of previous case
112 add_to _ (OldFact (ReachedBy p)) (NewFact (ReachedBy p')) =
113 let union = setUnion p' p
114 in if setSize union > setSize p then (SomeChange, ReachedBy union)
115 else (NoChange, ReachedBy p)
116 --------------------------------------------------
117 -- transfer equations
119 forward :: FwdTransfer CmmNode Status
120 forward = mkFTransfer3 first middle ((mkFactBase lattice . ) . last)
121 where first :: CmmNode C O -> Status -> Status
122 first (CmmEntry id) ProcPoint = ReachedBy \$ setSingleton id
123 first _ x = x
125 middle _ x = x
127 last :: CmmNode O C -> Status -> [(Label, Status)]
128 last (CmmCall {cml_cont = Just k}) _ = [(k, ProcPoint)]
129 last (CmmForeignCall {succ = k}) _ = [(k, ProcPoint)]
130 last l x = map (\id -> (id, x)) (successors l)
132 -- It is worth distinguishing two sets of proc points:
133 -- those that are induced by calls in the original graph
134 -- and those that are introduced because they're reachable from multiple proc points.
135 callProcPoints :: CmmGraph -> ProcPointSet
136 callProcPoints g = foldGraphBlocks add (setSingleton (g_entry g)) g
137 where add :: CmmBlock -> BlockSet -> BlockSet
138 add b set = case lastNode b of
139 CmmCall {cml_cont = Just k} -> setInsert k set
140 CmmForeignCall {succ=k} -> setInsert k set
141 _ -> set
143 minimalProcPointSet :: Platform -> ProcPointSet -> CmmGraph -> FuelUniqSM ProcPointSet
144 -- Given the set of successors of calls (which must be proc-points)
145 -- figure out the minimal set of necessary proc-points
146 minimalProcPointSet platform callProcPoints g = extendPPSet platform g (postorderDfs g) callProcPoints
148 procPointAnalysis :: ProcPointSet -> CmmGraph -> FuelUniqSM (BlockEnv Status)
149 -- Once you know what the proc-points are, figure out
150 -- what proc-points each block is reachable from
151 procPointAnalysis procPoints g =
152 liftM snd \$ dataflowPassFwd g initProcPoints \$ analFwd lattice forward
153 where initProcPoints = [(id, ProcPoint) | id <- setElems procPoints]
155 extendPPSet :: Platform -> CmmGraph -> [CmmBlock] -> ProcPointSet -> FuelUniqSM ProcPointSet
156 extendPPSet platform g blocks procPoints =
157 do env <- procPointAnalysis procPoints g
158 let add block pps = let id = entryLabel block
159 in case mapLookup id env of
160 Just ProcPoint -> setInsert id pps
161 _ -> pps
162 procPoints' = foldGraphBlocks add setEmpty g
163 newPoints = mapMaybe ppSuccessor blocks
164 newPoint = listToMaybe newPoints
165 ppSuccessor b =
166 let nreached id = case mapLookup id env `orElse`
167 pprPanic "no ppt" (ppr id <+> pprPlatform platform b) of
168 ProcPoint -> 1
169 ReachedBy ps -> setSize ps
170 block_procpoints = nreached (entryLabel b)
171 -- | Looking for a successor of b that is reached by
172 -- more proc points than b and is not already a proc
173 -- point. If found, it can become a proc point.
174 newId succ_id = not (setMember succ_id procPoints') &&
175 nreached succ_id > block_procpoints
176 in listToMaybe \$ filter newId \$ successors b
177 {-
178 case newPoints of
179 [] -> return procPoints'
180 pps -> extendPPSet g blocks
181 (foldl extendBlockSet procPoints' pps)
182 -}
183 case newPoint of Just id ->
184 if setMember id procPoints' then panic "added old proc pt"
185 else extendPPSet platform g blocks (setInsert id procPoints')
186 Nothing -> return procPoints'
189 ------------------------------------------------------------------------
190 -- Computing Proc-Point Protocols --
191 ------------------------------------------------------------------------
193 {-
195 There is one major trick, discovered by Michael Adams, which is that
196 we want to choose protocols in a way that enables us to optimize away
197 some continuations. The optimization is very much like branch-chain
198 elimination, except that it involves passing results as well as
199 control. The idea is that if a call's continuation k does nothing but
200 CopyIn its results and then goto proc point P, the call's continuation
201 may be changed to P, *provided* P's protocol is identical to the
202 protocol for the CopyIn. We choose protocols to make this so.
204 Here's an explanatory example; we begin with the source code (lines
205 separate basic blocks):
207 ..1..;
208 x, y = g();
209 goto P;
210 -------
211 P: ..2..;
213 Zipperization converts this code as follows:
215 ..1..;
216 call g() returns to k;
217 -------
218 k: CopyIn(x, y);
219 goto P;
220 -------
221 P: ..2..;
223 What we'd like to do is assign P the same CopyIn protocol as k, so we
224 can eliminate k:
226 ..1..;
227 call g() returns to P;
228 -------
229 P: CopyIn(x, y); ..2..;
231 Of course, P may be the target of more than one continuation, and
232 different continuations may have different protocols. Michael Adams
233 implemented a voting mechanism, but he thinks a simple greedy
234 algorithm would be just as good, so that's what we do.
236 -}
238 data Protocol = Protocol Convention [CmmFormal] Area
239 deriving Eq
240 instance Outputable Protocol where
241 ppr (Protocol c fs a) = text "Protocol" <+> ppr c <+> ppr fs <+> ppr a
243 -- | Function 'optimize_calls' chooses protocols only for those proc
244 -- points that are relevant to the optimization explained above.
245 -- The others are assigned by 'add_unassigned', which is not yet clever.
247 addProcPointProtocols :: ProcPointSet -> ProcPointSet -> CmmGraph -> FuelUniqSM CmmGraph
248 addProcPointProtocols callPPs procPoints g =
249 do liveness <- cmmLiveness g
250 (protos, g') <- optimize_calls liveness g
251 blocks'' <- add_CopyOuts protos procPoints g'
252 return \$ ofBlockMap (g_entry g) blocks''
253 where optimize_calls liveness g = -- see Note [Separate Adams optimization]
254 do let (protos, blocks') =
255 foldGraphBlocks maybe_add_call (mapEmpty, mapEmpty) g
256 protos' = add_unassigned liveness procPoints protos
257 let g' = ofBlockMap (g_entry g) (add_CopyIns callPPs protos' blocks')
258 return (protos', removeUnreachableBlocks g')
259 maybe_add_call :: CmmBlock -> (BlockEnv Protocol, BlockEnv CmmBlock)
260 -> (BlockEnv Protocol, BlockEnv CmmBlock)
261 -- ^ If the block is a call whose continuation goes to a proc point
262 -- whose protocol either matches the continuation's or is not yet set,
263 -- redirect the call (cf 'newblock') and set the protocol if necessary
264 maybe_add_call block (protos, blocks) =
265 case lastNode block of
266 CmmCall tgt (Just k) args res s
267 | Just proto <- mapLookup k protos,
268 Just pee <- branchesToProcPoint k
269 -> let newblock = replaceLastNode block (CmmCall tgt (Just pee)
270 args res s)
271 changed_blocks = insertBlock newblock blocks
272 unchanged_blocks = insertBlock block blocks
273 in case mapLookup pee protos of
274 Nothing -> (mapInsert pee proto protos, changed_blocks)
275 Just proto' ->
276 if proto == proto' then (protos, changed_blocks)
277 else (protos, unchanged_blocks)
278 _ -> (protos, insertBlock block blocks)
280 branchesToProcPoint :: BlockId -> Maybe BlockId
281 -- ^ Tells whether the named block is just a branch to a proc point
282 branchesToProcPoint id =
283 let block = mapLookup id (toBlockMap g) `orElse`
284 panic "branch out of graph"
285 in case blockToNodeList block of
286 -- MS: There is an ugly bug in ghc-6.10, which rejects following valid code.
287 -- After trying several tricks, the NOINLINE on getItOut worked. Uffff.
288 #if __GLASGOW_HASKELL__ >= 612
289 (_, [], JustC (CmmBranch pee)) | setMember pee procPoints -> Just pee
290 _ -> Nothing
291 #else
292 (_, [], exit) | CmmBranch pee <- getItOut exit
293 , setMember pee procPoints -> Just pee
294 _ -> Nothing
295 where {-# NOINLINE getItOut #-}
296 getItOut :: MaybeC C a -> a
297 getItOut (JustC a) = a
298 #endif
300 -- | For now, following a suggestion by Ben Lippmeier, we pass all
301 -- live variables as arguments, hoping that a clever register
302 -- allocator might help.
304 add_unassigned :: BlockEnv CmmLive -> ProcPointSet -> BlockEnv Protocol ->
305 BlockEnv Protocol
306 add_unassigned = pass_live_vars_as_args
308 pass_live_vars_as_args :: BlockEnv CmmLive -> ProcPointSet ->
309 BlockEnv Protocol -> BlockEnv Protocol
310 pass_live_vars_as_args _liveness procPoints protos = protos'
311 where protos' = setFold addLiveVars protos procPoints
312 addLiveVars :: BlockId -> BlockEnv Protocol -> BlockEnv Protocol
313 addLiveVars id protos =
314 case mapLookup id protos of
315 Just _ -> protos
316 Nothing -> let live = emptyRegSet
317 --lookupBlockEnv _liveness id `orElse`
318 --panic ("no liveness at block " ++ show id)
319 formals = uniqSetToList live
320 prot = Protocol Private formals \$ CallArea \$ Young id
321 in mapInsert id prot protos
324 -- | Add copy-in instructions to each proc point that did not arise from a call
325 -- instruction. (Proc-points that arise from calls already have their copy-in instructions.)
327 add_CopyIns :: ProcPointSet -> BlockEnv Protocol -> BlockEnv CmmBlock -> BlockEnv CmmBlock
328 add_CopyIns callPPs protos blocks = mapFold maybe_insert_CopyIns mapEmpty blocks
329 where maybe_insert_CopyIns block blocks
330 | not \$ setMember bid callPPs
331 , Just (Protocol c fs _area) <- mapLookup bid protos
332 = let nodes = copyInSlot c fs
333 (h, m, l) = blockToNodeList block
334 in insertBlock (blockOfNodeList (h, nodes ++ m, l)) blocks
335 | otherwise = insertBlock block blocks
336 where bid = entryLabel block
339 -- | Add a CopyOut node before each procpoint.
340 -- If the predecessor is a call, then the copy outs should already be done by the callee.
341 -- Note: If we need to add copy-out instructions, they may require stack space,
342 -- so we accumulate a map from the successors to the necessary stack space,
343 -- then update the successors after we have finished inserting the copy-outs.
345 add_CopyOuts :: BlockEnv Protocol -> ProcPointSet -> CmmGraph ->
346 FuelUniqSM (BlockEnv CmmBlock)
347 add_CopyOuts protos procPoints g = foldGraphBlocks mb_copy_out (return mapEmpty) g
348 where mb_copy_out :: CmmBlock -> FuelUniqSM (BlockEnv CmmBlock) ->
349 FuelUniqSM (BlockEnv CmmBlock)
350 mb_copy_out b z | entryLabel b == g_entry g = skip b z
351 mb_copy_out b z =
352 case lastNode b of
353 CmmCall {} -> skip b z -- copy out done by callee
354 CmmForeignCall {} -> skip b z -- copy out done by callee
355 _ -> copy_out b z
356 copy_out b z = foldr trySucc init (successors b) >>= finish
357 where init = (\bmap -> (b, bmap)) `liftM` z
358 trySucc succId z =
359 if setMember succId procPoints then
360 case mapLookup succId protos of
361 Nothing -> z
362 Just (Protocol c fs _area) -> insert z succId \$ copyOutSlot c fs
363 else z
364 insert z succId m =
365 do (b, bmap) <- z
366 (b, bs) <- insertBetween b m succId
367 -- pprTrace "insert for succ" (ppr succId <> ppr m) \$ do
368 return \$ (b, foldl (flip insertBlock) bmap bs)
369 finish (b, bmap) = return \$ insertBlock b bmap
370 skip b bs = insertBlock b `liftM` bs
372 -- At this point, we have found a set of procpoints, each of which should be
373 -- the entry point of a procedure.
374 -- Now, we create the procedure for each proc point,
375 -- which requires that we:
376 -- 1. build a map from proc points to the blocks reachable from the proc point
377 -- 2. turn each branch to a proc point into a jump
378 -- 3. turn calls and returns into jumps
379 -- 4. build info tables for the procedures -- and update the info table for
380 -- the SRTs in the entry procedure as well.
381 -- Input invariant: A block should only be reachable from a single ProcPoint.
382 -- ToDo: use the _ret naming convention that the old code generator
383 -- used. -- EZY
384 splitAtProcPoints :: CLabel -> ProcPointSet-> ProcPointSet -> BlockEnv Status ->
385 CmmTop -> FuelUniqSM [CmmTop]
386 splitAtProcPoints entry_label callPPs procPoints procMap
387 (CmmProc (TopInfo {info_tbl=info_tbl,
388 stack_info=stack_info})
389 top_l g@(CmmGraph {g_entry=entry})) =
390 do -- Build a map from procpoints to the blocks they reach
391 let addBlock b graphEnv =
392 case mapLookup bid procMap of
393 Just ProcPoint -> add graphEnv bid bid b
394 Just (ReachedBy set) ->
395 case setElems set of
396 [] -> graphEnv
397 [id] -> add graphEnv id bid b
398 _ -> panic "Each block should be reachable from only one ProcPoint"
399 Nothing -> pprPanic "block not reached by a proc point?" (ppr bid)
400 where bid = entryLabel b
401 add graphEnv procId bid b = mapInsert procId graph' graphEnv
402 where graph = mapLookup procId graphEnv `orElse` mapEmpty
403 graph' = mapInsert bid b graph
404 graphEnv <- return \$ foldGraphBlocks addBlock emptyBlockMap g
405 -- Build a map from proc point BlockId to pairs of:
406 -- * Labels for their new procedures
407 -- * Labels for the info tables of their new procedures (only if the proc point is a callPP)
408 -- Due to common blockification, we may overestimate the set of procpoints.
409 let add_label map pp = Map.insert pp lbls map
410 where lbls | pp == entry = (entry_label, Just entry_info_lbl)
411 | otherwise = (blockLbl pp, guard (setMember pp callPPs) >>
412 Just (infoTblLbl pp))
413 entry_info_lbl = cit_lbl info_tbl
414 procLabels = foldl add_label Map.empty
415 (filter (flip mapMember (toBlockMap g)) (setElems procPoints))
416 -- For each procpoint, we need to know the SP offset on entry.
417 -- If the procpoint is:
418 -- - continuation of a call, the SP offset is in the call
419 -- - otherwise, 0 (and left out of the spEntryMap)
420 let add_sp_off :: CmmBlock -> BlockEnv CmmStackInfo -> BlockEnv CmmStackInfo
421 add_sp_off b env =
422 case lastNode b of
423 CmmCall {cml_cont = Just succ, cml_ret_args = off, cml_ret_off = updfr_off} ->
424 mapInsert succ (StackInfo { arg_space = off, updfr_space = Just updfr_off}) env
425 CmmForeignCall {succ = succ, updfr = updfr_off} ->
426 mapInsert succ (StackInfo { arg_space = wORD_SIZE, updfr_space = Just updfr_off}) env
427 _ -> env
428 spEntryMap = foldGraphBlocks add_sp_off (mapInsert entry stack_info emptyBlockMap) g
429 getStackInfo id = mapLookup id spEntryMap `orElse` StackInfo {arg_space = 0, updfr_space = Nothing}
430 -- In each new graph, add blocks jumping off to the new procedures,
431 -- and replace branches to procpoints with branches to the jump-off blocks
432 let add_jump_block (env, bs) (pp, l) =
433 do bid <- liftM mkBlockId getUniqueM
434 let b = blockOfNodeList (JustC (CmmEntry bid), [], JustC jump)
435 StackInfo {arg_space = argSpace, updfr_space = off} = getStackInfo pp
436 jump = CmmCall (CmmLit (CmmLabel l)) Nothing argSpace 0
437 (off `orElse` 0) -- Jump's shouldn't need the offset...
438 return (mapInsert pp bid env, b : bs)
439 add_jumps (newGraphEnv) (ppId, blockEnv) =
440 do let needed_jumps = -- find which procpoints we currently branch to
441 mapFold add_if_branch_to_pp [] blockEnv
442 add_if_branch_to_pp :: CmmBlock -> [(BlockId, CLabel)] -> [(BlockId, CLabel)]
443 add_if_branch_to_pp block rst =
444 case lastNode block of
445 CmmBranch id -> add_if_pp id rst
446 CmmCondBranch _ ti fi -> add_if_pp ti (add_if_pp fi rst)
447 CmmSwitch _ tbl -> foldr add_if_pp rst (catMaybes tbl)
448 _ -> rst
449 add_if_pp id rst = case Map.lookup id procLabels of
450 Just (lbl, mb_info_lbl) -> (id, mb_info_lbl `orElse` lbl) : rst
451 Nothing -> rst
452 (jumpEnv, jumpBlocks) <-
453 foldM add_jump_block (mapEmpty, []) needed_jumps
454 -- update the entry block
455 let b = expectJust "block in env" \$ mapLookup ppId blockEnv
456 off = getStackInfo ppId
457 blockEnv' = mapInsert ppId b blockEnv
458 -- replace branches to procpoints with branches to jumps
459 blockEnv'' = toBlockMap \$ replaceBranches jumpEnv \$ ofBlockMap ppId blockEnv'
460 -- add the jump blocks to the graph
461 blockEnv''' = foldl (flip insertBlock) blockEnv'' jumpBlocks
462 let g' = (off, ofBlockMap ppId blockEnv''')
463 -- pprTrace "g' pre jumps" (ppr g') \$ do
464 return (mapInsert ppId g' newGraphEnv)
465 graphEnv <- foldM add_jumps emptyBlockMap \$ mapToList graphEnv
466 let to_proc (bid, (stack_info, g)) = case expectJust "pp label" \$ Map.lookup bid procLabels of
467 (lbl, Just info_lbl)
468 | bid == entry
469 -> CmmProc (TopInfo {info_tbl=info_tbl, stack_info=stack_info})
470 top_l (replacePPIds g)
471 | otherwise
472 -> CmmProc (TopInfo {info_tbl=mkEmptyContInfoTable info_lbl, stack_info=stack_info})
473 lbl (replacePPIds g)
474 (lbl, Nothing)
475 -> CmmProc (TopInfo {info_tbl=CmmNonInfoTable, stack_info=stack_info})
476 lbl (replacePPIds g)
477 -- References to procpoint IDs can now be replaced with the infotable's label
478 replacePPIds g = mapGraphNodes (id, mapExp repl, mapExp repl) g
479 where repl e@(CmmLit (CmmBlock bid)) =
480 case Map.lookup bid procLabels of
481 Just (_, Just info_lbl) -> CmmLit (CmmLabel info_lbl)
482 _ -> e
483 repl e = e
484 -- The C back end expects to see return continuations before the call sites.
485 -- Here, we sort them in reverse order -- it gets reversed later.
486 let (_, block_order) = foldl add_block_num (0::Int, emptyBlockMap) (postorderDfs g)
487 add_block_num (i, map) block = (i+1, mapInsert (entryLabel block) i map)
488 sort_fn (bid, _) (bid', _) =
489 compare (expectJust "block_order" \$ mapLookup bid block_order)
490 (expectJust "block_order" \$ mapLookup bid' block_order)
491 procs <- return \$ map to_proc \$ sortBy sort_fn \$ mapToList graphEnv
492 return -- pprTrace "procLabels" (ppr procLabels)
493 -- pprTrace "splitting graphs" (ppr procs)
494 procs
495 splitAtProcPoints _ _ _ _ t@(CmmData _ _) = return [t]
497 ----------------------------------------------------------------
499 {-
500 Note [Direct reachability]
502 Block B is directly reachable from proc point P iff control can flow
503 from P to B without passing through an intervening proc point.
504 -}
506 ----------------------------------------------------------------
508 {-
509 Note [No simple dataflow]
511 Sadly, it seems impossible to compute the proc points using a single
512 dataflow pass. One might attempt to use this simple lattice:
514 data Location = Unknown
515 | InProc BlockId -- node is in procedure headed by the named proc point
516 | ProcPoint -- node is itself a proc point
518 At a join, a node in two different blocks becomes a proc point.
519 The difficulty is that the change of information during iterative
520 computation may promote a node prematurely. Here's a program that
521 illustrates the difficulty:
523 f () {
524 entry:
525 ....
526 L1:
527 if (...) { ... }
528 else { ... }
530 L2: if (...) { g(); goto L1; }
531 return x + y;
532 }
534 The only proc-point needed (besides the entry) is L1. But in an
535 iterative analysis, consider what happens to L2. On the first pass
536 through, it rises from Unknown to 'InProc entry', but when L1 is
537 promoted to a proc point (because it's the successor of g()), L1's
538 successors will be promoted to 'InProc L1'. The problem hits when the
539 new fact 'InProc L1' flows into L2 which is already bound to 'InProc entry'.
540 The join operation makes it a proc point when in fact it needn't be,
541 because its immediate dominator L1 is already a proc point and there
542 are no other proc points that directly reach L2.
543 -}
547 {- Note [Separate Adams optimization]
548 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
549 It may be worthwhile to attempt the Adams optimization by rewriting
550 the graph before the assignment of proc-point protocols. Here are a
551 couple of rules:
553 g() returns to k; g() returns to L;
554 k: CopyIn c ress; goto L:
555 ... ==> ...
556 L: // no CopyIn node here L: CopyIn c ress;
559 And when c == c' and ress == ress', this also:
561 g() returns to k; g() returns to L;
562 k: CopyIn c ress; goto L:
563 ... ==> ...
564 L: CopyIn c' ress' L: CopyIn c' ress' ;
566 In both cases the goal is to eliminate k.
567 -}