[LLVMdev] Changing basic blocks

Emílio Wuerges wuerges at gmail.com
Wed Aug 15 18:13:55 PDT 2007


Hi all,

A week agoo I sent an email about reordering instruction in basicblocks.
And ... I was able to do it. I guess so, at least.

Now when compiling my test program, llc dumps:

--
llc: /home/mentat/llvm_work/llvm/lib/CodeGen/LiveVariables.cpp:155: void
llvm::LiveVariables::HandleVirtRegUse(llvm::LiveVariables::VarInfo&,
llvm::MachineBasicBlock*, llvm::MachineInstr*): Assertion `VRInfo.DefInst &&
"Register use before def!"' failed.
llc((anonymous namespace)::PrintStackTrace()+0x1a)[0x86a167a]
[0x6]
/lib/libc.so.6(abort+0x108)[0x556d9dc8]
/lib/libc.so.6(__assert_fail+0xfc)[0x556d1f6c]
llc(llvm::LiveVariables::HandleVirtRegUse(llvm::LiveVariables::VarInfo&,
llvm::MachineBasicBlock*, llvm::MachineInstr*)+0x15a)[0x84ffb0a]
make: *** [qsort_small.s] Aborted
--

The string "Register use before def!" kinda annoyed me.
So I wrote and run this test code, wich -should- just remove all
instructions in the basic block and put them back:

--
int total = BB->size();
std::vector<MachineInstr*> positionmap(total);
  for (int i = 0; i< total; ++i)
    positionmap.push_back(BB->remove(BB->begin()));
  for(int i = 0; i< total; ++i)
    BB->push_back(positionmap[i]);
--

And the same error ocurred.

Then I did this:

--
int total = BB->size();
for(int i = 0; i<total; ++i)
  BB->push_back(BB->remove(BB->begin()));
--

And this worked. Flawlessly. Without the error. But this is useless ^_^.

Can someone help me to understand this behavior?


PS, beware code above, I just tested it, not proven it correct, hehe.

2007/8/9, Emílio Wuerges <wuerges at gmail.com>:
>
> For adding the nop:
>
> TII->insertNoop(*BB, BB->end());
>
>
> 2007/8/9, Chris Lattner <sabre at nondot.org>:
> >
> > On Thu, 9 Aug 2007, [ISO-8859-1] Emílio Wuerges wrote:
> > > I too believe it should not be complicated.
> > > But I was not being able to do it.
> > > Finally, after some thinking (and tinkering), this worked like a
> > charm:
> > >
> > >  MachineInstr* mi = BB->remove(BB->begin());
> > >  BB->push_back(mi);
> > >
> > > But, is there a better way to do it?
> >
> > This is a good way to do a single instruction.  You can also use the
> > splice method, which allows you to move around ranges of instructions in
> > constant time.  It works the same was as std::list::splice.
> >
> > -Chris
> >
> > --
> > http://nondot.org/sabre/
> > http://llvm.org/
> > _______________________________________________
> > LLVM Developers mailing list
> > LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
> >
> >
>
>
> --
> Emilio Wuerges
> LAPS - Laboratorio de Automacao de Projeto de Sistemas
> UFSC - Universidade Federal de Santa Catarina
> Brasil
>



-- 
Emilio Wuerges
LAPS - Laboratorio de Automacao de Projeto de Sistemas
UFSC - Universidade Federal de Santa Catarina
Brasil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20070815/6bac2936/attachment.html>


More information about the llvm-dev mailing list