Commit a7bb3936 authored by Dmitry Vyukov's avatar Dmitry Vyukov

cmd/gc: don't emit write barriers for *tmp if tmp=&PAUTO

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/3285Reviewed-by: 's avatarRuss Cox <rsc@golang.org>
parent 9a36beb2
...@@ -1666,6 +1666,9 @@ reswitch: ...@@ -1666,6 +1666,9 @@ reswitch:
case OAS: case OAS:
ok |= Etop; ok |= Etop;
typecheckas(n); 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; goto ret;
case OAS2: case OAS2:
......
...@@ -1920,9 +1920,19 @@ callnew(Type *t) ...@@ -1920,9 +1920,19 @@ callnew(Type *t)
static int static int
isstack(Node *n) isstack(Node *n)
{ {
Node *defn;
while(n->op == ODOT || n->op == OPAREN || n->op == OCONVNOP || n->op == OINDEX && isfixedarray(n->left->type)) while(n->op == ODOT || n->op == OPAREN || n->op == OCONVNOP || n->op == OINDEX && isfixedarray(n->left->type))
n = n->left; 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) { switch(n->op) {
case OINDREG: case OINDREG:
// OINDREG only ends up in walk if it's indirect of SP. // OINDREG only ends up in walk if it's indirect of SP.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment