[llvm-dev] Adding an trinsics in x86

Craig Topper via llvm-dev llvm-dev at lists.llvm.org
Thu Sep 6 09:46:05 PDT 2018


Your builtin shouldn't use "V2iV2iV2i", V2i means it take a vector of two
32-bit integers. You just want "iii". You also don't need code in
CGBuiltin.cpp if you have a GCCBuiltin name in Intrinsics.td.

In your C code you need to call __builtin_x86_max_qb not
int_x86_max_qb. int_x86_max_qb(really
llvm.x86.max.qb) is the name in LLVM IR. Clang's C parser knows it as
__builtin_x86_max_qb because that's the name in clangs BuiltinsX86.def.


~Craig


On Thu, Sep 6, 2018 at 4:19 AM 沈天豪 via llvm-dev <llvm-dev at lists.llvm.org>
wrote:

> Hi Everyone!
> I am a newbie at llvm. So the question may be fundamental but difficult
> to me.
> I want to add an trinsics in x86 and make the following changes.I want
> that max_qb can find the max of two Integers and return it.
> In src/include/llvm/IR/Intrinsics.td :
> let TargetPrefix = "x86" in {
> def int_x86_max_qb: GCCBuiltin<"__builtin_x86_max_qb">,
> Intrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty], [IntrNoMem]>;
> }
> In src//tools/clang/include/clang/Basic/BuiltinsX86.def
> TARGET_BUILTIN(__builtin_x86_max_qb, "V2iV2iV2i", "ncV:64:", "") //I
> don't know the meaning of these parameters, just write according to the add
> function.
> In src/tools/clang/lib/CodeGen/CGBuiltin.cpp. in function
> EmitX86BuiltinExpr
> case X86::BI__builtin_x86_max_qb:{
> return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_max_qb));
> }
> Then I do a simple test,just like this:
> #include <stdlib.h>
> #include <stdio.h>
> int main()
> {
> int a, b, c;
> a=1;b=2;
> c = int_x86_max_qb(a, b);
> }
> When I use clang to compile,there is a warning:implicit declaration of
> function 'int_x86_max_qb' is invalid in C99
> [-Wimplicit-function-declaration].
> So I add the definition in src/lib/Target/X86/X86InstrInfo.td
> def MAX_QB : I<0xff,RawFrm, (outs GR32:$Rd), (ins
> GR32:$src1,GR32:$src2),"max_qb \t $Rd $src1 $src2", []>, OpSize32;
> But it doesn't work.What should I do to make it correct? please tell
> me.Thanks.
>
>
>
>
>
>
> _______________________________________________
> 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/20180906/373ec49c/attachment.html>


More information about the llvm-dev mailing list