summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2018-11-13 15:52:45 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2018-11-13 15:52:45 +0000
commitbe40afb2b93a0f8f5739dd36c3c804e6f809d1d4 (patch)
tree747ab50262a4fc7bca6c6ab7f2592d8e3720e8a4
parentf824e18c061f9ffa8c49275ba072c120a5b7cdba (diff)
downloadgcc-be40afb2b93a0f8f5739dd36c3c804e6f809d1d4.tar.gz
-fsave-optimization-record: compress the output using zlib
gcc/ChangeLog: * doc/invoke.texi (-fsave-optimization-record): Note that the output is compressed. * optinfo-emit-json.cc: Include <zlib.h>. (optrecord_json_writer::write): Compress the output. From-SVN: r266078
-rw-r--r--gcc/ChangeLog7
-rw-r--r--gcc/doc/invoke.texi6
-rw-r--r--gcc/optinfo-emit-json.cc35
3 files changed, 37 insertions, 11 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 670b1623ed8..18acf495a31 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,10 @@
+2018-11-13 David Malcolm <dmalcolm@redhat.com>
+
+ * doc/invoke.texi (-fsave-optimization-record): Note that the
+ output is compressed.
+ * optinfo-emit-json.cc: Include <zlib.h>.
+ (optrecord_json_writer::write): Compress the output.
+
2018-11-13 Aldy Hernandez <aldyh@redhat.com>
* tree-vrp.c (value_range_base::dump): Dump type.
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 755a00017f7..283d20fa296 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -14524,11 +14524,11 @@ dumps from the vectorizer about missed opportunities.
@item -fsave-optimization-record
@opindex fsave-optimization-record
-Write a SRCFILE.opt-record.json file detailing what optimizations
+Write a SRCFILE.opt-record.json.gz file detailing what optimizations
were performed, for those optimizations that support @option{-fopt-info}.
-This option is experimental and the format of the data within the JSON
-file is subject to change.
+This option is experimental and the format of the data within the
+compressed JSON file is subject to change.
It is roughly equivalent to a machine-readable version of
@option{-fopt-info-all}, as a collection of messages with source file,
diff --git a/gcc/optinfo-emit-json.cc b/gcc/optinfo-emit-json.cc
index 31029ad8479..6d4502c5129 100644
--- a/gcc/optinfo-emit-json.cc
+++ b/gcc/optinfo-emit-json.cc
@@ -45,6 +45,7 @@ along with GCC; see the file COPYING3. If not see
#include "pass_manager.h"
#include "selftest.h"
#include "dump-context.h"
+#include <zlib.h>
/* A class for writing out optimization records in JSON format. */
@@ -133,16 +134,34 @@ optrecord_json_writer::~optrecord_json_writer ()
void
optrecord_json_writer::write () const
{
- char *filename = concat (dump_base_name, ".opt-record.json", NULL);
- FILE *outfile = fopen (filename, "w");
- if (outfile)
+ pretty_printer pp;
+ m_root_tuple->print (&pp);
+
+ bool emitted_error = false;
+ char *filename = concat (dump_base_name, ".opt-record.json.gz", NULL);
+ gzFile outfile = gzopen (filename, "w");
+ if (outfile == NULL)
{
- m_root_tuple->dump (outfile);
- fclose (outfile);
+ error_at (UNKNOWN_LOCATION, "cannot open file %qs for writing optimization records",
+ filename); // FIXME: more info?
+ goto cleanup;
}
- else
- error_at (UNKNOWN_LOCATION, "unable to write optimization records to %qs",
- filename); // FIXME: more info?
+
+ if (gzputs (outfile, pp_formatted_text (&pp)) <= 0)
+ {
+ int tmp;
+ error_at (UNKNOWN_LOCATION, "error writing optimization records to %qs: %s",
+ filename, gzerror (outfile, &tmp));
+ emitted_error = true;
+ }
+
+ cleanup:
+ if (outfile)
+ if (gzclose (outfile) != Z_OK)
+ if (!emitted_error)
+ error_at (UNKNOWN_LOCATION, "error closing optimization records %qs",
+ filename);
+
free (filename);
}