This is another case where we can say that the address refers to stack.
We create such temps for OSTRUCTLIT initialization.
This eliminates a handful of write barriers today.
But this come up a prerequisite for another change (capturing vars by value),
otherwise we emit writebarriers in writebarrier itself when
capture writebarrier arguments by value.
Change-Id: Ibba93acd0f5431c5a4c3d90ef1e622cb9a7ff50e
Reviewed-on: https://go-review.googlesource.com/3285
Reviewed-by: Russ Cox <rsc@golang.org>
case OAS:
ok |= Etop;
typecheckas(n);
+ // Code that creates temps does not bother to set defn, so do it here.
+ if(n->left->op == ONAME && strncmp(n->left->sym->name, "autotmp_", 8) == 0)
+ n->left->defn = n;
goto ret;
case OAS2:
static int
isstack(Node *n)
{
+ Node *defn;
+
while(n->op == ODOT || n->op == OPAREN || n->op == OCONVNOP || n->op == OINDEX && isfixedarray(n->left->type))
n = n->left;
-
+
+ // If n is *autotmp and autotmp = &foo, replace n with foo.
+ // We introduce such temps when initializing struct literals.
+ if(n->op == OIND && n->left->op == ONAME && strncmp(n->left->sym->name, "autotmp_", 8) == 0) {
+ defn = n->left->defn;
+ if(defn != N && defn->op == OAS && defn->right->op == OADDR)
+ n = defn->right->left;
+ }
+
switch(n->op) {
case OINDREG:
// OINDREG only ends up in walk if it's indirect of SP.