diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2017-09-14 03:57:18 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2017-09-14 03:57:18 +0000 |
commit | 022aa0ce5eebafe60f20245c8ff26b60a5074dfd (patch) | |
tree | 4cff4e3e7be2beb8a86e66e9f1d6346a9e55fb36 /gcc | |
parent | 0468f67f27f49972dcd77758284a2709bd9249fe (diff) | |
download | gcc-022aa0ce5eebafe60f20245c8ff26b60a5074dfd.zip gcc-022aa0ce5eebafe60f20245c8ff26b60a5074dfd.tar.gz gcc-022aa0ce5eebafe60f20245c8ff26b60a5074dfd.tar.bz2 |
compiler, runtime: simplify select and channel operations
In preparation for upgrading libgo to the 1.9 release, this
approximately incorporates https://golang.org/cl/37661 and
https://golang.org/cl/38351.
CL 37661 changed the gc compiler such that the select statement simply
returns an integer which is then used as the argument for a switch.
Since gccgo already worked that way, this just adjusts the switch code
to look like the gc switch code by removing the explicit case index
expression and calculating it from the order of calls to selectsend,
selectrecv, and selectdefault.
CL 38351 simplifies the channel code by not passing the unused channel
type descriptor pointer.
Reviewed-on: https://go-review.googlesource.com/62730
From-SVN: r252749
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/go/gofrontend/MERGE | 2 | ||||
-rw-r--r-- | gcc/go/gofrontend/expressions.cc | 5 | ||||
-rw-r--r-- | gcc/go/gofrontend/runtime.def | 26 | ||||
-rw-r--r-- | gcc/go/gofrontend/statements.cc | 54 | ||||
-rw-r--r-- | gcc/go/gofrontend/statements.h | 32 |
5 files changed, 44 insertions, 75 deletions
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index 7c78efc..b07bce8 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -1,4 +1,4 @@ -0176cbc6dbd2170bfe2eb8904b80ddfe4c946997 +199f175f4239d1ca6d7e80d08639955d41c3b09f 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 82de4d8..8816232 100644 --- a/gcc/go/gofrontend/expressions.cc +++ b/gcc/go/gofrontend/expressions.cc @@ -14463,15 +14463,14 @@ Receive_expression::do_get_backend(Translate_context* context) go_assert(this->channel_->type()->is_error()); return context->backend()->error_expression(); } - Expression* td = Expression::make_type_descriptor(channel_type, loc); Expression* recv_ref = Expression::make_temporary_reference(this->temp_receiver_, loc); Expression* recv_addr = Expression::make_temporary_reference(this->temp_receiver_, loc); recv_addr = Expression::make_unary(OPERATOR_AND, recv_addr, loc); - Expression* recv = Runtime::make_call(Runtime::CHANRECV1, loc, 3, - td, this->channel_, recv_addr); + Expression* recv = Runtime::make_call(Runtime::CHANRECV1, loc, 2, + this->channel_, recv_addr); return Expression::make_compound(recv, recv_ref, loc)->get_backend(context); } diff --git a/gcc/go/gofrontend/runtime.def b/gcc/go/gofrontend/runtime.def index 635b7fe..6df5349 100644 --- a/gcc/go/gofrontend/runtime.def +++ b/gcc/go/gofrontend/runtime.def @@ -137,39 +137,31 @@ DEF_GO_RUNTIME(MAPITERNEXT, "runtime.mapiternext", P1(POINTER), R0()) DEF_GO_RUNTIME(MAKECHAN, "runtime.makechan", P2(TYPE, INT64), R1(CHAN)) // Send a value on a channel. -DEF_GO_RUNTIME(CHANSEND, "runtime.chansend1", P3(TYPE, CHAN, POINTER), R0()) +DEF_GO_RUNTIME(CHANSEND, "runtime.chansend1", P2(CHAN, POINTER), R0()) // Receive a value from a channel. -DEF_GO_RUNTIME(CHANRECV1, "runtime.chanrecv1", P3(TYPE, CHAN, POINTER), R0()) +DEF_GO_RUNTIME(CHANRECV1, "runtime.chanrecv1", P2(CHAN, POINTER), R0()) // Receive a value from a channel returning whether it is closed. -DEF_GO_RUNTIME(CHANRECV2, "runtime.chanrecv2", P3(TYPE, CHAN, POINTER), - R1(BOOL)) +DEF_GO_RUNTIME(CHANRECV2, "runtime.chanrecv2", P2(CHAN, POINTER), R1(BOOL)) // Start building a select statement. DEF_GO_RUNTIME(NEWSELECT, "runtime.newselect", P3(POINTER, INT64, INT32), R0()) // Add a default clause to a select statement. -DEF_GO_RUNTIME(SELECTDEFAULT, "runtime.selectdefault", - P2(POINTER, INT32), R0()) +DEF_GO_RUNTIME(SELECTDEFAULT, "runtime.selectdefault", P1(POINTER), R0()) // Add a send clause to a select statement. -DEF_GO_RUNTIME(SELECTSEND, "runtime.selectsend", - P4(POINTER, CHAN, POINTER, INT32), R0()) +DEF_GO_RUNTIME(SELECTSEND, "runtime.selectsend", P3(POINTER, CHAN, POINTER), + R0()) -// Add a receive clause to a select statement, for a clause which does -// not check whether the channel is closed. +// Add a receive clause to a select statement. DEF_GO_RUNTIME(SELECTRECV, "runtime.selectrecv", - P4(POINTER, CHAN, POINTER, INT32), R0()) - -// Add a receive clause to a select statement, for a clause which does -// check whether the channel is closed. -DEF_GO_RUNTIME(SELECTRECV2, "runtime.selectrecv2", - P5(POINTER, CHAN, POINTER, BOOLPTR, INT32), R0()) + P4(POINTER, CHAN, POINTER, BOOLPTR), R0()) // Run a select, returning the index of the selected clause. -DEF_GO_RUNTIME(SELECTGO, "runtime.selectgo", P1(POINTER), R1(INT32)) +DEF_GO_RUNTIME(SELECTGO, "runtime.selectgo", P1(POINTER), R1(INT)) // Panic. diff --git a/gcc/go/gofrontend/statements.cc b/gcc/go/gofrontend/statements.cc index e592176..eb370f8 100644 --- a/gcc/go/gofrontend/statements.cc +++ b/gcc/go/gofrontend/statements.cc @@ -1517,14 +1517,12 @@ Tuple_receive_assignment_statement::do_lower(Gogo*, Named_object*, NULL, loc); b->add_statement(closed_temp); - // closed_temp = chanrecv2(type, channel, &val_temp) - Expression* td = Expression::make_type_descriptor(this->channel_->type(), - loc); + // closed_temp = chanrecv2(channel, &val_temp) Temporary_reference_expression* ref = Expression::make_temporary_reference(val_temp, loc); Expression* p2 = Expression::make_unary(OPERATOR_AND, ref, loc); Expression* call = Runtime::make_call(Runtime::CHANRECV2, - loc, 3, td, this->channel_, p2); + loc, 2, this->channel_, p2); ref = Expression::make_temporary_reference(closed_temp, loc); ref->set_is_lvalue(); Statement* s = Statement::make_assignment(ref, call, loc); @@ -4516,9 +4514,6 @@ Send_statement::do_get_backend(Translate_context* context) && val->temporary_reference_expression() == NULL) can_take_address = false; - Expression* td = Expression::make_type_descriptor(this->channel_->type(), - loc); - Bstatement* btemp = NULL; if (can_take_address) { @@ -4539,7 +4534,7 @@ Send_statement::do_get_backend(Translate_context* context) btemp = temp->get_backend(context); } - Expression* call = Runtime::make_call(Runtime::CHANSEND, loc, 3, td, + Expression* call = Runtime::make_call(Runtime::CHANSEND, loc, 2, this->channel_, val); context->gogo()->lower_expression(context->function(), NULL, &call); @@ -4621,13 +4616,10 @@ Select_clauses::Select_clause::lower(Gogo* gogo, Named_object* function, Expression* selref = Expression::make_temporary_reference(sel, loc); selref = Expression::make_unary(OPERATOR_AND, selref, loc); - Expression* index_expr = Expression::make_integer_ul(this->index_, NULL, - loc); - if (this->is_default_) { go_assert(this->channel_ == NULL && this->val_ == NULL); - this->lower_default(b, selref, index_expr); + this->lower_default(b, selref); this->is_lowered_ = true; return; } @@ -4641,9 +4633,9 @@ Select_clauses::Select_clause::lower(Gogo* gogo, Named_object* function, loc); if (this->is_send_) - this->lower_send(b, selref, chanref, index_expr); + this->lower_send(b, selref, chanref); else - this->lower_recv(gogo, function, b, selref, chanref, index_expr); + this->lower_recv(gogo, function, b, selref, chanref); // Now all references should be handled through the statements, not // through here. @@ -4654,12 +4646,11 @@ Select_clauses::Select_clause::lower(Gogo* gogo, Named_object* function, // Lower a default clause in a select statement. void -Select_clauses::Select_clause::lower_default(Block* b, Expression* selref, - Expression* index_expr) +Select_clauses::Select_clause::lower_default(Block* b, Expression* selref) { Location loc = this->location_; - Expression* call = Runtime::make_call(Runtime::SELECTDEFAULT, loc, 2, selref, - index_expr); + Expression* call = Runtime::make_call(Runtime::SELECTDEFAULT, loc, 1, + selref); b->add_statement(Statement::make_statement(call, true)); } @@ -4667,8 +4658,7 @@ Select_clauses::Select_clause::lower_default(Block* b, Expression* selref, void Select_clauses::Select_clause::lower_send(Block* b, Expression* selref, - Expression* chanref, - Expression* index_expr) + Expression* chanref) { Location loc = this->location_; @@ -4687,8 +4677,8 @@ Select_clauses::Select_clause::lower_send(Block* b, Expression* selref, Expression* valref = Expression::make_temporary_reference(val, loc); Expression* valaddr = Expression::make_unary(OPERATOR_AND, valref, loc); - Expression* call = Runtime::make_call(Runtime::SELECTSEND, loc, 4, selref, - chanref, valaddr, index_expr); + Expression* call = Runtime::make_call(Runtime::SELECTSEND, loc, 3, selref, + chanref, valaddr); b->add_statement(Statement::make_statement(call, true)); } @@ -4697,8 +4687,7 @@ Select_clauses::Select_clause::lower_send(Block* b, Expression* selref, void Select_clauses::Select_clause::lower_recv(Gogo* gogo, Named_object* function, Block* b, Expression* selref, - Expression* chanref, - Expression* index_expr) + Expression* chanref) { Location loc = this->location_; @@ -4715,10 +4704,9 @@ Select_clauses::Select_clause::lower_recv(Gogo* gogo, Named_object* function, Temporary_statement* closed_temp = NULL; - Expression* call; + Expression* caddr; if (this->closed_ == NULL && this->closedvar_ == NULL) - call = Runtime::make_call(Runtime::SELECTRECV, loc, 4, selref, chanref, - valaddr, index_expr); + caddr = Expression::make_nil(loc); else { closed_temp = Statement::make_temporary(Type::lookup_bool_type(), NULL, @@ -4726,11 +4714,12 @@ Select_clauses::Select_clause::lower_recv(Gogo* gogo, Named_object* function, b->add_statement(closed_temp); Expression* cref = Expression::make_temporary_reference(closed_temp, loc); - Expression* caddr = Expression::make_unary(OPERATOR_AND, cref, loc); - call = Runtime::make_call(Runtime::SELECTRECV2, loc, 5, selref, chanref, - valaddr, caddr, index_expr); + caddr = Expression::make_unary(OPERATOR_AND, cref, loc); } + Expression* call = Runtime::make_call(Runtime::SELECTRECV, loc, 4, selref, + chanref, valaddr, caddr); + b->add_statement(Statement::make_statement(call, true)); // If the block of statements is executed, arrange for the received @@ -4958,15 +4947,14 @@ Select_clauses::get_backend(Translate_context* context, std::vector<std::vector<Bexpression*> > cases(count); std::vector<Bstatement*> clauses(count); - Type* int32_type = Type::lookup_integer_type("int32"); + Type* int_type = Type::lookup_integer_type("int"); int i = 0; for (Clauses::iterator p = this->clauses_.begin(); p != this->clauses_.end(); ++p, ++i) { - int index = p->index(); - Expression* index_expr = Expression::make_integer_ul(index, int32_type, + Expression* index_expr = Expression::make_integer_ul(i, int_type, location); cases[i].push_back(index_expr->get_backend(context)); diff --git a/gcc/go/gofrontend/statements.h b/gcc/go/gofrontend/statements.h index dac99de..852ab43 100644 --- a/gcc/go/gofrontend/statements.h +++ b/gcc/go/gofrontend/statements.h @@ -899,10 +899,9 @@ class Select_clauses Named_object* var, Named_object* closedvar, bool is_default, Block* statements, Location location) { - int index = static_cast<int>(this->clauses_.size()); - this->clauses_.push_back(Select_clause(index, is_send, channel, val, - closed, var, closedvar, is_default, - statements, location)); + this->clauses_.push_back(Select_clause(is_send, channel, val, closed, var, + closedvar, is_default, statements, + location)); } size_t @@ -950,21 +949,15 @@ class Select_clauses is_default_(false) { } - Select_clause(int index, bool is_send, Expression* channel, - Expression* val, Expression* closed, Named_object* var, + Select_clause(bool is_send, Expression* channel, Expression* val, + Expression* closed, Named_object* var, Named_object* closedvar, bool is_default, Block* statements, Location location) - : index_(index), channel_(channel), val_(val), closed_(closed), - var_(var), closedvar_(closedvar), statements_(statements), - location_(location), is_send_(is_send), is_default_(is_default), - is_lowered_(false) + : channel_(channel), val_(val), closed_(closed), var_(var), + closedvar_(closedvar), statements_(statements), location_(location), + is_send_(is_send), is_default_(is_default), is_lowered_(false) { go_assert(is_default ? channel == NULL : channel != NULL); } - // Return the index of this clause. - int - index() const - { return this->index_; } - // Traverse the select clause. int traverse(Traverse*); @@ -1025,17 +1018,14 @@ class Select_clauses private: void - lower_default(Block*, Expression*, Expression*); + lower_default(Block*, Expression*); void - lower_send(Block*, Expression*, Expression*, Expression*); + lower_send(Block*, Expression*, Expression*); void - lower_recv(Gogo*, Named_object*, Block*, Expression*, Expression*, - Expression*); + lower_recv(Gogo*, Named_object*, Block*, Expression*, Expression*); - // The index of this case in the generated switch statement. - int index_; // The channel. Expression* channel_; // The value to send or the lvalue to receive into. |