How to create a LLVM structure value?

I am trying to create an LLVM value of a structure type. I use the LLVM-C interface and find the function:

LLVMValueRef LLVMConstStruct (LLVMValueRef *ConstantVals, unsigned Count, LLVMBool Packed) 

This works fine if all members are a constant value created by LLVMConstXXX (), it generates code, for example:

 store { i32, i32, i32 } { i32 1, i32 2, i32 3 }, { i32, i32, i32 }* %17, align 4 

But the problem is that the member is not a 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 LLVM code snippet to NVVM (back-back-back-back-back-back file), it says:

module 0 (27, 39): parsing error: invalid use of the local-function name

So, I do not know if this construction of the structure value is correct. I need a value, not a dedicated memory.

Does anyone have an idea?

Regards, Xiang.

+6
source share
1 answer

A permanent structure is a kind of literal, which - loyal to its name - can contain only other constants, not general values. Thus, the correct way to create this structure is through insertvalue . In the above example, 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 
+10
source

All Articles