[llvm-dev] How to add assembly instructions in CodeGen

Jessica Paquette via llvm-dev llvm-dev at lists.llvm.org
Mon May 7 09:08:57 PDT 2018


One place to look might be in the MachineOutliner target hooks in X86InstrInfo and AArch64InstrInfo. The MachineOutliner runs extremely late in the pass pipeline so it might be a good place to look for some inspiration. Of course, because this is *extremely late* it might not do *exactly* what you need. (e.g, this is post-register allocation, post frame-lowering, etc.)

- Jessica

> On May 4, 2018, at 6:32 PM, Soham Sinha via llvm-dev <llvm-dev at lists.llvm.org> wrote:
> 
> Hello,
> 
> I want to add assembly instructions at certain points in a function. This is X86 specific. So I am working in the lib/Target/X86 folder. I create a `MachineFunctionPass` in that folder. I register it in the X86TargetMachine.cpp in addPreEmitPass(). I use BuildMI to insert my own assembly instructions in the MachineFunctionPass. This works and my assembly instructions are inserted at desired places. However, this breaks the alignment. So when I run the generated code, I get segmentation fault (precisely in printf with XMM registers). Where should I add my pass? 
> 
> My pass depends on the MachineBasicBlock information as well. Therefore, I cannot add my pass too early in LLVM IR. What is the proper pass to add my custom MachineFunctionPass? I tried addPreRegAlloc, but it failed due to insufficient register allocation error or something on that line.
> 
> Can anybody please help me write a MachineFunctionPass where I can insert assembly instruction without breaking the alignment? I am doing this for X86_64.
> 
> Regards,
> Soham Sinha
> PhD Student, Department of Computer Science
> Boston University
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev



More information about the llvm-dev mailing list