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

View File

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

7
decl.h
View File

@@ -55,6 +55,7 @@
#define ISPC_DECL_H
#include "ispc.h"
#include <llvm/ADT/SmallVector.h>
struct VariableDeclaration;
@@ -219,8 +220,8 @@ struct StructDeclaration {
/** Given a set of StructDeclaration instances, this returns the types of
the elements of the corresponding struct and their names. */
extern void GetStructTypesNamesPositions(const std::vector<StructDeclaration *> &sd,
std::vector<const Type *> *elementTypes,
std::vector<std::string> *elementNames,
std::vector<SourcePos> *elementPositions);
llvm::SmallVector<const Type *, 8> *elementTypes,
llvm::SmallVector<std::string, 8> *elementNames,
llvm::SmallVector<SourcePos, 8> *elementPositions);
#endif // ISPC_DECL_H

View File

@@ -853,9 +853,9 @@ struct_or_union_specifier
: struct_or_union struct_or_union_name '{' struct_declaration_list '}'
{
if ($4 != NULL) {
std::vector<const Type *> elementTypes;
std::vector<std::string> elementNames;
std::vector<SourcePos> elementPositions;
llvm::SmallVector<const Type *, 8> elementTypes;
llvm::SmallVector<std::string, 8> elementNames;
llvm::SmallVector<SourcePos, 8> elementPositions;
GetStructTypesNamesPositions(*$4, &elementTypes, &elementNames,
&elementPositions);
StructType *st = new StructType($2, elementTypes, elementNames,
@@ -869,9 +869,9 @@ struct_or_union_specifier
| struct_or_union '{' struct_declaration_list '}'
{
if ($3 != NULL) {
std::vector<const Type *> elementTypes;
std::vector<std::string> elementNames;
std::vector<SourcePos> elementPositions;
llvm::SmallVector<const Type *, 8> elementTypes;
llvm::SmallVector<std::string, 8> elementNames;
llvm::SmallVector<SourcePos, 8> elementPositions;
GetStructTypesNamesPositions(*$3, &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,
const std::vector<std::string> &en,
const std::vector<SourcePos> &ep,
StructType::StructType(const std::string &n, const llvm::SmallVector<const Type *, 8> &elts,
const llvm::SmallVector<std::string, 8> &en,
const llvm::SmallVector<SourcePos, 8> &ep,
bool ic, Variability v, SourcePos p)
: CollectionType(STRUCT_TYPE), name(n), elementTypes(elts), elementNames(en),
elementPositions(ep), variability(v), isConst(ic), pos(p) {
@@ -2590,22 +2590,22 @@ ReferenceType::GetDIType(llvm::DIDescriptor scope) const {
///////////////////////////////////////////////////////////////////////////
// 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)
: Type(FUNCTION_TYPE), isTask(false), isExported(false), isExternC(false),
returnType(r), paramTypes(a), paramNames(std::vector<std::string>(a.size(), "")),
paramDefaults(std::vector<Expr *>(a.size(), NULL)),
paramPositions(std::vector<SourcePos>(a.size(), p)) {
returnType(r), paramTypes(a), paramNames(llvm::SmallVector<std::string, 8>(a.size(), "")),
paramDefaults(llvm::SmallVector<Expr *, 8>(a.size(), NULL)),
paramPositions(llvm::SmallVector<SourcePos, 8>(a.size(), p)) {
Assert(returnType != NULL);
isSafe = false;
costOverride = -1;
}
FunctionType::FunctionType(const Type *r, const std::vector<const Type *> &a,
const std::vector<std::string> &an,
const std::vector<Expr *> &ad,
const std::vector<SourcePos> &ap,
FunctionType::FunctionType(const Type *r, const llvm::SmallVector<const Type *, 8> &a,
const llvm::SmallVector<std::string, 8> &an,
const llvm::SmallVector<Expr *, 8> &ad,
const llvm::SmallVector<SourcePos, 8> &ap,
bool it, bool is, bool ec)
: Type(FUNCTION_TYPE), isTask(it), isExported(is), isExternC(ec), returnType(r),
paramTypes(a), paramNames(an), paramDefaults(ad), paramPositions(ap) {
@@ -2697,7 +2697,7 @@ FunctionType::ResolveUnboundVariability(Variability v) const {
}
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) {
if (paramTypes[i] == NULL) {
Assert(m->errorCount > 0);

33
type.h
View File

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