Also, could you write this in a separate pass, and obtain the results from getAnalysis()? I think others would find it useful to discover if a Function may be called recursively. <div><br><div>-Jeff Kunkel<br><br><div class="gmail_quote">
On Tue, Nov 2, 2010 at 2:38 PM, Jeff Kunkel <span dir="ltr"><<a href="mailto:jdkunk3@gmail.com">jdkunk3@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi you basically need to find a cycles in the call graph. Do do this just search google for a graph algorithm, then make it for your problem. See <a href="http://en.wikipedia.org/wiki/Cycle_detection" target="_blank">http://en.wikipedia.org/wiki/Cycle_detection</a>.<div>

<br></div><div><font color="#888888">Jeff Kunkel</font><div><div></div><div class="h5"><br><div><br><div class="gmail_quote">On Tue, Nov 2, 2010 at 4:27 AM, Duncan Sands <span dir="ltr"><<a href="mailto:baldrick@free.fr" target="_blank">baldrick@free.fr</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Trevor,<br>
<div><br>
> Converting my ModulePass to a CallGraphSCCPass doesn't seem feasible, so I'll<br>
> use llvm::scc_iterator. Here's what I have so far:<br>
><br>
> bool MyModulePass::isRecursive() {<br>
> CallGraphNode* rootNode = getAnalysis<CallGraph>().getRoot();<br>
> for (scc_iterator<CallGraphNode*> SCCI = scc_begin(rootNode), E =<br>
> scc_end(rootNode); SCCI != E; ++SCCI) {<br>
> const std::vector<CallGraphNode*> &nextSCC = *SCCI;<br>
> if (nextSCC.size() == 1 && SCCI.hasLoop()) {<br>
> return true;<br>
> }<br>
> }<br>
> return false;<br>
> }<br>
><br>
> This correctly identifies direct (self) recursion but fails to identify indirect<br>
> recursion, such as:<br>
><br>
> void foo() { bar(); }<br>
> void bar() { foo(); }<br>
><br>
> Any suggestions on how to identify both types? Thanks,<br>
<br>
</div>in this case nextSCC.size() will be 2, so your logic will not consider it.<br>
<br>
Ciao,<br>
<br>
Duncan.<br>
<div><br>
> P.S. Is it possible to start the call graph traversal from a particular<br>
> function, rather than from getRoot()? Setting rootNode to "new<br>
> CallGraphNode(myFunction)" causes isRecursive to return false, even with direct<br>
> recursion.<br>
<br>
</div>I don't know.<br>
<div><div></div><div>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
</div></div></blockquote></div><br></div></div></div></div>
</blockquote></div><br></div></div>