Hi all,
Running LLVM 3.4 to create a custom pass for OpenCL transformations. I am attempting to GEP into a struct using IRBuilder's CreateStructGEP, but I keep getting this assert:
aoc: ../../../../../../compiler/llvm/include/llvm/Instructions.h:703: llvm::Type* llvm::checkGEPType(llvm::Type*): Assertion `Ty && "Invalid GetElementPtrInst indices for type!"' failed.
Which I've decoded as it doesn't recognize my struct as a built in type. This is confusing since it shouldn't care what type I'm indexing into, only that I give the correct indices. Otherwise what is the point of user defined structs?
//This part is atop my cl kernel file:
#define BUFFER_LEN 0x100000
typedef struct RB{
unsigned int x;
unsigned int y;
int z[BUFFER_LEN];
unsigned int xx[BUFFER_LEN];
unsigned int yy[BUFFER_LEN];
float zz[BUFFER_LEN];
} RB_t;
//The kernel sig. with the struct as the last argument:
__kernel void ht( int iteration, global RB_t *cB){ ... }
//My LLVM code:
void MPASS::exPointers(Module& M, Function& F){
BasicBlock *first = F.begin();
IRBuilder<> builder(first->begin());
Value *cB = --(F.arg_end());
Value *x_idx = builder.CreateStructGEP(cB, 0);
...
... < more of the same>
...
return
}
Simple enough, but I can't get past the first CreateStructGEP without the assert. I thought it was a version issue, so I changed the call to:
Value *x_idx = builder.CreateConstGEP2_32(cB, 0, 0);
However I got the same assert. It looks like this line in Instruction.h from LLVM is producing the assert further down the stack:
815 Type *PtrTy = PointerType::get(checkGEPType(
816 getIndexedType(Ptr->getType(), IdxList)),
817 Ptr->getType()->getPointerAddressSpace());
Resulting in the debugger producing:
(gdb) p PtrTy
$19 = (llvm::Type *) 0x7fffffff63d0
(gdb) p PtrTy->dump()
<unrecognized-type> $20 = void
Is there something special which needs to be done in order to index into a user defined struct in LLVM for OpenCL?