Hi Tanya and everybody, Ty for your support. I too believe it should not be complicated. But I was not being able to do it. For instance, I tried to run this code below: BB->push_back(&(BB->front())); BB->pop_front(); But it did not work (kinda obvious why). Nor this: BB->push_back(BB->begin()); BB->pop_front(); But also did not work. It seams the same instruction may not be duplicated in the base block. Finally, after some thinking (and tinkering), this worked like a charm: MachineInstr* mi = BB->remove(BB->begin()); BB->push_back(mi); =D But, is there a better way to do it? And for inserting a NOP ? Is there a simple way? Ty again. 2007/8/8, Tanya M. Lattner <tonic at nondot.org>:> > > > I need a way to reorder instructions inside MachineBasicBlocks or > > MachineFunctions. > > I've been searching for it but I have not found an example in the code > yet. > > For MachineBasicBlocks, check out this doc: > http://llvm.org/doxygen/classllvm_1_1MachineBasicBlock.html > > I believe its basically the same as basic blocks in that you can > manipulate the instruction list. > > Otherwise, you need to write a MachineFunction Pass: > http://llvm.org/docs/WritingAnLLVMPass.html#MachineFunctionPass > > -Tanya > _______________________________________________ > 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20070809/db2f6b9d/attachment.html>
My suggestion for NOP's: create a method "addNop()" in the MRegisterInfo class, and make it concrete on the targets that you are planning to use. For instance, in the x86, the opcode for NOP is 0x90 (le'me just use this opportunity to thank Anton for telling me the opcode :) use the method "copyRegToReg" as an example of how to add further methods into MRegisterInfo. The bad thing is that your version of LLVM will be off with the distributed version. Well, because more people have had this necessity of adding Nop's into the code, maybe the LLVM guys could consider adding this method officially to the MRegisterInfo class... and also a "swapRegs()" method into that class. It is very useful in register allocation. best, Fernando> Hi Tanya and everybody, > > Ty for your support. > > I too believe it should not be complicated. > But I was not being able to do it. > > For instance, I tried to run this code below: > > BB->push_back(&(BB->front())); > BB->pop_front(); > > But it did not work (kinda obvious why). > > Nor this: > > BB->push_back(BB->begin()); > BB->pop_front(); > > But also did not work. It seams the same instruction may not be duplicated > in the base block. > > Finally, after some thinking (and tinkering), this worked like a charm: > > MachineInstr* mi = BB->remove(BB->begin()); > BB->push_back(mi); > > =D > > But, is there a better way to do it? > And for inserting a NOP ? Is there a simple way? > > Ty again. > > > 2007/8/8, Tanya M. Lattner <tonic at nondot.org>: >> >> >>> I need a way to reorder instructions inside MachineBasicBlocks or >>> MachineFunctions. >>> I've been searching for it but I have not found an example in the code >> yet. >> >> For MachineBasicBlocks, check out this doc: >> http://llvm.org/doxygen/classllvm_1_1MachineBasicBlock.html >> >> I believe its basically the same as basic blocks in that you can >> manipulate the instruction list. >> >> Otherwise, you need to write a MachineFunction Pass: >> http://llvm.org/docs/WritingAnLLVMPass.html#MachineFunctionPass >> >> -Tanya >> _______________________________________________ >> 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 >
> But also did not work. It seams the same instruction may not be duplicated > in the base block.That is correct. You must remove it before moving it.> But, is there a better way to do it?I don't believe so. 2 lines of code are not that much though. -Tanya
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/
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 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20070809/7f546c7f/attachment.html>