I'm trying to create an LLVM value of a structure type. I'm using LLVM-C interface and find a function:
LLVMValueRef LLVMConstStruct (LLVMValueRef *ConstantVals, unsigned Count, LLVMBool Packed)
This works fine if all members are constant value created by LLVMConstXXX(), it will generate code like:
store { i32, i32, i32 } { i32 1, i32 2, i32 3 }, { i32, i32, i32 }* %17, align 4
But the problem is if the member is not constant, it will generate things like:
%0 = call i32 @llvm.nvvm.read.ptx.sreg.tid.x()
store { i32, i32, i32 } { i32 1, i32 %0, i32 3 }, { i32, i32, i32 }* %17, align 4
And when I send this piece of LLVM code to NVVM (Nvidia PTX backend), it says:
module 0 (27, 39): parse error: invalid use of function-local name
So, I don't know if this struct value creating is a correct. What I need is a value, not an allocated memory.
Anyone has idea?
Regards, Xiang.
A constant struct is a kind of literal that - loyal to its name - may only contain other constants, not general values. The correct way to generate that struct, then, is via insertvalue
. In your example above, it should look like this:
%0 = call i32 @llvm.nvvm.read.ptx.sreg.tid.x()
%1 = insertvalue {i32, i32, i32} {i32 1, i32 undef, i32 3}, i32 %0, 1
store { i32, i32, i32 } %1, { i32, i32, i32 }* %17, align 4