From patchwork Mon Oct 23 09:44:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 829205 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-464711-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="UNTc8V7l"; 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 3yLBMS4RJMz9sNV for ; Mon, 23 Oct 2017 20:44:51 +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 :subject:references:to:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=v0BuMVhxUtTBHvtMu lCtpluEaVuEQEuNLw5lK0wTusyVEtHSW6GvzmD7zGLKr1FFRyNkN7BlWfYpudLWD sDO56OONVoH6gG7IOnWtDw4o/Uv4G3ht9kmttxwPr8eXNLKR2iAIT8qAN8enI9hi ejp/OJMonTkixFzrAe5Ca/jb7s= 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 :subject:references:to:from:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=BNDUGoNwD0Y84WNGnNZIdmJ QXx4=; b=UNTc8V7lsfudVHRFkI+nzE0k7W9G5Q/+qTGq8fhs68O89GaFDuLNhf+ Qx6lPKuOmqzaubMJTbJCq+Psrw2kxHgQAS89GQPsrC1MkzFJ22eZ7Nn8EgdcuN12 bcoDK/hnowv+8/ncgWoHI/bpCUAROwmacos2nGUvF5LRX0mHNo8g= Received: (qmail 95176 invoked by alias); 23 Oct 2017 09:44:42 -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 95143 invoked by uid 89); 23 Oct 2017 09:44:40 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=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=REF, 98935, 9417 X-HELO: mail-wr0-f172.google.com Received: from mail-wr0-f172.google.com (HELO mail-wr0-f172.google.com) (209.85.128.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 23 Oct 2017 09:44:34 +0000 Received: by mail-wr0-f172.google.com with SMTP id r79so16665003wrb.13 for ; Mon, 23 Oct 2017 02:44:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:references:to:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=1oY+PTVGjuWtnyI7gusYHsPCVyWlmI2BBYUgz0rpawY=; b=CgkYm0vG8SgW4Z74HnLqbL8cK+vN9G9DF+kSw3CYIwCLNHjZu+Z2pOB3A4ZNKSayFB 9ZZYABmUkqaCWBipWOSnbOE6SVOQxnOf3DL+HzVf+f8zSdqGvXpbYzVE9+AQ8vpvvAqv PrHODgh34IpIn9785E8JxQBrf/llt7vLtIm/YjLAYnJ5pkeVE+6VFqD0eZgwO+oFevlk eIE2FhXT+7pCiMLYIvmxtwSQ+Mh1wXcd/ELx/6t4AjL16Cl6PpasGQzmiLjl3SDu/Q6e Rhy04t1WKRHoF9rXXnc371WqMS5R5OuG3WhRnfJ4a4pMKCPW8npSxPct7gFUEmNhS2c3 oZBQ== X-Gm-Message-State: AMCzsaVsRLC8p/UwuWBED39+1wFqLGjdaNw0DkUjo12KrGCnUuRHgGPR 3hJS1kP45+94DpGhwPrp6w2mcAC+KHk= X-Google-Smtp-Source: ABhQp+RyU2DC3PcmZpRql+U/gRWibpOKnY/nUBqTpanOzzzgoZ9+Npmuz1a1gWmXY3TI+TQe4GviXg== X-Received: by 10.223.183.135 with SMTP id s7mr10465724wre.265.1508751872287; Mon, 23 Oct 2017 02:44:32 -0700 (PDT) Received: from abulafia.quesejoda.com ([172.56.31.93]) by smtp.gmail.com with ESMTPSA id 50sm7218899wry.84.2017.10.23.02.44.29 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Oct 2017 02:44:31 -0700 (PDT) Subject: PING Fwd: [patch] implement generic debug() for vectors and hash sets References: To: gcc-patches From: Aldy Hernandez X-Forwarded-Message-Id: Message-ID: Date: Mon, 23 Oct 2017 05:44:24 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: X-IsSubscribed: yes -------- Forwarded Message -------- Subject: [patch] implement generic debug() for vectors and hash sets Date: Mon, 16 Oct 2017 09:52:51 -0400 From: Aldy Hernandez To: gcc-patches We have a generic mechanism for dumping types from the debugger with: (gdb) call debug(some_type) However, even though most types are implemented, we have no canonical way of dumping vectors or hash sets. The attached patch fixes this oversight. With it you can call debug(vec<>) and debug(hash_set<>) with the following types: rtx, tree, basic_block, edge, rtx_insn. More can be added simply by adding a debug_slim(your_type) overload and calling: DEFINE_DEBUG_VEC (your_type) DEFINE_DEBUG_HASH_SET (your_type) Here is an example of how things look with this patch: vec of edges: [0] = 10)> vec of bbs: [0] = [1] = vec of trees: [0] = [1] = [2] = vec of rtx: [0] = (reg:SI 87) [1] = (reg:SI 87) hash of bbs: OK for mainline? gcc/ * vec.h (debug_helper): New function. (DEFINE_DEBUG_VEC): New macro. * hash-set.h (debug_helper): New function. (DEFINE_DEBUG_HASH_SET): New macro. * cfg.c (debug_slim (edge)): New function. Call DEFINE_DEBUG_VEC for edges. Call DEFINE_DEBUG_HASH_SET for edges. * cfghooks.c (debug_slim (basic_block)): New function. Call DEFINE_DEBUG_VEC for basic blocks. Call DEFINE_DEBUG_HASH_SET for basic blocks. * print-tree.c (debug_slim): New function to handle trees. Call DEFINE_DEBUG_VEC for trees. Call DEFINE_DEBUG_HASH_SET for trees. (debug (vec) &): Remove. (debug () *): Remove. * print-rtl.c (debug_slim): New function to handle const_rtx. Call DEFINE_DEBUG_VEC for rtx_def. Call DEFINE_DEBUG_VEC for rtx_insn. Call DEFINE_DEBUG_HASH_SET for rtx_def. Call DEFINE_DEBUG_HASH_SET for rtx_insn. * sel-sched-dump.c (debug (vec &): Remove. (debug (vec *ptr): Remove. (debug_insn_vector): Remove. * stor-layout.c (debug_rli): Call debug() instead of debug_vec_tree. diff --git a/gcc/cfg.c b/gcc/cfg.c index 01e68aeda51..4d02fb56cbf 100644 --- a/gcc/cfg.c +++ b/gcc/cfg.c @@ -573,6 +573,16 @@ debug (edge_def *ptr) else fprintf (stderr, "\n"); } + +static void +debug_slim (edge e) +{ + fprintf (stderr, " %d)>", (void *) e, + e->src->index, e->dest->index); +} + +DEFINE_DEBUG_VEC (edge) +DEFINE_DEBUG_HASH_SET (edge) /* Simple routines to easily allocate AUX fields of basic blocks. */ diff --git a/gcc/cfghooks.c b/gcc/cfghooks.c index 258a5eabf8d..73b196feec7 100644 --- a/gcc/cfghooks.c +++ b/gcc/cfghooks.c @@ -304,6 +304,14 @@ debug (basic_block_def *ptr) fprintf (stderr, "\n"); } +static void +debug_slim (basic_block ptr) +{ + fprintf (stderr, "", (void *) ptr, ptr->index); +} + +DEFINE_DEBUG_VEC (basic_block_def *) +DEFINE_DEBUG_HASH_SET (basic_block_def *) /* Dumps basic block BB to pretty-printer PP, for use as a label of a DOT graph record-node. The implementation of this hook is diff --git a/gcc/hash-set.h b/gcc/hash-set.h index d2247d39571..58f7750243a 100644 --- a/gcc/hash-set.h +++ b/gcc/hash-set.h @@ -123,6 +123,44 @@ private: hash_table m_table; }; +/* Generic hash_set debug helper. + + This needs to be instantiated for each hash_set used throughout + the compiler like this: + + DEFINE_DEBUG_HASH_SET (TYPE) + + The reason we have a debug_helper() is because GDB can't + disambiguate a plain call to debug(some_hash), and it must be called + like debug(some_hash). */ +template +void +debug_helper (hash_set &ref) +{ + for (typename hash_set::iterator it = ref.begin (); + it != ref.end (); ++it) + { + debug_slim (*it); + fputc ('\n', stderr); + } +} + +#define DEFINE_DEBUG_HASH_SET(T) \ + template static void debug_helper (hash_set &); \ + DEBUG_FUNCTION void \ + debug (hash_set &ref) \ + { \ + debug_helper (ref); \ + } \ + DEBUG_FUNCTION void \ + debug (hash_set *ptr) \ + { \ + if (ptr) \ + debug (*ptr); \ + else \ + fprintf (stderr, "\n"); \ + } + /* ggc marking routines. */ template diff --git a/gcc/print-rtl.c b/gcc/print-rtl.c index 28d99862cad..5fe23801ab2 100644 --- a/gcc/print-rtl.c +++ b/gcc/print-rtl.c @@ -967,6 +967,23 @@ debug (const rtx_def *ptr) fprintf (stderr, "\n"); } +/* Like debug_rtx but with no newline, as debug_helper will add one. + + Note: No debug_slim(rtx_insn *) variant implemented, as this + function can serve for both rtx and rtx_insn. */ + +static void +debug_slim (const_rtx x) +{ + rtx_writer w (stderr, 0, false, false, NULL); + w.print_rtx (x); +} + +DEFINE_DEBUG_VEC (rtx_def *) +DEFINE_DEBUG_VEC (rtx_insn *) +DEFINE_DEBUG_HASH_SET (rtx_def *) +DEFINE_DEBUG_HASH_SET (rtx_insn *) + /* Count of rtx's to print with debug_rtx_list. This global exists because gdb user defined commands have no arguments. */ diff --git a/gcc/print-tree.c b/gcc/print-tree.c index d534c76ee49..3a0f85d4038 100644 --- a/gcc/print-tree.c +++ b/gcc/print-tree.c @@ -1095,32 +1095,6 @@ debug_raw (vec &ref) } DEBUG_FUNCTION void -debug (vec &ref) -{ - tree elt; - unsigned ix; - - /* Print the slot this node is in, and its code, and address. */ - fprintf (stderr, " *ptr) -{ - if (ptr) - debug (*ptr); - else - fprintf (stderr, "\n"); -} - -DEBUG_FUNCTION void debug_raw (vec *ptr) { if (ptr) @@ -1129,8 +1103,11 @@ debug_raw (vec *ptr) fprintf (stderr, "\n"); } -DEBUG_FUNCTION void -debug_vec_tree (vec *vec) +static void +debug_slim (tree t) { - debug_raw (vec); + print_node_brief (stderr, "", t, 0); } + +DEFINE_DEBUG_VEC (tree) +DEFINE_DEBUG_HASH_SET (tree) diff --git a/gcc/sel-sched-dump.c b/gcc/sel-sched-dump.c index 388a8af54c6..027b6b1c7c6 100644 --- a/gcc/sel-sched-dump.c +++ b/gcc/sel-sched-dump.c @@ -989,35 +989,6 @@ debug_blist (blist_t bnds) restore_dump (); } -/* Dump a rtx vector REF. */ -DEBUG_FUNCTION void -debug (vec &ref) -{ - switch_dump (stderr); - dump_insn_vector (ref); - sel_print ("\n"); - restore_dump (); -} - -DEBUG_FUNCTION void -debug (vec *ptr) -{ - if (ptr) - debug (*ptr); - else - fprintf (stderr, "\n"); -} - -/* Dump an insn vector SUCCS. */ -DEBUG_FUNCTION void -debug_insn_vector (rtx_vec_t succs) -{ - switch_dump (stderr); - dump_insn_vector (succs); - sel_print ("\n"); - restore_dump (); -} - /* Dump a hard reg set SET to stderr. */ DEBUG_FUNCTION void debug_hard_reg_set (HARD_REG_SET set) diff --git a/gcc/stor-layout.c b/gcc/stor-layout.c index 02739b0ed7f..9577cfa47ef 100644 --- a/gcc/stor-layout.c +++ b/gcc/stor-layout.c @@ -941,7 +941,7 @@ debug_rli (record_layout_info rli) if (!vec_safe_is_empty (rli->pending_statics)) { fprintf (stderr, "pending statics:\n"); - debug_vec_tree (rli->pending_statics); + debug (rli->pending_statics); } } diff --git a/gcc/vec.h b/gcc/vec.h index cbdd439571b..b145eef2bc7 100644 --- a/gcc/vec.h +++ b/gcc/vec.h @@ -407,6 +407,83 @@ struct GTY((user)) vec { }; +/* Generic vec<> debug helpers. + + These need to be instantiated for each vec used throughout + the compiler like this: + + DEFINE_DEBUG_VEC (TYPE) + + The reason we have a debug_helper() is because GDB can't + disambiguate a plain call to debug(some_vec), and it must be called + like debug(some_vec). */ + +template +void +debug_helper (vec &ref) +{ + unsigned i; + for (i = 0; i < ref.length (); ++i) + { + fprintf (stderr, "[%d] = ", i); + debug_slim (ref[i]); + fputc ('\n', stderr); + } +} + +/* We need a separate va_gc variant here because default template + argument for functions cannot be used in c++-98. Once this + restriction is removed, those variant should be folded with the + above debug_helper. */ + +template +void +debug_helper (vec &ref) +{ + unsigned i; + for (i = 0; i < ref.length (); ++i) + { + fprintf (stderr, "[%d] = ", i); + debug_slim (ref[i]); + fputc ('\n', stderr); + } +} + +/* Macro to define debug(vec) and debug(vec) helper + functions for a type T. */ + +#define DEFINE_DEBUG_VEC(T) \ + template static void debug_helper (vec &); \ + template static void debug_helper (vec &); \ + /* Define the vec debug functions. */ \ + DEBUG_FUNCTION void \ + debug (vec &ref) \ + { \ + debug_helper (ref); \ + } \ + DEBUG_FUNCTION void \ + debug (vec *ptr) \ + { \ + if (ptr) \ + debug (*ptr); \ + else \ + fprintf (stderr, "\n"); \ + } \ + /* Define the vec debug functions. */ \ + DEBUG_FUNCTION void \ + debug (vec &ref) \ + { \ + debug_helper (ref); \ + } \ + DEBUG_FUNCTION void \ + debug (vec *ptr) \ + { \ + if (ptr) \ + debug (*ptr); \ + else \ + fprintf (stderr, "\n"); \ + } + /* Default-construct N elements in DST. */ template