From 20b603dba4bea71cbdf9dde7db44d6b5bbcb7654 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Wed, 19 Jun 2019 04:53:51 +0000 Subject: compiler: stack allocate a buffer for non-escaping string ops For string concatenation, string to/from byte or rune slice conversion, and int to string conversion, if the result does not escape, we can allocate a small (32-element, or 4-byte for int to string) buffer on stack, and pass it to the runtime function. If the result fits in the buffer, it doesn't need to do a heap allocation. Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/182538 From-SVN: r272468 --- gcc/go/gofrontend/expressions.h | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'gcc/go/gofrontend/expressions.h') diff --git a/gcc/go/gofrontend/expressions.h b/gcc/go/gofrontend/expressions.h index 1595eb1..38dee04 100644 --- a/gcc/go/gofrontend/expressions.h +++ b/gcc/go/gofrontend/expressions.h @@ -1822,9 +1822,8 @@ class Type_conversion_expression : public Expression // True if a string([]byte) conversion can reuse the backing store // without copying. Only used in string([]byte) conversion. bool no_copy_; - // True if a conversion to interface does not escape, so it does - // not need a heap allocation. Only used in type-to-interface - // conversion. + // True if a conversion does not escape. Used in type-to-interface + // conversions and slice-to/from-string conversions. bool no_escape_; }; @@ -3561,13 +3560,19 @@ class Allocation_expression : public Expression public: Allocation_expression(Type* type, Location location) : Expression(EXPRESSION_ALLOCATION, location), - type_(type), allocate_on_stack_(false) + type_(type), allocate_on_stack_(false), + no_zero_(false) { } void set_allocate_on_stack() { this->allocate_on_stack_ = true; } + // Mark that the allocated memory doesn't need zeroing. + void + set_no_zero() + { this->no_zero_ = true; } + protected: int do_traverse(Traverse*); @@ -3596,6 +3601,8 @@ class Allocation_expression : public Expression Type* type_; // Whether or not this is a stack allocation. bool allocate_on_stack_; + // Whether we don't need to zero the allocated memory. + bool no_zero_; }; // A general composite literal. This is lowered to a type specific @@ -4541,4 +4548,8 @@ class Numeric_constant Type* type_; }; +// Temporary buffer size for string conversions. +// Also known to the runtime as tmpStringBufSize in runtime/string.go. +static const int tmp_string_buf_size = 32; + #endif // !defined(GO_EXPRESSIONS_H) -- cgit v1.1