diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2018-11-28 18:08:21 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2018-11-28 18:08:21 +0000 |
commit | 5456f30d92062d234208cd8634e54787f6e2664f (patch) | |
tree | 023b9e1979b33d40c37b642607932fe34787f69a /gcc/go/gofrontend/expressions.h | |
parent | 85041a5b7755dc7b9d74b183e933d89152997886 (diff) | |
download | gcc-5456f30d92062d234208cd8634e54787f6e2664f.zip gcc-5456f30d92062d234208cd8634e54787f6e2664f.tar.gz gcc-5456f30d92062d234208cd8634e54787f6e2664f.tar.bz2 |
compiler: inline functions with assignments and return statements
Support inlining functions that contain only assignments and return
statements, with expressions of either constants or parameters.
Functions that contain other kinds of statements or expressions are
not yet inlined. With this change, about 100 functions in the
standard library are inlinable.
Reviewed-on: https://go-review.googlesource.com/c/150073
From-SVN: r266573
Diffstat (limited to 'gcc/go/gofrontend/expressions.h')
-rw-r--r-- | gcc/go/gofrontend/expressions.h | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/gcc/go/gofrontend/expressions.h b/gcc/go/gofrontend/expressions.h index 7061657..a18322c 100644 --- a/gcc/go/gofrontend/expressions.h +++ b/gcc/go/gofrontend/expressions.h @@ -941,7 +941,7 @@ class Expression // Return the cost of this statement for inlining purposes. int - inlining_cost() + inlining_cost() const { return this->do_inlining_cost(); } // Return whether the expression is addressable--something which may @@ -1093,7 +1093,7 @@ class Expression // inlining. The default cost is high, so we only need to define // this method for expressions that can be inlined. virtual int - do_inlining_cost() + do_inlining_cost() const { return 0x100000; } // Child class implements whether the expression is addressable. @@ -1355,6 +1355,12 @@ class Var_expression : public Expression do_copy() { return this; } + int + do_inlining_cost() const; + + void + do_export(Export_function_body*) const; + bool do_is_addressable() const { return true; } @@ -1602,6 +1608,12 @@ class String_expression : public Expression static void export_string(String_dump* exp, const String_expression* str); + // Set the inlining cost a bit high since inlining may cause + // duplicated string literals. + int + do_inlining_cost() const + { return 5; } + void do_export(Export_function_body*) const; @@ -1686,6 +1698,9 @@ class Type_conversion_expression : public Expression Bexpression* do_get_backend(Translate_context* context); + int + do_inlining_cost() const; + void do_export(Export_function_body*) const; @@ -1877,6 +1892,10 @@ class Unary_expression : public Expression Bexpression* do_get_backend(Translate_context*); + int + do_inlining_cost() const + { return 1; } + void do_export(Export_function_body*) const; @@ -2022,6 +2041,10 @@ class Binary_expression : public Expression Bexpression* do_get_backend(Translate_context*); + int + do_inlining_cost() const + { return 1; } + void do_export(Export_function_body*) const; |