[llvm-dev] LLVM FunctionType cannot be returned as VectorType?

Jia Yu via llvm-dev llvm-dev at lists.llvm.org
Thu Jul 19 17:02:48 PDT 2018


Dear all,

I am using LLVM C++ API to generate some code. In particular, I am dealing
with AVX2 SIMD API which uses __m256i.

My function input types a set of vectors and return type is also a vector.

///////////////////////////////////////////////////////////////////////////////////////////

arguments.push_back(VectorType::get(IntegerType::getIntNTy(TheContext, 64),
4));//int64*4 = __m256i
                FunctionType * proto =
FunctionType::get(VectorType::get(IntegerType::getIntNTy(TheContext, 64),
4),//int64*4 = __m256i
                                                         arguments, false);
///////////////////////////////////////////////////////////////////////////////////////////

I can successfully use this way to produce the IR of my function properly
like this:
///////////////////////////////////////////////////////////////////////////////////////////

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) {

entry:

  %addtmp = add <4 x i64> %leaf14, %leaf13

  %leaf8.neg = sub <4 x i64> zeroinitializer, %leaf8

  %xortmp = xor <4 x i64> %addtmp, %leaf11

  %addtmp1 = add <4 x i64> %leaf8.neg, %leaf7

  %subtmp = add <4 x i64> %addtmp1, %leaf9

  %addtmp2 = add <4 x i64> %subtmp, %leaf10

  %addtmp3 = add <4 x i64> %addtmp2, %xortmp

  ret <4 x i64> %addtmp3

}

///////////////////////////////////////////////////////////////////////////////////////////

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.

My code is as follows: It always tells me segment fault
///////////////////////////////////////////////////////////////////////////////////////////
// Define the input/output data type in LLVM function
 typedef std::vector<int64_t> VecInt;

auto function = reinterpret_cast<VecInt (*)(VecInt , VecInt, VecInt,
VecInt, VecInt, VecInt, VecInt,
VecInt)>(TheExecutionEngine->getFunctionAddress(TheFunction->getName().str()));
VecInt result =
function(functionCallArgs[0],functionCallArgs[1],functionCallArgs[2],functionCallArgs[3],

functionCallArgs[4],functionCallArgs[5],functionCallArgs[6],functionCallArgs[7]);

std::cout<<"result size "<< result.size()<<"\n";
///////////////////////////////////////////////////////////////////////////////////////////


Can someone tell me whether this is the correct way to retrieve the vector
return type? Or is the vector type return supported?

Thanks,
Jia Yu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180719/85365cd1/attachment.html>


More information about the llvm-dev mailing list