From 43db682c6dfebefe9a0e963ffa8d4872782b369a Mon Sep 17 00:00:00 2001 From: jbrodman Date: Thu, 13 Mar 2014 06:07:56 -0700 Subject: [PATCH] Fix bugs with exported varyings. --- module.cpp | 33 ++++++++++----------------------- type.cpp | 35 ++++++++++++++++++++--------------- type.h | 3 ++- 3 files changed, 32 insertions(+), 39 deletions(-) diff --git a/module.cpp b/module.cpp index 014b7f5f..ad0ef284 100644 --- a/module.cpp +++ b/module.cpp @@ -1156,11 +1156,11 @@ lContainsPtrToVarying(const StructType *st) { */ static void lEmitStructDecl(const StructType *st, std::vector *emittedStructs, - FILE *file, bool printGenericHeader=false, bool emitUnifs=true) { + FILE *file, bool emitUnifs=true) { // if we're emitting this for a generic dispatch header file and it's // struct that only contains uniforms, don't bother if we're emitting uniforms - if (printGenericHeader && !emitUnifs && !lContainsPtrToVarying(st)) { + if (!emitUnifs && !lContainsPtrToVarying(st)) { return; } @@ -1176,33 +1176,20 @@ lEmitStructDecl(const StructType *st, std::vector *emittedSt const StructType *elementStructType = lGetElementStructType(st->GetElementType(i)); if (elementStructType != NULL) - lEmitStructDecl(elementStructType, emittedStructs, file, printGenericHeader, emitUnifs); + lEmitStructDecl(elementStructType, emittedStructs, file, emitUnifs); } // And now it's safe to declare this one emittedStructs->push_back(st); - - if (printGenericHeader && lContainsPtrToVarying(st)) { - fprintf(file, "#ifndef __ISPC_STRUCT_%s%d__\n", - st->GetStructName().c_str(), - g->target->getVectorWidth()); - fprintf(file, "#define __ISPC_STRUCT_%s%d__\n", - st->GetStructName().c_str(), - g->target->getVectorWidth()); - } - else { - fprintf(file, "#ifndef __ISPC_STRUCT_%s__\n",st->GetStructName().c_str()); - fprintf(file, "#define __ISPC_STRUCT_%s__\n",st->GetStructName().c_str()); - } - fprintf(file, "struct %s", st->GetStructName().c_str()); + fprintf(file, "#ifndef __ISPC_STRUCT_%s__\n",st->GetCStructName().c_str()); + fprintf(file, "#define __ISPC_STRUCT_%s__\n",st->GetCStructName().c_str()); + + fprintf(file, "struct %s", st->GetCStructName().c_str()); if (st->GetSOAWidth() > 0) // This has to match the naming scheme in // StructType::GetCDeclaration(). fprintf(file, "_SOA%d", st->GetSOAWidth()); - if (printGenericHeader && lContainsPtrToVarying(st)) { - fprintf(file, "%d", g->target->getVectorWidth()); - } fprintf(file, " {\n"); for (int i = 0; i < st->GetElementCount(); ++i) { @@ -1219,10 +1206,10 @@ lEmitStructDecl(const StructType *st, std::vector *emittedSt header file, emit their declarations. */ static void -lEmitStructDecls(std::vector &structTypes, FILE *file, bool printGenericHeader=false, bool emitUnifs=true) { +lEmitStructDecls(std::vector &structTypes, FILE *file, bool emitUnifs=true) { std::vector emittedStructs; for (unsigned int i = 0; i < structTypes.size(); ++i) - lEmitStructDecl(structTypes[i], &emittedStructs, file, printGenericHeader, emitUnifs); + lEmitStructDecl(structTypes[i], &emittedStructs, file, emitUnifs); } @@ -1938,7 +1925,7 @@ Module::writeDispatchHeader(DispatchHeaderInfo *DHI) { lEmitVectorTypedefs(exportedVectorTypes, f); lEmitEnumDecls(exportedEnumTypes, f); } - lEmitStructDecls(exportedStructTypes, f, true, DHI->EmitUnifs); + lEmitStructDecls(exportedStructTypes, f, DHI->EmitUnifs); // Update flags DHI->EmitUnifs = false; diff --git a/type.cpp b/type.cpp index 2e9d831e..e0e36182 100644 --- a/type.cpp +++ b/type.cpp @@ -456,15 +456,9 @@ AtomicType::GetCDeclaration(const std::string &name) const { ret += name; } - if (variability == Variability::Varying || - variability == Variability::SOA) { + if (variability == Variability::SOA) { char buf[32]; - // get program count - // g->mangleFunctionsNamesWithTarget - hack check for void * - int vWidth = (variability == Variability::Varying) ? - g->target->getVectorWidth() : - variability.soaWidth; - sprintf(buf, "[%d]", vWidth); + sprintf(buf, "[%d]", variability.soaWidth); ret += buf; } @@ -1096,20 +1090,27 @@ PointerType::GetCDeclaration(const std::string &name) const { } std::string ret = baseType->GetCDeclaration(""); + + bool baseIsBasicVarying = (IsBasicType(baseType)) && (baseType->IsVaryingType()); + + if (baseIsBasicVarying) ret += std::string("("); ret += std::string(" *"); if (isConst) ret += " const"; ret += std::string(" "); ret += name; + if (baseIsBasicVarying) ret += std::string(")"); - if (variability == Variability::SOA || - variability == Variability::Varying) { - int vWidth = (variability == Variability::Varying) ? - g->target->getVectorWidth() : - variability.soaWidth; + if (variability == Variability::SOA) { char buf[32]; - sprintf(buf, "[%d]", vWidth); + sprintf(buf, "[%d]", variability.soaWidth); ret += buf; } + if (baseIsBasicVarying) { + int vWidth = g->target->getVectorWidth(); + char buf[32]; + sprintf(buf, "[%d]", vWidth); + ret += buf; + } return ret; } @@ -1890,6 +1891,10 @@ StructType::StructType(const std::string &n, const llvm::SmallVector "Foo".) */ - const std::string &GetStructName() const { return name; } + const std::string &GetStructName() const { return name; } + const std::string GetCStructName() const; private: static bool checkIfCanBeSOA(const StructType *st);