[llvm-dev] Fwd: Writing simple intrinsic in clang

Павел Безбородов via llvm-dev llvm-dev at lists.llvm.org
Wed Sep 26 01:30:53 PDT 2018


Actually, I've done it, but I have problem with Intrinsic namespace, while
adding my intrinsic to CodeGenFunction::EmitMyTargetBuiltinExpr I do
something like CGF.getIntrinsic(Intrinsic::my_builtin) and it throws error
/tools/clang/lib/CodeGen/CGBuiltin.cpp:10327: error: no member named
'arc_sub4' in namespace 'llvm::Intrinsic'
        llvm::Function *F = CGM.getIntrinsic(Intrinsic::arc_sub4);
                                             ~~~~~~~~~~~^
I don't know how to fix this.
I'm new to LLVM and need some help in it...

вт, 25 сент. 2018 г. в 21:12, Friedman, Eli <efriedma at codeaurora.org>:

> On 9/24/2018 6:47 AM, Павел Безбородов via llvm-dev wrote:
> > I want to write a simple backend-specific instrinsic that will just
> > call an instruction. How should I do that?
>
> Is this really not documented anywhere...?
>
> Anyway, the basic steps:
>
> 1. Add the builtin to the list of intrinsics for your target:
> include/llvm/IR/IntrinsicsYourTarget.td.  Use a GCCBuiltin for the
> corresponding C intrinisc name.
> 2. Teach your target to lower the intrinsic to an instruction; you can
> usually just use the name of the intrinsic in a pattern in
> lib/Target/YourTarget/YourTargetInstrInfo.td.
> 3. Add the builtin to include/clang/Basic/BuiltinsYourTarget.def
>
> An example of an intrinsic implemented this way is int_arm_qadd8  in the
> ARM backend (corresponding to the C builtin __builtin_arm_qadd8); it
> should be straightforward to follow that example.
>
> This approach assumes your intrinsic is simple: it returns at most one
> value, and all the parameter and return types are legal.  If that isn't
> true, you might need to write some C++ code to handle it in clang or in
> your backend.
>
> Maybe we should add this as a section to
> http://llvm.org/docs/WritingAnLLVMBackend.html .
>
> -Eli
>
> --
> Employee of Qualcomm Innovation Center, Inc.
> Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux
> Foundation Collaborative Project
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180926/fd46870a/attachment.html>


More information about the llvm-dev mailing list