From 55bf0d23c2dd2f98d200b32a16105d6263fd3543 Mon Sep 17 00:00:00 2001 From: Evghenii Date: Wed, 13 Nov 2013 11:08:58 +0100 Subject: [PATCH] resotred non-ptx functionality --- ctx.cpp | 205 +------------------------------------------------------ func.cpp | 1 - type.cpp | 1 - 3 files changed, 1 insertion(+), 206 deletions(-) diff --git a/ctx.cpp b/ctx.cpp index 15b4743a..f33044f8 100644 --- a/ctx.cpp +++ b/ctx.cpp @@ -3526,7 +3526,6 @@ FunctionEmitContext::LaunchInst(llvm::Value *callee, if (!g->target->isPTX()) { - assert(0); /* evghenii: must be removed after testing is done */ if (callee == NULL) { AssertPos(currentPos, m->errorCount > 0); return NULL; @@ -3593,7 +3592,7 @@ FunctionEmitContext::LaunchInst(llvm::Value *callee, args.push_back(launchCount[2]); return CallInst(flaunch, NULL, args, ""); } - else if(1) /* isPTX == true */ + else /* isPTX == true */ { if (callee == NULL) { AssertPos(currentPos, m->errorCount > 0); @@ -3668,208 +3667,6 @@ FunctionEmitContext::LaunchInst(llvm::Value *callee, args.push_back(launchCount[1]); args.push_back(launchCount[2]); return CallInst(flaunch, NULL, args, ""); - - - } - else - { - assert(0); /* must only be called in export */ - // assert(g->target->getISA() != Target::NVPTX64); - - if (callee == NULL) { - AssertPos(currentPos, m->errorCount > 0); - return NULL; - } - - launchedTasks = true; - - AssertPos(currentPos, llvm::isa(callee)); -#if 0 - llvm::Type *argType = - (llvm::dyn_cast(callee))->arg_begin()->getType(); - AssertPos(currentPos, llvm::PointerType::classof(argType)); - llvm::PointerType *pt = - llvm::dyn_cast(argType); - AssertPos(currentPos, llvm::StructType::classof(pt->getElementType())); - llvm::StructType *argStructType = - static_cast(pt->getElementType()); -#endif - - llvm::Function *falloc = m->module->getFunction("ISPCAlloc"); - AssertPos(currentPos, falloc != NULL); -#if 0 - llvm::Value *structSize = g->target->SizeOf(argStructType, bblock); - if (structSize->getType() != LLVMTypes::Int64Type) - // ISPCAlloc expects the size as an uint64_t, but on 32-bit - // targets, SizeOf returns a 32-bit value - structSize = ZExtInst(structSize, LLVMTypes::Int64Type, - "struct_size_to_64"); -#else - /* CUDALaunch takes array of argVals.size() of pointer to parameters */ - /* code assumes sizeof(void*) pointer size */ - llvm::Value *structSize = llvm::ConstantInt::get(*g->ctx, llvm::APInt(64, sizeof(void*)*argVals.size())); -#endif - int align = 4 * RoundUpPow2(g->target->getNativeVectorWidth()); - - std::vector allocArgs; - allocArgs.push_back(launchGroupHandlePtr); - allocArgs.push_back(structSize); - allocArgs.push_back(LLVMInt32(align)); - CallInst(falloc, NULL, allocArgs, "args_ptr"); - - // Copy the values of the parameters into the appropriate place in - // the argument block - - /* allocate structure of pointer */ - llvm::ArrayType* ArrayTy_6 = llvm::ArrayType::get(LLVMTypes::VoidPointerType, argVals.size()*2); - llvm::Value* ptrParam = AllocaInst(ArrayTy_6, "arrayStructPtr"); - - /* constructed array of pointers to arguments - * this, and other parts are reverse enginered via - * cpp(clang++ -S -emit-llvm)->IR and then IR(llc -march=cpp)->cpp - */ - llvm::Function *func = llvm::dyn_cast(callee); - llvm::Function::arg_iterator argIter =func->arg_begin(); - llvm::Function::arg_iterator argIterEnd =func->arg_end(); - int i = 0; - for (; argIter != argIterEnd; argIter++, i++) - { - llvm::Type* type = argIter->getType(); //argStructType->getElementType(i); - llvm::Value* ptr_arg1_addr = AllocaInst(type, "argptr"); - StoreInst(argVals[i], ptr_arg1_addr); - - llvm::ConstantInt* const_int64_10 = llvm::ConstantInt::get(*g->ctx, llvm::APInt(64, 0)); - llvm::ConstantInt* const_int64_11 = llvm::ConstantInt::get(*g->ctx, llvm::APInt(64, i)); - std::vector ptr_arrayinit_begin_indices; - ptr_arrayinit_begin_indices.push_back(const_int64_10); - ptr_arrayinit_begin_indices.push_back(const_int64_11); - llvm::GetElementPtrInst* ptr_arrayinit_element = - llvm::GetElementPtrInst::Create(ptrParam, ptr_arrayinit_begin_indices, "el", bblock); - llvm::Value* ptr_15 = BitCastInst(ptr_arg1_addr, LLVMTypes::VoidPointerType, "voidptr"); -#if 0 - { - std::string str; llvm::raw_string_ostream rso(str); llvm::formatted_raw_ostream fos(rso); - ptr_arg1_addr->print(fos); - const_int64_11->print(fos); - ptr_arrayinit_element->print(fos); - ptr_15->print(fos); - fos.flush(); fprintf(stderr, ">>> %s\n", str.c_str()); - } -#endif - StoreInst(ptr_15, ptr_arrayinit_element); - } - -#if 0 /* evghenii:: must work uncommented */ - if (argStructType->getNumElements() == argVals.size() + 1) - assert(0); /* must not happen as task function is unmasked for PTX target */ -#endif - - // 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::Function *flaunch = m->module->getFunction("ISPCLaunch"); - AssertPos(currentPos, flaunch != NULL); - std::vector args; - - args.push_back(launchGroupHandlePtr); /* void **handler */ - -#if 0 - /* module name string to distinguish between different modules , generated ones */ - { - const std::string moduleNameStr = m->module->getModuleIdentifier(); - static llvm::ArrayType* ArrayTyModuleName = llvm::ArrayType::get(llvm::IntegerType::get(*g->ctx, 8), moduleNameStr.size()+1); - - static llvm::GlobalVariable* gvarModuleNameStr = new llvm::GlobalVariable( - /*Module=*/ *m->module, - /*Type=*/ ArrayTyModuleName, - /*isConstant=*/ true, - /*Linkage=*/ llvm::GlobalValue::PrivateLinkage, - /*Initializer=*/ 0, // has initializer, specified below - /*Name=*/ ".module_str"); - //gvarModuleNameStr->setAlignment(1); - - static 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)); - static llvm::Constant* const_ptr_12 = llvm::ConstantExpr::getGetElementPtr(gvarModuleNameStr, const_ptr_12_indices); - args.push_back(const_ptr_12); /* const char * module_name */ - } - - /* ptx string, quick hack with "static" to create only single string.. the must be a better way */ - { - const std::string moduleNameStr = g->PtxString; - static llvm::ArrayType* ArrayTyModuleName = llvm::ArrayType::get(llvm::IntegerType::get(*g->ctx, 8), moduleNameStr.size()+1); - - static llvm::GlobalVariable* gvarModuleNameStr = new llvm::GlobalVariable( - /*Module=*/ *m->module, - /*Type=*/ ArrayTyModuleName, - /*isConstant=*/ true, - /*Linkage=*/ llvm::GlobalValue::PrivateLinkage, - /*Initializer=*/ 0, // has initializer, specified below - /*Name=*/ ".ptx_str"); - - static 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)); - static llvm::Constant* const_ptr_12 = llvm::ConstantExpr::getGetElementPtr(gvarModuleNameStr, const_ptr_12_indices); - args.push_back(const_ptr_12); /* const char * module_name */ - } -#endif - -#if 0 - /* fucntion name string */ - { - 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=*/ ".func_str"); - - 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 */ - } -#else - { - llvm::Value *fptr = BitCastInst(callee, LLVMTypes::VoidPointerType); - args.push_back(fptr); - } -#endif - - /* pass array of pointers to function arguments, this is how cuLaunchKernel accepts arguments */ - { - std::vector ptr_arraydecay_indices; - llvm::ConstantInt* const_int32_14 = llvm::ConstantInt::get(*g->ctx, llvm::APInt(32, 0)); - ptr_arraydecay_indices.push_back(const_int32_14); - ptr_arraydecay_indices.push_back(const_int32_14); - llvm::Instruction* ptr_arraydecay = llvm::GetElementPtrInst::Create(ptrParam, ptr_arraydecay_indices, "arraydecay", bblock); - args.push_back(ptr_arraydecay); /* const void ** params */ - } - - llvm::ConstantInt* const_int64_10 = llvm::ConstantInt::get(*g->ctx, llvm::APInt(32, argVals.size()*2)); - args.push_back(const_int64_10); - args.push_back(launchCount[0]); - args.push_back(launchCount[1]); - args.push_back(launchCount[2]); - return CallInst(flaunch, NULL, args, ""); } } diff --git a/func.cpp b/func.cpp index e2e8ba84..c60c1f2c 100644 --- a/func.cpp +++ b/func.cpp @@ -244,7 +244,6 @@ Function::emitCode(FunctionEmitContext *ctx, llvm::Function *function, if (!g->target->isPTX()) //if (g->target->getISA() != Target::NVPTX64) { - assert(0); /* evghenii: must be removed in final, just for test for nvptx64 target */ llvm::Function::arg_iterator argIter = function->arg_begin(); llvm::Value *structParamPtr = argIter++; // Copy the function parameter values from the structure into local diff --git a/type.cpp b/type.cpp index 4dbbbf0a..8711361b 100644 --- a/type.cpp +++ b/type.cpp @@ -2959,7 +2959,6 @@ FunctionType::LLVMFunctionType(llvm::LLVMContext *ctx, bool removeMask) const { // if (g->target->getISA() != Target::NVPTX64) if (!g->target->isPTX()) { - assert(0); /* evghenii: must be removed in final, just for test for nvptx64 target */ llvm::Type *st = llvm::StructType::get(*ctx, llvmArgTypes); callTypes.push_back(llvm::PointerType::getUnqual(st)); callTypes.push_back(LLVMTypes::Int32Type); // threadIndex