0

I am writing a pass in llvm that would identify loop invariants and hoist those instructions who are using those invariants, above the loop body. But for that i need to know whether there is any back edge from one node to another. For e.g. I want to find whether there is a back edge from node N to node H, where node H dominates node N, that would help me identify a natural loop. How can i find whether there is any edge from one node to another in the CFG ? I could not found any class called CFG in LLVM from which i could gather this information.

TylerH
  • 20,799
  • 66
  • 75
  • 101
Vikash Joshi
  • 21
  • 1
  • 6

2 Answers2

0

You can roll your own (by iterating over the successors of a basic block with succ_iterator/succ_begin/succ_end) or you can use LoopInfo.

CAFxX
  • 28,060
  • 6
  • 41
  • 66
0

If you call the loop-simplify pass it will guarantee that there is only a single back edge to the loop header. This is a transformation pass so the CFG is modified but it makes additional CFG hacking far simpler.

laprej
  • 138
  • 1
  • 5