[llvm-dev] Reg: Adding Intrinsic at start of every function
Armand Behroozi via llvm-dev
llvm-dev at lists.llvm.org
Tue May 4 08:11:05 PDT 2021
Hey,
I'm probably not the best person to answer this, but I'll say something in
case no one else does b/c something is better than nothing. I noticed you
re-asked your question, so I'm replying on the older one in case someone
more qualified sees the more recent one.
I'm going to assume by "intrinsic" you mean an llvm intrinsic function. If
you're asking your question here, it sounds like you probably already tried
inserting your intrinsic function as the first IR instruction, looked at
the assembly and noticed that your instruction/instruction sequence isn't
the first one in the function. It's possible that there's a way to do it in
IR, but if there is, idk how to do it.
If I were to do it, I'd use a machine function pass like you suggest and
instead of an intrinsic create and insert the instruction as part of the
last pass in the codegen process (end of preEmit2 in x86). That way you
have total control where the instruction goes and know nothing in the
codegen process is going to move it.
MachineFunction passes sound scary, but here's a pretty pain-free link for
how to write your first one:
https://www.kharghoshal.xyz/blog/writing-machinefunctionpass. It's for x86,
but I'm sure you could do the same thing for RISC-V. There's one typo: " In
the pass's .cpp file "createX86MachineInstrPrinter*Pass*" is defined, and
in the other files "createX86MachineInstrPrinter" is used." They just need
to be the same.
All the best.
Regards,
Armand
On Mon, May 3, 2021 at 12:03 PM Sai Venkata Krishnan V via llvm-dev <
llvm-dev at lists.llvm.org> wrote:
> Hello Everyone
> I have create a new intrinsic in RISCV and I am trying to insert it at
> the start of every function based on Command-Line argument which determines
> the list of functions to omit. I expect this intrinsic to be inserted at
> the start of function as first instruction. Is this possible with a normal
> Module pass using opt command? Or, should I look into MachineFunction pass?
> Please guide me in this.
>
> Thanking you
> Sai
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://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/20210504/307fe203/attachment.html>
More information about the llvm-dev
mailing list