0
votes

I have a vector of integer values, vector<Value*> myIntegers in my LLVM code (not necessarily constant). I want to create a Store instruction to store these integers. To create the store instruction using the format below, for the first argument I need to create a Value* pointing to these integers (create an array out of them).

new StoreInst(Value *Val, Value *Ptr, ...);

If my integers were constants I would have used:

Constant *IntArrayConstant = ConstantDataArray::get(getGlobalContext(), ArrayRef<Value*> myIntegers);

How can I create a generic array of i32 types, with a Value* pointing to it? The documentation says storing ArrayRef is not safe either.

1

1 Answers

1
votes

You should probably use VectorType::get(), create an UndefValue of the type you just obtained, and then populate it with N InsertElementInsts, with N the number of elements. You will then create a StoreInst to store the Value* on the heap.

The result of the last InsertElementInst will thus be the Value* you are looking for (i.e. a vector containing the values). Please note that, depending on what you're trying to do, the StoreInst might actually be not needed at all.

Note that I'm assuming that all your Values have the same underlying type (i.e. getType() returns the same result for all of them).

Edit: also note that maybe, depending on what you're trying to do, it could be more appropriate to use ArrayType::get instead of VectorType::get.