Hi Susan,<div><br></div><div>Sorry - I had missed that you're using llvm-3.1, rather than the development branch. We encourage people to live on top-of-tree - it's well tested, easier for active developers to offer help with, and keeping up with incremental changes is often easier than porting between stable versions.</div>
<div><br></div><div>It also sounds like you were building a Release version of LLVM. That will not have any asserts enabled (though it will have some other diagnostics). You will probably want to work with a Debug+Asserts version (<src>/configure --disable-optimized --enable-assertions) while you're developing your allocator and watch for any asserts that trigger.</div>
<div><br></div><div>In your case the Assertion that is triggering in PEI indicates that the MachineRegisterInfo object still contained some virtregs post register-allocation. You need to call MRI->clearVirtRegs() at the end of your allocator.</div>
<div><br></div><div>Hope this helps!</div><div><br></div><div>Cheers,</div><div>Lang.<br><br><div class="gmail_quote">On Thu, Nov 1, 2012 at 2:41 PM, Susan Horwitz <span dir="ltr"><<a href="mailto:horwitz@cs.wisc.edu" target="_blank">horwitz@cs.wisc.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi again Lang,<br>
<br>
I decided to try the approach you proposed to see whether it makes the assembly-code problem go away.  Again, I tried a very simple register allocator (attached) that just calls vrm.assignVirt2Phys for every vreg in each function, mapping the vreg to the first preg in the register class.  I tried two versions: one maps *every* vreg, and the other only maps those for which MRI->reg_empty(vreg) returns false.  In both cases I get a core dump somewhere after my reg-allocation pass has run (when I use the "tst.c" file that I sent last time as input).<br>

<br>
Note also that there is no VirtRegMap.h in the "include" directory of my installed llvm-3.1.  I had to copy that file from the source directory.  That seems suspicious.<br>
<br>
Any thoughts?<br>
<br>
Thanks!<br>
<br>
Susan<div class="im"><br>
<br>
On 10/31/2012 07:51 PM, Lang Hames wrote:<br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Susan,<br>
<br><div class="im">
I'm having trouble reproducing that error on my end, but I think the<br>
problem is probably that you're not using the VirtRegRewriter<br>
infrastructure. What your allocator needs to do is populate the virtual<br>
register mapping (VirtRegMap pass) with your allocation, rather than<br>
rewriting the registers directly through MachineRegisterInfo.<br>
<br>
Have your allocator require and preserve the VirtRegMap pass, then in<br>
your runOnMachineFunction pass grab a reference to the pass with:<br>
<br>
VirtRegMap &vrm = getAnalysis<VirtRegMap>();<br>
<br>
You can then describe your register allocations with:<br>
<br>
vrm.assignVirt2Phys(<virtreg>, <physreg>)<br>
<br>
The VirtRegRewriter pass (in VirtRegMap.cpp) will run after your<br>
allocator and apply the mapping that you described in the VirtRegMap.<br>
<br>
I hope this helps. Let me know if it doesn't fix your issue.<br>
<br>
Cheers,<br>
Lang.<br>
<br>
On Wed, Oct 31, 2012 at 3:54 PM, Susan Horwitz <<a href="mailto:horwitz@cs.wisc.edu" target="_blank">horwitz@cs.wisc.edu</a><br></div><div class="im">
<mailto:<a href="mailto:horwitz@cs.wisc.edu" target="_blank">horwitz@cs.wisc.edu</a>>> wrote:<br>
<br>
    Thanks Lang!<br>
<br>
    Here's another question: I'm trying to process this input:<br>
<br>
    int main() {<br>
       return 0;<br>
    }<br>
<br>
    but I'm getting an error<br></div>
      Assertion `!Fn.getRegInfo(). getNumVirtRegs() && "Regalloc must<div><div class="h5"><br>
    assign all vregs"' failed.<br>
<br>
    At the start of runOnMachineFunction I call Fn.getRegInfo().<br>
    getNumVirtRegs();<br>
    and find that there is 1 virtual register.  However,<br>
      MRI->reg_empty(vreg)<br>
    tells me that it is not used or defined.  So my register-allocation<br>
    code never sees it, and thus can't allocate a preg for it.  I tried<br>
    using MRI->replaceRegWith(vreg, preg);<br>
    (where preg is available to vreg's register class) but that didn't<br>
    work.  When I look, the number of vregs in the function is still 1.<br>
<br>
    Can you help with this?<br>
<br>
    Thanks again!<br>
<br>
    Susan<br>
<br>
<br>
    On 10/31/2012 04:55 PM, Lang Hames wrote:<br>
<br>
        Hi Susan,<br>
<br>
        The meaning of "addRequired(X)" is that your pass needs X to be<br>
        run, and<br>
        for X to be preserved by all passes that run after X and before your<br>
        pass. The PHIElemination and TwoAddressInstruction passes do not<br>
        preserve each other, hence there's no way for the pass manager to<br>
        schedule them for you if you addRequire(...) them.<br>
<br>
        The trick is that CodeGen will schedule both of these passes to<br>
        be run<br>
        before _any_ register allocation pass (see Passes.cpp), so you<br>
        needn't<br>
        require them explicitly - you can just assume they have been<br>
        run. If you<br>
        just remove those lines from your getAnalysisUsage method your pass<br>
        should now run as you expect.<br>
<br>
        Cheers,<br>
        Lang.<br>
<br>
        On Wed, Oct 31, 2012 at 1:46 PM, Susan Horwitz<br>
        <<a href="mailto:horwitz@cs.wisc.edu" target="_blank">horwitz@cs.wisc.edu</a> <mailto:<a href="mailto:horwitz@cs.wisc.edu" target="_blank">horwitz@cs.wisc.edu</a>><br></div></div><div><div class="h5">
        <mailto:<a href="mailto:horwitz@cs.wisc.edu" target="_blank">horwitz@cs.wisc.edu</a> <mailto:<a href="mailto:horwitz@cs.wisc.edu" target="_blank">horwitz@cs.wisc.edu</a>>>> wrote:<br>
<br>
             I'm trying to write a MachineFunctionPass to do register<br>
        allocation.<br>
               I have code that worked with an old version of LLVM.  It<br>
        does not<br>
             work with llvm-3.1. (or various other versions that I've<br>
        tried).<br>
<br>
             The first problem is that including this line:<br>
<br>
               AU.addRequiredID(__ TwoAddressInstructionPassID);<br>
<br>
<br>
             in method getAnalysisUsage causes a runtime error:<br>
<br>
             Unable to schedule 'Eliminate PHI nodes for register<br>
        allocation'<br>
             required by 'Unnamed pass: implement Pass::getPassName()'<br>
             Unable to schedule pass<br>
             UNREACHABLE executed at ...<br>
<br>
             I'm invoking the pass like this (given input file foo.c):<br>
<br>
             clang -emit-llvm -O0 -c foo.c -o foo.bc<br>
             opt -mem2reg foo.bc > foo.ssa<br>
             mv foo.ssa foo.bc<br>
             llc -load Debug/lib/P4.so -regalloc=gc foo.bc<br>
<br>
<br>
             I've attached my entire file (it's very short).  Any help<br>
        would be<br>
             much appreciated!<br>
<br>
             Susan Horwitz<br>
<br>
             ______________________________ _________________<br>
             LLVM Developers mailing list<br>
        <a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a> <mailto:<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a>><br></div></div>
        <mailto:<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a> <mailto:<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a>>><div class="im"><br>
        <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
        <a href="http://lists.cs.uiuc.edu/" target="_blank">http://lists.cs.uiuc.edu/</a> mailman/listinfo/llvmdev<br></div>
        <<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/<u></u>mailman/listinfo/llvmdev</a>><br>
<br>
<br>
<br>
<br>
</blockquote>
<br>
</blockquote></div><br></div>