diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2019-06-19 04:53:51 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2019-06-19 04:53:51 +0000 |
commit | 20b603dba4bea71cbdf9dde7db44d6b5bbcb7654 (patch) | |
tree | 94c81c934c43d4b35ea3289daae6945a9a07b296 /gcc/go/gofrontend/expressions.h | |
parent | 17f62b7e1fef0a04c738419b0108eeb89f6b7463 (diff) | |
download | gcc-20b603dba4bea71cbdf9dde7db44d6b5bbcb7654.zip gcc-20b603dba4bea71cbdf9dde7db44d6b5bbcb7654.tar.gz gcc-20b603dba4bea71cbdf9dde7db44d6b5bbcb7654.tar.bz2 |
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
Diffstat (limited to 'gcc/go/gofrontend/expressions.h')
-rw-r--r-- | gcc/go/gofrontend/expressions.h | 19 |
1 files changed, 15 insertions, 4 deletions
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) |