diff --git a/ispc.cpp b/ispc.cpp index 00d94000..232b88e8 100644 --- a/ispc.cpp +++ b/ispc.cpp @@ -157,7 +157,7 @@ static const char *supportedCPUs[] = { #endif // LLVM 3.4+ }; -Target::Target(const char *arch, const char *cpu, const char *isa, bool pic) : +Target::Target(const char *arch, const char *cpu, const char *isa, bool pic, bool isPTX) : m_target(NULL), m_targetMachine(NULL), #if defined(LLVM_3_1) @@ -167,7 +167,7 @@ Target::Target(const char *arch, const char *cpu, const char *isa, bool pic) : #endif m_valid(false), m_isa(SSE2), - m_isPTX(false), + m_isPTX(isPTX), m_arch(""), m_is32Bit(true), m_cpu(""), diff --git a/ispc.h b/ispc.h index eea77348..29f34183 100644 --- a/ispc.h +++ b/ispc.h @@ -189,7 +189,7 @@ public: /** Initializes the given Target pointer for a target of the given name, if the name is a known target. Returns true if the target was initialized and false if the name is unknown. */ - Target(const char *arch, const char *cpu, const char *isa, bool pic); + Target(const char *arch, const char *cpu, const char *isa, bool pic, bool isPTX = false); /** Returns a comma-delimited string giving the names of the currently supported compilation targets. */ diff --git a/module.cpp b/module.cpp index 07dc5e48..071013b8 100644 --- a/module.cpp +++ b/module.cpp @@ -733,13 +733,11 @@ 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 0 /* NVPTX64::task_and_externC */ if (functionType->isTask && g->target->getISA() != Target::NVPTX64) { Error(pos, "\"task\" qualifier is illegal with C-linkage extern " "function \"%s\". Ignoring this function.", name.c_str()); return; } -#endif std::vector funcs; symbolTable->LookupFunction(name.c_str(), &funcs); @@ -2316,62 +2314,72 @@ Module::CompileAndOutput(const char *srcFile, const char *hostStubFileName, const char *devStubFileName) { - if (target != NULL && !strcmp(target,"nvptx64")) + if (target != NULL && !strcmp(target,"nvptx64")) // NVPTX64 { - fprintf(stderr, "compiling nvptx64 \n"); // We're only compiling to a single target - g->target = new Target(arch, cpu, target, generatePIC); - if (!g->target->isValid()) - return 1; + const char * target_list[] = {"nvptx64", "avx"}; + int errorCount = 0; + for (int itarget = 0; itarget < 2; itarget++) + { + fprintf(stderr, "compiling nvptx64 : target= %s\n",target_list[itarget]); + g->target = new Target(arch, cpu, target_list[itarget], generatePIC, /* isPTX= */ true); + if (!g->target->isValid()) + return 1; - m = new Module(srcFile); - if (m->CompileFile() == 0) { - if (outputType == CXX) { - if (target == NULL || strncmp(target, "generic-", 8) != 0) { - Error(SourcePos(), "When generating C++ output, one of the \"generic-*\" " - "targets must be used."); - return 1; - } - } - else if (outputType == Asm || outputType == Object) { - if (target != NULL && strncmp(target, "generic-", 8) == 0) { - Error(SourcePos(), "When using a \"generic-*\" compilation target, " - "%s output can not be used.", - (outputType == Asm) ? "assembly" : "object file"); - return 1; + m = new Module(srcFile); + if (m->CompileFile() == 0) { + if (outputType == CXX) { + if (target == NULL || strncmp(target, "generic-", 8) != 0) { + Error(SourcePos(), "When generating C++ output, one of the \"generic-*\" " + "targets must be used."); + return 1; + } + } + else if (outputType == Asm || outputType == Object) { + if (target != NULL && strncmp(target, "generic-", 8) == 0) { + Error(SourcePos(), "When using a \"generic-*\" compilation target, " + "%s output can not be used.", + (outputType == Asm) ? "assembly" : "object file"); + return 1; + } + } + + assert(outFileName != NULL); + std::string targetOutFileName = + lGetTargetFileName(outFileName, target_list[itarget]); + if (!m->writeOutput(outputType, targetOutFileName.c_str(), includeFileName)) + return 1; + + if (itarget > 0) + { + if (headerFileName != NULL) + if (!m->writeOutput(Module::Header, headerFileName)) + return 1; + if (depsFileName != NULL) + if (!m->writeOutput(Module::Deps,depsFileName)) + return 1; + if (hostStubFileName != NULL) + if (!m->writeOutput(Module::HostStub,hostStubFileName)) + return 1; + if (devStubFileName != NULL) + if (!m->writeOutput(Module::DevStub,devStubFileName)) + return 1; } } + else + ++m->errorCount; + + errorCount += m->errorCount; + delete m; + m = NULL; + + delete g->target; + g->target = NULL; - if (outFileName != NULL) - if (!m->writeOutput(outputType, outFileName, includeFileName)) - return 1; - if (headerFileName != NULL) - if (!m->writeOutput(Module::Header, headerFileName)) - return 1; - if (depsFileName != NULL) - if (!m->writeOutput(Module::Deps,depsFileName)) - return 1; - if (hostStubFileName != NULL) - if (!m->writeOutput(Module::HostStub,hostStubFileName)) - return 1; - if (devStubFileName != NULL) - if (!m->writeOutput(Module::DevStub,devStubFileName)) - return 1; } - else - ++m->errorCount; - - int errorCount = m->errorCount; - delete m; - m = NULL; - - delete g->target; - g->target = NULL; - return errorCount > 0; } - else - if (target == NULL || strchr(target, ',') == NULL) { + else if (target == NULL || strchr(target, ',') == NULL) { // We're only compiling to a single target g->target = new Target(arch, cpu, target, generatePIC); if (!g->target->isValid()) @@ -2542,4 +2550,5 @@ Module::CompileAndOutput(const char *srcFile, return errorCount > 0; } + return true; }