From e7ddb9e642b3ca83e59e2b206f85e5a99dd97a2b Mon Sep 17 00:00:00 2001 From: Evghenii Date: Wed, 30 Oct 2013 22:41:01 +0100 Subject: [PATCH] now adds function&module name. next step adding pointer to parameter list --- ctx.cpp | 65 ++++++++++++++++++++++++++++++++++++++++++++++++-------- func.cpp | 16 ++++++++------ 2 files changed, 65 insertions(+), 16 deletions(-) diff --git a/ctx.cpp b/ctx.cpp index 513c8f06..53c74870 100644 --- a/ctx.cpp +++ b/ctx.cpp @@ -3592,6 +3592,8 @@ FunctionEmitContext::LaunchInst(llvm::Value *callee, } else /* isPTX == true */ { + assert(g->target->getISA() != Target::NVPTX64); + if (callee == NULL) { AssertPos(currentPos, m->errorCount > 0); return NULL; @@ -3647,22 +3649,67 @@ FunctionEmitContext::LaunchInst(llvm::Value *callee, // And emit the call to the user-supplied task launch function, passing // a pointer to the task function being called and a pointer to the // argument block we just filled in + + + + // llvm::Value *fptr = BitCastInst(callee, LLVMTypes::VoidPointerType); llvm::Function *flaunch = m->module->getFunction("CUDALaunch"); AssertPos(currentPos, flaunch != NULL); std::vector args; args.push_back(launchGroupHandlePtr); /* void **handler */ - args.push_back(voidmem); /* const char * module_name */ + { + const std::string moduleNameStr("module_xyz"); + llvm::ArrayType* ArrayTyModuleName = llvm::ArrayType::get(llvm::IntegerType::get(*g->ctx, 8), moduleNameStr.size()+1); + + llvm::GlobalVariable* gvarModuleNameStr = new llvm::GlobalVariable( + /*Module=*/ *m->module, + /*Type=*/ ArrayTyModuleName, + /*isConstant=*/ true, + /*Linkage=*/ llvm::GlobalValue::PrivateLinkage, + /*Initializer=*/ 0, // has initializer, specified below + /*Name=*/ ".str"); + gvarModuleNameStr->setAlignment(1); + + llvm::Constant *constModuleName= llvm::ConstantDataArray::getString(*g->ctx, moduleNameStr.c_str(), true); + gvarModuleNameStr->setInitializer(constModuleName); + + std::vector const_ptr_12_indices; + const_ptr_12_indices.push_back(llvm::Constant::getNullValue(llvm::Type::getInt32Ty(*g->ctx))); + const_ptr_12_indices.push_back(llvm::ConstantInt::get(llvm::Type::getInt32Ty(*g->ctx),0)); + llvm::Constant* const_ptr_12 = llvm::ConstantExpr::getGetElementPtr(gvarModuleNameStr, const_ptr_12_indices); + args.push_back(const_ptr_12); /* const char * module_name */ + } + args.push_back(voidmem); /* const char * module */ -#if 0 - llvm::Value *fname = llvm::MDString::get(*g->ctx, - callee->getName().str().c_str()); - llvm::Value *fnameptr = BitCastInst(fname, LLVMTypes::VoidPointerType); - args.push_back(fnameptr); /* const char * func_name */ -#else - args.push_back(voidmem); /* const char * func_name */ -#endif + + { + const std::string funcNameStr = callee->getName().str(); + llvm::ArrayType* ArrayTyFuncName = llvm::ArrayType::get(llvm::IntegerType::get(*g->ctx, 8), funcNameStr.size()+1); + + llvm::GlobalVariable* gvarFuncNameStr = new llvm::GlobalVariable( + /*Module=*/ *m->module, + /*Type=*/ ArrayTyFuncName, + /*isConstant=*/ true, + /*Linkage=*/ llvm::GlobalValue::PrivateLinkage, + /*Initializer=*/ 0, // has initializer, specified below + /*Name=*/ ".str"); + gvarFuncNameStr->setAlignment(1); + + llvm::Constant *constFuncName= llvm::ConstantDataArray::getString(*g->ctx, funcNameStr.c_str(), true); + gvarFuncNameStr->setInitializer(constFuncName); + + std::vector const_ptr_12_indices; + const_ptr_12_indices.push_back(llvm::Constant::getNullValue(llvm::Type::getInt32Ty(*g->ctx))); + const_ptr_12_indices.push_back(llvm::ConstantInt::get(llvm::Type::getInt32Ty(*g->ctx),0)); + llvm::Constant* const_ptr_12 = llvm::ConstantExpr::getGetElementPtr(gvarFuncNameStr, const_ptr_12_indices); + args.push_back(const_ptr_12); /* const char * func_name */ + } + args.push_back(launchGroupHandlePtr); /* const void ** args */ + //args.push_back( (llvm::dyn_cast(callee))->arg_begin() ); + //llvm::PointerType *pt = + // llvm::dyn_cast(argType); args.push_back(launchCount[0]); args.push_back(launchCount[1]); args.push_back(launchCount[2]); diff --git a/func.cpp b/func.cpp index f930ce10..7531c5eb 100644 --- a/func.cpp +++ b/func.cpp @@ -523,19 +523,21 @@ Function::GenerateIR() { } // And we can now go ahead and emit the code - { /* export function with NVPTX64 target should be emitted host architecture */ - const FunctionType *type= CastType(sym->type); - if (g->target->getISA() == Target::NVPTX64 && type->isExported) - return; - if (g->target->getISA() != Target::NVPTX64 && g->target->isPTX() && !type->isExported) - return; - } + /* export function with NVPTX64 target should be emitted host architecture */ + 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->isExported) + return; + + if (!(g->target->getISA() && func_type->isExported)) { FunctionEmitContext ec(this, sym, function, firstStmtPos); emitCode(&ec, function, firstStmtPos); } if (m->errorCount == 0) { + if (!(g->target->getISA() && func_type->isExported)) if (llvm::verifyFunction(*function, llvm::ReturnStatusAction) == true) { if (g->debugPrint) function->dump();