Merge branch 'nvptx' of github.com:egaburov/ispc into nvptx

This commit is contained in:
egaburov
2013-10-29 15:25:14 +01:00
10 changed files with 427 additions and 657 deletions

View File

@@ -36,7 +36,7 @@
# If you have your own special version of llvm and/or clang, change
# these variables to match.
LLVM_CONFIG=$(shell which /usr/local/llvm-3.3/bin/llvm-config)
LLVM_CONFIG=$(shell which /home/evghenii/usr/local/llvm/bin-3.3/bin/llvm-config)
CLANG_INCLUDE=$(shell $(LLVM_CONFIG) --includedir)
# Enable ARM by request

View File

@@ -338,11 +338,13 @@ lSetInternalFunctions(llvm::Module *module) {
"__all",
"__any",
"__aos_to_soa3_float",
"__aos_to_soa3_float1",
"__aos_to_soa3_float16",
"__aos_to_soa3_float4",
"__aos_to_soa3_float8",
"__aos_to_soa3_int32",
"__aos_to_soa4_float",
"__aos_to_soa4_float1",
"__aos_to_soa4_float16",
"__aos_to_soa4_float4",
"__aos_to_soa4_float8",
@@ -555,11 +557,13 @@ lSetInternalFunctions(llvm::Module *module) {
"__shuffle_i64",
"__shuffle_i8",
"__soa_to_aos3_float",
"__soa_to_aos3_float1",
"__soa_to_aos3_float16",
"__soa_to_aos3_float4",
"__soa_to_aos3_float8",
"__soa_to_aos3_int32",
"__soa_to_aos4_float",
"__soa_to_aos4_float1",
"__soa_to_aos4_float16",
"__soa_to_aos4_float4",
"__soa_to_aos4_float8",

File diff suppressed because it is too large Load Diff

18
ctx.cpp
View File

@@ -1404,6 +1404,8 @@ FunctionEmitContext::MasksAllEqual(llvm::Value *v1, llvm::Value *v2) {
llvm::Value *
FunctionEmitContext::ProgramIndexVector(bool is32bits) {
if (1) //g->target->getISA() != Target::NVPTX64)
{
llvm::SmallVector<llvm::Constant*, 16> array;
for (int i = 0; i < g->target->getVectorWidth() ; ++i) {
llvm::Constant *C = is32bits ? LLVMInt32(i) : LLVMInt64(i);
@@ -1414,6 +1416,22 @@ FunctionEmitContext::ProgramIndexVector(bool is32bits) {
return index;
}
else
{ /* this idea is to call __tid_x() builtin, but it doesn't work */
std::vector<Symbol *> mm;
m->symbolTable->LookupFunction("laneIndex", &mm);
if (g->target->getMaskBitCount() == 1)
AssertPos(currentPos, mm.size() == 1);
else
// There should be one with signed int signature, one unsigned int.
AssertPos(currentPos, mm.size() == 2);
// We can actually call either one, since both are i32s as far as
// LLVM's type system is concerned...
llvm::Function *fmm = mm[0]->function;
std::vector<llvm::Value*> args;
return CallInst(fmm, NULL, args, "laneIndex");
}
}
llvm::Value *

View File

@@ -531,7 +531,7 @@ Declarator::InitFromType(const Type *baseType, DeclSpecs *ds) {
returnType = returnType->ResolveUnboundVariability(Variability::Varying);
bool isTask = ds && ((ds->typeQualifiers & TYPEQUAL_TASK) != 0);
if (isTask && g->target->getISA() == Target::NVPTX64)
if (isTask && g->target->isPTX()) //getISA() == Target::NVPTX64)
{
ds->storageClass = SC_EXTERN_C;
ds->typeQualifiers |= TYPEQUAL_UNMASKED;
@@ -546,13 +546,12 @@ Declarator::InitFromType(const Type *baseType, DeclSpecs *ds) {
"qualifiers");
return;
}
#if 0 /* NVPTX64::task_and_externC */
if (!g->target->isPTX())
if (isExternC && isTask) {
Error(pos, "Function can't have both \"extern \"C\"\" and \"task\" "
"qualifiers");
return;
}
#endif
if (isExternC && isExported) {
Error(pos, "Function can't have both \"extern \"C\"\" and \"export\" "
"qualifiers");

View File

@@ -47,7 +47,7 @@
#include <stdio.h>
#if defined(LLVM_3_1) || defined(LLVM_3_2)
#include <llvm/IR/Metadata.h>
#include <llvm/Metadata.h>
#include <llvm/LLVMContext.h>
#include <llvm/Module.h>
#include <llvm/Type.h>
@@ -523,6 +523,13 @@ 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<FunctionType>(sym->type);
if (g->target->getISA() == Target::NVPTX64 && type->isExported)
return;
if (g->target->getISA() != Target::NVPTX64 && g->target->isPTX() && !type->isExported)
return;
}
{
FunctionEmitContext ec(this, sym, function, firstStmtPos);
emitCode(&ec, function, firstStmtPos);
@@ -540,7 +547,7 @@ Function::GenerateIR() {
// the application can call it
const FunctionType *type = CastType<FunctionType>(sym->type);
Assert(type != NULL);
if (type->isExported) {
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;

View File

@@ -174,7 +174,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)
@@ -184,6 +184,7 @@ Target::Target(const char *arch, const char *cpu, const char *isa, bool pic) :
#endif
m_valid(false),
m_isa(SSE2),
m_isPTX(isPTX),
m_arch(""),
m_is32Bit(true),
m_cpu(""),
@@ -656,15 +657,16 @@ Target::Target(const char *arch, const char *cpu, const char *isa, bool pic) :
#endif
else if (!strcasecmp(isa, "nvptx64")) {
this->m_isa = Target::NVPTX64;
this->m_isPTX = true;
this->m_nativeVectorWidth = 1;
this->m_vectorWidth = 1;
this->m_attributes = "+sm_35";
#if 0
#if 1
this->m_hasHalf = false;
this->m_maskingIsFree = true;
this->m_maskBitCount = 1;
this->m_hasTranscendentals = true;
this->m_hasGather = this->m_hasScatter = true;
this->m_hasGather = this->m_hasScatter = false;
#else
this->m_maskingIsFree = false;
this->m_maskBitCount = 32;
@@ -727,6 +729,9 @@ Target::Target(const char *arch, const char *cpu, const char *isa, bool pic) :
dl_string = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
"i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-"
"f80:128:128-n8:16:32:64-S128-v16:16:16-v32:32:32-v4:128:128";
} else if (m_isa == Target::NVPTX64)
{
dl_string = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v32:32:32-v64:64:64-v128:128:128-n16:32:64";
}
// 3. Finally set member data

4
ispc.h
View File

@@ -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. */
@@ -244,6 +244,7 @@ public:
bool isValid() const {return m_valid;}
ISA getISA() const {return m_isa;}
bool isPTX() const {return m_isPTX;}
std::string getArch() const {return m_arch;}
@@ -298,6 +299,7 @@ private:
/** Instruction set being compiled to. */
ISA m_isa;
bool m_isPTX;
/** Target system architecture. (e.g. "x86-64", "x86"). */
std::string m_arch;

View File

@@ -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) {
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;
}
#endif
std::vector<Symbol *> funcs;
symbolTable->LookupFunction(name.c_str(), &funcs);
@@ -953,8 +951,14 @@ Module::writeOutput(OutputType outputType, const char *outFileName,
const char *fileType = NULL;
switch (outputType) {
case Asm:
if (g->target->getISA() != Target::NVPTX64)
{
if (strcasecmp(suffix, "s"))
fileType = "assembly";
}
else
if (strcasecmp(suffix, "ptx"))
fileType = "assembly";
break;
case Bitcode:
if (strcasecmp(suffix, "bc"))
@@ -1047,6 +1051,11 @@ Module::writeBitcode(llvm::Module *module, const char *outFileName) {
}
llvm::raw_fd_ostream fos(fd, (fd != 1), false);
if (g->target->getISA() == Target::NVPTX64)
{
const std::string dl_string = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v32:32:32-v64:64:64-v128:128:128-n16:32:64";
module->setDataLayout(dl_string);
}
llvm::WriteBitcodeToFile(module, fos);
return true;
}
@@ -2305,7 +2314,88 @@ Module::CompileAndOutput(const char *srcFile,
const char *hostStubFileName,
const char *devStubFileName)
{
if (target == NULL || strchr(target, ',') == NULL) {
if (target != NULL && !strcmp(target,"nvptx64")) // NVPTX64
{
// We're only compiling to a single target
const char * target_list[] = {"nvptx64", "avx"};
int errorCount = 0;
const char *suffix_orig = strrchr(outFileName, '.');
++suffix_orig;
assert(suffix_orig!=NULL);
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;
}
}
assert(outFileName != NULL);
std::string targetOutFileName =
lGetTargetFileName(outFileName, target_list[itarget]);
if (outputType == Asm)
{
const char * targetOutFileName_c = targetOutFileName.c_str();
const int suffix = strrchr(targetOutFileName_c, '.') - targetOutFileName_c + 1;
if (itarget == 1 && !strcasecmp(suffix_orig, "ptx"))
{
targetOutFileName[suffix ] = 's';
targetOutFileName[suffix+1] = 0;
}
}
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;
}
return errorCount > 0;
}
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())
@@ -2476,4 +2566,5 @@ Module::CompileAndOutput(const char *srcFile,
return errorCount > 0;
}
return true;
}

View File

@@ -2925,7 +2925,7 @@ FunctionType::GetReturnTypeString() const {
llvm::FunctionType *
FunctionType::LLVMFunctionType(llvm::LLVMContext *ctx, bool removeMask) const {
if (isTask == true && g->target->getISA() != Target::NVPTX64)
if (isTask == true && !g->target->isPTX()) //getISA() != Target::NVPTX64)
Assert(removeMask == false);
// Get the LLVM Type *s for the function arguments