From: David Malcolm Date: Tue, 13 Nov 2018 15:52:45 +0000 (+0000) Subject: -fsave-optimization-record: compress the output using zlib X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=be40afb2b93a0f8f5739dd36c3c804e6f809d1d4;p=gcc.git -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 . (optrecord_json_writer::write): Compress the output. From-SVN: r266078 --- 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 + + * doc/invoke.texi (-fsave-optimization-record): Note that the + output is compressed. + * optinfo-emit-json.cc: Include . + (optrecord_json_writer::write): Compress the output. + 2018-11-13 Aldy Hernandez * 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 /* 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); }