diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2019-05-03 21:45:35 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2019-05-03 21:45:35 +0000 |
commit | 08c8a26e9ca87ad2dd5b26d397e6107b68adfe76 (patch) | |
tree | 72997940c63241636375f8e4b4565d8f6301b724 /gcc/go/gofrontend/expressions.h | |
parent | e339291fc13d074bade3fd9ab3cbfacce5a21cbd (diff) | |
download | gcc-08c8a26e9ca87ad2dd5b26d397e6107b68adfe76.zip gcc-08c8a26e9ca87ad2dd5b26d397e6107b68adfe76.tar.gz gcc-08c8a26e9ca87ad2dd5b26d397e6107b68adfe76.tar.bz2 |
compiler: recognize and optimize array range clear
Recognize
for i := range a { a[i] = zero }
for array or slice a, and rewrite it to call memclr, as the gc
compiler does.
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/169398
From-SVN: r270862
Diffstat (limited to 'gcc/go/gofrontend/expressions.h')
-rw-r--r-- | gcc/go/gofrontend/expressions.h | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/gcc/go/gofrontend/expressions.h b/gcc/go/gofrontend/expressions.h index af7b00c..d2a3472 100644 --- a/gcc/go/gofrontend/expressions.h +++ b/gcc/go/gofrontend/expressions.h @@ -544,6 +544,11 @@ class Expression is_constant() const { return this->do_is_constant(); } + // Return whether this is the zero value of its type. + bool + is_zero_value() const + { return this->do_is_zero_value(); } + // Return whether this expression can be used as a static // initializer. This is true for an expression that has only // numbers and pointers to global variables or composite literals @@ -1066,6 +1071,11 @@ class Expression do_is_constant() const { return false; } + // Return whether this is the zero value of its type. + virtual bool + do_is_zero_value() const + { return false; } + // Return whether this expression can be used as a constant // initializer. virtual bool @@ -1600,6 +1610,10 @@ class String_expression : public Expression { return true; } bool + do_is_zero_value() const + { return this->val_ == ""; } + + bool do_is_static_initializer() const { return true; } @@ -1693,6 +1707,9 @@ class Type_conversion_expression : public Expression do_is_constant() const; bool + do_is_zero_value() const; + + bool do_is_static_initializer() const; bool @@ -1756,6 +1773,10 @@ class Unsafe_type_conversion_expression : public Expression do_traverse(Traverse* traverse); bool + do_is_zero_value() const + { return this->expr_->is_zero_value(); } + + bool do_is_static_initializer() const; Type* @@ -2152,6 +2173,9 @@ class String_concat_expression : public Expression do_is_constant() const; bool + do_is_zero_value() const; + + bool do_is_static_initializer() const; Type* @@ -3570,7 +3594,7 @@ class Struct_construction_expression : public Expression, type_(type) { } - // Return whether this is a constant initializer. + // Return whether this is a constant initializer. bool is_constant_struct() const; @@ -3579,6 +3603,9 @@ class Struct_construction_expression : public Expression, do_traverse(Traverse* traverse); bool + do_is_zero_value() const; + + bool do_is_static_initializer() const; Type* @@ -3643,6 +3670,9 @@ protected: do_traverse(Traverse* traverse); bool + do_is_zero_value() const; + + bool do_is_static_initializer() const; Type* |