public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Andrew MacLeod <amacleod@redhat.com>,
	Aldy Hernandez <aldyh@redhat.com>,
	Richard Biener <rguenther@suse.de>
Cc: gcc-patches@gcc.gnu.org
Subject: [PATCH] value-relation: Small tweaks to tables
Date: Thu, 26 Jan 2023 11:23:56 +0100	[thread overview]
Message-ID: <Y9JUvA7+lqVDt6WR@tucnak> (raw)

Hi!

As I said earlier, all these tables are used solely in value-relation.cc
and never modified, plus because VREL_LAST is small especially the
two-dimensional arrays are vast a lot of .data (or .rodata) space
- 576 bytes each.  The following patch makes those arrays static const
and uses unsigned char instead of relation_kind so that the
two-dimensional arrays shrink to 144 bytes.

Build-tested, ok for trunk if it passes bootstrap/regtest?

2023-01-26  Jakub Jelinek  <jakub@redhat.com>

	* value-relation.cc (kind_string): Add const.
	(rr_negate_table, rr_swap_table, rr_intersect_table,
	rr_union_table, rr_transitive_table): Add static const, change
	element type from relation_kind to unsigned char.
	(relation_negate, relation_swap, relation_intersect, relation_union,
	relation_transitive): Cast rr_*_table element to relation_kind.
	(relation_to_code): Add static const.
	(relation_tests): Assert VREL_LAST is smaller than UCHAR_MAX.

--- gcc/value-relation.cc.jj	2023-01-19 23:26:31.887212157 +0100
+++ gcc/value-relation.cc	2023-01-26 11:12:42.798750916 +0100
@@ -32,7 +32,7 @@ along with GCC; see the file COPYING3.
 #include "alloc-pool.h"
 #include "dominance.h"
 
-static const char *kind_string[VREL_LAST] =
+static const char *const kind_string[VREL_LAST] =
 { "varying", "undefined", "<", "<=", ">", ">=", "==", "!=", "pe8", "pe16",
   "pe32", "pe64" };
 
@@ -45,7 +45,7 @@ print_relation (FILE *f, relation_kind r
 }
 
 // This table is used to negate the operands.  op1 REL op2 -> !(op1 REL op2).
-relation_kind rr_negate_table[VREL_LAST] = {
+static const unsigned char rr_negate_table[VREL_LAST] = {
   VREL_VARYING, VREL_UNDEFINED, VREL_GE, VREL_GT, VREL_LE, VREL_LT, VREL_NE,
   VREL_EQ };
 
@@ -54,11 +54,11 @@ relation_kind rr_negate_table[VREL_LAST]
 relation_kind
 relation_negate (relation_kind r)
 {
-  return rr_negate_table [r];
+  return relation_kind (rr_negate_table [r]);
 }
 
 // This table is used to swap the operands.  op1 REL op2 -> op2 REL op1.
-relation_kind rr_swap_table[VREL_LAST] = {
+static const unsigned char rr_swap_table[VREL_LAST] = {
   VREL_VARYING, VREL_UNDEFINED, VREL_GT, VREL_GE, VREL_LT, VREL_LE, VREL_EQ,
   VREL_NE };
 
@@ -67,12 +67,12 @@ relation_kind rr_swap_table[VREL_LAST] =
 relation_kind
 relation_swap (relation_kind r)
 {
-  return rr_swap_table [r];
+  return relation_kind (rr_swap_table [r]);
 }
 
 // This table is used to perform an intersection between 2 relations.
 
-relation_kind rr_intersect_table[VREL_LAST][VREL_LAST] = {
+static const unsigned char rr_intersect_table[VREL_LAST][VREL_LAST] = {
 // VREL_VARYING
   { VREL_VARYING, VREL_UNDEFINED, VREL_LT, VREL_LE, VREL_GT, VREL_GE, VREL_EQ,
     VREL_NE },
@@ -104,13 +104,13 @@ relation_kind rr_intersect_table[VREL_LA
 relation_kind
 relation_intersect (relation_kind r1, relation_kind r2)
 {
-  return rr_intersect_table[r1][r2];
+  return relation_kind (rr_intersect_table[r1][r2]);
 }
 
 
 // This table is used to perform a union between 2 relations.
 
-relation_kind rr_union_table[VREL_LAST][VREL_LAST] = {
+static const unsigned char rr_union_table[VREL_LAST][VREL_LAST] = {
 // VREL_VARYING
   { VREL_VARYING, VREL_VARYING, VREL_VARYING, VREL_VARYING, VREL_VARYING,
     VREL_VARYING, VREL_VARYING, VREL_VARYING },
@@ -141,14 +141,14 @@ relation_kind rr_union_table[VREL_LAST][
 relation_kind
 relation_union (relation_kind r1, relation_kind r2)
 {
-  return rr_union_table[r1][r2];
+  return relation_kind (rr_union_table[r1][r2]);
 }
 
 
 // This table is used to determine transitivity between 2 relations.
 // (A relation0 B) and (B relation1 C) implies  (A result C)
 
-relation_kind rr_transitive_table[VREL_LAST][VREL_LAST] = {
+static const unsigned char rr_transitive_table[VREL_LAST][VREL_LAST] = {
 // VREL_VARYING
   { VREL_VARYING, VREL_VARYING, VREL_VARYING, VREL_VARYING, VREL_VARYING,
     VREL_VARYING, VREL_VARYING, VREL_VARYING },
@@ -180,12 +180,12 @@ relation_kind rr_transitive_table[VREL_L
 relation_kind
 relation_transitive (relation_kind r1, relation_kind r2)
 {
-  return rr_transitive_table[r1][r2];
+  return relation_kind (rr_transitive_table[r1][r2]);
 }
 
 // This vector maps a relation to the equivalent tree code.
 
-tree_code relation_to_code [VREL_LAST] = {
+static const tree_code relation_to_code [VREL_LAST] = {
   ERROR_MARK, ERROR_MARK, LT_EXPR, LE_EXPR, GT_EXPR, GE_EXPR, EQ_EXPR,
   NE_EXPR };
 
@@ -1727,6 +1727,8 @@ namespace selftest
 void
 relation_tests ()
 {
+  // rr_*_table tables use unsigned char rather than relation_kind.
+  ASSERT_LT (VREL_LAST, UCHAR_MAX);
   // Verify commutativity of relation_intersect and relation_union.
   for (relation_kind r1 = VREL_VARYING; r1 < VREL_PE8;
        r1 = relation_kind (r1 + 1))

	Jakub


             reply	other threads:[~2023-01-26 10:24 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-26 10:23 Jakub Jelinek [this message]
2023-01-26 12:52 ` Richard Biener

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y9JUvA7+lqVDt6WR@tucnak \
    --to=jakub@redhat.com \
    --cc=aldyh@redhat.com \
    --cc=amacleod@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=rguenther@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).