Skip to content

Commit

Permalink
Merge pull request #767 from jbrodman/nomosoa2
Browse files Browse the repository at this point in the history
Fix bugs with exported varyings.
  • Loading branch information
dbabokin committed Mar 14, 2014
2 parents 2e5b0b7 + 43db682 commit 11f17ce
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 39 deletions.
33 changes: 10 additions & 23 deletions module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1165,11 +1165,11 @@ lContainsPtrToVarying(const StructType *st) {
*/
static void
lEmitStructDecl(const StructType *st, std::vector<const StructType *> *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;
}

Expand All @@ -1185,33 +1185,20 @@ lEmitStructDecl(const StructType *st, std::vector<const StructType *> *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) {
Expand All @@ -1228,10 +1215,10 @@ lEmitStructDecl(const StructType *st, std::vector<const StructType *> *emittedSt
header file, emit their declarations.
*/
static void
lEmitStructDecls(std::vector<const StructType *> &structTypes, FILE *file, bool printGenericHeader=false, bool emitUnifs=true) {
lEmitStructDecls(std::vector<const StructType *> &structTypes, FILE *file, bool emitUnifs=true) {
std::vector<const StructType *> emittedStructs;
for (unsigned int i = 0; i < structTypes.size(); ++i)
lEmitStructDecl(structTypes[i], &emittedStructs, file, printGenericHeader, emitUnifs);
lEmitStructDecl(structTypes[i], &emittedStructs, file, emitUnifs);
}


Expand Down Expand Up @@ -1947,7 +1934,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;
Expand Down
35 changes: 20 additions & 15 deletions type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,15 +460,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;
}

Expand Down Expand Up @@ -1108,20 +1102,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;
}
Expand Down Expand Up @@ -1906,6 +1907,10 @@ StructType::StructType(const std::string &n, const llvm::SmallVector<const Type
}
}

const std::string
StructType::GetCStructName() const {
return lMangleStructName(name, variability);
}

Variability
StructType::GetVariability() const {
Expand Down Expand Up @@ -2094,7 +2099,7 @@ std::string
StructType::GetCDeclaration(const std::string &n) const {
std::string ret;
if (isConst) ret += "const ";
ret += std::string("struct ") + name;
ret += std::string("struct ") + GetCStructName();
if (lShouldPrintName(n)) {
ret += std::string(" ") + n;

Expand Down
3 changes: 2 additions & 1 deletion type.h
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,8 @@ class StructType : public CollectionType {
const SourcePos &GetElementPosition(int i) const { return elementPositions[i]; }

/** Returns the name of the structure type. (e.g. struct Foo -> "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);
Expand Down

0 comments on commit 11f17ce

Please sign in to comment.