can GHC generate an irreducible control-flow graph? If so, how?

Norman Ramsey nr at cs.tufts.edu
Mon Nov 22 19:51:54 UTC 2021


I'm trying to figure out how to persuade GHC to generate an
irreducible control-flow graph (so I can test an algorithm to convert
it to structured control flow).

The attached image shows (on the left) the classic simple irreducible
CFG: there is a loop between nodes A and B, but neither one dominates
the other, so there is no loop header.  I tried to get GHC to generate
this CFG using the following source code:

  length'' :: Bool -> List a -> Int
  length'' trigger xs = if trigger then countA 0 xs else countB 0 xs
    where countA n Nil = case n of m -> m
          countA n (Cons _ as) = case n + 1 of m -> countB m as
          countB n Nil = case n of m -> m
          countB n (Cons _ as) = case n + 2 of m -> countA m as

Unfortunately (for my purposes), GHC generates a perfectly lovely
reducible flow graph with a single header node.

It is even possible for GHC to generate an irreducible control-flow
graph?  If so, how can it be done?


Norman

-------------- next part --------------
A non-text attachment was scrubbed...
Name: On-the-left-is-an-unstructured-program-and-the-corresponding-irreducible-control-flow.png
Type: image/png
Size: 21365 bytes
Desc: not available
URL: <http://mail.haskell.org/pipermail/ghc-devs/attachments/20211122/a8528ef6/attachment.png>


More information about the ghc-devs mailing list