diff options
author | Ian Lance Taylor <iant@golang.org> | 2018-11-27 15:51:01 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2018-11-27 15:51:01 +0000 |
commit | 862ec76377acf7a20009d755f45d8480868c3fc8 (patch) | |
tree | 25de4037daed56b9de9e55e305cc684602cef5a2 /gcc/go/gofrontend/gogo.h | |
parent | 56c79e7f5d21660c2e16b2e17d5b48d1df10d92f (diff) | |
download | gcc-862ec76377acf7a20009d755f45d8480868c3fc8.zip gcc-862ec76377acf7a20009d755f45d8480868c3fc8.tar.gz gcc-862ec76377acf7a20009d755f45d8480868c3fc8.tar.bz2 |
compiler: import inlinable functions from package data
Start reading the export data generated by the last change in this
series. At this point we will inline direct calls to empty functions
and methods defined in different packages.
Reviewed-on: https://go-review.googlesource.com/c/150062
From-SVN: r266517
Diffstat (limited to 'gcc/go/gofrontend/gogo.h')
-rw-r--r-- | gcc/go/gofrontend/gogo.h | 84 |
1 files changed, 75 insertions, 9 deletions
diff --git a/gcc/go/gofrontend/gogo.h b/gcc/go/gofrontend/gogo.h index 1b13e5c..1c79f6f 100644 --- a/gcc/go/gofrontend/gogo.h +++ b/gcc/go/gofrontend/gogo.h @@ -43,6 +43,7 @@ class Backend; class Export; class Export_function_body; class Import; +class Import_function_body; class Bexpression; class Btype; class Bstatement; @@ -420,6 +421,17 @@ class Gogo Named_object* declare_package_function(const std::string&, Function_type*, Location); + // Add a function declaration to the list of functions we may want + // to inline. + void + add_imported_inlinable_function(Named_object*); + + // Add a function to the list of functions that we do want to + // inline. + void + add_imported_inline_function(Named_object* no) + { this->imported_inline_functions_.push_back(no); } + // Add a label. Label* add_label_definition(const std::string&, Location); @@ -661,7 +673,7 @@ class Gogo propagate_escape(Escape_context*, Node*); // Add notes about the escape level of a function's input and output - // parameters for exporting and importing top level functions. + // parameters for exporting and importing top level functions. void tag_function(Escape_context*, Named_object*); @@ -726,7 +738,7 @@ class Gogo void simplify_thunk_statements(); - // Dump AST if -fgo-dump-ast is set + // Dump AST if -fgo-dump-ast is set. void dump_ast(const char* basename); @@ -1062,6 +1074,12 @@ class Gogo std::vector<Analysis_set> analysis_sets_; // A list of objects to add to the GC roots. std::vector<Expression*> gc_roots_; + // A list of function declarations with imported bodies that we may + // want to inline. + std::vector<Named_object*> imported_inlinable_functions_; + // A list of functions that we want to inline. These will be sent + // to the backend. + std::vector<Named_object*> imported_inline_functions_; }; // A block of statements. @@ -1144,6 +1162,10 @@ class Block void export_block(Export_function_body*); + // Turn exported block data into a block. + static bool + import_block(Block*, Import_function_body*, Location); + // Convert the block to the backend representation. Bblock* get_backend(Translate_context*); @@ -1419,6 +1441,17 @@ class Function set_export_for_inlining() { this->export_for_inlining_ = true; } + // Return whether this function is inline only. + bool + is_inline_only() const + { return this->is_inline_only_; } + + // Mark the function as inline only: the body should not be emitted + // if it is not inlined. + void + set_is_inline_only() + { this->is_inline_only_ = true; } + // Swap with another function. Used only for the thunk which calls // recover. void @@ -1476,14 +1509,15 @@ class Function // Export a function with a type. static void export_func_with_type(Export*, const std::string& name, - const Function_type*, bool nointerface, Block* block); + const Function_type*, bool nointerface, Block* block, + Location); // Import a function. static void import_func(Import*, std::string* pname, Typed_identifier** receiver, Typed_identifier_list** pparameters, Typed_identifier_list** presults, bool* is_varargs, - bool* nointerface); + bool* nointerface, std::string* body); private: // Type for mapping from label names to Label objects. @@ -1557,6 +1591,9 @@ class Function // True if we should export the body of this function for // cross-package inlining. bool export_for_inlining_ : 1; + // True if this function is inline only: if it should not be emitted + // if it is not inlined. + bool is_inline_only_ : 1; }; // A snapshot of the current binding state. @@ -1600,7 +1637,8 @@ class Function_declaration public: Function_declaration(Function_type* fntype, Location location) : fntype_(fntype), location_(location), asm_name_(), descriptor_(NULL), - fndecl_(NULL), pragmas_(0) + fndecl_(NULL), pragmas_(0), imported_body_(), + is_on_inlinable_list_(false) { } Function_type* @@ -1646,6 +1684,30 @@ class Function_declaration void set_nointerface(); + // Whether we have an imported function body. + bool + has_imported_body() const + { return !this->imported_body_.empty(); } + + // Record the imported body of this function. + void + set_imported_body(const std::string& imported_body) + { this->imported_body_ = imported_body; } + + // Whether this declaration is on the list of inlinable functions. + bool + is_on_inlinable_list() const + { return this->is_on_inlinable_list_; } + + // Set that this function is on the list of inlinable functions. + void + set_is_on_inlinable_list() + { this->is_on_inlinable_list_ = true; } + + // Import the function body, creating a function. + void + import_function_body(Gogo*, Named_object*); + // Return an expression for the function descriptor, given the named // object for this function. This may only be called for functions // without a closure. This will be an immutable struct with one @@ -1673,7 +1735,7 @@ class Function_declaration { Function::export_func_with_type(exp, name, this->fntype_, this->is_method() && this->nointerface(), - NULL); + NULL, this->location_); } // Check that the types used in this declaration's signature are defined. @@ -1694,6 +1756,10 @@ class Function_declaration Bfunction* fndecl_; // Pragmas for this function. This is a set of GOPRAGMA bits. unsigned int pragmas_; + // Export data for function body if imported from a different package. + std::string imported_body_; + // Whether this declaration is already on the list of inlinable functions. + bool is_on_inlinable_list_; }; // A variable. @@ -1789,7 +1855,7 @@ class Variable bool is_in_heap() const { - return this->is_address_taken_ + return this->is_address_taken_ && this->escapes_ && !this->is_global_; } @@ -2103,7 +2169,7 @@ class Result_variable void set_non_escaping_address_taken() { this->is_non_escaping_address_taken_ = true; } - + // Return whether this variable escapes the function it is declared in. bool escapes() @@ -3200,7 +3266,7 @@ class Package // Return the bindings. Bindings* - bindings() + bindings() const { return this->bindings_; } // Type used to map import names to package aliases. |