Use llvm::SmallVectors for struct member types and function types.

Further reduction of dynamic memory allocation...
This commit is contained in:
Matt Pharr
2012-05-04 13:43:29 -07:00
parent 413264eaae
commit 8006589828
6 changed files with 51 additions and 49 deletions

View File

@@ -157,7 +157,7 @@ lLLVMTypeToISPCType(const llvm::Type *t, bool intAsUnsigned) {
static void static void
lCreateSymbol(const std::string &name, const Type *returnType, lCreateSymbol(const std::string &name, const Type *returnType,
const std::vector<const Type *> &argTypes, llvm::SmallVector<const Type *, 8> &argTypes,
const llvm::FunctionType *ftype, llvm::Function *func, const llvm::FunctionType *ftype, llvm::Function *func,
SymbolTable *symbolTable) { SymbolTable *symbolTable) {
SourcePos noPos; SourcePos noPos;
@@ -199,7 +199,7 @@ lCreateISPCSymbol(llvm::Function *func, SymbolTable *symbolTable) {
// bool, so just have a one-off override for that one... // bool, so just have a one-off override for that one...
if (g->target.maskBitCount != 1 && name == "__sext_varying_bool") { if (g->target.maskBitCount != 1 && name == "__sext_varying_bool") {
const Type *returnType = AtomicType::VaryingInt32; const Type *returnType = AtomicType::VaryingInt32;
std::vector<const Type *> argTypes; llvm::SmallVector<const Type *, 8> argTypes;
argTypes.push_back(AtomicType::VaryingBool); argTypes.push_back(AtomicType::VaryingBool);
FunctionType *funcType = new FunctionType(returnType, argTypes, noPos); FunctionType *funcType = new FunctionType(returnType, argTypes, noPos);
@@ -229,7 +229,7 @@ lCreateISPCSymbol(llvm::Function *func, SymbolTable *symbolTable) {
// Iterate over the arguments and try to find their equivalent ispc // Iterate over the arguments and try to find their equivalent ispc
// types. Track if any of the arguments has an integer type. // types. Track if any of the arguments has an integer type.
bool anyIntArgs = false; bool anyIntArgs = false;
std::vector<const Type *> argTypes; llvm::SmallVector<const Type *, 8> argTypes;
for (unsigned int j = 0; j < ftype->getNumParams(); ++j) { for (unsigned int j = 0; j < ftype->getNumParams(); ++j) {
const llvm::Type *llvmArgType = ftype->getParamType(j); const llvm::Type *llvmArgType = ftype->getParamType(j);
const Type *type = lLLVMTypeToISPCType(llvmArgType, intAsUnsigned); const Type *type = lLLVMTypeToISPCType(llvmArgType, intAsUnsigned);
@@ -674,7 +674,7 @@ lDefineConstantInt(const char *name, int val, llvm::Module *module,
static void static void
lDefineConstantIntFunc(const char *name, int val, llvm::Module *module, lDefineConstantIntFunc(const char *name, int val, llvm::Module *module,
SymbolTable *symbolTable) { SymbolTable *symbolTable) {
std::vector<const Type *> args; llvm::SmallVector<const Type *, 8> args;
FunctionType *ft = new FunctionType(AtomicType::UniformInt32, args, SourcePos()); FunctionType *ft = new FunctionType(AtomicType::UniformInt32, args, SourcePos());
Symbol *sym = new Symbol(name, SourcePos(), ft, SC_STATIC); Symbol *sym = new Symbol(name, SourcePos(), ft, SC_STATIC);

View File

@@ -386,11 +386,11 @@ Declarator::InitFromType(const Type *baseType, DeclSpecs *ds) {
type = arrayType; type = arrayType;
} }
else if (kind == DK_FUNCTION) { else if (kind == DK_FUNCTION) {
std::vector<const Type *> args; llvm::SmallVector<const Type *, 8> args;
std::vector<std::string> argNames; llvm::SmallVector<std::string, 8> argNames;
std::vector<Expr *> argDefaults; llvm::SmallVector<Expr *, 8> argDefaults;
std::vector<SourcePos> argPos; llvm::SmallVector<SourcePos, 8> argPos;
// Loop over the function arguments and store the names, types, // Loop over the function arguments and store the names, types,
// default values (if any), and source file positions each one in // default values (if any), and source file positions each one in
// the corresponding vector. // the corresponding vector.
@@ -646,9 +646,9 @@ Declaration::Print(int indent) const {
void void
GetStructTypesNamesPositions(const std::vector<StructDeclaration *> &sd, GetStructTypesNamesPositions(const std::vector<StructDeclaration *> &sd,
std::vector<const Type *> *elementTypes, llvm::SmallVector<const Type *, 8> *elementTypes,
std::vector<std::string> *elementNames, llvm::SmallVector<std::string, 8> *elementNames,
std::vector<SourcePos> *elementPositions) { llvm::SmallVector<SourcePos, 8> *elementPositions) {
std::set<std::string> seenNames; std::set<std::string> seenNames;
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;

7
decl.h
View File

@@ -55,6 +55,7 @@
#define ISPC_DECL_H #define ISPC_DECL_H
#include "ispc.h" #include "ispc.h"
#include <llvm/ADT/SmallVector.h>
struct VariableDeclaration; struct VariableDeclaration;
@@ -219,8 +220,8 @@ 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 GetStructTypesNamesPositions(const std::vector<StructDeclaration *> &sd, extern void GetStructTypesNamesPositions(const std::vector<StructDeclaration *> &sd,
std::vector<const Type *> *elementTypes, llvm::SmallVector<const Type *, 8> *elementTypes,
std::vector<std::string> *elementNames, llvm::SmallVector<std::string, 8> *elementNames,
std::vector<SourcePos> *elementPositions); llvm::SmallVector<SourcePos, 8> *elementPositions);
#endif // ISPC_DECL_H #endif // ISPC_DECL_H

View File

@@ -853,9 +853,9 @@ struct_or_union_specifier
: struct_or_union struct_or_union_name '{' struct_declaration_list '}' : struct_or_union struct_or_union_name '{' struct_declaration_list '}'
{ {
if ($4 != NULL) { if ($4 != NULL) {
std::vector<const Type *> elementTypes; llvm::SmallVector<const Type *, 8> elementTypes;
std::vector<std::string> elementNames; llvm::SmallVector<std::string, 8> elementNames;
std::vector<SourcePos> elementPositions; llvm::SmallVector<SourcePos, 8> elementPositions;
GetStructTypesNamesPositions(*$4, &elementTypes, &elementNames, GetStructTypesNamesPositions(*$4, &elementTypes, &elementNames,
&elementPositions); &elementPositions);
StructType *st = new StructType($2, elementTypes, elementNames, StructType *st = new StructType($2, elementTypes, elementNames,
@@ -869,9 +869,9 @@ struct_or_union_specifier
| struct_or_union '{' struct_declaration_list '}' | struct_or_union '{' struct_declaration_list '}'
{ {
if ($3 != NULL) { if ($3 != NULL) {
std::vector<const Type *> elementTypes; llvm::SmallVector<const Type *, 8> elementTypes;
std::vector<std::string> elementNames; llvm::SmallVector<std::string, 8> elementNames;
std::vector<SourcePos> elementPositions; llvm::SmallVector<SourcePos, 8> elementPositions;
GetStructTypesNamesPositions(*$3, &elementTypes, &elementNames, GetStructTypesNamesPositions(*$3, &elementTypes, &elementNames,
&elementPositions); &elementPositions);
$$ = new StructType("", elementTypes, elementNames, elementPositions, $$ = new StructType("", elementTypes, elementNames, elementPositions,

View File

@@ -1772,9 +1772,9 @@ lMangleStructName(const std::string &name, Variability variability) {
} }
StructType::StructType(const std::string &n, const std::vector<const Type *> &elts, StructType::StructType(const std::string &n, const llvm::SmallVector<const Type *, 8> &elts,
const std::vector<std::string> &en, const llvm::SmallVector<std::string, 8> &en,
const std::vector<SourcePos> &ep, const llvm::SmallVector<SourcePos, 8> &ep,
bool ic, Variability v, SourcePos p) bool ic, Variability v, SourcePos p)
: CollectionType(STRUCT_TYPE), name(n), elementTypes(elts), elementNames(en), : CollectionType(STRUCT_TYPE), name(n), elementTypes(elts), elementNames(en),
elementPositions(ep), variability(v), isConst(ic), pos(p) { elementPositions(ep), variability(v), isConst(ic), pos(p) {
@@ -2590,22 +2590,22 @@ ReferenceType::GetDIType(llvm::DIDescriptor scope) const {
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// FunctionType // FunctionType
FunctionType::FunctionType(const Type *r, const std::vector<const Type *> &a, FunctionType::FunctionType(const Type *r, const llvm::SmallVector<const Type *, 8> &a,
SourcePos p) SourcePos p)
: Type(FUNCTION_TYPE), isTask(false), isExported(false), isExternC(false), : Type(FUNCTION_TYPE), isTask(false), isExported(false), isExternC(false),
returnType(r), paramTypes(a), paramNames(std::vector<std::string>(a.size(), "")), returnType(r), paramTypes(a), paramNames(llvm::SmallVector<std::string, 8>(a.size(), "")),
paramDefaults(std::vector<Expr *>(a.size(), NULL)), paramDefaults(llvm::SmallVector<Expr *, 8>(a.size(), NULL)),
paramPositions(std::vector<SourcePos>(a.size(), p)) { paramPositions(llvm::SmallVector<SourcePos, 8>(a.size(), p)) {
Assert(returnType != NULL); Assert(returnType != NULL);
isSafe = false; isSafe = false;
costOverride = -1; costOverride = -1;
} }
FunctionType::FunctionType(const Type *r, const std::vector<const Type *> &a, FunctionType::FunctionType(const Type *r, const llvm::SmallVector<const Type *, 8> &a,
const std::vector<std::string> &an, const llvm::SmallVector<std::string, 8> &an,
const std::vector<Expr *> &ad, const llvm::SmallVector<Expr *, 8> &ad,
const std::vector<SourcePos> &ap, const llvm::SmallVector<SourcePos, 8> &ap,
bool it, bool is, bool ec) bool it, bool is, bool ec)
: Type(FUNCTION_TYPE), isTask(it), isExported(is), isExternC(ec), returnType(r), : Type(FUNCTION_TYPE), isTask(it), isExported(is), isExternC(ec), returnType(r),
paramTypes(a), paramNames(an), paramDefaults(ad), paramPositions(ap) { paramTypes(a), paramNames(an), paramDefaults(ad), paramPositions(ap) {
@@ -2697,7 +2697,7 @@ FunctionType::ResolveUnboundVariability(Variability v) const {
} }
const Type *rt = returnType->ResolveUnboundVariability(v); const Type *rt = returnType->ResolveUnboundVariability(v);
std::vector<const Type *> pt; llvm::SmallVector<const Type *, 8> pt;
for (unsigned int i = 0; i < paramTypes.size(); ++i) { for (unsigned int i = 0; i < paramTypes.size(); ++i) {
if (paramTypes[i] == NULL) { if (paramTypes[i] == NULL) {
Assert(m->errorCount > 0); Assert(m->errorCount > 0);

33
type.h
View File

@@ -42,6 +42,7 @@
#include "util.h" #include "util.h"
#include <llvm/Type.h> #include <llvm/Type.h>
#include <llvm/DerivedTypes.h> #include <llvm/DerivedTypes.h>
#include <llvm/ADT/SmallVector.h>
class ConstExpr; class ConstExpr;
class StructType; class StructType;
@@ -642,9 +643,9 @@ private:
*/ */
class StructType : public CollectionType { class StructType : public CollectionType {
public: public:
StructType(const std::string &name, const std::vector<const Type *> &elts, StructType(const std::string &name, const llvm::SmallVector<const Type *, 8> &elts,
const std::vector<std::string> &eltNames, const llvm::SmallVector<std::string, 8> &eltNames,
const std::vector<SourcePos> &eltPositions, bool isConst, const llvm::SmallVector<SourcePos, 8> &eltPositions, bool isConst,
Variability variability, SourcePos pos); Variability variability, SourcePos pos);
Variability GetVariability() const; Variability GetVariability() const;
@@ -709,16 +710,16 @@ private:
make a uniform version of the struct, we've maintained the original make a uniform version of the struct, we've maintained the original
information about the member types. information about the member types.
*/ */
const std::vector<const Type *> elementTypes; const llvm::SmallVector<const Type *, 8> elementTypes;
const std::vector<std::string> elementNames; const llvm::SmallVector<std::string, 8> elementNames;
/** Source file position at which each structure element declaration /** Source file position at which each structure element declaration
appeared. */ appeared. */
const std::vector<SourcePos> elementPositions; const llvm::SmallVector<SourcePos, 8> elementPositions;
const Variability variability; const Variability variability;
const bool isConst; const bool isConst;
const SourcePos pos; const SourcePos pos;
mutable std::vector<const Type *> finalElementTypes; mutable llvm::SmallVector<const Type *, 8> finalElementTypes;
mutable const StructType *oppositeConstStructType; mutable const StructType *oppositeConstStructType;
}; };
@@ -822,12 +823,12 @@ private:
class FunctionType : public Type { class FunctionType : public Type {
public: public:
FunctionType(const Type *returnType, FunctionType(const Type *returnType,
const std::vector<const Type *> &argTypes, SourcePos pos); const llvm::SmallVector<const Type *, 8> &argTypes, SourcePos pos);
FunctionType(const Type *returnType, FunctionType(const Type *returnType,
const std::vector<const Type *> &argTypes, const llvm::SmallVector<const Type *, 8> &argTypes,
const std::vector<std::string> &argNames, const llvm::SmallVector<std::string, 8> &argNames,
const std::vector<Expr *> &argDefaults, const llvm::SmallVector<Expr *, 8> &argDefaults,
const std::vector<SourcePos> &argPos, const llvm::SmallVector<SourcePos, 8> &argPos,
bool isTask, bool isExported, bool isExternC); bool isTask, bool isExported, bool isExternC);
Variability GetVariability() const; Variability GetVariability() const;
@@ -897,16 +898,16 @@ private:
// The following four vectors should all have the same length (which is // The following four vectors should all have the same length (which is
// in turn the length returned by GetNumParameters()). // in turn the length returned by GetNumParameters()).
const std::vector<const Type *> paramTypes; const llvm::SmallVector<const Type *, 8> paramTypes;
const std::vector<std::string> paramNames; const llvm::SmallVector<std::string, 8> paramNames;
/** Default values of the function's arguments. For arguments without /** Default values of the function's arguments. For arguments without
default values provided, NULL is stored. */ default values provided, NULL is stored. */
mutable std::vector<Expr *> paramDefaults; mutable llvm::SmallVector<Expr *, 8> paramDefaults;
/** The names provided (if any) with the function arguments in the /** The names provided (if any) with the function arguments in the
function's signature. These should only be used for error messages function's signature. These should only be used for error messages
and the like and so not affect testing function types for equality, and the like and so not affect testing function types for equality,
etc. */ etc. */
const std::vector<SourcePos> paramPositions; const llvm::SmallVector<SourcePos, 8> paramPositions;
}; };