added addrspace(3,4)->addrspace(0) convertion to ctx->GetElementPtrInst. Appears to work now.

This commit is contained in:
Evghenii
2014-01-08 19:31:28 +01:00
parent cc53fa4c14
commit 5f859e4885
4 changed files with 19 additions and 12 deletions

11
ctx.cpp
View File

@@ -1854,7 +1854,7 @@ static llvm::Value* lConvertGepToGenericPtr(FunctionEmitContext *ctx, llvm::Valu
return value; return value;
llvm::PointerType *pt = llvm::dyn_cast<llvm::PointerType>(value->getType()); llvm::PointerType *pt = llvm::dyn_cast<llvm::PointerType>(value->getType());
const int addressSpace = pt->getAddressSpace(); const int addressSpace = pt->getAddressSpace();
if (addressSpace != 3) // && addressSpace != 4) if (addressSpace != 3 && addressSpace != 4)
return value; return value;
llvm::Type *elTy = pt->getElementType(); llvm::Type *elTy = pt->getElementType();
@@ -1867,8 +1867,10 @@ static llvm::Value* lConvertGepToGenericPtr(FunctionEmitContext *ctx, llvm::Valu
llvm::ArrayType *arrTy = llvm::dyn_cast<llvm::ArrayType>(pt->getArrayElementType()); llvm::ArrayType *arrTy = llvm::dyn_cast<llvm::ArrayType>(pt->getArrayElementType());
assert(arrTy != NULL); assert(arrTy != NULL);
llvm::Type *arrElTy = arrTy->getElementType(); llvm::Type *arrElTy = arrTy->getElementType();
#if 0
if (arrElTy->isArrayTy()) if (arrElTy->isArrayTy())
Error(currentPos, "Currently \"nvptx\" target doesn't support array-of-array"); Error(currentPos, "Currently \"nvptx\" target doesn't support array-of-array");
#endif
/* convert elTy addrspace(3)* to i64* addrspace(3)* */ /* convert elTy addrspace(3)* to i64* addrspace(3)* */
llvm::PointerType *Int64Ptr3 = llvm::PointerType::get(LLVMTypes::Int64Type, addressSpace); llvm::PointerType *Int64Ptr3 = llvm::PointerType::get(LLVMTypes::Int64Type, addressSpace);
@@ -1886,6 +1888,8 @@ static llvm::Value* lConvertGepToGenericPtr(FunctionEmitContext *ctx, llvm::Valu
value = ctx->BitCastInst(value, arrElTyPt0, "gep2gen_cast2"); value = ctx->BitCastInst(value, arrElTyPt0, "gep2gen_cast2");
/* compute offset */ /* compute offset */
if (addressSpace == 3)
{
llvm::Function *funcTid = m->module->getFunction("__tid_x"); llvm::Function *funcTid = m->module->getFunction("__tid_x");
llvm::Function *funcWarpSz = m->module->getFunction("__warpsize"); llvm::Function *funcWarpSz = m->module->getFunction("__warpsize");
llvm::Value *tid = ctx->CallInst(funcTid, NULL, std::vector<llvm::Value*>(), "gep2gen_tid"); llvm::Value *tid = ctx->CallInst(funcTid, NULL, std::vector<llvm::Value*>(), "gep2gen_tid");
@@ -1893,6 +1897,7 @@ static llvm::Value* lConvertGepToGenericPtr(FunctionEmitContext *ctx, llvm::Valu
llvm::Value *warpId = ctx->BinaryOperator(llvm::Instruction::SDiv, tid, warpSz, "gep2gen_warpId"); llvm::Value *warpId = ctx->BinaryOperator(llvm::Instruction::SDiv, tid, warpSz, "gep2gen_warpId");
llvm::Value *offset = ctx->BinaryOperator(llvm::Instruction::Mul, warpId, LLVMInt32(numEl), "gep2gen_offset"); llvm::Value *offset = ctx->BinaryOperator(llvm::Instruction::Mul, warpId, LLVMInt32(numEl), "gep2gen_offset");
value = llvm::GetElementPtrInst::Create(value, offset, "gep2gen_offset", ctx->GetCurrentBasicBlock()); value = llvm::GetElementPtrInst::Create(value, offset, "gep2gen_offset", ctx->GetCurrentBasicBlock());
}
/* convert arrElTy* to elTy* */ /* convert arrElTy* to elTy* */
llvm::PointerType *elTyPt0 = llvm::PointerType::get(elTy, 0); llvm::PointerType *elTyPt0 = llvm::PointerType::get(elTy, 0);
@@ -3461,19 +3466,21 @@ lCalleeArgCount(llvm::Value *callee, const FunctionType *funcType) {
llvm::Value * llvm::Value *
FunctionEmitContext::CallInst(llvm::Value *func, const FunctionType *funcType, FunctionEmitContext::CallInst(llvm::Value *func, const FunctionType *funcType,
const std::vector<llvm::Value *> &args_in, const std::vector<llvm::Value *> &args,
const char *name) { const char *name) {
if (func == NULL) { if (func == NULL) {
AssertPos(currentPos, m->errorCount > 0); AssertPos(currentPos, m->errorCount > 0);
return NULL; return NULL;
} }
#if 0
std::vector<llvm::Value *> args = args_in; std::vector<llvm::Value *> args = args_in;
/* NVPTX: /* NVPTX:
* Convert all pointers to addrspace(0) * Convert all pointers to addrspace(0)
*/ */
for (unsigned int i = 0; i < args.size(); i++) for (unsigned int i = 0; i < args.size(); i++)
args[i] = lConvertToGenericPtr(this, args[i], currentPos); args[i] = lConvertToGenericPtr(this, args[i], currentPos);
#endif
std::vector<llvm::Value *> argVals = args; std::vector<llvm::Value *> argVals = args;
// Most of the time, the mask is passed as the last argument. this // Most of the time, the mask is passed as the last argument. this
// isn't the case for things like intrinsics, builtins, and extern "C" // isn't the case for things like intrinsics, builtins, and extern "C"

View File

@@ -506,7 +506,7 @@ RenderTile(uniform int num_groups_x, uniform int num_groups_y,
uniform float cameraProj_32 = inputHeader.cameraProj[3][2]; uniform float cameraProj_32 = inputHeader.cameraProj[3][2];
// Light intersection: figure out which lights illuminate this tile. // Light intersection: figure out which lights illuminate this tile.
#if 1 //def __NVPTX__ #if 1
uniform int * uniform tileLightIndices = uniform new uniform int [MAX_LIGHTS]; uniform int * uniform tileLightIndices = uniform new uniform int [MAX_LIGHTS];
#define MALLOC #define MALLOC
#else /* shared memory doesn't full work... why? */ #else /* shared memory doesn't full work... why? */

View File

@@ -328,7 +328,7 @@ volume_task(uniform float density[], uniform int _nVoxels[3],
{ {
if (taskIndex >= taskCount) return; if (taskIndex >= taskCount) return;
#if 0 /* cannot pass shared memory pointers to functions, need to find a way to solve this one :S */ #if 1 /* cannot pass shared memory pointers to functions, need to find a way to solve this one :S */
uniform int nVoxels[3]; uniform int nVoxels[3];
nVoxels[0] = _nVoxels[0]; nVoxels[0] = _nVoxels[0];
nVoxels[1] = _nVoxels[1]; nVoxels[1] = _nVoxels[1];

View File

@@ -278,7 +278,7 @@ DeclStmt::EmitCode(FunctionEmitContext *ctx) const {
int addressSpace; int addressSpace;
if (sym->type->IsConstType()) if (sym->type->IsConstType())
{ {
#if 0 /* current, addressSpace = 4 generates a compilation fails as it can't be passed as a function arg:S */ #if 1
addressSpace = 4; /* constant */ addressSpace = 4; /* constant */
#else #else
addressSpace = 0; /* use global for now */ addressSpace = 0; /* use global for now */