From patchwork Fri Jul 15 09:40:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 12 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a98:d5ce:0:b0:178:cc93:bf7d with SMTP id g14csp251297eik; Fri, 15 Jul 2022 02:42:20 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vYrACHp4FNSLryoYev76ovKrNWbu6MqgS8b251K9KcuqLQYNa6jss9iSEogCmZFbMku/i5 X-Received: by 2002:a05:6402:950:b0:43a:5194:174c with SMTP id h16-20020a056402095000b0043a5194174cmr17906083edz.145.1657878140237; Fri, 15 Jul 2022 02:42:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657878140; cv=none; d=google.com; s=arc-20160816; b=F9NjGaD9NC7igfaR/cHo1brwaWbm6c87dAikDBAW+XCpiKc6yiHhBePCtG+zOTB+xf ZByxQJl6TX19fsOAKSiZlLKBhU8l0U7nVcW8+I6rIQ+Pn5zXxAP3UDcGEe5roXKuTLDb 5icDlX41CBx2zA4hvHDSk/zz62UfxpfzqXpD6CC/ROB2aGuqrWbtrhVGFfYxSrXemFek 8N9D5EZ7twa0BhATKdRa+uZCROoGJp/Pqy2qqT5ocXVRDBBSMOVO6IHQyrQfNyam1Il9 8L7DWTykktkCHNxtqYJOHdgnv47mg7/MT66pjpNsaiJmctjbDRhvxgyAyVlINBqqz68N us/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=opYxlq2gO6V8ZMPuFsni2NdznR7vZ96K3iI76sz0UzA=; b=AvhLnzJ12oqDmQVLoO/BeN4XUOtx6E6GwSsh0NQcFP7kRJRejVtam/xsEXFxMdMAD3 BsbtUmDXdmxSBpraI/hcb++QzrheSLqhromssZCMJYwfHIwpmaEVHkqo72UgNO7LJevR cbZqHxarQKHstIxLFkeHOBD8aZDXdIFDsh6Nh8TkAJkxKmtx3T+D5fBLo3Qg0FK+8zX6 IgUDsbE2rlXuYJIeL5GK/70VVnHqaE0Lb+0K5Mo4UvlGhlAWKa5hv0eteMMLwovGdVXF zat0bIelUcyb+yBK9sSBHmExZABesbzg1oT+XtbU0R5nuQyMRd99J1+hhNV+NXI3jL9J vUDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=FerRrImy; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id nb29-20020a1709071c9d00b006f3b19b0bb9si3542196ejc.89.2022.07.15.02.42.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jul 2022 02:42:20 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=FerRrImy; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C8E963865C27 for ; Fri, 15 Jul 2022 09:41:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C8E963865C27 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1657878096; bh=opYxlq2gO6V8ZMPuFsni2NdznR7vZ96K3iI76sz0UzA=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=FerRrImykpRHtcoAdSffIFajZZ5nIF9VV2OTvuD65nYYEf5beXgais4vQTZt36Qa1 cXlNObwHsIShnjB9veVQgJ+/vLzQ7J+50yyTi52PE3P12uFUATm0TsABpNX2CGiZy7 4TkLlQcQbQV/ZywCQwDW0Jy5NEes/r2RjTqvUMT4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 0244B3856DE4 for ; Fri, 15 Jul 2022 09:40:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0244B3856DE4 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-433-4q04sWplOeK_uUtkAP-egA-1; Fri, 15 Jul 2022 05:40:45 -0400 X-MC-Unique: 4q04sWplOeK_uUtkAP-egA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 367A98117B0 for ; Fri, 15 Jul 2022 09:40:45 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.193.172]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BF5092EF9E; Fri, 15 Jul 2022 09:40:44 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.17.1/8.17.1) with ESMTPS id 26F9egwH1011304 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 15 Jul 2022 11:40:42 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 26F9eg5C1011303; Fri, 15 Jul 2022 11:40:42 +0200 To: GCC patches Subject: [COMMITTED] Convert vrange dumping facilities to pretty_printer. Date: Fri, 15 Jul 2022 11:40:34 +0200 Message-Id: <20220715094035.1011279-2-aldyh@redhat.com> In-Reply-To: <20220715094035.1011279-1-aldyh@redhat.com> References: <20220715094035.1011279-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Aldy Hernandez via Gcc-patches From: "Li, Pan2 via Gcc-patches" Reply-To: Aldy Hernandez Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1738411228782248866?= X-GMAIL-MSGID: =?utf-8?q?1738411228782248866?= We need to dump global ranges from the gimple pretty printer code, but all the vrange dumping facilities work with FILE handles. This patch converts all the dumping methods to work with pretty printers, and provides a wrapper so the FILE * methods continue to work for debugging. I also cleaned up the code a bit. Tested on x86-64 Linux. gcc/ChangeLog: * Makefile.in (OBJS): Add value-range-pretty-print.o. * pretty-print.h (pp_vrange): New. * value-range.cc (vrange::dump): Call pp version. (unsupported_range::dump): Move to its own file. (dump_bound_with_infinite_markers): Same. (irange::dump): Same. (irange::dump_bitmasks): Same. (vrange::debug): Remove. * value-range.h: Remove virtual designation for dump methods. Remove dump_bitmasks method. * value-range-pretty-print.cc: New file. * value-range-pretty-print.h: New file. --- gcc/Makefile.in | 1 + gcc/pretty-print.h | 7 ++ gcc/value-range-pretty-print.cc | 111 +++++++++++++++++++++++++++++++ gcc/value-range-pretty-print.h | 37 +++++++++++ gcc/value-range.cc | 113 ++++---------------------------- gcc/value-range.h | 8 +-- 6 files changed, 172 insertions(+), 105 deletions(-) create mode 100644 gcc/value-range-pretty-print.cc create mode 100644 gcc/value-range-pretty-print.h diff --git a/gcc/Makefile.in b/gcc/Makefile.in index 3ae23702426..001506f8abf 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -1711,6 +1711,7 @@ OBJS = \ value-query.o \ value-range.o \ value-range-equiv.o \ + value-range-pretty-print.o \ value-range-storage.o \ value-relation.o \ value-prof.o \ diff --git a/gcc/pretty-print.h b/gcc/pretty-print.h index fc588447460..d810e57bb14 100644 --- a/gcc/pretty-print.h +++ b/gcc/pretty-print.h @@ -340,6 +340,13 @@ pp_get_prefix (const pretty_printer *pp) { return pp->prefix; } pp_string (PP, pp_buffer (PP)->digit_buffer); \ } \ while (0) +#define pp_vrange(PP, R) \ + do \ + { \ + vrange_printer vrange_pp (PP); \ + (R)->accept (vrange_pp); \ + } \ + while (0) #define pp_double(PP, F) pp_scalar (PP, "%f", F) #define pp_pointer(PP, P) pp_scalar (PP, "%p", P) diff --git a/gcc/value-range-pretty-print.cc b/gcc/value-range-pretty-print.cc new file mode 100644 index 00000000000..b795e92d8fb --- /dev/null +++ b/gcc/value-range-pretty-print.cc @@ -0,0 +1,111 @@ +/* Pretty print support for value ranges. + Copyright (C) 2019-2022 Free Software Foundation, Inc. + Contributed by Aldy Hernandez . + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3, or (at your option) +any later version. + +GCC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ + +#include "config.h" +#include "system.h" +#include "coretypes.h" +#include "backend.h" +#include "tree.h" +#include "gimple.h" +#include "ssa.h" +#include "tree-pretty-print.h" +#include "fold-const.h" +#include "gimple-range.h" +#include "value-range-pretty-print.h" + +void +vrange_printer::visit (const unsupported_range &r) const +{ + pp_string (pp, "[unsupported_range] "); + if (r.undefined_p ()) + { + pp_string (pp, "UNDEFINED"); + return; + } + if (r.varying_p ()) + { + pp_string (pp, "VARYING"); + return; + } + gcc_unreachable (); +} + +void +vrange_printer::visit (const irange &r) const +{ + pp_string (pp, "[irange] "); + if (r.undefined_p ()) + { + pp_string (pp, "UNDEFINED"); + return; + } + dump_generic_node (pp, r.type (), 0, TDF_NONE, false); + pp_character (pp, ' '); + if (r.varying_p ()) + { + pp_string (pp, "VARYING"); + return; + } + for (unsigned i = 0; i < r.num_pairs (); ++i) + { + tree lb = wide_int_to_tree (r.type (), r.lower_bound (i)); + tree ub = wide_int_to_tree (r.type (), r.upper_bound (i)); + pp_character (pp, '['); + print_irange_bound (lb); + pp_string (pp, ", "); + print_irange_bound (ub); + pp_character (pp, ']'); + } + print_irange_bitmasks (r); +} + +void +vrange_printer::print_irange_bound (tree bound) const +{ + tree type = TREE_TYPE (bound); + wide_int type_min = wi::min_value (TYPE_PRECISION (type), TYPE_SIGN (type)); + wide_int type_max = wi::max_value (TYPE_PRECISION (type), TYPE_SIGN (type)); + + if (INTEGRAL_TYPE_P (type) + && !TYPE_UNSIGNED (type) + && TREE_CODE (bound) == INTEGER_CST + && wi::to_wide (bound) == type_min + && TYPE_PRECISION (type) != 1) + pp_string (pp, "-INF"); + else if (TREE_CODE (bound) == INTEGER_CST + && wi::to_wide (bound) == type_max + && TYPE_PRECISION (type) != 1) + pp_string (pp, "+INF"); + else + dump_generic_node (pp, bound, 0, TDF_NONE, false); +} + +void +vrange_printer::print_irange_bitmasks (const irange &r) const +{ + wide_int nz = r.get_nonzero_bits (); + if (nz == -1) + return; + + pp_string (pp, " NONZERO "); + char buf[WIDE_INT_PRINT_BUFFER_SIZE]; + print_hex (nz, buf); + pp_string (pp, buf); +} diff --git a/gcc/value-range-pretty-print.h b/gcc/value-range-pretty-print.h new file mode 100644 index 00000000000..6d2fb74cc7a --- /dev/null +++ b/gcc/value-range-pretty-print.h @@ -0,0 +1,37 @@ +/* Pretty print support for value ranges. + Copyright (C) 2022 Free Software Foundation, Inc. + Contributed by Aldy Hernandez . + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3, or (at your option) +any later version. + +GCC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ + +#ifndef GCC_VALUE_RANGE_PRETTY_H +#define GCC_VALUE_RANGE_PRETTY_H + +class vrange_printer : public vrange_visitor +{ +public: + vrange_printer (pretty_printer *pp_) : pp (pp_) { } + void visit (const unsupported_range &) const override; + void visit (const irange &) const override; +private: + void print_irange_bound (tree bound) const; + void print_irange_bitmasks (const irange &) const; + + pretty_printer *pp; +}; + +#endif // GCC_VALUE_RANGE_PRETTY_H diff --git a/gcc/value-range.cc b/gcc/value-range.cc index 8e6ec4cd740..525e1924057 100644 --- a/gcc/value-range.cc +++ b/gcc/value-range.cc @@ -27,6 +27,7 @@ along with GCC; see the file COPYING3. If not see #include "gimple.h" #include "ssa.h" #include "tree-pretty-print.h" +#include "value-range-pretty-print.h" #include "fold-const.h" #include "gimple-range.h" @@ -212,6 +213,19 @@ vrange::operator== (const vrange &src) const gcc_unreachable (); } +// Wrapper for vrange_printer to dump a range to a file. + +void +vrange::dump (FILE *file) const +{ + pretty_printer buffer; + pp_needs_newline (&buffer) = true; + buffer.buffer->stream = file; + vrange_printer vrange_pp (&buffer); + this->accept (vrange_pp); + pp_flush (&buffer); +} + bool irange::supports_type_p (tree type) const { @@ -238,23 +252,6 @@ unsupported_range::unsupported_range () set_undefined (); } -void -unsupported_range::dump (FILE *file) const -{ - fprintf (file, "[unsupported_range] "); - if (undefined_p ()) - { - fprintf (file, "UNDEFINED"); - return; - } - if (varying_p ()) - { - fprintf (file, "VARYING"); - return; - } - gcc_unreachable (); -} - // Here we copy between any two irange's. The ranges can be legacy or // multi-ranges, and copying between any combination works correctly. @@ -2461,88 +2458,6 @@ irange::union_nonzero_bits (const irange &r) return false; } -static void -dump_bound_with_infinite_markers (FILE *file, tree bound) -{ - tree type = TREE_TYPE (bound); - wide_int type_min = wi::min_value (TYPE_PRECISION (type), TYPE_SIGN (type)); - wide_int type_max = wi::max_value (TYPE_PRECISION (type), TYPE_SIGN (type)); - - if (INTEGRAL_TYPE_P (type) - && !TYPE_UNSIGNED (type) - && TREE_CODE (bound) == INTEGER_CST - && wi::to_wide (bound) == type_min - && TYPE_PRECISION (type) != 1) - fprintf (file, "-INF"); - else if (TREE_CODE (bound) == INTEGER_CST - && wi::to_wide (bound) == type_max - && TYPE_PRECISION (type) != 1) - fprintf (file, "+INF"); - else - print_generic_expr (file, bound); -} - -void -irange::dump (FILE *file) const -{ - fprintf (file, "[irange] "); - if (undefined_p ()) - { - fprintf (file, "UNDEFINED"); - return; - } - print_generic_expr (file, type ()); - fprintf (file, " "); - if (varying_p ()) - { - fprintf (file, "VARYING"); - dump_bitmasks (file); - return; - } - if (legacy_mode_p ()) - { - fprintf (file, "%s[", (m_kind == VR_ANTI_RANGE) ? "~" : ""); - dump_bound_with_infinite_markers (file, min ()); - fprintf (file, ", "); - dump_bound_with_infinite_markers (file, max ()); - fprintf (file, "]"); - dump_bitmasks (file); - return; - } - for (unsigned i = 0; i < m_num_ranges; ++i) - { - tree lb = m_base[i * 2]; - tree ub = m_base[i * 2 + 1]; - fprintf (file, "["); - dump_bound_with_infinite_markers (file, lb); - fprintf (file, ", "); - dump_bound_with_infinite_markers (file, ub); - fprintf (file, "]"); - } - dump_bitmasks (file); -} - -void -irange::dump_bitmasks (FILE *file) const -{ - if (m_nonzero_mask) - { - wide_int nz = get_nonzero_bits (); - if (nz != -1) - { - fprintf (file, " NONZERO "); - print_hex (nz, file); - } - } -} - -void -vrange::debug () const -{ - dump (stderr); - fprintf (stderr, "\n"); -} - void dump_value_range (FILE *file, const vrange *vr) { diff --git a/gcc/value-range.h b/gcc/value-range.h index a7da8c5e900..4af92fd65d9 100644 --- a/gcc/value-range.h +++ b/gcc/value-range.h @@ -79,7 +79,6 @@ public: virtual bool supports_type_p (tree type) const; virtual void set_varying (tree type); virtual void set_undefined (); - virtual void dump (FILE * = stderr) const = 0; virtual bool union_ (const vrange &); virtual bool intersect (const vrange &); virtual bool singleton_p (tree *result = NULL) const; @@ -96,9 +95,9 @@ public: vrange& operator= (const vrange &); bool operator== (const vrange &) const; bool operator!= (const vrange &r) const { return !(*this == r); } + void dump (FILE *) const; enum value_range_kind kind () const; // DEPRECATED - void debug () const; protected: ENUM_BITFIELD(value_range_kind) m_kind : 8; @@ -149,7 +148,6 @@ public: // Misc methods. virtual bool fits_p (const vrange &r) const override; - virtual void dump (FILE * = stderr) const override; virtual void accept (const vrange_visitor &v) const override; // Nonzero masks. @@ -206,7 +204,6 @@ private: void set_nonzero_bits (tree mask); bool intersect_nonzero_bits (const irange &r); bool union_nonzero_bits (const irange &r); - void dump_bitmasks (FILE *) const; bool intersect (const wide_int& lb, const wide_int& ub); unsigned char m_num_ranges; @@ -252,7 +249,6 @@ class unsupported_range : public vrange { public: unsupported_range (); - virtual void dump (FILE *) const override; virtual void accept (const vrange_visitor &v) const override; }; @@ -339,7 +335,7 @@ public: bool operator!= (const Value_Range &r) const; operator vrange &(); operator const vrange &() const; - void dump (FILE *out = stderr) const; + void dump (FILE *) const; static bool supports_type_p (tree type); // Convenience methods for vrange compatability.