[gcc r11-5143] options, lto: Optimize streaming of optimization nodes

Jakub Jelinek jakub@gcc.gnu.org
Wed Nov 18 19:14:41 GMT 2020


https://gcc.gnu.org/g:95db7e9afe57ca1c269d46baa2accced004e5c74

commit r11-5143-g95db7e9afe57ca1c269d46baa2accced004e5c74
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Wed Nov 18 20:14:00 2020 +0100

    options, lto: Optimize streaming of optimization nodes
    
    Honza mentioned that especially for the new param machinery, most of
    streamed values are probably going to be the default values.  Perhaps
    somehow we could stream them more effectively.
    
    This patch implements it and brings further savings, the size
    goes down from 574 bytes to 273 bytes, i.e. less than half.
    Not trying to handle enums because the code doesn't know if (enum ...) 10
    is even valid, similarly non-parameters because those really generally
    don't have large initializers, and params without Init (those are 0
    initialized and thus don't need to be handled).
    
    2020-11-18  Jakub Jelinek  <jakub@redhat.com>
    
            * optc-save-gen.awk: Initialize var_opt_init.  In
            cl_optimization_stream_out for params with default values larger than
            10, xor the default value with the actual parameter value.  In
            cl_optimization_stream_in repeat the above xor.

Diff:
---
 gcc/optc-save-gen.awk | 36 ++++++++++++++++++++++++++++--------
 1 file changed, 28 insertions(+), 8 deletions(-)

diff --git a/gcc/optc-save-gen.awk b/gcc/optc-save-gen.awk
index a756835230e..0a1be8ccb04 100644
--- a/gcc/optc-save-gen.awk
+++ b/gcc/optc-save-gen.awk
@@ -1290,6 +1290,7 @@ for (i = 0; i < n_opts; i++) {
 		var_opt_val_type[n_opt_val] = otype;
 		var_opt_val[n_opt_val] = "x_" name;
 		var_opt_hash[n_opt_val] = flag_set_p("Optimization", flags[i]);
+		var_opt_init[n_opt_val] = opt_args("Init", flags[i]);
 		n_opt_val++;
 	}
 }
@@ -1361,10 +1362,21 @@ for (i = 0; i < n_opt_val; i++) {
 	otype = var_opt_val_type[i];
 	if (otype ~ "^const char \\**$")
 		print "  bp_pack_string (ob, bp, ptr->" name", true);";
-	else if (otype ~ "^unsigned")
-		print "  bp_pack_var_len_unsigned (bp, ptr->" name");";
-	else
-		print "  bp_pack_var_len_int (bp, ptr->" name");";
+	else {
+		if (otype ~ "^unsigned") {
+			sgn = "unsigned";
+		} else {
+			sgn = "int";
+		}
+		if (name ~ "^x_param" && !(otype ~ "^enum ") && var_opt_init[i]) {
+			print "  if (" var_opt_init[i] " > (" var_opt_val_type[i] ") 10)";
+			print "    bp_pack_var_len_" sgn " (bp, ptr->" name" ^ " var_opt_init[i] ");";
+			print "  else";
+			print "    bp_pack_var_len_" sgn " (bp, ptr->" name");";
+		} else {
+			print "  bp_pack_var_len_" sgn " (bp, ptr->" name");";
+		}
+	}
 }
 print "  for (size_t i = 0; i < sizeof (ptr->explicit_mask) / sizeof (ptr->explicit_mask[0]); i++)";
 print "    bp_pack_value (bp, ptr->explicit_mask[i], 64);";
@@ -1385,10 +1397,18 @@ for (i = 0; i < n_opt_val; i++) {
 		print "  if (ptr->" name")";
 		print "    ptr->" name" = xstrdup (ptr->" name");";
 	}
-	else if (otype ~ "^unsigned")
-		print "  ptr->" name" = (" var_opt_val_type[i] ") bp_unpack_var_len_unsigned (bp);";
-	else
-		print "  ptr->" name" = (" var_opt_val_type[i] ") bp_unpack_var_len_int (bp);";
+	else {
+		if (otype ~ "^unsigned") {
+			sgn = "unsigned";
+		} else {
+			sgn = "int";
+		}
+		print "  ptr->" name" = (" var_opt_val_type[i] ") bp_unpack_var_len_" sgn " (bp);";
+		if (name ~ "^x_param" && !(otype ~ "^enum ") && var_opt_init[i]) {
+			print "  if (" var_opt_init[i] " > (" var_opt_val_type[i] ") 10)";
+			print "    ptr->" name" ^= " var_opt_init[i] ";";
+		}
+	}
 }
 print "  for (size_t i = 0; i < sizeof (ptr->explicit_mask) / sizeof (ptr->explicit_mask[0]); i++)";
 print "    ptr->explicit_mask[i] = bp_unpack_value (bp, 64);";


More information about the Gcc-cvs mailing list