Make IrDsymbol to be a typesafe union to reduce memory usage

This commit is contained in:
Alexey Prokhin 2014-09-12 00:17:18 +04:00
parent 5b15095c81
commit 18f33b1815
27 changed files with 465 additions and 293 deletions

View file

@ -501,7 +501,7 @@ static llvm::Function* DtoDeclareVaFunction(FuncDeclaration* fdecl)
func = GET_INTRINSIC_DECL(vaend);
assert(func);
fdecl->ir.irFunc->func = func;
getIrFunc(fdecl)->func = func;
return func;
}
@ -767,9 +767,8 @@ void DtoDeclareFunction(FuncDeclaration* fdecl)
Type* t = fdecl->type->toBasetype();
TypeFunction* f = static_cast<TypeFunction*>(t);
if (!fdecl->ir.irFunc) {
fdecl->ir.irFunc = new IrFunction(fdecl);
}
// create IrFunction
IrFunction *irFunc = getIrFunc(fdecl, true);
LLFunction* vafunc = 0;
if (fdecl->isVaIntrinsic())
@ -816,7 +815,7 @@ void DtoDeclareFunction(FuncDeclaration* fdecl)
IF_LOG Logger::cout() << "func = " << *func << std::endl;
// add func to IRFunc
fdecl->ir.irFunc->func = func;
irFunc->func = func;
// parameter attributes
if (!fdecl->isIntrinsic()) {
@ -838,7 +837,7 @@ void DtoDeclareFunction(FuncDeclaration* fdecl)
if (fdecl->neverInline)
{
fdecl->ir.irFunc->setNeverInline();
irFunc->setNeverInline();
}
if (fdecl->llvmInternal == LLVMglobal_crt_ctor || fdecl->llvmInternal == LLVMglobal_crt_dtor)
@ -855,13 +854,13 @@ void DtoDeclareFunction(FuncDeclaration* fdecl)
if (irFty.arg_sret) {
iarg->setName(".sret_arg");
fdecl->ir.irFunc->retArg = iarg;
irFunc->retArg = iarg;
++iarg;
}
if (irFty.arg_this) {
iarg->setName(".this_arg");
fdecl->ir.irFunc->thisArg = iarg;
irFunc->thisArg = iarg;
VarDeclaration* v = fdecl->vthis;
if (v) {
@ -869,25 +868,28 @@ void DtoDeclareFunction(FuncDeclaration* fdecl)
// later for codegen'ing the function, just as normal
// parameters below, because it can be referred to in nested
// context types. Will be given storage in DtoDefineFunction.
assert(!v->ir.irParam);
v->ir.irParam = new IrParameter(v, iarg, irFty.arg_this, true);
assert(!isIrParameterCreated(v));
IrParameter *irParam = getIrParameter(v, true);
irParam->value = iarg;
irParam->arg = irFty.arg_this;
irParam->isVthis = true;
}
++iarg;
}
else if (irFty.arg_nest) {
iarg->setName(".nest_arg");
fdecl->ir.irFunc->nestArg = iarg;
assert(fdecl->ir.irFunc->nestArg);
irFunc->nestArg = iarg;
assert(irFunc->nestArg);
++iarg;
}
if (irFty.arg_argptr) {
iarg->setName("._arguments");
fdecl->ir.irFunc->_arguments = iarg;
irFunc->_arguments = iarg;
++iarg;
iarg->setName("._argptr");
fdecl->ir.irFunc->_argptr = iarg;
irFunc->_argptr = iarg;
++iarg;
}
@ -902,11 +904,14 @@ void DtoDeclareFunction(FuncDeclaration* fdecl)
VarDeclaration* argvd = argsym->isVarDeclaration();
assert(argvd);
assert(!argvd->ir.irLocal);
assert(!isIrLocalCreated(argvd));
std::string str(argvd->ident->toChars());
str.append("_arg");
iarg->setName(str);
argvd->ir.irParam = new IrParameter(argvd, iarg, irFty.args[paramIndex]);
IrParameter *irParam = getIrParameter(argvd, true);
irParam->value = iarg;
irParam->arg = irFty.args[paramIndex];
k++;
}
@ -1023,24 +1028,23 @@ void DtoDefineFunction(FuncDeclaration* fd)
}
IrFuncTy &irFty = fd->irFty;
IrFunction *irFunc = getIrFunc(fd);
// debug info
fd->ir.irFunc->diSubprogram = gIR->DBuilder.EmitSubProgram(fd);
irFunc->diSubprogram = gIR->DBuilder.EmitSubProgram(fd);
Type* t = fd->type->toBasetype();
TypeFunction* f = static_cast<TypeFunction*>(t);
// assert(f->irtype);
llvm::Function* func = fd->ir.irFunc->func;
llvm::Function* func = irFunc->func;
// is there a body?
if (fd->fbody == NULL)
return;
IF_LOG Logger::println("Doing function body for: %s", fd->toChars());
assert(fd->ir.irFunc);
IrFunction* irfunction = fd->ir.irFunc;
gIR->functions.push_back(irfunction);
gIR->functions.push_back(irFunc);
if (fd->isMain())
gIR->emitMain = true;
@ -1079,7 +1083,7 @@ void DtoDefineFunction(FuncDeclaration* fd)
// create alloca point
// this gets erased when the function is complete, so alignment etc does not matter at all
llvm::Instruction* allocaPoint = new llvm::AllocaInst(LLType::getInt32Ty(gIR->context()), "alloca point", beginbb);
irfunction->allocapoint = allocaPoint;
irFunc->allocapoint = allocaPoint;
// debug info - after all allocas, but before any llvm.dbg.declare etc
gIR->DBuilder.EmitFuncStart(fd);
@ -1096,7 +1100,7 @@ void DtoDefineFunction(FuncDeclaration* fd)
// give the 'this' argument storage and debug info
if (irFty.arg_this)
{
LLValue* thisvar = irfunction->thisArg;
LLValue* thisvar = irFunc->thisArg;
assert(thisvar);
LLValue* thismem = thisvar;
@ -1104,11 +1108,11 @@ void DtoDefineFunction(FuncDeclaration* fd)
{
thismem = DtoRawAlloca(thisvar->getType(), 0, "this"); // FIXME: align?
DtoStore(thisvar, thismem);
irfunction->thisArg = thismem;
irFunc->thisArg = thismem;
}
assert(fd->vthis->ir.irParam->value == thisvar);
fd->vthis->ir.irParam->value = thismem;
assert(getIrParameter(fd->vthis)->value == thisvar);
getIrParameter(fd->vthis)->value = thismem;
gIR->DBuilder.EmitLocalVariable(thismem, fd->vthis);
}
@ -1116,10 +1120,10 @@ void DtoDefineFunction(FuncDeclaration* fd)
// give the 'nestArg' storage
if (irFty.arg_nest)
{
LLValue *nestArg = irfunction->nestArg;
LLValue *nestArg = irFunc->nestArg;
LLValue *val = DtoRawAlloca(nestArg->getType(), 0, "nestedFrame");
DtoStore(nestArg, val);
irfunction->nestArg = val;
irFunc->nestArg = val;
}
// give arguments storage
@ -1134,7 +1138,7 @@ void DtoDefineFunction(FuncDeclaration* fd)
VarDeclaration* vd = argsym->isVarDeclaration();
assert(vd);
IrParameter* irparam = vd->ir.irParam;
IrParameter* irparam = getIrParameter(vd);
assert(irparam);
bool refout = vd->storage_class & (STCref | STCout);
@ -1163,7 +1167,7 @@ void DtoDefineFunction(FuncDeclaration* fd)
}
FuncGen fg;
irfunction->gen = &fg;
irFunc->gen = &fg;
DtoCreateNestedContext(fd);
@ -1178,19 +1182,19 @@ void DtoDefineFunction(FuncDeclaration* fd)
if (f->linkage == LINKd && f->varargs == 1)
{
// _argptr
LLValue* argptrmem = DtoRawAlloca(fd->ir.irFunc->_argptr->getType(), 0, "_argptr_mem");
new llvm::StoreInst(fd->ir.irFunc->_argptr, argptrmem, gIR->scopebb());
fd->ir.irFunc->_argptr = argptrmem;
LLValue* argptrmem = DtoRawAlloca(irFunc->_argptr->getType(), 0, "_argptr_mem");
new llvm::StoreInst(irFunc->_argptr, argptrmem, gIR->scopebb());
irFunc->_argptr = argptrmem;
// _arguments
LLValue* argumentsmem = DtoRawAlloca(fd->ir.irFunc->_arguments->getType(), 0, "_arguments_mem");
new llvm::StoreInst(fd->ir.irFunc->_arguments, argumentsmem, gIR->scopebb());
fd->ir.irFunc->_arguments = argumentsmem;
LLValue* argumentsmem = DtoRawAlloca(irFunc->_arguments->getType(), 0, "_arguments_mem");
new llvm::StoreInst(irFunc->_arguments, argumentsmem, gIR->scopebb());
irFunc->_arguments = argumentsmem;
}
// output function body
Statement_toIR(fd->fbody, gIR);
irfunction->gen = 0;
irFunc->gen = 0;
// TODO: clean up this mess