aboutsummaryrefslogtreecommitdiff
path: root/gcc/go/gofrontend
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2020-07-27 15:19:54 -0700
committerIan Lance Taylor <iant@golang.org>2020-07-27 17:05:17 -0700
commit108fdcc56ee49dd7dc8314ce5022191f406a125f (patch)
tree60009bd42da0b9f335a0f4ab9d0179e9db0fd778 /gcc/go/gofrontend
parente1d3a86fd3e91ccdbc702fc99595116adeded0d5 (diff)
downloadgcc-108fdcc56ee49dd7dc8314ce5022191f406a125f.zip
gcc-108fdcc56ee49dd7dc8314ce5022191f406a125f.tar.gz
gcc-108fdcc56ee49dd7dc8314ce5022191f406a125f.tar.bz2
compiler,runtime: pass only ptr and len to some runtime calls
This ports https://golang.org/cl/227163 to the Go frontend. This is a step toward moving up to the go1.15rc1 release. Original CL description: cmd/compile,runtime: pass only ptr and len to some runtime calls Some runtime calls accept a slice, but only use ptr and len. This change modifies most such routines to accept only ptr and len. After this change, the only runtime calls that accept an unnecessary cap arg are concatstrings and slicerunetostring. Neither is particularly common, and both are complicated to modify. Negligible compiler performance impact. Shrinks binaries a little. There are only a few regressions; the one I investigated was due to register allocation fluctuation. Passes 'go test -race std cmd', modulo golang/go#38265 and golang/go#38266. Wow, does that take a long time to run. file before after Δ % compile 19655024 19655152 +128 +0.001% cover 5244840 5236648 -8192 -0.156% dist 3662376 3658280 -4096 -0.112% link 6680056 6675960 -4096 -0.061% pprof 14789844 14777556 -12288 -0.083% test2json 2824744 2820648 -4096 -0.145% trace 11647876 11639684 -8192 -0.070% vet 8260472 8256376 -4096 -0.050% total 115163736 115118808 -44928 -0.039% For golang/go#36890 Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/245099
Diffstat (limited to 'gcc/go/gofrontend')
-rw-r--r--gcc/go/gofrontend/MERGE2
-rw-r--r--gcc/go/gofrontend/expressions.cc60
-rw-r--r--gcc/go/gofrontend/runtime.def13
3 files changed, 40 insertions, 35 deletions
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 12e48c1..64a655e 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-8b9c7fb00ccaf1d4bcc8d581a1a4d46a35771b77
+63bc2430187efe5ff47e9c7b9cd6d40b350ee7d7
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 327f940..90f860b 100644
--- a/gcc/go/gofrontend/expressions.cc
+++ b/gcc/go/gofrontend/expressions.cc
@@ -4157,45 +4157,43 @@ Type_conversion_expression::do_get_backend(Translate_context* context)
go_assert(e->integer_type() != NULL);
go_assert(this->expr_->is_variable());
- Runtime::Function code;
+ Expression* buf;
+ if (this->no_escape_ && !this->no_copy_)
+ {
+ Type* byte_type = Type::lookup_integer_type("uint8");
+ Expression* buflen =
+ Expression::make_integer_ul(tmp_string_buf_size, NULL, loc);
+ Type* array_type = Type::make_array_type(byte_type, buflen);
+ buf = Expression::make_allocation(array_type, loc);
+ buf->allocation_expression()->set_allocate_on_stack();
+ buf->allocation_expression()->set_no_zero();
+ }
+ else
+ buf = Expression::make_nil(loc);
+
if (e->integer_type()->is_byte())
{
+ Expression* ptr =
+ Expression::make_slice_info(this->expr_, SLICE_INFO_VALUE_POINTER,
+ loc);
+ Expression* len =
+ Expression::make_slice_info(this->expr_, SLICE_INFO_LENGTH, loc);
if (this->no_copy_)
{
if (gogo->debug_optimization())
go_debug(loc, "no copy string([]byte)");
- Expression* ptr = Expression::make_slice_info(this->expr_,
- SLICE_INFO_VALUE_POINTER,
- loc);
- Expression* len = Expression::make_slice_info(this->expr_,
- SLICE_INFO_LENGTH,
- loc);
Expression* str = Expression::make_string_value(ptr, len, loc);
return str->get_backend(context);
}
- code = Runtime::SLICEBYTETOSTRING;
+ return Runtime::make_call(Runtime::SLICEBYTETOSTRING, loc, 3, buf,
+ ptr, len)->get_backend(context);
}
else
{
go_assert(e->integer_type()->is_rune());
- code = Runtime::SLICERUNETOSTRING;
- }
-
- Expression* buf;
- if (this->no_escape_)
- {
- Type* byte_type = Type::lookup_integer_type("uint8");
- Expression* buflen =
- Expression::make_integer_ul(tmp_string_buf_size, NULL, loc);
- Type* array_type = Type::make_array_type(byte_type, buflen);
- buf = Expression::make_allocation(array_type, loc);
- buf->allocation_expression()->set_allocate_on_stack();
- buf->allocation_expression()->set_no_zero();
- }
- else
- buf = Expression::make_nil(loc);
- return Runtime::make_call(code, loc, 2, buf,
- this->expr_)->get_backend(context);
+ return Runtime::make_call(Runtime::SLICERUNETOSTRING, loc, 2, buf,
+ this->expr_)->get_backend(context);
+ }
}
else if (type->is_slice_type() && expr_type->is_string_type())
{
@@ -8397,8 +8395,16 @@ Builtin_call_expression::do_flatten(Gogo* gogo, Named_object* function,
if (et->has_pointer())
{
Expression* td = Expression::make_type_descriptor(et, loc);
+ Expression* pd =
+ Expression::make_slice_info(arg1, SLICE_INFO_VALUE_POINTER, loc);
+ Expression* ld =
+ Expression::make_slice_info(arg1, SLICE_INFO_LENGTH, loc);
+ Expression* ps =
+ Expression::make_slice_info(arg2, SLICE_INFO_VALUE_POINTER, loc);
+ Expression* ls =
+ Expression::make_slice_info(arg2, SLICE_INFO_LENGTH, loc);
ret = Runtime::make_call(Runtime::TYPEDSLICECOPY, loc,
- 3, td, arg1, arg2);
+ 5, td, pd, ld, ps, ls);
}
else
{
diff --git a/gcc/go/gofrontend/runtime.def b/gcc/go/gofrontend/runtime.def
index 2ef0f94..a950079 100644
--- a/gcc/go/gofrontend/runtime.def
+++ b/gcc/go/gofrontend/runtime.def
@@ -47,7 +47,7 @@ DEF_GO_RUNTIME(INTSTRING, "runtime.intstring", P2(POINTER, INT64), R1(STRING))
// Convert a []byte to a string.
DEF_GO_RUNTIME(SLICEBYTETOSTRING, "runtime.slicebytetostring",
- P2(POINTER, SLICE), R1(STRING))
+ P3(POINTER, POINTER, INT), R1(STRING))
// Convert a []rune to a string.
DEF_GO_RUNTIME(SLICERUNETOSTRING, "runtime.slicerunetostring",
@@ -249,17 +249,16 @@ DEF_GO_RUNTIME(CLOSE, "runtime.closechan", P1(CHAN), R0())
// Copy.
-DEF_GO_RUNTIME(SLICECOPY, "runtime.slicecopy", P3(SLICE, SLICE, UINTPTR),
- R1(INT))
+DEF_GO_RUNTIME(SLICECOPY, "runtime.slicecopy",
+ P5(POINTER, INT, POINTER, INT, UINTPTR), R1(INT))
// Copy from string.
-DEF_GO_RUNTIME(SLICESTRINGCOPY, "runtime.slicestringcopy", P2(SLICE, STRING),
- R1(INT))
+DEF_GO_RUNTIME(SLICESTRINGCOPY, "runtime.slicestringcopy",
+ P3(POINTER, INT, STRING), R1(INT))
// Copy of value containing pointers.
DEF_GO_RUNTIME(TYPEDSLICECOPY, "runtime.typedslicecopy",
- P3(TYPE, SLICE, SLICE), R1(INT))
-
+ P5(TYPE, POINTER, INT, POINTER, INT), R1(INT))
// Grow a slice for append.
DEF_GO_RUNTIME(GROWSLICE, "runtime.growslice",