Pipe through source file locations of structure element declarations; these are now supplied to the llvm::DIBuilder::createMemberType() method rather than giving it the position of the overall struct declaration for each one. Fixes issue #31

This commit is contained in:
Matt Pharr
2011-06-29 05:38:42 +01:00
parent 86de910ecd
commit cb58c78c1a
5 changed files with 41 additions and 27 deletions

View File

@@ -318,9 +318,10 @@ Declaration::Print() const {
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
void void
GetStructTypesAndNames(const std::vector<StructDeclaration *> &sd, GetStructTypesNamesPositions(const std::vector<StructDeclaration *> &sd,
std::vector<const Type *> *elementTypes, std::vector<const Type *> *elementTypes,
std::vector<std::string> *elementNames) { std::vector<std::string> *elementNames,
std::vector<SourcePos> *elementPositions) {
for (unsigned int i = 0; i < sd.size(); ++i) { for (unsigned int i = 0; i < sd.size(); ++i) {
const Type *type = sd[i]->type; const Type *type = sd[i]->type;
// FIXME: making this fake little DeclSpecs here is really // FIXME: making this fake little DeclSpecs here is really
@@ -343,6 +344,7 @@ GetStructTypesAndNames(const std::vector<StructDeclaration *> &sd,
elementTypes->push_back(d->sym->type); elementTypes->push_back(d->sym->type);
elementNames->push_back(d->sym->name); elementNames->push_back(d->sym->name);
elementPositions->push_back(d->sym->pos);
} }
} }
} }

7
decl.h
View File

@@ -196,8 +196,9 @@ struct StructDeclaration {
/** Given a set of StructDeclaration instances, this returns the types of /** Given a set of StructDeclaration instances, this returns the types of
the elements of the corresponding struct and their names. */ the elements of the corresponding struct and their names. */
extern void GetStructTypesAndNames(const std::vector<StructDeclaration *> &sd, extern void GetStructTypesNamesPositions(const std::vector<StructDeclaration *> &sd,
std::vector<const Type *> *elementTypes, std::vector<const Type *> *elementTypes,
std::vector<std::string> *elementNames); std::vector<std::string> *elementNames,
std::vector<SourcePos> *elementPositions);
#endif // ISPC_DECL_H #endif // ISPC_DECL_H

View File

@@ -564,9 +564,11 @@ struct_or_union_specifier
{ {
std::vector<const Type *> elementTypes; std::vector<const Type *> elementTypes;
std::vector<std::string> elementNames; std::vector<std::string> elementNames;
GetStructTypesAndNames(*$4, &elementTypes, &elementNames); std::vector<SourcePos> elementPositions;
GetStructTypesNamesPositions(*$4, &elementTypes, &elementNames,
&elementPositions);
StructType *st = new StructType($2, elementTypes, elementNames, StructType *st = new StructType($2, elementTypes, elementNames,
false, true, @2); elementPositions, false, true, @2);
m->symbolTable->AddType($2, st, @2); m->symbolTable->AddType($2, st, @2);
$$ = st; $$ = st;
} }
@@ -574,8 +576,11 @@ struct_or_union_specifier
{ {
std::vector<const Type *> elementTypes; std::vector<const Type *> elementTypes;
std::vector<std::string> elementNames; std::vector<std::string> elementNames;
GetStructTypesAndNames(*$3, &elementTypes, &elementNames); std::vector<SourcePos> elementPositions;
$$ = new StructType("", elementTypes, elementNames, false, true, @1); GetStructTypesNamesPositions(*$3, &elementTypes, &elementNames,
&elementPositions);
$$ = new StructType("", elementTypes, elementNames, elementPositions,
false, true, @1);
} }
| struct_or_union '{' '}' | struct_or_union '{' '}'
{ {

View File

@@ -961,9 +961,10 @@ VectorType::getVectorMemoryCount() const {
StructType::StructType(const std::string &n, const std::vector<const Type *> &elts, StructType::StructType(const std::string &n, const std::vector<const Type *> &elts,
const std::vector<std::string> &en, const std::vector<std::string> &en,
const std::vector<SourcePos> &ep,
bool ic, bool iu, SourcePos p) bool ic, bool iu, SourcePos p)
: name(n), elementTypes(elts), elementNames(en), isUniform(iu), isConst(ic), : name(n), elementTypes(elts), elementNames(en), elementPositions(ep),
pos(p) { isUniform(iu), isConst(ic), pos(p) {
} }
@@ -1014,8 +1015,8 @@ StructType::GetAsVaryingType() const {
if (IsVaryingType()) if (IsVaryingType())
return this; return this;
else else
return new StructType(name, elementTypes, elementNames, isConst, return new StructType(name, elementTypes, elementNames, elementPositions,
false, pos); isConst, false, pos);
} }
@@ -1024,8 +1025,8 @@ StructType::GetAsUniformType() const {
if (IsUniformType()) if (IsUniformType())
return this; return this;
else else
return new StructType(name, elementTypes, elementNames, isConst, return new StructType(name, elementTypes, elementNames, elementPositions,
true, pos); isConst, true, pos);
} }
@@ -1038,7 +1039,8 @@ StructType::GetSOAType(int width) const {
const Type *t = GetMemberType(i); const Type *t = GetMemberType(i);
et.push_back(t->GetSOAType(width)); et.push_back(t->GetSOAType(width));
} }
return new StructType(name, et, elementNames, isConst, isUniform, pos); return new StructType(name, et, elementNames, elementPositions,
isConst, isUniform, pos);
} }
@@ -1047,8 +1049,8 @@ StructType::GetAsConstType() const {
if (IsConstType()) if (IsConstType())
return this; return this;
else else
return new StructType(name, elementTypes, elementNames, true, return new StructType(name, elementTypes, elementNames,
isUniform, pos); elementPositions, true, isUniform, pos);
} }
@@ -1057,8 +1059,8 @@ StructType::GetAsNonConstType() const {
if (!IsConstType()) if (!IsConstType())
return this; return this;
else else
return new StructType(name, elementTypes, elementNames, false, return new StructType(name, elementTypes, elementNames, elementPositions,
isUniform, pos); false, isUniform, pos);
} }
@@ -1138,7 +1140,6 @@ StructType::GetDIType(llvm::DIDescriptor scope) const {
return llvm::DIType(); return llvm::DIType();
#else #else
uint64_t currentSize = 0, align = 0; uint64_t currentSize = 0, align = 0;
llvm::DIFile diFile = pos.GetDIFile();
std::vector<llvm::Value *> elementLLVMTypes; std::vector<llvm::Value *> elementLLVMTypes;
// Walk through the elements of the struct; for each one figure out its // Walk through the elements of the struct; for each one figure out its
@@ -1159,17 +1160,17 @@ StructType::GetDIType(llvm::DIDescriptor scope) const {
currentSize += eltAlign - (currentSize % eltAlign); currentSize += eltAlign - (currentSize % eltAlign);
assert((currentSize == 0) || (currentSize % eltAlign) == 0); assert((currentSize == 0) || (currentSize % eltAlign) == 0);
// FIXME: we should pass this actual file/line number for the llvm::DIFile diFile = elementPositions[i].GetDIFile();
// member, not the position of the struct declaration int line = elementPositions[i].first_line;
#ifdef LLVM_2_9 #ifdef LLVM_2_9
llvm::DIType fieldType = llvm::DIType fieldType =
m->diBuilder->createMemberType(elementNames[i], diFile, pos.first_line, m->diBuilder->createMemberType(elementNames[i], diFile, line,
eltSize, eltAlign, currentSize, 0, eltSize, eltAlign, currentSize, 0,
eltType); eltType);
#else #else
llvm::DIType fieldType = llvm::DIType fieldType =
m->diBuilder->createMemberType(scope, elementNames[i], diFile, m->diBuilder->createMemberType(scope, elementNames[i], diFile,
pos.first_line, eltSize, eltAlign, line, eltSize, eltAlign,
currentSize, 0, eltType); currentSize, 0, eltType);
#endif // LLVM_2_9 #endif // LLVM_2_9
elementLLVMTypes.push_back(fieldType); elementLLVMTypes.push_back(fieldType);
@@ -1188,6 +1189,7 @@ StructType::GetDIType(llvm::DIDescriptor scope) const {
#else #else
llvm::DIArray elements = m->diBuilder->getOrCreateArray(elementLLVMTypes); llvm::DIArray elements = m->diBuilder->getOrCreateArray(elementLLVMTypes);
#endif #endif
llvm::DIFile diFile = pos.GetDIFile();
return m->diBuilder->createStructType(scope, name, diFile, pos.first_line, currentSize, return m->diBuilder->createStructType(scope, name, diFile, pos.first_line, currentSize,
align, 0, elements); align, 0, elements);
#endif // LLVM_2_8 #endif // LLVM_2_8

6
type.h
View File

@@ -442,7 +442,8 @@ private:
class StructType : public Type { class StructType : public Type {
public: public:
StructType(const std::string &name, const std::vector<const Type *> &elts, StructType(const std::string &name, const std::vector<const Type *> &elts,
const std::vector<std::string> &eltNames, bool isConst, const std::vector<std::string> &eltNames,
const std::vector<SourcePos> &eltPositions, bool isConst,
bool isUniform, SourcePos pos); bool isUniform, SourcePos pos);
bool IsUniformType() const; bool IsUniformType() const;
@@ -501,6 +502,9 @@ private:
*/ */
const std::vector<const Type *> elementTypes; const std::vector<const Type *> elementTypes;
const std::vector<std::string> elementNames; const std::vector<std::string> elementNames;
/** Source file position at which each structure element declaration
appeared. */
const std::vector<SourcePos> elementPositions;
const bool isUniform; const bool isUniform;
const bool isConst; const bool isConst;
const SourcePos pos; const SourcePos pos;