<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">On 4/25/15 10:51 AM, Xiangyang Guo
      wrote:<br>
    </div>
    <blockquote
cite="mid:CAJ9s6GRqK8ZLUyRJAEk8W-B_HGtZFEFo4R_6VCVKh+PFFnJhLA@mail.gmail.com"
      type="cite">
      <meta http-equiv="Context-Type" content="text/html; charset=UTF-8">
      <div dir="ltr">Hi, John,
        <div><br>
        </div>
        <div>Thanks for your valuable information. reg2mem will
          introduce too many load-store operation and the number of
          registers is huge. It seems the paper you mentioned is what I
          need. <br>
        </div>
      </div>
    </blockquote>
    <br>
    Yes, you'll either need to do what is in the paper or do what the
    code generator does (as Diego suggested).<br>
    <br>
    If you look at the paper, you can probably skip to the part in the
    end in which they discuss converting code out of SSA form.<br>
    <br>
    Regards,<br>
    <br>
    John Criswell<br>
    <br>
    <blockquote
cite="mid:CAJ9s6GRqK8ZLUyRJAEk8W-B_HGtZFEFo4R_6VCVKh+PFFnJhLA@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div><br>
        </div>
        <div>Regards</div>
        <div><br>
        </div>
        <div>Xiangyang</div>
      </div>
      <div class="gmail_extra"><br>
        <div class="gmail_quote">On Fri, Apr 24, 2015 at 7:43 PM, John
          Criswell <span dir="ltr"><<a moz-do-not-send="true"
              href="mailto:jtcriswel@gmail.com" target="_blank">jtcriswel@gmail.com</a>></span>
          wrote:<br>
          <blockquote class="gmail_quote">
            <div>
              <div>Dear Xiangyang,
                <div><br>
                </div>
                <div>There is an LLVM pass called reg2mem which does
                  what Diego suggests.  If you're not worried about
                  efficiency, that might work for you.</div>
                <div><br>
                </div>
                <div>If you need to do an efficient conversion of code
                  from SSA form to non-SSA form, then you need to read
                  Efficiently Computing Single Static Assignment Form
                  and the Control Dependence Graph by Ron Cytron, Jeane
                  Ferrante, et. al. (I may have gotten the title or
                  authors slightly wrong as I'm recalling this from
                  memory).</div>
                <div><br>
                </div>
                <div>Anyway, that paper describes how to generate code
                  from SSA form.  In essence, you need to do what
                  register allocation does: figure out which SSA values
                  in the same def-use chain can live in the same
                  variable (because they don't conflict) and which SSA
                  values must be assigned to different variables
                  (because they are alive at the same time).  If you
                  read the above paper, it should become clear.<br>
                </div>
                <div><br>
                </div>
                <div>Regards,</div>
                <div><br>
                </div>
                <div>John Criswell<br>
                  <br>
                </div>
                <div>
                  <div class="h5"> <br>
                    On 4/24/15 4:55 PM, Xiangyang Guo wrote:<br>
                  </div>
                </div>
              </div>
              <blockquote type="cite">
                <div>
                  <div class="h5">
                    <div dir="ltr">Hi, Diego,
                      <div><br>
                      </div>
                      <div>Thanks for your quick reply. Inserting a copy
                        instruction may not work here because I have a
                        limitation of virtual register number. I need to
                        assign registers with ssa form to registers
                        without ssa form. I will look the source code
                        you point out.</div>
                      <div><br>
                      </div>
                      <div>Thanks</div>
                      <div><br>
                      </div>
                      <div>Xiangyang</div>
                    </div>
                    <div class="gmail_extra"><br>
                      <div class="gmail_quote">On Fri, Apr 24, 2015 at
                        4:19 PM, Diego Novillo <span dir="ltr"><<a
                            moz-do-not-send="true"
                            href="mailto:dnovillo@google.com"
                            target="_blank">dnovillo@google.com</a>></span>
                        wrote:<br>
                        <blockquote class="gmail_quote">
                          <div dir="ltr"><br>
                            <div class="gmail_extra"><br>
                              <div class="gmail_quote"><span>On Fri, Apr
                                  24, 2015 at 3:17 PM, Xiangyang Guo <span
                                    dir="ltr"><<a
                                      moz-do-not-send="true"
                                      href="mailto:xguo6@ncsu.edu"
                                      target="_blank">xguo6@ncsu.edu</a>></span>
                                  wrote:<br>
                                  <blockquote class="gmail_quote">
                                    <div dir="ltr">Hi,
                                      <div><br>
                                      </div>
                                      <div>I want to convert LLVM IR to
                                        another type of IR, which has no
                                        SSA form. So the most important
                                        thing I need to handle is Phi
                                        node and register allocation
                                        because another type of IR has a
                                        limitation of virtual register
                                        number. The first thing I can
                                        think about is to learn how LLVM
                                        Backend works because LLVM
                                        Backend handles these things.
                                        But I'm not familiar with
                                        Backend. After reading some
                                        source code and online
                                        tutorials, I think a Backend is
                                        too much for my purpose. I
                                        really appreciate that if
                                        someone can give me hints. </div>
                                    </div>
                                  </blockquote>
                                  <div><br>
                                  </div>
                                </span>
                                <div>The easiest way to think about PHI
                                  nodes is to consider them copies on
                                  CFG edges.  If you do the naive
                                  translation of inserting a copy
                                  instruction on the corresponding edge
                                  for each PHI argument, you'll get a
                                  rough approximation for the
                                  corresponding normal form.</div>
                                <div><br>
                                </div>
                                <div>This is, of course, very
                                  inefficient, but it's the main idea.</div>
                                <div><br>
                                </div>
                                <div>If you can look at GCC's source
                                  code, take a look at the algorithm in
                                  file gcc/tree-outof-ssa.c.  That
                                  implements an SSA->Normal
                                  transformation. I'm not really sure
                                  where in the LLVM's backend this is
                                  done.</div>
                                <span>
                                  <div><br>
                                  </div>
                                  <div><br>
                                  </div>
                                  <div>Diego.</div>
                                </span></div>
                            </div>
                          </div>
                        </blockquote>
                      </div>
                      <br>
                    </div>
                    <br>
                    <fieldset></fieldset>
                    <br>
                  </div>
                </div>
                <pre>_______________________________________________
LLVM Developers mailing list
<a moz-do-not-send="true" href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a>         <a moz-do-not-send="true" href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a>
<a moz-do-not-send="true" href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><span class="HOEnZb">
</span></pre>
                <span class="HOEnZb"> </span></blockquote>
              <span class="HOEnZb"> <br>
                <br>
                <pre cols="72">-- 
John Criswell
Assistant Professor
Department of Computer Science, University of Rochester
<a moz-do-not-send="true" href="http://www.cs.rochester.edu/u/criswell" target="_blank">http://www.cs.rochester.edu/u/criswell</a></pre>
              </span></div>
          </blockquote>
        </div>
        <br>
      </div>
    </blockquote>
    <br>
    <br>
    <pre class="moz-signature" cols="72">-- 
John Criswell
Assistant Professor
Department of Computer Science, University of Rochester
<a class="moz-txt-link-freetext" href="http://www.cs.rochester.edu/u/criswell">http://www.cs.rochester.edu/u/criswell</a></pre>
  </body>
</html>