[LLVMdev] Changing basic blocks

Fernando Magno Quintao Pereira fernando at CS.UCLA.EDU
Wed Aug 8 22:31:03 PDT 2007


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
>



More information about the llvm-dev mailing list