mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-01 15:40:55 +03:00
Try to boil down special cases in nested.cpp
This commit is contained in:
parent
f4ccde3c24
commit
a6a6786d8d
3 changed files with 16 additions and 66 deletions
|
@ -605,13 +605,10 @@ void DtoDeclareFunction(FuncDeclaration *fdecl) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Dsymbol *const argsym = (*fdecl->parameters)[arg->parametersIdx];
|
auto *const vd = (*fdecl->parameters)[arg->parametersIdx];
|
||||||
VarDeclaration *argvd = argsym->isVarDeclaration();
|
iarg->setName(vd->ident->toChars() + llvm::Twine("_arg"));
|
||||||
assert(argvd);
|
|
||||||
|
|
||||||
iarg->setName(argvd->ident->toChars() + llvm::Twine("_arg"));
|
IrParameter *irParam = getIrParameter(vd, true);
|
||||||
|
|
||||||
IrParameter *irParam = getIrParameter(argvd, true);
|
|
||||||
irParam->arg = arg;
|
irParam->arg = arg;
|
||||||
irParam->value = &(*iarg);
|
irParam->value = &(*iarg);
|
||||||
}
|
}
|
||||||
|
@ -908,10 +905,7 @@ void DtoDefineFunction(FuncDeclaration *fd) {
|
||||||
// index in the IrFuncTy args array separately.
|
// index in the IrFuncTy args array separately.
|
||||||
size_t llArgIdx = 0;
|
size_t llArgIdx = 0;
|
||||||
for (size_t i = 0; i < fd->parameters->dim; ++i) {
|
for (size_t i = 0; i < fd->parameters->dim; ++i) {
|
||||||
Dsymbol *const argsym = (*fd->parameters)[i];
|
auto *const vd = (*fd->parameters)[i];
|
||||||
VarDeclaration *const vd = argsym->isVarDeclaration();
|
|
||||||
assert(vd);
|
|
||||||
const bool refout = vd->storage_class & (STCref | STCout);
|
|
||||||
|
|
||||||
IrParameter *irparam = getIrParameter(vd);
|
IrParameter *irparam = getIrParameter(vd);
|
||||||
Type *debugInfoType = vd->type;
|
Type *debugInfoType = vd->type;
|
||||||
|
@ -922,9 +916,7 @@ void DtoDefineFunction(FuncDeclaration *fd) {
|
||||||
irparam = getIrParameter(vd, true);
|
irparam = getIrParameter(vd, true);
|
||||||
irparam->value = DtoAlloca(vd, vd->ident->toChars());
|
irparam->value = DtoAlloca(vd, vd->ident->toChars());
|
||||||
} else {
|
} else {
|
||||||
const bool lazy = vd->storage_class & STClazy;
|
if (!irparam->arg->byref) {
|
||||||
const bool firstClassVal = !refout && (!irparam->arg->byref || lazy);
|
|
||||||
if (firstClassVal) {
|
|
||||||
// alloca a stack slot for this first class value arg
|
// alloca a stack slot for this first class value arg
|
||||||
LLValue *mem = DtoAlloca(irparam->arg->type, vd->ident->toChars());
|
LLValue *mem = DtoAlloca(irparam->arg->type, vd->ident->toChars());
|
||||||
|
|
||||||
|
@ -939,11 +931,8 @@ void DtoDefineFunction(FuncDeclaration *fd) {
|
||||||
++llArgIdx;
|
++llArgIdx;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (global.params.symdebug &&
|
if (global.params.symdebug)
|
||||||
!(isaArgument(irparam->value) &&
|
|
||||||
isaArgument(irparam->value)->hasByValAttr())) {
|
|
||||||
gIR->DBuilder.EmitLocalVariable(irparam->value, vd, debugInfoType);
|
gIR->DBuilder.EmitLocalVariable(irparam->value, vd, debugInfoType);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,23 +19,6 @@
|
||||||
#include "ir/irtypeaggr.h"
|
#include "ir/irtypeaggr.h"
|
||||||
#include "llvm/Analysis/ValueTracking.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) {
|
static unsigned getVthisIdx(AggregateDeclaration *ad) {
|
||||||
return getFieldGEPIndex(ad, ad->vthis);
|
return getFieldGEPIndex(ad, ad->vthis);
|
||||||
}
|
}
|
||||||
|
@ -161,8 +144,7 @@ DValue *DtoNestedVariable(Loc &loc, Type *astype, VarDeclaration *vd,
|
||||||
Logger::cout() << "Addr: " << *val << '\n';
|
Logger::cout() << "Addr: " << *val << '\n';
|
||||||
Logger::cout() << "of type: " << *val->getType() << '\n';
|
Logger::cout() << "of type: " << *val->getType() << '\n';
|
||||||
}
|
}
|
||||||
if (byref || (vd->isParameter() && getIrParameter(vd)->arg &&
|
if (!isSpecialRefVar(vd) && (byref || vd->isRef() || vd->isOut())) {
|
||||||
getIrParameter(vd)->arg->byref)) {
|
|
||||||
val = DtoAlignedLoad(val);
|
val = DtoAlignedLoad(val);
|
||||||
// dwarfOpDeref(dwarfAddr);
|
// dwarfOpDeref(dwarfAddr);
|
||||||
IF_LOG {
|
IF_LOG {
|
||||||
|
@ -402,31 +384,12 @@ static void DtoCreateNestedContextType(FuncDeclaration *fd) {
|
||||||
irLocal.nestedDepth = depth;
|
irLocal.nestedDepth = depth;
|
||||||
|
|
||||||
LLType *t = nullptr;
|
LLType *t = nullptr;
|
||||||
if (vd->isParameter() && getIrParameter(vd)->arg) {
|
if (vd->isRef() || vd->isOut())
|
||||||
// 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)) {
|
|
||||||
t = DtoType(vd->type->pointerTo());
|
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);
|
t = DtoMemType(vd->type);
|
||||||
}
|
|
||||||
|
|
||||||
builder.addType(t, getTypeAllocSize(t));
|
builder.addType(t, getTypeAllocSize(t));
|
||||||
|
|
||||||
|
@ -517,9 +480,12 @@ void DtoCreateNestedContext(FuncDeclaration *fd) {
|
||||||
IF_LOG Logger::println("nested param: %s", vd->toChars());
|
IF_LOG Logger::println("nested param: %s", vd->toChars());
|
||||||
LOG_SCOPE
|
LOG_SCOPE
|
||||||
IrParameter *parm = getIrParameter(vd);
|
IrParameter *parm = getIrParameter(vd);
|
||||||
|
assert(parm->value);
|
||||||
|
assert(parm->value->getType()->isPointerTy());
|
||||||
|
|
||||||
if (parm->arg && parm->arg->byref) {
|
if (vd->isRef() || vd->isOut()) {
|
||||||
storeVariable(vd, gep);
|
Logger::println("Captured by reference, copying pointer to nested frame");
|
||||||
|
DtoAlignedStore(parm->value, gep);
|
||||||
} else {
|
} else {
|
||||||
Logger::println("Copying to nested frame");
|
Logger::println("Copying to nested frame");
|
||||||
// The parameter value is an alloca'd stack slot.
|
// The parameter value is an alloca'd stack slot.
|
||||||
|
|
|
@ -58,11 +58,6 @@ struct IrLocal : IrVar {
|
||||||
// represents a function parameter
|
// represents a function parameter
|
||||||
struct IrParameter : IrLocal {
|
struct IrParameter : IrLocal {
|
||||||
explicit IrParameter(VarDeclaration *v) : IrLocal(v) {}
|
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;
|
IrFuncTyArg *arg = nullptr;
|
||||||
bool isVthis = false; // true, if it is the 'this' parameter
|
bool isVthis = false; // true, if it is the 'this' parameter
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue