Mercurial > projects > ldc
changeset 479:672eb4893b55
Move AllocaInst creation into DtoAlloca helper. Will enable special zero-init of fp80 reals' padding.
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Tue, 05 Aug 2008 19:28:19 +0200 |
parents | b657298222d9 |
children | fc12214ba4a1 |
files | gen/aa.cpp gen/arrays.cpp gen/asmstmt.cpp gen/classes.cpp gen/complex.cpp gen/functions.cpp gen/llvmhelpers.cpp gen/llvmhelpers.h gen/statements.cpp gen/tocall.cpp gen/toir.cpp ir/irlandingpad.cpp |
diffstat | 12 files changed, 60 insertions(+), 39 deletions(-) [+] |
line wrap: on
line diff
--- a/gen/aa.cpp Tue Aug 05 08:08:00 2008 +0200 +++ b/gen/aa.cpp Tue Aug 05 19:28:19 2008 +0200 @@ -36,7 +36,7 @@ pkey = key->getRVal(); } else { - LLValue* tmp = new llvm::AllocaInst(DtoType(keytype), "aatmpkeystorage", gIR->topallocapoint()); + LLValue* tmp = DtoAlloca(DtoType(keytype), "aatmpkeystorage"); DVarValue* var = new DVarValue(keytype, tmp, true); DtoAssign(loc, var, key); return tmp; @@ -44,7 +44,7 @@ // give memory if (needmem) { - LLValue* tmp = new llvm::AllocaInst(DtoType(keytype), "aatmpkeystorage", gIR->topallocapoint()); + LLValue* tmp = DtoAlloca(DtoType(keytype), "aatmpkeystorage"); DtoStore(pkey, tmp); pkey = tmp; }
--- a/gen/arrays.cpp Tue Aug 05 08:08:00 2008 +0200 +++ b/gen/arrays.cpp Tue Aug 05 19:28:19 2008 +0200 @@ -118,7 +118,7 @@ // give slices and complex values storage (and thus an address to pass) if (value->isSlice() || value->isComplex()) { - val = new llvm::AllocaInst(DtoType(value->getType()), ".tmpparam", gIR->topallocapoint()); + val = DtoAlloca(DtoType(value->getType()), ".tmpparam"); DVarValue lval(value->getType(), val, true); DtoAssign(loc, &lval, value); } @@ -445,7 +445,7 @@ LLFunction* fn = LLVM_D_GetRuntimeFunction(gIR->module, zeroInit ? "_d_newarraymT" : "_d_newarraymiT" ); // build dims - LLValue* dimsArg = new llvm::AllocaInst(DtoSize_t(), DtoConstUint(ndims), ".newdims", gIR->topallocapoint()); + LLValue* dimsArg = DtoAlloca(DtoSize_t(), DtoConstUint(ndims), ".newdims"); LLValue* firstDim = NULL; for (size_t i=0; i<ndims; ++i) { @@ -698,13 +698,13 @@ // we need to give slices storage if (l->isSlice()) { - lmem = new llvm::AllocaInst(DtoType(l->getType()), "tmpparam", gIR->topallocapoint()); + lmem = DtoAlloca(DtoType(l->getType()), "tmpparam"); DtoSetArray(lmem, DtoArrayLen(l), DtoArrayPtr(l)); } // also null else if (l->isNull()) { - lmem = new llvm::AllocaInst(DtoType(l->getType()), "tmpparam", gIR->topallocapoint()); + lmem = DtoAlloca(DtoType(l->getType()), "tmpparam"); DtoSetArray(lmem, llvm::Constant::getNullValue(DtoSize_t()), llvm::Constant::getNullValue(DtoType(l->getType()->next->pointerTo()))); } else @@ -713,13 +713,13 @@ // and for the rvalue ... // we need to give slices storage if (r->isSlice()) { - rmem = new llvm::AllocaInst(DtoType(r->getType()), "tmpparam", gIR->topallocapoint()); + rmem = DtoAlloca(DtoType(r->getType()), "tmpparam"); DtoSetArray(rmem, DtoArrayLen(r), DtoArrayPtr(r)); } // also null else if (r->isNull()) { - rmem = new llvm::AllocaInst(DtoType(r->getType()), "tmpparam", gIR->topallocapoint()); + rmem = DtoAlloca(DtoType(r->getType()), "tmpparam"); DtoSetArray(rmem, llvm::Constant::getNullValue(DtoSize_t()), llvm::Constant::getNullValue(DtoType(r->getType()->next->pointerTo()))); } else @@ -1078,7 +1078,7 @@ llvm::AllocaInst* alloc = gIR->func()->srcfileArg; if (!alloc) { - alloc = new llvm::AllocaInst(c->getType(), ".srcfile", gIR->topallocapoint()); + alloc = DtoAlloca(c->getType(), ".srcfile"); gIR->func()->srcfileArg = alloc; } LLValue* ptr = DtoGEPi(alloc, 0,0, "tmp");
--- a/gen/asmstmt.cpp Tue Aug 05 08:08:00 2008 +0200 +++ b/gen/asmstmt.cpp Tue Aug 05 19:28:19 2008 +0200 @@ -535,7 +535,7 @@ outSetterStmt->code += asmGotoEndLabel.str()+": ; "; // create storage for and initialize the temporary - jump_target = new llvm::AllocaInst(llvm::IntegerType::get(32), "__llvm_jump_target", p->topallocapoint()); + jump_target = DtoAlloca(LLType::Int32Ty, "__llvm_jump_target"); gIR->ir->CreateStore(DtoConstUint(0), jump_target); // setup variable for output from asm outSetterStmt->out_c = "=*m,";
--- a/gen/classes.cpp Tue Aug 05 08:08:00 2008 +0200 +++ b/gen/classes.cpp Tue Aug 05 19:28:19 2008 +0200 @@ -795,7 +795,7 @@ LLValue* mem; if (newexp->onstack) { - mem = new llvm::AllocaInst(DtoType(tc)->getContainedType(0), ".newclass_alloca", gIR->topallocapoint()); + mem = DtoAlloca(DtoType(tc)->getContainedType(0), ".newclass_alloca"); } // custom allocator else if (newexp->allocator)
--- a/gen/complex.cpp Tue Aug 05 08:08:00 2008 +0200 +++ b/gen/complex.cpp Tue Aug 05 19:28:19 2008 +0200 @@ -475,7 +475,7 @@ // unfortunately at this point, the cast value can show up as the lvalue for += and similar expressions. // so we need to give it storage, or fix the system that handles this stuff (DLRValue) - LLValue* mem = new llvm::AllocaInst(DtoType(_to), "castcomplextmp", gIR->topallocapoint()); + LLValue* mem = DtoAlloca(DtoType(_to), "castcomplextmp"); DtoComplexSet(mem, re, im); return new DLRValue(val, new DImValue(_to, mem)); }
--- a/gen/functions.cpp Tue Aug 05 08:08:00 2008 +0200 +++ b/gen/functions.cpp Tue Aug 05 19:28:19 2008 +0200 @@ -572,7 +572,7 @@ if (fd->vresult && !fd->vresult->nestedref) { Logger::println("non-nested vresult value"); fd->vresult->ir.irLocal = new IrLocal(fd->vresult); - fd->vresult->ir.irLocal->value = new llvm::AllocaInst(DtoType(fd->vresult->type),"function_vresult",allocaPoint); + fd->vresult->ir.irLocal->value = DtoAlloca(DtoType(fd->vresult->type),"function_vresult"); } // give the 'this' argument storage and debug info @@ -582,7 +582,7 @@ LLValue* thisvar = irfunction->thisVar; assert(thisvar); - LLValue* thismem = new llvm::AllocaInst(thisvar->getType(), ".newthis", allocaPoint); + LLValue* thismem = DtoAlloca(thisvar->getType(), ".newthis"); DtoStore(thisvar, thismem); irfunction->thisVar = thismem; @@ -619,7 +619,7 @@ } LLValue* a = irloc->value; - LLValue* v = new llvm::AllocaInst(a->getType(), "."+a->getName(), allocaPoint); + LLValue* v = DtoAlloca(a->getType(), "."+a->getName()); DtoStore(a,v); irloc->value = v; } @@ -665,7 +665,7 @@ } const llvm::StructType* nestSType = llvm::StructType::get(nestTypes); Logger::cout() << "nested var struct has type:" << *nestSType << '\n'; - fd->ir.irFunc->nestedVar = new llvm::AllocaInst(nestSType,"nestedvars",allocaPoint); + fd->ir.irFunc->nestedVar = DtoAlloca(nestSType,"nestedvars"); if (parentNested) { assert(fd->ir.irFunc->thisVar); LLValue* ptr = gIR->ir->CreateBitCast(fd->ir.irFunc->thisVar, parentNested->getType(), "tmp"); @@ -684,7 +684,7 @@ // copy _argptr to a memory location if (f->linkage == LINKd && f->varargs == 1) { - LLValue* argptrmem = new llvm::AllocaInst(fd->ir.irFunc->_argptr->getType(), "_argptrmem", gIR->topallocapoint()); + LLValue* argptrmem = DtoAlloca(fd->ir.irFunc->_argptr->getType(), "_argptrmem"); new llvm::StoreInst(fd->ir.irFunc->_argptr, argptrmem, gIR->scopebb()); fd->ir.irFunc->_argptr = argptrmem; } @@ -791,7 +791,7 @@ // byval arg, but expr has no storage yet else if (DtoIsPassedByRef(argexp->type) && (arg->isSlice() || arg->isComplex() || arg->isNull())) { - LLValue* alloc = new llvm::AllocaInst(DtoType(argexp->type), "tmpparam", gIR->topallocapoint()); + LLValue* alloc = DtoAlloca(DtoType(argexp->type), "tmpparam"); DVarValue* vv = new DVarValue(argexp->type, alloc, true); DtoAssign(argexp->loc, vv, arg); arg = vv;
--- a/gen/llvmhelpers.cpp Tue Aug 05 08:08:00 2008 +0200 +++ b/gen/llvmhelpers.cpp Tue Aug 05 19:28:19 2008 +0200 @@ -85,6 +85,23 @@ /****************************************************************************************/ /*//////////////////////////////////////////////////////////////////////////////////////// +// ALLOCA HELPERS +////////////////////////////////////////////////////////////////////////////////////////*/ + + +llvm::AllocaInst* DtoAlloca(const LLType* lltype, const std::string& name) +{ + return new llvm::AllocaInst(lltype, name, gIR->topallocapoint()); +} + +llvm::AllocaInst* DtoAlloca(const LLType* lltype, LLValue* arraysize, const std::string& name) +{ + return new llvm::AllocaInst(lltype, arraysize, name, gIR->topallocapoint()); +} + + +/****************************************************************************************/ +/*//////////////////////////////////////////////////////////////////////////////////////// // ASSERT HELPER ////////////////////////////////////////////////////////////////////////////////////////*/ @@ -112,7 +129,7 @@ llvm::AllocaInst* alloc = gIR->func()->msgArg; if (!alloc) { - alloc = new llvm::AllocaInst(c->getType(), ".assertmsg", gIR->topallocapoint()); + alloc = DtoAlloca(c->getType(), ".assertmsg"); DtoSetArray(alloc, DtoArrayLen(s), DtoArrayPtr(s)); gIR->func()->msgArg = alloc; } @@ -129,7 +146,7 @@ llvm::AllocaInst* alloc = gIR->func()->srcfileArg; if (!alloc) { - alloc = new llvm::AllocaInst(c->getType(), ".srcfile", gIR->topallocapoint()); + alloc = DtoAlloca(c->getType(), ".srcfile"); gIR->func()->srcfileArg = alloc; } LLValue* ptr = DtoGEPi(alloc, 0,0, "tmp"); @@ -1211,7 +1228,7 @@ if(gTargetData->getTypeSizeInBits(lltype) == 0) allocainst = llvm::ConstantPointerNull::get(getPtrToType(lltype)); else - allocainst = new llvm::AllocaInst(lltype, vd->toChars(), gIR->topallocapoint()); + allocainst = DtoAlloca(lltype, vd->toChars()); //allocainst->setAlignment(vd->type->alignsize()); // TODO vd->ir.irLocal = new IrLocal(vd);
--- a/gen/llvmhelpers.h Tue Aug 05 08:08:00 2008 +0200 +++ b/gen/llvmhelpers.h Tue Aug 05 19:28:19 2008 +0200 @@ -11,6 +11,10 @@ void DtoDeleteInterface(LLValue* inst); void DtoDeleteArray(DValue* arr); +// emit an alloca +llvm::AllocaInst* DtoAlloca(const LLType* lltype, const std::string& name = ""); +llvm::AllocaInst* DtoAlloca(const LLType* lltype, LLValue* arraysize, const std::string& name = ""); + // assertion generator void DtoAssert(Loc* loc, DValue* msg);
--- a/gen/statements.cpp Tue Aug 05 08:08:00 2008 +0200 +++ b/gen/statements.cpp Tue Aug 05 19:28:19 2008 +0200 @@ -144,7 +144,7 @@ if (match) { - LLValue* allocainst = new llvm::AllocaInst(DtoType(match->type), "._tmp_if_var", p->topallocapoint()); + LLValue* allocainst = DtoAlloca(DtoType(match->type), "._tmp_if_var"); match->ir.irLocal = new IrLocal(match); match->ir.irLocal->value = allocainst; } @@ -675,7 +675,7 @@ if (DSliceValue* sval = val->isSlice()) { // give storage - llval = new llvm::AllocaInst(DtoType(e->type), "tmp", gIR->topallocapoint()); + llval = DtoAlloca(DtoType(e->type), "tmp"); DVarValue* vv = new DVarValue(e->type, llval, true); DtoAssign(e->loc, vv, val); } @@ -913,7 +913,7 @@ // key const LLType* keytype = key ? DtoType(key->type) : DtoSize_t(); - LLValue* keyvar = new llvm::AllocaInst(keytype, "foreachkey", p->topallocapoint()); + LLValue* keyvar = DtoAlloca(keytype, "foreachkey"); if (key) { //key->llvmValue = keyvar; @@ -928,7 +928,7 @@ const LLType* valtype = DtoType(value->type); LLValue* valvar = NULL; if (!value->isRef() && !value->isOut()) - valvar = new llvm::AllocaInst(valtype, "foreachval", p->topallocapoint()); + valvar = DtoAlloca(valtype, "foreachval"); if (!value->ir.irLocal) value->ir.irLocal = new IrLocal(value); @@ -1248,7 +1248,7 @@ llvm::AllocaInst* alloc = gIR->func()->srcfileArg; if (!alloc) { - alloc = new llvm::AllocaInst(c->getType(), ".srcfile", gIR->topallocapoint()); + alloc = DtoAlloca(c->getType(), ".srcfile"); gIR->func()->srcfileArg = alloc; } LLValue* ptr = DtoGEPi(alloc, 0,0, "tmp");
--- a/gen/tocall.cpp Tue Aug 05 08:08:00 2008 +0200 +++ b/gen/tocall.cpp Tue Aug 05 19:28:19 2008 +0200 @@ -118,7 +118,7 @@ } const LLStructType* vtype = LLStructType::get(vtypes); Logger::cout() << "d-variadic argument struct type:\n" << *vtype << '\n'; - LLValue* mem = new llvm::AllocaInst(vtype,"_argptr_storage",gIR->topallocapoint()); + LLValue* mem = DtoAlloca(vtype,"_argptr_storage"); // store arguments in the struct for (int i=begin,k=0; i<arguments->dim; i++,k++) @@ -230,7 +230,7 @@ // return in hidden ptr is first if (retinptr) { - LLValue* retvar = new llvm::AllocaInst(argiter->get()->getContainedType(0), ".rettmp", gIR->topallocapoint()); + LLValue* retvar = DtoAlloca(argiter->get()->getContainedType(0), ".rettmp"); ++argiter; args.push_back(retvar); palist = palist.addAttr(1, llvm::ParamAttr::StructRet);
--- a/gen/toir.cpp Tue Aug 05 08:08:00 2008 +0200 +++ b/gen/toir.cpp Tue Aug 05 19:28:19 2008 +0200 @@ -358,7 +358,7 @@ if (dtype->ty == Tarray) { LLConstant* clen = llvm::ConstantInt::get(DtoSize_t(),len,false); - LLValue* tmpmem = new llvm::AllocaInst(DtoType(dtype),"tempstring",p->topallocapoint()); + LLValue* tmpmem = DtoAlloca(DtoType(dtype),"tempstring"); DtoSetArray(tmpmem, clen, arrptr); return new DVarValue(type, tmpmem, true); } @@ -770,7 +770,7 @@ DValue* expv = exp->toElem(p); if (expv->getType()->toBasetype()->ty != Tint32) expv = DtoCast(loc, expv, Type::tint32); - return new DImValue(type, gIR->ir->CreateAlloca(LLType::Int8Ty, expv->getRVal(), ".alloca")); + return new DImValue(type, DtoAlloca(LLType::Int8Ty, expv->getRVal(), ".alloca")); } } @@ -1595,7 +1595,7 @@ // allocate a temporary for the final result. failed to come up with a better way :/ LLValue* resval = 0; llvm::BasicBlock* entryblock = &p->topfunc()->front(); - resval = new llvm::AllocaInst(LLType::Int1Ty,"andandtmp",p->topallocapoint()); + resval = DtoAlloca(LLType::Int1Ty,"andandtmp"); DValue* u = e1->toElem(p); @@ -1631,7 +1631,7 @@ // allocate a temporary for the final result. failed to come up with a better way :/ LLValue* resval = 0; llvm::BasicBlock* entryblock = &p->topfunc()->front(); - resval = new llvm::AllocaInst(LLType::Int1Ty,"orortmp",p->topallocapoint()); + resval = DtoAlloca(LLType::Int1Ty,"orortmp"); DValue* u = e1->toElem(p); @@ -1758,7 +1758,7 @@ const LLPointerType* int8ptrty = getPtrToType(LLType::Int8Ty); - LLValue* lval = new llvm::AllocaInst(DtoType(type), "tmpdelegate", p->topallocapoint()); + LLValue* lval = DtoAlloca(DtoType(type), "tmpdelegate"); DValue* u = e1->toElem(p); LLValue* uval; @@ -1897,7 +1897,7 @@ // allocate a temporary for the final result. failed to come up with a better way :/ llvm::BasicBlock* entryblock = &p->topfunc()->front(); - LLValue* resval = new llvm::AllocaInst(resty,"condtmp",p->topallocapoint()); + LLValue* resval = DtoAlloca(resty,"condtmp"); DVarValue* dvv = new DVarValue(type, resval, true); llvm::BasicBlock* oldend = p->scopeend(); @@ -2034,7 +2034,7 @@ DtoForceDefineDsymbol(fd); const LLType* dgty = DtoType(type); - LLValue* lval = new llvm::AllocaInst(dgty,"dgstorage",p->topallocapoint()); + LLValue* lval = DtoAlloca(dgty,"dgstorage"); LLValue* context = DtoGEPi(lval,0,0); const LLPointerType* pty = isaPointer(context->getType()->getContainedType(0)); @@ -2085,7 +2085,7 @@ // dst pointer LLValue* dstMem = 0; - dstMem = new llvm::AllocaInst(llStoType, "arrayliteral", p->topallocapoint()); + dstMem = DtoAlloca(llStoType, "arrayliteral"); // store elements for (size_t i=0; i<len; ++i) @@ -2143,7 +2143,7 @@ LLValue* mem = 0; - LLValue* sptr = new llvm::AllocaInst(llt,"tmpstructliteral",p->topallocapoint()); + LLValue* sptr = DtoAlloca(llt,"tmpstructliteral"); // num elements in literal @@ -2255,7 +2255,7 @@ const LLType* aalltype = DtoType(type); // it should be possible to avoid the temporary in some cases - LLValue* tmp = new llvm::AllocaInst(aalltype,"aaliteral",p->topallocapoint()); + LLValue* tmp = DtoAlloca(aalltype,"aaliteral"); DValue* aa = new DVarValue(type, tmp, true); DtoStore(LLConstant::getNullValue(aalltype), tmp);
--- a/ir/irlandingpad.cpp Tue Aug 05 08:08:00 2008 +0200 +++ b/ir/irlandingpad.cpp Tue Aug 05 19:28:19 2008 +0200 @@ -187,7 +187,7 @@ { Logger::println("Making new catch var"); const LLType* objectTy = DtoType(ClassDeclaration::object->type); - catch_var = new llvm::AllocaInst(objectTy,"catchvar",gIR->topallocapoint()); + catch_var = DtoAlloca(objectTy,"catchvar"); } return catch_var; }