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

Stefan Gränitz via llvm-dev llvm-dev at lists.llvm.org
Sun Jul 22 08:51:42 PDT 2018


Hi Jia

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].

However, it would be easier with something like this:

using VecInt = int64[4];
VecInt args0 { 0, 1, 2, 3 };
...
VecInt result = function(args0, ...);

Btw.: Note that you may need to set target-feature attributes for your
function like so: [3]

Hope it helps.

Cheers,
Stefan

[1] https://llvm.org/docs/LangRef.html#vector-type
[2] https://en.cppreference.com/w/cpp/container/vector
[3] https://en.cppreference.com/w/cpp/container/vector/data
[4]
https://github.com/weliveindetail/DecisionTreeCompiler/blob/master/compiler/DecisionTreeCompiler.cpp#L83

Am 20.07.18 um 02:02 schrieb Jia Yu via llvm-dev:
> 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
>
>
>
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

-- 
https://weliveindetail.github.io/blog/
https://cryptup.org/pub/stefan.graenitz@gmail.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180722/18a00737/attachment-0001.html>


More information about the llvm-dev mailing list