<html>
  <head>
    <meta content="text/html; charset=windows-1252"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <br>
    <br>
    <div class="moz-cite-prefix">On 06/16/2015 07:22 AM,
      <a class="moz-txt-link-abbreviated" href="mailto:marwayusuf@feng.bu.edu.eg">marwayusuf@feng.bu.edu.eg</a> wrote:<br>
    </div>
    <blockquote
cite="mid:AM2PR01MB08043915CCC504ADD21E9F92BBA70@AM2PR01MB0804.eurprd01.prod.exchangelabs.com"
      type="cite">
      <meta http-equiv="Content-Type" content="text/html;
        charset=windows-1252">
      <style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
      <div id="divtagdefaultwrapper"
style="font-size:12pt;color:#000000;background-color:#FFFFFF;font-family:Calibri,Arial,Helvetica,sans-serif;">
        <p>Thanks a million. Now I managed to insert the block into the
          loop using the mentioned function. However I have another
          issue now. I've inserted a block (named foo) in the start of
          the loop. I want to make the predecessors of the the previous
          start block (for.cond) to jump to foo instead, and foo jumps
          to for.cond. Predecessors of for.cond are entry and for.inc.
          When I run my pass, only for.inc is changed, entry is not.
          Here is code:<br>
        </p>
        <p><br>
        </p>
        <div>          pred_iterator PI = pred_begin(loopCond), PE =
          pred_end(loopCond);</div>
        <div>          while (PI != PE) {</div>
        <div>            if((*PI)!=foo){   <br>
        </div>
        <div>              BasicBlock::iterator it = (*PI)->end();</div>
        <div>              it--;</div>
        <div>              BranchInst *bi =
          dyn_cast<BranchInst>(it);<br>
        </div>
        <div>              bi->setSuccessor(0, foo);<br>
        </div>
        <div>            }</div>
        <div>            PI++;</div>
        <div>          }<br>
        </div>
        <div><br>
        </div>
        <div>I guessed that the problem is that entry block is not part
          of the loop, and this is a loop pass. So, if this is this the
          problem, how can I overcome? And if not, what could be the
          problem?<br>
        </div>
      </div>
    </blockquote>
    You've identified the problem correctly.  The notion your looking
    for is a loop preheader (For LoopSimplify form), or a non-loop
    contained predecessor of the loop header (for generalized loops). 
    You need to explicitly locate and visit those blocks.  See
    LoopInfo.h.<br>
    <br>
    I would strongly suggest you use some of the existing loop
    transforms (LICM, LoopUnswitch, etc...) as examples.  They all have
    to do similar things.  <br>
    <blockquote
cite="mid:AM2PR01MB08043915CCC504ADD21E9F92BBA70@AM2PR01MB0804.eurprd01.prod.exchangelabs.com"
      type="cite">
      <div id="divtagdefaultwrapper"
style="font-size:12pt;color:#000000;background-color:#FFFFFF;font-family:Calibri,Arial,Helvetica,sans-serif;">
        <div>
        </div>
        <p><br>
        </p>
        <p><br>
        </p>
        <div id="Signature">
          <div id="divtagdefaultwrapper" style="font-size:12pt;
            color:#000000; background-color:#FFFFFF;
            font-family:Calibri,Arial,Helvetica,sans-serif">
            <div class="BodyFragment"><font size="2"><span
                  style="font-size:10pt">
                  <div class="PlainText">Regards,<br>
                    Marwa Yusuf<br>
                    Teaching Assistant - Computer Engineering Department<br>
                    Faculty of Engineering - Benha University<br>
                    E-JUST PhD Student<br>
                    Computer Science & Engineering Dept.</div>
                </span></font></div>
          </div>
        </div>
        <div style="color: rgb(0, 0, 0);">
          <hr tabindex="-1" style="display:inline-block; width:98%">
          <div id="divRplyFwdMsg" dir="ltr"><font style="font-size:11pt"
              color="#000000" face="Calibri, sans-serif"><b>From:</b>
              Philip Reames <a class="moz-txt-link-rfc2396E" href="mailto:listmail@philipreames.com"><listmail@philipreames.com></a><br>
              <b>Sent:</b> Friday, June 12, 2015 11:55 PM<br>
              <b>To:</b> <a class="moz-txt-link-abbreviated" href="mailto:marwayusuf@feng.bu.edu.eg">marwayusuf@feng.bu.edu.eg</a><br>
              <b>Cc:</b> <a class="moz-txt-link-abbreviated" href="mailto:llvmdev@cs.uiuc.edu">llvmdev@cs.uiuc.edu</a><br>
              <b>Subject:</b> Re: [LLVMdev] How to insert basic block in
              a loop</font>
            <div> </div>
          </div>
          <div>Given lack of context in your question, it's hard to
            figure out what you're asking, but as a guess, I'd suggest
            you look at addBasicBlockToLoop on LoopBase in LoopInfo.h<br>
            <br>
            Philip<br>
            <br>
            <div class="moz-cite-prefix">On 06/12/2015 01:53 PM, <a
                moz-do-not-send="true" class="moz-txt-link-abbreviated"
                href="mailto:marwayusuf@feng.bu.edu.eg">
                marwayusuf@feng.bu.edu.eg</a> wrote:<br>
            </div>
            <blockquote type="cite">
              <div id="divtagdefaultwrapper" style="font-size:12pt;
                color:#000000; background-color:#FFFFFF;
                font-family:Calibri,Arial,Helvetica,sans-serif">
                <p>Dear All<br>
                </p>
                <p>I'm making a transformation pass that inserts a new
                  basic block at the start of a loop. However when I try
                  to change predecessor/successor relations, it does not
                  consider the new block in the loop at all. So I got
                  that just inserting a loop in a function before
                  another loop is not enough. So how exactly to do this
                  job?<br>
                </p>
                <p><br>
                </p>
                <div id="Signature">
                  <div id="divtagdefaultwrapper" style="font-size:12pt;
                    color:#000000; background-color:#FFFFFF;
                    font-family:Calibri,Arial,Helvetica,sans-serif">
                    <div class="BodyFragment"><font size="2"><span
                          style="font-size:10pt">
                          <div class="PlainText">Regards,<br>
                            Marwa Yusuf<br>
                            Teaching Assistant - Computer Engineering
                            Department<br>
                            Faculty of Engineering - Benha University<br>
                            E-JUST PhD Student<br>
                            Computer Science & Engineering Dept.</div>
                        </span></font></div>
                  </div>
                </div>
              </div>
              <br>
              <fieldset class="mimeAttachmentHeader"></fieldset>
              <br>
              <pre>_______________________________________________
LLVM Developers mailing list
<a moz-do-not-send="true" class="moz-txt-link-abbreviated" href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://llvm.cs.uiuc.edu">http://llvm.cs.uiuc.edu</a>
<a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a>
</pre>
            </blockquote>
            <br>
          </div>
        </div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
LLVM Developers mailing list
<a class="moz-txt-link-abbreviated" href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a class="moz-txt-link-freetext" href="http://llvm.cs.uiuc.edu">http://llvm.cs.uiuc.edu</a>
<a class="moz-txt-link-freetext" href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>