On Mon, May 10, 2010 at 8:05 PM, Trevor Harmon <Trevor.W.Harmon at nasa.gov> wrote:> On May 10, 2010, at 8:43 AM, Xinfinity wrote: > >> Is it possible to get the list of BasicBlocks building the condition >> of a loop and the list of BasicBlocks that form the body? > > Based on my (limited) experience with Loop and LoopInfo, this isn't > possible. (But don't take my word for it.) > >> My aim is to manipulate for loops, while and do-while loops unitary, >> but I did not find an easy way to do this. > > I think the problem here is that LLVM's CFG is low-level enough such > that the distinction between the loop header expression and the loop > body is lost. > > Why exactly do you need to identify the blocks that form the loop > header expression? I'm wondering if you could find some workaround > that doesn't require this... >To me it looks like any basic block from the loop body with a successor not in the loop body is a BB "building the condition" (an "exit" block). If you already have the loop body, it should be pretty easy to find out about those nodes. cheers, Benoit
On May 10, 2010, at 11:35 AM, Benoit Boissinot wrote:> To me it looks like any basic block from the loop body with a > successor not in the loop body is a BB "building the condition" (an > "exit" block).I assume you mean "any basic block from the loop header". I don't think your rule will work. Consider this counterexample: while (j < 10 && j > 5 && j % 2 == 0) { j++; } This will give you the attached CFG. bb1 is the loop header; bb2 and bb3 are the other loop conditionals; bb is the loop body. Note that bb3 is part of the condition but is not a basic block from the loop header. Trevor -------------- next part -------------- A non-text attachment was scrubbed... Name: cfg._Z6simplei.dot Type: application/octet-stream Size: 2002 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20100510/2b9c3c70/attachment.obj> -------------- next part --------------
On Mon, May 10, 2010 at 12:32:06PM -0700, Trevor Harmon wrote:> On May 10, 2010, at 11:35 AM, Benoit Boissinot wrote: > > >To me it looks like any basic block from the loop body with a > >successor not in the loop body is a BB "building the condition" (an > >"exit" block). > > I assume you mean "any basic block from the loop header".No really, loop body.> > I don't think your rule will work. Consider this counterexample: > > while (j < 10 && j > 5 && j % 2 == 0) { > j++; > } > > This will give you the attached CFG. bb1 is the loop header; bb2 and > bb3 are the other loop conditionals; bb is the loop body. > > Note that bb3 is part of the condition but is not a basic block from > the loop header.At least in the CFG/graph theory I know, the loop body is the set of nodes which form the strongly connected component (it contains the headers). In this case that would be {bb1, bb2, bb3, bb}, with bb1 as header. (the header is un-ambiguous in this case since the CFG is natural/reducible there is only one possible header for the loop).>From this set, bb1, bb2 and bb3 have exit edges, those are theconditional blocks. cheers, Benoit -- :wq