<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#ffffff">
    On 2/28/11 4:43 PM, Devang Patel wrote:
    <blockquote
      cite="mid:DC195044-5B1A-4564-AB55-B1DE3497EFCC@apple.com"
      type="cite"><br>
      <div>
        <div>On Feb 28, 2011, at 2:35 PM, Naznin Fauzia wrote:</div>
        <br class="Apple-interchange-newline">
        <blockquote type="cite">Hi all,<br>
          <br>
          How Can I get the Loops around an Instruction?<br>
          <br>
          I know I can get the basic block of an instruction using
          inst.getParent() which returns a BasicBlock*. Now I want to
          use the getLoopFor(BasicBlock) method of the class LoopInfo.<br>
          But I dont know how to get the LoopInfo.<br>
          <br>
          BasicBlock* bb = inst.getParent();<br>
          <br>
          (... what should I add here?)<br>
          <br>
          Loop* innerloop = LI -> getLoopFor(bb):<br>
          <br>
        </blockquote>
        <br>
      </div>
      <div>Two steps:</div>
      <div>1) In your pass's getAnalysisUsage(), request LoopInfo.</div>
      <div><br>
      </div>
      <div>
        <div><span class="Apple-tab-span" style="white-space: pre;"><font
              class="Apple-style-span" face="Courier"> </font></span><font
            class="Apple-style-span" face="Courier">virtual void
            getAnalysisUsage(AnalysisUsage &AU) const {</font></div>
        <div><span class="Apple-tab-span" style="white-space: pre;"><font
              class="Apple-style-span" face="Courier"> </font></span><font
            class="Apple-style-span" face="Courier">  AU.addRequired<LoopInfo>();</font></div>
        <div><span class="Apple-tab-span" style="white-space: pre;"><font
              class="Apple-style-span" face="Courier"> </font></span><font
            class="Apple-style-span" face="Courier">}</font></div>
        <div><br>
        </div>
        <div>2) In your runOnLoop() method get the analysis.</div>
        <div><br>
        </div>
        <div><span class="Apple-tab-span" style="white-space: pre;"><font
              class="Apple-style-span" face="Courier"> </font></span><font
            class="Apple-style-span" face="Courier">LoopPass *</font><span
            class="Apple-tab-span" style="white-space: pre;"><font
              class="Apple-style-span" face="Courier">LI =
              &getAnalysis<LoopInfo>();</font></span></div>
        <div><span class="Apple-style-span" style="white-space: pre;"><br>
          </span></div>
        <div><span class="Apple-style-span" style="white-space: pre;">Now,
            you can do LI->getLoopFor(...)</span></div>
      </div>
    </blockquote>
    <br>
    To add to what Devang has said, you may find the doxygen docs on
    LoopInfo helpful:<br>
    <br>
    <a class="moz-txt-link-freetext" href="http://llvm.org/doxygen/classllvm_1_1LoopInfo.html">http://llvm.org/doxygen/classllvm_1_1LoopInfo.html</a><br>
    <br>
    -- John T.<br>
    <br>
    <br>
    <blockquote
      cite="mid:DC195044-5B1A-4564-AB55-B1DE3497EFCC@apple.com"
      type="cite">
      <div>
        <div><span class="Apple-style-span" style="white-space: pre;"><br>
          </span></div>
        <div><span class="Apple-style-span" style="white-space: pre;">-</span></div>
        <div><span class="Apple-style-span" style="white-space: pre;">Devang</span></div>
        <div><br>
        </div>
      </div>
      <br>
    </blockquote>
    <br>
  </body>
</html>