<html><body><div style="color:#000; background-color:#fff; font-family:Courier New, courier, monaco, monospace, sans-serif;font-size:10pt"><div style="RIGHT: auto"><SPAN style="RIGHT: auto">Thanks for giving me more insight into this. </SPAN></div>
<div style="RIGHT: auto"><SPAN style="RIGHT: auto"></SPAN> </div>
<div style="RIGHT: auto"><SPAN style="RIGHT: auto">I could use the approach of using LoopInfo in my pass. I have taken care of the memory management and validated the information as well.  LoopInfo has made the task a lot simpler. </SPAN></div>
<div style="RIGHT: auto"><SPAN style="RIGHT: auto"></SPAN> </div>
<div style="RIGHT: auto"><SPAN style="RIGHT: auto">In order to check whether the function basic block is a innermost loop, I am doing following:</SPAN></div>
<div style="RIGHT: auto"><SPAN style="RIGHT: auto">LoopInfo LI;<BR>DominatorTree DT;</SPAN></div>
<div style="RIGHT: auto"><SPAN style="RIGHT: auto">DT.DT->recalculate(*F);<BR>LI.getBase().Calculate( DT.getBase() ) ;</SPAN></div>
<div style="RIGHT: auto"><SPAN style="RIGHT: auto"></SPAN> </div>
<div style="RIGHT: auto"><SPAN style="RIGHT: auto">//.. some code</SPAN></div>
<div style="RIGHT: auto"><SPAN style="RIGHT: auto">//BB is a basic block in some function.</SPAN></div>
<div style="RIGHT: auto"><SPAN style="RIGHT: auto">if( Loop *L = LI.getLoopFor( BB) ) {</SPAN></div>
<div style="RIGHT: auto"><SPAN style="RIGHT: auto">  //loop with no subloops is innermost.</SPAN></div>
<div style="RIGHT: auto"><SPAN style="RIGHT: auto">  if( L->getSubLoops().empty() )  <BR style="RIGHT: auto">    break; //is innermost loop</div></SPAN>
<div style="RIGHT: auto"><SPAN style="RIGHT: auto">}</div></SPAN>
<div style="RIGHT: auto"><SPAN style="RIGHT: auto"><VAR id=yui-ie-cursor></VAR></SPAN> </div>
<div style="RIGHT: auto"><SPAN style="RIGHT: auto">Regards,</SPAN></div>
<div style="RIGHT: auto"><SPAN style="RIGHT: auto">Pankaj</SPAN></div>
<div><BR></div>
<DIV style="FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif; FONT-SIZE: 10pt">
<DIV style="FONT-FAMILY: times new roman, new york, times, serif; FONT-SIZE: 12pt"><FONT size=2 face=Arial>
<DIV style="BORDER-BOTTOM: #ccc 1px solid; BORDER-LEFT: #ccc 1px solid; PADDING-BOTTOM: 0px; LINE-HEIGHT: 0; MARGIN: 5px 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; HEIGHT: 0px; FONT-SIZE: 0px; BORDER-TOP: #ccc 1px solid; BORDER-RIGHT: #ccc 1px solid; PADDING-TOP: 0px" class=hr contentEditable=false readonly="true"></DIV><B><SPAN style="FONT-WEIGHT: bold">From:</SPAN></B> Devang Patel <dpatel@apple.com><BR><B><SPAN style="FONT-WEIGHT: bold">To:</SPAN></B> Pankaj Gode <godepankaj@yahoo.com><BR><B><SPAN style="FONT-WEIGHT: bold">Cc:</SPAN></B> llvm Developers <llvmdev@cs.uiuc.edu><BR><B><SPAN style="FONT-WEIGHT: bold">Sent:</SPAN></B> Wednesday, November 16, 2011 11:15 PM<BR><B><SPAN style="FONT-WEIGHT: bold">Subject:</SPAN></B> Re: [LLVMdev] CallSite in innermost loop<BR></FONT><BR>
<DIV style="RIGHT: auto" id=yiv220773130>
<DIV style="RIGHT: auto"><BR>
<DIV style="RIGHT: auto">
<DIV>On Nov 16, 2011, at 2:43 AM, Pankaj Gode wrote:</DIV><BR class=yiv220773130Apple-interchange-newline>
<BLOCKQUOTE type="cite">
<DIV>
<DIV style="BACKGROUND-COLOR: rgb(255,255,255); FONT-FAMILY: courier, monaco, monospace, sans-serif; COLOR: rgb(0,0,0); FONT-SIZE: 10pt">
<DIV>In order to detect whether CallSite is present in innermost loop, do I need to insert logic from LoopInfo pass for collecting loops, within a CallGraphSCC pass? </DIV>
<DIV> </DIV>
<DIV>Is there any other approach for this?<VAR id=yiv220773130yui-ie-cursor></VAR></DIV>
<DIV><BR></DIV></DIV></DIV></BLOCKQUOTE><BR></DIV>
<DIV style="RIGHT: auto">PassManager not only schedules passes, it also </DIV>
<DIV><SPAN style="WHITE-SPACE: pre" class=yiv220773130Apple-tab-span></SPAN>- manages memory</DIV>
<DIV style="RIGHT: auto"><SPAN style="WHITE-SPACE: pre" class=yiv220773130Apple-tab-span></SPAN>- ensures that analysis info is valid at the point of use</DIV>
<DIV style="RIGHT: auto"><SPAN style="WHITE-SPACE: pre" class=yiv220773130Apple-tab-span></SPAN>- eliminates redundant calculation of analysis</DIV>
<DIV style="RIGHT: auto"><SPAN style="WHITE-SPACE: pre" class=yiv220773130Apple-tab-span></SPAN>- automatically schedule other required passes</DIV>
<DIV style="RIGHT: auto"><SPAN style="WHITE-SPACE: pre" class=yiv220773130Apple-tab-span></SPAN>- takes responsibility of walking program construct. For example, a LoopPass does not need to worry about how to walk loop nest. A FunctionPass does not worry about in which order the functions are processed. </DIV>
<DIV><BR></DIV>
<DIV style="RIGHT: auto">Right now, CallGraph pass manager is not equipped to satisfy these requirements at loop level. You could certainly extend the PassManager, but it is not structured and designed to support such scenarios.</DIV>
<DIV style="RIGHT: auto"><BR></DIV>
<DIV style="RIGHT: auto">That does not mean you can not use LoopInfo in your pass. It means, you'll have to manage the memory, satisfy its needs and ensure validity of the info yourself. You could do something like,</DIV>
<DIV><BR></DIV>
<DIV style="RIGHT: auto"><FONT style="FONT-SIZE: 11px" class=yiv220773130Apple-style-span face=Menlo><SPAN style="WHITE-SPACE: pre" class=yiv220773130Apple-tab-span></SPAN>LoopInfo LI;</FONT></DIV>
<DIV><FONT style="FONT-SIZE: 11px" class=yiv220773130Apple-style-span face=Menlo><SPAN style="WHITE-SPACE: pre" class=yiv220773130Apple-tab-span></SPAN>DominatorTree DT;</FONT></DIV>
<DIV><FONT style="FONT-SIZE: 11px" class=yiv220773130Apple-style-span face=Menlo><BR></FONT></DIV>
<DIV><FONT style="FONT-SIZE: 11px" class=yiv220773130Apple-style-span face=Menlo><SPAN style="WHITE-SPACE: pre" class=yiv220773130Apple-tab-span></SPAN>....</FONT></DIV>
<DIV><FONT style="FONT-SIZE: 11px" class=yiv220773130Apple-style-span face=Menlo><SPAN style="WHITE-SPACE: pre" class=yiv220773130Apple-tab-span></SPAN>DT.recalculate(F)</FONT></DIV>
<DIV><FONT style="FONT-SIZE: 11px" class=yiv220773130Apple-style-span face=Menlo><SPAN style="WHITE-SPACE: pre" class=yiv220773130Apple-tab-span></SPAN>LI.Calculate(DT.getBase());</FONT></DIV>
<DIV><FONT style="FONT-SIZE: 11px" class=yiv220773130Apple-style-span face=Menlo><SPAN style="WHITE-SPACE: pre" class=yiv220773130Apple-tab-span></SPAN>...</FONT></DIV>
<DIV style="RIGHT: auto"><FONT style="FONT-SIZE: 11px" class=yiv220773130Apple-style-span face=Menlo><SPAN style="WHITE-SPACE: pre" class=yiv220773130Apple-tab-span></SPAN>... use LI ...  /* Make sure F is not modified since DT and LI were calculate. */</FONT></DIV>
<DIV><FONT style="FONT-SIZE: 11px" class=yiv220773130Apple-style-span face=Menlo><SPAN style="WHITE-SPACE: pre" class=yiv220773130Apple-tab-span></SPAN>...</FONT></DIV>
<DIV><FONT style="FONT-SIZE: 11px" class=yiv220773130Apple-style-span face=Menlo><SPAN style="WHITE-SPACE: pre" class=yiv220773130Apple-tab-span></SPAN>DT.releaseMemory();</FONT></DIV>
<DIV style="RIGHT: auto"><FONT style="FONT-SIZE: 11px" class=yiv220773130Apple-style-span face=Menlo><SPAN style="WHITE-SPACE: pre" class=yiv220773130Apple-tab-span></SPAN>LI.releaseMemory();</FONT></DIV>
<DIV style="RIGHT: auto"><BR></DIV>
<DIV>-</DIV>
<DIV>Devang</DIV></DIV></DIV><BR><BR></DIV></DIV></div></body></html>