Don't waste an alloca for the nested context argument

And so get rid of all loads too; just use the untouched pointer argument
directly.
This commit is contained in:
Martin 2018-02-11 15:14:18 +01:00 committed by David Nadlinger
parent aa0b1b4e3a
commit c6132508b1
3 changed files with 8 additions and 17 deletions

View file

@ -1098,11 +1098,6 @@ void DtoDefineFunction(FuncDeclaration *fd, bool linkageAvailableExternally) {
gIR->DBuilder.EmitLocalVariable(thismem, fd->vthis, nullptr, true); gIR->DBuilder.EmitLocalVariable(thismem, fd->vthis, nullptr, true);
} }
// give the 'nestArg' parameter (an lvalue) storage
if (irFty.arg_nest) {
irFunc->nestArg = DtoAllocaDump(irFunc->nestArg, 0, "nestedFrame");
}
// define all explicit parameters // define all explicit parameters
if (fd->parameters) if (fd->parameters)
defineParameters(irFty, *fd->parameters); defineParameters(irFty, *fd->parameters);

View file

@ -75,9 +75,8 @@ DValue *DtoNestedVariable(Loc &loc, Type *astype, VarDeclaration *vd,
ctx = DtoLoad(DtoGEPi(val, 0, getVthisIdx(cd), ".vthis")); ctx = DtoLoad(DtoGEPi(val, 0, getVthisIdx(cd), ".vthis"));
skipDIDeclaration = true; skipDIDeclaration = true;
} else { } else {
Logger::println("Regular nested function, loading context arg"); Logger::println("Regular nested function, using context arg");
ctx = irfunc->nestArg;
ctx = DtoLoad(irfunc->nestArg);
} }
assert(ctx); assert(ctx);
@ -224,7 +223,7 @@ LLValue *DtoNestedContext(Loc &loc, Dsymbol *sym) {
fromParent = false; fromParent = false;
} else if (irFunc.nestArg) { } else if (irFunc.nestArg) {
// otherwise, it may have gotten a context from the caller // otherwise, it may have gotten a context from the caller
val = DtoLoad(irFunc.nestArg); val = irFunc.nestArg;
} else if (irFunc.thisArg) { } else if (irFunc.thisArg) {
// or just have a this argument // or just have a this argument
AggregateDeclaration *ad = irFunc.decl->isMember2(); AggregateDeclaration *ad = irFunc.decl->isMember2();
@ -456,8 +455,6 @@ void DtoCreateNestedContext(FuncGenState &funcGen) {
} else { } else {
src = DtoLoad(DtoGEPi(thisval, 0, getVthisIdx(cd), ".vthis")); src = DtoLoad(DtoGEPi(thisval, 0, getVthisIdx(cd), ".vthis"));
} }
} else {
src = DtoLoad(src);
} }
if (depth > 1) { if (depth > 1) {
src = DtoBitCast(src, getVoidPtrType()); src = DtoBitCast(src, getVoidPtrType());

View file

@ -1021,20 +1021,19 @@ public:
assert(!isSpecialRefVar(vd) && "Code not expected to handle special ref " assert(!isSpecialRefVar(vd) && "Code not expected to handle special ref "
"vars, although it can easily be made to."); "vars, although it can easily be made to.");
LLValue *v;
const auto ident = p->func()->decl->ident; const auto ident = p->func()->decl->ident;
if (ident == Id::ensure || ident == Id::require) { if (ident == Id::ensure || ident == Id::require) {
Logger::println("contract this exp"); Logger::println("contract this exp");
v = DtoBitCast(p->func()->nestArg, DtoType(e->type)->getPointerTo()); LLValue *v = DtoBitCast(p->func()->nestArg, DtoType(e->type));
result = new DImValue(e->type, v);
} else if (vd->toParent2() != p->func()->decl) { } else if (vd->toParent2() != p->func()->decl) {
Logger::println("nested this exp"); Logger::println("nested this exp");
result = DtoNestedVariable(e->loc, e->type, vd, e->type->ty == Tstruct); result = DtoNestedVariable(e->loc, e->type, vd, e->type->ty == Tstruct);
return;
} else { } else {
Logger::println("normal this exp"); Logger::println("normal this exp");
v = p->func()->thisArg; LLValue *v = p->func()->thisArg;
result = new DLValue(e->type, DtoBitCast(v, DtoPtrToType(e->type)));
} }
result = new DLValue(e->type, DtoBitCast(v, DtoPtrToType(e->type)));
} }
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
@ -2184,7 +2183,7 @@ public:
// function. Happens with anonymous functions. // function. Happens with anonymous functions.
cval = funcGen.nestedVar; cval = funcGen.nestedVar;
} else if (irfn.nestArg) { } else if (irfn.nestArg) {
cval = DtoLoad(irfn.nestArg); cval = irfn.nestArg;
} else if (irfn.thisArg) { } else if (irfn.thisArg) {
AggregateDeclaration *ad = irfn.decl->isMember2(); AggregateDeclaration *ad = irfn.decl->isMember2();
if (!ad || !ad->vthis) { if (!ad || !ad->vthis) {