<div dir="ltr">Hi Stefan,<div><br></div><div>Thank you very much for answering my question!</div><div><br></div><div>I followed your suggestion but the function still cannot return the correct result. I also set target-feature attributes for my function. I am using LLVM 6.0.</div><div><br></div><div>

<div style="font-size:small;text-decoration-style:initial;text-decoration-color:initial">It only prints out some random large numbers but the correct answer is supposed to be all 0.</div><div><br></div>Can you please help me figure out what's going on here? Any help will be greatly appreciated.<br class="gmail-Apple-interchange-newline">

<br></div><div>

<div style="font-size:small;text-decoration-style:initial;text-decoration-color:initial;background-color:rgb(255,255,255)">///////////////////////////////////////////////////////////////////////////////////////////</div><br></div><div>My function prototype definition:</div><div><br></div><div><div>auto vectorDataType = VectorType::get(IntegerType::getIntNTy(TheContext, 64), 4);</div><div>                    std::vector<Type *> vecArguments;</div><div>                    for (Uint64 nodeId = startOfLeaves; nodeId < numNodes; ++nodeId) {</div><div>                        vecArguments.push_back(vectorDataType);</div><div>                    }</div><div>                    proto = FunctionType::get(vectorDataType,//int64*4 = __m256i</div><div>                                              vecArguments, false);</div></div><div><br></div><div>

<span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">//////////////////////////////</span><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">//////////////////////////////</span><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">//////////////////////////////</span><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">/</span><br class="gmail-Apple-interchange-newline">

<br></div><div>The generated IR:</div><div><br></div><div><div>define <4 x i64> @tpchq6(<4 x i64> %leaf7, <4 x i64> %leaf8, <4 x i64> %leaf9, <4 x i64> %leaf10, <4 x i64> %leaf11, <4 x i64> %leaf12, <4 x i64> %leaf13, <4 x i64> %leaf14) #0 {</div><div>entry:</div><div>  %addtmp = add <4 x i64> %leaf8, %leaf7</div><div>  %addtmp1 = add <4 x i64> %addtmp, %leaf9</div><div>  %addtmp4 = add <4 x i64> %addtmp1, %leaf10</div><div>  %addtmp2 = add <4 x i64> %addtmp4, %leaf11</div><div>  %addtmp3 = add <4 x i64> %addtmp2, %leaf12</div><div>  %addtmp5 = add <4 x i64> %addtmp3, %leaf13</div><div>  %addtmp6 = add <4 x i64> %addtmp5, %leaf14</div><div>  ret <4 x i64> %addtmp6</div><div>}</div></div><div><br></div><div>

<div style="font-size:small;text-decoration-style:initial;text-decoration-color:initial;background-color:rgb(255,255,255)">///////////////////////////////////////////////////////////////////////////////////////////</div><br class="gmail-Apple-interchange-newline">My JIT function call:</div><div><br></div><div><div>using VecInt = int64_t[4];</div></div><div><br></div><div><div>auto function = (int64_t *(*)(</div><div>                            VecInt</div><div>                            , VecInt</div><div>                            , VecInt</div><div>                            , VecInt</div><div>                            , VecInt</div><div>                            , VecInt</div><div>                            , VecInt</div><div>                            , VecInt</div><div>                    ))(TheExecutionEngine->getFunctionAddress(TheFunction->getName().str()));</div></div><div><br></div><div>VecInt argsX = {0,0,0,0};</div><div>int64_t* result = function(argsX,argsX,argsX,argsX,argsX,argsX,argsX,argsX);<br></div><div><br></div><div><br></div><div>

<span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">//////////////////////////////</span><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">//////////////////////////////</span><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">//////////////////////////////</span><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">/</span><br class="gmail-Apple-interchange-newline">My output result:</div><div><div>422162285262848 562251371602737 843692813695832 422162285262848</div></div><div><br></div><div>

<span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">It only prints out some random large numbers but the correct answer is supposed to be all 0.</span><br class="gmail-Apple-interchange-newline">

<br></div><div>

<span style="font-size:small;text-decoration-style:initial;text-decoration-color:initial;background-color:rgb(255,255,255);float:none;display:inline">//////////////////////////////</span><span style="font-size:small;text-decoration-style:initial;text-decoration-color:initial;background-color:rgb(255,255,255);float:none;display:inline">//////////////////////////////</span><span style="font-size:small;text-decoration-style:initial;text-decoration-color:initial;background-color:rgb(255,255,255);float:none;display:inline">//////////////////////////////</span><span style="font-size:small;text-decoration-style:initial;text-decoration-color:initial;background-color:rgb(255,255,255);float:none;display:inline">/</span><br class="gmail-Apple-interchange-newline" style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">

<br></div><div>Thanks,<br>Jia</div><div><br></div><div><span style="color:rgb(102,102,102);font-family:garamond,serif">------------------------------------</span><br></div><div><div><div dir="ltr" class="gmail_signature"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><p style="margin:0in 0in 0.0001pt"><font color="#666666" face="garamond, serif" size="2"><span style="line-height:21px">Jia Yu,</span></font></p><p style="margin:0in 0in 0.0001pt"><font color="#666666" face="garamond, serif" size="2"><span style="line-height:21px">Ph.D. Student in </span></font><span style="color:rgb(102,102,102);font-family:garamond,serif;font-size:small">Computer Science</span></p><div style="line-height:21px"><p style="line-height:normal;margin:0in 0in 0.0001pt"><font color="#666666" face="garamond, serif" size="2"><a href="http://www.asu.edu/" target="_blank">Arizona State University</a> </font></p></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Sun, Jul 22, 2018 at 8:51 AM Stefan Gränitz <<a href="mailto:stefan.graenitz@gmail.com">stefan.graenitz@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  
    
  
  <div text="#000000" bgcolor="#FFFFFF">
    Hi Jia<br>
    <br>
    I don't think this is a problem with the ExecutionEngine. Your
    problem comes from the confusion of the "Vector Type" in LLVM IR [1]
    with the "std::vector" data structure in the C++ STL. While there is
    no direct relation between the two, you should be able to use a
    std::vector to provide the input for the <4 x i61> Vector Type
    by passing the std::vector's raw data [3].<br>
    <br>
    However, it would be easier with something like this:<br>
    <br>
    using VecInt = int64[4];<br>
    VecInt args0 { 0, 1, 2, 3 };<br>
    ...<br>
    VecInt result = function(args0, ...);<br>
    <br>
    Btw.: Note that you may need to set target-feature attributes for
    your function like so: [3]<br>
    <br>
    Hope it helps.<br>
    <br>
    Cheers,<br>
    Stefan<br>
    <br>
    [1] <a class="m_5311497744342249161moz-txt-link-freetext" href="https://llvm.org/docs/LangRef.html#vector-type" target="_blank">https://llvm.org/docs/LangRef.html#vector-type</a><br>
    [2] <a class="m_5311497744342249161moz-txt-link-freetext" href="https://en.cppreference.com/w/cpp/container/vector" target="_blank">https://en.cppreference.com/w/cpp/container/vector</a><br>
    [3] <a class="m_5311497744342249161moz-txt-link-freetext" href="https://en.cppreference.com/w/cpp/container/vector/data" target="_blank">https://en.cppreference.com/w/cpp/container/vector/data</a><br>
    [4]
<a class="m_5311497744342249161moz-txt-link-freetext" href="https://github.com/weliveindetail/DecisionTreeCompiler/blob/master/compiler/DecisionTreeCompiler.cpp#L83" target="_blank">https://github.com/weliveindetail/DecisionTreeCompiler/blob/master/compiler/DecisionTreeCompiler.cpp#L83</a><br>
    <br>
    <div class="m_5311497744342249161moz-cite-prefix">Am 20.07.18 um 02:02 schrieb Jia Yu via
      llvm-dev:<br>
    </div>
    <blockquote type="cite">
      
      <div dir="ltr">Dear all,
        <div><br>
        </div>
        <div>I am using LLVM C++ API to generate some code. In
          particular, I am dealing with AVX2 SIMD API which uses
          __m256i.</div>
        <div><br>
        </div>
        <div>My function input types a set of vectors and return type is
          also a vector.</div>
        <div><br>
        </div>
        <div>///////////////////////////////////////////////////////////////////////////////////////////</div>
        <div>
          <div>               
            arguments.push_back(VectorType::get(IntegerType::getIntNTy(TheContext,
            64), 4));//int64*4 = __m256i</div>
          <div>                FunctionType * proto =
            FunctionType::get(VectorType::get(IntegerType::getIntNTy(TheContext,
            64), 4),//int64*4 = __m256i<br>
          </div>
          <div>                                                       
             arguments, false);</div>
        </div>
        <div>
          <div style="font-size:small;text-decoration-style:initial;text-decoration-color:initial">///////////////////////////////////////////////////////////////////////////////////////////</div>
          <div style="font-size:small;text-decoration-style:initial;text-decoration-color:initial"><br class="m_5311497744342249161gmail-Apple-interchange-newline">
          </div>
          I can successfully use this way to produce the IR of my
          function properly like this:</div>
        <div>
          <div style="font-size:small;text-decoration-style:initial;text-decoration-color:initial">///////////////////////////////////////////////////////////////////////////////////////////</div>
          <div style="text-decoration-style:initial;text-decoration-color:initial">
            <p style="margin-top:0pt;margin-bottom:0pt;direction:ltr;unicode-bidi:embed;vertical-align:baseline"><font color="#000000" face="Arial"><span style="font-size:16px">define <4 x i64>
                  @tpchq6(<4 x i64> %leaf7, <4 x i64>
                  %leaf8, <4 x i64> %leaf9, <4 x i64>
                  %leaf10, <4 x i64> %leaf11, <4 x i64>
                  %leaf12, <4 x i64> %leaf13, <4 x i64>
                  %leaf14) {</span></font></p>
            <p style="margin-top:0pt;margin-bottom:0pt;direction:ltr;unicode-bidi:embed;vertical-align:baseline"><font color="#000000" face="Arial"><span style="font-size:16px">entry:</span></font></p>
            <p style="margin-top:0pt;margin-bottom:0pt;direction:ltr;unicode-bidi:embed;vertical-align:baseline"><font color="#000000" face="Arial"><span style="font-size:16px">  %addtmp = add <4 x i64>
                  %leaf14, %leaf13</span></font></p>
            <p style="margin-top:0pt;margin-bottom:0pt;direction:ltr;unicode-bidi:embed;vertical-align:baseline"><font color="#000000" face="Arial"><span style="font-size:16px">  %leaf8.neg = sub <4 x
                  i64> zeroinitializer, %leaf8</span></font></p>
            <p style="margin-top:0pt;margin-bottom:0pt;direction:ltr;unicode-bidi:embed;vertical-align:baseline"><font color="#000000" face="Arial"><span style="font-size:16px">  %xortmp = xor <4 x i64>
                  %addtmp, %leaf11</span></font></p>
            <p style="margin-top:0pt;margin-bottom:0pt;direction:ltr;unicode-bidi:embed;vertical-align:baseline"><font color="#000000" face="Arial"><span style="font-size:16px">  %addtmp1 = add <4 x
                  i64> %leaf8.neg, %leaf7</span></font></p>
            <p style="margin-top:0pt;margin-bottom:0pt;direction:ltr;unicode-bidi:embed;vertical-align:baseline"><font color="#000000" face="Arial"><span style="font-size:16px">  %subtmp = add <4 x i64>
                  %addtmp1, %leaf9</span></font></p>
            <p style="margin-top:0pt;margin-bottom:0pt;direction:ltr;unicode-bidi:embed;vertical-align:baseline"><font color="#000000" face="Arial"><span style="font-size:16px">  %addtmp2 = add <4 x
                  i64> %subtmp, %leaf10</span></font></p>
            <p style="margin-top:0pt;margin-bottom:0pt;direction:ltr;unicode-bidi:embed;vertical-align:baseline"><font color="#000000" face="Arial"><span style="font-size:16px">  %addtmp3 = add <4 x
                  i64> %addtmp2, %xortmp</span></font></p>
            <p style="margin-top:0pt;margin-bottom:0pt;direction:ltr;unicode-bidi:embed;vertical-align:baseline"><font color="#000000" face="Arial"><span style="font-size:16px">  ret <4 x i64> %addtmp3</span></font></p>
            <p style="margin-top:0pt;margin-bottom:0pt;direction:ltr;unicode-bidi:embed;vertical-align:baseline"><font color="#000000" face="Arial"><span style="font-size:16px">}</span></font></p>
            <br class="m_5311497744342249161gmail-Apple-interchange-newline">
          </div>
          <div style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">///////////////////////////////////////////////////////////////////////////////////////////</div>
          <div><br>
          </div>
          However, when I use JIT ExectionEngine to run it, it cannot
          return the Vector type properly. I tried the jit execution
          engine with non-vector return like int64, it works fine.</div>
        <div><br>
        </div>
        <div>My code is as follows: It always tells me segment fault</div>
        <div>
          <div style="font-size:small;text-decoration-style:initial;text-decoration-color:initial;background-color:rgb(255,255,255)">///////////////////////////////////////////////////////////////////////////////////////////</div>
          <div>// Define the input/output data type in LLVM function</div>
          <div> typedef std::vector<int64_t> VecInt;</div>
        </div>
        <div><br>
        </div>
        <div>
          <div>auto function = reinterpret_cast<VecInt (*)(VecInt ,
            VecInt, VecInt, VecInt, VecInt, VecInt, VecInt,
VecInt)>(TheExecutionEngine->getFunctionAddress(TheFunction->getName().str()));</div>
          <div>VecInt result =
function(functionCallArgs[0],functionCallArgs[1],functionCallArgs[2],functionCallArgs[3],</div>
          <div>                           
functionCallArgs[4],functionCallArgs[5],functionCallArgs[6],functionCallArgs[7]);</div>
        </div>
        <div><br>
        </div>
        <div>std::cout<<"result size "<<
          <span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">result</span>.size()<<"\n";<br>
        </div>
        <div>
          <div style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">///////////////////////////////////////////////////////////////////////////////////////////</div>
          <div style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><br class="m_5311497744342249161gmail-Apple-interchange-newline">
          </div>
          <br class="m_5311497744342249161gmail-Apple-interchange-newline">
          Can someone tell me whether this is the correct way to
          retrieve the vector return type? Or is the vector type return
          supported?</div>
        <div><br>
        </div>
        <div>Thanks,</div>
        <div>Jia Yu<br clear="all">
          <div>
            <div dir="ltr" class="m_5311497744342249161gmail_signature">
              <div dir="ltr">
                <div dir="ltr">
                  <div dir="ltr">
                    <div dir="ltr">
                      <div dir="ltr">
                        <div dir="ltr">
                          <div dir="ltr">
                            <div dir="ltr">
                              <div dir="ltr">
                                <div dir="ltr">
                                  <div dir="ltr">
                                    <div dir="ltr">
                                      <div dir="ltr">
                                        <p style="margin:0in 0in 0.0001pt"><br>
                                        </p>
                                      </div>
                                    </div>
                                  </div>
                                </div>
                              </div>
                            </div>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <br>
      <fieldset class="m_5311497744342249161mimeAttachmentHeader"></fieldset>
      <br>
      <pre>_______________________________________________
LLVM Developers mailing list
<a class="m_5311497744342249161moz-txt-link-abbreviated" href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>
<a class="m_5311497744342249161moz-txt-link-freetext" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a>
</pre>
    </blockquote>
    <br>
    <pre class="m_5311497744342249161moz-signature" cols="72">-- 
<a class="m_5311497744342249161moz-txt-link-freetext" href="https://weliveindetail.github.io/blog/" target="_blank">https://weliveindetail.github.io/blog/</a>
<a class="m_5311497744342249161moz-txt-link-freetext" href="https://cryptup.org/pub/stefan.graenitz@gmail.com" target="_blank">https://cryptup.org/pub/stefan.graenitz@gmail.com</a></pre>
  </div>

</blockquote></div>