[llvm-dev] Writing simple intrinsic in clang

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


You were right, i forgot the include, thanks for your answers)

ср, 26 сент. 2018 г. в 21:07, Friedman, Eli <efriedma at codeaurora.org>:

> Are you sure you actually defined the intrinsic?  (If you're adding a new
> .td file to include/llvm/IR/, you need to make sure there's a corresponding
> line in include/llvm/IR/Intrinsics.td.)
>
> -Eli
>
> On 9/26/2018 1:29 AM, Павел Безбородов wrote:
>
> 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
>>
>>
> --
> 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/fdcef6e4/attachment.html>


More information about the llvm-dev mailing list