+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.
@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,
#include "pass_manager.h"
#include "selftest.h"
#include "dump-context.h"
+#include <zlib.h>
/* A class for writing out optimization records in JSON format. */
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);
}