<div dir="ltr">Hello,<br><br>I've made some fair progress on a target for 6502 family CPUs recently, but I've run into an error I'm not sure how to address. I've ruminated over it for about a week now, trying various things and not having any success. It seems to scale with the number of routines in my .ll file, which I am trying to run through llc. I get the following stack dump from an assertion:<br>
<div><br>llc: LeaksContext.h:50: void llvm::LeakDetectorImpl<T>::addGarbage(const T*) [with T = void]: Assertion `Ts.count(o) == 0 && "Object already in set!"' failed.<br>0  llc       0x08d2cde8<br>
1  llc       0x08d2d344<br>2            0xb7762400 __kernel_sigreturn + 0<br>3            0xb7762424 __kernel_vsyscall + 16<br>4  libc.so.6 0xb746a98f gsignal + 79<br>5  libc.so.6 0xb746c2d5 abort + 373<br>6  libc.so.6 0xb74636a5<br>
7  libc.so.6 0xb7463757<br>8  llc       0x08180167<br>9  llc       0x08c32bec llvm::LeakDetector::addGarbageObjectImpl(void*) + 380<br>10 llc       0x088a8ec5 llvm::MachineInstr::MachineInstr(llvm::MCInstrDesc const&, llvm::DebugLoc, bool) + 245<br>
11 llc       0x08899daf llvm::MachineFunction::CreateMachineInstr(llvm::MCInstrDesc const&, llvm::DebugLoc, bool) + 111<br>12 llc       0x0871b4a0 llvm::InstrEmitter::EmitMachineNode(llvm::SDNode*, bool, bool, llvm::DenseMap<llvm::SDValue, unsigned int, llvm::DenseMapInfo<llvm::SDValue> >&) + 512<br>
13 llc       0x0866dfbd llvm::ScheduleDAGSDNodes::EmitSchedule(llvm::MachineBasicBlock::bundle_iterator<llvm::MachineInstr, llvm::ilist_iterator<llvm::MachineInstr> >&) + 1325<br>14 llc       0x086ea97f llvm::SelectionDAGISel::CodeGenAndEmitDAG() + 1439<br>
15 llc       0x086ecdf6 llvm::SelectionDAGISel::SelectBasicBlock(llvm::ilist_iterator<llvm::Instruction const>, llvm::ilist_iterator<llvm::Instruction const>, bool&) + 198<br>16 llc       0x086f3cf0 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) + 2176<br>
17 llc       0x086f5850 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) + 1392<br>18 llc       0x088a0aca llvm::MachineFunctionPass::runOnFunction(llvm::Function&) + 186<br>19 llc       0x08c42fa3 llvm::FPPassManager::runOnFunction(llvm::Function&) + 659<br>
20 llc       0x08c4302c llvm::FPPassManager::runOnModule(llvm::Module&) + 76<br>21 llc       0x08c42c60 llvm::MPPassManager::runOnModule(llvm::Module&) + 592<br>22 llc       0x08c46528 llvm::PassManagerImpl::run(llvm::Module&) + 168<br>
23 llc       0x08c46636 llvm::PassManager::run(llvm::Module&) + 38<br>24 llc       0x0818513a main + 4026<br>25 libc.so.6 0xb74546b3 __libc_start_main + 243<br>26 llc       0x08195e8d<br>Stack dump:<br>0.    Program arguments: /home/MathOnNapkins/Documents/Programming/llvm-3.2/Release+Asserts/bin/llc -march=x65 -debug -filetype=asm ./test.ll <br>
1.    Running pass 'Function Pass Manager' on module './test.ll'.<br>2.    Running pass 'x65 DAG->DAG Pattern Instruction Selection' on function '@foo_and32'<br><br></div><div>For reference, I see this with both llvm 3.1 and 3.2. I have not tried the svn trunk, though.<br>
</div><div><br></div><div>The test *.ll file contains a number of small test routines, and I'll include it in the body as well:<br><br>    define i32 @foo_add32(i32 %alpha) nounwind<br>    {<br>        %result = add nsw i32 %alpha, 262145<br>
<br>        ret i32 %result<br>    }<br><br>     define i32 @foo_sub32(i32 %alpha) nounwind<br>     {<br>         %result = sub i32 %alpha, 262147<br><br>         ret i32 %result<br>     }<br><br>    define i32 @test_or32(i32 %alpha) nounwind<br>
    {<br>        %result = or i32 %alpha, 262148<br><br>        ret i32 %result<br>    }<br><br>    define i32 @foo_xor32(i32 %alpha) nounwind<br>    {<br><br>        %result = xor i32 %alpha, 262149<br><br>        ret i32 %result<br>
    }<br><br>    define i32 @foo_and32(i32 %alpha) nounwind<br>    {<br><br>        %result = and i32 %alpha, 262150<br><br>        ret i32 %result<br>    }<br><br>    ; Testing commutivity of add operation.<br>    define i32 @foo_reverse_add32(i32 %alpha) nounwind<br>
    {<br>        %result = add nsw i32 262151, %alpha<br><br>        ret i32 %result<br>    }<br><br></div><div>Previously, I had been testing with only one routine per test .ll file, but I thought I'd reached a point where I could test multiple operations at once and understand the output. The odd part about this is that the likelihood of seeing the above assertion scales with the number of functions in the .ll file. If I have one or two functions, I never see it. With three, I see it sporadically. With four or five, I see it about 80% of the time. I don't understand why it would only assert some of the time, as the inputs are not changing. Could it be a problem with my system itself, or perhaps I'm running low on RAM? If anybody has any insight on how to troubleshoot this kind of problem, i'd be very grateful.<br>
<br>Also, I have not overriden runOnMachineFunction() in my XXXISelDagToDag.cpp file, so this is happening somewhat out of my control. Should I attempt to override it? I noticed that only a couple targets actually override runOnMachineFunction() for that particular pass (MIPS, I think is one).<br>
<br></div><div>Sincerely,<br></div><div>~MathOnNapkins / Dave<br></div><div><br></div></div>