From 4cd7e10ad3823711f3bfe4e06ae8cd23d8d6a462 Mon Sep 17 00:00:00 2001 From: Evghenii Date: Tue, 12 Nov 2013 12:51:56 +0100 Subject: [PATCH] reversed to original changes. Here is the plan to use CDP and genarate only device code with host wrapper.. --- builtins.cpp | 2 +- ctx.cpp | 2 +- decl.cpp | 6 +++--- func.cpp | 17 ++++++++++++++--- module.cpp | 6 +++--- type.cpp | 4 ++-- 6 files changed, 24 insertions(+), 13 deletions(-) diff --git a/builtins.cpp b/builtins.cpp index b1933929..2db215a4 100644 --- a/builtins.cpp +++ b/builtins.cpp @@ -860,7 +860,7 @@ DefineStdlib(SymbolTable *symbolTable, llvm::LLVMContext *ctx, llvm::Module *mod case Target::NVPTX64: { if (runtime32) { - fprintf(stderr, " please add 32-bit bulitins .. \n"); + fprintf(stderr, "W're sorry, but only 64bit targets are supported at this moment .. \n"); assert(0); } else { diff --git a/ctx.cpp b/ctx.cpp index ccbf2c3b..be2f55b0 100644 --- a/ctx.cpp +++ b/ctx.cpp @@ -3524,7 +3524,7 @@ FunctionEmitContext::LaunchInst(llvm::Value *callee, std::vector &argVals, llvm::Value *launchCount[3]){ - if (!g->target->isPTX()) + if (1) // if (!g->target->isPTX()) { if (callee == NULL) { AssertPos(currentPos, m->errorCount > 0); diff --git a/decl.cpp b/decl.cpp index f21e3c41..adb6f521 100644 --- a/decl.cpp +++ b/decl.cpp @@ -533,8 +533,8 @@ Declarator::InitFromType(const Type *baseType, DeclSpecs *ds) { bool isTask = ds && ((ds->typeQualifiers & TYPEQUAL_TASK) != 0); if (isTask && g->target->isPTX()) //getISA() == Target::NVPTX64) { - ds->storageClass = SC_EXTERN_C; - ds->typeQualifiers |= TYPEQUAL_UNMASKED; +// ds->storageClass = SC_EXTERN_C; +// ds->typeQualifiers |= TYPEQUAL_UNMASKED; } bool isExternC = ds && (ds->storageClass == SC_EXTERN_C); @@ -546,7 +546,7 @@ Declarator::InitFromType(const Type *baseType, DeclSpecs *ds) { "qualifiers"); return; } - if (!g->target->isPTX()) +// if (!g->target->isPTX()) if (isExternC && isTask) { Error(pos, "Function can't have both \"extern \"C\"\" and \"task\" " "qualifiers"); diff --git a/func.cpp b/func.cpp index ac201980..1424edfb 100644 --- a/func.cpp +++ b/func.cpp @@ -242,7 +242,7 @@ Function::emitCode(FunctionEmitContext *ctx, llvm::Function *function, // pointer to the structure that holds all of the arguments, the // thread index, and the thread count variables. - if (g->target->getISA() != Target::NVPTX64) + if (1) //if (g->target->getISA() != Target::NVPTX64) { llvm::Function::arg_iterator argIter = function->arg_begin(); llvm::Value *structParamPtr = argIter++; @@ -342,7 +342,16 @@ Function::emitCode(FunctionEmitContext *ctx, llvm::Function *function, ctx->SetFunctionMask(LLVMMaskAllOn); } else /* for NVPTX64 , function must be unmasked */ - assert(0); + { + //assert(0); + Assert(type->isUnmasked == false); + + // Otherwise use the mask to set the entry mask value + argIter->setName("__mask"); + Assert(argIter->getType() == LLVMTypes::MaskType); + ctx->SetFunctionMask(argIter); + Assert(++argIter == function->arg_end()); + } llvm::NamedMDNode* annotations = m->module->getOrInsertNamedMetadata("nvvm.annotations"); @@ -524,11 +533,13 @@ Function::GenerateIR() { // And we can now go ahead and emit the code /* export function with NVPTX64 target should be emitted host architecture */ +#if 0 const FunctionType *func_type= CastType(sym->type); if (g->target->getISA() == Target::NVPTX64 && func_type->isExported) return; if (g->target->getISA() != Target::NVPTX64 && g->target->isPTX() && func_type->isTask) return; +#endif // if (!(g->target->getISA()==Target::NVPTX64 && func_type->isExported)) { @@ -549,7 +560,7 @@ Function::GenerateIR() { // the application can call it const FunctionType *type = CastType(sym->type); Assert(type != NULL); - if (type->isExported && g->target->getISA() != Target::NVPTX64) { + if (type->isExported) { // && g->target->getISA() != Target::NVPTX64) { if (!type->isTask) { llvm::FunctionType *ftype = type->LLVMFunctionType(g->ctx, true); llvm::GlobalValue::LinkageTypes linkage = llvm::GlobalValue::ExternalLinkage; diff --git a/module.cpp b/module.cpp index 28fc8ae7..1f9db87c 100644 --- a/module.cpp +++ b/module.cpp @@ -733,7 +733,7 @@ Module::AddFunctionDeclaration(const std::string &name, if (storageClass == SC_EXTERN_C) { // Make sure the user hasn't supplied both an 'extern "C"' and a // 'task' qualifier with the function - if (functionType->isTask && !g->target->isPTX()) { //tISA() != Target::NVPTX64) { + if (functionType->isTask) { // && !g->target->isPTX()) { //tISA() != Target::NVPTX64) { Error(pos, "\"task\" qualifier is illegal with C-linkage extern " "function \"%s\". Ignoring this function.", name.c_str()); return; @@ -795,7 +795,7 @@ Module::AddFunctionDeclaration(const std::string &name, #else // LLVM 3.1 and 3.3+ function->addFnAttr(llvm::Attribute::AlwaysInline); #endif - if (functionType->isTask && g->target->getISA() != Target::NVPTX64) + if (functionType->isTask) // && g->target->getISA() != Target::NVPTX64) // This also applies transitively to members I think? #if defined(LLVM_3_1) function->setDoesNotAlias(1, true); @@ -2327,7 +2327,7 @@ Module::CompileAndOutput(const char *srcFile, g->PtxString = std::string(); - for (int itarget = 0; itarget < 2; itarget++) + for (int itarget = 0; itarget < 1; itarget++) { fprintf(stderr, "compiling nvptx64 : target= %s\n",targets[itarget].c_str()); g->target = new Target(arch, cpu, targets[itarget].c_str(), generatePIC, /* isPTX= */ true); diff --git a/type.cpp b/type.cpp index d0dc0bd3..d4c969f2 100644 --- a/type.cpp +++ b/type.cpp @@ -2925,7 +2925,7 @@ FunctionType::GetReturnTypeString() const { llvm::FunctionType * FunctionType::LLVMFunctionType(llvm::LLVMContext *ctx, bool removeMask) const { - if (isTask == true && !g->target->isPTX()) //getISA() != Target::NVPTX64) + if (isTask == true) // && !g->target->isPTX()) //getISA() != Target::NVPTX64) Assert(removeMask == false); // Get the LLVM Type *s for the function arguments @@ -2957,7 +2957,7 @@ FunctionType::LLVMFunctionType(llvm::LLVMContext *ctx, bool removeMask) const { // marshalled in a struct so that it's easy to allocate space to // hold them until the task actually runs.) // if (g->target->getISA() != Target::NVPTX64) - if (!g->target->isPTX()) + if (1) //if (!g->target->isPTX()) { llvm::Type *st = llvm::StructType::get(*ctx, llvmArgTypes); callTypes.push_back(llvm::PointerType::getUnqual(st));