From patchwork Thu Nov 8 13:32:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 994884 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-489363-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="k/Q2lLhw"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42rPN447JHz9s9h for ; Fri, 9 Nov 2018 00:32:20 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=OeiInmghkoDW8FE+jD/QzSOjgc9CMYuAaa4EMCUQb+6J10V3XB MQX70B9SEmTCZn5Ty4ugVOGAYTR7aZvHZQzAANF21/ZnVdOq7OsrdDKZaBE1b5+k OYXxwKkj/NPSl9KlhqfwICxDlSKjeVDNRxrYOrJH2j3ZlW/6etr+hVj74= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=Ww2YMeNDWG4AbA9m503y0vjqI5k=; b=k/Q2lLhwopApMKsJQurE 5Q256iyr3y57cxO4RvSYIk75vWdFRDqqsi6htkWQ+KYivEA1hna/GcaPUj+kBYvD w9RqH9YfWB0bNlEVt8Yf53W4YSWXYd48noXyUj5hyw18Ac9/aGXdGEMYuGZ88ij+ QEcqkdAlWtjsUEZwwImPg0Q= Received: (qmail 43828 invoked by alias); 8 Nov 2018 13:32:13 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 43806 invoked by uid 89); 8 Nov 2018 13:32:12 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 spammy=vr, HX-Received:sk:7-v6mr1, spc X-HELO: mail-wm1-f45.google.com Received: from mail-wm1-f45.google.com (HELO mail-wm1-f45.google.com) (209.85.128.45) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 08 Nov 2018 13:32:10 +0000 Received: by mail-wm1-f45.google.com with SMTP id w7-v6so1275562wmc.1 for ; Thu, 08 Nov 2018 05:32:09 -0800 (PST) Received: from abulafia.quesejoda.com (128.red-88-6-116.staticip.rima-tde.net. [88.6.116.128]) by smtp.gmail.com with ESMTPSA id y13-v6sm3471085wrp.46.2018.11.08.05.32.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Nov 2018 05:32:07 -0800 (PST) To: gcc-patches , Richard Biener Cc: Andrew MacLeod From: Aldy Hernandez Subject: cleanups and unification of value_range dumping code Message-ID: <8987495e-4076-4ed5-ae85-160b77c3c7fb@redhat.com> Date: Thu, 8 Nov 2018 08:32:06 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.0 MIME-Version: 1.0 X-IsSubscribed: yes [Richard, you're right. An overloaded debug() is better than this->dump(). Anyone who thinks different is wrong. End of discussion.] There's no reason to have multiple ways of dumping a value range. And I'm not even talking about ipa-prop.* which decided that they should implement their own version of value_ranges basically to annoy me. Attached is a patch to remedy this. I have made three small user-visible changes to the dumping code-- cause, well... you know me... I can't leave things alone. 1. It *REALLY* irks me that bools are dumped with -INF/+INF. Everyone knows that bools should be 0/1. It's in the Bible. Look it up. 2. Analogous to #1, what's up with signed 1-bit fields? Who understands [0, +INF] as [0, 0]? No one; that's right. (It's still beyond me the necessity of signed bit fields in the standard period, but I'll pick my battles.) 3. I find it quite convenient to display the tree type along with the range as: [1, 1] int EQUIVALENCES { me, myself, I } Finally.. As mentioned, I've implement an overloaded debug() because it's *so* nice to use gdb and an alias of: define dd call debug($arg0) end ...and have stuff just work. I do realize that we still have dump() lying around. At some point, we should start dropping external access to the dump methods for objects that are never dumped by the compiler (but by the user at debug time). OK for trunk? * gimple-pretty-print.c (dump_ssaname_info): Use value_range dumper to dump range information. * tree-vrp.c (value_range::dump_range): New. (value_range::dump): Add variant for dumping to pretty_printer. Adjust FILE * version accordingly. (debug_value_range): Rename to debug. Remove unused prototypes: dump_value_range, debug_value_range, dump_all_value_ranges, dump_vr_equiv, debug_vr_equiv. * tree-vrp.h (value_range::dump): Add new variant that takes pretty_printer. (value_range::dump_range): New. diff --git a/gcc/gimple-pretty-print.c b/gcc/gimple-pretty-print.c index 7dfec9120ab..73af30ba92f 100644 --- a/gcc/gimple-pretty-print.c +++ b/gcc/gimple-pretty-print.c @@ -2122,21 +2122,11 @@ dump_ssaname_info (pretty_printer *buffer, tree node, int spc) if (!POINTER_TYPE_P (TREE_TYPE (node)) && SSA_NAME_RANGE_INFO (node)) { - wide_int min, max, nonzero_bits; - value_range_kind range_type = get_range_info (node, &min, &max); + value_range vr; - if (range_type == VR_VARYING) - pp_printf (buffer, "# RANGE VR_VARYING"); - else if (range_type == VR_RANGE || range_type == VR_ANTI_RANGE) - { - pp_printf (buffer, "# RANGE "); - pp_printf (buffer, "%s[", range_type == VR_RANGE ? "" : "~"); - pp_wide_int (buffer, min, TYPE_SIGN (TREE_TYPE (node))); - pp_printf (buffer, ", "); - pp_wide_int (buffer, max, TYPE_SIGN (TREE_TYPE (node))); - pp_printf (buffer, "]"); - } - nonzero_bits = get_nonzero_bits (node); + get_range_info (node, vr); + vr.dump (buffer); + wide_int nonzero_bits = get_nonzero_bits (node); if (nonzero_bits != -1) { pp_string (buffer, " NONZERO "); diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index b3f6490e1ca..db5e59b59e3 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -327,57 +327,69 @@ value_range::type () const return TREE_TYPE (min ()); } -/* Dump value range to FILE. */ +void +value_range::dump_range (pretty_printer *buffer) const +{ + tree ttype = type (); + pp_printf (buffer, "%s[", (m_kind == VR_ANTI_RANGE) ? "~" : ""); + if (INTEGRAL_TYPE_P (ttype) + && !TYPE_UNSIGNED (ttype) + && vrp_val_is_min (min ()) + && TYPE_PRECISION (ttype) != 1) + pp_printf (buffer, "-INF"); + else + dump_generic_node (buffer, min (), 0, TDF_SLIM, false); + + pp_printf (buffer, ", "); + + if (INTEGRAL_TYPE_P (ttype) + && vrp_val_is_max (max ()) + && TYPE_PRECISION (ttype) != 1) + pp_printf (buffer, "+INF"); + else + dump_generic_node (buffer, max (), 0, TDF_SLIM, false); + pp_string (buffer, "] "); + dump_generic_node (buffer, ttype, 0, TDF_SLIM, false); +} void -value_range::dump (FILE *file) const +value_range::dump (pretty_printer *buffer) const { if (undefined_p ()) - fprintf (file, "UNDEFINED"); + pp_string (buffer, "UNDEFINED"); else if (m_kind == VR_RANGE || m_kind == VR_ANTI_RANGE) { - tree type = TREE_TYPE (min ()); - - fprintf (file, "%s[", (m_kind == VR_ANTI_RANGE) ? "~" : ""); - - if (INTEGRAL_TYPE_P (type) - && !TYPE_UNSIGNED (type) - && vrp_val_is_min (min ())) - fprintf (file, "-INF"); - else - print_generic_expr (file, min ()); - - fprintf (file, ", "); - - if (INTEGRAL_TYPE_P (type) - && vrp_val_is_max (max ())) - fprintf (file, "+INF"); - else - print_generic_expr (file, max ()); - - fprintf (file, "]"); - + dump_range (buffer); if (m_equiv) { bitmap_iterator bi; unsigned i, c = 0; - fprintf (file, " EQUIVALENCES: { "); + pp_printf (buffer, " EQUIVALENCES: { "); EXECUTE_IF_SET_IN_BITMAP (m_equiv, 0, i, bi) { - print_generic_expr (file, ssa_name (i)); - fprintf (file, " "); + dump_generic_node (buffer, ssa_name (i), 0, TDF_SLIM, false); + pp_string (buffer, " "); c++; } - fprintf (file, "} (%u elements)", c); + pp_printf (buffer, "} (%u elements)", c); } } else if (varying_p ()) - fprintf (file, "VARYING"); + pp_string (buffer, "VARYING"); else - fprintf (file, "INVALID RANGE"); + pp_string (buffer, "INVALID RANGE"); +} + +void +dump_value_range (FILE *file, const value_range *vr) +{ + if (!vr) + fprintf (file, "[]"); + else + vr->dump (file); } void @@ -387,6 +399,28 @@ value_range::dump () const fprintf (stderr, "\n"); } +void +value_range::dump (FILE *file) const +{ + pretty_printer buffer; + pp_needs_newline (&buffer) = true; + buffer.buffer->stream = file; + dump (&buffer); + pp_flush (&buffer); +} + +DEBUG_FUNCTION void +debug (const value_range *vr) +{ + dump_value_range (stderr, vr); +} + +DEBUG_FUNCTION void +debug (const value_range vr) +{ + dump_value_range (stderr, &vr); +} + /* Return true if the SSA name NAME is live on the edge E. */ static bool @@ -2119,32 +2153,6 @@ extract_range_from_unary_expr (value_range *vr, return; } -/* Debugging dumps. */ - -void dump_value_range (FILE *, const value_range *); -void debug_value_range (const value_range *); -void dump_all_value_ranges (FILE *); -void dump_vr_equiv (FILE *, bitmap); -void debug_vr_equiv (bitmap); - -void -dump_value_range (FILE *file, const value_range *vr) -{ - if (!vr) - fprintf (file, "[]"); - else - vr->dump (file); -} - -/* Dump value range VR to stderr. */ - -DEBUG_FUNCTION void -debug_value_range (const value_range *vr) -{ - vr->dump (); -} - - /* Given a COND_EXPR COND of the form 'V OP W', and an SSA name V, create a new SSA name N and return the assertion assignment 'N = ASSERT_EXPR '. */ diff --git a/gcc/tree-vrp.h b/gcc/tree-vrp.h index c5811d50bbf..78964b4b10f 100644 --- a/gcc/tree-vrp.h +++ b/gcc/tree-vrp.h @@ -72,6 +72,7 @@ class GTY((for_user)) value_range void set_and_canonicalize (enum value_range_kind, tree, tree, bitmap); void dump (FILE *) const; void dump () const; + void dump (pretty_printer *buffer) const; enum value_range_kind kind () const; tree min () const; @@ -83,6 +84,7 @@ class GTY((for_user)) value_range bool equal_p (const value_range &, bool ignore_equivs) const; void intersect_helper (value_range *, const value_range *); void union_helper (value_range *, const value_range *); + void dump_range (pretty_printer *) const; enum value_range_kind m_kind; public: