aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2018-01-09 23:30:37 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2018-01-09 23:30:37 +0000
commiteb80a362bc7b382baf8541e84ccab33a887dd58a (patch)
tree10f75f4863f960463d056f07e7684bacf25e5850 /gcc
parent41a6da2de5102b6052175c82ad2fb2357c9eceab (diff)
downloadgcc-eb80a362bc7b382baf8541e84ccab33a887dd58a.zip
gcc-eb80a362bc7b382baf8541e84ccab33a887dd58a.tar.gz
gcc-eb80a362bc7b382baf8541e84ccab33a887dd58a.tar.bz2
compiler: move some escape check to Mark_address_taken
Move some check of escape state earlier, from get_backend to Mark_address_taken. So we can reclaim escape analysis Nodes before kicking off the backend (not done in this CL). Also it makes it easier to check variables and closures do not escape when the escape analysis is run for the runtime package (also not done in this CL). Reviewed-on: https://go-review.googlesource.com/85735 From-SVN: r256406
Diffstat (limited to 'gcc')
-rw-r--r--gcc/go/gofrontend/MERGE2
-rw-r--r--gcc/go/gofrontend/expressions.cc14
-rw-r--r--gcc/go/gofrontend/expressions.h8
-rw-r--r--gcc/go/gofrontend/wb.cc19
4 files changed, 30 insertions, 13 deletions
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 70dfeeb..b3f314a 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-cf5a64066fa21b20beae0b895c05d26af53e13e0
+584fdecefce831c3471dbd4857ba0ce0be2b5212
The first line of this file holds the git revision number of the last
merge done from the gofrontend repository.
diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc
index 2e0a143..319fc9e 100644
--- a/gcc/go/gofrontend/expressions.cc
+++ b/gcc/go/gofrontend/expressions.cc
@@ -12383,9 +12383,7 @@ Allocation_expression::do_get_backend(Translate_context* context)
Gogo* gogo = context->gogo();
Location loc = this->location();
- Node* n = Node::make_node(this);
- if (this->allocate_on_stack_
- || (n->encoding() & ESCAPE_MASK) == int(Node::ESCAPE_NONE))
+ if (this->allocate_on_stack_)
{
int64_t size;
bool ok = this->type_->backend_type_size(gogo, &size);
@@ -13161,13 +13159,8 @@ Slice_construction_expression::do_get_backend(Translate_context* context)
}
else
{
+ go_assert(this->storage_escapes_ || this->element_count() == 0);
space = Expression::make_heap_expression(this->array_val_, loc);
- Node* n = Node::make_node(this);
- if ((n->encoding() & ESCAPE_MASK) == int(Node::ESCAPE_NONE))
- {
- n = Node::make_node(space);
- n->set_encoding(Node::ESCAPE_NONE);
- }
}
// Build a constructor for the slice.
@@ -14261,8 +14254,7 @@ Heap_expression::do_get_backend(Translate_context* context)
Btype* btype = this->type()->get_backend(gogo);
Expression* alloc = Expression::make_allocation(etype, loc);
- Node* n = Node::make_node(this);
- if ((n->encoding() & ESCAPE_MASK) == int(Node::ESCAPE_NONE))
+ if (this->allocate_on_stack_)
alloc->allocation_expression()->set_allocate_on_stack();
Bexpression* space = alloc->get_backend(context);
diff --git a/gcc/go/gofrontend/expressions.h b/gcc/go/gofrontend/expressions.h
index cb60890..6b00cab 100644
--- a/gcc/go/gofrontend/expressions.h
+++ b/gcc/go/gofrontend/expressions.h
@@ -3870,13 +3870,17 @@ class Heap_expression : public Expression
public:
Heap_expression(Expression* expr, Location location)
: Expression(EXPRESSION_HEAP, location),
- expr_(expr)
+ expr_(expr), allocate_on_stack_(false)
{ }
Expression*
expr() const
{ return this->expr_; }
+ void
+ set_allocate_on_stack()
+ { this->allocate_on_stack_ = true; }
+
protected:
int
do_traverse(Traverse* traverse)
@@ -3910,6 +3914,8 @@ class Heap_expression : public Expression
private:
// The expression which is being put on the heap.
Expression* expr_;
+ // Whether or not this is a stack allocation.
+ bool allocate_on_stack_;
};
// A receive expression.
diff --git a/gcc/go/gofrontend/wb.cc b/gcc/go/gofrontend/wb.cc
index a3f71a4..77a59ac 100644
--- a/gcc/go/gofrontend/wb.cc
+++ b/gcc/go/gofrontend/wb.cc
@@ -65,6 +65,25 @@ Mark_address_taken::expression(Expression** pexpr)
aie->array()->address_taken(escapes);
}
+ if (expr->allocation_expression() != NULL)
+ {
+ Node* n = Node::make_node(expr);
+ if ((n->encoding() & ESCAPE_MASK) == Node::ESCAPE_NONE)
+ expr->allocation_expression()->set_allocate_on_stack();
+ }
+ if (expr->heap_expression() != NULL)
+ {
+ Node* n = Node::make_node(expr);
+ if ((n->encoding() & ESCAPE_MASK) == Node::ESCAPE_NONE)
+ expr->heap_expression()->set_allocate_on_stack();
+ }
+ if (expr->slice_literal() != NULL)
+ {
+ Node* n = Node::make_node(expr);
+ if ((n->encoding() & ESCAPE_MASK) == Node::ESCAPE_NONE)
+ expr->slice_literal()->set_storage_does_not_escape();
+ }
+
// Rewrite non-escaping makeslice with constant size to stack allocation.
Unsafe_type_conversion_expression* uce =
expr->unsafe_conversion_expression();