export functions are now also generated... next add proper CDP calls..

This commit is contained in:
Evghenii
2013-11-12 14:05:12 +01:00
parent dbb96c1885
commit fd17ad236a
3 changed files with 31 additions and 14 deletions

12
ctx.cpp
View File

@@ -3595,7 +3595,7 @@ FunctionEmitContext::LaunchInst(llvm::Value *callee,
}
else /* isPTX == true */
{
assert(0); /* must only be called in export */
//assert(0); /* must only be called in export */
// assert(g->target->getISA() != Target::NVPTX64);
if (callee == NULL) {
@@ -3606,6 +3606,7 @@ FunctionEmitContext::LaunchInst(llvm::Value *callee,
launchedTasks = true;
AssertPos(currentPos, llvm::isa<llvm::Function>(callee));
#if 0
llvm::Type *argType =
(llvm::dyn_cast<llvm::Function>(callee))->arg_begin()->getType();
AssertPos(currentPos, llvm::PointerType::classof(argType));
@@ -3614,6 +3615,7 @@ FunctionEmitContext::LaunchInst(llvm::Value *callee,
AssertPos(currentPos, llvm::StructType::classof(pt->getElementType()));
llvm::StructType *argStructType =
static_cast<llvm::StructType *>(pt->getElementType());
#endif
llvm::Function *falloc = m->module->getFunction("CUDAAlloc");
AssertPos(currentPos, falloc != NULL);
@@ -3648,9 +3650,13 @@ FunctionEmitContext::LaunchInst(llvm::Value *callee,
* this, and other parts are reverse enginered via
* cpp(clang++ -S -emit-llvm)->IR and then IR(llc -march=cpp)->cpp
*/
for (unsigned int i = 0; i < argVals.size(); ++i)
llvm::Function *func = llvm::dyn_cast<llvm::Function>(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 = argStructType->getElementType(i);
llvm::Type* type = argIter->getType(); //argStructType->getElementType(i);
llvm::Value* ptr_arg1_addr = AllocaInst(type, "argptr");
StoreInst(argVals[i], ptr_arg1_addr);

View File

@@ -354,7 +354,8 @@ Function::emitCode(FunctionEmitContext *ctx, llvm::Function *function,
Assert(++argIter == function->arg_end());
}
#if 0
if (g->target->isPTX() && g->target->getISA() == Target::NVPTX64)
{
llvm::NamedMDNode* annotations =
m->module->getOrInsertNamedMetadata("nvvm.annotations");
llvm::SmallVector<llvm::Value*, 3> av;
@@ -362,7 +363,7 @@ Function::emitCode(FunctionEmitContext *ctx, llvm::Function *function,
av.push_back(llvm::MDString::get(*g->ctx, "kernel"));
av.push_back(llvm::ConstantInt::get(llvm::IntegerType::get(*g->ctx,32), 1));
annotations->addOperand(llvm::MDNode::get(*g->ctx, av));
#endif
}
}
}
else {
@@ -538,7 +539,6 @@ Function::GenerateIR() {
/* export function with NVPTX64 target should be emitted host architecture */
#if 0
const FunctionType *func_type= CastType<FunctionType>(sym->type);
/* exported functions are not supported yet */
if (g->target->getISA() == Target::NVPTX64 && func_type->isExported)
return;
#endif
@@ -567,7 +567,7 @@ Function::GenerateIR() {
// the application can call it
const FunctionType *type = CastType<FunctionType>(sym->type);
Assert(type != NULL);
if (type->isExported) { // && g->target->getISA() != Target::NVPTX64) {
if (type->isExported) { // && g->target->getISA() != Target::VPTX64) {
if (!type->isTask) {
llvm::FunctionType *ftype = type->LLVMFunctionType(g->ctx, true);
llvm::GlobalValue::LinkageTypes linkage = llvm::GlobalValue::ExternalLinkage;
@@ -602,6 +602,16 @@ Function::GenerateIR() {
FATAL("Function verificication failed");
}
}
if (g->target->isPTX() && g->target->getISA() == Target::NVPTX64)
{
llvm::NamedMDNode* annotations =
m->module->getOrInsertNamedMetadata("nvvm.annotations");
llvm::SmallVector<llvm::Value*, 3> av;
av.push_back(appFunction);
av.push_back(llvm::MDString::get(*g->ctx, "kernel"));
av.push_back(llvm::ConstantInt::get(llvm::IntegerType::get(*g->ctx,32), 1));
annotations->addOperand(llvm::MDNode::get(*g->ctx, av));
}
}
}
}

View File

@@ -796,6 +796,7 @@ Module::AddFunctionDeclaration(const std::string &name,
#else // LLVM 3.1 and 3.3+
function->addFnAttr(llvm::Attribute::AlwaysInline);
#endif
/* evghenii: on PTX target this must not be used, cause crash, dunno why */
if (functionType->isTask && g->target->getISA() != Target::NVPTX64)
// This also applies transitively to members I think?
#if defined(LLVM_3_1)