Hi,
this patch implements OPTIMIZATION_NODE streaming same was as previous patch
did for TARGET_OPTION_NODE. Since the code turned out to be completely
analogous to the previous one I will go ahead and commit it as obvious.
It will help to make followup changes easier to follow.

I also tested this with forcing default optimization node on every function
with LTO.  It seems to just work, modulo inliner ignoring most of the flags and
happily dragging code from one set of optimization options to another.

Bootstrapped/regtested ppc64-linux and x86_64-linux, tested with Firefox, 
Comitted.

Honza

        * lto-streamer-out.c (hash_tree): Use cl_optimization_hash.
        * lto-streamer.h (cl_optimization_stream_out, 
cl_optimization_stream_in): Declare.
        * optc-save-gen.awk: Generate cl_optimization LTO streaming and hashing 
routines.
        * opth-gen.awk: Add prototype of cl_optimization_hash.
        * tree-streamer-in.c (unpack_ts_optimization): Remove.
        (streamer_unpack_tree_bitfields): Use cl_optimization_stream_in.
        * tree-streamer-out.c (pack_ts_optimization): Remove.
        (streamer_pack_tree_bitfields): Use cl_optimization_stream_out.
Index: lto-streamer-out.c
===================================================================
--- lto-streamer-out.c  (revision 217572)
+++ lto-streamer-out.c  (working copy)
@@ -948,7 +948,7 @@
     hstate.add_wide_int (cl_target_option_hash (TREE_TARGET_OPTION (t)));
 
   if (CODE_CONTAINS_STRUCT (code, TS_OPTIMIZATION))
-    hstate.add (t, sizeof (struct cl_optimization));
+    hstate.add_wide_int (cl_optimization_hash (TREE_OPTIMIZATION (t)));
 
   if (CODE_CONTAINS_STRUCT (code, TS_IDENTIFIER))
     hstate.merge_hash (IDENTIFIER_HASH_VALUE (t));
Index: lto-streamer.h
===================================================================
--- lto-streamer.h      (revision 217572)
+++ lto-streamer.h      (working copy)
@@ -844,7 +844,11 @@
                                 struct bitpack_d *,
                                 struct cl_target_option *);
 
+void cl_optimization_stream_out (struct bitpack_d *, struct cl_optimization *);
 
+void cl_optimization_stream_in (struct bitpack_d *, struct cl_optimization *);
+
+
 /* In lto-symtab.c.  */
 extern void lto_symtab_merge_decls (void);
 extern void lto_symtab_merge_symbols (void);
Index: optc-save-gen.awk
===================================================================
--- optc-save-gen.awk   (revision 217571)
+++ optc-save-gen.awk   (working copy)
@@ -551,4 +551,61 @@
 
 print "}";
 
+n_opt_val = 2;
+var_opt_val[0] = "x_optimize"
+var_opt_val_type[0] = "char "
+var_opt_val[1] = "x_optimize_size"
+var_opt_val_type[1] = "char "
+for (i = 0; i < n_opts; i++) {
+       if (flag_set_p("Optimization", flags[i])) {
+               name = var_name(flags[i])
+               if(name == "")
+                       continue;
+
+               if(name in var_opt_list_seen)
+                       continue;
+
+               var_opt_list_seen[name]++;
+
+               otype = var_type_struct(flags[i])
+               var_opt_val_type[n_opt_val] = otype;
+               var_opt_val[n_opt_val++] = "x_" name;
+       }
 }
+print "";
+print "/* Hash optimization options  */";
+print "hashval_t";
+print "cl_optimization_hash (struct cl_optimization const *ptr 
ATTRIBUTE_UNUSED)";
+print "{";
+print "  inchash::hash hstate;";
+for (i = 0; i < n_opt_val; i++) {
+       name = var_opt_val[i]
+       print "  hstate.add_wide_int (ptr->" name");";
+}
+print "  return hstate.end ();";
+print "}";
+
+print "";
+print "/* Stream out optimization options  */";
+print "void";
+print "cl_optimization_stream_out (struct bitpack_d *bp,";
+print "                            struct cl_optimization *ptr)";
+print "{";
+for (i = 0; i < n_opt_val; i++) {
+       name = var_opt_val[i]
+       print "  bp_pack_value (bp, ptr->" name", 64);";
+}
+print "}";
+
+print "";
+print "/* Stream in optimization options  */";
+print "void";
+print "cl_optimization_stream_in (struct bitpack_d *bp,";
+print "                           struct cl_optimization *ptr)";
+print "{";
+for (i = 0; i < n_opt_val; i++) {
+       name = var_opt_val[i]
+       print "  ptr->" name" = (" var_opt_val_type[i] ") bp_unpack_value (bp, 
64);";
+}
+print "}";
+}
Index: opth-gen.awk
===================================================================
--- opth-gen.awk        (revision 217571)
+++ opth-gen.awk        (working copy)
@@ -299,6 +299,9 @@
 print "/* Hash option variables from a structure.  */";
 print "extern hashval_t cl_target_option_hash (const struct cl_target_option 
*);";
 print "";
+print "/* Hash optimization from a structure.  */";
+print "extern hashval_t cl_optimization_hash (const struct cl_optimization 
*);";
+print "";
 print "/* Anything that includes tm.h, does not necessarily need this.  */"
 print "#if !defined(GCC_TM_H)"
 print "#include \"input.h\" /* for location_t */"
Index: tree-streamer-in.c
===================================================================
--- tree-streamer-in.c  (revision 217571)
+++ tree-streamer-in.c  (working copy)
@@ -399,22 +399,7 @@
   vec_safe_push (all_translation_units, expr);
 }
 
-/* Unpack a TS_OPTIMIZATION tree from BP into EXPR.  */
 
-static void
-unpack_ts_optimization (struct bitpack_d *bp, tree expr)
-{
-  unsigned i, len;
-  struct cl_optimization *t = TREE_OPTIMIZATION (expr);
-
-  len = sizeof (struct cl_optimization);
-  for (i = 0; i < len; i++)
-    ((unsigned char *)t)[i] = bp_unpack_value (bp, 8);
-  if (bp_unpack_value (bp, 32) != 0x12345678)
-    fatal_error ("cl_optimization size mismatch in LTO reader and writer");
-}
-
-
 /* Unpack all the non-pointer fields of the TS_OMP_CLAUSE
    structure of expression EXPR from bitpack BP.  */
 
@@ -507,7 +492,7 @@
     unpack_ts_translation_unit_decl_value_fields (data_in, bp, expr);
 
   if (CODE_CONTAINS_STRUCT (code, TS_OPTIMIZATION))
-    unpack_ts_optimization (bp, expr);
+    cl_optimization_stream_in (bp, TREE_OPTIMIZATION (expr));
 
   if (CODE_CONTAINS_STRUCT (code, TS_BINFO))
     {
Index: tree-streamer-out.c
===================================================================
--- tree-streamer-out.c (revision 217571)
+++ tree-streamer-out.c (working copy)
@@ -363,25 +363,7 @@
   bp_pack_string (ob, bp, TRANSLATION_UNIT_LANGUAGE (expr), true);
 }
 
-/* Pack a TS_OPTIMIZATION tree in EXPR to BP.  */
 
-static void
-pack_ts_optimization (struct bitpack_d *bp, tree expr)
-{
-  struct cl_optimization *t = TREE_OPTIMIZATION (expr);
-  unsigned i, len;
-
-  /* The cl_optimization is generated by the options
-     awk script, so we just recreate a byte-by-byte copy here. */
-
-  len = sizeof (struct cl_optimization);
-  for (i = 0; i < len; i++)
-    bp_pack_value (bp, ((unsigned char *)t)[i], 8);
-  /* Catch struct size mismatches between reader and writer. */
-  bp_pack_value (bp, 0x12345678, 32);
-}
-
-
 /* Pack all the non-pointer fields of the TS_OMP_CLAUSE structure
    of expression EXPR into bitpack BP.  */
 
@@ -473,7 +455,7 @@
     pack_ts_translation_unit_decl_value_fields (ob, bp, expr);
 
   if (CODE_CONTAINS_STRUCT (code, TS_OPTIMIZATION))
-    pack_ts_optimization (bp, expr);
+    cl_optimization_stream_out (bp, TREE_OPTIMIZATION (expr));
 
   if (CODE_CONTAINS_STRUCT (code, TS_BINFO))
     bp_pack_var_len_unsigned (bp, vec_safe_length (BINFO_BASE_ACCESSES 
(expr)));

Reply via email to