Move AllocaInst creation into DtoAlloca helper. Will enable special zero-init of fp80 reals' padding.

This commit is contained in:
Christian Kamm
2008-08-05 19:28:19 +02:00
parent 866360c23b
commit 8362b86c5a
12 changed files with 60 additions and 39 deletions

View File

@@ -36,7 +36,7 @@ static LLValue* to_pkey(Loc& loc, DValue* key)
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 @@ static LLValue* to_pkey(Loc& loc, DValue* key)
// 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;
}

View File

@@ -118,7 +118,7 @@ void DtoArrayInit(Loc& loc, DValue* array, DValue* value)
// 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 @@ DSliceValue* DtoNewMulDimDynArray(Type* arrayType, DValue** dims, size_t ndims,
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 @@ static LLValue* DtoArrayEqCmp_impl(Loc& loc, const char* func, DValue* l, DValue
// 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 @@ static LLValue* DtoArrayEqCmp_impl(Loc& loc, const char* func, DValue* l, DValue
// 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 @@ void DtoArrayBoundsCheck(Loc& loc, DValue* arr, DValue* index, bool isslice)
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");

View File

@@ -535,7 +535,7 @@ void AsmBlockStatement::toIR(IRState* p)
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,";

View File

@@ -795,7 +795,7 @@ DValue* DtoNewClass(TypeClass* tc, NewExp* newexp)
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)

View File

@@ -475,7 +475,7 @@ DValue* DtoCastComplex(Loc& loc, DValue* val, Type* _to)
// 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));
}

View File

@@ -572,7 +572,7 @@ void DtoDefineFunc(FuncDeclaration* fd)
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 @@ void DtoDefineFunc(FuncDeclaration* fd)
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 @@ void DtoDefineFunc(FuncDeclaration* fd)
}
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 @@ void DtoDefineFunc(FuncDeclaration* fd)
}
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 @@ void DtoDefineFunc(FuncDeclaration* fd)
// 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 @@ DValue* DtoArgument(Argument* fnarg, Expression* argexp)
// 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;

View File

@@ -83,6 +83,23 @@ void DtoDeleteArray(DValue* arr)
gIR->CreateCallOrInvoke(fn, arg.begin(), arg.end());
}
/****************************************************************************************/
/*////////////////////////////////////////////////////////////////////////////////////////
// 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 @@ void DtoAssert(Loc* loc, DValue* msg)
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 @@ void DtoAssert(Loc* loc, DValue* msg)
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 @@ DValue* DtoDeclarationExp(Dsymbol* declaration)
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);

View File

@@ -11,6 +11,10 @@ void DtoDeleteClass(LLValue* inst);
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);

View File

@@ -144,7 +144,7 @@ void IfStatement::toIR(IRState* p)
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 @@ static LLValue* call_string_switch_runtime(llvm::GlobalVariable* table, Expressi
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 @@ void ForeachStatement::toIR(IRState* p)
// 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 @@ void ForeachStatement::toIR(IRState* p)
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 @@ void SwitchErrorStatement::toIR(IRState* p)
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");

View File

@@ -118,7 +118,7 @@ void DtoBuildDVarArgList(std::vector<LLValue*>& args, llvm::PAListPtr& palist, T
}
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 @@ DValue* DtoCallFunction(Loc& loc, Type* resulttype, DValue* fnval, Expressions*
// 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);

View File

@@ -358,7 +358,7 @@ DValue* StringExp::toElem(IRState* p)
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* CallExp::toElem(IRState* p)
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 @@ DValue* AndAndExp::toElem(IRState* p)
// 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 @@ DValue* OrOrExp::toElem(IRState* p)
// 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 @@ DValue* DelegateExp::toElem(IRState* p)
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 @@ DValue* CondExp::toElem(IRState* p)
// 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 @@ DValue* FuncExp::toElem(IRState* p)
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 @@ DValue* ArrayLiteralExp::toElem(IRState* p)
// 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 @@ DValue* StructLiteralExp::toElem(IRState* p)
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 @@ DValue* AssocArrayLiteralExp::toElem(IRState* p)
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);

View File

@@ -187,7 +187,7 @@ LLValue* IRLandingPad::getExceptionStorage()
{
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;
}