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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20180906/57706ad3/attachment.html>
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>
Your opinion is very important, thank you very much. I want to ask you, if there
are some learning materials about how to add an trinsics in x86 or these are
your accumulated experience. The documenmation(Extending LLVM: Adding
instructions, intrinsics, types, etc.https://llvm.org/docs/ExtendingLLVM.html)
doesn't tell much content,I think.
I still have a question which I hope you answer.
In X86Instrindo.td, I define the max_qb as fllowing
def max_qb : I<0xff,RawFrm, (outs GR32:$Rd), (ins
GR32:$src1,GR32:$src2),"max_qb\t $Rd ,$src1 $src2", []>, OpSize32;
When I make the llvm,"Unexpected number of operands for RawFrm"
appears.
How can I do to convert trinsics to binary instructions?
Thanks a lot.
At 2018-09-07 00:46:05, "Craig Topper" <craig.topper at
gmail.com> wrote:
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/20180907/71021db0/attachment-0001.html>