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

Soham Sinha via llvm-dev llvm-dev at lists.llvm.org
Fri May 4 18:32:01 PDT 2018


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180504/7d720e63/attachment.html>


More information about the llvm-dev mailing list