[LLVMdev] Identify recursion in a call graph

Duncan Sands baldrick at free.fr
Tue Nov 2 01:27:35 PDT 2010


Hi Trevor,

> Converting my ModulePass to a CallGraphSCCPass doesn't seem feasible, so I'll
> use llvm::scc_iterator. Here's what I have so far:
>
> bool MyModulePass::isRecursive() {
> CallGraphNode* rootNode = getAnalysis<CallGraph>().getRoot();
> for (scc_iterator<CallGraphNode*> SCCI = scc_begin(rootNode), E =
> scc_end(rootNode); SCCI != E; ++SCCI) {
> const std::vector<CallGraphNode*> &nextSCC = *SCCI;
> if (nextSCC.size() == 1 && SCCI.hasLoop()) {
> return true;
> }
> }
> return false;
> }
>
> This correctly identifies direct (self) recursion but fails to identify indirect
> recursion, such as:
>
> void foo() { bar(); }
> void bar() { foo(); }
>
> Any suggestions on how to identify both types? Thanks,

in this case nextSCC.size() will be 2, so your logic will not consider it.

Ciao,

Duncan.

> P.S. Is it possible to start the call graph traversal from a particular
> function, rather than from getRoot()? Setting rootNode to "new
> CallGraphNode(myFunction)" causes isRecursive to return false, even with direct
> recursion.

I don't know.



More information about the llvm-dev mailing list