Reputation: 627
I want to build up LLVM IR for the following expression to add a scalar to a vector
[1,2,3,4]+1
I have found the correct methods to create the add and the scalar expression but not for the vector.
Value *L = //Missing code here
Value *R = ConstantFP::get(getGlobalContext(), APFloat(Val));
Value *exp = Builder.CreateFAdd(L, R, "addresult");
How can I generate this vector?
Upvotes: 0
Views: 2165
Reputation: 43662
First make sure you actually need a vector i.e. a datatype on which you can operate in parallel (SIMD/SIMT fashion) and not a simple array.
After that make also sure the type you intend to use is right (APFloat is arbitrary precision float).
Creating a vector can proceed in the same way you add elements via insertelement
Type* u32Ty = Type::getInt32Ty( llvmContext );
Type* vecTy = VectorType::get(u32Ty, 4);
Value* emptyVec = UndefValue::get(vecTy);
Constant* index0 = Constant::getIntegerValue(u32Ty, llvm::APInt(32, 0));
Value* insert1 = InsertElementInst(/*First integer value*/, emptyVec, index0, 0);
Upvotes: 1