From 2794baab686973f39045327970e4a7302c31ea88 Mon Sep 17 00:00:00 2001 From: Cherry Zhang Date: Fri, 2 Feb 2018 00:00:04 +0000 Subject: [PATCH] compiler: turn on escape analysis by default The escape analysis now runs by default. It can be disabled with the negative flag, -fno-go-optimize-allocs. Reviewed-on: https://go-review.googlesource.com/86247 * lang.opt (fgo-optimize): Remove RejectNegative. * go-c.h (go_enable_optimize): Update declaration to take value argument. * go-lang.c (go_langhook_handle_option): Pass value to go_enable_optimize. * gccgo.texi (Invoking gccgo): Update -fgo-optimize-allocs doc. From-SVN: r257319 --- gcc/go/ChangeLog | 9 +++++++++ gcc/go/gccgo.texi | 8 ++++---- gcc/go/go-c.h | 2 +- gcc/go/go-lang.c | 4 ++-- gcc/go/gofrontend/MERGE | 2 +- gcc/go/gofrontend/escape.cc | 2 +- gcc/go/gofrontend/go-optimize.cc | 14 +++++++------- gcc/go/gofrontend/go-optimize.h | 6 +++--- gcc/go/lang.opt | 2 +- 9 files changed, 29 insertions(+), 20 deletions(-) diff --git a/gcc/go/ChangeLog b/gcc/go/ChangeLog index b1876c57d5a..92abf590c29 100644 --- a/gcc/go/ChangeLog +++ b/gcc/go/ChangeLog @@ -1,3 +1,12 @@ +2018-02-01 Cherry Zhang + + * lang.opt (fgo-optimize): Remove RejectNegative. + * go-c.h (go_enable_optimize): Update declaration to take value + argument. + * go-lang.c (go_langhook_handle_option): Pass value to + go_enable_optimize. + * gccgo.texi (Invoking gccgo): Update -fgo-optimize-allocs doc. + 2018-01-30 Ian Lance Taylor * go-gcc.cc (Gcc_backend::convert_tree): New private method. diff --git a/gcc/go/gccgo.texi b/gcc/go/gccgo.texi index 48e69d42ddf..f42be9a52a6 100644 --- a/gcc/go/gccgo.texi +++ b/gcc/go/gccgo.texi @@ -229,10 +229,10 @@ may be used. Or the checks may be removed via by default, but in the future may be off by default on systems that do not require it. -@item -fgo-optimize-allocs -@cindex @option{-fgo-optimize-allocs} -Use escape analysis to allocate objects on the stack rather than the -heap when possible. In the future this may be the default. +@item -fno-go-optimize-allocs +@cindex @option{-fno-go-optimize-allocs} +Disable escape analysis, which tries to allocate objects on the stack +rather than the heap. @item -fgo-debug-escape@var{n} @cindex @option{-fgo-debug-escape} diff --git a/gcc/go/go-c.h b/gcc/go/go-c.h index 139c233aab4..2dc1d434bd5 100644 --- a/gcc/go/go-c.h +++ b/gcc/go/go-c.h @@ -29,7 +29,7 @@ class Backend; interface. */ extern int go_enable_dump (const char*); -extern int go_enable_optimize (const char*); +extern int go_enable_optimize (const char*, int); extern void go_add_search_path (const char*); diff --git a/gcc/go/go-lang.c b/gcc/go/go-lang.c index b5d8224a54e..45dee88fe48 100644 --- a/gcc/go/go-lang.c +++ b/gcc/go/go-lang.c @@ -194,7 +194,7 @@ static bool go_langhook_handle_option ( size_t scode, const char *arg, - int value ATTRIBUTE_UNUSED, + int value, int kind ATTRIBUTE_UNUSED, location_t loc ATTRIBUTE_UNUSED, const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED) @@ -251,7 +251,7 @@ go_langhook_handle_option ( break; case OPT_fgo_optimize_: - ret = go_enable_optimize (arg) ? true : false; + ret = go_enable_optimize (arg, value) ? true : false; break; case OPT_fgo_pkgpath_: diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index 6e580389d91..cc64fad98ce 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -1,4 +1,4 @@ -023c3d4358d101c71ac1436065690eaec2ce138e +e148068360699f24118950b728f23a5c98e1f85e The first line of this file holds the git revision number of the last merge done from the gofrontend repository. diff --git a/gcc/go/gofrontend/escape.cc b/gcc/go/gofrontend/escape.cc index 873c187bb57..51e80e44645 100644 --- a/gcc/go/gofrontend/escape.cc +++ b/gcc/go/gofrontend/escape.cc @@ -825,7 +825,7 @@ Escape_note::parse_tag(std::string* tag) // The -fgo-optimize-alloc flag activates this escape analysis. -Go_optimize optimize_allocation_flag("allocs"); +Go_optimize optimize_allocation_flag("allocs", true); // A helper function to compute whether a function name has a // matching hash value. diff --git a/gcc/go/gofrontend/go-optimize.cc b/gcc/go/gofrontend/go-optimize.cc index 6da934f4d13..d24f35c58d3 100644 --- a/gcc/go/gofrontend/go-optimize.cc +++ b/gcc/go/gofrontend/go-optimize.cc @@ -19,8 +19,8 @@ Go_optimize* optimizations; // Create a new optimization. -Go_optimize::Go_optimize(const char* name) - : next_(optimizations), name_(name), is_enabled_(false) +Go_optimize::Go_optimize(const char* name, bool enabled) + : next_(optimizations), name_(name), is_enabled_(enabled) { optimizations = this; } @@ -28,7 +28,7 @@ Go_optimize::Go_optimize(const char* name) // Enable an optimization by name. bool -Go_optimize::enable_by_name(const char* name) +Go_optimize::enable_by_name(const char* name, bool value) { bool is_all = strcmp(name, "all") == 0; bool found = false; @@ -36,18 +36,18 @@ Go_optimize::enable_by_name(const char* name) { if (is_all || strcmp(name, p->name_) == 0) { - p->is_enabled_ = true; + p->is_enabled_ = value; found = true; } } return found; } -// Enable an optimization. Return 1 if this is a real name, 0 if not. +// Enable/disable an optimization. Return 1 if this is a real name, 0 if not. GO_EXTERN_C int -go_enable_optimize(const char* name) +go_enable_optimize(const char* name, int value) { - return Go_optimize::enable_by_name(name) ? 1 : 0; + return Go_optimize::enable_by_name(name, (bool)value) ? 1 : 0; } diff --git a/gcc/go/gofrontend/go-optimize.h b/gcc/go/gofrontend/go-optimize.h index 8638498e18f..1ca68deba08 100644 --- a/gcc/go/gofrontend/go-optimize.h +++ b/gcc/go/gofrontend/go-optimize.h @@ -15,16 +15,16 @@ class Go_optimize { public: - Go_optimize(const char* name); + Go_optimize(const char*, bool); // Whether this optimizaiton was enabled. bool is_enabled() const { return this->is_enabled_; } - // Enable an optimization by name. Return true if found. + // Enable/disable an optimization by name. Return true if found. static bool - enable_by_name(const char*); + enable_by_name(const char*, bool); private: // The next optimize flag. These are not in any order. diff --git a/gcc/go/lang.opt b/gcc/go/lang.opt index 6dbb54298d7..ee1c2913f27 100644 --- a/gcc/go/lang.opt +++ b/gcc/go/lang.opt @@ -58,7 +58,7 @@ Go Joined RejectNegative -fgo-dump- Dump Go frontend internal information. fgo-optimize- -Go Joined RejectNegative +Go Joined -fgo-optimize- Turn on optimization passes in the frontend. fgo-pkgpath= -- 2.30.2