From c6132508b1e11a76d24cbb744b452775a686fdae Mon Sep 17 00:00:00 2001 From: Martin Date: Sun, 11 Feb 2018 15:14:18 +0100 Subject: [PATCH] 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. --- gen/functions.cpp | 5 ----- gen/nested.cpp | 9 +++------ gen/toir.cpp | 11 +++++------ 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/gen/functions.cpp b/gen/functions.cpp index be326938af..ad56713401 100644 --- a/gen/functions.cpp +++ b/gen/functions.cpp @@ -1098,11 +1098,6 @@ void DtoDefineFunction(FuncDeclaration *fd, bool linkageAvailableExternally) { 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 if (fd->parameters) defineParameters(irFty, *fd->parameters); diff --git a/gen/nested.cpp b/gen/nested.cpp index 9cd813fc86..ae6116347f 100644 --- a/gen/nested.cpp +++ b/gen/nested.cpp @@ -75,9 +75,8 @@ DValue *DtoNestedVariable(Loc &loc, Type *astype, VarDeclaration *vd, ctx = DtoLoad(DtoGEPi(val, 0, getVthisIdx(cd), ".vthis")); skipDIDeclaration = true; } else { - Logger::println("Regular nested function, loading context arg"); - - ctx = DtoLoad(irfunc->nestArg); + Logger::println("Regular nested function, using context arg"); + ctx = irfunc->nestArg; } assert(ctx); @@ -224,7 +223,7 @@ LLValue *DtoNestedContext(Loc &loc, Dsymbol *sym) { fromParent = false; } else if (irFunc.nestArg) { // otherwise, it may have gotten a context from the caller - val = DtoLoad(irFunc.nestArg); + val = irFunc.nestArg; } else if (irFunc.thisArg) { // or just have a this argument AggregateDeclaration *ad = irFunc.decl->isMember2(); @@ -456,8 +455,6 @@ void DtoCreateNestedContext(FuncGenState &funcGen) { } else { src = DtoLoad(DtoGEPi(thisval, 0, getVthisIdx(cd), ".vthis")); } - } else { - src = DtoLoad(src); } if (depth > 1) { src = DtoBitCast(src, getVoidPtrType()); diff --git a/gen/toir.cpp b/gen/toir.cpp index 60dd2fd490..de42d91f5d 100644 --- a/gen/toir.cpp +++ b/gen/toir.cpp @@ -1021,20 +1021,19 @@ public: assert(!isSpecialRefVar(vd) && "Code not expected to handle special ref " "vars, although it can easily be made to."); - LLValue *v; const auto ident = p->func()->decl->ident; if (ident == Id::ensure || ident == Id::require) { 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) { Logger::println("nested this exp"); result = DtoNestedVariable(e->loc, e->type, vd, e->type->ty == Tstruct); - return; } else { 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. cval = funcGen.nestedVar; } else if (irfn.nestArg) { - cval = DtoLoad(irfn.nestArg); + cval = irfn.nestArg; } else if (irfn.thisArg) { AggregateDeclaration *ad = irfn.decl->isMember2(); if (!ad || !ad->vthis) {