<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 9/17/17 10:24 AM, Gnanambikai
      Krishnakumar via llvm-dev wrote:<br>
    </div>
    <blockquote
cite="mid:CAHsZv_dvaPWzsN5WO+vzKn9_7BEZKU58UFzDWGd1au+amzq2SA@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div>
          <div>
            <div>
              <div>
                <div>
                  <div>Hello All,<br>
                    <br>
                  </div>
                      We want to write a transformation pass such that
                  the array accesses use a base register other than ebp
                  (assuming that the code is compiled for x86
                  architecture). For example,<br>
                  <br>
                </div>
                The below C code<br>
              </div>
              ->int a[5];<br>
            </div>
            ->a[2] = 2<br>
            <br>
          </div>
          by default, gets compiled to something like this:<br>
        </div>
        <div>->mov    dword ptr [ebp - 28], eax<br>
          <br>
        </div>
        <div>However, we want our pass to emit the something similar to
          the following instead:<br>
        </div>
        <div>->mov   ecx, "base of array"<br>
        </div>
        <div>->mov   dword ptr [ecx - "index from base of array a"],
          eax<br>
        </div>
        <div>
          <div>
            <div>
              <div>
                <div>
                  <div><br>
                    Is there any way we could modify the llvm code so as
                    to achieve the required instruction format? Please
                    let us know if there is some code that already does
                    this or if it is documented elsewhere. <br>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </blockquote>
    <br>
    There are two ways that I can see to do this:<br>
    <br>
    <ul>
      <li>Modify the register allocator so that stack offsets are
        referenced using another register</li>
      <li>Write a separate MachineFunctionPass that scans over the code
        and changes the register used to index into the array.  The SVA
        project has some code which searches for free registers.  If you
        need it, let me know, and I can point you to the relevant code
        on Github.</li>
    </ul>
    <br>
    I think the more interesting question is why you want to do this. 
    What is your end goal?<br>
    <br>
    Regards,<br>
    <br>
    John Criswell<br>
    <br>
    <blockquote
cite="mid:CAHsZv_dvaPWzsN5WO+vzKn9_7BEZKU58UFzDWGd1au+amzq2SA@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div>
          <div>
            <div>
              <div>
                <div>
                  <div><br>
                  </div>
                  <div>Regards,<br>
                  </div>
                  <div>Gnanambikai<br>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
LLVM Developers mailing list
<a class="moz-txt-link-abbreviated" href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>
<a class="moz-txt-link-freetext" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a>
</pre>
    </blockquote>
    <br>
    <p><br>
    </p>
    <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>