Commit 40bb0243 by Ian Lance Taylor

compiler: Don't create a closure if not needed.

From-SVN: r187897
parent 31a18a7e
...@@ -1312,30 +1312,18 @@ Func_expression::do_get_tree(Translate_context* context) ...@@ -1312,30 +1312,18 @@ Func_expression::do_get_tree(Translate_context* context)
&& TREE_CODE(TREE_OPERAND(fnaddr, 0)) == FUNCTION_DECL); && TREE_CODE(TREE_OPERAND(fnaddr, 0)) == FUNCTION_DECL);
TREE_ADDRESSABLE(TREE_OPERAND(fnaddr, 0)) = 1; TREE_ADDRESSABLE(TREE_OPERAND(fnaddr, 0)) = 1;
// For a normal non-nested function call, that is all we have to do. // If there is no closure, that is all have to do.
if (!this->function_->is_function() if (this->closure_ == NULL)
|| this->function_->func_value()->enclosing() == NULL) return fnaddr;
{
go_assert(this->closure_ == NULL);
return fnaddr;
}
// For a nested function call, we have to always allocate a go_assert(this->function_->func_value()->enclosing() != NULL);
// trampoline. If we don't always allocate, then closures will not
// be reliably distinct. // Get the value of the closure. This will be a pointer to space
Expression* closure = this->closure_; // allocated on the heap.
tree closure_tree; tree closure_tree = this->closure_->get_tree(context);
if (closure == NULL) if (closure_tree == error_mark_node)
closure_tree = null_pointer_node; return error_mark_node;
else go_assert(POINTER_TYPE_P(TREE_TYPE(closure_tree)));
{
// Get the value of the closure. This will be a pointer to
// space allocated on the heap.
closure_tree = closure->get_tree(context);
if (closure_tree == error_mark_node)
return error_mark_node;
go_assert(POINTER_TYPE_P(TREE_TYPE(closure_tree)));
}
// Now we need to build some code on the heap. This code will load // Now we need to build some code on the heap. This code will load
// the static chain pointer with the closure and then jump to the // the static chain pointer with the closure and then jump to the
......
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