added conversion from addrspace(3)/__local/__shared__ to addspace(0)/generic when PtrToInt is called

This commit is contained in:
Evghenii
2014-01-07 14:29:55 +01:00
parent 96597d3716
commit 9b74e60185
6 changed files with 44 additions and 6 deletions

View File

@@ -629,7 +629,8 @@ lSetInternalFunctions(llvm::Module *module) {
"__nctaid_x", "__nctaid_x",
"__nctaid_y", "__nctaid_y",
"__nctaid_z", "__nctaid_z",
"__warpsize" "__warpsize",
"__cvt_loc2gen"
}; };
int count = sizeof(names) / sizeof(names[0]); int count = sizeof(names) / sizeof(names[0]);

View File

@@ -61,6 +61,14 @@ define i32 @__nctaid_z() nounwind readnone alwaysinline
%nb = call i32 @llvm.nvvm.read.ptx.sreg.nctaid.z() %nb = call i32 @llvm.nvvm.read.ptx.sreg.nctaid.z()
ret i32 %nb ret i32 %nb
} }
;;;;;;;;
declare i64* @llvm.nvvm.ptr.shared.to.gen.p0i64.p3i64(i64 addrspace(3)*)
define i64* @__cvt_loc2gen(i64 addrspace(3)*) nounwind readnone alwaysinline
{
%ptr = tail call i64* @llvm.nvvm.ptr.shared.to.gen.p0i64.p3i64(i64 addrspace(3)* %0)
ret i64* %ptr
}
;;;;;;;;
define i32 @__shfl_i32_nvptx(i32, i32) nounwind readnone alwaysinline define i32 @__shfl_i32_nvptx(i32, i32) nounwind readnone alwaysinline
{ {
%shfl = tail call i32 asm sideeffect "shfl.idx.b32 $0, $1, $2, 0x1f;", "=r,r,r"(i32 %0, i32 %1) nounwind readnone alwaysinline %shfl = tail call i32 asm sideeffect "shfl.idx.b32 $0, $1, $2, 0x1f;", "=r,r,r"(i32 %0, i32 %1) nounwind readnone alwaysinline

View File

@@ -4542,5 +4542,6 @@ declare i32 @__ctaid_z() nounwind readnone alwaysinline
declare i32 @__nctaid_x() nounwind readnone alwaysinline declare i32 @__nctaid_x() nounwind readnone alwaysinline
declare i32 @__nctaid_y() nounwind readnone alwaysinline declare i32 @__nctaid_y() nounwind readnone alwaysinline
declare i32 @__nctaid_z() nounwind readnone alwaysinline declare i32 @__nctaid_z() nounwind readnone alwaysinline
declare i64* @__cvt_loc2gen(i64 addrspace(3)*) nounwind readnone alwaysinline
') ')

28
ctx.cpp
View File

@@ -1846,6 +1846,21 @@ FunctionEmitContext::PtrToIntInst(llvm::Value *value, const char *name) {
if (name == NULL) if (name == NULL)
name = LLVMGetName(value, "_ptr2int"); name = LLVMGetName(value, "_ptr2int");
if (value->getType()->isPointerTy() && g->target->getISA() == Target::NVPTX)
{
llvm::PointerType *pt = llvm::dyn_cast<llvm::PointerType>(value->getType());
if (pt->getAddressSpace() == 3)
{
llvm::PointerType *PointerTy3 = llvm::PointerType::get(LLVMTypes::Int64Type, 3);
llvm::Value *cast = BitCastInst(value, PointerTy3, "__cvt_log2gen_i64ptr1_");
llvm::Function *__cvt_loc2gen = m->module->getFunction("__cvt_loc2gen");
std::vector<llvm::Value *> __cvt_loc2gen_args;
__cvt_loc2gen_args.push_back(cast);
value = CallInst(__cvt_loc2gen, NULL, __cvt_loc2gen_args, "__cvt_loc2gen1_");
}
}
llvm::Type *type = LLVMTypes::PointerIntType; llvm::Type *type = LLVMTypes::PointerIntType;
llvm::Instruction *inst = new llvm::PtrToIntInst(value, type, name, bblock); llvm::Instruction *inst = new llvm::PtrToIntInst(value, type, name, bblock);
AddDebugPos(inst); AddDebugPos(inst);
@@ -1879,6 +1894,19 @@ FunctionEmitContext::PtrToIntInst(llvm::Value *value, llvm::Type *toType,
} }
} }
if (value->getType()->isPointerTy() && g->target->getISA() == Target::NVPTX)
{
llvm::PointerType *pt = llvm::dyn_cast<llvm::PointerType>(value->getType());
if (pt->getAddressSpace() == 3)
{
llvm::PointerType *PointerTy3 = llvm::PointerType::get(LLVMTypes::Int64Type, 3);
llvm::Value *cast = BitCastInst(value, PointerTy3, "__cvt_log2gen_i64ptr2_");
llvm::Function *__cvt_loc2gen = m->module->getFunction("__cvt_loc2gen");
std::vector<llvm::Value *> __cvt_loc2gen_args;
__cvt_loc2gen_args.push_back(cast);
value = CallInst(__cvt_loc2gen, NULL, __cvt_loc2gen_args, "__cvt_loc2gen2_");
}
}
llvm::Instruction *inst = new llvm::PtrToIntInst(value, toType, name, bblock); llvm::Instruction *inst = new llvm::PtrToIntInst(value, toType, name, bblock);
AddDebugPos(inst); AddDebugPos(inst);
return inst; return inst;

View File

@@ -5,8 +5,8 @@ DIS=$HOME/usr/local/llvm/bin-3.2/bin/llvm-dis
ISPC=ispc ISPC=ispc
PTXCC=ptxcc PTXCC=ptxcc
PTXGEN=~/ptxgen PTXGEN=~/ptxgen
#$(cat $1 |grep -v 'width'|$ISPC --target=nvptx --emit-llvm -o -|$LLC -march=nvptx64 -mcpu=sm_35 -o $1.ptx) && \ $(cat $1 |grep -v 'width'|$ISPC --target=nvptx --emit-llvm -o -|$LLC -march=nvptx64 -mcpu=sm_35 -o $1.ptx) && \
$(cat $1 |grep -v 'width'|$ISPC --target=nvptx --emit-llvm -o -|$DIS -o $1_32_ptx.ll && $PTXGEN $1_32_ptx.ll > $1.ptx) && \ #$(cat $1 |grep -v 'width'|$ISPC --target=nvptx --emit-llvm -o -|$DIS -o $1_32_ptx.ll && $PTXGEN $1_32_ptx.ll > $1.ptx) && \
$($PTXCC $1.ptx -Xptxas=-v -o $1.ptx.o) && \ $($PTXCC $1.ptx -Xptxas=-v -o $1.ptx.o) && \
nvcc -o test_nvptx test_static_nvptx.cpp examples_ptx/nvcc_helpers.cu examples_ptx/ispc_malloc.cpp $1.ptx.o -arch=sm_35 -Iexamples_ptx/ -D_CUDA_ -lcudadevrt -DTEST_SIG=$2 nvcc -o test_nvptx test_static_nvptx.cpp examples_ptx/nvcc_helpers.cu examples_ptx/ispc_malloc.cpp $1.ptx.o -arch=sm_35 -Iexamples_ptx/ -D_CUDA_ -lcudadevrt -DTEST_SIG=$2

View File

@@ -257,11 +257,10 @@ DeclStmt::EmitCode(FunctionEmitContext *ctx) const {
ctx->EmitVariableDebugInfo(sym); ctx->EmitVariableDebugInfo(sym);
} }
else { else {
#if 0 /* PTX:: shared/uniform data types are here */
if (sym->type->IsArrayType() && sym->type->IsUniformType() if (sym->type->IsArrayType() && sym->type->IsUniformType()
&& g->target->getISA() == Target::NVPTX) && g->target->getISA() == Target::NVPTX)
{ {
#if 0 #if 0 /* need to test if initializer works ... */
if (initExpr != NULL) if (initExpr != NULL)
Error(initExpr->pos, "Initializer for static variable " Error(initExpr->pos, "Initializer for static variable "
"\"%s\" must be a constant.", sym->name.c_str()); "\"%s\" must be a constant.", sym->name.c_str());
@@ -304,13 +303,14 @@ DeclStmt::EmitCode(FunctionEmitContext *ctx) const {
NULL, NULL,
llvm::GlobalVariable::NotThreadLocal, llvm::GlobalVariable::NotThreadLocal,
/*AddressSpace=*/ 3); /*AddressSpace=*/ 3);
#if 0
llvm::GlobalVariable *var = llvm::dyn_cast<llvm::GlobalVariable>(sym->storagePtr); llvm::GlobalVariable *var = llvm::dyn_cast<llvm::GlobalVariable>(sym->storagePtr);
var->setAlignment(128); var->setAlignment(128);
#endif
// Tell the FunctionEmitContext about the variable // Tell the FunctionEmitContext about the variable
ctx->EmitVariableDebugInfo(sym); ctx->EmitVariableDebugInfo(sym);
} }
else else
#endif
{ {
// For non-static variables, allocate storage on the stack // For non-static variables, allocate storage on the stack
sym->storagePtr = ctx->AllocaInst(llvmType, sym->name.c_str()); sym->storagePtr = ctx->AllocaInst(llvmType, sym->name.c_str());