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

@ -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.