diff --git a/driver/ldmd.cpp b/driver/ldmd.cpp index b9dba8a2a4..f918d61a91 100644 --- a/driver/ldmd.cpp +++ b/driver/ldmd.cpp @@ -807,7 +807,7 @@ void buildCommandLine(std::vector& r, const Params& p) if (p.logTlsUse) warning("-vtls not yet supported by LDC."); if (p.warnings == Warnings::asErrors) r.push_back("-w"); else if (p.warnings == Warnings::informational) r.push_back("-wi"); - if (p.optimize) r.push_back("-O2"); + if (p.optimize) r.push_back("-O3"); if (p.noObj) r.push_back("-o-"); if (p.objDir) r.push_back(concat("-od=", p.objDir)); if (p.objName) r.push_back(concat("-of=", p.objName)); diff --git a/gen/aa.cpp b/gen/aa.cpp index 1f37061153..67e6a4d4be 100644 --- a/gen/aa.cpp +++ b/gen/aa.cpp @@ -93,16 +93,15 @@ DValue* DtoAAIndex(Loc& loc, Type* type, DValue* aa, DValue* key, bool lvalue) gIR->scope() = IRScope(failbb, okbb); - std::vector args; - - // module param LLValue *moduleInfoSymbol = gIR->func()->decl->getModule()->moduleInfoSymbol(); LLType *moduleInfoType = DtoType(Module::moduleinfo->type); - args.push_back(DtoBitCast(moduleInfoSymbol, getPtrToType(moduleInfoType))); - // line param - LLConstant* c = DtoConstUint(loc.linnum); - args.push_back(c); + LLValue* args[] = { + // module param + DtoBitCast(moduleInfoSymbol, getPtrToType(moduleInfoType)), + // line param + DtoConstUint(loc.linnum) + }; // call llvm::Function* errorfn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_array_bounds"); @@ -201,10 +200,7 @@ DValue *DtoAARemove(Loc& loc, DValue* aa, DValue* key) pkey = DtoBitCast(pkey, funcTy->getParamType(2)); // build arg vector - LLSmallVector args; - args.push_back(aaval); - args.push_back(keyti); - args.push_back(pkey); + LLValue* args[] = { aaval, keyti, pkey }; // call runtime LLCallSite call = gIR->CreateCallOrInvoke(func, args); diff --git a/gen/arrays.cpp b/gen/arrays.cpp index bbebb884d2..854ec97277 100644 --- a/gen/arrays.cpp +++ b/gen/arrays.cpp @@ -215,10 +215,11 @@ void DtoArrayAssign(DValue *array, DValue *value, int op) Type *elemType = t->nextOf()->toBasetype(); LLFunction* fn = LLVM_D_GetRuntimeFunction(gIR->module, op == TOKconstruct ? "_d_arrayctor" : "_d_arrayassign"); - LLSmallVector args; - args.push_back(DtoTypeInfoOf(elemType)); - args.push_back(DtoAggrPaint(DtoSlice(value), fn->getFunctionType()->getParamType(1))); - args.push_back(DtoAggrPaint(DtoSlice(array), fn->getFunctionType()->getParamType(2))); + LLValue* args[] = { + DtoTypeInfoOf(elemType), + DtoAggrPaint(DtoSlice(value), fn->getFunctionType()->getParamType(1)), + DtoAggrPaint(DtoSlice(array), fn->getFunctionType()->getParamType(2)) + }; LLCallSite call = gIR->CreateCallOrInvoke(fn, args, ".array"); call.setCallingConv(llvm::CallingConv::C); @@ -238,11 +239,12 @@ void DtoArraySetAssign(Loc &loc, DValue *array, DValue *value, int op) LLValue *len = DtoArrayLen(array); LLFunction* fn = LLVM_D_GetRuntimeFunction(gIR->module, op == TOKconstruct ? "_d_arraysetctor" : "_d_arraysetassign"); - LLSmallVector args; - args.push_back(DtoBitCast(ptr, getVoidPtrType())); - args.push_back(DtoBitCast(makeLValue(loc, value), getVoidPtrType())); - args.push_back(len); - args.push_back(DtoTypeInfoOf(array->type->toBasetype()->nextOf()->toBasetype())); + LLValue* args[] = { + DtoBitCast(ptr, getVoidPtrType()), + DtoBitCast(makeLValue(loc, value), getVoidPtrType()), + len, + DtoTypeInfoOf(array->type->toBasetype()->nextOf()->toBasetype()) + }; LLCallSite call = gIR->CreateCallOrInvoke(fn, args, ".newptr"); call.setCallingConv(llvm::CallingConv::C); @@ -614,6 +616,7 @@ DSliceValue* DtoNewMulDimDynArray(Loc& loc, Type* arrayType, DValue** dims, size LLFunction* fn = LLVM_D_GetRuntimeFunction(gIR->module, fnname); std::vector args; + args.reserve(ndims+2); args.push_back(arrayTypeInfo); args.push_back(DtoConstSize_t(ndims)); @@ -647,11 +650,11 @@ DSliceValue* DtoResizeDynArray(Type* arrayType, DValue* array, LLValue* newdim) // call runtime LLFunction* fn = LLVM_D_GetRuntimeFunction(gIR->module, zeroInit ? "_d_arraysetlengthT" : "_d_arraysetlengthiT" ); - LLSmallVector args; - args.push_back(DtoTypeInfoOf(arrayType)); - args.push_back(newdim); - - args.push_back(DtoBitCast(array->getLVal(), fn->getFunctionType()->getParamType(2))); + LLValue* args[] = { + DtoTypeInfoOf(arrayType), + newdim, + DtoBitCast(array->getLVal(), fn->getFunctionType()->getParamType(2)) + }; LLValue* newArray = gIR->CreateCallOrInvoke(fn, args, ".gc_mem").getInstruction(); return getSlice(arrayType, newArray); @@ -673,10 +676,11 @@ void DtoCatAssignElement(Loc& loc, Type* arrayType, DValue* array, Expression* e DValue *expVal = exp->toElem(gIR); LLFunction* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_arrayappendcTX"); - LLSmallVector args; - args.push_back(DtoTypeInfoOf(arrayType)); - args.push_back(DtoBitCast(array->getLVal(), fn->getFunctionType()->getParamType(1))); - args.push_back(DtoConstSize_t(1)); + LLValue* args[] = { + DtoTypeInfoOf(arrayType), + DtoBitCast(array->getLVal(), fn->getFunctionType()->getParamType(1)), + DtoConstSize_t(1) + }; LLValue* appendedArray = gIR->CreateCallOrInvoke(fn, args, ".appendedArray").getInstruction(); appendedArray = DtoAggrPaint(appendedArray, DtoType(arrayType)); @@ -772,11 +776,12 @@ DSliceValue* DtoAppendDChar(DValue* arr, Expression* exp, const char *func) // Prepare arguments LLFunction* fn = LLVM_D_GetRuntimeFunction(gIR->module, func); - LLSmallVector args; - // ref string x - args.push_back(DtoBitCast(arr->getLVal(), fn->getFunctionType()->getParamType(0))); - // dchar c - args.push_back(DtoBitCast(valueToAppend->getRVal(), fn->getFunctionType()->getParamType(1))); + LLValue* args[] = { + // ref string x + DtoBitCast(arr->getLVal(), fn->getFunctionType()->getParamType(0)), + // dchar c + DtoBitCast(valueToAppend->getRVal(), fn->getFunctionType()->getParamType(1)) + }; // Call function LLValue* newArray = gIR->CreateCallOrInvoke(fn, args, ".appendedArray").getInstruction(); @@ -818,16 +823,11 @@ static LLValue* DtoArrayEqCmp_impl(Loc& loc, const char* func, DValue* l, DValue l = DtoCastArray(loc, l, commonType); r = DtoCastArray(loc, r, commonType); - LLValue* lmem; - LLValue* rmem; LLSmallVector args; // get values, reinterpret cast to void[] - lmem = DtoAggrPaint(l->getRVal(), DtoArrayType(LLType::getInt8Ty(gIR->context()))); - args.push_back(lmem); - - rmem = DtoAggrPaint(r->getRVal(), DtoArrayType(LLType::getInt8Ty(gIR->context()))); - args.push_back(rmem); + args.push_back(DtoAggrPaint(l->getRVal(), DtoArrayType(LLType::getInt8Ty(gIR->context())))); + args.push_back(DtoAggrPaint(r->getRVal(), DtoArrayType(LLType::getInt8Ty(gIR->context())))); // pass array typeinfo ? if (useti) { @@ -896,10 +896,11 @@ LLValue* DtoArrayCastLength(LLValue* len, LLType* elemty, LLType* newelemty) if (esz == nsz) return len; - LLSmallVector args; - args.push_back(len); - args.push_back(LLConstantInt::get(DtoSize_t(), esz, false)); - args.push_back(LLConstantInt::get(DtoSize_t(), nsz, false)); + LLValue* args[] = { + len, + LLConstantInt::get(DtoSize_t(), esz, false), + LLConstantInt::get(DtoSize_t(), nsz, false) + }; LLFunction* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_array_cast_len"); return gIR->CreateCallOrInvoke(fn, args, "tmp").getInstruction(); diff --git a/gen/asm-x86.h b/gen/asm-x86.h index 43cfffc021..3f47850eb8 100644 --- a/gen/asm-x86.h +++ b/gen/asm-x86.h @@ -10,6 +10,12 @@ // Parses "DMD-style" x86/x86_64 inline assembly blocks and converts them to // GDC/LLVM inline assembler syntax. // +// This file is designed to be included twice, once with the ASM_X86_64 define +// set to get the 64 bit asm parser, and once without to get the 32 bit one. +// This is a direct result of merging two disparate but largely identical +// implementations, and should be refactored to just use a runtime parameter +// for choosing the architecture. +// //===----------------------------------------------------------------------===// #include "id.h" diff --git a/gen/asmstmt.cpp b/gen/asmstmt.cpp index 621a0665b5..d7260586ed 100644 --- a/gen/asmstmt.cpp +++ b/gen/asmstmt.cpp @@ -522,7 +522,6 @@ void AsmBlockStatement::toIR(IRState* p) { Logger::println("AsmBlockStatement::toIR(): %s", loc.toChars()); LOG_SCOPE; - Logger::println("BEGIN ASM"); // disable inlining by default if (!p->func()->decl->allowInlining) @@ -768,7 +767,6 @@ void AsmBlockStatement::toIR(IRState* p) } p->asmBlock = NULL; - Logger::println("END ASM"); // if asm contained external branches, emit goto forwarder code if(!gotoToVal.empty()) diff --git a/gen/classes.cpp b/gen/classes.cpp index 5a268b48de..1bd326d773 100644 --- a/gen/classes.cpp +++ b/gen/classes.cpp @@ -232,8 +232,9 @@ void DtoFinalizeClass(LLValue* inst) // get runtime function llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_callfinalizer"); // build args - LLSmallVector 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, ""); } @@ -369,8 +370,6 @@ DValue* DtoDynamicCastObject(DValue* val, Type* _to) llvm::Function* func = LLVM_D_GetRuntimeFunction(gIR->module, "_d_dynamic_cast"); LLFunctionType* funcTy = func->getFunctionType(); - std::vector args; - // Object o LLValue* obj = val->getRVal(); obj = DtoBitCast(obj, funcTy->getParamType(0)); @@ -434,8 +433,6 @@ DValue* DtoDynamicCastInterface(DValue* val, Type* _to) llvm::Function* func = LLVM_D_GetRuntimeFunction(gIR->module, "_d_interface_cast"); LLFunctionType* funcTy = func->getFunctionType(); - std::vector args; - // void* p LLValue* ptr = val->getRVal(); ptr = DtoBitCast(ptr, funcTy->getParamType(0)); diff --git a/gen/complex.cpp b/gen/complex.cpp index f8875945e3..94db9e6ecb 100644 --- a/gen/complex.cpp +++ b/gen/complex.cpp @@ -23,10 +23,8 @@ llvm::StructType* DtoComplexType(Type* type) { Type* t = type->toBasetype(); LLType* base = DtoComplexBaseType(t); - llvm::SmallVector types; - types.push_back(base); - types.push_back(base); - return llvm::StructType::get(gIR->context(), types); + LLType* types[] = { base, base }; + return llvm::StructType::get(gIR->context(), types, false); } LLType* DtoComplexBaseType(Type* t) @@ -62,11 +60,10 @@ LLConstant* DtoConstComplex(Type* _ty, longdouble re, longdouble im) case Tcomplex80: base = Type::tfloat80; break; } - std::vector inits; - inits.push_back(DtoConstFP(base, re)); - inits.push_back(DtoConstFP(base, im)); + LLConstant * inits[] = { DtoConstFP(base, re), DtoConstFP(base, im) }; - return llvm::ConstantStruct::get(DtoComplexType(_ty), inits); + return llvm::ConstantStruct::get(DtoComplexType(_ty), + llvm::ArrayRef(inits)); } ////////////////////////////////////////////////////////////////////////////////////////// diff --git a/gen/irstate.cpp b/gen/irstate.cpp index b81c9e1b59..442f1292b5 100644 --- a/gen/irstate.cpp +++ b/gen/irstate.cpp @@ -143,39 +143,28 @@ LLCallSite IRState::CreateCallOrInvoke(LLValue* Callee, const char* Name) LLCallSite IRState::CreateCallOrInvoke(LLValue* Callee, LLValue* Arg1, const char* Name) { - LLSmallVector 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 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 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 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->() diff --git a/gen/llvmhelpers.cpp b/gen/llvmhelpers.cpp index ae4905e64f..85736c3328 100644 --- a/gen/llvmhelpers.cpp +++ b/gen/llvmhelpers.cpp @@ -59,8 +59,7 @@ void DtoDeleteMemory(LLValue* ptr) // get runtime function llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_delmemory"); // build args - LLSmallVector 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 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 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 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 args; - // func const char* fname = msg ? "_d_assert_msg" : "_d_assert"; llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, fname); + // Arguments + llvm::SmallVector 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); diff --git a/gen/module.cpp b/gen/module.cpp index 6788b448b8..fbbc4204f7 100644 --- a/gen/module.cpp +++ b/gen/module.cpp @@ -172,10 +172,11 @@ static LLFunction* build_module_reference_and_ctor(LLConstant* moduleinfo) // provide the default initializer LLStructType* modulerefTy = DtoModuleReferenceType(); - std::vector 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(mrefvalues)); // create the ModuleReference node for this module std::string thismrefname = "_D"; diff --git a/gen/optimizer.cpp b/gen/optimizer.cpp index fe01ff49ef..c2f1598dbf 100644 --- a/gen/optimizer.cpp +++ b/gen/optimizer.cpp @@ -47,7 +47,7 @@ static cl::opt optimizeLevel( cl::desc("Setting the optimization level:"), cl::ZeroOrMore, cl::values( - clEnumValN(2, "O", "Equivalent to -O2"), + clEnumValN(3, "O", "Equivalent to -O3"), clEnumValN(0, "O0", "No optimizations (default)"), clEnumValN(1, "O1", "Simple optimizations"), clEnumValN(2, "O2", "Good optimizations"), diff --git a/gen/rttibuilder.cpp b/gen/rttibuilder.cpp index 7e327645ed..cd12c7cb31 100644 --- a/gen/rttibuilder.cpp +++ b/gen/rttibuilder.cpp @@ -165,8 +165,10 @@ void RTTIBuilder::finalize(LLType* type, LLValue* value) // set struct body if (st->isOpaque()) { + const int n = inits.size(); std::vector 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); } diff --git a/gen/statements.cpp b/gen/statements.cpp index f6f6135561..96f7620eb3 100644 --- a/gen/statements.cpp +++ b/gen/statements.cpp @@ -938,7 +938,7 @@ void SwitchStatement::toIR(IRState* p) // first sort it caseArray.sort(); // iterate and add indices to cases - std::vector inits(caseArray.dim); + std::vector inits(caseArray.dim, 0); for (size_t i=0; i(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 types; - types.push_back(DtoSize_t()); - types.push_back(elemPtrTy); - LLStructType* sTy = llvm::StructType::get(gIR->context(), types); - std::vector 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(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 args; - - // module param LLValue *moduleInfoSymbol = gIR->func()->decl->getModule()->moduleInfoSymbol(); LLType *moduleInfoType = DtoType(Module::moduleinfo->type); - args.push_back(DtoBitCast(moduleInfoSymbol, getPtrToType(moduleInfoType))); - // line param - LLConstant* c = DtoConstUint(loc.linnum); - args.push_back(c); + LLValue* args[] = { + // module param + DtoBitCast(moduleInfoSymbol, getPtrToType(moduleInfoType)), + // line param + DtoConstUint(loc.linnum) + }; // call LLCallSite call = gIR->CreateCallOrInvoke(fn, args); diff --git a/gen/structs.cpp b/gen/structs.cpp index efa173100b..3835022f65 100644 --- a/gen/structs.cpp +++ b/gen/structs.cpp @@ -328,6 +328,7 @@ LLType* DtoUnpaddedStructType(Type* dty) { Array& fields = sty->sym->fields; std::vector types; + types.reserve(fields.dim); for (unsigned i = 0; i < fields.dim; i++) { VarDeclaration* vd = static_cast(fields.data[i]); diff --git a/gen/tocall.cpp b/gen/tocall.cpp index c6e2ea8219..9ade207f02 100644 --- a/gen/tocall.cpp +++ b/gen/tocall.cpp @@ -259,6 +259,7 @@ void DtoBuildDVarArgList(std::vector& args, Logger::cout() << "_arguments storage: " << *typeinfomem << '\n'; std::vector vtypeinfos; + vtypeinfos.reserve(n_arguments); for (size_t i=begin; i(arguments->data[i]); @@ -270,11 +271,12 @@ void DtoBuildDVarArgList(std::vector& args, typeinfomem->setInitializer(tiinits); // put data in d-array - std::vector 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(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 argvals; + argvals.reserve(n); if (dfnval && dfnval->func->isArrayOp) { // slightly different approach for array operators for (int i=n-1; i>=0; --i) { diff --git a/gen/todebug.cpp b/gen/todebug.cpp index 6792c7b2c2..0ca88df66c 100644 --- a/gen/todebug.cpp +++ b/gen/todebug.cpp @@ -84,28 +84,56 @@ static llvm::DIType dwarfBasicType(Type* type) LLType* T = DtoType(type); // find encoding - unsigned id; - if (t->isintegral()) + unsigned Encoding; + switch (t->ty) { - if (type->isunsigned()) - id = DW_ATE_unsigned; - else - id = DW_ATE_signed; - } - else if (t->isfloating()) - { - id = DW_ATE_float; - } - else - { - llvm_unreachable("unsupported basic type for debug info"); + case Tbool: + Encoding = DW_ATE_boolean; + break; + case Tchar: + case Twchar: + case Tdchar: + Encoding = type->isunsigned() ? DW_ATE_unsigned_char + : DW_ATE_signed_char; + break; + case Tint8: + case Tint16: + case Tint32: + case Tint64: + case Tint128: + Encoding = DW_ATE_signed; + break; + case Tuns8: + case Tuns16: + case Tuns32: + case Tuns64: + case Tuns128: + Encoding = DW_ATE_unsigned; + break; + case Tfloat32: + case Tfloat64: + case Tfloat80: + Encoding = DW_ATE_float; + break; + case Timaginary32: + case Timaginary64: + case Timaginary80: + Encoding = DW_ATE_imaginary_float; + break; + case Tcomplex32: + case Tcomplex64: + case Tcomplex80: + Encoding = DW_ATE_complex_float; + break; + default: + llvm_unreachable("Unsupported basic type for debug info"); } return gIR->dibuilder.createBasicType( type->toChars(), // name getTypeBitSize(T), // size (bits) getABITypeAlign(T)*8, // align (bits) - id + Encoding ); } @@ -188,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 elems; - - llvm::DIType derivedFrom; - assert((t->ty == Tstruct || t->ty == Tclass) && "unsupported type for dwarfCompositeType"); AggregateDeclaration* sd; @@ -226,12 +244,29 @@ static llvm::DIType dwarfCompositeType(Type* type) if (static_cast(ir->diCompositeType) != 0) return ir->diCompositeType; - name = sd->toChars(); - linnum = sd->loc.linnum; - file = DtoDwarfFile(sd->loc); + // elements + std::vector 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) + if (!ir->diCompositeType) { +#if LDC_LLVM_VER >= 301 + unsigned tag = (t->ty == Tstruct) ? llvm::dwarf::DW_TAG_structure_type + : llvm::dwarf::DW_TAG_class_type; + ir->diCompositeType = gIR->dibuilder.createForwardDecl(tag, name, +#if LDC_LLVM_VER >= 302 + llvm::DIDescriptor(file), +#endif + file, linnum); +#else ir->diCompositeType = gIR->dibuilder.createTemporaryType(); +#endif + } if (!ir->aggrdecl->isInterfaceDeclaration()) // plain interfaces don't have one { @@ -301,7 +336,10 @@ static llvm::DIGlobalVariable dwarfGlobalVariable(LLGlobalVariable* ll, VarDecla assert(vd->isDataseg() || (vd->storage_class & (STCconst | STCimmutable) && vd->init)); return gIR->dibuilder.createGlobalVariable( - vd->toChars(), // name TODO: mangle() or toPrettyChars() instead? + vd->toChars(), // name +#if LDC_LLVM_VER >= 303 + vd->mangle(), // linkage name +#endif DtoDwarfFile(vd->loc), // file vd->loc.linnum, // line num dwarfTypeDescription_impl(vd->type, NULL), // type @@ -328,9 +366,11 @@ static llvm::DIType dwarfArrayType(Type* type) { llvm::DIFile file = DtoDwarfFile(Loc(gIR->dmodule, 0)); - std::vector elems; - elems.push_back(dwarfMemberType(0, Type::tsize_t, file, "length", 0)); - elems.push_back(dwarfMemberType(0, t->nextOf()->pointerTo(), file, "ptr", global.params.is64bit?8:4)); + llvm::Value* elems[] = { + dwarfMemberType(0, Type::tsize_t, file, "length", 0), + dwarfMemberType(0, t->nextOf()->pointerTo(), file, "ptr", + global.params.is64bit ? 8 : 4) + }; return gIR->dibuilder.createStructType ( @@ -475,17 +515,26 @@ llvm::DISubprogram DtoDwarfSubProgram(FuncDeclaration* fd) Logger::println("D to dwarf subprogram"); LOG_SCOPE; + llvm::DICompileUnit CU(gIR->dibuilder.getCU()); + assert(CU && CU.Verify() && "Compilation unit missing or corrupted"); + llvm::DIFile file = DtoDwarfFile(fd->loc); Type *retType = static_cast(fd->type)->next; + // Create "dummy" subroutine type for the return type + llvm::SmallVector Elts; + Elts.push_back(dwarfTypeDescription(retType, NULL)); + llvm::DIArray EltTypeArray = gIR->dibuilder.getOrCreateArray(Elts); + llvm::DIType DIFnType = gIR->dibuilder.createSubroutineType(file, EltTypeArray); + // FIXME: duplicates ? return gIR->dibuilder.createFunction( - llvm::DICompileUnit(file), // context + CU, // context fd->toPrettyChars(), // name fd->mangle(), // linkage name file, // file fd->loc.linnum, // line no - dwarfTypeDescription(retType, NULL), // type + DIFnType, // type fd->protection == PROTprivate, // is local to unit gIR->dmodule == getDefinedModule(fd), // isdefinition #if LDC_LLVM_VER >= 301 @@ -509,6 +558,12 @@ llvm::DISubprogram DtoDwarfSubProgramInternal(const char* prettyname, const char llvm::DIFile file(DtoDwarfFile(Loc(gIR->dmodule, 0))); + // Create "dummy" subroutine type for the return type + llvm::SmallVector Elts; + Elts.push_back(llvm::DIType(NULL)); + llvm::DIArray EltTypeArray = gIR->dibuilder.getOrCreateArray(Elts); + llvm::DIType DIFnType = gIR->dibuilder.createSubroutineType(file, EltTypeArray); + // FIXME: duplicates ? return gIR->dibuilder.createFunction( llvm::DIDescriptor(file), // context @@ -516,7 +571,7 @@ llvm::DISubprogram DtoDwarfSubProgramInternal(const char* prettyname, const char mangledname, // linkage name file, // file 0, // line no - llvm::DIType(NULL), // return type. TODO: fill it up + DIFnType, // return type. TODO: fill it up true, // is local to unit true // isdefinition #if LDC_LLVM_VER >= 301 diff --git a/gen/todebug.h b/gen/todebug.h index 94468aaa21..822f97f6cf 100644 --- a/gen/todebug.h +++ b/gen/todebug.h @@ -17,27 +17,22 @@ #include "gen/irstate.h" #include "gen/tollvm.h" -void RegisterDwarfSymbols(llvm::Module* mod); -/** - * Emit the Dwarf compile_unit global for a Module m. - * @param m - */ +/// \brief Emit the Dwarf compile_unit global for a Module m. +/// \param m Module to emit as compile unit. void DtoDwarfCompileUnit(Module* m); -/** - * Emit the Dwarf subprogram global for a function declaration fd. - * @param fd - * @return the Dwarf subprogram global. - */ +/// \brief Emit the Dwarf subprogram global for a function declaration fd. +/// \param fd Function declaration to emit as subprogram. +/// \returns the Dwarf subprogram global. llvm::DISubprogram DtoDwarfSubProgram(FuncDeclaration* fd); -/** - * Emit the Dwarf subprogram global for a internal function. - * This is used for generated functions like moduleinfoctors, - * module ctors/dtors and unittests. - * @return the Dwarf subprogram global. - */ +/// \brief Emit the Dwarf subprogram global for a internal function. +/// This is used for generated functions like moduleinfoctors, +/// module ctors/dtors and unittests. +/// \param prettyname The name as seen in the source. +/// \param mangledname The mangled name in the object file. +/// \returns the Dwarf subprogram global. llvm::DISubprogram DtoDwarfSubProgramInternal(const char* prettyname, const char* mangledname); void DtoDwarfFuncStart(FuncDeclaration* fd); @@ -49,20 +44,17 @@ void DtoDwarfStopPoint(unsigned ln); void DtoDwarfValue(LLValue *val, VarDeclaration* vd); -/** - * Emits all things necessary for making debug info for a local variable vd. - * @param ll LLVM Value of the variable. - * @param vd Variable declaration to emit debug info for. - */ +/// \brief Emits all things necessary for making debug info for a local variable vd. +/// \param ll LLVM Value of the variable. +/// \param vd Variable declaration to emit debug info for. +/// \param addr An array of complex address operations. void DtoDwarfLocalVariable(LLValue* ll, VarDeclaration* vd, llvm::ArrayRef addr = llvm::ArrayRef()); -/** - * Emits all things necessary for making debug info for a global variable vd. - * @param ll - * @param vd - * @return - */ +/// \brief Emits all things necessary for making debug info for a global variable vd. +/// \param ll LLVM global variable +/// \param vd Variable declaration to emit debug info for. +/// \returns Created debug info llvm::DIGlobalVariable DtoDwarfGlobalVariable(LLGlobalVariable* ll, VarDeclaration* vd); void DtoDwarfModuleEnd(); diff --git a/gen/toir.cpp b/gen/toir.cpp index d922e906a7..7170453e23 100644 --- a/gen/toir.cpp +++ b/gen/toir.cpp @@ -1950,9 +1950,10 @@ DValue* NewExp::toElem(IRState* p) else { size_t ndims = arguments->dim; - std::vector dims(ndims); + std::vector dims; + dims.reserve(ndims); for (size_t i=0; i(arguments->data[i])->toElem(p); + dims.push_back(static_cast(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 vals(elements->dim, NULL); + std::vector vals; + vals.reserve(elements->dim); for (unsigned i=0; idim; ++i) { Expression* expr = static_cast(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 inits(sd->fields.dim, NULL); + std::vector 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 values = DtoStructLiteralValues(sd, inits); // we know those values are constants.. cast them - std::vector constvals(values.size(), NULL); - std::vector types(values.size(), NULL); + std::vector constvals(values.size(), 0); + std::vector types(values.size(), 0); for (size_t i = 0; i < values.size(); ++i) { constvals[i] = llvm::cast(values[i]); types[i] = values[i]->getType(); @@ -3059,6 +3061,8 @@ DValue* AssocArrayLiteralExp::toElem(IRState* p) { std::vector 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 types(exps->dim, NULL); + std::vector types; + types.reserve(exps->dim); for (size_t i = 0; i < exps->dim; i++) { Expression *el = static_cast(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++) diff --git a/gen/tollvm.cpp b/gen/tollvm.cpp index 99bb1c88d7..624fefc3db 100644 --- a/gen/tollvm.cpp +++ b/gen/tollvm.cpp @@ -492,7 +492,7 @@ LLValue* DtoGEP1(LLValue* ptr, LLValue* i0, const char* var, llvm::BasicBlock* b LLValue* DtoGEP(LLValue* ptr, LLValue* i0, LLValue* i1, const char* var, llvm::BasicBlock* bb) { - LLValue* v[2] = { i0, i1 }; + LLValue* v[] = { i0, i1 }; return llvm::GetElementPtrInst::Create(ptr, v, var?var:"tmp", bb?bb:gIR->scopebb()); } @@ -507,7 +507,7 @@ LLValue* DtoGEPi1(LLValue* ptr, unsigned i, const char* var, llvm::BasicBlock* b LLValue* DtoGEPi(LLValue* ptr, unsigned i0, unsigned i1, const char* var, llvm::BasicBlock* bb) { - LLValue* v[2] = { DtoConstUint(i0), DtoConstUint(i1) }; + LLValue* v[] = { DtoConstUint(i0), DtoConstUint(i1) }; return llvm::GetElementPtrInst::Create(ptr, v, var?var:"tmp", bb?bb:gIR->scopebb()); } @@ -515,7 +515,7 @@ LLValue* DtoGEPi(LLValue* ptr, unsigned i0, unsigned i1, const char* var, llvm:: LLConstant* DtoGEPi(LLConstant* ptr, unsigned i0, unsigned i1) { - LLValue* v[2] = { DtoConstUint(i0), DtoConstUint(i1) }; + LLValue* v[] = { DtoConstUint(i0), DtoConstUint(i1) }; return llvm::ConstantExpr::getGetElementPtr(ptr, v, true); } @@ -644,7 +644,7 @@ LLConstant* DtoConstFP(Type* t, longdouble value) if(llty == LLType::getFloatTy(gIR->context()) || llty == LLType::getDoubleTy(gIR->context())) return LLConstantFP::get(llty, value); else if(llty == LLType::getX86_FP80Ty(gIR->context())) { - uint64_t bits[] = {0, 0}; + uint64_t bits[] = { 0, 0 }; bits[0] = *reinterpret_cast(&value); bits[1] = *reinterpret_cast(reinterpret_cast(&value) + 1); #if LDC_LLVM_VER >= 303 @@ -678,7 +678,7 @@ LLConstant* DtoConstString(const char* str) #endif llvm::GlobalVariable* gvar = new llvm::GlobalVariable( *gIR->module, init->getType(), true, llvm::GlobalValue::InternalLinkage, init, ".str"); - LLConstant* idxs[2] = { DtoConstUint(0), DtoConstUint(0) }; + LLConstant* idxs[] = { DtoConstUint(0), DtoConstUint(0) }; return DtoConstSlice( DtoConstSize_t(s.size()), llvm::ConstantExpr::getGetElementPtr(gvar, idxs, true), @@ -697,7 +697,7 @@ LLConstant* DtoConstStringPtr(const char* str, const char* section) llvm::GlobalVariable* gvar = new llvm::GlobalVariable( *gIR->module, init->getType(), true, llvm::GlobalValue::InternalLinkage, init, ".str"); if (section) gvar->setSection(section); - LLConstant* idxs[2] = { DtoConstUint(0), DtoConstUint(0) }; + LLConstant* idxs[] = { DtoConstUint(0), DtoConstUint(0) }; return llvm::ConstantExpr::getGetElementPtr(gvar, idxs, true); } diff --git a/runtime/druntime b/runtime/druntime index a2efaf9525..34f9dcf7ae 160000 --- a/runtime/druntime +++ b/runtime/druntime @@ -1 +1 @@ -Subproject commit a2efaf9525894ccd0f649cc87fea269ff6263e4a +Subproject commit 34f9dcf7aed758a3cce48cb77e4e77d7d877d676