More changes to std::vector usage.

Replace with std::vector with static array, llvm::SmallVector or
add code to reserve space.
This commit is contained in:
kai 2013-03-17 22:05:04 +01:00
parent bc09ceae18
commit 7d65a311b1
9 changed files with 70 additions and 76 deletions

View file

@ -143,39 +143,28 @@ LLCallSite IRState::CreateCallOrInvoke(LLValue* Callee, const char* Name)
LLCallSite IRState::CreateCallOrInvoke(LLValue* Callee, LLValue* Arg1, const char* Name)
{
LLSmallVector<LLValue*, 1> args;
args.push_back(Arg1);
LLValue* args[] = { Arg1 };
return CreateCallOrInvoke(Callee, args, Name);
}
LLCallSite IRState::CreateCallOrInvoke2(LLValue* Callee, LLValue* Arg1, LLValue* Arg2, const char* Name)
{
LLSmallVector<LLValue*, 2> args;
args.push_back(Arg1);
args.push_back(Arg2);
LLValue* args[] = { Arg1, Arg2 };
return CreateCallOrInvoke(Callee, args, Name);
}
LLCallSite IRState::CreateCallOrInvoke3(LLValue* Callee, LLValue* Arg1, LLValue* Arg2, LLValue* Arg3, const char* Name)
{
LLSmallVector<LLValue*, 3> args;
args.push_back(Arg1);
args.push_back(Arg2);
args.push_back(Arg3);
LLValue* args[] = { Arg1, Arg2, Arg3 };
return CreateCallOrInvoke(Callee, args, Name);
}
LLCallSite IRState::CreateCallOrInvoke4(LLValue* Callee, LLValue* Arg1, LLValue* Arg2, LLValue* Arg3, LLValue* Arg4, const char* Name)
{
LLSmallVector<LLValue*, 4> args;
args.push_back(Arg1);
args.push_back(Arg2);
args.push_back(Arg3);
args.push_back(Arg4);
LLValue* args[] = { Arg1, Arg2, Arg3, Arg4 };
return CreateCallOrInvoke(Callee, args, Name);
}
//////////////////////////////////////////////////////////////////////////////////////////
IRBuilder<>* IRBuilderHelper::operator->()

View file

@ -59,8 +59,7 @@ void DtoDeleteMemory(LLValue* ptr)
// get runtime function
llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_delmemory");
// build args
LLSmallVector<LLValue*,1> arg;
arg.push_back(DtoBitCast(ptr, getVoidPtrType(), ".tmp"));
LLValue* arg[] = { DtoBitCast(ptr, getVoidPtrType(), ".tmp") };
// call
gIR->CreateCallOrInvoke(fn, arg);
}
@ -69,13 +68,14 @@ void DtoDeleteClass(LLValue* inst)
{
// get runtime function
llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_delclass");
// build args
LLSmallVector<LLValue*,1> arg;
// druntime wants a pointer to object
LLValue *ptr = DtoRawAlloca(inst->getType(), 0, "objectPtr");
DtoStore(inst, ptr);
inst = ptr;
arg.push_back(DtoBitCast(inst, fn->getFunctionType()->getParamType(0), ".tmp"));
// build args
LLValue* arg[] = {
DtoBitCast(inst, fn->getFunctionType()->getParamType(0), ".tmp")
};
// call
gIR->CreateCallOrInvoke(fn, arg);
}
@ -85,8 +85,9 @@ void DtoDeleteInterface(LLValue* inst)
// get runtime function
llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_delinterface");
// build args
LLSmallVector<LLValue*,1> arg;
arg.push_back(DtoBitCast(inst, fn->getFunctionType()->getParamType(0), ".tmp"));
LLValue* arg[] = {
DtoBitCast(inst, fn->getFunctionType()->getParamType(0), ".tmp")
};
// call
gIR->CreateCallOrInvoke(fn, arg);
}
@ -97,9 +98,10 @@ void DtoDeleteArray(DValue* arr)
llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_delarray_t");
// build args
LLSmallVector<LLValue*,2> arg;
arg.push_back(DtoBitCast(arr->getLVal(), fn->getFunctionType()->getParamType(0)));
arg.push_back(DtoBitCast(DtoTypeInfoOf(arr->type->nextOf()), fn->getFunctionType()->getParamType(1)));
LLValue* arg[] = {
DtoBitCast(arr->getLVal(), fn->getFunctionType()->getParamType(0)),
DtoBitCast(DtoTypeInfoOf(arr->type->nextOf()), fn->getFunctionType()->getParamType(1))
};
// call
gIR->CreateCallOrInvoke(fn, arg);
@ -155,12 +157,13 @@ LLValue* DtoGcMalloc(LLType* lltype, const char* name)
void DtoAssert(Module* M, Loc loc, DValue* msg)
{
std::vector<LLValue*> args;
// func
const char* fname = msg ? "_d_assert_msg" : "_d_assert";
llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, fname);
// Arguments
llvm::SmallVector<LLValue*, 3> args;
// msg param
if (msg)
{
@ -182,8 +185,7 @@ void DtoAssert(Module* M, Loc loc, DValue* msg)
}
// line param
LLConstant* c = DtoConstUint(loc.linnum);
args.push_back(c);
args.push_back(DtoConstUint(loc.linnum));
// call
gIR->CreateCallOrInvoke(fn, args);

View file

@ -172,10 +172,11 @@ static LLFunction* build_module_reference_and_ctor(LLConstant* moduleinfo)
// provide the default initializer
LLStructType* modulerefTy = DtoModuleReferenceType();
std::vector<LLConstant*> mrefvalues;
mrefvalues.push_back(LLConstant::getNullValue(modulerefTy->getContainedType(0)));
mrefvalues.push_back(llvm::ConstantExpr::getBitCast(moduleinfo, modulerefTy->getContainedType(1)));
LLConstant* thismrefinit = LLConstantStruct::get(modulerefTy, mrefvalues);
LLConstant* mrefvalues[] = {
LLConstant::getNullValue(modulerefTy->getContainedType(0)),
llvm::ConstantExpr::getBitCast(moduleinfo, modulerefTy->getContainedType(1))
};
LLConstant* thismrefinit = LLConstantStruct::get(modulerefTy, llvm::ArrayRef<LLConstant*>(mrefvalues));
// create the ModuleReference node for this module
std::string thismrefname = "_D";

View file

@ -165,8 +165,10 @@ void RTTIBuilder::finalize(LLType* type, LLValue* value)
// set struct body
if (st->isOpaque()) {
const int n = inits.size();
std::vector<LLType*> types;
for (int i = 0, n = inits.size(); i < n; ++i)
types.reserve(n);
for (int i = 0; i < n; ++i)
types.push_back(inits[i]->getType());
st->setBody(types);
}

View file

@ -938,7 +938,7 @@ void SwitchStatement::toIR(IRState* p)
// first sort it
caseArray.sort();
// iterate and add indices to cases
std::vector<LLConstant*> inits(caseArray.dim);
std::vector<LLConstant*> inits(caseArray.dim, 0);
for (size_t i=0; i<caseArray.dim; ++i)
{
Case* c = static_cast<Case*>(caseArray.data[i]);
@ -956,14 +956,10 @@ void SwitchStatement::toIR(IRState* p)
LLConstant* arrPtr = llvm::ConstantExpr::getBitCast(arr, elemPtrTy);
// build the static table
std::vector<LLType*> types;
types.push_back(DtoSize_t());
types.push_back(elemPtrTy);
LLStructType* sTy = llvm::StructType::get(gIR->context(), types);
std::vector<LLConstant*> sinits;
sinits.push_back(DtoConstSize_t(inits.size()));
sinits.push_back(arrPtr);
switchTable = llvm::ConstantStruct::get(sTy, sinits);
LLType* types[] = { DtoSize_t(), elemPtrTy };
LLStructType* sTy = llvm::StructType::get(gIR->context(), types, false);
LLConstant* sinits[] = { DtoConstSize_t(inits.size()), arrPtr };
switchTable = llvm::ConstantStruct::get(sTy, llvm::ArrayRef<LLConstant*>(sinits));
}
// condition var
@ -1609,16 +1605,15 @@ void SwitchErrorStatement::toIR(IRState* p)
llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_switch_error");
std::vector<LLValue*> args;
// module param
LLValue *moduleInfoSymbol = gIR->func()->decl->getModule()->moduleInfoSymbol();
LLType *moduleInfoType = DtoType(Module::moduleinfo->type);
args.push_back(DtoBitCast(moduleInfoSymbol, getPtrToType(moduleInfoType)));
LLValue* args[] = {
// module param
DtoBitCast(moduleInfoSymbol, getPtrToType(moduleInfoType)),
// line param
LLConstant* c = DtoConstUint(loc.linnum);
args.push_back(c);
DtoConstUint(loc.linnum)
};
// call
LLCallSite call = gIR->CreateCallOrInvoke(fn, args);

View file

@ -328,6 +328,7 @@ LLType* DtoUnpaddedStructType(Type* dty) {
Array& fields = sty->sym->fields;
std::vector<LLType*> types;
types.reserve(fields.dim);
for (unsigned i = 0; i < fields.dim; i++) {
VarDeclaration* vd = static_cast<VarDeclaration*>(fields.data[i]);

View file

@ -259,6 +259,7 @@ void DtoBuildDVarArgList(std::vector<LLValue*>& args,
Logger::cout() << "_arguments storage: " << *typeinfomem << '\n';
std::vector<LLConstant*> vtypeinfos;
vtypeinfos.reserve(n_arguments);
for (size_t i=begin; i<n_arguments; i++)
{
Expression* argexp = static_cast<Expression*>(arguments->data[i]);
@ -270,11 +271,12 @@ void DtoBuildDVarArgList(std::vector<LLValue*>& args,
typeinfomem->setInitializer(tiinits);
// put data in d-array
std::vector<LLConstant*> pinits;
pinits.push_back(DtoConstSize_t(vtype->getNumElements()));
pinits.push_back(llvm::ConstantExpr::getBitCast(typeinfomem, getPtrToType(typeinfotype)));
LLConstant* pinits[] = {
DtoConstSize_t(vtype->getNumElements()),
llvm::ConstantExpr::getBitCast(typeinfomem, getPtrToType(typeinfotype))
};
LLType* tiarrty = DtoType(Type::typeinfo->type->arrayOf());
tiinits = LLConstantStruct::get(isaStruct(tiarrty), pinits);
tiinits = LLConstantStruct::get(isaStruct(tiarrty), llvm::ArrayRef<LLConstant*>(pinits));
LLValue* typeinfoarrayparam = new llvm::GlobalVariable(*gIR->module, tiarrty,
true, llvm::GlobalValue::InternalLinkage, tiinits, "._arguments.array");
@ -507,6 +509,7 @@ DValue* DtoCallFunction(Loc& loc, Type* resulttype, DValue* fnval, Expressions*
size_t n = Parameter::dim(tf->parameters);
std::vector<DValue*> argvals;
argvals.reserve(n);
if (dfnval && dfnval->func->isArrayOp) {
// slightly different approach for array operators
for (int i=n-1; i>=0; --i) {

View file

@ -216,16 +216,6 @@ static llvm::DIType dwarfCompositeType(Type* type)
LLType* T = DtoType(type);
Type* t = type->toBasetype();
// defaults
llvm::StringRef name;
unsigned linnum = 0;
llvm::DIFile file;
// elements
std::vector<llvm::Value*> elems;
llvm::DIType derivedFrom;
assert((t->ty == Tstruct || t->ty == Tclass) &&
"unsupported type for dwarfCompositeType");
AggregateDeclaration* sd;
@ -254,9 +244,15 @@ static llvm::DIType dwarfCompositeType(Type* type)
if (static_cast<llvm::MDNode*>(ir->diCompositeType) != 0)
return ir->diCompositeType;
name = sd->toChars();
linnum = sd->loc.linnum;
file = DtoDwarfFile(sd->loc);
// elements
std::vector<llvm::Value*> elems;
// defaults
llvm::StringRef name = sd->toChars();
unsigned linnum = sd->loc.linnum;
llvm::DIFile file = DtoDwarfFile(sd->loc);
llvm::DIType derivedFrom;
// set diCompositeType to handle recursive types properly
if (!ir->diCompositeType)
ir->diCompositeType = gIR->dibuilder.createTemporaryType();

View file

@ -1950,9 +1950,10 @@ DValue* NewExp::toElem(IRState* p)
else
{
size_t ndims = arguments->dim;
std::vector<DValue*> dims(ndims);
std::vector<DValue*> dims;
dims.reserve(ndims);
for (size_t i=0; i<ndims; ++i)
dims[i] = static_cast<Expression*>(arguments->data[i])->toElem(p);
dims.push_back(static_cast<Expression*>(arguments->data[i])->toElem(p));
return DtoNewMulDimDynArray(loc, newtype, &dims[0], ndims, true);
}
}
@ -2798,11 +2799,12 @@ LLConstant* ArrayLiteralExp::toConstElem(IRState* p)
bool dyn = (bt->ty != Tsarray);
// build the initializer
std::vector<LLConstant*> vals(elements->dim, NULL);
std::vector<LLConstant*> vals;
vals.reserve(elements->dim);
for (unsigned i=0; i<elements->dim; ++i)
{
Expression* expr = static_cast<Expression*>(elements->data[i]);
vals[i] = expr->toConstElem(p);
vals.push_back(expr->toConstElem(p));
}
// build the constant array initialize
@ -2974,7 +2976,7 @@ LLConstant* StructLiteralExp::toConstElem(IRState* p)
sd->codegen(Type::sir);
// get inits
std::vector<LLConstant*> inits(sd->fields.dim, NULL);
std::vector<LLConstant*> inits(sd->fields.dim, 0);
size_t nexprs = elements->dim;;
Expression** exprs = (Expression**)elements->data;
@ -2987,8 +2989,8 @@ LLConstant* StructLiteralExp::toConstElem(IRState* p)
std::vector<LLConstant*> values = DtoStructLiteralValues(sd, inits);
// we know those values are constants.. cast them
std::vector<LLConstant*> constvals(values.size(), NULL);
std::vector<LLType*> types(values.size(), NULL);
std::vector<LLConstant*> constvals(values.size(), 0);
std::vector<LLType*> types(values.size(), 0);
for (size_t i = 0; i < values.size(); ++i) {
constvals[i] = llvm::cast<LLConstant>(values[i]);
types[i] = values[i]->getType();
@ -3059,6 +3061,8 @@ DValue* AssocArrayLiteralExp::toElem(IRState* p)
{
std::vector<LLConstant*> keysInits, valuesInits;
keysInits.reserve(keys->dim);
valuesInits.reserve(keys->dim);
for (size_t i = 0, n = keys->dim; i < n; ++i)
{
Expression* ekey = keys->tdata()[i];
@ -3178,11 +3182,12 @@ DValue* TypeExp::toElem(IRState *p)
DValue* TupleExp::toElem(IRState *p)
{
Logger::print("TupleExp::toElem() %s\n", toChars());
std::vector<LLType*> types(exps->dim, NULL);
std::vector<LLType*> types;
types.reserve(exps->dim);
for (size_t i = 0; i < exps->dim; i++)
{
Expression *el = static_cast<Expression *>(exps->data[i]);
types[i] = DtoTypeNotVoid(el->type);
types.push_back(DtoTypeNotVoid(el->type));
}
LLValue *val = DtoRawAlloca(LLStructType::get(gIR->context(), types),0, "tuple");
for (size_t i = 0; i < exps->dim; i++)