<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">Aha, yes, this is definitely helpful!<br>
      <br>
      Is there documentation on all this somewhere?  I still have errors
      for some large test inputs, and it would be nice if I didn't have
      to keep bugging you for information.<br>
      <br>
      Thanks!<br>
      <br>
      Susan<br>
      <br>
      On 12/2/2012 10:55 PM, Lang Hames wrote:<br>
    </div>
    <blockquote
cite="mid:CALLttgqo0u2AeiUXzm12ZKvjP1QrEFqrvhqhL53B5eRFj9B04A@mail.gmail.com"
      type="cite">
      <meta http-equiv="Context-Type" content="text/html;
        charset=ISO-8859-1">
      Hi Susan,
      <div><br>
      </div>
      <div>Thanks for the clarification, and the test case. I think I
        know what the problem is now. Saving and restoring RBP is the
        job of the PEI (PrologEpilogInsertion) pass, which runs after
        register allocation. To determine which callee-saved physregs
        actually need to be saved it checks
        MachineRegisterInfo::isPhysRegOrOverlapUsed(unsigned reg). Your
        register allocator needs to notify MachineRegisterInfo about the
        physical registers that have been assigned by calling
        MachineRegisterInfo::setPhysRegUsed(unsigned reg).</div>
      <div><br>
      </div>
      <div>You only need to call setPhysRegUsed for the physregs that
        you actually use. You do not need to specify the aliasing
        registers.</div>
      <div><br>
      </div>
      <div>Hope this helps!</div>
      <div><br>
      </div>
      <div>Regards,</div>
      <div>Lang.</div>
      <div class="gmail_extra"><br>
        <br>
        <div class="gmail_quote">On Sat, Dec 1, 2012 at 9:31 AM, Susan
          Horwitz <span dir="ltr"><<a moz-do-not-send="true"
              href="mailto:horwitz@cs.wisc.edu" target="_blank">horwitz@cs.wisc.edu</a>></span>
          wrote:<br>
          <blockquote class="gmail_quote">
            <div>
              <div class="im">
                <div>On 11/30/2012 6:36 PM, Lang Hames wrote:<br>
                </div>
                <blockquote type="cite"> <br>
                  <div><br>
                  </div>
                  <div>RBP is used as the frame pointer on x86 (hence
                    its automatic appearance in your code), and
                    shouldn't be allocated to any vreg in function bar.
                    Loading/saving RBP should be managed by the stack
                    frame setup/teardown code.</div>
                </blockquote>
                <blockquote type="cite">
                  <div>If it doesn't already, your allocator should
                    filter out reserved registers (See
                    MachineRegisterInfo::isReserved(unsigned preg)) when
                    assigning physregs.</div>
                </blockquote>
                <br>
              </div>
              I AM filtering out reserved registers. <br>
              <br>
              I am not allocating RBP in function bar, I am allocating
              EBP, because it is NOT in the list of reserved registers
              for function bar.<br>
              <br>
              Neither register RBP nor register EBP is saved/restored
              across the call from foo to bar, either by the code for
              the call or the code for entry to bar.<br>
              <br>
              The input C file that is causing this problem is flex.c
              (attached).  The calling function is "yyparse" and the
              called function is "scinstal".<br>
              <br>
              Here are the reserved registers for yyparse: { 7 44 54 106
              111 114 118 }<br>
              <br>
              Here are the reserved registers for scinstal: { 54 111 114
              }<br>
              <br>
              Register EBP is preg 44, which is NOT in the reserved list
              for scinstal (nor is it an alias of any of those reserved
              registers; the aliases are  { <a moz-do-not-send="true"
                href="tel:50%2064%20117%20118" value="+15064117118"
                target="_blank">50 64 117 118</a> }).  I don;t know
              which preg corresponds to RBP.<br>
              <br>
              You say that RBP should be saved/restored across the
              call.  I tried to generate that code, but, as I said in my
              previous mail,  I don't know how to get the appropriate
              TargetRegisterClass (needed to call
              CreateSpillStackObject).   Should I instead be generating
              code to save register EBP at the start of scinstal,
              restoring it at the end of that function?<span
                class="HOEnZb"><br>
                <br>
                Susan</span>
              <div class="im"><br>
                <br>
                <blockquote type="cite">
                  <div><br>
                  </div>
                  <div><span>ArrayRef<MCPhysReg> pregs =
                      TRC->getRawAllocationOrder(&MF);</span></div>
                  <div><span>for (int i = 0; i < pregs.size(); ++i) {</span></div>
                  <div><span>  if (MRI->isReserved(pregs[i]))</span></div>
                  <div><span>    continue;</span></div>
                  <div><span>  // use preg...</span></div>
                  <div><span>}</span></div>
                  <div><br>
                  </div>
                  <div>You could also use the AllocationOrder class to
                    simplify the task of finding valid pregs, though it
                    does require you to use VirtRegMap. </div>
                  <div><br>
                  </div>
                  <div>If you are already checking the reserved regs
                    then I've misdiagnosed the problem. I'd be happy to
                    dig further if you can point me to a copy of your
                    allocator and a test case.</div>
                  <div><br>
                  </div>
                  <div>Cheers,</div>
                  <div>Lang.</div>
                  <div class="gmail_extra"><br>
                    <br>
                    <div class="gmail_quote">On Thu, Nov 29, 2012 at
                      3:49 PM, Susan Horwitz <span dir="ltr"><<a
                          moz-do-not-send="true"
                          href="mailto:horwitz@cs.wisc.edu"
                          target="_blank">horwitz@cs.wisc.edu</a>></span>
                      wrote:<br>
                      <blockquote class="gmail_quote">I have a new
                        problem: Register RBP is used in a function foo.
                         (I am not allocating RBP to any virtual
                        register, the instances of RBP in function foo
                        are in the machine code when my register
                        allocator starts.)<br>
                        <br>
                        Function foo calls function bar.  Register RBP
                        is not saved across the call, though it is live
                        after the call.  Function bar includes a virtual
                        register.  The code that I'm using to find the
                        registers available to be allocated to that
                        virtual register includes EBP in that
                        available-preg set.  This is a disaster, since
                        writing into EBP clobbers RBP.<br>
                        <br>
                        I tried to add code to save all live physical
                        registers across calls, but I don't know how to
                        get the appropriate TargetRegisterClass (needed
                        to call CreateSpillStackObject).<br>
                        <br>
                        Is there a different way to save/restore RBP
                        across calls?  Or a way to get its
                        TargetRegisterClass?<span><br>
                          <br>
                          Susan<br>
                        </span></blockquote>
                    </div>
                    <br>
                  </div>
                </blockquote>
                <br>
              </div>
            </div>
          </blockquote>
        </div>
        <br>
      </div>
    </blockquote>
    <br>
  </body>
</html>