From 08c8a26e9ca87ad2dd5b26d397e6107b68adfe76 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 3 May 2019 21:45:35 +0000 Subject: 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 --- gcc/go/gofrontend/expressions.h | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'gcc/go/gofrontend/expressions.h') 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* -- cgit v1.1