[llvm-dev] Adding an trinsics in x86 (original) (raw)

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 maxqb can find the max of two Integers and return it. In src/include/llvm/IR/Intrinsics.td : let TargetPrefix = "x86" in { def intx86maxqb: GCCBuiltin<"_builtinx86maxqb">, Intrinsic<[llvmi32ty], [llvmi32ty, llvmi32ty], [IntrNoMem]>; } In src//tools/clang/include/clang/Basic/BuiltinsX86.def _TARGETBUILTIN(builtinx86maxqb, "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_builtinx86maxqb:{ return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86maxqb)); } 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 = intx86maxqb(a, b); } When I use clang to compile,there is a warning:implicit declaration of function 'intx86maxqb' is invalid in C99 [-Wimplicit-function-declaration]. So I add the definition in src/lib/Target/X86/X86InstrInfo.td def MAXQB : I<0xff,RawFrm, (outs GR32:$Rd), (ins_ _GR32:$src1,GR32:$src2),"maxqb \t RdRd Rdsrc1 $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