diff options
author | Cherry Zhang <cherryyz@google.com> | 2019-05-16 04:35:15 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2019-05-16 04:35:15 +0000 |
commit | e8e91b845496603168161015ccd5325524abbf7e (patch) | |
tree | 042ec42badf35137c4249ed7ab62797a8a50cf48 /gcc/go/gofrontend/expressions.h | |
parent | 92b8603c7c6789806879307a29ae3b85adaaaf14 (diff) | |
download | gcc-e8e91b845496603168161015ccd5325524abbf7e.zip gcc-e8e91b845496603168161015ccd5325524abbf7e.tar.gz gcc-e8e91b845496603168161015ccd5325524abbf7e.tar.bz2 |
compiler: improve escape analysis on interface conversions
If an interface does not escape, it doesn't need a heap
allocation to hold the data (for non-direct interface type).
This CL improves the escape analysis to track interface
conversions, and reduces these allocations.
Implicit interface conversions were mostly added late in the
compilation pipeline, after the escape analysis. For the escape
analysis to see them, we move the introduction of these
conversions earlier, right before the escape analysis.
Now that the compiler can generate interface conversions inlined,
gcc/testsuite/go.test/test/nilptr2.go needs to be adjusted as in
golang.org/cl/176579, so the use function does an actual use.
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/176459
* go.test/test/nilptr2.go: Change use function to actually do
something.
From-SVN: r271276
Diffstat (limited to 'gcc/go/gofrontend/expressions.h')
-rw-r--r-- | gcc/go/gofrontend/expressions.h | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/gcc/go/gofrontend/expressions.h b/gcc/go/gofrontend/expressions.h index 9ed81f1..b1811ea 100644 --- a/gcc/go/gofrontend/expressions.h +++ b/gcc/go/gofrontend/expressions.h @@ -934,6 +934,11 @@ class Expression flatten(Gogo* gogo, Named_object* function, Statement_inserter* inserter) { return this->do_flatten(gogo, function, inserter); } + // Make implicit type conversions explicit. + void + add_conversions() + { this->do_add_conversions(); } + // Determine the real type of an expression with abstract integer, // floating point, or complex type. TYPE_CONTEXT describes the // expected type. @@ -1019,6 +1024,13 @@ class Expression Expression* rhs, bool for_type_guard, Location); + // Return an expression for a conversion from a non-interface type to an + // interface type. If ON_STACK is true, it can allocate the storage on + // stack. + static Expression* + convert_type_to_interface(Type* lhs_type, Expression* rhs, + bool on_stack, Location); + // Return a backend expression implementing the comparison LEFT OP RIGHT. // TYPE is the type of both sides. static Bexpression* @@ -1070,6 +1082,10 @@ class Expression do_flatten(Gogo*, Named_object*, Statement_inserter*) { return this; } + // Make implicit type conversions explicit. + virtual void + do_add_conversions() + { } // Return whether this is a constant expression. virtual bool @@ -1215,9 +1231,6 @@ class Expression } static Expression* - convert_type_to_interface(Type*, Expression*, Location); - - static Expression* unpack_direct_iface(Expression*, Location); static Expression* @@ -1674,7 +1687,7 @@ class Type_conversion_expression : public Expression Location location) : Expression(EXPRESSION_CONVERSION, location), type_(type), expr_(expr), may_convert_function_types_(false), - no_copy_(false) + no_copy_(false), no_escape_(false) { } // Return the type to which we are converting. @@ -1766,6 +1779,10 @@ 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. + bool no_escape_; }; // An unsafe type conversion, used to pass values to builtin functions. @@ -2402,6 +2419,9 @@ class Call_expression : public Expression void do_dump_expression(Ast_dump_context*) const; + void + do_add_conversions(); + private: bool check_argument_type(int, const Type*, const Type*, Location, bool); @@ -3162,6 +3182,9 @@ class Map_index_expression : public Expression void do_dump_expression(Ast_dump_context*) const; + void + do_add_conversions(); + private: // The map we are looking into. Expression* map_; @@ -3648,6 +3671,9 @@ class Struct_construction_expression : public Expression, void do_dump_expression(Ast_dump_context*) const; + void + do_add_conversions(); + private: // The type of the struct to construct. Type* type_; @@ -3721,6 +3747,9 @@ protected: virtual void dump_slice_storage_expression(Ast_dump_context*) const { } + void + do_add_conversions(); + private: // The type of the array to construct. Type* type_; @@ -3844,6 +3873,9 @@ class Map_construction_expression : public Expression void do_dump_expression(Ast_dump_context*) const; + void + do_add_conversions(); + private: // The type of the map to construct. Type* type_; |