From: Ian Lance Taylor Date: Mon, 15 Jan 2018 19:35:44 +0000 (+0000) Subject: compiler: reclaim memory of escape analysis Nodes X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=97a78e3396d4b901800f43f1075058f876a86058;p=gcc.git compiler: reclaim memory of escape analysis Nodes Reclaim the memory of escape analysis Nodes before kicking off the backend, as they are not needed in get_backend. Reviewed-on: https://go-review.googlesource.com/86243 From-SVN: r256707 --- diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index 8f5e4ba6866..e948fed7321 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -1,4 +1,4 @@ -afac7d7bed07ebe3add1784aaa9547c4d660d0ed +ff851e1190923f8612004c6c214a7c202471b0ba 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/escape.cc b/gcc/go/gofrontend/escape.cc index 2e9798ea741..01329e10eb1 100644 --- a/gcc/go/gofrontend/escape.cc +++ b/gcc/go/gofrontend/escape.cc @@ -445,6 +445,17 @@ Node::state(Escape_context* context, Named_object* fn) return this->state_; } +Node::~Node() +{ + if (this->state_ != NULL) + { + if (this->expr() == NULL || this->expr()->var_expression() == NULL) + // Var expression Node is excluded since it shares state with the + // underlying var Node. + delete this->state_; + } +} + int Node::encoding() { @@ -552,6 +563,7 @@ Node::is_sink() const std::map Node::objects; std::map Node::expressions; std::map Node::statements; +std::vector Node::indirects; // Make a object node or return a cached node for this object. @@ -601,6 +613,7 @@ Node* Node::make_indirect_node(Node* child) { Node* n = new Node(child); + Node::indirects.push_back(n); return n; } @@ -3335,3 +3348,39 @@ Gogo::tag_function(Escape_context* context, Named_object* fn) Escape_analysis_tag eat(context); eat.tag(fn); } + +// Reclaim memory of escape analysis Nodes. + +void +Gogo::reclaim_escape_nodes() +{ + Node::reclaim_nodes(); +} + +void +Node::reclaim_nodes() +{ + for (std::map::iterator p = Node::objects.begin(); + p != Node::objects.end(); + ++p) + delete p->second; + Node::objects.clear(); + + for (std::map::iterator p = Node::expressions.begin(); + p != Node::expressions.end(); + ++p) + delete p->second; + Node::expressions.clear(); + + for (std::map::iterator p = Node::statements.begin(); + p != Node::statements.end(); + ++p) + delete p->second; + Node::statements.clear(); + + for (std::vector::iterator p = Node::indirects.begin(); + p != Node::indirects.end(); + ++p) + delete *p; + Node::indirects.clear(); +} diff --git a/gcc/go/gofrontend/escape.h b/gcc/go/gofrontend/escape.h index ac72b19a2a3..88e23ce204d 100644 --- a/gcc/go/gofrontend/escape.h +++ b/gcc/go/gofrontend/escape.h @@ -191,6 +191,8 @@ class Node child_(n) {} + ~Node(); + // Return this node's type. Type* type() const; @@ -296,6 +298,10 @@ class Node static int note_inout_flows(int e, int index, Level level); + // Reclaim nodes. + static void + reclaim_nodes(); + private: // The classification of this Node. Node_classification classification_; @@ -326,6 +332,10 @@ class Node static std::map objects; static std::map expressions; static std::map statements; + + // Collection of all NODE_INDIRECT Nodes, used for reclaiming memory. This + // is not a cache -- each make_indirect_node will make a fresh Node. + static std::vector indirects; }; // The amount of bits used for the escapement encoding. diff --git a/gcc/go/gofrontend/go.cc b/gcc/go/gofrontend/go.cc index 62a8a65609c..5f08eea3fe3 100644 --- a/gcc/go/gofrontend/go.cc +++ b/gcc/go/gofrontend/go.cc @@ -167,6 +167,9 @@ go_parse_input_files(const char** filenames, unsigned int filename_count, // Flatten the parse tree. ::gogo->flatten(); + // Reclaim memory of escape analysis Nodes. + ::gogo->reclaim_escape_nodes(); + // Dump ast, use filename[0] as the base name ::gogo->dump_ast(filenames[0]); } diff --git a/gcc/go/gofrontend/gogo.h b/gcc/go/gofrontend/gogo.h index c16788cf4ae..f7f8d602bd1 100644 --- a/gcc/go/gofrontend/gogo.h +++ b/gcc/go/gofrontend/gogo.h @@ -682,6 +682,10 @@ class Gogo void tag_function(Escape_context*, Named_object*); + // Reclaim memory of escape analysis Nodes. + void + reclaim_escape_nodes(); + // Do all exports. void do_exports();