compiler: only check whether struct or array types are big
Fetching the size of a type typically involves a hash table lookup,
and is generally non-trivial. The escape analysis code calls is_big
more than one might expect. So only fetch the size if we need it.
Change-Id: I44f28030f75c3e993020932631eea46fc6158b30
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/197699
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
diff --git a/go/escape.cc b/go/escape.cc
index db3afc7..91f43a6 100644
--- a/go/escape.cc
+++ b/go/escape.cc
@@ -511,16 +511,28 @@
|| t->is_abstract())
return false;
- int64_t size;
- bool ok = t->backend_type_size(context->gogo(), &size);
- bool big = ok && (size < 0 || size > 10 * 1024 * 1024);
+ bool big = false;
+ if (t->struct_type() != NULL
+ || (t->array_type() != NULL && !t->is_slice_type()))
+ {
+ int64_t size;
+ bool ok = t->backend_type_size(context->gogo(), &size);
+ big = ok && (size < 0 || size > 10 * 1024 * 1024);
+ }
if (this->expr() != NULL)
{
if (this->expr()->allocation_expression() != NULL)
{
- ok = t->deref()->backend_type_size(context->gogo(), &size);
- big = big || size <= 0 || size >= (1 << 16);
+ Type* pt = t->deref();
+ if (pt->struct_type() != NULL
+ || (pt->array_type() != NULL && !pt->is_slice_type()))
+ {
+ int64_t size;
+ bool ok = pt->backend_type_size(context->gogo(), &size);
+ if (ok)
+ big = big || size <= 0 || size >= (1 << 16);
+ }
}
else if (this->expr()->call_expression() != NULL)
{