<div style="line-height:1.7;color:#000000;font-size:14px;font-family:Arial"><div style="white-space: pre-wrap; color: rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">Hi Everyone£¡<br><span id="result_box" class="short_text" lang="en"><span class="">I am a newbie at llvm. So the question may be </span></span><span id="result_box" class="short_text" lang="en"><span class=""><span class="m"></span>fundamental but difficult to me.</span></span></div><div style="white-space: pre-wrap; color: rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"><span id="result_box" class="short_text" lang="en"><span class="">I want to add an  trinsics in x86 and</span></span><span id="result_box" class="short_text" lang="en"><span class=""> make the following changes.I want that max_qb can find the max </span></span><span id="result_box" class="short_text" lang="en"><span class="">of two Integers and return it. </span></span></div><div style="white-space: pre-wrap; color: rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"><span id="result_box" class="short_text" lang="en"><span class="">In src/include/llvm/IR/</span></span>Intrinsics.td :<br>  let TargetPrefix = "x86" in {<br>      def int_x86_max_qb: GCCBuiltin<"__builtin_x86_max_qb">,<br>      Intrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty], [<code class="language-cpp hljs">IntrNoMem</code>]>;<br>  }</div><div style="white-space: pre-wrap; color: rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">In src//tools/clang/include/clang/Basic/BuiltinsX86.def</div><div style="white-space: pre-wrap; color: rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"><code class="hljs java"> TARGET_BUILTIN(__builtin_x86_max_qb, "V2iV2iV2i", "ncV:64:", "") //</code><span id="result_box" class="short_text" tabindex="-1" lang="en"><span>I don't know the meaning of these parameters, just write according to the add function.</span></span></div><div style="white-space: pre-wrap; color: rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">In src/tools/clang/lib/CodeGen/CGBuiltin.cpp. in function EmitX86BuiltinExpr</div><div style="white-space: pre-wrap; color: rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">  case X86::BI__builtin_x86_max_qb:{<br>     return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_max_qb));<br>  }<br>Then I do a simple test£¬just like this£º</div><div style="white-space: pre-wrap; color: rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">#include <stdlib.h><br>#include <stdio.h> <br>int main()<br>{<br>  int a, b, c;<br>  a=1;b=2;<br>  c = int_x86_max_qb(a, b); <br>}<br><code class="hljs java"></code></div><div style="white-space: pre-wrap; color: rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">When I use clang to <span id="result_box" class="short_text" tabindex="-1" lang="en"><span class=""> compile£¬there is a warning:implicit declaration of function 'int_x86_max_qb' is invalid in C99 [-Wimplicit-function-declaration].</span></span></div><div style="white-space: pre-wrap; color: rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"><span id="result_box" class="short_text" tabindex="-1" lang="en"><span class="">So I add the </span></span><span id="result_box" class="short_text" tabindex="-1" lang="en"><span class="">definition in src/lib/Target/X86/X86InstrInfo.td</span></span></div><div style="white-space: pre-wrap; color: rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"><span id="result_box" class="short_text" tabindex="-1" lang="en"><span class="">def MAX_QB : I<0xff,RawFrm, (outs  GR32:$Rd), (ins GR32:$src1,GR32:$src2),"max_qb \t $Rd $src1 $src2", []>,  OpSize32;</span></span></div><div style="white-space: pre-wrap; color: rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"><span id="result_box" class="short_text" tabindex="-1" lang="en"><span class="">But it doesn't work.</span></span><span id="result_box" class="short_text" tabindex="-1" lang="en"><span class=""><span id="result_box" class="short_text" tabindex="-1" lang="en"><span>What should I do to make it correct? please tell me.Thanks.</span></span></span></span></div><div style="white-space: pre-wrap; color: rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"><span id="result_box" class="short_text" tabindex="-1" lang="en"><span class=""><span id="result_box" class="short_text" tabindex="-1" lang="en"><span><br></span></span></span></span></div><div style="white-space: pre-wrap; color: rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"><span id="result_box" class="short_text" tabindex="-1" lang="en"><span class=""><br></span></span></div></div><br><br><span title="neteasefooter"><p><br/> </p></span>