<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    On 7/5/11 1:12 PM, Sungjin Kim wrote:
    <blockquote
cite="mid:CAAiNKJ33JOqFPvhGe_xFvXBVANASMEuQnwiB3f8kVq8Jtf_qGQ@mail.gmail.com"
      type="cite">
      <meta http-equiv="Content-Type" content="text/html;
        charset=ISO-8859-1">
      Hi all,<br>
      <br>
      Can anyone give an idea to solve my problem? I'm implementing
      backend part <br>
      using LLVM for my research architecture. The main issue is that
      this architecture<br>
      cannot use stack/heap. So, all the value should be stored in the
      register.<br>
      Given that architecture, load/store instruction in IR uses virtual
      register to load/<br>
      store the value. For example:<br>
    </blockquote>
    <br>
    It's difficult to answer this question without understanding your
    architecture's replacement for the stack and heap.  While variables
    like those below can be moved into LLVM virtual registers using
    -mem2reg, not all variables can be promoted in such a fashion (for
    example, an address-taken local variable cannot be promoted to a
    register).  Also, how does your architecture support structures and
    arrays?  Does it support global variables?  Is it designed to
    support programs written in languages such as C (in which the stack
    and heap are assumed to exist)?<br>
    <br>
    There are some things that you can do to promote stack objects to
    global objects.  If a call graph analysis (like the one found in
    LLVM or the one we provide in DSA) indicates that a function is not
    called recursively (i.e., it is not part of a strongly connected
    component in the call graph), then you should be able to replace the
    stack allocations within the function with a global variables
    (provided that the allocas are not in loops).  I think you can do
    the same with heap allocations provided that they don't escape the
    function in which they are allocated.<br>
    <br>
    -- John T.<br>
    <br>
    <blockquote
cite="mid:CAAiNKJ33JOqFPvhGe_xFvXBVANASMEuQnwiB3f8kVq8Jtf_qGQ@mail.gmail.com"
      type="cite">C source code is:<br>
      <br>
      if(...) {<br>
          a = 1;<br>
      } <br>
      else {<br>
          a = 0;<br>
      }<br>
      c = a;<br>
      <br>
      It's IR from the front-end is:<br>
      ...<br>
      ;<label>:3<br>
      store i16 1, i16 *a, align 2<br>
      br label %5<br>
      ;<label>:4<br>
      store i16 0, i16 *a, align 2<br>
      br label %5<br>
      <br>
      ;<label>:5<br>
      %6 = load i16 *a, align 2<br>
      store i16 %6, i16 c<br>
      <br>
      I used getCopyToReg in SelectionDAG for store instruction to store
      value, and getCopyFromReg <br>
      for load instruction. So, storage values in block
      '<label>:3' and '<label>:4' are stored in VR0 and <br>
      VR1 respectively.
      However, load instruction in block '<label>:5' cannot choose
      which register <br>
      should be read.<br>
      Can anybody give an idea to overcome such a case?<br>
      <br>
      Thanks.<br>
      <br>
      Jin
      <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>