Try to boil down special cases in nested.cpp

This commit is contained in:
Martin 2016-05-28 02:21:58 +02:00
parent f4ccde3c24
commit a6a6786d8d
3 changed files with 16 additions and 66 deletions

View file

@ -605,13 +605,10 @@ void DtoDeclareFunction(FuncDeclaration *fdecl) {
continue;
}
Dsymbol *const argsym = (*fdecl->parameters)[arg->parametersIdx];
VarDeclaration *argvd = argsym->isVarDeclaration();
assert(argvd);
auto *const vd = (*fdecl->parameters)[arg->parametersIdx];
iarg->setName(vd->ident->toChars() + llvm::Twine("_arg"));
iarg->setName(argvd->ident->toChars() + llvm::Twine("_arg"));
IrParameter *irParam = getIrParameter(argvd, true);
IrParameter *irParam = getIrParameter(vd, true);
irParam->arg = arg;
irParam->value = &(*iarg);
}
@ -908,10 +905,7 @@ void DtoDefineFunction(FuncDeclaration *fd) {
// index in the IrFuncTy args array separately.
size_t llArgIdx = 0;
for (size_t i = 0; i < fd->parameters->dim; ++i) {
Dsymbol *const argsym = (*fd->parameters)[i];
VarDeclaration *const vd = argsym->isVarDeclaration();
assert(vd);
const bool refout = vd->storage_class & (STCref | STCout);
auto *const vd = (*fd->parameters)[i];
IrParameter *irparam = getIrParameter(vd);
Type *debugInfoType = vd->type;
@ -922,9 +916,7 @@ void DtoDefineFunction(FuncDeclaration *fd) {
irparam = getIrParameter(vd, true);
irparam->value = DtoAlloca(vd, vd->ident->toChars());
} else {
const bool lazy = vd->storage_class & STClazy;
const bool firstClassVal = !refout && (!irparam->arg->byref || lazy);
if (firstClassVal) {
if (!irparam->arg->byref) {
// alloca a stack slot for this first class value arg
LLValue *mem = DtoAlloca(irparam->arg->type, vd->ident->toChars());
@ -939,13 +931,10 @@ void DtoDefineFunction(FuncDeclaration *fd) {
++llArgIdx;
}
if (global.params.symdebug &&
!(isaArgument(irparam->value) &&
isaArgument(irparam->value)->hasByValAttr())) {
if (global.params.symdebug)
gIR->DBuilder.EmitLocalVariable(irparam->value, vd, debugInfoType);
}
}
}
{
ScopeStack scopeStack(gIR);

View file

@ -19,23 +19,6 @@
#include "ir/irtypeaggr.h"
#include "llvm/Analysis/ValueTracking.h"
static void storeVariable(VarDeclaration *vd, LLValue *dst) {
LLValue *value = getIrLocal(vd)->value;
int ty = vd->type->ty;
FuncDeclaration *fd = getParentFunc(vd, true);
assert(fd && "No parent function for nested variable?");
if (fd->needsClosure() && !vd->isRef() && (ty == Tstruct || ty == Tsarray) &&
isaPointer(value->getType())) {
// Copy structs and static arrays
LLValue *mem = DtoGcMalloc(vd->loc, DtoType(vd->type), ".gc_mem");
DtoMemCpy(mem, value);
DtoAlignedStore(mem, dst);
} else {
// Store the address into the frame
DtoAlignedStore(value, dst);
}
}
static unsigned getVthisIdx(AggregateDeclaration *ad) {
return getFieldGEPIndex(ad, ad->vthis);
}
@ -161,8 +144,7 @@ DValue *DtoNestedVariable(Loc &loc, Type *astype, VarDeclaration *vd,
Logger::cout() << "Addr: " << *val << '\n';
Logger::cout() << "of type: " << *val->getType() << '\n';
}
if (byref || (vd->isParameter() && getIrParameter(vd)->arg &&
getIrParameter(vd)->arg->byref)) {
if (!isSpecialRefVar(vd) && (byref || vd->isRef() || vd->isOut())) {
val = DtoAlignedLoad(val);
// dwarfOpDeref(dwarfAddr);
IF_LOG {
@ -402,31 +384,12 @@ static void DtoCreateNestedContextType(FuncDeclaration *fd) {
irLocal.nestedDepth = depth;
LLType *t = nullptr;
if (vd->isParameter() && getIrParameter(vd)->arg) {
// Parameters that are part of the LLVM signature will have
// storage associated with them (to handle byref etc.), so
// handle those cases specially by storing a pointer instead
// of a value.
const IrParameter *irparam = getIrParameter(vd);
const bool refout = vd->storage_class & (STCref | STCout);
const bool lazy = vd->storage_class & STClazy;
const bool byref = irparam->arg->byref;
const bool isVthisPtr = irparam->isVthis && !byref;
if (!(refout || (byref && !lazy)) || isVthisPtr) {
// This will be copied to the nesting frame.
if (lazy) {
t = irparam->value->getType()->getContainedType(0);
} else {
t = DtoMemType(vd->type);
}
} else {
t = irparam->value->getType();
}
} else if (isSpecialRefVar(vd)) {
if (vd->isRef() || vd->isOut())
t = DtoType(vd->type->pointerTo());
} else {
else if (vd->isParameter() && (vd->storage_class & STClazy))
t = getIrParameter(vd)->value->getType()->getContainedType(0);
else
t = DtoMemType(vd->type);
}
builder.addType(t, getTypeAllocSize(t));
@ -517,9 +480,12 @@ void DtoCreateNestedContext(FuncDeclaration *fd) {
IF_LOG Logger::println("nested param: %s", vd->toChars());
LOG_SCOPE
IrParameter *parm = getIrParameter(vd);
assert(parm->value);
assert(parm->value->getType()->isPointerTy());
if (parm->arg && parm->arg->byref) {
storeVariable(vd, gep);
if (vd->isRef() || vd->isOut()) {
Logger::println("Captured by reference, copying pointer to nested frame");
DtoAlignedStore(parm->value, gep);
} else {
Logger::println("Copying to nested frame");
// The parameter value is an alloca'd stack slot.

View file

@ -58,11 +58,6 @@ struct IrLocal : IrVar {
// represents a function parameter
struct IrParameter : IrLocal {
explicit IrParameter(VarDeclaration *v) : IrLocal(v) {}
IrParameter(VarDeclaration *v, llvm::Value *value) : IrLocal(v, value) {}
IrParameter(VarDeclaration *v, llvm::Value *value, IrFuncTyArg *arg,
bool isVthis = false)
: IrLocal(v, value), arg(arg), isVthis(isVthis) {}
IrFuncTyArg *arg = nullptr;
bool isVthis = false; // true, if it is the 'this' parameter
};