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

Soham Sinha via llvm-dev llvm-dev at lists.llvm.org
Mon May 7 11:17:04 PDT 2018


Hello Jessica,

I tried running my pass in the PreEmit phase in X86. It doesn't maintain
the alignment of stack pointer. I tried with PreRegAlloc phase and I got
into an error of insufficient register allocation. If I reduce my register
usage, source code can be compiled, but when the generated machine code is
run, I still get segmentation fault.

Regards,
Soham Sinha
PhD Student, Department of Computer Science
Boston University

On Mon, May 7, 2018 at 12:08 PM, Jessica Paquette <jpaquette at apple.com>
wrote:

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


More information about the llvm-dev mailing list